@portabletext/toolbar 8.0.50 → 9.0.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.
package/dist/index.js CHANGED
@@ -79,9 +79,6 @@ function useToolbarSchema(props) {
79
79
  styles: t5
80
80
  }, $[30] = t0, $[31] = t1, $[32] = t2, $[33] = t3, $[34] = t4, $[35] = t5, $[36] = t6) : t6 = $[36], t6;
81
81
  }
82
- /**
83
- * @beta
84
- */
85
82
  function _temp$2(snapshot) {
86
83
  return getUnionSchema(snapshot.context.schema, snapshot.context.containers);
87
84
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useEditor","useEditorSelector","compareApplicableSchema","getApplicableSchema","ApplicableSchema","useApplicableSchema","editor","useEditor","useEditorSelector","AnnotationDefinition","AnnotationSchemaType","BlockObjectSchemaType","DecoratorDefinition","DecoratorSchemaType","EditorSchema","InlineObjectSchemaType","ListSchemaType","StyleSchemaType","getUnionSchema","KeyboardShortcut","ExtendDecoratorSchemaType","decorator","ToolbarDecoratorSchemaType","ExtendAnnotationSchemaType","annotation","ToolbarAnnotationSchemaType","ExtendListSchemaType","list","ToolbarListSchemaType","ExtendBlockObjectSchemaType","blockObject","ToolbarBlockObjectSchemaType","ExtendInlineObjectSchemaType","inlineObject","ToolbarInlineObjectSchemaType","ExtendStyleSchemaType","style","ToolbarStyleSchemaType","useToolbarSchema","props","$","_c","editor","union","_temp","compareSchemas","t0","decorators","t1","extendDecorator","map","annotations","t2","extendAnnotation","lists","t3","extendList","blockObjects","t4","extendBlockObject","inlineObjects","t5","extendInlineObject","styles","t6","extendStyle","snapshot","context","schema","containers","ToolbarSchema","ReadonlyArray","icon","React","ComponentType","className","shortcut","mutuallyExclusive","defaultValues","Record","a","b","compareNamed","name","length","i","Editor","fromCallback","AnyEventObject","DisableListenerEvent","type","disableListener","editor","input","sendBack","getSnapshot","context","readOnly","on","batch","unsubscribe","useEditor","defineBehavior","execute","raise","isSelectionExpanded","useEffect","ToolbarAnnotationSchemaType","useMutuallyExclusiveAnnotation","props","$","_c","editor","t0","t1","schemaType","mutuallyExclusive","name","registerBehavior","behavior","on","guard","t2","snapshot","event","annotation","actions","t3","event_0","map","_temp","type","useEditor","Editor","defineBehavior","effect","raise","selectors","useActor","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","useMutuallyExclusiveAnnotation","ToolbarAnnotationSchemaType","activeListener","editor","schemaType","type","input","sendBack","isActiveAnnotation","name","getSnapshot","on","snapshot","batch","unsubscribe","keyboardShortcutRemove","shortcut","registerBehavior","behavior","guard","event","originEvent","actions","annotation","send","keyboardShortcutShowInsertDialog","annotationButtonMachine","types","context","events","AnnotationButtonEvent","add annotation","value","remove annotation","actors","createMachine","id","invoke","src","initial","states","disabled","inactive","target","active","enabled","Record","AnnotationButton","matches","state","useAnnotationButton","props","$","_c","t0","t1","t2","useEditor","AnnotationPath","AnnotationSchemaType","Editor","PortableTextObject","selectors","useActor","React","RefObject","assign","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","ToolbarAnnotationSchemaType","ActiveContext","annotations","Array","value","schemaType","at","elementRef","Element","ActiveListenerEvent","type","activeListener","editor","schemaTypes","ReadonlyArray","input","sendBack","on","snapshot","getSnapshot","activeAnnotations","getActiveAnnotations","focusBlock","getFocusBlock","length","selectedChildren","dom","getChildNodes","firstSelectedChild","createRef","current","flatMap","annotation","find","name","_type","path","_key","batch","unsubscribe","annotationPopoverMachine","types","context","events","AnnotationPopoverEvent","actions","reset","remove","event","send","actors","createMachine","id","invoke","src","initial","states","disabled","inactive","entry","target","active","enabled","props","key","AnnotationPopover","matches","state","useAnnotationPopover","$","_c","t0","actorSnapshot","t1","t2","t3","t4","useEditor","Editor","defineBehavior","effect","InsertPlacement","useActor","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","ToolbarBlockObjectSchemaType","keyboardShortcutListener","editor","schemaType","BlockObjectButtonEvent","input","sendBack","shortcut","registerBehavior","behavior","on","guard","event","originEvent","actions","type","blockObjectButtonMachine","types","context","events","insert","send","blockObject","name","value","placement","actors","createMachine","id","invoke","src","initial","states","disabled","enable","target","enabled","disable","key","BlockObjectButton","snapshot","matches","state","useBlockObjectButton","props","$","_c","t0","actorSnapshot","t1","t2","useEditor","BlockPath","Editor","PortableTextObject","selectors","useActor","React","RefObject","assign","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","ToolbarBlockObjectSchemaType","ActiveContext","blockObjects","Array","value","schemaType","at","elementRef","Element","ActiveListenerEvent","type","activeListener","editor","schemaTypes","ReadonlyArray","input","sendBack","on","snapshot","getSnapshot","isSelectionCollapsed","focusBlockObject","getFocusBlockObject","find","name","node","_type","selectedNodes","dom","getBlockNodes","firstSelectedNode","createRef","current","path","batch","unsubscribe","blockObjectPopoverMachine","types","context","events","BlockObjectPopoverEvent","actions","reset","actors","createMachine","id","invoke","src","initial","states","disabled","inactive","entry","event","target","active","enabled","send","props","key","BlockObjectPopover","matches","state","useBlockObjectPopover","$","_c","t0","actorSnapshot","t1","t2","t3","t4","useEditor","Editor","defineBehavior","raise","useActorRef","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","ToolbarDecoratorSchemaType","keyboardShortcutListener","editor","schemaType","input","shortcut","registerBehavior","behavior","on","guard","event","originEvent","actions","type","decorator","name","decoratorKeyboardShortcutMachine","types","context","events","actors","createMachine","id","invoke","src","initial","states","disabled","enable","target","enabled","disable","useDecoratorKeyboardShortcut","props","$","_c","t0","useEditor","defineBehavior","forward","raise","useEffect","ToolbarDecoratorSchemaType","useMutuallyExclusiveDecorator","props","$","_c","editor","t0","t1","schemaType","mutuallyExclusive","name","registerBehavior","behavior","on","guard","t2","event","decorator","actions","t3","event_0","map","_temp","type","useEditor","DecoratorSchemaType","Editor","selectors","useActor","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","useDecoratorKeyboardShortcut","useMutuallyExclusiveDecorator","ToolbarDecoratorSchemaType","activeListener","editor","schemaType","type","input","sendBack","isActiveDecorator","name","getSnapshot","on","snapshot","batch","unsubscribe","decoratorButtonMachine","types","context","events","DecoratorButtonEvent","actions","toggle","event","send","decorator","actors","createMachine","id","invoke","src","initial","states","disabled","inactive","target","active","enabled","DecoratorButton","matches","state","useDecoratorButton","props","$","_c","t0","actorSnapshot","t1","t2","useEditor","Editor","useActor","setup","disableListener","DisableListenerEvent","historyButtonsMachine","types","context","editor","input","events","HistoryButtonsEvent","actors","createMachine","id","invoke","src","initial","states","disabled","on","enable","target","enabled","actions","send","type","HistoryButtons","snapshot","matches","state","event","useHistoryButtons","$","_c","t0","actorSnapshot","t1","t2","useEditor","Editor","defineBehavior","effect","useActor","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","ToolbarInlineObjectSchemaType","keyboardShortcutListener","editor","schemaType","InlineObjectButtonEvent","input","sendBack","shortcut","registerBehavior","behavior","on","guard","event","originEvent","actions","type","inlineObjectButtonMachine","types","context","events","insert","send","inlineObject","name","value","actors","createMachine","id","invoke","src","initial","states","disabled","enable","target","enabled","disable","key","InlineObjectButton","snapshot","matches","state","useInlineObjectButton","props","$","_c","t0","actorSnapshot","t1","t2","useEditor","ChildPath","Editor","PortableTextObject","selectors","useActor","React","RefObject","assign","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","ToolbarInlineObjectSchemaType","ActiveContext","inlineObjects","Array","value","schemaType","at","elementRef","Element","ActiveListenerEvent","type","activeListener","editor","schemaTypes","ReadonlyArray","input","sendBack","on","snapshot","getSnapshot","isSelectionCollapsed","focusInlineObject","getFocusInlineObject","find","name","node","_type","selectedNodes","dom","getChildNodes","firstSelectedNode","createRef","current","path","batch","unsubscribe","inlineObjectPopoverMachine","types","context","events","InlineObjectPopoverEvent","actions","reset","actors","createMachine","id","invoke","src","initial","states","disabled","inactive","entry","event","target","active","enabled","send","props","key","InlineObjectPopover","matches","state","useInlineObjectPopover","$","_c","t0","actorSnapshot","t1","t2","t3","t4","useEditor","Editor","ListSchemaType","selectors","useActor","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","ToolbarListSchemaType","activeListener","editor","schemaType","type","input","sendBack","isActiveListItem","name","getSnapshot","on","snapshot","batch","unsubscribe","listButtonMachine","types","context","events","ListButtonEvent","actions","toggle","event","send","listItem","actors","createMachine","id","invoke","src","initial","states","disabled","inactive","target","active","enabled","ListButton","matches","state","useListButton","props","$","_c","t0","actorSnapshot","t1","t2","useEditor","Editor","defineBehavior","raise","useActorRef","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","ToolbarStyleSchemaType","styleKeyboardShortcutsListener","editor","schemaTypes","ReadonlyArray","input","unregisterBehaviors","flatMap","schemaType","shortcut","registerBehavior","behavior","on","guard","event","originEvent","actions","type","style","name","unregisterBehavior","styleKeyboardShortcutsMachine","types","context","events","actors","createMachine","id","invoke","src","initial","states","disabled","enable","target","enabled","disable","useStyleKeyboardShortcuts","props","$","_c","t0","useEditor","Editor","StyleSchemaType","selectors","useActor","assign","fromCallback","setup","AnyEventObject","disableListener","DisableListenerEvent","useStyleKeyboardShortcuts","ToolbarStyleSchemaType","ActiveStyleListenerEvent","type","style","activeListener","editor","input","sendBack","activeStyle","getActiveStyle","getSnapshot","on","snapshot","batch","unsubscribe","styleSelectorMachine","types","context","events","StyleSelectorEvent","actors","createMachine","id","undefined","invoke","src","guard","event","actions","initial","states","disabled","enable","target","enabled","disable","toggle","send","StyleSelector","matches","state","useStyleSelector","props","$","_c","t0","actorSnapshot","t1","t2","t3","t4"],"sources":["../src/use-applicable-schema.ts","../src/use-toolbar-schema.ts","../src/disable-listener.ts","../src/use-mutually-exclusive-annotation.ts","../src/use-annotation-button.ts","../src/use-annotation-popover.ts","../src/use-block-object-button.ts","../src/use-block-object-popover.ts","../src/use-decorator-keyboard-shortcut.ts","../src/use-mutually-exclusive-decorator.ts","../src/use-decorator-button.ts","../src/use-history-buttons.ts","../src/use-inline-object-button.ts","../src/use-inline-object-popover.ts","../src/use-list-button.ts","../src/use-style-keyboard-shortcuts.ts","../src/use-style-selector.ts"],"sourcesContent":["import {useEditor, useEditorSelector} from '@portabletext/editor'\nimport {\n compareApplicableSchema,\n getApplicableSchema,\n type ApplicableSchema,\n} from '@portabletext/editor/selectors'\n\nexport type {ApplicableSchema}\n\n/**\n * @beta\n *\n * React hook that subscribes to {@link getApplicableSchema} for the active\n * editor and returns a stable reference across editor ticks while the\n * applicable set is unchanged.\n *\n * Pair with {@link useToolbarSchema} to render a static toolbar whose\n * buttons stay stable across selection moves and gate their enabled state\n * on whether the corresponding name is in the relevant set.\n */\nexport function useApplicableSchema(): ApplicableSchema {\n const editor = useEditor()\n return useEditorSelector(editor, getApplicableSchema, compareApplicableSchema)\n}\n","import {\n useEditor,\n useEditorSelector,\n type AnnotationDefinition,\n type AnnotationSchemaType,\n type BlockObjectSchemaType,\n type DecoratorDefinition,\n type DecoratorSchemaType,\n type EditorSchema,\n type InlineObjectSchemaType,\n type ListSchemaType,\n type StyleSchemaType,\n} from '@portabletext/editor'\nimport {getUnionSchema} from '@portabletext/editor/traversal'\nimport type {KeyboardShortcut} from '@portabletext/keyboard-shortcuts'\n\n/**\n * @beta\n */\nexport type ExtendDecoratorSchemaType = (\n decorator: DecoratorSchemaType,\n) => ToolbarDecoratorSchemaType\n\n/**\n * @beta\n */\nexport type ExtendAnnotationSchemaType = (\n annotation: AnnotationSchemaType,\n) => ToolbarAnnotationSchemaType\n\n/**\n * @beta\n */\nexport type ExtendListSchemaType = (\n list: ListSchemaType,\n) => ToolbarListSchemaType\n\n/**\n * @beta\n */\nexport type ExtendBlockObjectSchemaType = (\n blockObject: BlockObjectSchemaType,\n) => ToolbarBlockObjectSchemaType\n\n/**\n * @beta\n */\nexport type ExtendInlineObjectSchemaType = (\n inlineObject: InlineObjectSchemaType,\n) => ToolbarInlineObjectSchemaType\n\n/**\n * @beta\n */\nexport type ExtendStyleSchemaType = (\n style: StyleSchemaType,\n) => ToolbarStyleSchemaType\n\n/**\n * @beta\n *\n * Resolve the editor's full toolbar schema. Returns the union of every\n * decorator, annotation, list, style, block object and inline object declared\n * anywhere in the editor's schema graph that is reachable from a position\n * where text is edited - the root schema merged with the sub-schema of every\n * registered container whose field accepts text blocks. Useful for rendering\n * a static toolbar whose buttons stay stable across selection moves.\n *\n * Re-renders only when the schema graph or the extension callbacks change.\n * Pair with {@link useApplicableSchema} to determine which entries are\n * applicable at the current selection (which buttons should be enabled vs.\n * disabled).\n */\nexport function useToolbarSchema(props: {\n extendDecorator?: ExtendDecoratorSchemaType\n extendAnnotation?: ExtendAnnotationSchemaType\n extendList?: ExtendListSchemaType\n extendBlockObject?: ExtendBlockObjectSchemaType\n extendInlineObject?: ExtendInlineObjectSchemaType\n extendStyle?: ExtendStyleSchemaType\n}): ToolbarSchema {\n const editor = useEditor()\n const union = useEditorSelector(\n editor,\n (snapshot) =>\n getUnionSchema(snapshot.context.schema, snapshot.context.containers),\n compareSchemas,\n )\n\n return {\n decorators: union.decorators.map(\n (decorator) => props.extendDecorator?.(decorator) ?? decorator,\n ),\n annotations: union.annotations.map(\n (annotation) => props.extendAnnotation?.(annotation) ?? annotation,\n ),\n lists: union.lists.map((list) => props.extendList?.(list) ?? list),\n blockObjects: union.blockObjects.map(\n (blockObject) => props.extendBlockObject?.(blockObject) ?? blockObject,\n ),\n inlineObjects: union.inlineObjects.map(\n (inlineObject) =>\n props.extendInlineObject?.(inlineObject) ?? inlineObject,\n ),\n styles: union.styles.map((style) => props.extendStyle?.(style) ?? style),\n }\n}\n\n/**\n * @beta\n */\nexport type ToolbarSchema = {\n decorators: ReadonlyArray<ToolbarDecoratorSchemaType>\n annotations: ReadonlyArray<ToolbarAnnotationSchemaType>\n lists: ReadonlyArray<ToolbarListSchemaType>\n blockObjects: ReadonlyArray<ToolbarBlockObjectSchemaType>\n inlineObjects: ReadonlyArray<ToolbarInlineObjectSchemaType>\n styles: ReadonlyArray<ToolbarStyleSchemaType>\n}\n\n/**\n * @beta\n */\nexport type ToolbarDecoratorSchemaType = DecoratorSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n shortcut?: KeyboardShortcut\n mutuallyExclusive?: ReadonlyArray<DecoratorDefinition['name']>\n}\n\n/**\n * @beta\n */\nexport type ToolbarAnnotationSchemaType = AnnotationSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n defaultValues?: Record<string, unknown>\n shortcut?: KeyboardShortcut\n /**\n * The annotations this annotation cannot coexist with. The list\n * replaces the default rule that an annotation is mutually exclusive\n * with itself:\n *\n * - Absent: the default applies (adding the annotation removes\n * existing annotations of the same type in the selection).\n * - `[]`: exclusive with nothing, not even itself, so same-type\n * annotations may overlap.\n * - `['other']`: exclusive with exactly the listed annotations.\n * Include the annotation's own name to keep self-exclusivity.\n */\n mutuallyExclusive?: ReadonlyArray<AnnotationDefinition['name']>\n}\n\n/**\n * @beta\n */\nexport type ToolbarListSchemaType = ListSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n}\n\n/**\n * @beta\n */\nexport type ToolbarBlockObjectSchemaType = BlockObjectSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n defaultValues?: Record<string, unknown>\n shortcut?: KeyboardShortcut\n}\n\n/**\n * @beta\n */\nexport type ToolbarInlineObjectSchemaType = InlineObjectSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n defaultValues?: Record<string, unknown>\n shortcut?: KeyboardShortcut\n}\n\n/**\n * @beta\n */\nexport type ToolbarStyleSchemaType = StyleSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n shortcut?: KeyboardShortcut\n}\n\nfunction compareSchemas(a: EditorSchema, b: EditorSchema) {\n if (a === b) {\n return true\n }\n return (\n compareNamed(a.decorators, b.decorators) &&\n compareNamed(a.annotations, b.annotations) &&\n compareNamed(a.lists, b.lists) &&\n compareNamed(a.styles, b.styles) &&\n compareNamed(a.blockObjects, b.blockObjects) &&\n compareNamed(a.inlineObjects, b.inlineObjects)\n )\n}\n\nfunction compareNamed(\n a: ReadonlyArray<{name: string}>,\n b: ReadonlyArray<{name: string}>,\n) {\n if (a === b) {\n return true\n }\n if (a.length !== b.length) {\n return false\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i]!.name !== b[i]!.name) {\n return false\n }\n }\n return true\n}\n","import type {Editor} from '@portabletext/editor'\nimport {fromCallback, type AnyEventObject} from 'xstate'\n\nexport type DisableListenerEvent = {type: 'enable'} | {type: 'disable'}\n\nexport const disableListener = fromCallback<\n AnyEventObject,\n {editor: Editor},\n DisableListenerEvent\n>(({input, sendBack}) => {\n // Send back the initial state\n if (input.editor.getSnapshot().context.readOnly) {\n sendBack({type: 'disable'})\n } else {\n sendBack({type: 'enable'})\n }\n\n return input.editor.on(\n '*',\n () => {\n if (input.editor.getSnapshot().context.readOnly) {\n sendBack({type: 'disable'})\n } else {\n sendBack({type: 'enable'})\n }\n },\n {batch: true},\n ).unsubscribe\n})\n","import {useEditor} from '@portabletext/editor'\nimport {defineBehavior, execute, raise} from '@portabletext/editor/behaviors'\nimport {isSelectionExpanded} from '@portabletext/editor/selectors'\nimport {useEffect} from 'react'\nimport type {ToolbarAnnotationSchemaType} from './use-toolbar-schema'\n\nexport function useMutuallyExclusiveAnnotation(props: {\n schemaType: ToolbarAnnotationSchemaType\n}) {\n const editor = useEditor()\n\n useEffect(() => {\n const mutuallyExclusive = props.schemaType.mutuallyExclusive\n\n if (!mutuallyExclusive) {\n // Absent config keeps the Core Behavior default (self-exclusive).\n // An empty array is deliberate \"exclusive with nothing\" config and\n // must fall through to register; see `mutuallyExclusive`'s docs.\n return\n }\n\n return editor.registerBehavior({\n behavior: defineBehavior({\n on: 'annotation.add',\n guard: ({snapshot, event}) => {\n if (event.annotation.name !== props.schemaType.name) {\n return false\n }\n\n // Declining collapsed selections lets the Core Behavior expand\n // them to the caret word and re-raise the add; the re-raised,\n // now-expanded add re-enters this chain and passes this guard.\n // Intercepting the collapsed add directly would `execute` past\n // that expansion and annotate nothing.\n return isSelectionExpanded(snapshot)\n },\n actions: [\n ({event}) => [\n // Unconditional removes: removing an annotation that isn't\n // active is a harmless no-op, while checking activity up\n // front invites the guard-versus-operation disagreement that\n // made `preventOverlappingAnnotations` recurse.\n ...mutuallyExclusive.map((annotation) =>\n raise({\n type: 'annotation.remove',\n annotation: {name: annotation},\n }),\n ),\n // `execute` (not `forward`) is deliberate: it skips the Core\n // Behavior that makes same-type annotations mutually\n // exclusive, so the configured list fully replaces the\n // default. An empty list therefore allows same-type overlap.\n execute(event),\n ],\n ],\n }),\n })\n }, [editor, props.schemaType.name, props.schemaType.mutuallyExclusive])\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {defineBehavior, effect, raise} from '@portabletext/editor/behaviors'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport {useMutuallyExclusiveAnnotation} from './use-mutually-exclusive-annotation'\nimport type {ToolbarAnnotationSchemaType} from './use-toolbar-schema'\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarAnnotationSchemaType},\n {type: 'set active'} | {type: 'set inactive'}\n>(({input, sendBack}) => {\n // Send back the initial state\n if (\n selectors.isActiveAnnotation(input.schemaType.name)(\n input.editor.getSnapshot(),\n )\n ) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (selectors.isActiveAnnotation(input.schemaType.name)(snapshot)) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst keyboardShortcutRemove = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarAnnotationSchemaType}\n>(({input}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n raise({\n type: 'annotation.remove',\n annotation: {\n name: input.schemaType.name,\n },\n }),\n effect(() => {\n input.editor.send({type: 'focus'})\n }),\n ],\n ],\n }),\n })\n})\n\nconst keyboardShortcutShowInsertDialog = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarAnnotationSchemaType},\n {type: 'open dialog'}\n>(({input, sendBack}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n effect(() => {\n sendBack({type: 'open dialog'})\n }),\n ],\n ],\n }),\n })\n})\n\nconst annotationButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ToolbarAnnotationSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ToolbarAnnotationSchemaType\n },\n events: {} as\n | AnnotationButtonEvent\n | DisableListenerEvent\n | {type: 'set active'}\n | {type: 'set inactive'},\n },\n actions: {\n 'add annotation': ({context, event}) => {\n if (event.type !== 'add') {\n return\n }\n\n context.editor.send({\n type: 'annotation.add',\n annotation: {\n name: context.schemaType.name,\n value: event.annotation.value,\n },\n })\n context.editor.send({type: 'focus'})\n },\n 'remove annotation': ({context}) => {\n context.editor.send({\n type: 'annotation.remove',\n annotation: {\n name: context.schemaType.name,\n },\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'active listener': activeListener,\n 'disable listener': disableListener,\n 'keyboard shortcut.remove': keyboardShortcutRemove,\n 'keyboard shortcut.show insert dialog': keyboardShortcutShowInsertDialog,\n },\n}).createMachine({\n id: 'annotation button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n {\n src: 'disable listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'enable': {\n target: '#annotation button.enabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'enable': {\n target: '#annotation button.enabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n enabled: {\n initial: 'inactive',\n states: {\n inactive: {\n initial: 'idle',\n on: {\n 'disable': {\n target: '#annotation button.disabled.inactive',\n },\n 'set active': {\n target: '#annotation button.enabled.active',\n },\n 'add': {\n actions: 'add annotation',\n },\n },\n states: {\n 'idle': {\n invoke: {\n src: 'keyboard shortcut.show insert dialog',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n on: {\n 'open dialog': {\n target: 'showing dialog',\n },\n },\n },\n 'showing dialog': {\n on: {\n 'close dialog': {\n target: 'idle',\n },\n },\n },\n },\n },\n active: {\n invoke: {\n src: 'keyboard shortcut.remove',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n on: {\n 'set inactive': {\n target: '#annotation button.enabled.inactive',\n },\n 'disable': {\n target: '#annotation button.disabled.active',\n },\n 'remove': {\n actions: 'remove annotation',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type AnnotationButtonEvent =\n | {type: 'close dialog'}\n | {type: 'open dialog'}\n | {\n type: 'add'\n annotation: {\n value: Record<string, unknown>\n }\n }\n | {type: 'remove'}\n\n/**\n * @beta\n */\nexport type AnnotationButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {disabled: 'inactive'}\n | {disabled: 'active'}\n | {enabled: 'inactive'}\n | {enabled: {inactive: 'idle'}}\n | {enabled: {inactive: 'showing dialog'}}\n | {enabled: 'active'},\n ) => boolean\n }\n send: (event: AnnotationButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcut and available events for an annotation\n * button.\n *\n * Note: This hook assumes that the button triggers a dialog for inputting\n * the annotation value.\n */\nexport function useAnnotationButton(props: {\n schemaType: ToolbarAnnotationSchemaType\n}): AnnotationButton {\n const editor = useEditor()\n const [snapshot, send] = useActor(annotationButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n useMutuallyExclusiveAnnotation(props)\n\n return {\n snapshot: {\n matches: (state) => snapshot.matches(state),\n },\n send,\n }\n}\n","import {\n useEditor,\n type AnnotationPath,\n type AnnotationSchemaType,\n type Editor,\n type PortableTextObject,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport * as React from 'react'\nimport type {RefObject} from 'react'\nimport {assign, fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarAnnotationSchemaType} from './use-toolbar-schema'\n\ntype ActiveContext = {\n annotations: Array<{\n value: PortableTextObject\n schemaType: ToolbarAnnotationSchemaType\n at: AnnotationPath\n }>\n elementRef: RefObject<Element | null>\n}\n\ntype ActiveListenerEvent =\n | ({\n type: 'set active'\n } & ActiveContext)\n | {\n type: 'set inactive'\n }\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>},\n ActiveListenerEvent\n>(({input, sendBack}) => {\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n const activeAnnotations = selectors.getActiveAnnotations(snapshot)\n const focusBlock = selectors.getFocusBlock(snapshot)\n\n if (activeAnnotations.length === 0 || !focusBlock) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const selectedChildren = input.editor.dom.getChildNodes(snapshot)\n const firstSelectedChild = selectedChildren.at(0)\n\n if (!firstSelectedChild || !(firstSelectedChild instanceof Element)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const elementRef = React.createRef<Element>()\n elementRef.current = firstSelectedChild\n\n sendBack({\n type: 'set active',\n annotations: activeAnnotations.flatMap((annotation) => {\n const schemaType = input.schemaTypes.find(\n (schemaType) => schemaType.name === annotation._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n return {\n value: annotation,\n schemaType,\n at: [...focusBlock.path, 'markDefs', {_key: annotation._key}],\n }\n }),\n elementRef,\n })\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst annotationPopoverMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>\n } & ActiveContext,\n input: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>\n },\n events: {} as\n | DisableListenerEvent\n | ActiveListenerEvent\n | AnnotationPopoverEvent,\n },\n actions: {\n reset: assign({\n annotations: [],\n elementRef: React.createRef<Element>(),\n }),\n remove: ({context, event}) => {\n if (event.type !== 'remove') {\n return\n }\n\n context.editor.send({\n type: 'annotation.remove',\n annotation: {\n name: event.schemaType.name,\n },\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'annotation popover',\n context: ({input}) => ({\n editor: input.editor,\n schemaTypes: input.schemaTypes,\n annotations: [],\n elementRef: React.createRef<Element>(),\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n actions: assign({\n annotations: ({event}) => event.annotations,\n elementRef: ({event}) => event.elementRef,\n }),\n target: 'active',\n },\n 'enable': {\n target: '#annotation popover.enabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'enable': {\n target: '#annotation popover.enabled.active',\n },\n },\n },\n },\n },\n enabled: {\n invoke: [\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaTypes: context.schemaTypes,\n }),\n },\n ],\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n target: 'active',\n actions: assign({\n annotations: ({event}) => event.annotations,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'disable': {\n target: '#annotation popover.disabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'disable': {\n target: '#annotation popover.disabled.active',\n },\n 'set active': {\n actions: assign({\n annotations: ({event}) => event.annotations,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'edit': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'annotation.set',\n at: event.at,\n props: event.props,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'remove': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'annotation.remove',\n annotation: {\n name: event.schemaType.name,\n },\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'close': {\n actions: ({context}) => {\n context.editor.send({type: 'focus'})\n },\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type AnnotationPopoverEvent =\n | {\n type: 'remove'\n schemaType: AnnotationSchemaType\n }\n | {\n type: 'edit'\n at: AnnotationPath\n props: {[key: string]: unknown}\n }\n | {\n type: 'close'\n }\n\n/**\n * @beta\n */\nexport type AnnotationPopover = {\n snapshot: {\n context: ActiveContext\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {\n enabled: 'inactive' | 'active'\n },\n ) => boolean\n }\n send: (event: AnnotationPopoverEvent) => void\n}\n\n/**\n * @beta\n * Manages the state and available events for an annotation popover.\n */\nexport function useAnnotationPopover(props: {\n schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>\n}): AnnotationPopover {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(annotationPopoverMachine, {\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n })\n\n return {\n snapshot: {\n context: {\n annotations: actorSnapshot.context.annotations,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {\n defineBehavior,\n effect,\n type InsertPlacement,\n} from '@portabletext/editor/behaviors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarBlockObjectSchemaType} from './use-toolbar-schema'\n\nconst keyboardShortcutListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarBlockObjectSchemaType},\n BlockObjectButtonEvent\n>(({input, sendBack}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n effect(() => {\n sendBack({type: 'open dialog'})\n }),\n ],\n ],\n }),\n })\n})\n\nconst blockObjectButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ToolbarBlockObjectSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ToolbarBlockObjectSchemaType\n },\n events: {} as DisableListenerEvent | BlockObjectButtonEvent,\n },\n actions: {\n insert: ({context, event}) => {\n if (event.type !== 'insert') {\n return\n }\n\n context.editor.send({\n type: 'insert.block object',\n blockObject: {\n name: context.schemaType.name,\n value: event.value,\n },\n placement: event.placement ?? 'auto',\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'keyboard shortcut listener': keyboardShortcutListener,\n },\n}).createMachine({\n id: 'block object button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n on: {\n disable: {\n target: 'disabled',\n },\n },\n initial: 'idle',\n states: {\n 'idle': {\n invoke: [\n {\n src: 'keyboard shortcut listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n on: {\n 'open dialog': {\n target: 'showing dialog',\n },\n },\n },\n 'showing dialog': {\n on: {\n 'close dialog': {\n target: 'idle',\n },\n 'insert': {\n actions: ['insert'],\n target: 'idle',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type BlockObjectButtonEvent =\n | {\n type: 'close dialog'\n }\n | {\n type: 'open dialog'\n }\n | {\n type: 'insert'\n value: {[key: string]: unknown}\n placement: InsertPlacement | undefined\n }\n\n/**\n * @beta\n */\nexport type BlockObjectButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {enabled: 'idle'}\n | {enabled: 'showing dialog'},\n ) => boolean\n }\n send: (event: BlockObjectButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcut and available events for a block\n * object button.\n *\n * Note: This hook assumes that the button triggers a dialog for inputting\n * the block object value.\n */\nexport function useBlockObjectButton(props: {\n schemaType: ToolbarBlockObjectSchemaType\n}): BlockObjectButton {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(blockObjectButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {\n useEditor,\n type BlockPath,\n type Editor,\n type PortableTextObject,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport * as React from 'react'\nimport type {RefObject} from 'react'\nimport {assign, fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarBlockObjectSchemaType} from './use-toolbar-schema'\n\ntype ActiveContext = {\n blockObjects: Array<{\n value: PortableTextObject\n schemaType: ToolbarBlockObjectSchemaType\n at: BlockPath\n }>\n elementRef: RefObject<Element | null>\n}\n\ntype ActiveListenerEvent =\n | ({\n type: 'set active'\n } & ActiveContext)\n | {\n type: 'set inactive'\n }\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>},\n ActiveListenerEvent\n>(({input, sendBack}) => {\n return input.editor.on(\n 'selection',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (!selectors.isSelectionCollapsed(snapshot)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const focusBlockObject = selectors.getFocusBlockObject(snapshot)\n\n if (!focusBlockObject) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const schemaType = input.schemaTypes.find(\n (schemaType) => schemaType.name === focusBlockObject.node._type,\n )\n\n if (!schemaType) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const selectedNodes = input.editor.dom.getBlockNodes(snapshot)\n const firstSelectedNode = selectedNodes.at(0)\n\n if (!firstSelectedNode || !(firstSelectedNode instanceof Element)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const elementRef = React.createRef<Element>()\n elementRef.current = firstSelectedNode\n\n sendBack({\n type: 'set active',\n blockObjects: [\n {\n value: focusBlockObject.node,\n schemaType,\n at: focusBlockObject.path,\n },\n ],\n elementRef,\n })\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst blockObjectPopoverMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>\n } & ActiveContext,\n input: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>\n },\n events: {} as\n | DisableListenerEvent\n | ActiveListenerEvent\n | BlockObjectPopoverEvent,\n },\n actions: {\n reset: assign({\n blockObjects: [],\n elementRef: React.createRef<Element>(),\n }),\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'block object popover',\n context: ({input}) => ({\n editor: input.editor,\n schemaTypes: input.schemaTypes,\n blockObjects: [],\n elementRef: React.createRef<Element>(),\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaTypes: context.schemaTypes,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n actions: assign({\n blockObjects: ({event}) => event.blockObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n target: 'active',\n },\n 'enable': {\n target: '#block object popover.enabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'enable': {\n target: '#block object popover.enabled.active',\n },\n },\n },\n },\n },\n enabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n target: 'active',\n actions: assign({\n blockObjects: ({event}) => event.blockObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'disable': {\n target: '#block object popover.disabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'disable': {\n target: '#block object popover.disabled.active',\n },\n 'set active': {\n actions: assign({\n blockObjects: ({event}) => event.blockObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'edit': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'block.set',\n at: event.at,\n props: event.props,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'remove': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'delete.block',\n at: event.at,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'close': {\n actions: ({context}) => {\n context.editor.send({type: 'focus'})\n },\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type BlockObjectPopoverEvent =\n | {\n type: 'remove'\n at: BlockPath\n }\n | {\n type: 'edit'\n at: BlockPath\n props: {[key: string]: unknown}\n }\n | {\n type: 'close'\n }\n\n/**\n * @beta\n */\nexport type BlockObjectPopover = {\n snapshot: {\n context: ActiveContext\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {\n enabled: 'inactive' | 'active'\n },\n ) => boolean\n }\n send: (event: BlockObjectPopoverEvent) => void\n}\n\n/**\n * @beta\n * Manages the state and available events for a block object popover.\n */\nexport function useBlockObjectPopover(props: {\n schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>\n}): BlockObjectPopover {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(blockObjectPopoverMachine, {\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n })\n\n return {\n snapshot: {\n context: {\n blockObjects: actorSnapshot.context.blockObjects,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {defineBehavior, raise} from '@portabletext/editor/behaviors'\nimport {useActorRef} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarDecoratorSchemaType} from './use-toolbar-schema'\n\nconst keyboardShortcutListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarDecoratorSchemaType}\n>(({input}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n raise({\n type: 'decorator.toggle',\n decorator: input.schemaType.name,\n }),\n ],\n ],\n }),\n })\n})\n\nconst decoratorKeyboardShortcutMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ToolbarDecoratorSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ToolbarDecoratorSchemaType\n },\n events: {} as DisableListenerEvent | {type: 'decorator.toggle'},\n },\n actors: {\n 'disable listener': disableListener,\n 'keyboard shortcut listener': keyboardShortcutListener,\n },\n}).createMachine({\n id: 'decorator keyboard shortcut',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n invoke: {\n src: 'keyboard shortcut listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n on: {\n disable: {\n target: 'disabled',\n },\n },\n },\n },\n})\n\nexport function useDecoratorKeyboardShortcut(props: {\n schemaType: ToolbarDecoratorSchemaType\n}) {\n const editor = useEditor()\n useActorRef(decoratorKeyboardShortcutMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n}\n","import {useEditor} from '@portabletext/editor'\nimport {defineBehavior, forward, raise} from '@portabletext/editor/behaviors'\nimport {useEffect} from 'react'\nimport type {ToolbarDecoratorSchemaType} from './use-toolbar-schema'\n\nexport function useMutuallyExclusiveDecorator(props: {\n schemaType: ToolbarDecoratorSchemaType\n}) {\n const editor = useEditor()\n\n useEffect(() => {\n const mutuallyExclusive = props.schemaType.mutuallyExclusive\n\n if (!mutuallyExclusive) {\n return\n }\n\n return editor.registerBehavior({\n behavior: defineBehavior({\n on: 'decorator.add',\n guard: ({event}) => event.decorator === props.schemaType.name,\n actions: [\n ({event}) => [\n forward(event),\n ...mutuallyExclusive.map((decorator) =>\n raise({\n type: 'decorator.remove',\n decorator,\n }),\n ),\n ],\n ],\n }),\n })\n }, [editor, props.schemaType.name, props.schemaType.mutuallyExclusive])\n}\n","import {\n useEditor,\n type DecoratorSchemaType,\n type Editor,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport {useDecoratorKeyboardShortcut} from './use-decorator-keyboard-shortcut'\nimport {useMutuallyExclusiveDecorator} from './use-mutually-exclusive-decorator'\nimport type {ToolbarDecoratorSchemaType} from './use-toolbar-schema'\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: DecoratorSchemaType},\n {type: 'set active'} | {type: 'set inactive'}\n>(({input, sendBack}) => {\n // Send back the initial state\n if (\n selectors.isActiveDecorator(input.schemaType.name)(\n input.editor.getSnapshot(),\n )\n ) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (selectors.isActiveDecorator(input.schemaType.name)(snapshot)) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst decoratorButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: DecoratorSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: DecoratorSchemaType\n },\n events: {} as DisableListenerEvent | DecoratorButtonEvent,\n },\n actions: {\n toggle: ({context, event}) => {\n if (event.type !== 'toggle') {\n return\n }\n\n context.editor.send({\n type: 'decorator.toggle',\n decorator: context.schemaType.name,\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'decorator button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'enable': {\n target: '#decorator button.enabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'enable': {\n target: '#decorator button.enabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n enabled: {\n on: {\n toggle: {\n actions: ['toggle'],\n },\n },\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'disable': {\n target: '#decorator button.disabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'disable': {\n target: '#decorator button.disabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type DecoratorButtonEvent = {\n type: 'toggle'\n}\n\n/**\n * @beta\n */\nexport type DecoratorButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {disabled: 'inactive'}\n | {disabled: 'active'}\n | {enabled: 'inactive'}\n | {enabled: 'active'},\n ) => boolean\n }\n send: (event: DecoratorButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcuts and available events for a decorator\n * button and sets up mutually exclusive decorator behaviors.\n */\nexport function useDecoratorButton(props: {\n schemaType: ToolbarDecoratorSchemaType\n}): DecoratorButton {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(decoratorButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n useDecoratorKeyboardShortcut(props)\n useMutuallyExclusiveDecorator(props)\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {useActor} from '@xstate/react'\nimport {setup} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\n\nconst historyButtonsMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n },\n input: {} as {\n editor: Editor\n },\n events: {} as DisableListenerEvent | HistoryButtonsEvent,\n },\n actors: {\n 'disable listener': disableListener,\n },\n}).createMachine({\n id: 'history buttons',\n context: ({input}) => ({\n editor: input.editor,\n }),\n invoke: {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n on: {\n 'disable': {\n target: 'disabled',\n },\n 'history.undo': {\n actions: ({context}) => {\n context.editor.send({type: 'history.undo'})\n context.editor.send({type: 'focus'})\n },\n },\n 'history.redo': {\n actions: ({context}) => {\n context.editor.send({type: 'history.redo'})\n context.editor.send({type: 'focus'})\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type HistoryButtonsEvent =\n | {\n type: 'history.undo'\n }\n | {\n type: 'history.redo'\n }\n\n/**\n * @beta\n */\nexport type HistoryButtons = {\n snapshot: {\n matches: (state: 'disabled' | 'enabled') => boolean\n }\n send: (event: HistoryButtonsEvent) => void\n}\n\n/**\n * @beta\n */\nexport function useHistoryButtons(): HistoryButtons {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(historyButtonsMachine, {\n input: {\n editor,\n },\n })\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {defineBehavior, effect} from '@portabletext/editor/behaviors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarInlineObjectSchemaType} from './use-toolbar-schema'\n\nconst keyboardShortcutListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarInlineObjectSchemaType},\n InlineObjectButtonEvent\n>(({input, sendBack}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n effect(() => {\n sendBack({type: 'open dialog'})\n }),\n ],\n ],\n }),\n })\n})\n\nconst inlineObjectButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ToolbarInlineObjectSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ToolbarInlineObjectSchemaType\n },\n events: {} as DisableListenerEvent | InlineObjectButtonEvent,\n },\n actions: {\n insert: ({context, event}) => {\n if (event.type !== 'insert') {\n return\n }\n\n context.editor.send({\n type: 'insert.inline object',\n inlineObject: {\n name: context.schemaType.name,\n value: event.value,\n },\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'keyboard shortcut listener': keyboardShortcutListener,\n },\n}).createMachine({\n id: 'inline object button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n on: {\n disable: {\n target: 'disabled',\n },\n },\n initial: 'idle',\n states: {\n 'idle': {\n invoke: [\n {\n src: 'keyboard shortcut listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n on: {\n 'open dialog': {\n target: 'showing dialog',\n },\n },\n },\n 'showing dialog': {\n on: {\n 'close dialog': {\n target: 'idle',\n },\n 'insert': {\n actions: ['insert'],\n target: 'idle',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type InlineObjectButtonEvent =\n | {\n type: 'close dialog'\n }\n | {\n type: 'open dialog'\n }\n | {\n type: 'insert'\n value: {[key: string]: unknown}\n }\n\n/**\n * @beta\n */\nexport type InlineObjectButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {enabled: 'idle'}\n | {enabled: 'showing dialog'},\n ) => boolean\n }\n send: (event: InlineObjectButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcut and available events for an inline\n * object button.\n *\n * Note: This hook assumes that the button triggers a dialog for inputting\n * the inline object value.\n */\nexport function useInlineObjectButton(props: {\n schemaType: ToolbarInlineObjectSchemaType\n}): InlineObjectButton {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(inlineObjectButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {\n useEditor,\n type ChildPath,\n type Editor,\n type PortableTextObject,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport * as React from 'react'\nimport type {RefObject} from 'react'\nimport {assign, fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarInlineObjectSchemaType} from './use-toolbar-schema'\n\ntype ActiveContext = {\n inlineObjects: Array<{\n value: PortableTextObject\n schemaType: ToolbarInlineObjectSchemaType\n at: ChildPath\n }>\n elementRef: RefObject<Element | null>\n}\n\ntype ActiveListenerEvent =\n | ({\n type: 'set active'\n } & ActiveContext)\n | {\n type: 'set inactive'\n }\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>},\n ActiveListenerEvent\n>(({input, sendBack}) => {\n return input.editor.on(\n 'selection',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (!selectors.isSelectionCollapsed(snapshot)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const focusInlineObject = selectors.getFocusInlineObject(snapshot)\n\n if (!focusInlineObject) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const schemaType = input.schemaTypes.find(\n (schemaType) => schemaType.name === focusInlineObject.node._type,\n )\n\n if (!schemaType) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const selectedNodes = input.editor.dom.getChildNodes(snapshot)\n const firstSelectedNode = selectedNodes.at(0)\n\n if (!firstSelectedNode || !(firstSelectedNode instanceof Element)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const elementRef = React.createRef<Element>()\n elementRef.current = firstSelectedNode\n\n sendBack({\n type: 'set active',\n inlineObjects: [\n {\n value: focusInlineObject.node,\n schemaType,\n at: focusInlineObject.path,\n },\n ],\n elementRef,\n })\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst inlineObjectPopoverMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>\n } & ActiveContext,\n input: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>\n },\n events: {} as\n | DisableListenerEvent\n | ActiveListenerEvent\n | InlineObjectPopoverEvent,\n },\n actions: {\n reset: assign({\n inlineObjects: [],\n elementRef: React.createRef<Element>(),\n }),\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'inline object popover',\n context: ({input}) => ({\n editor: input.editor,\n schemaTypes: input.schemaTypes,\n inlineObjects: [],\n elementRef: React.createRef<Element>(),\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaTypes: context.schemaTypes,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n actions: assign({\n inlineObjects: ({event}) => event.inlineObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n target: 'active',\n },\n 'enable': {\n target: '#inline object popover.enabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'enable': {\n target: '#inline object popover.enabled.active',\n },\n },\n },\n },\n },\n enabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n target: 'active',\n actions: assign({\n inlineObjects: ({event}) => event.inlineObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'disable': {\n target: '#inline object popover.disabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'disable': {\n target: '#inline object popover.disabled.active',\n },\n 'set active': {\n actions: assign({\n inlineObjects: ({event}) => event.inlineObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'edit': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'child.set',\n at: event.at,\n props: event.props,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'remove': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'delete.child',\n at: event.at,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'close': {\n actions: ({context}) => {\n context.editor.send({type: 'focus'})\n },\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type InlineObjectPopoverEvent =\n | {\n type: 'remove'\n at: ChildPath\n }\n | {\n type: 'edit'\n at: ChildPath\n props: {[key: string]: unknown}\n }\n | {\n type: 'close'\n }\n\n/**\n * @beta\n */\nexport type InlineObjectPopover = {\n snapshot: {\n context: ActiveContext\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {\n enabled: 'inactive' | 'active'\n },\n ) => boolean\n }\n send: (event: InlineObjectPopoverEvent) => void\n}\n\n/**\n * @beta\n * Manages the state and available events for an inline object popover.\n */\nexport function useInlineObjectPopover(props: {\n schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>\n}): InlineObjectPopover {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(inlineObjectPopoverMachine, {\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n })\n\n return {\n snapshot: {\n context: {\n inlineObjects: actorSnapshot.context.inlineObjects,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor, type ListSchemaType} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarListSchemaType} from './use-toolbar-schema'\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ListSchemaType},\n {type: 'set active'} | {type: 'set inactive'}\n>(({input, sendBack}) => {\n // Send back the initial state\n if (\n selectors.isActiveListItem(input.schemaType.name)(\n input.editor.getSnapshot(),\n )\n ) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (selectors.isActiveListItem(input.schemaType.name)(snapshot)) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst listButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ListSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ListSchemaType\n },\n events: {} as DisableListenerEvent | ListButtonEvent,\n },\n actions: {\n toggle: ({context, event}) => {\n if (event.type !== 'toggle') {\n return\n }\n\n context.editor.send({\n type: 'list item.toggle',\n listItem: context.schemaType.name,\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'list button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'enable': {\n target: '#list button.enabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'enable': {\n target: '#list button.enabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n enabled: {\n on: {\n toggle: {\n actions: ['toggle'],\n },\n },\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'disable': {\n target: '#list button.disabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'disable': {\n target: '#list button.disabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type ListButtonEvent = {\n type: 'toggle'\n}\n\n/**\n * @beta\n */\nexport type ListButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {disabled: 'inactive'}\n | {disabled: 'active'}\n | {enabled: 'inactive'}\n | {enabled: 'active'},\n ) => boolean\n }\n send: (event: ListButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcuts and available events for a list button.\n */\nexport function useListButton(props: {\n schemaType: ToolbarListSchemaType\n}): ListButton {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(listButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {defineBehavior, raise} from '@portabletext/editor/behaviors'\nimport {useActorRef} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarStyleSchemaType} from './use-toolbar-schema'\n\nconst styleKeyboardShortcutsListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>}\n>(({input}) => {\n const unregisterBehaviors = input.schemaTypes.flatMap((schemaType) => {\n const shortcut = schemaType.shortcut\n\n if (!shortcut) {\n return []\n }\n\n return [\n input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [raise({type: 'style.toggle', style: schemaType.name})],\n ],\n }),\n }),\n ]\n })\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n})\n\nconst styleKeyboardShortcutsMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>\n },\n input: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>\n },\n events: {} as DisableListenerEvent | {type: 'style.toggle'},\n },\n actors: {\n 'disable listener': disableListener,\n 'style keyboard shortcuts listener': styleKeyboardShortcutsListener,\n },\n}).createMachine({\n id: 'style keyboard shortcuts',\n context: ({input}) => ({\n editor: input.editor,\n schemaTypes: input.schemaTypes,\n }),\n invoke: {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n invoke: {\n src: 'style keyboard shortcuts listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaTypes: context.schemaTypes,\n }),\n },\n on: {\n disable: {\n target: 'disabled',\n },\n },\n },\n },\n})\n\n/**\n * @beta\n * Registers keyboard shortcuts for a set of style schema types.\n */\nexport function useStyleKeyboardShortcuts(props: {\n schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>\n}) {\n const editor = useEditor()\n useActorRef(styleKeyboardShortcutsMachine, {\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n })\n}\n","import {\n useEditor,\n type Editor,\n type StyleSchemaType,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport {assign, fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport {useStyleKeyboardShortcuts} from './use-style-keyboard-shortcuts'\nimport type {ToolbarStyleSchemaType} from './use-toolbar-schema'\n\ntype ActiveStyleListenerEvent = {\n type: 'set active style'\n style: StyleSchemaType['name'] | undefined\n}\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor},\n ActiveStyleListenerEvent\n>(({input, sendBack}) => {\n // Send back the initial state\n const activeStyle = selectors.getActiveStyle(input.editor.getSnapshot())\n sendBack({type: 'set active style', style: activeStyle})\n\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n const activeStyle = selectors.getActiveStyle(snapshot)\n\n sendBack({type: 'set active style', style: activeStyle})\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst styleSelectorMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n activeStyle: StyleSchemaType['name'] | undefined\n },\n input: {} as {\n editor: Editor\n },\n events: {} as\n | StyleSelectorEvent\n | DisableListenerEvent\n | ActiveStyleListenerEvent,\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'style selector',\n context: ({input}) => ({\n editor: input.editor,\n activeStyle: undefined,\n }),\n invoke: [\n {\n src: 'disable listener',\n input: ({context}) => ({\n editor: context.editor,\n }),\n },\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n }),\n },\n ],\n on: {\n 'set active style': {\n guard: ({context, event}) => context.activeStyle !== event.style,\n actions: assign({\n activeStyle: ({event}) => event.style,\n }),\n },\n },\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n on: {\n disable: {\n target: 'disabled',\n },\n toggle: {\n actions: [\n ({context, event}) => {\n context.editor.send({type: 'style.toggle', style: event.style})\n context.editor.send({type: 'focus'})\n },\n ],\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type StyleSelectorEvent = {\n type: 'toggle'\n style: StyleSchemaType['name']\n}\n\n/**\n * @beta\n */\nexport type StyleSelector = {\n snapshot: {\n matches: (state: 'disabled' | 'enabled') => boolean\n context: {\n activeStyle: StyleSchemaType['name'] | undefined\n }\n }\n send: (event: StyleSelectorEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcuts and available events for a style\n * selector.\n */\nexport function useStyleSelector(props: {\n schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>\n}): StyleSelector {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(styleSelectorMachine, {\n input: {\n editor,\n },\n })\n useStyleKeyboardShortcuts(props)\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n context: {\n activeStyle: actorSnapshot.context.activeStyle,\n },\n },\n send,\n }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AC;GACrC,CAAC,EAEL;EACF,EACF;CACF;AACF,CAAC;;;;;;AA4BD,SAAOuC,iBAAAC,OAAA;CAAA,IAAAC,IAAAC,EAAA,EAAA,GAGLvC,SAAejB,UAAU,GAACyD;CAAA,AAAAF,EAAA,OAAAtC,SAKzBwC,KAAAF,EAAA,MAJ4DE,KAAA,EAAAvC,OACpD,EAAAD,OAEP,EACF,GAACsC,EAAA,KAAAtC,QAAAsC,EAAA,KAAAE;CAJD,IAAA,CAAAC,eAAAT,QAA8B7C,SAASuB,sBAAsB8B,EAI5D;CACD9C,0BAA0B2C,KAAK;CAAC,IAAAK;CAAA,AAAAJ,EAAA,OAAAG,gBAIoBC,KAAAJ,EAAA,MAAvCI,MAAAP,UAAWM,cAAaP,QAASC,KAAK,GAACG,EAAA,KAAAG,eAAAH,EAAA,KAAAI;CAAA,IAAAC;CAAA,AAAAL,EAAA,OAAAG,cAAA7B,QAAAT,cAG/CwC,KAAAL,EAAA,MAFQK,KAAA,EAAAxC,aACMsC,cAAa7B,QAAQT,YACpC,GAACmC,EAAA,KAAAG,cAAA7B,QAAAT,aAAAmC,EAAA,KAAAK;CAAA,IAAAC;CAAA,AAAAN,EAAA,OAAAI,MAAAJ,EAAA,OAAAK,MAJOC,KAAA;EAAAV,SACCQ;EAAuC9B,SACvC+B;CAGX,GAACL,EAAA,KAAAI,IAAAJ,EAAA,KAAAK,IAAAL,EAAA,KAAAM,MAAAA,KAAAN,EAAA;CAAA,IAAAO;CAEF,OAFEP,EAAA,OAAAN,QAAAM,EAAA,QAAAM,MANIC,KAAA;EAAAtC,UACKqC;EAKTZ;CAEH,GAACM,EAAA,KAAAN,MAAAM,EAAA,MAAAM,IAAAN,EAAA,MAAAO,MAAAA,KAAAP,EAAA,KARMO;AAQN"}
1
+ {"version":3,"file":"index.js","names":["(snapshot) =>\n getUnionSchema(snapshot.context.schema, snapshot.context.containers)","union.decorators.map(\n (decorator) => props.extendDecorator?.(decorator) ?? decorator,\n )","props.extendDecorator","decorators","(decorator) => props.extendDecorator?.(decorator) ?? decorator","union.annotations.map(\n (annotation) => props.extendAnnotation?.(annotation) ?? annotation,\n )","props.extendAnnotation","annotations","(annotation) => props.extendAnnotation?.(annotation) ?? annotation","union.lists.map((list) => props.extendList?.(list) ?? list)","props.extendList","lists","(list) => props.extendList?.(list) ?? list","union.blockObjects.map(\n (blockObject) => props.extendBlockObject?.(blockObject) ?? blockObject,\n )","props.extendBlockObject","blockObjects","(blockObject) => props.extendBlockObject?.(blockObject) ?? blockObject","union.inlineObjects.map(\n (inlineObject) =>\n props.extendInlineObject?.(inlineObject) ?? inlineObject,\n )","props.extendInlineObject","inlineObjects","(inlineObject) =>\n props.extendInlineObject?.(inlineObject) ?? inlineObject","union.styles.map((style) => props.extendStyle?.(style) ?? style)","props.extendStyle","styles","(style) => props.extendStyle?.(style) ?? style","{\n decorators: union.decorators.map(\n (decorator) => props.extendDecorator?.(decorator) ?? decorator,\n ),\n annotations: union.annotations.map(\n (annotation) => props.extendAnnotation?.(annotation) ?? annotation,\n ),\n lists: union.lists.map((list) => props.extendList?.(list) ?? list),\n blockObjects: union.blockObjects.map(\n (blockObject) => props.extendBlockObject?.(blockObject) ?? blockObject,\n ),\n inlineObjects: union.inlineObjects.map(\n (inlineObject) =>\n props.extendInlineObject?.(inlineObject) ?? inlineObject,\n ),\n styles: union.styles.map((style) => props.extendStyle?.(style) ?? style),\n }","() => {\n const mutuallyExclusive = props.schemaType.mutuallyExclusive\n\n if (!mutuallyExclusive) {\n // Absent config keeps the Core Behavior default (self-exclusive).\n // An empty array is deliberate \"exclusive with nothing\" config and\n // must fall through to register; see `mutuallyExclusive`'s docs.\n return\n }\n\n return editor.registerBehavior({\n behavior: defineBehavior({\n on: 'annotation.add',\n guard: ({snapshot, event}) => {\n if (event.annotation.name !== props.schemaType.name) {\n return false\n }\n\n // Declining collapsed selections lets the Core Behavior expand\n // them to the caret word and re-raise the add; the re-raised,\n // now-expanded add re-enters this chain and passes this guard.\n // Intercepting the collapsed add directly would `execute` past\n // that expansion and annotate nothing.\n return isSelectionExpanded(snapshot)\n },\n actions: [\n ({event}) => [\n // Unconditional removes: removing an annotation that isn't\n // active is a harmless no-op, while checking activity up\n // front invites the guard-versus-operation disagreement that\n // made `preventOverlappingAnnotations` recurse.\n ...mutuallyExclusive.map((annotation) =>\n raise({\n type: 'annotation.remove',\n annotation: {name: annotation},\n }),\n ),\n // `execute` (not `forward`) is deliberate: it skips the Core\n // Behavior that makes same-type annotations mutually\n // exclusive, so the configured list fully replaces the\n // default. An empty list therefore allows same-type overlap.\n execute(event),\n ],\n ],\n }),\n })\n }","[editor, props.schemaType.name, props.schemaType.mutuallyExclusive]","mutuallyExclusive","name","{snapshot, event}","{event}","(annotation) =>\n raise({\n type: 'annotation.remove',\n annotation: {name: annotation},\n })","event","{\n input: {\n editor,\n schemaType: props.schemaType,\n },\n }","schemaType","{\n matches: (state) => snapshot.matches(state),\n }","{\n snapshot: {\n matches: (state) => snapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n }","schemaTypes","{\n annotations: actorSnapshot.context.annotations,\n elementRef: actorSnapshot.context.elementRef,\n }","annotations","elementRef","(state) => actorSnapshot.matches(state)","{\n context: {\n annotations: actorSnapshot.context.annotations,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n }","{\n snapshot: {\n context: {\n annotations: actorSnapshot.context.annotations,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n schemaType: props.schemaType,\n },\n }","schemaType","{\n matches: (state) => actorSnapshot.matches(state),\n }","{\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n }","schemaTypes","{\n blockObjects: actorSnapshot.context.blockObjects,\n elementRef: actorSnapshot.context.elementRef,\n }","blockObjects","elementRef","(state) => actorSnapshot.matches(state)","{\n context: {\n blockObjects: actorSnapshot.context.blockObjects,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n }","{\n snapshot: {\n context: {\n blockObjects: actorSnapshot.context.blockObjects,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n schemaType: props.schemaType,\n },\n }","schemaType","() => {\n const mutuallyExclusive = props.schemaType.mutuallyExclusive\n\n if (!mutuallyExclusive) {\n return\n }\n\n return editor.registerBehavior({\n behavior: defineBehavior({\n on: 'decorator.add',\n guard: ({event}) => event.decorator === props.schemaType.name,\n actions: [\n ({event}) => [\n forward(event),\n ...mutuallyExclusive.map((decorator) =>\n raise({\n type: 'decorator.remove',\n decorator,\n }),\n ),\n ],\n ],\n }),\n })\n }","[editor, props.schemaType.name, props.schemaType.mutuallyExclusive]","mutuallyExclusive","name","{event}","event","(decorator) =>\n raise({\n type: 'decorator.remove',\n decorator,\n })","{\n input: {\n editor,\n schemaType: props.schemaType,\n },\n }","schemaType","{\n matches: (state) => actorSnapshot.matches(state),\n }","{\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n },\n }","{\n matches: (state) => actorSnapshot.matches(state),\n }","{\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n schemaType: props.schemaType,\n },\n }","schemaType","{\n matches: (state) => actorSnapshot.matches(state),\n }","{\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n }","schemaTypes","{\n inlineObjects: actorSnapshot.context.inlineObjects,\n elementRef: actorSnapshot.context.elementRef,\n }","elementRef","inlineObjects","(state) => actorSnapshot.matches(state)","{\n context: {\n inlineObjects: actorSnapshot.context.inlineObjects,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n }","{\n snapshot: {\n context: {\n inlineObjects: actorSnapshot.context.inlineObjects,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n schemaType: props.schemaType,\n },\n }","schemaType","{\n matches: (state) => actorSnapshot.matches(state),\n }","{\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }","{\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n }","schemaTypes","{\n input: {\n editor,\n },\n }","(state) => actorSnapshot.matches(state)","{\n activeStyle: actorSnapshot.context.activeStyle,\n }","activeStyle","{\n matches: (state) => actorSnapshot.matches(state),\n context: {\n activeStyle: actorSnapshot.context.activeStyle,\n },\n }","{\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n context: {\n activeStyle: actorSnapshot.context.activeStyle,\n },\n },\n send,\n }"],"sources":["../src/use-applicable-schema.ts","../src/use-toolbar-schema.ts","../src/disable-listener.ts","../src/use-mutually-exclusive-annotation.ts","../src/use-annotation-button.ts","../src/use-annotation-popover.ts","../src/use-block-object-button.ts","../src/use-block-object-popover.ts","../src/use-decorator-keyboard-shortcut.ts","../src/use-mutually-exclusive-decorator.ts","../src/use-decorator-button.ts","../src/use-history-buttons.ts","../src/use-inline-object-button.ts","../src/use-inline-object-popover.ts","../src/use-list-button.ts","../src/use-style-keyboard-shortcuts.ts","../src/use-style-selector.ts"],"sourcesContent":["import {useEditor, useEditorSelector} from '@portabletext/editor'\nimport {\n compareApplicableSchema,\n getApplicableSchema,\n type ApplicableSchema,\n} from '@portabletext/editor/selectors'\n\nexport type {ApplicableSchema}\n\n/**\n * @beta\n *\n * React hook that subscribes to {@link getApplicableSchema} for the active\n * editor and returns a stable reference across editor ticks while the\n * applicable set is unchanged.\n *\n * Pair with {@link useToolbarSchema} to render a static toolbar whose\n * buttons stay stable across selection moves and gate their enabled state\n * on whether the corresponding name is in the relevant set.\n */\nexport function useApplicableSchema(): ApplicableSchema {\n const editor = useEditor()\n return useEditorSelector(editor, getApplicableSchema, compareApplicableSchema)\n}\n","import {\n useEditor,\n useEditorSelector,\n type AnnotationDefinition,\n type AnnotationSchemaType,\n type BlockObjectSchemaType,\n type DecoratorDefinition,\n type DecoratorSchemaType,\n type EditorSchema,\n type InlineObjectSchemaType,\n type ListSchemaType,\n type StyleSchemaType,\n} from '@portabletext/editor'\nimport {getUnionSchema} from '@portabletext/editor/traversal'\nimport type {KeyboardShortcut} from '@portabletext/keyboard-shortcuts'\n\n/**\n * @beta\n */\nexport type ExtendDecoratorSchemaType = (\n decorator: DecoratorSchemaType,\n) => ToolbarDecoratorSchemaType\n\n/**\n * @beta\n */\nexport type ExtendAnnotationSchemaType = (\n annotation: AnnotationSchemaType,\n) => ToolbarAnnotationSchemaType\n\n/**\n * @beta\n */\nexport type ExtendListSchemaType = (\n list: ListSchemaType,\n) => ToolbarListSchemaType\n\n/**\n * @beta\n */\nexport type ExtendBlockObjectSchemaType = (\n blockObject: BlockObjectSchemaType,\n) => ToolbarBlockObjectSchemaType\n\n/**\n * @beta\n */\nexport type ExtendInlineObjectSchemaType = (\n inlineObject: InlineObjectSchemaType,\n) => ToolbarInlineObjectSchemaType\n\n/**\n * @beta\n */\nexport type ExtendStyleSchemaType = (\n style: StyleSchemaType,\n) => ToolbarStyleSchemaType\n\n/**\n * @beta\n *\n * Resolve the editor's full toolbar schema. Returns the union of every\n * decorator, annotation, list, style, block object and inline object declared\n * anywhere in the editor's schema graph that is reachable from a position\n * where text is edited - the root schema merged with the sub-schema of every\n * registered container whose field accepts text blocks. Useful for rendering\n * a static toolbar whose buttons stay stable across selection moves.\n *\n * Re-renders only when the schema graph or the extension callbacks change.\n * Pair with {@link useApplicableSchema} to determine which entries are\n * applicable at the current selection (which buttons should be enabled vs.\n * disabled).\n */\nexport function useToolbarSchema(props: {\n extendDecorator?: ExtendDecoratorSchemaType\n extendAnnotation?: ExtendAnnotationSchemaType\n extendList?: ExtendListSchemaType\n extendBlockObject?: ExtendBlockObjectSchemaType\n extendInlineObject?: ExtendInlineObjectSchemaType\n extendStyle?: ExtendStyleSchemaType\n}): ToolbarSchema {\n const editor = useEditor()\n const union = useEditorSelector(\n editor,\n (snapshot) =>\n getUnionSchema(snapshot.context.schema, snapshot.context.containers),\n compareSchemas,\n )\n\n return {\n decorators: union.decorators.map(\n (decorator) => props.extendDecorator?.(decorator) ?? decorator,\n ),\n annotations: union.annotations.map(\n (annotation) => props.extendAnnotation?.(annotation) ?? annotation,\n ),\n lists: union.lists.map((list) => props.extendList?.(list) ?? list),\n blockObjects: union.blockObjects.map(\n (blockObject) => props.extendBlockObject?.(blockObject) ?? blockObject,\n ),\n inlineObjects: union.inlineObjects.map(\n (inlineObject) =>\n props.extendInlineObject?.(inlineObject) ?? inlineObject,\n ),\n styles: union.styles.map((style) => props.extendStyle?.(style) ?? style),\n }\n}\n\n/**\n * @beta\n */\nexport type ToolbarSchema = {\n decorators: ReadonlyArray<ToolbarDecoratorSchemaType>\n annotations: ReadonlyArray<ToolbarAnnotationSchemaType>\n lists: ReadonlyArray<ToolbarListSchemaType>\n blockObjects: ReadonlyArray<ToolbarBlockObjectSchemaType>\n inlineObjects: ReadonlyArray<ToolbarInlineObjectSchemaType>\n styles: ReadonlyArray<ToolbarStyleSchemaType>\n}\n\n/**\n * @beta\n */\nexport type ToolbarDecoratorSchemaType = DecoratorSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n shortcut?: KeyboardShortcut\n mutuallyExclusive?: ReadonlyArray<DecoratorDefinition['name']>\n}\n\n/**\n * @beta\n */\nexport type ToolbarAnnotationSchemaType = AnnotationSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n defaultValues?: Record<string, unknown>\n shortcut?: KeyboardShortcut\n /**\n * The annotations this annotation cannot coexist with. The list\n * replaces the default rule that an annotation is mutually exclusive\n * with itself:\n *\n * - Absent: the default applies (adding the annotation removes\n * existing annotations of the same type in the selection).\n * - `[]`: exclusive with nothing, not even itself, so same-type\n * annotations may overlap.\n * - `['other']`: exclusive with exactly the listed annotations.\n * Include the annotation's own name to keep self-exclusivity.\n */\n mutuallyExclusive?: ReadonlyArray<AnnotationDefinition['name']>\n}\n\n/**\n * @beta\n */\nexport type ToolbarListSchemaType = ListSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n}\n\n/**\n * @beta\n */\nexport type ToolbarBlockObjectSchemaType = BlockObjectSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n defaultValues?: Record<string, unknown>\n shortcut?: KeyboardShortcut\n}\n\n/**\n * @beta\n */\nexport type ToolbarInlineObjectSchemaType = InlineObjectSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n defaultValues?: Record<string, unknown>\n shortcut?: KeyboardShortcut\n}\n\n/**\n * @beta\n */\nexport type ToolbarStyleSchemaType = StyleSchemaType & {\n icon?: React.ComponentType<{className?: string}>\n shortcut?: KeyboardShortcut\n}\n\nfunction compareSchemas(a: EditorSchema, b: EditorSchema) {\n if (a === b) {\n return true\n }\n return (\n compareNamed(a.decorators, b.decorators) &&\n compareNamed(a.annotations, b.annotations) &&\n compareNamed(a.lists, b.lists) &&\n compareNamed(a.styles, b.styles) &&\n compareNamed(a.blockObjects, b.blockObjects) &&\n compareNamed(a.inlineObjects, b.inlineObjects)\n )\n}\n\nfunction compareNamed(\n a: ReadonlyArray<{name: string}>,\n b: ReadonlyArray<{name: string}>,\n) {\n if (a === b) {\n return true\n }\n if (a.length !== b.length) {\n return false\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i]!.name !== b[i]!.name) {\n return false\n }\n }\n return true\n}\n","import type {Editor} from '@portabletext/editor'\nimport {fromCallback, type AnyEventObject} from 'xstate'\n\nexport type DisableListenerEvent = {type: 'enable'} | {type: 'disable'}\n\nexport const disableListener = fromCallback<\n AnyEventObject,\n {editor: Editor},\n DisableListenerEvent\n>(({input, sendBack}) => {\n // Send back the initial state\n if (input.editor.getSnapshot().context.readOnly) {\n sendBack({type: 'disable'})\n } else {\n sendBack({type: 'enable'})\n }\n\n return input.editor.on(\n '*',\n () => {\n if (input.editor.getSnapshot().context.readOnly) {\n sendBack({type: 'disable'})\n } else {\n sendBack({type: 'enable'})\n }\n },\n {batch: true},\n ).unsubscribe\n})\n","import {useEditor} from '@portabletext/editor'\nimport {defineBehavior, execute, raise} from '@portabletext/editor/behaviors'\nimport {isSelectionExpanded} from '@portabletext/editor/selectors'\nimport {useEffect} from 'react'\nimport type {ToolbarAnnotationSchemaType} from './use-toolbar-schema'\n\nexport function useMutuallyExclusiveAnnotation(props: {\n schemaType: ToolbarAnnotationSchemaType\n}) {\n const editor = useEditor()\n\n useEffect(() => {\n const mutuallyExclusive = props.schemaType.mutuallyExclusive\n\n if (!mutuallyExclusive) {\n // Absent config keeps the Core Behavior default (self-exclusive).\n // An empty array is deliberate \"exclusive with nothing\" config and\n // must fall through to register; see `mutuallyExclusive`'s docs.\n return\n }\n\n return editor.registerBehavior({\n behavior: defineBehavior({\n on: 'annotation.add',\n guard: ({snapshot, event}) => {\n if (event.annotation.name !== props.schemaType.name) {\n return false\n }\n\n // Declining collapsed selections lets the Core Behavior expand\n // them to the caret word and re-raise the add; the re-raised,\n // now-expanded add re-enters this chain and passes this guard.\n // Intercepting the collapsed add directly would `execute` past\n // that expansion and annotate nothing.\n return isSelectionExpanded(snapshot)\n },\n actions: [\n ({event}) => [\n // Unconditional removes: removing an annotation that isn't\n // active is a harmless no-op, while checking activity up\n // front invites the guard-versus-operation disagreement that\n // made `preventOverlappingAnnotations` recurse.\n ...mutuallyExclusive.map((annotation) =>\n raise({\n type: 'annotation.remove',\n annotation: {name: annotation},\n }),\n ),\n // `execute` (not `forward`) is deliberate: it skips the Core\n // Behavior that makes same-type annotations mutually\n // exclusive, so the configured list fully replaces the\n // default. An empty list therefore allows same-type overlap.\n execute(event),\n ],\n ],\n }),\n })\n }, [editor, props.schemaType.name, props.schemaType.mutuallyExclusive])\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {defineBehavior, effect, raise} from '@portabletext/editor/behaviors'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport {useMutuallyExclusiveAnnotation} from './use-mutually-exclusive-annotation'\nimport type {ToolbarAnnotationSchemaType} from './use-toolbar-schema'\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarAnnotationSchemaType},\n {type: 'set active'} | {type: 'set inactive'}\n>(({input, sendBack}) => {\n // Send back the initial state\n if (\n selectors.isActiveAnnotation(input.schemaType.name)(\n input.editor.getSnapshot(),\n )\n ) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (selectors.isActiveAnnotation(input.schemaType.name)(snapshot)) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst keyboardShortcutRemove = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarAnnotationSchemaType}\n>(({input}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n raise({\n type: 'annotation.remove',\n annotation: {\n name: input.schemaType.name,\n },\n }),\n effect(() => {\n input.editor.send({type: 'focus'})\n }),\n ],\n ],\n }),\n })\n})\n\nconst keyboardShortcutShowInsertDialog = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarAnnotationSchemaType},\n {type: 'open dialog'}\n>(({input, sendBack}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n effect(() => {\n sendBack({type: 'open dialog'})\n }),\n ],\n ],\n }),\n })\n})\n\nconst annotationButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ToolbarAnnotationSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ToolbarAnnotationSchemaType\n },\n events: {} as\n | AnnotationButtonEvent\n | DisableListenerEvent\n | {type: 'set active'}\n | {type: 'set inactive'},\n },\n actions: {\n 'add annotation': ({context, event}) => {\n if (event.type !== 'add') {\n return\n }\n\n context.editor.send({\n type: 'annotation.add',\n annotation: {\n name: context.schemaType.name,\n value: event.annotation.value,\n },\n })\n context.editor.send({type: 'focus'})\n },\n 'remove annotation': ({context}) => {\n context.editor.send({\n type: 'annotation.remove',\n annotation: {\n name: context.schemaType.name,\n },\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'active listener': activeListener,\n 'disable listener': disableListener,\n 'keyboard shortcut.remove': keyboardShortcutRemove,\n 'keyboard shortcut.show insert dialog': keyboardShortcutShowInsertDialog,\n },\n}).createMachine({\n id: 'annotation button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n {\n src: 'disable listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'enable': {\n target: '#annotation button.enabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'enable': {\n target: '#annotation button.enabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n enabled: {\n initial: 'inactive',\n states: {\n inactive: {\n initial: 'idle',\n on: {\n 'disable': {\n target: '#annotation button.disabled.inactive',\n },\n 'set active': {\n target: '#annotation button.enabled.active',\n },\n 'add': {\n actions: 'add annotation',\n },\n },\n states: {\n 'idle': {\n invoke: {\n src: 'keyboard shortcut.show insert dialog',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n on: {\n 'open dialog': {\n target: 'showing dialog',\n },\n },\n },\n 'showing dialog': {\n on: {\n 'close dialog': {\n target: 'idle',\n },\n },\n },\n },\n },\n active: {\n invoke: {\n src: 'keyboard shortcut.remove',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n on: {\n 'set inactive': {\n target: '#annotation button.enabled.inactive',\n },\n 'disable': {\n target: '#annotation button.disabled.active',\n },\n 'remove': {\n actions: 'remove annotation',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type AnnotationButtonEvent =\n | {type: 'close dialog'}\n | {type: 'open dialog'}\n | {\n type: 'add'\n annotation: {\n value: Record<string, unknown>\n }\n }\n | {type: 'remove'}\n\n/**\n * @beta\n */\nexport type AnnotationButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {disabled: 'inactive'}\n | {disabled: 'active'}\n | {enabled: 'inactive'}\n | {enabled: {inactive: 'idle'}}\n | {enabled: {inactive: 'showing dialog'}}\n | {enabled: 'active'},\n ) => boolean\n }\n send: (event: AnnotationButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcut and available events for an annotation\n * button.\n *\n * Note: This hook assumes that the button triggers a dialog for inputting\n * the annotation value.\n */\nexport function useAnnotationButton(props: {\n schemaType: ToolbarAnnotationSchemaType\n}): AnnotationButton {\n const editor = useEditor()\n const [snapshot, send] = useActor(annotationButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n useMutuallyExclusiveAnnotation(props)\n\n return {\n snapshot: {\n matches: (state) => snapshot.matches(state),\n },\n send,\n }\n}\n","import {\n useEditor,\n type AnnotationPath,\n type AnnotationSchemaType,\n type Editor,\n type PortableTextObject,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport * as React from 'react'\nimport type {RefObject} from 'react'\nimport {assign, fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarAnnotationSchemaType} from './use-toolbar-schema'\n\ntype ActiveContext = {\n annotations: Array<{\n value: PortableTextObject\n schemaType: ToolbarAnnotationSchemaType\n at: AnnotationPath\n }>\n elementRef: RefObject<Element | null>\n}\n\ntype ActiveListenerEvent =\n | ({\n type: 'set active'\n } & ActiveContext)\n | {\n type: 'set inactive'\n }\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>},\n ActiveListenerEvent\n>(({input, sendBack}) => {\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n const activeAnnotations = selectors.getActiveAnnotations(snapshot)\n const focusBlock = selectors.getFocusBlock(snapshot)\n\n if (activeAnnotations.length === 0 || !focusBlock) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const selectedChildren = input.editor.dom.getChildNodes(snapshot)\n const firstSelectedChild = selectedChildren.at(0)\n\n if (!firstSelectedChild || !(firstSelectedChild instanceof Element)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const elementRef = React.createRef<Element>()\n elementRef.current = firstSelectedChild\n\n sendBack({\n type: 'set active',\n annotations: activeAnnotations.flatMap((annotation) => {\n const schemaType = input.schemaTypes.find(\n (schemaType) => schemaType.name === annotation._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n return {\n value: annotation,\n schemaType,\n at: [...focusBlock.path, 'markDefs', {_key: annotation._key}],\n }\n }),\n elementRef,\n })\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst annotationPopoverMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>\n } & ActiveContext,\n input: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>\n },\n events: {} as\n | DisableListenerEvent\n | ActiveListenerEvent\n | AnnotationPopoverEvent,\n },\n actions: {\n reset: assign({\n annotations: [],\n elementRef: React.createRef<Element>(),\n }),\n remove: ({context, event}) => {\n if (event.type !== 'remove') {\n return\n }\n\n context.editor.send({\n type: 'annotation.remove',\n annotation: {\n name: event.schemaType.name,\n },\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'annotation popover',\n context: ({input}) => ({\n editor: input.editor,\n schemaTypes: input.schemaTypes,\n annotations: [],\n elementRef: React.createRef<Element>(),\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n actions: assign({\n annotations: ({event}) => event.annotations,\n elementRef: ({event}) => event.elementRef,\n }),\n target: 'active',\n },\n 'enable': {\n target: '#annotation popover.enabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'enable': {\n target: '#annotation popover.enabled.active',\n },\n },\n },\n },\n },\n enabled: {\n invoke: [\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaTypes: context.schemaTypes,\n }),\n },\n ],\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n target: 'active',\n actions: assign({\n annotations: ({event}) => event.annotations,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'disable': {\n target: '#annotation popover.disabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'disable': {\n target: '#annotation popover.disabled.active',\n },\n 'set active': {\n actions: assign({\n annotations: ({event}) => event.annotations,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'edit': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'annotation.set',\n at: event.at,\n props: event.props,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'remove': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'annotation.remove',\n annotation: {\n name: event.schemaType.name,\n },\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'close': {\n actions: ({context}) => {\n context.editor.send({type: 'focus'})\n },\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type AnnotationPopoverEvent =\n | {\n type: 'remove'\n schemaType: AnnotationSchemaType\n }\n | {\n type: 'edit'\n at: AnnotationPath\n props: {[key: string]: unknown}\n }\n | {\n type: 'close'\n }\n\n/**\n * @beta\n */\nexport type AnnotationPopover = {\n snapshot: {\n context: ActiveContext\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {\n enabled: 'inactive' | 'active'\n },\n ) => boolean\n }\n send: (event: AnnotationPopoverEvent) => void\n}\n\n/**\n * @beta\n * Manages the state and available events for an annotation popover.\n */\nexport function useAnnotationPopover(props: {\n schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>\n}): AnnotationPopover {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(annotationPopoverMachine, {\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n })\n\n return {\n snapshot: {\n context: {\n annotations: actorSnapshot.context.annotations,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {\n defineBehavior,\n effect,\n type InsertPlacement,\n} from '@portabletext/editor/behaviors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarBlockObjectSchemaType} from './use-toolbar-schema'\n\nconst keyboardShortcutListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarBlockObjectSchemaType},\n BlockObjectButtonEvent\n>(({input, sendBack}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n effect(() => {\n sendBack({type: 'open dialog'})\n }),\n ],\n ],\n }),\n })\n})\n\nconst blockObjectButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ToolbarBlockObjectSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ToolbarBlockObjectSchemaType\n },\n events: {} as DisableListenerEvent | BlockObjectButtonEvent,\n },\n actions: {\n insert: ({context, event}) => {\n if (event.type !== 'insert') {\n return\n }\n\n context.editor.send({\n type: 'insert.block object',\n blockObject: {\n name: context.schemaType.name,\n value: event.value,\n },\n placement: event.placement ?? 'auto',\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'keyboard shortcut listener': keyboardShortcutListener,\n },\n}).createMachine({\n id: 'block object button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n on: {\n disable: {\n target: 'disabled',\n },\n },\n initial: 'idle',\n states: {\n 'idle': {\n invoke: [\n {\n src: 'keyboard shortcut listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n on: {\n 'open dialog': {\n target: 'showing dialog',\n },\n },\n },\n 'showing dialog': {\n on: {\n 'close dialog': {\n target: 'idle',\n },\n 'insert': {\n actions: ['insert'],\n target: 'idle',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type BlockObjectButtonEvent =\n | {\n type: 'close dialog'\n }\n | {\n type: 'open dialog'\n }\n | {\n type: 'insert'\n value: {[key: string]: unknown}\n placement: InsertPlacement | undefined\n }\n\n/**\n * @beta\n */\nexport type BlockObjectButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {enabled: 'idle'}\n | {enabled: 'showing dialog'},\n ) => boolean\n }\n send: (event: BlockObjectButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcut and available events for a block\n * object button.\n *\n * Note: This hook assumes that the button triggers a dialog for inputting\n * the block object value.\n */\nexport function useBlockObjectButton(props: {\n schemaType: ToolbarBlockObjectSchemaType\n}): BlockObjectButton {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(blockObjectButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {\n useEditor,\n type BlockPath,\n type Editor,\n type PortableTextObject,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport * as React from 'react'\nimport type {RefObject} from 'react'\nimport {assign, fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarBlockObjectSchemaType} from './use-toolbar-schema'\n\ntype ActiveContext = {\n blockObjects: Array<{\n value: PortableTextObject\n schemaType: ToolbarBlockObjectSchemaType\n at: BlockPath\n }>\n elementRef: RefObject<Element | null>\n}\n\ntype ActiveListenerEvent =\n | ({\n type: 'set active'\n } & ActiveContext)\n | {\n type: 'set inactive'\n }\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>},\n ActiveListenerEvent\n>(({input, sendBack}) => {\n return input.editor.on(\n 'selection',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (!selectors.isSelectionCollapsed(snapshot)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const focusBlockObject = selectors.getFocusBlockObject(snapshot)\n\n if (!focusBlockObject) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const schemaType = input.schemaTypes.find(\n (schemaType) => schemaType.name === focusBlockObject.node._type,\n )\n\n if (!schemaType) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const selectedNodes = input.editor.dom.getBlockNodes(snapshot)\n const firstSelectedNode = selectedNodes.at(0)\n\n if (!firstSelectedNode || !(firstSelectedNode instanceof Element)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const elementRef = React.createRef<Element>()\n elementRef.current = firstSelectedNode\n\n sendBack({\n type: 'set active',\n blockObjects: [\n {\n value: focusBlockObject.node,\n schemaType,\n at: focusBlockObject.path,\n },\n ],\n elementRef,\n })\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst blockObjectPopoverMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>\n } & ActiveContext,\n input: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>\n },\n events: {} as\n | DisableListenerEvent\n | ActiveListenerEvent\n | BlockObjectPopoverEvent,\n },\n actions: {\n reset: assign({\n blockObjects: [],\n elementRef: React.createRef<Element>(),\n }),\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'block object popover',\n context: ({input}) => ({\n editor: input.editor,\n schemaTypes: input.schemaTypes,\n blockObjects: [],\n elementRef: React.createRef<Element>(),\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaTypes: context.schemaTypes,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n actions: assign({\n blockObjects: ({event}) => event.blockObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n target: 'active',\n },\n 'enable': {\n target: '#block object popover.enabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'enable': {\n target: '#block object popover.enabled.active',\n },\n },\n },\n },\n },\n enabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n target: 'active',\n actions: assign({\n blockObjects: ({event}) => event.blockObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'disable': {\n target: '#block object popover.disabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'disable': {\n target: '#block object popover.disabled.active',\n },\n 'set active': {\n actions: assign({\n blockObjects: ({event}) => event.blockObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'edit': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'block.set',\n at: event.at,\n props: event.props,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'remove': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'delete.block',\n at: event.at,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'close': {\n actions: ({context}) => {\n context.editor.send({type: 'focus'})\n },\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type BlockObjectPopoverEvent =\n | {\n type: 'remove'\n at: BlockPath\n }\n | {\n type: 'edit'\n at: BlockPath\n props: {[key: string]: unknown}\n }\n | {\n type: 'close'\n }\n\n/**\n * @beta\n */\nexport type BlockObjectPopover = {\n snapshot: {\n context: ActiveContext\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {\n enabled: 'inactive' | 'active'\n },\n ) => boolean\n }\n send: (event: BlockObjectPopoverEvent) => void\n}\n\n/**\n * @beta\n * Manages the state and available events for a block object popover.\n */\nexport function useBlockObjectPopover(props: {\n schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>\n}): BlockObjectPopover {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(blockObjectPopoverMachine, {\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n })\n\n return {\n snapshot: {\n context: {\n blockObjects: actorSnapshot.context.blockObjects,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {defineBehavior, raise} from '@portabletext/editor/behaviors'\nimport {useActorRef} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarDecoratorSchemaType} from './use-toolbar-schema'\n\nconst keyboardShortcutListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarDecoratorSchemaType}\n>(({input}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n raise({\n type: 'decorator.toggle',\n decorator: input.schemaType.name,\n }),\n ],\n ],\n }),\n })\n})\n\nconst decoratorKeyboardShortcutMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ToolbarDecoratorSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ToolbarDecoratorSchemaType\n },\n events: {} as DisableListenerEvent | {type: 'decorator.toggle'},\n },\n actors: {\n 'disable listener': disableListener,\n 'keyboard shortcut listener': keyboardShortcutListener,\n },\n}).createMachine({\n id: 'decorator keyboard shortcut',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n invoke: {\n src: 'keyboard shortcut listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n on: {\n disable: {\n target: 'disabled',\n },\n },\n },\n },\n})\n\nexport function useDecoratorKeyboardShortcut(props: {\n schemaType: ToolbarDecoratorSchemaType\n}) {\n const editor = useEditor()\n useActorRef(decoratorKeyboardShortcutMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n}\n","import {useEditor} from '@portabletext/editor'\nimport {defineBehavior, forward, raise} from '@portabletext/editor/behaviors'\nimport {useEffect} from 'react'\nimport type {ToolbarDecoratorSchemaType} from './use-toolbar-schema'\n\nexport function useMutuallyExclusiveDecorator(props: {\n schemaType: ToolbarDecoratorSchemaType\n}) {\n const editor = useEditor()\n\n useEffect(() => {\n const mutuallyExclusive = props.schemaType.mutuallyExclusive\n\n if (!mutuallyExclusive) {\n return\n }\n\n return editor.registerBehavior({\n behavior: defineBehavior({\n on: 'decorator.add',\n guard: ({event}) => event.decorator === props.schemaType.name,\n actions: [\n ({event}) => [\n forward(event),\n ...mutuallyExclusive.map((decorator) =>\n raise({\n type: 'decorator.remove',\n decorator,\n }),\n ),\n ],\n ],\n }),\n })\n }, [editor, props.schemaType.name, props.schemaType.mutuallyExclusive])\n}\n","import {\n useEditor,\n type DecoratorSchemaType,\n type Editor,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport {useDecoratorKeyboardShortcut} from './use-decorator-keyboard-shortcut'\nimport {useMutuallyExclusiveDecorator} from './use-mutually-exclusive-decorator'\nimport type {ToolbarDecoratorSchemaType} from './use-toolbar-schema'\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: DecoratorSchemaType},\n {type: 'set active'} | {type: 'set inactive'}\n>(({input, sendBack}) => {\n // Send back the initial state\n if (\n selectors.isActiveDecorator(input.schemaType.name)(\n input.editor.getSnapshot(),\n )\n ) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (selectors.isActiveDecorator(input.schemaType.name)(snapshot)) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst decoratorButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: DecoratorSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: DecoratorSchemaType\n },\n events: {} as DisableListenerEvent | DecoratorButtonEvent,\n },\n actions: {\n toggle: ({context, event}) => {\n if (event.type !== 'toggle') {\n return\n }\n\n context.editor.send({\n type: 'decorator.toggle',\n decorator: context.schemaType.name,\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'decorator button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'enable': {\n target: '#decorator button.enabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'enable': {\n target: '#decorator button.enabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n enabled: {\n on: {\n toggle: {\n actions: ['toggle'],\n },\n },\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'disable': {\n target: '#decorator button.disabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'disable': {\n target: '#decorator button.disabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type DecoratorButtonEvent = {\n type: 'toggle'\n}\n\n/**\n * @beta\n */\nexport type DecoratorButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {disabled: 'inactive'}\n | {disabled: 'active'}\n | {enabled: 'inactive'}\n | {enabled: 'active'},\n ) => boolean\n }\n send: (event: DecoratorButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcuts and available events for a decorator\n * button and sets up mutually exclusive decorator behaviors.\n */\nexport function useDecoratorButton(props: {\n schemaType: ToolbarDecoratorSchemaType\n}): DecoratorButton {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(decoratorButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n useDecoratorKeyboardShortcut(props)\n useMutuallyExclusiveDecorator(props)\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {useActor} from '@xstate/react'\nimport {setup} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\n\nconst historyButtonsMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n },\n input: {} as {\n editor: Editor\n },\n events: {} as DisableListenerEvent | HistoryButtonsEvent,\n },\n actors: {\n 'disable listener': disableListener,\n },\n}).createMachine({\n id: 'history buttons',\n context: ({input}) => ({\n editor: input.editor,\n }),\n invoke: {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n on: {\n 'disable': {\n target: 'disabled',\n },\n 'history.undo': {\n actions: ({context}) => {\n context.editor.send({type: 'history.undo'})\n context.editor.send({type: 'focus'})\n },\n },\n 'history.redo': {\n actions: ({context}) => {\n context.editor.send({type: 'history.redo'})\n context.editor.send({type: 'focus'})\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type HistoryButtonsEvent =\n | {\n type: 'history.undo'\n }\n | {\n type: 'history.redo'\n }\n\n/**\n * @beta\n */\nexport type HistoryButtons = {\n snapshot: {\n matches: (state: 'disabled' | 'enabled') => boolean\n }\n send: (event: HistoryButtonsEvent) => void\n}\n\n/**\n * @beta\n */\nexport function useHistoryButtons(): HistoryButtons {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(historyButtonsMachine, {\n input: {\n editor,\n },\n })\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {defineBehavior, effect} from '@portabletext/editor/behaviors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarInlineObjectSchemaType} from './use-toolbar-schema'\n\nconst keyboardShortcutListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ToolbarInlineObjectSchemaType},\n InlineObjectButtonEvent\n>(({input, sendBack}) => {\n const shortcut = input.schemaType.shortcut\n\n if (!shortcut) {\n return\n }\n\n return input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [\n effect(() => {\n sendBack({type: 'open dialog'})\n }),\n ],\n ],\n }),\n })\n})\n\nconst inlineObjectButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ToolbarInlineObjectSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ToolbarInlineObjectSchemaType\n },\n events: {} as DisableListenerEvent | InlineObjectButtonEvent,\n },\n actions: {\n insert: ({context, event}) => {\n if (event.type !== 'insert') {\n return\n }\n\n context.editor.send({\n type: 'insert.inline object',\n inlineObject: {\n name: context.schemaType.name,\n value: event.value,\n },\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'keyboard shortcut listener': keyboardShortcutListener,\n },\n}).createMachine({\n id: 'inline object button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n on: {\n disable: {\n target: 'disabled',\n },\n },\n initial: 'idle',\n states: {\n 'idle': {\n invoke: [\n {\n src: 'keyboard shortcut listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n on: {\n 'open dialog': {\n target: 'showing dialog',\n },\n },\n },\n 'showing dialog': {\n on: {\n 'close dialog': {\n target: 'idle',\n },\n 'insert': {\n actions: ['insert'],\n target: 'idle',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type InlineObjectButtonEvent =\n | {\n type: 'close dialog'\n }\n | {\n type: 'open dialog'\n }\n | {\n type: 'insert'\n value: {[key: string]: unknown}\n }\n\n/**\n * @beta\n */\nexport type InlineObjectButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {enabled: 'idle'}\n | {enabled: 'showing dialog'},\n ) => boolean\n }\n send: (event: InlineObjectButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcut and available events for an inline\n * object button.\n *\n * Note: This hook assumes that the button triggers a dialog for inputting\n * the inline object value.\n */\nexport function useInlineObjectButton(props: {\n schemaType: ToolbarInlineObjectSchemaType\n}): InlineObjectButton {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(inlineObjectButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {\n useEditor,\n type ChildPath,\n type Editor,\n type PortableTextObject,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport * as React from 'react'\nimport type {RefObject} from 'react'\nimport {assign, fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarInlineObjectSchemaType} from './use-toolbar-schema'\n\ntype ActiveContext = {\n inlineObjects: Array<{\n value: PortableTextObject\n schemaType: ToolbarInlineObjectSchemaType\n at: ChildPath\n }>\n elementRef: RefObject<Element | null>\n}\n\ntype ActiveListenerEvent =\n | ({\n type: 'set active'\n } & ActiveContext)\n | {\n type: 'set inactive'\n }\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>},\n ActiveListenerEvent\n>(({input, sendBack}) => {\n return input.editor.on(\n 'selection',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (!selectors.isSelectionCollapsed(snapshot)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const focusInlineObject = selectors.getFocusInlineObject(snapshot)\n\n if (!focusInlineObject) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const schemaType = input.schemaTypes.find(\n (schemaType) => schemaType.name === focusInlineObject.node._type,\n )\n\n if (!schemaType) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const selectedNodes = input.editor.dom.getChildNodes(snapshot)\n const firstSelectedNode = selectedNodes.at(0)\n\n if (!firstSelectedNode || !(firstSelectedNode instanceof Element)) {\n sendBack({type: 'set inactive'})\n return\n }\n\n const elementRef = React.createRef<Element>()\n elementRef.current = firstSelectedNode\n\n sendBack({\n type: 'set active',\n inlineObjects: [\n {\n value: focusInlineObject.node,\n schemaType,\n at: focusInlineObject.path,\n },\n ],\n elementRef,\n })\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst inlineObjectPopoverMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>\n } & ActiveContext,\n input: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>\n },\n events: {} as\n | DisableListenerEvent\n | ActiveListenerEvent\n | InlineObjectPopoverEvent,\n },\n actions: {\n reset: assign({\n inlineObjects: [],\n elementRef: React.createRef<Element>(),\n }),\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'inline object popover',\n context: ({input}) => ({\n editor: input.editor,\n schemaTypes: input.schemaTypes,\n inlineObjects: [],\n elementRef: React.createRef<Element>(),\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaTypes: context.schemaTypes,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n actions: assign({\n inlineObjects: ({event}) => event.inlineObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n target: 'active',\n },\n 'enable': {\n target: '#inline object popover.enabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'enable': {\n target: '#inline object popover.enabled.active',\n },\n },\n },\n },\n },\n enabled: {\n initial: 'inactive',\n states: {\n inactive: {\n entry: ['reset'],\n on: {\n 'set active': {\n target: 'active',\n actions: assign({\n inlineObjects: ({event}) => event.inlineObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'disable': {\n target: '#inline object popover.disabled.inactive',\n },\n },\n },\n active: {\n on: {\n 'set inactive': {\n target: 'inactive',\n },\n 'disable': {\n target: '#inline object popover.disabled.active',\n },\n 'set active': {\n actions: assign({\n inlineObjects: ({event}) => event.inlineObjects,\n elementRef: ({event}) => event.elementRef,\n }),\n },\n 'edit': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'child.set',\n at: event.at,\n props: event.props,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'remove': {\n actions: ({context, event}) => {\n context.editor.send({\n type: 'delete.child',\n at: event.at,\n })\n context.editor.send({type: 'focus'})\n },\n },\n 'close': {\n actions: ({context}) => {\n context.editor.send({type: 'focus'})\n },\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type InlineObjectPopoverEvent =\n | {\n type: 'remove'\n at: ChildPath\n }\n | {\n type: 'edit'\n at: ChildPath\n props: {[key: string]: unknown}\n }\n | {\n type: 'close'\n }\n\n/**\n * @beta\n */\nexport type InlineObjectPopover = {\n snapshot: {\n context: ActiveContext\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {\n enabled: 'inactive' | 'active'\n },\n ) => boolean\n }\n send: (event: InlineObjectPopoverEvent) => void\n}\n\n/**\n * @beta\n * Manages the state and available events for an inline object popover.\n */\nexport function useInlineObjectPopover(props: {\n schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>\n}): InlineObjectPopover {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(inlineObjectPopoverMachine, {\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n })\n\n return {\n snapshot: {\n context: {\n inlineObjects: actorSnapshot.context.inlineObjects,\n elementRef: actorSnapshot.context.elementRef,\n },\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor, type ListSchemaType} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarListSchemaType} from './use-toolbar-schema'\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaType: ListSchemaType},\n {type: 'set active'} | {type: 'set inactive'}\n>(({input, sendBack}) => {\n // Send back the initial state\n if (\n selectors.isActiveListItem(input.schemaType.name)(\n input.editor.getSnapshot(),\n )\n ) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n\n if (selectors.isActiveListItem(input.schemaType.name)(snapshot)) {\n sendBack({type: 'set active'})\n } else {\n sendBack({type: 'set inactive'})\n }\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst listButtonMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaType: ListSchemaType\n },\n input: {} as {\n editor: Editor\n schemaType: ListSchemaType\n },\n events: {} as DisableListenerEvent | ListButtonEvent,\n },\n actions: {\n toggle: ({context, event}) => {\n if (event.type !== 'toggle') {\n return\n }\n\n context.editor.send({\n type: 'list item.toggle',\n listItem: context.schemaType.name,\n })\n context.editor.send({type: 'focus'})\n },\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'list button',\n context: ({input}) => ({\n editor: input.editor,\n schemaType: input.schemaType,\n }),\n invoke: [\n {src: 'disable listener', input: ({context}) => ({editor: context.editor})},\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaType: context.schemaType,\n }),\n },\n ],\n initial: 'disabled',\n states: {\n disabled: {\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'enable': {\n target: '#list button.enabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'enable': {\n target: '#list button.enabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n enabled: {\n on: {\n toggle: {\n actions: ['toggle'],\n },\n },\n initial: 'inactive',\n states: {\n inactive: {\n on: {\n 'disable': {\n target: '#list button.disabled.inactive',\n },\n 'set active': {\n target: 'active',\n },\n },\n },\n active: {\n on: {\n 'disable': {\n target: '#list button.disabled.active',\n },\n 'set inactive': {\n target: 'inactive',\n },\n },\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type ListButtonEvent = {\n type: 'toggle'\n}\n\n/**\n * @beta\n */\nexport type ListButton = {\n snapshot: {\n matches: (\n state:\n | 'disabled'\n | 'enabled'\n | {disabled: 'inactive'}\n | {disabled: 'active'}\n | {enabled: 'inactive'}\n | {enabled: 'active'},\n ) => boolean\n }\n send: (event: ListButtonEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcuts and available events for a list button.\n */\nexport function useListButton(props: {\n schemaType: ToolbarListSchemaType\n}): ListButton {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(listButtonMachine, {\n input: {\n editor,\n schemaType: props.schemaType,\n },\n })\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n },\n send,\n }\n}\n","import {useEditor, type Editor} from '@portabletext/editor'\nimport {defineBehavior, raise} from '@portabletext/editor/behaviors'\nimport {useActorRef} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport type {ToolbarStyleSchemaType} from './use-toolbar-schema'\n\nconst styleKeyboardShortcutsListener = fromCallback<\n AnyEventObject,\n {editor: Editor; schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>}\n>(({input}) => {\n const unregisterBehaviors = input.schemaTypes.flatMap((schemaType) => {\n const shortcut = schemaType.shortcut\n\n if (!shortcut) {\n return []\n }\n\n return [\n input.editor.registerBehavior({\n behavior: defineBehavior({\n on: 'keyboard.keydown',\n guard: ({event}) => shortcut.guard(event.originEvent),\n actions: [\n () => [raise({type: 'style.toggle', style: schemaType.name})],\n ],\n }),\n }),\n ]\n })\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n})\n\nconst styleKeyboardShortcutsMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>\n },\n input: {} as {\n editor: Editor\n schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>\n },\n events: {} as DisableListenerEvent | {type: 'style.toggle'},\n },\n actors: {\n 'disable listener': disableListener,\n 'style keyboard shortcuts listener': styleKeyboardShortcutsListener,\n },\n}).createMachine({\n id: 'style keyboard shortcuts',\n context: ({input}) => ({\n editor: input.editor,\n schemaTypes: input.schemaTypes,\n }),\n invoke: {\n src: 'disable listener',\n input: ({context}) => ({editor: context.editor}),\n },\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n invoke: {\n src: 'style keyboard shortcuts listener',\n input: ({context}) => ({\n editor: context.editor,\n schemaTypes: context.schemaTypes,\n }),\n },\n on: {\n disable: {\n target: 'disabled',\n },\n },\n },\n },\n})\n\n/**\n * @beta\n * Registers keyboard shortcuts for a set of style schema types.\n */\nexport function useStyleKeyboardShortcuts(props: {\n schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>\n}) {\n const editor = useEditor()\n useActorRef(styleKeyboardShortcutsMachine, {\n input: {\n editor,\n schemaTypes: props.schemaTypes,\n },\n })\n}\n","import {\n useEditor,\n type Editor,\n type StyleSchemaType,\n} from '@portabletext/editor'\nimport * as selectors from '@portabletext/editor/selectors'\nimport {useActor} from '@xstate/react'\nimport {assign, fromCallback, setup, type AnyEventObject} from 'xstate'\nimport {disableListener, type DisableListenerEvent} from './disable-listener'\nimport {useStyleKeyboardShortcuts} from './use-style-keyboard-shortcuts'\nimport type {ToolbarStyleSchemaType} from './use-toolbar-schema'\n\ntype ActiveStyleListenerEvent = {\n type: 'set active style'\n style: StyleSchemaType['name'] | undefined\n}\n\nconst activeListener = fromCallback<\n AnyEventObject,\n {editor: Editor},\n ActiveStyleListenerEvent\n>(({input, sendBack}) => {\n // Send back the initial state\n const activeStyle = selectors.getActiveStyle(input.editor.getSnapshot())\n sendBack({type: 'set active style', style: activeStyle})\n\n return input.editor.on(\n '*',\n () => {\n const snapshot = input.editor.getSnapshot()\n const activeStyle = selectors.getActiveStyle(snapshot)\n\n sendBack({type: 'set active style', style: activeStyle})\n },\n {batch: true},\n ).unsubscribe\n})\n\nconst styleSelectorMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n activeStyle: StyleSchemaType['name'] | undefined\n },\n input: {} as {\n editor: Editor\n },\n events: {} as\n | StyleSelectorEvent\n | DisableListenerEvent\n | ActiveStyleListenerEvent,\n },\n actors: {\n 'disable listener': disableListener,\n 'active listener': activeListener,\n },\n}).createMachine({\n id: 'style selector',\n context: ({input}) => ({\n editor: input.editor,\n activeStyle: undefined,\n }),\n invoke: [\n {\n src: 'disable listener',\n input: ({context}) => ({\n editor: context.editor,\n }),\n },\n {\n src: 'active listener',\n input: ({context}) => ({\n editor: context.editor,\n }),\n },\n ],\n on: {\n 'set active style': {\n guard: ({context, event}) => context.activeStyle !== event.style,\n actions: assign({\n activeStyle: ({event}) => event.style,\n }),\n },\n },\n initial: 'disabled',\n states: {\n disabled: {\n on: {\n enable: {\n target: 'enabled',\n },\n },\n },\n enabled: {\n on: {\n disable: {\n target: 'disabled',\n },\n toggle: {\n actions: [\n ({context, event}) => {\n context.editor.send({type: 'style.toggle', style: event.style})\n context.editor.send({type: 'focus'})\n },\n ],\n },\n },\n },\n },\n})\n\n/**\n * @beta\n */\nexport type StyleSelectorEvent = {\n type: 'toggle'\n style: StyleSchemaType['name']\n}\n\n/**\n * @beta\n */\nexport type StyleSelector = {\n snapshot: {\n matches: (state: 'disabled' | 'enabled') => boolean\n context: {\n activeStyle: StyleSchemaType['name'] | undefined\n }\n }\n send: (event: StyleSelectorEvent) => void\n}\n\n/**\n * @beta\n * Manages the state, keyboard shortcuts and available events for a style\n * selector.\n */\nexport function useStyleSelector(props: {\n schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>\n}): StyleSelector {\n const editor = useEditor()\n const [actorSnapshot, send] = useActor(styleSelectorMachine, {\n input: {\n editor,\n },\n })\n useStyleKeyboardShortcuts(props)\n\n return {\n snapshot: {\n matches: (state) => actorSnapshot.matches(state),\n context: {\n activeStyle: actorSnapshot.context.activeStyle,\n },\n },\n send,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,sBAAwC;CACtD,IAAM,SAAS,UAAU;CACzB,OAAO,kBAAkB,QAAQ,qBAAqB,uBAAuB;AAC/E;;;;;;;;;;;;;;;;ACkDA,SAAgB,iBAAiB,OAOf;gBACV,SAAS,UAAU,GACnB,QAAQ,kBACZ,QACAA,SAEA,cACF,GAGcC;CACKC,IAAAA,EAAAA,OAAAA,SAAAA,EAAAA,OADCC,MAAAA,YAAAA;EAChBC,IAAAA;EAAeF,EAAAA,OAAAA,qBAAf,MAAC,cAAc,MAAM,kBAAkB,SA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OAAAA,cAAR,QAAQ,2BAD5B,KAAA,EACP,aAAa,cAAc,QAAQ,YACrC,GADqCA,EAAAA,KAAAA,cAAR,QAAQ;CAH7BC,IAAAA;CACCH,AAAAA,EAAAA,OAAAA,MAAAA,EAAAA,OACAC,MAFD,KAAA;EACR,SAASD;EACT,SAASC;CAGX,GAJWD,EAAAA,KAAAA,IACAC,EAAAA,KAAAA;CAHNG,IAAAA;CAAP,OAOE,EAAA,OAAA,QAAA,EAAA,QANUD,MADL,KAAA;EACL,UAAUA;EAMV;CACF,GADE,EAAA,KAAA,MANUA,EAAAA,MAAAA,8BADLC;AAST"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/toolbar",
3
- "version": "8.0.50",
3
+ "version": "9.0.0",
4
4
  "description": "Utilities for building a toolbar for the Portable Text Editor",
5
5
  "keywords": [
6
6
  "portabletext",
@@ -22,8 +22,6 @@
22
22
  ],
23
23
  "type": "module",
24
24
  "sideEffects": false,
25
- "main": "./dist/index.js",
26
- "module": "./dist/index.js",
27
25
  "types": "./dist/index.d.ts",
28
26
  "exports": {
29
27
  ".": "./dist/index.js",
@@ -32,45 +30,37 @@
32
30
  "dependencies": {
33
31
  "@xstate/react": "^6.1.0",
34
32
  "xstate": "^5.32.5",
35
- "@portabletext/keyboard-shortcuts": "^2.1.4"
33
+ "@portabletext/keyboard-shortcuts": "^3.0.0"
36
34
  },
37
35
  "devDependencies": {
38
- "@rolldown/plugin-babel": "^0.2.3",
39
- "@sanity/pkg-utils": "^12.1.0",
36
+ "@sanity/pkg-utils": "^12.3.0",
40
37
  "@sanity/tsconfig": "^2.1.0",
41
38
  "@types/react": "^19.2.17",
42
- "@vitejs/plugin-react": "^6.0.5",
39
+ "@vitejs/plugin-react": "^6.1.0",
43
40
  "@vitest/browser": "^4.1.10",
44
41
  "@vitest/browser-playwright": "^4.1.10",
45
- "babel-plugin-react-compiler": "^1.0.0",
46
- "eslint": "^9.39.4",
47
- "eslint-formatter-gha": "^1.6.0",
48
- "eslint-plugin-react-hooks": "^7.1.1",
42
+ "oxc-transform-react": "^0.145.0",
49
43
  "react": "^19.2.8",
50
- "typescript": "6.0.3",
51
- "typescript-eslint": "^8.62.0",
44
+ "typescript": "^7.0.2",
52
45
  "vite": "^8.2.0",
53
46
  "vitest": "^4.1.10",
54
- "@portabletext/editor": "^7.12.1",
55
- "@portabletext/test": "1.0.5",
56
- "@portabletext/schema": "2.2.4"
47
+ "@portabletext/editor": "^8.0.0",
48
+ "@portabletext/schema": "3.0.0",
49
+ "@portabletext/test": "2.0.0"
57
50
  },
58
51
  "peerDependencies": {
59
- "@portabletext/editor": "^7.12.1",
52
+ "@portabletext/editor": "^8.0.0",
60
53
  "react": "^19.2.8"
61
54
  },
62
55
  "engines": {
63
- "node": ">=20.19 <22 || >=22.12"
56
+ "node": ">=22.12"
64
57
  },
65
58
  "scripts": {
66
59
  "build": "pkg-utils build --strict --check",
67
- "check:lint": "biome lint .",
68
- "check:react-compiler": "eslint --cache .",
69
60
  "check:types": "tsc",
70
61
  "check:types:watch": "tsc --watch",
71
62
  "clean": "del .turbo && del dist && del node_modules",
72
63
  "dev": "pkg-utils watch",
73
- "lint:fix": "biome lint --write .",
74
64
  "test:browser": "vitest --run --project browser",
75
65
  "test:browser:chromium": "vitest run --project \"browser (chromium)\"",
76
66
  "test:browser:chromium:watch": "vitest watch --project \"browser (chromium)\"",