@telperion/elements 1.2.1 → 2.0.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/.build-manifest.json +12 -1
- package/README.md +37 -0
- package/details-set/details-set-element.cjs +393 -0
- package/details-set/details-set-element.cjs.map +1 -0
- package/details-set/details-set-element.js +393 -0
- package/details-set/details-set-element.js.map +1 -0
- package/details-set/index.cjs +11 -0
- package/details-set/index.cjs.map +1 -0
- package/details-set/index.d.cts +117 -0
- package/details-set/index.d.ts +117 -0
- package/details-set/index.js +2 -0
- package/details-set/index.js.map +1 -0
- package/fesm/elements.mjs +388 -1
- package/fesm/elements.mjs.map +1 -1
- package/iife/details-set/index.js +35 -0
- package/iife/details-set/index.js.map +1 -0
- package/iife/elements.js +20 -20
- package/iife/elements.js.map +1 -1
- package/index.cjs +5 -0
- package/index.cjs.map +1 -1
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +23 -1
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { LitElement, html } from 'lit';
|
|
3
|
+
import { property, customElement } from 'lit/decorators.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Splice-style index resolution for `<template summary-marker index="…">`.
|
|
7
|
+
* - Missing / non-finite ⇒ `0` (prepend).
|
|
8
|
+
* - `>= 0` ⇒ clamped to `[0, length]`.
|
|
9
|
+
* - `< 0` ⇒ `length + raw`, clamped to `[0, length]` (so `-1` inserts
|
|
10
|
+
* before the last child).
|
|
11
|
+
*/
|
|
12
|
+
function resolveMarkerIndex(raw, length) {
|
|
13
|
+
if (raw === null || raw === "")
|
|
14
|
+
return 0;
|
|
15
|
+
const n = Number(raw);
|
|
16
|
+
if (!Number.isFinite(n))
|
|
17
|
+
return 0;
|
|
18
|
+
const i = Math.trunc(n);
|
|
19
|
+
if (i >= 0)
|
|
20
|
+
return Math.min(i, length);
|
|
21
|
+
return Math.max(0, length + i);
|
|
22
|
+
}
|
|
23
|
+
let DetailsSetElement = class DetailsSetElement extends LitElement {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
/**
|
|
27
|
+
* Maximum number of direct-child `<details>` allowed open at the same time.
|
|
28
|
+
* `0` (the default) means unlimited.
|
|
29
|
+
*/
|
|
30
|
+
this.maxOpenItems = 0;
|
|
31
|
+
/**
|
|
32
|
+
* Default trigger for toggling direct-child `<details>` elements:
|
|
33
|
+
*
|
|
34
|
+
* - `"summary"` (default): clicking anywhere on the `<summary>` toggles
|
|
35
|
+
* the details (native behavior).
|
|
36
|
+
* - `"marker"`: only clicks on (or inside) an element carrying the
|
|
37
|
+
* `tp-summary-marker` attribute toggle the details. If the summary has
|
|
38
|
+
* no marker, this falls back to summary toggle for that details so the
|
|
39
|
+
* details never becomes un-toggleable.
|
|
40
|
+
*
|
|
41
|
+
* Per-`<details>` `toggle-on` attribute overrides this set-level default.
|
|
42
|
+
* Keyboard activation (Enter/Space on a focused summary) is **never**
|
|
43
|
+
* suppressed, regardless of mode.
|
|
44
|
+
*/
|
|
45
|
+
this.toggleOn = "summary";
|
|
46
|
+
/** FIFO queue of currently-open direct-child `<details>` elements. */
|
|
47
|
+
this.#openOrder = [];
|
|
48
|
+
/** Per-child observers watching the `open` attribute. */
|
|
49
|
+
this.#childObservers = new Map();
|
|
50
|
+
/** Per-marker-template observers (content + `index` attribute changes). */
|
|
51
|
+
this.#markerObservers = new Map();
|
|
52
|
+
/**
|
|
53
|
+
* Tracks raw cloned marker nodes inserted into each summary, keyed by the
|
|
54
|
+
* source template, so re-syncs can remove and re-insert without leaving
|
|
55
|
+
* stale DOM behind.
|
|
56
|
+
*/
|
|
57
|
+
this.#insertedMarkers = new WeakMap();
|
|
58
|
+
this.#handleMarkerTemplateMutation = () => {
|
|
59
|
+
this.#syncAllMarkers();
|
|
60
|
+
};
|
|
61
|
+
this.#handleChildListMutation = () => {
|
|
62
|
+
this.#syncDirectChildren();
|
|
63
|
+
};
|
|
64
|
+
this.#handleToggle = (event) => {
|
|
65
|
+
const target = event.target;
|
|
66
|
+
if (!(target instanceof HTMLDetailsElement))
|
|
67
|
+
return;
|
|
68
|
+
if (target.parentElement !== this)
|
|
69
|
+
return;
|
|
70
|
+
this.#applyOpenState(target);
|
|
71
|
+
};
|
|
72
|
+
this.#handleChildOpenMutation = (child) => {
|
|
73
|
+
// Reconcile in case the `toggle` event was missed (e.g. in jsdom or when
|
|
74
|
+
// the `open` attribute is mutated programmatically without a toggle).
|
|
75
|
+
this.#applyOpenState(child);
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Capture-phase click handler that suppresses the native toggle when a
|
|
79
|
+
* `<summary>` is clicked outside its marker(s) and the effective
|
|
80
|
+
* `toggle-on` mode is `"marker"`.
|
|
81
|
+
*
|
|
82
|
+
* Resolution per `<details>`:
|
|
83
|
+
* - per-`<details>` `toggle-on` attribute (if `"summary"` or `"marker"`),
|
|
84
|
+
* else
|
|
85
|
+
* - the host's `toggle-on` property/attribute, else
|
|
86
|
+
* - `"summary"`.
|
|
87
|
+
*
|
|
88
|
+
* Carve-outs:
|
|
89
|
+
* - Keyboard activation (Enter/Space) produces a synthetic click with
|
|
90
|
+
* `event.detail === 0`; we never suppress those.
|
|
91
|
+
* - If the summary contains no `[tp-summary-marker]` element, fall back to
|
|
92
|
+
* summary-click toggle so the details cannot become un-toggleable.
|
|
93
|
+
*/
|
|
94
|
+
this.#handleSummaryClick = (event) => {
|
|
95
|
+
if (event.defaultPrevented)
|
|
96
|
+
return;
|
|
97
|
+
const target = event.target;
|
|
98
|
+
if (!(target instanceof Element))
|
|
99
|
+
return;
|
|
100
|
+
const summary = target.closest("summary");
|
|
101
|
+
if (!summary)
|
|
102
|
+
return;
|
|
103
|
+
const details = summary.parentElement;
|
|
104
|
+
if (!(details instanceof HTMLDetailsElement))
|
|
105
|
+
return;
|
|
106
|
+
if (details.parentElement !== this)
|
|
107
|
+
return;
|
|
108
|
+
// Only intercept clicks targeting the details' own first summary.
|
|
109
|
+
if (summary !== details.querySelector(":scope > summary"))
|
|
110
|
+
return;
|
|
111
|
+
const mode = this.#resolveToggleOn(details);
|
|
112
|
+
if (mode !== "marker")
|
|
113
|
+
return;
|
|
114
|
+
// Keyboard-originated synthetic click: never suppress.
|
|
115
|
+
if (event.detail === 0)
|
|
116
|
+
return;
|
|
117
|
+
// Fallback: if there is no marker in the summary, allow the native toggle
|
|
118
|
+
// so the details never becomes un-toggleable.
|
|
119
|
+
if (!summary.querySelector("[tp-summary-marker]"))
|
|
120
|
+
return;
|
|
121
|
+
if (target.closest("[tp-summary-marker]"))
|
|
122
|
+
return;
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
static {
|
|
127
|
+
const style = (this.GLOBAL_STYLE = document.createElement("style"));
|
|
128
|
+
style.textContent = `
|
|
129
|
+
tp-details-set {
|
|
130
|
+
display: block;
|
|
131
|
+
interpolate-size: allow-keywords;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
tp-details-set > details::details-content {
|
|
135
|
+
block-size: 0;
|
|
136
|
+
overflow: clip;
|
|
137
|
+
transition:
|
|
138
|
+
block-size var(--tp-details-set-transition-duration, 0.3s)
|
|
139
|
+
var(--tp-details-set-transition-easing, ease),
|
|
140
|
+
content-visibility var(--tp-details-set-transition-duration, 0.3s)
|
|
141
|
+
var(--tp-details-set-transition-easing, ease)
|
|
142
|
+
allow-discrete;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
tp-details-set > details[open]::details-content {
|
|
146
|
+
block-size: auto;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Hide the native disclosure marker when the consumer has supplied at
|
|
150
|
+
least one custom marker via <template summary-marker>. */
|
|
151
|
+
tp-details-set > details > summary:has(> [tp-summary-marker]) {
|
|
152
|
+
list-style: none;
|
|
153
|
+
}
|
|
154
|
+
tp-details-set > details > summary:has(> [tp-summary-marker])::-webkit-details-marker {
|
|
155
|
+
display: none;
|
|
156
|
+
}
|
|
157
|
+
tp-details-set > details > summary:has(> [tp-summary-marker])::marker {
|
|
158
|
+
content: "";
|
|
159
|
+
}
|
|
160
|
+
`;
|
|
161
|
+
document.head.appendChild(style);
|
|
162
|
+
}
|
|
163
|
+
/** FIFO queue of currently-open direct-child `<details>` elements. */
|
|
164
|
+
#openOrder;
|
|
165
|
+
/** Per-child observers watching the `open` attribute. */
|
|
166
|
+
#childObservers;
|
|
167
|
+
/** Observer watching `childList` changes on the host. */
|
|
168
|
+
#childListObserver;
|
|
169
|
+
/** Per-marker-template observers (content + `index` attribute changes). */
|
|
170
|
+
#markerObservers;
|
|
171
|
+
/**
|
|
172
|
+
* Tracks raw cloned marker nodes inserted into each summary, keyed by the
|
|
173
|
+
* source template, so re-syncs can remove and re-insert without leaving
|
|
174
|
+
* stale DOM behind.
|
|
175
|
+
*/
|
|
176
|
+
#insertedMarkers;
|
|
177
|
+
createRenderRoot() {
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
connectedCallback() {
|
|
181
|
+
super.connectedCallback();
|
|
182
|
+
// Capture-phase `toggle` listener: `toggle` does not bubble, but capture
|
|
183
|
+
// phase still reaches ancestors.
|
|
184
|
+
this.addEventListener("toggle", this.#handleToggle, { capture: true });
|
|
185
|
+
// Capture-phase click listener implements `toggle-on="marker"` by calling
|
|
186
|
+
// `preventDefault()` for non-marker clicks on summaries.
|
|
187
|
+
this.addEventListener("click", this.#handleSummaryClick, { capture: true });
|
|
188
|
+
this.#childListObserver = new MutationObserver(this.#handleChildListMutation);
|
|
189
|
+
this.#childListObserver.observe(this, { childList: true });
|
|
190
|
+
this.#syncDirectChildren();
|
|
191
|
+
}
|
|
192
|
+
disconnectedCallback() {
|
|
193
|
+
super.disconnectedCallback();
|
|
194
|
+
this.removeEventListener("toggle", this.#handleToggle, { capture: true });
|
|
195
|
+
this.removeEventListener("click", this.#handleSummaryClick, { capture: true });
|
|
196
|
+
this.#childListObserver?.disconnect();
|
|
197
|
+
this.#childListObserver = undefined;
|
|
198
|
+
for (const observer of this.#childObservers.values()) {
|
|
199
|
+
observer.disconnect();
|
|
200
|
+
}
|
|
201
|
+
this.#childObservers.clear();
|
|
202
|
+
for (const observer of this.#markerObservers.values()) {
|
|
203
|
+
observer.disconnect();
|
|
204
|
+
}
|
|
205
|
+
this.#markerObservers.clear();
|
|
206
|
+
this.#openOrder = [];
|
|
207
|
+
}
|
|
208
|
+
updated(changed) {
|
|
209
|
+
if (changed.has("maxOpenItems")) {
|
|
210
|
+
this.#enforceLimit();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
render() {
|
|
214
|
+
return html ``;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Reconcile observers and the FIFO queue with the current direct children.
|
|
218
|
+
* Called on connect and whenever the host's child list mutates.
|
|
219
|
+
*/
|
|
220
|
+
#syncDirectChildren() {
|
|
221
|
+
const current = new Set(this.#directDetails());
|
|
222
|
+
// Drop observers + queue entries for removed children.
|
|
223
|
+
for (const [child, observer] of this.#childObservers) {
|
|
224
|
+
if (!current.has(child)) {
|
|
225
|
+
observer.disconnect();
|
|
226
|
+
this.#childObservers.delete(child);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
this.#openOrder = this.#openOrder.filter((child) => current.has(child));
|
|
230
|
+
// Attach observers for new children, seed the queue with already-open ones.
|
|
231
|
+
for (const child of current) {
|
|
232
|
+
if (!this.#childObservers.has(child)) {
|
|
233
|
+
const observer = new MutationObserver(() => this.#handleChildOpenMutation(child));
|
|
234
|
+
observer.observe(child, { attributes: true, attributeFilter: ["open"] });
|
|
235
|
+
this.#childObservers.set(child, observer);
|
|
236
|
+
if (child.open && !this.#openOrder.includes(child)) {
|
|
237
|
+
this.#openOrder.push(child);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
this.#enforceLimit();
|
|
242
|
+
this.#syncMarkerTemplates();
|
|
243
|
+
this.#syncAllMarkers();
|
|
244
|
+
}
|
|
245
|
+
/** Reconcile per-template observers with the current marker templates. */
|
|
246
|
+
#syncMarkerTemplates() {
|
|
247
|
+
const current = new Set(this.#markerTemplates());
|
|
248
|
+
for (const [template, observer] of this.#markerObservers) {
|
|
249
|
+
if (!current.has(template)) {
|
|
250
|
+
observer.disconnect();
|
|
251
|
+
this.#markerObservers.delete(template);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
for (const template of current) {
|
|
255
|
+
if (!this.#markerObservers.has(template)) {
|
|
256
|
+
const observer = new MutationObserver(this.#handleMarkerTemplateMutation);
|
|
257
|
+
// Watch both the template's own `index` attribute and its content
|
|
258
|
+
// (including nested edits inside `template.content`).
|
|
259
|
+
observer.observe(template, {
|
|
260
|
+
attributes: true,
|
|
261
|
+
attributeFilter: ["index", "summary-marker"],
|
|
262
|
+
});
|
|
263
|
+
observer.observe(template.content, { childList: true, subtree: true, characterData: true, attributes: true });
|
|
264
|
+
this.#markerObservers.set(template, observer);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
#handleMarkerTemplateMutation;
|
|
269
|
+
/** Apply marker templates to every direct-child `<details>`'s `<summary>`. */
|
|
270
|
+
#syncAllMarkers() {
|
|
271
|
+
const templates = this.#markerTemplates();
|
|
272
|
+
for (const details of this.#directDetails()) {
|
|
273
|
+
const summary = details.querySelector(":scope > summary");
|
|
274
|
+
if (summary instanceof HTMLElement) {
|
|
275
|
+
this.#applyMarkersTo(summary, templates);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
#applyMarkersTo(summary, templates) {
|
|
280
|
+
let perTemplate = this.#insertedMarkers.get(summary);
|
|
281
|
+
if (!perTemplate) {
|
|
282
|
+
perTemplate = new Map();
|
|
283
|
+
this.#insertedMarkers.set(summary, perTemplate);
|
|
284
|
+
}
|
|
285
|
+
// Remove all previously-inserted marker nodes for this summary first, so
|
|
286
|
+
// re-application is order-stable and never duplicates.
|
|
287
|
+
for (const nodes of perTemplate.values()) {
|
|
288
|
+
for (const node of nodes) {
|
|
289
|
+
if (node.parentNode === summary)
|
|
290
|
+
summary.removeChild(node);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
perTemplate.clear();
|
|
294
|
+
for (const template of templates) {
|
|
295
|
+
const fragment = template.content.cloneNode(true);
|
|
296
|
+
// Capture nodes BEFORE insertion — the fragment empties on append.
|
|
297
|
+
const inserted = Array.from(fragment.childNodes);
|
|
298
|
+
if (inserted.length === 0)
|
|
299
|
+
continue;
|
|
300
|
+
// Tag every cloned element so consumers can target markers via CSS
|
|
301
|
+
// (e.g. `[tp-summary-marker]`) and so the host stylesheet can hide the
|
|
302
|
+
// native `::marker` on summaries that have a custom marker.
|
|
303
|
+
for (const node of inserted) {
|
|
304
|
+
if (node instanceof Element)
|
|
305
|
+
node.setAttribute("tp-summary-marker", "");
|
|
306
|
+
}
|
|
307
|
+
const idx = resolveMarkerIndex(template.getAttribute("index"), summary.childNodes.length);
|
|
308
|
+
const ref = summary.childNodes[idx] ?? null;
|
|
309
|
+
summary.insertBefore(fragment, ref);
|
|
310
|
+
perTemplate.set(template, inserted);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** Direct-child `<template>` elements with the `summary-marker` attribute. */
|
|
314
|
+
#markerTemplates() {
|
|
315
|
+
return Array.from(this.children).filter((c) => c instanceof HTMLTemplateElement && c.hasAttribute("summary-marker"));
|
|
316
|
+
}
|
|
317
|
+
#directDetails() {
|
|
318
|
+
return Array.from(this.children).filter((c) => c instanceof HTMLDetailsElement);
|
|
319
|
+
}
|
|
320
|
+
#handleChildListMutation;
|
|
321
|
+
#handleToggle;
|
|
322
|
+
#handleChildOpenMutation;
|
|
323
|
+
/**
|
|
324
|
+
* Capture-phase click handler that suppresses the native toggle when a
|
|
325
|
+
* `<summary>` is clicked outside its marker(s) and the effective
|
|
326
|
+
* `toggle-on` mode is `"marker"`.
|
|
327
|
+
*
|
|
328
|
+
* Resolution per `<details>`:
|
|
329
|
+
* - per-`<details>` `toggle-on` attribute (if `"summary"` or `"marker"`),
|
|
330
|
+
* else
|
|
331
|
+
* - the host's `toggle-on` property/attribute, else
|
|
332
|
+
* - `"summary"`.
|
|
333
|
+
*
|
|
334
|
+
* Carve-outs:
|
|
335
|
+
* - Keyboard activation (Enter/Space) produces a synthetic click with
|
|
336
|
+
* `event.detail === 0`; we never suppress those.
|
|
337
|
+
* - If the summary contains no `[tp-summary-marker]` element, fall back to
|
|
338
|
+
* summary-click toggle so the details cannot become un-toggleable.
|
|
339
|
+
*/
|
|
340
|
+
#handleSummaryClick;
|
|
341
|
+
#resolveToggleOn(details) {
|
|
342
|
+
const own = details.getAttribute("toggle-on");
|
|
343
|
+
if (own === "marker" || own === "summary")
|
|
344
|
+
return own;
|
|
345
|
+
return this.toggleOn === "marker" ? "marker" : "summary";
|
|
346
|
+
}
|
|
347
|
+
#applyOpenState(child) {
|
|
348
|
+
const inQueue = this.#openOrder.includes(child);
|
|
349
|
+
if (child.open && !inQueue) {
|
|
350
|
+
this.#openOrder.push(child);
|
|
351
|
+
this.#enforceLimit();
|
|
352
|
+
}
|
|
353
|
+
else if (!child.open && inQueue) {
|
|
354
|
+
this.#openOrder = this.#openOrder.filter((entry) => entry !== child);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
#enforceLimit() {
|
|
358
|
+
const limit = this.maxOpenItems;
|
|
359
|
+
if (!Number.isFinite(limit) || limit <= 0)
|
|
360
|
+
return;
|
|
361
|
+
const closed = [];
|
|
362
|
+
while (this.#openOrder.length > limit) {
|
|
363
|
+
const oldest = this.#openOrder.shift();
|
|
364
|
+
if (!oldest)
|
|
365
|
+
break;
|
|
366
|
+
if (oldest.open) {
|
|
367
|
+
oldest.open = false;
|
|
368
|
+
closed.push(oldest);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (closed.length > 0) {
|
|
372
|
+
this.dispatchEvent(new CustomEvent("tp-details-set-change", {
|
|
373
|
+
bubbles: true,
|
|
374
|
+
composed: true,
|
|
375
|
+
detail: { opened: [], closed },
|
|
376
|
+
}));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
__decorate([
|
|
381
|
+
property({ type: Number, reflect: true, attribute: "max-open-items" }),
|
|
382
|
+
__metadata("design:type", Object)
|
|
383
|
+
], DetailsSetElement.prototype, "maxOpenItems", void 0);
|
|
384
|
+
__decorate([
|
|
385
|
+
property({ reflect: true, attribute: "toggle-on" }),
|
|
386
|
+
__metadata("design:type", String)
|
|
387
|
+
], DetailsSetElement.prototype, "toggleOn", void 0);
|
|
388
|
+
DetailsSetElement = __decorate([
|
|
389
|
+
customElement("tp-details-set")
|
|
390
|
+
], DetailsSetElement);
|
|
391
|
+
|
|
392
|
+
export { DetailsSetElement };
|
|
393
|
+
//# sourceMappingURL=details-set-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"details-set-element.js","sources":["../../../../libs/elements/src/details-set/details-set-element.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;AAMG;AACH,SAAS,kBAAkB,CAAC,GAAkB,EAAE,MAAc,EAAA;AAC5D,IAAA,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE;AAAE,QAAA,OAAO,CAAC;AACxC,IAAA,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;AACrB,IAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;AAAE,QAAA,OAAO,CAAC;IACjC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACvB,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC;IACtC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAA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AACT,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAhEhC,iBAAiB,GAAA,UAAA,CAAA;IAD7B,aAAa,CAAC,gBAAgB;AAClB,CAAA,EAAA,iBAAiB,CA2X7B;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var detailsSetElement = require('./details-set-element.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "DetailsSetElement", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return detailsSetElement.DetailsSetElement; }
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElementTagNameMap {
|
|
5
|
+
/**
|
|
6
|
+
* A framework-agnostic grouping element for native `<details>` elements.
|
|
7
|
+
*
|
|
8
|
+
* Tracks the open/closed state of its **direct-child** `<details>` elements
|
|
9
|
+
* and enforces a configurable cap via the `max-open-items` attribute. When
|
|
10
|
+
* the cap is exceeded, the **earliest-opened** child is closed (FIFO).
|
|
11
|
+
*
|
|
12
|
+
* Renders into the **light DOM** so consumers retain full control over the
|
|
13
|
+
* styling of the slotted `<details>` / `<summary>` elements.
|
|
14
|
+
*
|
|
15
|
+
* Modern CSS defaults (smooth open/close via `interpolate-size: allow-keywords`
|
|
16
|
+
* + `::details-content` `block-size` transition) are injected once at the
|
|
17
|
+
* document level. Override timing via the
|
|
18
|
+
* `--tp-details-set-transition-duration` and
|
|
19
|
+
* `--tp-details-set-transition-easing` custom properties. In engines that
|
|
20
|
+
* do not yet support `interpolate-size` / `::details-content`, the
|
|
21
|
+
* animation is simply a no-op — the JS cap logic still works.
|
|
22
|
+
*
|
|
23
|
+
* Dispatches a bubbling `tp-details-set-change` `CustomEvent` whose
|
|
24
|
+
* `detail` is `{ opened: HTMLDetailsElement[]; closed: HTMLDetailsElement[] }`
|
|
25
|
+
* whenever the cap forces one or more children to close. Listen to the
|
|
26
|
+
* native `toggle` event on the children for ordinary open/close changes.
|
|
27
|
+
*
|
|
28
|
+
* @example Unlimited (the default)
|
|
29
|
+
* ```html
|
|
30
|
+
* <tp-details-set>
|
|
31
|
+
* <details><summary>One</summary>...</details>
|
|
32
|
+
* <details><summary>Two</summary>...</details>
|
|
33
|
+
* </tp-details-set>
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example Accordion
|
|
37
|
+
* ```html
|
|
38
|
+
* <tp-details-set max-open-items="1">
|
|
39
|
+
* <details><summary>One</summary>...</details>
|
|
40
|
+
* <details><summary>Two</summary>...</details>
|
|
41
|
+
* </tp-details-set>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example Two-at-a-time (FIFO)
|
|
45
|
+
* ```html
|
|
46
|
+
* <tp-details-set max-open-items="2">
|
|
47
|
+
* <details open><summary>A</summary>...</details>
|
|
48
|
+
* <details><summary>B</summary>...</details>
|
|
49
|
+
* <details><summary>C</summary>...</details>
|
|
50
|
+
* </tp-details-set>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Summary markers
|
|
54
|
+
* Direct-child `<template summary-marker index="…">` elements are cloned
|
|
55
|
+
* into every direct-child `<details>`'s `<summary>` at the position given
|
|
56
|
+
* by `index`. The index is splice-style: non-negative counts from the
|
|
57
|
+
* start (clamped to `[0, length]`), negative counts from the end (so
|
|
58
|
+
* `-1` inserts before the last child). Missing/invalid index defaults
|
|
59
|
+
* to `0`. Multiple marker templates apply in document order; each later
|
|
60
|
+
* marker sees the summary's current state (including markers already
|
|
61
|
+
* inserted by earlier templates) when computing its index.
|
|
62
|
+
* ```html
|
|
63
|
+
* <tp-details-set>
|
|
64
|
+
* <template summary-marker index="0"><span class="chev">▸</span></template>
|
|
65
|
+
* <template summary-marker index="-1"><span class="badge">★</span></template>
|
|
66
|
+
*
|
|
67
|
+
* <details><summary>One</summary>...</details>
|
|
68
|
+
* <details><summary>Two</summary>...</details>
|
|
69
|
+
* </tp-details-set>
|
|
70
|
+
* ```
|
|
71
|
+
* Use ordinary CSS for state-aware styling, e.g.
|
|
72
|
+
* `tp-details-set > details[open] > summary > .chev { rotate: 90deg; }`.
|
|
73
|
+
*
|
|
74
|
+
* @attr max-open-items - Maximum number of direct-child `<details>` allowed
|
|
75
|
+
* to be open simultaneously. `0` (or missing) means unlimited.
|
|
76
|
+
* @fires tp-details-set-change - When the set of open children changes.
|
|
77
|
+
*/
|
|
78
|
+
"tp-details-set": DetailsSetElement;
|
|
79
|
+
}
|
|
80
|
+
interface GlobalEventHandlersEventMap {
|
|
81
|
+
"tp-details-set-change": CustomEvent<{
|
|
82
|
+
opened: HTMLDetailsElement[];
|
|
83
|
+
closed: HTMLDetailsElement[];
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
declare class DetailsSetElement extends LitElement {
|
|
88
|
+
#private;
|
|
89
|
+
private static GLOBAL_STYLE;
|
|
90
|
+
/**
|
|
91
|
+
* Maximum number of direct-child `<details>` allowed open at the same time.
|
|
92
|
+
* `0` (the default) means unlimited.
|
|
93
|
+
*/
|
|
94
|
+
maxOpenItems: number;
|
|
95
|
+
/**
|
|
96
|
+
* Default trigger for toggling direct-child `<details>` elements:
|
|
97
|
+
*
|
|
98
|
+
* - `"summary"` (default): clicking anywhere on the `<summary>` toggles
|
|
99
|
+
* the details (native behavior).
|
|
100
|
+
* - `"marker"`: only clicks on (or inside) an element carrying the
|
|
101
|
+
* `tp-summary-marker` attribute toggle the details. If the summary has
|
|
102
|
+
* no marker, this falls back to summary toggle for that details so the
|
|
103
|
+
* details never becomes un-toggleable.
|
|
104
|
+
*
|
|
105
|
+
* Per-`<details>` `toggle-on` attribute overrides this set-level default.
|
|
106
|
+
* Keyboard activation (Enter/Space on a focused summary) is **never**
|
|
107
|
+
* suppressed, regardless of mode.
|
|
108
|
+
*/
|
|
109
|
+
toggleOn: "summary" | "marker";
|
|
110
|
+
protected createRenderRoot(): HTMLElement;
|
|
111
|
+
connectedCallback(): void;
|
|
112
|
+
disconnectedCallback(): void;
|
|
113
|
+
protected updated(changed: Map<string, unknown>): void;
|
|
114
|
+
protected render(): TemplateResult;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { DetailsSetElement };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElementTagNameMap {
|
|
5
|
+
/**
|
|
6
|
+
* A framework-agnostic grouping element for native `<details>` elements.
|
|
7
|
+
*
|
|
8
|
+
* Tracks the open/closed state of its **direct-child** `<details>` elements
|
|
9
|
+
* and enforces a configurable cap via the `max-open-items` attribute. When
|
|
10
|
+
* the cap is exceeded, the **earliest-opened** child is closed (FIFO).
|
|
11
|
+
*
|
|
12
|
+
* Renders into the **light DOM** so consumers retain full control over the
|
|
13
|
+
* styling of the slotted `<details>` / `<summary>` elements.
|
|
14
|
+
*
|
|
15
|
+
* Modern CSS defaults (smooth open/close via `interpolate-size: allow-keywords`
|
|
16
|
+
* + `::details-content` `block-size` transition) are injected once at the
|
|
17
|
+
* document level. Override timing via the
|
|
18
|
+
* `--tp-details-set-transition-duration` and
|
|
19
|
+
* `--tp-details-set-transition-easing` custom properties. In engines that
|
|
20
|
+
* do not yet support `interpolate-size` / `::details-content`, the
|
|
21
|
+
* animation is simply a no-op — the JS cap logic still works.
|
|
22
|
+
*
|
|
23
|
+
* Dispatches a bubbling `tp-details-set-change` `CustomEvent` whose
|
|
24
|
+
* `detail` is `{ opened: HTMLDetailsElement[]; closed: HTMLDetailsElement[] }`
|
|
25
|
+
* whenever the cap forces one or more children to close. Listen to the
|
|
26
|
+
* native `toggle` event on the children for ordinary open/close changes.
|
|
27
|
+
*
|
|
28
|
+
* @example Unlimited (the default)
|
|
29
|
+
* ```html
|
|
30
|
+
* <tp-details-set>
|
|
31
|
+
* <details><summary>One</summary>...</details>
|
|
32
|
+
* <details><summary>Two</summary>...</details>
|
|
33
|
+
* </tp-details-set>
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example Accordion
|
|
37
|
+
* ```html
|
|
38
|
+
* <tp-details-set max-open-items="1">
|
|
39
|
+
* <details><summary>One</summary>...</details>
|
|
40
|
+
* <details><summary>Two</summary>...</details>
|
|
41
|
+
* </tp-details-set>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example Two-at-a-time (FIFO)
|
|
45
|
+
* ```html
|
|
46
|
+
* <tp-details-set max-open-items="2">
|
|
47
|
+
* <details open><summary>A</summary>...</details>
|
|
48
|
+
* <details><summary>B</summary>...</details>
|
|
49
|
+
* <details><summary>C</summary>...</details>
|
|
50
|
+
* </tp-details-set>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Summary markers
|
|
54
|
+
* Direct-child `<template summary-marker index="…">` elements are cloned
|
|
55
|
+
* into every direct-child `<details>`'s `<summary>` at the position given
|
|
56
|
+
* by `index`. The index is splice-style: non-negative counts from the
|
|
57
|
+
* start (clamped to `[0, length]`), negative counts from the end (so
|
|
58
|
+
* `-1` inserts before the last child). Missing/invalid index defaults
|
|
59
|
+
* to `0`. Multiple marker templates apply in document order; each later
|
|
60
|
+
* marker sees the summary's current state (including markers already
|
|
61
|
+
* inserted by earlier templates) when computing its index.
|
|
62
|
+
* ```html
|
|
63
|
+
* <tp-details-set>
|
|
64
|
+
* <template summary-marker index="0"><span class="chev">▸</span></template>
|
|
65
|
+
* <template summary-marker index="-1"><span class="badge">★</span></template>
|
|
66
|
+
*
|
|
67
|
+
* <details><summary>One</summary>...</details>
|
|
68
|
+
* <details><summary>Two</summary>...</details>
|
|
69
|
+
* </tp-details-set>
|
|
70
|
+
* ```
|
|
71
|
+
* Use ordinary CSS for state-aware styling, e.g.
|
|
72
|
+
* `tp-details-set > details[open] > summary > .chev { rotate: 90deg; }`.
|
|
73
|
+
*
|
|
74
|
+
* @attr max-open-items - Maximum number of direct-child `<details>` allowed
|
|
75
|
+
* to be open simultaneously. `0` (or missing) means unlimited.
|
|
76
|
+
* @fires tp-details-set-change - When the set of open children changes.
|
|
77
|
+
*/
|
|
78
|
+
"tp-details-set": DetailsSetElement;
|
|
79
|
+
}
|
|
80
|
+
interface GlobalEventHandlersEventMap {
|
|
81
|
+
"tp-details-set-change": CustomEvent<{
|
|
82
|
+
opened: HTMLDetailsElement[];
|
|
83
|
+
closed: HTMLDetailsElement[];
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
declare class DetailsSetElement extends LitElement {
|
|
88
|
+
#private;
|
|
89
|
+
private static GLOBAL_STYLE;
|
|
90
|
+
/**
|
|
91
|
+
* Maximum number of direct-child `<details>` allowed open at the same time.
|
|
92
|
+
* `0` (the default) means unlimited.
|
|
93
|
+
*/
|
|
94
|
+
maxOpenItems: number;
|
|
95
|
+
/**
|
|
96
|
+
* Default trigger for toggling direct-child `<details>` elements:
|
|
97
|
+
*
|
|
98
|
+
* - `"summary"` (default): clicking anywhere on the `<summary>` toggles
|
|
99
|
+
* the details (native behavior).
|
|
100
|
+
* - `"marker"`: only clicks on (or inside) an element carrying the
|
|
101
|
+
* `tp-summary-marker` attribute toggle the details. If the summary has
|
|
102
|
+
* no marker, this falls back to summary toggle for that details so the
|
|
103
|
+
* details never becomes un-toggleable.
|
|
104
|
+
*
|
|
105
|
+
* Per-`<details>` `toggle-on` attribute overrides this set-level default.
|
|
106
|
+
* Keyboard activation (Enter/Space on a focused summary) is **never**
|
|
107
|
+
* suppressed, regardless of mode.
|
|
108
|
+
*/
|
|
109
|
+
toggleOn: "summary" | "marker";
|
|
110
|
+
protected createRenderRoot(): HTMLElement;
|
|
111
|
+
connectedCallback(): void;
|
|
112
|
+
disconnectedCallback(): void;
|
|
113
|
+
protected updated(changed: Map<string, unknown>): void;
|
|
114
|
+
protected render(): TemplateResult;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { DetailsSetElement };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|