@destyler/dialog 0.2.6-beta.1 → 0.2.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.
package/dist/index.d.mts CHANGED
@@ -1,11 +1,10 @@
1
- import * as _destyler_anatomy0 from "@destyler/anatomy";
2
1
  import { DismissableElementHandlers, FocusOutsideEvent, InteractOutsideEvent, PersistentElementOptions, PointerDownOutsideEvent } from "@destyler/dismissable";
3
2
  import * as _destyler_xstate0 from "@destyler/xstate";
4
3
  import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
5
4
  import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
6
5
 
7
6
  //#region src/anatomy.d.ts
8
- declare const anatomy: _destyler_anatomy0.AnatomyInstance<"trigger" | "positioner" | "backdrop" | "content" | "closeTrigger" | "title" | "description">;
7
+ declare const anatomy: any;
9
8
  //#endregion
10
9
  //#region src/types.d.ts
11
10
  interface OpenChangeDetails {
@@ -80,9 +79,10 @@ interface PublicContext extends DirectionProperty, CommonProperties, Dismissable
80
79
  */
81
80
  'open'?: boolean | undefined;
82
81
  /**
83
- * Whether the dialog is controlled by the user
82
+ * The initial open state of the dialog when it is not controlled.
83
+ * Prefer this over seeding with `open` for uncontrolled usage.
84
84
  */
85
- 'open.controlled'?: boolean | undefined;
85
+ 'defaultOpen'?: boolean | undefined;
86
86
  }
87
87
  type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
88
88
  type ComputedContext = Readonly<{}>;
@@ -128,7 +128,7 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
128
128
  declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
129
129
  //#endregion
130
130
  //#region src/props.d.ts
131
- declare const props: ("open" | "id" | "ids" | "trapFocus" | "preventScroll" | "modal" | "initialFocusEl" | "finalFocusEl" | "restoreFocus" | "onOpenChange" | "closeOnInteractOutside" | "closeOnEscape" | "aria-label" | "role" | "open.controlled" | "dir" | "getRootNode" | "onEscapeKeyDown" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside" | "persistentElements")[];
132
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "open" | "id" | "ids" | "trapFocus" | "preventScroll" | "modal" | "initialFocusEl" | "finalFocusEl" | "restoreFocus" | "onOpenChange" | "closeOnInteractOutside" | "closeOnEscape" | "aria-label" | "role" | "open.controlled" | "dir" | "getRootNode" | "onEscapeKeyDown" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside" | "persistentElements">];
131
+ 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")[];
132
+ 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
133
  //#endregion
134
134
  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": true,
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: ctx.open ? "open" : "closed",
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: { open: ["toggleVisibility"] },
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) => !!ctx$1["open.controlled"] },
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.6-beta.1",
4
+ "version": "0.2.7",
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.6-beta.1",
26
- "@destyler/aria-hidden": "0.2.6-beta.1",
27
- "@destyler/dismissable": "0.2.6-beta.1",
28
- "@destyler/dom": "0.2.6-beta.1",
29
- "@destyler/remove-scroll": "0.2.6-beta.1",
30
- "@destyler/types": "0.2.6-beta.1",
31
- "@destyler/xstate": "0.2.6-beta.1",
32
- "@destyler/focus-trap": "0.2.6-beta.1",
33
- "@destyler/utils": "0.2.6-beta.1"
25
+ "@destyler/anatomy": "0.2.7",
26
+ "@destyler/aria-hidden": "0.2.7",
27
+ "@destyler/dom": "0.2.7",
28
+ "@destyler/focus-trap": "0.2.7",
29
+ "@destyler/dismissable": "0.2.7",
30
+ "@destyler/types": "0.2.7",
31
+ "@destyler/utils": "0.2.7",
32
+ "@destyler/remove-scroll": "0.2.7",
33
+ "@destyler/xstate": "0.2.7"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"