@portabletext/editor 1.26.3 → 1.28.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 (66) hide show
  1. package/README.md +5 -5
  2. package/lib/_chunks-cjs/behavior.markdown.cjs +327 -0
  3. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -0
  4. package/lib/_chunks-cjs/plugin.event-listener.cjs +6827 -0
  5. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -0
  6. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +88 -88
  7. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  8. package/lib/_chunks-es/behavior.markdown.js +332 -0
  9. package/lib/_chunks-es/behavior.markdown.js.map +1 -0
  10. package/lib/_chunks-es/plugin.event-listener.js +6851 -0
  11. package/lib/_chunks-es/plugin.event-listener.js.map +1 -0
  12. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +88 -88
  13. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  14. package/lib/behaviors/index.cjs +2 -325
  15. package/lib/behaviors/index.cjs.map +1 -1
  16. package/lib/behaviors/index.d.cts +1 -1
  17. package/lib/behaviors/index.d.ts +1 -1
  18. package/lib/behaviors/index.js +2 -326
  19. package/lib/behaviors/index.js.map +1 -1
  20. package/lib/index.cjs +261 -6782
  21. package/lib/index.cjs.map +1 -1
  22. package/lib/index.d.cts +3509 -2161
  23. package/lib/index.d.ts +3509 -2161
  24. package/lib/index.js +223 -6761
  25. package/lib/index.js.map +1 -1
  26. package/lib/plugins/index.cjs +29 -0
  27. package/lib/plugins/index.cjs.map +1 -0
  28. package/lib/plugins/index.d.cts +19411 -0
  29. package/lib/plugins/index.d.ts +19411 -0
  30. package/lib/plugins/index.js +29 -0
  31. package/lib/plugins/index.js.map +1 -0
  32. package/lib/selectors/index.cjs +15 -3
  33. package/lib/selectors/index.cjs.map +1 -1
  34. package/lib/selectors/index.d.cts +19 -1
  35. package/lib/selectors/index.d.ts +19 -1
  36. package/lib/selectors/index.js +17 -4
  37. package/lib/selectors/index.js.map +1 -1
  38. package/package.json +14 -8
  39. package/src/behavior-actions/behavior.action.insert-break.ts +93 -83
  40. package/src/editor/Editable.tsx +6 -6
  41. package/src/editor/PortableTextEditor.tsx +288 -1
  42. package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -1
  43. package/src/editor/components/DefaultObject.tsx +21 -0
  44. package/src/editor/components/Element.tsx +5 -5
  45. package/src/editor/components/Leaf.tsx +1 -6
  46. package/src/editor/components/Synchronizer.tsx +16 -1
  47. package/src/editor/create-editor.ts +8 -48
  48. package/src/editor/editor-machine.ts +118 -131
  49. package/src/editor/plugins/create-with-event-listeners.ts +19 -38
  50. package/src/editor/plugins/createWithPatches.ts +1 -1
  51. package/src/editor/plugins/createWithPortableTextSelections.ts +2 -2
  52. package/src/editor/sync-machine.ts +3 -5
  53. package/src/index.ts +5 -11
  54. package/src/plugins/_exports/index.ts +1 -0
  55. package/src/plugins/index.ts +3 -0
  56. package/src/plugins/plugin.editor-ref.tsx +17 -0
  57. package/src/{editor/editor-event-listener.tsx → plugins/plugin.event-listener.tsx} +7 -6
  58. package/src/plugins/plugin.markdown.tsx +70 -0
  59. package/src/selectors/index.ts +4 -2
  60. package/src/selectors/selector.get-active-annotations.test.ts +122 -0
  61. package/src/selectors/selector.get-active-annotations.ts +30 -0
  62. package/src/selectors/selector.get-selection.ts +8 -0
  63. package/src/selectors/selector.get-value.ts +11 -0
  64. package/src/type-utils.ts +12 -2
  65. package/src/editor/nodes/DefaultAnnotation.tsx +0 -20
  66. package/src/editor/nodes/DefaultObject.tsx +0 -18
