@payloadcms/richtext-slate 3.29.0-internal.3471e81 → 3.29.0-internal.37e46b5
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/field/RichText.js +2 -2
- package/dist/field/RichText.js.map +1 -1
- package/dist/field/providers/ElementButtonProvider.js +2 -2
- package/dist/field/providers/ElementButtonProvider.js.map +1 -1
- package/dist/field/providers/ElementProvider.js +2 -2
- package/dist/field/providers/ElementProvider.js.map +1 -1
- package/dist/field/providers/LeafButtonProvider.js +2 -2
- package/dist/field/providers/LeafButtonProvider.js.map +1 -1
- package/dist/field/providers/LeafProvider.js +2 -2
- package/dist/field/providers/LeafProvider.js.map +1 -1
- package/dist/utilities/SlatePropsProvider.d.ts.map +1 -1
- package/dist/utilities/SlatePropsProvider.js +3 -3
- package/dist/utilities/SlatePropsProvider.js.map +1 -1
- package/package.json +5 -5
package/dist/field/RichText.js
CHANGED
|
@@ -46,11 +46,11 @@ const RichTextField = (props)=>{
|
|
|
46
46
|
required,
|
|
47
47
|
i18n
|
|
48
48
|
]);
|
|
49
|
-
const { customComponents: { Description, Error, Label } = {},
|
|
49
|
+
const { customComponents: { Description, Error, Label } = {}, formInitializing, initialValue, setValue, showError, value } = useField({
|
|
50
50
|
path,
|
|
51
51
|
validate: memoizedValidate
|
|
52
52
|
});
|
|
53
|
-
const disabled = readOnlyFromProps ||
|
|
53
|
+
const disabled = readOnlyFromProps || formInitializing;
|
|
54
54
|
const editor = useMemo(()=>{
|
|
55
55
|
let CreatedEditor = withEnterBreakOut(withHistory(withReact(createEditor())));
|
|
56
56
|
CreatedEditor = withHTML(CreatedEditor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/field/RichText.tsx"],"sourcesContent":["'use client'\n\nimport type { PayloadRequest } from 'payload'\nimport type { BaseEditor, BaseOperation } from 'slate'\nimport type { HistoryEditor } from 'slate-history'\nimport type { ReactEditor } from 'slate-react'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useEditDepth,\n useField,\n useTranslation,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport { isHotkey } from 'is-hotkey'\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react'\nimport { createEditor, Node, Element as SlateElement, Text, Transforms } from 'slate'\nimport { withHistory } from 'slate-history'\nimport { Editable, Slate, withReact } from 'slate-react'\n\nimport type { ElementNode, TextNode } from '../types.js'\nimport type { LoadedSlateFieldProps } from './types.js'\n\nimport { defaultRichTextValue } from '../data/defaultValue.js'\nimport { richTextValidate } from '../data/validation.js'\nimport { listTypes } from './elements/listTypes.js'\nimport './index.scss'\nimport { hotkeys } from './hotkeys.js'\nimport { toggleLeaf } from './leaves/toggle.js'\nimport { withEnterBreakOut } from './plugins/withEnterBreakOut.js'\nimport { withHTML } from './plugins/withHTML.js'\nimport { ElementButtonProvider } from './providers/ElementButtonProvider.js'\nimport { ElementProvider } from './providers/ElementProvider.js'\nimport { LeafButtonProvider } from './providers/LeafButtonProvider.js'\nimport { LeafProvider } from './providers/LeafProvider.js'\n\nconst baseClass = 'rich-text'\n\ndeclare module 'slate' {\n interface CustomTypes {\n Editor: BaseEditor & HistoryEditor & ReactEditor\n Element: ElementNode\n Text: TextNode\n }\n}\n\nconst RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {\n const {\n elements,\n field,\n field: {\n name,\n admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},\n label,\n required,\n },\n leaves,\n path: pathFromProps,\n plugins,\n readOnly: readOnlyFromTopLevelProps,\n schemaPath: schemaPathFromProps,\n validate = richTextValidate,\n } = props\n\n const path = pathFromProps ?? name\n const schemaPath = schemaPathFromProps ?? name\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const { i18n } = useTranslation()\n const editorRef = useRef(null)\n const toolbarRef = useRef(null)\n\n const drawerDepth = useEditDepth()\n const drawerIsOpen = drawerDepth > 1\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, {\n ...validationOptions,\n req: {\n t: i18n.t,\n } as PayloadRequest,\n required,\n })\n }\n },\n [validate, required, i18n],\n )\n\n const {\n customComponents: { Description, Error, Label } = {},\n disabled: disabledFromField,\n initialValue,\n setValue,\n showError,\n value,\n } = useField({\n path,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || disabledFromField\n\n const editor = useMemo(() => {\n let CreatedEditor = withEnterBreakOut(withHistory(withReact(createEditor())))\n\n CreatedEditor = withHTML(CreatedEditor)\n\n if (plugins.length) {\n CreatedEditor = plugins.reduce((editorWithPlugins, plugin) => {\n return plugin(editorWithPlugins)\n }, CreatedEditor)\n }\n\n return CreatedEditor\n }, [plugins])\n\n const renderElement = useCallback(\n ({ attributes, children, element }) => {\n // return <div {...attributes}>{children}</div>\n\n const matchedElement = elements[element.type]\n const Element = matchedElement?.Element\n\n let attr = { ...attributes }\n\n // this converts text alignment to margin when dealing with void elements\n if (element.textAlign) {\n if (element.type === 'relationship' || element.type === 'upload') {\n switch (element.textAlign) {\n case 'center':\n attr = { ...attr, style: { marginLeft: 'auto', marginRight: 'auto' } }\n break\n case 'left':\n attr = { ...attr, style: { marginRight: 'auto' } }\n break\n case 'right':\n attr = { ...attr, style: { marginLeft: 'auto' } }\n break\n default:\n attr = { ...attr, style: { textAlign: element.textAlign } }\n break\n }\n } else if (element.type === 'li') {\n switch (element.textAlign) {\n case 'center':\n attr = { ...attr, style: { listStylePosition: 'inside', textAlign: 'center' } }\n break\n case 'right':\n attr = { ...attr, style: { listStylePosition: 'inside', textAlign: 'right' } }\n break\n case 'left':\n default:\n attr = { ...attr, style: { listStylePosition: 'outside', textAlign: 'left' } }\n break\n }\n } else {\n attr = { ...attr, style: { textAlign: element.textAlign } }\n }\n }\n\n if (Element) {\n const el = (\n <ElementProvider\n attributes={attr}\n childNodes={children}\n editorRef={editorRef}\n element={element}\n fieldProps={props}\n path={path}\n schemaPath={schemaPath}\n >\n {Element}\n </ElementProvider>\n )\n\n return el\n }\n\n return <div {...attr}>{children}</div>\n },\n [elements, path, props, schemaPath],\n )\n\n const renderLeaf = useCallback(\n ({ attributes, children, leaf }) => {\n const matchedLeaves = Object.entries(leaves).filter(([leafName]) => leaf[leafName])\n\n if (matchedLeaves.length > 0) {\n return matchedLeaves.reduce(\n (result, [, leafConfig], i) => {\n if (leafConfig?.Leaf) {\n const Leaf = leafConfig.Leaf\n\n return (\n <LeafProvider\n attributes={attributes}\n editorRef={editorRef}\n fieldProps={props}\n key={i}\n leaf={leaf}\n path={path}\n result={result}\n schemaPath={schemaPath}\n >\n {Leaf}\n </LeafProvider>\n )\n }\n\n return result\n },\n <span {...attributes}>{children}</span>,\n )\n }\n\n return <span {...attributes}>{children}</span>\n },\n [path, props, schemaPath, leaves],\n )\n\n // All slate changes fire the onChange event\n // including selection changes\n // so we will filter the set_selection operations out\n // and only fire setValue when onChange is because of value\n const handleChange = useCallback(\n (val: unknown) => {\n const ops = editor?.operations.filter((o: BaseOperation) => {\n if (o) {\n return o.type !== 'set_selection'\n }\n return false\n })\n\n if (ops && Array.isArray(ops) && ops.length > 0) {\n if (!disabled && val !== defaultRichTextValue && val !== value) {\n setValue(val)\n }\n }\n },\n [editor?.operations, disabled, setValue, value],\n )\n\n useEffect(() => {\n function setClickableState(clickState: 'disabled' | 'enabled') {\n const selectors = 'button, a, [role=\"button\"]'\n const toolbarButtons: (HTMLAnchorElement | HTMLButtonElement)[] =\n toolbarRef.current?.querySelectorAll(selectors)\n\n ;(toolbarButtons || []).forEach((child) => {\n const isButton = child.tagName === 'BUTTON'\n const isDisabling = clickState === 'disabled'\n child.setAttribute('tabIndex', isDisabling ? '-1' : '0')\n if (isButton) {\n child.setAttribute('disabled', isDisabling ? 'disabled' : null)\n }\n })\n }\n\n if (disabled) {\n setClickableState('disabled')\n }\n\n return () => {\n if (disabled) {\n setClickableState('enabled')\n }\n }\n }, [disabled])\n\n // useEffect(() => {\n // // If there is a change to the initial value, we need to reset Slate history\n // // and clear selection because the old selection may no longer be valid\n // // as returned JSON may be modified in hooks and have a different shape\n // if (editor.selection) {\n // console.log('deselecting');\n // ReactEditor.deselect(editor);\n // }\n // }, [path, editor]);\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')\n\n let valueToRender = value\n\n if (typeof valueToRender === 'string') {\n try {\n const parsedJSON = JSON.parse(valueToRender)\n valueToRender = parsedJSON\n } catch (err) {\n valueToRender = null\n }\n }\n\n if (!valueToRender) {\n valueToRender = defaultRichTextValue\n }\n\n return (\n <div className={classes} style={styles}>\n {Label || <FieldLabel label={label} path={path} required={required} />}\n <div className={`${baseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n <Slate\n editor={editor}\n key={JSON.stringify({ initialValue, path })} // makes sure slate is completely re-rendered when initialValue changes, bypassing the slate-internal value memoization. That way, external changes to the form will update the editor\n onChange={handleChange}\n value={valueToRender as any[]}\n >\n <div className={`${baseClass}__wrapper`}>\n {Object.keys(elements)?.length + Object.keys(leaves)?.length > 0 && (\n <div\n className={[`${baseClass}__toolbar`, drawerIsOpen && `${baseClass}__drawerIsOpen`]\n .filter(Boolean)\n .join(' ')}\n ref={toolbarRef}\n >\n <div className={`${baseClass}__toolbar-wrap`}>\n {Object.values(elements).map((element) => {\n const Button = element?.Button\n\n if (Button) {\n return (\n <ElementButtonProvider\n disabled={disabled}\n fieldProps={props}\n key={element.name}\n path={path}\n schemaPath={schemaPath}\n >\n {Button}\n </ElementButtonProvider>\n )\n }\n\n return null\n })}\n {Object.values(leaves).map((leaf) => {\n const Button = leaf?.Button\n\n if (Button) {\n return (\n <LeafButtonProvider\n fieldProps={props}\n key={leaf.name}\n path={path}\n schemaPath={schemaPath}\n >\n {Button}\n </LeafButtonProvider>\n )\n }\n\n return null\n })}\n </div>\n </div>\n )}\n <div className={`${baseClass}__editor`} ref={editorRef}>\n <Editable\n className={`${baseClass}__input`}\n id={`field-${path.replace(/\\./g, '__')}`}\n onKeyDown={(event) => {\n if (event.key === 'Enter') {\n if (event.shiftKey) {\n event.preventDefault()\n editor.insertText('\\n')\n } else {\n const selectedElement = Node.descendant(\n editor,\n editor.selection.anchor.path.slice(0, -1),\n )\n\n if (SlateElement.isElement(selectedElement)) {\n // Allow hard enter to \"break out\" of certain elements\n if (editor.shouldBreakOutOnEnter(selectedElement)) {\n event.preventDefault()\n const selectedLeaf = Node.descendant(editor, editor.selection.anchor.path)\n\n if (\n Text.isText(selectedLeaf) &&\n String(selectedLeaf.text).length === editor.selection.anchor.offset\n ) {\n Transforms.insertNodes(editor, { children: [{ text: '' }] })\n } else {\n Transforms.splitNodes(editor)\n Transforms.setNodes(editor, {})\n }\n }\n }\n }\n }\n\n if (event.key === 'Backspace') {\n const selectedElement = Node.descendant(\n editor,\n editor.selection.anchor.path.slice(0, -1),\n )\n\n if (SlateElement.isElement(selectedElement) && selectedElement.type === 'li') {\n const selectedLeaf = Node.descendant(editor, editor.selection.anchor.path)\n if (Text.isText(selectedLeaf) && String(selectedLeaf.text).length === 0) {\n event.preventDefault()\n Transforms.unwrapNodes(editor, {\n match: (n) => SlateElement.isElement(n) && listTypes.includes(n.type),\n mode: 'lowest',\n split: true,\n })\n\n Transforms.setNodes(editor, { type: undefined })\n }\n } else if (editor.isVoid(selectedElement)) {\n Transforms.removeNodes(editor)\n }\n }\n\n Object.keys(hotkeys).forEach((hotkey) => {\n if (isHotkey(hotkey, event as any)) {\n event.preventDefault()\n const mark = hotkeys[hotkey]\n toggleLeaf(editor, mark)\n }\n })\n }}\n placeholder={getTranslation(placeholder, i18n)}\n readOnly={disabled}\n renderElement={renderElement}\n renderLeaf={renderLeaf}\n spellCheck\n />\n </div>\n </div>\n </Slate>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nexport const RichText = RichTextField\n"],"names":["getTranslation","FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useField","useTranslation","mergeFieldStyles","isHotkey","React","useCallback","useEffect","useMemo","useRef","createEditor","Node","Element","SlateElement","Text","Transforms","withHistory","Editable","Slate","withReact","defaultRichTextValue","richTextValidate","listTypes","hotkeys","toggleLeaf","withEnterBreakOut","withHTML","ElementButtonProvider","ElementProvider","LeafButtonProvider","LeafProvider","baseClass","RichTextField","props","elements","field","name","admin","className","description","placeholder","readOnly","readOnlyFromAdmin","label","required","leaves","path","pathFromProps","plugins","readOnlyFromTopLevelProps","schemaPath","schemaPathFromProps","validate","readOnlyFromProps","i18n","editorRef","toolbarRef","drawerDepth","drawerIsOpen","memoizedValidate","value","validationOptions","req","t","customComponents","Description","Error","Label","disabled","disabledFromField","initialValue","setValue","showError","editor","CreatedEditor","length","reduce","editorWithPlugins","plugin","renderElement","attributes","children","element","matchedElement","type","attr","textAlign","style","marginLeft","marginRight","listStylePosition","el","childNodes","fieldProps","div","renderLeaf","leaf","matchedLeaves","Object","entries","filter","leafName","result","leafConfig","i","Leaf","span","handleChange","val","ops","operations","o","Array","isArray","setClickableState","clickState","selectors","toolbarButtons","current","querySelectorAll","forEach","child","isButton","tagName","isDisabling","setAttribute","styles","classes","Boolean","join","valueToRender","parsedJSON","JSON","parse","err","CustomComponent","Fallback","onChange","keys","ref","values","map","Button","id","replace","onKeyDown","event","key","shiftKey","preventDefault","insertText","selectedElement","descendant","selection","anchor","slice","isElement","shouldBreakOutOnEnter","selectedLeaf","isText","String","text","offset","insertNodes","splitNodes","setNodes","unwrapNodes","match","n","includes","mode","split","undefined","isVoid","removeNodes","hotkey","mark","spellCheck","stringify","RichText"],"mappings":"AAAA;;AAOA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,gBAAgB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CAAC/E,QAAQA,OAAOgF,SAAS,CAACC,MAAM,CAAC5G,IAAI;oDACzE,IAAIhC,KAAKiJ,MAAM,CAACD,iBAAiBE,OAAOF,aAAaG,IAAI,EAAEtF,MAAM,KAAK,GAAG;wDACvEuE,MAAMG,cAAc;wDACpBtI,WAAWuJ,WAAW,CAAC7F,QAAQ;4DAC7B8F,OAAO,CAACC,IAAM3J,aAAa+I,SAAS,CAACY,MAAMlJ,UAAUmJ,QAAQ,CAACD,EAAEpF,IAAI;4DACpEsF,MAAM;4DACNC,OAAO;wDACT;wDAEA5J,WAAWsJ,QAAQ,CAAC5F,QAAQ;4DAAEW,MAAMwF;wDAAU;oDAChD;gDACF,OAAO,IAAInG,OAAOoG,MAAM,CAACtB,kBAAkB;oDACzCxI,WAAW+J,WAAW,CAACrG;gDACzB;4CACF;4CAEAyB,OAAOwC,IAAI,CAACnH,SAASiG,OAAO,CAAC,CAACuD;gDAC5B,IAAI3K,SAAS2K,QAAQ7B,QAAe;oDAClCA,MAAMG,cAAc;oDACpB,MAAM2B,OAAOzJ,OAAO,CAACwJ,OAAO;oDAC5BvJ,WAAWiD,QAAQuG;gDACrB;4CACF;wCACF;wCACAxI,aAAa7C,eAAe6C,aAAac;wCACzCb,UAAU2B;wCACVW,eAAeA;wCACfgB,YAAYA;wCACZkF,UAAU;;;;;uBA3HX7C,KAAK8C,SAAS,CAAC;wBAAE5G;wBAAcxB;oBAAK;kCAgI3C,KAAC/C;wBACCwI,iBAAiBtE;wBACjBuE,wBAAU,KAAC5I;4BAAiB2C,aAAaA;4BAAaO,MAAMA;;;;;;;AAKtE;AAEA,OAAO,MAAMqI,WAAWnJ,cAAa"}
|
|
1
|
+
{"version":3,"sources":["../../src/field/RichText.tsx"],"sourcesContent":["'use client'\n\nimport type { PayloadRequest } from 'payload'\nimport type { BaseEditor, BaseOperation } from 'slate'\nimport type { HistoryEditor } from 'slate-history'\nimport type { ReactEditor } from 'slate-react'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useEditDepth,\n useField,\n useTranslation,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport { isHotkey } from 'is-hotkey'\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react'\nimport { createEditor, Node, Element as SlateElement, Text, Transforms } from 'slate'\nimport { withHistory } from 'slate-history'\nimport { Editable, Slate, withReact } from 'slate-react'\n\nimport type { ElementNode, TextNode } from '../types.js'\nimport type { LoadedSlateFieldProps } from './types.js'\n\nimport { defaultRichTextValue } from '../data/defaultValue.js'\nimport { richTextValidate } from '../data/validation.js'\nimport { listTypes } from './elements/listTypes.js'\nimport './index.scss'\nimport { hotkeys } from './hotkeys.js'\nimport { toggleLeaf } from './leaves/toggle.js'\nimport { withEnterBreakOut } from './plugins/withEnterBreakOut.js'\nimport { withHTML } from './plugins/withHTML.js'\nimport { ElementButtonProvider } from './providers/ElementButtonProvider.js'\nimport { ElementProvider } from './providers/ElementProvider.js'\nimport { LeafButtonProvider } from './providers/LeafButtonProvider.js'\nimport { LeafProvider } from './providers/LeafProvider.js'\n\nconst baseClass = 'rich-text'\n\ndeclare module 'slate' {\n interface CustomTypes {\n Editor: BaseEditor & HistoryEditor & ReactEditor\n Element: ElementNode\n Text: TextNode\n }\n}\n\nconst RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {\n const {\n elements,\n field,\n field: {\n name,\n admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},\n label,\n required,\n },\n leaves,\n path: pathFromProps,\n plugins,\n readOnly: readOnlyFromTopLevelProps,\n schemaPath: schemaPathFromProps,\n validate = richTextValidate,\n } = props\n\n const path = pathFromProps ?? name\n const schemaPath = schemaPathFromProps ?? name\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const { i18n } = useTranslation()\n const editorRef = useRef(null)\n const toolbarRef = useRef(null)\n\n const drawerDepth = useEditDepth()\n const drawerIsOpen = drawerDepth > 1\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, {\n ...validationOptions,\n req: {\n t: i18n.t,\n } as PayloadRequest,\n required,\n })\n }\n },\n [validate, required, i18n],\n )\n\n const {\n customComponents: { Description, Error, Label } = {},\n formInitializing,\n initialValue,\n setValue,\n showError,\n value,\n } = useField({\n path,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || formInitializing\n\n const editor = useMemo(() => {\n let CreatedEditor = withEnterBreakOut(withHistory(withReact(createEditor())))\n\n CreatedEditor = withHTML(CreatedEditor)\n\n if (plugins.length) {\n CreatedEditor = plugins.reduce((editorWithPlugins, plugin) => {\n return plugin(editorWithPlugins)\n }, CreatedEditor)\n }\n\n return CreatedEditor\n }, [plugins])\n\n const renderElement = useCallback(\n ({ attributes, children, element }) => {\n // return <div {...attributes}>{children}</div>\n\n const matchedElement = elements[element.type]\n const Element = matchedElement?.Element\n\n let attr = { ...attributes }\n\n // this converts text alignment to margin when dealing with void elements\n if (element.textAlign) {\n if (element.type === 'relationship' || element.type === 'upload') {\n switch (element.textAlign) {\n case 'center':\n attr = { ...attr, style: { marginLeft: 'auto', marginRight: 'auto' } }\n break\n case 'left':\n attr = { ...attr, style: { marginRight: 'auto' } }\n break\n case 'right':\n attr = { ...attr, style: { marginLeft: 'auto' } }\n break\n default:\n attr = { ...attr, style: { textAlign: element.textAlign } }\n break\n }\n } else if (element.type === 'li') {\n switch (element.textAlign) {\n case 'center':\n attr = { ...attr, style: { listStylePosition: 'inside', textAlign: 'center' } }\n break\n case 'right':\n attr = { ...attr, style: { listStylePosition: 'inside', textAlign: 'right' } }\n break\n case 'left':\n default:\n attr = { ...attr, style: { listStylePosition: 'outside', textAlign: 'left' } }\n break\n }\n } else {\n attr = { ...attr, style: { textAlign: element.textAlign } }\n }\n }\n\n if (Element) {\n const el = (\n <ElementProvider\n attributes={attr}\n childNodes={children}\n editorRef={editorRef}\n element={element}\n fieldProps={props}\n path={path}\n schemaPath={schemaPath}\n >\n {Element}\n </ElementProvider>\n )\n\n return el\n }\n\n return <div {...attr}>{children}</div>\n },\n [elements, path, props, schemaPath],\n )\n\n const renderLeaf = useCallback(\n ({ attributes, children, leaf }) => {\n const matchedLeaves = Object.entries(leaves).filter(([leafName]) => leaf[leafName])\n\n if (matchedLeaves.length > 0) {\n return matchedLeaves.reduce(\n (result, [, leafConfig], i) => {\n if (leafConfig?.Leaf) {\n const Leaf = leafConfig.Leaf\n\n return (\n <LeafProvider\n attributes={attributes}\n editorRef={editorRef}\n fieldProps={props}\n key={i}\n leaf={leaf}\n path={path}\n result={result}\n schemaPath={schemaPath}\n >\n {Leaf}\n </LeafProvider>\n )\n }\n\n return result\n },\n <span {...attributes}>{children}</span>,\n )\n }\n\n return <span {...attributes}>{children}</span>\n },\n [path, props, schemaPath, leaves],\n )\n\n // All slate changes fire the onChange event\n // including selection changes\n // so we will filter the set_selection operations out\n // and only fire setValue when onChange is because of value\n const handleChange = useCallback(\n (val: unknown) => {\n const ops = editor?.operations.filter((o: BaseOperation) => {\n if (o) {\n return o.type !== 'set_selection'\n }\n return false\n })\n\n if (ops && Array.isArray(ops) && ops.length > 0) {\n if (!disabled && val !== defaultRichTextValue && val !== value) {\n setValue(val)\n }\n }\n },\n [editor?.operations, disabled, setValue, value],\n )\n\n useEffect(() => {\n function setClickableState(clickState: 'disabled' | 'enabled') {\n const selectors = 'button, a, [role=\"button\"]'\n const toolbarButtons: (HTMLAnchorElement | HTMLButtonElement)[] =\n toolbarRef.current?.querySelectorAll(selectors)\n\n ;(toolbarButtons || []).forEach((child) => {\n const isButton = child.tagName === 'BUTTON'\n const isDisabling = clickState === 'disabled'\n child.setAttribute('tabIndex', isDisabling ? '-1' : '0')\n if (isButton) {\n child.setAttribute('disabled', isDisabling ? 'disabled' : null)\n }\n })\n }\n\n if (disabled) {\n setClickableState('disabled')\n }\n\n return () => {\n if (disabled) {\n setClickableState('enabled')\n }\n }\n }, [disabled])\n\n // useEffect(() => {\n // // If there is a change to the initial value, we need to reset Slate history\n // // and clear selection because the old selection may no longer be valid\n // // as returned JSON may be modified in hooks and have a different shape\n // if (editor.selection) {\n // console.log('deselecting');\n // ReactEditor.deselect(editor);\n // }\n // }, [path, editor]);\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')\n\n let valueToRender = value\n\n if (typeof valueToRender === 'string') {\n try {\n const parsedJSON = JSON.parse(valueToRender)\n valueToRender = parsedJSON\n } catch (err) {\n valueToRender = null\n }\n }\n\n if (!valueToRender) {\n valueToRender = defaultRichTextValue\n }\n\n return (\n <div className={classes} style={styles}>\n {Label || <FieldLabel label={label} path={path} required={required} />}\n <div className={`${baseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n <Slate\n editor={editor}\n key={JSON.stringify({ initialValue, path })} // makes sure slate is completely re-rendered when initialValue changes, bypassing the slate-internal value memoization. That way, external changes to the form will update the editor\n onChange={handleChange}\n value={valueToRender as any[]}\n >\n <div className={`${baseClass}__wrapper`}>\n {Object.keys(elements)?.length + Object.keys(leaves)?.length > 0 && (\n <div\n className={[`${baseClass}__toolbar`, drawerIsOpen && `${baseClass}__drawerIsOpen`]\n .filter(Boolean)\n .join(' ')}\n ref={toolbarRef}\n >\n <div className={`${baseClass}__toolbar-wrap`}>\n {Object.values(elements).map((element) => {\n const Button = element?.Button\n\n if (Button) {\n return (\n <ElementButtonProvider\n disabled={disabled}\n fieldProps={props}\n key={element.name}\n path={path}\n schemaPath={schemaPath}\n >\n {Button}\n </ElementButtonProvider>\n )\n }\n\n return null\n })}\n {Object.values(leaves).map((leaf) => {\n const Button = leaf?.Button\n\n if (Button) {\n return (\n <LeafButtonProvider\n fieldProps={props}\n key={leaf.name}\n path={path}\n schemaPath={schemaPath}\n >\n {Button}\n </LeafButtonProvider>\n )\n }\n\n return null\n })}\n </div>\n </div>\n )}\n <div className={`${baseClass}__editor`} ref={editorRef}>\n <Editable\n className={`${baseClass}__input`}\n id={`field-${path.replace(/\\./g, '__')}`}\n onKeyDown={(event) => {\n if (event.key === 'Enter') {\n if (event.shiftKey) {\n event.preventDefault()\n editor.insertText('\\n')\n } else {\n const selectedElement = Node.descendant(\n editor,\n editor.selection.anchor.path.slice(0, -1),\n )\n\n if (SlateElement.isElement(selectedElement)) {\n // Allow hard enter to \"break out\" of certain elements\n if (editor.shouldBreakOutOnEnter(selectedElement)) {\n event.preventDefault()\n const selectedLeaf = Node.descendant(editor, editor.selection.anchor.path)\n\n if (\n Text.isText(selectedLeaf) &&\n String(selectedLeaf.text).length === editor.selection.anchor.offset\n ) {\n Transforms.insertNodes(editor, { children: [{ text: '' }] })\n } else {\n Transforms.splitNodes(editor)\n Transforms.setNodes(editor, {})\n }\n }\n }\n }\n }\n\n if (event.key === 'Backspace') {\n const selectedElement = Node.descendant(\n editor,\n editor.selection.anchor.path.slice(0, -1),\n )\n\n if (SlateElement.isElement(selectedElement) && selectedElement.type === 'li') {\n const selectedLeaf = Node.descendant(editor, editor.selection.anchor.path)\n if (Text.isText(selectedLeaf) && String(selectedLeaf.text).length === 0) {\n event.preventDefault()\n Transforms.unwrapNodes(editor, {\n match: (n) => SlateElement.isElement(n) && listTypes.includes(n.type),\n mode: 'lowest',\n split: true,\n })\n\n Transforms.setNodes(editor, { type: undefined })\n }\n } else if (editor.isVoid(selectedElement)) {\n Transforms.removeNodes(editor)\n }\n }\n\n Object.keys(hotkeys).forEach((hotkey) => {\n if (isHotkey(hotkey, event as any)) {\n event.preventDefault()\n const mark = hotkeys[hotkey]\n toggleLeaf(editor, mark)\n }\n })\n }}\n placeholder={getTranslation(placeholder, i18n)}\n readOnly={disabled}\n renderElement={renderElement}\n renderLeaf={renderLeaf}\n spellCheck\n />\n </div>\n </div>\n </Slate>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nexport const RichText = RichTextField\n"],"names":["getTranslation","FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useField","useTranslation","mergeFieldStyles","isHotkey","React","useCallback","useEffect","useMemo","useRef","createEditor","Node","Element","SlateElement","Text","Transforms","withHistory","Editable","Slate","withReact","defaultRichTextValue","richTextValidate","listTypes","hotkeys","toggleLeaf","withEnterBreakOut","withHTML","ElementButtonProvider","ElementProvider","LeafButtonProvider","LeafProvider","baseClass","RichTextField","props","elements","field","name","admin","className","description","placeholder","readOnly","readOnlyFromAdmin","label","required","leaves","path","pathFromProps","plugins","readOnlyFromTopLevelProps","schemaPath","schemaPathFromProps","validate","readOnlyFromProps","i18n","editorRef","toolbarRef","drawerDepth","drawerIsOpen","memoizedValidate","value","validationOptions","req","t","customComponents","Description","Error","Label","formInitializing","initialValue","setValue","showError","disabled","editor","CreatedEditor","length","reduce","editorWithPlugins","plugin","renderElement","attributes","children","element","matchedElement","type","attr","textAlign","style","marginLeft","marginRight","listStylePosition","el","childNodes","fieldProps","div","renderLeaf","leaf","matchedLeaves","Object","entries","filter","leafName","result","leafConfig","i","Leaf","span","handleChange","val","ops","operations","o","Array","isArray","setClickableState","clickState","selectors","toolbarButtons","current","querySelectorAll","forEach","child","isButton","tagName","isDisabling","setAttribute","styles","classes","Boolean","join","valueToRender","parsedJSON","JSON","parse","err","CustomComponent","Fallback","onChange","keys","ref","values","map","Button","id","replace","onKeyDown","event","key","shiftKey","preventDefault","insertText","selectedElement","descendant","selection","anchor","slice","isElement","shouldBreakOutOnEnter","selectedLeaf","isText","String","text","offset","insertNodes","splitNodes","setNodes","unwrapNodes","match","n","includes","mode","split","undefined","isVoid","removeNodes","hotkey","mark","spellCheck","stringify","RichText"],"mappings":"AAAA;;AAOA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC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CAAC5G,IAAI;oDACzE,IAAIhC,KAAKiJ,MAAM,CAACD,iBAAiBE,OAAOF,aAAaG,IAAI,EAAEtF,MAAM,KAAK,GAAG;wDACvEuE,MAAMG,cAAc;wDACpBtI,WAAWuJ,WAAW,CAAC7F,QAAQ;4DAC7B8F,OAAO,CAACC,IAAM3J,aAAa+I,SAAS,CAACY,MAAMlJ,UAAUmJ,QAAQ,CAACD,EAAEpF,IAAI;4DACpEsF,MAAM;4DACNC,OAAO;wDACT;wDAEA5J,WAAWsJ,QAAQ,CAAC5F,QAAQ;4DAAEW,MAAMwF;wDAAU;oDAChD;gDACF,OAAO,IAAInG,OAAOoG,MAAM,CAACtB,kBAAkB;oDACzCxI,WAAW+J,WAAW,CAACrG;gDACzB;4CACF;4CAEAyB,OAAOwC,IAAI,CAACnH,SAASiG,OAAO,CAAC,CAACuD;gDAC5B,IAAI3K,SAAS2K,QAAQ7B,QAAe;oDAClCA,MAAMG,cAAc;oDACpB,MAAM2B,OAAOzJ,OAAO,CAACwJ,OAAO;oDAC5BvJ,WAAWiD,QAAQuG;gDACrB;4CACF;wCACF;wCACAxI,aAAa7C,eAAe6C,aAAac;wCACzCb,UAAU+B;wCACVO,eAAeA;wCACfgB,YAAYA;wCACZkF,UAAU;;;;;uBA3HX7C,KAAK8C,SAAS,CAAC;wBAAE7G;wBAAcvB;oBAAK;kCAgI3C,KAAC/C;wBACCwI,iBAAiBtE;wBACjBuE,wBAAU,KAAC5I;4BAAiB2C,aAAaA;4BAAaO,MAAMA;;;;;;;AAKtE;AAEA,OAAO,MAAMqI,WAAWnJ,cAAa"}
|
|
@@ -8,7 +8,7 @@ const ElementButtonContext = /*#__PURE__*/ React.createContext({
|
|
|
8
8
|
});
|
|
9
9
|
export const ElementButtonProvider = (props)=>{
|
|
10
10
|
const { children, ...rest } = props;
|
|
11
|
-
return /*#__PURE__*/ _jsx(ElementButtonContext, {
|
|
11
|
+
return /*#__PURE__*/ _jsx(ElementButtonContext.Provider, {
|
|
12
12
|
value: {
|
|
13
13
|
...rest
|
|
14
14
|
},
|
|
@@ -16,7 +16,7 @@ export const ElementButtonProvider = (props)=>{
|
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
18
|
export const useElementButton = ()=>{
|
|
19
|
-
const path = React.
|
|
19
|
+
const path = React.useContext(ElementButtonContext);
|
|
20
20
|
return path;
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/field/providers/ElementButtonProvider.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { LoadedSlateFieldProps } from '../types.js'\n\ntype ElementButtonContextType = {\n disabled?: boolean\n fieldProps: LoadedSlateFieldProps\n path: string\n schemaPath: string\n}\n\nconst ElementButtonContext = React.createContext<ElementButtonContextType>({\n fieldProps: {} as any,\n path: '',\n schemaPath: '',\n})\n\nexport const ElementButtonProvider: React.FC<\n {\n children: React.ReactNode\n } & ElementButtonContextType\n> = (props) => {\n const { children, ...rest } = props\n\n return (\n <ElementButtonContext\n value={{\n ...rest,\n }}\n >\n {children}\n </ElementButtonContext>\n )\n}\n\nexport const useElementButton = () => {\n const path = React.
|
|
1
|
+
{"version":3,"sources":["../../../src/field/providers/ElementButtonProvider.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { LoadedSlateFieldProps } from '../types.js'\n\ntype ElementButtonContextType = {\n disabled?: boolean\n fieldProps: LoadedSlateFieldProps\n path: string\n schemaPath: string\n}\n\nconst ElementButtonContext = React.createContext<ElementButtonContextType>({\n fieldProps: {} as any,\n path: '',\n schemaPath: '',\n})\n\nexport const ElementButtonProvider: React.FC<\n {\n children: React.ReactNode\n } & ElementButtonContextType\n> = (props) => {\n const { children, ...rest } = props\n\n return (\n <ElementButtonContext.Provider\n value={{\n ...rest,\n }}\n >\n {children}\n </ElementButtonContext.Provider>\n )\n}\n\nexport const useElementButton = () => {\n const path = React.useContext(ElementButtonContext)\n return path\n}\n"],"names":["React","ElementButtonContext","createContext","fieldProps","path","schemaPath","ElementButtonProvider","props","children","rest","Provider","value","useElementButton","useContext"],"mappings":"AAAA;;AAEA,OAAOA,WAAW,QAAO;AAWzB,MAAMC,qCAAuBD,MAAME,aAAa,CAA2B;IACzEC,YAAY,CAAC;IACbC,MAAM;IACNC,YAAY;AACd;AAEA,OAAO,MAAMC,wBAIT,CAACC;IACH,MAAM,EAAEC,QAAQ,EAAE,GAAGC,MAAM,GAAGF;IAE9B,qBACE,KAACN,qBAAqBS,QAAQ;QAC5BC,OAAO;YACL,GAAGF,IAAI;QACT;kBAECD;;AAGP,EAAC;AAED,OAAO,MAAMI,mBAAmB;IAC9B,MAAMR,OAAOJ,MAAMa,UAAU,CAACZ;IAC9B,OAAOG;AACT,EAAC"}
|
|
@@ -12,7 +12,7 @@ const ElementContext = /*#__PURE__*/ React.createContext({
|
|
|
12
12
|
});
|
|
13
13
|
export const ElementProvider = (props)=>{
|
|
14
14
|
const { childNodes, children, ...rest } = props;
|
|
15
|
-
return /*#__PURE__*/ _jsx(ElementContext, {
|
|
15
|
+
return /*#__PURE__*/ _jsx(ElementContext.Provider, {
|
|
16
16
|
value: {
|
|
17
17
|
...rest,
|
|
18
18
|
children: childNodes
|
|
@@ -21,7 +21,7 @@ export const ElementProvider = (props)=>{
|
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
23
|
export const useElement = ()=>{
|
|
24
|
-
return React.
|
|
24
|
+
return React.useContext(ElementContext);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
//# sourceMappingURL=ElementProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/field/providers/ElementProvider.tsx"],"sourcesContent":["'use client'\nimport type { Element } from 'slate'\n\nimport React from 'react'\n\nimport type { LoadedSlateFieldProps } from '../types.js'\n\ntype ElementContextType<T> = {\n attributes: Record<string, unknown>\n children: React.ReactNode\n editorRef: React.RefObject<HTMLDivElement>\n element: T\n fieldProps: LoadedSlateFieldProps\n path: string\n schemaPath: string\n}\n\nconst ElementContext = React.createContext<ElementContextType<Element>>({\n attributes: {},\n children: null,\n editorRef: null,\n element: {} as Element,\n fieldProps: {} as any,\n path: '',\n schemaPath: '',\n})\n\nexport const ElementProvider: React.FC<\n {\n childNodes: React.ReactNode\n } & ElementContextType<Element>\n> = (props) => {\n const { childNodes, children, ...rest } = props\n\n return (\n <ElementContext\n value={{\n ...rest,\n children: childNodes,\n }}\n >\n {children}\n </ElementContext>\n )\n}\n\nexport const useElement = <T,>(): ElementContextType<T> => {\n return React.
|
|
1
|
+
{"version":3,"sources":["../../../src/field/providers/ElementProvider.tsx"],"sourcesContent":["'use client'\nimport type { Element } from 'slate'\n\nimport React from 'react'\n\nimport type { LoadedSlateFieldProps } from '../types.js'\n\ntype ElementContextType<T> = {\n attributes: Record<string, unknown>\n children: React.ReactNode\n editorRef: React.RefObject<HTMLDivElement>\n element: T\n fieldProps: LoadedSlateFieldProps\n path: string\n schemaPath: string\n}\n\nconst ElementContext = React.createContext<ElementContextType<Element>>({\n attributes: {},\n children: null,\n editorRef: null,\n element: {} as Element,\n fieldProps: {} as any,\n path: '',\n schemaPath: '',\n})\n\nexport const ElementProvider: React.FC<\n {\n childNodes: React.ReactNode\n } & ElementContextType<Element>\n> = (props) => {\n const { childNodes, children, ...rest } = props\n\n return (\n <ElementContext.Provider\n value={{\n ...rest,\n children: childNodes,\n }}\n >\n {children}\n </ElementContext.Provider>\n )\n}\n\nexport const useElement = <T,>(): ElementContextType<T> => {\n return React.useContext(ElementContext) as ElementContextType<T>\n}\n"],"names":["React","ElementContext","createContext","attributes","children","editorRef","element","fieldProps","path","schemaPath","ElementProvider","props","childNodes","rest","Provider","value","useElement","useContext"],"mappings":"AAAA;;AAGA,OAAOA,WAAW,QAAO;AAczB,MAAMC,+BAAiBD,MAAME,aAAa,CAA8B;IACtEC,YAAY,CAAC;IACbC,UAAU;IACVC,WAAW;IACXC,SAAS,CAAC;IACVC,YAAY,CAAC;IACbC,MAAM;IACNC,YAAY;AACd;AAEA,OAAO,MAAMC,kBAIT,CAACC;IACH,MAAM,EAAEC,UAAU,EAAER,QAAQ,EAAE,GAAGS,MAAM,GAAGF;IAE1C,qBACE,KAACV,eAAea,QAAQ;QACtBC,OAAO;YACL,GAAGF,IAAI;YACPT,UAAUQ;QACZ;kBAECR;;AAGP,EAAC;AAED,OAAO,MAAMY,aAAa;IACxB,OAAOhB,MAAMiB,UAAU,CAAChB;AAC1B,EAAC"}
|
|
@@ -8,7 +8,7 @@ const LeafButtonContext = /*#__PURE__*/ React.createContext({
|
|
|
8
8
|
});
|
|
9
9
|
export const LeafButtonProvider = (props)=>{
|
|
10
10
|
const { children, ...rest } = props;
|
|
11
|
-
return /*#__PURE__*/ _jsx(LeafButtonContext, {
|
|
11
|
+
return /*#__PURE__*/ _jsx(LeafButtonContext.Provider, {
|
|
12
12
|
value: {
|
|
13
13
|
...rest
|
|
14
14
|
},
|
|
@@ -16,7 +16,7 @@ export const LeafButtonProvider = (props)=>{
|
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
18
|
export const useLeafButton = ()=>{
|
|
19
|
-
const path = React.
|
|
19
|
+
const path = React.useContext(LeafButtonContext);
|
|
20
20
|
return path;
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/field/providers/LeafButtonProvider.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { LoadedSlateFieldProps } from '../types.js'\n\ntype LeafButtonContextType = {\n fieldProps: LoadedSlateFieldProps\n path: string\n schemaPath: string\n}\n\nconst LeafButtonContext = React.createContext<LeafButtonContextType>({\n fieldProps: {} as any,\n path: '',\n schemaPath: '',\n})\n\nexport const LeafButtonProvider: React.FC<\n {\n children: React.ReactNode\n } & LeafButtonContextType\n> = (props) => {\n const { children, ...rest } = props\n\n return (\n <LeafButtonContext\n value={{\n ...rest,\n }}\n >\n {children}\n </LeafButtonContext>\n )\n}\n\nexport const useLeafButton = () => {\n const path = React.
|
|
1
|
+
{"version":3,"sources":["../../../src/field/providers/LeafButtonProvider.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { LoadedSlateFieldProps } from '../types.js'\n\ntype LeafButtonContextType = {\n fieldProps: LoadedSlateFieldProps\n path: string\n schemaPath: string\n}\n\nconst LeafButtonContext = React.createContext<LeafButtonContextType>({\n fieldProps: {} as any,\n path: '',\n schemaPath: '',\n})\n\nexport const LeafButtonProvider: React.FC<\n {\n children: React.ReactNode\n } & LeafButtonContextType\n> = (props) => {\n const { children, ...rest } = props\n\n return (\n <LeafButtonContext.Provider\n value={{\n ...rest,\n }}\n >\n {children}\n </LeafButtonContext.Provider>\n )\n}\n\nexport const useLeafButton = () => {\n const path = React.useContext(LeafButtonContext)\n return path\n}\n"],"names":["React","LeafButtonContext","createContext","fieldProps","path","schemaPath","LeafButtonProvider","props","children","rest","Provider","value","useLeafButton","useContext"],"mappings":"AAAA;;AAEA,OAAOA,WAAW,QAAO;AAUzB,MAAMC,kCAAoBD,MAAME,aAAa,CAAwB;IACnEC,YAAY,CAAC;IACbC,MAAM;IACNC,YAAY;AACd;AAEA,OAAO,MAAMC,qBAIT,CAACC;IACH,MAAM,EAAEC,QAAQ,EAAE,GAAGC,MAAM,GAAGF;IAE9B,qBACE,KAACN,kBAAkBS,QAAQ;QACzBC,OAAO;YACL,GAAGF,IAAI;QACT;kBAECD;;AAGP,EAAC;AAED,OAAO,MAAMI,gBAAgB;IAC3B,MAAMR,OAAOJ,MAAMa,UAAU,CAACZ;IAC9B,OAAOG;AACT,EAAC"}
|
|
@@ -12,7 +12,7 @@ const LeafContext = /*#__PURE__*/ React.createContext({
|
|
|
12
12
|
});
|
|
13
13
|
export const LeafProvider = (props)=>{
|
|
14
14
|
const { children, result, ...rest } = props;
|
|
15
|
-
return /*#__PURE__*/ _jsx(LeafContext, {
|
|
15
|
+
return /*#__PURE__*/ _jsx(LeafContext.Provider, {
|
|
16
16
|
value: {
|
|
17
17
|
...rest,
|
|
18
18
|
children: result
|
|
@@ -21,7 +21,7 @@ export const LeafProvider = (props)=>{
|
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
23
|
export const useLeaf = ()=>{
|
|
24
|
-
const path = React.
|
|
24
|
+
const path = React.useContext(LeafContext);
|
|
25
25
|
return path;
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/field/providers/LeafProvider.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { LoadedSlateFieldProps } from '../types.js'\n\ntype LeafContextType = {\n attributes: Record<string, unknown>\n children: React.ReactNode\n editorRef: React.RefObject<HTMLDivElement>\n fieldProps: LoadedSlateFieldProps\n leaf: string\n path: string\n schemaPath: string\n}\n\nconst LeafContext = React.createContext<LeafContextType>({\n attributes: {},\n children: null,\n editorRef: null,\n fieldProps: {} as any,\n leaf: '',\n path: '',\n schemaPath: '',\n})\n\nexport const LeafProvider: React.FC<\n {\n result: React.ReactNode\n } & LeafContextType\n> = (props) => {\n const { children, result, ...rest } = props\n\n return (\n <LeafContext\n value={{\n ...rest,\n children: result,\n }}\n >\n {children}\n </LeafContext>\n )\n}\n\nexport const useLeaf = () => {\n const path = React.
|
|
1
|
+
{"version":3,"sources":["../../../src/field/providers/LeafProvider.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { LoadedSlateFieldProps } from '../types.js'\n\ntype LeafContextType = {\n attributes: Record<string, unknown>\n children: React.ReactNode\n editorRef: React.RefObject<HTMLDivElement>\n fieldProps: LoadedSlateFieldProps\n leaf: string\n path: string\n schemaPath: string\n}\n\nconst LeafContext = React.createContext<LeafContextType>({\n attributes: {},\n children: null,\n editorRef: null,\n fieldProps: {} as any,\n leaf: '',\n path: '',\n schemaPath: '',\n})\n\nexport const LeafProvider: React.FC<\n {\n result: React.ReactNode\n } & LeafContextType\n> = (props) => {\n const { children, result, ...rest } = props\n\n return (\n <LeafContext.Provider\n value={{\n ...rest,\n children: result,\n }}\n >\n {children}\n </LeafContext.Provider>\n )\n}\n\nexport const useLeaf = () => {\n const path = React.useContext(LeafContext)\n return path\n}\n"],"names":["React","LeafContext","createContext","attributes","children","editorRef","fieldProps","leaf","path","schemaPath","LeafProvider","props","result","rest","Provider","value","useLeaf","useContext"],"mappings":"AAAA;;AAEA,OAAOA,WAAW,QAAO;AAczB,MAAMC,4BAAcD,MAAME,aAAa,CAAkB;IACvDC,YAAY,CAAC;IACbC,UAAU;IACVC,WAAW;IACXC,YAAY,CAAC;IACbC,MAAM;IACNC,MAAM;IACNC,YAAY;AACd;AAEA,OAAO,MAAMC,eAIT,CAACC;IACH,MAAM,EAAEP,QAAQ,EAAEQ,MAAM,EAAE,GAAGC,MAAM,GAAGF;IAEtC,qBACE,KAACV,YAAYa,QAAQ;QACnBC,OAAO;YACL,GAAGF,IAAI;YACPT,UAAUQ;QACZ;kBAECR;;AAGP,EAAC;AAED,OAAO,MAAMY,UAAU;IACrB,MAAMR,OAAOR,MAAMiB,UAAU,CAAChB;IAC9B,OAAOO;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlatePropsProvider.d.ts","sourceRoot":"","sources":["../../src/utilities/SlatePropsProvider.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAiB,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"SlatePropsProvider.d.ts","sourceRoot":"","sources":["../../src/utilities/SlatePropsProvider.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAiB,KAAK,SAAS,EAAc,MAAM,OAAO,CAAA;AAExE,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAA;CACnB;AAID,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,UAAU,GACX,EAAE;IACD,QAAQ,EAAE,SAAS,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACnB,2CAEA;AAED,wBAAgB,aAAa,eAM5B"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React, { createContext,
|
|
3
|
+
import React, { createContext, useContext } from 'react';
|
|
4
4
|
const SlatePropsContext = /*#__PURE__*/ createContext(undefined);
|
|
5
5
|
export function SlatePropsProvider({ children, schemaPath }) {
|
|
6
|
-
return /*#__PURE__*/ _jsx(SlatePropsContext, {
|
|
6
|
+
return /*#__PURE__*/ _jsx(SlatePropsContext.Provider, {
|
|
7
7
|
value: {
|
|
8
8
|
schemaPath
|
|
9
9
|
},
|
|
@@ -11,7 +11,7 @@ export function SlatePropsProvider({ children, schemaPath }) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
export function useSlateProps() {
|
|
14
|
-
const context =
|
|
14
|
+
const context = useContext(SlatePropsContext);
|
|
15
15
|
if (!context) {
|
|
16
16
|
throw new Error('useSlateProps must be used within SlatePropsProvider');
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/SlatePropsProvider.tsx"],"sourcesContent":["'use client'\n\nimport React, { createContext, type ReactNode,
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/SlatePropsProvider.tsx"],"sourcesContent":["'use client'\n\nimport React, { createContext, type ReactNode, useContext } from 'react'\n\ninterface SlateProps {\n schemaPath: string\n}\n\nconst SlatePropsContext = createContext<SlateProps | undefined>(undefined)\n\nexport function SlatePropsProvider({\n children,\n schemaPath,\n}: {\n children: ReactNode\n schemaPath: string\n}) {\n return <SlatePropsContext.Provider value={{ schemaPath }}>{children}</SlatePropsContext.Provider>\n}\n\nexport function useSlateProps() {\n const context = useContext(SlatePropsContext)\n if (!context) {\n throw new Error('useSlateProps must be used within SlatePropsProvider')\n }\n return context\n}\n"],"names":["React","createContext","useContext","SlatePropsContext","undefined","SlatePropsProvider","children","schemaPath","Provider","value","useSlateProps","context","Error"],"mappings":"AAAA;;AAEA,OAAOA,SAASC,aAAa,EAAkBC,UAAU,QAAQ,QAAO;AAMxE,MAAMC,kCAAoBF,cAAsCG;AAEhE,OAAO,SAASC,mBAAmB,EACjCC,QAAQ,EACRC,UAAU,EAIX;IACC,qBAAO,KAACJ,kBAAkBK,QAAQ;QAACC,OAAO;YAAEF;QAAW;kBAAID;;AAC7D;AAEA,OAAO,SAASI;IACd,MAAMC,UAAUT,WAAWC;IAC3B,IAAI,CAACQ,SAAS;QACZ,MAAM,IAAIC,MAAM;IAClB;IACA,OAAOD;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/richtext-slate",
|
|
3
|
-
"version": "3.29.0-internal.
|
|
3
|
+
"version": "3.29.0-internal.37e46b5",
|
|
4
4
|
"description": "The officially supported Slate richtext adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -46,20 +46,20 @@
|
|
|
46
46
|
"slate-history": "0.86.0",
|
|
47
47
|
"slate-hyperscript": "0.81.3",
|
|
48
48
|
"slate-react": "0.92.0",
|
|
49
|
-
"@payloadcms/translations": "3.29.0-internal.
|
|
50
|
-
"@payloadcms/ui": "3.29.0-internal.
|
|
49
|
+
"@payloadcms/translations": "3.29.0-internal.37e46b5",
|
|
50
|
+
"@payloadcms/ui": "3.29.0-internal.37e46b5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/is-hotkey": "^0.1.10",
|
|
54
54
|
"@types/node": "22.5.4",
|
|
55
55
|
"@types/react": "19.0.10",
|
|
56
56
|
"@types/react-dom": "19.0.4",
|
|
57
|
-
"payload": "3.29.0-internal.
|
|
57
|
+
"payload": "3.29.0-internal.37e46b5",
|
|
58
58
|
"@payloadcms/eslint-config": "3.28.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
62
|
-
"payload": "3.29.0-internal.
|
|
62
|
+
"payload": "3.29.0-internal.37e46b5"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": "^18.20.2 || >=20.9.0"
|