@blockle/blocks 0.13.0 → 0.14.1

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.cjs CHANGED
@@ -17,6 +17,7 @@ const styles_components_form_Select_Select_cjs = require("./styles/components/fo
17
17
  const styles_components_form_Slider_Slider_cjs = require("./styles/components/form/Slider/Slider.cjs");
18
18
  const styles_components_form_Switch_Switch_cjs = require("./styles/components/form/Switch/Switch.cjs");
19
19
  const styles_components_other_BlocksProvider_BlocksProvider_cjs = require("./styles/components/other/BlocksProvider/BlocksProvider.cjs");
20
+ const reactDom = require("react-dom");
20
21
  const styles_components_overlay_Dialog_Dialog_cjs = require("./styles/components/overlay/Dialog/Dialog.cjs");
21
22
  const styles_components_typography_Heading_Heading_cjs = require("./styles/components/typography/Heading/Heading.cjs");
22
23
  const styles_components_typography_Text_Text_cjs = require("./styles/components/typography/Text/Text.cjs");
@@ -136,7 +137,47 @@ const Link = react.forwardRef(function Link2({ asChild, className, children, var
136
137
  }
137
138
  );
138
139
  });
139
- function getDopoverPosition(align, anchorRef, popoverRef) {
140
+ const Portal = ({ children, container }) => {
141
+ const context = styles_components_display_Divider_Divider_cjs.useTheme();
142
+ return reactDom.createPortal(
143
+ /* @__PURE__ */ jsxRuntime.jsx(styles_components_other_BlocksProvider_BlocksProvider_cjs.BlocksProvider, { theme: context, children }),
144
+ container || document.body
145
+ );
146
+ };
147
+ const useLayer = () => {
148
+ const layerRef = react.useRef();
149
+ react.useEffect(
150
+ () => () => {
151
+ if (layerRef.current) {
152
+ layerRef.current.remove();
153
+ layerRef.current = void 0;
154
+ }
155
+ },
156
+ []
157
+ );
158
+ return () => {
159
+ if (!layerRef.current) {
160
+ const div = document.createElement("div");
161
+ div.dataset.layer = "blocks";
162
+ layerRef.current = div;
163
+ document.body.append(layerRef.current);
164
+ }
165
+ return layerRef.current;
166
+ };
167
+ };
168
+ const useVisibilityState = (open) => {
169
+ const [visible, setVisible] = react.useState(open);
170
+ const hide = react.useCallback(() => {
171
+ setVisible(false);
172
+ }, []);
173
+ react.useEffect(() => {
174
+ if (open) {
175
+ setVisible(true);
176
+ }
177
+ }, [open]);
178
+ return [visible, hide];
179
+ };
180
+ function getPopoverPosition(align, anchorRef, popoverRef) {
140
181
  if (!anchorRef.current || !popoverRef.current) {
141
182
  return [0, 0];
142
183
  }
@@ -144,7 +185,12 @@ function getDopoverPosition(align, anchorRef, popoverRef) {
144
185
  popoverRef.current.style.transitionDuration = "0s";
145
186
  const anchorRect = anchorRef.current.getBoundingClientRect();
146
187
  const popoverRect = popoverRef.current.getBoundingClientRect();
147
- const popoverStyles = getComputedStyle(popoverRef.current);
188
+ let popoverStyles = getComputedStyle(popoverRef.current);
189
+ const top = popoverStyles.getPropertyValue("top");
190
+ const left = popoverStyles.getPropertyValue("left");
191
+ popoverRef.current.style.left = "0";
192
+ popoverRef.current.style.top = "0";
193
+ popoverStyles = getComputedStyle(popoverRef.current);
148
194
  const marginTop = Number.parseFloat(popoverStyles.getPropertyValue("margin-top"));
149
195
  const marginRight = Number.parseFloat(popoverStyles.getPropertyValue("margin-right"));
150
196
  const marginBottom = Number.parseFloat(popoverStyles.getPropertyValue("margin-bottom"));
@@ -165,6 +211,8 @@ function getDopoverPosition(align, anchorRef, popoverRef) {
165
211
  const offsetY = anchorTop - marginTop - (popoverRect.height - anchorRect.height) / 2;
166
212
  popoverRef.current.style.transform = "";
167
213
  popoverRef.current.style.transitionDuration = "";
214
+ popoverRef.current.style.top = top;
215
+ popoverRef.current.style.left = left;
168
216
  switch (align) {
169
217
  case "top": {
170
218
  return topPosition > 0 ? [offsetX, anchorTop - popoverRect.height - marginY] : [offsetX, anchorTop + anchorRect.height];
@@ -191,8 +239,8 @@ const Popover = ({
191
239
  style,
192
240
  ...restProps
193
241
  }) => {
194
- const layer = styles_components_overlay_Dialog_Dialog_cjs.useLayer();
195
- const [visible, hide] = styles_components_overlay_Dialog_Dialog_cjs.useVisibilityState(open);
242
+ const layer = useLayer();
243
+ const [visible, hide] = useVisibilityState(open);
196
244
  const [position, setPosition] = react.useState({ x: 0, y: 0 });
197
245
  const popoverRef = react.useRef(null);
198
246
  const containerClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("popover", { base: true }, false);
@@ -200,7 +248,7 @@ const Popover = ({
200
248
  if (!visible) {
201
249
  return;
202
250
  }
203
- const position2 = getDopoverPosition(align, anchorElement, popoverRef);
251
+ const position2 = getPopoverPosition(align, anchorElement, popoverRef);
204
252
  setPosition({ x: position2[0], y: position2[1] });
205
253
  }, [align, anchorElement, visible]);
206
254
  react.useEffect(() => {
@@ -208,7 +256,7 @@ const Popover = ({
208
256
  return;
209
257
  }
210
258
  function handleResize() {
211
- const position2 = getDopoverPosition(align, anchorElement, popoverRef);
259
+ const position2 = getPopoverPosition(align, anchorElement, popoverRef);
212
260
  setPosition({ x: position2[0], y: position2[1] });
213
261
  }
214
262
  window.addEventListener("resize", handleResize);
@@ -253,7 +301,7 @@ const Popover = ({
253
301
  return null;
254
302
  }
255
303
  const dataOpen = typeof window === "undefined" && open ? "" : void 0;
256
- return /* @__PURE__ */ jsxRuntime.jsx(styles_components_overlay_Dialog_Dialog_cjs.Portal, { container: layer(), children: /* @__PURE__ */ jsxRuntime.jsx(
304
+ return /* @__PURE__ */ jsxRuntime.jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsxRuntime.jsx(
257
305
  styles_components_display_Divider_Divider_cjs.Box,
258
306
  {
259
307
  ref: popoverRef,
@@ -366,7 +414,6 @@ exports.Slider = styles_components_form_Slider_Slider_cjs.Slider;
366
414
  exports.Switch = styles_components_form_Switch_Switch_cjs.Switch;
367
415
  exports.BlocksProvider = styles_components_other_BlocksProvider_BlocksProvider_cjs.BlocksProvider;
368
416
  exports.Dialog = styles_components_overlay_Dialog_Dialog_cjs.Dialog;
369
- exports.Portal = styles_components_overlay_Dialog_Dialog_cjs.Portal;
370
417
  exports.useIsomorphicLayoutEffect = styles_components_overlay_Dialog_Dialog_cjs.useIsomorphicLayoutEffect;
371
418
  exports.useKeyboard = styles_components_overlay_Dialog_Dialog_cjs.useKeyboard;
372
419
  exports.usePreventBodyScroll = styles_components_overlay_Dialog_Dialog_cjs.usePreventBodyScroll;
@@ -374,6 +421,7 @@ exports.Heading = styles_components_typography_Heading_Heading_cjs.Heading;
374
421
  exports.Text = styles_components_typography_Text_Text_cjs.Text;
375
422
  exports.Inline = Inline;
376
423
  exports.Link = Link;
424
+ exports.Portal = Portal;
377
425
  exports.Progress = Progress;
378
426
  exports.Stack = Stack;
379
427
  exports.Tooltip = Tooltip;
package/dist/index.mjs CHANGED
@@ -5,11 +5,11 @@ import { style } from "./styles/lib/css/style/style.mjs";
5
5
  import { makeComponentTheme } from "./styles/lib/theme/makeComponentTheme.mjs";
6
6
  import { makeTheme } from "./styles/lib/theme/makeTheme.mjs";
7
7
  import { vars } from "./styles/lib/theme/vars.css.mjs";
8
- import { useComponentStyles, Box, classnames, createAsChildTemplate, composeRefs, BlocksProviderContext } from "./styles/components/display/Divider/Divider.mjs";
8
+ import { useComponentStyles, Box, classnames, createAsChildTemplate, useTheme, composeRefs, BlocksProviderContext } from "./styles/components/display/Divider/Divider.mjs";
9
9
  import { Divider, useComponentStyleDefaultProps } from "./styles/components/display/Divider/Divider.mjs";
10
10
  import { atoms } from "./styles/lib/css/atoms/sprinkles.css.mjs";
11
11
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
12
- import { forwardRef, useState, useRef, useLayoutEffect, useEffect, useCallback, useId, Children, isValidElement, cloneElement, useContext } from "react";
12
+ import { forwardRef, useRef, useEffect, useState, useCallback, useLayoutEffect, useId, Children, isValidElement, cloneElement, useContext } from "react";
13
13
  import { Button, Spinner } from "./styles/components/form/Button/Button.mjs";
14
14
  import { Checkbox, Label } from "./styles/components/form/Checkbox/Checkbox.mjs";
15
15
  import { Input } from "./styles/components/form/Input/Input.mjs";
@@ -18,7 +18,8 @@ import { Select } from "./styles/components/form/Select/Select.mjs";
18
18
  import { Slider } from "./styles/components/form/Slider/Slider.mjs";
19
19
  import { Switch } from "./styles/components/form/Switch/Switch.mjs";
20
20
  import { BlocksProvider } from "./styles/components/other/BlocksProvider/BlocksProvider.mjs";
21
- import { useLayer, useVisibilityState, useIsomorphicLayoutEffect, hasAnimationDuration, useKeyboard, useClickOutside, Portal } from "./styles/components/overlay/Dialog/Dialog.mjs";
21
+ import { createPortal } from "react-dom";
22
+ import { useIsomorphicLayoutEffect, hasAnimationDuration, useKeyboard, useClickOutside } from "./styles/components/overlay/Dialog/Dialog.mjs";
22
23
  import { Dialog, usePreventBodyScroll } from "./styles/components/overlay/Dialog/Dialog.mjs";
23
24
  import { Heading } from "./styles/components/typography/Heading/Heading.mjs";
24
25
  import { Text } from "./styles/components/typography/Text/Text.mjs";
@@ -138,7 +139,47 @@ const Link = forwardRef(function Link2({ asChild, className, children, variant,
138
139
  }
139
140
  );
140
141
  });
141
- function getDopoverPosition(align, anchorRef, popoverRef) {
142
+ const Portal = ({ children, container }) => {
143
+ const context = useTheme();
144
+ return createPortal(
145
+ /* @__PURE__ */ jsx(BlocksProvider, { theme: context, children }),
146
+ container || document.body
147
+ );
148
+ };
149
+ const useLayer = () => {
150
+ const layerRef = useRef();
151
+ useEffect(
152
+ () => () => {
153
+ if (layerRef.current) {
154
+ layerRef.current.remove();
155
+ layerRef.current = void 0;
156
+ }
157
+ },
158
+ []
159
+ );
160
+ return () => {
161
+ if (!layerRef.current) {
162
+ const div = document.createElement("div");
163
+ div.dataset.layer = "blocks";
164
+ layerRef.current = div;
165
+ document.body.append(layerRef.current);
166
+ }
167
+ return layerRef.current;
168
+ };
169
+ };
170
+ const useVisibilityState = (open) => {
171
+ const [visible, setVisible] = useState(open);
172
+ const hide = useCallback(() => {
173
+ setVisible(false);
174
+ }, []);
175
+ useEffect(() => {
176
+ if (open) {
177
+ setVisible(true);
178
+ }
179
+ }, [open]);
180
+ return [visible, hide];
181
+ };
182
+ function getPopoverPosition(align, anchorRef, popoverRef) {
142
183
  if (!anchorRef.current || !popoverRef.current) {
143
184
  return [0, 0];
144
185
  }
@@ -146,7 +187,12 @@ function getDopoverPosition(align, anchorRef, popoverRef) {
146
187
  popoverRef.current.style.transitionDuration = "0s";
147
188
  const anchorRect = anchorRef.current.getBoundingClientRect();
148
189
  const popoverRect = popoverRef.current.getBoundingClientRect();
149
- const popoverStyles = getComputedStyle(popoverRef.current);
190
+ let popoverStyles = getComputedStyle(popoverRef.current);
191
+ const top = popoverStyles.getPropertyValue("top");
192
+ const left = popoverStyles.getPropertyValue("left");
193
+ popoverRef.current.style.left = "0";
194
+ popoverRef.current.style.top = "0";
195
+ popoverStyles = getComputedStyle(popoverRef.current);
150
196
  const marginTop = Number.parseFloat(popoverStyles.getPropertyValue("margin-top"));
151
197
  const marginRight = Number.parseFloat(popoverStyles.getPropertyValue("margin-right"));
152
198
  const marginBottom = Number.parseFloat(popoverStyles.getPropertyValue("margin-bottom"));
@@ -167,6 +213,8 @@ function getDopoverPosition(align, anchorRef, popoverRef) {
167
213
  const offsetY = anchorTop - marginTop - (popoverRect.height - anchorRect.height) / 2;
168
214
  popoverRef.current.style.transform = "";
169
215
  popoverRef.current.style.transitionDuration = "";
216
+ popoverRef.current.style.top = top;
217
+ popoverRef.current.style.left = left;
170
218
  switch (align) {
171
219
  case "top": {
172
220
  return topPosition > 0 ? [offsetX, anchorTop - popoverRect.height - marginY] : [offsetX, anchorTop + anchorRect.height];
@@ -202,7 +250,7 @@ const Popover = ({
202
250
  if (!visible) {
203
251
  return;
204
252
  }
205
- const position2 = getDopoverPosition(align, anchorElement, popoverRef);
253
+ const position2 = getPopoverPosition(align, anchorElement, popoverRef);
206
254
  setPosition({ x: position2[0], y: position2[1] });
207
255
  }, [align, anchorElement, visible]);
208
256
  useEffect(() => {
@@ -210,7 +258,7 @@ const Popover = ({
210
258
  return;
211
259
  }
212
260
  function handleResize() {
213
- const position2 = getDopoverPosition(align, anchorElement, popoverRef);
261
+ const position2 = getPopoverPosition(align, anchorElement, popoverRef);
214
262
  setPosition({ x: position2[0], y: position2[1] });
215
263
  }
216
264
  window.addEventListener("resize", handleResize);