@destyler/dialog 0.2.10 → 0.2.12
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 +6 -9
- package/dist/index.mjs +41 -47
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import * as _destyler_anatomy0 from "@destyler/anatomy";
|
|
2
1
|
import { DismissableElementHandlers, FocusOutsideEvent, InteractOutsideEvent, PersistentElementOptions, PointerDownOutsideEvent } from "@destyler/dismissable";
|
|
3
|
-
import * as _destyler_xstate0 from "@destyler/xstate";
|
|
4
2
|
import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
|
|
5
3
|
import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
|
|
6
|
-
|
|
7
4
|
//#region src/anatomy.d.ts
|
|
8
|
-
declare const anatomy:
|
|
5
|
+
export declare const anatomy: import("@destyler/anatomy").AnatomyInstance<"trigger" | "backdrop" | "positioner" | "content" | "title" | "description" | "closeTrigger">;
|
|
9
6
|
//#endregion
|
|
10
7
|
//#region src/types.d.ts
|
|
11
8
|
interface OpenChangeDetails {
|
|
@@ -123,13 +120,13 @@ interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
123
120
|
}
|
|
124
121
|
//#endregion
|
|
125
122
|
//#region src/connect.d.ts
|
|
126
|
-
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
123
|
+
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
127
124
|
//#endregion
|
|
128
125
|
//#region src/machine.d.ts
|
|
129
|
-
declare function machine(userContext: UserDefinedContext):
|
|
126
|
+
export declare function machine(userContext: UserDefinedContext): import("@destyler/xstate").Machine<MachineContext, MachineState, import("@destyler/xstate").AnyEventObject>;
|
|
130
127
|
//#endregion
|
|
131
128
|
//#region src/props.d.ts
|
|
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">];
|
|
129
|
+
export 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")[];
|
|
130
|
+
export 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">];
|
|
134
131
|
//#endregion
|
|
135
|
-
export {
|
|
132
|
+
export type { MachineApi as Api, UserDefinedContext as Context, ElementIds, FocusOutsideEvent, InteractOutsideEvent, OpenChangeDetails, PointerDownOutsideEvent, Service };
|
package/dist/index.mjs
CHANGED
|
@@ -7,11 +7,9 @@ import { preventBodyScroll } from "@destyler/remove-scroll";
|
|
|
7
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
|
-
|
|
11
10
|
//#region src/anatomy.ts
|
|
12
11
|
const anatomy = createAnatomy("dialog").parts("trigger", "backdrop", "positioner", "content", "title", "description", "closeTrigger");
|
|
13
12
|
const parts = anatomy.build();
|
|
14
|
-
|
|
15
13
|
//#endregion
|
|
16
14
|
//#region src/dom.ts
|
|
17
15
|
const dom = createScope({
|
|
@@ -30,7 +28,6 @@ const dom = createScope({
|
|
|
30
28
|
getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
|
|
31
29
|
getCloseTriggerEl: (ctx) => dom.getById(ctx, dom.getCloseTriggerId(ctx))
|
|
32
30
|
});
|
|
33
|
-
|
|
34
31
|
//#endregion
|
|
35
32
|
//#region src/connect.ts
|
|
36
33
|
function connect(state, send, normalize) {
|
|
@@ -120,7 +117,6 @@ function connect(state, send, normalize) {
|
|
|
120
117
|
}
|
|
121
118
|
};
|
|
122
119
|
}
|
|
123
|
-
|
|
124
120
|
//#endregion
|
|
125
121
|
//#region src/machine.ts
|
|
126
122
|
function machine(userContext) {
|
|
@@ -194,24 +190,24 @@ function machine(userContext) {
|
|
|
194
190
|
} }
|
|
195
191
|
}
|
|
196
192
|
}, {
|
|
197
|
-
guards: { isOpenControlled: (ctx
|
|
193
|
+
guards: { isOpenControlled: (ctx) => isControlled(ctx, "open") },
|
|
198
194
|
activities: {
|
|
199
|
-
trackDismissableElement(ctx
|
|
200
|
-
const getContentEl = () => dom.getContentEl(ctx
|
|
195
|
+
trackDismissableElement(ctx, _evt, { send }) {
|
|
196
|
+
const getContentEl = () => dom.getContentEl(ctx);
|
|
201
197
|
return trackDismissableElement(getContentEl, {
|
|
202
198
|
defer: true,
|
|
203
|
-
pointerBlocking: ctx
|
|
204
|
-
exclude: [dom.getTriggerEl(ctx
|
|
199
|
+
pointerBlocking: ctx.modal,
|
|
200
|
+
exclude: [dom.getTriggerEl(ctx)],
|
|
205
201
|
onInteractOutside(event) {
|
|
206
|
-
ctx
|
|
207
|
-
if (!ctx
|
|
202
|
+
ctx.onInteractOutside?.(event);
|
|
203
|
+
if (!ctx.closeOnInteractOutside) event.preventDefault();
|
|
208
204
|
},
|
|
209
|
-
persistentElements: ctx
|
|
210
|
-
onFocusOutside: ctx
|
|
211
|
-
onPointerDownOutside: ctx
|
|
205
|
+
persistentElements: ctx.persistentElements,
|
|
206
|
+
onFocusOutside: ctx.onFocusOutside,
|
|
207
|
+
onPointerDownOutside: ctx.onPointerDownOutside,
|
|
212
208
|
onEscapeKeyDown(event) {
|
|
213
|
-
ctx
|
|
214
|
-
if (!ctx
|
|
209
|
+
ctx.onEscapeKeyDown?.(event);
|
|
210
|
+
if (!ctx.closeOnEscape) event.preventDefault();
|
|
215
211
|
},
|
|
216
212
|
onDismiss() {
|
|
217
213
|
send({
|
|
@@ -221,64 +217,63 @@ function machine(userContext) {
|
|
|
221
217
|
}
|
|
222
218
|
});
|
|
223
219
|
},
|
|
224
|
-
preventScroll(ctx
|
|
225
|
-
if (!ctx
|
|
226
|
-
return preventBodyScroll(dom.getDoc(ctx
|
|
220
|
+
preventScroll(ctx) {
|
|
221
|
+
if (!ctx.preventScroll) return;
|
|
222
|
+
return preventBodyScroll(dom.getDoc(ctx));
|
|
227
223
|
},
|
|
228
|
-
trapFocus(ctx
|
|
229
|
-
if (!ctx
|
|
230
|
-
const contentEl = () => dom.getContentEl(ctx
|
|
224
|
+
trapFocus(ctx) {
|
|
225
|
+
if (!ctx.trapFocus || !ctx.modal) return;
|
|
226
|
+
const contentEl = () => dom.getContentEl(ctx);
|
|
231
227
|
return trapFocus(contentEl, {
|
|
232
228
|
preventScroll: true,
|
|
233
|
-
returnFocusOnDeactivate: !!ctx
|
|
234
|
-
initialFocus: ctx
|
|
235
|
-
setReturnFocus: (el) => ctx
|
|
229
|
+
returnFocusOnDeactivate: !!ctx.restoreFocus,
|
|
230
|
+
initialFocus: ctx.initialFocusEl,
|
|
231
|
+
setReturnFocus: (el) => ctx.finalFocusEl?.() ?? el
|
|
236
232
|
});
|
|
237
233
|
},
|
|
238
|
-
hideContentBelow(ctx
|
|
239
|
-
if (!ctx
|
|
240
|
-
const getElements = () => [dom.getContentEl(ctx
|
|
234
|
+
hideContentBelow(ctx) {
|
|
235
|
+
if (!ctx.modal) return;
|
|
236
|
+
const getElements = () => [dom.getContentEl(ctx)];
|
|
241
237
|
return ariaHidden(getElements, { defer: true });
|
|
242
238
|
}
|
|
243
239
|
},
|
|
244
240
|
actions: {
|
|
245
|
-
setAlertDialogProps(ctx
|
|
246
|
-
if (ctx
|
|
247
|
-
ctx
|
|
248
|
-
ctx
|
|
241
|
+
setAlertDialogProps(ctx) {
|
|
242
|
+
if (ctx.role !== "alertdialog") return;
|
|
243
|
+
ctx.initialFocusEl ||= () => dom.getCloseTriggerEl(ctx);
|
|
244
|
+
ctx.closeOnInteractOutside = false;
|
|
249
245
|
},
|
|
250
|
-
checkRenderedElements(ctx
|
|
246
|
+
checkRenderedElements(ctx) {
|
|
251
247
|
raf(() => {
|
|
252
|
-
ctx
|
|
253
|
-
ctx
|
|
248
|
+
ctx.renderedElements.title = !!dom.getTitleEl(ctx);
|
|
249
|
+
ctx.renderedElements.description = !!dom.getDescriptionEl(ctx);
|
|
254
250
|
});
|
|
255
251
|
},
|
|
256
|
-
syncZIndex(ctx
|
|
252
|
+
syncZIndex(ctx) {
|
|
257
253
|
raf(() => {
|
|
258
|
-
const contentEl = dom.getContentEl(ctx
|
|
254
|
+
const contentEl = dom.getContentEl(ctx);
|
|
259
255
|
if (!contentEl) return;
|
|
260
256
|
const styles = getComputedStyle(contentEl);
|
|
261
|
-
[dom.getPositionerEl(ctx
|
|
257
|
+
[dom.getPositionerEl(ctx), dom.getBackdropEl(ctx)].forEach((node) => {
|
|
262
258
|
node?.style.setProperty("--z-index", styles.zIndex);
|
|
263
259
|
});
|
|
264
260
|
});
|
|
265
261
|
},
|
|
266
|
-
invokeOnClose(ctx
|
|
267
|
-
ctx
|
|
262
|
+
invokeOnClose(ctx) {
|
|
263
|
+
ctx.onOpenChange?.({ open: false });
|
|
268
264
|
},
|
|
269
|
-
invokeOnOpen(ctx
|
|
270
|
-
ctx
|
|
265
|
+
invokeOnOpen(ctx) {
|
|
266
|
+
ctx.onOpenChange?.({ open: true });
|
|
271
267
|
},
|
|
272
|
-
toggleVisibility(ctx
|
|
268
|
+
toggleVisibility(ctx, evt, { send }) {
|
|
273
269
|
send({
|
|
274
|
-
type: ctx
|
|
270
|
+
type: ctx.open ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE",
|
|
275
271
|
previousEvent: evt
|
|
276
272
|
});
|
|
277
273
|
}
|
|
278
274
|
}
|
|
279
275
|
});
|
|
280
276
|
}
|
|
281
|
-
|
|
282
277
|
//#endregion
|
|
283
278
|
//#region src/props.ts
|
|
284
279
|
const props = createProps()([
|
|
@@ -308,6 +303,5 @@ const props = createProps()([
|
|
|
308
303
|
"trapFocus"
|
|
309
304
|
]);
|
|
310
305
|
const splitProps = createSplitProps(props);
|
|
311
|
-
|
|
312
306
|
//#endregion
|
|
313
|
-
export { anatomy, connect, machine, props, splitProps };
|
|
307
|
+
export { anatomy, connect, machine, props, splitProps };
|
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.12",
|
|
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/
|
|
29
|
-
"@destyler/focus-trap": "0.2.
|
|
30
|
-
"@destyler/
|
|
31
|
-
"@destyler/
|
|
32
|
-
"@destyler/utils": "0.2.
|
|
33
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.12",
|
|
26
|
+
"@destyler/aria-hidden": "0.2.12",
|
|
27
|
+
"@destyler/dismissable": "0.2.12",
|
|
28
|
+
"@destyler/dom": "0.2.12",
|
|
29
|
+
"@destyler/focus-trap": "0.2.12",
|
|
30
|
+
"@destyler/remove-scroll": "0.2.12",
|
|
31
|
+
"@destyler/types": "0.2.12",
|
|
32
|
+
"@destyler/utils": "0.2.12",
|
|
33
|
+
"@destyler/xstate": "0.2.12"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|