@portabletext/editor 2.8.2 → 2.8.4

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.
@@ -3621,7 +3621,7 @@ type BehaviorAction = {
3621
3621
  * })
3622
3622
  * ```
3623
3623
  */
3624
- send: (event: SyntheticBehaviorEvent | CustomBehaviorEvent) => void;
3624
+ send: (event: ExternalBehaviorEvent) => void;
3625
3625
  }) => void;
3626
3626
  };
3627
3627
  /**
@@ -1,7 +1,7 @@
1
1
  import { Patch, Patch as Patch$1 } from "@portabletext/patches";
2
2
  import * as _sanity_types5 from "@sanity/types";
3
3
  import { ArrayDefinition, ArraySchemaType, BlockDecoratorDefinition, BlockListDefinition, BlockStyleDefinition, ObjectSchemaType, Path, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextListBlock, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, TypedObject } from "@sanity/types";
4
- import * as _portabletext_schema5 from "@portabletext/schema";
4
+ import * as _portabletext_schema6 from "@portabletext/schema";
5
5
  import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, DecoratorDefinition, DecoratorSchemaType, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, ListDefinition, ListSchemaType, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, defineSchema } from "@portabletext/schema";
6
6
  import * as xstate227 from "xstate";
7
7
  import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
@@ -1780,7 +1780,7 @@ declare const editorMachine: xstate227.StateMachine<{
1780
1780
  keyGenerator: () => string;
1781
1781
  pendingEvents: never[];
1782
1782
  pendingIncomingPatchesEvents: never[];
1783
- schema: _portabletext_schema5.Schema;
1783
+ schema: _portabletext_schema6.Schema;
1784
1784
  selection: null;
1785
1785
  initialReadOnly: boolean;
1786
1786
  maxBlocks: number | undefined;
@@ -3621,7 +3621,7 @@ type BehaviorAction = {
3621
3621
  * })
3622
3622
  * ```
3623
3623
  */
3624
- send: (event: SyntheticBehaviorEvent | CustomBehaviorEvent) => void;
3624
+ send: (event: ExternalBehaviorEvent) => void;
3625
3625
  }) => void;
3626
3626
  };
