@portabletext/editor 1.26.2 → 1.27.0

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 (45) hide show
  1. package/lib/_chunks-cjs/behavior.markdown.cjs +327 -0
  2. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -0
  3. package/lib/_chunks-cjs/plugin.event-listener.cjs +6568 -0
  4. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -0
  5. package/lib/_chunks-es/behavior.markdown.js +332 -0
  6. package/lib/_chunks-es/behavior.markdown.js.map +1 -0
  7. package/lib/_chunks-es/plugin.event-listener.js +6592 -0
  8. package/lib/_chunks-es/plugin.event-listener.js.map +1 -0
  9. package/lib/behaviors/index.cjs +2 -325
  10. package/lib/behaviors/index.cjs.map +1 -1
  11. package/lib/behaviors/index.d.cts +1 -1
  12. package/lib/behaviors/index.d.ts +1 -1
  13. package/lib/behaviors/index.js +2 -326
  14. package/lib/behaviors/index.js.map +1 -1
  15. package/lib/index.cjs +182 -6702
  16. package/lib/index.cjs.map +1 -1
  17. package/lib/index.d.cts +3269 -2178
  18. package/lib/index.d.ts +3269 -2178
  19. package/lib/index.js +144 -6681
  20. package/lib/index.js.map +1 -1
  21. package/lib/plugins/index.cjs +29 -0
  22. package/lib/plugins/index.cjs.map +1 -0
  23. package/lib/plugins/index.d.cts +19411 -0
  24. package/lib/plugins/index.d.ts +19411 -0
  25. package/lib/plugins/index.js +29 -0
  26. package/lib/plugins/index.js.map +1 -0
  27. package/lib/selectors/index.d.cts +1 -1
  28. package/lib/selectors/index.d.ts +1 -1
  29. package/package.json +13 -7
  30. package/src/editor/Editable.tsx +6 -6
  31. package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -1
  32. package/src/editor/components/Synchronizer.tsx +16 -1
  33. package/src/editor/create-editor.ts +8 -48
  34. package/src/editor/editor-machine.ts +130 -141
  35. package/src/editor/plugins/create-with-event-listeners.ts +19 -38
  36. package/src/editor/plugins/createWithPatches.ts +1 -1
  37. package/src/editor/plugins/createWithPortableTextSelections.ts +2 -2
  38. package/src/editor/sync-machine.ts +3 -5
  39. package/src/index.ts +5 -11
  40. package/src/plugins/_exports/index.ts +1 -0
  41. package/src/plugins/index.ts +3 -0
  42. package/src/plugins/plugin.editor-ref.tsx +17 -0
  43. package/src/{editor/editor-event-listener.tsx → plugins/plugin.event-listener.tsx} +7 -6
  44. package/src/plugins/plugin.markdown.tsx +70 -0
  45. package/src/type-utils.ts +12 -2
