@jobber/components 7.10.0 → 7.11.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 (106) hide show
  1. package/dist/Autocomplete/index.cjs +1 -0
  2. package/dist/Autocomplete/index.mjs +1 -0
  3. package/dist/Card/index.cjs +3 -0
  4. package/dist/Card/index.mjs +3 -0
  5. package/dist/Chip/index.cjs +1 -0
  6. package/dist/Chip/index.mjs +1 -0
  7. package/dist/Chips/InternalChipDismissible/hooks/index.cjs +1 -0
  8. package/dist/Chips/InternalChipDismissible/hooks/index.mjs +1 -0
  9. package/dist/Chips/InternalChipDismissible/index.cjs +1 -0
  10. package/dist/Chips/InternalChipDismissible/index.mjs +1 -0
  11. package/dist/Chips/index.cjs +1 -0
  12. package/dist/Chips/index.mjs +1 -0
  13. package/dist/Combobox/components/ComboboxActivator/index.cjs +1 -0
  14. package/dist/Combobox/components/ComboboxActivator/index.mjs +1 -0
  15. package/dist/Combobox/components/ComboboxContent/index.cjs +1 -0
  16. package/dist/Combobox/components/ComboboxContent/index.mjs +1 -0
  17. package/dist/Combobox/components/ComboboxTrigger/index.cjs +1 -0
  18. package/dist/Combobox/components/ComboboxTrigger/index.mjs +1 -0
  19. package/dist/Combobox/index.cjs +1 -0
  20. package/dist/Combobox/index.mjs +1 -0
  21. package/dist/ConfirmationModal/index.cjs +1 -0
  22. package/dist/ConfirmationModal/index.mjs +1 -0
  23. package/dist/DataDump/index.cjs +3 -0
  24. package/dist/DataDump/index.mjs +3 -0
  25. package/dist/DataList/components/DataListActions/index.cjs +1 -0
  26. package/dist/DataList/components/DataListActions/index.mjs +1 -0
  27. package/dist/DataList/components/DataListBulkActions/index.cjs +1 -0
  28. package/dist/DataList/components/DataListBulkActions/index.mjs +1 -0
  29. package/dist/DataList/components/DataListFilters/components/DataListSort/index.cjs +1 -0
  30. package/dist/DataList/components/DataListFilters/components/DataListSort/index.mjs +1 -0
  31. package/dist/DataList/components/DataListFilters/index.cjs +1 -0
  32. package/dist/DataList/components/DataListFilters/index.mjs +1 -0
  33. package/dist/DataList/components/DataListHeader/index.cjs +1 -0
  34. package/dist/DataList/components/DataListHeader/index.mjs +1 -0
  35. package/dist/DataList/components/DataListItem/index.cjs +1 -0
  36. package/dist/DataList/components/DataListItem/index.mjs +1 -0
  37. package/dist/DataList/components/DataListItemActions/index.cjs +1 -0
  38. package/dist/DataList/components/DataListItemActions/index.mjs +1 -0
  39. package/dist/DataList/components/DataListItemActionsOverflow/index.cjs +1 -0
  40. package/dist/DataList/components/DataListItemActionsOverflow/index.mjs +1 -0
  41. package/dist/DataList/components/DataListItems/index.cjs +1 -0
  42. package/dist/DataList/components/DataListItems/index.mjs +1 -0
  43. package/dist/DataList/components/DataListLayout/index.cjs +1 -0
  44. package/dist/DataList/components/DataListLayout/index.mjs +1 -0
  45. package/dist/DataList/components/DataListLayoutActions/index.cjs +1 -0
  46. package/dist/DataList/components/DataListLayoutActions/index.mjs +1 -0
  47. package/dist/DataList/index.cjs +1 -0
  48. package/dist/DataList/index.mjs +1 -0
  49. package/dist/DatePicker/index.cjs +1 -0
  50. package/dist/DatePicker/index.mjs +1 -0
  51. package/dist/DrawerRoot-cjs.js +181 -968
  52. package/dist/DrawerRoot-es.js +5 -734
  53. package/dist/FormatFile/index.cjs +1 -0
  54. package/dist/FormatFile/index.mjs +1 -0
  55. package/dist/Gallery/index.cjs +1 -0
  56. package/dist/Gallery/index.mjs +1 -0
  57. package/dist/InputDate/index.cjs +1 -0
  58. package/dist/InputDate/index.mjs +1 -0
  59. package/dist/InputNumberExperimental-cjs.js +783 -0
  60. package/dist/InputNumberExperimental-es.js +763 -0
  61. package/dist/LightBox/index.cjs +1 -0
  62. package/dist/LightBox/index.mjs +1 -0
  63. package/dist/Menu/index.cjs +3 -0
  64. package/dist/Menu/index.mjs +3 -0
  65. package/dist/MenuSubmenuTrigger-cjs.js +202 -447
  66. package/dist/MenuSubmenuTrigger-es.js +7 -249
  67. package/dist/Modal/index.cjs +1 -0
  68. package/dist/Modal/index.mjs +1 -0
  69. package/dist/NumberFieldInput-cjs.js +1828 -0
  70. package/dist/NumberFieldInput-es.js +1788 -0
  71. package/dist/Page/index.cjs +3 -0
  72. package/dist/Page/index.mjs +3 -0
  73. package/dist/Popover/index.cjs +1 -0
  74. package/dist/Popover/index.mjs +1 -0
  75. package/dist/Tooltip/index.cjs +1 -0
  76. package/dist/Tooltip/index.mjs +1 -0
  77. package/dist/docs/Menu/Menu.md +197 -37
  78. package/dist/floating-ui.react-cjs.js +35 -34
  79. package/dist/floating-ui.react-dom-cjs.js +65 -64
  80. package/dist/floating-ui.react-dom-es.js +2 -1
  81. package/dist/floating-ui.react-es.js +2 -1
  82. package/dist/floating-ui.utils.dom-cjs.js +185 -0
  83. package/dist/floating-ui.utils.dom-es.js +165 -0
  84. package/dist/index.cjs +3 -0
  85. package/dist/index.esm-cjs.js +0 -183
  86. package/dist/index.esm-es.js +1 -165
  87. package/dist/index.mjs +3 -0
  88. package/dist/primitives/BottomSheet/index.cjs +3 -1
  89. package/dist/primitives/BottomSheet/index.mjs +3 -1
  90. package/dist/primitives/InputNumberExperimental/InputNumberExperimental.d.ts +20 -0
  91. package/dist/primitives/InputNumberExperimental/index.cjs +22 -0
  92. package/dist/primitives/InputNumberExperimental/index.d.ts +2 -0
  93. package/dist/primitives/InputNumberExperimental/index.mjs +16 -0
  94. package/dist/primitives/InputNumberExperimental/types.d.ts +147 -0
  95. package/dist/primitives/index.cjs +9 -1
  96. package/dist/primitives/index.d.ts +2 -0
  97. package/dist/primitives/index.mjs +8 -1
  98. package/dist/styles.css +499 -0
  99. package/dist/unstyledPrimitives/index.cjs +264 -2039
  100. package/dist/unstyledPrimitives/index.mjs +72 -1847
  101. package/dist/useBaseUiId-cjs.js +275 -0
  102. package/dist/useBaseUiId-es.js +251 -0
  103. package/dist/useValueChanged-cjs.js +820 -0
  104. package/dist/useValueChanged-es.js +736 -0
  105. package/package.json +2 -2
  106. package/rollup.config.mjs +13 -2
