@portabletext/editor 1.18.7 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +52 -35
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -1
  4. package/lib/_chunks-es/behavior.core.js +52 -35
  5. package/lib/_chunks-es/behavior.core.js.map +1 -1
  6. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -1
  7. package/lib/behaviors/index.cjs +1 -0
  8. package/lib/behaviors/index.cjs.map +1 -1
  9. package/lib/behaviors/index.d.cts +78 -86
  10. package/lib/behaviors/index.d.ts +78 -86
  11. package/lib/behaviors/index.js +3 -2
  12. package/lib/behaviors/index.js.map +1 -1
  13. package/lib/index.cjs +277 -422
  14. package/lib/index.cjs.map +1 -1
  15. package/lib/index.d.cts +488 -1127
  16. package/lib/index.d.ts +488 -1127
  17. package/lib/index.js +279 -425
  18. package/lib/index.js.map +1 -1
  19. package/lib/selectors/index.cjs +12 -9
  20. package/lib/selectors/index.cjs.map +1 -1
  21. package/lib/selectors/index.js +12 -9
  22. package/lib/selectors/index.js.map +1 -1
  23. package/package.json +5 -7
  24. package/src/behavior-actions/behavior.actions.ts +28 -36
  25. package/src/behaviors/behavior.core.decorators.ts +36 -42
  26. package/src/behaviors/behavior.core.ts +4 -3
  27. package/src/behaviors/behavior.types.ts +40 -26
  28. package/src/behaviors/index.ts +1 -0
  29. package/src/editor/PortableTextEditor.tsx +14 -16
  30. package/src/editor/__tests__/self-solving.test.tsx +4 -11
  31. package/src/editor/components/Element.tsx +17 -23
  32. package/src/editor/create-editor.ts +18 -3
  33. package/src/editor/editor-machine.ts +67 -45
  34. package/src/editor/nodes/DefaultObject.tsx +2 -2
  35. package/src/editor/plugins/create-with-event-listeners.ts +44 -57
  36. package/src/editor/plugins/createWithHotKeys.ts +1 -11
  37. package/src/editor/plugins/createWithPortableTextMarkModel.ts +12 -1
  38. package/src/editor/plugins/createWithPortableTextSelections.ts +1 -5
  39. package/src/editor/with-applying-behavior-actions.ts +15 -0
  40. package/src/selectors/selector.get-selected-spans.test.ts +122 -0
  41. package/src/selectors/selector.get-selected-spans.ts +3 -1
  42. package/src/selectors/selector.is-active-decorator.test.ts +65 -0
  43. package/src/editor/nodes/index.ts +0 -189
@@ -173,6 +173,12 @@ function toKeyName(name) {
173
173
  const keyName = name.toLowerCase();
174
174
  return aliases[keyName] ?? keyName;
175
175
  }
176
+ function raise(event) {
177
+ return {
178
+ type: "raise",
179
+ event
180
+ };
181
+ }
176
182
  function defineBehavior(behavior) {
177
183
  return behavior;
178
184
  }
