@payloadcms/richtext-lexical 3.0.0-beta.120 → 3.0.0-beta.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC1F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAY3D,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,CAAA;AAEtD,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,wBAAwB,CAmKlE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC1F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAa3D,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,CAAA;AAEtD,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,wBAAwB,CAmKlE,CAAA"}
@@ -7,10 +7,10 @@ import { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@le
7
7
  import { getTranslation } from '@payloadcms/translations';
8
8
  import { formatDrawerSlug, useEditDepth, useFieldProps, useTranslation } from '@payloadcms/ui';
9
9
  import { $createParagraphNode, $getNodeByKey, $getPreviousSelection, $getSelection, $insertNodes, $isParagraphNode, $isRangeSelection, $isRootOrShadowRoot, COMMAND_PRIORITY_EDITOR } from 'lexical';
10
- import { useLexicalDrawer } from 'packages/richtext-lexical/src/utilities/fieldsDrawer/useLexicalDrawer.js';
11
10
  import React, { useEffect, useState } from 'react';
12
11
  import { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js';
13
12
  import { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js';
13
+ import { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js';
14
14
  import { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js';
15
15
  import { $createInlineBlockNode, $isInlineBlockNode } from '../nodes/InlineBlocksNode.js';
16
16
  import { INSERT_BLOCK_COMMAND, INSERT_INLINE_BLOCK_COMMAND, OPEN_INLINE_BLOCK_DRAWER_COMMAND } from './commands.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","$wrapNodeInElement","mergeRegister","getTranslation","formatDrawerSlug","useEditDepth","useFieldProps","useTranslation","$createParagraphNode","$getNodeByKey","$getPreviousSelection","$getSelection","$insertNodes","$isParagraphNode","$isRangeSelection","$isRootOrShadowRoot","COMMAND_PRIORITY_EDITOR","useLexicalDrawer","React","useEffect","useState","useEditorConfigContext","FieldsDrawer","$createBlockNode","BlockNode","$createInlineBlockNode","$isInlineBlockNode","INSERT_BLOCK_COMMAND","INSERT_INLINE_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND","BlocksPlugin","$","editor","blockFields","setBlockFields","blockType","setBlockType","targetNodeKey","setTargetNodeKey","i18n","t","schemaPath","uuid","editDepth","t0","t1","slug","depth","drawerSlug","toggleDrawer","field","t2","richTextComponentMap","t3","t4","hasNodes","Error","registerCommand","payload","update","selection","blockNode","focus","focusNode","getNode","getTextContentSize","getParentOrThrow","getChildren","filter","node","length","remove","fields","node_0","setFields","inlineBlockNode","selectEnd","t5","fields_0","nodeKey","rangeSelection","getEditorState","read","selection_0","schemaFieldsPath","componentMapRenderedBlockPath","t6","Symbol","for","bb0","blocksField","has","get","clientBlock","blocks","find","block","blockDisplayName","labels","singular","t7","_fields","data","dispatchCommand","_jsx","drawerTitle","id","label","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPathSuffix"],"sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport type { BlocksFieldClient } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n formatDrawerSlug,\n useEditDepth,\n useFieldProps,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport {\n $createParagraphNode,\n $getNodeByKey,\n $getPreviousSelection,\n $getSelection,\n $insertNodes,\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_EDITOR,\n type RangeSelection,\n} from 'lexical'\nimport { useLexicalDrawer } from 'packages/richtext-lexical/src/utilities/fieldsDrawer/useLexicalDrawer.js'\nimport React, { useEffect, useState } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { BlockFields, BlockFieldsOptionalID } from '../../server/nodes/BlocksNode.js'\nimport type { BlocksFeatureClientProps } from '../index.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js'\nimport { $createInlineBlockNode, $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\nimport {\n INSERT_BLOCK_COMMAND,\n INSERT_INLINE_BLOCK_COMMAND,\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n} from './commands.js'\n\nexport type InsertBlockPayload = BlockFieldsOptionalID\n\nexport const BlocksPlugin: PluginComponent<BlocksFeatureClientProps> = () => {\n const [editor] = useLexicalComposerContext()\n const [blockFields, setBlockFields] = useState<BlockFields | null>(null)\n const [blockType, setBlockType] = useState<string>('' as any)\n const [targetNodeKey, setTargetNodeKey] = useState<null | string>(null)\n const { i18n, t } = useTranslation<string, any>()\n const { schemaPath } = useFieldProps()\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-` + uuid,\n depth: editDepth,\n })\n\n const { toggleDrawer } = useLexicalDrawer(drawerSlug)\n\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n useEffect(() => {\n if (!editor.hasNodes([BlockNode])) {\n throw new Error('BlocksPlugin: BlocksNode not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand<InsertBlockPayload>(\n INSERT_BLOCK_COMMAND,\n (payload: InsertBlockPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const blockNode = $createBlockNode(payload)\n // Insert blocks node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(blockNode)\n\n const { focus } = selection\n const focusNode = focus.getNode()\n\n // First, delete currently selected node if it's an empty paragraph and if there are sufficient\n // paragraph nodes (more than 1) left in the parent node, so that we don't \"trap\" the user\n if (\n $isParagraphNode(focusNode) &&\n focusNode.getTextContentSize() === 0 &&\n focusNode\n .getParentOrThrow()\n .getChildren()\n .filter((node) => $isParagraphNode(node)).length > 1\n ) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n INSERT_INLINE_BLOCK_COMMAND,\n (fields) => {\n if (targetNodeKey) {\n const node = $getNodeByKey(targetNodeKey)\n\n if (!node || !$isInlineBlockNode(node)) {\n return false\n }\n\n node.setFields(fields as BlockFields)\n\n setTargetNodeKey(null)\n return true\n }\n\n const inlineBlockNode = $createInlineBlockNode(fields as BlockFields)\n $insertNodes([inlineBlockNode])\n if ($isRootOrShadowRoot(inlineBlockNode.getParentOrThrow())) {\n $wrapNodeInElement(inlineBlockNode, $createParagraphNode).selectEnd()\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n ({ fields, nodeKey }) => {\n setBlockFields((fields as BlockFields) ?? null)\n setTargetNodeKey(nodeKey ?? null)\n setBlockType(fields?.blockType ?? ('' as any))\n\n if (nodeKey) {\n toggleDrawer()\n return true\n }\n\n let rangeSelection: null | RangeSelection = null\n\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n rangeSelection = selection\n }\n })\n\n if (rangeSelection) {\n //setLastSelection(rangeSelection)\n toggleDrawer()\n }\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [editor, targetNodeKey, toggleDrawer])\n\n if (!blockFields) {\n return null\n }\n\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.lexical_inline_blocks.${blockFields?.blockType}`\n\n const componentMapRenderedBlockPath = `lexical_internal_feature.blocks.fields.lexical_inline_blocks`\n const blocksField: BlocksFieldClient = richTextComponentMap?.has(componentMapRenderedBlockPath)\n ? richTextComponentMap.get(componentMapRenderedBlockPath)[0]\n : null\n\n const clientBlock = blocksField\n ? blocksField.blocks.find((block) => block.slug === blockFields?.blockType)\n : null\n\n if (!blocksField) {\n return null\n }\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels?.singular, i18n)\n : clientBlock?.slug\n\n return (\n <FieldsDrawer\n data={blockFields}\n drawerSlug={drawerSlug}\n drawerTitle={t(`lexical:blocks:inlineBlocks:${blockFields?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n featureKey=\"blocks\"\n fieldMapOverride={clientBlock?.fields}\n handleDrawerSubmit={(_fields, data) => {\n if (!data) {\n return\n }\n\n data.blockType = blockType\n\n editor.dispatchCommand(INSERT_INLINE_BLOCK_COMMAND, data)\n }}\n sch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AAA/C,IAAa;MAAA,IAAAsD,EAAA;MAAA,IAAArE,CAAA,SAAAI,SAAA,IAAAJ,CAAA,SAAAC,MAAA;QAWOoE,EAAA,GAAAA,CAAAC,OAAA,EAAAC,IAAA;UAAA,KACbA,IAAA;YAAA;UAAA;UAILA,IAAA,CAAAnE,SAAA,GAAiBA,SAAA;UAEjBH,MAAA,CAAAuE,eAAA,CAAA3E,2BAAA,EAAoD0E,IAAA;QAAA;QACtDvE,CAAA,OAAAI,SAAA;QAAAJ,CAAA,OAAAC,MAAA;QAAAD,CAAA,OAAAqE,EAAA;MAAA;QAAAA,EAAA,GAAArE,CAAA;MAAA;MAhBF8C,EAAA,GAAA2B,IAAA,CAAAlF,YAAA;QAAAgF,IAAA,EACQrE,WAAA;QAAAe,UAAA;QAAAyD,WAAA,EAEOjE,CAAA,CAAE,+BAA+BP,WAAA,EAAAyE,EAAA,GAAkB,SAAS,UAAU;UAAAC,KAAA,EAC1EV,gBAAA,IAAoBzD,CAAA,CAAE;QAAA,CAC/B;QAAAoE,UAAA,EACW;QAAAC,gBAAA,EACOhB,WAAA,EAAArB,MAAA;QAAAsC,kBAAA,EACEV,EAQpB;QAAAW,wBAAA,EAC0B3B,gBAAA;QAAA4B,gBAAA,EACR/E,WAAA,EAAAE;MAAA,C;;;;;;;;;;;;;;;;;;;SAlBpB0C,E;CAqBJ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","$wrapNodeInElement","mergeRegister","getTranslation","formatDrawerSlug","useEditDepth","useFieldProps","useTranslation","$createParagraphNode","$getNodeByKey","$getPreviousSelection","$getSelection","$insertNodes","$isParagraphNode","$isRangeSelection","$isRootOrShadowRoot","COMMAND_PRIORITY_EDITOR","React","useEffect","useState","useEditorConfigContext","FieldsDrawer","useLexicalDrawer","$createBlockNode","BlockNode","$createInlineBlockNode","$isInlineBlockNode","INSERT_BLOCK_COMMAND","INSERT_INLINE_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND","BlocksPlugin","$","editor","blockFields","setBlockFields","blockType","setBlockType","targetNodeKey","setTargetNodeKey","i18n","t","schemaPath","uuid","editDepth","t0","t1","slug","depth","drawerSlug","toggleDrawer","field","t2","richTextComponentMap","t3","t4","hasNodes","Error","registerCommand","payload","update","selection","blockNode","focus","focusNode","getNode","getTextContentSize","getParentOrThrow","getChildren","filter","node","length","remove","fields","node_0","setFields","inlineBlockNode","selectEnd","t5","fields_0","nodeKey","rangeSelection","getEditorState","read","selection_0","schemaFieldsPath","componentMapRenderedBlockPath","t6","Symbol","for","bb0","blocksField","has","get","clientBlock","blocks","find","block","blockDisplayName","labels","singular","t7","_fields","data","dispatchCommand","_jsx","drawerTitle","id","label","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPathSuffix"],"sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport type { BlocksFieldClient } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n formatDrawerSlug,\n useEditDepth,\n useFieldProps,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport {\n $createParagraphNode,\n $getNodeByKey,\n $getPreviousSelection,\n $getSelection,\n $insertNodes,\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_EDITOR,\n type RangeSelection,\n} from 'lexical'\nimport React, { useEffect, useState } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { BlockFields, BlockFieldsOptionalID } from '../../server/nodes/BlocksNode.js'\nimport type { BlocksFeatureClientProps } from '../index.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js'\nimport { $createInlineBlockNode, $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\nimport {\n INSERT_BLOCK_COMMAND,\n INSERT_INLINE_BLOCK_COMMAND,\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n} from './commands.js'\n\nexport type InsertBlockPayload = BlockFieldsOptionalID\n\nexport const BlocksPlugin: PluginComponent<BlocksFeatureClientProps> = () => {\n const [editor] = useLexicalComposerContext()\n const [blockFields, setBlockFields] = useState<BlockFields | null>(null)\n const [blockType, setBlockType] = useState<string>('' as any)\n const [targetNodeKey, setTargetNodeKey] = useState<null | string>(null)\n const { i18n, t } = useTranslation<string, any>()\n const { schemaPath } = useFieldProps()\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-` + uuid,\n depth: editDepth,\n })\n\n const { toggleDrawer } = useLexicalDrawer(drawerSlug)\n\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n useEffect(() => {\n if (!editor.hasNodes([BlockNode])) {\n throw new Error('BlocksPlugin: BlocksNode not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand<InsertBlockPayload>(\n INSERT_BLOCK_COMMAND,\n (payload: InsertBlockPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const blockNode = $createBlockNode(payload)\n // Insert blocks node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(blockNode)\n\n const { focus } = selection\n const focusNode = focus.getNode()\n\n // First, delete currently selected node if it's an empty paragraph and if there are sufficient\n // paragraph nodes (more than 1) left in the parent node, so that we don't \"trap\" the user\n if (\n $isParagraphNode(focusNode) &&\n focusNode.getTextContentSize() === 0 &&\n focusNode\n .getParentOrThrow()\n .getChildren()\n .filter((node) => $isParagraphNode(node)).length > 1\n ) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n INSERT_INLINE_BLOCK_COMMAND,\n (fields) => {\n if (targetNodeKey) {\n const node = $getNodeByKey(targetNodeKey)\n\n if (!node || !$isInlineBlockNode(node)) {\n return false\n }\n\n node.setFields(fields as BlockFields)\n\n setTargetNodeKey(null)\n return true\n }\n\n const inlineBlockNode = $createInlineBlockNode(fields as BlockFields)\n $insertNodes([inlineBlockNode])\n if ($isRootOrShadowRoot(inlineBlockNode.getParentOrThrow())) {\n $wrapNodeInElement(inlineBlockNode, $createParagraphNode).selectEnd()\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n ({ fields, nodeKey }) => {\n setBlockFields((fields as BlockFields) ?? null)\n setTargetNodeKey(nodeKey ?? null)\n setBlockType(fields?.blockType ?? ('' as any))\n\n if (nodeKey) {\n toggleDrawer()\n return true\n }\n\n let rangeSelection: null | RangeSelection = null\n\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n rangeSelection = selection\n }\n })\n\n if (rangeSelection) {\n //setLastSelection(rangeSelection)\n toggleDrawer()\n }\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [editor, targetNodeKey, toggleDrawer])\n\n if (!blockFields) {\n return null\n }\n\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.lexical_inline_blocks.${blockFields?.blockType}`\n\n const componentMapRenderedBlockPath = `lexical_internal_feature.blocks.fields.lexical_inline_blocks`\n const blocksField: BlocksFieldClient = richTextComponentMap?.has(componentMapRenderedBlockPath)\n ? richTextComponentMap.get(componentMapRenderedBlockPath)[0]\n : null\n\n const clientBlock = blocksField\n ? blocksField.blocks.find((block) => block.slug === blockFields?.blockType)\n : null\n\n if (!blocksField) {\n return null\n }\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels?.singular, i18n)\n : clientBlock?.slug\n\n return (\n <FieldsDrawer\n data={blockFields}\n drawerSlug={drawerSlug}\n drawerTitle={t(`lexical:blocks:inlineBlocks:${blockFields?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n featureKey=\"blocks\"\n fieldMapOverride={clientBlock?.fields}\n handleDrawerSubmit={(_fields, data) => {\n if (!data) {\n return\n }\n\n data.blockType = blockType\n\n editor.dispatchCommand(INSERT_INLINE_BLOCK_COMMAND, data)\n }}\n schemaFieldsPathOverride={schemaFieldsPath}\n schemaPathSuffix={blockFields?.blockType}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,wBAAwB,EAAEC,kBAAkB,EAAEC,aAAa,QAAQ;AAC5E,SAASC,cAAc,QAAQ;AAC/B,SACEC,gBAAgB,EAChBC,YAAY,EACZC,aAAa,EAEbC,cAAc,QACT;AACP,SACEC,oBAAoB,EACpBC,aAAa,EACbC,qBAAqB,EACrBC,aAAa,EACbC,YAAY,EACZC,gBAAgB,EAChBC,iBAAiB,EACjBC,mBAAmB,EACnBC,uBAAuB,QAElB;AACP,OAAOC,KAAA,IAASC,SAAS,EAAEC,QAAQ,QAAQ;AAM3C,SAASC,sBAAsB,QAAQ;AACvC,SAASC,YAAY,QAAQ;AAC7B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,EAAEC,SAAS,QAAQ;AAC5C,SAASC,sBAAsB,EAAEC,kBAAkB,QAAQ;AAC3D,SACEC,oBAAoB,EACpBC,2BAA2B,EAC3BC,gCAAgC,QAC3B;AAIP,OAAO,MAAMC,YAAA,GAA0DA,CAAA;EAAA,MAAAC,CAAA,GAAAjC,EAAA;EACrE,OAAAkC,MAAA,IAAiBjC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;;;;SAlBpB0C,E;CAqBJ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/experimental_table/client/plugins/TablePlugin/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,KAAK,EACL,cAAc,EACd,aAAa,EACb,WAAW,EAEZ,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAUhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAIjE,OAAO,cAAc,CAAA;AAErB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAA;IACzC,iBAAiB,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAAA;IAC1D,GAAG,EAAE,CACH,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,EACzC,iBAAiB,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,KACvD,IAAI,CAAA;CACV,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;IACzC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,KAAK,IAAI,CAAA;IACtD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,kBAAkB,CAAA;CAC3B,CAAC,CAAA;AAEF,eAAO,MAAM,yBAAyB,EAAE,cAAc,CAAC,EAAE,CAExD,CAAA;AAED,eAAO,MAAM,WAAW,iCAMtB,CAAA;AAEF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAA;CAAE,eAwBnE;AAED,eAAO,MAAM,WAAW,EAAE,eA6DzB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/experimental_table/client/plugins/TablePlugin/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,KAAK,EACL,cAAc,EACd,aAAa,EACb,WAAW,EAEZ,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAShC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAKjE,OAAO,cAAc,CAAA;AAErB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAA;IACzC,iBAAiB,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAAA;IAC1D,GAAG,EAAE,CACH,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,EACzC,iBAAiB,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,KACvD,IAAI,CAAA;CACV,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;IACzC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,KAAK,IAAI,CAAA;IACtD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,kBAAkB,CAAA;CAC3B,CAAC,CAAA;AAEF,eAAO,MAAM,yBAAyB,EAAE,cAAc,CAAC,EAAE,CAExD,CAAA;AAED,eAAO,MAAM,WAAW,iCAMtB,CAAA;AAEF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAA;CAAE,eAwBnE;AAED,eAAO,MAAM,WAAW,EAAE,eA6DzB,CAAA"}
@@ -8,11 +8,11 @@ import { INSERT_TABLE_COMMAND, TableNode } from '@lexical/table';
8
8
  import { mergeRegister } from '@lexical/utils';
9
9
  import { formatDrawerSlug, useEditDepth } from '@payloadcms/ui';
10
10
  import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
11
- import { useLexicalDrawer } from 'packages/richtext-lexical/src/utilities/fieldsDrawer/useLexicalDrawer.js';
12
11
  import { createContext, useContext, useEffect, useMemo, useState } from 'react';
13
12
  import * as React from 'react';
14
13
  import { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js';
15
14
  import { FieldsDrawer } from '../../../../../utilities/fieldsDrawer/Drawer.js';
15
+ import { useLexicalDrawer } from '../../../../../utilities/fieldsDrawer/useLexicalDrawer.js';
16
16
  export const OPEN_TABLE_DRAWER_COMMAND = createCommand('OPEN_EMBED_DRAWER_COMMAND');
17
17
  export const CellContext = /*#__PURE__*/createContext({
18
18
  cellEditorConfig: null,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","TablePlugin","LexicalReactTablePlugin","INSERT_TABLE_COMMAND","TableNode","mergeRegister","formatDrawerSlug","useEditDepth","$getSelection","$isRangeSelection","COMMAND_PRIORITY_EDITOR","createCommand","useLexicalDrawer","createContext","useContext","useEffect","useMemo","useState","React","useEditorConfigContext","FieldsDrawer","OPEN_TABLE_DRAWER_COMMAND","CellContext","cellEditorConfig","cellEditorPlugins","set","TableContext","children","contextValue","setContextValue","_jsx","Provider","value","$","editor","cellContext","editDepth","uuid","t0","t1","slug","depth","drawerSlug","toggleDrawer","t2","hasNodes","Error","registerCommand","rangeSelection","getEditorState","read","selection","t3","t4","_fields","data","columns","rows","dispatchCommand","String","t5","_jsxs","Fragment","drawerTitle","featureKey","handleDrawerSubmit","schemaPathSuffix","hasCellBackgroundColor","hasCellMerge"],"sources":["../../../../../../src/features/experimental_table/client/plugins/TablePlugin/index.tsx"],"sourcesContent":["'use client'\n\nimport type {\n EditorThemeClasses,\n Klass,\n LexicalCommand,\n LexicalEditor,\n LexicalNode,\n RangeSelection,\n} from 'lexical'\nimport type { JSX } from 'react'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { TablePlugin as LexicalReactTablePlugin } from '@lexical/react/LexicalTablePlugin'\nimport { INSERT_TABLE_COMMAND, TableNode } from '@lexical/table'\nimport { mergeRegister } from '@lexical/utils'\nimport { formatDrawerSlug, useEditDepth, useModal } from '@payloadcms/ui'\nimport { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical'\nimport { useLexicalDrawer } from 'packages/richtext-lexical/src/utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { createContext, useContext, useEffect, useMemo, useState } from 'react'\nimport * as React from 'react'\n\nimport type { PluginComponent } from '../../../../typesClient.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../../utilities/fieldsDrawer/Drawer.js'\nimport './index.scss'\n\nexport type CellContextShape = {\n cellEditorConfig: CellEditorConfig | null\n cellEditorPlugins: Array<JSX.Element> | JSX.Element | null\n set: (\n cellEditorConfig: CellEditorConfig | null,\n cellEditorPlugins: Array<JSX.Element> | JSX.Element | null,\n ) => void\n}\n\nexport type CellEditorConfig = Readonly<{\n namespace: string\n nodes?: ReadonlyArray<Klass<LexicalNode>>\n onError: (error: Error, editor: LexicalEditor) => void\n readOnly?: boolean\n theme?: EditorThemeClasses\n}>\n\nexport const OPEN_TABLE_DRAWER_COMMAND: LexicalCommand<{}> = createCommand(\n 'OPEN_EMBED_DRAWER_COMMAND',\n)\n\nexport const CellContext = createContext<CellContextShape>({\n cellEditorConfig: null,\n cellEditorPlugins: null,\n set: () => {\n // Empty\n },\n})\n\nexport function TableContext({ children }: { children: JSX.Element }) {\n const [contextValue, setContextValue] = useState<{\n cellEditorConfig: CellEditorConfig | null\n cellEditorPlugins: Array<JSX.Element> | JSX.Element | null\n }>({\n cellEditorConfig: null,\n cellEditorPlugins: null,\n })\n return (\n <CellContext.Provider\n value={useMemo(\n () => ({\n cellEditorConfig: contextValue.cellEditorConfig,\n cellEditorPlugins: contextValue.cellEditorPlugins,\n set: (cellEditorConfig, cellEditorPlugins) => {\n setContextValue({ cellEditorConfig, cellEditorPlugins })\n },\n }),\n [contextValue.cellEditorConfig, contextValue.cellEditorPlugins],\n )}\n >\n {children}\n </CellContext.Provider>\n )\n}\n\nexport const TablePlugin: PluginComponent = () => {\n const [editor] = useLexicalComposerContext()\n const cellContext = useContext(CellContext)\n const editDepth = useEditDepth()\n const { uuid } = useEditorConfigContext()\n\n const drawerSlug = formatDrawerSlug({\n slug: 'lexical-table-create-' + uuid,\n depth: editDepth,\n })\n const { toggleDrawer } = useLexicalDrawer(drawerSlug)\n\n useEffect(() => {\n if (!editor.hasNodes([TableNode])) {\n throw new Error('TablePlugin: TableNode is not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand(\n OPEN_TABLE_DRAWER_COMMAND,\n () => {\n let rangeSelection: null | RangeSelection = null\n\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n rangeSelection = selection\n }\n })\n\n if (rangeSelection) {\n toggleDrawer()\n }\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [cellContext, editor, toggleDrawer])\n\n return (\n <React.Fragment>\n <FieldsDrawer\n drawerSlug={drawerSlug}\n drawerTitle=\"Create Table\"\n featureKey=\"experimental_table\"\n handleDrawerSubmit={(_fields, data) => {\n if (!data.columns || !data.rows) {\n return\n }\n\n editor.dispatchCommand(INSERT_TABLE_COMMAND, {\n columns: String(data.columns),\n rows: String(data.rows),\n })\n }}\n schemaPathSuffix=\"fields\"\n />\n <LexicalReactTablePlugin hasCellBackgroundColor={false} hasCellMerge />\n </React.Fragment>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAYA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,WAAA,IAAeC,uBAAuB,QAAQ;AACvD,SAASC,oBAAoB,EAAEC,SAAS,QAAQ;AAChD,SAASC,aAAa,QAAQ;AAC9B,SAASC,gBAAgB,EAAEC,YAAY,QAAkB;AACzD,SAASC,aAAa,EAAEC,iBAAiB,EAAEC,uBAAuB,EAAEC,aAAa,QAAQ;AACzF,SAASC,gBAAgB,QAAQ;AACjC,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACxE,YAAYC,KAAA,MAAW;AAIvB,SAASC,sBAAsB,QAAQ;AACvC,SAASC,YAAY,QAAQ;AAoB7B,OAAO,MAAMC,yBAAA,GAAgDV,aAAA,CAC3D;AAGF,OAAO,MAAMW,WAAA,gBAAcT,aAAA,CAAgC;EACzDU,gBAAA,EAAkB;EAClBC,iBAAA,EAAmB;EACnBC,GAAA,EAAKA,CAAA;IACH;EAAA;AAEJ;AAEA,OAAO,SAASC,aAAa;EAAEC;AAAQ,CAA6B;EAClE,MAAM,CAACC,YAAA,EAAcC,eAAA,CAAgB,GAAGZ,QAAA,CAGrC;IACDM,gBAAA,EAAkB;IAClBC,iBAAA,EAAmB;EACrB;EACA,oBACEM,IAAA,CAACR,WAAA,CAAYS,QAAQ;IACnBC,KAAA,EAAOhB,OAAA,CACL,OAAO;MACLO,gBAAA,EAAkBK,YAAA,CAAaL,gBAAgB;MAC/CC,iBAAA,EAAmBI,YAAA,CAAaJ,iBAAiB;MACjDC,GAAA,EAAKA,CAACF,gBAAA,EAAkBC,iBAAA;QACtBK,eAAA,CAAgB;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SZ,EASpB;QAAAa,gBAAA,EACiB;MAAA,C,GAEnBpC,IAAA,CAAA5B,uBAAA;QAAAiE,sBAAA;QAAAC,YAAA;MAAA,C;;;;;;;;SAjBFR,E;CAoBJ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","TablePlugin","LexicalReactTablePlugin","INSERT_TABLE_COMMAND","TableNode","mergeRegister","formatDrawerSlug","useEditDepth","$getSelection","$isRangeSelection","COMMAND_PRIORITY_EDITOR","createCommand","createContext","useContext","useEffect","useMemo","useState","React","useEditorConfigContext","FieldsDrawer","useLexicalDrawer","OPEN_TABLE_DRAWER_COMMAND","CellContext","cellEditorConfig","cellEditorPlugins","set","TableContext","children","contextValue","setContextValue","_jsx","Provider","value","$","editor","cellContext","editDepth","uuid","t0","t1","slug","depth","drawerSlug","toggleDrawer","t2","hasNodes","Error","registerCommand","rangeSelection","getEditorState","read","selection","t3","t4","_fields","data","columns","rows","dispatchCommand","String","t5","_jsxs","Fragment","drawerTitle","featureKey","handleDrawerSubmit","schemaPathSuffix","hasCellBackgroundColor","hasCellMerge"],"sources":["../../../../../../src/features/experimental_table/client/plugins/TablePlugin/index.tsx"],"sourcesContent":["'use client'\n\nimport type {\n EditorThemeClasses,\n Klass,\n LexicalCommand,\n LexicalEditor,\n LexicalNode,\n RangeSelection,\n} from 'lexical'\nimport type { JSX } from 'react'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { TablePlugin as LexicalReactTablePlugin } from '@lexical/react/LexicalTablePlugin'\nimport { INSERT_TABLE_COMMAND, TableNode } from '@lexical/table'\nimport { mergeRegister } from '@lexical/utils'\nimport { formatDrawerSlug, useEditDepth, useModal } from '@payloadcms/ui'\nimport { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical'\nimport { createContext, useContext, useEffect, useMemo, useState } from 'react'\nimport * as React from 'react'\n\nimport type { PluginComponent } from '../../../../typesClient.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDrawer } from '../../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport './index.scss'\n\nexport type CellContextShape = {\n cellEditorConfig: CellEditorConfig | null\n cellEditorPlugins: Array<JSX.Element> | JSX.Element | null\n set: (\n cellEditorConfig: CellEditorConfig | null,\n cellEditorPlugins: Array<JSX.Element> | JSX.Element | null,\n ) => void\n}\n\nexport type CellEditorConfig = Readonly<{\n namespace: string\n nodes?: ReadonlyArray<Klass<LexicalNode>>\n onError: (error: Error, editor: LexicalEditor) => void\n readOnly?: boolean\n theme?: EditorThemeClasses\n}>\n\nexport const OPEN_TABLE_DRAWER_COMMAND: LexicalCommand<{}> = createCommand(\n 'OPEN_EMBED_DRAWER_COMMAND',\n)\n\nexport const CellContext = createContext<CellContextShape>({\n cellEditorConfig: null,\n cellEditorPlugins: null,\n set: () => {\n // Empty\n },\n})\n\nexport function TableContext({ children }: { children: JSX.Element }) {\n const [contextValue, setContextValue] = useState<{\n cellEditorConfig: CellEditorConfig | null\n cellEditorPlugins: Array<JSX.Element> | JSX.Element | null\n }>({\n cellEditorConfig: null,\n cellEditorPlugins: null,\n })\n return (\n <CellContext.Provider\n value={useMemo(\n () => ({\n cellEditorConfig: contextValue.cellEditorConfig,\n cellEditorPlugins: contextValue.cellEditorPlugins,\n set: (cellEditorConfig, cellEditorPlugins) => {\n setContextValue({ cellEditorConfig, cellEditorPlugins })\n },\n }),\n [contextValue.cellEditorConfig, contextValue.cellEditorPlugins],\n )}\n >\n {children}\n </CellContext.Provider>\n )\n}\n\nexport const TablePlugin: PluginComponent = () => {\n const [editor] = useLexicalComposerContext()\n const cellContext = useContext(CellContext)\n const editDepth = useEditDepth()\n const { uuid } = useEditorConfigContext()\n\n const drawerSlug = formatDrawerSlug({\n slug: 'lexical-table-create-' + uuid,\n depth: editDepth,\n })\n const { toggleDrawer } = useLexicalDrawer(drawerSlug)\n\n useEffect(() => {\n if (!editor.hasNodes([TableNode])) {\n throw new Error('TablePlugin: TableNode is not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand(\n OPEN_TABLE_DRAWER_COMMAND,\n () => {\n let rangeSelection: null | RangeSelection = null\n\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n rangeSelection = selection\n }\n })\n\n if (rangeSelection) {\n toggleDrawer()\n }\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [cellContext, editor, toggleDrawer])\n\n return (\n <React.Fragment>\n <FieldsDrawer\n drawerSlug={drawerSlug}\n drawerTitle=\"Create Table\"\n featureKey=\"experimental_table\"\n handleDrawerSubmit={(_fields, data) => {\n if (!data.columns || !data.rows) {\n return\n }\n\n editor.dispatchCommand(INSERT_TABLE_COMMAND, {\n columns: String(data.columns),\n rows: String(data.rows),\n })\n }}\n schemaPathSuffix=\"fields\"\n />\n <LexicalReactTablePlugin hasCellBackgroundColor={false} hasCellMerge />\n </React.Fragment>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAYA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,WAAA,IAAeC,uBAAuB,QAAQ;AACvD,SAASC,oBAAoB,EAAEC,SAAS,QAAQ;AAChD,SAASC,aAAa,QAAQ;AAC9B,SAASC,gBAAgB,EAAEC,YAAY,QAAkB;AACzD,SAASC,aAAa,EAAEC,iBAAiB,EAAEC,uBAAuB,EAAEC,aAAa,QAAQ;AACzF,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACxE,YAAYC,KAAA,MAAW;AAIvB,SAASC,sBAAsB,QAAQ;AACvC,SAASC,YAAY,QAAQ;AAC7B,SAASC,gBAAgB,QAAQ;AAoBjC,OAAO,MAAMC,yBAAA,GAAgDV,aAAA,CAC3D;AAGF,OAAO,MAAMW,W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MAAA;MAI/BvB,MAAA,CAAAwB,eAAA,CAAAvD,oBAAA;QAAAqD,OAAA,EACWG,MAAA,CAAOJ,IAAA,CAAAC,OAAY;QAAAC,IAAA,EACtBE,MAAA,CAAOJ,IAAA,CAAAE,IAAS;MAAA,CACxB;IAAA;IACFxB,CAAA,OAAAC,MAAA;IAAAD,CAAA,OAAAoB,EAAA;EAAA;IAAAA,EAAA,GAAApB,CAAA;EAAA;EAAA,IAAA2B,EAAA;EAAA,IAAA3B,CAAA,SAAAS,UAAA,IAAAT,CAAA,SAAAoB,EAAA;IAdJO,EAAA,GAAAC,KAAA,CAAA5C,KAAA,CAAA6C,QAAA;MAAAnC,QAAA,GACEG,IAAA,CAAAX,YAAA;QAAAuB,UAAA;QAAAqB,WAAA,EAEc;QAAAC,UAAA,EACD;QAAAC,kBAAA,EACSZ,EASpB;QAAAa,gBAAA,EACiB;MAAA,C,GAEnBpC,IAAA,CAAA5B,uBAAA;QAAAiE,sBAAA;QAAAC,YAAA;MAAA,C;;;;;;;;SAjBFR,E;CAoBJ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAS7C,MAAM,MAAM,iCAAiC,GACzC;IACE;;;QAGI;IACJ,mBAAmB,CAAC,EAAE,cAAc,EAAE,CAAA;IAGtC,kBAAkB,CAAC,EAAE,KAAK,CAAA;CAC3B,GACD;IAEE,mBAAmB,CAAC,EAAE,KAAK,CAAA;IAE3B;;;QAGI;IACJ,kBAAkB,CAAC,EAAE,cAAc,EAAE,CAAA;CACtC,CAAA;AAEL,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,iCAAiC,CAAA;AAErC,eAAO,MAAM,mBAAmB,qJAiE9B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAS7C,MAAM,MAAM,iCAAiC,GACzC;IACE;;;QAGI;IACJ,mBAAmB,CAAC,EAAE,cAAc,EAAE,CAAA;IAGtC,kBAAkB,CAAC,EAAE,KAAK,CAAA;CAC3B,GACD;IAEE,mBAAmB,CAAC,EAAE,KAAK,CAAA;IAE3B;;;QAGI;IACJ,kBAAkB,CAAC,EAAE,cAAc,EAAE,CAAA;CACtC,CAAA;AAEL,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,iCAAiC,CAAA;AAErC,eAAO,MAAM,mBAAmB,qJAkE9B,CAAA"}
@@ -51,6 +51,7 @@ export const RelationshipFeature = createServerFeature({
51
51
  key: 'value',
52
52
  overrideAccess,
53
53
  req,
54
+ select: collection.config.defaultPopulate,
54
55
  showHiddenFields
55
56
  }));
56
57
  return node;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["populate","createServerFeature","createNode","relationshipPopulationPromiseHOC","i18n","RelationshipServerNode","RelationshipFeature","feature","props","maxDepth","clientFeatureProps","ClientFeature","nodes","graphQLPopulationPromises","hooks","afterRead","currentDepth","depth","draft","node","overrideAccess","populationPromises","req","showHiddenFields","value","collection","payload","collections","relationTo","id","populateDepth","undefined","push","collectionSlug","config","slug","data","key"],"sources":["../../../../src/features/relationship/server/index.ts"],"sourcesContent":["import type { CollectionSlug } from 'payload'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { relationshipPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { RelationshipServerNode } from './nodes/RelationshipNode.js'\n\nexport type ExclusiveRelationshipFeatureProps =\n | {\n /**\n * The collections that should be disabled. Overrides the `enableRichTextRelationship` property in the collection config.\n * When this property is set, `enabledCollections` will not be available.\n **/\n disabledCollections?: CollectionSlug[]\n\n // Ensures that enabledCollections is not available when disabledCollections is set\n enabledCollections?: never\n }\n | {\n // Ensures that disabledCollections is not available when enabledCollections is set\n disabledCollections?: never\n\n /**\n * The collections that should be enabled. Overrides the `enableRichTextRelationship` property in the collection config\n * When this property is set, `disabledCollections` will not be available.\n **/\n enabledCollections?: CollectionSlug[]\n }\n\nexport type RelationshipFeatureProps = {\n /**\n * Sets a maximum population depth for this relationship, regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n} & ExclusiveRelationshipFeatureProps\n\nexport const RelationshipFeature = createServerFeature<\n RelationshipFeatureProps,\n RelationshipFeatureProps,\n ExclusiveRelationshipFeatureProps\n>({\n feature: ({ props }) => {\n // we don't need to pass maxDepth to the client, it's only used on the server\n const { maxDepth, ...clientFeatureProps } = props ?? {}\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#RelationshipFeatureClient',\n clientFeatureProps,\n i18n,\n nodes: [\n createNode({\n graphQLPopulationPromises: [relationshipPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth = maxDepth !== undefined && maxDepth < depth ? maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: RelationshipServerNode,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oB,IAAA,EAAMjB,IAAA;cACNF,KAAA,EAAOa,aAAA;cACPZ,KAAA;cACAmB,GAAA,EAAK;cACLjB,cAAA;cACAE,GAAA;cACAC;YACF;YAGF,OAAOJ,IAAA;UACT;QAEJ;QACAA,IAAA,EAAMd;MACR;IAEJ;EACF;EACAgC,GAAA,EAAK;AACP","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["populate","createServerFeature","createNode","relationshipPopulationPromiseHOC","i18n","RelationshipServerNode","RelationshipFeature","feature","props","maxDepth","clientFeatureProps","ClientFeature","nodes","graphQLPopulationPromises","hooks","afterRead","currentDepth","depth","draft","node","overrideAccess","populationPromises","req","showHiddenFields","value","collection","payload","collections","relationTo","id","populateDepth","undefined","push","collectionSlug","config","slug","data","key","select","defaultPopulate"],"sources":["../../../../src/features/relationship/server/index.ts"],"sourcesContent":["import type { CollectionSlug } from 'payload'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { relationshipPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { RelationshipServerNode } from './nodes/RelationshipNode.js'\n\nexport type ExclusiveRelationshipFeatureProps =\n | {\n /**\n * The collections that should be disabled. Overrides the `enableRichTextRelationship` property in the collection config.\n * When this property is set, `enabledCollections` will not be available.\n **/\n disabledCollections?: CollectionSlug[]\n\n // Ensures that enabledCollections is not available when disabledCollections is set\n enabledCollections?: never\n }\n | {\n // Ensures that disabledCollections is not available when enabledCollections is set\n disabledCollections?: never\n\n /**\n * The collections that should be enabled. Overrides the `enableRichTextRelationship` property in the collection config\n * When this property is set, `disabledCollections` will not be available.\n **/\n enabledCollections?: CollectionSlug[]\n }\n\nexport type RelationshipFeatureProps = {\n /**\n * Sets a maximum population depth for this relationship, regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n} & ExclusiveRelationshipFeatureProps\n\nexport const RelationshipFeature = createServerFeature<\n RelationshipFeatureProps,\n RelationshipFeatureProps,\n ExclusiveRelationshipFeatureProps\n>({\n feature: ({ props }) => {\n // we don't need to pass maxDepth to the client, it's only used on the server\n const { maxDepth, ...clientFeatureProps } = props ?? {}\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#RelationshipFeatureClient',\n clientFeatureProps,\n i18n,\n nodes: [\n createNode({\n graphQLPopulationPromises: [relationshipPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth = maxDepth !== undefined && maxDepth < depth ? maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n select: collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: RelationshipServerNode,\n }),\n ],\n }\n },\n key: 'relationship',\n})\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,gCAAgC,QAAQ;AACjD,SAASC,IAAI,QAAQ;AACrB,SAASC,sBAAsB,QAAQ;AAkCvC,OAAO,MAAMC,mBAAA,GAAsBL,mBAAA,CAIjC;EACAM,OAAA,EAASA,CAAC;IAAEC;EAAK,CAAE;IACjB;IACA,MAAM;MAAEC,QAAQ;MAAE,GAAGC;IAAA,CAAoB,GAAGF,KAAA,IAAS,CAAC;IACtD,OAAO;MACLG,aAAA,EAAe;MACfD,kBAAA;MACAN,IAAA;MACAQ,KAAA,EAAO,CACLV,UAAA,CAAW;QACTW,yBAAA,EAA2B,CAACV,gCAAA,CAAiCK,KAAA,EAAO;QACpEM,KAAA,EAAO;UACLC,SAAA,EAAW,CACT,CAAC;YACCC,YAAY;YACZC,KAAK;YACLC,KAAK;YACLC,IAAI;YACJC,cAAc;YACdC,kBAAkB;YAClBC,GAAG;YACHC;UAAgB,CACjB;YACC,IAAI,CAACJ,IAAA,EAAMK,KAAA,EAAO;cAChB,OAAOL,IAAA;YACT;YACA,MAAMM,UAAA,GAAaH,GAAA,CAAII,OAAO,CAACC,WAAW,CAACR,IAAA,EAAMS,UAAA,CAAW;YAE5D,IAAI,CAACH,UAAA,EAAY;cACf,OAAON,IAAA;YACT;YACA;YACA,MAAMU,EAAA,GAAKV,IAAA,EAAMK,KAAA,EAAOK,EAAA,IAAMV,IAAA,EAAMK,KAAA,CAAM;YAAA;YAE1C,MAAMM,aAAA,GAAgBrB,QAAA,KAAasB,SAAA,IAAatB,QAAA,GAAWQ,KAAA,GAAQR,QAAA,GAAWQ,KAAA;YAE9EI,kBAAA,CAAmBW,IAAI,CACrBhC,QAAA,CAAS;cACP6B,EAAA;cACAI,cAAA,EAAgBR,UAAA,CAAWS,MAAM,CAACC,IAAI;cACtCnB,YAAA;cACAoB,IAAA,EAAMjB,IAAA;cACNF,KAAA,EAAOa,aAAA;cACPZ,KAAA;cACAmB,GAAA,EAAK;cACLjB,cAAA;cACAE,GAAA;cACAgB,MAAA,EAAQb,UAAA,CAAWS,MAAM,CAACK,eAAe;cACzChB;YACF;YAGF,OAAOJ,IAAA;UACT;QAEJ;QACAA,IAAA,EAAMd;MACR;IAEJ;EACF;EACAgC,GAAA,EAAK;AACP","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useScrollInfo","useThrottledEffect","useTranslation","React","useMemo","useEditorConfigContext","ToolbarButton","ToolbarDropdown","ButtonGroupItem","anchorElem","editor","item","Component","_jsx","key","ChildComponent","ToolbarGroupComponent","t0","$","editorConfig","group","index","i18n","field","t1","richTextComponentMap","dropdownLabel","setDropdownLabel","useState","undefined","DropdownIcon","setDropdownIcon","t2","t3","type","items","length","useEffect","t4","t5","activeItems","label","substring","onActiveChange","t6","Icon","itemsContainerClassNames","maxActiveItems","t7","map","item_0","t8","features","toolbarFixed","_jsxs","className","children","groups","FixedToolbar","clientProps","parentWithFixedToolbar","currentToolbarRef","useRef","y","parentToolbarElem","disableIfParentHasFixedToolbar","parentEditorElem","editorContainerRef","current","sibling","previousElementSibling","classList","contains","currentToolbarElem","currentRect","getBoundingClientRect","parentRect","overlapping","bottom","top","onFocus","event","stopPropagation","ref","isEditable","Fragment","i","getParentEditorWithFixedToolbar","editorConfigContext","parentEditor","resolvedFeatureMap","has","FixedToolbarPlugin","currentEditor","currentEditorConfig","applyToFocusedEditor","focusedEditor"],"sources":["../../../../../../src/features/toolbars/fixed/client/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useScrollInfo, useThrottledEffect, useTranslation } from '@payloadcms/ui'\nimport * as React from 'react'\nimport { useMemo } from 'react'\n\nimport type { EditorConfigContextType } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport type { SanitizedClientEditorConfig } from '../../../../../lexical/config/types.js'\nimport type { PluginComponentWithAnchor } from '../../../../typesClient.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../../types.js'\nimport type { FixedToolbarFeatureProps } from '../../server/index.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { ToolbarButton } from '../../../shared/ToolbarButton/index.js'\nimport { ToolbarDropdown } from '../../../shared/ToolbarDropdown/index.js'\nimport './index.scss'\n\nfunction ButtonGroupItem({\n anchorElem,\n editor,\n item,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n item: ToolbarGroupItem\n}): React.ReactNode {\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n )\n }\n\n if (!item.ChildComponent) {\n return null\n }\n\n return (\n <ToolbarButton editor={editor} item={item} key={item.key}>\n {<item.ChildComponent />}\n </ToolbarButton>\n )\n}\n\nfunction ToolbarGroupComponent({\n anchorElem,\n editor,\n editorConfig,\n group,\n index,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n group: ToolbarGroup\n index: number\n}): React.ReactNode {\n const { i18n } = useTranslation()\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n const [dropdownLabel, setDropdownLabel] = React.useState<string | undefined>(undefined)\n const [DropdownIcon, setDropdownIcon] = React.useState<React.FC | undefined>(undefined)\n\n React.useEffect(() => {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent!)\n } else {\n setDropdownIcon(undefined)\n }\n }, [group])\n\n const onActiveChange = React.useCallback(\n ({ activeItems }: { activeItems: ToolbarGroupItem[] }) => {\n if (!activeItems.length) {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent!)\n setDropdownLabel(undefined)\n } else {\n setDropdownIcon(undefined)\n setDropdownLabel(undefined)\n }\n return\n }\n const item = activeItems[0]\n\n let label = item.key\n if (item.label) {\n label =\n typeof item.label === 'function' ? item.label({ i18n, richTextComponentMap }) : item.label\n }\n // Crop title to max. 25 characters\n if (label.length > 25) {\n label = label.substring(0, 25) + '...'\n }\n setDropdownLabel(label)\n setDropdownIcon(() => item.ChildComponent)\n },\n [group, i18n, richTextComponentMap],\n )\n\n return (\n <div className={`fixed-toolbar__group fixed-toolbar__group-${group.key}`} key={group.key}>\n {group.type === 'dropdown' &&\n group.items.length &&\n (DropdownIcon ? (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n Icon={DropdownIcon}\n itemsContainerClassNames={['fixed-toolbar__dropdown-items']}\n label={dropdownLabel}\n maxActiveItems={1}\n onActiveChange={onActiveChange}\n />\n ) : (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n itemsContainerClassNames={['fixed-toolbar__dropdown-items']}\n label={dropdownLabel}\n maxActiveItems={1}\n onActiveChange={onActiveChange}\n />\n ))}\n {group.type === 'buttons' &&\n group.items.length &&\n group.items.map((item) => {\n return (\n <ButtonGroupItem anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n })}\n {index < editorConfig.features.toolbarFixed?.groups.length - 1 && <div className=\"divider\" />}\n </div>\n )\n}\n\nfunction FixedToolbar({\n anchorElem,\n clientProps,\n editor,\n editorConfig,\n parentWithFixedToolbar,\n}: {\n anchorElem: HTMLElement\n clientProps?: FixedToolbarFeatureProps\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n parentWithFixedToolbar: EditorConfigContextType | false\n}): React.ReactNode {\n const currentToolbarRef = React.useRef<HTMLDivElement>(null)\n\n const { y } = useScrollInfo!()\n\n // Memoize the parent toolbar element\n const parentToolbarElem = useMemo(() => {\n if (!parentWithFixedToolbar || clientProps?.disableIfParentHasFixedToolbar) {\n return null\n }\n\n const parentEditorElem = parentWithFixedToolbar.editorContainerRef.current\n let sibling = parentEditorElem.previousElementSibling\n while (sibling) {\n if (sibling.classList.contains('fixed-toolbar')) {\n return sibling\n }\n sibling = sibling.previousElementSibling\n }\n return null\n }, [clientProps?.disableIfParentHasFixedToolbar, parentWithFixedToolbar])\n\n useThrottledEffect(\n () => {\n if (!parentToolbarElem) {\n // this also checks for clientProps?.disableIfParentHasFixedToolbar indirectly, see the parentToolbarElem useMemo\n return\n }\n const currentToolbarElem = currentToolbarRef.current\n if (!currentToolbarElem) {\n return\n }\n\n const currentRect = currentToolbarElem.getBoundingClientRect()\n const parentRect = parentToolbarElem.getBoundingClientRect()\n\n // we only need to check for vertical overlap\n const overlapping = !(\n currentRect.bottom < parentRect.top || currentRect.top > parentRect.bottom\n )\n\n if (overlapping) {\n currentToolbarElem.className = 'fixed-toolbar fixed-toolbar--overlapping'\n parentToolbarElem.className = 'fixed-toolbar fixed-toolbar--hide'\n } else {\n if (!currentToolbarElem.classList.contains('fixed-toolbar--overlapping')) {\n return\n }\n currentToolbarElem.className = 'fixed-toolbar'\n parentToolbarElem.className = 'fixed-toolbar'\n }\n },\n 50,\n [currentToolbarRef, parentToolbarElem, y],\n )\n\n return (\n <div\n className=\"fixed-toolbar\"\n onFocus={(event) => {\n // Prevent other focus events being triggered. Otherwise, if this was to be clicked while in a child editor,\n // the parent editor will be focused, and the child editor will lose focus.\n event.stopPropagation()\n }}\n ref={currentToolbarRef}\n >\n {editor.isEditable() && (\n <React.Fragment>\n {editorConfig?.features &&\n editorConfig.features?.toolbarFixed?.groups.map((group, i) => {\n return (\n <ToolbarGroupComponent\n anchorElem={anchorElem}\n editor={editor}\n editorConfig={editorConfig}\n group={group}\n index={i}\n key={group.key}\n />\n )\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n\nconst getParentEditorWithFixedToolbar = (\n editorConfigContext: EditorConfigContextType,\n): EditorConfigContextType | false => {\n if (editorConfigContext.parentEditor?.editorConfig) {\n if (editorConfigContext.parentEditor?.editorConfig.resolvedFeatureMap.has('toolbarFixed')) {\n return editorConfigContext.parentEditor\n } else {\n if (editorConfigContext.parentEditor) {\n return getParentEditorWithFixedToolbar(editorConfigContext.parentEditor)\n }\n }\n }\n return false\n}\n\nexport const FixedToolbarPlugin: PluginComponentWithAnchor<FixedToolbarFeatureProps> = ({\n anchorElem,\n clientProps,\n}) => {\n const [currentEditor] = useLexicalComposerContext()\n const editorConfigContext = useEditorConfigContext()\n\n const { editorConfig: currentEditorConfig } = editorConfigContext\n\n const editor = clientProps.applyToFocusedEditor\n ? editorConfigContext.focusedEditor?.editor || currentEditor\n : currentEditor\n\n const editorConfig = clientProps.applyToFocusedEditor\n ? editorConfigContext.focusedEditor?.editorConfig || currentEditorConfig\n : currentEditorConfig\n\n const parentWithFixedToolbar = getParentEditorWithFixedToolbar(editorConfigContext)\n\n if (clientProps?.disableIfParentHasFixedToolbar) {\n if (parentWithFixedToolbar) {\n return null\n }\n }\n\n if (!editorConfig?.features?.toolbarFixed?.groups?.length) {\n return null\n }\n\n return (\n <FixedToolbar\n anchorElem={anchorElem}\n editor={editor}\n editorConfig={editorConfig}\n parentWithFixedToolbar={parentWithFixedToolbar}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,EAAEC,kBAAkB,EAAEC,cAAc,QAAQ;AAClE,YAAYC,KAAA,MAAW;AACvB,SAASC,OAAO,QAAQ;AAQxB,SAASC,sBAAsB,QAAQ;AACvC,SAASC,aAAa,QAAQ;AAC9B,SAASC,eAAe,QAAQ;AAGhC,SAASC,gBAAgB;EACvBC,UAAU;EACVC,MAAM;EACNC;AAAI,CAKL;EACC,IAAIA,IAAA,CAAKC,SAAS,EAAE;IAClB,OACED,IAAA,EAAMC,SAAA,iBACJC,IAAA,CAACF,IAAA,CAAKC,SAAS;MAACH,UAAA,EAAYA,UAAA;MAAYC,MAAA,EAAQA,MAAA;MAAQC,IAAA,EAAMA;OAAWA,IAAA,CAAKG,GAAG;EAGvF;EAEA,IAAI,CAACH,IAAA,CAAKI,cAAc,EAAE;IACxB,OAAO;EACT;EAEA,oBACEF,IAAA,CAACP,aAAA;IAAcI,MAAA,EAAQA,MAAA;IAAQC,IAAA,EAAMA,IAAA;cAClC,aAAAE,IAAA,CAACF,IAAA,CAAKI,cAAc;KADyBJ,IAAA,CAAKG,GAAG;AAI5D;AAEA,SAAAE,sBAAAC,EAAA;EAAA,MAAAC,CAAA,GAAApB,EAAA;EAA+B;IAAAW,UAAA;IAAAC,MAAA;IAAAS,YAAA;IAAAC,KAAA;IAAAC;EAAA,IAAAJ,EAY9B;EACC;IAAAK;EAAA,IAAi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","useTranslation","React","useMemo","useEditorConfigContext","ToolbarButton","ToolbarDropdown","ButtonGroupItem","anchorElem","editor","item","Component","_jsx","key","ChildComponent","ToolbarGroupComponent","t0","$","editorConfig","group","index","i18n","field","t1","richTextComponentMap","dropdownLabel","setDropdownLabel","useState","undefined","DropdownIcon","setDropdownIcon","t2","t3","type","items","length","useEffect","t4","t5","activeItems","label","substring","onActiveChange","t6","Icon","itemsContainerClassNames","maxActiveItems","t7","map","item_0","t8","features","toolbarFixed","_jsxs","className","children","groups","FixedToolbar","clientProps","parentWithFixedToolbar","currentToolbarRef","useRef","y","parentToolbarElem","disableIfParentHasFixedToolbar","parentEditorElem","editorContainerRef","current","sibling","previousElementSibling","classList","contains","currentToolbarElem","currentRect","getBoundingClientRect","parentRect","overlapping","bottom","top","onFocus","event","stopPropagation","ref","isEditable","Fragment","i","getParentEditorWithFixedToolbar","editorConfigContext","parentEditor","resolvedFeatureMap","has","FixedToolbarPlugin","currentEditor","currentEditorConfig","applyToFocusedEditor","focusedEditor"],"sources":["../../../../../../src/features/toolbars/fixed/client/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useScrollInfo, useThrottledEffect, useTranslation } from '@payloadcms/ui'\nimport * as React from 'react'\nimport { useMemo } from 'react'\n\nimport type { EditorConfigContextType } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport type { SanitizedClientEditorConfig } from '../../../../../lexical/config/types.js'\nimport type { PluginComponentWithAnchor } from '../../../../typesClient.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../../types.js'\nimport type { FixedToolbarFeatureProps } from '../../server/index.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { ToolbarButton } from '../../../shared/ToolbarButton/index.js'\nimport { ToolbarDropdown } from '../../../shared/ToolbarDropdown/index.js'\nimport './index.scss'\n\nfunction ButtonGroupItem({\n anchorElem,\n editor,\n item,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n item: ToolbarGroupItem\n}): React.ReactNode {\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n )\n }\n\n if (!item.ChildComponent) {\n return null\n }\n\n return (\n <ToolbarButton editor={editor} item={item} key={item.key}>\n {<item.ChildComponent />}\n </ToolbarButton>\n )\n}\n\nfunction ToolbarGroupComponent({\n anchorElem,\n editor,\n editorConfig,\n group,\n index,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n group: ToolbarGroup\n index: number\n}): React.ReactNode {\n const { i18n } = useTranslation()\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n const [dropdownLabel, setDropdownLabel] = React.useState<string | undefined>(undefined)\n const [DropdownIcon, setDropdownIcon] = React.useState<React.FC | undefined>(undefined)\n\n React.useEffect(() => {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent!)\n } else {\n setDropdownIcon(undefined)\n }\n }, [group])\n\n const onActiveChange = React.useCallback(\n ({ activeItems }: { activeItems: ToolbarGroupItem[] }) => {\n if (!activeItems.length) {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent!)\n setDropdownLabel(undefined)\n } else {\n setDropdownIcon(undefined)\n setDropdownLabel(undefined)\n }\n return\n }\n const item = activeItems[0]\n\n let label = item.key\n if (item.label) {\n label =\n typeof item.label === 'function' ? item.label({ i18n, richTextComponentMap }) : item.label\n }\n // Crop title to max. 25 characters\n if (label.length > 25) {\n label = label.substring(0, 25) + '...'\n }\n setDropdownLabel(label)\n setDropdownIcon(() => item.ChildComponent)\n },\n [group, i18n, richTextComponentMap],\n )\n\n return (\n <div className={`fixed-toolbar__group fixed-toolbar__group-${group.key}`} key={group.key}>\n {group.type === 'dropdown' &&\n group.items.length &&\n (DropdownIcon ? (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n Icon={DropdownIcon}\n itemsContainerClassNames={['fixed-toolbar__dropdown-items']}\n label={dropdownLabel}\n maxActiveItems={1}\n onActiveChange={onActiveChange}\n />\n ) : (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n itemsContainerClassNames={['fixed-toolbar__dropdown-items']}\n label={dropdownLabel}\n maxActiveItems={1}\n onActiveChange={onActiveChange}\n />\n ))}\n {group.type === 'buttons' &&\n group.items.length &&\n group.items.map((item) => {\n return (\n <ButtonGroupItem anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n })}\n {index < editorConfig.features.toolbarFixed?.groups.length - 1 && <div className=\"divider\" />}\n </div>\n )\n}\n\nfunction FixedToolbar({\n anchorElem,\n clientProps,\n editor,\n editorConfig,\n parentWithFixedToolbar,\n}: {\n anchorElem: HTMLElement\n clientProps?: FixedToolbarFeatureProps\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n parentWithFixedToolbar: EditorConfigContextType | false\n}): React.ReactNode {\n const currentToolbarRef = React.useRef<HTMLDivElement>(null)\n\n const { y } = useScrollInfo()\n\n // Memoize the parent toolbar element\n const parentToolbarElem = useMemo(() => {\n if (!parentWithFixedToolbar || clientProps?.disableIfParentHasFixedToolbar) {\n return null\n }\n\n const parentEditorElem = parentWithFixedToolbar.editorContainerRef.current\n let sibling = parentEditorElem.previousElementSibling\n while (sibling) {\n if (sibling.classList.contains('fixed-toolbar')) {\n return sibling\n }\n sibling = sibling.previousElementSibling\n }\n return null\n }, [clientProps?.disableIfParentHasFixedToolbar, parentWithFixedToolbar])\n\n useThrottledEffect(\n () => {\n if (!parentToolbarElem) {\n // this also checks for clientProps?.disableIfParentHasFixedToolbar indirectly, see the parentToolbarElem useMemo\n return\n }\n const currentToolbarElem = currentToolbarRef.current\n if (!currentToolbarElem) {\n return\n }\n\n const currentRect = currentToolbarElem.getBoundingClientRect()\n const parentRect = parentToolbarElem.getBoundingClientRect()\n\n // we only need to check for vertical overlap\n const overlapping = !(\n currentRect.bottom < parentRect.top || currentRect.top > parentRect.bottom\n )\n\n if (overlapping) {\n currentToolbarElem.className = 'fixed-toolbar fixed-toolbar--overlapping'\n parentToolbarElem.className = 'fixed-toolbar fixed-toolbar--hide'\n } else {\n if (!currentToolbarElem.classList.contains('fixed-toolbar--overlapping')) {\n return\n }\n currentToolbarElem.className = 'fixed-toolbar'\n parentToolbarElem.className = 'fixed-toolbar'\n }\n },\n 50,\n [currentToolbarRef, parentToolbarElem, y],\n )\n\n return (\n <div\n className=\"fixed-toolbar\"\n onFocus={(event) => {\n // Prevent other focus events being triggered. Otherwise, if this was to be clicked while in a child editor,\n // the parent editor will be focused, and the child editor will lose focus.\n event.stopPropagation()\n }}\n ref={currentToolbarRef}\n >\n {editor.isEditable() && (\n <React.Fragment>\n {editorConfig?.features &&\n editorConfig.features?.toolbarFixed?.groups.map((group, i) => {\n return (\n <ToolbarGroupComponent\n anchorElem={anchorElem}\n editor={editor}\n editorConfig={editorConfig}\n group={group}\n index={i}\n key={group.key}\n />\n )\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n\nconst getParentEditorWithFixedToolbar = (\n editorConfigContext: EditorConfigContextType,\n): EditorConfigContextType | false => {\n if (editorConfigContext.parentEditor?.editorConfig) {\n if (editorConfigContext.parentEditor?.editorConfig.resolvedFeatureMap.has('toolbarFixed')) {\n return editorConfigContext.parentEditor\n } else {\n if (editorConfigContext.parentEditor) {\n return getParentEditorWithFixedToolbar(editorConfigContext.parentEditor)\n }\n }\n }\n return false\n}\n\nexport const FixedToolbarPlugin: PluginComponentWithAnchor<FixedToolbarFeatureProps> = ({\n anchorElem,\n clientProps,\n}) => {\n const [currentEditor] = useLexicalComposerContext()\n const editorConfigContext = useEditorConfigContext()\n\n const { editorConfig: currentEditorConfig } = editorConfigContext\n\n const editor = clientProps.applyToFocusedEditor\n ? editorConfigContext.focusedEditor?.editor || currentEditor\n : currentEditor\n\n const editorConfig = clientProps.applyToFocusedEditor\n ? editorConfigContext.focusedEditor?.editorConfig || currentEditorConfig\n : currentEditorConfig\n\n const parentWithFixedToolbar = getParentEditorWithFixedToolbar(editorConfigContext)\n\n if (clientProps?.disableIfParentHasFixedToolbar) {\n if (parentWithFixedToolbar) {\n return null\n }\n }\n\n if (!editorConfig?.features?.toolbarFixed?.groups?.length) {\n return null\n }\n\n return (\n <FixedToolbar\n anchorElem={anchorElem}\n editor={editor}\n editorConfig={editorConfig}\n parentWithFixedToolbar={parentWithFixedToolbar}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,EAAEC,kBAAkB,EAAEC,cAAc,QAAQ;AAClE,YAAYC,KAAA,MAAW;AACvB,SAASC,OAAO,QAAQ;AAQxB,SAASC,sBAAsB,QAAQ;AACvC,SAASC,aAAa,QAAQ;AAC9B,SAASC,eAAe,QAAQ;AAGhC,SAASC,gBAAgB;EACvBC,UAAU;EACVC,MAAM;EACNC;AAAI,CAKL;EACC,IAAIA,IAAA,CAAKC,SAAS,EAAE;IAClB,OACED,IAAA,EAAMC,SAAA,iBACJC,IAAA,CAACF,IAAA,CAAKC,SAAS;MAACH,UAAA,EAAYA,UAAA;MAAYC,MAAA,EAAQA,MAAA;MAAQC,IAAA,EAAMA;OAAWA,IAAA,CAAKG,GAAG;EAGvF;EAEA,IAAI,CAACH,IAAA,CAAKI,cAAc,EAAE;IACxB,OAAO;EACT;EAEA,oBACEF,IAAA,CAACP,aAAA;IAAcI,MAAA,EAAQA,MAAA;IAAQC,IAAA,EAAMA,IAAA;cAClC,aAAAE,IAAA,CAACF,IAAA,CAAKI,cAAc;KADyBJ,IAAA,CAAKG,GAAG;AAI5D;AAEA,SAAAE,sBAAAC,EAAA;EAAA,MAAAC,CAAA,GAAApB,EAAA;EAA+B;IAAAW,UAAA;IAAAC,MAAA;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B","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EAKN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAU3E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,cAAc,GAAG;YAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;SAChB,CAAA;KACF,CAAA;IACD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AASD,eAAO,MAAM,aAAa,gIA2OxB,CAAA"}
1
+ {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EAKN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAU3E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,cAAc,GAAG;YAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;SAChB,CAAA;KACF,CAAA;IACD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AASD,eAAO,MAAM,aAAa,gIA4OxB,CAAA"}
@@ -197,6 +197,7 @@ export const UploadFeature = createServerFeature({
197
197
  key: 'value',
198
198
  overrideAccess,
199
199
  req,
200
+ select: collection.config.defaultPopulate,
200
201
  showHiddenFields
201
202
  }));
202
203
  return node;
@@ -1 +1 @@
1
- {"version":3,"file":"feature.server.js","names":["sanitizeFields","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadServerNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","parentIsLocalized","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","currentDepth","depth","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","data","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","allSubFields","concat","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populationPromises","populateDepth","maxDepth","undefined","push","validations","sanitizedServerFeatureProps"],"sources":["../../../../src/features/upload/server/feature.server.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FileData,\n FileSize,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from '../client/feature.client.js'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { UploadServerNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: CollectionSlug]: {\n fields: Field[]\n }\n }\n /**\n * Sets a maximum population depth for this upload (not the fields for this upload), regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n}\n\n/**\n * Get the absolute URL for an upload URL by potentially prepending the serverURL\n */\nfunction getAbsoluteURL(url: string, payload: Payload): string {\n return url?.startsWith('http') ? url : (payload?.config?.serverURL || '') + url\n}\n\nexport const UploadFeature = createServerFeature<\n UploadFeatureProps,\n UploadFeatureProps,\n UploadFeaturePropsClient\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.collections) {\n for (const collection in props.collections) {\n clientProps.collections[collection] = {\n hasExtraFields: props.collections[collection].fields.length >= 1,\n }\n }\n }\n\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n props.collections[collection].fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: props.collections[collection].fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#UploadFeatureClient',\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) {\n return null\n }\n\n const schemaMap = new Map<string, Field[]>()\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n schemaMap.set(collection, props.collections[collection].fields)\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n req,\n showHiddenFields,\n }) => {\n // @ts-expect-error - for backwards-compatibility\n const id = node?.value?.id || node?.value\n\n if (req?.payload) {\n const uploadDocument: {\n value?: FileData & TypeWithID\n } = {}\n\n try {\n await populate({\n id,\n collectionSlug: node.relationTo,\n currentDepth,\n data: uploadDocument,\n depth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n })\n } catch (ignored) {\n // eslint-disable-next-line no-console\n console.error(\n 'Lexical upload node HTML converter: error fetching upload file',\n ignored,\n 'Node:',\n node,\n )\n return `<img />`\n }\n\n const url = getAbsoluteURL(uploadDocument?.value?.url ?? '', req?.payload)\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDocument?.value?.mimeType?.startsWith('image')) {\n return `<a href=\"${url}\" rel=\"noopener noreferrer\">${uploadDocument.value?.filename}</a>`\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (\n !uploadDocument?.value?.sizes ||\n !Object.keys(uploadDocument?.value?.sizes).length\n ) {\n return `<img src=\"${url}\" alt=\"${uploadDocument?.value?.filename}\" width=\"${uploadDocument?.value?.width}\" height=\"${uploadDocument?.value?.height}\"/>`\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n let pictureHTML = '<picture>'\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDocument.value?.sizes) {\n const imageSize: {\n url?: string\n } & FileSize = uploadDocument.value?.sizes[size]\n\n // Skip if any property of the size object is null\n if (\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = getAbsoluteURL(imageSize?.url, req?.payload)\n\n pictureHTML += `<source srcset=\"${imageSizeURL}\" media=\"(max-width: ${imageSize.width}px)\" type=\"${imageSize.mimeType}\">`\n }\n\n // Add the default img tag\n pictureHTML += `<img src=\"${url}\" alt=\"Image\" width=\"${uploadDocument.value?.width}\" height=\"${uploadDocument.value?.height}\">`\n pictureHTML += '</picture>'\n return pictureHTML\n } else {\n return `<img src=\"${id}\" />`\n }\n },\n nodeTypes: [UploadServerNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n if (!node) {\n let allSubFields: Field[] = []\n for (const collection in props?.collections) {\n allSubFields = allSubFields.concat(props?.collections?.[collection]?.fields)\n }\n return allSubFields\n }\n const collection = req ? req.payload.collections[node?.relationTo] : null\n\n if (collection) {\n const collectionFieldSchema = props?.collections?.[node?.relationTo]?.fields\n\n if (Array.isArray(collectionFieldSchema)) {\n if (!collectionFieldSchema?.length) {\n return null\n }\n return collectionFieldSchema\n }\n }\n return null\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [uploadPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth =\n props?.maxDepth !== undefined && props?.maxDepth < depth ? props?.maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadServerNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"mappings":"AAUA,SAASA,cAAc,QAAQ;AAI/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,IAAI,QAAQ;AACrB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,QAAQ;AAiBjC;;;AAGA,SAASC,eAAeC,GAAW,EAAEC,OAAgB;EACnD,OAAOD,GAAA,EAAKE,UAAA,CAAW,UAAUF,GAAA,GAAM,CAACC,OAAA,EAASE,MAAA,EAAQC,SAAA,IAAa,EAAC,IAAKJ,GAAA;AAC9E;AAEA,OAAO,MAAMK,aAAA,GAAgBZ,mBAAA,CAI3B;EACAa,OAAA,EAAS,MAAAA,CAAO;IAAEH,MAAA,EAAQI,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAAK,CAAE;IACnE,IAAI,CAACA,KAAA,EAAO;MACVA,KAAA,GAAQ;QAAEC,WAAA,EAAa,CAAC;MAAE;IAC5B;IAEA,MAAMC,WAAA,GAAwC;MAC5CD,WAAA,EAAa,CAAC;IAChB;IACA,IAAID,K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OiE,QAAA,GAAW1C,KAAA;YAE/EwC,kBAAA,CAAmBI,IAAI,CACrBrF,QAAA,CAAS;cACP+C,EAAA;cACAG,cAAA,EAAgB7B,UAAA,CAAWV,MAAM,CAACiB,IAAI;cACtCY,YAAA;cACAY,IAAA,EAAMT,IAAA;cACNF,KAAA,EAAOyC,aAAA;cACPxC,KAAA;cACAW,GAAA,EAAK;cACLT,cAAA;cACAC,GAAA;cACAC;YACF;YAGF,OAAOH,IAAA;UACT;QAEJ;QACAA,IAAA,EAAMtC,gBAAA;QACNiF,WAAA,EAAa,CAAChF,gBAAA,CAAiBY,KAAA;MACjC,GACD;MACDqE,2BAAA,EAA6BrE;IAC/B;EACF;EACAmC,GAAA,EAAK;AACP","ignoreList":[]}
1
+ {"version":3,"file":"feature.server.js","names":["sanitizeFields","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadServerNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","parentIsLocalized","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","currentDepth","depth","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","data","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","allSubFields","concat","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populationPromises","populateDepth","maxDepth","undefined","push","select","defaultPopulate","validations","sanitizedServerFeatureProps"],"sources":["../../../../src/features/upload/server/feature.server.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FileData,\n FileSize,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from '../client/feature.client.js'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { UploadServerNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: CollectionSlug]: {\n fields: Field[]\n }\n }\n /**\n * Sets a maximum population depth for this upload (not the fields for this upload), regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n}\n\n/**\n * Get the absolute URL for an upload URL by potentially prepending the serverURL\n */\nfunction getAbsoluteURL(url: string, payload: Payload): string {\n return url?.startsWith('http') ? url : (payload?.config?.serverURL || '') + url\n}\n\nexport const UploadFeature = createServerFeature<\n UploadFeatureProps,\n UploadFeatureProps,\n UploadFeaturePropsClient\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.collections) {\n for (const collection in props.collections) {\n clientProps.collections[collection] = {\n hasExtraFields: props.collections[collection].fields.length >= 1,\n }\n }\n }\n\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n props.collections[collection].fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: props.collections[collection].fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#UploadFeatureClient',\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) {\n return null\n }\n\n const schemaMap = new Map<string, Field[]>()\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n schemaMap.set(collection, props.collections[collection].fields)\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n req,\n showHiddenFields,\n }) => {\n // @ts-expect-error - for backwards-compatibility\n const id = node?.value?.id || node?.value\n\n if (req?.payload) {\n const uploadDocument: {\n value?: FileData & TypeWithID\n } = {}\n\n try {\n await populate({\n id,\n collectionSlug: node.relationTo,\n currentDepth,\n data: uploadDocument,\n depth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n })\n } catch (ignored) {\n // eslint-disable-next-line no-console\n console.error(\n 'Lexical upload node HTML converter: error fetching upload file',\n ignored,\n 'Node:',\n node,\n )\n return `<img />`\n }\n\n const url = getAbsoluteURL(uploadDocument?.value?.url ?? '', req?.payload)\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDocument?.value?.mimeType?.startsWith('image')) {\n return `<a href=\"${url}\" rel=\"noopener noreferrer\">${uploadDocument.value?.filename}</a>`\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (\n !uploadDocument?.value?.sizes ||\n !Object.keys(uploadDocument?.value?.sizes).length\n ) {\n return `<img src=\"${url}\" alt=\"${uploadDocument?.value?.filename}\" width=\"${uploadDocument?.value?.width}\" height=\"${uploadDocument?.value?.height}\"/>`\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n let pictureHTML = '<picture>'\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDocument.value?.sizes) {\n const imageSize: {\n url?: string\n } & FileSize = uploadDocument.value?.sizes[size]\n\n // Skip if any property of the size object is null\n if (\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = getAbsoluteURL(imageSize?.url, req?.payload)\n\n pictureHTML += `<source srcset=\"${imageSizeURL}\" media=\"(max-width: ${imageSize.width}px)\" type=\"${imageSize.mimeType}\">`\n }\n\n // Add the default img tag\n pictureHTML += `<img src=\"${url}\" alt=\"Image\" width=\"${uploadDocument.value?.width}\" height=\"${uploadDocument.value?.height}\">`\n pictureHTML += '</picture>'\n return pictureHTML\n } else {\n return `<img src=\"${id}\" />`\n }\n },\n nodeTypes: [UploadServerNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n if (!node) {\n let allSubFields: Field[] = []\n for (const collection in props?.collections) {\n allSubFields = allSubFields.concat(props?.collections?.[collection]?.fields)\n }\n return allSubFields\n }\n const collection = req ? req.payload.collections[node?.relationTo] : null\n\n if (collection) {\n const collectionFieldSchema = props?.collections?.[node?.relationTo]?.fields\n\n if (Array.isArray(collectionFieldSchema)) {\n if (!collectionFieldSchema?.length) {\n return null\n }\n return collectionFieldSchema\n }\n }\n return null\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [uploadPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth =\n props?.maxDepth !== undefined && props?.maxDepth < depth ? props?.maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n select: collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadServerNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"mappings":"AAUA,SAASA,cAAc,QAAQ;AAI/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,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