@makeswift/runtime 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/Box.es.js +1 -1
  2. package/dist/Button.es.js +1 -1
  3. package/dist/Carousel.es.js +1 -1
  4. package/dist/Countdown.es.js +1 -1
  5. package/dist/Divider.es.js +1 -1
  6. package/dist/EditableText.cjs.js +12 -3
  7. package/dist/EditableText.cjs.js.map +1 -1
  8. package/dist/EditableText.es.js +13 -4
  9. package/dist/EditableText.es.js.map +1 -1
  10. package/dist/Embed.es.js +1 -1
  11. package/dist/Form.es.js +1 -1
  12. package/dist/Image.es.js +1 -1
  13. package/dist/LiveProvider.es.js +1 -1
  14. package/dist/Navigation.es.js +1 -1
  15. package/dist/PreviewProvider.cjs.js +53 -16
  16. package/dist/PreviewProvider.cjs.js.map +1 -1
  17. package/dist/PreviewProvider.es.js +56 -20
  18. package/dist/PreviewProvider.es.js.map +1 -1
  19. package/dist/ReadOnlyText.cjs.js +5 -2
  20. package/dist/ReadOnlyText.cjs.js.map +1 -1
  21. package/dist/ReadOnlyText.es.js +6 -3
  22. package/dist/ReadOnlyText.es.js.map +1 -1
  23. package/dist/Root.es.js +1 -1
  24. package/dist/SocialLinks.es.js +1 -1
  25. package/dist/Text.es.js +1 -1
  26. package/dist/Video.es.js +1 -1
  27. package/dist/actions.cjs.js +11 -1
  28. package/dist/actions.cjs.js.map +1 -1
  29. package/dist/actions.es.js +11 -2
  30. package/dist/actions.es.js.map +1 -1
  31. package/dist/builder.cjs.js +1 -0
  32. package/dist/builder.cjs.js.map +1 -1
  33. package/dist/builder.es.js +1 -0
  34. package/dist/builder.es.js.map +1 -1
  35. package/dist/components.cjs.js +1 -0
  36. package/dist/components.cjs.js.map +1 -1
  37. package/dist/components.es.js +1 -1
  38. package/dist/constants.cjs.js +6 -1
  39. package/dist/constants.cjs.js.map +1 -1
  40. package/dist/constants.es.js +7 -3
  41. package/dist/constants.es.js.map +1 -1
  42. package/dist/controls.cjs.js +1 -0
  43. package/dist/controls.cjs.js.map +1 -1
  44. package/dist/controls.es.js +2 -1
  45. package/dist/controls.es.js.map +1 -1
  46. package/dist/index.cjs.js +494 -15
  47. package/dist/index.cjs.js.map +1 -1
  48. package/dist/index.es.js +495 -19
  49. package/dist/index.es.js.map +1 -1
  50. package/dist/index.es2.js +2 -2
  51. package/dist/index.es3.js +1 -1
  52. package/dist/index.es4.js +1 -1
  53. package/dist/index.es6.js +2 -2
  54. package/dist/main.cjs.js +1 -0
  55. package/dist/main.cjs.js.map +1 -1
  56. package/dist/main.es.js +1 -1
  57. package/dist/next.cjs.js +1 -0
  58. package/dist/next.cjs.js.map +1 -1
  59. package/dist/next.es.js +1 -1
  60. package/dist/prop-controllers.cjs.js +1 -0
  61. package/dist/prop-controllers.cjs.js.map +1 -1
  62. package/dist/prop-controllers.es.js +1 -0
  63. package/dist/prop-controllers.es.js.map +1 -1
  64. package/dist/rich-text.cjs.js +20 -4
  65. package/dist/rich-text.cjs.js.map +1 -1
  66. package/dist/rich-text.es.js +19 -5
  67. package/dist/rich-text.es.js.map +1 -1
  68. package/dist/types/src/components/builtin/Text/EditableText.d.ts.map +1 -1
  69. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
  70. package/dist/types/src/components/builtin/Text/register.d.ts.map +1 -1
  71. package/dist/types/src/components/page/Page.d.ts +5 -1
  72. package/dist/types/src/components/page/Page.d.ts.map +1 -1
  73. package/dist/types/src/controls/rich-text.d.ts +1 -1
  74. package/dist/types/src/controls/rich-text.d.ts.map +1 -1
  75. package/dist/types/src/index.d.ts +1 -1
  76. package/dist/types/src/index.d.ts.map +1 -1
  77. package/dist/types/src/next/api-handler.d.ts +14 -2
  78. package/dist/types/src/next/api-handler.d.ts.map +1 -1
  79. package/dist/types/src/next/client.d.ts +69 -32
  80. package/dist/types/src/next/client.d.ts.map +1 -1
  81. package/dist/types/src/next/index.d.ts +5 -1
  82. package/dist/types/src/next/index.d.ts.map +1 -1
  83. package/dist/types/src/next/preview-mode.d.ts.map +1 -1
  84. package/dist/types/src/prop-controllers/instances.d.ts +1 -1
  85. package/dist/types/src/prop-controllers/instances.d.ts.map +1 -1
  86. package/dist/types/src/runtimes/react/index.d.ts +2 -0
  87. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  88. package/dist/types/src/state/actions.d.ts +12 -1
  89. package/dist/types/src/state/actions.d.ts.map +1 -1
  90. package/dist/types/src/state/modules/api-resources.d.ts +6 -2
  91. package/dist/types/src/state/modules/api-resources.d.ts.map +1 -1
  92. package/dist/types/src/state/modules/builder-edit-mode.d.ts +11 -0
  93. package/dist/types/src/state/modules/builder-edit-mode.d.ts.map +1 -0
  94. package/dist/types/src/state/react-builder-preview.d.ts +2 -0
  95. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  96. package/dist/types/src/state/react-page.d.ts +3 -0
  97. package/dist/types/src/state/react-page.d.ts.map +1 -1
  98. package/package.json +1 -1
  99. package/dist/types/src/utils/constants.d.ts +0 -6
  100. package/dist/types/src/utils/constants.d.ts.map +0 -1
