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