reshaped 3.9.0 → 3.9.1-canary.3

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.
Files changed (53) hide show
  1. package/dist/bundle.css +1 -1
  2. package/dist/bundle.js +2 -2
  3. package/dist/components/Accordion/AccordionControlled.js +0 -1
  4. package/dist/components/Actionable/Actionable.d.ts +8 -3
  5. package/dist/components/Actionable/Actionable.js +17 -70
  6. package/dist/components/Actionable/Actionable.types.d.ts +2 -36
  7. package/dist/components/Actionable/index.d.ts +2 -1
  8. package/dist/components/Badge/Badge.js +5 -4
  9. package/dist/components/Badge/Badge.module.css +1 -1
  10. package/dist/components/Calendar/Calendar.utils.js +6 -7
  11. package/dist/components/Card/Card.d.ts +1 -1
  12. package/dist/components/Carousel/Carousel.js +0 -1
  13. package/dist/components/Flyout/Flyout.module.css +1 -1
  14. package/dist/components/Flyout/Flyout.types.d.ts +7 -7
  15. package/dist/components/Flyout/FlyoutContent.js +3 -58
  16. package/dist/components/Flyout/FlyoutControlled.js +84 -83
  17. package/dist/components/Flyout/FlyoutTrigger.js +3 -3
  18. package/dist/components/Flyout/useFlyout.d.ts +3 -4
  19. package/dist/components/Flyout/useFlyout.js +70 -88
  20. package/dist/components/Flyout/utilities/safeArea.d.ts +10 -0
  21. package/dist/components/Flyout/utilities/safeArea.js +100 -0
  22. package/dist/components/Select/Select.js +1 -1
  23. package/dist/components/Select/SelectCustomControlled.js +0 -1
  24. package/dist/components/Tabs/TabsControlled.js +0 -1
  25. package/dist/components/Toast/ToastContainer.js +0 -1
  26. package/dist/components/_private/Expandable/Expandable.js +1 -3
  27. package/dist/components/_private/Portal/Portal.js +0 -3
  28. package/dist/core/Actionable/Actionable.d.ts +4 -0
  29. package/dist/core/Actionable/Actionable.js +73 -0
  30. package/dist/core/Actionable/Actionable.types.d.ts +34 -0
  31. package/dist/core/Actionable/Actionable.types.js +1 -0
  32. package/dist/core/Actionable/index.d.ts +2 -0
  33. package/dist/core/Actionable/index.js +1 -0
  34. package/dist/hooks/_private/usePrevious.js +0 -1
  35. package/dist/hooks/useOnClickOutside.js +8 -0
  36. package/dist/utilities/a11y/TrapFocus.js +9 -3
  37. package/dist/utilities/dom/index.d.ts +0 -1
  38. package/dist/utilities/dom/index.js +0 -1
  39. package/package.json +4 -2
  40. package/dist/components/Flyout/utilities/calculatePosition.d.ts +0 -31
  41. package/dist/components/Flyout/utilities/calculatePosition.js +0 -185
  42. package/dist/components/Flyout/utilities/constants.d.ts +0 -1
  43. package/dist/components/Flyout/utilities/constants.js +0 -1
  44. package/dist/components/Flyout/utilities/flyout.d.ts +0 -11
  45. package/dist/components/Flyout/utilities/flyout.js +0 -115
  46. package/dist/components/Flyout/utilities/getPositionFallbacks.d.ts +0 -3
  47. package/dist/components/Flyout/utilities/getPositionFallbacks.js +0 -39
  48. package/dist/components/Flyout/utilities/helpers.d.ts +0 -7
  49. package/dist/components/Flyout/utilities/helpers.js +0 -14
  50. package/dist/components/Flyout/utilities/isFullyVisible.d.ts +0 -13
  51. package/dist/components/Flyout/utilities/isFullyVisible.js +0 -23
  52. package/dist/utilities/dom/flyout.d.ts +0 -2
  53. package/dist/utilities/dom/flyout.js +0 -14
