@makeswift/runtime 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -710,7 +710,7 @@ async function fonts(_req, res, { getFonts } = {}) {
710
710
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
711
711
  return res.json(fonts2);
712
712
  }
713
- const version = "0.8.3";
713
+ const version = "0.8.4";
714
714
  async function handler(req, res, { apiKey }) {
715
715
  if (req.query.secret !== apiKey) {
716
716
  return res.status(401).json({ message: "Unauthorized" });
@@ -44,6 +44,7 @@ var index = require("./index.cjs3.js");
44
44
  var next = require("./index.cjs.js");
45
45
  var isHotkey = require("is-hotkey");
46
46
  var index$1 = require("./index.cjs5.js");
47
+ var useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect.cjs.js");
47
48
  require("css-box-model");
48
49
  require("./actions.cjs.js");
49
50
  require("./isNonNullable.cjs.js");
@@ -258,6 +259,28 @@ function useSyncWithBuilder(editor, text) {
258
259
  }, [shouldCommit]);
259
260
  return React.useCallback(() => setShouldCommit(false), []);
260
261
  }
262
+ function useSyncDOMSelection(editor, hasBeenSelected) {
263
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
264
+ if (!hasBeenSelected || editor.selection == null || slateReact.ReactEditor.isFocused(editor))
265
+ return;
266
+ try {
267
+ const root = slateReact.ReactEditor.findDocumentOrShadowRoot(editor);
268
+ const domSelection = root.getSelection();
269
+ const newDomRange = slateReact.ReactEditor.toDOMRange(editor, editor.selection);
270
+ if (newDomRange) {
271
+ if (slate.Range.isBackward(editor.selection)) {
272
+ domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset);
273
+ } else {
274
+ domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset);
275
+ }
276
+ } else {
277
+ domSelection == null ? void 0 : domSelection.removeAllRanges();
278
+ }
279
+ } catch (e) {
280
+ console.error(e);
281
+ }
282
+ });
283
+ }
261
284
  const defaultText = [{
262
285
  type: descriptors.BlockType.Paragraph,
263
286
  children: [{
@@ -271,6 +294,8 @@ const EditableText = React.forwardRef(function EditableText2({
271
294
  margin
272
295
  }, ref) {
273
296
  const [editor] = React.useState(() => index$1.withBlock(index$1.withTypography(index$1.withList(slateReact.withReact(slate.createEditor())))));
297
+ const [hasBeenSelected, setHasBeenSelected] = React.useState(false);
298
+ useSyncDOMSelection(editor, hasBeenSelected);
274
299
  const delaySync = useSyncWithBuilder(editor, text);
275
300
  const editMode = next.useBuilderEditMode();
276
301
  const [propControllers, setPropControllers] = React.useState(null);
@@ -299,6 +324,7 @@ const EditableText = React.forwardRef(function EditableText2({
299
324
  }, [controller, editor]);
300
325
  const handleFocus = React.useCallback(() => {
301
326
  controller == null ? void 0 : controller.focus();
327
+ setHasBeenSelected(true);
302
328
  }, [controller]);
303
329
  const handleKeyDown = React.useCallback((e) => {
304
330
  if (isHotkey__default["default"]("mod+shift+z", e))
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs7.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'\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 {\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.CONTENT}\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","Link","textDecoration","InlineType","Code","SuperScript","SubScript","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","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","Slate","Editable","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAU6B,sBAAA;AAAA,EAAEA;AAAAA,EAASC;AAAAA,EAAYC;AAAAA,GAAsC;AAClFC,QAAAA,cAAc,CAClBC,yBAAS;AAAA,IAAEC,QAAQ;AAAA,EAAA,CAAX,GACRD,gBAAAA,SAASE,gBAAgB,gBAAA,CAACN,QAAQO,SAAT,GAAqB,CAAC,CAACA,YAAY,YAAa;AAAA,IAAEA;AAAAA,EAAAA,EAAnD,CAAhB,CAFU;AAKZP,UAAAA,QAAQQ;AAAAA,SACTC,YAAUC,UAAAA;AACb,kFACST;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC7BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUG,UAAAA;AACb,mFACUX;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUI,UAAAA;AACb,mFACUZ;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUK,UAAAA;AACb,mFACUb;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SA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AAhB;AAAoB,aAAOjB,yCAAYmB;AAC/CD,QAAAA,kBAAAA,WAAS,SAASD,CAAV;AAAc,aAAOjB,yCAAYoB;AACzCF,QAAAA,kBAAAA,WAAS,QAAD,EAAWD,CAAnB;AAAuB,aAAOjB,yCAAYqB;AAC9CC,sBAAUL,GAAGtD,MAAJ;AAAA,EAAA,GAEX,CAACqC,YAAYrC,MAAb,CAP+B;AAUjC,wCACG4D,WAAAA,OAAD;AAAA,IAAO;AAAA,IAAgB,OAAOZ;AAAAA,IAAc,UAAUjB;AAAAA,IAAtD,yCACG8B,qBAAD;AAAA,MACE;AAAA,MACA,YAAYC,KAAAA;AAAAA,MACZ,eAAeC;AAAAA,MACf,WAAWV;AAAAA,MACX,SAASF;AAAAA,MACT,WAAW/E,IAAAA,GAAGoD,OAAO1D,MAAR;AAAA,MACb,UAAUmE,aAAa+B,YAAAA,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CARd;AAAA,EAAA,CAFJ;AAcD,CAvEqC;AAyEtC,IAAA,iBAAe5C;;;"}
1
+ {"version":3,"file":"index.cjs7.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 { 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'\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, hasBeenSelected: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!hasBeenSelected || 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 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 [hasBeenSelected, setHasBeenSelected] = useState(false)\n useSyncDOMSelection(editor, hasBeenSelected)\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 setHasBeenSelected(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 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.CONTENT}\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","Link","textDecoration","InlineType","Code","SuperScript","SubScript","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","hasBeenSelected","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","setHasBeenSelected","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","Slate","Editable","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAU6B,sBAAA;AAAA,EAAEA;AAAAA,EAASC;AAAAA,EAAYC;AAAAA,GAAsC;AAClFC,QAAAA,cAAc,CAClBC,yBAAS;AAAA,IAAEC,QAAQ;AAAA,EAAA,CAAX,GACRD,gBAAAA,SAASE,gBAAgB,gBAAA,CAACN,QAAQO,SAAT,GAAqB,CAAC,CAACA,YAAY,YAAa;AAAA,IAAEA;AAAAA,EAAAA,EAAnD,CAAhB,CAFU;AAKZP,UAAAA,QAAQQ;AAAAA,SACTC,YAAUC,UAAAA;AACb,kFACST;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC7BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUG,UAAAA;AACb,mFACUX;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUI,UAAAA;AACb,mFACUZ;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUK,UAAAA;AACb,mFACUb;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUM,UAAAA;AACb,mFACUd;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUO,UAAAA;AACb,mFACUf;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUQ,UAA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.es.js CHANGED
@@ -677,7 +677,7 @@ async function fonts(_req, res, { getFonts } = {}) {
677
677
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
678
678
  return res.json(fonts2);
679
679
  }
680
- const version = "0.8.3";
680
+ const version = "0.8.4";
681
681
  async function handler(req, res, { apiKey }) {
682
682
  if (req.query.secret !== apiKey) {
683
683
  return res.status(401).json({ message: "Unauthorized" });
package/dist/index.es7.js CHANGED
@@ -30,8 +30,8 @@ var __objRest = (source, exclude) => {
30
30
  return target;
31
31
  };
32
32
  import { useCallback, useState, useEffect, forwardRef, useImperativeHandle, useMemo } from "react";
33
- import { createEditor } from "slate";
34
- import { withReact, ReactEditor, Slate, Editable } from "slate-react";
33
+ import { Range, createEditor } from "slate";
34
+ import { ReactEditor, withReact, Slate, Editable } from "slate-react";
35
35
  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";
@@ -42,6 +42,7 @@ import { L as Link } from "./index.es3.js";
42
42
  import { u as useIsInBuilder, y as useBuilderEditMode, z as pollBoxModel } from "./index.es.js";
43
43
  import isHotkey from "is-hotkey";
44
44
  import { b as withBlock, a as withTypography, w as withList, o as onKeyDown } from "./index.es5.js";
45
+ import { u as useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.es.js";
45
46
  import "css-box-model";
46
47
  import "./actions.es.js";
47
48
  import "./isNonNullable.es.js";
@@ -252,6 +253,28 @@ function useSyncWithBuilder(editor, text) {
252
253
  }, [shouldCommit]);
253
254
  return useCallback(() => setShouldCommit(false), []);
254
255
  }
256
+ function useSyncDOMSelection(editor, hasBeenSelected) {
257
+ useIsomorphicLayoutEffect(() => {
258
+ if (!hasBeenSelected || editor.selection == null || ReactEditor.isFocused(editor))
259
+ return;
260
+ try {
261
+ const root = ReactEditor.findDocumentOrShadowRoot(editor);
262
+ const domSelection = root.getSelection();
263
+ const newDomRange = ReactEditor.toDOMRange(editor, editor.selection);
264
+ if (newDomRange) {
265
+ if (Range.isBackward(editor.selection)) {
266
+ domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset);
267
+ } else {
268
+ domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset);
269
+ }
270
+ } else {
271
+ domSelection == null ? void 0 : domSelection.removeAllRanges();
272
+ }
273
+ } catch (e) {
274
+ console.error(e);
275
+ }
276
+ });
277
+ }
255
278
  const defaultText = [{
256
279
  type: BlockType.Paragraph,
257
280
  children: [{
@@ -265,6 +288,8 @@ const EditableText = forwardRef(function EditableText2({
265
288
  margin
266
289
  }, ref) {
267
290
  const [editor] = useState(() => withBlock(withTypography(withList(withReact(createEditor())))));
291
+ const [hasBeenSelected, setHasBeenSelected] = useState(false);
292
+ useSyncDOMSelection(editor, hasBeenSelected);
268
293
  const delaySync = useSyncWithBuilder(editor, text);
269
294
  const editMode = useBuilderEditMode();
270
295
  const [propControllers, setPropControllers] = useState(null);
@@ -293,6 +318,7 @@ const EditableText = forwardRef(function EditableText2({
293
318
  }, [controller, editor]);
294
319
  const handleFocus = useCallback(() => {
295
320
  controller == null ? void 0 : controller.focus();
321
+ setHasBeenSelected(true);
296
322
  }, [controller]);
297
323
  const handleKeyDown = useCallback((e) => {
298
324
  if (isHotkey("mod+shift+z", e))
@@ -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/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'\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 {\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.CONTENT}\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","isInBuilder","useIsInBuilder","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","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,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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AAA,IAAc,UAAUjB;AAAAA,IAAtD,8BACG,UAAD;AAAA,MACE;AAAA,MACA,YAAY6B;AAAAA,MACZ,eAAeC;AAAAA,MACf,WAAWR;AAAAA,MACX,SAASF;AAAAA,MACT,WAAW/E,GAAGoD,OAAO1D,MAAR;AAAA,MACb,UAAUmE,aAAa6B,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CARd;AAAA,EAAA,CAFJ;AAcD,CAvEqC;AAyEtC,IAAA,iBAAe1C;;"}
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 { 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'\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, hasBeenSelected: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!hasBeenSelected || 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 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 [hasBeenSelected, setHasBeenSelected] = useState(false)\n useSyncDOMSelection(editor, hasBeenSelected)\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 setHasBeenSelected(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 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.CONTENT}\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","isInBuilder","useIsInBuilder","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","hasBeenSelected","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","setHasBeenSelected","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","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,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AAA,MACE;AAAA,MACA,YAAY2B;AAAAA,MACZ,eAAeC;AAAAA,MACf,WAAWP;AAAAA,MACX,SAASF;AAAAA,MACT,WAAWrG,GAAGyE,OAAO/E,MAAR;AAAA,MACb,UAAU0F,aAAa2B,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CARd;AAAA,EAAA,CAFJ;AAcD,CA1EqC;AA4EtC,IAAA,iBAAe1C;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"editable-text.d.ts","sourceRoot":"","sources":["../../../../../../../src/components/builtin/Text/EditableText/editable-text.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAA;AAGxF,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAA;AAE3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AAWzF,aAAK,KAAK,GAAG;IACX,EAAE,CAAC,EAAE,cAAc,CAAA;IACnB,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAID,eAAO,MAAM,YAAY,sHAuEvB,CAAA;AAEF,eAAe,YAAY,CAAA"}
1
+ {"version":3,"file":"editable-text.d.ts","sourceRoot":"","sources":["../../../../../../../src/components/builtin/Text/EditableText/editable-text.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAA;AAGxF,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAA;AAE3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AAYzF,aAAK,KAAK,GAAG;IACX,EAAE,CAAC,EAAE,cAAc,CAAA;IACnB,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAID,eAAO,MAAM,YAAY,sHA0EvB,CAAA;AAEF,eAAe,YAAY,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { Editor } from 'slate';
2
+ /**
3
+ * Clicking outside of the host blurs our `<Editable />`.
4
+ * `<Editable />` only updates the DOM's selection to match slate when it is focused.
5
+ * In the case of a panel being clicked this hook updates the DOM selection to match slate.
6
+ */
7
+ export declare function useSyncDOMSelection(editor: Editor, hasBeenSelected: boolean): void;
8
+ //# sourceMappingURL=useSyncDOMSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSyncDOMSelection.d.ts","sourceRoot":"","sources":["../../../../../../../src/components/builtin/Text/EditableText/useSyncDOMSelection.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAuB,MAAM,OAAO,CAAA;AAEnD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,QA+B3E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makeswift/runtime",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/main.cjs",
6
6
  "module": "dist/main.es",