@typed/ui 1.0.0-beta.6 → 1.0.0-beta.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.
Files changed (128) hide show
  1. package/dist/Alert.d.ts +35 -41
  2. package/dist/Alert.d.ts.map +1 -1
  3. package/dist/Alert.js +23 -20
  4. package/dist/Button.d.ts +34 -78
  5. package/dist/Button.d.ts.map +1 -1
  6. package/dist/Button.js +16 -12
  7. package/dist/Carousel.d.ts +35 -236
  8. package/dist/Carousel.d.ts.map +1 -1
  9. package/dist/Carousel.js +13 -136
  10. package/dist/Checkbox.d.ts +55 -90
  11. package/dist/Checkbox.d.ts.map +1 -1
  12. package/dist/Checkbox.js +44 -38
  13. package/dist/Collection.d.ts +15 -15
  14. package/dist/Collection.js +7 -7
  15. package/dist/Combobox.d.ts +38 -187
  16. package/dist/Combobox.d.ts.map +1 -1
  17. package/dist/Combobox.js +9 -80
  18. package/dist/Component.d.ts +30 -24
  19. package/dist/Component.d.ts.map +1 -1
  20. package/dist/Component.js +23 -12
  21. package/dist/Composite.d.ts +50 -50
  22. package/dist/Composite.js +20 -20
  23. package/dist/Dialog.d.ts +34 -34
  24. package/dist/Dialog.d.ts.map +1 -1
  25. package/dist/Dialog.js +16 -14
  26. package/dist/Disclosure.d.ts +15 -15
  27. package/dist/Disclosure.js +6 -6
  28. package/dist/Dom/Events.d.ts +4 -4
  29. package/dist/Dom/Events.js +4 -4
  30. package/dist/Dom/Props.d.ts +9 -9
  31. package/dist/Dom/Props.js +4 -4
  32. package/dist/Dom/Refs.d.ts +2 -2
  33. package/dist/Dom/Refs.js +1 -1
  34. package/dist/Dom/Render.d.ts +2 -2
  35. package/dist/Dom/Render.js +2 -2
  36. package/dist/Dom/Types.d.ts +33 -33
  37. package/dist/Dom/index.d.ts +5 -5
  38. package/dist/Dom/index.d.ts.map +1 -1
  39. package/dist/Dom/index.js +4 -4
  40. package/dist/Dom.d.ts +1 -1
  41. package/dist/Dom.js +1 -1
  42. package/dist/Focusable.d.ts +5 -5
  43. package/dist/Focusable.js +1 -1
  44. package/dist/Form.d.ts +565 -533
  45. package/dist/Form.d.ts.map +1 -1
  46. package/dist/Form.js +350 -195
  47. package/dist/Grid.d.ts +39 -220
  48. package/dist/Grid.d.ts.map +1 -1
  49. package/dist/Grid.js +12 -107
  50. package/dist/Group.d.ts +50 -69
  51. package/dist/Group.d.ts.map +1 -1
  52. package/dist/Group.js +33 -25
  53. package/dist/Heading.d.ts +41 -40
  54. package/dist/Heading.d.ts.map +1 -1
  55. package/dist/Heading.js +26 -16
  56. package/dist/Hovercard.d.ts +18 -18
  57. package/dist/Hovercard.js +6 -6
  58. package/dist/HttpRouter.d.ts +3 -3
  59. package/dist/HttpRouter.js +5 -5
  60. package/dist/Link.d.ts +17 -21
  61. package/dist/Link.d.ts.map +1 -1
  62. package/dist/Link.js +11 -0
  63. package/dist/Listbox.d.ts +31 -163
  64. package/dist/Listbox.d.ts.map +1 -1
  65. package/dist/Listbox.js +9 -80
  66. package/dist/Menu.d.ts +67 -376
  67. package/dist/Menu.d.ts.map +1 -1
  68. package/dist/Menu.js +17 -179
  69. package/dist/Menubar.d.ts +24 -142
  70. package/dist/Menubar.d.ts.map +1 -1
  71. package/dist/Menubar.js +8 -66
  72. package/dist/Meter.d.ts +72 -132
  73. package/dist/Meter.d.ts.map +1 -1
  74. package/dist/Meter.js +35 -42
  75. package/dist/NativeDetails.d.ts +1 -1
  76. package/dist/NativeDetails.js +1 -1
  77. package/dist/NativeDialog.d.ts +7 -5
  78. package/dist/NativeDialog.d.ts.map +1 -1
  79. package/dist/NativeDialog.js +42 -4
  80. package/dist/NativePopover.d.ts +6 -4
  81. package/dist/NativePopover.d.ts.map +1 -1
  82. package/dist/NativePopover.js +43 -5
  83. package/dist/Popover.d.ts +18 -19
  84. package/dist/Popover.d.ts.map +1 -1
  85. package/dist/Popover.js +7 -8
  86. package/dist/RadioGroup.d.ts +86 -188
  87. package/dist/RadioGroup.d.ts.map +1 -1
  88. package/dist/RadioGroup.js +55 -105
  89. package/dist/Role.d.ts +4 -4
  90. package/dist/Role.js +1 -1
  91. package/dist/Select.d.ts +109 -220
  92. package/dist/Select.d.ts.map +1 -1
  93. package/dist/Select.js +67 -117
  94. package/dist/Separator.d.ts +30 -26
  95. package/dist/Separator.d.ts.map +1 -1
  96. package/dist/Separator.js +16 -10
  97. package/dist/Slider.d.ts +64 -111
  98. package/dist/Slider.d.ts.map +1 -1
  99. package/dist/Slider.js +47 -42
  100. package/dist/SpinButton.d.ts +64 -111
  101. package/dist/SpinButton.d.ts.map +1 -1
  102. package/dist/SpinButton.js +47 -42
  103. package/dist/Storybook.d.ts +2 -2
  104. package/dist/Storybook.js +1 -1
  105. package/dist/Switch.d.ts +52 -91
  106. package/dist/Switch.d.ts.map +1 -1
  107. package/dist/Switch.js +30 -36
  108. package/dist/Tabs.d.ts +44 -224
  109. package/dist/Tabs.d.ts.map +1 -1
  110. package/dist/Tabs.js +10 -94
  111. package/dist/Toolbar.d.ts +24 -142
  112. package/dist/Toolbar.d.ts.map +1 -1
  113. package/dist/Toolbar.js +8 -66
  114. package/dist/Tooltip.d.ts +20 -20
  115. package/dist/Tooltip.js +6 -6
  116. package/dist/Tree.d.ts +43 -229
  117. package/dist/Tree.d.ts.map +1 -1
  118. package/dist/Tree.js +12 -113
  119. package/dist/TreeGrid.d.ts +45 -264
  120. package/dist/TreeGrid.d.ts.map +1 -1
  121. package/dist/TreeGrid.js +13 -125
  122. package/dist/VisuallyHidden.d.ts +41 -27
  123. package/dist/VisuallyHidden.d.ts.map +1 -1
  124. package/dist/VisuallyHidden.js +27 -10
  125. package/dist/WindowSplitter.d.ts +68 -108
  126. package/dist/WindowSplitter.d.ts.map +1 -1
  127. package/dist/WindowSplitter.js +106 -23
  128. package/package.json +9 -8
