@jobber/components 6.90.4 → 6.91.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 (211) hide show
  1. package/dist/AtlantisThemeContext-es.js +1 -1
  2. package/dist/Autocomplete/index.cjs +12 -15
  3. package/dist/Autocomplete/index.mjs +13 -16
  4. package/dist/Banner/index.cjs +1 -6
  5. package/dist/Banner/index.mjs +1 -6
  6. package/dist/Banner-cjs.js +2 -2
  7. package/dist/Banner-es.js +2 -2
  8. package/dist/Card/index.cjs +1 -4
  9. package/dist/Card/index.mjs +1 -4
  10. package/dist/Chip/index.cjs +1 -3
  11. package/dist/Chip/index.mjs +1 -3
  12. package/dist/Chip-cjs.js +3 -3
  13. package/dist/Chip-es.js +3 -3
  14. package/dist/Chips/InternalChipDismissible/hooks/index.cjs +1 -0
  15. package/dist/Chips/InternalChipDismissible/hooks/index.mjs +1 -0
  16. package/dist/Chips/InternalChipDismissible/index.cjs +1 -3
  17. package/dist/Chips/InternalChipDismissible/index.mjs +1 -3
  18. package/dist/Chips/index.cjs +1 -3
  19. package/dist/Chips/index.mjs +1 -3
  20. package/dist/Combobox/components/ComboboxActivator/index.cjs +1 -3
  21. package/dist/Combobox/components/ComboboxActivator/index.mjs +1 -3
  22. package/dist/Combobox/components/ComboboxContent/ComboboxContentList/index.cjs +1 -1
  23. package/dist/Combobox/components/ComboboxContent/ComboboxContentList/index.mjs +1 -1
  24. package/dist/Combobox/components/ComboboxContent/ComboboxLoadMore/index.cjs +1 -1
  25. package/dist/Combobox/components/ComboboxContent/ComboboxLoadMore/index.mjs +1 -1
  26. package/dist/Combobox/components/ComboboxContent/index.cjs +1 -3
  27. package/dist/Combobox/components/ComboboxContent/index.mjs +1 -3
  28. package/dist/Combobox/components/ComboboxTrigger/index.cjs +1 -3
  29. package/dist/Combobox/components/ComboboxTrigger/index.mjs +1 -3
  30. package/dist/Combobox/index.cjs +1 -6
  31. package/dist/Combobox/index.mjs +1 -6
  32. package/dist/Combobox-cjs.js +2 -2
  33. package/dist/Combobox-es.js +2 -2
  34. package/dist/ComboboxContent-cjs.js +3 -4
  35. package/dist/ComboboxContent-es.js +4 -5
  36. package/dist/ComboboxLoadMore-cjs.js +2 -2
  37. package/dist/ComboboxLoadMore-es.js +2 -2
  38. package/dist/ConfirmationModal/index.cjs +1 -3
  39. package/dist/ConfirmationModal/index.mjs +1 -3
  40. package/dist/ConfirmationModal-cjs.js +2 -2
  41. package/dist/ConfirmationModal-es.js +2 -2
  42. package/dist/ContentBlock/index.cjs +1 -6
  43. package/dist/ContentBlock/index.mjs +1 -6
  44. package/dist/ContentBlock-cjs.js +2 -2
  45. package/dist/ContentBlock-es.js +2 -2
  46. package/dist/DataDump/index.cjs +1 -4
  47. package/dist/DataDump/index.mjs +1 -4
  48. package/dist/DataList/components/DataListActions/index.cjs +1 -5
  49. package/dist/DataList/components/DataListActions/index.mjs +1 -5
  50. package/dist/DataList/components/DataListActionsMenu/index.cjs +1 -5
  51. package/dist/DataList/components/DataListActionsMenu/index.mjs +1 -5
  52. package/dist/DataList/components/DataListBulkActions/index.cjs +1 -5
  53. package/dist/DataList/components/DataListBulkActions/index.mjs +1 -5
  54. package/dist/DataList/components/DataListFilters/components/DataListSort/index.cjs +1 -6
  55. package/dist/DataList/components/DataListFilters/components/DataListSort/index.mjs +1 -6
  56. package/dist/DataList/components/DataListFilters/index.cjs +1 -7
  57. package/dist/DataList/components/DataListFilters/index.mjs +1 -7
  58. package/dist/DataList/components/DataListHeader/index.cjs +1 -5
  59. package/dist/DataList/components/DataListHeader/index.mjs +1 -5
  60. package/dist/DataList/components/DataListHeaderTile/components/index.cjs +1 -2
  61. package/dist/DataList/components/DataListHeaderTile/components/index.mjs +1 -2
  62. package/dist/DataList/components/DataListHeaderTile/index.cjs +1 -3
  63. package/dist/DataList/components/DataListHeaderTile/index.mjs +1 -3
  64. package/dist/DataList/components/DataListItem/index.cjs +1 -5
  65. package/dist/DataList/components/DataListItem/index.mjs +1 -5
  66. package/dist/DataList/components/DataListItemActions/index.cjs +1 -5
  67. package/dist/DataList/components/DataListItemActions/index.mjs +1 -5
  68. package/dist/DataList/components/DataListItemActionsOverflow/index.cjs +1 -5
  69. package/dist/DataList/components/DataListItemActionsOverflow/index.mjs +1 -5
  70. package/dist/DataList/components/DataListItems/index.cjs +1 -5
  71. package/dist/DataList/components/DataListItems/index.mjs +1 -5
  72. package/dist/DataList/components/DataListLayout/index.cjs +1 -5
  73. package/dist/DataList/components/DataListLayout/index.mjs +1 -5
  74. package/dist/DataList/components/DataListLayoutActions/index.cjs +1 -5
  75. package/dist/DataList/components/DataListLayoutActions/index.mjs +1 -5
  76. package/dist/DataList/components/DataListLoadMore/index.cjs +1 -1
  77. package/dist/DataList/components/DataListLoadMore/index.mjs +1 -1
  78. package/dist/DataList/components/DataListOverflowFade/index.cjs +1 -1
  79. package/dist/DataList/components/DataListOverflowFade/index.mjs +1 -1
  80. package/dist/DataList/components/DataListSearch/index.cjs +1 -2
  81. package/dist/DataList/components/DataListSearch/index.mjs +1 -2
  82. package/dist/DataList/components/DataListStatusBar/index.cjs +1 -3
  83. package/dist/DataList/components/DataListStatusBar/index.mjs +1 -3
  84. package/dist/DataList/index.cjs +1 -7
  85. package/dist/DataList/index.mjs +1 -7
  86. package/dist/DataListActionsMenu-cjs.js +5 -8
  87. package/dist/DataListActionsMenu-es.js +5 -8
  88. package/dist/DataListHeaderTile-cjs.js +2 -2
  89. package/dist/DataListHeaderTile-es.js +2 -2
  90. package/dist/DataListLoadMore-cjs.js +2 -2
  91. package/dist/DataListLoadMore-es.js +2 -2
  92. package/dist/DataListOverflowFade-cjs.js +3 -3
  93. package/dist/DataListOverflowFade-es.js +3 -3
  94. package/dist/DataListSearch-cjs.js +2 -2
  95. package/dist/DataListSearch-es.js +2 -2
  96. package/dist/DataListSortingOptions-cjs.js +3 -4
  97. package/dist/DataListSortingOptions-es.js +3 -4
  98. package/dist/DataTable/index.cjs +4 -6
  99. package/dist/DataTable/index.mjs +4 -6
  100. package/dist/DataTable/test-utilities/index.cjs +1 -7
  101. package/dist/DataTable/test-utilities/index.mjs +1 -7
  102. package/dist/DataTable-cjs.js +4 -4
  103. package/dist/DataTable-es.js +4 -4
  104. package/dist/DatePicker/index.cjs +1 -1
  105. package/dist/DatePicker/index.mjs +1 -1
  106. package/dist/DatePicker-cjs.js +2 -2
  107. package/dist/DatePicker-es.js +3 -3
  108. package/dist/Disclosure/index.cjs +1 -6
  109. package/dist/Disclosure/index.mjs +1 -6
  110. package/dist/Disclosure-cjs.js +3 -3
  111. package/dist/Disclosure-es.js +3 -3
  112. package/dist/FormField/FormFieldWrapper.d.ts +1 -1
  113. package/dist/FormField/index.cjs +1 -0
  114. package/dist/FormField/index.mjs +1 -0
  115. package/dist/FormField-cjs.js +2 -21
  116. package/dist/FormField-es.js +2 -21
  117. package/dist/FormatFile/index.cjs +1 -3
  118. package/dist/FormatFile/index.mjs +1 -3
  119. package/dist/Gallery/index.cjs +1 -6
  120. package/dist/Gallery/index.mjs +1 -6
  121. package/dist/InputDate/index.cjs +1 -2
  122. package/dist/InputDate/index.mjs +1 -2
  123. package/dist/InputEmail/index.cjs +1 -0
  124. package/dist/InputEmail/index.mjs +1 -0
  125. package/dist/InputNumber/index.cjs +1 -0
  126. package/dist/InputNumber/index.mjs +1 -0
  127. package/dist/InputPassword/index.cjs +1 -0
  128. package/dist/InputPassword/index.mjs +1 -0
  129. package/dist/InputPassword-cjs.js +1 -0
  130. package/dist/InputPassword-es.js +1 -0
  131. package/dist/InputPhoneNumber/InputPhoneNumber.types.d.ts +1 -1
  132. package/dist/InputPhoneNumber/index.cjs +1 -0
  133. package/dist/InputPhoneNumber/index.mjs +1 -0
  134. package/dist/InputText/InputText.d.ts +2 -2
  135. package/dist/InputText/index.cjs +3 -3
  136. package/dist/InputText/index.mjs +3 -3
  137. package/dist/InputTime/index.cjs +1 -0
  138. package/dist/InputTime/index.mjs +2 -1
  139. package/dist/InternalChipDismissible-cjs.js +1 -0
  140. package/dist/InternalChipDismissible-es.js +1 -0
  141. package/dist/LightBox/index.cjs +1 -6
  142. package/dist/LightBox/index.mjs +1 -6
  143. package/dist/LightBox-cjs.js +12 -74
  144. package/dist/LightBox-es.js +12 -74
  145. package/dist/Menu/index.cjs +1 -4
  146. package/dist/Menu/index.mjs +1 -4
  147. package/dist/Menu-cjs.js +5 -37
  148. package/dist/Menu-es.js +6 -38
  149. package/dist/Modal/index.cjs +4 -6
  150. package/dist/Modal/index.mjs +5 -7
  151. package/dist/Page/index.cjs +2 -10
  152. package/dist/Page/index.mjs +2 -10
  153. package/dist/Page-cjs.js +5 -5
  154. package/dist/Page-es.js +5 -5
  155. package/dist/Popover/index.cjs +1 -1
  156. package/dist/Popover/index.mjs +1 -1
  157. package/dist/Popover-cjs.js +2 -2
  158. package/dist/Popover-es.js +3 -3
  159. package/dist/RecurringSelect/index.cjs +1 -0
  160. package/dist/RecurringSelect/index.mjs +1 -0
  161. package/dist/Select/index.cjs +1 -0
  162. package/dist/Select/index.mjs +1 -0
  163. package/dist/SideDrawer/index.cjs +1 -5
  164. package/dist/SideDrawer/index.mjs +1 -5
  165. package/dist/SideDrawer-cjs.js +7 -10
  166. package/dist/SideDrawer-es.js +7 -10
  167. package/dist/Tabs/index.cjs +0 -1
  168. package/dist/Tabs/index.mjs +0 -1
  169. package/dist/Tabs-cjs.js +76 -2
  170. package/dist/Tabs-es.js +76 -2
  171. package/dist/Tooltip/index.cjs +1 -2
  172. package/dist/Tooltip/index.mjs +1 -2
  173. package/dist/Tooltip-cjs.js +3 -4
  174. package/dist/Tooltip-es.js +4 -5
  175. package/dist/_baseEach-es.js +1 -1
  176. package/dist/_commonjsHelpers-cjs.js +0 -26
  177. package/dist/_commonjsHelpers-es.js +1 -26
  178. package/dist/_isIterateeCall-es.js +1 -1
  179. package/dist/debounce-es.js +2 -2
  180. package/dist/floating-ui.react-es.js +1 -1
  181. package/dist/helpers-cjs.js +21 -2
  182. package/dist/helpers-es.js +1 -1
  183. package/dist/index.cjs +1 -9
  184. package/dist/index.mjs +1 -9
  185. package/dist/isObjectLike-es.js +1 -1
  186. package/dist/isSymbol-es.js +1 -1
  187. package/dist/isTypedArray-es.js +1 -1
  188. package/dist/keysIn-es.js +1 -1
  189. package/dist/omit-es.js +1 -1
  190. package/dist/useScrollToActive-cjs.js +3 -45
  191. package/dist/useScrollToActive-es.js +5 -47
  192. package/package.json +3 -3
  193. package/rollup.config.mjs +0 -15
  194. package/dist/throttle-cjs.js +0 -80
  195. package/dist/throttle-es.js +0 -77
  196. package/dist/useDebounce-cjs.js +0 -4416
  197. package/dist/useDebounce-es.js +0 -4413
  198. package/dist/useFocusTrap-cjs.js +0 -75
  199. package/dist/useFocusTrap-es.js +0 -73
  200. package/dist/useInView-cjs.js +0 -26
  201. package/dist/useInView-es.js +0 -24
  202. package/dist/useIsMounted-cjs.js +0 -51
  203. package/dist/useIsMounted-es.js +0 -49
  204. package/dist/useOnKeyDown-cjs.js +0 -41
  205. package/dist/useOnKeyDown-es.js +0 -39
  206. package/dist/useRefocusOnActivator-cjs.js +0 -33
  207. package/dist/useRefocusOnActivator-es.js +0 -31
  208. package/dist/useResizeObserver-cjs.js +0 -1131
  209. package/dist/useResizeObserver-es.js +0 -1128
  210. package/dist/useSafeLayoutEffect-cjs.js +0 -14
  211. package/dist/useSafeLayoutEffect-es.js +0 -12
