@sentry/scraps 0.2.0 → 0.4.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.
Files changed (114) hide show
  1. package/dist/button/buttonBar.js +7 -1
  2. package/dist/dragHandle/dragHandle.d.ts +34 -0
  3. package/dist/dragHandle/dragHandle.js +115 -0
  4. package/dist/dragHandle/index.d.ts +4 -0
  5. package/dist/dragHandle/index.js +4 -0
  6. package/dist/dragHandle/setDocumentDragging.d.ts +9 -0
  7. package/dist/dragHandle/setDocumentDragging.js +6 -0
  8. package/dist/dragHandle/useDragMove.d.ts +244 -0
  9. package/dist/dragHandle/useDragMove.js +66 -0
  10. package/dist/dragHandle/useDragSeparator.d.ts +256 -0
  11. package/dist/dragHandle/useDragSeparator.js +36 -0
  12. package/dist/formPresentation/autoSaveContext.d.ts +23 -0
  13. package/dist/formPresentation/autoSaveContext.js +13 -0
  14. package/dist/formPresentation/base.d.ts +11 -0
  15. package/dist/formPresentation/base.js +37 -0
  16. package/dist/formPresentation/displayField.d.ts +17 -0
  17. package/dist/formPresentation/displayField.js +69 -0
  18. package/dist/formPresentation/fieldIds.d.ts +3 -0
  19. package/dist/formPresentation/fieldIds.js +14 -0
  20. package/dist/formPresentation/fieldLayout.d.ts +23 -0
  21. package/dist/formPresentation/fieldLayout.js +76 -0
  22. package/dist/formPresentation/formContext.d.ts +4 -0
  23. package/dist/formPresentation/formContext.js +6 -0
  24. package/dist/formPresentation/groupContext.d.ts +24 -0
  25. package/dist/formPresentation/groupContext.js +22 -0
  26. package/dist/formPresentation/icons.d.ts +11 -0
  27. package/dist/formPresentation/icons.js +61 -0
  28. package/dist/formPresentation/index.d.ts +8 -0
  29. package/dist/formPresentation/index.js +8 -0
  30. package/dist/formPresentation/meta.d.ts +18 -0
  31. package/dist/formPresentation/meta.js +88 -0
  32. package/dist/formPresentation/useStackedLayout.d.ts +1 -0
  33. package/dist/formPresentation/useStackedLayout.js +9 -0
  34. package/dist/input/index.d.ts +8 -0
  35. package/dist/input/index.js +6 -0
  36. package/dist/input/input.d.ts +19 -0
  37. package/dist/input/input.js +14 -0
  38. package/dist/input/inputGroup.d.ts +29 -0
  39. package/dist/input/inputGroup.js +167 -0
  40. package/dist/input/inputStyles.d.ts +13 -0
  41. package/dist/input/inputStyles.js +52 -0
  42. package/dist/input/numberDragInput.d.ts +20 -0
  43. package/dist/input/numberDragInput.js +97 -0
  44. package/dist/input/numberInput.d.ts +10 -0
  45. package/dist/input/numberInput.js +94 -0
  46. package/dist/input/otpInput.d.ts +28 -0
  47. package/dist/input/otpInput.js +81 -0
  48. package/dist/input/useAutosizeInput.d.ts +17 -0
  49. package/dist/input/useAutosizeInput.js +56 -0
  50. package/dist/layout/styles.d.ts +1 -1
  51. package/dist/menu/controlContext.d.ts +32 -0
  52. package/dist/menu/controlContext.js +7 -0
  53. package/dist/menu/dropdownButton.d.ts +18 -0
  54. package/dist/menu/dropdownButton.js +66 -0
  55. package/dist/menu/index.d.ts +7 -0
  56. package/dist/menu/index.js +3 -0
  57. package/dist/menu/menu.d.ts +159 -0
  58. package/dist/menu/menu.js +464 -0
  59. package/dist/menu/selectTypes.d.ts +96 -0
  60. package/dist/menu/selectTypes.js +0 -0
  61. package/dist/menu/selectValue.d.ts +13 -0
  62. package/dist/menu/selectValue.js +0 -0
  63. package/dist/overlayPositioning.d.ts +10 -1
  64. package/dist/overlayPositioning.js +15 -2
  65. package/dist/overlayTrigger.d.ts +22 -0
  66. package/dist/overlayTrigger.js +30 -0
  67. package/dist/slot/knownContexts.d.ts +1 -1
  68. package/dist/spinner/index.d.ts +1 -0
  69. package/dist/spinner/index.js +1 -0
  70. package/dist/spinner/spinner.d.ts +14 -0
  71. package/dist/spinner/spinner.js +126 -0
  72. package/dist/splitPanel/index.d.ts +1 -0
  73. package/dist/splitPanel/index.js +1 -0
  74. package/dist/splitPanel/splitPanel.d.ts +36 -0
  75. package/dist/splitPanel/splitPanel.js +144 -0
  76. package/dist/table/index.d.ts +3 -0
  77. package/dist/table/index.js +3 -0
  78. package/dist/table/sortableHeaderCell.d.ts +36 -0
  79. package/dist/table/sortableHeaderCell.js +99 -0
  80. package/dist/table/styles.d.ts +46 -0
  81. package/dist/table/styles.js +93 -0
  82. package/dist/table/table.d.ts +64 -0
  83. package/dist/table/table.js +228 -0
  84. package/dist/table/useColumnResize.d.ts +27 -0
  85. package/dist/table/useColumnResize.js +62 -0
  86. package/dist/table/useObservedColumnSize.d.ts +12 -0
  87. package/dist/table/useObservedColumnSize.js +74 -0
  88. package/dist/text/heading.d.ts +1 -1
  89. package/dist/text/text.d.ts +7 -0
  90. package/dist/text/text.js +1 -1
  91. package/dist/textarea/index.d.ts +1 -0
  92. package/dist/textarea/index.js +1 -0
  93. package/dist/textarea/textarea.d.ts +22 -0
  94. package/dist/textarea/textarea.js +77 -0
  95. package/dist/toast/index.d.ts +5 -0
  96. package/dist/toast/index.js +4 -0
  97. package/dist/toast/toast.d.ts +10 -0
  98. package/dist/toast/toast.js +182 -0
  99. package/dist/toast/toastApi.d.ts +10 -0
  100. package/dist/toast/toastApi.js +53 -0
  101. package/dist/toast/toaster.d.ts +4 -0
  102. package/dist/toast/toaster.js +42 -0
  103. package/dist/toast/types.d.ts +17 -0
  104. package/dist/toast/types.js +2 -0
  105. package/dist/toggleCard/index.d.ts +1 -0
  106. package/dist/toggleCard/index.js +1 -0
  107. package/dist/toggleCard/toggleCard.d.ts +32 -0
  108. package/dist/toggleCard/toggleCard.js +301 -0
  109. package/dist/useDimensions.d.ts +12 -0
  110. package/dist/useDimensions.js +31 -0
  111. package/dist/useOverlay.js +2 -1
  112. package/dist/useResizableDrawer.d.ts +72 -0
  113. package/dist/useResizableDrawer.js +136 -0
  114. package/package.json +60 -1
