@panneau/fields 5.0.0-alpha.3 → 5.0.0-alpha.5
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 +67 -20
- package/dist/file/FileField.css +54 -0
- package/dist/file/FileField.d.ts +50 -0
- package/dist/file/FileField.d.ts.map +1 -0
- package/dist/file/FileField.js +198 -0
- package/dist/file/FileField.js.map +1 -0
- package/dist/file/FileField.module.js +22 -0
- package/dist/file/FileField.module.js.map +1 -0
- package/dist/file/index.d.ts +3 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/file/index.js +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/localized/LocalizedField.d.ts.map +1 -1
- package/dist/localized/LocalizedField.js +1 -0
- package/dist/localized/LocalizedField.js.map +1 -1
- package/dist/relation/RelationField.d.ts.map +1 -1
- package/dist/relation/RelationField.js +24 -24
- package/dist/relation/RelationField.js.map +1 -1
- package/dist/shared/DefinitionField.d.ts +3 -1
- package/dist/shared/DefinitionField.d.ts.map +1 -1
- package/dist/shared/DefinitionField.js +80 -72
- package/dist/shared/DefinitionField.js.map +1 -1
- package/dist/shared/builtIn.d.ts +3 -2
- package/dist/shared/builtIn.d.ts.map +1 -1
- package/dist/shared/builtIn.js +5 -2
- package/dist/shared/builtIn.js.map +1 -1
- package/dist/shared/check.d.ts +27 -0
- package/dist/shared/check.d.ts.map +1 -0
- package/dist/shared/check.js +18 -0
- package/dist/shared/check.js.map +1 -0
- package/dist/shared/context.d.ts +15 -2
- package/dist/shared/context.d.ts.map +1 -1
- package/dist/shared/context.js +26 -18
- package/dist/shared/context.js.map +1 -1
- package/dist/shared/entry.d.ts +4 -0
- package/dist/shared/entry.d.ts.map +1 -1
- package/dist/shared/entry.js +12 -1
- package/dist/shared/entry.js.map +1 -1
- package/dist/shared/types.d.ts +2 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/slug/SlugField.css +18 -0
- package/dist/slug/SlugField.d.ts +31 -3
- package/dist/slug/SlugField.d.ts.map +1 -1
- package/dist/slug/SlugField.js +231 -159
- package/dist/slug/SlugField.js.map +1 -1
- package/dist/slug/SlugField.module.js +14 -0
- package/dist/slug/SlugField.module.js.map +1 -0
- package/dist/slug/index.d.ts +1 -1
- package/dist/slug/index.d.ts.map +1 -1
- package/dist/slug/index.js +1 -1
- package/dist/upload/FilePicker.css +24 -0
- package/dist/upload/FilePicker.d.ts +14 -0
- package/dist/upload/FilePicker.d.ts.map +1 -0
- package/dist/upload/FilePicker.js +47 -0
- package/dist/upload/FilePicker.js.map +1 -0
- package/dist/upload/FilePicker.module.js +12 -0
- package/dist/upload/FilePicker.module.js.map +1 -0
- package/dist/upload/UploadList.css +93 -0
- package/dist/upload/UploadList.d.ts +18 -0
- package/dist/upload/UploadList.d.ts.map +1 -0
- package/dist/upload/UploadList.js +144 -0
- package/dist/upload/UploadList.js.map +1 -0
- package/dist/upload/UploadList.module.js +32 -0
- package/dist/upload/UploadList.module.js.map +1 -0
- package/dist/upload/files.d.ts +5 -0
- package/dist/upload/files.d.ts.map +1 -0
- package/dist/upload/files.js +26 -0
- package/dist/upload/files.js.map +1 -0
- package/dist/upload/types.d.ts +58 -0
- package/dist/upload/types.d.ts.map +1 -0
- package/dist/upload/useRejectionMessage.d.ts +4 -0
- package/dist/upload/useRejectionMessage.d.ts.map +1 -0
- package/dist/upload/useRejectionMessage.js +25 -0
- package/dist/upload/useRejectionMessage.js.map +1 -0
- package/dist/upload/useUploads.d.ts +30 -0
- package/dist/upload/useUploads.d.ts.map +1 -0
- package/dist/upload/useUploads.js +115 -0
- package/dist/upload/useUploads.js.map +1 -0
- package/dist/uppy/index.d.ts +3 -0
- package/dist/uppy/index.d.ts.map +1 -0
- package/dist/uppy/index.js +1 -0
- package/dist/uppy/uploader.d.ts +44 -0
- package/dist/uppy/uploader.d.ts.map +1 -0
- package/dist/uppy/uploader.js +139 -0
- package/dist/uppy/uploader.js.map +1 -0
- package/package.json +30 -5
|
@@ -273,28 +273,28 @@ function RelationFieldEntry(props) {
|
|
|
273
273
|
$[1] = t0;
|
|
274
274
|
} else t0 = $[1];
|
|
275
275
|
const references = t0;
|
|
276
|
+
const resource = typeof field.resource === "string" ? field.resource : "";
|
|
276
277
|
let t1;
|
|
277
278
|
if ($[2] !== props) {
|
|
278
279
|
t1 = getFieldProps(props);
|
|
279
280
|
$[2] = props;
|
|
280
281
|
$[3] = t1;
|
|
281
282
|
} else t1 = $[3];
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
t3 = {
|
|
283
|
+
let t2;
|
|
284
|
+
if ($[4] !== resource || $[5] !== t1) {
|
|
285
|
+
t2 = {
|
|
286
286
|
...t1,
|
|
287
|
-
resource
|
|
287
|
+
resource
|
|
288
288
|
};
|
|
289
|
-
$[4] =
|
|
290
|
-
$[5] =
|
|
291
|
-
$[6] =
|
|
292
|
-
} else
|
|
293
|
-
const shared =
|
|
289
|
+
$[4] = resource;
|
|
290
|
+
$[5] = t1;
|
|
291
|
+
$[6] = t2;
|
|
292
|
+
} else t2 = $[6];
|
|
293
|
+
const shared = t2;
|
|
294
294
|
if (field.multiple === true) {
|
|
295
|
-
let
|
|
295
|
+
let t3;
|
|
296
296
|
if ($[7] !== props.onChange || $[8] !== references || $[9] !== shared) {
|
|
297
|
-
|
|
297
|
+
t3 = /* @__PURE__ */ jsx(RelationField, {
|
|
298
298
|
...shared,
|
|
299
299
|
multiple: true,
|
|
300
300
|
value: references,
|
|
@@ -303,24 +303,24 @@ function RelationFieldEntry(props) {
|
|
|
303
303
|
$[7] = props.onChange;
|
|
304
304
|
$[8] = references;
|
|
305
305
|
$[9] = shared;
|
|
306
|
-
$[10] =
|
|
307
|
-
} else
|
|
308
|
-
return
|
|
306
|
+
$[10] = t3;
|
|
307
|
+
} else t3 = $[10];
|
|
308
|
+
return t3;
|
|
309
309
|
}
|
|
310
|
-
const
|
|
311
|
-
let
|
|
312
|
-
if ($[11] !== props.onChange || $[12] !== shared || $[13] !==
|
|
313
|
-
|
|
310
|
+
const t3 = references[0] ?? null;
|
|
311
|
+
let t4;
|
|
312
|
+
if ($[11] !== props.onChange || $[12] !== shared || $[13] !== t3) {
|
|
313
|
+
t4 = /* @__PURE__ */ jsx(RelationField, {
|
|
314
314
|
...shared,
|
|
315
|
-
value:
|
|
315
|
+
value: t3,
|
|
316
316
|
onChange: props.onChange
|
|
317
317
|
});
|
|
318
318
|
$[11] = props.onChange;
|
|
319
319
|
$[12] = shared;
|
|
320
|
-
$[13] =
|
|
321
|
-
$[14] =
|
|
322
|
-
} else
|
|
323
|
-
return
|
|
320
|
+
$[13] = t3;
|
|
321
|
+
$[14] = t4;
|
|
322
|
+
} else t4 = $[14];
|
|
323
|
+
return t4;
|
|
324
324
|
}
|
|
325
325
|
//#endregion
|
|
326
326
|
export { RelationField, RelationFieldEntry, useRelationSearch };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationField.js","names":["X","text","reference","item","entry","onChange","itemId","references","_c","styles","_Fragment"],"sources":["../../src/relation/RelationField.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport { useEffect, useState } from 'react';\n\nimport { ComboBox, Fieldset, IconButton, usePanneauIntl } from '@panneau/ui';\n\nimport { useFieldsContext } from '../shared/context';\nimport { cx } from '../shared/cx';\nimport { getFieldProps } from '../shared/entry';\nimport { messages } from '../shared/messages';\nimport {\n type RelationReference,\n type RelationSource,\n toReferences,\n useRelationReferences,\n} from '../shared/relation';\nimport type { FieldEntryProps, FieldProps } from '../shared/types';\nimport styles from './RelationField.module.css';\n\n/** The id of the \"Create “…”\" option of the picker. */\nconst CREATE_ID = '\\u0000create';\n\n/** Results of a search in a relation source, as it types. */\nexport function useRelationSearch(\n source: RelationSource | null,\n resource: string,\n query: string,\n { enabled = true, delay = 250 }: { enabled?: boolean; delay?: number } = {},\n): { items: RelationReference[]; isLoading: boolean } {\n const [state, setState] = useState<{\n key: string;\n items: RelationReference[];\n isLoading: boolean;\n }>({ key: '', items: [], isLoading: false });\n const key = `${resource}\\u0000${query}`;\n\n useEffect(() => {\n if (source === null || !enabled) {\n return undefined;\n }\n const controller = new AbortController();\n const timer = setTimeout(() => {\n setState((current) => ({ ...current, key, isLoading: true }));\n source\n .search(resource, query, { signal: controller.signal })\n .then((items) => {\n if (!controller.signal.aborted) {\n setState({ key, items, isLoading: false });\n }\n })\n .catch(() => {\n if (!controller.signal.aborted) {\n setState({ key, items: [], isLoading: false });\n }\n });\n }, delay);\n return () => {\n clearTimeout(timer);\n controller.abort();\n };\n }, [source, resource, query, key, enabled, delay]);\n\n return { items: state.items, isLoading: state.isLoading || state.key !== key };\n}\n\n/** Props of both single and multiple relation fields. */\nexport interface RelationFieldBaseProps extends Omit<FieldProps<never>, 'value' | 'onChange'> {\n /** Id of the related resource, passed to the source. */\n resource: string;\n /** Where to search. Defaults to the fields context's. Without one, the field is read-only. */\n source?: RelationSource | null;\n /**\n * Creates an item from the typed text, offered as \"Create “…”\" in the picker: it can open a\n * dialog, and resolves with the new reference, or `null` when nothing was created. Defaults to\n * the source's `create()`. `null` turns creating off.\n */\n onCreate?: ((text: string) => Promise<RelationReference | null>) | null;\n placeholder?: string;\n controlClassName?: string;\n}\n\nexport interface SingleRelationFieldProps extends RelationFieldBaseProps {\n multiple?: false;\n value?: RelationReference | null;\n onChange?: (value: RelationReference | null) => void;\n}\n\nexport interface MultipleRelationFieldProps extends RelationFieldBaseProps {\n multiple: true;\n value?: readonly RelationReference[] | null;\n /** Called with the references. An empty list is `null`. */\n onChange?: (value: RelationReference[] | null) => void;\n}\n\nexport type RelationFieldProps = SingleRelationFieldProps | MultipleRelationFieldProps;\n\nfunction References({\n references,\n onRemove,\n removeLabel,\n}: {\n references: readonly RelationReference[];\n onRemove?: (reference: RelationReference) => void;\n removeLabel: (reference: RelationReference) => string;\n}) {\n return (\n <ul className={cx(styles.selected, onRemove === undefined && styles.readOnly)}>\n {references.map((reference) => (\n <li key={reference.id} className={styles.reference}>\n <span className={styles.referenceLabel}>{reference.label}</span>\n {onRemove !== undefined ? (\n <IconButton\n icon={X}\n size=\"sm\"\n label={removeLabel(reference)}\n showTooltip={false}\n onPress={() => onRemove(reference)}\n />\n ) : null}\n </li>\n ))}\n </ul>\n );\n}\n\n/**\n * A reference to an item of another resource, or several with `multiple`, picked by searching a\n * `RelationSource`. Values are references (`{ id, label }`), as items carry them; plain ids get\n * their labels from the source's `resolve()`. When the source can `create()` (or with `onCreate`),\n * the picker offers to create an item from the typed text. Without a source, the field shows its\n * references and can't change them.\n */\nexport function RelationField(props: RelationFieldProps) {\n const intl = usePanneauIntl();\n const context = useFieldsContext();\n const source = props.source === undefined ? context.relationSource : props.source;\n const {\n resource,\n label,\n description,\n errors,\n disabled,\n readOnly,\n required,\n placeholder = intl.formatMessage(messages.search),\n onBlur,\n name,\n id,\n className,\n labelClassName,\n descriptionClassName,\n errorsClassName,\n controlClassName,\n } = props;\n const selected = useRelationReferences(source, resource, toReferences(props.value));\n const [query, setQuery] = useState<string | null>(null);\n const [creating, setCreating] = useState(false);\n const [createError, setCreateError] = useState<string | null>(null);\n const editable = source !== null && disabled !== true && readOnly !== true;\n const { items: found, isLoading: searching } = useRelationSearch(\n source,\n resource,\n query ?? '',\n { enabled: editable },\n );\n const sourceCreate = source?.create;\n const create =\n props.onCreate !== undefined\n ? props.onCreate\n : sourceCreate !== undefined && source?.canCreate?.(resource) !== false\n ? (text: string) => sourceCreate.call(source, resource, text)\n : null;\n const text = (query ?? '').trim();\n const offersCreate =\n create !== null &&\n text !== '' &&\n !searching &&\n ![...found, ...selected].some(\n (item) =>\n item.label.toLocaleLowerCase(intl.locale) === text.toLocaleLowerCase(intl.locale),\n );\n const items = offersCreate\n ? [\n ...found,\n { id: CREATE_ID, label: intl.formatMessage(messages.createRelation, { text }) },\n ]\n : found;\n const isLoading = searching || creating;\n const allErrors = createError !== null ? [...(errors ?? []), createError] : errors;\n /** Creates an item from the text, then adds its reference with `add`. */\n const createFrom = (add: (reference: RelationReference) => void) => {\n if (create === null) {\n return;\n }\n setCreating(true);\n setCreateError(null);\n create(text)\n .then((reference) => {\n if (reference !== null) {\n add(reference);\n setQuery(null);\n }\n })\n .catch(() =>\n setCreateError(intl.formatMessage(messages.createRelationFailed, { text })),\n )\n .finally(() => setCreating(false));\n };\n const removeLabel = (reference: RelationReference) =>\n `${intl.formatMessage(messages.remove)} ${reference.label}`;\n const chrome = {\n legend: label,\n errors: allErrors,\n isRequired: required,\n className,\n legendClassName: labelClassName,\n descriptionClassName,\n errorsClassName,\n };\n\n if (!editable) {\n return (\n <Fieldset\n {...chrome}\n description={\n source === null && disabled !== true && readOnly !== true ? (\n <>\n {description} {intl.formatMessage(messages.relationUnavailable)}\n </>\n ) : (\n description\n )\n }\n >\n {selected.length > 0 ? (\n <References references={selected} removeLabel={removeLabel} />\n ) : (\n <span className={styles.none}>{intl.formatMessage(messages.noRelation)}</span>\n )}\n </Fieldset>\n );\n }\n\n const comboLabel = typeof label === 'string' ? label : props['aria-label'];\n\n if (props.multiple === true) {\n const { onChange } = props;\n const set = (next: RelationReference[]) => onChange?.(next.length > 0 ? next : null);\n return (\n <Fieldset {...chrome} description={description}>\n <div className={styles.multiple}>\n {selected.length > 0 ? (\n <References\n references={selected}\n removeLabel={removeLabel}\n onRemove={(reference) =>\n set(selected.filter((entry) => entry.id !== reference.id))\n }\n />\n ) : null}\n <ComboBox\n aria-label={comboLabel}\n items={items\n .filter((item) => !selected.some((entry) => entry.id === item.id))\n .map((item) => ({ id: item.id, label: item.label }))}\n value={null}\n inputValue={query ?? ''}\n onInputChange={setQuery}\n onChange={(itemId) => {\n if (itemId === CREATE_ID) {\n createFrom((reference) => set([...selected, reference]));\n return;\n }\n const reference = found.find((item) => item.id === itemId);\n if (reference !== undefined) {\n set([...selected, reference]);\n setQuery(null);\n }\n }}\n isLoading={isLoading}\n placeholder={placeholder}\n emptyMessage={intl.formatMessage(messages.noResults)}\n {...(onBlur !== undefined ? { onBlur: () => onBlur() } : {})}\n {...(name !== undefined ? { name } : {})}\n {...(id !== undefined ? { id } : {})}\n {...(controlClassName !== undefined ? { controlClassName } : {})}\n />\n </div>\n </Fieldset>\n );\n }\n\n const { onChange } = props;\n const current = selected[0] ?? null;\n // The selected reference is among the items, so that the combo box knows its label.\n const shown =\n current !== null && !items.some((item) => item.id === current.id)\n ? [current, ...items]\n : items;\n return (\n <ComboBox\n label={label}\n description={description}\n errors={allErrors}\n isRequired={required}\n className={className}\n labelClassName={labelClassName}\n descriptionClassName={descriptionClassName}\n errorsClassName={errorsClassName}\n {...(controlClassName !== undefined ? { controlClassName } : {})}\n {...(props['aria-label'] !== undefined ? { 'aria-label': props['aria-label'] } : {})}\n items={shown.map((item) => ({ id: item.id, label: item.label }))}\n value={current?.id ?? null}\n inputValue={query ?? current?.label ?? ''}\n onInputChange={(text) => {\n setQuery(text);\n if (text === '' && current !== null) {\n onChange?.(null);\n }\n }}\n onChange={(itemId) => {\n if (itemId === CREATE_ID) {\n createFrom((reference) => onChange?.(reference));\n return;\n }\n setQuery(null);\n if (itemId === null) {\n return;\n }\n const reference = shown.find((item) => item.id === itemId) ?? null;\n if (reference?.id !== current?.id) {\n onChange?.(reference);\n }\n }}\n isLoading={isLoading}\n placeholder={placeholder}\n emptyMessage={intl.formatMessage(messages.noResults)}\n {...(onBlur !== undefined\n ? {\n onBlur: () => {\n setQuery(null);\n onBlur();\n },\n }\n : { onBlur: () => setQuery(null) })}\n {...(name !== undefined ? { name } : {})}\n {...(id !== undefined ? { id } : {})}\n />\n );\n}\n\n/** The `relation` type: `resource` and `multiple`. Items search the fields context's source. */\nexport function RelationFieldEntry(props: FieldEntryProps) {\n const { field } = props;\n const references = toReferences(props.value);\n const shared = { ...getFieldProps(props), resource: field.resource ?? '' };\n if (field.multiple === true) {\n return <RelationField {...shared} multiple value={references} onChange={props.onChange} />;\n }\n return <RelationField {...shared} value={references[0] ?? null} onChange={props.onChange} />;\n}\n"],"mappings":";;;;;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UAAA,MAAK;GAAS,CAAA;GAAI,EAAA,KAAA,MAAA;GAAA,EAAA,KAAA;GAAA,EAAA,KAAA;GAAA,EAAA,MAAA;EAAA,OAAA,KAAA,EAAA;EAAA,OAAnF;CAAmF;CAErD,MAAA,KAAA,WAAU,MAAV;CAAqB,IAAA;CAAA,IAAA,EAAA,QAAA,MAAA,YAAA,EAAA,QAAA,UAAA,EAAA,QAAA,IAAA;EAAvD,KAAA,oBAAC,eAAD;GAAc,GAAK;GAAe,OAAA;GAAiC,UAAA,MAAK;EAAS,CAAA;EAAI,EAAA,MAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAArF;AAAqF"}
|
|
1
|
+
{"version":3,"file":"RelationField.js","names":["X","text","reference","item","entry","onChange","itemId","references","_c","styles","_Fragment"],"sources":["../../src/relation/RelationField.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport { useEffect, useState } from 'react';\n\nimport { ComboBox, Fieldset, IconButton, usePanneauIntl } from '@panneau/ui';\n\nimport { useFieldsContext } from '../shared/context';\nimport { cx } from '../shared/cx';\nimport { getFieldProps } from '../shared/entry';\nimport { messages } from '../shared/messages';\nimport {\n type RelationReference,\n type RelationSource,\n toReferences,\n useRelationReferences,\n} from '../shared/relation';\nimport type { FieldEntryProps, FieldProps } from '../shared/types';\nimport styles from './RelationField.module.css';\n\n/** The id of the \"Create “…”\" option of the picker. */\nconst CREATE_ID = '\\u0000create';\n\n/** Results of a search in a relation source, as it types. */\nexport function useRelationSearch(\n source: RelationSource | null,\n resource: string,\n query: string,\n { enabled = true, delay = 250 }: { enabled?: boolean; delay?: number } = {},\n): { items: RelationReference[]; isLoading: boolean } {\n const [state, setState] = useState<{\n key: string;\n items: RelationReference[];\n isLoading: boolean;\n }>({ key: '', items: [], isLoading: false });\n const key = `${resource}\\u0000${query}`;\n\n useEffect(() => {\n if (source === null || !enabled) {\n return undefined;\n }\n const controller = new AbortController();\n const timer = setTimeout(() => {\n setState((current) => ({ ...current, key, isLoading: true }));\n source\n .search(resource, query, { signal: controller.signal })\n .then((items) => {\n if (!controller.signal.aborted) {\n setState({ key, items, isLoading: false });\n }\n })\n .catch(() => {\n if (!controller.signal.aborted) {\n setState({ key, items: [], isLoading: false });\n }\n });\n }, delay);\n return () => {\n clearTimeout(timer);\n controller.abort();\n };\n }, [source, resource, query, key, enabled, delay]);\n\n return { items: state.items, isLoading: state.isLoading || state.key !== key };\n}\n\n/** Props of both single and multiple relation fields. */\nexport interface RelationFieldBaseProps extends Omit<FieldProps<never>, 'value' | 'onChange'> {\n /** Id of the related resource, passed to the source. */\n resource: string;\n /** Where to search. Defaults to the fields context's. Without one, the field is read-only. */\n source?: RelationSource | null;\n /**\n * Creates an item from the typed text, offered as \"Create “…”\" in the picker: it can open a\n * dialog, and resolves with the new reference, or `null` when nothing was created. Defaults to\n * the source's `create()`. `null` turns creating off.\n */\n onCreate?: ((text: string) => Promise<RelationReference | null>) | null;\n placeholder?: string;\n controlClassName?: string;\n}\n\nexport interface SingleRelationFieldProps extends RelationFieldBaseProps {\n multiple?: false;\n value?: RelationReference | null;\n onChange?: (value: RelationReference | null) => void;\n}\n\nexport interface MultipleRelationFieldProps extends RelationFieldBaseProps {\n multiple: true;\n value?: readonly RelationReference[] | null;\n /** Called with the references. An empty list is `null`. */\n onChange?: (value: RelationReference[] | null) => void;\n}\n\nexport type RelationFieldProps = SingleRelationFieldProps | MultipleRelationFieldProps;\n\nfunction References({\n references,\n onRemove,\n removeLabel,\n}: {\n references: readonly RelationReference[];\n onRemove?: (reference: RelationReference) => void;\n removeLabel: (reference: RelationReference) => string;\n}) {\n return (\n <ul className={cx(styles.selected, onRemove === undefined && styles.readOnly)}>\n {references.map((reference) => (\n <li key={reference.id} className={styles.reference}>\n <span className={styles.referenceLabel}>{reference.label}</span>\n {onRemove !== undefined ? (\n <IconButton\n icon={X}\n size=\"sm\"\n label={removeLabel(reference)}\n showTooltip={false}\n onPress={() => onRemove(reference)}\n />\n ) : null}\n </li>\n ))}\n </ul>\n );\n}\n\n/**\n * A reference to an item of another resource, or several with `multiple`, picked by searching a\n * `RelationSource`. Values are references (`{ id, label }`), as items carry them; plain ids get\n * their labels from the source's `resolve()`. When the source can `create()` (or with `onCreate`),\n * the picker offers to create an item from the typed text. Without a source, the field shows its\n * references and can't change them.\n */\nexport function RelationField(props: RelationFieldProps) {\n const intl = usePanneauIntl();\n const context = useFieldsContext();\n const source = props.source === undefined ? context.relationSource : props.source;\n const {\n resource,\n label,\n description,\n errors,\n disabled,\n readOnly,\n required,\n placeholder = intl.formatMessage(messages.search),\n onBlur,\n name,\n id,\n className,\n labelClassName,\n descriptionClassName,\n errorsClassName,\n controlClassName,\n } = props;\n const selected = useRelationReferences(source, resource, toReferences(props.value));\n const [query, setQuery] = useState<string | null>(null);\n const [creating, setCreating] = useState(false);\n const [createError, setCreateError] = useState<string | null>(null);\n const editable = source !== null && disabled !== true && readOnly !== true;\n const { items: found, isLoading: searching } = useRelationSearch(\n source,\n resource,\n query ?? '',\n { enabled: editable },\n );\n const sourceCreate = source?.create;\n const create =\n props.onCreate !== undefined\n ? props.onCreate\n : sourceCreate !== undefined && source?.canCreate?.(resource) !== false\n ? (text: string) => sourceCreate.call(source, resource, text)\n : null;\n const text = (query ?? '').trim();\n const offersCreate =\n create !== null &&\n text !== '' &&\n !searching &&\n ![...found, ...selected].some(\n (item) =>\n item.label.toLocaleLowerCase(intl.locale) === text.toLocaleLowerCase(intl.locale),\n );\n const items = offersCreate\n ? [\n ...found,\n { id: CREATE_ID, label: intl.formatMessage(messages.createRelation, { text }) },\n ]\n : found;\n const isLoading = searching || creating;\n const allErrors = createError !== null ? [...(errors ?? []), createError] : errors;\n /** Creates an item from the text, then adds its reference with `add`. */\n const createFrom = (add: (reference: RelationReference) => void) => {\n if (create === null) {\n return;\n }\n setCreating(true);\n setCreateError(null);\n create(text)\n .then((reference) => {\n if (reference !== null) {\n add(reference);\n setQuery(null);\n }\n })\n .catch(() =>\n setCreateError(intl.formatMessage(messages.createRelationFailed, { text })),\n )\n .finally(() => setCreating(false));\n };\n const removeLabel = (reference: RelationReference) =>\n `${intl.formatMessage(messages.remove)} ${reference.label}`;\n const chrome = {\n legend: label,\n errors: allErrors,\n isRequired: required,\n className,\n legendClassName: labelClassName,\n descriptionClassName,\n errorsClassName,\n };\n\n if (!editable) {\n return (\n <Fieldset\n {...chrome}\n description={\n source === null && disabled !== true && readOnly !== true ? (\n <>\n {description} {intl.formatMessage(messages.relationUnavailable)}\n </>\n ) : (\n description\n )\n }\n >\n {selected.length > 0 ? (\n <References references={selected} removeLabel={removeLabel} />\n ) : (\n <span className={styles.none}>{intl.formatMessage(messages.noRelation)}</span>\n )}\n </Fieldset>\n );\n }\n\n const comboLabel = typeof label === 'string' ? label : props['aria-label'];\n\n if (props.multiple === true) {\n const { onChange } = props;\n const set = (next: RelationReference[]) => onChange?.(next.length > 0 ? next : null);\n return (\n <Fieldset {...chrome} description={description}>\n <div className={styles.multiple}>\n {selected.length > 0 ? (\n <References\n references={selected}\n removeLabel={removeLabel}\n onRemove={(reference) =>\n set(selected.filter((entry) => entry.id !== reference.id))\n }\n />\n ) : null}\n <ComboBox\n aria-label={comboLabel}\n items={items\n .filter((item) => !selected.some((entry) => entry.id === item.id))\n .map((item) => ({ id: item.id, label: item.label }))}\n value={null}\n inputValue={query ?? ''}\n onInputChange={setQuery}\n onChange={(itemId) => {\n if (itemId === CREATE_ID) {\n createFrom((reference) => set([...selected, reference]));\n return;\n }\n const reference = found.find((item) => item.id === itemId);\n if (reference !== undefined) {\n set([...selected, reference]);\n setQuery(null);\n }\n }}\n isLoading={isLoading}\n placeholder={placeholder}\n emptyMessage={intl.formatMessage(messages.noResults)}\n {...(onBlur !== undefined ? { onBlur: () => onBlur() } : {})}\n {...(name !== undefined ? { name } : {})}\n {...(id !== undefined ? { id } : {})}\n {...(controlClassName !== undefined ? { controlClassName } : {})}\n />\n </div>\n </Fieldset>\n );\n }\n\n const { onChange } = props;\n const current = selected[0] ?? null;\n // The selected reference is among the items, so that the combo box knows its label.\n const shown =\n current !== null && !items.some((item) => item.id === current.id)\n ? [current, ...items]\n : items;\n return (\n <ComboBox\n label={label}\n description={description}\n errors={allErrors}\n isRequired={required}\n className={className}\n labelClassName={labelClassName}\n descriptionClassName={descriptionClassName}\n errorsClassName={errorsClassName}\n {...(controlClassName !== undefined ? { controlClassName } : {})}\n {...(props['aria-label'] !== undefined ? { 'aria-label': props['aria-label'] } : {})}\n items={shown.map((item) => ({ id: item.id, label: item.label }))}\n value={current?.id ?? null}\n inputValue={query ?? current?.label ?? ''}\n onInputChange={(text) => {\n setQuery(text);\n if (text === '' && current !== null) {\n onChange?.(null);\n }\n }}\n onChange={(itemId) => {\n if (itemId === CREATE_ID) {\n createFrom((reference) => onChange?.(reference));\n return;\n }\n setQuery(null);\n if (itemId === null) {\n return;\n }\n const reference = shown.find((item) => item.id === itemId) ?? null;\n if (reference?.id !== current?.id) {\n onChange?.(reference);\n }\n }}\n isLoading={isLoading}\n placeholder={placeholder}\n emptyMessage={intl.formatMessage(messages.noResults)}\n {...(onBlur !== undefined\n ? {\n onBlur: () => {\n setQuery(null);\n onBlur();\n },\n }\n : { onBlur: () => setQuery(null) })}\n {...(name !== undefined ? { name } : {})}\n {...(id !== undefined ? { id } : {})}\n />\n );\n}\n\n/** The `relation` type: `resource` and `multiple`. Items search the fields context's source. */\nexport function RelationFieldEntry(props: FieldEntryProps) {\n const { field } = props;\n const references = toReferences(props.value);\n // A relation names one resource: `lintDefinition()` reports a list (only `media` fields take one).\n const resource = typeof field.resource === 'string' ? field.resource : '';\n const shared = { ...getFieldProps(props), resource };\n if (field.multiple === true) {\n return <RelationField {...shared} multiple value={references} onChange={props.onChange} />;\n }\n return <RelationField {...shared} value={references[0] ?? null} onChange={props.onChange} />;\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,IAAM,YAAY;;AAGlB,SAAgB,kBACZ,QACA,UACA,O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AA;GAAA,EAAA,KAAA;GAAA,EAAA,KAAA;GAAA,EAAA,MAAA;EAAA,OAAA,KAAA,EAAA;EAAA,OAAnF;CAAmF;CAErD,MAAA,KAAA,WAAU,MAAV;CAAqB,IAAA;CAAA,IAAA,EAAA,QAAA,MAAA,YAAA,EAAA,QAAA,UAAA,EAAA,QAAA,IAAA;EAAvD,KAAA,oBAAC,eAAD;GAAc,GAAK;GAAe,OAAA;GAAiC,UAAA,MAAK;EAAS,CAAA;EAAI,EAAA,MAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAArF;AAAqF"}
|
|
@@ -12,6 +12,8 @@ export interface NestedFieldProps {
|
|
|
12
12
|
errors?: readonly string[];
|
|
13
13
|
/** The object the field belongs to, for conditions and generated values. */
|
|
14
14
|
parentValue?: unknown;
|
|
15
|
+
/** The locale of the value, in a localized field. */
|
|
16
|
+
locale?: string;
|
|
15
17
|
disabled?: boolean;
|
|
16
18
|
readOnly?: boolean;
|
|
17
19
|
className?: string;
|
|
@@ -22,7 +24,7 @@ export interface NestedFieldProps {
|
|
|
22
24
|
* one, it uses `value` and `onChange`, and hides itself when its `visibleWhen` condition on the
|
|
23
25
|
* parent value is false.
|
|
24
26
|
*/
|
|
25
|
-
export declare function NestedField({ field, path, value, onChange, onBlur, errors, parentValue, disabled, readOnly, className, }: NestedFieldProps): import("react").JSX.Element | null;
|
|
27
|
+
export declare function NestedField({ field, path, value, onChange, onBlur, errors, parentValue, locale, disabled, readOnly, className, }: NestedFieldProps): import("react").JSX.Element | null;
|
|
26
28
|
/**
|
|
27
29
|
* Renders a field of the definition with the entry of its type: from the fields context, or a
|
|
28
30
|
* built-in one. A localized field renders an input per locale. A type without an entry renders a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefinitionField.d.ts","sourceRoot":"","sources":["../../src/shared/DefinitionField.tsx"],"names":[],"mappings":"AAAA,OAA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MAAM,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,4EAA4E;IAC5E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EACxB,KAAK,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,WAAW,EACX,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,SAAS,GACZ,EAAE,gBAAgB,sCAiClB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,eAAe,+BAQrD"}
|
|
@@ -13,110 +13,118 @@ import { jsx } from "react/jsx-runtime";
|
|
|
13
13
|
* parent value is false.
|
|
14
14
|
*/
|
|
15
15
|
function NestedField(t0) {
|
|
16
|
-
const $ = c(
|
|
17
|
-
const { field, path, value, onChange, onBlur, errors, parentValue, disabled, readOnly, className } = t0;
|
|
16
|
+
const $ = c(36);
|
|
17
|
+
const { field, path, value, onChange, onBlur, errors, parentValue, locale, disabled, readOnly, className } = t0;
|
|
18
18
|
const { binding: Binding } = useFieldsContext();
|
|
19
19
|
let t1;
|
|
20
|
-
if ($[0] !==
|
|
21
|
-
t1 =
|
|
22
|
-
$[0] =
|
|
20
|
+
if ($[0] !== locale) {
|
|
21
|
+
t1 = locale !== void 0 ? { locale } : {};
|
|
22
|
+
$[0] = locale;
|
|
23
23
|
$[1] = t1;
|
|
24
24
|
} else t1 = $[1];
|
|
25
25
|
let t2;
|
|
26
|
-
if ($[2] !==
|
|
27
|
-
t2 =
|
|
28
|
-
$[2] =
|
|
26
|
+
if ($[2] !== disabled) {
|
|
27
|
+
t2 = disabled !== void 0 ? { disabled } : {};
|
|
28
|
+
$[2] = disabled;
|
|
29
29
|
$[3] = t2;
|
|
30
30
|
} else t2 = $[3];
|
|
31
31
|
let t3;
|
|
32
|
-
if ($[4] !==
|
|
33
|
-
t3 =
|
|
34
|
-
$[4] =
|
|
32
|
+
if ($[4] !== readOnly) {
|
|
33
|
+
t3 = readOnly !== void 0 ? { readOnly } : {};
|
|
34
|
+
$[4] = readOnly;
|
|
35
35
|
$[5] = t3;
|
|
36
36
|
} else t3 = $[5];
|
|
37
37
|
let t4;
|
|
38
|
-
if ($[6] !==
|
|
39
|
-
t4 = {
|
|
38
|
+
if ($[6] !== className) {
|
|
39
|
+
t4 = className !== void 0 ? { className } : {};
|
|
40
|
+
$[6] = className;
|
|
41
|
+
$[7] = t4;
|
|
42
|
+
} else t4 = $[7];
|
|
43
|
+
let t5;
|
|
44
|
+
if ($[8] !== field || $[9] !== parentValue || $[10] !== path || $[11] !== t1 || $[12] !== t2 || $[13] !== t3 || $[14] !== t4) {
|
|
45
|
+
t5 = {
|
|
40
46
|
field,
|
|
41
47
|
path,
|
|
42
48
|
parentValue,
|
|
43
49
|
...t1,
|
|
44
50
|
...t2,
|
|
45
|
-
...t3
|
|
51
|
+
...t3,
|
|
52
|
+
...t4
|
|
46
53
|
};
|
|
47
|
-
$[
|
|
48
|
-
$[
|
|
49
|
-
$[
|
|
50
|
-
$[
|
|
51
|
-
$[
|
|
52
|
-
$[
|
|
53
|
-
$[
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
$[8] = field;
|
|
55
|
+
$[9] = parentValue;
|
|
56
|
+
$[10] = path;
|
|
57
|
+
$[11] = t1;
|
|
58
|
+
$[12] = t2;
|
|
59
|
+
$[13] = t3;
|
|
60
|
+
$[14] = t4;
|
|
61
|
+
$[15] = t5;
|
|
62
|
+
} else t5 = $[15];
|
|
63
|
+
const shared = t5;
|
|
56
64
|
if (Binding !== null) {
|
|
57
|
-
let t5;
|
|
58
|
-
if ($[13] !== path) {
|
|
59
|
-
t5 = getParentPath(path);
|
|
60
|
-
$[13] = path;
|
|
61
|
-
$[14] = t5;
|
|
62
|
-
} else t5 = $[14];
|
|
63
65
|
let t6;
|
|
64
|
-
if ($[
|
|
65
|
-
t6 = (
|
|
66
|
+
if ($[16] !== path) {
|
|
67
|
+
t6 = getParentPath(path);
|
|
68
|
+
$[16] = path;
|
|
69
|
+
$[17] = t6;
|
|
70
|
+
} else t6 = $[17];
|
|
71
|
+
let t7;
|
|
72
|
+
if ($[18] !== shared) {
|
|
73
|
+
t7 = (bound) => /* @__PURE__ */ jsx(DefinitionField, {
|
|
66
74
|
...shared,
|
|
67
75
|
...bound
|
|
68
76
|
});
|
|
69
|
-
$[
|
|
70
|
-
$[
|
|
71
|
-
} else
|
|
72
|
-
let
|
|
73
|
-
if ($[
|
|
74
|
-
|
|
77
|
+
$[18] = shared;
|
|
78
|
+
$[19] = t7;
|
|
79
|
+
} else t7 = $[19];
|
|
80
|
+
let t8;
|
|
81
|
+
if ($[20] !== Binding || $[21] !== field || $[22] !== path || $[23] !== t6 || $[24] !== t7) {
|
|
82
|
+
t8 = /* @__PURE__ */ jsx(Binding, {
|
|
75
83
|
field,
|
|
76
84
|
path,
|
|
77
|
-
parentPath:
|
|
78
|
-
render:
|
|
85
|
+
parentPath: t6,
|
|
86
|
+
render: t7
|
|
79
87
|
});
|
|
80
|
-
$[
|
|
81
|
-
$[
|
|
82
|
-
$[
|
|
83
|
-
$[
|
|
84
|
-
$[
|
|
85
|
-
$[
|
|
86
|
-
} else
|
|
87
|
-
return
|
|
88
|
+
$[20] = Binding;
|
|
89
|
+
$[21] = field;
|
|
90
|
+
$[22] = path;
|
|
91
|
+
$[23] = t6;
|
|
92
|
+
$[24] = t7;
|
|
93
|
+
$[25] = t8;
|
|
94
|
+
} else t8 = $[25];
|
|
95
|
+
return t8;
|
|
88
96
|
}
|
|
89
97
|
if (field.visibleWhen !== void 0 && !evaluateCondition(field.visibleWhen, parentValue)) return null;
|
|
90
|
-
const
|
|
91
|
-
let t6;
|
|
92
|
-
if ($[23] !== onBlur) {
|
|
93
|
-
t6 = onBlur !== void 0 ? { onBlur } : {};
|
|
94
|
-
$[23] = onBlur;
|
|
95
|
-
$[24] = t6;
|
|
96
|
-
} else t6 = $[24];
|
|
98
|
+
const t6 = onChange ?? _temp;
|
|
97
99
|
let t7;
|
|
98
|
-
if ($[
|
|
99
|
-
t7 =
|
|
100
|
-
$[
|
|
101
|
-
$[
|
|
102
|
-
} else t7 = $[
|
|
100
|
+
if ($[26] !== onBlur) {
|
|
101
|
+
t7 = onBlur !== void 0 ? { onBlur } : {};
|
|
102
|
+
$[26] = onBlur;
|
|
103
|
+
$[27] = t7;
|
|
104
|
+
} else t7 = $[27];
|
|
103
105
|
let t8;
|
|
104
|
-
if ($[
|
|
105
|
-
t8 =
|
|
106
|
+
if ($[28] !== errors) {
|
|
107
|
+
t8 = errors !== void 0 ? { errors } : {};
|
|
108
|
+
$[28] = errors;
|
|
109
|
+
$[29] = t8;
|
|
110
|
+
} else t8 = $[29];
|
|
111
|
+
let t9;
|
|
112
|
+
if ($[30] !== shared || $[31] !== t6 || $[32] !== t7 || $[33] !== t8 || $[34] !== value) {
|
|
113
|
+
t9 = /* @__PURE__ */ jsx(DefinitionField, {
|
|
106
114
|
...shared,
|
|
107
115
|
value,
|
|
108
|
-
onChange:
|
|
109
|
-
...
|
|
110
|
-
...
|
|
116
|
+
onChange: t6,
|
|
117
|
+
...t7,
|
|
118
|
+
...t8
|
|
111
119
|
});
|
|
112
|
-
$[
|
|
113
|
-
$[
|
|
114
|
-
$[
|
|
115
|
-
$[
|
|
116
|
-
$[
|
|
117
|
-
$[
|
|
118
|
-
} else
|
|
119
|
-
return
|
|
120
|
+
$[30] = shared;
|
|
121
|
+
$[31] = t6;
|
|
122
|
+
$[32] = t7;
|
|
123
|
+
$[33] = t8;
|
|
124
|
+
$[34] = value;
|
|
125
|
+
$[35] = t9;
|
|
126
|
+
} else t9 = $[35];
|
|
127
|
+
return t9;
|
|
120
128
|
}
|
|
121
129
|
/**
|
|
122
130
|
* Renders a field of the definition with the entry of its type: from the fields context, or a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefinitionField.js","names":["field","path","value","_c"],"sources":["../../src/shared/DefinitionField.tsx"],"sourcesContent":["import type { Field } from '@panneau/protocol';\nimport { evaluateCondition } from '@panneau/protocol/runtime';\n\n// Groups, repeaters and localized values render nested fields, which render through\n// `DefinitionField`: the modules import each other, which is fine since they only use each other\n// while rendering.\nimport { LocalizedFieldEntry } from '../localized/LocalizedField';\nimport { MissingFieldEntry } from '../missing/MissingField';\nimport { builtInFields } from './builtIn';\nimport { getParentPath, useFieldsContext } from './context';\nimport type { FieldEntryProps } from './types';\n\nexport interface NestedFieldProps {\n field: Field;\n /** Dot path of the field's value. */\n path: string;\n /** The value, without a binding. */\n value?: unknown;\n /** Sets the value, without a binding. */\n onChange?: (value: unknown) => void;\n onBlur?: () => void;\n errors?: readonly string[];\n /** The object the field belongs to, for conditions and generated values. */\n parentValue?: unknown;\n disabled?: boolean;\n readOnly?: boolean;\n className?: string;\n}\n\n/**\n * A field inside another one (a group, a block, a localized value), or at the top of a form.\n * With a binding in context, the binding gives its value and decides whether it shows. Without\n * one, it uses `value` and `onChange`, and hides itself when its `visibleWhen` condition on the\n * parent value is false.\n */\nexport function NestedField({\n field,\n path,\n value,\n onChange,\n onBlur,\n errors,\n parentValue,\n disabled,\n readOnly,\n className,\n}: NestedFieldProps) {\n const { binding: Binding } = useFieldsContext();\n const shared = {\n field,\n path,\n parentValue,\n ...(disabled !== undefined ? { disabled } : {}),\n ...(readOnly !== undefined ? { readOnly } : {}),\n ...(className !== undefined ? { className } : {}),\n };\n if (Binding !== null) {\n return (\n <Binding\n field={field}\n path={path}\n parentPath={getParentPath(path)}\n render={(bound) => <DefinitionField {...shared} {...bound} />}\n />\n );\n }\n if (field.visibleWhen !== undefined && !evaluateCondition(field.visibleWhen, parentValue)) {\n return null;\n }\n return (\n <DefinitionField\n {...shared}\n value={value}\n onChange={onChange ?? (() => undefined)}\n {...(onBlur !== undefined ? { onBlur } : {})}\n {...(errors !== undefined ? { errors } : {})}\n />\n );\n}\n\n/**\n * Renders a field of the definition with the entry of its type: from the fields context, or a\n * built-in one. A localized field renders an input per locale. A type without an entry renders a\n * placeholder that names the missing plugin.\n */\nexport function DefinitionField(props: FieldEntryProps) {\n const { components } = useFieldsContext();\n const { field } = props;\n if (field.localized === true) {\n return <LocalizedFieldEntry {...props} />;\n }\n const Entry = components[field.type] ?? builtInFields[field.type] ?? MissingFieldEntry;\n return <Entry {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"DefinitionField.js","names":["field","path","value","_c"],"sources":["../../src/shared/DefinitionField.tsx"],"sourcesContent":["import type { Field } from '@panneau/protocol';\nimport { evaluateCondition } from '@panneau/protocol/runtime';\n\n// Groups, repeaters and localized values render nested fields, which render through\n// `DefinitionField`: the modules import each other, which is fine since they only use each other\n// while rendering.\nimport { LocalizedFieldEntry } from '../localized/LocalizedField';\nimport { MissingFieldEntry } from '../missing/MissingField';\nimport { builtInFields } from './builtIn';\nimport { getParentPath, useFieldsContext } from './context';\nimport type { FieldEntryProps } from './types';\n\nexport interface NestedFieldProps {\n field: Field;\n /** Dot path of the field's value. */\n path: string;\n /** The value, without a binding. */\n value?: unknown;\n /** Sets the value, without a binding. */\n onChange?: (value: unknown) => void;\n onBlur?: () => void;\n errors?: readonly string[];\n /** The object the field belongs to, for conditions and generated values. */\n parentValue?: unknown;\n /** The locale of the value, in a localized field. */\n locale?: string;\n disabled?: boolean;\n readOnly?: boolean;\n className?: string;\n}\n\n/**\n * A field inside another one (a group, a block, a localized value), or at the top of a form.\n * With a binding in context, the binding gives its value and decides whether it shows. Without\n * one, it uses `value` and `onChange`, and hides itself when its `visibleWhen` condition on the\n * parent value is false.\n */\nexport function NestedField({\n field,\n path,\n value,\n onChange,\n onBlur,\n errors,\n parentValue,\n locale,\n disabled,\n readOnly,\n className,\n}: NestedFieldProps) {\n const { binding: Binding } = useFieldsContext();\n const shared = {\n field,\n path,\n parentValue,\n ...(locale !== undefined ? { locale } : {}),\n ...(disabled !== undefined ? { disabled } : {}),\n ...(readOnly !== undefined ? { readOnly } : {}),\n ...(className !== undefined ? { className } : {}),\n };\n if (Binding !== null) {\n return (\n <Binding\n field={field}\n path={path}\n parentPath={getParentPath(path)}\n render={(bound) => <DefinitionField {...shared} {...bound} />}\n />\n );\n }\n if (field.visibleWhen !== undefined && !evaluateCondition(field.visibleWhen, parentValue)) {\n return null;\n }\n return (\n <DefinitionField\n {...shared}\n value={value}\n onChange={onChange ?? (() => undefined)}\n {...(onBlur !== undefined ? { onBlur } : {})}\n {...(errors !== undefined ? { errors } : {})}\n />\n );\n}\n\n/**\n * Renders a field of the definition with the entry of its type: from the fields context, or a\n * built-in one. A localized field renders an input per locale. A type without an entry renders a\n * placeholder that names the missing plugin.\n */\nexport function DefinitionField(props: FieldEntryProps) {\n const { components } = useFieldsContext();\n const { field } = props;\n if (field.localized === true) {\n return <LocalizedFieldEntry {...props} />;\n }\n const Entry = components[field.type] ?? builtInFields[field.type] ?? MissingFieldEntry;\n return <Entry {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;;;AAqCA,SAAO,YAAA,IAAA;CAAA,MAAA,IAAAG,EAAA,EAAA;CAAqB,MAAA,EAAA,OAAA,MAAA,OAAA,UAAA,QAAA,QAAA,aAAA,QAAA,UAAA,UAAA,cAAA;CAaxB,MAAA,EAAA,SAAA,YAA6B,iBAAiB;CAAE,IAAA;CAAA,IAAA,EAAA,OAAA,QAAA;EAKxC,KAAA,WAAW,KAAA,IAAX,EAAA,OAAqC,IAArC,CAAqC;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,IAAA;CAAA,IAAA,EAAA,OAAA,UAAA;EACtC,KAAA,aAAa,KAAA,IAAb,EAAA,SAAyC,IAAzC,CAAyC;EAAC,EAAA,KAAA;EAAA,EAA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,qBAAD,EAAoB,GAAK,MAAK,CAAA;GAAI,EAAA,KAAA;GAAA,EAAA,KAAA;EAAA,OAAA,KAAA,EAAA;EAAA,OAAlC;CAAkC;CAE7C,MAAA,QAAc,WAAW,MAAK,SAAU,cAAc,MAAK,SAA7C;CAAyE,IAAA;CAAA,IAAA,EAAA,OAAA,SAAA,EAAA,OAAA,OAAA;EAChF,KAAA,oBAAC,OAAD,EAAM,GAAK,MAAK,CAAA;EAAI,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAApB;AAAoB"}
|
package/dist/shared/builtIn.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { FieldEntry } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* The entries of the built-in field types. `richtext` and `media` come with their plugins
|
|
4
|
-
*
|
|
3
|
+
* The entries of the built-in field types. `richtext` and `media` come with their plugins
|
|
4
|
+
* (`@panneau/editor` and `@panneau/media`): without them, `DefinitionField` renders a placeholder.
|
|
5
|
+
* `file` uploads through the upload source of the fields context, or gives the files themselves.
|
|
5
6
|
*/
|
|
6
7
|
export declare const builtInFields: Readonly<Record<string, FieldEntry>>;
|
|
7
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtIn.d.ts","sourceRoot":"","sources":["../../src/shared/builtIn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builtIn.d.ts","sourceRoot":"","sources":["../../src/shared/builtIn.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAiB9D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAC7C,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CAK7D,CAAC"}
|
package/dist/shared/builtIn.js
CHANGED
|
@@ -4,6 +4,7 @@ import { ColorFieldEntry } from "../color/ColorField.js";
|
|
|
4
4
|
import { DateFieldEntry } from "../date/DateField.js";
|
|
5
5
|
import { DateTimeFieldEntry } from "../datetime/DateTimeField.js";
|
|
6
6
|
import { EmailFieldEntry } from "../email/EmailField.js";
|
|
7
|
+
import { FileFieldEntry } from "../file/FileField.js";
|
|
7
8
|
import { GroupFieldEntry } from "../group/GroupField.js";
|
|
8
9
|
import { NumberFieldEntry } from "../number/NumberField.js";
|
|
9
10
|
import { RelationFieldEntry } from "../relation/RelationField.js";
|
|
@@ -16,8 +17,9 @@ import { UrlFieldEntry } from "../url/UrlField.js";
|
|
|
16
17
|
import { fr } from "@panneau/intl";
|
|
17
18
|
//#region src/shared/builtIn.ts
|
|
18
19
|
/**
|
|
19
|
-
* The entries of the built-in field types. `richtext` and `media` come with their plugins
|
|
20
|
-
*
|
|
20
|
+
* The entries of the built-in field types. `richtext` and `media` come with their plugins
|
|
21
|
+
* (`@panneau/editor` and `@panneau/media`): without them, `DefinitionField` renders a placeholder.
|
|
22
|
+
* `file` uploads through the upload source of the fields context, or gives the files themselves.
|
|
21
23
|
*/
|
|
22
24
|
var builtInFields = {
|
|
23
25
|
text: TextFieldEntry,
|
|
@@ -32,6 +34,7 @@ var builtInFields = {
|
|
|
32
34
|
url: UrlFieldEntry,
|
|
33
35
|
color: ColorFieldEntry,
|
|
34
36
|
slug: SlugFieldEntry,
|
|
37
|
+
file: FileFieldEntry,
|
|
35
38
|
relation: RelationFieldEntry,
|
|
36
39
|
group: GroupFieldEntry,
|
|
37
40
|
repeater: RepeaterFieldEntry
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtIn.js","names":[],"sources":["../../src/shared/builtIn.ts"],"sourcesContent":["import { fr } from '@panneau/intl';\n\nimport { BooleanFieldEntry } from '../boolean/BooleanField';\nimport { ColorFieldEntry } from '../color/ColorField';\nimport { DateFieldEntry } from '../date/DateField';\nimport { DateTimeFieldEntry } from '../datetime/DateTimeField';\nimport { EmailFieldEntry } from '../email/EmailField';\nimport { GroupFieldEntry } from '../group/GroupField';\nimport { NumberFieldEntry } from '../number/NumberField';\nimport { RelationFieldEntry } from '../relation/RelationField';\nimport { RepeaterFieldEntry } from '../repeater/RepeaterField';\nimport { SelectFieldEntry } from '../select/SelectField';\nimport { SlugFieldEntry } from '../slug/SlugField';\nimport { TextFieldEntry } from '../text/TextField';\nimport { TextAreaFieldEntry } from '../textarea/TextAreaField';\nimport { TimeFieldEntry } from '../time/TimeField';\nimport { UrlFieldEntry } from '../url/UrlField';\nimport type { FieldEntry } from './types';\n\n/**\n * The entries of the built-in field types. `richtext` and `media` come with their plugins
|
|
1
|
+
{"version":3,"file":"builtIn.js","names":[],"sources":["../../src/shared/builtIn.ts"],"sourcesContent":["import { fr } from '@panneau/intl';\n\nimport { BooleanFieldEntry } from '../boolean/BooleanField';\nimport { ColorFieldEntry } from '../color/ColorField';\nimport { DateFieldEntry } from '../date/DateField';\nimport { DateTimeFieldEntry } from '../datetime/DateTimeField';\nimport { EmailFieldEntry } from '../email/EmailField';\nimport { FileFieldEntry } from '../file/FileField';\nimport { GroupFieldEntry } from '../group/GroupField';\nimport { NumberFieldEntry } from '../number/NumberField';\nimport { RelationFieldEntry } from '../relation/RelationField';\nimport { RepeaterFieldEntry } from '../repeater/RepeaterField';\nimport { SelectFieldEntry } from '../select/SelectField';\nimport { SlugFieldEntry } from '../slug/SlugField';\nimport { TextFieldEntry } from '../text/TextField';\nimport { TextAreaFieldEntry } from '../textarea/TextAreaField';\nimport { TimeFieldEntry } from '../time/TimeField';\nimport { UrlFieldEntry } from '../url/UrlField';\nimport type { FieldEntry } from './types';\n\n/**\n * The entries of the built-in field types. `richtext` and `media` come with their plugins\n * (`@panneau/editor` and `@panneau/media`): without them, `DefinitionField` renders a placeholder.\n * `file` uploads through the upload source of the fields context, or gives the files themselves.\n */\nexport const builtInFields: Readonly<Record<string, FieldEntry>> = {\n text: TextFieldEntry,\n textarea: TextAreaFieldEntry,\n number: NumberFieldEntry,\n boolean: BooleanFieldEntry,\n date: DateFieldEntry,\n datetime: DateTimeFieldEntry,\n time: TimeFieldEntry,\n select: SelectFieldEntry,\n email: EmailFieldEntry,\n url: UrlFieldEntry,\n color: ColorFieldEntry,\n slug: SlugFieldEntry,\n file: FileFieldEntry,\n relation: RelationFieldEntry,\n group: GroupFieldEntry,\n repeater: RepeaterFieldEntry,\n};\n\n/**\n * The built-in fields as a `@panneau/core` plugin: their entries, and the French messages of\n * every Panneau package (`@panneau/ui`, `@panneau/fields`, `@panneau/forms`…, from\n * `@panneau/intl`). Pass it before the plugins that override a type.\n */\nexport const fieldsPlugin: {\n id: string;\n fields: Readonly<Record<string, FieldEntry>>;\n locales: Readonly<Record<string, Record<string, string>>>;\n} = {\n id: 'panneau-fields',\n fields: builtInFields,\n locales: { fr },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,gBAAsD;CAC/D,MAAM;CACN,UAAU;CACV,QAAQ;CACR,SAAS;CACT,MAAM;CACN,UAAU;CACV,MAAM;CACN,QAAQ;CACR,OAAO;CACP,KAAK;CACL,OAAO;CACP,MAAM;CACN,MAAM;CACN,UAAU;CACV,OAAO;CACP,UAAU;AACd;;;;;;AAOA,IAAa,eAIT;CACA,IAAI;CACJ,QAAQ;CACR,SAAS,EAAE,GAAG;AAClB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FieldCheckRequest, FieldCheckResponse } from '@panneau/protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Where fields with `check` check their value as it is typed: whether a slug is available, and
|
|
4
|
+
* its URL. The value's locale and the form's values come with each check.
|
|
5
|
+
*/
|
|
6
|
+
export interface FieldCheckSource {
|
|
7
|
+
check(field: string, request: {
|
|
8
|
+
value: string;
|
|
9
|
+
locale?: string;
|
|
10
|
+
values?: Record<string, unknown>;
|
|
11
|
+
}, options: {
|
|
12
|
+
signal: AbortSignal;
|
|
13
|
+
}): Promise<FieldCheckResponse>;
|
|
14
|
+
}
|
|
15
|
+
/** What `createFieldCheckSource()` needs from an adapter: the `checkField()` of `@panneau/data`. */
|
|
16
|
+
export interface FieldCheckAdapter {
|
|
17
|
+
checkField?(resource: string, field: string, request: FieldCheckRequest, options?: {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}): Promise<FieldCheckResponse>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The check source of a form of a resource, through an adapter (`POST
|
|
23
|
+
* /resources/{resource}/fields/{field}/check`): `id` is the item being edited, or null when
|
|
24
|
+
* creating one. Null when the adapter can't check.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createFieldCheckSource(adapter: FieldCheckAdapter, resource: string, id?: string | null): FieldCheckSource | null;
|
|
27
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/shared/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE/E;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,KAAK,CACD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EAC7E,OAAO,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAClC;AAED,oGAAoG;AACpG,MAAM,WAAW,iBAAiB;IAC9B,UAAU,CAAC,CACP,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACnC,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAClC;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,MAAM,EAChB,EAAE,GAAE,MAAM,GAAG,IAAW,GACzB,gBAAgB,GAAG,IAAI,CASzB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/shared/check.ts
|
|
2
|
+
/**
|
|
3
|
+
* The check source of a form of a resource, through an adapter (`POST
|
|
4
|
+
* /resources/{resource}/fields/{field}/check`): `id` is the item being edited, or null when
|
|
5
|
+
* creating one. Null when the adapter can't check.
|
|
6
|
+
*/
|
|
7
|
+
function createFieldCheckSource(adapter, resource, id = null) {
|
|
8
|
+
const { checkField } = adapter;
|
|
9
|
+
if (checkField === void 0) return null;
|
|
10
|
+
return { check: (field, request, { signal }) => checkField.call(adapter, resource, field, {
|
|
11
|
+
...request,
|
|
12
|
+
id
|
|
13
|
+
}, { signal }) };
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createFieldCheckSource };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","names":[],"sources":["../../src/shared/check.ts"],"sourcesContent":["import type { FieldCheckRequest, FieldCheckResponse } from '@panneau/protocol';\n\n/**\n * Where fields with `check` check their value as it is typed: whether a slug is available, and\n * its URL. The value's locale and the form's values come with each check.\n */\nexport interface FieldCheckSource {\n check(\n field: string,\n request: { value: string; locale?: string; values?: Record<string, unknown> },\n options: { signal: AbortSignal },\n ): Promise<FieldCheckResponse>;\n}\n\n/** What `createFieldCheckSource()` needs from an adapter: the `checkField()` of `@panneau/data`. */\nexport interface FieldCheckAdapter {\n checkField?(\n resource: string,\n field: string,\n request: FieldCheckRequest,\n options?: { signal?: AbortSignal },\n ): Promise<FieldCheckResponse>;\n}\n\n/**\n * The check source of a form of a resource, through an adapter (`POST\n * /resources/{resource}/fields/{field}/check`): `id` is the item being edited, or null when\n * creating one. Null when the adapter can't check.\n */\nexport function createFieldCheckSource(\n adapter: FieldCheckAdapter,\n resource: string,\n id: string | null = null,\n): FieldCheckSource | null {\n const { checkField } = adapter;\n if (checkField === undefined) {\n return null;\n }\n return {\n check: (field, request, { signal }) =>\n checkField.call(adapter, resource, field, { ...request, id }, { signal }),\n };\n}\n"],"mappings":";;;;;;AA6BA,SAAgB,uBACZ,SACA,UACA,KAAoB,MACG;CACvB,MAAM,EAAE,eAAe;CACvB,IAAI,eAAe,KAAA,GACf,OAAO;CAEX,OAAO,EACH,QAAQ,OAAO,SAAS,EAAE,aACtB,WAAW,KAAK,SAAS,UAAU,OAAO;EAAE,GAAG;EAAS;CAAG,GAAG,EAAE,OAAO,CAAC,EAChF;AACJ"}
|
package/dist/shared/context.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ComponentType, type ReactNode } from 'react';
|
|
2
2
|
import type { Field } from '@panneau/protocol';
|
|
3
|
+
import type { UploadSource } from '../upload/types';
|
|
4
|
+
import type { FieldCheckSource } from './check';
|
|
3
5
|
import type { RelationSource } from './relation';
|
|
4
6
|
import type { FieldEntry } from './types';
|
|
5
7
|
/** What a binding gives a field: its value, handlers and errors at a path. */
|
|
@@ -32,6 +34,13 @@ export interface FieldsContextValue {
|
|
|
32
34
|
locales: readonly string[];
|
|
33
35
|
/** Where relation fields search for items. */
|
|
34
36
|
relationSource: RelationSource | null;
|
|
37
|
+
/**
|
|
38
|
+
* Where fields that take files upload them directly to storage. Without one, they give the
|
|
39
|
+
* files themselves.
|
|
40
|
+
*/
|
|
41
|
+
uploadSource: UploadSource | null;
|
|
42
|
+
/** Where fields with `check` check their value, such as a slug's availability. */
|
|
43
|
+
checkSource: FieldCheckSource | null;
|
|
35
44
|
binding: FieldBinding | null;
|
|
36
45
|
}
|
|
37
46
|
/** The fields context of the closest `FieldsProvider`. */
|
|
@@ -41,15 +50,19 @@ export interface FieldsProviderProps {
|
|
|
41
50
|
components?: Readonly<Record<string, FieldEntry>>;
|
|
42
51
|
locales?: readonly string[];
|
|
43
52
|
relationSource?: RelationSource | null;
|
|
53
|
+
/** Make it once, outside of render: fields make an uploader for each source they get. */
|
|
54
|
+
uploadSource?: UploadSource | null;
|
|
55
|
+
/** `createFieldCheckSource(adapter, resource, id)`, for the form of an item. */
|
|
56
|
+
checkSource?: FieldCheckSource | null;
|
|
44
57
|
binding?: FieldBinding | null;
|
|
45
58
|
children?: ReactNode;
|
|
46
59
|
}
|
|
47
60
|
/**
|
|
48
61
|
* Provides what fields rendered from a definition need: the components of each type, the locales
|
|
49
|
-
* of localized values, a relation source and a binding. Values not given come from the parent
|
|
62
|
+
* of localized values, a relation source, an upload source, a check source and a binding. Values not given come from the parent
|
|
50
63
|
* provider.
|
|
51
64
|
*/
|
|
52
|
-
export declare function FieldsProvider({ components, locales, relationSource, binding, children, }: FieldsProviderProps): import("react").JSX.Element;
|
|
65
|
+
export declare function FieldsProvider({ components, locales, relationSource, uploadSource, checkSource, binding, children, }: FieldsProviderProps): import("react").JSX.Element;
|
|
53
66
|
/** The parent path of a path: `blocks.2` for `blocks.2.title`, `''` for `title`. */
|
|
54
67
|
export declare function getParentPath(path: string): string;
|
|
55
68
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/shared/context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAsB,MAAM,OAAO,CAAC;AAE/E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mB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