@@ -1,115 +0,0 @@
1
- import { getRectFromCoordinates, getShadowRoot, findClosestPositionContainer } from "../../../utilities/dom/index.js";
2
- import { resetStyles } from "../Flyout.constants.js";
3
- import calculatePosition from "./calculatePosition.js";
4
- import { SCREEN_OFFSET } from "./constants.js";
5
- import getPositionFallbacks from "./getPositionFallbacks.js";
6
- import isFullyVisible from "./isFullyVisible.js";
7
- /**
8
- * Set position of the target element to fit on the screen
9
- */
10
- const flyout = (args) => {
11
- const { triggerEl, flyoutEl, triggerBounds: passedTriggerBounds, contentShift = 0, contentGap = 0, position, fallbackPositions, fallbackAdjustLayout, fallbackMinWidth, fallbackMinHeight, width, container: passedContainer, lastUsedPosition, onPositionChoose, rtl, } = args;
12
- const targetClone = flyoutEl.cloneNode(true);
13
- const baseUnit = getComputedStyle(flyoutEl).getPropertyValue("--rs-unit-x1");
14
- const unitModifier = baseUnit ? parseInt(baseUnit) : 4;
15
- const triggerBounds = passedTriggerBounds || triggerEl?.getBoundingClientRect();
16
- if (!triggerBounds)
17
- return;
18
- const resolvedTriggerBounds = getRectFromCoordinates(triggerBounds);
19
- // Reset all styles applied on the previous hook execution
20
- targetClone.style.cssText = "";
21
- Object.keys(resetStyles).forEach((key) => {
22
- const value = resetStyles[key];
23
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
24
- // @ts-ignore
25
- if (value)
26
- targetClone.style[key] = value.toString();
27
- });
28
- if (width === "trigger") {
29
- targetClone.style.width = `${resolvedTriggerBounds.width}px`;
30
- }
31
- else if (width && width !== "full") {
32
- targetClone.style.width = width;
33
- }
34
- const shadowRoot = triggerEl && getShadowRoot(triggerEl);
35
- // Insert inside shadow root if possible to make sure styles are applied correctly
36
- (shadowRoot || document.body).appendChild(targetClone);
37
- const closestFixedContainer = !passedContainer && triggerEl ? findClosestPositionContainer({ el: triggerEl }) : undefined;
38
- const container = passedContainer ||
39
- // Render inside fixed position container automatically to keep their position synced on scroll
40
- closestFixedContainer ||
41
- document.body;
42
- const renderContainerBounds = container.getBoundingClientRect();
43
- const applyPosition = (position, options) => {
44
- const widthOption = options?.width || width;
45
- // If there is a width override, apply it to calculate the position and the height correctly
46
- if (widthOption === "full") {
47
- targetClone.style.width = `calc(100% - ${SCREEN_OFFSET * 2}px)`;
48
- }
49
- else if (widthOption === "trigger") {
50
- targetClone.style.width = `${resolvedTriggerBounds.width}px`;
51
- }
52
- else {
53
- targetClone.style.width = widthOption || "";
54
- }
55
- const cloneRect = targetClone.getBoundingClientRect();
56
- const flyoutBounds = { width: cloneRect.width, height: cloneRect.height };
57
- return calculatePosition({
58
- triggerBounds: resolvedTriggerBounds,
59
- flyoutBounds,
60
- containerBounds: renderContainerBounds,
61
- position,
62
- contentGap: contentGap * unitModifier,
63
- contentShift: contentShift * unitModifier,
64
- rtl,
65
- width: widthOption,
66
- passedContainer: passedContainer ||
67
- (closestFixedContainer !== document.body ? closestFixedContainer : undefined),
68
- fallbackAdjustLayout,
69
- fallbackMinWidth,
70
- fallbackMinHeight,
71
- });
72
- };
73
- const testVisibility = (calculated) => {
74
- const visualContainerBounds = passedContainer?.getBoundingClientRect() ?? {
75
- width: window.innerWidth,
76
- height: window.innerHeight,
77
- left: window.scrollX,
78
- top: window.scrollY,
79
- };
80
- return isFullyVisible({
81
- flyoutBounds: calculated.boundaries,
82
- visualContainerBounds,
83
- renderContainerBounds,
84
- });
85
- };
86
- let calculated = null;
87
- const testOrder = getPositionFallbacks(position, fallbackPositions);
88
- testOrder.some((currentPosition) => {
89
- const tested = applyPosition(currentPosition);
90
- const visible = testVisibility(tested);
91
- if (visible)
92
- calculated = tested;
93
- return visible;
94
- });
95
- // Try full width positions in case it doesn't fit on any side
96
- if (!calculated) {
97
- const smallScreenFallbackPositions = ["top", "bottom"].filter((position) => testOrder.includes(position));
98
- smallScreenFallbackPositions.some((position) => {
99
- const tested = applyPosition(position, { width: "full" });
100
- const visible = testVisibility(tested);
101
- if (visible)
102
- calculated = tested;
103
- return visible;
104
- });
105
- }
106
- if (!calculated)
107
- calculated = applyPosition(lastUsedPosition);
108
- onPositionChoose(calculated.position);
109
- targetClone.parentNode?.removeChild(targetClone);
110
- Object.entries(calculated.styles).forEach(([key, value]) => {
111
- flyoutEl.style.setProperty(key, value);
112
- });
113
- return { position: calculated.position };
114
- };
115
- export default flyout;
@@ -1,3 +0,0 @@
1
- import type * as T from "../Flyout.types";
2
- declare const getPositionFallbacks: (position: T.Position, availableFallbacks?: T.Position[]) => T.Position[];
3
- export default getPositionFallbacks;
@@ -1,39 +0,0 @@
1
- // All available positions for each side
2
- const positions = {
3
- top: ["top-start", "top-end", "top"],
4
- bottom: ["bottom-start", "bottom-end", "bottom"],
5
- start: ["start-top", "start-bottom", "start"],
6
- end: ["end-top", "end-bottom", "end"],
7
- };
8
- // Order of sides to try depending on the starting side
9
- const fallbackOrder = {
10
- top: ["bottom", "start", "end"],
11
- bottom: ["top", "end", "start"],
12
- start: ["end", "top", "bottom"],
13
- end: ["start", "bottom", "top"],
14
- };
15
- // Get an order of positions to try to fit flyout on the screen based on its starting position
16
- const getPositionFallbacks = (position, availableFallbacks) => {
17
- const result = new Set([position]);
18
- const chunks = position.split("-");
19
- const [firstChunk] = chunks;
20
- const passedPositionOrder = positions[firstChunk];
21
- const startingFallbackIndex = passedPositionOrder.indexOf(position);
22
- const fallbackIndexOrder = [startingFallbackIndex];
23
- passedPositionOrder.forEach((_, index) => {
24
- if (index === startingFallbackIndex)
25
- return;
26
- fallbackIndexOrder.push(index);
27
- });
28
- [firstChunk, ...fallbackOrder[firstChunk]].forEach((fallbackSide) => {
29
- const fallbackOrder = positions[fallbackSide];
30
- fallbackIndexOrder.forEach((index) => {
31
- const position = fallbackOrder[index];
32
- if (availableFallbacks?.indexOf(position) === -1)
33
- return;
34
- result.add(position);
35
- });
36
- });
37
- return Array.from(result);
38
- };
39
- export default getPositionFallbacks;
@@ -1,7 +0,0 @@
1
- import type * as T from "../Flyout.types";
2
- /** Mirror the position for RTL */
3
- export declare const getRTLPosition: (position: T.Position) => T.Position;
4
- /**
5
- * Get a position value which centers 2 elements vertically or horizontally
6
- */
7
- export declare const centerBySize: (originSize: number, targetSize: number) => number;
@@ -1,14 +0,0 @@
1
- /** Mirror the position for RTL */
2
- export const getRTLPosition = (position) => {
3
- if (position.includes("start"))
4
- return position.replace("start", "end");
5
- if (position.includes("end"))
6
- return position.replace("end", "start");
7
- return position;
8
- };
9
- /**
10
- * Get a position value which centers 2 elements vertically or horizontally
11
- */
12
- export const centerBySize = (originSize, targetSize) => {
13
- return Math.floor(originSize / 2 - targetSize / 2);
14
- };
@@ -1,13 +0,0 @@
1
- type Bounds = Pick<DOMRect, "left" | "top" | "width" | "height">;
2
- /**
3
- * Check if element visually fits within its render container
4
- */
5
- declare const isFullyVisible: (args: {
6
- /** Bounds of the flyout content */
7
- flyoutBounds: Bounds;
8
- /** Bounds of the container where the flyout content should fit */
9
- visualContainerBounds: Bounds;
10
- /** Bounds of the container where flyout content is rendered */
11
- renderContainerBounds: Bounds;
12
- }) => boolean;
13
- export default isFullyVisible;
@@ -1,23 +0,0 @@
1
- import { SCREEN_OFFSET } from "./constants.js";
2
- /**
3
- * Check if element visually fits within its render container
4
- */
5
- const isFullyVisible = (args) => {
6
- const { flyoutBounds, visualContainerBounds, renderContainerBounds } = args;
7
- if (renderContainerBounds.left + flyoutBounds.left < visualContainerBounds.left + SCREEN_OFFSET) {
8
- return false;
9
- }
10
- if (renderContainerBounds.top + flyoutBounds.top < visualContainerBounds.top + SCREEN_OFFSET) {
11
- return false;
12
- }
13
- if (renderContainerBounds.left + flyoutBounds.left + flyoutBounds.width >
14
- visualContainerBounds.left + visualContainerBounds.width - SCREEN_OFFSET) {
15
- return false;
16
- }
17
- if (renderContainerBounds.top + flyoutBounds.top + flyoutBounds.height >
18
- visualContainerBounds.top + visualContainerBounds.height - SCREEN_OFFSET) {
19
- return false;
20
- }
21
- return true;
22
- };
23
- export default isFullyVisible;
@@ -1,2 +0,0 @@
1
- import type * as G from "../../types/global";
2
- export declare const getRectFromCoordinates: (coordinates: DOMRect | G.Coordinates) => DOMRect;
@@ -1,14 +0,0 @@
1
- export const getRectFromCoordinates = (coordinates) => {
2
- if ("width" in coordinates && coordinates.width !== undefined)
3
- return coordinates;
4
- return {
5
- ...coordinates,
6
- width: 0,
7
- height: 0,
8
- left: coordinates.x,
9
- right: coordinates.x,
10
- top: coordinates.y,
11
- bottom: coordinates.y,
12
- toJSON: () => { },
13
- };
14
- };