@@ -0,0 +1,301 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { useCallback, useId } from "react";
3
+ import { css } from "@emotion/react";
4
+ import styled from "@emotion/styled";
5
+ import { IconCheckmark } from "@sentry/icons/checkmark";
6
+ import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
7
+ import { Container, Flex, Stack } from "../layout/index.js";
8
+ function ToggleCardRoot(props) {
9
+ const { ref, children, className, style, disabled, autoFocus, padding = 'xl' } = props;
10
+ const detailsId = useId();
11
+ const reducedMotion = useReducedMotion();
12
+ const setRef = useCallback((element)=>{
13
+ if ('function' == typeof ref) return ref(element);
14
+ if (ref) ref.current = element;
15
+ }, [
16
+ ref
17
+ ]);
18
+ if ('button' === props.variant) {
19
+ const { variant, onClick, checked: _checked, details: _details, ref: _ref, padding: _padding, className: _className, style: _style, ...buttonProps } = props;
20
+ return /*#__PURE__*/ jsx(Surface, {
21
+ ref: setRef,
22
+ className: className,
23
+ style: style,
24
+ "data-variant": variant,
25
+ "aria-disabled": disabled || void 0,
26
+ children: /*#__PURE__*/ jsx(Stack, {
27
+ height: "100%",
28
+ "data-toggle-card-face": true,
29
+ children: /*#__PURE__*/ jsx(ButtonTrigger, {
30
+ ...buttonProps,
31
+ type: "button",
32
+ disabled: void 0,
33
+ "aria-disabled": disabled || void 0,
34
+ autoFocus: autoFocus,
35
+ "data-toggle-card-trigger": true,
36
+ onClick: (event)=>{
37
+ if (disabled) event.preventDefault();
38
+ else onClick?.(event);
39
+ },
40
+ children: /*#__PURE__*/ jsx(Container, {
41
+ height: "100%",
42
+ padding: padding,
43
+ children: children
44
+ })
45
+ })
46
+ })
47
+ });
48
+ }
49
+ const { variant, checked, onChange, details, name, value, required, id, tabIndex, disabled: _disabled, autoFocus: _autoFocus, ref: _ref, children: _children, padding: _padding, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, "aria-description": ariaDescription, 'aria-invalid': ariaInvalid, 'aria-errormessage': ariaErrorMessage, ...surfaceProps } = props;
50
+ return /*#__PURE__*/ jsx(Surface, {
51
+ ...surfaceProps,
52
+ ref: setRef,
53
+ className: className,
54
+ style: style,
55
+ "aria-disabled": disabled || void 0,
56
+ "data-checked": checked,
57
+ "data-variant": variant,
58
+ children: /*#__PURE__*/ jsxs(Stack, {
59
+ height: "100%",
60
+ "data-toggle-card-face": true,
61
+ children: [
62
+ /*#__PURE__*/ jsxs(LabelTrigger, {
63
+ children: [
64
+ /*#__PURE__*/ jsx(SelectionInput, {
65
+ id: id,
66
+ tabIndex: tabIndex,
67
+ type: variant,
68
+ name: disabled ? void 0 : name,
69
+ value: value,
70
+ checked: checked,
71
+ required: disabled ? void 0 : required,
72
+ autoFocus: autoFocus,
73
+ "aria-label": ariaLabel,
74
+ "aria-labelledby": ariaLabelledBy,
75
+ "aria-describedby": ariaDescribedBy,
76
+ "aria-description": ariaDescription,
77
+ "aria-invalid": ariaInvalid,
78
+ "aria-errormessage": ariaErrorMessage,
79
+ "aria-disabled": disabled || void 0,
80
+ "aria-controls": checked && details ? detailsId : void 0,
81
+ "data-toggle-card-input": true,
82
+ onClickCapture: (event)=>{
83
+ if (disabled) {
84
+ event.preventDefault();
85
+ event.stopPropagation();
86
+ }
87
+ },
88
+ onChange: (event)=>{
89
+ if (!disabled) onChange(event);
90
+ }
91
+ }),
92
+ /*#__PURE__*/ jsx(Container, {
93
+ height: "100%",
94
+ padding: padding,
95
+ children: children
96
+ })
97
+ ]
98
+ }),
99
+ /*#__PURE__*/ jsx(AnimatePresence, {
100
+ initial: false,
101
+ children: checked && details && /*#__PURE__*/ jsx(motion.div, {
102
+ id: detailsId,
103
+ initial: {
104
+ height: 0,
105
+ opacity: 0,
106
+ overflow: 'hidden'
107
+ },
108
+ animate: {
109
+ height: 'auto',
110
+ opacity: 1,
111
+ overflow: 'hidden',
112
+ transitionEnd: {
113
+ overflow: 'visible'
114
+ }
115
+ },
116
+ exit: {
117
+ height: 0,
118
+ opacity: 0,
119
+ overflow: 'hidden'
120
+ },
121
+ transition: {
122
+ duration: reducedMotion ? 0 : 0.2,
123
+ ease: 'easeOut'
124
+ },
125
+ children: /*#__PURE__*/ jsx(Container, {
126
+ padding: padding,
127
+ paddingTop: "0",
128
+ children: details
129
+ })
130
+ }, "details")
131
+ })
132
+ ]
133
+ })
134
+ });
135
+ }
136
+ function ToggleCardIndicator() {
137
+ return /*#__PURE__*/ jsx(Indicator, {
138
+ as: "span",
139
+ align: "center",
140
+ justify: "center",
141
+ width: "20px",
142
+ height: "20px",
143
+ flexShrink: 0,
144
+ "aria-hidden": true,
145
+ pointerEvents: "none",
146
+ children: /*#__PURE__*/ jsx(IconCheckmark, {
147
+ size: "xs"
148
+ })
149
+ });
150
+ }
151
+ const ToggleCard = Object.assign(ToggleCardRoot, {
152
+ Indicator: ToggleCardIndicator
153
+ });
154
+ const Surface = styled('div')`
155
+ --card-lift: 2px;
156
+ --card-chonk: ${(p)=>p.theme.tokens.interactive.chonky.embossed.neutral.chonk};
157
+ --card-indicator-radius: ${(p)=>p.theme.radius.full};
158
+ --card-indicator-background: ${(p)=>p.theme.tokens.background.primary};
159
+ --card-indicator-border: ${(p)=>p.theme.tokens.border.primary};
160
+ --card-radio-dot: 0;
161
+ --card-checkbox-mark: 0;
162
+ position: relative;
163
+ width: 100%;
164
+ height: 100%;
165
+ border-radius: ${(p)=>p.theme.radius.md};
166
+ color: ${(p)=>p.theme.tokens.content.primary};
167
+ cursor: pointer;
168
+
169
+ &::before,
170
+ &::after {
171
+ content: '';
172
+ position: absolute;
173
+ inset: 0;
174
+ border-radius: inherit;
175
+ }
176
+ &::before {
177
+ background: var(--card-chonk);
178
+ }
179
+ &::after {
180
+ background: ${(p)=>p.theme.tokens.interactive.chonky.embossed.neutral.background};
181
+ border: 1px solid ${(p)=>p.theme.tokens.border.primary};
182
+ }
183
+ &::after,
184
+ > [data-toggle-card-face] {
185
+ transform: translateY(calc(-1 * var(--card-lift)));
186
+ transition: transform ${(p)=>p.theme.motion.snap.fast};
187
+ }
188
+ > [data-toggle-card-face] {
189
+ position: relative;
190
+ z-index: 1;
191
+ border-radius: inherit;
192
+ }
193
+ &[data-variant='checkbox'] {
194
+ --card-indicator-radius: ${(p)=>p.theme.radius.xs};
195
+ }
196
+ &:hover:not([aria-disabled='true']):not([data-checked='true']) {
197
+ --card-lift: 3px;
198
+ }
199
+ &:active,
200
+ &[data-checked='true'],
201
+ &[aria-disabled='true'] {
202
+ --card-lift: 0px;
203
+ }
204
+ &[data-checked='true'] {
205
+ --card-chonk: ${(p)=>p.theme.tokens.interactive.chonky.embossed.accent.chonk};
206
+ --card-indicator-background: ${(p)=>p.theme.tokens.interactive.chonky.debossed.accent.background};
207
+ --card-indicator-border: ${(p)=>p.theme.tokens.interactive.chonky.debossed.accent.chonk};
208
+ &::after {
209
+ border-color: ${(p)=>p.theme.tokens.border.accent.vibrant};
210
+ background-image: linear-gradient(
211
+ ${(p)=>p.theme.tokens.interactive.transparent.accent.selected.background.rest},
212
+ ${(p)=>p.theme.tokens.interactive.transparent.accent.selected.background.rest}
213
+ );
214
+ }
215
+ }
216
+ &[data-checked='true'][data-variant='radio'] {
217
+ --card-radio-dot: 1;
218
+ }
219
+ &[data-checked='true'][data-variant='checkbox'] {
220
+ --card-checkbox-mark: 1;
221
+ }
222
+ &[data-checked='true'][data-variant='checkbox']:hover:not(
223
+ [aria-disabled='true']
224
+ )::after {
225
+ background-image: linear-gradient(
226
+ ${(p)=>p.theme.tokens.interactive.transparent.accent.selected.background.hover},
227
+ ${(p)=>p.theme.tokens.interactive.transparent.accent.selected.background.hover}
228
+ );
229
+ }
230
+ &:has([data-toggle-card-input]:focus-visible),
231
+ &:has([data-toggle-card-trigger]:focus-visible) {
232
+ &::after {
233
+ box-shadow:
234
+ 0 var(--card-lift) 0 0 var(--card-chonk),
235
+ 0 var(--card-lift) 0 2px ${(p)=>p.theme.tokens.focus.default},
236
+ 0 0 0 2px ${(p)=>p.theme.tokens.focus.default};
237
+ }
238
+ }
239
+ &[aria-disabled='true'] {
240
+ cursor: not-allowed;
241
+ }
242
+ &[aria-disabled='true']:not([data-checked='true']) {
243
+ opacity: ${(p)=>p.theme.tokens.interactive.disabled};
244
+ }
245
+ @media (prefers-reduced-motion: reduce) {
246
+ &::after,
247
+ > [data-toggle-card-face] {
248
+ transition: none;
249
+ }
250
+ }
251
+ `;
252
+ const triggerStyles = ({ theme })=>css`
253
+ appearance: none;
254
+ display: block;
255
+ flex: 1;
256
+ width: 100%;
257
+ margin: 0;
258
+ padding: 0;
259
+ border: 0;
260
+ background: transparent;
261
+ color: inherit;
262
+ font: inherit;
263
+ font-weight: ${theme.font.weight.sans.regular};
264
+ text-align: left;
265
+ cursor: inherit;
266
+ outline: none;
267
+ `;
268
+ const LabelTrigger = styled('label')`
269
+ ${triggerStyles}
270
+ position: relative;
271
+ `;
272
+ const ButtonTrigger = styled('button')(triggerStyles);
273
+ const SelectionInput = styled('input')`
274
+ position: absolute;
275
+ inset: 0;
276
+ width: 100%;
277
+ height: 100%;
278
+ margin: 0;
279
+ opacity: 0;
280
+ cursor: inherit;
281
+ `;
282
+ const Indicator = styled(Flex)`
283
+ position: relative;
284
+ border: 1px solid var(--card-indicator-border);
285
+ background: var(--card-indicator-background);
286
+ border-radius: var(--card-indicator-radius);
287
+ color: ${(p)=>p.theme.tokens.content.onVibrant.light};
288
+ > svg {
289
+ opacity: var(--card-checkbox-mark);
290
+ }
291
+ &::after {
292
+ content: '';
293
+ position: absolute;
294
+ width: 10px;
295
+ height: 10px;
296
+ border-radius: ${(p)=>p.theme.radius.full};
297
+ background: currentColor;
298
+ opacity: var(--card-radio-dot);
299
+ }
300
+ `;
301
+ export { ToggleCard };
@@ -0,0 +1,12 @@
1
+ import type { RefObject } from 'react';
2
+ interface Props {
3
+ elementRef: RefObject<Element | null>;
4
+ }
5
+ /**
6
+ * Returns a ref to be added to an element and returns the dimensions of that element
7
+ */
8
+ export declare function useDimensions({ elementRef }: Props): {
9
+ height: number;
10
+ width: number;
11
+ };
12
+ export {};
@@ -0,0 +1,31 @@
1
+ import { useCallback, useLayoutEffect, useState } from "react";
2
+ import { useResizeObserver } from "@react-aria/utils";
3
+ function useDimensions({ elementRef }) {
4
+ const [dimensions, setDimensions] = useState({
5
+ height: 0,
6
+ width: 0
7
+ });
8
+ const element = elementRef.current;
9
+ useLayoutEffect(()=>{
10
+ setDimensions({
11
+ height: element?.clientHeight || 0,
12
+ width: element?.clientWidth || 0
13
+ });
14
+ }, [
15
+ element
16
+ ]);
17
+ const onResize = useCallback(()=>{
18
+ setDimensions({
19
+ height: element?.clientHeight || 0,
20
+ width: element?.clientWidth || 0
21
+ });
22
+ }, [
23
+ element
24
+ ]);
25
+ useResizeObserver({
26
+ ref: elementRef,
27
+ onResize
28
+ });
29
+ return dimensions;
30
+ }
31
+ export { useDimensions };
@@ -4,7 +4,7 @@ import { useButton } from "@react-aria/button";
4
4
  import { useOverlay, useOverlayTrigger } from "@react-aria/overlays";
