@makeswift/runtime 0.9.5 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LiveProvider.es.js +2 -2
- package/dist/PreviewProvider.es.js +2 -2
- package/dist/ReadOnlyText.cjs.js +2 -1
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +4 -3
- package/dist/ReadOnlyText.es.js.map +1 -1
- package/dist/ReadOnlyTextV2.cjs.js +2 -1
- package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
- package/dist/ReadOnlyTextV2.es.js +4 -3
- package/dist/ReadOnlyTextV2.es.js.map +1 -1
- package/dist/api.cjs.js +20 -1
- package/dist/api.cjs.js.map +1 -1
- package/dist/api.es.js +20 -1
- package/dist/api.es.js.map +1 -1
- package/dist/control-serialization.es.js +1 -1
- package/dist/controls.cjs.js +1 -0
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +1 -1
- package/dist/index.cjs.js +58 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs10.js +2 -1
- package/dist/index.cjs10.js.map +1 -1
- package/dist/index.cjs5.js +29 -10
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.es.js +58 -33
- package/dist/index.es.js.map +1 -1
- package/dist/index.es10.js +4 -3
- package/dist/index.es10.js.map +1 -1
- package/dist/index.es2.js +1 -1
- package/dist/index.es5.js +31 -12
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es6.js +1 -1
- package/dist/index.es9.js +2 -2
- package/dist/next.es.js +1 -1
- package/dist/react-page.cjs.js +16 -9
- package/dist/react-page.cjs.js.map +1 -1
- package/dist/react-page.es.js +16 -10
- package/dist/react-page.es.js.map +1 -1
- package/dist/slate.cjs.js +19 -61
- package/dist/slate.cjs.js.map +1 -1
- package/dist/slate.es.js +25 -65
- package/dist/slate.es.js.map +1 -1
- package/dist/state/breakpoints.cjs.js +13 -0
- package/dist/state/breakpoints.cjs.js.map +1 -1
- package/dist/state/breakpoints.es.js +13 -1
- package/dist/state/breakpoints.es.js.map +1 -1
- package/dist/types/src/api/graphql/documents/fragments.d.ts +1 -1
- package/dist/types/src/api/graphql/documents/fragments.d.ts.map +1 -1
- package/dist/types/src/api/graphql/documents/queries.d.ts.map +1 -1
- package/dist/types/src/api/graphql/generated/fragment-document-nodes.d.ts.map +1 -1
- package/dist/types/src/api/graphql/generated/types.d.ts +12 -0
- package/dist/types/src/api/graphql/generated/types.d.ts.map +1 -1
- package/dist/types/src/api/react.d.ts +3 -1
- package/dist/types/src/api/react.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
- package/dist/types/src/controls/icon-radio-group.d.ts +1 -1
- package/dist/types/src/controls/icon-radio-group.d.ts.map +1 -1
- package/dist/types/src/controls/link.d.ts +1 -1
- package/dist/types/src/controls/link.d.ts.map +1 -1
- package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts +2 -0
- package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/src/controls/select.d.ts +1 -1
- package/dist/types/src/controls/select.d.ts.map +1 -1
- package/dist/types/src/controls/typography.d.ts +1 -1
- package/dist/types/src/controls/typography.d.ts.map +1 -1
- package/dist/types/src/next/api-handler/index.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +2 -1
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/introspection.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +2 -2
- package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/style-v2.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/typography.d.ts +2 -2
- package/dist/types/src/runtimes/react/controls/typography.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
- package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/InlinePlugin/getValue.d.ts +1 -1
- package/dist/types/src/slate/InlinePlugin/getValue.d.ts.map +1 -1
- package/dist/types/src/slate/LinkPlugin/getValue.d.ts.map +1 -1
- package/dist/types/src/slate/TextAlignPlugin/getValue.d.ts +4 -0
- package/dist/types/src/slate/TextAlignPlugin/getValue.d.ts.map +1 -0
- package/dist/types/src/slate/TextAlignPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/getValue.d.ts +4 -0
- package/dist/types/src/slate/TypographyPlugin/getValue.d.ts.map +1 -0
- package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/index.d.ts +0 -1
- package/dist/types/src/slate/index.d.ts.map +1 -1
- package/dist/types/src/slate/utils/responsive.d.ts +3 -5
- package/dist/types/src/slate/utils/responsive.d.ts.map +1 -1
- package/dist/types/src/state/makeswift-api-client.d.ts +1 -1
- package/dist/types/src/state/makeswift-api-client.d.ts.map +1 -1
- package/dist/types/src/state/modules/breakpoints.d.ts +2 -0
- package/dist/types/src/state/modules/breakpoints.d.ts.map +1 -1
- package/dist/types/types/locale.d.ts +1 -1
- package/dist/types.cjs2.js.map +1 -1
- package/dist/types.es2.js +1 -1
- package/dist/types.es2.js.map +1 -1
- package/dist/typography.cjs.js.map +1 -1
- package/dist/typography.es.js.map +1 -1
- package/package.json +1 -1
- package/dist/types/src/slate/ColorPlugin/index.d.ts +0 -10
- package/dist/types/src/slate/ColorPlugin/index.d.ts.map +0 -1
package/dist/index.es10.js
CHANGED
|
@@ -34,8 +34,8 @@ import { Range, createEditor } from "slate";
|
|
|
34
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
|
-
import { U as useStyle,
|
|
38
|
-
import {
|
|
37
|
+
import { U as useStyle, bg as BlockType, be as InlineType, b6 as richTextDTOtoDAO, b5 as richTextDTOtoSelection, bp as BuilderEditMode } from "./react-page.es.js";
|
|
38
|
+
import { V as useEnhancedTypography, W as useTypographyClassName, n as useResponsiveStyle, u as useIsInBuilder, K as deepEqual, T as useBuilderEditMode, U as pollBoxModel } from "./index.es.js";
|
|
39
39
|
import { jsx } from "react/jsx-runtime";
|
|
40
40
|
import "./state/breakpoints.es.js";
|
|
41
41
|
import "./actions.es.js";
|
|
@@ -195,6 +195,7 @@ function InlineElement({
|
|
|
195
195
|
attributes,
|
|
196
196
|
children
|
|
197
197
|
}) {
|
|
198
|
+
var _a;
|
|
198
199
|
switch (element.type) {
|
|
199
200
|
case InlineType.Code:
|
|
200
201
|
return /* @__PURE__ */ jsx("code", __spreadProps(__spreadValues({}, attributes), {
|
|
@@ -210,7 +211,7 @@ function InlineElement({
|
|
|
210
211
|
}));
|
|
211
212
|
case InlineType.Link:
|
|
212
213
|
return /* @__PURE__ */ jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
|
|
213
|
-
link: element.link,
|
|
214
|
+
link: (_a = element.link) != null ? _a : void 0,
|
|
214
215
|
children
|
|
215
216
|
}));
|
|
216
217
|
}
|
package/dist/index.es10.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es10.js","sources":["../src/components/builtin/Text/components/Leaf/leaf.tsx","../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 { RenderLeafProps } from 'slate-react'\nimport useEnhancedTypography, {\n useTypographyClassName,\n} from '../../../../../runtimes/react/controls/typography'\n\nexport function Leaf({ leaf, ...props }: RenderLeafProps) {\n // for each breakpoint fetch related resources and merge its value with its override\n const enhancedTypography = useEnhancedTypography(leaf.typography)\n\n // for each breakpoint shallow merge back up through the breakpoints and create a className\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span {...props.attributes} className={typographyClassName}>\n {props.children}\n </span>\n )\n}\n","import { cx } from '@emotion/css'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { useResponsiveStyle } from '../../../../utils/responsive-style'\nimport { Block, BlockType } from '../../../../../slate'\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Block\n}\n\nexport function BlockElement({ element, attributes, children }: InlineRenderElementProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([element.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n const quoteStyles = 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 switch (element.type) {\n case BlockType.Text:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\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 {...attributes} className={cx(...blockStyles, quoteStyles)}>\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 default:\n return null\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { Link } from '../../../../shared/Link'\nimport { Inline, InlineType } from '../../../../../slate'\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 { BlockElement } from './block'\nimport { InlineElement } from './inline'\nimport { InlineType, BlockType } from '../../../../../slate'\n\nexport function Element({ element, ...props }: RenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n case InlineType.SuperScript:\n case InlineType.SubScript:\n case InlineType.Link:\n return <InlineElement element={element} {...props} />\n case BlockType.Paragraph:\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement element={element} {...props} />\n default:\n return <span {...props.attributes}>{props.children}</span>\n }\n}\n","import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { richTextDTOtoDAO, richTextDTOtoSelection } from '../../../../controls'\nimport { RichTextValue } from '../../../../prop-controllers'\nimport deepEqual from '../../../../utils/deepEqual'\nimport { useIsInBuilder } from '../../../../runtimes/react'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextValue) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n","import { ReactEditor } from 'slate-react'\nimport { useIsomorphicLayoutEffect } from '../../../hooks/useIsomorphicLayoutEffect'\nimport { Editor, Range as SlateRange } from 'slate'\n\n/**\n * Clicking outside of the host blurs our `<Editable />`.\n * `<Editable />` only updates the DOM's selection to match slate when it is focused.\n * In the case of a panel being clicked this hook updates the DOM selection to match slate.\n */\nexport function useSyncDOMSelection(editor: Editor, isEnabled: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled || editor.selection == null || ReactEditor.isFocused(editor)) return\n try {\n const root = ReactEditor.findDocumentOrShadowRoot(editor) as Document\n const domSelection = root.getSelection()\n const newDomRange: Range | null = ReactEditor.toDOMRange(editor, editor.selection)\n\n if (newDomRange) {\n if (SlateRange.isBackward(editor.selection!)) {\n domSelection?.setBaseAndExtent(\n newDomRange.endContainer,\n newDomRange.endOffset,\n newDomRange.startContainer,\n newDomRange.startOffset,\n )\n } else {\n domSelection?.setBaseAndExtent(\n newDomRange.startContainer,\n newDomRange.startOffset,\n newDomRange.endContainer,\n newDomRange.endOffset,\n )\n }\n } else {\n domSelection?.removeAllRanges()\n }\n } catch (e) {\n console.error(e)\n }\n })\n}\n","import {\n FocusEvent,\n forwardRef,\n KeyboardEvent,\n Ref,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react'\n\nimport { createEditor } from 'slate'\nimport { Slate, Editable, withReact, ReactEditor } from 'slate-react'\n\nimport { ElementIDValue, RichTextValue } from '../../../../prop-controllers/descriptors'\nimport { cx } from '@emotion/css'\nimport { DescriptorsPropControllers } from '../../../../prop-controllers/instances'\nimport { Descriptors } from '../../../../runtimes/react/controls/rich-text'\nimport { getBox } from '../../../../box-model'\nimport { PropControllersHandle } from '../../../../state/modules/prop-controller-handles'\nimport { 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, withTypography, withBuilder } from '../../../../slate'\nimport { pollBoxModel } from '../../../../runtimes/react/poll-box-model'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { RichTextDAO, BlockType } from '../../../../slate'\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(withBuilder(withReact(createEditor())))))\n const [isPreservingDOMSElection, setIsPreservingDOMSelection] = useState(false)\n useSyncDOMSelection(editor, isPreservingDOMSElection)\n const delaySync = useSyncWithBuilder(editor, text)\n const editMode = useBuilderEditMode()\n\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n if (controller == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getDomNode() {\n return ReactEditor.toDOMNode(editor, editor)\n },\n getBoxModel() {\n return getBox(ReactEditor.toDOMNode(editor, editor))\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n const initialValue = useMemo(() => (text ? richTextDTOtoDAO(text) : defaultText), [text])\n\n useEffect(() => {\n controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n const handleFocus = useCallback(() => {\n controller?.focus()\n setIsPreservingDOMSelection(true)\n }, [controller])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return controller?.redo()\n if (isHotkey('mod+z', e)) return controller?.undo()\n if (isHotkey('escape')(e)) return controller?.blur()\n onKeyDown(e, editor)\n },\n [controller, editor],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // When clicking outside of the iframe (`relatedTarget` is null) we want to preserve the DOM selection.\n if (e.relatedTarget == null) return\n // Otherwise we want to deselect on blur and stop preserving selection.\n setIsPreservingDOMSelection(false)\n ReactEditor.deselect(editor)\n }, [])\n\n return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n className={cx(width, margin)}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["leaf","props","enhancedTypography","useEnhancedTypography","typography","typographyClassName","useTypographyClassName","attributes","children","element","blockStyles","useStyle","margin","useResponsiveStyle","textAlign","quoteStyles","padding","fontSize","fontWeight","borderLeft","type","BlockType","Text","cx","Paragraph","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","className","restOfProps","textDecoration","InlineType","Code","SuperScript","SubScript","Link","link","COMMIT_DEBOUNCE_DELAY","editor","text","shouldCommit","setShouldCommit","useState","isInBuilder","useIsInBuilder","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","isEnabled","useIsomorphicLayoutEffect","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withBuilder","withReact","createEditor","isPreservingDOMSElection","setIsPreservingDOMSelection","useSyncDOMSelection","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","isHotkey","redo","undo","blur","onKeyDown","handleBlur","relatedTarget","deselect","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKqB,cAAA,IAAqC;AAArC,eAAEA;AAAAA;AAAAA,MAAF,IAAWC,kBAAX,IAAWA;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H0E,QAAAA,cAAcvD,YAAY,MAAM;AACpC0C,6CAAYc;AACZtB,gCAA4B,IAAD;AAAA,EAAA,GAC1B,CAACQ,UAAD,CAH4B;AAKzBe,QAAAA,gBAAgBzD,YACpB,CAACmB,MAAqB;AAChBuC,QAAAA,SAAS,eAAevC,CAAhB;AAAoB,aAAOuB,yCAAYiB;AAC/CD,QAAAA,SAAS,SAASvC,CAAV;AAAc,aAAOuB,yCAAYkB;AACzCF,QAAAA,SAAS,QAAD,EAAWvC,CAAnB;AAAuB,aAAOuB,yCAAYmB;AAC9CC,cAAU3C,GAAGtC,MAAJ;AAAA,EAAA,GAEX,CAAC6D,YAAY7D,MAAb,CAP+B;AAU3BkF,QAAAA,aAAa/D,YAAY,CAACmB,MAAkB;AAEhD,QAAIA,EAAE6C,iBAAiB;AAAM;AAE7B9B,gCAA4B,KAAD;AAC3B/B,gBAAY8D,SAASpF,MAArB;AAAA,EAL4B,GAM3B,CAN2B,CAAA;AAQ9B,6BACG,OAAD;AAAA,IAAO;AAAA,IAAgB,OAAOuE;AAAAA,IAAc,UAAUhB;AAAAA,IAAtD,8BACG,UAAD;AAAA,MACE;AAAA,MACA,YAAY8B;AAAAA,MACZ,eAAeC;AAAAA,MACf,SAASZ;AAAAA,MACT,WAAWE;AAAAA,MACX,QAAQM;AAAAA,MACR,WAAW1G,GAAGqE,OAAOhF,MAAR;AAAA,MACb,UAAU4F,aAAa8B,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CATd;AAAA,EAAA,CAFJ;AAeD,CAnFqC;AAqFtC,IAAA,iBAAe9C;;"}
|
|
1
|
+
{"version":3,"file":"index.es10.js","sources":["../src/components/builtin/Text/components/Leaf/leaf.tsx","../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 { RenderLeafProps } from 'slate-react'\nimport useEnhancedTypography, {\n useTypographyClassName,\n} from '../../../../../runtimes/react/controls/typography'\n\nexport function Leaf({ leaf, ...props }: RenderLeafProps) {\n // for each breakpoint fetch related resources and merge its value with its override\n const enhancedTypography = useEnhancedTypography(leaf.typography)\n\n // for each breakpoint shallow merge back up through the breakpoints and create a className\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span {...props.attributes} className={typographyClassName}>\n {props.children}\n </span>\n )\n}\n","import { cx } from '@emotion/css'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { useResponsiveStyle } from '../../../../utils/responsive-style'\nimport { Block, BlockType } from '../../../../../slate'\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Block\n}\n\nexport function BlockElement({ element, attributes, children }: InlineRenderElementProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([element.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n const quoteStyles = 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 switch (element.type) {\n case BlockType.Text:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\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 {...attributes} className={cx(...blockStyles, quoteStyles)}>\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 default:\n return null\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { Link } from '../../../../shared/Link'\nimport { Inline, InlineType } from '../../../../../slate'\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 ?? undefined}>\n {children}\n </StyledLink>\n )\n }\n}\n","import { RenderElementProps } from 'slate-react'\nimport { BlockElement } from './block'\nimport { InlineElement } from './inline'\nimport { InlineType, BlockType } from '../../../../../slate'\n\nexport function Element({ element, ...props }: RenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n case InlineType.SuperScript:\n case InlineType.SubScript:\n case InlineType.Link:\n return <InlineElement element={element} {...props} />\n case BlockType.Paragraph:\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement element={element} {...props} />\n default:\n return <span {...props.attributes}>{props.children}</span>\n }\n}\n","import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { richTextDTOtoDAO, richTextDTOtoSelection } from '../../../../controls'\nimport { RichTextValue } from '../../../../prop-controllers'\nimport deepEqual from '../../../../utils/deepEqual'\nimport { useIsInBuilder } from '../../../../runtimes/react'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextValue) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n","import { ReactEditor } from 'slate-react'\nimport { useIsomorphicLayoutEffect } from '../../../hooks/useIsomorphicLayoutEffect'\nimport { Editor, Range as SlateRange } from 'slate'\n\n/**\n * Clicking outside of the host blurs our `<Editable />`.\n * `<Editable />` only updates the DOM's selection to match slate when it is focused.\n * In the case of a panel being clicked this hook updates the DOM selection to match slate.\n */\nexport function useSyncDOMSelection(editor: Editor, isEnabled: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled || editor.selection == null || ReactEditor.isFocused(editor)) return\n try {\n const root = ReactEditor.findDocumentOrShadowRoot(editor) as Document\n const domSelection = root.getSelection()\n const newDomRange: Range | null = ReactEditor.toDOMRange(editor, editor.selection)\n\n if (newDomRange) {\n if (SlateRange.isBackward(editor.selection!)) {\n domSelection?.setBaseAndExtent(\n newDomRange.endContainer,\n newDomRange.endOffset,\n newDomRange.startContainer,\n newDomRange.startOffset,\n )\n } else {\n domSelection?.setBaseAndExtent(\n newDomRange.startContainer,\n newDomRange.startOffset,\n newDomRange.endContainer,\n newDomRange.endOffset,\n )\n }\n } else {\n domSelection?.removeAllRanges()\n }\n } catch (e) {\n console.error(e)\n }\n })\n}\n","import {\n FocusEvent,\n forwardRef,\n KeyboardEvent,\n Ref,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react'\n\nimport { createEditor } from 'slate'\nimport { Slate, Editable, withReact, ReactEditor } from 'slate-react'\n\nimport { ElementIDValue, RichTextValue } from '../../../../prop-controllers/descriptors'\nimport { cx } from '@emotion/css'\nimport { DescriptorsPropControllers } from '../../../../prop-controllers/instances'\nimport { Descriptors } from '../../../../runtimes/react/controls/rich-text'\nimport { getBox } from '../../../../box-model'\nimport { PropControllersHandle } from '../../../../state/modules/prop-controller-handles'\nimport { 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, withTypography, withBuilder } from '../../../../slate'\nimport { pollBoxModel } from '../../../../runtimes/react/poll-box-model'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { RichTextDAO, BlockType } from '../../../../slate'\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(withBuilder(withReact(createEditor())))))\n const [isPreservingDOMSElection, setIsPreservingDOMSelection] = useState(false)\n useSyncDOMSelection(editor, isPreservingDOMSElection)\n const delaySync = useSyncWithBuilder(editor, text)\n const editMode = useBuilderEditMode()\n\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n if (controller == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getDomNode() {\n return ReactEditor.toDOMNode(editor, editor)\n },\n getBoxModel() {\n return getBox(ReactEditor.toDOMNode(editor, editor))\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n const initialValue = useMemo(() => (text ? richTextDTOtoDAO(text) : defaultText), [text])\n\n useEffect(() => {\n controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n const handleFocus = useCallback(() => {\n controller?.focus()\n setIsPreservingDOMSelection(true)\n }, [controller])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return controller?.redo()\n if (isHotkey('mod+z', e)) return controller?.undo()\n if (isHotkey('escape')(e)) return controller?.blur()\n onKeyDown(e, editor)\n },\n [controller, editor],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // When clicking outside of the iframe (`relatedTarget` is null) we want to preserve the DOM selection.\n if (e.relatedTarget == null) return\n // Otherwise we want to deselect on blur and stop preserving selection.\n setIsPreservingDOMSelection(false)\n ReactEditor.deselect(editor)\n }, [])\n\n return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n className={cx(width, margin)}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["leaf","props","enhancedTypography","useEnhancedTypography","typography","typographyClassName","useTypographyClassName","attributes","children","element","blockStyles","useStyle","margin","useResponsiveStyle","textAlign","quoteStyles","padding","fontSize","fontWeight","borderLeft","type","BlockType","Text","cx","Paragraph","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","className","restOfProps","textDecoration","InlineType","Code","SuperScript","SubScript","Link","link","undefined","COMMIT_DEBOUNCE_DELAY","editor","text","shouldCommit","setShouldCommit","useState","isInBuilder","useIsInBuilder","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","isEnabled","useIsomorphicLayoutEffect","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withBuilder","withReact","createEditor","isPreservingDOMSElection","setIsPreservingDOMSelection","useSyncDOMSelection","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","isHotkey","redo","undo","blur","onKeyDown","handleBlur","relatedTarget","deselect","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":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ude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
import { useMemo, useState, useEffect, useCallback, useRef, forwardRef, createElement, Children } from "react";
|
|
33
|
-
import { Y as isNonNullable,
|
|
33
|
+
import { Y as isNonNullable, aw as getBackgroundsFileIds, ax as getBackgroundsSwatchIds, U as useStyle } from "./react-page.es.js";
|
|
34
34
|
import "use-sync-external-store/shim";
|
|
35
35
|
import { G as useFiles, H as useSwatches, v as useResponsiveGridItem, c as DEFAULT_BOX_ANIMATE_TYPE, f as DEFAULT_ITEM_ANIMATE_TYPE, e as DEFAULT_BOX_ANIMATE_DURATION, d as DEFAULT_BOX_ANIMATE_DELAY, i as DEFAULT_ITEM_STAGGER_DURATION, n as useResponsiveStyle, q as colorToString } from "./index.es.js";
|
|
36
36
|
import "./actions.es.js";
|
package/dist/index.es5.js
CHANGED
|
@@ -19,11 +19,11 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
import { Editor, Transforms, Text, Range } from "slate";
|
|
21
21
|
import { findBreakpointOverride } from "./state/breakpoints.es.js";
|
|
22
|
-
import {
|
|
22
|
+
import { ba as createRichTextV2Plugin } from "./react-page.es.js";
|
|
23
23
|
import "./actions.es.js";
|
|
24
24
|
import { i as unstable_Typography } from "./typography.es.js";
|
|
25
25
|
import { g as getSelection } from "./types.es2.js";
|
|
26
|
-
import { K as deepEqual } from "./index.es.js";
|
|
26
|
+
import { L as shallowEqual, K as deepEqual } from "./index.es.js";
|
|
27
27
|
function clearActiveTypographyStyle(editor, options) {
|
|
28
28
|
Editor.withoutNormalizing(editor, () => {
|
|
29
29
|
var _a;
|
|
@@ -216,14 +216,6 @@ function setResponsiveValue(editor, key, value, options) {
|
|
|
216
216
|
atRef.unref();
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
|
-
function getResponsiveValue(editor, key, options) {
|
|
220
|
-
const matchingValues = Array.from(Editor.nodes(editor, {
|
|
221
|
-
at: getSelection(editor),
|
|
222
|
-
match: options == null ? void 0 : options.match
|
|
223
|
-
})).filter(([node, path]) => options.match(node, path)).map(([node]) => node[key]);
|
|
224
|
-
const value = matchingValues.length === 0 ? void 0 : matchingValues.reduce((a, b) => deepEqual(a, b) ? b : void 0);
|
|
225
|
-
return value;
|
|
226
|
-
}
|
|
227
219
|
function normalizeResponsiveValue(editor, key, options) {
|
|
228
220
|
return (entry) => {
|
|
229
221
|
const [node, path] = entry;
|
|
@@ -242,6 +234,33 @@ function normalizeResponsiveValue(editor, key, options) {
|
|
|
242
234
|
return false;
|
|
243
235
|
};
|
|
244
236
|
}
|
|
237
|
+
function responsiveShallowEqual(a = [], b = []) {
|
|
238
|
+
const aObject = a.reduce((acc, curr) => __spreadProps(__spreadValues({}, acc), {
|
|
239
|
+
[curr.deviceId]: curr.value
|
|
240
|
+
}), {});
|
|
241
|
+
const bObject = b.reduce((acc, curr) => __spreadProps(__spreadValues({}, acc), {
|
|
242
|
+
[curr.deviceId]: curr.value
|
|
243
|
+
}), {});
|
|
244
|
+
const definedDevices = /* @__PURE__ */ new Set([...a.map((a2) => a2.deviceId), ...b.map((b2) => b2.deviceId)]);
|
|
245
|
+
return Array.from(definedDevices).map((deviceId) => {
|
|
246
|
+
const aVal = aObject[deviceId];
|
|
247
|
+
const bVal = bObject[deviceId];
|
|
248
|
+
if (aVal === void 0 && bVal === void 0)
|
|
249
|
+
return { deviceId, value: void 0 };
|
|
250
|
+
return shallowEqual(aVal, bVal) ? { deviceId, value: aVal } : { deviceId, value: null };
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function getValue(editor) {
|
|
254
|
+
var _a;
|
|
255
|
+
const matchingValues = Array.from(Editor.nodes(editor, {
|
|
256
|
+
at: getSelection(editor),
|
|
257
|
+
match: Text.isText
|
|
258
|
+
})).map(([node]) => node["typography"]);
|
|
259
|
+
if (matchingValues.length === 0) {
|
|
260
|
+
return void 0;
|
|
261
|
+
}
|
|
262
|
+
return (_a = matchingValues.reduce((a, b) => deepEqual(a, b) ? b : void 0, matchingValues.at(0))) != null ? _a : null;
|
|
263
|
+
}
|
|
245
264
|
const TypographyActions = {
|
|
246
265
|
setActiveTypographyId,
|
|
247
266
|
setActiveTypographyStyle,
|
|
@@ -278,7 +297,7 @@ function TypographyPlugin() {
|
|
|
278
297
|
split: true
|
|
279
298
|
});
|
|
280
299
|
},
|
|
281
|
-
getValue: (editor) =>
|
|
300
|
+
getValue: (editor) => getValue(editor),
|
|
282
301
|
getLeafValue: (text) => {
|
|
283
302
|
return Text.isText(text) ? text.typography : void 0;
|
|
284
303
|
}
|
|
@@ -292,5 +311,5 @@ function TypographyPlugin() {
|
|
|
292
311
|
}
|
|
293
312
|
});
|
|
294
313
|
}
|
|
295
|
-
export { TypographyActions as T, TYPOGRAPHY_KEY as a, TypographyPlugin as b,
|
|
314
|
+
export { TypographyActions as T, TYPOGRAPHY_KEY as a, TypographyPlugin as b, normalizeResponsiveValue as n, responsiveShallowEqual as r, setResponsiveValue as s, withTypography as w };
|
|
296
315
|
//# sourceMappingURL=index.es5.js.map
|
package/dist/index.es5.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es5.js","sources":["../src/slate/TypographyPlugin/clearActiveTypographyStyle.ts","../src/slate/TypographyPlugin/clearDeviceActiveTypography.ts","../src/slate/TypographyPlugin/detachActiveTypography.ts","../src/slate/TypographyPlugin/setActiveTypographyId.ts","../src/slate/TypographyPlugin/setActiveTypographyStyle.ts","../src/slate/utils/responsive.ts","../src/slate/TypographyPlugin/index.ts"],"sourcesContent":["import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../types'\n\ntype ClearActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function clearActiveTypographyStyle(\n editor: Editor,\n options?: ClearActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const typography: RichTextTypography = {\n ...node.typography,\n style: [],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../types'\n\ntype ClearDeviceActiveTypographyOptions = {\n at?: Range\n}\n\nexport function clearDeviceActiveTypography(\n editor: Editor,\n currentDeviceId: string,\n options?: ClearDeviceActiveTypographyOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const typography: RichTextTypography = {\n ...node.typography,\n style:\n node?.typography?.style.filter(({ deviceId }) => deviceId !== currentDeviceId) ?? [],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../types'\n\ntype SetActiveTypographyIdOptions = {\n at?: Range\n}\n\nexport function detachActiveTypography(\n editor: Editor,\n value: RichTextTypography['style'],\n options?: SetActiveTypographyIdOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n Transforms.setNodes(\n editor,\n {\n typography: {\n style: value,\n },\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\n\ntype SetActiveTypographyIdOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyId(\n editor: Editor,\n id?: string,\n options?: SetActiveTypographyIdOptions,\n) {\n const at = options?.at ?? editor.selection\n if (!at) return\n Transforms.setNodes(\n editor,\n {\n typography: {\n id,\n style: [],\n },\n },\n {\n at,\n match: node => Text.isText(node),\n split: Range.isExpanded(at),\n },\n )\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { Breakpoints, findBreakpointOverride, BreakpointId } from '../../state/modules/breakpoints'\nimport { RichTextTypography } from '../types'\n\ntype SetActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyStyle(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: string,\n prop: string,\n value?: unknown,\n options?: SetActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const deviceOverrides = node?.typography?.style ?? []\n const deviceStyle = findBreakpointOverride(\n breakpoints,\n deviceOverrides,\n deviceId as BreakpointId,\n v => v,\n ) || {\n value: {},\n }\n const nextDeviceStyle = {\n deviceId,\n value: { ...deviceStyle.value, [prop]: value },\n }\n\n const nextTypography: RichTextTypography = {\n ...node.typography,\n style: [...deviceOverrides.filter(v => v.deviceId !== deviceId), nextDeviceStyle],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography: nextTypography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, NodeMatch, Descendant, NodeEntry } from 'slate'\nimport { getSelection } from '../selectors'\nimport deepEqual from '../../utils/deepEqual'\n\ntype SetResponsiveValueOptions<T extends Descendant> = {\n match: NodeMatch<T>\n split: boolean\n}\n\nexport function setResponsiveValue<T extends Descendant, K extends keyof T>(\n editor: Editor,\n key: K,\n value: T[K] | undefined,\n options: SetResponsiveValueOptions<T>,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = getSelection(editor)\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes<Descendant>(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: options.match,\n split: options.split,\n },\n )\n }\n\n if (atRef.current) {\n const nodesToUpdate = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: (node, path) => options.match(node, path) && node.slice === true,\n }),\n )\n\n for (const [, path] of nodesToUpdate) {\n Transforms.setNodes(\n editor,\n {\n [key]: value,\n },\n { at: path },\n )\n }\n }\n\n atRef.unref()\n })\n}\n\ntype GetResponsiveValueOptions<T extends Descendant> = {\n match: NodeMatch<T>\n}\n\nexport function getResponsiveValue<T extends Descendant, K extends keyof T>(\n editor: Editor,\n key: K,\n options: GetResponsiveValueOptions<T>,\n): T[K] | undefined {\n const matchingValues = Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: options?.match,\n }),\n )\n .filter(([node, path]) => options.match(node, path))\n .map(([node]) => node[key]) as (T[K] | undefined)[]\n\n const value =\n matchingValues.length === 0\n ? undefined\n : matchingValues.reduce((a, b) => (deepEqual(a, b) ? b : undefined))\n\n return value\n}\n\ntype NormalizeResponsiveValueOptions<T extends Descendant> = {\n match: NodeMatch<T>\n}\n\nexport function normalizeResponsiveValue<T extends Descendant, K extends keyof T & string>(\n editor: Editor,\n key: K,\n options: NormalizeResponsiveValueOptions<T>,\n) {\n return (entry: NodeEntry) => {\n const [node, path] = entry\n\n if (!options.match(node, path)) {\n return false\n }\n\n const responsiveValue = node?.[key]\n\n if (Array.isArray(responsiveValue) && responsiveValue.length === 0) {\n Transforms.unsetNodes(editor, key, { at: path })\n return true\n }\n\n if (node?.slice != null) {\n Transforms.unsetNodes(editor, 'slice', { at: path })\n return true\n }\n\n return false\n }\n}\n","import { Editor, Text, Transforms } from 'slate'\nimport { clearActiveTypographyStyle } from './clearActiveTypographyStyle'\nimport { clearDeviceActiveTypography } from './clearDeviceActiveTypography'\nimport { detachActiveTypography } from './detachActiveTypography'\nimport { setActiveTypographyId } from './setActiveTypographyId'\nimport { setActiveTypographyStyle } from './setActiveTypographyStyle'\nimport { createRichTextV2Plugin, unstable_Typography } from '../../controls'\nimport { getResponsiveValue, setResponsiveValue } from '../utils/responsive'\n\nexport const TypographyActions = {\n setActiveTypographyId,\n setActiveTypographyStyle,\n clearActiveTypographyStyle,\n clearDeviceActiveTypography,\n detachActiveTypography,\n}\n\nexport const TYPOGRAPHY_KEY = 'typography'\n\nexport function withTypography(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n if (\n Text.isText(normalizationNode) &&\n normalizationNode?.typography?.id == null &&\n normalizationNode?.typography?.style.length === 0\n ) {\n Transforms.unsetNodes(editor, TYPOGRAPHY_KEY, { at: normalizationPath })\n return\n }\n\n if (Text.isText(normalizationNode) && normalizationNode?.slice != null) {\n Transforms.unsetNodes(editor, 'slice', { at: normalizationPath })\n return\n }\n\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TypographyPlugin() {\n return createRichTextV2Plugin({\n withPlugin: withTypography,\n control: {\n definition: unstable_Typography(),\n onChange: (editor, value) => {\n setResponsiveValue(editor, TYPOGRAPHY_KEY, value, {\n match: Text.isText,\n split: true,\n })\n },\n getValue: editor => getResponsiveValue(editor, TYPOGRAPHY_KEY, { match: Text.isText }),\n getLeafValue: (text: Text) => {\n return Text.isText(text) ? text.typography : undefined\n },\n },\n renderLeaf: (renderLeaf, className) => props => {\n return renderLeaf({\n ...props,\n leaf: {\n ...props.leaf,\n className: `${props.leaf.className} ${className}`,\n },\n })\n },\n })\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAOO,oCACL,QACA,SACA;AACO,SAAA,mBAAmB,QAAQ,MAAM;;AAChC,UAAA,KAAK,yCAAS,OAAT,YAAe,OAAO;AACjC,QAAI,CAAC;AAAI;AACT,UAAM,QAAQ,OAAO,SAAS,QAAQ,EAAE;AAExC,QAAI,MAAM,SAAS;AACjB,iBAAW,SACT,QACA;AAAA,QACE,OAAO;AAAA,MAAA,GAET;AAAA,QACE,IAAI,MAAM;AAAA,QACV,OAAO,CAAA,SAAQ,KAAK,OAAO,IAAI;AAAA,QAC/B,OAAO,MAAM,WAAW,MAAM,OAAO;AAAA,MAAA,CAEzC;AAAA,IACF;AAEA,QAAI,MAAM,SAAS;AACjB,YAAM,YAAY,MAAM,KACtB,OAAO,MAAM,QAAQ;AAAA,QACnB,IAAI,MAAM;AAAA,QACV,OAAO,CAAQ,SAAA,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU;AAAA,MACpD,CAAA,CACH;AAEW,iBAAA,CAAC,MAAM,SAAS,WAAW;AAChC,YAAA,KAAK,OAAO,IAAI,GAAG;AACrB,gBAAM,aAAiC,iCAClC,KAAK,aAD6B;AAAA,YAErC,OAAO,CAA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AEhB,MAAM,iCACD,MAAM,OADL;AAAA,UAEJ,WAAW,GAAG,MAAM,KAAK,aAAa;AAAA,QACxC;AAAA,MAAA,EACD;AAAA,IACH;AAAA,EAAA,CACD;AACH;;"}
|
|
1
|
+
{"version":3,"file":"index.es5.js","sources":["../src/slate/TypographyPlugin/clearActiveTypographyStyle.ts","../src/slate/TypographyPlugin/clearDeviceActiveTypography.ts","../src/slate/TypographyPlugin/detachActiveTypography.ts","../src/slate/TypographyPlugin/setActiveTypographyId.ts","../src/slate/TypographyPlugin/setActiveTypographyStyle.ts","../src/slate/utils/responsive.ts","../src/slate/TypographyPlugin/getValue.tsx","../src/slate/TypographyPlugin/index.ts"],"sourcesContent":["import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../types'\n\ntype ClearActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function clearActiveTypographyStyle(\n editor: Editor,\n options?: ClearActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const typography: RichTextTypography = {\n ...node.typography,\n style: [],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../types'\n\ntype ClearDeviceActiveTypographyOptions = {\n at?: Range\n}\n\nexport function clearDeviceActiveTypography(\n editor: Editor,\n currentDeviceId: string,\n options?: ClearDeviceActiveTypographyOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const typography: RichTextTypography = {\n ...node.typography,\n style:\n node?.typography?.style.filter(({ deviceId }) => deviceId !== currentDeviceId) ?? [],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '../types'\n\ntype SetActiveTypographyIdOptions = {\n at?: Range\n}\n\nexport function detachActiveTypography(\n editor: Editor,\n value: RichTextTypography['style'],\n options?: SetActiveTypographyIdOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n Transforms.setNodes(\n editor,\n {\n typography: {\n style: value,\n },\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\n\ntype SetActiveTypographyIdOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyId(\n editor: Editor,\n id?: string,\n options?: SetActiveTypographyIdOptions,\n) {\n const at = options?.at ?? editor.selection\n if (!at) return\n Transforms.setNodes(\n editor,\n {\n typography: {\n id,\n style: [],\n },\n },\n {\n at,\n match: node => Text.isText(node),\n split: Range.isExpanded(at),\n },\n )\n}\n","import { Editor, Transforms, Text, Range } from 'slate'\nimport { Breakpoints, findBreakpointOverride, BreakpointId } from '../../state/modules/breakpoints'\nimport { RichTextTypography } from '../types'\n\ntype SetActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyStyle(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: string,\n prop: string,\n value?: unknown,\n options?: SetActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const deviceOverrides = node?.typography?.style ?? []\n const deviceStyle = findBreakpointOverride(\n breakpoints,\n deviceOverrides,\n deviceId as BreakpointId,\n v => v,\n ) || {\n value: {},\n }\n const nextDeviceStyle = {\n deviceId,\n value: { ...deviceStyle.value, [prop]: value },\n }\n\n const nextTypography: RichTextTypography = {\n ...node.typography,\n style: [...deviceOverrides.filter(v => v.deviceId !== deviceId), nextDeviceStyle],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography: nextTypography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n","import { Editor, Transforms, NodeMatch, Descendant, NodeEntry } from 'slate'\nimport { getSelection } from '../selectors'\nimport { ResponsiveValue } from '../../prop-controllers'\nimport shallowEqual from '../../utils/shallowEqual'\nimport { BlockTextAlignment } from '../types'\n\ntype SetResponsiveValueOptions<T extends Descendant> = {\n match: NodeMatch<T>\n split: boolean\n}\n\nexport function setResponsiveValue<T extends Descendant, K extends keyof T>(\n editor: Editor,\n key: K,\n value: T[K] | undefined | null,\n options: SetResponsiveValueOptions<T>,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = getSelection(editor)\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes<Descendant>(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: options.match,\n split: options.split,\n },\n )\n }\n\n if (atRef.current) {\n const nodesToUpdate = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: (node, path) => options.match(node, path) && node.slice === true,\n }),\n )\n\n for (const [, path] of nodesToUpdate) {\n Transforms.setNodes(\n editor,\n {\n [key]: value,\n },\n { at: path },\n )\n }\n }\n\n atRef.unref()\n })\n}\n\ntype NormalizeResponsiveValueOptions<T extends Descendant> = {\n match: NodeMatch<T>\n}\n\nexport function normalizeResponsiveValue<T extends Descendant, K extends keyof T & string>(\n editor: Editor,\n key: K,\n options: NormalizeResponsiveValueOptions<T>,\n) {\n return (entry: NodeEntry) => {\n const [node, path] = entry\n\n if (!options.match(node, path)) {\n return false\n }\n\n const responsiveValue = node?.[key]\n\n if (Array.isArray(responsiveValue) && responsiveValue.length === 0) {\n Transforms.unsetNodes(editor, key, { at: path })\n return true\n }\n\n if (node?.slice != null) {\n Transforms.unsetNodes(editor, 'slice', { at: path })\n return true\n }\n\n return false\n }\n}\n\nexport function responsiveShallowEqual<T>(\n a: ResponsiveValue<T> = [],\n b: ResponsiveValue<T> = [],\n): ResponsiveValue<T> {\n const aObject: Record<string, BlockTextAlignment> = a.reduce(\n (acc, curr) => ({\n ...acc,\n [curr.deviceId]: curr.value,\n }),\n {},\n )\n const bObject: Record<string, BlockTextAlignment> = b.reduce(\n (acc, curr) => ({\n ...acc,\n [curr.deviceId]: curr.value,\n }),\n {},\n )\n\n const definedDevices = new Set([...a.map(a => a.deviceId), ...b.map(b => b.deviceId)])\n\n return Array.from(definedDevices).map(deviceId => {\n const aVal = aObject[deviceId]\n const bVal = bObject[deviceId]\n\n if (aVal === undefined && bVal === undefined) return { deviceId, value: undefined }\n\n return shallowEqual(aVal, bVal) ? { deviceId, value: aVal } : { deviceId, value: null }\n }) as ResponsiveValue<T>\n}\n","import { Editor, Text } from 'slate'\nimport { RichTextTypography } from '../types'\nimport { getSelection } from '../selectors'\nimport deepEqual from '../../utils/deepEqual'\n\nexport function getValue(editor: Editor) {\n const matchingValues = Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: Text.isText,\n }),\n ).map(([node]) => node['typography']) as (RichTextTypography | undefined)[]\n\n if (matchingValues.length === 0) {\n return undefined\n }\n\n return (\n matchingValues.reduce((a, b) => (deepEqual(a, b) ? b : undefined), matchingValues.at(0)) ?? null\n )\n}\n","import { Editor, Text, Transforms } from 'slate'\nimport { clearActiveTypographyStyle } from './clearActiveTypographyStyle'\nimport { clearDeviceActiveTypography } from './clearDeviceActiveTypography'\nimport { detachActiveTypography } from './detachActiveTypography'\nimport { setActiveTypographyId } from './setActiveTypographyId'\nimport { setActiveTypographyStyle } from './setActiveTypographyStyle'\nimport { createRichTextV2Plugin, unstable_Typography } from '../../controls'\nimport { setResponsiveValue } from '../utils/responsive'\nimport { getValue } from './getValue'\n\nexport const TypographyActions = {\n setActiveTypographyId,\n setActiveTypographyStyle,\n clearActiveTypographyStyle,\n clearDeviceActiveTypography,\n detachActiveTypography,\n}\n\nexport const TYPOGRAPHY_KEY = 'typography'\n\nexport function withTypography(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n if (\n Text.isText(normalizationNode) &&\n normalizationNode?.typography?.id == null &&\n normalizationNode?.typography?.style.length === 0\n ) {\n Transforms.unsetNodes(editor, TYPOGRAPHY_KEY, { at: normalizationPath })\n return\n }\n\n if (Text.isText(normalizationNode) && normalizationNode?.slice != null) {\n Transforms.unsetNodes(editor, 'slice', { at: normalizationPath })\n return\n }\n\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TypographyPlugin() {\n return createRichTextV2Plugin({\n withPlugin: withTypography,\n control: {\n definition: unstable_Typography(),\n onChange: (editor, value) => {\n setResponsiveValue(editor, TYPOGRAPHY_KEY, value, {\n match: Text.isText,\n split: true,\n })\n },\n getValue: editor => getValue(editor),\n getLeafValue: (text: Text) => {\n return Text.isText(text) ? text.typography : undefined\n },\n },\n renderLeaf: (renderLeaf, className) => props => {\n return renderLeaf({\n ...props,\n leaf: {\n ...props.leaf,\n className: `${props.leaf.className} ${className}`,\n },\n })\n },\n })\n}\n"],"names":["editor","matchingValues","Array","from","Editor","nodes","at","getSelection","match","Text","isText","map","node","length","undefined","reduce","a","b","deepEqual"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAOO,oCACL,QACA,SACA;AACO,SAAA,mBAAmB,QAAQ,MAAM;;AAChC,UAAA,KAAK,yCAAS,OAAT,YAAe,OAAO;AACjC,QAAI,CAAC;AAAI;AACT,UAAM,QAAQ,OAAO,SAAS,QAAQ,EAAE;AAExC,QAAI,MAAM,SAAS;AACjB,iBAAW,SACT,QACA;AAAA,QACE,OAAO;AAAA,MAAA,GAET;AAAA,QACE,IAAI,MAAM;AAAA,QACV,OAAO,CAAA,SAAQ,KAAK,OAAO,IAAI;AAAA,QAC/B,OAAO,MAAM,WAAW,MAAM,OAAO;AAAA,MAAA,CAEzC;AAAA,IACF;AAEA,QAAI,MAAM,SAAS;AACjB,YAAM,YAAY,MAAM,KACtB,OAAO,MAAM,QAAQ;AAAA,QACnB,IAAI,MAAM;AAAA,QACV,OAAO,CAAQ,SAAA,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU;AAAA,MACpD,CAAA,CACH;AAEW,iBAAA,CAAC,MAAM,SAAS,WAAW;AAChC,YAAA,KAAK,OAAO,IAAI,GAAG;AACrB,gBAAM,aAAiC,iCAClC,KAAK,aAD6B;AAAA,YAEr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,iBAAW,WAAW,QAAQ,gBAAgB,EAAE,IAAI,mBAAmB;AACvE;AAAA,IACF;AAEA,QAAI,KAAK,OAAO,iBAAiB,KAAK,wDAAmB,UAAS,MAAM;AACtE,iBAAW,WAAW,QAAQ,SAAS,EAAE,IAAI,mBAAmB;AAChE;AAAA,IACF;AAEA,kBAAc,KAAK;AAAA,EAAA;AAGd,SAAA;AACT;AAEmC,4BAAA;AACjC,SAAO,uBAAuB;AAAA,IAC5B,YAAY;AAAA,IACZ,SAAS;AAAA,MACP,YAAY,oBAAoB;AAAA,MAChC,UAAU,CAAC,QAAQ,UAAU;AACR,2BAAA,QAAQ,gBAAgB,OAAO;AAAA,UAChD,OAAO,KAAK;AAAA,UACZ,OAAO;AAAA,QAAA,CACR;AAAA,MACH;AAAA,MACA,UAAU,CAAU,WAAA,SAAS,MAAM;AAAA,MACnC,cAAc,CAAC,SAAe;AAC5B,eAAO,KAAK,OAAO,IAAI,IAAI,KAAK,aAAa;AAAA,MAC/C;AAAA,IACF;AAAA,IACA,YAAY,CAAC,YAAY,cAAc,CAAS,UAAA;AAC9C,aAAO,WAAW,iCACb,QADa;AAAA,QAEhB,MAAM,iCACD,MAAM,OADL;AAAA,UAEJ,WAAW,GAAG,MAAM,KAAK,aAAa;AAAA,QACxC;AAAA,MAAA,EACD;AAAA,IACH;AAAA,EAAA,CACD;AACH;;"}
|
package/dist/index.es6.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Path, Transforms } from "slate";
|
|
2
2
|
import isHotkey from "is-hotkey";
|
|
3
|
-
import {
|
|
3
|
+
import { bg as BlockType, ba as createRichTextV2Plugin } from "./react-page.es.js";
|
|
4
4
|
import { E as ElementUtils } from "./types.es2.js";
|
|
5
5
|
const BLOCK_ONE_PATH = [0];
|
|
6
6
|
const BLOCK_TWO_PATH = [1];
|
package/dist/index.es9.js
CHANGED
|
@@ -34,8 +34,8 @@ import { Range, createEditor } from "slate";
|
|
|
34
34
|
import isHotkey from "is-hotkey";
|
|
35
35
|
import { withHistory, HistoryEditor } from "slate-history";
|
|
36
36
|
import { ReactEditor, withReact, Slate, Editable } from "slate-react";
|
|
37
|
-
import { U as useStyle,
|
|
38
|
-
import {
|
|
37
|
+
import { U as useStyle, b9 as RichTextV2Mode, bg as BlockType, bp as BuilderEditMode } from "./react-page.es.js";
|
|
38
|
+
import { Q as ControlValue, T as useBuilderEditMode, U as pollBoxModel } from "./index.es.js";
|
|
39
39
|
import "./state/breakpoints.es.js";
|
|
40
40
|
import "./types.es2.js";
|
|
41
41
|
import { I as InlineModePlugin } from "./index.es6.js";
|
package/dist/next.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "react";
|
|
2
|
-
export {
|
|
2
|
+
export { a1 as Document, $ as Makeswift, a2 as MakeswiftApiHandler, _ as Page, a0 as PreviewModeScript, B as forwardNextDynamicRef, Z as getServerSideProps, X as getStaticPaths, Y as getStaticProps } from "./index.es.js";
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
import "use-sync-external-store/shim/with-selector";
|
|
5
5
|
import "next/dynamic";
|
package/dist/react-page.cjs.js
CHANGED
|
@@ -2090,6 +2090,7 @@ function richTextDTOtoDAO(data) {
|
|
|
2090
2090
|
return (_c = (_b = (_a2 = data.document) == null ? void 0 : _a2.nodes) == null ? void 0 : _b.flatMap(toNodeDAO)) != null ? _c : [];
|
|
2091
2091
|
}
|
|
2092
2092
|
function toInlineOrTextDTO(node) {
|
|
2093
|
+
var _a2;
|
|
2093
2094
|
if (isText(node)) {
|
|
2094
2095
|
return [
|
|
2095
2096
|
{
|
|
@@ -2114,7 +2115,7 @@ function toInlineOrTextDTO(node) {
|
|
|
2114
2115
|
object: ObjectType.Inline,
|
|
2115
2116
|
nodes: node.children.flatMap(toInlineOrTextDTO),
|
|
2116
2117
|
type: node.type,
|
|
2117
|
-
data: node.link
|
|
2118
|
+
data: (_a2 = node.link) != null ? _a2 : void 0
|
|
2118
2119
|
}
|
|
2119
2120
|
];
|
|
2120
2121
|
case InlineType.Code:
|
|
@@ -2367,6 +2368,9 @@ class RichTextV2Control extends PropController {
|
|
|
2367
2368
|
this.send({ type: RichTextV2ControlMessageType.CHANGE_BOX_MODEL, payload: { boxModel } });
|
|
2368
2369
|
}
|
|
2369
2370
|
}
|
|
2371
|
+
function isRichTextV1Data(value) {
|
|
2372
|
+
return value !== void 0 && typeof value === "object" && !Array.isArray(value);
|
|
2373
|
+
}
|
|
2370
2374
|
function isNonNullable(value) {
|
|
2371
2375
|
return value != null;
|
|
2372
2376
|
}
|
|
@@ -2451,7 +2455,7 @@ function getTypographyStyleSwatchIds(style) {
|
|
|
2451
2455
|
}).filter(isNonNullable)) != null ? _a2 : [];
|
|
2452
2456
|
}
|
|
2453
2457
|
function getSwatchIds(descriptor, prop) {
|
|
2454
|
-
var _a2;
|
|
2458
|
+
var _a2, _b;
|
|
2455
2459
|
if (prop == null)
|
|
2456
2460
|
return [];
|
|
2457
2461
|
switch (descriptor.type) {
|
|
@@ -2462,12 +2466,12 @@ function getSwatchIds(descriptor, prop) {
|
|
|
2462
2466
|
case Types.NavigationLinks: {
|
|
2463
2467
|
const value = prop;
|
|
2464
2468
|
return (_a2 = value == null ? void 0 : value.flatMap((item) => {
|
|
2465
|
-
var _a3,
|
|
2469
|
+
var _a3, _b2, _c, _d;
|
|
2466
2470
|
switch (item.type) {
|
|
2467
2471
|
case "button":
|
|
2468
2472
|
case "dropdown":
|
|
2469
2473
|
return [
|
|
2470
|
-
...(
|
|
2474
|
+
...(_b2 = (_a3 = item.payload.color) == null ? void 0 : _a3.map((override) => override.value).map((color) => color.swatchId)) != null ? _b2 : [],
|
|
2471
2475
|
...(_d = (_c = item.payload.textColor) == null ? void 0 : _c.map((override) => override.value).map((color) => color.swatchId)) != null ? _d : []
|
|
2472
2476
|
];
|
|
2473
2477
|
}
|
|
@@ -2479,20 +2483,20 @@ function getSwatchIds(descriptor, prop) {
|
|
|
2479
2483
|
return getBoxShadowsSwatchIds(prop);
|
|
2480
2484
|
case Types.RichText: {
|
|
2481
2485
|
let getNodeSwatchIds = function(node) {
|
|
2482
|
-
var _a3,
|
|
2486
|
+
var _a3, _b2, _c, _d;
|
|
2483
2487
|
switch (node.object) {
|
|
2484
2488
|
case "document":
|
|
2485
2489
|
case "block":
|
|
2486
2490
|
case "inline":
|
|
2487
|
-
return (
|
|
2491
|
+
return (_b2 = (_a3 = node.nodes) == null ? void 0 : _a3.flatMap(getNodeSwatchIds)) != null ? _b2 : [];
|
|
2488
2492
|
case "text":
|
|
2489
2493
|
return (_d = (_c = node.marks) == null ? void 0 : _c.flatMap(getMarkSwatchIds)) != null ? _d : [];
|
|
2490
2494
|
default:
|
|
2491
2495
|
return [];
|
|
2492
2496
|
}
|
|
2493
2497
|
}, getMarkSwatchIds = function(mark) {
|
|
2494
|
-
var _a3,
|
|
2495
|
-
return getTypographyStyleSwatchIds((
|
|
2498
|
+
var _a3, _b2;
|
|
2499
|
+
return getTypographyStyleSwatchIds((_b2 = (_a3 = mark.data) == null ? void 0 : _a3.value) == null ? void 0 : _b2.style);
|
|
2496
2500
|
};
|
|
2497
2501
|
const value = prop;
|
|
2498
2502
|
if (value == null || value.document == null)
|
|
@@ -2505,7 +2509,7 @@ function getSwatchIds(descriptor, prop) {
|
|
|
2505
2509
|
}
|
|
2506
2510
|
case StyleV2ControlType: {
|
|
2507
2511
|
const value = prop;
|
|
2508
|
-
return value.flatMap((value2) => getSwatchIds(descriptor.config.type, value2.value));
|
|
2512
|
+
return (_b = value == null ? void 0 : value.flatMap((value2) => getSwatchIds(descriptor.config.type, value2.value))) != null ? _b : [];
|
|
2509
2513
|
}
|
|
2510
2514
|
case RichTextV2ControlType: {
|
|
2511
2515
|
let getDescendantSwatchIds = function(descendant) {
|
|
@@ -2534,6 +2538,8 @@ function getSwatchIds(descriptor, prop) {
|
|
|
2534
2538
|
};
|
|
2535
2539
|
const descendants = prop;
|
|
2536
2540
|
const plugins = descriptor.config.plugins;
|
|
2541
|
+
if (isRichTextV1Data(descendants))
|
|
2542
|
+
return [];
|
|
2537
2543
|
return descendants.flatMap((d) => getDescendantSwatchIds(d));
|
|
2538
2544
|
}
|
|
2539
2545
|
case ShapeControlType: {
|
|
@@ -3088,6 +3094,7 @@ exports.introspection = introspection;
|
|
|
3088
3094
|
exports.isElementReference = isElementReference;
|
|
3089
3095
|
exports.isNonNullable = isNonNullable;
|
|
3090
3096
|
exports.isPropControllersHandle = isPropControllersHandle;
|
|
3097
|
+
exports.isRichTextV1Data = isRichTextV1Data;
|
|
3091
3098
|
exports.merge = merge;
|
|
3092
3099
|
exports.mergeSlotData = mergeSlotData;
|
|
3093
3100
|
exports.parseLocalesInput = parseLocalesInput;
|