@sankhyalabs/core 0.0.0-bugfix-dev-KB-75940.0 → 0.0.0-bugfix-dev-KB-81596.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.docs/classes/ColumnFilterManager.md +145 -0
  2. package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
  3. package/.docs/classes/DataUnitLoaderUtils.md +151 -0
  4. package/.docs/classes/FieldComparator.md +2 -2
  5. package/.docs/classes/KeyboardManager.md +9 -79
  6. package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
  7. package/.docs/globals.md +6 -0
  8. package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
  9. package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
  10. package/.releaserc +1 -0
  11. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
  12. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
  13. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
  14. package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
  15. package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
  16. package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
  17. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
  18. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
  19. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
  20. package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
  21. package/dist/dataunit/sorting/FieldComparator.js +4 -9
  22. package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
  23. package/dist/index.d.ts +5 -1
  24. package/dist/index.js +5 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/utils/ColumnFilterManager.d.ts +19 -0
  27. package/dist/utils/ColumnFilterManager.js +73 -0
  28. package/dist/utils/ColumnFilterManager.js.map +1 -0
  29. package/dist/utils/KeyboardManager/index.d.ts +0 -4
  30. package/dist/utils/KeyboardManager/index.js +1 -37
  31. package/dist/utils/KeyboardManager/index.js.map +1 -1
  32. package/dist/utils/KeyboardManager/interface.d.ts +0 -1
  33. package/package.json +1 -1
  34. package/reports/test-report.xml +137 -97
  35. package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
  36. package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
  37. package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
  38. package/src/dataunit/sorting/FieldComparator.ts +18 -32
  39. package/src/index.ts +11 -1
  40. package/src/utils/ColumnFilterManager.ts +104 -0
  41. package/src/utils/KeyboardManager/index.ts +0 -47
  42. package/src/utils/KeyboardManager/interface.ts +0 -1
  43. package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
  44. package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
  45. package/test/util/ColumnFilterManager.spec.ts +133 -0
