@destyler/popover 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 CHANGED
@@ -6,7 +6,7 @@ import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
6
6
  import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
7
7
 
8
8
  //#region src/anatomy.d.ts
9
- declare const anatomy: _destyler_anatomy0.AnatomyInstance<"anchor" | "trigger" | "content" | "title" | "description" | "closeTrigger" | "positioner" | "arrow" | "arrowTip" | "indicator">;
9
+ declare const anatomy: _destyler_anatomy0.AnatomyInstance<"arrow" | "arrowTip" | "anchor" | "trigger" | "indicator" | "positioner" | "content" | "title" | "description" | "closeTrigger">;
10
10
  //#endregion
11
11
  //#region src/types.d.ts
12
12
  interface OpenChangeDetails {
@@ -26,7 +26,7 @@ interface PublicContext extends CommonProperties, DirectionProperty, Dismissable
26
26
  /**
27
27
  * The ids of the elements in the popover. Useful for composition.
28
28
  */
29
- 'ids'?: ElementIds | undefined;
29
+ ids?: ElementIds | undefined;
30
30
  /**
31
31
  * Whether the popover should be modal. When set to `true`:
32
32
  * - interaction with outside elements will be disabled
@@ -36,51 +36,52 @@ interface PublicContext extends CommonProperties, DirectionProperty, Dismissable
36
36
  *
37
37
  * @default false
38
38
  */
39
- 'modal'?: boolean | undefined;
39
+ modal?: boolean | undefined;
40
40
  /**
41
41
  * Whether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position
42
42
  * of the popover content.
43
43
  *
44
44
  * @default true
45
45
  */
46
- 'portalled'?: boolean | undefined;
46
+ portalled?: boolean | undefined;
47
47
  /**
48
48
  * Whether to automatically set focus on the first focusable
49
49
  * content within the popover when opened.
50
50
  *
51
51
  * @default true
52
52
  */
53
- 'autoFocus'?: boolean | undefined;
53
+ autoFocus?: boolean | undefined;
54
54
  /**
55
55
  * The element to focus on when the popover is opened.
56
56
  */
57
- 'initialFocusEl'?: (() => HTMLElement | null) | undefined;
57
+ initialFocusEl?: (() => HTMLElement | null) | undefined;
58
58
  /**
59
59
  * Whether to close the popover when the user clicks outside of the popover.
60
60
  * @default true
61
61
  */
62
- 'closeOnInteractOutside'?: boolean | undefined;
62
+ closeOnInteractOutside?: boolean | undefined;
63
63
  /**
64
64
  * Whether to close the popover when the escape key is pressed.
65
65
  * @default true
66
66
  */
67
- 'closeOnEscape'?: boolean | undefined;
67
+ closeOnEscape?: boolean | undefined;
68
68
  /**
69
69
  * Function invoked when the popover opens or closes
70
70
  */
71
- 'onOpenChange'?: ((details: OpenChangeDetails) => void) | undefined;
71
+ onOpenChange?: ((details: OpenChangeDetails) => void) | undefined;
72
72
  /**
73
73
  * The user provided options used to position the popover content
74
74
  */
75
- 'positioning': PositioningOptions;
75
+ positioning: PositioningOptions;
76
76
  /**
77
77
  * Whether the popover is open
78
78
  */
79
- 'open'?: boolean | undefined;
79
+ open?: boolean | undefined;
80
80
  /**
81
- * Whether the popover is controlled by the user
81
+ * The initial open state of the popover when it is not controlled.
82
+ * Prefer this over seeding with `open` for uncontrolled usage.
82
83
  */
83
- 'open.controlled'?: boolean | undefined;
84
+ defaultOpen?: boolean | undefined;
84
85
  }
85
86
  type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
