@openelement/ui 1.0.0-alpha.15 → 1.0.0-alpha.16

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.
@@ -1,671 +1,141 @@
1
- import { readInstanceState, writeInstanceState } from "./instance-state.js";
2
- import { OpenElement, effect } from "@openelement/element";
3
- import overlayRecipe from "./overlay-recipe.css";
4
- import openDialogStyles from "./open-dialog.css";
1
+ import { defineComponentConfig } from "./component-config.js";
2
+ import { handleDialogCancel, handleDialogNativeClose, syncOpenDialog } from "./dialog-machine.js";
3
+ import { jsx, jsxs } from "@openelement/element/jsx-runtime";
4
+ import { onConnect, onPropertyChange } from "@openelement/element/lifecycle";
5
5
  //#region src/open-dialog.tsx
6
- const __partProgram = {
7
- "version": 2,
8
- "tag": "open-dialog",
9
- "root": {
10
- "id": "root",
11
- "kind": "shadow-open",
12
- "nodes": ["e0"]
13
- },
14
- "template": [{
15
- "k": "el",
16
- "id": "e0",
17
- "tag": "div",
18
- "attrs": [["style", "display:contents"]],
19
- "children": [{
20
- "k": "el",
21
- "id": "e1",
22
- "tag": "slot",
23
- "attrs": [["name", "trigger"]],
24
- "children": []
25
- }, {
26
- "k": "el",
27
- "id": "e2",
28
- "tag": "dialog",
29
- "attrs": [["class", "p-6 rounded-xl max-w-[min(90vw,480px)] font-sans"], ["part", "overlay"]],
30
- "children": [
31
- {
32
- "k": "el",
33
- "id": "e3",
34
- "tag": "div",
35
- "attrs": [["class", "dialog-header mb-4 flex items-center justify-between"], ["part", "header"]],
36
- "children": [{
37
- "k": "el",
38
- "id": "e4",
39
- "tag": "h2",
40
- "attrs": [["class", "dialog-title m-0 text-xl font-semibold text-foreground"]],
41
- "children": [{
42
- "k": "part",
43
- "id": "p5",
44
- "index": 5
45
- }]
46
- }, {
47
- "k": "el",
48
- "id": "e5",
49
- "tag": "button",
50
- "attrs": [
51
- ["type", "button"],
52
- ["class", "dialog-close cursor-pointer rounded-md border-0 bg-transparent p-1 text-xl leading-tight text-muted-foreground transition-colors duration-150 ease-out"],
53
- ["part", "close"],
54
- ["aria-label", "Close"]
55
- ],
56
- "children": [{
57
- "k": "text",
58
- "value": "×"
59
- }]
60
- }]
61
- },
62
- {
63
- "k": "el",
64
- "id": "e6",
65
- "tag": "div",
66
- "attrs": [["class", "dialog-body text-base leading-normal text-muted-foreground"], ["part", "body"]],
67
- "children": [{
68
- "k": "el",
69
- "id": "e7",
70
- "tag": "slot",
71
- "attrs": [],
72
- "children": []
73
- }]
74
- },
75
- {
76
- "k": "el",
77
- "id": "e8",
78
- "tag": "div",
79
- "attrs": [["class", "dialog-footer mt-5 flex justify-end gap-2"], ["part", "footer"]],
80
- "children": [{
81
- "k": "el",
82
- "id": "e9",
83
- "tag": "slot",
84
- "attrs": [["name", "footer"]],
85
- "children": []
86
- }]
87
- }
88
- ]
89
- }]
90
- }],
91
- "parts": [
92
- {
93
- "k": "event",
94
- "event": "click",
95
- "handler": "handleTrigger",
96
- "action": {
97
- "kind": "method",
98
- "name": "handleTrigger"
99
- },
100
- "path": [0, 0],
101
- "index": 0,
102
- "location": {
103
- "id": "p0",
104
- "kind": "sink",
105
- "path": [0, 0],
106
- "node": "e1"
107
- }
108
- },
109
- {
110
- "k": "bool",
111
- "signal": "open",
112
- "name": "open",
113
- "path": [0, 1],
114
- "index": 1,
115
- "location": {
116
- "id": "p1",
117
- "kind": "sink",
118
- "path": [0, 1],
119
- "node": "e2"
120
- }
121
- },
122
- {
123
- "k": "attr",
124
- "signal": "label",
125
- "name": "aria-label",
126
- "path": [0, 1],
127
- "index": 2,
128
- "location": {
129
- "id": "p2",
130
- "kind": "sink",
131
- "path": [0, 1],
132
- "node": "e2"
133
- }
134
- },
135
- {
136
- "k": "event",
137
- "event": "cancel",
138
- "handler": "handleCancel",
139
- "action": {
140
- "kind": "method",
141
- "name": "handleCancel"
142
- },
143
- "path": [0, 1],
144
- "index": 3,
145
- "location": {
146
- "id": "p3",
147
- "kind": "sink",
148
- "path": [0, 1],
149
- "node": "e2"
150
- }
151
- },
152
- {
153
- "k": "event",
154
- "event": "close",
155
- "handler": "handleNativeClose",
156
- "action": {
157
- "kind": "method",
158
- "name": "handleNativeClose"
159
- },
160
- "path": [0, 1],
161
- "index": 4,
162
- "location": {
163
- "id": "p4",
164
- "kind": "sink",
165
- "path": [0, 1],
166
- "node": "e2"
167
- }
168
- },
169
- {
170
- "k": "text",
171
- "signal": "label",
172
- "index": 5,
173
- "location": {
174
- "id": "p5",
175
- "kind": "anchor",
176
- "path": [
177
- 0,
178
- 1,
179
- 0,
180
- 0,
181
- 0
182
- ]
183
- }
184
- },
185
- {
186
- "k": "event",
187
- "event": "click",
188
- "handler": "handleClose",
189
- "action": {
190
- "kind": "method",
191
- "name": "handleClose"
192
- },
193
- "path": [
194
- 0,
195
- 1,
196
- 0,
197
- 1
198
- ],
199
- "index": 6,
200
- "location": {
201
- "id": "p6",
202
- "kind": "sink",
203
- "path": [
204
- 0,
205
- 1,
206
- 0,
207
- 1
208
- ],
209
- "node": "e5"
210
- }
211
- }
212
- ],
213
- "blocks": [],
214
- "dependencies": [
215
- {
216
- "signal": "open",
217
- "owner": {
218
- "kind": "part",
219
- "index": 1
220
- },
221
- "location": "p1"
222
- },
223
- {
224
- "signal": "label",
225
- "owner": {
226
- "kind": "part",
227
- "index": 2
228
- },
229
- "location": "p2"
230
- },
231
- {
232
- "signal": "label",
233
- "owner": {
234
- "kind": "part",
235
- "index": 5
236
- },
237
- "location": "p5"
238
- }
239
- ],
240
- "locations": [
241
- {
242
- "id": "e0",
243
- "kind": "element",
244
- "tag": "div",
245
- "path": [0]
246
- },
247
- {
248
- "id": "e1",
249
- "kind": "element",
250
- "tag": "slot",
251
- "path": [0, 0]
252
- },
253
- {
254
- "id": "p0",
255
- "kind": "sink",
256
- "part": 0,
257
- "node": "e1",
258
- "path": [0, 0]
259
- },
260
- {
261
- "id": "e2",
262
- "kind": "element",
263
- "tag": "dialog",
264
- "path": [0, 1]
265
- },
266
- {
267
- "id": "p1",
268
- "kind": "sink",
269
- "part": 1,
270
- "node": "e2",
271
- "path": [0, 1]
272
- },
273
- {
274
- "id": "p2",
275
- "kind": "sink",
276
- "part": 2,
277
- "node": "e2",
278
- "path": [0, 1]
279
- },
280
- {
281
- "id": "p3",
282
- "kind": "sink",
283
- "part": 3,
284
- "node": "e2",
285
- "path": [0, 1]
286
- },
287
- {
288
- "id": "p4",
289
- "kind": "sink",
290
- "part": 4,
291
- "node": "e2",
292
- "path": [0, 1]
293
- },
294
- {
295
- "id": "e3",
296
- "kind": "element",
297
- "tag": "div",
298
- "path": [
299
- 0,
300
- 1,
301
- 0
302
- ]
303
- },
304
- {
305
- "id": "e4",
306
- "kind": "element",
307
- "tag": "h2",
308
- "path": [
309
- 0,
310
- 1,
311
- 0,
312
- 0
313
- ]
314
- },
315
- {
316
- "id": "p5",
317
- "kind": "anchor",
318
- "part": 5,
319
- "path": [
320
- 0,
321
- 1,
322
- 0,
323
- 0,
324
- 0
325
- ]
326
- },
327
- {
328
- "id": "e5",
329
- "kind": "element",
330
- "tag": "button",
331
- "path": [
332
- 0,
333
- 1,
334
- 0,
335
- 1
336
- ]
337
- },
338
- {
339
- "id": "p6",
340
- "kind": "sink",
341
- "part": 6,
342
- "node": "e5",
343
- "path": [
344
- 0,
345
- 1,
346
- 0,
347
- 1
348
- ]
349
- },
350
- {
351
- "id": "e6",
352
- "kind": "element",
353
- "tag": "div",
354
- "path": [
355
- 0,
356
- 1,
357
- 1
358
- ]
359
- },
360
- {
361
- "id": "e7",
362
- "kind": "element",
363
- "tag": "slot",
364
- "path": [
365
- 0,
366
- 1,
367
- 1,
368
- 0
369
- ]
370
- },
371
- {
372
- "id": "e8",
373
- "kind": "element",
374
- "tag": "div",
375
- "path": [
376
- 0,
377
- 1,
378
- 2
379
- ]
380
- },
381
- {
382
- "id": "e9",
383
- "kind": "element",
384
- "tag": "slot",
385
- "path": [
386
- 0,
387
- 1,
388
- 2,
389
- 0
390
- ]
391
- }
392
- ],
393
- "metadata": {
394
- "tag": "open-dialog",
395
- "className": "OpenDialog",
396
- "sourceFile": "open-dialog.tsx",
397
- "properties": [{
398
- "name": "open",
399
- "attribute": "open",
400
- "type": "boolean",
401
- "converter": "boolean",
402
- "reflect": true,
403
- "default": false
404
- }, {
405
- "name": "label",
406
- "attribute": "label",
407
- "type": "string",
408
- "converter": "string",
409
- "reflect": false,
410
- "default": ""
411
- }],
412
- "observedAttributes": ["open", "label"],
413
- "cem": {
414
- "tagName": "open-dialog",
415
- "className": "OpenDialog",
416
- "declaration": {
417
- "name": "OpenDialog",
418
- "module": "open-dialog.tsx"
419
- },
420
- "attributes": [{
421
- "name": "open",
422
- "fieldName": "open",
423
- "type": "boolean",
424
- "reflect": true
425
- }, {
426
- "name": "label",
427
- "fieldName": "label",
428
- "type": "string",
429
- "reflect": false
430
- }],
431
- "members": [{
432
- "name": "open",
433
- "fieldName": "open",
434
- "type": "boolean",
435
- "attribute": "open",
436
- "reflect": true
437
- }, {
438
- "name": "label",
439
- "fieldName": "label",
440
- "type": "string",
441
- "attribute": "label",
442
- "reflect": false
443
- }]
444
- }
445
- }
446
- };
447
- const __compiledProperties = [{
448
- "name": "open",
449
- "attribute": "open",
450
- "type": "boolean",
451
- "converter": "boolean",
452
- "reflect": true,
453
- "default": false
454
- }, {
455
- "name": "label",
456
- "attribute": "label",
457
- "type": "string",
458
- "converter": "string",
459
- "reflect": false,
460
- "default": ""
461
- }];
462
- const __elementMetadata = {
463
- "tag": "open-dialog",
464
- "className": "OpenDialog",
465
- "sourceFile": "open-dialog.tsx",
466
- "properties": [{
467
- "name": "open",
468
- "attribute": "open",
469
- "type": "boolean",
470
- "converter": "boolean",
471
- "reflect": true,
472
- "default": false
473
- }, {
474
- "name": "label",
475
- "attribute": "label",
476
- "type": "string",
477
- "converter": "string",
478
- "reflect": false,
479
- "default": ""
480
- }],
481
- "observedAttributes": ["open", "label"],
482
- "cem": {
483
- "tagName": "open-dialog",
484
- "className": "OpenDialog",
485
- "declaration": {
486
- "name": "OpenDialog",
487
- "module": "open-dialog.tsx"
488
- },
489
- "attributes": [{
490
- "name": "open",
491
- "fieldName": "open",
492
- "type": "boolean",
493
- "reflect": true
494
- }, {
495
- "name": "label",
496
- "fieldName": "label",
497
- "type": "string",
498
- "reflect": false
499
- }],
500
- "members": [{
501
- "name": "open",
502
- "fieldName": "open",
503
- "type": "boolean",
504
- "attribute": "open",
505
- "reflect": true
506
- }, {
507
- "name": "label",
508
- "fieldName": "label",
509
- "type": "string",
510
- "attribute": "label",
511
- "reflect": false
512
- }]
513
- }
514
- };
515
- const __observedAttributes = ["open", "label"];
516
- const __compiledProps = {
517
- open: {
518
- type: Boolean,
519
- default: false,
520
- reflect: true,
521
- attribute: "open"
522
- },
523
- label: {
524
- type: String,
525
- default: "",
526
- reflect: false,
527
- attribute: "label"
528
- }
529
- };
530
- var OpenDialog = class extends OpenElement {
531
- static __partProgram = __partProgram;
532
- static __compiledProperties = __compiledProperties;
533
- static __elementMetadata = __elementMetadata;
534
- static props = __compiledProps;
535
- static observedAttributes = __observedAttributes;
536
- static delegatesFocus = true;
537
- static __oeUtilityClasses = true;
538
- static __oeClassCandidates = [
539
- "p-6",
540
- "rounded-xl",
541
- "max-w-[min(90vw,480px)]",
542
- "font-sans",
543
- "dialog-header",
544
- "mb-4",
545
- "flex",
546
- "items-center",
547
- "justify-between",
548
- "dialog-title",
549
- "m-0",
550
- "text-xl",
551
- "font-semibold",
552
- "text-foreground",
553
- "dialog-close",
554
- "cursor-pointer",
555
- "rounded-md",
556
- "border-0",
557
- "bg-transparent",
558
- "p-1",
559
- "leading-tight",
560
- "text-muted-foreground",
561
- "transition-colors",
562
- "duration-150",
563
- "ease-out",
564
- "dialog-body",
565
- "text-base",
566
- "leading-normal",
567
- "dialog-footer",
568
- "mt-5",
569
- "justify-end",
570
- "gap-2"
571
- ];
572
- static styles = [overlayRecipe, openDialogStyles];
573
- open = false;
574
- label = "";
575
- onCsrRendered() {
576
- this.syncOpenState();
577
- }
578
- onDsdHydrated() {
579
- this.syncOpenState();
580
- }
581
- disconnectedCallback() {
582
- try {
583
- readInstanceState(this, "openEffect", () => void 0)?.();
584
- writeInstanceState(this, "openEffect", void 0);
585
- super.disconnectedCallback();
586
- } catch (error) {
587
- if (!this._captureError(error)) throw error;
6
+ /**
7
+ * @openelement/ui - open-dialog
8
+ *
9
+ * Dialog component using native <dialog> element + popover API.
10
+ * Per WHATWG HTML Living Standard sections 4.11.4 (dialog) and 6.9.2 (popover).
11
+ *
12
+ * Experimental (owner ruling C1, #1468): no compatibility promise — may
13
+ * change or be removed before 1.0.
14
+ *
15
+ * Generated authoring. The `open` property drives the compiled bool sink on
16
+ * the inner <dialog> and the declared `label` drives the aria-label/text
17
+ * sinks; the top-layer/modal choreography (showModal/show/close) and the
18
+ * close-echo guards stay imperative in the dialog-machine module helper, run
19
+ * from the lifecycle intrinsics. The class lane's `show` / `close`
20
+ * / `toggle` methods are property sugar and are retired with the class export:
21
+ * drive the declared `open` property instead (`el.open = true`).
22
+ *
23
+ * @csspart overlay - The dialog backdrop/element
24
+ * @csspart header -The header bar
25
+ * @csspart close -The close button
26
+ * @csspart body -The content area (<slot>)
27
+ * @csspart footer -The optional footer slot
28
+ *
29
+ * Entry/exit transitions ride `transition-behavior: allow-discrete` +
30
+ * `@starting-style` (the allow-discrete dialog recipe, cf. upstream #591),
31
+ * so open AND close animate
32
+ * while the display flip and top-layer membership wait for the exit
33
+ * transition. Under `forced-colors: active` (and `prefers-reduced-motion`)
34
+ * the transitions collapse: the dialog appears and dismisses immediately
35
+ * instead of fighting the system-owned rendering.
36
+ *
37
+ * Usage:
38
+ * ```html
39
+ * <open-dialog label="Dialog title">
40
+ * <button slot="trigger">Open Dialog</button>
41
+ * <div>Dialog content here</div>
42
+ * </open-dialog>
43
+ * ```
44
+ *
45
+ * Attributes:
46
+ * - `open` - Presence opens the dialog (reflected into :state(open))
47
+ * - `label` - Title text and aria-label of the dialog
48
+ * - `close-label` - Accessible name of the close button (defaults to `Close`)
49
+ * - `mode` - `modal` (default, showModal()) or `non-modal` (show()); read at open time
50
+ */
51
+ /**
52
+ * Platform facts for the generated element: shadow root with delegated focus,
53
+ * the authored package stylesheets, and the declared property rows. Only
54
+ * `open` reflects property updates back to the attribute.
55
+ */
56
+ const openElement = /* @__PURE__ */ defineComponentConfig({
57
+ root: "shadow",
58
+ delegatesFocus: true,
59
+ styles: ["./overlay-recipe.css", "./open-dialog.css"],
60
+ properties: {
61
+ open: {
62
+ default: false,
63
+ reflect: true
64
+ },
65
+ label: { default: "" },
66
+ closeLabel: {
67
+ default: "Close",
68
+ attribute: "close-label"
588
69
  }
589
70
  }
590
- syncOpenState() {
591
- this.updateStates();
592
- this.syncDialogElement();
593
- const off = effect(() => {
594
- this.open;
595
- this.updateStates();
596
- this.syncDialogElement();
597
- });
598
- writeInstanceState(this, "openEffect", off);
599
- }
600
- updateStates() {
601
- const states = this.stateSet();
602
- if (!states) return;
603
- if (this.open) {
604
- states.add("open");
605
- states.delete("closed");
606
- } else {
607
- states.delete("open");
608
- states.add("closed");
609
- }
610
- }
611
- stateSet() {
612
- if (this._internals?.states) return this._internals.states;
613
- let internals = readInstanceState(this, "internals", () => void 0);
614
- if (!internals) {
615
- if (typeof this.attachInternals !== "function") return void 0;
616
- internals = this.attachInternals();
617
- writeInstanceState(this, "internals", internals);
618
- }
619
- return internals.states;
620
- }
621
- show() {
622
- this.open = true;
623
- }
624
- close() {
625
- this.open = false;
626
- }
627
- toggle() {
628
- this.open = !this.open;
629
- }
630
- syncDialogElement() {
631
- const dialog = this.shadowRoot?.querySelector("dialog");
632
- if (!dialog) return;
633
- const modalActive = readInstanceState(this, "modalActive", () => false);
634
- if (this.open) {
635
- if ((this.getAttribute("mode") || "modal") === "modal") {
636
- if (modalActive) return;
637
- if (dialog.open) dialog.close();
638
- dialog.showModal();
639
- writeInstanceState(this, "modalActive", true);
640
- } else if (!dialog.open) dialog.show();
641
- } else {
642
- if (modalActive && !dialog.open) dialog.setAttribute("open", "");
643
- if (dialog.open) dialog.close();
644
- writeInstanceState(this, "modalActive", false);
645
- }
646
- }
647
- handleNativeClose() {
648
- if ((this.shadowRoot?.querySelector("dialog"))?.open && this.open) return;
649
- if (!this.open) return;
650
- this.handleClose();
651
- }
652
- handleClose() {
653
- this.open = false;
654
- this.dispatchEvent(new CustomEvent("open-dialog-close", {
655
- bubbles: true,
656
- composed: true
657
- }));
658
- }
659
- handleCancel(e) {
660
- e.preventDefault();
661
- this.handleClose();
662
- }
663
- handleTrigger() {
664
- this.toggle();
665
- }
666
- render() {
667
- throw new Error("[open:compiled-element] open-dialog is compiled to a Part Program; the runtime JSX render path is not available.");
668
- }
669
- };
71
+ });
72
+ /** Dialog component using native <dialog> element + popover API. */
73
+ function OpenDialog(props) {
74
+ /** The host the inline handler's currentTarget belongs to. */
75
+ const hostOf = (event) => event.currentTarget.getRootNode().host;
76
+ onConnect((env) => {
77
+ const host = env.host;
78
+ globalThis.requestAnimationFrame(() => syncOpenDialog(host, env.states));
79
+ });
80
+ onPropertyChange((event) => {
81
+ if (event.name !== "open") return;
82
+ syncOpenDialog(event.host, event.states);
83
+ });
84
+ return /* @__PURE__ */ jsxs("div", {
85
+ style: "display:contents",
86
+ children: [/* @__PURE__ */ jsx("slot", {
87
+ name: "trigger",
88
+ onClick: (event) => {
89
+ const host = hostOf(event);
90
+ host.open = !host.open;
91
+ }
92
+ }), /* @__PURE__ */ jsxs("dialog", {
93
+ class: "p-6 rounded-xl max-w-[min(90vw,480px)] font-sans",
94
+ open: props.open,
95
+ "aria-label": props.label,
96
+ part: "overlay",
97
+ onCancel: (event) => handleDialogCancel(hostOf(event), event),
98
+ onClose: (event) => handleDialogNativeClose(hostOf(event)),
99
+ children: [
100
+ /* @__PURE__ */ jsxs("div", {
101
+ class: "dialog-header mb-4 flex items-center justify-between",
102
+ part: "header",
103
+ children: [/* @__PURE__ */ jsx("h2", {
104
+ class: "dialog-title m-0 text-xl font-semibold text-foreground",
105
+ children: props.label
106
+ }), /* @__PURE__ */ jsx("button", {
107
+ type: "button",
108
+ class: "dialog-close cursor-pointer rounded-md border-0 bg-transparent p-1 text-xl leading-tight text-muted-foreground transition-colors duration-150 ease-out",
109
+ part: "close",
110
+ "aria-label": props.closeLabel.trim() || "Close",
111
+ onClick: (event) => {
112
+ const host = hostOf(event);
113
+ host.open = false;
114
+ host.dispatchEvent(new globalThis.CustomEvent("open-dialog-close", {
115
+ bubbles: true,
116
+ composed: true
117
+ }));
118
+ },
119
+ children: "×"
120
+ })]
121
+ }),
122
+ /* @__PURE__ */ jsx("div", {
123
+ class: "dialog-body text-base leading-normal text-muted-foreground",
124
+ part: "body",
125
+ children: /* @__PURE__ */ jsx("slot", {})
126
+ }),
127
+ /* @__PURE__ */ jsx("div", {
128
+ class: "dialog-footer mt-5 flex justify-end gap-2",
129
+ part: "footer",
130
+ children: /* @__PURE__ */ jsx("slot", { name: "footer" })
131
+ })
132
+ ]
133
+ })]
134
+ });
135
+ }
670
136
  //#endregion
671
- export { OpenDialog, __elementMetadata, __partProgram };
137
+ export { OpenDialog as default, openElement };
138
+
139
+ export { OpenDialogElement, OpenDialog__ssrHost } from './open-dialog.generated.js';
140
+
141
+ // openElement:class-candidates ["bg-transparent","border-0","cursor-pointer","dialog-body","dialog-close","dialog-footer","dialog-header","dialog-title","duration-150","ease-out","flex","font-sans","font-semibold","gap-2","items-center","justify-between","justify-end","leading-normal","leading-tight","m-0","max-w-[min(90vw,480px)]","mb-4","mt-5","p-1","p-6","rounded-md","rounded-xl","text-base","text-foreground","text-muted-foreground","text-xl","transition-colors"]