@makeswift/runtime 0.0.0-20221025192145 → 0.0.0-20221110161746

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
@@ -459,10 +459,11 @@ const Text = React.forwardRef(function Text2({
459
459
  }
460
460
  return next2();
461
461
  }, []);
462
- const handleBlur = React.useCallback((event, _editor, next2) => {
462
+ const handleBlur = React.useCallback((event, editor2, next2) => {
463
+ const selection = editor2.value.selection;
464
+ next2();
463
465
  if (event.relatedTarget == null)
464
- return true;
465
- return next2();
466
+ editor2.select(selection);
466
467
  }, []);
467
468
  const isInBuilder = next.useIsInBuilder();
468
469
  return /* @__PURE__ */ jsxRuntime.jsx(StyledRichTextEditor, {
@@ -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 // 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,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,CAAC;AAAA,EAET;AAAA;AAEW,MAAA,0BAA0B,CACrC,QACA,aAC6B;AAC7B,QAAM,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,IAAI,WAAW,EAAE,OAAO,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S;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 const selection = editor.value.selection\n\n next()\n\n // Normally, after a user highlight a text, clicking on the panel will remove the text selection.\n // This line is a workaround for that. Because the panel is not in the iframe, relatedTarget\n // would be null, and we select the previous text selection to maintain the text highlight.\n // Inspiration: https://github.com/ianstormtaylor/slate/issues/3412#issuecomment-663906003\n if (event.relatedTarget == null) editor.select(selection)\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <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","select","isInBuilder","useIsInBuilder","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,uBACL,cAC+B;AAC/B,QAAM,EAAE,OAAO,SAASA,KAAAA,SAASC,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F4B,CAAA;AAG/B,QAAMC,gBAAgBF,MAAAA,YACpB,CAACG,OAA2BxF,SAAiBC,UAAoB;;AAC3DwF,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,WAAO9F,MAAP;AAAA,EApB6B,GAsB/B,CAtB+B,CAAA;AAwBjC,QAAM+F,aAAaX,MAAAA,YAAY,CAACG,OAAwBvC,SAAgBhD,UAAoB;AACpF+D,UAAAA,YAAYf,QAAO7D,MAAM4E;;AAQ3BwB,QAAAA,MAAMS,iBAAiB;AAAMhD,cAAOiD,OAAOlC,SAAd;AAAA,EATL,GAU3B,CAV2B,CAAA;AAYxBmC,QAAAA,cAAcC,KAAAA;AAGlB,wCAAC,sBAAD;AAAA,IAEE;AAAA,IACA,KAAKlD;AAAAA,IACL;AAAA,IACA,UAAU,CAACiD;AAAAA,IACX;AAAA,IACA;AAAA,IACA,UAAUE;AAAAA,IACV,SAASjB;AAAAA,IACT,WAAWG;AAAAA,IACX,QAAQS;AAAAA,EAAAA,CAZZ;AAeD,CAhJsB;;"}
package/dist/Text.es.js CHANGED
@@ -451,10 +451,11 @@ const Text = forwardRef(function Text2({
451
451
  }
452
452
  return next();
453
453
  }, []);
454
- const handleBlur = useCallback((event, _editor, next) => {
454
+ const handleBlur = useCallback((event, editor2, next) => {
455
+ const selection = editor2.value.selection;
456
+ next();
455
457
  if (event.relatedTarget == null)
456
- return true;
457
- return next();
458
+ editor2.select(selection);
458
459
  }, []);
459
460
  const isInBuilder = useIsInBuilder();
460
461
  return /* @__PURE__ */ jsx(StyledRichTextEditor, {
@@ -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 // 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,QAA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AAfF,mBAAwBc;AAEjB,aAAA;AAAA,IACR;AAED,WAAO9F,KAAP;AAAA,EApB6B,GAsB/B,CAtB+B,CAAA;AAwBjC,QAAM+F,aAAaX,YAAY,CAACG,OAAwBxF,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;;"}
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 const selection = editor.value.selection\n\n next()\n\n // Normally, after a user highlight a text, clicking on the panel will remove the text selection.\n // This line is a workaround for that. Because the panel is not in the iframe, relatedTarget\n // would be null, and we select the previous text selection to maintain the text highlight.\n // Inspiration: https://github.com/ianstormtaylor/slate/issues/3412#issuecomment-663906003\n if (event.relatedTarget == null) editor.select(selection)\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <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","select","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,CAAC;AAAA,EAET;AAAA;AAEW,MAAA,0BAA0B,CACrC,QACA,aAC6B;AAC7B,QAAM,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,IAAI,WAAW,EAAE,OAAO,S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tB;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,OAA2BxF,SAAiBC,SAAoB;;AAC3DwF,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,WAAO9F,KAAP;AAAA,EApB6B,GAsB/B,CAtB+B,CAAA;AAwBjC,QAAM+F,aAAaX,YAAY,CAACG,OAAwBvC,SAAgBhD,SAAoB;AACpF+D,UAAAA,YAAYf,QAAO7D,MAAM4E;;AAQ3BwB,QAAAA,MAAMS,iBAAiB;AAAMhD,cAAOiD,OAAOlC,SAAd;AAAA,EATL,GAU3B,CAV2B,CAAA;AAYxBmC,QAAAA,cAAcC;AAGlB,6BAAC,sBAAD;AAAA,IAEE;AAAA,IACA,KAAKlD;AAAAA,IACL;AAAA,IACA,UAAU,CAACiD;AAAAA,IACX;AAAA,IACA;AAAA,IACA,UAAUE;AAAAA,IACV,SAASjB;AAAAA,IACT,WAAWG;AAAAA,IACX,QAAQS;AAAAA,EAAAA,CAZZ;AAeD,CAhJsB;;"}
package/dist/index.cjs.js CHANGED
@@ -1002,16 +1002,25 @@ class Document$1 extends NextDocument__default["default"] {
1002
1002
  });
1003
1003
  }
1004
1004
  }
1005
- const version = "0.0.0-20221025192145";
1005
+ const version = "0.0.0-20221110161746";
1006
+ function isErrorWithMessage(error) {
1007
+ return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
1008
+ }
1006
1009
  function MakeswiftApiHandler(apiKey, { appOrigin = "https://app.makeswift.com", getFonts } = {}) {
1007
1010
  const cors = Cors__default["default"]({ origin: appOrigin });
1008
1011
  const previewModeProxy = httpProxy.createProxyServer();
1012
+ previewModeProxy.on("proxyReq", (proxyReq) => {
1013
+ proxyReq.removeHeader("X-Makeswift-Preview-Mode");
1014
+ const url = new URL(proxyReq.path, "http://n");
1015
+ url.searchParams.delete("x-makeswift-preview-mode");
1016
+ proxyReq.path = url.pathname + url.search;
1017
+ });
1009
1018
  if (typeof apiKey !== "string") {
1010
1019
  throw new Error(`The Makeswift Next.js API handler must be passed a valid Makeswift site API key: \`MakeswiftApiHandler('<makeswift_site_api_key>')\`
1011
1020
  Received "${apiKey}" instead.`);
1012
1021
  }
1013
1022
  return async function makeswiftApiHandler(req, res) {
1014
- var _a, _b, _c;
1023
+ var _a, _b;
1015
1024
  await new Promise((resolve2, reject) => {
1016
1025
  cors(req, res, (err) => {
1017
1026
  if (err instanceof Error)
@@ -1054,6 +1063,9 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1054
1063
  await revalidate(req.query.path);
1055
1064
  return res.json({ revalidated: true });
1056
1065
  } catch (error) {
1066
+ if (isErrorWithMessage(error)) {
1067
+ return res.status(500).json({ message: error.message });
1068
+ }
1057
1069
  return res.status(500).json({ message: "Error Revalidating" });
1058
1070
  }
1059
1071
  }
@@ -1064,22 +1076,22 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1064
1076
  if (host == null)
1065
1077
  return res.status(400).send("Bad Request");
1066
1078
  const forwardedProto = req.headers["x-forwarded-proto"];
1067
- const proto = typeof forwardedProto === "string" ? forwardedProto : "http";
1079
+ const isForwardedProtoHttps = typeof forwardedProto === "string" && forwardedProto === "https";
1080
+ const forwardedSSL = req.headers["x-forwarded-ssl"];
1081
+ const isForwardedSSL = typeof forwardedSSL === "string" && forwardedSSL === "on";
1082
+ const proto = isForwardedProtoHttps || isForwardedSSL ? "https" : "http";
1068
1083
  let target = `${proto}://${host}`;
1069
1084
  if (process.env["NODE_ENV"] !== "production") {
1070
1085
  const port = req.socket.localPort;
1071
1086
  if (port != null)
1072
1087
  target = `http://localhost:${port}`;
1073
1088
  }
1074
- const url = new URL((_b = req.url) != null ? _b : "/", "http://n");
1075
- url.searchParams.delete("x-makeswift-preview-mode");
1076
- req.url = url.pathname + url.search;
1077
1089
  const setCookie = res.setPreviewData({ makeswift: true }).getHeader("Set-Cookie");
1078
1090
  res.removeHeader("Set-Cookie");
1079
1091
  if (!Array.isArray(setCookie))
1080
1092
  return res.status(500).send("Internal Server Error");
1081
1093
  const cookie$1 = setCookieParser.parse(setCookie).map((cookie2) => cookie.serialize(cookie2.name, cookie2.value, cookie2)).join(";");
1082
- return await new Promise((resolve2, reject) => previewModeProxy.web(req, res, { target, headers: { cookie: cookie$1 }, followRedirects: true }, (err) => {
1094
+ return await new Promise((resolve2, reject) => previewModeProxy.web(req, res, { target, headers: { cookie: cookie$1 } }, (err) => {
1083
1095
  if (err)
1084
1096
  reject(err);
1085
1097
  else
@@ -1087,7 +1099,7 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1087
1099
  }));
1088
1100
  }
1089
1101
  case "fonts": {
1090
- const fonts = (_c = await (getFonts == null ? void 0 : getFonts())) != null ? _c : [];
1102
+ const fonts = (_b = await (getFonts == null ? void 0 : getFonts())) != null ? _b : [];
1091
1103
  return res.json(fonts);
1092
1104
  }
1093
1105
  default: