@oscarpalmer/tabela 0.4.0 → 0.5.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.
- package/dist/components/body.component.js +32 -55
- package/dist/components/column.component.js +20 -25
- package/dist/components/footer.component.js +33 -34
- package/dist/components/header.component.js +21 -26
- package/dist/components/row.component.js +30 -36
- package/dist/helpers/dom.helpers.js +35 -30
- package/dist/index.js +5 -5
- package/dist/managers/column.manager.js +19 -0
- package/dist/managers/data.manager.js +34 -0
- package/dist/managers/row.manager.js +21 -0
- package/dist/managers/virtualization.manager.js +81 -85
- package/dist/models/column.model.js +0 -1
- package/dist/models/tabela.options.js +0 -1
- package/dist/tabela.full.js +851 -0
- package/dist/tabela.js +43 -43
- package/package.json +22 -24
- package/src/components/body.component.ts +19 -46
- package/src/components/column.component.ts +14 -8
- package/src/components/footer.component.ts +16 -9
- package/src/components/header.component.ts +7 -9
- package/src/components/row.component.ts +31 -31
- package/src/helpers/dom.helpers.ts +50 -15
- package/src/index.ts +8 -1
- package/src/managers/column.manager.ts +32 -0
- package/src/managers/data.manager.ts +66 -0
- package/src/managers/row.manager.ts +32 -0
- package/src/managers/virtualization.manager.ts +86 -59
- package/src/models/column.model.ts +1 -7
- package/src/models/tabela.options.ts +2 -0
- package/src/tabela.ts +62 -36
- package/types/components/body.component.d.ts +0 -7
- package/types/components/footer.component.d.ts +2 -0
- package/types/components/header.component.d.ts +2 -2
- package/types/components/row.component.d.ts +5 -6
- package/types/helpers/dom.helpers.d.ts +1 -0
- package/types/index.d.ts +4 -1
- package/types/managers/column.manager.d.ts +10 -0
- package/types/managers/data.manager.d.ts +25 -0
- package/types/managers/row.manager.d.ts +11 -0
- package/types/managers/virtualization.manager.d.ts +7 -8
- package/types/models/tabela.options.d.ts +2 -0
- package/types/tabela.d.ts +17 -5
- package/dist/components/body.component.cjs +0 -58
- package/dist/components/column.component.cjs +0 -27
- package/dist/components/footer.component.cjs +0 -35
- package/dist/components/header.component.cjs +0 -28
- package/dist/components/row.component.cjs +0 -38
- package/dist/helpers/dom.helpers.cjs +0 -36
- package/dist/index.cjs +0 -5
- package/dist/managers/virtualization.manager.cjs +0 -88
- package/dist/models/column.model.cjs +0 -1
- package/dist/models/tabela.options.cjs +0 -1
- package/dist/tabela.cjs +0 -47
- package/types/components/body.component.d.cts +0 -98
- package/types/components/column.component.d.cts +0 -98
- package/types/components/footer.component.d.cts +0 -98
- package/types/components/header.component.d.cts +0 -98
- package/types/components/row.component.d.cts +0 -98
- package/types/helpers/dom.helpers.d.cts +0 -12
- package/types/index.d.cts +0 -99
- package/types/managers/virtualization.manager.d.cts +0 -98
- package/types/models/column.model.d.cts +0 -17
- package/types/models/tabela.options.d.cts +0 -18
- package/types/tabela.d.cts +0 -99
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {Key} from '@oscarpalmer/atoms/models';
|
|
2
|
+
import {RowComponent} from '../components/row.component';
|
|
3
|
+
import type {Tabela} from '../tabela';
|
|
4
|
+
|
|
5
|
+
export class RowManager {
|
|
6
|
+
readonly components: Map<Key, RowComponent> = new Map();
|
|
7
|
+
|
|
8
|
+
readonly height: number;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
readonly tabela: Tabela,
|
|
12
|
+
rowHeight: number,
|
|
13
|
+
) {
|
|
14
|
+
this.height = rowHeight;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
destroy(): void {
|
|
18
|
+
this.components.clear();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get(key: Key): RowComponent | undefined {
|
|
22
|
+
let row = this.components.get(key);
|
|
23
|
+
|
|
24
|
+
if (row == null) {
|
|
25
|
+
row = new RowComponent(key);
|
|
26
|
+
|
|
27
|
+
this.components.set(key, row);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return row;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import {on} from '@oscarpalmer/toretto/event';
|
|
2
|
+
import type {RemovableEventListener} from '@oscarpalmer/toretto/models';
|
|
3
|
+
import {removeRow, renderRow, RowComponent} from '../components/row.component';
|
|
4
|
+
import type {Tabela} from '../tabela';
|
|
5
|
+
|
|
6
|
+
type Bound = {
|
|
7
|
+
manager: VirtualizationManager;
|
|
8
|
+
state: State;
|
|
9
|
+
};
|
|
3
10
|
|
|
4
11
|
export type ElementPool = {
|
|
5
12
|
cells: Record<string, HTMLDivElement[]>;
|
|
@@ -11,113 +18,133 @@ type Range = {
|
|
|
11
18
|
start: number;
|
|
12
19
|
};
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
type State = {
|
|
22
|
+
active: boolean;
|
|
23
|
+
top: number;
|
|
24
|
+
};
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
function getRange(tabela: Tabela, down: boolean): Range {
|
|
27
|
+
const {components, managers} = tabela;
|
|
28
|
+
const {body} = components;
|
|
29
|
+
const {data, rows} = managers;
|
|
30
|
+
const {clientHeight, scrollTop} = body.elements.group;
|
|
19
31
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
Math.ceil((scrollTop + clientHeight) / 32) - 1,
|
|
23
|
-
);
|
|
32
|
+
const first = Math.floor(scrollTop / rows.height);
|
|
33
|
+
const last = Math.min(data.length - 1, Math.ceil((scrollTop + clientHeight) / rows.height) - 1);
|
|
24
34
|
|
|
25
|
-
const before = Math.ceil(clientHeight /
|
|
26
|
-
const after = Math.ceil(clientHeight /
|
|
35
|
+
const before = Math.ceil(clientHeight / rows.height) * (down ? 1 : 2);
|
|
36
|
+
const after = Math.ceil(clientHeight / rows.height) * (down ? 2 : 1);
|
|
27
37
|
|
|
28
38
|
const start = Math.max(0, first - before);
|
|
29
|
-
const end = Math.min(
|
|
39
|
+
const end = Math.min(data.length - 1, last + after);
|
|
30
40
|
|
|
31
41
|
return {end, start};
|
|
32
42
|
}
|
|
33
43
|
|
|
44
|
+
function onScroll(this: Bound): void {
|
|
45
|
+
if (!this.state.active) {
|
|
46
|
+
requestAnimationFrame(() => {
|
|
47
|
+
const top = this.manager.tabela.components.body.elements.group.scrollTop;
|
|
48
|
+
|
|
49
|
+
this.manager.update(top > this.state.top);
|
|
50
|
+
|
|
51
|
+
this.state.active = false;
|
|
52
|
+
this.state.top = top;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
this.state.active = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
34
59
|
export class VirtualizationManager {
|
|
35
|
-
|
|
60
|
+
fragment!: DocumentFragment;
|
|
36
61
|
|
|
37
|
-
|
|
62
|
+
listener: RemovableEventListener;
|
|
63
|
+
|
|
64
|
+
readonly #pool: ElementPool = {
|
|
38
65
|
cells: {},
|
|
39
66
|
rows: [],
|
|
40
67
|
};
|
|
41
68
|
|
|
42
|
-
|
|
69
|
+
readonly #state: State = {
|
|
70
|
+
active: false,
|
|
71
|
+
top: 0,
|
|
72
|
+
};
|
|
43
73
|
|
|
44
|
-
|
|
74
|
+
readonly #visible = new Map<number, RowComponent>();
|
|
45
75
|
|
|
46
|
-
constructor(
|
|
47
|
-
this.
|
|
76
|
+
constructor(readonly tabela: Tabela) {
|
|
77
|
+
this.listener = on(
|
|
78
|
+
tabela.components.body.elements.group,
|
|
48
79
|
'scroll',
|
|
49
|
-
(
|
|
50
|
-
this
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
passive: true,
|
|
54
|
-
},
|
|
80
|
+
onScroll.bind({
|
|
81
|
+
manager: this,
|
|
82
|
+
state: this.#state,
|
|
83
|
+
}),
|
|
55
84
|
);
|
|
56
85
|
}
|
|
57
86
|
|
|
58
87
|
destroy(): void {
|
|
59
|
-
|
|
88
|
+
this.listener();
|
|
60
89
|
|
|
61
|
-
for (const [index, row] of visible) {
|
|
62
|
-
row
|
|
63
|
-
|
|
90
|
+
for (const [index, row] of this.#visible) {
|
|
91
|
+
removeRow(row, this.#pool);
|
|
92
|
+
|
|
93
|
+
this.#visible.delete(index);
|
|
64
94
|
}
|
|
65
95
|
|
|
66
|
-
pool.cells = {};
|
|
67
|
-
pool.rows = [];
|
|
96
|
+
this.#pool.cells = {};
|
|
97
|
+
this.#pool.rows = [];
|
|
68
98
|
}
|
|
69
99
|
|
|
70
100
|
update(down: boolean): void {
|
|
71
|
-
const {
|
|
101
|
+
const {tabela} = this;
|
|
102
|
+
const {rows} = tabela.managers;
|
|
72
103
|
|
|
73
104
|
const indices = new Set<number>();
|
|
74
|
-
const range = getRange(
|
|
105
|
+
const range = getRange(tabela, down);
|
|
75
106
|
|
|
76
107
|
for (let index = range.start; index <= range.end; index += 1) {
|
|
77
108
|
indices.add(index);
|
|
78
109
|
}
|
|
79
110
|
|
|
80
|
-
for (const [index, row] of visible) {
|
|
111
|
+
for (const [index, row] of this.#visible) {
|
|
81
112
|
if (!indices.has(index)) {
|
|
82
|
-
visible.delete(index);
|
|
113
|
+
this.#visible.delete(index);
|
|
83
114
|
|
|
84
|
-
row
|
|
115
|
+
removeRow(row, this.#pool);
|
|
85
116
|
}
|
|
86
117
|
}
|
|
87
118
|
|
|
88
|
-
|
|
119
|
+
this.fragment ??= document.createDocumentFragment();
|
|
89
120
|
|
|
90
|
-
|
|
91
|
-
if (!visible.has(index)) {
|
|
92
|
-
const row = body.rows[index];
|
|
121
|
+
this.fragment.replaceChildren();
|
|
93
122
|
|
|
94
|
-
|
|
123
|
+
const keys =
|
|
124
|
+
tabela.managers.data.values.keys.active ?? tabela.managers.data.values.keys.original;
|
|
95
125
|
|
|
96
|
-
|
|
126
|
+
for (let index = range.start; index <= range.end; index += 1) {
|
|
127
|
+
if (this.#visible.has(index)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
97
130
|
|
|
98
|
-
|
|
99
|
-
row.element.style.transform = `translateY(${index * 32}px)`;
|
|
131
|
+
const row = tabela.managers.rows.get(keys[index]);
|
|
100
132
|
|
|
101
|
-
|
|
102
|
-
|
|
133
|
+
if (row == null) {
|
|
134
|
+
continue;
|
|
103
135
|
}
|
|
104
136
|
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private onScroll(): void {
|
|
110
|
-
if (!this.active) {
|
|
111
|
-
requestAnimationFrame(() => {
|
|
112
|
-
const top = this.body.elements.group.scrollTop;
|
|
137
|
+
renderRow(tabela, this.#pool, row);
|
|
113
138
|
|
|
114
|
-
|
|
139
|
+
this.#visible.set(index, row);
|
|
115
140
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
141
|
+
if (row.element != null) {
|
|
142
|
+
row.element.style.transform = `translateY(${index * rows.height}px)`;
|
|
119
143
|
|
|
120
|
-
|
|
144
|
+
this.fragment.append(row.element);
|
|
145
|
+
}
|
|
121
146
|
}
|
|
147
|
+
|
|
148
|
+
tabela.components.body.elements.group.append(this.fragment);
|
|
122
149
|
}
|
|
123
150
|
}
|
|
@@ -12,10 +12,4 @@ export type TabelaColumnOptions = {
|
|
|
12
12
|
width?: number;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export type TabelaColumnType =
|
|
16
|
-
| 'boolean'
|
|
17
|
-
| 'date'
|
|
18
|
-
| 'date-time'
|
|
19
|
-
| 'number'
|
|
20
|
-
| 'string'
|
|
21
|
-
| 'time';
|
|
15
|
+
export type TabelaColumnType = 'boolean' | 'date' | 'date-time' | 'number' | 'string' | 'time';
|
package/src/tabela.ts
CHANGED
|
@@ -1,54 +1,80 @@
|
|
|
1
1
|
import {BodyComponent} from './components/body.component';
|
|
2
2
|
import {FooterComponent} from './components/footer.component';
|
|
3
3
|
import {HeaderComponent} from './components/header.component';
|
|
4
|
+
import {ColumnManager} from './managers/column.manager';
|
|
5
|
+
import {DataManager} from './managers/data.manager';
|
|
6
|
+
import {RowManager} from './managers/row.manager';
|
|
4
7
|
import type {TabelaOptions} from './models/tabela.options';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
type Components = {
|
|
10
|
+
body: BodyComponent;
|
|
11
|
+
footer: FooterComponent;
|
|
12
|
+
header: HeaderComponent;
|
|
13
|
+
};
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
element.role = 'table';
|
|
15
|
+
type Managers = {
|
|
16
|
+
columns: ColumnManager;
|
|
17
|
+
data: DataManager;
|
|
18
|
+
rows: RowManager;
|
|
19
|
+
};
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
export class Tabela {
|
|
22
|
+
readonly components: Components;
|
|
23
|
+
readonly key: string;
|
|
24
|
+
readonly managers: Managers;
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
constructor(
|
|
27
|
+
public element: HTMLElement,
|
|
28
|
+
options: TabelaOptions,
|
|
29
|
+
) {
|
|
30
|
+
element.innerHTML = '';
|
|
31
|
+
element.role = 'table';
|
|
21
32
|
|
|
22
|
-
|
|
23
|
-
this.body = new BodyComponent(this);
|
|
24
|
-
this.footer = new FooterComponent(this);
|
|
33
|
+
element.classList.add('tabela');
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
this.header.elements.group,
|
|
28
|
-
this.body.elements.group,
|
|
29
|
-
this.footer.elements.group,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
35
|
+
element.setAttribute('aria-label', options.label);
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
this.body.destroy();
|
|
35
|
-
this.footer.destroy();
|
|
36
|
-
this.header.destroy();
|
|
37
|
+
this.key = options.key;
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
this.components = {
|
|
40
|
+
header: new HeaderComponent(this),
|
|
41
|
+
body: new BodyComponent(this),
|
|
42
|
+
footer: new FooterComponent(this),
|
|
43
|
+
};
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
this.
|
|
45
|
+
this.managers = {
|
|
46
|
+
columns: new ColumnManager(this, options.columns),
|
|
47
|
+
data: new DataManager(this, options.data),
|
|
48
|
+
rows: new RowManager(this, options.rowHeight),
|
|
49
|
+
};
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
51
|
+
element.append(
|
|
52
|
+
this.components.header.elements.group,
|
|
53
|
+
this.components.body.elements.group,
|
|
54
|
+
this.components.footer.elements.group,
|
|
55
|
+
);
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
}
|
|
57
|
+
this.managers.data.update();
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
destroy(): void {
|
|
61
|
+
const {components, element, managers} = this;
|
|
62
|
+
|
|
63
|
+
components.body.destroy();
|
|
64
|
+
components.footer.destroy();
|
|
65
|
+
components.header.destroy();
|
|
66
|
+
|
|
67
|
+
managers.columns.destroy();
|
|
68
|
+
managers.data.destroy();
|
|
69
|
+
managers.rows.destroy();
|
|
70
|
+
|
|
71
|
+
element.innerHTML = '';
|
|
72
|
+
element.role = '';
|
|
73
|
+
|
|
74
|
+
element.classList.remove('tabela');
|
|
75
|
+
element.removeAttribute('aria-label');
|
|
76
|
+
element.removeAttribute('role');
|
|
77
|
+
|
|
78
|
+
this.element = undefined as never;
|
|
79
|
+
}
|
|
54
80
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type { PlainObject } from '@oscarpalmer/atoms/models';
|
|
2
|
-
import { VirtualizationManager } from '../managers/virtualization.manager';
|
|
3
1
|
import type { Tabela } from '../tabela';
|
|
4
|
-
import { RowComponent } from './row.component';
|
|
5
2
|
type Elements = {
|
|
6
3
|
faker: HTMLDivElement;
|
|
7
4
|
group: HTMLDivElement;
|
|
@@ -9,11 +6,7 @@ type Elements = {
|
|
|
9
6
|
export declare class BodyComponent {
|
|
10
7
|
readonly tabela: Tabela;
|
|
11
8
|
readonly elements: Elements;
|
|
12
|
-
readonly rows: RowComponent[];
|
|
13
|
-
readonly virtualization: VirtualizationManager;
|
|
14
9
|
constructor(tabela: Tabela);
|
|
15
|
-
addData(data: PlainObject[]): Promise<void>;
|
|
16
10
|
destroy(): void;
|
|
17
|
-
private updateVirtualization;
|
|
18
11
|
}
|
|
19
12
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Tabela } from '../tabela';
|
|
2
|
+
import type { ColumnComponent } from './column.component';
|
|
2
3
|
type Elements = {
|
|
3
4
|
cells: HTMLDivElement[];
|
|
4
5
|
group: HTMLDivElement;
|
|
@@ -9,5 +10,6 @@ export declare class FooterComponent {
|
|
|
9
10
|
readonly elements: Elements;
|
|
10
11
|
constructor(tabela: Tabela);
|
|
11
12
|
destroy(): void;
|
|
13
|
+
update(columns: ColumnComponent[]): void;
|
|
12
14
|
}
|
|
13
15
|
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Tabela } from '../tabela';
|
|
2
|
-
import { ColumnComponent } from './column.component';
|
|
2
|
+
import type { ColumnComponent } from './column.component';
|
|
3
3
|
type Elements = {
|
|
4
4
|
group: HTMLDivElement;
|
|
5
5
|
row: HTMLDivElement;
|
|
6
6
|
};
|
|
7
7
|
export declare class HeaderComponent {
|
|
8
8
|
readonly tabela: Tabela;
|
|
9
|
-
readonly columns: ColumnComponent[];
|
|
10
9
|
readonly elements: Elements;
|
|
11
10
|
constructor(tabela: Tabela);
|
|
12
11
|
destroy(): void;
|
|
12
|
+
update(columns: ColumnComponent[]): void;
|
|
13
13
|
}
|
|
14
14
|
export {};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Key } from '@oscarpalmer/atoms/models';
|
|
2
2
|
import type { ElementPool } from '../managers/virtualization.manager';
|
|
3
3
|
import type { Tabela } from '../tabela';
|
|
4
|
+
export declare function removeRow(row: RowComponent, pool: ElementPool): void;
|
|
5
|
+
export declare function renderRow(tabela: Tabela, pool: ElementPool, row: RowComponent): void;
|
|
4
6
|
export declare class RowComponent {
|
|
5
|
-
readonly
|
|
6
|
-
readonly data: PlainObject;
|
|
7
|
+
readonly key: Key;
|
|
7
8
|
element: HTMLDivElement | undefined;
|
|
8
|
-
constructor(
|
|
9
|
-
remove(pool: ElementPool): void;
|
|
10
|
-
render(pool: ElementPool): void;
|
|
9
|
+
constructor(key: Key);
|
|
11
10
|
}
|
|
@@ -3,6 +3,7 @@ type RowGroupWithRow = {
|
|
|
3
3
|
row: HTMLDivElement;
|
|
4
4
|
};
|
|
5
5
|
export declare function createCell(width: number, body?: boolean): HTMLDivElement;
|
|
6
|
+
export declare function createElement<TagName extends keyof HTMLElementTagNameMap>(tagName: TagName, properties: Partial<HTMLElementTagNameMap[TagName]>, style: Partial<CSSStyleDeclaration>): HTMLElementTagNameMap[TagName];
|
|
6
7
|
export declare function createRowGroup(): RowGroupWithRow;
|
|
7
8
|
export declare function createRowGroup(withRow: boolean): HTMLDivElement;
|
|
8
9
|
export declare function createRow(withStyle?: boolean): HTMLDivElement;
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ColumnComponent } from '../components/column.component';
|
|
2
|
+
import type { TabelaColumnOptions } from '../models/column.model';
|
|
3
|
+
import type { Tabela } from '../tabela';
|
|
4
|
+
export declare class ColumnManager {
|
|
5
|
+
readonly tabela: Tabela;
|
|
6
|
+
readonly components: ColumnComponent[];
|
|
7
|
+
constructor(tabela: Tabela, columns: TabelaColumnOptions[]);
|
|
8
|
+
destroy(): void;
|
|
9
|
+
set(columns: TabelaColumnOptions[]): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Key, PlainObject } from '@oscarpalmer/atoms/models';
|
|
2
|
+
import type { Tabela } from '../tabela';
|
|
3
|
+
import { VirtualizationManager } from './virtualization.manager';
|
|
4
|
+
type Keys = {
|
|
5
|
+
active?: Key[];
|
|
6
|
+
original: Key[];
|
|
7
|
+
};
|
|
8
|
+
type Objects = {
|
|
9
|
+
array: PlainObject[];
|
|
10
|
+
mapped: Map<Key, PlainObject>;
|
|
11
|
+
};
|
|
12
|
+
type Values = {
|
|
13
|
+
keys: Keys;
|
|
14
|
+
objects: Objects;
|
|
15
|
+
};
|
|
16
|
+
export declare class DataManager {
|
|
17
|
+
readonly tabela: Tabela;
|
|
18
|
+
readonly values: Values;
|
|
19
|
+
readonly virtualization: VirtualizationManager;
|
|
20
|
+
get length(): number;
|
|
21
|
+
constructor(tabela: Tabela, values: PlainObject[]);
|
|
22
|
+
destroy(): void;
|
|
23
|
+
update(): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Key } from '@oscarpalmer/atoms/models';
|
|
2
|
+
import { RowComponent } from '../components/row.component';
|
|
3
|
+
import type { Tabela } from '../tabela';
|
|
4
|
+
export declare class RowManager {
|
|
5
|
+
readonly tabela: Tabela;
|
|
6
|
+
readonly components: Map<Key, RowComponent>;
|
|
7
|
+
readonly height: number;
|
|
8
|
+
constructor(tabela: Tabela, rowHeight: number);
|
|
9
|
+
destroy(): void;
|
|
10
|
+
get(key: Key): RowComponent | undefined;
|
|
11
|
+
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RemovableEventListener } from '@oscarpalmer/toretto/models';
|
|
2
|
+
import type { Tabela } from '../tabela';
|
|
2
3
|
export type ElementPool = {
|
|
3
4
|
cells: Record<string, HTMLDivElement[]>;
|
|
4
5
|
rows: HTMLDivElement[];
|
|
5
6
|
};
|
|
6
7
|
export declare class VirtualizationManager {
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor(body: BodyComponent);
|
|
8
|
+
#private;
|
|
9
|
+
readonly tabela: Tabela;
|
|
10
|
+
fragment: DocumentFragment;
|
|
11
|
+
listener: RemovableEventListener;
|
|
12
|
+
constructor(tabela: Tabela);
|
|
13
13
|
destroy(): void;
|
|
14
14
|
update(down: boolean): void;
|
|
15
|
-
private onScroll;
|
|
16
15
|
}
|
package/types/tabela.d.ts
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { BodyComponent } from './components/body.component';
|
|
2
2
|
import { FooterComponent } from './components/footer.component';
|
|
3
3
|
import { HeaderComponent } from './components/header.component';
|
|
4
|
+
import { ColumnManager } from './managers/column.manager';
|
|
5
|
+
import { DataManager } from './managers/data.manager';
|
|
6
|
+
import { RowManager } from './managers/row.manager';
|
|
4
7
|
import type { TabelaOptions } from './models/tabela.options';
|
|
8
|
+
type Components = {
|
|
9
|
+
body: BodyComponent;
|
|
10
|
+
footer: FooterComponent;
|
|
11
|
+
header: HeaderComponent;
|
|
12
|
+
};
|
|
13
|
+
type Managers = {
|
|
14
|
+
columns: ColumnManager;
|
|
15
|
+
data: DataManager;
|
|
16
|
+
rows: RowManager;
|
|
17
|
+
};
|
|
5
18
|
export declare class Tabela {
|
|
6
19
|
element: HTMLElement;
|
|
7
|
-
readonly
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly header: HeaderComponent;
|
|
20
|
+
readonly components: Components;
|
|
21
|
+
readonly key: string;
|
|
22
|
+
readonly managers: Managers;
|
|
11
23
|
constructor(element: HTMLElement, options: TabelaOptions);
|
|
12
24
|
destroy(): void;
|
|
13
25
|
}
|
|
14
|
-
export
|
|
26
|
+
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
-
const helpers_dom_helpers = require("../helpers/dom.helpers.cjs");
|
|
7
|
-
const managers_virtualization_manager = require("../managers/virtualization.manager.cjs");
|
|
8
|
-
const components_row_component = require("./row.component.cjs");
|
|
9
|
-
function createFaker() {
|
|
10
|
-
const element = document.createElement("div");
|
|
11
|
-
element.style.height = "0";
|
|
12
|
-
element.style.inset = "0 auto auto 0";
|
|
13
|
-
element.style.opacity = "0";
|
|
14
|
-
element.style.pointerEvents = "none";
|
|
15
|
-
element.style.position = "absolute";
|
|
16
|
-
element.style.width = "1px";
|
|
17
|
-
return element;
|
|
18
|
-
}
|
|
19
|
-
class BodyComponent {
|
|
20
|
-
constructor(tabela) {
|
|
21
|
-
__publicField(this, "elements", {
|
|
22
|
-
faker: createFaker(),
|
|
23
|
-
group: void 0
|
|
24
|
-
});
|
|
25
|
-
__publicField(this, "rows", []);
|
|
26
|
-
__publicField(this, "virtualization");
|
|
27
|
-
this.tabela = tabela;
|
|
28
|
-
const group = helpers_dom_helpers.createRowGroup(false);
|
|
29
|
-
this.elements.group = group;
|
|
30
|
-
this.virtualization = new managers_virtualization_manager.VirtualizationManager(this);
|
|
31
|
-
group.className += " tabela__rowgroup-body";
|
|
32
|
-
group.style.height = "100%";
|
|
33
|
-
group.style.overflow = "auto";
|
|
34
|
-
group.style.position = "relative";
|
|
35
|
-
group.append(this.elements.faker);
|
|
36
|
-
void this.addData(tabela.options.data).then(() => {
|
|
37
|
-
this.virtualization.update(true);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
async addData(data) {
|
|
41
|
-
const { length } = data;
|
|
42
|
-
for (let index = 0; index < length; index += 1) {
|
|
43
|
-
this.rows.push(new components_row_component.RowComponent(this.tabela, data[index]));
|
|
44
|
-
}
|
|
45
|
-
this.updateVirtualization();
|
|
46
|
-
}
|
|
47
|
-
destroy() {
|
|
48
|
-
this.virtualization.destroy();
|
|
49
|
-
this.elements.faker = void 0;
|
|
50
|
-
this.elements.group = void 0;
|
|
51
|
-
this.rows.length = 0;
|
|
52
|
-
}
|
|
53
|
-
updateVirtualization() {
|
|
54
|
-
this.elements.faker.style.height = `${this.rows.length * 32}px`;
|
|
55
|
-
this.virtualization.update(true);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.BodyComponent = BodyComponent;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
-
function createElement(title, width) {
|
|
7
|
-
const cell = document.createElement("div");
|
|
8
|
-
cell.className = "tabela__heading";
|
|
9
|
-
cell.role = "columnheader";
|
|
10
|
-
cell.style.width = `${width}px`;
|
|
11
|
-
cell.textContent = title;
|
|
12
|
-
return cell;
|
|
13
|
-
}
|
|
14
|
-
class ColumnComponent {
|
|
15
|
-
constructor(tabela, options) {
|
|
16
|
-
__publicField(this, "element");
|
|
17
|
-
__publicField(this, "options");
|
|
18
|
-
this.tabela = tabela;
|
|
19
|
-
const width = Number.parseInt(getComputedStyle(tabela.element).fontSize, 10) * (options.width ?? options.title.length * 1.5);
|
|
20
|
-
this.options = {
|
|
21
|
-
...options,
|
|
22
|
-
width
|
|
23
|
-
};
|
|
24
|
-
this.element = createElement(options.title, width);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.ColumnComponent = ColumnComponent;
|