@@ -0,0 +1,29 @@
1
+ import { useEditor } from "../_chunks-es/plugin.event-listener.js";
2
+ import { EventListenerPlugin } from "../_chunks-es/plugin.event-listener.js";
3
+ import { c } from "react-compiler-runtime";
4
+ import React, { useEffect } from "react";
5
+ import { createMarkdownBehaviors } from "../_chunks-es/behavior.markdown.js";
6
+ const EditorRefPlugin = React.forwardRef((_, ref) => {
7
+ const $ = c(2), editor = useEditor(), portableTextEditorRef = React.useRef(editor);
8
+ let t0, t1;
9
+ 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;
10
+ });
11
+ EditorRefPlugin.displayName = "EditorRefPlugin";
12
+ function MarkdownPlugin(props) {
13
+ const editor = useEditor();
14
+ return useEffect(() => {
15
+ const unregisterBehaviors = createMarkdownBehaviors(props.config).map((behavior) => editor.registerBehavior({
16
+ behavior
17
+ }));
18
+ return () => {
19
+ for (const unregisterBehavior of unregisterBehaviors)
20
+ unregisterBehavior();
21
+ };
22
+ }, [editor, props.config]), null;
23
+ }
24
+ export {
25
+ EditorRefPlugin,
26
+ EventListenerPlugin,
27
+ MarkdownPlugin
28
+ };
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.markdown.tsx"],"sourcesContent":["import React from 'react'\nimport type {Editor} from '../editor/create-editor'\nimport {useEditor} from '../editor/editor-provider'\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 {\n createMarkdownBehaviors,\n type MarkdownBehaviorsConfig,\n} from '../behaviors/behavior.markdown'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport type MarkdownPluginConfig = MarkdownBehaviorsConfig\n\n/**\n * @beta\n * Add markdown behaviors for common markdown actions such as converting ### to headings, --- to HRs, and more.\n *\n * @example\n * Configure the bundled markdown behaviors\n * ```ts\n * import {EditorProvider} from '@portabletext/editor'\n * import {MarkdownPlugin} from '@portabletext/editor/plugins'\n *\n * function App() {\n * return (\n * <EditorProvider>\n * <MarkdownPlugin\n * config={{\n * horizontalRuleObject: ({schema}) => {\n * const name = schema.blockObjects.find(\n * (object) => object.name === 'break',\n * )?.name\n * return name ? {name} : undefined\n * },\n * defaultStyle: ({schema}) => schema.styles[0].value,\n * headingStyle: ({schema, level}) =>\n * schema.styles.find((style) => style.value === `h${level}`)\n * ?.value,\n * blockquoteStyle: ({schema}) =>\n * schema.styles.find((style) => style.value === 'blockquote')\n * ?.value,\n * unorderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'bullet')?.value,\n * orderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'number')?.value,\n * }}\n * />\n * {...}\n * </EditorProvider>\n * )\n * }\n */\nexport function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {\n const editor = useEditor()\n\n useEffect(() => {\n const behaviors = createMarkdownBehaviors(props.config)\n\n const unregisterBehaviors = behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n }, [editor, props.config])\n\n return null\n}\n"],"names":["EditorRefPlugin","React","forwardRef","_","ref","$","_c","editor","useEditor","portableTextEditorRef","useRef","t0","t1","Symbol","for","current","useImperativeHandle","displayName","MarkdownPlugin","props","useEffect","unregisterBehaviors","createMarkdownBehaviors","config","map","behavior","registerBehavior","unregisterBehavior"],"mappings":";;;;;AAOO,MAAMA,kBAAkBC,MAAMC,WAA0B,CAAAC,GAAAC,QAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA,GAC7DC,SAAeC,UAEfC,GAAAA,wBAA8BR,MAAAS,OAAaH,MAAM;AAAC,MAAAI,IAAAC;AAAA,SAAAP,EAAA,CAAA,MAAAQ,OAAAC,IAAA,2BAAA,KAEnBH,KAAAA,MAAMF,sBAAqBM,SAAUH,KAAA,CAAA,GAAEP,OAAAM,IAAAN,OAAAO,OAAAD,KAAAN,EAAA,CAAA,GAAAO,KAAAP,EAAA,CAAA,IAAtEJ,MAAAe,oBAA0BZ,KAAKO,IAAqCC,EAAE,GAAC;AAAA,CAGxE;AACDZ,gBAAgBiB,cAAc;ACmCvB,SAASC,eAAeC,OAAuC;AACpE,QAAMZ,SAASC,UAAU;AAEzBY,SAAAA,UAAU,MAAM;AAGRC,UAAAA,sBAFYC,wBAAwBH,MAAMI,MAAM,EAEhBC,IAAKC,CAAAA,aACzClB,OAAOmB,iBAAiB;AAAA,MAACD;AAAAA,IAAAA,CAAS,CACpC;AAEA,WAAO,MAAM;AACX,iBAAWE,sBAAsBN;AACZ,2BAAA;AAAA,IAEvB;AAAA,KACC,CAACd,QAAQY,MAAMI,MAAM,CAAC,GAElB;AACT;"}
@@ -358,7 +358,7 @@ export declare const isSelectionExpanded: EditorSelector<boolean>
358
358
  declare type MIMEType = `${string}/${string}`
359
359
 
360
360
  /**
361
- * @alpha
361
+ * @internal
362
362
  */
363
363
  declare type PickFromUnion<
364
364
  TUnion,
@@ -358,7 +358,7 @@ export declare const isSelectionExpanded: EditorSelector<boolean>
358
358
  declare type MIMEType = `${string}/${string}`
359
359
 
360
360
  /**
361
- * @alpha
361
+ * @internal
362
362
  */
363
363
  declare type PickFromUnion<
