@syware/jlib 0.12.0 → 0.12.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/README.md
CHANGED
|
@@ -128,7 +128,7 @@ npm run size # what each component adds to a bundle
|
|
|
128
128
|
```
|
|
129
129
|
|
|
130
130
|
`src/index.ts` and `src/all.ts` are generated from the component folders, and the plugins' lists of components and
|
|
131
|
-
patterns from their documentation pages: run `npm run generate` after adding a component or a pattern. Conventions for contributors are in [
|
|
131
|
+
patterns from their documentation pages: run `npm run generate` after adding a component or a pattern. Conventions for contributors are in [AGENTS.md](AGENTS.md).
|
|
132
132
|
|
|
133
133
|
## Releasing
|
|
134
134
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// src/organisms/jl-page-header.css?inline
|
|
2
|
-
var jl_page_header_default = ":host{display:block}.page-header{gap:12px;display:grid}:host([divided]) .page-header{border-bottom:1px solid var(--jl-line);padding-bottom:20px}.breadcrumb{color:var(--jl-muted);font-size:var(--jl-font-sm);line-height:1.4}.main{flex-wrap:wrap;justify-content:space-between;align-items:flex-start;gap:12px 24px;display:flex}.titles{flex:
|
|
2
|
+
var jl_page_header_default = ":host{display:block}.page-header{gap:12px;display:grid}:host([divided]) .page-header{border-bottom:1px solid var(--jl-line);padding-bottom:20px}.breadcrumb{color:var(--jl-muted);font-size:var(--jl-font-sm);line-height:1.4}.main{flex-wrap:wrap;justify-content:space-between;align-items:flex-start;gap:12px 24px;display:flex}.titles{flex:275px;gap:6px;min-width:0;display:grid}h1{color:var(--jl-text);letter-spacing:-.02em;overflow-wrap:anywhere;font-size:26px;font-weight:700;line-height:1.25}.description{max-width:72ch;color:var(--jl-muted);font-size:var(--jl-font-md);line-height:1.55}.actions{flex-wrap:wrap;align-items:center;gap:8px;padding-top:2px;display:flex}.meta{flex-wrap:wrap;align-items:center;gap:8px;display:flex}";
|
|
3
3
|
export { jl_page_header_default as default };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// src/organisms/jl-side-nav.css?inline
|
|
2
|
-
var jl_side_nav_default = ":host{width:var(--width,248px);height:100%;min-height:0;transition:width var(--jl-slow) var(--jl-ease);display:block}:host([rail]){width:var(--rail-width,60px)}nav{height:100%;color:var(--jl-text-2);font-size:var(--jl-font-md);flex-direction:column;gap:8px;padding:12px 8px;display:flex;overflow:hidden
|
|
2
|
+
var jl_side_nav_default = ":host{width:var(--width,248px);height:100%;min-height:0;transition:width var(--jl-slow) var(--jl-ease);display:block}:host([rail]){width:var(--rail-width,60px)}nav{height:100%;color:var(--jl-text-2);font-size:var(--jl-font-md);flex-direction:column;gap:8px;padding:12px 8px;display:flex;overflow:hidden}.bottom{flex-direction:column;flex:none;gap:8px;margin-top:auto;display:flex}::slotted([slot=header]){flex:none}.fold::part(base){justify-content:flex-start;gap:10px;padding:0 9px}:host([rail]) .fold::part(base){justify-content:center;padding:0}.sections{scrollbar-gutter:stable;flex:1;align-content:start;gap:14px;min-height:0;display:grid;overflow-y:auto}.section{gap:2px;display:grid}.sections,.section,.items,.children{grid-template-columns:minmax(0,1fr)}.section-label{color:var(--jl-muted);letter-spacing:.08em;text-overflow:ellipsis;text-transform:uppercase;white-space:nowrap;padding:4px 10px 6px;font-size:11px;font-weight:650;overflow:hidden}.items,.children{gap:2px;margin:0;padding:0;list-style:none;display:grid}.children{margin-top:2px}.entry{position:relative}.item{border-radius:var(--jl-radius-sm);width:100%;min-height:34px;color:inherit;font:inherit;text-align:start;white-space:nowrap;cursor:pointer;transition:background var(--jl-fast) var(--jl-ease), color var(--jl-fast) var(--jl-ease);background:0 0;border:none;align-items:center;gap:10px;padding:0 10px;font-weight:550;text-decoration:none;display:flex}.item[data-depth=\"1\"]{padding-left:36px}.item[data-depth=\"2\"]{padding-left:50px}.item[data-depth=\"3\"]{padding-left:64px}.item:hover{background:var(--jl-surface-3);color:var(--jl-text)}.item[aria-current=page]{background:var(--jl-accent-soft);color:var(--jl-accent)}.item.holds-active{color:var(--jl-text)}.item-icon{color:var(--jl-faint)}.item:hover .item-icon,.item.holds-active .item-icon{color:var(--jl-text-2)}.item[aria-current=page] .item-icon{color:var(--jl-accent)}.item-initial{border-radius:var(--jl-radius-xs);background:var(--jl-surface-3);width:20px;height:20px;color:var(--jl-text-2);flex:none;justify-content:center;align-items:center;font-size:11px;font-weight:700;display:none}.item:not([data-depth=\"0\"]) .item-initial{display:none}.item-label{text-overflow:ellipsis;flex:1;min-width:0;overflow:hidden}.item-badge{border-radius:var(--jl-radius-pill);background:var(--jl-surface-3);min-width:20px;color:var(--jl-text-2);text-align:center;flex:none;padding:2px 6px;font-size:11px;font-weight:650;line-height:14px}.item[aria-current=page] .item-badge{background:var(--jl-accent);color:var(--jl-on-accent)}.expander jl-icon{transition:transform var(--jl-fast) var(--jl-ease)}.chevron{color:var(--jl-faint);transition:transform var(--jl-fast) var(--jl-ease)}.entry.open>.item .chevron,.entry.open>.expander jl-icon{transform:rotate(90deg)}.expander{border-radius:var(--jl-radius-xs);width:24px;height:24px;color:var(--jl-faint);cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;padding:0;display:inline-flex;position:absolute;top:5px;right:6px}.expander:hover{background:var(--jl-surface-3);color:var(--jl-text)}.entry:has(>.expander)>.item{padding-right:36px}:host([rail]) .section-label{background:var(--jl-line);color:#0000;height:1px;margin:4px 10px;padding:0;overflow:hidden}:host([rail]) .section:first-child .section-label{display:none}:host([rail]) .item{justify-content:center;padding:0}:host([rail]) .item-label{clip-path:inset(50%);width:1px;height:1px;position:absolute;overflow:hidden}:host([rail]) .item-initial{display:inline-flex}:host([rail]) .item-badge{background:var(--jl-accent);color:#0000;width:8px;min-width:0;height:8px;padding:0;position:absolute;top:5px;right:9px;overflow:hidden}:host([rail]) .children{display:none}";
|
|
3
3
|
export { jl_side_nav_default as default };
|
|
@@ -65,6 +65,7 @@ export declare class JlTree extends JlElement {
|
|
|
65
65
|
private readonly _rows;
|
|
66
66
|
private readonly _focus;
|
|
67
67
|
private readonly _loading;
|
|
68
|
+
private readonly _drawing;
|
|
68
69
|
private readonly _refs;
|
|
69
70
|
/** Loads the items a page at a time; setting it forgets `items` and loads the roots. */
|
|
70
71
|
get loader(): TreeLoader | null;
|
|
@@ -111,7 +112,20 @@ export declare class JlTree extends JlElement {
|
|
|
111
112
|
private hasLevelEndRow;
|
|
112
113
|
protected drawTexts(): void;
|
|
113
114
|
private errorLabel;
|
|
115
|
+
private itemsChanged;
|
|
114
116
|
private renderItems;
|
|
117
|
+
/** Where the Tab stop goes once rows are drawn: where it was, else the selected item, else the first. */
|
|
118
|
+
private tabStop;
|
|
119
|
+
/**
|
|
120
|
+
* Draws the rows a page added to a level, then the row that ends the level again, and nothing else: a spinner, a
|
|
121
|
+
* page or an error leaves the other rows as they are. A level not drawn yet draws the whole tree. The focus that
|
|
122
|
+
* was on the row ending the level moves to the one replacing it.
|
|
123
|
+
*/
|
|
124
|
+
private drawLevelEnd;
|
|
125
|
+
/** The element holding a level's rows; null when they are not drawn, or when the tree shows its empty note. */
|
|
126
|
+
private levelContainer;
|
|
127
|
+
/** The depth of a level's rows: 1 for the roots. */
|
|
128
|
+
private levelOf;
|
|
115
129
|
private itemNode;
|
|
116
130
|
/** The row that ends a level, if it has one. */
|
|
117
131
|
private levelEndNodes;
|
|
@@ -121,8 +135,11 @@ export declare class JlTree extends JlElement {
|
|
|
121
135
|
private errorNode;
|
|
122
136
|
private noteNode;
|
|
123
137
|
private renderExpanded;
|
|
138
|
+
/** Opens or closes the groups of these rows, as `expanded` says. */
|
|
139
|
+
private drawExpanded;
|
|
124
140
|
private isVisible;
|
|
125
141
|
/** The item itself when it shows, else the nearest folder around it that does: the focus goes there. */
|
|
126
142
|
private visibleAncestor;
|
|
127
143
|
private renderSelection;
|
|
144
|
+
private drawSelection;
|
|
128
145
|
}
|
|
@@ -43,7 +43,7 @@ var messageOf = (error) => error instanceof Error ? error.message : String(error
|
|
|
43
43
|
var JlTree = class extends JlElement {
|
|
44
44
|
static selector = "jl-tree";
|
|
45
45
|
events = this.useEvents();
|
|
46
|
-
items = this.useChange([], () => this.
|
|
46
|
+
items = this.useChange([], () => this.itemsChanged(), {
|
|
47
47
|
attribute: "items",
|
|
48
48
|
parse: jsonOf([])
|
|
49
49
|
});
|
|
@@ -76,6 +76,7 @@ var JlTree = class extends JlElement {
|
|
|
76
76
|
generation: 0,
|
|
77
77
|
levels: /* @__PURE__ */ new Map()
|
|
78
78
|
};
|
|
79
|
+
_drawing = { pageOnly: false };
|
|
79
80
|
_refs = this.useRefs((ref) => ({ tree: ref(".tree") }));
|
|
80
81
|
/** Loads the items a page at a time; setting it forgets `items` and loads the roots. */
|
|
81
82
|
get loader() {
|
|
@@ -220,7 +221,7 @@ var JlTree = class extends JlElement {
|
|
|
220
221
|
pending,
|
|
221
222
|
total: level?.total ?? 0
|
|
222
223
|
});
|
|
223
|
-
this.whenRendered(() => this.
|
|
224
|
+
this.whenRendered(() => this.drawLevelEnd(parent));
|
|
224
225
|
return pending;
|
|
225
226
|
}
|
|
226
227
|
loadNextPage(parent) {
|
|
@@ -236,7 +237,18 @@ var JlTree = class extends JlElement {
|
|
|
236
237
|
pending: null,
|
|
237
238
|
total
|
|
238
239
|
});
|
|
239
|
-
|
|
240
|
+
const items = withPage(this.items.get(), parent, page.items);
|
|
241
|
+
if (this.levelContainer(parent) === null) this.items.set(items);
|
|
242
|
+
else {
|
|
243
|
+
this._drawing.pageOnly = true;
|
|
244
|
+
try {
|
|
245
|
+
this.items.set(items);
|
|
246
|
+
} finally {
|
|
247
|
+
this._drawing.pageOnly = false;
|
|
248
|
+
}
|
|
249
|
+
const level = this.levelOf(parent);
|
|
250
|
+
this.drawLevelEnd(parent, page.items.map((item) => this.itemNode(item, level)));
|
|
251
|
+
}
|
|
240
252
|
this.loadOpenFolders();
|
|
241
253
|
const first = page.items[0];
|
|
242
254
|
if (focusFirst && first !== void 0) this.moveFocus(first.id, true);
|
|
@@ -249,7 +261,7 @@ var JlTree = class extends JlElement {
|
|
|
249
261
|
pending: null,
|
|
250
262
|
total
|
|
251
263
|
});
|
|
252
|
-
this.whenRendered(() => this.
|
|
264
|
+
this.whenRendered(() => this.drawLevelEnd(parent));
|
|
253
265
|
}
|
|
254
266
|
/** The open folders whose children the loader has not given yet: their first page. */
|
|
255
267
|
loadOpenFolders() {
|
|
@@ -283,15 +295,54 @@ var JlTree = class extends JlElement {
|
|
|
283
295
|
errorLabel() {
|
|
284
296
|
return this.errorText.get() || jlText("loadError");
|
|
285
297
|
}
|
|
298
|
+
itemsChanged() {
|
|
299
|
+
if (!this._drawing.pageOnly) this.renderItems();
|
|
300
|
+
}
|
|
286
301
|
renderItems() {
|
|
287
302
|
const hadFocus = this.hasFocusInside();
|
|
288
303
|
this._rows.clear();
|
|
289
304
|
this._refs.tree.replaceChildren(...this.items.get().map((item) => this.itemNode(item, 1)), ...this.levelEndNodes(null, 1));
|
|
290
305
|
this.renderExpanded();
|
|
291
306
|
this.renderSelection();
|
|
307
|
+
this.moveFocus(this.tabStop(), hadFocus);
|
|
308
|
+
}
|
|
309
|
+
/** Where the Tab stop goes once rows are drawn: where it was, else the selected item, else the first. */
|
|
310
|
+
tabStop() {
|
|
311
|
+
if (this._rows.has(this._focus.id)) return this._focus.id;
|
|
292
312
|
const first = this._rows.keys().next().value ?? "";
|
|
293
|
-
|
|
294
|
-
|
|
313
|
+
return this._rows.has(this.value.get()) ? this.value.get() : first;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Draws the rows a page added to a level, then the row that ends the level again, and nothing else: a spinner, a
|
|
317
|
+
* page or an error leaves the other rows as they are. A level not drawn yet draws the whole tree. The focus that
|
|
318
|
+
* was on the row ending the level moves to the one replacing it.
|
|
319
|
+
*/
|
|
320
|
+
drawLevelEnd(parent, added = []) {
|
|
321
|
+
const container = this.levelContainer(parent);
|
|
322
|
+
if (container === null) {
|
|
323
|
+
this.renderItems();
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const hadFocus = this.hasFocusInside();
|
|
327
|
+
const endId = levelEndId(parent);
|
|
328
|
+
this._rows.get(endId)?.remove();
|
|
329
|
+
this._rows.delete(endId);
|
|
330
|
+
const ending = this.levelEndNodes(parent, this.levelOf(parent));
|
|
331
|
+
container.append(...added, ...ending);
|
|
332
|
+
const drawn = [...added, ...ending].filter((node) => node instanceof HTMLElement && node.dataset.id !== void 0).flatMap((row) => [row, ...row.querySelectorAll("[role=\"treeitem\"]")]).map((row) => [row.dataset.id ?? "", row]);
|
|
333
|
+
this.drawExpanded(drawn);
|
|
334
|
+
this.drawSelection(drawn);
|
|
335
|
+
this.moveFocus(this.tabStop(), hadFocus && !this.hasFocusInside());
|
|
336
|
+
}
|
|
337
|
+
/** The element holding a level's rows; null when they are not drawn, or when the tree shows its empty note. */
|
|
338
|
+
levelContainer(parent) {
|
|
339
|
+
if (parent === null) return this.items.get().length > 0 && this._rows.size > 0 ? this._refs.tree : null;
|
|
340
|
+
return this._rows.get(parent)?.querySelector(":scope > .group") ?? null;
|
|
341
|
+
}
|
|
342
|
+
/** The depth of a level's rows: 1 for the roots. */
|
|
343
|
+
levelOf(parent) {
|
|
344
|
+
if (parent === null) return 1;
|
|
345
|
+
return (allItems(this.items.get()).find((entry) => entry.item.id === parent)?.level ?? 0) + 1;
|
|
295
346
|
}
|
|
296
347
|
itemNode(item, level) {
|
|
297
348
|
const folder = isFolder(item);
|
|
@@ -438,8 +489,13 @@ var JlTree = class extends JlElement {
|
|
|
438
489
|
return node;
|
|
439
490
|
}
|
|
440
491
|
renderExpanded() {
|
|
492
|
+
this.drawExpanded(this._rows);
|
|
493
|
+
if (!this.isVisible(this._focus.id)) this.moveFocus(this.visibleAncestor(this._focus.id), false);
|
|
494
|
+
}
|
|
495
|
+
/** Opens or closes the groups of these rows, as `expanded` says. */
|
|
496
|
+
drawExpanded(rows) {
|
|
441
497
|
const expanded = new Set(this.expanded.get());
|
|
442
|
-
for (const [id, row] of
|
|
498
|
+
for (const [id, row] of rows) {
|
|
443
499
|
const group = row.querySelector(":scope > .group");
|
|
444
500
|
if (group === null) continue;
|
|
445
501
|
const open = expanded.has(id);
|
|
@@ -447,7 +503,6 @@ var JlTree = class extends JlElement {
|
|
|
447
503
|
group.hidden = !open;
|
|
448
504
|
row.querySelector(":scope > .row > .icon.auto")?.name.set(open ? OPEN_FOLDER_ICON : FOLDER_ICON);
|
|
449
505
|
}
|
|
450
|
-
if (!this.isVisible(this._focus.id)) this.moveFocus(this.visibleAncestor(this._focus.id), false);
|
|
451
506
|
}
|
|
452
507
|
isVisible(id) {
|
|
453
508
|
const row = this._rows.get(id);
|
|
@@ -459,8 +514,11 @@ var JlTree = class extends JlElement {
|
|
|
459
514
|
return owner?.dataset.id === void 0 ? id : this.visibleAncestor(owner.dataset.id);
|
|
460
515
|
}
|
|
461
516
|
renderSelection() {
|
|
517
|
+
this.drawSelection(this._rows);
|
|
518
|
+
}
|
|
519
|
+
drawSelection(rows) {
|
|
462
520
|
const value = this.value.get();
|
|
463
|
-
for (const [id, row] of
|
|
521
|
+
for (const [id, row] of rows) row.setAttribute("aria-selected", String(id === value));
|
|
464
522
|
}
|
|
465
523
|
};
|
|
466
524
|
JlTree.register();
|