@payloadcms/richtext-lexical 3.57.0-canary.6 → 3.57.0-canary.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/component-VDJI45F2.js +2 -0
- package/dist/exports/client/component-VDJI45F2.js.map +7 -0
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +4 -4
- package/dist/features/upload/client/component/index.d.ts +2 -0
- package/dist/features/upload/client/component/index.d.ts.map +1 -1
- package/dist/features/upload/client/component/index.js +28 -24
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/features/upload/client/component/pending/index.d.ts +3 -0
- package/dist/features/upload/client/component/pending/index.d.ts.map +1 -0
- package/dist/features/upload/client/component/pending/index.js +14 -0
- package/dist/features/upload/client/component/pending/index.js.map +1 -0
- package/dist/features/upload/client/nodes/UploadNode.d.ts +2 -7
- package/dist/features/upload/client/nodes/UploadNode.d.ts.map +1 -1
- package/dist/features/upload/client/nodes/UploadNode.js +9 -27
- package/dist/features/upload/client/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/client/plugin/index.d.ts +6 -0
- package/dist/features/upload/client/plugin/index.d.ts.map +1 -1
- package/dist/features/upload/client/plugin/index.js +306 -23
- package/dist/features/upload/client/plugin/index.js.map +1 -1
- package/dist/features/upload/server/nodes/UploadNode.d.ts +16 -1
- package/dist/features/upload/server/nodes/UploadNode.d.ts.map +1 -1
- package/dist/features/upload/server/nodes/UploadNode.js +12 -39
- package/dist/features/upload/server/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/server/nodes/conversions.d.ts +6 -0
- package/dist/features/upload/server/nodes/conversions.d.ts.map +1 -0
- package/dist/features/upload/server/nodes/conversions.js +53 -0
- package/dist/features/upload/server/nodes/conversions.js.map +1 -0
- package/dist/field/bundled.css +1 -1
- package/package.json +7 -7
- package/dist/exports/client/component-3PENNOM3.js +0 -2
- package/dist/exports/client/component-3PENNOM3.js.map +0 -7
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { type ElementFormatType } from 'lexical';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { UploadData } from '../../server/nodes/UploadNode.js';
|
|
3
4
|
import './index.scss';
|
|
4
5
|
export type ElementProps = {
|
|
5
6
|
data: UploadData;
|
|
7
|
+
format?: ElementFormatType;
|
|
6
8
|
nodeKey: string;
|
|
7
9
|
};
|
|
8
10
|
export declare const UploadComponent: (props: ElementProps) => React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/upload/client/component/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/upload/client/component/index.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE/D,OAAO,KAA2D,MAAM,OAAO,CAAA;AAG/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAUlE,OAAO,cAAc,CAAA;AAQrB,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AA6MD,eAAO,MAAM,eAAe,UAAW,YAAY,KAAG,KAAK,CAAC,SAM3D,CAAA"}
|
|
@@ -112,37 +112,35 @@ const Component = props => {
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
}, [editor, nodeKey]);
|
|
115
|
+
const aspectRatio = thumbnailSRC && data?.width && data?.height ? data.width > data.height ? 'landscape' : 'portrait' : 'landscape';
|
|
115
116
|
return /*#__PURE__*/_jsxs("div", {
|
|
116
|
-
className: baseClass
|
|
117
|
-
|
|
117
|
+
className: `${baseClass} ${baseClass}--${aspectRatio}`,
|
|
118
|
+
"data-filename": data?.filename,
|
|
118
119
|
ref: uploadRef,
|
|
119
120
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
120
121
|
className: `${baseClass}__card`,
|
|
121
122
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
122
|
-
className: `${baseClass}
|
|
123
|
-
children: [/*#__PURE__*/_jsx(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}), /*#__PURE__*/
|
|
130
|
-
className: `${baseClass}
|
|
131
|
-
children:
|
|
132
|
-
className: `${baseClass}__collectionLabel`,
|
|
133
|
-
children: getTranslation(relatedCollection.labels.singular, i18n)
|
|
134
|
-
}), editor.isEditable() && /*#__PURE__*/_jsxs("div", {
|
|
123
|
+
className: `${baseClass}__media`,
|
|
124
|
+
children: [/*#__PURE__*/_jsx(Thumbnail, {
|
|
125
|
+
collectionSlug: relationTo,
|
|
126
|
+
fileSrc: isImage(data?.mimeType) ? thumbnailSRC : null,
|
|
127
|
+
height: data?.height,
|
|
128
|
+
size: "none",
|
|
129
|
+
width: data?.width
|
|
130
|
+
}), editor.isEditable() && /*#__PURE__*/_jsx("div", {
|
|
131
|
+
className: `${baseClass}__overlay ${baseClass}__floater`,
|
|
132
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
135
133
|
className: `${baseClass}__actions`,
|
|
134
|
+
role: "toolbar",
|
|
136
135
|
children: [hasExtraFields ? /*#__PURE__*/_jsx(Button, {
|
|
137
136
|
buttonStyle: "icon-label",
|
|
138
137
|
className: `${baseClass}__upload-drawer-toggler`,
|
|
139
138
|
disabled: readOnly,
|
|
140
139
|
el: "button",
|
|
141
140
|
icon: "edit",
|
|
142
|
-
onClick:
|
|
143
|
-
toggleDrawer();
|
|
144
|
-
},
|
|
141
|
+
onClick: toggleDrawer,
|
|
145
142
|
round: true,
|
|
143
|
+
size: "medium",
|
|
146
144
|
tooltip: t('fields:editRelationship')
|
|
147
145
|
}) : null, /*#__PURE__*/_jsx(Button, {
|
|
148
146
|
buttonStyle: "icon-label",
|
|
@@ -158,6 +156,7 @@ const Component = props => {
|
|
|
158
156
|
});
|
|
159
157
|
},
|
|
160
158
|
round: true,
|
|
159
|
+
size: "medium",
|
|
161
160
|
tooltip: t('fields:swapUpload')
|
|
162
161
|
}), /*#__PURE__*/_jsx(Button, {
|
|
163
162
|
buttonStyle: "icon-label",
|
|
@@ -169,18 +168,23 @@ const Component = props => {
|
|
|
169
168
|
removeUpload();
|
|
170
169
|
},
|
|
171
170
|
round: true,
|
|
171
|
+
size: "medium",
|
|
172
172
|
tooltip: t('fields:removeUpload')
|
|
173
173
|
})]
|
|
174
|
-
})
|
|
174
|
+
})
|
|
175
175
|
})]
|
|
176
|
-
}), /*#__PURE__*/
|
|
177
|
-
className: `${baseClass}
|
|
178
|
-
children: /*#__PURE__*/_jsx(DocumentDrawerToggler, {
|
|
176
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
177
|
+
className: `${baseClass}__metaOverlay ${baseClass}__floater`,
|
|
178
|
+
children: [/*#__PURE__*/_jsx(DocumentDrawerToggler, {
|
|
179
179
|
className: `${baseClass}__doc-drawer-toggler`,
|
|
180
180
|
children: /*#__PURE__*/_jsx("strong", {
|
|
181
|
-
|
|
181
|
+
className: `${baseClass}__filename`,
|
|
182
|
+
children: data?.filename || t('general:untitled')
|
|
182
183
|
})
|
|
183
|
-
})
|
|
184
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
185
|
+
className: `${baseClass}__collectionLabel`,
|
|
186
|
+
children: getTranslation(relatedCollection.labels.singular, i18n)
|
|
187
|
+
})]
|
|
184
188
|
})]
|
|
185
189
|
}), value ? /*#__PURE__*/_jsx(DocumentDrawer, {
|
|
186
190
|
onSave: updateUpload
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useLexicalComposerContext","getTranslation","Button","formatDrawerSlug","Thumbnail","useConfig","useEditDepth","usePayloadAPI","useTranslation","$getNodeByKey","isImage","React","useCallback","useId","useReducer","useRef","useState","useEditorConfigContext","FieldsDrawer","useLexicalDocumentDrawer","useLexicalDrawer","EnabledRelationshipsCondition","INSERT_UPLOAD_WITH_DRAWER_COMMAND","baseClass","initialParams","depth","Component","props","data","fields","relationTo","value","nodeKey","Error","config","routes","api","serverURL","getEntityConfig","uploadRef","uuid","editDepth","editor","editorConfig","fieldProps","readOnly","schemaPath","i18n","t","cacheBust","dispatchCacheBust","state","relatedCollection","collectionSlug","componentID","extraFieldsDrawerSlug","slug","toggleDrawer","closeDocumentDrawer","DocumentDrawer","DocumentDrawerToggler","id","setParams","thumbnailSRC","thumbnailURL","url","removeUpload","update","remove","updateUpload","hasExtraFields","resolvedFeatureMap","get","sanitizedClientFeatureProps","collections","onExtraFieldsDrawerSubmit","_","uploadNode","newData","getData","setData","_jsxs","className","contentEditable","ref","_jsx","fileSrc","mimeType","labels","singular","isEditable","buttonStyle","disabled","el","icon","onClick","round","tooltip","dispatchCommand","replace","e","preventDefault","filename","onSave","drawerSlug","drawerTitle","label","featureKey","handleDrawerSubmit","schemaPathSuffix","UploadComponent","uploads"],"sources":["../../../../../src/features/upload/client/component/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientCollectionConfig, Data, FormState, JsonObject } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n formatDrawerSlug,\n Thumbnail,\n useConfig,\n useEditDepth,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport { $getNodeByKey } from 'lexical'\nimport { isImage } from 'payload/shared'\nimport React, { useCallback, useId, useReducer, useRef, useState } from 'react'\n\nimport type { BaseClientFeatureProps } from '../../../typesClient.js'\nimport type { UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\nimport type { UploadNode } from '../nodes/UploadNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { EnabledRelationshipsCondition } from '../../../relationship/client/utils/EnabledRelationshipsCondition.js'\nimport { INSERT_UPLOAD_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nexport type ElementProps = {\n data: UploadData\n nodeKey: string\n}\n\nconst Component: React.FC<ElementProps> = (props) => {\n const {\n data: { fields, relationTo, value },\n nodeKey,\n } = props\n\n if (typeof value === 'object') {\n throw new Error(\n 'Upload value should be a string or number. The Lexical Upload component should not receive the populated value object.',\n )\n }\n\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n const uploadRef = useRef<HTMLDivElement | null>(null)\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n const [editor] = useLexicalComposerContext()\n\n const {\n editorConfig,\n fieldProps: { readOnly, schemaPath },\n } = useEditorConfigContext()\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection] = useState<ClientCollectionConfig>(() =>\n getEntityConfig({ collectionSlug: relationTo }),\n )\n\n const componentID = useId()\n\n const extraFieldsDrawerSlug = formatDrawerSlug({\n slug: `lexical-upload-drawer-` + uuid + componentID, // There can be multiple upload components, each with their own drawer, in one single editor => separate them by componentID\n depth: editDepth,\n })\n\n // Need to use hook to initialize useEffect that restores cursor position\n const { toggleDrawer } = useLexicalDrawer(extraFieldsDrawerSlug, true)\n\n const { closeDocumentDrawer, DocumentDrawer, DocumentDrawerToggler } = useLexicalDocumentDrawer({\n id: value,\n collectionSlug: relatedCollection.slug,\n })\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const updateUpload = useCallback(\n (data: Data) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDocumentDrawer()\n },\n [setParams, cacheBust, closeDocumentDrawer],\n )\n\n const hasExtraFields = (\n editorConfig?.resolvedFeatureMap?.get('upload')\n ?.sanitizedClientFeatureProps as BaseClientFeatureProps<UploadFeaturePropsClient>\n ).collections?.[relatedCollection.slug]?.hasExtraFields\n\n const onExtraFieldsDrawerSubmit = useCallback(\n (_: FormState, data: JsonObject) => {\n // Update lexical node (with key nodeKey) with new data\n editor.update(() => {\n const uploadNode: null | UploadNode = $getNodeByKey(nodeKey)\n if (uploadNode) {\n const newData: UploadData = {\n ...uploadNode.getData(),\n fields: data,\n }\n uploadNode.setData(newData)\n }\n })\n },\n [editor, nodeKey],\n )\n\n return (\n <div className={baseClass} contentEditable={false} ref={uploadRef}>\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__topRow`}>\n <div className={`${baseClass}__thumbnail`}>\n <Thumbnail\n collectionSlug={relationTo}\n fileSrc={isImage(data?.mimeType) ? thumbnailSRC : null}\n />\n </div>\n <div className={`${baseClass}__topRowRightPanel`}>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n {hasExtraFields ? (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={readOnly}\n el=\"button\"\n icon=\"edit\"\n onClick={() => {\n toggleDrawer()\n }}\n round\n tooltip={t('fields:editRelationship')}\n />\n ) : null}\n\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swap-drawer-toggler`}\n disabled={readOnly}\n el=\"button\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_UPLOAD_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapUpload')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n tooltip={t('fields:removeUpload')}\n />\n </div>\n )}\n </div>\n </div>\n <div className={`${baseClass}__bottomRow`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong>{data?.filename}</strong>\n </DocumentDrawerToggler>\n </div>\n </div>\n {value ? <DocumentDrawer onSave={updateUpload} /> : null}\n {hasExtraFields ? (\n <FieldsDrawer\n data={fields}\n drawerSlug={extraFieldsDrawerSlug}\n drawerTitle={t('general:editLabel', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n featureKey=\"upload\"\n handleDrawerSubmit={onExtraFieldsDrawerSubmit}\n schemaPath={schemaPath}\n schemaPathSuffix={relatedCollection.slug}\n />\n ) : null}\n </div>\n )\n}\n\nexport const UploadComponent = (props: ElementProps): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <Component {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,cAAc,QAAQ;AAC/B,SACEC,MAAM,EACNC,gBAAgB,EAChBC,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,aAAa,EACbC,cAAc,QACT;AACP,SAASC,aAAa,QAAQ;AAC9B,SAASC,OAAO,QAAQ;AACxB,OAAOC,KAAA,IAASC,WAAW,EAAEC,KAAK,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAOxE,SAASC,sBAAsB,QAAQ;AACvC,SAASC,YAAY,QAAQ;AAC7B,SAASC,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OAAO;cAC/C,aAAA1B,IAAA,CAAC3D,SAAA;MAAW,GAAGC;;;AAGrB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["useLexicalComposerContext","getTranslation","Button","formatDrawerSlug","Thumbnail","useConfig","useEditDepth","usePayloadAPI","useTranslation","$getNodeByKey","isImage","React","useCallback","useId","useReducer","useRef","useState","useEditorConfigContext","FieldsDrawer","useLexicalDocumentDrawer","useLexicalDrawer","EnabledRelationshipsCondition","INSERT_UPLOAD_WITH_DRAWER_COMMAND","baseClass","initialParams","depth","Component","props","data","fields","relationTo","value","nodeKey","Error","config","routes","api","serverURL","getEntityConfig","uploadRef","uuid","editDepth","editor","editorConfig","fieldProps","readOnly","schemaPath","i18n","t","cacheBust","dispatchCacheBust","state","relatedCollection","collectionSlug","componentID","extraFieldsDrawerSlug","slug","toggleDrawer","closeDocumentDrawer","DocumentDrawer","DocumentDrawerToggler","id","setParams","thumbnailSRC","thumbnailURL","url","removeUpload","update","remove","updateUpload","hasExtraFields","resolvedFeatureMap","get","sanitizedClientFeatureProps","collections","onExtraFieldsDrawerSubmit","_","uploadNode","newData","getData","setData","aspectRatio","width","height","_jsxs","className","filename","ref","_jsx","fileSrc","mimeType","size","isEditable","role","buttonStyle","disabled","el","icon","onClick","round","tooltip","dispatchCommand","replace","e","preventDefault","labels","singular","onSave","drawerSlug","drawerTitle","label","featureKey","handleDrawerSubmit","schemaPathSuffix","UploadComponent","uploads"],"sources":["../../../../../src/features/upload/client/component/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientCollectionConfig, Data, FormState, JsonObject } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n formatDrawerSlug,\n Thumbnail,\n useConfig,\n useEditDepth,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport { $getNodeByKey, type ElementFormatType } from 'lexical'\nimport { isImage } from 'payload/shared'\nimport React, { useCallback, useId, useReducer, useRef, useState } from 'react'\n\nimport type { BaseClientFeatureProps } from '../../../typesClient.js'\nimport type { UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\nimport type { UploadNode } from '../nodes/UploadNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { EnabledRelationshipsCondition } from '../../../relationship/client/utils/EnabledRelationshipsCondition.js'\nimport { INSERT_UPLOAD_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nexport type ElementProps = {\n data: UploadData\n format?: ElementFormatType\n nodeKey: string\n}\n\nconst Component: React.FC<ElementProps> = (props) => {\n const {\n data: { fields, relationTo, value },\n nodeKey,\n } = props\n\n if (typeof value === 'object') {\n throw new Error(\n 'Upload value should be a string or number. The Lexical Upload component should not receive the populated value object.',\n )\n }\n\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n const uploadRef = useRef<HTMLDivElement | null>(null)\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n const [editor] = useLexicalComposerContext()\n\n const {\n editorConfig,\n fieldProps: { readOnly, schemaPath },\n } = useEditorConfigContext()\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection] = useState<ClientCollectionConfig>(() =>\n getEntityConfig({ collectionSlug: relationTo }),\n )\n\n const componentID = useId()\n\n const extraFieldsDrawerSlug = formatDrawerSlug({\n slug: `lexical-upload-drawer-` + uuid + componentID, // There can be multiple upload components, each with their own drawer, in one single editor => separate them by componentID\n depth: editDepth,\n })\n\n // Need to use hook to initialize useEffect that restores cursor position\n const { toggleDrawer } = useLexicalDrawer(extraFieldsDrawerSlug, true)\n\n const { closeDocumentDrawer, DocumentDrawer, DocumentDrawerToggler } = useLexicalDocumentDrawer({\n id: value,\n collectionSlug: relatedCollection.slug,\n })\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const updateUpload = useCallback(\n (data: Data) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDocumentDrawer()\n },\n [setParams, cacheBust, closeDocumentDrawer],\n )\n\n const hasExtraFields = (\n editorConfig?.resolvedFeatureMap?.get('upload')\n ?.sanitizedClientFeatureProps as BaseClientFeatureProps<UploadFeaturePropsClient>\n ).collections?.[relatedCollection.slug]?.hasExtraFields\n\n const onExtraFieldsDrawerSubmit = useCallback(\n (_: FormState, data: JsonObject) => {\n // Update lexical node (with key nodeKey) with new data\n editor.update(() => {\n const uploadNode: null | UploadNode = $getNodeByKey(nodeKey)\n if (uploadNode) {\n const newData: UploadData = {\n ...uploadNode.getData(),\n fields: data,\n }\n uploadNode.setData(newData)\n }\n })\n },\n [editor, nodeKey],\n )\n\n const aspectRatio =\n thumbnailSRC && data?.width && data?.height\n ? data.width > data.height\n ? 'landscape'\n : 'portrait'\n : 'landscape'\n\n return (\n <div\n className={`${baseClass} ${baseClass}--${aspectRatio}`}\n data-filename={data?.filename}\n ref={uploadRef}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__media`}>\n <Thumbnail\n collectionSlug={relationTo}\n fileSrc={isImage(data?.mimeType) ? thumbnailSRC : null}\n height={data?.height}\n size=\"none\"\n width={data?.width}\n />\n\n {editor.isEditable() && (\n <div className={`${baseClass}__overlay ${baseClass}__floater`}>\n <div className={`${baseClass}__actions`} role=\"toolbar\">\n {hasExtraFields ? (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={readOnly}\n el=\"button\"\n icon=\"edit\"\n onClick={toggleDrawer}\n round\n size=\"medium\"\n tooltip={t('fields:editRelationship')}\n />\n ) : null}\n\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swap-drawer-toggler`}\n disabled={readOnly}\n el=\"button\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_UPLOAD_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n size=\"medium\"\n tooltip={t('fields:swapUpload')}\n />\n\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n size=\"medium\"\n tooltip={t('fields:removeUpload')}\n />\n </div>\n </div>\n )}\n </div>\n\n <div className={`${baseClass}__metaOverlay ${baseClass}__floater`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong className={`${baseClass}__filename`}>\n {data?.filename || t('general:untitled')}\n </strong>\n </DocumentDrawerToggler>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n </div>\n </div>\n\n {value ? <DocumentDrawer onSave={updateUpload} /> : null}\n {hasExtraFields ? (\n <FieldsDrawer\n data={fields}\n drawerSlug={extraFieldsDrawerSlug}\n drawerTitle={t('general:editLabel', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n featureKey=\"upload\"\n handleDrawerSubmit={onExtraFieldsDrawerSubmit}\n schemaPath={schemaPath}\n schemaPathSuffix={relatedCollection.slug}\n />\n ) : null}\n </div>\n )\n}\n\nexport const UploadComponent = (props: ElementProps): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <Component {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,cAAc,QAAQ;AAC/B,SACEC,MAAM,EACNC,gBAAgB,EAChBC,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,aAAa,EACbC,cAAc,QACT;AACP,SAASC,aAAa,QAAgC;AACtD,SAASC,OAAO,QAAQ;AACxB,OAAOC,KAAA,IAASC,WAAW,EAAEC,KAAK,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAOxE,SAASC,sBAAsB,QAAQ;AACvC,SAASC,YAAY,QAAQ;AAC7B,SAASC,wBAAwB,QAAQ;AACzC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,6BAA6B,QAAQ;AAC9C,SAASC,iCAAiC,QAAQ;AAGlD,MAAMC,SAAA,GAAY;AAElB,MAAMC,aAAA,GAAgB;EACpBC,KAAA,EAAO;AACT;AAQA,MAAMC,SAAA,GAAqCC,KAAA;EACzC,MAAM;IACJC,IAAA,EAAM;MAAEC,MAAM;MAAEC,UAAU;MAAEC;IAAK,CAAE;IACnCC;EAAO,CACR,GAAGL,KAAA;EAEJ,IAAI,OAAOI,KAAA,KAAU,UAAU;IAC7B,MAAM,IAAIE,KAAA,CACR;EAEJ;EAEA,MAAM;IACJC,MAAA,EAAQ;MACNC,MAAA,EAAQ;QAAEC;MAAG,CAAE;MACfC;IAAS,CACV;IACDC;EAAe,CAChB,GAAGjC,SAAA;EACJ,MAAMkC,SAAA,GAAYxB,MAAA,CAA8B;EAChD,MAAM;IAAEyB;EAAI,CAAE,GAAGvB,sBAAA;EACjB,MAAMwB,SAAA,GAAYnC,YAAA;EAClB,MAAM,CAACoC,MAAA,CAAO,GAAG1C,yBAAA;EAEjB,MAAM;IACJ2C,YAAY;IACZC,UAAA,EAAY;MAAEC,QAAQ;MAAEC;IAAU;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iE,IAAA,CAAC5B,qBAAA;UAAsByB,SAAA,EAAW,GAAG9D,SAAA,sBAA+B;oBAClE,aAAAiE,IAAA,CAAC;YAAOH,SAAA,EAAW,GAAG9D,SAAA,YAAqB;sBACxCK,IAAA,EAAM0D,QAAA,IAAYtC,CAAA,CAAE;;yBAGzBwC,IAAA,CAAC;UAAIH,SAAA,EAAW,GAAG9D,SAAA,mBAA4B;oBAC5CtB,cAAA,CAAemD,iBAAA,CAAkBqD,MAAM,CAACC,QAAQ,EAAE3D,IAAA;;;QAKxDhB,KAAA,gBAAQyD,IAAA,CAAC7B,cAAA;MAAegD,MAAA,EAAQtC;SAAmB,MACnDC,cAAA,gBACCkB,IAAA,CAACtE,YAAA;MACCU,IAAA,EAAMC,MAAA;MACN+E,UAAA,EAAYrD,qBAAA;MACZsD,WAAA,EAAa7D,CAAA,CAAE,qBAAqB;QAClC8D,KAAA,EAAO7G,cAAA,CAAemD,iBAAA,CAAkBqD,MAAM,CAACC,QAAQ,EAAE3D,IAAA;MAC3D;MACAgE,UAAA,EAAW;MACXC,kBAAA,EAAoBrC,yBAAA;MACpB7B,UAAA,EAAYA,UAAA;MACZmE,gBAAA,EAAkB7D,iBAAA,CAAkBI;SAEpC;;AAGV;AAEA,OAAO,MAAM0D,eAAA,GAAmBvF,KAAA;EAC9B,oBACE6D,IAAA,CAACnE,6BAAA;IAA+B,GAAGM,KAAK;IAAEwF,OAAO;cAC/C,aAAA3B,IAAA,CAAC9D,SAAA;MAAW,GAAGC;;;AAGrB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/upload/client/component/pending/index.tsx"],"names":[],"mappings":"AAIA,OAAO,eAAe,CAAA;AAEtB,eAAO,MAAM,sBAAsB,QAAO,KAAK,CAAC,SAM/C,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { ShimmerEffect } from '@payloadcms/ui';
|
|
5
|
+
export const PendingUploadComponent = () => {
|
|
6
|
+
return /*#__PURE__*/_jsx("div", {
|
|
7
|
+
className: 'lexical-upload',
|
|
8
|
+
children: /*#__PURE__*/_jsx(ShimmerEffect, {
|
|
9
|
+
height: '95px',
|
|
10
|
+
width: '203px'
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ShimmerEffect","PendingUploadComponent","_jsx","className","height","width"],"sources":["../../../../../../src/features/upload/client/component/pending/index.tsx"],"sourcesContent":["'use client'\n\nimport { ShimmerEffect } from '@payloadcms/ui'\n\nimport '../index.scss'\n\nexport const PendingUploadComponent = (): React.ReactNode => {\n return (\n <div className={'lexical-upload'}>\n <ShimmerEffect height={'95px'} width={'203px'} />\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAEA,SAASA,aAAa,QAAQ;AAI9B,OAAO,MAAMC,sBAAA,GAAyBA,CAAA;EACpC,oBACEC,IAAA,CAAC;IAAIC,SAAA,EAAW;cACd,aAAAD,IAAA,CAACF,aAAA;MAAcI,MAAA,EAAQ;MAAQC,KAAA,EAAO;;;AAG5C","ignoreList":[]}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DOMConversionMap, LexicalNode, Spread } from 'lexical';
|
|
1
|
+
import type { DOMConversionMap, LexicalNode } from 'lexical';
|
|
3
2
|
import type { JSX } from 'react';
|
|
4
|
-
import type { UploadData } from '../../server/nodes/UploadNode.js';
|
|
3
|
+
import type { SerializedUploadNode, UploadData } from '../../server/nodes/UploadNode.js';
|
|
5
4
|
import { UploadServerNode } from '../../server/nodes/UploadNode.js';
|
|
6
|
-
export type SerializedUploadNode = {
|
|
7
|
-
children?: never;
|
|
8
|
-
type: 'upload';
|
|
9
|
-
} & Spread<UploadData, SerializedDecoratorBlockNode>;
|
|
10
5
|
export declare class UploadNode extends UploadServerNode {
|
|
11
6
|
static clone(node: UploadServerNode): UploadServerNode;
|
|
12
7
|
static getType(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/upload/client/nodes/UploadNode.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"UploadNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/upload/client/nodes/UploadNode.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC5D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAMhC,OAAO,KAAK,EAEV,oBAAoB,EACpB,UAAU,EACX,MAAM,kCAAkC,CAAA;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AAOnE,qBAAa,UAAW,SAAQ,gBAAgB;WAC9B,KAAK,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB;WAI/C,OAAO,IAAI,MAAM;WAIjB,SAAS,IAAI,gBAAgB,CAAC,gBAAgB,CAAC;WAS/C,UAAU,CAAC,cAAc,EAAE,oBAAoB,GAAG,UAAU;IAuBnE,QAAQ,IAAI,GAAG,CAAC,OAAO;IAOvB,UAAU,IAAI,oBAAoB;CAG5C;AAED,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,GACL,EAAE;IACD,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAA;CAC/D,GAAG,UAAU,CAMb;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,IAAI,UAAU,CAEtF"}
|
|
@@ -4,35 +4,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
4
4
|
import ObjectID from 'bson-objectid';
|
|
5
5
|
import { $applyNodeReplacement } from 'lexical';
|
|
6
6
|
import * as React from 'react';
|
|
7
|
-
import {
|
|
7
|
+
import { $convertUploadElement } from '../../server/nodes/conversions.js';
|
|
8
|
+
import { UploadServerNode } from '../../server/nodes/UploadNode.js';
|
|
9
|
+
import { PendingUploadComponent } from '../component/pending/index.js';
|
|
8
10
|
const RawUploadComponent = /*#__PURE__*/React.lazy(() => import('../../client/component/index.js').then(module => ({
|
|
9
11
|
default: module.UploadComponent
|
|
10
12
|
})));
|
|
11
|
-
function $convertUploadElement(domNode) {
|
|
12
|
-
if (domNode.hasAttribute('data-lexical-upload-relation-to') && domNode.hasAttribute('data-lexical-upload-id')) {
|
|
13
|
-
const id = domNode.getAttribute('data-lexical-upload-id');
|
|
14
|
-
const relationTo = domNode.getAttribute('data-lexical-upload-relation-to');
|
|
15
|
-
if (id != null && relationTo != null) {
|
|
16
|
-
const node = $createUploadNode({
|
|
17
|
-
data: {
|
|
18
|
-
fields: {},
|
|
19
|
-
relationTo,
|
|
20
|
-
value: id
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return {
|
|
24
|
-
node
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const img = domNode;
|
|
29
|
-
if (img.src.startsWith('file:///') || isGoogleDocCheckboxImg(img)) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
// TODO: Auto-upload functionality here!
|
|
33
|
-
//}
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
13
|
export class UploadNode extends UploadServerNode {
|
|
37
14
|
static clone(node) {
|
|
38
15
|
return super.clone(node);
|
|
@@ -43,7 +20,7 @@ export class UploadNode extends UploadServerNode {
|
|
|
43
20
|
static importDOM() {
|
|
44
21
|
return {
|
|
45
22
|
img: node => ({
|
|
46
|
-
conversion: $convertUploadElement,
|
|
23
|
+
conversion: domNode => $convertUploadElement(domNode, $createUploadNode),
|
|
47
24
|
priority: 0
|
|
48
25
|
})
|
|
49
26
|
};
|
|
@@ -59,6 +36,7 @@ export class UploadNode extends UploadServerNode {
|
|
|
59
36
|
const importedData = {
|
|
60
37
|
id: serializedNode.id,
|
|
61
38
|
fields: serializedNode.fields,
|
|
39
|
+
pending: serializedNode.pending,
|
|
62
40
|
relationTo: serializedNode.relationTo,
|
|
63
41
|
value: serializedNode.value
|
|
64
42
|
};
|
|
@@ -69,8 +47,12 @@ export class UploadNode extends UploadServerNode {
|
|
|
69
47
|
return node;
|
|
70
48
|
}
|
|
71
49
|
decorate() {
|
|
50
|
+
if (this.__data.pending) {
|
|
51
|
+
return /*#__PURE__*/_jsx(PendingUploadComponent, {});
|
|
52
|
+
}
|
|
72
53
|
return /*#__PURE__*/_jsx(RawUploadComponent, {
|
|
73
54
|
data: this.__data,
|
|
55
|
+
format: this.__format,
|
|
74
56
|
nodeKey: this.getKey()
|
|
75
57
|
});
|
|
76
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadNode.js","names":["ObjectID","$applyNodeReplacement","React","
|
|
1
|
+
{"version":3,"file":"UploadNode.js","names":["ObjectID","$applyNodeReplacement","React","$convertUploadElement","UploadServerNode","PendingUploadComponent","RawUploadComponent","lazy","then","module","default","UploadComponent","UploadNode","clone","node","getType","importDOM","img","conversion","domNode","$createUploadNode","priority","importJSON","serializedNode","version","value","id","toHexString","importedData","fields","pending","relationTo","data","setFormat","format","decorate","__data","_jsx","__format","nodeKey","getKey","exportJSON","$isUploadNode"],"sources":["../../../../../src/features/upload/client/nodes/UploadNode.tsx"],"sourcesContent":["'use client'\nimport type { DOMConversionMap, LexicalNode } from 'lexical'\nimport type { JSX } from 'react'\n\nimport ObjectID from 'bson-objectid'\nimport { $applyNodeReplacement } from 'lexical'\nimport * as React from 'react'\n\nimport type {\n Internal_UploadData,\n SerializedUploadNode,\n UploadData,\n} from '../../server/nodes/UploadNode.js'\n\nimport { $convertUploadElement } from '../../server/nodes/conversions.js'\nimport { UploadServerNode } from '../../server/nodes/UploadNode.js'\nimport { PendingUploadComponent } from '../component/pending/index.js'\n\nconst RawUploadComponent = React.lazy(() =>\n import('../../client/component/index.js').then((module) => ({ default: module.UploadComponent })),\n)\n\nexport class UploadNode extends UploadServerNode {\n static override clone(node: UploadServerNode): UploadServerNode {\n return super.clone(node)\n }\n\n static override getType(): string {\n return super.getType()\n }\n\n static override importDOM(): DOMConversionMap<HTMLImageElement> {\n return {\n img: (node) => ({\n conversion: (domNode) => $convertUploadElement(domNode, $createUploadNode),\n priority: 0,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedUploadNode): UploadNode {\n if (serializedNode.version === 1 && (serializedNode?.value as unknown as { id: string })?.id) {\n serializedNode.value = (serializedNode.value as unknown as { id: string }).id\n }\n if (serializedNode.version === 2 && !serializedNode?.id) {\n serializedNode.id = new ObjectID.default().toHexString()\n serializedNode.version = 3\n }\n\n const importedData: 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 = $createUploadNode({ data: importedData })\n node.setFormat(serializedNode.format)\n\n return node\n }\n\n override decorate(): JSX.Element {\n if ((this.__data as Internal_UploadData).pending) {\n return <PendingUploadComponent />\n }\n return <RawUploadComponent data={this.__data} format={this.__format} nodeKey={this.getKey()} />\n }\n\n override exportJSON(): SerializedUploadNode {\n return super.exportJSON()\n }\n}\n\nexport function $createUploadNode({\n data,\n}: {\n data: Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>\n}): UploadNode {\n if (!data?.id) {\n data.id = new ObjectID.default().toHexString()\n }\n\n return $applyNodeReplacement(new UploadNode({ data: data as UploadData }))\n}\n\nexport function $isUploadNode(node: LexicalNode | null | undefined): node is UploadNode {\n return node instanceof UploadNode\n}\n"],"mappings":"AAAA;;;AAIA,OAAO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,CAAeQ,UAAU;MACrCN,KAAA,EAAOF,cAAA,CAAeE;IACxB;IAEA,MAAMX,IAAA,GAAOM,iBAAA,CAAkB;MAAEY,IAAA,EAAMJ;IAAa;IACpDd,IAAA,CAAKmB,SAAS,CAACV,cAAA,CAAeW,MAAM;IAEpC,OAAOpB,IAAA;EACT;EAESqB,SAAA,EAAwB;IAC/B,IAAI,IAAK,CAACC,MAAM,CAAyBN,OAAO,EAAE;MAChD,oBAAOO,IAAA,CAAChC,sBAAA;IACV;IACA,oBAAOgC,IAAA,CAAC/B,kBAAA;MAAmB0B,IAAA,EAAM,IAAI,CAACI,MAAM;MAAEF,MAAA,EAAQ,IAAI,CAACI,QAAQ;MAAEC,OAAA,EAAS,IAAI,CAACC,MAAM;;EAC3F;EAESC,WAAA,EAAmC;IAC1C,OAAO,KAAK,CAACA,UAAA;EACf;AACF;AAEA,OAAO,SAASrB,kBAAkB;EAChCY;AAAI,CAGL;EACC,IAAI,CAACA,IAAA,EAAMN,EAAA,EAAI;IACbM,IAAA,CAAKN,EAAE,GAAG,IAAI1B,QAAA,CAASU,OAAO,GAAGiB,WAAW;EAC9C;EAEA,OAAO1B,qBAAA,CAAsB,IAAIW,UAAA,CAAW;IAAEoB,IAAA,EAAMA;EAAmB;AACzE;AAEA,OAAO,SAASU,cAAc5B,IAAoC;EAChE,OAAOA,IAAA,YAAgBF,UAAA;AACzB","ignoreList":[]}
|
|
@@ -3,6 +3,12 @@ import type { PluginComponent } from '../../../typesClient.js';
|
|
|
3
3
|
import type { UploadData } from '../../server/nodes/UploadNode.js';
|
|
4
4
|
import type { UploadFeaturePropsClient } from '../index.js';
|
|
5
5
|
export type InsertUploadPayload = Readonly<Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>>;
|
|
6
|
+
declare global {
|
|
7
|
+
interface DragEvent {
|
|
8
|
+
rangeOffset?: number;
|
|
9
|
+
rangeParent?: Node;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
6
12
|
export declare const INSERT_UPLOAD_COMMAND: LexicalCommand<InsertUploadPayload>;
|
|
7
13
|
export declare const UploadPlugin: PluginComponent<UploadFeaturePropsClient>;
|
|
8
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/upload/client/plugin/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/upload/client/plugin/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAuB7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAuB,UAAU,EAAE,MAAM,kCAAkC,CAAA;AACvF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAK3D,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;AAEpG,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,SAAS;QACjB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,WAAW,CAAC,EAAE,IAAI,CAAA;KACnB;CACF;AA4BD,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAAC,mBAAmB,CAC9B,CAAA;AAYxC,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,wBAAwB,CA+TlE,CAAA"}
|