@openelement/ui 1.0.0-alpha.14 → 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.
Files changed (43) hide show
  1. package/CUSTOMIZATION.md +106 -112
  2. package/README.md +19 -39
  3. package/custom-elements.json +369 -0
  4. package/package.json +3 -2
  5. package/src/button-machine.js +54 -0
  6. package/src/component-config.js +7 -0
  7. package/src/component-recipes.js +2 -24
  8. package/src/copy-feedback.js +32 -0
  9. package/src/dialog-machine.js +104 -0
  10. package/src/dropdown-machine.js +253 -0
  11. package/src/generated-manifest.json +135 -87
  12. package/src/index.d.ts +7 -8
  13. package/src/index.js +7 -8
  14. package/src/input-machine.js +33 -0
  15. package/src/open-button.css +119 -108
  16. package/src/open-button.d.ts +34 -342
  17. package/src/open-button.generated.js +592 -0
  18. package/src/open-button.js +115 -1140
  19. package/src/open-code-block.css +24 -44
  20. package/src/open-code-block.d.ts +15 -175
  21. package/src/open-code-block.generated.js +293 -0
  22. package/src/open-code-block.js +112 -224
  23. package/src/open-dialog.css +114 -127
  24. package/src/open-dialog.d.ts +22 -261
  25. package/src/open-dialog.generated.js +501 -0
  26. package/src/open-dialog.js +137 -632
  27. package/src/open-dropdown.css +26 -26
  28. package/src/open-dropdown.d.ts +15 -218
  29. package/src/open-dropdown.generated.js +211 -0
  30. package/src/open-dropdown.js +74 -355
  31. package/src/open-input.css +69 -74
  32. package/src/open-input.d.ts +34 -461
  33. package/src/open-input.generated.js +685 -0
  34. package/src/open-input.js +161 -1802
  35. package/src/open-theme-toggle.css +37 -47
  36. package/src/open-theme-toggle.d.ts +19 -190
  37. package/src/open-theme-toggle.generated.js +564 -0
  38. package/src/open-theme-toggle.js +209 -509
  39. package/src/theme-contract.js +40 -0
  40. package/src/theme.css +26 -8
  41. package/src/control-recipe.css +0 -21
  42. package/src/register.d.ts +0 -4
  43. package/src/register.js +0 -22
