@cscfi/csc-ui 4.0.0-rc.4 → 4.0.0-rc.6

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.
Files changed (44) hide show
  1. package/dist/csc-ui.js +11345 -10712
  2. package/dist/custom-elements.json +145 -23
  3. package/dist/docs/c-button/usage.md +63 -6
  4. package/dist/docs/c-color-picker/usage.md +2 -1
  5. package/dist/docs/c-date-picker/usage.md +2 -1
  6. package/dist/docs/c-file-upload/usage.md +3 -3
  7. package/dist/docs/c-icon-button/usage.md +1 -0
  8. package/dist/docs/c-otp-input/usage.md +4 -1
  9. package/dist/docs/c-radio-group/usage.md +3 -1
  10. package/dist/docs/c-slider/usage.md +2 -2
  11. package/dist/docs/c-text-field/usage.md +53 -1
  12. package/dist/styles/css/tailwind-theme.css +6 -0
  13. package/dist/styles/css/tokens.css +95 -88
  14. package/dist/vscode.css-custom-data.json +2 -2
  15. package/dist/vscode.html-custom-data.json +63 -15
  16. package/dist/web-types.json +85 -29
  17. package/dist-types/components/c-autocomplete/CAutocomplete.vue.d.ts +2 -1
  18. package/dist-types/components/c-button/CButton.vue.d.ts +6 -2
  19. package/dist-types/components/c-button/injectButtonStyles.d.ts +1 -0
  20. package/dist-types/components/c-button-group/CButtonGroup.vue.d.ts +8 -0
  21. package/dist-types/components/c-checkbox/CCheckbox.vue.d.ts +3 -3
  22. package/dist-types/components/c-color-picker/CColorPicker.vue.d.ts +2 -1
  23. package/dist-types/components/c-date-picker/CDatePicker.vue.d.ts +2 -1
  24. package/dist-types/components/c-icon-button/CIconButton.vue.d.ts +3 -1
  25. package/dist-types/components/c-number-field/CNumberField.vue.d.ts +2 -1
  26. package/dist-types/components/c-otp-input/COtpInput.vue.d.ts +7 -0
  27. package/dist-types/components/c-radio-group/CRadioGroup.vue.d.ts +8 -0
  28. package/dist-types/components/c-select/CSelect.vue.d.ts +2 -1
  29. package/dist-types/components/c-slider/CSlider.vue.d.ts +2 -3
  30. package/dist-types/components/c-switch/CSwitch.vue.d.ts +8 -0
  31. package/dist-types/components/c-text-field/CTextField.vue.d.ts +3 -2
  32. package/dist-types/components/c-text-field/injectTextFieldStyles.d.ts +1 -0
  33. package/dist-types/components/c-time-picker/CTimePicker.vue.d.ts +2 -1
  34. package/dist-types/components/c-tree-select/CTreeSelect.vue.d.ts +1 -1
  35. package/dist-types/registry.d.ts +7 -0
  36. package/dist-types/shared/defineElement.d.ts +5 -1
  37. package/dist-types/shared/implicitSubmission.d.ts +31 -0
  38. package/dist-types/shared/useElementInternals.d.ts +7 -0
  39. package/dist-types/shared/useFormAssociation.d.ts +88 -0
  40. package/dist-types/shared/useHostStates.d.ts +5 -4
  41. package/dist-types/shared/useTypedField.d.ts +7 -0
  42. package/dist-types/shared/valueEvents.d.ts +6 -0
  43. package/dist-types/tag-name-map.d.ts +61 -21
  44. package/package.json +3 -2
