@payloadcms/richtext-lexical 3.57.0-internal.74d0404 → 3.57.0-internal.801ab5a
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/index.js +10 -10
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/client/pendingComponent-WFSCE6LJ.js +2 -0
- package/dist/exports/client/pendingComponent-WFSCE6LJ.js.map +7 -0
- package/dist/features/heading/client/index.d.ts.map +1 -1
- package/dist/features/heading/client/index.js +0 -60
- package/dist/features/heading/client/index.js.map +1 -1
- package/dist/features/heading/server/index.d.ts.map +1 -1
- package/dist/features/heading/server/index.js +0 -1
- package/dist/features/heading/server/index.js.map +1 -1
- package/dist/features/upload/client/index.d.ts.map +1 -1
- package/dist/features/upload/client/index.js +2 -1
- package/dist/features/upload/client/index.js.map +1 -1
- package/dist/features/upload/client/nodes/PendingUploadNode.d.ts +17 -0
- package/dist/features/upload/client/nodes/PendingUploadNode.d.ts.map +1 -0
- package/dist/features/upload/client/nodes/PendingUploadNode.js +57 -0
- package/dist/features/upload/client/nodes/PendingUploadNode.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 +3 -27
- package/dist/features/upload/client/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/client/pendingComponent/index.d.ts +7 -0
- package/dist/features/upload/client/pendingComponent/index.d.ts.map +1 -0
- package/dist/features/upload/client/pendingComponent/index.js +14 -0
- package/dist/features/upload/client/pendingComponent/index.js.map +1 -0
- 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 +292 -22
- package/dist/features/upload/client/plugin/index.js.map +1 -1
- package/dist/features/upload/server/index.d.ts.map +1 -1
- package/dist/features/upload/server/index.js +4 -1
- package/dist/features/upload/server/index.js.map +1 -1
- package/dist/features/upload/server/nodes/PendingUploadNode.d.ts +42 -0
- package/dist/features/upload/server/nodes/PendingUploadNode.d.ts.map +1 -0
- package/dist/features/upload/server/nodes/PendingUploadNode.js +92 -0
- package/dist/features/upload/server/nodes/PendingUploadNode.js.map +1 -0
- package/dist/features/upload/server/nodes/UploadNode.d.ts +0 -1
- package/dist/features/upload/server/nodes/UploadNode.d.ts.map +1 -1
- package/dist/features/upload/server/nodes/UploadNode.js +3 -37
- package/dist/features/upload/server/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/server/nodes/conversions.d.ts +9 -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 +6 -6
|
@@ -3,30 +3,166 @@
|
|
|
3
3
|
import { c as _c } from "react/compiler-runtime";
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
|
|
6
|
-
import { $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils';
|
|
7
|
-
import { useConfig } from '@payloadcms/ui';
|
|
8
|
-
import
|
|
6
|
+
import { $dfsIterator, $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils';
|
|
7
|
+
import { useBulkUpload, useConfig, useEffectEvent, useModal } from '@payloadcms/ui';
|
|
8
|
+
import ObjectID from 'bson-objectid';
|
|
9
|
+
import { $createRangeSelection, $getPreviousSelection, $getSelection, $isParagraphNode, $isRangeSelection, $setSelection, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, createCommand, DROP_COMMAND, getDOMSelectionFromTarget, isHTMLElement, PASTE_COMMAND } from 'lexical';
|
|
9
10
|
import React, { useEffect } from 'react';
|
|
10
11
|
import { UploadDrawer } from '../drawer/index.js';
|
|
12
|
+
import { $isPendingUploadNode, PendingUploadNode } from '../nodes/PendingUploadNode.js';
|
|
11
13
|
import { $createUploadNode, UploadNode } from '../nodes/UploadNode.js';
|
|
14
|
+
function canDropImage(event) {
|
|
15
|
+
const target = event.target;
|
|
16
|
+
return !!(isHTMLElement(target) && !target.closest('code, span.editor-image') && isHTMLElement(target.parentElement) && target.parentElement.closest('div.ContentEditable__root'));
|
|
17
|
+
}
|
|
18
|
+
function getDragSelection(event) {
|
|
19
|
+
// Source: https://github.com/AlessioGr/lexical/blob/main/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx
|
|
20
|
+
let range;
|
|
21
|
+
const domSelection = getDOMSelectionFromTarget(event.target);
|
|
22
|
+
if (document.caretRangeFromPoint) {
|
|
23
|
+
range = document.caretRangeFromPoint(event.clientX, event.clientY);
|
|
24
|
+
} else if (event.rangeParent && domSelection !== null) {
|
|
25
|
+
domSelection.collapse(event.rangeParent, event.rangeOffset || 0);
|
|
26
|
+
range = domSelection.getRangeAt(0);
|
|
27
|
+
} else {
|
|
28
|
+
throw Error(`Cannot get the selection when dragging`);
|
|
29
|
+
}
|
|
30
|
+
return range;
|
|
31
|
+
}
|
|
12
32
|
export const INSERT_UPLOAD_COMMAND = createCommand('INSERT_UPLOAD_COMMAND');
|
|
13
|
-
export const UploadPlugin =
|
|
14
|
-
const $ = _c(
|
|
33
|
+
export const UploadPlugin = () => {
|
|
34
|
+
const $ = _c(18);
|
|
15
35
|
const [editor] = useLexicalComposerContext();
|
|
16
36
|
const {
|
|
17
|
-
config:
|
|
37
|
+
config: t0
|
|
18
38
|
} = useConfig();
|
|
19
39
|
const {
|
|
20
40
|
collections
|
|
21
|
-
} =
|
|
41
|
+
} = t0;
|
|
42
|
+
const {
|
|
43
|
+
drawerSlug: bulkUploadDrawerSlug,
|
|
44
|
+
setCollectionSlug,
|
|
45
|
+
setInitialForms,
|
|
46
|
+
setOnCancel,
|
|
47
|
+
setOnSuccess,
|
|
48
|
+
setSelectableCollections
|
|
49
|
+
} = useBulkUpload();
|
|
50
|
+
const {
|
|
51
|
+
isModalOpen,
|
|
52
|
+
openModal
|
|
53
|
+
} = useModal();
|
|
54
|
+
let t1;
|
|
55
|
+
if ($[0] !== bulkUploadDrawerSlug || $[1] !== collections || $[2] !== editor || $[3] !== isModalOpen || $[4] !== openModal || $[5] !== setCollectionSlug || $[6] !== setInitialForms || $[7] !== setOnCancel || $[8] !== setOnSuccess || $[9] !== setSelectableCollections) {
|
|
56
|
+
t1 = t2 => {
|
|
57
|
+
const {
|
|
58
|
+
files
|
|
59
|
+
} = t2;
|
|
60
|
+
if (files?.length === 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
setInitialForms(initialForms => [...(initialForms ?? []), ...files.map(_temp)]);
|
|
64
|
+
if (!isModalOpen(bulkUploadDrawerSlug)) {
|
|
65
|
+
const uploadCollections = collections.filter(_temp2).map(_temp3);
|
|
66
|
+
if (!uploadCollections.length || !uploadCollections[0]) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setCollectionSlug(uploadCollections[0]);
|
|
70
|
+
setSelectableCollections(uploadCollections);
|
|
71
|
+
setOnCancel(() => {
|
|
72
|
+
editor.update(_temp4);
|
|
73
|
+
});
|
|
74
|
+
setOnSuccess(newDocs => {
|
|
75
|
+
const newDocsMap = new Map(newDocs.map(_temp5));
|
|
76
|
+
editor.update(() => {
|
|
77
|
+
for (const dfsNode_0 of $dfsIterator()) {
|
|
78
|
+
const node_0 = dfsNode_0.node;
|
|
79
|
+
if ($isPendingUploadNode(node_0)) {
|
|
80
|
+
const newDoc = newDocsMap.get(node_0.getData().formID);
|
|
81
|
+
if (newDoc) {
|
|
82
|
+
node_0.replace($createUploadNode({
|
|
83
|
+
data: {
|
|
84
|
+
id: new ObjectID.default().toHexString(),
|
|
85
|
+
fields: newDoc.doc,
|
|
86
|
+
relationTo: newDoc.collectionSlug,
|
|
87
|
+
value: newDoc.doc.id
|
|
88
|
+
}
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
openModal(bulkUploadDrawerSlug);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
$[0] = bulkUploadDrawerSlug;
|
|
99
|
+
$[1] = collections;
|
|
100
|
+
$[2] = editor;
|
|
101
|
+
$[3] = isModalOpen;
|
|
102
|
+
$[4] = openModal;
|
|
103
|
+
$[5] = setCollectionSlug;
|
|
104
|
+
$[6] = setInitialForms;
|
|
105
|
+
$[7] = setOnCancel;
|
|
106
|
+
$[8] = setOnSuccess;
|
|
107
|
+
$[9] = setSelectableCollections;
|
|
108
|
+
$[10] = t1;
|
|
109
|
+
} else {
|
|
110
|
+
t1 = $[10];
|
|
111
|
+
}
|
|
112
|
+
const openBulkUpload = useEffectEvent(t1);
|
|
22
113
|
let t2;
|
|
23
|
-
|
|
24
|
-
if ($[0] !== editor) {
|
|
114
|
+
if ($[11] !== editor || $[12] !== openBulkUpload) {
|
|
25
115
|
t2 = () => {
|
|
26
116
|
if (!editor.hasNodes([UploadNode])) {
|
|
27
117
|
throw new Error("UploadPlugin: UploadNode not registered on editor");
|
|
28
118
|
}
|
|
29
|
-
return mergeRegister(editor.
|
|
119
|
+
return mergeRegister(editor.registerNodeTransform(PendingUploadNode, node_1 => {
|
|
120
|
+
const nodeData = node_1.getData();
|
|
121
|
+
const upload_0 = async function upload() {
|
|
122
|
+
let transformedImage = null;
|
|
123
|
+
const src = nodeData.src;
|
|
124
|
+
const formID = nodeData.formID;
|
|
125
|
+
if (src.startsWith("data:")) {
|
|
126
|
+
const mimeMatch = src.match(/data:(image\/[a-zA-Z]+);base64,/);
|
|
127
|
+
const mimeType = mimeMatch ? mimeMatch[1] : "image/png";
|
|
128
|
+
const base64Data = src.replace(/^data:image\/[a-zA-Z]+;base64,/, "");
|
|
129
|
+
const byteCharacters = atob(base64Data);
|
|
130
|
+
const byteNumbers = new Array(byteCharacters.length);
|
|
131
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
132
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
133
|
+
}
|
|
134
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
135
|
+
const file_0 = new File([byteArray], "pasted-image." + mimeType?.split("/")[1], {
|
|
136
|
+
type: mimeType
|
|
137
|
+
});
|
|
138
|
+
transformedImage = {
|
|
139
|
+
alt: undefined,
|
|
140
|
+
file: file_0,
|
|
141
|
+
formID
|
|
142
|
+
};
|
|
143
|
+
} else {
|
|
144
|
+
if (src.startsWith("http") || src.startsWith("https")) {
|
|
145
|
+
const res = await fetch(src);
|
|
146
|
+
const blob = await res.blob();
|
|
147
|
+
const file_1 = new File([blob], "pasted-image." + blob.type.split("/")[1], {
|
|
148
|
+
type: blob.type
|
|
149
|
+
});
|
|
150
|
+
transformedImage = {
|
|
151
|
+
alt: undefined,
|
|
152
|
+
file: file_1,
|
|
153
|
+
formID
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!transformedImage) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
openBulkUpload({
|
|
161
|
+
files: [transformedImage]
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
upload_0();
|
|
165
|
+
}), editor.registerCommand(INSERT_UPLOAD_COMMAND, payload => {
|
|
30
166
|
editor.update(() => {
|
|
31
167
|
const selection = $getSelection() || $getPreviousSelection();
|
|
32
168
|
if ($isRangeSelection(selection)) {
|
|
@@ -49,33 +185,167 @@ export const UploadPlugin = t0 => {
|
|
|
49
185
|
}
|
|
50
186
|
});
|
|
51
187
|
return true;
|
|
52
|
-
}, COMMAND_PRIORITY_EDITOR)
|
|
188
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(PASTE_COMMAND, event => {
|
|
189
|
+
if (!(event instanceof ClipboardEvent)) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
const clipboardData = event.clipboardData;
|
|
193
|
+
if (!clipboardData?.types?.length || clipboardData?.types?.includes("text/html")) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const files_0 = [];
|
|
197
|
+
if (clipboardData?.files?.length) {
|
|
198
|
+
Array.from(clipboardData.files).forEach(file_2 => {
|
|
199
|
+
files_0.push({
|
|
200
|
+
alt: "",
|
|
201
|
+
file: file_2,
|
|
202
|
+
formID: new ObjectID.default().toHexString()
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (files_0.length) {
|
|
207
|
+
editor.update(() => {
|
|
208
|
+
const selection_0 = $getSelection() || $getPreviousSelection();
|
|
209
|
+
if ($isRangeSelection(selection_0)) {
|
|
210
|
+
for (const file_3 of files_0) {
|
|
211
|
+
const pendingUploadNode = new PendingUploadNode({
|
|
212
|
+
data: {
|
|
213
|
+
formID: file_3.formID,
|
|
214
|
+
src: URL.createObjectURL(file_3.file)
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
const {
|
|
218
|
+
focus: focus_0
|
|
219
|
+
} = selection_0;
|
|
220
|
+
const focusNode_0 = focus_0.getNode();
|
|
221
|
+
$insertNodeToNearestRoot(pendingUploadNode);
|
|
222
|
+
if ($isParagraphNode(focusNode_0) && !focusNode_0.__first) {
|
|
223
|
+
focusNode_0.remove();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
openBulkUpload({
|
|
229
|
+
files: files_0
|
|
230
|
+
});
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(DROP_COMMAND, event_0 => {
|
|
235
|
+
if (!(event_0 instanceof DragEvent)) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const dt = event_0.dataTransfer;
|
|
239
|
+
if (!dt?.types?.length) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
const files_1 = [];
|
|
243
|
+
if (dt?.files?.length) {
|
|
244
|
+
Array.from(dt.files).forEach(file_4 => {
|
|
245
|
+
files_1.push({
|
|
246
|
+
alt: "",
|
|
247
|
+
file: file_4,
|
|
248
|
+
formID: new ObjectID.default().toHexString()
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (files_1.length) {
|
|
253
|
+
event_0.preventDefault();
|
|
254
|
+
event_0.stopPropagation();
|
|
255
|
+
editor.update(() => {
|
|
256
|
+
if (canDropImage(event_0)) {
|
|
257
|
+
const range = getDragSelection(event_0);
|
|
258
|
+
const selection_1 = $createRangeSelection();
|
|
259
|
+
if (range !== null && range !== undefined) {
|
|
260
|
+
selection_1.applyDOMRange(range);
|
|
261
|
+
}
|
|
262
|
+
$setSelection(selection_1);
|
|
263
|
+
for (const file_5 of files_1) {
|
|
264
|
+
const pendingUploadNode_0 = new PendingUploadNode({
|
|
265
|
+
data: {
|
|
266
|
+
formID: file_5.formID,
|
|
267
|
+
src: URL.createObjectURL(file_5.file)
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
const {
|
|
271
|
+
focus: focus_1
|
|
272
|
+
} = selection_1;
|
|
273
|
+
const focusNode_1 = focus_1.getNode();
|
|
274
|
+
$insertNodeToNearestRoot(pendingUploadNode_0);
|
|
275
|
+
if ($isParagraphNode(focusNode_1) && !focusNode_1.__first) {
|
|
276
|
+
focusNode_1.remove();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
openBulkUpload({
|
|
282
|
+
files: files_1
|
|
283
|
+
});
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
return false;
|
|
287
|
+
}, COMMAND_PRIORITY_LOW));
|
|
53
288
|
};
|
|
289
|
+
$[11] = editor;
|
|
290
|
+
$[12] = openBulkUpload;
|
|
291
|
+
$[13] = t2;
|
|
292
|
+
} else {
|
|
293
|
+
t2 = $[13];
|
|
294
|
+
}
|
|
295
|
+
let t3;
|
|
296
|
+
if ($[14] !== editor) {
|
|
54
297
|
t3 = [editor];
|
|
55
|
-
$[
|
|
56
|
-
$[
|
|
57
|
-
$[2] = t3;
|
|
298
|
+
$[14] = editor;
|
|
299
|
+
$[15] = t3;
|
|
58
300
|
} else {
|
|
59
|
-
|
|
60
|
-
t3 = $[2];
|
|
301
|
+
t3 = $[15];
|
|
61
302
|
}
|
|
62
303
|
useEffect(t2, t3);
|
|
63
304
|
let t4;
|
|
64
|
-
if ($[
|
|
305
|
+
if ($[16] !== collections) {
|
|
65
306
|
t4 = _jsx(UploadDrawer, {
|
|
66
|
-
enabledCollectionSlugs: collections.map(
|
|
307
|
+
enabledCollectionSlugs: collections.map(_temp6)
|
|
67
308
|
});
|
|
68
|
-
$[
|
|
69
|
-
$[
|
|
309
|
+
$[16] = collections;
|
|
310
|
+
$[17] = t4;
|
|
70
311
|
} else {
|
|
71
|
-
t4 = $[
|
|
312
|
+
t4 = $[17];
|
|
72
313
|
}
|
|
73
314
|
return t4;
|
|
74
315
|
};
|
|
75
|
-
function _temp(
|
|
316
|
+
function _temp(file) {
|
|
317
|
+
return {
|
|
318
|
+
file: file.file,
|
|
319
|
+
formID: file.formID
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function _temp2(t0) {
|
|
323
|
+
const {
|
|
324
|
+
upload
|
|
325
|
+
} = t0;
|
|
326
|
+
return !!upload;
|
|
327
|
+
}
|
|
328
|
+
function _temp3(t0) {
|
|
76
329
|
const {
|
|
77
330
|
slug
|
|
78
331
|
} = t0;
|
|
79
332
|
return slug;
|
|
80
333
|
}
|
|
334
|
+
function _temp4() {
|
|
335
|
+
for (const dfsNode of $dfsIterator()) {
|
|
336
|
+
const node = dfsNode.node;
|
|
337
|
+
if ($isPendingUploadNode(node)) {
|
|
338
|
+
node.remove();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function _temp5(doc) {
|
|
343
|
+
return [doc.formID, doc];
|
|
344
|
+
}
|
|
345
|
+
function _temp6(t0) {
|
|
346
|
+
const {
|
|
347
|
+
slug: slug_0
|
|
348
|
+
} = t0;
|
|
349
|
+
return slug_0;
|
|
350
|
+
}
|
|
81
351
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","mergeRegister","useConfig","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","COMMAND_PRIORITY_EDITOR","createCommand","React","useEffect","UploadDrawer","$createUploadNode","UploadNode","INSERT_UPLOAD_COMMAND","UploadPlugin","t0","$","editor","config","t1","collections","t2","t3","hasNodes","Error","registerCommand","payload","update","selection","uploadNode","data","id","fields","relationTo","value","focus","focusNode","getNode","__first","remove","t4","_jsx","enabledCollectionSlugs","map","_temp","slug"],"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 { $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils'\nimport { useConfig } from '@payloadcms/ui'\nimport {\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n COMMAND_PRIORITY_EDITOR,\n createCommand,\n} from 'lexical'\nimport React, { useEffect } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\n\nimport { UploadDrawer } from '../drawer/index.js'\nimport { $createUploadNode, UploadNode } from '../nodes/UploadNode.js'\n\nexport type InsertUploadPayload = Readonly<Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>>\n\nexport const INSERT_UPLOAD_COMMAND: LexicalCommand<InsertUploadPayload> =\n createCommand('INSERT_UPLOAD_COMMAND')\n\nexport const UploadPlugin: PluginComponent<UploadFeaturePropsClient> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n const {\n config: { collections },\n } = useConfig()\n\n useEffect(() => {\n if (!editor.hasNodes([UploadNode])) {\n throw new Error('UploadPlugin: UploadNode not registered on editor')\n }\n\n return mergeRegister(\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 )\n }, [editor])\n\n return <UploadDrawer enabledCollectionSlugs={collections.map(({ slug }) => slug)} />\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,wBAAwB,EAAEC,aAAa,QAAQ;AACxD,SAASC,SAAS,QAAQ;AAC1B,SACEC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,uBAAuB,EACvBC,aAAa,QACR;AACP,OAAOC,KAAA,IAASC,SAAS,QAAQ;AAMjC,SAASC,YAAY,QAAQ;AAC7B,SAASC,iBAAiB,EAAEC,UAAU,QAAQ;AAI9C,OAAO,MAAMC,qBAAA,GACXN,aAAA,CAAc;AAEhB,OAAO,MAAMO,YAAA,GAA0DC,EAAA;EAAA,MAAAC,CAAA,GAAAnB,EAAA;EACrE,OAAAoB,MAAA,IAAiBnB,yBAAA;EACjB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GAAAC,IAAA,CAAA/B,YAAA;MAAAgC,sBAAA,EAAsCtB,WAAA,CAAAuB,GAAA,CAAAC,KAA8B;IAAA,C;;;;;;SAApEJ,E;CACT;AAhDuE,SAAAI,MAAA7B,EAAA;EA+CP;IAAA8B;EAAA,IAAA9B,EAAQ;EAAA,OAAK8B,IAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$dfsIterator","$insertNodeToNearestRoot","mergeRegister","useBulkUpload","useConfig","useEffectEvent","useModal","ObjectID","$createRangeSelection","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","$setSelection","COMMAND_PRIORITY_EDITOR","COMMAND_PRIORITY_LOW","createCommand","DROP_COMMAND","getDOMSelectionFromTarget","isHTMLElement","PASTE_COMMAND","React","useEffect","UploadDrawer","$isPendingUploadNode","PendingUploadNode","$createUploadNode","UploadNode","canDropImage","event","target","closest","parentElement","getDragSelection","range","domSelection","document","caretRangeFromPoint","clientX","clientY","rangeParent","collapse","rangeOffset","getRangeAt","Error","INSERT_UPLOAD_COMMAND","UploadPlugin","$","editor","config","t0","collections","drawerSlug","bulkUploadDrawerSlug","setCollectionSlug","setInitialForms","setOnCancel","setOnSuccess","setSelectableCollections","isModalOpen","openModal","t1","t2","files","length","initialForms","map","_temp","uploadCollections","filter","_temp2","_temp3","update","_temp4","newDocs","newDocsMap","Map","_temp5","dfsNode_0","node_0","dfsNode","node","newDoc","get","getData","formID","replace","data","id","default","toHexString","fields","doc","relationTo","collectionSlug","value","openBulkUpload","hasNodes","registerNodeTransform","node_1","nodeData","upload_0","upload","transformedImage","src","startsWith","mimeMatch","match","mimeType","base64Data","byteCharacters","atob","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","file_0","File","split","type","file","res","fetch","blob","file_1","registerCommand","payload","selection","uploadNode","focus","focusNode","getNode","__first","remove","ClipboardEvent","clipboardData","types","includes","files_0","from","forEach","file_2","push","alt","selection_0","file_3","pendingUploadNode","URL","createObjectURL","focus_0","focusNode_0","event_0","DragEvent","dt","dataTransfer","files_1","file_4","preventDefault","stopPropagation","selection_1","undefined","applyDOMRange","file_5","pendingUploadNode_0","focus_1","focusNode_1","t3","t4","_jsx","enabledCollectionSlugs","_temp6","slug","slug_0"],"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, useConfig, 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 { UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\n\nimport { UploadDrawer } from '../drawer/index.js'\nimport { $isPendingUploadNode, PendingUploadNode } from '../nodes/PendingUploadNode.js'\nimport { $createUploadNode, 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> = () => {\n const [editor] = useLexicalComposerContext()\n const {\n config: { collections },\n } = useConfig()\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 const uploadCollections = collections.filter(({ upload }) => !!upload).map(({ slug }) => slug)\n if (!uploadCollections.length || !uploadCollections[0]) {\n return\n }\n\n setCollectionSlug(uploadCollections[0])\n setSelectableCollections(uploadCollections)\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 ($isPendingUploadNode(node)) {\n node.remove()\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 ($isPendingUploadNode(node)) {\n const newDoc = newDocsMap.get(node.getData().formID)\n if (newDoc) {\n node.replace(\n $createUploadNode({\n data: {\n id: new ObjectID.default().toHexString(),\n fields: newDoc.doc,\n relationTo: newDoc.collectionSlug,\n value: newDoc.doc.id,\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(PendingUploadNode, (node) => {\n const nodeData = node.getData()\n async function upload() {\n let transformedImage: FileToUpload | null = null\n\n const src = nodeData.src\n const formID = nodeData.formID\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('/')[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 file = new File([blob], 'pasted-image.' + blob.type.split('/')[1], {\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 // PendingUploadNodes 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 PendingUploadNode\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 PendingUploadNode 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 = new PendingUploadNode({\n data: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\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 = new PendingUploadNode({\n data: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\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={collections.map(({ slug }) => slug)} />\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,S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IACpB,MAAAiF,IAAA,GAAaD,OAAA,CAAAC,IAAA;IAAY,IAErBzD,oBAAA,CAAqByD,IAAA;MACvBA,IAAA,CAAAsD,MAAA,CAAW;IAAA;EAAA;AAAA;AA9C8C,SAAA1D,OAAAe,GAAA;EAAA,QAqDdA,GAAA,CAAAP,MAAA,EAAYO,GAAA;AAAA;AArDE,SAAAgF,OAAA1H,EAAA;EA6SP;IAAA2H,IAAA,EAAAC;EAAA,IAAA5H,EAAQ;EAAA,OAAK2H,MAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EAMN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EAMN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAWlE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,cAAc,GAAG;YAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;SAChB,CAAA;KACF,CAAA;IACD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AASD,eAAO,MAAM,aAAa,gIAoPxB,CAAA"}
|
|
@@ -4,6 +4,7 @@ import { createServerFeature } from '../../../utilities/createServerFeature.js';
|
|
|
4
4
|
import { createNode } from '../../typeUtilities.js';
|
|
5
5
|
import { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js';
|
|
6
6
|
import { i18n } from './i18n.js';
|
|
7
|
+
import { PendingUploadServerNode } from './nodes/PendingUploadNode.js';
|
|
7
8
|
import { UploadServerNode } from './nodes/UploadNode.js';
|
|
8
9
|
import { uploadValidation } from './validate.js';
|
|
9
10
|
/**
|
|
@@ -211,7 +212,9 @@ export const UploadFeature = createServerFeature({
|
|
|
211
212
|
},
|
|
212
213
|
node: UploadServerNode,
|
|
213
214
|
validations: [uploadValidation(props)]
|
|
214
|
-
})
|
|
215
|
+
}), {
|
|
216
|
+
node: PendingUploadServerNode
|
|
217
|
+
}],
|
|
215
218
|
sanitizedServerFeatureProps: props
|
|
216
219
|
};
|
|
217
220
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["sanitizeFields","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadServerNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","parentIsLocalized","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","collectionKey","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","currentDepth","depth","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","data","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","allSubFields","collectionFields","concat","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populateArg","populationPromises","populateDepth","maxDepth","undefined","push","select","defaultPopulate","validations","sanitizedServerFeatureProps"],"sources":["../../../../src/features/upload/server/index.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FieldSchemaMap,\n FileData,\n FileSizeImproved,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from '../client/index.js'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { UploadServerNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: CollectionSlug]: {\n fields: Field[]\n }\n }\n /**\n * Sets a maximum population depth for this upload (not the fields for this upload), regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n}\n\n/**\n * Get the absolute URL for an upload URL by potentially prepending the serverURL\n */\nfunction getAbsoluteURL(url: string, payload: Payload): string {\n return url?.startsWith('http') ? url : (payload?.config?.serverURL || '') + url\n}\n\nexport const UploadFeature = createServerFeature<\n UploadFeatureProps,\n UploadFeatureProps,\n UploadFeaturePropsClient\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.collections) {\n for (const collection in props.collections) {\n clientProps.collections[collection] = {\n hasExtraFields: props.collections[collection]!.fields.length >= 1,\n }\n }\n }\n\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n for (const collectionKey in props.collections) {\n const collection = props.collections[collectionKey]!\n if (collection.fields?.length) {\n collection.fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: collection.fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#UploadFeatureClient',\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) {\n return null\n }\n\n const schemaMap: FieldSchemaMap = new Map()\n\n for (const collectionKey in props.collections) {\n const collection = props.collections[collectionKey]!\n if (collection.fields?.length) {\n schemaMap.set(collectionKey, {\n fields: collection.fields,\n })\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n req,\n showHiddenFields,\n }) => {\n // @ts-expect-error - for backwards-compatibility\n const id = node?.value?.id || node?.value\n\n if (req?.payload) {\n const uploadDocument: {\n value?: FileData & TypeWithID\n } = {}\n\n try {\n await populate({\n id,\n collectionSlug: node.relationTo,\n currentDepth,\n data: uploadDocument,\n depth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n })\n } catch (ignored) {\n // eslint-disable-next-line no-console\n console.error(\n 'Lexical upload node HTML converter: error fetching upload file',\n ignored,\n 'Node:',\n node,\n )\n return `<img />`\n }\n\n const url = getAbsoluteURL(uploadDocument?.value?.url ?? '', req?.payload)\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDocument?.value?.mimeType?.startsWith('image')) {\n return `<a href=\"${url}\" rel=\"noopener noreferrer\">${uploadDocument.value?.filename}</a>`\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (\n !uploadDocument?.value?.sizes ||\n !Object.keys(uploadDocument?.value?.sizes).length\n ) {\n return `<img src=\"${url}\" alt=\"${uploadDocument?.value?.filename}\" width=\"${uploadDocument?.value?.width}\" height=\"${uploadDocument?.value?.height}\"/>`\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n let pictureHTML = '<picture>'\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDocument.value?.sizes) {\n const imageSize = uploadDocument.value.sizes[size] as FileSizeImproved\n\n // Skip if any property of the size object is null\n if (\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = getAbsoluteURL(imageSize?.url, req?.payload)\n\n pictureHTML += `<source srcset=\"${imageSizeURL}\" media=\"(max-width: ${imageSize.width}px)\" type=\"${imageSize.mimeType}\">`\n }\n\n // Add the default img tag\n pictureHTML += `<img src=\"${url}\" alt=\"Image\" width=\"${uploadDocument.value?.width}\" height=\"${uploadDocument.value?.height}\">`\n pictureHTML += '</picture>'\n return pictureHTML\n } else {\n return `<img src=\"${id}\" />`\n }\n },\n nodeTypes: [UploadServerNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n if (!node) {\n let allSubFields: Field[] = []\n for (const collection in props?.collections) {\n const collectionFields = props.collections[collection]!.fields\n allSubFields = allSubFields.concat(collectionFields)\n }\n return allSubFields\n }\n const collection = req ? req.payload.collections[node?.relationTo] : null\n\n if (collection) {\n const collectionFieldSchema = props?.collections?.[node?.relationTo]?.fields\n\n if (Array.isArray(collectionFieldSchema)) {\n if (!collectionFieldSchema?.length) {\n return null\n }\n return collectionFieldSchema\n }\n }\n return null\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [uploadPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populateArg,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error - Fix in Payload v4\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth =\n props?.maxDepth !== undefined && props?.maxDepth < depth ? props?.maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n select:\n populateArg?.[collection.config.slug] ?? collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadServerNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"mappings":"AAWA,SAASA,cAAc,QAAQ;AAI/B,SAASC,QAAQ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,2BAAA,EAA6B1E;IAC/B;EACF;EACAoC,GAAA,EAAK;AACP","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["sanitizeFields","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","PendingUploadServerNode","UploadServerNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","parentIsLocalized","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","collectionKey","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","currentDepth","depth","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","data","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","allSubFields","collectionFields","concat","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populateArg","populationPromises","populateDepth","maxDepth","undefined","push","select","defaultPopulate","validations","sanitizedServerFeatureProps"],"sources":["../../../../src/features/upload/server/index.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FieldSchemaMap,\n FileData,\n FileSizeImproved,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from '../client/index.js'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { PendingUploadServerNode } from './nodes/PendingUploadNode.js'\nimport { UploadServerNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: CollectionSlug]: {\n fields: Field[]\n }\n }\n /**\n * Sets a maximum population depth for this upload (not the fields for this upload), regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n}\n\n/**\n * Get the absolute URL for an upload URL by potentially prepending the serverURL\n */\nfunction getAbsoluteURL(url: string, payload: Payload): string {\n return url?.startsWith('http') ? url : (payload?.config?.serverURL || '') + url\n}\n\nexport const UploadFeature = createServerFeature<\n UploadFeatureProps,\n UploadFeatureProps,\n UploadFeaturePropsClient\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.collections) {\n for (const collection in props.collections) {\n clientProps.collections[collection] = {\n hasExtraFields: props.collections[collection]!.fields.length >= 1,\n }\n }\n }\n\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n for (const collectionKey in props.collections) {\n const collection = props.collections[collectionKey]!\n if (collection.fields?.length) {\n collection.fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: collection.fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#UploadFeatureClient',\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) {\n return null\n }\n\n const schemaMap: FieldSchemaMap = new Map()\n\n for (const collectionKey in props.collections) {\n const collection = props.collections[collectionKey]!\n if (collection.fields?.length) {\n schemaMap.set(collectionKey, {\n fields: collection.fields,\n })\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n req,\n showHiddenFields,\n }) => {\n // @ts-expect-error - for backwards-compatibility\n const id = node?.value?.id || node?.value\n\n if (req?.payload) {\n const uploadDocument: {\n value?: FileData & TypeWithID\n } = {}\n\n try {\n await populate({\n id,\n collectionSlug: node.relationTo,\n currentDepth,\n data: uploadDocument,\n depth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n })\n } catch (ignored) {\n // eslint-disable-next-line no-console\n console.error(\n 'Lexical upload node HTML converter: error fetching upload file',\n ignored,\n 'Node:',\n node,\n )\n return `<img />`\n }\n\n const url = getAbsoluteURL(uploadDocument?.value?.url ?? '', req?.payload)\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDocument?.value?.mimeType?.startsWith('image')) {\n return `<a href=\"${url}\" rel=\"noopener noreferrer\">${uploadDocument.value?.filename}</a>`\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (\n !uploadDocument?.value?.sizes ||\n !Object.keys(uploadDocument?.value?.sizes).length\n ) {\n return `<img src=\"${url}\" alt=\"${uploadDocument?.value?.filename}\" width=\"${uploadDocument?.value?.width}\" height=\"${uploadDocument?.value?.height}\"/>`\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n let pictureHTML = '<picture>'\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDocument.value?.sizes) {\n const imageSize = uploadDocument.value.sizes[size] as FileSizeImproved\n\n // Skip if any property of the size object is null\n if (\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = getAbsoluteURL(imageSize?.url, req?.payload)\n\n pictureHTML += `<source srcset=\"${imageSizeURL}\" media=\"(max-width: ${imageSize.width}px)\" type=\"${imageSize.mimeType}\">`\n }\n\n // Add the default img tag\n pictureHTML += `<img src=\"${url}\" alt=\"Image\" width=\"${uploadDocument.value?.width}\" height=\"${uploadDocument.value?.height}\">`\n pictureHTML += '</picture>'\n return pictureHTML\n } else {\n return `<img src=\"${id}\" />`\n }\n },\n nodeTypes: [UploadServerNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n if (!node) {\n let allSubFields: Field[] = []\n for (const collection in props?.collections) {\n const collectionFields = props.collections[collection]!.fields\n allSubFields = allSubFields.concat(collectionFields)\n }\n return allSubFields\n }\n const collection = req ? req.payload.collections[node?.relationTo] : null\n\n if (collection) {\n const collectionFieldSchema = props?.collections?.[node?.relationTo]?.fields\n\n if (Array.isArray(collectionFieldSchema)) {\n if (!collectionFieldSchema?.length) {\n return null\n }\n return collectionFieldSchema\n }\n }\n return null\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [uploadPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populateArg,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error - Fix in Payload v4\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth =\n props?.maxDepth !== undefined && props?.maxDepth < depth ? props?.maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n select:\n populateArg?.[collection.config.slug] ?? collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadServerNode,\n validations: [uploadValidation(props)],\n }),\n {\n node: PendingUploadServerNode,\n },\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"mappings":"AAWA,SAASA,cAAc,QAAQ;AAI/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,IAAI,QAAQ;AACrB,SAASC,uBAAuB,QAAQ;AACxC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,QAAQ;AAiBjC;;;AAGA,SAASC,eAAeC,GAAW,EAAEC,OAAgB;E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;YACXC,kBAAkB;YAClBtC,GAAG;YACHC;UAAgB,CACjB;YACC,IAAI,CAACH,IAAA,EAAMK,KAAA,EAAO;cAChB,OAAOL,IAAA;YACT;YACA,MAAMvB,UAAA,GAAayB,GAAA,CAAIrC,OAAO,CAACU,WAAW,CAACyB,IAAA,EAAMQ,UAAA,CAAW;YAE5D,IAAI,CAAC/B,UAAA,EAAY;cACf,OAAOuB,IAAA;YACT;YACA;YACA,MAAMI,EAAA,GAAKJ,IAAA,EAAMK,KAAA,EAAOD,EAAA,IAAMJ,IAAA,EAAMK,KAAA,CAAM;YAAA;YAE1C,MAAMoC,aAAA,GACJnE,KAAA,EAAOoE,QAAA,KAAaC,SAAA,IAAarE,KAAA,EAAOoE,QAAA,GAAW5C,KAAA,GAAQxB,KAAA,EAAOoE,QAAA,GAAW5C,KAAA;YAE/E0C,kBAAA,CAAmBI,IAAI,CACrBzF,QAAA,CAAS;cACPiD,EAAA;cACAG,cAAA,EAAgB9B,UAAA,CAAWV,MAAM,CAACiB,IAAI;cACtCa,YAAA;cACAY,IAAA,EAAMT,IAAA;cACNF,KAAA,EAAO2C,aAAA;cACP1C,KAAA;cACAW,GAAA,EAAK;cACLT,cAAA;cACAC,GAAA;cACA2C,MAAA,EACEN,WAAA,GAAc9D,UAAA,CAAWV,MAAM,CAACiB,IAAI,CAAC,IAAIP,UAAA,CAAWV,MAAM,CAAC+E,eAAe;cAC5E3C;YACF;YAGF,OAAOH,IAAA;UACT;QAEJ;QACAA,IAAA,EAAMvC,gBAAA;QACNsF,WAAA,EAAa,CAACrF,gBAAA,CAAiBY,KAAA;MACjC,IACA;QACE0B,IAAA,EAAMxC;MACR,EACD;MACDwF,2BAAA,EAA6B1E;IAC/B;EACF;EACAoC,GAAA,EAAK;AACP","ignoreList":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js';
|
|
2
|
+
import type { DOMConversionMap, DOMExportOutput, ElementFormatType, LexicalNode, NodeKey, Spread } from 'lexical';
|
|
3
|
+
import type { JSX } from 'react';
|
|
4
|
+
import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js';
|
|
5
|
+
export type PendingUploadData = {
|
|
6
|
+
/**
|
|
7
|
+
* ID that corresponds to the bulk upload form ID
|
|
8
|
+
*/
|
|
9
|
+
formID: string;
|
|
10
|
+
/**
|
|
11
|
+
* src value of the image dom element
|
|
12
|
+
*/
|
|
13
|
+
src: string;
|
|
14
|
+
};
|
|
15
|
+
export type SerializedPendingUploadNode = {
|
|
16
|
+
children?: never;
|
|
17
|
+
type: 'pendingUpload';
|
|
18
|
+
} & Spread<PendingUploadData, SerializedDecoratorBlockNode>;
|
|
19
|
+
export declare class PendingUploadServerNode extends DecoratorBlockNode {
|
|
20
|
+
__data: PendingUploadData;
|
|
21
|
+
constructor({ data, format, key, }: {
|
|
22
|
+
data: PendingUploadData;
|
|
23
|
+
format?: ElementFormatType;
|
|
24
|
+
key?: NodeKey;
|
|
25
|
+
});
|
|
26
|
+
static clone(node: PendingUploadServerNode): PendingUploadServerNode;
|
|
27
|
+
static getType(): string;
|
|
28
|
+
static importDOM(): DOMConversionMap<HTMLImageElement>;
|
|
29
|
+
static importJSON(serializedNode: SerializedPendingUploadNode): PendingUploadServerNode;
|
|
30
|
+
static isInline(): false;
|
|
31
|
+
decorate(): JSX.Element;
|
|
32
|
+
exportDOM(): DOMExportOutput;
|
|
33
|
+
exportJSON(): SerializedPendingUploadNode;
|
|
34
|
+
getData(): PendingUploadData;
|
|
35
|
+
setData(data: PendingUploadData): void;
|
|
36
|
+
updateDOM(): false;
|
|
37
|
+
}
|
|
38
|
+
export declare function $createPendingUploadServerNode({ data, }: {
|
|
39
|
+
data: PendingUploadData;
|
|
40
|
+
}): PendingUploadServerNode;
|
|
41
|
+
export declare function $isPendingUploadServerNode(node: LexicalNode | null | undefined): node is PendingUploadServerNode;
|
|
42
|
+
//# sourceMappingURL=PendingUploadNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PendingUploadNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/upload/server/nodes/PendingUploadNode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAA;AAC/F,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,OAAO,EACP,MAAM,EACP,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAMhF,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,IAAI,EAAE,eAAe,CAAA;CACtB,GAAG,MAAM,CAAC,iBAAiB,EAAE,4BAA4B,CAAC,CAAA;AAE3D,qBAAa,uBAAwB,SAAQ,kBAAkB;IAC7D,MAAM,EAAE,iBAAiB,CAAA;gBAEb,EACV,IAAI,EACJ,MAAM,EACN,GAAG,GACJ,EAAE;QACD,IAAI,EAAE,iBAAiB,CAAA;QACvB,MAAM,CAAC,EAAE,iBAAiB,CAAA;QAC1B,GAAG,CAAC,EAAE,OAAO,CAAA;KACd;WAKe,KAAK,CAAC,IAAI,EAAE,uBAAuB,GAAG,uBAAuB;WAQ7D,OAAO,IAAI,MAAM;WAIjB,SAAS,IAAI,gBAAgB,CAAC,gBAAgB,CAAC;WAU/C,UAAU,CAAC,cAAc,EAAE,2BAA2B,GAAG,uBAAuB;IAYhG,MAAM,CAAC,QAAQ,IAAI,KAAK;IAIf,QAAQ,IAAI,GAAG,CAAC,OAAO;IAKvB,SAAS,IAAI,eAA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