@pritzlaff/nano-elements 0.2.0 → 0.5.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/README.md +4 -15
- package/attrs.d.ts +1 -0
- package/index.d.ts +1 -3
- package/index.js +301 -152
- package/index.js.map +8 -7
- package/kit/data-table.d.ts +18 -0
- package/kit/tree-styles.d.ts +1 -0
- package/kit/tree.d.ts +54 -0
- package/package.json +3 -3
- package/catalog.d.ts +0 -9
- package/model-element.d.ts +0 -31
- package/placed-element.d.ts +0 -17
package/index.js
CHANGED
|
@@ -1,106 +1,3 @@
|
|
|
1
|
-
// packages/elements/src/model-element.ts
|
|
2
|
-
import { LitElement } from "lit";
|
|
3
|
-
import { Type } from "typebox";
|
|
4
|
-
import { Components, Ops } from "@pritzlaff/nano-core";
|
|
5
|
-
var n = 0;
|
|
6
|
-
|
|
7
|
-
class ModelElement extends LitElement {
|
|
8
|
-
static properties = { registry: { attribute: false }, model: {}, watch: { attribute: false }, problem: { state: true } };
|
|
9
|
-
#values = new Map;
|
|
10
|
-
#view;
|
|
11
|
-
connectedCallback() {
|
|
12
|
-
super.connectedCallback();
|
|
13
|
-
if (this.hasUpdated)
|
|
14
|
-
this.#attach();
|
|
15
|
-
}
|
|
16
|
-
disconnectedCallback() {
|
|
17
|
-
super.disconnectedCallback();
|
|
18
|
-
this.#detach();
|
|
19
|
-
}
|
|
20
|
-
willUpdate(changed) {
|
|
21
|
-
if (changed.has("registry") || changed.has("model") || changed.has("watch")) {
|
|
22
|
-
this.#detach();
|
|
23
|
-
this.#attach();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
read(op) {
|
|
27
|
-
return this.#values.get(Ops.key(op));
|
|
28
|
-
}
|
|
29
|
-
async act(op, arg = null) {
|
|
30
|
-
if (!this.#view || !this.model)
|
|
31
|
-
return { error: "not attached to a model" };
|
|
32
|
-
const r = await this.#view.handle.call(this.model, op, arg);
|
|
33
|
-
this.problem = "error" in r ? r.error : undefined;
|
|
34
|
-
return r;
|
|
35
|
-
}
|
|
36
|
-
#attach() {
|
|
37
|
-
const reg = this.registry;
|
|
38
|
-
if (!reg || !this.model || !reg.get(this.model) || this.#view || !this.isConnected)
|
|
39
|
-
return;
|
|
40
|
-
const sources = [this.model, ...this.watch ?? []].flatMap((i) => [...reg.get(i)?.actions.values() ?? []].filter((a) => a.op.output && !a.op.input).map((a) => [i, a]));
|
|
41
|
-
const id = `${this.model}~view-${n++}`;
|
|
42
|
-
const view = Components.create({ ns: "composable.editor", name: "view" }, () => this);
|
|
43
|
-
for (const [, a] of sources) {
|
|
44
|
-
const key = Ops.key(a.op);
|
|
45
|
-
view.action(Ops.sink("composable.editor/view", key, Type.Unknown()), (el, data) => {
|
|
46
|
-
el.#values.set(key, data);
|
|
47
|
-
el.requestUpdate();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
reg.add(id, Components.instantiate(view));
|
|
51
|
-
for (const [i, a] of sources)
|
|
52
|
-
reg.subscribe({ source: i, op: Ops.key(a.op), listener: id, target: `composable.editor/view/${Ops.key(a.op)}` });
|
|
53
|
-
this.#view = { id, handle: reg.get(id).env.handles()[0], registry: reg };
|
|
54
|
-
for (const [i, a] of sources)
|
|
55
|
-
if (a.run)
|
|
56
|
-
this.#view.handle.call(i, a.op, null).then((r) => {
|
|
57
|
-
if ("value" in r && this.#view?.id === id) {
|
|
58
|
-
this.#values.set(Ops.key(a.op), r.value);
|
|
59
|
-
this.requestUpdate();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
#detach() {
|
|
64
|
-
this.#view?.registry.remove(this.#view.id);
|
|
65
|
-
this.#view = undefined;
|
|
66
|
-
this.#values.clear();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// packages/elements/src/placed-element.ts
|
|
70
|
-
import { Components as Components2 } from "@pritzlaff/nano-core";
|
|
71
|
-
var provided = new WeakMap;
|
|
72
|
-
var n2 = 0;
|
|
73
|
-
var provide = (doc, registry) => {
|
|
74
|
-
provided.set(doc, registry);
|
|
75
|
-
};
|
|
76
|
-
var providedRegistry = (doc) => provided.get(doc);
|
|
77
|
-
|
|
78
|
-
class PlacedElement extends ModelElement {
|
|
79
|
-
static component;
|
|
80
|
-
#mine;
|
|
81
|
-
connectedCallback() {
|
|
82
|
-
this.registry ??= providedRegistry(this.ownerDocument);
|
|
83
|
-
this.model ??= this.getAttribute("name") ?? `${this.localName}-${n2++}`;
|
|
84
|
-
const reg = this.registry;
|
|
85
|
-
if (reg && !reg.get(this.model)) {
|
|
86
|
-
const inst = Components2.instantiate(this.constructor.component);
|
|
87
|
-
if (!("error" in reg.add(this.model, inst)))
|
|
88
|
-
this.#mine = { id: this.model, inst, registry: reg };
|
|
89
|
-
}
|
|
90
|
-
super.connectedCallback();
|
|
91
|
-
}
|
|
92
|
-
disconnectedCallback() {
|
|
93
|
-
super.disconnectedCallback();
|
|
94
|
-
queueMicrotask(() => {
|
|
95
|
-
const mine = this.#mine;
|
|
96
|
-
if (this.isConnected || !mine || this.hasAttribute("keep"))
|
|
97
|
-
return;
|
|
98
|
-
if (mine.registry.get(mine.id) === mine.inst)
|
|
99
|
-
mine.registry.remove(mine.id);
|
|
100
|
-
this.#mine = undefined;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
1
|
// packages/elements/src/styles.ts
|
|
105
2
|
import { css } from "lit";
|
|
106
3
|
|
|
@@ -273,7 +170,7 @@ var kit = css2`
|
|
|
273
170
|
.toast.good { border-left: 3px solid ${t("good")} } .toast.bad { border-left: 3px solid ${t("bad")} } .toast.warn { border-left: 3px solid ${t("warn")} }
|
|
274
171
|
`;
|
|
275
172
|
// packages/elements/src/kit/select.ts
|
|
276
|
-
import { LitElement
|
|
173
|
+
import { LitElement, css as css3, html, nothing } from "lit";
|
|
277
174
|
|
|
278
175
|
// packages/elements/src/kit/popup.ts
|
|
279
176
|
function place(pop, anchor, at) {
|
|
@@ -297,8 +194,8 @@ var labelOf = (i) => i.label ?? i.value;
|
|
|
297
194
|
var CHECK = html`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3 8.5l3 3 7-7" fill="none" stroke="currentColor" stroke-width="2"/></svg>`;
|
|
298
195
|
var ids = 0;
|
|
299
196
|
|
|
300
|
-
class NanoCommand extends
|
|
301
|
-
static shadowRootOptions = { ...
|
|
197
|
+
class NanoCommand extends LitElement {
|
|
198
|
+
static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
302
199
|
static properties = { items: { attribute: false }, selected: { attribute: false }, placeholder: {}, q: { state: true }, active: { state: true } };
|
|
303
200
|
static styles = [base, kit, css3`
|
|
304
201
|
:host { display: block; min-width: 220px }
|
|
@@ -330,11 +227,11 @@ class NanoCommand extends LitElement2 {
|
|
|
330
227
|
this.dispatchEvent(new CustomEvent("pick", { detail: i, bubbles: true, composed: true }));
|
|
331
228
|
}
|
|
332
229
|
onKey(e) {
|
|
333
|
-
const
|
|
230
|
+
const n = this.shown.length;
|
|
334
231
|
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
335
232
|
e.preventDefault();
|
|
336
|
-
if (
|
|
337
|
-
this.active = (this.active + (e.key === "ArrowDown" ? 1 : -1) +
|
|
233
|
+
if (n)
|
|
234
|
+
this.active = (this.active + (e.key === "ArrowDown" ? 1 : -1) + n) % n;
|
|
338
235
|
} else if (e.key === "Enter") {
|
|
339
236
|
e.preventDefault();
|
|
340
237
|
this.pick(this.shown[this.active]);
|
|
@@ -354,20 +251,20 @@ class NanoCommand extends LitElement2 {
|
|
|
354
251
|
this.active = 0;
|
|
355
252
|
}} @keydown=${this.onKey}></div>
|
|
356
253
|
<div role="listbox" id=${`${this.uid}-list`} aria-multiselectable=${this.selected.length > 1 ? "true" : nothing}>
|
|
357
|
-
${shown.length ? shown.map((i,
|
|
254
|
+
${shown.length ? shown.map((i, n) => {
|
|
358
255
|
const head = i.group && i.group !== group ? html`<div class="menu-label" role="presentation">${i.group}</div>` : nothing;
|
|
359
256
|
group = i.group;
|
|
360
|
-
return html`${head}<div role="option" id=${`${this.uid}-${
|
|
257
|
+
return html`${head}<div role="option" id=${`${this.uid}-${n}`} data-value=${i.value} class="menu-item ${n === this.active ? "active" : ""}"
|
|
361
258
|
aria-selected=${String(this.selected.includes(i.value))} aria-disabled=${i.disabled ? "true" : nothing}
|
|
362
259
|
@pointermove=${() => {
|
|
363
|
-
this.active =
|
|
260
|
+
this.active = n;
|
|
364
261
|
}} @click=${() => this.pick(i)}>
|
|
365
262
|
<span class="check">${this.selected.includes(i.value) ? CHECK : nothing}</span>${labelOf(i)}${i.shortcut ? html`<span class="shortcut">${i.shortcut}</span>` : nothing}</div>`;
|
|
366
263
|
}) : html`<div class="empty">No results.</div>`}</div>`;
|
|
367
264
|
}
|
|
368
265
|
}
|
|
369
266
|
|
|
370
|
-
class NanoSelect extends
|
|
267
|
+
class NanoSelect extends LitElement {
|
|
371
268
|
static properties = { options: { attribute: false }, value: { attribute: false }, multiple: { type: Boolean }, placeholder: {}, label: {}, open: { state: true } };
|
|
372
269
|
static styles = [base, kit, css3`
|
|
373
270
|
:host { display: inline-block; min-width: 180px }
|
|
@@ -456,22 +353,22 @@ for (const [tag, cls] of [["nano-command", NanoCommand], ["nano-select", NanoSel
|
|
|
456
353
|
if (globalThis.customElements && !customElements.get(tag))
|
|
457
354
|
customElements.define(tag, cls);
|
|
458
355
|
// packages/elements/src/kit/calendar.ts
|
|
459
|
-
import { LitElement as
|
|
460
|
-
var pad = (
|
|
356
|
+
import { LitElement as LitElement2, css as css4, html as html2, nothing as nothing2 } from "lit";
|
|
357
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
461
358
|
var iso = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
462
359
|
var parse = (s) => {
|
|
463
360
|
const [y, m, d] = s.split("-").map(Number);
|
|
464
361
|
return y && m && d ? new Date(y, m - 1, d) : undefined;
|
|
465
362
|
};
|
|
466
|
-
var addDays = (s,
|
|
363
|
+
var addDays = (s, n) => {
|
|
467
364
|
const d = parse(s);
|
|
468
|
-
d.setDate(d.getDate() +
|
|
365
|
+
d.setDate(d.getDate() + n);
|
|
469
366
|
return iso(d);
|
|
470
367
|
};
|
|
471
368
|
var DOW = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
472
369
|
var chevron = (d) => html2`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d=${d} fill="none" stroke="currentColor" stroke-width="1.5"/></svg>`;
|
|
473
370
|
|
|
474
|
-
class NanoCalendar extends
|
|
371
|
+
class NanoCalendar extends LitElement2 {
|
|
475
372
|
static properties = { value: {}, view: { state: true }, focusDate: { state: true } };
|
|
476
373
|
static styles = [base, kit, css4`
|
|
477
374
|
:host { display: inline-block; padding: 8px }
|
|
@@ -495,8 +392,8 @@ class NanoCalendar extends LitElement3 {
|
|
|
495
392
|
this.focusDate = this.value;
|
|
496
393
|
}
|
|
497
394
|
}
|
|
498
|
-
shift(
|
|
499
|
-
const d = new Date(this.view.y, this.view.m +
|
|
395
|
+
shift(n) {
|
|
396
|
+
const d = new Date(this.view.y, this.view.m + n, 1);
|
|
500
397
|
this.view = { y: d.getFullYear(), m: d.getMonth() };
|
|
501
398
|
this.focusDate = iso(d);
|
|
502
399
|
}
|
|
@@ -543,7 +440,7 @@ class NanoCalendar extends LitElement3 {
|
|
|
543
440
|
}
|
|
544
441
|
}
|
|
545
442
|
|
|
546
|
-
class NanoDatePicker extends
|
|
443
|
+
class NanoDatePicker extends LitElement2 {
|
|
547
444
|
static properties = { value: {}, placeholder: {}, open: { state: true } };
|
|
548
445
|
static styles = [base, kit, css4`
|
|
549
446
|
:host { display: inline-block } .trigger { min-width: 200px; justify-content: flex-start; background: ${t("bg")} }
|
|
@@ -597,7 +494,7 @@ for (const [tag, cls] of [["nano-calendar", NanoCalendar], ["nano-date-picker",
|
|
|
597
494
|
if (globalThis.customElements && !customElements.get(tag))
|
|
598
495
|
customElements.define(tag, cls);
|
|
599
496
|
// packages/elements/src/kit/overlays.ts
|
|
600
|
-
import { LitElement as
|
|
497
|
+
import { LitElement as LitElement3, css as css5, html as html3, nothing as nothing3 } from "lit";
|
|
601
498
|
var pickable = (i) => ("label" in i) && !i.disabled;
|
|
602
499
|
var menus = 0;
|
|
603
500
|
var define = (tag, cls) => {
|
|
@@ -605,7 +502,7 @@ var define = (tag, cls) => {
|
|
|
605
502
|
customElements.define(tag, cls);
|
|
606
503
|
};
|
|
607
504
|
|
|
608
|
-
class NanoMenu extends
|
|
505
|
+
class NanoMenu extends LitElement3 {
|
|
609
506
|
static properties = { items: { attribute: false }, open: { type: Boolean, reflect: true }, active: { state: true } };
|
|
610
507
|
static styles = [base, kit, css5`:host { display: contents } [role='menu'] { outline: 0; min-width: 12rem }`];
|
|
611
508
|
constructor() {
|
|
@@ -643,8 +540,8 @@ class NanoMenu extends LitElement4 {
|
|
|
643
540
|
const step = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
|
|
644
541
|
if (step) {
|
|
645
542
|
e.preventDefault();
|
|
646
|
-
for (let
|
|
647
|
-
const i = (this.active + step *
|
|
543
|
+
for (let n = 1, len = this.items.length;n <= len; n++) {
|
|
544
|
+
const i = (this.active + step * n + len) % len;
|
|
648
545
|
if (pickable(this.items[i])) {
|
|
649
546
|
this.active = i;
|
|
650
547
|
break;
|
|
@@ -664,15 +561,15 @@ class NanoMenu extends LitElement4 {
|
|
|
664
561
|
if (e.newState === "closed")
|
|
665
562
|
this.open = false;
|
|
666
563
|
}}>
|
|
667
|
-
${this.items.map((i,
|
|
564
|
+
${this.items.map((i, n) => ("separator" in i) ? html3`<div class="menu-sep" role="separator"></div>` : ("heading" in i) ? html3`<div class="menu-label">${i.heading}</div>` : html3`<div role="menuitem" id=${`${this.uid}-${n}`} class="menu-item ${i.danger ? "danger" : ""} ${n === this.active ? "active" : ""}" aria-disabled=${i.disabled ? "true" : nothing3}
|
|
668
565
|
@pointermove=${() => {
|
|
669
566
|
if (!i.disabled)
|
|
670
|
-
this.active =
|
|
567
|
+
this.active = n;
|
|
671
568
|
}} @click=${() => this.pick(i)}>${i.label}${i.shortcut ? html3`<span class="shortcut">${i.shortcut}</span>` : nothing3}</div>`)}</div>`;
|
|
672
569
|
}
|
|
673
570
|
}
|
|
674
571
|
|
|
675
|
-
class NanoHoverCard extends
|
|
572
|
+
class NanoHoverCard extends LitElement3 {
|
|
676
573
|
static properties = { open: { type: Boolean, reflect: true }, openDelay: { type: Number, attribute: "open-delay" }, closeDelay: { type: Number, attribute: "close-delay" } };
|
|
677
574
|
static styles = [base, kit, css5`:host { display: inline-block } .pop { width: 280px; padding: 14px }`];
|
|
678
575
|
timer;
|
|
@@ -706,7 +603,7 @@ class NanoHoverCard extends LitElement4 {
|
|
|
706
603
|
}
|
|
707
604
|
var toastIds = 0;
|
|
708
605
|
|
|
709
|
-
class NanoToaster extends
|
|
606
|
+
class NanoToaster extends LitElement3 {
|
|
710
607
|
static properties = { toasts: { state: true } };
|
|
711
608
|
static styles = [base, kit, css5`:host { position: fixed; right: 16px; bottom: 16px; z-index: 1000 } ol { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none }`];
|
|
712
609
|
constructor() {
|
|
@@ -734,7 +631,7 @@ function toast(title, opts = {}) {
|
|
|
734
631
|
return id;
|
|
735
632
|
}
|
|
736
633
|
|
|
737
|
-
class NanoCodeBlock extends
|
|
634
|
+
class NanoCodeBlock extends LitElement3 {
|
|
738
635
|
static properties = { code: {}, language: {}, copied: { state: true } };
|
|
739
636
|
static styles = [base, kit, css5`
|
|
740
637
|
.frame { position: relative } .bar { position: absolute; top: 4px; right: 4px; display: flex; align-items: center; gap: 6px }
|
|
@@ -762,17 +659,37 @@ define("nano-hover-card", NanoHoverCard);
|
|
|
762
659
|
define("nano-toaster", NanoToaster);
|
|
763
660
|
define("nano-code-block", NanoCodeBlock);
|
|
764
661
|
// packages/elements/src/kit/data-table.ts
|
|
765
|
-
import { LitElement as
|
|
662
|
+
import { LitElement as LitElement4, css as css6, html as html4, nothing as nothing4 } from "lit";
|
|
663
|
+
import { ref } from "lit/directives/ref.js";
|
|
664
|
+
|
|
665
|
+
// packages/elements/src/attrs.ts
|
|
666
|
+
var was = new WeakMap;
|
|
667
|
+
function setAttrs(el, all = {}) {
|
|
668
|
+
if (!el)
|
|
669
|
+
return;
|
|
670
|
+
const attrs = Object.fromEntries(Object.entries(all).filter(([k]) => /^[a-z][a-z0-9-]*$/.test(k)));
|
|
671
|
+
for (const k of was.get(el) ?? [])
|
|
672
|
+
if (!(k in attrs))
|
|
673
|
+
el.removeAttribute(k);
|
|
674
|
+
for (const [k, v] of Object.entries(attrs))
|
|
675
|
+
v === undefined ? el.removeAttribute(k) : el.setAttribute(k, v);
|
|
676
|
+
was.set(el, Object.keys(attrs));
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// packages/elements/src/kit/data-table.ts
|
|
680
|
+
var STEP = 10;
|
|
766
681
|
var cell = (r, k) => String(r[k] ?? "");
|
|
767
682
|
var compare = (a, b) => typeof a === "number" && typeof b === "number" ? a - b : String(a ?? "").localeCompare(String(b ?? ""), undefined, { numeric: true });
|
|
768
683
|
|
|
769
|
-
class NanoDataTable extends
|
|
684
|
+
class NanoDataTable extends LitElement4 {
|
|
770
685
|
static properties = {
|
|
771
686
|
columns: { attribute: false },
|
|
687
|
+
rowAttrs: { attribute: false },
|
|
772
688
|
rows: { attribute: false },
|
|
773
689
|
filter: { type: Boolean },
|
|
774
690
|
selectable: { type: Boolean },
|
|
775
691
|
pageSize: { type: Number, attribute: "page-size" },
|
|
692
|
+
widths: { state: true },
|
|
776
693
|
q: { state: true },
|
|
777
694
|
sort: { state: true },
|
|
778
695
|
page: { state: true },
|
|
@@ -781,9 +698,12 @@ class NanoDataTable extends LitElement5 {
|
|
|
781
698
|
static styles = [base, kit, css6`
|
|
782
699
|
.frame { border: 1px solid ${t("border")}; border-radius: ${t("radius")}; overflow: auto }
|
|
783
700
|
.table { margin: 0 } .table tr:last-child td { border-bottom: 0 } .table tbody tr:hover { background: ${t("surface-2")} }
|
|
784
|
-
.table tr[aria-selected='true'] { background: ${t("surface-2")} } .table .right { text-align: right } .table .tick { width: 28px }
|
|
701
|
+
.table tr[data-mark] { background: ${t("warn-bg")}; box-shadow: inset 3px 0 ${t("warn")} } .table tr[aria-selected='true'] { background: ${t("surface-2")} } .table .right { text-align: right } .table .tick { width: 28px }
|
|
785
702
|
th button { border: 0; padding: 0; background: none; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit }
|
|
786
703
|
.filter { width: min(280px, 100%); margin-bottom: 10px } .empty { text-align: center; padding: 24px; color: ${t("muted")} }
|
|
704
|
+
th { position: relative } .fixed { table-layout: fixed } .fixed td, .fixed th { overflow: hidden; text-overflow: ellipsis }
|
|
705
|
+
.resize { position: absolute; top: 0; right: 0; bottom: 0; width: 6px; cursor: col-resize; touch-action: none }
|
|
706
|
+
.resize:hover, .resize:focus-visible { background: ${t("border")}; outline: none }
|
|
787
707
|
.foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; color: ${t("muted")}; font-size: 12px }`];
|
|
788
708
|
constructor() {
|
|
789
709
|
super();
|
|
@@ -792,6 +712,7 @@ class NanoDataTable extends LitElement5 {
|
|
|
792
712
|
this.filter = false;
|
|
793
713
|
this.selectable = false;
|
|
794
714
|
this.pageSize = 0;
|
|
715
|
+
this.widths = {};
|
|
795
716
|
this.q = "";
|
|
796
717
|
this.page = 0;
|
|
797
718
|
this.picked = new Set;
|
|
@@ -802,6 +723,50 @@ class NanoDataTable extends LitElement5 {
|
|
|
802
723
|
const s = this.sort;
|
|
803
724
|
return s ? rows.sort((a, b) => compare(a[s.key], b[s.key]) * s.dir) : rows;
|
|
804
725
|
}
|
|
726
|
+
measured = {};
|
|
727
|
+
updated() {
|
|
728
|
+
if (this.isFixed())
|
|
729
|
+
return;
|
|
730
|
+
let moved = false;
|
|
731
|
+
for (const c of this.columns) {
|
|
732
|
+
const w = this.renderRoot.querySelector(`th[data-key="${c.key}"]`)?.offsetWidth || 120;
|
|
733
|
+
if (this.measured[c.key] !== w) {
|
|
734
|
+
this.measured[c.key] = w;
|
|
735
|
+
moved = true;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (moved)
|
|
739
|
+
this.requestUpdate();
|
|
740
|
+
}
|
|
741
|
+
isFixed() {
|
|
742
|
+
return this.columns.some((c) => (this.widths[c.key] ?? c.width) !== undefined);
|
|
743
|
+
}
|
|
744
|
+
widthOf(c) {
|
|
745
|
+
return this.widths[c.key] ?? c.width ?? this.measured[c.key] ?? 120;
|
|
746
|
+
}
|
|
747
|
+
resize(c, px) {
|
|
748
|
+
const all = this.isFixed() ? this.widths : Object.fromEntries(this.columns.map((x) => [x.key, this.widthOf(x)]));
|
|
749
|
+
this.widths = { ...all, [c.key]: Math.max(c.minWidth ?? 60, Math.round(px)) };
|
|
750
|
+
}
|
|
751
|
+
drag(c, e) {
|
|
752
|
+
e.preventDefault();
|
|
753
|
+
e.stopPropagation();
|
|
754
|
+
const x0 = e.clientX, w0 = this.widthOf(c);
|
|
755
|
+
const move = (m) => this.resize(c, w0 + m.clientX - x0);
|
|
756
|
+
const up = () => {
|
|
757
|
+
removeEventListener("pointermove", move);
|
|
758
|
+
removeEventListener("pointerup", up);
|
|
759
|
+
};
|
|
760
|
+
addEventListener("pointermove", move);
|
|
761
|
+
addEventListener("pointerup", up);
|
|
762
|
+
}
|
|
763
|
+
nudge(c, e) {
|
|
764
|
+
const d = e.key === "ArrowRight" ? STEP : e.key === "ArrowLeft" ? -STEP : 0;
|
|
765
|
+
if (d) {
|
|
766
|
+
e.preventDefault();
|
|
767
|
+
this.resize(c, this.widthOf(c) + d);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
805
770
|
sortBy(key) {
|
|
806
771
|
this.sort = this.sort?.key === key && this.sort.dir === 1 ? { key, dir: -1 } : { key, dir: 1 };
|
|
807
772
|
}
|
|
@@ -815,20 +780,26 @@ class NanoDataTable extends LitElement5 {
|
|
|
815
780
|
render() {
|
|
816
781
|
const all = this.shown, size = this.pageSize || all.length || 1, pages = Math.max(1, Math.ceil(all.length / size));
|
|
817
782
|
const page = Math.min(this.page, pages - 1), rows = all.slice(page * size, page * size + size);
|
|
783
|
+
const fixed = this.isFixed();
|
|
784
|
+
const total = this.columns.reduce((n, c) => n + this.widthOf(c), this.selectable ? 28 : 0);
|
|
818
785
|
const allPicked = rows.length > 0 && rows.every((r) => this.picked.has(r));
|
|
819
786
|
const head = (c) => {
|
|
820
787
|
const sorted = this.sort?.key === c.key ? this.sort.dir === 1 ? "ascending" : "descending" : undefined;
|
|
821
|
-
return html4`<th data-key=${c.key} class=${c.align ?? ""} aria-sort=${c.sortable ? sorted ?? "none" : nothing4}>${c.sortable ? html4`<button @click=${() => this.sortBy(c.key)}>${c.label} ${sorted === "ascending" ? "↑" : sorted === "descending" ? "↓" : "↕"}</button>` : c.label}
|
|
788
|
+
return html4`<th data-key=${c.key} class=${c.align ?? ""} aria-sort=${c.sortable ? sorted ?? "none" : nothing4}>${c.sortable ? html4`<button @click=${() => this.sortBy(c.key)}>${c.label} ${sorted === "ascending" ? "↑" : sorted === "descending" ? "↓" : "↕"}</button>` : c.label}<span
|
|
789
|
+
class="resize" role="separator" aria-orientation="vertical" tabindex="0" aria-label="Resize ${c.label}" aria-valuemin=${c.minWidth ?? 60}
|
|
790
|
+
aria-valuenow=${this.widthOf(c)} @pointerdown=${(e) => this.drag(c, e)} @keydown=${(e) => this.nudge(c, e)}
|
|
791
|
+
@click=${(e) => e.stopPropagation()}></span></th>`;
|
|
822
792
|
};
|
|
823
793
|
return html4`${this.filter ? html4`<input class="input filter" placeholder="Filter…" aria-label="Filter rows" .value=${this.q}
|
|
824
794
|
@input=${(e) => {
|
|
825
795
|
this.q = e.target.value;
|
|
826
796
|
this.page = 0;
|
|
827
797
|
}}>` : nothing4}
|
|
828
|
-
<div class="frame"><table class="table"
|
|
798
|
+
<div class="frame"><table class="table ${fixed ? "fixed" : ""}" style=${fixed ? `width: ${total}px` : ""}>${fixed ? html4`<colgroup>${this.selectable ? html4`<col style="width: 28px">` : nothing4}
|
|
799
|
+
${this.columns.map((c) => html4`<col style="width: ${this.widthOf(c)}px">`)}</colgroup>` : nothing4}<thead><tr>
|
|
829
800
|
${this.selectable ? html4`<th class="tick"><input type="checkbox" aria-label="Select all" .checked=${allPicked} @click=${() => this.pick(rows, !allPicked)}></th>` : nothing4}
|
|
830
801
|
${this.columns.map(head)}</tr></thead><tbody>
|
|
831
|
-
${rows.length ? rows.map((r) => html4`<tr aria-selected=${this.selectable ? String(this.picked.has(r)) : nothing4}>
|
|
802
|
+
${rows.length ? rows.map((r) => html4`<tr aria-selected=${this.selectable ? String(this.picked.has(r)) : nothing4} ${ref((el) => setAttrs(el, this.rowAttrs?.(r)))}>
|
|
832
803
|
${this.selectable ? html4`<td class="tick"><input type="checkbox" aria-label="Select row" .checked=${this.picked.has(r)} @click=${() => this.pick([r], !this.picked.has(r))}></td>` : nothing4}
|
|
833
804
|
${this.columns.map((c) => html4`<td data-key=${c.key} class=${c.align ?? ""}>${c.render ? c.render(r) : cell(r, c.key)}</td>`)}</tr>`) : html4`<tr><td class="empty" colspan=${this.columns.length + (this.selectable ? 1 : 0)}>No results.</td></tr>`}</tbody></table></div>
|
|
834
805
|
${this.selectable || this.pageSize ? html4`<div class="foot"><span>${this.selectable ? `${this.picked.size} of ${this.rows.length} row(s) selected.` : ""}</span>
|
|
@@ -844,7 +815,7 @@ class NanoDataTable extends LitElement5 {
|
|
|
844
815
|
if (globalThis.customElements && !customElements.get("nano-data-table"))
|
|
845
816
|
customElements.define("nano-data-table", NanoDataTable);
|
|
846
817
|
// packages/elements/src/agent/parts.ts
|
|
847
|
-
import { LitElement as
|
|
818
|
+
import { LitElement as LitElement5, css as css7, html as html5, nothing as nothing5 } from "lit";
|
|
848
819
|
var json = (v) => typeof v === "string" ? v : JSON.stringify(v, null, 2);
|
|
849
820
|
var STATE = { "input-streaming": ["Pending", ""], "input-available": ["Running", "accent"], "output-available": ["Completed", "good"], "output-error": ["Error", "bad"] };
|
|
850
821
|
var AGENT = { running: ["Running", "accent"], completed: ["Completed", "good"], error: ["Error", "bad"] };
|
|
@@ -860,7 +831,7 @@ var agentStyles = css7`
|
|
|
860
831
|
details.card > summary .badge { margin-left: auto } .body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px }
|
|
861
832
|
.name { font-weight: 600 } .kicker { margin-bottom: 4px } .code { max-height: 220px }`;
|
|
862
833
|
|
|
863
|
-
class NanoTool extends
|
|
834
|
+
class NanoTool extends LitElement5 {
|
|
864
835
|
static properties = { tool: { attribute: false } };
|
|
865
836
|
static styles = [base, kit, agentStyles];
|
|
866
837
|
render() {
|
|
@@ -878,7 +849,7 @@ class NanoTool extends LitElement6 {
|
|
|
878
849
|
}
|
|
879
850
|
}
|
|
880
851
|
|
|
881
|
-
class NanoTask extends
|
|
852
|
+
class NanoTask extends LitElement5 {
|
|
882
853
|
static properties = { task: { attribute: false } };
|
|
883
854
|
static styles = [base, kit, agentStyles, css7`
|
|
884
855
|
ul { list-style: none; margin: 0; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 6px }
|
|
@@ -896,7 +867,7 @@ class NanoTask extends LitElement6 {
|
|
|
896
867
|
}
|
|
897
868
|
}
|
|
898
869
|
|
|
899
|
-
class NanoSubagent extends
|
|
870
|
+
class NanoSubagent extends LitElement5 {
|
|
900
871
|
static properties = { agent: { attribute: false } };
|
|
901
872
|
static styles = [base, kit, agentStyles, css7`.desc { color: ${t("muted")}; font-size: 12px } .body { border-left: 2px solid ${t("border")}; margin-left: 18px; padding-left: 12px }`];
|
|
902
873
|
render() {
|
|
@@ -911,7 +882,7 @@ class NanoSubagent extends LitElement6 {
|
|
|
911
882
|
}
|
|
912
883
|
}
|
|
913
884
|
|
|
914
|
-
class NanoCli extends
|
|
885
|
+
class NanoCli extends LitElement5 {
|
|
915
886
|
static properties = { runs: { attribute: false } };
|
|
916
887
|
static styles = [base, kit, css7`
|
|
917
888
|
.term { font: 12px/1.6 ${t("font-mono")}; background: ${t("surface-2")}; border: 1px solid ${t("border")}; border-radius: ${t("radius")}; padding: 10px 12px; overflow: auto }
|
|
@@ -933,9 +904,9 @@ define2("nano-task", NanoTask);
|
|
|
933
904
|
define2("nano-subagent", NanoSubagent);
|
|
934
905
|
define2("nano-cli", NanoCli);
|
|
935
906
|
// packages/elements/src/agent/timeline.ts
|
|
936
|
-
import { LitElement as
|
|
937
|
-
var ms = (
|
|
938
|
-
var pct = (
|
|
907
|
+
import { LitElement as LitElement6, css as css8, html as html6, nothing as nothing6 } from "lit";
|
|
908
|
+
var ms = (n) => n < 1000 ? `${Math.round(n)}ms` : `${(n / 1000).toFixed(2)}s`;
|
|
909
|
+
var pct = (n) => `${+n.toFixed(2)}%`;
|
|
939
910
|
var ordered = (spans) => {
|
|
940
911
|
const ids2 = new Set(spans.map((s) => s.spanId)), out = [];
|
|
941
912
|
const walk = (parent, depth) => spans.filter((s) => parent === undefined ? !s.parentSpanId || !ids2.has(s.parentSpanId) : s.parentSpanId === parent).sort((a, b) => a.startTime - b.startTime).forEach((s) => {
|
|
@@ -946,7 +917,7 @@ var ordered = (spans) => {
|
|
|
946
917
|
return out;
|
|
947
918
|
};
|
|
948
919
|
|
|
949
|
-
class NanoTrace extends
|
|
920
|
+
class NanoTrace extends LitElement6 {
|
|
950
921
|
static properties = { spans: { attribute: false } };
|
|
951
922
|
static styles = [base, kit, css8`
|
|
952
923
|
.frame { border: 1px solid ${t("border")}; border-radius: ${t("radius")}; padding: 8px 0 }
|
|
@@ -972,7 +943,7 @@ class NanoTrace extends LitElement7 {
|
|
|
972
943
|
}
|
|
973
944
|
var MARK = { passed: "✓", failed: "✕", skipped: "–" };
|
|
974
945
|
|
|
975
|
-
class NanoTestResults extends
|
|
946
|
+
class NanoTestResults extends LitElement6 {
|
|
976
947
|
static properties = { results: { attribute: false } };
|
|
977
948
|
static styles = [base, kit, agentStyles, css8`
|
|
978
949
|
.summary { display: flex; align-items: center; gap: 8px; margin-bottom: 8px } .dur { margin-left: auto; color: ${t("muted")}; font: 11px ${t("font-mono")} }
|
|
@@ -1003,15 +974,194 @@ class NanoTestResults extends LitElement7 {
|
|
|
1003
974
|
for (const [tag, cls] of [["nano-trace", NanoTrace], ["nano-test-results", NanoTestResults]])
|
|
1004
975
|
if (globalThis.customElements && !customElements.get(tag))
|
|
1005
976
|
customElements.define(tag, cls);
|
|
977
|
+
// packages/elements/src/kit/tree.ts
|
|
978
|
+
import { LitElement as LitElement7, html as html7, nothing as nothing7 } from "lit";
|
|
979
|
+
import { ref as ref2 } from "lit/directives/ref.js";
|
|
980
|
+
|
|
981
|
+
// packages/elements/src/kit/tree-styles.ts
|
|
982
|
+
import { css as css9 } from "lit";
|
|
983
|
+
var treeStyles = css9`
|
|
984
|
+
:host { display: block } ul { list-style: none; margin: 0; padding: 0 }
|
|
985
|
+
ul.group { margin-left: 15px; padding-left: 8px; border-left: 1px solid ${t("border")} }
|
|
986
|
+
li[role='treeitem'] { outline: 0 } li[role='treeitem']:focus-visible > .line { outline: 2px solid ${t("focus")}; outline-offset: -2px }
|
|
987
|
+
.line { display: flex; align-items: center; gap: 6px; padding: 5px 8px; margin: 1px 0; border-radius: ${t("radius-s")}; cursor: pointer; min-width: 0 }
|
|
988
|
+
.line:hover { background: ${t("surface-2")} } li[aria-selected='true'] > .line { background: ${t("accent-soft")} }
|
|
989
|
+
.chev { flex: none; width: 16px; cursor: pointer; text-align: center; color: ${t("muted")}; transition: transform .15s; user-select: none }
|
|
990
|
+
li[data-mark] > .line { background: ${t("warn-bg")}; box-shadow: inset 3px 0 ${t("warn")} } li[data-mark][aria-selected='true'] > .line { background: ${t("accent-soft")} }
|
|
991
|
+
li[aria-expanded='true'] > .line .chev { transform: rotate(90deg) }
|
|
992
|
+
.label { overflow-wrap: anywhere } .kind { color: ${t("muted")}; font-size: 11px; letter-spacing: .06em; text-transform: uppercase }
|
|
993
|
+
.count { color: ${t("muted")}; font-size: 11px; font-variant-numeric: tabular-nums }
|
|
994
|
+
.tag { font-size: 11px; padding: 2px 7px; border-radius: ${t("radius-s")}; background: ${t("accent-soft")}; white-space: nowrap }
|
|
995
|
+
.icon { flex: none; display: inline-flex; align-items: center; gap: 4px } .end { margin-left: auto; display: inline-flex; align-items: center; gap: 4px }
|
|
996
|
+
.body { padding: 2px 8px 6px 30px; color: ${t("muted")}; font-size: 12px }
|
|
997
|
+
mark { background: ${t("warn-bg")}; color: inherit; border-radius: 2px } .empty { color: ${t("muted")}; padding: 12px }
|
|
998
|
+
@media (pointer: coarse) { .line { min-height: 44px } }`;
|
|
999
|
+
|
|
1000
|
+
// packages/elements/src/kit/tree.ts
|
|
1001
|
+
var has = (n, q) => [n.label, ...n.terms ?? []].some((s) => s.toLowerCase().includes(q));
|
|
1002
|
+
var prune = (nodes, q, all) => nodes.flatMap((node) => {
|
|
1003
|
+
const hit = all || has(node, q), kids = prune(node.children ?? [], q, hit);
|
|
1004
|
+
return hit || kids.length ? [{ node, kids }] : [];
|
|
1005
|
+
});
|
|
1006
|
+
var pathTo = (nodes, id) => {
|
|
1007
|
+
for (const n of nodes) {
|
|
1008
|
+
if (n.id === id)
|
|
1009
|
+
return [id];
|
|
1010
|
+
const rest = pathTo(n.children ?? [], id);
|
|
1011
|
+
if (rest.length)
|
|
1012
|
+
return [n.id, ...rest];
|
|
1013
|
+
}
|
|
1014
|
+
return [];
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
class NanoTree extends LitElement7 {
|
|
1018
|
+
static properties = {
|
|
1019
|
+
nodes: { attribute: false },
|
|
1020
|
+
query: {},
|
|
1021
|
+
selected: {},
|
|
1022
|
+
openDepth: { type: Number, attribute: "open-depth" },
|
|
1023
|
+
icon: { attribute: false },
|
|
1024
|
+
flipped: { state: true },
|
|
1025
|
+
focused: { state: true }
|
|
1026
|
+
};
|
|
1027
|
+
static styles = [base, kit, treeStyles];
|
|
1028
|
+
#rows = [];
|
|
1029
|
+
constructor() {
|
|
1030
|
+
super();
|
|
1031
|
+
this.nodes = [];
|
|
1032
|
+
this.query = "";
|
|
1033
|
+
this.selected = null;
|
|
1034
|
+
this.openDepth = 0;
|
|
1035
|
+
this.flipped = new Set;
|
|
1036
|
+
this.focused = null;
|
|
1037
|
+
}
|
|
1038
|
+
get #q() {
|
|
1039
|
+
return this.query.trim().toLowerCase();
|
|
1040
|
+
}
|
|
1041
|
+
#isOpen(id, depth) {
|
|
1042
|
+
return this.#q !== "" || depth < this.openDepth !== this.flipped.has(id);
|
|
1043
|
+
}
|
|
1044
|
+
#flip(id) {
|
|
1045
|
+
const f = new Set(this.flipped);
|
|
1046
|
+
f.has(id) ? f.delete(id) : f.add(id);
|
|
1047
|
+
this.flipped = f;
|
|
1048
|
+
}
|
|
1049
|
+
#setOpen(row, open) {
|
|
1050
|
+
if (row.can && row.open !== open && !this.#q)
|
|
1051
|
+
this.#flip(row.id);
|
|
1052
|
+
}
|
|
1053
|
+
reveal(id, { focus = true } = {}) {
|
|
1054
|
+
const path = pathTo(this.nodes, id);
|
|
1055
|
+
path.slice(0, -1).forEach((a, depth) => {
|
|
1056
|
+
if (!this.#isOpen(a, depth))
|
|
1057
|
+
this.#flip(a);
|
|
1058
|
+
});
|
|
1059
|
+
if (path.length)
|
|
1060
|
+
this.#focus(id, focus);
|
|
1061
|
+
}
|
|
1062
|
+
async#focus(id, focus = true) {
|
|
1063
|
+
this.focused = id;
|
|
1064
|
+
await this.updateComplete;
|
|
1065
|
+
const li = this.renderRoot.querySelector(`[role='treeitem'][data-id="${CSS.escape(id)}"]`);
|
|
1066
|
+
if (focus)
|
|
1067
|
+
li?.focus();
|
|
1068
|
+
li?.querySelector(".line")?.scrollIntoView?.({ block: "nearest" });
|
|
1069
|
+
}
|
|
1070
|
+
#choose(id) {
|
|
1071
|
+
const go = this.dispatchEvent(new CustomEvent("select", { detail: { id }, cancelable: true, bubbles: true, composed: true }));
|
|
1072
|
+
if (go)
|
|
1073
|
+
this.selected = id;
|
|
1074
|
+
}
|
|
1075
|
+
#click(e, row) {
|
|
1076
|
+
const el = e.target;
|
|
1077
|
+
if (el.closest(".chev")) {
|
|
1078
|
+
this.#setOpen(row, !row.open);
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
if (el.closest("button, a, input, select, textarea, label"))
|
|
1082
|
+
return;
|
|
1083
|
+
this.#choose(row.id);
|
|
1084
|
+
this.#focus(row.id);
|
|
1085
|
+
}
|
|
1086
|
+
#key(e) {
|
|
1087
|
+
const li = e.target;
|
|
1088
|
+
if (li.getAttribute("role") !== "treeitem" || e.altKey || e.ctrlKey || e.metaKey)
|
|
1089
|
+
return;
|
|
1090
|
+
const rows = this.#rows, i = rows.findIndex((r) => r.id === li.dataset.id), row = rows[i];
|
|
1091
|
+
if (!row)
|
|
1092
|
+
return;
|
|
1093
|
+
const to = (r) => {
|
|
1094
|
+
if (r)
|
|
1095
|
+
this.#focus(r.id);
|
|
1096
|
+
};
|
|
1097
|
+
const k = e.key;
|
|
1098
|
+
if (k === "ArrowDown")
|
|
1099
|
+
to(rows[i + 1]);
|
|
1100
|
+
else if (k === "ArrowUp")
|
|
1101
|
+
to(rows[i - 1]);
|
|
1102
|
+
else if (k === "Home")
|
|
1103
|
+
to(rows[0]);
|
|
1104
|
+
else if (k === "End")
|
|
1105
|
+
to(rows.at(-1));
|
|
1106
|
+
else if (k === "ArrowRight")
|
|
1107
|
+
row.can && !row.open ? this.#setOpen(row, true) : rows[i + 1]?.parent === row.id && to(rows[i + 1]);
|
|
1108
|
+
else if (k === "ArrowLeft")
|
|
1109
|
+
row.can && row.open && !this.#q ? this.#setOpen(row, false) : to(rows.find((r) => r.id === row.parent));
|
|
1110
|
+
else if (k === "Enter" || k === " ")
|
|
1111
|
+
this.#choose(row.id);
|
|
1112
|
+
else if (k.length === 1 && k.trim()) {
|
|
1113
|
+
const c = k.toLowerCase();
|
|
1114
|
+
to([...rows.slice(i + 1), ...rows.slice(0, i)].find((r) => r.label.toLowerCase().startsWith(c)));
|
|
1115
|
+
} else
|
|
1116
|
+
return;
|
|
1117
|
+
e.preventDefault();
|
|
1118
|
+
}
|
|
1119
|
+
#label(s) {
|
|
1120
|
+
const q = this.#q, i = q ? s.toLowerCase().indexOf(q) : -1;
|
|
1121
|
+
return i < 0 ? s : html7`${s.slice(0, i)}<mark>${s.slice(i, i + q.length)}</mark>${s.slice(i + q.length)}`;
|
|
1122
|
+
}
|
|
1123
|
+
#item(s, depth, byId, tab) {
|
|
1124
|
+
const n = s.node, ic = this.icon?.(n), row = byId.get(n.id), { can, open } = row;
|
|
1125
|
+
return html7`<li role="treeitem" data-id=${n.id} aria-level=${depth + 1} aria-expanded=${can ? String(open) : nothing7}
|
|
1126
|
+
aria-selected=${this.selected === n.id ? "true" : nothing7} tabindex=${n.id === tab ? 0 : -1}
|
|
1127
|
+
${ref2((el) => setAttrs(el, n.data && Object.fromEntries(Object.entries(n.data).map(([k, v]) => [`data-${k}`, v]))))}>
|
|
1128
|
+
<div class="line" @click=${(e) => this.#click(e, row)}>
|
|
1129
|
+
<span class="chev" data-toggle=${n.id} aria-hidden="true">${can ? "▸" : ""}</span>
|
|
1130
|
+
${ic ? html7`<span class="icon" title=${n.kind ?? nothing7}>${ic}</span>` : nothing7}<span class="label">${this.#label(n.label)}</span>
|
|
1131
|
+
${n.kind && !ic ? html7`<span class="kind">${n.kind}</span>` : nothing7}${n.count !== undefined ? html7`<span class="count">${n.count}</span>` : nothing7}
|
|
1132
|
+
${n.badge ? html7`<span class="tag">${n.badge}</span>` : nothing7}${n.end !== undefined ? html7`<span class="end">${n.end}</span>` : nothing7}
|
|
1133
|
+
</div>
|
|
1134
|
+
${open ? html7`${n.body !== undefined ? html7`<div class="body">${n.body}</div>` : nothing7}
|
|
1135
|
+
${s.kids.length ? html7`<ul class="group" role="group">${s.kids.map((k) => this.#item(k, depth + 1, byId, tab))}</ul>` : nothing7}` : nothing7}
|
|
1136
|
+
</li>`;
|
|
1137
|
+
}
|
|
1138
|
+
render() {
|
|
1139
|
+
const shown = prune(this.nodes, this.#q, this.#q === "");
|
|
1140
|
+
const rows = [];
|
|
1141
|
+
const walk = (list, depth, parent) => list.forEach((s) => {
|
|
1142
|
+
const can = s.kids.length > 0 || s.node.body !== undefined, open = can && this.#isOpen(s.node.id, depth);
|
|
1143
|
+
rows.push({ id: s.node.id, label: s.node.label, parent, can, open });
|
|
1144
|
+
if (open)
|
|
1145
|
+
walk(s.kids, depth + 1, s.node.id);
|
|
1146
|
+
});
|
|
1147
|
+
walk(shown, 0);
|
|
1148
|
+
this.#rows = rows;
|
|
1149
|
+
if (!rows.length)
|
|
1150
|
+
return html7`<div class="empty">${this.#q ? `Nothing matches “${this.query.trim()}”.` : "Nothing here."}</div>`;
|
|
1151
|
+
const ids2 = new Set(rows.map((r) => r.id));
|
|
1152
|
+
const tab = [this.focused, this.selected].find((id) => id && ids2.has(id)) ?? rows[0].id;
|
|
1153
|
+
return html7`<ul role="tree" @keydown=${(e) => this.#key(e)}>${shown.map((s) => this.#item(s, 0, new Map(rows.map((r) => [r.id, r])), tab))}</ul>`;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (globalThis.customElements && !customElements.get("nano-tree"))
|
|
1157
|
+
customElements.define("nano-tree", NanoTree);
|
|
1006
1158
|
export {
|
|
1007
1159
|
tv,
|
|
1008
1160
|
toast,
|
|
1009
1161
|
t,
|
|
1010
|
-
providedRegistry,
|
|
1011
|
-
provide,
|
|
1012
1162
|
kit,
|
|
1013
1163
|
base,
|
|
1014
|
-
|
|
1164
|
+
NanoTree,
|
|
1015
1165
|
NanoTrace,
|
|
1016
1166
|
NanoTool,
|
|
1017
1167
|
NanoToaster,
|
|
@@ -1027,9 +1177,8 @@ export {
|
|
|
1027
1177
|
NanoCodeBlock,
|
|
1028
1178
|
NanoCli,
|
|
1029
1179
|
NanoCalendar,
|
|
1030
|
-
NANO_TOKENS
|
|
1031
|
-
ModelElement
|
|
1180
|
+
NANO_TOKENS
|
|
1032
1181
|
};
|
|
1033
1182
|
|
|
1034
|
-
//# debugId=
|
|
1183
|
+
//# debugId=3D55D8602F737C2B64756E2164756E21
|
|
1035
1184
|
//# sourceMappingURL=index.js.map
|