@cscfi/csc-ui 4.0.0-alpha.13 → 4.0.0-alpha.14

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.
@@ -0,0 +1,247 @@
1
+ import type { CFieldSize } from '../../types';
2
+ /**
3
+ * Custom search predicate for `c-tree-select`. Receives the item, the query
4
+ * and the item's ancestors root-first; return `true` to list the item. The
5
+ * default matches the query case-insensitively anywhere in the `name` or
6
+ * `code` of the item or of any of its ancestors.
7
+ */
8
+ export type CTreeSelectFilter = (item: CTreeSelectItem, query: string, path: CTreeSelectItem[]) => boolean;
9
+ /**
10
+ * One item of a `c-tree-select` tree. An item with a non-empty `children`
11
+ * array is a branch; any other item is a leaf. Values must be unique across
12
+ * the whole tree.
13
+ */
14
+ export interface CTreeSelectItem {
15
+ /** Child items; present and non-empty for a branch. */
16
+ children?: CTreeSelectItem[];
17
+ /**
18
+ * Short code shown before the name and matched by the search (a
19
+ * classification number, say).
20
+ */
21
+ code?: string;
22
+ /**
23
+ * Disable the item: a disabled branch cannot be entered, a disabled leaf
24
+ * cannot be committed.
25
+ */
26
+ disabled?: boolean;
27
+ /** The item's label. */
28
+ name: string;
29
+ /** The item's value, unique across the tree. */
30
+ value: number | string;
31
+ }
32
+ export interface CTreeSelectProps {
33
+ /**
34
+ * Let a branch be committed as the value: a pinned select-branch row heads
35
+ * every level below the root, and matching branches are listed as search
36
+ * results
37
+ */
38
+ allowBranch?: boolean;
39
+ /**
40
+ * Make the selected value clearable
41
+ */
42
+ clearable?: boolean;
43
+ /**
44
+ * Disable the field
45
+ */
46
+ disabled?: boolean;
47
+ /**
48
+ * Error message shown in place of the hint while the field is invalid
49
+ *
50
+ * @freeform
51
+ */
52
+ errorMessage?: string;
53
+ /**
54
+ * Custom search predicate; receives the item, the query and the item's
55
+ * ancestors. Functions have no attribute form — bind as a DOM property
56
+ */
57
+ filter?: CTreeSelectFilter;
58
+ /**
59
+ * Hide the hint and error messages
60
+ */
61
+ hideDetails?: boolean;
62
+ /**
63
+ * Hint text for the field
64
+ *
65
+ * @freeform
66
+ */
67
+ hint?: string;
68
+ /**
69
+ * Id of the element
70
+ *
71
+ * @freeform
72
+ */
73
+ hostId?: string;
74
+ /**
75
+ * The tree to pick from. Arrays have no attribute form — bind as a DOM
76
+ * property (`:items.prop` in Vue)
77
+ */
78
+ items?: CTreeSelectItem[];
79
+ /**
80
+ * Items per page before the list scrolls
81
+ */
82
+ itemsPerPage?: number;
83
+ /**
84
+ * Element label
85
+ *
86
+ * @freeform
87
+ */
88
+ label?: string;
89
+ /**
90
+ * Label on top of the field
91
+ */
92
+ labelOnTop?: boolean;
93
+ /**
94
+ * Names of the levels, top level first, shown in the panel header; a
95
+ * missing entry falls back to `texts.level(n)`. Arrays have no attribute
96
+ * form — bind as a DOM property
97
+ */
98
+ levelLabels?: string[];
99
+ /**
100
+ * Input field name
101
+ *
102
+ * @freeform
103
+ */
104
+ name?: string;
105
+ /**
106
+ * Placeholder for the search input inside the panel
107
+ *
108
+ * @freeform
109
+ */
110
+ placeholder?: string;
111
+ /**
112
+ * Set the field as required
113
+ */
114
+ required?: boolean;
115
+ /**
116
+ * Emit the committed item with its path as a `CTreeSelectSelection` instead
117
+ * of its value
118
+ */
119
+ returnObject?: boolean;
120
+ /**
121
+ * Shadow variant
122
+ */
123
+ shadow?: boolean;
124
+ /**
125
+ * Field height: the 44px default or the 36px `small` box
126
+ */
127
+ size?: CFieldSize;
128
+ /**
129
+ * UI text overrides (i18n), merged over the English defaults. Objects have
130
+ * no attribute form — bind as a DOM property (`:texts.prop` in Vue)
131
+ */
132
+ texts?: CTreeSelectTexts;
133
+ /**
134
+ * Set the validity of the field
135
+ */
136
+ valid?: boolean;
137
+ /**
138
+ * Selected value: the committed item's value, or the `CTreeSelectSelection`
139
+ * with `return-object`; `null` when nothing is selected
140
+ */
141
+ value?: CTreeSelectValue;
142
+ }
143
+ /**
144
+ * The committed item as emitted with `return-object`: a fresh object — never
145
+ * the `items` entry itself — with its ancestors root-first and without
146
+ * `children`.
147
+ */
148
+ export interface CTreeSelectSelection {
149
+ /** The committed item's code, when it has one. */
150
+ code?: string;
151
+ /** The committed item's label. */
152
+ name: string;
153
+ /** The committed item's ancestors, root-first. */
154
+ path: Array<{
155
+ code?: string;
156
+ name: string;
157
+ value: number | string;
158
+ }>;
159
+ /** The committed item's value. */
160
+ value: number | string;
161
+ }
162
+ /**
163
+ * UI texts of `c-tree-select`, shallow-merged over the English defaults.
164
+ * Static labels are strings; interpolated ones are functions.
165
+ */
166
+ export interface CTreeSelectTexts {
167
+ /** Accessible label of the breadcrumb navigation in the panel. */
168
+ breadcrumb?: string;
169
+ /**
170
+ * Label of the "Browse instead" control shown in the header while a query
171
+ * is typed.
172
+ */
173
+ browse?: string;
174
+ /** Meta text on a branch row; receives its number of children. */
175
+ children?: (count: number) => string;
176
+ /**
177
+ * Header text in browse mode; receives the label of the level being
178
+ * listed.
179
+ */
180
+ choose?: (levelLabel: string) => string;
181
+ /** Accessible label of the clear button. */
182
+ clearSelection?: string;
183
+ /** Accessible label of the search input inside the panel. */
184
+ filterOptions?: string;
185
+ /**
186
+ * Header text of a level whose rows are all leaves in an unevenly deep
187
+ * tree (an evenly deep tree shows the step counter instead).
188
+ */
189
+ final?: string;
190
+ /**
191
+ * Default label of level `n` (1 = the top level) when `level-labels` gives
192
+ * none.
193
+ */
194
+ level?: (n: number) => string;
195
+ /** Header text in search mode; receives the number of matches. */
196
+ matches?: (count: number) => string;
197
+ /** Text of the row shown when nothing is listed. */
198
+ noResults?: string;
199
+ /** Label of the root crumb. */
200
+ root?: string;
201
+ /** Placeholder of the search input when the `placeholder` prop is empty. */
202
+ searchPlaceholder?: string;
203
+ /**
204
+ * Label of the pinned select-branch row; receives the current branch's
205
+ * name.
206
+ */
207
+ select?: (name: string) => string;
208
+ /**
209
+ * Header step counter shown while the tree is evenly deep (every leaf at
210
+ * one level); receives the step and the total number of levels.
211
+ */
212
+ step?: (n: number, total: number) => string;
213
+ /** Accessible label of the chevron button that opens and closes the panel. */
214
+ toggleOptions?: string;
215
+ }
216
+ /**
217
+ * Selection value of `c-tree-select`: the committed item's value — or a
218
+ * {@link CTreeSelectSelection} with `return-object` — and `null` when
219
+ * cleared.
220
+ */
221
+ export type CTreeSelectValue = CTreeSelectSelection | null | number | string;
222
+ declare const _default: typeof __VLS_export;
223
+ export default _default;
224
+ declare const __VLS_export: import("vue").DefineComponent<CTreeSelectProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CTreeSelectProps> & Readonly<{}>, {
225
+ label: string;
226
+ filter: CTreeSelectFilter;
227
+ value: CTreeSelectValue;
228
+ name: string;
229
+ clearable: boolean;
230
+ disabled: boolean;
231
+ errorMessage: string;
232
+ hideDetails: boolean;
233
+ hint: string;
234
+ hostId: string;
235
+ items: CTreeSelectItem[];
236
+ itemsPerPage: number;
237
+ labelOnTop: boolean;
238
+ placeholder: string;
239
+ required: boolean;
240
+ returnObject: boolean;
241
+ shadow: boolean;
242
+ size: CFieldSize;
243
+ texts: CTreeSelectTexts;
244
+ valid: boolean;
245
+ allowBranch: boolean;
246
+ levelLabels: string[];
247
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -20,6 +20,7 @@ export type { CTextFieldAutocapitalize, CTextFieldProps, CTextFieldType, } from
20
20
  export type { CToastProps } from './components/c-toast/CToast.vue';
21
21
  export type { CToastsHorizontal, CToastsProps, CToastsVertical, } from './components/c-toasts/CToasts.vue';
22
22
  export type { CTooltipProps } from './components/c-tooltip/CTooltip.vue';
23
+ export type { CTreeSelectFilter, CTreeSelectItem, CTreeSelectProps, CTreeSelectSelection, CTreeSelectTexts, CTreeSelectValue, } from './components/c-tree-select/CTreeSelect.vue';
23
24
  export type * from './tag-name-map';
24
25
  export { applyTheme, resetTheme, themeToCss } from './theme/applyTheme';
25
26
  export type { Family, ThemeSeeds } from './theme/applyTheme';
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Anchored field panel (CONTEXT.md "Autocomplete", "Tree select", "Top
3
+ * layer"; ADR-0008, ADR-0009, ADR-0047): the lifecycle shared by the
4
+ * value-selection fields that keep a readonly value field in place and open a
5
+ * native popover panel anchored under it — `c-autocomplete` and
6
+ * `c-tree-select`.
7
+ *
8
+ * What it owns:
9
+ * - the anchor. CSS anchor names are tree-scoped, so the consumer wraps its
10
+ * value field in a shadow-DOM box carrying `anchor-name`; `anchorStyle`
11
+ * supplies that declaration and `panelStyle` the matching
12
+ * `position-anchor` / `position-area` plus the panel width pinned to the
13
+ * anchor's rect on open;
14
+ * - the message pull-back. The anchor wrapper spans the whole inner
15
+ * `c-input`, INCLUDING its hint / error message area (reserved unless
16
+ * `hide-details` is set). The panel must sit flush under the field
17
+ * itself, so the `[part='message']` height is measured on open and pulled
18
+ * back with a negative block-start margin;
19
+ * - open / close through `showPopover()` / `hidePopover()` on a
20
+ * `popover="manual"` panel, with the native `toggle` event as the single
21
+ * source of truth for `isOpen` (browser-initiated closes included);
22
+ * - light dismiss: a capture-phase document `pointerdown` listener that
23
+ * closes unless the composed path includes the host;
24
+ * - focus return to the value field on `close(true)`;
25
+ * - the OddBird anchor polyfill kick-off on open (Firefox).
26
+ *
27
+ * What stays in the consumer: the `@position-try --c-field-panel-above` /
28
+ * `--c-field-panel-above-left` flip rules and `position-try-fallbacks` —
29
+ * per-shadow-root escape-hatch CSS (ADR-0007; each element type has its own
30
+ * adopted sheet, so the block is copy-identical in every consumer) — and the
31
+ * open sequence (peek cap, focus, highlight seed, announcement), run from
32
+ * `onOpened` synchronously inside the `toggle` handler.
33
+ */
34
+ import { type ComputedRef, type MaybeRefOrGetter, type Ref } from 'vue';
35
+ /**
36
+ * The `anchor-name` every anchored field panel uses. Anchor names are
37
+ * tree-scoped, so one name serves every consumer's shadow root.
38
+ */
39
+ export declare const FIELD_PANEL_ANCHOR = "--c-field-panel-anchor";
40
+ export interface AnchoredPanel {
41
+ /** Inline style for the anchor wrapper: `anchor-name: --c-field-panel-anchor`. */
42
+ anchorStyle: string;
43
+ /** Hide the panel; `returnFocus` moves focus to `returnFocusTo` once the `toggle` event confirms the close. */
44
+ close(returnFocus?: boolean): void;
45
+ /** Open state — written only by the native `toggle` event (single source of truth, browser-initiated closes included). */
46
+ isOpen: Readonly<Ref<boolean>>;
47
+ /** Bind as the panel's `@toggle` handler. */
48
+ onToggle(event: Event): void;
49
+ /** Measure the anchor width and the field's message height, then `showPopover()`. */
50
+ open(): void;
51
+ /** Inline style for the panel: `position-anchor`, `position-area: bottom span-right`, `inset: auto`, the pinned width and the message pull-back. */
52
+ panelStyle: ComputedRef<string>;
53
+ }
54
+ export interface UseAnchoredPanelOptions {
55
+ /** Shadow-DOM wrapper around the value field; carries `anchor-name`, and its rect pins the panel width. */
56
+ anchor: Readonly<Ref<HTMLElement | null>>;
57
+ /** `open()` is a no-op while this returns true (the field's `disabled`). */
58
+ disabled?: () => boolean;
59
+ /** The inner `c-input` host: its `[part='message']` height is pulled back so the panel sits flush under the field box. */
60
+ field: Readonly<Ref<HTMLElement | null>>;
61
+ /** The custom element host: light dismiss keeps pointerdowns whose composed path includes it; its shadow root is what the anchor polyfill runs against. */
62
+ host: HTMLElement | null;
63
+ /** Runs inside the native `toggle` handler once closed, before focus returns. */
64
+ onClosed?: () => void;
65
+ /** Runs inside the native `toggle` handler once open, after the polyfill kick-off and the dismiss listener — the consumer's open sequence goes here. */
66
+ onOpened?: () => void;
67
+ /** The `popover="manual"` panel element. */
68
+ panel: Readonly<Ref<HTMLElement | null>>;
69
+ /** Receives focus when the panel closes via `close(true)`. */
70
+ returnFocusTo: MaybeRefOrGetter<HTMLElement | null | undefined>;
71
+ }
72
+ export declare const useAnchoredPanel: (options: UseAnchoredPanelOptions) => AnchoredPanel;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Debounced polite live region for a component's status text — the
3
+ * announcer behind the visually hidden `aria-live="polite" aria-atomic="true"`
4
+ * region a value-selection field renders (`c-autocomplete`, `c-tree-select`).
5
+ *
6
+ * The 1400 ms debounce is the cadence every list panel in the library uses
7
+ * (`c-dropdown` / `c-select` keep their own copies for now — `set()` is the
8
+ * seam for a later refit): a screen reader must not hear every keystroke's
9
+ * intermediate count, only where the user came to rest. `announce()` takes a
10
+ * *compose* thunk rather than a string on purpose — it runs when the timer
11
+ * fires, so it reads the state current *then* (a fetch landing during the
12
+ * debounce is announced correctly).
13
+ *
14
+ * The region itself stays a template snippet in the consumer: it has no
15
+ * `part` and no slot, so a shared SFC would add an analyzer-scanned import
16
+ * and a child instance for no contract gain.
17
+ */
18
+ import { type Ref } from 'vue';
19
+ export interface StatusAnnouncer {
20
+ /** Schedule an announcement. `compose` runs when the debounce fires, so it reads the state current *then*; every call restarts the timer. */
21
+ announce(compose: () => string): void;
22
+ /** Drop a pending announcement (also runs on unmount). */
23
+ cancel(): void;
24
+ /** Write immediately, dropping any pending announcement. */
25
+ set(text: string): void;
26
+ /** The live text; bind as the content of the `aria-live="polite" aria-atomic="true"` region. */
27
+ text: Readonly<Ref<string>>;
28
+ }
29
+ export interface UseStatusAnnouncerOptions {
30
+ /** Debounce before a scheduled announcement lands, in ms. Default 1400. */
31
+ delay?: number;
32
+ }
33
+ export declare const useStatusAnnouncer: ({ delay, }?: UseStatusAnnouncerOptions) => StatusAnnouncer;
@@ -12,6 +12,7 @@ import type { CButtonGroupValue } from './components/c-button-group/CButtonGroup
12
12
  import type { CDataTableCellContent, CDataTableColumn, CDataTableExpandedContext, CDataTableRow, CDataTableSort, CDataTableTexts } from './components/c-data-table/CDataTable.vue';
13
13
  import type { CPaginationOptions } from './components/c-pagination/CPagination.vue';
14
14
  import type { CSelectTexts, CSelectValue } from './components/c-select/CSelect.vue';
15
+ import type { CTreeSelectFilter, CTreeSelectItem, CTreeSelectTexts, CTreeSelectValue } from './components/c-tree-select/CTreeSelect.vue';
15
16
  import type { CSelectItem, CToastMessage } from './types';
16
17
  type AccordionPrimitive = number | string;
17
18
  type AccordionValue = AccordionPrimitive | AccordionPrimitive[] | null;
@@ -560,8 +561,9 @@ export interface CDropdownElement extends Omit<HTMLElement, 'dropdownItemType' |
560
561
  */
561
562
  selectAllRow?: CDropdownSelectAllRow | null;
562
563
  /**
563
- * Values of the currently selected items in `multiple` mode; drives each
564
- * row's `aria-selected` and its indicator
564
+ * Values of the currently selected items — the picked values in `multiple`
565
+ * mode, the single value otherwise; drives each row's `aria-selected`, its
566
+ * indicator and the single-mode selected-row check
565
567
  */
566
568
  selected?: (number | string)[];
567
569
  /** Parent type — drives autocomplete-only behaviour (highlight, messages) */
@@ -1708,6 +1710,102 @@ export interface CTooltipElement extends Omit<HTMLElement, 'delay' | 'distance'
1708
1710
  removeEventListener<K extends keyof CTooltipElementEventMap>(type: K, listener: (this: CTooltipElement, ev: CTooltipElementEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
1709
1711
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
1710
1712
  }
1713
+ /** Events dispatched by `<c-tree-select>`. */
1714
+ export interface CTreeSelectElementEventMap {
1715
+ /**
1716
+ * Fired when the selection changes — an item is committed or the selection
1717
+ * is cleared — carrying the new value: the item's value, the
1718
+ * `CTreeSelectSelection` with `return-object`, or `null` when cleared.
1719
+ */
1720
+ change: CustomEvent<CTreeSelectValue>;
1721
+ /**
1722
+ * Fired whenever the query changes — on every keystroke in the search
1723
+ * input, and with an empty string when the panel opens. Carries the query
1724
+ * string.
1725
+ */
1726
+ 'change:query': CustomEvent<string>;
1727
+ /**
1728
+ * Native bubbling input event dispatched alongside every value change so a
1729
+ * plain `v-model` stays in sync. Carries no detail.
1730
+ */
1731
+ input: CustomEvent<void>;
1732
+ /** Fired alongside `change` with the same detail — the `v-model` contract. */
1733
+ 'update:value': CustomEvent<CTreeSelectValue>;
1734
+ }
1735
+ /** A hierarchical value-selection component: a readonly value field that opens a panel for browsing a tree one level at a time, or searching it as a whole, to commit one item. */
1736
+ export interface CTreeSelectElement extends Omit<HTMLElement, 'allowBranch' | 'clearable' | 'disabled' | 'errorMessage' | 'filter' | 'hideDetails' | 'hint' | 'hostId' | 'items' | 'itemsPerPage' | 'label' | 'labelOnTop' | 'levelLabels' | 'name' | 'placeholder' | 'required' | 'returnObject' | 'shadow' | 'size' | 'texts' | 'valid' | 'value'> {
1737
+ /**
1738
+ * Let a branch be committed as the value: a pinned select-branch row heads
1739
+ * every level below the root, and matching branches are listed as search
1740
+ * results
1741
+ */
1742
+ allowBranch?: boolean;
1743
+ /** Make the selected value clearable */
1744
+ clearable?: boolean;
1745
+ /** Disable the field */
1746
+ disabled?: boolean;
1747
+ /** Error message shown in place of the hint while the field is invalid */
1748
+ errorMessage?: string;
1749
+ /**
1750
+ * Custom search predicate; receives the item, the query and the item's
1751
+ * ancestors. Functions have no attribute form — bind as a DOM property
1752
+ */
1753
+ filter?: CTreeSelectFilter;
1754
+ /** Hide the hint and error messages */
1755
+ hideDetails?: boolean;
1756
+ /** Hint text for the field */
1757
+ hint?: string;
1758
+ /** Id of the element */
1759
+ hostId?: string;
1760
+ /**
1761
+ * The tree to pick from. Arrays have no attribute form — bind as a DOM
1762
+ * property (`:items.prop` in Vue)
1763
+ */
1764
+ items?: CTreeSelectItem[];
1765
+ /** Items per page before the list scrolls */
1766
+ itemsPerPage?: number;
1767
+ /** Element label */
1768
+ label?: string;
1769
+ /** Label on top of the field */
1770
+ labelOnTop?: boolean;
1771
+ /**
1772
+ * Names of the levels, top level first, shown in the panel header; a
1773
+ * missing entry falls back to `texts.level(n)`. Arrays have no attribute
1774
+ * form — bind as a DOM property
1775
+ */
1776
+ levelLabels?: string[];
1777
+ /** Input field name */
1778
+ name?: string;
1779
+ /** Placeholder for the search input inside the panel */
1780
+ placeholder?: string;
1781
+ /** Set the field as required */
1782
+ required?: boolean;
1783
+ /**
1784
+ * Emit the committed item with its path as a `CTreeSelectSelection` instead
1785
+ * of its value
1786
+ */
1787
+ returnObject?: boolean;
1788
+ /** Shadow variant */
1789
+ shadow?: boolean;
1790
+ /** Field height: the 44px default or the 36px `small` box */
1791
+ size?: 'default' | 'small';
1792
+ /**
1793
+ * UI text overrides (i18n), merged over the English defaults. Objects have
1794
+ * no attribute form — bind as a DOM property (`:texts.prop` in Vue)
1795
+ */
1796
+ texts?: CTreeSelectTexts;
1797
+ /** Set the validity of the field */
1798
+ valid?: boolean;
1799
+ /**
1800
+ * Selected value: the committed item's value, or the `CTreeSelectSelection`
1801
+ * with `return-object`; `null` when nothing is selected
1802
+ */
1803
+ value?: CTreeSelectValue;
1804
+ addEventListener<K extends keyof CTreeSelectElementEventMap>(type: K, listener: (this: CTreeSelectElement, ev: CTreeSelectElementEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
1805
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
1806
+ removeEventListener<K extends keyof CTreeSelectElementEventMap>(type: K, listener: (this: CTreeSelectElement, ev: CTreeSelectElementEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
1807
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
1808
+ }
1711
1809
  declare global {
1712
1810
  interface HTMLElementTagNameMap {
1713
1811
  'c-accordion': CAccordionElement;
@@ -1781,6 +1879,7 @@ declare global {
1781
1879
  'c-toasts': CToastsElement;
1782
1880
  'c-toolbar': CToolbarElement;
1783
1881
  'c-tooltip': CTooltipElement;
1882
+ 'c-tree-select': CTreeSelectElement;
1784
1883
  }
1785
1884
  }
1786
1885
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cscfi/csc-ui",
3
- "version": "4.0.0-alpha.13",
3
+ "version": "4.0.0-alpha.14",
4
4
  "description": "Vue 3-based replacement for @cscfi/csc-ui — same custom element tag names, Vue v-model contract.",
5
5
  "type": "module",
6
6
  "main": "./dist/csc-ui.js",