@@ -0,0 +1,176 @@
1
+ import {
2
+ Change,
3
+ ChangeOperation,
4
+ DataType,
5
+ DataUnit,
6
+ DateUtils,
7
+ FieldDescriptor,
8
+ LoadDataRequest,
9
+ LoadDataResponse,
10
+ Record,
11
+ SavedRecord,
12
+ StringUtils,
13
+ UnitMetadata,
14
+ } from '../../index.js';
15
+ import { DataUnitInMemoryLoaderConfig, RECORD_DATE_FORMAT } from './DataUnitInMemoryLoaderConfig.js';
16
+ import { DataUnitLoaderUtils } from './utils/dataUnitLoaderUtils.js';
17
+
18
+ export class DataUnitInMemoryLoader {
19
+ private _dataUnit: DataUnit;
20
+ private _metadata: UnitMetadata | undefined;
21
+ private _initialRecords: Array<Record> = [];
22
+ private recordDateFormat: RECORD_DATE_FORMAT;
23
+ public static readonly IN_MEMORY_DATA_UNIT_NAME = 'InMemoryDataUnit';
24
+ public static readonly DEFAULT_PAGE_SIZE = 150;
25
+
26
+ constructor(metadata?: UnitMetadata, records?: Array<Record>, config?: DataUnitInMemoryLoaderConfig) {
27
+
28
+ this.metadata = metadata as UnitMetadata;
29
+ this.recordDateFormat = config?.recordDateFormat ?? RECORD_DATE_FORMAT.DD_MM_YYYY;
30
+ this.records = records ?? [] as Array<Record>;
31
+
32
+ this._dataUnit = new DataUnit(DataUnitInMemoryLoader.IN_MEMORY_DATA_UNIT_NAME);
33
+ this._dataUnit.pageSize = config?.pageSize ?? DataUnitInMemoryLoader.DEFAULT_PAGE_SIZE;
34
+ this._dataUnit.metadataLoader = () => this.metadaLoader();
35
+ this._dataUnit.dataLoader = (dataUnit: DataUnit, request: LoadDataRequest) => this.inMemoryLoader(dataUnit, request, this.getRecordsToLoad());
36
+ this._dataUnit.saveLoader = (_dataUnit: DataUnit, changes: Array<Change>) => this.saveLoader(_dataUnit, changes);
37
+ this._dataUnit.removeLoader = (_dataUnit: DataUnit, recordIds: Array<string>) => this.removeLoader(_dataUnit, recordIds);
38
+
39
+ this.dataUnit.loadMetadata().then(() => {
40
+ if (config?.autoLoad !== false) {
41
+ this.dataUnit.loadData();
42
+ }
43
+ });
44
+ }
45
+
46
+ private getRecordsToLoad(): Array<Record> {
47
+ if (this._initialRecords == undefined && this.dataUnit.records.length > 0) {
48
+ this._initialRecords = this.dataUnit.records;
49
+ }
50
+
51
+ const addedRecords = this.dataUnit.getAddedRecords();
52
+ if (addedRecords) {
53
+ return [...this._initialRecords, ...addedRecords];
54
+ }
55
+ return this._initialRecords;
56
+ }
57
+
58
+ public get dataUnit(): DataUnit {
59
+ return this._dataUnit;
60
+ }
61
+
62
+ public get records(): Array<Record> {
63
+ return this.dataUnit.records;
64
+ }
65
+
66
+ public set records(records: Array<Record>) {
67
+ const columns = this.buildColumns();
68
+
69
+ this._initialRecords = this.buildInitialRecords(records, columns);
70
+
71
+ if (!this._dataUnit) return;
72
+
73
+ //Isso força o refresh internamente no datunit
74
+ this._dataUnit.loadData();
75
+ }
76
+
77
+ public static getConvertedValue(descriptor: FieldDescriptor, strValue: string, dateFormat?: RECORD_DATE_FORMAT) {
78
+ if (!descriptor) return strValue;
79
+ if (descriptor.dataType === DataType.BOOLEAN) return strValue === 'S';
80
+ if (descriptor.dataType === DataType.NUMBER) return Number(strValue);
81
+ if (descriptor.dataType === DataType.OBJECT) return JSON.parse(strValue);
82
+
83
+ if (descriptor.dataType === DataType.DATE) {
84
+ return dateFormat === RECORD_DATE_FORMAT.ISO
85
+ ? DateUtils.validateDate(new Date(strValue), true)
86
+ : DateUtils.strToDate(strValue, true);
87
+ }
88
+
89
+ return strValue;
90
+ }
91
+
92
+ private buildColumns() {
93
+ return this._metadata
94
+ ? new Map(this._metadata.fields.map(descriptor => [descriptor.name, descriptor]))
95
+ : undefined;
96
+ }
97
+
98
+ private buildInitialRecords(records: Array<Record>, columns: Map<string, FieldDescriptor> | undefined) {
99
+ const newRecords = records?.map(record => {
100
+
101
+ if (!record['__record__id__']) {
102
+ record['__record__id__'] = this.generateUniqueId();
103
+ }
104
+
105
+ if (!columns) return record;
106
+
107
+ for (const fieldName in record) {
108
+ const value = record[fieldName];
109
+ const fieldDescriptor = columns.get(fieldName);
110
+
111
+ if (typeof value === 'string' && fieldDescriptor) {
112
+ record[fieldName] = DataUnitInMemoryLoader.getConvertedValue(fieldDescriptor, value, this.recordDateFormat);
113
+ }
114
+ }
115
+
116
+ return record;
117
+ });
118
+
119
+ return newRecords;
120
+ }
121
+
122
+ public get metadata(): UnitMetadata {
123
+ return this._metadata as UnitMetadata;
124
+ }
125
+
126
+ public set metadata(metadata: UnitMetadata) {
127
+ this._metadata = metadata;
128
+
129
+ if (this._dataUnit) {
130
+ this._dataUnit.metadata = metadata as UnitMetadata;
131
+ }
132
+ }
133
+
134
+ private generateUniqueId(): string {
135
+ return StringUtils.generateUUID();
136
+ }
137
+
138
+ private inMemoryLoader(dataUnit: DataUnit, request: LoadDataRequest, recordsIn: Array<Record>): Promise<LoadDataResponse> {
139
+ return DataUnitLoaderUtils.buildLoadDataResponse(recordsIn, dataUnit, request);
140
+ }
141
+
142
+ private metadaLoader(): Promise<UnitMetadata> {
143
+ return Promise.resolve(this._metadata as UnitMetadata);
144
+ }
145
+
146
+ private saveLoader(_dataUnit: DataUnit, changes: Array<Change>): Promise<Array<SavedRecord>> {
147
+ return new Promise((resolve) => {
148
+ let dataUnitRecords: SavedRecord[] = [];
149
+
150
+ changes.forEach(change => {
151
+ let { record, updatingFields, operation } = change;
152
+
153
+ const changedRecord = { ...record, ...updatingFields };
154
+
155
+ if (operation === ChangeOperation.INSERT ||
156
+ operation === ChangeOperation.COPY) {
157
+ changedRecord['__old__id__'] = record['__record__id__'];
158
+ changedRecord['__record__id__'] = this.generateUniqueId();
159
+
160
+ this.records.push(changedRecord);
161
+ } else {
162
+ const recordIndex = this.records.findIndex(r => r['__record__id__'] == changedRecord['__record__id__']);
163
+ this.records[recordIndex] = changedRecord;
164
+ }
165
+
166
+ dataUnitRecords.push(changedRecord);
167
+ });
168
+
169
+ resolve(dataUnitRecords);
170
+ });
171
+ }
172
+
173
+ public removeLoader(_dataUnit: DataUnit, recordIds: Array<string>): Promise<Array<string>> {
174
+ return new Promise((resolve) => resolve(recordIds));
175
+ }
176
+ }
@@ -0,0 +1,86 @@
1
+ import DataUnit, { Record } from '../../DataUnit.js';
2
+ import { Filter, Sort } from '../../metadata/UnitMetadata.js';
3
+ import { LoadDataRequest } from '../../loading/LoadDataRequest.js';
4
+ import { PaginationInfo } from '../../loading/PaginationInfo.js';
5
+ import { IColumnFilter, ColumnFilterManager } from '../../../utils/ColumnFilterManager.js';
6
+ import SortingUtils from '../../../utils/SortingUtils.js';
7
+
8
+ export class DataUnitLoaderUtils {
9
+
10
+
11
+ public static applyFilter(records: Array<Record>, dataUnit: DataUnit, filters: Array<Filter>): Array<Record> {
12
+ const columnFilters: Map<string, IColumnFilter> = ColumnFilterManager.getColumnFilters(filters, "");
13
+ if (!columnFilters?.size) return records;
14
+
15
+ const filterFunction: ((record: Record) => boolean) | undefined = ColumnFilterManager.getFilterFunction(dataUnit, Array.from(columnFilters.values()));
16
+ return (filterFunction) ? records.filter(filterFunction) : records;
17
+ }
18
+
19
+
20
+ public static buildLoadDataResponse(recordsIn: Array<Record>, dataUnit: DataUnit, request: LoadDataRequest) {
21
+ let records = recordsIn ? [...recordsIn] : [];
22
+ records = DataUnitLoaderUtils.applyFilter(records, dataUnit, request?.filters ?? []);
23
+ records = DataUnitLoaderUtils.applySorting(records, dataUnit, request?.sort ?? []);
24
+
25
+ const { offset, limit } = request;
26
+
27
+ const paginationInfoBuilderParams = {
28
+ recordsLength: records.length,
29
+ offset,
30
+ recordsPerPage: limit,
31
+ } as PaginationInfoBuilderParams;
32
+
33
+ return Promise.resolve({
34
+ records: DataUnitLoaderUtils.getPagesByRecords(records, offset, limit),
35
+ paginationInfo: dataUnit.pageSize ? DataUnitLoaderUtils.buildPaginationInfo(paginationInfoBuilderParams) : undefined,
36
+ });
37
+ }
38
+
39
+
40
+ public static applySorting(records: Array<Record>, dataUnit: DataUnit, sorting: Array<Sort>): Array<Record> {
41
+ if (sorting == undefined || sorting.length == 0) {
42
+ return records;
43
+ }
44
+ const sortingFunction = SortingUtils.getSortingFunction(dataUnit, sorting);
45
+ if (sortingFunction == undefined) {
46
+ return records;
47
+ }
48
+ return records.sort(sortingFunction);
49
+ }
50
+
51
+ public static getPagesByRecords(records: Record[], offset = 0, limit = 0){
52
+ if(!records || !records.length || !this.hasValidLimitAndOffset(offset, limit)) return [];
53
+ if(limit === 0 && offset === 0) return records;
54
+ return records.slice(offset, offset + limit);
55
+ }
56
+
57
+ private static hasValidLimitAndOffset(offset: number, limit: number) {
58
+ return offset >= 0 && limit >= 0;
59
+ }
60
+
61
+ public static buildPaginationInfo({recordsLength = 0, offset = 0, recordsPerPage = 0}: PaginationInfoBuilderParams): PaginationInfo | undefined {
62
+
63
+ if (!recordsLength) {
64
+ return { currentPage: 0, firstRecord: 0, lastRecord: 0, total: 0, hasMore: false };
65
+ }
66
+
67
+ const lastRecordIndex = offset + recordsPerPage;
68
+ const lastRecord = lastRecordIndex ? Math.min(lastRecordIndex, recordsLength) : recordsLength;
69
+
70
+ return {
71
+ currentPage: recordsPerPage === 0 ? 0 : Math.ceil(offset / recordsPerPage),
72
+ firstRecord: offset + 1,
73
+ lastRecord: lastRecord,
74
+ total: recordsLength,
75
+ hasMore: lastRecord < recordsLength,
76
+ };
77
+ }
78
+
79
+ }
80
+
81
+
82
+ export interface PaginationInfoBuilderParams {
83
+ recordsLength: number,
84
+ offset: number,
85
+ recordsPerPage: number
86
+ }
@@ -1,38 +1,24 @@
1
- import { Record } from "../DataUnit.js";
2
- import { compareValues } from "../metadata/DataType.js";
3
- import { FieldDescriptor } from "../metadata/UnitMetadata.js";
1
+ import { Record } from '../DataUnit.js';
2
+ import { compareValues } from '../metadata/DataType.js';
3
+ import { FieldDescriptor } from '../metadata/UnitMetadata.js';
4
4
 