@@ -0,0 +1,369 @@
1
+ {
2
+ "schemaVersion": "2.1.0",
3
+ "modules": [
4
+ {
5
+ "kind": "javascript-module",
6
+ "path": "src/open-button.tsx",
7
+ "declarations": [
8
+ {
9
+ "kind": "class",
10
+ "name": "OpenButtonElement",
11
+ "tagName": "open-button",
12
+ "customElement": true,
13
+ "description": "Button or link control with variant/size surfaces and form participation.",
14
+ "members": [],
15
+ "attributes": [
16
+ {
17
+ "name": "variant",
18
+ "type": {
19
+ "text": "string"
20
+ },
21
+ "default": "default"
22
+ },
23
+ {
24
+ "name": "size",
25
+ "type": {
26
+ "text": "string"
27
+ },
28
+ "default": "md"
29
+ },
30
+ {
31
+ "name": "disabled",
32
+ "type": {
33
+ "text": "boolean"
34
+ },
35
+ "default": "false"
36
+ },
37
+ {
38
+ "name": "href",
39
+ "type": {
40
+ "text": "string"
41
+ },
42
+ "default": ""
43
+ },
44
+ {
45
+ "name": "target",
46
+ "type": {
47
+ "text": "string"
48
+ },
49
+ "default": ""
50
+ },
51
+ {
52
+ "name": "type",
53
+ "type": {
54
+ "text": "string"
55
+ },
56
+ "default": "button"
57
+ }
58
+ ],
59
+ "events": [
60
+ {
61
+ "name": "open-click",
62
+ "type": {
63
+ "text": "CustomEvent"
64
+ },
65
+ "description": "Fired on open-click"
66
+ }
67
+ ],
68
+ "slots": [
69
+ {
70
+ "name": ""
71
+ }
72
+ ],
73
+ "cssParts": [
74
+ {
75
+ "name": "control"
76
+ }
77
+ ]
78
+ }
79
+ ]
80
+ },
81
+ {
82
+ "kind": "javascript-module",
83
+ "path": "src/open-input.tsx",
84
+ "declarations": [
85
+ {
86
+ "kind": "class",
87
+ "name": "OpenInputElement",
88
+ "tagName": "open-input",
89
+ "customElement": true,
90
+ "description": "Form-associated text input with a label, an error slot and native validity.",
91
+ "members": [],
92
+ "attributes": [
93
+ {
94
+ "name": "type",
95
+ "type": {
96
+ "text": "string"
97
+ },
98
+ "default": "text"
99
+ },
100
+ {
101
+ "name": "placeholder",
102
+ "type": {
103
+ "text": "string"
104
+ },
105
+ "default": ""
106
+ },
107
+ {
108
+ "name": "label",
109
+ "type": {
110
+ "text": "string"
111
+ },
112
+ "default": ""
113
+ },
114
+ {
115
+ "name": "name",
116
+ "type": {
117
+ "text": "string"
118
+ },
119
+ "default": ""
120
+ },
121
+ {
122
+ "name": "value",
123
+ "type": {
124
+ "text": "string"
125
+ },
126
+ "default": ""
127
+ },
128
+ {
129
+ "name": "disabled",
130
+ "type": {
131
+ "text": "boolean"
132
+ },
133
+ "default": "false"
134
+ },
135
+ {
136
+ "name": "required",
137
+ "type": {
138
+ "text": "boolean"
139
+ },
140
+ "default": "false"
141
+ },
142
+ {
143
+ "name": "error",
144
+ "type": {
145
+ "text": "string"
146
+ },
147
+ "default": ""
148
+ }
149
+ ],
150
+ "events": [
151
+ {
152
+ "name": "open-input",
153
+ "type": {
154
+ "text": "CustomEvent<{ value: unknown }>"
155
+ },
156
+ "description": "Fired on open-input"
157
+ },
158
+ {
159
+ "name": "open-change",
160
+ "type": {
161
+ "text": "CustomEvent<{ value: unknown }>"
162
+ },
163
+ "description": "Fired on open-change"
164
+ },
165
+ {
166
+ "name": "open-focus",
167
+ "type": {
168
+ "text": "CustomEvent"
169
+ },
170
+ "description": "Fired on open-focus"
171
+ },
172
+ {
173
+ "name": "open-blur",
174
+ "type": {
175
+ "text": "CustomEvent"
176
+ },
177
+ "description": "Fired on open-blur"
178
+ }
179
+ ],
180
+ "cssParts": [
181
+ {
182
+ "name": "wrapper"
183
+ },
184
+ {
185
+ "name": "label"
186
+ },
187
+ {
188
+ "name": "control"
189
+ },
190
+ {
191
+ "name": "error"
192
+ }
193
+ ]
194
+ }
195
+ ]
196
+ },
197
+ {
198
+ "kind": "javascript-module",
199
+ "path": "src/open-theme-toggle.tsx",
200
+ "declarations": [
201
+ {
202
+ "kind": "class",
203
+ "name": "OpenThemeToggleElement",
204
+ "tagName": "open-theme-toggle",
205
+ "customElement": true,
206
+ "description": "Theme toggle button for dark/light mode: reads and flips the document's `data-theme` (with an initialization priority chain) and persists the choice; icon visibility follows the current theme attribute.",
207
+ "members": [],
208
+ "attributes": [
209
+ {
210
+ "name": "theme",
211
+ "type": {
212
+ "text": "string"
213
+ },
214
+ "default": "dark"
215
+ }
216
+ ],
217
+ "events": [
218
+ {
219
+ "name": "open:theme-change",
220
+ "type": {
221
+ "text": "CustomEvent<{ theme: unknown }>"
222
+ },
223
+ "description": "Fired on open:theme-change"
224
+ }
225
+ ],
226
+ "cssParts": [
227
+ {
228
+ "name": "toggle"
229
+ },
230
+ {
231
+ "name": "icon-sun"
232
+ },
233
+ {
234
+ "name": "icon-moon"
235
+ }
236
+ ]
237
+ }
238
+ ]
239
+ },
240
+ {
241
+ "kind": "javascript-module",
242
+ "path": "src/open-code-block.tsx",
243
+ "declarations": [
244
+ {
245
+ "kind": "class",
246
+ "name": "OpenCodeBlockElement",
247
+ "tagName": "open-code-block",
248
+ "customElement": true,
249
+ "description": "Code block with a copy button.",
250
+ "members": [],
251
+ "slots": [
252
+ {
253
+ "name": ""
254
+ }
255
+ ],
256
+ "cssParts": [
257
+ {
258
+ "name": "copy"
259
+ }
260
+ ]
261
+ }
262
+ ]
263
+ },
264
+ {
265
+ "kind": "javascript-module",
266
+ "path": "src/open-dialog.tsx",
267
+ "declarations": [
268
+ {
269
+ "kind": "class",
270
+ "name": "OpenDialogElement",
271
+ "tagName": "open-dialog",
272
+ "customElement": true,
273
+ "description": "Dialog component using native <dialog> element + popover API.",
274
+ "members": [],
275
+ "attributes": [
276
+ {
277
+ "name": "open",
278
+ "type": {
279
+ "text": "boolean"
280
+ },
281
+ "default": "false"
282
+ },
283
+ {
284
+ "name": "label",
285
+ "type": {
286
+ "text": "string"
287
+ },
288
+ "default": ""
289
+ },
290
+ {
291
+ "name": "close-label",
292
+ "type": {
293
+ "text": "string"
294
+ },
295
+ "default": "Close"
296
+ }
297
+ ],
298
+ "events": [
299
+ {
300
+ "name": "open-dialog-close",
301
+ "type": {
302
+ "text": "CustomEvent"
303
+ },
304
+ "description": "Fired on open-dialog-close"
305
+ }
306
+ ],
307
+ "slots": [
308
+ {
309
+ "name": ""
310
+ },
311
+ {
312
+ "name": "trigger"
313
+ },
314
+ {
315
+ "name": "footer"
316
+ }
317
+ ],
318
+ "cssParts": [
319
+ {
320
+ "name": "overlay"
321
+ },
322
+ {
323
+ "name": "header"
324
+ },
325
+ {
326
+ "name": "close"
327
+ },
328
+ {
329
+ "name": "body"
330
+ },
331
+ {
332
+ "name": "footer"
333
+ }
334
+ ]
335
+ }
336
+ ]
337
+ },
338
+ {
339
+ "kind": "javascript-module",
340
+ "path": "src/open-dropdown.tsx",
341
+ "declarations": [
342
+ {
343
+ "kind": "class",
344
+ "name": "OpenDropdownElement",
345
+ "tagName": "open-dropdown",
346
+ "customElement": true,
347
+ "description": "Popover-API dropdown with CSS Anchor Positioning placement.",
348
+ "members": [],
349
+ "slots": [
350
+ {
351
+ "name": ""
352
+ },
353
+ {
354
+ "name": "trigger"
355
+ }
356
+ ],
357
+ "cssParts": [
358
+ {
359
+ "name": "trigger"
360
+ },
361
+ {
362
+ "name": "content"
363
+ }
364
+ ]
365
+ }
366
+ ]
367
+ }
368
+ ]
369
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openelement/ui",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.16",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -73,8 +73,9 @@
73
73
  "node": ">=24.2"
74
74
  },