@@ -1,1131 +0,0 @@
1
- 'use strict';
2
-
3
- var _commonjsHelpers = require('./_commonjsHelpers-cjs.js');
4
- var React = require('react');
5
- var throttle$1 = require('./throttle-cjs.js');
6
-
7
- function _mergeNamespaces(n, m) {
8
- m.forEach(function (e) {
9
- e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
10
- if (k !== 'default' && !(k in n)) {
11
- var d = Object.getOwnPropertyDescriptor(e, k);
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: function () { return e[k]; }
15
- });
16
- }
17
- });
18
- });
19
- return Object.freeze(n);
20
- }
21
-
22
- var useResizeObserver$2 = {};
23
-
24
- /**
25
- * A collection of shims that provide minimal functionality of the ES6 collections.
26
- *
27
- * These implementations are not meant to be used outside of the ResizeObserver
28
- * modules as they cover only a limited range of use cases.
29
- */
30
- /* eslint-disable require-jsdoc, valid-jsdoc */
31
- var MapShim = (function () {
32
- if (typeof Map !== 'undefined') {
33
- return Map;
34
- }
35
- /**
36
- * Returns index in provided array that matches the specified key.
37
- *
38
- * @param {Array<Array>} arr
39
- * @param {*} key
40
- * @returns {number}
41
- */
42
- function getIndex(arr, key) {
43
- var result = -1;
44
- arr.some(function (entry, index) {
45
- if (entry[0] === key) {
46
- result = index;
47
- return true;
48
- }
49
- return false;
50
- });
51
- return result;
52
- }
53
- return /** @class */ (function () {
54
- function class_1() {
55
- this.__entries__ = [];
56
- }
57
- Object.defineProperty(class_1.prototype, "size", {
58
- /**
59
- * @returns {boolean}
60
- */
61
- get: function () {
62
- return this.__entries__.length;
63
- },
64
- enumerable: true,
65
- configurable: true
66
- });
67
- /**
68
- * @param {*} key
69
- * @returns {*}
70
- */
71
- class_1.prototype.get = function (key) {
72
- var index = getIndex(this.__entries__, key);
73
- var entry = this.__entries__[index];
74
- return entry && entry[1];
75
- };
76
- /**
77
- * @param {*} key
78
- * @param {*} value
79
- * @returns {void}
80
- */
81
- class_1.prototype.set = function (key, value) {
82
- var index = getIndex(this.__entries__, key);
83
- if (~index) {
84
- this.__entries__[index][1] = value;
85
- }
86
- else {
87
- this.__entries__.push([key, value]);
88
- }
89
- };
90
- /**
91
- * @param {*} key
92
- * @returns {void}
93
- */
94
- class_1.prototype.delete = function (key) {
95
- var entries = this.__entries__;
96
- var index = getIndex(entries, key);
97
- if (~index) {
98
- entries.splice(index, 1);
99
- }
100
- };
101
- /**
102
- * @param {*} key
103
- * @returns {void}
104
- */
105
- class_1.prototype.has = function (key) {
106
- return !!~getIndex(this.__entries__, key);
107
- };
108
- /**
109
- * @returns {void}
110
- */
111
- class_1.prototype.clear = function () {
112
- this.__entries__.splice(0);
113
- };
114
- /**
115
- * @param {Function} callback
116
- * @param {*} [ctx=null]
117
- * @returns {void}
118
- */
119
- class_1.prototype.forEach = function (callback, ctx) {
120
- if (ctx === void 0) { ctx = null; }
121
- for (var _i = 0, _a = this.__entries__; _i < _a.length; _i++) {
122
- var entry = _a[_i];
123
- callback.call(ctx, entry[1], entry[0]);
124
- }
125
- };
126
- return class_1;
127
- }());
128
- })();
129
-
130
- /**
131
- * Detects whether window and document objects are available in current environment.
132
- */
133
- var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document;
134
-
135
- // Returns global object of a current environment.
136
- var global$1 = (function () {
137
- if (typeof global !== 'undefined' && global.Math === Math) {
138
- return global;
139
- }
140
- if (typeof self !== 'undefined' && self.Math === Math) {
141
- return self;
142
- }
143
- if (typeof window !== 'undefined' && window.Math === Math) {
144
- return window;
145
- }
146
- // eslint-disable-next-line no-new-func
147
- return Function('return this')();
148
- })();
149
-
150
- /**
151
- * A shim for the requestAnimationFrame which falls back to the setTimeout if
152
- * first one is not supported.
153
- *
154
- * @returns {number} Requests' identifier.
155
- */
156
- var requestAnimationFrame$1 = (function () {
157
- if (typeof requestAnimationFrame === 'function') {
158
- // It's required to use a bounded function because IE sometimes throws
159
- // an "Invalid calling object" error if rAF is invoked without the global
160
- // object on the left hand side.
161
- return requestAnimationFrame.bind(global$1);
162
- }
163
- return function (callback) { return setTimeout(function () { return callback(Date.now()); }, 1000 / 60); };
164
- })();
165
-
166
- // Defines minimum timeout before adding a trailing call.
167
- var trailingTimeout = 2;
168
- /**
169
- * Creates a wrapper function which ensures that provided callback will be
170
- * invoked only once during the specified delay period.
171
- *
172
- * @param {Function} callback - Function to be invoked after the delay period.
173
- * @param {number} delay - Delay after which to invoke callback.
174
- * @returns {Function}
175
- */
176
- function throttle (callback, delay) {
177
- var leadingCall = false, trailingCall = false, lastCallTime = 0;
178
- /**
179
- * Invokes the original callback function and schedules new invocation if
180
- * the "proxy" was called during current request.
181
- *
182
- * @returns {void}
183
- */
184
- function resolvePending() {
185
- if (leadingCall) {
186
- leadingCall = false;
187
- callback();
188
- }
189
- if (trailingCall) {
190
- proxy();
191
- }
192
- }
193
- /**
194
- * Callback invoked after the specified delay. It will further postpone
195
- * invocation of the original function delegating it to the
196
- * requestAnimationFrame.
197
- *
198
- * @returns {void}
199
- */
200
- function timeoutCallback() {
201
- requestAnimationFrame$1(resolvePending);
202
- }
203
- /**
204
- * Schedules invocation of the original function.
205
- *
206
- * @returns {void}
207
- */
208
- function proxy() {
209
- var timeStamp = Date.now();
210
- if (leadingCall) {
211
- // Reject immediately following calls.
212
- if (timeStamp - lastCallTime < trailingTimeout) {
213
- return;
214
- }
215
- // Schedule new call to be in invoked when the pending one is resolved.
216
- // This is important for "transitions" which never actually start
217
- // immediately so there is a chance that we might miss one if change
218
- // happens amids the pending invocation.
219
- trailingCall = true;
220
- }
221
- else {
222
- leadingCall = true;
223
- trailingCall = false;
224
- setTimeout(timeoutCallback, delay);
225
- }
226
- lastCallTime = timeStamp;
227
- }
228
- return proxy;
229
- }
230
-
231
- // Minimum delay before invoking the update of observers.
232
- var REFRESH_DELAY = 20;
233
- // A list of substrings of CSS properties used to find transition events that
234
- // might affect dimensions of observed elements.
235
- var transitionKeys = ['top', 'right', 'bottom', 'left', 'width', 'height', 'size', 'weight'];
236
- // Check if MutationObserver is available.
237
- var mutationObserverSupported = typeof MutationObserver !== 'undefined';
238
- /**
239
- * Singleton controller class which handles updates of ResizeObserver instances.
240
- */
241
- var ResizeObserverController = /** @class */ (function () {
242
- /**
243
- * Creates a new instance of ResizeObserverController.
244
- *
245
- * @private
246
- */
247
- function ResizeObserverController() {
248
- /**
249
- * Indicates whether DOM listeners have been added.
250
- *
251
- * @private {boolean}
252
- */
253
- this.connected_ = false;
254
- /**
255
- * Tells that controller has subscribed for Mutation Events.
256
- *
257
- * @private {boolean}
258
- */
259
- this.mutationEventsAdded_ = false;
260
- /**
261
- * Keeps reference to the instance of MutationObserver.
262
- *
263
- * @private {MutationObserver}
264
- */
265
- this.mutationsObserver_ = null;
266
- /**
267
- * A list of connected observers.
268
- *
269
- * @private {Array<ResizeObserverSPI>}
270
- */
271
- this.observers_ = [];
272
- this.onTransitionEnd_ = this.onTransitionEnd_.bind(this);
273
- this.refresh = throttle(this.refresh.bind(this), REFRESH_DELAY);
274
- }
275
- /**
276
- * Adds observer to observers list.
277
- *
278
- * @param {ResizeObserverSPI} observer - Observer to be added.
279
- * @returns {void}
280
- */
281
- ResizeObserverController.prototype.addObserver = function (observer) {
282
- if (!~this.observers_.indexOf(observer)) {
283
- this.observers_.push(observer);
284
- }
285
- // Add listeners if they haven't been added yet.
286
- if (!this.connected_) {
287
- this.connect_();
288
- }
289
- };
290
- /**
291
- * Removes observer from observers list.
292
- *
293
- * @param {ResizeObserverSPI} observer - Observer to be removed.
294
- * @returns {void}
295
- */
296
- ResizeObserverController.prototype.removeObserver = function (observer) {
297
- var observers = this.observers_;
298
- var index = observers.indexOf(observer);
299
- // Remove observer if it's present in registry.
300
- if (~index) {
301
- observers.splice(index, 1);
302
- }
303
- // Remove listeners if controller has no connected observers.
304
- if (!observers.length && this.connected_) {
305
- this.disconnect_();
306
- }
307
- };
308
- /**
309
- * Invokes the update of observers. It will continue running updates insofar
310
- * it detects changes.
311
- *
312
- * @returns {void}
313
- */
314
- ResizeObserverController.prototype.refresh = function () {
315
- var changesDetected = this.updateObservers_();
316
- // Continue running updates if changes have been detected as there might
317
- // be future ones caused by CSS transitions.
318
- if (changesDetected) {
319
- this.refresh();
320
- }
321
- };
322
- /**
323
- * Updates every observer from observers list and notifies them of queued
324
- * entries.
325
- *
326
- * @private
327
- * @returns {boolean} Returns "true" if any observer has detected changes in
328
- * dimensions of it's elements.
329
- */
330
- ResizeObserverController.prototype.updateObservers_ = function () {
331
- // Collect observers that have active observations.
332
- var activeObservers = this.observers_.filter(function (observer) {
333
- return observer.gatherActive(), observer.hasActive();
334
- });
335
- // Deliver notifications in a separate cycle in order to avoid any
336
- // collisions between observers, e.g. when multiple instances of
337
- // ResizeObserver are tracking the same element and the callback of one
338
- // of them changes content dimensions of the observed target. Sometimes
339
- // this may result in notifications being blocked for the rest of observers.
340
- activeObservers.forEach(function (observer) { return observer.broadcastActive(); });
341
- return activeObservers.length > 0;
342
- };
343
- /**
344
- * Initializes DOM listeners.
345
- *
346
- * @private
347
- * @returns {void}
348
- */
349
- ResizeObserverController.prototype.connect_ = function () {
350
- // Do nothing if running in a non-browser environment or if listeners
351
- // have been already added.
352
- if (!isBrowser || this.connected_) {
353
- return;
354
- }
355
- // Subscription to the "Transitionend" event is used as a workaround for
356
- // delayed transitions. This way it's possible to capture at least the
357
- // final state of an element.
358
- document.addEventListener('transitionend', this.onTransitionEnd_);
359
- window.addEventListener('resize', this.refresh);
360
- if (mutationObserverSupported) {
361
- this.mutationsObserver_ = new MutationObserver(this.refresh);
362
- this.mutationsObserver_.observe(document, {
363
- attributes: true,
364
- childList: true,
365
- characterData: true,
366
- subtree: true
367
- });
368
- }
369
- else {
370
- document.addEventListener('DOMSubtreeModified', this.refresh);
371
- this.mutationEventsAdded_ = true;
372
- }
373
- this.connected_ = true;
374
- };
375
- /**
376
- * Removes DOM listeners.
377
- *
378
- * @private
379
- * @returns {void}
380
- */
381
- ResizeObserverController.prototype.disconnect_ = function () {
382
- // Do nothing if running in a non-browser environment or if listeners
383
- // have been already removed.
384
- if (!isBrowser || !this.connected_) {
385
- return;
386
- }
387
- document.removeEventListener('transitionend', this.onTransitionEnd_);
388
- window.removeEventListener('resize', this.refresh);
389
- if (this.mutationsObserver_) {
390
- this.mutationsObserver_.disconnect();
391
- }
392
- if (this.mutationEventsAdded_) {
393
- document.removeEventListener('DOMSubtreeModified', this.refresh);
394
- }
395
- this.mutationsObserver_ = null;
396
- this.mutationEventsAdded_ = false;
397
- this.connected_ = false;
398
- };
399
- /**
400
- * "Transitionend" event handler.
401
- *
402
- * @private
403
- * @param {TransitionEvent} event
404
- * @returns {void}
405
- */
406
- ResizeObserverController.prototype.onTransitionEnd_ = function (_a) {
407
- var _b = _a.propertyName, propertyName = _b === void 0 ? '' : _b;
408
- // Detect whether transition may affect dimensions of an element.
409
- var isReflowProperty = transitionKeys.some(function (key) {
410
- return !!~propertyName.indexOf(key);
411
- });
412
- if (isReflowProperty) {
413
- this.refresh();
414
- }
415
- };
416
- /**
417
- * Returns instance of the ResizeObserverController.
418
- *
419
- * @returns {ResizeObserverController}
420
- */
421
- ResizeObserverController.getInstance = function () {
422
- if (!this.instance_) {
423
- this.instance_ = new ResizeObserverController();
424
- }
425
- return this.instance_;
426
- };
427
- /**
428
- * Holds reference to the controller's instance.
429
- *
430
- * @private {ResizeObserverController}
431
- */
432
- ResizeObserverController.instance_ = null;
433
- return ResizeObserverController;
434
- }());
435
-
436
- /**
437
- * Defines non-writable/enumerable properties of the provided target object.
438
- *
439
- * @param {Object} target - Object for which to define properties.
440
- * @param {Object} props - Properties to be defined.
441
- * @returns {Object} Target object.
442
- */
443
- var defineConfigurable = (function (target, props) {
444
- for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) {
445
- var key = _a[_i];
446
- Object.defineProperty(target, key, {
447
- value: props[key],
448
- enumerable: false,
449
- writable: false,
450
- configurable: true
451
- });
452
- }
453
- return target;
454
- });
455
-
456
- /**
457
- * Returns the global object associated with provided element.
458
- *
459
- * @param {Object} target
460
- * @returns {Object}
461
- */
462
- var getWindowOf = (function (target) {
463
- // Assume that the element is an instance of Node, which means that it
464
- // has the "ownerDocument" property from which we can retrieve a
465
- // corresponding global object.
466
- var ownerGlobal = target && target.ownerDocument && target.ownerDocument.defaultView;
467
- // Return the local global object if it's not possible extract one from
468
- // provided element.
469
- return ownerGlobal || global$1;
470
- });
471
-
472
- // Placeholder of an empty content rectangle.
473
- var emptyRect = createRectInit(0, 0, 0, 0);
474
- /**
475
- * Converts provided string to a number.
476
- *
477
- * @param {number|string} value
478
- * @returns {number}
479
- */
480
- function toFloat(value) {
481
- return parseFloat(value) || 0;
482
- }
483
- /**
484
- * Extracts borders size from provided styles.
485
- *
486
- * @param {CSSStyleDeclaration} styles
487
- * @param {...string} positions - Borders positions (top, right, ...)
488
- * @returns {number}
489
- */
490
- function getBordersSize(styles) {
491
- var positions = [];
492
- for (var _i = 1; _i < arguments.length; _i++) {
493
- positions[_i - 1] = arguments[_i];
494
- }
495
- return positions.reduce(function (size, position) {
496
- var value = styles['border-' + position + '-width'];
497
- return size + toFloat(value);
498
- }, 0);
499
- }
500
- /**
501
- * Extracts paddings sizes from provided styles.
502
- *
503
- * @param {CSSStyleDeclaration} styles
504
- * @returns {Object} Paddings box.
505
- */
506
- function getPaddings(styles) {
507
- var positions = ['top', 'right', 'bottom', 'left'];
508
- var paddings = {};
509
- for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
510
- var position = positions_1[_i];
511
- var value = styles['padding-' + position];
512
- paddings[position] = toFloat(value);
513
- }
514
- return paddings;
515
- }
516
- /**
517
- * Calculates content rectangle of provided SVG element.
518
- *
519
- * @param {SVGGraphicsElement} target - Element content rectangle of which needs
520
- * to be calculated.
521
- * @returns {DOMRectInit}
522
- */
523
- function getSVGContentRect(target) {
524
- var bbox = target.getBBox();
525
- return createRectInit(0, 0, bbox.width, bbox.height);
526
- }
527
- /**
528
- * Calculates content rectangle of provided HTMLElement.
529
- *
530
- * @param {HTMLElement} target - Element for which to calculate the content rectangle.
531
- * @returns {DOMRectInit}
532
- */
533
- function getHTMLElementContentRect(target) {
534
- // Client width & height properties can't be
535
- // used exclusively as they provide rounded values.
536
- var clientWidth = target.clientWidth, clientHeight = target.clientHeight;
537
- // By this condition we can catch all non-replaced inline, hidden and
538
- // detached elements. Though elements with width & height properties less
539
- // than 0.5 will be discarded as well.
540
- //
541
- // Without it we would need to implement separate methods for each of
542
- // those cases and it's not possible to perform a precise and performance
543
- // effective test for hidden elements. E.g. even jQuery's ':visible' filter
544
- // gives wrong results for elements with width & height less than 0.5.
545
- if (!clientWidth && !clientHeight) {
546
- return emptyRect;
547
- }
548
- var styles = getWindowOf(target).getComputedStyle(target);
549
- var paddings = getPaddings(styles);
550
- var horizPad = paddings.left + paddings.right;
551
- var vertPad = paddings.top + paddings.bottom;
552
- // Computed styles of width & height are being used because they are the
553
- // only dimensions available to JS that contain non-rounded values. It could
554
- // be possible to utilize the getBoundingClientRect if only it's data wasn't
555
- // affected by CSS transformations let alone paddings, borders and scroll bars.
556
- var width = toFloat(styles.width), height = toFloat(styles.height);
557
- // Width & height include paddings and borders when the 'border-box' box
558
- // model is applied (except for IE).
559
- if (styles.boxSizing === 'border-box') {
560
- // Following conditions are required to handle Internet Explorer which
561
- // doesn't include paddings and borders to computed CSS dimensions.
562
- //
563
- // We can say that if CSS dimensions + paddings are equal to the "client"
564
- // properties then it's either IE, and thus we don't need to subtract
565
- // anything, or an element merely doesn't have paddings/borders styles.
566
- if (Math.round(width + horizPad) !== clientWidth) {
567
- width -= getBordersSize(styles, 'left', 'right') + horizPad;
568
- }
569
- if (Math.round(height + vertPad) !== clientHeight) {
570
- height -= getBordersSize(styles, 'top', 'bottom') + vertPad;
571
- }
572
- }
573
- // Following steps can't be applied to the document's root element as its
574
- // client[Width/Height] properties represent viewport area of the window.
575
- // Besides, it's as well not necessary as the <html> itself neither has
576
- // rendered scroll bars nor it can be clipped.
577
- if (!isDocumentElement(target)) {
578
- // In some browsers (only in Firefox, actually) CSS width & height
579
- // include scroll bars size which can be removed at this step as scroll
580
- // bars are the only difference between rounded dimensions + paddings
581
- // and "client" properties, though that is not always true in Chrome.
582
- var vertScrollbar = Math.round(width + horizPad) - clientWidth;
583
- var horizScrollbar = Math.round(height + vertPad) - clientHeight;
584
- // Chrome has a rather weird rounding of "client" properties.
585
- // E.g. for an element with content width of 314.2px it sometimes gives
586
- // the client width of 315px and for the width of 314.7px it may give
587
- // 314px. And it doesn't happen all the time. So just ignore this delta
588
- // as a non-relevant.
589
- if (Math.abs(vertScrollbar) !== 1) {
590
- width -= vertScrollbar;
591
- }
592
- if (Math.abs(horizScrollbar) !== 1) {
593
- height -= horizScrollbar;
594
- }
595
- }
596
- return createRectInit(paddings.left, paddings.top, width, height);
597
- }
598
- /**
599
- * Checks whether provided element is an instance of the SVGGraphicsElement.
600
- *
601
- * @param {Element} target - Element to be checked.
602
- * @returns {boolean}
603
- */
604
- var isSVGGraphicsElement = (function () {
605
- // Some browsers, namely IE and Edge, don't have the SVGGraphicsElement
606
- // interface.
607
- if (typeof SVGGraphicsElement !== 'undefined') {
608
- return function (target) { return target instanceof getWindowOf(target).SVGGraphicsElement; };
609
- }
610
- // If it's so, then check that element is at least an instance of the
611
- // SVGElement and that it has the "getBBox" method.
612
- // eslint-disable-next-line no-extra-parens
613
- return function (target) { return (target instanceof getWindowOf(target).SVGElement &&
614
- typeof target.getBBox === 'function'); };
615
- })();
616
- /**
617
- * Checks whether provided element is a document element (<html>).
618
- *
619
- * @param {Element} target - Element to be checked.
620
- * @returns {boolean}
621
- */
622
- function isDocumentElement(target) {
623
- return target === getWindowOf(target).document.documentElement;
624
- }
625
- /**
626
- * Calculates an appropriate content rectangle for provided html or svg element.
627
- *
628
- * @param {Element} target - Element content rectangle of which needs to be calculated.
629
- * @returns {DOMRectInit}
630
- */
631
- function getContentRect(target) {
632
- if (!isBrowser) {
633
- return emptyRect;
634
- }
635
- if (isSVGGraphicsElement(target)) {
636
- return getSVGContentRect(target);
637
- }
638
- return getHTMLElementContentRect(target);
639
- }
640
- /**
641
- * Creates rectangle with an interface of the DOMRectReadOnly.
642
- * Spec: https://drafts.fxtf.org/geometry/#domrectreadonly
643
- *
644
- * @param {DOMRectInit} rectInit - Object with rectangle's x/y coordinates and dimensions.
645
- * @returns {DOMRectReadOnly}
646
- */
647
- function createReadOnlyRect(_a) {
648
- var x = _a.x, y = _a.y, width = _a.width, height = _a.height;
649
- // If DOMRectReadOnly is available use it as a prototype for the rectangle.
650
- var Constr = typeof DOMRectReadOnly !== 'undefined' ? DOMRectReadOnly : Object;
651
- var rect = Object.create(Constr.prototype);
652
- // Rectangle's properties are not writable and non-enumerable.
653
- defineConfigurable(rect, {
654
- x: x, y: y, width: width, height: height,
655
- top: y,
656
- right: x + width,
657
- bottom: height + y,
658
- left: x
659
- });
660
- return rect;
661
- }
662
- /**
663
- * Creates DOMRectInit object based on the provided dimensions and the x/y coordinates.
664
- * Spec: https://drafts.fxtf.org/geometry/#dictdef-domrectinit
665
- *
666
- * @param {number} x - X coordinate.
667
- * @param {number} y - Y coordinate.
668
- * @param {number} width - Rectangle's width.
669
- * @param {number} height - Rectangle's height.
670
- * @returns {DOMRectInit}
671
- */
672
- function createRectInit(x, y, width, height) {
673
- return { x: x, y: y, width: width, height: height };
674
- }
675
-
676
- /**
677
- * Class that is responsible for computations of the content rectangle of
678
- * provided DOM element and for keeping track of it's changes.
679
- */
680
- var ResizeObservation = /** @class */ (function () {
681
- /**
682
- * Creates an instance of ResizeObservation.
683
- *
684
- * @param {Element} target - Element to be observed.
685
- */
686
- function ResizeObservation(target) {
687
- /**
688
- * Broadcasted width of content rectangle.
689
- *
690
- * @type {number}
691
- */
692
- this.broadcastWidth = 0;
693
- /**
694
- * Broadcasted height of content rectangle.
695
- *
696
- * @type {number}
697
- */
698
- this.broadcastHeight = 0;
699
- /**
700
- * Reference to the last observed content rectangle.
701
- *
702
- * @private {DOMRectInit}
703
- */
704
- this.contentRect_ = createRectInit(0, 0, 0, 0);
705
- this.target = target;
706
- }
707
- /**
708
- * Updates content rectangle and tells whether it's width or height properties
709
- * have changed since the last broadcast.
710
- *
711
- * @returns {boolean}
712
- */
713
- ResizeObservation.prototype.isActive = function () {
714
- var rect = getContentRect(this.target);
715
- this.contentRect_ = rect;
716
- return (rect.width !== this.broadcastWidth ||
717
- rect.height !== this.broadcastHeight);
718
- };
719
- /**
720
- * Updates 'broadcastWidth' and 'broadcastHeight' properties with a data
721
- * from the corresponding properties of the last observed content rectangle.
722
- *
723
- * @returns {DOMRectInit} Last observed content rectangle.
724
- */
725
- ResizeObservation.prototype.broadcastRect = function () {
726
- var rect = this.contentRect_;
727
- this.broadcastWidth = rect.width;
728
- this.broadcastHeight = rect.height;
729
- return rect;
730
- };
731
- return ResizeObservation;
732
- }());
733
-
734
- var ResizeObserverEntry = /** @class */ (function () {
735
- /**
736
- * Creates an instance of ResizeObserverEntry.
737
- *
738
- * @param {Element} target - Element that is being observed.
739
- * @param {DOMRectInit} rectInit - Data of the element's content rectangle.
740
- */
741
- function ResizeObserverEntry(target, rectInit) {
742
- var contentRect = createReadOnlyRect(rectInit);
743
- // According to the specification following properties are not writable
744
- // and are also not enumerable in the native implementation.
745
- //
746
- // Property accessors are not being used as they'd require to define a
747
- // private WeakMap storage which may cause memory leaks in browsers that
748
- // don't support this type of collections.
749
- defineConfigurable(this, { target: target, contentRect: contentRect });
750
- }
751
- return ResizeObserverEntry;
752
- }());
753
-
754
- var ResizeObserverSPI = /** @class */ (function () {
755
- /**
756
- * Creates a new instance of ResizeObserver.
757
- *
758
- * @param {ResizeObserverCallback} callback - Callback function that is invoked
759
- * when one of the observed elements changes it's content dimensions.
760
- * @param {ResizeObserverController} controller - Controller instance which
761
- * is responsible for the updates of observer.
762
- * @param {ResizeObserver} callbackCtx - Reference to the public
763
- * ResizeObserver instance which will be passed to callback function.
764
- */
765
- function ResizeObserverSPI(callback, controller, callbackCtx) {
766
- /**
767
- * Collection of resize observations that have detected changes in dimensions
768
- * of elements.
769
- *
770
- * @private {Array<ResizeObservation>}
771
- */
772
- this.activeObservations_ = [];
773
- /**
774
- * Registry of the ResizeObservation instances.
775
- *
776
- * @private {Map<Element, ResizeObservation>}
777
- */
778
- this.observations_ = new MapShim();
779
- if (typeof callback !== 'function') {
780
- throw new TypeError('The callback provided as parameter 1 is not a function.');
781
- }
782
- this.callback_ = callback;
783
- this.controller_ = controller;
784
- this.callbackCtx_ = callbackCtx;
785
- }
786
- /**
787
- * Starts observing provided element.
788
- *
789
- * @param {Element} target - Element to be observed.
790
- * @returns {void}
791
- */
792
- ResizeObserverSPI.prototype.observe = function (target) {
793
- if (!arguments.length) {
794
- throw new TypeError('1 argument required, but only 0 present.');
795
- }
796
- // Do nothing if current environment doesn't have the Element interface.
797
- if (typeof Element === 'undefined' || !(Element instanceof Object)) {
798
- return;
799
- }
800
- if (!(target instanceof getWindowOf(target).Element)) {
801
- throw new TypeError('parameter 1 is not of type "Element".');
802
- }
803
- var observations = this.observations_;
804
- // Do nothing if element is already being observed.
805
- if (observations.has(target)) {
806
- return;
807
- }
808
- observations.set(target, new ResizeObservation(target));
809
- this.controller_.addObserver(this);
810
- // Force the update of observations.
811
- this.controller_.refresh();
812
- };
813
- /**
814
- * Stops observing provided element.
815
- *
816
- * @param {Element} target - Element to stop observing.
817
- * @returns {void}
818
- */
819
- ResizeObserverSPI.prototype.unobserve = function (target) {
820
- if (!arguments.length) {
821
- throw new TypeError('1 argument required, but only 0 present.');
822
- }
823
- // Do nothing if current environment doesn't have the Element interface.
824
- if (typeof Element === 'undefined' || !(Element instanceof Object)) {
825
- return;
826
- }
827
- if (!(target instanceof getWindowOf(target).Element)) {
828
- throw new TypeError('parameter 1 is not of type "Element".');
829
- }
830
- var observations = this.observations_;
831
- // Do nothing if element is not being observed.
832
- if (!observations.has(target)) {
833
- return;
834
- }
835
- observations.delete(target);
836
- if (!observations.size) {
837
- this.controller_.removeObserver(this);
838
- }
839
- };
840
- /**
841
- * Stops observing all elements.
842
- *
843
- * @returns {void}
844
- */
845
- ResizeObserverSPI.prototype.disconnect = function () {
846
- this.clearActive();
847
- this.observations_.clear();
848
- this.controller_.removeObserver(this);
849
- };
850
- /**
851
- * Collects observation instances the associated element of which has changed
852
- * it's content rectangle.
853
- *
854
- * @returns {void}
855
- */
856
- ResizeObserverSPI.prototype.gatherActive = function () {
857
- var _this = this;
858
- this.clearActive();
859
- this.observations_.forEach(function (observation) {
860
- if (observation.isActive()) {
861
- _this.activeObservations_.push(observation);
862
- }
863
- });
864
- };
865
- /**
866
- * Invokes initial callback function with a list of ResizeObserverEntry
867
- * instances collected from active resize observations.
868
- *
869
- * @returns {void}
870
- */
871
- ResizeObserverSPI.prototype.broadcastActive = function () {
872
- // Do nothing if observer doesn't have active observations.
873
- if (!this.hasActive()) {
874
- return;
875
- }
876
- var ctx = this.callbackCtx_;
877
- // Create ResizeObserverEntry instance for every active observation.
878
- var entries = this.activeObservations_.map(function (observation) {
879
- return new ResizeObserverEntry(observation.target, observation.broadcastRect());
880
- });
881
- this.callback_.call(ctx, entries, ctx);
882
- this.clearActive();
883
- };
884
- /**
885
- * Clears the collection of active observations.
886
- *
887
- * @returns {void}
888
- */
889
- ResizeObserverSPI.prototype.clearActive = function () {
890
- this.activeObservations_.splice(0);
891
- };
892
- /**
893
- * Tells whether observer has active observations.
894
- *
895
- * @returns {boolean}
896
- */
897
- ResizeObserverSPI.prototype.hasActive = function () {
898
- return this.activeObservations_.length > 0;
899
- };
900
- return ResizeObserverSPI;
901
- }());
902
-
903
- // Registry of internal observers. If WeakMap is not available use current shim
904
- // for the Map collection as it has all required methods and because WeakMap
905
- // can't be fully polyfilled anyway.
906
- var observers = typeof WeakMap !== 'undefined' ? new WeakMap() : new MapShim();
907
- /**
908
- * ResizeObserver API. Encapsulates the ResizeObserver SPI implementation
909
- * exposing only those methods and properties that are defined in the spec.
910
- */
911
- var ResizeObserver$1 = /** @class */ (function () {
912
- /**
913
- * Creates a new instance of ResizeObserver.
914
- *
915
- * @param {ResizeObserverCallback} callback - Callback that is invoked when
916
- * dimensions of the observed elements change.
917
- */
918
- function ResizeObserver(callback) {
919
- if (!(this instanceof ResizeObserver)) {
920
- throw new TypeError('Cannot call a class as a function.');
921
- }
922
- if (!arguments.length) {
923
- throw new TypeError('1 argument required, but only 0 present.');
924
- }
925
- var controller = ResizeObserverController.getInstance();
926
- var observer = new ResizeObserverSPI(callback, controller, this);
927
- observers.set(this, observer);
928
- }
929
- return ResizeObserver;
930
- }());
931
- // Expose public methods of ResizeObserver.
932
- [
933
- 'observe',
934
- 'unobserve',
935
- 'disconnect'
936
- ].forEach(function (method) {
937
- ResizeObserver$1.prototype[method] = function () {
938
- var _a;
939
- return (_a = observers.get(this))[method].apply(_a, arguments);
940
- };
941
- });
942
-
943
- var index = (function () {
944
- // Export existing implementation if available.
945
- if (typeof global$1.ResizeObserver !== 'undefined') {
946
- return global$1.ResizeObserver;
947
- }
948
- return ResizeObserver$1;
949
- })();
950
-
951
- var ResizeObserver_es = /*#__PURE__*/Object.freeze({
952
- __proto__: null,
953
- default: index
954
- });
955
-
956
- var require$$0 = /*@__PURE__*/_commonjsHelpers.getAugmentedNamespace(ResizeObserver_es);
957
-
958
- function _interopDefault$1 (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
959
-
960
- var ResizeObserver = _interopDefault$1(require$$0);
961
- var react = React;
962
-
963
- function useResizeObserver$1(opts) {
964
- if (opts === void 0) {
965
- opts = {};
966
- }
967
-
968
- // `defaultRef` Has to be non-conditionally declared here whether or not it'll
969
- // be used as that's how hooks work.
970
- // @see https://reactjs.org/docs/hooks-rules.html#explanation
971
- var defaultRef = react.useRef(null); // Saving the callback as a ref. With this, I don't need to put onResize in the
972
- // effect dep array, and just passing in an anonymous function without memoising
973
- // will not reinstantiate the hook's ResizeObserver
974
-
975
- var onResize = opts.onResize;
976
- var onResizeRef = react.useRef(undefined);
977
- onResizeRef.current = onResize; // Using a single instance throughought the hook's lifetime
978
-
979
- var resizeObserverRef = react.useRef();
980
- var ref = opts.ref || defaultRef;
981
-
982
- var _useState = react.useState({
983
- width: undefined,
984
- height: undefined
985
- }),
986
- size = _useState[0],
987
- setSize = _useState[1]; // Using a ref to track the previous width / height to avoid unnecessary renders
988
-
989
-
990
- var previous = react.useRef({
991
- width: undefined,
992
- height: undefined
993
- });
994
- react.useEffect(function () {
995
- if (resizeObserverRef.current) {
996
- return;
997
- }
998
-
999
- resizeObserverRef.current = new ResizeObserver(function (entries) {
1000
- if (!Array.isArray(entries)) {
1001
- return;
1002
- } // Since we only observe the one element, we don't need to loop over the
1003
- // array
1004
-
1005
-
1006
- if (!entries.length) {
1007
- return;
1008
- }
1009
-
1010
- var entry = entries[0]; // `Math.round` is in line with how CSS resolves sub-pixel values
1011
-
1012
- var newWidth = Math.round(entry.contentRect.width);
1013
- var newHeight = Math.round(entry.contentRect.height);
1014
-
1015
- if (previous.current.width !== newWidth || previous.current.height !== newHeight) {
1016
- var newSize = {
1017
- width: newWidth,
1018
- height: newHeight
1019
- };
1020
-
1021
- if (onResizeRef.current) {
1022
- onResizeRef.current(newSize);
1023
- } else {
1024
- previous.current.width = newWidth;
1025
- previous.current.height = newHeight;
1026
- setSize(newSize);
1027
- }
1028
- }
1029
- });
1030
- }, []);
1031
- react.useEffect(function () {
1032
- if (typeof ref !== "object" || ref === null || !(ref.current instanceof Element)) {
1033
- return;
1034
- }
1035
-
1036
- var element = ref.current;
1037
- resizeObserverRef.current.observe(element);
1038
- return function () {
1039
- return resizeObserverRef.current.unobserve(element);
1040
- };
1041
- }, [ref]);
1042
- return react.useMemo(function () {
1043
- return {
1044
- ref: ref,
1045
- width: size.width,
1046
- height: size.height
1047
- };
1048
- }, [ref, size ? size.width : null, size ? size.height : null]);
1049
- }
1050
-
1051
- var polyfilled = useResizeObserver$1;
1052
-
1053
- (function (exports) {
1054
- var __importDefault = (_commonjsHelpers.commonjsGlobal && _commonjsHelpers.commonjsGlobal.__importDefault) || function (mod) {
1055
- return (mod && mod.__esModule) ? mod : { "default": mod };
1056
- };
1057
- Object.defineProperty(exports, "__esModule", { value: true });
1058
- exports.Breakpoints = void 0;
1059
- exports.useResizeObserver = useResizeObserver;
1060
- const react_1 = React;
1061
- // Importing the polyfilled version of ResizeObserver
1062
- // eslint-disable-next-line import/no-internal-modules
1063
- const polyfilled_1 = __importDefault(polyfilled);
1064
- const throttle_1 = __importDefault(throttle$1.throttle_1);
1065
- exports.Breakpoints = {
1066
- base: 640,
1067
- small: 500,
1068
- smaller: 265,
1069
- large: 750,
1070
- larger: 1024,
1071
- };
1072
- const wait = 100;
1073
- function useResizeObserver({ widths = exports.Breakpoints, heights = exports.Breakpoints, } = {}) {
1074
- const [exactSize, setSize] = (0, react_1.useState)({
1075
- width: undefined,
1076
- height: undefined,
1077
- });
1078
- const onResize = (0, react_1.useMemo)(() => {
1079
- return (0, throttle_1.default)(({ width, height }) => {
1080
- if (!width || width <= 1) {
1081
- // Ignore invalid values. ResizeObserver is unexpectedly looping between 1 and the actual
1082
- // width of the element. This is only happening in playwright chromium.
1083
- // Soon we need to replace this unmaintained package with a more reliable one.
1084
- return;
1085
- }
1086
- setSize({ width, height });
1087
- }, wait);
1088
- }, []);
1089
- const { ref } = (0, polyfilled_1.default)({
1090
- onResize,
1091
- });
1092
- const exactWidth = exactSize.width;
1093
- const exactHeight = exactSize.height;
1094
- const sizes = {
1095
- width: getSize(widths, exactSize.width),
1096
- height: getSize(heights, exactSize.height),
1097
- exactWidth,
1098
- exactHeight,
1099
- };
1100
- return [ref, sizes];
1101
- }
1102
- /**
1103
- * To get the proper size we want to make sure that our value is greater
1104
- * then the comparable, but less then the next largest number in our
1105
- * object.
1106
- */
1107
- function getSize(sizes, comparable) {
1108
- if (!comparable || !sizes) {
1109
- return undefined;
1110
- }
1111
- /**
1112
- * Sort the values of our object so that we know they are in proper
1113
- * order to be compared by
1114
- */
1115
- const sortedSizes = Object.values(sizes)
1116
- .sort((a, b) => a - b)
1117
- .reverse();
1118
- return (sortedSizes.find(value => value <= comparable) ||
1119
- sortedSizes[sortedSizes.length - 1]);
1120
- }
1121
- } (useResizeObserver$2));
1122
-
1123
- var useResizeObserver = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(useResizeObserver$2);
1124
-
1125
- var jobberHooks = /*#__PURE__*/_mergeNamespaces({
1126
- __proto__: null,
1127
- default: useResizeObserver
1128
- }, [useResizeObserver$2]);
1129
-
1130
- exports.jobberHooks = jobberHooks;
1131
- exports.useResizeObserver = useResizeObserver$2;