86
87
  type ComputedContext = Readonly<{
@@ -148,7 +149,7 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
148
149
  declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
149
150
  //#endregion
150
151
  //#region src/props.d.ts
151
- declare const props: ("open" | "id" | "ids" | "modal" | "portalled" | "autoFocus" | "initialFocusEl" | "closeOnInteractOutside" | "closeOnEscape" | "onOpenChange" | "positioning" | "open.controlled" | "getRootNode" | "dir" | "onEscapeKeyDown" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside" | "persistentElements")[];
152
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "open" | "id" | "ids" | "modal" | "portalled" | "autoFocus" | "initialFocusEl" | "closeOnInteractOutside" | "closeOnEscape" | "onOpenChange" | "positioning" | "open.controlled" | "getRootNode" | "dir" | "onEscapeKeyDown" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside" | "persistentElements">];
152
+ declare const props: ("open" | "ids" | "modal" | "portalled" | "autoFocus" | "initialFocusEl" | "closeOnInteractOutside" | "closeOnEscape" | "onOpenChange" | "positioning" | "defaultOpen" | "id" | "getRootNode" | "dir" | "onEscapeKeyDown" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside" | "persistentElements")[];
153
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "open" | "ids" | "modal" | "portalled" | "autoFocus" | "initialFocusEl" | "closeOnInteractOutside" | "closeOnEscape" | "onOpenChange" | "positioning" | "defaultOpen" | "id" | "getRootNode" | "dir" | "onEscapeKeyDown" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside" | "persistentElements">];
153
154
  //#endregion
154
155
  export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type FocusOutsideEvent, type InteractOutsideEvent, type OpenChangeDetails, type Placement, type PointerDownOutsideEvent, type PositioningOptions, type Service, anatomy, connect, machine, props, splitProps };
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { ariaHidden } from "@destyler/aria-hidden";
5
5
  import { trackDismissableElement } from "@destyler/dismissable";
6
6
  import { trapFocus } from "@destyler/focus-trap";
7
7
  import { preventBodyScroll } from "@destyler/remove-scroll";
8
- import { compact, createSplitProps } from "@destyler/utils";
8
+ import { compact, createSplitProps, isControlled, resolveControllableOpen, withControllableProvided } from "@destyler/utils";
9
9
  import { createMachine } from "@destyler/xstate";
10
10
  import { createProps } from "@destyler/types";
11
11
 
@@ -169,10 +169,11 @@ function connect(state, send, normalize) {
169
169
  //#endregion
170
170
  //#region src/machine.ts
171
171
  function machine(userContext) {
172
- const ctx = compact(userContext);
172
+ const ctx = compact(withControllableProvided(userContext, ["open"]));
173
+ const { initialOpen } = resolveControllableOpen(ctx);
173
174
  return createMachine({
174
175
  id: "popover",
175
- initial: ctx.open ? "open" : "closed",
176
+ initial: initialOpen ? "open" : "closed",
176
177
  context: {
177
178
  closeOnInteractOutside: true,
178
179
  closeOnEscape: true,
@@ -247,7 +248,7 @@ function machine(userContext) {
247
248
  }
248
249
  }
249
250
  }, {
250
- guards: { isOpenControlled: (ctx$1) => !!ctx$1["open.controlled"] },
251
+ guards: { isOpenControlled: (ctx$1) => isControlled(ctx$1, "open") },
251
252
  activities: {
252
253
  trackPositioning(ctx$1) {
253
254
  ctx$1.currentPlacement = ctx$1.positioning.placement;
@@ -393,8 +394,8 @@ const props = createProps()([
393
394
  "onInteractOutside",
394
395
  "onOpenChange",
395
396
  "onPointerDownOutside",
396
- "open.controlled",
397
397
  "open",
398
+ "defaultOpen",
398
399
  "persistentElements",
399
400
  "portalled",
400
401
  "positioning"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@destyler/popover",
3
3
  "type": "module",
4
- "version": "0.2.6",
4
+ "version": "0.2.9",
5
5
  "description": "displays rich content in a portal, triggered by a button.",
6
6
  "author": "Elone Hoo <elonehoo@gmail.com>",
7
7
  "license": "MIT",
@@ -22,16 +22,16 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@destyler/dismissable": "0.2.6",
26
- "@destyler/aria-hidden": "0.2.6",
27
- "@destyler/dom": "0.2.6",
28
- "@destyler/anatomy": "0.2.6",
29
- "@destyler/remove-scroll": "0.2.6",
30
- "@destyler/types": "0.2.6",
31
- "@destyler/popper": "0.2.6",
32
- "@destyler/focus-trap": "0.2.6",
33
- "@destyler/xstate": "0.2.6",
34
- "@destyler/utils": "0.2.6"
25
+ "@destyler/aria-hidden": "0.2.9",
26
+ "@destyler/dom": "0.2.9",
27
+ "@destyler/anatomy": "0.2.9",
28
+ "@destyler/dismissable": "0.2.9",
29
+ "@destyler/types": "0.2.9",
30
+ "@destyler/remove-scroll": "0.2.9",
31
+ "@destyler/focus-trap": "0.2.9",
32
+ "@destyler/utils": "0.2.9",
33
+ "@destyler/xstate": "0.2.9",
34
+ "@destyler/popper": "0.2.9"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"