@payloadcms/richtext-lexical 3.0.0-canary.ef0a8d0 → 3.0.0-canary.f1f97ff

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.
Files changed (156) hide show
  1. package/dist/exports/client/Field-YNHIDK3D.js +2 -0
  2. package/dist/exports/client/Field-YNHIDK3D.js.map +7 -0
  3. package/dist/exports/client/RelationshipComponent-ZR2OCBGL.js +2 -0
  4. package/dist/exports/client/RelationshipComponent-ZR2OCBGL.js.map +7 -0
  5. package/dist/exports/client/bundled.css +1 -1
  6. package/dist/exports/client/{chunk-LGMNC5KQ.js → chunk-6QXGZYUK.js} +2 -2
  7. package/dist/exports/client/chunk-EBB2CEB6.js +2 -0
  8. package/dist/exports/client/chunk-EBB2CEB6.js.map +7 -0
  9. package/dist/exports/client/chunk-IPCJ5EVK.js +2 -0
  10. package/dist/exports/client/chunk-IPCJ5EVK.js.map +7 -0
  11. package/dist/exports/client/{chunk-QZIAQPM7.js → chunk-IWZVO3AI.js} +2 -2
  12. package/dist/exports/client/chunk-IWZVO3AI.js.map +7 -0
  13. package/dist/exports/client/chunk-VUVXZJJR.js +2 -0
  14. package/dist/exports/client/chunk-VUVXZJJR.js.map +7 -0
  15. package/dist/exports/client/{component-VQ4OUM2Q.js → component-D4GWDXK5.js} +2 -2
  16. package/dist/exports/client/component-KA7FDRMA.js +2 -0
  17. package/dist/exports/client/component-KA7FDRMA.js.map +7 -0
  18. package/dist/exports/client/componentInline-6EKPZSCV.js +2 -0
  19. package/dist/exports/client/componentInline-6EKPZSCV.js.map +7 -0
  20. package/dist/exports/client/index.d.ts +0 -1
  21. package/dist/exports/client/index.d.ts.map +1 -1
  22. package/dist/exports/client/index.js +7 -7
  23. package/dist/exports/client/index.js.map +4 -4
  24. package/dist/features/blocks/component/BlockContent.d.ts +3 -3
  25. package/dist/features/blocks/component/BlockContent.d.ts.map +1 -1
  26. package/dist/features/blocks/component/BlockContent.js +5 -2
  27. package/dist/features/blocks/component/BlockContent.js.map +1 -1
  28. package/dist/features/blocks/component/index.d.ts +0 -4
  29. package/dist/features/blocks/component/index.d.ts.map +1 -1
  30. package/dist/features/blocks/component/index.js +6 -2
  31. package/dist/features/blocks/component/index.js.map +1 -1
  32. package/dist/features/blocks/componentInline/index.d.ts +10 -0
  33. package/dist/features/blocks/componentInline/index.d.ts.map +1 -0
  34. package/dist/features/blocks/componentInline/index.js +133 -0
  35. package/dist/features/blocks/componentInline/index.js.map +1 -0
  36. package/dist/features/blocks/feature.client.d.ts +6 -2
  37. package/dist/features/blocks/feature.client.d.ts.map +1 -1
  38. package/dist/features/blocks/feature.client.js +70 -8
  39. package/dist/features/blocks/feature.client.js.map +1 -1
  40. package/dist/features/blocks/feature.server.d.ts +2 -1
  41. package/dist/features/blocks/feature.server.d.ts.map +1 -1
  42. package/dist/features/blocks/feature.server.js +99 -34
  43. package/dist/features/blocks/feature.server.js.map +1 -1
  44. package/dist/features/blocks/graphQLPopulationPromise.d.ts +3 -2
  45. package/dist/features/blocks/graphQLPopulationPromise.d.ts.map +1 -1
  46. package/dist/features/blocks/graphQLPopulationPromise.js +2 -2
  47. package/dist/features/blocks/graphQLPopulationPromise.js.map +1 -1
  48. package/dist/features/blocks/i18n.d.ts.map +1 -1
  49. package/dist/features/blocks/i18n.js +192 -0
  50. package/dist/features/blocks/i18n.js.map +1 -1
  51. package/dist/features/blocks/nodes/BlocksNode.d.ts +3 -2
  52. package/dist/features/blocks/nodes/BlocksNode.d.ts.map +1 -1
  53. package/dist/features/blocks/nodes/BlocksNode.js +2 -2
  54. package/dist/features/blocks/nodes/BlocksNode.js.map +1 -1
  55. package/dist/features/blocks/nodes/InlineBlocksNode.d.ts +39 -0
  56. package/dist/features/blocks/nodes/InlineBlocksNode.d.ts.map +1 -0
  57. package/dist/features/blocks/nodes/InlineBlocksNode.js +94 -0
  58. package/dist/features/blocks/nodes/InlineBlocksNode.js.map +1 -0
  59. package/dist/features/blocks/plugin/commands.d.ts +5 -0
  60. package/dist/features/blocks/plugin/commands.d.ts.map +1 -1
  61. package/dist/features/blocks/plugin/commands.js +2 -0
  62. package/dist/features/blocks/plugin/commands.js.map +1 -1
  63. package/dist/features/blocks/plugin/index.d.ts.map +1 -1
  64. package/dist/features/blocks/plugin/index.js +76 -7
  65. package/dist/features/blocks/plugin/index.js.map +1 -1
  66. package/dist/features/blocks/validate.d.ts +3 -2
  67. package/dist/features/blocks/validate.d.ts.map +1 -1
  68. package/dist/features/blocks/validate.js +2 -2
  69. package/dist/features/blocks/validate.js.map +1 -1
  70. package/dist/features/link/feature.server.js +1 -1
  71. package/dist/features/link/feature.server.js.map +1 -1
  72. package/dist/features/link/nodes/types.d.ts +3 -2
  73. package/dist/features/link/nodes/types.d.ts.map +1 -1
  74. package/dist/features/link/nodes/types.js.map +1 -1
  75. package/dist/features/link/plugins/floatingLinkEditor/utilities.d.ts +1 -1
  76. package/dist/features/link/plugins/floatingLinkEditor/utilities.d.ts.map +1 -1
  77. package/dist/features/link/plugins/floatingLinkEditor/utilities.js.map +1 -1
  78. package/dist/features/relationship/nodes/components/RelationshipComponent.d.ts +0 -1
  79. package/dist/features/relationship/nodes/components/RelationshipComponent.d.ts.map +1 -1
  80. package/dist/features/relationship/nodes/components/RelationshipComponent.js +2 -3
  81. package/dist/features/relationship/nodes/components/RelationshipComponent.js.map +1 -1
  82. package/dist/features/typesServer.d.ts +5 -5
  83. package/dist/features/typesServer.d.ts.map +1 -1
  84. package/dist/features/typesServer.js.map +1 -1
  85. package/dist/features/upload/nodes/UploadNode.d.ts +2 -4
  86. package/dist/features/upload/nodes/UploadNode.d.ts.map +1 -1
  87. package/dist/features/upload/nodes/UploadNode.js.map +1 -1
  88. package/dist/field/Field.d.ts +1 -1
  89. package/dist/field/Field.d.ts.map +1 -1
  90. package/dist/field/Field.js.map +1 -1
  91. package/dist/field/index.d.ts +1 -1
  92. package/dist/field/index.d.ts.map +1 -1
  93. package/dist/field/index.js +10 -10
  94. package/dist/field/index.js.map +1 -1
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +5 -6
  97. package/dist/index.js.map +1 -1
  98. package/dist/lexical/LexicalProvider.d.ts +1 -1
  99. package/dist/lexical/LexicalProvider.d.ts.map +1 -1
  100. package/dist/lexical/LexicalProvider.js +2 -2
  101. package/dist/lexical/LexicalProvider.js.map +1 -1
  102. package/dist/lexical/config/client/EditorConfigProvider.d.ts +1 -1
  103. package/dist/lexical/config/client/EditorConfigProvider.d.ts.map +1 -1
  104. package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
  105. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts +4 -4
  106. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
  107. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
  108. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts +0 -1
  109. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts.map +1 -1
  110. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +1 -20
  111. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
  112. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts +2 -2
  113. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts.map +1 -1
  114. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js.map +1 -1
  115. package/dist/lexical/plugins/SlashMenu/index.d.ts.map +1 -1
  116. package/dist/lexical/plugins/SlashMenu/index.js +43 -41
  117. package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
  118. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +1 -1
  119. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
  120. package/dist/lexical/ui/icons/InlineBlocks/index.d.ts +3 -0
  121. package/dist/lexical/ui/icons/InlineBlocks/index.d.ts.map +1 -0
  122. package/dist/lexical/ui/icons/InlineBlocks/index.js +20 -0
  123. package/dist/lexical/ui/icons/InlineBlocks/index.js.map +1 -0
  124. package/dist/populateGraphQL/populateLexicalPopulationPromises.d.ts.map +1 -1
  125. package/dist/populateGraphQL/populateLexicalPopulationPromises.js.map +1 -1
  126. package/dist/populateGraphQL/recursivelyPopulateFieldsForGraphQL.d.ts +2 -2
  127. package/dist/populateGraphQL/recursivelyPopulateFieldsForGraphQL.d.ts.map +1 -1
  128. package/dist/populateGraphQL/recursivelyPopulateFieldsForGraphQL.js.map +1 -1
  129. package/dist/utilities/fieldsDrawer/Drawer.d.ts +2 -2
  130. package/dist/utilities/fieldsDrawer/Drawer.d.ts.map +1 -1
  131. package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
  132. package/dist/validate/validateNodes.d.ts +1 -1
  133. package/dist/validate/validateNodes.d.ts.map +1 -1
  134. package/dist/validate/validateNodes.js.map +1 -1
  135. package/package.json +9 -9
  136. package/dist/exports/client/Field-5KHQLTCU.js +0 -2
  137. package/dist/exports/client/Field-5KHQLTCU.js.map +0 -7
  138. package/dist/exports/client/RelationshipComponent-EJB6LBDR.js +0 -2
  139. package/dist/exports/client/RelationshipComponent-EJB6LBDR.js.map +0 -7
  140. package/dist/exports/client/chunk-QZIAQPM7.js.map +0 -7
  141. package/dist/exports/client/chunk-SVDDFJRT.js +0 -2
  142. package/dist/exports/client/chunk-SVDDFJRT.js.map +0 -7
  143. package/dist/exports/client/chunk-XMCXIHWD.js +0 -2
  144. package/dist/exports/client/chunk-XMCXIHWD.js.map +0 -7
  145. package/dist/exports/client/component-Z5R2PHH3.js +0 -2
  146. package/dist/exports/client/component-Z5R2PHH3.js.map +0 -7
  147. package/dist/features/blocks/drawer/index.d.ts +0 -9
  148. package/dist/features/blocks/drawer/index.d.ts.map +0 -1
  149. package/dist/features/blocks/drawer/index.js +0 -78
  150. package/dist/features/blocks/drawer/index.js.map +0 -1
  151. package/dist/lexical/utils/cloneDeep.d.ts +0 -2
  152. package/dist/lexical/utils/cloneDeep.d.ts.map +0 -1
  153. package/dist/lexical/utils/cloneDeep.js +0 -50
  154. package/dist/lexical/utils/cloneDeep.js.map +0 -1
  155. /package/dist/exports/client/{chunk-LGMNC5KQ.js.map → chunk-6QXGZYUK.js.map} +0 -0
  156. /package/dist/exports/client/{component-VQ4OUM2Q.js.map → component-D4GWDXK5.js.map} +0 -0
