(
e: Editor,
{
id,
affinity = true,
autoSelect,
chunking = true,
maxLength,
navigationFeedback,
nodeId,
optionsStoreFactory,
plugins = [],
readOnly = false,
rootPlugin,
selection,
shouldNormalizeEditor,
skipInitialization,
userId,
value,
onReady,
...pluginConfig
}: WithSlateOptions<V, P> = {}
)
| 214 | * @see {@link withPlate} for the React-specific enhancement function. |
| 215 | */ |
| 216 | export const withSlate = < |
| 217 | V extends Value = Value, |
| 218 | P extends AnyPluginConfig = CorePlugin, |
| 219 | >( |
| 220 | e: Editor, |
| 221 | { |
| 222 | id, |
| 223 | affinity = true, |
| 224 | autoSelect, |
| 225 | chunking = true, |
| 226 | maxLength, |
| 227 | navigationFeedback, |
| 228 | nodeId, |
| 229 | optionsStoreFactory, |
| 230 | plugins = [], |
| 231 | readOnly = false, |
| 232 | rootPlugin, |
| 233 | selection, |
| 234 | shouldNormalizeEditor, |
| 235 | skipInitialization, |
| 236 | userId, |
| 237 | value, |
| 238 | onReady, |
| 239 | ...pluginConfig |
| 240 | }: WithSlateOptions<V, P> = {} |
| 241 | ): TSlateEditor<V, InferPlugins<P[]>> => { |
| 242 | const editor = e as SlateEditor; |
| 243 | |
| 244 | editor.id = id ?? editor.id ?? nanoid(); |
| 245 | editor.meta.key = editor.meta.key ?? nanoid(); |
| 246 | editor.meta.isFallback = false; |
| 247 | editor.meta.userId = userId; |
| 248 | editor.dom = { |
| 249 | composing: false, |
| 250 | currentKeyboardEvent: null, |
| 251 | focused: false, |
| 252 | prevSelection: null, |
| 253 | readOnly, |
| 254 | }; |
| 255 | |
| 256 | editor.getApi = () => editor.api as any; |
| 257 | editor.getTransforms = () => editor.transforms as any; |
| 258 | editor.getPlugin = (plugin) => getSlatePlugin(editor, plugin) as any; |
| 259 | editor.getType = (pluginKey) => getPluginType(editor, pluginKey); |
| 260 | editor.getInjectProps = (plugin) => { |
| 261 | const nodeProps = |
| 262 | editor.getPlugin<AnySlatePlugin>(plugin).inject?.nodeProps ?? ({} as any); |
| 263 | |
| 264 | nodeProps.nodeKey = nodeProps.nodeKey ?? editor.getType(plugin.key); |
| 265 | nodeProps.styleKey = nodeProps.styleKey ?? nodeProps.nodeKey; |
| 266 | |
| 267 | return nodeProps; |
| 268 | }; |
| 269 | editor.getOptionsStore = (plugin) => editor.getPlugin(plugin).optionsStore; |
| 270 | editor.getOptions = (plugin) => { |
| 271 | const store = editor.getOptionsStore(plugin); |
| 272 | |
| 273 | if (!store) return editor.getPlugin(plugin).options; |
no test coverage detected
searching dependent graphs…