@makeswift/runtime 0.7.16 → 0.7.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LiveProvider.es.js +1 -1
- package/dist/PreviewProvider.es.js +1 -1
- package/dist/Text.cjs.js +1 -1
- package/dist/Text.es.js +1 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs5.js +568 -37
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.cjs6.js +17 -697
- package/dist/index.cjs6.js.map +1 -1
- package/dist/index.cjs7.js +327 -0
- package/dist/index.cjs7.js.map +1 -0
- package/dist/index.es.js +3 -3
- package/dist/index.es5.js +558 -35
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es6.js +16 -692
- package/dist/index.es6.js.map +1 -1
- package/dist/index.es7.js +320 -0
- package/dist/index.es7.js.map +1 -0
- package/dist/leaf.cjs.js +1 -0
- package/dist/leaf.cjs.js.map +1 -1
- package/dist/leaf.es.js +2 -2
- package/dist/rich-text.cjs.js.map +1 -1
- package/dist/rich-text.es.js.map +1 -1
- package/dist/slate.cjs.js +48 -0
- package/dist/slate.cjs.js.map +1 -0
- package/dist/slate.es.js +39 -0
- package/dist/slate.es.js.map +1 -0
- package/dist/types/src/controls/rich-text/dto-types.d.ts +1 -2
- package/dist/types/src/controls/rich-text/dto-types.d.ts.map +1 -1
- package/package.json +5 -4
- package/slate.js +1 -0
package/dist/index.es6.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es6.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/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/index.ts","../src/slate/BlockPlugin/index.ts","../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 { responsiveStyle } 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(responsiveStyle([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'\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\n useEffect(() => {\n if (shouldCommit && text) {\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","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.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'\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, 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 { 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","import {\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'\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 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 }, [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 return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n className={cx(width, margin)}\n readOnly={editMode === BuilderEditMode.INTERACT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["element","attributes","children","blockStyles","useStyle","margin","responsiveStyle","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","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","Element","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withList","withReact","createEditor","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","ReactEditor","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","e","isHotkey","redo","undo","blur","onKeyDown","Leaf","BuilderEditMode","INTERACT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAU6B,sBAAA;AAAA,EAAEA;AAAAA,EAASC;AAAAA,EAAYC;AAAAA,GAAsC;AAClFC,QAAAA,cAAc,CAClBC,SAAS;AAAA,IAAEC,QAAQ;AAAA,EAAA,CAAX,GACRD,SAASE,gBAAgB,CAACN,QAAQO,SAAT,GAAqB,CAAC,CAACA,YAAY,YAAa;AAAA,IAAEA;AAAAA,EAAAA,EAAnD,CAAhB,CAFU;AAKZP,UAAAA,QAAQQ;AAAAA,SACTC,UAAUC;AACb,uEACST;QAAY,WAAWU,GAAG,GAAGR,WAAJ;AAAA,QAC7BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,UAAUG;AACb,wEACUX;QAAY,WAAWU,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,UAAUI;AACb,wEACUZ;QAAY,WAAWU,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,UAAUK;AACb,wEACUb;QAAY,WAAWU,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,UAAUM;AACb,wEACUd;QAAY,WAAWU,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,UAAUO;AACb,wEACUf;QAAY,WAAWU,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAA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,IAAD,CAAtD;AAE5BI,YAAU,MAAM;AACd+B,6CAAYa,eAAejD;AAAAA,EAA3B,GACC,CAACoC,YAAYpC,MAAb,CAFM;AAIHkD,QAAAA,cAAcjC,YAAY,MAAM;AACpCmB,6CAAYe;AAAAA,EAAZ,GACC,CAACf,UAAD,CAF4B;AAIzBgB,QAAAA,gBAAgBnC,YACpB,CAACoC,MAAqB;AAChBC,QAAAA,SAAS,eAAeD,CAAhB;AAAoB,aAAOjB,yCAAYmB;AAC/CD,QAAAA,SAAS,SAASD,CAAV;AAAc,aAAOjB,yCAAYoB;AACzCF,QAAAA,SAAS,QAAD,EAAWD,CAAnB;AAAuB,aAAOjB,yCAAYqB;AAC9CC,cAAUL,GAAGrD,MAAJ;AAAA,EAAA,GAEX,CAACoC,YAAYpC,MAAb,CAP+B;AAUjC,6BACG,OAAD;AAAA,IAAO;AAAA,IAAgB,OAAO+C;AAAAA,IAAc,UAAUjB;AAAAA,IAAtD,8BACG,UAAD;AAAA,MACE;AAAA,MACA,YAAY6B;AAAAA,MACZ,eAAezC;AAAAA,MACf,WAAWkC;AAAAA,MACX,SAASF;AAAAA,MACT,WAAW9E,GAAGmD,OAAOzD,MAAR;AAAA,MACb,UAAUkE,aAAa4B,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CARd;AAAA,EAAA,CAFJ;AAcD,CAvEqC;AAyEtC,IAAA,iBAAezC;;"}
|
|
1
|
+
{"version":3,"file":"index.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { useCallback, useState, useEffect, forwardRef, useImperativeHandle, useMemo } from "react";
|
|
33
|
+
import { createEditor } from "slate";
|
|
34
|
+
import { withReact, ReactEditor, Slate, Editable } from "slate-react";
|
|
35
|
+
import { cx } from "@emotion/css";
|
|
36
|
+
import { g as getBox } from "./box-models.es.js";
|
|
37
|
+
import { au as BlockType, av as InlineType, ar as richTextDTOtoDAO, aq as richTextDTOtoSelection, ax as BuilderEditMode } from "./rich-text.es.js";
|
|
38
|
+
import { L as Leaf } from "./leaf.es.js";
|
|
39
|
+
import { o as useStyle, r as responsiveStyle, Q as deepEqual, X as useBuilderEditMode, Y as pollBoxModel } from "./index.es.js";
|
|
40
|
+
import { jsx } from "react/jsx-runtime";
|
|
41
|
+
import { L as Link } from "./index.es3.js";
|
|
42
|
+
import isHotkey from "is-hotkey";
|
|
43
|
+
import { b as withBlock, a as withTypography, w as withList, o as onKeyDown } from "./index.es5.js";
|
|
44
|
+
import "css-box-model";
|
|
45
|
+
import "./actions.es.js";
|
|
46
|
+
import "./introspection.es.js";
|
|
47
|
+
import "use-sync-external-store/shim/with-selector";
|
|
48
|
+
import "next/dynamic";
|
|
49
|
+
import "./constants.es.js";
|
|
50
|
+
import "redux";
|
|
51
|
+
import "redux-thunk";
|
|
52
|
+
import "@emotion/serialize";
|
|
53
|
+
import "@emotion/utils";
|
|
54
|
+
import "./text-input.es.js";
|
|
55
|
+
import "./combobox.es.js";
|
|
56
|
+
import "use-sync-external-store/shim";
|
|
57
|
+
import "./types.es.js";
|
|
58
|
+
import "color";
|
|
59
|
+
import "scroll-into-view-if-needed";
|
|
60
|
+
import "react-dom";
|
|
61
|
+
import "html-react-parser";
|
|
62
|
+
import "next/head";
|
|
63
|
+
import "@emotion/server/create-instance";
|
|
64
|
+
import "next/document";
|
|
65
|
+
import "cookie";
|
|
66
|
+
import "cors";
|
|
67
|
+
import "http-proxy";
|
|
68
|
+
import "set-cookie-parser";
|
|
69
|
+
import "uuid";
|
|
70
|
+
import "corporate-ipsum";
|
|
71
|
+
import "next/link";
|
|
72
|
+
function BlockElement({
|
|
73
|
+
element,
|
|
74
|
+
attributes,
|
|
75
|
+
children
|
|
76
|
+
}) {
|
|
77
|
+
const blockStyles = [useStyle({
|
|
78
|
+
margin: 0
|
|
79
|
+
}), useStyle(responsiveStyle([element.textAlign], ([textAlign = "left"]) => ({
|
|
80
|
+
textAlign
|
|
81
|
+
})))];
|
|
82
|
+
switch (element.type) {
|
|
83
|
+
case BlockType.Paragraph:
|
|
84
|
+
return /* @__PURE__ */ jsx("p", __spreadProps(__spreadValues({}, attributes), {
|
|
85
|
+
className: cx(...blockStyles),
|
|
86
|
+
children
|
|
87
|
+
}));
|
|
88
|
+
case BlockType.Heading1:
|
|
89
|
+
return /* @__PURE__ */ jsx("h1", __spreadProps(__spreadValues({}, attributes), {
|
|
90
|
+
className: cx(...blockStyles),
|
|
91
|
+
children
|
|
92
|
+
}));
|
|
93
|
+
case BlockType.Heading2:
|
|
94
|
+
return /* @__PURE__ */ jsx("h2", __spreadProps(__spreadValues({}, attributes), {
|
|
95
|
+
className: cx(...blockStyles),
|
|
96
|
+
children
|
|
97
|
+
}));
|
|
98
|
+
case BlockType.Heading3:
|
|
99
|
+
return /* @__PURE__ */ jsx("h3", __spreadProps(__spreadValues({}, attributes), {
|
|
100
|
+
className: cx(...blockStyles),
|
|
101
|
+
children
|
|
102
|
+
}));
|
|
103
|
+
case BlockType.Heading4:
|
|
104
|
+
return /* @__PURE__ */ jsx("h4", __spreadProps(__spreadValues({}, attributes), {
|
|
105
|
+
className: cx(...blockStyles),
|
|
106
|
+
children
|
|
107
|
+
}));
|
|
108
|
+
case BlockType.Heading5:
|
|
109
|
+
return /* @__PURE__ */ jsx("h5", __spreadProps(__spreadValues({}, attributes), {
|
|
110
|
+
className: cx(...blockStyles),
|
|
111
|
+
children
|
|
112
|
+
}));
|
|
113
|
+
case BlockType.Heading6:
|
|
114
|
+
return /* @__PURE__ */ jsx("h6", __spreadProps(__spreadValues({}, attributes), {
|
|
115
|
+
className: cx(...blockStyles),
|
|
116
|
+
children
|
|
117
|
+
}));
|
|
118
|
+
case BlockType.BlockQuote:
|
|
119
|
+
return /* @__PURE__ */ jsx("blockquote", __spreadProps(__spreadValues({}, attributes), {
|
|
120
|
+
className: cx(...blockStyles, useStyle({
|
|
121
|
+
padding: "0.5em 10px",
|
|
122
|
+
fontSize: "1.25em",
|
|
123
|
+
fontWeight: "300",
|
|
124
|
+
borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
|
|
125
|
+
})),
|
|
126
|
+
children
|
|
127
|
+
}));
|
|
128
|
+
case BlockType.OrderedList:
|
|
129
|
+
return /* @__PURE__ */ jsx("ol", __spreadProps(__spreadValues({}, attributes), {
|
|
130
|
+
className: cx(...blockStyles),
|
|
131
|
+
style: {
|
|
132
|
+
listStylePosition: "inside"
|
|
133
|
+
},
|
|
134
|
+
children
|
|
135
|
+
}));
|
|
136
|
+
case BlockType.UnorderedList:
|
|
137
|
+
return /* @__PURE__ */ jsx("ul", __spreadProps(__spreadValues({}, attributes), {
|
|
138
|
+
className: cx(...blockStyles),
|
|
139
|
+
style: {
|
|
140
|
+
listStylePosition: "inside"
|
|
141
|
+
},
|
|
142
|
+
children
|
|
143
|
+
}));
|
|
144
|
+
case BlockType.ListItem:
|
|
145
|
+
return /* @__PURE__ */ jsx("li", __spreadProps(__spreadValues({}, attributes), {
|
|
146
|
+
className: cx(...blockStyles),
|
|
147
|
+
children
|
|
148
|
+
}));
|
|
149
|
+
case BlockType.ListItemChild:
|
|
150
|
+
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, attributes), {
|
|
151
|
+
className: cx(...blockStyles),
|
|
152
|
+
children
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function StyledLink(_a) {
|
|
157
|
+
var _b = _a, {
|
|
158
|
+
className
|
|
159
|
+
} = _b, restOfProps = __objRest(_b, [
|
|
160
|
+
"className"
|
|
161
|
+
]);
|
|
162
|
+
return /* @__PURE__ */ jsx(Link, __spreadProps(__spreadValues({}, restOfProps), {
|
|
163
|
+
className: cx(useStyle({
|
|
164
|
+
textDecoration: "none"
|
|
165
|
+
}), className)
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
function InlineElement({
|
|
169
|
+
element,
|
|
170
|
+
attributes,
|
|
171
|
+
children
|
|
172
|
+
}) {
|
|
173
|
+
switch (element.type) {
|
|
174
|
+
case InlineType.Code:
|
|
175
|
+
return /* @__PURE__ */ jsx("code", __spreadProps(__spreadValues({}, attributes), {
|
|
176
|
+
children
|
|
177
|
+
}));
|
|
178
|
+
case InlineType.SuperScript:
|
|
179
|
+
return /* @__PURE__ */ jsx("sup", __spreadProps(__spreadValues({}, attributes), {
|
|
180
|
+
children
|
|
181
|
+
}));
|
|
182
|
+
case InlineType.SubScript:
|
|
183
|
+
return /* @__PURE__ */ jsx("sub", __spreadProps(__spreadValues({}, attributes), {
|
|
184
|
+
children
|
|
185
|
+
}));
|
|
186
|
+
case InlineType.Link:
|
|
187
|
+
return /* @__PURE__ */ jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
|
|
188
|
+
link: element.link,
|
|
189
|
+
children
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function Element(_c) {
|
|
194
|
+
var _d = _c, {
|
|
195
|
+
element
|
|
196
|
+
} = _d, props = __objRest(_d, [
|
|
197
|
+
"element"
|
|
198
|
+
]);
|
|
199
|
+
switch (element.type) {
|
|
200
|
+
case InlineType.Code:
|
|
201
|
+
case InlineType.SuperScript:
|
|
202
|
+
case InlineType.SubScript:
|
|
203
|
+
case InlineType.Link:
|
|
204
|
+
return /* @__PURE__ */ jsx(InlineElement, __spreadValues({
|
|
205
|
+
element
|
|
206
|
+
}, props));
|
|
207
|
+
case BlockType.Paragraph:
|
|
208
|
+
case BlockType.Heading1:
|
|
209
|
+
case BlockType.Heading2:
|
|
210
|
+
case BlockType.Heading3:
|
|
211
|
+
case BlockType.BlockQuote:
|
|
212
|
+
case BlockType.OrderedList:
|
|
213
|
+
case BlockType.UnorderedList:
|
|
214
|
+
case BlockType.ListItem:
|
|
215
|
+
case BlockType.ListItemChild:
|
|
216
|
+
return /* @__PURE__ */ jsx(BlockElement, __spreadValues({
|
|
217
|
+
element
|
|
218
|
+
}, props));
|
|
219
|
+
default:
|
|
220
|
+
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
221
|
+
children: props.children
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const COMMIT_DEBOUNCE_DELAY = 500;
|
|
226
|
+
function useSyncWithBuilder(editor, text) {
|
|
227
|
+
const [shouldCommit, setShouldCommit] = useState(true);
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (shouldCommit && text) {
|
|
230
|
+
const nextValue = richTextDTOtoDAO(text);
|
|
231
|
+
const nextSelection = richTextDTOtoSelection(text);
|
|
232
|
+
if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {
|
|
233
|
+
editor.children = nextValue;
|
|
234
|
+
editor.selection = nextSelection;
|
|
235
|
+
editor.onChange();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}, [editor, shouldCommit, text]);
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
if (shouldCommit)
|
|
241
|
+
return;
|
|
242
|
+
const timeoutId = window.setTimeout(() => {
|
|
243
|
+
setShouldCommit(true);
|
|
244
|
+
}, COMMIT_DEBOUNCE_DELAY);
|
|
245
|
+
return () => {
|
|
246
|
+
window.clearTimeout(timeoutId);
|
|
247
|
+
};
|
|
248
|
+
}, [shouldCommit]);
|
|
249
|
+
return useCallback(() => setShouldCommit(false), []);
|
|
250
|
+
}
|
|
251
|
+
const defaultText = [{
|
|
252
|
+
type: BlockType.Paragraph,
|
|
253
|
+
children: [{
|
|
254
|
+
text: ""
|
|
255
|
+
}]
|
|
256
|
+
}];
|
|
257
|
+
const EditableText = forwardRef(function EditableText2({
|
|
258
|
+
id,
|
|
259
|
+
text,
|
|
260
|
+
width,
|
|
261
|
+
margin
|
|
262
|
+
}, ref) {
|
|
263
|
+
const [editor] = useState(() => withBlock(withTypography(withList(withReact(createEditor())))));
|
|
264
|
+
const delaySync = useSyncWithBuilder(editor, text);
|
|
265
|
+
const editMode = useBuilderEditMode();
|
|
266
|
+
const [propControllers, setPropControllers] = useState(null);
|
|
267
|
+
const controller = propControllers == null ? void 0 : propControllers.text;
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
if (controller == null)
|
|
270
|
+
return;
|
|
271
|
+
const element = ReactEditor.toDOMNode(editor, editor);
|
|
272
|
+
return pollBoxModel({
|
|
273
|
+
element,
|
|
274
|
+
onBoxModelChange: (boxModel) => controller.changeBoxModel(boxModel)
|
|
275
|
+
});
|
|
276
|
+
}, [editor, controller]);
|
|
277
|
+
useImperativeHandle(ref, () => ({
|
|
278
|
+
getDomNode() {
|
|
279
|
+
return ReactEditor.toDOMNode(editor, editor);
|
|
280
|
+
},
|
|
281
|
+
getBoxModel() {
|
|
282
|
+
return getBox(ReactEditor.toDOMNode(editor, editor));
|
|
283
|
+
},
|
|
284
|
+
setPropControllers
|
|
285
|
+
}), [editor, setPropControllers]);
|
|
286
|
+
const initialValue = useMemo(() => text ? richTextDTOtoDAO(text) : defaultText, [text]);
|
|
287
|
+
useEffect(() => {
|
|
288
|
+
controller == null ? void 0 : controller.setSlateEditor(editor);
|
|
289
|
+
}, [controller, editor]);
|
|
290
|
+
const handleFocus = useCallback(() => {
|
|
291
|
+
controller == null ? void 0 : controller.focus();
|
|
292
|
+
}, [controller]);
|
|
293
|
+
const handleKeyDown = useCallback((e) => {
|
|
294
|
+
if (isHotkey("mod+shift+z", e))
|
|
295
|
+
return controller == null ? void 0 : controller.redo();
|
|
296
|
+
if (isHotkey("mod+z", e))
|
|
297
|
+
return controller == null ? void 0 : controller.undo();
|
|
298
|
+
if (isHotkey("escape")(e))
|
|
299
|
+
return controller == null ? void 0 : controller.blur();
|
|
300
|
+
onKeyDown(e, editor);
|
|
301
|
+
}, [controller, editor]);
|
|
302
|
+
return /* @__PURE__ */ jsx(Slate, {
|
|
303
|
+
editor,
|
|
304
|
+
value: initialValue,
|
|
305
|
+
onChange: delaySync,
|
|
306
|
+
children: /* @__PURE__ */ jsx(Editable, {
|
|
307
|
+
id,
|
|
308
|
+
renderLeaf: Leaf,
|
|
309
|
+
renderElement: Element,
|
|
310
|
+
onKeyDown: handleKeyDown,
|
|
311
|
+
onFocus: handleFocus,
|
|
312
|
+
className: cx(width, margin),
|
|
313
|
+
readOnly: editMode === BuilderEditMode.INTERACT,
|
|
314
|
+
placeholder: "Write some text..."
|
|
315
|
+
})
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
var EditableText$1 = EditableText;
|
|
319
|
+
export { EditableText, EditableText$1 as default };
|
|
320
|
+
//# sourceMappingURL=index.es7.js.map
|
|
@@ -0,0 +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/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 { responsiveStyle } 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(responsiveStyle([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'\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\n useEffect(() => {\n if (shouldCommit && text) {\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 {\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'\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 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 }, [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 return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n className={cx(width, margin)}\n readOnly={editMode === BuilderEditMode.INTERACT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["element","attributes","children","blockStyles","useStyle","margin","responsiveStyle","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","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withList","withReact","createEditor","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","ReactEditor","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","e","isHotkey","redo","undo","blur","onKeyDown","Leaf","Element","BuilderEditMode","INTERACT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAU6B,sBAAA;AAAA,EAAEA;AAAAA,EAASC;AAAAA,EAAYC;AAAAA,GAAsC;AAClFC,QAAAA,cAAc,CAClBC,SAAS;AAAA,IAAEC,QAAQ;AAAA,E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AACf,UAAD,CAF4B;AAIzBgB,QAAAA,gBAAgBlC,YACpB,CAACmC,MAAqB;AAChBC,QAAAA,SAAS,eAAeD,CAAhB;AAAoB,aAAOjB,yCAAYmB;AAC/CD,QAAAA,SAAS,SAASD,CAAV;AAAc,aAAOjB,yCAAYoB;AACzCF,QAAAA,SAAS,QAAD,EAAWD,CAAnB;AAAuB,aAAOjB,yCAAYqB;AAC9CC,cAAUL,GAAGpD,MAAJ;AAAA,EAAA,GAEX,CAACmC,YAAYnC,MAAb,CAP+B;AAUjC,6BACG,OAAD;AAAA,IAAO;AAAA,IAAgB,OAAO8C;AAAAA,IAAc,UAAUjB;AAAAA,IAAtD,8BACG,UAAD;AAAA,MACE;AAAA,MACA,YAAY6B;AAAAA,MACZ,eAAeC;AAAAA,MACf,WAAWR;AAAAA,MACX,SAASF;AAAAA,MACT,WAAW7E,GAAGkD,OAAOxD,MAAR;AAAA,MACb,UAAUiE,aAAa6B,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CARd;AAAA,EAAA,CAFJ;AAcD,CAvEqC;AAyEtC,IAAA,iBAAe1C;;"}
|
package/dist/leaf.cjs.js
CHANGED
|
@@ -178,6 +178,7 @@ function Leaf(_a) {
|
|
|
178
178
|
}));
|
|
179
179
|
}
|
|
180
180
|
exports.Leaf = Leaf;
|
|
181
|
+
exports.isDeviceOverride = isDeviceOverride;
|
|
181
182
|
exports.useEnhancedTypography = useEnhancedTypography;
|
|
182
183
|
exports.useTypographyClassName = useTypographyClassName;
|
|
183
184
|
//# sourceMappingURL=leaf.cjs.js.map
|
package/dist/leaf.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leaf.cjs.js","sources":["../src/components/builtin/Text/components/Leaf/leaf.tsx"],"sourcesContent":["import { RenderLeafProps } from 'slate-react'\nimport { CSSObject } from '@emotion/serialize'\nimport { Swatch, Typography } from '../../../../../api'\nimport { DeviceOverride, ResponsiveValue } from '../../../../../prop-controllers'\nimport { useTypography, useSwatches } from '../../../../../runtimes/react/hooks/makeswift-api'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { colorToString } from '../../../../utils/colorToString'\nimport { findDeviceOverride, shallowMergeFallbacks } from '../../../../utils/devices'\nimport { isNonNullable } from '../../../../utils/isNonNullable'\nimport { responsiveStyle } from '../../../../utils/responsive-style'\nimport { ColorValue } from '../../../../utils/types'\nimport { RichTextTypography } from '../../../../../controls'\n\nexport type RichTextTypographyValue = RichTextTypography['style'][number]['value']\n\nfunction typographyFragementToRichTextTypography(\n typography: Typography | null,\n): RichTextTypography | undefined {\n if (typography == null) return undefined\n return {\n id: typography.id,\n style: typography.style.map(({ deviceId, value }) => ({\n deviceId,\n value: {\n fontFamily: value.fontFamily ?? undefined,\n lineHeight: value.lineHeight ?? undefined,\n letterSpacing: value.letterSpacing ?? undefined,\n fontWeight: value.fontWeight ?? undefined,\n textAlign: value.textAlign ?? undefined,\n uppercase: value.uppercase ?? undefined,\n underline: value.underline ?? undefined,\n strikethrough: value.strikethrough ?? undefined,\n italic: value.italic ?? undefined,\n fontSize: value.fontSize ?? undefined,\n color: value.color ?? undefined,\n },\n })),\n }\n}\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\ntype EnhancedTypographyValue = Omit<RichTextTypographyValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function isDeviceOverride(value: {\n deviceId: string\n value: RichTextTypographyValue\n}): value is DeviceOverride<RichTextTypographyValue> {\n return value.deviceId === 'desktop' || value.deviceId === 'tablet' || value.deviceId === 'mobile'\n}\n\nexport function getTypographyStyleSwatchIds(\n style: RichTextTypography['style'] | Typography['style'] | null | undefined,\n): string[] {\n return (\n style\n ?.map(override => override.value)\n .flatMap(typographyStyle => typographyStyle.color?.swatchId)\n .filter(isNonNullable) ?? []\n )\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<RichTextTypographyValue>,\n ): DeviceOverride<EnhancedTypographyValue> => {\n const { value, deviceId } = deviceRawTypographyValue\n\n if (value.color == null) {\n const { color, ...nextValue } = value\n return {\n deviceId,\n value: nextValue,\n }\n }\n return {\n deviceId,\n value: {\n ...value,\n color: {\n swatch: swatches.find(s => s && s.id === value.color?.swatchId),\n alpha: value.color?.alpha ?? undefined,\n },\n },\n }\n }\n\nconst getDeviceId = ({ deviceId }: DeviceOverride<unknown>) => deviceId\n\n/**\n * `enhanced` here just means typography ids have been replaced with the related entity.\n */\nexport default function useEnhancedTypography(value?: RichTextTypography): EnhancedTypography {\n const typography = typographyFragementToRichTextTypography(useTypography(value?.id ?? null))\n const source = typography?.style.filter(isDeviceOverride) ?? []\n const override = value?.style.filter(isDeviceOverride) ?? []\n\n const swatchIds = [\n ...getTypographyStyleSwatchIds(value?.style),\n ...getTypographyStyleSwatchIds(typography?.style),\n ]\n const swatches = useSwatches(swatchIds).filter(isNonNullable)\n\n const enhancedSource = source.map(withColor(swatches))\n const enhancedOverride = override.map(withColor(swatches))\n\n const devices = [\n ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId))),\n ]\n\n return devices\n .map(deviceId => {\n const deviceSource = findDeviceOverride(enhancedSource, deviceId)?.value\n const deviceOverride = findDeviceOverride(enhancedOverride, deviceId)?.value\n\n if (deviceSource && deviceOverride) {\n return {\n deviceId,\n value: { ...deviceSource, ...deviceOverride },\n }\n } else if (deviceOverride) {\n return {\n deviceId,\n value: deviceOverride,\n }\n } else if (deviceSource) {\n return {\n deviceId,\n value: deviceSource,\n }\n }\n return null\n })\n .filter(isNonNullable)\n}\n\nexport function useTypographyClassName(value: EnhancedTypography): string {\n return useStyle(\n responsiveStyle<\n EnhancedTypographyValue,\n [ResponsiveValue<EnhancedTypographyValue> | null | undefined]\n >(\n [value],\n ([value]) => {\n if (value === undefined) return {}\n\n let styles: CSSObject = {}\n if (value.color != null) styles.color = colorToString(value.color)\n if (value.fontFamily != null) styles.fontFamily = value.fontFamily\n if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)\n styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`\n if (value.fontWeight != null) styles.fontWeight = value.fontWeight\n if (value.lineHeight != null) styles.lineHeight = value.lineHeight\n if (value.letterSpacing != null) styles.letterSpacing = `${value.letterSpacing / 10}em`\n if (value.uppercase != null)\n styles.textTransform = value.uppercase === true ? 'uppercase' : 'initial'\n if (value.underline != null || value.strikethrough != null)\n styles.textDecoration = [\n Boolean(value.underline) && 'underline',\n Boolean(value.strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')\n if (value.italic != null) styles.fontStyle = value.italic === true ? 'italic' : 'initial'\n\n return styles\n },\n shallowMergeFallbacks,\n ),\n )\n}\n\nexport function Leaf({ leaf, ...props }: RenderLeafProps) {\n const enhancedTypography = useEnhancedTypography(leaf.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span {...props.attributes} className={typographyClassName}>\n {props.children}\n </span>\n )\n}\n"],"names":["typography","undefined","id","style","map","deviceId","value","fontFamily","lineHeight","letterSpacing","fontWeight","textAlign","uppercase","underline","strikethrough","italic","fontSize","color","override","flatMap","typographyStyle","swatchId","filter","isNonNullable","withColor","swatches","deviceRawTypographyValue","nextValue","swatch","find","s","alpha","getDeviceId","typographyFragementToRichTextTypography","useTypography","source","isDeviceOverride","swatchIds","getTypographyStyleSwatchIds","useSwatches","enhancedSource","enhancedOverride","devices","Set","concat","deviceSource","findDeviceOverride","deviceOverride","useStyle","responsiveStyle","styles","colorToString","unit","textTransform","textDecoration","Boolean","join","fontStyle","shallowMergeFallbacks","leaf","props","enhancedTypography","useEnhancedTypography","typographyClassName","useTypographyClassName","attributes","children"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,iDACEA,YACgC;AAChC,MAAIA,cAAc;AAAaC,WAAAA;AACxB,SAAA;AAAA,IACLC,IAAIF,WAAWE;AAAAA,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KAAyB,cAFV,EAIrBQ,OAAOiC,OAJc,EAKrBC,KAAK,GALgB;AAM1B,QAAIlD,OAAMS,UAAU;AAAMmC,aAAOO,YAAYnD,OAAMS,WAAW,OAAO,WAAW;AAEzEmC,WAAAA;AAAAA,EAAAA,GAETQ,KAAAA,qBA7Ba,CADF;AAiChB;AAEoB,cAAA,IAAqC;AAArC,eAAEC;AAAAA;AAAAA,MAAF,IAAWC,kBAAX,IAAWA;AAAAA,IAATD;AAAAA;AACfE,QAAAA,qBAAqBC,sBAAsBH,KAAK3D,UAAN;AAC1C+D,QAAAA,sBAAsBC,uBAAuBH,kBAAD;AAGhD,wCAAA,QAAA,iCAAUD,MAAMK,aAAhB;AAAA,IAA4B,WAAWF;AAAAA,IAAvC,UACGH,MAAMM;AAAAA,EAAAA,EAFX;AAKD;;;;"}
|
|
1
|
+
{"version":3,"file":"leaf.cjs.js","sources":["../src/components/builtin/Text/components/Leaf/leaf.tsx"],"sourcesContent":["import { RenderLeafProps } from 'slate-react'\nimport { CSSObject } from '@emotion/serialize'\nimport { Swatch, Typography } from '../../../../../api'\nimport { DeviceOverride, ResponsiveValue } from '../../../../../prop-controllers'\nimport { useTypography, useSwatches } from '../../../../../runtimes/react/hooks/makeswift-api'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { colorToString } from '../../../../utils/colorToString'\nimport { findDeviceOverride, shallowMergeFallbacks } from '../../../../utils/devices'\nimport { isNonNullable } from '../../../../utils/isNonNullable'\nimport { responsiveStyle } from '../../../../utils/responsive-style'\nimport { ColorValue } from '../../../../utils/types'\nimport { RichTextTypography } from '../../../../../controls'\n\nexport type RichTextTypographyValue = RichTextTypography['style'][number]['value']\n\nfunction typographyFragementToRichTextTypography(\n typography: Typography | null,\n): RichTextTypography | undefined {\n if (typography == null) return undefined\n return {\n id: typography.id,\n style: typography.style.map(({ deviceId, value }) => ({\n deviceId,\n value: {\n fontFamily: value.fontFamily ?? undefined,\n lineHeight: value.lineHeight ?? undefined,\n letterSpacing: value.letterSpacing ?? undefined,\n fontWeight: value.fontWeight ?? undefined,\n textAlign: value.textAlign ?? undefined,\n uppercase: value.uppercase ?? undefined,\n underline: value.underline ?? undefined,\n strikethrough: value.strikethrough ?? undefined,\n italic: value.italic ?? undefined,\n fontSize: value.fontSize ?? undefined,\n color: value.color ?? undefined,\n },\n })),\n }\n}\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\ntype EnhancedTypographyValue = Omit<RichTextTypographyValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function isDeviceOverride(value: {\n deviceId: string\n value: RichTextTypographyValue\n}): value is DeviceOverride<RichTextTypographyValue> {\n return value.deviceId === 'desktop' || value.deviceId === 'tablet' || value.deviceId === 'mobile'\n}\n\nexport function getTypographyStyleSwatchIds(\n style: RichTextTypography['style'] | Typography['style'] | null | undefined,\n): string[] {\n return (\n style\n ?.map(override => override.value)\n .flatMap(typographyStyle => typographyStyle.color?.swatchId)\n .filter(isNonNullable) ?? []\n )\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<RichTextTypographyValue>,\n ): DeviceOverride<EnhancedTypographyValue> => {\n const { value, deviceId } = deviceRawTypographyValue\n\n if (value.color == null) {\n const { color, ...nextValue } = value\n return {\n deviceId,\n value: nextValue,\n }\n }\n return {\n deviceId,\n value: {\n ...value,\n color: {\n swatch: swatches.find(s => s && s.id === value.color?.swatchId),\n alpha: value.color?.alpha ?? undefined,\n },\n },\n }\n }\n\nconst getDeviceId = ({ deviceId }: DeviceOverride<unknown>) => deviceId\n\n/**\n * `enhanced` here just means typography ids have been replaced with the related entity.\n */\nexport default function useEnhancedTypography(value?: RichTextTypography): EnhancedTypography {\n const typography = typographyFragementToRichTextTypography(useTypography(value?.id ?? null))\n const source = typography?.style.filter(isDeviceOverride) ?? []\n const override = value?.style.filter(isDeviceOverride) ?? []\n\n const swatchIds = [\n ...getTypographyStyleSwatchIds(value?.style),\n ...getTypographyStyleSwatchIds(typography?.style),\n ]\n const swatches = useSwatches(swatchIds).filter(isNonNullable)\n\n const enhancedSource = source.map(withColor(swatches))\n const enhancedOverride = override.map(withColor(swatches))\n\n const devices = [\n ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId))),\n ]\n\n return devices\n .map(deviceId => {\n const deviceSource = findDeviceOverride(enhancedSource, deviceId)?.value\n const deviceOverride = findDeviceOverride(enhancedOverride, deviceId)?.value\n\n if (deviceSource && deviceOverride) {\n return {\n deviceId,\n value: { ...deviceSource, ...deviceOverride },\n }\n } else if (deviceOverride) {\n return {\n deviceId,\n value: deviceOverride,\n }\n } else if (deviceSource) {\n return {\n deviceId,\n value: deviceSource,\n }\n }\n return null\n })\n .filter(isNonNullable)\n}\n\nexport function useTypographyClassName(value: EnhancedTypography): string {\n return useStyle(\n responsiveStyle<\n EnhancedTypographyValue,\n [ResponsiveValue<EnhancedTypographyValue> | null | undefined]\n >(\n [value],\n ([value]) => {\n if (value === undefined) return {}\n\n let styles: CSSObject = {}\n if (value.color != null) styles.color = colorToString(value.color)\n if (value.fontFamily != null) styles.fontFamily = value.fontFamily\n if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)\n styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`\n if (value.fontWeight != null) styles.fontWeight = value.fontWeight\n if (value.lineHeight != null) styles.lineHeight = value.lineHeight\n if (value.letterSpacing != null) styles.letterSpacing = `${value.letterSpacing / 10}em`\n if (value.uppercase != null)\n styles.textTransform = value.uppercase === true ? 'uppercase' : 'initial'\n if (value.underline != null || value.strikethrough != null)\n styles.textDecoration = [\n Boolean(value.underline) && 'underline',\n Boolean(value.strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')\n if (value.italic != null) styles.fontStyle = value.italic === true ? 'italic' : 'initial'\n\n return styles\n },\n shallowMergeFallbacks,\n ),\n )\n}\n\nexport function Leaf({ leaf, ...props }: RenderLeafProps) {\n const enhancedTypography = useEnhancedTypography(leaf.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span {...props.attributes} className={typographyClassName}>\n {props.children}\n </span>\n )\n}\n"],"names":["typography","undefined","id","style","map","deviceId","value","fontFamily","lineHeight","letterSpacing","fontWeight","textAlign","uppercase","underline","strikethrough","italic","fontSize","color","override","flatMap","typographyStyle","swatchId","filter","isNonNullable","withColor","swatches","deviceRawTypographyValue","nextValue","swatch","find","s","alpha","getDeviceId","typographyFragementToRichTextTypography","useTypography","source","isDeviceOverride","swatchIds","getTypographyStyleSwatchIds","useSwatches","enhancedSource","enhancedOverride","devices","Set","concat","deviceSource","findDeviceOverride","deviceOverride","useStyle","responsiveStyle","styles","colorToString","unit","textTransform","textDecoration","Boolean","join","fontStyle","shallowMergeFallbacks","leaf","props","enhancedTypography","useEnhancedTypography","typographyClassName","useTypographyClassName","attributes","children"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,iDACEA,YACgC;AAChC,MAAIA,cAAc;AAAaC,WAAAA;AACxB,SAAA;AAAA,IACLC,IAAIF,WAAWE;AAAAA,IACfC,OAAOH,WAAWG,MAAMC,IAAI,CAAC;AAAA,MAAEC;AAAAA,MAAUC;AAAAA,UAAa;;AAAA;AAAA,QACpDD;AAAAA,QACAC,OAAO;AAAA,UACLC,YAAYD,YAAMC,eAAND,YAAoBL;AAAAA,UAChCO,YAAYF,YAAME,eAANF,YAAoBL;AAAAA,UAChCQ,eAAeH,YAAMG,kBAANH,YAAuBL;AAAAA,UACtCS,YAAYJ,YAAMI,eAANJ,YAAoBL;AAAAA,UAChCU,WAAWL,YAAMK,cAANL,YAAmBL;AAAAA,UAC9BW,WAAWN,YAAMM,cAANN,YAAmBL;AAAAA,UAC9BY,WAAWP,YAAMO,cAANP,YAAmBL;AAAAA,UAC9Ba,eAAeR,YAAMQ,kBAANR,YAAuBL;AAAAA,UACtCc,QAAQT,YAAMS,WAANT,YA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"}
|
package/dist/leaf.es.js
CHANGED
|
@@ -29,7 +29,7 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
-
import {
|
|
32
|
+
import { N as useTypography, K as useSwatches, G as findDeviceOverride, o as useStyle, r as responsiveStyle, O as shallowMergeFallbacks, s as colorToString } from "./index.es.js";
|
|
33
33
|
import { j as isNonNullable } from "./introspection.es.js";
|
|
34
34
|
import { jsx } from "react/jsx-runtime";
|
|
35
35
|
function typographyFragementToRichTextTypography(typography) {
|
|
@@ -176,5 +176,5 @@ function Leaf(_a) {
|
|
|
176
176
|
children: props.children
|
|
177
177
|
}));
|
|
178
178
|
}
|
|
179
|
-
export { Leaf as L, useTypographyClassName as a, useEnhancedTypography as u };
|
|
179
|
+
export { Leaf as L, useTypographyClassName as a, isDeviceOverride as i, useEnhancedTypography as u };
|
|
180
180
|
//# sourceMappingURL=leaf.es.js.map
|