@blockle/blocks 0.13.0 → 0.14.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.
@@ -3,15 +3,6 @@ const jsxRuntime = require("react/jsx-runtime");
3
3
  const react = require("react");
4
4
  const styles_components_display_Divider_Divider_cjs = require("../../display/Divider/Divider.cjs");
5
5
  const styles_components_overlay_Dialog_dialog_css_cjs = require("./dialog.css.cjs");
6
- const reactDom = require("react-dom");
7
- const styles_components_other_BlocksProvider_BlocksProvider_cjs = require("../../other/BlocksProvider/BlocksProvider.cjs");
8
- const Portal = ({ children, container }) => {
9
- const context = styles_components_display_Divider_Divider_cjs.useTheme();
10
- return reactDom.createPortal(
11
- /* @__PURE__ */ jsxRuntime.jsx(styles_components_other_BlocksProvider_BlocksProvider_cjs.BlocksProvider, { theme: context, children }),
12
- container || document.body
13
- );
14
- };
15
6
  const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
16
7
  react.useEffect(() => {
17
8
  if (!enabled) {
@@ -22,8 +13,11 @@ const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
22
13
  onClickOutside();
23
14
  }
24
15
  };
25
- document.addEventListener("click", listener);
16
+ const rafId = requestAnimationFrame(() => {
17
+ document.addEventListener("click", listener);
18
+ });
26
19
  return () => {
20
+ cancelAnimationFrame(rafId);
27
21
  document.removeEventListener("click", listener);
28
22
  };
29
23
  }, [ref, onClickOutside, enabled]);
@@ -45,27 +39,6 @@ const useKeyboard = (key, callback, { enabled = true, type = "keydown" } = {}) =
45
39
  };
46
40
  }, [callback, enabled, key, type]);
47
41
  };
