@panneau/media 5.0.0-alpha.4 → 5.0.0-alpha.42
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/README.md +106 -7
- package/dist/ImageItem.d.ts +23 -0
- package/dist/ImageItem.d.ts.map +1 -0
- package/dist/ImageItem.js +292 -0
- package/dist/ImageItem.js.map +1 -0
- package/dist/MediaField.css +127 -0
- package/dist/MediaField.d.ts +74 -15
- package/dist/MediaField.d.ts.map +1 -1
- package/dist/MediaField.js +790 -189
- package/dist/MediaField.js.map +1 -1
- package/dist/MediaField.module.js +28 -2
- package/dist/MediaField.module.js.map +1 -1
- package/dist/editor/ImageEditor.css +369 -0
- package/dist/editor/ImageEditor.d.ts +13 -0
- package/dist/editor/ImageEditor.d.ts.map +1 -0
- package/dist/editor/ImageEditor.js +692 -0
- package/dist/editor/ImageEditor.js.map +1 -0
- package/dist/editor/ImageEditor.module.js +86 -0
- package/dist/editor/ImageEditor.module.js.map +1 -0
- package/dist/editor/draw.d.ts +37 -0
- package/dist/editor/draw.d.ts.map +1 -0
- package/dist/editor/draw.js +130 -0
- package/dist/editor/draw.js.map +1 -0
- package/dist/editor/geometry.d.ts +54 -0
- package/dist/editor/geometry.d.ts.map +1 -0
- package/dist/editor/geometry.js +227 -0
- package/dist/editor/geometry.js.map +1 -0
- package/dist/editor/index.d.ts +5 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +3 -0
- package/dist/editor/tools.d.ts +11 -0
- package/dist/editor/tools.d.ts.map +1 -0
- package/dist/editor/tools.js +1199 -0
- package/dist/editor/tools.js.map +1 -0
- package/dist/editor/types.d.ts +111 -0
- package/dist/editor/types.d.ts.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/picker/MediaDetails.d.ts +22 -0
- package/dist/picker/MediaDetails.d.ts.map +1 -0
- package/dist/picker/MediaDetails.js +368 -0
- package/dist/picker/MediaDetails.js.map +1 -0
- package/dist/picker/MediaGrid.d.ts +31 -0
- package/dist/picker/MediaGrid.d.ts.map +1 -0
- package/dist/picker/MediaGrid.js +281 -0
- package/dist/picker/MediaGrid.js.map +1 -0
- package/dist/picker/MediaLibrary.d.ts +9 -0
- package/dist/picker/MediaLibrary.d.ts.map +1 -0
- package/dist/picker/MediaLibrary.js +80 -0
- package/dist/picker/MediaLibrary.js.map +1 -0
- package/dist/picker/MediaPicker.css +627 -0
- package/dist/picker/MediaPicker.d.ts +9 -0
- package/dist/picker/MediaPicker.d.ts.map +1 -0
- package/dist/picker/MediaPicker.js +246 -0
- package/dist/picker/MediaPicker.js.map +1 -0
- package/dist/picker/MediaPicker.module.js +124 -0
- package/dist/picker/MediaPicker.module.js.map +1 -0
- package/dist/picker/PickerToolbar.d.ts +19 -0
- package/dist/picker/PickerToolbar.d.ts.map +1 -0
- package/dist/picker/PickerToolbar.js +266 -0
- package/dist/picker/PickerToolbar.js.map +1 -0
- package/dist/picker/UploadPanel.d.ts +22 -0
- package/dist/picker/UploadPanel.d.ts.map +1 -0
- package/dist/picker/UploadPanel.js +186 -0
- package/dist/picker/UploadPanel.js.map +1 -0
- package/dist/picker/format.d.ts +18 -0
- package/dist/picker/format.d.ts.map +1 -0
- package/dist/picker/format.js +64 -0
- package/dist/picker/format.js.map +1 -0
- package/dist/picker/index.d.ts +4 -0
- package/dist/picker/index.d.ts.map +1 -0
- package/dist/picker/index.js +3 -0
- package/dist/picker/types.d.ts +131 -0
- package/dist/picker/types.d.ts.map +1 -0
- package/dist/picker/useMediaBrowser.d.ts +50 -0
- package/dist/picker/useMediaBrowser.d.ts.map +1 -0
- package/dist/picker/useMediaBrowser.js +314 -0
- package/dist/picker/useMediaBrowser.js.map +1 -0
- package/dist/picker/useMediaLibrary.d.ts +51 -0
- package/dist/picker/useMediaLibrary.d.ts.map +1 -0
- package/dist/picker/useMediaLibrary.js +1051 -0
- package/dist/picker/useMediaLibrary.js.map +1 -0
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +5 -2
- package/dist/plugin.js.map +1 -1
- package/dist/resourceSource.d.ts +21 -0
- package/dist/resourceSource.d.ts.map +1 -0
- package/dist/resourceSource.js +108 -0
- package/dist/resourceSource.js.map +1 -0
- package/package.json +20 -9
package/dist/MediaField.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import MediaField_module_default from "./MediaField.module.js";
|
|
2
|
+
import { ImageItem, editedImageOf } from "./ImageItem.js";
|
|
3
|
+
import { useImageEditorTools } from "./editor/tools.js";
|
|
4
|
+
import { ImageEditorDialog } from "./editor/ImageEditor.js";
|
|
5
|
+
import { MediaPicker } from "./picker/MediaPicker.js";
|
|
6
|
+
import { createResourceMediaSource } from "./resourceSource.js";
|
|
2
7
|
import { c } from "react/compiler-runtime";
|
|
3
|
-
import { FileImage, X } from "lucide-react";
|
|
8
|
+
import { FileImage, Images, X } from "lucide-react";
|
|
4
9
|
import { useEffect, useRef, useState } from "react";
|
|
5
10
|
import { usePanneau } from "@panneau/core";
|
|
6
11
|
import { useOptionalDataAdapter } from "@panneau/data/query";
|
|
7
12
|
import { FilePicker, UploadList, formatSize, getAccept, getFieldProps, getMaxSize, useFieldsContext, useRejectionMessage, useUploads } from "@panneau/fields";
|
|
8
13
|
import { fieldsMessages, mediaMessages } from "@panneau/intl";
|
|
9
|
-
import {
|
|
14
|
+
import { getMediaLibraries } from "@panneau/protocol/runtime";
|
|
15
|
+
import { Badge, Button, Fieldset, IconButton, Spinner, usePanneauIntl } from "@panneau/ui";
|
|
10
16
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
17
|
//#region src/MediaField.tsx
|
|
12
18
|
/**
|
|
@@ -16,10 +22,11 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
16
22
|
function toMediaReference(value, itemTitle = "name") {
|
|
17
23
|
if (typeof value === "string" || typeof value === "number") return { id: String(value) };
|
|
18
24
|
if (typeof value !== "object" || value === null) return null;
|
|
19
|
-
const { id, label, media, transform } = value;
|
|
25
|
+
const { id, resource, label, media, transform } = value;
|
|
20
26
|
if (typeof id !== "string" && typeof id !== "number") return null;
|
|
21
27
|
const title = value[itemTitle];
|
|
22
28
|
const reference = { id: String(id) };
|
|
29
|
+
if (typeof resource === "string") reference.resource = resource;
|
|
23
30
|
if (typeof label === "string") reference.label = label;
|
|
24
31
|
else if (typeof title === "string") reference.label = title;
|
|
25
32
|
if (typeof media === "object" && media !== null) reference.media = media;
|
|
@@ -30,26 +37,30 @@ function toMediaReference(value, itemTitle = "name") {
|
|
|
30
37
|
function toMediaReferences(value, itemTitle) {
|
|
31
38
|
return (Array.isArray(value) ? value : [value]).map((entry) => toMediaReference(entry, itemTitle)).filter((reference) => reference !== null);
|
|
32
39
|
}
|
|
40
|
+
/** A reference without its transform for this use. */
|
|
41
|
+
var withoutTransform = ({ transform: _transform, ...reference }) => reference;
|
|
42
|
+
/** The key of a reference: its library and its id, which are unique only together. */
|
|
43
|
+
var keyOf = (reference, resource) => `${reference.resource ?? resource}\n${reference.id}`;
|
|
33
44
|
/** Whether the file of a media is still being processed. */
|
|
34
45
|
function isProcessing(reference) {
|
|
35
46
|
const status = reference.media?.status;
|
|
36
47
|
return status === "pending" || status === "processing";
|
|
37
48
|
}
|
|
38
49
|
/**
|
|
39
|
-
* The library
|
|
40
|
-
* definition.
|
|
50
|
+
* The first library a `media` field allows (decision 0027): the one its `resource` names, the
|
|
51
|
+
* first one it lists, or the first resource of kind `media` of the definition when it names none.
|
|
52
|
+
* The field uploads to it.
|
|
41
53
|
*/
|
|
42
54
|
function getLibrary(definition, resource) {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
return libraries.length === 1 ? libraries[0] ?? null : null;
|
|
55
|
+
const [first] = getMediaLibraries(definition, { resource });
|
|
56
|
+
return definition?.resources.find((candidate) => candidate.id === first) ?? null;
|
|
46
57
|
}
|
|
47
58
|
/**
|
|
48
59
|
* Reads media again while they are being ingested, until they are ready or failed, and calls
|
|
49
60
|
* `onRefresh` with the media that changed.
|
|
50
61
|
*/
|
|
51
62
|
function useMediaRefresh(media, resource, adapter, interval, onRefresh) {
|
|
52
|
-
const $ = c(
|
|
63
|
+
const $ = c(16);
|
|
53
64
|
const latest = useRef(onRefresh);
|
|
54
65
|
let t0;
|
|
55
66
|
if ($[0] !== onRefresh) {
|
|
@@ -61,245 +72,832 @@ function useMediaRefresh(media, resource, adapter, interval, onRefresh) {
|
|
|
61
72
|
} else t0 = $[1];
|
|
62
73
|
useEffect(t0);
|
|
63
74
|
let t1;
|
|
64
|
-
if ($[2] !== media) {
|
|
65
|
-
|
|
75
|
+
if ($[2] !== media || $[3] !== resource) {
|
|
76
|
+
let t2;
|
|
77
|
+
if ($[5] !== resource) {
|
|
78
|
+
t2 = (item) => JSON.stringify([
|
|
79
|
+
item.resource ?? resource,
|
|
80
|
+
item.id,
|
|
81
|
+
item.media?.status ?? ""
|
|
82
|
+
]);
|
|
83
|
+
$[5] = resource;
|
|
84
|
+
$[6] = t2;
|
|
85
|
+
} else t2 = $[6];
|
|
86
|
+
t1 = media.filter(isProcessing).map(t2).join("\n");
|
|
66
87
|
$[2] = media;
|
|
67
|
-
$[3] =
|
|
68
|
-
|
|
88
|
+
$[3] = resource;
|
|
89
|
+
$[4] = t1;
|
|
90
|
+
} else t1 = $[4];
|
|
69
91
|
const key = t1;
|
|
70
92
|
let t2;
|
|
71
|
-
|
|
72
|
-
if ($[4] !== adapter || $[5] !== interval || $[6] !== key || $[7] !== resource) {
|
|
93
|
+
if ($[7] !== adapter || $[8] !== interval || $[9] !== key) {
|
|
73
94
|
t2 = () => {
|
|
74
95
|
if (adapter === null || key === "") return;
|
|
75
|
-
const
|
|
96
|
+
const entries = key.split("\n").map(_temp);
|
|
76
97
|
const controller = new AbortController();
|
|
77
98
|
const timer = setTimeout(() => {
|
|
78
|
-
Promise.all(
|
|
99
|
+
Promise.all(entries.map((t3) => {
|
|
100
|
+
const { library: library_0, id: id_0 } = t3;
|
|
101
|
+
return adapter.get(library_0, id_0, { signal: controller.signal }).then((item_0) => ({
|
|
102
|
+
resource: library_0,
|
|
103
|
+
item: item_0
|
|
104
|
+
}));
|
|
105
|
+
})).then((refreshed) => {
|
|
79
106
|
if (!controller.signal.aborted) latest.current(refreshed);
|
|
80
|
-
}).catch(
|
|
107
|
+
}).catch(_temp2);
|
|
81
108
|
}, interval);
|
|
82
109
|
return () => {
|
|
83
110
|
clearTimeout(timer);
|
|
84
111
|
controller.abort();
|
|
85
112
|
};
|
|
86
113
|
};
|
|
114
|
+
$[7] = adapter;
|
|
115
|
+
$[8] = interval;
|
|
116
|
+
$[9] = key;
|
|
117
|
+
$[10] = t2;
|
|
118
|
+
} else t2 = $[10];
|
|
119
|
+
let t3;
|
|
120
|
+
if ($[11] !== adapter || $[12] !== interval || $[13] !== key || $[14] !== resource) {
|
|
87
121
|
t3 = [
|
|
88
122
|
adapter,
|
|
89
123
|
resource,
|
|
90
124
|
key,
|
|
91
125
|
interval
|
|
92
126
|
];
|
|
93
|
-
$[
|
|
94
|
-
$[
|
|
95
|
-
$[
|
|
96
|
-
$[
|
|
97
|
-
$[
|
|
98
|
-
|
|
99
|
-
} else {
|
|
100
|
-
t2 = $[8];
|
|
101
|
-
t3 = $[9];
|
|
102
|
-
}
|
|
127
|
+
$[11] = adapter;
|
|
128
|
+
$[12] = interval;
|
|
129
|
+
$[13] = key;
|
|
130
|
+
$[14] = resource;
|
|
131
|
+
$[15] = t3;
|
|
132
|
+
} else t3 = $[15];
|
|
103
133
|
useEffect(t2, t3);
|
|
104
134
|
}
|
|
105
135
|
/**
|
|
106
|
-
* Media of
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
136
|
+
* Media of libraries (the `media` type, decisions 0026 and 0027). "Choose media" ("Add media"
|
|
137
|
+
* with `multiple`) opens the media picker on the `sources`, and a file chosen or dropped becomes
|
|
138
|
+
* a media of the library, an item of its resource (`create(resource, { file })`), sent directly
|
|
139
|
+
* to storage first when there is an upload source. Values are references to the media, with
|
|
140
|
+
* their library, their `media` and their `transform` for this use. The field shows each media
|
|
141
|
+
* with its thumbnail and its status, and reads it again until its file is processed.
|
|
112
142
|
*/
|
|
113
|
-
function
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
143
|
+
function _temp2() {}
|
|
144
|
+
function _temp(entry) {
|
|
145
|
+
const [library, id] = JSON.parse(entry);
|
|
146
|
+
return {
|
|
147
|
+
library,
|
|
148
|
+
id
|
|
149
|
+
};
|
|
119
150
|
}
|
|
120
151
|
function MediaField(props) {
|
|
152
|
+
const $ = c(148);
|
|
121
153
|
const intl = usePanneauIntl();
|
|
122
154
|
const contextAdapter = useOptionalDataAdapter();
|
|
123
155
|
const context = useFieldsContext();
|
|
124
|
-
const { adapter
|
|
156
|
+
const { adapter: t0, accept: t1, maxSize: t2, refreshInterval: t3, resource, itemTitle: t4, sources: t5, stateKey, label, description, errors: t6, disabled, readOnly, required, className, labelClassName, descriptionClassName, errorsClassName } = props;
|
|
157
|
+
const adapter = t0 === void 0 ? contextAdapter : t0;
|
|
158
|
+
const accept = t1 === void 0 ? null : t1;
|
|
159
|
+
const maxSize = t2 === void 0 ? null : t2;
|
|
160
|
+
const refreshInterval = t3 === void 0 ? 3e3 : t3;
|
|
161
|
+
const itemTitle = t4 === void 0 ? "name" : t4;
|
|
162
|
+
let t7;
|
|
163
|
+
if ($[0] !== t5) {
|
|
164
|
+
t7 = t5 === void 0 ? [] : t5;
|
|
165
|
+
$[0] = t5;
|
|
166
|
+
$[1] = t7;
|
|
167
|
+
} else t7 = $[1];
|
|
168
|
+
const sources = t7;
|
|
169
|
+
let t8;
|
|
170
|
+
if ($[2] !== t6) {
|
|
171
|
+
t8 = t6 === void 0 ? [] : t6;
|
|
172
|
+
$[2] = t6;
|
|
173
|
+
$[3] = t8;
|
|
174
|
+
} else t8 = $[3];
|
|
175
|
+
const errors = t8;
|
|
176
|
+
const uploadSource = props.uploadSource === void 0 ? context.uploadSource : props.uploadSource;
|
|
125
177
|
const multiple = props.multiple === true;
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
178
|
+
const imageOptions = props.image ?? null;
|
|
179
|
+
const keepsTransforms = imageOptions?.transforms !== false;
|
|
180
|
+
const editable = imageOptions !== null && keepsTransforms;
|
|
181
|
+
let t9;
|
|
182
|
+
if ($[4] !== itemTitle || $[5] !== keepsTransforms || $[6] !== props.value) {
|
|
183
|
+
let t10;
|
|
184
|
+
if ($[8] !== keepsTransforms) {
|
|
185
|
+
t10 = (reference) => keepsTransforms ? reference : withoutTransform(reference);
|
|
186
|
+
$[8] = keepsTransforms;
|
|
187
|
+
$[9] = t10;
|
|
188
|
+
} else t10 = $[9];
|
|
189
|
+
t9 = toMediaReferences(props.value, itemTitle).map(t10);
|
|
190
|
+
$[4] = itemTitle;
|
|
191
|
+
$[5] = keepsTransforms;
|
|
192
|
+
$[6] = props.value;
|
|
193
|
+
$[7] = t9;
|
|
194
|
+
} else t9 = $[7];
|
|
195
|
+
const media = t9;
|
|
196
|
+
const enabled = disabled !== true && readOnly !== true;
|
|
197
|
+
const canUpload = adapter !== null && enabled;
|
|
198
|
+
const canPick = sources.length > 0 && enabled;
|
|
199
|
+
const [picking, setPicking] = useState(false);
|
|
200
|
+
const [editing, setEditing] = useState(null);
|
|
201
|
+
const editorTools = useImageEditorTools();
|
|
202
|
+
let t10;
|
|
203
|
+
if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
|
|
204
|
+
t10 = [];
|
|
205
|
+
$[10] = t10;
|
|
206
|
+
} else t10 = $[10];
|
|
207
|
+
const [problems, setProblems] = useState(t10);
|
|
208
|
+
let t11;
|
|
209
|
+
if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
|
|
210
|
+
t11 = [];
|
|
211
|
+
$[11] = t11;
|
|
212
|
+
} else t11 = $[11];
|
|
213
|
+
const [creating, setCreating] = useState(t11);
|
|
130
214
|
const rejectionMessage = useRejectionMessage(maxSize);
|
|
131
215
|
const latest = useRef(media);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
216
|
+
let t12;
|
|
217
|
+
if ($[12] !== media) {
|
|
218
|
+
t12 = () => {
|
|
219
|
+
latest.current = media;
|
|
220
|
+
};
|
|
221
|
+
$[12] = media;
|
|
222
|
+
$[13] = t12;
|
|
223
|
+
} else t12 = $[13];
|
|
224
|
+
useEffect(t12);
|
|
225
|
+
let t13;
|
|
226
|
+
if ($[14] !== keepsTransforms || $[15] !== props) {
|
|
227
|
+
t13 = (next) => {
|
|
228
|
+
const values = keepsTransforms ? next : next.map(withoutTransform);
|
|
229
|
+
latest.current = values;
|
|
230
|
+
if (props.multiple === true) props.onChange?.(values.length > 0 ? values : null);
|
|
231
|
+
else props.onChange?.(values[0] ?? null);
|
|
232
|
+
};
|
|
233
|
+
$[14] = keepsTransforms;
|
|
234
|
+
$[15] = props;
|
|
235
|
+
$[16] = t13;
|
|
236
|
+
} else t13 = $[16];
|
|
237
|
+
const set = t13;
|
|
238
|
+
let t14;
|
|
239
|
+
if ($[17] !== multiple || $[18] !== resource || $[19] !== set) {
|
|
240
|
+
t14 = (picked) => {
|
|
241
|
+
const known = new Set(latest.current.map((entry) => keyOf(entry, resource)));
|
|
242
|
+
set(multiple ? [...latest.current, ...picked.filter((entry_0) => !known.has(keyOf(entry_0, resource)))] : picked.slice(0, 1));
|
|
243
|
+
};
|
|
244
|
+
$[17] = multiple;
|
|
245
|
+
$[18] = resource;
|
|
246
|
+
$[19] = set;
|
|
247
|
+
$[20] = t14;
|
|
248
|
+
} else t14 = $[20];
|
|
249
|
+
const add = t14;
|
|
250
|
+
let t15;
|
|
251
|
+
if ($[21] !== itemTitle || $[22] !== resource || $[23] !== set) {
|
|
252
|
+
t15 = (refreshed) => set(latest.current.map((reference_0) => {
|
|
253
|
+
const item = refreshed.find((candidate) => candidate.item.id === reference_0.id && candidate.resource === (reference_0.resource ?? resource))?.item;
|
|
254
|
+
const fresh = item !== void 0 ? toMediaReference(item, itemTitle) : null;
|
|
255
|
+
return fresh !== null ? {
|
|
256
|
+
...reference_0,
|
|
257
|
+
...fresh,
|
|
258
|
+
transform: reference_0.transform
|
|
259
|
+
} : reference_0;
|
|
260
|
+
}));
|
|
261
|
+
$[21] = itemTitle;
|
|
262
|
+
$[22] = resource;
|
|
263
|
+
$[23] = set;
|
|
264
|
+
$[24] = t15;
|
|
265
|
+
} else t15 = $[24];
|
|
266
|
+
useMediaRefresh(media, resource, adapter, refreshInterval, t15);
|
|
267
|
+
let t16;
|
|
268
|
+
if ($[25] !== adapter || $[26] !== intl || $[27] !== itemTitle || $[28] !== multiple || $[29] !== resource || $[30] !== set) {
|
|
269
|
+
t16 = (file) => {
|
|
154
270
|
if (adapter === null) return;
|
|
155
271
|
const name = file.name;
|
|
156
272
|
setCreating((current) => [...current, name]);
|
|
157
273
|
adapter.create(resource, { file: file instanceof File ? file : { upload: file.upload } }).then((item_0) => {
|
|
158
|
-
const created =
|
|
274
|
+
const created = {
|
|
275
|
+
...toMediaReference(item_0, itemTitle) ?? { id: item_0.id },
|
|
276
|
+
resource
|
|
277
|
+
};
|
|
159
278
|
set(multiple ? [...latest.current, created] : [created]);
|
|
160
279
|
}).catch((error) => setProblems((current_0) => [...current_0, intl.formatMessage(fieldsMessages.uploadFailed, { error: `${name}: ${error instanceof Error ? error.message : String(error)}` })])).finally(() => setCreating((current_1) => {
|
|
161
280
|
const at = current_1.indexOf(name);
|
|
162
281
|
return at === -1 ? current_1 : current_1.filter((_, index) => index !== at);
|
|
163
282
|
}));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
283
|
+
};
|
|
284
|
+
$[25] = adapter;
|
|
285
|
+
$[26] = intl;
|
|
286
|
+
$[27] = itemTitle;
|
|
287
|
+
$[28] = multiple;
|
|
288
|
+
$[29] = resource;
|
|
289
|
+
$[30] = set;
|
|
290
|
+
$[31] = t16;
|
|
291
|
+
} else t16 = $[31];
|
|
292
|
+
let t17;
|
|
293
|
+
if ($[32] !== rejectionMessage) {
|
|
294
|
+
t17 = (file_0, reason) => setProblems((current_2) => [...current_2, rejectionMessage(file_0, reason)]);
|
|
295
|
+
$[32] = rejectionMessage;
|
|
296
|
+
$[33] = t17;
|
|
297
|
+
} else t17 = $[33];
|
|
298
|
+
let t18;
|
|
299
|
+
if ($[34] !== accept || $[35] !== maxSize || $[36] !== t16 || $[37] !== t17 || $[38] !== uploadSource) {
|
|
300
|
+
t18 = {
|
|
301
|
+
source: uploadSource,
|
|
302
|
+
accept,
|
|
303
|
+
maxSize,
|
|
304
|
+
onUploaded: t16,
|
|
305
|
+
onRejected: t17
|
|
306
|
+
};
|
|
307
|
+
$[34] = accept;
|
|
308
|
+
$[35] = maxSize;
|
|
309
|
+
$[36] = t16;
|
|
310
|
+
$[37] = t17;
|
|
311
|
+
$[38] = uploadSource;
|
|
312
|
+
$[39] = t18;
|
|
313
|
+
} else t18 = $[39];
|
|
314
|
+
const upload = useUploads(t18);
|
|
315
|
+
let t19;
|
|
316
|
+
if ($[40] !== intl) {
|
|
317
|
+
t19 = (item_1) => {
|
|
318
|
+
if (item_1.media?.status === "failed") {
|
|
319
|
+
const reason_0 = item_1.media.error?.message;
|
|
320
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
321
|
+
className: MediaField_module_default.failed,
|
|
322
|
+
children: [/* @__PURE__ */ jsx(Badge, {
|
|
323
|
+
tone: "danger",
|
|
324
|
+
children: intl.formatMessage(mediaMessages.statusFailed)
|
|
325
|
+
}), typeof reason_0 === "string" && reason_0 !== "" ? /* @__PURE__ */ jsx("span", {
|
|
326
|
+
className: MediaField_module_default.failure,
|
|
327
|
+
title: reason_0,
|
|
328
|
+
children: reason_0
|
|
329
|
+
}) : null]
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
if (isProcessing(item_1)) return /* @__PURE__ */ jsx(Badge, {
|
|
333
|
+
tone: "warning",
|
|
334
|
+
children: intl.formatMessage(item_1.media?.status === "pending" ? mediaMessages.statusPending : mediaMessages.statusProcessing)
|
|
335
|
+
});
|
|
336
|
+
return null;
|
|
337
|
+
};
|
|
338
|
+
$[40] = intl;
|
|
339
|
+
$[41] = t19;
|
|
340
|
+
} else t19 = $[41];
|
|
341
|
+
const statusBadge = t19;
|
|
342
|
+
let imageRatios;
|
|
343
|
+
let t20;
|
|
344
|
+
if ($[42] !== editable || $[43] !== imageOptions || $[44] !== intl) {
|
|
345
|
+
imageRatios = imageOptions?.ratios ?? [];
|
|
346
|
+
t20 = imageOptions === null || !editable ? [] : [...imageRatios.length > 0 ? [intl.formatMessage(imageOptions.enforceRatios === true ? mediaMessages.imageRatios : mediaMessages.imageSuggestedRatios, { ratios: intl.formatList(imageRatios, { type: "disjunction" }) })] : [], ...imageOptions.cropRequired === true ? [intl.formatMessage(mediaMessages.imageCropRequired)] : []];
|
|
347
|
+
$[42] = editable;
|
|
348
|
+
$[43] = imageOptions;
|
|
349
|
+
$[44] = intl;
|
|
350
|
+
$[45] = imageRatios;
|
|
351
|
+
$[46] = t20;
|
|
352
|
+
} else {
|
|
353
|
+
imageRatios = $[45];
|
|
354
|
+
t20 = $[46];
|
|
355
|
+
}
|
|
356
|
+
const constraints = t20;
|
|
357
|
+
let t21;
|
|
358
|
+
if ($[47] !== editing || $[48] !== media || $[49] !== resource) {
|
|
359
|
+
t21 = editing === null ? null : "key" in editing ? media.find((entry_1) => keyOf(entry_1, resource) === editing.key) ?? null : editing.picked;
|
|
360
|
+
$[47] = editing;
|
|
361
|
+
$[48] = media;
|
|
362
|
+
$[49] = resource;
|
|
363
|
+
$[50] = t21;
|
|
364
|
+
} else t21 = $[50];
|
|
365
|
+
const edited = t21;
|
|
366
|
+
let t22;
|
|
367
|
+
if ($[51] !== edited) {
|
|
368
|
+
t22 = edited !== null ? editedImageOf(edited) : null;
|
|
369
|
+
$[51] = edited;
|
|
370
|
+
$[52] = t22;
|
|
371
|
+
} else t22 = $[52];
|
|
372
|
+
const editedImage = t22;
|
|
373
|
+
let t23;
|
|
374
|
+
if ($[53] !== editorTools.rotate || $[54] !== imageOptions?.rotate) {
|
|
375
|
+
t23 = imageOptions?.rotate === false ? [] : [editorTools.rotate];
|
|
376
|
+
$[53] = editorTools.rotate;
|
|
377
|
+
$[54] = imageOptions?.rotate;
|
|
378
|
+
$[55] = t23;
|
|
379
|
+
} else t23 = $[55];
|
|
380
|
+
let t24;
|
|
381
|
+
if ($[56] !== editorTools.focalPoint || $[57] !== imageOptions?.focalPoint) {
|
|
382
|
+
t24 = imageOptions?.focalPoint === false ? [] : [editorTools.focalPoint];
|
|
383
|
+
$[56] = editorTools.focalPoint;
|
|
384
|
+
$[57] = imageOptions?.focalPoint;
|
|
385
|
+
$[58] = t24;
|
|
386
|
+
} else t24 = $[58];
|
|
387
|
+
let t25;
|
|
388
|
+
if ($[59] !== editorTools.crop || $[60] !== t23 || $[61] !== t24) {
|
|
389
|
+
t25 = [
|
|
390
|
+
editorTools.crop,
|
|
391
|
+
...t23,
|
|
392
|
+
...t24
|
|
393
|
+
];
|
|
394
|
+
$[59] = editorTools.crop;
|
|
395
|
+
$[60] = t23;
|
|
396
|
+
$[61] = t24;
|
|
397
|
+
$[62] = t25;
|
|
398
|
+
} else t25 = $[62];
|
|
399
|
+
const tools = t25;
|
|
400
|
+
const unavailable = adapter === null && disabled !== true && readOnly !== true;
|
|
401
|
+
const chooseLabel = imageOptions !== null ? multiple ? mediaMessages.addImages : mediaMessages.chooseImage : multiple ? mediaMessages.addMedia : mediaMessages.chooseMedia;
|
|
402
|
+
const cropStep = editable && imageOptions.cropRequired === true && !multiple;
|
|
403
|
+
const withTransform = _temp3;
|
|
404
|
+
let t26;
|
|
405
|
+
if ($[63] !== constraints || $[64] !== description || $[65] !== intl || $[66] !== unavailable) {
|
|
406
|
+
t26 = description !== void 0 || unavailable || constraints.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
181
407
|
description,
|
|
182
|
-
" ",
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
statusBadge(item_2)
|
|
221
|
-
]
|
|
222
|
-
})]
|
|
223
|
-
}),
|
|
224
|
-
editable ? /* @__PURE__ */ jsx(IconButton, {
|
|
225
|
-
icon: X,
|
|
226
|
-
size: "sm",
|
|
227
|
-
label: intl.formatMessage(fieldsMessages.removeFile, { name: name_0 }),
|
|
228
|
-
onPress: () => set(latest.current.filter((entry) => entry.id !== item_2.id))
|
|
229
|
-
}) : null
|
|
230
|
-
]
|
|
231
|
-
}, item_2.id);
|
|
232
|
-
})
|
|
233
|
-
}) : creating.length === 0 && upload.items.length === 0 ? /* @__PURE__ */ jsx("span", {
|
|
234
|
-
className: MediaField_module_default.none,
|
|
235
|
-
children: intl.formatMessage(mediaMessages.noMedia)
|
|
236
|
-
}) : null,
|
|
237
|
-
/* @__PURE__ */ jsx(UploadList, {
|
|
238
|
-
items: upload.items,
|
|
239
|
-
onPause: upload.pause,
|
|
240
|
-
onResume: upload.resume,
|
|
241
|
-
onCancel: upload.cancel,
|
|
242
|
-
onRetry: upload.retry
|
|
243
|
-
}),
|
|
244
|
-
creating.length > 0 ? /* @__PURE__ */ jsxs("span", {
|
|
245
|
-
className: MediaField_module_default.meta,
|
|
246
|
-
role: "status",
|
|
408
|
+
unavailable ? `${description !== void 0 ? " " : ""}${intl.formatMessage(mediaMessages.unavailable)}` : null,
|
|
409
|
+
constraints.length > 0 ? /* @__PURE__ */ jsx("span", {
|
|
410
|
+
className: MediaField_module_default.constraints,
|
|
411
|
+
children: constraints.map(_temp4)
|
|
412
|
+
}) : null
|
|
413
|
+
] }) : void 0;
|
|
414
|
+
$[63] = constraints;
|
|
415
|
+
$[64] = description;
|
|
416
|
+
$[65] = intl;
|
|
417
|
+
$[66] = unavailable;
|
|
418
|
+
$[67] = t26;
|
|
419
|
+
} else t26 = $[67];
|
|
420
|
+
let t27;
|
|
421
|
+
if ($[68] !== errors || $[69] !== problems) {
|
|
422
|
+
t27 = [...errors, ...problems];
|
|
423
|
+
$[68] = errors;
|
|
424
|
+
$[69] = problems;
|
|
425
|
+
$[70] = t27;
|
|
426
|
+
} else t27 = $[70];
|
|
427
|
+
let t28;
|
|
428
|
+
if ($[71] !== canPick || $[72] !== canUpload || $[73] !== creating.length || $[74] !== editable || $[75] !== enabled || $[76] !== imageOptions || $[77] !== intl || $[78] !== media || $[79] !== multiple || $[80] !== resource || $[81] !== set || $[82] !== statusBadge || $[83] !== upload.items) {
|
|
429
|
+
t28 = media.length > 0 && imageOptions !== null ? /* @__PURE__ */ jsx("ul", {
|
|
430
|
+
className: multiple ? MediaField_module_default.gallery : MediaField_module_default.media,
|
|
431
|
+
children: media.map((item_2) => /* @__PURE__ */ jsx(ImageItem, {
|
|
432
|
+
reference: item_2,
|
|
433
|
+
tile: multiple,
|
|
434
|
+
cropRequired: editable && imageOptions.cropRequired === true,
|
|
435
|
+
status: statusBadge(item_2),
|
|
436
|
+
onEdit: enabled && editable ? () => setEditing({ key: keyOf(item_2, resource) }) : null,
|
|
437
|
+
onRemove: canUpload || canPick ? () => set(latest.current.filter((entry_2) => keyOf(entry_2, resource) !== keyOf(item_2, resource))) : null
|
|
438
|
+
}, keyOf(item_2, resource)))
|
|
439
|
+
}) : media.length > 0 ? /* @__PURE__ */ jsx("ul", {
|
|
440
|
+
className: MediaField_module_default.media,
|
|
441
|
+
children: media.map((item_3) => {
|
|
442
|
+
const name_0 = item_3.label ?? item_3.id;
|
|
443
|
+
const size = item_3.media?.size;
|
|
444
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
445
|
+
className: MediaField_module_default.item,
|
|
247
446
|
children: [
|
|
248
|
-
/* @__PURE__ */ jsx(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
447
|
+
/* @__PURE__ */ jsx("span", {
|
|
448
|
+
className: MediaField_module_default.thumbnail,
|
|
449
|
+
children: typeof item_3.media?.thumbnailUrl === "string" ? /* @__PURE__ */ jsx("img", {
|
|
450
|
+
src: item_3.media.thumbnailUrl,
|
|
451
|
+
alt: ""
|
|
452
|
+
}) : /* @__PURE__ */ jsx(FileImage, { "aria-hidden": true })
|
|
453
|
+
}),
|
|
454
|
+
/* @__PURE__ */ jsxs("span", {
|
|
455
|
+
className: MediaField_module_default.details,
|
|
456
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
457
|
+
className: MediaField_module_default.name,
|
|
458
|
+
children: name_0
|
|
459
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
460
|
+
className: MediaField_module_default.meta,
|
|
461
|
+
children: [
|
|
462
|
+
item_3.media !== void 0 ? /* @__PURE__ */ jsx("span", { children: item_3.media.type }) : null,
|
|
463
|
+
typeof size === "number" ? /* @__PURE__ */ jsx("span", { children: formatSize(size, intl.locale) }) : null,
|
|
464
|
+
statusBadge(item_3)
|
|
465
|
+
]
|
|
466
|
+
})]
|
|
467
|
+
}),
|
|
468
|
+
canUpload || canPick ? /* @__PURE__ */ jsx(IconButton, {
|
|
469
|
+
icon: X,
|
|
470
|
+
size: "sm",
|
|
471
|
+
label: intl.formatMessage(fieldsMessages.removeFile, { name: name_0 }),
|
|
472
|
+
onPress: () => set(latest.current.filter((entry_3) => keyOf(entry_3, resource) !== keyOf(item_3, resource)))
|
|
473
|
+
}) : null
|
|
252
474
|
]
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
475
|
+
}, keyOf(item_3, resource));
|
|
476
|
+
})
|
|
477
|
+
}) : creating.length === 0 && upload.items.length === 0 ? /* @__PURE__ */ jsx("span", {
|
|
478
|
+
className: MediaField_module_default.none,
|
|
479
|
+
children: intl.formatMessage(imageOptions !== null ? mediaMessages.noImage : mediaMessages.noMedia)
|
|
480
|
+
}) : null;
|
|
481
|
+
$[71] = canPick;
|
|
482
|
+
$[72] = canUpload;
|
|
483
|
+
$[73] = creating.length;
|
|
484
|
+
$[74] = editable;
|
|
485
|
+
$[75] = enabled;
|
|
486
|
+
$[76] = imageOptions;
|
|
487
|
+
$[77] = intl;
|
|
488
|
+
$[78] = media;
|
|
489
|
+
$[79] = multiple;
|
|
490
|
+
$[80] = resource;
|
|
491
|
+
$[81] = set;
|
|
492
|
+
$[82] = statusBadge;
|
|
493
|
+
$[83] = upload.items;
|
|
494
|
+
$[84] = t28;
|
|
495
|
+
} else t28 = $[84];
|
|
496
|
+
let t29;
|
|
497
|
+
if ($[85] !== upload.cancel || $[86] !== upload.items || $[87] !== upload.pause || $[88] !== upload.resume || $[89] !== upload.retry) {
|
|
498
|
+
t29 = /* @__PURE__ */ jsx(UploadList, {
|
|
499
|
+
items: upload.items,
|
|
500
|
+
onPause: upload.pause,
|
|
501
|
+
onResume: upload.resume,
|
|
502
|
+
onCancel: upload.cancel,
|
|
503
|
+
onRetry: upload.retry
|
|
504
|
+
});
|
|
505
|
+
$[85] = upload.cancel;
|
|
506
|
+
$[86] = upload.items;
|
|
507
|
+
$[87] = upload.pause;
|
|
508
|
+
$[88] = upload.resume;
|
|
509
|
+
$[89] = upload.retry;
|
|
510
|
+
$[90] = t29;
|
|
511
|
+
} else t29 = $[90];
|
|
512
|
+
let t30;
|
|
513
|
+
if ($[91] !== creating || $[92] !== intl) {
|
|
514
|
+
t30 = creating.length > 0 ? /* @__PURE__ */ jsxs("span", {
|
|
515
|
+
className: MediaField_module_default.meta,
|
|
516
|
+
role: "status",
|
|
517
|
+
children: [
|
|
518
|
+
/* @__PURE__ */ jsx(Spinner, { size: "sm" }),
|
|
519
|
+
intl.formatMessage(fieldsMessages.uploadCompleting),
|
|
520
|
+
" ",
|
|
521
|
+
creating.join(", ")
|
|
262
522
|
]
|
|
263
|
-
})
|
|
264
|
-
|
|
523
|
+
}) : null;
|
|
524
|
+
$[91] = creating;
|
|
525
|
+
$[92] = intl;
|
|
526
|
+
$[93] = t30;
|
|
527
|
+
} else t30 = $[93];
|
|
528
|
+
let t31;
|
|
529
|
+
if ($[94] !== accept || $[95] !== canPick || $[96] !== canUpload || $[97] !== chooseLabel || $[98] !== imageOptions || $[99] !== intl || $[100] !== multiple || $[101] !== upload) {
|
|
530
|
+
t31 = canPick || canUpload ? /* @__PURE__ */ jsxs("div", {
|
|
531
|
+
className: MediaField_module_default.actions,
|
|
532
|
+
children: [canPick ? /* @__PURE__ */ jsx(Button, {
|
|
533
|
+
size: "sm",
|
|
534
|
+
appearance: "outline",
|
|
535
|
+
icon: Images,
|
|
536
|
+
onPress: () => setPicking(true),
|
|
537
|
+
children: intl.formatMessage(chooseLabel)
|
|
538
|
+
}) : null, canUpload ? /* @__PURE__ */ jsx(FilePicker, {
|
|
539
|
+
accept,
|
|
540
|
+
multiple,
|
|
541
|
+
className: MediaField_module_default.upload,
|
|
542
|
+
...canPick ? { label: intl.formatMessage(imageOptions !== null ? multiple ? mediaMessages.uploadImages : mediaMessages.uploadImage : multiple ? mediaMessages.uploadFiles : mediaMessages.uploadFile) } : {},
|
|
543
|
+
onSelect: (selected) => {
|
|
544
|
+
setProblems([]);
|
|
545
|
+
upload.add(selected);
|
|
546
|
+
}
|
|
547
|
+
}) : null]
|
|
548
|
+
}) : null;
|
|
549
|
+
$[94] = accept;
|
|
550
|
+
$[95] = canPick;
|
|
551
|
+
$[96] = canUpload;
|
|
552
|
+
$[97] = chooseLabel;
|
|
553
|
+
$[98] = imageOptions;
|
|
554
|
+
$[99] = intl;
|
|
555
|
+
$[100] = multiple;
|
|
556
|
+
$[101] = upload;
|
|
557
|
+
$[102] = t31;
|
|
558
|
+
} else t31 = $[102];
|
|
559
|
+
let t32;
|
|
560
|
+
if ($[103] !== t28 || $[104] !== t29 || $[105] !== t30 || $[106] !== t31) {
|
|
561
|
+
t32 = /* @__PURE__ */ jsxs("div", {
|
|
562
|
+
className: MediaField_module_default.field,
|
|
563
|
+
children: [
|
|
564
|
+
t28,
|
|
565
|
+
t29,
|
|
566
|
+
t30,
|
|
567
|
+
t31
|
|
568
|
+
]
|
|
569
|
+
});
|
|
570
|
+
$[103] = t28;
|
|
571
|
+
$[104] = t29;
|
|
572
|
+
$[105] = t30;
|
|
573
|
+
$[106] = t31;
|
|
574
|
+
$[107] = t32;
|
|
575
|
+
} else t32 = $[107];
|
|
576
|
+
let t33;
|
|
577
|
+
if ($[108] !== accept || $[109] !== add || $[110] !== canPick || $[111] !== chooseLabel || $[112] !== cropStep || $[113] !== intl || $[114] !== maxSize || $[115] !== media || $[116] !== multiple || $[117] !== picking || $[118] !== refreshInterval || $[119] !== sources || $[120] !== stateKey || $[121] !== uploadSource) {
|
|
578
|
+
t33 = canPick ? /* @__PURE__ */ jsx(MediaPicker, {
|
|
579
|
+
isOpen: picking,
|
|
580
|
+
onOpenChange: setPicking,
|
|
581
|
+
sources,
|
|
582
|
+
multiple,
|
|
583
|
+
accept,
|
|
584
|
+
maxSize,
|
|
585
|
+
value: media,
|
|
586
|
+
title: intl.formatMessage(chooseLabel),
|
|
587
|
+
...cropStep ? { confirmLabel: intl.formatMessage(mediaMessages.imageNextCrop) } : {},
|
|
588
|
+
uploadSource,
|
|
589
|
+
refreshInterval,
|
|
590
|
+
...stateKey !== void 0 ? { stateKey } : {},
|
|
591
|
+
onSelect: (picked_0) => {
|
|
592
|
+
setProblems([]);
|
|
593
|
+
const [first] = picked_0;
|
|
594
|
+
if (cropStep && picked_0.length === 1 && first !== void 0 && editedImageOf(first) !== null) {
|
|
595
|
+
setEditing({ picked: first });
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
add(picked_0);
|
|
599
|
+
}
|
|
600
|
+
}) : null;
|
|
601
|
+
$[108] = accept;
|
|
602
|
+
$[109] = add;
|
|
603
|
+
$[110] = canPick;
|
|
604
|
+
$[111] = chooseLabel;
|
|
605
|
+
$[112] = cropStep;
|
|
606
|
+
$[113] = intl;
|
|
607
|
+
$[114] = maxSize;
|
|
608
|
+
$[115] = media;
|
|
609
|
+
$[116] = multiple;
|
|
610
|
+
$[117] = picking;
|
|
611
|
+
$[118] = refreshInterval;
|
|
612
|
+
$[119] = sources;
|
|
613
|
+
$[120] = stateKey;
|
|
614
|
+
$[121] = uploadSource;
|
|
615
|
+
$[122] = t33;
|
|
616
|
+
} else t33 = $[122];
|
|
617
|
+
let t34;
|
|
618
|
+
if ($[123] !== add || $[124] !== editable || $[125] !== edited || $[126] !== editedImage || $[127] !== editing || $[128] !== imageOptions || $[129] !== imageRatios || $[130] !== intl || $[131] !== resource || $[132] !== set || $[133] !== tools) {
|
|
619
|
+
t34 = imageOptions !== null && editable && edited !== null && editedImage !== null && editing !== null ? /* @__PURE__ */ jsx(ImageEditorDialog, {
|
|
620
|
+
isOpen: true,
|
|
621
|
+
onOpenChange: (isOpen) => {
|
|
622
|
+
if (!isOpen) setEditing(null);
|
|
623
|
+
},
|
|
624
|
+
image: editedImage,
|
|
625
|
+
value: "key" in editing ? edited.transform ?? null : null,
|
|
626
|
+
base: imageOptions.transformBase === "original" ? "original" : "media",
|
|
627
|
+
canChooseBase: imageOptions.transformBase === "choose",
|
|
628
|
+
tools,
|
|
629
|
+
ratios: imageRatios,
|
|
630
|
+
enforceRatios: imageOptions.enforceRatios === true,
|
|
631
|
+
cropRequired: imageOptions.cropRequired === true,
|
|
632
|
+
..."picked" in editing ? {
|
|
633
|
+
title: intl.formatMessage(mediaMessages.imageCropForUse),
|
|
634
|
+
applyLabel: intl.formatMessage(mediaMessages.imageUseCrop),
|
|
635
|
+
onBack: () => {
|
|
636
|
+
setEditing(null);
|
|
637
|
+
setPicking(true);
|
|
638
|
+
}
|
|
639
|
+
} : {},
|
|
640
|
+
onApply: (transform_0) => {
|
|
641
|
+
const next_0 = withTransform(edited, transform_0);
|
|
642
|
+
if ("picked" in editing) add([next_0]);
|
|
643
|
+
else set(latest.current.map((entry_4) => keyOf(entry_4, resource) === editing.key ? next_0 : entry_4));
|
|
644
|
+
}
|
|
645
|
+
}) : null;
|
|
646
|
+
$[123] = add;
|
|
647
|
+
$[124] = editable;
|
|
648
|
+
$[125] = edited;
|
|
649
|
+
$[126] = editedImage;
|
|
650
|
+
$[127] = editing;
|
|
651
|
+
$[128] = imageOptions;
|
|
652
|
+
$[129] = imageRatios;
|
|
653
|
+
$[130] = intl;
|
|
654
|
+
$[131] = resource;
|
|
655
|
+
$[132] = set;
|
|
656
|
+
$[133] = tools;
|
|
657
|
+
$[134] = t34;
|
|
658
|
+
} else t34 = $[134];
|
|
659
|
+
let t35;
|
|
660
|
+
if ($[135] !== className || $[136] !== descriptionClassName || $[137] !== disabled || $[138] !== errorsClassName || $[139] !== label || $[140] !== labelClassName || $[141] !== required || $[142] !== t26 || $[143] !== t27 || $[144] !== t32 || $[145] !== t33 || $[146] !== t34) {
|
|
661
|
+
t35 = /* @__PURE__ */ jsxs(Fieldset, {
|
|
662
|
+
legend: label,
|
|
663
|
+
description: t26,
|
|
664
|
+
errors: t27,
|
|
665
|
+
isRequired: required,
|
|
666
|
+
isDisabled: disabled,
|
|
667
|
+
className,
|
|
668
|
+
legendClassName: labelClassName,
|
|
669
|
+
descriptionClassName,
|
|
670
|
+
errorsClassName,
|
|
671
|
+
children: [
|
|
672
|
+
t32,
|
|
673
|
+
t33,
|
|
674
|
+
t34
|
|
675
|
+
]
|
|
676
|
+
});
|
|
677
|
+
$[135] = className;
|
|
678
|
+
$[136] = descriptionClassName;
|
|
679
|
+
$[137] = disabled;
|
|
680
|
+
$[138] = errorsClassName;
|
|
681
|
+
$[139] = label;
|
|
682
|
+
$[140] = labelClassName;
|
|
683
|
+
$[141] = required;
|
|
684
|
+
$[142] = t26;
|
|
685
|
+
$[143] = t27;
|
|
686
|
+
$[144] = t32;
|
|
687
|
+
$[145] = t33;
|
|
688
|
+
$[146] = t34;
|
|
689
|
+
$[147] = t35;
|
|
690
|
+
} else t35 = $[147];
|
|
691
|
+
return t35;
|
|
692
|
+
}
|
|
693
|
+
/** The props of `ImageField`: those of `MediaField`, with the options of an `image` field. */
|
|
694
|
+
function _temp4(constraint) {
|
|
695
|
+
return /* @__PURE__ */ jsx(Badge, { children: constraint }, constraint);
|
|
696
|
+
}
|
|
697
|
+
function _temp3(reference_1, transform) {
|
|
698
|
+
const { transform: _previous, ...rest } = reference_1;
|
|
699
|
+
return transform === null || transform === void 0 ? rest : {
|
|
700
|
+
...rest,
|
|
701
|
+
transform
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* An `image` field (decision 0031): a `media` field for images, with the image editor. It accepts
|
|
706
|
+
* `image/*` by default. Each image shows as it is rendered for this use, with Edit, which opens
|
|
707
|
+
* the editor on its transform. When a crop is required, the editor is the step right after the
|
|
708
|
+
* pick of one image. With `transforms={false}`, the field has no editor (decision 0087).
|
|
709
|
+
*/
|
|
710
|
+
function ImageField(props) {
|
|
711
|
+
const $ = c(38);
|
|
712
|
+
let cropRequired;
|
|
713
|
+
let enforceRatios;
|
|
714
|
+
let focalPoint;
|
|
715
|
+
let ratios;
|
|
716
|
+
let rest;
|
|
717
|
+
let rotate;
|
|
718
|
+
let t0;
|
|
719
|
+
let transformBase;
|
|
720
|
+
let transforms;
|
|
721
|
+
if ($[0] !== props) {
|
|
722
|
+
({ratios, enforceRatios, cropRequired, rotate, focalPoint, transformBase, transforms, accept: t0, ...rest} = props);
|
|
723
|
+
$[0] = props;
|
|
724
|
+
$[1] = cropRequired;
|
|
725
|
+
$[2] = enforceRatios;
|
|
726
|
+
$[3] = focalPoint;
|
|
727
|
+
$[4] = ratios;
|
|
728
|
+
$[5] = rest;
|
|
729
|
+
$[6] = rotate;
|
|
730
|
+
$[7] = t0;
|
|
731
|
+
$[8] = transformBase;
|
|
732
|
+
$[9] = transforms;
|
|
733
|
+
} else {
|
|
734
|
+
cropRequired = $[1];
|
|
735
|
+
enforceRatios = $[2];
|
|
736
|
+
focalPoint = $[3];
|
|
737
|
+
ratios = $[4];
|
|
738
|
+
rest = $[5];
|
|
739
|
+
rotate = $[6];
|
|
740
|
+
t0 = $[7];
|
|
741
|
+
transformBase = $[8];
|
|
742
|
+
transforms = $[9];
|
|
743
|
+
}
|
|
744
|
+
let t1;
|
|
745
|
+
if ($[10] !== t0) {
|
|
746
|
+
t1 = t0 === void 0 ? ["image/*"] : t0;
|
|
747
|
+
$[10] = t0;
|
|
748
|
+
$[11] = t1;
|
|
749
|
+
} else t1 = $[11];
|
|
750
|
+
const accept = t1;
|
|
751
|
+
let t2;
|
|
752
|
+
if ($[12] !== ratios) {
|
|
753
|
+
t2 = ratios !== void 0 ? { ratios } : {};
|
|
754
|
+
$[12] = ratios;
|
|
755
|
+
$[13] = t2;
|
|
756
|
+
} else t2 = $[13];
|
|
757
|
+
let t3;
|
|
758
|
+
if ($[14] !== enforceRatios) {
|
|
759
|
+
t3 = enforceRatios !== void 0 ? { enforceRatios } : {};
|
|
760
|
+
$[14] = enforceRatios;
|
|
761
|
+
$[15] = t3;
|
|
762
|
+
} else t3 = $[15];
|
|
763
|
+
let t4;
|
|
764
|
+
if ($[16] !== cropRequired) {
|
|
765
|
+
t4 = cropRequired !== void 0 ? { cropRequired } : {};
|
|
766
|
+
$[16] = cropRequired;
|
|
767
|
+
$[17] = t4;
|
|
768
|
+
} else t4 = $[17];
|
|
769
|
+
let t5;
|
|
770
|
+
if ($[18] !== rotate) {
|
|
771
|
+
t5 = rotate !== void 0 ? { rotate } : {};
|
|
772
|
+
$[18] = rotate;
|
|
773
|
+
$[19] = t5;
|
|
774
|
+
} else t5 = $[19];
|
|
775
|
+
let t6;
|
|
776
|
+
if ($[20] !== focalPoint) {
|
|
777
|
+
t6 = focalPoint !== void 0 ? { focalPoint } : {};
|
|
778
|
+
$[20] = focalPoint;
|
|
779
|
+
$[21] = t6;
|
|
780
|
+
} else t6 = $[21];
|
|
781
|
+
let t7;
|
|
782
|
+
if ($[22] !== transformBase) {
|
|
783
|
+
t7 = transformBase !== void 0 ? { transformBase } : {};
|
|
784
|
+
$[22] = transformBase;
|
|
785
|
+
$[23] = t7;
|
|
786
|
+
} else t7 = $[23];
|
|
787
|
+
let t8;
|
|
788
|
+
if ($[24] !== transforms) {
|
|
789
|
+
t8 = transforms !== void 0 ? { transforms } : {};
|
|
790
|
+
$[24] = transforms;
|
|
791
|
+
$[25] = t8;
|
|
792
|
+
} else t8 = $[25];
|
|
793
|
+
let t9;
|
|
794
|
+
if ($[26] !== t2 || $[27] !== t3 || $[28] !== t4 || $[29] !== t5 || $[30] !== t6 || $[31] !== t7 || $[32] !== t8) {
|
|
795
|
+
t9 = {
|
|
796
|
+
...t2,
|
|
797
|
+
...t3,
|
|
798
|
+
...t4,
|
|
799
|
+
...t5,
|
|
800
|
+
...t6,
|
|
801
|
+
...t7,
|
|
802
|
+
...t8
|
|
803
|
+
};
|
|
804
|
+
$[26] = t2;
|
|
805
|
+
$[27] = t3;
|
|
806
|
+
$[28] = t4;
|
|
807
|
+
$[29] = t5;
|
|
808
|
+
$[30] = t6;
|
|
809
|
+
$[31] = t7;
|
|
810
|
+
$[32] = t8;
|
|
811
|
+
$[33] = t9;
|
|
812
|
+
} else t9 = $[33];
|
|
813
|
+
const image = t9;
|
|
814
|
+
const t10 = rest;
|
|
815
|
+
let t11;
|
|
816
|
+
if ($[34] !== accept || $[35] !== image || $[36] !== t10) {
|
|
817
|
+
t11 = /* @__PURE__ */ jsx(MediaField, {
|
|
818
|
+
...t10,
|
|
819
|
+
accept,
|
|
820
|
+
image
|
|
821
|
+
});
|
|
822
|
+
$[34] = accept;
|
|
823
|
+
$[35] = image;
|
|
824
|
+
$[36] = t10;
|
|
825
|
+
$[37] = t11;
|
|
826
|
+
} else t11 = $[37];
|
|
827
|
+
return t11;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* The options of an `image` field of a definition: its `crop` rule (enforced ratios, a required
|
|
831
|
+
* crop), its suggested `ratios`, the tools and base of its editor, and whether its values keep
|
|
832
|
+
* transforms.
|
|
833
|
+
*/
|
|
834
|
+
function getImageOptions(field) {
|
|
835
|
+
const rule = field.rules?.find((candidate) => candidate.rule === "crop");
|
|
836
|
+
const value = rule !== void 0 && "value" in rule && typeof rule.value === "object" && rule.value !== null ? rule.value : {};
|
|
837
|
+
const enforced = Array.isArray(value.ratios) ? value.ratios.filter((ratio) => typeof ratio === "string") : [];
|
|
838
|
+
return {
|
|
839
|
+
ratios: enforced.length > 0 ? enforced : field.ratios ?? [],
|
|
840
|
+
enforceRatios: enforced.length > 0,
|
|
841
|
+
cropRequired: value.required === true,
|
|
842
|
+
rotate: field.rotate !== false,
|
|
843
|
+
focalPoint: field.focalPoint !== false,
|
|
844
|
+
transformBase: field.transformBase ?? "media",
|
|
845
|
+
transforms: field.transforms !== false
|
|
846
|
+
};
|
|
265
847
|
}
|
|
266
848
|
/**
|
|
267
|
-
* The registry entry of the `media`
|
|
268
|
-
*
|
|
269
|
-
* with the adapter of `@panneau/data` and the upload source
|
|
270
|
-
*
|
|
849
|
+
* The registry entry of the `media` and `image` types: the picker on the libraries the field allows
|
|
850
|
+
* (`getMediaLibraries()`), uploads to the first one (`getLibrary()`), `multiple`, `accept` (or
|
|
851
|
+
* its `accept` rule) and `maxSize` rule, with the adapter of `@panneau/data` and the upload source
|
|
852
|
+
* of the fields context. The picker opens again where the user left it in the same libraries.
|
|
853
|
+
* Without a library, the field shows its media and can't add any. An `image` field also gets its
|
|
854
|
+
* options (`getImageOptions()`), and accepts `image/*` by default.
|
|
271
855
|
*/
|
|
272
856
|
function MediaFieldEntry(props) {
|
|
273
|
-
const $ = c(
|
|
857
|
+
const $ = c(14);
|
|
274
858
|
const { field, value, onChange } = props;
|
|
275
859
|
const { definition } = usePanneau();
|
|
860
|
+
const adapter = useOptionalDataAdapter();
|
|
276
861
|
let common;
|
|
277
862
|
let t0;
|
|
278
|
-
if ($[0] !==
|
|
863
|
+
if ($[0] !== adapter || $[1] !== definition || $[2] !== field || $[3] !== props || $[4] !== value) {
|
|
279
864
|
const library = getLibrary(definition, field.resource);
|
|
280
865
|
const itemTitle = library?.itemTitle ?? "name";
|
|
866
|
+
let t1;
|
|
867
|
+
if ($[7] !== definition?.resources) {
|
|
868
|
+
t1 = (id) => definition?.resources.find((candidate) => candidate.id === id) ?? [];
|
|
869
|
+
$[7] = definition?.resources;
|
|
870
|
+
$[8] = t1;
|
|
871
|
+
} else t1 = $[8];
|
|
872
|
+
const libraries = getMediaLibraries(definition, field).flatMap(t1);
|
|
873
|
+
const sources = adapter !== null ? libraries.map((candidate_0) => createResourceMediaSource(adapter, candidate_0)) : [];
|
|
874
|
+
const image = field.type === "image" ? getImageOptions(field) : null;
|
|
281
875
|
common = {
|
|
282
876
|
...getFieldProps(props),
|
|
283
|
-
resource: library?.id ?? field.resource
|
|
877
|
+
resource: library?.id ?? (typeof field.resource === "string" ? field.resource : ""),
|
|
284
878
|
itemTitle,
|
|
285
|
-
accept: getAccept(field),
|
|
879
|
+
accept: getAccept(field) ?? (image !== null ? ["image/*"] : null),
|
|
286
880
|
maxSize: getMaxSize(field),
|
|
881
|
+
sources,
|
|
882
|
+
image,
|
|
883
|
+
stateKey: `panneau.media.${libraries.map(_temp5).join(",")}`,
|
|
287
884
|
...library === null ? { adapter: null } : {}
|
|
288
885
|
};
|
|
289
886
|
t0 = toMediaReferences(value, itemTitle);
|
|
290
|
-
$[0] =
|
|
291
|
-
$[1] =
|
|
292
|
-
$[2] =
|
|
293
|
-
$[3] =
|
|
294
|
-
$[4] =
|
|
295
|
-
$[5] =
|
|
887
|
+
$[0] = adapter;
|
|
888
|
+
$[1] = definition;
|
|
889
|
+
$[2] = field;
|
|
890
|
+
$[3] = props;
|
|
891
|
+
$[4] = value;
|
|
892
|
+
$[5] = common;
|
|
893
|
+
$[6] = t0;
|
|
296
894
|
} else {
|
|
297
|
-
common = $[
|
|
298
|
-
t0 = $[
|
|
895
|
+
common = $[5];
|
|
896
|
+
t0 = $[6];
|
|
299
897
|
}
|
|
300
898
|
const references = t0;
|
|
301
899
|
let t1;
|
|
302
|
-
if ($[
|
|
900
|
+
if ($[9] !== common || $[10] !== field.multiple || $[11] !== onChange || $[12] !== references) {
|
|
303
901
|
t1 = field.multiple === true ? /* @__PURE__ */ jsx(MediaField, {
|
|
304
902
|
...common,
|
|
305
903
|
multiple: true,
|
|
@@ -310,15 +908,18 @@ function MediaFieldEntry(props) {
|
|
|
310
908
|
value: references[0] ?? null,
|
|
311
909
|
onChange
|
|
312
910
|
});
|
|
313
|
-
$[
|
|
314
|
-
$[
|
|
315
|
-
$[
|
|
316
|
-
$[
|
|
317
|
-
$[
|
|
318
|
-
} else t1 = $[
|
|
911
|
+
$[9] = common;
|
|
912
|
+
$[10] = field.multiple;
|
|
913
|
+
$[11] = onChange;
|
|
914
|
+
$[12] = references;
|
|
915
|
+
$[13] = t1;
|
|
916
|
+
} else t1 = $[13];
|
|
319
917
|
return t1;
|
|
320
918
|
}
|
|
919
|
+
function _temp5(candidate_1) {
|
|
920
|
+
return candidate_1.id;
|
|
921
|
+
}
|
|
321
922
|
//#endregion
|
|
322
|
-
export { MediaField, MediaFieldEntry, getLibrary, isProcessing, toMediaReference, toMediaReferences };
|
|
923
|
+
export { ImageField, MediaField, MediaFieldEntry, getImageOptions, getLibrary, isProcessing, toMediaReference, toMediaReferences };
|
|
323
924
|
|
|
324
925
|
//# sourceMappingURL=MediaField.js.map
|