@portabletext/editor 1.17.1 → 1.18.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 (56) hide show
  1. package/README.md +228 -261
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  4. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -1
  5. package/lib/_chunks-es/behavior.core.js.map +1 -1
  6. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  7. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -1
  8. package/lib/behaviors/index.cjs +4 -1
  9. package/lib/behaviors/index.cjs.map +1 -1
  10. package/lib/behaviors/index.d.cts +23 -23
  11. package/lib/behaviors/index.d.ts +23 -23
  12. package/lib/behaviors/index.js +4 -1
  13. package/lib/behaviors/index.js.map +1 -1
  14. package/lib/index.cjs +78 -69
  15. package/lib/index.cjs.map +1 -1
  16. package/lib/index.d.cts +123 -753
  17. package/lib/index.d.ts +123 -753
  18. package/lib/index.js +78 -69
  19. package/lib/index.js.map +1 -1
  20. package/lib/selectors/index.cjs.map +1 -1
  21. package/lib/selectors/index.d.cts +30 -30
  22. package/lib/selectors/index.d.ts +30 -30
  23. package/lib/selectors/index.js.map +1 -1
  24. package/package.json +8 -8
  25. package/src/behaviors/behavior.code-editor.ts +2 -2
  26. package/src/behaviors/behavior.core.ts +2 -2
  27. package/src/behaviors/behavior.emoji-picker.ts +8 -3
  28. package/src/behaviors/behavior.links.ts +2 -2
  29. package/src/behaviors/behavior.markdown.ts +2 -2
  30. package/src/behaviors/behavior.types.ts +10 -10
  31. package/src/editor/PortableTextEditor.tsx +2 -0
  32. package/src/editor/__tests__/self-solving.test.tsx +14 -0
  33. package/src/editor/components/Synchronizer.tsx +6 -1
  34. package/src/editor/create-editor.ts +14 -3
  35. package/src/editor/define-schema.ts +4 -4
  36. package/src/editor/editor-event-listener.tsx +1 -1
  37. package/src/editor/editor-machine.ts +42 -52
  38. package/src/editor/editor-provider.tsx +3 -3
  39. package/src/editor/editor-selector.ts +31 -14
  40. package/src/editor/editor-snapshot.ts +2 -2
  41. package/src/editor/get-value.ts +12 -5
  42. package/src/editor/hooks/usePortableTextEditor.ts +1 -0
  43. package/src/editor/hooks/usePortableTextEditorSelection.tsx +1 -0
  44. package/src/selectors/selector.get-active-list-item.ts +1 -1
  45. package/src/selectors/selector.get-active-style.ts +1 -1
  46. package/src/selectors/selector.get-selected-spans.ts +1 -1
  47. package/src/selectors/selector.get-selection-text.ts +1 -1
  48. package/src/selectors/selector.get-text-before.ts +1 -1
  49. package/src/selectors/selector.is-active-annotation.ts +1 -1
  50. package/src/selectors/selector.is-active-decorator.ts +1 -1
  51. package/src/selectors/selector.is-active-list-item.ts +1 -1
  52. package/src/selectors/selector.is-active-style.ts +1 -1
  53. package/src/selectors/selector.is-selection-collapsed.ts +1 -1
  54. package/src/selectors/selector.is-selection-expanded.ts +1 -1
  55. package/src/selectors/selectors.ts +13 -13
  56. package/src/types/editor.ts +2 -2
@@ -9,7 +9,7 @@ const softReturn = defineBehavior({
9
9
  })
10
10
 
11
11
  /**
12
- * @alpha
12
+ * @beta
13
13
  */