package/dist/Switch.d.ts CHANGED
@@ -1,68 +1,43 @@
1
+ /**
2
+ * A button-backed on/off setting with a stable accessible name.
3
+ * The internal click toggles boolean state; persistence and form serialization remain explicit.
4
+ *
5
+ * Read the [Switch guide](/explore/ui-switch) for a complete example.
6
+ *
7
+ * [APG interaction reference](https://www.w3.org/WAI/ARIA/apg/patterns/switch/).
8
+ * @since 1.0.0
9
+ * @category Overview
10
+ * @packageDocumentation
11
+ */
1
12
  import * as Effect from "effect/Effect";
2
13
  import * as Schema from "effect/Schema";
3
14
  import { RefSubject } from "@typed/fx";
4
15
  import { type Renderable } from "@typed/template";
5
16
  import * as Dom from "./Dom.js";
6
17
  import type { HostResult } from "./Dom/Types.js";
7
- /** Current renderer-independent switch state.
8
- * @remarks
9
- * ## Why
10
- * The boolean can be tested and transformed without mounting a button.
11
- * ## Ownership and lifetime
12
- * Plain state retains no resources; its RefSubject owns updates by Scope.
13
- * @since 1.0.0
14
- * @category state
18
+ /**
15
19
  */
16
20
  export interface State {
17
- /** Whether the switch is on.
18
- * @remarks
19
- * ## Why
20
- * This value drives the required `aria-checked` state.
21
- * ## Ownership and lifetime
22
- * Plain data acquires no resources.
23
- * @since 1.0.0
24
- * @category state
21
+ /**
25
22
  */
26
23
  readonly checked: boolean;
27
24
  }
