@panneau/fields 4.1.0 → 5.0.0-alpha.0
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 +72 -0
- package/dist/boolean/BooleanField.d.ts +11 -0
- package/dist/boolean/BooleanField.d.ts.map +1 -0
- package/dist/boolean/BooleanField.js +67 -0
- package/dist/boolean/BooleanField.js.map +1 -0
- package/dist/boolean/index.d.ts +2 -0
- package/dist/boolean/index.d.ts.map +1 -0
- package/dist/boolean/index.js +1 -0
- package/dist/color/ColorField.css +33 -0
- package/dist/color/ColorField.d.ts +16 -0
- package/dist/color/ColorField.d.ts.map +1 -0
- package/dist/color/ColorField.js +187 -0
- package/dist/color/ColorField.js.map +1 -0
- package/dist/color/ColorField.module.js +14 -0
- package/dist/color/ColorField.module.js.map +1 -0
- package/dist/color/index.d.ts +2 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +1 -0
- package/dist/date/DateField.d.ts +16 -0
- package/dist/date/DateField.d.ts.map +1 -0
- package/dist/date/DateField.js +132 -0
- package/dist/date/DateField.js.map +1 -0
- package/dist/date/index.d.ts +2 -0
- package/dist/date/index.d.ts.map +1 -0
- package/dist/date/index.js +1 -0
- package/dist/datetime/DateTimeField.d.ts +22 -0
- package/dist/datetime/DateTimeField.d.ts.map +1 -0
- package/dist/datetime/DateTimeField.js +78 -0
- package/dist/datetime/DateTimeField.js.map +1 -0
- package/dist/datetime/index.d.ts +2 -0
- package/dist/datetime/index.d.ts.map +1 -0
- package/dist/datetime/index.js +1 -0
- package/dist/email/EmailField.d.ts +8 -0
- package/dist/email/EmailField.d.ts.map +1 -0
- package/dist/email/EmailField.js +84 -0
- package/dist/email/EmailField.js.map +1 -0
- package/dist/email/index.d.ts +2 -0
- package/dist/email/index.d.ts.map +1 -0
- package/dist/email/index.js +1 -0
- package/dist/group/GroupField.css +14 -0
- package/dist/group/GroupField.d.ts +19 -0
- package/dist/group/GroupField.d.ts.map +1 -0
- package/dist/group/GroupField.js +140 -0
- package/dist/group/GroupField.js.map +1 -0
- package/dist/group/GroupField.module.js +8 -0
- package/dist/group/GroupField.module.js.map +1 -0
- package/dist/group/index.d.ts +2 -0
- package/dist/group/index.d.ts.map +1 -0
- package/dist/group/index.js +1 -0
- package/dist/index.d.ts +8 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -134
- package/dist/locales/index.d.ts +15 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/index.js +21 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/localized/LocalizedField.css +9 -0
- package/dist/localized/LocalizedField.d.ts +36 -0
- package/dist/localized/LocalizedField.d.ts.map +1 -0
- package/dist/localized/LocalizedField.js +207 -0
- package/dist/localized/LocalizedField.js.map +1 -0
- package/dist/localized/LocalizedField.module.js +12 -0
- package/dist/localized/LocalizedField.module.js.map +1 -0
- package/dist/localized/index.d.ts +2 -0
- package/dist/localized/index.d.ts.map +1 -0
- package/dist/localized/index.js +1 -0
- package/dist/missing/MissingField.css +18 -0
- package/dist/missing/MissingField.d.ts +7 -0
- package/dist/missing/MissingField.d.ts.map +1 -0
- package/dist/missing/MissingField.js +68 -0
- package/dist/missing/MissingField.js.map +1 -0
- package/dist/missing/MissingField.module.js +14 -0
- package/dist/missing/MissingField.module.js.map +1 -0
- package/dist/number/NumberField.d.ts +23 -0
- package/dist/number/NumberField.d.ts.map +1 -0
- package/dist/number/NumberField.js +175 -0
- package/dist/number/NumberField.js.map +1 -0
- package/dist/number/index.d.ts +2 -0
- package/dist/number/index.d.ts.map +1 -0
- package/dist/number/index.js +1 -0
- package/dist/relation/RelationField.css +43 -0
- package/dist/relation/RelationField.d.ts +40 -0
- package/dist/relation/RelationField.d.ts.map +1 -0
- package/dist/relation/RelationField.js +293 -0
- package/dist/relation/RelationField.js.map +1 -0
- package/dist/relation/RelationField.module.js +20 -0
- package/dist/relation/RelationField.module.js.map +1 -0
- package/dist/relation/index.d.ts +3 -0
- package/dist/relation/index.d.ts.map +1 -0
- package/dist/relation/index.js +3 -0
- package/dist/repeater/RepeaterField.css +80 -0
- package/dist/repeater/RepeaterField.d.ts +29 -0
- package/dist/repeater/RepeaterField.d.ts.map +1 -0
- package/dist/repeater/RepeaterField.js +220 -0
- package/dist/repeater/RepeaterField.js.map +1 -0
- package/dist/repeater/RepeaterField.module.js +26 -0
- package/dist/repeater/RepeaterField.module.js.map +1 -0
- package/dist/repeater/index.d.ts +2 -0
- package/dist/repeater/index.d.ts.map +1 -0
- package/dist/repeater/index.js +1 -0
- package/dist/select/SelectField.css +5 -0
- package/dist/select/SelectField.d.ts +38 -0
- package/dist/select/SelectField.d.ts.map +1 -0
- package/dist/select/SelectField.js +434 -0
- package/dist/select/SelectField.js.map +1 -0
- package/dist/select/SelectField.module.js +8 -0
- package/dist/select/SelectField.module.js.map +1 -0
- package/dist/select/index.d.ts +2 -0
- package/dist/select/index.d.ts.map +1 -0
- package/dist/select/index.js +1 -0
- package/dist/shared/DefinitionField.d.ts +32 -0
- package/dist/shared/DefinitionField.d.ts.map +1 -0
- package/dist/shared/DefinitionField.js +153 -0
- package/dist/shared/DefinitionField.js.map +1 -0
- package/dist/shared/builtIn.d.ts +17 -0
- package/dist/shared/builtIn.d.ts.map +1 -0
- package/dist/shared/builtIn.js +52 -0
- package/dist/shared/builtIn.js.map +1 -0
- package/dist/shared/context.d.ts +55 -0
- package/dist/shared/context.d.ts.map +1 -0
- package/dist/shared/context.js +72 -0
- package/dist/shared/context.js.map +1 -0
- package/dist/shared/cx.d.ts +3 -0
- package/dist/shared/cx.d.ts.map +1 -0
- package/dist/shared/cx.js +9 -0
- package/dist/shared/cx.js.map +1 -0
- package/dist/shared/dates.d.ts +15 -0
- package/dist/shared/dates.d.ts.map +1 -0
- package/dist/shared/dates.js +49 -0
- package/dist/shared/dates.js.map +1 -0
- package/dist/shared/entry.d.ts +23 -0
- package/dist/shared/entry.d.ts.map +1 -0
- package/dist/shared/entry.js +45 -0
- package/dist/shared/entry.js.map +1 -0
- package/dist/shared/messages.d.ts +2 -0
- package/dist/shared/messages.d.ts.map +1 -0
- package/dist/shared/messages.js +1 -0
- package/dist/shared/relation.d.ts +37 -0
- package/dist/shared/relation.d.ts.map +1 -0
- package/dist/shared/relation.js +49 -0
- package/dist/shared/relation.js.map +1 -0
- package/dist/shared/types.d.ts +50 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/slug/SlugField.d.ts +24 -0
- package/dist/slug/SlugField.d.ts.map +1 -0
- package/dist/slug/SlugField.js +216 -0
- package/dist/slug/SlugField.js.map +1 -0
- package/dist/slug/index.d.ts +2 -0
- package/dist/slug/index.d.ts.map +1 -0
- package/dist/slug/index.js +1 -0
- package/dist/text/TextField.d.ts +24 -0
- package/dist/text/TextField.d.ts.map +1 -0
- package/dist/text/TextField.js +179 -0
- package/dist/text/TextField.js.map +1 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.d.ts.map +1 -0
- package/dist/text/index.js +1 -0
- package/dist/textarea/TextAreaField.d.ts +14 -0
- package/dist/textarea/TextAreaField.d.ts.map +1 -0
- package/dist/textarea/TextAreaField.js +126 -0
- package/dist/textarea/TextAreaField.js.map +1 -0
- package/dist/textarea/index.d.ts +2 -0
- package/dist/textarea/index.d.ts.map +1 -0
- package/dist/textarea/index.js +1 -0
- package/dist/time/TimeField.d.ts +13 -0
- package/dist/time/TimeField.d.ts.map +1 -0
- package/dist/time/TimeField.js +49 -0
- package/dist/time/TimeField.js.map +1 -0
- package/dist/time/index.d.ts +2 -0
- package/dist/time/index.d.ts.map +1 -0
- package/dist/time/index.js +1 -0
- package/dist/url/UrlField.css +11 -0
- package/dist/url/UrlField.d.ts +16 -0
- package/dist/url/UrlField.d.ts.map +1 -0
- package/dist/url/UrlField.js +94 -0
- package/dist/url/UrlField.js.map +1 -0
- package/dist/url/UrlField.module.js +8 -0
- package/dist/url/UrlField.module.js.map +1 -0
- package/dist/url/index.d.ts +2 -0
- package/dist/url/index.d.ts.map +1 -0
- package/dist/url/index.js +1 -0
- package/package.json +108 -79
- package/assets/css/styles.css +0 -14
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { messages } from "../shared/messages.js";
|
|
2
|
+
import { fr as fr$1, getDefaultMessages } from "@panneau/intl";
|
|
3
|
+
//#region src/locales/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* The English messages of `@panneau/fields`, by id. They are also the default messages.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use `en`, or `withPanneauMessages()`, from `@panneau/intl`: they have the messages
|
|
8
|
+
* of every package.
|
|
9
|
+
*/
|
|
10
|
+
var en = getDefaultMessages(messages);
|
|
11
|
+
/**
|
|
12
|
+
* The French messages of `@panneau/fields`, by id.
|
|
13
|
+
*
|
|
14
|
+
* @deprecated Use `fr`, or `withPanneauMessages()`, from `@panneau/intl`: they have the messages
|
|
15
|
+
* of every package.
|
|
16
|
+
*/
|
|
17
|
+
var fr = Object.fromEntries(Object.entries(fr$1).filter(([id]) => id in en));
|
|
18
|
+
//#endregion
|
|
19
|
+
export { en, fr };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["allFr"],"sources":["../../src/locales/index.ts"],"sourcesContent":["import { fr as allFr, getDefaultMessages } from '@panneau/intl';\n\nimport { messages } from '../shared/messages';\n\n/**\n * The English messages of `@panneau/fields`, by id. They are also the default messages.\n *\n * @deprecated Use `en`, or `withPanneauMessages()`, from `@panneau/intl`: they have the messages\n * of every package.\n */\nexport const en: Record<string, string> = getDefaultMessages(messages);\n\n/**\n * The French messages of `@panneau/fields`, by id.\n *\n * @deprecated Use `fr`, or `withPanneauMessages()`, from `@panneau/intl`: they have the messages\n * of every package.\n */\nexport const fr: Record<string, string> = Object.fromEntries(\n Object.entries(allFr).filter(([id]) => id in en),\n);\n"],"mappings":";;;;;;;;;AAUA,IAAa,KAA6B,mBAAmB,QAAQ;;;;;;;AAQrE,IAAa,KAA6B,OAAO,YAC7C,OAAO,QAAQA,IAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,MAAM,EAAE,CACnD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { FieldEntryProps, FieldProps } from '../shared/types';
|
|
3
|
+
/** A localized value: a value per locale (`{ fr: 'Été', en: 'Summer' }`). */
|
|
4
|
+
export type LocalizedValue<V> = Partial<Record<string, V | null>>;
|
|
5
|
+
/** What `LocalizedField` gives the input of each locale. */
|
|
6
|
+
export interface LocalizedInputProps<V> {
|
|
7
|
+
locale: string;
|
|
8
|
+
/** Name of the locale in the UI's language, as the input's label. */
|
|
9
|
+
label: string;
|
|
10
|
+
value: V | null;
|
|
11
|
+
onChange: (value: V | null) => void;
|
|
12
|
+
onBlur?: () => void;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
readOnly?: boolean;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface LocalizedFieldProps<V> extends FieldProps<LocalizedValue<V>> {
|
|
18
|
+
/** Locales, in order. */
|
|
19
|
+
locales: readonly string[];
|
|
20
|
+
/** Renders the input of a locale. */
|
|
21
|
+
children: (props: LocalizedInputProps<V>) => ReactNode;
|
|
22
|
+
localeClassName?: string;
|
|
23
|
+
}
|
|
24
|
+
/** The name of a locale in the UI's language, capitalized (`Français`, `English`). */
|
|
25
|
+
export declare function useLocaleName(): (locale: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* A value per locale, with an input for each locale under one legend. A value without any locale
|
|
28
|
+
* filled is `null`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function LocalizedField<V>({ locales, children, value, onChange, onBlur, label, description, errors, disabled, readOnly, required, className, labelClassName, descriptionClassName, errorsClassName, localeClassName, }: LocalizedFieldProps<V>): import("react").JSX.Element;
|
|
31
|
+
/**
|
|
32
|
+
* A field of the definition with `localized: true`: the field of its type for each locale of the
|
|
33
|
+
* fields context, each at its own path (`title.fr`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function LocalizedFieldEntry(props: FieldEntryProps): import("react").JSX.Element;
|
|
36
|
+
//# sourceMappingURL=LocalizedField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizedField.d.ts","sourceRoot":"","sources":["../../src/localized/LocalizedField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAQvC,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGnE,6EAA6E;AAC7E,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAElE,4DAA4D;AAC5D,MAAM,WAAW,mBAAmB,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACzE,yBAAyB;IACzB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;IACvD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,sFAAsF;AACtF,wBAAgB,aAAa,IAAI,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAY1D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAC9B,OAAO,EACP,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,WAAW,EACX,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,eAAe,GAClB,EAAE,mBAAmB,CAAC,CAAC,CAAC,+BAsCxB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,+BA8BzD"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { useFieldsContext } from "../shared/context.js";
|
|
2
|
+
import { cx } from "../shared/cx.js";
|
|
3
|
+
import { getFieldProps } from "../shared/entry.js";
|
|
4
|
+
import LocalizedField_module_default from "./LocalizedField.module.js";
|
|
5
|
+
import { NestedField } from "../shared/DefinitionField.js";
|
|
6
|
+
import { c } from "react/compiler-runtime";
|
|
7
|
+
import { Fieldset, usePanneauIntl } from "@panneau/ui";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
//#region src/localized/LocalizedField.tsx
|
|
10
|
+
/** The name of a locale in the UI's language, capitalized (`Français`, `English`). */
|
|
11
|
+
function useLocaleName() {
|
|
12
|
+
const $ = c(2);
|
|
13
|
+
const intl = usePanneauIntl();
|
|
14
|
+
let t0;
|
|
15
|
+
if ($[0] !== intl) {
|
|
16
|
+
t0 = (locale) => {
|
|
17
|
+
let name;
|
|
18
|
+
try {
|
|
19
|
+
name = intl.formatDisplayName(locale, { type: "language" });
|
|
20
|
+
} catch {
|
|
21
|
+
name = void 0;
|
|
22
|
+
}
|
|
23
|
+
const text = name ?? locale.toUpperCase();
|
|
24
|
+
return text.charAt(0).toLocaleUpperCase(intl.locale) + text.slice(1);
|
|
25
|
+
};
|
|
26
|
+
$[0] = intl;
|
|
27
|
+
$[1] = t0;
|
|
28
|
+
} else t0 = $[1];
|
|
29
|
+
return t0;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A value per locale, with an input for each locale under one legend. A value without any locale
|
|
33
|
+
* filled is `null`.
|
|
34
|
+
*/
|
|
35
|
+
function LocalizedField(t0) {
|
|
36
|
+
const $ = c(33);
|
|
37
|
+
const { locales, children, value, onChange, onBlur, label, description, errors, disabled, readOnly, required, className, labelClassName, descriptionClassName, errorsClassName, localeClassName } = t0;
|
|
38
|
+
const localeName = useLocaleName();
|
|
39
|
+
let t1;
|
|
40
|
+
if ($[0] !== children || $[1] !== disabled || $[2] !== localeClassName || $[3] !== localeName || $[4] !== locales || $[5] !== onBlur || $[6] !== onChange || $[7] !== readOnly || $[8] !== required || $[9] !== value) {
|
|
41
|
+
let t2;
|
|
42
|
+
if ($[11] !== children || $[12] !== disabled || $[13] !== localeClassName || $[14] !== localeName || $[15] !== onBlur || $[16] !== onChange || $[17] !== readOnly || $[18] !== required || $[19] !== value) {
|
|
43
|
+
t2 = (locale) => /* @__PURE__ */ jsx("div", {
|
|
44
|
+
className: cx(LocalizedField_module_default.locale, localeClassName),
|
|
45
|
+
children: children({
|
|
46
|
+
locale,
|
|
47
|
+
label: localeName(locale),
|
|
48
|
+
value: value?.[locale] ?? null,
|
|
49
|
+
onChange: (next) => {
|
|
50
|
+
const updated = {
|
|
51
|
+
...value,
|
|
52
|
+
[locale]: next
|
|
53
|
+
};
|
|
54
|
+
const filled = Object.values(updated).some(_temp);
|
|
55
|
+
onChange?.(filled ? updated : null);
|
|
56
|
+
},
|
|
57
|
+
...onBlur !== void 0 ? { onBlur } : {},
|
|
58
|
+
...disabled !== void 0 ? { disabled } : {},
|
|
59
|
+
...readOnly !== void 0 ? { readOnly } : {},
|
|
60
|
+
...required !== void 0 ? { required } : {}
|
|
61
|
+
})
|
|
62
|
+
}, locale);
|
|
63
|
+
$[11] = children;
|
|
64
|
+
$[12] = disabled;
|
|
65
|
+
$[13] = localeClassName;
|
|
66
|
+
$[14] = localeName;
|
|
67
|
+
$[15] = onBlur;
|
|
68
|
+
$[16] = onChange;
|
|
69
|
+
$[17] = readOnly;
|
|
70
|
+
$[18] = required;
|
|
71
|
+
$[19] = value;
|
|
72
|
+
$[20] = t2;
|
|
73
|
+
} else t2 = $[20];
|
|
74
|
+
t1 = locales.map(t2);
|
|
75
|
+
$[0] = children;
|
|
76
|
+
$[1] = disabled;
|
|
77
|
+
$[2] = localeClassName;
|
|
78
|
+
$[3] = localeName;
|
|
79
|
+
$[4] = locales;
|
|
80
|
+
$[5] = onBlur;
|
|
81
|
+
$[6] = onChange;
|
|
82
|
+
$[7] = readOnly;
|
|
83
|
+
$[8] = required;
|
|
84
|
+
$[9] = value;
|
|
85
|
+
$[10] = t1;
|
|
86
|
+
} else t1 = $[10];
|
|
87
|
+
let t2;
|
|
88
|
+
if ($[21] !== t1) {
|
|
89
|
+
t2 = /* @__PURE__ */ jsx("div", {
|
|
90
|
+
className: LocalizedField_module_default.locales,
|
|
91
|
+
children: t1
|
|
92
|
+
});
|
|
93
|
+
$[21] = t1;
|
|
94
|
+
$[22] = t2;
|
|
95
|
+
} else t2 = $[22];
|
|
96
|
+
let t3;
|
|
97
|
+
if ($[23] !== className || $[24] !== description || $[25] !== descriptionClassName || $[26] !== errors || $[27] !== errorsClassName || $[28] !== label || $[29] !== labelClassName || $[30] !== required || $[31] !== t2) {
|
|
98
|
+
t3 = /* @__PURE__ */ jsx(Fieldset, {
|
|
99
|
+
legend: label,
|
|
100
|
+
description,
|
|
101
|
+
errors,
|
|
102
|
+
isRequired: required,
|
|
103
|
+
className,
|
|
104
|
+
legendClassName: labelClassName,
|
|
105
|
+
descriptionClassName,
|
|
106
|
+
errorsClassName,
|
|
107
|
+
children: t2
|
|
108
|
+
});
|
|
109
|
+
$[23] = className;
|
|
110
|
+
$[24] = description;
|
|
111
|
+
$[25] = descriptionClassName;
|
|
112
|
+
$[26] = errors;
|
|
113
|
+
$[27] = errorsClassName;
|
|
114
|
+
$[28] = label;
|
|
115
|
+
$[29] = labelClassName;
|
|
116
|
+
$[30] = required;
|
|
117
|
+
$[31] = t2;
|
|
118
|
+
$[32] = t3;
|
|
119
|
+
} else t3 = $[32];
|
|
120
|
+
return t3;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A field of the definition with `localized: true`: the field of its type for each locale of the
|
|
124
|
+
* fields context, each at its own path (`title.fr`).
|
|
125
|
+
*/
|
|
126
|
+
function _temp(entry) {
|
|
127
|
+
return entry !== null && entry !== void 0 && entry !== "";
|
|
128
|
+
}
|
|
129
|
+
function LocalizedFieldEntry(props) {
|
|
130
|
+
const $ = c(22);
|
|
131
|
+
const { locales: contextLocales } = useFieldsContext();
|
|
132
|
+
const { field, path, value } = props;
|
|
133
|
+
let t0;
|
|
134
|
+
if ($[0] !== value) {
|
|
135
|
+
t0 = value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
136
|
+
$[0] = value;
|
|
137
|
+
$[1] = t0;
|
|
138
|
+
} else t0 = $[1];
|
|
139
|
+
const record = t0;
|
|
140
|
+
let t1;
|
|
141
|
+
if ($[2] !== contextLocales || $[3] !== record) {
|
|
142
|
+
t1 = contextLocales.length > 0 ? contextLocales : Object.keys(record);
|
|
143
|
+
$[2] = contextLocales;
|
|
144
|
+
$[3] = record;
|
|
145
|
+
$[4] = t1;
|
|
146
|
+
} else t1 = $[4];
|
|
147
|
+
const locales = t1;
|
|
148
|
+
let t2;
|
|
149
|
+
if ($[5] !== props) {
|
|
150
|
+
t2 = getFieldProps(props);
|
|
151
|
+
$[5] = props;
|
|
152
|
+
$[6] = t2;
|
|
153
|
+
} else t2 = $[6];
|
|
154
|
+
let chrome;
|
|
155
|
+
if ($[7] !== t2) {
|
|
156
|
+
const { name: _name, onBlur: _onBlur, ...t3 } = t2;
|
|
157
|
+
chrome = t3;
|
|
158
|
+
$[7] = t2;
|
|
159
|
+
$[8] = chrome;
|
|
160
|
+
} else chrome = $[8];
|
|
161
|
+
let t3;
|
|
162
|
+
if ($[9] !== field || $[10] !== path || $[11] !== props.disabled || $[12] !== props.onBlur || $[13] !== props.parentValue || $[14] !== props.readOnly) {
|
|
163
|
+
t3 = (input) => /* @__PURE__ */ jsx(NestedField, {
|
|
164
|
+
field: {
|
|
165
|
+
...field,
|
|
166
|
+
localized: false,
|
|
167
|
+
label: input.label,
|
|
168
|
+
help: void 0
|
|
169
|
+
},
|
|
170
|
+
path: `${path}.${input.locale}`,
|
|
171
|
+
value: input.value,
|
|
172
|
+
onChange: input.onChange,
|
|
173
|
+
...props.onBlur !== void 0 ? { onBlur: props.onBlur } : {},
|
|
174
|
+
parentValue: props.parentValue,
|
|
175
|
+
...props.disabled !== void 0 ? { disabled: props.disabled } : {},
|
|
176
|
+
...props.readOnly !== void 0 ? { readOnly: props.readOnly } : {}
|
|
177
|
+
});
|
|
178
|
+
$[9] = field;
|
|
179
|
+
$[10] = path;
|
|
180
|
+
$[11] = props.disabled;
|
|
181
|
+
$[12] = props.onBlur;
|
|
182
|
+
$[13] = props.parentValue;
|
|
183
|
+
$[14] = props.readOnly;
|
|
184
|
+
$[15] = t3;
|
|
185
|
+
} else t3 = $[15];
|
|
186
|
+
let t4;
|
|
187
|
+
if ($[16] !== chrome || $[17] !== locales || $[18] !== props.onChange || $[19] !== record || $[20] !== t3) {
|
|
188
|
+
t4 = /* @__PURE__ */ jsx(LocalizedField, {
|
|
189
|
+
...chrome,
|
|
190
|
+
locales,
|
|
191
|
+
value: record,
|
|
192
|
+
onChange: props.onChange,
|
|
193
|
+
children: t3
|
|
194
|
+
});
|
|
195
|
+
$[16] = chrome;
|
|
196
|
+
$[17] = locales;
|
|
197
|
+
$[18] = props.onChange;
|
|
198
|
+
$[19] = record;
|
|
199
|
+
$[20] = t3;
|
|
200
|
+
$[21] = t4;
|
|
201
|
+
} else t4 = $[21];
|
|
202
|
+
return t4;
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
export { LocalizedField, LocalizedFieldEntry, useLocaleName };
|
|
206
|
+
|
|
207
|
+
//# sourceMappingURL=LocalizedField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizedField.js","names":["name","locale","label","description","errors","required","className","labelClassName","descriptionClassName","errorsClassName","locales","record","_c","styles"],"sources":["../../src/localized/LocalizedField.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { Fieldset, usePanneauIntl } from '@panneau/ui';\n\nimport { NestedField } from '../shared/DefinitionField';\nimport { useFieldsContext } from '../shared/context';\nimport { cx } from '../shared/cx';\nimport { getFieldProps } from '../shared/entry';\nimport type { FieldEntryProps, FieldProps } from '../shared/types';\nimport styles from './LocalizedField.module.css';\n\n/** A localized value: a value per locale (`{ fr: 'Été', en: 'Summer' }`). */\nexport type LocalizedValue<V> = Partial<Record<string, V | null>>;\n\n/** What `LocalizedField` gives the input of each locale. */\nexport interface LocalizedInputProps<V> {\n locale: string;\n /** Name of the locale in the UI's language, as the input's label. */\n label: string;\n value: V | null;\n onChange: (value: V | null) => void;\n onBlur?: () => void;\n disabled?: boolean;\n readOnly?: boolean;\n required?: boolean;\n}\n\nexport interface LocalizedFieldProps<V> extends FieldProps<LocalizedValue<V>> {\n /** Locales, in order. */\n locales: readonly string[];\n /** Renders the input of a locale. */\n children: (props: LocalizedInputProps<V>) => ReactNode;\n localeClassName?: string;\n}\n\n/** The name of a locale in the UI's language, capitalized (`Français`, `English`). */\nexport function useLocaleName(): (locale: string) => string {\n const intl = usePanneauIntl();\n return (locale) => {\n let name: string | undefined;\n try {\n name = intl.formatDisplayName(locale, { type: 'language' });\n } catch {\n name = undefined;\n }\n const text = name ?? locale.toUpperCase();\n return text.charAt(0).toLocaleUpperCase(intl.locale) + text.slice(1);\n };\n}\n\n/**\n * A value per locale, with an input for each locale under one legend. A value without any locale\n * filled is `null`.\n */\nexport function LocalizedField<V>({\n locales,\n children,\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 localeClassName,\n}: LocalizedFieldProps<V>) {\n const localeName = useLocaleName();\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={styles.locales}>\n {locales.map((locale) => (\n <div key={locale} className={cx(styles.locale, localeClassName)}>\n {children({\n locale,\n label: localeName(locale),\n value: value?.[locale] ?? null,\n onChange: (next) => {\n const updated = { ...value, [locale]: next };\n const filled = Object.values(updated).some(\n (entry) =>\n entry !== null && entry !== undefined && entry !== '',\n );\n onChange?.(filled ? updated : null);\n },\n ...(onBlur !== undefined ? { onBlur } : {}),\n ...(disabled !== undefined ? { disabled } : {}),\n ...(readOnly !== undefined ? { readOnly } : {}),\n ...(required !== undefined ? { required } : {}),\n })}\n </div>\n ))}\n </div>\n </Fieldset>\n );\n}\n\n/**\n * A field of the definition with `localized: true`: the field of its type for each locale of the\n * fields context, each at its own path (`title.fr`).\n */\nexport function LocalizedFieldEntry(props: FieldEntryProps) {\n const { locales: contextLocales } = useFieldsContext();\n const { field, path, value } = props;\n const record =\n value !== null && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : {};\n const locales = contextLocales.length > 0 ? contextLocales : Object.keys(record);\n const { name: _name, onBlur: _onBlur, ...chrome } = getFieldProps(props);\n return (\n <LocalizedField<unknown>\n {...chrome}\n locales={locales}\n value={record}\n onChange={props.onChange}\n >\n {(input) => (\n <NestedField\n field={{ ...field, localized: false, label: input.label, help: undefined }}\n path={`${path}.${input.locale}`}\n value={input.value}\n onChange={input.onChange}\n {...(props.onBlur !== undefined ? { onBlur: props.onBlur } : {})}\n parentValue={props.parentValue}\n {...(props.disabled !== undefined ? { disabled: props.disabled } : {})}\n {...(props.readOnly !== undefined ? { readOnly: props.readOnly } : {})}\n />\n )}\n </LocalizedField>\n );\n}\n"],"mappings":";;;;;;;;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|
|
|
1
|
+
import "./LocalizedField.css";
|
|
2
|
+
//#region src/localized/LocalizedField.module.css
|
|
3
|
+
var locales = "panneau-locales-TQodj-";
|
|
4
|
+
var locale = "panneau-locale-NSOW2A";
|
|
5
|
+
var LocalizedField_module_default = {
|
|
6
|
+
locales,
|
|
7
|
+
locale
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { LocalizedField_module_default as default, locale, locales };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=LocalizedField.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizedField.module.js","names":[],"sources":["../../src/localized/LocalizedField.module.css"],"sourcesContent":[".locales {\n display: flex;\n flex-direction: column;\n gap: var(--panneau-space-3);\n}\n\n.locale {\n min-width: 0;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/localized/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EACd,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,aAAa,GAChB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LocalizedField, LocalizedFieldEntry, useLocaleName } from "./LocalizedField.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.panneau-missing-w-xDO3 {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--panneau-space-1);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.panneau-notice-uaGWZE {
|
|
8
|
+
padding: var(--panneau-space-2) var(--panneau-space-3);
|
|
9
|
+
font-size: var(--panneau-font-size-sm);
|
|
10
|
+
color: var(--panneau-color-text-muted);
|
|
11
|
+
background-color: var(--panneau-color-surface-sunken);
|
|
12
|
+
border: var(--panneau-border-width) dashed var(--panneau-color-border-control);
|
|
13
|
+
border-radius: var(--panneau-radius-md);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.panneau-label-5coKrn {
|
|
17
|
+
font-weight: var(--panneau-font-weight-medium);
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FieldEntryProps } from '../shared/types';
|
|
2
|
+
/**
|
|
3
|
+
* The slot of a field type that no plugin provides, such as `richtext` and `media` until Phase 2:
|
|
4
|
+
* it keeps the field's place in the form and names the missing type. The value is left as is.
|
|
5
|
+
*/
|
|
6
|
+
export declare function MissingFieldEntry({ field, className }: FieldEntryProps): import("react").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=MissingField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MissingField.d.ts","sourceRoot":"","sources":["../../src/missing/MissingField.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,eAAe,+BAUtE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { cx } from "../shared/cx.js";
|
|
2
|
+
import { messages } from "../shared/messages.js";
|
|
3
|
+
import MissingField_module_default from "./MissingField.module.js";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { usePanneauIntl } from "@panneau/ui";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/missing/MissingField.tsx
|
|
8
|
+
/**
|
|
9
|
+
* The slot of a field type that no plugin provides, such as `richtext` and `media` until Phase 2:
|
|
10
|
+
* it keeps the field's place in the form and names the missing type. The value is left as is.
|
|
11
|
+
*/
|
|
12
|
+
function MissingFieldEntry(t0) {
|
|
13
|
+
const $ = c(14);
|
|
14
|
+
const { field, className } = t0;
|
|
15
|
+
const intl = usePanneauIntl();
|
|
16
|
+
let t1;
|
|
17
|
+
if ($[0] !== className) {
|
|
18
|
+
t1 = cx(MissingField_module_default.missing, className);
|
|
19
|
+
$[0] = className;
|
|
20
|
+
$[1] = t1;
|
|
21
|
+
} else t1 = $[1];
|
|
22
|
+
const t2 = field.type;
|
|
23
|
+
const t3 = field.label ?? field.name;
|
|
24
|
+
let t4;
|
|
25
|
+
if ($[2] !== t3) {
|
|
26
|
+
t4 = /* @__PURE__ */ jsx("span", {
|
|
27
|
+
className: MissingField_module_default.label,
|
|
28
|
+
children: t3
|
|
29
|
+
});
|
|
30
|
+
$[2] = t3;
|
|
31
|
+
$[3] = t4;
|
|
32
|
+
} else t4 = $[3];
|
|
33
|
+
let t5;
|
|
34
|
+
if ($[4] !== field.type || $[5] !== intl) {
|
|
35
|
+
t5 = intl.formatMessage(messages.missingPlugin, { type: field.type });
|
|
36
|
+
$[4] = field.type;
|
|
37
|
+
$[5] = intl;
|
|
38
|
+
$[6] = t5;
|
|
39
|
+
} else t5 = $[6];
|
|
40
|
+
let t6;
|
|
41
|
+
if ($[7] !== t5) {
|
|
42
|
+
t6 = /* @__PURE__ */ jsx("p", {
|
|
43
|
+
className: MissingField_module_default.notice,
|
|
44
|
+
role: "note",
|
|
45
|
+
children: t5
|
|
46
|
+
});
|
|
47
|
+
$[7] = t5;
|
|
48
|
+
$[8] = t6;
|
|
49
|
+
} else t6 = $[8];
|
|
50
|
+
let t7;
|
|
51
|
+
if ($[9] !== field.type || $[10] !== t1 || $[11] !== t4 || $[12] !== t6) {
|
|
52
|
+
t7 = /* @__PURE__ */ jsxs("div", {
|
|
53
|
+
className: t1,
|
|
54
|
+
"data-field-type": t2,
|
|
55
|
+
children: [t4, t6]
|
|
56
|
+
});
|
|
57
|
+
$[9] = field.type;
|
|
58
|
+
$[10] = t1;
|
|
59
|
+
$[11] = t4;
|
|
60
|
+
$[12] = t6;
|
|
61
|
+
$[13] = t7;
|
|
62
|
+
} else t7 = $[13];
|
|
63
|
+
return t7;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { MissingFieldEntry };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=MissingField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MissingField.js","names":["_c","styles"],"sources":["../../src/missing/MissingField.tsx"],"sourcesContent":["import { usePanneauIntl } from '@panneau/ui';\n\nimport { cx } from '../shared/cx';\nimport { messages } from '../shared/messages';\nimport type { FieldEntryProps } from '../shared/types';\nimport styles from './MissingField.module.css';\n\n/**\n * The slot of a field type that no plugin provides, such as `richtext` and `media` until Phase 2:\n * it keeps the field's place in the form and names the missing type. The value is left as is.\n */\nexport function MissingFieldEntry({ field, className }: FieldEntryProps) {\n const intl = usePanneauIntl();\n return (\n <div className={cx(styles.missing, className)} data-field-type={field.type}>\n <span className={styles.label}>{field.label ?? field.name}</span>\n <p className={styles.notice} role=\"note\">\n {intl.formatMessage(messages.missingPlugin, { type: field.type })}\n </p>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAO,kBAAA,IAAA;CAAA,MAAA,IAAAA,EAAA,EAAA;CAA2B,MAAA,EAAA,OAAA,cAAA;CAC9B,MAAA,OAAa,eAAe;CAAE,IAAA;CAAA,IAAA,EAAA,OAAA,WAAA;EAEV,KAAA,GAAGC,4BAAM,SAAU,SAAS;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAmB,MAAA,KAAA,MAAK;CACjC,MAAA,KAAA,MAAK,SAAU,MAAK;CAAK,IAAA;CAAA,IAAA,EAAA,OAAA,IAAA;EAAzD,KAAA,oBAAA,QAAA;GAAiB,WAAAA,4BAAM;GAAS,UAAA;EAAiC,CAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,IAAA;CAAA,IAAA,EAAA,OAAA,MAAA,QAAA,EAAA,OAAA,MAAA;EAE5D,KAAA,KAAI,cAAe,SAAQ,eAAgB,EAAA,MAAQ,MAAK,KAAM,CAAC;EAAC,EAAA,KAAA,MAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,IAAA;CAAA,IAAA,EAAA,OAAA,IAAA;EADrE,KAAA,oBAAA,KAAA;GAAc,WAAAA,4BAAM;GAAc,MAAA;GAC7B,UAAA;EACD,CAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,IAAA;CAAA,IAAA,EAAA,OAAA,MAAA,QAAA,EAAA,QAAA,MAAA,EAAA,QAAA,MAAA,EAAA,QAAA,IAAA;EAJR,KAAA,qBAAA,OAAA;GAAgB,WAAA;GAAgD,mBAAA;GAAhE,UAAA,CACI,IACA,EAGE;;EAAA,EAAA,KAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OALN;AAKM"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./MissingField.css";
|
|
2
|
+
//#region src/missing/MissingField.module.css
|
|
3
|
+
var missing = "panneau-missing-w-xDO3";
|
|
4
|
+
var notice = "panneau-notice-uaGWZE";
|
|
5
|
+
var label = "panneau-label-5coKrn";
|
|
6
|
+
var MissingField_module_default = {
|
|
7
|
+
missing,
|
|
8
|
+
notice,
|
|
9
|
+
label
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { MissingField_module_default as default, label, missing, notice };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=MissingField.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MissingField.module.js","names":[],"sources":["../../src/missing/MissingField.module.css"],"sourcesContent":[".missing {\n display: flex;\n flex-direction: column;\n gap: var(--panneau-space-1);\n}\n\n.notice {\n padding: var(--panneau-space-2) var(--panneau-space-3);\n font-size: var(--panneau-font-size-sm);\n color: var(--panneau-color-text-muted);\n background-color: var(--panneau-color-surface-sunken);\n border: var(--panneau-border-width) dashed var(--panneau-color-border-control);\n border-radius: var(--panneau-radius-md);\n}\n\n.label {\n font-weight: var(--panneau-font-weight-medium);\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { FieldEntryProps, FieldProps } from '../shared/types';
|
|
3
|
+
export interface NumberFieldProps extends FieldProps<number> {
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
min?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
/** Step of the steppers and arrow keys. Defaults to 1. */
|
|
8
|
+
step?: number;
|
|
9
|
+
/** Format of the number, for the locale: decimals, percent, currency. */
|
|
10
|
+
formatOptions?: Intl.NumberFormatOptions;
|
|
11
|
+
/** Content after the number: a unit. */
|
|
12
|
+
suffix?: ReactNode;
|
|
13
|
+
controlClassName?: string;
|
|
14
|
+
inputClassName?: string;
|
|
15
|
+
}
|
|
16
|
+
/** A number, formatted for the locale. An empty field is `null`. */
|
|
17
|
+
export declare function NumberField({ value, onChange, min, max, disabled, readOnly, required, ...props }: NumberFieldProps): import("react").JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* The `number` type: `min` and `max` from its rules, and settings `step`, `decimals` (the most
|
|
20
|
+
* digits after the decimal point) and `suffix`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function NumberFieldEntry(props: FieldEntryProps): import("react").JSX.Element;
|
|
23
|
+
//# sourceMappingURL=NumberField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NumberField.d.ts","sourceRoot":"","sources":["../../src/number/NumberField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEnE,MAAM,WAAW,gBAAiB,SAAQ,UAAU,CAAC,MAAM,CAAC;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,aAAa,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;IACzC,wCAAwC;IACxC,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,EACxB,KAAK,EACL,QAAQ,EACR,GAAG,EACH,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,GAAG,KAAK,EACX,EAAE,gBAAgB,+BAalB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,+BAqBtD"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { getFieldProps, getRuleNumber, getSetting, isNumber, isString } from "../shared/entry.js";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { NumberInput } from "@panneau/ui";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/number/NumberField.tsx
|
|
6
|
+
/** A number, formatted for the locale. An empty field is `null`. */
|
|
7
|
+
function NumberField(t0) {
|
|
8
|
+
const $ = c(20);
|
|
9
|
+
let disabled;
|
|
10
|
+
let max;
|
|
11
|
+
let min;
|
|
12
|
+
let onChange;
|
|
13
|
+
let props;
|
|
14
|
+
let readOnly;
|
|
15
|
+
let required;
|
|
16
|
+
let value;
|
|
17
|
+
if ($[0] !== t0) {
|
|
18
|
+
({value, onChange, min, max, disabled, readOnly, required, ...props} = t0);
|
|
19
|
+
$[0] = t0;
|
|
20
|
+
$[1] = disabled;
|
|
21
|
+
$[2] = max;
|
|
22
|
+
$[3] = min;
|
|
23
|
+
$[4] = onChange;
|
|
24
|
+
$[5] = props;
|
|
25
|
+
$[6] = readOnly;
|
|
26
|
+
$[7] = required;
|
|
27
|
+
$[8] = value;
|
|
28
|
+
} else {
|
|
29
|
+
disabled = $[1];
|
|
30
|
+
max = $[2];
|
|
31
|
+
min = $[3];
|
|
32
|
+
onChange = $[4];
|
|
33
|
+
props = $[5];
|
|
34
|
+
readOnly = $[6];
|
|
35
|
+
required = $[7];
|
|
36
|
+
value = $[8];
|
|
37
|
+
}
|
|
38
|
+
const t1 = value ?? null;
|
|
39
|
+
let t2;
|
|
40
|
+
if ($[9] !== onChange) {
|
|
41
|
+
t2 = (next) => onChange?.(next);
|
|
42
|
+
$[9] = onChange;
|
|
43
|
+
$[10] = t2;
|
|
44
|
+
} else t2 = $[10];
|
|
45
|
+
let t3;
|
|
46
|
+
if ($[11] !== disabled || $[12] !== max || $[13] !== min || $[14] !== props || $[15] !== readOnly || $[16] !== required || $[17] !== t1 || $[18] !== t2) {
|
|
47
|
+
t3 = /* @__PURE__ */ jsx(NumberInput, {
|
|
48
|
+
...props,
|
|
49
|
+
value: t1,
|
|
50
|
+
onChange: t2,
|
|
51
|
+
minValue: min,
|
|
52
|
+
maxValue: max,
|
|
53
|
+
isDisabled: disabled,
|
|
54
|
+
isReadOnly: readOnly,
|
|
55
|
+
isRequired: required
|
|
56
|
+
});
|
|
57
|
+
$[11] = disabled;
|
|
58
|
+
$[12] = max;
|
|
59
|
+
$[13] = min;
|
|
60
|
+
$[14] = props;
|
|
61
|
+
$[15] = readOnly;
|
|
62
|
+
$[16] = required;
|
|
63
|
+
$[17] = t1;
|
|
64
|
+
$[18] = t2;
|
|
65
|
+
$[19] = t3;
|
|
66
|
+
} else t3 = $[19];
|
|
67
|
+
return t3;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The `number` type: `min` and `max` from its rules, and settings `step`, `decimals` (the most
|
|
71
|
+
* digits after the decimal point) and `suffix`.
|
|
72
|
+
*/
|
|
73
|
+
function NumberFieldEntry(props) {
|
|
74
|
+
const $ = c(31);
|
|
75
|
+
const { field } = props;
|
|
76
|
+
let t0;
|
|
77
|
+
if ($[0] !== field) {
|
|
78
|
+
t0 = getRuleNumber(field, "min");
|
|
79
|
+
$[0] = field;
|
|
80
|
+
$[1] = t0;
|
|
81
|
+
} else t0 = $[1];
|
|
82
|
+
const min = t0;
|
|
83
|
+
let t1;
|
|
84
|
+
if ($[2] !== field) {
|
|
85
|
+
t1 = getRuleNumber(field, "max");
|
|
86
|
+
$[2] = field;
|
|
87
|
+
$[3] = t1;
|
|
88
|
+
} else t1 = $[3];
|
|
89
|
+
const max = t1;
|
|
90
|
+
let t2;
|
|
91
|
+
if ($[4] !== field) {
|
|
92
|
+
t2 = getSetting(field, "step", isNumber);
|
|
93
|
+
$[4] = field;
|
|
94
|
+
$[5] = t2;
|
|
95
|
+
} else t2 = $[5];
|
|
96
|
+
const step = t2;
|
|
97
|
+
let t3;
|
|
98
|
+
if ($[6] !== field) {
|
|
99
|
+
t3 = getSetting(field, "decimals", isNumber);
|
|
100
|
+
$[6] = field;
|
|
101
|
+
$[7] = t3;
|
|
102
|
+
} else t3 = $[7];
|
|
103
|
+
const decimals = t3;
|
|
104
|
+
let t4;
|
|
105
|
+
if ($[8] !== field) {
|
|
106
|
+
t4 = getSetting(field, "suffix", isString);
|
|
107
|
+
$[8] = field;
|
|
108
|
+
$[9] = t4;
|
|
109
|
+
} else t4 = $[9];
|
|
110
|
+
const suffix = t4;
|
|
111
|
+
let t5;
|
|
112
|
+
if ($[10] !== props) {
|
|
113
|
+
t5 = getFieldProps(props);
|
|
114
|
+
$[10] = props;
|
|
115
|
+
$[11] = t5;
|
|
116
|
+
} else t5 = $[11];
|
|
117
|
+
const t6 = isNumber(props.value) ? props.value : null;
|
|
118
|
+
let t7;
|
|
119
|
+
if ($[12] !== min) {
|
|
120
|
+
t7 = min !== void 0 ? { min } : {};
|
|
121
|
+
$[12] = min;
|
|
122
|
+
$[13] = t7;
|
|
123
|
+
} else t7 = $[13];
|
|
124
|
+
let t8;
|
|
125
|
+
if ($[14] !== max) {
|
|
126
|
+
t8 = max !== void 0 ? { max } : {};
|
|
127
|
+
$[14] = max;
|
|
128
|
+
$[15] = t8;
|
|
129
|
+
} else t8 = $[15];
|
|
130
|
+
let t9;
|
|
131
|
+
if ($[16] !== step) {
|
|
132
|
+
t9 = step !== void 0 ? { step } : {};
|
|
133
|
+
$[16] = step;
|
|
134
|
+
$[17] = t9;
|
|
135
|
+
} else t9 = $[17];
|
|
136
|
+
let t10;
|
|
137
|
+
if ($[18] !== decimals) {
|
|
138
|
+
t10 = decimals !== void 0 ? { formatOptions: { maximumFractionDigits: decimals } } : {};
|
|
139
|
+
$[18] = decimals;
|
|
140
|
+
$[19] = t10;
|
|
141
|
+
} else t10 = $[19];
|
|
142
|
+
let t11;
|
|
143
|
+
if ($[20] !== suffix) {
|
|
144
|
+
t11 = suffix !== void 0 ? { suffix } : {};
|
|
145
|
+
$[20] = suffix;
|
|
146
|
+
$[21] = t11;
|
|
147
|
+
} else t11 = $[21];
|
|
148
|
+
let t12;
|
|
149
|
+
if ($[22] !== props.onChange || $[23] !== t10 || $[24] !== t11 || $[25] !== t5 || $[26] !== t6 || $[27] !== t7 || $[28] !== t8 || $[29] !== t9) {
|
|
150
|
+
t12 = /* @__PURE__ */ jsx(NumberField, {
|
|
151
|
+
...t5,
|
|
152
|
+
value: t6,
|
|
153
|
+
onChange: props.onChange,
|
|
154
|
+
...t7,
|
|
155
|
+
...t8,
|
|
156
|
+
...t9,
|
|
157
|
+
...t10,
|
|
158
|
+
...t11
|
|
159
|
+
});
|
|
160
|
+
$[22] = props.onChange;
|
|
161
|
+
$[23] = t10;
|
|
162
|
+
$[24] = t11;
|
|
163
|
+
$[25] = t5;
|
|
164
|
+
$[26] = t6;
|
|
165
|
+
$[27] = t7;
|
|
166
|
+
$[28] = t8;
|
|
167
|
+
$[29] = t9;
|
|
168
|
+
$[30] = t12;
|
|
169
|
+
} else t12 = $[30];
|
|
170
|
+
return t12;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { NumberField, NumberFieldEntry };
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=NumberField.js.map
|