75
75
  "sideEffects": false,
76
+ "customElements": "custom-elements.json",
76
77
  "peerDependenciesMeta": {},
77
78
  "dependencies": {
78
- "@openelement/element": "1.0.0-alpha.14"
79
+ "@openelement/element": "1.0.0-alpha.16"
79
80
  }
80
81
  }
@@ -0,0 +1,54 @@
1
+ //#region src/button-machine.ts
2
+ function associatedForm(host) {
3
+ const id = host.getAttribute("form");
4
+ if (id === null) return host.closest("form");
5
+ const owner = host.getRootNode().getElementById?.(id);
6
+ return owner?.tagName === "FORM" ? owner : null;
7
+ }
8
+ /**
9
+ * Dispatch the composed `open-click` and run the control's action.
10
+ *
11
+ * Disabled guard (#757): the anchor branch and a programmatic `click()` both
12
+ * reach this handler, so a disabled open-button must not fire `open-click`,
13
+ * navigate, or submit. The anchor's own `href` is already dropped by the
14
+ * compiled sink; this covers the rest.
15
+ *
16
+ * The anchor branch is a navigation control and never submits or resets a form
17
+ * (异味③, #637): only the `<button>` branch continues past the `open-click`.
18
+ */
19
+ function activateButton(host, event, publishClick) {
20
+ if (host.disabled || host.matches(":disabled")) {
21
+ event.preventDefault();
22
+ return;
23
+ }
24
+ publishClick();
25
+ if (host.href !== "") return;
26
+ const form = associatedForm(host);
27
+ if (form === null) return;
28
+ const prototype = form.ownerDocument?.defaultView?.HTMLFormElement.prototype;
29
+ if (host.type === "submit") submitForm(form, prototype);
30
+ else if (host.type === "reset") (prototype?.reset ?? form.reset).call(form);
31
+ }
32
+ /**
33
+ * Submit `form` on behalf of the host (#637).
34
+ *
35
+ * `requestSubmit()` runs native constraint validation and dispatches exactly
36
+ * one native submit event. The router's enhancement handler is attached to the
37
+ * form's containing shadow root, so it sees that event without a synthetic
38
+ * composed event from the custom control's separate shadow root.
39
+ */
40
+ function submitForm(form, prototype) {
41
+ const requestSubmit = prototype?.requestSubmit ?? form.requestSubmit;
42
+ if (typeof requestSubmit === "function") {
43
+ requestSubmit.call(form);
44
+ return;
45
+ }
46
+ const reportValidity = prototype?.reportValidity ?? form.reportValidity;
47
+ const checkValidity = prototype?.checkValidity ?? form.checkValidity;
48
+ const validate = typeof reportValidity === "function" ? reportValidity : checkValidity;
49
+ if (!form.noValidate && typeof validate === "function" && !validate.call(form)) return;
50
+ const submit = prototype?.submit ?? form.submit;
51
+ if (typeof submit === "function") submit.call(form);
52
+ }
53
+ //#endregion
54
+ export { activateButton };
@@ -0,0 +1,7 @@
1
+ //#region src/component-config.ts
2
+ /** Identity helper: returns the config unchanged so the authored statement keeps its literal shape. */
3
+ function defineComponentConfig(config) {
4
+ return config;
5
+ }
6
+ //#endregion
7
+ export { defineComponentConfig };
@@ -1,4 +1,4 @@
1
- import { createLogger } from "@openelement/element";
1
+ import { createLogger } from "@openelement/element/logger";
2
2
  //#region src/component-recipes.ts