@@ -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}),
@@ -17,6 +17,24 @@ export function createWithEventListeners(
17
17
  subscriptions.push(() => {
18
18
  const subscription = editorActor.on('*', (event) => {
19
19
  switch (event.type) {
20
+ // These events are not relevant for Behaviors
21
+ case 'blurred':
22
+ case 'done loading':
23
+ case 'editable':
24
+ case 'error':
25
+ case 'focused':
26
+ case 'invalid value':
27
+ case 'loading':
28
+ case 'mutation':
29
+ case 'patch':
30
+ case 'patches':
31
+ case 'read only':
32
+ case 'ready':
33
+ case 'selection':
34
+ case 'value changed':
35
+ case 'unset':
36
+ break
37
+
20
38
  case 'custom.*':
21
39
  editorActor.send({
22
40
  type: 'custom behavior event',
@@ -25,44 +43,7 @@ export function createWithEventListeners(
25
43
  })
26
44
  break
27
45
 
28
- case 'annotation.add':
29
- case 'annotation.remove':
30
- case 'annotation.toggle':
31
- case 'block.set':
32
- case 'block.unset':
33
- case 'blur':
34
- case 'data transfer.set':
35
- case 'decorator.add':
36
- case 'decorator.remove':
37
- case 'decorator.toggle':
38
- case 'delete.backward':
39
- case 'delete.block':
40
- case 'delete.forward':
41
- case 'delete.text':
42
- case 'deserialization.failure':
43
- case 'deserialization.success':
44
- case 'focus':
45
- case 'insert.block':
46
- case 'insert.block object':
47
- case 'insert.inline object':
48
- case 'insert.span':
49
- case 'insert.text block':
50
- case 'list item.add':
51
- case 'list item.remove':
52
- case 'list item.toggle':
53
- case 'move.block':
54
- case 'move.block down':
55
- case 'move.block up':
56
- case 'select':
57
- case 'select.next block':
58
- case 'select.previous block':
59
- case 'serialization.failure':
60
- case 'serialization.success':
61
- case 'style.add':
62
- case 'style.remove':
63
- case 'style.toggle':
64
- case 'text block.set':
65
- case 'text block.unset':
46
+ default:
66
47
  editorActor.send({
67
48
  type: 'behavior event',
68
49
  behaviorEvent: event,
@@ -271,7 +271,7 @@ export function createWithPatches({
271
271
  ) {
272
272
  patches = [...patches, unset([])]
273
273
  editorActor.send({
274
- type: 'unset',
274
+ type: 'notify.unset',
275
275
  previousValue: fromSlateValue(
276
276
  previousChildren,
277
277
  schemaTypes.block.name,
@@ -45,9 +45,9 @@ export function createWithPortableTextSelections(
45
45
  )
46
46
  }
47
47
  if (ptRange) {
48
- editorActor.send({type: 'selection', selection: ptRange})
48
+ editorActor.send({type: 'notify.selection', selection: ptRange})
49
49
  } else {
50
- editorActor.send({type: 'selection', selection: null})
50
+ editorActor.send({type: 'notify.selection', selection: null})
51
51
  }
52
52
  }
53
53
  prevSelection = editor.selection
@@ -168,11 +168,9 @@ export const syncMachine = setup({
168
168
  assertEvent(event, 'done syncing')
169
169
  return context.pendingValue !== event.value
170
170
  },
171
- 'pending value equals previous value': ({context}) =>
172
- !(
173
- context.previousValue === undefined &&
174
- context.pendingValue === undefined
175
- ) && isEqual(context.pendingValue, context.previousValue),
171
+ 'pending value equals previous value': ({context}) => {
172
+ return isEqual(context.pendingValue, context.previousValue)
173
+ },
176
174
  },
177
175
  actors: {
178
176
  'sync value': syncValueLogic,
package/src/index.ts CHANGED
@@ -25,16 +25,11 @@ export type {PortableTextMemberSchemaTypes} from './types/editor'
25
25
  export type {EditorSchema} from './editor/define-schema'
26
26
  export {PortableTextEditable} from './editor/Editable'
27
27
  export type {PortableTextEditableProps} from './editor/Editable'
28
- export {EditorEventListener} from './editor/editor-event-listener'
29
- export {
30
- editorMachine,
31
- type EditorActor,
32
- type EditorEmittedEvent,
33
- type InternalEditorEmittedEvent,
34
- type InternalEditorEvent,
35
- type MutationEvent,
36
- type PatchEvent,
37
- type PatchesEvent,
28
+ export {EventListenerPlugin as EditorEventListener} from './plugins/plugin.event-listener'
29
+ export type {
30
+ EditorEmittedEvent,
31
+ MutationEvent,
32
+ PatchesEvent,
38
33
  } from './editor/editor-machine'
39
34
  export {
40
35
  EditorProvider,
@@ -49,6 +44,5 @@ export {defaultKeyGenerator as keyGenerator} from './editor/key-generator'
49
44
  export type {AddedAnnotationPaths} from './editor/plugins/createWithEditableAPI'
50
45
  export {PortableTextEditor} from './editor/PortableTextEditor'
51
46
  export type {PortableTextEditorProps} from './editor/PortableTextEditor'
52
- export type {OmitFromUnion, PickFromUnion} from './type-utils'
53
47
  export * from './types/editor'
54
48
  export type {HotkeyOptions} from './types/options'
@@ -0,0 +1 @@
1
+ export * from '../index'
@@ -0,0 +1,3 @@
1
+ export {EventListenerPlugin} from './plugin.event-listener'
2
+ export {EditorRefPlugin} from './plugin.editor-ref'
3
+ export {MarkdownPlugin, type MarkdownPluginConfig} from './plugin.markdown'
@@ -0,0 +1,17 @@
1
+ import React from 'react'
2
+ import type {Editor} from '../editor/create-editor'
3
+ import {useEditor} from '../editor/editor-provider'
4
+
5
+ /**
6
+ * @beta
7
+ */
8
+ export const EditorRefPlugin = React.forwardRef<Editor | null>((_, ref) => {
9
+ const editor = useEditor()
10
+
11
+ const portableTextEditorRef = React.useRef(editor)
12
+
13
+ React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])
14
+
15
+ return null
16
+ })
17
+ EditorRefPlugin.displayName = 'EditorRefPlugin'
@@ -1,7 +1,7 @@
1
1
  import {useEffect} from 'react'
2
2
  import {useEffectEvent} from 'use-effect-event'
3
- import type {EditorEmittedEvent} from './editor-machine'
4
- import {useEditor} from './editor-provider'
3
+ import type {EditorEmittedEvent} from '../editor/editor-machine'
4
+ import {useEditor} from '../editor/editor-provider'
5
5
 
6
6
  /**
7
7
  * @public
@@ -23,12 +23,13 @@ import {useEditor} from './editor-provider'
23
23
  * @example
24
24
  * Listen and log events.
25
25
  * ```tsx
26
- * import {EditorEventListener, EditorProvider} from '@portabletext/editor'
26
+ * import {EditorProvider} from '@portabletext/editor'
27
+ * import {EventListenerPlugin} from '@portabletext/editor/plugins'
27
28
  *
28
29
  * function MyComponent() {
29
30
  * return (
30
31
  * <EditorProvider>
31
- * <EditorEventListener
32
+ * <EventListenerPlugin
32
33
  * on={(event) => {
33
34
  * console.log(event)
34
35
  * }
@@ -41,7 +42,7 @@ import {useEditor} from './editor-provider'
41
42
  * @example
42
43
  * Handle events when there is a mutation.
43
44
  * ```tsx
44
- * <EditorEventListener
45
+ * <EventListenerPlugin
45
46
  * on={(event) => {
46
47
  * if (event.type === 'mutation') {
47
48
  * console.log('Value changed:', event.snapshot)
@@ -51,7 +52,7 @@ import {useEditor} from './editor-provider'
51
52
  * ```
52
53
  * @group Components
53
54
  */
54
- export function EditorEventListener(props: {
55
+ export function EventListenerPlugin(props: {
55
56
  on: (event: EditorEmittedEvent) => void
56
57
  }) {
57
58
  const editor = useEditor()
@@ -0,0 +1,70 @@
1
+ import {useEffect} from 'react'
2
+ import {
3
+ createMarkdownBehaviors,
4
+ type MarkdownBehaviorsConfig,
5
+ } from '../behaviors/behavior.markdown'
6
+ import {useEditor} from '../editor/editor-provider'
7
+
8
+ /**
9
+ * @beta
10
+ */
11
+ export type MarkdownPluginConfig = MarkdownBehaviorsConfig
12
+
13
+ /**
14
+ * @beta
15
+ * Add markdown behaviors for common markdown actions such as converting ### to headings, --- to HRs, and more.
16
+ *
17
+ * @example
18
+ * Configure the bundled markdown behaviors
19
+ * ```ts
20
+ * import {EditorProvider} from '@portabletext/editor'
21
+ * import {MarkdownPlugin} from '@portabletext/editor/plugins'
22
+ *
23
+ * function App() {
24
+ * return (
25
+ * <EditorProvider>
26
+ * <MarkdownPlugin
27
+ * config={{
28
+ * horizontalRuleObject: ({schema}) => {
29
+ * const name = schema.blockObjects.find(
30
+ * (object) => object.name === 'break',
31
+ * )?.name
32
+ * return name ? {name} : undefined
33
+ * },
34
+ * defaultStyle: ({schema}) => schema.styles[0].value,
35
+ * headingStyle: ({schema, level}) =>
36
+ * schema.styles.find((style) => style.value === `h${level}`)
37
+ * ?.value,
38
+ * blockquoteStyle: ({schema}) =>
39
+ * schema.styles.find((style) => style.value === 'blockquote')
40
+ * ?.value,
41
+ * unorderedListStyle: ({schema}) =>
42
+ * schema.lists.find((list) => list.value === 'bullet')?.value,
43
+ * orderedListStyle: ({schema}) =>
44
+ * schema.lists.find((list) => list.value === 'number')?.value,
45
+ * }}
46
+ * />
47
+ * {...}
48
+ * </EditorProvider>
49
+ * )
50
+ * }
51
+ */
52
+ export function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {
53
+ const editor = useEditor()
54
+
55
+ useEffect(() => {
56
+ const behaviors = createMarkdownBehaviors(props.config)
57
+
58
+ const unregisterBehaviors = behaviors.map((behavior) =>
59
+ editor.registerBehavior({behavior}),
60
+ )
61
+
62
+ return () => {
63
+ for (const unregisterBehavior of unregisterBehaviors) {
64
+ unregisterBehavior()
65
+ }
66
+ }
67
+ }, [editor, props.config])
68
+
69
+ return null
70
+ }
@@ -1,3 +1,4 @@
1
+ export type {EditorSchema} from '../editor/define-schema'
1
2
  export type {EditorSelector} from '../editor/editor-selector'
2
3
  export type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
3
4
  export type {
@@ -5,14 +6,15 @@ export type {
5
6
  EditorSelectionPoint,
6
7
  PortableTextMemberSchemaTypes,
7
8
  } from '../types/editor'
8
-
9
- export type {EditorSchema} from '../editor/define-schema'
9
+ export {getActiveAnnotations} from './selector.get-active-annotations'
10
10
  export {getActiveListItem} from './selector.get-active-list-item'
11
11
  export {getActiveStyle} from './selector.get-active-style'
12
12
  export {getSelectedSlice} from './selector.get-selected-slice'
13
13
  export {getSelectedSpans} from './selector.get-selected-spans'
14
+ export {getSelection} from './selector.get-selection'
14
15
  export {getSelectionText} from './selector.get-selection-text'
15
16
  export {getBlockTextBefore} from './selector.get-text-before'
17
+ export {getValue} from './selector.get-value'
16
18
  export {isActiveAnnotation} from './selector.is-active-annotation'
17
19
  export {isActiveDecorator} from './selector.is-active-decorator'
18
20
  export {isActiveListItem} from './selector.is-active-list-item'