@sankhyalabs/core 7.1.1-rc.1 → 7.2.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.
@@ -23,7 +23,6 @@ export interface FieldDescriptor {
23
23
  label: string;
24
24
  dataType: DataType;
25
25
  userInterface?: UserInterface;
26
- aggFunc?: any;
27
26
  defaultValue?: any;
28
27
  visible?: boolean;
29
28
  readOnly?: boolean;
@@ -60,7 +60,6 @@ export class MaskFormatter {
60
60
  "cnpj": "ZZ.ZZZ.ZZZ/ZZZZ-##",
61
61
  "cpf": "###.###.###-##",
62
62
  "phone": "(##) ####-####",
63
- "phone_mobile": "(##) #####-####",
64
63
  "cep": "##.###-###",
65
64
  "cor_rgb" : "'#AAAAAA"
66
65
  };
@@ -9,295 +9,236 @@ export * from "./types/overflow-callback.js";
9
9
  export const OVERFLOWED_CLASS_NAME = 'overflowed';
10
10
 
11
11
  export default class OverflowWatcher {
12
- private _onResize:OnOverflowCallBack;
13
- private _resizeObserver:ResizeObserver;
14
- private _lastContainerSize:number|undefined = undefined;
15
- private _lastContainerInstance: HTMLElement | undefined = undefined;
16
- private _scrollDirection = OverflowDirection.HORIZONTAL;
17
- private _propSize:string;
18
- private _hiddenItemsProps:Map<Element, SizeProps> = new Map();
19
- private _notOverFlowPros:Map<string, SizeProps> = new Map();
20
- private _deltaSize:number;
21
- private _notOverFlow: string[] = [];
22
-
23
- readonly DATA_ELEMENT_ID = 'data-element-id';
24
-
25
- /**
26
- * Cria uma instancia do OverflowWatcher
27
- *
28
- * @param element - Elemento HTML que o overflow será observado.
29
- * @param callback - Função que sera chamada quando ocorrer overflow no elemento.
30
- * @param overFlowDirection - Indica direção que o overflow será monitorado.
31
- * @param deltaSize - Variação de tamanho que será considerada como overflow.
32
- * @param debounce - Tempo até execução do callback em milissegundos.
33
- * @param notOverFlow - Lista de ids ou data-element-ids dos elementos que não devem sofrer overFlow.
34
- */
35
- constructor({
36
- element,
37
- callback,
38
- overFlowDirection = OverflowDirection.HORIZONTAL,
39
- debounce = 200,
40
- deltaSize = 0,
41
- notOverFlow = []
42
- }: OverFlowWatcherParams){
43
- this._onResize = callback;
44
- this._scrollDirection = overFlowDirection;
45
- this._propSize = (OverflowDirection.HORIZONTAL === overFlowDirection) ? "width" : "height";
46
- this._resizeObserver = new ResizeObserver(JSUtils.debounce((entries: ResizeObserverEntry[]) => this.handleResize(entries), debounce));
47
- this._resizeObserver.observe(element);
48
- this._deltaSize = deltaSize;
49
- this._notOverFlow = notOverFlow;
50
- }
51
-
52
- public addNotOverFlowElement(elementId: string){
53
- if(!this._notOverFlow.includes(elementId)){
54
- this._notOverFlow.push(elementId);
12
+ private _onResize:OnOverflowCallBack;
13
+ private _resizeObserver:ResizeObserver;
14
+ private _lastContainerSize:number|undefined = undefined;
15
+ private _lastContainerInstance: HTMLElement | undefined = undefined;
16
+ private _scrollDirection = OverflowDirection.HORIZONTAL;
17
+ private _propSize:string;
18
+ private _hiddenItemsProps:Map<Element, SizeProps> = new Map();
19
+ private _notOverFlowPros:Map<string, SizeProps> = new Map();
20
+ private _deltaSize:number;
21
+ private _notOverFlow: string[] = [];
22
+
23
+ readonly DATA_ELEMENT_ID = 'data-element-id';
24
+
25
+ /**
26
+ * Cria uma instancia do OverflowWatcher
27
+ *
28
+ * @param element - Elemento HTML que o overflow será observado.
29
+ * @param callback - Função que sera chamada quando ocorrer overflow no elemento.
30
+ * @param overFlowDirection - Indica direção que o overflow será monitorado.
31
+ * @param deltaSize - Variação de tamanho que será considerada como overflow.
32
+ * @param debounce - Tempo até execução do callback em milissegundos.
33
+ * @param notOverFlow - Lista de ids ou data-element-ids dos elementos que não devem sofrer overFlow.
34
+ */
35
+ constructor({
36
+ element,
37
+ callback,
38
+ overFlowDirection = OverflowDirection.HORIZONTAL,
39
+ debounce = 200,
40
+ deltaSize = 0,
41
+ notOverFlow = []
42
+ }: OverFlowWatcherParams){
43
+ this._onResize = callback;
44
+ this._scrollDirection = overFlowDirection;
45
+ this._propSize = (OverflowDirection.HORIZONTAL === overFlowDirection) ? "width" : "height";
46
+ this._resizeObserver = new ResizeObserver(JSUtils.debounce((entries: ResizeObserverEntry[]) => this.handleResize(entries), debounce));
47
+ this._resizeObserver.observe(element);
48
+ this._deltaSize = deltaSize;
49
+ this._notOverFlow = notOverFlow;
55
50
  }
56
- }
57
51
 
58
- public destroy(){
59
- this._resizeObserver.disconnect();
60
- }
52
+ public addNotOverFlowElement(elementId: string){
53
+ if(!this._notOverFlow.includes(elementId)){
54
+ this._notOverFlow.push(elementId);
55
+ }
56
+ }
57
+
58
+ public destroy(){
59
+ this._resizeObserver.disconnect();
60
+ }
61
61
 
62
- public forceUpdate(){
63
- if(this._lastContainerSize && this._lastContainerInstance){
64
- this.updateOverFlowedItems(this._lastContainerInstance, this._lastContainerSize);
62
+ public forceUpdate(){
63
+ if(this._lastContainerSize && this._lastContainerInstance){
64
+ this.updateOverFlowedItems(this._lastContainerInstance, this._lastContainerSize);
65
+ }
65
66
  }
66
- }
67
67
 
68
- private handleResize(entries: ResizeObserverEntry[]){
69
- if(!entries || entries.length === 0) return;
68
+ private handleResize(entries: ResizeObserverEntry[]){
69
+ if(!entries || entries.length === 0) return;
70
70
 
71
- const container = entries[0];
72
- const containerSize:number = (container.contentRect as any)[this._propSize];
73
- if(!containerSize) return;
71
+ const container = entries[0];
72
+ const containerSize:number = (container.contentRect as any)[this._propSize];
73
+ if(!containerSize) return;
74
74
 
75
- if(this.hasChangedSize(containerSize)){
76
- this.updateOverFlowedItems(container.target as HTMLElement, containerSize);
75
+ if(this.hasChangedSize(containerSize)){
76
+ this.updateOverFlowedItems(container.target as HTMLElement, containerSize);
77
+ }
77
78
  }
78
- }
79
-
80
- private updateOverFlowedItems(container: HTMLElement, containerSize: number){
81
- const children:Element[] = this.getProcessableElements(container);
82
- this.registerNotOverflowProps(children);
83
- this.proccessElements(containerSize, children);
84
- this._lastContainerSize = containerSize;
85
- this._lastContainerInstance = container;
86
- }
87
-
88
- private getProcessableElements(container: HTMLElement): Element[] {
89
- const directChildren = Array.from(container.children);
90
- const processableElements: Element[] = [];
91
-
92
- for (const child of directChildren) {
93
- if (child.classList.contains('taskbar-group')) {
94
- processableElements.push(...Array.from(child.children));
95
- } else {
96
- processableElements.push(child);
97
- }
79
+
80
+ private updateOverFlowedItems(container: HTMLElement, containerSize: number){
81
+ const children:Element[] = Array.from(container.children);
82
+ this.registerNotOverflowProps(children);
83
+ this.proccessElements(containerSize, children);
84
+ this._lastContainerSize = containerSize;
85
+ this._lastContainerInstance = container;
98
86
  }
99
87
 
100
- return processableElements;
101
- }
88
+ private registerNotOverflowProps(children: Element[]) {
89
+ children.forEach(childElement => {
90
+ const id = childElement.id || this.getDataElementId(childElement);
91
+ if (this.canNotRegisterNotOverFlow(id)) return;
92
+ this._notOverFlowPros.set(id, this.getElementSizeProps(childElement));
93
+ });
94
+ }
102
95
 
103
- private registerNotOverflowProps(children: Element[]) {
104
- children.forEach(childElement => {
105
- const id = childElement.id || this.getDataElementId(childElement);
106
- if (this.canNotRegisterNotOverFlow(id)) return;
107
- this._notOverFlowPros.set(id, this.getElementSizeProps(childElement));
108
- });
109
- }
96
+ private canNotRegisterNotOverFlow(id: string) {
97
+ return !id || !this._notOverFlow.includes(id);
98
+ }
110
99
 
111
- private canNotRegisterNotOverFlow(id: string) {
112
- return !id || !this._notOverFlow.includes(id);
113
- }
100
+ private hasChangedSize(elementSize: number):boolean{
101
+ if(!this._lastContainerSize) return true;
102
+ const variation = elementSize - this._lastContainerSize;
114
103
 
115
- private hasChangedSize(elementSize: number):boolean{
116
- if(!this._lastContainerSize) return true;
117
- const variation = elementSize - this._lastContainerSize;
104
+ if(variation < 0){
105
+ const absoluteVariation = Math.abs(variation);
106
+ return (absoluteVariation > this._deltaSize);
107
+ }
118
108
 
119
- if(variation < 0){
120
- const absoluteVariation = Math.abs(variation);
121
- return (absoluteVariation > this._deltaSize);
109
+ return variation > 0;
122
110
  }
123
111
 
124
- return variation > 0;
125
- }
112
+ private proccessElements(elementSize:number, children:Element[]){
113
+ if(children.length === 0) return;
126
114
 
127
- private proccessElements(elementSize:number, children:Element[]){
128
- if(children.length === 0) return;
115
+ const childrenSize = this.calcChildrenSize(children);
116
+ let diff = Number((elementSize - childrenSize).toFixed(4));
129
117
 
130
- const childrenSize = this.calcChildrenSize(children);
131
- let diff = Number((elementSize - childrenSize).toFixed(4));
118
+ if(diff > 0){
119
+ this.clearOverFlow();
120
+ return;
121
+ }
132
122
 
133
- if(diff > 0){
134
- this.clearOverFlow();
135
- return;
123
+ this.proccessElementsOverFlow(children, elementSize);
136
124
  }
137
125
 
138
- this.proccessElementsOverFlow(children, elementSize);
139
- }
126
+ private clearOverFlow(){
127
+ this._hiddenItemsProps = new Map();
128
+ this._onResize([]);
129
+ }
130
+
131
+ private proccessElementsOverFlow(allElements:Element[], avaliableSize:number){
132
+ const elementsThatFit: Element[] = [];
133
+ const avaliableSizeConsideringDelta = (avaliableSize - this._deltaSize);
134
+
135
+ let sumElementsSize = 0;
140
136
 
141
- private clearOverFlow(){
142
- this._hiddenItemsProps = new Map();
143
- this._onResize([]);
144
- }
137
+ for (const element of allElements) {
138
+ sumElementsSize += this.calcElementSize(element);
139
+ if(this.exceedsAvaliableSize(sumElementsSize, elementsThatFit, avaliableSizeConsideringDelta)) break;
140
+ elementsThatFit.push(element);
141
+ }
145
142
 
146
- private proccessElementsOverFlow(allElements:Element[], avaliableSize:number){
147
- const elementsThatFit: Element[] = [];
148
- const avaliableSizeConsideringDelta = (avaliableSize - this._deltaSize);
143
+ const overFlowedElements = allElements.filter(element => this.isElementOverFlowing(elementsThatFit, element));
149
144
 
150
- let sumElementsSize = 0;
145
+ overFlowedElements.forEach(overFlowed => {
146
+ if(!this._hiddenItemsProps.has(overFlowed)){
147
+ this.registerElementSize(overFlowed);
148
+ }
149
+ });
151
150
 
152
- for (const element of allElements) {
153
- sumElementsSize += this.calcElementSize(element);
154
- if(this.exceedsAvaliableSize(sumElementsSize, elementsThatFit, avaliableSizeConsideringDelta)) break;
155
- elementsThatFit.push(element);
151
+ this._onResize(overFlowedElements);
156
152
  }
157
153
 
158
- const overFlowedElements = allElements.filter(element => this.isElementOverFlowing(elementsThatFit, element));
159
-
160
- overFlowedElements.forEach(overFlowed => {
161
- if(!this._hiddenItemsProps.has(overFlowed)){
162
- this.registerElementSize(overFlowed);
163
- }
164
- });
165
-
166
- this._onResize(overFlowedElements);
167
- }
168
-
169
- private isElementOverFlowing(elementsThatFit: Element[], element: Element) {
170
- return !elementsThatFit.includes(element) && this.canOverFlowElement(element);
171
- }
172
-
173
- private canOverFlowElement(element: Element) {
174
- return !this._notOverFlow.includes(element.id)
175
- && !this._notOverFlow.includes(this.getDataElementId(element));
176
- }
177
-
178
- private getDataElementId(element: Element): string {
179
- return (element as HTMLElement).getAttribute('data-element-id') ?? "";
180
- }
181
-
182
- private exceedsAvaliableSize(sumElementsSize: number, elements: Element[], avaliableSize: number): boolean {
183
- if(!this._notOverFlow.length) return sumElementsSize > avaliableSize
184
-
185
- const elementIdsToCalculate = this.canNotOverFlowNotIncludedIds(elements);
186
- if(!elementIdsToCalculate.length) return sumElementsSize > avaliableSize
187
-
188
- const variation = this.calculateVariation(elementIdsToCalculate);
189
- const occupiedSize = sumElementsSize + variation;
190
- return occupiedSize > avaliableSize;
191
- }
192
-
193
- private calculateVariation(elementIdsToCalculate: string[]) {
194
- let variation = 0
195
- elementIdsToCalculate.forEach(id => {
196
- const sizeProps = this._notOverFlowPros.get(id);
197
- variation += sizeProps?.size ?? 0;
198
- variation += sizeProps?.margin ?? 0;
199
- });
200
- return variation;
201
- }
202
-
203
- private canNotOverFlowNotIncludedIds(elements: Element[]): string[]{
204
- const elementsIdList = elements.map(el => el.id || this.getDataElementId(el)).filter(id => !!id);
205
- return this._notOverFlow.filter(id => !elementsIdList.includes(id));
206
- }
207
-
208
- private registerElementSize(element: Element) {
209
- const sizeProps = this.getElementSizeProps(element);
210
- this._hiddenItemsProps.set(element, sizeProps);
211
- }
212
-
213
- private getElementSizeProps(element: Element) {
214
- const sizeProps: SizeProps = {
215
- size: (element.getBoundingClientRect() as any)[this._propSize],
216
- margin: calcMarginSize(element, this._scrollDirection),
217
- };
218
- return sizeProps;
219
- }
220
-
221
- private calcChildrenSize(children:Element[]):number{
222
- let sumChildren = 0;
223
- sumChildren += this._deltaSize;
224
-
225
- // Agrupa os elementos por container pai
226
- const elementsByContainer = this.groupElementsByContainer(children);
227
-
228
- // Calcula o tamanho considerando os containers
229
- for (const [container, elements] of elementsByContainer) {
230
- if (container && container.classList.contains('taskbar-group')) {
231
- // Se é um grupo da taskbar, adiciona o tamanho do container mais os elementos
232
- sumChildren += this.calcContainerSize(container);
233
- elements.forEach(el => sumChildren += this.calcElementSize(el));
234
- } else {
235
- // Se não é um grupo, adiciona apenas o tamanho dos elementos
236
- elements.forEach(el => sumChildren += this.calcElementSize(el));
237
- }
154
+ private isElementOverFlowing(elementsThatFit: Element[], element: Element) {
155
+ return !elementsThatFit.includes(element) && this.canOverFlowElement(element);
238
156
  }
239
157
 
240
- return sumChildren;
241
- }
158
+ private canOverFlowElement(element: Element) {
159
+ return !this._notOverFlow.includes(element.id)
160
+ && !this._notOverFlow.includes(this.getDataElementId(element));
161
+ }
162
+
163
+ private getDataElementId(element: Element): string {
164
+ return (element as HTMLElement).getAttribute('data-element-id') ?? "";
165
+ }
242
166
 
243
- private groupElementsByContainer(elements: Element[]): Map<Element | null, Element[]> {
244
- const grouped = new Map<Element | null, Element[]>();
167
+ private exceedsAvaliableSize(sumElementsSize: number, elements: Element[], avaliableSize: number): boolean {
168
+ if(!this._notOverFlow.length) return sumElementsSize > avaliableSize
245
169
 
246
- for (const element of elements) {
247
- const container = element.parentElement;
248
- if (!grouped.has(container)) {
249
- grouped.set(container, []);
250
- }
251
- grouped.get(container)!.push(element);
170
+ const elementIdsToCalculate = this.canNotOverFlowNotIncludedIds(elements);
171
+ if(!elementIdsToCalculate.length) return sumElementsSize > avaliableSize
172
+
173
+ const variation = this.calculateVariation(elementIdsToCalculate);
174
+ const occupiedSize = sumElementsSize + variation;
175
+ return occupiedSize > avaliableSize;
176
+ }
177
+
178
+ private calculateVariation(elementIdsToCalculate: string[]) {
179
+ let variation = 0
180
+ elementIdsToCalculate.forEach(id => {
181
+ const sizeProps = this._notOverFlowPros.get(id);
182
+ variation += sizeProps?.size ?? 0;
183
+ variation += sizeProps?.margin ?? 0;
184
+ });
185
+ return variation;
252
186
  }
253
187
 
254
- return grouped;
255
- }
256
-
257
- private calcContainerSize(container: Element): number {
258
- const rect = container.getBoundingClientRect();
259
- const elementSize = rect[this._propSize as keyof DOMRect] as number;
260
- const marginSize = calcMarginSize(container, this._scrollDirection);
261
-
262
- // Subtrai o tamanho dos filhos para não contar em duplicidade
263
- let childrenSize = 0;
264
- Array.from(container.children).forEach(child => {
265
- const childRect = child.getBoundingClientRect();
266
- childrenSize += childRect[this._propSize as keyof DOMRect] as number;
267
- });
268
-
269
- return Math.max(0, elementSize - childrenSize) + marginSize;
270
- }
271
-
272
- private calcElementSize(el: Element) {
273
- let size = 0
274
- if (this.isOverFlowed(el)) {
275
- const sizeProps = this._hiddenItemsProps.get(el);
276
- size += sizeProps?.size ?? 0;
277
- size += sizeProps?.margin ?? 0;
278
- return size;
188
+ private canNotOverFlowNotIncludedIds(elements: Element[]): string[]{
189
+ const elementsIdList = elements.map(el => el.id || this.getDataElementId(el)).filter(id => !!id);
190
+ return this._notOverFlow.filter(id => !elementsIdList.includes(id));
279
191
  }
280
192
 
281
- size += (el.getBoundingClientRect() as any)[this._propSize];
282
- size += calcMarginSize(el, this._scrollDirection);
283
- return size;
284
- }
193
+ private registerElementSize(element: Element) {
194
+ const sizeProps = this.getElementSizeProps(element);
195
+ this._hiddenItemsProps.set(element, sizeProps);
196
+ }
197
+
198
+ private getElementSizeProps(element: Element) {
199
+ const sizeProps: SizeProps = {
200
+ size: (element.getBoundingClientRect() as any)[this._propSize],
201
+ margin: calcMarginSize(element, this._scrollDirection),
202
+ };
203
+ return sizeProps;
204
+ }
285
205
 
286
- private isOverFlowed(el: Element) {
287
- return el.classList.contains(OVERFLOWED_CLASS_NAME);
288
- }
206
+ private calcChildrenSize(children:Element[]):number{
207
+ let sumChildren = 0;
208
+ sumChildren += this._deltaSize;
209
+ Array.from(children).forEach(el => sumChildren += this.calcElementSize(el));
210
+ return sumChildren;
211
+ }
212
+
213
+ private calcElementSize(el: Element) {
214
+ let size = 0
215
+ if (this.isOverFlowed(el)) {
216
+ const sizeProps = this._hiddenItemsProps.get(el);
217
+ size += sizeProps?.size ?? 0;
218
+ size += sizeProps?.margin ?? 0;
219
+ return size;
220
+ }
221
+
222
+ size += (el.getBoundingClientRect() as any)[this._propSize];
223
+ size += calcMarginSize(el, this._scrollDirection);
224
+ return size;
225
+ }
226
+
227
+ private isOverFlowed(el: Element) {
228
+ return el.classList.contains(OVERFLOWED_CLASS_NAME);
229
+ }
289
230
  }
290
231
 
291
232
  export interface OverFlowWatcherParams {
292
- element:HTMLElement,
293
- callback:OnOverflowCallBack,
294
- overFlowDirection?:OverflowDirection,
295
- deltaSize?:number,
296
- debounce?: number,
297
- notOverFlow?: string[]
233
+ element:HTMLElement,
234
+ callback:OnOverflowCallBack,
235
+ overFlowDirection?:OverflowDirection,
236
+ deltaSize?:number,
237
+ debounce?: number,
238
+ notOverFlow?: string[]
298
239
  }
299
240
 
300
241
  interface SizeProps {
301
- size: number,
302
- margin: number,
242
+ size: number,
243
+ margin: number,
303
244
  }