3
3
  /** Shared helpers and visual recipes for the public UI primitives. */
4
4
  /**
@@ -14,28 +14,6 @@ function nextInstanceId() {
14
14
  return instanceCount++;
15
15
  }
16
16
  /**
17
- * Reflect the `disabled` attribute into ElementInternals custom states
18
- * (:state(disabled)/:state(enabled)). Shared by the form-associated
19
- * primitives (open-button, open-input).
20
- */
21
- function syncDisabledState(internals, disabled) {
22
- if (!internals?.states) return;
23
- if (disabled) {
24
- internals.states.delete("enabled");
25
- internals.states.add("disabled");
26
- } else {
27
- internals.states.delete("disabled");
28
- internals.states.add("enabled");
29
- }
30
- }
31
- /**
32
- * Compiled modules may not carry helper functions at top level (OEC9008), so
33
- * the form lookup shared by the form-associated primitives lives here.
34
- */
35
- function closestFormOf(element) {
36
- return typeof element.closest === "function" ? element.closest("form") : null;
37
- }
38
- /**
39
17
  * Deepest focused element, descending through open shadow roots (OEC9008:
40
18
  * shared helpers live in plain .ts modules, not compiled component modules).
41
19
  */
@@ -45,4 +23,4 @@ function deepActiveElement() {
45
23
  return active ?? null;
46
24
  }
47
25
  //#endregion
