@portabletext/editor 1.48.13 → 1.48.15

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 (78) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +682 -609
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-es/editor-provider.js +683 -610
  4. package/lib/_chunks-es/editor-provider.js.map +1 -1
  5. package/lib/behaviors/index.cjs.map +1 -1
  6. package/lib/behaviors/index.d.cts +226 -2772
  7. package/lib/behaviors/index.d.ts +226 -2772
  8. package/lib/behaviors/index.js.map +1 -1
  9. package/lib/index.cjs +22 -6
  10. package/lib/index.cjs.map +1 -1
  11. package/lib/index.d.cts +227 -2780
  12. package/lib/index.d.ts +227 -2780
  13. package/lib/index.js +23 -7
  14. package/lib/index.js.map +1 -1
  15. package/lib/plugins/index.cjs +1 -7
  16. package/lib/plugins/index.cjs.map +1 -1
  17. package/lib/plugins/index.d.cts +226 -2785
  18. package/lib/plugins/index.d.ts +226 -2785
  19. package/lib/plugins/index.js +2 -8
  20. package/lib/plugins/index.js.map +1 -1
  21. package/lib/selectors/index.d.cts +225 -2771
  22. package/lib/selectors/index.d.ts +225 -2771
  23. package/lib/utils/index.d.cts +227 -2772
  24. package/lib/utils/index.d.ts +227 -2772
  25. package/package.json +1 -1
  26. package/src/behaviors/behavior.abstract.keyboard.ts +16 -0
  27. package/src/behaviors/{behavior.default.ts → behavior.abstract.ts} +3 -3
  28. package/src/behaviors/behavior.config.ts +7 -0
  29. package/src/behaviors/behavior.core.ts +6 -5
  30. package/src/behaviors/behavior.perform-event.ts +27 -51
  31. package/src/behaviors/behavior.types.action.ts +1 -11
  32. package/src/editor/PortableTextEditor.tsx +1 -1
  33. package/src/editor/components/Element.tsx +30 -4
  34. package/src/editor/create-editor.ts +17 -5
  35. package/src/editor/editor-machine.ts +23 -17
  36. package/src/editor/mutation-machine.ts +6 -6
  37. package/src/editor/plugins/create-with-event-listeners.ts +25 -25
  38. package/src/editor/plugins/createWithEditableAPI.ts +3 -3
  39. package/src/editor/plugins/createWithPatches.ts +13 -5
  40. package/src/editor/plugins/createWithPortableTextMarkModel.ts +5 -5
  41. package/src/editor/plugins/createWithUndoRedo.ts +8 -8
  42. package/src/editor/with-applying-behavior-operations.ts +18 -0
  43. package/src/editor/{with-applying-behavior-actions.ts → with-undo-step.ts} +1 -19
  44. package/src/index.ts +1 -1
  45. package/src/{behavior-actions/behavior.action.annotation.add.ts → operations/behavior.operation.annotation.add.ts} +7 -7
  46. package/src/{behavior-actions/behavior.action.annotation.remove.ts → operations/behavior.operation.annotation.remove.ts} +6 -6
  47. package/src/{behavior-actions/behavior.action.block.set.ts → operations/behavior.operation.block.set.ts} +14 -14
  48. package/src/{behavior-actions/behavior.action.block.unset.ts → operations/behavior.operation.block.unset.ts} +19 -17
  49. package/src/{behavior-actions/behavior.action.decorator.add.ts → operations/behavior.operation.decorator.add.ts} +10 -10
  50. package/src/operations/behavior.operation.delete.backward.ts +8 -0
  51. package/src/operations/behavior.operation.delete.block.ts +24 -0
  52. package/src/operations/behavior.operation.delete.forward.ts +8 -0
  53. package/src/{behavior-actions/behavior.action.delete.ts → operations/behavior.operation.delete.ts} +8 -8
  54. package/src/{behavior-actions/behavior.action.insert-inline-object.ts → operations/behavior.operation.insert-inline-object.ts} +11 -11
  55. package/src/{behavior-actions/behavior.action.insert-span.ts → operations/behavior.operation.insert-span.ts} +15 -15
  56. package/src/{behavior-actions/behavior.action.insert.block.ts → operations/behavior.operation.insert.block.ts} +8 -8
  57. package/src/operations/behavior.operation.insert.text.ts +17 -0
  58. package/src/operations/behavior.operation.move.backward.ts +12 -0
  59. package/src/operations/behavior.operation.move.block.ts +16 -0
  60. package/src/operations/behavior.operation.move.forward.ts +11 -0
  61. package/src/operations/behavior.operation.select.ts +15 -0
  62. package/src/operations/behavior.operations.ts +239 -0
  63. package/src/plugins/index.ts +0 -1
  64. package/src/priority/priority.core.ts +3 -0
  65. package/src/priority/priority.sort.test.ts +319 -0
  66. package/src/priority/priority.sort.ts +121 -0
  67. package/src/priority/priority.types.ts +24 -0
  68. package/src/behavior-actions/behavior.action.delete.backward.ts +0 -7
  69. package/src/behavior-actions/behavior.action.delete.block.ts +0 -24
  70. package/src/behavior-actions/behavior.action.delete.forward.ts +0 -7
  71. package/src/behavior-actions/behavior.action.insert.text.ts +0 -17
  72. package/src/behavior-actions/behavior.action.move.backward.ts +0 -12
  73. package/src/behavior-actions/behavior.action.move.block.ts +0 -16
  74. package/src/behavior-actions/behavior.action.move.forward.ts +0 -11
  75. package/src/behavior-actions/behavior.action.select.ts +0 -15
  76. package/src/behavior-actions/behavior.actions.ts +0 -219
  77. package/src/behaviors/behavior.default.raise-soft-break.ts +0 -14
  78. package/src/plugins/plugin.core.tsx +0 -9
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport type {OmitFromUnion, PickFromUnion} from '../type-utils'\nimport type {PortableTextSlateEditor} from '../types/editor'\nimport type {\n AbstractBehaviorEventType,\n CustomBehaviorEvent,\n NativeBehaviorEvent,\n SyntheticBehaviorEvent,\n} from './behavior.types.event'\n\n/**\n * @beta\n */\nexport type BehaviorAction =\n | {\n type: 'execute'\n event: SyntheticBehaviorEvent\n }\n | {\n type: 'forward'\n event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent\n }\n | {\n type: 'raise'\n event: SyntheticBehaviorEvent | CustomBehaviorEvent\n }\n | {\n type: 'effect'\n effect: () => void\n }\n\n/**\n * @beta\n */\nexport function execute(\n event: SyntheticBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'execute'> {\n return {type: 'execute', event}\n}\n\n/**\n * @beta\n */\nexport function forward(\n event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'forward'> {\n return {type: 'forward', event}\n}\n\n/**\n * @beta\n */\nexport function raise(\n event: SyntheticBehaviorEvent | CustomBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'raise'> {\n return {type: 'raise', event}\n}\n\n/**\n * @beta\n */\nexport function effect(\n effect: () => void,\n): PickFromUnion<BehaviorAction, 'type', 'effect'> {\n return {type: 'effect', effect}\n}\n\n/**\n * @beta\n */\nexport type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (\n payload: {\n snapshot: EditorSnapshot\n event: TBehaviorEvent\n },\n guardResponse: TGuardResponse,\n) => Array<BehaviorAction>\n\nexport type InternalBehaviorAction = OmitFromUnion<\n SyntheticBehaviorEvent,\n 'type',\n AbstractBehaviorEventType\n> & {\n editor: PortableTextSlateEditor\n}\n","import type {BehaviorActionSet} from './behavior.types.action'\nimport type {\n BehaviorEvent,\n BehaviorEventTypeNamespace,\n CustomBehaviorEvent,\n ResolveBehaviorEvent,\n} from './behavior.types.event'\nimport type {BehaviorGuard} from './behavior.types.guard'\n\n/**\n * @beta\n */\nexport type Behavior<\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] =\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'],\n TGuardResponse = true,\n TBehaviorEvent extends\n ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>,\n> = {\n /**\n * Editor Event that triggers this Behavior.\n */\n on: TBehaviorEventType\n /**\n * Predicate function that determines if the Behavior should be executed.\n * Returning a non-nullable value from the guard will pass the value to the\n * actions and execute them.\n */\n guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>\n /**\n * Array of Behavior Action sets.\n * Each set represents a step in the history stack.\n */\n actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>\n}\n\n/**\n * @beta\n *\n * @example\n *\n * ```tsx\n * const noLowerCaseA = defineBehavior({\n * on: 'insert.text',\n * guard: ({event, snapshot}) => event.text === 'a',\n * actions: [({event, snapshot}) => [{type: 'insert.text', text: 'A'}]],\n * })\n * ```\n *\n */\nexport function defineBehavior<\n TPayload extends Record<string, unknown>,\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] = CustomBehaviorEvent['type'],\n TGuardResponse = true,\n>(\n behavior: Behavior<\n TBehaviorEventType,\n TGuardResponse,\n ResolveBehaviorEvent<TBehaviorEventType, TPayload>\n >,\n): Behavior\nexport function defineBehavior<\n TPayload extends never = never,\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] = BehaviorEvent['type'],\n TGuardResponse = true,\n TBehaviorEvent extends ResolveBehaviorEvent<\n TBehaviorEventType,\n TPayload\n > = ResolveBehaviorEvent<TBehaviorEventType, TPayload>,\n>(\n behavior: Behavior<TBehaviorEventType, TGuardResponse, TBehaviorEvent>,\n): Behavior {\n return behavior as unknown as Behavior\n}\n"],"names":["execute","event","type","forward","raise","effect","defineBehavior","behavior"],"mappings":"AAkCO,SAASA,QACdC,OACkD;AAC3C,SAAA;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAK;AAChC;AAKO,SAASE,QACdF,OACkD;AAC3C,SAAA;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAK;AAChC;AAKO,SAASG,MACdH,OACgD;AACzC,SAAA;AAAA,IAACC,MAAM;AAAA,IAASD;AAAAA,EAAK;AAC9B;AAKO,SAASI,OACdA,SACiD;AAC1C,SAAA;AAAA,IAACH,MAAM;AAAA,IAAUG,QAAAA;AAAAA,EAAM;AAChC;ACIO,SAASC,eAYdC,UACU;AACHA,SAAAA;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport type {PickFromUnion} from '../type-utils'\nimport type {\n CustomBehaviorEvent,\n NativeBehaviorEvent,\n SyntheticBehaviorEvent,\n} from './behavior.types.event'\n\n/**\n * @beta\n */\nexport type BehaviorAction =\n | {\n type: 'execute'\n event: SyntheticBehaviorEvent\n }\n | {\n type: 'forward'\n event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent\n }\n | {\n type: 'raise'\n event: SyntheticBehaviorEvent | CustomBehaviorEvent\n }\n | {\n type: 'effect'\n effect: () => void\n }\n\n/**\n * @beta\n */\nexport function execute(\n event: SyntheticBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'execute'> {\n return {type: 'execute', event}\n}\n\n/**\n * @beta\n */\nexport function forward(\n event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'forward'> {\n return {type: 'forward', event}\n}\n\n/**\n * @beta\n */\nexport function raise(\n event: SyntheticBehaviorEvent | CustomBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'raise'> {\n return {type: 'raise', event}\n}\n\n/**\n * @beta\n */\nexport function effect(\n effect: () => void,\n): PickFromUnion<BehaviorAction, 'type', 'effect'> {\n return {type: 'effect', effect}\n}\n\n/**\n * @beta\n */\nexport type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (\n payload: {\n snapshot: EditorSnapshot\n event: TBehaviorEvent\n },\n guardResponse: TGuardResponse,\n) => Array<BehaviorAction>\n","import type {BehaviorActionSet} from './behavior.types.action'\nimport type {\n BehaviorEvent,\n BehaviorEventTypeNamespace,\n CustomBehaviorEvent,\n ResolveBehaviorEvent,\n} from './behavior.types.event'\nimport type {BehaviorGuard} from './behavior.types.guard'\n\n/**\n * @beta\n */\nexport type Behavior<\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] =\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'],\n TGuardResponse = true,\n TBehaviorEvent extends\n ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>,\n> = {\n /**\n * Editor Event that triggers this Behavior.\n */\n on: TBehaviorEventType\n /**\n * Predicate function that determines if the Behavior should be executed.\n * Returning a non-nullable value from the guard will pass the value to the\n * actions and execute them.\n */\n guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>\n /**\n * Array of Behavior Action sets.\n * Each set represents a step in the history stack.\n */\n actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>\n}\n\n/**\n * @beta\n *\n * @example\n *\n * ```tsx\n * const noLowerCaseA = defineBehavior({\n * on: 'insert.text',\n * guard: ({event, snapshot}) => event.text === 'a',\n * actions: [({event, snapshot}) => [{type: 'insert.text', text: 'A'}]],\n * })\n * ```\n *\n */\nexport function defineBehavior<\n TPayload extends Record<string, unknown>,\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] = CustomBehaviorEvent['type'],\n TGuardResponse = true,\n>(\n behavior: Behavior<\n TBehaviorEventType,\n TGuardResponse,\n ResolveBehaviorEvent<TBehaviorEventType, TPayload>\n >,\n): Behavior\nexport function defineBehavior<\n TPayload extends never = never,\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] = BehaviorEvent['type'],\n TGuardResponse = true,\n TBehaviorEvent extends ResolveBehaviorEvent<\n TBehaviorEventType,\n TPayload\n > = ResolveBehaviorEvent<TBehaviorEventType, TPayload>,\n>(\n behavior: Behavior<TBehaviorEventType, TGuardResponse, TBehaviorEvent>,\n): Behavior {\n return behavior as unknown as Behavior\n}\n"],"names":["execute","event","type","forward","raise","effect","defineBehavior","behavior"],"mappings":"AAgCO,SAASA,QACdC,OACkD;AAC3C,SAAA;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAK;AAChC;AAKO,SAASE,QACdF,OACkD;AAC3C,SAAA;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAK;AAChC;AAKO,SAASG,MACdH,OACgD;AACzC,SAAA;AAAA,IAACC,MAAM;AAAA,IAASD;AAAAA,EAAK;AAC9B;AAKO,SAASI,OACdA,SACiD;AAC1C,SAAA;AAAA,IAACH,MAAM;AAAA,IAAUG,QAAAA;AAAAA,EAAM;AAChC;ACMO,SAASC,eAYdC,UACU;AACHA,SAAAA;AACT;"}
package/lib/index.cjs CHANGED
@@ -423,14 +423,22 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
423
423
  setDragPositionBlock(event_0.position.block);
