@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,369 +1,78 @@
1
- import { readInstanceState, writeInstanceState } from "./instance-state.js";
2
- import { deepActiveElement, nextInstanceId } from "./component-recipes.js";
3
- import { OpenElement, computed } from "@openelement/element";
4
- import overlayRecipe from "./overlay-recipe.css";
5
- import openDropdownStyles from "./open-dropdown.css";
1
+ import { defineComponentConfig } from "./component-config.js";
2
+ import { activateDropdown, clearDropdownPositionAnchor, clearDropdownTriggerAria, disposeDropdownFocusWiring, recordDropdownPointerDown, syncDropdownAnchor, toggleDropdown } from "./dropdown-machine.js";
3
+ import { jsx, jsxs } from "@openelement/element/jsx-runtime";
4
+ import { onConnect, onDispose, onPropertyChange } from "@openelement/element/lifecycle";
6
5
  //#region src/open-dropdown.tsx
7
- const __partProgram = {
8
- "version": 2,
9
- "tag": "open-dropdown",
10
- "root": {
11
- "id": "root",
12
- "kind": "shadow-open",
13
- "nodes": ["e0"]
14
- },
15
- "template": [{
16
- "k": "el",
17
- "id": "e0",
18
- "tag": "div",
19
- "attrs": [],
20
- "children": [{
21
- "k": "el",
22
- "id": "e1",
23
- "tag": "span",
24
- "attrs": [["class", "trigger contents"], ["part", "trigger"]],
25
- "children": [{
26
- "k": "el",
27
- "id": "e2",
28
- "tag": "slot",
29
- "attrs": [["name", "trigger"]],
30
- "children": []
31
- }]
32
- }, {
33
- "k": "el",
34
- "id": "e3",
35
- "tag": "div",
36
- "attrs": [
37
- ["class", "overlay content min-w-48 p-2 font-sans"],
38
- ["part", "content"],
39
- ["popover", "auto"]
40
- ],
41
- "children": [{
42
- "k": "el",
43
- "id": "e4",
44
- "tag": "slot",
45
- "attrs": [],
46
- "children": []
47
- }]
48
- }]
49
- }],
50
- "parts": [
51
- {
52
- "k": "event",
53
- "event": "pointerdown",
54
- "handler": "onTriggerPointerDown",
55
- "action": {
56
- "kind": "method",
57
- "name": "onTriggerPointerDown"
58
- },
59
- "path": [0, 0],
60
- "index": 0,
61
- "location": {
62
- "id": "p0",
63
- "kind": "sink",
64
- "path": [0, 0],
65
- "node": "e1"
66
- }
67
- },
68
- {
69
- "k": "event",
70
- "event": "click",
71
- "handler": "toggle",
72
- "action": {
73
- "kind": "method",
74
- "name": "toggle"
75
- },
76
- "path": [0, 0],
77
- "index": 1,
78
- "location": {
79
- "id": "p1",
80
- "kind": "sink",
81
- "path": [0, 0],
82
- "node": "e1"
83
- }
84
- },
85
- {
86
- "k": "style",
87
- "signal": "anchorStyle",
88
- "path": [0, 1],
89
- "index": 2,
90
- "location": {
91
- "id": "p2",
92
- "kind": "sink",
93
- "path": [0, 1],
94
- "node": "e3"
95
- }
96
- }
97
- ],
98
- "blocks": [],
99
- "dependencies": [{
100
- "signal": "anchorStyle",
101
- "owner": {
102
- "kind": "part",
103
- "index": 2
104
- },
105
- "location": "p2"
106
- }],
107
- "locations": [
108
- {
109
- "id": "e0",
110
- "kind": "element",
111
- "tag": "div",
112
- "path": [0]
113
- },
114
- {
115
- "id": "e1",
116
- "kind": "element",
117
- "tag": "span",
118
- "path": [0, 0]
119
- },
120
- {
121
- "id": "p0",
122
- "kind": "sink",
123
- "part": 0,
124
- "node": "e1",
125
- "path": [0, 0]
126
- },
127
- {
128
- "id": "p1",
129
- "kind": "sink",
130
- "part": 1,
131
- "node": "e1",
132
- "path": [0, 0]
133
- },
134
- {
135
- "id": "e2",
136
- "kind": "element",
137
- "tag": "slot",
138
- "path": [
139
- 0,
140
- 0,
141
- 0
142
- ]
143
- },
144
- {
145
- "id": "e3",
146
- "kind": "element",
147
- "tag": "div",
148
- "path": [0, 1]
149
- },
150
- {
151
- "id": "p2",
152
- "kind": "sink",
153
- "part": 2,
154
- "node": "e3",
155
- "path": [0, 1]
156
- },
157
- {
158
- "id": "e4",
159
- "kind": "element",
160
- "tag": "slot",
161
- "path": [
162
- 0,
163
- 1,
164
- 0
165
- ]
166
- }
167
- ],
168
- "metadata": {
169
- "tag": "open-dropdown",
170
- "className": "OpenDropdown",
171
- "sourceFile": "open-dropdown.tsx",
172
- "properties": [{
173
- "name": "anchorName",
174
- "attribute": null,
175
- "type": "string",
176
- "converter": "string",
177
- "reflect": false,
178
- "default": ""
179
- }, {
180
- "name": "anchorStyle",
181
- "attribute": null,
182
- "type": "string",
183
- "converter": "string",
184
- "reflect": false,
185
- "default": null,
186
- "computed": true,
187
- "deps": ["anchorName"]
188
- }],
189
- "observedAttributes": [],
190
- "cem": {
191
- "tagName": "open-dropdown",
192
- "className": "OpenDropdown",
193
- "declaration": {
194
- "name": "OpenDropdown",
195
- "module": "open-dropdown.tsx"
196
- },
197
- "attributes": [],
198
- "members": [{
199
- "name": "anchorName",
200
- "fieldName": "anchorName",
201
- "type": "string",
202
- "attribute": null,
203
- "reflect": false
204
- }, {
205
- "name": "anchorStyle",
206
- "fieldName": "anchorStyle",
207
- "type": "string",
208
- "attribute": null,
209
- "reflect": false
210
- }]
211
- }
212
- }
213
- };
214
- const __compiledProperties = [{
215
- "name": "anchorName",
216
- "attribute": null,
217
- "type": "string",
218
- "converter": "string",
219
- "reflect": false,
220
- "default": ""
221
- }, {
222
- "name": "anchorStyle",
223
- "attribute": null,
224
- "type": "string",
225
- "converter": "string",
226
- "reflect": false,
227
- "default": null,
228
- "computed": true,
229
- "deps": ["anchorName"]
230
- }];
231
- const __elementMetadata = {
232
- "tag": "open-dropdown",
233
- "className": "OpenDropdown",
234
- "sourceFile": "open-dropdown.tsx",
235
- "properties": [{
236
- "name": "anchorName",
237
- "attribute": null,
238
- "type": "string",
239
- "converter": "string",
240
- "reflect": false,
241
- "default": ""
242
- }, {
243
- "name": "anchorStyle",
244
- "attribute": null,
245
- "type": "string",
246
- "converter": "string",
247
- "reflect": false,
248
- "default": null,
249
- "computed": true,
250
- "deps": ["anchorName"]
251
- }],
252
- "observedAttributes": [],
253
- "cem": {
254
- "tagName": "open-dropdown",
255
- "className": "OpenDropdown",
256
- "declaration": {
257
- "name": "OpenDropdown",
258
- "module": "open-dropdown.tsx"
259
- },
260
- "attributes": [],
261
- "members": [{
262
- "name": "anchorName",
263
- "fieldName": "anchorName",
264
- "type": "string",
265
- "attribute": null,
266
- "reflect": false
267
- }, {
268
- "name": "anchorStyle",
269
- "fieldName": "anchorStyle",
270
- "type": "string",
271
- "attribute": null,
272
- "reflect": false
273
- }]
274
- }
275
- };
276
- const __observedAttributes = [];
277
- const __compiledProps = {
278
- anchorName: {
279
- type: String,
6
+ /**
7
+ * @openelement/ui - open-dropdown
8
+ * Popover-API dropdown with CSS Anchor Positioning placement.
9
+ * The content is a native popover (top layer, built-in light dismiss and
10
+ * focus return); placement anchors to the host, no hand-rolled fallback.
11
+ *
12
+ * Experimental (owner ruling C1, #1468): no compatibility promise — may
13
+ * change or be removed before 1.0.
14
+ *
15
+ * Generated authoring. The compiled template carries the trigger span and the
16
+ * native popover content; the realm-unique anchor-name assignment and the
17
+ * cross-shadow focus-return restoration stay imperative in the
18
+ * dropdown-machine module helper, run from the lifecycle intrinsics.
19
+ * The class lane's `anchorStyle` readonly signal — a derived
20
+ * `position-anchor: ${anchorName}` — is retired with the class export: the
21
+ * activation helper applies both anchor halves imperatively, and a consumer
22
+ * who needs the value derives it from the declared `anchorName` property.
23
+ *
24
+ * @slot trigger - Control used to toggle the dropdown
25
+ * @slot - Dropdown content
26
+ * @csspart trigger - Trigger wrapper
27
+ * @csspart content - Popover content
28
+ */
29
+ /**
30
+ * Platform facts for the generated element: shadow root, the authored
31
+ * package stylesheets, and the property-only `anchorName` row (the anchor
32
+ * identity is assigned at activation, never spelled as an attribute).
33
+ */
34
+ const openElement = /* @__PURE__ */ defineComponentConfig({
35
+ root: "shadow",
36
+ styles: ["./overlay-recipe.css", "./open-dropdown.css"],
37
+ properties: { anchorName: {
280
38
  default: "",
281
- reflect: false,
282
39
  attribute: false
283
- },
284
- anchorStyle: {
285
- type: Object,
286
- default: void 0,
287
- reflect: false,
288
- attribute: false
289
- }
290
- };
291
- var OpenDropdown = class extends OpenElement {
292
- static __partProgram = __partProgram;
293
- static __compiledProperties = __compiledProperties;
294
- static __elementMetadata = __elementMetadata;
295
- static props = __compiledProps;
296
- static observedAttributes = __observedAttributes;
297
- static __oeUtilityClasses = true;
298
- static __oeClassCandidates = [
299
- "trigger",
300
- "contents",
301
- "overlay",
302
- "content",
303
- "min-w-48",
304
- "p-2",
305
- "font-sans"
306
- ];
307
- static __computedFields = { anchorStyle: (__s) => computed(() => __s.anchorName.value === "" ? "" : `position-anchor: ${__s.anchorName.value}`) };
308
- static styles = [overlayRecipe, openDropdownStyles];
309
- anchorName = "";
310
- onDsdHydrated() {
311
- this.syncAnchorName();
312
- this.watchFocusReturn();
313
- }
314
- onCsrRendered() {
315
- this.syncAnchorName();
316
- this.watchFocusReturn();
317
- }
318
- watchFocusReturn() {
319
- if (readInstanceState(this, "focusWired", () => false)) return;
320
- writeInstanceState(this, "focusWired", true);
321
- const content = this.shadowRoot?.querySelector(".content");
322
- if (!content) return;
323
- content.addEventListener("focusin", () => {
324
- writeInstanceState(this, "popoverHadFocus", true);
325
- });
326
- content.addEventListener("beforetoggle", (event) => {
327
- if (event.newState !== "open") return;
328
- writeInstanceState(this, "popoverHadFocus", false);
329
- writeInstanceState(this, "previouslyFocused", deepActiveElement());
330
- });
331
- content.addEventListener("toggle", (event) => {
332
- if (event.newState !== "closed") return;
333
- const hadFocus = readInstanceState(this, "popoverHadFocus", () => false);
334
- const previous = readInstanceState(this, "previouslyFocused", () => null);
335
- writeInstanceState(this, "previouslyFocused", null);
336
- if (!hadFocus || !previous?.isConnected) return;
337
- queueMicrotask(() => {
338
- if (!previous.isConnected) return;
339
- const active = deepActiveElement();
340
- if (active === previous) return;
341
- const focusInside = active !== null && (this.contains(active) || content.contains(active));
342
- const dropped = !active || active === document.body || active === document.documentElement;
343
- if (!focusInside && !dropped) return;
344
- previous.focus();
345
- });
346
- });
347
- }
348
- syncAnchorName() {
349
- if (this.anchorName === "") this.anchorName = `--open-dropdown-trigger-${nextInstanceId()}`;
350
- this.style.setProperty("anchor-name", this.anchorName);
351
- }
352
- onTriggerPointerDown() {
353
- const content = this.shadowRoot?.querySelector(".content");
354
- writeInstanceState(this, "openAtPointerDown", content?.matches(":popover-open") ?? false);
355
- }
356
- toggle() {
357
- const wasOpen = readInstanceState(this, "openAtPointerDown", () => false);
358
- writeInstanceState(this, "openAtPointerDown", false);
359
- if (wasOpen) return;
360
- const content = this.shadowRoot?.querySelector(".content");
361
- if (!content) return;
362
- content.togglePopover();
363
- }
364
- render() {
365
- throw new Error("[open:compiled-element] open-dropdown is compiled to a Part Program; the runtime JSX render path is not available.");
366
- }
367
- };
40
+ } }
41
+ });
42
+ /** Popover-API dropdown with CSS Anchor Positioning placement. */
43
+ function OpenDropdown(props) {
44
+ /** The host the inline handler's currentTarget belongs to. */
45
+ const hostOf = (event) => event.currentTarget.getRootNode().host;
46
+ onConnect((env) => {
47
+ const host = env.host;
48
+ activateDropdown(host);
49
+ return () => clearDropdownTriggerAria(host);
50
+ });
51
+ onDispose((env) => {
52
+ const host = env.host;
53
+ clearDropdownPositionAnchor(host);
54
+ disposeDropdownFocusWiring(host);
55
+ });
56
+ onPropertyChange((event) => {
57
+ if (event.name !== "anchorName") return;
58
+ syncDropdownAnchor(event.host);
59
+ });
60
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", {
61
+ class: "trigger contents",
62
+ part: "trigger",
63
+ onPointerDown: (event) => recordDropdownPointerDown(hostOf(event)),
64
+ onClick: (event) => toggleDropdown(hostOf(event)),
65
+ children: /* @__PURE__ */ jsx("slot", { name: "trigger" })
66
+ }), /* @__PURE__ */ jsx("div", {
67
+ class: "overlay content min-w-48 p-2 font-sans",
68
+ part: "content",
69
+ popover: "auto",
70
+ children: /* @__PURE__ */ jsx("slot", {})
71
+ })] });
72
+ }
368
73
  //#endregion
