@openelement/ui 1.0.0-alpha.6 → 1.0.0-alpha.7

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/src/open-tabs.js CHANGED
@@ -1,283 +1,236 @@
1
- // <auto-generated by open:compiled-element; part-program format 1 / module ABI 1 - do not edit>
2
- import { effect, OpenElement } from '@openelement/element';
3
- import { nextInstanceId, recipe } from './component-recipes.js';
4
- import { readInstanceState, writeInstanceState } from './instance-state.js';
1
+ import { readInstanceState, writeInstanceState } from "./instance-state.js";
2
+ import { nextInstanceId, recipe } from "./component-recipes.js";
3
+ import { OpenElement, effect } from "@openelement/element";
4
+ //#region src/open-tabs.tsx
5
5
  const __partProgram = {
6
- "version": 1,
7
- "tag": "open-tabs",
8
- "root": {
9
- "id": "root",
10
- "kind": "shadow-open",
11
- "nodes": [
12
- "e0"
13
- ]
14
- },
15
- "template": [
16
- {
17
- "k": "el",
18
- "id": "e0",
19
- "tag": "div",
20
- "attrs": [],
21
- "children": [
22
- {
23
- "k": "el",
24
- "id": "e1",
25
- "tag": "div",
26
- "attrs": [
27
- [
28
- "class",
29
- "tabs"
30
- ],
31
- [
32
- "role",
33
- "tablist"
34
- ]
35
- ],
36
- "children": [
37
- {
38
- "k": "el",
39
- "id": "e2",
40
- "tag": "slot",
41
- "attrs": [
42
- [
43
- "name",
44
- "tab"
45
- ]
46
- ],
47
- "children": []
48
- }
49
- ]
50
- },
51
- {
52
- "k": "el",
53
- "id": "e3",
54
- "tag": "slot",
55
- "attrs": [
56
- [
57
- "name",
58
- "panel"
59
- ]
60
- ],
61
- "children": []
62
- }
63
- ]
64
- }
65
- ],
66
- "parts": [
67
- {
68
- "k": "event",
69
- "event": "keydown",
70
- "handler": "onKeydown",
71
- "action": {
72
- "kind": "method",
73
- "name": "onKeydown"
74
- },
75
- "path": [
76
- 0,
77
- 0
78
- ],
79
- "index": 0,
80
- "location": {
81
- "id": "p0",
82
- "kind": "sink",
83
- "path": [
84
- 0,
85
- 0
86
- ],
87
- "node": "e1"
88
- }
89
- }
90
- ],
91
- "regions": [],
92
- "dependencies": [],
93
- "locations": [
94
- {
95
- "id": "e0",
96
- "kind": "element",
97
- "tag": "div",
98
- "path": [
99
- 0
100
- ]
101
- },
102
- {
103
- "id": "e1",
104
- "kind": "element",
105
- "tag": "div",
106
- "path": [
107
- 0,
108
- 0
109
- ]
110
- },
111
- {
112
- "id": "p0",
113
- "kind": "sink",
114
- "part": 0,
115
- "node": "e1",
116
- "path": [
117
- 0,
118
- 0
119
- ]
120
- },
121
- {
122
- "id": "e2",
123
- "kind": "element",
124
- "tag": "slot",
125
- "path": [
126
- 0,
127
- 0,
128
- 0
129
- ]
130
- },
131
- {
132
- "id": "e3",
133
- "kind": "element",
134
- "tag": "slot",
135
- "path": [
136
- 0,
137
- 1
138
- ]
139
- }
140
- ],
141
- "metadata": {
142
- "tag": "open-tabs",
143
- "className": "OpenTabs",
144
- "sourceFile": "open-tabs.tsx",
145
- "properties": [
146
- {
147
- "name": "active",
148
- "attribute": null,
149
- "type": "number",
150
- "converter": "number",
151
- "reflect": false,
152
- "default": 0
153
- },
154
- {
155
- "name": "tabsId",
156
- "attribute": null,
157
- "type": "string",
158
- "converter": "string",
159
- "reflect": false,
160
- "default": ""
161
- }
162
- ],
163
- "observedAttributes": [],
164
- "cem": {
165
- "tagName": "open-tabs",
166
- "className": "OpenTabs",
167
- "declaration": {
168
- "name": "OpenTabs",
169
- "module": "open-tabs.tsx"
170
- },
171
- "attributes": [],
172
- "members": [
173
- {
174
- "name": "active",
175
- "fieldName": "active",
176
- "type": "number",
177
- "attribute": null,
178
- "reflect": false
179
- },
180
- {
181
- "name": "tabsId",
182
- "fieldName": "tabsId",
183
- "type": "string",
184
- "attribute": null,
185
- "reflect": false
186
- }
187
- ]
188
- }
189
- }
6
+ "version": 1,
7
+ "tag": "open-tabs",
8
+ "root": {
9
+ "id": "root",
10
+ "kind": "shadow-open",
11
+ "nodes": ["e0"]
12
+ },
13
+ "template": [{
14
+ "k": "el",
15
+ "id": "e0",
16
+ "tag": "div",
17
+ "attrs": [],
18
+ "children": [{
19
+ "k": "el",
20
+ "id": "e1",
21
+ "tag": "div",
22
+ "attrs": [["class", "tabs"], ["role", "tablist"]],
23
+ "children": [{
24
+ "k": "el",
25
+ "id": "e2",
26
+ "tag": "slot",
27
+ "attrs": [["name", "tab"]],
28
+ "children": []
29
+ }]
30
+ }, {
31
+ "k": "el",
32
+ "id": "e3",
33
+ "tag": "slot",
34
+ "attrs": [["name", "panel"]],
35
+ "children": []
36
+ }]
37
+ }],
38
+ "parts": [{
39
+ "k": "event",
40
+ "event": "keydown",
41
+ "handler": "onKeydown",
42
+ "action": {
43
+ "kind": "method",
44
+ "name": "onKeydown"
45
+ },
46
+ "path": [0, 0],
47
+ "index": 0,
48
+ "location": {
49
+ "id": "p0",
50
+ "kind": "sink",
51
+ "path": [0, 0],
52
+ "node": "e1"
53
+ }
54
+ }],
55
+ "regions": [],
56
+ "dependencies": [],
57
+ "locations": [
58
+ {
59
+ "id": "e0",
60
+ "kind": "element",
61
+ "tag": "div",
62
+ "path": [0]
63
+ },
64
+ {
65
+ "id": "e1",
66
+ "kind": "element",
67
+ "tag": "div",
68
+ "path": [0, 0]
69
+ },
70
+ {
71
+ "id": "p0",
72
+ "kind": "sink",
73
+ "part": 0,
74
+ "node": "e1",
75
+ "path": [0, 0]
76
+ },
77
+ {
78
+ "id": "e2",
79
+ "kind": "element",
80
+ "tag": "slot",
81
+ "path": [
82
+ 0,
83
+ 0,
84
+ 0
85
+ ]
86
+ },
87
+ {
88
+ "id": "e3",
89
+ "kind": "element",
90
+ "tag": "slot",
91
+ "path": [0, 1]
92
+ }
93
+ ],
94
+ "metadata": {
95
+ "tag": "open-tabs",
96
+ "className": "OpenTabs",
97
+ "sourceFile": "open-tabs.tsx",
98
+ "properties": [{
99
+ "name": "active",
100
+ "attribute": null,
101
+ "type": "number",
102
+ "converter": "number",
103
+ "reflect": false,
104
+ "default": 0
105
+ }, {
106
+ "name": "tabsId",
107
+ "attribute": null,
108
+ "type": "string",
109
+ "converter": "string",
110
+ "reflect": false,
111
+ "default": ""
112
+ }],
113
+ "observedAttributes": [],
114
+ "cem": {
115
+ "tagName": "open-tabs",
116
+ "className": "OpenTabs",
117
+ "declaration": {
118
+ "name": "OpenTabs",
119
+ "module": "open-tabs.tsx"
120
+ },
121
+ "attributes": [],
122
+ "members": [{
123
+ "name": "active",
124
+ "fieldName": "active",
125
+ "type": "number",
126
+ "attribute": null,
127
+ "reflect": false
128
+ }, {
129
+ "name": "tabsId",
130
+ "fieldName": "tabsId",
131
+ "type": "string",
132
+ "attribute": null,
133
+ "reflect": false
134
+ }]
135
+ }
136
+ }
190
137
  };