424
424
  }
425
425
  }]]
426
- });
426
+ }), priority = editorProvider.createEditorPriority({
427
+ reference: {
428
+ priority: editorProvider.corePriority,
429
+ importance: "lower"
430
+ }
431
+ }), behaviorConfig = {
432
+ behavior,
433
+ priority
434
+ };
427
435
  return editorActor.send({
428
436
  type: "add behavior",
429
- behavior
437
+ behaviorConfig
430
438
  }), () => {
431
439
  editorActor.send({
432
440
  type: "remove behavior",
433
- behavior
441
+ behaviorConfig
434
442
  });
435
443
  };
436
444
  }, [editorActor, element._key]), React.useEffect(() => {
@@ -447,14 +455,22 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
447
455
  setDragPositionBlock(void 0);
448
456
  }
449
457
  }, behaviors_index.forward(event_2)]]
450
- });
458
+ }), priority_0 = editorProvider.createEditorPriority({
459
+ reference: {
460
+ priority: editorProvider.corePriority,
461
+ importance: "lower"
462
+ }
463
+ }), behaviorConfig_0 = {
464
+ behavior: behavior_0,
465
+ priority: priority_0
466
+ };
451
467
  return editorActor.send({
452
468
  type: "add behavior",
453
- behavior: behavior_0
469
+ behaviorConfig: behaviorConfig_0
454
470
  }), () => {
455
471
  editorActor.send({
456
472
  type: "remove behavior",
457
- behavior: behavior_0
473
+ behaviorConfig: behaviorConfig_0
458
474
  });
459
475
  };
460
476
  }, [editorActor]);