@payloadcms/ui 3.83.0-internal.06ac84e → 3.83.0-internal.86b7bfb
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/elements/BulkUpload/FormsManager/createFormData.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/createFormData.js +1 -0
- package/dist/elements/BulkUpload/FormsManager/createFormData.js.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.js +29 -5
- package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
- package/dist/elements/BulkUpload/index.d.ts +2 -0
- package/dist/elements/BulkUpload/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/index.js +44 -35
- package/dist/elements/BulkUpload/index.js.map +1 -1
- package/dist/elements/EditUpload/index.d.ts.map +1 -1
- package/dist/elements/EditUpload/index.js +2 -2
- package/dist/elements/EditUpload/index.js.map +1 -1
- package/dist/elements/ListHeader/TitleActions/ListBulkUploadButton.d.ts.map +1 -1
- package/dist/elements/ListHeader/TitleActions/ListBulkUploadButton.js +23 -15
- package/dist/elements/ListHeader/TitleActions/ListBulkUploadButton.js.map +1 -1
- package/dist/elements/LivePreview/Toolbar/Controls/index.js +1 -1
- package/dist/elements/LivePreview/Toolbar/Controls/index.js.map +1 -1
- package/dist/elements/PreviewSizes/index.d.ts.map +1 -1
- package/dist/elements/PreviewSizes/index.js +2 -2
- package/dist/elements/PreviewSizes/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/File/index.d.ts.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/File/index.js +4 -2
- package/dist/elements/Table/DefaultCell/fields/File/index.js.map +1 -1
- package/dist/elements/Thumbnail/createThumbnail.js +1 -1
- package/dist/elements/Thumbnail/createThumbnail.js.map +1 -1
- package/dist/elements/Thumbnail/index.d.ts.map +1 -1
- package/dist/elements/Thumbnail/index.js +54 -123
- package/dist/elements/Thumbnail/index.js.map +1 -1
- package/dist/elements/withMergedProps/index.d.ts +1 -1
- package/dist/elements/withMergedProps/index.js +1 -1
- package/dist/elements/withMergedProps/index.js.map +1 -1
- package/dist/exports/client/index.js +12 -12
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/shared/index.js.map +1 -1
- package/dist/fields/Slug/index.d.ts.map +1 -1
- package/dist/fields/Slug/index.js +62 -51
- package/dist/fields/Slug/index.js.map +1 -1
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +1 -0
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/providers/UploadHandlers/index.d.ts +1 -0
- package/dist/providers/UploadHandlers/index.d.ts.map +1 -1
- package/dist/providers/UploadHandlers/index.js.map +1 -1
- package/dist/utilities/appendCacheTag.d.ts +6 -0
- package/dist/utilities/appendCacheTag.d.ts.map +1 -0
- package/dist/utilities/appendCacheTag.js +11 -0
- package/dist/utilities/appendCacheTag.js.map +1 -0
- package/dist/utilities/appendCacheTag.spec.js +34 -0
- package/dist/utilities/appendCacheTag.spec.js.map +1 -0
- package/dist/utilities/deepMerge.d.ts +2 -0
- package/dist/utilities/deepMerge.d.ts.map +1 -1
- package/dist/utilities/deepMerge.js +5 -0
- package/dist/utilities/deepMerge.js.map +1 -1
- package/dist/utilities/handleLivePreview.d.ts.map +1 -1
- package/package.json +6 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThumbnail.js","names":["createThumbnail","file","Promise","resolve","reject","img","Image","src","URL","createObjectURL","onload","maxDimension","drawHeight","drawWidth","aspectRatio","
|
|
1
|
+
{"version":3,"file":"createThumbnail.js","names":["createThumbnail","file","Promise","resolve","reject","img","Image","src","URL","createObjectURL","onload","maxDimension","drawHeight","drawWidth","aspectRatio","height","width","canvas","OffscreenCanvas","ctx","getContext","outputFormat","type","quality","undefined","drawImage","convertToBlob","then","blob","revokeObjectURL","reader","FileReader","result","onerror","readAsDataURL","catch","error"],"sources":["../../../src/elements/Thumbnail/createThumbnail.ts"],"sourcesContent":["/**\n * Create a thumbnail from a File object by drawing it onto an OffscreenCanvas\n */\nexport const createThumbnail = (file: File): Promise<string> => {\n return new Promise((resolve, reject) => {\n const img = new Image()\n img.src = URL.createObjectURL(file) // Use Object URL directly\n\n img.onload = () => {\n const maxDimension = 280\n let drawHeight: number, drawWidth: number\n\n // Calculate aspect ratio\n const aspectRatio = img.height && img.width ? img.width / img.height : 1\n\n // Determine dimensions to fit within maxDimension while maintaining aspect ratio\n if (aspectRatio > 1) {\n // Image is wider than tall\n drawWidth = maxDimension\n drawHeight = maxDimension / aspectRatio\n } else {\n // Image is taller than wide, or square\n drawWidth = maxDimension * aspectRatio\n drawHeight = maxDimension\n }\n\n const canvas = new OffscreenCanvas(drawWidth, drawHeight) // Create an OffscreenCanvas\n const ctx = canvas.getContext('2d')\n\n // Determine output format based on input file type\n const outputFormat = file.type === 'image/png' ? 'image/png' : 'image/jpeg'\n const quality = file.type === 'image/png' ? undefined : 0.8 // PNG doesn't use quality, use higher quality for JPEG\n\n // Draw the image onto the OffscreenCanvas with calculated dimensions\n ctx.drawImage(img, 0, 0, drawWidth, drawHeight)\n\n // Convert the OffscreenCanvas to a Blob and free up memory\n canvas\n .convertToBlob({ type: outputFormat, ...(quality && { quality }) })\n .then((blob) => {\n URL.revokeObjectURL(img.src) // Release the Object URL\n const reader = new FileReader()\n reader.onload = () => resolve(reader.result as string) // Resolve as data URL\n reader.onerror = reject\n reader.readAsDataURL(blob)\n })\n .catch(reject)\n }\n\n img.onerror = (error) => {\n URL.revokeObjectURL(img.src) // Release Object URL on error\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error)\n }\n })\n}\n"],"mappings":"AAAA;;GAGA,OAAO,MAAMA,eAAA,GAAmBC,IAAA;EAC9B,OAAO,IAAIC,OAAA,CAAQ,CAACC,OAAA,EAASC,MAAA;IAC3B,MAAMC,GAAA,GAAM,IAAIC,KAAA;IAChBD,GAAA,CAAIE,GAAG,G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a,CAACN,IAAA;MACvB,GACCO,KAAK,CAAC/B,MAAA;IACX;IAEAC,GAAA,CAAI4B,OAAO,GAAIG,KAAA;MACb5B,GAAA,CAAIqB,eAAe,CAACxB,GAAA,CAAIE,GAAG,GAAE;MAC7B;MACAH,MAAA,CAAOgC,KAAA;IACT;EACF;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/Thumbnail/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,cAAc,CAAA;AAIrB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/Thumbnail/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,cAAc,CAAA;AAIrB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAMxD,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;IACvD,YAAY,CAAC,EAAE,yBAAyB,CAAC,QAAQ,CAAC,CAAA;IAClD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA2C9C,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;CACjE,CAAA;AACD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,qBAmChE"}
|
|
@@ -1,158 +1,89 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { c as _c } from "react/compiler-runtime";
|
|
4
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
4
|
import React from 'react';
|
|
6
5
|
import './index.scss';
|
|
7
6
|
const baseClass = 'thumbnail';
|
|
8
7
|
import { File } from '../../graphics/File/index.js';
|
|
8
|
+
import { appendCacheTag } from '../../utilities/appendCacheTag.js';
|
|
9
9
|
import { ShimmerEffect } from '../ShimmerEffect/index.js';
|
|
10
10
|
export const Thumbnail = props => {
|
|
11
|
-
const $ = _c(6);
|
|
12
11
|
const {
|
|
13
|
-
className
|
|
14
|
-
doc:
|
|
12
|
+
className = '',
|
|
13
|
+
doc: {
|
|
14
|
+
filename
|
|
15
|
+
} = {},
|
|
15
16
|
fileSrc,
|
|
16
17
|
height,
|
|
17
18
|
imageCacheTag,
|
|
18
19
|
size,
|
|
19
20
|
width
|
|
20
21
|
} = props;
|
|
21
|
-
const className = t0 === undefined ? "" : t0;
|
|
22
|
-
const {
|
|
23
|
-
filename
|
|
24
|
-
} = t1 === undefined ? {} : t1;
|
|
25
22
|
const [fileExists, setFileExists] = React.useState(undefined);
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!fileSrc) {
|
|
42
|
-
setFileExists(false);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
setFileExists(undefined);
|
|
46
|
-
const img = new Image();
|
|
47
|
-
img.src = fileSrc;
|
|
48
|
-
img.onload = () => {
|
|
49
|
-
setFileExists(true);
|
|
50
|
-
};
|
|
51
|
-
img.onerror = () => {
|
|
52
|
-
setFileExists(false);
|
|
53
|
-
};
|
|
23
|
+
const classNames = [baseClass, `${baseClass}--size-${size || 'medium'}`, className].join(' ');
|
|
24
|
+
const src = React.useMemo(() => fileSrc ? appendCacheTag(fileSrc, imageCacheTag) : null, [fileSrc, imageCacheTag]);
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
if (!src) {
|
|
27
|
+
setFileExists(false);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
setFileExists(undefined);
|
|
31
|
+
const img = new Image();
|
|
32
|
+
img.src = src;
|
|
33
|
+
img.onload = () => {
|
|
34
|
+
setFileExists(true);
|
|
35
|
+
};
|
|
36
|
+
img.onerror = () => {
|
|
37
|
+
setFileExists(false);
|
|
54
38
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
$[4] = t4;
|
|
58
|
-
$[5] = t5;
|
|
59
|
-
} else {
|
|
60
|
-
t4 = $[4];
|
|
61
|
-
t5 = $[5];
|
|
62
|
-
}
|
|
63
|
-
React.useEffect(t4, t5);
|
|
64
|
-
let src = null;
|
|
65
|
-
if (fileSrc) {
|
|
66
|
-
const queryChar = fileSrc?.includes("?") ? "&" : "?";
|
|
67
|
-
src = imageCacheTag ? `${fileSrc}${queryChar}${encodeURIComponent(imageCacheTag)}` : fileSrc;
|
|
68
|
-
}
|
|
69
|
-
return _jsxs("div", {
|
|
39
|
+
}, [src]);
|
|
40
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
70
41
|
className: classNames,
|
|
71
|
-
children: [fileExists === undefined && _jsx(ShimmerEffect, {
|
|
42
|
+
children: [fileExists === undefined && /*#__PURE__*/_jsx(ShimmerEffect, {
|
|
72
43
|
height: "100%"
|
|
73
|
-
}), fileExists && _jsx("img", {
|
|
44
|
+
}), fileExists && /*#__PURE__*/_jsx("img", {
|
|
74
45
|
alt: filename,
|
|
75
|
-
height,
|
|
76
|
-
src,
|
|
77
|
-
width
|
|
78
|
-
}), fileExists === false && _jsx(File, {})]
|
|
46
|
+
height: height,
|
|
47
|
+
src: src,
|
|
48
|
+
width: width
|
|
49
|
+
}), fileExists === false && /*#__PURE__*/_jsx(File, {})]
|
|
79
50
|
});
|
|
80
51
|
};
|
|
81
52
|
export function ThumbnailComponent(props) {
|
|
82
|
-
const $ = _c(12);
|
|
83
53
|
const {
|
|
84
54
|
alt,
|
|
85
|
-
className
|
|
55
|
+
className = '',
|
|
86
56
|
filename,
|
|
87
57
|
fileSrc,
|
|
88
58
|
imageCacheTag,
|
|
89
59
|
size
|
|
90
60
|
} = props;
|
|
91
|
-
const className = t0 === undefined ? "" : t0;
|
|
92
61
|
const [fileExists, setFileExists] = React.useState(undefined);
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (!fileSrc) {
|
|
109
|
-
setFileExists(false);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
setFileExists(undefined);
|
|
113
|
-
const img = new Image();
|
|
114
|
-
img.src = fileSrc;
|
|
115
|
-
img.onload = () => {
|
|
116
|
-
setFileExists(true);
|
|
117
|
-
};
|
|
118
|
-
img.onerror = () => {
|
|
119
|
-
setFileExists(false);
|
|
120
|
-
};
|
|
62
|
+
const classNames = [baseClass, `${baseClass}--size-${size || 'medium'}`, className].join(' ');
|
|
63
|
+
const src = React.useMemo(() => fileSrc ? appendCacheTag(fileSrc, imageCacheTag) : null, [fileSrc, imageCacheTag]);
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
if (!src) {
|
|
66
|
+
setFileExists(false);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setFileExists(undefined);
|
|
70
|
+
const img = new Image();
|
|
71
|
+
img.src = src;
|
|
72
|
+
img.onload = () => {
|
|
73
|
+
setFileExists(true);
|
|
74
|
+
};
|
|
75
|
+
img.onerror = () => {
|
|
76
|
+
setFileExists(false);
|
|
121
77
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (fileSrc) {
|
|
133
|
-
const queryChar = fileSrc?.includes("?") ? "&" : "?";
|
|
134
|
-
src = imageCacheTag ? `${fileSrc}${queryChar}${encodeURIComponent(imageCacheTag)}` : fileSrc;
|
|
135
|
-
}
|
|
136
|
-
let t5;
|
|
137
|
-
if ($[6] !== alt || $[7] !== classNames || $[8] !== fileExists || $[9] !== filename || $[10] !== src) {
|
|
138
|
-
t5 = _jsxs("div", {
|
|
139
|
-
className: classNames,
|
|
140
|
-
children: [fileExists === undefined && _jsx(ShimmerEffect, {
|
|
141
|
-
height: "100%"
|
|
142
|
-
}), fileExists && _jsx("img", {
|
|
143
|
-
alt: alt || filename,
|
|
144
|
-
src
|
|
145
|
-
}), fileExists === false && _jsx(File, {})]
|
|
146
|
-
});
|
|
147
|
-
$[6] = alt;
|
|
148
|
-
$[7] = classNames;
|
|
149
|
-
$[8] = fileExists;
|
|
150
|
-
$[9] = filename;
|
|
151
|
-
$[10] = src;
|
|
152
|
-
$[11] = t5;
|
|
153
|
-
} else {
|
|
154
|
-
t5 = $[11];
|
|
155
|
-
}
|
|
156
|
-
return t5;
|
|
78
|
+
}, [src]);
|
|
79
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
80
|
+
className: classNames,
|
|
81
|
+
children: [fileExists === undefined && /*#__PURE__*/_jsx(ShimmerEffect, {
|
|
82
|
+
height: "100%"
|
|
83
|
+
}), fileExists && /*#__PURE__*/_jsx("img", {
|
|
84
|
+
alt: alt || filename,
|
|
85
|
+
src: src
|
|
86
|
+
}), fileExists === false && /*#__PURE__*/_jsx(File, {})]
|
|
87
|
+
});
|
|
157
88
|
}
|
|
158
89
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","baseClass","File","appendCacheTag","ShimmerEffect","Thumbnail","props","className","doc","filename","fileSrc","height","imageCacheTag","size","width","fileExists","setFileExists","useState","undefined","classNames","join","src","useMemo","useEffect","img","Image","onload","onerror","_jsxs","_jsx","alt","ThumbnailComponent"],"sources":["../../../src/elements/Thumbnail/index.tsx"],"sourcesContent":["'use client'\nimport React from 'react'\n\nimport './index.scss'\n\nconst baseClass = 'thumbnail'\n\nimport type { SanitizedCollectionConfig } from 'payload'\n\nimport { File } from '../../graphics/File/index.js'\nimport { appendCacheTag } from '../../utilities/appendCacheTag.js'\nimport { ShimmerEffect } from '../ShimmerEffect/index.js'\n\nexport type ThumbnailProps = {\n className?: string\n collectionSlug?: string\n doc?: Record<string, unknown>\n fileSrc?: string\n height?: number\n imageCacheTag?: string\n size?: 'expand' | 'large' | 'medium' | 'none' | 'small'\n uploadConfig?: SanitizedCollectionConfig['upload']\n width?: number\n}\n\nexport const Thumbnail: React.FC<ThumbnailProps> = (props) => {\n const {\n className = '',\n doc: { filename } = {},\n fileSrc,\n height,\n imageCacheTag,\n size,\n width,\n } = props\n const [fileExists, setFileExists] = React.useState(undefined)\n\n const classNames = [baseClass, `${baseClass}--size-${size || 'medium'}`, className].join(' ')\n\n const src = React.useMemo(\n () => (fileSrc ? appendCacheTag(fileSrc, imageCacheTag) : null),\n [fileSrc, imageCacheTag],\n )\n\n React.useEffect(() => {\n if (!src) {\n setFileExists(false)\n return\n }\n setFileExists(undefined)\n\n const img = new Image()\n img.src = src\n img.onload = () => {\n setFileExists(true)\n }\n img.onerror = () => {\n setFileExists(false)\n }\n }, [src])\n\n return (\n <div className={classNames}>\n {fileExists === undefined && <ShimmerEffect height=\"100%\" />}\n {fileExists && <img alt={filename as string} height={height} src={src} width={width} />}\n {fileExists === false && <File />}\n </div>\n )\n}\n\ntype ThumbnailComponentProps = {\n readonly alt?: string\n readonly className?: string\n readonly filename: string\n readonly fileSrc: string\n readonly imageCacheTag?: string\n readonly size?: 'expand' | 'large' | 'medium' | 'none' | 'small'\n}\nexport function ThumbnailComponent(props: ThumbnailComponentProps) {\n const { alt, className = '', filename, fileSrc, imageCacheTag, size } = props\n const [fileExists, setFileExists] = React.useState(undefined)\n\n const classNames = [baseClass, `${baseClass}--size-${size || 'medium'}`, className].join(' ')\n\n const src = React.useMemo(\n () => (fileSrc ? appendCacheTag(fileSrc, imageCacheTag) : null),\n [fileSrc, imageCacheTag],\n )\n\n React.useEffect(() => {\n if (!src) {\n setFileExists(false)\n return\n }\n setFileExists(undefined)\n\n const img = new Image()\n img.src = src\n img.onload = () => {\n setFileExists(true)\n }\n img.onerror = () => {\n setFileExists(false)\n }\n }, [src])\n\n return (\n <div className={classNames}>\n {fileExists === undefined && <ShimmerEffect height=\"100%\" />}\n {fileExists && <img alt={alt || filename} src={src} />}\n {fileExists === false && <File />}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AACA,OAAOA,KAAA,MAAW;AAElB,OAAO;AAEP,MAAMC,SAAA,GAAY;AAIlB,SAASC,IAAI,QAAQ;AACrB,SAASC,cAAc,QAAQ;AAC/B,SAASC,aAAa,QAAQ;AAc9B,OAAO,MAAMC,SAAA,GAAuCC,KAAA;EAClD,MAAM;IACJC,SAAA,GAAY,EAAE;IACdC,GAAA,EAAK;MAAEC;IAA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AAEC,OAAO;IAAEE,aAAa;IAAEC;EAAI,CAAE,GAAGP,KAAA;EACxE,MAAM,CAACS,UAAA,EAAYC,aAAA,CAAc,GAAGhB,KAAA,CAAMiB,QAAQ,CAACC,SAAA;EAEnD,MAAMC,UAAA,GAAa,CAAClB,SAAA,EAAW,GAAGA,SAAA,UAAmBY,IAAA,IAAQ,UAAU,EAAEN,SAAA,CAAU,CAACa,IAAI,CAAC;EAEzF,MAAMC,GAAA,GAAMrB,KAAA,CAAMsB,OAAO,CACvB,MAAOZ,OAAA,GAAUP,cAAA,CAAeO,OAAA,EAASE,aAAA,IAAiB,MAC1D,CAACF,OAAA,EAASE,aAAA,CAAc;EAG1BZ,KAAA,CAAMuB,SAAS,CAAC;IACd,IAAI,CAACF,GAAA,EAAK;MACRL,aAAA,CAAc;MACd;IACF;IACAA,aAAA,CAAcE,SAAA;IAEd,MAAMM,GAAA,GAAM,IAAIC,KAAA;IAChBD,GAAA,CAAIH,GAAG,GAAGA,GAAA;IACVG,GAAA,CAAIE,MAAM,GAAG;MACXV,aAAA,CAAc;IAChB;IACAQ,GAAA,CAAIG,OAAO,GAAG;MACZX,aAAA,CAAc;IAChB;EACF,GAAG,CAACK,GAAA,CAAI;EAER,oBACEO,KAAA,CAAC;IAAIrB,SAAA,EAAWY,UAAA;eACbJ,UAAA,KAAeG,SAAA,iBAAaW,IAAA,CAACzB,aAAA;MAAcO,MAAA,EAAO;QAClDI,UAAA,iBAAcc,IAAA,CAAC;MAAIC,GAAA,EAAKA,GAAA,IAAOrB,QAAA;MAAUY,GAAA,EAAKA;QAC9CN,UAAA,KAAe,sBAASc,IAAA,CAAC3B,IAAA;;AAGhC","ignoreList":[]}
|
|
@@ -8,7 +8,7 @@ import React from 'react';
|
|
|
8
8
|
* rendering the original component.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* const PredefinedComponent =
|
|
11
|
+
* const PredefinedComponent = withMergedProps({
|
|
12
12
|
* Component: OriginalComponent,
|
|
13
13
|
* toMergeIntoProps: { someExtraValue: 5 }
|
|
14
14
|
* });
|
|
@@ -10,7 +10,7 @@ import React from 'react';
|
|
|
10
10
|
* rendering the original component.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* const PredefinedComponent =
|
|
13
|
+
* const PredefinedComponent = withMergedProps({
|
|
14
14
|
* Component: OriginalComponent,
|
|
15
15
|
* toMergeIntoProps: { someExtraValue: 5 }
|
|
16
16
|
* });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["isReactServerComponentOrFunction","serverProps","React","withMergedProps","Component","sanitizeServerOnlyProps","toMergeIntoProps","undefined","MergedPropsComponent","passedProps","mergedProps","simpleMergeProps","forEach","prop","_jsx","props","toMerge"],"sources":["../../../src/elements/withMergedProps/index.tsx"],"sourcesContent":["import { isReactServerComponentOrFunction, serverProps } from 'payload/shared'\nimport React from 'react'\n\n/**\n * Creates a higher-order component (HOC) that merges predefined properties (`toMergeIntoProps`)\n * with any properties passed to the resulting component.\n *\n * Use this when you want to pre-specify some props for a component, while also allowing users to\n * pass in their own props. The HOC ensures the passed props and predefined props are combined before\n * rendering the original component.\n *\n * @example\n * const PredefinedComponent =
|
|
1
|
+
{"version":3,"file":"index.js","names":["isReactServerComponentOrFunction","serverProps","React","withMergedProps","Component","sanitizeServerOnlyProps","toMergeIntoProps","undefined","MergedPropsComponent","passedProps","mergedProps","simpleMergeProps","forEach","prop","_jsx","props","toMerge"],"sources":["../../../src/elements/withMergedProps/index.tsx"],"sourcesContent":["import { isReactServerComponentOrFunction, serverProps } from 'payload/shared'\nimport React from 'react'\n\n/**\n * Creates a higher-order component (HOC) that merges predefined properties (`toMergeIntoProps`)\n * with any properties passed to the resulting component.\n *\n * Use this when you want to pre-specify some props for a component, while also allowing users to\n * pass in their own props. The HOC ensures the passed props and predefined props are combined before\n * rendering the original component.\n *\n * @example\n * const PredefinedComponent = withMergedProps({\n * Component: OriginalComponent,\n * toMergeIntoProps: { someExtraValue: 5 }\n * });\n * // Using <PredefinedComponent customProp=\"value\" /> will result in\n * // <OriginalComponent customProp=\"value\" someExtraValue={5} />\n *\n * @returns A higher-order component with combined properties.\n *\n * @param Component - The original component to wrap.\n * @param sanitizeServerOnlyProps - If true, server-only props will be removed from the merged props. @default true if the component is not a server component, false otherwise.\n * @param toMergeIntoProps - The properties to merge into the passed props.\n */\nexport function withMergedProps<ToMergeIntoProps, CompleteReturnProps>({\n Component,\n sanitizeServerOnlyProps,\n toMergeIntoProps,\n}: {\n Component: React.FC<CompleteReturnProps>\n sanitizeServerOnlyProps?: boolean\n toMergeIntoProps: ToMergeIntoProps\n}): React.FC<CompleteReturnProps> {\n if (sanitizeServerOnlyProps === undefined) {\n sanitizeServerOnlyProps = !isReactServerComponentOrFunction(Component)\n }\n // A wrapper around the args.Component to inject the args.toMergeArgs as props, which are merged with the passed props\n const MergedPropsComponent: React.FC<CompleteReturnProps> = (passedProps) => {\n const mergedProps = simpleMergeProps(passedProps, toMergeIntoProps) as CompleteReturnProps\n\n if (sanitizeServerOnlyProps) {\n serverProps.forEach((prop) => {\n delete mergedProps[prop]\n })\n }\n\n return <Component {...mergedProps} />\n }\n\n return MergedPropsComponent\n}\n\nfunction simpleMergeProps(props, toMerge) {\n return { ...props, ...toMerge }\n}\n"],"mappings":";AAAA,SAASA,gCAAgC,EAAEC,WAAW,QAAQ;AAC9D,OAAOC,KAAA,MAAW;AAElB;;;;;;;;;;;;;;;;;;;;;;AAsBA,OAAO,SAASC,gBAAuD;EACrEC,SAAS;EACTC,uBAAuB;EACvBC;AAAgB,CAKjB;EACC,IAAID,uBAAA,KAA4BE,SAAA,EAAW;IACzCF,uBAAA,GAA0B,CAACL,gCAAA,CAAiCI,SAAA;EAC9D;EACA;EACA,MAAMI,oBAAA,GAAuDC,WAAA;IAC3D,MAAMC,WAAA,GAAcC,gBAAA,CAAiBF,WAAA,EAAaH,gBAAA;IAElD,IAAID,uBAAA,EAAyB;MAC3BJ,WAAA,CAAYW,OAAO,CAAEC,IAAA;QACnB,OAAOH,WAAW,CAACG,IAAA,CAAK;MAC1B;IACF;IAEA,oBAAOC,IAAA,CAACV,SAAA;MAAW,GAAGM;;EACxB;EAEA,OAAOF,oBAAA;AACT;AAEA,SAASG,iBAAiBI,KAAK,EAAEC,OAAO;EACtC,OAAO;IAAE,GAAGD,KAAK;IAAE,GAAGC;EAAQ;AAChC","ignoreList":[]}
|