28
- /** Optional initial switch state.
29
- * @remarks
30
- * ## Why
31
- * Omission provides a deterministic off state for SSR and clients.
32
- * ## Ownership and lifetime
33
- * Configuration is inert.
34
- * @since 1.0.0
35
- * @category state
25
+ /**
36
26
  */
37
27
  export interface InitialState {
38
- /** Initial on/off value, defaulting to false.
39
- * @remarks
40
- * ## Why
41
- * The value seeds the serializable hydration contract.
42
- * ## Ownership and lifetime
43
- * It is copied into state and retains no resource.
44
- * @since 1.0.0
45
- * @category state
28
+ /**
46
29
  */
47
30
  readonly checked?: boolean;
48
31
  }
49
- /** Schema for switch hydration state.
50
- * @remarks
51
- * ## Why
52
- * Shared encoding keeps SSR and browser state compatible.
53
- * ## Ownership and lifetime
54
- * The immutable schema acquires no resources.
55
- * @since 1.0.0
56
- * @category schemas
32
+ /**
57
33
  */
58
34
  export declare const StateSchema: Schema.Struct<{
59
35
  readonly checked: Schema.Boolean;
60
36
  }>;
61
- /** Creates hydrated switch state independent of rendering.
37
+ /**
38
+ * Creates hydrated switch state independent of rendering.
62
39
  * @remarks
63
- * ## Why
64
40
  * Domain code and tests can own the state while any renderer consumes it.
65
- * ## Ownership and lifetime
66
41
  * The caller's Effect Scope owns the returned RefSubject.
67
42
  * @example
68
43
  * ```ts
@@ -74,17 +49,13 @@ export declare const StateSchema: Schema.Struct<{
74
49
  * })
75
50
  * ```
76
51
  * @since 1.0.0
77
- * @category constructors
52
+ * @category State construction
78
53
  */
79
54
  export declare function makeState(initial?: InitialState): Effect.Effect<RefSubject.HydratedRefSubject<{
80
55
  readonly checked: boolean;
81
56
  }, Schema.SchemaError, never, never>, never, import("effect/Scope").Scope>;
82
- /** Sets the switch on/off state.
83
- * @remarks
84
- * ## Why
85
- * Explicit transitions keep state logic outside the renderer.
86
- * ## Ownership and lifetime
87
- * The Effect reuses the subject's lifetime and acquires no resource.
57
+ /**
58
+ * Sets the switch to the requested checked state.
88
59
  * @example
89
60
  * ```ts
90
61
  * import { Effect } from "effect"
@@ -96,15 +67,11 @@ export declare function makeState(initial?: InitialState): Effect.Effect<RefSubj
96
67
  * })
97
68
  * ```
98
69
  * @since 1.0.0
99
- * @category state
70
+ * @category State transitions
100
71
  */
101
72
  export declare function setChecked<E, R>(state: RefSubject.RefSubject<State, E, R>, checked: boolean): Effect.Effect<State, E, R>;
102
- /** Atomically inverts the switch state.
103
- * @remarks
104
- * ## Why
105
- * A RefSubject update prevents stale read-then-write transitions.
106
- * ## Ownership and lifetime
107
- * The Effect acquires no resource and uses the existing state Scope.
73
+ /**
74
+ * Toggles the switch between checked and unchecked.
108
75
  * @example
109
76
  * ```ts
110
77
  * import { Effect } from "effect"
@@ -116,38 +83,22 @@ export declare function setChecked<E, R>(state: RefSubject.RefSubject<State, E,
116
83
  * })
117
84
  * ```
118
85
  * @since 1.0.0
119
- * @category state
86
+ * @category State transitions
120
87
  */
121
88
  export declare function toggle<E, R>(state: RefSubject.RefSubject<State, E, R>): Effect.Effect<State, E, R>;
122
- /** Options for an ARIA switch rendered as a native button.
123
- * @remarks
124
- * ## Why
125
- * Button behavior supplies focus and keyboard activation while ARIA exposes
126
- * the binary switch semantic.
127
- * ## Ownership and lifetime
128
- * Options are inert; rendering owns subscriptions and listeners by Scope.
129
- * @since 1.0.0
130
- * @category models
89
+ /**
131
90
  */