5
- export class FieldComparator{
5
+ export class FieldComparator {
6
6
 
7
- public static compare(field: FieldDescriptor, recordA: Record, recordB: Record, asc: boolean = true): number{
7
+ public static compare(field: FieldDescriptor, recordA: Record, recordB: Record, asc: boolean = true): number {
8
+ const valueA = (asc ? recordA : recordB)[field.name];
9
+ const valueB = (asc ? recordB : recordA)[field.name];
8
10
 
9
- const valueA = (asc ? recordA : recordB)[field.name];
10
- const valueB = (asc ? recordB : recordA)[field.name];
11
+ return FieldComparator.compareValues(field, valueA, valueB);
12
+ }
11
13
 
12
-
13
- return FieldComparator.compareValues(field, valueA, valueB);
14
- }
15
-
16
- public static compareValues(descriptor: FieldDescriptor, valueA: any, valueB: any): number{
17
- const undefinedComparison = this.compareUndefined(valueA == undefined, valueB == undefined);
18
-
19
- if(undefinedComparison != undefined){
20
- return undefinedComparison;
21
- }
14
+ public static compareValues(descriptor: FieldDescriptor, valueA: any, valueB: any): number {
15
+ const undefinedComparison = this.compareUndefined(valueA == undefined, valueB == undefined);
16
+ return (undefinedComparison != undefined) ? undefinedComparison : compareValues(valueA, valueB, descriptor);
17
+ }
22
18
 
23
- return compareValues(valueA, valueB, descriptor)
24
- }
25
-
26
- public static compareUndefined(isUndefinedA: boolean, isUndefinedB: boolean): number | undefined {
27
-
28
- if(!isUndefinedA && !isUndefinedB){
29
- return;
30
- }
31
-
32
- if(isUndefinedA && isUndefinedB){
33
- return 0;
34
- }
35
-
36
- return isUndefinedA ? -1 : 1;
37
- }
19
+ public static compareUndefined(isUndefinedA: boolean, isUndefinedB: boolean): number | undefined {
20
+ if (!isUndefinedA && !isUndefinedB) return;
21
+ if (isUndefinedA && isUndefinedB) return 0;
22
+ return isUndefinedA ? -1 : 1;
23
+ }
38
24
  }
package/src/index.ts CHANGED
@@ -45,6 +45,10 @@ import { ServiceUtils } from "./utils/ServiceUtils.js";
45
45
  import { StorageType } from "./utils/CacheManager/index.js";
46
46
  import OverflowWatcher, { OnOverflowCallBack, OverflowDirection, OverFlowWatcherParams, OVERFLOWED_CLASS_NAME } from "./utils/OverflowWatcher/index.js";
47
47
  import {LockManager, LockManagerOperation} from "./utils/LockManager.js";
48
+ import { DataUnitInMemoryLoader } from "./dataunit/loader/dataUnitInMemoryLoader.js";
49
+ import { DataUnitLoaderUtils, PaginationInfoBuilderParams } from "./dataunit/loader/utils/dataUnitLoaderUtils.js";
50
+ import { ColumnFilterManager } from "./utils/ColumnFilterManager.js";
51
+ import { DataUnitInMemoryLoaderConfig, RECORD_DATE_FORMAT } from "./dataunit/loader/DataUnitInMemoryLoaderConfig.js";
48
52
 
49
53
  /*Classes públicas no pacote*/
50
54
  export {
@@ -123,5 +127,11 @@ export {
123
127
  OVERFLOWED_CLASS_NAME,
124
128
  DataUnitEventOptions,
125
129
  ServiceCanceledException,
126
- SilentException
130
+ SilentException,
131
+ DataUnitInMemoryLoader,
132
+ DataUnitLoaderUtils,
133
+ PaginationInfoBuilderParams,
134
+ ColumnFilterManager,
135
+ DataUnitInMemoryLoaderConfig,
136
+ RECORD_DATE_FORMAT
127
137
  };
@@ -0,0 +1,104 @@
1
+ import { Filter } from '../dataunit/metadata/UnitMetadata.js';
2
+ import DataUnit, { Record } from '../dataunit/DataUnit.js';
3
+ import { FieldComparator } from '../dataunit/sorting/FieldComparator.js';
4
+ import { LoadDataRequest } from '../dataunit/loading/LoadDataRequest.js';
5
+
6
+ const COLUMN_FILTER_PATTERN = /FILTRO_COLUNA_(.+)/;
7
+
8
+ export class ColumnFilterManager {
9
+
10
+ public static getColumnFilters(filters: Array<Filter>, fieldName: string): Map<string, IColumnFilter> {
11
+ const columnFilters: Map<string, IColumnFilter> = new Map();
12
+
13
+ if (!filters?.length) {
14
+ return columnFilters;
15
+ }
16
+
17
+ filters.forEach(filter => {
18
+ const result = COLUMN_FILTER_PATTERN.exec(filter.name);
19
+ if (result) {
20
+ if (fieldName !== result[1]) {
21
+ columnFilters.set(filter.name, { columnName: result[1], ...filter });
22
+ }
23
+ }
24
+ });
25
+
26
+ return columnFilters;
27
+ }
28
+
29
+ public static getFilterFunction(dataUnit: DataUnit, filters?: Array<IColumnFilter>): ((record: Record) => boolean) | undefined {
30
+ if (!filters?.length) return undefined;
31
+
32
+ return record => {
33
+ for (const filter of filters) {
34
+ if (!ColumnFilterManager.recordMatchesFilter(dataUnit, record, filter)) {
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ };
40
+ }
41
+
42
+ private static recordMatchesFilter(dataUnit: DataUnit, record: Record, columnFilter: IColumnFilter): boolean {
43
+ const fieldDescriptor = dataUnit.getField(columnFilter.columnName);
44
+
45
+ if (!columnFilter.params || !fieldDescriptor) return false;
46
+
47
+ const fieldValue = record[columnFilter.columnName];
48
+
49
+ for (let param of columnFilter.params) {
50
+ const paramValue = dataUnit.valueFromString(columnFilter.columnName, param.value);
51
+ if (FieldComparator.compareValues(fieldDescriptor, fieldValue, paramValue) === 0) {
52
+ return true;
53
+ }
54
+
55
+ }
56
+ return false;
57
+ }
58
+
59
+ public static compileDistinct(fieldName: string, dataUnit: DataUnit): Array<IMultiSelectionOption> {
60
+ const request = dataUnit.getLastLoadRequest();
61
+ let list = dataUnit.records;
62
+ return this.doCompileDistinct(request, fieldName, dataUnit, list);
63
+ }
64
+
65
+ public static compileDistinctFromArray(fieldName: string, dataUnit: DataUnit, records: Array<Record>): Array<IMultiSelectionOption> {
66
+ const request = dataUnit.getLastLoadRequest();
67
+ return this.doCompileDistinct(request, fieldName, dataUnit, records);
68
+ }
69
+
70
+ private static doCompileDistinct(request: LoadDataRequest | undefined, fieldName: string, dataUnit: DataUnit, list: Array<Record>) {
71
+ if (request != undefined) {
72
+ const columnFilters: Array<IColumnFilter> = Array.from(ColumnFilterManager.getColumnFilters(request?.filters ?? [], fieldName).values());
73
+ const filterFunction = ColumnFilterManager.getFilterFunction(dataUnit, columnFilters);
74
+ if (filterFunction != undefined) {
75
+ list = list.filter(filterFunction);
76
+ }
77
+ }
78
+
79
+ const distinct: Map<string, IMultiSelectionOption> = new Map(
80
+ list.map(record => {
81
+ const fieldValue = record[fieldName];
82
+ if (fieldValue == undefined) {
83
+ return [null, { label: null, value: null, check: true }];
84
+ }
85
+ const item = { label: dataUnit.getFormattedValue(fieldName, fieldValue), value: fieldValue, check: true };
86
+ return [item.label, item];
87
+ }) as any,
88
+ );
89
+
90
+ return Array.from(distinct.values());
91
+ }
92
+
93
+ }
94
+
95
+
96
+ interface IMultiSelectionOption {
97
+ value: string;
98
+ label: string;
99
+ check: boolean;
100
+ }
101
+
102
+ export interface IColumnFilter extends Filter {
103
+ columnName: string;
104
+ }
@@ -9,7 +9,6 @@ import { keyCodeEventValues } from "./keyCodes/index.js";
9
9
  */
10
10
  export class KeyboardManager {
11
11
  private _options: IKeyboardOptions;
12
- private _shadowRoots: ShadowRoot [] = [];
13
12
  private _mappedElements: IKeyboardMappedKeysElements = {};
14
13
 
15
14
  /**
@@ -23,48 +22,10 @@ export class KeyboardManager {
23
22
  propagate: false,
24
23
  element: document.body,
25
24
  debounceTime: 0,
26
- enableShadowDom: false,
27
25
  ...options
28
26
  }
29
-
30
- if(this._options.enableShadowDom) {
31
- this._shadowRoots = this.findAllNestedShadowRoots(this._options.element);
32
- }
33
27
  }
34
28
 
35
- private findAllNestedShadowRoots(element: HTMLElement | Element | ChildNode | Document , results: ShadowRoot [] = []): ShadowRoot [] {
36
- if (!element) {
37
- return results;
38
- }
39
-
40
- const shadowRoot = (element as HTMLElement)?.shadowRoot;
41
- if (shadowRoot) {
42
- results.push(shadowRoot);
43
-
44
- shadowRoot.querySelectorAll("*").forEach((child) => {
45
- this.findAllNestedShadowRoots(child, results);
46
- });
47
- }
48
-
49
- element.childNodes.forEach((child) => {
50
- this.findAllNestedShadowRoots(child, results);
51
- });
52
-
53
- return results;
54
- }
55
-
56
- private addEventListenerToNestedShadowRoots(event: 'keydown' | 'keyup', callback: VoidFunction) {
57
- this._shadowRoots.forEach((shadowRoot) => {
58
- shadowRoot.addEventListener(event, callback);
59
- });
60
- }
61
-
62
- private removeEventListenerToNestedShadowRoots(event: 'keydown' | 'keyup', callback: VoidFunction) {
63
- this._shadowRoots.forEach((shadowRoot) => {
64
- shadowRoot.removeEventListener(event, callback);
65
- });
66
- }
67
-
68
29
  /**
69
30
  * Associa um evento de teclado com uma função
70
31
  *
@@ -100,10 +61,6 @@ export class KeyboardManager {
100
61
 
101
62
  bindOptions.element.addEventListener(bindOptions.type, debounceFunction);
102
63
 
103
- if(bindOptions.enableShadowDom) {
104
- this.addEventListenerToNestedShadowRoots(bindOptions.type, debounceFunction);
105
- }
106
-
107
64
  return this;
108
65
  }
109
66
 
@@ -129,10 +86,6 @@ export class KeyboardManager {
129
86
 
130
87
  element.removeEventListener(type, callback);
131
88
 
132
- if(unbindElement.options.enableShadowDom) {
133
- this.removeEventListenerToNestedShadowRoots(type, callback);
134
- }
135
-
136
89
  return this;
137
90
  }
138
91
 
@@ -1,7 +1,6 @@
1
1
  export interface IKeyboardOptions {
2
2
  type: 'keydown' | 'keyup',
3
3
  propagate: boolean,
4
- enableShadowDom: boolean,
5
4
  element: HTMLElement | Document,
6
5
  debounceTime: number,
7
6
  description?: string,