@oscarpalmer/tabela 0.10.0 → 0.12.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 +1 -0
- package/dist/components/column.component.js +4 -4
- package/dist/components/group.component.js +28 -0
- package/dist/components/row.component.js +11 -8
- package/dist/helpers/dom.helpers.js +1 -1
- package/dist/managers/column.manager.js +9 -8
- package/dist/managers/data.manager.js +95 -30
- package/dist/managers/event.manager.js +42 -23
- package/dist/managers/filter.manager.js +16 -10
- package/dist/managers/group.manager.js +46 -0
- package/dist/managers/navigation.manager.js +73 -0
- package/dist/managers/render.manager.js +61 -31
- package/dist/managers/row.manager.js +7 -7
- package/dist/managers/selection.manager.js +49 -46
- package/dist/managers/sort.manager.js +37 -9
- package/dist/models/group.model.js +0 -0
- package/dist/models/selection.model.js +0 -0
- package/dist/tabela.full.js +682 -591
- package/dist/tabela.js +31 -10
- package/package.json +1 -1
- package/src/components/body.component.ts +2 -0
- package/src/components/column.component.ts +6 -6
- package/src/components/group.component.ts +43 -0
- package/src/components/row.component.ts +14 -9
- package/src/helpers/dom.helpers.ts +3 -1
- package/src/managers/column.manager.ts +13 -15
- package/src/managers/data.manager.ts +176 -38
- package/src/managers/event.manager.ts +68 -41
- package/src/managers/filter.manager.ts +29 -20
- package/src/managers/group.manager.ts +79 -0
- package/src/managers/navigation.manager.ts +146 -0
- package/src/managers/render.manager.ts +84 -40
- package/src/managers/row.manager.ts +9 -14
- package/src/managers/selection.manager.ts +68 -67
- package/src/managers/sort.manager.ts +85 -22
- package/src/models/column.model.ts +2 -2
- package/src/models/data.model.ts +14 -3
- package/src/models/filter.model.ts +11 -3
- package/src/models/group.model.ts +4 -0
- package/src/models/render.model.ts +3 -1
- package/src/models/selection.model.ts +9 -0
- package/src/models/sort.model.ts +11 -3
- package/src/models/tabela.model.ts +14 -36
- package/src/models/tabela.options.ts +3 -2
- package/src/tabela.ts +43 -19
- package/types/components/column.component.d.ts +3 -3
- package/types/components/group.component.d.ts +14 -0
- package/types/components/row.component.d.ts +2 -2
- package/types/helpers/style.helper.d.ts +1 -1
- package/types/managers/column.manager.d.ts +6 -7
- package/types/managers/data.manager.d.ts +7 -6
- package/types/managers/event.manager.d.ts +3 -6
- package/types/managers/filter.manager.d.ts +11 -11
- package/types/managers/group.manager.d.ts +17 -0
- package/types/managers/navigation.manager.d.ts +10 -0
- package/types/managers/render.manager.d.ts +6 -7
- package/types/managers/row.manager.d.ts +4 -5
- package/types/managers/selection.manager.d.ts +12 -7
- package/types/managers/sort.manager.d.ts +11 -9
- package/types/models/column.model.d.ts +2 -2
- package/types/models/data.model.d.ts +13 -3
- package/types/models/filter.model.d.ts +10 -3
- package/types/models/group.model.d.ts +4 -0
- package/types/models/render.model.d.ts +2 -1
- package/types/models/selection.model.d.ts +8 -0
- package/types/models/sort.model.d.ts +10 -3
- package/types/models/tabela.model.d.ts +14 -33
- package/types/models/tabela.options.d.ts +3 -2
- package/types/tabela.d.ts +4 -1
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import type {Key} from '@oscarpalmer/atoms/models';
|
|
2
2
|
import {removeRow, renderRow, RowComponent} from '../components/row.component';
|
|
3
|
-
import type {
|
|
3
|
+
import type {State} from '../models/tabela.model';
|
|
4
4
|
|
|
5
5
|
export class RowManager {
|
|
6
|
-
|
|
6
|
+
components = new Map<Key, RowComponent>();
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
readonly managers: TabelaManagers,
|
|
12
|
-
rowHeight: number,
|
|
13
|
-
) {
|
|
14
|
-
this.height = rowHeight;
|
|
15
|
-
}
|
|
8
|
+
constructor(public state: State) {}
|
|
16
9
|
|
|
17
10
|
destroy(): void {
|
|
18
11
|
const components = [...this.components.values()];
|
|
19
|
-
|
|
20
12
|
const {length} = components;
|
|
21
13
|
|
|
22
14
|
for (let index = 0; index < length; index += 1) {
|
|
23
|
-
removeRow(this.managers.render.pool, components[index]);
|
|
15
|
+
removeRow(this.state.managers.render.pool, components[index]);
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
this.components.clear();
|
|
19
|
+
|
|
20
|
+
this.components = undefined as never;
|
|
21
|
+
this.state = undefined as never;
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
get(key: Key): RowComponent | undefined {
|
|
@@ -46,7 +41,7 @@ export class RowManager {
|
|
|
46
41
|
const row = this.components.get(key);
|
|
47
42
|
|
|
48
43
|
if (row != null) {
|
|
49
|
-
removeRow(this.managers.render.pool, row);
|
|
44
|
+
removeRow(this.state.managers.render.pool, row);
|
|
50
45
|
|
|
51
46
|
this.components.delete(key);
|
|
52
47
|
}
|
|
@@ -56,7 +51,7 @@ export class RowManager {
|
|
|
56
51
|
const row = this.components.get(key);
|
|
57
52
|
|
|
58
53
|
if (row != null) {
|
|
59
|
-
renderRow(this.
|
|
54
|
+
renderRow(this.state, row);
|
|
60
55
|
}
|
|
61
56
|
}
|
|
62
57
|
}
|
|
@@ -1,68 +1,72 @@
|
|
|
1
1
|
import {isKey} from '@oscarpalmer/atoms/is';
|
|
2
2
|
import type {Key} from '@oscarpalmer/atoms/models';
|
|
3
|
-
import {findAncestor, type EventPosition} from '@oscarpalmer/toretto';
|
|
4
3
|
import {setAttribute} from '@oscarpalmer/toretto/attribute';
|
|
5
4
|
import {getPosition, on} from '@oscarpalmer/toretto/event';
|
|
5
|
+
import {findAncestor} from '@oscarpalmer/toretto/find';
|
|
6
|
+
import type {EventPosition} from '@oscarpalmer/toretto/models';
|
|
6
7
|
import {createElement} from '../helpers/dom.helpers';
|
|
7
8
|
import {getKey} from '../helpers/misc.helpers';
|
|
8
9
|
import {dragStyling} from '../helpers/style.helper';
|
|
9
|
-
import type {
|
|
10
|
+
import type {TabelaSelection} from '../models/selection.model';
|
|
11
|
+
import type {State} from '../models/tabela.model';
|
|
12
|
+
import {GroupComponent} from '../components/group.component';
|
|
10
13
|
|
|
11
14
|
export class SelectionManager {
|
|
12
15
|
handlers = Object.freeze({
|
|
16
|
+
add: keys => this.add(keys),
|
|
13
17
|
clear: () => this.clear(),
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
remove: keys => this.remove(keys),
|
|
19
|
+
set: keys => this.set(keys),
|
|
16
20
|
toggle: () => this.toggle(),
|
|
17
|
-
}
|
|
21
|
+
} satisfies TabelaSelection);
|
|
18
22
|
|
|
19
23
|
items = new Set<Key>();
|
|
20
24
|
|
|
21
25
|
last: Key | undefined;
|
|
22
26
|
|
|
23
|
-
constructor(
|
|
24
|
-
|
|
25
|
-
readonly managers: TabelaManagers,
|
|
26
|
-
) {
|
|
27
|
-
mapped.set(element, this);
|
|
27
|
+
constructor(public state: State) {
|
|
28
|
+
mapped.set(state.element, this);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
if (this.items.size === 0) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const removed = [...this.items];
|
|
36
|
-
|
|
37
|
-
this.items.clear();
|
|
38
|
-
|
|
39
|
-
this.update(removed);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
deselect(keys: Key[]): void {
|
|
31
|
+
add(keys: Key[]): void {
|
|
43
32
|
const {length} = keys;
|
|
44
33
|
|
|
45
|
-
|
|
34
|
+
let update = false;
|
|
46
35
|
|
|
47
36
|
for (let index = 0; index < length; index += 1) {
|
|
48
37
|
const key = keys[index];
|
|
49
38
|
|
|
50
|
-
if (this.items.
|
|
51
|
-
|
|
39
|
+
if (!this.items.has(key)) {
|
|
40
|
+
this.items.add(key);
|
|
41
|
+
|
|
42
|
+
update = true;
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
45
|
|
|
55
|
-
if (
|
|
56
|
-
this.update(
|
|
46
|
+
if (update) {
|
|
47
|
+
this.update([]);
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
50
|
|
|
51
|
+
clear(): void {
|
|
52
|
+
if (this.items.size === 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const removed = [...this.items];
|
|
57
|
+
|
|
58
|
+
this.items.clear();
|
|
59
|
+
|
|
60
|
+
this.update(removed);
|
|
61
|
+
}
|
|
62
|
+
|
|
60
63
|
destroy(): void {
|
|
61
|
-
mapped.delete(this.element);
|
|
64
|
+
mapped.delete(this.state.element);
|
|
62
65
|
|
|
63
66
|
this.handlers = undefined as never;
|
|
64
|
-
this.element = undefined as never;
|
|
65
67
|
this.items = undefined as never;
|
|
68
|
+
this.last = undefined;
|
|
69
|
+
this.state = undefined as never;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
handle(event: MouseEvent, target: HTMLElement): void {
|
|
@@ -76,42 +80,34 @@ export class SelectionManager {
|
|
|
76
80
|
|
|
77
81
|
if (event.shiftKey) {
|
|
78
82
|
if (this.last == null) {
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
this.state.managers.navigation.setActive(key, false);
|
|
84
|
+
} else {
|
|
85
|
+
this.range(this.last, key);
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
this.range(this.last, key);
|
|
85
|
-
|
|
86
|
-
this.last = key;
|
|
87
|
-
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
this.last = key;
|
|
92
92
|
|
|
93
|
+
this.state.managers.navigation.setActive(key, false);
|
|
94
|
+
|
|
93
95
|
if (event.ctrlKey || event.metaKey) {
|
|
94
96
|
if (items.has(key)) {
|
|
95
|
-
this.
|
|
97
|
+
this.remove([key]);
|
|
96
98
|
} else {
|
|
97
|
-
this.
|
|
99
|
+
this.add([key]);
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
return;
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
if (items.size === 1) {
|
|
105
|
-
this.clear();
|
|
106
|
-
} else {
|
|
107
|
-
this.set([key]);
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
this.set([key]);
|
|
111
|
-
}
|
|
105
|
+
this.set([key]);
|
|
112
106
|
}
|
|
113
107
|
|
|
114
108
|
range(from: Key | HTMLElement, to: Key | HTMLElement): void {
|
|
109
|
+
const {state} = this;
|
|
110
|
+
|
|
115
111
|
const keyed = isKey(from) && isKey(to);
|
|
116
112
|
|
|
117
113
|
const fromKey = keyed ? (from as Key) : getKey((from as HTMLElement).getAttribute('data-key'))!;
|
|
@@ -121,10 +117,10 @@ export class SelectionManager {
|
|
|
121
117
|
return;
|
|
122
118
|
}
|
|
123
119
|
|
|
124
|
-
const keys =
|
|
120
|
+
const {keys} = state.managers.data;
|
|
125
121
|
|
|
126
|
-
const fromIndex =
|
|
127
|
-
const toIndex =
|
|
122
|
+
const fromIndex = state.managers.data.getIndex(fromKey);
|
|
123
|
+
const toIndex = state.managers.data.getIndex(toKey);
|
|
128
124
|
|
|
129
125
|
if (fromIndex === -1 || toIndex === -1) {
|
|
130
126
|
return;
|
|
@@ -135,33 +131,39 @@ export class SelectionManager {
|
|
|
135
131
|
const selected: Key[] = [];
|
|
136
132
|
|
|
137
133
|
for (let index = start; index <= end; index += 1) {
|
|
138
|
-
|
|
134
|
+
const key = keys[index];
|
|
135
|
+
|
|
136
|
+
if (!(key instanceof GroupComponent)) {
|
|
137
|
+
selected.push(key);
|
|
138
|
+
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
if (keyed) {
|
|
142
|
-
this.
|
|
142
|
+
this.add(selected);
|
|
143
143
|
} else {
|
|
144
144
|
this.set(selected);
|
|
145
145
|
}
|
|
146
|
+
|
|
147
|
+
this.last = toKey;
|
|
148
|
+
|
|
149
|
+
this.state.managers.navigation.setActive(toKey, false);
|
|
146
150
|
}
|
|
147
151
|
|
|
148
|
-
|
|
152
|
+
remove(keys: Key[]): void {
|
|
149
153
|
const {length} = keys;
|
|
150
154
|
|
|
151
|
-
|
|
155
|
+
const removed: Key[] = [];
|
|
152
156
|
|
|
153
157
|
for (let index = 0; index < length; index += 1) {
|
|
154
158
|
const key = keys[index];
|
|
155
159
|
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
update = true;
|
|
160
|
+
if (this.items.delete(key)) {
|
|
161
|
+
removed.push(key);
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
|
|
163
|
-
if (
|
|
164
|
-
this.update(
|
|
165
|
+
if (removed.length > 0) {
|
|
166
|
+
this.update(removed);
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
|
|
@@ -181,14 +183,13 @@ export class SelectionManager {
|
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
toggle(): void {
|
|
184
|
-
const {items,
|
|
185
|
-
|
|
186
|
-
const all = managers.data.values.keys.active ?? managers.data.values.keys.original;
|
|
186
|
+
const {items, state} = this;
|
|
187
|
+
const {keys} = state.managers.data;
|
|
187
188
|
|
|
188
|
-
if (items.size ===
|
|
189
|
+
if (items.size === keys.length - state.managers.group.items.length) {
|
|
189
190
|
this.clear();
|
|
190
191
|
} else {
|
|
191
|
-
this.
|
|
192
|
+
this.set(keys.filter(key => !(key instanceof GroupComponent)) as Key[]);
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
|
|
@@ -203,7 +204,7 @@ export class SelectionManager {
|
|
|
203
204
|
for (let index = 0; index < length; index += 1) {
|
|
204
205
|
const {key, removed} = items[index];
|
|
205
206
|
|
|
206
|
-
const row = this.managers.row.get(key);
|
|
207
|
+
const row = this.state.managers.row.get(key);
|
|
207
208
|
|
|
208
209
|
if (row == null || row.element == null) {
|
|
209
210
|
continue;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {sort, type ArrayKeySorter} from '@oscarpalmer/atoms/array';
|
|
2
2
|
import type {Key, PlainObject} from '@oscarpalmer/atoms/models';
|
|
3
|
+
import {compare} from '@oscarpalmer/atoms/value/compare';
|
|
3
4
|
import {setAttribute, setAttributes} from '@oscarpalmer/toretto/attribute';
|
|
4
|
-
import
|
|
5
|
-
import type {
|
|
5
|
+
import {GroupComponent} from '../components/group.component';
|
|
6
|
+
import type {TabelaSort, TabelaSortDirection, TabelaSortItem} from '../models/sort.model';
|
|
7
|
+
import type {State} from '../models/tabela.model';
|
|
6
8
|
|
|
7
9
|
export class SortManager {
|
|
8
10
|
handlers = Object.freeze({
|
|
@@ -13,11 +15,11 @@ export class SortManager {
|
|
|
13
15
|
set: items => this.set(items),
|
|
14
16
|
} satisfies TabelaSort);
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
items: ArrayKeySorter<PlainObject>[] = [];
|
|
17
19
|
|
|
18
|
-
constructor(
|
|
20
|
+
constructor(public state: State) {}
|
|
19
21
|
|
|
20
|
-
add(field: string, direction?:
|
|
22
|
+
add(field: string, direction?: TabelaSortDirection): void {
|
|
21
23
|
const index = this.items.findIndex(item => item.key === field);
|
|
22
24
|
|
|
23
25
|
if (index > -1) {
|
|
@@ -50,7 +52,8 @@ export class SortManager {
|
|
|
50
52
|
|
|
51
53
|
destroy(): void {
|
|
52
54
|
this.handlers = undefined as never;
|
|
53
|
-
this.items
|
|
55
|
+
this.items = undefined as never;
|
|
56
|
+
this.state = undefined as never;
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
flip(field: string): void {
|
|
@@ -83,7 +86,7 @@ export class SortManager {
|
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
set(items:
|
|
89
|
+
set(items: TabelaSortItem[]): void {
|
|
87
90
|
this.items.splice(
|
|
88
91
|
0,
|
|
89
92
|
this.items.length,
|
|
@@ -94,12 +97,12 @@ export class SortManager {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
sort(): void {
|
|
97
|
-
const {items,
|
|
100
|
+
const {items, state} = this;
|
|
98
101
|
|
|
99
|
-
const {length} = managers.column.items;
|
|
102
|
+
const {length} = state.managers.column.items;
|
|
100
103
|
|
|
101
104
|
for (let index = 0; index < length; index += 1) {
|
|
102
|
-
const column = managers.column.items[index];
|
|
105
|
+
const column = state.managers.column.items[index];
|
|
103
106
|
|
|
104
107
|
const sorterIndex = items.findIndex(item => item.key === column.options.field);
|
|
105
108
|
const sorterItem = items[sorterIndex];
|
|
@@ -117,18 +120,10 @@ export class SortManager {
|
|
|
117
120
|
);
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
managers.data.values.keys.active =
|
|
121
|
-
items.length === 0
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
managers.data.values.keys.active?.map(
|
|
125
|
-
key => managers.data.values.objects.mapped.get(key)!,
|
|
126
|
-
) ??
|
|
127
|
-
managers.data.values.objects.array,
|
|
128
|
-
items,
|
|
129
|
-
).map(row => row[managers.data.field]) as Key[]);
|
|
130
|
-
|
|
131
|
-
managers.render.update(true, true);
|
|
123
|
+
state.managers.data.values.keys.active =
|
|
124
|
+
items.length === 0 ? undefined : getSortedKeys(state, items);
|
|
125
|
+
|
|
126
|
+
state.managers.render.update(true, true);
|
|
132
127
|
}
|
|
133
128
|
|
|
134
129
|
toggle(event: MouseEvent, field: string, direction?: string | null): void {
|
|
@@ -147,3 +142,71 @@ export class SortManager {
|
|
|
147
142
|
}
|
|
148
143
|
}
|
|
149
144
|
}
|
|
145
|
+
|
|
146
|
+
function getSortedKeys(
|
|
147
|
+
state: State,
|
|
148
|
+
sorters: ArrayKeySorter<PlainObject>[],
|
|
149
|
+
): Array<GroupComponent | Key> {
|
|
150
|
+
const data =
|
|
151
|
+
state.managers.data.values.keys.active?.map(key =>
|
|
152
|
+
key instanceof GroupComponent ? key : state.managers.data.values.objects.mapped.get(key)!,
|
|
153
|
+
) ?? state.managers.data.values.objects.array.slice();
|
|
154
|
+
|
|
155
|
+
if (!state.managers.group.enabled) {
|
|
156
|
+
return sort(data as PlainObject[], sorters).map(
|
|
157
|
+
item => (item as PlainObject)[state.key] as Key,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return sortWithGroups(state, data, sorters).map(item =>
|
|
162
|
+
item instanceof GroupComponent ? item : (item[state.key] as Key),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function sortWithGroups(
|
|
167
|
+
state: State,
|
|
168
|
+
data: Array<GroupComponent | PlainObject>,
|
|
169
|
+
sorters: ArrayKeySorter<PlainObject>[],
|
|
170
|
+
): Array<GroupComponent | PlainObject> {
|
|
171
|
+
const {length} = sorters;
|
|
172
|
+
|
|
173
|
+
return data.sort((first, second) => {
|
|
174
|
+
const firstValue =
|
|
175
|
+
first instanceof GroupComponent
|
|
176
|
+
? first.value
|
|
177
|
+
: (first as PlainObject)[state.managers.group.field];
|
|
178
|
+
|
|
179
|
+
const secondValue =
|
|
180
|
+
second instanceof GroupComponent
|
|
181
|
+
? second.value
|
|
182
|
+
: (second as PlainObject)[state.managers.group.field];
|
|
183
|
+
|
|
184
|
+
const firstOrder = state.managers.group.order[firstValue as never];
|
|
185
|
+
const secondOrder = state.managers.group.order[secondValue as never];
|
|
186
|
+
|
|
187
|
+
const groupComparison = compare(firstOrder, secondOrder);
|
|
188
|
+
|
|
189
|
+
if (groupComparison !== 0) {
|
|
190
|
+
return groupComparison;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const firstIsGroup = first instanceof GroupComponent;
|
|
194
|
+
const secondIsGroup = second instanceof GroupComponent;
|
|
195
|
+
|
|
196
|
+
if (firstIsGroup || secondIsGroup) {
|
|
197
|
+
return firstIsGroup && secondIsGroup ? 0 : firstIsGroup ? -1 : 1;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for (let index = 0; index < length; index += 1) {
|
|
201
|
+
const sorter = sorters[index];
|
|
202
|
+
|
|
203
|
+
const comparison = compare(first[sorter.key], second[sorter.key]);
|
|
204
|
+
|
|
205
|
+
if (comparison !== 0) {
|
|
206
|
+
return comparison * (sorter.direction === 'ascending' ? 1 : -1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return 0;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type Column = {
|
|
2
2
|
field: string;
|
|
3
3
|
title: string;
|
|
4
4
|
type: TabelaColumnType;
|
|
5
5
|
width: number;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type TabelaColumn = {
|
|
9
9
|
field: string;
|
|
10
10
|
title: string;
|
|
11
11
|
type: TabelaColumnType;
|
package/src/models/data.model.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {Key, PlainObject} from '@oscarpalmer/atoms/models';
|
|
2
|
+
import type {GroupComponent} from '../components/group.component';
|
|
2
3
|
|
|
3
4
|
export type DataValues = {
|
|
4
5
|
keys: DataValuesKeys;
|
|
@@ -6,11 +7,21 @@ export type DataValues = {
|
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
type DataValuesKeys = {
|
|
9
|
-
active?: Key
|
|
10
|
-
original: Key
|
|
10
|
+
active?: Array<GroupComponent | Key>;
|
|
11
|
+
original: Array<GroupComponent | Key>;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
type DataValuesObjects = {
|
|
14
|
-
array: PlainObject
|
|
15
|
+
array: Array<GroupComponent | PlainObject>;
|
|
15
16
|
mapped: Map<Key, PlainObject>;
|
|
16
17
|
};
|
|
18
|
+
|
|
19
|
+
export type TabelaData = {
|
|
20
|
+
add(data: PlainObject[]): void;
|
|
21
|
+
clear(): void;
|
|
22
|
+
get(active?: boolean): PlainObject[];
|
|
23
|
+
remove(keys: Key[]): void;
|
|
24
|
+
remove(data: PlainObject[]): void;
|
|
25
|
+
synchronize(data: PlainObject[], remove?: boolean): void;
|
|
26
|
+
update(data: PlainObject[]): void;
|
|
27
|
+
};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type TabelaFilter = {
|
|
2
|
+
add(item: TabelaFilterItem): void;
|
|
3
|
+
clear(): void;
|
|
4
|
+
remove(field: string): void;
|
|
5
|
+
remove(item: TabelaFilterItem): void;
|
|
6
|
+
set(items: TabelaFilterItem[]): void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type TabelaFilterComparison =
|
|
2
10
|
| 'contains'
|
|
3
11
|
| 'ends-with'
|
|
4
12
|
| 'equals'
|
|
@@ -10,8 +18,8 @@ export type FilterComparison =
|
|
|
10
18
|
| 'not-equals'
|
|
11
19
|
| 'starts-with';
|
|
12
20
|
|
|
13
|
-
export type
|
|
14
|
-
comparison:
|
|
21
|
+
export type TabelaFilterItem = {
|
|
22
|
+
comparison: TabelaFilterComparison;
|
|
15
23
|
field: string;
|
|
16
24
|
value: unknown;
|
|
17
25
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type {State} from './tabela.model';
|
|
2
|
+
|
|
1
3
|
export type RenderElementPool = {
|
|
2
4
|
cells: Record<string, HTMLDivElement[]>;
|
|
3
5
|
rows: HTMLDivElement[];
|
|
@@ -11,4 +13,4 @@ export type RenderRange = {
|
|
|
11
13
|
export type RenderState = {
|
|
12
14
|
active: boolean;
|
|
13
15
|
top: number;
|
|
14
|
-
};
|
|
16
|
+
} & State;
|
package/src/models/sort.model.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type TabelaSort = {
|
|
2
|
+
add(field: string, direction?: TabelaSortDirection): void;
|
|
3
|
+
clear(): void;
|
|
4
|
+
flip(field: string): void;
|
|
5
|
+
remove(field: string): void;
|
|
6
|
+
set(items: TabelaSortItem[]): void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type TabelaSortDirection = 'ascending' | 'descending';
|
|
2
10
|
|
|
3
|
-
export type
|
|
4
|
-
direction:
|
|
11
|
+
export type TabelaSortItem = {
|
|
12
|
+
direction: TabelaSortDirection;
|
|
5
13
|
field: string;
|
|
6
14
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {Key, PlainObject} from '@oscarpalmer/atoms/models';
|
|
2
1
|
import type {BodyComponent} from '../components/body.component';
|
|
3
2
|
import type {FooterComponent} from '../components/footer.component';
|
|
4
3
|
import type {HeaderComponent} from '../components/header.component';
|
|
@@ -6,59 +5,38 @@ import type {ColumnManager} from '../managers/column.manager';
|
|
|
6
5
|
import type {DataManager} from '../managers/data.manager';
|
|
7
6
|
import type {EventManager} from '../managers/event.manager';
|
|
8
7
|
import type {FilterManager} from '../managers/filter.manager';
|
|
8
|
+
import type { GroupManager } from '../managers/group.manager';
|
|
9
|
+
import type {NavigationManager} from '../managers/navigation.manager';
|
|
9
10
|
import type {RenderManager} from '../managers/render.manager';
|
|
10
11
|
import type {RowManager} from '../managers/row.manager';
|
|
11
12
|
import type {SelectionManager} from '../managers/selection.manager';
|
|
12
13
|
import type {SortManager} from '../managers/sort.manager';
|
|
13
|
-
import type {
|
|
14
|
-
import type {SortDirection, SortItem} from './sort.model';
|
|
14
|
+
import type {TabelaOptions} from './tabela.options';
|
|
15
15
|
|
|
16
|
-
export type
|
|
16
|
+
export type Components = {
|
|
17
17
|
body: BodyComponent;
|
|
18
18
|
footer: FooterComponent;
|
|
19
19
|
header: HeaderComponent;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export type
|
|
23
|
-
add(data: PlainObject[]): void;
|
|
24
|
-
clear(): void;
|
|
25
|
-
get(active?: boolean): PlainObject[];
|
|
26
|
-
remove(keys: Key[]): void;
|
|
27
|
-
remove(data: PlainObject[]): void;
|
|
28
|
-
synchronize(data: PlainObject[], remove?: boolean): void;
|
|
29
|
-
update(data: PlainObject[]): void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type TabelaFilter = {
|
|
33
|
-
add(item: FilterItem): void;
|
|
34
|
-
clear(): void;
|
|
35
|
-
remove(field: string): void;
|
|
36
|
-
remove(item: FilterItem): void;
|
|
37
|
-
set(items: FilterItem[]): void;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type TabelaManagers = {
|
|
22
|
+
export type Managers = {
|
|
41
23
|
column: ColumnManager;
|
|
42
24
|
data: DataManager;
|
|
43
25
|
event: EventManager;
|
|
44
26
|
filter: FilterManager;
|
|
27
|
+
group: GroupManager;
|
|
28
|
+
navigation: NavigationManager;
|
|
45
29
|
row: RowManager;
|
|
46
30
|
selection: SelectionManager;
|
|
47
31
|
sort: SortManager;
|
|
48
32
|
render: RenderManager;
|
|
49
33
|
};
|
|
50
34
|
|
|
51
|
-
export type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export type TabelaSort = {
|
|
59
|
-
add(field: string, direction?: SortDirection): void;
|
|
60
|
-
clear(): void;
|
|
61
|
-
flip(field: string): void;
|
|
62
|
-
remove(field: string): void;
|
|
63
|
-
set(items: SortItem[]): void;
|
|
35
|
+
export type State = {
|
|
36
|
+
readonly components: Components;
|
|
37
|
+
readonly element: HTMLElement;
|
|
38
|
+
readonly id: number;
|
|
39
|
+
readonly key: string;
|
|
40
|
+
readonly managers: Managers;
|
|
41
|
+
readonly options: TabelaOptions;
|
|
64
42
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type {PlainObject} from '@oscarpalmer/atoms/models';
|
|
2
|
-
import type {
|
|
2
|
+
import type {TabelaColumn} from './column.model';
|
|
3
3
|
|
|
4
4
|
export type TabelaOptions = {
|
|
5
|
-
columns:
|
|
5
|
+
columns: TabelaColumn[];
|
|
6
6
|
data: PlainObject[];
|
|
7
|
+
grouping?: string;
|
|
7
8
|
key: string;
|
|
8
9
|
label: string;
|
|
9
10
|
rowHeight: number;
|