@design.estate/dees-catalog 24.4.0 → 24.6.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/dist_bundle/bundle.js +105 -199
- package/dist_bundle/bundle.js.map +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-7CM7S6EQ.js → chunk-LRGVCS7F.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-R6EBIDCM.js → chunk-PKH6IGY6.js} +347 -4
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-R6EBIDCM.js.map → chunk-PKH6IGY6.js.map} +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-Z3DSEMNI.js → dees-modal-ORXOZADW.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-KPB3RVGL.js → dees-workspace-terminal-MUU2HDU3.js} +3 -3
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.d.ts +22 -1
- package/dist_ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.demo.js +18 -1
- package/dist_ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.js +59 -13
- package/dist_ts_web/elements/00group-input/dees-input-tags/dees-input-tags.d.ts +4 -13
- package/dist_ts_web/elements/00group-input/dees-input-tags/dees-input-tags.js +29 -174
- package/dist_ts_web/elements/00group-input/dees-input-text/dees-input-text.d.ts +41 -0
- package/dist_ts_web/elements/00group-input/dees-input-text/dees-input-text.demo.js +16 -1
- package/dist_ts_web/elements/00group-input/dees-input-text/dees-input-text.js +103 -3
- package/dist_ts_web/elements/00group-input/suggestion-list.d.ts +102 -0
- package/dist_ts_web/elements/00group-input/suggestion-list.js +300 -0
- package/package.json +2 -2
- package/readme.md +30 -2
- package/scripts/token-baseline.json +1 -1
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.demo.ts +17 -0
- package/ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.ts +49 -12
- package/ts_web/elements/00group-input/dees-input-tags/dees-input-tags.ts +27 -171
- package/ts_web/elements/00group-input/dees-input-text/dees-input-text.demo.ts +17 -0
- package/ts_web/elements/00group-input/dees-input-text/dees-input-text.ts +106 -1
- package/ts_web/elements/00group-input/suggestion-list.ts +323 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-7CM7S6EQ.js.map → chunk-LRGVCS7F.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-Z3DSEMNI.js.map → dees-modal-ORXOZADW.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-KPB3RVGL.js.map → dees-workspace-terminal-MUU2HDU3.js.map} +0 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { css, html, type CSSResult, type DeesElement, type TemplateResult } from '@design.estate/dees-element';
|
|
2
|
+
import { listenForScrollAround, placeAnchored, visibleRect } from '../00anchorplacement.js';
|
|
3
|
+
import type { TReactiveController } from '../00controller.js';
|
|
4
|
+
import { OverlayScrollbarController } from '../00scrollbars.js';
|
|
5
|
+
|
|
6
|
+
/** A suggestion with a label of its own, or a second line under it. `value` is what a pick sets. */
|
|
7
|
+
export interface IInputSuggestion {
|
|
8
|
+
value: string;
|
|
9
|
+
/** Shown instead of `value`. */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** A second, quieter line under the label. */
|
|
12
|
+
description?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A suggestion a host offers a field: the value itself, or the value with a label and a description. */
|
|
16
|
+
export type TInputSuggestion = string | IInputSuggestion;
|
|
17
|
+
|
|
18
|
+
/** A suggestion in its object form. */
|
|
19
|
+
export const inputSuggestion = (suggestionArg: TInputSuggestion): IInputSuggestion =>
|
|
20
|
+
typeof suggestionArg === 'string' ? { value: suggestionArg } : suggestionArg;
|
|
21
|
+
|
|
22
|
+
export interface ISuggestionListOptions {
|
|
23
|
+
/** The field the list stands under, as wide as it is. */
|
|
24
|
+
anchor: () => HTMLElement | null | undefined;
|
|
25
|
+
/** What a pick by pointer or Enter does, given the index of the picked suggestion. */
|
|
26
|
+
pick: (indexArg: number) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The suggestions an editable field offers in a list under it, as a WAI-ARIA combobox: the field
|
|
31
|
+
* keeps the focus, the arrow keys move the highlighted option, Enter or a press picks it, Escape
|
|
32
|
+
* closes the list. The host owns the suggestions and what a pick does; the controller owns whether
|
|
33
|
+
* the list is open, the highlighted option, the list's markup and its place.
|
|
34
|
+
*
|
|
35
|
+
* The open list stands in the top layer (`popover="manual"`), below the field or above it without
|
|
36
|
+
* room there, so no scroll container, clipping ancestor or dialog around the field cuts it off. It
|
|
37
|
+
* follows the field as it scrolls or grows and steps out of view while none of the field shows.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* public static styles = [themeDefaultStyles, overlayScrollbarStyles, suggestionListStyles, css`…`];
|
|
41
|
+
* private readonly suggestionList = new SuggestionListController(this, {
|
|
42
|
+
* anchor: () => this.shadowRoot?.querySelector('input'),
|
|
43
|
+
* pick: (index) => this.choose(this.suggestions[index]),
|
|
44
|
+
* });
|
|
45
|
+
* public render() {
|
|
46
|
+
* return html`<input @keydown=${(e) => this.suggestionList.handleKeydown(e, this.suggestions.length)}>
|
|
47
|
+
* ${this.suggestionList.render(this.suggestions.map(inputSuggestion), this.label)}`;
|
|
48
|
+
* }
|
|
49
|
+
* public updated() {
|
|
50
|
+
* this.suggestionList.applyComboboxAttributes(this.shadowRoot!.querySelector('input')!, this.suggestions.length);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export class SuggestionListController implements TReactiveController {
|
|
55
|
+
/** The id of the list in the host's shadow root, for the field's `aria-controls`. */
|
|
56
|
+
public static readonly listboxId = 'suggestion-listbox';
|
|
57
|
+
|
|
58
|
+
/** Whether the list shows while there are suggestions. */
|
|
59
|
+
public expanded = false;
|
|
60
|
+
|
|
61
|
+
/** The highlighted option, -1 for none. */
|
|
62
|
+
public highlightedIndex = -1;
|
|
63
|
+
|
|
64
|
+
/** The name the last render gave the list; empty for none. */
|
|
65
|
+
private listLabel = '';
|
|
66
|
+
|
|
67
|
+
/** Ends the listeners that keep the open list beside the field. */
|
|
68
|
+
private tracking?: AbortController;
|
|
69
|
+
|
|
70
|
+
/** The list's scrollbar, shown while it scrolls. */
|
|
71
|
+
private readonly scrollbars: OverlayScrollbarController;
|
|
72
|
+
|
|
73
|
+
constructor(
|
|
74
|
+
private readonly host: DeesElement,
|
|
75
|
+
private readonly options: ISuggestionListOptions,
|
|
76
|
+
) {
|
|
77
|
+
host.addController(this);
|
|
78
|
+
this.scrollbars = new OverlayScrollbarController(host, () => this.popup()?.querySelector<HTMLElement>('.suggestions-list'));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The id of the option at `indexArg`, for the field's `aria-activedescendant`. */
|
|
82
|
+
public static optionId(indexArg: number): string {
|
|
83
|
+
return `suggestion-option-${indexArg}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Whether the list shows `countArg` suggestions now. */
|
|
87
|
+
public isOpen(countArg: number): boolean {
|
|
88
|
+
return this.expanded && countArg > 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Opens the list; it shows while there are suggestions. */
|
|
92
|
+
public show(): void {
|
|
93
|
+
if (this.expanded) return;
|
|
94
|
+
this.expanded = true;
|
|
95
|
+
this.host.requestUpdate();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Closes the list and lets go of the highlighted option. */
|
|
99
|
+
public hide(): void {
|
|
100
|
+
if (!this.expanded && this.highlightedIndex === -1) return;
|
|
101
|
+
this.expanded = false;
|
|
102
|
+
this.highlightedIndex = -1;
|
|
103
|
+
this.host.requestUpdate();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Highlights the option at `indexArg`, -1 for none. */
|
|
107
|
+
public highlight(indexArg: number): void {
|
|
108
|
+
if (indexArg === this.highlightedIndex) return;
|
|
109
|
+
this.highlightedIndex = indexArg;
|
|
110
|
+
this.host.requestUpdate();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Answers the list's keys in the field while the list shows: ArrowDown and ArrowUp move the
|
|
115
|
+
* highlighted option, Enter picks the highlighted one, Escape closes the list. Returns whether it
|
|
116
|
+
* answered the key; a key it answers in a showing list is prevented, so a form does not take Enter
|
|
117
|
+
* and a dialog does not take Escape. A list with no suggestions shows nothing and answers none of
|
|
118
|
+
* them: the arrows move the caret and Enter is the host's or the form's. Tab is the host's: it
|
|
119
|
+
* leaves the field without a pick.
|
|
120
|
+
*/
|
|
121
|
+
public handleKeydown(eventArg: KeyboardEvent, countArg: number): boolean {
|
|
122
|
+
if (eventArg.isComposing) return false;
|
|
123
|
+
const open = this.isOpen(countArg);
|
|
124
|
+
switch (eventArg.key) {
|
|
125
|
+
case 'ArrowDown':
|
|
126
|
+
if (!open) return false;
|
|
127
|
+
eventArg.preventDefault();
|
|
128
|
+
this.highlight(Math.min(this.highlightedIndex + 1, countArg - 1));
|
|
129
|
+
return true;
|
|
130
|
+
case 'ArrowUp':
|
|
131
|
+
if (!open) return false;
|
|
132
|
+
eventArg.preventDefault();
|
|
133
|
+
this.highlight(Math.min(Math.max(this.highlightedIndex - 1, 0), countArg - 1));
|
|
134
|
+
return true;
|
|
135
|
+
case 'Enter':
|
|
136
|
+
if (!open || this.highlightedIndex < 0 || this.highlightedIndex >= countArg) return false;
|
|
137
|
+
eventArg.preventDefault();
|
|
138
|
+
this.options.pick(this.highlightedIndex);
|
|
139
|
+
return true;
|
|
140
|
+
case 'Escape': {
|
|
141
|
+
if (!this.expanded) return false;
|
|
142
|
+
if (open) eventArg.preventDefault();
|
|
143
|
+
this.hide();
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
default:
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Writes the combobox state onto the field: `role="combobox"`, `aria-autocomplete="list"`,
|
|
153
|
+
* `aria-expanded`, and while the list shows `aria-controls` and the highlighted option's
|
|
154
|
+
* `aria-activedescendant`. With `activeArg` false it removes all of them, for a field that offers
|
|
155
|
+
* no suggestions and is a plain text field.
|
|
156
|
+
*/
|
|
157
|
+
public applyComboboxAttributes(fieldArg: HTMLElement, countArg: number, activeArg = true): void {
|
|
158
|
+
const open = this.isOpen(countArg);
|
|
159
|
+
const highlighted = open && this.highlightedIndex >= 0 && this.highlightedIndex < countArg;
|
|
160
|
+
const attributes: Record<string, string | null> = {
|
|
161
|
+
role: activeArg ? 'combobox' : null,
|
|
162
|
+
'aria-autocomplete': activeArg ? 'list' : null,
|
|
163
|
+
'aria-expanded': activeArg ? String(open) : null,
|
|
164
|
+
'aria-controls': activeArg && open ? SuggestionListController.listboxId : null,
|
|
165
|
+
'aria-activedescendant': activeArg && highlighted ? SuggestionListController.optionId(this.highlightedIndex) : null,
|
|
166
|
+
};
|
|
167
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
168
|
+
if (value === null) fieldArg.removeAttribute(name);
|
|
169
|
+
else if (fieldArg.getAttribute(name) !== value) fieldArg.setAttribute(name, value);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The open list, or nothing while it is closed or has no suggestions. `labelArg` names it; an
|
|
175
|
+
* empty one leaves it without an `aria-label`.
|
|
176
|
+
*/
|
|
177
|
+
public render(itemsArg: IInputSuggestion[], labelArg = ''): TemplateResult | string {
|
|
178
|
+
this.listLabel = labelArg;
|
|
179
|
+
if (!this.isOpen(itemsArg.length)) return '';
|
|
180
|
+
return html`
|
|
181
|
+
<div class="suggestions-dropdown" popover="manual"><div
|
|
182
|
+
class="suggestions-list"
|
|
183
|
+
id=${SuggestionListController.listboxId}
|
|
184
|
+
role="listbox"
|
|
185
|
+
>
|
|
186
|
+
${itemsArg.map((item, index) => html`
|
|
187
|
+
<div
|
|
188
|
+
class="suggestion ${index === this.highlightedIndex ? 'highlighted' : ''}"
|
|
189
|
+
id=${SuggestionListController.optionId(index)}
|
|
190
|
+
role="option"
|
|
191
|
+
aria-selected=${index === this.highlightedIndex ? 'true' : 'false'}
|
|
192
|
+
@mousedown=${(event: Event) => {
|
|
193
|
+
event.preventDefault(); // the field keeps the focus
|
|
194
|
+
this.options.pick(index);
|
|
195
|
+
}}
|
|
196
|
+
@mouseenter=${() => this.highlight(index)}
|
|
197
|
+
>
|
|
198
|
+
${item.label ?? item.value}
|
|
199
|
+
${item.description ? html`<div class="suggestion-description">${item.description}</div>` : ''}
|
|
200
|
+
</div>
|
|
201
|
+
`)}
|
|
202
|
+
</div></div>
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The open list follows the field from the render that shows it until the render that removes it. */
|
|
207
|
+
public hostUpdated(): void {
|
|
208
|
+
const popup = this.popup();
|
|
209
|
+
if (!popup) {
|
|
210
|
+
this.stopTracking();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// Applied here, not bound, so a list without a name carries no empty `aria-label`.
|
|
214
|
+
const listbox = popup.querySelector<HTMLElement>('[role="listbox"]')!;
|
|
215
|
+
if (this.listLabel) listbox.setAttribute('aria-label', this.listLabel);
|
|
216
|
+
else listbox.removeAttribute('aria-label');
|
|
217
|
+
const field = this.options.anchor();
|
|
218
|
+
if (!field) return;
|
|
219
|
+
if (!this.tracking) {
|
|
220
|
+
const tracking = new AbortController();
|
|
221
|
+
this.tracking = tracking;
|
|
222
|
+
listenForScrollAround(field, this.place, tracking.signal);
|
|
223
|
+
window.addEventListener('resize', this.place, { passive: true, signal: tracking.signal });
|
|
224
|
+
// A field can grow as the reader works in it (tags wrap onto another line).
|
|
225
|
+
const observer = new ResizeObserver(this.place);
|
|
226
|
+
observer.observe(field);
|
|
227
|
+
tracking.signal.addEventListener('abort', () => observer.disconnect());
|
|
228
|
+
}
|
|
229
|
+
this.place();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public hostDisconnected(): void {
|
|
233
|
+
this.stopTracking();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private popup(): HTMLElement | null | undefined {
|
|
237
|
+
return this.host.shadowRoot?.querySelector<HTMLElement>('.suggestions-dropdown');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private stopTracking(): void {
|
|
241
|
+
this.tracking?.abort();
|
|
242
|
+
this.tracking = undefined;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Places the open list below the field, or above it without room there, as wide as the field. */
|
|
246
|
+
private place = (): void => {
|
|
247
|
+
const popup = this.popup();
|
|
248
|
+
const field = this.options.anchor();
|
|
249
|
+
if (!popup || !field) return;
|
|
250
|
+
const shown = visibleRect(field);
|
|
251
|
+
if (!shown) {
|
|
252
|
+
if (popup.matches(':popover-open')) popup.hidePopover();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (!popup.matches(':popover-open')) popup.showPopover();
|
|
256
|
+
const box = field.getBoundingClientRect();
|
|
257
|
+
popup.style.width = `${box.width}px`;
|
|
258
|
+
const placed = placeAnchored({
|
|
259
|
+
anchor: { left: box.left, right: box.right, top: shown.top, bottom: shown.bottom },
|
|
260
|
+
width: box.width,
|
|
261
|
+
height: popup.offsetHeight,
|
|
262
|
+
placement: 'bottom',
|
|
263
|
+
flip: true,
|
|
264
|
+
gap: 4,
|
|
265
|
+
});
|
|
266
|
+
popup.style.left = `${placed.left}px`;
|
|
267
|
+
popup.style.top = `${placed.top}px`;
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** The open list's look; a host adds `overlayScrollbarStyles` beside it. */
|
|
272
|
+
export const suggestionListStyles: CSSResult = css`
|
|
273
|
+
/* A popover in the top layer, placed by the controller. The list scrolls inside it, the frame
|
|
274
|
+
its scrollbar is placed in. */
|
|
275
|
+
.suggestions-dropdown {
|
|
276
|
+
position: fixed;
|
|
277
|
+
inset: auto;
|
|
278
|
+
margin: 0;
|
|
279
|
+
padding: 0;
|
|
280
|
+
color: inherit;
|
|
281
|
+
background: var(--dees-material-regular-bg-opaque);
|
|
282
|
+
border: var(--dees-line-width-hairline) solid var(--dees-color-border-default);
|
|
283
|
+
border-radius: var(--dees-radius-lg);
|
|
284
|
+
corner-shape: var(--dees-corner-shape);
|
|
285
|
+
box-shadow: var(--dees-shadow-lg);
|
|
286
|
+
overflow: hidden;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.suggestions-list {
|
|
290
|
+
max-height: calc(200px - 2 * var(--dees-line-width-hairline));
|
|
291
|
+
overflow-y: auto;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
@media (prefers-reduced-transparency: reduce) {
|
|
295
|
+
.suggestions-dropdown {
|
|
296
|
+
-webkit-backdrop-filter: none;
|
|
297
|
+
backdrop-filter: none;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.suggestion {
|
|
302
|
+
padding: var(--dees-spacing-xs-plus) var(--dees-spacing-sm-plus);
|
|
303
|
+
cursor: pointer;
|
|
304
|
+
transition: background-color var(--dees-transition-fast) var(--dees-ease-standard);
|
|
305
|
+
font-size: 14px;
|
|
306
|
+
color: var(--dees-color-text-primary);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.suggestion:hover {
|
|
310
|
+
background: var(--dees-color-hover);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.suggestion.highlighted {
|
|
314
|
+
background: var(--dees-color-active);
|
|
315
|
+
color: var(--dees-color-text-primary);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.suggestion-description {
|
|
319
|
+
color: var(--dees-color-text-secondary);
|
|
320
|
+
font-size: var(--dees-font-footnote-size);
|
|
321
|
+
line-height: var(--dees-font-footnote-line);
|
|
322
|
+
}
|
|
323
|
+
`;
|
/package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-7CM7S6EQ.js.map → chunk-LRGVCS7F.js.map}
RENAMED
|
File without changes
|
|
File without changes
|