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