@payloadcms/richtext-slate 3.0.0-beta.36 → 3.0.0-beta.38

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.
@@ -1 +1 @@
1
- {"version":3,"file":"RichText.d.ts","sourceRoot":"","sources":["../../src/field/RichText.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,OAAO,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAY9C,OAAO,KAAkD,MAAM,OAAO,CAAA;AAKtE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,OAAO,cAAc,CAAA;AAWrB,OAAO,QAAQ,OAAO,CAAC;IACrB,UAAU,WAAW;QACnB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,CAAA;QAChD,OAAO,EAAE,WAAW,CAAA;QACpB,IAAI,EAAE,QAAQ,CAAA;KACf;CACF;AAiaD,eAAO,MAAM,QAAQ;cA7ZP,eAAe,CAAC,UAAU,CAAC;YAC7B,eAAe,CAAC,QAAQ,CAAC;UAC3B,MAAM;kBACE,MAAM;aACX,cAAc,EAAE;0BACH,IAAI,MAAM,EAAE,MAAM,SAAS,CAAC;YAC1C,MAAM;EAuZkC,CAAA"}
1
+ {"version":3,"file":"RichText.d.ts","sourceRoot":"","sources":["../../src/field/RichText.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,OAAO,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAY9C,OAAO,KAAkD,MAAM,OAAO,CAAA;AAKtE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,OAAO,cAAc,CAAA;AAWrB,OAAO,QAAQ,OAAO,CAAC;IACrB,UAAU,WAAW;QACnB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,CAAA;QAChD,OAAO,EAAE,WAAW,CAAA;QACpB,IAAI,EAAE,QAAQ,CAAA;KACf;CACF;AAsaD,eAAO,MAAM,QAAQ;cAlaP,eAAe,CAAC,UAAU,CAAC;YAC7B,eAAe,CAAC,QAAQ,CAAC;UAC3B,MAAM;kBACE,MAAM;aACX,cAAc,EAAE;0BACH,IAAI,MAAM,EAAE,MAAM,SAAS,CAAC;YAC1C,MAAM;EA4ZkC,CAAA"}
@@ -28,7 +28,7 @@ import { LeafButtonProvider } from './providers/LeafButtonProvider.js';
28
28
  import { LeafProvider } from './providers/LeafProvider.js';
29
29
  const baseClass = 'rich-text';
30
30
  const RichTextField = (props)=>{
31
- const { name, CustomDescription, CustomError, CustomLabel, className, descriptionProps, elements, errorProps, label, labelProps, leaves, path: pathFromProps, placeholder, plugins, readOnly, required, style, validate = richTextValidate, width } = props;
31
+ const { name, CustomDescription, CustomError, CustomLabel, className, descriptionProps, elements, errorProps, label, labelProps, leaves, path: pathFromProps, placeholder, plugins, readOnly: readOnlyFromProps, required, style, validate = richTextValidate, width } = props;
32
32
  const { i18n } = useTranslation();
33
33
  const editorRef = useRef(null);
34
34
  const toolbarRef = useRef(null);
@@ -49,11 +49,12 @@ const RichTextField = (props)=>{
49
49
  required,
50
50
  i18n
51
51
  ]);
52
- const { path: pathFromContext } = useFieldProps();
53
- const { initialValue, path, schemaPath, setValue, showError, value } = useField({
52
+ const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
53
+ const { formInitializing, initialValue, path, schemaPath, setValue, showError, value } = useField({
54
54
  path: pathFromContext || pathFromProps || name,
55
55
  validate: memoizedValidate
56
56
  });
57
+ const disabled = readOnlyFromProps || readOnlyFromContext || formInitializing;
57
58
  const editor = useMemo(()=>{
58
59
  let CreatedEditor = withEnterBreakOut(withHistory(withReact(createEditor())));
59
60
  CreatedEditor = withHTML(CreatedEditor);
@@ -219,13 +220,13 @@ const RichTextField = (props)=>{
219
220
  return false;
220
221
  });
221
222
  if (ops && Array.isArray(ops) && ops.length > 0) {
222
- if (!readOnly && val !== defaultRichTextValue && val !== value) {
223
+ if (!disabled && val !== defaultRichTextValue && val !== value) {
223
224
  setValue(val);
224
225
  }
225
226
  }
226
227
  }, [
227
228
  editor?.operations,
228
- readOnly,
229
+ disabled,
229
230
  setValue,
230
231
  value
231
232
  ]);
@@ -240,16 +241,16 @@ const RichTextField = (props)=>{
240
241
  if (isButton) child.setAttribute('disabled', isDisabling ? 'disabled' : null);
241
242
  });
242
243
  }
243
- if (readOnly) {
244
+ if (disabled) {
244
245
  setClickableState('disabled');
245
246
  }
246
247
  return ()=>{
247
- if (readOnly) {
248
+ if (disabled) {
248
249
  setClickableState('enabled');
249
250
  }
250
251
  };
251
252
  }, [
252
- readOnly
253
+ disabled
253
254
  ]);
254
255
  // useEffect(() => {
255
256
  // // If there is a change to the initial value, we need to reset Slate history
@@ -265,7 +266,7 @@ const RichTextField = (props)=>{
265
266
  'field-type',
266
267
  className,
267
268
  showError && 'error',
268
- readOnly && `${baseClass}--read-only`
269
+ disabled && `${baseClass}--read-only`
269
270
  ].filter(Boolean).join(' ');
270
271
  let valueToRender = value;
271
272
  if (typeof valueToRender === 'string') {
@@ -318,6 +319,7 @@ const RichTextField = (props)=>{
318
319
  const Button = element?.Button;
319
320
  if (Button) {
320
321
  return /*#__PURE__*/ _jsx(ElementButtonProvider, {
322
+ disabled: disabled,
321
323
  fieldProps: props,
322
324
  path: path,
323
325
  schemaPath: schemaPath,
@@ -403,7 +405,7 @@ const RichTextField = (props)=>{
403
405
  });
404
406
  },
405
407
  placeholder: getTranslation(placeholder, i18n),
406
- readOnly: readOnly,
408
+ readOnly: disabled,
407
409
  renderElement: renderElement,
408
410
  renderLeaf: renderLeaf,
409
411
  spellCheck: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/field/RichText.tsx"],"sourcesContent":["'use client'\n\nimport type { FormFieldBase } from '@payloadcms/ui/fields/shared'\nimport type { ClientValidate } from 'payload/types'\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 { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { FieldError } from '@payloadcms/ui/forms/FieldError'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useField } from '@payloadcms/ui/forms/useField'\nimport { withCondition } from '@payloadcms/ui/forms/withCondition'\nimport { useEditDepth } from '@payloadcms/ui/providers/EditDepth'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport { isHotkey } from 'is-hotkey'\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react'\nimport { Node, Element as SlateElement, Text, Transforms, createEditor } from 'slate'\nimport { withHistory } from 'slate-history'\nimport { Editable, Slate, withReact } from 'slate-react'\n\nimport type { ElementNode, RichTextPlugin, TextNode } from '../types.js'\nimport type { EnabledFeatures } from './types.js'\n\nimport { defaultRichTextValue } from '../data/defaultValue.js'\nimport { richTextValidate } from '../data/validation.js'\nimport { listTypes } from './elements/listTypes.js'\nimport { hotkeys } from './hotkeys.js'\nimport './index.scss'\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 & ReactEditor & HistoryEditor\n Element: ElementNode\n Text: TextNode\n }\n}\n\nconst RichTextField: React.FC<\n FormFieldBase & {\n elements: EnabledFeatures['elements']\n leaves: EnabledFeatures['leaves']\n name: string\n placeholder?: string\n plugins: RichTextPlugin[]\n richTextComponentMap: Map<string, React.ReactNode>\n width?: string\n }\n> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n elements,\n errorProps,\n label,\n labelProps,\n leaves,\n path: pathFromProps,\n placeholder,\n plugins,\n readOnly,\n required,\n style,\n validate = richTextValidate,\n width,\n } = props\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: ClientValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, {\n ...validationOptions,\n req: {\n t: i18n.t,\n },\n required,\n })\n }\n },\n [validate, required, i18n],\n )\n\n const { path: pathFromContext } = useFieldProps()\n\n const { initialValue, path, schemaPath, setValue, showError, value } = useField({\n path: pathFromContext || pathFromProps || name,\n validate: memoizedValidate,\n })\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 'left':\n attr = { ...attr, style: { marginRight: 'auto' } }\n break\n case 'right':\n attr = { ...attr, style: { marginLeft: 'auto' } }\n break\n case 'center':\n attr = { ...attr, style: { marginLeft: 'auto', marginRight: '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 'right':\n attr = { ...attr, style: { listStylePosition: 'inside', textAlign: 'right' } }\n break\n case 'center':\n attr = { ...attr, style: { listStylePosition: 'inside', textAlign: 'center' } }\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 (!readOnly && val !== defaultRichTextValue && val !== value) {\n setValue(val)\n }\n }\n },\n [editor?.operations, readOnly, 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) child.setAttribute('disabled', isDisabling ? 'disabled' : null)\n })\n }\n\n if (readOnly) {\n setClickableState('disabled')\n }\n\n return () => {\n if (readOnly) {\n setClickableState('enabled')\n }\n }\n }, [readOnly])\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 classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n readOnly && `${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) valueToRender = defaultRichTextValue\n\n return (\n <div\n className={classes}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${baseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\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 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={readOnly}\n renderElement={renderElement}\n renderLeaf={renderLeaf}\n spellCheck\n />\n </div>\n </div>\n </Slate>\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n </div>\n )\n}\n\nexport const RichText = withCondition(RichTextField)\n"],"names":["getTranslation","FieldDescription","FieldError","FieldLabel","useFieldProps","useField","withCondition","useEditDepth","useTranslation","isHotkey","React","useCallback","useEffect","useMemo","useRef","Node","Element","SlateElement","Text","Transforms","createEditor","withHistory","Editable","Slate","withReact","defaultRichTextValue","richTextValidate","listTypes","hotkeys","toggleLeaf","withEnterBreakOut","withHTML","ElementButtonProvider","ElementProvider","LeafButtonProvider","LeafProvider","baseClass","RichTextField","props","name","CustomDescription","CustomError","CustomLabel","className","descriptionProps","elements","errorProps","label","labelProps","leaves","path","pathFromProps","placeholder","plugins","readOnly","required","style","validate","width","i18n","editorRef","toolbarRef","drawerDepth","drawerIsOpen","memoizedValidate","value","validationOptions","req","t","pathFromContext","initialValue","schemaPath","setValue","showError","editor","CreatedEditor","length","reduce","editorWithPlugins","plugin","renderElement","attributes","children","element","matchedElement","type","attr","textAlign","marginRight","marginLeft","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","classes","Boolean","join","valueToRender","parsedJSON","JSON","parse","err","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAQA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aA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AACC,IAAMpJ,aAAawI,SAAS,CAACY,MAAM1I,UAAU2I,QAAQ,CAACD,EAAEhF,IAAI;4DACpEkF,MAAM;4DACNC,OAAO;wDACT;wDAEArJ,WAAW+I,QAAQ,CAACxF,QAAQ;4DAAEW,MAAMoF;wDAAU;oDAChD;gDACF,OAAO,IAAI/F,OAAOgG,MAAM,CAACtB,kBAAkB;oDACzCjI,WAAWwJ,WAAW,CAACjG;gDACzB;4CACF;4CAEAwB,OAAOqC,IAAI,CAAC3G,SAAS4F,OAAO,CAAC,CAACoD;gDAC5B,IAAInK,SAASmK,QAAQ7B,QAAe;oDAClCA,MAAMG,cAAc;oDACpB,MAAM2B,OAAOjJ,OAAO,CAACgJ,OAAO;oDAC5B/I,WAAW6C,QAAQmG;gDACrB;4CACF;wCACF;wCACAzH,aAAapD,eAAeoD,aAAaO;wCACzCL,UAAUA;wCACV0B,eAAeA;wCACfe,YAAYA;wCACZ+E,UAAU;;;;;uBA1HX3C,KAAK4C,SAAS,CAAC;wBAAEzG;wBAAcpB;oBAAK;oBA+H1CV,sBAAsBiI,YACrBjI,kCAEA,KAACvC;wBAAkB,GAAI2C,oBAAoB,CAAC,CAAC;;;;;;AAKvD;AAEA,OAAO,MAAMoI,WAAW1K,cAAc+B,eAAc"}
1
+ {"version":3,"sources":["../../src/field/RichText.tsx"],"sourcesContent":["'use client'\n\nimport type { FormFieldBase } from '@payloadcms/ui/fields/shared'\nimport type { ClientValidate } from 'payload/types'\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 { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { FieldError } from '@payloadcms/ui/forms/FieldError'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useField } from '@payloadcms/ui/forms/useField'\nimport { withCondition } from '@payloadcms/ui/forms/withCondition'\nimport { useEditDepth } from '@payloadcms/ui/providers/EditDepth'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport { isHotkey } from 'is-hotkey'\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react'\nimport { Node, Element as SlateElement, Text, Transforms, createEditor } from 'slate'\nimport { withHistory } from 'slate-history'\nimport { Editable, Slate, withReact } from 'slate-react'\n\nimport type { ElementNode, RichTextPlugin, TextNode } from '../types.js'\nimport type { EnabledFeatures } from './types.js'\n\nimport { defaultRichTextValue } from '../data/defaultValue.js'\nimport { richTextValidate } from '../data/validation.js'\nimport { listTypes } from './elements/listTypes.js'\nimport { hotkeys } from './hotkeys.js'\nimport './index.scss'\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 & ReactEditor & HistoryEditor\n Element: ElementNode\n Text: TextNode\n }\n}\n\nconst RichTextField: React.FC<\n FormFieldBase & {\n elements: EnabledFeatures['elements']\n leaves: EnabledFeatures['leaves']\n name: string\n placeholder?: string\n plugins: RichTextPlugin[]\n richTextComponentMap: Map<string, React.ReactNode>\n width?: string\n }\n> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n elements,\n errorProps,\n label,\n labelProps,\n leaves,\n path: pathFromProps,\n placeholder,\n plugins,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate = richTextValidate,\n width,\n } = props\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: ClientValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, {\n ...validationOptions,\n req: {\n t: i18n.t,\n },\n required,\n })\n }\n },\n [validate, required, i18n],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, initialValue, path, schemaPath, setValue, showError, value } = useField(\n {\n path: pathFromContext || pathFromProps || name,\n validate: memoizedValidate,\n },\n )\n\n const disabled = readOnlyFromProps || readOnlyFromContext || 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 'left':\n attr = { ...attr, style: { marginRight: 'auto' } }\n break\n case 'right':\n attr = { ...attr, style: { marginLeft: 'auto' } }\n break\n case 'center':\n attr = { ...attr, style: { marginLeft: 'auto', marginRight: '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 'right':\n attr = { ...attr, style: { listStylePosition: 'inside', textAlign: 'right' } }\n break\n case 'center':\n attr = { ...attr, style: { listStylePosition: 'inside', textAlign: 'center' } }\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) child.setAttribute('disabled', isDisabling ? 'disabled' : null)\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 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) valueToRender = defaultRichTextValue\n\n return (\n <div\n className={classes}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${baseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\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 {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n </div>\n )\n}\n\nexport const RichText = withCondition(RichTextField)\n"],"names":["getTranslation","FieldDescription","FieldError","FieldLabel","useFieldProps","useField","withCondition","useEditDepth","useTranslation","isHotkey","React","useCallback","useEffect","useMemo","useRef","Node","Element","SlateElement","Text","Transforms","createEditor","withHistory","Editable","Slate","withReact","defaultRichTextValue","richTextValidate","listTypes","hotkeys","toggleLeaf","withEnterBreakOut","withHTML","ElementButtonProvider","ElementProvider","LeafButtonProvider","LeafProvider","baseClass","RichTextField","props","name","CustomDescription","CustomError","CustomLabel","className","descriptionProps","elements","errorProps","label","labelProps","leaves","path","pathFromProps","placeholder","plugins","readOnly","readOnlyFromProps","required","style","validate","width","i18n","editorRef","toolbarRef","drawerDepth","drawerIsOpen","memoizedValidate","value","validationOptions","req","t","pathFromContext","readOnlyFromContext","formInitializing","initialValue","schemaPath","setValue","showError","disabled","editor","CreatedEditor","length","reduce","editorWithPlugins","plugin","renderElement","attributes","children","element","matchedElement","type","attr","textAlign","marginRight","marginLeft","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","classes","Boolean","join","valueToRender","parsedJSON","JSON","parse","err","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AACoJ,OAAO;oDAC5BnJ,WAAWiD,QAAQmG;gDACrB;4CACF;wCACF;wCACA7H,aAAapD,eAAeoD,aAAaQ;wCACzCN,UAAUuB;wCACVO,eAAeA;wCACfe,YAAYA;wCACZ+E,UAAU;;;;;uBA3HX3C,KAAK4C,SAAS,CAAC;wBAAE1G;wBAAcvB;oBAAK;oBAgI1CV,sBAAsBqI,YACrBrI,kCAEA,KAACvC;wBAAkB,GAAI2C,oBAAoB,CAAC,CAAC;;;;;;AAKvD;AAEA,OAAO,MAAMwI,WAAW9K,cAAc+B,eAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../src/field/elements/Button.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAgC,MAAM,OAAO,CAAA;AAGpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,iBAAiB,CAAA;AAIxB,eAAO,MAAM,SAAS,sBAAsB,CAAA;AAE5C,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAmC/C,CAAA"}
1
+ {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../src/field/elements/Button.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAgC,MAAM,OAAO,CAAA;AAGpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,iBAAiB,CAAA;AAKxB,eAAO,MAAM,SAAS,sBAAsB,CAAA;AAE5C,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CA+C/C,CAAA"}
@@ -4,12 +4,14 @@ import { Tooltip } from '@payloadcms/ui/elements/Tooltip';
4
4
  import React, { useCallback, useState } from 'react';
5
5
  import { useSlate } from 'slate-react';
6
6
  import '../buttons.scss';
7
+ import { useElementButton } from '../providers/ElementButtonProvider.js';
7
8
  import { isElementActive } from './isActive.js';
8
9
  import { toggleElement } from './toggle.js';
9
10
  export const baseClass = 'rich-text__button';
10
11
  export const ElementButton = (props)=>{
11
- const { type = 'type', children, className, el = 'button', format, onClick, tooltip } = props;
12
+ const { type = 'type', children, className, disabled: disabledFromProps, el = 'button', format, onClick, tooltip } = props;
12
13
  const editor = useSlate();
14
+ const { disabled: disabledFromContext } = useElementButton();
13
15
  const [showTooltip, setShowTooltip] = useState(false);
14
16
  const defaultOnClick = useCallback((event)=>{
15
17
  event.preventDefault();
@@ -21,9 +23,11 @@ export const ElementButton = (props)=>{
21
23
  type
22
24
  ]);
23
25
  const Tag = el;
26
+ const disabled = disabledFromProps || disabledFromContext;
24
27
  return /*#__PURE__*/ _jsxs(Tag, {
25
28
  ...el === 'button' && {
26
- type: 'button'
29
+ type: 'button',
30
+ disabled
27
31
  },
28
32
  className: [
29
33
  baseClass,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/field/elements/Button.tsx"],"sourcesContent":["'use client'\nimport type { ElementType } from 'react'\n\nimport { Tooltip } from '@payloadcms/ui/elements/Tooltip'\nimport React, { useCallback, useState } from 'react'\nimport { useSlate } from 'slate-react'\n\nimport type { ButtonProps } from './types.js'\n\nimport '../buttons.scss'\nimport { isElementActive } from './isActive.js'\nimport { toggleElement } from './toggle.js'\n\nexport const baseClass = 'rich-text__button'\n\nexport const ElementButton: React.FC<ButtonProps> = (props) => {\n const { type = 'type', children, className, el = 'button', format, onClick, tooltip } = props\n\n const editor = useSlate()\n const [showTooltip, setShowTooltip] = useState(false)\n\n const defaultOnClick = useCallback(\n (event) => {\n event.preventDefault()\n setShowTooltip(false)\n toggleElement(editor, format, type)\n },\n [editor, format, type],\n )\n\n const Tag: ElementType = el\n\n return (\n <Tag\n {...(el === 'button' && { type: 'button' })}\n className={[\n baseClass,\n className,\n isElementActive(editor, format, type) && `${baseClass}__button--active`,\n ]\n .filter(Boolean)\n .join(' ')}\n onClick={onClick || defaultOnClick}\n onMouseEnter={() => setShowTooltip(true)}\n onMouseLeave={() => setShowTooltip(false)}\n >\n {tooltip && <Tooltip show={showTooltip}>{tooltip}</Tooltip>}\n {children}\n </Tag>\n )\n}\n"],"names":["Tooltip","React","useCallback","useState","useSlate","isElementActive","toggleElement","baseClass","ElementButton","props","type","children","className","el","format","onClick","tooltip","editor","showTooltip","setShowTooltip","defaultOnClick","event","preventDefault","Tag","filter","Boolean","join","onMouseEnter","onMouseLeave","show"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,SAASA,OAAO,QAAQ,kCAAiC;AACzD,OAAOC,SAASC,WAAW,EAAEC,QAAQ,QAAQ,QAAO;AACpD,SAASC,QAAQ,QAAQ,cAAa;AAItC,OAAO,kBAAiB;AACxB,SAASC,eAAe,QAAQ,gBAAe;AAC/C,SAASC,aAAa,QAAQ,cAAa;AAE3C,OAAO,MAAMC,YAAY,oBAAmB;AAE5C,OAAO,MAAMC,gBAAuC,CAACC;IACnD,MAAM,EAAEC,OAAO,MAAM,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,KAAK,QAAQ,EAAEC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGP;IAExF,MAAMQ,SAASb;IACf,MAAM,CAACc,aAAaC,eAAe,GAAGhB,SAAS;IAE/C,MAAMiB,iBAAiBlB,YACrB,CAACmB;QACCA,MAAMC,cAAc;QACpBH,eAAe;QACfb,cAAcW,QAAQH,QAAQJ;IAChC,GACA;QAACO;QAAQH;QAAQJ;KAAK;IAGxB,MAAMa,MAAmBV;IAEzB,qBACE,MAACU;QACE,GAAIV,OAAO,YAAY;YAAEH,MAAM;QAAS,CAAC;QAC1CE,WAAW;YACTL;YACAK;YACAP,gBAAgBY,QAAQH,QAAQJ,SAAS,CAAC,EAAEH,UAAU,gBAAgB,CAAC;SACxE,CACEiB,MAAM,CAACC,SACPC,IAAI,CAAC;QACRX,SAASA,WAAWK;QACpBO,cAAc,IAAMR,eAAe;QACnCS,cAAc,IAAMT,eAAe;;YAElCH,yBAAW,KAAChB;gBAAQ6B,MAAMX;0BAAcF;;YACxCL;;;AAGP,EAAC"}
1
+ {"version":3,"sources":["../../../src/field/elements/Button.tsx"],"sourcesContent":["'use client'\nimport type { ElementType } from 'react'\n\nimport { Tooltip } from '@payloadcms/ui/elements/Tooltip'\nimport React, { useCallback, useState } from 'react'\nimport { useSlate } from 'slate-react'\n\nimport type { ButtonProps } from './types.js'\n\nimport '../buttons.scss'\nimport { useElementButton } from '../providers/ElementButtonProvider.js'\nimport { isElementActive } from './isActive.js'\nimport { toggleElement } from './toggle.js'\n\nexport const baseClass = 'rich-text__button'\n\nexport const ElementButton: React.FC<ButtonProps> = (props) => {\n const {\n type = 'type',\n children,\n className,\n disabled: disabledFromProps,\n el = 'button',\n format,\n onClick,\n tooltip,\n } = props\n\n const editor = useSlate()\n const { disabled: disabledFromContext } = useElementButton()\n const [showTooltip, setShowTooltip] = useState(false)\n\n const defaultOnClick = useCallback(\n (event) => {\n event.preventDefault()\n setShowTooltip(false)\n toggleElement(editor, format, type)\n },\n [editor, format, type],\n )\n\n const Tag: ElementType = el\n\n const disabled = disabledFromProps || disabledFromContext\n\n return (\n <Tag\n {...(el === 'button' && { type: 'button', disabled })}\n className={[\n baseClass,\n className,\n isElementActive(editor, format, type) && `${baseClass}__button--active`,\n ]\n .filter(Boolean)\n .join(' ')}\n onClick={onClick || defaultOnClick}\n onMouseEnter={() => setShowTooltip(true)}\n onMouseLeave={() => setShowTooltip(false)}\n >\n {tooltip && <Tooltip show={showTooltip}>{tooltip}</Tooltip>}\n {children}\n </Tag>\n )\n}\n"],"names":["Tooltip","React","useCallback","useState","useSlate","useElementButton","isElementActive","toggleElement","baseClass","ElementButton","props","type","children","className","disabled","disabledFromProps","el","format","onClick","tooltip","editor","disabledFromContext","showTooltip","setShowTooltip","defaultOnClick","event","preventDefault","Tag","filter","Boolean","join","onMouseEnter","onMouseLeave","show"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,SAASA,OAAO,QAAQ,kCAAiC;AACzD,OAAOC,SAASC,WAAW,EAAEC,QAAQ,QAAQ,QAAO;AACpD,SAASC,QAAQ,QAAQ,cAAa;AAItC,OAAO,kBAAiB;AACxB,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,eAAe,QAAQ,gBAAe;AAC/C,SAASC,aAAa,QAAQ,cAAa;AAE3C,OAAO,MAAMC,YAAY,oBAAmB;AAE5C,OAAO,MAAMC,gBAAuC,CAACC;IACnD,MAAM,EACJC,OAAO,MAAM,EACbC,QAAQ,EACRC,SAAS,EACTC,UAAUC,iBAAiB,EAC3BC,KAAK,QAAQ,EACbC,MAAM,EACNC,OAAO,EACPC,OAAO,EACR,GAAGT;IAEJ,MAAMU,SAAShB;IACf,MAAM,EAAEU,UAAUO,mBAAmB,EAAE,GAAGhB;IAC1C,MAAM,CAACiB,aAAaC,eAAe,GAAGpB,SAAS;IAE/C,MAAMqB,iBAAiBtB,YACrB,CAACuB;QACCA,MAAMC,cAAc;QACpBH,eAAe;QACfhB,cAAca,QAAQH,QAAQN;IAChC,GACA;QAACS;QAAQH;QAAQN;KAAK;IAGxB,MAAMgB,MAAmBX;IAEzB,MAAMF,WAAWC,qBAAqBM;IAEtC,qBACE,MAACM;QACE,GAAIX,OAAO,YAAY;YAAEL,MAAM;YAAUG;QAAS,CAAC;QACpDD,WAAW;YACTL;YACAK;YACAP,gBAAgBc,QAAQH,QAAQN,SAAS,CAAC,EAAEH,UAAU,gBAAgB,CAAC;SACxE,CACEoB,MAAM,CAACC,SACPC,IAAI,CAAC;QACRZ,SAASA,WAAWM;QACpBO,cAAc,IAAMR,eAAe;QACnCS,cAAc,IAAMT,eAAe;;YAElCJ,yBAAW,KAACnB;gBAAQiC,MAAMX;0BAAcH;;YACxCP;;;AAGP,EAAC"}
@@ -2,6 +2,7 @@ import type { ElementType } from 'react';
2
2
  export type ButtonProps = {
3
3
  children?: React.ReactNode;
4
4
  className?: string;
5
+ disabled?: boolean;
5
6
  el?: ElementType;
6
7
  format: string;
7
8
  onClick?: (e: React.MouseEvent) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/field/elements/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAExC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,EAAE,CAAC,EAAE,WAAW,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAA;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/field/elements/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAExC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,EAAE,CAAC,EAAE,WAAW,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAA;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/field/elements/types.ts"],"sourcesContent":["import type { ElementType } from 'react'\n\nexport type ButtonProps = {\n children?: React.ReactNode\n className?: string\n el?: ElementType\n format: string\n onClick?: (e: React.MouseEvent) => void\n tooltip?: string\n type?: string\n}\n"],"names":[],"rangeMappings":"","mappings":"AAEA,WAQC"}
1
+ {"version":3,"sources":["../../../src/field/elements/types.ts"],"sourcesContent":["import type { ElementType } from 'react'\n\nexport type ButtonProps = {\n children?: React.ReactNode\n className?: string\n disabled?: boolean\n el?: ElementType\n format: string\n onClick?: (e: React.MouseEvent) => void\n tooltip?: string\n type?: string\n}\n"],"names":[],"rangeMappings":"","mappings":"AAEA,WASC"}
@@ -1,6 +1,7 @@
1
1
  import type { FormFieldBase } from '@payloadcms/ui/fields/shared';
2
2
  import React from 'react';
3
3
  type ElementButtonContextType = {
4
+ disabled?: boolean;
4
5
  fieldProps: FormFieldBase & {
5
6
  name: string;
6
7
  richTextComponentMap: Map<string, React.ReactNode>;
@@ -1 +1 @@
1
- {"version":3,"file":"ElementButtonProvider.d.ts","sourceRoot":"","sources":["../../../src/field/providers/ElementButtonProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,KAAK,wBAAwB,GAAG;IAC9B,UAAU,EAAE,aAAa,GAAG;QAC1B,IAAI,EAAE,MAAM,CAAA;QACZ,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;KACnD,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAQD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,wBAAwB,GAAG;IACzB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAaF,CAAA;AAED,eAAO,MAAM,gBAAgB,gCAG5B,CAAA"}
1
+ {"version":3,"file":"ElementButtonProvider.d.ts","sourceRoot":"","sources":["../../../src/field/providers/ElementButtonProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,aAAa,GAAG;QAC1B,IAAI,EAAE,MAAM,CAAA;QACZ,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;KACnD,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAQD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,wBAAwB,GAAG;IACzB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAaF,CAAA;AAED,eAAO,MAAM,gBAAgB,gCAG5B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/field/providers/ElementButtonProvider.tsx"],"sourcesContent":["'use client'\n\nimport type { FormFieldBase } from '@payloadcms/ui/fields/shared'\n\nimport React from 'react'\n\ntype ElementButtonContextType = {\n fieldProps: FormFieldBase & {\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n }\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 ElementButtonContextType & {\n children: React.ReactNode\n }\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAIA,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"}
1
+ {"version":3,"sources":["../../../src/field/providers/ElementButtonProvider.tsx"],"sourcesContent":["'use client'\n\nimport type { FormFieldBase } from '@payloadcms/ui/fields/shared'\n\nimport React from 'react'\n\ntype ElementButtonContextType = {\n disabled?: boolean\n fieldProps: FormFieldBase & {\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n }\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 ElementButtonContextType & {\n children: React.ReactNode\n }\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAIA,OAAOA,WAAW,QAAO;AAYzB,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/richtext-slate",
3
- "version": "3.0.0-beta.36",
3
+ "version": "3.0.0-beta.38",
4
4
  "description": "The officially supported Slate richtext adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -36,15 +36,15 @@
36
36
  "@types/node": "20.12.5",
37
37
  "@types/react": "npm:types-react@19.0.0-beta.2",
38
38
  "@types/react-dom": "npm:types-react-dom@19.0.0-beta.2",
39
- "payload": "3.0.0-beta.36",
40
- "@payloadcms/ui": "3.0.0-beta.36",
41
- "@payloadcms/eslint-config": "1.1.1"
39
+ "@payloadcms/eslint-config": "1.1.1",
40
+ "payload": "3.0.0-beta.38",
41
+ "@payloadcms/ui": "3.0.0-beta.38"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "^19.0.0 || ^19.0.0-rc-f994737d14-20240522",
45
- "@payloadcms/translations": "3.0.0-beta.36",
46
- "@payloadcms/ui": "3.0.0-beta.36",
47
- "payload": "3.0.0-beta.36"
45
+ "@payloadcms/translations": "3.0.0-beta.38",
46
+ "@payloadcms/ui": "3.0.0-beta.38",
47
+ "payload": "3.0.0-beta.38"
48
48
  },
49
49
  "engines": {
50
50
  "node": ">=18.20.2"