191
- const __compiledProperties = [
192
- {
193
- "name": "active",
194
- "attribute": null,
195
- "type": "number",
196
- "converter": "number",
197
- "reflect": false,
198
- "default": 0
199
- },
200
- {
201
- "name": "tabsId",
202
- "attribute": null,
203
- "type": "string",
204
- "converter": "string",
205
- "reflect": false,
206
- "default": ""
207
- }
208
- ];
138
+ const __compiledProperties = [{
139
+ "name": "active",
140
+ "attribute": null,
141
+ "type": "number",
142
+ "converter": "number",
143
+ "reflect": false,
144
+ "default": 0
145
+ }, {
146
+ "name": "tabsId",
147
+ "attribute": null,
148
+ "type": "string",
149
+ "converter": "string",
150
+ "reflect": false,
151
+ "default": ""
152
+ }];
209
153
  const __elementMetadata = {
210
- "tag": "open-tabs",
211
- "className": "OpenTabs",
212
- "sourceFile": "open-tabs.tsx",
213
- "properties": [
214
- {
215
- "name": "active",
216
- "attribute": null,
217
- "type": "number",
218
- "converter": "number",
219
- "reflect": false,
220
- "default": 0
221
- },
222
- {
223
- "name": "tabsId",
224
- "attribute": null,
225
- "type": "string",
226
- "converter": "string",
227
- "reflect": false,
228
- "default": ""
229
- }
230
- ],
231
- "observedAttributes": [],
232
- "cem": {
233
- "tagName": "open-tabs",
234
- "className": "OpenTabs",
235
- "declaration": {
236
- "name": "OpenTabs",
237
- "module": "open-tabs.tsx"
238
- },
239
- "attributes": [],
240
- "members": [
241
- {
242
- "name": "active",
243
- "fieldName": "active",
244
- "type": "number",
245
- "attribute": null,
246
- "reflect": false
247
- },
248
- {
249
- "name": "tabsId",
250
- "fieldName": "tabsId",
251
- "type": "string",
252
- "attribute": null,
253
- "reflect": false
254
- }
255
- ]
256
- }
154
+ "tag": "open-tabs",
155
+ "className": "OpenTabs",
156
+ "sourceFile": "open-tabs.tsx",
157
+ "properties": [{
158
+ "name": "active",
159
+ "attribute": null,
160
+ "type": "number",
161
+ "converter": "number",
162
+ "reflect": false,
163
+ "default": 0
164
+ }, {
165
+ "name": "tabsId",
166
+ "attribute": null,
167
+ "type": "string",
168
+ "converter": "string",
169
+ "reflect": false,
170
+ "default": ""
171
+ }],
172
+ "observedAttributes": [],
173
+ "cem": {
174
+ "tagName": "open-tabs",
175
+ "className": "OpenTabs",
176
+ "declaration": {
177
+ "name": "OpenTabs",
178
+ "module": "open-tabs.tsx"
179
+ },
180
+ "attributes": [],
181
+ "members": [{
182
+ "name": "active",
183
+ "fieldName": "active",
184
+ "type": "number",
185
+ "attribute": null,
186
+ "reflect": false
187
+ }, {
188
+ "name": "tabsId",
189
+ "fieldName": "tabsId",
190
+ "type": "string",
191
+ "attribute": null,
192
+ "reflect": false
193
+ }]
194
+ }
257
195
  };