14
14
  export const coreBehaviors = [
15
15
  softReturn,
@@ -29,7 +29,7 @@ export const coreBehaviors = [
29
29
  ]
30
30
 
31
31
  /**
32
- * @alpha
32
+ * @beta
33
33
  */
34
34
  export const coreBehavior = {
35
35
  softReturn,
@@ -8,7 +8,7 @@ const incompleteEmojiRegEx = /:([a-zA-Z-_0-9]+)$/
8
8
  const emojiRegEx = /:([a-zA-Z-_0-9]+):$/
9
9
 
10
10
  /**
11
- * @alpha
11
+ * @beta
12
12
  */
13
13
  export type EmojiPickerBehaviorsConfig<TEmojiMatch> = {
14
14
  /**
@@ -24,7 +24,7 @@ export type EmojiPickerBehaviorsConfig<TEmojiMatch> = {
24
24
  }
25
25
 
26
26
  /**
27
- * @alpha
27
+ * @beta
28
28
  */
29
29
  export function createEmojiPickerBehaviors<TEmojiMatch>(
30
30
  config: EmojiPickerBehaviorsConfig<TEmojiMatch>,
@@ -146,6 +146,12 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
146
146
  defineBehavior({
147
147
  on: 'key.down',
148
148
  guard: ({context, event}) => {
149
+ const matches = emojiPickerActor.getSnapshot().context.matches
150
+
151
+ if (matches.length === 0) {
152
+ return false
153
+ }
154
+
149
155
  const isShift = isHotkey('Shift', event.keyboardEvent)
150
156
  const isColon = event.keyboardEvent.key === ':'
151
157
  const isEmojiChar = emojiCharRegEx.test(event.keyboardEvent.key)
@@ -158,7 +164,6 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
158
164
  const isArrowUp = isHotkey('ArrowUp', event.keyboardEvent)
159
165
  const isEnter = isHotkey('Enter', event.keyboardEvent)
160
166
  const isTab = isHotkey('Tab', event.keyboardEvent)
161
- const matches = emojiPickerActor.getSnapshot().context.matches
162
167
 
163
168
  if (isEnter || isTab) {
164
169
  const selectedIndex =
@@ -3,7 +3,7 @@ import * as selectors from '../selectors'
3
3
  import {defineBehavior} from './behavior.types'
4
4
 
5
5
  /**
6
- * @alpha
6
+ * @beta
7
7
  */
8
8
  export type LinkBehaviorsConfig = {
9
9
  linkAnnotation?: (context: {
@@ -13,7 +13,7 @@ export type LinkBehaviorsConfig = {
13
13
  }
14
14
 
15
15
  /**
16
- * @alpha
16
+ * @beta
17
17
  */
18
18
  export function createLinkBehaviors(config: LinkBehaviorsConfig) {
19
19
  const pasteLinkOnSelection = defineBehavior({
@@ -7,7 +7,7 @@ import {getBlockTextBefore} from '../selectors/selector.get-text-before'
7
7
  import {defineBehavior} from './behavior.types'
8
8
 
9
9
  /**
10
- * @alpha
10
+ * @beta
11
11
  */
12
12
  export type MarkdownBehaviorsConfig = {
13
13
  horizontalRuleObject?: (context: {
@@ -24,7 +24,7 @@ export type MarkdownBehaviorsConfig = {
24
24
  }
25
25
 
26
26
  /**
27
- * @alpha
27
+ * @beta
28
28
  */
29
29
  export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
30
30
  const automaticBlockquoteOnSpace = defineBehavior({
@@ -6,7 +6,7 @@ import type {PickFromUnion} from '../type-utils'
6
6
  import type {EditorSelection, PortableTextSlateEditor} from '../types/editor'
7
7
 
8
8
  /**
9
- * @alpha
9
+ * @beta
10
10
  */
11
11
  export type SyntheticBehaviorEvent =
12
12
  | {
@@ -91,7 +91,7 @@ export type SyntheticBehaviorEvent =
91
91
  }
92
92
 
93
93
  /**
94
- * @alpha
94
+ * @beta
95
95
  */
96
96
  export type NativeBehaviorEvent =
97
97
  | {
@@ -118,7 +118,7 @@ export type NativeBehaviorEvent =
118
118
  }
119
119
 
120
120
  /**
121
- * @alpha
121
+ * @beta
122
122
  */
123
123
  export type BehaviorActionIntend =
124
124
  | SyntheticBehaviorEvent
@@ -210,19 +210,19 @@ export type BehaviorActionIntend =
210
210
  }
211
211
 
212
212
  /**
213
- * @alpha
213
+ * @beta
214
214
  */
215
215
  export type BehaviorAction = BehaviorActionIntend & {
216
216
  editor: PortableTextSlateEditor
217
217
  }
218
218
 
219
219
  /**
220
- * @alpha
220
+ * @beta
221
221
  */
222
222
  export type BehaviorEvent = SyntheticBehaviorEvent | NativeBehaviorEvent
223
223
 
224
224
  /**
225
- * @alpha
225
+ * @beta
226
226
  */
227
227
  export type Behavior<
228
228
  TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
@@ -248,7 +248,7 @@ export type Behavior<
248
248
  }
249
249
 
250
250
  /**
251
- * @alpha
251
+ * @beta
252
252
  */
253
253
  export type BehaviorGuard<
254
254
  TBehaviorEvent extends BehaviorEvent,
@@ -262,7 +262,7 @@ export type BehaviorGuard<
262
262
  }) => TGuardResponse | false
263
263
 
264
264
  /**
265
- * @alpha
265
+ * @beta
266
266
  */
267
267
  export type BehaviorActionIntendSet<
268
268
  TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
@@ -279,7 +279,7 @@ export type BehaviorActionIntendSet<
279
279
  ) => Array<BehaviorActionIntend>
280
280
 
281
281
  /**
282
- * @alpha
282
+ * @beta
283
283
  */
284
284
  export function defineBehavior<
285
285
  TAnyBehaviorEventType extends BehaviorEvent['type'],
@@ -289,7 +289,7 @@ export function defineBehavior<
289
289
  }
290
290
 
291
291
  /**
292
- * @alpha
292
+ * @beta
293
293
  */
294
294
  export type BlockOffset = {
295
295
  path: [KeyedSegment]
@@ -42,6 +42,7 @@ const debug = debugWithName('component:PortableTextEditor')
42
42
  * Props for the PortableTextEditor component
43
43
  *
44
44
  * @public
45
+ * @deprecated Use `EditorProvider` instead
45
46
  */
46
47
  export type PortableTextEditorProps<
47
48
  TEditor extends Editor | undefined = undefined,
@@ -106,6 +107,7 @@ export type PortableTextEditorProps<
106
107
  /**
107
108
  * The main Portable Text Editor component.
108
109
  * @public
110
+ * @deprecated Use `EditorProvider` instead
109
111
  */
110
112
  export class PortableTextEditor extends Component<
111
113
  PortableTextEditorProps<Editor | undefined>
@@ -169,6 +169,20 @@ describe('Feature: Self-solving', () => {
169
169
  markDefs: [],
170
170
  }),
171
171
  ],
172
+ value: [
173
+ block({
174
+ _key: 'b1',
175
+ children: [
176
+ span({
177
+ _key: 's1',
178
+ text: 'foo',
179
+ marks: ['strong'],
180
+ }),
181
+ ],
182
+ style: 'normal',
183
+ markDefs: [],
184
+ }),
185
+ ],
172
186
  })
173
187
  }
174
188
  })
@@ -51,7 +51,12 @@ export function Synchronizer(props: SynchronizerProps) {
51
51
  }
52
52
  if (event.type === 'mutation') {
53
53
  syncActorRef.send({type: 'mutation'})
54
- editorActor.send(event)
54
+ editorActor.send({
55
+ type: 'mutation',
56
+ patches: event.patches,
57
+ snapshot: event.snapshot,
58
+ value: event.snapshot,
59
+ })
55
60
  }
56
61
  })
57
62
 
@@ -24,13 +24,18 @@ import {
24
24
  type EditorEmittedEvent,
25
25
  type InternalEditorEvent,
26
26
  } from './editor-machine'
27
+ import {getEditorSnapshot} from './editor-selector'
28
+ import type {EditorSnapshot} from './editor-snapshot'
27
29
  import {defaultKeyGenerator} from './key-generator'
28
30
  import {createEditableAPI} from './plugins/createWithEditableAPI'
29
31
 
30
32
  /**
31
- * @alpha
33
+ * @public
32
34
  */
33
35
  export type EditorConfig = {
36
+ /**
37
+ * @beta
38
+ */
34
39
  behaviors?: Array<Behavior>
35
40
  keyGenerator?: () => string
36
41
  /**
@@ -51,7 +56,7 @@ export type EditorConfig = {
51
56
  )
52
57
 
53
58
  /**
54
- * @alpha
59
+ * @public
55
60
  */
56
61
  export type EditorEvent = PickFromUnion<
57
62
  InternalEditorEvent,
@@ -75,9 +80,10 @@ export type EditorEvent = PickFromUnion<
75
80
  >
76
81
 
77
82
  /**
78
- * @alpha
83
+ * @public
79
84
  */
80
85
  export type Editor = {
86
+ getSnapshot: () => EditorSnapshot
81
87
  send: (event: EditorEvent) => void
82
88
  on: ActorRef<Snapshot<unknown>, EventObject, EditorEmittedEvent>['on']
83
89
  _internal: {
@@ -126,6 +132,11 @@ function createEditorFromActor(editorActor: EditorActor): Editor {
126
132
  const editable = createEditableAPI(slateEditor.instance, editorActor)
127
133
 
128
134
  return {
135
+ getSnapshot: () =>
136
+ getEditorSnapshot({
137
+ editorActorSnapshot: editorActor.getSnapshot(),
138
+ slateEditorInstance: slateEditor.instance,
139
+ }),
129
140
  send: (event) => {
130
141
  editorActor.send(event)
131
142
  },
@@ -10,7 +10,7 @@ import type {PortableTextMemberSchemaTypes} from '../types/editor'
10
10
  import {createEditorSchema} from './create-editor-schema'
11
11
 
12
12
  /**
13
- * @alpha
13
+ * @public
14
14
  */
15
15
  export type BaseDefinition = {
16
16
  name: string
@@ -19,7 +19,7 @@ export type BaseDefinition = {
19
19
  }
20
20
 
21
21
  /**
22
- * @alpha
22
+ * @public
23
23
  */
24
24
  export type SchemaDefinition<
25
25
  TBaseDefinition extends BaseDefinition = BaseDefinition,
@@ -33,7 +33,7 @@ export type SchemaDefinition<
33
33
  }
34
34
 
35
35
  /**
36
- * @alpha
36
+ * @public
37
37
  */
38
38
  export function defineSchema<const TSchemaDefinition extends SchemaDefinition>(
39
39
  definition: TSchemaDefinition,
@@ -42,7 +42,7 @@ export function defineSchema<const TSchemaDefinition extends SchemaDefinition>(
42
42
  }
43
43
 
44
44
  /**
45
- * @alpha
45
+ * @public
46
46
  */
47
47
  export type EditorSchema = PortableTextMemberSchemaTypes
48
48
 
@@ -4,7 +4,7 @@ import type {EditorEmittedEvent} from './editor-machine'
4
4
  import {useEditor} from './editor-provider'
5
5
 
6
6
  /**
7
- * @alpha
7
+ * @public
8
8
  */
9
9
  export function EditorEventListener(props: {
10
10
  on: (event: EditorEmittedEvent) => void
@@ -15,7 +15,6 @@ import {coreBehaviors} from '../behaviors/behavior.core'
15
15
  import type {
16
16
  Behavior,
17
17
  BehaviorAction,
18
- BehaviorActionIntend,
19
18
  NativeBehaviorEvent,
20
19
  SyntheticBehaviorEvent,
21
20
  } from '../behaviors/behavior.types'
@@ -59,7 +58,11 @@ export type PatchesEvent = {
59
58
  export type MutationEvent = {
60
59
  type: 'mutation'
61
60
  patches: Array<Patch>
61
+ /**
62
+ * @deprecated Use `value` instead
63
+ */
62
64
  snapshot: Array<PortableTextBlock> | undefined
65
+ value: Array<PortableTextBlock> | undefined
63
66
  }
64
67
 
65
68
  /**
@@ -75,11 +78,6 @@ export type InternalEditorEvent =
75
78
  editor: PortableTextSlateEditor
76
79
  nativeEvent?: {preventDefault: () => void}
77
80
  }
78
- | {
79
- type: 'behavior action intends'
80
- editor: PortableTextSlateEditor
81
- actionIntends: Array<BehaviorActionIntend>
82
- }
83
81
  | {
84
82
  type: 'update readOnly'
85
83
  readOnly: boolean
@@ -107,7 +105,7 @@ export type InternalEditorEvent =
107
105
  >
108
106
 
109
107
  /**
110
- * @alpha
108
+ * @public
111
109
  */
112
110
  export type EditorEmittedEvent = PickFromUnion<
113
111
  InternalEditorEmittedEvent,
@@ -265,11 +263,13 @@ export const editorMachine = setup({
265
263
  return
266
264
  }
267
265
 
268
- enqueue.raise({
269
- type: 'behavior action intends',
270
- editor: event.editor,
271
- actionIntends: [defaultAction],
266
+ Editor.withoutNormalizing(event.editor, () => {
267
+ performAction({
268
+ context,
269
+ action: defaultAction,
270
+ })
272
271
  })
272
+ event.editor.onChange()
273
273
  return
274
274
  }
275
275
 
@@ -324,11 +324,32 @@ export const editorMachine = setup({
324
324
  (actionIntend) => actionIntend.type !== 'effect',
325
325
  ))
326
326
 
327
- enqueue.raise({
328
- type: 'behavior action intends',
329
- editor: event.editor,
330
- actionIntends,
327
+ Editor.withoutNormalizing(event.editor, () => {
328
+ for (const actionIntend of actionIntends) {
329
+ const action = {
330
+ ...actionIntend,
331
+ editor: event.editor,
332
+ }
333
+
334
+ performAction({context, action})
335
+ }
331
336
  })
337
+ event.editor.onChange()
338
+
339
+ if (
340
+ actionIntends.some(
341
+ (actionIntend) => actionIntend.type === 'reselect',
342
+ )
343
+ ) {
344
+ enqueue.raise({
345
+ type: 'selection',
346
+ selection: toPortableTextRange(
347
+ event.editor.children,
348
+ event.editor.selection,
349
+ context.schema,
350
+ ),
351
+ })
352
+ }
332
353
  }
333
354
 
334
355
  if (behaviorOverwritten) {
@@ -342,11 +363,13 @@ export const editorMachine = setup({
342
363
  return
343
364
  }
344
365
 
345
- enqueue.raise({
346
- type: 'behavior action intends',
347
- editor: event.editor,
348
- actionIntends: [defaultAction],
366
+ Editor.withoutNormalizing(event.editor, () => {
367
+ performAction({
368
+ context,
369
+ action: defaultAction,
370
+ })
349
371
  })
372
+ event.editor.onChange()
350
373
  }
351
374
  }),
352
375
  },
@@ -384,39 +407,6 @@ export const editorMachine = setup({
384
407
  'update maxBlocks': {
385
408
  actions: assign({maxBlocks: ({event}) => event.maxBlocks}),
386
409
  },
387
- 'behavior action intends': {
388
- actions: [
389
- ({context, event}) => {
390
- Editor.withoutNormalizing(event.editor, () => {
391
- for (const actionIntend of event.actionIntends) {
392
- const action = {
393
- ...actionIntend,
394
- editor: event.editor,
395
- }
396
-
397
- performAction({context, action})
398
- }
399
- })
400
- event.editor.onChange()
401
- },
402
- enqueueActions(({context, event, enqueue}) => {
403
- if (
404
- event.actionIntends.some(
405
- (actionIntend) => actionIntend.type === 'reselect',
406
- )
407
- ) {
408
- enqueue.raise({
409
- type: 'selection',
410
- selection: toPortableTextRange(
411
- event.editor.children,
412
- event.editor.selection,
413
- context.schema,
414
- ),
415
- })
416
- }
417
- }),
418
- ],
419
- },
420
410
  },
421
411
  type: 'parallel',
422
412
  states: {
@@ -14,7 +14,7 @@ import {
14
14
  const EditorContext = React.createContext<Editor | undefined>(undefined)
15
15
 
16
16
  /**
17
- * @alpha
17
+ * @public
18
18
  */
19
19
  export type EditorProviderProps = {
20
20
  initialConfig: EditorConfig
@@ -22,7 +22,7 @@ export type EditorProviderProps = {
22
22
  }
23
23
 
24
24
  /**
25
- * @alpha
25
+ * @public
26
26
  */
27
27
  export function EditorProvider(props: EditorProviderProps) {
28
28
  const editor = useCreateEditor(props.initialConfig)
@@ -65,7 +65,7 @@ export function EditorProvider(props: EditorProviderProps) {
65
65
  }
66
66
 
67
67
  /**
68
- * @alpha
68
+ * @public
69
69
  */
70
70
  export function useEditor() {
71
71
  const editor = React.useContext(EditorContext)
@@ -1,5 +1,7 @@
1
1
  import {useSelector} from '@xstate/react'
2
+ import type {PortableTextSlateEditor} from '../types/editor'
2
3
  import type {Editor} from './create-editor'
4
+ import type {EditorActor} from './editor-machine'
3
5
  import type {EditorSnapshot} from './editor-snapshot'
4
6
  import {getActiveDecorators} from './get-active-decorators'
5
7
  import {getValue} from './get-value'
@@ -9,12 +11,12 @@ function defaultCompare<T>(a: T, b: T) {
9
11
  }
10
12
 
11
13
  /**
12
- * @alpha
14
+ * @public
13
15
  */
14
16
  export type EditorSelector<TSelected> = (snapshot: EditorSnapshot) => TSelected
15
17
 
16
18
  /**
17
- * @alpha
19
+ * @public
18
20
  */
19
21
  export function useEditorSelector<TSelected>(
20
22
  editor: Editor,
@@ -23,20 +25,35 @@ export function useEditorSelector<TSelected>(
23
25
  ) {
24
26
  return useSelector(
25
27
  editor._internal.editorActor,
26
- (snapshot) => {
27
- const context = {
28
- activeDecorators: getActiveDecorators({
29
- schema: snapshot.context.schema,
30
- slateEditorInstance: editor._internal.slateEditor.instance,
31
- }),
32
- keyGenerator: snapshot.context.keyGenerator,
33
- schema: snapshot.context.schema,
34
- selection: snapshot.context.selection,
35
- value: getValue(editor),
36
- }
28
+ (editorActorSnapshot) => {
29
+ const snapshot = getEditorSnapshot({
30
+ editorActorSnapshot,
31
+ slateEditorInstance: editor._internal.slateEditor.instance,
32
+ })
37
33
 
38
- return selector({context})
34
+ return selector(snapshot)
39
35
  },
40
36
  compare,
41
37
  )
42
38
  }
39
+
40
+ export function getEditorSnapshot({
41
+ editorActorSnapshot,
42
+ slateEditorInstance,
43
+ }: {
44
+ editorActorSnapshot: ReturnType<EditorActor['getSnapshot']>
45
+ slateEditorInstance: PortableTextSlateEditor
46
+ }): EditorSnapshot {
47
+ return {
48
+ context: {
49
+ activeDecorators: getActiveDecorators({
50
+ schema: editorActorSnapshot.context.schema,
51
+ slateEditorInstance,
52
+ }),
53
+ keyGenerator: editorActorSnapshot.context.keyGenerator,
54
+ schema: editorActorSnapshot.context.schema,
55
+ selection: editorActorSnapshot.context.selection,
56
+ value: getValue({editorActorSnapshot, slateEditorInstance}),
57
+ },
58
+ }
59
+ }
@@ -3,7 +3,7 @@ import type {EditorSelection} from '../types/editor'
3
3
  import type {EditorSchema} from './define-schema'
4
4
 
5
5
  /**
6
- * @alpha
6
+ * @public
7
7
  */
8
8
  export type EditorContext = {
9
9
  activeDecorators: Array<string>
@@ -14,7 +14,7 @@ export type EditorContext = {
14
14
  }
15
15
 
16
16
  /**
17
- * @alpha
17
+ * @public
18
18
  */
19
19
  export type EditorSnapshot = {
20
20
  context: EditorContext
@@ -1,11 +1,18 @@
1
+ import type {PortableTextSlateEditor} from '../types/editor'
1
2
  import {fromSlateValue} from '../utils/values'
2
3
  import {KEY_TO_VALUE_ELEMENT} from '../utils/weakMaps'
3
- import type {Editor} from './create-editor'
4
+ import type {EditorActor} from './editor-machine'
4
5
 
5
- export function getValue(editor: Editor) {
6
+ export function getValue({
7
+ editorActorSnapshot,
8
+ slateEditorInstance,
9
+ }: {
10
+ editorActorSnapshot: ReturnType<EditorActor['getSnapshot']>
11
+ slateEditorInstance: PortableTextSlateEditor
12
+ }) {
6
13
  return fromSlateValue(
7
- editor._internal.slateEditor.instance.children,
8
- editor._internal.editorActor.getSnapshot().context.schema.block.name,
9
- KEY_TO_VALUE_ELEMENT.get(editor._internal.slateEditor.instance),
14
+ slateEditorInstance.children,
15
+ editorActorSnapshot.context.schema.block.name,
16
+ KEY_TO_VALUE_ELEMENT.get(slateEditorInstance),
10
17
  )
11
18
  }
@@ -8,6 +8,7 @@ export const PortableTextEditorContext =
8
8
  createContext<PortableTextEditor | null>(null)
9
9
 
10
10
  /**
11
+ * @deprecated Use `useEditor` to get the current editor instance.
11
12
  * @public
12
13
  * Get the current editor object from the React context.
13
14
  */
@@ -16,6 +16,7 @@ const PortableTextEditorSelectionContext =
16
16
  createContext<EditorSelection | null>(null)
17
17
 
18
18
  /**
19
+ * @deprecated Use `useEditorSelector` to get the current editor selection.
19
20
  * @public
20
21
  * Get the current editor selection from the React context.
21
22
  */
@@ -4,7 +4,7 @@ import type {EditorSelector} from '../editor/editor-selector'
4
4
  import {getSelectedBlocks} from './selectors'
5
5
 
6
6
  /**
7
- * @alpha
7
+ * @public
8
8
  */
9
9
  export const getActiveListItem: EditorSelector<
10
10
  PortableTextListBlock['listItem'] | undefined
@@ -4,7 +4,7 @@ import type {EditorSelector} from '../editor/editor-selector'
4
4
  import {getSelectedBlocks} from './selectors'
5
5
 
6
6
  /**
7
- * @alpha
7
+ * @public
8
8
  */
9
9
  export const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({
10
10
  context,
@@ -8,7 +8,7 @@ import {
8
8
  import type {EditorSelector} from '../editor/editor-selector'
9
9
 
10
10
  /**
11
- * @alpha
11
+ * @public
12
12
  */
13
13
  export const getSelectedSpans: EditorSelector<
14
14
  Array<{
@@ -4,7 +4,7 @@ import {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'
4
4
  import {reverseSelection} from '../editor/utils/utils.reverse-selection'
5
5
 
6
6
  /**
7
- * @alpha
7
+ * @public
8
8
  */
9
9
  export const getSelectionText: EditorSelector<string> = ({context}) => {
10
10
  let text = ''