5
5
  import { mergeProps } from "@react-aria/utils";
6
6
  import { useOverlayTriggerState } from "@react-stately/overlays";
7
- import { anchorOverlay, anchoredStyles, arrowOverlay, placementMiddleware, shiftOverlay } from "./overlayPositioning.js";
7
+ import { anchorOverlay, anchoredStyles, arrowOverlay, overlayPlatform, placementMiddleware, shiftOverlay } from "./overlayPositioning.js";
8
8
  function maxSize(options) {
9
9
  return {
10
10
  name: 'maxSize',
@@ -116,6 +116,7 @@ function useOverlay_useOverlay({ isOpen, onClose, defaultOpen, onOpenChange, typ
116
116
  },
117
117
  middleware,
118
118
  placement: initialPlacement,
119
+ platform: overlayPlatform,
119
120
  strategy,
120
121
  transform: false,
121
122
  whileElementsMounted: openState.isOpen ? autoUpdate : void 0
@@ -0,0 +1,72 @@
1
+ import type * as React from 'react';
2
+ export interface UseResizableDrawerOptions {
3
+ /**
4
+ * When dragging, which direction should be used for the delta
5
+ */
6
+ direction: 'right' | 'left' | 'down' | 'up';
7
+ /**
8
+ * The starting size of the container
9
+ */
10
+ initialSize: number;
11
+ /**
12
+ * The minimum sizes the container may be dragged to
13
+ */
14
+ min: number;
15
+ /**
16
+ * The maximum size the container may be dragged to. Optional — defaults
17
+ * to no upper bound. Only enforced during drag, mirroring `min`.
18
+ */
19
+ max?: number;
20
+ /**
21
+ * Triggered while dragging
22
+ */
23
+ onResize?: (newSize: number, maybeOldSize: number | undefined, userEvent: boolean) => void;
24
+ /**
25
+ * Fires once when a drag completes (on mouseUp). Receives the size at
26
+ * the start and end of the drag.
27
+ */
28
+ onResizeEnd?: (sizes: {
29
+ endSize: number;
30
+ startSize: number;
31
+ }) => void;
32
+ /**
33
+ * The local storage key used to persist the size of the container
34
+ */
35
+ sizeStorageKey?: string;
36
+ }
37
+ /**
38
+ * Hook to support draggable container resizing
39
+ *
40
+ * This only resizes one dimension at a time.
41
+ */
42
+ export declare function useResizableDrawer(options: UseResizableDrawerOptions): {
43
+ /**
44
+ * Indicates the drag handle is held. Useful to apply a styled to your handle
45
+ * that will not be removed if the mouse moves outside of the hitbox of your
46
+ * handle.
47
+ */
48
+ isHeld: boolean;
49
+ /**
50
+ * Apply this to include 'reset' functionality on the drag handle
51
+ */
52
+ onDoubleClick: React.MouseEventHandler<HTMLElement>;
53
+ /**
54
+ * Apply to the drag handle element
55
+ */
56
+ onMouseDown: React.MouseEventHandler<HTMLElement>;
57
+ /**
58
+ * Apply to the drag handle element. Supports touch and pen input.
59
+ */
60
+ onPointerDown: React.PointerEventHandler<HTMLElement>;
61
+ /**
62
+ * Call this function to manually set the size of the drawer.
63
+ */
64
+ setSize: (newSize: number, userEvent?: boolean) => void;
65
+ /**
66
+ * The resulting size of the container axis. Updated while dragging.
67
+ *
68
+ * NOTE: Be careful using this as this as react state updates are not
69
+ * synchronous, you may want to update the element size using onResize instead
70
+ */
71
+ size: number;
72
+ };
@@ -0,0 +1,136 @@
1
+ import { useCallback, useLayoutEffect, useRef, useState } from "react";
2
+ import { setDocumentDragging } from "./dragHandle/index.js";
3
+ function clampSize(value, min, max) {
4
+ return Math.min(max ?? 1 / 0, Math.max(min, value));
5
+ }
6
+ function useResizableDrawer(options) {
7
+ const rafIdRef = useRef(null);
8
+ const currentMouseVectorRaf = useRef(null);
9
+ const [size, setSize] = useState(()=>{
10
+ const storedSize = options.sizeStorageKey ? parseInt(localStorage.getItem(options.sizeStorageKey) ?? '', 10) : void 0;
11
+ return clampSize(storedSize || options.initialSize, options.min, options.max);
12
+ });
13
+ const [isHeld, setIsHeld] = useState(false);
14
+ const optionsRef = useRef(options);
15
+ useLayoutEffect(()=>{
16
+ optionsRef.current = options;
17
+ });
18
+ const updateSize = useCallback((newSize, userEvent = false)=>{
19
+ sizeRef.current = newSize;
20
+ setSize(newSize);
21
+ optionsRef.current.onResize?.(newSize, void 0, userEvent);
22
+ if (optionsRef.current.sizeStorageKey) localStorage.setItem(optionsRef.current.sizeStorageKey, newSize.toString());
23
+ }, []);
24
+ useLayoutEffect(()=>{
25
+ const clamped = clampSize(options.initialSize ?? 0, options.min, options.max);
26
+ options.onResize?.(clamped, size, false);
27
+ setSize(clamped);
28
+ }, [
29
+ options.direction
30
+ ]);
31
+ const sizeRef = useRef(size);
32
+ sizeRef.current = size;
33
+ const onDragMove = useCallback((event)=>{
34
+ event.stopPropagation();
35
+ event.preventDefault();
36
+ const isXAxis = 'left' === options.direction || 'right' === options.direction;
37
+ const isInverted = 'down' === options.direction || 'left' === options.direction;
38
+ setDocumentDragging(isXAxis ? 'ew-resize' : 'ns-resize');
39
+ if (null !== rafIdRef.current) window.cancelAnimationFrame(rafIdRef.current);
40
+ rafIdRef.current = window.requestAnimationFrame(()=>{
41
+ if (!currentMouseVectorRaf.current) return;
42
+ const newPositionVector = [
43
+ event.clientX,
44
+ event.clientY
45
+ ];
46
+ const newAxisPosition = isXAxis ? newPositionVector[0] : newPositionVector[1];
47
+ const currentAxisPosition = isXAxis ? currentMouseVectorRaf.current[0] : currentMouseVectorRaf.current[1];
48
+ const positionDelta = currentAxisPosition - newAxisPosition;
49
+ currentMouseVectorRaf.current = newPositionVector;
50
+ const newSize = Math.round(clampSize(sizeRef.current + positionDelta * (isInverted ? -1 : 1), options.min, options.max));
51
+ updateSize(newSize, true);
52
+ });
53
+ }, [
54
+ options.direction,
55
+ options.min,
56
+ options.max,
57
+ updateSize
58
+ ]);
59
+ const dragStartSizeRef = useRef(null);
60
+ const onDragEnd = useCallback(()=>{
61
+ setDocumentDragging(null);
62
+ document.removeEventListener('mousemove', onDragMove);
63
+ document.removeEventListener('mouseup', onDragEnd);
64
+ document.removeEventListener('pointermove', onDragMove);
65
+ document.removeEventListener('pointerup', onDragEnd);
66
+ document.removeEventListener('pointercancel', onDragEnd);
67
+ setIsHeld(false);
68
+ if (null !== dragStartSizeRef.current) {
69
+ options.onResizeEnd?.({
70
+ startSize: dragStartSizeRef.current,
71
+ endSize: sizeRef.current
72
+ });
73
+ dragStartSizeRef.current = null;
74
+ }
75
+ }, [
76
+ onDragMove,
77
+ options
78
+ ]);
79
+ const startDrag = useCallback((clientX, clientY)=>{
80
+ const { min, max } = optionsRef.current;
81
+ const clamped = clampSize(sizeRef.current, min, max);
82
+ sizeRef.current = clamped;
83
+ setSize(clamped);
84
+ setIsHeld(true);
85
+ dragStartSizeRef.current = clamped;
86
+ currentMouseVectorRaf.current = [
87
+ clientX,
88
+ clientY
89
+ ];
90
+ }, []);
91
+ const onMouseDown = useCallback((evt)=>{
92
+ if (0 !== evt.button) return;
93
+ evt.preventDefault();
94
+ startDrag(evt.clientX, evt.clientY);
95
+ document.addEventListener('mousemove', onDragMove, {
96
+ passive: false
97
+ });
98
+ document.addEventListener('mouseup', onDragEnd);
99
+ }, [
100
+ onDragMove,
101
+ onDragEnd,
102
+ startDrag
103
+ ]);
104
+ const onPointerDown = useCallback((evt)=>{
105
+ if (!evt.isPrimary || 'mouse' === evt.pointerType && 0 !== evt.button) return;
106
+ evt.preventDefault();
107
+ startDrag(evt.clientX, evt.clientY);
108
+ document.addEventListener('pointermove', onDragMove, {
109
+ passive: false
110
+ });
111
+ document.addEventListener('pointerup', onDragEnd);
112
+ document.addEventListener('pointercancel', onDragEnd);
113
+ }, [
114
+ onDragMove,
115
+ onDragEnd,
116
+ startDrag
117
+ ]);
118
+ const onDoubleClick = useCallback(()=>{
119
+ updateSize(options.initialSize, true);
120
+ }, [
121
+ updateSize,
122
+ options.initialSize
123
+ ]);
124
+ useLayoutEffect(()=>()=>{
125
+ if (null !== rafIdRef.current) window.cancelAnimationFrame(rafIdRef.current);
126
+ });
127
+ return {
128
+ size,
129
+ isHeld,
130
+ onMouseDown,
131
+ onPointerDown,
132
+ onDoubleClick,
133
+ setSize: updateSize
134
+ };
135
+ }
136
+ export { useResizableDrawer };