132
91
  export interface SwitchOptions extends Dom.HostOptions<HTMLButtonElement> {
133
- /** Hydrated state synchronized with `aria-checked`.
134
- * @remarks
135
- * ## Why
136
- * One source controls SSR, render output, and activation updates.
137
- * ## Ownership and lifetime
138
- * The component borrows the state; its originating Scope owns it.
92
+ /**
93
+ * Hydrated state synchronized with `aria-checked`.
139
94
  * @since 1.0.0
140
- * @category state
95
+ * @category State connection
141
96
  */
142
97
  readonly state: RefSubject.HydratedRefSubject<State, Schema.SchemaError>;
143
- /** Visible content and accessible name.
144
- * @remarks
145
- * ## Why
146
- * A switch requires an accessible name, normally supplied by its content.
147
- * ## Ownership and lifetime
148
- * Dynamic content follows the component Scope.
98
+ /**
99
+ * Visible content and accessible name.
149
100
  * @since 1.0.0
150
- * @category content
101
+ * @category Rendered content
151
102
  */
152
103
  readonly content: Renderable.Any;
153
104
  }
@@ -160,27 +111,37 @@ declare function internalProps<const Options extends SwitchOptions>(options: Opt
160
111
  readonly ref: RefSubject.HydratedRefSubject<State, Schema.SchemaError, never, never>;
161
112
  };
162
113
  type SwitchInternalProps<Options extends SwitchOptions> = ReturnType<ReturnType<typeof internalProps<Options>>>;
163
- /** Renders a button-backed ARIA switch.
114
+ /**
115
+ * Renders a button-backed ARIA switch.
164
116
  * @remarks
165
- * ## Why
166
117
  * The component combines native button activation with a renderer-independent
167
118
  * boolean state and real DOM click events.
168
- * ## Ownership and lifetime
169
119
  * Running the Fx owns listener/state subscriptions in its Effect Scope. A
170
120
  * custom host must preserve button type, role, `aria-checked`, click handler,
171
121
  * and the single hydration ref owner.
172
122
  * @example
173
123
  * ```ts
174
- * import { Effect } from "effect"
175
- * import * as Switch from "@typed/ui/Switch"
124
+ * import { RefSubject } from "@typed/fx";
125
+ * import { html } from "@typed/template";
126
+ * import { component } from "@typed/ui/Component";
127
+ * import * as Switch from "@typed/ui/Switch";
176
128
  *
177
- * const program = Effect.gen(function* () {
178
- * const state = yield* Switch.makeState()
179
- * return Switch.Switch({ state, content: "Notifications" })
180
- * })
129
+ * export const PreviewSetting = component(function* () {
130
+ * const state = yield* Switch.makeState({ checked: true });
131
+ * const status = RefSubject.map(state, ({ checked }) => checked ? "On" : "Off");
132
+ * return html`<section>
133
+ * ${Switch.Switch({
134
+ * state,
135
+ * content: "Show live preview",
136
+ * props: { class: "preview-switch", "aria-describedby": "preview-setting-help" },
137
+ * })}
138
+ * <span aria-hidden="true">${status}</span>
139
+ * <p id="preview-setting-help">Updates the preview while you edit.</p>
140
+ * </section>`;
141
+ * });
181
142
  * ```
182
143
  * @since 1.0.0
183
- * @category components
144
+ * @category Native controls
184
145
  */
185
146
  export declare function Switch<const Options extends SwitchOptions, const Host extends HostResult = never>(options: Options, host?: Dom.HostOverride<Dom.RenderHostProps<Options, SwitchInternalProps<Options>>, Options["content"], Host>): import("./Dom/Types.js").HostComponent<Host | Options>;
186
147
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../src/Switch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAO,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EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,GAAG,CAAC,YAAY,CACrB,GAAG,CAAC,eAAe,CAAC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAC1D,OAAO,CAAC,SAAS,CAAC,EAClB,IAAI,CACL,0DAWF"}
package/dist/Switch.js CHANGED
@@ -2,21 +2,13 @@ import * as Schema from "effect/Schema";
2
2
  import { RefSubject } from "@typed/fx";
3
3
  import { html } from "@typed/template";
4
4
  import * as Dom from "./Dom.js";
5
- /** Schema for switch hydration state.
6
- * @remarks
7
- * ## Why
8
- * Shared encoding keeps SSR and browser state compatible.
9
- * ## Ownership and lifetime
10
- * The immutable schema acquires no resources.
11
- * @since 1.0.0
12
- * @category schemas
5
+ /**
13
6
  */
14
7
  export const StateSchema = Schema.Struct({ checked: Schema.Boolean });