package/dist/Box.es.js CHANGED
@@ -32,7 +32,7 @@ var __objRest = (source, exclude) => {
32
32
  import { forwardRef, useRef, useCallback, useImperativeHandle, useState, useEffect } from "react";
33
33
  import { cx } from "@emotion/css";
34
34
  import { v4 } from "uuid";
35
- import { o as useStyle, r as responsiveStyle, E as Element } from "./index.es.js";
35
+ import { p as useStyle, r as responsiveStyle, E as Element } from "./index.es.js";
36
36
  import { jsx } from "react/jsx-runtime";
37
37
  import { a as useBoxAnimation, b as areBoxAnimationPropsEqual, B as BackgroundsContainer, G as GridItem } from "./index.es2.js";
38
38
  import { p as parse, c as createBox } from "./box-models.es.js";
package/dist/Button.es.js CHANGED
@@ -31,7 +31,7 @@ var __objRest = (source, exclude) => {
31
31
  };
32
32
  import { forwardRef } from "react";
33
33
  import ColorHelper from "color";
34
- import { o as useStyle, p as responsiveWidth, r as responsiveStyle, q as responsiveTextStyle, s as colorToString } from "./index.es.js";
34
+ import { p as useStyle, q as responsiveWidth, r as responsiveStyle, s as responsiveTextStyle, t as colorToString } from "./index.es.js";
35
35
  import { L as Link } from "./index.es3.js";
36
36
  import { cx } from "@emotion/css";
37
37
  import { jsx } from "react/jsx-runtime";
@@ -33,7 +33,7 @@ import { forwardRef, useState, useRef, useCallback, useEffect } from "react";
33
33
  import { useAnimation, motion } from "framer-motion";
34
34
  import { useGesture } from "react-use-gesture";
35
35
  import { wrap } from "@popmotion/popcorn";
36
- import { m as useMediaQuery, o as useStyle, r as responsiveStyle, s as colorToString } from "./index.es.js";
36
+ import { m as useMediaQuery, p as useStyle, r as responsiveStyle, t as colorToString } from "./index.es.js";
37
37
  import "use-sync-external-store/shim";
38
38
  import "./rich-text.es.js";
39
39
  import ImageComponent from "./Image.es.js";
@@ -31,7 +31,7 @@ var __objRest = (source, exclude) => {
31
31
  };
32
32
  import { cx } from "@emotion/css";
33
33
  import { forwardRef, useState, useEffect } from "react";
34
- import { o as useStyle, r as responsiveStyle, s as colorToString } from "./index.es.js";
34
+ import { p as useStyle, r as responsiveStyle, t as colorToString } from "./index.es.js";
35
35
  import { jsx, jsxs } from "react/jsx-runtime";
36
36
  import "use-sync-external-store/shim/with-selector";
37
37
  import "next/dynamic";
@@ -1,5 +1,5 @@
1
1
  import { forwardRef } from "react";
2
- import { o as useStyle, r as responsiveStyle, s as colorToString } from "./index.es.js";
2
+ import { p as useStyle, r as responsiveStyle, t as colorToString } from "./index.es.js";
3
3
  import { cx } from "@emotion/css";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import "use-sync-external-store/shim/with-selector";
@@ -44,7 +44,7 @@ var css = require("@emotion/css");
44
44
  var next = require("./index.cjs.js");
45
45
  var index$1 = require("./index.cjs3.js");
46
46
  require("use-sync-external-store/shim");
47
- require("./rich-text.cjs.js");
47
+ var richText = require("./rich-text.cjs.js");
48
48
  require("css-box-model");
49
49
  require("./actions.cjs.js");
50
50
  require("./constants.cjs.js");
@@ -264,6 +264,7 @@ const EditableText = React.forwardRef(function EditableText2({
264
264
  const [editor, setEditor] = React.useState(null);
265
265
  const [propControllers, setPropControllers] = React.useState(null);
266
266
  const controller = propControllers == null ? void 0 : propControllers.text;
267
+ const editMode = next.useBuilderEditMode();
267
268
  React.useEffect(() => {
268
269
  const element = editor == null ? void 0 : editor.findDOMNode([]);
269
270
  if (element == null || !(element instanceof HTMLElement) || controller == null)
@@ -347,7 +348,14 @@ const EditableText = React.forwardRef(function EditableText2({
347
348
  if (event.relatedTarget == null)
348
349
  editor2.select(selection);
349
350
  }, []);
350
- const isInBuilder = next.useIsInBuilder();
351
+ const lastEditMode = React.useRef(editMode);
352
+ if (lastEditMode.current !== editMode)
353
+ lastEditMode.current = editMode;
354
+ const handleClick = (event, _editor, next2) => {
355
+ next2();
356
+ if (lastEditMode.current === richText.BuilderEditMode.CONTENT)
357
+ event.stopPropagation();
358
+ };
351
359
  return /* @__PURE__ */ jsxRuntime.jsx(RichTextEditor, {
352
360
  id,
353
361
  ref: setEditor,
@@ -361,7 +369,8 @@ const EditableText = React.forwardRef(function EditableText2({
361
369
  onFocus: handleFocus,
362
370
  onKeyDown: handleKeyDown,
363
371
  onBlur: handleBlur,
364
- readOnly: !isInBuilder || controller == null
372
+ onClick: handleClick,
373
+ readOnly: editMode !== richText.BuilderEditMode.CONTENT
365
374
  });
366
375
  });
367
376
  exports["default"] = EditableText;
@@ -1 +1 @@
1
- {"version":3,"file":"EditableText.cjs.js","sources":["../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesBlocks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Link.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Inlines.tsx","../src/components/builtin/Text/components/RichTextEditor/index.tsx","../src/components/builtin/Text/EditableText.tsx"],"sourcesContent":["import type { Plugin } from 'slate-react'\n\nimport Mark from '../components/Mark'\n\nconst TYPOGRAPHY_TYPE = 'typography'\n\nexport default function DeviceOverridesMarksPlugin(): Plugin {\n return {\n renderMark({ mark, children }, _editor, next) {\n if (mark.type === TYPOGRAPHY_TYPE) {\n return <Mark value={mark.data.get('value')}>{children}</Mark>\n }\n\n return next()\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nimport Block from '../components/Block'\n\nexport default function DeviceOverridesBlockPlugin(): Plugin {\n return {\n renderBlock(props, _editor, next): JSX.Element {\n const { node, attributes, children } = props\n const blockProps = { textAlign: node.data.get('textAlign') }\n\n switch (node.type) {\n case 'paragraph':\n return (\n <Block {...attributes} {...blockProps} as=\"p\">\n {children}\n </Block>\n )\n\n case 'heading-one':\n return (\n <Block {...attributes} {...blockProps} as=\"h1\">\n {children}\n </Block>\n )\n\n case 'heading-two':\n return (\n <Block {...attributes} {...blockProps} as=\"h2\">\n {children}\n </Block>\n )\n\n case 'heading-three':\n return (\n <Block {...attributes} {...blockProps} as=\"h3\">\n {children}\n </Block>\n )\n\n case 'heading-four':\n return (\n <Block {...attributes} {...blockProps} as=\"h4\">\n {children}\n </Block>\n )\n\n case 'heading-five':\n return (\n <Block {...attributes} {...blockProps} as=\"h5\">\n {children}\n </Block>\n )\n\n case 'heading-six':\n return (\n <Block {...attributes} {...blockProps} as=\"h6\">\n {children}\n </Block>\n )\n\n case 'blockquote':\n return (\n <Block {...attributes} {...blockProps} as=\"blockquote\">\n {children}\n </Block>\n )\n\n default:\n return next()\n }\n },\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { Plugin } from 'slate-react'\nimport { useStyle } from '../../../../../../runtimes/react/use-style'\n\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 default function LinkPlugin(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'link': {\n const { data } = node\n\n return (\n <StyledLink {...attributes} link={data.toJS()}>\n {children}\n </StyledLink>\n )\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nexport default function Inlines(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'code': {\n return <code {...attributes}>{children}</code>\n }\n\n case 'superscript': {\n return <sup {...attributes}>{children}</sup>\n }\n\n case 'subscript': {\n return <sub {...attributes}>{children}</sub>\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { ComponentPropsWithoutRef, forwardRef, useMemo } from 'react'\n\nimport { Editor as SlateEditor } from 'slate-react'\n\n// @ts-expect-error: no types for '@convertkit/slate-lists'\nimport Lists from '@convertkit/slate-lists'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', className, ...restOfProps }: Props,\n ref,\n) {\n const plugins = useMemo(\n () => [Lists(), Link(), Inlines(), DeviceOverridesBlocks(), DeviceOverridesMarks()],\n [],\n )\n\n return (\n <SlateEditor\n {...restOfProps}\n // Workaround because our Slate editor is broken on Chrome 105\n // Problem: https://linear.app/makeswift/issue/PRD-434/our-rich-text-component-breaks-in-the-latest-version-of-chrome\n // Workaround: https://github.com/ianstormtaylor/slate/issues/5110#issuecomment-1234951122\n style={{ WebkitUserModify: undefined }}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), className)}\n ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n})\n","import {\n useState,\n Ref,\n useImperativeHandle,\n forwardRef,\n useEffect,\n useCallback,\n useRef,\n KeyboardEvent as ReactKeyboardEvent,\n FocusEvent as ReactFocusEvent,\n} from 'react'\nimport { Editor, OnChangeParam } from 'slate-react'\nimport { Value, ValueJSON } from 'slate'\n// @ts-expect-error: no types for 'slate-hotkeys'\nimport Hotkeys from 'slate-hotkeys'\nimport { isHotkey } from 'is-hotkey'\n\nimport {\n ElementIDValue,\n RichTextDescriptor,\n RichTextValue,\n} from '../../../prop-controllers/descriptors'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\nimport { cx } from '@emotion/css'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { useIsInBuilder } from '../../../runtimes/react'\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: ValueJSON = {\n document: { nodes: [{ object: 'block' as const, type: 'paragraph' as const, nodes: [] }] },\n data: {},\n}\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\ntype Descriptors = { text?: RichTextDescriptor }\n\nconst EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<BoxModelHandle & PropControllersHandle<Descriptors>>,\n) {\n const [editor, setEditor] = useState<Editor | null>(null)\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n const element = editor?.findDOMNode([])\n if (element == null || !(element instanceof HTMLElement) || controller == null) return\n return pollBoxModel({\n element: element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getBoxModel() {\n const el = editor?.findDOMNode([])\n\n return el instanceof Element ? getBox(el) : null\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n useEffect(() => {\n if (editor) controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n /**\n * We must keep local state so that we can reflect the user's typed changes immediately. At the\n * same time, though, the source of truth for the data is the prop data. This presents a\n * challenge: how do we keep local state in sync with the prop data without mangling user input as\n * data comes in?\n *\n * Consider, for example, that the user types \"Hello\". If at a later time, when the user is trying\n * to type \", world\" the component re-renders with prop data \"H\", \"He\", \"Hel\", \"Hell\", \"Hello\", it\n * will disrupt the user's typing. This could also happen as a result of the prop data changing\n * for other reasons, like collaborators changing the prop data concurrently. We want to avoid to\n * disrupt the user's typing, while at the same time display the \"true\" value as quickly as\n * possible.\n *\n * The approach we take here is to commit the prop data at an opportune time: as the user is\n * typing we avoid to commit prop data. But once they've stopped typing, we commit it as soon as\n * possible. This is known as a debounce.\n */\n const [value, setValue] = useState(() => {\n const { selection, ...textWithoutSelection } = text ?? defaultText\n\n return Value.fromJSON(textWithoutSelection)\n })\n const [shouldCommit, setShouldCommit] = useState(true)\n\n useEffect(() => {\n if (shouldCommit) {\n const nextValue = Value.fromJSON(text ?? defaultText)\n\n setValue(currentValue =>\n currentValue.selection.isBlurred\n ? Value.fromJSON(nextValue.toJSON({ preserveSelection: false }))\n : nextValue,\n )\n }\n }, [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 function handleChange(change: OnChangeParam) {\n setValue(change.value as Value)\n\n if (change.value !== value) {\n setShouldCommit(false)\n\n controller?.onChange(change)\n }\n }\n\n // HACK: Slate holds on to the very first DOM event handlers passed in and doesn't update them\n // even if they change. Since `controller` is first `undefined` then we must use a ref.\n const lastController = useRef(controller)\n if (lastController.current !== controller) lastController.current = controller\n const handleFocus = useCallback(() => {\n lastController.current?.focus()\n }, [])\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent, _editor: Editor, next: () => any) => {\n if (Hotkeys.isUndo(event)) {\n lastController.current?.undo()\n\n return true\n }\n\n if (Hotkeys.isRedo(event)) {\n lastController.current?.redo()\n\n return true\n }\n\n if (isHotkey('escape')(event)) {\n lastController.current?.blur()\n\n return true\n }\n\n return next()\n },\n [],\n )\n const handleBlur = useCallback((event: ReactFocusEvent, editor: Editor, next: () => any) => {\n const selection = editor.value.selection\n\n next()\n\n // Normally, after a user highlight a text, clicking on the panel will remove the text selection.\n // This line is a workaround for that. Because the panel is not in the iframe, relatedTarget\n // would be null, and we select the previous text selection to maintain the text highlight.\n // Inspiration: https://github.com/ianstormtaylor/slate/issues/3412#issuecomment-663906003\n if (event.relatedTarget == null) editor.select(selection)\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <RichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), width, margin)}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n readOnly={!isInBuilder || controller == null}\n />\n )\n})\n\nexport default EditableText\n"],"names":["TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","Mark","data","get","renderBlock","props","node","attributes","blockProps","textAlign","Block","className","restOfProps","Link","cx","useStyle","textDecoration","renderInline","toJS","RichTextEditor","forwardRef","ref","placeholder","plugins","useMemo","Lists","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","WebkitUserModify","undefined","margin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","EditableText","id","text","width","editor","setEditor","useState","propControllers","setPropControllers","controller","useEffect","element","findDOMNode","HTMLElement","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getBoxModel","el","Element","getBox","setSlateEditor","value","setValue","selection","textWithoutSelection","Value","fromJSON","shouldCommit","setShouldCommit","nextValue","currentValue","isBlurred","toJSON","preserveSelection","timeoutId","window","setTimeout","clearTimeout","change","onChange","lastController","useRef","current","handleFocus","useCallback","focus","handleKeyDown","event","Hotkeys","isUndo","undo","isRedo","redo","isHotkey","blur","handleBlur","relatedTarget","select","isInBuilder","useIsInBuilder","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAMA,kBAAkB;AAEqC,sCAAA;AACpD,SAAA;AAAA,IACLC,WAAW;AAAA,MAAEC;AAAAA,MAAMC;AAAAA,OAAYC,SAASC,OAAM;AACxCH,UAAAA,KAAKI,SAASN,iBAAiB;AACjC,8CAAQO,MAAAA,MAAD;AAAA,UAAM,OAAOL,KAAKM,KAAKC,IAAI,OAAd;AAAA,UAAyBN;AAAAA,QAAAA,CAA7C;AAAA,MACD;AAED,aAAOE,MAAP;AAAA,IACD;AAAA,EAAA;AAEJ;ACZ4D,sCAAA;AACpD,SAAA;AAAA,IACLK,YAAYC,OAAOP,SAASC,OAAmB;AACvC,YAAA;AAAA,QAAEO;AAAAA,QAAMC;AAAAA,QAAYV;AAAAA,UAAaQ;AACvC,YAAMG,aAAa;AAAA,QAAEC,WAAWH,KAAKJ,KAAKC,IAAI,WAAd;AAAA,MAAA;AAExBG,cAAAA,KAAKN;AAAAA,aACN;AAED,gDAACU,MAAAA,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA,YACvCX;AAAAA,UAAAA,EAFL;AAAA,aAMG;AAED,gDAACa,MAAAA,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA,YACvCX;AAAAA,UAAAA,EAFL;AAAA,aAMG;AAED,gDAACa,MAAAA,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA,YACvCX;AAAAA,UAAAA,EAFL;AAAA,aAMG;AAED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AEjB,aAAA;AAAA,IACR;AAED,QAAIC,kBAAS,QAAD,EAAWN,KAAnB,GAA2B;AAC7BP,2BAAeE,YAAfF,mBAAwBc;AAEjB,aAAA;AAAA,IACR;AAED,WAAOhG,MAAP;AAAA,EApB6B,GAsB/B,CAtB+B,CAAA;AAwBjC,QAAMiG,aAAaX,MAAAA,YAAY,CAACG,OAAwB9C,SAAgB3C,UAAoB;AACpFiE,UAAAA,YAAYtB,QAAOoB,MAAME;;AAQ3BwB,QAAAA,MAAMS,iBAAiB;AAAMvD,cAAOwD,OAAOlC,SAAd;AAAA,EATL,GAU3B,CAV2B,CAAA;AAYxBmC,QAAAA,cAAcC,KAAAA;AAGlB,wCAAC,gBAAD;AAAA,IAEE;AAAA,IACA,KAAKzD;AAAAA,IACL,WAAW7B,OAAGC,cAAS;AAAA,MAAY,UAAA;AAAA,QAAEiB,QAAQ;AAAA,MAAV;AAAA,IAAA,CAAb,GAA+BS,OAAOT,MAA/C;AAAA,IACb;AAAA,IACA,UAAUqE;AAAAA,IACV,SAASjB;AAAAA,IACT,WAAWG;AAAAA,IACX,QAAQS;AAAAA,IACR,UAAU,CAACG,eAAepD,cAAc;AAAA,EAAA,CAX5C;AAcD,CAxJ8B;;"}
1
+ {"version":3,"file":"EditableText.cjs.js","sources":["../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesBlocks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Link.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Inlines.tsx","../src/components/builtin/Text/components/RichTextEditor/index.tsx","../src/components/builtin/Text/EditableText.tsx"],"sourcesContent":["import type { Plugin } from 'slate-react'\n\nimport Mark from '../components/Mark'\n\nconst TYPOGRAPHY_TYPE = 'typography'\n\nexport default function DeviceOverridesMarksPlugin(): Plugin {\n return {\n renderMark({ mark, children }, _editor, next) {\n if (mark.type === TYPOGRAPHY_TYPE) {\n return <Mark value={mark.data.get('value')}>{children}</Mark>\n }\n\n return next()\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nimport Block from '../components/Block'\n\nexport default function DeviceOverridesBlockPlugin(): Plugin {\n return {\n renderBlock(props, _editor, next): JSX.Element {\n const { node, attributes, children } = props\n const blockProps = { textAlign: node.data.get('textAlign') }\n\n switch (node.type) {\n case 'paragraph':\n return (\n <Block {...attributes} {...blockProps} as=\"p\">\n {children}\n </Block>\n )\n\n case 'heading-one':\n return (\n <Block {...attributes} {...blockProps} as=\"h1\">\n {children}\n </Block>\n )\n\n case 'heading-two':\n return (\n <Block {...attributes} {...blockProps} as=\"h2\">\n {children}\n </Block>\n )\n\n case 'heading-three':\n return (\n <Block {...attributes} {...blockProps} as=\"h3\">\n {children}\n </Block>\n )\n\n case 'heading-four':\n return (\n <Block {...attributes} {...blockProps} as=\"h4\">\n {children}\n </Block>\n )\n\n case 'heading-five':\n return (\n <Block {...attributes} {...blockProps} as=\"h5\">\n {children}\n </Block>\n )\n\n case 'heading-six':\n return (\n <Block {...attributes} {...blockProps} as=\"h6\">\n {children}\n </Block>\n )\n\n case 'blockquote':\n return (\n <Block {...attributes} {...blockProps} as=\"blockquote\">\n {children}\n </Block>\n )\n\n default:\n return next()\n }\n },\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { Plugin } from 'slate-react'\nimport { useStyle } from '../../../../../../runtimes/react/use-style'\n\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 default function LinkPlugin(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'link': {\n const { data } = node\n\n return (\n <StyledLink {...attributes} link={data.toJS()}>\n {children}\n </StyledLink>\n )\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nexport default function Inlines(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'code': {\n return <code {...attributes}>{children}</code>\n }\n\n case 'superscript': {\n return <sup {...attributes}>{children}</sup>\n }\n\n case 'subscript': {\n return <sub {...attributes}>{children}</sub>\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { ComponentPropsWithoutRef, forwardRef, useMemo } from 'react'\n\nimport { Editor as SlateEditor } from 'slate-react'\n\n// @ts-expect-error: no types for '@convertkit/slate-lists'\nimport Lists from '@convertkit/slate-lists'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', className, ...restOfProps }: Props,\n ref,\n) {\n const plugins = useMemo(\n () => [Lists(), Link(), Inlines(), DeviceOverridesBlocks(), DeviceOverridesMarks()],\n [],\n )\n\n return (\n <SlateEditor\n {...restOfProps}\n // Workaround because our Slate editor is broken on Chrome 105\n // Problem: https://linear.app/makeswift/issue/PRD-434/our-rich-text-component-breaks-in-the-latest-version-of-chrome\n // Workaround: https://github.com/ianstormtaylor/slate/issues/5110#issuecomment-1234951122\n style={{ WebkitUserModify: undefined }}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), className)}\n ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n})\n","import {\n useState,\n Ref,\n useImperativeHandle,\n forwardRef,\n useEffect,\n useCallback,\n useRef,\n KeyboardEvent as ReactKeyboardEvent,\n FocusEvent as ReactFocusEvent,\n MouseEvent as ReactMouseEvent,\n} from 'react'\nimport { Editor, OnChangeParam } from 'slate-react'\nimport { Value, ValueJSON } from 'slate'\n// @ts-expect-error: no types for 'slate-hotkeys'\nimport Hotkeys from 'slate-hotkeys'\nimport { isHotkey } from 'is-hotkey'\n\nimport {\n ElementIDValue,\n RichTextDescriptor,\n RichTextValue,\n} from '../../../prop-controllers/descriptors'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\nimport { cx } from '@emotion/css'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { pollBoxModel } from '../../../runtimes/react/poll-box-model'\nimport { useBuilderEditMode } from '../../../runtimes/react'\nimport { BuilderEditMode } from '../../../state/modules/builder-edit-mode'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst defaultText: ValueJSON = {\n document: { nodes: [{ object: 'block' as const, type: 'paragraph' as const, nodes: [] }] },\n data: {},\n}\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\ntype Descriptors = { text?: RichTextDescriptor }\n\nconst EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<BoxModelHandle & PropControllersHandle<Descriptors>>,\n) {\n const [editor, setEditor] = useState<Editor | null>(null)\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n const editMode = useBuilderEditMode()\n\n useEffect(() => {\n const element = editor?.findDOMNode([])\n if (element == null || !(element instanceof HTMLElement) || controller == null) return\n return pollBoxModel({\n element: element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getBoxModel() {\n const el = editor?.findDOMNode([])\n\n return el instanceof Element ? getBox(el) : null\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n useEffect(() => {\n if (editor) controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n /**\n * We must keep local state so that we can reflect the user's typed changes immediately. At the\n * same time, though, the source of truth for the data is the prop data. This presents a\n * challenge: how do we keep local state in sync with the prop data without mangling user input as\n * data comes in?\n *\n * Consider, for example, that the user types \"Hello\". If at a later time, when the user is trying\n * to type \", world\" the component re-renders with prop data \"H\", \"He\", \"Hel\", \"Hell\", \"Hello\", it\n * will disrupt the user's typing. This could also happen as a result of the prop data changing\n * for other reasons, like collaborators changing the prop data concurrently. We want to avoid to\n * disrupt the user's typing, while at the same time display the \"true\" value as quickly as\n * possible.\n *\n * The approach we take here is to commit the prop data at an opportune time: as the user is\n * typing we avoid to commit prop data. But once they've stopped typing, we commit it as soon as\n * possible. This is known as a debounce.\n */\n const [value, setValue] = useState(() => {\n const { selection, ...textWithoutSelection } = text ?? defaultText\n\n return Value.fromJSON(textWithoutSelection)\n })\n const [shouldCommit, setShouldCommit] = useState(true)\n\n useEffect(() => {\n if (shouldCommit) {\n const nextValue = Value.fromJSON(text ?? defaultText)\n\n setValue(currentValue =>\n currentValue.selection.isBlurred\n ? Value.fromJSON(nextValue.toJSON({ preserveSelection: false }))\n : nextValue,\n )\n }\n }, [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 function handleChange(change: OnChangeParam) {\n setValue(change.value as Value)\n\n if (change.value !== value) {\n setShouldCommit(false)\n\n controller?.onChange(change)\n }\n }\n\n // HACK: Slate holds on to the very first DOM event handlers passed in and doesn't update them\n // even if they change. Since `controller` is first `undefined` then we must use a ref.\n const lastController = useRef(controller)\n if (lastController.current !== controller) lastController.current = controller\n const handleFocus = useCallback(() => {\n lastController.current?.focus()\n }, [])\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent, _editor: Editor, next: () => any) => {\n if (Hotkeys.isUndo(event)) {\n lastController.current?.undo()\n\n return true\n }\n\n if (Hotkeys.isRedo(event)) {\n lastController.current?.redo()\n\n return true\n }\n\n if (isHotkey('escape')(event)) {\n lastController.current?.blur()\n\n return true\n }\n\n return next()\n },\n [],\n )\n const handleBlur = useCallback((event: ReactFocusEvent, editor: Editor, next: () => any) => {\n const selection = editor.value.selection\n\n next()\n\n // Normally, after a user highlight a text, clicking on the panel will remove the text selection.\n // This line is a workaround for that. Because the panel is not in the iframe, relatedTarget\n // would be null, and we select the previous text selection to maintain the text highlight.\n // Inspiration: https://github.com/ianstormtaylor/slate/issues/3412#issuecomment-663906003\n if (event.relatedTarget == null) editor.select(selection)\n }, [])\n\n // HACK: Slate holds on to the very first DOM event handlers passed in and doesn't update them\n // even if they change.\n const lastEditMode = useRef(editMode)\n if (lastEditMode.current !== editMode) lastEditMode.current = editMode\n\n const handleClick = (event: ReactMouseEvent, _editor: Editor, next: () => any) => {\n next()\n\n // This is needed to prevent clicks from propagating in content mode.\n // This is not ideal because it might break if we implement a plugin in the future that depends on click.\n // Also, we might also want to stop hover/mousedown event\n if (lastEditMode.current === BuilderEditMode.CONTENT) event.stopPropagation()\n }\n\n return (\n <RichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), width, margin)}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n onClick={handleClick}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n />\n )\n})\n\nexport default EditableText\n"],"names":["TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","Mark","data","get","renderBlock","props","node","attributes","blockProps","textAlign","Block","className","restOfProps","Link","cx","useStyle","textDecoration","renderInline","toJS","RichTextEditor","forwardRef","ref","placeholder","plugins","useMemo","Lists","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","WebkitUserModify","undefined","margin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","EditableText","id","text","width","editor","setEditor","useState","propControllers","setPropControllers","controller","editMode","useBuilderEditMode","useEffect","element","findDOMNode","HTMLElement","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getBoxModel","el","Element","getBox","setSlateEditor","value","setValue","selection","textWithoutSelection","Value","fromJSON","shouldCommit","setShouldCommit","nextValue","currentValue","isBlurred","toJSON","preserveSelection","timeoutId","window","setTimeout","clearTimeout","change","onChange","lastController","useRef","current","handleFocus","useCallback","focus","handleKeyDown","event","Hotkeys","isUndo","undo","isRedo","redo","isHotkey","blur","handleBlur","relatedTarget","select","lastEditMode","handleClick","BuilderEditMode","CONTENT","stopPropagation","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAMA,kBAAkB;AAEqC,sCAAA;AACpD,SAAA;AAAA,IACLC,WAAW;AAAA,MAAEC;AAAAA,MAAMC;AAAAA,OAAYC,SAASC,OAAM;AACxCH,UAAAA,KAAKI,SAASN,iBAAiB;AACjC,8CAAQO,MAAAA,MAAD;AAAA,UAAM,OAAOL,KAAKM,KAAKC,IAAI,OAAd;AAAA,UAAyBN;AAAAA,QAAAA,CAA7C;AAAA,MACD;AAED,aAAOE,MAAP;AAAA,IACD;AAAA,EAAA;AAEJ;ACZ4D,sCAAA;AACpD,SAAA;AAAA,IACLK,YAAYC,OAAOP,SAASC,OAAmB;AACvC,YAAA;AAAA,QAAEO;AAAAA,QAAMC;AAAAA,QAAYV;AAAAA,UAAaQ;AACvC,YAAMG,aAAa;AAAA,QAAEC,WAAWH,KAAKJ,KAAKC,IAAI,WAAd;AAAA,MAAA;AAExBG,cAAAA,KAAKN;AAAAA,aACN;AAED,gDAACU,MAAAA,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA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,SAAAA,gBAAgBC;AAAAA,EAAAA,CAZ3C;AAeD,CAtK8B;;"}
@@ -39,10 +39,10 @@ import Lists from "@convertkit/slate-lists";
39
39
  import { M as Mark, D as DeviceOverrideBlock } from "./index.es6.js";
40
40
  import { jsx } from "react/jsx-runtime";
41
41
  import { cx } from "@emotion/css";
42
- import { o as useStyle, U as pollBoxModel, u as useIsInBuilder } from "./index.es.js";
42
+ import { p as useStyle, V as useBuilderEditMode, W as pollBoxModel } from "./index.es.js";
43
43
  import { L as Link } from "./index.es3.js";
44
44
  import "use-sync-external-store/shim";
45
- import "./rich-text.es.js";
45
+ import { aa as BuilderEditMode } from "./rich-text.es.js";
46
46
  import "css-box-model";
47
47
  import "./actions.es.js";
48
48
  import "./constants.es.js";
@@ -257,6 +257,7 @@ const EditableText = forwardRef(function EditableText2({
257
257
  const [editor, setEditor] = useState(null);
258
258
  const [propControllers, setPropControllers] = useState(null);
259
259
  const controller = propControllers == null ? void 0 : propControllers.text;
260
+ const editMode = useBuilderEditMode();
260
261
  useEffect(() => {
261
262
  const element = editor == null ? void 0 : editor.findDOMNode([]);
262
263
  if (element == null || !(element instanceof HTMLElement) || controller == null)
@@ -340,7 +341,14 @@ const EditableText = forwardRef(function EditableText2({
340
341
  if (event.relatedTarget == null)
341
342
  editor2.select(selection);
342
343
  }, []);
343
- const isInBuilder = useIsInBuilder();
344
+ const lastEditMode = useRef(editMode);
345
+ if (lastEditMode.current !== editMode)
346
+ lastEditMode.current = editMode;
347
+ const handleClick = (event, _editor, next) => {
348
+ next();
349
+ if (lastEditMode.current === BuilderEditMode.CONTENT)
350
+ event.stopPropagation();
351
+ };
344
352
  return /* @__PURE__ */ jsx(RichTextEditor, {
345
353
  id,
346
354
  ref: setEditor,
@@ -354,7 +362,8 @@ const EditableText = forwardRef(function EditableText2({
354
362
  onFocus: handleFocus,
355
363
  onKeyDown: handleKeyDown,
356
364
  onBlur: handleBlur,
357
- readOnly: !isInBuilder || controller == null
365
+ onClick: handleClick,
366
+ readOnly: editMode !== BuilderEditMode.CONTENT
358
367
  });
359
368
  });
360
369
  export { EditableText as default };
@@ -1 +1 @@
1
- {"version":3,"file":"EditableText.es.js","sources":["../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesBlocks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Link.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Inlines.tsx","../src/components/builtin/Text/components/RichTextEditor/index.tsx","../src/components/builtin/Text/EditableText.tsx"],"sourcesContent":["import type { Plugin } from 'slate-react'\n\nimport Mark from '../components/Mark'\n\nconst TYPOGRAPHY_TYPE = 'typography'\n\nexport default function DeviceOverridesMarksPlugin(): Plugin {\n return {\n renderMark({ mark, children }, _editor, next) {\n if (mark.type === TYPOGRAPHY_TYPE) {\n return <Mark value={mark.data.get('value')}>{children}</Mark>\n }\n\n return next()\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nimport Block from '../components/Block'\n\nexport default function DeviceOverridesBlockPlugin(): Plugin {\n return {\n renderBlock(props, _editor, next): JSX.Element {\n const { node, attributes, children } = props\n const blockProps = { textAlign: node.data.get('textAlign') }\n\n switch (node.type) {\n case 'paragraph':\n return (\n <Block {...attributes} {...blockProps} as=\"p\">\n {children}\n </Block>\n )\n\n case 'heading-one':\n return (\n <Block {...attributes} {...blockProps} as=\"h1\">\n {children}\n </Block>\n )\n\n case 'heading-two':\n return (\n <Block {...attributes} {...blockProps} as=\"h2\">\n {children}\n </Block>\n )\n\n case 'heading-three':\n return (\n <Block {...attributes} {...blockProps} as=\"h3\">\n {children}\n </Block>\n )\n\n case 'heading-four':\n return (\n <Block {...attributes} {...blockProps} as=\"h4\">\n {children}\n </Block>\n )\n\n case 'heading-five':\n return (\n <Block {...attributes} {...blockProps} as=\"h5\">\n {children}\n </Block>\n )\n\n case 'heading-six':\n return (\n <Block {...attributes} {...blockProps} as=\"h6\">\n {children}\n </Block>\n )\n\n case 'blockquote':\n return (\n <Block {...attributes} {...blockProps} as=\"blockquote\">\n {children}\n </Block>\n )\n\n default:\n return next()\n }\n },\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { Plugin } from 'slate-react'\nimport { useStyle } from '../../../../../../runtimes/react/use-style'\n\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 default function LinkPlugin(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'link': {\n const { data } = node\n\n return (\n <StyledLink {...attributes} link={data.toJS()}>\n {children}\n </StyledLink>\n )\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nexport default function Inlines(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'code': {\n return <code {...attributes}>{children}</code>\n }\n\n case 'superscript': {\n return <sup {...attributes}>{children}</sup>\n }\n\n case 'subscript': {\n return <sub {...attributes}>{children}</sub>\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { ComponentPropsWithoutRef, forwardRef, useMemo } from 'react'\n\nimport { Editor as SlateEditor } from 'slate-react'\n\n// @ts-expect-error: no types for '@convertkit/slate-lists'\nimport Lists from '@convertkit/slate-lists'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', className, ...restOfProps }: Props,\n ref,\n) {\n const plugins = useMemo(\n () => [Lists(), Link(), Inlines(), DeviceOverridesBlocks(), DeviceOverridesMarks()],\n [],\n )\n\n return (\n <SlateEditor\n {...restOfProps}\n // Workaround because our Slate editor is broken on Chrome 105\n // Problem: https://linear.app/makeswift/issue/PRD-434/our-rich-text-component-breaks-in-the-latest-version-of-chrome\n // Workaround: https://github.com/ianstormtaylor/slate/issues/5110#issuecomment-1234951122\n style={{ WebkitUserModify: undefined }}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), className)}\n ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n})\n","import {\n useState,\n Ref,\n useImperativeHandle,\n forwardRef,\n useEffect,\n useCallback,\n useRef,\n KeyboardEvent as ReactKeyboardEvent,\n FocusEvent as ReactFocusEvent,\n} from 'react'\nimport { Editor, OnChangeParam } from 'slate-react'\nimport { Value, ValueJSON } from 'slate'\n// @ts-expect-error: no types for 'slate-hotkeys'\nimport Hotkeys from 'slate-hotkeys'\nimport { isHotkey } from 'is-hotkey'\n\nimport {\n ElementIDValue,\n RichTextDescriptor,\n RichTextValue,\n} from '../../../prop-controllers/descriptors'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\nimport { cx } from '@emotion/css'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { useIsInBuilder } from '../../../runtimes/react'\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: ValueJSON = {\n document: { nodes: [{ object: 'block' as const, type: 'paragraph' as const, nodes: [] }] },\n data: {},\n}\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\ntype Descriptors = { text?: RichTextDescriptor }\n\nconst EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<BoxModelHandle & PropControllersHandle<Descriptors>>,\n) {\n const [editor, setEditor] = useState<Editor | null>(null)\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n const element = editor?.findDOMNode([])\n if (element == null || !(element instanceof HTMLElement) || controller == null) return\n return pollBoxModel({\n element: element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getBoxModel() {\n const el = editor?.findDOMNode([])\n\n return el instanceof Element ? getBox(el) : null\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n useEffect(() => {\n if (editor) controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n /**\n * We must keep local state so that we can reflect the user's typed changes immediately. At the\n * same time, though, the source of truth for the data is the prop data. This presents a\n * challenge: how do we keep local state in sync with the prop data without mangling user input as\n * data comes in?\n *\n * Consider, for example, that the user types \"Hello\". If at a later time, when the user is trying\n * to type \", world\" the component re-renders with prop data \"H\", \"He\", \"Hel\", \"Hell\", \"Hello\", it\n * will disrupt the user's typing. This could also happen as a result of the prop data changing\n * for other reasons, like collaborators changing the prop data concurrently. We want to avoid to\n * disrupt the user's typing, while at the same time display the \"true\" value as quickly as\n * possible.\n *\n * The approach we take here is to commit the prop data at an opportune time: as the user is\n * typing we avoid to commit prop data. But once they've stopped typing, we commit it as soon as\n * possible. This is known as a debounce.\n */\n const [value, setValue] = useState(() => {\n const { selection, ...textWithoutSelection } = text ?? defaultText\n\n return Value.fromJSON(textWithoutSelection)\n })\n const [shouldCommit, setShouldCommit] = useState(true)\n\n useEffect(() => {\n if (shouldCommit) {\n const nextValue = Value.fromJSON(text ?? defaultText)\n\n setValue(currentValue =>\n currentValue.selection.isBlurred\n ? Value.fromJSON(nextValue.toJSON({ preserveSelection: false }))\n : nextValue,\n )\n }\n }, [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 function handleChange(change: OnChangeParam) {\n setValue(change.value as Value)\n\n if (change.value !== value) {\n setShouldCommit(false)\n\n controller?.onChange(change)\n }\n }\n\n // HACK: Slate holds on to the very first DOM event handlers passed in and doesn't update them\n // even if they change. Since `controller` is first `undefined` then we must use a ref.\n const lastController = useRef(controller)\n if (lastController.current !== controller) lastController.current = controller\n const handleFocus = useCallback(() => {\n lastController.current?.focus()\n }, [])\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent, _editor: Editor, next: () => any) => {\n if (Hotkeys.isUndo(event)) {\n lastController.current?.undo()\n\n return true\n }\n\n if (Hotkeys.isRedo(event)) {\n lastController.current?.redo()\n\n return true\n }\n\n if (isHotkey('escape')(event)) {\n lastController.current?.blur()\n\n return true\n }\n\n return next()\n },\n [],\n )\n const handleBlur = useCallback((event: ReactFocusEvent, editor: Editor, next: () => any) => {\n const selection = editor.value.selection\n\n next()\n\n // Normally, after a user highlight a text, clicking on the panel will remove the text selection.\n // This line is a workaround for that. Because the panel is not in the iframe, relatedTarget\n // would be null, and we select the previous text selection to maintain the text highlight.\n // Inspiration: https://github.com/ianstormtaylor/slate/issues/3412#issuecomment-663906003\n if (event.relatedTarget == null) editor.select(selection)\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <RichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), width, margin)}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n readOnly={!isInBuilder || controller == null}\n />\n )\n})\n\nexport default EditableText\n"],"names":["TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","data","get","renderBlock","props","node","attributes","blockProps","textAlign","Block","className","restOfProps","cx","useStyle","textDecoration","renderInline","toJS","RichTextEditor","forwardRef","ref","placeholder","plugins","useMemo","Lists","Link","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","WebkitUserModify","undefined","margin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","EditableText","id","text","width","editor","setEditor","useState","propControllers","setPropControllers","controller","useEffect","element","findDOMNode","HTMLElement","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getBoxModel","el","Element","getBox","setSlateEditor","value","setValue","selection","textWithoutSelection","Value","fromJSON","shouldCommit","setShouldCommit","nextValue","currentValue","isBlurred","toJSON","preserveSelection","timeoutId","window","setTimeout","clearTimeout","change","onChange","lastController","useRef","current","handleFocus","useCallback","focus","handleKeyDown","event","Hotkeys","isUndo","undo","isRedo","redo","isHotkey","blur","handleBlur","relatedTarget","select","isInBuilder","useIsInBuilder","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAMA,kBAAkB;AAEqC,sCAAA;AACpD,SAAA;AAAA,IACLC,WAAW;AAAA,MAAEC;AAAAA,MAAMC;AAAAA,OAAYC,SAASC,MAAM;AACxCH,UAAAA,KAAKI,SAASN,iBAAiB;AACjC,mCAAQ,MAAD;AAAA,UAAM,OAAOE,KAAKK,KAAKC,IAAI,OAAd;AAAA,UAAyBL;AAAAA,QAAAA,CAA7C;AAAA,MACD;AAED,aAAOE,KAAP;AAAA,IACD;AAAA,EAAA;AAEJ;ACZ4D,sCAAA;AACpD,SAAA;AAAA,IACLI,YAAYC,OAAON,SAASC,MAAmB;AACvC,YAAA;AAAA,QAAEM;AAAAA,QAAMC;AAAAA,QAAYT;AAAAA,UAAaO;AACvC,YAAMG,aAAa;AAAA,QAAEC,WAAWH,KAAKJ,KAAKC,IAAI,WAAd;AAAA,MAAA;AAExB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,OAAOF,KAAf,GAAuB;AACzBP,2BAAeE,YAAfF,mBAAwBU;AAEjB,aAAA;AAAA,IACR;AAEGF,QAAAA,QAAQG,OAAOJ,KAAf,GAAuB;AACzBP,2BAAeE,YAAfF,mBAAwBY;AAEjB,aAAA;AAAA,IACR;AAED,QAAIC,SAAS,QAAD,EAAWN,KAAnB,GAA2B;AAC7BP,2BAAeE,YAAfF,mBAAwBc;AAEjB,aAAA;AAAA,IACR;AAED,WAAO/F,KAAP;AAAA,EApB6B,GAsB/B,CAtB+B,CAAA;AAwBjC,QAAMgG,aAAaX,YAAY,CAACG,OAAwB9C,SAAgB1C,SAAoB;AACpFgE,UAAAA,YAAYtB,QAAOoB,MAAME;;AAQ3BwB,QAAAA,MAAMS,iBAAiB;AAAMvD,cAAOwD,OAAOlC,SAAd;AAAA,EATL,GAU3B,CAV2B,CAAA;AAYxBmC,QAAAA,cAAcC;AAGlB,6BAAC,gBAAD;AAAA,IAEE;AAAA,IACA,KAAKzD;AAAAA,IACL,WAAW9B,GAAGC,SAAS;AAAA,MAAY,UAAA;AAAA,QAAEkB,QAAQ;AAAA,MAAV;AAAA,IAAA,CAAb,GAA+BS,OAAOT,MAA/C;AAAA,IACb;AAAA,IACA,UAAUqE;AAAAA,IACV,SAASjB;AAAAA,IACT,WAAWG;AAAAA,IACX,QAAQS;AAAAA,IACR,UAAU,CAACG,eAAepD,cAAc;AAAA,EAAA,CAX5C;AAcD,CAxJ8B;;"}
1
+ {"version":3,"file":"EditableText.es.js","sources":["../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesBlocks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Link.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Inlines.tsx","../src/components/builtin/Text/components/RichTextEditor/index.tsx","../src/components/builtin/Text/EditableText.tsx"],"sourcesContent":["import type { Plugin } from 'slate-react'\n\nimport Mark from '../components/Mark'\n\nconst TYPOGRAPHY_TYPE = 'typography'\n\nexport default function DeviceOverridesMarksPlugin(): Plugin {\n return {\n renderMark({ mark, children }, _editor, next) {\n if (mark.type === TYPOGRAPHY_TYPE) {\n return <Mark value={mark.data.get('value')}>{children}</Mark>\n }\n\n return next()\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nimport Block from '../components/Block'\n\nexport default function DeviceOverridesBlockPlugin(): Plugin {\n return {\n renderBlock(props, _editor, next): JSX.Element {\n const { node, attributes, children } = props\n const blockProps = { textAlign: node.data.get('textAlign') }\n\n switch (node.type) {\n case 'paragraph':\n return (\n <Block {...attributes} {...blockProps} as=\"p\">\n {children}\n </Block>\n )\n\n case 'heading-one':\n return (\n <Block {...attributes} {...blockProps} as=\"h1\">\n {children}\n </Block>\n )\n\n case 'heading-two':\n return (\n <Block {...attributes} {...blockProps} as=\"h2\">\n {children}\n </Block>\n )\n\n case 'heading-three':\n return (\n <Block {...attributes} {...blockProps} as=\"h3\">\n {children}\n </Block>\n )\n\n case 'heading-four':\n return (\n <Block {...attributes} {...blockProps} as=\"h4\">\n {children}\n </Block>\n )\n\n case 'heading-five':\n return (\n <Block {...attributes} {...blockProps} as=\"h5\">\n {children}\n </Block>\n )\n\n case 'heading-six':\n return (\n <Block {...attributes} {...blockProps} as=\"h6\">\n {children}\n </Block>\n )\n\n case 'blockquote':\n return (\n <Block {...attributes} {...blockProps} as=\"blockquote\">\n {children}\n </Block>\n )\n\n default:\n return next()\n }\n },\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { Plugin } from 'slate-react'\nimport { useStyle } from '../../../../../../runtimes/react/use-style'\n\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 default function LinkPlugin(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'link': {\n const { data } = node\n\n return (\n <StyledLink {...attributes} link={data.toJS()}>\n {children}\n </StyledLink>\n )\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nexport default function Inlines(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'code': {\n return <code {...attributes}>{children}</code>\n }\n\n case 'superscript': {\n return <sup {...attributes}>{children}</sup>\n }\n\n case 'subscript': {\n return <sub {...attributes}>{children}</sub>\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { ComponentPropsWithoutRef, forwardRef, useMemo } from 'react'\n\nimport { Editor as SlateEditor } from 'slate-react'\n\n// @ts-expect-error: no types for '@convertkit/slate-lists'\nimport Lists from '@convertkit/slate-lists'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', className, ...restOfProps }: Props,\n ref,\n) {\n const plugins = useMemo(\n () => [Lists(), Link(), Inlines(), DeviceOverridesBlocks(), DeviceOverridesMarks()],\n [],\n )\n\n return (\n <SlateEditor\n {...restOfProps}\n // Workaround because our Slate editor is broken on Chrome 105\n // Problem: https://linear.app/makeswift/issue/PRD-434/our-rich-text-component-breaks-in-the-latest-version-of-chrome\n // Workaround: https://github.com/ianstormtaylor/slate/issues/5110#issuecomment-1234951122\n style={{ WebkitUserModify: undefined }}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), className)}\n ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n})\n","import {\n useState,\n Ref,\n useImperativeHandle,\n forwardRef,\n useEffect,\n useCallback,\n useRef,\n KeyboardEvent as ReactKeyboardEvent,\n FocusEvent as ReactFocusEvent,\n MouseEvent as ReactMouseEvent,\n} from 'react'\nimport { Editor, OnChangeParam } from 'slate-react'\nimport { Value, ValueJSON } from 'slate'\n// @ts-expect-error: no types for 'slate-hotkeys'\nimport Hotkeys from 'slate-hotkeys'\nimport { isHotkey } from 'is-hotkey'\n\nimport {\n ElementIDValue,\n RichTextDescriptor,\n RichTextValue,\n} from '../../../prop-controllers/descriptors'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\nimport { cx } from '@emotion/css'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { pollBoxModel } from '../../../runtimes/react/poll-box-model'\nimport { useBuilderEditMode } from '../../../runtimes/react'\nimport { BuilderEditMode } from '../../../state/modules/builder-edit-mode'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst defaultText: ValueJSON = {\n document: { nodes: [{ object: 'block' as const, type: 'paragraph' as const, nodes: [] }] },\n data: {},\n}\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\ntype Descriptors = { text?: RichTextDescriptor }\n\nconst EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<BoxModelHandle & PropControllersHandle<Descriptors>>,\n) {\n const [editor, setEditor] = useState<Editor | null>(null)\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n const editMode = useBuilderEditMode()\n\n useEffect(() => {\n const element = editor?.findDOMNode([])\n if (element == null || !(element instanceof HTMLElement) || controller == null) return\n return pollBoxModel({\n element: element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getBoxModel() {\n const el = editor?.findDOMNode([])\n\n return el instanceof Element ? getBox(el) : null\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n useEffect(() => {\n if (editor) controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n /**\n * We must keep local state so that we can reflect the user's typed changes immediately. At the\n * same time, though, the source of truth for the data is the prop data. This presents a\n * challenge: how do we keep local state in sync with the prop data without mangling user input as\n * data comes in?\n *\n * Consider, for example, that the user types \"Hello\". If at a later time, when the user is trying\n * to type \", world\" the component re-renders with prop data \"H\", \"He\", \"Hel\", \"Hell\", \"Hello\", it\n * will disrupt the user's typing. This could also happen as a result of the prop data changing\n * for other reasons, like collaborators changing the prop data concurrently. We want to avoid to\n * disrupt the user's typing, while at the same time display the \"true\" value as quickly as\n * possible.\n *\n * The approach we take here is to commit the prop data at an opportune time: as the user is\n * typing we avoid to commit prop data. But once they've stopped typing, we commit it as soon as\n * possible. This is known as a debounce.\n */\n const [value, setValue] = useState(() => {\n const { selection, ...textWithoutSelection } = text ?? defaultText\n\n return Value.fromJSON(textWithoutSelection)\n })\n const [shouldCommit, setShouldCommit] = useState(true)\n\n useEffect(() => {\n if (shouldCommit) {\n const nextValue = Value.fromJSON(text ?? defaultText)\n\n setValue(currentValue =>\n currentValue.selection.isBlurred\n ? Value.fromJSON(nextValue.toJSON({ preserveSelection: false }))\n : nextValue,\n )\n }\n }, [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 function handleChange(change: OnChangeParam) {\n setValue(change.value as Value)\n\n if (change.value !== value) {\n setShouldCommit(false)\n\n controller?.onChange(change)\n }\n }\n\n // HACK: Slate holds on to the very first DOM event handlers passed in and doesn't update them\n // even if they change. Since `controller` is first `undefined` then we must use a ref.\n const lastController = useRef(controller)\n if (lastController.current !== controller) lastController.current = controller\n const handleFocus = useCallback(() => {\n lastController.current?.focus()\n }, [])\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent, _editor: Editor, next: () => any) => {\n if (Hotkeys.isUndo(event)) {\n lastController.current?.undo()\n\n return true\n }\n\n if (Hotkeys.isRedo(event)) {\n lastController.current?.redo()\n\n return true\n }\n\n if (isHotkey('escape')(event)) {\n lastController.current?.blur()\n\n return true\n }\n\n return next()\n },\n [],\n )\n const handleBlur = useCallback((event: ReactFocusEvent, editor: Editor, next: () => any) => {\n const selection = editor.value.selection\n\n next()\n\n // Normally, after a user highlight a text, clicking on the panel will remove the text selection.\n // This line is a workaround for that. Because the panel is not in the iframe, relatedTarget\n // would be null, and we select the previous text selection to maintain the text highlight.\n // Inspiration: https://github.com/ianstormtaylor/slate/issues/3412#issuecomment-663906003\n if (event.relatedTarget == null) editor.select(selection)\n }, [])\n\n // HACK: Slate holds on to the very first DOM event handlers passed in and doesn't update them\n // even if they change.\n const lastEditMode = useRef(editMode)\n if (lastEditMode.current !== editMode) lastEditMode.current = editMode\n\n const handleClick = (event: ReactMouseEvent, _editor: Editor, next: () => any) => {\n next()\n\n // This is needed to prevent clicks from propagating in content mode.\n // This is not ideal because it might break if we implement a plugin in the future that depends on click.\n // Also, we might also want to stop hover/mousedown event\n if (lastEditMode.current === BuilderEditMode.CONTENT) event.stopPropagation()\n }\n\n return (\n <RichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), width, margin)}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n onClick={handleClick}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n />\n )\n})\n\nexport default EditableText\n"],"names":["TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","data","get","renderBlock","props","node","attributes","blockProps","textAlign","Block","className","restOfProps","cx","useStyle","textDecoration","renderInline","toJS","RichTextEditor","forwardRef","ref","placeholder","plugins","useMemo","Lists","Link","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","WebkitUserModify","undefined","margin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","EditableText","id","text","width","editor","setEditor","useState","propControllers","setPropControllers","controller","editMode","useBuilderEditMode","useEffect","element","findDOMNode","HTMLElement","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getBoxModel","el","Element","getBox","setSlateEditor","value","setValue","selection","textWithoutSelection","Value","fromJSON","shouldCommit","setShouldCommit","nextValue","currentValue","isBlurred","toJSON","preserveSelection","timeoutId","window","setTimeout","clearTimeout","change","onChange","lastController","useRef","current","handleFocus","useCallback","focus","handleKeyDown","event","Hotkeys","isUndo","undo","isRedo","redo","isHotkey","blur","handleBlur","relatedTarget","select","lastEditMode","handleClick","BuilderEditMode","CONTENT","stopPropagation","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAMA,kBAAkB;AAEqC,sCAAA;AACpD,SAAA;AAAA,IACLC,WAAW;AAAA,MAAEC;AAAAA,MAAMC;AAAAA,OAAYC,SAASC,MAAM;AACxCH,UAAAA,KAAKI,SAASN,iBAAiB;AACjC,mCAAQ,MAAD;AAAA,UAAM,OAAOE,KAAKK,KAAKC,IAAI,OAAd;AAAA,UAAyBL;AAAAA,QAAAA,CAA7C;AAAA,MACD;AAED,aAAOE,KAAP;AAAA,IACD;AAAA,EAAA;AAEJ;ACZ4D,sCAAA;AACpD,SAAA;AAAA,IACLI,YAAYC,OAAON,SAASC,MAAmB;AACvC,YAAA;AAAA,QAAEM;AAAAA,QAAMC;AAAAA,QAAYT;AAAAA,UAAaO;AACvC,YAAMG,aAAa;AAAA,QAAEC,WAAWH,KAAKJ,KAAKC,IAAI,WAAd;AAAA,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"react";
2
2
  import { u as useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.es.js";
3
- import { o as useStyle } from "./index.es.js";
3
+ import { p as useStyle } from "./index.es.js";
4
4
  import { cx } from "@emotion/css";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import "use-sync-external-store/shim/with-selector";
package/dist/Form.es.js CHANGED
@@ -33,7 +33,7 @@ import * as React from "react";
33
33
  import { forwardRef, useRef, useImperativeHandle, useState, useEffect, useMemo } from "react";
34
34
  import { Field as Field$1, getIn, Formik } from "formik";
35
35
  import { cx, keyframes } from "@emotion/css";
36
- import { r as responsiveStyle, S as Shapes, t as Sizes, C as Contrasts, s as colorToString, v as useFormContext, o as useStyle, q as responsiveTextStyle, u as useIsInBuilder, w as responsiveGridItem, x as useTable, y as useMakeswiftClient, z as Provider, A as Alignments } from "./index.es.js";
36
+ import { r as responsiveStyle, S as Shapes, v as Sizes, C as Contrasts, t as colorToString, w as useFormContext, p as useStyle, s as responsiveTextStyle, u as useIsInBuilder, x as responsiveGridItem, y as useTable, z as useMakeswiftClient, A as Provider, B as Alignments } from "./index.es.js";
37
37
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
38
38
  import ColorHelper from "color";
39
39
  import Button$1 from "./Button.es.js";
package/dist/Image.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { forwardRef, useState, useEffect } from "react";
2
2
  import NextImage from "next/image";
3
- import { B as useFile, o as useStyle, p as responsiveWidth, r as responsiveStyle, F as DEVICES, G as findDeviceOverride } from "./index.es.js";
3
+ import { F as useFile, p as useStyle, q as responsiveWidth, r as responsiveStyle, G as DEVICES, H as findDeviceOverride } from "./index.es.js";
4
4
  import { p as placeholders } from "./placeholders.es.js";
5
5
  import { L as Link } from "./index.es3.js";
6
6
  import { cx } from "@emotion/css";
@@ -1,5 +1,5 @@
1
1
  import { useMemo } from "react";
2
- import { O as storeContextDefaultValue, Q as StoreContext, T as MakeswiftProvider } from "./index.es.js";
2
+ import { Q as storeContextDefaultValue, T as StoreContext, U as MakeswiftProvider } from "./index.es.js";
3
3
  import { r as configureStore } from "./constants.es.js";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import "use-sync-external-store/shim/with-selector";
@@ -34,7 +34,7 @@ import { forwardRef, useRef, useState, createElement, Fragment as Fragment$1 } f
34
34
  import { G as GutterContainer } from "./index.es4.js";
35
35
  import ImageComponent from "./Image.es.js";
36
36
  import Button from "./Button.es.js";
37
- import { o as useStyle, l as useResponsiveColor, q as responsiveTextStyle, r as responsiveStyle, s as colorToString } from "./index.es.js";
37
+ import { p as useStyle, l as useResponsiveColor, s as responsiveTextStyle, r as responsiveStyle, t as colorToString } from "./index.es.js";
38
38
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
39
39
  import "use-sync-external-store/shim";
40
40
  import "./rich-text.es.js";
@@ -23,6 +23,7 @@ var React = require("react");
23
23
  var next = require("./index.cjs.js");
24
24
  var redux = require("redux");
25
25
  var thunk = require("redux-thunk");
26
+ var isHotkey = require("is-hotkey");
26
27
  var immutable = require("immutable");
27
28
  var constants = require("./constants.cjs.js");
28
29
  var actions = require("./actions.cjs.js");
@@ -58,6 +59,7 @@ function _interopDefaultLegacy(e) {
58
59
  return e && typeof e === "object" && "default" in e ? e : { "default": e };
59
60
  }
60
61
  var thunk__default = /* @__PURE__ */ _interopDefaultLegacy(thunk);
62
+ var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
61
63
  function apply(data, operation) {
62
64
  let applied = data;
63
65
  operation.forEach((component) => {
@@ -106,7 +108,8 @@ const reducer = redux.combineReducers({
106
108
  propControllers: constants.reducer$3,
107
109
  propControllerHandles: constants.reducer$4,
108
110
  isInBuilder: constants.reducer$5,
109
- isPreview: constants.reducer$6
111
+ isPreview: constants.reducer$6,
112
+ builderEditMode: richText.reducer
110
113
  });
111
114
  function getBoxModelsStateSlice(state) {
112
115
  return state.boxModels;
@@ -230,22 +233,30 @@ function startHandlingPointerMoveEvent() {
230
233
  };
231
234
  }
232
235
  function startHandlingFocusEvents() {
233
- window.addEventListener("focusin", handleFocusIn);
234
- window.addEventListener("focusout", handleFocusOut);
235
- return () => {
236
- window.removeEventListener("focusin", handleFocusIn);
237
- window.removeEventListener("focusout", handleFocusOut);
238
- };
239
- function handleFocusIn(event) {
240
- if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {
241
- window.parent.focus();
236
+ return (_dispatch, getState) => {
237
+ window.addEventListener("focusin", handleFocusIn);
238
+ window.addEventListener("focusout", handleFocusOut);
239
+ return () => {
240
+ window.removeEventListener("focusin", handleFocusIn);
241
+ window.removeEventListener("focusout", handleFocusOut);
242
+ };
243
+ function handleFocusIn(event) {
244
+ if (constants.getBuilderEditMode(getState()) === richText.BuilderEditMode.INTERACT) {
245
+ return;
246
+ }
247
+ if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {
248
+ window.parent.focus();
249
+ }
242
250
  }
243
- }
244
- function handleFocusOut(event) {
245
- if (!(event.relatedTarget instanceof window.HTMLElement) || !event.relatedTarget.isContentEditable) {
246
- window.parent.focus();
251
+ function handleFocusOut(event) {
252
+ if (constants.getBuilderEditMode(getState()) === richText.BuilderEditMode.INTERACT) {
253
+ return;
254
+ }
255
+ if (!(event.relatedTarget instanceof window.HTMLElement) || !event.relatedTarget.isContentEditable) {
256
+ window.parent.focus();
257
+ }
247
258
  }
248
- }
259
+ };
249
260
  }
250
261
  function startMeasuringDocumentElement() {
251
262
  return (dispatch) => {
@@ -264,13 +275,33 @@ function startMeasuringDocumentElement() {
264
275
  }
265
276
  };
266
277
  }
278
+ function startHandlingKeyDownEvent() {
279
+ return (dispatch, getState) => {
280
+ window.document.body.addEventListener("keydown", handle);
281
+ return () => {
282
+ window.document.body.removeEventListener("keydown", handle);
283
+ };
284
+ function handle(event) {
285
+ if (event.defaultPrevented)
286
+ return;
287
+ if (constants.getBuilderEditMode(getState()) !== richText.BuilderEditMode.INTERACT) {
288
+ return;
289
+ }
290
+ if (isHotkey__default["default"]("escape")(event)) {
291
+ window.parent.focus();
292
+ dispatch(actions.setBuilderEditMode(richText.BuilderEditMode.BUILD));
293
+ }
294
+ }
295
+ };
296
+ }
267
297
  function initialize() {
268
298
  return (dispatch) => {
269
299
  const stopMeasuringElements = dispatch(startMeasuringElements());
270
300
  const stopMeasuringDocumentElement = dispatch(startMeasuringDocumentElement());
271
- const stopHandlingFocusEvent = startHandlingFocusEvents();
301
+ const stopHandlingFocusEvent = dispatch(startHandlingFocusEvents());
272
302
  const unlockDocumentScroll = dispatch(lockDocumentScroll());
273
303
  const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent());
304
+ const stopHandlingKeyDownEvent = dispatch(startHandlingKeyDownEvent());
274
305
  dispatch(actions.setIsInBuilder(true));
275
306
  return () => {
276
307
  stopMeasuringElements();
@@ -278,6 +309,7 @@ function initialize() {
278
309
  stopHandlingFocusEvent();
279
310
  unlockDocumentScroll();
280
311
  stopHandlingPointerMoveEvent();
312
+ stopHandlingKeyDownEvent();
281
313
  dispatch(actions.setIsInBuilder(false));
282
314
  };
283
315
  };
@@ -319,6 +351,7 @@ function messageChannelMiddleware() {
319
351
  }
320
352
  });
321
353
  return (action) => {
354
+ var _a;
322
355
  switch (action.type) {
323
356
  case actions.ActionTypes.CHANGE_ELEMENT_BOX_MODELS:
324
357
  case actions.ActionTypes.MOUNT_COMPONENT:
@@ -344,6 +377,10 @@ function messageChannelMiddleware() {
344
377
  case actions.ActionTypes.SCROLL_DOCUMENT_ELEMENT:
345
378
  window.document.documentElement.scrollTop += action.payload.scrollTopDelta;
346
379
  break;
380
+ case actions.ActionTypes.SET_BUILDER_EDIT_MODE:
381
+ messageChannel.port1.postMessage(action);
382
+ (_a = window.getSelection()) == null ? void 0 : _a.removeAllRanges();
383
+ break;
347
384
  case actions.ActionTypes.INIT:
348
385
  cleanUp = dispatch(initialize());
349
386
  break;