@portabletext/editor 7.10.16 → 7.10.18

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.
Files changed (63) hide show
  1. package/lib/{_chunks-dts/behavior.types.action.d.ts → behavior.types.action-CYtiRDck.d.ts} +260 -59
  2. package/lib/behavior.types.action-CYtiRDck.d.ts.map +1 -0
  3. package/lib/behavior.types.behavior-B_77VtQR.js +159 -0
  4. package/lib/behavior.types.behavior-B_77VtQR.js.map +1 -0
  5. package/lib/behaviors/index.d.ts +1 -1
  6. package/lib/behaviors/index.js +2 -35
  7. package/lib/get-container-BeXYKpoi.js +222 -0
  8. package/lib/get-container-BeXYKpoi.js.map +1 -0
  9. package/lib/get-parent-51Kzgaf9.js +237 -0
  10. package/lib/get-parent-51Kzgaf9.js.map +1 -0
  11. package/lib/get-path-sub-schema--2I4NJbG.js +513 -0
  12. package/lib/get-path-sub-schema--2I4NJbG.js.map +1 -0
  13. package/lib/index.d.ts +2 -67
  14. package/lib/index.js +16743 -18963
  15. package/lib/index.js.map +1 -1
  16. package/lib/plugins/index.d.ts +1 -2
  17. package/lib/plugins/index.d.ts.map +1 -1
  18. package/lib/plugins/index.js +103 -41
  19. package/lib/plugins/index.js.map +1 -1
  20. package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js +822 -0
  21. package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js.map +1 -0
  22. package/lib/selectors/index.d.ts +1 -3
  23. package/lib/selectors/index.d.ts.map +1 -1
  24. package/lib/selectors/index.js +256 -215
  25. package/lib/selectors/index.js.map +1 -1
  26. package/lib/traversal/index.d.ts +1 -1
  27. package/lib/traversal/index.d.ts.map +1 -1
  28. package/lib/traversal/index.js +33 -52
  29. package/lib/traversal/index.js.map +1 -1
  30. package/lib/use-editor-CwNeVwVC.js +47 -0
  31. package/lib/use-editor-CwNeVwVC.js.map +1 -0
  32. package/lib/util.is-equal-selections-BF4WJtz5.js +25 -0
  33. package/lib/util.is-equal-selections-BF4WJtz5.js.map +1 -0
  34. package/lib/util.slice-blocks-DQnr9X2s.js +633 -0
  35. package/lib/util.slice-blocks-DQnr9X2s.js.map +1 -0
  36. package/lib/utils/index.d.ts +11 -39
  37. package/lib/utils/index.d.ts.map +1 -1
  38. package/lib/utils/index.js +87 -123
  39. package/lib/utils/index.js.map +1 -1
  40. package/package.json +25 -20
  41. package/lib/_chunks-dts/behavior.types.action.d.ts.map +0 -1
  42. package/lib/_chunks-dts/block-offset.d.ts +0 -10
  43. package/lib/_chunks-dts/block-offset.d.ts.map +0 -1
  44. package/lib/_chunks-dts/editor-selector.d.ts +0 -33
  45. package/lib/_chunks-dts/editor-selector.d.ts.map +0 -1
  46. package/lib/_chunks-dts/editor.d.ts +0 -99
  47. package/lib/_chunks-dts/editor.d.ts.map +0 -1
  48. package/lib/_chunks-es/get-container.js +0 -187
  49. package/lib/_chunks-es/get-container.js.map +0 -1
  50. package/lib/_chunks-es/get-parent.js +0 -195
  51. package/lib/_chunks-es/get-parent.js.map +0 -1
  52. package/lib/_chunks-es/get-path-sub-schema.js +0 -399
  53. package/lib/_chunks-es/get-path-sub-schema.js.map +0 -1
  54. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +0 -947
  55. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +0 -1
  56. package/lib/_chunks-es/use-editor.js +0 -20
  57. package/lib/_chunks-es/use-editor.js.map +0 -1
  58. package/lib/_chunks-es/util.is-equal-selections.js +0 -20
  59. package/lib/_chunks-es/util.is-equal-selections.js.map +0 -1
  60. package/lib/_chunks-es/util.slice-blocks.js +0 -720
  61. package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
  62. package/lib/behaviors/index.js.map +0 -1
  63. package/lib/index.d.ts.map +0 -1
