@sankhyalabs/core 5.20.0-dev.8 → 5.20.0-dev.9
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/.docs/classes/OverflowWatcher.md +269 -0
- package/.docs/enumerations/OverflowDirection.md +29 -0
- package/.docs/globals.md +6 -0
- package/.docs/type-aliases/OnOverflowCallBack.md +25 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/OverflowWatcher/index.d.ts +31 -0
- package/dist/utils/OverflowWatcher/index.js +107 -0
- package/dist/utils/OverflowWatcher/index.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/utils/OverflowWatcher/index.ts +151 -0
- package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
- package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
- package/test/util/OverflowWatcher.spec.ts +118 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
[**@sankhyalabs/core**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@sankhyalabs/core](../globals.md) / OverflowWatcher
|
|
6
|
+
|
|
7
|
+
# Class: OverflowWatcher
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### new OverflowWatcher()
|
|
12
|
+
|
|
13
|
+
> **new OverflowWatcher**(`element`, `callback`, `overFlowDirection`, `deltaSize`): [`OverflowWatcher`](OverflowWatcher.md)
|
|
14
|
+
|
|
15
|
+
Cria uma instancia do OverflowWatcher
|
|
16
|
+
|
|
17
|
+
#### Parameters
|
|
18
|
+
|
|
19
|
+
• **element**: `HTMLElement`
|
|
20
|
+
|
|
21
|
+
Elemento HTML que o overflow será observado.
|
|
22
|
+
|
|
23
|
+
• **callback**: [`OnOverflowCallBack`](../type-aliases/OnOverflowCallBack.md)
|
|
24
|
+
|
|
25
|
+
Função que sera chamada quando ocorrer overflow no elemento.
|
|
26
|
+
|
|
27
|
+
• **overFlowDirection**: [`OverflowDirection`](../enumerations/OverflowDirection.md)= `OverflowDirection.HORIZONTAL`
|
|
28
|
+
|
|
29
|
+
Indica direção que o overflow será monitorado.
|
|
30
|
+
|
|
31
|
+
• **deltaSize**: `number`= `10`
|
|
32
|
+
|
|
33
|
+
Variação de tamanho que será considerada como overflow.
|
|
34
|
+
|
|
35
|
+
#### Returns
|
|
36
|
+
|
|
37
|
+
[`OverflowWatcher`](OverflowWatcher.md)
|
|
38
|
+
|
|
39
|
+
#### Source
|
|
40
|
+
|
|
41
|
+
src/utils/OverflowWatcher/index.ts:25
|
|
42
|
+
|
|
43
|
+
## Properties
|
|
44
|
+
|
|
45
|
+
### \_deltaSize
|
|
46
|
+
|
|
47
|
+
> `private` **\_deltaSize**: `number`
|
|
48
|
+
|
|
49
|
+
#### Source
|
|
50
|
+
|
|
51
|
+
src/utils/OverflowWatcher/index.ts:15
|
|
52
|
+
|
|
53
|
+
***
|
|
54
|
+
|
|
55
|
+
### \_hiddenItems
|
|
56
|
+
|
|
57
|
+
> `private` **\_hiddenItems**: `Element`[] = `[]`
|
|
58
|
+
|
|
59
|
+
#### Source
|
|
60
|
+
|
|
61
|
+
src/utils/OverflowWatcher/index.ts:14
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### \_lastContentRect
|
|
66
|
+
|
|
67
|
+
> `private` **\_lastContentRect**: `undefined` \| `DOMRectReadOnly` = `undefined`
|
|
68
|
+
|
|
69
|
+
#### Source
|
|
70
|
+
|
|
71
|
+
src/utils/OverflowWatcher/index.ts:11
|
|
72
|
+
|
|
73
|
+
***
|
|
74
|
+
|
|
75
|
+
### \_onResize
|
|
76
|
+
|
|
77
|
+
> `private` **\_onResize**: [`OnOverflowCallBack`](../type-aliases/OnOverflowCallBack.md)
|
|
78
|
+
|
|
79
|
+
#### Source
|
|
80
|
+
|
|
81
|
+
src/utils/OverflowWatcher/index.ts:9
|
|
82
|
+
|
|
83
|
+
***
|
|
84
|
+
|
|
85
|
+
### \_propSize
|
|
86
|
+
|
|
87
|
+
> `private` **\_propSize**: `string`
|
|
88
|
+
|
|
89
|
+
#### Source
|
|
90
|
+
|
|
91
|
+
src/utils/OverflowWatcher/index.ts:13
|
|
92
|
+
|
|
93
|
+
***
|
|
94
|
+
|
|
95
|
+
### \_resizeObserver
|
|
96
|
+
|
|
97
|
+
> `private` **\_resizeObserver**: `ResizeObserver`
|
|
98
|
+
|
|
99
|
+
#### Source
|
|
100
|
+
|
|
101
|
+
src/utils/OverflowWatcher/index.ts:10
|
|
102
|
+
|
|
103
|
+
***
|
|
104
|
+
|
|
105
|
+
### \_scrollDirection
|
|
106
|
+
|
|
107
|
+
> `private` **\_scrollDirection**: [`OverflowDirection`](../enumerations/OverflowDirection.md) = `OverflowDirection.HORIZONTAL`
|
|
108
|
+
|
|
109
|
+
#### Source
|
|
110
|
+
|
|
111
|
+
src/utils/OverflowWatcher/index.ts:12
|
|
112
|
+
|
|
113
|
+
## Methods
|
|
114
|
+
|
|
115
|
+
### calcChildrenSize()
|
|
116
|
+
|
|
117
|
+
> `private` **calcChildrenSize**(`children`): `number`
|
|
118
|
+
|
|
119
|
+
#### Parameters
|
|
120
|
+
|
|
121
|
+
• **children**: `Element`[]
|
|
122
|
+
|
|
123
|
+
#### Returns
|
|
124
|
+
|
|
125
|
+
`number`
|
|
126
|
+
|
|
127
|
+
#### Source
|
|
128
|
+
|
|
129
|
+
src/utils/OverflowWatcher/index.ts:126
|
|
130
|
+
|
|
131
|
+
***
|
|
132
|
+
|
|
133
|
+
### calcMarginSize()
|
|
134
|
+
|
|
135
|
+
> `private` **calcMarginSize**(`el`): `number`
|
|
136
|
+
|
|
137
|
+
#### Parameters
|
|
138
|
+
|
|
139
|
+
• **el**: `Element`
|
|
140
|
+
|
|
141
|
+
#### Returns
|
|
142
|
+
|
|
143
|
+
`number`
|
|
144
|
+
|
|
145
|
+
#### Source
|
|
146
|
+
|
|
147
|
+
src/utils/OverflowWatcher/index.ts:141
|
|
148
|
+
|
|
149
|
+
***
|
|
150
|
+
|
|
151
|
+
### destroy()
|
|
152
|
+
|
|
153
|
+
> **destroy**(): `void`
|
|
154
|
+
|
|
155
|
+
#### Returns
|
|
156
|
+
|
|
157
|
+
`void`
|
|
158
|
+
|
|
159
|
+
#### Source
|
|
160
|
+
|
|
161
|
+
src/utils/OverflowWatcher/index.ts:37
|
|
162
|
+
|
|
163
|
+
***
|
|
164
|
+
|
|
165
|
+
### getPropSizeByDirection()
|
|
166
|
+
|
|
167
|
+
> `private` **getPropSizeByDirection**(): `string`
|
|
168
|
+
|
|
169
|
+
#### Returns
|
|
170
|
+
|
|
171
|
+
`string`
|
|
172
|
+
|
|
173
|
+
#### Source
|
|
174
|
+
|
|
175
|
+
src/utils/OverflowWatcher/index.ts:65
|
|
176
|
+
|
|
177
|
+
***
|
|
178
|
+
|
|
179
|
+
### handleResize()
|
|
180
|
+
|
|
181
|
+
> `private` **handleResize**(`entries`): `void`
|
|
182
|
+
|
|
183
|
+
#### Parameters
|
|
184
|
+
|
|
185
|
+
• **entries**: `ResizeObserverEntry`[]
|
|
186
|
+
|
|
187
|
+
#### Returns
|
|
188
|
+
|
|
189
|
+
`void`
|
|
190
|
+
|
|
191
|
+
#### Source
|
|
192
|
+
|
|
193
|
+
src/utils/OverflowWatcher/index.ts:41
|
|
194
|
+
|
|
195
|
+
***
|
|
196
|
+
|
|
197
|
+
### isChangedSize()
|
|
198
|
+
|
|
199
|
+
> `private` **isChangedSize**(`newContentRect`): `boolean`
|
|
200
|
+
|
|
201
|
+
#### Parameters
|
|
202
|
+
|
|
203
|
+
• **newContentRect**: `DOMRectReadOnly`
|
|
204
|
+
|
|
205
|
+
#### Returns
|
|
206
|
+
|
|
207
|
+
`boolean`
|
|
208
|
+
|
|
209
|
+
#### Source
|
|
210
|
+
|
|
211
|
+
src/utils/OverflowWatcher/index.ts:57
|
|
212
|
+
|
|
213
|
+
***
|
|
214
|
+
|
|
215
|
+
### proccessElements()
|
|
216
|
+
|
|
217
|
+
> `private` **proccessElements**(`elementSize`, `children`): `void`
|
|
218
|
+
|
|
219
|
+
#### Parameters
|
|
220
|
+
|
|
221
|
+
• **elementSize**: `number`
|
|
222
|
+
|
|
223
|
+
• **children**: `Element`[]
|
|
224
|
+
|
|
225
|
+
#### Returns
|
|
226
|
+
|
|
227
|
+
`void`
|
|
228
|
+
|
|
229
|
+
#### Source
|
|
230
|
+
|
|
231
|
+
src/utils/OverflowWatcher/index.ts:73
|
|
232
|
+
|
|
233
|
+
***
|
|
234
|
+
|
|
235
|
+
### proccessElementsOverFlow()
|
|
236
|
+
|
|
237
|
+
> `private` **proccessElementsOverFlow**(`children`, `diff`): `void`
|
|
238
|
+
|
|
239
|
+
#### Parameters
|
|
240
|
+
|
|
241
|
+
• **children**: `Element`[]
|
|
242
|
+
|
|
243
|
+
• **diff**: `number`
|
|
244
|
+
|
|
245
|
+
#### Returns
|
|
246
|
+
|
|
247
|
+
`void`
|
|
248
|
+
|
|
249
|
+
#### Source
|
|
250
|
+
|
|
251
|
+
src/utils/OverflowWatcher/index.ts:103
|
|
252
|
+
|
|
253
|
+
***
|
|
254
|
+
|
|
255
|
+
### proccessElementsWithoutOverFlow()
|
|
256
|
+
|
|
257
|
+
> `private` **proccessElementsWithoutOverFlow**(`diff`): `void`
|
|
258
|
+
|
|
259
|
+
#### Parameters
|
|
260
|
+
|
|
261
|
+
• **diff**: `number`
|
|
262
|
+
|
|
263
|
+
#### Returns
|
|
264
|
+
|
|
265
|
+
`void`
|
|
266
|
+
|
|
267
|
+
#### Source
|
|
268
|
+
|
|
269
|
+
src/utils/OverflowWatcher/index.ts:91
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[**@sankhyalabs/core**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@sankhyalabs/core](../globals.md) / OverflowDirection
|
|
6
|
+
|
|
7
|
+
# Enumeration: OverflowDirection
|
|
8
|
+
|
|
9
|
+
Define em qual direção o overflow será observado
|
|
10
|
+
|
|
11
|
+
## Enumeration Members
|
|
12
|
+
|
|
13
|
+
### HORIZONTAL
|
|
14
|
+
|
|
15
|
+
> **HORIZONTAL**: `1`
|
|
16
|
+
|
|
17
|
+
#### Source
|
|
18
|
+
|
|
19
|
+
src/utils/OverflowWatcher/types/overflow-direction.ts:6
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### VERTICAL
|
|
24
|
+
|
|
25
|
+
> **VERTICAL**: `0`
|
|
26
|
+
|
|
27
|
+
#### Source
|
|
28
|
+
|
|
29
|
+
src/utils/OverflowWatcher/types/overflow-direction.ts:5
|
package/.docs/globals.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
- [ChangeOperation](enumerations/ChangeOperation.md)
|
|
15
15
|
- [DataType](enumerations/DataType.md)
|
|
16
16
|
- [DependencyType](enumerations/DependencyType.md)
|
|
17
|
+
- [OverflowDirection](enumerations/OverflowDirection.md)
|
|
17
18
|
- [SelectionMode](enumerations/SelectionMode.md)
|
|
18
19
|
- [SortMode](enumerations/SortMode.md)
|
|
19
20
|
- [UserInterface](enumerations/UserInterface.md)
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
- [NumberUtils](classes/NumberUtils.md)
|
|
43
44
|
- [ObjectUtils](classes/ObjectUtils.md)
|
|
44
45
|
- [OnboardingUtils](classes/OnboardingUtils.md)
|
|
46
|
+
- [OverflowWatcher](classes/OverflowWatcher.md)
|
|
45
47
|
- [PromiseSync](classes/PromiseSync.md)
|
|
46
48
|
- [ReadyUtil](classes/ReadyUtil.md)
|
|
47
49
|
- [RequestMetadata](classes/RequestMetadata.md)
|
|
@@ -80,6 +82,10 @@
|
|
|
80
82
|
- [UnitMetadata](interfaces/UnitMetadata.md)
|
|
81
83
|
- [WaitingChange](interfaces/WaitingChange.md)
|
|
82
84
|
|
|
85
|
+
## Type Aliases
|
|
86
|
+
|
|
87
|
+
- [OnOverflowCallBack](type-aliases/OnOverflowCallBack.md)
|
|
88
|
+
|
|
83
89
|
## Functions
|
|
84
90
|
|
|
85
91
|
- [defaultDataLoader](functions/defaultDataLoader.md)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[**@sankhyalabs/core**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@sankhyalabs/core](../globals.md) / OnOverflowCallBack
|
|
6
|
+
|
|
7
|
+
# Type alias: OnOverflowCallBack()
|
|
8
|
+
|
|
9
|
+
> **OnOverflowCallBack**: (`elementsOverFlow`) => `void`
|
|
10
|
+
|
|
11
|
+
Callback que será chamado quando o overflow de um elemento for alterado.
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
• **elementsOverFlow**: `Element`[]
|
|
16
|
+
|
|
17
|
+
Conjunto de elementos filhos que estão causando overflow no elemento pai.
|
|
18
|
+
|
|
19
|
+
## Returns
|
|
20
|
+
|
|
21
|
+
`void`
|
|
22
|
+
|
|
23
|
+
## Source
|
|
24
|
+
|
|
25
|
+
src/utils/OverflowWatcher/types/overflow-callback.ts:6
|
package/dist/index.d.ts
CHANGED
|
@@ -39,4 +39,5 @@ import { IRepositoryIndex } from "./repository/indexeddb/IRepositoryIndex.js";
|
|
|
39
39
|
import { FieldComparator } from "./dataunit/sorting/FieldComparator.js";
|
|
40
40
|
import { KeyboardManager } from "./utils/KeyboardManager/index.js";
|
|
41
41
|
import { SearchUtils } from "./utils/SearchUtils.js";
|
|
42
|
-
|
|
42
|
+
import OverflowWatcher, { OnOverflowCallBack, OverflowDirection } from "./utils/OverflowWatcher/index.js";
|
|
43
|
+
export { StringUtils, MaskFormatter, NumberUtils, FloatingManager, DateUtils, ArrayUtils, TimeFormatter, SkwHttpProvider, HttpProvider, RequestMetadata, AuthorizedServiceCaller, DataUnit, DataUnitStorage, Record, SavedRecord, DataType, UnitMetadata, FieldDescriptor, UserInterface, DependencyType, ChildDescriptor, ChildLink, DataUnitAction, Action, Change, Sort, Filter, ChangeOperation, DUActionInterceptor, ApplicationContext, WaitingChange, PageRequest, QuickFilter, ReadyUtil, ObjectUtils, WarningException, WaitingChangeException, ErrorException, ErrorTracking, ExecutionContext, PaginationInfo, SortingProvider, SortMode, LoadDataRequest, LoadDataResponse, SelectionInfo, SelectionMode, ElementIDUtils, IElementIDInfo, UserAgentUtils, JSUtils, VersionUtils, OnboardingUtils, PromiseSync, PromiseSyncCallback, HTMLBuilder, IRepository, IDBRepository, ILoadResult, IRepositoryIndex, FieldComparator, defaultDataLoader, KeyboardManager, SearchUtils, OverflowWatcher, OnOverflowCallBack, OverflowDirection };
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ import { IDBRepository } from "./repository/indexeddb/IDBRepository.js";
|
|
|
33
33
|
import { FieldComparator } from "./dataunit/sorting/FieldComparator.js";
|
|
34
34
|
import { KeyboardManager } from "./utils/KeyboardManager/index.js";
|
|
35
35
|
import { SearchUtils } from "./utils/SearchUtils.js";
|
|
36
|
+
import OverflowWatcher, { OverflowDirection } from "./utils/OverflowWatcher/index.js";
|
|
36
37
|
/*Classes públicas no pacote*/
|
|
37
|
-
export { StringUtils, MaskFormatter, NumberUtils, FloatingManager, DateUtils, ArrayUtils, TimeFormatter, SkwHttpProvider, HttpProvider, RequestMetadata, AuthorizedServiceCaller, DataUnit, DataUnitStorage, DataType, UserInterface, DependencyType, DataUnitAction, Action, Change, ChangeOperation, ApplicationContext, ReadyUtil, ObjectUtils, WarningException, WaitingChangeException, ErrorException, ErrorTracking, SortMode, SelectionInfo, SelectionMode, ElementIDUtils, UserAgentUtils, JSUtils, VersionUtils, OnboardingUtils, PromiseSync, HTMLBuilder, IDBRepository, FieldComparator, defaultDataLoader, KeyboardManager, SearchUtils, };
|
|
38
|
+
export { StringUtils, MaskFormatter, NumberUtils, FloatingManager, DateUtils, ArrayUtils, TimeFormatter, SkwHttpProvider, HttpProvider, RequestMetadata, AuthorizedServiceCaller, DataUnit, DataUnitStorage, DataType, UserInterface, DependencyType, DataUnitAction, Action, Change, ChangeOperation, ApplicationContext, ReadyUtil, ObjectUtils, WarningException, WaitingChangeException, ErrorException, ErrorTracking, SortMode, SelectionInfo, SelectionMode, ElementIDUtils, UserAgentUtils, JSUtils, VersionUtils, OnboardingUtils, PromiseSync, HTMLBuilder, IDBRepository, FieldComparator, defaultDataLoader, KeyboardManager, SearchUtils, OverflowWatcher, OverflowDirection };
|
|
38
39
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;A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eAAe,EACf,WAAW,EACX,eAAe,EAEf,iBAAiB,EACpB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OverflowDirection } from "./types/overflow-direction.js";
|
|
2
|
+
import { OnOverflowCallBack } from "./types/overflow-callback.js";
|
|
3
|
+
export * from "./types/overflow-direction.js";
|
|
4
|
+
export * from "./types/overflow-callback.js";
|
|
5
|
+
export default class OverflowWatcher {
|
|
6
|
+
private _onResize;
|
|
7
|
+
private _resizeObserver;
|
|
8
|
+
private _lastContentRect;
|
|
9
|
+
private _scrollDirection;
|
|
10
|
+
private _propSize;
|
|
11
|
+
private _hiddenItems;
|
|
12
|
+
private _deltaSize;
|
|
13
|
+
/**
|
|
14
|
+
* Cria uma instancia do OverflowWatcher
|
|
15
|
+
*
|
|
16
|
+
* @param element - Elemento HTML que o overflow será observado.
|
|
17
|
+
* @param callback - Função que sera chamada quando ocorrer overflow no elemento.
|
|
18
|
+
* @param overFlowDirection - Indica direção que o overflow será monitorado.
|
|
19
|
+
* @param deltaSize - Variação de tamanho que será considerada como overflow.
|
|
20
|
+
*/
|
|
21
|
+
constructor(element: HTMLElement, callback: OnOverflowCallBack, overFlowDirection?: OverflowDirection, deltaSize?: number);
|
|
22
|
+
destroy(): void;
|
|
23
|
+
private handleResize;
|
|
24
|
+
private isChangedSize;
|
|
25
|
+
private getPropSizeByDirection;
|
|
26
|
+
private proccessElements;
|
|
27
|
+
private proccessElementsWithoutOverFlow;
|
|
28
|
+
private proccessElementsOverFlow;
|
|
29
|
+
private calcChildrenSize;
|
|
30
|
+
private calcMarginSize;
|
|
31
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { JSUtils } from "../JSUtils.js";
|
|
2
|
+
import { OverflowDirection } from "./types/overflow-direction.js";
|
|
3
|
+
export * from "./types/overflow-direction.js";
|
|
4
|
+
export * from "./types/overflow-callback.js";
|
|
5
|
+
export default class OverflowWatcher {
|
|
6
|
+
/**
|
|
7
|
+
* Cria uma instancia do OverflowWatcher
|
|
8
|
+
*
|
|
9
|
+
* @param element - Elemento HTML que o overflow será observado.
|
|
10
|
+
* @param callback - Função que sera chamada quando ocorrer overflow no elemento.
|
|
11
|
+
* @param overFlowDirection - Indica direção que o overflow será monitorado.
|
|
12
|
+
* @param deltaSize - Variação de tamanho que será considerada como overflow.
|
|
13
|
+
*/
|
|
14
|
+
constructor(element, callback, overFlowDirection = OverflowDirection.HORIZONTAL, deltaSize = 10) {
|
|
15
|
+
this._lastContentRect = undefined;
|
|
16
|
+
this._scrollDirection = OverflowDirection.HORIZONTAL;
|
|
17
|
+
this._hiddenItems = [];
|
|
18
|
+
this._onResize = callback;
|
|
19
|
+
this._scrollDirection = overFlowDirection;
|
|
20
|
+
this._resizeObserver = new ResizeObserver(JSUtils.debounce((entries) => this.handleResize(entries), 200));
|
|
21
|
+
this._resizeObserver.observe(element);
|
|
22
|
+
this._propSize = this.getPropSizeByDirection();
|
|
23
|
+
this._deltaSize = deltaSize;
|
|
24
|
+
}
|
|
25
|
+
destroy() {
|
|
26
|
+
this._resizeObserver.disconnect();
|
|
27
|
+
}
|
|
28
|
+
handleResize(entries) {
|
|
29
|
+
if (!entries || entries.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const resizeItem = entries[0];
|
|
33
|
+
const contentRect = resizeItem.contentRect;
|
|
34
|
+
if (this.isChangedSize(contentRect)) {
|
|
35
|
+
const children = Array.from(resizeItem.target.children);
|
|
36
|
+
this.proccessElements(contentRect[this._propSize], children);
|
|
37
|
+
this._lastContentRect = contentRect;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
isChangedSize(newContentRect) {
|
|
41
|
+
if (this._lastContentRect == undefined) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return Math.abs(newContentRect[this._propSize] - this._lastContentRect[this._propSize]) >= this._deltaSize;
|
|
45
|
+
}
|
|
46
|
+
getPropSizeByDirection() {
|
|
47
|
+
if (OverflowDirection.HORIZONTAL === this._scrollDirection) {
|
|
48
|
+
return "width";
|
|
49
|
+
}
|
|
50
|
+
return "height";
|
|
51
|
+
}
|
|
52
|
+
proccessElements(elementSize, children) {
|
|
53
|
+
if (children.length === 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const childrenSize = this.calcChildrenSize(children);
|
|
57
|
+
let diff = Number((elementSize - childrenSize).toFixed(4));
|
|
58
|
+
if (diff > 0) {
|
|
59
|
+
this.proccessElementsWithoutOverFlow(diff);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.proccessElementsOverFlow(children, diff);
|
|
63
|
+
}
|
|
64
|
+
proccessElementsWithoutOverFlow(diff) {
|
|
65
|
+
this._hiddenItems.forEach((item) => {
|
|
66
|
+
if (item.getBoundingClientRect().width < diff) {
|
|
67
|
+
this._hiddenItems.pop();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this._onResize(this._hiddenItems);
|
|
71
|
+
}
|
|
72
|
+
proccessElementsOverFlow(children, diff) {
|
|
73
|
+
const elementsOverflow = [];
|
|
74
|
+
let sumRemovedItems = 0;
|
|
75
|
+
while (elementsOverflow.length < children.length && sumRemovedItems < (diff * -1)) {
|
|
76
|
+
const itemToRemove = children.pop();
|
|
77
|
+
if (itemToRemove != undefined && itemToRemove.style.display === 'none') {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (itemToRemove != undefined) {
|
|
81
|
+
elementsOverflow.push(itemToRemove);
|
|
82
|
+
sumRemovedItems += itemToRemove.getBoundingClientRect()[this._propSize];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
this._hiddenItems = elementsOverflow;
|
|
86
|
+
this._onResize(elementsOverflow);
|
|
87
|
+
}
|
|
88
|
+
calcChildrenSize(children) {
|
|
89
|
+
let sumChildren = 0;
|
|
90
|
+
Array.from(children).forEach(el => {
|
|
91
|
+
sumChildren += el.getBoundingClientRect()[this._propSize];
|
|
92
|
+
sumChildren += this.calcMarginSize(el);
|
|
93
|
+
});
|
|
94
|
+
if (sumChildren > 0) {
|
|
95
|
+
sumChildren += this._deltaSize;
|
|
96
|
+
}
|
|
97
|
+
return sumChildren;
|
|
98
|
+
}
|
|
99
|
+
calcMarginSize(el) {
|
|
100
|
+
const computedStyle = getComputedStyle(el);
|
|
101
|
+
if (OverflowDirection.HORIZONTAL === this._scrollDirection) {
|
|
102
|
+
return (parseInt(computedStyle.marginLeft || '0') + parseInt(computedStyle.marginRight || '0'));
|
|
103
|
+
}
|
|
104
|
+
return (parseInt(computedStyle.marginTop || '0') + parseInt(computedStyle.marginBottom || '0'));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/OverflowWatcher/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAGjE,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,eAAe;IAShC;;;;;;;OAOG;IACH,YAAY,OAAmB,EACnB,QAA2B,EAC3B,oBAAsC,iBAAiB,CAAC,UAAU,EAClE,YAAmB,EAAE;QAjBzB,qBAAgB,GAA6B,SAAS,CAAC;QACvD,qBAAgB,GAAG,iBAAiB,CAAC,UAAU,CAAC;QAEhD,iBAAY,GAAa,EAAE,CAAC;QAehC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,gBAAgB,GAAG,iBAAiB,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAA8B,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC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AAC;gBACpC,eAAe,IAAK,YAAY,CAAC,qBAAqB,EAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACpF;SACJ;QAGD,IAAI,CAAC,YAAY,GAAG,gBAAgB,CAAC;QACrC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAErC,CAAC;IAEO,gBAAgB,CAAC,QAAkB;QACvC,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YAC9B,WAAW,IAAK,EAAE,CAAC,qBAAqB,EAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnE,WAAW,IAAI,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,IAAG,WAAW,GAAG,CAAC,EAAC;YACf,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC;SAClC;QAED,OAAO,WAAW,CAAC;IACvB,CAAC;IAEO,cAAc,CAAC,EAAU;QAC7B,MAAM,aAAa,GAAG,gBAAgB,CAAC,EAAE,CAAC,CAAC;QAE3C,IAAG,iBAAiB,CAAC,UAAU,KAAK,IAAI,CAAC,gBAAgB,EAAC;YACvD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,IAAI,GAAG,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,WAAW,IAAI,GAAG,CAAC,CAAC,CAAC;SAClG;QAED,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,YAAY,IAAI,GAAG,CAAC,CAAC,CAAC;IACpG,CAAC;CAEJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback que será chamado quando o overflow de um elemento for alterado.
|
|
3
|
+
*
|
|
4
|
+
* @param elementsOverFlow - Conjunto de elementos filhos que estão causando overflow no elemento pai.
|
|
5
|
+
*/
|
|
6
|
+
export type OnOverflowCallBack = (elementsOverFlow: Array<Element>) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overflow-callback.js","sourceRoot":"","sources":["../../../../src/utils/OverflowWatcher/types/overflow-callback.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define em qual direção o overflow será observado
|
|
3
|
+
*/
|
|
4
|
+
export var OverflowDirection;
|
|
5
|
+
(function (OverflowDirection) {
|
|
6
|
+
OverflowDirection[OverflowDirection["VERTICAL"] = 0] = "VERTICAL";
|
|
7
|
+
OverflowDirection[OverflowDirection["HORIZONTAL"] = 1] = "HORIZONTAL";
|
|
8
|
+
})(OverflowDirection || (OverflowDirection = {}));
|
|
9
|
+
//# sourceMappingURL=overflow-direction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overflow-direction.js","sourceRoot":"","sources":["../../../../src/utils/OverflowWatcher/types/overflow-direction.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IACzB,iEAAU,CAAA;IACV,qEAAY,CAAA;AAChB,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ import { IRepositoryIndex } from "./repository/indexeddb/IRepositoryIndex.js"
|
|
|
39
39
|
import { FieldComparator } from "./dataunit/sorting/FieldComparator.js";
|
|
40
40
|
import { KeyboardManager } from "./utils/KeyboardManager/index.js";
|
|
41
41
|
import { SearchUtils } from "./utils/SearchUtils.js";
|
|
42
|
+
import OverflowWatcher, { OnOverflowCallBack, OverflowDirection } from "./utils/OverflowWatcher/index.js";
|
|
42
43
|
|
|
43
44
|
/*Classes públicas no pacote*/
|
|
44
45
|
export {
|
|
@@ -106,4 +107,7 @@ export {
|
|
|
106
107
|
defaultDataLoader,
|
|
107
108
|
KeyboardManager,
|
|
108
109
|
SearchUtils,
|
|
110
|
+
OverflowWatcher,
|
|
111
|
+
OnOverflowCallBack,
|
|
112
|
+
OverflowDirection
|
|
109
113
|
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { JSUtils } from "../JSUtils.js";
|
|
2
|
+
import { OverflowDirection } from "./types/overflow-direction.js"
|
|
3
|
+
import { OnOverflowCallBack } from "./types/overflow-callback.js"
|
|
4
|
+
|
|
5
|
+
export * from "./types/overflow-direction.js";
|
|
6
|
+
export * from "./types/overflow-callback.js";
|
|
7
|
+
|
|
8
|
+
export default class OverflowWatcher {
|
|
9
|
+
private _onResize:OnOverflowCallBack;
|
|
10
|
+
private _resizeObserver:ResizeObserver;
|
|
11
|
+
private _lastContentRect:DOMRectReadOnly|undefined = undefined;
|
|
12
|
+
private _scrollDirection = OverflowDirection.HORIZONTAL;
|
|
13
|
+
private _propSize:string;
|
|
14
|
+
private _hiddenItems:Element[] = [];
|
|
15
|
+
private _deltaSize:number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Cria uma instancia do OverflowWatcher
|
|
19
|
+
*
|
|
20
|
+
* @param element - Elemento HTML que o overflow será observado.
|
|
21
|
+
* @param callback - Função que sera chamada quando ocorrer overflow no elemento.
|
|
22
|
+
* @param overFlowDirection - Indica direção que o overflow será monitorado.
|
|
23
|
+
* @param deltaSize - Variação de tamanho que será considerada como overflow.
|
|
24
|
+
*/
|
|
25
|
+
constructor(element:HTMLElement,
|
|
26
|
+
callback:OnOverflowCallBack,
|
|
27
|
+
overFlowDirection:OverflowDirection = OverflowDirection.HORIZONTAL,
|
|
28
|
+
deltaSize:number = 10){
|
|
29
|
+
this._onResize = callback;
|
|
30
|
+
this._scrollDirection = overFlowDirection;
|
|
31
|
+
this._resizeObserver = new ResizeObserver(JSUtils.debounce((entries: ResizeObserverEntry[]) => this.handleResize(entries), 200));
|
|
32
|
+
this._resizeObserver.observe(element);
|
|
33
|
+
this._propSize = this.getPropSizeByDirection();
|
|
34
|
+
this._deltaSize = deltaSize;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public destroy(){
|
|
38
|
+
this._resizeObserver.disconnect();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private handleResize(entries: ResizeObserverEntry[]){
|
|
42
|
+
|
|
43
|
+
if(!entries || entries.length === 0){
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const resizeItem = entries[0];
|
|
48
|
+
const contentRect:any = resizeItem.contentRect;
|
|
49
|
+
|
|
50
|
+
if(this.isChangedSize(contentRect)){
|
|
51
|
+
const children:Element[] = Array.from(resizeItem.target.children);
|
|
52
|
+
this.proccessElements(contentRect[this._propSize], children);
|
|
53
|
+
this._lastContentRect = contentRect;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private isChangedSize(newContentRect:DOMRectReadOnly):boolean{
|
|
58
|
+
if(this._lastContentRect == undefined){
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return Math.abs((newContentRect as any)[this._propSize] - (this._lastContentRect as any)[this._propSize]) >= this._deltaSize;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
private getPropSizeByDirection():string{
|
|
66
|
+
if(OverflowDirection.HORIZONTAL === this._scrollDirection){
|
|
67
|
+
return "width"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return "height";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private proccessElements(elementSize:number, children:Element[]){
|
|
74
|
+
|
|
75
|
+
if(children.length === 0){
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const childrenSize = this.calcChildrenSize(children);
|
|
80
|
+
|
|
81
|
+
let diff = Number((elementSize - childrenSize).toFixed(4));
|
|
82
|
+
|
|
83
|
+
if(diff > 0){
|
|
84
|
+
this.proccessElementsWithoutOverFlow(diff);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.proccessElementsOverFlow(children, diff);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private proccessElementsWithoutOverFlow(diff:number){
|
|
92
|
+
this._hiddenItems.forEach((item:any) => {
|
|
93
|
+
|
|
94
|
+
if(item.getBoundingClientRect().width < diff){
|
|
95
|
+
this._hiddenItems.pop();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
this._onResize(this._hiddenItems);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private proccessElementsOverFlow(children:Element[], diff:number){
|
|
104
|
+
const elementsOverflow = [];
|
|
105
|
+
let sumRemovedItems = 0;
|
|
106
|
+
|
|
107
|
+
while(elementsOverflow.length < children.length && sumRemovedItems < (diff * -1) ) {
|
|
108
|
+
const itemToRemove = children.pop();
|
|
109
|
+
|
|
110
|
+
if(itemToRemove != undefined && (itemToRemove as any).style.display === 'none'){
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if(itemToRemove != undefined){
|
|
115
|
+
elementsOverflow.push(itemToRemove);
|
|
116
|
+
sumRemovedItems += (itemToRemove.getBoundingClientRect() as any)[this._propSize];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
this._hiddenItems = elementsOverflow;
|
|
122
|
+
this._onResize(elementsOverflow);
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private calcChildrenSize(children:Element[]):number{
|
|
127
|
+
let sumChildren = 0;
|
|
128
|
+
|
|
129
|
+
Array.from(children).forEach(el => {
|
|
130
|
+
sumChildren += (el.getBoundingClientRect() as any)[this._propSize];
|
|
131
|
+
sumChildren += this.calcMarginSize(el);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if(sumChildren > 0){
|
|
135
|
+
sumChildren += this._deltaSize;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return sumChildren;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private calcMarginSize(el:Element){
|
|
142
|
+
const computedStyle = getComputedStyle(el);
|
|
143
|
+
|
|
144
|
+
if(OverflowDirection.HORIZONTAL === this._scrollDirection){
|
|
145
|
+
return (parseInt(computedStyle.marginLeft || '0') + parseInt(computedStyle.marginRight || '0'));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return (parseInt(computedStyle.marginTop || '0') + parseInt(computedStyle.marginBottom || '0'));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback que será chamado quando o overflow de um elemento for alterado.
|
|
3
|
+
*
|
|
4
|
+
* @param elementsOverFlow - Conjunto de elementos filhos que estão causando overflow no elemento pai.
|
|
5
|
+
*/
|
|
6
|
+
export type OnOverflowCallBack = (elementsOverFlow:Array<Element>) => void;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import OverFlowWatcher, { OnOverflowCallBack, OverflowDirection } from '../../src/utils/OverflowWatcher';
|
|
2
|
+
|
|
3
|
+
describe('OverflowWatcher', function () {
|
|
4
|
+
|
|
5
|
+
let element: HTMLElement;
|
|
6
|
+
let callbackHorizontalDirection: OnOverflowCallBack;
|
|
7
|
+
let watcherHorizontalDirection: OverFlowWatcher;
|
|
8
|
+
let callbackVerticalDirection: OnOverflowCallBack;
|
|
9
|
+
let watcherVerticallDirection: OverFlowWatcher;
|
|
10
|
+
let child1:HTMLDivElement;
|
|
11
|
+
let child2:HTMLDivElement;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
|
|
15
|
+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
16
|
+
observe: jest.fn(),
|
|
17
|
+
unobserve: jest.fn(),
|
|
18
|
+
disconnect: jest.fn(),
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
element = document.createElement('div');
|
|
22
|
+
|
|
23
|
+
//Horizontal
|
|
24
|
+
callbackHorizontalDirection = jest.fn();
|
|
25
|
+
watcherHorizontalDirection = new OverFlowWatcher(element, callbackHorizontalDirection);
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
//Vertical
|
|
29
|
+
callbackVerticalDirection = jest.fn();
|
|
30
|
+
watcherVerticallDirection = new OverFlowWatcher(element, callbackVerticalDirection, OverflowDirection.VERTICAL);
|
|
31
|
+
|
|
32
|
+
child1 = document.createElement('div');
|
|
33
|
+
child2 = document.createElement('div');
|
|
34
|
+
|
|
35
|
+
child1.style.width = '50px';
|
|
36
|
+
child2.style.width = '100px';
|
|
37
|
+
child1.style.height = '50px';
|
|
38
|
+
child2.style.height = '100px';
|
|
39
|
+
|
|
40
|
+
//TODO: No futuro utilizar JSDOM para não precisar fazer mock dessas coisas
|
|
41
|
+
child1['getBoundingClientRect'] = () => {
|
|
42
|
+
return {
|
|
43
|
+
width: 50,
|
|
44
|
+
height: 50,
|
|
45
|
+
} as DOMRect;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
child2['getBoundingClientRect'] = () => {
|
|
49
|
+
return {
|
|
50
|
+
width: 100,
|
|
51
|
+
height: 100,
|
|
52
|
+
} as DOMRect;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
element.appendChild(child1);
|
|
56
|
+
element.appendChild(child2);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
watcherHorizontalDirection.destroy();
|
|
61
|
+
watcherVerticallDirection.destroy();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('constructor initializes properties correctly', () => {
|
|
65
|
+
expect(watcherHorizontalDirection['_onResize']).toBe(callbackHorizontalDirection);
|
|
66
|
+
expect(watcherHorizontalDirection['_scrollDirection']).toBe(OverflowDirection.HORIZONTAL);
|
|
67
|
+
expect(watcherHorizontalDirection['_deltaSize']).toBe(10);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('handleResize horizontal calls callback with hidden items', () => {
|
|
71
|
+
const entries: any[] = [{
|
|
72
|
+
contentRect: {
|
|
73
|
+
width: 120
|
|
74
|
+
},
|
|
75
|
+
target: element
|
|
76
|
+
}];
|
|
77
|
+
|
|
78
|
+
watcherHorizontalDirection['handleResize'](entries);
|
|
79
|
+
|
|
80
|
+
expect(callbackHorizontalDirection).toHaveBeenCalledWith([child2]);
|
|
81
|
+
|
|
82
|
+
entries[0].contentRect.width = 100;
|
|
83
|
+
watcherHorizontalDirection['handleResize'](entries);
|
|
84
|
+
|
|
85
|
+
expect(callbackHorizontalDirection).toHaveBeenCalledWith([child2]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('handleResize vertical calls callback with hidden items', () => {
|
|
89
|
+
const entries: any[] = [{
|
|
90
|
+
contentRect: {
|
|
91
|
+
height: 120
|
|
92
|
+
},
|
|
93
|
+
target: element
|
|
94
|
+
}];
|
|
95
|
+
|
|
96
|
+
watcherVerticallDirection['handleResize'](entries);
|
|
97
|
+
|
|
98
|
+
expect(callbackVerticalDirection).toHaveBeenCalledWith([child2]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('isChangedSize returns true if no previous size', () => {
|
|
102
|
+
const newContentRect: DOMRectReadOnly = { width: 100 } as DOMRectReadOnly;
|
|
103
|
+
watcherHorizontalDirection['_lastContentRect'] = undefined;
|
|
104
|
+
|
|
105
|
+
const result = watcherHorizontalDirection['isChangedSize'](newContentRect);
|
|
106
|
+
|
|
107
|
+
expect(result).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('prevent resize without entries', () => {
|
|
111
|
+
const entries: any[] = [];
|
|
112
|
+
|
|
113
|
+
watcherHorizontalDirection['handleResize'](entries);
|
|
114
|
+
|
|
115
|
+
expect(callbackHorizontalDirection).toHaveBeenCalledTimes(0);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
});
|