@@ -306,41 +312,51 @@ const arrowDownOnLonelyBlockObject = {
306
312
  breakingBlockObject,
307
313
  deletingEmptyTextBlockAfterBlockObject,
308
314
  deletingEmptyTextBlockBeforeBlockObject
309
- }, decoratorAdd = {
310
- on: "decorator.add",
311
- actions: [({
312
- event
313
- }) => [event, {
314
- type: "reselect"
315
- }]]
316
- }, decoratorRemove = {
317
- on: "decorator.remove",
318
- guard: ({
319
- event
320
- }) => ({
321
- decorator: event.decorator
322
- }),
323
- actions: [({
324
- event
325
- }) => [event, {
326
- type: "reselect"
327
- }]]
328
- }, decoratorToggle = {
329
- on: "decorator.toggle",
330
- guard: ({
331
- event
332
- }) => ({
333
- decorator: event.decorator
334
- }),
335
- actions: [({
336
- event
337
- }) => [event, {
338
- type: "reselect"
339
- }]]
340
315
  }, coreDecoratorBehaviors = {
341
- decoratorAdd,
342
- decoratorRemove,
343
- decoratorToggle
316
+ strongShortcut: {
317
+ on: "key.down",
318
+ guard: ({
319
+ context,
320
+ event
321
+ }) => isHotkey("mod+b", event.keyboardEvent) && context.schema.decorators.some((decorator) => decorator.value === "strong"),
322
+ actions: [() => [raise({
323
+ type: "decorator.toggle",
324
+ decorator: "strong"
325
+ })]]
326
+ },
327
+ emShortcut: {
328
+ on: "key.down",
329
+ guard: ({
330
+ context,
331
+ event
332
+ }) => isHotkey("mod+i", event.keyboardEvent) && context.schema.decorators.some((decorator) => decorator.value === "em"),
333
+ actions: [() => [raise({
334
+ type: "decorator.toggle",
335
+ decorator: "em"
336
+ })]]
337
+ },
338
+ underlineShortcut: {
339
+ on: "key.down",
340
+ guard: ({
341
+ context,
342
+ event
343
+ }) => isHotkey("mod+u", event.keyboardEvent) && context.schema.decorators.some((decorator) => decorator.value === "underline"),
344
+ actions: [() => [raise({
345
+ type: "decorator.toggle",
346
+ decorator: "underline"
347
+ })]]
348
+ },
349
+ codeShortcut: {
350
+ on: "key.down",
351
+ guard: ({
352
+ context,
353
+ event
354
+ }) => isHotkey("mod+'", event.keyboardEvent) && context.schema.decorators.some((decorator) => decorator.value === "code"),
355
+ actions: [() => [raise({
356
+ type: "decorator.toggle",
357
+ decorator: "code"
358
+ })]]
359
+ }
344
360
  }, MAX_LIST_LEVEL = 10, clearListOnBackspace = {
345
361
  on: "delete.backward",
346
362
  guard: ({
@@ -473,7 +489,7 @@ const arrowDownOnLonelyBlockObject = {
473
489
  text: `
474
490
  `
475
491
  }]]
476
- }, coreBehaviors = [softReturn, coreDecoratorBehaviors.decoratorAdd, coreDecoratorBehaviors.decoratorRemove, coreDecoratorBehaviors.decoratorToggle, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab], coreBehavior = {
492
+ }, coreBehaviors = [softReturn, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab], coreBehavior = {
477
493
  softReturn,
478
494
  decorators: coreDecoratorBehaviors,
479
495
  blockObjects: coreBlockObjectBehaviors,
@@ -485,5 +501,6 @@ exports.coreBehaviors = coreBehaviors;
485
501
  exports.defineBehavior = defineBehavior;
486
502
  exports.getTextBlockText = getTextBlockText;
487
503
  exports.isHotkey = isHotkey;
504
+ exports.raise = raise;
488
505
  exports.spanSelectionPointToBlockOffset = spanSelectionPointToBlockOffset;
489
506
  //# sourceMappingURL=behavior.core.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"behavior.core.cjs","sources":["../../src/editor/utils/utils.block-offset.ts","../../src/editor/utils/utils.ts","../../src/utils/is-hotkey.ts","../../src/behaviors/behavior.types.ts","../../src/behaviors/behavior.core.block-objects.ts","../../src/behaviors/behavior.core.decorators.ts","../../src/behaviors/behavior.core.lists.ts","../../src/behaviors/behavior.core.ts"],"sourcesContent":["import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../../behaviors/behavior.types'\n\nexport function blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n\n for (const block of value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (offsetLeft === 0) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n break\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n }\n }\n\n return selectionPoint\n}\n\nexport function spanSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: {\n path: [KeyedSegment, 'children', KeyedSegment]\n offset: number\n }\n}): BlockOffset | undefined {\n let offset = 0\n\n for (const block of value) {\n if (block._key !== selectionPoint.path[0]._key) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (child._key === selectionPoint.path[2]._key) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\n\nexport function isEmptyTextBlock(block: PortableTextBlock) {\n if (!isPortableTextTextBlock(block)) {\n return false\n }\n\n const onlyText = block.children.every(isPortableTextSpan)\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","export interface KeyboardEventLike {\n key: string\n keyCode?: number\n altKey: boolean\n ctrlKey: boolean\n metaKey: boolean\n shiftKey: boolean\n}\n\ninterface HotKey {\n keyCode?: number | undefined\n key?: string | undefined\n altKey: boolean | null\n ctrlKey: boolean | null\n metaKey: boolean | null\n shiftKey: boolean | null\n}\n\nconst IS_MAC =\n typeof window !== 'undefined' &&\n /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent)\n\ntype Modifier = 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n\nconst modifiers: Record<string, Modifier | undefined> = {\n alt: 'altKey',\n control: 'ctrlKey',\n meta: 'metaKey',\n shift: 'shiftKey',\n}\n\nconst aliases: Record<string, string | undefined> = {\n add: '+',\n break: 'pause',\n cmd: 'meta',\n command: 'meta',\n ctl: 'control',\n ctrl: 'control',\n del: 'delete',\n down: 'arrowdown',\n esc: 'escape',\n ins: 'insert',\n left: 'arrowleft',\n mod: IS_MAC ? 'meta' : 'control',\n opt: 'alt',\n option: 'alt',\n return: 'enter',\n right: 'arrowright',\n space: ' ',\n spacebar: ' ',\n up: 'arrowup',\n win: 'meta',\n windows: 'meta',\n}\n\nconst keyCodes: Record<string, number | undefined> = {\n 'backspace': 8,\n 'tab': 9,\n 'enter': 13,\n 'shift': 16,\n 'control': 17,\n 'alt': 18,\n 'pause': 19,\n 'capslock': 20,\n 'escape': 27,\n ' ': 32,\n 'pageup': 33,\n 'pagedown': 34,\n 'end': 35,\n 'home': 36,\n 'arrowleft': 37,\n 'arrowup': 38,\n 'arrowright': 39,\n 'arrowdown': 40,\n 'insert': 45,\n 'delete': 46,\n 'meta': 91,\n 'numlock': 144,\n 'scrolllock': 145,\n ';': 186,\n '=': 187,\n ',': 188,\n '-': 189,\n '.': 190,\n '/': 191,\n '`': 192,\n '[': 219,\n '\\\\': 220,\n ']': 221,\n \"'\": 222,\n 'f1': 112,\n 'f2': 113,\n 'f3': 114,\n 'f4': 115,\n 'f5': 116,\n 'f6': 117,\n 'f7': 118,\n 'f8': 119,\n 'f9': 120,\n 'f10': 121,\n 'f11': 122,\n 'f12': 123,\n 'f13': 124,\n 'f14': 125,\n 'f15': 126,\n 'f16': 127,\n 'f17': 128,\n 'f18': 129,\n 'f19': 130,\n 'f20': 131,\n}\n\nexport function isHotkey(hotkey: string, event: KeyboardEventLike): boolean {\n return compareHotkey(parseHotkey(hotkey), event)\n}\n\nfunction parseHotkey(hotkey: string): HotKey {\n // Ensure that all the modifiers are set to false unless the hotkey has them.\n const parsedHotkey: HotKey = {\n altKey: false,\n ctrlKey: false,\n metaKey: false,\n shiftKey: false,\n }\n\n // Special case to handle the `+` key since we use it as a separator.\n const hotkeySegments = hotkey.replace('++', '+add').split('+')\n\n for (const rawHotkeySegment of hotkeySegments) {\n const optional =\n rawHotkeySegment.endsWith('?') && rawHotkeySegment.length > 1\n const hotkeySegment = optional\n ? rawHotkeySegment.slice(0, -1)\n : rawHotkeySegment\n const keyName = toKeyName(hotkeySegment)\n const modifier = modifiers[keyName]\n const alias = aliases[hotkeySegment]\n const code = keyCodes[keyName]\n\n if (\n hotkeySegment.length > 1 &&\n modifier === undefined &&\n alias === undefined &&\n code === undefined\n ) {\n throw new TypeError(`Unknown modifier: \"${hotkeySegment}\"`)\n }\n\n if (hotkeySegments.length === 1 || modifier === undefined) {\n parsedHotkey.key = keyName\n parsedHotkey.keyCode = toKeyCode(hotkeySegment)\n }\n\n if (modifier !== undefined) {\n parsedHotkey[modifier] = optional ? null : true\n }\n }\n\n return parsedHotkey\n}\n\nfunction compareHotkey(\n parsedHotkey: HotKey,\n event: KeyboardEventLike,\n): boolean {\n const matchingModifiers =\n (parsedHotkey.altKey != null\n ? parsedHotkey.altKey === event.altKey\n : true) &&\n (parsedHotkey.ctrlKey != null\n ? parsedHotkey.ctrlKey === event.ctrlKey\n : true) &&\n (parsedHotkey.metaKey != null\n ? parsedHotkey.metaKey === event.metaKey\n : true) &&\n (parsedHotkey.shiftKey != null\n ? parsedHotkey.shiftKey === event.shiftKey\n : true)\n\n if (!matchingModifiers) {\n return false\n }\n\n if (parsedHotkey.keyCode !== undefined && event.keyCode !== undefined) {\n if (parsedHotkey.keyCode === 91 && event.keyCode === 93) {\n return true\n }\n\n return parsedHotkey.keyCode === event.keyCode\n }\n\n return (\n parsedHotkey.keyCode === event.keyCode ||\n parsedHotkey.key === event.key.toLowerCase()\n )\n}\n\nfunction toKeyCode(name: string): number {\n const keyName = toKeyName(name)\n const keyCode = keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0)\n\n return keyCode\n}\n\nfunction toKeyName(name: string): string {\n const keyName = name.toLowerCase()\n\n return aliases[keyName] ?? keyName\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {TextUnit} from 'slate'\nimport type {TextInsertTextOptions} from 'slate/dist/interfaces/transforms/text'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {PickFromUnion} from '../type-utils'\nimport type {EditorSelection, PortableTextSlateEditor} from '../types/editor'\n\n/**\n * @beta\n */\nexport type SyntheticBehaviorEvent =\n | {\n type: 'annotation.add'\n annotation: {\n name: string\n value: {[prop: string]: unknown}\n }\n }\n | {\n type: 'annotation.remove'\n annotation: {\n name: string\n }\n }\n | {\n type: 'annotation.toggle'\n annotation: {\n name: string\n value: {[prop: string]: unknown}\n }\n }\n | {\n type: 'blur'\n }\n | {\n type: 'decorator.add'\n decorator: string\n }\n | {\n type: 'decorator.remove'\n decorator: string\n }\n | {\n type: 'decorator.toggle'\n decorator: string\n }\n | {\n type: 'delete.backward'\n unit: TextUnit\n }\n | {\n type: 'delete.forward'\n unit: TextUnit\n }\n | {\n type: 'focus'\n }\n | {\n type: 'insert.block object'\n placement: 'auto' | 'after' | 'before'\n blockObject: {\n name: string\n value?: {[prop: string]: unknown}\n }\n }\n | {\n type: 'insert.inline object'\n inlineObject: {\n name: string\n value?: {[prop: string]: unknown}\n }\n }\n | {\n type: 'insert.break'\n }\n | {\n type: 'insert.soft break'\n }\n | {\n type: 'insert.text'\n text: string\n options?: TextInsertTextOptions\n }\n | {\n type: 'list item.toggle'\n listItem: string\n }\n | {\n type: 'style.toggle'\n style: string\n }\n\n/**\n * @beta\n */\nexport type NativeBehaviorEvent =\n | {\n type: 'copy'\n data: DataTransfer\n }\n | {\n type: 'key.down'\n keyboardEvent: Pick<\n KeyboardEvent,\n 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n >\n }\n | {\n type: 'key.up'\n keyboardEvent: Pick<\n KeyboardEvent,\n 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n >\n }\n | {\n type: 'paste'\n data: DataTransfer\n }\n\n/**\n * @beta\n */\nexport type BehaviorActionIntend =\n | SyntheticBehaviorEvent\n | {\n type: 'insert.span'\n text: string\n annotations?: Array<{\n name: string\n value: {[prop: string]: unknown}\n }>\n decorators?: Array<string>\n }\n | {\n type: 'insert.text block'\n placement: 'auto' | 'after' | 'before'\n textBlock?: {\n children?: PortableTextTextBlock['children']\n }\n }\n | {\n type: 'list item.add'\n listItem: string\n }\n | {\n type: 'list item.remove'\n listItem: string\n }\n | {\n type: 'move.block'\n at: [KeyedSegment]\n to: [KeyedSegment]\n }\n | {\n type: 'move.block down'\n at: [KeyedSegment]\n }\n | {\n type: 'move.block up'\n at: [KeyedSegment]\n }\n | {\n type: 'noop'\n }\n | {\n type: 'delete.block'\n blockPath: [KeyedSegment]\n }\n | {\n type: 'delete.text'\n anchor: BlockOffset\n focus: BlockOffset\n }\n | {\n type: 'effect'\n effect: () => void\n }\n | {\n type: 'reselect'\n }\n | {\n type: 'select'\n selection: EditorSelection\n }\n | {\n type: 'select.previous block'\n }\n | {\n type: 'select.next block'\n }\n | {\n type: 'style.add'\n style: string\n }\n | {\n type: 'style.remove'\n style: string\n }\n | {\n type: 'text block.set'\n at: [KeyedSegment]\n level?: number\n listItem?: string\n style?: string\n }\n | {\n type: 'text block.unset'\n at: [KeyedSegment]\n props: Array<'level' | 'listItem' | 'style'>\n }\n\n/**\n * @beta\n */\nexport type BehaviorAction = BehaviorActionIntend & {\n editor: PortableTextSlateEditor\n}\n\n/**\n * @beta\n */\nexport type BehaviorEvent = SyntheticBehaviorEvent | NativeBehaviorEvent\n\n/**\n * @beta\n */\nexport type Behavior<\n TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],\n TGuardResponse = true,\n> = {\n /**\n * The internal editor event that triggers this behavior.\n */\n on: TBehaviorEventType\n /**\n * Predicate function that determines if the behavior should be executed.\n * Returning a non-nullable value from the guard will pass the value to the\n * actions and execute them.\n */\n guard?: BehaviorGuard<\n PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,\n TGuardResponse\n >\n /**\n * Array of behavior action sets.\n */\n actions: Array<BehaviorActionIntendSet<TBehaviorEventType, TGuardResponse>>\n}\n\n/**\n * @beta\n */\nexport type BehaviorGuard<\n TBehaviorEvent extends BehaviorEvent,\n TGuardResponse,\n> = ({\n context,\n event,\n}: {\n context: EditorContext\n event: TBehaviorEvent\n}) => TGuardResponse | false\n\n/**\n * @beta\n */\nexport type BehaviorActionIntendSet<\n TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],\n TGuardResponse = true,\n> = (\n {\n context,\n event,\n }: {\n context: EditorContext\n event: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>\n },\n guardResponse: TGuardResponse,\n) => Array<BehaviorActionIntend>\n\n/**\n * @beta\n */\nexport function defineBehavior<\n TAnyBehaviorEventType extends BehaviorEvent['type'],\n TGuardResponse = true,\n>(behavior: Behavior<TAnyBehaviorEventType, TGuardResponse>): Behavior {\n return behavior as unknown as Behavior\n}\n\n/**\n * @beta\n */\nexport type BlockOffset = {\n path: [KeyedSegment]\n offset: number\n}\n","import {isPortableTextTextBlock} from '@sanity/types'\nimport {isEmptyTextBlock} from '../editor/utils/utils'\nimport * as selectors from '../selectors'\nimport {isHotkey} from '../utils/is-hotkey'\nimport {defineBehavior} from './behavior.types'\n\nconst arrowDownOnLonelyBlockObject = defineBehavior({\n on: 'key.down',\n guard: ({context, event}) => {\n const isArrowDown = isHotkey('ArrowDown', event.keyboardEvent)\n const focusBlockObject = selectors.getFocusBlockObject({context})\n const nextBlock = selectors.getNextBlock({context})\n\n return isArrowDown && focusBlockObject && !nextBlock\n },\n actions: [() => [{type: 'insert.text block', placement: 'after'}]],\n})\n\nconst arrowUpOnLonelyBlockObject = defineBehavior({\n on: 'key.down',\n guard: ({context, event}) => {\n const isArrowUp = isHotkey('ArrowUp', event.keyboardEvent)\n const focusBlockObject = selectors.getFocusBlockObject({context})\n const previousBlock = selectors.getPreviousBlock({context})\n\n return isArrowUp && focusBlockObject && !previousBlock\n },\n actions: [\n () => [\n {type: 'insert.text block', placement: 'before'},\n {type: 'select.previous block'},\n ],\n ],\n})\n\nconst breakingBlockObject = defineBehavior({\n on: 'insert.break',\n guard: ({context}) => {\n const focusBlockObject = selectors.getFocusBlockObject({context})\n const collapsedSelection = selectors.isSelectionCollapsed({context})\n\n return collapsedSelection && focusBlockObject !== undefined\n },\n actions: [() => [{type: 'insert.text block', placement: 'after'}]],\n})\n\nconst deletingEmptyTextBlockAfterBlockObject = defineBehavior({\n on: 'delete.backward',\n guard: ({context}) => {\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const previousBlock = selectors.getPreviousBlock({context})\n\n if (!focusTextBlock || !selectionCollapsed || !previousBlock) {\n return false\n }\n\n if (\n isEmptyTextBlock(focusTextBlock.node) &&\n !isPortableTextTextBlock(previousBlock.node)\n ) {\n return {focusTextBlock, previousBlock}\n }\n\n return false\n },\n actions: [\n (_, {focusTextBlock, previousBlock}) => [\n {\n type: 'delete.block',\n blockPath: focusTextBlock.path,\n },\n {\n type: 'select',\n selection: {\n anchor: {path: previousBlock.path, offset: 0},\n focus: {path: previousBlock.path, offset: 0},\n },\n },\n ],\n ],\n})\n\nconst deletingEmptyTextBlockBeforeBlockObject = defineBehavior({\n on: 'delete.forward',\n guard: ({context}) => {\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const nextBlock = selectors.getNextBlock({context})\n\n if (!focusTextBlock || !selectionCollapsed || !nextBlock) {\n return false\n }\n\n if (\n isEmptyTextBlock(focusTextBlock.node) &&\n !isPortableTextTextBlock(nextBlock.node)\n ) {\n return {focusTextBlock, nextBlock}\n }\n\n return false\n },\n actions: [\n (_, {focusTextBlock, nextBlock}) => [\n {\n type: 'delete.block',\n blockPath: focusTextBlock.path,\n },\n {\n type: 'select',\n selection: {\n anchor: {path: nextBlock.path, offset: 0},\n focus: {path: nextBlock.path, offset: 0},\n },\n },\n ],\n ],\n})\n\nexport const coreBlockObjectBehaviors = {\n arrowDownOnLonelyBlockObject,\n arrowUpOnLonelyBlockObject,\n breakingBlockObject,\n deletingEmptyTextBlockAfterBlockObject,\n deletingEmptyTextBlockBeforeBlockObject,\n}\n","import {defineBehavior} from './behavior.types'\n\nconst decoratorAdd = defineBehavior({\n on: 'decorator.add',\n actions: [\n ({event}) => [\n event,\n {\n type: 'reselect',\n },\n ],\n ],\n})\n\nconst decoratorRemove = defineBehavior({\n on: 'decorator.remove',\n guard: ({event}) => ({decorator: event.decorator}),\n actions: [\n ({event}) => [\n event,\n {\n type: 'reselect',\n },\n ],\n ],\n})\n\nconst decoratorToggle = defineBehavior({\n on: 'decorator.toggle',\n guard: ({event}) => ({decorator: event.decorator}),\n actions: [\n ({event}) => [\n event,\n {\n type: 'reselect',\n },\n ],\n ],\n})\n\nexport const coreDecoratorBehaviors = {\n decoratorAdd,\n decoratorRemove,\n decoratorToggle,\n}\n","import {createGuards} from '../behavior-actions/behavior.guards'\nimport {isEmptyTextBlock} from '../editor/utils/utils'\nimport * as selectors from '../selectors'\nimport {isHotkey} from '../utils/is-hotkey'\nimport {defineBehavior} from './behavior.types'\n\nconst MAX_LIST_LEVEL = 10\n\nconst clearListOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({context}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n context.selection?.focus.offset === 0\n\n if (atTheBeginningOfBLock && focusTextBlock.node.level === 1) {\n return {focusTextBlock}\n }\n\n return false\n },\n actions: [\n (_, {focusTextBlock}) => [\n {\n type: 'text block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n },\n ],\n ],\n})\n\nconst unindentListOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({context}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n context.selection?.focus.offset === 0\n\n if (\n atTheBeginningOfBLock &&\n focusTextBlock.node.level !== undefined &&\n focusTextBlock.node.level > 1\n ) {\n return {focusTextBlock, level: focusTextBlock.node.level - 1}\n }\n\n return false\n },\n actions: [\n (_, {focusTextBlock, level}) => [\n {\n type: 'text block.set',\n level,\n at: focusTextBlock.path,\n },\n ],\n ],\n})\n\nconst clearListOnEnter = defineBehavior({\n on: 'insert.break',\n guard: ({context}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusListBlock = selectors.getFocusListBlock({context})\n\n if (\n !selectionCollapsed ||\n !focusListBlock ||\n !isEmptyTextBlock(focusListBlock.node)\n ) {\n return false\n }\n\n return {focusListBlock}\n },\n actions: [\n (_, {focusListBlock}) => [\n {\n type: 'text block.unset',\n props: ['listItem', 'level'],\n at: focusListBlock.path,\n },\n ],\n ],\n})\n\nconst indentListOnTab = defineBehavior({\n on: 'key.down',\n guard: ({context, event}) => {\n const isTab = isHotkey('Tab', event.keyboardEvent)\n\n if (!isTab) {\n return false\n }\n\n const selectedBlocks = selectors.getSelectedBlocks({context})\n const guards = createGuards(context)\n const selectedListBlocks = selectedBlocks.flatMap((block) =>\n guards.isListBlock(block.node)\n ? [\n {\n node: block.node,\n path: block.path,\n },\n ]\n : [],\n )\n\n if (selectedListBlocks.length === selectedBlocks.length) {\n return {selectedListBlocks}\n }\n\n return false\n },\n actions: [\n (_, {selectedListBlocks}) =>\n selectedListBlocks.map((selectedListBlock) => ({\n type: 'text block.set',\n level: Math.min(\n MAX_LIST_LEVEL,\n Math.max(1, selectedListBlock.node.level + 1),\n ),\n at: selectedListBlock.path,\n })),\n ],\n})\n\nconst unindentListOnShiftTab = defineBehavior({\n on: 'key.down',\n guard: ({context, event}) => {\n const isShiftTab = isHotkey('Shift+Tab', event.keyboardEvent)\n\n if (!isShiftTab) {\n return false\n }\n\n const selectedBlocks = selectors.getSelectedBlocks({context})\n const guards = createGuards(context)\n const selectedListBlocks = selectedBlocks.flatMap((block) =>\n guards.isListBlock(block.node)\n ? [\n {\n node: block.node,\n path: block.path,\n },\n ]\n : [],\n )\n\n if (selectedListBlocks.length === selectedBlocks.length) {\n return {selectedListBlocks}\n }\n\n return false\n },\n actions: [\n (_, {selectedListBlocks}) =>\n selectedListBlocks.map((selectedListBlock) => ({\n type: 'text block.set',\n level: Math.min(\n MAX_LIST_LEVEL,\n Math.max(1, selectedListBlock.node.level - 1),\n ),\n at: selectedListBlock.path,\n })),\n ],\n})\n\nexport const coreListBehaviors = {\n clearListOnBackspace,\n unindentListOnBackspace,\n clearListOnEnter,\n indentListOnTab,\n unindentListOnShiftTab,\n}\n","import {coreBlockObjectBehaviors} from './behavior.core.block-objects'\nimport {coreDecoratorBehaviors} from './behavior.core.decorators'\nimport {coreListBehaviors} from './behavior.core.lists'\nimport {defineBehavior} from './behavior.types'\n\nconst softReturn = defineBehavior({\n on: 'insert.soft break',\n actions: [() => [{type: 'insert.text', text: '\\n'}]],\n})\n\n/**\n * @beta\n */\nexport const coreBehaviors = [\n softReturn,\n coreDecoratorBehaviors.decoratorAdd,\n coreDecoratorBehaviors.decoratorRemove,\n coreDecoratorBehaviors.decoratorToggle,\n coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject,\n coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject,\n coreBlockObjectBehaviors.breakingBlockObject,\n coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject,\n coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject,\n coreListBehaviors.clearListOnBackspace,\n coreListBehaviors.unindentListOnBackspace,\n coreListBehaviors.clearListOnEnter,\n coreListBehaviors.indentListOnTab,\n coreListBehaviors.unindentListOnShiftTab,\n]\n\n/**\n * @beta\n */\nexport const coreBehavior = {\n softReturn,\n decorators: coreDecoratorBehaviors,\n blockObjects: coreBlockObjectBehaviors,\n lists: coreListBehaviors,\n}\n"],"names":["blockOffsetToSpanSelectionPoint","value","blockOffset","offsetLeft","offset","selectionPoint","block","_key","path","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","spanSelectionPointToBlockOffset","isEmptyTextBlock","onlyText","every","blockText","getTextBlockText","map","join","IS_MAC","window","test","navigator","userAgent","modifiers","alt","control","meta","shift","aliases","add","break","cmd","command","ctl","ctrl","del","down","esc","ins","left","mod","opt","option","return","right","space","spacebar","up","win","windows","keyCodes","isHotkey","hotkey","event","compareHotkey","parseHotkey","parsedHotkey","altKey","ctrlKey","metaKey","shiftKey","hotkeySegments","replace","split","rawHotkeySegment","optional","endsWith","hotkeySegment","slice","keyName","toKeyName","modifier","alias","code","undefined","TypeError","key","keyCode","toKeyCode","toLowerCase","name","toUpperCase","charCodeAt","defineBehavior","behavior","arrowDownOnLonelyBlockObject","on","guard","context","isArrowDown","keyboardEvent","focusBlockObject","selectors","nextBlock","actions","type","placement","arrowUpOnLonelyBlockObject","isArrowUp","previousBlock","breakingBlockObject","deletingEmptyTextBlockAfterBlockObject","focusTextBlock","selectionCollapsed","node","_","blockPath","selection","anchor","focus","deletingEmptyTextBlockBeforeBlockObject","coreBlockObjectBehaviors","decoratorAdd","decoratorRemove","decorator","decoratorToggle","coreDecoratorBehaviors","MAX_LIST_LEVEL","clearListOnBackspace","focusSpan","level","props","at","unindentListOnBackspace","clearListOnEnter","focusListBlock","indentListOnTab","selectedBlocks","guards","createGuards","selectedListBlocks","flatMap","isListBlock","selectedListBlock","Math","min","max","unindentListOnShiftTab","coreListBehaviors","softReturn","coreBehaviors","coreBehavior","decorators","blockObjects","lists"],"mappings":";;AAQO,SAASA,gCAAgC;AAAA,EAC9CC;AAAAA,EACAC;AAIF,GAAG;AACGC,MAAAA,aAAaD,YAAYE,QACzBC;AAIJ,aAAWC,SAASL;AACdK,QAAAA,MAAMC,SAASL,YAAYM,KAAK,CAAC,EAAED,QAIlCE,8BAAwBH,KAAK;AAIlC,iBAAWI,SAASJ,MAAMK;AACnBC,YAAAA,MAAAA,mBAAmBF,KAAK,GAI7B;AAAA,cAAIP,eAAe,GAAG;AACH,6BAAA;AAAA,cACfK,MAAM,CAAC,GAAGN,YAAYM,MAAM,YAAY;AAAA,gBAACD,MAAMG,MAAMH;AAAAA,cAAAA,CAAK;AAAA,cAC1DH,QAAQ;AAAA,YACV;AACA;AAAA,UAAA;AAGED,cAAAA,cAAcO,MAAMG,KAAKC,QAAQ;AAClB,6BAAA;AAAA,cACfN,MAAM,CAAC,GAAGN,YAAYM,MAAM,YAAY;AAAA,gBAACD,MAAMG,MAAMH;AAAAA,cAAAA,CAAK;AAAA,cAC1DH,QAAQD;AAAAA,YACV;AACA;AAAA,UAAA;AAGFA,wBAAcO,MAAMG,KAAKC;AAAAA,QAAAA;AAAAA;AAItBT,SAAAA;AACT;AAEO,SAASU,gCAAgC;AAAA,EAC9Cd;AAAAA,EACAI;AAOF,GAA4B;AAC1B,MAAID,SAAS;AAEb,aAAWE,SAASL;AACdK,QAAAA,MAAMC,SAASF,eAAeG,KAAK,CAAC,EAAED,QAIrCE,8BAAwBH,KAAK;AAIlC,iBAAWI,SAASJ,MAAMK;AACnBC,YAAAA,MAAAA,mBAAmBF,KAAK,GAI7B;AAAA,cAAIA,MAAMH,SAASF,eAAeG,KAAK,CAAC,EAAED;AACjC,mBAAA;AAAA,cACLC,MAAM,CAAC;AAAA,gBAACD,MAAMD,MAAMC;AAAAA,cAAAA,CAAK;AAAA,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ACNyB,OAAOc,KAAKC,IACVlB,gBACAiB,KAAKE,IAAI,GAAGH,kBAAkB7B,KAAKgB,QAAQ,CAAC,CAC9C;AAAA,IACAE,IAAIW,kBAAkBlI;AAAAA,EAAAA,EACtB,CAAC;AAET,GAEauI,oBAAoB;AAAA,EAC/BpB;AAAAA,EACAK;AAAAA,EACAC;AAAAA,EACAE;AAAAA,EACAW;AACF,GC1LME,aAA4B;AAAA,EAChCrD,IAAI;AAAA,EACJQ,SAAS,CAAC,MAAM,CAAC;AAAA,IAACC,MAAM;AAAA,IAAevF,MAAM;AAAA;AAAA,EAAA,CAAK,CAAC;AACrD,GAKaoI,gBAAgB,CAC3BD,YACAvB,uBAAuBJ,cACvBI,uBAAuBH,iBACvBG,uBAAuBD,iBACvBJ,yBAAyB1B,8BACzB0B,yBAAyBd,4BACzBc,yBAAyBX,qBACzBW,yBAAyBV,wCACzBU,yBAAyBD,yCACzB4B,kBAAkBpB,sBAClBoB,kBAAkBf,yBAClBe,kBAAkBd,kBAClBc,kBAAkBZ,iBAClBY,kBAAkBD,sBAAsB,GAM7BI,eAAe;AAAA,EAC1BF;AAAAA,EACAG,YAAY1B;AAAAA,EACZ2B,cAAchC;AAAAA,EACdiC,OAAON;AACT;;;;;;;;"}
1
+ {"version":3,"file":"behavior.core.cjs","sources":["../../src/editor/utils/utils.block-offset.ts","../../src/editor/utils/utils.ts","../../src/utils/is-hotkey.ts","../../src/behaviors/behavior.types.ts","../../src/behaviors/behavior.core.block-objects.ts","../../src/behaviors/behavior.core.decorators.ts","../../src/behaviors/behavior.core.lists.ts","../../src/behaviors/behavior.core.ts"],"sourcesContent":["import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../../behaviors/behavior.types'\n\nexport function blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n\n for (const block of value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (offsetLeft === 0) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n break\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n }\n }\n\n return selectionPoint\n}\n\nexport function spanSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: {\n path: [KeyedSegment, 'children', KeyedSegment]\n offset: number\n }\n}): BlockOffset | undefined {\n let offset = 0\n\n for (const block of value) {\n if (block._key !== selectionPoint.path[0]._key) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (child._key === selectionPoint.path[2]._key) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\n\nexport function isEmptyTextBlock(block: PortableTextBlock) {\n if (!isPortableTextTextBlock(block)) {\n return false\n }\n\n const onlyText = block.children.every(isPortableTextSpan)\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","export interface KeyboardEventLike {\n key: string\n keyCode?: number\n altKey: boolean\n ctrlKey: boolean\n metaKey: boolean\n shiftKey: boolean\n}\n\ninterface HotKey {\n keyCode?: number | undefined\n key?: string | undefined\n altKey: boolean | null\n ctrlKey: boolean | null\n metaKey: boolean | null\n shiftKey: boolean | null\n}\n\nconst IS_MAC =\n typeof window !== 'undefined' &&\n /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent)\n\ntype Modifier = 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n\nconst modifiers: Record<string, Modifier | undefined> = {\n alt: 'altKey',\n control: 'ctrlKey',\n meta: 'metaKey',\n shift: 'shiftKey',\n}\n\nconst aliases: Record<string, string | undefined> = {\n add: '+',\n break: 'pause',\n cmd: 'meta',\n command: 'meta',\n ctl: 'control',\n ctrl: 'control',\n del: 'delete',\n down: 'arrowdown',\n esc: 'escape',\n ins: 'insert',\n left: 'arrowleft',\n mod: IS_MAC ? 'meta' : 'control',\n opt: 'alt',\n option: 'alt',\n return: 'enter',\n right: 'arrowright',\n space: ' ',\n spacebar: ' ',\n up: 'arrowup',\n win: 'meta',\n windows: 'meta',\n}\n\nconst keyCodes: Record<string, number | undefined> = {\n 'backspace': 8,\n 'tab': 9,\n 'enter': 13,\n 'shift': 16,\n 'control': 17,\n 'alt': 18,\n 'pause': 19,\n 'capslock': 20,\n 'escape': 27,\n ' ': 32,\n 'pageup': 33,\n 'pagedown': 34,\n 'end': 35,\n 'home': 36,\n 'arrowleft': 37,\n 'arrowup': 38,\n 'arrowright': 39,\n 'arrowdown': 40,\n 'insert': 45,\n 'delete': 46,\n 'meta': 91,\n 'numlock': 144,\n 'scrolllock': 145,\n ';': 186,\n '=': 187,\n ',': 188,\n '-': 189,\n '.': 190,\n '/': 191,\n '`': 192,\n '[': 219,\n '\\\\': 220,\n ']': 221,\n \"'\": 222,\n 'f1': 112,\n 'f2': 113,\n 'f3': 114,\n 'f4': 115,\n 'f5': 116,\n 'f6': 117,\n 'f7': 118,\n 'f8': 119,\n 'f9': 120,\n 'f10': 121,\n 'f11': 122,\n 'f12': 123,\n 'f13': 124,\n 'f14': 125,\n 'f15': 126,\n 'f16': 127,\n 'f17': 128,\n 'f18': 129,\n 'f19': 130,\n 'f20': 131,\n}\n\nexport function isHotkey(hotkey: string, event: KeyboardEventLike): boolean {\n return compareHotkey(parseHotkey(hotkey), event)\n}\n\nfunction parseHotkey(hotkey: string): HotKey {\n // Ensure that all the modifiers are set to false unless the hotkey has them.\n const parsedHotkey: HotKey = {\n altKey: false,\n ctrlKey: false,\n metaKey: false,\n shiftKey: false,\n }\n\n // Special case to handle the `+` key since we use it as a separator.\n const hotkeySegments = hotkey.replace('++', '+add').split('+')\n\n for (const rawHotkeySegment of hotkeySegments) {\n const optional =\n rawHotkeySegment.endsWith('?') && rawHotkeySegment.length > 1\n const hotkeySegment = optional\n ? rawHotkeySegment.slice(0, -1)\n : rawHotkeySegment\n const keyName = toKeyName(hotkeySegment)\n const modifier = modifiers[keyName]\n const alias = aliases[hotkeySegment]\n const code = keyCodes[keyName]\n\n if (\n hotkeySegment.length > 1 &&\n modifier === undefined &&\n alias === undefined &&\n code === undefined\n ) {\n throw new TypeError(`Unknown modifier: \"${hotkeySegment}\"`)\n }\n\n if (hotkeySegments.length === 1 || modifier === undefined) {\n parsedHotkey.key = keyName\n parsedHotkey.keyCode = toKeyCode(hotkeySegment)\n }\n\n if (modifier !== undefined) {\n parsedHotkey[modifier] = optional ? null : true\n }\n }\n\n return parsedHotkey\n}\n\nfunction compareHotkey(\n parsedHotkey: HotKey,\n event: KeyboardEventLike,\n): boolean {\n const matchingModifiers =\n (parsedHotkey.altKey != null\n ? parsedHotkey.altKey === event.altKey\n : true) &&\n (parsedHotkey.ctrlKey != null\n ? parsedHotkey.ctrlKey === event.ctrlKey\n : true) &&\n (parsedHotkey.metaKey != null\n ? parsedHotkey.metaKey === event.metaKey\n : true) &&\n (parsedHotkey.shiftKey != null\n ? parsedHotkey.shiftKey === event.shiftKey\n : true)\n\n if (!matchingModifiers) {\n return false\n }\n\n if (parsedHotkey.keyCode !== undefined && event.keyCode !== undefined) {\n if (parsedHotkey.keyCode === 91 && event.keyCode === 93) {\n return true\n }\n\n return parsedHotkey.keyCode === event.keyCode\n }\n\n return (\n parsedHotkey.keyCode === event.keyCode ||\n parsedHotkey.key === event.key.toLowerCase()\n )\n}\n\nfunction toKeyCode(name: string): number {\n const keyName = toKeyName(name)\n const keyCode = keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0)\n\n return keyCode\n}\n\nfunction toKeyName(name: string): string {\n const keyName = name.toLowerCase()\n\n return aliases[keyName] ?? keyName\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {TextUnit} from 'slate'\nimport type {TextInsertTextOptions} from 'slate/dist/interfaces/transforms/text'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {OmitFromUnion, PickFromUnion} from '../type-utils'\nimport type {EditorSelection, PortableTextSlateEditor} from '../types/editor'\n\n/**\n * @beta\n */\nexport type SyntheticBehaviorEvent =\n | {\n type: 'annotation.add'\n annotation: {\n name: string\n value: {[prop: string]: unknown}\n }\n }\n | {\n type: 'annotation.remove'\n annotation: {\n name: string\n }\n }\n | {\n type: 'blur'\n }\n | {\n type: 'decorator.toggle'\n decorator: string\n }\n | {\n type: 'delete.backward'\n unit: TextUnit\n }\n | {\n type: 'delete.forward'\n unit: TextUnit\n }\n | {\n type: 'focus'\n }\n | {\n type: 'insert.block object'\n placement: 'auto' | 'after' | 'before'\n blockObject: {\n name: string\n value?: {[prop: string]: unknown}\n }\n }\n | {\n type: 'insert.inline object'\n inlineObject: {\n name: string\n value?: {[prop: string]: unknown}\n }\n }\n | {\n type: 'insert.break'\n }\n | {\n type: 'insert.soft break'\n }\n | {\n type: 'insert.text'\n text: string\n options?: TextInsertTextOptions\n }\n | {\n type: 'list item.toggle'\n listItem: string\n }\n | {\n type: 'select'\n selection: EditorSelection\n }\n | {\n type: 'style.toggle'\n style: string\n }\n\n/**\n * @beta\n */\nexport type NativeBehaviorEvent =\n | {\n type: 'copy'\n data: DataTransfer\n }\n | {\n type: 'key.down'\n keyboardEvent: Pick<\n KeyboardEvent,\n 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n >\n }\n | {\n type: 'key.up'\n keyboardEvent: Pick<\n KeyboardEvent,\n 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n >\n }\n | {\n type: 'paste'\n data: DataTransfer\n }\n\n/**\n * @beta\n */\nexport type BehaviorActionIntend =\n | SyntheticBehaviorEvent\n | {\n type: 'raise'\n event: SyntheticBehaviorEvent\n }\n | {\n type: 'annotation.toggle'\n annotation: {\n name: string\n value: {[prop: string]: unknown}\n }\n }\n | {\n type: 'decorator.add'\n decorator: string\n }\n | {\n type: 'decorator.remove'\n decorator: string\n }\n | {\n type: 'insert.span'\n text: string\n annotations?: Array<{\n name: string\n value: {[prop: string]: unknown}\n }>\n decorators?: Array<string>\n }\n | {\n type: 'insert.text block'\n placement: 'auto' | 'after' | 'before'\n textBlock?: {\n children?: PortableTextTextBlock['children']\n }\n }\n | {\n type: 'list item.add'\n listItem: string\n }\n | {\n type: 'list item.remove'\n listItem: string\n }\n | {\n type: 'move.block'\n at: [KeyedSegment]\n to: [KeyedSegment]\n }\n | {\n type: 'move.block down'\n at: [KeyedSegment]\n }\n | {\n type: 'move.block up'\n at: [KeyedSegment]\n }\n | {\n type: 'noop'\n }\n | {\n type: 'delete.block'\n blockPath: [KeyedSegment]\n }\n | {\n type: 'delete.text'\n anchor: BlockOffset\n focus: BlockOffset\n }\n | {\n type: 'effect'\n effect: () => void\n }\n | {\n type: 'select.previous block'\n }\n | {\n type: 'select.next block'\n }\n | {\n type: 'style.add'\n style: string\n }\n | {\n type: 'style.remove'\n style: string\n }\n | {\n type: 'text block.set'\n at: [KeyedSegment]\n level?: number\n listItem?: string\n style?: string\n }\n | {\n type: 'text block.unset'\n at: [KeyedSegment]\n props: Array<'level' | 'listItem' | 'style'>\n }\n\n/**\n * @beta\n */\nexport type BehaviorAction = OmitFromUnion<\n BehaviorActionIntend,\n 'type',\n 'raise'\n> & {\n editor: PortableTextSlateEditor\n}\n\n/**\n * @beta\n */\nexport function raise(\n event: SyntheticBehaviorEvent,\n): PickFromUnion<BehaviorActionIntend, 'type', 'raise'> {\n return {type: 'raise', event}\n}\n\n/**\n * @beta\n */\nexport type BehaviorEvent = SyntheticBehaviorEvent | NativeBehaviorEvent\n\n/**\n * @beta\n */\nexport type Behavior<\n TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],\n TGuardResponse = true,\n> = {\n /**\n * The internal editor event that triggers this behavior.\n */\n on: TBehaviorEventType\n /**\n * Predicate function that determines if the behavior should be executed.\n * Returning a non-nullable value from the guard will pass the value to the\n * actions and execute them.\n */\n guard?: BehaviorGuard<\n PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,\n TGuardResponse\n >\n /**\n * Array of behavior action sets.\n */\n actions: Array<BehaviorActionIntendSet<TBehaviorEventType, TGuardResponse>>\n}\n\n/**\n * @beta\n */\nexport type BehaviorGuard<\n TBehaviorEvent extends BehaviorEvent,\n TGuardResponse,\n> = ({\n context,\n event,\n}: {\n context: EditorContext\n event: TBehaviorEvent\n}) => TGuardResponse | false\n\n/**\n * @beta\n */\nexport type BehaviorActionIntendSet<\n TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],\n TGuardResponse = true,\n> = (\n {\n context,\n event,\n }: {\n context: EditorContext\n event: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>\n },\n guardResponse: TGuardResponse,\n) => Array<BehaviorActionIntend>\n\n/**\n * @beta\n */\nexport function defineBehavior<\n TBehaviorEventType extends BehaviorEvent['type'],\n TGuardResponse = true,\n>(behavior: Behavior<TBehaviorEventType, TGuardResponse>): Behavior {\n return behavior as unknown as Behavior\n}\n\n/**\n * @beta\n */\nexport type BlockOffset = {\n path: [KeyedSegment]\n offset: number\n}\n","import {isPortableTextTextBlock} from '@sanity/types'\nimport {isEmptyTextBlock} from '../editor/utils/utils'\nimport * as selectors from '../selectors'\nimport {isHotkey} from '../utils/is-hotkey'\nimport {defineBehavior} from './behavior.types'\n\nconst arrowDownOnLonelyBlockObject = defineBehavior({\n on: 'key.down',\n guard: ({context, event}) => {\n const isArrowDown = isHotkey('ArrowDown', event.keyboardEvent)\n const focusBlockObject = selectors.getFocusBlockObject({context})\n const nextBlock = selectors.getNextBlock({context})\n\n return isArrowDown && focusBlockObject && !nextBlock\n },\n actions: [() => [{type: 'insert.text block', placement: 'after'}]],\n})\n\nconst arrowUpOnLonelyBlockObject = defineBehavior({\n on: 'key.down',\n guard: ({context, event}) => {\n const isArrowUp = isHotkey('ArrowUp', event.keyboardEvent)\n const focusBlockObject = selectors.getFocusBlockObject({context})\n const previousBlock = selectors.getPreviousBlock({context})\n\n return isArrowUp && focusBlockObject && !previousBlock\n },\n actions: [\n () => [\n {type: 'insert.text block', placement: 'before'},\n {type: 'select.previous block'},\n ],\n ],\n})\n\nconst breakingBlockObject = defineBehavior({\n on: 'insert.break',\n guard: ({context}) => {\n const focusBlockObject = selectors.getFocusBlockObject({context})\n const collapsedSelection = selectors.isSelectionCollapsed({context})\n\n return collapsedSelection && focusBlockObject !== undefined\n },\n actions: [() => [{type: 'insert.text block', placement: 'after'}]],\n})\n\nconst deletingEmptyTextBlockAfterBlockObject = defineBehavior({\n on: 'delete.backward',\n guard: ({context}) => {\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const previousBlock = selectors.getPreviousBlock({context})\n\n if (!focusTextBlock || !selectionCollapsed || !previousBlock) {\n return false\n }\n\n if (\n isEmptyTextBlock(focusTextBlock.node) &&\n !isPortableTextTextBlock(previousBlock.node)\n ) {\n return {focusTextBlock, previousBlock}\n }\n\n return false\n },\n actions: [\n (_, {focusTextBlock, previousBlock}) => [\n {\n type: 'delete.block',\n blockPath: focusTextBlock.path,\n },\n {\n type: 'select',\n selection: {\n anchor: {path: previousBlock.path, offset: 0},\n focus: {path: previousBlock.path, offset: 0},\n },\n },\n ],\n ],\n})\n\nconst deletingEmptyTextBlockBeforeBlockObject = defineBehavior({\n on: 'delete.forward',\n guard: ({context}) => {\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const nextBlock = selectors.getNextBlock({context})\n\n if (!focusTextBlock || !selectionCollapsed || !nextBlock) {\n return false\n }\n\n if (\n isEmptyTextBlock(focusTextBlock.node) &&\n !isPortableTextTextBlock(nextBlock.node)\n ) {\n return {focusTextBlock, nextBlock}\n }\n\n return false\n },\n actions: [\n (_, {focusTextBlock, nextBlock}) => [\n {\n type: 'delete.block',\n blockPath: focusTextBlock.path,\n },\n {\n type: 'select',\n selection: {\n anchor: {path: nextBlock.path, offset: 0},\n focus: {path: nextBlock.path, offset: 0},\n },\n },\n ],\n ],\n})\n\nexport const coreBlockObjectBehaviors = {\n arrowDownOnLonelyBlockObject,\n arrowUpOnLonelyBlockObject,\n breakingBlockObject,\n deletingEmptyTextBlockAfterBlockObject,\n deletingEmptyTextBlockBeforeBlockObject,\n}\n","import {isHotkey} from '../utils/is-hotkey'\nimport {defineBehavior, raise} from './behavior.types'\n\nexport const coreDecoratorBehaviors = {\n strongShortcut: defineBehavior({\n on: 'key.down',\n guard: ({context, event}) =>\n isHotkey('mod+b', event.keyboardEvent) &&\n context.schema.decorators.some(\n (decorator) => decorator.value === 'strong',\n ),\n actions: [() => [raise({type: 'decorator.toggle', decorator: 'strong'})]],\n }),\n emShortcut: defineBehavior({\n on: 'key.down',\n guard: ({context, event}) =>\n isHotkey('mod+i', event.keyboardEvent) &&\n context.schema.decorators.some((decorator) => decorator.value === 'em'),\n actions: [() => [raise({type: 'decorator.toggle', decorator: 'em'})]],\n }),\n underlineShortcut: defineBehavior({\n on: 'key.down',\n guard: ({context, event}) =>\n isHotkey('mod+u', event.keyboardEvent) &&\n context.schema.decorators.some(\n (decorator) => decorator.value === 'underline',\n ),\n actions: [\n () => [raise({type: 'decorator.toggle', decorator: 'underline'})],\n ],\n }),\n codeShortcut: defineBehavior({\n on: 'key.down',\n guard: ({context, event}) =>\n isHotkey(\"mod+'\", event.keyboardEvent) &&\n context.schema.decorators.some((decorator) => decorator.value === 'code'),\n actions: [() => [raise({type: 'decorator.toggle', decorator: 'code'})]],\n }),\n}\n","import {createGuards} from '../behavior-actions/behavior.guards'\nimport {isEmptyTextBlock} from '../editor/utils/utils'\nimport * as selectors from '../selectors'\nimport {isHotkey} from '../utils/is-hotkey'\nimport {defineBehavior} from './behavior.types'\n\nconst MAX_LIST_LEVEL = 10\n\nconst clearListOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({context}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n context.selection?.focus.offset === 0\n\n if (atTheBeginningOfBLock && focusTextBlock.node.level === 1) {\n return {focusTextBlock}\n }\n\n return false\n },\n actions: [\n (_, {focusTextBlock}) => [\n {\n type: 'text block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n },\n ],\n ],\n})\n\nconst unindentListOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({context}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const focusSpan = selectors.getFocusSpan({context})\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n context.selection?.focus.offset === 0\n\n if (\n atTheBeginningOfBLock &&\n focusTextBlock.node.level !== undefined &&\n focusTextBlock.node.level > 1\n ) {\n return {focusTextBlock, level: focusTextBlock.node.level - 1}\n }\n\n return false\n },\n actions: [\n (_, {focusTextBlock, level}) => [\n {\n type: 'text block.set',\n level,\n at: focusTextBlock.path,\n },\n ],\n ],\n})\n\nconst clearListOnEnter = defineBehavior({\n on: 'insert.break',\n guard: ({context}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed({context})\n const focusListBlock = selectors.getFocusListBlock({context})\n\n if (\n !selectionCollapsed ||\n !focusListBlock ||\n !isEmptyTextBlock(focusListBlock.node)\n ) {\n return false\n }\n\n return {focusListBlock}\n },\n actions: [\n (_, {focusListBlock}) => [\n {\n type: 'text block.unset',\n props: ['listItem', 'level'],\n at: focusListBlock.path,\n },\n ],\n ],\n})\n\nconst indentListOnTab = defineBehavior({\n on: 'key.down',\n guard: ({context, event}) => {\n const isTab = isHotkey('Tab', event.keyboardEvent)\n\n if (!isTab) {\n return false\n }\n\n const selectedBlocks = selectors.getSelectedBlocks({context})\n const guards = createGuards(context)\n const selectedListBlocks = selectedBlocks.flatMap((block) =>\n guards.isListBlock(block.node)\n ? [\n {\n node: block.node,\n path: block.path,\n },\n ]\n : [],\n )\n\n if (selectedListBlocks.length === selectedBlocks.length) {\n return {selectedListBlocks}\n }\n\n return false\n },\n actions: [\n (_, {selectedListBlocks}) =>\n selectedListBlocks.map((selectedListBlock) => ({\n type: 'text block.set',\n level: Math.min(\n MAX_LIST_LEVEL,\n Math.max(1, selectedListBlock.node.level + 1),\n ),\n at: selectedListBlock.path,\n })),\n ],\n})\n\nconst unindentListOnShiftTab = defineBehavior({\n on: 'key.down',\n guard: ({context, event}) => {\n const isShiftTab = isHotkey('Shift+Tab', event.keyboardEvent)\n\n if (!isShiftTab) {\n return false\n }\n\n const selectedBlocks = selectors.getSelectedBlocks({context})\n const guards = createGuards(context)\n const selectedListBlocks = selectedBlocks.flatMap((block) =>\n guards.isListBlock(block.node)\n ? [\n {\n node: block.node,\n path: block.path,\n },\n ]\n : [],\n )\n\n if (selectedListBlocks.length === selectedBlocks.length) {\n return {selectedListBlocks}\n }\n\n return false\n },\n actions: [\n (_, {selectedListBlocks}) =>\n selectedListBlocks.map((selectedListBlock) => ({\n type: 'text block.set',\n level: Math.min(\n MAX_LIST_LEVEL,\n Math.max(1, selectedListBlock.node.level - 1),\n ),\n at: selectedListBlock.path,\n })),\n ],\n})\n\nexport const coreListBehaviors = {\n clearListOnBackspace,\n unindentListOnBackspace,\n clearListOnEnter,\n indentListOnTab,\n unindentListOnShiftTab,\n}\n","import {coreBlockObjectBehaviors} from './behavior.core.block-objects'\nimport {coreDecoratorBehaviors} from './behavior.core.decorators'\nimport {coreListBehaviors} from './behavior.core.lists'\nimport {defineBehavior} from './behavior.types'\n\nconst softReturn = defineBehavior({\n on: 'insert.soft break',\n actions: [() => [{type: 'insert.text', text: '\\n'}]],\n})\n\n/**\n * @beta\n */\nexport const coreBehaviors = [\n softReturn,\n coreDecoratorBehaviors.strongShortcut,\n coreDecoratorBehaviors.emShortcut,\n coreDecoratorBehaviors.underlineShortcut,\n coreDecoratorBehaviors.codeShortcut,\n coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject,\n coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject,\n coreBlockObjectBehaviors.breakingBlockObject,\n coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject,\n coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject,\n coreListBehaviors.clearListOnBackspace,\n coreListBehaviors.unindentListOnBackspace,\n coreListBehaviors.clearListOnEnter,\n coreListBehaviors.indentListOnTab,\n coreListBehaviors.unindentListOnShiftTab,\n]\n\n/**\n * @beta\n */\nexport const coreBehavior = {\n softReturn,\n decorators: coreDecoratorBehaviors,\n blockObjects: coreBlockObjectBehaviors,\n lists: coreListBehaviors,\n}\n"],"names":["blockOffsetToSpanSelectionPoint","value","blockOffset","offsetLeft","offset","selectionPoint","block","_key","path","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","spanSelectionPointToBlockOffset","isEmptyTextBlock","onlyText","every","blockText","getTextBlockText","map","join","IS_MAC","window","test","navigator","userAgent","modifiers","alt","control","meta","shift","aliases","add","break","cmd","command","ctl","ctrl","del","down","esc","ins","left","mod","opt","option","return","right","space","spacebar","up","win","windows","keyCodes","isHotkey","hotkey","event","compareHotkey","parseHotkey","parsedHotkey","altKey","ctrlKey","metaKey","shiftKey","hotkeySegments","replace","split","rawHotkeySegment","optional","endsWith","hotkeySegment","slice","keyName","toKeyName","modifier","alias","code","undefined","TypeError","key","keyCode","toKeyCode","toLowerCase","name","toUpperCase","charCodeAt","raise","type","defineBehavior","behavior","arrowDownOnLonelyBlockObject","on","guard","context","isArrowDown","keyboardEvent","focusBlockObject","selectors","nextBlock","actions","placement","arrowUpOnLonelyBlockObject","isArrowUp","previousBlock","breakingBlockObject","deletingEmptyTextBlockAfterBlockObject","focusTextBlock","selectionCollapsed","node","_","blockPath","selection","anchor","focus","deletingEmptyTextBlockBeforeBlockObject","coreBlockObjectBehaviors","coreDecoratorBehaviors","strongShortcut","schema","decorators","some","decorator","emShortcut","underlineShortcut","codeShortcut","MAX_LIST_LEVEL","clearListOnBackspace","focusSpan","level","props","at","unindentListOnBackspace","clearListOnEnter","focusListBlock","indentListOnTab","selectedBlocks","guards","createGuards","selectedListBlocks","flatMap","isListBlock","selectedListBlock","Math","min","max","unindentListOnShiftTab","coreListBehaviors","softReturn","coreBehaviors","coreBehavior","blockObjects","lists"],"mappings":";;AAQO,SAASA,gCAAgC;AAAA,EAC9CC;AAAAA,EACAC;AAIF,GAAG;AACGC,MAAAA,aAAaD,YAAYE,QACzBC;AAIJ,aAAWC,SAASL;AACdK,QAAAA,MAAMC,SAASL,YAAYM,KAAK,CAAC,EAAED,QAIlCE,8BAAwBH,KAAK;AAIlC,iBAAWI,SAASJ,MAAMK;AACnBC,YAAAA,MAAAA,mBAAmBF,KAAK,GAI7B;AAAA,cAAIP,eAAe,GAAG;AACH,6BAAA;AAAA,cACfK,MAAM,CAAC,GAAGN,YAAYM,MAAM,YAAY;AAAA,gBAACD,MAAMG,MAAMH;AAAAA,cAAAA,CAAK;AAAA,cAC1DH,QAAQ;AAAA,YACV;AACA;AAAA,UAAA;AAGED,cAAA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9H,WAAW2H,eAAe3H,SACxC;AAAA,MAAC8H;AAAAA,IAAAA,IAGH;AAAA,EACT;AAAA,EACAvC,SAAS,CACP,CAACU,GAAG;AAAA,IAAC6B;AAAAA,EAAAA,MACHA,mBAAmBvH,IAAK0H,CAAuB,uBAAA;AAAA,IAC7CtD,MAAM;AAAA,IACNyC,OAAOc,KAAKC,IACVlB,gBACAiB,KAAKE,IAAI,GAAGH,kBAAkBjC,KAAKoB,QAAQ,CAAC,CAC9C;AAAA,IACAE,IAAIW,kBAAkBvI;AAAAA,EAAAA,EACtB,CAAC;AAET,GAEa4I,oBAAoB;AAAA,EAC/BpB;AAAAA,EACAK;AAAAA,EACAC;AAAAA,EACAE;AAAAA,EACAW;AACF,GC1LME,aAA4B;AAAA,EAChCxD,IAAI;AAAA,EACJQ,SAAS,CAAC,MAAM,CAAC;AAAA,IAACZ,MAAM;AAAA,IAAe5E,MAAM;AAAA;AAAA,EAAA,CAAK,CAAC;AACrD,GAKayI,gBAAgB,CAC3BD,YACA/B,uBAAuBC,gBACvBD,uBAAuBM,YACvBN,uBAAuBO,mBACvBP,uBAAuBQ,cACvBT,yBAAyBzB,8BACzByB,yBAAyBd,4BACzBc,yBAAyBX,qBACzBW,yBAAyBV,wCACzBU,yBAAyBD,yCACzBgC,kBAAkBpB,sBAClBoB,kBAAkBf,yBAClBe,kBAAkBd,kBAClBc,kBAAkBZ,iBAClBY,kBAAkBD,sBAAsB,GAM7BI,eAAe;AAAA,EAC1BF;AAAAA,EACA5B,YAAYH;AAAAA,EACZkC,cAAcnC;AAAAA,EACdoC,OAAOL;AACT;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"selector.is-selection-collapsed.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.is-selection-collapsed.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n return (\n JSON.stringify(context.selection?.anchor.path) ===\n JSON.stringify(context.selection?.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","context","key","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock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Mb,MAAMa;AAAAA,QAAK,CAAA;AAAA,MAAC;AACpD;AAAA,IAAA;AAAA,EACF;AAGF,MAAImC,0BAA0BF;AACrBA,WAAAA;AAIX,GCxTaG,uBAAgDA,CAAC;AAAA,EAAC1C;AAAO,MAElE2C,KAAKC,UAAU5C,QAAQE,WAAW2B,OAAOxB,IAAI,MAC3CsC,KAAKC,UAAU5C,QAAQE,WAAWE,MAAMC,IAAI,KAC9CL,QAAQE,WAAW2B,OAAOgB,WAAW7C,QAAQE,WAAWE,MAAMyC;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"selector.is-selection-collapsed.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.is-selection-collapsed.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n return (\n JSON.stringify(context.selection?.anchor.path) ===\n JSON.stringify(context.selection?.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","context","key","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","isSelectionCollapsed","JSON","stringify","offset"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,MAAAA,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACNO,MAAME,gBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,QAAMC,MAAMD,QAAQE,aAChBC,MAAAA,aAAaH,QAAQE,UAAUE,MAAMC,KAAK,CAAC,CAAC,IAC1CL,QAAQE,UAAUE,MAAMC,KAAK,CAAC,EAAEC,OAElCC,QAEEC,OAAOP,MACTD,QAAQS,MAAMC,KAAMjB,CAAUA,UAAAA,MAAMa,SAASL,GAAG,IAChDM;A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AAA,IAAA;AAGc,oBAAA;AAAA,MAACE,MAAMf;AAAAA,MAAOY,MAAM,CAAC;AAAA,QAACC,MAAMb,MAAMa;AAAAA,MAAK,CAAA;AAAA,IAAC;AAAA,EAAA;AAG1D,MAAI+B,4BAA4BF;AACvBA,WAAAA;AAIX,GAKaG,eAETA,CAAC;AAAA,EAACtC;AAAO,MAAM;AACbuC,MAAAA;AACJ,QAAMC,oBAAoBP,qBAAqB;AAAA,IAACjC;AAAAA,EAAAA,CAAQ;AAExD,MAAI,CAACwC;AACH;AAGF,MAAIC,yBAAyB;AAElBhD,aAAAA,SAASO,QAAQS,OAAO;AACjC,QAAIhB,MAAMa,SAASkC,kBAAkBhC,KAAKF,MAAM;AACrB,+BAAA;AACzB;AAAA,IAAA;AAGF,QAAImC,wBAAwB;AACd,kBAAA;AAAA,QAACjC,MAAMf;AAAAA,QAAOY,MAAM,CAAC;AAAA,UAACC,MAAMb,MAAMa;AAAAA,QAAK,CAAA;AAAA,MAAC;AACpD;AAAA,IAAA;AAAA,EACF;AAGF,MAAImC,0BAA0BF;AACrBA,WAAAA;AAIX,GCxTaG,uBAAgDA,CAAC;AAAA,EAAC1C;AAAO,MAElE2C,KAAKC,UAAU5C,QAAQE,WAAW2B,OAAOxB,IAAI,MAC3CsC,KAAKC,UAAU5C,QAAQE,WAAWE,MAAMC,IAAI,KAC9CL,QAAQE,WAAW2B,OAAOgB,WAAW7C,QAAQE,WAAWE,MAAMyC;;;;;;;;;;;;;;;;"}
@@ -173,6 +173,12 @@ function toKeyName(name) {
173
173
  const keyName = name.toLowerCase();
174
174
  return aliases[keyName] ?? keyName;
175
175
  }
176
+ function raise(event) {
177
+ return {
178
+ type: "raise",
179
+ event
180
+ };
181
+ }
176
182
  function defineBehavior(behavior) {
177
183
  return behavior;
178
184
  }
@@ -306,41 +312,51 @@ const arrowDownOnLonelyBlockObject = {
306
312
  breakingBlockObject,
307
313
  deletingEmptyTextBlockAfterBlockObject,
308
314
  deletingEmptyTextBlockBeforeBlockObject
309
- }, decoratorAdd = {
310
- on: "decorator.add",
311
- actions: [({
312
- event
313
- }) => [event, {
314
- type: "reselect"
315
- }]]
316
- }, decoratorRemove = {
317
- on: "decorator.remove",
318
- guard: ({
319
- event
320
- }) => ({
321
- decorator: event.decorator
322
- }),
323
- actions: [({
324
- event
325
- }) => [event, {
326
- type: "reselect"
327
- }]]
328
- }, decoratorToggle = {
329
- on: "decorator.toggle",
330
- guard: ({
331
- event
332
- }) => ({
333
- decorator: event.decorator
334
- }),
335
- actions: [({
336
- event
337
- }) => [event, {
338
- type: "reselect"
339
- }]]
340
315
  }, coreDecoratorBehaviors = {
341
- decoratorAdd,
342
- decoratorRemove,
343
- decoratorToggle
316
+ strongShortcut: {
317
+ on: "key.down",
318
+ guard: ({
319
+ context,
320
+ event
321
+ }) => isHotkey("mod+b", event.keyboardEvent) && context.schema.decorators.some((decorator) => decorator.value === "strong"),
322
+ actions: [() => [raise({
323
+ type: "decorator.toggle",
324
+ decorator: "strong"
325
+ })]]
326
+ },
327
+ emShortcut: {
328
+ on: "key.down",
329
+ guard: ({
330
+ context,
331
+ event
332
+ }) => isHotkey("mod+i", event.keyboardEvent) && context.schema.decorators.some((decorator) => decorator.value === "em"),
333
+ actions: [() => [raise({
334
+ type: "decorator.toggle",
335
+ decorator: "em"
336
+ })]]
337
+ },
338
+ underlineShortcut: {
339
+ on: "key.down",
340
+ guard: ({
341
+ context,
342
+ event
343
+ }) => isHotkey("mod+u", event.keyboardEvent) && context.schema.decorators.some((decorator) => decorator.value === "underline"),
344
+ actions: [() => [raise({
345
+ type: "decorator.toggle",
346
+ decorator: "underline"
347
+ })]]
348
+ },
349
+ codeShortcut: {
350
+ on: "key.down",
351
+ guard: ({
352
+ context,
353
+ event
354
+ }) => isHotkey("mod+'", event.keyboardEvent) && context.schema.decorators.some((decorator) => decorator.value === "code"),
355
+ actions: [() => [raise({
356
+ type: "decorator.toggle",
357
+ decorator: "code"
358
+ })]]
359
+ }
344
360
  }, MAX_LIST_LEVEL = 10, clearListOnBackspace = {
345
361
  on: "delete.backward",
346
362
  guard: ({
@@ -473,7 +489,7 @@ const arrowDownOnLonelyBlockObject = {
473
489
  text: `
474
490
  `
475
491
  }]]
476
- }, coreBehaviors = [softReturn, coreDecoratorBehaviors.decoratorAdd, coreDecoratorBehaviors.decoratorRemove, coreDecoratorBehaviors.decoratorToggle, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab], coreBehavior = {
492
+ }, coreBehaviors = [softReturn, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab], coreBehavior = {
477
493
  softReturn,
478
494
  decorators: coreDecoratorBehaviors,
479
495
  blockObjects: coreBlockObjectBehaviors,
@@ -486,6 +502,7 @@ export {
486
502
  defineBehavior,
487
503
  getTextBlockText,
488
504
  isHotkey,
505
+ raise,
489
506
  spanSelectionPointToBlockOffset
490
507
  };
491
508
  //# sourceMappingURL=behavior.core.js.map