@telperion/elements 3.0.3 → 4.1.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/.build-manifest.json +12 -1
- package/README.md +45 -0
- package/_chunks/signal-watcher-lit-element-B9xodkLt.d.cts +29 -0
- package/_chunks/signal-watcher-lit-element-B9xodkLt.d.ts +29 -0
- package/drag-drop/drag-handle-element.cjs +1 -1
- package/drag-drop/drag-handle-element.js +1 -1
- package/fesm/elements.mjs +610 -30
- package/fesm/elements.mjs.map +1 -1
- package/iife/elements.js +192 -21
- package/iife/elements.js.map +1 -1
- package/iife/popover/index.js +44 -6
- package/iife/popover/index.js.map +1 -1
- package/iife/router/index.js.map +1 -1
- package/iife/select/index.js +278 -0
- package/iife/select/index.js.map +1 -0
- package/index.cjs +17 -0
- package/index.cjs.map +1 -1
- package/index.d.cts +2 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/index.js.map +1 -1
- package/package.json +32 -5
- package/popover/index.d.cts +1 -1
- package/popover/index.d.ts +1 -1
- package/popover/popover-element.cjs +28 -18
- package/popover/popover-element.cjs.map +1 -1
- package/popover/popover-element.js +29 -19
- package/popover/popover-element.js.map +1 -1
- package/router/index.d.cts +2 -26
- package/router/index.d.ts +2 -26
- package/router/tha-router-config.cjs +2 -2
- package/router/tha-router-config.cjs.map +1 -1
- package/router/tha-router-config.js +2 -2
- package/router/tha-router-config.js.map +1 -1
- package/router/tha-router-link.cjs +1 -1
- package/router/tha-router-link.js +1 -1
- package/router/tha-router-outlet.cjs +1 -1
- package/router/tha-router-outlet.js +1 -1
- package/router/tha-router-param.cjs +1 -1
- package/router/tha-router-param.js +1 -1
- package/router/tha-router.cjs +1 -1
- package/router/tha-router.js +1 -1
- package/select/index.cjs +23 -0
- package/select/index.cjs.map +1 -0
- package/select/index.d.cts +284 -0
- package/select/index.d.ts +284 -0
- package/select/index.js +5 -0
- package/select/index.js.map +1 -0
- package/select/internal-props.cjs +10 -0
- package/select/internal-props.cjs.map +1 -0
- package/select/internal-props.js +6 -0
- package/select/internal-props.js.map +1 -0
- package/select/option.element.cjs +88 -0
- package/select/option.element.cjs.map +1 -0
- package/select/option.element.js +88 -0
- package/select/option.element.js.map +1 -0
- package/select/select-change-event.cjs +30 -0
- package/select/select-change-event.cjs.map +1 -0
- package/select/select-change-event.js +28 -0
- package/select/select-change-event.js.map +1 -0
- package/select/select-context.cjs +14 -0
- package/select/select-context.cjs.map +1 -0
- package/select/select-context.js +12 -0
- package/select/select-context.js.map +1 -0
- package/select/select.element.cjs +414 -0
- package/select/select.element.cjs.map +1 -0
- package/select/select.element.js +414 -0
- package/select/select.element.js.map +1 -0
- package/select/selected-content.element.cjs +65 -0
- package/select/selected-content.element.cjs.map +1 -0
- package/select/selected-content.element.js +65 -0
- package/select/selected-content.element.js.map +1 -0
- package/utils/signal-watcher-lit-element.cjs.map +1 -0
- package/utils/signal-watcher-lit-element.js.map +1 -0
- package/router/signal-watcher-lit-element.cjs.map +0 -1
- package/router/signal-watcher-lit-element.js.map +0 -1
- /package/{router → utils}/signal-watcher-lit-element.cjs +0 -0
- /package/{router → utils}/signal-watcher-lit-element.js +0 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { PropertyValues } from 'lit';
|
|
2
|
+
import { S as SignalWatcherLitElement } from '../_chunks/signal-watcher-lit-element-B9xodkLt.cjs';
|
|
3
|
+
|
|
4
|
+
declare const REGISTER_OPTION: unique symbol;
|
|
5
|
+
declare const UNREGISTER_OPTION: unique symbol;
|
|
6
|
+
declare const SHOULD_REGISTER_TO_SELECT: unique symbol;
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLElementTagNameMap {
|
|
10
|
+
/**
|
|
11
|
+
* A single selectable item inside a `<tp-select>`.
|
|
12
|
+
*
|
|
13
|
+
* Discovers its host `<tp-select>` via `@lit/context`, registers itself
|
|
14
|
+
* on connect, and reflects its own selected state through the
|
|
15
|
+
* `selected` attribute (read-only — set selection by clicking, by
|
|
16
|
+
* mutating `tp-select.value`, or by calling
|
|
17
|
+
* `selectOption()`/`deselectOption()`/`toggleOption()` on the host).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```html
|
|
21
|
+
* <tp-select>
|
|
22
|
+
* <tp-option value="apple">Apple</tp-option>
|
|
23
|
+
* <tp-option value="banana">Banana</tp-option>
|
|
24
|
+
* </tp-select>
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @attr value - The submitted value when this option is selected.
|
|
28
|
+
* @attr selected - Reflects current selection state (do not set manually).
|
|
29
|
+
*
|
|
30
|
+
* @slot - Visible label for the option.
|
|
31
|
+
*/
|
|
32
|
+
"tp-option": OptionElement;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
declare class OptionElement extends SignalWatcherLitElement {
|
|
36
|
+
static styles: any;
|
|
37
|
+
private select?;
|
|
38
|
+
[SHOULD_REGISTER_TO_SELECT]: boolean;
|
|
39
|
+
value: string;
|
|
40
|
+
connectedCallback(): void;
|
|
41
|
+
disconnectedCallback(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Reflect `selected` state by reading the parent's signal during the
|
|
44
|
+
* normal Lit update. `SignalWatcher` auto-tracks signal access here, so
|
|
45
|
+
* the option will re-render whenever the selection changes — without
|
|
46
|
+
* the disposal-race that `updateEffect` exposes.
|
|
47
|
+
*/
|
|
48
|
+
protected willUpdate(_changed: PropertyValues): void;
|
|
49
|
+
protected createRenderRoot(): this;
|
|
50
|
+
protected render(): any;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare global {
|
|
54
|
+
interface HTMLElementTagNameMap {
|
|
55
|
+
/**
|
|
56
|
+
* A form-associated, framework-agnostic selectbox.
|
|
57
|
+
*
|
|
58
|
+
* Composes `<tp-popover>` for placement and `<tp-option>` for items.
|
|
59
|
+
* Single-select by default; switches to multi-select via `max`.
|
|
60
|
+
*
|
|
61
|
+
* @example Single-select
|
|
62
|
+
* ```html
|
|
63
|
+
* <tp-select name="fruit" required>
|
|
64
|
+
* <tp-option value="apple">Apple</tp-option>
|
|
65
|
+
* <tp-option value="banana">Banana</tp-option>
|
|
66
|
+
* </tp-select>
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Multi-select with eviction limit
|
|
70
|
+
* ```html
|
|
71
|
+
* <tp-select name="tags" max="3">…</tp-select>
|
|
72
|
+
* <tp-select name="tags" max="infinite">…</tp-select>
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Custom trigger button
|
|
76
|
+
* ```html
|
|
77
|
+
* <tp-select>
|
|
78
|
+
* <button slot="button">Open</button>
|
|
79
|
+
* <tp-option value="a">A</tp-option>
|
|
80
|
+
* </tp-select>
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @attr value - Comma-joined list of selected `<tp-option>` values
|
|
84
|
+
* (read-only; derived from `selectedOptions`).
|
|
85
|
+
* @attr placeholder - Text shown by `<tp-selected-content>` when no
|
|
86
|
+
* option is selected.
|
|
87
|
+
* @attr max - `1` (default) for single-select, any positive integer
|
|
88
|
+
* for multi-select with FIFO eviction, or `infinite`
|
|
89
|
+
* for unbounded selection.
|
|
90
|
+
* @attr name - Form field name.
|
|
91
|
+
* @attr disabled - Non-interactive; excluded from form submission.
|
|
92
|
+
* @attr required - Empty selection triggers `valueMissing`.
|
|
93
|
+
* @attr open - Reflects the popover's open state (read-only).
|
|
94
|
+
*
|
|
95
|
+
* @slot button - Replaces the default trigger button.
|
|
96
|
+
* @slot indicator - Replaces the default open/close caret (`▾`) shown
|
|
97
|
+
* inside the trigger button. Rendered next to
|
|
98
|
+
* `<tp-selected-content>`; rotates 180° while the
|
|
99
|
+
* select is `open` (via the `[pseudo="indicator"]`
|
|
100
|
+
* styling).
|
|
101
|
+
* @slot popover - Replaces the default rendering of the host's children
|
|
102
|
+
* inside the panel. Use this when you want to keep the
|
|
103
|
+
* `<tp-option>`s registered in the select context — so
|
|
104
|
+
* selection, validation and form submission still work —
|
|
105
|
+
* but display something else in the popover (a message,
|
|
106
|
+
* a search field, a custom layout, …) instead of the
|
|
107
|
+
* default option list.
|
|
108
|
+
* @slot - Default slot inside the popover (where `<tp-option>`s go).
|
|
109
|
+
*
|
|
110
|
+
* @csspart button - The trigger wrapper.
|
|
111
|
+
* @csspart indicator - The default open/close caret (`▾`).
|
|
112
|
+
* Rotated 180° while the select is `open`.
|
|
113
|
+
* Suppressed when the `indicator` slot is
|
|
114
|
+
* filled.
|
|
115
|
+
* @csspart popover - The `<tp-popover>` panel.
|
|
116
|
+
* @csspart selected-content - The default `<tp-selected-content>`.
|
|
117
|
+
* @csspart placeholder - The `<span>` rendered by the default
|
|
118
|
+
* `<tp-selected-content>` when no option
|
|
119
|
+
* is selected (renders the `placeholder`
|
|
120
|
+
* attribute). Exposed because
|
|
121
|
+
* `<tp-selected-content>` is light-DOM
|
|
122
|
+
* and lives inside this element's shadow
|
|
123
|
+
* root by default.
|
|
124
|
+
* @csspart selected-content-option - Each cloned `<tp-option>` mirrored by
|
|
125
|
+
* the default `<tp-selected-content>`.
|
|
126
|
+
* Exposed for the same reason as
|
|
127
|
+
* `placeholder`. Set on the clones
|
|
128
|
+
* themselves — use
|
|
129
|
+
* `tp-select::part(selected-content-option)`
|
|
130
|
+
* to style them.
|
|
131
|
+
*
|
|
132
|
+
* @fires change - {@link SelectChangeEvent} dispatched when the selected
|
|
133
|
+
* option set changes. Bubbles, not composed (mirrors the
|
|
134
|
+
* native `<select>` `change` event). Not fired on initial
|
|
135
|
+
* mount or when the selection is re-set to the same value.
|
|
136
|
+
*/
|
|
137
|
+
"tp-select": SelectElement;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
declare class SelectElement extends SignalWatcherLitElement {
|
|
141
|
+
#private;
|
|
142
|
+
static formAssociated: boolean;
|
|
143
|
+
private static ALLOWED_OPTION_ELEMENTS;
|
|
144
|
+
static styles: any;
|
|
145
|
+
/**
|
|
146
|
+
* Provides this `<tp-select>` instance to descendants via `@lit/context`,
|
|
147
|
+
* so consumers (e.g. `<tp-selected-content>`) can find it across any
|
|
148
|
+
* number of shadow DOM boundaries — not just light-DOM ancestors.
|
|
149
|
+
*/
|
|
150
|
+
readonly self: SelectElement;
|
|
151
|
+
readonly selectedOptions: Signal.State<T>;
|
|
152
|
+
get value(): string;
|
|
153
|
+
set value(next: string);
|
|
154
|
+
get placeholder(): string;
|
|
155
|
+
set placeholder(next: string);
|
|
156
|
+
/**
|
|
157
|
+
* Maximum number of options that can be selected at once.
|
|
158
|
+
*
|
|
159
|
+
* Defaults to `1` (single-select). Any positive integer enables
|
|
160
|
+
* multi-select up to that many entries. Use the literal string
|
|
161
|
+
* `"infinite"` in HTML to allow an unbounded
|
|
162
|
+
* selection — the converter normalises it to `Number.POSITIVE_INFINITY`.
|
|
163
|
+
*
|
|
164
|
+
* When the limit is reached and a new option is selected, the oldest
|
|
165
|
+
* entry in `selectedOptions` is dropped (FIFO) so the new selection can
|
|
166
|
+
* fit. Setting `max` to a smaller number trims the current selection
|
|
167
|
+
* down to size from the end.
|
|
168
|
+
*/
|
|
169
|
+
max: number;
|
|
170
|
+
/** Form field name. Submitted with the owning `<form>`. */
|
|
171
|
+
name: string | null;
|
|
172
|
+
/** When true, the element is non-interactive and excluded from form submission. */
|
|
173
|
+
disabled: boolean;
|
|
174
|
+
/** When true, an empty selection makes the element invalid (`valueMissing`). */
|
|
175
|
+
required: boolean;
|
|
176
|
+
open: boolean;
|
|
177
|
+
constructor();
|
|
178
|
+
/** Live `ElementInternals` (validity, form, labels, etc.). */
|
|
179
|
+
get internals(): ElementInternals;
|
|
180
|
+
/** Owning `<form>` element, or `null` when not associated. */
|
|
181
|
+
get form(): HTMLFormElement | null;
|
|
182
|
+
/** Native validity state of this control. */
|
|
183
|
+
get validity(): ValidityState;
|
|
184
|
+
get validationMessage(): string;
|
|
185
|
+
get willValidate(): boolean;
|
|
186
|
+
checkValidity(): boolean;
|
|
187
|
+
reportValidity(): boolean;
|
|
188
|
+
protected createRenderRoot(): ShadowRoot;
|
|
189
|
+
connectedCallback(): void;
|
|
190
|
+
disconnectedCallback(): void;
|
|
191
|
+
protected render(): unknown;
|
|
192
|
+
protected updated(changed: Map<string, unknown>): void;
|
|
193
|
+
/**
|
|
194
|
+
* Keep `ElementInternals` in sync with the current value and validity.
|
|
195
|
+
* Reading `this.value` here transitively reads `selectedOptions`, so the
|
|
196
|
+
* `SignalWatcher` base auto-tracks it and re-runs `willUpdate` whenever
|
|
197
|
+
* the selection changes — no `updateEffect` (and no microtask race) needed.
|
|
198
|
+
*/
|
|
199
|
+
protected willUpdate(_changed: Map<string, unknown>): void;
|
|
200
|
+
formResetCallback(): void;
|
|
201
|
+
formDisabledCallback(disabled: boolean): void;
|
|
202
|
+
formStateRestoreCallback(state: File | string | FormData | null): void;
|
|
203
|
+
selectOption(option: OptionElement): void;
|
|
204
|
+
deselectOption(option: OptionElement): void;
|
|
205
|
+
toggleOption(option: OptionElement): void;
|
|
206
|
+
[REGISTER_OPTION](option: OptionElement): void;
|
|
207
|
+
[UNREGISTER_OPTION](option: OptionElement): void;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare global {
|
|
211
|
+
interface HTMLElementTagNameMap {
|
|
212
|
+
/**
|
|
213
|
+
* Mirrors the currently-selected `<tp-option>`(s) of an ancestor
|
|
214
|
+
* `<tp-select>`, falling back to the host's `placeholder` text when
|
|
215
|
+
* the selection is empty.
|
|
216
|
+
*
|
|
217
|
+
* Discovers its host via `@lit/context`, so it can live anywhere in
|
|
218
|
+
* the descendant composed tree — including across nested shadow DOM
|
|
219
|
+
* boundaries. Selected options are deeply cloned and projected into
|
|
220
|
+
* this element's light DOM; clones are inert (they don't register
|
|
221
|
+
* back to the select) and carry `part="selected-content-option"`.
|
|
222
|
+
*
|
|
223
|
+
* Used as the default content of the `<tp-select>` trigger button,
|
|
224
|
+
* but can be placed anywhere a label-style mirror is useful.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```html
|
|
228
|
+
* <tp-select>
|
|
229
|
+
* <button slot="button">
|
|
230
|
+
* <tp-selected-content></tp-selected-content>
|
|
231
|
+
* </button>
|
|
232
|
+
* <tp-option value="apple">Apple</tp-option>
|
|
233
|
+
* </tp-select>
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* Renders into its own light DOM, so it has no slots and exposes no CSS
|
|
237
|
+
* Shadow Parts of its own. The `part` attributes it stamps onto the rendered
|
|
238
|
+
* placeholder span and cloned `<tp-option>`s only become real Shadow Parts
|
|
239
|
+
* when this element happens to sit inside another shadow root — which is
|
|
240
|
+
* what happens by default inside `<tp-select>`, so those parts (`placeholder`,
|
|
241
|
+
* `selected-content-option`) are documented on `<tp-select>`.
|
|
242
|
+
*/
|
|
243
|
+
"tp-selected-content": SelectedContentElement;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
declare class SelectedContentElement extends SignalWatcherLitElement {
|
|
247
|
+
#private;
|
|
248
|
+
static styles: any;
|
|
249
|
+
private select?;
|
|
250
|
+
protected createRenderRoot(): this;
|
|
251
|
+
protected render(): unknown;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
interface SelectChangeEventInit {
|
|
255
|
+
value: string;
|
|
256
|
+
selectedOptions: readonly OptionElement[];
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Dispatched by `<tp-select>` whenever its selected option set changes.
|
|
260
|
+
*
|
|
261
|
+
* Mirrors the native `<select>` `change` event semantics:
|
|
262
|
+
* - type is `'change'`
|
|
263
|
+
* - `bubbles: true`, `composed: false`, `cancelable: false` by default
|
|
264
|
+
* - not fired on initial mount, nor when the selection is set to the
|
|
265
|
+
* same value it already had
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* select.addEventListener('change', e => {
|
|
270
|
+
* if (e instanceof SelectChangeEvent) {
|
|
271
|
+
* console.log(e.value, e.selectedOptions);
|
|
272
|
+
* }
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
declare class SelectChangeEvent extends Event {
|
|
277
|
+
/** Joined value string of the new selection (same as `tp-select.value`). */
|
|
278
|
+
readonly value: string;
|
|
279
|
+
/** Snapshot of the currently selected `<tp-option>` elements. */
|
|
280
|
+
readonly selectedOptions: readonly OptionElement[];
|
|
281
|
+
constructor(init: SelectChangeEventInit, eventInit?: EventInit);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export { OptionElement, SelectChangeEvent, SelectElement, SelectedContentElement };
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { PropertyValues } from 'lit';
|
|
2
|
+
import { S as SignalWatcherLitElement } from '../_chunks/signal-watcher-lit-element-B9xodkLt.js';
|
|
3
|
+
|
|
4
|
+
declare const REGISTER_OPTION: unique symbol;
|
|
5
|
+
declare const UNREGISTER_OPTION: unique symbol;
|
|
6
|
+
declare const SHOULD_REGISTER_TO_SELECT: unique symbol;
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLElementTagNameMap {
|
|
10
|
+
/**
|
|
11
|
+
* A single selectable item inside a `<tp-select>`.
|
|
12
|
+
*
|
|
13
|
+
* Discovers its host `<tp-select>` via `@lit/context`, registers itself
|
|
14
|
+
* on connect, and reflects its own selected state through the
|
|
15
|
+
* `selected` attribute (read-only — set selection by clicking, by
|
|
16
|
+
* mutating `tp-select.value`, or by calling
|
|
17
|
+
* `selectOption()`/`deselectOption()`/`toggleOption()` on the host).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```html
|
|
21
|
+
* <tp-select>
|
|
22
|
+
* <tp-option value="apple">Apple</tp-option>
|
|
23
|
+
* <tp-option value="banana">Banana</tp-option>
|
|
24
|
+
* </tp-select>
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @attr value - The submitted value when this option is selected.
|
|
28
|
+
* @attr selected - Reflects current selection state (do not set manually).
|
|
29
|
+
*
|
|
30
|
+
* @slot - Visible label for the option.
|
|
31
|
+
*/
|
|
32
|
+
"tp-option": OptionElement;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
declare class OptionElement extends SignalWatcherLitElement {
|
|
36
|
+
static styles: any;
|
|
37
|
+
private select?;
|
|
38
|
+
[SHOULD_REGISTER_TO_SELECT]: boolean;
|
|
39
|
+
value: string;
|
|
40
|
+
connectedCallback(): void;
|
|
41
|
+
disconnectedCallback(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Reflect `selected` state by reading the parent's signal during the
|
|
44
|
+
* normal Lit update. `SignalWatcher` auto-tracks signal access here, so
|
|
45
|
+
* the option will re-render whenever the selection changes — without
|
|
46
|
+
* the disposal-race that `updateEffect` exposes.
|
|
47
|
+
*/
|
|
48
|
+
protected willUpdate(_changed: PropertyValues): void;
|
|
49
|
+
protected createRenderRoot(): this;
|
|
50
|
+
protected render(): any;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare global {
|
|
54
|
+
interface HTMLElementTagNameMap {
|
|
55
|
+
/**
|
|
56
|
+
* A form-associated, framework-agnostic selectbox.
|
|
57
|
+
*
|
|
58
|
+
* Composes `<tp-popover>` for placement and `<tp-option>` for items.
|
|
59
|
+
* Single-select by default; switches to multi-select via `max`.
|
|
60
|
+
*
|
|
61
|
+
* @example Single-select
|
|
62
|
+
* ```html
|
|
63
|
+
* <tp-select name="fruit" required>
|
|
64
|
+
* <tp-option value="apple">Apple</tp-option>
|
|
65
|
+
* <tp-option value="banana">Banana</tp-option>
|
|
66
|
+
* </tp-select>
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Multi-select with eviction limit
|
|
70
|
+
* ```html
|
|
71
|
+
* <tp-select name="tags" max="3">…</tp-select>
|
|
72
|
+
* <tp-select name="tags" max="infinite">…</tp-select>
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Custom trigger button
|
|
76
|
+
* ```html
|
|
77
|
+
* <tp-select>
|
|
78
|
+
* <button slot="button">Open</button>
|
|
79
|
+
* <tp-option value="a">A</tp-option>
|
|
80
|
+
* </tp-select>
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @attr value - Comma-joined list of selected `<tp-option>` values
|
|
84
|
+
* (read-only; derived from `selectedOptions`).
|
|
85
|
+
* @attr placeholder - Text shown by `<tp-selected-content>` when no
|
|
86
|
+
* option is selected.
|
|
87
|
+
* @attr max - `1` (default) for single-select, any positive integer
|
|
88
|
+
* for multi-select with FIFO eviction, or `infinite`
|
|
89
|
+
* for unbounded selection.
|
|
90
|
+
* @attr name - Form field name.
|
|
91
|
+
* @attr disabled - Non-interactive; excluded from form submission.
|
|
92
|
+
* @attr required - Empty selection triggers `valueMissing`.
|
|
93
|
+
* @attr open - Reflects the popover's open state (read-only).
|
|
94
|
+
*
|
|
95
|
+
* @slot button - Replaces the default trigger button.
|
|
96
|
+
* @slot indicator - Replaces the default open/close caret (`▾`) shown
|
|
97
|
+
* inside the trigger button. Rendered next to
|
|
98
|
+
* `<tp-selected-content>`; rotates 180° while the
|
|
99
|
+
* select is `open` (via the `[pseudo="indicator"]`
|
|
100
|
+
* styling).
|
|
101
|
+
* @slot popover - Replaces the default rendering of the host's children
|
|
102
|
+
* inside the panel. Use this when you want to keep the
|
|
103
|
+
* `<tp-option>`s registered in the select context — so
|
|
104
|
+
* selection, validation and form submission still work —
|
|
105
|
+
* but display something else in the popover (a message,
|
|
106
|
+
* a search field, a custom layout, …) instead of the
|
|
107
|
+
* default option list.
|
|
108
|
+
* @slot - Default slot inside the popover (where `<tp-option>`s go).
|
|
109
|
+
*
|
|
110
|
+
* @csspart button - The trigger wrapper.
|
|
111
|
+
* @csspart indicator - The default open/close caret (`▾`).
|
|
112
|
+
* Rotated 180° while the select is `open`.
|
|
113
|
+
* Suppressed when the `indicator` slot is
|
|
114
|
+
* filled.
|
|
115
|
+
* @csspart popover - The `<tp-popover>` panel.
|
|
116
|
+
* @csspart selected-content - The default `<tp-selected-content>`.
|
|
117
|
+
* @csspart placeholder - The `<span>` rendered by the default
|
|
118
|
+
* `<tp-selected-content>` when no option
|
|
119
|
+
* is selected (renders the `placeholder`
|
|
120
|
+
* attribute). Exposed because
|
|
121
|
+
* `<tp-selected-content>` is light-DOM
|
|
122
|
+
* and lives inside this element's shadow
|
|
123
|
+
* root by default.
|
|
124
|
+
* @csspart selected-content-option - Each cloned `<tp-option>` mirrored by
|
|
125
|
+
* the default `<tp-selected-content>`.
|
|
126
|
+
* Exposed for the same reason as
|
|
127
|
+
* `placeholder`. Set on the clones
|
|
128
|
+
* themselves — use
|
|
129
|
+
* `tp-select::part(selected-content-option)`
|
|
130
|
+
* to style them.
|
|
131
|
+
*
|
|
132
|
+
* @fires change - {@link SelectChangeEvent} dispatched when the selected
|
|
133
|
+
* option set changes. Bubbles, not composed (mirrors the
|
|
134
|
+
* native `<select>` `change` event). Not fired on initial
|
|
135
|
+
* mount or when the selection is re-set to the same value.
|
|
136
|
+
*/
|
|
137
|
+
"tp-select": SelectElement;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
declare class SelectElement extends SignalWatcherLitElement {
|
|
141
|
+
#private;
|
|
142
|
+
static formAssociated: boolean;
|
|
143
|
+
private static ALLOWED_OPTION_ELEMENTS;
|
|
144
|
+
static styles: any;
|
|
145
|
+
/**
|
|
146
|
+
* Provides this `<tp-select>` instance to descendants via `@lit/context`,
|
|
147
|
+
* so consumers (e.g. `<tp-selected-content>`) can find it across any
|
|
148
|
+
* number of shadow DOM boundaries — not just light-DOM ancestors.
|
|
149
|
+
*/
|
|
150
|
+
readonly self: SelectElement;
|
|
151
|
+
readonly selectedOptions: Signal.State<T>;
|
|
152
|
+
get value(): string;
|
|
153
|
+
set value(next: string);
|
|
154
|
+
get placeholder(): string;
|
|
155
|
+
set placeholder(next: string);
|
|
156
|
+
/**
|
|
157
|
+
* Maximum number of options that can be selected at once.
|
|
158
|
+
*
|
|
159
|
+
* Defaults to `1` (single-select). Any positive integer enables
|
|
160
|
+
* multi-select up to that many entries. Use the literal string
|
|
161
|
+
* `"infinite"` in HTML to allow an unbounded
|
|
162
|
+
* selection — the converter normalises it to `Number.POSITIVE_INFINITY`.
|
|
163
|
+
*
|
|
164
|
+
* When the limit is reached and a new option is selected, the oldest
|
|
165
|
+
* entry in `selectedOptions` is dropped (FIFO) so the new selection can
|
|
166
|
+
* fit. Setting `max` to a smaller number trims the current selection
|
|
167
|
+
* down to size from the end.
|
|
168
|
+
*/
|
|
169
|
+
max: number;
|
|
170
|
+
/** Form field name. Submitted with the owning `<form>`. */
|
|
171
|
+
name: string | null;
|
|
172
|
+
/** When true, the element is non-interactive and excluded from form submission. */
|
|
173
|
+
disabled: boolean;
|
|
174
|
+
/** When true, an empty selection makes the element invalid (`valueMissing`). */
|
|
175
|
+
required: boolean;
|
|
176
|
+
open: boolean;
|
|
177
|
+
constructor();
|
|
178
|
+
/** Live `ElementInternals` (validity, form, labels, etc.). */
|
|
179
|
+
get internals(): ElementInternals;
|
|
180
|
+
/** Owning `<form>` element, or `null` when not associated. */
|
|
181
|
+
get form(): HTMLFormElement | null;
|
|
182
|
+
/** Native validity state of this control. */
|
|
183
|
+
get validity(): ValidityState;
|
|
184
|
+
get validationMessage(): string;
|
|
185
|
+
get willValidate(): boolean;
|
|
186
|
+
checkValidity(): boolean;
|
|
187
|
+
reportValidity(): boolean;
|
|
188
|
+
protected createRenderRoot(): ShadowRoot;
|
|
189
|
+
connectedCallback(): void;
|
|
190
|
+
disconnectedCallback(): void;
|
|
191
|
+
protected render(): unknown;
|
|
192
|
+
protected updated(changed: Map<string, unknown>): void;
|
|
193
|
+
/**
|
|
194
|
+
* Keep `ElementInternals` in sync with the current value and validity.
|
|
195
|
+
* Reading `this.value` here transitively reads `selectedOptions`, so the
|
|
196
|
+
* `SignalWatcher` base auto-tracks it and re-runs `willUpdate` whenever
|
|
197
|
+
* the selection changes — no `updateEffect` (and no microtask race) needed.
|
|
198
|
+
*/
|
|
199
|
+
protected willUpdate(_changed: Map<string, unknown>): void;
|
|
200
|
+
formResetCallback(): void;
|
|
201
|
+
formDisabledCallback(disabled: boolean): void;
|
|
202
|
+
formStateRestoreCallback(state: File | string | FormData | null): void;
|
|
203
|
+
selectOption(option: OptionElement): void;
|
|
204
|
+
deselectOption(option: OptionElement): void;
|
|
205
|
+
toggleOption(option: OptionElement): void;
|
|
206
|
+
[REGISTER_OPTION](option: OptionElement): void;
|
|
207
|
+
[UNREGISTER_OPTION](option: OptionElement): void;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare global {
|
|
211
|
+
interface HTMLElementTagNameMap {
|
|
212
|
+
/**
|
|
213
|
+
* Mirrors the currently-selected `<tp-option>`(s) of an ancestor
|
|
214
|
+
* `<tp-select>`, falling back to the host's `placeholder` text when
|
|
215
|
+
* the selection is empty.
|
|
216
|
+
*
|
|
217
|
+
* Discovers its host via `@lit/context`, so it can live anywhere in
|
|
218
|
+
* the descendant composed tree — including across nested shadow DOM
|
|
219
|
+
* boundaries. Selected options are deeply cloned and projected into
|
|
220
|
+
* this element's light DOM; clones are inert (they don't register
|
|
221
|
+
* back to the select) and carry `part="selected-content-option"`.
|
|
222
|
+
*
|
|
223
|
+
* Used as the default content of the `<tp-select>` trigger button,
|
|
224
|
+
* but can be placed anywhere a label-style mirror is useful.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```html
|
|
228
|
+
* <tp-select>
|
|
229
|
+
* <button slot="button">
|
|
230
|
+
* <tp-selected-content></tp-selected-content>
|
|
231
|
+
* </button>
|
|
232
|
+
* <tp-option value="apple">Apple</tp-option>
|
|
233
|
+
* </tp-select>
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* Renders into its own light DOM, so it has no slots and exposes no CSS
|
|
237
|
+
* Shadow Parts of its own. The `part` attributes it stamps onto the rendered
|
|
238
|
+
* placeholder span and cloned `<tp-option>`s only become real Shadow Parts
|
|
239
|
+
* when this element happens to sit inside another shadow root — which is
|
|
240
|
+
* what happens by default inside `<tp-select>`, so those parts (`placeholder`,
|
|
241
|
+
* `selected-content-option`) are documented on `<tp-select>`.
|
|
242
|
+
*/
|
|
243
|
+
"tp-selected-content": SelectedContentElement;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
declare class SelectedContentElement extends SignalWatcherLitElement {
|
|
247
|
+
#private;
|
|
248
|
+
static styles: any;
|
|
249
|
+
private select?;
|
|
250
|
+
protected createRenderRoot(): this;
|
|
251
|
+
protected render(): unknown;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
interface SelectChangeEventInit {
|
|
255
|
+
value: string;
|
|
256
|
+
selectedOptions: readonly OptionElement[];
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Dispatched by `<tp-select>` whenever its selected option set changes.
|
|
260
|
+
*
|
|
261
|
+
* Mirrors the native `<select>` `change` event semantics:
|
|
262
|
+
* - type is `'change'`
|
|
263
|
+
* - `bubbles: true`, `composed: false`, `cancelable: false` by default
|
|
264
|
+
* - not fired on initial mount, nor when the selection is set to the
|
|
265
|
+
* same value it already had
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* select.addEventListener('change', e => {
|
|
270
|
+
* if (e instanceof SelectChangeEvent) {
|
|
271
|
+
* console.log(e.value, e.selectedOptions);
|
|
272
|
+
* }
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
declare class SelectChangeEvent extends Event {
|
|
277
|
+
/** Joined value string of the new selection (same as `tp-select.value`). */
|
|
278
|
+
readonly value: string;
|
|
279
|
+
/** Snapshot of the currently selected `<tp-option>` elements. */
|
|
280
|
+
readonly selectedOptions: readonly OptionElement[];
|
|
281
|
+
constructor(init: SelectChangeEventInit, eventInit?: EventInit);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export { OptionElement, SelectChangeEvent, SelectElement, SelectedContentElement };
|
package/select/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { SelectElement } from './select.element.js';
|
|
2
|
+
export { OptionElement } from './option.element.js';
|
|
3
|
+
export { SelectedContentElement } from './selected-content.element.js';
|
|
4
|
+
export { SelectChangeEvent } from './select-change-event.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const REGISTER_OPTION = Symbol("select:register-option");
|
|
4
|
+
const UNREGISTER_OPTION = Symbol("select:unregister-option");
|
|
5
|
+
const SHOULD_REGISTER_TO_SELECT = Symbol("option:should-register-to-select");
|
|
6
|
+
|
|
7
|
+
exports.REGISTER_OPTION = REGISTER_OPTION;
|
|
8
|
+
exports.SHOULD_REGISTER_TO_SELECT = SHOULD_REGISTER_TO_SELECT;
|
|
9
|
+
exports.UNREGISTER_OPTION = UNREGISTER_OPTION;
|
|
10
|
+
//# sourceMappingURL=internal-props.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-props.cjs","sources":["../../../../libs/elements/src/select/internal-props.ts"],"sourcesContent":[null],"names":[],"mappings":";;MAAa,eAAe,GAAG,MAAM,CAAC,wBAAwB;MACjD,iBAAiB,GAAG,MAAM,CAAC,0BAA0B;MACrD,yBAAyB,GAAG,MAAM,CAAC,kCAAkC;;;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const REGISTER_OPTION = Symbol("select:register-option");
|
|
2
|
+
const UNREGISTER_OPTION = Symbol("select:unregister-option");
|
|
3
|
+
const SHOULD_REGISTER_TO_SELECT = Symbol("option:should-register-to-select");
|
|
4
|
+
|
|
5
|
+
export { REGISTER_OPTION, SHOULD_REGISTER_TO_SELECT, UNREGISTER_OPTION };
|
|
6
|
+
//# sourceMappingURL=internal-props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-props.js","sources":["../../../../libs/elements/src/select/internal-props.ts"],"sourcesContent":[null],"names":[],"mappings":"MAAa,eAAe,GAAG,MAAM,CAAC,wBAAwB;MACjD,iBAAiB,GAAG,MAAM,CAAC,0BAA0B;MACrD,yBAAyB,GAAG,MAAM,CAAC,kCAAkC;;;;"}
|