@panneau/fields 5.0.0-alpha.6 → 5.0.0-alpha.8
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/boolean/BooleanField.d.ts +1 -1
- package/dist/boolean/BooleanField.js +78 -17
- package/dist/boolean/BooleanField.js.map +1 -1
- package/dist/boolean/index.d.ts +1 -1
- package/dist/color/ColorField.d.ts +2 -2
- package/dist/color/ColorField.js.map +1 -1
- package/dist/color/index.d.ts +1 -1
- package/dist/date/DateField.d.ts +1 -1
- package/dist/date/DateField.js.map +1 -1
- package/dist/date/index.d.ts +1 -1
- package/dist/datetime/DateTimeField.d.ts +1 -1
- package/dist/datetime/DateTimeField.js +107 -20
- package/dist/datetime/DateTimeField.js.map +1 -1
- package/dist/datetime/index.d.ts +1 -1
- package/dist/duration/DurationField.d.ts +1 -1
- package/dist/duration/DurationField.js +126 -41
- package/dist/duration/DurationField.js.map +1 -1
- package/dist/duration/index.d.ts +1 -1
- package/dist/email/EmailField.d.ts +2 -2
- package/dist/email/EmailField.js.map +1 -1
- package/dist/email/index.d.ts +1 -1
- package/dist/embed/EmbedField.d.ts +2 -2
- package/dist/embed/EmbedField.js +185 -69
- package/dist/embed/EmbedField.js.map +1 -1
- package/dist/embed/index.d.ts +2 -2
- package/dist/file/FileField.d.ts +2 -2
- package/dist/file/FileField.d.ts.map +1 -1
- package/dist/file/FileField.js +167 -77
- package/dist/file/FileField.js.map +1 -1
- package/dist/file/index.d.ts +2 -2
- package/dist/group/GroupField.d.ts +1 -1
- package/dist/group/GroupField.js.map +1 -1
- package/dist/group/index.d.ts +1 -1
- package/dist/index.d.ts +18 -18
- package/dist/json/JsonField.d.ts +1 -1
- package/dist/json/JsonField.js +104 -22
- package/dist/json/JsonField.js.map +1 -1
- package/dist/json/index.d.ts +1 -1
- package/dist/locales/index.js.map +1 -1
- package/dist/localized/LocalizedField.d.ts +1 -1
- package/dist/localized/LocalizedField.js.map +1 -1
- package/dist/localized/index.d.ts +1 -1
- package/dist/location/LocationField.d.ts +3 -3
- package/dist/location/LocationField.d.ts.map +1 -1
- package/dist/location/LocationField.js +351 -138
- package/dist/location/LocationField.js.map +1 -1
- package/dist/location/LocationMap.d.ts +1 -1
- package/dist/location/LocationMap.d.ts.map +1 -1
- package/dist/location/LocationMap.js +155 -65
- package/dist/location/LocationMap.js.map +1 -1
- package/dist/location/index.d.ts +4 -4
- package/dist/location/leafletCss.js.map +1 -1
- package/dist/location/nominatim.d.ts +1 -1
- package/dist/location/nominatim.js.map +1 -1
- package/dist/missing/MissingField.d.ts +4 -3
- package/dist/missing/MissingField.d.ts.map +1 -1
- package/dist/missing/MissingField.js +3 -2
- package/dist/missing/MissingField.js.map +1 -1
- package/dist/number/NumberField.d.ts +1 -1
- package/dist/number/NumberField.js.map +1 -1
- package/dist/number/index.d.ts +1 -1
- package/dist/range/RangeField.d.ts +1 -1
- package/dist/range/RangeField.js +82 -11
- package/dist/range/RangeField.js.map +1 -1
- package/dist/range/index.d.ts +1 -1
- package/dist/relation/RelationField.d.ts +2 -2
- package/dist/relation/RelationField.js +485 -145
- package/dist/relation/RelationField.js.map +1 -1
- package/dist/relation/index.d.ts +2 -2
- package/dist/repeater/RepeaterField.d.ts +1 -1
- package/dist/repeater/RepeaterField.js +118 -34
- package/dist/repeater/RepeaterField.js.map +1 -1
- package/dist/repeater/index.d.ts +1 -1
- package/dist/select/SelectField.d.ts +1 -1
- package/dist/select/SelectField.js.map +1 -1
- package/dist/select/index.d.ts +1 -1
- package/dist/shared/DefinitionField.d.ts +1 -1
- package/dist/shared/DefinitionField.js.map +1 -1
- package/dist/shared/builtIn.d.ts +1 -1
- package/dist/shared/builtIn.js.map +1 -1
- package/dist/shared/check.js.map +1 -1
- package/dist/shared/context.d.ts +6 -6
- package/dist/shared/context.js.map +1 -1
- package/dist/shared/cx.js.map +1 -1
- package/dist/shared/dates.js.map +1 -1
- package/dist/shared/embed.js.map +1 -1
- package/dist/shared/entry.d.ts +1 -1
- package/dist/shared/entry.js.map +1 -1
- package/dist/shared/relation.js.map +1 -1
- package/dist/slug/SlugField.d.ts +2 -2
- package/dist/slug/SlugField.d.ts.map +1 -1
- package/dist/slug/SlugField.js +184 -36
- package/dist/slug/SlugField.js.map +1 -1
- package/dist/slug/index.d.ts +1 -1
- package/dist/tags/TagsField.d.ts +1 -1
- package/dist/tags/TagsField.js.map +1 -1
- package/dist/tags/index.d.ts +1 -1
- package/dist/tel/TelField.d.ts +2 -2
- package/dist/tel/TelField.js.map +1 -1
- package/dist/tel/index.d.ts +1 -1
- package/dist/text/TextField.d.ts +1 -1
- package/dist/text/TextField.js.map +1 -1
- package/dist/text/index.d.ts +1 -1
- package/dist/textarea/TextAreaField.d.ts +1 -1
- package/dist/textarea/TextAreaField.js.map +1 -1
- package/dist/textarea/index.d.ts +1 -1
- package/dist/time/TimeField.d.ts +1 -1
- package/dist/time/TimeField.js +64 -10
- package/dist/time/TimeField.js.map +1 -1
- package/dist/time/index.d.ts +1 -1
- package/dist/upload/FilePicker.js +107 -24
- package/dist/upload/FilePicker.js.map +1 -1
- package/dist/upload/UploadList.d.ts +1 -1
- package/dist/upload/UploadList.js.map +1 -1
- package/dist/upload/files.js.map +1 -1
- package/dist/upload/useRejectionMessage.d.ts +1 -1
- package/dist/upload/useRejectionMessage.js.map +1 -1
- package/dist/upload/useUploads.d.ts +1 -1
- package/dist/upload/useUploads.js.map +1 -1
- package/dist/uppy/index.d.ts +2 -2
- package/dist/uppy/uploader.d.ts +1 -1
- package/dist/uppy/uploader.js.map +1 -1
- package/dist/url/UrlField.d.ts +2 -2
- package/dist/url/UrlField.js +69 -14
- package/dist/url/UrlField.js.map +1 -1
- package/dist/url/index.d.ts +1 -1
- package/package.json +6 -6
package/dist/file/FileField.js
CHANGED
|
@@ -37,102 +37,192 @@ function toFiles(value) {
|
|
|
37
37
|
* value, and is added to a multiple one.
|
|
38
38
|
*/
|
|
39
39
|
function FileField(props) {
|
|
40
|
+
const $ = c(42);
|
|
40
41
|
const intl = usePanneauIntl();
|
|
41
42
|
const context = useFieldsContext();
|
|
42
|
-
const { accept
|
|
43
|
+
const { accept: t0, maxSize: t1, label, description, errors: t2, disabled, readOnly, required, className, labelClassName, descriptionClassName, errorsClassName } = props;
|
|
44
|
+
const accept = t0 === void 0 ? null : t0;
|
|
45
|
+
const maxSize = t1 === void 0 ? null : t1;
|
|
46
|
+
let t3;
|
|
47
|
+
if ($[0] !== t2) {
|
|
48
|
+
t3 = t2 === void 0 ? [] : t2;
|
|
49
|
+
$[0] = t2;
|
|
50
|
+
$[1] = t3;
|
|
51
|
+
} else t3 = $[1];
|
|
52
|
+
const errors = t3;
|
|
53
|
+
const uploadSource = props.uploadSource === void 0 ? context.uploadSource : props.uploadSource;
|
|
43
54
|
const multiple = props.multiple === true;
|
|
44
|
-
|
|
55
|
+
let t4;
|
|
56
|
+
if ($[2] !== props.value) {
|
|
57
|
+
t4 = toFiles(props.value);
|
|
58
|
+
$[2] = props.value;
|
|
59
|
+
$[3] = t4;
|
|
60
|
+
} else t4 = $[3];
|
|
61
|
+
const files = t4;
|
|
45
62
|
const editable = disabled !== true && readOnly !== true;
|
|
46
|
-
|
|
63
|
+
let t5;
|
|
64
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
65
|
+
t5 = [];
|
|
66
|
+
$[4] = t5;
|
|
67
|
+
} else t5 = $[4];
|
|
68
|
+
const [rejections, setRejections] = useState(t5);
|
|
47
69
|
const rejectionMessage = useRejectionMessage(maxSize);
|
|
48
70
|
const latest = useRef(files);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
let t6;
|
|
72
|
+
if ($[5] !== files) {
|
|
73
|
+
t6 = () => {
|
|
74
|
+
latest.current = files;
|
|
75
|
+
};
|
|
76
|
+
$[5] = files;
|
|
77
|
+
$[6] = t6;
|
|
78
|
+
} else t6 = $[6];
|
|
79
|
+
useEffect(t6);
|
|
52
80
|
const set = (next) => {
|
|
53
81
|
latest.current = next;
|
|
54
82
|
if (props.multiple === true) props.onChange?.(next.length > 0 ? next : null);
|
|
55
83
|
else props.onChange?.(next[0] ?? null);
|
|
56
84
|
};
|
|
85
|
+
let t7;
|
|
86
|
+
if ($[7] !== rejectionMessage) {
|
|
87
|
+
t7 = (file_0, reason) => setRejections((current) => [...current, rejectionMessage(file_0, reason)]);
|
|
88
|
+
$[7] = rejectionMessage;
|
|
89
|
+
$[8] = t7;
|
|
90
|
+
} else t7 = $[8];
|
|
57
91
|
const upload = useUploads({
|
|
58
92
|
source: uploadSource,
|
|
59
93
|
accept,
|
|
60
94
|
maxSize,
|
|
61
95
|
onUploaded: (file) => set(multiple ? [...latest.current, file] : [file]),
|
|
62
|
-
onRejected:
|
|
96
|
+
onRejected: t7
|
|
63
97
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
98
|
+
const T0 = Fieldset;
|
|
99
|
+
let t8;
|
|
100
|
+
if ($[9] !== errors || $[10] !== rejections) {
|
|
101
|
+
t8 = [...errors, ...rejections];
|
|
102
|
+
$[9] = errors;
|
|
103
|
+
$[10] = rejections;
|
|
104
|
+
$[11] = t8;
|
|
105
|
+
} else t8 = $[11];
|
|
106
|
+
const t9 = FileField_module_default;
|
|
107
|
+
const t10 = files.length > 0 ? /* @__PURE__ */ jsx("ul", {
|
|
108
|
+
className: FileField_module_default.files,
|
|
109
|
+
children: files.map((file_1, index) => {
|
|
110
|
+
const { name } = file_1;
|
|
111
|
+
const url = fileUrl(file_1);
|
|
112
|
+
const size = fileSize(file_1);
|
|
113
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
114
|
+
className: FileField_module_default.file,
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsx(FileText, {
|
|
117
|
+
"aria-hidden": true,
|
|
118
|
+
className: FileField_module_default.icon
|
|
119
|
+
}),
|
|
120
|
+
url !== null ? /* @__PURE__ */ jsx("a", {
|
|
121
|
+
href: url,
|
|
122
|
+
className: FileField_module_default.name,
|
|
123
|
+
target: "_blank",
|
|
124
|
+
rel: "noreferrer",
|
|
125
|
+
children: name
|
|
126
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
127
|
+
className: FileField_module_default.name,
|
|
128
|
+
children: name
|
|
129
|
+
}),
|
|
130
|
+
size !== null ? /* @__PURE__ */ jsx("span", {
|
|
131
|
+
className: FileField_module_default.size,
|
|
132
|
+
children: formatSize(size, intl.locale)
|
|
133
|
+
}) : null,
|
|
134
|
+
editable ? /* @__PURE__ */ jsx(IconButton, {
|
|
135
|
+
icon: X,
|
|
136
|
+
size: "sm",
|
|
137
|
+
label: intl.formatMessage(messages.removeFile, { name }),
|
|
138
|
+
onPress: () => set(latest.current.filter((_, at) => at !== index))
|
|
139
|
+
}) : null
|
|
140
|
+
]
|
|
141
|
+
}, `${String(index)}-${name}`);
|
|
142
|
+
})
|
|
143
|
+
}) : upload.items.length === 0 ? /* @__PURE__ */ jsx("span", {
|
|
144
|
+
className: FileField_module_default.none,
|
|
145
|
+
children: intl.formatMessage(messages.noFile)
|
|
146
|
+
}) : null;
|
|
147
|
+
let t11;
|
|
148
|
+
if ($[12] !== upload.cancel || $[13] !== upload.items || $[14] !== upload.pause || $[15] !== upload.resume || $[16] !== upload.retry) {
|
|
149
|
+
t11 = /* @__PURE__ */ jsx(UploadList, {
|
|
150
|
+
items: upload.items,
|
|
151
|
+
onPause: upload.pause,
|
|
152
|
+
onResume: upload.resume,
|
|
153
|
+
onCancel: upload.cancel,
|
|
154
|
+
onRetry: upload.retry
|
|
155
|
+
});
|
|
156
|
+
$[12] = upload.cancel;
|
|
157
|
+
$[13] = upload.items;
|
|
158
|
+
$[14] = upload.pause;
|
|
159
|
+
$[15] = upload.resume;
|
|
160
|
+
$[16] = upload.retry;
|
|
161
|
+
$[17] = t11;
|
|
162
|
+
} else t11 = $[17];
|
|
163
|
+
let t12;
|
|
164
|
+
if ($[18] !== accept || $[19] !== editable || $[20] !== files.length || $[21] !== intl || $[22] !== multiple || $[23] !== upload) {
|
|
165
|
+
t12 = editable ? /* @__PURE__ */ jsx(FilePicker, {
|
|
166
|
+
accept,
|
|
167
|
+
multiple,
|
|
168
|
+
...!multiple && files.length > 0 ? { label: intl.formatMessage(messages.replaceFile) } : {},
|
|
169
|
+
onSelect: (selected) => {
|
|
170
|
+
setRejections([]);
|
|
171
|
+
upload.add(selected);
|
|
172
|
+
}
|
|
173
|
+
}) : null;
|
|
174
|
+
$[18] = accept;
|
|
175
|
+
$[19] = editable;
|
|
176
|
+
$[20] = files.length;
|
|
177
|
+
$[21] = intl;
|
|
178
|
+
$[22] = multiple;
|
|
179
|
+
$[23] = upload;
|
|
180
|
+
$[24] = t12;
|
|
181
|
+
} else t12 = $[24];
|
|
182
|
+
let t13;
|
|
183
|
+
if ($[25] !== t10 || $[26] !== t11 || $[27] !== t12 || $[28] !== t9.field) {
|
|
184
|
+
t13 = /* @__PURE__ */ jsxs("div", {
|
|
185
|
+
className: t9.field,
|
|
76
186
|
children: [
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const { name } = file_1;
|
|
81
|
-
const url = fileUrl(file_1);
|
|
82
|
-
const size = fileSize(file_1);
|
|
83
|
-
return /* @__PURE__ */ jsxs("li", {
|
|
84
|
-
className: FileField_module_default.file,
|
|
85
|
-
children: [
|
|
86
|
-
/* @__PURE__ */ jsx(FileText, {
|
|
87
|
-
"aria-hidden": true,
|
|
88
|
-
className: FileField_module_default.icon
|
|
89
|
-
}),
|
|
90
|
-
url !== null ? /* @__PURE__ */ jsx("a", {
|
|
91
|
-
href: url,
|
|
92
|
-
className: FileField_module_default.name,
|
|
93
|
-
target: "_blank",
|
|
94
|
-
rel: "noreferrer",
|
|
95
|
-
children: name
|
|
96
|
-
}) : /* @__PURE__ */ jsx("span", {
|
|
97
|
-
className: FileField_module_default.name,
|
|
98
|
-
children: name
|
|
99
|
-
}),
|
|
100
|
-
size !== null ? /* @__PURE__ */ jsx("span", {
|
|
101
|
-
className: FileField_module_default.size,
|
|
102
|
-
children: formatSize(size, intl.locale)
|
|
103
|
-
}) : null,
|
|
104
|
-
editable ? /* @__PURE__ */ jsx(IconButton, {
|
|
105
|
-
icon: X,
|
|
106
|
-
size: "sm",
|
|
107
|
-
label: intl.formatMessage(messages.removeFile, { name }),
|
|
108
|
-
onPress: () => set(latest.current.filter((_, at) => at !== index))
|
|
109
|
-
}) : null
|
|
110
|
-
]
|
|
111
|
-
}, `${String(index)}-${name}`);
|
|
112
|
-
})
|
|
113
|
-
}) : upload.items.length === 0 ? /* @__PURE__ */ jsx("span", {
|
|
114
|
-
className: FileField_module_default.none,
|
|
115
|
-
children: intl.formatMessage(messages.noFile)
|
|
116
|
-
}) : null,
|
|
117
|
-
/* @__PURE__ */ jsx(UploadList, {
|
|
118
|
-
items: upload.items,
|
|
119
|
-
onPause: upload.pause,
|
|
120
|
-
onResume: upload.resume,
|
|
121
|
-
onCancel: upload.cancel,
|
|
122
|
-
onRetry: upload.retry
|
|
123
|
-
}),
|
|
124
|
-
editable ? /* @__PURE__ */ jsx(FilePicker, {
|
|
125
|
-
accept,
|
|
126
|
-
multiple,
|
|
127
|
-
...!multiple && files.length > 0 ? { label: intl.formatMessage(messages.replaceFile) } : {},
|
|
128
|
-
onSelect: (selected) => {
|
|
129
|
-
setRejections([]);
|
|
130
|
-
upload.add(selected);
|
|
131
|
-
}
|
|
132
|
-
}) : null
|
|
187
|
+
t10,
|
|
188
|
+
t11,
|
|
189
|
+
t12
|
|
133
190
|
]
|
|
134
|
-
})
|
|
135
|
-
|
|
191
|
+
});
|
|
192
|
+
$[25] = t10;
|
|
193
|
+
$[26] = t11;
|
|
194
|
+
$[27] = t12;
|
|
195
|
+
$[28] = t9.field;
|
|
196
|
+
$[29] = t13;
|
|
197
|
+
} else t13 = $[29];
|
|
198
|
+
let t14;
|
|
199
|
+
if ($[30] !== T0 || $[31] !== className || $[32] !== description || $[33] !== descriptionClassName || $[34] !== disabled || $[35] !== errorsClassName || $[36] !== label || $[37] !== labelClassName || $[38] !== required || $[39] !== t13 || $[40] !== t8) {
|
|
200
|
+
t14 = /* @__PURE__ */ jsx(T0, {
|
|
201
|
+
legend: label,
|
|
202
|
+
description,
|
|
203
|
+
errors: t8,
|
|
204
|
+
isRequired: required,
|
|
205
|
+
isDisabled: disabled,
|
|
206
|
+
className,
|
|
207
|
+
legendClassName: labelClassName,
|
|
208
|
+
descriptionClassName,
|
|
209
|
+
errorsClassName,
|
|
210
|
+
children: t13
|
|
211
|
+
});
|
|
212
|
+
$[30] = T0;
|
|
213
|
+
$[31] = className;
|
|
214
|
+
$[32] = description;
|
|
215
|
+
$[33] = descriptionClassName;
|
|
216
|
+
$[34] = disabled;
|
|
217
|
+
$[35] = errorsClassName;
|
|
218
|
+
$[36] = label;
|
|
219
|
+
$[37] = labelClassName;
|
|
220
|
+
$[38] = required;
|
|
221
|
+
$[39] = t13;
|
|
222
|
+
$[40] = t8;
|
|
223
|
+
$[41] = t14;
|
|
224
|
+
} else t14 = $[41];
|
|
225
|
+
return t14;
|
|
136
226
|
}
|
|
137
227
|
/**
|
|
138
228
|
* The registry entry of the `file` type: the field's `multiple`, `accept` (or its `accept` rule)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileField.js","names":["file","onChange","styles","_c"],"sources":["../../src/file/FileField.tsx"],"sourcesContent":["import { FileText, X } from 'lucide-react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport type { StoredFile } from '@panneau/protocol';\nimport { Fieldset, IconButton, usePanneauIntl } from '@panneau/ui';\n\nimport { useFieldsContext } from '../shared/context';\nimport { getAccept, getFieldProps, getMaxSize } from '../shared/entry';\nimport { messages } from '../shared/messages';\nimport type { FieldEntryProps, FieldProps } from '../shared/types';\nimport { FilePicker } from '../upload/FilePicker';\nimport { UploadList } from '../upload/UploadList';\nimport { formatSize } from '../upload/files';\nimport type { UploadSource, UploadedFile } from '../upload/types';\nimport { useRejectionMessage } from '../upload/useRejectionMessage';\nimport { useUploads } from '../upload/useUploads';\nimport styles from './FileField.module.css';\n\n/**\n * A file of a `file` value: a stored file, as items give it; an upload, once the browser sent the\n * file to storage; or the file itself, sent in a multipart request without direct uploads.\n */\nexport type FileValue = StoredFile | UploadedFile | File;\n\nexport interface FileFieldBaseProps extends Omit<FieldProps<never>, 'value' | 'onChange'> {\n /** Accepted MIME types (`application/pdf`, `image/*`). Others are refused before they are sent. */\n accept?: readonly string[] | null;\n /** Largest file, in bytes. Larger ones are refused before they are sent. */\n maxSize?: number | null;\n /**\n * Where files are uploaded directly to storage. Defaults to the one of the fields context.\n * Without one, the value holds the files themselves, which the adapter sends in\n * `multipart/form-data`.\n */\n uploadSource?: UploadSource | null;\n}\n\nexport interface SingleFileFieldProps extends FileFieldBaseProps {\n multiple?: false;\n value?: FileValue | null;\n onChange?: (value: FileValue | null) => void;\n}\n\nexport interface MultipleFileFieldProps extends FileFieldBaseProps {\n multiple: true;\n value?: readonly FileValue[] | null;\n /** Called with the files. An empty list is `null`. */\n onChange?: (value: FileValue[] | null) => void;\n}\n\nexport type FileFieldProps = SingleFileFieldProps | MultipleFileFieldProps;\n\nfunction fileSize(file: FileValue): number | null {\n return typeof file.size === 'number' ? file.size : null;\n}\n\nfunction fileUrl(file: FileValue): string | null {\n return !(file instanceof Blob) && 'url' in file && typeof file.url === 'string'\n ? file.url\n : null;\n}\n\n/** Whether a value is a file of a `file` value. */\nexport function isFileValue(value: unknown): value is FileValue {\n if (typeof File !== 'undefined' && value instanceof File) {\n return true;\n }\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { name?: unknown }).name === 'string'\n );\n}\n\n/** The files of a value, single or multiple. */\nexport function toFiles(value: unknown): FileValue[] {\n if (Array.isArray(value)) {\n return value.filter(isFileValue);\n }\n return isFileValue(value) ? [value] : [];\n}\n\n/**\n * Files that belong to an item, outside the media library: an attachment, a PDF, a CSV (the\n * `file` type). With an upload source, files go directly to storage, and the value references\n * each upload (`{ upload, name, mime, size }`). Without one, the value is the file itself. Items\n * give stored files, which the field shows with a link. A new file replaces the file of a single\n * value, and is added to a multiple one.\n */\nexport function FileField(props: FileFieldProps) {\n const intl = usePanneauIntl();\n const context = useFieldsContext();\n const {\n accept = null,\n maxSize = null,\n uploadSource = context.uploadSource,\n label,\n description,\n errors = [],\n disabled,\n readOnly,\n required,\n className,\n labelClassName,\n descriptionClassName,\n errorsClassName,\n } = props;\n const multiple = props.multiple === true;\n const files = toFiles(props.value);\n const editable = disabled !== true && readOnly !== true;\n const [rejections, setRejections] = useState<string[]>([]);\n const rejectionMessage = useRejectionMessage(maxSize);\n\n // The files as last set, so that uploads that end together all add theirs.\n const latest = useRef(files);\n useEffect(() => {\n latest.current = files;\n });\n const set = (next: FileValue[]) => {\n latest.current = next;\n if (props.multiple === true) {\n props.onChange?.(next.length > 0 ? next : null);\n } else {\n props.onChange?.(next[0] ?? null);\n }\n };\n\n const upload = useUploads({\n source: uploadSource,\n accept,\n maxSize,\n onUploaded: (file) => set(multiple ? [...latest.current, file] : [file]),\n onRejected: (file, reason) =>\n setRejections((current) => [...current, rejectionMessage(file, reason)]),\n });\n\n return (\n <Fieldset\n legend={label}\n description={description}\n errors={[...errors, ...rejections]}\n isRequired={required}\n isDisabled={disabled}\n className={className}\n legendClassName={labelClassName}\n descriptionClassName={descriptionClassName}\n errorsClassName={errorsClassName}\n >\n <div className={styles.field}>\n {files.length > 0 ? (\n <ul className={styles.files}>\n {files.map((file, index) => {\n const { name } = file;\n const url = fileUrl(file);\n const size = fileSize(file);\n return (\n <li key={`${String(index)}-${name}`} className={styles.file}>\n <FileText aria-hidden className={styles.icon} />\n {url !== null ? (\n <a\n href={url}\n className={styles.name}\n target=\"_blank\"\n rel=\"noreferrer\"\n >\n {name}\n </a>\n ) : (\n <span className={styles.name}>{name}</span>\n )}\n {size !== null ? (\n <span className={styles.size}>\n {formatSize(size, intl.locale)}\n </span>\n ) : null}\n {editable ? (\n <IconButton\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.removeFile, {\n name,\n })}\n onPress={() =>\n set(latest.current.filter((_, at) => at !== index))\n }\n />\n ) : null}\n </li>\n );\n })}\n </ul>\n ) : upload.items.length === 0 ? (\n <span className={styles.none}>{intl.formatMessage(messages.noFile)}</span>\n ) : null}\n <UploadList\n items={upload.items}\n onPause={upload.pause}\n onResume={upload.resume}\n onCancel={upload.cancel}\n onRetry={upload.retry}\n />\n {editable ? (\n <FilePicker\n accept={accept}\n multiple={multiple}\n {...(!multiple && files.length > 0\n ? { label: intl.formatMessage(messages.replaceFile) }\n : {})}\n onSelect={(selected) => {\n setRejections([]);\n upload.add(selected);\n }}\n />\n ) : null}\n </div>\n </Fieldset>\n );\n}\n\n/**\n * The registry entry of the `file` type: the field's `multiple`, `accept` (or its `accept` rule)\n * and `maxSize` rule, with the upload source of the fields context.\n */\nexport function FileFieldEntry(props: FieldEntryProps) {\n const { field, value, onChange } = props;\n const common = {\n ...getFieldProps(props),\n accept: getAccept(field),\n maxSize: getMaxSize(field),\n };\n return field.multiple === true ? (\n <FileField {...common} multiple value={toFiles(value)} onChange={onChange} />\n ) : (\n <FileField {...common} value={toFiles(value)[0] ?? null} onChange={onChange} />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoDA,SAAS,SAAS,MAAgC;CAC9C,OAAO,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO;AACvD;AAEA,SAAS,QAAQ,MAAgC;CAC7C,OAAO,EAAE,gBAAgB,SAAS,SAAS,QAAQ,OAAO,KAAK,QAAQ,WACjE,KAAK,MACL;AACV;;AAGA,SAAgB,YAAY,OAAoC;CAC5D,IAAI,OAAO,SAAS,eAAe,iBAAiB,MAChD,OAAO;CAEX,OACI,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAEtD;;AAGA,SAAgB,QAAQ,OAA6B;CACjD,IAAI,MAAM,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","names":["FileText","X","useEffect","useRef","useState","StoredFile","Fieldset","IconButton","usePanneauIntl","useFieldsContext","getAccept","getFieldProps","getMaxSize","messages","FieldEntryProps","FieldProps","FilePicker","UploadList","formatSize","UploadSource","UploadedFile","useRejectionMessage","useUploads","styles","FileValue","File","FileFieldBaseProps","Omit","accept","maxSize","uploadSource","SingleFileFieldProps","multiple","value","onChange","MultipleFileFieldProps","FileFieldProps","fileSize","file","size","fileUrl","Blob","url","isFileValue","name","toFiles","Array","isArray","filter","FileField","props","$","_c","intl","context","t0","t1","label","description","errors","t2","disabled","readOnly","required","className","labelClassName","descriptionClassName","errorsClassName","undefined","t3","t4","files","editable","t5","Symbol","for","rejections","setRejections","rejectionMessage","latest","t6","current","set","next","length","t7","file_0","reason","upload","source","onUploaded","onRejected","T0","t8","t10","map","file_1","index","String","icon","locale","formatMessage","removeFile","_","at","items","none","noFile","t11","cancel","pause","resume","retry","t12","replaceFile","selected","add","t13","t9","field","t14","FileFieldEntry","common","_c","styles"],"sources":["../../src/file/FileField.tsx"],"sourcesContent":["import { FileText, X } from 'lucide-react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport type { StoredFile } from '@panneau/protocol';\nimport { Fieldset, IconButton, usePanneauIntl } from '@panneau/ui';\n\nimport { useFieldsContext } from '../shared/context';\nimport { getAccept, getFieldProps, getMaxSize } from '../shared/entry';\nimport { messages } from '../shared/messages';\nimport type { FieldEntryProps, FieldProps } from '../shared/types';\nimport { FilePicker } from '../upload/FilePicker';\nimport { UploadList } from '../upload/UploadList';\nimport { formatSize } from '../upload/files';\nimport type { UploadSource, UploadedFile } from '../upload/types';\nimport { useRejectionMessage } from '../upload/useRejectionMessage';\nimport { useUploads } from '../upload/useUploads';\nimport styles from './FileField.module.css';\n\n/**\n * A file of a `file` value: a stored file, as items give it; an upload, once the browser sent the\n * file to storage; or the file itself, sent in a multipart request without direct uploads.\n */\nexport type FileValue = StoredFile | UploadedFile | File;\n\nexport interface FileFieldBaseProps extends Omit<FieldProps<never>, 'value' | 'onChange'> {\n /** Accepted MIME types (`application/pdf`, `image/*`). Others are refused before they are sent. */\n accept?: readonly string[] | null;\n /** Largest file, in bytes. Larger ones are refused before they are sent. */\n maxSize?: number | null;\n /**\n * Where files are uploaded directly to storage. Defaults to the one of the fields context.\n * Without one, the value holds the files themselves, which the adapter sends in\n * `multipart/form-data`.\n */\n uploadSource?: UploadSource | null;\n}\n\nexport interface SingleFileFieldProps extends FileFieldBaseProps {\n multiple?: false;\n value?: FileValue | null;\n onChange?: (value: FileValue | null) => void;\n}\n\nexport interface MultipleFileFieldProps extends FileFieldBaseProps {\n multiple: true;\n value?: readonly FileValue[] | null;\n /** Called with the files. An empty list is `null`. */\n onChange?: (value: FileValue[] | null) => void;\n}\n\nexport type FileFieldProps = SingleFileFieldProps | MultipleFileFieldProps;\n\nfunction fileSize(file: FileValue): number | null {\n return typeof file.size === 'number' ? file.size : null;\n}\n\nfunction fileUrl(file: FileValue): string | null {\n return !(file instanceof Blob) && 'url' in file && typeof file.url === 'string'\n ? file.url\n : null;\n}\n\n/** Whether a value is a file of a `file` value. */\nexport function isFileValue(value: unknown): value is FileValue {\n if (typeof File !== 'undefined' && value instanceof File) {\n return true;\n }\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { name?: unknown }).name === 'string'\n );\n}\n\n/** The files of a value, single or multiple. */\nexport function toFiles(value: unknown): FileValue[] {\n if (Array.isArray(value)) {\n return value.filter(isFileValue);\n }\n return isFileValue(value) ? [value] : [];\n}\n\n/**\n * Files that belong to an item, outside the media library: an attachment, a PDF, a CSV (the\n * `file` type). With an upload source, files go directly to storage, and the value references\n * each upload (`{ upload, name, mime, size }`). Without one, the value is the file itself. Items\n * give stored files, which the field shows with a link. A new file replaces the file of a single\n * value, and is added to a multiple one.\n */\nexport function FileField(props: FileFieldProps) {\n const intl = usePanneauIntl();\n const context = useFieldsContext();\n const {\n accept = null,\n maxSize = null,\n label,\n description,\n errors = [],\n disabled,\n readOnly,\n required,\n className,\n labelClassName,\n descriptionClassName,\n errorsClassName,\n } = props;\n const uploadSource =\n props.uploadSource === undefined ? context.uploadSource : props.uploadSource;\n const multiple = props.multiple === true;\n const files = toFiles(props.value);\n const editable = disabled !== true && readOnly !== true;\n const [rejections, setRejections] = useState<string[]>([]);\n const rejectionMessage = useRejectionMessage(maxSize);\n\n // The files as last set, so that uploads that end together all add theirs.\n const latest = useRef(files);\n useEffect(() => {\n latest.current = files;\n });\n const set = (next: FileValue[]) => {\n latest.current = next;\n if (props.multiple === true) {\n props.onChange?.(next.length > 0 ? next : null);\n } else {\n props.onChange?.(next[0] ?? null);\n }\n };\n\n const upload = useUploads({\n source: uploadSource,\n accept,\n maxSize,\n onUploaded: (file) => set(multiple ? [...latest.current, file] : [file]),\n onRejected: (file, reason) =>\n setRejections((current) => [...current, rejectionMessage(file, reason)]),\n });\n\n return (\n <Fieldset\n legend={label}\n description={description}\n errors={[...errors, ...rejections]}\n isRequired={required}\n isDisabled={disabled}\n className={className}\n legendClassName={labelClassName}\n descriptionClassName={descriptionClassName}\n errorsClassName={errorsClassName}\n >\n <div className={styles.field}>\n {files.length > 0 ? (\n <ul className={styles.files}>\n {files.map((file, index) => {\n const { name } = file;\n const url = fileUrl(file);\n const size = fileSize(file);\n return (\n <li key={`${String(index)}-${name}`} className={styles.file}>\n <FileText aria-hidden className={styles.icon} />\n {url !== null ? (\n <a\n href={url}\n className={styles.name}\n target=\"_blank\"\n rel=\"noreferrer\"\n >\n {name}\n </a>\n ) : (\n <span className={styles.name}>{name}</span>\n )}\n {size !== null ? (\n <span className={styles.size}>\n {formatSize(size, intl.locale)}\n </span>\n ) : null}\n {editable ? (\n <IconButton\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.removeFile, {\n name,\n })}\n onPress={() =>\n set(latest.current.filter((_, at) => at !== index))\n }\n />\n ) : null}\n </li>\n );\n })}\n </ul>\n ) : upload.items.length === 0 ? (\n <span className={styles.none}>{intl.formatMessage(messages.noFile)}</span>\n ) : null}\n <UploadList\n items={upload.items}\n onPause={upload.pause}\n onResume={upload.resume}\n onCancel={upload.cancel}\n onRetry={upload.retry}\n />\n {editable ? (\n <FilePicker\n accept={accept}\n multiple={multiple}\n {...(!multiple && files.length > 0\n ? { label: intl.formatMessage(messages.replaceFile) }\n : {})}\n onSelect={(selected) => {\n setRejections([]);\n upload.add(selected);\n }}\n />\n ) : null}\n </div>\n </Fieldset>\n );\n}\n\n/**\n * The registry entry of the `file` type: the field's `multiple`, `accept` (or its `accept` rule)\n * and `maxSize` rule, with the upload source of the fields context.\n */\nexport function FileFieldEntry(props: FieldEntryProps) {\n const { field, value, onChange } = props;\n const common = {\n ...getFieldProps(props),\n accept: getAccept(field),\n maxSize: getMaxSize(field),\n };\n return field.multiple === true ? (\n <FileField {...common} multiple value={toFiles(value)} onChange={onChange} />\n ) : (\n <FileField {...common} value={toFiles(value)[0] ?? null} onChange={onChange} />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoDA,SAASqC,SAASC,MAAgC;CAC9C,OAAO,OAAOA,KAAKC,SAAS,WAAWD,KAAKC,OAAO;AACvD;AAEA,SAASC,QAAQF,MAAgC;CAC7C,OAAO,EAAEA,gBAAgBG,SAAS,SAASH,QAAQ,OAAOA,KAAKI,QAAQ,WACjEJ,KAAKI,MACL;AACV;;AAGA,SAAgBC,YAAYV,OAAoC;CAC5D,IAAI,OAAOR,SAAS,eAAeQ,iBAAiBR,MAChD,OAAO;CAEX,OACI,OAAOQ,UAAU,YACjBA,UAAU,QACV,OAAQA,MAA6BW,SAAS;AAEtD;;AAGA,SAAgBC,QAAQZ,OAA6B;CACjD,IAAIa,MAAMC,QAAQd,KAAK,GACnB,OAAOA,MAAMe,OAAOL,WAAW;CAEnC,OAAOA,YAAYV,KAAK,IAAI,CAACA,KAAK,IAAI,CAAA;AAC1C;;;;;;;;AASA,SAAOgB,UAAAC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CACH,MAAAC,OAAa7C,eAAe;CAC5B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,KAAAI;EAAAJ,EAAA,KAAAK;EAAAL,EAAA,KAAAS;EAAAT,EAAA,KAAAkB;CAAA,OAAAA,KAAAlB,EAAA;CAJD,MAAAuE,SAAerD;CAIb,IAAAC;CAAA,IAAAnB,EAAA,QAAAuE,UAAAvE,EAAA,QAAAoE,MAAAvF,YAAAmB,EAAA,QAAAjB,YAAAiB,EAAA,QAAAlB,OAAA;EACKqC,KAAAiD,MAAKvF,aAAc,OACtB,oBAAC,WAAD;GAAU,GAAK0F;GAAQ,UAAA;GAAgB,OAAA7E,QAAQZ,KAAK;GAAaC;EAAQ,CAAA,IAEzE,oBAAC,WAAD;GAAU,GAAKwF;GAAe,OAAA7E,QAAQZ,KAAK,CAAC,CAAA,MAAd;GAAqCC;EAAQ,CAAA;EAC9EiB,EAAA,MAAAuE;EAAAvE,EAAA,MAAAoE,MAAAvF;EAAAmB,EAAA,MAAAjB;EAAAiB,EAAA,MAAAlB;EAAAkB,EAAA,MAAAmB;CAAA,OAAAA,KAAAnB,EAAA;CAAA,OAJMmB;AAIN"}
|
package/dist/file/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { type FileFieldBaseProps, FileField, FileFieldEntry, type FileFieldProps, type FileValue, type MultipleFileFieldProps, type SingleFileFieldProps, isFileValue, toFiles, } from './FileField';
|
|
2
|
-
export type { UploadItem, UploadItemStatus, UploadSource, UploadedFile, Uploader, } from '../upload/types';
|
|
1
|
+
export { type FileFieldBaseProps, FileField, FileFieldEntry, type FileFieldProps, type FileValue, type MultipleFileFieldProps, type SingleFileFieldProps, isFileValue, toFiles, } from './FileField.js';
|
|
2
|
+
export type { UploadItem, UploadItemStatus, UploadSource, UploadedFile, Uploader, } from '../upload/types.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Field } from '@panneau/protocol';
|
|
2
|
-
import type { FieldEntryProps, FieldProps } from '../shared/types';
|
|
2
|
+
import type { FieldEntryProps, FieldProps } from '../shared/types.js';
|
|
3
3
|
export type GroupValue = Record<string, unknown>;
|
|
4
4
|
export interface GroupFieldProps extends FieldProps<GroupValue> {
|
|
5
5
|
/** The nested fields, rendered with the entries of the fields context. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupField.js","names":["
|
|
1
|
+
{"version":3,"file":"GroupField.js","names":["Field","Fieldset","NestedField","cx","getFieldProps","FieldEntryProps","FieldProps","styles","GroupValue","Record","GroupFieldProps","fields","path","fieldsClassName","GroupField","t0","$","_c","name","value","onChange","onBlur","label","description","errors","disabled","readOnly","required","className","labelClassName","descriptionClassName","errorsClassName","base","t1","object","t2","t3","t4","field","next","undefined","map","t5","GroupFieldEntry","props","Array","isArray","_c","styles"],"sources":["../../src/group/GroupField.tsx"],"sourcesContent":["import type { Field } from '@panneau/protocol';\nimport { Fieldset } from '@panneau/ui';\n\nimport { NestedField } from '../shared/DefinitionField';\nimport { cx } from '../shared/cx';\nimport { getFieldProps } from '../shared/entry';\nimport type { FieldEntryProps, FieldProps } from '../shared/types';\nimport styles from './GroupField.module.css';\n\nexport type GroupValue = Record<string, unknown>;\n\nexport interface GroupFieldProps extends FieldProps<GroupValue> {\n /** The nested fields, rendered with the entries of the fields context. */\n fields: readonly Field[];\n /** Dot path of the group's value, the prefix of its fields' paths. Defaults to `name`. */\n path?: string;\n fieldsClassName?: string;\n}\n\n/**\n * A nested object: its fields under a legend. Each field renders with the entry of its type, at\n * the path `<group>.<field>`. Without a binding in the fields context, the group sets the whole\n * object through `onChange`.\n */\nexport function GroupField({\n fields,\n path,\n name,\n value,\n onChange,\n onBlur,\n label,\n description,\n errors,\n disabled,\n readOnly,\n required,\n className,\n labelClassName,\n descriptionClassName,\n errorsClassName,\n fieldsClassName,\n}: GroupFieldProps) {\n const base = path ?? name ?? '';\n const object = value ?? {};\n return (\n <Fieldset\n legend={label}\n description={description}\n errors={errors}\n isRequired={required}\n className={className}\n legendClassName={labelClassName}\n descriptionClassName={descriptionClassName}\n errorsClassName={errorsClassName}\n >\n <div className={cx(styles.fields, fieldsClassName)}>\n {fields.map((field) => (\n <NestedField\n key={field.name}\n field={field}\n path={base !== '' ? `${base}.${field.name}` : field.name}\n value={object[field.name]}\n onChange={(next) => onChange?.({ ...object, [field.name]: next })}\n {...(onBlur !== undefined ? { onBlur } : {})}\n parentValue={object}\n {...(disabled !== undefined ? { disabled } : {})}\n {...(readOnly !== undefined ? { readOnly } : {})}\n />\n ))}\n </div>\n </Fieldset>\n );\n}\n\n/** The `group` type: its `fields`, as a nested object. */\nexport function GroupFieldEntry(props: FieldEntryProps) {\n const { value } = props;\n return (\n <GroupField\n {...getFieldProps(props)}\n fields={props.field.fields ?? []}\n path={props.path}\n value={\n value !== null && typeof value === 'object' && !Array.isArray(value)\n ? (value as GroupValue)\n : null\n }\n onChange={props.onChange}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAOc,WAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAoB,MAAA,EAAAN,QAAAC,MAAAM,MAAAC,OAAAC,UAAAC,QAAAC,OAAAC,aAAAC,QAAAC,UAAAC,UAAAC,UAAAC,WAAAC,gBAAAC,sBAAAC,iBAAAlB,oBAAAE;CAmBvB,MAAAiB,OAAapB,QAAAM,QAAA;CAAmB,IAAAe;CAAA,IAAAjB,EAAA,OAAAG,OAAA;EACjBc,KAAAd,SAAA,CAAU;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAiB;CAAA,OAAAA,KAAAjB,EAAA;CAA1B,MAAAkB,SAAeD;CAAY,IAAAE;CAAA,IAAAnB,EAAA,OAAAH,iBAAA;EAYHsB,KAAAhC,GAAGI,0BAAMI,QAASE,eAAe;EAACG,EAAA,KAAAH;EAAAG,EAAA,KAAAmB;CAAA,OAAAA,KAAAnB,EAAA;CAAA,IAAAoB;CAAA,IAAApB,EAAA,OAAAgB,QAAAhB,EAAA,OAAAS,YAAAT,EAAA,OAAAL,UA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S3B,KAAK,IAC5DA,QADP;CAEU,IAAAiB;CAAA,IAAApB,EAAA,OAAA4B,MAAAxB,YAAAJ,EAAA,OAAA4B,MAAAhC,QAAAI,EAAA,OAAAD,MAAAC,EAAA,OAAAiB,MAAAjB,EAAA,OAAAmB,IAAA;EAPlBC,KAAA,oBAAC,YAAD;GAAW,GACHrB;GACI,QAAAkB;GACF,MAAAW,MAAKhC;GAEP,OAAAuB;GAIM,UAAAS,MAAKxB;EAAS,CAAA;EAC1BJ,EAAA,KAAA4B,MAAAxB;EAAAJ,EAAA,KAAA4B,MAAAhC;EAAAI,EAAA,KAAAD;EAAAC,EAAA,KAAAiB;EAAAjB,EAAA,KAAAmB;EAAAnB,EAAA,KAAAoB;CAAA,OAAAA,KAAApB,EAAA;CAAA,OAVFoB;AAUE"}
|
package/dist/group/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { GroupField, GroupFieldEntry, type GroupFieldProps, type GroupValue } from './GroupField';
|
|
1
|
+
export { GroupField, GroupFieldEntry, type GroupFieldProps, type GroupValue } from './GroupField.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export { DefinitionField, NestedField, type NestedFieldProps } from './shared/DefinitionField';
|
|
2
|
-
export { builtInFields, fieldsPlugin } from './shared/builtIn';
|
|
3
|
-
export { type BoundFieldProps, type FieldBinding, type FieldBindingProps, FieldsProvider, type FieldsContextValue, type FieldsProviderProps, getParentPath, useFieldsContext, } from './shared/context';
|
|
4
|
-
export { findRule, getAccept, getFieldProps, getMaxSize, getRuleNumber, isRequired, } from './shared/entry';
|
|
5
|
-
export { type RelationListAdapter, type RelationReference, type RelationSource, type RelationSourceOptions, createRelationSource, toReferences, useRelationReferences, } from './shared/relation';
|
|
6
|
-
export { type FieldCheckAdapter, type FieldCheckSource, createFieldCheckSource, } from './shared/check';
|
|
7
|
-
export { type EmbedAdapter, type EmbedSource, createEmbedSource } from './shared/embed';
|
|
8
|
-
export type { GeocodingResult, GeocodingSource, MapTiles, MapsConfig } from './location/types';
|
|
9
|
-
export { type NominatimSourceOptions, createNominatimSource } from './location/nominatim';
|
|
10
|
-
export type { FieldEntry, FieldEntryProps, FieldProps } from './shared/types';
|
|
11
|
-
export { MissingFieldEntry } from './missing/MissingField';
|
|
12
|
-
export { type FileFieldBaseProps, FileField, FileFieldEntry, type FileFieldProps, type FileValue, type MultipleFileFieldProps, type SingleFileFieldProps, isFileValue, toFiles, } from './file/FileField';
|
|
13
|
-
export { FilePicker, type FilePickerProps } from './upload/FilePicker';
|
|
14
|
-
export { UploadList, type UploadListProps } from './upload/UploadList';
|
|
15
|
-
export { formatSize, matchesMime } from './upload/files';
|
|
16
|
-
export { type UploadItem, type UploadItemStatus, type UploadRejection, type UploadSource, type UploadedFile, type Uploader, } from './upload/types';
|
|
17
|
-
export { useRejectionMessage } from './upload/useRejectionMessage';
|
|
18
|
-
export { type UseUploadsOptions, type UseUploadsResult, useUploads } from './upload/useUploads';
|
|
1
|
+
export { DefinitionField, NestedField, type NestedFieldProps } from './shared/DefinitionField.js';
|
|
2
|
+
export { builtInFields, fieldsPlugin } from './shared/builtIn.js';
|
|
3
|
+
export { type BoundFieldProps, type FieldBinding, type FieldBindingProps, FieldsProvider, type FieldsContextValue, type FieldsProviderProps, getParentPath, useFieldsContext, } from './shared/context.js';
|
|
4
|
+
export { findRule, getAccept, getFieldProps, getMaxSize, getRuleNumber, isRequired, } from './shared/entry.js';
|
|
5
|
+
export { type RelationListAdapter, type RelationReference, type RelationSource, type RelationSourceOptions, createRelationSource, toReferences, useRelationReferences, } from './shared/relation.js';
|
|
6
|
+
export { type FieldCheckAdapter, type FieldCheckSource, createFieldCheckSource, } from './shared/check.js';
|
|
7
|
+
export { type EmbedAdapter, type EmbedSource, createEmbedSource } from './shared/embed.js';
|
|
8
|
+
export type { GeocodingResult, GeocodingSource, MapTiles, MapsConfig } from './location/types.js';
|
|
9
|
+
export { type NominatimSourceOptions, createNominatimSource } from './location/nominatim.js';
|
|
10
|
+
export type { FieldEntry, FieldEntryProps, FieldProps } from './shared/types.js';
|
|
11
|
+
export { MissingFieldEntry } from './missing/MissingField.js';
|
|
12
|
+
export { type FileFieldBaseProps, FileField, FileFieldEntry, type FileFieldProps, type FileValue, type MultipleFileFieldProps, type SingleFileFieldProps, isFileValue, toFiles, } from './file/FileField.js';
|
|
13
|
+
export { FilePicker, type FilePickerProps } from './upload/FilePicker.js';
|
|
14
|
+
export { UploadList, type UploadListProps } from './upload/UploadList.js';
|
|
15
|
+
export { formatSize, matchesMime } from './upload/files.js';
|
|
16
|
+
export { type UploadItem, type UploadItemStatus, type UploadRejection, type UploadSource, type UploadedFile, type Uploader, } from './upload/types.js';
|
|
17
|
+
export { useRejectionMessage } from './upload/useRejectionMessage.js';
|
|
18
|
+
export { type UseUploadsOptions, type UseUploadsResult, useUploads } from './upload/useUploads.js';
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/json/JsonField.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FieldEntryProps, FieldProps } from '../shared/types';
|
|
1
|
+
import type { FieldEntryProps, FieldProps } from '../shared/types.js';
|
|
2
2
|
/** The value of a `json` field: an object or an array, or the text while it doesn't parse. */
|
|
3
3
|
export type JsonValue = Record<string, unknown> | unknown[] | string;
|
|
4
4
|
export interface JsonFieldProps extends FieldProps<JsonValue> {
|
package/dist/json/JsonField.js
CHANGED
|
@@ -39,45 +39,127 @@ function parseJson(text) {
|
|
|
39
39
|
* is the text itself, which the `json` rule refuses, so the form can't be saved with it. The text
|
|
40
40
|
* is indented again on blur once it parses.
|
|
41
41
|
*/
|
|
42
|
-
function JsonField(
|
|
42
|
+
function JsonField(t0) {
|
|
43
|
+
const $ = c(33);
|
|
44
|
+
let disabled;
|
|
45
|
+
let onBlur;
|
|
46
|
+
let onChange;
|
|
47
|
+
let props;
|
|
48
|
+
let readOnly;
|
|
49
|
+
let required;
|
|
50
|
+
let t1;
|
|
51
|
+
let t2;
|
|
52
|
+
let value;
|
|
53
|
+
if ($[0] !== t0) {
|
|
54
|
+
({value, onChange, onBlur, errors: t1, rows: t2, disabled, readOnly, required, ...props} = t0);
|
|
55
|
+
$[0] = t0;
|
|
56
|
+
$[1] = disabled;
|
|
57
|
+
$[2] = onBlur;
|
|
58
|
+
$[3] = onChange;
|
|
59
|
+
$[4] = props;
|
|
60
|
+
$[5] = readOnly;
|
|
61
|
+
$[6] = required;
|
|
62
|
+
$[7] = t1;
|
|
63
|
+
$[8] = t2;
|
|
64
|
+
$[9] = value;
|
|
65
|
+
} else {
|
|
66
|
+
disabled = $[1];
|
|
67
|
+
onBlur = $[2];
|
|
68
|
+
onChange = $[3];
|
|
69
|
+
props = $[4];
|
|
70
|
+
readOnly = $[5];
|
|
71
|
+
required = $[6];
|
|
72
|
+
t1 = $[7];
|
|
73
|
+
t2 = $[8];
|
|
74
|
+
value = $[9];
|
|
75
|
+
}
|
|
76
|
+
let t3;
|
|
77
|
+
if ($[10] !== t1) {
|
|
78
|
+
t3 = t1 === void 0 ? [] : t1;
|
|
79
|
+
$[10] = t1;
|
|
80
|
+
$[11] = t3;
|
|
81
|
+
} else t3 = $[11];
|
|
82
|
+
const errors = t3;
|
|
83
|
+
const rows = t2 === void 0 ? 8 : t2;
|
|
43
84
|
const intl = usePanneauIntl();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
85
|
+
let t4;
|
|
86
|
+
if ($[12] !== value) {
|
|
87
|
+
t4 = () => ({
|
|
88
|
+
value,
|
|
89
|
+
text: toText(value)
|
|
90
|
+
});
|
|
91
|
+
$[12] = value;
|
|
92
|
+
$[13] = t4;
|
|
93
|
+
} else t4 = $[13];
|
|
94
|
+
const [state, setState] = useState(t4);
|
|
48
95
|
if (state.value !== value) setState({
|
|
49
96
|
value,
|
|
50
97
|
text: toText(value)
|
|
51
98
|
});
|
|
52
99
|
const { text } = state;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
100
|
+
let t5;
|
|
101
|
+
if ($[14] !== errors || $[15] !== intl || $[16] !== text) {
|
|
102
|
+
const { error } = parseJson(text);
|
|
103
|
+
t5 = error !== null && errors.length === 0 ? [intl.formatMessage(messages.jsonInvalid, { error })] : errors;
|
|
104
|
+
$[14] = errors;
|
|
105
|
+
$[15] = intl;
|
|
106
|
+
$[16] = text;
|
|
107
|
+
$[17] = t5;
|
|
108
|
+
} else t5 = $[17];
|
|
109
|
+
const shown = t5;
|
|
110
|
+
let t6;
|
|
111
|
+
if ($[18] !== onChange) {
|
|
112
|
+
t6 = (next) => {
|
|
59
113
|
const parsed = parseJson(next).value;
|
|
60
114
|
setState({
|
|
61
115
|
value: parsed,
|
|
62
116
|
text: next
|
|
63
117
|
});
|
|
64
118
|
onChange?.(parsed);
|
|
65
|
-
}
|
|
66
|
-
|
|
119
|
+
};
|
|
120
|
+
$[18] = onChange;
|
|
121
|
+
$[19] = t6;
|
|
122
|
+
} else t6 = $[19];
|
|
123
|
+
let t7;
|
|
124
|
+
if ($[20] !== onBlur || $[21] !== value) {
|
|
125
|
+
t7 = () => {
|
|
67
126
|
if (value !== null && value !== void 0 && typeof value !== "string") setState({
|
|
68
127
|
value,
|
|
69
128
|
text: toText(value)
|
|
70
129
|
});
|
|
71
130
|
onBlur?.();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
131
|
+
};
|
|
132
|
+
$[20] = onBlur;
|
|
133
|
+
$[21] = value;
|
|
134
|
+
$[22] = t7;
|
|
135
|
+
} else t7 = $[22];
|
|
136
|
+
let t8;
|
|
137
|
+
if ($[23] !== disabled || $[24] !== props || $[25] !== readOnly || $[26] !== required || $[27] !== rows || $[28] !== shown || $[29] !== t6 || $[30] !== t7 || $[31] !== text) {
|
|
138
|
+
t8 = /* @__PURE__ */ jsx(TextArea, {
|
|
139
|
+
...props,
|
|
140
|
+
value: text,
|
|
141
|
+
onChange: t6,
|
|
142
|
+
onBlur: t7,
|
|
143
|
+
errors: shown,
|
|
144
|
+
rows,
|
|
145
|
+
spellCheck: "false",
|
|
146
|
+
textAreaClassName: JsonField_module_default.code,
|
|
147
|
+
isDisabled: disabled,
|
|
148
|
+
isReadOnly: readOnly,
|
|
149
|
+
isRequired: required
|
|
150
|
+
});
|
|
151
|
+
$[23] = disabled;
|
|
152
|
+
$[24] = props;
|
|
153
|
+
$[25] = readOnly;
|
|
154
|
+
$[26] = required;
|
|
155
|
+
$[27] = rows;
|
|
156
|
+
$[28] = shown;
|
|
157
|
+
$[29] = t6;
|
|
158
|
+
$[30] = t7;
|
|
159
|
+
$[31] = text;
|
|
160
|
+
$[32] = t8;
|
|
161
|
+
} else t8 = $[32];
|
|
162
|
+
return t8;
|
|
81
163
|
}
|
|
82
164
|
/** The `json` type: an object or an array, with setting `rows`. */
|
|
83
165
|
function JsonFieldEntry(props) {
|