@stratakit/structures 0.4.4 → 0.5.0

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/Dialog.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { c as _c } from "react-compiler-runtime";
1
2
  import { jsx, jsxs } from "react/jsx-runtime";
2
3
  import * as React from "react";
3
4
  import * as AkDialog from "@ariakit/react/dialog";
@@ -6,14 +7,15 @@ import { Role } from "@ariakit/react/role";
6
7
  import { useStoreState } from "@ariakit/react/store";
7
8
  import { IconButton, Text } from "@stratakit/bricks";
8
9
  import { GhostAligner } from "@stratakit/bricks/secret-internals";
9
- import {
10
- forwardRef,
11
- usePopoverApi
12
- } from "@stratakit/foundations/secret-internals";
10
+ import { forwardRef, usePopoverApi } from "@stratakit/foundations/secret-internals";
13
11
  import cx from "classnames";
14
12
  import { Dismiss } from "./~utils.icons.js";
15
13
  const DialogRoot = forwardRef((props, forwardedRef) => {
16
- const { backdrop = true, unmountOnHide = true, ...rest } = props;
14
+ const {
15
+ backdrop = true,
16
+ unmountOnHide = true,
17
+ ...rest
18
+ } = props;
17
19
  const store = AkDialog.useDialogStore();
18
20
  const contentElement = useStoreState(store, "contentElement");
19
21
  const mounted = useStoreState(store, (state) => {
@@ -21,143 +23,149 @@ const DialogRoot = forwardRef((props, forwardedRef) => {
21
23
  return props.open ?? state?.mounted;
22
24
  });
23
25
  if (!mounted) return null;
24
- return /* @__PURE__ */ jsx(AkDialog.DialogProvider, { store, children: /* @__PURE__ */ jsx(DialogWrapper, { open: props.open, children: /* @__PURE__ */ jsxs(
25
- AkDialog.Dialog,
26
- {
27
- unmountOnHide,
28
- portal: false,
29
- ...rest,
30
- backdrop: backdrop === true ? /* @__PURE__ */ jsx(DialogBackdrop, {}) : backdrop,
31
- className: cx("\u{1F95D}Dialog", props.className),
32
- ref: forwardedRef,
33
- children: [
34
- /* @__PURE__ */ jsx(AkDialog.DialogDismiss, { hidden: true }),
35
- /* @__PURE__ */ jsx(PortalContext.Provider, { value: contentElement, children: props.children })
36
- ]
37
- }
38
- ) }) });
26
+ return /* @__PURE__ */ jsx(AkDialog.DialogProvider, {
27
+ store,
28
+ children: /* @__PURE__ */ jsx(DialogWrapper, {
29
+ open: props.open,
30
+ children: /* @__PURE__ */ jsxs(AkDialog.Dialog, {
31
+ unmountOnHide,
32
+ portal: false,
33
+ ...rest,
34
+ backdrop: backdrop === true ? /* @__PURE__ */ jsx(DialogBackdrop, {}) : backdrop,
35
+ className: cx("\u{1F95D}Dialog", props.className),
36
+ ref: forwardedRef,
37
+ children: [/* @__PURE__ */ jsx(AkDialog.DialogDismiss, {
38
+ hidden: true
39
+ }), /* @__PURE__ */ jsx(PortalContext.Provider, {
40
+ value: contentElement,
41
+ children: props.children
42
+ })]
43
+ })
44
+ })
45
+ });
39
46
  });
40
47
  function DialogWrapper(props) {
48
+ const $ = _c(9);
41
49
  const [wrapper, setWrapper] = React.useState(null);
42
50
  const store = AkDialog.useDialogContext();
43
- const open = useStoreState(store, (state) => {
44
- return props.open ?? state?.open;
45
- });
46
- const popoverProps = usePopoverApi({
47
- element: wrapper,
48
- open
49
- });
51
+ let t0;
52
+ if ($[0] !== props.open) {
53
+ t0 = (state) => props.open ?? state?.open;
54
+ $[0] = props.open;
55
+ $[1] = t0;
56
+ } else {
57
+ t0 = $[1];
58
+ }
59
+ const open = useStoreState(store, t0);
60
+ let t1;
61
+ if ($[2] !== open || $[3] !== wrapper) {
62
+ t1 = {
63
+ element: wrapper,
64
+ open
65
+ };
66
+ $[2] = open;
67
+ $[3] = wrapper;
68
+ $[4] = t1;
69
+ } else {
70
+ t1 = $[4];
71
+ }
72
+ const popoverProps = usePopoverApi(t1);
50
73
  const mounted = useStoreState(store, "mounted");
51
- return /* @__PURE__ */ jsx(
52
- Portal,
53
- {
74
+ const t2 = mounted ? void 0 : true;
75
+ let t3;
76
+ if ($[5] !== popoverProps || $[6] !== props.children || $[7] !== t2) {
77
+ t3 = jsx(Portal, {
54
78
  className: "\u{1F95D}DialogWrapper",
55
79
  ref: setWrapper,
56
80
  ...popoverProps,
57
- hidden: mounted ? void 0 : true,
81
+ hidden: t2,
58
82
  children: props.children
59
- }
60
- );
61
- }
62
- const DialogHeader = forwardRef(
63
- (props, forwardedRef) => {
64
- return /* @__PURE__ */ jsx(
65
- Role,
66
- {
67
- ...props,
68
- className: cx("\u{1F95D}DialogHeader", props.className),
69
- ref: forwardedRef
70
- }
71
- );
72
- }
73
- );
74
- const DialogHeading = forwardRef(
75
- (props, forwardedRef) => {
76
- return /* @__PURE__ */ jsx(
77
- AkDialog.DialogHeading,
78
- {
79
- ...props,
80
- className: cx("\u{1F95D}DialogHeading", props.className),
81
- render: /* @__PURE__ */ jsx(Text, { variant: "body-lg", render: props.render ?? /* @__PURE__ */ jsx("h1", {}) }),
82
- ref: forwardedRef
83
- }
84
- );
85
- }
86
- );
87
- const DialogCloseButton = forwardRef(
88
- (props, forwardedRef) => {
89
- const { label = "Dismiss", ...rest } = props;
90
- return /* @__PURE__ */ jsx(GhostAligner, { align: "inline-end", children: /* @__PURE__ */ jsx(
91
- AkDialog.DialogDismiss,
92
- {
93
- ...rest,
94
- render: /* @__PURE__ */ jsx(
95
- IconButton,
96
- {
97
- render: props.render,
98
- variant: "ghost",
99
- label,
100
- icon: /* @__PURE__ */ jsx(Dismiss, {})
101
- }
102
- ),
103
- ref: forwardedRef
104
- }
105
- ) });
106
- }
107
- );
108
- const DialogContent = forwardRef(
109
- (props, forwardedRef) => {
110
- return /* @__PURE__ */ jsx(
111
- Role,
112
- {
113
- ...props,
114
- className: cx("\u{1F95D}DialogContent", props.className),
115
- ref: forwardedRef
116
- }
117
- );
118
- }
119
- );
120
- const DialogFooter = forwardRef(
121
- (props, forwardedRef) => {
122
- return /* @__PURE__ */ jsx(
123
- Role,
124
- {
125
- ...props,
126
- className: cx("\u{1F95D}DialogFooter", props.className),
127
- ref: forwardedRef
128
- }
129
- );
130
- }
131
- );
132
- const DialogActionList = forwardRef(
133
- (props, forwardedRef) => {
134
- const { actions, ...rest } = props;
135
- return /* @__PURE__ */ jsx(
136
- Role,
137
- {
138
- role: "list",
139
- ...rest,
140
- className: cx("\u{1F95D}DialogActionList", props.className),
141
- ref: forwardedRef,
142
- children: React.Children.map(actions, (action) => {
143
- return /* @__PURE__ */ jsx("div", { role: "listitem", children: action });
144
- })
145
- }
146
- );
83
+ });
84
+ $[5] = popoverProps;
85
+ $[6] = props.children;
86
+ $[7] = t2;
87
+ $[8] = t3;
88
+ } else {
89
+ t3 = $[8];
147
90
  }
148
- );
149
- const DialogBackdrop = forwardRef(
150
- (props, forwardedRef) => {
151
- return /* @__PURE__ */ jsx(
152
- Role,
153
- {
154
- ...props,
155
- className: cx("\u{1F95D}DialogBackdrop", props.className),
156
- ref: forwardedRef
157
- }
158
- );
159
- }
160
- );
91
+ return t3;
92
+ }
93
+ const DialogHeader = forwardRef((props, forwardedRef) => {
94
+ return /* @__PURE__ */ jsx(Role, {
95
+ ...props,
96
+ className: cx("\u{1F95D}DialogHeader", props.className),
97
+ ref: forwardedRef
98
+ });
99
+ });
100
+ const DialogHeading = forwardRef((props, forwardedRef) => {
101
+ return /* @__PURE__ */ jsx(AkDialog.DialogHeading, {
102
+ ...props,
103
+ className: cx("\u{1F95D}DialogHeading", props.className),
104
+ render: /* @__PURE__ */ jsx(Text, {
105
+ variant: "body-lg",
106
+ render: props.render ?? /* @__PURE__ */ jsx("h1", {})
107
+ }),
108
+ ref: forwardedRef
109
+ });
110
+ });
111
+ const DialogCloseButton = forwardRef((props, forwardedRef) => {
112
+ const {
113
+ label = "Dismiss",
114
+ ...rest
115
+ } = props;
116
+ return /* @__PURE__ */ jsx(GhostAligner, {
117
+ align: "inline-end",
118
+ children: /* @__PURE__ */ jsx(AkDialog.DialogDismiss, {
119
+ ...rest,
120
+ render: /* @__PURE__ */ jsx(IconButton, {
121
+ render: props.render,
122
+ variant: "ghost",
123
+ label,
124
+ icon: /* @__PURE__ */ jsx(Dismiss, {})
125
+ }),
126
+ ref: forwardedRef
127
+ })
128
+ });
129
+ });
130
+ const DialogContent = forwardRef((props, forwardedRef) => {
131
+ return /* @__PURE__ */ jsx(Role, {
132
+ ...props,
133
+ className: cx("\u{1F95D}DialogContent", props.className),
134
+ ref: forwardedRef
135
+ });
136
+ });
137
+ const DialogFooter = forwardRef((props, forwardedRef) => {
138
+ return /* @__PURE__ */ jsx(Role, {
139
+ ...props,
140
+ className: cx("\u{1F95D}DialogFooter", props.className),
141
+ ref: forwardedRef
142
+ });
143
+ });
144
+ const DialogActionList = forwardRef((props, forwardedRef) => {
145
+ const {
146
+ actions,
147
+ ...rest
148
+ } = props;
149
+ return /* @__PURE__ */ jsx(Role, {
150
+ role: "list",
151
+ ...rest,
152
+ className: cx("\u{1F95D}DialogActionList", props.className),
153
+ ref: forwardedRef,
154
+ children: React.Children.map(actions, (action) => {
155
+ return /* @__PURE__ */ jsx("div", {
156
+ role: "listitem",
157
+ children: action
158
+ });
159
+ })
160
+ });
161
+ });
162
+ const DialogBackdrop = forwardRef((props, forwardedRef) => {
163
+ return /* @__PURE__ */ jsx(Role, {
164
+ ...props,
165
+ className: cx("\u{1F95D}DialogBackdrop", props.className),
166
+ ref: forwardedRef
167
+ });
168
+ });
161
169
  export {
162
170
  DialogActionList as ActionList,
163
171
  DialogBackdrop as Backdrop,