Editor
The withPortive
plugin adds image and file attachment uploading to Slate.
When used with withReact
and withHistory
those plugins should be applied inside:
Options
Configuration options for withPortive
:
authToken: string | () => string | () => Promise<string>
authToken: string | () => string | () => Promise<string>
To learn what an authToken
is, why you need one and how to generate one see the authToken
reference.
The authToken
can be provided as a string
or a function
(including an async function
) that returns a string
.
initialMaxSize: [number, number]
initialMaxSize: [number, number]
Sets the initial maximum size of an uploaded image in the Editor. The value represents a max [width, height]
.
If an image is smaller than the initialMaxSize
width/height, the image is shown at full size. If an image is larger than the width/height, the image is scaled down to fit within the width/height.
minResizeWidth?: number = 100
minResizeWidth?: number = 100
Images below the minResizeWidth
are not shown drag handles for resizing. This is usually a good idea because there is not much value in resizing very small images and the resize handles can overwhelm the size of a small image.
Images above the minResizeWidth
can be resized, but they can only be resized down to the minResizeWidth
.
maxResizeWidth?: number = 1280
maxResizeWidth?: number = 1280
The maximum width an image can be resized to.
createImageFileElement: (e: CreateImageFileElementEvent) => Element & ImageElementInterface
createImageFileElement: (e: CreateImageFileElementEvent) => Element & ImageElementInterface
When a user starts uploading a file, it is handled in one of two ways:
If it is a supported image file type (e.g.
.gif
,.jpg
,.jpeg
,.png
or.webp
) then this methodcreateImageFileElement
is calledIf it is not a supported image file type then a different method
createGenericFileElement
is called
The result of the callback is an Image Element
which must include but is not limited to these props:
originKey
which is astring
the file'sOrigin
(i.e. where it comes from and also its current uploading state).originSize
which are the dimensions of the image a theOrigin
size
which represents the current display width/height of the image
Typically, these properties are passed almost straight through from the CreateImageFileEvent
. for example:
createGenericFileElement: (e: CreateGenericFileElementEvent) => Element & { originKey: string }
createGenericFileElement: (e: CreateGenericFileElementEvent) => Element & { originKey: string }
If it is a supported image file type (e.g.
.gif
,.jpg
,.jpeg
,.png
or.webp
) then a different methodcreateImageFileElement
is calledIf it is not a supported image file type then this method
createGenericFileElement
is called
The result of the callback is a Generic File Element
(i.e. usually an Element that represents a file attachment) which must include but is not limited to this prop:
originKey
which is astring
the file'sOrigin
(i.e. where it comes from and also its current uploading state).
Typically, several of these properties are used to provide information for an attachment Element. for example:
initialOrigins?: Record<string, Origin> = {}
initialOrigins?: Record<string, Origin> = {}
For Unit Testing and Demos
During testing, however, we may wish to create an editor
object with
Last updated