MCPcopy
hub / github.com/udecode/plate / withSlate

Function withSlate

packages/core/src/lib/editor/withSlate.ts:216–373  ·  view source on GitHub ↗
(
  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> = {}
)

Source from the content-addressed store, hash-verified

214 * @see {@link withPlate} for the React-specific enhancement function.
215 */
216export 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;

Callers 7

withPlateFunction · 0.90
withStaticFunction · 0.90
createSlateEditorFunction · 0.85
withSlate.spec.tsFile · 0.85

Calls 9

getSlatePluginFunction · 0.90
getPluginTypeFunction · 0.90
getCorePluginsFunction · 0.90
createSlatePluginFunction · 0.90
resolvePluginsFunction · 0.90
initMethod · 0.80
normalizeNodeFunction · 0.50
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…