@lofcz/platejs-core 52.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2582 @@
1
+ import { Gt as getEditorPlugin$1, Kt as createSlatePlugin, Pt as BaseParagraphPlugin, Z as DOMPlugin, dt as getPluginNodeProps, f as isEditOnly, n as withSlate, s as SlateExtensionPlugin, tt as ChunkingPlugin, ut as getSlateClass, zt as getPluginByType } from "../withSlate-1B0SfAWG.js";
2
+ import { t as Hotkeys } from "../hotkeys-DI1HPO2Q.js";
3
+ import { A as pipeInjectNodeProps, C as createStaticEditor, k as pipeDecorate, s as PlateStatic } from "../static-CVN6JhaR.js";
4
+ import { PathApi, createEditor } from "@platejs/slate";
5
+ import { isDefined } from "@udecode/utils";
6
+ import { DefaultPlaceholder, Editable, Slate, useComposing, useFocused, useReadOnly, useSelected, useSlateStatic, withReact } from "slate-react";
7
+ import { c } from "react-compiler-runtime";
8
+ import React, { useEffect, useId, useRef } from "react";
9
+ import { Key, useHotkeys } from "@udecode/react-hotkeys";
10
+ import { createAtomStore, useAtomStoreSet, useAtomStoreState, useAtomStoreValue, useStoreAtomState, useStoreAtomValue, useStoreAtomValue as useStoreAtomValue$1, useStoreSetAtom } from "jotai-x";
11
+ import { atom, atom as atom$1 } from "jotai";
12
+ import { createZustandStore, createZustandStore as createZustandStore$1, useStoreSelect, useStoreSelect as useStoreSelect$1, useStoreState, useStoreValue, useStoreValue as useStoreValue$1, useTracked, useTrackedStore } from "zustand-x";
13
+ import clsx$1, { clsx } from "clsx";
14
+ import omit from "lodash/omit.js";
15
+ import { useDeepCompareMemo } from "use-deep-compare";
16
+ import { useComposedRef, useMemoizedSelector, useStableFn } from "@udecode/react-utils";
17
+ import { selectAtom } from "jotai/utils";
18
+ import { focusAtom } from "jotai-optics";
19
+
20
+ //#region src/react/components/ContentVisibilityChunk.tsx
21
+ const ContentVisibilityChunk = (t0) => {
22
+ const $ = c(4);
23
+ const { attributes, children, lowest } = t0;
24
+ if (!lowest) return children;
25
+ let t1;
26
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
27
+ t1 = { contentVisibility: "auto" };
28
+ $[0] = t1;
29
+ } else t1 = $[0];
30
+ let t2;
31
+ if ($[1] !== attributes || $[2] !== children) {
32
+ t2 = /* @__PURE__ */ React.createElement("div", {
33
+ ...attributes,
34
+ style: t1
35
+ }, children);
36
+ $[1] = attributes;
37
+ $[2] = children;
38
+ $[3] = t2;
39
+ } else t2 = $[3];
40
+ return t2;
41
+ };
42
+
43
+ //#endregion
44
+ //#region src/react/plugin/toPlatePlugin.ts
45
+ const methodsToWrap = [
46
+ "configure",
47
+ "configurePlugin",
48
+ "extendEditorApi",
49
+ "extendSelectors",
50
+ "extendApi",
51
+ "extendEditorTransforms",
52
+ "extendTransforms",
53
+ "overrideEditor",
54
+ "extend",
55
+ "extendPlugin"
56
+ ];
57
+ /**
58
+ * Extends a SlatePlugin to create a React PlatePlugin.
59
+ *
60
+ * @remarks
61
+ * This function transforms a SlatePlugin into a React PlatePlugin, allowing for
62
+ * React-specific functionality to be added.
63
+ * @param basePlugin - The base SlatePlugin to be extended.
64
+ * @param extendConfig - A function or object that provides the extension
65
+ * configuration. If a function, it receives the plugin context and should
66
+ * return a partial PlatePlugin. If an object, it should be a partial
67
+ * PlatePlugin configuration.
68
+ * @returns A new PlatePlugin that combines the base SlatePlugin functionality
69
+ * with React-specific features defined in the extension configuration.
70
+ */
71
+ function toPlatePlugin(basePlugin, extendConfig) {
72
+ const plugin = { ...basePlugin };
73
+ methodsToWrap.forEach((method) => {
74
+ const originalMethod = plugin[method];
75
+ plugin[method] = (...args) => {
76
+ return toPlatePlugin(originalMethod(...args));
77
+ };
78
+ });
79
+ if (!extendConfig) return plugin;
80
+ return plugin.extend(extendConfig);
81
+ }
82
+ /**
83
+ * Explicitly typed version of {@link toPlatePlugin}.
84
+ *
85
+ * @remarks
86
+ * This function requires explicit type parameters for both the base plugin
87
+ * configuration and the extension configuration. Use this when you need
88
+ * precise control over the plugin's type structure or when type inference
89
+ * doesn't provide the desired result.
90
+ * @typeParam C - The type of the extension configuration for the PlatePlugin
91
+ * (required).
92
+ * @typeParam TContext - The type of the base SlatePlugin configuration
93
+ * (optional).
94
+ */
95
+ function toTPlatePlugin(basePlugin, extendConfig) {
96
+ return toPlatePlugin(basePlugin, extendConfig);
97
+ }
98
+
99
+ //#endregion
100
+ //#region src/react/plugin/createPlatePlugin.ts
101
+ const createPlatePlugin = (config = {}) => {
102
+ return toPlatePlugin(createSlatePlugin(config));
103
+ };
104
+ /**
105
+ * Explicitly typed version of `createPlatePlugin`.
106
+ *
107
+ * @remarks
108
+ * While `createPlatePlugin` uses type inference, this function requires an
109
+ * explicit type parameter. Use this when you need precise control over the
110
+ * plugin's type structure or when type inference doesn't provide the desired
111
+ * result.
112
+ */
113
+ function createTPlatePlugin(config = {}) {
114
+ return createPlatePlugin(config);
115
+ }
116
+
117
+ //#endregion
118
+ //#region src/react/plugin/getEditorPlugin.ts
119
+ function getEditorPlugin(editor, plugin) {
120
+ return getEditorPlugin$1(editor, plugin);
121
+ }
122
+
123
+ //#endregion
124
+ //#region src/react/plugin/getPlugin.ts
125
+ /** Get editor plugin by key or plugin object. */
126
+ function getPlugin(editor, plugin) {
127
+ return editor.plugins[plugin.key] ?? createPlatePlugin({ key: plugin.key });
128
+ }
129
+
130
+ //#endregion
131
+ //#region src/react/plugin/omitPluginContext.ts
132
+ const omitPluginContext = (ctx) => {
133
+ const { api, editor, getOption, getOptions, plugin, setOption, setOptions, tf, type, ...rest } = ctx;
134
+ return rest;
135
+ };
136
+
137
+ //#endregion
138
+ //#region src/react/plugins/SlateReactExtensionPlugin.ts
139
+ const SlateReactExtensionPlugin = toPlatePlugin(SlateExtensionPlugin, { handlers: { onKeyDown: ({ editor, event }) => {
140
+ event.persist();
141
+ editor.dom.currentKeyboardEvent = event;
142
+ if (Hotkeys.isMoveUpward(event)) {
143
+ if (editor.tf.moveLine({ reverse: true })) {
144
+ event.preventDefault();
145
+ event.stopPropagation();
146
+ }
147
+ } else if (Hotkeys.isMoveDownward(event)) {
148
+ if (editor.tf.moveLine({ reverse: false })) {
149
+ event.preventDefault();
150
+ event.stopPropagation();
151
+ }
152
+ } else if (Hotkeys.isTab(editor, event) || Hotkeys.isUntab(editor, event)) {
153
+ if (editor.tf.tab({ reverse: Hotkeys.isUntab(editor, event) })) {
154
+ event.preventDefault();
155
+ event.stopPropagation();
156
+ }
157
+ } else if (Hotkeys.isSelectAll(event)) {
158
+ if (editor.tf.selectAll()) {
159
+ event.preventDefault();
160
+ event.stopPropagation();
161
+ }
162
+ } else if (Hotkeys.isEscape(event) && editor.tf.escape()) {
163
+ event.preventDefault();
164
+ event.stopPropagation();
165
+ }
166
+ } } }).extendEditorApi(({ editor }) => ({ redecorate: () => {
167
+ editor.api.debug.warn("The method editor.api.redecorate() has not been overridden. This may cause unexpected behavior. Please ensure that all required editor methods are properly defined.", "OVERRIDE_MISSING");
168
+ } })).extendEditorTransforms(({ editor, tf: { reset } }) => ({ reset(options) {
169
+ const isFocused = editor.api.isFocused();
170
+ reset(options);
171
+ if (isFocused) editor.tf.focus({ edge: "startEditor" });
172
+ } })).overrideEditor(({ editor, tf: { normalizeNode } }) => ({ transforms: { normalizeNode(entry, options) {
173
+ if (isDefined(entry[0]._memo)) {
174
+ editor.tf.unsetNodes("_memo", { at: entry[1] });
175
+ return;
176
+ }
177
+ normalizeNode(entry, options);
178
+ } } }));
179
+
180
+ //#endregion
181
+ //#region src/react/plugins/event-editor/EventEditorStore.ts
182
+ /** Store where the keys are event names and the values are editor ids. */
183
+ const EventEditorStore = createZustandStore$1({
184
+ blur: null,
185
+ focus: null,
186
+ last: null
187
+ }, {
188
+ mutative: true,
189
+ name: "event-editor"
190
+ });
191
+ const { useValue: useEventEditorValue } = EventEditorStore;
192
+
193
+ //#endregion
194
+ //#region src/react/plugins/event-editor/useFocusEditorEvents.ts
195
+ const FOCUS_EDITOR_EVENT = "focus-editor-event";
196
+ const BLUR_EDITOR_EVENT = "blur-editor-event";
197
+ const useFocusEditorEvents = (t0) => {
198
+ const $ = c(5);
199
+ const { editorRef, onEditorBlur, onEditorFocus } = t0;
200
+ let t1;
201
+ let t2;
202
+ if ($[0] !== editorRef || $[1] !== onEditorBlur || $[2] !== onEditorFocus) {
203
+ t1 = () => {
204
+ const onFocusEditor = (event) => {
205
+ const id = event.detail.id;
206
+ if (!!onEditorFocus && editorRef && editorRef.id === id) onEditorFocus();
207
+ };
208
+ const onBlurEditor = (event_0) => {
209
+ const id_0 = event_0.detail.id;
210
+ if (!!onEditorBlur && editorRef && editorRef.id === id_0) onEditorBlur();
211
+ };
212
+ document.addEventListener(FOCUS_EDITOR_EVENT, onFocusEditor);
213
+ document.addEventListener(BLUR_EDITOR_EVENT, onBlurEditor);
214
+ return () => {
215
+ document.removeEventListener(FOCUS_EDITOR_EVENT, onFocusEditor);
216
+ document.removeEventListener(BLUR_EDITOR_EVENT, onBlurEditor);
217
+ };
218
+ };
219
+ t2 = [
220
+ editorRef,
221
+ onEditorBlur,
222
+ onEditorFocus
223
+ ];
224
+ $[0] = editorRef;
225
+ $[1] = onEditorBlur;
226
+ $[2] = onEditorFocus;
227
+ $[3] = t1;
228
+ $[4] = t2;
229
+ } else {
230
+ t1 = $[3];
231
+ t2 = $[4];
232
+ }
233
+ useEffect(t1, t2);
234
+ };
235
+
236
+ //#endregion
237
+ //#region src/react/plugins/event-editor/EventEditorPlugin.ts
238
+ const EventEditorPlugin = createPlatePlugin({
239
+ key: "eventEditor",
240
+ handlers: {
241
+ onBlur: ({ editor }) => {
242
+ if (EventEditorStore.get("focus") === editor.id) EventEditorStore.set("focus", null);
243
+ EventEditorStore.set("blur", editor.id);
244
+ document.dispatchEvent(new CustomEvent(BLUR_EDITOR_EVENT, { detail: { id: editor.id } }));
245
+ },
246
+ onFocus: ({ editor }) => {
247
+ EventEditorStore.set("focus", editor.id);
248
+ EventEditorStore.set("last", editor.id);
249
+ document.dispatchEvent(new CustomEvent(FOCUS_EDITOR_EVENT, { detail: { id: editor.id } }));
250
+ }
251
+ }
252
+ });
253
+
254
+ //#endregion
255
+ //#region src/react/plugins/event-editor/getEventPlateId.ts
256
+ const getEventPlateId = (id) => {
257
+ if (id) return id;
258
+ const focus = EventEditorStore.get("focus");
259
+ if (focus) return focus;
260
+ const blur = EventEditorStore.get("blur");
261
+ if (blur) return blur;
262
+ return EventEditorStore.get("last") ?? "plate";
263
+ };
264
+
265
+ //#endregion
266
+ //#region src/react/plugins/event-editor/useFocusedLast.ts
267
+ /** Whether the current editor is the last focused editor. */
268
+ const useFocusedLast = (id) => {
269
+ return (id ?? useEditorId()) === useEventEditorValue("last");
270
+ };
271
+
272
+ //#endregion
273
+ //#region src/react/plugins/paragraph/ParagraphPlugin.tsx
274
+ const ParagraphPlugin = toPlatePlugin(BaseParagraphPlugin, ({ editor, type }) => ({ shortcuts: { toggleParagraph: {
275
+ keys: [[
276
+ Key.Mod,
277
+ Key.Alt,
278
+ "0"
279
+ ], [
280
+ Key.Mod,
281
+ Key.Shift,
282
+ "0"
283
+ ]],
284
+ preventDefault: true,
285
+ handler: () => {
286
+ editor.tf.toggleBlock(type);
287
+ }
288
+ } } }));
289
+
290
+ //#endregion
291
+ //#region src/react/plugins/react/withPlateReact.ts
292
+ const withPlateReact = ({ editor }) => withReact(editor);
293
+
294
+ //#endregion
295
+ //#region src/react/plugins/react/ReactPlugin.ts
296
+ /** @see {@link withReact} */
297
+ const ReactPlugin = toPlatePlugin(DOMPlugin, {
298
+ key: "dom",
299
+ extendEditor: withPlateReact
300
+ });
301
+
302
+ //#endregion
303
+ //#region src/react/editor/getPlateCorePlugins.ts
304
+ const getPlateCorePlugins = () => [
305
+ SlateReactExtensionPlugin,
306
+ ReactPlugin,
307
+ EventEditorPlugin,
308
+ ParagraphPlugin
309
+ ];
310
+
311
+ //#endregion
312
+ //#region src/react/editor/withPlate.ts
313
+ /**
314
+ * Applies Plate enhancements to an editor instance (React version).
315
+ *
316
+ * @remarks
317
+ * This function supports React-specific features including component rendering,
318
+ * event handlers, and React hooks integration.
319
+ * @see {@link createPlateEditor} for a higher-level React editor creation function.
320
+ * @see {@link usePlateEditor} for a memoized version in React components.
321
+ * @see {@link withSlate} for the non-React version of editor enhancement.
322
+ */
323
+ const withPlate = (e, options = {}) => {
324
+ const { optionsStoreFactory, plugins = [], ...rest } = options;
325
+ return withSlate(e, {
326
+ ...rest,
327
+ optionsStoreFactory: optionsStoreFactory ?? createZustandStore,
328
+ plugins: [...getPlateCorePlugins(), ...plugins]
329
+ });
330
+ };
331
+ /**
332
+ * Creates a Plate editor (React version).
333
+ *
334
+ * This function creates a fully configured Plate editor instance with
335
+ * React-specific enhancements including component rendering, event handlers,
336
+ * and hooks integration. It applies all specified plugins and configurations to
337
+ * create a functional editor.
338
+ *
339
+ * Examples:
340
+ *
341
+ * ```ts
342
+ * const editor = createPlateEditor({
343
+ * plugins: [ParagraphPlugin, HeadingPlugin],
344
+ * value: [{ type: 'p', children: [{ text: 'Hello world!' }] }],
345
+ * });
346
+ *
347
+ * // Editor with custom components
348
+ * const editor = createPlateEditor({
349
+ * plugins: [ParagraphPlugin.withComponent(ParagraphElement)],
350
+ * components: { [CodePlugin.key]: CodeLeaf },
351
+ * });
352
+ *
353
+ * // Editor with React-specific options
354
+ * const editor = createPlateEditor({
355
+ * plugins: [ParagraphPlugin],
356
+ * handlers: { onKeyDown: customKeyHandler },
357
+ * });
358
+ * ```
359
+ *
360
+ * @see {@link createSlateEditor} for a non-React version of editor creation.
361
+ * @see {@link usePlateEditor} for a memoized version in React components.
362
+ * @see {@link withPlate} for the underlying function that applies Plate enhancements to an editor.
363
+ */
364
+ const createPlateEditor = ({ editor = createEditor(), ...options } = {}) => withPlate(editor, options);
365
+
366
+ //#endregion
367
+ //#region src/react/utils/createPlateFallbackEditor.ts
368
+ const createPlateFallbackEditor = (options = {}) => {
369
+ const editor = createPlateEditor(options);
370
+ editor.meta.isFallback = true;
371
+ editor.apply = () => {
372
+ throw new Error("Cannot apply operations on the fallback editor. The fallback editor is used when a hook that depends on the Plate store was unable to locate a valid store. If you are using PlateController, use `useEditorMounted(id?: string)` or `!editor.meta.isFallback` to ensure that a valid Plate store is available before attempting to call operations on the editor.");
373
+ };
374
+ return editor;
375
+ };
376
+
377
+ //#endregion
378
+ //#region src/react/utils/dom-attributes.ts
379
+ const DOM_HANDLERS = [
380
+ "onCopy",
381
+ "onCopyCapture",
382
+ "onCut",
383
+ "onCutCapture",
384
+ "onPaste",
385
+ "onPasteCapture",
386
+ "onCompositionEnd",
387
+ "onCompositionEndCapture",
388
+ "onCompositionStart",
389
+ "onCompositionStartCapture",
390
+ "onCompositionUpdate",
391
+ "onCompositionUpdateCapture",
392
+ "onFocus",
393
+ "onFocusCapture",
394
+ "onBlur",
395
+ "onBlurCapture",
396
+ "onDOMBeforeInput",
397
+ "onBeforeInput",
398
+ "onBeforeInputCapture",
399
+ "onInput",
400
+ "onInputCapture",
401
+ "onReset",
402
+ "onResetCapture",
403
+ "onSubmit",
404
+ "onSubmitCapture",
405
+ "onInvalid",
406
+ "onInvalidCapture",
407
+ "onLoad",
408
+ "onLoadCapture",
409
+ "onKeyDown",
410
+ "onKeyDownCapture",
411
+ "onKeyPress",
412
+ "onKeyPressCapture",
413
+ "onKeyUp",
414
+ "onKeyUpCapture",
415
+ "onAbort",
416
+ "onAbortCapture",
417
+ "onCanPlay",
418
+ "onCanPlayCapture",
419
+ "onCanPlayThrough",
420
+ "onCanPlayThroughCapture",
421
+ "onDurationChange",
422
+ "onDurationChangeCapture",
423
+ "onEmptied",
424
+ "onEmptiedCapture",
425
+ "onEncrypted",
426
+ "onEncryptedCapture",
427
+ "onEnded",
428
+ "onEndedCapture",
429
+ "onLoadedData",
430
+ "onLoadedDataCapture",
431
+ "onLoadedMetadata",
432
+ "onLoadedMetadataCapture",
433
+ "onLoadStart",
434
+ "onLoadStartCapture",
435
+ "onPause",
436
+ "onPauseCapture",
437
+ "onPlay",
438
+ "onPlayCapture",
439
+ "onPlaying",
440
+ "onPlayingCapture",
441
+ "onProgress",
442
+ "onProgressCapture",
443
+ "onRateChange",
444
+ "onRateChangeCapture",
445
+ "onSeeked",
446
+ "onSeekedCapture",
447
+ "onSeeking",
448
+ "onSeekingCapture",
449
+ "onStalled",
450
+ "onStalledCapture",
451
+ "onSuspend",
452
+ "onSuspendCapture",
453
+ "onTimeUpdate",
454
+ "onTimeUpdateCapture",
455
+ "onVolumeChange",
456
+ "onVolumeChangeCapture",
457
+ "onWaiting",
458
+ "onWaitingCapture",
459
+ "onAuxClick",
460
+ "onAuxClickCapture",
461
+ "onClick",
462
+ "onClickCapture",
463
+ "onContextMenu",
464
+ "onContextMenuCapture",
465
+ "onDoubleClick",
466
+ "onDoubleClickCapture",
467
+ "onDrag",
468
+ "onDragCapture",
469
+ "onDragEnd",
470
+ "onDragEndCapture",
471
+ "onDragEnter",
472
+ "onDragEnterCapture",
473
+ "onDragExit",
474
+ "onDragExitCapture",
475
+ "onDragLeave",
476
+ "onDragLeaveCapture",
477
+ "onDragOver",
478
+ "onDragOverCapture",
479
+ "onDragStart",
480
+ "onDragStartCapture",
481
+ "onDrop",
482
+ "onDropCapture",
483
+ "onMouseDown",
484
+ "onMouseDownCapture",
485
+ "onMouseEnter",
486
+ "onMouseLeave",
487
+ "onMouseMove",
488
+ "onMouseMoveCapture",
489
+ "onMouseOut",
490
+ "onMouseOutCapture",
491
+ "onMouseOver",
492
+ "onMouseOverCapture",
493
+ "onMouseUp",
494
+ "onMouseUpCapture",
495
+ "onSelect",
496
+ "onSelectCapture",
497
+ "onTouchCancel",
498
+ "onTouchCancelCapture",
499
+ "onTouchEnd",
500
+ "onTouchEndCapture",
501
+ "onTouchMove",
502
+ "onTouchMoveCapture",
503
+ "onTouchStart",
504
+ "onTouchStartCapture",
505
+ "onPointerDown",
506
+ "onPointerDownCapture",
507
+ "onPointerMove",
508
+ "onPointerUp",
509
+ "onPointerUpCapture",
510
+ "onPointerCancel",
511
+ "onPointerCancelCapture",
512
+ "onPointerEnter",
513
+ "onPointerLeave",
514
+ "onPointerOver",
515
+ "onPointerOverCapture",
516
+ "onPointerOut",
517
+ "onPointerOutCapture",
518
+ "onGotPointerCapture",
519
+ "onGotPointerCaptureCapture",
520
+ "onLostPointerCapture",
521
+ "onLostPointerCaptureCapture",
522
+ "onScroll",
523
+ "onScrollCapture",
524
+ "onWheel",
525
+ "onWheelCapture",
526
+ "onAnimationStart",
527
+ "onAnimationStartCapture",
528
+ "onAnimationEnd",
529
+ "onAnimationEndCapture",
530
+ "onAnimationIteration",
531
+ "onAnimationIterationCapture",
532
+ "onTransitionEnd",
533
+ "onTransitionEndCapture"
534
+ ];
535
+
536
+ //#endregion
537
+ //#region src/react/utils/getRenderNodeProps.ts
538
+ /**
539
+ * Override node props with plugin props. Allowed properties in
540
+ * `props.element.attributes` are passed into `props.attributes`. Extend the
541
+ * class name with the node type.
542
+ */
543
+ const getRenderNodeProps = ({ attributes: nodeAttributes, disableInjectNodeProps, editor, plugin, props, readOnly }) => {
544
+ let newProps = {
545
+ ...props,
546
+ ...plugin ? getEditorPlugin(editor, plugin) : {
547
+ api: editor.api,
548
+ editor,
549
+ tf: editor.transforms
550
+ }
551
+ };
552
+ const { className } = props;
553
+ const pluginProps = getPluginNodeProps({
554
+ attributes: nodeAttributes,
555
+ plugin,
556
+ props: newProps
557
+ });
558
+ newProps = {
559
+ ...pluginProps,
560
+ attributes: {
561
+ ...pluginProps.attributes,
562
+ className: clsx(getSlateClass(plugin?.node.type), pluginProps.attributes?.className, className) || void 0
563
+ }
564
+ };
565
+ if (!disableInjectNodeProps) newProps = pipeInjectNodeProps(editor, newProps, (node) => editor.api.findPath(node), readOnly);
566
+ if (newProps.attributes?.style && Object.keys(newProps.attributes.style).length === 0) newProps.attributes.style = void 0;
567
+ return newProps;
568
+ };
569
+
570
+ //#endregion
571
+ //#region src/react/utils/pipeHandler.ts
572
+ const convertDomEventToSyntheticEvent = (domEvent) => {
573
+ let propagationStopped = false;
574
+ return {
575
+ ...domEvent,
576
+ bubbles: domEvent.bubbles,
577
+ cancelable: domEvent.cancelable,
578
+ currentTarget: domEvent.currentTarget,
579
+ defaultPrevented: domEvent.defaultPrevented,
580
+ eventPhase: domEvent.eventPhase,
581
+ isTrusted: domEvent.isTrusted,
582
+ nativeEvent: domEvent,
583
+ target: domEvent.target,
584
+ timeStamp: domEvent.timeStamp,
585
+ type: domEvent.type,
586
+ isDefaultPrevented: () => domEvent.defaultPrevented,
587
+ isPropagationStopped: () => propagationStopped,
588
+ persist: () => {
589
+ throw new Error("persist is not implemented for synthetic events created using convertDomEventToSyntheticEvent");
590
+ },
591
+ preventDefault: () => domEvent.preventDefault(),
592
+ stopPropagation: () => {
593
+ propagationStopped = true;
594
+ domEvent.stopPropagation();
595
+ }
596
+ };
597
+ };
598
+ /** Check if an event is overrided by a handler. */
599
+ const isEventHandled = (event, handler) => {
600
+ if (!handler) return false;
601
+ const shouldTreatEventAsHandled = handler(event);
602
+ if (shouldTreatEventAsHandled != null) return shouldTreatEventAsHandled;
603
+ return event.isPropagationStopped();
604
+ };
605
+ /**
606
+ * Generic pipe for handlers.
607
+ *
608
+ * - Get all the plugins handlers by `handlerKey`.
609
+ * - If there is no plugin handler or editable prop handler for this key, return
610
+ * `undefined`.
611
+ * - Return a handler calling all the plugins handlers then the prop handler.
612
+ * - Any handler returning true will stop the next handlers to be called,
613
+ * including slate internal handler.
614
+ */
615
+ const pipeHandler = (editor, { editableProps, handlerKey }) => {
616
+ const propsHandler = editableProps?.[handlerKey];
617
+ const relevantPlugins = editor.meta.pluginList.filter((plugin) => plugin.handlers?.[handlerKey]);
618
+ if (relevantPlugins.length === 0 && !propsHandler) return;
619
+ return (event) => {
620
+ const handledEvent = event instanceof Event ? convertDomEventToSyntheticEvent(event) : event;
621
+ if (relevantPlugins.some((plugin) => {
622
+ if (isEditOnly(editor.dom.readOnly, plugin, "handlers")) return false;
623
+ const pluginHandler = plugin.handlers[handlerKey];
624
+ const shouldTreatEventAsHandled = pluginHandler({
625
+ ...getEditorPlugin(editor, plugin),
626
+ event: handledEvent
627
+ });
628
+ if (shouldTreatEventAsHandled != null) return shouldTreatEventAsHandled;
629
+ return false;
630
+ })) return true;
631
+ return isEventHandled(handledEvent, propsHandler);
632
+ };
633
+ };
634
+
635
+ //#endregion
636
+ //#region src/react/utils/pipeOnChange.ts
637
+ const pipeOnChange = (editor, value) => {
638
+ return editor.meta.pluginCache.handlers.onChange.some((key) => {
639
+ const plugin = getPlugin(editor, { key });
640
+ if (isEditOnly(editor.dom.readOnly, plugin, "handlers")) return false;
641
+ const handler = plugin.handlers.onChange;
642
+ const shouldTreatEventAsHandled = handler({
643
+ ...getEditorPlugin(editor, plugin),
644
+ value
645
+ });
646
+ if (shouldTreatEventAsHandled != null) return shouldTreatEventAsHandled;
647
+ return false;
648
+ });
649
+ };
650
+
651
+ //#endregion
652
+ //#region src/react/components/plate-nodes.tsx
653
+ const useNodeAttributes = (props, ref) => {
654
+ const $ = c(11);
655
+ const t0 = props.attributes;
656
+ let t1;
657
+ if ($[0] !== props.attributes || $[1] !== props.className) {
658
+ t1 = clsx(props.attributes.className, props.className) || void 0;
659
+ $[0] = props.attributes;
660
+ $[1] = props.className;
661
+ $[2] = t1;
662
+ } else t1 = $[2];
663
+ const t2 = useComposedRef(ref, props.attributes.ref);
664
+ const t3 = props.attributes;
665
+ let t4;
666
+ if ($[3] !== props.style || $[4] !== t3.style) {
667
+ t4 = {
668
+ ...t3.style,
669
+ ...props.style
670
+ };
671
+ $[3] = props.style;
672
+ $[4] = t3.style;
673
+ $[5] = t4;
674
+ } else t4 = $[5];
675
+ let t5;
676
+ if ($[6] !== props.attributes || $[7] !== t1 || $[8] !== t2 || $[9] !== t4) {
677
+ t5 = {
678
+ ...t0,
679
+ className: t1,
680
+ ref: t2,
681
+ style: t4
682
+ };
683
+ $[6] = props.attributes;
684
+ $[7] = t1;
685
+ $[8] = t2;
686
+ $[9] = t4;
687
+ $[10] = t5;
688
+ } else t5 = $[10];
689
+ return t5;
690
+ };
691
+ const PlateElement = React.forwardRef(function PlateElement$1(t0, ref) {
692
+ const $ = c(22);
693
+ let children;
694
+ let insetProp;
695
+ let props;
696
+ let t1;
697
+ if ($[0] !== t0) {
698
+ ({as: t1, children, insetProp, ...props} = t0);
699
+ $[0] = t0;
700
+ $[1] = children;
701
+ $[2] = insetProp;
702
+ $[3] = props;
703
+ $[4] = t1;
704
+ } else {
705
+ children = $[1];
706
+ insetProp = $[2];
707
+ props = $[3];
708
+ t1 = $[4];
709
+ }
710
+ const Tag = t1 === void 0 ? "div" : t1;
711
+ const attributes = useNodeAttributes(props, ref);
712
+ const block = useEditorMounted() && !!props.element.id && !!props.editor.api.isBlock(props.element);
713
+ const inset = insetProp ?? props.plugin?.rules.selection?.affinity === "directional";
714
+ let t2;
715
+ if ($[5] !== inset) {
716
+ t2 = inset && /* @__PURE__ */ React.createElement(NonBreakingSpace, null);
717
+ $[5] = inset;
718
+ $[6] = t2;
719
+ } else t2 = $[6];
720
+ const t3 = attributes["data-slate-inline"];
721
+ const t4 = block ? props.element.id : void 0;
722
+ const t5 = attributes?.style;
723
+ let t6;
724
+ if ($[7] !== t5) {
725
+ t6 = {
726
+ position: "relative",
727
+ ...t5
728
+ };
729
+ $[7] = t5;
730
+ $[8] = t6;
731
+ } else t6 = $[8];
732
+ const t7 = t6;
733
+ let t8;
734
+ if ($[9] !== inset) {
735
+ t8 = inset && /* @__PURE__ */ React.createElement(NonBreakingSpace, null);
736
+ $[9] = inset;
737
+ $[10] = t8;
738
+ } else t8 = $[10];
739
+ let t9;
740
+ if ($[11] !== Tag || $[12] !== attributes || $[13] !== children || $[14] !== t3 || $[15] !== t4 || $[16] !== t7 || $[17] !== t8) {
741
+ t9 = /* @__PURE__ */ React.createElement(Tag, {
742
+ "data-slate-node": "element",
743
+ "data-slate-inline": t3,
744
+ "data-block-id": t4,
745
+ ...attributes,
746
+ style: t7
747
+ }, children, t8);
748
+ $[11] = Tag;
749
+ $[12] = attributes;
750
+ $[13] = children;
751
+ $[14] = t3;
752
+ $[15] = t4;
753
+ $[16] = t7;
754
+ $[17] = t8;
755
+ $[18] = t9;
756
+ } else t9 = $[18];
757
+ let t10;
758
+ if ($[19] !== t2 || $[20] !== t9) {
759
+ t10 = /* @__PURE__ */ React.createElement(React.Fragment, null, t2, t9);
760
+ $[19] = t2;
761
+ $[20] = t9;
762
+ $[21] = t10;
763
+ } else t10 = $[21];
764
+ return t10;
765
+ });
766
+ const PlateText = React.forwardRef((t0, ref) => {
767
+ const $ = c(8);
768
+ let children;
769
+ let props;
770
+ let t1;
771
+ if ($[0] !== t0) {
772
+ ({as: t1, children, ...props} = t0);
773
+ $[0] = t0;
774
+ $[1] = children;
775
+ $[2] = props;
776
+ $[3] = t1;
777
+ } else {
778
+ children = $[1];
779
+ props = $[2];
780
+ t1 = $[3];
781
+ }
782
+ const Tag = t1 === void 0 ? "span" : t1;
783
+ const attributes = useNodeAttributes(props, ref);
784
+ let t2;
785
+ if ($[4] !== Tag || $[5] !== attributes || $[6] !== children) {
786
+ t2 = /* @__PURE__ */ React.createElement(Tag, attributes, children);
787
+ $[4] = Tag;
788
+ $[5] = attributes;
789
+ $[6] = children;
790
+ $[7] = t2;
791
+ } else t2 = $[7];
792
+ return t2;
793
+ });
794
+ const NonBreakingSpace = () => {
795
+ const $ = c(2);
796
+ let t0;
797
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
798
+ t0 = {
799
+ fontSize: 0,
800
+ lineHeight: 0
801
+ };
802
+ $[0] = t0;
803
+ } else t0 = $[0];
804
+ let t1;
805
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
806
+ t1 = /* @__PURE__ */ React.createElement("span", {
807
+ style: t0,
808
+ contentEditable: false
809
+ }, String.fromCodePoint(160));
810
+ $[1] = t1;
811
+ } else t1 = $[1];
812
+ return t1;
813
+ };
814
+ const PlateLeaf = React.forwardRef((t0, ref) => {
815
+ const $ = c(15);
816
+ let children;
817
+ let insetProp;
818
+ let props;
819
+ let t1;
820
+ if ($[0] !== t0) {
821
+ ({as: t1, children, inset: insetProp, ...props} = t0);
822
+ $[0] = t0;
823
+ $[1] = children;
824
+ $[2] = insetProp;
825
+ $[3] = props;
826
+ $[4] = t1;
827
+ } else {
828
+ children = $[1];
829
+ insetProp = $[2];
830
+ props = $[3];
831
+ t1 = $[4];
832
+ }
833
+ const Tag = t1 === void 0 ? "span" : t1;
834
+ const attributes = useNodeAttributes(props, ref);
835
+ if (insetProp ?? props.plugin?.rules.selection?.affinity === "hard") {
836
+ let t2$1;
837
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
838
+ t2$1 = /* @__PURE__ */ React.createElement(NonBreakingSpace, null);
839
+ $[5] = t2$1;
840
+ } else t2$1 = $[5];
841
+ let t3;
842
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
843
+ t3 = /* @__PURE__ */ React.createElement(NonBreakingSpace, null);
844
+ $[6] = t3;
845
+ } else t3 = $[6];
846
+ let t4;
847
+ if ($[7] !== Tag || $[8] !== attributes || $[9] !== children) {
848
+ t4 = /* @__PURE__ */ React.createElement(React.Fragment, null, t2$1, /* @__PURE__ */ React.createElement(Tag, attributes, children, t3));
849
+ $[7] = Tag;
850
+ $[8] = attributes;
851
+ $[9] = children;
852
+ $[10] = t4;
853
+ } else t4 = $[10];
854
+ return t4;
855
+ }
856
+ let t2;
857
+ if ($[11] !== Tag || $[12] !== attributes || $[13] !== children) {
858
+ t2 = /* @__PURE__ */ React.createElement(Tag, attributes, children);
859
+ $[11] = Tag;
860
+ $[12] = attributes;
861
+ $[13] = children;
862
+ $[14] = t2;
863
+ } else t2 = $[14];
864
+ return t2;
865
+ });
866
+
867
+ //#endregion
868
+ //#region src/react/utils/pluginRenderLeaf.tsx
869
+ /**
870
+ * Get a `Editable.renderLeaf` handler for `plugin.node.type`. If the type is
871
+ * equals to the slate leaf type, render `plugin.render.node`. Else, return
872
+ * `children`.
873
+ */
874
+ const pluginRenderLeaf = (editor, plugin) => function render(props) {
875
+ const { render: { leaf: leafComponent, node } } = plugin;
876
+ const { children, leaf } = props;
877
+ const readOnly = useReadOnly();
878
+ if (isEditOnly(readOnly, plugin, "render")) return children;
879
+ if (leaf[plugin.node.type]) {
880
+ const Component = leafComponent ?? node;
881
+ const Leaf = Component ?? PlateLeaf;
882
+ const ctxProps = getRenderNodeProps({
883
+ attributes: leaf.attributes,
884
+ editor,
885
+ plugin,
886
+ props,
887
+ readOnly
888
+ });
889
+ const defaultProps = Component ? {} : { as: plugin.render?.as };
890
+ return /* @__PURE__ */ React.createElement(Leaf, {
891
+ ...defaultProps,
892
+ ...ctxProps
893
+ }, children);
894
+ }
895
+ return children;
896
+ };
897
+
898
+ //#endregion
899
+ //#region src/react/utils/pipeRenderLeaf.tsx
900
+ /** @see {@link RenderLeaf} */
901
+ const pipeRenderLeaf = (editor, renderLeafProp) => {
902
+ const renderLeafs = [];
903
+ const leafPropsPlugins = [];
904
+ editor.meta.pluginCache.node.isLeaf.forEach((key) => {
905
+ const plugin = editor.getPlugin({ key });
906
+ if (plugin) renderLeafs.push(pluginRenderLeaf(editor, plugin));
907
+ });
908
+ editor.meta.pluginCache.node.leafProps.forEach((key) => {
909
+ const plugin = editor.getPlugin({ key });
910
+ if (plugin) leafPropsPlugins.push(plugin);
911
+ });
912
+ return function render({ attributes, ...props }) {
913
+ const readOnly = useReadOnly();
914
+ renderLeafs.forEach((renderLeaf) => {
915
+ const newChildren = renderLeaf(props);
916
+ if (newChildren !== void 0) props.children = newChildren;
917
+ });
918
+ leafPropsPlugins.forEach((plugin) => {
919
+ if (props.leaf[plugin.node.type]) {
920
+ const pluginLeafProps = typeof plugin.node.leafProps === "function" ? plugin.node.leafProps(props) : plugin.node.leafProps ?? {};
921
+ if (pluginLeafProps.className) pluginLeafProps.className = clsx$1(props.className, pluginLeafProps.className);
922
+ attributes = {
923
+ ...attributes,
924
+ ...pluginLeafProps
925
+ };
926
+ }
927
+ });
928
+ if (renderLeafProp) return renderLeafProp({
929
+ attributes,
930
+ ...props
931
+ });
932
+ const ctxProps = getRenderNodeProps({
933
+ editor,
934
+ props: {
935
+ attributes,
936
+ ...props
937
+ },
938
+ readOnly
939
+ });
940
+ return /* @__PURE__ */ React.createElement(PlateLeaf, ctxProps, props.children);
941
+ };
942
+ };
943
+
944
+ //#endregion
945
+ //#region src/react/utils/pluginRenderText.tsx
946
+ /**
947
+ * Get a `Editable.renderText` handler for `plugin.node.type`. If the type is
948
+ * equals to the slate text type and isDecoration is false, render
949
+ * `plugin.render.node`. Else, return the default text rendering.
950
+ */
951
+ const pluginRenderText = (editor, plugin) => function render(nodeProps) {
952
+ const { render: { node } } = plugin;
953
+ const { children, text } = nodeProps;
954
+ const readOnly = useReadOnly();
955
+ if (isEditOnly(readOnly, plugin, "render")) return children;
956
+ if (text[plugin.node.type ?? plugin.key]) {
957
+ const Text = node ?? PlateText;
958
+ const ctxProps = getRenderNodeProps({
959
+ attributes: nodeProps.attributes,
960
+ editor,
961
+ plugin,
962
+ props: nodeProps,
963
+ readOnly
964
+ });
965
+ const defaultProps = node ? {} : { as: plugin.render?.as };
966
+ return /* @__PURE__ */ React.createElement(Text, {
967
+ ...defaultProps,
968
+ ...ctxProps
969
+ }, children);
970
+ }
971
+ return children;
972
+ };
973
+
974
+ //#endregion
975
+ //#region src/react/utils/pipeRenderText.tsx
976
+ /** @see {@link RenderText} */
977
+ const pipeRenderText = (editor, renderTextProp) => {
978
+ const renderTexts = [];
979
+ const textPropsPlugins = [];
980
+ editor.meta.pluginList.forEach((plugin) => {
981
+ if (plugin.node.isLeaf && plugin.node.isDecoration === false) renderTexts.push(pluginRenderText(editor, plugin));
982
+ if (plugin.node.textProps) textPropsPlugins.push(plugin);
983
+ });
984
+ return function render({ attributes, ...props }) {
985
+ const readOnly = useReadOnly();
986
+ renderTexts.forEach((renderText) => {
987
+ const newChildren = renderText(props);
988
+ if (newChildren !== void 0) props.children = newChildren;
989
+ });
990
+ textPropsPlugins.forEach((plugin) => {
991
+ if (props.text[plugin.node.type ?? plugin.key]) {
992
+ const pluginTextProps = typeof plugin.node.textProps === "function" ? plugin.node.textProps(props) : plugin.node.textProps ?? {};
993
+ if (pluginTextProps.className) pluginTextProps.className = clsx$1(props.className, pluginTextProps.className);
994
+ attributes = {
995
+ ...attributes,
996
+ ...pluginTextProps
997
+ };
998
+ }
999
+ });
1000
+ if (renderTextProp) return renderTextProp({
1001
+ attributes,
1002
+ ...props
1003
+ });
1004
+ const ctxProps = getRenderNodeProps({
1005
+ editor,
1006
+ props: {
1007
+ attributes,
1008
+ ...props
1009
+ },
1010
+ readOnly
1011
+ });
1012
+ return /* @__PURE__ */ React.createElement(PlateText, ctxProps, props.children);
1013
+ };
1014
+ };
1015
+
1016
+ //#endregion
1017
+ //#region src/react/hooks/useEditableProps.ts
1018
+ const useEditableProps = ({ disabled, readOnly, ...editableProps } = {}) => {
1019
+ const { id } = editableProps;
1020
+ const editor = useEditorRef(id);
1021
+ const store = usePlateStore(id);
1022
+ const versionDecorate = useAtomStoreValue(store, "versionDecorate");
1023
+ const storeDecorate = useAtomStoreValue(store, "decorate");
1024
+ const storeRenderChunk = useAtomStoreValue(store, "renderChunk");
1025
+ const storeRenderElement = useAtomStoreValue(store, "renderElement");
1026
+ const storeRenderLeaf = useAtomStoreValue(store, "renderLeaf");
1027
+ const storeRenderText = useAtomStoreValue(store, "renderText");
1028
+ const decorateMemo = React.useMemo(() => pipeDecorate(editor, storeDecorate ?? editableProps?.decorate), [
1029
+ editableProps?.decorate,
1030
+ editor,
1031
+ storeDecorate
1032
+ ]);
1033
+ const decorate = React.useMemo(() => {
1034
+ if (!versionDecorate || !decorateMemo) return;
1035
+ return (entry) => decorateMemo(entry);
1036
+ }, [decorateMemo, versionDecorate]);
1037
+ const defaultRenderChunk = usePluginOption(ChunkingPlugin, "contentVisibilityAuto") ? ContentVisibilityChunk : void 0;
1038
+ const renderChunk = storeRenderChunk ?? editableProps?.renderChunk ?? defaultRenderChunk;
1039
+ const renderElement = React.useMemo(() => pipeRenderElement(editor, storeRenderElement ?? editableProps?.renderElement), [
1040
+ editableProps?.renderElement,
1041
+ editor,
1042
+ storeRenderElement
1043
+ ]);
1044
+ const renderLeaf = React.useMemo(() => pipeRenderLeaf(editor, storeRenderLeaf ?? editableProps?.renderLeaf), [
1045
+ editableProps?.renderLeaf,
1046
+ editor,
1047
+ storeRenderLeaf
1048
+ ]);
1049
+ const renderText = React.useMemo(() => pipeRenderText(editor, storeRenderText ?? editableProps?.renderText), [
1050
+ editableProps?.renderText,
1051
+ editor,
1052
+ storeRenderText
1053
+ ]);
1054
+ const props = useDeepCompareMemo(() => {
1055
+ const _props = {
1056
+ decorate,
1057
+ renderChunk,
1058
+ renderElement,
1059
+ renderLeaf,
1060
+ renderText
1061
+ };
1062
+ DOM_HANDLERS.forEach((handlerKey) => {
1063
+ const handler = pipeHandler(editor, {
1064
+ editableProps,
1065
+ handlerKey
1066
+ });
1067
+ if (handler) _props[handlerKey] = handler;
1068
+ });
1069
+ return _props;
1070
+ }, [
1071
+ decorate,
1072
+ editableProps,
1073
+ renderChunk,
1074
+ renderElement,
1075
+ renderLeaf,
1076
+ renderText
1077
+ ]);
1078
+ return useDeepCompareMemo(() => ({
1079
+ ...omit(editableProps, [
1080
+ ...DOM_HANDLERS,
1081
+ "renderChunk",
1082
+ "renderElement",
1083
+ "renderLeaf",
1084
+ "renderText",
1085
+ "decorate"
1086
+ ]),
1087
+ ...props,
1088
+ "aria-disabled": disabled,
1089
+ className: clsx$1("slate-editor", "ignore-click-outside/toolbar", editableProps.className),
1090
+ "data-readonly": readOnly ? "true" : void 0,
1091
+ readOnly
1092
+ }), [
1093
+ editableProps,
1094
+ props,
1095
+ readOnly
1096
+ ]);
1097
+ };
1098
+
1099
+ //#endregion
1100
+ //#region src/react/hooks/useNodePath.ts
1101
+ /**
1102
+ * Returns the path of a node every time the node changes. Note, however, that
1103
+ * if another node is updated in a way that affects this node's path, this hook
1104
+ * will not return the new path.
1105
+ */
1106
+ const useNodePath = (node) => {
1107
+ const $ = c(6);
1108
+ const editor = useEditorRef();
1109
+ let t0;
1110
+ if ($[0] !== editor.api || $[1] !== node) {
1111
+ t0 = () => editor.api.findPath(node);
1112
+ $[0] = editor.api;
1113
+ $[1] = node;
1114
+ $[2] = t0;
1115
+ } else t0 = $[2];
1116
+ let t1;
1117
+ if ($[3] !== editor || $[4] !== node) {
1118
+ t1 = [editor, node];
1119
+ $[3] = editor;
1120
+ $[4] = node;
1121
+ $[5] = t1;
1122
+ } else t1 = $[5];
1123
+ return useMemoizedSelector(t0, t1, _temp);
1124
+ };
1125
+ function _temp(a, b) {
1126
+ return !!a && !!b && PathApi.equals(a, b);
1127
+ }
1128
+
1129
+ //#endregion
1130
+ //#region src/react/hooks/useSlateProps.ts
1131
+ /** Get Slate props stored in a global store. */
1132
+ const useSlateProps = (t0) => {
1133
+ const $ = c(19);
1134
+ const { id } = t0;
1135
+ const editor = useEditorRef(id);
1136
+ const store = usePlateStore(id);
1137
+ const onChangeProp = useAtomStoreValue(store, "onChange");
1138
+ const onValueChangeProp = useAtomStoreValue(store, "onValueChange");
1139
+ const onSelectionChangeProp = useAtomStoreValue(store, "onSelectionChange");
1140
+ const updateVersionEditor = useIncrementVersion("versionEditor", id);
1141
+ const updateVersionSelection = useIncrementVersion("versionSelection", id);
1142
+ const updateVersionValue = useIncrementVersion("versionValue", id);
1143
+ let t1;
1144
+ if ($[0] !== editor || $[1] !== onChangeProp || $[2] !== updateVersionEditor) {
1145
+ t1 = (newValue) => {
1146
+ updateVersionEditor();
1147
+ if (!pipeOnChange(editor, newValue)) onChangeProp?.({
1148
+ editor,
1149
+ value: newValue
1150
+ });
1151
+ };
1152
+ $[0] = editor;
1153
+ $[1] = onChangeProp;
1154
+ $[2] = updateVersionEditor;
1155
+ $[3] = t1;
1156
+ } else t1 = $[3];
1157
+ const onChange = t1;
1158
+ let t2;
1159
+ if ($[4] !== editor || $[5] !== onValueChangeProp || $[6] !== updateVersionValue) {
1160
+ t2 = (value) => {
1161
+ updateVersionValue();
1162
+ onValueChangeProp?.({
1163
+ editor,
1164
+ value
1165
+ });
1166
+ };
1167
+ $[4] = editor;
1168
+ $[5] = onValueChangeProp;
1169
+ $[6] = updateVersionValue;
1170
+ $[7] = t2;
1171
+ } else t2 = $[7];
1172
+ const onValueChange = t2;
1173
+ let t3;
1174
+ if ($[8] !== editor || $[9] !== onSelectionChangeProp || $[10] !== updateVersionSelection) {
1175
+ t3 = (selection) => {
1176
+ updateVersionSelection();
1177
+ onSelectionChangeProp?.({
1178
+ editor,
1179
+ selection
1180
+ });
1181
+ };
1182
+ $[8] = editor;
1183
+ $[9] = onSelectionChangeProp;
1184
+ $[10] = updateVersionSelection;
1185
+ $[11] = t3;
1186
+ } else t3 = $[11];
1187
+ const onSelectionChange = t3;
1188
+ const t4 = editor;
1189
+ const t5 = editor.children;
1190
+ let t6;
1191
+ if ($[12] !== editor.meta.key || $[13] !== onChange || $[14] !== onSelectionChange || $[15] !== onValueChange || $[16] !== t4 || $[17] !== t5) {
1192
+ t6 = {
1193
+ key: editor.meta.key,
1194
+ editor: t4,
1195
+ initialValue: t5,
1196
+ onChange,
1197
+ onSelectionChange,
1198
+ onValueChange
1199
+ };
1200
+ $[12] = editor.meta.key;
1201
+ $[13] = onChange;
1202
+ $[14] = onSelectionChange;
1203
+ $[15] = onValueChange;
1204
+ $[16] = t4;
1205
+ $[17] = t5;
1206
+ $[18] = t6;
1207
+ } else t6 = $[18];
1208
+ return t6;
1209
+ };
1210
+
1211
+ //#endregion
1212
+ //#region src/react/stores/element/usePath.ts
1213
+ /** Get the memoized path of the closest element. */
1214
+ const usePath = (pluginKey) => {
1215
+ const editor = useEditorRef();
1216
+ const value = useAtomStoreValue(useElementStore(pluginKey), "path");
1217
+ if (!value) {
1218
+ editor.api.debug.warn(`usePath(${pluginKey}) hook must be used inside the node component's context`, "USE_ELEMENT_CONTEXT");
1219
+ return;
1220
+ }
1221
+ return value;
1222
+ };
1223
+
1224
+ //#endregion
1225
+ //#region src/react/stores/element/useElementStore.tsx
1226
+ const SCOPE_ELEMENT = "element";
1227
+ const initialState = {
1228
+ element: null,
1229
+ entry: null,
1230
+ path: null
1231
+ };
1232
+ const { ElementProvider, elementStore, useElementStore } = createAtomStore(initialState, {
1233
+ effect: Effect,
1234
+ name: "element",
1235
+ suppressWarnings: true
1236
+ });
1237
+ function Effect() {
1238
+ const $ = c(1);
1239
+ const path = usePath();
1240
+ if (path && PathApi.equals(path, [0])) {
1241
+ let t0;
1242
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1243
+ t0 = /* @__PURE__ */ React.createElement(FirstBlockEffect, null);
1244
+ $[0] = t0;
1245
+ } else t0 = $[0];
1246
+ return t0;
1247
+ }
1248
+ return null;
1249
+ }
1250
+ function FirstBlockEffect() {
1251
+ const editor = useEditorRef();
1252
+ const store = usePlateStore();
1253
+ const composing = useComposing();
1254
+ const readOnly = useReadOnly();
1255
+ editor.dom.readOnly = readOnly;
1256
+ editor.dom.composing = composing;
1257
+ React.useLayoutEffect(() => {
1258
+ store.set("composing", composing);
1259
+ }, [composing, store]);
1260
+ return null;
1261
+ }
1262
+
1263
+ //#endregion
1264
+ //#region src/react/utils/pluginRenderElement.tsx
1265
+ function ElementContent(t0) {
1266
+ const $ = c(3);
1267
+ const { editor, plugin, ...t1 } = t0;
1268
+ let props = t1;
1269
+ const element = useElement();
1270
+ const readOnly = useReadOnly();
1271
+ if (isEditOnly(readOnly, plugin, "render")) return null;
1272
+ const { children: _children } = props;
1273
+ const Component = plugin.render?.node;
1274
+ const Element = Component ?? PlateElement;
1275
+ props = getRenderNodeProps({
1276
+ attributes: element.attributes,
1277
+ editor,
1278
+ plugin,
1279
+ props,
1280
+ readOnly
1281
+ });
1282
+ let children = _children;
1283
+ editor.meta.pluginCache.render.belowNodes.forEach((key) => {
1284
+ const plugin_0 = editor.getPlugin({ key });
1285
+ const withHOC$1 = plugin_0.render.belowNodes;
1286
+ const hoc = withHOC$1({
1287
+ ...props,
1288
+ key
1289
+ });
1290
+ if (hoc && !isEditOnly(readOnly, plugin_0, "render")) children = hoc({
1291
+ ...props,
1292
+ children
1293
+ });
1294
+ });
1295
+ let t2;
1296
+ if ($[0] !== Component || $[1] !== plugin.render?.as) {
1297
+ t2 = Component ? {} : { as: plugin.render?.as };
1298
+ $[0] = Component;
1299
+ $[1] = plugin.render?.as;
1300
+ $[2] = t2;
1301
+ } else t2 = $[2];
1302
+ const defaultProps = t2;
1303
+ let component = /* @__PURE__ */ React.createElement(Element, {
1304
+ ...defaultProps,
1305
+ ...props
1306
+ }, children, /* @__PURE__ */ React.createElement(BelowRootNodes, {
1307
+ ...defaultProps,
1308
+ ...props
1309
+ }));
1310
+ editor.meta.pluginCache.render.aboveNodes.forEach((key_0) => {
1311
+ const plugin_1 = editor.getPlugin({ key: key_0 });
1312
+ const withHOC_0 = plugin_1.render.aboveNodes;
1313
+ const hoc_0 = withHOC_0({
1314
+ ...props,
1315
+ key: key_0
1316
+ });
1317
+ if (hoc_0 && !isEditOnly(readOnly, plugin_1, "render")) component = hoc_0({
1318
+ ...props,
1319
+ children: component
1320
+ });
1321
+ });
1322
+ return component;
1323
+ }
1324
+ function BelowRootNodes(props) {
1325
+ const $ = c(6);
1326
+ const editor = useEditorRef();
1327
+ const readOnly = useReadOnly();
1328
+ let t0;
1329
+ if ($[0] !== editor || $[1] !== props || $[2] !== readOnly) {
1330
+ t0 = editor.meta.pluginCache.render.belowRootNodes.map((key) => {
1331
+ const plugin = editor.getPlugin({ key });
1332
+ if (isEditOnly(readOnly, plugin, "render")) return null;
1333
+ const Component = plugin.render.belowRootNodes;
1334
+ return /* @__PURE__ */ React.createElement(Component, {
1335
+ key,
1336
+ ...props
1337
+ });
1338
+ });
1339
+ $[0] = editor;
1340
+ $[1] = props;
1341
+ $[2] = readOnly;
1342
+ $[3] = t0;
1343
+ } else t0 = $[3];
1344
+ let t1;
1345
+ if ($[4] !== t0) {
1346
+ t1 = /* @__PURE__ */ React.createElement(React.Fragment, null, t0);
1347
+ $[4] = t0;
1348
+ $[5] = t1;
1349
+ } else t1 = $[5];
1350
+ return t1;
1351
+ }
1352
+ /**
1353
+ * Get a `Editable.renderElement` handler for `plugin.node.type`. If the type is
1354
+ * equals to the slate element type, render `plugin.render.node`. Else, return
1355
+ * `undefined` so the pipeline can check the next plugin.
1356
+ */
1357
+ const pluginRenderElement = (editor, plugin) => function render(props) {
1358
+ const { element, path } = props;
1359
+ return /* @__PURE__ */ React.createElement(ElementProvider, {
1360
+ element,
1361
+ entry: [element, path],
1362
+ path,
1363
+ scope: plugin.key
1364
+ }, /* @__PURE__ */ React.createElement(ElementContent, {
1365
+ editor,
1366
+ plugin,
1367
+ ...props
1368
+ }));
1369
+ };
1370
+
1371
+ //#endregion
1372
+ //#region src/react/utils/pipeRenderElement.tsx
1373
+ /** @see {@link RenderElement} */
1374
+ const pipeRenderElement = (editor, renderElementProp) => {
1375
+ return function render(props) {
1376
+ const readOnly = useReadOnly();
1377
+ const path = useNodePath(props.element);
1378
+ const plugin = getPluginByType(editor, props.element.type);
1379
+ if (plugin?.node.isElement) return pluginRenderElement(editor, plugin)({
1380
+ ...props,
1381
+ path
1382
+ });
1383
+ if (renderElementProp) return renderElementProp({
1384
+ ...props,
1385
+ path
1386
+ });
1387
+ const ctxProps = getRenderNodeProps({
1388
+ disableInjectNodeProps: true,
1389
+ editor,
1390
+ props: {
1391
+ ...props,
1392
+ path
1393
+ },
1394
+ readOnly
1395
+ });
1396
+ return /* @__PURE__ */ React.createElement(ElementProvider, {
1397
+ element: ctxProps.element,
1398
+ entry: [ctxProps.element, path],
1399
+ path,
1400
+ scope: ctxProps.element.type ?? "default"
1401
+ }, /* @__PURE__ */ React.createElement(PlateElement, ctxProps, props.children, /* @__PURE__ */ React.createElement(BelowRootNodes, ctxProps)));
1402
+ };
1403
+ };
1404
+
1405
+ //#endregion
1406
+ //#region src/react/stores/plate-controller/plateControllerStore.ts
1407
+ const { PlateControllerProvider: PlateController, plateControllerStore, usePlateControllerStore: _usePlateControllerStore } = createAtomStore({
1408
+ activeId: atom$1(null),
1409
+ editorStores: atom$1({}),
1410
+ primaryEditorIds: atom$1([])
1411
+ }, { name: "plateController" });
1412
+ const usePlateControllerLocalStore = (options) => _usePlateControllerStore({
1413
+ scope: typeof options === "string" ? options : void 0,
1414
+ warnIfNoStore: false,
1415
+ ...typeof options === "object" ? options : {}
1416
+ });
1417
+ const usePlateControllerExists = () => {
1418
+ return !!usePlateControllerLocalStore().store;
1419
+ };
1420
+ /**
1421
+ * Retrieve from PlateController the JotaiStore for the editor with a given ID,
1422
+ * or the active editor if no ID is provided, or the first primary editor if no
1423
+ * editor is active, or null.
1424
+ */
1425
+ const usePlateControllerStore = (idProp) => {
1426
+ const $ = c(2);
1427
+ let t0;
1428
+ if ($[0] !== idProp) {
1429
+ t0 = atom$1((get) => {
1430
+ const editorStores = get(plateControllerStore.atom.editorStores);
1431
+ const forId = (id) => {
1432
+ if (!id) return null;
1433
+ return editorStores[id] ?? null;
1434
+ };
1435
+ if (idProp) return forId(idProp);
1436
+ const lookupOrder = [get(plateControllerStore.atom.activeId), ...get(plateControllerStore.atom.primaryEditorIds)];
1437
+ for (const id_0 of lookupOrder) {
1438
+ const store = forId(id_0);
1439
+ if (store) return store;
1440
+ }
1441
+ return null;
1442
+ });
1443
+ $[0] = idProp;
1444
+ $[1] = t0;
1445
+ } else t0 = $[1];
1446
+ const storeAtom = t0;
1447
+ return useStoreAtomValue(usePlateControllerLocalStore(), storeAtom);
1448
+ };
1449
+
1450
+ //#endregion
1451
+ //#region src/react/stores/plate/createPlateStore.ts
1452
+ const PLATE_SCOPE = "plate";
1453
+ const GLOBAL_PLATE_SCOPE = Symbol("global-plate");
1454
+ const createPlateStore = ({ id, composing = false, containerRef = { current: null }, decorate = null, editor, isMounted = false, primary = true, readOnly = null, renderChunk = null, renderElement = null, renderLeaf = null, renderText = null, scrollRef = { current: null }, versionDecorate = 1, versionEditor = 1, versionSelection = 1, versionValue = 1, onChange = null, onNodeChange = null, onSelectionChange = null, onTextChange = null, onValueChange = null, ...state } = {}) => createAtomStore({
1455
+ composing,
1456
+ containerRef,
1457
+ decorate,
1458
+ editor,
1459
+ isMounted,
1460
+ primary,
1461
+ readOnly,
1462
+ renderChunk,
1463
+ renderElement,
1464
+ renderLeaf,
1465
+ renderText,
1466
+ scrollRef,
1467
+ versionDecorate,
1468
+ versionEditor,
1469
+ versionSelection,
1470
+ versionValue,
1471
+ onChange,
1472
+ onNodeChange,
1473
+ onSelectionChange,
1474
+ onTextChange,
1475
+ onValueChange,
1476
+ ...state
1477
+ }, {
1478
+ name: "plate",
1479
+ suppressWarnings: true,
1480
+ extend: (atoms) => ({
1481
+ trackedEditor: atom$1((get) => ({
1482
+ editor: get(atoms.editor),
1483
+ version: get(atoms.versionEditor)
1484
+ })),
1485
+ trackedSelection: atom$1((get) => ({
1486
+ selection: get(atoms.editor).selection,
1487
+ version: get(atoms.versionSelection)
1488
+ })),
1489
+ trackedValue: atom$1((get) => ({
1490
+ value: get(atoms.editor).children,
1491
+ version: get(atoms.versionValue)
1492
+ }))
1493
+ })
1494
+ });
1495
+ const { PlateProvider: PlateStoreProvider, plateStore, usePlateSet: usePlateLocalSet, usePlateState: usePlateLocalState, usePlateStore: usePlateLocalStore, usePlateValue: usePlateLocalValue } = createPlateStore();
1496
+ const { usePlateStore: useFallbackPlateStore } = createPlateStore();
1497
+ const usePlateStore = (id) => {
1498
+ const localStore = usePlateLocalStore({
1499
+ scope: id,
1500
+ warnIfNoStore: false
1501
+ }) ?? null;
1502
+ const [localStoreExists] = React.useState(!!localStore.store);
1503
+ const store = localStoreExists ? localStore : usePlateControllerStore(id);
1504
+ /**
1505
+ * If we still have no store, there are two possibilities.
1506
+ *
1507
+ * Case 1: There is neither a Plate nor a PlateController above us in the
1508
+ * tree. In this case, throw an error, since calling the hook will never
1509
+ * work.
1510
+ *
1511
+ * Case 2: There is a PlateController, but it has no active editor. In this
1512
+ * case, return a fallback store until an editor becomes active.
1513
+ */
1514
+ const plateControllerExists = usePlateControllerExists();
1515
+ const fallbackStore = useFallbackPlateStore();
1516
+ if (!store) {
1517
+ if (plateControllerExists) return fallbackStore;
1518
+ throw new Error("Plate hooks must be used inside a Plate or PlateController");
1519
+ }
1520
+ return store;
1521
+ };
1522
+ const usePlateSet = (key, options) => {
1523
+ return useAtomStoreSet(usePlateStore(typeof options === "string" ? options : options?.scope), key);
1524
+ };
1525
+ const usePlateValue = ((key, options) => {
1526
+ return useAtomStoreValue(usePlateStore(typeof options === "string" ? options : options?.scope), key);
1527
+ });
1528
+ const usePlateState = ((key, options) => {
1529
+ return useAtomStoreState(usePlateStore(typeof options === "string" ? options : options?.scope), key);
1530
+ });
1531
+ /** Get the closest `Plate` id. */
1532
+ const useEditorId = () => {
1533
+ return useAtomStoreValue(usePlateStore(), "editor").id;
1534
+ };
1535
+ const useEditorContainerRef = (id) => {
1536
+ return useAtomStoreValue(usePlateStore(id), "containerRef");
1537
+ };
1538
+ const useEditorScrollRef = (id) => {
1539
+ return useAtomStoreValue(usePlateStore(id), "scrollRef");
1540
+ };
1541
+ /** Returns the scrollRef if it exists, otherwise returns the containerRef. */
1542
+ const useScrollRef = (id) => {
1543
+ const scrollRef = useEditorScrollRef(id);
1544
+ const containerRef = useEditorContainerRef(id);
1545
+ return scrollRef.current ? scrollRef : containerRef;
1546
+ };
1547
+ const useEditorMounted = (id) => {
1548
+ return !!useAtomStoreValue(usePlateStore(id), "isMounted");
1549
+ };
1550
+ /**
1551
+ * Whether the editor is read-only. You can also use `useReadOnly` from
1552
+ * `slate-react` in node components.
1553
+ */
1554
+ const useEditorReadOnly = (id) => {
1555
+ return !!useAtomStoreValue(usePlateStore(id), "readOnly");
1556
+ };
1557
+ /** Whether the editor is composing. */
1558
+ const useEditorComposing = (id) => {
1559
+ return !!useAtomStoreValue(usePlateStore(id), "composing");
1560
+ };
1561
+ /**
1562
+ * Get a reference to the editor instance that remains stable across re-renders.
1563
+ * The editor object is enhanced with a `store` property that provides access to
1564
+ * the Plate store.
1565
+ *
1566
+ * @example
1567
+ * ```tsx
1568
+ * const editor = useEditorRef();
1569
+ * const readOnly = useAtomStoreValue(editor.store, 'readOnly');
1570
+ */
1571
+ const useEditorRef = (id) => {
1572
+ const store = usePlateStore(id);
1573
+ const editor = useAtomStoreValue(store, "editor") ?? createPlateFallbackEditor();
1574
+ editor.store = store;
1575
+ return editor;
1576
+ };
1577
+ /** Get the editor selection (deeply memoized). */
1578
+ const useEditorSelection = (id) => usePlateStore(id).useTrackedSelectionValue().selection;
1579
+ /** Get editor state which is updated on editor change. */
1580
+ const useEditorState = (id) => usePlateStore(id).useTrackedEditorValue().editor;
1581
+ /** Version incremented on each editor change. */
1582
+ const useEditorVersion = (id) => {
1583
+ return useAtomStoreValue(usePlateStore(id), "versionEditor");
1584
+ };
1585
+ /** Version incremented on selection change. */
1586
+ const useSelectionVersion = (id) => {
1587
+ return useAtomStoreValue(usePlateStore(id), "versionSelection");
1588
+ };
1589
+ /** Get the editor value (deeply memoized). */
1590
+ const useEditorValue = (id) => usePlateStore(id).useTrackedValueValue().value;
1591
+ /** Version incremented on value change. */
1592
+ const useValueVersion = (id) => {
1593
+ return useAtomStoreValue(usePlateStore(id), "versionValue");
1594
+ };
1595
+ const useIncrementVersion = (key, id) => {
1596
+ const $ = c(6);
1597
+ const previousVersionRef = React.useRef(1);
1598
+ const store = usePlateStore(id);
1599
+ const setVersionDecorate = useAtomStoreSet(store, "versionDecorate");
1600
+ const setVersionSelection = useAtomStoreSet(store, "versionSelection");
1601
+ const setVersionValue = useAtomStoreSet(store, "versionValue");
1602
+ const setVersionEditor = useAtomStoreSet(store, "versionEditor");
1603
+ let t0;
1604
+ if ($[0] !== key || $[1] !== setVersionDecorate || $[2] !== setVersionEditor || $[3] !== setVersionSelection || $[4] !== setVersionValue) {
1605
+ t0 = () => {
1606
+ const nextVersion = previousVersionRef.current + 1;
1607
+ bb2: switch (key) {
1608
+ case "versionDecorate":
1609
+ setVersionDecorate(nextVersion);
1610
+ break bb2;
1611
+ case "versionEditor":
1612
+ setVersionEditor(nextVersion);
1613
+ break bb2;
1614
+ case "versionSelection":
1615
+ setVersionSelection(nextVersion);
1616
+ break bb2;
1617
+ case "versionValue": setVersionValue(nextVersion);
1618
+ }
1619
+ previousVersionRef.current = nextVersion;
1620
+ };
1621
+ $[0] = key;
1622
+ $[1] = setVersionDecorate;
1623
+ $[2] = setVersionEditor;
1624
+ $[3] = setVersionSelection;
1625
+ $[4] = setVersionValue;
1626
+ $[5] = t0;
1627
+ } else t0 = $[5];
1628
+ return t0;
1629
+ };
1630
+ const useRedecorate = (id) => {
1631
+ const $ = c(2);
1632
+ const updateDecorate = useIncrementVersion("versionDecorate", id);
1633
+ let t0;
1634
+ if ($[0] !== updateDecorate) {
1635
+ t0 = () => {
1636
+ updateDecorate();
1637
+ };
1638
+ $[0] = updateDecorate;
1639
+ $[1] = t0;
1640
+ } else t0 = $[1];
1641
+ return t0;
1642
+ };
1643
+
1644
+ //#endregion
1645
+ //#region src/react/stores/plate/useEditorPlugin.ts
1646
+ /** Get editor and plugin context. */
1647
+ function useEditorPlugin(p, id) {
1648
+ const $ = c(6);
1649
+ const editor = useEditorRef(id);
1650
+ let t0;
1651
+ if ($[0] !== editor || $[1] !== p) {
1652
+ t0 = getEditorPlugin(editor, p);
1653
+ $[0] = editor;
1654
+ $[1] = p;
1655
+ $[2] = t0;
1656
+ } else t0 = $[2];
1657
+ let t1;
1658
+ if ($[3] !== editor.store || $[4] !== t0) {
1659
+ t1 = {
1660
+ ...t0,
1661
+ store: editor.store
1662
+ };
1663
+ $[3] = editor.store;
1664
+ $[4] = t0;
1665
+ $[5] = t1;
1666
+ } else t1 = $[5];
1667
+ return t1;
1668
+ }
1669
+
1670
+ //#endregion
1671
+ //#region src/react/stores/plate/useEditorSelector.ts
1672
+ const useEditorSelector = (selector, deps, { id, equalityFn = (a, b) => a === b } = {}) => {
1673
+ const selectorAtom = React.useMemo(() => selectAtom(plateStore.atom.trackedEditor, ({ editor }, prev) => selector(editor, prev), equalityFn), deps);
1674
+ return useStoreAtomValue$1(usePlateStore(id), selectorAtom);
1675
+ };
1676
+
1677
+ //#endregion
1678
+ //#region src/react/stores/plate/usePluginOption.ts
1679
+ /**
1680
+ * Hook to access plugin options. For usage outside `<Plate>`, use
1681
+ * `useEditorPluginOption` instead.
1682
+ *
1683
+ * @example
1684
+ * const value = usePluginOption(plugin, 'value');
1685
+ * const doubleValue = usePluginOption(plugin, 'doubleValue', 2);
1686
+ */
1687
+ function usePluginOption(plugin, key, ...args) {
1688
+ return useEditorPluginOption(useEditorRef(), plugin, key, ...args);
1689
+ }
1690
+ function useEditorPluginOption(editor, plugin, key, ...args) {
1691
+ const store = editor.getOptionsStore(plugin);
1692
+ if (!store) return;
1693
+ if (key !== "state" && !(key in store.get("state")) && !(key in store.selectors)) {
1694
+ editor.api.debug.error(`usePluginOption: ${key} option is not defined in plugin ${plugin.key}`, "OPTION_UNDEFINED");
1695
+ return;
1696
+ }
1697
+ if (key === "state") return useStoreSelect$1(store, (state) => state, args[0]);
1698
+ return useStoreValue$1(store, key, ...args);
1699
+ }
1700
+ /**
1701
+ * Use zustand store selector.
1702
+ *
1703
+ * @example
1704
+ * const name = usePluginOptions(plugin, (state) => state.name, equalityFn);
1705
+ */
1706
+ function usePluginOptions(plugin, selector, t0) {
1707
+ const $ = c(4);
1708
+ let t1;
1709
+ if ($[0] !== t0) {
1710
+ t1 = t0 === void 0 ? {} : t0;
1711
+ $[0] = t0;
1712
+ $[1] = t1;
1713
+ } else t1 = $[1];
1714
+ const { id, equalityFn } = t1;
1715
+ const editor = useEditorRef(id);
1716
+ let t2;
1717
+ if ($[2] !== equalityFn) {
1718
+ t2 = { equalityFn };
1719
+ $[2] = equalityFn;
1720
+ $[3] = t2;
1721
+ } else t2 = $[3];
1722
+ return useEditorPluginOptions(editor, plugin, selector, t2);
1723
+ }
1724
+ function useEditorPluginOptions(editor, plugin, selector, { equalityFn } = {}) {
1725
+ const store = editor.getOptionsStore(plugin);
1726
+ if (!store) return;
1727
+ return useStoreSelect$1(store, selector, equalityFn);
1728
+ }
1729
+
1730
+ //#endregion
1731
+ //#region src/react/stores/element/useElement.ts
1732
+ /**
1733
+ * Get the element by plugin key. If no element is found in the context, it will
1734
+ * return an empty object.
1735
+ */
1736
+ const useElement = (t0) => {
1737
+ const $ = c(1);
1738
+ const pluginKey = t0 === void 0 ? SCOPE_ELEMENT : t0;
1739
+ const editor = useEditorRef();
1740
+ const value = useAtomStoreValue(useElementStore(pluginKey), "element");
1741
+ if (!value) {
1742
+ editor.api.debug.warn(`useElement(${pluginKey}) hook must be used inside the node component's context`, "USE_ELEMENT_CONTEXT");
1743
+ let t1;
1744
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1745
+ t1 = {};
1746
+ $[0] = t1;
1747
+ } else t1 = $[0];
1748
+ return t1;
1749
+ }
1750
+ return value;
1751
+ };
1752
+
1753
+ //#endregion
1754
+ //#region src/react/stores/element/useElementSelector.ts
1755
+ const useElementSelector = (selector, deps, { key, equalityFn = (a, b) => a === b } = {}) => {
1756
+ const selectorAtom = React.useMemo(() => selectAtom(elementStore.atom.entry, (entry, prev) => selector(entry, prev), equalityFn), deps);
1757
+ return useStoreAtomValue$1(useElementStore(key), selectorAtom);
1758
+ };
1759
+
1760
+ //#endregion
1761
+ //#region src/react/stores/event-editor/useEventPlateId.ts
1762
+ /** Get last event editor id: focus, blur or last. */
1763
+ const useEventPlateId = (id) => {
1764
+ const focus = useEventEditorValue("focus");
1765
+ const blur = useEventEditorValue("blur");
1766
+ const last = useEventEditorValue("last");
1767
+ const providerId = useEditorRef().id;
1768
+ if (id) return id;
1769
+ if (focus) return focus;
1770
+ if (blur) return blur;
1771
+ return last ?? providerId ?? PLATE_SCOPE;
1772
+ };
1773
+
1774
+ //#endregion
1775
+ //#region src/react/components/EditorHotkeysEffect.tsx
1776
+ function EditorHotkeysEffect(t0) {
1777
+ const $ = c(4);
1778
+ const { id, editableRef } = t0;
1779
+ const editor = useEditorRef(id);
1780
+ let t1;
1781
+ if ($[0] !== editableRef || $[1] !== editor.meta.shortcuts || $[2] !== id) {
1782
+ t1 = /* @__PURE__ */ React.createElement(React.Fragment, null, Object.entries(editor.meta.shortcuts).map((t2) => {
1783
+ const [hotkeyString, hotkeyConfig] = t2;
1784
+ if (!hotkeyConfig || !isDefined(hotkeyConfig.keys) || !hotkeyConfig.handler) return null;
1785
+ return /* @__PURE__ */ React.createElement(HotkeyEffect, {
1786
+ id,
1787
+ key: hotkeyString,
1788
+ editableRef,
1789
+ hotkeyConfig
1790
+ });
1791
+ }));
1792
+ $[0] = editableRef;
1793
+ $[1] = editor.meta.shortcuts;
1794
+ $[2] = id;
1795
+ $[3] = t1;
1796
+ } else t1 = $[3];
1797
+ return t1;
1798
+ }
1799
+ function HotkeyEffect(t0) {
1800
+ const $ = c(15);
1801
+ const { id, editableRef, hotkeyConfig } = t0;
1802
+ const editor = useEditorRef(id);
1803
+ let handler;
1804
+ let keys;
1805
+ let options;
1806
+ if ($[0] !== hotkeyConfig) {
1807
+ ({keys, handler, ...options} = hotkeyConfig);
1808
+ $[0] = hotkeyConfig;
1809
+ $[1] = handler;
1810
+ $[2] = keys;
1811
+ $[3] = options;
1812
+ } else {
1813
+ handler = $[1];
1814
+ keys = $[2];
1815
+ options = $[3];
1816
+ }
1817
+ let t1;
1818
+ if ($[4] !== editor || $[5] !== handler || $[6] !== options) {
1819
+ t1 = (event, eventDetails) => {
1820
+ if (handler({
1821
+ editor,
1822
+ event,
1823
+ eventDetails
1824
+ }) !== false && !isDefined(options.preventDefault)) {
1825
+ event.preventDefault();
1826
+ event.stopPropagation?.();
1827
+ }
1828
+ };
1829
+ $[4] = editor;
1830
+ $[5] = handler;
1831
+ $[6] = options;
1832
+ $[7] = t1;
1833
+ } else t1 = $[7];
1834
+ let t2;
1835
+ if ($[8] !== options) {
1836
+ t2 = {
1837
+ enableOnContentEditable: true,
1838
+ ...options
1839
+ };
1840
+ $[8] = options;
1841
+ $[9] = t2;
1842
+ } else t2 = $[9];
1843
+ let t3;
1844
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
1845
+ t3 = [];
1846
+ $[10] = t3;
1847
+ } else t3 = $[10];
1848
+ const setHotkeyRef = useHotkeys(keys, t1, t2, t3);
1849
+ let t4;
1850
+ let t5;
1851
+ if ($[11] !== editableRef || $[12] !== setHotkeyRef) {
1852
+ t4 = () => {
1853
+ if (editableRef.current) setHotkeyRef(editableRef.current);
1854
+ };
1855
+ t5 = [setHotkeyRef, editableRef];
1856
+ $[11] = editableRef;
1857
+ $[12] = setHotkeyRef;
1858
+ $[13] = t4;
1859
+ $[14] = t5;
1860
+ } else {
1861
+ t4 = $[13];
1862
+ t5 = $[14];
1863
+ }
1864
+ useEffect(t4, t5);
1865
+ return null;
1866
+ }
1867
+
1868
+ //#endregion
1869
+ //#region src/react/components/EditorMethodsEffect.ts
1870
+ const EditorMethodsEffect = ({ id }) => {
1871
+ const editor = useEditorRef(id);
1872
+ const redecorate = useRedecorate(id);
1873
+ React.useEffect(() => {
1874
+ editor.api.redecorate = redecorate;
1875
+ }, [editor, redecorate]);
1876
+ return null;
1877
+ };
1878
+
1879
+ //#endregion
1880
+ //#region src/react/components/EditorRefEffect.tsx
1881
+ function EditorRefPluginEffect({ id, plugin }) {
1882
+ const editor = useEditorRef(id);
1883
+ plugin.useHooks?.(getEditorPlugin(editor, plugin));
1884
+ return null;
1885
+ }
1886
+ function EditorRefEffect({ id }) {
1887
+ const store = usePlateStore(id);
1888
+ const editor = useAtomStoreValue(store, "editor");
1889
+ const setIsMounted = useAtomStoreSet(store, "isMounted");
1890
+ React.useEffect(() => {
1891
+ setIsMounted(true);
1892
+ return () => {
1893
+ setIsMounted(false);
1894
+ };
1895
+ }, [setIsMounted]);
1896
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, editor.meta.pluginCache.useHooks.map((key) => /* @__PURE__ */ React.createElement(EditorRefPluginEffect, {
1897
+ id,
1898
+ key,
1899
+ plugin: getPlugin(editor, { key })
1900
+ })));
1901
+ }
1902
+
1903
+ //#endregion
1904
+ //#region src/internal/hooks/usePlateInstancesWarn.ts
1905
+ function checkPlateInstances() {
1906
+ globalThis.__PLATE_INSTANCES__ = (globalThis.__PLATE_INSTANCES__ || 0) + 1;
1907
+ }
1908
+ checkPlateInstances();
1909
+ function usePlateInstancesWarn(disabled) {
1910
+ const $ = c(3);
1911
+ let t0;
1912
+ let t1;
1913
+ if ($[0] !== disabled) {
1914
+ t0 = () => {
1915
+ if (!disabled && globalThis.__PLATE_INSTANCES__ && globalThis.__PLATE_INSTANCES__ > 1) console.warn("Detected multiple @platejs/core instances!");
1916
+ };
1917
+ t1 = [disabled];
1918
+ $[0] = disabled;
1919
+ $[1] = t0;
1920
+ $[2] = t1;
1921
+ } else {
1922
+ t0 = $[1];
1923
+ t1 = $[2];
1924
+ }
1925
+ React.useEffect(t0, t1);
1926
+ }
1927
+
1928
+ //#endregion
1929
+ //#region src/react/components/Plate.tsx
1930
+ function PlateInner(t0) {
1931
+ const $ = c(15);
1932
+ const { children, containerRef, decorate, editor, primary, readOnly, renderElement, renderLeaf, scrollRef, onChange, onNodeChange, onSelectionChange, onTextChange, onValueChange } = t0;
1933
+ const t1 = readOnly ?? editor?.dom.readOnly;
1934
+ let t2;
1935
+ if ($[0] !== children || $[1] !== containerRef || $[2] !== decorate || $[3] !== editor || $[4] !== onChange || $[5] !== onNodeChange || $[6] !== onSelectionChange || $[7] !== onTextChange || $[8] !== onValueChange || $[9] !== primary || $[10] !== renderElement || $[11] !== renderLeaf || $[12] !== scrollRef || $[13] !== t1) {
1936
+ t2 = /* @__PURE__ */ React.createElement(PlateStoreProvider, {
1937
+ readOnly: t1,
1938
+ onChange,
1939
+ onNodeChange,
1940
+ onSelectionChange,
1941
+ onTextChange,
1942
+ onValueChange,
1943
+ containerRef,
1944
+ decorate,
1945
+ editor,
1946
+ primary,
1947
+ renderElement,
1948
+ renderLeaf,
1949
+ scope: editor.id,
1950
+ scrollRef
1951
+ }, children);
1952
+ $[0] = children;
1953
+ $[1] = containerRef;
1954
+ $[2] = decorate;
1955
+ $[3] = editor;
1956
+ $[4] = onChange;
1957
+ $[5] = onNodeChange;
1958
+ $[6] = onSelectionChange;
1959
+ $[7] = onTextChange;
1960
+ $[8] = onValueChange;
1961
+ $[9] = primary;
1962
+ $[10] = renderElement;
1963
+ $[11] = renderLeaf;
1964
+ $[12] = scrollRef;
1965
+ $[13] = t1;
1966
+ $[14] = t2;
1967
+ } else t2 = $[14];
1968
+ return t2;
1969
+ }
1970
+ function Plate(props) {
1971
+ const id = useId();
1972
+ const containerRef = React.useRef(null);
1973
+ const scrollRef = React.useRef(null);
1974
+ usePlateInstancesWarn(props.suppressInstanceWarning);
1975
+ if (!props.editor) return null;
1976
+ props.editor.meta.uid = `e-${id.replaceAll(":", "")}`;
1977
+ return /* @__PURE__ */ React.createElement(PlateInner, {
1978
+ key: props.editor.meta.key,
1979
+ containerRef,
1980
+ scrollRef,
1981
+ ...props
1982
+ });
1983
+ }
1984
+
1985
+ //#endregion
1986
+ //#region src/react/components/PlateContainer.tsx
1987
+ const PlateContainer = (t0) => {
1988
+ const $ = c(20);
1989
+ let children;
1990
+ let props;
1991
+ if ($[0] !== t0) {
1992
+ ({children, ...props} = t0);
1993
+ $[0] = t0;
1994
+ $[1] = children;
1995
+ $[2] = props;
1996
+ } else {
1997
+ children = $[1];
1998
+ props = $[2];
1999
+ }
2000
+ const editor = useEditorRef();
2001
+ const readOnly = useEditorReadOnly();
2002
+ const containerRef = useEditorContainerRef();
2003
+ let afterContainer;
2004
+ let beforeContainer;
2005
+ let mainContainer;
2006
+ if ($[3] !== children || $[4] !== containerRef || $[5] !== editor || $[6] !== props || $[7] !== readOnly) {
2007
+ afterContainer = null;
2008
+ beforeContainer = null;
2009
+ let t1$1;
2010
+ if ($[11] !== children || $[12] !== containerRef || $[13] !== editor.meta.uid || $[14] !== props) {
2011
+ t1$1 = /* @__PURE__ */ React.createElement("div", {
2012
+ id: editor.meta.uid,
2013
+ ref: containerRef,
2014
+ ...props
2015
+ }, children);
2016
+ $[11] = children;
2017
+ $[12] = containerRef;
2018
+ $[13] = editor.meta.uid;
2019
+ $[14] = props;
2020
+ $[15] = t1$1;
2021
+ } else t1$1 = $[15];
2022
+ mainContainer = t1$1;
2023
+ editor.meta.pluginCache.render.beforeContainer.forEach((key) => {
2024
+ const plugin = editor.getPlugin({ key });
2025
+ if (isEditOnly(readOnly, plugin, "render")) return;
2026
+ const BeforeContainer = plugin.render.beforeContainer;
2027
+ beforeContainer = /* @__PURE__ */ React.createElement(React.Fragment, null, beforeContainer, /* @__PURE__ */ React.createElement(BeforeContainer, props));
2028
+ });
2029
+ editor.meta.pluginCache.render.afterContainer.forEach((key_0) => {
2030
+ const plugin_0 = editor.getPlugin({ key: key_0 });
2031
+ if (isEditOnly(readOnly, plugin_0, "render")) return;
2032
+ const AfterContainer = plugin_0.render.afterContainer;
2033
+ afterContainer = /* @__PURE__ */ React.createElement(React.Fragment, null, afterContainer, /* @__PURE__ */ React.createElement(AfterContainer, props));
2034
+ });
2035
+ $[3] = children;
2036
+ $[4] = containerRef;
2037
+ $[5] = editor;
2038
+ $[6] = props;
2039
+ $[7] = readOnly;
2040
+ $[8] = afterContainer;
2041
+ $[9] = beforeContainer;
2042
+ $[10] = mainContainer;
2043
+ } else {
2044
+ afterContainer = $[8];
2045
+ beforeContainer = $[9];
2046
+ mainContainer = $[10];
2047
+ }
2048
+ let t1;
2049
+ if ($[16] !== afterContainer || $[17] !== beforeContainer || $[18] !== mainContainer) {
2050
+ t1 = /* @__PURE__ */ React.createElement(React.Fragment, null, beforeContainer, mainContainer, afterContainer);
2051
+ $[16] = afterContainer;
2052
+ $[17] = beforeContainer;
2053
+ $[18] = mainContainer;
2054
+ $[19] = t1;
2055
+ } else t1 = $[19];
2056
+ return t1;
2057
+ };
2058
+ PlateContainer.displayName = "PlateContainer";
2059
+
2060
+ //#endregion
2061
+ //#region src/react/components/PlateControllerEffect.ts
2062
+ const PlateControllerEffect = (t0) => {
2063
+ const $ = c(23);
2064
+ const { id: idProp } = t0;
2065
+ const idFromStore = useEditorId();
2066
+ const id = idProp ?? idFromStore;
2067
+ let t1;
2068
+ if ($[0] !== id) {
2069
+ t1 = focusAtom(plateControllerStore.atom.editorStores, (optic) => optic.prop(id));
2070
+ $[0] = id;
2071
+ $[1] = t1;
2072
+ } else t1 = $[1];
2073
+ const currentStoreAtom = t1;
2074
+ const t2 = usePlateControllerLocalStore();
2075
+ let t3;
2076
+ if ($[2] !== currentStoreAtom || $[3] !== t2) {
2077
+ t3 = t2.setAtom(currentStoreAtom);
2078
+ $[2] = currentStoreAtom;
2079
+ $[3] = t2;
2080
+ $[4] = t3;
2081
+ } else t3 = $[4];
2082
+ let t4;
2083
+ if ($[5] !== currentStoreAtom) {
2084
+ t4 = [currentStoreAtom];
2085
+ $[5] = currentStoreAtom;
2086
+ $[6] = t4;
2087
+ } else t4 = $[6];
2088
+ const setCurrentStore = useStableFn(t3, t4);
2089
+ const setPrimaryEditorIds = useStableFn(useAtomStoreSet(usePlateControllerLocalStore(), "primaryEditorIds"));
2090
+ const setActiveId = useStableFn(useAtomStoreSet(usePlateControllerLocalStore(), "activeId"));
2091
+ const store = usePlateStore(id);
2092
+ const primary = useAtomStoreValue(store, "primary");
2093
+ const focused = useFocused();
2094
+ let t5;
2095
+ let t6;
2096
+ if ($[7] !== id || $[8] !== setActiveId || $[9] !== setCurrentStore || $[10] !== store) {
2097
+ t5 = () => {
2098
+ setCurrentStore(store ?? null);
2099
+ return () => {
2100
+ setCurrentStore(null);
2101
+ setActiveId((activeId) => activeId === id ? null : activeId);
2102
+ };
2103
+ };
2104
+ t6 = [
2105
+ store,
2106
+ setCurrentStore,
2107
+ setActiveId,
2108
+ id
2109
+ ];
2110
+ $[7] = id;
2111
+ $[8] = setActiveId;
2112
+ $[9] = setCurrentStore;
2113
+ $[10] = store;
2114
+ $[11] = t5;
2115
+ $[12] = t6;
2116
+ } else {
2117
+ t5 = $[11];
2118
+ t6 = $[12];
2119
+ }
2120
+ React.useEffect(t5, t6);
2121
+ let t7;
2122
+ let t8;
2123
+ if ($[13] !== id || $[14] !== primary || $[15] !== setPrimaryEditorIds) {
2124
+ t7 = () => {
2125
+ if (primary) {
2126
+ setPrimaryEditorIds((ids) => [...ids, id]);
2127
+ return () => {
2128
+ setPrimaryEditorIds((ids_0) => ids_0.filter((i) => i !== id));
2129
+ };
2130
+ }
2131
+ };
2132
+ t8 = [
2133
+ id,
2134
+ primary,
2135
+ setPrimaryEditorIds
2136
+ ];
2137
+ $[13] = id;
2138
+ $[14] = primary;
2139
+ $[15] = setPrimaryEditorIds;
2140
+ $[16] = t7;
2141
+ $[17] = t8;
2142
+ } else {
2143
+ t7 = $[16];
2144
+ t8 = $[17];
2145
+ }
2146
+ React.useEffect(t7, t8);
2147
+ let t10;
2148
+ let t9;
2149
+ if ($[18] !== focused || $[19] !== id || $[20] !== setActiveId) {
2150
+ t9 = () => {
2151
+ if (id && focused) setActiveId(id);
2152
+ };
2153
+ t10 = [
2154
+ id,
2155
+ focused,
2156
+ setActiveId
2157
+ ];
2158
+ $[18] = focused;
2159
+ $[19] = id;
2160
+ $[20] = setActiveId;
2161
+ $[21] = t10;
2162
+ $[22] = t9;
2163
+ } else {
2164
+ t10 = $[21];
2165
+ t9 = $[22];
2166
+ }
2167
+ React.useEffect(t9, t10);
2168
+ return null;
2169
+ };
2170
+
2171
+ //#endregion
2172
+ //#region src/react/components/PlateSlate.tsx
2173
+ /**
2174
+ * Slate with plugins.
2175
+ *
2176
+ * - OnChange prop
2177
+ * - RenderAboveSlate
2178
+ */
2179
+ function PlateSlate(t0) {
2180
+ const $ = c(11);
2181
+ const { id, children } = t0;
2182
+ let t1;
2183
+ if ($[0] !== id) {
2184
+ t1 = { id };
2185
+ $[0] = id;
2186
+ $[1] = t1;
2187
+ } else t1 = $[1];
2188
+ const slateProps = useSlateProps(t1);
2189
+ const editor = useEditorRef(id);
2190
+ let aboveSlate;
2191
+ if ($[2] !== children || $[3] !== editor || $[4] !== slateProps.editor || $[5] !== slateProps.initialValue || $[6] !== slateProps.key || $[7] !== slateProps.onChange || $[8] !== slateProps.onSelectionChange || $[9] !== slateProps.onValueChange) {
2192
+ aboveSlate = /* @__PURE__ */ React.createElement(Slate, {
2193
+ key: slateProps.key,
2194
+ editor: slateProps.editor,
2195
+ initialValue: slateProps.initialValue,
2196
+ onChange: slateProps.onChange,
2197
+ onSelectionChange: slateProps.onSelectionChange,
2198
+ onValueChange: slateProps.onValueChange
2199
+ }, children);
2200
+ editor.meta.pluginCache.render.aboveSlate.forEach((key) => {
2201
+ const AboveSlate = editor.getPlugin({ key }).render.aboveSlate;
2202
+ aboveSlate = /* @__PURE__ */ React.createElement(AboveSlate, null, aboveSlate);
2203
+ });
2204
+ $[2] = children;
2205
+ $[3] = editor;
2206
+ $[4] = slateProps.editor;
2207
+ $[5] = slateProps.initialValue;
2208
+ $[6] = slateProps.key;
2209
+ $[7] = slateProps.onChange;
2210
+ $[8] = slateProps.onSelectionChange;
2211
+ $[9] = slateProps.onValueChange;
2212
+ $[10] = aboveSlate;
2213
+ } else aboveSlate = $[10];
2214
+ return aboveSlate;
2215
+ }
2216
+
2217
+ //#endregion
2218
+ //#region src/react/components/PlateContent.tsx
2219
+ /**
2220
+ * Editable with plugins.
2221
+ *
2222
+ * - Decorate prop
2223
+ * - DOM handler props
2224
+ * - ReadOnly prop
2225
+ * - Render.afterEditable
2226
+ * - Render.beforeEditable
2227
+ * - RenderElement prop
2228
+ * - RenderLeaf prop
2229
+ * - UseHooks
2230
+ */
2231
+ const PlateContent = React.forwardRef(({ autoFocusOnEditable, readOnly: readOnlyProp, renderEditable, ...props }, ref) => {
2232
+ const { id } = props;
2233
+ const editor = useEditorRef(id);
2234
+ const storeReadOnly = useEditorReadOnly();
2235
+ const readOnly = props.disabled ? true : readOnlyProp ?? storeReadOnly;
2236
+ editor.dom.readOnly = readOnly;
2237
+ if (!editor) throw new Error("Editor not found. Please ensure that PlateContent is rendered below Plate.");
2238
+ const editableProps = useEditableProps({
2239
+ ...props,
2240
+ readOnly
2241
+ });
2242
+ const editableRef = useRef(null);
2243
+ const combinedRef = useComposedRef(ref, editableRef);
2244
+ if (!editor.children || editor.children.length === 0) return null;
2245
+ const editable = /* @__PURE__ */ React.createElement(Editable, {
2246
+ ref: combinedRef,
2247
+ ...editableProps
2248
+ });
2249
+ let afterEditable = null;
2250
+ let beforeEditable = null;
2251
+ editor.meta.pluginCache.render.beforeEditable.forEach((key) => {
2252
+ const plugin = editor.getPlugin({ key });
2253
+ if (isEditOnly(readOnly, plugin, "render")) return;
2254
+ const BeforeEditable = plugin.render.beforeEditable;
2255
+ beforeEditable = /* @__PURE__ */ React.createElement(React.Fragment, null, beforeEditable, /* @__PURE__ */ React.createElement(BeforeEditable, editableProps));
2256
+ });
2257
+ editor.meta.pluginCache.render.afterEditable.forEach((key_0) => {
2258
+ const plugin_0 = editor.getPlugin({ key: key_0 });
2259
+ if (isEditOnly(readOnly, plugin_0, "render")) return;
2260
+ const AfterEditable = plugin_0.render.afterEditable;
2261
+ afterEditable = /* @__PURE__ */ React.createElement(React.Fragment, null, afterEditable, /* @__PURE__ */ React.createElement(AfterEditable, editableProps));
2262
+ });
2263
+ let aboveEditable = /* @__PURE__ */ React.createElement(React.Fragment, null, renderEditable ? renderEditable(editable) : editable, /* @__PURE__ */ React.createElement(EditorMethodsEffect, { id }), /* @__PURE__ */ React.createElement(EditorHotkeysEffect, {
2264
+ id,
2265
+ editableRef
2266
+ }), /* @__PURE__ */ React.createElement(EditorRefEffect, { id }), /* @__PURE__ */ React.createElement(PlateControllerEffect, { id }));
2267
+ editor.meta.pluginCache.render.aboveEditable.forEach((key_1) => {
2268
+ const plugin_1 = editor.getPlugin({ key: key_1 });
2269
+ if (isEditOnly(readOnly, plugin_1, "render")) return;
2270
+ const AboveEditable = plugin_1.render.aboveEditable;
2271
+ aboveEditable = /* @__PURE__ */ React.createElement(AboveEditable, null, aboveEditable);
2272
+ });
2273
+ return /* @__PURE__ */ React.createElement(PlateSlate, { id }, /* @__PURE__ */ React.createElement(EditorStateEffect, {
2274
+ id,
2275
+ disabled: props.disabled,
2276
+ readOnly: readOnlyProp,
2277
+ autoFocusOnEditable,
2278
+ editor
2279
+ }), beforeEditable, aboveEditable, afterEditable);
2280
+ });
2281
+ PlateContent.displayName = "PlateContent";
2282
+ function EditorStateEffect(t0) {
2283
+ const $ = c(25);
2284
+ const { id, autoFocusOnEditable, disabled, editor, readOnly } = t0;
2285
+ const store = usePlateStore(id);
2286
+ let t1;
2287
+ if ($[0] !== disabled || $[1] !== readOnly || $[2] !== store) {
2288
+ t1 = () => {
2289
+ if (disabled) {
2290
+ store.setReadOnly(true);
2291
+ return;
2292
+ }
2293
+ if (isDefined(readOnly)) store.setReadOnly(readOnly);
2294
+ };
2295
+ $[0] = disabled;
2296
+ $[1] = readOnly;
2297
+ $[2] = store;
2298
+ $[3] = t1;
2299
+ } else t1 = $[3];
2300
+ let t2;
2301
+ if ($[4] !== disabled || $[5] !== editor.dom || $[6] !== readOnly || $[7] !== store) {
2302
+ t2 = [
2303
+ disabled,
2304
+ editor.dom,
2305
+ readOnly,
2306
+ store
2307
+ ];
2308
+ $[4] = disabled;
2309
+ $[5] = editor.dom;
2310
+ $[6] = readOnly;
2311
+ $[7] = store;
2312
+ $[8] = t2;
2313
+ } else t2 = $[8];
2314
+ React.useLayoutEffect(t1, t2);
2315
+ const onNodeChange = useAtomStoreValue(store, "onNodeChange");
2316
+ let t3;
2317
+ let t4;
2318
+ if ($[9] !== editor || $[10] !== onNodeChange) {
2319
+ t3 = () => {
2320
+ if (onNodeChange) editor.setOption(SlateExtensionPlugin, "onNodeChange", onNodeChange);
2321
+ };
2322
+ t4 = [editor, onNodeChange];
2323
+ $[9] = editor;
2324
+ $[10] = onNodeChange;
2325
+ $[11] = t3;
2326
+ $[12] = t4;
2327
+ } else {
2328
+ t3 = $[11];
2329
+ t4 = $[12];
2330
+ }
2331
+ React.useLayoutEffect(t3, t4);
2332
+ const onTextChange = useAtomStoreValue(store, "onTextChange");
2333
+ let t5;
2334
+ let t6;
2335
+ if ($[13] !== editor || $[14] !== onTextChange) {
2336
+ t5 = () => {
2337
+ if (onTextChange) editor.setOption(SlateExtensionPlugin, "onTextChange", onTextChange);
2338
+ };
2339
+ t6 = [editor, onTextChange];
2340
+ $[13] = editor;
2341
+ $[14] = onTextChange;
2342
+ $[15] = t5;
2343
+ $[16] = t6;
2344
+ } else {
2345
+ t5 = $[15];
2346
+ t6 = $[16];
2347
+ }
2348
+ React.useLayoutEffect(t5, t6);
2349
+ const prevReadOnly = React.useRef(readOnly);
2350
+ let t7;
2351
+ if ($[17] !== autoFocusOnEditable || $[18] !== editor.tf || $[19] !== readOnly) {
2352
+ t7 = () => {
2353
+ if (autoFocusOnEditable && prevReadOnly.current && !readOnly) editor.tf.focus({ edge: "endEditor" });
2354
+ prevReadOnly.current = readOnly;
2355
+ };
2356
+ $[17] = autoFocusOnEditable;
2357
+ $[18] = editor.tf;
2358
+ $[19] = readOnly;
2359
+ $[20] = t7;
2360
+ } else t7 = $[20];
2361
+ let t8;
2362
+ if ($[21] !== autoFocusOnEditable || $[22] !== editor || $[23] !== readOnly) {
2363
+ t8 = [
2364
+ autoFocusOnEditable,
2365
+ editor,
2366
+ readOnly
2367
+ ];
2368
+ $[21] = autoFocusOnEditable;
2369
+ $[22] = editor;
2370
+ $[23] = readOnly;
2371
+ $[24] = t8;
2372
+ } else t8 = $[24];
2373
+ React.useEffect(t7, t8);
2374
+ return null;
2375
+ }
2376
+
2377
+ //#endregion
2378
+ //#region src/react/editor/usePlateEditor.ts
2379
+ /**
2380
+ * Creates a memoized Plate editor for React components.
2381
+ *
2382
+ * This hook creates a fully configured Plate editor instance that is memoized
2383
+ * based on the provided dependencies. It's optimized for React components to
2384
+ * prevent unnecessary re-creation of the editor on every render.
2385
+ *
2386
+ * Examples:
2387
+ *
2388
+ * ```ts
2389
+ * const editor = usePlateEditor({
2390
+ * plugins: [ParagraphPlugin, HeadingPlugin],
2391
+ * value: [{ type: 'p', children: [{ text: 'Hello world!' }] }],
2392
+ * });
2393
+ *
2394
+ * // Editor with custom dependencies
2395
+ * const editor = usePlateEditor(
2396
+ * {
2397
+ * plugins: [ParagraphPlugin],
2398
+ * enabled,
2399
+ * },
2400
+ * [enabled]
2401
+ * ); // Re-create when enabled changes
2402
+ * ```
2403
+ *
2404
+ * @param options - Configuration options for creating the Plate editor
2405
+ * @param deps - Additional dependencies for the useMemo hook (default: [])
2406
+ * @see {@link createPlateEditor} for detailed information on React editor creation and configuration.
2407
+ * @see {@link createSlateEditor} for a non-React version of editor creation.
2408
+ * @see {@link withPlate} for the underlying React-specific enhancement function.
2409
+ */
2410
+ function usePlateEditor(options = {}, deps = []) {
2411
+ const [, forceRender] = React.useState({});
2412
+ const isMountedRef = React.useRef(false);
2413
+ React.useEffect(() => {
2414
+ isMountedRef.current = true;
2415
+ return () => {
2416
+ isMountedRef.current = false;
2417
+ };
2418
+ }, []);
2419
+ return React.useMemo(() => {
2420
+ if (options.enabled === false) return null;
2421
+ return createPlateEditor({
2422
+ ...options,
2423
+ onReady: (ctx) => {
2424
+ if (ctx.isAsync && isMountedRef.current) forceRender({});
2425
+ options.onReady?.(ctx);
2426
+ }
2427
+ });
2428
+ }, [
2429
+ options.id,
2430
+ options.enabled,
2431
+ ...deps
2432
+ ]);
2433
+ }
2434
+
2435
+ //#endregion
2436
+ //#region src/react/editor/usePlateViewEditor.ts
2437
+ /**
2438
+ * Creates a memoized static Plate editor for view-only React components.
2439
+ *
2440
+ * This hook creates a fully configured static Plate editor instance that is
2441
+ * memoized based on the provided dependencies. It's optimized for React
2442
+ * components to prevent unnecessary re-creation of the editor on every render.
2443
+ * Uses createStaticEditor.
2444
+ *
2445
+ * @param options - Configuration options for creating the static Plate editor
2446
+ * @param deps - Additional dependencies for the useMemo hook (default: [])
2447
+ * @see {@link createStaticEditor} for detailed information on static editor creation and configuration.
2448
+ */
2449
+ function usePlateViewEditor(options = {}, deps = []) {
2450
+ const isMountedRef = React.useRef(false);
2451
+ const [, forceRender] = React.useState({});
2452
+ React.useEffect(() => {
2453
+ isMountedRef.current = true;
2454
+ return () => {
2455
+ isMountedRef.current = false;
2456
+ };
2457
+ }, []);
2458
+ return React.useMemo(() => {
2459
+ if (options.enabled === false) return null;
2460
+ return createStaticEditor({
2461
+ ...options,
2462
+ onReady: (ctx) => {
2463
+ if (ctx.isAsync && isMountedRef.current) forceRender({});
2464
+ options.onReady?.(ctx);
2465
+ }
2466
+ });
2467
+ }, [
2468
+ options?.id,
2469
+ options?.enabled,
2470
+ ...deps
2471
+ ]);
2472
+ }
2473
+
2474
+ //#endregion
2475
+ //#region src/react/components/PlateTest.tsx
2476
+ function PlateTest(t0) {
2477
+ const $ = c(12);
2478
+ let editableProps;
2479
+ let editor;
2480
+ let props;
2481
+ let variant;
2482
+ if ($[0] !== t0) {
2483
+ const { editableProps: t1$1, shouldNormalizeEditor, variant: t2$1, ...t3 } = t0;
2484
+ editableProps = t1$1;
2485
+ props = t3;
2486
+ variant = t2$1 === void 0 ? "wordProcessor" : t2$1;
2487
+ const { id, editor: _editor, plugins } = props;
2488
+ editor = _editor;
2489
+ if (editor && !editor.meta.pluginList) editor = createPlateEditor({
2490
+ id,
2491
+ editor,
2492
+ plugins,
2493
+ shouldNormalizeEditor
2494
+ });
2495
+ $[0] = t0;
2496
+ $[1] = editableProps;
2497
+ $[2] = editor;
2498
+ $[3] = props;
2499
+ $[4] = variant;
2500
+ } else {
2501
+ editableProps = $[1];
2502
+ editor = $[2];
2503
+ props = $[3];
2504
+ variant = $[4];
2505
+ }
2506
+ let t1;
2507
+ if ($[5] !== editableProps || $[6] !== variant) {
2508
+ t1 = /* @__PURE__ */ React.createElement(PlateContent, {
2509
+ "data-testid": "slate-content-editable",
2510
+ "data-variant": variant,
2511
+ autoFocus: true,
2512
+ ...editableProps
2513
+ });
2514
+ $[5] = editableProps;
2515
+ $[6] = variant;
2516
+ $[7] = t1;
2517
+ } else t1 = $[7];
2518
+ let t2;
2519
+ if ($[8] !== editor || $[9] !== props || $[10] !== t1) {
2520
+ t2 = /* @__PURE__ */ React.createElement(Plate, {
2521
+ ...props,
2522
+ editor
2523
+ }, t1);
2524
+ $[8] = editor;
2525
+ $[9] = props;
2526
+ $[10] = t1;
2527
+ $[11] = t2;
2528
+ } else t2 = $[11];
2529
+ return t2;
2530
+ }
2531
+
2532
+ //#endregion
2533
+ //#region src/react/components/PlateView.tsx
2534
+ const PlateView = (props) => {
2535
+ const $ = c(5);
2536
+ let t0;
2537
+ if ($[0] !== props.editor.tf) {
2538
+ t0 = (e) => {
2539
+ props.editor.tf.setFragmentData(e.clipboardData, "copy");
2540
+ if (e.clipboardData.getData("application/x-slate-fragment")) e.preventDefault();
2541
+ };
2542
+ $[0] = props.editor.tf;
2543
+ $[1] = t0;
2544
+ } else t0 = $[1];
2545
+ const t1 = t0;
2546
+ let t2;
2547
+ if ($[2] !== props || $[3] !== t1) {
2548
+ t2 = /* @__PURE__ */ React.createElement(PlateStatic, {
2549
+ onCopy: t1,
2550
+ ...props
2551
+ });
2552
+ $[2] = props;
2553
+ $[3] = t1;
2554
+ $[4] = t2;
2555
+ } else t2 = $[4];
2556
+ return t2;
2557
+ };
2558
+
2559
+ //#endregion
2560
+ //#region src/react/components/withHOC.tsx
2561
+ const withHOC = (HOC, Component, hocProps, hocRef) => React.forwardRef((props, componentRef) => {
2562
+ const $ = c(3);
2563
+ const t0 = props;
2564
+ let t1;
2565
+ if ($[0] !== componentRef || $[1] !== t0) {
2566
+ t1 = /* @__PURE__ */ React.createElement(HOC, {
2567
+ ...hocProps,
2568
+ ref: hocRef
2569
+ }, /* @__PURE__ */ React.createElement(Component, {
2570
+ ...t0,
2571
+ ref: componentRef
2572
+ }));
2573
+ $[0] = componentRef;
2574
+ $[1] = t0;
2575
+ $[2] = t1;
2576
+ } else t1 = $[2];
2577
+ return t1;
2578
+ });
2579
+
2580
+ //#endregion
2581
+ export { BLUR_EDITOR_EVENT, BelowRootNodes, ContentVisibilityChunk, DOM_HANDLERS, DefaultPlaceholder, Editable, EditorHotkeysEffect, EditorMethodsEffect, EditorRefEffect, EditorRefPluginEffect, ElementProvider, EventEditorPlugin, EventEditorStore, FOCUS_EDITOR_EVENT, GLOBAL_PLATE_SCOPE, PLATE_SCOPE, ParagraphPlugin, Plate, PlateContainer, PlateContent, PlateController, PlateControllerEffect, PlateElement, PlateLeaf, PlateSlate, PlateStoreProvider, PlateTest, PlateText, PlateView, ReactPlugin, SCOPE_ELEMENT, Slate, SlateReactExtensionPlugin, atom, convertDomEventToSyntheticEvent, createAtomStore, createPlateEditor, createPlateFallbackEditor, createPlatePlugin, createPlateStore, createTPlatePlugin, createZustandStore, elementStore, getEditorPlugin, getEventPlateId, getPlateCorePlugins, getPlugin, getRenderNodeProps, isEventHandled, omitPluginContext, pipeHandler, pipeOnChange, pipeRenderElement, pipeRenderLeaf, pipeRenderText, plateControllerStore, plateStore, pluginRenderElement, pluginRenderLeaf, pluginRenderText, toPlatePlugin, toTPlatePlugin, useComposing, useEditableProps, useEditorComposing, useEditorContainerRef, useEditorId, useEditorMounted, useEditorPlugin, useEditorPluginOption, useEditorPluginOptions, useEditorReadOnly, useEditorRef, useEditorScrollRef, useEditorSelection, useEditorSelector, useEditorState, useEditorValue, useEditorVersion, useElement, useElementSelector, useElementStore, useEventEditorValue, useEventPlateId, useFocusEditorEvents, useFocused, useFocusedLast, useIncrementVersion, useNodeAttributes, useNodePath, usePath, usePlateControllerExists, usePlateControllerLocalStore, usePlateControllerStore, usePlateEditor, usePlateLocalStore, usePlateSet, usePlateState, usePlateStore, usePlateValue, usePlateViewEditor, usePluginOption, usePluginOptions, useReadOnly, useRedecorate, useScrollRef, useSelected, useSelectionVersion, useSlateProps, useSlateStatic, useStoreAtomState, useStoreAtomValue, useStoreSelect, useStoreSetAtom, useStoreState, useStoreValue, useTracked, useTrackedStore, useValueVersion, withHOC, withPlate, withPlateReact, withReact };
2582
+ //# sourceMappingURL=index.js.map