364
364
  TUnion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.26.2",
3
+ "version": "1.27.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -39,6 +39,12 @@
39
39
  "require": "./lib/behaviors/index.cjs",
40
40
  "default": "./lib/behaviors/index.js"
41
41
  },
42
+ "./plugins": {
43
+ "source": "./src/plugins/index.ts",
44
+ "import": "./lib/plugins/index.js",
45
+ "require": "./lib/plugins/index.cjs",
46
+ "default": "./lib/plugins/index.js"
47
+ },
42
48
  "./selectors": {
43
49
  "source": "./src/selectors/_exports/index.ts",
44
50
  "import": "./lib/selectors/index.js",
@@ -73,15 +79,15 @@
73
79
  "slate-react": "0.112.1",
74
80
  "use-effect-event": "^1.0.2",
75
81
  "xstate": "^5.19.2",
76
- "@portabletext/block-tools": "1.1.3",
82
+ "@portabletext/block-tools": "1.1.4",
77
83
  "@portabletext/patches": "1.1.2"
78
84
  },
79
85
  "devDependencies": {
80
86
  "@portabletext/toolkit": "^2.0.16",
81
87
  "@sanity/diff-match-patch": "^3.2.0",
82
- "@sanity/pkg-utils": "^7.0.2",
83
- "@sanity/schema": "^3.71.2",
84
- "@sanity/types": "^3.71.2",
88
+ "@sanity/pkg-utils": "^7.0.3",
89
+ "@sanity/schema": "^3.72.1",
90
+ "@sanity/types": "^3.72.1",
85
91
  "@testing-library/jest-dom": "^6.6.3",
86
92
  "@testing-library/react": "^16.2.0",
87
93
  "@types/debug": "^4.1.12",
@@ -109,8 +115,8 @@
109
115
  "racejar": "1.1.2"
110
116
  },
111
117
  "peerDependencies": {
112
- "@sanity/schema": "^3.71.2",
113
- "@sanity/types": "^3.71.2",
118
+ "@sanity/schema": "^3.72.1",
119
+ "@sanity/types": "^3.72.1",
114
120
  "react": "^16.9 || ^17 || ^18 || ^19",
115
121
  "rxjs": "^7.8.1"
116
122
  },
@@ -295,7 +295,7 @@ export const PortableTextEditable = forwardRef<
295
295
  // The selection is usually automatically emitted to change$ by the withPortableTextSelections plugin whenever there is a set_selection operation applied.
296
296
  if (!slateEditor.operations.some((o) => o.type === 'set_selection')) {
297
297
  editorActor.send({
298
- type: 'selection',
298
+ type: 'notify.selection',
299
299
  selection: normalizedSelection,
300
300
  })
301
301
  }
@@ -465,7 +465,7 @@ export const PortableTextEditable = forwardRef<
465
465
  event.preventDefault()
466
466
 
467
467
  // Resolve it as promise (can be either async promise or sync return value)
468
- editorActor.send({type: 'loading'})
468
+ editorActor.send({type: 'notify.loading'})
469
469
 
470
470
  Promise.resolve(onPasteResult)
471
471
  .then((result) => {
@@ -494,7 +494,7 @@ export const PortableTextEditable = forwardRef<
494
494
  return error
495
495
  })
496
496
  .finally(() => {
497
- editorActor.send({type: 'done loading'})
497
+ editorActor.send({type: 'notify.done loading'})
498
498
  })
499
499
  } else if (event.nativeEvent.clipboardData) {
500
500
  editorActor.send({
@@ -525,12 +525,12 @@ export const PortableTextEditable = forwardRef<
525
525
  Transforms.select(slateEditor, Editor.start(slateEditor, []))
526
526
  slateEditor.onChange()
527
527
  }
528
- editorActor.send({type: 'focused', event})
528
+ editorActor.send({type: 'notify.focused', event})
529
529
  const newSelection = PortableTextEditor.getSelection(portableTextEditor)
530
530
  // If the selection is the same, emit it explicitly here as there is no actual onChange event triggered.
531
531
  if (selection === newSelection) {
532
532
  editorActor.send({
533
- type: 'selection',
533
+ type: 'notify.selection',
534
534
  selection,
535
535
  })
536
536
  }
@@ -581,7 +581,7 @@ export const PortableTextEditable = forwardRef<
581
581
  onBlur(event)
582
582
  }
583
583
  if (!event.isPropagationStopped()) {
584
- editorActor.send({type: 'blurred', event})
584
+ editorActor.send({type: 'notify.blurred', event})
585
585
  }
586
586
  },
