@stratakit/structures 0.4.5 → 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/Table.js CHANGED
@@ -1,137 +1,145 @@
1
+ import { c as _c } from "react-compiler-runtime";
1
2
  import { jsx } from "react/jsx-runtime";
2
3
  import * as React from "react";
3
4
  import { Role } from "@ariakit/react/role";
4
- import {
5
- forwardRef,
6
- useMergedRefs,
7
- useSafeContext
8
- } from "@stratakit/foundations/secret-internals";
5
+ import { forwardRef, useMergedRefs, useSafeContext } from "@stratakit/foundations/secret-internals";
9
6
  import cx from "classnames";
10
7
  const TableContext = React.createContext(void 0);
11
8
  const TableHeaderContext = React.createContext(false);
12
9
  const HtmlTable = forwardRef((props, forwardedRef) => {
13
- const tableContextValue = React.useMemo(
14
- () => ({ mode: "html" }),
15
- []
16
- );
17
- return /* @__PURE__ */ jsx(TableContext.Provider, { value: tableContextValue, children: /* @__PURE__ */ jsx(
18
- Role,
19
- {
10
+ const tableContextValue = React.useMemo(() => ({
11
+ mode: "html"
12
+ }), []);
13
+ return /* @__PURE__ */ jsx(TableContext.Provider, {
14
+ value: tableContextValue,
15
+ children: /* @__PURE__ */ jsx(Role, {
20
16
  render: /* @__PURE__ */ jsx("table", {}),
21
17
  ...props,
22
18
  ref: forwardedRef,
23
19
  className: cx("\u{1F95D}Table", props.className)
24
- }
25
- ) });
20
+ })
21
+ });
26
22
  });
