@jini-ai/ui-kit 0.6.23 → 0.7.0
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/CHANGELOG.md +2 -0
- package/README.md +5 -1
- package/dist/confirm.d.ts +1 -1
- package/dist/confirm.js +1 -1
- package/dist/kit-contract.d.ts +16 -16
- package/dist/kit-contract.js +16 -16
- package/dist/react/Kit.hooks.d.ts +1 -0
- package/dist/react/Kit.hooks.js +18 -7
- package/dist/react/agent-attrs.hooks.d.ts +25 -0
- package/dist/react/agent-attrs.hooks.js +62 -0
- package/dist/react/confirm/ConfirmDialog.hooks.js +29 -6
- package/dist/react/native/Controls.hooks.d.ts +5 -4
- package/dist/react/native/Controls.hooks.js +11 -5
- package/dist/react/native/Dialog.hooks.d.ts +4 -0
- package/dist/react/native/Dialog.hooks.js +7 -3
- package/dist/react/native/Navigation.hooks.js +19 -4
- package/dist/react/types.d.ts +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -83,7 +83,11 @@ const report = describeKit({ kit: variant });
|
|
|
83
83
|
|
|
84
84
|
## Provider ports and overlays
|
|
85
85
|
|
|
86
|
-
`KitProvider` accepts `kit`, `agent`, `overlayContainer`, `toast`, `cancelLabel`, `guard`, `needs`, and `children`. It creates an overlay element under `document.body` when none is supplied and removes that element on unmount. Dialog and
|
|
86
|
+
`KitProvider` accepts `kit`, `agent`, `overlayContainer`, `toast`, `cancelLabel`, `guard`, `needs`, and `children`. It creates an overlay element under `document.body` when none is supplied and removes that element on unmount. Dialog, confirmation and native menu overlays portal there. `Overlay` also accepts an explicit `container`.
|
|
87
|
+
|
|
88
|
+
Ordinary interactive facades and native controls publish a handle by default. `agentHandle="save-record"` supplies a durable name; `agentHandle={false}` suppresses addressing, including caller-supplied `data-agent-*` attributes. Existing handles in `attrs` keep their names. Automatic handles use mounted React identity, so they survive rerenders and keyed reordering but may change after remount or reload. Give independently server-rendered React roots different `identifierPrefix` values, as for accessible React IDs. Menu and tab leaves derive their names from item IDs, and dialog close buttons use the component base plus `-close`. Portalled leaves retain their page metadata. Tags do not grant permission to operate a control.
|
|
89
|
+
|
|
90
|
+
Secret fields and reveal controls remain private before and after reveal. Ordinary feature confirmations use a mounted base by default. A human-only confirmation with no supplied base leaves both decisions unpublished; existing explicit-base cancellation semantics remain available. Withheld actions carry an explicit opt-out so nested facades cannot recreate them.
|
|
87
91
|
|
|
88
92
|
The agent port is `agent({ handle }, { role, label }) => KitAttrs`. The host owns validation and runtime wiring; ui-kit has no dependency on an agent runtime. Components forward metadata to the declared focus target. Select keeps an `HTMLSelectElement`, visible or synchronized in custom implementations.
|
|
89
93
|
|
package/dist/confirm.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface ConfirmInput {
|
|
|
9
9
|
readonly tone?: ConfirmTone;
|
|
10
10
|
readonly pending?: boolean;
|
|
11
11
|
readonly consequence?: string;
|
|
12
|
-
readonly agentHandle?: string;
|
|
12
|
+
readonly agentHandle?: string | false;
|
|
13
13
|
readonly agentMayConfirm?: boolean;
|
|
14
14
|
}
|
|
15
15
|
export declare function planConfirm(required: ConfirmInput, _optional?: Record<string, never>): Readonly<{
|
package/dist/confirm.js
CHANGED
|
@@ -7,7 +7,7 @@ export function planConfirm(required, _optional = {}) {
|
|
|
7
7
|
const consequenceLabel = consequence ? '; ' + consequence : '';
|
|
8
8
|
const confirmLabel = `${required.confirmLabel} — ${required.title}${consequenceLabel}`;
|
|
9
9
|
const cancelLabel = required.cancelLabel ?? 'Cancel';
|
|
10
|
-
const agent = (action, label) => required.agentHandle
|
|
10
|
+
const agent = (action, label) => typeof required.agentHandle !== 'string' ? undefined :
|
|
11
11
|
{ handle: `${required.agentHandle}-${action}`, role: 'button', label };
|
|
12
12
|
return Object.freeze({ initialFocus: 'cancel', pending, dismissible: required.open && !pending,
|
|
13
13
|
cancelDisabled: pending, confirmDisabled: pending, cancelLabel, confirmLabel, consequence,
|
package/dist/kit-contract.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare const kitSpec: {
|
|
|
27
27
|
readonly portal: "none";
|
|
28
28
|
readonly safety: false;
|
|
29
29
|
readonly behaviors: readonly ["press", "disabled-blocks-press", "attrs-on-focus-target"];
|
|
30
|
-
readonly props: readonly ["attrs", "className", "children", "disabled", "pending", "variant", "type", "ref", "onPress"];
|
|
30
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "children", "disabled", "pending", "variant", "type", "ref", "onPress"];
|
|
31
31
|
readonly events: readonly ["onPress"];
|
|
32
32
|
readonly variants: readonly ["primary", "secondary", "danger", "warning", "ghost"];
|
|
33
33
|
readonly states: readonly ["disabled", "pending"];
|
|
@@ -41,7 +41,7 @@ export declare const kitSpec: {
|
|
|
41
41
|
readonly portal: "none";
|
|
42
42
|
readonly safety: false;
|
|
43
43
|
readonly behaviors: readonly ["accessible-label", "press", "attrs-on-focus-target"];
|
|
44
|
-
readonly props: readonly ["attrs", "className", "children", "disabled", "pending", "variant", "type", "ref", "onPress", "label"];
|
|
44
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "children", "disabled", "pending", "variant", "type", "ref", "onPress", "label"];
|
|
45
45
|
readonly events: readonly ["onPress"];
|
|
46
46
|
readonly variants: readonly ["primary", "secondary", "danger", "warning", "ghost"];
|
|
47
47
|
readonly states: readonly ["disabled", "pending"];
|
|
@@ -55,7 +55,7 @@ export declare const kitSpec: {
|
|
|
55
55
|
readonly portal: "none";
|
|
56
56
|
readonly safety: false;
|
|
57
57
|
readonly behaviors: readonly ["value-change", "labelled-control", "attrs-on-focus-target", "secret-reveal"];
|
|
58
|
-
readonly props: readonly ["attrs", "className", "label", "value", "disabled", "required", "placeholder", "type", "ref", "onValueChange", "secretToggleLabels"];
|
|
58
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "label", "value", "disabled", "required", "placeholder", "type", "ref", "onValueChange", "secretToggleLabels"];
|
|
59
59
|
readonly events: readonly ["onValueChange"];
|
|
60
60
|
readonly variants: readonly [];
|
|
61
61
|
readonly states: readonly ["disabled"];
|
|
@@ -69,7 +69,7 @@ export declare const kitSpec: {
|
|
|
69
69
|
readonly portal: "none";
|
|
70
70
|
readonly safety: false;
|
|
71
71
|
readonly behaviors: readonly ["value-change", "labelled-control", "attrs-on-focus-target"];
|
|
72
|
-
readonly props: readonly ["attrs", "className", "label", "value", "disabled", "required", "placeholder", "ref", "onValueChange", "rows"];
|
|
72
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "label", "value", "disabled", "required", "placeholder", "ref", "onValueChange", "rows"];
|
|
73
73
|
readonly events: readonly ["onValueChange"];
|
|
74
74
|
readonly variants: readonly [];
|
|
75
75
|
readonly states: readonly ["disabled"];
|
|
@@ -83,7 +83,7 @@ export declare const kitSpec: {
|
|
|
83
83
|
readonly portal: "none";
|
|
84
84
|
readonly safety: false;
|
|
85
85
|
readonly behaviors: readonly ["native-select", "value-change", "attrs-on-focus-target"];
|
|
86
|
-
readonly props: readonly ["attrs", "className", "label", "value", "disabled", "required", "ref", "onValueChange", "options"];
|
|
86
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "label", "value", "disabled", "required", "ref", "onValueChange", "options"];
|
|
87
87
|
readonly events: readonly ["onValueChange"];
|
|
88
88
|
readonly variants: readonly [];
|
|
89
89
|
readonly states: readonly ["disabled"];
|
|
@@ -97,7 +97,7 @@ export declare const kitSpec: {
|
|
|
97
97
|
readonly portal: "none";
|
|
98
98
|
readonly safety: false;
|
|
99
99
|
readonly behaviors: readonly ["checked-change", "labelled-control", "attrs-on-focus-target"];
|
|
100
|
-
readonly props: readonly ["attrs", "className", "label", "checked", "disabled", "ref", "onCheckedChange"];
|
|
100
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "label", "checked", "disabled", "ref", "onCheckedChange"];
|
|
101
101
|
readonly events: readonly ["onCheckedChange"];
|
|
102
102
|
readonly variants: readonly [];
|
|
103
103
|
readonly states: readonly ["disabled"];
|
|
@@ -111,7 +111,7 @@ export declare const kitSpec: {
|
|
|
111
111
|
readonly portal: "none";
|
|
112
112
|
readonly safety: false;
|
|
113
113
|
readonly behaviors: readonly ["checked-change", "switch-role", "attrs-on-focus-target"];
|
|
114
|
-
readonly props: readonly ["attrs", "className", "label", "checked", "disabled", "ref", "onCheckedChange"];
|
|
114
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "label", "checked", "disabled", "ref", "onCheckedChange"];
|
|
115
115
|
readonly events: readonly ["onCheckedChange"];
|
|
116
116
|
readonly variants: readonly [];
|
|
117
117
|
readonly states: readonly ["disabled"];
|
|
@@ -125,7 +125,7 @@ export declare const kitSpec: {
|
|
|
125
125
|
readonly portal: "overlay";
|
|
126
126
|
readonly safety: false;
|
|
127
127
|
readonly behaviors: readonly ["escape-dismissal", "pending-blocks-dismissal", "focus-restore"];
|
|
128
|
-
readonly props: readonly ["attrs", "className", "open", "title", "children", "pending", "closeLabel", "ref", "onClose"];
|
|
128
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "open", "title", "children", "pending", "closeLabel", "ref", "onClose"];
|
|
129
129
|
readonly events: readonly ["onClose"];
|
|
130
130
|
readonly variants: readonly [];
|
|
131
131
|
readonly states: readonly ["disabled", "pending"];
|
|
@@ -139,7 +139,7 @@ export declare const kitSpec: {
|
|
|
139
139
|
readonly portal: "overlay";
|
|
140
140
|
readonly safety: true;
|
|
141
141
|
readonly behaviors: readonly ["pending-blocks-every-dismissal", "cancel-first-focus", "agent-confirm-withheld", "consequence-label"];
|
|
142
|
-
readonly props: readonly ["attrs", "className", "open", "title", "body", "confirmLabel", "cancelLabel", "tone", "pending", "consequence", "
|
|
142
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "open", "title", "body", "confirmLabel", "cancelLabel", "tone", "pending", "consequence", "agentMayConfirm", "errorLabel", "actionAccessibleNames", "onConfirm", "onCancel"];
|
|
143
143
|
readonly events: readonly ["onConfirm", "onCancel"];
|
|
144
144
|
readonly variants: readonly ["default", "warning", "danger"];
|
|
145
145
|
readonly states: readonly ["disabled", "pending"];
|
|
@@ -153,7 +153,7 @@ export declare const kitSpec: {
|
|
|
153
153
|
readonly portal: "none";
|
|
154
154
|
readonly safety: false;
|
|
155
155
|
readonly behaviors: readonly ["roving-tabs", "labelled-panel"];
|
|
156
|
-
readonly props: readonly ["attrs", "className", "label", "value", "items", "onValueChange"];
|
|
156
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "label", "value", "items", "onValueChange"];
|
|
157
157
|
readonly events: readonly ["onValueChange"];
|
|
158
158
|
readonly variants: readonly [];
|
|
159
159
|
readonly states: readonly [];
|
|
@@ -167,7 +167,7 @@ export declare const kitSpec: {
|
|
|
167
167
|
readonly portal: "none";
|
|
168
168
|
readonly safety: false;
|
|
169
169
|
readonly behaviors: readonly ["roving-menu", "escape-dismissal", "focus-restore"];
|
|
170
|
-
readonly props: readonly ["attrs", "className", "label", "items", "disabled"];
|
|
170
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "label", "items", "disabled"];
|
|
171
171
|
readonly events: readonly [];
|
|
172
172
|
readonly variants: readonly [];
|
|
173
173
|
readonly states: readonly ["open"];
|
|
@@ -181,7 +181,7 @@ export declare const kitSpec: {
|
|
|
181
181
|
readonly portal: "overlay";
|
|
182
182
|
readonly safety: false;
|
|
183
183
|
readonly behaviors: readonly ["live-region", "dismiss-toast"];
|
|
184
|
-
readonly props: readonly ["attrs", "className", "message", "tone", "dismissLabel", "onDismiss"];
|
|
184
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "message", "tone", "dismissLabel", "onDismiss"];
|
|
185
185
|
readonly events: readonly ["onDismiss"];
|
|
186
186
|
readonly variants: readonly ["info", "success", "warning", "danger"];
|
|
187
187
|
readonly states: readonly [];
|
|
@@ -195,7 +195,7 @@ export declare const kitSpec: {
|
|
|
195
195
|
readonly portal: "none";
|
|
196
196
|
readonly safety: false;
|
|
197
197
|
readonly behaviors: readonly ["focus-tooltip", "hover-tooltip", "escape-dismissal"];
|
|
198
|
-
readonly props: readonly ["attrs", "className", "content", "children", "label"];
|
|
198
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "content", "children", "label"];
|
|
199
199
|
readonly events: readonly [];
|
|
200
200
|
readonly variants: readonly [];
|
|
201
201
|
readonly states: readonly ["open"];
|
|
@@ -209,7 +209,7 @@ export declare const kitSpec: {
|
|
|
209
209
|
readonly portal: "none";
|
|
210
210
|
readonly safety: false;
|
|
211
211
|
readonly behaviors: readonly ["status-region"];
|
|
212
|
-
readonly props: readonly ["attrs", "className", "children", "tone"];
|
|
212
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "children", "tone"];
|
|
213
213
|
readonly events: readonly [];
|
|
214
214
|
readonly variants: readonly ["info", "success", "warning", "danger"];
|
|
215
215
|
readonly states: readonly [];
|
|
@@ -223,7 +223,7 @@ export declare const kitSpec: {
|
|
|
223
223
|
readonly portal: "none";
|
|
224
224
|
readonly safety: false;
|
|
225
225
|
readonly behaviors: readonly ["accessible-label"];
|
|
226
|
-
readonly props: readonly ["attrs", "className", "label"];
|
|
226
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "label"];
|
|
227
227
|
readonly events: readonly [];
|
|
228
228
|
readonly variants: readonly [];
|
|
229
229
|
readonly states: readonly [];
|
|
@@ -237,7 +237,7 @@ export declare const kitSpec: {
|
|
|
237
237
|
readonly portal: "none";
|
|
238
238
|
readonly safety: false;
|
|
239
239
|
readonly behaviors: readonly ["text-content"];
|
|
240
|
-
readonly props: readonly ["attrs", "className", "children", "tone"];
|
|
240
|
+
readonly props: readonly ["attrs", "className", "agentHandle", "children", "tone"];
|
|
241
241
|
readonly events: readonly [];
|
|
242
242
|
readonly variants: readonly ["info", "success", "warning", "danger"];
|
|
243
243
|
readonly states: readonly [];
|
package/dist/kit-contract.js
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
export const KIT_CONTRACT = { id: '@jini-ai/ui-kit', version: '1.0.0' };
|
|
3
3
|
const ATTRS_ON_FOCUS_TARGET = 'attrs-on-focus-target';
|
|
4
4
|
export const kitSpec = {
|
|
5
|
-
Button: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.button"], "focusTarget": "button", "portal": "none", "safety": false, "behaviors": ["press", "disabled-blocks-press", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "children", "disabled", "pending", "variant", "type", "ref", "onPress"], "events": ["onPress"], "variants": ["primary", "secondary", "danger", "warning", "ghost"], "states": ["disabled", "pending"] },
|
|
6
|
-
IconButton: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.icon-button"], "focusTarget": "button", "portal": "none", "safety": false, "behaviors": ["accessible-label", "press", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "children", "disabled", "pending", "variant", "type", "ref", "onPress", "label"], "events": ["onPress"], "variants": ["primary", "secondary", "danger", "warning", "ghost"], "states": ["disabled", "pending"] },
|
|
7
|
-
TextField: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.text-field", "kit.field-label", "kit.secret-toggle"], "focusTarget": "input", "portal": "none", "safety": false, "behaviors": ["value-change", "labelled-control", ATTRS_ON_FOCUS_TARGET, "secret-reveal"], "props": ["attrs", "className", "label", "value", "disabled", "required", "placeholder", "type", "ref", "onValueChange", "secretToggleLabels"], "events": ["onValueChange"], "variants": [], "states": ["disabled"] },
|
|
8
|
-
TextArea: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.text-area", "kit.field-label"], "focusTarget": "textarea", "portal": "none", "safety": false, "behaviors": ["value-change", "labelled-control", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "label", "value", "disabled", "required", "placeholder", "ref", "onValueChange", "rows"], "events": ["onValueChange"], "variants": [], "states": ["disabled"] },
|
|
9
|
-
Select: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.select", "kit.field-label"], "focusTarget": "select", "portal": "none", "safety": false, "behaviors": ["native-select", "value-change", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "label", "value", "disabled", "required", "ref", "onValueChange", "options"], "events": ["onValueChange"], "variants": [], "states": ["disabled"] },
|
|
10
|
-
Checkbox: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.checkbox"], "focusTarget": "input", "portal": "none", "safety": false, "behaviors": ["checked-change", "labelled-control", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "label", "checked", "disabled", "ref", "onCheckedChange"], "events": ["onCheckedChange"], "variants": [], "states": ["disabled"] },
|
|
11
|
-
Switch: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.switch"], "focusTarget": "input", "portal": "none", "safety": false, "behaviors": ["checked-change", "switch-role", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "label", "checked", "disabled", "ref", "onCheckedChange"], "events": ["onCheckedChange"], "variants": [], "states": ["disabled"] },
|
|
12
|
-
Dialog: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.dialog", "kit.dialog-title", "kit.dialog-close", "kit.overlay"], "focusTarget": "dialog", "portal": "overlay", "safety": false, "behaviors": ["escape-dismissal", "pending-blocks-dismissal", "focus-restore"], "props": ["attrs", "className", "open", "title", "children", "pending", "closeLabel", "ref", "onClose"], "events": ["onClose"], "variants": [], "states": ["disabled", "pending"] },
|
|
13
|
-
ConfirmDialog: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["confirm.dialog", "confirm.title", "confirm.body", "confirm.actions", "confirm.cancel", "confirm.confirm"], "focusTarget": "cancel", "portal": "overlay", "safety": true, "behaviors": ["pending-blocks-every-dismissal", "cancel-first-focus", "agent-confirm-withheld", "consequence-label"], "props": ["attrs", "className", "open", "title", "body", "confirmLabel", "cancelLabel", "tone", "pending", "consequence", "
|
|
14
|
-
Tabs: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.tabs", "kit.tab", "kit.tab-panel"], "focusTarget": "active-tab", "portal": "none", "safety": false, "behaviors": ["roving-tabs", "labelled-panel"], "props": ["attrs", "className", "label", "value", "items", "onValueChange"], "events": ["onValueChange"], "variants": [], "states": [] },
|
|
15
|
-
Menu: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.menu-trigger", "kit.menu", "kit.menu-item"], "focusTarget": "trigger-and-item", "portal": "none", "safety": false, "behaviors": ["roving-menu", "escape-dismissal", "focus-restore"], "props": ["attrs", "className", "label", "items", "disabled"], "events": [], "variants": [], "states": ["open"] },
|
|
16
|
-
Toast: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.toast", "kit.toast-dismiss", "kit.toast-region"], "focusTarget": "dismiss", "portal": "overlay", "safety": false, "behaviors": ["live-region", "dismiss-toast"], "props": ["attrs", "className", "message", "tone", "dismissLabel", "onDismiss"], "events": ["onDismiss"], "variants": ["info", "success", "warning", "danger"], "states": [] },
|
|
17
|
-
Tooltip: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.tooltip-trigger", "kit.tooltip"], "focusTarget": "trigger", "portal": "none", "safety": false, "behaviors": ["focus-tooltip", "hover-tooltip", "escape-dismissal"], "props": ["attrs", "className", "content", "children", "label"], "events": [], "variants": [], "states": ["open"] },
|
|
18
|
-
Notice: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.notice"], "focusTarget": "root", "portal": "none", "safety": false, "behaviors": ["status-region"], "props": ["attrs", "className", "children", "tone"], "events": [], "variants": ["info", "success", "warning", "danger"], "states": [] },
|
|
19
|
-
Spinner: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.spinner"], "focusTarget": "root", "portal": "none", "safety": false, "behaviors": ["accessible-label"], "props": ["attrs", "className", "label"], "events": [], "variants": [], "states": [] },
|
|
20
|
-
Badge: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.badge"], "focusTarget": "root", "portal": "none", "safety": false, "behaviors": ["text-content"], "props": ["attrs", "className", "children", "tone"], "events": [], "variants": ["info", "success", "warning", "danger"], "states": [] },
|
|
5
|
+
Button: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.button"], "focusTarget": "button", "portal": "none", "safety": false, "behaviors": ["press", "disabled-blocks-press", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "agentHandle", "children", "disabled", "pending", "variant", "type", "ref", "onPress"], "events": ["onPress"], "variants": ["primary", "secondary", "danger", "warning", "ghost"], "states": ["disabled", "pending"] },
|
|
6
|
+
IconButton: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.icon-button"], "focusTarget": "button", "portal": "none", "safety": false, "behaviors": ["accessible-label", "press", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "agentHandle", "children", "disabled", "pending", "variant", "type", "ref", "onPress", "label"], "events": ["onPress"], "variants": ["primary", "secondary", "danger", "warning", "ghost"], "states": ["disabled", "pending"] },
|
|
7
|
+
TextField: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.text-field", "kit.field-label", "kit.secret-toggle"], "focusTarget": "input", "portal": "none", "safety": false, "behaviors": ["value-change", "labelled-control", ATTRS_ON_FOCUS_TARGET, "secret-reveal"], "props": ["attrs", "className", "agentHandle", "label", "value", "disabled", "required", "placeholder", "type", "ref", "onValueChange", "secretToggleLabels"], "events": ["onValueChange"], "variants": [], "states": ["disabled"] },
|
|
8
|
+
TextArea: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.text-area", "kit.field-label"], "focusTarget": "textarea", "portal": "none", "safety": false, "behaviors": ["value-change", "labelled-control", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "agentHandle", "label", "value", "disabled", "required", "placeholder", "ref", "onValueChange", "rows"], "events": ["onValueChange"], "variants": [], "states": ["disabled"] },
|
|
9
|
+
Select: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.select", "kit.field-label"], "focusTarget": "select", "portal": "none", "safety": false, "behaviors": ["native-select", "value-change", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "agentHandle", "label", "value", "disabled", "required", "ref", "onValueChange", "options"], "events": ["onValueChange"], "variants": [], "states": ["disabled"] },
|
|
10
|
+
Checkbox: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.checkbox"], "focusTarget": "input", "portal": "none", "safety": false, "behaviors": ["checked-change", "labelled-control", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "agentHandle", "label", "checked", "disabled", "ref", "onCheckedChange"], "events": ["onCheckedChange"], "variants": [], "states": ["disabled"] },
|
|
11
|
+
Switch: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.switch"], "focusTarget": "input", "portal": "none", "safety": false, "behaviors": ["checked-change", "switch-role", ATTRS_ON_FOCUS_TARGET], "props": ["attrs", "className", "agentHandle", "label", "checked", "disabled", "ref", "onCheckedChange"], "events": ["onCheckedChange"], "variants": [], "states": ["disabled"] },
|
|
12
|
+
Dialog: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.dialog", "kit.dialog-title", "kit.dialog-close", "kit.overlay"], "focusTarget": "dialog", "portal": "overlay", "safety": false, "behaviors": ["escape-dismissal", "pending-blocks-dismissal", "focus-restore"], "props": ["attrs", "className", "agentHandle", "open", "title", "children", "pending", "closeLabel", "ref", "onClose"], "events": ["onClose"], "variants": [], "states": ["disabled", "pending"] },
|
|
13
|
+
ConfirmDialog: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["confirm.dialog", "confirm.title", "confirm.body", "confirm.actions", "confirm.cancel", "confirm.confirm"], "focusTarget": "cancel", "portal": "overlay", "safety": true, "behaviors": ["pending-blocks-every-dismissal", "cancel-first-focus", "agent-confirm-withheld", "consequence-label"], "props": ["attrs", "className", "agentHandle", "open", "title", "body", "confirmLabel", "cancelLabel", "tone", "pending", "consequence", "agentMayConfirm", "errorLabel", "actionAccessibleNames", "onConfirm", "onCancel"], "events": ["onConfirm", "onCancel"], "variants": ["default", "warning", "danger"], "states": ["disabled", "pending"] },
|
|
14
|
+
Tabs: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.tabs", "kit.tab", "kit.tab-panel"], "focusTarget": "active-tab", "portal": "none", "safety": false, "behaviors": ["roving-tabs", "labelled-panel"], "props": ["attrs", "className", "agentHandle", "label", "value", "items", "onValueChange"], "events": ["onValueChange"], "variants": [], "states": [] },
|
|
15
|
+
Menu: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.menu-trigger", "kit.menu", "kit.menu-item"], "focusTarget": "trigger-and-item", "portal": "none", "safety": false, "behaviors": ["roving-menu", "escape-dismissal", "focus-restore"], "props": ["attrs", "className", "agentHandle", "label", "items", "disabled"], "events": [], "variants": [], "states": ["open"] },
|
|
16
|
+
Toast: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.toast", "kit.toast-dismiss", "kit.toast-region"], "focusTarget": "dismiss", "portal": "overlay", "safety": false, "behaviors": ["live-region", "dismiss-toast"], "props": ["attrs", "className", "agentHandle", "message", "tone", "dismissLabel", "onDismiss"], "events": ["onDismiss"], "variants": ["info", "success", "warning", "danger"], "states": [] },
|
|
17
|
+
Tooltip: { "status": "implemented", "tier": "composite", "since": "1.0.0", "parts": ["kit.tooltip-trigger", "kit.tooltip"], "focusTarget": "trigger", "portal": "none", "safety": false, "behaviors": ["focus-tooltip", "hover-tooltip", "escape-dismissal"], "props": ["attrs", "className", "agentHandle", "content", "children", "label"], "events": [], "variants": [], "states": ["open"] },
|
|
18
|
+
Notice: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.notice"], "focusTarget": "root", "portal": "none", "safety": false, "behaviors": ["status-region"], "props": ["attrs", "className", "agentHandle", "children", "tone"], "events": [], "variants": ["info", "success", "warning", "danger"], "states": [] },
|
|
19
|
+
Spinner: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.spinner"], "focusTarget": "root", "portal": "none", "safety": false, "behaviors": ["accessible-label"], "props": ["attrs", "className", "agentHandle", "label"], "events": [], "variants": [], "states": [] },
|
|
20
|
+
Badge: { "status": "implemented", "tier": "control", "since": "1.0.0", "parts": ["kit.badge"], "focusTarget": "root", "portal": "none", "safety": false, "behaviors": ["text-content"], "props": ["attrs", "className", "agentHandle", "children", "tone"], "events": [], "variants": ["info", "success", "warning", "danger"], "states": [] },
|
|
21
21
|
Link: { "status": "planned", "tier": "composite", "since": null, "parts": [], "focusTarget": "planned", "portal": "none", "safety": false, "behaviors": [], "props": [], "events": [], "variants": [], "states": [] },
|
|
22
22
|
Icon: { "status": "planned", "tier": "composite", "since": null, "parts": [], "focusTarget": "planned", "portal": "none", "safety": false, "behaviors": [], "props": [], "events": [], "variants": [], "states": [] },
|
|
23
23
|
RadioGroup: { "status": "planned", "tier": "composite", "since": null, "parts": [], "focusTarget": "planned", "portal": "none", "safety": false, "behaviors": [], "props": [], "events": [], "variants": [], "states": [] },
|
|
@@ -2,6 +2,7 @@ import type { ReactNode } from 'react';
|
|
|
2
2
|
import { type ImplementedComponentName } from '../kit-contract.js';
|
|
3
3
|
import type { KitContextValue, KitProviderProps, ReactKitProps, ToastProps } from './types.js';
|
|
4
4
|
import { createToastService } from '../toast.js';
|
|
5
|
+
/** Keep fallback guard failures local to this mounted consumer, like provider-owned kits. */
|
|
5
6
|
export declare function useKit(_required?: Record<string, never>, _optional?: Record<string, never>): KitContextValue;
|
|
6
7
|
export declare function useKitProvider(required: KitProviderProps, _optional?: Record<string, never>): KitContextValue;
|
|
7
8
|
export declare function useOverlayContainer(_required?: Record<string, never>, _optional?: Record<string, never>): HTMLElement | null;
|
package/dist/react/Kit.hooks.js
CHANGED
|
@@ -5,13 +5,15 @@ import { createKit } from './kit.js';
|
|
|
5
5
|
import { assertKitContract, KitConfigError } from '../needs.js';
|
|
6
6
|
import { kitSpec } from '../kit-contract.js';
|
|
7
7
|
import { createToastService } from '../toast.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
defaultValue ??= { kit: createKit({}), agent: undefined, overlayContainer: null, toast: undefined, cancelLabel: 'Cancel', guard: 'fallback' };
|
|
11
|
-
return defaultValue;
|
|
12
|
-
}
|
|
8
|
+
import { useControlAttrs } from './agent-attrs.hooks.js';
|
|
9
|
+
/** Keep fallback guard failures local to this mounted consumer, like provider-owned kits. */
|
|
13
10
|
export function useKit(_required = {}, _optional = {}) {
|
|
14
|
-
|
|
11
|
+
const context = useKitContext({});
|
|
12
|
+
const fallback = useRef(undefined);
|
|
13
|
+
if (context)
|
|
14
|
+
return context;
|
|
15
|
+
fallback.current ??= { kit: createKit({}), agent: undefined, overlayContainer: null, toast: undefined, cancelLabel: 'Cancel', guard: 'fallback' };
|
|
16
|
+
return fallback.current;
|
|
15
17
|
}
|
|
16
18
|
export function useKitProvider(required, _optional = {}) {
|
|
17
19
|
const fallback = useMemo(() => createKit({}), []);
|
|
@@ -63,9 +65,18 @@ export function useKitComponent(required, _optional = {}) {
|
|
|
63
65
|
const context = useKit({});
|
|
64
66
|
return context.kit.components[required.name];
|
|
65
67
|
}
|
|
68
|
+
const facadeRoles = new Map([
|
|
69
|
+
['Button', 'button'], ['IconButton', 'button'], ['TextField', 'field'], ['TextArea', 'field'],
|
|
70
|
+
['Select', 'field'],
|
|
71
|
+
]);
|
|
66
72
|
export function useFacade(required, _optional = {}) {
|
|
67
73
|
const Component = useKitComponent({ name: required.name });
|
|
68
|
-
const
|
|
74
|
+
const part = required.name === 'Tabs' ? 'kit.tab' : kitSpec[required.name].parts[0];
|
|
75
|
+
const role = facadeRoles.get(required.name);
|
|
76
|
+
const attrs = { 'data-jini-part': part, ...useControlAttrs(required.props, { part: required.name.toLowerCase(), role,
|
|
77
|
+
enabled: role !== undefined || ['Menu', 'Checkbox', 'Switch'].includes(required.name),
|
|
78
|
+
secret: required.name === 'TextField' && 'type' in required.props && required.props.type === 'password',
|
|
79
|
+
label: 'label' in required.props ? required.props.label : undefined }) };
|
|
69
80
|
return { Component, props: { ...required.props, attrs } };
|
|
70
81
|
}
|
|
71
82
|
export function useToast(_required = {}, _optional = {}) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgentSpec, KitAttrs } from '../attrs.js';
|
|
2
|
+
import type { BaseProps } from './types.js';
|
|
3
|
+
/** Resolves one mounted control's metadata. Privacy and opt-out override caller addressing;
|
|
4
|
+
* supplied handles are preserved, while defaults use React instance identity rather than labels.
|
|
5
|
+
* @complexity O(p + i) in attribute count and React id length; no I/O or persistent state. */
|
|
6
|
+
export declare function useControlAttrs(required: BaseProps, optional: {
|
|
7
|
+
part: string;
|
|
8
|
+
role?: AgentSpec['role'] | undefined;
|
|
9
|
+
label?: string | undefined;
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
secret?: boolean;
|
|
12
|
+
}): KitAttrs;
|
|
13
|
+
/** Derives one actual control from a composite base and stable item/action id, retaining page metadata.
|
|
14
|
+
* Explicit item attributes remain authoritative; opt-out removes addressing at every leaf.
|
|
15
|
+
* @complexity O(p + a) in attribute count and action id length, without I/O. */
|
|
16
|
+
export declare function childControlAttrs(required: {
|
|
17
|
+
parent: BaseProps;
|
|
18
|
+
attrs: KitAttrs;
|
|
19
|
+
action: string;
|
|
20
|
+
}, optional?: {
|
|
21
|
+
attrs?: KitAttrs | undefined;
|
|
22
|
+
label?: string | undefined;
|
|
23
|
+
role?: AgentSpec['role'] | undefined;
|
|
24
|
+
}): KitAttrs;
|
|
25
|
+
//# sourceMappingURL=agent-attrs.hooks.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useId } from 'react';
|
|
2
|
+
import { secretControlAttrs } from '../attrs.js';
|
|
3
|
+
import { useKitContext } from './context.js';
|
|
4
|
+
/** Local identity encoding keeps the UI contract independent of any agent runtime.
|
|
5
|
+
* Compatible with the agent handle segment grammar; opaque ids use a bounded fingerprint.
|
|
6
|
+
* @complexity O(n) time in id length, O(1) auxiliary space. No effects. */
|
|
7
|
+
function handleSegment({ value }) {
|
|
8
|
+
if (value.length <= 40 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value) && !/^h-[0-9a-f]{16}$/.test(value))
|
|
9
|
+
return value;
|
|
10
|
+
let hash = 0xcbf29ce484222325n;
|
|
11
|
+
for (let index = 0; index < value.length; index += 1)
|
|
12
|
+
hash = BigInt.asUintN(64, (hash ^ BigInt(value.charCodeAt(index))) * 0x100000001b3n);
|
|
13
|
+
return `h-${hash.toString(16).padStart(16, '0')}`;
|
|
14
|
+
}
|
|
15
|
+
function ordinaryAttrs({ attrs = {} }) {
|
|
16
|
+
return Object.fromEntries(Object.entries(attrs).filter(([key]) => !key.toLowerCase().startsWith('data-agent-')));
|
|
17
|
+
}
|
|
18
|
+
function definedAttrs({ attrs = {} }) {
|
|
19
|
+
return Object.fromEntries(Object.entries(attrs).filter(([, value]) => value !== undefined));
|
|
20
|
+
}
|
|
21
|
+
function publishedAttrs({ handle, agent, role, label }) {
|
|
22
|
+
return agent ? agent({ handle }, { ...(role === undefined ? {} : { role }), ...(label === undefined ? {} : { label }) }) : { 'data-agent-element': handle, 'data-agent-role': role, 'data-agent-label': label };
|
|
23
|
+
}
|
|
24
|
+
function controlHandle({ props, id, options }) {
|
|
25
|
+
const supplied = props.attrs?.['data-agent-element'];
|
|
26
|
+
if (typeof supplied === 'string')
|
|
27
|
+
return supplied;
|
|
28
|
+
if (typeof props.agentHandle === 'string')
|
|
29
|
+
return props.agentHandle;
|
|
30
|
+
return options.enabled === false ? undefined : `kit-${handleSegment({ value: id })}-${options.part}`;
|
|
31
|
+
}
|
|
32
|
+
/** Resolves one mounted control's metadata. Privacy and opt-out override caller addressing;
|
|
33
|
+
* supplied handles are preserved, while defaults use React instance identity rather than labels.
|
|
34
|
+
* @complexity O(p + i) in attribute count and React id length; no I/O or persistent state. */
|
|
35
|
+
export function useControlAttrs(required, optional) {
|
|
36
|
+
const id = useId(), context = useKitContext({});
|
|
37
|
+
if (optional.secret || required.attrs?.['data-agent-private'] !== undefined)
|
|
38
|
+
return secretControlAttrs({ attrs: required.attrs ?? {} });
|
|
39
|
+
if (required.agentHandle === false)
|
|
40
|
+
return ordinaryAttrs({ attrs: required.attrs });
|
|
41
|
+
const handle = controlHandle({ props: required, id, options: optional });
|
|
42
|
+
if (handle === undefined)
|
|
43
|
+
return required.attrs ?? {};
|
|
44
|
+
return { ...publishedAttrs({ handle, agent: context?.agent, role: optional.role, label: optional.label }), ...definedAttrs({ attrs: required.attrs }) };
|
|
45
|
+
}
|
|
46
|
+
/** Derives one actual control from a composite base and stable item/action id, retaining page metadata.
|
|
47
|
+
* Explicit item attributes remain authoritative; opt-out removes addressing at every leaf.
|
|
48
|
+
* @complexity O(p + a) in attribute count and action id length, without I/O. */
|
|
49
|
+
export function childControlAttrs(required, optional = {}) {
|
|
50
|
+
const combined = { ...required.attrs, ...optional.attrs };
|
|
51
|
+
if (required.attrs['data-agent-private'] !== undefined || optional.attrs?.['data-agent-private'] !== undefined)
|
|
52
|
+
return secretControlAttrs({ attrs: combined });
|
|
53
|
+
if (required.parent.agentHandle === false)
|
|
54
|
+
return ordinaryAttrs({ attrs: combined });
|
|
55
|
+
const base = required.attrs['data-agent-element'];
|
|
56
|
+
if (typeof base !== 'string')
|
|
57
|
+
return optional.attrs ?? {};
|
|
58
|
+
const root = base.length > 80 ? handleSegment({ value: base }) : base;
|
|
59
|
+
return { 'data-agent-element': `${root}-${handleSegment({ value: required.action })}`, 'data-agent-page': required.attrs['data-agent-page'],
|
|
60
|
+
'data-agent-role': optional.role ?? 'button', 'data-agent-label': optional.label, ...definedAttrs({ attrs: optional.attrs }) };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=agent-attrs.hooks.js.map
|
|
@@ -4,10 +4,33 @@ import { useKit, useOverlayContainer } from '../Kit.hooks.js';
|
|
|
4
4
|
import { isDevelopment } from '../context.js';
|
|
5
5
|
import { nativeKit } from '../native/index.js';
|
|
6
6
|
import { inspectConfirm } from './guard.js';
|
|
7
|
+
import { useControlAttrs } from '../agent-attrs.hooks.js';
|
|
8
|
+
function actionHandle({ spec }) { return spec?.handle ?? false; }
|
|
9
|
+
function reactConfirmationPlan({ props, attrs, cancelLabel, pending }) {
|
|
10
|
+
const handle = attrs['data-agent-element'];
|
|
11
|
+
return planConfirm({ ...props, agentHandle: typeof handle === 'string' ? handle : false, cancelLabel, pending });
|
|
12
|
+
}
|
|
13
|
+
function confirmationFrameAttrs({ props, attrs }) {
|
|
14
|
+
return props.agentHandle === false || props.attrs?.['data-agent-private'] !== undefined ? attrs : props.attrs;
|
|
15
|
+
}
|
|
16
|
+
function actionMetadata({ spec, agent, page }) {
|
|
17
|
+
if (!spec)
|
|
18
|
+
return {};
|
|
19
|
+
const attrs = agent ? agent({ handle: spec.handle }, { role: spec.role, label: spec.label }) : {};
|
|
20
|
+
return { ...attrs, ...(page === undefined ? {} : { 'data-agent-page': page }) };
|
|
21
|
+
}
|
|
22
|
+
function actionLabel({ label, spec, fallback, explicit }) {
|
|
23
|
+
if (label !== undefined)
|
|
24
|
+
return label;
|
|
25
|
+
if (!explicit)
|
|
26
|
+
return fallback;
|
|
27
|
+
return spec?.label ?? fallback;
|
|
28
|
+
}
|
|
7
29
|
/** Shared confirmation policy and execution; adapters may supply their existing agent-attribute port.
|
|
8
30
|
* @example useConfirmController({ open, title, confirmLabel, onConfirm, onCancel }, { agent: agentAttrs })
|
|
9
31
|
*/
|
|
10
32
|
export function useConfirmController(required, optional = {}) {
|
|
33
|
+
const baseAttrs = useControlAttrs(required, { part: 'confirm', enabled: required.agentMayConfirm !== false });
|
|
11
34
|
const context = useKit({}), titleId = useId(), frameId = useId(), consequenceId = useId(), cancelRef = useRef(null);
|
|
12
35
|
const boundaryRef = useRef(null), latest = useRef(required), mounted = useRef(false);
|
|
13
36
|
const [executing, setExecuting] = useState(false), [error, setError] = useState(false);
|
|
@@ -16,13 +39,13 @@ export function useConfirmController(required, optional = {}) {
|
|
|
16
39
|
const model = useMemo(() => createConfirmController({ read: () => latest.current,
|
|
17
40
|
onCancel: () => latest.current.onCancel({}), onConfirm: () => latest.current.onConfirm({}) }), []);
|
|
18
41
|
const pending = !!required.pending || executing;
|
|
19
|
-
const plan =
|
|
42
|
+
const plan = reactConfirmationPlan({ props: required, attrs: baseAttrs, cancelLabel: required.cancelLabel ?? context.cancelLabel, pending });
|
|
20
43
|
const actionState = pending ? 'pending' : 'ready';
|
|
21
44
|
function actionAttrs(input, _optional = {}) {
|
|
22
45
|
const { part, spec } = input;
|
|
23
|
-
const label = input.label
|
|
46
|
+
const label = actionLabel({ label: input.label, spec, fallback: input.fallbackLabel, explicit: typeof required.agentHandle === 'string' });
|
|
24
47
|
const agent = optional.agent ?? context.agent;
|
|
25
|
-
const attrs =
|
|
48
|
+
const attrs = actionMetadata({ spec, agent, page: baseAttrs['data-agent-page'] });
|
|
26
49
|
return Object.freeze({ ...attrs, 'data-jini-part': part, 'aria-label': label,
|
|
27
50
|
...(required.actionAccessibleNames && plan.consequence ? { 'aria-describedby': consequenceId } : {}),
|
|
28
51
|
'aria-busy': pending, 'data-jini-state': actionState });
|
|
@@ -46,14 +69,14 @@ export function useConfirmController(required, optional = {}) {
|
|
|
46
69
|
}
|
|
47
70
|
return { className: required.className, open: required.open, pending, title: required.title, body: required.body, consequence: plan.consequence,
|
|
48
71
|
error: error ? createElement('p', { className: 'jini-notice jini-notice-error', role: 'alert' }, required.errorLabel ?? 'The action failed. Please try again.') : null,
|
|
49
|
-
frameAttrs: Object.freeze({ ...required
|
|
72
|
+
frameAttrs: Object.freeze({ ...confirmationFrameAttrs({ props: required, attrs: baseAttrs }), id: frameId, 'data-jini-part': 'confirm.dialog', role: 'alertdialog',
|
|
50
73
|
'aria-labelledby': titleId, 'aria-modal': true, 'aria-busy': pending }),
|
|
51
74
|
titleAttrs: { id: titleId, 'data-jini-part': 'confirm.title' },
|
|
52
75
|
consequenceAttrs: { id: consequenceId, 'data-jini-part': 'confirm.consequence' },
|
|
53
|
-
cancel: Object.freeze({ attrs: actionAttrs({ part: 'confirm.cancel', spec: plan.cancel, label: required.actionAccessibleNames?.cancel, fallbackLabel: `${plan.cancelLabel} — no action taken` }),
|
|
76
|
+
cancel: Object.freeze({ agentHandle: actionHandle({ spec: plan.cancel }), attrs: actionAttrs({ part: 'confirm.cancel', spec: plan.cancel, label: required.actionAccessibleNames?.cancel, fallbackLabel: `${plan.cancelLabel} — no action taken` }),
|
|
54
77
|
ref: cancelRef, disabled: pending, variant: 'secondary', children: plan.cancelLabel,
|
|
55
78
|
onPress: () => { model.requestDismiss({ reason: 'cancel-button' }); } }),
|
|
56
|
-
confirm: Object.freeze({ attrs: actionAttrs({ part: 'confirm.confirm', spec: plan.confirm, label: required.actionAccessibleNames?.confirm, fallbackLabel: plan.confirmLabel }), disabled: pending, pending,
|
|
79
|
+
confirm: Object.freeze({ agentHandle: actionHandle({ spec: plan.confirm }), attrs: actionAttrs({ part: 'confirm.confirm', spec: plan.confirm, label: required.actionAccessibleNames?.confirm, fallbackLabel: plan.confirmLabel }), disabled: pending, pending,
|
|
57
80
|
variant: plan.confirmVariant, children: required.confirmLabel, onPress }),
|
|
58
81
|
boundaryRef, overlayContainer: useOverlayContainer({}), agentMayConfirm: required.agentMayConfirm !== false,
|
|
59
82
|
requestDismiss: model.requestDismiss,
|
|
@@ -17,9 +17,9 @@ export declare function useNativeButton(required: ButtonProps, _optional?: Recor
|
|
|
17
17
|
};
|
|
18
18
|
export declare function useNativeIconButton(required: IconButtonProps, _optional?: Record<string, never>): {
|
|
19
19
|
props: {
|
|
20
|
-
id?: string;
|
|
21
20
|
'data-jini-part': string;
|
|
22
21
|
'aria-label': string;
|
|
22
|
+
id?: string;
|
|
23
23
|
ref: import("react").Ref<HTMLButtonElement> | undefined;
|
|
24
24
|
className: string;
|
|
25
25
|
type: "button" | "submit" | "reset";
|
|
@@ -140,11 +140,12 @@ export declare function useNativeToast(required: ToastProps, _optional?: Record<
|
|
|
140
140
|
};
|
|
141
141
|
message: string;
|
|
142
142
|
dismiss: import("react").DetailedReactHTMLElement<{
|
|
143
|
-
type: string;
|
|
144
|
-
className: string;
|
|
145
|
-
'data-jini-part': string;
|
|
146
143
|
'aria-label': string;
|
|
147
144
|
onClick: () => void | undefined;
|
|
145
|
+
id?: string;
|
|
146
|
+
'data-jini-part': string;
|
|
147
|
+
type: string;
|
|
148
|
+
className: string;
|
|
148
149
|
}, HTMLElement> | null;
|
|
149
150
|
};
|
|
150
151
|
export declare function useNativeNotice(required: NoticeProps, _optional?: Record<string, never>): {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createElement, useId, useState } from 'react';
|
|
2
2
|
import { secretControlAttrs } from '../../attrs.js';
|
|
3
|
+
import { childControlAttrs, useControlAttrs } from '../agent-attrs.hooks.js';
|
|
3
4
|
export function useNativeButton(required, _optional = {}) {
|
|
4
5
|
const readyState = required.disabled ? 'disabled' : 'ready';
|
|
6
|
+
const attrs = useControlAttrs(required, { part: 'button', role: 'button' });
|
|
5
7
|
return { children: required.children, props: { 'data-jini-part': 'kit.button', ref: required.ref, className: `jini-btn jini-btn-${required.variant ?? 'primary'} ${required.className ?? ''}`.trim(),
|
|
6
8
|
type: required.type ?? 'button', disabled: !!required.disabled || !!required.pending,
|
|
7
9
|
'aria-busy': required.pending, 'data-jini-variant': required.variant ?? 'primary',
|
|
@@ -9,16 +11,17 @@ export function useNativeButton(required, _optional = {}) {
|
|
|
9
11
|
onClick: () => { if (!required.disabled && !required.pending)
|
|
10
12
|
required.onPress?.({}); },
|
|
11
13
|
// Opaque metadata wins over generated metadata; behavioral props cannot be supplied through attrs.
|
|
12
|
-
...
|
|
14
|
+
...attrs } };
|
|
13
15
|
}
|
|
14
16
|
export function useNativeIconButton(required, _optional = {}) {
|
|
15
17
|
const vm = useNativeButton(required);
|
|
16
|
-
return { ...vm, props: { ...vm.props, 'data-jini-part': 'kit.icon-button', 'aria-label': required.label
|
|
18
|
+
return { ...vm, props: { ...vm.props, 'data-jini-part': required.attrs?.['data-jini-part'] ?? 'kit.icon-button', 'aria-label': required.label } };
|
|
17
19
|
}
|
|
18
|
-
function useField(required) {
|
|
20
|
+
function useField(required, role = 'field') {
|
|
19
21
|
const generated = useId();
|
|
22
|
+
const attrs = useControlAttrs(required, { part: 'field', role, label: required.label });
|
|
20
23
|
return { id: required.attrs?.id ?? generated, label: required.label, labelAttrs: { 'data-jini-part': 'kit.field-label', className: 'jini-field' },
|
|
21
|
-
props: { ...
|
|
24
|
+
props: { ...attrs, className: `jini-input ${required.className ?? ''}`.trim(), disabled: required.disabled, required: required.required } };
|
|
22
25
|
}
|
|
23
26
|
/** Eye / eye-off glyphs, decorative: the button's aria-label carries the meaning. */
|
|
24
27
|
const EYE_PATHS = ['M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z', 'M12 9a3 3 0 1 0 0 6 3 3 0 1 0 0-6z'];
|
|
@@ -81,16 +84,19 @@ export function useNativeSelect(required, _optional = {}) {
|
|
|
81
84
|
}
|
|
82
85
|
export function useNativeCheckbox(required, optional = {}) {
|
|
83
86
|
const generated = useId();
|
|
87
|
+
const attrs = useControlAttrs(required, { part: optional.role ?? 'checkbox', label: required.label });
|
|
84
88
|
return { label: required.label, id: required.attrs?.id ?? generated,
|
|
85
|
-
props: { ...
|
|
89
|
+
props: { ...attrs, id: required.attrs?.id ?? generated, ref: required.ref, className: `jini-checkbox ${required.className ?? ''}`.trim(),
|
|
86
90
|
type: 'checkbox', role: optional.role, checked: required.checked, disabled: required.disabled,
|
|
87
91
|
onChange: (event) => { if (!required.disabled)
|
|
88
92
|
required.onCheckedChange({ checked: event.currentTarget.checked }); } } };
|
|
89
93
|
}
|
|
90
94
|
export function useNativeToast(required, _optional = {}) {
|
|
95
|
+
const attrs = useControlAttrs(required, { part: 'toast' });
|
|
91
96
|
return { props: { 'data-jini-part': 'kit.toast', ...required.attrs, className: `jini-toast ${required.className ?? ''}`.trim(),
|
|
92
97
|
role: required.tone === 'danger' ? 'alert' : 'status', tabIndex: -1, 'data-jini-variant': required.tone ?? 'info' },
|
|
93
98
|
message: required.message, dismiss: required.onDismiss ? createElement('button', { type: 'button', className: 'jini-btn jini-btn-ghost jini-toast-dismiss', 'data-jini-part': 'kit.toast-dismiss',
|
|
99
|
+
...childControlAttrs({ parent: required, attrs, action: 'dismiss' }, { label: required.dismissLabel ?? 'Dismiss notification' }),
|
|
94
100
|
'aria-label': required.dismissLabel ?? 'Dismiss notification', onClick: () => required.onDismiss?.({}) }, '×') : null };
|
|
95
101
|
}
|
|
96
102
|
export function useNativeNotice(required, _optional = {}) {
|
|
@@ -17,9 +17,11 @@ export declare function useNativeDialog(required: DialogProps, optional?: {
|
|
|
17
17
|
variant: "secondary";
|
|
18
18
|
attrs: {
|
|
19
19
|
'data-jini-part': string;
|
|
20
|
+
id?: string;
|
|
20
21
|
};
|
|
21
22
|
disabled: boolean;
|
|
22
23
|
onPress: () => void;
|
|
24
|
+
agentHandle?: false;
|
|
23
25
|
};
|
|
24
26
|
props: {
|
|
25
27
|
className: string;
|
|
@@ -65,9 +67,11 @@ export declare function useNativeConfirm(required: ConfirmViewProps, { Button }?
|
|
|
65
67
|
variant: "secondary";
|
|
66
68
|
attrs: {
|
|
67
69
|
'data-jini-part': string;
|
|
70
|
+
id?: string;
|
|
68
71
|
};
|
|
69
72
|
disabled: boolean;
|
|
70
73
|
onPress: () => void;
|
|
74
|
+
agentHandle?: false;
|
|
71
75
|
};
|
|
72
76
|
};
|
|
73
77
|
//# sourceMappingURL=Dialog.hooks.d.ts.map
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { useId, useImperativeHandle, useLayoutEffect, useRef } from 'react';
|
|
2
2
|
import { NativeButton } from './Controls.js';
|
|
3
|
+
import { childControlAttrs, useControlAttrs } from '../agent-attrs.hooks.js';
|
|
3
4
|
/** Native modal lifecycle shared by kit views and compatibility adapters; DOM effects are O(1).
|
|
4
5
|
* The document port preserves hosts' focus injection seam without introducing another lifecycle.
|
|
5
6
|
* @example useNativeDialog({ open, title, onClose }, { initialFocus: () => cancelRef.current?.focus() })
|
|
6
7
|
*/
|
|
7
8
|
export function useNativeDialog(required, optional = {}) {
|
|
8
9
|
const dialogRef = useRef(null), opener = useRef(null), titleId = useId();
|
|
10
|
+
const attrs = useControlAttrs(required, { part: 'dialog' });
|
|
11
|
+
const closeAttrs = childControlAttrs({ parent: required, attrs, action: 'close' }, { label: required.closeLabel ?? 'Close' });
|
|
12
|
+
const frameAttrs = required.agentHandle === false || required.attrs?.['data-agent-private'] !== undefined ? attrs : required.attrs;
|
|
9
13
|
useImperativeHandle(required.ref, () => dialogRef.current, []);
|
|
10
14
|
useLayoutEffect(() => {
|
|
11
15
|
const dialog = dialogRef.current;
|
|
@@ -39,9 +43,9 @@ export function useNativeDialog(required, optional = {}) {
|
|
|
39
43
|
// Open is the transition boundary: editing content must not recapture the original trigger.
|
|
40
44
|
}, [required.open]);
|
|
41
45
|
return { title: required.title, children: required.children, titleId, closeLabel: required.closeLabel ?? 'Close',
|
|
42
|
-
closeProps: { className: 'jini-dialog-close', variant: 'secondary', attrs: { 'data-jini-part': 'kit.dialog-close' }, disabled: !!required.pending, onPress: () => { if (!required.pending)
|
|
46
|
+
closeProps: { ...(required.agentHandle === false ? { agentHandle: false } : {}), className: 'jini-dialog-close', variant: 'secondary', attrs: { ...closeAttrs, 'data-jini-part': 'kit.dialog-close' }, disabled: !!required.pending, onPress: () => { if (!required.pending)
|
|
43
47
|
required.onClose({}); } },
|
|
44
|
-
props: { 'aria-labelledby': titleId, 'data-jini-part': 'kit.dialog', ...
|
|
48
|
+
props: { 'aria-labelledby': titleId, 'data-jini-part': 'kit.dialog', ...frameAttrs, className: `jini-dialog ${required.className ?? ''}`.trim(), ref: dialogRef, tabIndex: -1,
|
|
45
49
|
'aria-busy': required.pending,
|
|
46
50
|
onCancel: (event) => { event.preventDefault(); if (!required.pending)
|
|
47
51
|
required.onClose({}); },
|
|
@@ -73,7 +77,7 @@ function isOutsideBox(event) {
|
|
|
73
77
|
*/
|
|
74
78
|
export function useNativeConfirm(required, { Button = NativeButton } = {}) {
|
|
75
79
|
const c = required.controller;
|
|
76
|
-
const vm = useNativeDialog({ open: c.open, title: c.title, pending: c.pending, onClose: () => c.requestDismiss({ reason: 'close' }) }, { initialFocus: () => c.focusInitial({}) });
|
|
80
|
+
const vm = useNativeDialog({ open: c.open, title: c.title, pending: c.pending, agentHandle: false, onClose: () => c.requestDismiss({ reason: 'close' }) }, { initialFocus: () => c.focusInitial({}) });
|
|
77
81
|
return { ...vm, controller: c, Button: c.nativeActions ? NativeButton : Button,
|
|
78
82
|
props: { ...vm.props, ...c.frameAttrs, className: `jini-dialog jini-confirm-dialog ${c.className ?? ''}`.trim(), role: 'alertdialog' } };
|
|
79
83
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createElement, useId, useRef, useState, useEffect, useLayoutEffect } from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
|
+
import { childControlAttrs, useControlAttrs } from '../agent-attrs.hooks.js';
|
|
4
|
+
import { useKitContext } from '../context.js';
|
|
3
5
|
function navigationIndex(required, _optional = {}) {
|
|
4
6
|
switch (required.key) {
|
|
5
7
|
case 'Home': return 0;
|
|
@@ -9,8 +11,16 @@ function navigationIndex(required, _optional = {}) {
|
|
|
9
11
|
default: return undefined;
|
|
10
12
|
}
|
|
11
13
|
}
|
|
14
|
+
function legacyActiveTabAttrs({ parent, item, active }) {
|
|
15
|
+
if (!active || parent.agentHandle !== undefined)
|
|
16
|
+
return {};
|
|
17
|
+
if (parent.attrs?.['data-agent-private'] !== undefined || item.attrs?.['data-agent-private'] !== undefined)
|
|
18
|
+
return {};
|
|
19
|
+
return Object.fromEntries(Object.entries(parent.attrs ?? {}).filter(([, value]) => value !== undefined));
|
|
20
|
+
}
|
|
12
21
|
export function useNativeTabs(required, _optional = {}) {
|
|
13
22
|
const prefix = useId(), root = useRef(null);
|
|
23
|
+
const attrs = useControlAttrs(required, { part: 'tabs' });
|
|
14
24
|
const enabled = required.items.filter(item => !item.disabled);
|
|
15
25
|
const active = enabled.find(item => item.id === required.value) ?? enabled[0];
|
|
16
26
|
function onKeyDown(event) {
|
|
@@ -24,7 +34,9 @@ export function useNativeTabs(required, _optional = {}) {
|
|
|
24
34
|
}
|
|
25
35
|
const tabs = required.items.map((item, index) => createElement('button', {
|
|
26
36
|
key: item.id, type: 'button', role: 'tab', id: `${prefix}-tab-${index}`, 'data-jini-part': 'kit.tab', className: 'jini-tab-bar-item',
|
|
27
|
-
...
|
|
37
|
+
...childControlAttrs({ parent: required, attrs, action: item.id }, { attrs: item.attrs, label: item.label }),
|
|
38
|
+
// A caller's legacy base was attached to the active tab; keep that explicit name.
|
|
39
|
+
...legacyActiveTabAttrs({ parent: required, item, active: item.id === active?.id }),
|
|
28
40
|
'data-tab-id': item.id, 'aria-controls': `${prefix}-panel-${index}`, 'aria-selected': item.id === active?.id,
|
|
29
41
|
disabled: item.disabled, tabIndex: item.id === active?.id ? 0 : -1,
|
|
30
42
|
onClick: () => { if (!item.disabled)
|
|
@@ -37,6 +49,9 @@ export function useNativeTabs(required, _optional = {}) {
|
|
|
37
49
|
export function useNativeMenu(required, _optional = {}) {
|
|
38
50
|
const [open, setOpen] = useState(false), trigger = useRef(null), menu = useRef(null), id = useId();
|
|
39
51
|
const [position, setPosition] = useState({ top: 0, left: 0 });
|
|
52
|
+
// Read the binding without loading default-kit hooks, which import this native assembly.
|
|
53
|
+
const container = useKitContext({})?.overlayContainer ?? (typeof document === 'undefined' ? null : document.body);
|
|
54
|
+
const attrs = useControlAttrs(required, { part: 'menu', role: 'button', label: required.label });
|
|
40
55
|
useLayoutEffect(() => {
|
|
41
56
|
if (!open || !trigger.current || !menu.current)
|
|
42
57
|
return undefined;
|
|
@@ -84,14 +99,14 @@ export function useNativeMenu(required, _optional = {}) {
|
|
|
84
99
|
}
|
|
85
100
|
}
|
|
86
101
|
const items = required.items.map(item => createElement('button', { key: item.id, role: 'menuitem', type: 'button', tabIndex: -1,
|
|
87
|
-
'data-jini-part': 'kit.menu-item', ...item.attrs, className: `jini-row-menu-item ${item.attrs?.['data-jini-variant'] === 'danger' ? 'jini-btn-danger' : ''}`.trim(), disabled: item.disabled,
|
|
102
|
+
'data-jini-part': 'kit.menu-item', ...childControlAttrs({ parent: required, attrs, action: item.id }, { attrs: item.attrs, label: item.label }), className: `jini-row-menu-item ${item.attrs?.['data-jini-variant'] === 'danger' ? 'jini-btn-danger' : ''}`.trim(), disabled: item.disabled,
|
|
88
103
|
onClick: () => { if (!item.disabled) {
|
|
89
104
|
close();
|
|
90
105
|
item.onPress({});
|
|
91
106
|
} }, onKeyDown: (event) => onKeyDown(event, enabled.indexOf(item)) }, item.label));
|
|
92
107
|
const menuProps = { ref: menu, id, role: 'menu', 'aria-label': required.label, hidden: !open, className: 'jini-row-menu-popup', 'data-jini-part': 'kit.menu', style: { position: 'fixed', ...position } };
|
|
93
|
-
return { label: '⋮', items, popup: open ? createPortal(createElement('div', menuProps, items),
|
|
94
|
-
triggerProps: { 'data-jini-part': 'kit.menu-trigger', ...
|
|
108
|
+
return { label: '⋮', items, popup: open && container ? createPortal(createElement('div', menuProps, items), container) : null,
|
|
109
|
+
triggerProps: { 'data-jini-part': 'kit.menu-trigger', ...attrs, ref: trigger, type: 'button',
|
|
95
110
|
className: `jini-row-menu-trigger ${required.className ?? ''}`.trim(), disabled: required.disabled, 'aria-label': required.label, 'aria-haspopup': 'menu', 'aria-expanded': open, 'aria-controls': id,
|
|
96
111
|
onClick: () => { if (!required.disabled)
|
|
97
112
|
setOpen(!open); }, onKeyDown: (event) => {
|
package/dist/react/types.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ import type { ToastMessage, ToastService } from '../toast.js';
|
|
|
7
7
|
export interface BaseProps {
|
|
8
8
|
readonly attrs?: KitAttrs;
|
|
9
9
|
readonly className?: string;
|
|
10
|
+
/** Defaults to a mounted-instance handle. Set false to suppress all addressing on this control. */
|
|
11
|
+
readonly agentHandle?: string | false;
|
|
10
12
|
}
|
|
11
13
|
export type ActionPort = (required: Record<string, never>, optional?: Record<string, never>) => void;
|
|
12
14
|
export type ValuePort<T> = (required: {
|
|
@@ -198,7 +200,7 @@ export interface KitProviderProps {
|
|
|
198
200
|
readonly kit?: ResolvedKit;
|
|
199
201
|
readonly children: ReactNode;
|
|
200
202
|
readonly agent?: AgentAttrsPort;
|
|
201
|
-
readonly overlayContainer?: HTMLElement;
|
|
203
|
+
readonly overlayContainer?: HTMLElement | null;
|
|
202
204
|
readonly needs?: readonly KitNeeds[];
|
|
203
205
|
readonly toast?: ToastService;
|
|
204
206
|
readonly cancelLabel?: string;
|