@@ -1,5 +1,4 @@
1
- import { bt as RegistrableNode, g as EditorEmittedEvent, y as Behavior } from "../_chunks-dts/behavior.types.action.js";
2
- import { t as Editor } from "../_chunks-dts/editor.js";
1
+ import { W as Editor, X as Behavior, Zt as RegistrableNode, q as EditorEmittedEvent } from "../behavior.types.action-CYtiRDck.js";
3
2
  import React from "react";
4
3
  /**
5
4
  * @beta
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/plugins/plugin.behavior.tsx","../../src/plugins/plugin.node.tsx","../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.event-listener.tsx"],"mappings":";;;;;;AAcA;;;;;;;iBAAgB,cAAA,CAAe,KAAA;EAAQ,SAAA,EAAW,KAAK,CAAC,QAAA;AAAA;;;;AAAxD;;;;;;;;;iBCEgB,UAAA,CAAW,KAAA;EAAQ,KAAA,EAAO,KAAK,CAAC,eAAA;AAAA;;;ADFhD;cEPa,eAAA,EAAe,KAAA,CAAA,yBAAA,CAAA,KAAA,CAAA,aAAA,CAAA,MAAA;;;;AFO5B;;;;;;;;;AAAkE;;ACElE;;;;;;;;;AAAiE;;ACTjE;;;;;;;;;;;;;;AAA4B;;AC8C5B;;;;;;;;iBAAgB,mBAAA,CAAoB,KAAA;EAClC,EAAA,GAAK,KAAA,EAAO,kBAAkB;AAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/plugins/plugin.behavior.tsx","../../src/plugins/plugin.node.tsx","../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.event-listener.tsx"],"mappings":";;;;;;;;;;;;iBAcgB,eAAe;EAAQ,WAAW,MAAM;;;;;;;;;;;;;;iBCExC,WAAW;EAAQ,OAAO,MAAM;;;;;cCTnC,iBAAe,MAAA,0BAAA,MAAA,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBC8CZ,oBAAoB;EAClC,KAAK,OAAO"}
@@ -1,56 +1,118 @@
1
+ import { t as useEditor } from "../use-editor-CwNeVwVC.js";
1
2
  import { c } from "react/compiler-runtime";
2
3
  import React, { useEffect } from "react";
3
- import { useEditor } from "../_chunks-es/use-editor.js";
4
+ /**
5
+ * @beta
6
+ *
7
+ * Plugin component that registers a list of `Behavior`s with the editor.
8
+ *
9
+ * Stabilize the `behaviors` array (a module-level constant or `useMemo`)
10
+ * to avoid a full unregister/re-register cycle on every parent render: a
11
+ * new array reference per render triggers the registration effect to
12
+ * re-run.
13
+ */
4
14
  function BehaviorPlugin(props) {
5
- const $ = c(4), editor = useEditor();
6
- let t0, t1;
7
- return $[0] !== editor || $[1] !== props.behaviors ? (t0 = () => {
8
- const unregisterBehaviors = props.behaviors.map((behavior) => editor.registerBehavior({
9
- behavior
10
- }));
11
- return () => {
12
- unregisterBehaviors.forEach(_temp$1);
13
- };
14
- }, t1 = [editor, props.behaviors], $[0] = editor, $[1] = props.behaviors, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
15
+ let $ = c(4), editor = useEditor(), t0, t1;
16
+ return $[0] !== editor || $[1] !== props.behaviors ? (t0 = () => {
17
+ let unregisterBehaviors = props.behaviors.map((behavior) => editor.registerBehavior({ behavior }));
18
+ return () => {
19
+ unregisterBehaviors.forEach(_temp$1);
20
+ };
21
+ }, t1 = [editor, props.behaviors], $[0] = editor, $[1] = props.behaviors, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
15
22
  }
16
23
  function _temp$1(unregister) {
17
- unregister();
24
+ unregister();
18
25
  }
26
+ /**
27
+ * @alpha
28
+ *
29
+ * Plugin component that registers a list of nodes (containers, text
30
+ * blocks, spans, block objects, inline objects) with the editor. Each
31
+ * node is the result of a `defineX` factory.
32
+ *
33
+ * Stabilize the `nodes` array (a module-level constant or `useMemo`)
34
+ * to avoid a full unregister/re-register cycle on every parent
35
+ * render: a new array reference per render triggers the registration
36
+ * effect to re-run.
37
+ */
19
38
  function NodePlugin(props) {
20
- const $ = c(4), editor = useEditor();
21
- let t0, t1;
22
- return $[0] !== editor || $[1] !== props.nodes ? (t0 = () => {
23
- const unregisterNodes = props.nodes.map((node) => editor.registerNode({
24
- node
25
- }));
26
- return () => {
27
- unregisterNodes.forEach(_temp);
28
- };
29
- }, t1 = [editor, props.nodes], $[0] = editor, $[1] = props.nodes, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
39
+ let $ = c(4), editor = useEditor(), t0, t1;
40
+ return $[0] !== editor || $[1] !== props.nodes ? (t0 = () => {
41
+ let unregisterNodes = props.nodes.map((node) => editor.registerNode({ node }));
42
+ return () => {
43
+ unregisterNodes.forEach(_temp);
44
+ };
45
+ }, t1 = [editor, props.nodes], $[0] = editor, $[1] = props.nodes, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
30
46
  }
31
47
  function _temp(unregister) {
32
- unregister();
48
+ unregister();
33
49
  }
50
+ /**
51
+ * @beta
52
+ */
34
53
  const EditorRefPlugin = React.forwardRef((_, ref) => {
35
- const $ = c(2), editor = useEditor(), portableTextEditorRef = React.useRef(editor);
36
- let t0, t1;
37
- return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = () => portableTextEditorRef.current, t1 = [], $[0] = t0, $[1] = t1) : (t0 = $[0], t1 = $[1]), React.useImperativeHandle(ref, t0, t1), null;
54
+ let $ = c(2), editor = useEditor(), portableTextEditorRef = React.useRef(editor), t0, t1;
55
+ return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = () => portableTextEditorRef.current, t1 = [], $[0] = t0, $[1] = t1) : (t0 = $[0], t1 = $[1]), React.useImperativeHandle(ref, t0, t1), null;
38
56
  });
39
57
  EditorRefPlugin.displayName = "EditorRefPlugin";
58
+ /**
59
+ * @public
60
+ * Listen for events emitted by the editor. Must be used inside `EditorProvider`. Events available include:
61
+ * - 'blurred'
62
+ * - 'done loading'
63
+ * - 'editable'
64
+ * - 'error'
65
+ * - 'focused'
66
+ * - 'invalid value'
67
+ * - 'loading'
68
+ * - 'mutation'
69
+ * - 'patch'
70
+ * - 'read only'
71
+ * - 'ready'
72
+ * - 'selection'
73
+ * - 'value changed'
74
+ *
75
+ * @example
76
+ * Listen and log events.
77
+ * ```tsx
78
+ * import {EditorProvider} from '@portabletext/editor'
79
+ * import {EventListenerPlugin} from '@portabletext/editor/plugins'
80
+ *
81
+ * function MyComponent() {
82
+ * return (
83
+ * <EditorProvider>
84
+ * <EventListenerPlugin
85
+ * on={(event) => {
86
+ * console.log(event)
87
+ * }
88
+ * } />
89
+ * { ... }
90
+ * </EditorProvider>
91
+ * )
92
+ * }
93
+ * ```
94
+ * @example
95
+ * Handle events when there is a mutation.
96
+ * ```tsx
97
+ * <EventListenerPlugin
98
+ * on={(event) => {
99
+ * if (event.type === 'mutation') {
100
+ * console.log('Value changed:', event.snapshot)
101
+ * }
102
+ * }}
103
+ * />
104
+ * ```
105
+ * @group Components
106
+ */
40
107
  function EventListenerPlugin(props) {
41
- const $ = c(4), editor = useEditor();
42
- let t0, t1;
43
- return $[0] !== editor || $[1] !== props.on ? (t0 = () => {
44
- const subscription = editor.on("*", props.on);
45
- return () => {
46
- subscription.unsubscribe();
47
- };
48
- }, t1 = [editor, props.on], $[0] = editor, $[1] = props.on, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
108
+ let $ = c(4), editor = useEditor(), t0, t1;
109
+ return $[0] !== editor || $[1] !== props.on ? (t0 = () => {
110
+ let subscription = editor.on("*", props.on);
111
+ return () => {
112
+ subscription.unsubscribe();
113
+ };
114
+ }, t1 = [editor, props.on], $[0] = editor, $[1] = props.on, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
49
115
  }
50
- export {
51
- BehaviorPlugin,
52
- EditorRefPlugin,
53
- EventListenerPlugin,
54
- NodePlugin
55
- };
56
- //# sourceMappingURL=index.js.map
116
+ export { BehaviorPlugin, EditorRefPlugin, EventListenerPlugin, NodePlugin };
117
+
118
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/plugins/plugin.behavior.tsx","../../src/plugins/plugin.node.tsx","../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.event-listener.tsx"],"sourcesContent":["import {useEffect} from 'react'\nimport type {Behavior} from '../behaviors/behavior.types.behavior'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @beta\n *\n * Plugin component that registers a list of `Behavior`s with the editor.\n *\n * Stabilize the `behaviors` array (a module-level constant or `useMemo`)\n * to avoid a full unregister/re-register cycle on every parent render: a\n * new array reference per render triggers the registration effect to\n * re-run.\n */\nexport function BehaviorPlugin(props: {behaviors: Array<Behavior>}) {\n const editor = useEditor()\n\n useEffect(() => {\n const unregisterBehaviors = props.behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n unregisterBehaviors.forEach((unregister) => {\n unregister()\n })\n }\n }, [editor, props.behaviors])\n\n return null\n}\n","import {useEffect} from 'react'\nimport {useEditor} from '../editor/use-editor'\nimport type {RegistrableNode} from '../renderers/renderer.types'\n\n/**\n * @alpha\n *\n * Plugin component that registers a list of nodes (containers, text\n * blocks, spans, block objects, inline objects) with the editor. Each\n * node is the result of a `defineX` factory.\n *\n * Stabilize the `nodes` array (a module-level constant or `useMemo`)\n * to avoid a full unregister/re-register cycle on every parent\n * render: a new array reference per render triggers the registration\n * effect to re-run.\n */\nexport function NodePlugin(props: {nodes: Array<RegistrableNode>}) {\n const editor = useEditor()\n\n useEffect(() => {\n const unregisterNodes = props.nodes.map((node) =>\n editor.registerNode({node}),\n )\n\n return () => {\n unregisterNodes.forEach((unregister) => {\n unregister()\n })\n }\n }, [editor, props.nodes])\n\n return null\n}\n","import React from 'react'\nimport type {Editor} from '../editor'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @beta\n */\nexport const EditorRefPlugin = React.forwardRef<Editor | null>((_, ref) => {\n const editor = useEditor()\n\n const portableTextEditorRef = React.useRef(editor)\n\n React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])\n\n return null\n})\nEditorRefPlugin.displayName = 'EditorRefPlugin'\n","import {useEffect} from 'react'\nimport type {EditorEmittedEvent} from '../editor/relay'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @public\n * Listen for events emitted by the editor. Must be used inside `EditorProvider`. Events available include:\n * - 'blurred'\n * - 'done loading'\n * - 'editable'\n * - 'error'\n * - 'focused'\n * - 'invalid value'\n * - 'loading'\n * - 'mutation'\n * - 'patch'\n * - 'read only'\n * - 'ready'\n * - 'selection'\n * - 'value changed'\n *\n * @example\n * Listen and log events.\n * ```tsx\n * import {EditorProvider} from '@portabletext/editor'\n * import {EventListenerPlugin} from '@portabletext/editor/plugins'\n *\n * function MyComponent() {\n * return (\n * <EditorProvider>\n * <EventListenerPlugin\n * on={(event) => {\n * console.log(event)\n * }\n * } />\n * { ... }\n * </EditorProvider>\n * )\n * }\n * ```\n * @example\n * Handle events when there is a mutation.\n * ```tsx\n * <EventListenerPlugin\n * on={(event) => {\n * if (event.type === 'mutation') {\n * console.log('Value changed:', event.snapshot)\n * }\n * }}\n * />\n * ```\n * @group Components\n */\nexport function EventListenerPlugin(props: {\n on: (event: EditorEmittedEvent) => void\n}) {\n const editor = useEditor()\n\n useEffect(() => {\n const subscription = editor.on('*', props.on)\n\n return () => {\n subscription.unsubscribe()\n }\n }, [editor, props.on])\n\n return null\n}\n"],"names":["BehaviorPlugin","props","$","_c","editor","useEditor","t0","t1","behaviors","unregisterBehaviors","map","behavior","registerBehavior","forEach","_temp","useEffect","unregister","NodePlugin","nodes","unregisterNodes","node","registerNode","EditorRefPlugin","React","forwardRef","_","ref","portableTextEditorRef","useRef","Symbol","for","current","useImperativeHandle","displayName","EventListenerPlugin","on","subscription","unsubscribe"],"mappings":";;;AAcO,SAAAA,eAAAC,OAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GACLC,SAAeC,UAAAA;AAAW,MAAAC,IAAAC;AAAA,SAAAL,SAAAE,UAAAF,EAAA,CAAA,MAAAD,MAAAO,aAEhBF,KAAAA,MAAA;AACR,UAAAG,s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AAA,CAAA,MAAA2B,uBAAAC,IAAA,2BAAA,KAEnBxB,KAAAA,MAAMqB,sBAAqBI,SAAUxB,KAAA,CAAA,GAAEL,OAAAI,IAAAJ,OAAAK,OAAAD,KAAAJ,EAAA,CAAA,GAAAK,KAAAL,EAAA,CAAA,IAAtEqB,MAAKS,oBAAqBN,KAAKpB,IAAqCC,EAAE,GAE/D;AAAI,CACZ;AACDe,gBAAgBW,cAAc;ACqCvB,SAAAC,oBAAAjC,OAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAGLC,SAAeC,UAAAA;AAAW,MAAAC,IAAAC;AAAA,SAAAL,SAAAE,UAAAF,EAAA,CAAA,MAAAD,MAAAkC,MAEhB7B,KAAAA,MAAA;AACR,UAAA8B,eAAqBhC,OAAM+B,GAAI,KAAKlC,MAAKkC,EAAG;AAAC,WAEtC,MAAA;AACLC,mBAAYC,YAAAA;AAAAA,IAAc;AAAA,EAC3B,GACA9B,MAACH,QAAQH,MAAKkC,EAAG,GAACjC,OAAAE,QAAAF,EAAA,CAAA,IAAAD,MAAAkC,IAAAjC,OAAAI,IAAAJ,OAAAK,OAAAD,KAAAJ,EAAA,CAAA,GAAAK,KAAAL,EAAA,CAAA,IANrBa,UAAUT,IAMPC,EAAkB,GAEd;AAAI;"}
1
+ {"version":3,"file":"index.js","names":["useEffect","Behavior","useEditor","BehaviorPlugin","props","$","_c","editor","t0","t1","behaviors","unregisterBehaviors","map","behavior","registerBehavior","forEach","_temp","unregister","useEffect","useEditor","RegistrableNode","NodePlugin","props","$","_c","editor","t0","t1","nodes","unregisterNodes","map","node","registerNode","forEach","_temp","unregister","React","Editor","useEditor","EditorRefPlugin","forwardRef","_","ref","$","_c","editor","portableTextEditorRef","useRef","t0","t1","Symbol","for","current","useImperativeHandle","displayName","useEffect","EditorEmittedEvent","useEditor","EventListenerPlugin","props","$","_c","editor","t0","t1","on","subscription","unsubscribe"],"sources":["../../src/plugins/plugin.behavior.tsx","../../src/plugins/plugin.node.tsx","../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.event-listener.tsx"],"sourcesContent":["import {useEffect} from 'react'\nimport type {Behavior} from '../behaviors/behavior.types.behavior'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @beta\n *\n * Plugin component that registers a list of `Behavior`s with the editor.\n *\n * Stabilize the `behaviors` array (a module-level constant or `useMemo`)\n * to avoid a full unregister/re-register cycle on every parent render: a\n * new array reference per render triggers the registration effect to\n * re-run.\n */\nexport function BehaviorPlugin(props: {behaviors: Array<Behavior>}) {\n const editor = useEditor()\n\n useEffect(() => {\n const unregisterBehaviors = props.behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n unregisterBehaviors.forEach((unregister) => {\n unregister()\n })\n }\n }, [editor, props.behaviors])\n\n return null\n}\n","import {useEffect} from 'react'\nimport {useEditor} from '../editor/use-editor'\nimport type {RegistrableNode} from '../renderers/renderer.types'\n\n/**\n * @alpha\n *\n * Plugin component that registers a list of nodes (containers, text\n * blocks, spans, block objects, inline objects) with the editor. Each\n * node is the result of a `defineX` factory.\n *\n * Stabilize the `nodes` array (a module-level constant or `useMemo`)\n * to avoid a full unregister/re-register cycle on every parent\n * render: a new array reference per render triggers the registration\n * effect to re-run.\n */\nexport function NodePlugin(props: {nodes: Array<RegistrableNode>}) {\n const editor = useEditor()\n\n useEffect(() => {\n const unregisterNodes = props.nodes.map((node) =>\n editor.registerNode({node}),\n )\n\n return () => {\n unregisterNodes.forEach((unregister) => {\n unregister()\n })\n }\n }, [editor, props.nodes])\n\n return null\n}\n","import React from 'react'\nimport type {Editor} from '../editor'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @beta\n */\nexport const EditorRefPlugin = React.forwardRef<Editor | null>((_, ref) => {\n const editor = useEditor()\n\n const portableTextEditorRef = React.useRef(editor)\n\n React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])\n\n return null\n})\nEditorRefPlugin.displayName = 'EditorRefPlugin'\n","import {useEffect} from 'react'\nimport type {EditorEmittedEvent} from '../editor/relay'\nimport {useEditor} from '../editor/use-editor'\n\n/**\n * @public\n * Listen for events emitted by the editor. Must be used inside `EditorProvider`. Events available include:\n * - 'blurred'\n * - 'done loading'\n * - 'editable'\n * - 'error'\n * - 'focused'\n * - 'invalid value'\n * - 'loading'\n * - 'mutation'\n * - 'patch'\n * - 'read only'\n * - 'ready'\n * - 'selection'\n * - 'value changed'\n *\n * @example\n * Listen and log events.\n * ```tsx\n * import {EditorProvider} from '@portabletext/editor'\n * import {EventListenerPlugin} from '@portabletext/editor/plugins'\n *\n * function MyComponent() {\n * return (\n * <EditorProvider>\n * <EventListenerPlugin\n * on={(event) => {\n * console.log(event)\n * }\n * } />\n * { ... }\n * </EditorProvider>\n * )\n * }\n * ```\n * @example\n * Handle events when there is a mutation.\n * ```tsx\n * <EventListenerPlugin\n * on={(event) => {\n * if (event.type === 'mutation') {\n * console.log('Value changed:', event.snapshot)\n * }\n * }}\n * />\n * ```\n * @group Components\n */\nexport function EventListenerPlugin(props: {\n on: (event: EditorEmittedEvent) => void\n}) {\n const editor = useEditor()\n\n useEffect(() => {\n const subscription = editor.on('*', props.on)\n\n return () => {\n subscription.unsubscribe()\n }\n }, [editor, props.on])\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAOG,eAAAC,OAAA;CAAA,IAAAC,IAAAC,EAAA,CAAA,GACLC,SAAeL,UAAU,GAACM,IAAAC;CAYG,OAZHJ,EAAA,OAAAE,UAAAF,EAAA,OAAAD,MAAAM,aAEhBF,WAAA;EACR,IAAAG,sBAA4BP,MAAKM,UAAUE,KAAKC,aAC9CN,OAAMO,iBAAkB,EAAAD,SAAS,CAAC,CACpC;EAAC,aAEM;GACLF,oBAAmBI,QAASC,OAE3B;EAAC;CACH,GACAP,KAAA,CAACF,QAAQH,MAAKM,SAAU,GAACL,EAAA,KAAAE,QAAAF,EAAA,KAAAD,MAAAM,WAAAL,EAAA,KAAAG,IAAAH,EAAA,KAAAI,OA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