@syware/jlib 0.17.1 → 0.18.1
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/all.js +5 -3
- package/dist/base/jl-combobox-base.css.js +3 -0
- package/dist/base/jl-combobox-base.d.ts +202 -0
- package/dist/base/jl-combobox-base.js +632 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -2
- package/dist/lib/combobox.d.ts +12 -0
- package/dist/lib/combobox.js +22 -0
- package/dist/lib/option-filter.d.ts +6 -4
- package/dist/lib/option-filter.js +63 -33
- package/dist/lib/table.d.ts +24 -3
- package/dist/lib/table.js +58 -2
- package/dist/lib/texts-de.d.ts +3 -0
- package/dist/lib/texts-de.js +3 -0
- package/dist/lib/texts-fr.d.ts +3 -0
- package/dist/lib/texts-fr.js +3 -0
- package/dist/lib/texts.d.ts +3 -0
- package/dist/lib/texts.js +3 -0
- package/dist/molecules/jl-combobox.d.ts +15 -123
- package/dist/molecules/jl-combobox.js +24 -461
- package/dist/molecules/jl-multi-combobox.css.js +3 -0
- package/dist/molecules/jl-multi-combobox.d.ts +50 -0
- package/dist/molecules/jl-multi-combobox.js +176 -0
- package/dist/organisms/jl-table.css.js +1 -1
- package/dist/organisms/jl-table.d.ts +77 -5
- package/dist/organisms/jl-table.js +223 -23
- package/dist/types/jl-combobox.types.d.ts +5 -0
- package/dist/types/jl-table.types.d.ts +22 -0
- package/package.json +2 -1
- package/dist/molecules/jl-combobox.css.js +0 -3
|
@@ -1,487 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BASE_STYLES, CONTROL_STYLES, FLOATING_STYLES } from "../styles/shared.js";
|
|
3
|
-
import { JlFormControl } from "../base/jl-form-control.js";
|
|
4
|
-
import { jsonOf, oneOf } from "../lib/attributes.js";
|
|
5
|
-
import { followAnchor } from "../lib/floating.js";
|
|
6
|
-
import { registerIcons } from "../lib/icons.js";
|
|
7
|
-
import { CONTROL_SIZES } from "../lib/options.js";
|
|
8
|
-
import { JlIcon } from "../atoms/jl-icon.js";
|
|
9
|
-
import { setAriaFlag, setOrRemove, uniqueId } from "../lib/dom.js";
|
|
10
|
-
import { keepInView } from "../lib/keep-in-view.js";
|
|
11
|
-
import { edgeEnabledIndex, filterOptions, foldText, matchParts, nextEnabledIndex } from "../lib/option-filter.js";
|
|
12
|
-
import jl_combobox_default from "./jl-combobox.css.js";
|
|
13
|
-
import { css } from "@jadis/core";
|
|
14
|
-
import { Check, ChevronDown, X } from "lucide";
|
|
15
|
-
import { Fragment, jsx, jsxs } from "@jadis/core/jsx-runtime";
|
|
1
|
+
import { COMBOBOX_FILTERS, JlComboboxBase } from "../base/jl-combobox-base.js";
|
|
16
2
|
// src/molecules/jl-combobox.tsx
|
|
17
|
-
registerIcons({
|
|
18
|
-
check: Check,
|
|
19
|
-
"chevron-down": ChevronDown,
|
|
20
|
-
x: X
|
|
21
|
-
});
|
|
22
|
-
var ICON_SIZE = 16;
|
|
23
|
-
var ACTION_ICON_SIZE = 14;
|
|
24
|
-
var CHECK_SIZE = 14;
|
|
25
|
-
var NONE = -1;
|
|
26
|
-
var PLACEMENT = "bottom-start";
|
|
27
|
-
/** A JSON attribute that should hold a list of options; anything else gives none. */
|
|
28
|
-
var parseOptions = (value) => {
|
|
29
|
-
const parsed = jsonOf([])(value);
|
|
30
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
31
|
-
};
|
|
32
|
-
/** A label with the searched text in a `<mark>`. */
|
|
33
|
-
var highlighted = (label, query) => matchParts(label, query).map((part) => part.matched ? /* @__PURE__ */ jsx("mark", { children: part.text }) : part.text);
|
|
34
3
|
/**
|
|
35
4
|
* A text field with a list of options that narrows as people type; they choose with the arrows and Enter, or with
|
|
36
5
|
* the pointer. The field shows the option's label, `value` and the form hold its value. With `allow-custom`, the
|
|
37
|
-
* text people type becomes the value when no option matches it.
|
|
6
|
+
* text people type becomes the value when no option matches it. With `filter="none"` the page finds the options
|
|
7
|
+
* (on `input`, which `debounce` holds back while people type) and shows `loading` meanwhile. For several values,
|
|
8
|
+
* `jl-multi-combobox`.
|
|
38
9
|
*/
|
|
39
|
-
var JlCombobox = class extends
|
|
10
|
+
var JlCombobox = class extends JlComboboxBase {
|
|
40
11
|
static selector = "jl-combobox";
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
attribute: "options",
|
|
44
|
-
parse: parseOptions
|
|
45
|
-
});
|
|
46
|
-
/** The chosen option's value (with `allow-custom`, any text). */
|
|
47
|
-
value = this.useChange("", () => this.renderValue(), { attribute: "value" });
|
|
48
|
-
placeholder = this.useChange("", (value) => setOrRemove(this._refs.native, "placeholder", value), { attribute: "placeholder" });
|
|
49
|
-
/** The field's name for screen readers, when no visible label names it. */
|
|
50
|
-
label = this.useChange("", (value) => {
|
|
51
|
-
setOrRemove(this._refs.native, "aria-label", value);
|
|
52
|
-
setOrRemove(this._refs.listbox, "aria-label", value);
|
|
53
|
-
}, { attribute: "label" });
|
|
54
|
-
/** Takes the typed text as the value when no option has it as its label. */
|
|
55
|
-
allowCustom = this.useChange(false, () => this.renderValue(), { attribute: "allow-custom" });
|
|
56
|
-
/** Shows a button that empties the field while it holds text. */
|
|
57
|
-
clearable = this.useChange(false, () => this.renderClear(), { attribute: "clearable" });
|
|
58
|
-
/** What the list says when no option matches; jlib's own when empty. */
|
|
59
|
-
emptyText = this.useChange("", () => this.renderEmptyText(), { attribute: "empty-text" });
|
|
60
|
-
required = this.useChange(false, (value) => {
|
|
61
|
-
setAriaFlag(this._refs.native, "aria-required", value);
|
|
62
|
-
this.reflect("required", value);
|
|
63
|
-
this.renderValidity();
|
|
64
|
-
}, { attribute: "required" });
|
|
65
|
-
disabled = this.useChange(false, (value) => this.renderDisabled(value), { attribute: "disabled" });
|
|
66
|
-
/** Draws the field in the danger colour, for an error the page found itself. */
|
|
67
|
-
invalid = this.useChange(false, (value) => {
|
|
68
|
-
this.reflect("invalid", value);
|
|
69
|
-
setAriaFlag(this._refs.native, "aria-invalid", value);
|
|
70
|
-
}, { attribute: "invalid" });
|
|
71
|
-
size = this.useChange("md", (value) => this.reflect("size", value), {
|
|
72
|
-
attribute: "size",
|
|
73
|
-
parse: oneOf(CONTROL_SIZES, "md")
|
|
74
|
-
});
|
|
75
|
-
_listId = uniqueId("jl-combobox-list");
|
|
76
|
-
_state = {
|
|
77
|
-
active: NONE,
|
|
78
|
-
/** The option element the arrows reached: it alone is marked, wherever the filter put it. */
|
|
79
|
-
activeItem: null,
|
|
80
|
-
disabledByForm: false,
|
|
81
|
-
matches: [],
|
|
82
|
-
opening: new AbortController(),
|
|
83
|
-
/** What people typed since the last choice; empty shows every option. */
|
|
84
|
-
query: ""
|
|
85
|
-
};
|
|
86
|
-
_items = /* @__PURE__ */ new WeakMap();
|
|
87
|
-
_refs = this.useRefs((ref) => ({
|
|
88
|
-
clear: ref(".clear"),
|
|
89
|
-
control: ref(".control"),
|
|
90
|
-
empty: ref(".empty"),
|
|
91
|
-
listbox: ref(".listbox"),
|
|
92
|
-
native: ref("input"),
|
|
93
|
-
popup: ref(".popup"),
|
|
94
|
-
toggle: ref(".toggle")
|
|
95
|
-
}));
|
|
96
|
-
focus(options) {
|
|
97
|
-
this._refs.native.focus(options);
|
|
98
|
-
}
|
|
99
|
-
templateHtml() {
|
|
100
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
101
|
-
class: "control",
|
|
102
|
-
attrs: { part: "base" },
|
|
103
|
-
children: [
|
|
104
|
-
/* @__PURE__ */ jsx("input", {
|
|
105
|
-
class: "native",
|
|
106
|
-
id: "field",
|
|
107
|
-
role: "combobox",
|
|
108
|
-
"aria-autocomplete": "list",
|
|
109
|
-
"aria-expanded": "false",
|
|
110
|
-
"aria-controls": this._listId,
|
|
111
|
-
autocomplete: "off",
|
|
112
|
-
spellcheck: false
|
|
113
|
-
}),
|
|
114
|
-
/* @__PURE__ */ jsx("button", {
|
|
115
|
-
class: "action clear",
|
|
116
|
-
type: "button",
|
|
117
|
-
tabIndex: -1,
|
|
118
|
-
hidden: true,
|
|
119
|
-
children: /* @__PURE__ */ jsx(JlIcon, {
|
|
120
|
-
name: "x",
|
|
121
|
-
size: ACTION_ICON_SIZE
|
|
122
|
-
})
|
|
123
|
-
}),
|
|
124
|
-
/* @__PURE__ */ jsx("button", {
|
|
125
|
-
class: "action toggle",
|
|
126
|
-
type: "button",
|
|
127
|
-
tabIndex: -1,
|
|
128
|
-
children: /* @__PURE__ */ jsx(JlIcon, {
|
|
129
|
-
name: "chevron-down",
|
|
130
|
-
size: ICON_SIZE
|
|
131
|
-
})
|
|
132
|
-
})
|
|
133
|
-
]
|
|
134
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
135
|
-
class: "floating panel popup",
|
|
136
|
-
popover: "manual",
|
|
137
|
-
attrs: { part: "list" },
|
|
138
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
139
|
-
class: "listbox",
|
|
140
|
-
role: "listbox",
|
|
141
|
-
id: this._listId
|
|
142
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
143
|
-
class: "empty",
|
|
144
|
-
hidden: true
|
|
145
|
-
})]
|
|
146
|
-
})] });
|
|
147
|
-
}
|
|
148
|
-
templateCss() {
|
|
149
|
-
return css`${BASE_STYLES}${CONTROL_STYLES}${FLOATING_STYLES}${jl_combobox_default}`;
|
|
150
|
-
}
|
|
151
|
-
onConnect() {
|
|
152
|
-
const native = this._refs.native;
|
|
153
|
-
this.on(native, "input", (event) => {
|
|
154
|
-
event.stopPropagation();
|
|
155
|
-
this.onType();
|
|
156
|
-
});
|
|
157
|
-
this.on(native, "keydown", (event) => this.onKey(event));
|
|
158
|
-
this.on(native, "blur", () => this.commitText());
|
|
159
|
-
this.on(native, "click", () => this.openList(false));
|
|
160
|
-
this.on(this._refs.toggle, "click", () => this.toggleList());
|
|
161
|
-
this.on(this._refs.clear, "click", () => this.clearValue());
|
|
162
|
-
for (const element of [
|
|
163
|
-
this._refs.popup,
|
|
164
|
-
this._refs.toggle,
|
|
165
|
-
this._refs.clear
|
|
166
|
-
]) this.on(element, "mousedown", (event) => event.preventDefault());
|
|
167
|
-
this.on(this._refs.listbox, "click", (event) => this.choose(this.optionAt(event)));
|
|
168
|
-
this.on(this._refs.listbox, "pointermove", (event) => this.hover(event));
|
|
169
|
-
}
|
|
170
|
-
onDisconnect() {
|
|
171
|
-
this._state.opening.abort();
|
|
172
|
-
}
|
|
173
|
-
resetValue() {
|
|
174
|
-
this._state.query = "";
|
|
175
|
-
this.value.set(this.getAttribute("value") ?? "");
|
|
176
|
-
}
|
|
177
|
-
setDisabledByForm(disabled) {
|
|
178
|
-
this._state.disabledByForm = disabled;
|
|
179
|
-
this.whenRendered(() => this.drawDisabled());
|
|
180
|
-
}
|
|
181
|
-
/** Disabled by its own input, or by a `<fieldset disabled>` around it. */
|
|
182
|
-
isOff() {
|
|
183
|
-
return this.disabled.get() || this._state.disabledByForm;
|
|
12
|
+
shaped(values) {
|
|
13
|
+
return values[0] ?? "";
|
|
184
14
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this._refs.toggle.setAttribute("aria-label", jlText("showOptions"));
|
|
188
|
-
this.renderEmptyText();
|
|
189
|
-
this.renderValidity();
|
|
15
|
+
parseValue(text) {
|
|
16
|
+
return text ?? "";
|
|
190
17
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
isOpen() {
|
|
195
|
-
return this._refs.popup.matches(":popover-open");
|
|
196
|
-
}
|
|
197
|
-
onType() {
|
|
198
|
-
const text = this._refs.native.value;
|
|
199
|
-
this._state.query = text;
|
|
200
|
-
this.events.emit("input", text);
|
|
201
|
-
this.renderClear();
|
|
202
|
-
this.openList(true);
|
|
203
|
-
}
|
|
204
|
-
onKey(event) {
|
|
205
|
-
const handler = (/* @__PURE__ */ new Map([
|
|
206
|
-
["ArrowDown", () => this.onArrow(1, event.altKey)],
|
|
207
|
-
["ArrowUp", () => this.onArrow(-1, event.altKey)],
|
|
208
|
-
["Enter", () => this.onEnter()],
|
|
209
|
-
["Escape", () => this.onEscape()],
|
|
210
|
-
["Tab", () => this.onTab()]
|
|
211
|
-
])).get(event.key);
|
|
212
|
-
if (handler === void 0) return;
|
|
213
|
-
if (handler()) {
|
|
214
|
-
event.preventDefault();
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
if (event.key === "Enter") this.submitImplicitly(event);
|
|
218
|
-
}
|
|
219
|
-
/** Down opens the list or moves down it; Alt + Down opens it as it is, Alt + Up closes it. */
|
|
220
|
-
onArrow(direction, alt) {
|
|
221
|
-
if (alt) {
|
|
222
|
-
this.toggleWithAlt(direction);
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
if (!this.isOpen()) {
|
|
226
|
-
this.openList(false);
|
|
227
|
-
this.activateEdgeIfNone(direction);
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
this.moveActive(direction);
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
toggleWithAlt(direction) {
|
|
234
|
-
if (direction > 0) {
|
|
235
|
-
this.openList(false);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
18
|
+
/** A choice closes the list, and the field shows the option's label. */
|
|
19
|
+
chooseOption(option) {
|
|
20
|
+
this.clearTyped();
|
|
238
21
|
this.closeList();
|
|
22
|
+
this.commitValues([option.value]);
|
|
239
23
|
}
|
|
240
|
-
/**
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (this.isOpen() && active !== void 0) {
|
|
244
|
-
this.choose(active);
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
if (this._state.query !== "") {
|
|
248
|
-
this.commitText();
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
if (this.isOpen()) {
|
|
252
|
-
this.closeList();
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
/** Escape closes the list, then a second one brings back the chosen option's label over unfinished typing. */
|
|
258
|
-
onEscape() {
|
|
259
|
-
if (this.isOpen()) {
|
|
260
|
-
this.closeList();
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
if (this._state.query === "") return false;
|
|
264
|
-
this._state.query = "";
|
|
265
|
-
this.renderValue();
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
/** Tab takes the option the arrows reached, and lets the focus move on. */
|
|
269
|
-
onTab() {
|
|
270
|
-
const active = this._state.matches[this._state.active];
|
|
271
|
-
if (this.isOpen() && active !== void 0) this.choose(active);
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
toggleList() {
|
|
275
|
-
if (this.isOpen()) {
|
|
276
|
-
this.closeList();
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
this.openList(false);
|
|
280
|
-
this.focus();
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Opens the list, or refreshes it, for what was typed. While typing, the first match is active, so Enter takes
|
|
284
|
-
* it; otherwise the chosen option is. With free text allowed and nothing matching, the list stays closed.
|
|
285
|
-
*/
|
|
286
|
-
openList(typing) {
|
|
287
|
-
if (this.isOff() || this.options.get().length === 0 && this._state.query === "") return;
|
|
288
|
-
this.renderOptions();
|
|
289
|
-
const matches = this._state.matches;
|
|
290
|
-
const autoActive = typing && this._state.query.trim() !== "" && !this.allowCustom.get();
|
|
291
|
-
this._state.active = autoActive ? edgeEnabledIndex(matches, 1) : this.chosenIndex();
|
|
292
|
-
this.renderActive();
|
|
293
|
-
if (matches.length === 0 && this.allowCustom.get()) {
|
|
294
|
-
this.closeList();
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
if (!this.isOpen()) this.showPopup();
|
|
298
|
-
this.revealActive();
|
|
299
|
-
}
|
|
300
|
-
showPopup() {
|
|
301
|
-
const popup = this._refs.popup;
|
|
302
|
-
popup.style.width = `${this._refs.control.offsetWidth}px`;
|
|
303
|
-
popup.showPopover();
|
|
304
|
-
this._state.opening.abort();
|
|
305
|
-
this._state.opening = new AbortController();
|
|
306
|
-
followAnchor(this._refs.control, popup, PLACEMENT, this._state.opening.signal);
|
|
307
|
-
this._refs.native.setAttribute("aria-expanded", "true");
|
|
308
|
-
this.reflect("open", true);
|
|
309
|
-
}
|
|
310
|
-
closeList() {
|
|
311
|
-
this._state.active = NONE;
|
|
312
|
-
this.renderActive();
|
|
313
|
-
if (!this.isOpen()) return;
|
|
314
|
-
this._refs.popup.hidePopover();
|
|
315
|
-
this._state.opening.abort();
|
|
316
|
-
this._refs.native.setAttribute("aria-expanded", "false");
|
|
317
|
-
this.reflect("open", false);
|
|
318
|
-
}
|
|
319
|
-
chosenIndex() {
|
|
320
|
-
const value = this.value.get();
|
|
321
|
-
return this._state.matches.findIndex((option) => option.value === value && option.disabled !== true);
|
|
322
|
-
}
|
|
323
|
-
activateEdgeIfNone(direction) {
|
|
324
|
-
if (this._state.active !== NONE) return;
|
|
325
|
-
this._state.active = edgeEnabledIndex(this._state.matches, direction);
|
|
326
|
-
this.renderActive();
|
|
327
|
-
this.revealActive();
|
|
328
|
-
}
|
|
329
|
-
moveActive(direction) {
|
|
330
|
-
this._state.active = nextEnabledIndex(this._state.matches, this._state.active, direction);
|
|
331
|
-
this.renderActive();
|
|
332
|
-
this.revealActive();
|
|
333
|
-
}
|
|
334
|
-
optionAt(event) {
|
|
335
|
-
const item = event.target.closest("[data-index]");
|
|
336
|
-
return item === null ? void 0 : this._state.matches[Number(item.dataset.index)];
|
|
337
|
-
}
|
|
338
|
-
hover(event) {
|
|
339
|
-
const option = this.optionAt(event);
|
|
340
|
-
const index = option === void 0 ? NONE : this._state.matches.indexOf(option);
|
|
341
|
-
if (index === this._state.active || option?.disabled === true) return;
|
|
342
|
-
this._state.active = index;
|
|
343
|
-
this.renderActive();
|
|
344
|
-
}
|
|
345
|
-
choose(option) {
|
|
346
|
-
if (option === void 0 || option.disabled === true) return;
|
|
347
|
-
this._state.query = "";
|
|
348
|
-
this.closeList();
|
|
349
|
-
this.commit(option.value);
|
|
350
|
-
}
|
|
351
|
-
/** Leaving the field, or Enter on typed text: an option with that label, free text, nothing, or back as it was. */
|
|
352
|
-
commitText() {
|
|
353
|
-
this.closeList();
|
|
354
|
-
const text = this._refs.native.value.trim();
|
|
355
|
-
this._state.query = "";
|
|
356
|
-
if (text === this.displayOf(this.value.get()).trim()) {
|
|
24
|
+
/** Typed text: an option with that label, free text, nothing, or back as it was. */
|
|
25
|
+
commitTyped(text) {
|
|
26
|
+
if (text === this.fieldText().trim()) {
|
|
357
27
|
this.renderValue();
|
|
358
28
|
return;
|
|
359
29
|
}
|
|
360
30
|
const exact = this.optionWithLabel(text);
|
|
361
31
|
if (exact !== void 0) {
|
|
362
|
-
this.
|
|
32
|
+
this.commitValues([exact.value]);
|
|
363
33
|
return;
|
|
364
34
|
}
|
|
365
35
|
if (text === "" || this.allowCustom.get()) {
|
|
366
|
-
this.
|
|
36
|
+
this.commitValues(text === "" ? [] : [text]);
|
|
367
37
|
return;
|
|
368
38
|
}
|
|
369
39
|
this.renderValue();
|
|
370
40
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
return this.
|
|
374
|
-
}
|
|
375
|
-
/** Sets the value as people chose it, and says so when it changed. */
|
|
376
|
-
commit(value) {
|
|
377
|
-
const changed = value !== this.value.get();
|
|
378
|
-
this.value.set(value);
|
|
379
|
-
if (changed) this.events.emit("change", value);
|
|
380
|
-
}
|
|
381
|
-
clearValue() {
|
|
382
|
-
this._state.query = "";
|
|
383
|
-
this.closeList();
|
|
384
|
-
this.commit("");
|
|
385
|
-
this.focus();
|
|
386
|
-
}
|
|
387
|
-
/** New options: the field may now show the value's label, and an open list (or one being typed in) refreshes. */
|
|
388
|
-
renderOptionsChange() {
|
|
389
|
-
this.renderValue();
|
|
390
|
-
const typing = this._state.query !== "";
|
|
391
|
-
if (this.isOpen() || typing && this.matches(":focus-within")) this.openList(typing);
|
|
392
|
-
}
|
|
393
|
-
/** The options that match what was typed, in their order: elements already made are moved, not made again. */
|
|
394
|
-
renderOptions() {
|
|
395
|
-
const matches = filterOptions(this.options.get(), this._state.query);
|
|
396
|
-
const value = this.value.get();
|
|
397
|
-
const listbox = this._refs.listbox;
|
|
398
|
-
this._state.matches = matches;
|
|
399
|
-
matches.forEach((option, index) => {
|
|
400
|
-
const item = this.drawOption(option, index, value);
|
|
401
|
-
const current = listbox.children.item(index);
|
|
402
|
-
if (current !== item) listbox.insertBefore(item, current);
|
|
403
|
-
});
|
|
404
|
-
while (listbox.children.length > matches.length) listbox.lastElementChild?.remove();
|
|
405
|
-
listbox.hidden = matches.length === 0;
|
|
406
|
-
this._refs.empty.hidden = matches.length > 0;
|
|
407
|
-
}
|
|
408
|
-
/** The option's element, made once, with where it now sits, whether it is chosen, and the typed text marked. */
|
|
409
|
-
drawOption(option, index, value) {
|
|
410
|
-
const item = this._items.get(option) ?? this.optionNode(option);
|
|
411
|
-
this._items.set(option, item);
|
|
412
|
-
item.id = `${this._listId}-${index}`;
|
|
413
|
-
item.dataset.index = String(index);
|
|
414
|
-
item.classList.toggle("chosen", option.value === value);
|
|
415
|
-
item.querySelector(".option-label")?.replaceChildren(...highlighted(option.label, this._state.query));
|
|
416
|
-
return item;
|
|
417
|
-
}
|
|
418
|
-
optionNode(option) {
|
|
419
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
420
|
-
class: "option",
|
|
421
|
-
role: "option",
|
|
422
|
-
"aria-selected": "false",
|
|
423
|
-
"aria-disabled": option.disabled === true ? "true" : void 0,
|
|
424
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
425
|
-
class: "text",
|
|
426
|
-
children: [/* @__PURE__ */ jsx("span", { class: "option-label" }), option.description === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
427
|
-
class: "description",
|
|
428
|
-
children: option.description
|
|
429
|
-
})]
|
|
430
|
-
}), /* @__PURE__ */ jsx(JlIcon, {
|
|
431
|
-
class: "check",
|
|
432
|
-
name: "check",
|
|
433
|
-
size: CHECK_SIZE
|
|
434
|
-
})]
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
/** The active option is the one the arrows reached: aria-selected and aria-activedescendant follow it. */
|
|
438
|
-
renderActive() {
|
|
439
|
-
const option = this._state.matches[this._state.active];
|
|
440
|
-
const item = option === void 0 ? null : this._items.get(option) ?? null;
|
|
441
|
-
this._state.activeItem?.setAttribute("aria-selected", "false");
|
|
442
|
-
item?.setAttribute("aria-selected", "true");
|
|
443
|
-
this._state.activeItem = item;
|
|
444
|
-
setOrRemove(this._refs.native, "aria-activedescendant", item?.id ?? "");
|
|
445
|
-
}
|
|
446
|
-
revealActive() {
|
|
447
|
-
const item = this._state.activeItem;
|
|
448
|
-
if (item !== null) keepInView(this._refs.listbox, item);
|
|
449
|
-
}
|
|
450
|
-
/** The label of the value's option (or the value itself, as free text), unless people are typing. */
|
|
451
|
-
renderValue() {
|
|
452
|
-
const value = this.value.get();
|
|
453
|
-
if (this._state.query === "") this._refs.native.value = this.displayOf(value);
|
|
454
|
-
this.internals.setFormValue(value);
|
|
455
|
-
this.renderValidity();
|
|
456
|
-
this.renderClear();
|
|
41
|
+
/** The label of the value's option, the one kept from when it was chosen, or the free text. */
|
|
42
|
+
fieldText() {
|
|
43
|
+
return this.displayOf(this.value.get());
|
|
457
44
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (option !== void 0) return option.label;
|
|
461
|
-
return this.allowCustom.get() ? value : "";
|
|
462
|
-
}
|
|
463
|
-
renderValidity() {
|
|
464
|
-
if (this.required.get() && this.value.get() === "") {
|
|
465
|
-
this.internals.setValidity({ valueMissing: true }, jlText("chooseOption"), this._refs.native);
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
this.internals.setValidity({});
|
|
469
|
-
}
|
|
470
|
-
renderClear() {
|
|
471
|
-
const native = this._refs.native;
|
|
472
|
-
this._refs.clear.hidden = !(this.clearable.get() && !this.isOff() && native.value !== "");
|
|
473
|
-
}
|
|
474
|
-
renderDisabled(disabled) {
|
|
475
|
-
this.reflect("disabled", disabled);
|
|
476
|
-
this.drawDisabled();
|
|
477
|
-
}
|
|
478
|
-
/** Without the attribute: the form says its state before the `disabled` input has taken the attribute's change. */
|
|
479
|
-
drawDisabled() {
|
|
480
|
-
this._refs.native.disabled = this.isOff();
|
|
481
|
-
this._refs.toggle.disabled = this.isOff();
|
|
482
|
-
this.closeList();
|
|
483
|
-
this.renderClear();
|
|
45
|
+
renderFormValue() {
|
|
46
|
+
this.internals.setFormValue(this.value.get());
|
|
484
47
|
}
|
|
485
48
|
};
|
|
486
49
|
JlCombobox.register();
|
|
487
|
-
export { JlCombobox };
|
|
50
|
+
export { COMBOBOX_FILTERS, JlCombobox };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// src/molecules/jl-multi-combobox.css?inline
|
|
2
|
+
var jl_multi_combobox_default = ".chips{margin:0;padding:0;list-style:none;display:contents}.chip-item{max-width:100%;display:inline-flex}.control{padding:3px 12px 3px 4px}.native{height:calc(var(--height,var(--jl-control-md)) - 8px);flex:1 0 80px;padding-left:6px}:host(:disabled) jl-chip::part(base){color:var(--jl-muted)}";
|
|
3
|
+
export { jl_multi_combobox_default as default };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { JlComboboxBase } from '../base/jl-combobox-base';
|
|
2
|
+
import type { ComboboxOption } from '../types/jl-combobox.types';
|
|
3
|
+
/**
|
|
4
|
+
* A combobox that holds several values, shown as chips in the field: `value` and `change` are lists. Choosing an
|
|
5
|
+
* option adds it and keeps the list open for the next one; choosing it again, its chip's × or Backspace in the empty
|
|
6
|
+
* field takes it out. The list narrows as people type, or shows what the page found (`filter="none"`, `loading`,
|
|
7
|
+
* `debounce`), as `jl-combobox`'s does; the form gets each value under the field's name.
|
|
8
|
+
*/
|
|
9
|
+
export declare class JlMultiCombobox extends JlComboboxBase<string[]> {
|
|
10
|
+
static readonly selector = "jl-multi-combobox";
|
|
11
|
+
private readonly _chips;
|
|
12
|
+
private readonly _nameWatch;
|
|
13
|
+
private readonly _parts;
|
|
14
|
+
templateCss(): string;
|
|
15
|
+
onConnect(): void;
|
|
16
|
+
onDisconnect(): void;
|
|
17
|
+
protected shaped(values: string[]): string[];
|
|
18
|
+
/** A JSON list, or one plain value. */
|
|
19
|
+
protected parseValue(text: string | null): string[];
|
|
20
|
+
protected entryStart(): Node;
|
|
21
|
+
/**
|
|
22
|
+
* A choice adds the option, or takes it out when it was held. The typed text goes, and the list stays open on the
|
|
23
|
+
* option for the next choice: the page's options, as it gave them, or all of them.
|
|
24
|
+
*/
|
|
25
|
+
protected chooseOption(option: ComboboxOption): void;
|
|
26
|
+
/** Typed text adds the option of that label, or itself with free text allowed; the field empties. */
|
|
27
|
+
protected commitTyped(text: string): void;
|
|
28
|
+
/** The field holds only what people type: the chips show the values. */
|
|
29
|
+
protected fieldText(): string;
|
|
30
|
+
/** Backspace in an empty field takes the last value out. */
|
|
31
|
+
protected onBackspace(): boolean;
|
|
32
|
+
/** Tab moves on: a choice here keeps the list open, which leaving the field would not show. */
|
|
33
|
+
protected onTab(): boolean;
|
|
34
|
+
/** `aria-selected` says which options are held: the active one is marked alone. */
|
|
35
|
+
protected markActive(previous: HTMLElement | null, item: HTMLElement | null): void;
|
|
36
|
+
protected drawHeld(item: HTMLElement, held: boolean): void;
|
|
37
|
+
/** The placeholder shows while no value is held: chips take its place. */
|
|
38
|
+
protected placeholderShown(): boolean;
|
|
39
|
+
protected isFilled(): boolean;
|
|
40
|
+
protected renderValue(): void;
|
|
41
|
+
/** A disabled field keeps its chips, without their ×: a chip of its own disabled would dim its text past reading. */
|
|
42
|
+
protected drawDisabled(): void;
|
|
43
|
+
/** Each value under the field's name, as several checked boxes of one name would be. */
|
|
44
|
+
protected renderFormValue(): void;
|
|
45
|
+
/** A chip's ×, or Backspace on the last one: the value goes, and the focus stays in the field. */
|
|
46
|
+
private removeValue;
|
|
47
|
+
/** One chip per value held, in their order: a chip stays while its value does. */
|
|
48
|
+
private renderChips;
|
|
49
|
+
private chipFor;
|
|
50
|
+
}
|