48
- const useLayer = () => {
49
- const layerRef = react.useRef();
50
- react.useEffect(
51
- () => () => {
52
- if (layerRef.current) {
53
- layerRef.current.remove();
54
- layerRef.current = void 0;
55
- }
56
- },
57
- []
58
- );
59
- return () => {
60
- if (!layerRef.current) {
61
- const div = document.createElement("div");
62
- div.dataset.layer = "blocks";
63
- layerRef.current = div;
64
- document.body.append(layerRef.current);
65
- }
66
- return layerRef.current;
67
- };
68
- };
69
42
  const usePreventBodyScroll = (enabled = true) => {
70
43
  useIsomorphicLayoutEffect(() => {
71
44
  if (!enabled) {
@@ -106,24 +79,15 @@ const useRestoreFocus = (active) => {
106
79
  }
107
80
  }, [active]);
108
81
  };
109
- const useVisibilityState = (open) => {
110
- const [visible, setVisible] = react.useState(open);
111
- const hide = react.useCallback(() => {
112
- setVisible(false);
113
- }, []);
114
- react.useEffect(() => {
115
- if (open) {
116
- setVisible(true);
117
- }
118
- }, [open]);
119
- return [visible, hide];
120
- };
121
82
  function hasAnimationDuration(element) {
122
83
  if (!element) {
123
84
  return false;
124
85
  }
125
86
  const style = window.getComputedStyle(element);
126
- return style.transitionDuration !== "0s" || style.animationDuration !== "0s";
87
+ return hasDuration(style.transitionDuration) || hasDuration(style.animationDuration);
88
+ }
89
+ function hasDuration(duration) {
90
+ return duration.split(",").map((part) => Number.parseFloat(part.trim())).some((part) => part > 0);
127
91
  }
128
92
  const DialogContext = react.createContext(void 0);
129
93
  const useNestedDialog = (open) => {
@@ -149,12 +113,11 @@ const Dialog = ({
149
113
  }) => {
150
114
  const dialogClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("dialog", { dialog: true, variants: { size } });
151
115
  const dialogRef = react.useRef(null);
152
- const layer = useLayer();
153
- const [visible, hide] = useVisibilityState(open);
154
116
  const [enabled, setEnabled] = react.useState(true);
117
+ const [visible, setVisible] = react.useState(open);
155
118
  useRestoreFocus(open);
156
- const isNested = useNestedDialog(visible);
157
- usePreventBodyScroll(visible && !isNested);
119
+ const isNested = useNestedDialog(open);
120
+ usePreventBodyScroll(open && !isNested);
158
121
  const onEscape = react.useCallback(
159
122
  (event) => {
160
123
  event.preventDefault();
@@ -166,47 +129,32 @@ const Dialog = ({
166
129
  useClickOutside(dialogRef, onRequestClose, { enabled: open && enabled });
167
130
  useIsomorphicLayoutEffect(() => {
168
131
  var _a, _b;
169
- if (!visible) {
170
- (_a = dialogRef.current) == null ? void 0 : _a.close();
171
- }
172
- if (!open) {
173
- (_b = dialogRef.current) == null ? void 0 : _b.removeAttribute("data-open");
174
- return;
132
+ if (open && visible) {
133
+ (_a = dialogRef.current) == null ? void 0 : _a.showModal();
134
+ } else if (open) {
135
+ setVisible(true);
136
+ } else {
137
+ if (!hasAnimationDuration(dialogRef.current)) {
138
+ setVisible(false);
139
+ }
140
+ (_b = dialogRef.current) == null ? void 0 : _b.close();
175
141
  }
176
- let timer = requestAnimationFrame(() => {
177
- timer = requestAnimationFrame(() => {
178
- var _a2, _b2;
179
- (_a2 = dialogRef.current) == null ? void 0 : _a2.showModal();
180
- (_b2 = dialogRef.current) == null ? void 0 : _b2.setAttribute("data-open", "");
181
- });
182
- });
183
- return () => {
184
- cancelAnimationFrame(timer);
185
- };
186
142
  }, [open, visible]);
187
143
  const onAnimationEnd = react.useCallback(() => {
188
144
  if (!open) {
189
- hide();
190
- }
191
- }, [hide, open]);
192
- react.useEffect(() => {
193
- if (open) {
194
- return;
195
- }
196
- if (!hasAnimationDuration(dialogRef.current)) {
197
- hide();
145
+ setVisible(false);
198
146
  }
199
- }, [hide, open]);
147
+ }, [setVisible, open]);
200
148
  if (!visible) {
201
149
  return null;
202
150
  }
203
- const dataOpen = typeof window === "undefined" && open ? "" : void 0;
204
- return /* @__PURE__ */ jsxRuntime.jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsxRuntime.jsx(DialogContext.Provider, { value: { setEnabled }, children: /* @__PURE__ */ jsxRuntime.jsx(
151
+ const dataOpen = typeof window === "undefined" && open ? true : void 0;
152
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(DialogContext.Provider, { value: { setEnabled }, children: /* @__PURE__ */ jsxRuntime.jsx(
205
153
  "dialog",
206
154
  {
207
155
  ref: dialogRef,
208
156
  "aria-modal": "true",
209
- "data-open": dataOpen,
157
+ open: dataOpen,
210
158
  className: styles_components_display_Divider_Divider_cjs.classnames(styles_components_overlay_Dialog_dialog_css_cjs.dialog, dialogClassName, className),
211
159
  onAnimationEnd,
212
160
  onTransitionEnd: onAnimationEnd,
@@ -216,11 +164,8 @@ const Dialog = ({
216
164
  ) }) });
217
165
  };
218
166
  exports.Dialog = Dialog;
219
- exports.Portal = Portal;
220
167
  exports.hasAnimationDuration = hasAnimationDuration;
221
168
  exports.useClickOutside = useClickOutside;
222
169
  exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
223
170
  exports.useKeyboard = useKeyboard;
224
- exports.useLayer = useLayer;
225
171
  exports.usePreventBodyScroll = usePreventBodyScroll;
226
- exports.useVisibilityState = useVisibilityState;
@@ -1,16 +1,7 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { useEffect, useLayoutEffect, useRef, useState, useCallback, createContext, useContext } from "react";
3
- import { useTheme, useComponentStyles, classnames } from "../../display/Divider/Divider.mjs";
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useLayoutEffect, useRef, createContext, useContext, useState, useCallback } from "react";
3
+ import { useComponentStyles, classnames } from "../../display/Divider/Divider.mjs";
4
4
  import { dialog } from "./dialog.css.mjs";
5
- import { createPortal } from "react-dom";
6
- import { BlocksProvider } from "../../other/BlocksProvider/BlocksProvider.mjs";
7
- const Portal = ({ children, container }) => {
8
- const context = useTheme();
9
- return createPortal(
10
- /* @__PURE__ */ jsx(BlocksProvider, { theme: context, children }),
11
- container || document.body
12
- );
13
- };
14
5
  const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
15
6
  useEffect(() => {
16
7
  if (!enabled) {
@@ -21,8 +12,11 @@ const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
21
12
  onClickOutside();
22
13
  }
23
14
  };
24
- document.addEventListener("click", listener);
15
+ const rafId = requestAnimationFrame(() => {
16
+ document.addEventListener("click", listener);
17
+ });
25
18
  return () => {
19
+ cancelAnimationFrame(rafId);
26
20
  document.removeEventListener("click", listener);
27
21
  };
28
22
  }, [ref, onClickOutside, enabled]);
@@ -44,27 +38,6 @@ const useKeyboard = (key, callback, { enabled = true, type = "keydown" } = {}) =
44
38
  };
45
39
  }, [callback, enabled, key, type]);
46
40
  };
47
- const useLayer = () => {
48
- const layerRef = useRef();
49
- useEffect(
50
- () => () => {
51
- if (layerRef.current) {
52
- layerRef.current.remove();
53
- layerRef.current = void 0;
54
- }
55
- },
56
- []
57
- );
58
- return () => {
59
- if (!layerRef.current) {
60
- const div = document.createElement("div");
61
- div.dataset.layer = "blocks";
62
- layerRef.current = div;
63
- document.body.append(layerRef.current);
64
- }
65
- return layerRef.current;
66
- };
67
- };
68
41
  const usePreventBodyScroll = (enabled = true) => {
69
42
  useIsomorphicLayoutEffect(() => {
70
43
  if (!enabled) {
@@ -105,24 +78,15 @@ const useRestoreFocus = (active) => {
105
78
  }
106
79
  }, [active]);
107
80
  };
108
- const useVisibilityState = (open) => {
109
- const [visible, setVisible] = useState(open);
110
- const hide = useCallback(() => {
111
- setVisible(false);
112
- }, []);
113
- useEffect(() => {
114
- if (open) {
115
- setVisible(true);
116
- }
117
- }, [open]);
118
- return [visible, hide];
119
- };
120
81
  function hasAnimationDuration(element) {
121
82
  if (!element) {
122
83
  return false;
123
84
  }
124
85
  const style = window.getComputedStyle(element);
125
- return style.transitionDuration !== "0s" || style.animationDuration !== "0s";
86
+ return hasDuration(style.transitionDuration) || hasDuration(style.animationDuration);
87
+ }
88
+ function hasDuration(duration) {
89
+ return duration.split(",").map((part) => Number.parseFloat(part.trim())).some((part) => part > 0);
126
90
  }
127
91
  const DialogContext = createContext(void 0);
128
92
  const useNestedDialog = (open) => {
@@ -148,12 +112,11 @@ const Dialog = ({
148
112
  }) => {
149
113
  const dialogClassName = useComponentStyles("dialog", { dialog: true, variants: { size } });
150
114
  const dialogRef = useRef(null);
151
- const layer = useLayer();
152
- const [visible, hide] = useVisibilityState(open);
153
115
  const [enabled, setEnabled] = useState(true);
116
+ const [visible, setVisible] = useState(open);
154
117
  useRestoreFocus(open);
155
- const isNested = useNestedDialog(visible);
156
- usePreventBodyScroll(visible && !isNested);
118
+ const isNested = useNestedDialog(open);
119
+ usePreventBodyScroll(open && !isNested);
157
120
  const onEscape = useCallback(
158
121
  (event) => {
159
122
  event.preventDefault();
@@ -165,47 +128,32 @@ const Dialog = ({
165
128
  useClickOutside(dialogRef, onRequestClose, { enabled: open && enabled });
166
129
  useIsomorphicLayoutEffect(() => {
167
130
  var _a, _b;
168
- if (!visible) {
169
- (_a = dialogRef.current) == null ? void 0 : _a.close();
170
- }
171
- if (!open) {
172
- (_b = dialogRef.current) == null ? void 0 : _b.removeAttribute("data-open");
173
- return;
131
+ if (open && visible) {
132
+ (_a = dialogRef.current) == null ? void 0 : _a.showModal();
133
+ } else if (open) {
134
+ setVisible(true);
135
+ } else {
136
+ if (!hasAnimationDuration(dialogRef.current)) {
137
+ setVisible(false);
138
+ }
139
+ (_b = dialogRef.current) == null ? void 0 : _b.close();
174
140
  }
175
- let timer = requestAnimationFrame(() => {
176
- timer = requestAnimationFrame(() => {
177
- var _a2, _b2;
178
- (_a2 = dialogRef.current) == null ? void 0 : _a2.showModal();
179
- (_b2 = dialogRef.current) == null ? void 0 : _b2.setAttribute("data-open", "");
180
- });
181
- });
182
- return () => {
183
- cancelAnimationFrame(timer);
184
- };
185
141
  }, [open, visible]);
186
142
  const onAnimationEnd = useCallback(() => {
187
143
  if (!open) {
188
- hide();
189
- }
190
- }, [hide, open]);
191
- useEffect(() => {
192
- if (open) {
193
- return;
194
- }
195
- if (!hasAnimationDuration(dialogRef.current)) {
196
- hide();
144
+ setVisible(false);
197
145
  }
198
- }, [hide, open]);
146
+ }, [setVisible, open]);
199
147
  if (!visible) {
200
148
  return null;
201
149
  }
202
- const dataOpen = typeof window === "undefined" && open ? "" : void 0;
203
- return /* @__PURE__ */ jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsx(DialogContext.Provider, { value: { setEnabled }, children: /* @__PURE__ */ jsx(
150
+ const dataOpen = typeof window === "undefined" && open ? true : void 0;
151
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(DialogContext.Provider, { value: { setEnabled }, children: /* @__PURE__ */ jsx(
204
152
  "dialog",
205
153
  {
206
154
  ref: dialogRef,
207
155
  "aria-modal": "true",
208
- "data-open": dataOpen,
156
+ open: dataOpen,
209
157
  className: classnames(dialog, dialogClassName, className),
210
158
  onAnimationEnd,
211
159
  onTransitionEnd: onAnimationEnd,
@@ -216,12 +164,9 @@ const Dialog = ({
216
164
  };
217
165
  export {
218
166
  Dialog,
219
- Portal,
220
167
  hasAnimationDuration,
221
168
  useClickOutside,
222
169
  useIsomorphicLayoutEffect,
223
170
  useKeyboard,
224
- useLayer,
225
- usePreventBodyScroll,
226
- useVisibilityState
171
+ usePreventBodyScroll
227
172
  };
@@ -20,23 +20,36 @@ const dialog = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("dialo
20
20
  backgroundColor: "rgba(0, 0, 0, 0.5)"
21
21
  },
22
22
  selectors: {
23
- "&[data-open]": {
23
+ "&[open]": {
24
24
  transform: "translate(0, 0)",
25
25
  opacity: 1
26
26
  },
27
- "&[data-open]::backdrop": {
27
+ "&[open]::backdrop": {
28
28
  opacity: 1
29
29
  }
30
30
  },
31
31
  // Apply the animation only if the user has not requested reduced motion
32
32
  "@media": {
33
33
  "(prefers-reduced-motion: no-preference)": {
34
+ // Ending style
34
35
  transform: "translate(0, -120px)",
35
36
  opacity: 0,
36
- transition: "transform 240ms, opacity 160ms",
37
+ transitionBehavior: "allow-discrete",
38
+ transitionProperty: "opacity, transform, overlay, display",
39
+ transitionDuration: "240ms, 160ms, 240ms, 240ms",
40
+ // @ts-expect-error - Vanilla Extract does not support @starting-style (yet)
41
+ "@starting-style": {
42
+ transform: "translate(0, -120px)",
43
+ opacity: 0
44
+ },
37
45
  "::backdrop": {
38
46
  opacity: 0,
39
- transition: "opacity 160ms"
47
+ transitionBehavior: "allow-discrete",
48
+ transitionProperty: "opacity, overlay, display",
49
+ transitionDuration: "160ms, 240ms, 240ms",
50
+ "@starting-style": {
51
+ opacity: 0
52
+ }
40
53
  }
41
54
  }
42
55
  }
@@ -19,23 +19,36 @@ const dialog = makeComponentTheme("dialog", {
19
19
  backgroundColor: "rgba(0, 0, 0, 0.5)"
20
20
  },
21
21
  selectors: {
22
- "&[data-open]": {
22
+ "&[open]": {
23
23
  transform: "translate(0, 0)",
24
24
  opacity: 1
25
25
  },
26
- "&[data-open]::backdrop": {
26
+ "&[open]::backdrop": {
27
27
  opacity: 1
28
28
  }
29
29
  },
30
30
  // Apply the animation only if the user has not requested reduced motion
31
31
  "@media": {
32
32
  "(prefers-reduced-motion: no-preference)": {
33
+ // Ending style
33
34
  transform: "translate(0, -120px)",
34
35
  opacity: 0,
35
- transition: "transform 240ms, opacity 160ms",
36
+ transitionBehavior: "allow-discrete",
37
+ transitionProperty: "opacity, transform, overlay, display",
38
+ transitionDuration: "240ms, 160ms, 240ms, 240ms",
39
+ // @ts-expect-error - Vanilla Extract does not support @starting-style (yet)
40
+ "@starting-style": {
41
+ transform: "translate(0, -120px)",
42
+ opacity: 0
43
+ },
36
44
  "::backdrop": {
37
45
  opacity: 0,
38
- transition: "opacity 160ms"
46
+ transitionBehavior: "allow-discrete",
47
+ transitionProperty: "opacity, overlay, display",
48
+ transitionDuration: "160ms, 240ms, 240ms",
49
+ "@starting-style": {
50
+ opacity: 0
51
+ }
39
52
  }
40
53
  }
41
54
  }
@@ -19,6 +19,12 @@ const link = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("link",
19
19
  textDecoration: "underline"
20
20
  },
21
21
  cursor: "pointer"
22
+ // selectors: {
23
+ // '&[target="_blank"]::after': {
24
+ // content: '"\\2197"',
25
+ // marginLeft: 4,
26
+ // },
27
+ // },
22
28
  }, styles_themes_momotaro_components_helpers_css_cjs.focusable], "link_base"),
23
29
  variants: {
24
30
  variant: {
@@ -18,6 +18,12 @@ const link = makeComponentTheme("link", {
18
18
  textDecoration: "underline"
19
19
  },
20
20
  cursor: "pointer"
21
+ // selectors: {
22
+ // '&[target="_blank"]::after': {
23
+ // content: '"\\2197"',
24
+ // marginLeft: 4,
25
+ // },
26
+ // },
21
27
  }, focusable], "link_base"),
22
28
  variants: {
23
29
  variant: {
@@ -11,6 +11,7 @@ const popover = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("popo
11
11
  padding: "medium",
12
12
  margin: "small",
13
13
  // Space between the popover and the anchor element
14
+ width: "max-content",
14
15
  selectors: {
15
16
  "&[data-open]": {
16
17
  transform: "scale(1)",
@@ -10,6 +10,7 @@ const popover = makeComponentTheme("popover", {
10
10
  padding: "medium",
11
11
  margin: "small",
12
12
  // Space between the popover and the anchor element
13
+ width: "max-content",
13
14
  selectors: {
14
15
  "&[data-open]": {
15
16
  transform: "scale(1)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockle/blocks",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Blocks design system",
5
5
  "repository": "git@github.com:Blockle/blocks.git",
6
6
  "license": "MIT",
@@ -34,7 +34,6 @@
34
34
  "import": "./dist/themes/momotaro.mjs",
35
35
  "require": "./dist/themes/momotaro.cjs"
36
36
  },
37
- "./dist/style.css": "./dist/style.css",
38
37
  "./package.json": "./package.json"
39
38
  },
40
39
  "main": "./dist/index.cjs",
@@ -59,6 +58,10 @@
59
58
  "resolutions": {
60
59
  "string-width": "^4.2.2"
61
60
  },
61
+ "dependencies": {
62
+ "npm": "^10.8.1",
63
+ "update": "^0.4.2"
64
+ },
62
65
  "devDependencies": {
63
66
  "@changesets/cli": "^2.27.5",
64
67
  "@crackle/cli": "^0.15.4",