@eagami/ui 5.85.0 → 5.86.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/fesm2022/eagami-ui.mjs +56 -25
- package/fesm2022/eagami-ui.mjs.map +1 -1
- package/package.json +1 -1
- package/types/eagami-ui.d.ts +10 -9
package/fesm2022/eagami-ui.mjs
CHANGED
|
@@ -14863,12 +14863,46 @@ function focusOnReveal(isOpen, popover, focus) {
|
|
|
14863
14863
|
pending.set(latestRequest);
|
|
14864
14864
|
};
|
|
14865
14865
|
}
|
|
14866
|
+
const QUERY_RESET_MS = 500;
|
|
14867
|
+
function isTypedCharacter(event) {
|
|
14868
|
+
return event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey;
|
|
14869
|
+
}
|
|
14870
|
+
var Typeahead = class {
|
|
14871
|
+
query = "";
|
|
14872
|
+
timer;
|
|
14873
|
+
constructor() {
|
|
14874
|
+
inject(DestroyRef).onDestroy(() => this.reset());
|
|
14875
|
+
}
|
|
14876
|
+
accepts(event) {
|
|
14877
|
+
return isTypedCharacter(event) && (event.key !== " " || this.query !== "");
|
|
14878
|
+
}
|
|
14879
|
+
match(key, labels, current, includeCurrent = false) {
|
|
14880
|
+
clearTimeout(this.timer);
|
|
14881
|
+
this.timer = setTimeout(() => this.query = "", QUERY_RESET_MS);
|
|
14882
|
+
this.query += foldForSearch(key);
|
|
14883
|
+
if (labels.length === 0) return -1;
|
|
14884
|
+
const start = Math.max(current, 0);
|
|
14885
|
+
const firstOffset = this.query.length > 1 || includeCurrent || current < 0 ? 0 : 1;
|
|
14886
|
+
for (let offset = firstOffset; offset <= labels.length; offset++) {
|
|
14887
|
+
const idx = (start + offset) % labels.length;
|
|
14888
|
+
const label = labels[idx];
|
|
14889
|
+
if (label !== null && foldForSearch(label).startsWith(this.query)) return idx;
|
|
14890
|
+
}
|
|
14891
|
+
return -1;
|
|
14892
|
+
}
|
|
14893
|
+
reset() {
|
|
14894
|
+
clearTimeout(this.timer);
|
|
14895
|
+
this.timer = void 0;
|
|
14896
|
+
this.query = "";
|
|
14897
|
+
}
|
|
14898
|
+
};
|
|
14866
14899
|
var MenuComponent = class MenuComponent {
|
|
14867
14900
|
injector = inject(Injector);
|
|
14868
14901
|
i18n = inject(EagamiI18nService);
|
|
14869
14902
|
listEl = viewChild("listEl", ...ngDevMode ? [{ debugName: "listEl" }] : /* istanbul ignore next */ []);
|
|
14870
14903
|
popover = viewChild(PopoverComponent, ...ngDevMode ? [{ debugName: "popover" }] : /* istanbul ignore next */ []);
|
|
14871
14904
|
focusFirstItemOnReveal = focusOnReveal(() => this.open(), () => this.popover(), () => this.focusFirstItem());
|
|
14905
|
+
typeahead = new Typeahead();
|
|
14872
14906
|
placement = input("bottom-start", ...ngDevMode ? [{ debugName: "placement" }] : /* istanbul ignore next */ []);
|
|
14873
14907
|
size = input("md", ...ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []);
|
|
14874
14908
|
maxHeight = input("20rem", ...ngDevMode ? [{ debugName: "maxHeight" }] : /* istanbul ignore next */ []);
|
|
@@ -14891,6 +14925,7 @@ var MenuComponent = class MenuComponent {
|
|
|
14891
14925
|
constructor() {
|
|
14892
14926
|
effect(() => {
|
|
14893
14927
|
if (!this.open()) {
|
|
14928
|
+
this.typeahead.reset();
|
|
14894
14929
|
this.activeItemId.set(null);
|
|
14895
14930
|
this.asContextMenu.set(false);
|
|
14896
14931
|
this.anchorPoint.set(null);
|
|
@@ -14981,6 +15016,12 @@ var MenuComponent = class MenuComponent {
|
|
|
14981
15016
|
case "End":
|
|
14982
15017
|
event.preventDefault();
|
|
14983
15018
|
next = items.length - 1;
|
|
15019
|
+
break;
|
|
15020
|
+
default: if (this.typeahead.accepts(event)) {
|
|
15021
|
+
event.preventDefault();
|
|
15022
|
+
const labels = items.map((item) => item.querySelector(".ea-menu-item__label")?.textContent?.trim() ?? "");
|
|
15023
|
+
next = this.typeahead.match(event.key, labels, current);
|
|
15024
|
+
}
|
|
14984
15025
|
}
|
|
14985
15026
|
if (next >= 0) this.focusItem(items[next]);
|
|
14986
15027
|
}
|
|
@@ -18954,9 +18995,6 @@ const LIST_KEYS = /* @__PURE__ */ new Set([
|
|
|
18954
18995
|
"Enter",
|
|
18955
18996
|
"Escape"
|
|
18956
18997
|
]);
|
|
18957
|
-
function isTypedCharacter(event) {
|
|
18958
|
-
return event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey;
|
|
18959
|
-
}
|
|
18960
18998
|
var DropdownComponent = class DropdownComponent extends LabelledFieldControlBase {
|
|
18961
18999
|
elRef = viewChild("triggerEl", ...ngDevMode ? [{ debugName: "elRef" }] : /* istanbul ignore next */ []);
|
|
18962
19000
|
popover = viewChild(PopoverComponent, ...ngDevMode ? [{ debugName: "popover" }] : /* istanbul ignore next */ []);
|
|
@@ -18985,13 +19023,11 @@ var DropdownComponent = class DropdownComponent extends LabelledFieldControlBase
|
|
|
18985
19023
|
focusedIndex = signal(-1, ...ngDevMode ? [{ debugName: "focusedIndex" }] : /* istanbul ignore next */ []);
|
|
18986
19024
|
searchTerm = signal("", ...ngDevMode ? [{ debugName: "searchTerm" }] : /* istanbul ignore next */ []);
|
|
18987
19025
|
_formDisabled = signal(false, ...ngDevMode ? [{ debugName: "_formDisabled" }] : /* istanbul ignore next */ []);
|
|
18988
|
-
|
|
18989
|
-
typeaheadTimer;
|
|
19026
|
+
typeahead = new Typeahead();
|
|
18990
19027
|
onChange = () => {};
|
|
18991
19028
|
onTouched = () => {};
|
|
18992
19029
|
constructor() {
|
|
18993
19030
|
super();
|
|
18994
|
-
inject(DestroyRef).onDestroy(() => clearTimeout(this.typeaheadTimer));
|
|
18995
19031
|
afterRenderEffect(() => {
|
|
18996
19032
|
if (this.searchable() && this.popover()?.isPositioned()) untracked(() => this.searchEl()?.nativeElement.focus());
|
|
18997
19033
|
});
|
|
@@ -19074,8 +19110,7 @@ var DropdownComponent = class DropdownComponent extends LabelledFieldControlBase
|
|
|
19074
19110
|
this.isOpen.set(false);
|
|
19075
19111
|
this.focusedIndex.set(-1);
|
|
19076
19112
|
this.searchTerm.set("");
|
|
19077
|
-
this.
|
|
19078
|
-
clearTimeout(this.typeaheadTimer);
|
|
19113
|
+
this.typeahead.reset();
|
|
19079
19114
|
if (searching) this.focus();
|
|
19080
19115
|
}
|
|
19081
19116
|
clear() {
|
|
@@ -19094,7 +19129,7 @@ var DropdownComponent = class DropdownComponent extends LabelledFieldControlBase
|
|
|
19094
19129
|
if (this.isDisabled() || this.readonly()) return;
|
|
19095
19130
|
switch (event.key) {
|
|
19096
19131
|
case " ":
|
|
19097
|
-
if (this.
|
|
19132
|
+
if (this.typeahead.accepts(event)) this.handleTypeahead(event);
|
|
19098
19133
|
else this.selectFocusedOrOpen(event);
|
|
19099
19134
|
break;
|
|
19100
19135
|
case "Enter":
|
|
@@ -19184,25 +19219,13 @@ var DropdownComponent = class DropdownComponent extends LabelledFieldControlBase
|
|
|
19184
19219
|
document.getElementById(`${this.id()}-option-${idx}`)?.scrollIntoView({ block: "nearest" });
|
|
19185
19220
|
}
|
|
19186
19221
|
handleTypeahead(event) {
|
|
19187
|
-
if (!
|
|
19222
|
+
if (!this.typeahead.accepts(event)) return;
|
|
19188
19223
|
event.preventDefault();
|
|
19189
|
-
if (this.typeaheadTimer !== void 0) clearTimeout(this.typeaheadTimer);
|
|
19190
|
-
this.typeaheadTimer = setTimeout(() => this.typeaheadQuery = "", 500);
|
|
19191
|
-
this.typeaheadQuery += foldForSearch(event.key);
|
|
19192
19224
|
const wasOpen = this.isOpen();
|
|
19193
19225
|
if (!wasOpen) this.toggle();
|
|
19194
|
-
const
|
|
19195
|
-
|
|
19196
|
-
|
|
19197
|
-
const firstOffset = this.typeaheadQuery.length > 1 || !wasOpen ? 0 : 1;
|
|
19198
|
-
for (let offset = firstOffset; offset <= opts.length; offset++) {
|
|
19199
|
-
const idx = (start + offset) % opts.length;
|
|
19200
|
-
const opt = opts[idx];
|
|
19201
|
-
if (!opt.disabled && foldForSearch(opt.label).startsWith(this.typeaheadQuery)) {
|
|
19202
|
-
this.setFocusedIndex(idx);
|
|
19203
|
-
return;
|
|
19204
|
-
}
|
|
19205
|
-
}
|
|
19226
|
+
const labels = this.filteredOptions().map((o) => o.disabled ? null : o.label);
|
|
19227
|
+
const idx = this.typeahead.match(event.key, labels, this.focusedIndex(), !wasOpen);
|
|
19228
|
+
if (idx >= 0) this.setFocusedIndex(idx);
|
|
19206
19229
|
}
|
|
19207
19230
|
moveFocus(delta) {
|
|
19208
19231
|
const opts = this.filteredOptions();
|
|
@@ -32944,6 +32967,7 @@ var TreeComponent = class TreeComponent {
|
|
|
32944
32967
|
nodeClick = output();
|
|
32945
32968
|
listEl = viewChild("listEl", ...ngDevMode ? [{ debugName: "listEl" }] : /* istanbul ignore next */ []);
|
|
32946
32969
|
_focusedId = signal(null, ...ngDevMode ? [{ debugName: "_focusedId" }] : /* istanbul ignore next */ []);
|
|
32970
|
+
typeahead = new Typeahead();
|
|
32947
32971
|
expandedSet = computed(() => new Set(this.expandedIds()), ...ngDevMode ? [{ debugName: "expandedSet" }] : /* istanbul ignore next */ []);
|
|
32948
32972
|
focusedId = computed(() => {
|
|
32949
32973
|
const explicit = this._focusedId();
|
|
@@ -32991,6 +33015,13 @@ var TreeComponent = class TreeComponent {
|
|
|
32991
33015
|
if (visible.length === 0) return;
|
|
32992
33016
|
const currentId = this.focusedId();
|
|
32993
33017
|
const currentIdx = currentId ? visible.indexOf(currentId) : -1;
|
|
33018
|
+
if (this.typeahead.accepts(event)) {
|
|
33019
|
+
event.preventDefault();
|
|
33020
|
+
const labels = visible.map((id) => this.findNode(id)?.label ?? null);
|
|
33021
|
+
const idx = this.typeahead.match(event.key, labels, currentIdx);
|
|
33022
|
+
if (idx >= 0) this.focusNode(visible[idx]);
|
|
33023
|
+
return;
|
|
33024
|
+
}
|
|
32994
33025
|
const rtl = isRtl(event.currentTarget);
|
|
32995
33026
|
let key = event.key;
|
|
32996
33027
|
if (rtl && key === "ArrowRight") key = "ArrowLeft";
|