@destyler/tooltip 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 { Placement, PositioningOptions } from "@destyler/popper";
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" | "content" | "arrow" | "positioner" | "arrowTip">;
7
+ declare const anatomy: any;
9
8
  //#endregion
10
9
  //#region src/types.d.ts
11
10
  interface OpenChangeDetails {
@@ -85,9 +84,10 @@ interface PublicContext extends DirectionProperty, CommonProperties {
85
84
  */
86
85
  'open'?: boolean | undefined;
87
86
  /**
88
- * Whether the tooltip is controlled by the user
87
+ * The initial open state of the tooltip when it is not controlled.
88
+ * Prefer this over seeding with `open` for uncontrolled usage.
89
89
  */
90
- 'open.controlled'?: boolean | undefined;
90
+ 'defaultOpen'?: boolean | undefined;
91
91
  }
92
92
  type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
93
93
  type ComputedContext = Readonly<{
@@ -143,7 +143,7 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
143
143
  declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
144
144
  //#endregion
145
145
  //#region src/props.d.ts
146
- declare const props: ("open" | "id" | "ids" | "openDelay" | "closeDelay" | "closeOnPointerDown" | "closeOnEscape" | "closeOnScroll" | "closeOnClick" | "interactive" | "onOpenChange" | "aria-label" | "positioning" | "disabled" | "open.controlled" | "dir" | "getRootNode")[];
147
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "open" | "id" | "ids" | "openDelay" | "closeDelay" | "closeOnPointerDown" | "closeOnEscape" | "closeOnScroll" | "closeOnClick" | "interactive" | "onOpenChange" | "aria-label" | "positioning" | "disabled" | "open.controlled" | "dir" | "getRootNode">];
146
+ declare const props: ("open" | "ids" | "id" | "openDelay" | "closeDelay" | "closeOnPointerDown" | "closeOnEscape" | "closeOnScroll" | "closeOnClick" | "interactive" | "onOpenChange" | "aria-label" | "positioning" | "disabled" | "defaultOpen" | "dir" | "getRootNode")[];
147
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "open" | "ids" | "id" | "openDelay" | "closeDelay" | "closeOnPointerDown" | "closeOnEscape" | "closeOnScroll" | "closeOnClick" | "interactive" | "onOpenChange" | "aria-label" | "positioning" | "disabled" | "defaultOpen" | "dir" | "getRootNode">];
148
148
  //#endregion
149
149
  export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type OpenChangeDetails, type Placement, type PositioningOptions, type Service, anatomy, connect, machine, props, splitProps };
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { addDomEvent, createScope, dataAttr, getOverflowAncestors, isComposingEv
3
3
  import { isFocusVisible, trackFocusVisible } from "@destyler/focus-visible";
4
4
  import { getPlacement, getPlacementStyles } from "@destyler/popper";
5
5
  import { createMachine, guards, proxy, subscribe } from "@destyler/xstate";
6
- import { compact, createSplitProps } from "@destyler/utils";
6
+ import { compact, createSplitProps, isControlled, resolveControllableOpen, withControllableProvided } from "@destyler/utils";
7
7
  import { createProps } from "@destyler/types";
8
8
 
9
9
  //#region src/anatomy.ts
@@ -167,10 +167,11 @@ function connect(state, send, normalize) {
167
167
  //#region src/machine.ts
168
168
  const { and, not } = guards;
169
169
  function machine(userContext) {
170
- const ctx = compact(userContext);
170
+ const ctx = compact(withControllableProvided(userContext, ["open"]));
171
+ const { initialOpen } = resolveControllableOpen(ctx);
171
172
  return createMachine({
172
173
  id: "tooltip",
173
- initial: ctx.open ? "open" : "closed",
174
+ initial: initialOpen ? "open" : "closed",
174
175
  activities: ["trackFocusVisible"],
175
176
  context: {
176
177
  openDelay: 1e3,
@@ -454,7 +455,7 @@ function machine(userContext) {
454
455
  isVisible: (ctx$1) => ctx$1.id === store.id,
455
456
  isInteractive: (ctx$1) => ctx$1.interactive,
456
457
  hasPointerMoveOpened: (ctx$1) => !!ctx$1.hasPointerMoveOpened,
457
- isOpenControlled: (ctx$1) => !!ctx$1["open.controlled"]
458
+ isOpenControlled: (ctx$1) => isControlled(ctx$1, "open")
458
459
  },
459
460
  delays: {
460
461
  OPEN_DELAY: (ctx$1) => ctx$1.openDelay,
@@ -479,8 +480,8 @@ const props = createProps()([
479
480
  "ids",
480
481
  "interactive",
481
482
  "onOpenChange",
482
- "open.controlled",
483
483
  "open",
484
+ "defaultOpen",
484
485
  "openDelay",
485
486
  "positioning"
486
487
  ]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@destyler/tooltip",
3
3
  "type": "module",
4
- "version": "0.2.6-beta.1",
4
+ "version": "0.2.7",
5
5
  "description": "A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.",
6
6
  "author": "Elone Hoo <elonehoo@gmail.com>",
7
7
  "license": "MIT",
@@ -22,13 +22,13 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@destyler/dom": "0.2.6-beta.1",
26
- "@destyler/anatomy": "0.2.6-beta.1",
27
- "@destyler/focus-visible": "0.2.6-beta.1",
28
- "@destyler/popper": "0.2.6-beta.1",
29
- "@destyler/utils": "0.2.6-beta.1",
30
- "@destyler/xstate": "0.2.6-beta.1",
31
- "@destyler/types": "0.2.6-beta.1"
25
+ "@destyler/anatomy": "0.2.7",
26
+ "@destyler/popper": "0.2.7",
27
+ "@destyler/focus-visible": "0.2.7",
28
+ "@destyler/dom": "0.2.7",
29
+ "@destyler/utils": "0.2.7",
30
+ "@destyler/types": "0.2.7",
31
+ "@destyler/xstate": "0.2.7"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"