@@ -1,2 +0,0 @@
1
- "use client";import{b as x}from"./chunk-QZIAQPM7.js";import{Collapsible as oe,Form as te,Pill as ae,SectionTitle as re,ShimmerEffect as le,useConfig as ie,useDocumentInfo as se,useFieldProps as ne,useFormSubmitted as ce,useTranslation as de}from"@payloadcms/ui";import{useCallback as me,useEffect as pe,useMemo as fe,useState as ue}from"react";import{getTranslation as ye}from"@payloadcms/translations";import{getFormState as V}from"@payloadcms/ui/shared";import{v4 as he}from"uuid";import{useLexicalComposerContext as j}from"@lexical/react/LexicalComposerContext.js";import{getTranslation as W}from"@payloadcms/translations";import{Button as z,Collapsible as H,ErrorPill as q,Pill as G,RenderFields as J,SectionTitle as Q,useDocumentInfo as X,useFormSubmitted as Y,useTranslation as Z}from"@payloadcms/ui";import{dequal as ee}from"dequal/lite";import{$getNodeByKey as L}from"lexical";import w,{useCallback as D}from"react";import{useAllFormFields as U}from"@payloadcms/ui";import{reduceFieldsToValues as I}from"payload/shared";import{useEffect as K}from"react";function E({fields:s}){for(let e in s){let a=s[e];Array.isArray(a.rows)&&"value"in a&&(a.disableFormData=!0)}return s}var M=s=>{let{onChange:e}=s,[a]=U(),o=E({fields:a}),m=I(o,!0);return K(()=>{e&&e({fullFieldsWithValues:o,newFormData:m})},[m,e,o]),null};import{jsx as F,jsxs as A}from"react/jsx-runtime";var O=s=>{let{baseClass:e,field:a,formData:o,formSchema:m,nodeKey:n,reducedBlock:{labels:g},schemaPath:N}=s,{i18n:S}=Z(),[c]=j(),{getDocPreferences:y,setDocFieldPreferences:P}=X(),[T,B]=w.useState(()=>{let r=!1;return y().then(d=>{let t=d?.fields[a.name]?.collapsed;t&&t.includes(o.id)&&(r=!0,B(!0))}),r}),i=Y(),[p,k]=w.useState(0),h=i&&p>0,_=[`${e}__row`,h?`${e}__row--has-errors`:`${e}__row--no-errors`].filter(Boolean).join(" "),R=D(({fullFieldsWithValues:r,newFormData:d})=>{d={...d,id:o.id,blockType:o.blockType};function v(t){for(let l in t){let b=t[l];Array.isArray(b)&&!b?.length?delete t[l]:b&&typeof b=="object"?v(b):b==null&&delete t[l]}}if(v(d),v(o),ee(o,d)||setTimeout(()=>{c.update(()=>{let t=L(n);t&&t.setFields(d)})},0),i){let t=0;for(let l of Object.values(r))l?.valid===!1&&t++;k(t)}},[c,n,i,o]),$=D(r=>{y().then(d=>{let t=d?.fields[a.name]?.collapsed,l=t&&t?.length?t:[];r?l.includes(o.id)||l.push(o.id):l.includes(o.id)&&l.splice(l.indexOf(o.id),1),P(a.name,{collapsed:l,hello:"hi"})})},[y,a.name,P,o.id]),C=D(()=>{c.update(()=>{L(n).remove()})},[c,n]);return A(w.Fragment,{children:[F(H,{className:_,collapsibleStyle:h?"error":"default",header:A("div",{className:`${e}__block-header`,children:[A("div",{children:[F(G,{className:`${e}__block-pill ${e}__block-pill-${o?.blockType}`,pillStyle:"white",children:typeof g.singular=="string"?W(g.singular,S):"[Singular Label]"}),F(Q,{path:"blockName",readOnly:a?.readOnly}),h&&F(q,{count:p,i18n:S,withMessage:!0})]}),c.isEditable()&&F(z,{buttonStyle:"icon-label",className:`${e}__removeButton`,disabled:a?.readOnly,icon:"x",onClick:r=>{r.preventDefault(),C()},round:!0,tooltip:"Remove Block"})]}),isCollapsed:T,onToggle:r=>{$(r),B(r)},children:F(J,{className:`${e}__fields`,fieldMap:Array.isArray(m)?m:[],forceRender:!0,margins:"small",path:"",readOnly:!1,schemaPath:N})},0),F(M,{onChange:R})]})};import{jsx as u,jsxs as be}from"react/jsx-runtime";var f="lexical-block",Ie=s=>{let{formData:e,nodeKey:a}=s,o=ie(),m=ce(),{id:n}=se(),{path:g,schemaPath:N}=ne(),{editorConfig:S,field:c}=x(),[y,P]=ue(!1),{field:{richTextComponentMap:T}}=x(),B=`lexical_internal_feature.blocks.fields.${e?.blockType}`,i=`${N}.lexical_internal_feature.blocks.${e?.blockType}`,p=S?.resolvedFeatureMap?.get("blocks")?.sanitizedClientFeatureProps?.reducedBlocks?.find(C=>C.slug===e?.blockType),k=T.get(B);pe(()=>{e&&(async()=>{let r=await V({apiRoute:o.routes.api,body:{id:n,data:e,operation:"update",schemaPath:i},serverURL:o.serverURL});r&&P({...r,blockName:{initialValue:"",passesCondition:!0,valid:!0,value:e.blockName}})})()},[o.routes.api,o.serverURL,i,n]);let h=me(async({formState:C})=>({...await V({apiRoute:o.routes.api,body:{id:n,formState:C,operation:"update",schemaPath:i},serverURL:o.serverURL}),blockName:{initialValue:"",passesCondition:!0,valid:!0,value:e.blockName}}),[o.routes.api,o.serverURL,i,n,e.blockName]),{i18n:_}=de(),R=[`${f}__row`,`${f}__row--no-errors`].filter(Boolean).join(" "),$=fe(()=>p&&y!==!1?u(te,{beforeSubmit:[h],fields:k,initialState:y,onChange:[h],submitted:m,uuid:he(),children:u(O,{baseClass:f,field:c,formData:e,formSchema:Array.isArray(k)?k:[],nodeKey:a,path:`${g}.lexical_internal_feature.blocks.${e.blockType}`,reducedBlock:p,schemaPath:i})}):u(oe,{className:R,collapsibleStyle:"default",header:u("div",{className:`${f}__block-header`,children:be("div",{children:[u(ae,{className:`${f}__block-pill ${f}__block-pill-${e?.blockType}`,pillStyle:"white",children:typeof p.labels.singular=="string"?ye(p.labels.singular,_):"[Singular Label]"}),u(re,{path:"blockName",readOnly:c?.readOnly})]})}),children:u(le,{height:"35vh"})},0),[R,k,c,a,_,m,y,p,h,i,g]);return u("div",{className:f+" "+f+"-"+e.blockType,children:$})};export{Ie as BlockComponent};
2
- //# sourceMappingURL=component-Z5R2PHH3.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/features/blocks/component/index.tsx", "../../../src/features/blocks/component/BlockContent.tsx", "../../../src/features/blocks/component/FormSavePlugin.tsx", "../../../src/features/blocks/component/removeEmptyArrayValues.ts"],
4
- "sourcesContent": ["'use client'\n\nimport type { FormProps } from '@payloadcms/ui'\n\nimport {\n Collapsible,\n Form,\n Pill,\n SectionTitle,\n ShimmerEffect,\n useConfig,\n useDocumentInfo,\n useFieldProps,\n useFormSubmitted,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { type BlockFields } from '../nodes/BlocksNode.js'\nconst baseClass = 'lexical-block'\nimport type { ReducedBlock } from '@payloadcms/ui/utilities/buildComponentMap'\nimport type { FormState } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { getFormState } from '@payloadcms/ui/shared'\nimport { v4 as uuid } from 'uuid'\n\nimport type { ClientComponentProps } from '../../typesClient.js'\nimport type { BlocksFeatureClientProps } from '../feature.client.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { BlockContent } from './BlockContent.js'\ntype Props = {\n children?: React.ReactNode\n\n formData: BlockFields\n nodeKey?: string\n /**\n * This transformedFormData already comes wrapped in blockFieldWrapperName\n */\n transformedFormData: BlockFields\n}\n\nexport const BlockComponent: React.FC<Props> = (props) => {\n const { formData, nodeKey } = props\n const config = useConfig()\n const submitted = useFormSubmitted()\n const { id } = useDocumentInfo()\n const { path, schemaPath } = useFieldProps()\n const { editorConfig, field: parentLexicalRichTextField } = useEditorConfigContext()\n\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `lexical_internal_feature.blocks.fields.${formData?.blockType}`\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.${formData?.blockType}`\n\n const reducedBlock: ReducedBlock = (\n editorConfig?.resolvedFeatureMap?.get('blocks')\n ?.sanitizedClientFeatureProps as ClientComponentProps<BlocksFeatureClientProps>\n )?.reducedBlocks?.find((block) => block.slug === formData?.blockType)\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath)\n // Field Schema\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data: formData,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n if (state) {\n setInitialState({\n ...state,\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n })\n }\n }\n\n if (formData) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const formState = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n formState: prevFormState,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n })\n\n return {\n ...formState,\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n }\n },\n\n [config.routes.api, config.serverURL, schemaFieldsPath, id, formData.blockName],\n )\n const { i18n } = useTranslation()\n\n const classNames = [`${baseClass}__row`, `${baseClass}__row--no-errors`].filter(Boolean).join(' ')\n\n // Memoized Form JSX\n const formContent = useMemo(() => {\n return reducedBlock && initialState !== false ? (\n <Form\n beforeSubmit={[onChange]}\n // @ts-expect-error TODO: Fix this\n fields={fieldMap}\n initialState={initialState}\n onChange={[onChange]}\n submitted={submitted}\n uuid={uuid()}\n >\n <BlockContent\n baseClass={baseClass}\n field={parentLexicalRichTextField}\n formData={formData}\n formSchema={Array.isArray(fieldMap) ? fieldMap : []}\n nodeKey={nodeKey}\n path={`${path}.lexical_internal_feature.blocks.${formData.blockType}`}\n reducedBlock={reducedBlock}\n schemaPath={schemaFieldsPath}\n />\n </Form>\n ) : (\n <Collapsible\n className={classNames}\n collapsibleStyle=\"default\"\n header={\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 reducedBlock.labels.singular === 'string'\n ? getTranslation(reducedBlock.labels.singular, i18n)\n : '[Singular Label]'}\n </Pill>\n <SectionTitle path=\"blockName\" readOnly={parentLexicalRichTextField?.readOnly} />\n </div>\n </div>\n }\n key={0}\n >\n <ShimmerEffect height=\"35vh\" />\n </Collapsible>\n )\n }, [\n classNames,\n fieldMap,\n parentLexicalRichTextField,\n nodeKey,\n i18n,\n submitted,\n initialState,\n reducedBlock,\n onChange,\n schemaFieldsPath,\n path,\n ]) // Adding formData to the dependencies here might break it\n return <div className={baseClass + ' ' + baseClass + '-' + formData.blockType}>{formContent}</div>\n}\n", "import type { FormFieldBase } from '@payloadcms/ui'\nimport type { FieldMap, ReducedBlock } 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 { 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: ReducedBlock\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: { 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 <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 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", "import type { Data, FormState } from 'payload'\nimport type React from 'react'\n\nimport { useAllFormFields } from '@payloadcms/ui'\nimport { reduceFieldsToValues } from 'payload/shared'\nimport { useEffect } from 'react'\n\nimport { removeEmptyArrayValues } from './removeEmptyArrayValues.js'\n\ntype Props = {\n onChange?: ({\n fullFieldsWithValues,\n newFormData,\n }: {\n fullFieldsWithValues: FormState\n newFormData: Data\n }) => void\n}\n\nexport const FormSavePlugin: React.FC<Props> = (props) => {\n const { onChange } = props\n\n const [_fields] = useAllFormFields()\n\n const fields = removeEmptyArrayValues({ fields: _fields })\n\n // Pass in fields, and indicate if you'd like to \"unflatten\" field data.\n // The result below will reflect the data stored in the form at the given time\n const newFormData = reduceFieldsToValues(fields, true)\n\n useEffect(() => {\n if (onChange) {\n onChange({ fullFieldsWithValues: fields, newFormData })\n }\n }, [newFormData, onChange, fields])\n\n return null\n}\n", "import type { FormState } from 'payload'\n\n/**\n * By default, if an array field is empty, it will be included in the form state with a value of 0.\n * We do not need this behavior here, By setting `disableFormData` to true, we can prevent the field from being included in the form state\n * like that.\n * @param fields form state\n */\nexport function removeEmptyArrayValues({ fields }: { fields: FormState }): FormState {\n for (const key in fields) {\n const field = fields[key]\n if (Array.isArray(field.rows) && 'value' in field) {\n field.disableFormData = true\n }\n }\n return fields\n}\n"],
5
- "mappings": "qDAIA,OACE,eAAAA,GACA,QAAAC,GACA,QAAAC,GACA,gBAAAC,GACA,iBAAAC,GACA,aAAAC,GACA,mBAAAC,GACA,iBAAAC,GACA,oBAAAC,GACA,kBAAAC,OACK,iBACP,OAAgB,eAAAC,GAAa,aAAAC,GAAW,WAAAC,GAAS,YAAAC,OAAgB,QAOjE,OAAS,kBAAAC,OAAsB,2BAC/B,OAAS,gBAAAC,MAAoB,wBAC7B,OAAS,MAAMC,OAAY,OCrB3B,OAAS,6BAAAC,MAAiC,2CAC1C,OAAS,kBAAAC,MAAsB,2BAC/B,OACE,UAAAC,EACA,eAAAC,EACA,aAAAC,EACA,QAAAC,EACA,gBAAAC,EACA,gBAAAC,EACA,mBAAAC,EACA,oBAAAC,EACA,kBAAAC,MACK,iBACP,OAAS,UAAAC,OAAc,cACvB,OAAS,iBAAAC,MAAqB,UAC9B,OAAOC,GAAS,eAAAC,MAAmB,QChBnC,OAAS,oBAAAC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,SAAU5B,GAA4B,SAAU,GACjF,EACF,EAIF,SAAAjB,EAAC8C,GAAA,CAAc,OAAO,OAAO,GAFxB,CAGP,EAED,CACDV,EACAT,EACAV,EACAX,EACA4B,EACAzB,EACAU,EACAM,EACAM,EACAP,EACAX,CACF,CAAC,EACD,OAAOb,EAAC,OAAI,UAAWE,EAAY,IAAMA,EAAY,IAAMG,EAAS,UAAY,SAAAgC,EAAY,CAC9F",
6
- "names": ["Collapsible", "Form", "Pill", "SectionTitle", "ShimmerEffect", "useConfig", "useDocumentInfo", "useFieldProps", "useFormSubmitted", "useTranslation", "useCallback", "useEffect", "useMemo", "useState", "getTranslation", "getFormState", "uuid", "useLexicalComposerContext", "getTranslation", "Button", "Collapsible", "ErrorPill", "Pill", "RenderFields", "SectionTitle", "useDocumentInfo", "useFormSubmitted", "useTranslation", "dequal", "$getNodeByKey", "React", "useCallback", "useAllFormFields", "reduceFieldsToValues", "useEffect", "removeEmptyArrayValues", "fields", "key", "field", "FormSavePlugin", "props", "onChange", "_fields", "useAllFormFields", "fields", "removeEmptyArrayValues", "newFormData", "reduceFieldsToValues", "useEffect", "jsx", "jsxs", "BlockContent", "props", "baseClass", "field", "formData", "formSchema", "nodeKey", "labels", "schemaPath", "i18n", "useTranslation", "editor", "useLexicalComposerContext", "getDocPreferences", "setDocFieldPreferences", "useDocumentInfo", "isCollapsed", "setIsCollapsed", "React", "initialState", "currentDocPreferences", "collapsedArray", "hasSubmitted", "useFormSubmitted", "errorCount", "setErrorCount", "fieldHasErrors", "classNames", "onFormChange", "useCallback", "fullFieldsWithValues", "newFormData", "removeUndefinedAndNullAndEmptyArraysRecursively", "obj", "key", "value", "dequal", "node", "$getNodeByKey", "rowErrorCount", "formField", "onCollapsedChange", "changedCollapsed", "newCollapsed", "removeBlock", "Collapsible", "Pill", "getTranslation", "SectionTitle", "ErrorPill", "Button", "e", "incomingCollapsedState", "RenderFields", "FormSavePlugin", "jsx", "jsxs", "baseClass", "BlockComponent", "props", "formData", "nodeKey", "config", "useConfig", "submitted", "useFormSubmitted", "id", "useDocumentInfo", "path", "schemaPath", "useFieldProps", "editorConfig", "parentLexicalRichTextField", "useEditorConfigContext", "initialState", "setInitialState", "useState", "richTextComponentMap", "componentMapRenderedFieldsPath", "schemaFieldsPath", "reducedBlock", "block", "fieldMap", "useEffect", "state", "getFormState", "onChange", "useCallback", "prevFormState", "i18n", "useTranslation", "classNames", "formContent", "useMemo", "Form", "uuid", "BlockContent", "Collapsible", "Pill", "getTranslation", "SectionTitle", "ShimmerEffect"]
7
- }
@@ -1,9 +0,0 @@
1
- import type { LexicalCommand } from 'lexical';
2
- import React from 'react';
3
- export declare const INSERT_BLOCK_WITH_DRAWER_COMMAND: LexicalCommand<{
4
- replace: {
5
- nodeKey: string;
6
- } | false;
7
- }>;
8
- export declare const BlocksDrawerComponent: React.FC;
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/drawer/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,SAAS,CAAA;AAW5D,OAAO,KAA2C,MAAM,OAAO,CAAA;AAU/D,eAAO,MAAM,gCAAgC,EAAE,cAAc,CAAC;IAC5D,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,KAAK,CAAA;CACrC,CAAqD,CAAA;AAiCtD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EA0DzC,CAAA"}
@@ -1,78 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
4
- import { BlocksDrawer, formatDrawerSlug, useEditDepth, useModal, useTranslation } from '@payloadcms/ui';
5
- import { $getNodeByKey, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
6
- import React, { useCallback, useEffect, useState } from 'react';
7
- import { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js';
8
- import { $createBlockNode } from '../nodes/BlocksNode.js';
9
- import { INSERT_BLOCK_COMMAND } from '../plugin/commands.js';
10
- const baseClass = 'lexical-blocks-drawer';
11
- export const INSERT_BLOCK_WITH_DRAWER_COMMAND = createCommand('INSERT_BLOCK_WITH_DRAWER_COMMAND');
12
- const insertBlock = ({ blockType, editor, replaceNodeKey })=>{
13
- if (!replaceNodeKey) {
14
- editor.dispatchCommand(INSERT_BLOCK_COMMAND, {
15
- id: null,
16
- blockName: '',
17
- blockType
18
- });
19
- } else {
20
- editor.update(()=>{
21
- const node = $getNodeByKey(replaceNodeKey);
22
- if (node) {
23
- node.replace($createBlockNode({
24
- id: null,
25
- blockName: '',
26
- blockType
27
- }));
28
- }
29
- });
30
- }
31
- };
32
- export const BlocksDrawerComponent = ()=>{
33
- const [editor] = useLexicalComposerContext();
34
- const { editorConfig, uuid } = useEditorConfigContext();
35
- const [replaceNodeKey, setReplaceNodeKey] = useState(null);
36
- const editDepth = useEditDepth();
37
- const { t } = useTranslation();
38
- const { openModal } = useModal();
39
- const labels = {
40
- plural: t('fields:blocks') || 'Blocks',
41
- singular: t('fields:block') || 'Block'
42
- };
43
- const addRow = useCallback((rowIndex, blockType)=>{
44
- insertBlock({
45
- blockType,
46
- editor,
47
- replaceNodeKey
48
- });
49
- }, [
50
- editor,
51
- replaceNodeKey
52
- ]);
53
- const drawerSlug = formatDrawerSlug({
54
- slug: `lexical-rich-text-blocks-` + uuid,
55
- depth: editDepth
56
- });
57
- const reducedBlocks = editorConfig?.resolvedFeatureMap?.get('blocks')?.sanitizedClientFeatureProps?.reducedBlocks;
58
- useEffect(()=>{
59
- return editor.registerCommand(INSERT_BLOCK_WITH_DRAWER_COMMAND, (payload)=>{
60
- setReplaceNodeKey(payload?.replace ? payload?.replace.nodeKey : null);
61
- openModal(drawerSlug);
62
- return true;
63
- }, COMMAND_PRIORITY_EDITOR);
64
- }, [
65
- editor,
66
- drawerSlug,
67
- openModal
68
- ]);
69
- return /*#__PURE__*/ _jsx(BlocksDrawer, {
70
- addRow: addRow,
71
- addRowIndex: 0,
72
- blocks: reducedBlocks,
73
- drawerSlug: drawerSlug,
74
- labels: labels
75
- });
76
- };
77
-
78
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/features/blocks/drawer/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand, LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport {\n BlocksDrawer,\n formatDrawerSlug,\n useEditDepth,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport { $getNodeByKey, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { ClientComponentProps } from '../../typesClient.js'\nimport type { BlocksFeatureClientProps } from '../feature.client.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { $createBlockNode } from '../nodes/BlocksNode.js'\nimport { INSERT_BLOCK_COMMAND } from '../plugin/commands.js'\nconst baseClass = 'lexical-blocks-drawer'\n\nexport const INSERT_BLOCK_WITH_DRAWER_COMMAND: LexicalCommand<{\n replace: { nodeKey: string } | false\n}> = createCommand('INSERT_BLOCK_WITH_DRAWER_COMMAND')\n\nconst insertBlock = ({\n blockType,\n editor,\n replaceNodeKey,\n}: {\n blockType: string\n editor: LexicalEditor\n replaceNodeKey: null | string\n}) => {\n if (!replaceNodeKey) {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n id: null,\n blockName: '',\n blockType,\n })\n } else {\n editor.update(() => {\n const node = $getNodeByKey(replaceNodeKey)\n if (node) {\n node.replace(\n $createBlockNode({\n id: null,\n blockName: '',\n blockType,\n }),\n )\n }\n })\n }\n}\n\nexport const BlocksDrawerComponent: React.FC = () => {\n const [editor] = useLexicalComposerContext()\n const { editorConfig, uuid } = useEditorConfigContext()\n\n const [replaceNodeKey, setReplaceNodeKey] = useState<null | string>(null)\n const editDepth = useEditDepth()\n const { t } = useTranslation()\n const { openModal } = useModal()\n\n const labels = {\n plural: t('fields:blocks') || 'Blocks',\n singular: t('fields:block') || 'Block',\n }\n\n const addRow = useCallback(\n (rowIndex: number, blockType: string) => {\n insertBlock({\n blockType,\n editor,\n replaceNodeKey,\n })\n },\n [editor, replaceNodeKey],\n )\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-rich-text-blocks-` + uuid,\n depth: editDepth,\n })\n\n const reducedBlocks = (\n editorConfig?.resolvedFeatureMap?.get('blocks')\n ?.sanitizedClientFeatureProps as ClientComponentProps<BlocksFeatureClientProps>\n )?.reducedBlocks\n\n useEffect(() => {\n return editor.registerCommand<{\n replace: { nodeKey: string } | false\n }>(\n INSERT_BLOCK_WITH_DRAWER_COMMAND,\n (payload) => {\n setReplaceNodeKey(payload?.replace ? payload?.replace.nodeKey : null)\n openModal(drawerSlug)\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor, drawerSlug, openModal])\n\n return (\n <BlocksDrawer\n addRow={addRow}\n addRowIndex={0}\n blocks={reducedBlocks}\n drawerSlug={drawerSlug}\n labels={labels}\n />\n )\n}\n"],"names":["useLexicalComposerContext","BlocksDrawer","formatDrawerSlug","useEditDepth","useModal","useTranslation","$getNodeByKey","COMMAND_PRIORITY_EDITOR","createCommand","React","useCallback","useEffect","useState","useEditorConfigContext","$createBlockNode","INSERT_BLOCK_COMMAND","baseClass","INSERT_BLOCK_WITH_DRAWER_COMMAND","insertBlock","blockType","editor","replaceNodeKey","dispatchCommand","id","blockName","update","node","replace","BlocksDrawerComponent","editorConfig","uuid","setReplaceNodeKey","editDepth","t","openModal","labels","plural","singular","addRow","rowIndex","drawerSlug","slug","depth","reducedBlocks","resolvedFeatureMap","get","sanitizedClientFeatureProps","registerCommand","payload","nodeKey","addRowIndex","blocks"],"mappings":"AAAA;;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SACE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MAAM,CAAC,yBAAyB,CAAC,GAAGX;QACpCY,OAAOV;IACT;IAEA,MAAMW,gBACJd,cAAce,oBAAoBC,IAAI,WAClCC,6BACHH;IAEHhC,UAAU;QACR,OAAOS,OAAO2B,eAAe,CAG3B9B,kCACA,CAAC+B;YACCjB,kBAAkBiB,SAASrB,UAAUqB,SAASrB,QAAQsB,UAAU;YAChEf,UAAUM;YACV,OAAO;QACT,GACAjC;IAEJ,GAAG;QAACa;QAAQoB;QAAYN;KAAU;IAElC,qBACE,KAACjC;QACCqC,QAAQA;QACRY,aAAa;QACbC,QAAQR;QACRH,YAAYA;QACZL,QAAQA;;AAGd,EAAC"}
@@ -1,2 +0,0 @@
1
- export declare function cloneDeep<T>(object: T, cache?: WeakMap<any, any>): T;
2
- //# sourceMappingURL=cloneDeep.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloneDeep.d.ts","sourceRoot":"","sources":["../../../src/lexical/utils/cloneDeep.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,GAAE,OAAO,CAAC,GAAG,EAAE,GAAG,CAAiB,GAAG,CAAC,CA8DnF"}
@@ -1,50 +0,0 @@
1
- export function cloneDeep(object, cache = new WeakMap()) {
2
- if (object === null) return null;
3
- if (cache.has(object)) {
4
- return cache.get(object);
5
- }
6
- // Handle Date
7
- if (object instanceof Date) {
8
- return new Date(object.getTime());
9
- }
10
- // Handle RegExp
11
- if (object instanceof RegExp) {
12
- return new RegExp(object.source, object.flags);
13
- }
14
- // Handle Map
15
- if (object instanceof Map) {
16
- const clonedMap = new Map();
17
- cache.set(object, clonedMap);
18
- for (const [key, value] of object.entries()){
19
- clonedMap.set(key, cloneDeep(value, cache));
20
- }
21
- return clonedMap;
22
- }
23
- // Handle Set
24
- if (object instanceof Set) {
25
- const clonedSet = new Set();
26
- cache.set(object, clonedSet);
27
- for (const value of object.values()){
28
- clonedSet.add(cloneDeep(value, cache));
29
- }
30
- return clonedSet;
31
- }
32
- // Handle Array and Object
33
- if (typeof object === 'object' && object !== null) {
34
- if ('$$typeof' in object && typeof object.$$typeof === 'symbol') {
35
- return object;
36
- }
37
- const clonedObject = Array.isArray(object) ? [] : Object.create(Object.getPrototypeOf(object));
38
- cache.set(object, clonedObject);
39
- for(const key in object){
40
- if (Object.prototype.hasOwnProperty.call(object, key) || Object.getOwnPropertySymbols(object).includes(key)) {
41
- clonedObject[key] = cloneDeep(object[key], cache);
42
- }
43
- }
44
- return clonedObject;
45
- }
46
- // Handle all other cases
47
- return object;
48
- }
49
-
50
- //# sourceMappingURL=cloneDeep.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lexical/utils/cloneDeep.ts"],"sourcesContent":["export function cloneDeep<T>(object: T, cache: WeakMap<any, any> = new WeakMap()): T {\n if (object === null) return null\n\n if (cache.has(object)) {\n return cache.get(object)\n }\n\n // Handle Date\n if (object instanceof Date) {\n return new Date(object.getTime()) as unknown as T\n }\n\n // Handle RegExp\n if (object instanceof RegExp) {\n return new RegExp(object.source, object.flags) as unknown as T\n }\n\n // Handle Map\n if (object instanceof Map) {\n const clonedMap = new Map()\n cache.set(object, clonedMap)\n for (const [key, value] of object.entries()) {\n clonedMap.set(key, cloneDeep(value, cache))\n }\n return clonedMap as unknown as T\n }\n\n // Handle Set\n if (object instanceof Set) {\n const clonedSet = new Set()\n cache.set(object, clonedSet)\n for (const value of object.values()) {\n clonedSet.add(cloneDeep(value, cache))\n }\n return clonedSet as unknown as T\n }\n\n // Handle Array and Object\n if (typeof object === 'object' && object !== null) {\n if ('$$typeof' in object && typeof object.$$typeof === 'symbol') {\n return object\n }\n\n const clonedObject: any = Array.isArray(object)\n ? []\n : Object.create(Object.getPrototypeOf(object))\n cache.set(object, clonedObject)\n\n for (const key in object) {\n if (\n Object.prototype.hasOwnProperty.call(object, key) ||\n Object.getOwnPropertySymbols(object).includes(key as any)\n ) {\n clonedObject[key] = cloneDeep(object[key], cache)\n }\n }\n\n return clonedObject as T\n }\n\n // Handle all other cases\n return object\n}\n"],"names":["cloneDeep","object","cache","WeakMap","has","get","Date","getTime","RegExp","source","flags","Map","clonedMap","set","key","value","entries","Set","clonedSet","values","add","$$typeof","clonedObject","Array","isArray","Object","create","getPrototypeOf","prototype","hasOwnProperty","call","getOwnPropertySymbols","includes"],"mappings":"AAAA,OAAO,SAASA,UAAaC,MAAS,EAAEC,QAA2B,IAAIC,SAAS;IAC9E,IAAIF,WAAW,MAAM,OAAO;IAE5B,IAAIC,MAAME,GAAG,CAACH,SAAS;QACrB,OAAOC,MAAMG,GAAG,CAACJ;IACnB;IAEA,cAAc;IACd,IAAIA,kBAAkBK,MAAM;QAC1B,OAAO,IAAIA,KAAKL,OAAOM,OAAO;IAChC;IAEA,gBAAgB;IAChB,IAAIN,kBAAkBO,QAAQ;QAC5B,OAAO,IAAIA,OAAOP,OAAOQ,MAAM,EAAER,OAAOS,KAAK;IAC/C;IAEA,aAAa;IACb,IAAIT,kBAAkBU,KAAK;QACzB,MAAMC,YAAY,IAAID;QACtBT,MAAMW,GAAG,CAACZ,QAAQW;QAClB,KAAK,MAAM,CAACE,KAAKC,MAAM,IAAId,OAAOe,OAAO,GAAI;YAC3CJ,UAAUC,GAAG,CAACC,KAAKd,UAAUe,OAAOb;QACtC;QACA,OAAOU;IACT;IAEA,aAAa;IACb,IAAIX,kBAAkBgB,KAAK;QACzB,MAAMC,YAAY,IAAID;QACtBf,MAAMW,GAAG,CAACZ,QAAQiB;QAClB,KAAK,MAAMH,SAASd,OAAOkB,MAAM,GAAI;YACnCD,UAAUE,GAAG,CAACpB,UAAUe,OAAOb;QACjC;QACA,OAAOgB;IACT;IAEA,0BAA0B;IAC1B,IAAI,OAAOjB,WAAW,YAAYA,WAAW,MAAM;QACjD,IAAI,cAAcA,UAAU,OAAOA,OAAOoB,QAAQ,KAAK,UAAU;YAC/D,OAAOpB;QACT;QAEA,MAAMqB,eAAoBC,MAAMC,OAAO,CAACvB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