@deepfuture/dui-components 0.0.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/accordion/accordion-context.d.ts +15 -0
- package/accordion/accordion-context.js +3 -0
- package/accordion/accordion-item.d.ts +22 -0
- package/accordion/accordion-item.js +254 -0
- package/accordion/accordion.d.ts +20 -0
- package/accordion/accordion.js +185 -0
- package/accordion/index.d.ts +3 -0
- package/accordion/index.js +2 -0
- package/accordion/register.d.ts +1 -0
- package/accordion/register.js +8 -0
- package/alert-dialog/alert-dialog-close.d.ts +15 -0
- package/alert-dialog/alert-dialog-close.js +35 -0
- package/alert-dialog/alert-dialog-context.d.ts +13 -0
- package/alert-dialog/alert-dialog-context.js +3 -0
- package/alert-dialog/alert-dialog-popup.d.ts +34 -0
- package/alert-dialog/alert-dialog-popup.js +260 -0
- package/alert-dialog/alert-dialog-trigger.d.ts +15 -0
- package/alert-dialog/alert-dialog-trigger.js +52 -0
- package/alert-dialog/alert-dialog.d.ts +30 -0
- package/alert-dialog/alert-dialog.js +97 -0
- package/alert-dialog/index.d.ts +6 -0
- package/alert-dialog/index.js +4 -0
- package/alert-dialog/register.d.ts +1 -0
- package/alert-dialog/register.js +16 -0
- package/all.d.ts +86 -0
- package/all.js +191 -0
- package/avatar/avatar.d.ts +41 -0
- package/avatar/avatar.js +188 -0
- package/avatar/index.d.ts +2 -0
- package/avatar/index.js +1 -0
- package/avatar/register.d.ts +1 -0
- package/avatar/register.js +4 -0
- package/badge/badge.d.ts +14 -0
- package/badge/badge.js +43 -0
- package/badge/index.d.ts +2 -0
- package/badge/index.js +1 -0
- package/badge/register.d.ts +1 -0
- package/badge/register.js +4 -0
- package/breadcrumb/breadcrumb-ellipsis.d.ts +14 -0
- package/breadcrumb/breadcrumb-ellipsis.js +39 -0
- package/breadcrumb/breadcrumb-item.d.ts +13 -0
- package/breadcrumb/breadcrumb-item.js +31 -0
- package/breadcrumb/breadcrumb-link.d.ts +14 -0
- package/breadcrumb/breadcrumb-link.js +32 -0
- package/breadcrumb/breadcrumb-page.d.ts +13 -0
- package/breadcrumb/breadcrumb-page.js +36 -0
- package/breadcrumb/breadcrumb-separator.d.ts +14 -0
- package/breadcrumb/breadcrumb-separator.js +36 -0
- package/breadcrumb/breadcrumb.d.ts +14 -0
- package/breadcrumb/breadcrumb.js +38 -0
- package/breadcrumb/index.d.ts +6 -0
- package/breadcrumb/index.js +6 -0
- package/breadcrumb/register.d.ts +1 -0
- package/breadcrumb/register.js +14 -0
- package/button/button.d.ts +38 -0
- package/button/button.js +143 -0
- package/button/index.d.ts +2 -0
- package/button/index.js +1 -0
- package/button/register.d.ts +1 -0
- package/button/register.js +4 -0
- package/calendar/calendar.d.ts +33 -0
- package/calendar/calendar.js +428 -0
- package/calendar/index.d.ts +1 -0
- package/calendar/index.js +1 -0
- package/calendar/register.d.ts +1 -0
- package/calendar/register.js +4 -0
- package/center/center.d.ts +14 -0
- package/center/center.js +37 -0
- package/center/index.d.ts +1 -0
- package/center/index.js +1 -0
- package/center/register.d.ts +1 -0
- package/center/register.js +4 -0
- package/checkbox/checkbox-group-context.d.ts +11 -0
- package/checkbox/checkbox-group-context.js +3 -0
- package/checkbox/checkbox-group.d.ts +34 -0
- package/checkbox/checkbox-group.js +128 -0
- package/checkbox/checkbox.d.ts +46 -0
- package/checkbox/checkbox.js +314 -0
- package/checkbox/index.d.ts +3 -0
- package/checkbox/index.js +2 -0
- package/checkbox/register.d.ts +1 -0
- package/checkbox/register.js +8 -0
- package/collapsible/collapsible.d.ts +22 -0
- package/collapsible/collapsible.js +227 -0
- package/collapsible/index.d.ts +1 -0
- package/collapsible/index.js +1 -0
- package/collapsible/register.d.ts +1 -0
- package/collapsible/register.js +4 -0
- package/combobox/combobox.d.ts +46 -0
- package/combobox/combobox.js +524 -0
- package/combobox/index.d.ts +2 -0
- package/combobox/index.js +1 -0
- package/combobox/register.d.ts +1 -0
- package/combobox/register.js +4 -0
- package/command/command-context.d.ts +30 -0
- package/command/command-context.js +3 -0
- package/command/command-empty.d.ts +10 -0
- package/command/command-empty.js +50 -0
- package/command/command-group.d.ts +15 -0
- package/command/command-group.js +79 -0
- package/command/command-input.d.ts +13 -0
- package/command/command-input.js +106 -0
- package/command/command-item.d.ts +20 -0
- package/command/command-item.js +175 -0
- package/command/command-list.d.ts +9 -0
- package/command/command-list.js +43 -0
- package/command/command-score.d.ts +6 -0
- package/command/command-score.js +31 -0
- package/command/command-separator.d.ts +7 -0
- package/command/command-separator.js +15 -0
- package/command/command-shortcut.d.ts +7 -0
- package/command/command-shortcut.js +16 -0
- package/command/command.d.ts +25 -0
- package/command/command.js +278 -0
- package/command/index.d.ts +10 -0
- package/command/index.js +9 -0
- package/command/register.d.ts +1 -0
- package/command/register.js +22 -0
- package/data-table/data-table.d.ts +59 -0
- package/data-table/data-table.js +416 -0
- package/data-table/index.d.ts +2 -0
- package/data-table/index.js +1 -0
- package/data-table/register.d.ts +1 -0
- package/data-table/register.js +4 -0
- package/dialog/dialog-close.d.ts +15 -0
- package/dialog/dialog-close.js +35 -0
- package/dialog/dialog-context.d.ts +13 -0
- package/dialog/dialog-context.js +3 -0
- package/dialog/dialog-popup.d.ts +36 -0
- package/dialog/dialog-popup.js +277 -0
- package/dialog/dialog-trigger.d.ts +15 -0
- package/dialog/dialog-trigger.js +52 -0
- package/dialog/dialog.d.ts +30 -0
- package/dialog/dialog.js +97 -0
- package/dialog/index.d.ts +6 -0
- package/dialog/index.js +4 -0
- package/dialog/register.d.ts +1 -0
- package/dialog/register.js +16 -0
- package/dropzone/dropzone.d.ts +74 -0
- package/dropzone/dropzone.js +357 -0
- package/dropzone/index.d.ts +2 -0
- package/dropzone/index.js +1 -0
- package/dropzone/register.d.ts +1 -0
- package/dropzone/register.js +4 -0
- package/field/field-context.d.ts +20 -0
- package/field/field-context.js +2 -0
- package/field/index.d.ts +2 -0
- package/field/index.js +1 -0
- package/global.d.ts +189 -0
- package/hstack/hstack.d.ts +25 -0
- package/hstack/hstack.js +141 -0
- package/hstack/index.d.ts +2 -0
- package/hstack/index.js +1 -0
- package/hstack/register.d.ts +1 -0
- package/hstack/register.js +4 -0
- package/icon/icon.d.ts +16 -0
- package/icon/icon.js +34 -0
- package/icon/index.d.ts +1 -0
- package/icon/index.js +1 -0
- package/icon/register.d.ts +1 -0
- package/icon/register.js +4 -0
- package/input/index.d.ts +1 -0
- package/input/index.js +1 -0
- package/input/input.d.ts +47 -0
- package/input/input.js +205 -0
- package/input/register.d.ts +1 -0
- package/input/register.js +4 -0
- package/link/index.d.ts +1 -0
- package/link/index.js +1 -0
- package/link/link.d.ts +27 -0
- package/link/link.js +57 -0
- package/link/register.d.ts +1 -0
- package/link/register.js +4 -0
- package/menu/index.d.ts +2 -0
- package/menu/index.js +2 -0
- package/menu/menu-item.d.ts +17 -0
- package/menu/menu-item.js +62 -0
- package/menu/menu.d.ts +15 -0
- package/menu/menu.js +228 -0
- package/menu/register.d.ts +1 -0
- package/menu/register.js +8 -0
- package/menubar/index.d.ts +2 -0
- package/menubar/index.js +1 -0
- package/menubar/menubar-context.d.ts +9 -0
- package/menubar/menubar-context.js +2 -0
- package/menubar/menubar.d.ts +19 -0
- package/menubar/menubar.js +130 -0
- package/menubar/register.d.ts +1 -0
- package/menubar/register.js +4 -0
- package/number-field/index.d.ts +1 -0
- package/number-field/index.js +1 -0
- package/number-field/number-field.d.ts +34 -0
- package/number-field/number-field.js +326 -0
- package/number-field/register.d.ts +1 -0
- package/number-field/register.js +4 -0
- package/package.json +217 -0
- package/page-inset/index.d.ts +1 -0
- package/page-inset/index.js +1 -0
- package/page-inset/page-inset.d.ts +28 -0
- package/page-inset/page-inset.js +103 -0
- package/page-inset/register.d.ts +1 -0
- package/page-inset/register.js +4 -0
- package/popover/index.d.ts +6 -0
- package/popover/index.js +4 -0
- package/popover/popover-close.d.ts +13 -0
- package/popover/popover-close.js +33 -0
- package/popover/popover-context.d.ts +17 -0
- package/popover/popover-context.js +3 -0
- package/popover/popover-popup.d.ts +20 -0
- package/popover/popover-popup.js +176 -0
- package/popover/popover-trigger.d.ts +13 -0
- package/popover/popover-trigger.js +57 -0
- package/popover/popover.d.ts +30 -0
- package/popover/popover.js +140 -0
- package/popover/register.d.ts +1 -0
- package/popover/register.js +16 -0
- package/portal/index.d.ts +2 -0
- package/portal/index.js +1 -0
- package/portal/portal.d.ts +29 -0
- package/portal/portal.js +115 -0
- package/portal/register.d.ts +1 -0
- package/portal/register.js +4 -0
- package/preview-card/index.d.ts +5 -0
- package/preview-card/index.js +3 -0
- package/preview-card/preview-card-context.d.ts +16 -0
- package/preview-card/preview-card-context.js +3 -0
- package/preview-card/preview-card-popup.d.ts +16 -0
- package/preview-card/preview-card-popup.js +167 -0
- package/preview-card/preview-card-trigger.d.ts +13 -0
- package/preview-card/preview-card-trigger.js +75 -0
- package/preview-card/preview-card.d.ts +34 -0
- package/preview-card/preview-card.js +164 -0
- package/preview-card/register.d.ts +1 -0
- package/preview-card/register.js +12 -0
- package/progress/index.d.ts +1 -0
- package/progress/index.js +1 -0
- package/progress/progress.d.ts +19 -0
- package/progress/progress.js +94 -0
- package/progress/register.d.ts +1 -0
- package/progress/register.js +4 -0
- package/radio/index.d.ts +3 -0
- package/radio/index.js +2 -0
- package/radio/radio-group-context.d.ts +11 -0
- package/radio/radio-group-context.js +2 -0
- package/radio/radio-group.d.ts +37 -0
- package/radio/radio-group.js +135 -0
- package/radio/radio.d.ts +27 -0
- package/radio/radio.js +204 -0
- package/radio/register.d.ts +1 -0
- package/radio/register.js +8 -0
- package/scroll-area/index.d.ts +1 -0
- package/scroll-area/index.js +1 -0
- package/scroll-area/register.d.ts +1 -0
- package/scroll-area/register.js +4 -0
- package/scroll-area/scroll-area.d.ts +38 -0
- package/scroll-area/scroll-area.js +453 -0
- package/select/index.d.ts +2 -0
- package/select/index.js +1 -0
- package/select/register.d.ts +1 -0
- package/select/register.js +4 -0
- package/select/select.d.ts +36 -0
- package/select/select.js +404 -0
- package/separator/index.d.ts +1 -0
- package/separator/index.js +1 -0
- package/separator/register.d.ts +1 -0
- package/separator/register.js +4 -0
- package/separator/separator.d.ts +12 -0
- package/separator/separator.js +50 -0
- package/sidebar/index.d.ts +16 -0
- package/sidebar/index.js +13 -0
- package/sidebar/register.d.ts +1 -0
- package/sidebar/register.js +52 -0
- package/sidebar/sidebar-content.d.ts +14 -0
- package/sidebar/sidebar-content.js +30 -0
- package/sidebar/sidebar-context.d.ts +15 -0
- package/sidebar/sidebar-context.js +3 -0
- package/sidebar/sidebar-footer.d.ts +12 -0
- package/sidebar/sidebar-footer.js +21 -0
- package/sidebar/sidebar-group-label.d.ts +17 -0
- package/sidebar/sidebar-group-label.js +49 -0
- package/sidebar/sidebar-group.d.ts +15 -0
- package/sidebar/sidebar-group.js +29 -0
- package/sidebar/sidebar-header.d.ts +12 -0
- package/sidebar/sidebar-header.js +21 -0
- package/sidebar/sidebar-inset.d.ts +15 -0
- package/sidebar/sidebar-inset.js +29 -0
- package/sidebar/sidebar-menu-button.d.ts +31 -0
- package/sidebar/sidebar-menu-button.js +201 -0
- package/sidebar/sidebar-menu-item.d.ts +12 -0
- package/sidebar/sidebar-menu-item.js +20 -0
- package/sidebar/sidebar-menu.d.ts +14 -0
- package/sidebar/sidebar-menu.js +30 -0
- package/sidebar/sidebar-provider.d.ts +34 -0
- package/sidebar/sidebar-provider.js +157 -0
- package/sidebar/sidebar-separator.d.ts +12 -0
- package/sidebar/sidebar-separator.js +24 -0
- package/sidebar/sidebar-trigger.d.ts +16 -0
- package/sidebar/sidebar-trigger.js +50 -0
- package/sidebar/sidebar.d.ts +21 -0
- package/sidebar/sidebar.js +228 -0
- package/slider/index.d.ts +1 -0
- package/slider/index.js +1 -0
- package/slider/register.d.ts +1 -0
- package/slider/register.js +4 -0
- package/slider/slider.d.ts +37 -0
- package/slider/slider.js +268 -0
- package/spinner/index.d.ts +1 -0
- package/spinner/index.js +1 -0
- package/spinner/register.d.ts +1 -0
- package/spinner/register.js +4 -0
- package/spinner/spinner.d.ts +18 -0
- package/spinner/spinner.js +138 -0
- package/switch/index.d.ts +1 -0
- package/switch/index.js +1 -0
- package/switch/register.d.ts +1 -0
- package/switch/register.js +4 -0
- package/switch/switch.d.ts +29 -0
- package/switch/switch.js +201 -0
- package/tabs/index.d.ts +6 -0
- package/tabs/index.js +5 -0
- package/tabs/register.d.ts +1 -0
- package/tabs/register.js +10 -0
- package/tabs/tab.d.ts +16 -0
- package/tabs/tab.js +98 -0
- package/tabs/tabs-context.d.ts +8 -0
- package/tabs/tabs-context.js +2 -0
- package/tabs/tabs-indicator.d.ts +11 -0
- package/tabs/tabs-indicator.js +27 -0
- package/tabs/tabs-list.d.ts +17 -0
- package/tabs/tabs-list.js +85 -0
- package/tabs/tabs-panel.d.ts +18 -0
- package/tabs/tabs-panel.js +85 -0
- package/tabs/tabs.d.ts +24 -0
- package/tabs/tabs.js +111 -0
- package/textarea/index.d.ts +2 -0
- package/textarea/index.js +1 -0
- package/textarea/register.d.ts +1 -0
- package/textarea/register.js +4 -0
- package/textarea/textarea.d.ts +37 -0
- package/textarea/textarea.js +170 -0
- package/toggle/index.d.ts +3 -0
- package/toggle/index.js +2 -0
- package/toggle/register.d.ts +1 -0
- package/toggle/register.js +8 -0
- package/toggle/toggle-group-context.d.ts +9 -0
- package/toggle/toggle-group-context.js +2 -0
- package/toggle/toggle-group.d.ts +27 -0
- package/toggle/toggle-group.js +163 -0
- package/toggle/toggle.d.ts +25 -0
- package/toggle/toggle.js +124 -0
- package/toolbar/index.d.ts +1 -0
- package/toolbar/index.js +1 -0
- package/toolbar/register.d.ts +1 -0
- package/toolbar/register.js +4 -0
- package/toolbar/toolbar.d.ts +15 -0
- package/toolbar/toolbar.js +89 -0
- package/tooltip/index.d.ts +5 -0
- package/tooltip/index.js +3 -0
- package/tooltip/register.d.ts +1 -0
- package/tooltip/register.js +12 -0
- package/tooltip/tooltip-context.d.ts +17 -0
- package/tooltip/tooltip-context.js +3 -0
- package/tooltip/tooltip-popup.d.ts +16 -0
- package/tooltip/tooltip-popup.js +162 -0
- package/tooltip/tooltip-trigger.d.ts +15 -0
- package/tooltip/tooltip-trigger.js +110 -0
- package/tooltip/tooltip.d.ts +36 -0
- package/tooltip/tooltip.js +176 -0
- package/trunc/index.d.ts +1 -0
- package/trunc/index.js +1 -0
- package/trunc/register.d.ts +1 -0
- package/trunc/register.js +4 -0
- package/trunc/trunc.d.ts +19 -0
- package/trunc/trunc.js +68 -0
- package/vstack/index.d.ts +1 -0
- package/vstack/index.js +1 -0
- package/vstack/register.d.ts +1 -0
- package/vstack/register.js +4 -0
- package/vstack/vstack.d.ts +17 -0
- package/vstack/vstack.js +83 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/** Ported from original DUI: deep-future-app/app/client/components/dui/command */
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
import { css, html, LitElement } from "lit";
|
|
9
|
+
import { property, state } from "lit/decorators.js";
|
|
10
|
+
import { provide } from "@lit/context";
|
|
11
|
+
import { base } from "@deepfuture/dui-core/base";
|
|
12
|
+
import { customEvent } from "@deepfuture/dui-core/event";
|
|
13
|
+
import { commandContext, } from "./command-context.js";
|
|
14
|
+
import { commandScore } from "./command-score.js";
|
|
15
|
+
export const selectEvent = customEvent("select", {
|
|
16
|
+
bubbles: true,
|
|
17
|
+
composed: true,
|
|
18
|
+
});
|
|
19
|
+
export const searchChangeEvent = customEvent("search-change", {
|
|
20
|
+
bubbles: true,
|
|
21
|
+
composed: true,
|
|
22
|
+
});
|
|
23
|
+
export const escapeEvent = customEvent("escape", {
|
|
24
|
+
bubbles: true,
|
|
25
|
+
composed: true,
|
|
26
|
+
});
|
|
27
|
+
let idCounter = 0;
|
|
28
|
+
const nextId = () => `dui-command-${++idCounter}`;
|
|
29
|
+
const styles = css `
|
|
30
|
+
:host {
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
export class DuiCommand extends LitElement {
|
|
37
|
+
static { this.tagName = "dui-command"; }
|
|
38
|
+
static { this.styles = [base, styles]; }
|
|
39
|
+
#loop_accessor_storage = false;
|
|
40
|
+
/** Whether keyboard navigation wraps from last to first and vice versa. */
|
|
41
|
+
get loop() { return this.#loop_accessor_storage; }
|
|
42
|
+
set loop(value) { this.#loop_accessor_storage = value; }
|
|
43
|
+
#shouldFilter_accessor_storage = true;
|
|
44
|
+
/** Whether items should be filtered based on search text. */
|
|
45
|
+
get shouldFilter() { return this.#shouldFilter_accessor_storage; }
|
|
46
|
+
set shouldFilter(value) { this.#shouldFilter_accessor_storage = value; }
|
|
47
|
+
#value_accessor_storage = undefined;
|
|
48
|
+
/** Controlled value — the currently selected item value. */
|
|
49
|
+
get value() { return this.#value_accessor_storage; }
|
|
50
|
+
set value(value) { this.#value_accessor_storage = value; }
|
|
51
|
+
#filter_accessor_storage = undefined;
|
|
52
|
+
/** Custom filter function. */
|
|
53
|
+
get filter() { return this.#filter_accessor_storage; }
|
|
54
|
+
set filter(value) { this.#filter_accessor_storage = value; }
|
|
55
|
+
#search_accessor_storage = "";
|
|
56
|
+
get #search() { return this.#search_accessor_storage; }
|
|
57
|
+
set #search(value) { this.#search_accessor_storage = value; }
|
|
58
|
+
#selectedItemId_accessor_storage = undefined;
|
|
59
|
+
get #selectedItemId() { return this.#selectedItemId_accessor_storage; }
|
|
60
|
+
set #selectedItemId(value) { this.#selectedItemId_accessor_storage = value; }
|
|
61
|
+
#items = new Map();
|
|
62
|
+
#itemOrder = [];
|
|
63
|
+
#groups = new Set();
|
|
64
|
+
#scoresMap = new Map();
|
|
65
|
+
#listId = nextId();
|
|
66
|
+
#recomputeScores() {
|
|
67
|
+
this.#scoresMap.clear();
|
|
68
|
+
for (const [id, entry] of this.#items) {
|
|
69
|
+
const score = this.filter
|
|
70
|
+
? this.filter(entry.value, this.#search, entry.keywords)
|
|
71
|
+
: commandScore(this.#search, entry.value, entry.textContent, entry.keywords);
|
|
72
|
+
this.#scoresMap.set(id, score);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
#getScore = (itemId) => {
|
|
76
|
+
if (!this.shouldFilter)
|
|
77
|
+
return 1;
|
|
78
|
+
return this.#scoresMap.get(itemId) ?? 0;
|
|
79
|
+
};
|
|
80
|
+
#getVisibleItems() {
|
|
81
|
+
return this.#itemOrder
|
|
82
|
+
.map((id) => this.#items.get(id))
|
|
83
|
+
.filter((entry) => {
|
|
84
|
+
if (!entry)
|
|
85
|
+
return false;
|
|
86
|
+
if (!this.shouldFilter)
|
|
87
|
+
return true;
|
|
88
|
+
return (this.#scoresMap.get(entry.id) ?? 0) > 0;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
#getVisibleCount = () => {
|
|
92
|
+
return this.#getVisibleItems().length;
|
|
93
|
+
};
|
|
94
|
+
#getGroupVisibleCount = (groupId) => {
|
|
95
|
+
return this.#getVisibleItems().filter((e) => e.groupId === groupId).length;
|
|
96
|
+
};
|
|
97
|
+
#registerItem = (entry) => {
|
|
98
|
+
this.#items.set(entry.id, entry);
|
|
99
|
+
if (!this.#itemOrder.includes(entry.id)) {
|
|
100
|
+
this.#itemOrder.push(entry.id);
|
|
101
|
+
}
|
|
102
|
+
// Recompute scores for new item
|
|
103
|
+
const score = this.filter
|
|
104
|
+
? this.filter(entry.value, this.#search, entry.keywords)
|
|
105
|
+
: commandScore(this.#search, entry.value, entry.textContent, entry.keywords);
|
|
106
|
+
this.#scoresMap.set(entry.id, score);
|
|
107
|
+
// Auto-select first visible item if nothing selected
|
|
108
|
+
if (!this.#selectedItemId) {
|
|
109
|
+
const visible = this.#getVisibleItems();
|
|
110
|
+
if (visible.length > 0 && !visible[0].disabled) {
|
|
111
|
+
this.#selectedItemId = visible[0].id;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
this.requestUpdate();
|
|
115
|
+
};
|
|
116
|
+
#unregisterItem = (id) => {
|
|
117
|
+
this.#items.delete(id);
|
|
118
|
+
this.#itemOrder = this.#itemOrder.filter((v) => v !== id);
|
|
119
|
+
this.#scoresMap.delete(id);
|
|
120
|
+
this.requestUpdate();
|
|
121
|
+
};
|
|
122
|
+
#updateItem = (entry) => {
|
|
123
|
+
this.#items.set(entry.id, entry);
|
|
124
|
+
const score = this.filter
|
|
125
|
+
? this.filter(entry.value, this.#search, entry.keywords)
|
|
126
|
+
: commandScore(this.#search, entry.value, entry.textContent, entry.keywords);
|
|
127
|
+
this.#scoresMap.set(entry.id, score);
|
|
128
|
+
this.requestUpdate();
|
|
129
|
+
};
|
|
130
|
+
#registerGroup = (groupId) => {
|
|
131
|
+
this.#groups.add(groupId);
|
|
132
|
+
};
|
|
133
|
+
#unregisterGroup = (groupId) => {
|
|
134
|
+
this.#groups.delete(groupId);
|
|
135
|
+
};
|
|
136
|
+
#setSearch = (value) => {
|
|
137
|
+
this.#search = value;
|
|
138
|
+
this.#recomputeScores();
|
|
139
|
+
// Select first visible non-disabled item
|
|
140
|
+
const visible = this.#getVisibleItems();
|
|
141
|
+
const firstSelectable = visible.find((e) => !e.disabled);
|
|
142
|
+
this.#selectedItemId = firstSelectable?.id;
|
|
143
|
+
this.dispatchEvent(searchChangeEvent(value));
|
|
144
|
+
};
|
|
145
|
+
#selectItem = (id) => {
|
|
146
|
+
this.#selectedItemId = id;
|
|
147
|
+
};
|
|
148
|
+
#handleItemSelect = (value) => {
|
|
149
|
+
this.dispatchEvent(selectEvent(value));
|
|
150
|
+
};
|
|
151
|
+
#handleKeyDown = (event) => {
|
|
152
|
+
const visible = this.#getVisibleItems().filter((e) => !e.disabled);
|
|
153
|
+
if (visible.length === 0)
|
|
154
|
+
return;
|
|
155
|
+
const currentIndex = visible.findIndex((e) => e.id === this.#selectedItemId);
|
|
156
|
+
const selectByIndex = (index) => {
|
|
157
|
+
const item = visible[index];
|
|
158
|
+
if (item) {
|
|
159
|
+
this.#selectedItemId = item.id;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
switch (event.key) {
|
|
163
|
+
case "ArrowDown":
|
|
164
|
+
case "n":
|
|
165
|
+
case "j": {
|
|
166
|
+
// Ctrl+N and Ctrl+J for down
|
|
167
|
+
if (event.key !== "ArrowDown" &&
|
|
168
|
+
!event.ctrlKey &&
|
|
169
|
+
!event.metaKey) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
if (currentIndex < visible.length - 1) {
|
|
174
|
+
selectByIndex(currentIndex + 1);
|
|
175
|
+
}
|
|
176
|
+
else if (this.loop) {
|
|
177
|
+
selectByIndex(0);
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case "ArrowUp":
|
|
182
|
+
case "p":
|
|
183
|
+
case "k": {
|
|
184
|
+
// Ctrl+P and Ctrl+K for up
|
|
185
|
+
if (event.key !== "ArrowUp" &&
|
|
186
|
+
!event.ctrlKey &&
|
|
187
|
+
!event.metaKey) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
if (currentIndex > 0) {
|
|
192
|
+
selectByIndex(currentIndex - 1);
|
|
193
|
+
}
|
|
194
|
+
else if (this.loop) {
|
|
195
|
+
selectByIndex(visible.length - 1);
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case "Home": {
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
selectByIndex(0);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case "End": {
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
selectByIndex(visible.length - 1);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case "Enter": {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
const selected = visible.find((e) => e.id === this.#selectedItemId);
|
|
212
|
+
if (selected) {
|
|
213
|
+
this.#handleItemSelect(selected.value);
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case "Escape": {
|
|
218
|
+
event.preventDefault();
|
|
219
|
+
this.dispatchEvent(escapeEvent());
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
#_ctx_accessor_storage = this.#buildContext();
|
|
225
|
+
get _ctx() { return this.#_ctx_accessor_storage; }
|
|
226
|
+
set _ctx(value) { this.#_ctx_accessor_storage = value; }
|
|
227
|
+
#buildContext() {
|
|
228
|
+
return {
|
|
229
|
+
search: this.#search,
|
|
230
|
+
selectedItemId: this.#selectedItemId,
|
|
231
|
+
listId: this.#listId,
|
|
232
|
+
loop: this.loop,
|
|
233
|
+
shouldFilter: this.shouldFilter,
|
|
234
|
+
getScore: this.#getScore,
|
|
235
|
+
getVisibleCount: this.#getVisibleCount,
|
|
236
|
+
getGroupVisibleCount: this.#getGroupVisibleCount,
|
|
237
|
+
registerItem: this.#registerItem,
|
|
238
|
+
unregisterItem: this.#unregisterItem,
|
|
239
|
+
updateItem: this.#updateItem,
|
|
240
|
+
registerGroup: this.#registerGroup,
|
|
241
|
+
unregisterGroup: this.#unregisterGroup,
|
|
242
|
+
setSearch: this.#setSearch,
|
|
243
|
+
selectItem: this.#selectItem,
|
|
244
|
+
handleItemSelect: this.#handleItemSelect,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
connectedCallback() {
|
|
248
|
+
super.connectedCallback();
|
|
249
|
+
this.addEventListener("keydown", this.#handleKeyDown);
|
|
250
|
+
this._ctx = this.#buildContext();
|
|
251
|
+
}
|
|
252
|
+
disconnectedCallback() {
|
|
253
|
+
super.disconnectedCallback();
|
|
254
|
+
this.removeEventListener("keydown", this.#handleKeyDown);
|
|
255
|
+
}
|
|
256
|
+
willUpdate() {
|
|
257
|
+
this._ctx = this.#buildContext();
|
|
258
|
+
}
|
|
259
|
+
render() {
|
|
260
|
+
return html `<slot></slot>`;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
__decorate([
|
|
264
|
+
property({ type: Boolean })
|
|
265
|
+
], DuiCommand.prototype, "loop", null);
|
|
266
|
+
__decorate([
|
|
267
|
+
property({ type: Boolean, attribute: "should-filter" })
|
|
268
|
+
], DuiCommand.prototype, "shouldFilter", null);
|
|
269
|
+
__decorate([
|
|
270
|
+
property({ type: String })
|
|
271
|
+
], DuiCommand.prototype, "value", null);
|
|
272
|
+
__decorate([
|
|
273
|
+
property({ attribute: false })
|
|
274
|
+
], DuiCommand.prototype, "filter", null);
|
|
275
|
+
__decorate([
|
|
276
|
+
provide({ context: commandContext }),
|
|
277
|
+
state()
|
|
278
|
+
], DuiCommand.prototype, "_ctx", null);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { DuiCommand } from "./command.js";
|
|
2
|
+
export { DuiCommandInput } from "./command-input.js";
|
|
3
|
+
export { DuiCommandList } from "./command-list.js";
|
|
4
|
+
export { DuiCommandGroup } from "./command-group.js";
|
|
5
|
+
export { DuiCommandItem } from "./command-item.js";
|
|
6
|
+
export { DuiCommandEmpty } from "./command-empty.js";
|
|
7
|
+
export { DuiCommandSeparator } from "./command-separator.js";
|
|
8
|
+
export { DuiCommandShortcut } from "./command-shortcut.js";
|
|
9
|
+
export type { CommandContext, CommandItemEntry } from "./command-context.js";
|
|
10
|
+
export { commandScore } from "./command-score.js";
|
package/command/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DuiCommand } from "./command.js";
|
|
2
|
+
export { DuiCommandInput } from "./command-input.js";
|
|
3
|
+
export { DuiCommandList } from "./command-list.js";
|
|
4
|
+
export { DuiCommandGroup } from "./command-group.js";
|
|
5
|
+
export { DuiCommandItem } from "./command-item.js";
|
|
6
|
+
export { DuiCommandEmpty } from "./command-empty.js";
|
|
7
|
+
export { DuiCommandSeparator } from "./command-separator.js";
|
|
8
|
+
export { DuiCommandShortcut } from "./command-shortcut.js";
|
|
9
|
+
export { commandScore } from "./command-score.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DuiCommand } from "./command.js";
|
|
2
|
+
import { DuiCommandInput } from "./command-input.js";
|
|
3
|
+
import { DuiCommandList } from "./command-list.js";
|
|
4
|
+
import { DuiCommandGroup } from "./command-group.js";
|
|
5
|
+
import { DuiCommandItem } from "./command-item.js";
|
|
6
|
+
import { DuiCommandEmpty } from "./command-empty.js";
|
|
7
|
+
import { DuiCommandSeparator } from "./command-separator.js";
|
|
8
|
+
import { DuiCommandShortcut } from "./command-shortcut.js";
|
|
9
|
+
for (const C of [
|
|
10
|
+
DuiCommand,
|
|
11
|
+
DuiCommandInput,
|
|
12
|
+
DuiCommandList,
|
|
13
|
+
DuiCommandGroup,
|
|
14
|
+
DuiCommandItem,
|
|
15
|
+
DuiCommandEmpty,
|
|
16
|
+
DuiCommandSeparator,
|
|
17
|
+
DuiCommandShortcut,
|
|
18
|
+
]) {
|
|
19
|
+
if (!customElements.get(C.tagName)) {
|
|
20
|
+
customElements.define(C.tagName, C);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Ported from original DUI: deep-future-app/app/client/components/dui/data-table */
|
|
2
|
+
import { LitElement, type PropertyValues, type TemplateResult } from "lit";
|
|
3
|
+
export type ColumnDef<T> = {
|
|
4
|
+
/** Unique key identifying the column (usually a key of T). */
|
|
5
|
+
key: string;
|
|
6
|
+
/** Column header label. */
|
|
7
|
+
header: string;
|
|
8
|
+
/** Whether this column is sortable. */
|
|
9
|
+
sortable?: boolean;
|
|
10
|
+
/** Fixed column width (CSS value). */
|
|
11
|
+
width?: string;
|
|
12
|
+
/** Custom render function for cell content. */
|
|
13
|
+
render?: (value: unknown, row: T) => TemplateResult | string | number;
|
|
14
|
+
};
|
|
15
|
+
export type SortDirection = "asc" | "desc";
|
|
16
|
+
export type SortState = {
|
|
17
|
+
column: string;
|
|
18
|
+
direction: SortDirection;
|
|
19
|
+
} | null;
|
|
20
|
+
export type PageState = {
|
|
21
|
+
page: number;
|
|
22
|
+
pageSize: number;
|
|
23
|
+
totalRows: number;
|
|
24
|
+
totalPages: number;
|
|
25
|
+
};
|
|
26
|
+
export declare const sortChangeEvent: (detail: {
|
|
27
|
+
column: string;
|
|
28
|
+
direction: SortDirection;
|
|
29
|
+
}) => CustomEvent<{
|
|
30
|
+
column: string;
|
|
31
|
+
direction: SortDirection;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const pageChangeEvent: (detail: PageState) => CustomEvent<PageState>;
|
|
34
|
+
/**
|
|
35
|
+
* `<dui-data-table>` — A sortable, paginated data table.
|
|
36
|
+
*
|
|
37
|
+
* Accepts column definitions and row data, with optional sorting and
|
|
38
|
+
* pagination. Cells can be customized via column `render` functions.
|
|
39
|
+
*
|
|
40
|
+
* @fires sort-change - Fired when a sortable column header is clicked. Detail: SortState
|
|
41
|
+
* @fires page-change - Fired when the page changes. Detail: PageState
|
|
42
|
+
*/
|
|
43
|
+
export declare class DuiDataTable<T extends Record<string, unknown> = Record<string, unknown>> extends LitElement {
|
|
44
|
+
#private;
|
|
45
|
+
static tagName: "dui-data-table";
|
|
46
|
+
static styles: import("lit").CSSResult[];
|
|
47
|
+
/** Column definitions describing each visible column. */
|
|
48
|
+
accessor columns: ColumnDef<T>[];
|
|
49
|
+
/** The full data array. Sorting and pagination are applied internally. */
|
|
50
|
+
accessor data: T[];
|
|
51
|
+
/** Number of rows per page. Set to 0 to disable pagination. */
|
|
52
|
+
accessor pageSize: number;
|
|
53
|
+
/** Key function to derive a unique identifier from each row. */
|
|
54
|
+
accessor rowKey: ((row: T) => string) | undefined;
|
|
55
|
+
/** Text shown when the data array is empty. */
|
|
56
|
+
accessor emptyText: string;
|
|
57
|
+
willUpdate(changed: PropertyValues): void;
|
|
58
|
+
render(): TemplateResult;
|
|
59
|
+
}
|