@destyler/dialog 0.2.6 → 0.2.9
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/dist/index.d.mts +5 -4
- package/dist/index.mjs +11 -7
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -80,9 +80,10 @@ interface PublicContext extends DirectionProperty, CommonProperties, Dismissable
|
|
|
80
80
|
*/
|
|
81
81
|
'open'?: boolean | undefined;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
83
|
+
* The initial open state of the dialog when it is not controlled.
|
|
84
|
+
* Prefer this over seeding with `open` for uncontrolled usage.
|
|
84
85
|
*/
|
|
85
|
-
'
|
|
86
|
+
'defaultOpen'?: boolean | undefined;
|
|
86
87
|
}
|
|
87
88
|
type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
|
|
88
89
|
type ComputedContext = Readonly<{}>;
|
|
@@ -128,7 +129,7 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
|
|
|
128
129
|
declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
|
|
129
130
|
//#endregion
|
|
130
131
|
//#region src/props.d.ts
|
|
131
|
-
declare const props: ("open" | "
|
|
132
|
-
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "open" | "
|
|
132
|
+
declare const props: ("open" | "ids" | "trapFocus" | "preventScroll" | "modal" | "initialFocusEl" | "finalFocusEl" | "restoreFocus" | "onOpenChange" | "closeOnInteractOutside" | "closeOnEscape" | "aria-label" | "role" | "defaultOpen" | "dir" | "id" | "getRootNode" | "onEscapeKeyDown" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside" | "persistentElements")[];
|
|
133
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "open" | "ids" | "trapFocus" | "preventScroll" | "modal" | "initialFocusEl" | "finalFocusEl" | "restoreFocus" | "onOpenChange" | "closeOnInteractOutside" | "closeOnEscape" | "aria-label" | "role" | "defaultOpen" | "dir" | "id" | "getRootNode" | "onEscapeKeyDown" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside" | "persistentElements">];
|
|
133
134
|
//#endregion
|
|
134
135
|
export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type FocusOutsideEvent, type InteractOutsideEvent, type OpenChangeDetails, type PointerDownOutsideEvent, type Service, anatomy, connect, machine, props, splitProps };
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { ariaHidden } from "@destyler/aria-hidden";
|
|
|
4
4
|
import { trackDismissableElement } from "@destyler/dismissable";
|
|
5
5
|
import { trapFocus } from "@destyler/focus-trap";
|
|
6
6
|
import { preventBodyScroll } from "@destyler/remove-scroll";
|
|
7
|
-
import { compact, createSplitProps } from "@destyler/utils";
|
|
7
|
+
import { compact, createSplitProps, isControlled, resolveControllableOpen, withControllableProvided } from "@destyler/utils";
|
|
8
8
|
import { createMachine } from "@destyler/xstate";
|
|
9
9
|
import { createProps } from "@destyler/types";
|
|
10
10
|
|
|
@@ -85,7 +85,7 @@ function connect(state, send, normalize) {
|
|
|
85
85
|
"id": dom.getContentId(state.context),
|
|
86
86
|
"tabIndex": -1,
|
|
87
87
|
"data-state": open ? "open" : "closed",
|
|
88
|
-
"aria-modal":
|
|
88
|
+
"aria-modal": !!state.context.modal,
|
|
89
89
|
"aria-label": ariaLabel || void 0,
|
|
90
90
|
"aria-labelledby": ariaLabel || !rendered.title ? void 0 : dom.getTitleId(state.context),
|
|
91
91
|
"aria-describedby": rendered.description ? dom.getDescriptionId(state.context) : void 0
|
|
@@ -124,10 +124,11 @@ function connect(state, send, normalize) {
|
|
|
124
124
|
//#endregion
|
|
125
125
|
//#region src/machine.ts
|
|
126
126
|
function machine(userContext) {
|
|
127
|
-
const ctx = compact(userContext);
|
|
127
|
+
const ctx = compact(withControllableProvided(userContext, ["open"]));
|
|
128
|
+
const { initialOpen } = resolveControllableOpen(ctx);
|
|
128
129
|
return createMachine({
|
|
129
130
|
id: "dialog",
|
|
130
|
-
initial:
|
|
131
|
+
initial: initialOpen ? "open" : "closed",
|
|
131
132
|
context: {
|
|
132
133
|
role: "dialog",
|
|
133
134
|
renderedElements: {
|
|
@@ -143,7 +144,10 @@ function machine(userContext) {
|
|
|
143
144
|
...ctx
|
|
144
145
|
},
|
|
145
146
|
created: ["setAlertDialogProps"],
|
|
146
|
-
watch: {
|
|
147
|
+
watch: {
|
|
148
|
+
open: ["toggleVisibility"],
|
|
149
|
+
role: ["setAlertDialogProps"]
|
|
150
|
+
},
|
|
147
151
|
states: {
|
|
148
152
|
open: {
|
|
149
153
|
entry: ["checkRenderedElements", "syncZIndex"],
|
|
@@ -190,7 +194,7 @@ function machine(userContext) {
|
|
|
190
194
|
} }
|
|
191
195
|
}
|
|
192
196
|
}, {
|
|
193
|
-
guards: { isOpenControlled: (ctx$1) =>
|
|
197
|
+
guards: { isOpenControlled: (ctx$1) => isControlled(ctx$1, "open") },
|
|
194
198
|
activities: {
|
|
195
199
|
trackDismissableElement(ctx$1, _evt, { send }) {
|
|
196
200
|
const getContentEl = () => dom.getContentEl(ctx$1);
|
|
@@ -295,8 +299,8 @@ const props = createProps()([
|
|
|
295
299
|
"onInteractOutside",
|
|
296
300
|
"onOpenChange",
|
|
297
301
|
"onPointerDownOutside",
|
|
298
|
-
"open.controlled",
|
|
299
302
|
"open",
|
|
303
|
+
"defaultOpen",
|
|
300
304
|
"persistentElements",
|
|
301
305
|
"preventScroll",
|
|
302
306
|
"restoreFocus",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/dialog",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.9",
|
|
5
5
|
"description": "before taking action, please confirm.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@destyler/anatomy": "0.2.
|
|
26
|
-
"@destyler/aria-hidden": "0.2.
|
|
27
|
-
"@destyler/dismissable": "0.2.
|
|
28
|
-
"@destyler/dom": "0.2.
|
|
29
|
-
"@destyler/remove-scroll": "0.2.
|
|
30
|
-
"@destyler/
|
|
31
|
-
"@destyler/
|
|
32
|
-
"@destyler/utils": "0.2.
|
|
33
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.9",
|
|
26
|
+
"@destyler/aria-hidden": "0.2.9",
|
|
27
|
+
"@destyler/dismissable": "0.2.9",
|
|
28
|
+
"@destyler/dom": "0.2.9",
|
|
29
|
+
"@destyler/remove-scroll": "0.2.9",
|
|
30
|
+
"@destyler/focus-trap": "0.2.9",
|
|
31
|
+
"@destyler/types": "0.2.9",
|
|
32
|
+
"@destyler/utils": "0.2.9",
|
|
33
|
+
"@destyler/xstate": "0.2.9"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|