48
- export { CODE_BLOCK_CONSTANTS, closestFormOf, deepActiveElement, log, nextInstanceId, syncDisabledState };
26
+ export { CODE_BLOCK_CONSTANTS, deepActiveElement, log, nextInstanceId };
@@ -0,0 +1,32 @@
1
+ import { CODE_BLOCK_CONSTANTS } from "./component-recipes.js";
2
+ //#region src/copy-feedback.ts
3
+ /**
4
+ * @openelement/ui — the copy-feedback reset timer, per host.
5
+ *
6
+ * `open-code-block` shows a transient label (`Copied!` / `Failed`) and resets
7
+ * it after the shared feedback window. The timer is per element and must be
8
+ * re-armed (not stacked) when the user clicks again, and it must not outlive
9
+ * the element's teardown. A WeakMap keyed by the host gives that lifetime
10
+ * without a second state channel: the generated component writes its declared
11
+ * `copyLabel` property, and the property-change callback in the component
12
+ * owns the custom-state and timer bookkeeping.
13
+ */
14
+ const timers = /* @__PURE__ */ new WeakMap();
15
+ /** Arm the reset for `host`, replacing a pending one. */
16
+ function scheduleCopyReset(host) {
17
+ cancelCopyReset(host);
18
+ const timer = setTimeout(() => {
19
+ timers.delete(host);
20
+ host.copyLabel = "Copy";
21
+ }, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
22
+ timers.set(host, timer);
23
+ }
24
+ /** Drop a pending reset (teardown, or a transition back to the idle label). */
25
+ function cancelCopyReset(host) {
26
+ const timer = timers.get(host);
27
+ if (timer === void 0) return;
28
+ clearTimeout(timer);
29
+ timers.delete(host);
30
+ }
31
+ //#endregion
32
+ export { cancelCopyReset, scheduleCopyReset };
@@ -0,0 +1,104 @@
1
+ import { readInstanceState, writeInstanceState } from "./instance-state.js";
2
+ //#region src/dialog-machine.ts
3
+ /**
4
+ * @openelement/ui - open-dialog top-layer choreography (module helper).
5
+ *
6
+ * The generated element owns the compiled sinks (`open` attribute, `label`
7
+ * sinks); this module owns the imperative state machine the compiled program
8
+ * cannot express: the native <dialog> top-layer moves (showModal / show /
9
+ * close) and the close-echo guards (#1030, #1226). Every function takes the
10
+ * host explicitly — the same host the lifecycle `env` provides — so the unit
11
+ * harness drives them without connecting an element.
12
+ *
13
+ * Modal-session bookkeeping lives in the shared instance-state module (the
14
+ * generated class carries only the declared property fields).
15
+ */
16
+ /**
17
+ * Mirror the `open` property into the custom states (`:state(open)` /
18
+ * `:state(closed)`).
19
+ */
20
+ function updateDialogStates(host, states) {
21
+ if (!states) return;
22
+ if (host.open) {
23
+ states.add("open");
24
+ states.delete("closed");
25
+ } else {
26
+ states.delete("open");
27
+ states.add("closed");
28
+ }
29
+ }
30
+ function dialogElement(host) {
31
+ return host.shadowRoot?.querySelector("dialog") ?? null;
32
+ }
33
+ /**
34
+ * Apply the `open` state to the inner <dialog> once the shadow DOM exists:
35
+ * the modal session enters the platform top layer exactly once, the
36
+ * attribute-driven open is closed first (#1030), and the exit restores the
37
+ * sink-removed attribute before close() (#1226).
38
+ */
39
+ function syncDialogElement(host) {
40
+ const dialog = dialogElement(host);
41
+ if (!dialog) return;
42
+ const modalActive = readInstanceState(host, "modalActive", () => false);
43
+ if (host.open) {
44
+ if ((host.getAttribute("mode") || "modal") === "modal") {
45
+ if (modalActive) {
46
+ if (dialog.matches(":modal")) return;
47
+ writeInstanceState(host, "modalActive", false);
48
+ }
49
+ if (dialog.open) dialog.close();
50
+ dialog.showModal();
51
+ writeInstanceState(host, "modalActive", true);
52
+ } else if (!dialog.open) dialog.show();
53
+ } else {
54
+ if (modalActive && !dialog.open) dialog.setAttribute("open", "");
55
+ if (dialog.open) dialog.close();
56
+ writeInstanceState(host, "modalActive", false);
57
+ }
58
+ }
59
+ /**
60
+ * One sync = custom states + top-layer choreography. The generated component
61
+ * calls this once per frame after connect (initial state, including an
62
+ * upgrade-time attribute seed) and on every committed `open` change.
63
+ */
64
+ function syncOpenDialog(host, states) {
65
+ updateDialogStates(host, states);
66
+ syncDialogElement(host);
67
+ }
68
+ /**
69
+ * The user-facing close path (close button, cancel): clear the declared
70
+ * `open` property (the change channel applies the states and the top-layer
71
+ * exit) and dispatch the component's event.
72
+ */
73
+ function handleDialogClose(host) {
74
+ host.open = false;
75
+ host.dispatchEvent(new CustomEvent("open-dialog-close", {
76
+ bubbles: true,
77
+ composed: true
78
+ }));
79
+ }
80
+ /**
81
+ * The native `cancel` event (Escape): dismissals are not abortable here, so
82
+ * preventDefault first, then run the close path.
83
+ */
84
+ function handleDialogCancel(host, event) {
85
+ event.preventDefault();
86
+ handleDialogClose(host);
87
+ }
88
+ /**
89
+ * The inner dialog's native `close` event. The attribute→modal transition
90
+ * above close()es the attribute-opened dialog and immediately re-opens it via
91
+ * showModal(); if the resulting close event is dispatched asynchronously it
92
+ * arrives after the re-open and must be ignored. A close() driven by
93
+ * handleDialogClose (property already cleared) is the same closing session —
94
+ * its open-dialog-close event already fired (#1226). A genuine native close
95
+ * (e.g. form method="dialog") finds the platform has already cleared
96
+ * dialog.open.
97
+ */
98
+ function handleDialogNativeClose(host) {
99
+ if (dialogElement(host)?.open && host.open) return;
100
+ if (!host.open) return;
101
+ handleDialogClose(host);
102
+ }
103
+ //#endregion
104
+ export { handleDialogCancel, handleDialogClose, handleDialogNativeClose, syncDialogElement, syncOpenDialog, updateDialogStates };