@jini-ai/ui-kit 0.1.1 → 0.1.3
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 +6 -0
- package/dist/react/confirm/ConfirmDialog.hooks.d.ts +7 -1
- package/dist/react/confirm/ConfirmDialog.hooks.js +6 -2
- package/dist/react/native/Dialog.hooks.d.ts +5 -0
- package/dist/react/native/Dialog.hooks.js +19 -2
- package/dist/react/native/index.d.ts +1 -0
- package/dist/react/native/index.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @jini-ai/ui-kit
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Tovu clean-up release (2026-10-08): code Tovu moved into Jini, plus the Jini clean-up (see the commit log since 0.1.1).
|
|
8
|
+
|
|
3
9
|
## 0.1.1 — 2026-10-05
|
|
4
10
|
|
|
5
11
|
- Native menu items step by their position among enabled items (from the render closure) instead of re-querying the menu ref. Same order as `focus()`; arrow keys skip a disabled item. Behavior unchanged.
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import type { AgentAttrsPort } from '../../attrs.js';
|
|
1
2
|
import type { ConfirmController, ConfirmDialogProps } from '../types.js';
|
|
2
|
-
|
|
3
|
+
/** Shared confirmation policy and execution; adapters may supply their existing agent-attribute port.
|
|
4
|
+
* @example useConfirmController({ open, title, confirmLabel, onConfirm, onCancel }, { agent: agentAttrs })
|
|
5
|
+
*/
|
|
6
|
+
export declare function useConfirmController(required: ConfirmDialogProps, optional?: {
|
|
7
|
+
agent?: AgentAttrsPort;
|
|
8
|
+
}): ConfirmController;
|
|
3
9
|
export declare function useConfirmFacade(required: ConfirmDialogProps, _optional?: Record<string, never>): {
|
|
4
10
|
Component: import("react").ComponentType<import("../types.js").ConfirmViewProps>;
|
|
5
11
|
controller: ConfirmController;
|
|
@@ -4,7 +4,10 @@ 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
|
-
|
|
7
|
+
/** Shared confirmation policy and execution; adapters may supply their existing agent-attribute port.
|
|
8
|
+
* @example useConfirmController({ open, title, confirmLabel, onConfirm, onCancel }, { agent: agentAttrs })
|
|
9
|
+
*/
|
|
10
|
+
export function useConfirmController(required, optional = {}) {
|
|
8
11
|
const context = useKit({}), titleId = useId(), frameId = useId(), consequenceId = useId(), cancelRef = useRef(null);
|
|
9
12
|
const boundaryRef = useRef(null), latest = useRef(required), mounted = useRef(false);
|
|
10
13
|
const [executing, setExecuting] = useState(false), [error, setError] = useState(false);
|
|
@@ -15,7 +18,8 @@ export function useConfirmController(required, _optional = {}) {
|
|
|
15
18
|
const pending = !!required.pending || executing;
|
|
16
19
|
const plan = planConfirm({ ...required, cancelLabel: required.cancelLabel ?? context.cancelLabel, pending });
|
|
17
20
|
function actionAttrs(part, spec, label) {
|
|
18
|
-
const
|
|
21
|
+
const agent = optional.agent ?? context.agent;
|
|
22
|
+
const attrs = spec && agent ? agent({ handle: spec.handle }, { role: spec.role, label: spec.label }) : {};
|
|
19
23
|
return Object.freeze({ ...attrs, 'data-jini-part': part, 'aria-label': label,
|
|
20
24
|
...(required.actionAccessibleNames && plan.consequence ? { 'aria-describedby': consequenceId } : {}),
|
|
21
25
|
'aria-busy': pending, 'data-jini-state': pending ? 'pending' : 'ready' });
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { MouseEvent, SyntheticEvent } from 'react';
|
|
2
2
|
import type { DialogProps, ConfirmViewProps } from '../types.js';
|
|
3
|
+
/** Native modal lifecycle shared by kit views and compatibility adapters; DOM effects are O(1).
|
|
4
|
+
* The document port preserves hosts' focus injection seam without introducing another lifecycle.
|
|
5
|
+
* @example useNativeDialog({ open, title, onClose }, { initialFocus: () => cancelRef.current?.focus() })
|
|
6
|
+
*/
|
|
3
7
|
export declare function useNativeDialog(required: DialogProps, optional?: {
|
|
4
8
|
initialFocus?: () => void;
|
|
9
|
+
document?: Pick<Document, 'activeElement'>;
|
|
5
10
|
}): {
|
|
6
11
|
title: string;
|
|
7
12
|
children: import("react").ReactNode;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useId, useImperativeHandle, useLayoutEffect, useRef } from 'react';
|
|
2
2
|
import { Button } from '../facade.js';
|
|
3
3
|
import { NativeButton } from './Controls.js';
|
|
4
|
+
/** Native modal lifecycle shared by kit views and compatibility adapters; DOM effects are O(1).
|
|
5
|
+
* The document port preserves hosts' focus injection seam without introducing another lifecycle.
|
|
6
|
+
* @example useNativeDialog({ open, title, onClose }, { initialFocus: () => cancelRef.current?.focus() })
|
|
7
|
+
*/
|
|
4
8
|
export function useNativeDialog(required, optional = {}) {
|
|
5
9
|
const dialogRef = useRef(null), opener = useRef(null), titleId = useId();
|
|
6
10
|
useImperativeHandle(required.ref, () => dialogRef.current, []);
|
|
@@ -13,7 +17,7 @@ export function useNativeDialog(required, optional = {}) {
|
|
|
13
17
|
opener.current.focus({ preventScroll: true });
|
|
14
18
|
return;
|
|
15
19
|
}
|
|
16
|
-
opener.current = document.activeElement;
|
|
20
|
+
opener.current = (optional.document ?? document).activeElement;
|
|
17
21
|
if (typeof dialog.showModal === 'function') {
|
|
18
22
|
if (!dialog.open)
|
|
19
23
|
dialog.showModal();
|
|
@@ -44,9 +48,22 @@ export function useNativeDialog(required, optional = {}) {
|
|
|
44
48
|
'aria-busy': required.pending,
|
|
45
49
|
onCancel: (event) => { event.preventDefault(); if (!required.pending)
|
|
46
50
|
required.onClose({}); },
|
|
47
|
-
|
|
51
|
+
// A click whose target is the <dialog> itself is not always the backdrop: the dialog's own
|
|
52
|
+
// padding and gaps hit it too, and so does the click that dismisses a native date/select
|
|
53
|
+
// popup inside it (seen live: closing a datetime picker closed the whole modal). Only a point
|
|
54
|
+
// outside the dialog's box is a backdrop click.
|
|
55
|
+
onClick: (event) => { if (event.target === event.currentTarget && !required.pending && isOutsideBox(event))
|
|
48
56
|
required.onClose({}); } } };
|
|
49
57
|
}
|
|
58
|
+
/** True when the pointer is outside the dialog's own rectangle, i.e. on the ::backdrop. A click with no
|
|
59
|
+
* coordinates (keyboard activation, synthetic test clicks) keeps the old target-only behaviour. */
|
|
60
|
+
function isOutsideBox(event) {
|
|
61
|
+
const { clientX: x, clientY: y } = event;
|
|
62
|
+
if (x === 0 && y === 0)
|
|
63
|
+
return true;
|
|
64
|
+
const r = event.currentTarget.getBoundingClientRect();
|
|
65
|
+
return x < r.left || x > r.right || y < r.top || y > r.bottom;
|
|
66
|
+
}
|
|
50
67
|
export function useNativeConfirm(required, _optional = {}) {
|
|
51
68
|
const c = required.controller;
|
|
52
69
|
const vm = useNativeDialog({ open: c.open, title: c.title, pending: c.pending, onClose: () => c.requestDismiss({ reason: 'close' }) }, { initialFocus: () => c.focusInitial({}) });
|
|
@@ -6,4 +6,5 @@ export const nativeKit = Object.freeze({ Button: NativeButton, IconButton: Nativ
|
|
|
6
6
|
Switch: NativeSwitch, Dialog: NativeDialog, ConfirmDialog: NativeConfirmDialog, Tabs: NativeTabs,
|
|
7
7
|
Menu: NativeMenu, Toast: NativeToast, Tooltip: NativeTooltip, Notice: NativeNotice, Spinner: NativeSpinner, Badge: NativeBadge });
|
|
8
8
|
// This is a concrete kit, rather than a forwarding subpath to another package's implementation.
|
|
9
|
+
export { useNativeDialog } from './Dialog.hooks.js';
|
|
9
10
|
//# sourceMappingURL=index.js.map
|