@makeswift/runtime 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Text.cjs.js CHANGED
@@ -348,6 +348,9 @@ const RichTextEditor = styled__default["default"](React.forwardRef(function Rich
348
348
  ]);
349
349
  const plugins = React.useMemo(() => [Lists__default["default"](), LinkPlugin(), Inlines(), DeviceOverridesBlockPlugin(), DeviceOverridesMarksPlugin()], []);
350
350
  return /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editor, __spreadProps(__spreadValues({}, restOfProps), {
351
+ style: {
352
+ WebkitUserModify: void 0
353
+ },
351
354
  ref,
352
355
  autoFocus: false,
353
356
  plugins,
@@ -1 +1 @@
1
- {"version":3,"file":"Text.cjs.js","sources":["../src/components/hooks/useTypography.ts","../src/components/builtin/Text/components/RichTextEditor/components/Mark/hooks/useTypographyMark.ts","../src/components/builtin/Text/components/RichTextEditor/components/Mark/index.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/components/Block/index.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/Text.tsx"],"sourcesContent":["import type { ColorValue } from '../utils/types'\nimport type { Length as LengthValue } from '../../prop-controllers'\nimport { DeviceOverride } from '../../prop-controllers'\nimport { TYPOGRAPHIES_BY_ID } from '../utils/queries'\nimport { useQuery } from '../../api/react'\n\nexport type TypographyStyleValue = {\n fontFamily?: string\n fontWeight?: number\n fontSize?: LengthValue\n color?: ColorValue\n textAlign?: string\n lineHeight?: number\n letterSpacing?: number\n uppercase?: boolean\n underline?: boolean\n strikethrough?: boolean\n italic?: boolean\n}\n\nexport type TypographyStyle = Array<DeviceOverride<TypographyStyleValue>>\n\nexport type Typography = {\n id: string\n name: string\n style: TypographyStyle\n}\n\nexport function useTypography(\n typographyId: string | null | undefined,\n): Typography | null | undefined {\n const { error, data } = useQuery(TYPOGRAPHIES_BY_ID, {\n skip: typographyId == null,\n variables: { ids: typographyId != null ? [typographyId] : [] },\n })\n\n if (typographyId == null || error != null) return null\n\n return data?.typographies[0] as Typography | null\n}\n","import { Length as LengthValue } from '../../../../../../../../prop-controllers'\nimport { ColorValue as Color } from '../../../../../../../utils/types'\nimport { findDeviceOverride } from '../../../../../../../utils/devices'\nimport type { DeviceOverride } from '../../../../../../../../prop-controllers'\nimport { SWATCHES_BY_ID } from '../../../../../../../utils/queries'\nimport { useTypography, TypographyStyle } from '../../../../../../../hooks/useTypography'\nimport { useQuery } from '../../../../../../../../api/react'\n\nexport type TypographyMarkDataValue = {\n fontWeight?: number\n fontSize?: LengthValue\n fontFamily?: string\n color?: Color\n textAlign?: string\n lineHeight?: number\n letterSpacing?: number\n uppercase?: boolean\n italic?: boolean\n underline?: boolean\n strikethrough?: boolean\n}\n\nexport type TypographyMarkValue = {\n id: string | null | undefined\n style: TypographyStyle\n}\n\nexport type TypographyMarkData = Array<DeviceOverride<TypographyMarkDataValue>>\n\nconst concat = <A extends unknown[], B extends unknown[]>(a: A, b: B) => a.concat(b)\nconst getSwatchId = ({ value: { color } }: any) => color && color.swatchId\nconst getDeviceId = ({ deviceId }: any) => deviceId\n\nconst withColor =\n (swatches: any) =>\n ({ value: { color, ...restOfValue }, ...rest }: any) => ({\n ...rest,\n value: {\n ...restOfValue,\n ...(color\n ? {\n color: {\n swatch: swatches.find((s: any) => s && s.id === color.swatchId),\n alpha: color.alpha,\n },\n }\n : {}),\n },\n })\n\nexport const overrideTypographyStyle = <A>(\n source: Array<DeviceOverride<A>>,\n override: Array<DeviceOverride<A>>,\n): Array<DeviceOverride<A>> => {\n const devices = [...new Set(source.map(getDeviceId).concat(override.map(getDeviceId)))]\n\n return devices.map((deviceId: any) => ({\n deviceId,\n value: {\n ...(findDeviceOverride(source, deviceId) || { value: {} }).value,\n ...(findDeviceOverride(override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n\nexport default function useTypographyMark(\n value: TypographyMarkValue | null | undefined,\n): TypographyMarkData | null | undefined {\n const typography = useTypography(value && value.id)\n\n const swatchIds = [\n (typography && typography.style.map(getSwatchId)) || [],\n (value && value.style.map(getSwatchId)) || [],\n ]\n .reduce(concat)\n .filter(Boolean)\n\n const { error: colorError, data: colorData = {} } = useQuery(SWATCHES_BY_ID, {\n skip: swatchIds == null || swatchIds.length === 0,\n variables: { ids: swatchIds },\n })\n\n const { swatches = [] } = colorData\n\n if (colorError != null) return null\n\n return overrideTypographyStyle(\n (typography && typography.style.map(withColor(swatches))) || [],\n (value && value.style.map(withColor(swatches))) || [],\n )\n}\n","import { ComponentPropsWithoutRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport useTypographyMark, {\n TypographyMarkValue,\n TypographyMarkData,\n overrideTypographyStyle,\n TypographyMarkDataValue,\n} from './hooks/useTypographyMark'\nimport { cssMediaRules } from '../../../../../../utils/cssMediaRules'\nimport { colorToString } from '../../../../../../utils/colorToString'\nimport { shallowMergeFallbacks } from '../../../../../../utils/devices'\n\nexport type { TypographyMarkValue }\nexport { overrideTypographyStyle }\n\nconst Span = styled.span<{ typographyStyle: TypographyMarkData | null | undefined }>`\n ${p =>\n cssMediaRules(\n [p.typographyStyle] as const,\n ([\n {\n color,\n fontFamily,\n fontSize,\n fontWeight,\n lineHeight,\n letterSpacing,\n uppercase,\n underline,\n strikethrough,\n italic,\n } = {} as TypographyMarkDataValue,\n ]) => css`\n ${color == null\n ? ''\n : css`\n color: ${colorToString(color)};\n `}\n\n ${fontFamily == null\n ? ''\n : css`\n font-family: '${fontFamily}';\n `}\n\n ${fontSize == null || fontSize.value == null || fontSize.unit == null\n ? ''\n : css`\n font-size: ${`${fontSize.value}${fontSize.unit}`};\n `}\n\n ${fontWeight == null\n ? ''\n : css`\n font-weight: ${fontWeight};\n `}\n\n ${lineHeight == null\n ? ''\n : css`\n line-height: ${lineHeight};\n `}\n\n ${letterSpacing == null\n ? ''\n : css`\n letter-spacing: ${letterSpacing / 10}em;\n `}\n\n ${underline == null && strikethrough == null\n ? ''\n : css`\n text-decoration: ${[\n Boolean(underline) && 'underline',\n Boolean(strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')};\n `}\n\n ${uppercase == null\n ? ''\n : css`\n text-transform: ${uppercase === true ? 'uppercase' : 'initial'};\n `}\n\n ${italic == null\n ? ''\n : css`\n font-style: ${italic === true ? 'italic' : 'initial'};\n `}\n `,\n shallowMergeFallbacks,\n )}\n`\n\ntype BaseProps = { value: TypographyMarkValue }\n\ntype Props = BaseProps & Omit<ComponentPropsWithoutRef<typeof Span>, keyof BaseProps>\n\nexport default function Mark({ value, ...restOfProps }: Props): JSX.Element {\n const typographyStyle = useTypographyMark(value)\n\n return <Span {...restOfProps} typographyStyle={typographyStyle} />\n}\n","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 { forwardRef, ElementType, ComponentPropsWithoutRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { cssMediaRules } from '../../../../../../utils/cssMediaRules'\nimport type { ResponsiveValue } from '../../../../../../../prop-controllers'\n\ntype StyledBlockProps = {\n textAlign?: ResponsiveValue<'left' | 'center' | 'right' | 'justify'>\n as?: ElementType\n}\n\nconst StyledBlock = styled.div<StyledBlockProps>`\n margin: 0;\n ${p =>\n cssMediaRules([p.textAlign] as const, ([textAlign]) =>\n textAlign == null\n ? css``\n : css`\n text-align: ${textAlign};\n `,\n )}\n\n ${p =>\n p.as === 'blockquote'\n ? css`\n padding: 0.5em 10px;\n font-size: 1.25em;\n font-weight: 300;\n border-left: 5px solid rgba(0, 0, 0, 0.1);\n `\n : ''}\n`\n\ntype Props = ComponentPropsWithoutRef<typeof StyledBlock>\n\nexport default forwardRef<HTMLDivElement, Props>(function Block(\n { textAlign, ...restOfProps }: Props,\n ref,\n) {\n return <StyledBlock {...restOfProps} ref={ref} textAlign={textAlign} />\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 { Plugin } from 'slate-react'\nimport styled from 'styled-components'\n\nimport { Link } from '../../../../../shared/Link'\n\nconst StyledLink = styled(Link)`\n text-decoration: none;\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'\nimport styled from 'styled-components'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = styled(\n forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', ...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 ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n }),\n)`\n ul,\n ol {\n margin: 0;\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 styled from 'styled-components'\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 MarginValue,\n RichTextDescriptor,\n RichTextValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { useIsInBuilder } from '../../../runtimes/react'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: WidthValue\n margin?: MarginValue\n}\n\nconst StyledRichTextEditor = styled(RichTextEditor).withConfig({\n shouldForwardProp: prop => !['width', 'margin'].includes(prop.toString()),\n})<{ width: Props['width']; margin: Props['margin'] }>`\n ${cssWidth()}\n ${cssMargin()}\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 Text = forwardRef(function Text(\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 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 // 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 return early so we don't remove the selection.\n if (event.relatedTarget == null) return true\n\n // Blur the selection if the user is clicking on other text.\n return next()\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <StyledRichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n width={width}\n readOnly={!isInBuilder}\n margin={margin}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n />\n )\n})\n\nexport default Text\n"],"names":["useQuery","TYPOGRAPHIES_BY_ID","findDeviceOverride","SWATCHES_BY_ID","Span","styled","span","p","cssMediaRules","typographyStyle","color","fontFamily","fontSize","fontWeight","lineHeight","letterSpacing","uppercase","underline","strikethrough","italic","css","colorToString","value","unit","Boolean","filter","join","shallowMergeFallbacks","restOfProps","useTypographyMark","TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","data","get","StyledBlock","div","textAlign","as","forwardRef","ref","renderBlock","props","node","attributes","blockProps","StyledLink","Link","renderInline","toJS","RichTextEditor","placeholder","plugins","useMemo","Lists","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","StyledRichTextEditor","withConfig","shouldForwardProp","prop","includes","toString","cssWidth","cssMargin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","Text","id","text","width","margin","editor","setEditor","useState","propControllers","setPropControllers","controller","useImperativeHandle","getBoxModel","el","findDOMNode","Element","getBox","useEffect","setSlateEditor","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","isInBuilder","useIsInBuil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,mBAAeE,UAAU7B;AAC9D8B,QAAAA,cAAcC,MAAAA,YAAY,MAAM;;AACpCJ,yBAAeE,YAAfF,mBAAwBK;AAAAA,EADK,GAE5B,CAF4B,CAAA;AAG/B,QAAMC,gBAAgBF,MAAAA,YACpB,CAACG,OAA2BtF,SAAiBC,UAAoB;;AAC3DsF,QAAAA,iBAAAA,WAAQC,OAAOF,KAAf,GAAuB;AACzBP,2BAAeE,YAAfF,mBAAwBU;AAEjB,aAAA;AAAA,IACR;AAEGF,QAAAA,iBAAAA,WAAQG,OAAOJ,KAAf,GAAuB;AACzBP,2BAAeE,YAAfF,mBAAwBY;AAEjB,aAAA;AAAA,IACR;AAED,QAAIC,kBAAS,QAAD,EAAWN,KAAnB,GAA2B;AAC7BP,2BAAeE,YAAfF,mBAAwBc;AAEjB,aAAA;AAAA,IACR;AAED,WAAO5F,MAAP;AAAA,EApB6B,GAsB/B,CAtB+B,CAAA;AAwBjC,QAAM6F,aAAaX,MAAAA,YAAY,CAACG,OAAwBtF,SAAiBC,UAAoB;AAIvFqF,QAAAA,MAAMS,iBAAiB;AAAa,aAAA;AAGxC,WAAO9F,MAAP;AAAA,EAP4B,GAQ3B,CAR2B,CAAA;AAUxB+F,QAAAA,cAAcC,KAAAA;AAGlB,wCAAC,sBAAD;AAAA,IAEE;AAAA,IACA,KAAKjD;AAAAA,IACL;AAAA,IACA,UAAU,CAACgD;AAAAA,IACX;AAAA,IACA;AAAA,IACA,UAAUE;AAAAA,IACV,SAAShB;AAAAA,IACT,WAAWG;AAAAA,IACX,QAAQS;AAAAA,EAAAA,CAZZ;AAeD,CA9IsB;;"}
1
+ {"version":3,"file":"Text.cjs.js","sources":["../src/components/hooks/useTypography.ts","../src/components/builtin/Text/components/RichTextEditor/components/Mark/hooks/useTypographyMark.ts","../src/components/builtin/Text/components/RichTextEditor/components/Mark/index.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/components/Block/index.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/Text.tsx"],"sourcesContent":["import type { ColorValue } from '../utils/types'\nimport type { Length as LengthValue } from '../../prop-controllers'\nimport { DeviceOverride } from '../../prop-controllers'\nimport { TYPOGRAPHIES_BY_ID } from '../utils/queries'\nimport { useQuery } from '../../api/react'\n\nexport type TypographyStyleValue = {\n fontFamily?: string\n fontWeight?: number\n fontSize?: LengthValue\n color?: ColorValue\n textAlign?: string\n lineHeight?: number\n letterSpacing?: number\n uppercase?: boolean\n underline?: boolean\n strikethrough?: boolean\n italic?: boolean\n}\n\nexport type TypographyStyle = Array<DeviceOverride<TypographyStyleValue>>\n\nexport type Typography = {\n id: string\n name: string\n style: TypographyStyle\n}\n\nexport function useTypography(\n typographyId: string | null | undefined,\n): Typography | null | undefined {\n const { error, data } = useQuery(TYPOGRAPHIES_BY_ID, {\n skip: typographyId == null,\n variables: { ids: typographyId != null ? [typographyId] : [] },\n })\n\n if (typographyId == null || error != null) return null\n\n return data?.typographies[0] as Typography | null\n}\n","import { Length as LengthValue } from '../../../../../../../../prop-controllers'\nimport { ColorValue as Color } from '../../../../../../../utils/types'\nimport { findDeviceOverride } from '../../../../../../../utils/devices'\nimport type { DeviceOverride } from '../../../../../../../../prop-controllers'\nimport { SWATCHES_BY_ID } from '../../../../../../../utils/queries'\nimport { useTypography, TypographyStyle } from '../../../../../../../hooks/useTypography'\nimport { useQuery } from '../../../../../../../../api/react'\n\nexport type TypographyMarkDataValue = {\n fontWeight?: number\n fontSize?: LengthValue\n fontFamily?: string\n color?: Color\n textAlign?: string\n lineHeight?: number\n letterSpacing?: number\n uppercase?: boolean\n italic?: boolean\n underline?: boolean\n strikethrough?: boolean\n}\n\nexport type TypographyMarkValue = {\n id: string | null | undefined\n style: TypographyStyle\n}\n\nexport type TypographyMarkData = Array<DeviceOverride<TypographyMarkDataValue>>\n\nconst concat = <A extends unknown[], B extends unknown[]>(a: A, b: B) => a.concat(b)\nconst getSwatchId = ({ value: { color } }: any) => color && color.swatchId\nconst getDeviceId = ({ deviceId }: any) => deviceId\n\nconst withColor =\n (swatches: any) =>\n ({ value: { color, ...restOfValue }, ...rest }: any) => ({\n ...rest,\n value: {\n ...restOfValue,\n ...(color\n ? {\n color: {\n swatch: swatches.find((s: any) => s && s.id === color.swatchId),\n alpha: color.alpha,\n },\n }\n : {}),\n },\n })\n\nexport const overrideTypographyStyle = <A>(\n source: Array<DeviceOverride<A>>,\n override: Array<DeviceOverride<A>>,\n): Array<DeviceOverride<A>> => {\n const devices = [...new Set(source.map(getDeviceId).concat(override.map(getDeviceId)))]\n\n return devices.map((deviceId: any) => ({\n deviceId,\n value: {\n ...(findDeviceOverride(source, deviceId) || { value: {} }).value,\n ...(findDeviceOverride(override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n\nexport default function useTypographyMark(\n value: TypographyMarkValue | null | undefined,\n): TypographyMarkData | null | undefined {\n const typography = useTypography(value && value.id)\n\n const swatchIds = [\n (typography && typography.style.map(getSwatchId)) || [],\n (value && value.style.map(getSwatchId)) || [],\n ]\n .reduce(concat)\n .filter(Boolean)\n\n const { error: colorError, data: colorData = {} } = useQuery(SWATCHES_BY_ID, {\n skip: swatchIds == null || swatchIds.length === 0,\n variables: { ids: swatchIds },\n })\n\n const { swatches = [] } = colorData\n\n if (colorError != null) return null\n\n return overrideTypographyStyle(\n (typography && typography.style.map(withColor(swatches))) || [],\n (value && value.style.map(withColor(swatches))) || [],\n )\n}\n","import { ComponentPropsWithoutRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport useTypographyMark, {\n TypographyMarkValue,\n TypographyMarkData,\n overrideTypographyStyle,\n TypographyMarkDataValue,\n} from './hooks/useTypographyMark'\nimport { cssMediaRules } from '../../../../../../utils/cssMediaRules'\nimport { colorToString } from '../../../../../../utils/colorToString'\nimport { shallowMergeFallbacks } from '../../../../../../utils/devices'\n\nexport type { TypographyMarkValue }\nexport { overrideTypographyStyle }\n\nconst Span = styled.span<{ typographyStyle: TypographyMarkData | null | undefined }>`\n ${p =>\n cssMediaRules(\n [p.typographyStyle] as const,\n ([\n {\n color,\n fontFamily,\n fontSize,\n fontWeight,\n lineHeight,\n letterSpacing,\n uppercase,\n underline,\n strikethrough,\n italic,\n } = {} as TypographyMarkDataValue,\n ]) => css`\n ${color == null\n ? ''\n : css`\n color: ${colorToString(color)};\n `}\n\n ${fontFamily == null\n ? ''\n : css`\n font-family: '${fontFamily}';\n `}\n\n ${fontSize == null || fontSize.value == null || fontSize.unit == null\n ? ''\n : css`\n font-size: ${`${fontSize.value}${fontSize.unit}`};\n `}\n\n ${fontWeight == null\n ? ''\n : css`\n font-weight: ${fontWeight};\n `}\n\n ${lineHeight == null\n ? ''\n : css`\n line-height: ${lineHeight};\n `}\n\n ${letterSpacing == null\n ? ''\n : css`\n letter-spacing: ${letterSpacing / 10}em;\n `}\n\n ${underline == null && strikethrough == null\n ? ''\n : css`\n text-decoration: ${[\n Boolean(underline) && 'underline',\n Boolean(strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')};\n `}\n\n ${uppercase == null\n ? ''\n : css`\n text-transform: ${uppercase === true ? 'uppercase' : 'initial'};\n `}\n\n ${italic == null\n ? ''\n : css`\n font-style: ${italic === true ? 'italic' : 'initial'};\n `}\n `,\n shallowMergeFallbacks,\n )}\n`\n\ntype BaseProps = { value: TypographyMarkValue }\n\ntype Props = BaseProps & Omit<ComponentPropsWithoutRef<typeof Span>, keyof BaseProps>\n\nexport default function Mark({ value, ...restOfProps }: Props): JSX.Element {\n const typographyStyle = useTypographyMark(value)\n\n return <Span {...restOfProps} typographyStyle={typographyStyle} />\n}\n","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 { forwardRef, ElementType, ComponentPropsWithoutRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { cssMediaRules } from '../../../../../../utils/cssMediaRules'\nimport type { ResponsiveValue } from '../../../../../../../prop-controllers'\n\ntype StyledBlockProps = {\n textAlign?: ResponsiveValue<'left' | 'center' | 'right' | 'justify'>\n as?: ElementType\n}\n\nconst StyledBlock = styled.div<StyledBlockProps>`\n margin: 0;\n ${p =>\n cssMediaRules([p.textAlign] as const, ([textAlign]) =>\n textAlign == null\n ? css``\n : css`\n text-align: ${textAlign};\n `,\n )}\n\n ${p =>\n p.as === 'blockquote'\n ? css`\n padding: 0.5em 10px;\n font-size: 1.25em;\n font-weight: 300;\n border-left: 5px solid rgba(0, 0, 0, 0.1);\n `\n : ''}\n`\n\ntype Props = ComponentPropsWithoutRef<typeof StyledBlock>\n\nexport default forwardRef<HTMLDivElement, Props>(function Block(\n { textAlign, ...restOfProps }: Props,\n ref,\n) {\n return <StyledBlock {...restOfProps} ref={ref} textAlign={textAlign} />\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 { Plugin } from 'slate-react'\nimport styled from 'styled-components'\n\nimport { Link } from '../../../../../shared/Link'\n\nconst StyledLink = styled(Link)`\n text-decoration: none;\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'\nimport styled from 'styled-components'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = styled(\n forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', ...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 ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n }),\n)`\n ul,\n ol {\n margin: 0;\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 styled from 'styled-components'\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 MarginValue,\n RichTextDescriptor,\n RichTextValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { useIsInBuilder } from '../../../runtimes/react'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: WidthValue\n margin?: MarginValue\n}\n\nconst StyledRichTextEditor = styled(RichTextEditor).withConfig({\n shouldForwardProp: prop => !['width', 'margin'].includes(prop.toString()),\n})<{ width: Props['width']; margin: Props['margin'] }>`\n ${cssWidth()}\n ${cssMargin()}\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 Text = forwardRef(function Text(\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 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 // 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 return early so we don't remove the selection.\n if (event.relatedTarget == null) return true\n\n // Blur the selection if the user is clicking on other text.\n return next()\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <StyledRichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n width={width}\n readOnly={!isInBuilder}\n margin={margin}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n />\n )\n})\n\nexport default Text\n"],"names":["useQuery","TYPOGRAPHIES_BY_ID","findDeviceOverride","SWATCHES_BY_ID","Span","styled","span","p","cssMediaRules","typographyStyle","color","fontFamily","fontSize","fontWeight","lineHeight","letterSpacing","uppercase","underline","strikethrough","italic","css","colorToString","value","unit","Boolean","filter","join","shallowMergeFallbacks","restOfProps","useTypographyMark","TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","data","get","StyledBlock","div","textAlign","as","forwardRef","ref","renderBlock","props","node","attributes","blockProps","StyledLink","Link","renderInline","toJS","RichTextEditor","placeholder","plugins","useMemo","Lists","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","WebkitUserModify","undefined","StyledRichTextEditor","withConfig","shouldForwardProp","prop","includes","toString","cssWidth","cssMargin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","Text","id","text","width","margin","editor","setEditor","useState","propControllers","setPropControllers","controller","useImperativeHandle","getBoxModel","el","findDOMNode","Element","getBox","useEffect","setSlateEditor","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","isInBuilder","useIsInBuilder","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,uBACL,cAC+B;AAC/B,QAAM,EAAE,OAAO,SAASA,KAAAA,SAASC,KAAAA,oBAAoB;AAAA,IACnD,MAAM,gBAAgB;AAAA,IACtB,WAAW,EAAE,KAAK,gBAAgB,OAAO,CAAC,YAAY,IAAI,GAAG;AAAA,EAAA,CAC9D;AAEG,MAAA,gBAAgB,QAAQ,SAAS;AAAa,WAAA;AAElD,SAAO,6BAAM,aAAa;AAC5B;ACVA,MAAM,SAAS,CAA2C,GAAM,MAAS,EAAE,OAAO,CAAC;AACnF,MAAM,cAAc,CAAC,EAAE,OAAO,EAAE,cAAmB,SAAS,MAAM;AAClE,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KAAnB,GAA2B;AAC7BP,2BAAeE,YAAfF,mBAAwBc;AAEjB,aAAA;AAAA,IACR;AAED,WAAO9F,MAAP;AAAA,EApB6B,GAsB/B,CAtB+B,CAAA;AAwBjC,QAAM+F,aAAaX,MAAAA,YAAY,CAACG,OAAwBxF,SAAiBC,UAAoB;AAIvFuF,QAAAA,MAAMS,iBAAiB;AAAa,aAAA;AAGxC,WAAOhG,MAAP;AAAA,EAP4B,GAQ3B,CAR2B,CAAA;AAUxBiG,QAAAA,cAAcC,KAAAA;AAGlB,wCAAC,sBAAD;AAAA,IAEE;AAAA,IACA,KAAKjD;AAAAA,IACL;AAAA,IACA,UAAU,CAACgD;AAAAA,IACX;AAAA,IACA;AAAA,IACA,UAAUE;AAAAA,IACV,SAAShB;AAAAA,IACT,WAAWG;AAAAA,IACX,QAAQS;AAAAA,EAAAA,CAZZ;AAeD,CA9IsB;;"}
package/dist/Text.es.js CHANGED
@@ -340,6 +340,9 @@ const RichTextEditor = styled(forwardRef(function RichTextEditor2(_e, ref) {
340
340
  ]);
341
341
  const plugins = useMemo(() => [Lists(), LinkPlugin(), Inlines(), DeviceOverridesBlockPlugin(), DeviceOverridesMarksPlugin()], []);
342
342
  return /* @__PURE__ */ jsx(Editor, __spreadProps(__spreadValues({}, restOfProps), {
343
+ style: {
344
+ WebkitUserModify: void 0
345
+ },
343
346
  ref,
344
347
  autoFocus: false,
345
348
  plugins,
@@ -1 +1 @@
1
- {"version":3,"file":"Text.es.js","sources":["../src/components/hooks/useTypography.ts","../src/components/builtin/Text/components/RichTextEditor/components/Mark/hooks/useTypographyMark.ts","../src/components/builtin/Text/components/RichTextEditor/components/Mark/index.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/components/Block/index.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/Text.tsx"],"sourcesContent":["import type { ColorValue } from '../utils/types'\nimport type { Length as LengthValue } from '../../prop-controllers'\nimport { DeviceOverride } from '../../prop-controllers'\nimport { TYPOGRAPHIES_BY_ID } from '../utils/queries'\nimport { useQuery } from '../../api/react'\n\nexport type TypographyStyleValue = {\n fontFamily?: string\n fontWeight?: number\n fontSize?: LengthValue\n color?: ColorValue\n textAlign?: string\n lineHeight?: number\n letterSpacing?: number\n uppercase?: boolean\n underline?: boolean\n strikethrough?: boolean\n italic?: boolean\n}\n\nexport type TypographyStyle = Array<DeviceOverride<TypographyStyleValue>>\n\nexport type Typography = {\n id: string\n name: string\n style: TypographyStyle\n}\n\nexport function useTypography(\n typographyId: string | null | undefined,\n): Typography | null | undefined {\n const { error, data } = useQuery(TYPOGRAPHIES_BY_ID, {\n skip: typographyId == null,\n variables: { ids: typographyId != null ? [typographyId] : [] },\n })\n\n if (typographyId == null || error != null) return null\n\n return data?.typographies[0] as Typography | null\n}\n","import { Length as LengthValue } from '../../../../../../../../prop-controllers'\nimport { ColorValue as Color } from '../../../../../../../utils/types'\nimport { findDeviceOverride } from '../../../../../../../utils/devices'\nimport type { DeviceOverride } from '../../../../../../../../prop-controllers'\nimport { SWATCHES_BY_ID } from '../../../../../../../utils/queries'\nimport { useTypography, TypographyStyle } from '../../../../../../../hooks/useTypography'\nimport { useQuery } from '../../../../../../../../api/react'\n\nexport type TypographyMarkDataValue = {\n fontWeight?: number\n fontSize?: LengthValue\n fontFamily?: string\n color?: Color\n textAlign?: string\n lineHeight?: number\n letterSpacing?: number\n uppercase?: boolean\n italic?: boolean\n underline?: boolean\n strikethrough?: boolean\n}\n\nexport type TypographyMarkValue = {\n id: string | null | undefined\n style: TypographyStyle\n}\n\nexport type TypographyMarkData = Array<DeviceOverride<TypographyMarkDataValue>>\n\nconst concat = <A extends unknown[], B extends unknown[]>(a: A, b: B) => a.concat(b)\nconst getSwatchId = ({ value: { color } }: any) => color && color.swatchId\nconst getDeviceId = ({ deviceId }: any) => deviceId\n\nconst withColor =\n (swatches: any) =>\n ({ value: { color, ...restOfValue }, ...rest }: any) => ({\n ...rest,\n value: {\n ...restOfValue,\n ...(color\n ? {\n color: {\n swatch: swatches.find((s: any) => s && s.id === color.swatchId),\n alpha: color.alpha,\n },\n }\n : {}),\n },\n })\n\nexport const overrideTypographyStyle = <A>(\n source: Array<DeviceOverride<A>>,\n override: Array<DeviceOverride<A>>,\n): Array<DeviceOverride<A>> => {\n const devices = [...new Set(source.map(getDeviceId).concat(override.map(getDeviceId)))]\n\n return devices.map((deviceId: any) => ({\n deviceId,\n value: {\n ...(findDeviceOverride(source, deviceId) || { value: {} }).value,\n ...(findDeviceOverride(override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n\nexport default function useTypographyMark(\n value: TypographyMarkValue | null | undefined,\n): TypographyMarkData | null | undefined {\n const typography = useTypography(value && value.id)\n\n const swatchIds = [\n (typography && typography.style.map(getSwatchId)) || [],\n (value && value.style.map(getSwatchId)) || [],\n ]\n .reduce(concat)\n .filter(Boolean)\n\n const { error: colorError, data: colorData = {} } = useQuery(SWATCHES_BY_ID, {\n skip: swatchIds == null || swatchIds.length === 0,\n variables: { ids: swatchIds },\n })\n\n const { swatches = [] } = colorData\n\n if (colorError != null) return null\n\n return overrideTypographyStyle(\n (typography && typography.style.map(withColor(swatches))) || [],\n (value && value.style.map(withColor(swatches))) || [],\n )\n}\n","import { ComponentPropsWithoutRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport useTypographyMark, {\n TypographyMarkValue,\n TypographyMarkData,\n overrideTypographyStyle,\n TypographyMarkDataValue,\n} from './hooks/useTypographyMark'\nimport { cssMediaRules } from '../../../../../../utils/cssMediaRules'\nimport { colorToString } from '../../../../../../utils/colorToString'\nimport { shallowMergeFallbacks } from '../../../../../../utils/devices'\n\nexport type { TypographyMarkValue }\nexport { overrideTypographyStyle }\n\nconst Span = styled.span<{ typographyStyle: TypographyMarkData | null | undefined }>`\n ${p =>\n cssMediaRules(\n [p.typographyStyle] as const,\n ([\n {\n color,\n fontFamily,\n fontSize,\n fontWeight,\n lineHeight,\n letterSpacing,\n uppercase,\n underline,\n strikethrough,\n italic,\n } = {} as TypographyMarkDataValue,\n ]) => css`\n ${color == null\n ? ''\n : css`\n color: ${colorToString(color)};\n `}\n\n ${fontFamily == null\n ? ''\n : css`\n font-family: '${fontFamily}';\n `}\n\n ${fontSize == null || fontSize.value == null || fontSize.unit == null\n ? ''\n : css`\n font-size: ${`${fontSize.value}${fontSize.unit}`};\n `}\n\n ${fontWeight == null\n ? ''\n : css`\n font-weight: ${fontWeight};\n `}\n\n ${lineHeight == null\n ? ''\n : css`\n line-height: ${lineHeight};\n `}\n\n ${letterSpacing == null\n ? ''\n : css`\n letter-spacing: ${letterSpacing / 10}em;\n `}\n\n ${underline == null && strikethrough == null\n ? ''\n : css`\n text-decoration: ${[\n Boolean(underline) && 'underline',\n Boolean(strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')};\n `}\n\n ${uppercase == null\n ? ''\n : css`\n text-transform: ${uppercase === true ? 'uppercase' : 'initial'};\n `}\n\n ${italic == null\n ? ''\n : css`\n font-style: ${italic === true ? 'italic' : 'initial'};\n `}\n `,\n shallowMergeFallbacks,\n )}\n`\n\ntype BaseProps = { value: TypographyMarkValue }\n\ntype Props = BaseProps & Omit<ComponentPropsWithoutRef<typeof Span>, keyof BaseProps>\n\nexport default function Mark({ value, ...restOfProps }: Props): JSX.Element {\n const typographyStyle = useTypographyMark(value)\n\n return <Span {...restOfProps} typographyStyle={typographyStyle} />\n}\n","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 { forwardRef, ElementType, ComponentPropsWithoutRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { cssMediaRules } from '../../../../../../utils/cssMediaRules'\nimport type { ResponsiveValue } from '../../../../../../../prop-controllers'\n\ntype StyledBlockProps = {\n textAlign?: ResponsiveValue<'left' | 'center' | 'right' | 'justify'>\n as?: ElementType\n}\n\nconst StyledBlock = styled.div<StyledBlockProps>`\n margin: 0;\n ${p =>\n cssMediaRules([p.textAlign] as const, ([textAlign]) =>\n textAlign == null\n ? css``\n : css`\n text-align: ${textAlign};\n `,\n )}\n\n ${p =>\n p.as === 'blockquote'\n ? css`\n padding: 0.5em 10px;\n font-size: 1.25em;\n font-weight: 300;\n border-left: 5px solid rgba(0, 0, 0, 0.1);\n `\n : ''}\n`\n\ntype Props = ComponentPropsWithoutRef<typeof StyledBlock>\n\nexport default forwardRef<HTMLDivElement, Props>(function Block(\n { textAlign, ...restOfProps }: Props,\n ref,\n) {\n return <StyledBlock {...restOfProps} ref={ref} textAlign={textAlign} />\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 { Plugin } from 'slate-react'\nimport styled from 'styled-components'\n\nimport { Link } from '../../../../../shared/Link'\n\nconst StyledLink = styled(Link)`\n text-decoration: none;\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'\nimport styled from 'styled-components'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = styled(\n forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', ...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 ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n }),\n)`\n ul,\n ol {\n margin: 0;\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 styled from 'styled-components'\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 MarginValue,\n RichTextDescriptor,\n RichTextValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { useIsInBuilder } from '../../../runtimes/react'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: WidthValue\n margin?: MarginValue\n}\n\nconst StyledRichTextEditor = styled(RichTextEditor).withConfig({\n shouldForwardProp: prop => !['width', 'margin'].includes(prop.toString()),\n})<{ width: Props['width']; margin: Props['margin'] }>`\n ${cssWidth()}\n ${cssMargin()}\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 Text = forwardRef(function Text(\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 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 // 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 return early so we don't remove the selection.\n if (event.relatedTarget == null) return true\n\n // Blur the selection if the user is clicking on other text.\n return next()\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <StyledRichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n width={width}\n readOnly={!isInBuilder}\n margin={margin}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n />\n )\n})\n\nexport default Text\n"],"names":["Span","styled","span","p","cssMediaRules","typographyStyle","color","fontFamily","fontSize","fontWeight","lineHeight","letterSpacing","uppercase","underline","strikethrough","italic","css","colorToString","value","unit","Boolean","filter","join","shallowMergeFallbacks","restOfProps","useTypographyMark","TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","data","get","StyledBlock","div","textAlign","as","forwardRef","ref","renderBlock","props","node","attributes","blockProps","StyledLink","Link","renderInline","toJS","RichTextEditor","placeholder","plugins","useMemo","Lists","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","StyledRichTextEditor","withConfig","shouldForwardProp","prop","includes","toString","cssWidth","cssMargin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","Text","id","text","width","margin","editor","setEditor","useState","propControllers","setPropControllers","controller","useImperativeHandle","getBoxModel","el","findDOMNode","Element","getBox","useEffect","setSlateEditor","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","isInBuilder","useIsInBuilder","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,uBACL,cAC+B;AAC/B,QAAM,EAAE,OAAO,SAAS,SAAS,oBAAoB;AAAA,IACnD,MAAM,gBAAgB;AAAA,IACtB,WAAW,EAAE,KAAK,gBAAgB,OAAO,CAAC,YAAY,IAAI,GAAG;AAAA,EAAA,CAC9D;AAEG,MAAA,gBAAgB,QAAQ,SAAS;AAAa,WAAA;AAElD,SAAO,6BAAM,aAAa;AAC5B;ACVA,MAAM,SAAS,CAA2C,GAAM,MAAS,EAAE,OAAO,CAAC;AACnF,MAAM,cAAc,CAAC,EAAE,OAAO,EAAE,cAAmB,SAAS,MAAM;AAClE,MAAM,cAAc,CAAC,EAAE,eAAoB;AAE3C,MAAM,YACJ,CAAC,aACD,CAAC,OAAwD;AAAxD,eAAS,EAAP,OAAO,OAAT,IAAS,SAAE,YAAF,IAAY,wBAAZ,IAAY,CAAV,WAA4B,iBAAvC,IAAuC,CAArC;AAAsD,0CACpD,OADoD;AAAA,IAEvD,OAAO,kCACF,cACC,QACA;AAAA,MACE,OAAO;AAAA,QACL,QAAQ,SAAS,KAAK,CAAC,MAAW,KAAK,EAAE,OAAO,MAAM,QAAQ;AAAA,QAC9D,OAAO,MAAM;AAAA,MACf;AAAA,IAAA,IAEF,CA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OAAOzF,UAAUA,OAAO;AAC1B+E,sBAAgB,KAAD;AAEff,+CAAY0B,SAASD;AAAAA,IACtB;AAAA,EACF;AAIKE,QAAAA,iBAAiBC,OAAO5B,UAAD;AACzB2B,MAAAA,eAAeE,YAAY7B;AAAY2B,mBAAeE,UAAU7B;AAC9D8B,QAAAA,cAAcC,YAAY,MAAM;;AACpCJ,yBAAeE,YAAfF,mBAAwBK;AAAAA,EADK,GAE5B,CAF4B,CAAA;AAG/B,QAAMC,gBAAgBF,YACpB,CAACG,OAA2BtF,SAAiBC,SAAoB;;AAC3DsF,QAAAA,QAAQC,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,WAAO5F,KAAP;AAAA,EApB6B,GAsB/B,CAtB+B,CAAA;AAwBjC,QAAM6F,aAAaX,YAAY,CAACG,OAAwBtF,SAAiBC,SAAoB;AAIvFqF,QAAAA,MAAMS,iBAAiB;AAAa,aAAA;AAGxC,WAAO9F,KAAP;AAAA,EAP4B,GAQ3B,CAR2B,CAAA;AAUxB+F,QAAAA,cAAcC;AAGlB,6BAAC,sBAAD;AAAA,IAEE;AAAA,IACA,KAAKjD;AAAAA,IACL;AAAA,IACA,UAAU,CAACgD;AAAAA,IACX;AAAA,IACA;AAAA,IACA,UAAUE;AAAAA,IACV,SAAShB;AAAAA,IACT,WAAWG;AAAAA,IACX,QAAQS;AAAAA,EAAAA,CAZZ;AAeD,CA9IsB;;"}
1
+ {"version":3,"file":"Text.es.js","sources":["../src/components/hooks/useTypography.ts","../src/components/builtin/Text/components/RichTextEditor/components/Mark/hooks/useTypographyMark.ts","../src/components/builtin/Text/components/RichTextEditor/components/Mark/index.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/components/Block/index.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/Text.tsx"],"sourcesContent":["import type { ColorValue } from '../utils/types'\nimport type { Length as LengthValue } from '../../prop-controllers'\nimport { DeviceOverride } from '../../prop-controllers'\nimport { TYPOGRAPHIES_BY_ID } from '../utils/queries'\nimport { useQuery } from '../../api/react'\n\nexport type TypographyStyleValue = {\n fontFamily?: string\n fontWeight?: number\n fontSize?: LengthValue\n color?: ColorValue\n textAlign?: string\n lineHeight?: number\n letterSpacing?: number\n uppercase?: boolean\n underline?: boolean\n strikethrough?: boolean\n italic?: boolean\n}\n\nexport type TypographyStyle = Array<DeviceOverride<TypographyStyleValue>>\n\nexport type Typography = {\n id: string\n name: string\n style: TypographyStyle\n}\n\nexport function useTypography(\n typographyId: string | null | undefined,\n): Typography | null | undefined {\n const { error, data } = useQuery(TYPOGRAPHIES_BY_ID, {\n skip: typographyId == null,\n variables: { ids: typographyId != null ? [typographyId] : [] },\n })\n\n if (typographyId == null || error != null) return null\n\n return data?.typographies[0] as Typography | null\n}\n","import { Length as LengthValue } from '../../../../../../../../prop-controllers'\nimport { ColorValue as Color } from '../../../../../../../utils/types'\nimport { findDeviceOverride } from '../../../../../../../utils/devices'\nimport type { DeviceOverride } from '../../../../../../../../prop-controllers'\nimport { SWATCHES_BY_ID } from '../../../../../../../utils/queries'\nimport { useTypography, TypographyStyle } from '../../../../../../../hooks/useTypography'\nimport { useQuery } from '../../../../../../../../api/react'\n\nexport type TypographyMarkDataValue = {\n fontWeight?: number\n fontSize?: LengthValue\n fontFamily?: string\n color?: Color\n textAlign?: string\n lineHeight?: number\n letterSpacing?: number\n uppercase?: boolean\n italic?: boolean\n underline?: boolean\n strikethrough?: boolean\n}\n\nexport type TypographyMarkValue = {\n id: string | null | undefined\n style: TypographyStyle\n}\n\nexport type TypographyMarkData = Array<DeviceOverride<TypographyMarkDataValue>>\n\nconst concat = <A extends unknown[], B extends unknown[]>(a: A, b: B) => a.concat(b)\nconst getSwatchId = ({ value: { color } }: any) => color && color.swatchId\nconst getDeviceId = ({ deviceId }: any) => deviceId\n\nconst withColor =\n (swatches: any) =>\n ({ value: { color, ...restOfValue }, ...rest }: any) => ({\n ...rest,\n value: {\n ...restOfValue,\n ...(color\n ? {\n color: {\n swatch: swatches.find((s: any) => s && s.id === color.swatchId),\n alpha: color.alpha,\n },\n }\n : {}),\n },\n })\n\nexport const overrideTypographyStyle = <A>(\n source: Array<DeviceOverride<A>>,\n override: Array<DeviceOverride<A>>,\n): Array<DeviceOverride<A>> => {\n const devices = [...new Set(source.map(getDeviceId).concat(override.map(getDeviceId)))]\n\n return devices.map((deviceId: any) => ({\n deviceId,\n value: {\n ...(findDeviceOverride(source, deviceId) || { value: {} }).value,\n ...(findDeviceOverride(override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n\nexport default function useTypographyMark(\n value: TypographyMarkValue | null | undefined,\n): TypographyMarkData | null | undefined {\n const typography = useTypography(value && value.id)\n\n const swatchIds = [\n (typography && typography.style.map(getSwatchId)) || [],\n (value && value.style.map(getSwatchId)) || [],\n ]\n .reduce(concat)\n .filter(Boolean)\n\n const { error: colorError, data: colorData = {} } = useQuery(SWATCHES_BY_ID, {\n skip: swatchIds == null || swatchIds.length === 0,\n variables: { ids: swatchIds },\n })\n\n const { swatches = [] } = colorData\n\n if (colorError != null) return null\n\n return overrideTypographyStyle(\n (typography && typography.style.map(withColor(swatches))) || [],\n (value && value.style.map(withColor(swatches))) || [],\n )\n}\n","import { ComponentPropsWithoutRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport useTypographyMark, {\n TypographyMarkValue,\n TypographyMarkData,\n overrideTypographyStyle,\n TypographyMarkDataValue,\n} from './hooks/useTypographyMark'\nimport { cssMediaRules } from '../../../../../../utils/cssMediaRules'\nimport { colorToString } from '../../../../../../utils/colorToString'\nimport { shallowMergeFallbacks } from '../../../../../../utils/devices'\n\nexport type { TypographyMarkValue }\nexport { overrideTypographyStyle }\n\nconst Span = styled.span<{ typographyStyle: TypographyMarkData | null | undefined }>`\n ${p =>\n cssMediaRules(\n [p.typographyStyle] as const,\n ([\n {\n color,\n fontFamily,\n fontSize,\n fontWeight,\n lineHeight,\n letterSpacing,\n uppercase,\n underline,\n strikethrough,\n italic,\n } = {} as TypographyMarkDataValue,\n ]) => css`\n ${color == null\n ? ''\n : css`\n color: ${colorToString(color)};\n `}\n\n ${fontFamily == null\n ? ''\n : css`\n font-family: '${fontFamily}';\n `}\n\n ${fontSize == null || fontSize.value == null || fontSize.unit == null\n ? ''\n : css`\n font-size: ${`${fontSize.value}${fontSize.unit}`};\n `}\n\n ${fontWeight == null\n ? ''\n : css`\n font-weight: ${fontWeight};\n `}\n\n ${lineHeight == null\n ? ''\n : css`\n line-height: ${lineHeight};\n `}\n\n ${letterSpacing == null\n ? ''\n : css`\n letter-spacing: ${letterSpacing / 10}em;\n `}\n\n ${underline == null && strikethrough == null\n ? ''\n : css`\n text-decoration: ${[\n Boolean(underline) && 'underline',\n Boolean(strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')};\n `}\n\n ${uppercase == null\n ? ''\n : css`\n text-transform: ${uppercase === true ? 'uppercase' : 'initial'};\n `}\n\n ${italic == null\n ? ''\n : css`\n font-style: ${italic === true ? 'italic' : 'initial'};\n `}\n `,\n shallowMergeFallbacks,\n )}\n`\n\ntype BaseProps = { value: TypographyMarkValue }\n\ntype Props = BaseProps & Omit<ComponentPropsWithoutRef<typeof Span>, keyof BaseProps>\n\nexport default function Mark({ value, ...restOfProps }: Props): JSX.Element {\n const typographyStyle = useTypographyMark(value)\n\n return <Span {...restOfProps} typographyStyle={typographyStyle} />\n}\n","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 { forwardRef, ElementType, ComponentPropsWithoutRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { cssMediaRules } from '../../../../../../utils/cssMediaRules'\nimport type { ResponsiveValue } from '../../../../../../../prop-controllers'\n\ntype StyledBlockProps = {\n textAlign?: ResponsiveValue<'left' | 'center' | 'right' | 'justify'>\n as?: ElementType\n}\n\nconst StyledBlock = styled.div<StyledBlockProps>`\n margin: 0;\n ${p =>\n cssMediaRules([p.textAlign] as const, ([textAlign]) =>\n textAlign == null\n ? css``\n : css`\n text-align: ${textAlign};\n `,\n )}\n\n ${p =>\n p.as === 'blockquote'\n ? css`\n padding: 0.5em 10px;\n font-size: 1.25em;\n font-weight: 300;\n border-left: 5px solid rgba(0, 0, 0, 0.1);\n `\n : ''}\n`\n\ntype Props = ComponentPropsWithoutRef<typeof StyledBlock>\n\nexport default forwardRef<HTMLDivElement, Props>(function Block(\n { textAlign, ...restOfProps }: Props,\n ref,\n) {\n return <StyledBlock {...restOfProps} ref={ref} textAlign={textAlign} />\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 { Plugin } from 'slate-react'\nimport styled from 'styled-components'\n\nimport { Link } from '../../../../../shared/Link'\n\nconst StyledLink = styled(Link)`\n text-decoration: none;\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'\nimport styled from 'styled-components'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = styled(\n forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', ...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 ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n }),\n)`\n ul,\n ol {\n margin: 0;\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 styled from 'styled-components'\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 MarginValue,\n RichTextDescriptor,\n RichTextValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { useIsInBuilder } from '../../../runtimes/react'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: WidthValue\n margin?: MarginValue\n}\n\nconst StyledRichTextEditor = styled(RichTextEditor).withConfig({\n shouldForwardProp: prop => !['width', 'margin'].includes(prop.toString()),\n})<{ width: Props['width']; margin: Props['margin'] }>`\n ${cssWidth()}\n ${cssMargin()}\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 Text = forwardRef(function Text(\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 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 // 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 return early so we don't remove the selection.\n if (event.relatedTarget == null) return true\n\n // Blur the selection if the user is clicking on other text.\n return next()\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <StyledRichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n width={width}\n readOnly={!isInBuilder}\n margin={margin}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n />\n )\n})\n\nexport default Text\n"],"names":["Span","styled","span","p","cssMediaRules","typographyStyle","color","fontFamily","fontSize","fontWeight","lineHeight","letterSpacing","uppercase","underline","strikethrough","italic","css","colorToString","value","unit","Boolean","filter","join","shallowMergeFallbacks","restOfProps","useTypographyMark","TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","data","get","StyledBlock","div","textAlign","as","forwardRef","ref","renderBlock","props","node","attributes","blockProps","StyledLink","Link","renderInline","toJS","RichTextEditor","placeholder","plugins","useMemo","Lists","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","WebkitUserModify","undefined","StyledRichTextEditor","withConfig","shouldForwardProp","prop","includes","toString","cssWidth","cssMargin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","Text","id","text","width","margin","editor","setEditor","useState","propControllers","setPropControllers","controller","useImperativeHandle","getBoxModel","el","findDOMNode","Element","getBox","useEffect","setSlateEditor","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","isInBuilder","useIsInBuilder","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,uBACL,cAC+B;AAC/B,QAAM,EAAE,OAAO,SAAS,SAAS,oBAAoB;AAAA,IACnD,MAAM,gBAAgB;AAAA,IACtB,WAAW,EAAE,KAAK,gBAAgB,OAAO,CAAC,YAAY,IAAI,GAAG;AAAA,EAAA,CAC9D;AAEG,MAAA,gBAAgB,QAAQ,SAAS;AAAa,WAAA;AAElD,SAAO,6BAAM,aAAa;AAC5B;ACVA,MAAM,SAAS,CAA2C,GAAM,MAAS,EAAE,OAAO,CAAC;AACnF,MAAM,cAAc,CAAC,EA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BxF,SAAiBC,SAAoB;AAIvFuF,QAAAA,MAAMS,iBAAiB;AAAa,aAAA;AAGxC,WAAOhG,KAAP;AAAA,EAP4B,GAQ3B,CAR2B,CAAA;AAUxBiG,QAAAA,cAAcC;AAGlB,6BAAC,sBAAD;AAAA,IAEE;AAAA,IACA,KAAKjD;AAAAA,IACL;AAAA,IACA,UAAU,CAACgD;AAAAA,IACX;AAAA,IACA;AAAA,IACA,UAAUE;AAAAA,IACV,SAAShB;AAAAA,IACT,WAAWG;AAAAA,IACX,QAAQS;AAAAA,EAAAA,CAZZ;AAeD,CA9IsB;;"}
@@ -53,23 +53,28 @@ const Link = React.forwardRef(function Link2(_a, ref) {
53
53
  const page = next.usePage(link && link.type === "OPEN_PAGE" ? link.payload.pageId : null);
54
54
  const elementKey = (link == null ? void 0 : link.type) === "SCROLL_TO_ELEMENT" ? (_a2 = link.payload.elementIdConfig) == null ? void 0 : _a2.elementKey : null;
55
55
  const elementId = next.useElementId(elementKey);
56
- let href = "#";
56
+ let useNextLink;
57
+ let href;
57
58
  let target;
58
59
  let block;
59
60
  if (link) {
60
61
  switch (link.type) {
61
62
  case "OPEN_PAGE": {
62
- if (page)
63
+ if (page) {
64
+ useNextLink = true;
63
65
  href = `/${page.pathname}`;
66
+ }
64
67
  target = link.payload.openInNewTab ? "_blank" : "_self";
65
68
  break;
66
69
  }
67
70
  case "OPEN_URL": {
71
+ useNextLink = true;
68
72
  href = link.payload.url;
69
73
  target = link.payload.openInNewTab ? "_blank" : "_self";
70
74
  break;
71
75
  }
72
76
  case "SEND_EMAIL": {
77
+ useNextLink = false;
73
78
  const {
74
79
  to,
75
80
  subject = "",
@@ -80,10 +85,12 @@ const Link = React.forwardRef(function Link2(_a, ref) {
80
85
  break;
81
86
  }
82
87
  case "CALL_PHONE": {
88
+ useNextLink = false;
83
89
  href = `tel:${link.payload.phoneNumber}`;
84
90
  break;
85
91
  }
86
92
  case "SCROLL_TO_ELEMENT": {
93
+ useNextLink = false;
87
94
  href = `#${elementId != null ? elementId : ""}`;
88
95
  block = link.payload.block;
89
96
  break;
@@ -101,11 +108,12 @@ const Link = React.forwardRef(function Link2(_a, ref) {
101
108
  if (link && link.type === "SCROLL_TO_ELEMENT") {
102
109
  let hash;
103
110
  try {
104
- hash = new URL(`http://www.example.com/${href}`).hash;
111
+ if (href != null)
112
+ hash = new URL(`http://www.example.com/${href}`).hash;
105
113
  } catch (error) {
106
114
  console.error(`Link received invalid href: ${href}`, error);
107
115
  }
108
- if (href != null && href === hash) {
116
+ if (href != null && hash != null && href === hash) {
109
117
  event.preventDefault();
110
118
  const view = event.view;
111
119
  scrollIntoView__default["default"](view.document.querySelector(hash), {
@@ -117,14 +125,22 @@ const Link = React.forwardRef(function Link2(_a, ref) {
117
125
  }
118
126
  }
119
127
  }
120
- return /* @__PURE__ */ jsxRuntime.jsx(NextLink__default["default"], {
128
+ if (useNextLink && href != null) {
129
+ return /* @__PURE__ */ jsxRuntime.jsx(NextLink__default["default"], {
130
+ href,
131
+ children: /* @__PURE__ */ jsxRuntime.jsx("a", __spreadProps(__spreadValues({}, restOfProps), {
132
+ ref,
133
+ target,
134
+ onClick: handleClick
135
+ }))
136
+ });
137
+ }
138
+ return /* @__PURE__ */ jsxRuntime.jsx("a", __spreadProps(__spreadValues({}, restOfProps), {
139
+ ref,
121
140
  href,
122
- children: /* @__PURE__ */ jsxRuntime.jsx("a", __spreadProps(__spreadValues({}, restOfProps), {
123
- ref,
124
- target,
125
- onClick: handleClick
126
- }))
127
- });
141
+ target,
142
+ onClick: handleClick
143
+ }));
128
144
  });
129
145
  exports.Link = Link;
130
146
  //# sourceMappingURL=index.cjs3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs3.js","sources":["../src/components/shared/Link/index.tsx"],"sourcesContent":["import { ComponentPropsWithoutRef, forwardRef, MouseEvent } from 'react'\nimport scrollIntoView from 'scroll-into-view-if-needed'\nimport NextLink from 'next/link'\n\nimport { LinkValue as LinkPropControllerValue } from '../../../prop-controllers/descriptors'\nimport { usePage } from '../../hooks'\nimport { useElementId } from '../../../runtimes/react'\n\ntype BaseProps = {\n link?: LinkPropControllerValue\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype Props = BaseProps & Omit<ComponentPropsWithoutRef<'a'>, keyof BaseProps>\n\nexport const Link = forwardRef<HTMLAnchorElement, Props>(function Link(\n { link, onClick = () => {}, ...restOfProps }: Props,\n ref,\n) {\n const page = usePage(link && link.type === 'OPEN_PAGE' ? link.payload.pageId : null)\n const elementKey =\n link?.type === 'SCROLL_TO_ELEMENT' ? link.payload.elementIdConfig?.elementKey : null\n const elementId = useElementId(elementKey)\n\n let href = '#'\n let target: '_blank' | '_self' | undefined\n let block: 'start' | 'center' | 'end' | undefined\n\n if (link) {\n switch (link.type) {\n case 'OPEN_PAGE': {\n if (page) href = `/${page.pathname}`\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'OPEN_URL': {\n href = link.payload.url\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'SEND_EMAIL': {\n const { to, subject = '', body = '' } = link.payload\n\n if (to != null) href = `mailto:${to}?subject=${subject}&body=${body}`\n\n break\n }\n\n case 'CALL_PHONE': {\n href = `tel:${link.payload.phoneNumber}`\n\n break\n }\n\n case 'SCROLL_TO_ELEMENT': {\n href = `#${elementId ?? ''}`\n block = link.payload.block\n\n break\n }\n\n default:\n throw new RangeError(`Invalid link type \"${(link as any).type}.\"`)\n }\n }\n\n function handleClick(event: MouseEvent<HTMLAnchorElement>) {\n onClick(event)\n\n if (event.defaultPrevented) return\n\n /**\n * When we introduced `next/link` instead of just `a` element slate no longer prevented link from navigating within\n * content mode. This is a hack to compensate for what would be expected as slate's default behavior.\n * On upgrade of slate this can be reevaluated.\n */\n if (event.currentTarget.isContentEditable) return event.preventDefault()\n\n if (link && link.type === 'SCROLL_TO_ELEMENT') {\n let hash: string | undefined\n\n try {\n hash = new URL(`http://www.example.com/${href}`).hash\n } catch (error) {\n console.error(`Link received invalid href: ${href}`, error)\n }\n\n if (href != null && href === hash) {\n event.preventDefault()\n const view = event.view as unknown as Window\n\n scrollIntoView(view.document.querySelector(hash)!, {\n behavior: 'smooth',\n block,\n })\n\n if (view.location.hash !== hash) view.history.pushState({}, '', hash)\n }\n }\n }\n\n return (\n <NextLink href={href}>\n {/* eslint-disable-next-line */}\n <a {...restOfProps} ref={ref} target={target} onClick={handleClick} />\n </NextLink>\n )\n})\n"],"names":["Link","forwardRef","ref","link","onClick","restOfProps","page","usePage","type","payload","pageId","elementKey","elementIdConfig","elementId","useElementId","href","target","block","pathname","openInNewTab","url","to","subject","body","phoneNumber","RangeError","handleClick","event","defaultPrevented","currentTarget","isContentEditable","preventDefault","hash","URL","error","view","scrollIntoView","document","querySelector","behavior","location","history","pushState","NextLink"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeaA,MAAAA,OAAOC,MAAAA,WAAqC,eACvD,IACAC,KACA;AAFA,eAAEC;AAAAA;AAAAA,IAAMC,UAAU,MAAM;AAAA,IAAE;AAAA,MAA1B,IAA+BC,wBAA/B,IAA+BA;AAAAA,IAA7BF;AAAAA,IAAMC;AAAAA;;AAGFE,QAAAA,OAAOC,KAAAA,QAAQJ,QAAQA,KAAKK,SAAS,cAAcL,KAAKM,QAAQC,SAAS,IAA3D;AACpB,QAAMC,aACJR,8BAAMK,UAAS,sBAAsBL,YAAKM,QAAQG,oBAAbT,oBAA8BQ,aAAa;AAC5EE,QAAAA,YAAYC,kBAAaH,UAAD;AAE1BI,MAAAA,OAAO;AACPC,MAAAA;AACAC,MAAAA;AAEJ,MAAId,MAAM;AACAA,YAAAA,KAAKK;AAAAA,WACN,aAAa;AACZF,YAAAA;AAAMS,iBAAQ,IAAGT,KAAKY;AAEjBf,iBAAAA,KAAKM,QAAQU,eAAe,WAAW;AAEhD;AAAA,MACD;AAAA,WAEI,YAAY;AACfJ,eAAOZ,KAAKM,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;AAAAA,IAAAA,EAAvD;AAAA,EAAA,CAHJ;AAMD,CAlG6B;;"}
1
+ {"version":3,"file":"index.cjs3.js","sources":["../src/components/shared/Link/index.tsx"],"sourcesContent":["import { ComponentPropsWithoutRef, forwardRef, MouseEvent } from 'react'\nimport scrollIntoView from 'scroll-into-view-if-needed'\nimport NextLink from 'next/link'\n\nimport { LinkValue as LinkPropControllerValue } from '../../../prop-controllers/descriptors'\nimport { usePage } from '../../hooks'\nimport { useElementId } from '../../../runtimes/react'\n\ntype BaseProps = {\n link?: LinkPropControllerValue\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype Props = BaseProps & Omit<ComponentPropsWithoutRef<'a'>, keyof BaseProps>\n\nexport const Link = forwardRef<HTMLAnchorElement, Props>(function Link(\n { link, onClick = () => {}, ...restOfProps }: Props,\n ref,\n) {\n const page = usePage(link && link.type === 'OPEN_PAGE' ? link.payload.pageId : null)\n const elementKey =\n link?.type === 'SCROLL_TO_ELEMENT' ? link.payload.elementIdConfig?.elementKey : null\n const elementId = useElementId(elementKey)\n\n // We don't want to use `next/link` with relative paths because Next.js will attempt to normalize\n // it and mess up the path.\n let useNextLink: boolean | undefined\n let href: string | undefined\n let target: '_blank' | '_self' | undefined\n let block: 'start' | 'center' | 'end' | undefined\n\n if (link) {\n switch (link.type) {\n case 'OPEN_PAGE': {\n if (page) {\n useNextLink = true\n\n href = `/${page.pathname}`\n }\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'OPEN_URL': {\n useNextLink = true\n\n href = link.payload.url\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'SEND_EMAIL': {\n useNextLink = false\n\n const { to, subject = '', body = '' } = link.payload\n\n if (to != null) href = `mailto:${to}?subject=${subject}&body=${body}`\n\n break\n }\n\n case 'CALL_PHONE': {\n useNextLink = false\n\n href = `tel:${link.payload.phoneNumber}`\n\n break\n }\n\n case 'SCROLL_TO_ELEMENT': {\n useNextLink = false\n\n href = `#${elementId ?? ''}`\n\n block = link.payload.block\n\n break\n }\n\n default:\n throw new RangeError(`Invalid link type \"${(link as any).type}.\"`)\n }\n }\n\n function handleClick(event: MouseEvent<HTMLAnchorElement>) {\n onClick(event)\n\n if (event.defaultPrevented) return\n\n /**\n * When we introduced `next/link` instead of just `a` element slate no longer prevented link from navigating within\n * content mode. This is a hack to compensate for what would be expected as slate's default behavior.\n * On upgrade of slate this can be reevaluated.\n */\n if (event.currentTarget.isContentEditable) return event.preventDefault()\n\n if (link && link.type === 'SCROLL_TO_ELEMENT') {\n let hash: string | undefined\n\n try {\n if (href != null) hash = new URL(`http://www.example.com/${href}`).hash\n } catch (error) {\n console.error(`Link received invalid href: ${href}`, error)\n }\n\n if (href != null && hash != null && href === hash) {\n event.preventDefault()\n const view = event.view as unknown as Window\n\n scrollIntoView(view.document.querySelector(hash)!, {\n behavior: 'smooth',\n block,\n })\n\n if (view.location.hash !== hash) view.history.pushState({}, '', hash)\n }\n }\n }\n\n if (useNextLink && href != null) {\n return (\n <NextLink href={href}>\n {/* eslint-disable-next-line */}\n <a {...restOfProps} ref={ref} target={target} onClick={handleClick} />\n </NextLink>\n )\n }\n\n // eslint-disable-next-line\n return <a {...restOfProps} ref={ref} href={href} target={target} onClick={handleClick} />\n})\n"],"names":["Link","forwardRef","ref","link","onClick","restOfProps","page","usePage","type","payload","pageId","elementKey","elementIdConfig","elementId","useElementId","useNextLink","href","target","block","pathname","openInNewTab","url","to","subject","body","phoneNumber","RangeError","handleClick","event","defaultPrevented","currentTarget","isContentEditable","preventDefault","hash","URL","error","view","scrollIntoView","document","querySelector","behavior","location","history","pushState","NextLink"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeaA,MAAAA,OAAOC,MAAAA,WAAqC,eACvD,IACAC,KACA;AAFA,eAAEC;AAAAA;AAAAA,IAAMC,UAAU,MAAM;AAAA,IAAE;AAAA,MAA1B,IAA+BC,wBAA/B,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,QAAQA,KAAKK,SAAS,qBAAqB;AACzCyB,UAAAA;AAEA,UAAA;AACF,YAAIjB,QAAQ;AAAMiB,iBAAO,IAAIC,IAAK,0BAAyBlB,MAAlC,EAA0CiB;AAAAA,eAC5DE;AACCA,gBAAAA,MAAO,+BAA8BnB,QAAQmB,KAArD;AAAA,MACD;AAEGnB,UAAAA,QAAQ,QAAQiB,QAAQ,QAAQjB,SAASiB,MAAM;AACjDL,cAAMI,eAAN;AACMI,cAAAA,OAAOR,MAAMQ;AAEnBC,gCAAAA,WAAeD,KAAKE,SAASC,cAAcN,IAA5B,GAAoC;AAAA,UACjDO,UAAU;AAAA,UACVtB;AAAAA,QAAAA,CAFY;AAKVkB,YAAAA,KAAKK,SAASR,SAASA;AAAMG,eAAKM,QAAQC,UAAU,IAAI,IAAIV,IAA/B;AAAA,MAClC;AAAA,IACF;AAAA,EACF;AAEGlB,MAAAA,eAAeC,QAAQ,MAAM;AAC/B,0CACG4B,kBAAAA,YAAD;AAAA,MAAU;AAAA,MAAV,+EAESvC;QAAa;AAAA,QAAU;AAAA,QAAgB,SAASsB;AAAAA,MAAAA,EAAvD;AAAA,IAAA,CAHJ;AAAA,EAMD;AAGD,8EAActB;IAAa;AAAA,IAAU;AAAA,IAAY;AAAA,IAAgB,SAASsB;AAAAA,EAAAA,EAA1E;AACD,CAvH6B;;"}
package/dist/index.es3.js CHANGED
@@ -47,23 +47,28 @@ const Link = forwardRef(function Link2(_a, ref) {
47
47
  const page = usePage(link && link.type === "OPEN_PAGE" ? link.payload.pageId : null);
48
48
  const elementKey = (link == null ? void 0 : link.type) === "SCROLL_TO_ELEMENT" ? (_a2 = link.payload.elementIdConfig) == null ? void 0 : _a2.elementKey : null;
49
49
  const elementId = useElementId(elementKey);
50
- let href = "#";
50
+ let useNextLink;
51
+ let href;
51
52
  let target;
52
53
  let block;
53
54
  if (link) {
54
55
  switch (link.type) {
55
56
  case "OPEN_PAGE": {
56
- if (page)
57
+ if (page) {
58
+ useNextLink = true;
57
59
  href = `/${page.pathname}`;
60
+ }
58
61
  target = link.payload.openInNewTab ? "_blank" : "_self";
59
62
  break;
60
63
  }
61
64
  case "OPEN_URL": {
65
+ useNextLink = true;
62
66
  href = link.payload.url;
63
67
  target = link.payload.openInNewTab ? "_blank" : "_self";
64
68
  break;
65
69
  }
66
70
  case "SEND_EMAIL": {
71
+ useNextLink = false;
67
72
  const {
68
73
  to,
69
74
  subject = "",
@@ -74,10 +79,12 @@ const Link = forwardRef(function Link2(_a, ref) {
74
79
  break;
75
80
  }
76
81
  case "CALL_PHONE": {
82
+ useNextLink = false;
77
83
  href = `tel:${link.payload.phoneNumber}`;
78
84
  break;
79
85
  }
80
86
  case "SCROLL_TO_ELEMENT": {
87
+ useNextLink = false;
81
88
  href = `#${elementId != null ? elementId : ""}`;
82
89
  block = link.payload.block;
83
90
  break;
@@ -95,11 +102,12 @@ const Link = forwardRef(function Link2(_a, ref) {
95
102
  if (link && link.type === "SCROLL_TO_ELEMENT") {
96
103
  let hash;
97
104
  try {
98
- hash = new URL(`http://www.example.com/${href}`).hash;
105
+ if (href != null)
106
+ hash = new URL(`http://www.example.com/${href}`).hash;
99
107
  } catch (error) {
100
108
  console.error(`Link received invalid href: ${href}`, error);
101
109
  }
102
- if (href != null && href === hash) {
110
+ if (href != null && hash != null && href === hash) {
103
111
  event.preventDefault();
104
112
  const view = event.view;
105
113
  scrollIntoView(view.document.querySelector(hash), {
@@ -111,14 +119,22 @@ const Link = forwardRef(function Link2(_a, ref) {
111
119
  }
112
120
  }
113
121
  }
114
- return /* @__PURE__ */ jsx(NextLink, {
122
+ if (useNextLink && href != null) {
123
+ return /* @__PURE__ */ jsx(NextLink, {
124
+ href,
125
+ children: /* @__PURE__ */ jsx("a", __spreadProps(__spreadValues({}, restOfProps), {
126
+ ref,
127
+ target,
128
+ onClick: handleClick
129
+ }))
130
+ });
131
+ }
132
+ return /* @__PURE__ */ jsx("a", __spreadProps(__spreadValues({}, restOfProps), {
133
+ ref,
115
134
  href,
116
- children: /* @__PURE__ */ jsx("a", __spreadProps(__spreadValues({}, restOfProps), {
117
- ref,
118
- target,
119
- onClick: handleClick
120
- }))
121
- });
135
+ target,
136
+ onClick: handleClick
137
+ }));
122
138
  });
123
139
  export { Link as L };
124
140
  //# sourceMappingURL=index.es3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es3.js","sources":["../src/components/shared/Link/index.tsx"],"sourcesContent":["import { ComponentPropsWithoutRef, forwardRef, MouseEvent } from 'react'\nimport scrollIntoView from 'scroll-into-view-if-needed'\nimport NextLink from 'next/link'\n\nimport { LinkValue as LinkPropControllerValue } from '../../../prop-controllers/descriptors'\nimport { usePage } from '../../hooks'\nimport { useElementId } from '../../../runtimes/react'\n\ntype BaseProps = {\n link?: LinkPropControllerValue\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype Props = BaseProps & Omit<ComponentPropsWithoutRef<'a'>, keyof BaseProps>\n\nexport const Link = forwardRef<HTMLAnchorElement, Props>(function Link(\n { link, onClick = () => {}, ...restOfProps }: Props,\n ref,\n) {\n const page = usePage(link && link.type === 'OPEN_PAGE' ? link.payload.pageId : null)\n const elementKey =\n link?.type === 'SCROLL_TO_ELEMENT' ? link.payload.elementIdConfig?.elementKey : null\n const elementId = useElementId(elementKey)\n\n let href = '#'\n let target: '_blank' | '_self' | undefined\n let block: 'start' | 'center' | 'end' | undefined\n\n if (link) {\n switch (link.type) {\n case 'OPEN_PAGE': {\n if (page) href = `/${page.pathname}`\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'OPEN_URL': {\n href = link.payload.url\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'SEND_EMAIL': {\n const { to, subject = '', body = '' } = link.payload\n\n if (to != null) href = `mailto:${to}?subject=${subject}&body=${body}`\n\n break\n }\n\n case 'CALL_PHONE': {\n href = `tel:${link.payload.phoneNumber}`\n\n break\n }\n\n case 'SCROLL_TO_ELEMENT': {\n href = `#${elementId ?? ''}`\n block = link.payload.block\n\n break\n }\n\n default:\n throw new RangeError(`Invalid link type \"${(link as any).type}.\"`)\n }\n }\n\n function handleClick(event: MouseEvent<HTMLAnchorElement>) {\n onClick(event)\n\n if (event.defaultPrevented) return\n\n /**\n * When we introduced `next/link` instead of just `a` element slate no longer prevented link from navigating within\n * content mode. This is a hack to compensate for what would be expected as slate's default behavior.\n * On upgrade of slate this can be reevaluated.\n */\n if (event.currentTarget.isContentEditable) return event.preventDefault()\n\n if (link && link.type === 'SCROLL_TO_ELEMENT') {\n let hash: string | undefined\n\n try {\n hash = new URL(`http://www.example.com/${href}`).hash\n } catch (error) {\n console.error(`Link received invalid href: ${href}`, error)\n }\n\n if (href != null && href === hash) {\n event.preventDefault()\n const view = event.view as unknown as Window\n\n scrollIntoView(view.document.querySelector(hash)!, {\n behavior: 'smooth',\n block,\n })\n\n if (view.location.hash !== hash) view.history.pushState({}, '', hash)\n }\n }\n }\n\n return (\n <NextLink href={href}>\n {/* eslint-disable-next-line */}\n <a {...restOfProps} ref={ref} target={target} onClick={handleClick} />\n </NextLink>\n )\n})\n"],"names":["Link","forwardRef","ref","link","onClick","restOfProps","page","usePage","type","payload","pageId","elementKey","elementIdConfig","elementId","useElementId","href","target","block","pathname","openInNewTab","url","to","subject","body","phoneNumber","RangeError","handleClick","event","defaultPrevented","currentTarget","isContentEditable","preventDefault","hash","URL","error","view","scrollIntoView","document","querySelector","behavior","location","history","pushState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeaA,MAAAA,OAAOC,WAAqC,eACvD,IACAC,KACA;AAFA,eAAEC;AAAAA;AAAAA,IAAMC,UAAU,MAAM;AAAA,IAAE;AAAA,MAA1B,IAA+BC,wBAA/B,IAA+BA;AAAAA,IAA7BF;AAAAA,IAAMC;AAAAA;;AAGFE,QAAAA,OAAOC,QAAQJ,QAAQA,KAAKK,SAAS,cAAcL,KAAKM,QAAQC,SAAS,IAA3D;AAC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,cAAMI,eAAN;AACMI,cAAAA,OAAOR,MAAMQ;AAEnBC,uBAAeD,KAAKE,SAASC,cAAcN,IAA5B,GAAoC;AAAA,UACjDO,UAAU;AAAA,UACVtB;AAAAA,QAAAA,CAFY;AAKVkB,YAAAA,KAAKK,SAASR,SAASA;AAAMG,eAAKM,QAAQC,UAAU,IAAI,IAAIV,IAA/B;AAAA,MAClC;AAAA,IACF;AAAA,EACF;AAED,6BACG,UAAD;AAAA,IAAU;AAAA,IAAV,oEAES3B;MAAa;AAAA,MAAU;AAAA,MAAgB,SAASqB;AAAAA,IAAAA,EAAvD;AAAA,EAAA,CAHJ;AAMD,CAlG6B;;"}
1
+ {"version":3,"file":"index.es3.js","sources":["../src/components/shared/Link/index.tsx"],"sourcesContent":["import { ComponentPropsWithoutRef, forwardRef, MouseEvent } from 'react'\nimport scrollIntoView from 'scroll-into-view-if-needed'\nimport NextLink from 'next/link'\n\nimport { LinkValue as LinkPropControllerValue } from '../../../prop-controllers/descriptors'\nimport { usePage } from '../../hooks'\nimport { useElementId } from '../../../runtimes/react'\n\ntype BaseProps = {\n link?: LinkPropControllerValue\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype Props = BaseProps & Omit<ComponentPropsWithoutRef<'a'>, keyof BaseProps>\n\nexport const Link = forwardRef<HTMLAnchorElement, Props>(function Link(\n { link, onClick = () => {}, ...restOfProps }: Props,\n ref,\n) {\n const page = usePage(link && link.type === 'OPEN_PAGE' ? link.payload.pageId : null)\n const elementKey =\n link?.type === 'SCROLL_TO_ELEMENT' ? link.payload.elementIdConfig?.elementKey : null\n const elementId = useElementId(elementKey)\n\n // We don't want to use `next/link` with relative paths because Next.js will attempt to normalize\n // it and mess up the path.\n let useNextLink: boolean | undefined\n let href: string | undefined\n let target: '_blank' | '_self' | undefined\n let block: 'start' | 'center' | 'end' | undefined\n\n if (link) {\n switch (link.type) {\n case 'OPEN_PAGE': {\n if (page) {\n useNextLink = true\n\n href = `/${page.pathname}`\n }\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'OPEN_URL': {\n useNextLink = true\n\n href = link.payload.url\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'SEND_EMAIL': {\n useNextLink = false\n\n const { to, subject = '', body = '' } = link.payload\n\n if (to != null) href = `mailto:${to}?subject=${subject}&body=${body}`\n\n break\n }\n\n case 'CALL_PHONE': {\n useNextLink = false\n\n href = `tel:${link.payload.phoneNumber}`\n\n break\n }\n\n case 'SCROLL_TO_ELEMENT': {\n useNextLink = false\n\n href = `#${elementId ?? ''}`\n\n block = link.payload.block\n\n break\n }\n\n default:\n throw new RangeError(`Invalid link type \"${(link as any).type}.\"`)\n }\n }\n\n function handleClick(event: MouseEvent<HTMLAnchorElement>) {\n onClick(event)\n\n if (event.defaultPrevented) return\n\n /**\n * When we introduced `next/link` instead of just `a` element slate no longer prevented link from navigating within\n * content mode. This is a hack to compensate for what would be expected as slate's default behavior.\n * On upgrade of slate this can be reevaluated.\n */\n if (event.currentTarget.isContentEditable) return event.preventDefault()\n\n if (link && link.type === 'SCROLL_TO_ELEMENT') {\n let hash: string | undefined\n\n try {\n if (href != null) hash = new URL(`http://www.example.com/${href}`).hash\n } catch (error) {\n console.error(`Link received invalid href: ${href}`, error)\n }\n\n if (href != null && hash != null && href === hash) {\n event.preventDefault()\n const view = event.view as unknown as Window\n\n scrollIntoView(view.document.querySelector(hash)!, {\n behavior: 'smooth',\n block,\n })\n\n if (view.location.hash !== hash) view.history.pushState({}, '', hash)\n }\n }\n }\n\n if (useNextLink && href != null) {\n return (\n <NextLink href={href}>\n {/* eslint-disable-next-line */}\n <a {...restOfProps} ref={ref} target={target} onClick={handleClick} />\n </NextLink>\n )\n }\n\n // eslint-disable-next-line\n return <a {...restOfProps} ref={ref} href={href} target={target} onClick={handleClick} />\n})\n"],"names":["Link","forwardRef","ref","link","onClick","restOfProps","page","usePage","type","payload","pageId","elementKey","elementIdConfig","elementId","useElementId","useNextLink","href","target","block","pathname","openInNewTab","url","to","subject","body","phoneNumber","RangeError","handleClick","event","defaultPrevented","currentTarget","isContentEditable","preventDefault","hash","URL","error","view","scrollIntoView","document","querySelector","behavior","location","history","pushState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeaA,MAAAA,OAAOC,WAAqC,eACvD,IACAC,KACA;AAFA,eAAEC;AAAAA;AAAAA,IAAMC,UAAU,MAAM;AAAA,IAAE;AAAA,MAA1B,IAA+BC,wBAA/B,IAA+BA;AAAAA,IAA7BF;AAAAA,IAAMC;AAAAA;;AAGFE,QAAAA,OAAOC,QAAQJ,QAAQA,KAAKK,SAAS,cAAcL,KAAKM,QAAQC,SAAS,IAA3D;AACpB,QAAMC,aACJR,8BAAMK,UAAS,sBAAsBL,YAAKM,QAAQG,oBAAbT,oBAA8BQ,aAAa;AAC5EE,QAAAA,YAAYC,aAAaH,UAAD;AAI1BI,MAAAA;AACAC,MAAAA;AACAC,MAAAA;AACAC,MAAAA;AAEJ,MAAIf,MAAM;AACAA,YAAAA,KAAKK;AAAAA,WACN,aAAa;AAChB,YAAIF,MAAM;AACM,wBAAA;AAEdU,iBAAQ,IAAGV,KAAKa;AAAAA,QACjB;AAEQhB,iBAAAA,KAAKM,QAAQW,eAAe,WAAW;AAEhD;AAAA,MACD;AAAA,WAEI,YAAY;AACD,sBAAA;AAEdJ,eAAOb,KAAKM,QAAQY;AAEXlB,iBAAAA,KAAKM,QAAQW,eAAe,WAAW;AAEhD;AAAA,MACD;AAAA,WAEI,cAAc;AACH,sBAAA;AAER,cAAA;AAAA,UAAEE;AAAAA,UAAIC,UAAU;AAAA,UAAIC,OAAO;AAAA,YAAOrB,KAAKM;AAE7C,YAAIa,MAAM;AAAc,iBAAA,UAASA,cAAcC,gBAAgBC;AAE/D;AAAA,MACD;AAAA,WAEI,cAAc;AACH,sBAAA;AAEN,eAAA,OAAMrB,KAAKM,QAAQgB;AAE3B;AAAA,MACD;AAAA,WAEI,qBAAqB;AACV,sBAAA;AAEdT,eAAQ,IAAGH,gCAAa;AAExBK,gBAAQf,KAAKM,QAAQS;AAErB;AAAA,MACD;AAAA;AAGO,cAAA,IAAIQ,WAAY,sBAAsBvB,KAAaK,QAAnD;AAAA;AAAA,EAEX;AAEQmB,uBAAYC,OAAsC;AACzDxB,YAAQwB,KAAD;AAEHA,QAAAA,MAAMC;AAAkB;AAOxBD,QAAAA,MAAME,cAAcC;AAAmB,aAAOH,MAAMI;AAEpD7B,QAAAA,QAAQA,KAAKK,SAAS,qBAAqB;AACzCyB,UAAAA;AAEA,UAAA;AACF,YAAIjB,QAAQ;AAAMiB,iBAAO,IAAIC,IAAK,0BAAyBlB,MAAlC,EAA0CiB;AAAAA,eAC5DE;AACCA,gBAAAA,MAAO,+BAA8BnB,QAAQmB,KAArD;AAAA,MACD;AAEGnB,UAAAA,QAAQ,QAAQiB,QAAQ,QAAQjB,SAASiB,MAAM;AACjDL,cAAMI,eAAN;AACMI,cAAAA,OAAOR,MAAMQ;AAEnBC,uBAAeD,KAAKE,SAASC,cAAcN,IAA5B,GAAoC;AAAA,UACjDO,UAAU;AAAA,UACVtB;AAAAA,QAAAA,CAFY;AAKVkB,YAAAA,KAAKK,SAASR,SAASA;AAAMG,eAAKM,QAAQC,UAAU,IAAI,IAAIV,IAA/B;AAAA,MAClC;AAAA,IACF;AAAA,EACF;AAEGlB,MAAAA,eAAeC,QAAQ,MAAM;AAC/B,+BACG,UAAD;AAAA,MAAU;AAAA,MAAV,oEAESX;QAAa;AAAA,QAAU;AAAA,QAAgB,SAASsB;AAAAA,MAAAA,EAAvD;AAAA,IAAA,CAHJ;AAAA,EAMD;AAGD,mEAActB;IAAa;AAAA,IAAU;AAAA,IAAY;AAAA,IAAgB,SAASsB;AAAAA,EAAAA,EAA1E;AACD,CAvH6B;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/components/builtin/Text/components/RichTextEditor/index.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,aAAa,CAAA;AAWnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAI3D,eAAO,MAAM,cAAc,sPAyB1B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/components/builtin/Text/components/RichTextEditor/index.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,aAAa,CAAA;AAWnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAI3D,eAAO,MAAM,cAAc,sPA6B1B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/shared/Link/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwC,UAAU,EAAE,MAAM,OAAO,CAAA;AAIxE,OAAO,EAAE,SAAS,IAAI,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AAI5F,aAAK,SAAS,GAAG;IACf,IAAI,CAAC,EAAE,uBAAuB,CAAA;IAC9B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAA;CAC5D,CAAA;AAID,eAAO,MAAM,IAAI,6TAkGf,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/shared/Link/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwC,UAAU,EAAE,MAAM,OAAO,CAAA;AAIxE,OAAO,EAAE,SAAS,IAAI,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AAI5F,aAAK,SAAS,GAAG;IACf,IAAI,CAAC,EAAE,uBAAuB,CAAA;IAC9B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAA;CAC5D,CAAA;AAID,eAAO,MAAM,IAAI,6TAuHf,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makeswift/runtime",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "license": "MIT",
5
5
  "main": "dist/main.cjs",
6
6
  "module": "dist/main.es",