@portabletext/editor 1.48.12 → 1.48.13

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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 = (\n | OmitFromUnion<SyntheticBehaviorEvent, 'type', AbstractBehaviorEventType>\n | {type: 'effect'; effect: () => void}\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.cjs","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 +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 = (\n | OmitFromUnion<SyntheticBehaviorEvent, 'type', AbstractBehaviorEventType>\n | {type: 'effect'; effect: () => void}\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 {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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.48.12",
3
+ "version": "1.48.13",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -79,15 +79,15 @@
79
79
  "slate-react": "0.114.2",
80
80
  "use-effect-event": "^1.0.2",
81
81
  "xstate": "^5.19.2",
82
- "@portabletext/block-tools": "1.1.22",
82
+ "@portabletext/block-tools": "1.1.23",
83
83
  "@portabletext/patches": "1.1.3"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@portabletext/toolkit": "^2.0.17",
87
87
  "@sanity/diff-match-patch": "^3.2.0",
88
88
  "@sanity/pkg-utils": "^7.2.2",
89
- "@sanity/schema": "^3.87.0",
90
- "@sanity/types": "^3.87.0",
89
+ "@sanity/schema": "^3.87.1",
90
+ "@sanity/types": "^3.87.1",
91
91
  "@testing-library/jest-dom": "^6.6.3",
92
92
  "@testing-library/react": "^16.3.0",
93
93
  "@types/debug": "^4.1.12",
@@ -114,8 +114,8 @@
114
114
  "racejar": "1.2.4"
115
115
  },
116
116
  "peerDependencies": {
117
- "@sanity/schema": "^3.87.0",
118
- "@sanity/types": "^3.87.0",
117
+ "@sanity/schema": "^3.87.1",
118
+ "@sanity/types": "^3.87.1",
119
119
  "react": "^16.9 || ^17 || ^18 || ^19",
120
120
  "rxjs": "^7.8.2"
121
121
  },
@@ -15,7 +15,6 @@ import {deleteActionImplementation} from './behavior.action.delete'
15
15
  import {deleteBackwardActionImplementation} from './behavior.action.delete.backward'
16
16
  import {deleteBlockActionImplementation} from './behavior.action.delete.block'
17
17
  import {deleteForwardActionImplementation} from './behavior.action.delete.forward'
18
- import {effectActionImplementation} from './behavior.action.effect'
19
18
  import {insertInlineObjectActionImplementation} from './behavior.action.insert-inline-object'
20
19
  import {insertSpanActionImplementation} from './behavior.action.insert-span'
21
20
  import {insertBlockActionImplementation} from './behavior.action.insert.block'
@@ -62,7 +61,6 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
62
61
  'insert.inline object': insertInlineObjectActionImplementation,
63
62
  'insert.span': insertSpanActionImplementation,
64
63
  'insert.text': insertTextActionImplementation,
65
- 'effect': effectActionImplementation,
66
64
  'move.backward': moveBackwardActionImplementation,
67
65
  'move.block': moveBlockActionImplementation,
68
66
  'move.forward': moveForwardActionImplementation,
@@ -147,13 +145,6 @@ export function performAction({
147
145
  })
148
146
  break
149
147
  }
150
- case 'effect': {
151
- behaviorActionImplementations.effect({
152
- context,
153
- action,
154
- })
155
- break
156
- }
157
148
  case 'history.redo': {
158
149
  behaviorActionImplementations['history.redo']({
159
150
  context,
@@ -1,4 +1,3 @@
1
- import type {Behavior, BehaviorEvent} from '.'
2
1
  import {performAction} from '../behavior-actions/behavior.actions'
3
2
  import type {EditorSchema} from '../editor/editor-schema'
4
3
  import type {EditorSnapshot} from '../editor/editor-snapshot'
@@ -9,11 +8,14 @@ import {
9
8
  import {debugWithName} from '../internal-utils/debug'
10
9
  import type {PortableTextSlateEditor} from '../types/editor'
11
10
  import {defaultBehaviors} from './behavior.default'
11
+ import type {BehaviorAction} from './behavior.types.action'
12
+ import type {Behavior} from './behavior.types.behavior'
12
13
  import {
13
14
  isAbstractBehaviorEvent,
14
15
  isCustomBehaviorEvent,
15
16
  isNativeBehaviorEvent,
16
17
  isSyntheticBehaviorEvent,
18
+ type BehaviorEvent,
17
19
  } from './behavior.types.event'
18
20
 
19
21
  const debug = debugWithName('behaviors:event')
@@ -166,13 +168,23 @@ export function performEvent({
166
168
  for (const actionSet of eventBehavior.actions) {
167
169
  const actionsSnapshot = getSnapshot()
168
170
 
169
- const actions = actionSet(
170
- {
171
- snapshot: actionsSnapshot,
172
- event,
173
- },
174
- shouldRun,
175
- )
171
+ let actions: Array<BehaviorAction> = []
172
+
173
+ try {
174
+ actions = actionSet(
175
+ {
176
+ snapshot: actionsSnapshot,
177
+ event,
178
+ },
179
+ shouldRun,
180
+ )
181
+ } catch (error) {
182
+ console.error(
183
+ new Error(
184
+ `Evaluating actions for "${event.type}" failed due to: ${error.message}`,
185
+ ),
186
+ )
187
+ }
176
188
 
177
189
  if (actions.length === 0) {
178
190
  continue
@@ -188,16 +200,15 @@ export function performEvent({
188
200
  if (action.type === 'effect') {
189
201
  nativeEventPrevented = true
190
202
 
191
- performAction({
192
- context: {
193
- keyGenerator,
194
- schema,
195
- },
196
- action: {
197
- ...action,
198
- editor,
199
- },
200
- })
203
+ try {
204
+ action.effect()
205
+ } catch (error) {
206
+ console.error(
207
+ new Error(
208
+ `Executing effect as a result of "${event.type}" failed due to: ${error.message}`,
209
+ ),
210
+ )
211
+ }
201
212
 
202
213
  continue
203
214
  }
@@ -265,16 +276,15 @@ export function performEvent({
265
276
  if (action.type === 'effect') {
266
277
  nativeEventPrevented = true
267
278
 
268
- performAction({
269
- context: {
270
- keyGenerator,
271
- schema,
272
- },
273
- action: {
274
- ...action,
275
- editor,
276
- },
277
- })
279
+ try {
280
+ action.effect()
281
+ } catch (error) {
282
+ console.error(
283
+ new Error(
284
+ `Executing effect as a result of "${event.type}" failed due to: ${error.message}`,
285
+ ),
286
+ )
287
+ }
278
288
 
279
289
  continue
280
290
  }
@@ -76,9 +76,10 @@ export type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
76
76
  guardResponse: TGuardResponse,
77
77
  ) => Array<BehaviorAction>
78
78
 
79
- export type InternalBehaviorAction = (
80
- | OmitFromUnion<SyntheticBehaviorEvent, 'type', AbstractBehaviorEventType>
81
- | {type: 'effect'; effect: () => void}
82
- ) & {
79
+ export type InternalBehaviorAction = OmitFromUnion<
80
+ SyntheticBehaviorEvent,
81
+ 'type',
82
+ AbstractBehaviorEventType
83
+ > & {
83
84
  editor: PortableTextSlateEditor
84
85
  }
@@ -341,26 +341,34 @@ export const editorMachine = setup({
341
341
  'handle behavior event': ({context, event, self}) => {
342
342
  assertEvent(event, ['behavior event'])
343
343
 
344
- performEvent({
345
- mode: 'raise',
346
- behaviors: [...context.behaviors.values()],
347
- remainingEventBehaviors: [...context.behaviors.values()],
348
- event: event.behaviorEvent,
349
- editor: event.editor,
350
- keyGenerator: context.keyGenerator,
351
- schema: context.schema,
352
- getSnapshot: () =>
353
- createEditorSnapshot({
354
- converters: [...context.converters],
355
- editor: event.editor,
356
- keyGenerator: context.keyGenerator,
357
- readOnly: self.getSnapshot().matches({'edit mode': 'read only'}),
358
- schema: context.schema,
359
- hasTag: (tag) => self.getSnapshot().hasTag(tag),
360
- internalDrag: context.internalDrag,
361
- }),
362
- nativeEvent: event.nativeEvent,
363
- })
344
+ try {
345
+ performEvent({
346
+ mode: 'raise',
347
+ behaviors: [...context.behaviors.values()],
348
+ remainingEventBehaviors: [...context.behaviors.values()],
349
+ event: event.behaviorEvent,
350
+ editor: event.editor,
351
+ keyGenerator: context.keyGenerator,
352
+ schema: context.schema,
353
+ getSnapshot: () =>
354
+ createEditorSnapshot({
355
+ converters: [...context.converters],
356
+ editor: event.editor,
357
+ keyGenerator: context.keyGenerator,
358
+ readOnly: self.getSnapshot().matches({'edit mode': 'read only'}),
359
+ schema: context.schema,
360
+ hasTag: (tag) => self.getSnapshot().hasTag(tag),
361
+ internalDrag: context.internalDrag,
362
+ }),
363
+ nativeEvent: event.nativeEvent,
364
+ })
365
+ } catch (error) {
366
+ console.error(
367
+ new Error(
368
+ `Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`,
369
+ ),
370
+ )
371
+ }
364
372
  },
365
373
  },
366
374
  guards: {
@@ -1,7 +0,0 @@
1
- import type {BehaviorActionImplementation} from './behavior.actions'
2
-
3
- export const effectActionImplementation: BehaviorActionImplementation<
4
- 'effect'
5
- > = ({action}) => {
6
- action.effect()
7
- }