@payloadcms/richtext-lexical 3.0.0-beta.70 → 3.0.0-beta.71
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/exports/client/{Field-6VQ73D3D.js → Field-YNHIDK3D.js} +2 -2
- package/dist/exports/client/Field-YNHIDK3D.js.map +7 -0
- package/dist/exports/client/{RelationshipComponent-FFJCVTWM.js → RelationshipComponent-ZR2OCBGL.js} +2 -2
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/{chunk-HO42U3IJ.js → chunk-6QXGZYUK.js} +2 -2
- package/dist/exports/client/{chunk-SFUMQAVE.js → chunk-IPCJ5EVK.js} +2 -2
- package/dist/exports/client/{chunk-QZIAQPM7.js → chunk-IWZVO3AI.js} +2 -2
- package/dist/exports/client/chunk-IWZVO3AI.js.map +7 -0
- package/dist/exports/client/{chunk-KTD7OXVC.js → chunk-VUVXZJJR.js} +2 -2
- package/dist/exports/client/{component-5K355FZZ.js → component-D4GWDXK5.js} +2 -2
- package/dist/exports/client/{component-TYPMHBL7.js → component-KA7FDRMA.js} +2 -2
- package/dist/exports/client/component-KA7FDRMA.js.map +7 -0
- package/dist/exports/client/{componentInline-3JDU4HVQ.js → componentInline-6EKPZSCV.js} +2 -2
- package/dist/exports/client/index.js +3 -3
- package/dist/exports/client/index.js.map +2 -2
- package/dist/features/blocks/component/BlockContent.d.ts +1 -2
- package/dist/features/blocks/component/BlockContent.d.ts.map +1 -1
- package/dist/features/blocks/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/feature.client.d.ts +1 -2
- package/dist/features/blocks/feature.client.d.ts.map +1 -1
- package/dist/features/blocks/feature.client.js.map +1 -1
- package/dist/field/Field.d.ts +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js.map +1 -1
- package/dist/field/index.d.ts +1 -1
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +7 -7
- package/dist/field/index.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts +1 -1
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.d.ts +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.d.ts.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
- package/package.json +9 -9
- package/dist/exports/client/Field-6VQ73D3D.js.map +0 -7
- package/dist/exports/client/chunk-QZIAQPM7.js.map +0 -7
- package/dist/exports/client/component-TYPMHBL7.js.map +0 -7
- /package/dist/exports/client/{RelationshipComponent-FFJCVTWM.js.map → RelationshipComponent-ZR2OCBGL.js.map} +0 -0
- /package/dist/exports/client/{chunk-HO42U3IJ.js.map → chunk-6QXGZYUK.js.map} +0 -0
- /package/dist/exports/client/{chunk-SFUMQAVE.js.map → chunk-IPCJ5EVK.js.map} +0 -0
- /package/dist/exports/client/{chunk-KTD7OXVC.js.map → chunk-VUVXZJJR.js.map} +0 -0
- /package/dist/exports/client/{component-5K355FZZ.js.map → component-D4GWDXK5.js.map} +0 -0
- /package/dist/exports/client/{componentInline-3JDU4HVQ.js.map → componentInline-6EKPZSCV.js.map} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { FormFieldBase } from '
|
|
2
|
-
import type { FieldMap } from '@payloadcms/ui/utilities/buildComponentMap';
|
|
1
|
+
import type { FieldMap, FormFieldBase } from 'payload';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import type { SanitizedClientEditorConfig } from '../../../lexical/config/types.js';
|
|
5
4
|
import type { ClientBlock } from '../feature.client.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockContent.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/component/BlockContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"BlockContent.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/component/BlockContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8B,QAAQ,EAAE,aAAa,EAAa,MAAM,SAAS,CAAA;AAiB7F,OAAO,KAAsB,MAAM,OAAO,CAAA;AAE1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AACnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,wBAAwB,CAAA;AAIpE,KAAK,KAAK,GAAG;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE;QACL,YAAY,EAAE,2BAA2B,CAAA;QACzC,IAAI,EAAE,MAAM,CAAA;QACZ,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;KACnD,GAAG,aAAa,CAAA;IACjB,QAAQ,EAAE,WAAW,CAAA;IACrB,UAAU,EAAE,QAAQ,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,WAAW,CAAA;IACzB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAgNxC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/features/blocks/component/BlockContent.tsx"],"sourcesContent":["import type { FormFieldBase } from '@payloadcms/ui'\nimport type { FieldMap } from '@payloadcms/ui/utilities/buildComponentMap'\nimport type { CollapsedPreferences, Data, FormState } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Collapsible,\n ErrorPill,\n Pill,\n RenderFields,\n SectionTitle,\n useDocumentInfo,\n useFormSubmitted,\n useTranslation,\n} from '@payloadcms/ui'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport { $getNodeByKey } from 'lexical'\nimport React, { useCallback } from 'react'\n\nimport type { SanitizedClientEditorConfig } from '../../../lexical/config/types.js'\nimport type { ClientBlock } from '../feature.client.js'\nimport type { BlockFields, BlockNode } from '../nodes/BlocksNode.js'\n\nimport { FormSavePlugin } from './FormSavePlugin.js'\n\ntype Props = {\n baseClass: string\n field: {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n } & FormFieldBase\n formData: BlockFields\n formSchema: FieldMap\n nodeKey: string\n path: string\n reducedBlock: ClientBlock\n schemaPath: string\n}\n\n/**\n * The actual content of the Block. This should be INSIDE a Form component,\n * scoped to the block. All format operations in here are thus scoped to the block's form, and\n * not the whole document.\n */\nexport const BlockContent: React.FC<Props> = (props) => {\n const {\n baseClass,\n field,\n formData,\n formSchema,\n nodeKey,\n reducedBlock: { LabelComponent, labels },\n schemaPath,\n } = props\n\n const { i18n } = useTranslation()\n const [editor] = useLexicalComposerContext()\n // Used for saving collapsed to preferences (and gettin' it from there again)\n // Remember, these preferences are scoped to the whole document, not just this form. This\n // is important to consider for the data path used in setDocFieldPreferences\n const { getDocPreferences, setDocFieldPreferences } = useDocumentInfo()\n\n const [isCollapsed, setIsCollapsed] = React.useState<boolean>(() => {\n let initialState = false\n\n void getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedArray = currentFieldPreferences?.collapsed\n\n if (collapsedArray && collapsedArray.includes(formData.id)) {\n initialState = true\n setIsCollapsed(true)\n }\n })\n return initialState\n })\n\n const hasSubmitted = useFormSubmitted()\n\n const [errorCount, setErrorCount] = React.useState(0)\n\n const fieldHasErrors = hasSubmitted && errorCount > 0\n\n const classNames = [\n `${baseClass}__row`,\n fieldHasErrors ? `${baseClass}__row--has-errors` : `${baseClass}__row--no-errors`,\n ]\n .filter(Boolean)\n .join(' ')\n\n const onFormChange = useCallback(\n ({\n fullFieldsWithValues,\n newFormData,\n }: {\n fullFieldsWithValues: FormState\n newFormData: Data\n }) => {\n newFormData = {\n ...newFormData,\n id: formData.id,\n blockType: formData.blockType,\n }\n\n // Recursively remove all undefined values from even being present in formData, as they will\n // cause isDeepEqual to return false if, for example, formData has a key that fields.data\n // does not have, even if it's undefined.\n // Currently, this happens if a block has another sub-blocks field. Inside formData, that sub-blocks field has an undefined blockName property.\n // Inside of fields.data however, that sub-blocks blockName property does not exist at all.\n function removeUndefinedAndNullAndEmptyArraysRecursively(obj: object) {\n for (const key in obj) {\n const value = obj[key]\n if (Array.isArray(value) && !value?.length) {\n delete obj[key]\n } else if (value && typeof value === 'object') {\n removeUndefinedAndNullAndEmptyArraysRecursively(value)\n } else if (value === undefined || value === null) {\n delete obj[key]\n }\n }\n }\n removeUndefinedAndNullAndEmptyArraysRecursively(newFormData)\n\n removeUndefinedAndNullAndEmptyArraysRecursively(formData)\n\n // Only update if the data has actually changed. Otherwise, we may be triggering an unnecessary value change,\n // which would trigger the \"Leave without saving\" dialog unnecessarily\n if (!dequal(formData, newFormData)) {\n // Running this in the next tick in the meantime fixes this issue: https://github.com/payloadcms/payload/issues/4108\n // I don't know why. When this is called immediately, it might focus out of a nested lexical editor field if an update is made there.\n // My hypothesis is that the nested editor might not have fully finished its update cycle yet. By updating in the next tick, we\n // ensure that the nested editor has finished its update cycle before we update the block node.\n setTimeout(() => {\n editor.update(() => {\n const node: BlockNode = $getNodeByKey(nodeKey)\n if (node) {\n node.setFields(newFormData as BlockFields)\n }\n })\n }, 0)\n }\n\n // update error count\n if (hasSubmitted) {\n let rowErrorCount = 0\n for (const formField of Object.values(fullFieldsWithValues)) {\n if (formField?.valid === false) {\n rowErrorCount++\n }\n }\n setErrorCount(rowErrorCount)\n }\n },\n [editor, nodeKey, hasSubmitted, formData],\n )\n\n const onCollapsedChange = useCallback(\n (changedCollapsed: boolean) => {\n void getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedArray = currentFieldPreferences?.collapsed\n\n const newCollapsed: CollapsedPreferences =\n collapsedArray && collapsedArray?.length ? collapsedArray : []\n\n if (changedCollapsed) {\n if (!newCollapsed.includes(formData.id)) {\n newCollapsed.push(formData.id)\n }\n } else {\n if (newCollapsed.includes(formData.id)) {\n newCollapsed.splice(newCollapsed.indexOf(formData.id), 1)\n }\n }\n\n setDocFieldPreferences(field.name, {\n collapsed: newCollapsed,\n hello: 'hi',\n })\n })\n },\n [getDocPreferences, field.name, setDocFieldPreferences, formData.id],\n )\n\n const removeBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey).remove()\n })\n }, [editor, nodeKey])\n\n return (\n <React.Fragment>\n <Collapsible\n className={classNames}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n LabelComponent ? (\n <LabelComponent blockKind={'lexicalBlock'} formData={formData} />\n ) : (\n <div className={`${baseClass}__block-header`}>\n <div>\n <Pill\n className={`${baseClass}__block-pill ${baseClass}__block-pill-${formData?.blockType}`}\n pillStyle=\"white\"\n >\n {typeof labels.singular === 'string'\n ? getTranslation(labels.singular, i18n)\n : '[Singular Label]'}\n </Pill>\n <SectionTitle path=\"blockName\" readOnly={field?.readOnly} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n {editor.isEditable() && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeBlock()\n }}\n round\n tooltip=\"Remove Block\"\n />\n )}\n </div>\n )\n }\n isCollapsed={isCollapsed}\n key={0}\n onToggle={(incomingCollapsedState) => {\n onCollapsedChange(incomingCollapsedState)\n setIsCollapsed(incomingCollapsedState)\n }}\n >\n <RenderFields\n className={`${baseClass}__fields`}\n fieldMap={Array.isArray(formSchema) ? formSchema : []}\n forceRender\n margins=\"small\"\n path=\"\" // Leaving path empty makes it so field values are not prefixed / scoped by the entire schemaPath. e.g. we can access \"myField\" instead of \"someLexicalField.feature.blocks.someArrayB\" // TODO: Could there be any implications leaving path different than schemaPath?\n readOnly={false}\n schemaPath={schemaPath} // Having the correct schemaPath here allows sub-fields (like array > addRow) to run correct form-state calls and retrieve their needed form state from the server\n />\n </Collapsible>\n\n <FormSavePlugin onChange={onFormChange} />\n </React.Fragment>\n )\n}\n"],"names":["useLexicalComposerContext","getTranslation","Button","Collapsible","ErrorPill","Pill","RenderFields","SectionTitle","useDocumentInfo","useFormSubmitted","useTranslation","dequal","$getNodeByKey","React","useCallback","FormSavePlugin","BlockContent","props","baseClass","field","formData","formSchema","nodeKey","reducedBlock","LabelComponent","labels","schemaPath","i18n","editor","getDocPreferences","setDocFieldPreferences","isCollapsed","setIsCollapsed","useState","initialState","then","currentDocPreferences","currentFieldPreferences","fields","name","collapsedArray","collapsed","includes","id","hasSubmitted","errorCount","setErrorCount","fieldHasErrors","classNames","filter","Boolean","join","onFormChange","fullFieldsWithValues","newFormData","blockType","removeUndefinedAndNullAndEmptyArraysRecursively","obj","key","value","Array","isArray","length","undefined","setTimeout","update","node","setFields","rowErrorCount","formField","Object","values","valid","onCollapsedChange","changedCollapsed","newCollapsed","push","splice","indexOf","hello","removeBlock","remove","Fragment","className","collapsibleStyle","header","blockKind","div","pillStyle","singular","path","readOnly","count","withMessage","isEditable","buttonStyle","disabled","icon","onClick","e","preventDefault","round","tooltip","onToggle","incomingCollapsedState","fieldMap","forceRender","margins","onChange"],"mappings":";AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,IAAI,EACJC,YAAY,EACZC,YAAY,EACZC,eAAe,EACfC,gBAAgB,EAChBC,cAAc,QACT,iBAAgB;AACvB,SAASC,MAAM,QAAQ,cAAa,CAAC,wCAAwC;AAC7E,SAASC,aAAa,QAAQ,UAAS;AACvC,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAM1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AAc,CAAC;4BACvC8E,UAAU7E,OAAOwE;4BACjBM,MAAK;4BACLC,SAAS,CAACC;gCACRA,EAAEC,cAAc;gCAChBpB;4BACF;4BACAqB,KAAK;4BACLC,SAAQ;;;;gBAMlBvE,aAAaA;gBAEbwE,UAAU,CAACC;oBACT/B,kBAAkB+B;oBAClBxE,eAAewE;gBACjB;0BAEA,cAAA,KAAClG;oBACC6E,WAAW,CAAC,EAAEjE,UAAU,QAAQ,CAAC;oBACjCuF,UAAU7C,MAAMC,OAAO,CAACxC,cAAcA,aAAa,EAAE;oBACrDqF,WAAW;oBACXC,SAAQ;oBACRjB,MAAK,GAAG,wQAAwQ;;oBAChRC,UAAU;oBACVjE,YAAYA;;eAbT;0BAiBP,KAACX;gBAAe6F,UAAUxD;;;;AAGhC,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/blocks/component/BlockContent.tsx"],"sourcesContent":["import type { CollapsedPreferences, Data, FieldMap, FormFieldBase, FormState } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Collapsible,\n ErrorPill,\n Pill,\n RenderFields,\n SectionTitle,\n useDocumentInfo,\n useFormSubmitted,\n useTranslation,\n} from '@payloadcms/ui'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport { $getNodeByKey } from 'lexical'\nimport React, { useCallback } from 'react'\n\nimport type { SanitizedClientEditorConfig } from '../../../lexical/config/types.js'\nimport type { ClientBlock } from '../feature.client.js'\nimport type { BlockFields, BlockNode } from '../nodes/BlocksNode.js'\n\nimport { FormSavePlugin } from './FormSavePlugin.js'\n\ntype Props = {\n baseClass: string\n field: {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n } & FormFieldBase\n formData: BlockFields\n formSchema: FieldMap\n nodeKey: string\n path: string\n reducedBlock: ClientBlock\n schemaPath: string\n}\n\n/**\n * The actual content of the Block. This should be INSIDE a Form component,\n * scoped to the block. All format operations in here are thus scoped to the block's form, and\n * not the whole document.\n */\nexport const BlockContent: React.FC<Props> = (props) => {\n const {\n baseClass,\n field,\n formData,\n formSchema,\n nodeKey,\n reducedBlock: { LabelComponent, labels },\n schemaPath,\n } = props\n\n const { i18n } = useTranslation()\n const [editor] = useLexicalComposerContext()\n // Used for saving collapsed to preferences (and gettin' it from there again)\n // Remember, these preferences are scoped to the whole document, not just this form. This\n // is important to consider for the data path used in setDocFieldPreferences\n const { getDocPreferences, setDocFieldPreferences } = useDocumentInfo()\n\n const [isCollapsed, setIsCollapsed] = React.useState<boolean>(() => {\n let initialState = false\n\n void getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedArray = currentFieldPreferences?.collapsed\n\n if (collapsedArray && collapsedArray.includes(formData.id)) {\n initialState = true\n setIsCollapsed(true)\n }\n })\n return initialState\n })\n\n const hasSubmitted = useFormSubmitted()\n\n const [errorCount, setErrorCount] = React.useState(0)\n\n const fieldHasErrors = hasSubmitted && errorCount > 0\n\n const classNames = [\n `${baseClass}__row`,\n fieldHasErrors ? `${baseClass}__row--has-errors` : `${baseClass}__row--no-errors`,\n ]\n .filter(Boolean)\n .join(' ')\n\n const onFormChange = useCallback(\n ({\n fullFieldsWithValues,\n newFormData,\n }: {\n fullFieldsWithValues: FormState\n newFormData: Data\n }) => {\n newFormData = {\n ...newFormData,\n id: formData.id,\n blockType: formData.blockType,\n }\n\n // Recursively remove all undefined values from even being present in formData, as they will\n // cause isDeepEqual to return false if, for example, formData has a key that fields.data\n // does not have, even if it's undefined.\n // Currently, this happens if a block has another sub-blocks field. Inside formData, that sub-blocks field has an undefined blockName property.\n // Inside of fields.data however, that sub-blocks blockName property does not exist at all.\n function removeUndefinedAndNullAndEmptyArraysRecursively(obj: object) {\n for (const key in obj) {\n const value = obj[key]\n if (Array.isArray(value) && !value?.length) {\n delete obj[key]\n } else if (value && typeof value === 'object') {\n removeUndefinedAndNullAndEmptyArraysRecursively(value)\n } else if (value === undefined || value === null) {\n delete obj[key]\n }\n }\n }\n removeUndefinedAndNullAndEmptyArraysRecursively(newFormData)\n\n removeUndefinedAndNullAndEmptyArraysRecursively(formData)\n\n // Only update if the data has actually changed. Otherwise, we may be triggering an unnecessary value change,\n // which would trigger the \"Leave without saving\" dialog unnecessarily\n if (!dequal(formData, newFormData)) {\n // Running this in the next tick in the meantime fixes this issue: https://github.com/payloadcms/payload/issues/4108\n // I don't know why. When this is called immediately, it might focus out of a nested lexical editor field if an update is made there.\n // My hypothesis is that the nested editor might not have fully finished its update cycle yet. By updating in the next tick, we\n // ensure that the nested editor has finished its update cycle before we update the block node.\n setTimeout(() => {\n editor.update(() => {\n const node: BlockNode = $getNodeByKey(nodeKey)\n if (node) {\n node.setFields(newFormData as BlockFields)\n }\n })\n }, 0)\n }\n\n // update error count\n if (hasSubmitted) {\n let rowErrorCount = 0\n for (const formField of Object.values(fullFieldsWithValues)) {\n if (formField?.valid === false) {\n rowErrorCount++\n }\n }\n setErrorCount(rowErrorCount)\n }\n },\n [editor, nodeKey, hasSubmitted, formData],\n )\n\n const onCollapsedChange = useCallback(\n (changedCollapsed: boolean) => {\n void getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedArray = currentFieldPreferences?.collapsed\n\n const newCollapsed: CollapsedPreferences =\n collapsedArray && collapsedArray?.length ? collapsedArray : []\n\n if (changedCollapsed) {\n if (!newCollapsed.includes(formData.id)) {\n newCollapsed.push(formData.id)\n }\n } else {\n if (newCollapsed.includes(formData.id)) {\n newCollapsed.splice(newCollapsed.indexOf(formData.id), 1)\n }\n }\n\n setDocFieldPreferences(field.name, {\n collapsed: newCollapsed,\n hello: 'hi',\n })\n })\n },\n [getDocPreferences, field.name, setDocFieldPreferences, formData.id],\n )\n\n const removeBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey).remove()\n })\n }, [editor, nodeKey])\n\n return (\n <React.Fragment>\n <Collapsible\n className={classNames}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n LabelComponent ? (\n <LabelComponent blockKind={'lexicalBlock'} formData={formData} />\n ) : (\n <div className={`${baseClass}__block-header`}>\n <div>\n <Pill\n className={`${baseClass}__block-pill ${baseClass}__block-pill-${formData?.blockType}`}\n pillStyle=\"white\"\n >\n {typeof labels.singular === 'string'\n ? getTranslation(labels.singular, i18n)\n : '[Singular Label]'}\n </Pill>\n <SectionTitle path=\"blockName\" readOnly={field?.readOnly} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n {editor.isEditable() && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeBlock()\n }}\n round\n tooltip=\"Remove Block\"\n />\n )}\n </div>\n )\n }\n isCollapsed={isCollapsed}\n key={0}\n onToggle={(incomingCollapsedState) => {\n onCollapsedChange(incomingCollapsedState)\n setIsCollapsed(incomingCollapsedState)\n }}\n >\n <RenderFields\n className={`${baseClass}__fields`}\n fieldMap={Array.isArray(formSchema) ? formSchema : []}\n forceRender\n margins=\"small\"\n path=\"\" // Leaving path empty makes it so field values are not prefixed / scoped by the entire schemaPath. e.g. we can access \"myField\" instead of \"someLexicalField.feature.blocks.someArrayB\" // TODO: Could there be any implications leaving path different than schemaPath?\n readOnly={false}\n schemaPath={schemaPath} // Having the correct schemaPath here allows sub-fields (like array > addRow) to run correct form-state calls and retrieve their needed form state from the server\n />\n </Collapsible>\n\n <FormSavePlugin onChange={onFormChange} />\n </React.Fragment>\n )\n}\n"],"names":["useLexicalComposerContext","getTranslation","Button","Collapsible","ErrorPill","Pill","RenderFields","SectionTitle","useDocumentInfo","useFormSubmitted","useTranslation","dequal","$getNodeByKey","React","useCallback","FormSavePlugin","BlockContent","props","baseClass","field","formData","formSchema","nodeKey","reducedBlock","LabelComponent","labels","schemaPath","i18n","editor","getDocPreferences","setDocFieldPreferences","isCollapsed","setIsCollapsed","useState","initialState","then","currentDocPreferences","currentFieldPreferences","fields","name","collapsedArray","collapsed","includes","id","hasSubmitted","errorCount","setErrorCount","fieldHasErrors","classNames","filter","Boolean","join","onFormChange","fullFieldsWithValues","newFormData","blockType","removeUndefinedAndNullAndEmptyArraysRecursively","obj","key","value","Array","isArray","length","undefined","setTimeout","update","node","setFields","rowErrorCount","formField","Object","values","valid","onCollapsedChange","changedCollapsed","newCollapsed","push","splice","indexOf","hello","removeBlock","remove","Fragment","className","collapsibleStyle","header","blockKind","div","pillStyle","singular","path","readOnly","count","withMessage","isEditable","buttonStyle","disabled","icon","onClick","e","preventDefault","round","tooltip","onToggle","incomingCollapsedState","fieldMap","forceRender","margins","onChange"],"mappings":";AAEA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,IAAI,EACJC,YAAY,EACZC,YAAY,EACZC,eAAe,EACfC,gBAAgB,EAChBC,cAAc,QACT,iBAAgB;AACvB,SAASC,MAAM,QAAQ,cAAa,CAAC,wCAAwC;AAC7E,SAASC,aAAa,QAAQ,UAAS;AACvC,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAM1C,SAASC,cAAc,QAAQ,sBAAqB;AAiBpD;;;;CAIC,GACD,OAAO,MAAMC,eAAgC,CAACC;IAC5C,MAAM,EACJC,SAAS,EACTC,KAAK,EACLC,QAAQ,EACRC,UAAU,EACVC,OAAO,EACPC,cAAc,EAAEC,cAAc,EAAEC,MAAM,EAAE,EACxCC,UAAU,EACX,GAAGT;IAEJ,MAAM,EAAEU,IAAI,EAAE,GAAGjB;IACjB,MAAM,CAACkB,OAAO,GAAG5B;IACjB,6EAA6E;IAC7E,yFAAyF;IACzF,4EAA4E;IAC5E,MAAM,EAAE6B,iBAAiB,EAAEC,s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ACRjB,MAAK,GAAG,wQAAwQ;;oBAChRC,UAAU;oBACVjE,YAAYA;;eAbT;0BAiBP,KAACX;gBAAe6F,UAAUxD;;;;AAGhC,EAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ReducedBlock } from '
|
|
2
|
-
import type { Block } from 'payload';
|
|
1
|
+
import type { Block, ReducedBlock } from 'payload';
|
|
3
2
|
export type ClientBlock = {
|
|
4
3
|
LabelComponent?: Block['admin']['components']['Label'];
|
|
5
4
|
} & ReducedBlock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.client.d.ts","sourceRoot":"","sources":["../../../src/features/blocks/feature.client.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"feature.client.d.ts","sourceRoot":"","sources":["../../../src/features/blocks/feature.client.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAclD,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAA;CACvD,GAAG,YAAY,CAAA;AAEhB,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,WAAW,EAAE,CAAA;IAC5B,mBAAmB,EAAE,WAAW,EAAE,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,mBAAmB;;;6BAyI7B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/blocks/feature.client.tsx"],"sourcesContent":["'use client'\n\nimport type { ReducedBlock } from '
|
|
1
|
+
{"version":3,"sources":["../../../src/features/blocks/feature.client.tsx"],"sourcesContent":["'use client'\n\nimport type { Block, ReducedBlock } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { ToolbarGroup } from '../toolbars/types.js'\n\nimport { BlockIcon } from '../../lexical/ui/icons/Block/index.js'\nimport { InlineBlocksIcon } from '../../lexical/ui/icons/InlineBlocks/index.js'\nimport { createClientFeature } from '../../utilities/createClientFeature.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { InlineBlockNode } from './nodes/InlineBlocksNode.js'\nimport { INSERT_BLOCK_COMMAND, OPEN_INLINE_BLOCK_DRAWER_COMMAND } from './plugin/commands.js'\nimport { BlocksPlugin } from './plugin/index.js'\n\nexport type ClientBlock = {\n LabelComponent?: Block['admin']['components']['Label']\n} & ReducedBlock\n\nexport type BlocksFeatureClientProps = {\n reducedBlocks: ClientBlock[]\n reducedInlineBlocks: ClientBlock[]\n}\n\nexport const BlocksFeatureClient = createClientFeature<BlocksFeatureClientProps>(({ props }) => ({\n nodes: [BlockNode, InlineBlockNode],\n plugins: [\n {\n Component: BlocksPlugin,\n position: 'normal',\n },\n ],\n sanitizedClientFeatureProps: props,\n slashMenu: {\n groups: [\n props.reducedBlocks?.length\n ? {\n items: props.reducedBlocks.map((block) => {\n return {\n Icon: BlockIcon,\n key: 'block-' + block.slug,\n keywords: ['block', 'blocks', block.slug],\n label: ({ i18n }) => {\n if (!block.labels.singular) {\n return block.slug\n }\n\n return getTranslation(block.labels.singular, i18n)\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n id: null,\n blockName: '',\n blockType: block.slug,\n })\n },\n }\n }),\n key: 'blocks',\n label: ({ i18n }) => {\n return i18n.t('lexical:blocks:label')\n },\n }\n : null,\n props.reducedInlineBlocks?.length\n ? {\n items: props.reducedInlineBlocks.map((inlineBlock) => {\n return {\n Icon: InlineBlocksIcon,\n key: 'inlineBlocks-' + inlineBlock.slug,\n keywords: ['inlineBlock', 'inline block', inlineBlock.slug],\n label: ({ i18n }) => {\n if (!inlineBlock.labels.singular) {\n return inlineBlock.slug\n }\n\n return getTranslation(inlineBlock.labels.singular, i18n)\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(OPEN_INLINE_BLOCK_DRAWER_COMMAND, {\n fields: {\n id: null,\n blockName: '',\n blockType: inlineBlock.slug,\n },\n })\n },\n }\n }),\n key: 'inlineBlocks',\n label: ({ i18n }) => {\n return i18n.t('lexical:blocks:inlineBlocks:label')\n },\n }\n : null,\n ].filter(Boolean),\n },\n toolbarFixed: {\n groups: [\n props.reducedBlocks?.length\n ? {\n type: 'dropdown',\n ChildComponent: BlockIcon,\n items: props.reducedBlocks.map((block, index) => {\n return {\n ChildComponent: BlockIcon,\n isActive: undefined, // At this point, we would be inside a sub-richtext-editor. And at this point this will be run against the focused sub-editor, not the parent editor which has the actual block. Thus, no point in running this\n key: 'block-' + block.slug,\n label: ({ i18n }) => {\n if (!block.labels.singular) {\n return block.slug\n }\n\n return getTranslation(block.labels.singular, i18n)\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n id: null,\n blockName: '',\n blockType: block.slug,\n })\n },\n order: index,\n }\n }),\n key: 'blocks',\n order: 20,\n }\n : null,\n props.reducedInlineBlocks?.length\n ? {\n type: 'dropdown',\n ChildComponent: InlineBlocksIcon,\n items: props.reducedInlineBlocks.map((inlineBlock, index) => {\n return {\n ChildComponent: InlineBlocksIcon,\n isActive: undefined,\n key: 'inlineBlock-' + inlineBlock.slug,\n label: ({ i18n }) => {\n if (!inlineBlock.labels.singular) {\n return inlineBlock.slug\n }\n\n return getTranslation(inlineBlock.labels.singular, i18n)\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(OPEN_INLINE_BLOCK_DRAWER_COMMAND, {\n fields: {\n blockType: inlineBlock.slug,\n },\n })\n },\n order: index,\n }\n }),\n key: 'inlineBlocks',\n order: 25,\n }\n : null,\n ].filter(Boolean) as ToolbarGroup[],\n },\n}))\n"],"names":["getTranslation","BlockIcon","InlineBlocksIcon","createClientFeature","BlockNode","InlineBlockNode","INSERT_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND","BlocksPlugin","BlocksFeatureClient","props","nodes","plugins","Component","position","sanitizedClientFeatureProps","slashMenu","groups","reducedBlocks","length","items","map","block","Icon","key","slug","keywords","label","i18n","labels","singular","onSelect","editor","dispatchCommand","id","blockName","blockType","t","reducedInlineBlocks","inlineBlock","fields","filter","Boolean","toolbarFixed","type","ChildComponent","index","isActive","undefined","order"],"mappings":"AAAA;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AAIzD,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,gBAAgB,QAAQ,+CAA8C;AAC/E,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SAASC,oBAAoB,EAAEC,gCAAgC,QAAQ,uBAAsB;AAC7F,SAASC,YAAY,QAAQ,oBAAmB;AAWhD,OAAO,MAAMC,sBAAsBN,oBAA8C,CAAC,EAAEO,KAAK,EAAE,GAAM,CAAA;QAC/FC,OAAO;YAACP;YAAWC;SAAgB;QACnCO,SAAS;YACP;gBACEC,WAAWL;gBACXM,UAAU;YACZ;SACD;QACDC,6BAA6BL;QAC7BM,WAAW;YACTC,QAAQ;gBACNP,MAAMQ,aAAa,EAAEC,SACjB;oBACEC,OAAOV,MAAMQ,aAAa,CAACG,GAAG,CAAC,CAACC;wBAC9B,OAAO;4BACLC,MAAMtB;4BACNuB,KAAK,WAAWF,MAAMG,IAAI;4BAC1BC,UAAU;gCAAC;gCAAS;gCAAUJ,MAAMG,IAAI;6BAAC;4BACzCE,OAAO,CAAC,EAAEC,IAAI,EAAE;gCACd,IAAI,CAACN,MAAMO,MAAM,CAACC,QAAQ,EAAE;oCAC1B,OAAOR,MAAMG,IAAI;gCACnB;gCAEA,OAAOzB,eAAesB,MAAMO,MAAM,CAACC,QAAQ,EAAEF;4BAC/C;4BACAG,UAAU,CAAC,EAAEC,MAAM,EAAE;gCACnBA,OAAOC,eAAe,CAAC3B,sBAAsB;oCAC3C4B,IAAI;oCACJC,WAAW;o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AMG,IAAI;gCACnB;gCAEA,OAAOzB,eAAesB,MAAMO,MAAM,CAACC,QAAQ,EAAEF;4BAC/C;4BACAG,UAAU,CAAC,EAAEC,MAAM,EAAE;gCACnBA,OAAOC,eAAe,CAAC3B,sBAAsB;oCAC3C4B,IAAI;oCACJC,WAAW;oCACXC,WAAWd,MAAMG,IAAI;gCACvB;4BACF;4BACAwB,OAAOH;wBACT;oBACF;oBACAtB,KAAK;oBACLyB,OAAO;gBACT,IACA;gBACJvC,MAAM4B,mBAAmB,EAAEnB,SACvB;oBACEyB,MAAM;oBACNC,gBAAgB3C;oBAChBkB,OAAOV,MAAM4B,mBAAmB,CAACjB,GAAG,CAAC,CAACkB,aAAaO;wBACjD,OAAO;4BACLD,gBAAgB3C;4BAChB6C,UAAUC;4BACVxB,KAAK,iBAAiBe,YAAYd,IAAI;4BACtCE,OAAO,CAAC,EAAEC,IAAI,EAAE;gCACd,IAAI,CAACW,YAAYV,MAAM,CAACC,QAAQ,EAAE;oCAChC,OAAOS,YAAYd,IAAI;gCACzB;gCAEA,OAAOzB,eAAeuC,YAAYV,MAAM,CAACC,QAAQ,EAAEF;4BACrD;4BACAG,UAAU,CAAC,EAAEC,MAAM,EAAE;gCACnBA,OAAOC,eAAe,CAAC1B,kCAAkC;oCACvDiC,QAAQ;wCACNJ,WAAWG,YAAYd,IAAI;oCAC7B;gCACF;4BACF;4BACAwB,OAAOH;wBACT;oBACF;oBACAtB,KAAK;oBACLyB,OAAO;gBACT,IACA;aACL,CAACR,MAAM,CAACC;QACX;IACF,CAAA,GAAG"}
|
package/dist/field/Field.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAU5C,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAG7E,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AA0HrB,eAAO,MAAM,QAAQ;kBApHH,2BAA2B;UACnC,MAAM;0BACU,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC;YAC1C,MAAM;kBAiH8B,CAAA"}
|
package/dist/field/Field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { SerializedEditorState } from 'lexical'\nimport type { FormFieldBase } from 'payload'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n useField,\n useFieldProps,\n withCondition,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport './bundled.css'\nimport './index.scss'\n\nconst baseClass = 'rich-text-lexical'\n\nconst _RichText: React.FC<\n {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n width?: string\n } & FormFieldBase\n> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n editorConfig,\n errorProps,\n label,\n labelProps,\n path: pathFromProps,\n readOnly,\n required,\n style,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n width,\n } = props\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, { ...validationOptions, props, required })\n }\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n const { path: pathFromContext } = useFieldProps()\n\n const fieldType = useField<SerializedEditorState>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const { errorMessage, initialValue, path, schemaPath, setValue, showError, value } = fieldType\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n readOnly && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true ? `${baseClass}--show-gutter` : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <div\n className={classes}\n key={path}\n style={{\n ...style,\n width,\n }}\n >\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} alignCaret=\"left\" />\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n <LexicalProvider\n editorConfig={editorConfig}\n fieldProps={props}\n key={JSON.stringify({ initialValue, path })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={(editorState) => {\n let serializedEditorState = editorState.toJSON()\n\n // Transform state through save hooks\n if (editorConfig?.features?.hooks?.save?.length) {\n editorConfig.features.hooks.save.forEach((hook) => {\n serializedEditorState = hook({ incomingEditorState: serializedEditorState })\n })\n }\n\n setValue(serializedEditorState)\n }}\n path={path}\n readOnly={readOnly}\n value={value}\n />\n </ErrorBoundary>\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }): React.ReactElement {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n </div>\n )\n}\n\nexport const RichText = withCondition(_RichText)\n"],"names":["FieldDescription","FieldError","FieldLabel","useField","useFieldProps","withCondition","React","useCallback","ErrorBoundary","LexicalProvider","baseClass","_RichText","props","name","CustomDescription","CustomError","CustomLabel","className","descriptionProps","editorConfig","errorProps","label","labelProps","path","pathFromProps","readOnly","required","style","validate","width","memoizedValidate","value","validationOptions","pathFromContext","fieldType","errorMessage","initialValue","schemaPath","setValue","showError","classes","admin","hideGutter","filter","Boolean","join","div","alignCaret","fallbackRender","onReset","fieldProps","onChange","editorState","serializedEditorState","toJSON","features","hooks","save","length","forEach","hook","incomingEditorState","JSON","stringify","undefined","error","role","p","pre","color","message","RichText"],"mappings":"AAAA;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,QAAQ,EACRC,aAAa,EACbC,aAAa,QACR,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAC1C,SAASC,aAAa,QAAQ,uBAAsB;AAIpD,SAASC,eAAe,QAAQ,gCAA+B;AAC/D,OAAO,gBAAe;AAGtB,MAAMC,YAAY;AAElB,MAAMC,YAOF,CAACC;IACH,MAAM,EACJC,IAAI,EACJC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,YAAY,EACZC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,MAAMC,aAAa,EACnBC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,QAAQ,EACRC,KAAK,EACN,GAAGjB;IAEJ,MAAMkB,mBAAmBvB,YACvB,CAACwB,OAAOC;QACN,IAAI,OAAOJ,aAAa,YAAY;YAClC,OAAOA,SAASG,OAAO;gBAAE,GAAGC,iBAAiB;gBAAEpB;gBAAOc;YAAS;QACjE;IACF,GACA,yDAAyD;IACzD,8DAA8D;IAC9D,iHAAiH;IACjH;QAACE;QAAUF;KAAS;IAEtB,MAAM,EAAEH,MAAMU,eAAe,EAAE,GAAG7B;IAElC,MAAM8B,YAAY/B,SAAgC;QAChD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lD,kCAEA,KAACd;wBAAkB,GAAIkB,oBAAoB,CAAC,CAAC;;;;;OAvC5CK;AA4CX;AAEA,SAASyB,eAAe,EAAEiB,KAAK,EAAE;IAC/B,8EAA8E;IAE9E,qBACE,MAACnB;QAAI7B,WAAU;QAAgBiD,MAAK;;0BAClC,KAACC;0BAAE;;0BACH,KAACC;gBAAIzC,OAAO;oBAAE0C,OAAO;gBAAM;0BAAIJ,MAAMK,OAAO;;;;AAGlD;AAEA,OAAO,MAAMC,WAAWlE,cAAcM,WAAU"}
|
package/dist/field/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FormFieldBase } from '@payloadcms/ui';
|
|
2
1
|
import type { EditorConfig as LexicalEditorConfig } from 'lexical';
|
|
2
|
+
import type { FormFieldBase } from 'payload';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import type { LexicalFieldAdminProps } from '../types.js';
|
|
5
5
|
export declare const RichTextField: React.FC<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/field/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/field/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAG5C,OAAO,KAA8C,MAAM,OAAO,CAAA;AAIlE,OAAO,KAAK,EAAqC,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAU5F,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAClC;IACE,KAAK,CAAC,EAAE,sBAAsB,CAAA;IAC9B,mBAAmB,EAAE,mBAAmB,CAAA;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;CACnD,GAAG,aAAa,CA0HlB,CAAA"}
|