@@ -31,6 +31,13 @@ interface CButtonGroupProps {
31
31
  * form — bind `value` as a DOM property (`:value.prop` in Vue).
32
32
  */
33
33
  multiple?: boolean;
34
+ /**
35
+ * The name the active button's value submits under in a native `<form>` —
36
+ * one entry per active button with `multiple`, nothing while none is active
37
+ *
38
+ * @freeform
39
+ */
40
+ name?: string;
34
41
  /**
35
42
  * Set as required — shows the required marker on the label
36
43
  */
@@ -52,6 +59,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<CButto
52
59
  focus: (options?: FocusOptions) => void;
53
60
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CButtonGroupProps> & Readonly<{}>, {
54
61
  label: string;
62
+ name: string;
55
63
  value: CButtonGroupValue;
56
64
  mandatory: boolean;
57
65
  multiple: boolean;
@@ -56,8 +56,8 @@ interface CCheckboxProps {
56
56
  */
57
57
  label?: string;
58
58
  /**
59
- * `name` of the inner checkbox input. The component is not
60
- * form-associated, so it does not submit with a `<form>`.
59
+ * The name the checkbox submits under in a native `<form>` while it is
60
+ * checked: its `true-value`, or `on` when that is `true`
61
61
  *
62
62
  * @freeform
63
63
  */
@@ -95,8 +95,8 @@ declare const __VLS_base: import("vue").DefineComponent<CCheckboxProps, {
95
95
  hint: string;
96
96
  required: boolean;
97
97
  checked: boolean;
98
- falseValue: boolean | number | string;
99
98
  indeterminate: boolean;
99
+ falseValue: boolean | number | string;
100
100
  trueValue: boolean | number | string;
101
101
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
102
102
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
@@ -118,7 +118,8 @@ interface CColorPickerProps {
118
118
  */
119
119
  labelOnTop?: boolean;
120
120
  /**
121
- * Input field name
121
+ * The name the colour submits under in a native `<form>`, in the
122
+ * picker's notation
122
123
  *
123
124
  * @freeform
124
125
  */
@@ -186,7 +186,8 @@ interface CDatePickerProps {
186
186
  */
187
187
  min?: string;
188
188
  /**
189
- * Input field name
189
+ * The name the date submits under in a native `<form>`, as its ISO text;
190
+ * a `range` as one ISO 8601 interval, `start/end`
190
191
  *
191
192
  * @freeform
192
193
  */
@@ -88,7 +88,9 @@ interface CIconButtonProps {
88
88
  }
89
89
  declare const _default: typeof __VLS_export;
90
90
  export default _default;
91
- declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<CIconButtonProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CIconButtonProps> & Readonly<{}>, {
91
+ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<CIconButtonProps, {
92
+ focus: (options?: FocusOptions) => void;
93
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CIconButtonProps> & Readonly<{}>, {
92
94
  path: string;
93
95
  text: boolean;
94
96
  outlined: boolean;
@@ -89,7 +89,8 @@ interface CNumberFieldProps {
89
89
  */
90
90
  min?: null | number;
91
91
  /**
92
- * Name of the input
92
+ * The name the number submits under in a native `<form>`, written as a
93
+ * plain JS number (`1234.5`)
93
94
  *
94
95
  * @freeform
95
96
  */
@@ -41,6 +41,12 @@ interface COtpInputProps {
41
41
  * Number of digits in the code, one box each
42
42
  */
43
43
  length?: number;
44
+ /**
45
+ * The name the code submits under in a native `<form>`, as typed so far
46
+ *
47
+ * @freeform
48
+ */
49
+ name?: string;
44
50
  /**
45
51
  * Set as required — shows the required marker on the label
46
52
  */
@@ -63,6 +69,7 @@ declare const __VLS_base: import("vue").DefineComponent<COtpInputProps, {
63
69
  label: string;
64
70
  invalid: boolean;
65
71
  length: number;
72
+ name: string;
66
73
  value: string;
67
74
  hideDetails: boolean;
68
75
  hideMessage: boolean;
@@ -41,6 +41,13 @@ interface CRadioGroupProps {
41
41
  * @freeform
42
42
  */
43
43
  label?: string;
44
+ /**
45
+ * The name the picked radio's value submits under in a native `<form>`;
46
+ * nothing submits while no radio is picked
47
+ *
48
+ * @freeform
49
+ */
50
+ name?: string;
44
51
  /**
45
52
  * Set as required
46
53
  */
@@ -62,6 +69,7 @@ declare const __VLS_base: import("vue").DefineComponent<CRadioGroupProps, {
62
69
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CRadioGroupProps> & Readonly<{}>, {
63
70
  label: string;
64
71
  invalid: boolean;
72
+ name: string;
65
73
  value: null | string;
66
74
  inline: boolean;
67
75
  hideDetails: boolean;
@@ -108,7 +108,8 @@ interface CSelectProps {
108
108
  */
109
109
  multiple?: boolean;
110
110
  /**
111
- * Input field name
111
+ * The name the picked value submits under in a native `<form>` — one entry
112
+ * per value with `multiple`
112
113
  *
113
114
  * @freeform
114
115
  */
@@ -26,8 +26,7 @@ interface CSliderProps {
26
26
  /** The smallest value. */
27
27
  min?: number;
28
28
  /**
29
- * `name` of the inner range input. The component is not
30
- * form-associated, so it does not submit with a `<form>`.
29
+ * The name the value submits under in a native `<form>`
31
30
  *
32
31
  * @freeform
33
32
  */
@@ -62,8 +61,8 @@ declare const __VLS_export: import("vue").DefineComponent<CSliderProps, {
62
61
  disabled: boolean;
63
62
  max: number;
64
63
  min: number;
65
- disableTooltip: boolean;
66
64
  labels: boolean;
65
+ disableTooltip: boolean;
67
66
  segments: number;
68
67
  tickLabels: boolean;
69
68
  ticks: boolean;
@@ -26,6 +26,13 @@ interface CSwitchProps {
26
26
  * saved. The switch ignores toggles meanwhile and is announced as busy
27
27
  */
28
28
  loading?: boolean;
29
+ /**
30
+ * The name the switch submits under in a native `<form>` while it is on:
31
+ * its `true-value`, or `on` when that is `true`
32
+ *
33
+ * @freeform
34
+ */
35
+ name?: string;
29
36
  /**
30
37
  * Set as required — shows the required marker on the label
31
38
  */
@@ -49,6 +56,7 @@ declare const __VLS_base: import("vue").DefineComponent<CSwitchProps, {
49
56
  focus: (options?: FocusOptions) => void;
50
57
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CSwitchProps> & Readonly<{}>, {
51
58
  label: string;
59
+ name: string;
52
60
  value: string | number | boolean;
53
61
  disabled: boolean;
54
62
  loading: boolean;
@@ -97,8 +97,7 @@ interface CTextFieldProps {
97
97
  */
98
98
  min?: null | number;
99
99
  /**
100
- * `name` of the inner input. The component is not form-associated, so it
101
- * does not submit with a `<form>`.
100
+ * The name the text submits under in a native `<form>`
102
101
  *
103
102
  * @freeform
104
103
  */
@@ -194,6 +193,8 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<CTextF
194
193
  trimWhitespace: boolean;
195
194
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
196
195
  pre?: (props: {}) => any;
196
+ } & {
197
+ default?: (props: {}) => any;
197
198
  } & {
198
199
  post?: (props: {}) => any;
199
200
  }>;
@@ -0,0 +1 @@
1
+ export declare const ensureTextFieldStyles: () => void;
@@ -131,7 +131,8 @@ interface CTimePickerProps {
131
131
  */
132
132
  minuteStep?: number;
133
133
  /**
134
- * Input field name
134
+ * The name the time submits under in a native `<form>`, as its ISO text;
135
+ * a `range` as one ISO 8601 interval, `start/end`
135
136
  *
136
137
  * @freeform
137
138
  */
@@ -191,7 +191,7 @@ interface CTreeSelectProps {
191
191
  */
192
192
  levelLabels?: string[];
193
193
  /**
194
- * Input field name
194
+ * The name the picked value submits under in a native `<form>`
195
195
  *
196
196
  * @freeform
197
197
  */
@@ -5,5 +5,12 @@
5
5
  * conformance suites enrol every tag from it.
6
6
  */
7
7
  export declare const components: ReadonlyArray<readonly [string, unknown]>;
8
+ /**
9
+ * The tags whose elements take part in a native `<form>` (ADR-0084): every
10
+ * value control that is a form field — not c-file-upload, whose upload
11
+ * function carries its files, nor c-tabs, c-accordion, c-modal and
12
+ * c-pagination — and the buttons, without a value.
13
+ */
14
+ export declare const formAssociatedTags: ReadonlySet<string>;
8
15
  /** Every tag `defineCustomElements()` registers, internal ones included. */
9
16
  export declare const registeredTags: ReadonlyArray<string>;
@@ -1,5 +1,9 @@
1
1
  import { type Component } from 'vue';
2
2
  export declare const hyphenate: (key: string) => string;
3
+ export interface DefineElementOptions {
4
+ /** Take part in a native `<form>` (ADR-0084). */
5
+ formAssociated?: boolean;
6
+ }
3
7
  /**
4
8
  * Register a Vue SFC as a custom element under `tag`, with the shared Tailwind
5
9
  * utility stylesheet applied to its shadow root alongside the SFC's own styles.
@@ -18,4 +22,4 @@ export declare const hyphenate: (key: string) => string;
18
22
  * No-op if `tag` is already defined — the docs may have registered the Stencil
19
23
  * version first, or this function may be called twice.
20
24
  */
21
- export declare function defineElement(tag: string, component: Component): void;
25
+ export declare function defineElement(tag: string, component: Component, { formAssociated }?: DefineElementOptions): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Implicit submission (ADR-0084): Enter in a single-line text field submits
3
+ * its form, by the browser's rule — with `<c-button type="submit">` counted as
4
+ * a submit button, which the browser's own rule cannot see (its native button
5
+ * lives in a shadow root), and the csc-ui text fields counted as the fields
6
+ * that block a form without a button from submitting.
7
+ *
8
+ * The browser does none of this for a field whose input lives in a shadow
9
+ * root, so each text-entry field calls `submitOnEnter` from its own keydown.
10
+ */
11
+ /**
12
+ * Submit `form` as Enter in one of its text fields would: click its first
13
+ * submit button — through the button, so a disabled or loading one does
14
+ * nothing — or, without one, submit when it has only one text field.
15
+ */
16
+ export declare const submitImplicitly: (form: HTMLFormElement) => void;
17
+ /**
18
+ * A text field's keydown: a plain Enter submits `form` once the event has
19
+ * finished dispatching, unless the page cancelled it, as the browser's own
20
+ * implicit submission is the keydown's default action.
21
+ */
22
+ export declare const submitOnEnter: (event: KeyboardEvent, form: HTMLFormElement | null) => void;
23
+ /**
24
+ * The keydown of a page's own input inside a csc-ui field (c-text-field's
25
+ * slotted input, ADR-0083): the browser runs its own implicit submission
26
+ * there, blind to `<c-button type="submit">`, so a plain Enter that the page
27
+ * has not cancelled by the end of its dispatch is cancelled here and
28
+ * submitted by this rule instead. A listener that stops the event first
29
+ * leaves the browser's own submission in place.
30
+ */
31
+ export declare const submitOnEnterInstead: (event: KeyboardEvent, form: HTMLFormElement | null) => void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The single path to the host's internals — custom states (`useHostStates`,
3
+ * ADR-0035) and form association (`useFormAssociation`, ADR-0084) both go
4
+ * through it. `null` where internals are unavailable (SSR, an ancient
5
+ * browser): callers degrade to a silent no-op.
6
+ */
7
+ export declare const useElementInternals: () => ElementInternals | null;
@@ -0,0 +1,88 @@
1
+ import { type Ref } from 'vue';
2
+ /**
3
+ * Form association (ADR-0084): a value control takes part in a native
4
+ * `<form>` the way a built-in control does — its value submits under its
5
+ * `name`, `form.reset()` returns it to its authored default, a disabled
6
+ * `<fieldset>` disables it, and a validating form checks it.
7
+ *
8
+ * The element class is form-associated (`defineElement`'s `formAssociated`);
9
+ * the browser calls its form callbacks, which land here through
10
+ * `formCallbacks`. Everything degrades to a silent no-op where the element is
11
+ * not form-associated or internals are unavailable (SSR).
12
+ */
13
+ /** The `value` and `checked` attributes as authored, before any upgrade. */
14
+ export interface AuthoredDefaults {
15
+ checked: boolean;
16
+ value: null | string;
17
+ }
18
+ export interface FormAssociation {
19
+ /** The form owner, or `null`. */
20
+ form(): HTMLFormElement | null;
21
+ /**
22
+ * Whether the element is disabled from outside: a disabled `<fieldset>`
23
+ * around it, or a `disabled` attribute on the host.
24
+ */
25
+ formDisabled: Readonly<Ref<boolean>>;
26
+ }
27
+ export interface FormAssociationOptions {
28
+ /** The entry name; nothing submits without one. */
29
+ name(): string | undefined;
30
+ /**
31
+ * Return the control to `authored` on `form.reset()`, through the model
32
+ * path (`emitModelInput`), so a bound model follows (ADR-0084).
33
+ */
34
+ reset(authored: AuthoredDefaults): void;
35
+ /** The failed check now, or `null` when the control passes. */
36
+ validity?(): FormValidity | null;
37
+ /** The entry value now; read only while the control has a name. */
38
+ value(): FormEntryValue;
39
+ }
40
+ /** What a control submits: one entry, one per value, or nothing. */
41
+ export type FormEntryValue = null | readonly string[] | string;
42
+ /** A failed check: the flags, the bubble's text and the control it points at. */
43
+ export interface FormValidity {
44
+ anchor?: HTMLElement | null;
45
+ flags: ValidityStateFlags;
46
+ message: string;
47
+ }
48
+ /**
49
+ * The browser's form callbacks, as `defineElement` forwards them, and the
50
+ * authored-default capture it runs on connect.
51
+ */
52
+ export declare const formCallbacks: {
53
+ /**
54
+ * Keep the authored `value` and `checked` before the element first
55
+ * upgrades: Vue's custom element writes every string, number or `true` prop
56
+ * back to its attribute (`_setProp`), so after that the attribute follows
57
+ * the value and no longer says what the markup — or a server render — set.
58
+ * A value bound as a property is not an attribute yet at this point.
59
+ */
60
+ captureAuthored(host: HTMLElement): void;
61
+ disabled(host: HTMLElement, on: boolean): void;
62
+ reset(host: HTMLElement): void;
63
+ };
64
+ /** A constraint as a detached native control would hold it. */
65
+ export type NativeConstraint = 'select' | Partial<Pick<HTMLInputElement, 'max' | 'min' | 'name' | 'pattern' | 'required' | 'type' | 'value'>>;
66
+ /**
67
+ * The browser's own wording for a failed check, in its UI language, read off
68
+ * a detached native control holding the same constraint — so a csc-ui field's
69
+ * bubble reads as a native field's would: `{ required: true }` for a missing
70
+ * value, `{ pattern: 'a', value: 'b' }` for a format, `{ type: 'number', min:
71
+ * '5', value: '3' }` for a range, `'select'` for a list.
72
+ */
73
+ export declare const nativeMessage: (constraint: NativeConstraint) => string;
74
+ /** The wording of a malformed value: a mask, a code, an unreadable date. */
75
+ export declare const formatMessage: () => string;
76
+ /**
77
+ * A native control's own failed check — `required`, a `type="email"`, `min` /
78
+ * `max` / `step` — as the host reports it, pointing at that control. `null`
79
+ * while it passes.
80
+ */
81
+ export declare const validityOf: (control: HTMLInputElement | HTMLTextAreaElement | null | undefined) => FormValidity | null;
82
+ /**
83
+ * The form side of a value control. Call once from the component's setup;
84
+ * it hands the form what `value()` returns under `name()`, reports
85
+ * `validity()` (the browser skips a disabled element's), and runs `reset` on
86
+ * a form reset.
87
+ */
88
+ export declare const useFormAssociation: (options: FormAssociationOptions) => FormAssociation;
@@ -17,9 +17,10 @@
17
17
  * Each exposed state name is public API — curated like parts, documented with
18
18
  * a `@cssstate` docblock tag so it lands in the manifest.
19
19
  *
20
- * `attachInternals()` may be called only once per element; this composable
21
- * owns that call. Everything degrades to a silent no-op where internals or
22
- * `states` are unavailable (SSR, tests, an ancient browser) — the component
23
- * still renders and behaves, only the `:state()` selector surface is absent.
20
+ * The internals come from `useElementInternals`, which owns the element's one
21
+ * `attachInternals()` call. Everything degrades to a silent no-op where
22
+ * internals or `states` are unavailable (SSR, an ancient browser) — the
23
+ * component still renders and behaves, only the `:state()` selector surface
24
+ * is absent.
24
25
  */
25
26
  export declare const useHostStates: () => ((name: string, on: boolean) => void);
@@ -39,12 +39,16 @@ export interface UseTypedFieldOptions {
39
39
  codec: TypedFieldCodec;
40
40
  /** The custom element host: the model events dispatch from it. */
41
41
  host: HTMLElement | null;
42
+ /** Whether the panel is open: Enter in the field then submits no form. */
43
+ isOpen: () => boolean;
42
44
  /** The field label (props.label). */
43
45
  label: () => string;
44
46
  /** Whether the label rests on top of the field (the resolved app default). */
45
47
  labelOnTop: Readonly<Ref<boolean>>;
46
48
  /** The typing mask derived from `pattern`; without one, typing is free. */
47
49
  mask?: Readonly<Ref<MaskSlot[]>>;
50
+ /** The name the value submits under in a native `<form>` (props.name). */
51
+ name: () => string | undefined;
48
52
  /** The end inputs' accessible names under `range`. */
49
53
  names: () => {
50
54
  end: string;
@@ -60,6 +64,8 @@ export interface UseTypedFieldOptions {
60
64
  placeholder: () => string;
61
65
  /** Whether the field holds a start and an end. */
62
66
  range: Readonly<Ref<boolean>>;
67
+ /** Whether the form demands an answer (props.required). */
68
+ required: () => boolean;
63
69
  /** What a committed range with its start after its end becomes: swapped, or kept as typed. */
64
70
  reversed: 'keep' | 'swap';
65
71
  /** The host's `value` prop. */
@@ -84,6 +90,7 @@ export declare const useTypedField: (options: UseTypedFieldOptions) => {
84
90
  endText: Ref<string, string>;
85
91
  field: import("vue").ShallowRef<HTMLElement | null, HTMLElement | null>;
86
92
  focused: Ref<boolean, boolean>;
93
+ formDisabled: Readonly<Ref<boolean, boolean>>;
87
94
  hasContent: import("vue").ComputedRef<boolean>;
88
95
  hasText: import("vue").ComputedRef<boolean>;
89
96
  inputLabel: (end: TypedFieldEnd) => string | undefined;
@@ -32,6 +32,12 @@ export declare const seedModelValue: (host: HTMLElement | null, value: unknown)
32
32
  * native range input fires `input` per move and `change` on release.
33
33
  */
34
34
  export declare const emitModelInput: (host: HTMLElement | null, value: unknown) => void;
35
+ /**
36
+ * A change a page's own input inside the control reports itself
37
+ * (c-text-field's slotted input, ADR-0083): its native `input` and `change`
38
+ * already bubble through the host, so only `update:value` joins them.
39
+ */
40
+ export declare const emitModelUpdate: (host: HTMLElement | null, value: unknown) => void;
35
41
  /** The `change` that commits what `emitModelInput` reported. */
36
42
  export declare const emitModelSettled: (host: HTMLElement | null, value: unknown) => void;
37
43
  /**