@payloadcms/richtext-lexical 3.68.0-internal-debug.35482da → 3.68.0-internal-debug.e9b66ee
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/rscEntry.js +2 -21
- package/dist/cell/rscEntry.js.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +13 -48
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockCollapsible.js +1 -10
- package/dist/features/blocks/client/component/components/BlockCollapsible.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockEditButton.js +1 -7
- package/dist/features/blocks/client/component/components/BlockEditButton.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockRemoveButton.js +1 -7
- package/dist/features/blocks/client/component/components/BlockRemoveButton.js.map +1 -1
- package/dist/features/blocks/client/component/index.js +81 -247
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js +1 -9
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js +1 -7
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js +1 -7
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js +1 -7
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +68 -217
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/getBlockImageComponent.js +4 -15
- package/dist/features/blocks/client/getBlockImageComponent.js.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.js +1 -12
- package/dist/features/blocks/client/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js +2 -12
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js +26 -127
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js +49 -65
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.js +3 -16
- package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.js +4 -25
- package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.js.map +1 -1
- package/dist/features/blocks/server/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/server/nodes/InlineBlocksNode.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.js +2 -13
- package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/blockquote.js +1 -8
- package/dist/features/converters/lexicalToJSX/converter/converters/blockquote.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/heading.js +1 -8
- package/dist/features/converters/lexicalToJSX/converter/converters/heading.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/horizontalRule.js +1 -6
- package/dist/features/converters/lexicalToJSX/converter/converters/horizontalRule.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/linebreak.js +1 -6
- package/dist/features/converters/lexicalToJSX/converter/converters/linebreak.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/link.js +10 -19
- package/dist/features/converters/lexicalToJSX/converter/converters/link.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/list.js +16 -63
- package/dist/features/converters/lexicalToJSX/converter/converters/list.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/paragraph.js +4 -19
- package/dist/features/converters/lexicalToJSX/converter/converters/paragraph.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/table.js +12 -45
- package/dist/features/converters/lexicalToJSX/converter/converters/table.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/text.js +11 -57
- package/dist/features/converters/lexicalToJSX/converter/converters/text.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/upload.js +7 -46
- package/dist/features/converters/lexicalToJSX/converter/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.js +5 -12
- package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js +3 -16
- package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
- package/dist/features/debug/testRecorder/client/plugin/index.js +38 -113
- package/dist/features/debug/testRecorder/client/plugin/index.js.map +1 -1
- package/dist/features/debug/treeView/client/plugin/index.js +1 -15
- package/dist/features/debug/treeView/client/plugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js +79 -357
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +7 -41
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +9 -39
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js +28 -59
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +1 -1
- package/dist/features/horizontalRule/client/nodes/HorizontalRuleNode.js +0 -1
- package/dist/features/horizontalRule/client/nodes/HorizontalRuleNode.js.map +1 -1
- package/dist/features/indent/client/IndentPlugin.js +1 -6
- package/dist/features/indent/client/IndentPlugin.js.map +1 -1
- package/dist/features/link/client/plugins/clickableLink/index.js +1 -7
- package/dist/features/link/client/plugins/clickableLink/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +59 -151
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/index.js +1 -9
- package/dist/features/link/client/plugins/floatingLinkEditor/index.js.map +1 -1
- package/dist/features/link/nodes/LinkNode.js.map +1 -1
- package/dist/features/lists/checklist/client/plugin/index.js +1 -7
- package/dist/features/lists/checklist/client/plugin/index.js.map +1 -1
- package/dist/features/lists/plugin/index.js +1 -7
- package/dist/features/lists/plugin/index.js.map +1 -1
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/Component.js +3 -18
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/Component.js.map +1 -1
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js +2 -9
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/Component.js +3 -18
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/Component.js.map +1 -1
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js +2 -9
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.js +31 -100
- package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
- package/dist/features/relationship/client/drawer/index.js +4 -21
- package/dist/features/relationship/client/drawer/index.js.map +1 -1
- package/dist/features/relationship/client/nodes/RelationshipNode.js +2 -12
- package/dist/features/relationship/client/nodes/RelationshipNode.js.map +1 -1
- package/dist/features/relationship/client/plugins/index.js +1 -8
- package/dist/features/relationship/client/plugins/index.js.map +1 -1
- package/dist/features/relationship/server/nodes/RelationshipNode.js.map +1 -1
- package/dist/features/textState/feature.client.js +5 -22
- package/dist/features/textState/feature.client.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.js +27 -123
- package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js +18 -111
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.js +4 -14
- package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +56 -135
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js +16 -70
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/features/upload/client/component/index.js +43 -167
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/features/upload/client/component/pending/index.js +3 -16
- package/dist/features/upload/client/component/pending/index.js.map +1 -1
- package/dist/features/upload/client/drawer/index.js +4 -21
- package/dist/features/upload/client/drawer/index.js.map +1 -1
- package/dist/features/upload/client/nodes/UploadNode.js +3 -17
- package/dist/features/upload/client/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/client/plugin/index.js +2 -9
- package/dist/features/upload/client/plugin/index.js.map +1 -1
- package/dist/features/upload/server/nodes/UploadNode.js.map +1 -1
- package/dist/field/Diff/converters/listitem/index.js +11 -54
- package/dist/field/Diff/converters/listitem/index.js.map +1 -1
- package/dist/field/Diff/converters/relationship/index.js +18 -60
- package/dist/field/Diff/converters/relationship/index.js.map +1 -1
- package/dist/field/Diff/converters/unknown/index.js +7 -42
- package/dist/field/Diff/converters/unknown/index.js.map +1 -1
- package/dist/field/Diff/converters/upload/index.js +21 -91
- package/dist/field/Diff/converters/upload/index.js.map +1 -1
- package/dist/field/Diff/index.js +4 -17
- package/dist/field/Diff/index.js.map +1 -1
- package/dist/field/Field.js +25 -124
- package/dist/field/Field.js.map +1 -1
- package/dist/field/RenderLexical/index.js +15 -47
- package/dist/field/RenderLexical/index.js.map +1 -1
- package/dist/field/index.js +5 -24
- package/dist/field/index.js.map +1 -1
- package/dist/field/rscEntry.js +1 -9
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/lexical/EditorPlugin.js +2 -17
- package/dist/lexical/EditorPlugin.js.map +1 -1
- package/dist/lexical/LexicalEditor.js +69 -232
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalProvider.js +13 -64
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.js +2 -11
- package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js +5 -28
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +1 -14
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.js +31 -98
- package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js +7 -27
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +7 -45
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.js +3 -18
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/lexical/ui/icons/AI/index.js +10 -58
- package/dist/lexical/ui/icons/AI/index.js.map +1 -1
- package/dist/lexical/ui/icons/Add/index.js +4 -31
- package/dist/lexical/ui/icons/Add/index.js.map +1 -1
- package/dist/lexical/ui/icons/AlignCenter/index.js +5 -45
- package/dist/lexical/ui/icons/AlignCenter/index.js.map +1 -1
- package/dist/lexical/ui/icons/AlignJustify/index.js +5 -45
- package/dist/lexical/ui/icons/AlignJustify/index.js.map +1 -1
- package/dist/lexical/ui/icons/AlignLeft/index.js +5 -45
- package/dist/lexical/ui/icons/AlignLeft/index.js.map +1 -1
- package/dist/lexical/ui/icons/AlignRight/index.js +5 -45
- package/dist/lexical/ui/icons/AlignRight/index.js.map +1 -1
- package/dist/lexical/ui/icons/Block/index.js +5 -54
- package/dist/lexical/ui/icons/Block/index.js.map +1 -1
- package/dist/lexical/ui/icons/Blockquote/index.js +3 -24
- package/dist/lexical/ui/icons/Blockquote/index.js.map +1 -1
- package/dist/lexical/ui/icons/Bold/index.js +3 -24
- package/dist/lexical/ui/icons/Bold/index.js.map +1 -1
- package/dist/lexical/ui/icons/Checklist/index.js +4 -39
- package/dist/lexical/ui/icons/Checklist/index.js.map +1 -1
- package/dist/lexical/ui/icons/Code/index.js +4 -34
- package/dist/lexical/ui/icons/Code/index.js.map +1 -1
- package/dist/lexical/ui/icons/CodeBlock/index.js +3 -22
- package/dist/lexical/ui/icons/CodeBlock/index.js.map +1 -1
- package/dist/lexical/ui/icons/Collapse/index.js +3 -23
- package/dist/lexical/ui/icons/Collapse/index.js.map +1 -1
- package/dist/lexical/ui/icons/H1/index.js +3 -24
- package/dist/lexical/ui/icons/H1/index.js.map +1 -1
- package/dist/lexical/ui/icons/H2/index.js +3 -24
- package/dist/lexical/ui/icons/H2/index.js.map +1 -1
- package/dist/lexical/ui/icons/H3/index.js +3 -24
- package/dist/lexical/ui/icons/H3/index.js.map +1 -1
- package/dist/lexical/ui/icons/H4/index.js +3 -24
- package/dist/lexical/ui/icons/H4/index.js.map +1 -1
- package/dist/lexical/ui/icons/H5/index.js +3 -24
- package/dist/lexical/ui/icons/H5/index.js.map +1 -1
- package/dist/lexical/ui/icons/H6/index.js +3 -24
- package/dist/lexical/ui/icons/H6/index.js.map +1 -1
- package/dist/lexical/ui/icons/HorizontalRule/index.js +3 -27
- package/dist/lexical/ui/icons/HorizontalRule/index.js.map +1 -1
- package/dist/lexical/ui/icons/IndentDecrease/index.js +6 -53
- package/dist/lexical/ui/icons/IndentDecrease/index.js.map +1 -1
- package/dist/lexical/ui/icons/IndentIncrease/index.js +6 -53
- package/dist/lexical/ui/icons/IndentIncrease/index.js.map +1 -1
- package/dist/lexical/ui/icons/InlineBlocks/index.js +3 -26
- package/dist/lexical/ui/icons/InlineBlocks/index.js.map +1 -1
- package/dist/lexical/ui/icons/Italic/index.js +3 -24
- package/dist/lexical/ui/icons/Italic/index.js.map +1 -1
- package/dist/lexical/ui/icons/Link/index.js +3 -25
- package/dist/lexical/ui/icons/Link/index.js.map +1 -1
- package/dist/lexical/ui/icons/Meatballs/index.js +5 -39
- package/dist/lexical/ui/icons/Meatballs/index.js.map +1 -1
- package/dist/lexical/ui/icons/OrderedList/index.js +7 -61
- package/dist/lexical/ui/icons/OrderedList/index.js.map +1 -1
- package/dist/lexical/ui/icons/Relationship/index.js +10 -58
- package/dist/lexical/ui/icons/Relationship/index.js.map +1 -1
- package/dist/lexical/ui/icons/Strikethrough/index.js +4 -34
- package/dist/lexical/ui/icons/Strikethrough/index.js.map +1 -1
- package/dist/lexical/ui/icons/Subscript/index.js +3 -24
- package/dist/lexical/ui/icons/Subscript/index.js.map +1 -1
- package/dist/lexical/ui/icons/Superscript/index.js +3 -24
- package/dist/lexical/ui/icons/Superscript/index.js.map +1 -1
- package/dist/lexical/ui/icons/Table/index.js +3 -24
- package/dist/lexical/ui/icons/Table/index.js.map +1 -1
- package/dist/lexical/ui/icons/Text/index.js +3 -24
- package/dist/lexical/ui/icons/Text/index.js.map +1 -1
- package/dist/lexical/ui/icons/TextState/index.js +12 -18
- package/dist/lexical/ui/icons/TextState/index.js.map +1 -1
- package/dist/lexical/ui/icons/Underline/index.js +4 -34
- package/dist/lexical/ui/icons/Underline/index.js.map +1 -1
- package/dist/lexical/ui/icons/UnorderedList/index.js +8 -81
- package/dist/lexical/ui/icons/UnorderedList/index.js.map +1 -1
- package/dist/lexical/ui/icons/Upload/index.js +5 -48
- package/dist/lexical/ui/icons/Upload/index.js.map +1 -1
- package/dist/lexical/utils/point.js.map +1 -1
- package/dist/lexical/utils/rect.js.map +1 -1
- package/dist/utilities/fieldsDrawer/Drawer.js +16 -41
- package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +10 -42
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js +1 -9
- package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js +3 -11
- package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/features/upload/client/plugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $dfsIterator, $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils'\nimport { useBulkUpload, useEffectEvent, useModal } from '@payloadcms/ui'\nimport ObjectID from 'bson-objectid'\nimport {\n $createRangeSelection,\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n $setSelection,\n COMMAND_PRIORITY_EDITOR,\n COMMAND_PRIORITY_LOW,\n createCommand,\n DROP_COMMAND,\n getDOMSelectionFromTarget,\n isHTMLElement,\n PASTE_COMMAND,\n} from 'lexical'\nimport React, { useEffect } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { Internal_UploadData, UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\n\nimport { useEnabledRelationships } from '../../../relationship/client/utils/useEnabledRelationships.js'\nimport { UploadDrawer } from '../drawer/index.js'\nimport { $createUploadNode, $isUploadNode, UploadNode } from '../nodes/UploadNode.js'\n\nexport type InsertUploadPayload = Readonly<Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>>\n\ndeclare global {\n interface DragEvent {\n rangeOffset?: number\n rangeParent?: Node\n }\n}\n\nfunction canDropImage(event: DragEvent): boolean {\n const target = event.target\n return !!(\n isHTMLElement(target) &&\n !target.closest('code, span.editor-image') &&\n isHTMLElement(target.parentElement) &&\n target.parentElement.closest('div.ContentEditable__root')\n )\n}\n\nfunction getDragSelection(event: DragEvent): null | Range | undefined {\n // Source: https://github.com/AlessioGr/lexical/blob/main/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx\n let range\n const domSelection = getDOMSelectionFromTarget(event.target)\n if (document.caretRangeFromPoint) {\n range = document.caretRangeFromPoint(event.clientX, event.clientY)\n } else if (event.rangeParent && domSelection !== null) {\n domSelection.collapse(event.rangeParent, event.rangeOffset || 0)\n range = domSelection.getRangeAt(0)\n } else {\n throw Error(`Cannot get the selection when dragging`)\n }\n\n return range\n}\n\nexport const INSERT_UPLOAD_COMMAND: LexicalCommand<InsertUploadPayload> =\n createCommand('INSERT_UPLOAD_COMMAND')\n\ntype FileToUpload = {\n alt?: string\n file: File\n /**\n * Bulk Upload Form ID that should be created, which can then be matched\n * against the node formID if the upload is successful\n */\n formID: string\n}\n\nexport const UploadPlugin: PluginComponent<UploadFeaturePropsClient> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n\n const { enabledCollectionSlugs } = useEnabledRelationships({\n collectionSlugsBlacklist: clientProps?.disabledCollections,\n collectionSlugsWhitelist: clientProps?.enabledCollections,\n uploads: true,\n })\n\n const {\n drawerSlug: bulkUploadDrawerSlug,\n setCollectionSlug,\n setInitialForms,\n setOnCancel,\n setOnSuccess,\n setSelectableCollections,\n } = useBulkUpload()\n\n const { isModalOpen, openModal } = useModal()\n\n const openBulkUpload = useEffectEvent(({ files }: { files: FileToUpload[] }) => {\n if (files?.length === 0) {\n return\n }\n\n setInitialForms((initialForms) => [\n ...(initialForms ?? []),\n ...files.map((file) => ({\n file: file.file,\n formID: file.formID,\n })),\n ])\n\n if (!isModalOpen(bulkUploadDrawerSlug)) {\n if (!enabledCollectionSlugs.length || !enabledCollectionSlugs[0]) {\n return\n }\n\n setCollectionSlug(enabledCollectionSlugs[0])\n setSelectableCollections(enabledCollectionSlugs)\n\n setOnCancel(() => {\n // Remove all the pending upload nodes that were added but not uploaded\n editor.update(() => {\n for (const dfsNode of $dfsIterator()) {\n const node = dfsNode.node\n\n if ($isUploadNode(node)) {\n const nodeData = node.getData()\n if ((nodeData as Internal_UploadData)?.pending) {\n node.remove()\n }\n }\n }\n })\n })\n\n setOnSuccess((newDocs) => {\n const newDocsMap = new Map(newDocs.map((doc) => [doc.formID, doc]))\n editor.update(() => {\n for (const dfsNode of $dfsIterator()) {\n const node = dfsNode.node\n if ($isUploadNode(node)) {\n const nodeData: Internal_UploadData = node.getData()\n\n if (nodeData?.pending) {\n const newDoc = newDocsMap.get(nodeData.pending?.formID)\n if (newDoc) {\n node.replace(\n $createUploadNode({\n data: {\n id: new ObjectID.default().toHexString(),\n fields: {},\n relationTo: newDoc.collectionSlug,\n value: newDoc.doc.id,\n } as UploadData,\n }),\n )\n }\n }\n }\n }\n })\n })\n\n openModal(bulkUploadDrawerSlug)\n }\n })\n\n useEffect(() => {\n if (!editor.hasNodes([UploadNode])) {\n throw new Error('UploadPlugin: UploadNode not registered on editor')\n }\n\n return mergeRegister(\n /**\n * Handle auto-uploading files if you copy & paste an image dom element from the clipboard\n */\n editor.registerNodeTransform(UploadNode, (node) => {\n const nodeData: Internal_UploadData = node.getData()\n if (!nodeData?.pending) {\n return\n }\n\n async function upload() {\n let transformedImage: FileToUpload | null = null\n\n const src = nodeData?.pending?.src\n const formID = nodeData?.pending?.formID as string\n\n if (src?.startsWith('data:')) {\n // It's a base64-encoded image\n const mimeMatch = src.match(/data:(image\\/[a-zA-Z]+);base64,/)\n const mimeType = mimeMatch ? mimeMatch[1] : 'image/png' // Default to PNG if MIME type not found\n const base64Data = src.replace(/^data:image\\/[a-zA-Z]+;base64,/, '')\n const byteCharacters = atob(base64Data)\n const byteNumbers = new Array(byteCharacters.length)\n for (let i = 0; i < byteCharacters.length; i++) {\n byteNumbers[i] = byteCharacters.charCodeAt(i)\n }\n const byteArray = new Uint8Array(byteNumbers)\n const file = new File([byteArray], 'pasted-image.' + mimeType?.split('/', 2)[1], {\n type: mimeType,\n })\n transformedImage = { alt: undefined, file, formID }\n } else if (src?.startsWith('http') || src?.startsWith('https')) {\n // It's an image URL\n const res = await fetch(src)\n const blob = await res.blob()\n const inferredFileName =\n src.split('/').pop() || 'pasted-image' + blob.type.split('/', 2)[1]\n const file = new File([blob], inferredFileName, {\n type: blob.type,\n })\n\n transformedImage = { alt: undefined, file, formID }\n }\n\n if (!transformedImage) {\n return\n }\n\n openBulkUpload({ files: [transformedImage] })\n }\n void upload()\n }),\n editor.registerCommand<InsertUploadPayload>(\n INSERT_UPLOAD_COMMAND,\n (payload: InsertUploadPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const uploadNode = $createUploadNode({\n data: {\n id: payload.id,\n fields: payload.fields,\n relationTo: payload.relationTo,\n value: payload.value,\n },\n })\n // we need to get the focus node before inserting the block node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(uploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n PASTE_COMMAND,\n (event) => {\n // Pending UploadNodes are automatically created when importDOM is called. However, if you paste a file from your computer\n // directly, importDOM won't be called, as it's not a HTML dom element. So we need to handle that case here.\n\n if (!(event instanceof ClipboardEvent)) {\n return false\n }\n const clipboardData = event.clipboardData\n\n if (!clipboardData?.types?.length || clipboardData?.types?.includes('text/html')) {\n // HTML is handled through importDOM => registerNodeTransform for pending UploadNode\n return false\n }\n\n const files: FileToUpload[] = []\n if (clipboardData?.files?.length) {\n Array.from(clipboardData.files).forEach((file) => {\n files.push({\n alt: '',\n file,\n formID: new ObjectID.default().toHexString(),\n })\n })\n }\n\n if (files.length) {\n // Insert a pending UploadNode for each image\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n for (const file of files) {\n const pendingUploadNode = $createUploadNode({\n data: {\n pending: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\n } as Internal_UploadData,\n })\n // we need to get the focus node before inserting the upload node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(pendingUploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n }\n })\n\n // Open the bulk drawer - the node transform will not open it for us, as it does not handle blob/file uploads\n openBulkUpload({ files })\n\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n // Handle drag & drop of files from the desktop into the editor\n editor.registerCommand(\n DROP_COMMAND,\n (event) => {\n if (!(event instanceof DragEvent)) {\n return false\n }\n\n const dt = event.dataTransfer\n\n if (!dt?.types?.length) {\n return false\n }\n\n const files: FileToUpload[] = []\n if (dt?.files?.length) {\n Array.from(dt.files).forEach((file) => {\n files.push({\n alt: '',\n file,\n formID: new ObjectID.default().toHexString(),\n })\n })\n }\n\n if (files.length) {\n // Prevent the default browser drop handling, which would open the file in the browser\n event.preventDefault()\n event.stopPropagation()\n\n // Insert a PendingUploadNode for each image\n editor.update(() => {\n if (canDropImage(event)) {\n const range = getDragSelection(event)\n const selection = $createRangeSelection()\n if (range !== null && range !== undefined) {\n selection.applyDOMRange(range)\n }\n $setSelection(selection)\n\n for (const file of files) {\n const pendingUploadNode = $createUploadNode({\n data: {\n pending: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\n } as Internal_UploadData,\n })\n // we need to get the focus node before inserting the upload node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(pendingUploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n }\n })\n\n // Open the bulk drawer - the node transform will not open it for us, as it does not handle blob/file uploads\n openBulkUpload({ files })\n\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor])\n\n return <UploadDrawer enabledCollectionSlugs={enabledCollectionSlugs} />\n}\n"],"names":["useLexicalComposerContext","$dfsIterator","$insertNodeToNearestRoot","mergeRegister","useBulkUpload","useEffectEvent","useModal","ObjectID","$createRangeSelection","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","$setSelection","COMMAND_PRIORITY_EDITOR","COMMAND_PRIORITY_LOW","createCommand","DROP_COMMAND","getDOMSelectionFromTarget","isHTMLElement","PASTE_COMMAND","React","useEffect","useEnabledRelationships","UploadDrawer","$createUploadNode","$isUploadNode","UploadNode","canDropImage","event","target","closest","parentElement","getDragSelection","range","domSelection","document","caretRangeFromPoint","clientX","clientY","rangeParent","collapse","rangeOffset","getRangeAt","Error","INSERT_UPLOAD_COMMAND","UploadPlugin","clientProps","editor","enabledCollectionSlugs","collectionSlugsBlacklist","disabledCollections","collectionSlugsWhitelist","enabledCollections","uploads","drawerSlug","bulkUploadDrawerSlug","setCollectionSlug","setInitialForms","setOnCancel","setOnSuccess","setSelectableCollections","isModalOpen","openModal","openBulkUpload","files","length","initialForms","map","file","formID","update","dfsNode","node","nodeData","getData","pending","remove","newDocs","newDocsMap","Map","doc","newDoc","get","replace","data","id","default","toHexString","fields","relationTo","collectionSlug","value","hasNodes","registerNodeTransform","upload","transformedImage","src","startsWith","mimeMatch","match","mimeType","base64Data","byteCharacters","atob","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","File","split","type","alt","undefined","res","fetch","blob","inferredFileName","pop","registerCommand","payload","selection","uploadNode","focus","focusNode","getNode","__first","ClipboardEvent","clipboardData","types","includes","from","forEach","push","pendingUploadNode","URL","createObjectURL","DragEvent","dt","dataTransfer","preventDefault","stopPropagation","applyDOMRange"],"mappings":"AAAA;;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,YAAY,EAAEC,wBAAwB,EAAEC,aAAa,QAAQ,iBAAgB;AACtF,SAASC,aAAa,EAAEC,cAAc,EAAEC,QAAQ,QAAQ,iBAAgB;AACxE,OAAOC,cAAc,gBAAe;AACpC,SACEC,qBAAqB,EACrBC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,aAAa,EACbC,uBAAuB,EACvBC,oBAAoB,EACpBC,aAAa,EACbC,YAAY,EACZC,yBAAyB,EACzBC,aAAa,EACbC,aAAa,QACR,UAAS;AAChB,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAMxC,SAASC,uBAAuB,QAAQ,gEAA+D;AACvG,SAASC,YAAY,QAAQ,qBAAoB;AACjD,SAASC,iBAAiB,EAAEC,aAAa,EAAEC,UAAU,QAAQ,yBAAwB;AAWrF,SAASC,aAAaC,KAAgB;IACpC,MAAMC,SAASD,MAAMC,MAAM;IAC3B,OAAO,CAAC,CACNX,CAAAA,cAAcW,WACd,CAACA,OAAOC,OAAO,CAAC,8BAChBZ,cAAcW,OAAOE,aAAa,KAClCF,OAAOE,aAAa,CAACD,OAAO,CAAC,4BAA2B;AAE5D;AAEA,SAASE,iBAAiBJ,KAAgB;IACxC,wHAAwH;IACxH,IAAIK;IACJ,MAAMC,eAAejB,0BAA0BW,MAAMC,MAAM;IAC3D,IAAIM,SAASC,mBAAmB,EAAE;QAChCH,QAAQE,SAASC,mBAAmB,CAACR,MAAMS,OAAO,EAAET,MAAMU,OAAO;IACnE,OAAO,IAAIV,MAAMW,WAAW,IAAIL,iBAAi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AAI0B,UAAU,QAAQA,UAAUiF,WAAW;4BACzCQ,UAAUqB,aAAa,CAAC9G;wBAC1B;wBACArB,cAAc8G;wBAEd,KAAK,MAAMtD,QAAQJ,MAAO;4BACxB,MAAMuE,oBAAoB/G,kBAAkB;gCAC1C4D,MAAM;oCACJT,SAAS;wCACPN,QAAQD,KAAKC,MAAM;wCACnB2B,KAAKwC,IAAIC,eAAe,CAACrE,KAAKA,IAAI;oCACpC;gCACF;4BACF;4BACA,wHAAwH;4BACxH,MAAM,EAAEwD,KAAK,EAAE,GAAGF;4BAClB,MAAMG,YAAYD,MAAME,OAAO;4BAC/B,8HAA8H;4BAC9H7H,yBAAyBsI;4BAEzB,6CAA6C;4BAC7C,IAAI7H,iBAAiBmH,cAAc,CAACA,UAAUE,OAAO,EAAE;gCACrDF,UAAUjD,MAAM;4BAClB;wBACF;oBACF;gBACF;gBAEA,6GAA6G;gBAC7Gb,eAAe;oBAAEC;gBAAM;gBAEvB,OAAO;YACT;YAEA,OAAO;QACT,GACAlD;IAGN,GAAG;QAACiC;KAAO;IAEX,qBAAO,QAACxB;QAAayB,wBAAwBA;;;;;;AAC/C,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/features/upload/client/plugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $dfsIterator, $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils'\nimport { useBulkUpload, useEffectEvent, useModal } from '@payloadcms/ui'\nimport ObjectID from 'bson-objectid'\nimport {\n $createRangeSelection,\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n $setSelection,\n COMMAND_PRIORITY_EDITOR,\n COMMAND_PRIORITY_LOW,\n createCommand,\n DROP_COMMAND,\n getDOMSelectionFromTarget,\n isHTMLElement,\n PASTE_COMMAND,\n} from 'lexical'\nimport React, { useEffect } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { Internal_UploadData, UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\n\nimport { useEnabledRelationships } from '../../../relationship/client/utils/useEnabledRelationships.js'\nimport { UploadDrawer } from '../drawer/index.js'\nimport { $createUploadNode, $isUploadNode, UploadNode } from '../nodes/UploadNode.js'\n\nexport type InsertUploadPayload = Readonly<Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>>\n\ndeclare global {\n interface DragEvent {\n rangeOffset?: number\n rangeParent?: Node\n }\n}\n\nfunction canDropImage(event: DragEvent): boolean {\n const target = event.target\n return !!(\n isHTMLElement(target) &&\n !target.closest('code, span.editor-image') &&\n isHTMLElement(target.parentElement) &&\n target.parentElement.closest('div.ContentEditable__root')\n )\n}\n\nfunction getDragSelection(event: DragEvent): null | Range | undefined {\n // Source: https://github.com/AlessioGr/lexical/blob/main/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx\n let range\n const domSelection = getDOMSelectionFromTarget(event.target)\n if (document.caretRangeFromPoint) {\n range = document.caretRangeFromPoint(event.clientX, event.clientY)\n } else if (event.rangeParent && domSelection !== null) {\n domSelection.collapse(event.rangeParent, event.rangeOffset || 0)\n range = domSelection.getRangeAt(0)\n } else {\n throw Error(`Cannot get the selection when dragging`)\n }\n\n return range\n}\n\nexport const INSERT_UPLOAD_COMMAND: LexicalCommand<InsertUploadPayload> =\n createCommand('INSERT_UPLOAD_COMMAND')\n\ntype FileToUpload = {\n alt?: string\n file: File\n /**\n * Bulk Upload Form ID that should be created, which can then be matched\n * against the node formID if the upload is successful\n */\n formID: string\n}\n\nexport const UploadPlugin: PluginComponent<UploadFeaturePropsClient> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n\n const { enabledCollectionSlugs } = useEnabledRelationships({\n collectionSlugsBlacklist: clientProps?.disabledCollections,\n collectionSlugsWhitelist: clientProps?.enabledCollections,\n uploads: true,\n })\n\n const {\n drawerSlug: bulkUploadDrawerSlug,\n setCollectionSlug,\n setInitialForms,\n setOnCancel,\n setOnSuccess,\n setSelectableCollections,\n } = useBulkUpload()\n\n const { isModalOpen, openModal } = useModal()\n\n const openBulkUpload = useEffectEvent(({ files }: { files: FileToUpload[] }) => {\n if (files?.length === 0) {\n return\n }\n\n setInitialForms((initialForms) => [\n ...(initialForms ?? []),\n ...files.map((file) => ({\n file: file.file,\n formID: file.formID,\n })),\n ])\n\n if (!isModalOpen(bulkUploadDrawerSlug)) {\n if (!enabledCollectionSlugs.length || !enabledCollectionSlugs[0]) {\n return\n }\n\n setCollectionSlug(enabledCollectionSlugs[0])\n setSelectableCollections(enabledCollectionSlugs)\n\n setOnCancel(() => {\n // Remove all the pending upload nodes that were added but not uploaded\n editor.update(() => {\n for (const dfsNode of $dfsIterator()) {\n const node = dfsNode.node\n\n if ($isUploadNode(node)) {\n const nodeData = node.getData()\n if ((nodeData as Internal_UploadData)?.pending) {\n node.remove()\n }\n }\n }\n })\n })\n\n setOnSuccess((newDocs) => {\n const newDocsMap = new Map(newDocs.map((doc) => [doc.formID, doc]))\n editor.update(() => {\n for (const dfsNode of $dfsIterator()) {\n const node = dfsNode.node\n if ($isUploadNode(node)) {\n const nodeData: Internal_UploadData = node.getData()\n\n if (nodeData?.pending) {\n const newDoc = newDocsMap.get(nodeData.pending?.formID)\n if (newDoc) {\n node.replace(\n $createUploadNode({\n data: {\n id: new ObjectID.default().toHexString(),\n fields: {},\n relationTo: newDoc.collectionSlug,\n value: newDoc.doc.id,\n } as UploadData,\n }),\n )\n }\n }\n }\n }\n })\n })\n\n openModal(bulkUploadDrawerSlug)\n }\n })\n\n useEffect(() => {\n if (!editor.hasNodes([UploadNode])) {\n throw new Error('UploadPlugin: UploadNode not registered on editor')\n }\n\n return mergeRegister(\n /**\n * Handle auto-uploading files if you copy & paste an image dom element from the clipboard\n */\n editor.registerNodeTransform(UploadNode, (node) => {\n const nodeData: Internal_UploadData = node.getData()\n if (!nodeData?.pending) {\n return\n }\n\n async function upload() {\n let transformedImage: FileToUpload | null = null\n\n const src = nodeData?.pending?.src\n const formID = nodeData?.pending?.formID as string\n\n if (src?.startsWith('data:')) {\n // It's a base64-encoded image\n const mimeMatch = src.match(/data:(image\\/[a-zA-Z]+);base64,/)\n const mimeType = mimeMatch ? mimeMatch[1] : 'image/png' // Default to PNG if MIME type not found\n const base64Data = src.replace(/^data:image\\/[a-zA-Z]+;base64,/, '')\n const byteCharacters = atob(base64Data)\n const byteNumbers = new Array(byteCharacters.length)\n for (let i = 0; i < byteCharacters.length; i++) {\n byteNumbers[i] = byteCharacters.charCodeAt(i)\n }\n const byteArray = new Uint8Array(byteNumbers)\n const file = new File([byteArray], 'pasted-image.' + mimeType?.split('/', 2)[1], {\n type: mimeType,\n })\n transformedImage = { alt: undefined, file, formID }\n } else if (src?.startsWith('http') || src?.startsWith('https')) {\n // It's an image URL\n const res = await fetch(src)\n const blob = await res.blob()\n const inferredFileName =\n src.split('/').pop() || 'pasted-image' + blob.type.split('/', 2)[1]\n const file = new File([blob], inferredFileName, {\n type: blob.type,\n })\n\n transformedImage = { alt: undefined, file, formID }\n }\n\n if (!transformedImage) {\n return\n }\n\n openBulkUpload({ files: [transformedImage] })\n }\n void upload()\n }),\n editor.registerCommand<InsertUploadPayload>(\n INSERT_UPLOAD_COMMAND,\n (payload: InsertUploadPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const uploadNode = $createUploadNode({\n data: {\n id: payload.id,\n fields: payload.fields,\n relationTo: payload.relationTo,\n value: payload.value,\n },\n })\n // we need to get the focus node before inserting the block node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(uploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n PASTE_COMMAND,\n (event) => {\n // Pending UploadNodes are automatically created when importDOM is called. However, if you paste a file from your computer\n // directly, importDOM won't be called, as it's not a HTML dom element. So we need to handle that case here.\n\n if (!(event instanceof ClipboardEvent)) {\n return false\n }\n const clipboardData = event.clipboardData\n\n if (!clipboardData?.types?.length || clipboardData?.types?.includes('text/html')) {\n // HTML is handled through importDOM => registerNodeTransform for pending UploadNode\n return false\n }\n\n const files: FileToUpload[] = []\n if (clipboardData?.files?.length) {\n Array.from(clipboardData.files).forEach((file) => {\n files.push({\n alt: '',\n file,\n formID: new ObjectID.default().toHexString(),\n })\n })\n }\n\n if (files.length) {\n // Insert a pending UploadNode for each image\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n for (const file of files) {\n const pendingUploadNode = $createUploadNode({\n data: {\n pending: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\n } as Internal_UploadData,\n })\n // we need to get the focus node before inserting the upload node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(pendingUploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n }\n })\n\n // Open the bulk drawer - the node transform will not open it for us, as it does not handle blob/file uploads\n openBulkUpload({ files })\n\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n // Handle drag & drop of files from the desktop into the editor\n editor.registerCommand(\n DROP_COMMAND,\n (event) => {\n if (!(event instanceof DragEvent)) {\n return false\n }\n\n const dt = event.dataTransfer\n\n if (!dt?.types?.length) {\n return false\n }\n\n const files: FileToUpload[] = []\n if (dt?.files?.length) {\n Array.from(dt.files).forEach((file) => {\n files.push({\n alt: '',\n file,\n formID: new ObjectID.default().toHexString(),\n })\n })\n }\n\n if (files.length) {\n // Prevent the default browser drop handling, which would open the file in the browser\n event.preventDefault()\n event.stopPropagation()\n\n // Insert a PendingUploadNode for each image\n editor.update(() => {\n if (canDropImage(event)) {\n const range = getDragSelection(event)\n const selection = $createRangeSelection()\n if (range !== null && range !== undefined) {\n selection.applyDOMRange(range)\n }\n $setSelection(selection)\n\n for (const file of files) {\n const pendingUploadNode = $createUploadNode({\n data: {\n pending: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\n } as Internal_UploadData,\n })\n // we need to get the focus node before inserting the upload node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(pendingUploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n }\n })\n\n // Open the bulk drawer - the node transform will not open it for us, as it does not handle blob/file uploads\n openBulkUpload({ files })\n\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor])\n\n return <UploadDrawer enabledCollectionSlugs={enabledCollectionSlugs} />\n}\n"],"names":["useLexicalComposerContext","$dfsIterator","$insertNodeToNearestRoot","mergeRegister","useBulkUpload","useEffectEvent","useModal","ObjectID","$createRangeSelection","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","$setSelection","COMMAND_PRIORITY_EDITOR","COMMAND_PRIORITY_LOW","createCommand","DROP_COMMAND","getDOMSelectionFromTarget","isHTMLElement","PASTE_COMMAND","useEffect","useEnabledRelationships","UploadDrawer","$createUploadNode","$isUploadNode","UploadNode","canDropImage","event","target","closest","parentElement","getDragSelection","range","domSelection","document","caretRangeFromPoint","clientX","clientY","rangeParent","collapse","rangeOffset","getRangeAt","Error","INSERT_UPLOAD_COMMAND","UploadPlugin","clientProps","editor","enabledCollectionSlugs","collectionSlugsBlacklist","disabledCollections","collectionSlugsWhitelist","enabledCollections","uploads","drawerSlug","bulkUploadDrawerSlug","setCollectionSlug","setInitialForms","setOnCancel","setOnSuccess","setSelectableCollections","isModalOpen","openModal","openBulkUpload","files","length","initialForms","map","file","formID","update","dfsNode","node","nodeData","getData","pending","remove","newDocs","newDocsMap","Map","doc","newDoc","get","replace","data","id","default","toHexString","fields","relationTo","collectionSlug","value","hasNodes","registerNodeTransform","upload","transformedImage","src","startsWith","mimeMatch","match","mimeType","base64Data","byteCharacters","atob","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","File","split","type","alt","undefined","res","fetch","blob","inferredFileName","pop","registerCommand","payload","selection","uploadNode","focus","focusNode","getNode","__first","ClipboardEvent","clipboardData","types","includes","from","forEach","push","pendingUploadNode","URL","createObjectURL","DragEvent","dt","dataTransfer","preventDefault","stopPropagation","applyDOMRange"],"mappings":"AAAA;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,YAAY,EAAEC,wBAAwB,EAAEC,aAAa,QAAQ,iBAAgB;AACtF,SAASC,aAAa,EAAEC,cAAc,EAAEC,QAAQ,QAAQ,iBAAgB;AACxE,OAAOC,cAAc,gBAAe;AACpC,SACEC,qBAAqB,EACrBC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,aAAa,EACbC,uBAAuB,EACvBC,oBAAoB,EACpBC,aAAa,EACbC,YAAY,EACZC,yBAAyB,EACzBC,aAAa,EACbC,aAAa,QACR,UAAS;AAChB,SAAgBC,SAAS,QAAQ,QAAO;AAMxC,SAASC,uBAAuB,QAAQ,gEAA+D;AACvG,SAASC,YAAY,QAAQ,qBAAoB;AACjD,SAASC,iBAAiB,EAAEC,aAAa,EAAEC,UAAU,QAAQ,yBAAwB;AAWrF,SAASC,aAAaC,KAAgB;IACpC,MAAMC,SAASD,MAAMC,MAAM;IAC3B,OAAO,CAAC,CACNV,CAAAA,cAAcU,WACd,CA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BJ,MAAMsE,IAAI,CAAC;wBACTrB,KAAK;wBACL7C;wBACAC,QAAQ,IAAI9D,SAAS+E,OAAO,GAAGC,WAAW;oBAC5C;gBACF;YACF;YAEA,IAAIvB,MAAMC,MAAM,EAAE;gBAChB,sFAAsF;gBACtFrC,MAAMiH,cAAc;gBACpBjH,MAAMkH,eAAe;gBAErB,4CAA4C;gBAC5C/F,OAAOuB,MAAM,CAAC;oBACZ,IAAI3C,aAAaC,QAAQ;wBACvB,MAAMK,QAAQD,iBAAiBJ;wBAC/B,MAAM8F,YAAYlH;wBAClB,IAAIyB,UAAU,QAAQA,UAAUiF,WAAW;4BACzCQ,UAAUqB,aAAa,CAAC9G;wBAC1B;wBACApB,cAAc6G;wBAEd,KAAK,MAAMtD,QAAQJ,MAAO;4BACxB,MAAMuE,oBAAoB/G,kBAAkB;gCAC1C4D,MAAM;oCACJT,SAAS;wCACPN,QAAQD,KAAKC,MAAM;wCACnB2B,KAAKwC,IAAIC,eAAe,CAACrE,KAAKA,IAAI;oCACpC;gCACF;4BACF;4BACA,wHAAwH;4BACxH,MAAM,EAAEwD,KAAK,EAAE,GAAGF;4BAClB,MAAMG,YAAYD,MAAME,OAAO;4BAC/B,8HAA8H;4BAC9H5H,yBAAyBqI;4BAEzB,6CAA6C;4BAC7C,IAAI5H,iBAAiBkH,cAAc,CAACA,UAAUE,OAAO,EAAE;gCACrDF,UAAUjD,MAAM;4BAClB;wBACF;oBACF;gBACF;gBAEA,6GAA6G;gBAC7Gb,eAAe;oBAAEC;gBAAM;gBAEvB,OAAO;YACT;YAEA,OAAO;QACT,GACAjD;IAGN,GAAG;QAACgC;KAAO;IAEX,QAAQxB,aAAayB,wBAAwBA;AAC/C,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/features/upload/server/nodes/UploadNode.tsx"],"sourcesContent":["import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport type {\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n ElementFormatType,\n LexicalNode,\n NodeKey,\n} from 'lexical'\nimport type {\n CollectionSlug,\n DataFromCollectionSlug,\n JsonObject,\n TypedUploadCollection,\n UploadCollectionSlug,\n} from 'payload'\nimport type { JSX } from 'react'\n\nimport { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport { addClassNamesToElement } from '@lexical/utils'\nimport ObjectID from 'bson-objectid'\nimport { $applyNodeReplacement } from 'lexical'\n\nimport type { StronglyTypedLeafNode } from '../../../../nodeTypes.js'\n\nimport { $convertUploadElement } from './conversions.js'\n\nexport type UploadData<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n [TCollectionSlug in CollectionSlug]: {\n fields: TUploadExtraFieldsData\n /**\n * Every lexical node that has sub-fields needs to have a unique ID. This is the ID of this upload node, not the ID of the linked upload document\n */\n id: string\n relationTo: TCollectionSlug\n /**\n * Value can be just the document ID, or the full, populated document\n */\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[CollectionSlug]\n\n/**\n * Internal use only - UploadData type that can contain a pending state\n * @internal\n */\nexport type Internal_UploadData<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n pending?: {\n /**\n * ID that corresponds to the bulk upload form ID\n */\n formID: string\n /**\n * src value of the image dom element\n */\n src: string\n }\n} & UploadData<TUploadExtraFieldsData>\n\n/**\n * UploadDataImproved is a more precise type, and will replace UploadData in Payload v4.\n * This type is for internal use only as it will be deprecated in the future.\n * @internal\n *\n * @todo Replace UploadData with UploadDataImproved in 4.0\n */\nexport type UploadDataImproved<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n [TCollectionSlug in UploadCollectionSlug]: {\n fields: TUploadExtraFieldsData\n /**\n * Every lexical node that has sub-fields needs to have a unique ID. This is the ID of this upload node, not the ID of the linked upload document\n */\n id: string\n relationTo: TCollectionSlug\n /**\n * Value can be just the document ID, or the full, populated document\n */\n value: number | string | TypedUploadCollection[TCollectionSlug]\n }\n}[UploadCollectionSlug]\n\nexport type SerializedUploadNode = StronglyTypedLeafNode<SerializedDecoratorBlockNode, 'upload'> &\n UploadData\n\nexport class UploadServerNode 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 override clone(node: UploadServerNode): UploadServerNode {\n return new this({\n data: node.__data,\n format: node.__format,\n key: node.__key,\n })\n }\n\n static override getType(): string {\n return 'upload'\n }\n\n static override importDOM(): DOMConversionMap<HTMLImageElement> {\n return {\n img: (node) => ({\n conversion: (domNode) => $convertUploadElement(domNode, $createUploadServerNode),\n priority: 0,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedUploadNode): UploadServerNode {\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: Internal_UploadData = {\n id: serializedNode.id,\n fields: serializedNode.fields,\n pending: (serializedNode as Internal_UploadData).pending,\n relationTo: serializedNode.relationTo,\n value: serializedNode.value,\n }\n\n const node = $createUploadServerNode({ data: importedData })\n node.setFormat(serializedNode.format)\n\n return node\n }\n\n static isInline(): false {\n return false\n }\n\n override createDOM(config?: EditorConfig): HTMLElement {\n const element = document.createElement('div')\n addClassNamesToElement(element, config?.theme?.upload)\n return element\n }\n\n override decorate(): JSX.Element {\n return null as unknown as JSX.Element\n }\n\n override exportDOM(): DOMExportOutput {\n const element = document.createElement('img')\n const data = this.__data as Internal_UploadData\n if (data.pending) {\n element.setAttribute('data-lexical-pending-upload-form-id', String(data?.pending?.formID))\n element.setAttribute('src', data?.pending?.src || '')\n } else {\n element.setAttribute('data-lexical-upload-id', String(data?.value))\n element.setAttribute('data-lexical-upload-relation-to', data?.relationTo)\n }\n\n return { element }\n }\n\n override 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 override updateDOM(): false {\n return false\n }\n}\n\nexport function $createUploadServerNode({\n data,\n}: {\n data: Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>\n}): UploadServerNode {\n if (!data?.id) {\n data.id = new ObjectID.default().toHexString()\n }\n return $applyNodeReplacement(new UploadServerNode({ data: data as UploadData }))\n}\n\nexport function $isUploadServerNode(\n node: LexicalNode | null | undefined,\n): node is UploadServerNode {\n return node instanceof UploadServerNode\n}\n"],"names":["DecoratorBlockNode","addClassNamesToElement","ObjectID","$applyNodeReplacement","$convertUploadElement","UploadServerNode","__data","
|
|
1
|
+
{"version":3,"sources":["../../../../../src/features/upload/server/nodes/UploadNode.tsx"],"sourcesContent":["import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport type {\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n ElementFormatType,\n LexicalNode,\n NodeKey,\n} from 'lexical'\nimport type {\n CollectionSlug,\n DataFromCollectionSlug,\n JsonObject,\n TypedUploadCollection,\n UploadCollectionSlug,\n} from 'payload'\nimport type { JSX } from 'react'\n\nimport { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport { addClassNamesToElement } from '@lexical/utils'\nimport ObjectID from 'bson-objectid'\nimport { $applyNodeReplacement } from 'lexical'\n\nimport type { StronglyTypedLeafNode } from '../../../../nodeTypes.js'\n\nimport { $convertUploadElement } from './conversions.js'\n\nexport type UploadData<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n [TCollectionSlug in CollectionSlug]: {\n fields: TUploadExtraFieldsData\n /**\n * Every lexical node that has sub-fields needs to have a unique ID. This is the ID of this upload node, not the ID of the linked upload document\n */\n id: string\n relationTo: TCollectionSlug\n /**\n * Value can be just the document ID, or the full, populated document\n */\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[CollectionSlug]\n\n/**\n * Internal use only - UploadData type that can contain a pending state\n * @internal\n */\nexport type Internal_UploadData<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n pending?: {\n /**\n * ID that corresponds to the bulk upload form ID\n */\n formID: string\n /**\n * src value of the image dom element\n */\n src: string\n }\n} & UploadData<TUploadExtraFieldsData>\n\n/**\n * UploadDataImproved is a more precise type, and will replace UploadData in Payload v4.\n * This type is for internal use only as it will be deprecated in the future.\n * @internal\n *\n * @todo Replace UploadData with UploadDataImproved in 4.0\n */\nexport type UploadDataImproved<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n [TCollectionSlug in UploadCollectionSlug]: {\n fields: TUploadExtraFieldsData\n /**\n * Every lexical node that has sub-fields needs to have a unique ID. This is the ID of this upload node, not the ID of the linked upload document\n */\n id: string\n relationTo: TCollectionSlug\n /**\n * Value can be just the document ID, or the full, populated document\n */\n value: number | string | TypedUploadCollection[TCollectionSlug]\n }\n}[UploadCollectionSlug]\n\nexport type SerializedUploadNode = StronglyTypedLeafNode<SerializedDecoratorBlockNode, 'upload'> &\n UploadData\n\nexport class UploadServerNode 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 override clone(node: UploadServerNode): UploadServerNode {\n return new this({\n data: node.__data,\n format: node.__format,\n key: node.__key,\n })\n }\n\n static override getType(): string {\n return 'upload'\n }\n\n static override importDOM(): DOMConversionMap<HTMLImageElement> {\n return {\n img: (node) => ({\n conversion: (domNode) => $convertUploadElement(domNode, $createUploadServerNode),\n priority: 0,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedUploadNode): UploadServerNode {\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: Internal_UploadData = {\n id: serializedNode.id,\n fields: serializedNode.fields,\n pending: (serializedNode as Internal_UploadData).pending,\n relationTo: serializedNode.relationTo,\n value: serializedNode.value,\n }\n\n const node = $createUploadServerNode({ data: importedData })\n node.setFormat(serializedNode.format)\n\n return node\n }\n\n static isInline(): false {\n return false\n }\n\n override createDOM(config?: EditorConfig): HTMLElement {\n const element = document.createElement('div')\n addClassNamesToElement(element, config?.theme?.upload)\n return element\n }\n\n override decorate(): JSX.Element {\n return null as unknown as JSX.Element\n }\n\n override exportDOM(): DOMExportOutput {\n const element = document.createElement('img')\n const data = this.__data as Internal_UploadData\n if (data.pending) {\n element.setAttribute('data-lexical-pending-upload-form-id', String(data?.pending?.formID))\n element.setAttribute('src', data?.pending?.src || '')\n } else {\n element.setAttribute('data-lexical-upload-id', String(data?.value))\n element.setAttribute('data-lexical-upload-relation-to', data?.relationTo)\n }\n\n return { element }\n }\n\n override 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 override updateDOM(): false {\n return false\n }\n}\n\nexport function $createUploadServerNode({\n data,\n}: {\n data: Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>\n}): UploadServerNode {\n if (!data?.id) {\n data.id = new ObjectID.default().toHexString()\n }\n return $applyNodeReplacement(new UploadServerNode({ data: data as UploadData }))\n}\n\nexport function $isUploadServerNode(\n node: LexicalNode | null | undefined,\n): node is UploadServerNode {\n return node instanceof UploadServerNode\n}\n"],"names":["DecoratorBlockNode","addClassNamesToElement","ObjectID","$applyNodeReplacement","$convertUploadElement","UploadServerNode","__data","data","format","key","clone","node","__format","__key","getType","importDOM","img","conversion","domNode","$createUploadServerNode","priority","importJSON","serializedNode","version","value","id","default","toHexString","importedData","fields","pending","relationTo","setFormat","isInline","createDOM","config","element","document","createElement","theme","upload","decorate","exportDOM","setAttribute","String","formID","src","exportJSON","getData","type","getLatest","setData","writable","getWritable","updateDOM","$isUploadServerNode"],"mappings":"AAkBA,SAASA,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,sBAAsB,QAAQ,iBAAgB;AACvD,OAAOC,cAAc,gBAAe;AACpC,SAASC,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,qBAAqB,QAAQ,mBAAkB;AAKpD;;KAEC,GAGD;;KAEC,GAKL;;;CAGC,GAGG;;KAEC,GAED;;KAEC,GAKL;;;;;;CAMC,GAIG;;KAEC,GAGD;;KAEC,GAQL,OAAO,MAAMC,yBAAyBL;IACpCM,OAAkB;IAElB,YAAY,EACVC,IAAI,EACJC,MAAM,EACNC,GAAG,EAKJ,CAAE;QACD,KAAK,CAACD,QAAQC;QACd,IAAI,CAACH,MAAM,GAAGC;IAChB;IAEA,OAAgBG,MAAMC,IAAsB,EAAoB;QAC9D,OAAO,IAAI,IAAI,CAAC;YACdJ,MAAMI,KAAKL,MAAM;YACjBE,QAAQG,KAAKC,QAAQ;YACrBH,KAAKE,KAAKE,KAAK;QACjB;IACF;IAEA,OAAgBC,UAAkB;QAChC,OAAO;IACT;IAEA,OAAgBC,YAAgD;QAC9D,OAAO;YACLC,KAAK,CAACL,OAAU,CAAA;oBACdM,YAAY,CAACC,UAAYd,sBAAsBc,SAASC;oBACxDC,UAAU;gBACZ,CAAA;QACF;IACF;IAEA,OAAgBC,WAAWC,cAAoC,EAAoB;QACjF,IAAIA,eAAeC,OAAO,KAAK,KAAMD,gBAAgBE,OAAqCC,IAAI;YAC5FH,eAAeE,KAAK,GAAG,AAACF,eAAeE,KAAK,CAA+BC,EAAE;QAC/E;QACA,IAAIH,eAAeC,OAAO,KAAK,KAAK,CAACD,gBAAgBG,IAA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AW;QACjCD,SAAS9C,MAAM,GAAGC;IACpB;IAES+C,YAAmB;QAC1B,OAAO;IACT;AACF;AAEA,OAAO,SAASnC,wBAAwB,EACtCZ,IAAI,EAGL;IACC,IAAI,CAACA,MAAMkB,IAAI;QACblB,KAAKkB,EAAE,GAAG,IAAIvB,SAASwB,OAAO,GAAGC,WAAW;IAC9C;IACA,OAAOxB,sBAAsB,IAAIE,iBAAiB;QAAEE,MAAMA;IAAmB;AAC/E;AAEA,OAAO,SAASgD,oBACd5C,IAAoC;IAEpC,OAAOA,gBAAgBN;AACzB"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
2
1
|
import { CheckIcon } from '@payloadcms/ui/rsc';
|
|
3
2
|
import './index.scss';
|
|
4
3
|
export const ListItemDiffHTMLConverterAsync = {
|
|
@@ -9,59 +8,17 @@ export const ListItemDiffHTMLConverterAsync = {
|
|
|
9
8
|
})).join('');
|
|
10
9
|
if ('listType' in parent && parent?.listType === 'check') {
|
|
11
10
|
const ReactDOMServer = (await import('react-dom/server')).default;
|
|
12
|
-
const JSX =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
}, void 0, false, {
|
|
25
|
-
fileName: "src/field/Diff/converters/listitem/index.tsx",
|
|
26
|
-
lineNumber: 34,
|
|
27
|
-
columnNumber: 13
|
|
28
|
-
}, this) : // Otherwise, show our custom styled checkbox
|
|
29
|
-
/*#__PURE__*/ _jsxDEV("div", {
|
|
30
|
-
className: "checkboxItem__wrapper",
|
|
31
|
-
children: [
|
|
32
|
-
/*#__PURE__*/ _jsxDEV("div", {
|
|
33
|
-
className: "checkboxItem__icon",
|
|
34
|
-
"data-checked": node.checked,
|
|
35
|
-
"data-enable-match": "true",
|
|
36
|
-
children: node.checked && /*#__PURE__*/ _jsxDEV(CheckIcon, {}, void 0, false, {
|
|
37
|
-
fileName: "src/field/Diff/converters/listitem/index.tsx",
|
|
38
|
-
lineNumber: 43,
|
|
39
|
-
columnNumber: 34
|
|
40
|
-
}, this)
|
|
41
|
-
}, void 0, false, {
|
|
42
|
-
fileName: "src/field/Diff/converters/listitem/index.tsx",
|
|
43
|
-
lineNumber: 38,
|
|
44
|
-
columnNumber: 15
|
|
45
|
-
}, this),
|
|
46
|
-
/*#__PURE__*/ _jsxDEV("span", {
|
|
47
|
-
className: "checkboxItem__label",
|
|
48
|
-
children: children
|
|
49
|
-
}, void 0, false, {
|
|
50
|
-
fileName: "src/field/Diff/converters/listitem/index.tsx",
|
|
51
|
-
lineNumber: 45,
|
|
52
|
-
columnNumber: 15
|
|
53
|
-
}, this)
|
|
54
|
-
]
|
|
55
|
-
}, void 0, true, {
|
|
56
|
-
fileName: "src/field/Diff/converters/listitem/index.tsx",
|
|
57
|
-
lineNumber: 37,
|
|
58
|
-
columnNumber: 13
|
|
59
|
-
}, this)
|
|
60
|
-
}, void 0, false, {
|
|
61
|
-
fileName: "src/field/Diff/converters/listitem/index.tsx",
|
|
62
|
-
lineNumber: 22,
|
|
63
|
-
columnNumber: 9
|
|
64
|
-
}, this);
|
|
11
|
+
const JSX = <li aria-checked={node.checked ? true : false} className={`checkboxItem ${node.checked ? 'checkboxItem--checked' : 'checkboxItem--unchecked'}${hasSubLists ? ' checkboxItem--nested' : ''}`} // eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role
|
|
12
|
+
role="checkbox" tabIndex={-1} value={node.value}>
|
|
13
|
+
{hasSubLists ? <div dangerouslySetInnerHTML={{
|
|
14
|
+
__html: children
|
|
15
|
+
}}/> : <div className="checkboxItem__wrapper">
|
|
16
|
+
<div className="checkboxItem__icon" data-checked={node.checked} data-enable-match="true">
|
|
17
|
+
{node.checked && <CheckIcon/>}
|
|
18
|
+
</div>
|
|
19
|
+
<span className="checkboxItem__label">{children}</span>
|
|
20
|
+
</div>}
|
|
21
|
+
</li>;
|
|
65
22
|
const html = ReactDOMServer.renderToStaticMarkup(JSX);
|
|
66
23
|
// Add style="list-style-type: none;${providedCSSString}" to html
|
|
67
24
|
const styleIndex = html.indexOf('class="list-item-checkbox');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/Diff/converters/listitem/index.tsx"],"sourcesContent":["import { CheckIcon } from '@payloadcms/ui/rsc'\n\nimport type { HTMLConvertersAsync } from '../../../../features/converters/lexicalToHtml/async/types.js'\nimport type { SerializedListItemNode } from '../../../../nodeTypes.js'\n\nimport './index.scss'\n\nexport const ListItemDiffHTMLConverterAsync: HTMLConvertersAsync<SerializedListItemNode> = {\n listitem: async ({ node, nodesToHTML, parent, providedCSSString }) => {\n const hasSubLists = node.children.some((child) => child.type === 'list')\n\n const children = (\n await nodesToHTML({\n nodes: node.children,\n })\n ).join('')\n\n if ('listType' in parent && parent?.listType === 'check') {\n const ReactDOMServer = (await import('react-dom/server')).default\n\n const JSX = (\n <li\n aria-checked={node.checked ? true : false}\n className={`checkboxItem ${node.checked ? 'checkboxItem--checked' : 'checkboxItem--unchecked'}${\n hasSubLists ? ' checkboxItem--nested' : ''\n }`}\n // eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n role=\"checkbox\"\n tabIndex={-1}\n value={node.value}\n >\n {hasSubLists ? (\n // When sublists exist, just render them safely as HTML\n <div dangerouslySetInnerHTML={{ __html: children }} />\n ) : (\n // Otherwise, show our custom styled checkbox\n <div className=\"checkboxItem__wrapper\">\n <div\n className=\"checkboxItem__icon\"\n data-checked={node.checked}\n data-enable-match=\"true\"\n >\n {node.checked && <CheckIcon />}\n </div>\n <span className=\"checkboxItem__label\">{children}</span>\n </div>\n )}\n </li>\n )\n\n const html = ReactDOMServer.renderToStaticMarkup(JSX)\n\n // Add style=\"list-style-type: none;${providedCSSString}\" to html\n const styleIndex = html.indexOf('class=\"list-item-checkbox')\n const classIndex = html.indexOf('class=\"list-item-checkbox', styleIndex)\n const classEndIndex = html.indexOf('\"', classIndex + 6)\n const className = html.substring(classIndex, classEndIndex)\n const classNameWithStyle = `${className} style=\"list-style-type: none;${providedCSSString}\"`\n const htmlWithStyle = html.replace(className, classNameWithStyle)\n\n return htmlWithStyle\n } else {\n return `<li\n class=\"${hasSubLists ? 'nestedListItem' : ''}\"\n style=\"${hasSubLists ? `list-style-type: none;${providedCSSString}` : providedCSSString}\"\n value=\"${node.value}\"\n data-enable-match=\"true\"\n >${children}</li>`\n }\n },\n}\n"],"names":["CheckIcon","ListItemDiffHTMLConverterAsync","listitem","node","nodesToHTML","parent","providedCSSString","hasSubLists","children","some","child","type","nodes","join","listType","ReactDOMServer","default","JSX","li","aria-checked","checked","className","role","tabIndex","value","div","dangerouslySetInnerHTML","__html","data-checked","data-enable-match","span","html","renderToStaticMarkup","styleIndex","indexOf","classIndex","classEndIndex","substring","classNameWithStyle","htmlWithStyle","replace"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/Diff/converters/listitem/index.tsx"],"sourcesContent":["import { CheckIcon } from '@payloadcms/ui/rsc'\n\nimport type { HTMLConvertersAsync } from '../../../../features/converters/lexicalToHtml/async/types.js'\nimport type { SerializedListItemNode } from '../../../../nodeTypes.js'\n\nimport './index.scss'\n\nexport const ListItemDiffHTMLConverterAsync: HTMLConvertersAsync<SerializedListItemNode> = {\n listitem: async ({ node, nodesToHTML, parent, providedCSSString }) => {\n const hasSubLists = node.children.some((child) => child.type === 'list')\n\n const children = (\n await nodesToHTML({\n nodes: node.children,\n })\n ).join('')\n\n if ('listType' in parent && parent?.listType === 'check') {\n const ReactDOMServer = (await import('react-dom/server')).default\n\n const JSX = (\n <li\n aria-checked={node.checked ? true : false}\n className={`checkboxItem ${node.checked ? 'checkboxItem--checked' : 'checkboxItem--unchecked'}${\n hasSubLists ? ' checkboxItem--nested' : ''\n }`}\n // eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n role=\"checkbox\"\n tabIndex={-1}\n value={node.value}\n >\n {hasSubLists ? (\n // When sublists exist, just render them safely as HTML\n <div dangerouslySetInnerHTML={{ __html: children }} />\n ) : (\n // Otherwise, show our custom styled checkbox\n <div className=\"checkboxItem__wrapper\">\n <div\n className=\"checkboxItem__icon\"\n data-checked={node.checked}\n data-enable-match=\"true\"\n >\n {node.checked && <CheckIcon />}\n </div>\n <span className=\"checkboxItem__label\">{children}</span>\n </div>\n )}\n </li>\n )\n\n const html = ReactDOMServer.renderToStaticMarkup(JSX)\n\n // Add style=\"list-style-type: none;${providedCSSString}\" to html\n const styleIndex = html.indexOf('class=\"list-item-checkbox')\n const classIndex = html.indexOf('class=\"list-item-checkbox', styleIndex)\n const classEndIndex = html.indexOf('\"', classIndex + 6)\n const className = html.substring(classIndex, classEndIndex)\n const classNameWithStyle = `${className} style=\"list-style-type: none;${providedCSSString}\"`\n const htmlWithStyle = html.replace(className, classNameWithStyle)\n\n return htmlWithStyle\n } else {\n return `<li\n class=\"${hasSubLists ? 'nestedListItem' : ''}\"\n style=\"${hasSubLists ? `list-style-type: none;${providedCSSString}` : providedCSSString}\"\n value=\"${node.value}\"\n data-enable-match=\"true\"\n >${children}</li>`\n }\n },\n}\n"],"names":["CheckIcon","ListItemDiffHTMLConverterAsync","listitem","node","nodesToHTML","parent","providedCSSString","hasSubLists","children","some","child","type","nodes","join","listType","ReactDOMServer","default","JSX","li","aria-checked","checked","className","role","tabIndex","value","div","dangerouslySetInnerHTML","__html","data-checked","data-enable-match","span","html","renderToStaticMarkup","styleIndex","indexOf","classIndex","classEndIndex","substring","classNameWithStyle","htmlWithStyle","replace"],"mappings":"AAAA,SAASA,SAAS,QAAQ,qBAAoB;AAK9C,OAAO,eAAc;AAErB,OAAO,MAAMC,iCAA8E;IACzFC,UAAU,OAAO,EAAEC,IAAI,EAAEC,WAAW,EAAEC,MAAM,EAAEC,iBAAiB,EAAE;QAC/D,MAAMC,cAAcJ,KAAKK,QAAQ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OAAO,CAAC;iBACG,EAAEhC,cAAc,mBAAmB,GAAG;iBACtC,EAAEA,cAAc,CAAC,sBAAsB,EAAED,mBAAmB,GAAGA,kBAAkB;iBACjF,EAAEH,KAAKqB,KAAK,CAAC;;SAErB,EAAEhB,SAAS,KAAK,CAAC;QACtB;IACF;AACF,EAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
2
1
|
import { getTranslation } from '@payloadcms/translations';
|
|
3
2
|
import './index.scss';
|
|
4
3
|
import { formatAdminURL } from 'payload/shared';
|
|
@@ -22,65 +21,24 @@ export const RelationshipDiffHTMLConverterAsync = ({ i18n, req })=>{
|
|
|
22
21
|
}
|
|
23
22
|
const relatedCollection = req.payload.collections[node.relationTo]?.config;
|
|
24
23
|
const ReactDOMServer = (await import('react-dom/server')).default;
|
|
25
|
-
const JSX =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
data && relatedCollection?.admin?.useAsTitle && data[relatedCollection.admin.useAsTitle] ? /*#__PURE__*/ _jsxDEV("strong", {
|
|
44
|
-
className: `${baseClass}__title`,
|
|
45
|
-
"data-enable-match": "false",
|
|
46
|
-
children: /*#__PURE__*/ _jsxDEV("a", {
|
|
47
|
-
className: `${baseClass}__link`,
|
|
48
|
-
"data-enable-match": "false",
|
|
49
|
-
href: formatAdminURL({
|
|
50
|
-
adminRoute: req.payload.config.routes.admin,
|
|
51
|
-
path: `/collections/${relatedCollection?.slug}/${data.id}`,
|
|
52
|
-
serverURL: req.payload.config.serverURL
|
|
53
|
-
}),
|
|
54
|
-
rel: "noopener noreferrer",
|
|
55
|
-
target: "_blank",
|
|
56
|
-
children: data[relatedCollection.admin.useAsTitle]
|
|
57
|
-
}, void 0, false, {
|
|
58
|
-
fileName: "src/field/Diff/converters/relationship/index.tsx",
|
|
59
|
-
lineNumber: 60,
|
|
60
|
-
columnNumber: 17
|
|
61
|
-
}, this)
|
|
62
|
-
}, void 0, false, {
|
|
63
|
-
fileName: "src/field/Diff/converters/relationship/index.tsx",
|
|
64
|
-
lineNumber: 59,
|
|
65
|
-
columnNumber: 15
|
|
66
|
-
}, this) : /*#__PURE__*/ _jsxDEV("strong", {
|
|
67
|
-
children: id
|
|
68
|
-
}, void 0, false, {
|
|
69
|
-
fileName: "src/field/Diff/converters/relationship/index.tsx",
|
|
70
|
-
lineNumber: 75,
|
|
71
|
-
columnNumber: 15
|
|
72
|
-
}, this)
|
|
73
|
-
]
|
|
74
|
-
}, void 0, true, {
|
|
75
|
-
fileName: "src/field/Diff/converters/relationship/index.tsx",
|
|
76
|
-
lineNumber: 48,
|
|
77
|
-
columnNumber: 11
|
|
78
|
-
}, this)
|
|
79
|
-
}, void 0, false, {
|
|
80
|
-
fileName: "src/field/Diff/converters/relationship/index.tsx",
|
|
81
|
-
lineNumber: 42,
|
|
82
|
-
columnNumber: 9
|
|
83
|
-
}, this);
|
|
24
|
+
const JSX = <div className={`${baseClass}${providedCSSString}`} data-enable-match="true" data-id={id} data-slug={node.relationTo}>
|
|
25
|
+
<div className={`${baseClass}__card`}>
|
|
26
|
+
<div className={`${baseClass}__collectionLabel`}>
|
|
27
|
+
{i18n.t('fields:labelRelationship', {
|
|
28
|
+
label: relatedCollection?.labels?.singular ? getTranslation(relatedCollection?.labels?.singular, i18n) : relatedCollection?.slug
|
|
29
|
+
})}
|
|
30
|
+
</div>
|
|
31
|
+
{data && relatedCollection?.admin?.useAsTitle && data[relatedCollection.admin.useAsTitle] ? <strong className={`${baseClass}__title`} data-enable-match="false">
|
|
32
|
+
<a className={`${baseClass}__link`} data-enable-match="false" href={formatAdminURL({
|
|
33
|
+
adminRoute: req.payload.config.routes.admin,
|
|
34
|
+
path: `/collections/${relatedCollection?.slug}/${data.id}`,
|
|
35
|
+
serverURL: req.payload.config.serverURL
|
|
36
|
+
})} rel="noopener noreferrer" target="_blank">
|
|
37
|
+
{data[relatedCollection.admin.useAsTitle]}
|
|
38
|
+
</a>
|
|
39
|
+
</strong> : <strong>{id}</strong>}
|
|
40
|
+
</div>
|
|
41
|
+
</div>;
|
|
84
42
|
// Render to HTML
|
|
85
43
|
const html = ReactDOMServer.renderToStaticMarkup(JSX);
|
|
86
44
|
return html;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/Diff/converters/relationship/index.tsx"],"sourcesContent":["import type { FileData, PayloadRequest, TypeWithID } from 'payload'\n\nimport { getTranslation, type I18nClient } from '@payloadcms/translations'\n\nimport './index.scss'\n\nimport { formatAdminURL } from 'payload/shared'\n\nimport type { HTMLConvertersAsync } from '../../../../features/converters/lexicalToHtml/async/types.js'\nimport type { SerializedRelationshipNode } from '../../../../nodeTypes.js'\n\nconst baseClass = 'lexical-relationship-diff'\n\nexport const RelationshipDiffHTMLConverterAsync: (args: {\n i18n: I18nClient\n req: PayloadRequest\n}) => HTMLConvertersAsync<SerializedRelationshipNode> = ({ i18n, req }) => {\n return {\n relationship: async ({ node, populate, providedCSSString }) => {\n let data: (Record<string, any> & TypeWithID) | undefined = undefined\n\n const id = typeof node.value === 'object' ? node.value.id : node.value\n\n // If there's no valid upload data, populate return an empty string\n if (typeof node.value !== 'object') {\n if (!populate) {\n return ''\n }\n data = await populate<FileData & TypeWithID>({\n id,\n collectionSlug: node.relationTo,\n })\n } else {\n data = node.value as unknown as FileData & TypeWithID\n }\n\n const relatedCollection = req.payload.collections[node.relationTo]?.config\n\n const ReactDOMServer = (await import('react-dom/server')).default\n\n const JSX = (\n <div\n className={`${baseClass}${providedCSSString}`}\n data-enable-match=\"true\"\n data-id={id}\n data-slug={node.relationTo}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__collectionLabel`}>\n {i18n.t('fields:labelRelationship', {\n label: relatedCollection?.labels?.singular\n ? getTranslation(relatedCollection?.labels?.singular, i18n)\n : relatedCollection?.slug,\n })}\n </div>\n {data &&\n relatedCollection?.admin?.useAsTitle &&\n data[relatedCollection.admin.useAsTitle] ? (\n <strong className={`${baseClass}__title`} data-enable-match=\"false\">\n <a\n className={`${baseClass}__link`}\n data-enable-match=\"false\"\n href={formatAdminURL({\n adminRoute: req.payload.config.routes.admin,\n path: `/collections/${relatedCollection?.slug}/${data.id}`,\n serverURL: req.payload.config.serverURL,\n })}\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {data[relatedCollection.admin.useAsTitle]}\n </a>\n </strong>\n ) : (\n <strong>{id as string}</strong>\n )}\n </div>\n </div>\n )\n\n // Render to HTML\n const html = ReactDOMServer.renderToStaticMarkup(JSX)\n\n return html\n },\n }\n}\n"],"names":["getTranslation","formatAdminURL","baseClass","RelationshipDiffHTMLConverterAsync","i18n","req","relationship","node","populate","providedCSSString","data","undefined","id","value","collectionSlug","relationTo","relatedCollection","payload","collections","config","ReactDOMServer","default","JSX","div","className","data-enable-match","data-id","data-slug","t","label","labels","singular","slug","admin","useAsTitle","strong","a","href","adminRoute","routes","path","serverURL","rel","target","html","renderToStaticMarkup"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/Diff/converters/relationship/index.tsx"],"sourcesContent":["import type { FileData, PayloadRequest, TypeWithID } from 'payload'\n\nimport { getTranslation, type I18nClient } from '@payloadcms/translations'\n\nimport './index.scss'\n\nimport { formatAdminURL } from 'payload/shared'\n\nimport type { HTMLConvertersAsync } from '../../../../features/converters/lexicalToHtml/async/types.js'\nimport type { SerializedRelationshipNode } from '../../../../nodeTypes.js'\n\nconst baseClass = 'lexical-relationship-diff'\n\nexport const RelationshipDiffHTMLConverterAsync: (args: {\n i18n: I18nClient\n req: PayloadRequest\n}) => HTMLConvertersAsync<SerializedRelationshipNode> = ({ i18n, req }) => {\n return {\n relationship: async ({ node, populate, providedCSSString }) => {\n let data: (Record<string, any> & TypeWithID) | undefined = undefined\n\n const id = typeof node.value === 'object' ? node.value.id : node.value\n\n // If there's no valid upload data, populate return an empty string\n if (typeof node.value !== 'object') {\n if (!populate) {\n return ''\n }\n data = await populate<FileData & TypeWithID>({\n id,\n collectionSlug: node.relationTo,\n })\n } else {\n data = node.value as unknown as FileData & TypeWithID\n }\n\n const relatedCollection = req.payload.collections[node.relationTo]?.config\n\n const ReactDOMServer = (await import('react-dom/server')).default\n\n const JSX = (\n <div\n className={`${baseClass}${providedCSSString}`}\n data-enable-match=\"true\"\n data-id={id}\n data-slug={node.relationTo}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__collectionLabel`}>\n {i18n.t('fields:labelRelationship', {\n label: relatedCollection?.labels?.singular\n ? getTranslation(relatedCollection?.labels?.singular, i18n)\n : relatedCollection?.slug,\n })}\n </div>\n {data &&\n relatedCollection?.admin?.useAsTitle &&\n data[relatedCollection.admin.useAsTitle] ? (\n <strong className={`${baseClass}__title`} data-enable-match=\"false\">\n <a\n className={`${baseClass}__link`}\n data-enable-match=\"false\"\n href={formatAdminURL({\n adminRoute: req.payload.config.routes.admin,\n path: `/collections/${relatedCollection?.slug}/${data.id}`,\n serverURL: req.payload.config.serverURL,\n })}\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {data[relatedCollection.admin.useAsTitle]}\n </a>\n </strong>\n ) : (\n <strong>{id as string}</strong>\n )}\n </div>\n </div>\n )\n\n // Render to HTML\n const html = ReactDOMServer.renderToStaticMarkup(JSX)\n\n return html\n },\n }\n}\n"],"names":["getTranslation","formatAdminURL","baseClass","RelationshipDiffHTMLConverterAsync","i18n","req","relationship","node","populate","providedCSSString","data","undefined","id","value","collectionSlug","relationTo","relatedCollection","payload","collections","config","ReactDOMServer","default","JSX","div","className","data-enable-match","data-id","data-slug","t","label","labels","singular","slug","admin","useAsTitle","strong","a","href","adminRoute","routes","path","serverURL","rel","target","html","renderToSta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kBAAkBiB,KAAK,CAACC,UAAU,CAAC,IACrCC,OAAOX,WAAW,GAAGtB,UAAU,OAAO,CAAC,EAAEuB,kBAAkB,QAAQ;gBAClE,CAACW,EACCZ,WAAW,GAAGtB,UAAU,MAAM,CAAC,EAC/BuB,kBAAkB,QAClBY,MAAMpC,eAAe;gBACnBqC,YAAYjC,IAAIY,OAAO,CAACE,MAAM,CAACoB,MAAM,CAACN,KAAK;gBAC3CO,MAAM,CAAC,aAAa,EAAExB,mBAAmBgB,KAAK,CAAC,EAAEtB,KAAKE,EAAE,EAAE;gBAC1D6B,WAAWpC,IAAIY,OAAO,CAACE,MAAM,CAACsB,SAAS;YACzC,IACAC,IAAI,sBACJC,OAAO,SACR;kBACC,CAACjC,IAAI,CAACM,kBAAkBiB,KAAK,CAACC,UAAU,CAAC,CAAC;gBAC5C,EAAEE,EAAE;cACN,EAAED,WAEDA,QAAQvB,KAAeuB,QACxB;UACJ,EAAEZ,IAAI;QACR,EAAEA;YAGJ,iBAAiB;YACjB,MAAMqB,OAAOxB,eAAeyB,oBAAoB,CAACvB;YAEjD,OAAOsB;QACT;IACF;AACF,EAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
2
1
|
import './index.scss';
|
|
3
2
|
import { createHash } from 'crypto';
|
|
4
3
|
const baseClass = 'lexical-unknown-diff';
|
|
@@ -17,47 +16,13 @@ export const UnknownDiffHTMLConverterAsync = ({ i18n, req })=>{
|
|
|
17
16
|
nodeTypeSpecifier = node.fields.blockType;
|
|
18
17
|
nodeType = 'InlineBlock';
|
|
19
18
|
}
|
|
20
|
-
const JSX =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
children: [
|
|
28
|
-
nodeTypeSpecifier,
|
|
29
|
-
" "
|
|
30
|
-
]
|
|
31
|
-
}, void 0, true, {
|
|
32
|
-
fileName: "src/field/Diff/converters/unknown/index.tsx",
|
|
33
|
-
lineNumber: 47,
|
|
34
|
-
columnNumber: 13
|
|
35
|
-
}, this),
|
|
36
|
-
/*#__PURE__*/ _jsxDEV("span", {
|
|
37
|
-
children: nodeType
|
|
38
|
-
}, void 0, false, {
|
|
39
|
-
fileName: "src/field/Diff/converters/unknown/index.tsx",
|
|
40
|
-
lineNumber: 49,
|
|
41
|
-
columnNumber: 11
|
|
42
|
-
}, this),
|
|
43
|
-
/*#__PURE__*/ _jsxDEV("div", {
|
|
44
|
-
className: `${baseClass}__meta`,
|
|
45
|
-
children: /*#__PURE__*/ _jsxDEV("br", {}, void 0, false, {
|
|
46
|
-
fileName: "src/field/Diff/converters/unknown/index.tsx",
|
|
47
|
-
lineNumber: 51,
|
|
48
|
-
columnNumber: 13
|
|
49
|
-
}, this)
|
|
50
|
-
}, void 0, false, {
|
|
51
|
-
fileName: "src/field/Diff/converters/unknown/index.tsx",
|
|
52
|
-
lineNumber: 50,
|
|
53
|
-
columnNumber: 11
|
|
54
|
-
}, this)
|
|
55
|
-
]
|
|
56
|
-
}, void 0, true, {
|
|
57
|
-
fileName: "src/field/Diff/converters/unknown/index.tsx",
|
|
58
|
-
lineNumber: 41,
|
|
59
|
-
columnNumber: 9
|
|
60
|
-
}, this);
|
|
19
|
+
const JSX = <div className={`${baseClass}${providedCSSString}`} data-enable-match="true" data-fields-hash={`${nodeFieldsHash}`}>
|
|
20
|
+
{nodeTypeSpecifier && <span className={`${baseClass}__specifier`}>{nodeTypeSpecifier} </span>}
|
|
21
|
+
<span>{nodeType}</span>
|
|
22
|
+
<div className={`${baseClass}__meta`}>
|
|
23
|
+
<br/>
|
|
24
|
+
</div>
|
|
25
|
+
</div>;
|
|
61
26
|
// Render to HTML
|
|
62
27
|
const html = ReactDOMServer.renderToStaticMarkup(JSX);
|
|
63
28
|
return html;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/Diff/converters/unknown/index.tsx"],"sourcesContent":["import type { LexicalNode } from 'lexical'\nimport type { PayloadRequest } from 'payload'\n\nimport { type I18nClient } from '@payloadcms/translations'\n\nimport './index.scss'\n\nimport { createHash } from 'crypto'\n\nimport type { HTMLConvertersAsync } from '../../../../features/converters/lexicalToHtml/async/types.js'\nimport type { SerializedBlockNode } from '../../../../nodeTypes.js'\n\nconst baseClass = 'lexical-unknown-diff'\n\nexport const UnknownDiffHTMLConverterAsync: (args: {\n i18n: I18nClient\n req: PayloadRequest\n}) => HTMLConvertersAsync<LexicalNode> = ({ i18n, req }) => {\n return {\n unknown: async ({ node, providedCSSString }) => {\n const ReactDOMServer = (await import('react-dom/server')).default\n\n // hash fields to ensure they are diffed if they change\n const nodeFieldsHash = createHash('sha256')\n .update(JSON.stringify(node ?? {}))\n .digest('hex')\n\n let nodeType = node.type\n\n let nodeTypeSpecifier: null | string = null\n\n if (node.type === 'block') {\n nodeTypeSpecifier = (node as SerializedBlockNode).fields.blockType\n nodeType = 'Block'\n } else if (node.type === 'inlineBlock') {\n nodeTypeSpecifier = (node as SerializedBlockNode).fields.blockType\n nodeType = 'InlineBlock'\n }\n\n const JSX = (\n <div\n className={`${baseClass}${providedCSSString}`}\n data-enable-match=\"true\"\n data-fields-hash={`${nodeFieldsHash}`}\n >\n {nodeTypeSpecifier && (\n <span className={`${baseClass}__specifier`}>{nodeTypeSpecifier} </span>\n )}\n <span>{nodeType}</span>\n <div className={`${baseClass}__meta`}>\n <br />\n </div>\n </div>\n )\n\n // Render to HTML\n const html = ReactDOMServer.renderToStaticMarkup(JSX)\n\n return html\n },\n }\n}\n"],"names":["createHash","baseClass","UnknownDiffHTMLConverterAsync","i18n","req","unknown","node","providedCSSString","ReactDOMServer","default","nodeFieldsHash","update","JSON","stringify","digest","nodeType","type","nodeTypeSpecifier","fields","blockType","JSX","div","className","data-enable-match","data-fields-hash","span","br","html","renderToStaticMarkup"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/Diff/converters/unknown/index.tsx"],"sourcesContent":["import type { LexicalNode } from 'lexical'\nimport type { PayloadRequest } from 'payload'\n\nimport { type I18nClient } from '@payloadcms/translations'\n\nimport './index.scss'\n\nimport { createHash } from 'crypto'\n\nimport type { HTMLConvertersAsync } from '../../../../features/converters/lexicalToHtml/async/types.js'\nimport type { SerializedBlockNode } from '../../../../nodeTypes.js'\n\nconst baseClass = 'lexical-unknown-diff'\n\nexport const UnknownDiffHTMLConverterAsync: (args: {\n i18n: I18nClient\n req: PayloadRequest\n}) => HTMLConvertersAsync<LexicalNode> = ({ i18n, req }) => {\n return {\n unknown: async ({ node, providedCSSString }) => {\n const ReactDOMServer = (await import('react-dom/server')).default\n\n // hash fields to ensure they are diffed if they change\n const nodeFieldsHash = createHash('sha256')\n .update(JSON.stringify(node ?? {}))\n .digest('hex')\n\n let nodeType = node.type\n\n let nodeTypeSpecifier: null | string = null\n\n if (node.type === 'block') {\n nodeTypeSpecifier = (node as SerializedBlockNode).fields.blockType\n nodeType = 'Block'\n } else if (node.type === 'inlineBlock') {\n nodeTypeSpecifier = (node as SerializedBlockNode).fields.blockType\n nodeType = 'InlineBlock'\n }\n\n const JSX = (\n <div\n className={`${baseClass}${providedCSSString}`}\n data-enable-match=\"true\"\n data-fields-hash={`${nodeFieldsHash}`}\n >\n {nodeTypeSpecifier && (\n <span className={`${baseClass}__specifier`}>{nodeTypeSpecifier} </span>\n )}\n <span>{nodeType}</span>\n <div className={`${baseClass}__meta`}>\n <br />\n </div>\n </div>\n )\n\n // Render to HTML\n const html = ReactDOMServer.renderToStaticMarkup(JSX)\n\n return html\n },\n }\n}\n"],"names":["createHash","baseClass","UnknownDiffHTMLConverterAsync","i18n","req","unknown","node","providedCSSString","ReactDOMServer","default","nodeFieldsHash","update","JSON","stringify","digest","nodeType","type","nodeTypeSpecifier","fields","blockType","JSX","div","className","data-enable-match","data-fields-hash","span","br","html","renderToStaticMarkup"],"mappings":"AAKA,OAAO,eAAc;AAErB,SAASA,UAAU,QAAQ,SAAQ;AAKnC,MAAMC,YAAY;AAElB,OAAO,MAAMC,gCAG4B,CAAC,EAAEC,IAAI,EAAEC,GAAG,EAAE;IACrD,OAAO;QACLC,SAAS,OAAO,EAAEC,IAAI,EAAEC,iBAAiB,EAAE;YACzC,MAAMC,iBAAiB,AAAC,CAAA,MAAM,MAAM,CAAC,mBAAkB,EAAGC,OAAO;YAEjE,uDAAuD;YACvD,MAAMC,iBAAiBV,WAAW,UAC/BW,MAAM,CAACC,KAAKC,SAAS,CAACP,QAAQ,CAAC,IAC/BQ,MAAM,CAAC;YAEV,IAAIC,WAAWT,KAAKU,IAAI;YAExB,IAAIC,oBAAmC;YAEvC,IAAIX,KAAKU,IAAI,KAAK,SAAS;gBACzBC,oBAAoB,AAACX,KAA6BY,MAAM,CAACC,SAAS;gBAClEJ,WAAW;YACb,OAAO,IAAIT,KAAKU,IAAI,KAAK,eAAe;gBACtCC,oBAAoB,AAACX,KAA6BY,MAAM,CAACC,SAAS;gBAClEJ,WAAW;YACb;YAEA,MAAMK,OACHC,IACCC,WAAW,GAAGrB,YAAYM,mBAAmB,EAC7CgB,kBAAkB,OAClBC,kBAAkB,GAAGd,gBAAgB,EACtC;UACC,CAACO,sBACEQ,KAAKH,WAAW,GAAGrB,UAAU,WAAW,CAAC,GAAGgB,kBAAkB,MAAM,EAAEQ,MACvE;UACF,CAACA,MAAMV,WAAWU,KAAK;UACvB,CAACJ,IAAIC,WAAW,GAAGrB,UAAU,MAAM,CAAC,EAAE;YACpC,CAACyB,IAAK;UACR,EAAEL,IAAI;QACR,EAAEA;YAGJ,iBAAiB;YACjB,MAAMM,OAAOnB,eAAeoB,oBAAoB,CAACR;YAEjD,OAAOO;QACT;IACF;AACF,EAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
2
1
|
import { File } from '@payloadcms/ui/rsc';
|
|
3
2
|
import { createHash } from 'crypto';
|
|
4
3
|
import './index.scss';
|
|
@@ -30,96 +29,27 @@ export const UploadDiffHTMLConverterAsync = ({ i18n, req })=>{
|
|
|
30
29
|
const ReactDOMServer = (await import('react-dom/server')).default;
|
|
31
30
|
// hash fields to ensure they are diffed if they change
|
|
32
31
|
const nodeFieldsHash = createHash('sha256').update(JSON.stringify(node.fields ?? {})).digest('hex');
|
|
33
|
-
const JSX =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
55
|
-
lineNumber: 72,
|
|
56
|
-
columnNumber: 17
|
|
57
|
-
}, this)
|
|
58
|
-
}, void 0, false, {
|
|
59
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
60
|
-
lineNumber: 68,
|
|
61
|
-
columnNumber: 13
|
|
62
|
-
}, this),
|
|
63
|
-
/*#__PURE__*/ _jsxDEV("div", {
|
|
64
|
-
className: `${baseClass}__info`,
|
|
65
|
-
"data-enable-match": "false",
|
|
66
|
-
children: [
|
|
67
|
-
/*#__PURE__*/ _jsxDEV("strong", {
|
|
68
|
-
children: uploadDoc?.filename
|
|
69
|
-
}, void 0, false, {
|
|
70
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
71
|
-
lineNumber: 76,
|
|
72
|
-
columnNumber: 15
|
|
73
|
-
}, this),
|
|
74
|
-
/*#__PURE__*/ _jsxDEV("div", {
|
|
75
|
-
className: `${baseClass}__meta`,
|
|
76
|
-
children: [
|
|
77
|
-
formatFilesize(uploadDoc?.filesize),
|
|
78
|
-
typeof uploadDoc?.width === 'number' && typeof uploadDoc?.height === 'number' && /*#__PURE__*/ _jsxDEV(React.Fragment, {
|
|
79
|
-
children: [
|
|
80
|
-
" - ",
|
|
81
|
-
uploadDoc?.width,
|
|
82
|
-
"x",
|
|
83
|
-
uploadDoc?.height
|
|
84
|
-
]
|
|
85
|
-
}, void 0, true, {
|
|
86
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
87
|
-
lineNumber: 80,
|
|
88
|
-
columnNumber: 19
|
|
89
|
-
}, this),
|
|
90
|
-
uploadDoc?.mimeType && /*#__PURE__*/ _jsxDEV(React.Fragment, {
|
|
91
|
-
children: [
|
|
92
|
-
" - ",
|
|
93
|
-
uploadDoc?.mimeType
|
|
94
|
-
]
|
|
95
|
-
}, void 0, true, {
|
|
96
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
97
|
-
lineNumber: 86,
|
|
98
|
-
columnNumber: 19
|
|
99
|
-
}, this)
|
|
100
|
-
]
|
|
101
|
-
}, void 0, true, {
|
|
102
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
103
|
-
lineNumber: 77,
|
|
104
|
-
columnNumber: 15
|
|
105
|
-
}, this)
|
|
106
|
-
]
|
|
107
|
-
}, void 0, true, {
|
|
108
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
109
|
-
lineNumber: 75,
|
|
110
|
-
columnNumber: 13
|
|
111
|
-
}, this)
|
|
112
|
-
]
|
|
113
|
-
}, void 0, true, {
|
|
114
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
115
|
-
lineNumber: 67,
|
|
116
|
-
columnNumber: 11
|
|
117
|
-
}, this)
|
|
118
|
-
}, void 0, false, {
|
|
119
|
-
fileName: "src/field/Diff/converters/upload/index.tsx",
|
|
120
|
-
lineNumber: 58,
|
|
121
|
-
columnNumber: 9
|
|
122
|
-
}, this);
|
|
32
|
+
const JSX = <div className={`${baseClass}${providedCSSString}`} data-enable-match="true" data-fields-hash={`${nodeFieldsHash}`} data-filename={uploadDoc?.filename} data-lexical-upload-id={uploadNode.value} data-lexical-upload-relation-to={uploadNode.relationTo} data-src={thumbnailSRC}>
|
|
33
|
+
<div className={`${baseClass}__card`}>
|
|
34
|
+
<div className={`${baseClass}__thumbnail`}>
|
|
35
|
+
{thumbnailSRC?.length ? <img alt={uploadDoc?.filename} src={thumbnailSRC}/> : <File/>}
|
|
36
|
+
</div>
|
|
37
|
+
<div className={`${baseClass}__info`} data-enable-match="false">
|
|
38
|
+
<strong>{uploadDoc?.filename}</strong>
|
|
39
|
+
<div className={`${baseClass}__meta`}>
|
|
40
|
+
{formatFilesize(uploadDoc?.filesize)}
|
|
41
|
+
{typeof uploadDoc?.width === 'number' && typeof uploadDoc?.height === 'number' && <React.Fragment>
|
|
42
|
+
-
|
|
43
|
+
{uploadDoc?.width}x{uploadDoc?.height}
|
|
44
|
+
</React.Fragment>}
|
|
45
|
+
{uploadDoc?.mimeType && <React.Fragment>
|
|
46
|
+
-
|
|
47
|
+
{uploadDoc?.mimeType}
|
|
48
|
+
</React.Fragment>}
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</div>;
|
|
123
53
|
// Render to HTML
|
|
124
54
|
const html = ReactDOMServer.renderToStaticMarkup(JSX);
|
|
125
55
|
return html;
|