3627
3627
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {EditorDom} from '../editor/editor-dom'\nimport 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: (payload: {\n /**\n * Send a Behavior Event back into the Editor.\n *\n * @example\n * ```ts\n * defineBehavior({\n * on: '...',\n * actions: [\n * () => [\n * effect(({send}) => {\n * doSomethingAsync()\n * .then(() => {\n * send({\n * type: '...',\n * })\n * })\n * })\n * ],\n * ],\n * })\n * ```\n */\n send: (event: SyntheticBehaviorEvent | CustomBehaviorEvent) => void\n }) => 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: PickFromUnion<BehaviorAction, 'type', 'effect'>['effect'],\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 dom: EditorDom\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":";;AAyDO,SAASA,QACdC,OACkD;AAClD,SAAO;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAAA;AAC3B;AAKO,SAASE,QACdF,OACkD;AAClD,SAAO;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAAA;AAC3B;AAKO,SAASG,MACdH,OACgD;AAChD,SAAO;AAAA,IAACC,MAAM;AAAA,IAASD;AAAAA,EAAAA;AACzB;AAKO,SAASI,OACdA,SACiD;AACjD,SAAO;AAAA,IAACH,MAAM;AAAA,IAAUG,QAAAA;AAAAA,EAAAA;AAC1B;ACnBO,SAASC,eAYdC,UACU;AACV,SAAOA;AACT;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {EditorDom} from '../editor/editor-dom'\nimport type {EditorSnapshot} from '../editor/editor-snapshot'\nimport type {PickFromUnion} from '../type-utils'\nimport type {\n CustomBehaviorEvent,\n ExternalBehaviorEvent,\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: (payload: {\n /**\n * Send a Behavior Event back into the Editor.\n *\n * @example\n * ```ts\n * defineBehavior({\n * on: '...',\n * actions: [\n * () => [\n * effect(({send}) => {\n * doSomethingAsync()\n * .then(() => {\n * send({\n * type: '...',\n * })\n * })\n * })\n * ],\n * ],\n * })\n * ```\n */\n send: (event: ExternalBehaviorEvent) => void\n }) => 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: PickFromUnion<BehaviorAction, 'type', 'effect'>['effect'],\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 dom: EditorDom\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":";;AA0DO,SAASA,QACdC,OACkD;AAClD,SAAO;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAAA;AAC3B;AAKO,SAASE,QACdF,OACkD;AAClD,SAAO;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAAA;AAC3B;AAKO,SAASG,MACdH,OACgD;AAChD,SAAO;AAAA,IAACC,MAAM;AAAA,IAASD;AAAAA,EAAAA;AACzB;AAKO,SAASI,OACdA,SACiD;AACjD,SAAO;AAAA,IAACH,MAAM;AAAA,IAAUG,QAAAA;AAAAA,EAAAA;AAC1B;ACpBO,SAASC,eAYdC,UACU;AACV,SAAOA;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 {EditorDom} from '../editor/editor-dom'\nimport 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: (payload: {\n /**\n * Send a Behavior Event back into the Editor.\n *\n * @example\n * ```ts\n * defineBehavior({\n * on: '...',\n * actions: [\n * () => [\n * effect(({send}) => {\n * doSomethingAsync()\n * .then(() => {\n * send({\n * type: '...',\n * })\n * })\n * })\n * ],\n * ],\n * })\n * ```\n */\n send: (event: SyntheticBehaviorEvent | CustomBehaviorEvent) => void\n }) => 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: PickFromUnion<BehaviorAction, 'type', 'effect'>['effect'],\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 dom: EditorDom\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":"AAyDO,SAASA,QACdC,OACkD;AAClD,SAAO;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAAA;AAC3B;AAKO,SAASE,QACdF,OACkD;AAClD,SAAO;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAAA;AAC3B;AAKO,SAASG,MACdH,OACgD;AAChD,SAAO;AAAA,IAACC,MAAM;AAAA,IAASD;AAAAA,EAAAA;AACzB;AAKO,SAASI,OACdA,SACiD;AACjD,SAAO;AAAA,IAACH,MAAM;AAAA,IAAUG,QAAAA;AAAAA,EAAAA;AAC1B;ACnBO,SAASC,eAYdC,UACU;AACV,SAAOA;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {EditorDom} from '../editor/editor-dom'\nimport type {EditorSnapshot} from '../editor/editor-snapshot'\nimport type {PickFromUnion} from '../type-utils'\nimport type {\n CustomBehaviorEvent,\n ExternalBehaviorEvent,\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: (payload: {\n /**\n * Send a Behavior Event back into the Editor.\n *\n * @example\n * ```ts\n * defineBehavior({\n * on: '...',\n * actions: [\n * () => [\n * effect(({send}) => {\n * doSomethingAsync()\n * .then(() => {\n * send({\n * type: '...',\n * })\n * })\n * })\n * ],\n * ],\n * })\n * ```\n */\n send: (event: ExternalBehaviorEvent) => void\n }) => 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: PickFromUnion<BehaviorAction, 'type', 'effect'>['effect'],\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 dom: EditorDom\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":"AA0DO,SAASA,QACdC,OACkD;AAClD,SAAO;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAAA;AAC3B;AAKO,SAASE,QACdF,OACkD;AAClD,SAAO;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAAA;AAC3B;AAKO,SAASG,MACdH,OACgD;AAChD,SAAO;AAAA,IAACC,MAAM;AAAA,IAASD;AAAAA,EAAAA;AACzB;AAKO,SAASI,OACdA,SACiD;AACjD,SAAO;AAAA,IAACH,MAAM;AAAA,IAAUG,QAAAA;AAAAA,EAAAA;AAC1B;ACpBO,SAASC,eAYdC,UACU;AACV,SAAOA;AACT;"}
package/lib/index.cjs CHANGED
@@ -3669,19 +3669,17 @@ function toInt(num) {
3669
3669
  return parseInt(num, 10);
3670
3670
  }
3671
3671
  const CURRENT_UNDO_STEP = /* @__PURE__ */ new WeakMap();
3672
- function withUndoStep(editor, fn) {
3673
- const current = CURRENT_UNDO_STEP.get(editor);
3674
- if (current) {
3675
- fn();
3676
- return;
3677
- }
3678
- CURRENT_UNDO_STEP.set(editor, current ?? {
3679
- undoStepId: util_sliceBlocks.defaultKeyGenerator()
3680
- }), fn(), CURRENT_UNDO_STEP.set(editor, void 0);
3681
- }
3682
3672
  function getCurrentUndoStepId(editor) {
3683
3673
  return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
3684
3674
  }
3675
+ function createUndoStep(editor) {
3676
+ CURRENT_UNDO_STEP.set(editor, {
3677
+ undoStepId: util_sliceBlocks.defaultKeyGenerator()
3678
+ });
3679
+ }
3680
+ function clearUndoStep(editor) {
3681
+ CURRENT_UNDO_STEP.set(editor, void 0);
3682
+ }
3685
3683
  const debug$b = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
3686
3684
  const state = SAVING.get(editor);
3687
3685
  return state === void 0 ? !0 : state;
@@ -9027,7 +9025,7 @@ function performEvent({
9027
9025
  nativeEvent,
9028
9026
  sendBack
9029
9027
  }) {
9030
- debug$6(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
9028
+ mode === "send" && !isNativeBehaviorEvent(event) && createUndoStep(editor), debug$6(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
9031
9029
  const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
9032
9030
  if (behavior.on === "*")
9033
9031
  return !0;
@@ -9035,7 +9033,7 @@ function performEvent({
9035
9033
  return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
9036
9034
  });
9037
9035
  if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
9038
- nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
9036
+ nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withApplyingBehaviorOperations(editor, () => {
9039
9037
  debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
9040
9038
  context: {
9041
9039
  keyGenerator,
@@ -9079,63 +9077,63 @@ function performEvent({
9079
9077
  }
9080
9078
  if (actions.length !== 0) {
9081
9079
  if (nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward"), actions.some((action) => action.type === "execute")) {
9082
- withUndoStep(editor, () => {
9083
- for (const action of actions) {
9084
- if (action.type === "effect") {
9085
- try {
9086
- action.effect({
9087
- send: sendBack
9088
- });
9089
- } catch (error) {
9090
- console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
9091
- }
9092
- continue;
9093
- }
9094
- if (action.type === "forward") {
9095
- const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9096
- performEvent({
9097
- mode: "forward",
9098
- behaviors,
9099
- remainingEventBehaviors: remainingEventBehaviors2,
9100
- event: action.event,
9101
- editor,
9102
- keyGenerator,
9103
- schema: schema2,
9104
- getSnapshot,
9105
- nativeEvent,
9106
- sendBack
9107
- });
9108
- continue;
9109
- }
9110
- if (action.type === "raise") {
9111
- performEvent({
9112
- mode: "raise",
9113
- behaviors,
9114
- remainingEventBehaviors: behaviors,
9115
- event: action.event,
9116
- editor,
9117
- keyGenerator,
9118
- schema: schema2,
9119
- getSnapshot,
9120
- nativeEvent,
9121
- sendBack
9080
+ createUndoStep(editor);
9081
+ for (const action of actions) {
9082
+ if (action.type === "effect") {
9083
+ try {
9084
+ action.effect({
9085
+ send: sendBack
9122
9086
  });
9123
- continue;
9087
+ } catch (error) {
9088
+ console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
9124
9089
  }
9090
+ continue;
9091
+ }
9092
+ if (action.type === "forward") {
9093
+ const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9125
9094
  performEvent({
9126
- mode: "execute",
9095
+ mode: "forward",
9127
9096
  behaviors,
9128
- remainingEventBehaviors: [],
9097
+ remainingEventBehaviors: remainingEventBehaviors2,
9129
9098
  event: action.event,
9130
9099
  editor,
9131
9100
  keyGenerator,
9132
9101
  schema: schema2,
9133
9102
  getSnapshot,
9134
- nativeEvent: void 0,
9103
+ nativeEvent,
9135
9104
  sendBack
9136
9105
  });
9106
+ continue;
9137
9107
  }
9138
- });
9108
+ if (action.type === "raise") {
9109
+ performEvent({
9110
+ mode: "raise",
9111
+ behaviors,
9112
+ remainingEventBehaviors: behaviors,
9113
+ event: action.event,
9114
+ editor,
9115
+ keyGenerator,
9116
+ schema: schema2,
9117
+ getSnapshot,
9118
+ nativeEvent,
9119
+ sendBack
9120
+ });
9121
+ continue;
9122
+ }
9123
+ performEvent({
9124
+ mode: "execute",
9125
+ behaviors,
9126
+ remainingEventBehaviors: [],
9127
+ event: action.event,
9128
+ editor,
9129
+ keyGenerator,
9130
+ schema: schema2,
9131
+ getSnapshot,
9132
+ nativeEvent: void 0,
9133
+ sendBack
9134
+ });
9135
+ }
9136
+ clearUndoStep(editor);
9139
9137
  continue;
9140
9138
  }
9141
9139
  for (const action of actions) {
@@ -9187,7 +9185,7 @@ function performEvent({
9187
9185
  break;
9188
9186
  }
9189
9187
  }
9190
- !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
9188
+ !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withApplyingBehaviorOperations(editor, () => {
9191
9189
  debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
9192
9190
  context: {
9193
9191
  keyGenerator,
@@ -9268,7 +9266,44 @@ function createEditorSnapshot({
9268
9266
  decoratorState: editor.decoratorState
9269
9267
  };
9270
9268
  }
9271
- const debug$5 = debugWithName("editor machine"), editorMachine = xstate.setup({
9269
+ const debug$5 = debugWithName("editor machine");
9270
+ function rerouteExternalBehaviorEvent({
9271
+ event,
9272
+ slateEditor
9273
+ }) {
9274
+ switch (event.type) {
9275
+ case "blur":
9276
+ return {
9277
+ type: "blur",
9278
+ editor: slateEditor
9279
+ };
9280
+ case "focus":
9281
+ return {
9282
+ type: "focus",
9283
+ editor: slateEditor
9284
+ };
9285
+ case "insert.block object":
9286
+ return {
9287
+ type: "behavior event",
9288
+ behaviorEvent: {
9289
+ type: "insert.block",
9290
+ block: {
9291
+ _type: event.blockObject.name,
9292
+ ...event.blockObject.value ?? {}
9293
+ },
9294
+ placement: event.placement
9295
+ },
9296
+ editor: slateEditor
9297
+ };
9298
+ default:
9299
+ return {
9300
+ type: "behavior event",
9301
+ behaviorEvent: event,
9302
+ editor: slateEditor
9303
+ };
9304
+ }
9305
+ }
9306
+ const editorMachine = xstate.setup({
9272
9307
  types: {
9273
9308
  context: {},
9274
9309
  events: {},
@@ -9370,7 +9405,7 @@ const debug$5 = debugWithName("editor machine"), editorMachine = xstate.setup({
9370
9405
  try {
9371
9406
  const behaviors = [...context.behaviors.values()].map((config) => config.behavior);
9372
9407
  performEvent({
9373
- mode: "raise",
9408
+ mode: "send",
9374
9409
  behaviors,
9375
9410
  remainingEventBehaviors: behaviors,
9376
9411
  event: event.behaviorEvent,
@@ -9392,11 +9427,10 @@ const debug$5 = debugWithName("editor machine"), editorMachine = xstate.setup({
9392
9427
  self.send(eventSentBack);
9393
9428
  return;
9394
9429
  }
9395
- self.send({
9396
- type: "behavior event",
9397
- behaviorEvent: eventSentBack,
9398
- editor: event.editor
9399
- });
9430
+ self.send(rerouteExternalBehaviorEvent({
9431
+ event: eventSentBack,
9432
+ slateEditor: event.editor
9433
+ }));
9400
9434
  }
9401
9435
  });
9402
9436
  } catch (error) {
@@ -11342,38 +11376,11 @@ function createInternalEditor(config) {
11342
11376
  case "update maxBlocks":
11343
11377
  editorActor.send(event);
11344
11378
  break;
11345
- case "blur":
11346
- editorActor.send({
11347
- type: "blur",
11348
- editor: slateEditor.instance
11349
- });
11350
- break;
11351
- case "focus":
11352
- editorActor.send({
11353
- type: "focus",
11354
- editor: slateEditor.instance
11355
- });
11356
- break;
11357
- case "insert.block object":
11358
- editorActor.send({
11359
- type: "behavior event",
11360
- behaviorEvent: {
11361
- type: "insert.block",
11362
- block: {
11363
- _type: event.blockObject.name,
11364
- ...event.blockObject.value ?? {}
11365
- },
11366
- placement: event.placement
11367
- },
11368
- editor: slateEditor.instance
11369
- });
11370
- break;
11371
11379
  default:
11372
- editorActor.send({
11373
- type: "behavior event",
11374
- behaviorEvent: event,
11375
- editor: slateEditor.instance
11376
- });
11380
+ editorActor.send(rerouteExternalBehaviorEvent({
11381
+ event,
11382
+ slateEditor: slateEditor.instance
11383
+ }));
11377
11384
  }
11378
11385
  },
11379
11386
  on: (event, listener) => relayActor.on(event, (event2) => {