@@ -0,0 +1,820 @@
1
+ 'use strict';
2
+
3
+ var useRenderElement = require('./useRenderElement-cjs.js');
4
+ var React = require('react');
5
+ var ReactDOM = require('react-dom');
6
+
7
+ function _interopNamespaceDefault(e) {
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
25
+ var ReactDOM__namespace = /*#__PURE__*/_interopNamespaceDefault(ReactDOM);
26
+
27
+ let TransitionStatusDataAttributes = /*#__PURE__*/function (TransitionStatusDataAttributes) {
28
+ /**
29
+ * Present when the component is animating in.
30
+ */
31
+ TransitionStatusDataAttributes["startingStyle"] = "data-starting-style";
32
+ /**
33
+ * Present when the component is animating out.
34
+ */
35
+ TransitionStatusDataAttributes["endingStyle"] = "data-ending-style";
36
+ return TransitionStatusDataAttributes;
37
+ }({});
38
+ const STARTING_HOOK = {
39
+ [TransitionStatusDataAttributes.startingStyle]: ''
40
+ };
41
+ const ENDING_HOOK = {
42
+ [TransitionStatusDataAttributes.endingStyle]: ''
43
+ };
44
+ const transitionStatusMapping = {
45
+ transitionStatus(value) {
46
+ if (value === 'starting') {
47
+ return STARTING_HOOK;
48
+ }
49
+ if (value === 'ending') {
50
+ return ENDING_HOOK;
51
+ }
52
+ return null;
53
+ }
54
+ };
55
+
56
+ // https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
57
+ const useInsertionEffect = React__namespace[`useInsertionEffect${Math.random().toFixed(1)}`.slice(0, -3)];
58
+ const useSafeInsertionEffect =
59
+ // React 17 doesn't have useInsertionEffect.
60
+ useInsertionEffect &&
61
+ // Preact replaces useInsertionEffect with useLayoutEffect and fires too late.
62
+ useInsertionEffect !== React__namespace.useLayoutEffect ? useInsertionEffect : fn => fn();
63
+ /**
64
+ * Stabilizes the function passed so it's always the same between renders.
65
+ *
66
+ * The function becomes non-reactive to any values it captures.
67
+ * It can safely be passed as a dependency of `React.useMemo` and `React.useEffect` without re-triggering them if its captured values change.
68
+ *
69
+ * The function must only be called inside effects and event handlers, never during render (which throws an error).
70
+ *
71
+ * This hook is a more permissive version of React 19.2's `React.useEffectEvent` in that it can be passed through contexts and called in event handler props, not just effects.
72
+ */
73
+ function useStableCallback(callback) {
74
+ const stable = useRenderElement.useRefWithInit(createStableCallback).current;
75
+ stable.next = callback;
76
+ useSafeInsertionEffect(stable.effect);
77
+ return stable.trampoline;
78
+ }
79
+ function createStableCallback() {
80
+ const stable = {
81
+ next: undefined,
82
+ callback: assertNotCalled,
83
+ trampoline: (...args) => stable.callback?.(...args),
84
+ effect: () => {
85
+ stable.callback = stable.next;
86
+ }
87
+ };
88
+ return stable;
89
+ }
90
+ function assertNotCalled() {
91
+ if (process.env.NODE_ENV !== 'production') {
92
+ throw /* minify-error-disabled */new Error('Base UI: Cannot call an event handler while rendering.');
93
+ }
94
+ }
95
+
96
+ // https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
97
+ const SafeReact = {
98
+ ...React__namespace
99
+ };
100
+
101
+ const noop = () => {};
102
+ const useIsoLayoutEffect = typeof document !== 'undefined' ? React__namespace.useLayoutEffect : noop;
103
+
104
+ const none = 'none';
105
+ const triggerPress = 'trigger-press';
106
+ const triggerHover = 'trigger-hover';
107
+ const triggerFocus = 'trigger-focus';
108
+ const outsidePress = 'outside-press';
109
+ const itemPress = 'item-press';
110
+ const closePress = 'close-press';
111
+ const clearPress = 'clear-press';
112
+ const chipRemovePress = 'chip-remove-press';
113
+ const incrementPress = 'increment-press';
114
+ const decrementPress = 'decrement-press';
115
+ const inputChange = 'input-change';
116
+ const inputClear = 'input-clear';
117
+ const inputBlur = 'input-blur';
118
+ const inputPaste = 'input-paste';
119
+ const inputPress = 'input-press';
120
+ const focusOut = 'focus-out';
121
+ const escapeKey = 'escape-key';
122
+ const closeWatcher = 'close-watcher';
123
+ const listNavigation = 'list-navigation';
124
+ const keyboard = 'keyboard';
125
+ const scrub = 'scrub';
126
+ const cancelOpen = 'cancel-open';
127
+ const siblingOpen = 'sibling-open';
128
+ const imperativeAction = 'imperative-action';
129
+ const swipe = 'swipe';
130
+
131
+ /**
132
+ * Maps a change `reason` string to the corresponding native event type.
133
+ */
134
+
135
+ /**
136
+ * Details of custom change events emitted by Base UI components.
137
+ */
138
+
139
+ /**
140
+ * Details of custom generic events emitted by Base UI components.
141
+ */
142
+
143
+ /**
144
+ * Creates a Base UI event details object with the given reason and utilities
145
+ * for preventing Base UI's internal event handling.
146
+ */
147
+ function createChangeEventDetails(reason, event, trigger, customProperties) {
148
+ let canceled = false;
149
+ let allowPropagation = false;
150
+ const custom = customProperties ?? useRenderElement.EMPTY_OBJECT;
151
+ const details = {
152
+ reason,
153
+ event: event ?? new Event('base-ui'),
154
+ cancel() {
155
+ canceled = true;
156
+ },
157
+ allowPropagation() {
158
+ allowPropagation = true;
159
+ },
160
+ get isCanceled() {
161
+ return canceled;
162
+ },
163
+ get isPropagationAllowed() {
164
+ return allowPropagation;
165
+ },
166
+ trigger,
167
+ ...custom
168
+ };
169
+ return details;
170
+ }
171
+ function createGenericEventDetails(reason, event, customProperties) {
172
+ const custom = customProperties ?? useRenderElement.EMPTY_OBJECT;
173
+ const details = {
174
+ reason,
175
+ event: event ?? new Event('base-ui'),
176
+ ...custom
177
+ };
178
+ return details;
179
+ }
180
+
181
+ let globalId = 0;
182
+
183
+ // TODO React 17: Remove `useGlobalId` once React 17 support is removed
184
+ function useGlobalId(idOverride, prefix = 'mui') {
185
+ const [defaultId, setDefaultId] = React__namespace.useState(idOverride);
186
+ const id = idOverride || defaultId;
187
+ React__namespace.useEffect(() => {
188
+ if (defaultId == null) {
189
+ // Fallback to this default id when possible.
190
+ // Use the incrementing value for client-side rendering only.
191
+ // We can't use it server-side.
192
+ // If you want to use random values please consider the Birthday Problem: https://en.wikipedia.org/wiki/Birthday_problem
193
+ globalId += 1;
194
+ setDefaultId(`${prefix}-${globalId}`);
195
+ }
196
+ }, [defaultId, prefix]);
197
+ return id;
198
+ }
199
+ const maybeReactUseId = SafeReact.useId;
200
+
201
+ /**
202
+ *
203
+ * @example <div id={useId()} />
204
+ * @param idOverride
205
+ * @returns {string}
206
+ */
207
+ function useId(idOverride, prefix) {
208
+ // React.useId() is only available from React 17.0.0.
209
+ if (maybeReactUseId !== undefined) {
210
+ const reactId = maybeReactUseId();
211
+ return idOverride ?? (prefix ? `${prefix}-${reactId}` : reactId);
212
+ }
213
+
214
+ // TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
215
+ // eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
216
+ return useGlobalId(idOverride, prefix);
217
+ }
218
+
219
+ const EMPTY$2 = [];
220
+
221
+ /**
222
+ * A React.useEffect equivalent that runs once, when the component is mounted.
223
+ */
224
+ function useOnMount(fn) {
225
+ // TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- no need to put `fn` in the dependency array
226
+ /* eslint-disable react-hooks/exhaustive-deps */
227
+ React__namespace.useEffect(fn, EMPTY$2);
228
+ /* eslint-enable react-hooks/exhaustive-deps */
229
+ }
230
+
231
+ const EMPTY$1 = 0;
232
+ class Timeout {
233
+ static create() {
234
+ return new Timeout();
235
+ }
236
+ currentId = EMPTY$1;
237
+
238
+ /**
239
+ * Executes `fn` after `delay`, clearing any previously scheduled call.
240
+ */
241
+ start(delay, fn) {
242
+ this.clear();
243
+ this.currentId = setTimeout(() => {
244
+ this.currentId = EMPTY$1;
245
+ fn();
246
+ }, delay); /* Node.js types are enabled in development */
247
+ }
248
+ isStarted() {
249
+ return this.currentId !== EMPTY$1;
250
+ }
251
+ clear = () => {
252
+ if (this.currentId !== EMPTY$1) {
253
+ clearTimeout(this.currentId);
254
+ this.currentId = EMPTY$1;
255
+ }
256
+ };
257
+ disposeEffect = () => {
258
+ return this.clear;
259
+ };
260
+ }
261
+
262
+ /**
263
+ * A `setTimeout` with automatic cleanup and guard.
264
+ */
265
+ function useTimeout() {
266
+ const timeout = useRenderElement.useRefWithInit(Timeout.create).current;
267
+ useOnMount(timeout.disposeEffect);
268
+ return timeout;
269
+ }
270
+
271
+ const hasNavigator = typeof navigator !== 'undefined';
272
+ const nav = getNavigatorData();
273
+ const platform = getPlatform();
274
+ const userAgent = getUserAgent();
275
+ const isWebKit = typeof CSS === 'undefined' || !CSS.supports ? false : CSS.supports('-webkit-backdrop-filter:none');
276
+ const isIOS =
277
+ // iPads can claim to be MacIntel
278
+ nav.platform === 'MacIntel' && nav.maxTouchPoints > 1 ? true : /iP(hone|ad|od)|iOS/.test(nav.platform);
279
+ const isFirefox = hasNavigator && /firefox/i.test(userAgent);
280
+ const isSafari = hasNavigator && /apple/i.test(navigator.vendor);
281
+ const isAndroid = hasNavigator && /android/i.test(platform) || /android/i.test(userAgent);
282
+ const isMac = hasNavigator && platform.toLowerCase().startsWith('mac') && !navigator.maxTouchPoints;
283
+ const isJSDOM = userAgent.includes('jsdom/');
284
+
285
+ // Avoid Chrome DevTools blue warning.
286
+ function getNavigatorData() {
287
+ if (!hasNavigator) {
288
+ return {
289
+ platform: '',
290
+ maxTouchPoints: -1
291
+ };
292
+ }
293
+ const uaData = navigator.userAgentData;
294
+ if (uaData?.platform) {
295
+ return {
296
+ platform: uaData.platform,
297
+ maxTouchPoints: navigator.maxTouchPoints
298
+ };
299
+ }
300
+ return {
301
+ platform: navigator.platform ?? '',
302
+ maxTouchPoints: navigator.maxTouchPoints ?? -1
303
+ };
304
+ }
305
+ function getUserAgent() {
306
+ if (!hasNavigator) {
307
+ return '';
308
+ }
309
+ const uaData = navigator.userAgentData;
310
+ if (uaData && Array.isArray(uaData.brands)) {
311
+ return uaData.brands.map(({
312
+ brand,
313
+ version
314
+ }) => `${brand}/${version}`).join(' ');
315
+ }
316
+ return navigator.userAgent;
317
+ }
318
+ function getPlatform() {
319
+ if (!hasNavigator) {
320
+ return '';
321
+ }
322
+ const uaData = navigator.userAgentData;
323
+ if (uaData?.platform) {
324
+ return uaData.platform;
325
+ }
326
+ return navigator.platform ?? '';
327
+ }
328
+
329
+ function stopEvent(event) {
330
+ event.preventDefault();
331
+ event.stopPropagation();
332
+ }
333
+ function isReactEvent(event) {
334
+ return 'nativeEvent' in event;
335
+ }
336
+
337
+ // License: https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/utils/src/isVirtualEvent.ts
338
+ function isVirtualClick(event) {
339
+ if (event.pointerType === '' && event.isTrusted) {
340
+ return true;
341
+ }
342
+ if (isAndroid && event.pointerType) {
343
+ return event.type === 'click' && event.buttons === 1;
344
+ }
345
+ return event.detail === 0 && !event.pointerType;
346
+ }
347
+ function isVirtualPointerEvent(event) {
348
+ if (isJSDOM) {
349
+ return false;
350
+ }
351
+ return !isAndroid && event.width === 0 && event.height === 0 || isAndroid && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse' ||
352
+ // iOS VoiceOver returns 0.333• for width/height.
353
+ event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'touch';
354
+ }
355
+ function isMouseLikePointerType(pointerType, strict) {
356
+ // On some Linux machines with Chromium, mouse inputs return a `pointerType`
357
+ // of "pen": https://github.com/floating-ui/floating-ui/issues/2015
358
+ const values = ['mouse', 'pen'];
359
+ if (!strict) {
360
+ values.push('', undefined);
361
+ }
362
+ return values.includes(pointerType);
363
+ }
364
+ function isClickLikeEvent(event) {
365
+ const type = event.type;
366
+ return type === 'click' || type === 'mousedown' || type === 'keydown' || type === 'keyup';
367
+ }
368
+
369
+ function ownerDocument(node) {
370
+ return node?.ownerDocument || document;
371
+ }
372
+
373
+ /**
374
+ * Untracks the provided value by turning it into a ref to remove its reactivity.
375
+ *
376
+ * Used to access the passed value inside `React.useEffect` without causing the effect to re-run when the value changes.
377
+ */
378
+ function useValueAsRef(value) {
379
+ const latest = useRenderElement.useRefWithInit(createLatestRef, value).current;
380
+ latest.next = value;
381
+
382
+ // eslint-disable-next-line react-hooks/exhaustive-deps
383
+ useIsoLayoutEffect(latest.effect);
384
+ return latest;
385
+ }
386
+ function createLatestRef(value) {
387
+ const latest = {
388
+ current: value,
389
+ next: value,
390
+ effect: () => {
391
+ latest.current = latest.next;
392
+ }
393
+ };
394
+ return latest;
395
+ }
396
+
397
+ /** Unlike `setTimeout`, rAF doesn't guarantee a positive integer return value, so we can't have
398
+ * a monomorphic `uint` type with `0` meaning empty.
399
+ * See warning note at:
400
+ * https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame#return_value */
401
+ const EMPTY = null;
402
+ let LAST_RAF = globalThis.requestAnimationFrame;
403
+ class Scheduler {
404
+ /* This implementation uses an array as a backing data-structure for frame callbacks.
405
+ * It allows `O(1)` callback cancelling by inserting a `null` in the array, though it
406
+ * never calls the native `cancelAnimationFrame` if there are no frames left. This can
407
+ * be much more efficient if there is a call pattern that alterns as
408
+ * "request-cancel-request-cancel-…".
409
+ * But in the case of "request-request-…-cancel-cancel-…", it leaves the final animation
410
+ * frame to run anyway. We turn that frame into a `O(1)` no-op via `callbacksCount`. */
411
+
412
+ callbacks = [];
413
+ callbacksCount = 0;
414
+ nextId = 1;
415
+ startId = 1;
416
+ isScheduled = false;
417
+ tick = timestamp => {
418
+ this.isScheduled = false;
419
+ const currentCallbacks = this.callbacks;
420
+ const currentCallbacksCount = this.callbacksCount;
421
+
422
+ // Update these before iterating, callbacks could call `requestAnimationFrame` again.
423
+ this.callbacks = [];
424
+ this.callbacksCount = 0;
425
+ this.startId = this.nextId;
426
+ if (currentCallbacksCount > 0) {
427
+ for (let i = 0; i < currentCallbacks.length; i += 1) {
428
+ currentCallbacks[i]?.(timestamp);
429
+ }
430
+ }
431
+ };
432
+ request(fn) {
433
+ const id = this.nextId;
434
+ this.nextId += 1;
435
+ this.callbacks.push(fn);
436
+ this.callbacksCount += 1;
437
+
438
+ /* In a test environment with fake timers, a fake `requestAnimationFrame` can be called
439
+ * but there's no guarantee that the animation frame will actually run before the fake
440
+ * timers are teared, which leaves `isScheduled` set, but won't run our `tick()`. */
441
+ const didRAFChange = process.env.NODE_ENV !== 'production' && LAST_RAF !== requestAnimationFrame && (LAST_RAF = requestAnimationFrame, true);
442
+ if (!this.isScheduled || didRAFChange) {
443
+ requestAnimationFrame(this.tick);
444
+ this.isScheduled = true;
445
+ }
446
+ return id;
447
+ }
448
+ cancel(id) {
449
+ const index = id - this.startId;
450
+ if (index < 0 || index >= this.callbacks.length) {
451
+ return;
452
+ }
453
+ this.callbacks[index] = null;
454
+ this.callbacksCount -= 1;
455
+ }
456
+ }
457
+ const scheduler = new Scheduler();
458
+ class AnimationFrame {
459
+ static create() {
460
+ return new AnimationFrame();
461
+ }
462
+ static request(fn) {
463
+ return scheduler.request(fn);
464
+ }
465
+ static cancel(id) {
466
+ return scheduler.cancel(id);
467
+ }
468
+ currentId = EMPTY;
469
+
470
+ /**
471
+ * Executes `fn` after `delay`, clearing any previously scheduled call.
472
+ */
473
+ request(fn) {
474
+ this.cancel();
475
+ this.currentId = scheduler.request(() => {
476
+ this.currentId = EMPTY;
477
+ fn();
478
+ });
479
+ }
480
+ cancel = () => {
481
+ if (this.currentId !== EMPTY) {
482
+ scheduler.cancel(this.currentId);
483
+ this.currentId = EMPTY;
484
+ }
485
+ };
486
+ disposeEffect = () => {
487
+ return this.cancel;
488
+ };
489
+ }
490
+
491
+ /**
492
+ * A `requestAnimationFrame` with automatic cleanup and guard.
493
+ */
494
+ function useAnimationFrame() {
495
+ const timeout = useRenderElement.useRefWithInit(AnimationFrame.create).current;
496
+ useOnMount(timeout.disposeEffect);
497
+ return timeout;
498
+ }
499
+
500
+ const visuallyHiddenBase = {
501
+ clipPath: 'inset(50%)',
502
+ overflow: 'hidden',
503
+ whiteSpace: 'nowrap',
504
+ border: 0,
505
+ padding: 0,
506
+ width: 1,
507
+ height: 1,
508
+ margin: -1
509
+ };
510
+ const visuallyHidden = {
511
+ ...visuallyHiddenBase,
512
+ position: 'fixed',
513
+ top: 0,
514
+ left: 0
515
+ };
516
+ const visuallyHiddenInput = {
517
+ ...visuallyHiddenBase,
518
+ position: 'absolute'
519
+ };
520
+
521
+ /**
522
+ * If the provided argument is a ref object, returns its `current` value.
523
+ * Otherwise, returns the argument itself.
524
+ */
525
+ function resolveRef(maybeRef) {
526
+ if (maybeRef == null) {
527
+ return maybeRef;
528
+ }
529
+ return 'current' in maybeRef ? maybeRef.current : maybeRef;
530
+ }
531
+
532
+ /**
533
+ * Provides a status string for CSS animations.
534
+ * @param open - a boolean that determines if the element is open.
535
+ * @param enableIdleState - a boolean that enables the `'idle'` state between `'starting'` and `'ending'`
536
+ */
537
+ function useTransitionStatus(open, enableIdleState = false, deferEndingState = false) {
538
+ const [transitionStatus, setTransitionStatus] = React__namespace.useState(open && enableIdleState ? 'idle' : undefined);
539
+ const [mounted, setMounted] = React__namespace.useState(open);
540
+ if (open && !mounted) {
541
+ setMounted(true);
542
+ setTransitionStatus('starting');
543
+ }
544
+ if (!open && mounted && transitionStatus !== 'ending' && !deferEndingState) {
545
+ setTransitionStatus('ending');
546
+ }
547
+ if (!open && !mounted && transitionStatus === 'ending') {
548
+ setTransitionStatus(undefined);
549
+ }
550
+ useIsoLayoutEffect(() => {
551
+ if (!open && mounted && transitionStatus !== 'ending' && deferEndingState) {
552
+ const frame = AnimationFrame.request(() => {
553
+ setTransitionStatus('ending');
554
+ });
555
+ return () => {
556
+ AnimationFrame.cancel(frame);
557
+ };
558
+ }
559
+ return undefined;
560
+ }, [open, mounted, transitionStatus, deferEndingState]);
561
+ useIsoLayoutEffect(() => {
562
+ if (!open || enableIdleState) {
563
+ return undefined;
564
+ }
565
+ const frame = AnimationFrame.request(() => {
566
+ // Avoid `flushSync` here due to Firefox.
567
+ // See https://github.com/mui/base-ui/pull/3424
568
+ setTransitionStatus(undefined);
569
+ });
570
+ return () => {
571
+ AnimationFrame.cancel(frame);
572
+ };
573
+ }, [enableIdleState, open]);
574
+ useIsoLayoutEffect(() => {
575
+ if (!open || !enableIdleState) {
576
+ return undefined;
577
+ }
578
+ if (open && mounted && transitionStatus !== 'idle') {
579
+ setTransitionStatus('starting');
580
+ }
581
+ const frame = AnimationFrame.request(() => {
582
+ setTransitionStatus('idle');
583
+ });
584
+ return () => {
585
+ AnimationFrame.cancel(frame);
586
+ };
587
+ }, [enableIdleState, open, mounted, setTransitionStatus, transitionStatus]);
588
+ return React__namespace.useMemo(() => ({
589
+ mounted,
590
+ setMounted,
591
+ transitionStatus
592
+ }), [mounted, transitionStatus]);
593
+ }
594
+
595
+ /**
596
+ * Executes a function once all animations have finished on the provided element.
597
+ * @param elementOrRef - The element to watch for animations.
598
+ * @param waitForStartingStyleRemoved - Whether to wait for [data-starting-style] to be removed before checking for animations.
599
+ * @param treatAbortedAsFinished - Whether to treat aborted animations as finished. If `false`, and there are aborted animations,
600
+ * the function will check again if any new animations have started and wait for them to finish.
601
+ * @returns A function that takes a callback to execute once all animations have finished, and an optional AbortSignal to abort the callback
602
+ */
603
+ function useAnimationsFinished(elementOrRef, waitForStartingStyleRemoved = false, treatAbortedAsFinished = true) {
604
+ const frame = useAnimationFrame();
605
+ return useStableCallback((fnToExecute,
606
+ /**
607
+ * An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that
608
+ * can be used to abort `fnToExecute` before all the animations have finished.
609
+ * @default null
610
+ */
611
+ signal = null) => {
612
+ frame.cancel();
613
+ function done() {
614
+ // Synchronously flush the unmounting of the component so that the browser doesn't
615
+ // paint: https://github.com/mui/base-ui/issues/979
616
+ ReactDOM__namespace.flushSync(fnToExecute);
617
+ }
618
+ const element = resolveRef(elementOrRef);
619
+ if (element == null) {
620
+ return;
621
+ }
622
+ const resolvedElement = element;
623
+ if (typeof resolvedElement.getAnimations !== 'function' || globalThis.BASE_UI_ANIMATIONS_DISABLED) {
624
+ fnToExecute();
625
+ } else {
626
+ function execWaitForStartingStyleRemoved() {
627
+ const startingStyleAttribute = TransitionStatusDataAttributes.startingStyle;
628
+
629
+ // If `[data-starting-style]` isn't present, fall back to waiting one more frame
630
+ // to give "open" animations a chance to be registered.
631
+ if (!resolvedElement.hasAttribute(startingStyleAttribute)) {
632
+ frame.request(exec);
633
+ return;
634
+ }
635
+
636
+ // Wait for `[data-starting-style]` to have been removed.
637
+ const attributeObserver = new MutationObserver(() => {
638
+ if (!resolvedElement.hasAttribute(startingStyleAttribute)) {
639
+ attributeObserver.disconnect();
640
+ exec();
641
+ }
642
+ });
643
+ attributeObserver.observe(resolvedElement, {
644
+ attributes: true,
645
+ attributeFilter: [startingStyleAttribute]
646
+ });
647
+ signal?.addEventListener('abort', () => attributeObserver.disconnect(), {
648
+ once: true
649
+ });
650
+ }
651
+ function exec() {
652
+ Promise.all(resolvedElement.getAnimations().map(anim => anim.finished)).then(() => {
653
+ if (signal?.aborted) {
654
+ return;
655
+ }
656
+ done();
657
+ }).catch(() => {
658
+ const currentAnimations = resolvedElement.getAnimations();
659
+ if (treatAbortedAsFinished) {
660
+ if (signal?.aborted) {
661
+ return;
662
+ }
663
+ done();
664
+ } else if (currentAnimations.length > 0 && currentAnimations.some(anim => anim.pending || anim.playState !== 'finished')) {
665
+ // Sometimes animations can be aborted because a property they depend on changes while the animation plays.
666
+ // In such cases, we need to re-check if any new animations have started.
667
+ exec();
668
+ }
669
+ });
670
+ }
671
+ if (waitForStartingStyleRemoved) {
672
+ execWaitForStartingStyleRemoved();
673
+ return;
674
+ }
675
+ frame.request(exec);
676
+ }
677
+ });
678
+ }
679
+
680
+ /**
681
+ * Calls the provided function when the CSS open/close animation or transition completes.
682
+ */
683
+ function useOpenChangeComplete(parameters) {
684
+ const {
685
+ enabled = true,
686
+ open,
687
+ ref,
688
+ onComplete: onCompleteParam
689
+ } = parameters;
690
+ const onComplete = useStableCallback(onCompleteParam);
691
+ const runOnceAnimationsFinish = useAnimationsFinished(ref, open, false);
692
+ React__namespace.useEffect(() => {
693
+ if (!enabled) {
694
+ return undefined;
695
+ }
696
+ const abortController = new AbortController();
697
+ runOnceAnimationsFinish(onComplete, abortController.signal);
698
+ return () => {
699
+ abortController.abort();
700
+ };
701
+ }, [enabled, open, onComplete, runOnceAnimationsFinish]);
702
+ }
703
+
704
+ function clamp(val, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
705
+ return Math.max(min, Math.min(val, max));
706
+ }
707
+
708
+ function useControlled({
709
+ controlled,
710
+ default: defaultProp,
711
+ name,
712
+ state = 'value'
713
+ }) {
714
+ // isControlled is ignored in the hook dependency lists as it should never change.
715
+ const {
716
+ current: isControlled
717
+ } = React__namespace.useRef(controlled !== undefined);
718
+ const [valueState, setValue] = React__namespace.useState(defaultProp);
719
+ const value = isControlled ? controlled : valueState;
720
+ if (process.env.NODE_ENV !== 'production') {
721
+ React__namespace.useEffect(() => {
722
+ if (isControlled !== (controlled !== undefined)) {
723
+ console.error([`Base UI: A component is changing the ${isControlled ? '' : 'un'}controlled ${state} state of ${name} to be ${isControlled ? 'un' : ''}controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', `Decide between using a controlled or uncontrolled ${name} ` + 'element for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
724
+ }
725
+ }, [state, name, controlled]);
726
+ const {
727
+ current: defaultValue
728
+ } = React__namespace.useRef(defaultProp);
729
+ React__namespace.useEffect(() => {
730
+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is for more details.
731
+ if (!isControlled && JSON.stringify(defaultValue) !== JSON.stringify(defaultProp)) {
732
+ console.error([`Base UI: A component is changing the default ${state} state of an uncontrolled ${name} after being initialized. ` + `To suppress this warning opt to use a controlled ${name}.`].join('\n'));
733
+ }
734
+ }, [JSON.stringify(defaultProp)]);
735
+ }
736
+ const setValueIfUncontrolled = React__namespace.useCallback(newValue => {
737
+ if (!isControlled) {
738
+ setValue(newValue);
739
+ }
740
+ }, []);
741
+ return [value, setValueIfUncontrolled];
742
+ }
743
+
744
+ function useValueChanged(value, onChange) {
745
+ const valueRef = React__namespace.useRef(value);
746
+ const onChangeCallback = useStableCallback(onChange);
747
+ useIsoLayoutEffect(() => {
748
+ if (valueRef.current === value) {
749
+ return;
750
+ }
751
+ onChangeCallback(valueRef.current);
752
+ }, [value, onChangeCallback]);
753
+ useIsoLayoutEffect(() => {
754
+ valueRef.current = value;
755
+ }, [value]);
756
+ }
757
+
758
+ exports.AnimationFrame = AnimationFrame;
759
+ exports.SafeReact = SafeReact;
760
+ exports.Timeout = Timeout;
761
+ exports.TransitionStatusDataAttributes = TransitionStatusDataAttributes;
762
+ exports.cancelOpen = cancelOpen;
763
+ exports.chipRemovePress = chipRemovePress;
764
+ exports.clamp = clamp;
765
+ exports.clearPress = clearPress;
766
+ exports.closePress = closePress;
767
+ exports.closeWatcher = closeWatcher;
768
+ exports.createChangeEventDetails = createChangeEventDetails;
769
+ exports.createGenericEventDetails = createGenericEventDetails;
770
+ exports.decrementPress = decrementPress;
771
+ exports.escapeKey = escapeKey;
772
+ exports.focusOut = focusOut;
773
+ exports.imperativeAction = imperativeAction;
774
+ exports.incrementPress = incrementPress;
775
+ exports.inputBlur = inputBlur;
776
+ exports.inputChange = inputChange;
777
+ exports.inputClear = inputClear;
778
+ exports.inputPaste = inputPaste;
779
+ exports.inputPress = inputPress;
780
+ exports.isAndroid = isAndroid;
781
+ exports.isClickLikeEvent = isClickLikeEvent;
782
+ exports.isFirefox = isFirefox;
783
+ exports.isIOS = isIOS;
784
+ exports.isJSDOM = isJSDOM;
785
+ exports.isMac = isMac;
786
+ exports.isMouseLikePointerType = isMouseLikePointerType;
787
+ exports.isReactEvent = isReactEvent;
788
+ exports.isSafari = isSafari;
789
+ exports.isVirtualClick = isVirtualClick;
790
+ exports.isVirtualPointerEvent = isVirtualPointerEvent;
791
+ exports.isWebKit = isWebKit;
792
+ exports.itemPress = itemPress;
793
+ exports.keyboard = keyboard;
794
+ exports.listNavigation = listNavigation;
795
+ exports.none = none;
796
+ exports.outsidePress = outsidePress;
797
+ exports.ownerDocument = ownerDocument;
798
+ exports.resolveRef = resolveRef;
799
+ exports.scrub = scrub;
800
+ exports.siblingOpen = siblingOpen;
801
+ exports.stopEvent = stopEvent;
802
+ exports.swipe = swipe;
803
+ exports.transitionStatusMapping = transitionStatusMapping;
804
+ exports.triggerFocus = triggerFocus;
805
+ exports.triggerHover = triggerHover;
806
+ exports.triggerPress = triggerPress;
807
+ exports.useAnimationFrame = useAnimationFrame;
808
+ exports.useAnimationsFinished = useAnimationsFinished;
809
+ exports.useControlled = useControlled;
810
+ exports.useId = useId;
811
+ exports.useIsoLayoutEffect = useIsoLayoutEffect;
812
+ exports.useOnMount = useOnMount;
813
+ exports.useOpenChangeComplete = useOpenChangeComplete;
814
+ exports.useStableCallback = useStableCallback;
815
+ exports.useTimeout = useTimeout;
816
+ exports.useTransitionStatus = useTransitionStatus;
817
+ exports.useValueAsRef = useValueAsRef;
818
+ exports.useValueChanged = useValueChanged;
819
+ exports.visuallyHidden = visuallyHidden;
820
+ exports.visuallyHiddenInput = visuallyHiddenInput;