258
196
  const __observedAttributes = [];
259
197
  const __compiledProps = {
260
- active: {
261
- type: Number,
262
- default: 0,
263
- reflect: false,
264
- attribute: false
265
- },
266
- tabsId: {
267
- type: String,
268
- default: '',
269
- reflect: false,
270
- attribute: false
271
- }
198
+ active: {
199
+ type: Number,
200
+ default: 0,
201
+ reflect: false,
202
+ attribute: false
203
+ },
204
+ tabsId: {
205
+ type: String,
206
+ default: "",
207
+ reflect: false,
208
+ attribute: false
209
+ }
272
210
  };
273
- export class OpenTabs extends OpenElement {
274
- static __partProgram = __partProgram;
275
- static __compiledProperties = __compiledProperties;
276
- static __elementMetadata = __elementMetadata;
277
- static props = __compiledProps;
278
- static observedAttributes = __observedAttributes;
279
- static styles = [
280
- recipe(`
211
+ var OpenTabs = class extends OpenElement {
212
+ constructor(..._args) {
213
+ super(..._args);
214
+ this.active = 0;
215
+ this.tabsId = "";
216
+ }
217
+ static {
218
+ this.__partProgram = __partProgram;
219
+ }
220
+ static {
221
+ this.__compiledProperties = __compiledProperties;
222
+ }
223
+ static {
224
+ this.__elementMetadata = __elementMetadata;
225
+ }
226
+ static {
227
+ this.props = __compiledProps;
228
+ }
229
+ static {
230
+ this.observedAttributes = __observedAttributes;
231
+ }
232
+ static {
233
+ this.styles = [recipe(`
281
234
  :host {
282
235
  display: block;
283
236
  }
@@ -311,91 +264,83 @@ export class OpenTabs extends OpenElement {
311
264
  padding-block: var(--size-4);
312
265
  color: var(--text-secondary);
313
266
  }
314
- `)
315
- ];
316
- active = 0;
317
- tabsId = '';
318
- onDsdHydrated() {
319
- this.activate();
320
- }
321
- onCsrRendered() {
322
- this.activate();
323
- }
324
- disconnectedCallback() {
325
- readInstanceState(this, 'decorateEffect', ()=>undefined)?.();
326
- writeInstanceState(this, 'decorateEffect', undefined);
327
- super.disconnectedCallback();
328
- }
329
- activate() {
330
- if (this.tabsId === '') this.tabsId = `open-tabs-${nextInstanceId()}`;
331
- // The decorate effect re-runs when the compiled `active` signal changes;
332
- // its first synchronous run applies the initial wiring.
333
- const off = effect(()=>{
334
- void this.active;
335
- this.decorate();
336
- });
337
- writeInstanceState(this, 'decorateEffect', off);
338
- }
339
- tabs() {
340
- return [
341
- ...this.querySelectorAll('[slot="tab"]')
342
- ];
343
- }
344
- count() {
345
- return Math.min(this.tabs().length, this.querySelectorAll('[slot="panel"]').length);
346
- }
347
- select(idx) {
348
- this.active = idx;
349
- }
350
- onKeydown(e) {
351
- const count = this.count();
352
- if (count === 0) return;
353
- const key = e.key;
354
- const next = key === 'Home' ? 0 : key === 'End' ? count - 1 : key === 'ArrowLeft' ? (this.active - 1 + count) % count : key === 'ArrowRight' ? (this.active + 1) % count : undefined;
355
- if (next === undefined) return;
356
- e.preventDefault();
357
- this.select(next);
358
- // Selection follows focus: move DOM focus onto the newly active tab.
359
- const tab = this.tabs()[next];
360
- if (tab && typeof tab.focus === 'function') tab.focus();
361
- }
362
- decorate() {
363
- const tabs = this.tabs();
364
- const panels = [
365
- ...this.querySelectorAll('[slot="panel"]')
366
- ];
367
- const count = Math.min(tabs.length, panels.length);
368
- const active = this.active;
369
- const prefix = this.tabsId;
370
- const wired = readInstanceState(this, 'wiredTabs', ()=>new WeakSet());
371
- tabs.forEach((tab, i)=>{
372
- const enabled = i < count;
373
- tab.setAttribute('role', 'tab');
374
- tab.setAttribute('id', `${prefix}-tab-${i}`);
375
- tab.setAttribute('aria-selected', i === active && enabled ? 'true' : 'false');
376
- tab.setAttribute('aria-controls', `${prefix}-panel-${i}`);
377
- tab.setAttribute('tabindex', i === active ? '0' : '-1');
378
- tab.classList.toggle('tab-active', i === active);
379
- if (enabled) tab.removeAttribute('aria-disabled');
380
- else tab.setAttribute('aria-disabled', 'true');
381
- if (!wired.has(tab)) {
382
- wired.add(tab);
383
- tab.addEventListener('click', ()=>{
384
- const idx = this.tabs().indexOf(tab);
385
- if (idx >= 0 && idx < this.count()) this.select(idx);
386
- });
387
- }
388
- });
389
- panels.forEach((panel, i)=>{
390
- panel.setAttribute('role', 'tabpanel');
391
- panel.setAttribute('id', `${prefix}-panel-${i}`);
392
- panel.setAttribute('aria-labelledby', `${prefix}-tab-${i}`);
393
- if (i === active) panel.removeAttribute('hidden');
394
- else panel.setAttribute('hidden', '');
395
- });
396
- }
397
- render() {
398
- throw new Error('[open:compiled-element] open-tabs is compiled to a Part Program; the runtime JSX render path is not available.');
399
- }
400
- }
401
- export { __partProgram, __elementMetadata };
267
+ `)];
268
+ }
269
+ onDsdHydrated() {
270
+ this.activate();
271
+ }
272
+ onCsrRendered() {
273
+ this.activate();
274
+ }
275
+ disconnectedCallback() {
276
+ readInstanceState(this, "decorateEffect", () => void 0)?.();
277
+ writeInstanceState(this, "decorateEffect", void 0);
278
+ super.disconnectedCallback();
279
+ }
280
+ activate() {
281
+ if (this.tabsId === "") this.tabsId = `open-tabs-${nextInstanceId()}`;
282
+ const off = effect(() => {
283
+ this.active;
284
+ this.decorate();
285
+ });
286
+ writeInstanceState(this, "decorateEffect", off);
287
+ }
288
+ tabs() {
289
+ return [...this.querySelectorAll("[slot=\"tab\"]")];
290
+ }
291
+ count() {
292
+ return Math.min(this.tabs().length, this.querySelectorAll("[slot=\"panel\"]").length);
293
+ }
294
+ select(idx) {
295
+ this.active = idx;
296
+ }
297
+ onKeydown(e) {
298
+ const count = this.count();
299
+ if (count === 0) return;
300
+ const key = e.key;
301
+ const next = key === "Home" ? 0 : key === "End" ? count - 1 : key === "ArrowLeft" ? (this.active - 1 + count) % count : key === "ArrowRight" ? (this.active + 1) % count : void 0;
302
+ if (next === void 0) return;
303
+ e.preventDefault();
304
+ this.select(next);
305
+ const tab = this.tabs()[next];
306
+ if (tab && typeof tab.focus === "function") tab.focus();
307
+ }
308
+ decorate() {
309
+ const tabs = this.tabs();
310
+ const panels = [...this.querySelectorAll("[slot=\"panel\"]")];
311
+ const count = Math.min(tabs.length, panels.length);
312
+ const active = this.active;
313
+ const prefix = this.tabsId;
314
+ const wired = readInstanceState(this, "wiredTabs", () => /* @__PURE__ */ new WeakSet());
315
+ tabs.forEach((tab, i) => {
316
+ const enabled = i < count;
317
+ tab.setAttribute("role", "tab");
318
+ tab.setAttribute("id", `${prefix}-tab-${i}`);
319
+ tab.setAttribute("aria-selected", i === active && enabled ? "true" : "false");
320
+ tab.setAttribute("aria-controls", `${prefix}-panel-${i}`);
321
+ tab.setAttribute("tabindex", i === active ? "0" : "-1");
322
+ tab.classList.toggle("tab-active", i === active);
323
+ if (enabled) tab.removeAttribute("aria-disabled");
324
+ else tab.setAttribute("aria-disabled", "true");
325
+ if (!wired.has(tab)) {
326
+ wired.add(tab);
327
+ tab.addEventListener("click", () => {
328
+ const idx = this.tabs().indexOf(tab);
329
+ if (idx >= 0 && idx < this.count()) this.select(idx);
330
+ });
331
+ }
332
+ });
333
+ panels.forEach((panel, i) => {
334
+ panel.setAttribute("role", "tabpanel");
335
+ panel.setAttribute("id", `${prefix}-panel-${i}`);
336
+ panel.setAttribute("aria-labelledby", `${prefix}-tab-${i}`);
337
+ if (i === active) panel.removeAttribute("hidden");
338
+ else panel.setAttribute("hidden", "");
339
+ });
340
+ }
341
+ render() {
342
+ throw new Error("[open:compiled-element] open-tabs is compiled to a Part Program; the runtime JSX render path is not available.");
343
+ }
344
+ };
345
+ //#endregion
346
+ export { OpenTabs, __elementMetadata, __partProgram };