27
- const CustomTable = forwardRef(
28
- (props, forwardedRef) => {
29
- const [captionId, setCaptionId] = React.useState();
30
- const tableContextValue = React.useMemo(
31
- () => ({ captionId, setCaptionId, mode: "aria" }),
32
- [captionId]
33
- );
34
- return /* @__PURE__ */ jsx(TableContext.Provider, { value: tableContextValue, children: /* @__PURE__ */ jsx(
35
- Role.div,
36
- {
37
- role: "table",
38
- "aria-labelledby": captionId,
39
- ...props,
40
- ref: forwardedRef,
41
- className: cx("\u{1F95D}Table", props.className)
42
- }
43
- ) });
44
- }
45
- );
46
- const TableHeader = forwardRef(
47
- (props, forwardedRef) => {
48
- const { mode } = useSafeContext(TableContext);
49
- const render = mode === "html" ? /* @__PURE__ */ jsx("thead", {}) : void 0;
50
- const role = mode === "aria" ? "rowgroup" : void 0;
51
- return /* @__PURE__ */ jsx(TableHeaderContext.Provider, { value: true, children: /* @__PURE__ */ jsx(
52
- Role.div,
53
- {
54
- render,
55
- role,
56
- ...props,
57
- ref: forwardedRef,
58
- className: cx("\u{1F95D}TableHeader", props.className)
59
- }
60
- ) });
61
- }
62
- );
63
- const TableBody = forwardRef((props, forwardedRef) => {
64
- const { mode } = useSafeContext(TableContext);
65
- const render = mode === "html" ? /* @__PURE__ */ jsx("tbody", {}) : void 0;
66
- return /* @__PURE__ */ jsx(
67
- Role.div,
68
- {
69
- render,
70
- role: void 0,
23
+ const CustomTable = forwardRef((props, forwardedRef) => {
24
+ const [captionId, setCaptionId] = React.useState();
25
+ const tableContextValue = React.useMemo(() => ({
26
+ captionId,
27
+ setCaptionId,
28
+ mode: "aria"
29
+ }), [captionId]);
30
+ return /* @__PURE__ */ jsx(TableContext.Provider, {
31
+ value: tableContextValue,
32
+ children: /* @__PURE__ */ jsx(Role.div, {
33
+ role: "table",
34
+ "aria-labelledby": captionId,
71
35
  ...props,
72
36
  ref: forwardedRef,
73
- className: cx("\u{1F95D}TableBody", props.className)
74
- }
75
- );
37
+ className: cx("\u{1F95D}Table", props.className)
38
+ })
39
+ });
76
40
  });
77
- const TableRow = forwardRef((props, forwardedRef) => {
78
- const { mode } = useSafeContext(TableContext);
79
- const render = mode === "html" ? /* @__PURE__ */ jsx("tr", {}) : void 0;
80
- const role = mode === "aria" ? "row" : void 0;
81
- return /* @__PURE__ */ jsx(
82
- Role.div,
83
- {
41
+ const TableHeader = forwardRef((props, forwardedRef) => {
42
+ const {
43
+ mode
44
+ } = useSafeContext(TableContext);
45
+ const render = mode === "html" ? /* @__PURE__ */ jsx("thead", {}) : void 0;
46
+ const role = mode === "aria" ? "rowgroup" : void 0;
47
+ return /* @__PURE__ */ jsx(TableHeaderContext.Provider, {
48
+ value: true,
49
+ children: /* @__PURE__ */ jsx(Role.div, {
84
50
  render,
85
51
  role,
86
52
  ...props,
87
53
  ref: forwardedRef,
88
- className: cx("\u{1F95D}TableRow", props.className)
89
- }
90
- );
54
+ className: cx("\u{1F95D}TableHeader", props.className)
55
+ })
56
+ });
91
57
  });
92
- const TableCaption = forwardRef(
93
- (props, forwardedRef) => {
94
- const fallbackId = React.useId();
95
- const { id = fallbackId, ...rest } = props;
96
- const { mode, setCaptionId } = useSafeContext(TableContext);
97
- const render = mode === "html" ? /* @__PURE__ */ jsx("caption", {}) : void 0;
98
- const captionIdRef = React.useCallback(
99
- (element) => {
100
- setCaptionId?.(element ? id : void 0);
101
- },
102
- [id, setCaptionId]
103
- );
104
- return /* @__PURE__ */ jsx(
105
- Role.div,
106
- {
107
- render,
108
- ...rest,
109
- id,
110
- ref: useMergedRefs(forwardedRef, captionIdRef),
111
- className: cx("\u{1F95D}TableCaption", props.className)
112
- }
113
- );
58
+ const TableBody = forwardRef((props, forwardedRef) => {
59
+ const {
60
+ mode
61
+ } = useSafeContext(TableContext);
62
+ const render = mode === "html" ? /* @__PURE__ */ jsx("tbody", {}) : void 0;
63
+ return /* @__PURE__ */ jsx(Role.div, {
64
+ render,
65
+ role: void 0,
66
+ ...props,
67
+ ref: forwardedRef,
68
+ className: cx("\u{1F95D}TableBody", props.className)
69
+ });
70
+ });
71
+ const TableRow = forwardRef((props, forwardedRef) => {
72
+ const {
73
+ mode
74
+ } = useSafeContext(TableContext);
75
+ const render = mode === "html" ? /* @__PURE__ */ jsx("tr", {}) : void 0;
76
+ const role = mode === "aria" ? "row" : void 0;
77
+ return /* @__PURE__ */ jsx(Role.div, {
78
+ render,
79
+ role,
80
+ ...props,
81
+ ref: forwardedRef,
82
+ className: cx("\u{1F95D}TableRow", props.className)
83
+ });
84
+ });
85
+ const TableCaption = forwardRef((props, forwardedRef) => {
86
+ const $ = _c(3);
87
+ const fallbackId = React.useId();
88
+ const {
89
+ id: t0,
90
+ ...rest
91
+ } = props;
92
+ const id = t0 === void 0 ? fallbackId : t0;
93
+ const {
94
+ mode,
95
+ setCaptionId
96
+ } = useSafeContext(TableContext);
97
+ const render = mode === "html" ? jsx("caption", {}) : void 0;
98
+ let t1;
99
+ if ($[0] !== id || $[1] !== setCaptionId) {
100
+ t1 = (element) => {
101
+ setCaptionId?.(element ? id : void 0);
102
+ };
103
+ $[0] = id;
104
+ $[1] = setCaptionId;
105
+ $[2] = t1;
106
+ } else {
107
+ t1 = $[2];
114
108
  }
115
- );
109
+ const captionIdRef = t1;
110
+ return jsx(Role.div, {
111
+ render,
112
+ ...rest,
113
+ id,
114
+ ref: useMergedRefs(forwardedRef, captionIdRef),
115
+ className: cx("\u{1F95D}TableCaption", props.className)
116
+ });
117
+ });
116
118
  const TableCell = forwardRef((props, forwardedRef) => {
117
119
  const isWithinTableHeader = useSafeContext(TableHeaderContext);
118
- const { mode } = useSafeContext(TableContext);
119
- const { render, role } = React.useMemo(() => {
120
+ const {
121
+ mode
122
+ } = useSafeContext(TableContext);
123
+ const {
124
+ render,
125
+ role
126
+ } = React.useMemo(() => {
120
127
  if (mode === "aria") {
121
- return { role: isWithinTableHeader ? "columnheader" : "cell" };
128
+ return {
129
+ role: isWithinTableHeader ? "columnheader" : "cell"
130
+ };
122
131
  }
123
- return { render: isWithinTableHeader ? /* @__PURE__ */ jsx("th", {}) : /* @__PURE__ */ jsx("td", {}) };
132
+ return {
133
+ render: isWithinTableHeader ? /* @__PURE__ */ jsx("th", {}) : /* @__PURE__ */ jsx("td", {})
134
+ };
124
135
  }, [isWithinTableHeader, mode]);
125
- return /* @__PURE__ */ jsx(
126
- Role.div,
127
- {
128
- render,
129
- role,
130
- ...props,
131
- ref: forwardedRef,
132
- className: cx("\u{1F95D}TableCell", props.className)
133
- }
134
- );
136
+ return /* @__PURE__ */ jsx(Role.div, {
137
+ render,
138
+ role,
139
+ ...props,
140
+ ref: forwardedRef,
141
+ className: cx("\u{1F95D}TableCell", props.className)
142
+ });
135
143
  });
136
144
  export {
137
145
  TableBody as Body,
package/dist/Tabs.js CHANGED
@@ -1,94 +1,129 @@
1
+ import { c as _c } from "react-compiler-runtime";
1
2
  import { jsx } from "react/jsx-runtime";
2
3
  import { useStoreState } from "@ariakit/react/store";
3
4
  import * as AkTab from "@ariakit/react/tab";
4
- import {
5
- forwardRef,
6
- isBrowser,
7
- useUnreactiveCallback
8
- } from "@stratakit/foundations/secret-internals";
5
+ import { forwardRef, isBrowser, useUnreactiveCallback } from "@stratakit/foundations/secret-internals";
9
6
  import cx from "classnames";
10
7
  const supportsAnchorPositioning = isBrowser && CSS?.supports("anchor-name: --foo");
11
8
  const prefersReducedMotion = () => isBrowser && window.matchMedia("(prefers-reduced-motion)").matches;
12
9
  function TabsProvider(props) {
10
+ const $ = _c(14);
13
11
  const {
14
12
  defaultSelectedId,
15
13
  selectedId,
16
14
  setSelectedId,
17
- selectOnMove = false,
15
+ selectOnMove: t0,
18
16
  children
19
17
  } = props;
20
- const store = AkTab.useTabStore({ defaultSelectedId });
18
+ const selectOnMove = t0 === void 0 ? false : t0;
19
+ let t1;
20
+ if ($[0] !== defaultSelectedId) {
21
+ t1 = {
22
+ defaultSelectedId
23
+ };
24
+ $[0] = defaultSelectedId;
25
+ $[1] = t1;
26
+ } else {
27
+ t1 = $[1];
28
+ }
29
+ const store = AkTab.useTabStore(t1);
21
30
  const tablist = useStoreState(store, "baseElement");
22
31
  const selectedIdFromStore = useStoreState(store, "selectedId");
23
- const flipAnimateStripe = (newSelectedId) => {
24
- if (!supportsAnchorPositioning) return;
25
- const rootNode = tablist?.getRootNode();
26
- if (!rootNode || !selectedIdFromStore || !newSelectedId) return;
27
- const previousTabRect = rootNode.getElementById?.(selectedIdFromStore)?.getBoundingClientRect();
28
- const nextTabRect = rootNode.getElementById?.(newSelectedId)?.getBoundingClientRect();
29
- if (!previousTabRect || !nextTabRect) return;
30
- const deltaX = previousTabRect.left - nextTabRect.left;
31
- const deltaWidth = previousTabRect.width / nextTabRect.width;
32
- tablist?.animate(
33
- [
34
- { transform: `translateX(${deltaX}px) scaleX(${deltaWidth})` },
35
- { transform: "none" }
36
- ],
37
- {
32
+ let t2;
33
+ if ($[2] !== selectedIdFromStore || $[3] !== tablist) {
34
+ t2 = (newSelectedId) => {
35
+ if (!supportsAnchorPositioning) {
36
+ return;
37
+ }
38
+ const rootNode = tablist?.getRootNode();
39
+ if (!rootNode || !selectedIdFromStore || !newSelectedId) {
40
+ return;
41
+ }
42
+ const previousTabRect = rootNode.getElementById?.(selectedIdFromStore)?.getBoundingClientRect();
43
+ const nextTabRect = rootNode.getElementById?.(newSelectedId)?.getBoundingClientRect();
44
+ if (!previousTabRect || !nextTabRect) {
45
+ return;
46
+ }
47
+ const deltaX = previousTabRect.left - nextTabRect.left;
48
+ const deltaWidth = previousTabRect.width / nextTabRect.width;
49
+ tablist?.animate([{
50
+ transform: `translateX(${deltaX}px) scaleX(${deltaWidth})`
51
+ }, {
52
+ transform: "none"
53
+ }], {
38
54
  pseudoElement: "::after",
39
55
  duration: 150,
40
56
  easing: "ease-in-out"
57
+ });
58
+ };
59
+ $[2] = selectedIdFromStore;
60
+ $[3] = tablist;
61
+ $[4] = t2;
62
+ } else {
63
+ t2 = $[4];
64
+ }
65
+ const flipAnimateStripe = t2;
66
+ let t3;
67
+ if ($[5] !== flipAnimateStripe || $[6] !== setSelectedId) {
68
+ t3 = (newSelectedId_0) => {
69
+ if (!prefersReducedMotion()) {
70
+ flipAnimateStripe(newSelectedId_0);
41
71
  }
42
- );
43
- };
44
- return /* @__PURE__ */ jsx(
45
- AkTab.TabProvider,
46
- {
72
+ setSelectedId?.(newSelectedId_0);
73
+ };
74
+ $[5] = flipAnimateStripe;
75
+ $[6] = setSelectedId;
76
+ $[7] = t3;
77
+ } else {
78
+ t3 = $[7];
79
+ }
80
+ const t4 = useUnreactiveCallback(t3);
81
+ let t5;
82
+ if ($[8] !== children || $[9] !== selectOnMove || $[10] !== selectedId || $[11] !== store || $[12] !== t4) {
83
+ t5 = jsx(AkTab.TabProvider, {
47
84
  store,
48
85
  selectedId,
49
- setSelectedId: useUnreactiveCallback(
50
- (newSelectedId) => {
51
- if (!prefersReducedMotion()) flipAnimateStripe(newSelectedId);
52
- setSelectedId?.(newSelectedId);
53
- }
54
- ),
86
+ setSelectedId: t4,
55
87
  selectOnMove,
56
88
  children
57
- }
58
- );
89
+ });
90
+ $[8] = children;
91
+ $[9] = selectOnMove;
92
+ $[10] = selectedId;
93
+ $[11] = store;
94
+ $[12] = t4;
95
+ $[13] = t5;
96
+ } else {
97
+ t5 = $[13];
98
+ }
99
+ return t5;
59
100
  }
60
101
  const TabList = forwardRef((props, forwardedRef) => {
61
- const { tone = "neutral", ...rest } = props;
62
- return /* @__PURE__ */ jsx(
63
- AkTab.TabList,
64
- {
65
- ...rest,
66
- "data-_sk-tone": tone,
67
- className: cx("\u{1F95D}TabList", props.className),
68
- ref: forwardedRef
69
- }
70
- );
102
+ const {
103
+ tone = "neutral",
104
+ ...rest
105
+ } = props;
106
+ return /* @__PURE__ */ jsx(AkTab.TabList, {
107
+ ...rest,
108
+ "data-_sk-tone": tone,
109
+ className: cx("\u{1F95D}TabList", props.className),
110
+ ref: forwardedRef
111
+ });
71
112
  });
72
113
  const Tab = forwardRef((props, forwardedRef) => {
73
- return /* @__PURE__ */ jsx(
74
- AkTab.Tab,
75
- {
76
- accessibleWhenDisabled: true,
77
- ...props,
78
- className: cx("\u{1F95D}Tab", props.className),
79
- ref: forwardedRef
80
- }
81
- );
114
+ return /* @__PURE__ */ jsx(AkTab.Tab, {
115
+ accessibleWhenDisabled: true,
116
+ ...props,
117
+ className: cx("\u{1F95D}Tab", props.className),
118
+ ref: forwardedRef
119
+ });
82
120
  });
83
121
  const TabPanel = forwardRef((props, forwardedRef) => {
84
- return /* @__PURE__ */ jsx(
85
- AkTab.TabPanel,
86
- {
87
- ...props,
88
- className: cx("\u{1F95D}TabPanel", props.className),
89
- ref: forwardedRef
90
- }
91
- );
122
+ return /* @__PURE__ */ jsx(AkTab.TabPanel, {
123
+ ...props,
124
+ className: cx("\u{1F95D}TabPanel", props.className),
125
+ ref: forwardedRef
126
+ });
92
127
  });
93
128
  export {
94
129
  TabsProvider as Provider,
package/dist/Toolbar.js CHANGED
@@ -1,53 +1,33 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import * as Toolbar from "@ariakit/react/toolbar";
4
- import {
5
- IconButtonContext,
6
- TooltipContext
7
- } from "@stratakit/bricks/secret-internals";
4
+ import { IconButtonContext, TooltipContext } from "@stratakit/bricks/secret-internals";
8
5
  import { forwardRef } from "@stratakit/foundations/secret-internals";
9
6
  import cx from "classnames";
10
- const ToolbarGroup = forwardRef(
11
- (props, forwardedRef) => {
12
- return /* @__PURE__ */ jsx(
13
- IconButtonContext.Provider,
14
- {
15
- value: React.useMemo(() => ({ iconSize: "large" }), []),
16
- children: /* @__PURE__ */ jsx(
17
- TooltipContext.Provider,
18
- {
19
- value: React.useMemo(
20
- () => ({
21
- placement: props.orientation === "vertical" ? "right" : "top"
22
- }),
23
- [props.orientation]
24
- ),
25
- children: /* @__PURE__ */ jsx(
26
- Toolbar.Toolbar,
27
- {
28
- ...props,
29
- className: cx("\u{1F95D}Toolbar", props.className),
30
- ref: forwardedRef
31
- }
32
- )
33
- }
34
- )
35
- }
36
- );
37
- }
38
- );
39
- const ToolbarItem = forwardRef(
40
- (props, forwardedRef) => {
41
- return /* @__PURE__ */ jsx(
42
- Toolbar.ToolbarItem,
43
- {
7
+ const ToolbarGroup = forwardRef((props, forwardedRef) => {
8
+ return /* @__PURE__ */ jsx(IconButtonContext.Provider, {
9
+ value: React.useMemo(() => ({
10
+ iconSize: "large"
11
+ }), []),
12
+ children: /* @__PURE__ */ jsx(TooltipContext.Provider, {
13
+ value: React.useMemo(() => ({
14
+ placement: props.orientation === "vertical" ? "right" : "top"
15
+ }), [props.orientation]),
16
+ children: /* @__PURE__ */ jsx(Toolbar.Toolbar, {
44
17
  ...props,
45
- className: cx("\u{1F95D}ToolbarItem", props.className),
18
+ className: cx("\u{1F95D}Toolbar", props.className),
46
19
  ref: forwardedRef
47
- }
48
- );
49
- }
50
- );
20
+ })
21
+ })
22
+ });
23
+ });
24
+ const ToolbarItem = forwardRef((props, forwardedRef) => {
25
+ return /* @__PURE__ */ jsx(Toolbar.ToolbarItem, {
26
+ ...props,
27
+ className: cx("\u{1F95D}ToolbarItem", props.className),
28
+ ref: forwardedRef
29
+ });
30
+ });
51
31
  export {
52
32
  ToolbarGroup as Group,
53
33
  ToolbarItem as Item
package/dist/Tree.js CHANGED
@@ -5,18 +5,19 @@ import { forwardRef } from "@stratakit/foundations/secret-internals";
5
5
  import cx from "classnames";
6
6
  import { Action as TreeItemAction, Root as TreeItemRoot } from "./TreeItem.js";
7
7
  const Tree = forwardRef((props, forwardedRef) => {
8
- const composite = useCompositeStore({ orientation: "vertical" });
9
- return /* @__PURE__ */ jsx(
10
- Role.div,
11
- {
12
- role: "tree",
13
- ...props,
14
- render: /* @__PURE__ */ jsx(Composite, { store: composite }),
15
- className: cx("\u{1F95D}Tree", props.className),
16
- ref: forwardedRef,
17
- children: props.children
18
- }
19
- );
8
+ const composite = useCompositeStore({
9
+ orientation: "vertical"
10
+ });
11
+ return /* @__PURE__ */ jsx(Role.div, {
12
+ role: "tree",
13
+ ...props,
14
+ render: /* @__PURE__ */ jsx(Composite, {
15
+ store: composite
16
+ }),
17
+ className: cx("\u{1F95D}Tree", props.className),
18
+ ref: forwardedRef,
19
+ children: props.children
20
+ });
20
21
  });
21
22
  export {
22
23
  TreeItemRoot as Item,