@makeswift/runtime 0.8.6 → 0.8.8

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 (90) hide show
  1. package/dist/LiveProvider.cjs.js +4 -3
  2. package/dist/LiveProvider.cjs.js.map +1 -1
  3. package/dist/LiveProvider.es.js +5 -4
  4. package/dist/LiveProvider.es.js.map +1 -1
  5. package/dist/PreviewProvider.cjs.js +4 -3
  6. package/dist/PreviewProvider.cjs.js.map +1 -1
  7. package/dist/PreviewProvider.es.js +5 -4
  8. package/dist/PreviewProvider.es.js.map +1 -1
  9. package/dist/actions.es.js +1 -1
  10. package/dist/constants.cjs.js +6 -2
  11. package/dist/constants.cjs.js.map +1 -1
  12. package/dist/constants.es.js +8 -4
  13. package/dist/constants.es.js.map +1 -1
  14. package/dist/index.cjs.js +83 -50
  15. package/dist/index.cjs.js.map +1 -1
  16. package/dist/index.cjs5.js +260 -106
  17. package/dist/index.cjs5.js.map +1 -1
  18. package/dist/index.cjs7.js.map +1 -1
  19. package/dist/index.es.js +86 -52
  20. package/dist/index.es.js.map +1 -1
  21. package/dist/index.es5.js +260 -106
  22. package/dist/index.es5.js.map +1 -1
  23. package/dist/index.es7.js +1 -1
  24. package/dist/index.es7.js.map +1 -1
  25. package/dist/leaf.es.js +1 -1
  26. package/dist/next.es.js +1 -1
  27. package/dist/state/breakpoints.cjs.js +44 -10
  28. package/dist/state/breakpoints.cjs.js.map +1 -1
  29. package/dist/state/breakpoints.es.js +44 -10
  30. package/dist/state/breakpoints.es.js.map +1 -1
  31. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  32. package/dist/types/src/next/api-handler/handlers/manifest.d.ts +1 -0
  33. package/dist/types/src/next/api-handler/handlers/manifest.d.ts.map +1 -1
  34. package/dist/types/src/next/client.d.ts +4 -1
  35. package/dist/types/src/next/client.d.ts.map +1 -1
  36. package/dist/types/src/next/index.d.ts +3 -1
  37. package/dist/types/src/next/index.d.ts.map +1 -1
  38. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts +3 -1
  39. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts.map +1 -1
  40. package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts +3 -1
  41. package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts.map +1 -1
  42. package/dist/types/src/runtimes/react/index.d.ts +19 -5
  43. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  44. package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts +2 -2
  45. package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts.map +1 -1
  46. package/dist/types/src/slate/BlockPlugin/index.d.ts +4 -0
  47. package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -1
  48. package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts +7 -4
  49. package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts.map +1 -1
  50. package/dist/types/src/slate/BlockPlugin/types.d.ts +2 -2
  51. package/dist/types/src/slate/BlockPlugin/types.d.ts.map +1 -1
  52. package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts +4 -0
  53. package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts.map +1 -0
  54. package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts +4 -0
  55. package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts.map +1 -0
  56. package/dist/types/src/slate/ListPlugin/toggleList.d.ts +2 -1
  57. package/dist/types/src/slate/ListPlugin/toggleList.d.ts.map +1 -1
  58. package/dist/types/src/slate/ListPlugin/unwrapList.d.ts +6 -2
  59. package/dist/types/src/slate/ListPlugin/unwrapList.d.ts.map +1 -1
  60. package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts +0 -1
  61. package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts.map +1 -1
  62. package/dist/types/src/slate/ListPlugin/wrapList.d.ts +2 -1
  63. package/dist/types/src/slate/ListPlugin/wrapList.d.ts.map +1 -1
  64. package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts +6 -2
  65. package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts.map +1 -1
  66. package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts +6 -2
  67. package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts.map +1 -1
  68. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts +6 -2
  69. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts.map +1 -1
  70. package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
  71. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts +6 -2
  72. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts.map +1 -1
  73. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts +6 -2
  74. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -1
  75. package/dist/types/src/slate/selectors.d.ts +19 -0
  76. package/dist/types/src/slate/selectors.d.ts.map +1 -0
  77. package/dist/types/src/slate/utils/editor.d.ts.map +1 -1
  78. package/dist/types/src/slate/utils/element.d.ts +2 -1
  79. package/dist/types/src/slate/utils/element.d.ts.map +1 -1
  80. package/dist/types/src/slate/utils/unhangRange.d.ts +10 -0
  81. package/dist/types/src/slate/utils/unhangRange.d.ts.map +1 -0
  82. package/dist/types/src/state/modules/breakpoints.d.ts +3 -4
  83. package/dist/types/src/state/modules/breakpoints.d.ts.map +1 -1
  84. package/dist/types/src/state/modules/breakpoints.test.d.ts +2 -0
  85. package/dist/types/src/state/modules/breakpoints.test.d.ts.map +1 -0
  86. package/dist/types/src/state/react-page.d.ts +2 -1
  87. package/dist/types/src/state/react-page.d.ts.map +1 -1
  88. package/dist/types/src/utils/isNonNullable.d.ts +2 -0
  89. package/dist/types/src/utils/isNonNullable.d.ts.map +1 -0
  90. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.es5.js","sources":["../src/slate/ListPlugin/constants.ts","../src/slate/utils/element.ts","../src/slate/utils/editor.ts","../src/slate/ListPlugin/utils/filterForSubtreeRoots.ts","../src/slate/ListPlugin/utils/location.ts","../src/slate/ListPlugin/utils/getSelectedListItems.ts","../src/slate/ListPlugin/indent.ts","../src/slate/ListPlugin/dedent.ts","../src/slate/ListPlugin/unwrapList.ts","../src/slate/ListPlugin/wrapList.ts","../src/slate/ListPlugin/toggleList.ts","../src/slate/ListPlugin/index.ts","../src/slate/TypographyPlugin/clearActiveTypographyStyle.ts","../src/slate/TypographyPlugin/clearDeviceActiveTypography.ts","../src/slate/TypographyPlugin/detachActiveTypography.ts","../src/slate/TypographyPlugin/setActiveTypographyId.ts","../src/slate/TypographyPlugin/setActiveTypographyStyle.ts","../src/slate/TypographyPlugin/index.ts","../src/slate/BlockPlugin/setBlockKeyForDevice.ts","../src/slate/BlockPlugin/clearBlockKeyForDevice.ts","../src/slate/BlockPlugin/index.ts"],"sourcesContent":["export const LIST_ITEM_CHILD_POSITION = 0\nexport const LIST_ITEM_LIST_POSITION = 1\n","import { Node, Element } from 'slate'\nimport {\n BlockType,\n Block,\n ParagraphElement,\n OrderedListElement,\n UnorderedListElement,\n ListItemElement,\n ListItemChildElement,\n Inline,\n InlineType,\n} from '../../controls'\n\nexport const ElementUtils = {\n isBlock(node: Node): node is Block {\n return (\n Element.isElement(node) &&\n (Element.isElementType(node, BlockType.Paragraph) ||\n Element.isElementType(node, BlockType.Heading1) ||\n Element.isElementType(node, BlockType.Heading2) ||\n Element.isElementType(node, BlockType.Heading3) ||\n Element.isElementType(node, BlockType.Heading3) ||\n Element.isElementType(node, BlockType.Heading4) ||\n Element.isElementType(node, BlockType.Heading5) ||\n Element.isElementType(node, BlockType.Heading6) ||\n Element.isElementType(node, BlockType.BlockQuote) ||\n Element.isElementType(node, BlockType.UnorderedList) ||\n Element.isElementType(node, BlockType.OrderedList) ||\n Element.isElementType(node, BlockType.ListItem) ||\n Element.isElementType(node, BlockType.ListItemChild))\n )\n },\n isInline(node: Node): node is Inline {\n return (\n Element.isElement(node) &&\n (Element.isElementType(node, InlineType.Link) ||\n Element.isElementType(node, InlineType.Link) ||\n Element.isElementType(node, InlineType.SubScript) ||\n Element.isElementType(node, InlineType.SuperScript))\n )\n },\n isConvertibleToListTextNode(node: Node) {\n return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node)\n },\n isParagraph(node: Node): node is ParagraphElement {\n return Element.isElementType(node, BlockType.Paragraph)\n },\n isList(node: Node): node is OrderedListElement | UnorderedListElement {\n return (\n Element.isElementType(node, BlockType.OrderedList) ||\n Element.isElementType(node, BlockType.UnorderedList)\n )\n },\n isListItem(node: Node): node is ListItemElement {\n return Element.isElementType(node, BlockType.ListItem)\n },\n isListItemChild(node: Node): node is ListItemChildElement {\n return Element.isElementType(node, BlockType.ListItemChild)\n },\n createText() {\n return { text: '' }\n },\n createParagraph() {\n return {\n children: [this.createText()],\n type: BlockType.Paragraph,\n }\n },\n createList(type: BlockType = BlockType.UnorderedList): Block {\n return { children: [this.createText()], type }\n },\n createListItem(): Block {\n return {\n children: [this.createText()],\n type: BlockType.ListItem,\n }\n },\n createListItemChild(): Block {\n return {\n children: [this.createText()],\n type: BlockType.ListItemChild,\n }\n },\n}\n","import { Path, Editor, NodeEntry } from 'slate'\nimport { ListElement, ListItemElement } from '../../controls'\nimport { ElementUtils } from './element'\n\nexport const EditorUtils = {\n getFirstAncestorList(editor: Editor, path: Path): NodeEntry<ListElement> | null {\n const parentList = Editor.above(editor, {\n at: path,\n match: (node): node is ListElement => ElementUtils.isList(node),\n })\n return parentList ?? null\n },\n getFirstAncestorListItem(editor: Editor, path: Path): NodeEntry<ListItemElement> | null {\n const parentListItem = Editor.above(editor, {\n at: path,\n match: (node): node is ListItemElement => ElementUtils.isListItem(node),\n })\n\n return parentListItem ?? null\n },\n}\n","import type { Node, NodeEntry } from 'slate'\nimport { Path } from 'slate'\n\nexport function filterForSubtreeRoots(entries: NodeEntry<Node>[]): NodeEntry<Node>[] {\n return entries.filter(\n ([, nodePath]) =>\n !Path.ancestors(nodePath).some(ancestor => {\n return entries.some(([, path]) => Path.equals(path, ancestor))\n }),\n )\n}\n","import { Range, Point, Path, Location } from 'slate'\n\nexport const LocationUtils = {\n getStartPath(location: Location): Path {\n if (Range.isRange(location)) return Range.start(location).path\n if (Point.isPoint(location)) return location.path\n return location\n },\n}\n","import type { Element, NodeEntry } from 'slate'\nimport { Editor, Path } from 'slate'\nimport { EditorUtils } from '../../utils/editor'\nimport { ElementUtils } from '../../utils/element'\nimport { LocationUtils } from './location'\n\nexport function getSelectedListItems(editor: Editor): NodeEntry<Element>[] {\n if (!editor.selection) return []\n\n const start = LocationUtils.getStartPath(editor.selection)\n const listItems = Editor.nodes(editor, {\n at: editor.selection,\n match: node => ElementUtils.isListItem(node),\n })\n const firstAncestorPath = EditorUtils.getFirstAncestorListItem(editor, start)?.[1] ?? []\n\n return Array.from(listItems).filter((node): node is NodeEntry<Element> =>\n Path.isDescendant(start, node[1])\n ? Path.equals(node[1], firstAncestorPath)\n : !Path.isAfter(start, node[1]),\n )\n}\n\nexport function getSelectedLists(editor: Editor): NodeEntry<Element>[] {\n if (!editor.selection) return []\n\n const start = LocationUtils.getStartPath(editor.selection)\n const lists = Editor.nodes(editor, {\n at: editor.selection,\n match: node => ElementUtils.isList(node),\n })\n const firstAncestorPath = EditorUtils.getFirstAncestorList(editor, start)?.[1] ?? []\n\n return Array.from(lists).filter((node): node is NodeEntry<Element> =>\n Path.isDescendant(start, node[1])\n ? Path.equals(node[1], firstAncestorPath)\n : !Path.isAfter(start, node[1]),\n )\n}\n","import { Editor, Node, Path, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { LIST_ITEM_LIST_POSITION } from './constants'\nimport { filterForSubtreeRoots } from './utils/filterForSubtreeRoots'\nimport { getSelectedListItems } from './utils/getSelectedListItems'\n\nexport function indentPath(editor: Editor, path: Path) {\n const parent = Node.parent(editor, path)\n if (!path || !Path.hasPrevious(path) || !ElementUtils.isList(parent)) return\n\n const previosPath = Path.previous(path)\n\n const previousChildListPath = [...previosPath, LIST_ITEM_LIST_POSITION]\n const previousHasChildList = Node.has(editor, previousChildListPath)\n\n Editor.withoutNormalizing(editor, () => {\n if (!previousHasChildList) {\n Transforms.insertNodes(editor, ElementUtils.createList(parent.type), {\n at: previousChildListPath,\n })\n }\n\n const previousChildList = Node.get(editor, previousChildListPath)\n\n if (ElementUtils.isList(previousChildList)) {\n const index = previousHasChildList ? previousChildList.children.length : 0\n Transforms.moveNodes(editor, {\n at: path,\n to: [...previousChildListPath, index],\n })\n }\n })\n}\n\nexport function indent(editor: Editor) {\n if (!editor.selection) return\n\n const listItems = getSelectedListItems(editor)\n const subRoots = filterForSubtreeRoots(listItems)\n const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path))\n\n refs.forEach(ref => {\n if (ref.current) {\n indentPath(editor, ref.current)\n }\n ref.unref()\n })\n}\n","import { Editor, Path, Transforms } from 'slate'\nimport { indentPath } from './indent'\nimport { getSelectedListItems } from './utils/getSelectedListItems'\nimport { filterForSubtreeRoots } from './utils/filterForSubtreeRoots'\nimport { EditorUtils } from '../utils/editor'\n\nfunction dedentPath(editor: Editor, listItemPath: Path) {\n const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath)\n const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath)\n if (!parentList || !listItemContainingParentList) return\n\n const [parentListNode, parentListPath] = parentList\n const [_, listItemContainingParentListPath] = listItemContainingParentList\n\n const listItemPosition = listItemPath[listItemPath.length - 1]\n const previousSiblings = parentListNode.children.slice(0, listItemPosition)\n const nextSiblings = parentListNode.children.slice(listItemPosition + 1)\n\n Editor.withoutNormalizing(editor, () => {\n // put next siblings into list item\n nextSiblings.forEach(() => {\n const nextSiblingPath = [...parentListPath, listItemPosition + 1]\n indentPath(editor, nextSiblingPath)\n })\n // move list item to parent list\n Transforms.moveNodes(editor, {\n at: listItemPath,\n to: Path.next(listItemContainingParentListPath),\n })\n // delete old parent list if there are no other list items\n if (previousSiblings.length === 0) {\n Transforms.removeNodes(editor, { at: parentListPath })\n }\n })\n}\n\nexport function dedent(editor: Editor) {\n if (!editor.selection) return\n\n const listItems = getSelectedListItems(editor)\n const subRoots = filterForSubtreeRoots(listItems)\n const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path))\n\n refs.forEach(ref => {\n if (ref.current) {\n dedentPath(editor, ref.current)\n }\n ref.unref()\n })\n}\n","import { Editor, Transforms, Path, Node } from 'slate'\nimport { BlockType } from '../../controls'\nimport { EditorUtils } from '../utils/editor'\nimport { LIST_ITEM_CHILD_POSITION, LIST_ITEM_LIST_POSITION } from './constants'\nimport { filterForSubtreeRoots } from './utils/filterForSubtreeRoots'\nimport { getSelectedListItems } from './utils/getSelectedListItems'\n\nexport function unwrapPath(editor: Editor, listItemPath: Path) {\n const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath)\n const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath)\n //if this is a nested item we don't want to unwrap it\n if (!parentList || listItemContainingParentList) return\n\n Editor.withoutNormalizing(editor, () => {\n const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION]\n const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION]\n\n if (Node.has(editor, listItemNestedListPath)) {\n Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath })\n Transforms.liftNodes(editor, { at: listItemNestedListPath })\n Transforms.liftNodes(editor, { at: Path.next(listItemPath) })\n }\n\n if (Node.has(editor, listItemTextPath)) {\n Transforms.setNodes(\n editor,\n { type: BlockType.Paragraph },\n {\n at: listItemTextPath,\n },\n )\n Transforms.liftNodes(editor, { at: listItemTextPath })\n Transforms.liftNodes(editor, { at: listItemPath })\n }\n })\n}\n\nexport function unwrapList(editor: Editor) {\n if (!editor.selection) return\n\n const listItems = getSelectedListItems(editor)\n const subRoots = filterForSubtreeRoots(listItems)\n const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path))\n\n refs.forEach(ref => {\n if (ref.current) {\n unwrapPath(editor, ref.current)\n }\n ref.unref()\n })\n}\n","import { Editor, Element, Transforms } from 'slate'\nimport { BlockType } from '../../controls'\nimport { ElementUtils } from '../utils/element'\n\ntype WrapListOptions = {\n type: typeof BlockType.UnorderedList | typeof BlockType.OrderedList\n}\n\nexport function wrapList(\n editor: Editor,\n options: WrapListOptions = { type: BlockType.UnorderedList },\n) {\n if (!editor.selection) return\n\n const nonListEntries = Array.from(\n Editor.nodes(editor, {\n at: editor.selection,\n match: node => {\n return Element.isElement(node) && ElementUtils.isConvertibleToListTextNode(node)\n },\n }),\n )\n\n const refs = nonListEntries.map(([_, path]) => Editor.pathRef(editor, path))\n\n refs.forEach(ref => {\n const path = ref.current\n if (path) {\n Editor.withoutNormalizing(editor, () => {\n Transforms.setNodes(\n editor,\n { type: BlockType.ListItemChild },\n {\n at: path,\n },\n )\n Transforms.wrapNodes(editor, ElementUtils.createListItem(), {\n at: path,\n })\n Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {\n at: path,\n })\n })\n }\n ref.unref()\n })\n}\n","import { Editor, Node, Path, Transforms } from 'slate'\nimport { BlockType } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { unwrapList } from './unwrapList'\nimport { LocationUtils } from './utils/location'\nimport { wrapList } from './wrapList'\n\ntype ToggleListOptions = {\n type: typeof BlockType.UnorderedList | typeof BlockType.OrderedList\n}\n\nexport function toggleList(\n editor: Editor,\n options: ToggleListOptions = { type: BlockType.UnorderedList },\n) {\n if (!editor.selection) return\n const start = LocationUtils.getStartPath(editor.selection)\n const ancestorPath = Path.ancestors(start).at(1)\n if (!ancestorPath || !Node.has(editor, ancestorPath)) return\n const ancestor = Node.get(editor, ancestorPath)\n\n if (!ElementUtils.isList(ancestor)) {\n return wrapList(editor, { type: options.type })\n }\n\n if (ancestor.type === options.type) {\n unwrapList(editor)\n } else {\n Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath })\n }\n}\n","import type { KeyboardEvent } from 'react'\nimport { Editor, Transforms, Range, Node, PathRef, Text } from 'slate'\nimport isHotkey from 'is-hotkey'\nimport { LIST_ITEM_CHILD_POSITION } from './constants'\nimport { EditorUtils } from '../utils/editor'\nimport { ElementUtils } from '../utils/element'\nimport { dedent } from './dedent'\nimport { indent } from './indent'\nimport { toggleList } from './toggleList'\nimport { unwrapList } from './unwrapList'\nimport { wrapList } from './wrapList'\nimport { BlockType } from '../../controls'\n\nexport const List = {\n unwrapList,\n wrapList,\n indent,\n dedent,\n toggleList,\n}\n\nexport function onKeyDown(e: KeyboardEvent, editor: Editor) {\n if (\n !editor.selection ||\n Array.from(Editor.nodes(editor, { match: node => ElementUtils.isListItem(node) })).length === 0\n )\n return\n\n if (isHotkey('shift+tab', e)) {\n e.preventDefault()\n List.dedent(editor)\n }\n\n if (isHotkey('tab', e)) {\n e.preventDefault()\n List.indent(editor)\n }\n\n if (isHotkey('backspace', e)) {\n if (!editor.selection) return\n if (Range.isExpanded(editor.selection)) return\n const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path)\n if (editor.selection.anchor.offset === 0 && listItem) {\n e.preventDefault()\n const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1])\n const list = EditorUtils.getFirstAncestorList(editor, listItem[1])\n\n if (parentListItem) {\n List.dedent(editor)\n } else if (list) {\n List.unwrapList(editor)\n }\n return\n }\n }\n\n if (isHotkey('enter', e)) {\n e.preventDefault()\n\n if (!editor.selection) return\n\n if (Range.isExpanded(editor.selection)) {\n Transforms.delete(editor)\n return\n }\n\n const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path)\n if (\n editor.selection.anchor.offset === 0 &&\n listItem &&\n Editor.string(editor, listItem[1]) === ''\n ) {\n const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1])\n\n if (parentListItem) {\n List.dedent(editor)\n } else {\n List.unwrapList(editor)\n }\n return\n }\n\n Transforms.splitNodes(editor, {\n at: editor.selection,\n always: true,\n match: node => ElementUtils.isListItem(node),\n })\n }\n\n if (isHotkey('shift+enter', e)) {\n e.preventDefault()\n editor.insertText('\\n')\n }\n}\n\nexport function withList(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n\n // Normalization for converting children of list items to list item children\n // In the case of backspace from position 0 of node into a list this converts the node into a list item.\n if (ElementUtils.isListItem(normalizationNode)) {\n const pathToListItemText = [...normalizationPath, LIST_ITEM_CHILD_POSITION]\n\n if (Node.has(editor, pathToListItemText)) {\n const nodeInListItemTextPosition = Node.get(editor, pathToListItemText)\n if (ElementUtils.isParagraph(nodeInListItemTextPosition)) {\n Transforms.setNodes(\n editor,\n { type: BlockType.ListItemChild },\n {\n at: pathToListItemText,\n },\n )\n return\n }\n } else {\n Transforms.insertNodes(editor, ElementUtils.createListItem(), {\n at: pathToListItemText,\n })\n return\n }\n }\n\n // Normalization for merging adjacent lists of the same type\n if (!Text.isText(normalizationNode)) {\n const mergeableChildren = Array.from(Node.children(editor, normalizationPath))\n .map((child, index, children) => {\n const potentialNodeToBeMerged = children.at(index + 1)\n if (\n !potentialNodeToBeMerged ||\n !ElementUtils.isList(potentialNodeToBeMerged[0]) ||\n !ElementUtils.isList(child[0]) ||\n potentialNodeToBeMerged[0].type !== child[0].type\n ) {\n return null\n }\n return [\n Editor.pathRef(editor, child[1]),\n Editor.pathRef(editor, potentialNodeToBeMerged[1]),\n ]\n })\n .filter((mergeableNodes): mergeableNodes is PathRef[] => Boolean(mergeableNodes))\n\n if (mergeableChildren.length !== 0) {\n mergeableChildren.reverse().forEach(([nodePathRef, nodeToBeMergedPathRef]) => {\n const nodePath = nodePathRef.current\n const nodeToBeMergedPath = nodeToBeMergedPathRef.current\n if (nodePath == null || nodeToBeMergedPath == null) return\n const nodeChildren = Array.from(Node.children(editor, nodePath))\n const childrenToBeMerged = Array.from(Node.children(editor, nodeToBeMergedPath))\n Editor.withoutNormalizing(editor, () => {\n childrenToBeMerged.forEach(([_, childPath], index) => {\n Transforms.moveNodes(editor, {\n at: childPath,\n to: [...nodePath, nodeChildren.length + index],\n })\n })\n Transforms.removeNodes(editor, { at: nodeToBeMergedPath })\n })\n nodePathRef.unref()\n nodeToBeMergedPathRef.unref()\n })\n return\n }\n }\n\n normalizeNode(entry)\n }\n\n return editor\n}\n","import { Editor, Transforms, Text } from 'slate'\nimport { RichTextTypography } from '../../controls'\n\nexport function clearActiveTypographyStyle(editor: Editor) {\n if (!editor.selection) return\n\n // Due to the nested nature of `typography` I can't just call a single `Transforms.setNodes` on our selection\n const textNodes = Editor.nodes(editor, {\n at: editor.selection,\n match: node => Text.isText(node),\n })\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const typography: RichTextTypography = {\n ...node.typography,\n style: [],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography,\n },\n { at: path },\n )\n }\n }\n}\n","import { Editor, Transforms, Text } from 'slate'\nimport { RichTextTypography } from '../../controls'\n\nexport function clearDeviceActiveTypography(editor: Editor, currentDeviceId: string) {\n if (!editor.selection) return\n\n const textNodes = Editor.nodes(editor, {\n at: editor.selection,\n match: node => Text.isText(node),\n })\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const typography: RichTextTypography = {\n ...node.typography,\n style: node?.typography?.style.filter(({ deviceId }) => deviceId !== currentDeviceId) ?? [],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography,\n },\n { at: path },\n )\n }\n }\n}\n","import { Editor, Transforms, Text } from 'slate'\nimport { RichTextTypography } from '../../controls'\n\nexport function detachActiveTypography(editor: Editor, value: RichTextTypography['style']) {\n if (!editor.selection) return\n\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: editor.selection,\n match: node => Text.isText(node),\n }),\n )\n\n textNodes.forEach(([node, path]) => {\n if (Text.isText(node)) {\n Transforms.setNodes(\n editor,\n {\n typography: {\n style: value,\n },\n },\n { at: path },\n )\n }\n })\n}\n","import { Editor, Transforms, Text } from 'slate'\n\nexport function setActiveTypographyId(editor: Editor, id: string) {\n Transforms.setNodes(\n editor,\n {\n typography: {\n id,\n style: [],\n },\n },\n {\n match: node => Text.isText(node),\n },\n )\n}\n","import { Editor, Transforms, Text } from 'slate'\nimport { RichTextTypography } from '../../controls'\nimport { Breakpoints, findBreakpointOverride } from '../../state/modules/breakpoints'\n\nexport function setActiveTypographyStyle(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: string,\n prop: string,\n value?: unknown,\n) {\n if (!editor.selection) return\n\n const textNodes = Editor.nodes(editor, {\n at: editor.selection,\n match: node => Text.isText(node),\n })\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const deviceOverrides = node?.typography?.style ?? []\n const deviceStyle = findBreakpointOverride(\n breakpoints,\n deviceOverrides,\n deviceId,\n v => v,\n ) || { value: {} }\n const nextDeviceStyle = {\n deviceId,\n value: { ...deviceStyle.value, [prop]: value },\n }\n const nextTypography: RichTextTypography = {\n ...node.typography,\n style: [...deviceOverrides.filter(v => v.deviceId !== deviceId), nextDeviceStyle],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography: nextTypography,\n },\n { at: path },\n )\n }\n }\n}\n","import { Editor, Text, Transforms } from 'slate'\nimport { clearActiveTypographyStyle } from './clearActiveTypographyStyle'\nimport { clearDeviceActiveTypography } from './clearDeviceActiveTypography'\nimport { detachActiveTypography } from './detachActiveTypography'\nimport { setActiveTypographyId } from './setActiveTypographyId'\nimport { setActiveTypographyStyle } from './setActiveTypographyStyle'\n\nexport const Typography = {\n setActiveTypographyId,\n setActiveTypographyStyle,\n clearActiveTypographyStyle,\n clearDeviceActiveTypography,\n detachActiveTypography,\n}\n\nexport function withTypography(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n // Normalization typography with empty style and id to be text\n if (\n Text.isText(normalizationNode) &&\n normalizationNode?.typography?.id == null &&\n normalizationNode?.typography?.style.length === 0\n ) {\n Transforms.unsetNodes(editor, 'typography', { at: normalizationPath })\n return\n }\n\n normalizeNode(entry)\n }\n\n return editor\n}\n","import { Editor, Transforms } from 'slate'\nimport { Device } from '../../controls/types'\nimport { Breakpoints, findBreakpointOverride } from '../../state/modules/breakpoints'\nimport { ElementUtils } from '../utils/element'\nimport { EditableBlockKey, EditableBlockValue } from './types'\n\nexport function setBlockKeyForDevice(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: Device,\n key: EditableBlockKey,\n value: EditableBlockValue,\n) {\n if (!editor.selection) return\n\n const rootElements = Editor.nodes(editor, {\n match: (_, path) => path.length === 1,\n at: Editor.unhangRange(editor, editor.selection),\n })\n\n for (const [node, path] of rootElements) {\n if (ElementUtils.isBlock(node)) {\n const deviceValues = node[key] ?? []\n const currentDeviceValue = findBreakpointOverride(breakpoints, deviceValues, deviceId, v => v)\n const nextDeviceValue = {\n ...currentDeviceValue,\n deviceId,\n value,\n }\n Transforms.setNodes(\n editor,\n {\n [key]: [...deviceValues.filter(v => v.deviceId !== deviceId), nextDeviceValue],\n },\n { at: path },\n )\n }\n }\n}\n","import { Editor, Transforms } from 'slate'\nimport { Device } from '../../controls/types'\nimport { ElementUtils } from '../utils/element'\nimport { EditableBlockKey } from './types'\n\nexport function clearBlockKeyForDevice(editor: Editor, deviceId: Device, key: EditableBlockKey) {\n if (!editor.selection) return\n\n const rootElements = Editor.nodes(editor, {\n match: (_, path) => path.length === 1,\n at: Editor.unhangRange(editor, editor.selection),\n })\n\n for (const [node, path] of rootElements) {\n if (ElementUtils.isBlock(node)) {\n const deviceOverrides = node[key] ?? []\n Transforms.setNodes(\n editor,\n {\n [key]: deviceOverrides.filter(v => v.deviceId !== deviceId),\n },\n { at: path },\n )\n }\n }\n}\n","import { Editor, Transforms } from 'slate'\nimport { setBlockKeyForDevice } from './setBlockKeyForDevice'\nimport { clearBlockKeyForDevice } from './clearBlockKeyForDevice'\nimport { ElementUtils } from '../utils/element'\n\nexport const Block = {\n setBlockKeyForDevice: setBlockKeyForDevice,\n clearBlockKeyForDevice: clearBlockKeyForDevice,\n}\n\nexport function withBlock(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n // Normalization textAlign with empty array of values\n if (ElementUtils.isBlock(normalizationNode) && normalizationNode?.textAlign?.length == 0) {\n Transforms.unsetNodes(editor, 'textAlign', { at: normalizationPath })\n return\n }\n\n normalizeNode(entry)\n }\n\n return editor\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAO,MAAM,2BAA2B;AACjC,MAAM,0BAA0B;ACYhC,MAAM,eAAe;AAAA,EAC1B,QAAQ,MAA2B;AACjC,WACE,QAAQ,UAAU,IAAI,KACrB,SAAQ,cAAc,MAAM,UAAU,SAAS,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,UAAU,KAChD,QAAQ,cAAc,MAAM,UAAU,aAAa,KACnD,QAAQ,cAAc,MAAM,UAAU,WAAW,KACjD,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,aAAa;AAAA,EAEzD;AAAA,EACA,SAAS,MAA4B;AAEjC,WAAA,QAAQ,UAAU,IAAI,KACrB,SAAQ,cAAc,MAAM,WAAW,IAAI,KAC1C,QAAQ,cAAc,MAAM,WAAW,IAAI,KAC3C,QAAQ,cAAc,MAAM,WAAW,SAAS,KAChD,QAAQ,cAAc,M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":"index.es5.js","sources":["../src/slate/ListPlugin/constants.ts","../src/slate/utils/element.ts","../src/slate/utils/editor.ts","../src/slate/ListPlugin/utils/filterForSubtreeRoots.ts","../src/slate/ListPlugin/utils/location.ts","../src/slate/ListPlugin/utils/getSelectedListItems.ts","../src/slate/ListPlugin/indent.ts","../src/slate/ListPlugin/dedent.ts","../src/slate/ListPlugin/unwrapList.ts","../src/slate/ListPlugin/wrapList.ts","../src/slate/ListPlugin/toggleList.ts","../src/slate/ListPlugin/index.ts","../src/slate/TypographyPlugin/clearActiveTypographyStyle.ts","../src/slate/TypographyPlugin/clearDeviceActiveTypography.ts","../src/slate/TypographyPlugin/detachActiveTypography.ts","../src/slate/TypographyPlugin/setActiveTypographyId.ts","../src/slate/TypographyPlugin/setActiveTypographyStyle.ts","../src/slate/TypographyPlugin/index.ts","../src/slate/utils/unhangRange.ts","../src/slate/selectors.ts","../src/slate/BlockPlugin/setBlockKeyForDevice.ts","../src/slate/BlockPlugin/clearBlockKeyForDevice.ts","../src/slate/BlockPlugin/wrapInline.ts","../src/slate/BlockPlugin/unwrapInline.ts","../src/slate/BlockPlugin/index.ts"],"sourcesContent":["export const LIST_ITEM_CHILD_POSITION = 0\nexport const LIST_ITEM_LIST_POSITION = 1\n","import { Node, Element } from 'slate'\nimport {\n RootBlock,\n BlockType,\n Block,\n Inline,\n InlineType,\n ParagraphElement,\n OrderedListElement,\n UnorderedListElement,\n ListItemElement,\n ListItemChildElement,\n} from '../../controls'\n\nexport const ElementUtils = {\n isRootBlock(node: Node): node is RootBlock {\n return (\n Element.isElement(node) &&\n (Element.isElementType(node, BlockType.Paragraph) ||\n Element.isElementType(node, BlockType.Heading1) ||\n Element.isElementType(node, BlockType.Heading2) ||\n Element.isElementType(node, BlockType.Heading3) ||\n Element.isElementType(node, BlockType.Heading3) ||\n Element.isElementType(node, BlockType.Heading4) ||\n Element.isElementType(node, BlockType.Heading5) ||\n Element.isElementType(node, BlockType.Heading6) ||\n Element.isElementType(node, BlockType.BlockQuote) ||\n Element.isElementType(node, BlockType.UnorderedList) ||\n Element.isElementType(node, BlockType.OrderedList))\n )\n },\n isBlock(node: Node): node is Block {\n return (\n Element.isElement(node) &&\n (this.isRootBlock(node) ||\n Element.isElementType(node, BlockType.ListItem) ||\n Element.isElementType(node, BlockType.ListItemChild))\n )\n },\n isInline(node: Node): node is Inline {\n return (\n Element.isElementType(node, InlineType.Code) ||\n Element.isElementType(node, InlineType.Link) ||\n Element.isElementType(node, InlineType.SubScript) ||\n Element.isElementType(node, InlineType.SuperScript)\n )\n },\n isConvertibleToListTextNode(node: Node) {\n return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node)\n },\n isParagraph(node: Node): node is ParagraphElement {\n return Element.isElementType(node, BlockType.Paragraph)\n },\n isList(node: Node): node is OrderedListElement | UnorderedListElement {\n return (\n Element.isElementType(node, BlockType.OrderedList) ||\n Element.isElementType(node, BlockType.UnorderedList)\n )\n },\n isListItem(node: Node): node is ListItemElement {\n return Element.isElementType(node, BlockType.ListItem)\n },\n isListItemChild(node: Node): node is ListItemChildElement {\n return Element.isElementType(node, BlockType.ListItemChild)\n },\n createText() {\n return { text: '' }\n },\n createParagraph() {\n return {\n children: [this.createText()],\n type: BlockType.Paragraph,\n }\n },\n createList(type: BlockType = BlockType.UnorderedList): Block {\n return { children: [this.createText()], type }\n },\n createListItem(): Block {\n return {\n children: [this.createListItemChild()],\n type: BlockType.ListItem,\n }\n },\n createListItemChild(): Block {\n return {\n children: [this.createText()],\n type: BlockType.ListItemChild,\n }\n },\n}\n","import { Path, Editor, NodeEntry } from 'slate'\n\nimport { ElementUtils } from './element'\nimport { ListElement, ListItemElement } from '../../controls'\n\nexport const EditorUtils = {\n getFirstAncestorList(editor: Editor, path: Path): NodeEntry<ListElement> | null {\n try {\n const parentList = Editor.above(editor, {\n at: path,\n match: (node): node is ListElement => ElementUtils.isList(node),\n })\n return parentList ?? null\n } catch (e) {\n return null\n }\n },\n getFirstAncestorListItem(editor: Editor, path: Path): NodeEntry<ListItemElement> | null {\n try {\n const parentListItem = Editor.above(editor, {\n at: path,\n match: (node): node is ListItemElement => ElementUtils.isListItem(node),\n })\n\n return parentListItem ?? null\n } catch (e) {\n return null\n }\n },\n}\n","import type { Node, NodeEntry } from 'slate'\nimport { Path } from 'slate'\n\nexport function filterForSubtreeRoots(entries: NodeEntry<Node>[]): NodeEntry<Node>[] {\n return entries.filter(\n ([, nodePath]) =>\n !Path.ancestors(nodePath).some(ancestor => {\n return entries.some(([, path]) => Path.equals(path, ancestor))\n }),\n )\n}\n","import { Range, Point, Path, Location } from 'slate'\n\nexport const LocationUtils = {\n getStartPath(location: Location): Path {\n if (Range.isRange(location)) return Range.start(location).path\n if (Point.isPoint(location)) return location.path\n return location\n },\n}\n","import type { Element, NodeEntry } from 'slate'\nimport { Editor, Path } from 'slate'\nimport { EditorUtils } from '../../utils/editor'\nimport { ElementUtils } from '../../utils/element'\nimport { LocationUtils } from './location'\n\nexport function getSelectedListItems(editor: Editor): NodeEntry<Element>[] {\n if (!editor.selection) return []\n\n const start = LocationUtils.getStartPath(editor.selection)\n const listItems = Editor.nodes(editor, {\n at: editor.selection,\n match: node => ElementUtils.isListItem(node),\n })\n const firstAncestorPath = EditorUtils.getFirstAncestorListItem(editor, start)?.[1] ?? []\n\n return Array.from(listItems).filter((node): node is NodeEntry<Element> =>\n Path.isDescendant(start, node[1])\n ? Path.equals(node[1], firstAncestorPath)\n : !Path.isAfter(start, node[1]),\n )\n}\n","import { Editor, Node, Path, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { LIST_ITEM_LIST_POSITION } from './constants'\nimport { filterForSubtreeRoots } from './utils/filterForSubtreeRoots'\nimport { getSelectedListItems } from './utils/getSelectedListItems'\n\nexport function indentPath(editor: Editor, path: Path) {\n const parent = Node.parent(editor, path)\n if (!path || !Path.hasPrevious(path) || !ElementUtils.isList(parent)) return\n\n const previosPath = Path.previous(path)\n\n const previousChildListPath = [...previosPath, LIST_ITEM_LIST_POSITION]\n const previousHasChildList = Node.has(editor, previousChildListPath)\n\n Editor.withoutNormalizing(editor, () => {\n if (!previousHasChildList) {\n Transforms.insertNodes(editor, ElementUtils.createList(parent.type), {\n at: previousChildListPath,\n })\n }\n\n const previousChildList = Node.get(editor, previousChildListPath)\n\n if (ElementUtils.isList(previousChildList)) {\n const index = previousHasChildList ? previousChildList.children.length : 0\n Transforms.moveNodes(editor, {\n at: path,\n to: [...previousChildListPath, index],\n })\n }\n })\n}\n\nexport function indent(editor: Editor) {\n if (!editor.selection) return\n\n const listItems = getSelectedListItems(editor)\n const subRoots = filterForSubtreeRoots(listItems)\n const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path))\n\n refs.forEach(ref => {\n if (ref.current) {\n indentPath(editor, ref.current)\n }\n ref.unref()\n })\n}\n","import { Editor, Path, Transforms } from 'slate'\nimport { indentPath } from './indent'\nimport { getSelectedListItems } from './utils/getSelectedListItems'\nimport { filterForSubtreeRoots } from './utils/filterForSubtreeRoots'\nimport { EditorUtils } from '../utils/editor'\n\nfunction dedentPath(editor: Editor, listItemPath: Path) {\n const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath)\n const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath)\n if (!parentList || !listItemContainingParentList) return\n\n const [parentListNode, parentListPath] = parentList\n const [_, listItemContainingParentListPath] = listItemContainingParentList\n\n const listItemPosition = listItemPath[listItemPath.length - 1]\n const previousSiblings = parentListNode.children.slice(0, listItemPosition)\n const nextSiblings = parentListNode.children.slice(listItemPosition + 1)\n\n Editor.withoutNormalizing(editor, () => {\n // put next siblings into list item\n nextSiblings.forEach(() => {\n const nextSiblingPath = [...parentListPath, listItemPosition + 1]\n indentPath(editor, nextSiblingPath)\n })\n // move list item to parent list\n Transforms.moveNodes(editor, {\n at: listItemPath,\n to: Path.next(listItemContainingParentListPath),\n })\n // delete old parent list if there are no other list items\n if (previousSiblings.length === 0) {\n Transforms.removeNodes(editor, { at: parentListPath })\n }\n })\n}\n\nexport function dedent(editor: Editor) {\n if (!editor.selection) return\n\n const listItems = getSelectedListItems(editor)\n const subRoots = filterForSubtreeRoots(listItems)\n const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path))\n\n refs.forEach(ref => {\n if (ref.current) {\n dedentPath(editor, ref.current)\n }\n ref.unref()\n })\n}\n","import { Editor, Element, Transforms, Path, Node, Location, Span } from 'slate'\nimport { EditorUtils } from '../utils/editor'\nimport { LIST_ITEM_CHILD_POSITION, LIST_ITEM_LIST_POSITION } from './constants'\nimport { filterForSubtreeRoots } from './utils/filterForSubtreeRoots'\nimport { ElementUtils } from '../utils/element'\nimport { BlockType } from '../../controls'\n\nexport function unwrapPath(editor: Editor, listItemPath: Path) {\n const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath)\n const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath)\n //if this is a nested item we don't want to unwrap it\n if (!parentList || listItemContainingParentList) return\n\n Editor.withoutNormalizing(editor, () => {\n const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION]\n const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION]\n\n if (Node.has(editor, listItemNestedListPath)) {\n Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath })\n Transforms.liftNodes(editor, { at: listItemNestedListPath })\n Transforms.liftNodes(editor, { at: Path.next(listItemPath) })\n }\n\n if (Node.has(editor, listItemTextPath)) {\n Transforms.setNodes(\n editor,\n { type: BlockType.Paragraph },\n {\n at: listItemTextPath,\n },\n )\n Transforms.liftNodes(editor, { at: listItemTextPath })\n Transforms.liftNodes(editor, { at: listItemPath })\n }\n })\n}\n\ntype UnwrapListOptions = {\n at?: Location | Span\n}\n\nexport function unwrapList(editor: Editor, options?: UnwrapListOptions) {\n const at = options?.at ?? editor.selection\n if (!at) return\n\n const listItems = Array.from(\n Editor.nodes(editor, {\n at,\n match: node => {\n return Element.isElement(node) && ElementUtils.isListItem(node)\n },\n }),\n )\n const subRoots = filterForSubtreeRoots(listItems)\n const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path))\n\n refs.forEach(ref => {\n if (ref.current) {\n unwrapPath(editor, ref.current)\n }\n ref.unref()\n })\n}\n","import { Editor, Element, Location, Span, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { BlockType } from '../../controls'\n\ntype WrapListOptions = {\n type: typeof BlockType.UnorderedList | typeof BlockType.OrderedList\n at?: Location | Span\n}\n\nexport function wrapList(\n editor: Editor,\n options: WrapListOptions = { type: BlockType.UnorderedList },\n) {\n const at = options.at ?? editor.selection\n if (!at) return\n\n const nonListEntries = Array.from(\n Editor.nodes(editor, {\n at,\n match: node => {\n return Element.isElement(node) && ElementUtils.isConvertibleToListTextNode(node)\n },\n }),\n )\n\n const refs = nonListEntries.map(([_, path]) => Editor.pathRef(editor, path))\n\n refs.forEach(ref => {\n const path = ref.current\n if (path) {\n Editor.withoutNormalizing(editor, () => {\n Transforms.setNodes(\n editor,\n { type: BlockType.ListItemChild },\n {\n at: path,\n },\n )\n Transforms.wrapNodes(editor, ElementUtils.createListItem(), {\n match: node => ElementUtils.isListItemChild(node),\n at: path,\n })\n Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {\n at: path,\n })\n })\n }\n ref.unref()\n })\n}\n","import { Editor, Location, Node, Path, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { unwrapList } from './unwrapList'\nimport { LocationUtils } from './utils/location'\nimport { wrapList } from './wrapList'\nimport { BlockType } from '../../controls'\n\ntype ToggleListOptions = {\n type: typeof BlockType.UnorderedList | typeof BlockType.OrderedList\n at?: Location\n}\n\nexport function toggleList(\n editor: Editor,\n options: ToggleListOptions = { type: BlockType.UnorderedList },\n) {\n const at = options.at ?? editor.selection\n if (at == null) return\n const start = LocationUtils.getStartPath(at)\n const ancestorPath = Path.ancestors(start).at(1)\n if (!ancestorPath || !Node.has(editor, ancestorPath)) return\n const ancestor = Node.get(editor, ancestorPath)\n\n if (!ElementUtils.isList(ancestor)) {\n return wrapList(editor, { type: options.type, at })\n }\n\n if (ancestor.type === options.type) {\n unwrapList(editor, { at })\n } else {\n Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath })\n }\n}\n","import type { KeyboardEvent } from 'react'\nimport { Editor, Transforms, Range, Node, PathRef, Text } from 'slate'\nimport isHotkey from 'is-hotkey'\nimport { LIST_ITEM_CHILD_POSITION } from './constants'\nimport { EditorUtils } from '../utils/editor'\nimport { ElementUtils } from '../utils/element'\nimport { dedent } from './dedent'\nimport { indent } from './indent'\nimport { toggleList } from './toggleList'\nimport { unwrapList } from './unwrapList'\nimport { wrapList } from './wrapList'\nimport { BlockType } from '../../controls'\n\nexport const List = {\n unwrapList,\n wrapList,\n indent,\n dedent,\n toggleList,\n}\n\nexport function onKeyDown(e: KeyboardEvent, editor: Editor) {\n if (\n !editor.selection ||\n Array.from(Editor.nodes(editor, { match: node => ElementUtils.isListItem(node) })).length === 0\n )\n return\n\n if (isHotkey('shift+tab', e)) {\n e.preventDefault()\n List.dedent(editor)\n }\n\n if (isHotkey('tab', e)) {\n e.preventDefault()\n List.indent(editor)\n }\n\n if (isHotkey('backspace', e)) {\n if (!editor.selection) return\n if (Range.isExpanded(editor.selection)) return\n const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path)\n if (editor.selection.anchor.offset === 0 && listItem) {\n e.preventDefault()\n const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1])\n const list = EditorUtils.getFirstAncestorList(editor, listItem[1])\n\n if (parentListItem) {\n List.dedent(editor)\n } else if (list) {\n List.unwrapList(editor)\n }\n return\n }\n }\n\n if (isHotkey('enter', e)) {\n e.preventDefault()\n\n if (!editor.selection) return\n\n if (Range.isExpanded(editor.selection)) {\n Transforms.delete(editor)\n return\n }\n\n const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path)\n if (\n editor.selection.anchor.offset === 0 &&\n listItem &&\n Editor.string(editor, listItem[1]) === ''\n ) {\n const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1])\n\n if (parentListItem) {\n List.dedent(editor)\n } else {\n List.unwrapList(editor)\n }\n return\n }\n\n Transforms.splitNodes(editor, {\n at: editor.selection,\n always: true,\n match: node => ElementUtils.isListItem(node),\n })\n }\n\n if (isHotkey('shift+enter', e)) {\n e.preventDefault()\n editor.insertText('\\n')\n }\n}\n\nexport function withList(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n\n // Normalization for converting children of list items to list item children\n // In the case of backspace from position 0 of node into a list this converts the node into a list item.\n if (ElementUtils.isListItem(normalizationNode)) {\n const pathToListItemText = [...normalizationPath, LIST_ITEM_CHILD_POSITION]\n\n if (Node.has(editor, pathToListItemText)) {\n const nodeInListItemTextPosition = Node.get(editor, pathToListItemText)\n if (ElementUtils.isParagraph(nodeInListItemTextPosition)) {\n Transforms.setNodes(\n editor,\n { type: BlockType.ListItemChild },\n {\n at: pathToListItemText,\n },\n )\n return\n }\n } else {\n Transforms.insertNodes(editor, ElementUtils.createListItem(), {\n at: pathToListItemText,\n })\n return\n }\n }\n\n // Normalization for merging adjacent lists of the same type\n if (!Text.isText(normalizationNode)) {\n const mergeableChildren = Array.from(Node.children(editor, normalizationPath))\n .map((child, index, children) => {\n const potentialNodeToBeMerged = children.at(index + 1)\n if (\n !potentialNodeToBeMerged ||\n !ElementUtils.isList(potentialNodeToBeMerged[0]) ||\n !ElementUtils.isList(child[0]) ||\n potentialNodeToBeMerged[0].type !== child[0].type\n ) {\n return null\n }\n return [\n Editor.pathRef(editor, child[1]),\n Editor.pathRef(editor, potentialNodeToBeMerged[1]),\n ]\n })\n .filter((mergeableNodes): mergeableNodes is PathRef[] => Boolean(mergeableNodes))\n\n if (mergeableChildren.length !== 0) {\n mergeableChildren.reverse().forEach(([nodePathRef, nodeToBeMergedPathRef]) => {\n const nodePath = nodePathRef.current\n const nodeToBeMergedPath = nodeToBeMergedPathRef.current\n if (nodePath == null || nodeToBeMergedPath == null) return\n const nodeChildren = Array.from(Node.children(editor, nodePath))\n const childrenToBeMerged = Array.from(Node.children(editor, nodeToBeMergedPath))\n Editor.withoutNormalizing(editor, () => {\n childrenToBeMerged.reverse().forEach(([_, childPath]) => {\n Transforms.moveNodes(editor, {\n at: childPath,\n to: [...nodePath, nodeChildren.length],\n })\n })\n Transforms.removeNodes(editor, { at: nodeToBeMergedPath })\n })\n nodePathRef.unref()\n nodeToBeMergedPathRef.unref()\n })\n return\n }\n }\n\n normalizeNode(entry)\n }\n\n return editor\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../../controls'\n\ntype ClearActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function clearActiveTypographyStyle(\n editor: Editor,\n options?: ClearActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const typography: RichTextTypography = {\n ...node.typography,\n style: [],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../../controls'\n\ntype ClearDeviceActiveTypographyOptions = {\n at?: Range\n}\n\nexport function clearDeviceActiveTypography(\n editor: Editor,\n currentDeviceId: string,\n options?: ClearDeviceActiveTypographyOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const typography: RichTextTypography = {\n ...node.typography,\n style:\n node?.typography?.style.filter(({ deviceId }) => deviceId !== currentDeviceId) ?? [],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../../controls'\n\ntype SetActiveTypographyIdOptions = {\n at?: Range\n}\n\nexport function detachActiveTypography(\n editor: Editor,\n value: RichTextTypography['style'],\n options?: SetActiveTypographyIdOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n Transforms.setNodes(\n editor,\n {\n typography: {\n style: value,\n },\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\n\ntype SetActiveTypographyIdOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyId(\n editor: Editor,\n id?: string,\n options?: SetActiveTypographyIdOptions,\n) {\n const at = options?.at ?? editor.selection\n if (!at) return\n Transforms.setNodes(\n editor,\n {\n typography: {\n id,\n style: [],\n },\n },\n {\n at,\n match: node => Text.isText(node),\n split: Range.isExpanded(at),\n },\n )\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../../controls'\nimport { Breakpoints, findBreakpointOverride, BreakpointId } from '../../state/modules/breakpoints'\n\ntype SetActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyStyle(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: string,\n prop: string,\n value?: unknown,\n options?: SetActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const deviceOverrides = node?.typography?.style ?? []\n const deviceStyle = findBreakpointOverride(\n breakpoints,\n deviceOverrides,\n deviceId as BreakpointId,\n v => v,\n ) || {\n value: {},\n }\n const nextDeviceStyle = {\n deviceId,\n value: { ...deviceStyle.value, [prop]: value },\n }\n\n const nextTypography: RichTextTypography = {\n ...node.typography,\n style: [...deviceOverrides.filter(v => v.deviceId !== deviceId), nextDeviceStyle],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography: nextTypography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Text, Transforms } from 'slate'\nimport { clearActiveTypographyStyle } from './clearActiveTypographyStyle'\nimport { clearDeviceActiveTypography } from './clearDeviceActiveTypography'\nimport { detachActiveTypography } from './detachActiveTypography'\nimport { setActiveTypographyId } from './setActiveTypographyId'\nimport { setActiveTypographyStyle } from './setActiveTypographyStyle'\n\nexport const Typography = {\n setActiveTypographyId,\n setActiveTypographyStyle,\n clearActiveTypographyStyle,\n clearDeviceActiveTypography,\n detachActiveTypography,\n}\n\nexport function withTypography(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n if (\n Text.isText(normalizationNode) &&\n normalizationNode?.typography?.id == null &&\n normalizationNode?.typography?.style.length === 0\n ) {\n Transforms.unsetNodes(editor, 'typography', { at: normalizationPath })\n return\n }\n\n if (Text.isText(normalizationNode) && normalizationNode?.slice != null) {\n Transforms.unsetNodes(editor, 'slice', { at: normalizationPath })\n return\n }\n\n normalizeNode(entry)\n }\n\n return editor\n}\n","import { Editor, Range, Element, Text, Path } from 'slate'\n\n/**\n * The `Editor.unhangeRange` within Slate early exits if `Path.hasPrevious(end.path)` ie if this isn't a root block.\n * Unfortunately when you `setNode(..., {split:true})` or `wrapNodes()` you also have a hanging selection, but not in the root position.\n *\n * This c/p removes the `Path.hasPrevious(end.path)` from the early exit but it the same otherwise\n */\nfunction unhangRange(editor: Editor, range: Range): Range {\n // eslint-disable-next-line prefer-const\n let [start, end] = Range.edges(range)\n // PERF: exit early if we can guarantee that the range isn't hanging.\n if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) {\n return range\n }\n\n const endBlock = Editor.above(editor, {\n at: end,\n match: n => Element.isElement(n) && Editor.isBlock(editor, n),\n })\n const blockPath = endBlock ? endBlock[1] : []\n const first = Editor.start(editor, start)\n const before = { anchor: first, focus: end }\n let skip = true\n\n for (const [node, path] of Editor.nodes(editor, {\n at: before,\n match: Text.isText,\n reverse: true,\n })) {\n if (skip) {\n skip = false\n continue\n }\n\n if (node.text !== '' || Path.isBefore(path, blockPath)) {\n end = { path, offset: node.text.length }\n break\n }\n }\n\n return { anchor: start, focus: end }\n}\n\nexport default unhangRange\n","import { Editor, NodeEntry, Range, Text } from 'slate'\nimport { EditableBlockKey } from './BlockPlugin/types'\nimport { ElementUtils } from './utils/element'\n\nimport unhangRange from './utils/unhangRange'\nimport shallowEqual from '../utils/shallowEqual'\nimport { isNonNullable } from '../utils/isNonNullable'\n\nimport {\n RootBlock,\n Inline,\n RootBlockType,\n ResponsiveBlockTextAlignment,\n BlockTextAlignment,\n RichTextTypography,\n} from '../controls'\nimport { Breakpoints, BreakpointId, findBreakpointOverride } from '../state/modules/breakpoints'\nimport deepEqual from '../utils/deepEqual'\nimport keys from '../utils/keys'\n\nexport function getSelection(editor: Editor): Range {\n if (editor.selection) return unhangRange(editor, editor.selection)\n return {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n }\n}\n\nexport function getBlocksInSelection(editor: Editor): NodeEntry<RootBlock>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => ElementUtils.isRootBlock(node),\n }),\n ).filter((entry): entry is NodeEntry<RootBlock> => ElementUtils.isRootBlock(entry[0]))\n}\n\nexport function getInlinesInSelection(editor: Editor): NodeEntry<Inline>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => ElementUtils.isInline(node),\n }),\n ).filter((entry): entry is NodeEntry<Inline> => ElementUtils.isInline(entry[0]))\n}\n\nexport function getActiveBlockType(editor: Editor): RootBlockType | null {\n const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type)\n\n return rootBlocks.reduce<RootBlockType | null>(\n (a, b) => (a === b ? b : null),\n rootBlocks.at(0) ?? null,\n )\n}\n\nexport function getActiveBlockValue(editor: Editor, key: EditableBlockKey) {\n const blocks = getBlocksInSelection(editor)\n\n const active = blocks.map(\n ([block]) => block[key] ?? null,\n ) as (ResponsiveBlockTextAlignment | null)[]\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\nexport function getActiveBlockDeviceOverrideValue(\n editor: Editor,\n key: EditableBlockKey,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n) {\n const active: (BlockTextAlignment | null)[] = []\n const blocks = getBlocksInSelection(editor)\n\n blocks.forEach(([block]) => {\n const deviceOverride =\n findBreakpointOverride<BlockTextAlignment>(breakpoints, block[key], deviceId) || null\n active.push(deviceOverride?.value ?? null)\n })\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\n// Typography\n\nconst concat = (a: unknown[], b: unknown[]) => a.concat(b)\n\n// TODO: This is more cruft from trying to remove null from the typography type. This optimization is not worth it.\n/**\n * This is a c/p of the intersection of the utils from the root utils folder.\n * The only change is defaulting to undefined instead of to null.\n */\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | undefined } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce((acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = undefined\n\n return acc\n }, {} as { [K in keyof A]: A[K] | undefined })\n}\n\nconst fuseTypographyMarks = (\n values: Array<RichTextTypography | null | undefined>,\n breakpoints: Breakpoints,\n): RichTextTypography => {\n const devices = [\n ...new Set(\n values\n .filter(isNonNullable)\n .map(({ style }) => style.map(({ deviceId }) => deviceId))\n .reduce(concat, []),\n ),\n ] as BreakpointId[]\n\n return {\n id: values.map(v => v && v.id).reduce((a, b) => (a === b ? a : undefined)) ?? undefined,\n style: devices.map(deviceId =>\n values\n .map(\n v =>\n (v && findBreakpointOverride(breakpoints, v.style, deviceId)) || {\n deviceId,\n value: {},\n },\n )\n .reduce((acc, { value }) => {\n const a = intersection(acc.value, value)\n return {\n deviceId,\n value: a,\n }\n }),\n ),\n }\n}\n\nexport function getActiveTypographyMark(\n editor: Editor,\n breakpoints: Breakpoints,\n): RichTextTypography {\n const active: RichTextTypography[] = []\n\n const textNodes = Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Text.isText(node),\n })\n\n for (const [node] of textNodes) {\n if (Text.isText(node) && 'typography' in node && node.typography != undefined) {\n active.push(node.typography)\n }\n }\n return active.length === 0 ? { style: [] } : fuseTypographyMarks(active, breakpoints)\n}\n","import { Editor, Transforms, Location } from 'slate'\nimport { getBlocksInSelection } from '../selectors'\nimport { ElementUtils } from '../utils/element'\nimport { EditableBlockKey, EditableBlockValue } from './types'\nimport { Breakpoints, BreakpointId, findBreakpointOverride } from '../../state/modules/breakpoints'\n\ntype SetBlockKeyForDeviceOptions = {\n at?: Location\n}\n\nexport function setBlockKeyForDevice(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n key: EditableBlockKey,\n value: EditableBlockValue[number]['value'],\n options?: SetBlockKeyForDeviceOptions,\n) {\n const at = options?.at ?? editor.selection\n if (!at) return\n\n const rootElements = getBlocksInSelection(editor)\n\n for (const [node, path] of rootElements) {\n if (ElementUtils.isBlock(node)) {\n const deviceValues = node[key] ?? []\n const currentDeviceValue = findBreakpointOverride(breakpoints, deviceValues, deviceId, v => v)\n const nextDeviceValue = {\n ...currentDeviceValue,\n deviceId,\n value,\n }\n Transforms.setNodes(\n editor,\n {\n [key]: [...deviceValues.filter(v => v.deviceId !== deviceId), nextDeviceValue],\n },\n { at: path },\n )\n }\n }\n}\n","import { Editor, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { EditableBlockKey } from './types'\nimport { getBlocksInSelection } from '../selectors'\nimport { BreakpointId } from '../../state/modules/breakpoints'\n\nexport function clearBlockKeyForDevice(\n editor: Editor,\n deviceId: BreakpointId,\n key: EditableBlockKey,\n) {\n const rootElements = getBlocksInSelection(editor)\n\n for (const [node, path] of rootElements) {\n if (ElementUtils.isBlock(node)) {\n const deviceOverrides = node[key] ?? []\n Transforms.setNodes(\n editor,\n {\n [key]: deviceOverrides.filter(v => v.deviceId !== deviceId),\n },\n { at: path },\n )\n }\n }\n}\n","import { Editor, Transforms } from 'slate'\nimport { getSelection } from '../selectors'\nimport { Inline } from '../../controls'\n\nexport function wrapInline(editor: Editor, inline: Inline) {\n Transforms.wrapNodes(editor, inline, {\n at: getSelection(editor),\n split: true,\n })\n}\n","import { Editor, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { getSelection } from '../selectors'\nimport { InlineType } from '../../controls'\n\nexport function unwrapInline(editor: Editor, type: InlineType) {\n Transforms.unwrapNodes(editor, {\n match: node => ElementUtils.isInline(node) && node.type === type,\n at: getSelection(editor),\n })\n}\n","import { Editor, Transforms } from 'slate'\nimport { setBlockKeyForDevice } from './setBlockKeyForDevice'\nimport { clearBlockKeyForDevice } from './clearBlockKeyForDevice'\nimport { wrapInline } from './wrapInline'\nimport { unwrapInline } from './unwrapInline'\nimport { ElementUtils } from '../utils/element'\n\nexport const Block = {\n setBlockKeyForDevice,\n clearBlockKeyForDevice,\n wrapInline,\n unwrapInline,\n}\n\nexport function withBlock(editor: Editor) {\n const { normalizeNode } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry)\n }\n\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n // Normalization textAlign with empty array of values\n if (ElementUtils.isBlock(normalizationNode) && normalizationNode?.textAlign?.length == 0) {\n Transforms.unsetNodes(editor, 'textAlign', { at: normalizationPath })\n return\n }\n\n normalizeNode(entry)\n }\n\n return editor\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAO,MAAM,2BAA2B;AACjC,MAAM,0BAA0B;ACahC,MAAM,eAAe;AAAA,EAC1B,YAAY,MAA+B;AACzC,WACE,QAAQ,UAAU,IAAI,cACb,cAAc,MAAM,UAAU,SAAS,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KAC9C,QAAQ,cAAc,MAAM,UAAU,QAAQ,KA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AW,YAAY,QAAQ;AAAA,IAC7B,OAAO,CAAQ,SAAA,aAAa,SAAS,IAAI,KAAK,KAAK,SAAS;AAAA,IAC5D,IAAI,aAAa,MAAM;AAAA,EAAA,CACxB;AACH;ACHO,MAAM,QAAQ;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,mBAAmB,QAAgB;AACxC,QAAM,EAAE,kBAAkB;AAE1B,SAAO,WAAW,CAAS,UAAA;AAClB,WAAA,aAAa,SAAS,KAAK;AAAA,EAAA;AAGpC,SAAO,gBAAgB,CAAS,UAAA;;AACxB,UAAA,CAAC,mBAAmB,qBAAqB;AAE/C,QAAI,aAAa,QAAQ,iBAAiB,KAAK,8DAAmB,cAAnB,mBAA8B,WAAU,GAAG;AACxF,iBAAW,WAAW,QAAQ,aAAa,EAAE,IAAI,mBAAmB;AACpE;AAAA,IACF;AAEA,kBAAc,KAAK;AAAA,EAAA;AAGd,SAAA;AACT;;"}
package/dist/index.es7.js CHANGED
@@ -36,7 +36,7 @@ import { cx } from "@emotion/css";
36
36
  import { g as getBox } from "./box-models.es.js";
37
37
  import { ax as BlockType, ay as InlineType, at as richTextDTOtoDAO, as as richTextDTOtoSelection, aA as BuilderEditMode } from "./descriptors.es.js";
38
38
  import { L as Leaf } from "./leaf.es.js";
39
- import { n as useStyle, o as useResponsiveStyle, u as useIsInBuilder, L as deepEqual, T as useBuilderEditMode, U as pollBoxModel } from "./index.es.js";
39
+ import { n as useStyle, o as useResponsiveStyle, u as useIsInBuilder, L as deepEqual, Q as useBuilderEditMode, T as pollBoxModel } from "./index.es.js";
40
40
  import { jsx } from "react/jsx-runtime";
41
41
  import { L as Link } from "./index.es3.js";
42
42
  import isHotkey from "is-hotkey";
@@ -1 +1 @@
1
- {"version":3,"file":"index.es7.js","sources":["../src/components/builtin/Text/components/Element/block.tsx","../src/components/builtin/Text/components/Element/inline.tsx","../src/components/builtin/Text/components/Element/element.tsx","../src/components/builtin/Text/EditableText/useSyncWithBuilder.tsx","../src/components/builtin/Text/EditableText/useSyncDOMSelection.tsx","../src/components/builtin/Text/EditableText/editable-text.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { RenderElementProps } from 'slate-react'\nimport { Block, BlockType } from '../../../../../controls'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { useResponsiveStyle } from '../../../../utils/responsive-style'\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Block\n}\n\nexport function BlockElement({ element, attributes, children }: InlineRenderElementProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([element.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n switch (element.type) {\n case BlockType.Paragraph:\n return (\n <p {...attributes} className={cx(...blockStyles)}>\n {children}\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote\n {...attributes}\n className={cx(\n ...blockStyles,\n useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n }),\n )}\n >\n {children}\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li {...attributes} className={cx(...blockStyles)}>\n {children}\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { RenderElementProps } from 'slate-react'\nimport { Inline, InlineType } from '../../../../../controls'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { Link } from '../../../../shared/Link'\n\nfunction StyledLink({ className, ...restOfProps }: ComponentPropsWithoutRef<typeof Link>) {\n return <Link {...restOfProps} className={cx(useStyle({ textDecoration: 'none' }), className)} />\n}\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Inline\n}\n\nexport function InlineElement({ element, attributes, children }: InlineRenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n case InlineType.Link:\n return (\n <StyledLink {...attributes} link={element.link}>\n {children}\n </StyledLink>\n )\n }\n}\n","import { RenderElementProps } from 'slate-react'\nimport { BlockType, InlineType } from '../../../../../controls'\nimport { BlockElement } from './block'\nimport { InlineElement } from './inline'\n\nexport function Element({ element, ...props }: RenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n case InlineType.SuperScript:\n case InlineType.SubScript:\n case InlineType.Link:\n return <InlineElement element={element} {...props} />\n case BlockType.Paragraph:\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement element={element} {...props} />\n default:\n return <span {...props.attributes}>{props.children}</span>\n }\n}\n","import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { richTextDTOtoDAO, richTextDTOtoSelection } from '../../../../controls'\nimport { RichTextValue } from '../../../../prop-controllers'\nimport deepEqual from '../../../../utils/deepEqual'\nimport { useIsInBuilder } from '../../../../react'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextValue) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n","import { ReactEditor } from 'slate-react'\nimport { useIsomorphicLayoutEffect } from '../../../hooks/useIsomorphicLayoutEffect'\nimport { Editor, Range as SlateRange } from 'slate'\n\n/**\n * Clicking outside of the host blurs our `<Editable />`.\n * `<Editable />` only updates the DOM's selection to match slate when it is focused.\n * In the case of a panel being clicked this hook updates the DOM selection to match slate.\n */\nexport function useSyncDOMSelection(editor: Editor, isEnabled: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled || editor.selection == null || ReactEditor.isFocused(editor)) return\n try {\n const root = ReactEditor.findDocumentOrShadowRoot(editor) as Document\n const domSelection = root.getSelection()\n const newDomRange: Range | null = ReactEditor.toDOMRange(editor, editor.selection)\n\n if (newDomRange) {\n if (SlateRange.isBackward(editor.selection!)) {\n domSelection?.setBaseAndExtent(\n newDomRange.endContainer,\n newDomRange.endOffset,\n newDomRange.startContainer,\n newDomRange.startOffset,\n )\n } else {\n domSelection?.setBaseAndExtent(\n newDomRange.startContainer,\n newDomRange.startOffset,\n newDomRange.endContainer,\n newDomRange.endOffset,\n )\n }\n } else {\n domSelection?.removeAllRanges()\n }\n } catch (e) {\n console.error(e)\n }\n })\n}\n","import {\n FocusEvent,\n forwardRef,\n KeyboardEvent,\n Ref,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react'\n\nimport { createEditor } from 'slate'\nimport { Slate, Editable, withReact, ReactEditor } from 'slate-react'\n\nimport { ElementIDValue, RichTextValue } from '../../../../prop-controllers/descriptors'\nimport { cx } from '@emotion/css'\nimport { DescriptorsPropControllers } from '../../../../prop-controllers/instances'\nimport { Descriptors } from '../../../../runtimes/react/controls/rich-text'\nimport { getBox } from '../../../../box-model'\nimport { PropControllersHandle } from '../../../../state/modules/prop-controller-handles'\nimport { BlockType, RichTextDAO, richTextDTOtoDAO } from '../../../../controls'\nimport { Leaf } from '../components/Leaf'\nimport { Element } from '../components/Element'\nimport { useSyncWithBuilder } from './useSyncWithBuilder'\nimport isHotkey from 'is-hotkey'\nimport { useBuilderEditMode } from '../../../../runtimes/react'\nimport { BuilderEditMode } from '../../../../state/modules/builder-edit-mode'\nimport { onKeyDown, withBlock, withList, withTypography } from '../../../../slate'\nimport { pollBoxModel } from '../../../../runtimes/react/poll-box-model'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst defaultText: RichTextDAO = [{ type: BlockType.Paragraph, children: [{ text: '' }] }]\n\nexport const EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<PropControllersHandle<Descriptors>>,\n) {\n const [editor] = useState(() => withBlock(withTypography(withList(withReact(createEditor())))))\n const [isPreservingDOMSElection, setIsPreservingDOMSelection] = useState(false)\n useSyncDOMSelection(editor, isPreservingDOMSElection)\n const delaySync = useSyncWithBuilder(editor, text)\n const editMode = useBuilderEditMode()\n\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n if (controller == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getDomNode() {\n return ReactEditor.toDOMNode(editor, editor)\n },\n getBoxModel() {\n return getBox(ReactEditor.toDOMNode(editor, editor))\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n const initialValue = useMemo(() => (text ? richTextDTOtoDAO(text) : defaultText), [text])\n\n useEffect(() => {\n controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n const handleFocus = useCallback(() => {\n controller?.focus()\n setIsPreservingDOMSelection(true)\n }, [controller])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return controller?.redo()\n if (isHotkey('mod+z', e)) return controller?.undo()\n if (isHotkey('escape')(e)) return controller?.blur()\n onKeyDown(e, editor)\n },\n [controller, editor],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // When clicking outside of the iframe (`relatedTarget` is null) we want to preserve the DOM selection.\n if (e.relatedTarget == null) return\n // Otherwise we want to deselect on blur and stop preserving selection.\n setIsPreservingDOMSelection(false)\n ReactEditor.deselect(editor)\n }, [])\n\n return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n className={cx(width, margin)}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["element","attributes","children","blockStyles","useStyle","margin","useResponsiveStyle","textAlign","type","BlockType","Paragraph","cx","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","padding","fontSize","fontWeight","borderLeft","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","className","restOfProps","textDecoration","InlineType","Code","SuperScript","SubScript","Link","link","props","COMMIT_DEBOUNCE_DELAY","editor","text","shouldCommit","setShouldCommit","useState","isInBuilder","useIsInBuilder","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","isEnabled","useIsomorphicLayoutEffect","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withList","withReact","createEditor","isPreservingDOMSElection","setIsPreservingDOMSelection","useSyncDOMSelection","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","isHotkey","redo","undo","blur","onKeyDown","handleBlur","relatedTarget","deselect","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAU6B,sBAAA;AAAA,EAAEA;AAAAA,EAASC;AAAAA,EAAYC;AAAAA,GAAsC;AAClFC,QAAAA,cAAc,CAClBC,SAAS;AAAA,IAAEC,QAAQ;AAAA,EAAA,CAAX,GACRD,SAASE,mBAAmB,CAACN,QAAQO,SAAT,GAAqB,CAAC,CAACA,YAAY,YAAa;AAAA,IAAEA;AAAAA,EAAAA,EAAnD,CAAnB,CAFU;AAKZP,UAAAA,QAAQQ;AAAAA,SACTC,UAAUC;AACb,uEACST;QAAY,WAAWU,GAAG,GAAGR,WAAJ;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,MACZ,eAAeC;AAAAA,MACf,SAASZ;AAAAA,MACT,WAAWE;AAAAA,MACX,QAAQM;AAAAA,MACR,WAAW9G,GAAGyE,OAAO/E,MAAR;AAAA,MACb,UAAU2F,aAAa8B,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CATd;AAAA,EAAA,CAFJ;AAeD,CAnFqC;AAqFtC,IAAA,iBAAe9C;;"}
1
+ {"version":3,"file":"index.es7.js","sources":["../src/components/builtin/Text/components/Element/block.tsx","../src/components/builtin/Text/components/Element/inline.tsx","../src/components/builtin/Text/components/Element/element.tsx","../src/components/builtin/Text/EditableText/useSyncWithBuilder.tsx","../src/components/builtin/Text/EditableText/useSyncDOMSelection.tsx","../src/components/builtin/Text/EditableText/editable-text.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { RenderElementProps } from 'slate-react'\nimport { Block, BlockType } from '../../../../../controls'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { useResponsiveStyle } from '../../../../utils/responsive-style'\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Block\n}\n\nexport function BlockElement({ element, attributes, children }: InlineRenderElementProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([element.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n switch (element.type) {\n case BlockType.Paragraph:\n return (\n <p {...attributes} className={cx(...blockStyles)}>\n {children}\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote\n {...attributes}\n className={cx(\n ...blockStyles,\n useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n }),\n )}\n >\n {children}\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li {...attributes} className={cx(...blockStyles)}>\n {children}\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { RenderElementProps } from 'slate-react'\nimport { Inline, InlineType } from '../../../../../controls'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { Link } from '../../../../shared/Link'\n\nfunction StyledLink({ className, ...restOfProps }: ComponentPropsWithoutRef<typeof Link>) {\n return <Link {...restOfProps} className={cx(useStyle({ textDecoration: 'none' }), className)} />\n}\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Inline\n}\n\nexport function InlineElement({ element, attributes, children }: InlineRenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n case InlineType.Link:\n return (\n <StyledLink {...attributes} link={element.link}>\n {children}\n </StyledLink>\n )\n }\n}\n","import { RenderElementProps } from 'slate-react'\nimport { BlockType, InlineType } from '../../../../../controls'\nimport { BlockElement } from './block'\nimport { InlineElement } from './inline'\n\nexport function Element({ element, ...props }: RenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n case InlineType.SuperScript:\n case InlineType.SubScript:\n case InlineType.Link:\n return <InlineElement element={element} {...props} />\n case BlockType.Paragraph:\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement element={element} {...props} />\n default:\n return <span {...props.attributes}>{props.children}</span>\n }\n}\n","import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { richTextDTOtoDAO, richTextDTOtoSelection } from '../../../../controls'\nimport { RichTextValue } from '../../../../prop-controllers'\nimport deepEqual from '../../../../utils/deepEqual'\nimport { useIsInBuilder } from '../../../../runtimes/react'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextValue) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n","import { ReactEditor } from 'slate-react'\nimport { useIsomorphicLayoutEffect } from '../../../hooks/useIsomorphicLayoutEffect'\nimport { Editor, Range as SlateRange } from 'slate'\n\n/**\n * Clicking outside of the host blurs our `<Editable />`.\n * `<Editable />` only updates the DOM's selection to match slate when it is focused.\n * In the case of a panel being clicked this hook updates the DOM selection to match slate.\n */\nexport function useSyncDOMSelection(editor: Editor, isEnabled: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled || editor.selection == null || ReactEditor.isFocused(editor)) return\n try {\n const root = ReactEditor.findDocumentOrShadowRoot(editor) as Document\n const domSelection = root.getSelection()\n const newDomRange: Range | null = ReactEditor.toDOMRange(editor, editor.selection)\n\n if (newDomRange) {\n if (SlateRange.isBackward(editor.selection!)) {\n domSelection?.setBaseAndExtent(\n newDomRange.endContainer,\n newDomRange.endOffset,\n newDomRange.startContainer,\n newDomRange.startOffset,\n )\n } else {\n domSelection?.setBaseAndExtent(\n newDomRange.startContainer,\n newDomRange.startOffset,\n newDomRange.endContainer,\n newDomRange.endOffset,\n )\n }\n } else {\n domSelection?.removeAllRanges()\n }\n } catch (e) {\n console.error(e)\n }\n })\n}\n","import {\n FocusEvent,\n forwardRef,\n KeyboardEvent,\n Ref,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react'\n\nimport { createEditor } from 'slate'\nimport { Slate, Editable, withReact, ReactEditor } from 'slate-react'\n\nimport { ElementIDValue, RichTextValue } from '../../../../prop-controllers/descriptors'\nimport { cx } from '@emotion/css'\nimport { DescriptorsPropControllers } from '../../../../prop-controllers/instances'\nimport { Descriptors } from '../../../../runtimes/react/controls/rich-text'\nimport { getBox } from '../../../../box-model'\nimport { PropControllersHandle } from '../../../../state/modules/prop-controller-handles'\nimport { BlockType, RichTextDAO, richTextDTOtoDAO } from '../../../../controls'\nimport { Leaf } from '../components/Leaf'\nimport { Element } from '../components/Element'\nimport { useSyncWithBuilder } from './useSyncWithBuilder'\nimport isHotkey from 'is-hotkey'\nimport { useBuilderEditMode } from '../../../../runtimes/react'\nimport { BuilderEditMode } from '../../../../state/modules/builder-edit-mode'\nimport { onKeyDown, withBlock, withList, withTypography } from '../../../../slate'\nimport { pollBoxModel } from '../../../../runtimes/react/poll-box-model'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst defaultText: RichTextDAO = [{ type: BlockType.Paragraph, children: [{ text: '' }] }]\n\nexport const EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<PropControllersHandle<Descriptors>>,\n) {\n const [editor] = useState(() => withBlock(withTypography(withList(withReact(createEditor())))))\n const [isPreservingDOMSElection, setIsPreservingDOMSelection] = useState(false)\n useSyncDOMSelection(editor, isPreservingDOMSElection)\n const delaySync = useSyncWithBuilder(editor, text)\n const editMode = useBuilderEditMode()\n\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n if (controller == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getDomNode() {\n return ReactEditor.toDOMNode(editor, editor)\n },\n getBoxModel() {\n return getBox(ReactEditor.toDOMNode(editor, editor))\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n const initialValue = useMemo(() => (text ? richTextDTOtoDAO(text) : defaultText), [text])\n\n useEffect(() => {\n controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n const handleFocus = useCallback(() => {\n controller?.focus()\n setIsPreservingDOMSelection(true)\n }, [controller])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return controller?.redo()\n if (isHotkey('mod+z', e)) return controller?.undo()\n if (isHotkey('escape')(e)) return controller?.blur()\n onKeyDown(e, editor)\n },\n [controller, editor],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // When clicking outside of the iframe (`relatedTarget` is null) we want to preserve the DOM selection.\n if (e.relatedTarget == null) return\n // Otherwise we want to deselect on blur and stop preserving selection.\n setIsPreservingDOMSelection(false)\n ReactEditor.deselect(editor)\n }, [])\n\n return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n className={cx(width, margin)}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["element","attributes","children","blockStyles","useStyle","margin","useResponsiveStyle","textAlign","type","BlockType","Paragraph","cx","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","padding","fontSize","fontWeight","borderLeft","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","className","restOfProps","textDecoration","InlineType","Code","SuperScript","SubScript","Link","link","props","COMMIT_DEBOUNCE_DELAY","editor","text","shouldCommit","setShouldCommit","useState","isInBuilder","useIsInBuilder","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","isEnabled","useIsomorphicLayoutEffect","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withList","withReact","createEditor","isPreservingDOMSElection","setIsPreservingDOMSelection","useSyncDOMSelection","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","isHotkey","redo","undo","blur","onKeyDown","handleBlur","relatedTarget","deselect","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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yCAAYmB;AAC9CC,cAAU3C,GAAGtC,MAAJ;AAAA,EAAA,GAEX,CAAC6D,YAAY7D,MAAb,CAP+B;AAU3BkF,QAAAA,aAAa/D,YAAY,CAACmB,MAAkB;AAEhD,QAAIA,EAAE6C,iBAAiB;AAAM;AAE7B9B,gCAA4B,KAAD;AAC3B/B,gBAAY8D,SAASpF,MAArB;AAAA,EAL4B,GAM3B,CAN2B,CAAA;AAQ9B,6BACG,OAAD;AAAA,IAAO;AAAA,IAAgB,OAAOuE;AAAAA,IAAc,UAAUhB;AAAAA,IAAtD,8BACG,UAAD;AAAA,MACE;AAAA,MACA,YAAY8B;AAAAA,MACZ,eAAeC;AAAAA,MACf,SAASZ;AAAAA,MACT,WAAWE;AAAAA,MACX,QAAQM;AAAAA,MACR,WAAW9G,GAAGyE,OAAO/E,MAAR;AAAA,MACb,UAAU2F,aAAa8B,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CATd;AAAA,EAAA,CAFJ;AAeD,CAnFqC;AAqFtC,IAAA,iBAAe9C;;"}
package/dist/leaf.es.js CHANGED
@@ -29,7 +29,7 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
- import { V as useTypography, s as useBreakpoints, I as useSwatches, n as useStyle, o as useResponsiveStyle, r as colorToString } from "./index.es.js";
32
+ import { U as useTypography, s as useBreakpoints, I as useSwatches, n as useStyle, o as useResponsiveStyle, r as colorToString } from "./index.es.js";
33
33
  import { j as isNonNullable } from "./introspection.es.js";
34
34
  import { findBreakpointOverride, shallowMergeFallbacks } from "./state/breakpoints.es.js";
35
35
  import { jsx } from "react/jsx-runtime";
package/dist/next.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "react";
2
- export { a0 as Document, _ as Makeswift, a1 as MakeswiftApiHandler, Z as Page, $ as PreviewModeScript, F as forwardNextDynamicRef, Y as getServerSideProps, W as getStaticPaths, X as getStaticProps } from "./index.es.js";
2
+ export { $ as Document, Z as Makeswift, a0 as MakeswiftApiHandler, Y as Page, _ as PreviewModeScript, F as forwardNextDynamicRef, X as getServerSideProps, V as getStaticPaths, W as getStaticProps } from "./index.es.js";
3
3
  import "react/jsx-runtime";
4
4
  import "use-sync-external-store/shim/with-selector";
5
5
  import "next/dynamic";
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
3
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -15,6 +17,7 @@ var __spreadValues = (a, b) => {
15
17
  }
16
18
  return a;
17
19
  };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
18
21
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
19
22
  var actions = require("../actions.cjs.js");
20
23
  const keys = (o) => Object.keys(o);
@@ -59,8 +62,8 @@ const DEFAULT_BREAKPOINTS = [
59
62
  viewportWidth: 390
60
63
  }
61
64
  ];
62
- function getInitialState() {
63
- return DEFAULT_BREAKPOINTS;
65
+ function getInitialState(breakpoints = DEFAULT_BREAKPOINTS) {
66
+ return breakpoints;
64
67
  }
65
68
  function reducer(state = getInitialState(), action) {
66
69
  switch (action.type) {
@@ -75,14 +78,45 @@ function reducer(state = getInitialState(), action) {
75
78
  }
76
79
  }
77
80
  function parseBreakpointsInput(input) {
78
- const breakpoints = Object.entries(input).map(([id, { label, min, max, viewport }]) => ({
79
- id,
80
- label: label != null ? label : id,
81
- minWidth: min,
82
- maxWidth: max,
83
- viewportWidth: viewport
84
- }));
85
- return sortBreakpoints(breakpoints);
81
+ validateBreakpointsInput(input);
82
+ const sorted = Object.entries(input).map(([id, value]) => __spreadProps(__spreadValues({}, value), { id })).sort((a, b) => b.width - a.width);
83
+ const transformed = sorted.reduce((prev, curr, index, array) => {
84
+ const { width, viewport, id, label } = curr;
85
+ const next = array[index + 1];
86
+ const breakpoint = __spreadProps(__spreadValues(__spreadValues({
87
+ id
88
+ }, label && { label }), next && { minWidth: next.width + 1 }), {
89
+ maxWidth: width,
90
+ viewportWidth: viewport != null ? viewport : width
91
+ });
92
+ return [...prev, breakpoint];
93
+ }, [
94
+ { id: DefaultBreakpointID.Desktop, label: "Desktop", minWidth: sorted[0].width + 1 }
95
+ ]);
96
+ return transformed;
97
+ }
98
+ function validateBreakpointsInput(input) {
99
+ if (DefaultBreakpointID.Desktop in input) {
100
+ throw new Error(`Cannot change the base breakpoint. "${DefaultBreakpointID.Desktop}" is reserved as the base breakpoint.`);
101
+ }
102
+ if (Object.keys(input).length === 0) {
103
+ throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`);
104
+ }
105
+ const sorted = Object.entries(input).map(([id, value]) => __spreadProps(__spreadValues({}, value), { id })).sort((a, b) => b.width - a.width);
106
+ sorted.forEach(({ id, width, viewport }, index, array) => {
107
+ if (viewport && viewport > width) {
108
+ throw new Error(`Error on breakpoint "${id}". Viewport cannot be greater than its width.
109
+ "${id}" has a viewport of ${viewport}px and a width of ${width}px.`);
110
+ }
111
+ const next = array[index + 1];
112
+ if (viewport && next && viewport < next.width) {
113
+ throw new Error(`Error on breakpoint "${id}". Viewport cannot be smaller than the next breakpoint's width.
114
+ "${id}" has a viewport of ${viewport}px and the next breakpoint "${next.id}" has a width of ${next.width}px.`);
115
+ }
116
+ if (next && width === next.width) {
117
+ throw new Error(`Breakpoints cannot have the same width. "${id}" and "${next.id}" have the same width`);
118
+ }
119
+ });
86
120
  }
87
121
  function sortBreakpoints(breakpoints) {
88
122
  return breakpoints.sort((a, b) => {
@@ -1 +1 @@
1
- {"version":3,"file":"breakpoints.cjs.js","sources":["../../src/utils/keys.ts","../../src/utils/coalesce.ts","../../src/utils/shallowMerge.ts","../../src/state/modules/breakpoints.ts"],"sourcesContent":["const keys = <O extends { [key: string]: unknown }>(o: O): (keyof O)[] => Object.keys(o)\n\nexport default keys\n","const coalesce = <T>(...args: Array<T>): T => {\n let i: number\n\n for (i = 0; i < args.length - 1; i += 1) {\n if (args[i] != null) return args[i]\n }\n\n return args[i]\n}\n\nexport default coalesce\n","import keys from './keys'\nimport coalesce from './coalesce'\n\nexport default function shallowMerge<\n A extends Record<string, unknown>,\n B extends Record<string, unknown>,\n>(a: A, b: B): A & B {\n const bKeys = keys(b)\n const merged = { ...a } as A & B\n\n bKeys.forEach(key => {\n // @ts-expect-error: `coalesce` returns `null | undefined` regardless of input guarantees.\n merged[key] = coalesce(merged[key], b[key])\n })\n\n return merged\n}\n","import { Viewport } from 'csstype'\n\nimport {\n ResponsiveValue as PropControllerResponsiveValue,\n DeviceOverride as PropControllerDeviceOverride,\n Device as DeviceId,\n} from '../../prop-controllers'\nimport shallowMerge from '../../utils/shallowMerge'\nimport { Action, ActionTypes } from '../actions'\n\nexport type DeviceOverride<T> = PropControllerDeviceOverride<T>\nexport type ResponsiveValue<T> = PropControllerResponsiveValue<T>\nexport type BreakpointId = DeviceId\n\nexport type Breakpoint = {\n id: BreakpointId\n label: string\n viewportWidth?: number\n minWidth?: number\n maxWidth?: number\n}\n\nexport type Breakpoints = Breakpoint[]\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = typeof DefaultBreakpointID[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(): State {\n return DEFAULT_BREAKPOINTS\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<\n string,\n { label?: string; min?: number; max?: number; viewport?: number }\n>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n const breakpoints = Object.entries(input).map(([id, { label, min, max, viewport }]) => ({\n id,\n label: label ?? id,\n minWidth: min,\n maxWidth: max,\n viewportWidth: viewport,\n }))\n\n return sortBreakpoints(breakpoints)\n}\n\n// Sort breakpoints by minWidth in descending order\nfunction sortBreakpoints(breakpoints: Breakpoints): Breakpoints {\n return breakpoints.sort((a, b) => (b?.minWidth ?? 0) - (a?.minWidth ?? 0))\n}\n\nexport const getBreakpoint = (state: State, breakpointId: Breakpoint['id']): Breakpoint => {\n const breakpoint = state.find(({ id }) => id === breakpointId)\n\n if (breakpoint == null) throw new Error(`Unrecognized breakpoint ID: \"${breakpointId}\".`)\n\n return breakpoint\n}\n\nexport const getBaseBreakpoint = (breakpoints: Breakpoints): Breakpoint => {\n const breakpoint = sortBreakpoints(breakpoints)[0]\n\n if (breakpoint == null) throw new Error(`Cannot get base breakpoint.`)\n\n return breakpoint\n}\n\nexport function findBreakpointOverride<S>(\n breakpoints: Breakpoints,\n values: ResponsiveValue<S> = [],\n deviceId: string,\n strategy: FallbackStrategy<S> = defaultStrategy,\n): DeviceOverride<S> | undefined {\n const value = values.find(({ deviceId: d }) => d === deviceId)\n const fallbacks = breakpoints\n .slice(0, breakpoints.findIndex(d => d.id === deviceId) + 1)\n .reverse()\n .map(d => values.find(v => v.deviceId === d.id))\n .filter((override): override is DeviceOverride<S> => Boolean(override))\n\n return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : undefined\n}\n\nexport type FallbackStrategy<V> = (\n arg0: DeviceOverride<V> | undefined,\n arg1: ResponsiveValue<V>,\n) => DeviceOverride<V> | undefined\n\nfunction defaultStrategy<V>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return value || fallbacks[0]\n}\n\nexport function shallowMergeFallbacks<V extends Record<string, unknown>>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return [value, ...fallbacks]\n .filter((override): override is DeviceOverride<V> => Boolean(override))\n .reduce((a, b) => ({\n deviceId: a.deviceId || b.deviceId,\n value: shallowMerge(a.value, b.value),\n }))\n}\n\nexport type ExtractResponsiveValue<T> = T extends ResponsiveValue<infer V> ? V : never\n\nexport function join<V, A extends ReadonlyArray<ResponsiveValue<V> | null | undefined>, R>(\n breakpoints: Breakpoints,\n responsiveValues: A,\n joinFn: (values: { [I in keyof A]: ExtractResponsiveValue<A[I]> | undefined }) => R,\n strategy?: FallbackStrategy<V>,\n): ResponsiveValue<R> {\n return breakpoints\n .map(({ id }) => id)\n .map(deviceId => {\n const value = joinFn(\n responsiveValues.map(responsiveValue => {\n const deviceValue =\n responsiveValue &&\n findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy)\n\n return deviceValue == null ? undefined : deviceValue.value\n }) as unknown as { [I in keyof A]: ExtractResponsiveValue<A[I] | undefined> },\n )\n\n if (value == null) return null\n\n return { deviceId, value }\n })\n .filter((override): override is DeviceOverride<R> => Boolean(override))\n}\n\nexport const getBreakpointMediaQuery = (breakpoint: Breakpoint): string => {\n const parts = ['@media only screen']\n\n if (breakpoint.minWidth != null) {\n parts.push(`(min-width: ${breakpoint.minWidth}px)`)\n }\n\n if (breakpoint.maxWidth != null) {\n parts.push(`(max-width: ${breakpoint.maxWidth}px)`)\n }\n\n return parts.join(' and ')\n}\n\nexport const getViewportStyle = (\n state: State,\n deviceId: string,\n): Viewport<string | number> | null | undefined => {\n const device = getBreakpoint(state, deviceId)\n\n return (\n device && {\n width: device.viewportWidth != null ? device.viewportWidth : '100%',\n minWidth: device.minWidth,\n }\n )\n}\n\nexport function findNextFallback<V>(\n breakpoints: Breakpoints,\n value: ResponsiveValue<V>,\n deviceId: BreakpointId,\n activeDeviceId: BreakpointId,\n fallbackStrategy?: FallbackStrategy<V>,\n): Breakpoint | null {\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n value.filter(v => v.deviceId !== activeDeviceId),\n deviceId,\n fallbackStrategy,\n )\n\n return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null\n}\n\nexport const mergeResponsiveValues = <A>(\n breakpoints: Breakpoints,\n source: DeviceOverride<A>[],\n override: DeviceOverride<A>[],\n): DeviceOverride<A>[] => {\n const devices = [\n ...new Set(\n source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId)),\n ),\n ]\n\n return devices.map(deviceId => ({\n deviceId,\n value: {\n ...(findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value,\n ...(findBreakpointOverride(breakpoints, override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n"],"names":["ActionTypes"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,MAAM,OAAO,CAAuC,MAAsB,OAAO,KAAK,CAAC;ACAvF,MAAM,WAAW,IAAO,SAAsB;AACxC,MAAA;AAEJ,OAAK,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG;AACvC,QAAI,KAAK,MAAM;AAAM,aAAO,KAAK;AAAA,EACnC;AAEA,SAAO,KAAK;AACd;ACLA,sBAGE,GAAM,GAAa;AACb,QAAA,QAAQ,KAAK,CAAC;AACd,QAAA,SAAS,mBAAK;AAEpB,QAAM,QAAQ,CAAO,QAAA;AAEnB,WAAO,OAAO,SAAS,OAAO,MAAM,EAAE,IAAI;AAAA,EAAA,CAC3C;AAEM,SAAA;AACT;ACUO,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,s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A,QAAQ,CAAC,oBAAoB;AAE/B,MAAA,WAAW,YAAY,MAAM;AACzB,UAAA,KAAK,eAAe,WAAW,aAAa;AAAA,EACpD;AAEI,MAAA,WAAW,YAAY,MAAM;AACzB,UAAA,KAAK,eAAe,WAAW,aAAa;AAAA,EACpD;AAEO,SAAA,MAAM,KAAK,OAAO;AAC3B;AAEa,MAAA,mBAAmB,CAC9B,OACA,aACiD;AAC3C,QAAA,SAAS,cAAc,OAAO,QAAQ;AAE5C,SACE,UAAU;AAAA,IACR,OAAO,OAAO,iBAAiB,OAAO,OAAO,gBAAgB;AAAA,IAC7D,UAAU,OAAO;AAAA,EAAA;AAGvB;AAEO,0BACL,aACA,OACA,UACA,gBACA,kBACmB;;AACb,QAAA,iBAAiB,uBACrB,aACA,MAAM,OAAO,CAAK,MAAA,EAAE,aAAa,cAAc,GAC/C,UACA,gBACF;AAEA,SAA0B,wBAAA,cAAc,aAAa,eAAe,QAAQ,MAAlD,YAAwD;AACpF;AAEO,MAAM,wBAAwB,CACnC,aACA,QACA,aACwB;AACxB,QAAM,UAAU;AAAA,IACd,GAAG,IAAI,IACL,OAAO,IAAI,CAAC,EAAE,eAAe,QAAQ,EAAE,OAAO,SAAS,IAAI,CAAC,EAAE,eAAe,QAAQ,CAAC,CACxF;AAAA,EAAA;AAGK,SAAA,QAAQ,IAAI,CAAa,aAAA;AAAA,IAC9B;AAAA,IACA,OAAO,kCACD,wBAAuB,aAAa,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC,EAAA,GAAK,QACxE,wBAAuB,aAAa,UAAU,UAAU,CAAA,MAAK,CAAC,KAAK,EAAE,OAAO,CAAA,EAAM,GAAA;AAAA,EAExF,EAAA;AACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"breakpoints.cjs.js","sources":["../../src/utils/keys.ts","../../src/utils/coalesce.ts","../../src/utils/shallowMerge.ts","../../src/state/modules/breakpoints.ts"],"sourcesContent":["const keys = <O extends { [key: string]: unknown }>(o: O): (keyof O)[] => Object.keys(o)\n\nexport default keys\n","const coalesce = <T>(...args: Array<T>): T => {\n let i: number\n\n for (i = 0; i < args.length - 1; i += 1) {\n if (args[i] != null) return args[i]\n }\n\n return args[i]\n}\n\nexport default coalesce\n","import keys from './keys'\nimport coalesce from './coalesce'\n\nexport default function shallowMerge<\n A extends Record<string, unknown>,\n B extends Record<string, unknown>,\n>(a: A, b: B): A & B {\n const bKeys = keys(b)\n const merged = { ...a } as A & B\n\n bKeys.forEach(key => {\n // @ts-expect-error: `coalesce` returns `null | undefined` regardless of input guarantees.\n merged[key] = coalesce(merged[key], b[key])\n })\n\n return merged\n}\n","import { Viewport } from 'csstype'\n\nimport {\n ResponsiveValue as PropControllerResponsiveValue,\n DeviceOverride as PropControllerDeviceOverride,\n Device as DeviceId,\n} from '../../prop-controllers'\nimport shallowMerge from '../../utils/shallowMerge'\nimport { Action, ActionTypes } from '../actions'\n\nexport type DeviceOverride<T> = PropControllerDeviceOverride<T>\nexport type ResponsiveValue<T> = PropControllerResponsiveValue<T>\nexport type BreakpointId = DeviceId\n\nexport type Breakpoint = {\n id: BreakpointId\n label?: string\n viewportWidth?: number\n minWidth?: number\n maxWidth?: number\n}\n\nexport type Breakpoints = Breakpoint[]\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = typeof DefaultBreakpointID[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(breakpoints = DEFAULT_BREAKPOINTS): State {\n return breakpoints\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<string, { width: number; label?: string; viewport?: number }>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n validateBreakpointsInput(input)\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n const transformed = sorted.reduce(\n (prev, curr, index, array) => {\n const { width, viewport, id, label } = curr\n const next = array[index + 1]\n\n const breakpoint: Breakpoint = {\n id,\n ...(label && { label }),\n ...(next && { minWidth: next.width + 1 }),\n maxWidth: width,\n viewportWidth: viewport ?? width,\n }\n\n return [...prev, breakpoint]\n },\n [\n { id: DefaultBreakpointID.Desktop, label: 'Desktop', minWidth: sorted[0].width + 1 },\n ] as Breakpoints,\n )\n\n return transformed\n}\n\nfunction validateBreakpointsInput(input: BreakpointsInput) {\n if (DefaultBreakpointID.Desktop in input) {\n throw new Error(\n `Cannot change the base breakpoint. \"${DefaultBreakpointID.Desktop}\" is reserved as the base breakpoint.`,\n )\n }\n\n if (Object.keys(input).length === 0) {\n throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`)\n }\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n sorted.forEach(({ id, width, viewport }, index, array) => {\n // This is only valid for desktop-first. We need to check the inverse for mobile-first.\n if (viewport && viewport > width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be greater than its width.\n \"${id}\" has a viewport of ${viewport}px and a width of ${width}px.`,\n )\n }\n\n const next = array[index + 1]\n\n if (viewport && next && viewport < next.width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be smaller than the next breakpoint's width. \n \"${id}\" has a viewport of ${viewport}px and the next breakpoint \"${next.id}\" has a width of ${next.width}px.`,\n )\n }\n\n if (next && width === next.width) {\n throw new Error(\n `Breakpoints cannot have the same width. \"${id}\" and \"${next.id}\" have the same width`,\n )\n }\n })\n}\n\n// Sort breakpoints by minWidth in descending order\nfunction sortBreakpoints(breakpoints: Breakpoints): Breakpoints {\n return breakpoints.sort((a, b) => (b?.minWidth ?? 0) - (a?.minWidth ?? 0))\n}\n\nexport const getBreakpoint = (state: State, breakpointId: Breakpoint['id']): Breakpoint => {\n const breakpoint = state.find(({ id }) => id === breakpointId)\n\n if (breakpoint == null) throw new Error(`Unrecognized breakpoint ID: \"${breakpointId}\".`)\n\n return breakpoint\n}\n\nexport const getBaseBreakpoint = (breakpoints: Breakpoints): Breakpoint => {\n const breakpoint = sortBreakpoints(breakpoints)[0]\n\n if (breakpoint == null) throw new Error(`Cannot get base breakpoint.`)\n\n return breakpoint\n}\n\nexport function findBreakpointOverride<S>(\n breakpoints: Breakpoints,\n values: ResponsiveValue<S> = [],\n deviceId: string,\n strategy: FallbackStrategy<S> = defaultStrategy,\n): DeviceOverride<S> | undefined {\n const value = values.find(({ deviceId: d }) => d === deviceId)\n const fallbacks = breakpoints\n .slice(0, breakpoints.findIndex(d => d.id === deviceId) + 1)\n .reverse()\n .map(d => values.find(v => v.deviceId === d.id))\n .filter((override): override is DeviceOverride<S> => Boolean(override))\n\n return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : undefined\n}\n\nexport type FallbackStrategy<V> = (\n arg0: DeviceOverride<V> | undefined,\n arg1: ResponsiveValue<V>,\n) => DeviceOverride<V> | undefined\n\nfunction defaultStrategy<V>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return value || fallbacks[0]\n}\n\nexport function shallowMergeFallbacks<V extends Record<string, unknown>>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return [value, ...fallbacks]\n .filter((override): override is DeviceOverride<V> => Boolean(override))\n .reduce((a, b) => ({\n deviceId: a.deviceId || b.deviceId,\n value: shallowMerge(a.value, b.value),\n }))\n}\n\nexport type ExtractResponsiveValue<T> = T extends ResponsiveValue<infer V> ? V : never\n\nexport function join<V, A extends ReadonlyArray<ResponsiveValue<V> | null | undefined>, R>(\n breakpoints: Breakpoints,\n responsiveValues: A,\n joinFn: (values: { [I in keyof A]: ExtractResponsiveValue<A[I]> | undefined }) => R,\n strategy?: FallbackStrategy<V>,\n): ResponsiveValue<R> {\n return breakpoints\n .map(({ id }) => id)\n .map(deviceId => {\n const value = joinFn(\n responsiveValues.map(responsiveValue => {\n const deviceValue =\n responsiveValue &&\n findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy)\n\n return deviceValue == null ? undefined : deviceValue.value\n }) as unknown as { [I in keyof A]: ExtractResponsiveValue<A[I] | undefined> },\n )\n\n if (value == null) return null\n\n return { deviceId, value }\n })\n .filter((override): override is DeviceOverride<R> => Boolean(override))\n}\n\nexport const getBreakpointMediaQuery = (breakpoint: Breakpoint): string => {\n const parts = ['@media only screen']\n\n if (breakpoint.minWidth != null) {\n parts.push(`(min-width: ${breakpoint.minWidth}px)`)\n }\n\n if (breakpoint.maxWidth != null) {\n parts.push(`(max-width: ${breakpoint.maxWidth}px)`)\n }\n\n return parts.join(' and ')\n}\n\nexport const getViewportStyle = (\n state: State,\n deviceId: string,\n): Viewport<string | number> | null | undefined => {\n const device = getBreakpoint(state, deviceId)\n\n return (\n device && {\n width: device.viewportWidth != null ? device.viewportWidth : '100%',\n minWidth: device.minWidth,\n }\n )\n}\n\nexport function findNextFallback<V>(\n breakpoints: Breakpoints,\n value: ResponsiveValue<V>,\n deviceId: BreakpointId,\n activeDeviceId: BreakpointId,\n fallbackStrategy?: FallbackStrategy<V>,\n): Breakpoint | null {\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n value.filter(v => v.deviceId !== activeDeviceId),\n deviceId,\n fallbackStrategy,\n )\n\n return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null\n}\n\nexport const mergeResponsiveValues = <A>(\n breakpoints: Breakpoints,\n source: DeviceOverride<A>[],\n override: DeviceOverride<A>[],\n): DeviceOverride<A>[] => {\n const devices = [\n ...new Set(\n source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId)),\n ),\n ]\n\n return devices.map(deviceId => ({\n deviceId,\n value: {\n ...(findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value,\n ...(findBreakpointOverride(breakpoints, override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n"],"names":["ActionTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,OAAO,CAAuC,MAAsB,OAAO,KAAK,CAAC;ACAvF,MAAM,WAAW,IAAO,SAAsB;AACxC,MAAA;AAEJ,OAAK,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG;AACvC,QAAI,KAAK,MAAM;AAAM,aAAO,KAAK;AAAA,EACnC;AAEA,SAAO,KAAK;AACd;ACLA,sBAGE,GAAM,GAAa;AACb,QAAA,QAAQ,KAAK,CAAC;AACd,QAAA,SAAS,mBAAK;AAEpB,QAAM,QAAQ,CAAO,QAAA;AAEnB,WAAO,OAAO,SAAS,OAAO,MAAM,EAAE,IAAI;AAAA,EAAA,CAC3C;AAEM,SAAA;AACT;ACUO,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,sBAAmC;AAAA,EAC9C;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA;AAAA,IACE,IA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OAAO;AAC3B;AAEa,MAAA,mBAAmB,CAC9B,OACA,aACiD;AAC3C,QAAA,SAAS,cAAc,OAAO,QAAQ;AAE5C,SACE,UAAU;AAAA,IACR,OAAO,OAAO,iBAAiB,OAAO,OAAO,gBAAgB;AAAA,IAC7D,UAAU,OAAO;AAAA,EAAA;AAGvB;AAEO,0BACL,aACA,OACA,UACA,gBACA,kBACmB;;AACb,QAAA,iBAAiB,uBACrB,aACA,MAAM,OAAO,CAAK,MAAA,EAAE,aAAa,cAAc,GAC/C,UACA,gBACF;AAEA,SAA0B,wBAAA,cAAc,aAAa,eAAe,QAAQ,MAAlD,YAAwD;AACpF;AAEO,MAAM,wBAAwB,CACnC,aACA,QACA,aACwB;AACxB,QAAM,UAAU;AAAA,IACd,GAAG,IAAI,IACL,OAAO,IAAI,CAAC,EAAE,eAAe,QAAQ,EAAE,OAAO,SAAS,IAAI,CAAC,EAAE,eAAe,QAAQ,CAAC,CACxF;AAAA,EAAA;AAGK,SAAA,QAAQ,IAAI,CAAa,aAAA;AAAA,IAC9B;AAAA,IACA,OAAO,kCACD,wBAAuB,aAAa,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC,EAAA,GAAK,QACxE,wBAAuB,aAAa,UAAU,UAAU,CAAA,MAAK,CAAC,KAAK,EAAE,OAAO,CAAA,EAAM,GAAA;AAAA,EAExF,EAAA;AACJ;;;;;;;;;;;;;;;"}
@@ -1,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  import { A as ActionTypes } from "../actions.es.js";
18
21
  const keys = (o) => Object.keys(o);
19
22
  const coalesce = (...args) => {
@@ -57,8 +60,8 @@ const DEFAULT_BREAKPOINTS = [
57
60
  viewportWidth: 390
58
61
  }
59
62
  ];
60
- function getInitialState() {
61
- return DEFAULT_BREAKPOINTS;
63
+ function getInitialState(breakpoints = DEFAULT_BREAKPOINTS) {
64
+ return breakpoints;
62
65
  }
63
66
  function reducer(state = getInitialState(), action) {
64
67
  switch (action.type) {
@@ -73,14 +76,45 @@ function reducer(state = getInitialState(), action) {
73
76
  }
74
77
  }
75
78
  function parseBreakpointsInput(input) {
76
- const breakpoints = Object.entries(input).map(([id, { label, min, max, viewport }]) => ({
77
- id,
78
- label: label != null ? label : id,
79
- minWidth: min,
80
- maxWidth: max,
81
- viewportWidth: viewport
82
- }));
83
- return sortBreakpoints(breakpoints);
79
+ validateBreakpointsInput(input);
80
+ const sorted = Object.entries(input).map(([id, value]) => __spreadProps(__spreadValues({}, value), { id })).sort((a, b) => b.width - a.width);
81
+ const transformed = sorted.reduce((prev, curr, index, array) => {
82
+ const { width, viewport, id, label } = curr;
83
+ const next = array[index + 1];
84
+ const breakpoint = __spreadProps(__spreadValues(__spreadValues({
85
+ id
86
+ }, label && { label }), next && { minWidth: next.width + 1 }), {
87
+ maxWidth: width,
88
+ viewportWidth: viewport != null ? viewport : width
89
+ });
90
+ return [...prev, breakpoint];
91
+ }, [
92
+ { id: DefaultBreakpointID.Desktop, label: "Desktop", minWidth: sorted[0].width + 1 }
93
+ ]);
94
+ return transformed;
95
+ }
96
+ function validateBreakpointsInput(input) {
97
+ if (DefaultBreakpointID.Desktop in input) {
98
+ throw new Error(`Cannot change the base breakpoint. "${DefaultBreakpointID.Desktop}" is reserved as the base breakpoint.`);
99
+ }
100
+ if (Object.keys(input).length === 0) {
101
+ throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`);
102
+ }
103
+ const sorted = Object.entries(input).map(([id, value]) => __spreadProps(__spreadValues({}, value), { id })).sort((a, b) => b.width - a.width);
104
+ sorted.forEach(({ id, width, viewport }, index, array) => {
105
+ if (viewport && viewport > width) {
106
+ throw new Error(`Error on breakpoint "${id}". Viewport cannot be greater than its width.
107
+ "${id}" has a viewport of ${viewport}px and a width of ${width}px.`);
108
+ }
109
+ const next = array[index + 1];
110
+ if (viewport && next && viewport < next.width) {
111
+ throw new Error(`Error on breakpoint "${id}". Viewport cannot be smaller than the next breakpoint's width.
112
+ "${id}" has a viewport of ${viewport}px and the next breakpoint "${next.id}" has a width of ${next.width}px.`);
113
+ }
114
+ if (next && width === next.width) {
115
+ throw new Error(`Breakpoints cannot have the same width. "${id}" and "${next.id}" have the same width`);
116
+ }
117
+ });
84
118
  }
85
119
  function sortBreakpoints(breakpoints) {
86
120
  return breakpoints.sort((a, b) => {