369
- export { OpenDropdown, __elementMetadata, __partProgram };
74
+ export { OpenDropdown as default, openElement };
75
+
76
+ export { OpenDropdownElement, OpenDropdown__ssrHost } from './open-dropdown.generated.js';
77
+
78
+ // openElement:class-candidates ["content","contents","font-sans","min-w-48","overlay","p-2","trigger"]
@@ -7,7 +7,7 @@
7
7
  * rules into this shadow root.
8
8
  *
9
9
  * What stays here, and why (CUSTOMIZATION.md → "Why the residue is CSS"): each
10
- * block below has a real utility spelling — `[:host(:state(invalid))_&]:border-destructive`
10
+ * block below has a real utility spelling — `.control[aria-invalid='true'] { border-color: var(--color-destructive) }`
11
11
  * compiles to exactly the rule kept here — and the sheet keeps it because one
12
12
  * owned rule reads as the component's state contract, where the utility form
13
13
  * embeds an escaped ancestor selector in the class attribute.
@@ -15,9 +15,15 @@
15
15
  * - the control's DERIVED surfaces: the popover/border mixes of its resting
16
16
  * border and background, the violet-400 hover border, and the focus ring's
17
17
  * doubled box-shadow, each computed from pairs of role variables;
18
- * - the disabled and invalid treatments, which are scoped to the HOST's form
19
- * state (`:host(:state(disabled))` / `:host(:state(invalid))`) — the state
20
- * lives on the host, so the selector is what ties the rule to it.
18
+ * - the DISABLED treatment, scoped to the host's form state
19
+ * (`:host(:state(disabled))`, owned by the shell's form mapping);
20
+ * - the INVALID treatment, scoped to the control's own `[aria-invalid]`. The
21
+ * `:state(invalid)` custom state is FORM VALIDITY and belongs to the shell's
22
+ * form mapping (it is recomputed from required/value and deleted when the
23
+ * control is valid); an `error` MESSAGE is the author's. Sharing one channel
24
+ * would make this component a second writer whose value the owner wipes, so
25
+ * the invalid border reads the ARIA attribute the message already implies —
26
+ * one fact, one attribute, no extra host state.
21
27
  * The `hidden` attributes need no rules: nothing here sets `display` on the
22
28
  * label or the error message, so the platform's own `[hidden]` behavior holds.
23
29
  * One owner per property: nothing here is also authored as a utility.
@@ -53,6 +59,17 @@
53
59
  background: var(--color-muted);
54
60
  }
55
61
 
56
- :host(:state(invalid)) .control {
62
+ .control[aria-invalid='true'] {
57
63
  border-color: var(--color-destructive);
58
- }
64
+ }
65
+ /* The control's outline is retired by the component sheet, not by a utility.
66
+ *
67
+ * `outline-none` is a Tailwind utility that lives in the DOCUMENT sheet; a
68
+ * shadow root cannot see the document sheet, and the utility extractor emitted
69
+ * it only into the document layer for this class list. The focus affordance is
70
+ * this component's own contract (the sheet's `box-shadow` ring), so its "no UA
71
+ * outline" half belongs here too — one owner for the control's focus surface.
72
+ */
73
+ .control {
74
+ outline: none;
75
+ }