@ixfx/components 0.7.2 → 0.7.4
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/bundle/index.d.ts +805 -137
- package/bundle/index.d.ts.map +1 -1
- package/bundle/index.js +2168 -42
- package/bundle/index.js.map +1 -1
- package/dist/ac-text.js +1 -1
- package/dist/ac-token.js +1 -1
- package/dist/crumbs.js +3 -3
- package/dist/{data-grid-Bh4YrQGK.d.ts → data-grid-BddUjAti.d.ts} +33 -1
- package/dist/data-grid-BddUjAti.d.ts.map +1 -0
- package/dist/data-grid.d.ts +1 -1
- package/dist/data-grid.js +180 -7
- package/dist/data-grid.js.map +1 -1
- package/dist/detail-list-Br0WAnry.d.ts +167 -0
- package/dist/detail-list-Br0WAnry.d.ts.map +1 -0
- package/dist/detail-list.d.ts +3 -0
- package/dist/detail-list.js +1115 -0
- package/dist/detail-list.js.map +1 -0
- package/dist/grid-list-B_orPsot.d.ts +304 -0
- package/dist/grid-list-B_orPsot.d.ts.map +1 -0
- package/dist/grid-list.d.ts +3 -0
- package/dist/grid-list.js +933 -0
- package/dist/grid-list.js.map +1 -0
- package/dist/{grouped-item-lister-DnWB-eFT.d.ts → grouped-item-lister-fdZHVxFM.d.ts} +2 -2
- package/dist/{grouped-item-lister-DnWB-eFT.d.ts.map → grouped-item-lister-fdZHVxFM.d.ts.map} +1 -1
- package/dist/grouped-item-lister.d.ts +1 -1
- package/dist/index.d.ts +267 -124
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +469 -979
- package/dist/index.js.map +1 -1
- package/dist/interaction-Cr13azbM.js +3 -0
- package/dist/list-item-animation-DuiwgN3l.js +112 -0
- package/dist/list-item-animation-DuiwgN3l.js.map +1 -0
- package/dist/list-selection-controller-CUo-Hhcm.js +338 -0
- package/dist/list-selection-controller-CUo-Hhcm.js.map +1 -0
- package/dist/{list-selection-types-DSuRNWpx.d.ts → list-selection-types-B5ioL-dG.d.ts} +6 -1
- package/dist/list-selection-types-B5ioL-dG.d.ts.map +1 -0
- package/dist/{menu-CXDFJxNm.js → menu-Bg90Qr0B.js} +7 -7
- package/dist/menu-Bg90Qr0B.js.map +1 -0
- package/dist/{menu-item-D2S4i8u1.js → menu-item-Bx-Fs7jq.js} +3 -3
- package/dist/{menu-item-D2S4i8u1.js.map → menu-item-Bx-Fs7jq.js.map} +1 -1
- package/dist/menu.js +2 -2
- package/dist/miller.d.ts +1 -1
- package/dist/miller.js +2 -2
- package/dist/narrowed-text.js +2 -2
- package/dist/plots.js +1 -1
- package/dist/select-horiz.js +2 -2
- package/dist/{tickled-controller-CRzdIEjJ.d.ts → tickled-controller-Bn3YdQsM.d.ts} +13 -2
- package/dist/{tickled-controller-CRzdIEjJ.d.ts.map → tickled-controller-Bn3YdQsM.d.ts.map} +1 -1
- package/dist/{tickled-controller-h9GmJ_bU.js → tickled-controller-C66DgJHl.js} +16 -1
- package/dist/tickled-controller-C66DgJHl.js.map +1 -0
- package/dist/{tree-Ch4W8qXQ.js → tree-B74zdI60.js} +116 -17
- package/dist/tree-B74zdI60.js.map +1 -0
- package/dist/tree.d.ts +6 -3
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +1 -1
- package/dist/vertical-list-CQSEVeOT.d.ts +140 -0
- package/dist/vertical-list-CQSEVeOT.d.ts.map +1 -0
- package/dist/vertical-list.d.ts +3 -121
- package/dist/vertical-list.js +710 -1
- package/dist/vertical-list.js.map +1 -0
- package/dist/{xy-axis-DWizs0bt.js → xy-axis-VrX8dmvS.js} +2 -2
- package/dist/{xy-axis-DWizs0bt.js.map → xy-axis-VrX8dmvS.js.map} +1 -1
- package/docs-user/README.md +2 -0
- package/docs-user/data-grid.md +51 -2
- package/docs-user/detail-list.md +80 -15
- package/docs-user/grid-list.md +274 -0
- package/docs-user/index.json +11 -2
- package/docs-user/infra-tickled.md +163 -0
- package/docs-user/llms.txt +2 -0
- package/docs-user/tree.md +13 -0
- package/docs-user/vertical-list.md +51 -1
- package/llms.txt +2 -0
- package/package.json +17 -2
- package/dist/data-grid-Bh4YrQGK.d.ts.map +0 -1
- package/dist/interaction-D5XdKzbR.js +0 -2
- package/dist/list-selection-types-DSuRNWpx.d.ts.map +0 -1
- package/dist/menu-CXDFJxNm.js.map +0 -1
- package/dist/tickled-controller-h9GmJ_bU.js.map +0 -1
- package/dist/tree-Ch4W8qXQ.js.map +0 -1
- package/dist/vertical-list-ClnqTkF3.js +0 -814
- package/dist/vertical-list-ClnqTkF3.js.map +0 -1
- package/dist/vertical-list.d.ts.map +0 -1
|
@@ -0,0 +1,933 @@
|
|
|
1
|
+
import { t as TickledController } from "./tickled-controller-C66DgJHl.js";
|
|
2
|
+
import { n as tickledStyles, t as tickledItemStyles } from "./tickled-styles-BrAHEj1q.js";
|
|
3
|
+
import { t as themeFallbacks } from "./fallbacks-DNI9xt0F.js";
|
|
4
|
+
import { n as safeCustomElement, t as __decorate } from "./decorate-VRK8rslU.js";
|
|
5
|
+
import { i as keyForElement, t as ListSelectionController } from "./list-selection-controller-CUo-Hhcm.js";
|
|
6
|
+
import { i as listItemFadeKeyframes } from "./list-item-animation-DuiwgN3l.js";
|
|
7
|
+
import "./interaction-Cr13azbM.js";
|
|
8
|
+
import { t as scrollFadeStyles } from "./scroll-fade-CAs1EabA.js";
|
|
9
|
+
import { LitElement, css, html } from "lit";
|
|
10
|
+
import { property, state } from "lit/decorators.js";
|
|
11
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
12
|
+
import { createRef, ref } from "lit/directives/ref.js";
|
|
13
|
+
//#region src/grid-list/grid-list.ts
|
|
14
|
+
const ITEM_SELECTOR = `:scope > *`;
|
|
15
|
+
const MIN_ITEM_SIZE = 16;
|
|
16
|
+
/**
|
|
17
|
+
* How long the host keeps the `[reflowing]` attribute after items are inserted
|
|
18
|
+
* mid-list — long enough for the cell move-transition and the enter animation
|
|
19
|
+
* to finish. Kept a touch above the default `--grid-list-item-move-duration`.
|
|
20
|
+
*/
|
|
21
|
+
const REFLOW_WINDOW_MS = 320;
|
|
22
|
+
function computeGridWindow(count, itemWidth, rowHeight, gap, viewportWidth, viewportHeight, scrollOffset, orientation, overscan = 2) {
|
|
23
|
+
const w = Math.max(1, itemWidth);
|
|
24
|
+
const h = Math.max(1, rowHeight);
|
|
25
|
+
const g = Math.max(0, gap);
|
|
26
|
+
const colStride = w + g;
|
|
27
|
+
const rowStride = h + g;
|
|
28
|
+
const offset = Math.max(0, scrollOffset);
|
|
29
|
+
if (orientation === `row`) {
|
|
30
|
+
const rows = count === 0 ? 0 : 1;
|
|
31
|
+
const totalWidth = count === 0 ? 0 : (count - 1) * colStride + w;
|
|
32
|
+
if (count === 0 || viewportWidth <= 0) return {
|
|
33
|
+
cols: count,
|
|
34
|
+
rows,
|
|
35
|
+
totalHeight: 0,
|
|
36
|
+
totalWidth,
|
|
37
|
+
startIndex: 0,
|
|
38
|
+
endIndex: 0,
|
|
39
|
+
colStride,
|
|
40
|
+
rowStride,
|
|
41
|
+
horizontal: true
|
|
42
|
+
};
|
|
43
|
+
const firstVisible = Math.max(0, Math.floor(offset / colStride));
|
|
44
|
+
const lastVisible = Math.ceil((offset + viewportWidth) / colStride);
|
|
45
|
+
return {
|
|
46
|
+
cols: count,
|
|
47
|
+
rows,
|
|
48
|
+
totalHeight: 0,
|
|
49
|
+
totalWidth,
|
|
50
|
+
startIndex: Math.max(0, firstVisible - overscan),
|
|
51
|
+
endIndex: Math.min(count, lastVisible + overscan),
|
|
52
|
+
colStride,
|
|
53
|
+
rowStride,
|
|
54
|
+
horizontal: true
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const cols = orientation === `column` ? 1 : Math.max(1, Math.floor((Math.max(0, viewportWidth) + g) / colStride));
|
|
58
|
+
const rows = count === 0 ? 0 : Math.ceil(count / cols);
|
|
59
|
+
const totalHeight = rows === 0 ? 0 : (rows - 1) * rowStride + h;
|
|
60
|
+
if (count === 0 || viewportHeight <= 0) return {
|
|
61
|
+
cols,
|
|
62
|
+
rows,
|
|
63
|
+
totalHeight,
|
|
64
|
+
totalWidth: 0,
|
|
65
|
+
startIndex: 0,
|
|
66
|
+
endIndex: 0,
|
|
67
|
+
colStride,
|
|
68
|
+
rowStride,
|
|
69
|
+
horizontal: false
|
|
70
|
+
};
|
|
71
|
+
const firstVisibleRow = Math.max(0, Math.floor(offset / rowStride));
|
|
72
|
+
const lastVisibleRow = Math.ceil((offset + viewportHeight) / rowStride);
|
|
73
|
+
const rowStart = Math.max(0, firstVisibleRow - overscan);
|
|
74
|
+
const rowEnd = Math.min(rows, lastVisibleRow + overscan);
|
|
75
|
+
return {
|
|
76
|
+
cols,
|
|
77
|
+
rows,
|
|
78
|
+
totalHeight,
|
|
79
|
+
totalWidth: 0,
|
|
80
|
+
startIndex: rowStart * cols,
|
|
81
|
+
endIndex: Math.min(count, rowEnd * cols),
|
|
82
|
+
colStride,
|
|
83
|
+
rowStride,
|
|
84
|
+
horizontal: false
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function columnOf(index, cols) {
|
|
88
|
+
return cols <= 1 ? 0 : index % cols;
|
|
89
|
+
}
|
|
90
|
+
function rowOf(index, cols) {
|
|
91
|
+
return cols <= 1 ? index : Math.floor(index / cols);
|
|
92
|
+
}
|
|
93
|
+
let GridListElement = class GridListElement extends LitElement {
|
|
94
|
+
constructor(..._args) {
|
|
95
|
+
super(..._args);
|
|
96
|
+
this.selectionMode = `single`;
|
|
97
|
+
this.interactionMode = `standard`;
|
|
98
|
+
this.itemSize = 160;
|
|
99
|
+
this.gap = 8;
|
|
100
|
+
this.orientation = `grid`;
|
|
101
|
+
this.captionStyle = `under`;
|
|
102
|
+
this.captionAlign = `middle`;
|
|
103
|
+
this.captionPosition = `bottom`;
|
|
104
|
+
this.captionBackdrop = `scrim`;
|
|
105
|
+
this.captionHeight = 24;
|
|
106
|
+
this.itemWrap = `stop`;
|
|
107
|
+
this._scrollTop = 0;
|
|
108
|
+
this._scrollLeft = 0;
|
|
109
|
+
this._viewportHeight = 0;
|
|
110
|
+
this._viewportWidth = 0;
|
|
111
|
+
this.#viewportRef = createRef();
|
|
112
|
+
this.#scrollRaf = 0;
|
|
113
|
+
this.#items = [];
|
|
114
|
+
this.#itemWrap = `stop`;
|
|
115
|
+
this.#entering = /* @__PURE__ */ new Set();
|
|
116
|
+
this.#reflowTimer = 0;
|
|
117
|
+
this.#slotNames = /* @__PURE__ */ new WeakMap();
|
|
118
|
+
this.#slotSeq = 0;
|
|
119
|
+
this.selection = new ListSelectionController({
|
|
120
|
+
getOrderedItems: () => this._getVisibleItems(),
|
|
121
|
+
isSelectable: () => true,
|
|
122
|
+
getModes: () => ({
|
|
123
|
+
selectionMode: this.selectionMode,
|
|
124
|
+
interactionMode: this.interactionMode
|
|
125
|
+
}),
|
|
126
|
+
getKey: keyForElement,
|
|
127
|
+
onChange: (selected, previous) => {
|
|
128
|
+
this._syncItemStates();
|
|
129
|
+
this.requestUpdate();
|
|
130
|
+
this._dispatch(`list-select`, {
|
|
131
|
+
selected,
|
|
132
|
+
previous,
|
|
133
|
+
selectedKeys: this.selection.selectedKeys
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
this.tickled = new TickledController(this, {
|
|
138
|
+
getItems: () => this.#items.map((el) => ({
|
|
139
|
+
id: el,
|
|
140
|
+
enabled: !el.hasAttribute(`not-checked`)
|
|
141
|
+
})),
|
|
142
|
+
onTickle: (id) => {
|
|
143
|
+
if (id !== void 0) this._dispatch(`list-tickle`, { item: id });
|
|
144
|
+
},
|
|
145
|
+
onStateChange: () => this._syncItemStates(),
|
|
146
|
+
itemWrap: this.#itemWrap
|
|
147
|
+
});
|
|
148
|
+
this.#onScroll = (e) => {
|
|
149
|
+
const el = e.target;
|
|
150
|
+
this.#cancelScrollRaf();
|
|
151
|
+
this.#scrollRaf = requestAnimationFrame(() => {
|
|
152
|
+
this.#scrollRaf = 0;
|
|
153
|
+
this._scrollTop = el.scrollTop;
|
|
154
|
+
this._scrollLeft = el.scrollLeft;
|
|
155
|
+
this.#emitViewportChange();
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
this._onKeyDown = (e) => {
|
|
159
|
+
if ((e.ctrlKey || e.metaKey) && e.key === `f`) return;
|
|
160
|
+
if ((e.ctrlKey || e.metaKey) && e.key === `a`) {
|
|
161
|
+
if (this.selection.canSelectAll()) {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
this.selection.selectAll();
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const count = this.#items.length;
|
|
168
|
+
if (count === 0) return;
|
|
169
|
+
const win = this.#currentWindow();
|
|
170
|
+
const move = (delta) => {
|
|
171
|
+
const from = this.tickled.tickledId ? this.#items.indexOf(this.tickled.tickledId) : -1;
|
|
172
|
+
const nextIndex = Math.max(0, Math.min(count - 1, from + delta));
|
|
173
|
+
const next = this.#items[nextIndex];
|
|
174
|
+
if (next) this.tickled.handleKeyboardNavigation(next);
|
|
175
|
+
};
|
|
176
|
+
const perLine = this.orientation === `grid` ? win.cols : 1;
|
|
177
|
+
switch (e.key) {
|
|
178
|
+
case `ArrowLeft`:
|
|
179
|
+
move(-1);
|
|
180
|
+
break;
|
|
181
|
+
case `ArrowRight`:
|
|
182
|
+
move(1);
|
|
183
|
+
break;
|
|
184
|
+
case `ArrowUp`:
|
|
185
|
+
move(-perLine);
|
|
186
|
+
break;
|
|
187
|
+
case `ArrowDown`:
|
|
188
|
+
move(perLine);
|
|
189
|
+
break;
|
|
190
|
+
case `Home`:
|
|
191
|
+
this.tickled.handleKeyboardNavigation(`first`);
|
|
192
|
+
break;
|
|
193
|
+
case `End`:
|
|
194
|
+
this.tickled.handleKeyboardNavigation(`last`);
|
|
195
|
+
break;
|
|
196
|
+
case `PageUp`:
|
|
197
|
+
case `PageDown`: {
|
|
198
|
+
const mainExtent = win.horizontal ? this._viewportWidth : this._viewportHeight;
|
|
199
|
+
const mainStride = win.horizontal ? win.colStride : win.rowStride;
|
|
200
|
+
const visibleLines = Math.max(1, Math.floor(mainExtent / mainStride));
|
|
201
|
+
move((e.key === `PageDown` ? 1 : -1) * visibleLines * perLine);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case `Enter`: {
|
|
205
|
+
const id = this.tickled.tickledId;
|
|
206
|
+
if (id) {
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
this._dispatch(`list-item-click`, { item: id });
|
|
209
|
+
this.#onCellActivate(id);
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case ` `: {
|
|
214
|
+
const id = this.tickled.tickledId;
|
|
215
|
+
if (id) {
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
this.selection.handleSpace(id);
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case `Escape`:
|
|
222
|
+
this.selection.clear();
|
|
223
|
+
break;
|
|
224
|
+
default: return;
|
|
225
|
+
}
|
|
226
|
+
e.preventDefault();
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
static {
|
|
230
|
+
this.styles = [
|
|
231
|
+
themeFallbacks,
|
|
232
|
+
tickledStyles,
|
|
233
|
+
tickledItemStyles,
|
|
234
|
+
scrollFadeStyles(`x`),
|
|
235
|
+
scrollFadeStyles(`y`),
|
|
236
|
+
listItemFadeKeyframes,
|
|
237
|
+
css`
|
|
238
|
+
:host {
|
|
239
|
+
--grid-list-item-bg: var(--item-bg);
|
|
240
|
+
--grid-list-radius: var(--radius-m);
|
|
241
|
+
--grid-list-gap: var(--space-xs);
|
|
242
|
+
display: block;
|
|
243
|
+
height: 100%;
|
|
244
|
+
min-height: 2em;
|
|
245
|
+
overflow: hidden;
|
|
246
|
+
user-select: none;
|
|
247
|
+
background: var(--surface-3);
|
|
248
|
+
color: var(--surface-3-text);
|
|
249
|
+
border-radius: var(--radius-s);
|
|
250
|
+
border: 1px solid var(--border);
|
|
251
|
+
}
|
|
252
|
+
:host(:focus-visible) {
|
|
253
|
+
outline: 2px solid var(--accent);
|
|
254
|
+
outline-offset: -2px;
|
|
255
|
+
}
|
|
256
|
+
.viewport {
|
|
257
|
+
position: relative;
|
|
258
|
+
height: 100%;
|
|
259
|
+
overflow-y: auto;
|
|
260
|
+
overflow-x: hidden;
|
|
261
|
+
}
|
|
262
|
+
:host([orientation="row"]) .viewport {
|
|
263
|
+
overflow-x: auto;
|
|
264
|
+
overflow-y: hidden;
|
|
265
|
+
}
|
|
266
|
+
.spacer {
|
|
267
|
+
position: relative;
|
|
268
|
+
width: 100%;
|
|
269
|
+
}
|
|
270
|
+
.cell {
|
|
271
|
+
position: absolute;
|
|
272
|
+
inset: 0 auto auto 0;
|
|
273
|
+
box-sizing: border-box;
|
|
274
|
+
display: flex;
|
|
275
|
+
flex-direction: column;
|
|
276
|
+
align-items: stretch;
|
|
277
|
+
contain: layout style;
|
|
278
|
+
border-radius: var(--grid-list-radius);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/* The square that holds the slotted content. */
|
|
282
|
+
.thumb {
|
|
283
|
+
position: relative;
|
|
284
|
+
flex: 1;
|
|
285
|
+
min-height: 0;
|
|
286
|
+
display: flex;
|
|
287
|
+
align-items: stretch;
|
|
288
|
+
box-sizing: border-box;
|
|
289
|
+
overflow: hidden;
|
|
290
|
+
border-radius: 0;
|
|
291
|
+
background: transparent;
|
|
292
|
+
border: 1px solid transparent;
|
|
293
|
+
transition: background var(--transition), border-color var(--transition);
|
|
294
|
+
}
|
|
295
|
+
.thumb ::slotted(*) {
|
|
296
|
+
flex: 1;
|
|
297
|
+
min-width: 0;
|
|
298
|
+
min-height: 0;
|
|
299
|
+
width: 100%;
|
|
300
|
+
display: flex;
|
|
301
|
+
align-items: center;
|
|
302
|
+
justify-content: center;
|
|
303
|
+
overflow: hidden;
|
|
304
|
+
}
|
|
305
|
+
.thumb ::slotted(*:empty)::after {
|
|
306
|
+
content: "Empty";
|
|
307
|
+
color: var(--surface-muted-text);
|
|
308
|
+
font-size: var(--text-s);
|
|
309
|
+
}
|
|
310
|
+
::slotted([hidden]) {
|
|
311
|
+
display: none !important;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* Selection / cursor wash — sits over the slotted content so it reads
|
|
315
|
+
on photos and arbitrary DOM alike. */
|
|
316
|
+
.thumb::after {
|
|
317
|
+
content: "";
|
|
318
|
+
position: absolute;
|
|
319
|
+
inset: 0;
|
|
320
|
+
pointer-events: none;
|
|
321
|
+
border-radius: inherit;
|
|
322
|
+
background: var(--accent);
|
|
323
|
+
opacity: 0;
|
|
324
|
+
transition: opacity var(--transition, 0.1s ease-out);
|
|
325
|
+
}
|
|
326
|
+
.cell.selected .thumb::after {
|
|
327
|
+
opacity: 0.18;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/* ---- Caption (base) ---- */
|
|
331
|
+
.caption {
|
|
332
|
+
box-sizing: border-box;
|
|
333
|
+
flex: none;
|
|
334
|
+
padding: 3px 6px;
|
|
335
|
+
font-size: var(--text-s, 0.8rem);
|
|
336
|
+
line-height: 1.3;
|
|
337
|
+
text-align: center;
|
|
338
|
+
white-space: nowrap;
|
|
339
|
+
overflow: hidden;
|
|
340
|
+
text-overflow: ellipsis;
|
|
341
|
+
color: var(--surface-3-text);
|
|
342
|
+
}
|
|
343
|
+
:host([caption-align="left"]) .caption { text-align: left; }
|
|
344
|
+
:host([caption-align="right"]) .caption { text-align: right; }
|
|
345
|
+
|
|
346
|
+
/* ---- Box modes (hidden / under / overlaid): the cell is one box with a
|
|
347
|
+
single selection outline ---- */
|
|
348
|
+
:host(:not([caption-style="separate"])) .cell {
|
|
349
|
+
background: var(--grid-list-item-bg);
|
|
350
|
+
border: 1px solid transparent;
|
|
351
|
+
overflow: hidden;
|
|
352
|
+
transition: background var(--transition), border-color var(--transition);
|
|
353
|
+
}
|
|
354
|
+
:host(:not([caption-style="separate"])) .cell:hover {
|
|
355
|
+
background: var(--item-bg-tickled);
|
|
356
|
+
border-color: var(--item-border-tickled);
|
|
357
|
+
}
|
|
358
|
+
:host(:not([caption-style="separate"])) .cell.selected {
|
|
359
|
+
outline: 2px solid var(--accent);
|
|
360
|
+
outline-offset: -2px;
|
|
361
|
+
}
|
|
362
|
+
:host(:not([caption-style="separate"])) .cell.tickled {
|
|
363
|
+
box-shadow: inset 0 0 0 2px var(--accent);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/* under: caption is a strip inside the box, below the content */
|
|
367
|
+
:host([caption-style="under"]) .caption {
|
|
368
|
+
border-top: 1px solid var(--border, rgba(128, 128, 128, 0.3));
|
|
369
|
+
background: var(--surface-4, transparent);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/* overlaid: caption floats over the content */
|
|
373
|
+
:host([caption-style="overlaid"]) .caption {
|
|
374
|
+
position: absolute;
|
|
375
|
+
left: 0;
|
|
376
|
+
right: 0;
|
|
377
|
+
bottom: 0;
|
|
378
|
+
color: #fff;
|
|
379
|
+
}
|
|
380
|
+
:host([caption-style="overlaid"][caption-position="top"]) .caption {
|
|
381
|
+
top: 0;
|
|
382
|
+
bottom: auto;
|
|
383
|
+
}
|
|
384
|
+
:host([caption-style="overlaid"][caption-position="middle"]) .caption {
|
|
385
|
+
top: 50%;
|
|
386
|
+
bottom: auto;
|
|
387
|
+
transform: translateY(-50%);
|
|
388
|
+
}
|
|
389
|
+
/* overlaid backdrop */
|
|
390
|
+
:host([caption-style="overlaid"][caption-backdrop="scrim"]) .caption {
|
|
391
|
+
background: rgba(0, 0, 0, 0.55);
|
|
392
|
+
}
|
|
393
|
+
:host([caption-style="overlaid"][caption-backdrop="gradient"]) .caption {
|
|
394
|
+
background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
|
|
395
|
+
padding-block: 10px 4px;
|
|
396
|
+
}
|
|
397
|
+
:host([caption-style="overlaid"][caption-backdrop="gradient"][caption-position="top"]) .caption {
|
|
398
|
+
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
|
|
399
|
+
padding-block: 4px 10px;
|
|
400
|
+
}
|
|
401
|
+
:host([caption-style="overlaid"][caption-backdrop="gradient"][caption-position="middle"]) .caption {
|
|
402
|
+
background: rgba(0, 0, 0, 0.5);
|
|
403
|
+
padding-block: 3px;
|
|
404
|
+
}
|
|
405
|
+
:host([caption-style="overlaid"][caption-backdrop="blur"]) .caption {
|
|
406
|
+
background: rgba(20, 20, 20, 0.3);
|
|
407
|
+
backdrop-filter: blur(6px);
|
|
408
|
+
-webkit-backdrop-filter: blur(6px);
|
|
409
|
+
}
|
|
410
|
+
:host([caption-style="overlaid"][caption-backdrop="none"]) .caption {
|
|
411
|
+
background: none;
|
|
412
|
+
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.7);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/* ---- separate mode: square + detached caption, each highlighted ---- */
|
|
416
|
+
:host([caption-style="separate"]) .thumb {
|
|
417
|
+
flex: none;
|
|
418
|
+
border-radius: var(--grid-list-radius);
|
|
419
|
+
background: var(--grid-list-item-bg);
|
|
420
|
+
border: 1px solid transparent;
|
|
421
|
+
}
|
|
422
|
+
:host([caption-style="separate"]) .cell:hover .thumb {
|
|
423
|
+
background: var(--item-bg-tickled);
|
|
424
|
+
border-color: var(--item-border-tickled);
|
|
425
|
+
}
|
|
426
|
+
:host([caption-style="separate"]) .caption {
|
|
427
|
+
display: flex;
|
|
428
|
+
align-items: center;
|
|
429
|
+
align-self: center;
|
|
430
|
+
max-width: 100%;
|
|
431
|
+
margin-top: 4px;
|
|
432
|
+
border-radius: var(--radius-s, 4px);
|
|
433
|
+
}
|
|
434
|
+
:host([caption-style="separate"][caption-align="left"]) .caption { align-self: flex-start; }
|
|
435
|
+
:host([caption-style="separate"][caption-align="right"]) .caption { align-self: flex-end; }
|
|
436
|
+
:host([caption-style="separate"]) .cell.selected .thumb,
|
|
437
|
+
:host([caption-style="separate"]) .cell.tickled .thumb {
|
|
438
|
+
outline: 2px solid var(--accent);
|
|
439
|
+
outline-offset: 2px;
|
|
440
|
+
}
|
|
441
|
+
:host([caption-style="separate"]) .cell.tickled .thumb {
|
|
442
|
+
outline-style: dashed;
|
|
443
|
+
}
|
|
444
|
+
:host([caption-style="separate"]) .cell.selected .caption {
|
|
445
|
+
background: var(--accent);
|
|
446
|
+
color: var(--accent-text, #000);
|
|
447
|
+
}
|
|
448
|
+
:host([caption-style="separate"]) .cell.tickled .caption {
|
|
449
|
+
outline: 1px dashed var(--accent);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/* ---- Insertion / removal animation ----
|
|
453
|
+
Active only while the host carries [reflowing] — the ~0.3s window after
|
|
454
|
+
the child list changes mid-list (see #noteChildMutation). Kept out of
|
|
455
|
+
the base rules so it never fires during scroll virtualisation, where
|
|
456
|
+
cells are recycled to wildly different positions every frame. Placed
|
|
457
|
+
last so it wins over the earlier cell transition rule regardless of
|
|
458
|
+
specificity. Survivors slide to their new slot; a freshly inserted cell
|
|
459
|
+
also fades in. (A removed item's element is already gone, so there's
|
|
460
|
+
nothing left to fade — the gap simply closes as the others slide.) */
|
|
461
|
+
:host([reflowing]) .cell {
|
|
462
|
+
transition:
|
|
463
|
+
transform var(--grid-list-item-move-duration, 200ms) cubic-bezier(0.2, 0, 0, 1),
|
|
464
|
+
background var(--transition),
|
|
465
|
+
border-color var(--transition);
|
|
466
|
+
}
|
|
467
|
+
.cell.entering {
|
|
468
|
+
animation: ixfx-list-item-in var(--grid-list-item-move-duration, 200ms) ease both;
|
|
469
|
+
}
|
|
470
|
+
@media (prefers-reduced-motion: reduce) {
|
|
471
|
+
:host([reflowing]) .cell { transition: background var(--transition), border-color var(--transition); }
|
|
472
|
+
.cell.entering { animation: none; }
|
|
473
|
+
}
|
|
474
|
+
`
|
|
475
|
+
];
|
|
476
|
+
}
|
|
477
|
+
#viewportRef;
|
|
478
|
+
#resizeObserver;
|
|
479
|
+
#mutationObserver;
|
|
480
|
+
#scrollRaf;
|
|
481
|
+
#items;
|
|
482
|
+
#itemWrap;
|
|
483
|
+
/** Items added mid-list that are still playing their enter animation. */
|
|
484
|
+
#entering;
|
|
485
|
+
/** Timer that ends the `[reflowing]` window opened by a mid-list insertion. */
|
|
486
|
+
#reflowTimer;
|
|
487
|
+
/**
|
|
488
|
+
* When cell geometry changes (zoom), the item nearest the viewport centre is
|
|
489
|
+
* captured here in `willUpdate` and the scroll position is corrected in
|
|
490
|
+
* `updated` so that item stays put — rather than the grid anchoring to its
|
|
491
|
+
* top-left corner.
|
|
492
|
+
*/
|
|
493
|
+
#zoomAnchor;
|
|
494
|
+
/**
|
|
495
|
+
* Per-item slot name. Each cell renders its own named `<slot>` and the
|
|
496
|
+
* matching light-DOM child carries `slot="<name>"`, so a child is projected
|
|
497
|
+
* into exactly one cell. (A single unnamed slot would collapse every child
|
|
498
|
+
* into the first cell.)
|
|
499
|
+
*/
|
|
500
|
+
#slotNames;
|
|
501
|
+
#slotSeq;
|
|
502
|
+
connectedCallback() {
|
|
503
|
+
super.connectedCallback();
|
|
504
|
+
if (!this.hasAttribute(`tabindex`)) this.tabIndex = 0;
|
|
505
|
+
for (const [attr, value] of [
|
|
506
|
+
[`caption-style`, this.captionStyle],
|
|
507
|
+
[`caption-align`, this.captionAlign],
|
|
508
|
+
[`caption-position`, this.captionPosition],
|
|
509
|
+
[`caption-backdrop`, this.captionBackdrop]
|
|
510
|
+
]) if (!this.hasAttribute(attr)) this.setAttribute(attr, value);
|
|
511
|
+
this.addEventListener(`keydown`, this._onKeyDown);
|
|
512
|
+
this.#mutationObserver ??= new MutationObserver((records) => this.#onChildrenChanged(records));
|
|
513
|
+
this.#mutationObserver.observe(this, { childList: true });
|
|
514
|
+
}
|
|
515
|
+
disconnectedCallback() {
|
|
516
|
+
super.disconnectedCallback();
|
|
517
|
+
this.removeEventListener(`keydown`, this._onKeyDown);
|
|
518
|
+
this.#resizeObserver?.disconnect();
|
|
519
|
+
this.#resizeObserver = void 0;
|
|
520
|
+
this.#mutationObserver?.disconnect();
|
|
521
|
+
this.#cancelScrollRaf();
|
|
522
|
+
if (this.#reflowTimer) {
|
|
523
|
+
clearTimeout(this.#reflowTimer);
|
|
524
|
+
this.#reflowTimer = 0;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
#onChildrenChanged(records) {
|
|
528
|
+
const previousLength = this.#items.length;
|
|
529
|
+
this.#syncItems();
|
|
530
|
+
this._syncItemStates();
|
|
531
|
+
this.#noteChildMutation(previousLength, records);
|
|
532
|
+
this.requestUpdate();
|
|
533
|
+
this.updateComplete.then(() => this.#emitViewportChange());
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* When the child list changes mid-list — not a first populate or a wholesale
|
|
537
|
+
* replace — mark any newcomers for an enter animation and open a short
|
|
538
|
+
* `[reflowing]` window so the cells that shift slide to their new position
|
|
539
|
+
* instead of snapping. Removals get the same window (the survivors slide to
|
|
540
|
+
* close the gap). The window is bounded in time so the transform transition
|
|
541
|
+
* never bleeds into scroll virtualisation.
|
|
542
|
+
*
|
|
543
|
+
* Reads the `MutationRecord`s directly rather than diffing `#items`, because a
|
|
544
|
+
* `requestUpdate()` between the DOM change and this callback (e.g. a caller
|
|
545
|
+
* that clears the selection before removing) lets `updated()` re-sync `#items`
|
|
546
|
+
* first, which would hide the change from a naive diff.
|
|
547
|
+
*/
|
|
548
|
+
#noteChildMutation(previousLength, records) {
|
|
549
|
+
if (!this.hasUpdated || !records || records.length === 0) return;
|
|
550
|
+
const currentSet = new Set(this.#items);
|
|
551
|
+
const added = [];
|
|
552
|
+
let removedCount = 0;
|
|
553
|
+
for (const record of records) {
|
|
554
|
+
for (const node of record.addedNodes) if (node.nodeType === Node.ELEMENT_NODE && currentSet.has(node)) added.push(node);
|
|
555
|
+
for (const node of record.removedNodes) if (node.nodeType === Node.ELEMENT_NODE) removedCount++;
|
|
556
|
+
}
|
|
557
|
+
if (added.length === 0 && removedCount === 0) return;
|
|
558
|
+
if (previousLength === 0 && removedCount === 0) return;
|
|
559
|
+
if (added.length > 0 && added.length === this.#items.length) return;
|
|
560
|
+
for (const el of added) this.#entering.add(el);
|
|
561
|
+
this.toggleAttribute(`reflowing`, true);
|
|
562
|
+
if (this.#reflowTimer) clearTimeout(this.#reflowTimer);
|
|
563
|
+
this.#reflowTimer = window.setTimeout(() => {
|
|
564
|
+
this.#reflowTimer = 0;
|
|
565
|
+
this.#entering.clear();
|
|
566
|
+
this.toggleAttribute(`reflowing`, false);
|
|
567
|
+
this.requestUpdate();
|
|
568
|
+
}, REFLOW_WINDOW_MS);
|
|
569
|
+
}
|
|
570
|
+
#emitViewportChange() {
|
|
571
|
+
this._dispatch(`grid-list-viewport-change`, { visibleKeys: this.visibleKeys() });
|
|
572
|
+
}
|
|
573
|
+
firstUpdated() {
|
|
574
|
+
const el = this.#viewportRef.value;
|
|
575
|
+
if (!el) return;
|
|
576
|
+
this._viewportWidth = el.clientWidth;
|
|
577
|
+
this._viewportHeight = el.clientHeight;
|
|
578
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
579
|
+
for (const entry of entries) {
|
|
580
|
+
this._viewportWidth = entry.contentRect.width;
|
|
581
|
+
this._viewportHeight = entry.contentRect.height;
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
this.#resizeObserver.observe(el);
|
|
585
|
+
this.#syncItems();
|
|
586
|
+
this.requestUpdate();
|
|
587
|
+
}
|
|
588
|
+
willUpdate(changed) {
|
|
589
|
+
if (changed.has(`itemSize`) || changed.has(`gap`)) {
|
|
590
|
+
this.itemSize = Math.max(MIN_ITEM_SIZE, Math.round(this.itemSize));
|
|
591
|
+
this.gap = Math.max(0, Math.round(this.gap));
|
|
592
|
+
}
|
|
593
|
+
if (changed.has(`captionHeight`)) this.captionHeight = Math.max(0, Math.round(this.captionHeight));
|
|
594
|
+
if (changed.has(`itemWrap`)) this.#itemWrap = this.itemWrap;
|
|
595
|
+
if ((changed.has(`itemSize`) || changed.has(`gap`) || changed.has(`captionStyle`) || changed.has(`captionHeight`) || changed.has(`orientation`)) && this.hasUpdated && this.#items.length > 0) {
|
|
596
|
+
const prevOrientation = changed.get(`orientation`) ?? this.orientation;
|
|
597
|
+
const horizontal = prevOrientation === `row`;
|
|
598
|
+
const prevOffset = horizontal ? this._scrollLeft : this._scrollTop;
|
|
599
|
+
const prevExtent = horizontal ? this._viewportWidth : this._viewportHeight;
|
|
600
|
+
if (prevExtent > 0 && prevOffset > 1) {
|
|
601
|
+
const prevItemSize = changed.get(`itemSize`) ?? this.itemSize;
|
|
602
|
+
const prevGap = changed.get(`gap`) ?? this.gap;
|
|
603
|
+
const prevCaptionStyle = changed.get(`captionStyle`) ?? this.captionStyle;
|
|
604
|
+
const prevCaptionHeight = changed.get(`captionHeight`) ?? this.captionHeight;
|
|
605
|
+
const prevRowHeight = prevItemSize + (prevCaptionStyle === `separate` || prevCaptionStyle === `under` ? prevCaptionHeight : 0);
|
|
606
|
+
const prev = computeGridWindow(this.#items.length, prevItemSize, prevRowHeight, prevGap, this._viewportWidth, this._viewportHeight, prevOffset, prevOrientation);
|
|
607
|
+
const mainStride = horizontal ? prev.colStride : prev.rowStride;
|
|
608
|
+
const centerLine = (prevOffset + prevExtent / 2) / mainStride;
|
|
609
|
+
const lineFloor = Math.max(0, Math.floor(centerLine));
|
|
610
|
+
const index = horizontal ? Math.min(this.#items.length - 1, lineFloor) : Math.min(this.#items.length - 1, lineFloor * prev.cols + Math.max(0, Math.floor((prev.cols - 1) / 2)));
|
|
611
|
+
this.#zoomAnchor = {
|
|
612
|
+
index,
|
|
613
|
+
lineFrac: centerLine - lineFloor
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
/** Full cell height: the square, plus a caption band in `separate` / `under`. */
|
|
619
|
+
#rowHeight() {
|
|
620
|
+
const captionBand = this.captionStyle === `separate` || this.captionStyle === `under`;
|
|
621
|
+
return this.itemSize + (captionBand ? this.captionHeight : 0);
|
|
622
|
+
}
|
|
623
|
+
#captionFor(el) {
|
|
624
|
+
return el.getAttribute(`data-label`) ?? el.querySelector(`[data-grid-list-caption]`)?.textContent?.trim() ?? ``;
|
|
625
|
+
}
|
|
626
|
+
updated(changed) {
|
|
627
|
+
super.updated(changed);
|
|
628
|
+
this.#syncItems();
|
|
629
|
+
if (changed.has(`selectionMode`) || changed.has(`interactionMode`)) this.selection.clearAnchor();
|
|
630
|
+
if (changed.has(`orientation`)) {
|
|
631
|
+
const vp = this.#viewportRef.value;
|
|
632
|
+
if (vp) {
|
|
633
|
+
if (this.orientation === `row`) {
|
|
634
|
+
vp.scrollTop = 0;
|
|
635
|
+
this._scrollTop = 0;
|
|
636
|
+
} else {
|
|
637
|
+
vp.scrollLeft = 0;
|
|
638
|
+
this._scrollLeft = 0;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
this.#applyZoomAnchor();
|
|
643
|
+
}
|
|
644
|
+
/** Re-anchor the scroll so the item captured in `willUpdate` stays centred. */
|
|
645
|
+
#applyZoomAnchor() {
|
|
646
|
+
if (!this.#zoomAnchor) return;
|
|
647
|
+
const { index, lineFrac } = this.#zoomAnchor;
|
|
648
|
+
this.#zoomAnchor = void 0;
|
|
649
|
+
const vp = this.#viewportRef.value;
|
|
650
|
+
if (!vp) return;
|
|
651
|
+
const win = this.#currentWindow();
|
|
652
|
+
if (win.horizontal) {
|
|
653
|
+
if (this._viewportWidth <= 0) return;
|
|
654
|
+
const targetCenter = (index + lineFrac) * win.colStride;
|
|
655
|
+
const maxScroll = Math.max(0, win.totalWidth - this._viewportWidth);
|
|
656
|
+
const next = Math.min(maxScroll, Math.max(0, targetCenter - this._viewportWidth / 2));
|
|
657
|
+
if (Math.abs(vp.scrollLeft - next) > .5) {
|
|
658
|
+
vp.scrollLeft = next;
|
|
659
|
+
this._scrollLeft = next;
|
|
660
|
+
}
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (this._viewportHeight <= 0) return;
|
|
664
|
+
const targetCenter = ((win.cols > 0 ? Math.floor(index / win.cols) : 0) + lineFrac) * win.rowStride;
|
|
665
|
+
const maxScroll = Math.max(0, win.totalHeight - this._viewportHeight);
|
|
666
|
+
const next = Math.min(maxScroll, Math.max(0, targetCenter - this._viewportHeight / 2));
|
|
667
|
+
if (Math.abs(vp.scrollTop - next) > .5) {
|
|
668
|
+
vp.scrollTop = next;
|
|
669
|
+
this._scrollTop = next;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
#syncItems() {
|
|
673
|
+
this.#items = Array.from(this.querySelectorAll(ITEM_SELECTOR));
|
|
674
|
+
for (const el of this.#items) {
|
|
675
|
+
const name = this.#slotNameFor(el);
|
|
676
|
+
if (el.getAttribute(`slot`) !== name) el.setAttribute(`slot`, name);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
#slotNameFor(el) {
|
|
680
|
+
let name = this.#slotNames.get(el);
|
|
681
|
+
if (name === void 0) {
|
|
682
|
+
this.#slotSeq += 1;
|
|
683
|
+
name = `gl-item-${this.#slotSeq}`;
|
|
684
|
+
this.#slotNames.set(el, name);
|
|
685
|
+
}
|
|
686
|
+
return name;
|
|
687
|
+
}
|
|
688
|
+
_getVisibleItems() {
|
|
689
|
+
return this.#items.filter((el) => {
|
|
690
|
+
if (el.hidden) return false;
|
|
691
|
+
return true;
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
get count() {
|
|
695
|
+
return this.#items.length;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Number of cells currently rendered in the shadow DOM. With virtualization
|
|
699
|
+
* this is roughly the visible rows plus overscan, regardless of how large
|
|
700
|
+
* `count` is — useful for demos/diagnostics.
|
|
701
|
+
*/
|
|
702
|
+
get renderedCount() {
|
|
703
|
+
return this.renderRoot.querySelectorAll(`.cell`).length;
|
|
704
|
+
}
|
|
705
|
+
get selectedItems() {
|
|
706
|
+
return this.selection.selected;
|
|
707
|
+
}
|
|
708
|
+
/** The selection as stable `data-key` / `data-value` strings. */
|
|
709
|
+
get selectedKeys() {
|
|
710
|
+
return this.selection.selectedKeys;
|
|
711
|
+
}
|
|
712
|
+
select(item) {
|
|
713
|
+
this.selection.replace(item);
|
|
714
|
+
}
|
|
715
|
+
selectMany(items) {
|
|
716
|
+
this.selection.selectMany(items);
|
|
717
|
+
}
|
|
718
|
+
deselect(item) {
|
|
719
|
+
this.selection.deselect(item);
|
|
720
|
+
}
|
|
721
|
+
clearSelection() {
|
|
722
|
+
this.selection.clear();
|
|
723
|
+
}
|
|
724
|
+
selectAll() {
|
|
725
|
+
if (this.selection.canSelectAll()) this.selection.selectAll();
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Replace the selection with the items carrying these keys. Unknown keys are
|
|
729
|
+
* ignored; survives the host rebuilding the item set. Requires each item to
|
|
730
|
+
* have a `data-key` (or `data-value`).
|
|
731
|
+
*/
|
|
732
|
+
selectKeys(keys) {
|
|
733
|
+
this.selection.selectKeys(keys, (key) => this.getItem(key));
|
|
734
|
+
}
|
|
735
|
+
/** Add items by key to the selection (multi-select modes only). */
|
|
736
|
+
addSelectedKeys(keys) {
|
|
737
|
+
this.selection.addKeys(keys, (key) => this.getItem(key));
|
|
738
|
+
}
|
|
739
|
+
/** Remove items by key from the selection. */
|
|
740
|
+
removeSelectedKeys(keys) {
|
|
741
|
+
this.selection.removeKeys(keys, (key) => this.getItem(key));
|
|
742
|
+
}
|
|
743
|
+
/** Move the cursor to the item with this key and scroll it into view. */
|
|
744
|
+
focusKey(key) {
|
|
745
|
+
const el = this.getItem(key);
|
|
746
|
+
if (!el) return;
|
|
747
|
+
this.tickled.focus(el);
|
|
748
|
+
this.#scrollItemIntoView(el);
|
|
749
|
+
}
|
|
750
|
+
/** The key of the item under the cursor, or `undefined`. */
|
|
751
|
+
get tickledKey() {
|
|
752
|
+
const id = this.tickled.tickledId;
|
|
753
|
+
return id ? keyForElement(id) : void 0;
|
|
754
|
+
}
|
|
755
|
+
getItem(key) {
|
|
756
|
+
return this.#items.find((el) => keyForElement(el) === key);
|
|
757
|
+
}
|
|
758
|
+
getItemByIndex(index) {
|
|
759
|
+
return this.#items[index];
|
|
760
|
+
}
|
|
761
|
+
getKey(item) {
|
|
762
|
+
return keyForElement(item);
|
|
763
|
+
}
|
|
764
|
+
visibleKeys() {
|
|
765
|
+
const win = this.#currentWindow();
|
|
766
|
+
return this.#items.slice(win.startIndex, win.endIndex).map((el) => keyForElement(el)).filter((k) => k !== void 0);
|
|
767
|
+
}
|
|
768
|
+
/** Adjust the scroll offset so `el` is fully within the viewport. */
|
|
769
|
+
#scrollItemIntoView(el) {
|
|
770
|
+
const index = this.#items.indexOf(el);
|
|
771
|
+
const vp = this.#viewportRef.value;
|
|
772
|
+
if (index < 0 || !vp) return;
|
|
773
|
+
const win = this.#currentWindow();
|
|
774
|
+
if (win.horizontal) {
|
|
775
|
+
const left = index * win.colStride;
|
|
776
|
+
const right = left + this.itemSize;
|
|
777
|
+
const viewLeft = vp.scrollLeft;
|
|
778
|
+
let next = viewLeft;
|
|
779
|
+
if (left < viewLeft) next = left;
|
|
780
|
+
else if (right > viewLeft + this._viewportWidth) next = right - this._viewportWidth;
|
|
781
|
+
if (next !== viewLeft) {
|
|
782
|
+
vp.scrollLeft = next;
|
|
783
|
+
this._scrollLeft = next;
|
|
784
|
+
}
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
const top = (win.cols > 0 ? Math.floor(index / win.cols) : 0) * win.rowStride;
|
|
788
|
+
const bottom = top + this.#rowHeight();
|
|
789
|
+
const viewTop = vp.scrollTop;
|
|
790
|
+
let next = viewTop;
|
|
791
|
+
if (top < viewTop) next = top;
|
|
792
|
+
else if (bottom > viewTop + this._viewportHeight) next = bottom - this._viewportHeight;
|
|
793
|
+
if (next !== viewTop) {
|
|
794
|
+
vp.scrollTop = next;
|
|
795
|
+
this._scrollTop = next;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
_syncItemStates() {
|
|
799
|
+
for (const el of this.#items) {
|
|
800
|
+
el.toggleAttribute(`data-tickled`, this.tickled.isTickled(el));
|
|
801
|
+
el.toggleAttribute(`data-selected`, this.selection.selected.has(el));
|
|
802
|
+
}
|
|
803
|
+
this.setAttribute(`data-input-mode`, this.tickled.inputMode);
|
|
804
|
+
}
|
|
805
|
+
_dispatch(name, detail) {
|
|
806
|
+
this.dispatchEvent(new CustomEvent(name, {
|
|
807
|
+
detail,
|
|
808
|
+
bubbles: true,
|
|
809
|
+
composed: true
|
|
810
|
+
}));
|
|
811
|
+
}
|
|
812
|
+
render() {
|
|
813
|
+
const win = this.#currentWindow();
|
|
814
|
+
const slice = this.#items.slice(win.startIndex, win.endIndex);
|
|
815
|
+
const spacerStyle = win.horizontal ? `width:${win.totalWidth}px;height:100%` : `height:${win.totalHeight}px`;
|
|
816
|
+
const scrollFade = win.horizontal ? `scroll-fade-x` : `scroll-fade-y`;
|
|
817
|
+
return html`
|
|
818
|
+
<div
|
|
819
|
+
class="viewport ${scrollFade}"
|
|
820
|
+
part="viewport"
|
|
821
|
+
${ref(this.#viewportRef)}
|
|
822
|
+
data-input-mode=${this.tickled.inputMode}
|
|
823
|
+
@scroll=${this.#onScroll}
|
|
824
|
+
>
|
|
825
|
+
<div class="spacer" style=${spacerStyle}>
|
|
826
|
+
${repeat(slice, (el) => this.#slotNameFor(el), (el, i) => this.#renderCell(el, win.startIndex + i, win))}
|
|
827
|
+
</div>
|
|
828
|
+
</div>
|
|
829
|
+
`;
|
|
830
|
+
}
|
|
831
|
+
#renderCell(el, index, win) {
|
|
832
|
+
const selected = this.selection.selected.has(el);
|
|
833
|
+
const tickled = this.tickled.isTickled(el);
|
|
834
|
+
const entering = this.#entering.has(el);
|
|
835
|
+
const style = this.captionStyle;
|
|
836
|
+
const separate = style === `separate`;
|
|
837
|
+
const caption = style === `hidden` ? `` : this.#captionFor(el);
|
|
838
|
+
const showCaption = caption !== ``;
|
|
839
|
+
const cellHeight = win.rowStride - this.gap;
|
|
840
|
+
const x = win.horizontal ? index * win.colStride : columnOf(index, win.cols) * win.colStride;
|
|
841
|
+
const y = win.horizontal ? Math.max(0, (this._viewportHeight - cellHeight) / 2) : rowOf(index, win.cols) * win.rowStride;
|
|
842
|
+
const thumbStyle = separate ? `height:${this.itemSize}px` : ``;
|
|
843
|
+
const captionCss = separate ? `height:${Math.max(0, this.captionHeight - 4)}px` : style === `under` ? `height:${this.captionHeight}px` : ``;
|
|
844
|
+
return html`
|
|
845
|
+
<div
|
|
846
|
+
class="cell${selected ? ` selected` : ``}${tickled ? ` tickled` : ``}${entering ? ` entering` : ``}"
|
|
847
|
+
part="item"
|
|
848
|
+
style="width:${this.itemSize}px;height:${cellHeight}px;transform:translate(${x}px,${y}px)"
|
|
849
|
+
data-index=${index}
|
|
850
|
+
@click=${(e) => this.#onCellClick(e, el)}
|
|
851
|
+
@dblclick=${() => this.#onCellActivate(el)}
|
|
852
|
+
@pointerenter=${() => this.tickled.handlePointerEnter(el)}
|
|
853
|
+
>
|
|
854
|
+
<div class="thumb" part="thumb" style=${thumbStyle}>
|
|
855
|
+
<slot name=${this.#slotNameFor(el)}></slot>
|
|
856
|
+
</div>
|
|
857
|
+
${showCaption ? html`<div class="caption" part="caption" style=${captionCss}>${caption}</div>` : ``}
|
|
858
|
+
</div>
|
|
859
|
+
`;
|
|
860
|
+
}
|
|
861
|
+
#onScroll;
|
|
862
|
+
#cancelScrollRaf() {
|
|
863
|
+
if (this.#scrollRaf !== 0) {
|
|
864
|
+
cancelAnimationFrame(this.#scrollRaf);
|
|
865
|
+
this.#scrollRaf = 0;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
#onCellClick(e, item) {
|
|
869
|
+
this.selection.handleClick(item, e);
|
|
870
|
+
this._dispatch(`list-item-click`, { item });
|
|
871
|
+
}
|
|
872
|
+
#onCellActivate(item) {
|
|
873
|
+
if (this.interactionMode !== `manual`) this.selection.replace(item);
|
|
874
|
+
this._dispatch(`list-activate`, { item });
|
|
875
|
+
}
|
|
876
|
+
#currentWindow() {
|
|
877
|
+
return computeGridWindow(this.#items.length, this.itemSize, this.#rowHeight(), this.gap, this._viewportWidth, this._viewportHeight, this.orientation === `row` ? this._scrollLeft : this._scrollTop, this.orientation);
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
__decorate([property({
|
|
881
|
+
type: String,
|
|
882
|
+
attribute: `selection-mode`
|
|
883
|
+
})], GridListElement.prototype, "selectionMode", void 0);
|
|
884
|
+
__decorate([property({
|
|
885
|
+
type: String,
|
|
886
|
+
attribute: `interaction-mode`
|
|
887
|
+
})], GridListElement.prototype, "interactionMode", void 0);
|
|
888
|
+
__decorate([property({
|
|
889
|
+
type: Number,
|
|
890
|
+
attribute: `item-size`
|
|
891
|
+
})], GridListElement.prototype, "itemSize", void 0);
|
|
892
|
+
__decorate([property({ type: Number })], GridListElement.prototype, "gap", void 0);
|
|
893
|
+
__decorate([property({
|
|
894
|
+
type: String,
|
|
895
|
+
reflect: true
|
|
896
|
+
})], GridListElement.prototype, "orientation", void 0);
|
|
897
|
+
__decorate([property({
|
|
898
|
+
type: String,
|
|
899
|
+
attribute: `caption-style`,
|
|
900
|
+
reflect: true
|
|
901
|
+
})], GridListElement.prototype, "captionStyle", void 0);
|
|
902
|
+
__decorate([property({
|
|
903
|
+
type: String,
|
|
904
|
+
attribute: `caption-align`,
|
|
905
|
+
reflect: true
|
|
906
|
+
})], GridListElement.prototype, "captionAlign", void 0);
|
|
907
|
+
__decorate([property({
|
|
908
|
+
type: String,
|
|
909
|
+
attribute: `caption-position`,
|
|
910
|
+
reflect: true
|
|
911
|
+
})], GridListElement.prototype, "captionPosition", void 0);
|
|
912
|
+
__decorate([property({
|
|
913
|
+
type: String,
|
|
914
|
+
attribute: `caption-backdrop`,
|
|
915
|
+
reflect: true
|
|
916
|
+
})], GridListElement.prototype, "captionBackdrop", void 0);
|
|
917
|
+
__decorate([property({
|
|
918
|
+
type: Number,
|
|
919
|
+
attribute: `caption-height`
|
|
920
|
+
})], GridListElement.prototype, "captionHeight", void 0);
|
|
921
|
+
__decorate([property({
|
|
922
|
+
type: String,
|
|
923
|
+
attribute: `item-wrap`
|
|
924
|
+
})], GridListElement.prototype, "itemWrap", void 0);
|
|
925
|
+
__decorate([state()], GridListElement.prototype, "_scrollTop", void 0);
|
|
926
|
+
__decorate([state()], GridListElement.prototype, "_scrollLeft", void 0);
|
|
927
|
+
__decorate([state()], GridListElement.prototype, "_viewportHeight", void 0);
|
|
928
|
+
__decorate([state()], GridListElement.prototype, "_viewportWidth", void 0);
|
|
929
|
+
GridListElement = __decorate([safeCustomElement(`ixfx-grid-list`)], GridListElement);
|
|
930
|
+
//#endregion
|
|
931
|
+
export { GridListElement };
|
|
932
|
+
|
|
933
|
+
//# sourceMappingURL=grid-list.js.map
|