587
587
  [editorActor, onBlur],
@@ -32,7 +32,6 @@ describe('initialization', () => {
32
32
  await waitFor(() => {
33
33
  expect(editorRef.current).not.toBe(null)
34
34
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
35
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: undefined})
36
35
  expect(container).toMatchInlineSnapshot(`
37
36
  <div>
38
37
  <div
@@ -67,7 +67,22 @@ export function Synchronizer(props: SynchronizerProps) {
67
67
 
68
68
  useEffect(() => {
69
69
  const subscription = syncActorRef.on('*', (event) => {
70
- props.editorActor.send(event)
70
+ switch (event.type) {
71
+ case 'invalid value':
72
+ props.editorActor.send({
73
+ ...event,
74
+ type: 'notify.invalid value',
75
+ })
76
+ break
77
+ case 'value changed':
78
+ props.editorActor.send({
79
+ ...event,
80
+ type: 'notify.value changed',
81
+ })
82
+ break
83
+ default:
84
+ props.editorActor.send(event)
85
+ }
71
86
  })
72
87
 
73
88
  return () => {
@@ -11,10 +11,13 @@ import {
11
11
  type EventObject,
12
12
  type Snapshot,
13
13
  } from 'xstate'
14
- import type {Behavior, CustomBehaviorEvent} from '../behaviors/behavior.types'
14
+ import type {
15
+ Behavior,
16
+ CustomBehaviorEvent,
17
+ SyntheticBehaviorEvent,
18
+ } from '../behaviors/behavior.types'
15
19
  import {coreConverters} from '../converters/converters.core'
16
20
  import {compileType} from '../internal-utils/schema'
17
- import type {PickFromUnion} from '../type-utils'
18
21
  import type {EditableAPI} from '../types/editor'
19
22
  import {createEditorSchema} from './create-editor-schema'
20
23
  import {createSlateEditor, type SlateEditor} from './create-slate-editor'
@@ -23,7 +26,7 @@ import {
23
26
  editorMachine,
24
27
  type EditorActor,
25
28
  type EditorEmittedEvent,
26
- type InternalEditorEvent,
29
+ type ExternalEditorEvent,
27
30
  } from './editor-machine'
28
31
  import {getEditorSnapshot} from './editor-selector'
29
32
  import type {EditorSnapshot} from './editor-snapshot'
@@ -60,51 +63,8 @@ export type EditorConfig = {
60
63
  * @public
61
64
  */
62
65
  export type EditorEvent =
63
- | PickFromUnion<
64
- InternalEditorEvent,
65
- 'type',
66
- | 'annotation.add'
67
- | 'annotation.remove'
68
- | 'annotation.toggle'
69
- | 'block.set'
70
- | 'block.unset'
71
- | 'blur'
72
- | 'data transfer.set'
73
- | 'decorator.add'
74
- | 'decorator.remove'
75
- | 'decorator.toggle'
76
- | 'delete.block'
77
- | 'delete.text'
78
- | 'deserialization.failure'
79
- | 'deserialization.success'
80
- | 'focus'
81
- | 'insert.block'
82
- | 'insert.block object'
83
- | 'insert.inline object'
84
- | 'insert.span'
85
- | 'insert.text block'
86
- | 'list item.add'
87
- | 'list item.remove'
88
- | 'list item.toggle'
89
- | 'move.block'
90
- | 'move.block down'
91
- | 'move.block up'
92
- | 'select'
93
- | 'select.next block'
94
- | 'select.previous block'
95
- | 'serialization.failure'
96
- | 'serialization.success'
97
- | 'style.add'
98
- | 'style.remove'
99
- | 'style.toggle'
100
- | 'text block.set'
101
- | 'text block.unset'
102
- | 'patches'
103
- | 'update behaviors'
104
- | 'update key generator'
105
- | 'update readOnly'
106
- | 'update value'
107
- >
66
+ | ExternalEditorEvent
67
+ | SyntheticBehaviorEvent
108
68
  | CustomBehaviorEvent
109
69
 
110
70
  /**
@@ -21,7 +21,7 @@ import {
21
21
  type SyntheticBehaviorEvent,
22
22
  } from '../behaviors/behavior.types'
23
23
  import type {Converter} from '../converters/converter.types'
24
- import type {OmitFromUnion, PickFromUnion} from '../type-utils'
24
+ import type {NamespaceEvent} from '../type-utils'
25
25
  import type {
26
26
  EditorSelection,
27
27
  InvalidValueResolution,
@@ -34,17 +34,7 @@ import {withApplyingBehaviorActions} from './with-applying-behavior-actions'
34
34
  export * from 'xstate/guards'
35
35
 
36
36
  /**
37
- * @internal
38
- */
39
- export type EditorActor = ActorRefFrom<typeof editorMachine>
40
-
41
- /**
42
- * @internal
43
- */
44
- export type PatchEvent = {type: 'patch'; patch: Patch}
45
-
46
- /**
47
- * @internal
37
+ * @public
48
38
  */
49
39
  export type PatchesEvent = {
50
40
  type: 'patches'
@@ -53,7 +43,7 @@ export type PatchesEvent = {
53
43
  }
54
44
 
55
45
  /**
56
- * @internal
46
+ * @public
57
47
  */
58
48
  export type MutationEvent = {
59
49
  type: 'mutation'
@@ -66,26 +56,9 @@ export type MutationEvent = {
66
56
  }
67
57
 
68
58
  /**
69
- * @internal
59
+ * @public
70
60
  */
71
- export type InternalEditorEvent =
72
- | {type: 'normalizing'}
73
- | {type: 'done normalizing'}
74
- | {type: 'done syncing initial value'}
75
- | {
76
- type: 'behavior event'
77
- behaviorEvent: SyntheticBehaviorEvent | NativeBehaviorEvent
78
- editor: PortableTextSlateEditor
79
- defaultActionCallback?: () => void
80
- nativeEvent?: {preventDefault: () => void}
81
- }
82
- | {
83
- type: 'custom behavior event'
84
- behaviorEvent: CustomBehaviorEvent
85
- editor: PortableTextSlateEditor
86
- nativeEvent?: {preventDefault: () => void}
87
- }
88
- | CustomBehaviorEvent
61
+ export type ExternalEditorEvent =
89
62
  | {
90
63
  type: 'add behavior'
91
64
  behavior: Behavior
@@ -118,53 +91,21 @@ export type InternalEditorEvent =
118
91
  type: 'update maxBlocks'
119
92
  maxBlocks: number | undefined
120
93
  }
121
- | OmitFromUnion<
122
- InternalEditorEmittedEvent,
123
- 'type',
124
- 'ready' | 'read only' | 'editable'
125
- >
94
+ | PatchesEvent
126
95
 
127
96
  /**
128
97
  * @public
129
98
  */
130
- export type EditorEmittedEvent = PickFromUnion<
131
- InternalEditorEmittedEvent,
132
- 'type',
133
- | 'blurred'
134
- | 'done loading'
135
- | 'editable'
136
- | 'error'
137
- | 'focused'
138
- | 'invalid value'
139
- | 'loading'
140
- | 'mutation'
141
- | 'patch'
142
- | 'read only'
143
- | 'ready'
144
- | 'selection'
145
- | 'value changed'
146
- >
147
-
148
- /**
149
- * @internal
150
- */
151
- export type InternalEditorEmittedEvent =
152
- | {type: 'ready'}
153
- | PatchEvent
154
- | PatchesEvent
155
- | MutationEvent
99
+ export type EditorEmittedEvent =
156
100
  | {
157
- type: 'unset'
158
- previousValue: Array<PortableTextBlock>
101
+ type: 'blurred'
102
+ event: FocusEvent<HTMLDivElement, Element>
159
103
  }
160
104
  | {
161
- type: 'value changed'
162
- value: Array<PortableTextBlock> | undefined
105
+ type: 'done loading'
163
106
  }
164
107
  | {
165
- type: 'invalid value'
166
- resolution: InvalidValueResolution | null
167
- value: Array<PortableTextBlock> | undefined
108
+ type: 'editable'
168
109
  }
169
110
  | {
170
111
  type: 'error'
@@ -172,59 +113,96 @@ export type InternalEditorEmittedEvent =
172
113
  description: string
173
114
  data: unknown
174
115
  }
175
- | {type: 'selection'; selection: EditorSelection}
176
- | {type: 'blurred'; event: FocusEvent<HTMLDivElement, Element>}
177
- | {type: 'focused'; event: FocusEvent<HTMLDivElement, Element>}
178
- | {type: 'loading'}
179
- | {type: 'done loading'}
180
- | {type: 'read only'}
181
- | {type: 'editable'}
182
- | PickFromUnion<
183
- SyntheticBehaviorEvent,
184
- 'type',
185
- | 'annotation.add'
186
- | 'annotation.remove'
187
- | 'annotation.toggle'
188
- | 'block.set'
189
- | 'block.unset'
190
- | 'blur'
191
- | 'data transfer.set'
192
- | 'decorator.add'
193
- | 'decorator.remove'
194
- | 'decorator.toggle'
195
- | 'delete.backward'
196
- | 'delete.block'
197
- | 'delete.forward'
198
- | 'delete.text'
199
- | 'deserialization.failure'
200
- | 'deserialization.success'
201
- | 'focus'
202
- | 'insert.block'
203
- | 'insert.block object'
204
- | 'insert.inline object'
205
- | 'insert.span'
206
- | 'insert.text block'
207
- | 'list item.add'
208
- | 'list item.remove'
209
- | 'list item.toggle'
210
- | 'move.block'
211
- | 'move.block down'
212
- | 'move.block up'
213
- | 'select'
214
- | 'select.next block'
215
- | 'select.previous block'
216
- | 'serialization.failure'
217
- | 'serialization.success'
218
- | 'style.add'
219
- | 'style.remove'
220
- | 'style.toggle'
221
- | 'text block.set'
222
- | 'text block.unset'
223
- >
116
+ | {
117
+ type: 'focused'
118
+ event: FocusEvent<HTMLDivElement, Element>
119
+ }
120
+ | {
121
+ type: 'invalid value'
122
+ resolution: InvalidValueResolution | null
123
+ value: Array<PortableTextBlock> | undefined
124
+ }
125
+ | {
126
+ type: 'loading'
127
+ }
128
+ | MutationEvent
129
+ | PatchEvent
130
+ | {
131
+ type: 'read only'
132
+ }
133
+ | {
134
+ type: 'ready'
135
+ }
136
+ | {
137
+ type: 'selection'
138
+ selection: EditorSelection
139
+ }
140
+ | {
141
+ type: 'value changed'
142
+ value: Array<PortableTextBlock> | undefined
143
+ }
144
+
145
+ type PatchEvent = {
146
+ type: 'patch'
147
+ patch: Patch
148
+ }
149
+
150
+ type UnsetEvent = {
151
+ type: 'unset'
152
+ previousValue: Array<PortableTextBlock>
153
+ }
154
+
155
+ /**
156
+ * @internal
157
+ */
158
+ export type EditorActor = ActorRefFrom<typeof editorMachine>
159
+
160
+ /**
161
+ * @internal
162
+ */
163
+ export type InternalEditorEvent =
164
+ | {
165
+ type: 'normalizing'
166
+ }
167
+ | {
168
+ type: 'done normalizing'
169
+ }
170
+ | {
171
+ type: 'done syncing initial value'
172
+ }
173
+ | {
174
+ type: 'behavior event'
175
+ behaviorEvent: SyntheticBehaviorEvent | NativeBehaviorEvent
176
+ editor: PortableTextSlateEditor
177
+ defaultActionCallback?: () => void
178
+ nativeEvent?: {preventDefault: () => void}
179
+ }
180
+ | {
181
+ type: 'custom behavior event'
182
+ behaviorEvent: CustomBehaviorEvent
183
+ editor: PortableTextSlateEditor
184
+ nativeEvent?: {preventDefault: () => void}
185
+ }
186
+ | CustomBehaviorEvent
187
+ | ExternalEditorEvent
188
+ | MutationEvent
189
+ | NamespaceEvent<EditorEmittedEvent, 'notify'>
190
+ | NamespaceEvent<UnsetEvent, 'notify'>
191
+ | PatchEvent
192
+ | SyntheticBehaviorEvent
193
+
194
+ /**
195
+ * @internal
196
+ */
197
+ export type InternalEditorEmittedEvent =
198
+ | EditorEmittedEvent
199
+ | PatchesEvent
200
+ | UnsetEvent
224
201
  | {
225
202
  type: 'custom.*'
226
203
  event: CustomBehaviorEvent
227
204
  }
205
+ | SyntheticBehaviorEvent
228
206
 
229
207
  /**
230
208
  * @internal
@@ -514,23 +492,32 @@ export const editorMachine = setup({
514
492
  value: input.value,
515
493
  }),
516
494
  on: {
517
- 'add behavior': {actions: 'add behavior to context'},
518
- 'remove behavior': {actions: 'remove behavior from context'},
519
- 'unset': {actions: emit(({event}) => event)},
520
- 'value changed': {actions: emit(({event}) => event)},
521
- 'invalid value': {actions: emit(({event}) => event)},
522
- 'error': {actions: emit(({event}) => event)},
523
- 'selection': {
495
+ 'notify.blurred': {
496
+ actions: emit(({event}) => ({...event, type: 'blurred'})),
497
+ },
498
+ 'notify.done loading': {actions: emit({type: 'done loading'})},
499
+ 'notify.error': {actions: emit(({event}) => ({...event, type: 'error'}))},
500
+ 'notify.invalid value': {
501
+ actions: emit(({event}) => ({...event, type: 'invalid value'})),
502
+ },
503
+ 'notify.focused': {
504
+ actions: emit(({event}) => ({...event, type: 'focused'})),
505
+ },
506
+ 'notify.selection': {
524
507
  actions: [
525
508
  assign({selection: ({event}) => event.selection}),
526
- emit(({event}) => event),
509
+ emit(({event}) => ({...event, type: 'selection'})),
527
510
  ],
528
511
  },
529
- 'blurred': {actions: emit(({event}) => event)},
530
- 'focused': {actions: emit(({event}) => event)},
531
- 'loading': {actions: emit({type: 'loading'})},
512
+ 'notify.unset': {actions: emit(({event}) => ({...event, type: 'unset'}))},
513
+ 'notify.loading': {actions: emit({type: 'loading'})},
514
+ 'notify.value changed': {
515
+ actions: emit(({event}) => ({...event, type: 'value changed'})),
516
+ },
517
+
518
+ 'add behavior': {actions: 'add behavior to context'},
519
+ 'remove behavior': {actions: 'remove behavior from context'},
532
520
  'patches': {actions: emit(({event}) => event)},
533
- 'done loading': {actions: emit({type: 'done loading'})},
534
521
  'update behaviors': {actions: 'assign behaviors'},
535
522
  'update key generator': {
536
523
  actions: assign({keyGenerator: ({event}) => event.keyGenerator}),
@@ -548,6 +535,18 @@ export const editorMachine = setup({
548
535
  states: {
549
536
  'read only': {
550
537
  initial: 'determine initial edit mode',
538
+ on: {
539
+ 'behavior event': {
540
+ actions: 'handle behavior event',
541
+ guard: ({event}) =>
542
+ event.behaviorEvent.type === 'copy' ||
543
+ event.behaviorEvent.type === 'data transfer.set' ||
544
+ event.behaviorEvent.type === 'serialize' ||
545
+ event.behaviorEvent.type === 'serialization.failure' ||
546
+ event.behaviorEvent.type === 'serialization.success' ||
547
+ event.behaviorEvent.type === 'select',
548
+ },
549
+ },
551
550
  states: {
552
551
  'determine initial edit mode': {
553
552
  on: {
@@ -564,16 +563,6 @@ export const editorMachine = setup({
564
563
  },
565
564
  'read only': {
566
565
  on: {
567
- 'behavior event': {
568
- actions: 'handle behavior event',
569
- guard: ({event}) =>
570
- event.behaviorEvent.type === 'copy' ||
571
- event.behaviorEvent.type === 'data transfer.set' ||
572
- event.behaviorEvent.type === 'serialize' ||
573
- event.behaviorEvent.type === 'serialization.failure' ||
574
- event.behaviorEvent.type === 'serialization.success' ||
575
- event.behaviorEvent.type === 'select',
576
- },
577
566
  'update readOnly': {
578
567
  guard: ({event}) => !event.readOnly,
579
568
  target: '#editor.edit mode.editable',