@portabletext/editor 1.45.3 → 1.46.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.core.cjs +20 -0
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +25 -25
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +93 -59
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-es/behavior.core.js +20 -0
  8. package/lib/_chunks-es/behavior.core.js.map +1 -1
  9. package/lib/_chunks-es/behavior.markdown.js +26 -26
  10. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  11. package/lib/_chunks-es/editor-provider.js +93 -59
  12. package/lib/_chunks-es/editor-provider.js.map +1 -1
  13. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +1 -1
  14. package/lib/behaviors/index.cjs +37 -53
  15. package/lib/behaviors/index.cjs.map +1 -1
  16. package/lib/behaviors/index.d.cts +52 -37
  17. package/lib/behaviors/index.d.ts +52 -37
  18. package/lib/behaviors/index.js +38 -54
  19. package/lib/behaviors/index.js.map +1 -1
  20. package/lib/index.d.cts +33 -37
  21. package/lib/index.d.ts +33 -37
  22. package/lib/plugins/index.cjs +23 -29
  23. package/lib/plugins/index.cjs.map +1 -1
  24. package/lib/plugins/index.d.cts +33 -37
  25. package/lib/plugins/index.d.ts +33 -37
  26. package/lib/plugins/index.js +24 -30
  27. package/lib/plugins/index.js.map +1 -1
  28. package/lib/selectors/index.d.cts +33 -37
  29. package/lib/selectors/index.d.ts +33 -37
  30. package/lib/utils/index.d.cts +33 -37
  31. package/lib/utils/index.d.ts +33 -37
  32. package/package.json +1 -1
  33. package/src/behaviors/behavior.decorator-pair.ts +16 -19
  34. package/src/behaviors/behavior.emoji-picker.ts +26 -45
  35. package/src/behaviors/behavior.links.ts +5 -4
  36. package/src/behaviors/behavior.markdown.ts +37 -34
  37. package/src/behaviors/behavior.perform-event.ts +67 -18
  38. package/src/behaviors/behavior.types.action.ts +39 -13
  39. package/src/behaviors/behavior.types.guard.ts +1 -6
  40. package/src/behaviors/index.ts +3 -0
  41. package/src/editor/components/Synchronizer.tsx +6 -3
  42. package/src/editor/create-editor.ts +1 -1
  43. package/src/editor/editor-machine.ts +8 -6
  44. package/src/plugins/plugin.decorator-shortcut.ts +6 -8
  45. package/src/plugins/plugin.one-line.tsx +4 -4
@@ -10,7 +10,6 @@ import {
10
10
  type ActorRefFrom,
11
11
  } from 'xstate'
12
12
  import {coreBehaviors} from '../behaviors/behavior.core'
13
- import {defaultBehaviors} from '../behaviors/behavior.default'
14
13
  import {performEvent} from '../behaviors/behavior.perform-event'
15
14
  import type {Behavior} from '../behaviors/behavior.types.behavior'
16
15
  import type {BehaviorEvent} from '../behaviors/behavior.types.event'
@@ -213,7 +212,7 @@ export const editorMachine = setup({
213
212
  initialReadOnly: boolean
214
213
  maxBlocks: number | undefined
215
214
  selection: EditorSelection
216
- value: Array<PortableTextBlock> | undefined
215
+ incomingValue: Array<PortableTextBlock> | undefined
217
216
  internalDrag?: {
218
217
  ghost?: HTMLElement
219
218
  origin: Pick<EventPosition, 'selection'>
@@ -228,7 +227,7 @@ export const editorMachine = setup({
228
227
  maxBlocks?: number
229
228
  readOnly?: boolean
230
229
  schema: EditorSchema
231
- value?: Array<PortableTextBlock>
230
+ initialValue?: Array<PortableTextBlock>
232
231
  },
233
232
  tags: {} as 'dragging internally',
234
233
  },
@@ -297,7 +296,8 @@ export const editorMachine = setup({
297
296
  assertEvent(event, ['behavior event'])
298
297
 
299
298
  performEvent({
300
- behaviors: [...context.behaviors.values(), ...defaultBehaviors],
299
+ mode: 'raise',
300
+ behaviors: [...context.behaviors.values()],
301
301
  event: event.behaviorEvent,
302
302
  editor: event.editor,
303
303
  keyGenerator: context.keyGenerator,
@@ -331,7 +331,7 @@ export const editorMachine = setup({
331
331
  selection: null,
332
332
  initialReadOnly: input.readOnly ?? false,
333
333
  maxBlocks: input.maxBlocks,
334
- value: input.value,
334
+ incomingValue: input.initialValue,
335
335
  }),
336
336
  on: {
337
337
  'notify.blurred': {
@@ -365,7 +365,9 @@ export const editorMachine = setup({
365
365
  actions: assign({keyGenerator: ({event}) => event.keyGenerator}),
366
366
  },
367
367
  'update schema': {actions: 'assign schema'},
368
- 'update value': {actions: assign({value: ({event}) => event.value})},
368
+ 'update value': {
369
+ actions: assign({incomingValue: ({event}) => event.value}),
370
+ },
369
371
  'update maxBlocks': {
370
372
  actions: assign({maxBlocks: ({event}) => event.maxBlocks}),
371
373
  },
@@ -8,6 +8,7 @@ import {
8
8
  type CallbackLogicFunction,
9
9
  } from 'xstate'
10
10
  import {createDecoratorPairBehavior} from '../behaviors/behavior.decorator-pair'
11
+ import {effect, execute} from '../behaviors/behavior.types.action'
11
12
  import {defineBehavior} from '../behaviors/behavior.types.behavior'
12
13
  import type {Editor} from '../editor/create-editor'
13
14
  import type {EditorSchema} from '../editor/define-schema'
@@ -132,15 +133,12 @@ const deleteBackwardListenerCallback: CallbackLogicFunction<
132
133
  on: 'delete.backward',
133
134
  actions: [
134
135
  () => [
135
- {
136
+ execute({
136
137
  type: 'history.undo',
137
- },
138
- {
139
- type: 'effect',
140
- effect: () => {
141
- sendBack({type: 'delete.backward'})
142
- },
143
- },
138
+ }),
139
+ effect(() => {
140
+ sendBack({type: 'delete.backward'})
141
+ }),
144
142
  ],
145
143
  ],
146
144
  }),
@@ -1,4 +1,4 @@
1
- import {defineBehavior, raise} from '../behaviors'
1
+ import {defineBehavior, execute, raise} from '../behaviors'
2
2
  import * as selectors from '../selectors'
3
3
  import * as utils from '../utils'
4
4
  import {BehaviorPlugin} from './plugin.behavior'
@@ -14,7 +14,7 @@ const oneLineBehaviors = [
14
14
  snapshot.context.selection && selectors.isSelectionExpanded(snapshot)
15
15
  ? {selection: snapshot.context.selection}
16
16
  : false,
17
- actions: [(_, {selection}) => [{type: 'delete', at: selection}]],
17
+ actions: [(_, {selection}) => [execute({type: 'delete', at: selection})]],
18
18
  }),
19
19
  /**
20
20
  * All other cases of `insert.break` should be aborted.
@@ -59,12 +59,12 @@ const oneLineBehaviors = [
59
59
  },
60
60
  actions: [
61
61
  ({event}) => [
62
- {
62
+ execute({
63
63
  type: 'insert.block',
64
64
  block: event.block,
65
65
  placement: 'auto',
66
66
  select: 'end',
67
- },
67
+ }),
68
68
  ],
69
69
  ],
70
70
  }),