15
- /** Creates hydrated switch state independent of rendering.
8
+ /**
9
+ * Creates hydrated switch state independent of rendering.
16
10
  * @remarks
17
- * ## Why
18
11
  * Domain code and tests can own the state while any renderer consumes it.
19
- * ## Ownership and lifetime
20
12
  * The caller's Effect Scope owns the returned RefSubject.
21
13
  * @example
22
14
  * ```ts
@@ -28,17 +20,13 @@ export const StateSchema = Schema.Struct({ checked: Schema.Boolean });
28
20
  * })
29
21
  * ```
30
22
  * @since 1.0.0
31
- * @category constructors
23
+ * @category State construction
32
24
  */
33
25
  export function makeState(initial = {}) {
34
26
  return RefSubject.hydrate(StateSchema, { checked: initial.checked ?? false });
35
27
  }
36
- /** Sets the switch on/off state.
37
- * @remarks
38
- * ## Why
39
- * Explicit transitions keep state logic outside the renderer.
40
- * ## Ownership and lifetime
41
- * The Effect reuses the subject's lifetime and acquires no resource.
28
+ /**
29
+ * Sets the switch to the requested checked state.
42
30
  * @example
43
31
  * ```ts
44
32
  * import { Effect } from "effect"
@@ -50,17 +38,13 @@ export function makeState(initial = {}) {
50
38
  * })
51
39
  * ```
52
40
  * @since 1.0.0
53
- * @category state
41
+ * @category State transitions
54
42
  */
55
43
  export function setChecked(state, checked) {
56
44
  return RefSubject.update(state, (current) => ({ ...current, checked }));
57
45
  }
58
- /** Atomically inverts the switch state.
59
- * @remarks
60
- * ## Why
61
- * A RefSubject update prevents stale read-then-write transitions.
62
- * ## Ownership and lifetime
63
- * The Effect acquires no resource and uses the existing state Scope.
46
+ /**
47
+ * Toggles the switch between checked and unchecked.
64
48
  * @example
65
49
  * ```ts
66
50
  * import { Effect } from "effect"
@@ -72,7 +56,7 @@ export function setChecked(state, checked) {
72
56
  * })
73
57
  * ```
74
58
  * @since 1.0.0
75
- * @category state
59
+ * @category State transitions
76
60
  */
77
61
  export function toggle(state) {
78
62
  return RefSubject.update(state, (current) => ({ ...current, checked: !current.checked }));
@@ -87,27 +71,37 @@ function internalProps(options) {
87
71
  ref: options.state,
88
72
  });
89
73
  }
90
- /** Renders a button-backed ARIA switch.
74
+ /**
75
+ * Renders a button-backed ARIA switch.
91
76
  * @remarks
92
- * ## Why
93
77
  * The component combines native button activation with a renderer-independent
94
78
  * boolean state and real DOM click events.
95
- * ## Ownership and lifetime
96
79
  * Running the Fx owns listener/state subscriptions in its Effect Scope. A
97
80
  * custom host must preserve button type, role, `aria-checked`, click handler,
98
81
  * and the single hydration ref owner.
99
82
  * @example
100
83
  * ```ts
101
- * import { Effect } from "effect"
102
- * import * as Switch from "@typed/ui/Switch"
84
+ * import { RefSubject } from "@typed/fx";
85
+ * import { html } from "@typed/template";
86
+ * import { component } from "@typed/ui/Component";
87
+ * import * as Switch from "@typed/ui/Switch";
103
88
  *
104
- * const program = Effect.gen(function* () {
105
- * const state = yield* Switch.makeState()
106
- * return Switch.Switch({ state, content: "Notifications" })
107
- * })
89
+ * export const PreviewSetting = component(function* () {
90
+ * const state = yield* Switch.makeState({ checked: true });
91
+ * const status = RefSubject.map(state, ({ checked }) => checked ? "On" : "Off");
92
+ * return html`<section>
93
+ * ${Switch.Switch({
94
+ * state,
95
+ * content: "Show live preview",
96
+ * props: { class: "preview-switch", "aria-describedby": "preview-setting-help" },
97
+ * })}
98
+ * <span aria-hidden="true">${status}</span>
99
+ * <p id="preview-setting-help">Updates the preview while you edit.</p>
100
+ * </section>`;
101
+ * });
108
102
  * ```
109
103
  * @since 1.0.0
110
- * @category components
104
+ * @category Native controls
111
105
  */
112
106
  export function Switch(options, host) {
113
107
  return Dom.renderHost()(options, host, internalProps(options), options.content, (props, content) => {