@payloadcms/richtext-lexical 3.0.0-beta.58 → 3.0.0-beta.59
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/cell/index.d.ts.map +1 -1
- package/dist/cell/index.js +2 -2
- package/dist/cell/index.js.map +1 -1
- package/dist/exports/client/chunk-CUMDYP5E.js +2 -0
- package/dist/exports/client/chunk-CUMDYP5E.js.map +7 -0
- package/dist/exports/client/component-7J2IXLN3.js +2 -0
- package/dist/exports/client/component-7J2IXLN3.js.map +7 -0
- package/dist/exports/client/{component-V5QZ7EVZ.js → component-RV346GAA.js} +2 -2
- package/dist/exports/client/index.js +6 -6
- package/dist/exports/client/index.js.map +2 -2
- package/dist/features/blocks/component/index.js +3 -3
- package/dist/features/blocks/component/index.js.map +1 -1
- package/dist/features/createFeaturePropComponent.js +1 -1
- package/dist/features/createFeaturePropComponent.js.map +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/utilities/fieldsDrawer/DrawerContent.js +2 -2
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/dist/utilities/generateComponentMap.d.ts.map +1 -1
- package/dist/utilities/generateComponentMap.js +3 -3
- package/dist/utilities/generateComponentMap.js.map +1 -1
- package/dist/utilities/generateSchemaMap.js +1 -1
- package/dist/utilities/generateSchemaMap.js.map +1 -1
- package/package.json +11 -11
- package/dist/exports/client/chunk-OAQL5GDK.js +0 -2
- package/dist/exports/client/chunk-OAQL5GDK.js.map +0 -7
- package/dist/exports/client/component-YNZTTMBY.js +0 -2
- package/dist/exports/client/component-YNZTTMBY.js.map +0 -7
- /package/dist/exports/client/{component-V5QZ7EVZ.js.map → component-RV346GAA.js.map} +0 -0
package/dist/cell/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cell/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,OAAO,KAA8B,MAAM,OAAO,CAAA;AAIlD,OAAO,KAAK,EAAqC,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAO5F,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CACjC,kBAAkB,GAAG;IACnB,KAAK,CAAC,EAAE,sBAAsB,CAAA;IAC9B,mBAAmB,EAAE,mBAAmB,CAAA;CACzC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cell/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,OAAO,KAA8B,MAAM,OAAO,CAAA;AAIlD,OAAO,KAAK,EAAqC,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAO5F,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CACjC,kBAAkB,GAAG;IACnB,KAAK,CAAC,EAAE,sBAAsB,CAAA;IAC9B,mBAAmB,EAAE,mBAAmB,CAAA;CACzC,CA4KF,CAAA"}
|
package/dist/cell/index.js
CHANGED
|
@@ -32,7 +32,7 @@ export const RichTextCell = (props)=>{
|
|
|
32
32
|
;
|
|
33
33
|
Object.entries(clientFunctions).forEach(([key, plugin])=>{
|
|
34
34
|
if (key.startsWith(`lexicalFeature.${schemaPath}.`)) {
|
|
35
|
-
if (!key.includes('.
|
|
35
|
+
if (!key.includes('.lexical_internal_components.')) {
|
|
36
36
|
featureProvidersLocal.push(plugin);
|
|
37
37
|
}
|
|
38
38
|
featureProvidersAndComponentsLoaded++;
|
|
@@ -122,7 +122,7 @@ export const RichTextCell = (props)=>{
|
|
|
122
122
|
return /*#__PURE__*/ _jsx(React.Fragment, {
|
|
123
123
|
children: Array.isArray(featureProviderComponents) && featureProviderComponents.map((featureProvider)=>{
|
|
124
124
|
// get all components starting with key feature.${FeatureProvider.key}.components.{featureComponentKey}
|
|
125
|
-
const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key)=>key.startsWith(`
|
|
125
|
+
const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key)=>key.startsWith(`lexical_internal_feature.${featureProvider.key}.lexical_internal_components.`));
|
|
126
126
|
const featureComponents = featureComponentKeys.map((key)=>{
|
|
127
127
|
return richTextComponentMap.get(key);
|
|
128
128
|
});
|
package/dist/cell/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cell/index.tsx"],"sourcesContent":["'use client'\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical'\nimport type { CellComponentProps } from 'payload'\n\nimport { createHeadlessEditor } from '@lexical/headless'\nimport { useClientFunctions, useTableCell } from '@payloadcms/ui'\nimport { $getRoot } from 'lexical'\nimport React, { useEffect, useState } from 'react'\n\nimport type { FeatureProviderClient } from '../features/typesClient.js'\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\nimport type { GeneratedFeatureProviderComponent, LexicalFieldAdminProps } from '../types.js'\n\nimport { defaultEditorLexicalConfig } from '../lexical/config/client/default.js'\nimport { loadClientFeatures } from '../lexical/config/client/loader.js'\nimport { sanitizeClientEditorConfig } from '../lexical/config/client/sanitize.js'\nimport { getEnabledNodes } from '../lexical/nodes/index.js'\n\nexport const RichTextCell: React.FC<\n CellComponentProps & {\n admin?: LexicalFieldAdminProps\n lexicalEditorConfig: LexicalEditorConfig\n }\n> = (props) => {\n const { admin, lexicalEditorConfig, richTextComponentMap } = props\n\n const [preview, setPreview] = React.useState('Loading...')\n\n const {\n cellData,\n cellProps: { schemaPath },\n } = useTableCell()\n\n const clientFunctions = useClientFunctions()\n const [hasLoadedFeatures, setHasLoadedFeatures] = useState(false)\n\n const [featureProviders, setFeatureProviders] = useState<\n FeatureProviderClient<unknown, unknown>[]\n >([])\n\n const [finalSanitizedEditorConfig, setFinalSanitizedEditorConfig] =\n useState<SanitizedClientEditorConfig>(null)\n\n const featureProviderComponents: GeneratedFeatureProviderComponent[] = (\n richTextComponentMap.get('features') as GeneratedFeatureProviderComponent[]\n ).sort((a, b) => a.order - b.order) // order by order\n\n let featureProvidersAndComponentsToLoad = 0 // feature providers and components\n for (const featureProvider of featureProviderComponents) {\n const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>\n key.startsWith(`feature.${featureProvider.key}.components.`),\n )\n\n featureProvidersAndComponentsToLoad += 1\n featureProvidersAndComponentsToLoad += featureComponentKeys.length\n }\n\n useEffect(() => {\n if (!hasLoadedFeatures) {\n const featureProvidersLocal: FeatureProviderClient<unknown, unknown>[] = []\n let featureProvidersAndComponentsLoaded = 0 // feature providers and components only\n\n Object.entries(clientFunctions).forEach(([key, plugin]) => {\n if (key.startsWith(`lexicalFeature.${schemaPath}.`)) {\n if (!key.includes('.components.')) {\n featureProvidersLocal.push(plugin)\n }\n featureProvidersAndComponentsLoaded++\n }\n })\n\n if (featureProvidersAndComponentsLoaded === featureProvidersAndComponentsToLoad) {\n setFeatureProviders(featureProvidersLocal)\n setHasLoadedFeatures(true)\n\n /**\n * Loaded feature provided => create the final sanitized editor config\n */\n\n const resolvedClientFeatures = loadClientFeatures({\n clientFunctions,\n schemaPath,\n unSanitizedEditorConfig: {\n features: featureProvidersLocal,\n lexical: lexicalEditorConfig,\n },\n })\n\n setFinalSanitizedEditorConfig(\n sanitizeClientEditorConfig(\n lexicalEditorConfig ? lexicalEditorConfig : defaultEditorLexicalConfig,\n resolvedClientFeatures,\n admin,\n ),\n )\n }\n }\n }, [\n admin,\n featureProviderComponents,\n hasLoadedFeatures,\n clientFunctions,\n schemaPath,\n featureProviderComponents.length,\n featureProviders,\n finalSanitizedEditorConfig,\n lexicalEditorConfig,\n richTextComponentMap,\n featureProvidersAndComponentsToLoad,\n ])\n\n useEffect(() => {\n if (!hasLoadedFeatures) {\n return\n }\n let dataToUse = cellData\n if (dataToUse == null || !hasLoadedFeatures || !finalSanitizedEditorConfig) {\n setPreview('')\n return\n }\n\n // Transform data through load hooks\n if (finalSanitizedEditorConfig?.features?.hooks?.load?.length) {\n finalSanitizedEditorConfig.features.hooks.load.forEach((hook) => {\n dataToUse = hook({ incomingEditorState: dataToUse })\n })\n }\n\n if (!dataToUse || typeof dataToUse !== 'object') {\n setPreview('')\n return\n }\n\n // If data is from Slate and not Lexical\n if (Array.isArray(dataToUse) && !('root' in dataToUse)) {\n setPreview('')\n return\n }\n\n // If data is from payload-plugin-lexical\n if ('jsonContent' in dataToUse) {\n setPreview('')\n return\n }\n\n // initialize headless editor\n const headlessEditor = createHeadlessEditor({\n namespace: finalSanitizedEditorConfig.lexical.namespace,\n nodes: getEnabledNodes({ editorConfig: finalSanitizedEditorConfig }),\n theme: finalSanitizedEditorConfig.lexical.theme,\n })\n headlessEditor.setEditorState(headlessEditor.parseEditorState(dataToUse))\n\n const textContent =\n headlessEditor.getEditorState().read(() => {\n return $getRoot().getTextContent()\n }) || ''\n\n // Limiting the number of characters shown is done in a CSS rule\n setPreview(textContent)\n }, [cellData, lexicalEditorConfig, hasLoadedFeatures, finalSanitizedEditorConfig])\n\n if (!hasLoadedFeatures) {\n return (\n <React.Fragment>\n {Array.isArray(featureProviderComponents) &&\n featureProviderComponents.map((featureProvider) => {\n // get all components starting with key feature.${FeatureProvider.key}.components.{featureComponentKey}\n const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>\n key.startsWith(`feature.${featureProvider.key}.components.`),\n )\n\n const featureComponents: React.ReactNode[] = featureComponentKeys.map((key) => {\n return richTextComponentMap.get(key)\n })\n\n return (\n <React.Fragment key={featureProvider.key}>\n {featureComponents?.length\n ? featureComponents.map((FeatureComponent) => {\n return FeatureComponent\n })\n : null}\n {featureProvider.ClientFeature}\n </React.Fragment>\n )\n })}\n </React.Fragment>\n )\n }\n\n return <span>{preview}</span>\n}\n"],"names":["createHeadlessEditor","useClientFunctions","useTableCell","$getRoot","React","useEffect","useState","defaultEditorLexicalConfig","loadClientFeatures","sanitizeClientEditorConfig","getEnabledNodes","RichTextCell","props","admin","lexicalEditorConfig","richTextComponentMap","preview","setPreview","cellData","cellProps","schemaPath","clientFunctions","hasLoadedFeatures","setHasLoadedFeatures","featureProviders","setFeatureProviders","finalSanitizedEditorConfig","setFinalSanitizedEditorConfig","featureProviderComponents","get","sort","a","b","order","featureProvidersAndComponentsToLoad","featureProvider","featureComponentKeys","Array","from","keys","filter","key","startsWith","length","featureProvidersLocal","featureProvidersAndComponentsLoaded","Object","entries","forEach","plugin","includes","push","resolvedClientFeatures","unSanitizedEditorConfig","features","lexical","dataToUse","hooks","load","hook","incomingEditorState","isArray","headlessEditor","namespace","nodes","editorConfig","theme","setEditorState","parseEditorState","textContent","getEditorState","read","getTextContent","Fragment","map","featureComponents","FeatureComponent","ClientFeature","span"],"mappings":"AAAA;;AAIA,SAASA,oBAAoB,QAAQ,oBAAmB;AACxD,SAASC,kBAAkB,EAAEC,YAAY,QAAQ,iBAAgB;AACjE,SAASC,QAAQ,QAAQ,UAAS;AAClC,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAMlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,0BAA0B,QAAQ,uCAAsC;AACjF,SAASC,eAAe,QAAQ,4BAA2B;AAE3D,OAAO,MAAMC,eAKT,CAACC;IACH,MAAM,EAAEC,KAAK,EAAEC,mBAAmB,EAAEC,oBAAoB,EAAE,GAAGH;IAE7D,MAAM,CAACI,SAASC,WAAW,GAAGb,MAAME,QAAQ,CAAC;IAE7C,MAAM,EACJY,QAAQ,EACRC,WAAW,EAAEC,UAAU,EAAE,EAC1B,GAAGlB;IAEJ,MAAMmB,kBAAkBpB;IACxB,MAAM,CAACqB,mBA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C,GAAG,CAAC,CAACvC;gBAC7B,uGAAuG;gBACvG,MAAMC,uBAAuBC,MAAMC,IAAI,CAACvB,qBAAqBwB,IAAI,IAAIC,MAAM,CAAC,CAACC,MAC3EA,IAAIC,UAAU,CAAC,CAAC,QAAQ,EAAEP,gBAAgBM,GAAG,CAAC,YAAY,CAAC;gBAG7D,MAAMkC,oBAAuCvC,qBAAqBsC,GAAG,CAAC,CAACjC;oBACrE,OAAO1B,qBAAqBc,GAAG,CAACY;gBAClC;gBAEA,qBACE,MAACrC,MAAMqE,QAAQ;;wBACZE,mBAAmBhC,SAChBgC,kBAAkBD,GAAG,CAAC,CAACE;4BACrB,OAAOA;wBACT,KACA;wBACHzC,gBAAgB0C,aAAa;;mBANX1C,gBAAgBM,GAAG;YAS5C;;IAGR;IAEA,qBAAO,KAACqC;kBAAM9D;;AAChB,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/cell/index.tsx"],"sourcesContent":["'use client'\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical'\nimport type { CellComponentProps } from 'payload'\n\nimport { createHeadlessEditor } from '@lexical/headless'\nimport { useClientFunctions, useTableCell } from '@payloadcms/ui'\nimport { $getRoot } from 'lexical'\nimport React, { useEffect, useState } from 'react'\n\nimport type { FeatureProviderClient } from '../features/typesClient.js'\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\nimport type { GeneratedFeatureProviderComponent, LexicalFieldAdminProps } from '../types.js'\n\nimport { defaultEditorLexicalConfig } from '../lexical/config/client/default.js'\nimport { loadClientFeatures } from '../lexical/config/client/loader.js'\nimport { sanitizeClientEditorConfig } from '../lexical/config/client/sanitize.js'\nimport { getEnabledNodes } from '../lexical/nodes/index.js'\n\nexport const RichTextCell: React.FC<\n CellComponentProps & {\n admin?: LexicalFieldAdminProps\n lexicalEditorConfig: LexicalEditorConfig\n }\n> = (props) => {\n const { admin, lexicalEditorConfig, richTextComponentMap } = props\n\n const [preview, setPreview] = React.useState('Loading...')\n\n const {\n cellData,\n cellProps: { schemaPath },\n } = useTableCell()\n\n const clientFunctions = useClientFunctions()\n const [hasLoadedFeatures, setHasLoadedFeatures] = useState(false)\n\n const [featureProviders, setFeatureProviders] = useState<\n FeatureProviderClient<unknown, unknown>[]\n >([])\n\n const [finalSanitizedEditorConfig, setFinalSanitizedEditorConfig] =\n useState<SanitizedClientEditorConfig>(null)\n\n const featureProviderComponents: GeneratedFeatureProviderComponent[] = (\n richTextComponentMap.get('features') as GeneratedFeatureProviderComponent[]\n ).sort((a, b) => a.order - b.order) // order by order\n\n let featureProvidersAndComponentsToLoad = 0 // feature providers and components\n for (const featureProvider of featureProviderComponents) {\n const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>\n key.startsWith(`feature.${featureProvider.key}.components.`),\n )\n\n featureProvidersAndComponentsToLoad += 1\n featureProvidersAndComponentsToLoad += featureComponentKeys.length\n }\n\n useEffect(() => {\n if (!hasLoadedFeatures) {\n const featureProvidersLocal: FeatureProviderClient<unknown, unknown>[] = []\n let featureProvidersAndComponentsLoaded = 0 // feature providers and components only\n\n Object.entries(clientFunctions).forEach(([key, plugin]) => {\n if (key.startsWith(`lexicalFeature.${schemaPath}.`)) {\n if (!key.includes('.lexical_internal_components.')) {\n featureProvidersLocal.push(plugin)\n }\n featureProvidersAndComponentsLoaded++\n }\n })\n\n if (featureProvidersAndComponentsLoaded === featureProvidersAndComponentsToLoad) {\n setFeatureProviders(featureProvidersLocal)\n setHasLoadedFeatures(true)\n\n /**\n * Loaded feature provided => create the final sanitized editor config\n */\n\n const resolvedClientFeatures = loadClientFeatures({\n clientFunctions,\n schemaPath,\n unSanitizedEditorConfig: {\n features: featureProvidersLocal,\n lexical: lexicalEditorConfig,\n },\n })\n\n setFinalSanitizedEditorConfig(\n sanitizeClientEditorConfig(\n lexicalEditorConfig ? lexicalEditorConfig : defaultEditorLexicalConfig,\n resolvedClientFeatures,\n admin,\n ),\n )\n }\n }\n }, [\n admin,\n featureProviderComponents,\n hasLoadedFeatures,\n clientFunctions,\n schemaPath,\n featureProviderComponents.length,\n featureProviders,\n finalSanitizedEditorConfig,\n lexicalEditorConfig,\n richTextComponentMap,\n featureProvidersAndComponentsToLoad,\n ])\n\n useEffect(() => {\n if (!hasLoadedFeatures) {\n return\n }\n let dataToUse = cellData\n if (dataToUse == null || !hasLoadedFeatures || !finalSanitizedEditorConfig) {\n setPreview('')\n return\n }\n\n // Transform data through load hooks\n if (finalSanitizedEditorConfig?.features?.hooks?.load?.length) {\n finalSanitizedEditorConfig.features.hooks.load.forEach((hook) => {\n dataToUse = hook({ incomingEditorState: dataToUse })\n })\n }\n\n if (!dataToUse || typeof dataToUse !== 'object') {\n setPreview('')\n return\n }\n\n // If data is from Slate and not Lexical\n if (Array.isArray(dataToUse) && !('root' in dataToUse)) {\n setPreview('')\n return\n }\n\n // If data is from payload-plugin-lexical\n if ('jsonContent' in dataToUse) {\n setPreview('')\n return\n }\n\n // initialize headless editor\n const headlessEditor = createHeadlessEditor({\n namespace: finalSanitizedEditorConfig.lexical.namespace,\n nodes: getEnabledNodes({ editorConfig: finalSanitizedEditorConfig }),\n theme: finalSanitizedEditorConfig.lexical.theme,\n })\n headlessEditor.setEditorState(headlessEditor.parseEditorState(dataToUse))\n\n const textContent =\n headlessEditor.getEditorState().read(() => {\n return $getRoot().getTextContent()\n }) || ''\n\n // Limiting the number of characters shown is done in a CSS rule\n setPreview(textContent)\n }, [cellData, lexicalEditorConfig, hasLoadedFeatures, finalSanitizedEditorConfig])\n\n if (!hasLoadedFeatures) {\n return (\n <React.Fragment>\n {Array.isArray(featureProviderComponents) &&\n featureProviderComponents.map((featureProvider) => {\n // get all components starting with key feature.${FeatureProvider.key}.components.{featureComponentKey}\n const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>\n key.startsWith(\n `lexical_internal_feature.${featureProvider.key}.lexical_internal_components.`,\n ),\n )\n\n const featureComponents: React.ReactNode[] = featureComponentKeys.map((key) => {\n return richTextComponentMap.get(key)\n })\n\n return (\n <React.Fragment key={featureProvider.key}>\n {featureComponents?.length\n ? featureComponents.map((FeatureComponent) => {\n return FeatureComponent\n })\n : null}\n {featureProvider.ClientFeature}\n </React.Fragment>\n )\n })}\n </React.Fragment>\n )\n }\n\n return <span>{preview}</span>\n}\n"],"names":["createHeadlessEditor","useClientFunctions","useTableCell","$getRoot","React","useEffect","useState","defaultEditorLexicalConfig","loadClientFeatures","sanitizeClientEditorConfig","getEnabledNodes","RichTextCell","props","admin","lexicalEditorConfig","richTextComponentMap","preview","setPreview","cellData","cellProps","schemaPath","clientFunctions","hasLoadedFeatures","setHasLoadedFeatures","featureProviders","setFeatureProviders","finalSanitizedEditorConfig","setFinalSanitizedEditorConfig","featureProviderComponents","get","sort","a","b","order","featureProvidersAndComponentsToLoad","featureProvider","featureComponentKeys","Array","from","keys","filter","key","startsWith","length","featureProvidersLocal","featureProvidersAndComponentsLoaded","Object","entries","forEach","plugin","includes","push","resolvedClientFeatures","unSanitizedEditorConfig","features","lexical","dataToUse","hooks","load","hook","incomingEditorState","isArray","headlessEditor","namespace","nodes","editorConfig","theme","setEditorState","parseEditorState","textContent","getEditorState","read","getTextContent","Fragment","map","featureComponents","FeatureComponent","ClientFeature","span"],"mappings":"AAAA;;AAIA,SAASA,oBAAoB,QAAQ,oBAAmB;AACxD,SAASC,kBAAkB,EAAEC,YAAY,QAAQ,iBAAgB;AACjE,SAASC,QAAQ,QAAQ,UAAS;AAClC,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAMlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,0BAA0B,QAAQ,uCAAsC;AACjF,SAASC,eAAe,QAAQ,4BAA2B;AAE3D,OAAO,MAAMC,eAKT,CAACC;IACH,MAAM,EAAEC,KAAK,EAAEC,mBAAmB,EAAEC,oBAAoB,EAAE,GAAGH;IAE7D,MAAM,CAACI,SAASC,WAAW,GAAGb,MAAME,QAAQ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BQ;QAAmBI;KAA2B;IAEjF,IAAI,CAACJ,mBAAmB;QACtB,qBACE,KAAClB,MAAMqE,QAAQ;sBACZpC,MAAMwB,OAAO,CAACjC,8BACbA,0BAA0B8C,GAAG,CAAC,CAACvC;gBAC7B,uGAAuG;gBACvG,MAAMC,uBAAuBC,MAAMC,IAAI,CAACvB,qBAAqBwB,IAAI,IAAIC,MAAM,CAAC,CAACC,MAC3EA,IAAIC,UAAU,CACZ,CAAC,yBAAyB,EAAEP,gBAAgBM,GAAG,CAAC,6BAA6B,CAAC;gBAIlF,MAAMkC,oBAAuCvC,qBAAqBsC,GAAG,CAAC,CAACjC;oBACrE,OAAO1B,qBAAqBc,GAAG,CAACY;gBAClC;gBAEA,qBACE,MAACrC,MAAMqE,QAAQ;;wBACZE,mBAAmBhC,SAChBgC,kBAAkBD,GAAG,CAAC,CAACE;4BACrB,OAAOA;wBACT,KACA;wBACHzC,gBAAgB0C,aAAa;;mBANX1C,gBAAgBM,GAAG;YAS5C;;IAGR;IAEA,qBAAO,KAACqC;kBAAM9D;;AAChB,EAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b as y}from"./chunk-3K3B6PJM.js";import{Drawer as $}from"@payloadcms/ui";import{Form as R,FormSubmit as F,RenderFields as O,useConfig as E,useDocumentInfo as M,useFieldProps as T,useTranslation as A}from"@payloadcms/ui";import{getFormState as g}from"@payloadcms/ui/shared";import{useCallback as L,useEffect as k,useState as P}from"react";import{v4 as I}from"uuid";import{jsx as D,jsxs as N}from"react/jsx-runtime";var C=({data:e,featureKey:t,handleDrawerSubmit:o,schemaPathSuffix:a})=>{let{t:i}=A(),{id:n}=M(),{schemaPath:l}=T(),r=E(),[p,x]=P(!1),{field:{richTextComponentMap:_}}=y(),U=`lexical_internal_feature.${t}.fields${a?`.${a}`:""}`,s=`${l}.lexical_internal_feature.${t}${a?`.${a}`:""}`,d=_.get(U);k(()=>{e&&(async()=>{let w=await g({apiRoute:r.routes.api,body:{id:n,data:e,operation:"update",schemaPath:s},serverURL:r.serverURL});x(w)})()},[r.routes.api,r.serverURL,s,n,e]);let m=L(async({formState:f})=>await g({apiRoute:r.routes.api,body:{id:n,formState:f,operation:"update",schemaPath:s},serverURL:r.serverURL}),[r.routes.api,r.serverURL,s,n]);return p===!1?null:N(R,{beforeSubmit:[m],disableValidationOnSubmit:!0,fields:Array.isArray(d)?d:[],initialState:p,onChange:[m],onSubmit:o,uuid:I(),children:[D(O,{fieldMap:Array.isArray(d)?d:[],forceRender:!0,path:"",readOnly:!1,schemaPath:s}),D(F,{children:i("fields:saveChanges")})]})};import{jsx as S}from"react/jsx-runtime";var lt=({className:e,data:t,drawerSlug:o,drawerTitle:a,featureKey:i,handleDrawerSubmit:n,schemaPathSuffix:l})=>S($,{className:e,slug:o,title:a??"",children:S(C,{data:t,featureKey:i,handleDrawerSubmit:n,schemaPathSuffix:l})});import{useAuth as H,useConfig as B,useEntityVisibility as K}from"@payloadcms/ui";import*as u from"react";var W=(e,t)=>e.filter(({slug:o,admin:{enableRichTextRelationship:a},upload:i})=>t.visibleEntities.collections.includes(o)?t?.uploads?a&&!!i:i?!1:a:!1),ut=e=>{let{children:t,uploads:o=!1,...a}=e,{collections:i}=B(),{user:n}=H(),{visibleEntities:l}=K(),[r]=u.useState(()=>W(i,{uploads:o,user:n,visibleEntities:l}).map(({slug:p})=>p));return r.length?u.cloneElement(t,{...a,enabledCollectionSlugs:r}):null};import{createCommand as J}from"lexical";var ft=J("INSERT_UPLOAD_WITH_DRAWER_COMMAND");import{DecoratorBlockNode as V}from"@lexical/react/LexicalDecoratorBlockNode.js";import h from"bson-objectid";import{$applyNodeReplacement as X}from"lexical";import*as b from"react";import{jsx as Q}from"react/jsx-runtime";var G=b.lazy(()=>import("./component-RV346GAA.js").then(e=>({default:e.UploadComponent})));function j(e){return e.parentElement!=null&&e.parentElement.tagName==="LI"&&e.previousSibling===null&&e.getAttribute("aria-roledescription")==="checkbox"}function q(e){if(e.hasAttribute("data-lexical-upload-relation-to")&&e.hasAttribute("data-lexical-upload-id")){let o=e.getAttribute("data-lexical-upload-id"),a=e.getAttribute("data-lexical-upload-relation-to");if(o!=null&&a!=null)return{node:v({data:{fields:{},relationTo:a,value:o}})}}let t=e;return t.src.startsWith("file:///")||j(t),null}var c=class e extends V{__data;constructor({data:t,format:o,key:a}){super(o,a),this.__data=t}static clone(t){return new e({data:t.__data,format:t.__format,key:t.__key})}static getType(){return"upload"}static importDOM(){return{img:t=>({conversion:q,priority:0})}}static importJSON(t){t.version===1&&t?.value?.id&&(t.value=t.value.id),t.version===2&&!t?.id&&(t.id=new h.default().toHexString(),t.version=3);let o={id:t.id,fields:t.fields,relationTo:t.relationTo,value:t.value},a=v({data:o});return a.setFormat(t.format),a}static isInline(){return!1}decorate(){return Q(G,{data:this.__data,format:this.__format,nodeKey:this.getKey()})}exportDOM(){let t=document.createElement("img");return t.setAttribute("data-lexical-upload-id",String(this.__data?.value)),t.setAttribute("data-lexical-upload-relation-to",this.__data?.relationTo),{element:t}}exportJSON(){return{...super.exportJSON(),...this.getData(),type:"upload",version:3}}getData(){return this.getLatest().__data}setData(t){let o=this.getWritable();o.__data=t}updateDOM(){return!1}};function v({data:e}){return e?.id||(e.id=new h.default().toHexString()),X(new c({data:e}))}function St(e){return e instanceof c}export{lt as a,ut as b,ft as c,c as d,v as e,St as f};
|
|
2
|
+
//# sourceMappingURL=chunk-CUMDYP5E.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utilities/fieldsDrawer/Drawer.tsx", "../../../src/utilities/fieldsDrawer/DrawerContent.tsx", "../../../src/features/relationship/utils/EnabledRelationshipsCondition.tsx", "../../../src/features/upload/drawer/commands.ts", "../../../src/features/upload/nodes/UploadNode.tsx"],
|
|
4
|
+
"sourcesContent": ["'use client'\nimport type { FormState } from 'payload'\n\nimport { Drawer } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { DrawerContent } from './DrawerContent.js'\n\nexport type FieldsDrawerProps = {\n className?: string\n data: any\n drawerSlug: string\n drawerTitle?: string\n featureKey: string\n handleDrawerSubmit: (fields: FormState, data: Record<string, unknown>) => void\n schemaPathSuffix?: string\n}\n\n/**\n * This FieldsDrawer component can be used to easily create a Drawer that contains a form with fields within your feature.\n * The fields are taken directly from the schema map based on your `featureKey` and `schemaPathSuffix`. Thus, this can only\n * be used if you provide your field schema inside the `generateSchemaMap` prop of your feature.server.ts.\n */\nexport const FieldsDrawer: React.FC<FieldsDrawerProps> = ({\n className,\n data,\n drawerSlug,\n drawerTitle,\n featureKey,\n handleDrawerSubmit,\n schemaPathSuffix,\n}) => {\n // The Drawer only renders its children (and itself) if it's open. Thus, by extracting the main content\n // to DrawerContent, this should be faster\n return (\n <Drawer className={className} slug={drawerSlug} title={drawerTitle ?? ''}>\n <DrawerContent\n data={data}\n featureKey={featureKey}\n handleDrawerSubmit={handleDrawerSubmit}\n schemaPathSuffix={schemaPathSuffix}\n />\n </Drawer>\n )\n}\n", "'use client'\nimport type { FormProps } from '@payloadcms/ui'\nimport type { FormState } from 'payload'\n\nimport {\n Form,\n FormSubmit,\n RenderFields,\n useConfig,\n useDocumentInfo,\n useFieldProps,\n useTranslation,\n} from '@payloadcms/ui'\nimport { getFormState } from '@payloadcms/ui/shared'\nimport React, { useCallback, useEffect, useState } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport type { FieldsDrawerProps } from './Drawer.js'\n\nimport { useEditorConfigContext } from '../../lexical/config/client/EditorConfigProvider.js'\n\nexport const DrawerContent: React.FC<Omit<FieldsDrawerProps, 'drawerSlug' | 'drawerTitle'>> = ({\n data,\n featureKey,\n handleDrawerSubmit,\n schemaPathSuffix,\n}) => {\n const { t } = useTranslation()\n const { id } = useDocumentInfo()\n const { schemaPath } = useFieldProps()\n const config = useConfig()\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `lexical_internal_feature.${featureKey}.fields${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.${featureKey}${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath) // Field Schema\n\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n setInitialState(state)\n }\n\n if (data) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id, data])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n return 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\n [config.routes.api, config.serverURL, schemaFieldsPath, id],\n )\n\n if (initialState === false) {\n return null\n }\n\n return (\n <Form\n beforeSubmit={[onChange]}\n disableValidationOnSubmit\n fields={Array.isArray(fieldMap) ? fieldMap : []}\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleDrawerSubmit}\n uuid={uuid()}\n >\n <RenderFields\n fieldMap={Array.isArray(fieldMap) ? fieldMap : []}\n forceRender\n path=\"\" // See Blocks feature path for details as for why this is empty\n readOnly={false}\n schemaPath={schemaFieldsPath}\n />\n\n <FormSubmit>{t('fields:saveChanges')}</FormSubmit>\n </Form>\n )\n}\n", "import type { ClientCollectionConfig, ClientUser, VisibleEntities } from 'payload'\n\nimport { useAuth, useConfig, useEntityVisibility } from '@payloadcms/ui'\nimport * as React from 'react'\n\ntype Options = {\n uploads: boolean\n user: ClientUser\n visibleEntities: VisibleEntities\n}\n\ntype FilteredCollectionsT = (\n collections: ClientCollectionConfig[],\n options?: Options,\n) => ClientCollectionConfig[]\n\nconst filterRichTextCollections: FilteredCollectionsT = (collections, options) => {\n return collections.filter(({ slug, admin: { enableRichTextRelationship }, upload }) => {\n if (!options.visibleEntities.collections.includes(slug)) {\n return false\n }\n\n if (options?.uploads) {\n return enableRichTextRelationship && Boolean(upload) === true\n }\n\n return upload ? false : enableRichTextRelationship\n })\n}\n\nexport const EnabledRelationshipsCondition: React.FC<any> = (props) => {\n const { children, uploads = false, ...rest } = props\n const { collections } = useConfig()\n const { user } = useAuth()\n const { visibleEntities } = useEntityVisibility()\n\n const [enabledCollectionSlugs] = React.useState(() =>\n filterRichTextCollections(collections, { uploads, user, visibleEntities }).map(\n ({ slug }) => slug,\n ),\n )\n\n if (!enabledCollectionSlugs.length) {\n return null\n }\n\n return React.cloneElement(children, { ...rest, enabledCollectionSlugs })\n}\n", "'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { createCommand } from 'lexical'\n\nexport const INSERT_UPLOAD_WITH_DRAWER_COMMAND: LexicalCommand<{\n replace: { nodeKey: string } | false\n}> = createCommand('INSERT_UPLOAD_WITH_DRAWER_COMMAND')\n", "import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport type {\n DOMConversionMap,\n DOMConversionOutput,\n DOMExportOutput,\n ElementFormatType,\n LexicalNode,\n NodeKey,\n Spread,\n} from 'lexical'\nimport type { CollectionSlug } from 'payload'\nimport type { JSX } from 'react'\n\nimport { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport ObjectID from 'bson-objectid'\nimport { $applyNodeReplacement } from 'lexical'\nimport * as React from 'react'\n\nconst RawUploadComponent = React.lazy(() =>\n import('../component/index.js').then((module) => ({ default: module.UploadComponent })),\n)\n\nexport type UploadData = {\n fields: {\n // unknown, custom fields:\n [key: string]: unknown\n }\n id: string\n relationTo: CollectionSlug\n value: number | string\n}\n\nfunction isGoogleDocCheckboxImg(img: HTMLImageElement): boolean {\n return (\n img.parentElement != null &&\n img.parentElement.tagName === 'LI' &&\n img.previousSibling === null &&\n img.getAttribute('aria-roledescription') === 'checkbox'\n )\n}\n\nfunction $convertUploadElement(domNode: HTMLImageElement): DOMConversionOutput | null {\n if (\n domNode.hasAttribute('data-lexical-upload-relation-to') &&\n domNode.hasAttribute('data-lexical-upload-id')\n ) {\n const id = domNode.getAttribute('data-lexical-upload-id')\n const relationTo = domNode.getAttribute('data-lexical-upload-relation-to')\n\n if (id != null && relationTo != null) {\n const node = $createUploadNode({\n data: {\n fields: {},\n relationTo,\n value: id,\n },\n })\n return { node }\n }\n }\n const img = domNode\n if (img.src.startsWith('file:///') || isGoogleDocCheckboxImg(img)) {\n return null\n }\n // TODO: Auto-upload functionality here!\n //}\n return null\n}\n\nexport type SerializedUploadNode = Spread<UploadData, SerializedDecoratorBlockNode> & {\n children?: never // required so that our typed editor state doesn't automatically add children\n type: 'upload'\n}\n\nexport class UploadNode extends DecoratorBlockNode {\n __data: UploadData\n\n constructor({\n data,\n format,\n key,\n }: {\n data: UploadData\n format?: ElementFormatType\n key?: NodeKey\n }) {\n super(format, key)\n this.__data = data\n }\n\n static clone(node: UploadNode): UploadNode {\n return new UploadNode({\n data: node.__data,\n format: node.__format,\n key: node.__key,\n })\n }\n\n static getType(): string {\n return 'upload'\n }\n\n static importDOM(): DOMConversionMap | null {\n return {\n img: (node: HTMLImageElement) => ({\n conversion: $convertUploadElement,\n priority: 0,\n }),\n }\n }\n\n static importJSON(serializedNode: SerializedUploadNode): UploadNode {\n if (serializedNode.version === 1 && (serializedNode?.value as unknown as { id: string })?.id) {\n serializedNode.value = (serializedNode.value as unknown as { id: string }).id\n }\n if (serializedNode.version === 2 && !serializedNode?.id) {\n serializedNode.id = new ObjectID.default().toHexString()\n serializedNode.version = 3\n }\n\n const importedData: UploadData = {\n id: serializedNode.id,\n fields: serializedNode.fields,\n relationTo: serializedNode.relationTo,\n value: serializedNode.value,\n }\n\n const node = $createUploadNode({ data: importedData })\n node.setFormat(serializedNode.format)\n\n return node\n }\n\n static isInline(): false {\n return false\n }\n\n decorate(): JSX.Element {\n // @ts-expect-error\n return <RawUploadComponent data={this.__data} format={this.__format} nodeKey={this.getKey()} />\n }\n\n exportDOM(): DOMExportOutput {\n const element = document.createElement('img')\n element.setAttribute('data-lexical-upload-id', String(this.__data?.value))\n element.setAttribute('data-lexical-upload-relation-to', this.__data?.relationTo)\n\n return { element }\n }\n\n exportJSON(): SerializedUploadNode {\n return {\n ...super.exportJSON(),\n ...this.getData(),\n type: 'upload',\n version: 3,\n }\n }\n\n getData(): UploadData {\n return this.getLatest().__data\n }\n\n setData(data: UploadData): void {\n const writable = this.getWritable()\n writable.__data = data\n }\n\n // eslint-disable-next-line class-methods-use-this\n updateDOM(): false {\n return false\n }\n}\n\nexport function $createUploadNode({\n data,\n}: {\n data: Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>\n}): UploadNode {\n if (!data?.id) {\n data.id = new ObjectID.default().toHexString()\n }\n return $applyNodeReplacement(new UploadNode({ data: data as UploadData }))\n}\n\nexport function $isUploadNode(node: LexicalNode | null | undefined): node is UploadNode {\n return node instanceof UploadNode\n}\n"],
|
|
5
|
+
"mappings": "wCAGA,OAAS,UAAAA,MAAc,iBCCvB,OACE,QAAAC,EACA,cAAAC,EACA,gBAAAC,EACA,aAAAC,EACA,mBAAAC,EACA,iBAAAC,EACA,kBAAAC,MACK,iBACP,OAAS,gBAAAC,MAAoB,wBAC7B,OAAgB,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACxD,OAAS,MAAMC,MAAY,OAqEvB,OASE,OAAAC,EATF,QAAAC,MAAA,oBA/DG,IAAMC,EAAiF,CAAC,CAC7F,KAAAC,EACA,WAAAC,EACA,mBAAAC,EACA,iBAAAC,CACF,IAAM,CACJ,GAAM,CAAE,EAAAC,CAAE,EAAIC,EAAe,EACvB,CAAE,GAAAC,CAAG,EAAIC,EAAgB,EACzB,CAAE,WAAAC,CAAW,EAAIC,EAAc,EAC/BC,EAASC,EAAU,EACnB,CAACC,EAAcC,C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"FormSubmit", "RenderFields", "useConfig", "useDocumentInfo", "useFieldProps", "useTranslation", "getFormState", "useCallback", "useEffect", "useState", "uuid", "jsx", "jsxs", "DrawerContent", "data", "featureKey", "handleDrawerSubmit", "schemaPathSuffix", "t", "useTranslation", "id", "useDocumentInfo", "schemaPath", "useFieldProps", "config", "useConfig", "initialState", "setInitialState", "useState", "richTextComponentMap", "useEditorConfigContext", "componentMapRenderedFieldsPath", "schemaFieldsPath", "fieldMap", "useEffect", "state", "getFormState", "onChange", "useCallback", "prevFormState", "Form", "uuid", "RenderFields", "FormSubmit", "jsx", "FieldsDrawer", "className", "data", "drawerSlug", "drawerTitle", "featureKey", "handleDrawerSubmit", "schemaPathSuffix", "Drawer", "DrawerContent", "useAuth", "useConfig", "useEntityVisibility", "React", "filterRichTextCollections", "collections", "options", "slug", "enableRichTextRelationship", "upload", "EnabledRelationshipsCondition", "props", "children", "uploads", "rest", "user", "visibleEntities", "enabledCollectionSlugs", "createCommand", "INSERT_UPLOAD_WITH_DRAWER_COMMAND", "DecoratorBlockNode", "ObjectID", "$applyNodeReplacement", "React", "jsx", "RawUploadComponent", "module", "isGoogleDocCheckboxImg", "img", "$convertUploadElement", "domNode", "id", "relationTo", "$createUploadNode", "UploadNode", "_UploadNode", "data", "format", "key", "node", "serializedNode", "importedData", "element", "writable", "$isUploadNode"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{b as x}from"./chunk-3K3B6PJM.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"@payloadcms/ui/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-7J2IXLN3.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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: FormFieldBase & {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n }\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 '@payloadcms/ui/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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AAQ,EACnB,UAAWtB,EACX,KAAM+B,GAAK,EAEX,SAAAxC,EAACyC,EAAA,CACC,UAAWvC,EACX,MAAOe,EACP,SAAUZ,EACV,WAAY,MAAM,QAAQsB,CAAQ,EAAIA,EAAW,CAAC,EAClD,QAASrB,EACT,KAAM,GAAGO,CAAI,oCAAoCR,EAAS,SAAS,GACnE,aAAcoB,EACd,WAAYD,EACd,EACF,EAEAxB,EAAC0C,GAAA,CACC,UAAWN,EACX,iBAAiB,UACjB,OACEpC,EAAC,OAAI,UAAW,GAAGE,CAAS,iBAC1B,SAAAD,GAAC,OACC,UAAAD,EAAC2C,GAAA,CACC,UAAW,GAAGzC,CAAS,gBAAgBA,CAAS,gBAAgBG,GAAU,SAAS,GACnF,UAAU,QAET,gBAAOoB,EAAa,OAAO,UAAa,SACrCmB,GAAenB,EAAa,OAAO,SAAUS,CAAI,EACjD,mBACN,EACAlC,EAAC6C,GAAA,CAAa,KAAK,YAAY,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,2 +1,2 @@
|
|
|
1
|
-
"use client";import{a as L,b as O,c as A,f as F}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=component-
|
|
1
|
+
"use client";import{a as L,b as O,c as A,f as F}from"./chunk-CUMDYP5E.js";import{b as T}from"./chunk-3K3B6PJM.js";import{useLexicalComposerContext as X}from"@lexical/react/LexicalComposerContext.js";import{useLexicalNodeSelection as Z}from"@lexical/react/useLexicalNodeSelection.js";import{mergeRegister as ee}from"@lexical/utils";import{getTranslation as K}from"@payloadcms/translations";import{Button as N,DrawerToggler as oe,File as te,useConfig as ae,useDocumentDrawer as le,useDrawerSlug as re,useModal as ne,usePayloadAPI as ie,useTranslation as se}from"@payloadcms/ui";import{$getNodeByKey as E,$getSelection as de,$isNodeSelection as ce,CLICK_COMMAND as ue,COMMAND_PRIORITY_LOW as w,KEY_BACKSPACE_COMMAND as pe,KEY_DELETE_COMMAND as me}from"lexical";import{useCallback as i,useEffect as fe,useReducer as ge,useRef as Ce,useState as De}from"react";import{jsx as o,jsxs as s}from"react/jsx-runtime";var t="lexical-upload",B={depth:0},ve=d=>{let{data:{fields:I,relationTo:R,value:c},nodeKey:l}=d,{collections:k,routes:{api:j},serverURL:W}=ae(),C=Ce(null),{closeModal:y}=ne(),[a]=X(),[r,u,D]=Z(l),{editorConfig:Y,field:v}=T(),{i18n:S,t:p}=se(),[$,H]=ge(e=>e+1,0),[n]=De(()=>k.find(e=>e.slug===R)),m=re("upload-drawer"),[z,q,{closeDrawer:h}]=le({id:c,collectionSlug:n.slug}),[{data:f},{setParams:P}]=ie(`${W}${j}/${n.slug}/${c}`,{initialParams:B}),U=f?.thumbnailURL||f?.url,G=i(()=>{a.update(()=>{E(l).remove()})},[a,l]),J=i(e=>{P({...B,cacheBust:$}),H(),h()},[P,$,h]),_=i(e=>{if(r&&ce(de())){e.preventDefault();let g=E(l);if(F(g))return g.remove(),!0}return!1},[r,l]),M=i(e=>e.target===C.current||C.current?.contains(e.target)?(e.shiftKey?u(!r):r||(D(),u(!0)),!0):!1,[r,u,D]);fe(()=>ee(a.registerCommand(ue,M,w),a.registerCommand(me,_,w),a.registerCommand(pe,_,w)),[D,a,r,l,_,u,M]);let x=(Y?.resolvedFeatureMap?.get("upload")?.sanitizedClientFeatureProps).collections?.[n.slug]?.hasExtraFields,Q=i((e,g)=>{a.update(()=>{let b=E(l);if(b){let V={...b.getData(),fields:g};b.setData(V)}}),y(m)},[y,a,m,l]);return s("div",{className:[t,r&&`${t}--selected`].filter(Boolean).join(" "),contentEditable:!1,ref:C,children:[s("div",{className:`${t}__card`,children:[s("div",{className:`${t}__topRow`,children:[o("div",{className:`${t}__thumbnail`,children:U?o("img",{alt:f?.filename,"data-lexical-upload-id":c,"data-lexical-upload-relation-to":R,src:U}):o(te,{})}),s("div",{className:`${t}__topRowRightPanel`,children:[o("div",{className:`${t}__collectionLabel`,children:K(n.labels.singular,S)}),a.isEditable()&&s("div",{className:`${t}__actions`,children:[x?o(oe,{className:`${t}__upload-drawer-toggler`,disabled:v?.readOnly,slug:m,children:o(N,{buttonStyle:"icon-label",el:"div",icon:"edit",onClick:e=>{e.preventDefault()},round:!0,tooltip:p("fields:editRelationship")})}):null,o(N,{buttonStyle:"icon-label",disabled:v?.readOnly,el:"div",icon:"swap",onClick:()=>{a.dispatchCommand(A,{replace:{nodeKey:l}})},round:!0,tooltip:p("fields:swapUpload")}),o(N,{buttonStyle:"icon-label",className:`${t}__removeButton`,disabled:v?.readOnly,icon:"x",onClick:e=>{e.preventDefault(),G()},round:!0,tooltip:p("fields:removeUpload")})]})]})]}),o("div",{className:`${t}__bottomRow`,children:o(q,{className:`${t}__doc-drawer-toggler`,children:o("strong",{children:f?.filename})})})]}),c&&o(z,{onSave:J}),x?o(L,{data:I,drawerSlug:m,drawerTitle:p("general:editLabel",{label:K(n.labels.singular,S)}),featureKey:"upload",handleDrawerSubmit:Q,schemaPathSuffix:n.slug}):null]})},xe=d=>o(O,{...d,uploads:!0,children:o(ve,{...d})});export{xe as UploadComponent};
|
|
2
|
+
//# sourceMappingURL=component-RV346GAA.js.map
|