@revolist/revogrid 3.2.13 → 3.2.16
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/custom-element/_baseIteratee.js +2070 -0
- package/custom-element/columnService.js +743 -0
- package/custom-element/consts.js +46 -0
- package/custom-element/data.store.js +545 -0
- package/custom-element/debounce.js +217 -0
- package/custom-element/dimension.helpers.js +340 -0
- package/custom-element/each.js +180 -0
- package/custom-element/filter.button.js +36 -0
- package/custom-element/identity.js +26 -0
- package/custom-element/index.d.ts +15 -98
- package/custom-element/index.js +15 -29221
- package/custom-element/isSymbol.js +220 -0
- package/custom-element/keys.js +561 -0
- package/custom-element/localScrollService.js +86 -0
- package/custom-element/revo-grid.d.ts +11 -0
- package/custom-element/revo-grid.js +3662 -0
- package/custom-element/revogr-clipboard.d.ts +11 -0
- package/custom-element/revogr-clipboard.js +72 -0
- package/custom-element/revogr-data.d.ts +11 -0
- package/custom-element/revogr-data.js +9 -0
- package/custom-element/revogr-data2.js +171 -0
- package/custom-element/revogr-edit.d.ts +11 -0
- package/custom-element/revogr-edit.js +9 -0
- package/custom-element/revogr-edit2.js +402 -0
- package/custom-element/revogr-filter-panel.d.ts +11 -0
- package/custom-element/revogr-filter-panel.js +308 -0
- package/custom-element/revogr-focus.d.ts +11 -0
- package/custom-element/revogr-focus.js +9 -0
- package/custom-element/revogr-focus2.js +64 -0
- package/custom-element/revogr-header.d.ts +11 -0
- package/custom-element/revogr-header.js +9 -0
- package/custom-element/revogr-header2.js +591 -0
- package/custom-element/revogr-order-editor.d.ts +11 -0
- package/custom-element/revogr-order-editor.js +9 -0
- package/custom-element/revogr-order-editor2.js +190 -0
- package/custom-element/revogr-overlay-selection.d.ts +11 -0
- package/custom-element/revogr-overlay-selection.js +9 -0
- package/custom-element/revogr-overlay-selection2.js +741 -0
- package/custom-element/revogr-row-headers.d.ts +11 -0
- package/custom-element/revogr-row-headers.js +9 -0
- package/custom-element/revogr-row-headers2.js +403 -0
- package/custom-element/revogr-scroll-virtual.d.ts +11 -0
- package/custom-element/revogr-scroll-virtual.js +9 -0
- package/custom-element/revogr-scroll-virtual2.js +135 -0
- package/custom-element/revogr-temp-range.d.ts +11 -0
- package/custom-element/revogr-temp-range.js +9 -0
- package/custom-element/revogr-temp-range2.js +17275 -0
- package/custom-element/revogr-viewport-scroll.d.ts +11 -0
- package/custom-element/revogr-viewport-scroll.js +9 -0
- package/custom-element/revogr-viewport-scroll2.js +367 -0
- package/custom-element/selection.utils.js +106 -0
- package/custom-element/toInteger.js +107 -0
- package/custom-element/toNumber.js +105 -0
- package/custom-element/utils.js +69 -0
- package/dist/cjs/revo-grid_11.cjs.entry.js +1 -1
- package/dist/collection/plugins/filter/filter.plugin.js +1 -1
- package/dist/collection/utilsExternal/generate-data.js +1 -0
- package/dist/esm/revo-grid_11.entry.js +1 -1
- package/dist/esm-es5/revo-grid_11.entry.js +1 -1
- package/dist/revo-grid/revo-grid_11.entry.js +1 -1
- package/dist/revo-grid/revo-grid_11.system.entry.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Built by Revolist
|
|
3
|
+
*/
|
|
4
|
+
import { h } from '@stencil/core/internal/client';
|
|
5
|
+
import { c as createStore, d as setStore, b as getVisibleSourceItem, g as getSourceItem, s as setSourceByVirtualIndex } from './data.store.js';
|
|
6
|
+
import { G as GRID_INTERNALS, h as CELL_CLASS, i as DISABLED_CLASS } from './consts.js';
|
|
7
|
+
|
|
8
|
+
const GROUP_DEPTH = `${GRID_INTERNALS}-depth`;
|
|
9
|
+
const PSEUDO_GROUP_ITEM = `${GRID_INTERNALS}-name`;
|
|
10
|
+
const PSEUDO_GROUP_ITEM_ID = `${GRID_INTERNALS}-id`;
|
|
11
|
+
const PSEUDO_GROUP_ITEM_VALUE = `${GRID_INTERNALS}-value`;
|
|
12
|
+
const PSEUDO_GROUP_COLUMN = `${GRID_INTERNALS}-column`;
|
|
13
|
+
const GROUP_EXPANDED = `${GRID_INTERNALS}-expanded`;
|
|
14
|
+
const GROUP_EXPAND_BTN = `group-expand`;
|
|
15
|
+
const GROUP_EXPAND_EVENT = `groupExpandClick`;
|
|
16
|
+
const GROUPING_ROW_TYPE = 'rgRow';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Do actual grouping
|
|
20
|
+
* @param array - items to group
|
|
21
|
+
* @param f - function responsible for grouping, returns property to group by
|
|
22
|
+
*/
|
|
23
|
+
function groupBy(array, f) {
|
|
24
|
+
const groupsOrder = [];
|
|
25
|
+
const itemsByGroup = {};
|
|
26
|
+
array.forEach((item, i) => {
|
|
27
|
+
// get grouping values
|
|
28
|
+
const groupKeys = JSON.stringify(f(item));
|
|
29
|
+
// new group identification
|
|
30
|
+
if (!itemsByGroup[groupKeys]) {
|
|
31
|
+
itemsByGroup[groupKeys] = new Map();
|
|
32
|
+
// create group parents
|
|
33
|
+
groupsOrder.push({
|
|
34
|
+
children: itemsByGroup[groupKeys],
|
|
35
|
+
id: groupKeys,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// save to group with previous index
|
|
39
|
+
itemsByGroup[groupKeys].set(i, item);
|
|
40
|
+
});
|
|
41
|
+
return groupsOrder;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gather data for grouping
|
|
45
|
+
* @param array - flat data array
|
|
46
|
+
* @param mapFunc - mapping function for stringify
|
|
47
|
+
* @param expanded - potentially expanded items if present
|
|
48
|
+
*/
|
|
49
|
+
function gatherGrouping(array, mapFunc, { prevExpanded, expandedAll }) {
|
|
50
|
+
// build groups
|
|
51
|
+
const groupsOrder = groupBy(array, mapFunc);
|
|
52
|
+
const itemsMirror = []; // grouped source
|
|
53
|
+
const pseudoGroupTest = {}; // check if group header exists
|
|
54
|
+
// item index in source
|
|
55
|
+
let itemIndex = 0;
|
|
56
|
+
// to save max group depth
|
|
57
|
+
let groupingDepth = 0;
|
|
58
|
+
// collapse all groups in the beginning
|
|
59
|
+
const trimmed = {};
|
|
60
|
+
// index mapping
|
|
61
|
+
const oldNewIndexMap = {};
|
|
62
|
+
// go through groups
|
|
63
|
+
groupsOrder.forEach(group => {
|
|
64
|
+
const parseGroup = getParsedGroup(group.id);
|
|
65
|
+
// extra precaution and type safe guard
|
|
66
|
+
if (!parseGroup) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let depth = 0;
|
|
70
|
+
let skipTrim = !!expandedAll;
|
|
71
|
+
let isExpanded = skipTrim;
|
|
72
|
+
const children = [];
|
|
73
|
+
// add group headers
|
|
74
|
+
parseGroup.reduce((prevVal, groupValue) => {
|
|
75
|
+
prevVal.push(groupValue);
|
|
76
|
+
const newVal = prevVal.join(',');
|
|
77
|
+
// if header not added, add new header
|
|
78
|
+
if (!pseudoGroupTest[newVal]) {
|
|
79
|
+
isExpanded = expandedAll || (prevExpanded && prevExpanded[newVal]);
|
|
80
|
+
itemsMirror.push(getPseudoGroup(groupValue, newVal, depth, group.id, isExpanded));
|
|
81
|
+
// if not first level auto collapse
|
|
82
|
+
if (depth && !isExpanded && !skipTrim) {
|
|
83
|
+
// check if parent expanded, expand this layer too
|
|
84
|
+
const parent = prevVal.slice(0, prevVal.length - 1);
|
|
85
|
+
if (!(prevExpanded && parent.length && prevExpanded[parent.join(',')])) {
|
|
86
|
+
trimmed[itemIndex] = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
itemIndex++;
|
|
90
|
+
pseudoGroupTest[newVal] = children;
|
|
91
|
+
}
|
|
92
|
+
// calculate depth
|
|
93
|
+
depth++;
|
|
94
|
+
groupingDepth = depth;
|
|
95
|
+
return prevVal;
|
|
96
|
+
}, []);
|
|
97
|
+
// add regular items
|
|
98
|
+
group.children.forEach((item, oldIndex) => {
|
|
99
|
+
// hide items if group colapsed
|
|
100
|
+
if (!isExpanded && !skipTrim) {
|
|
101
|
+
// collapse rgRow
|
|
102
|
+
trimmed[itemIndex] = true;
|
|
103
|
+
}
|
|
104
|
+
// add items to new source
|
|
105
|
+
itemsMirror.push(item);
|
|
106
|
+
oldNewIndexMap[oldIndex] = itemIndex;
|
|
107
|
+
children.push(itemIndex);
|
|
108
|
+
itemIndex++;
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
// updates source mirror
|
|
113
|
+
sourceWithGroups: itemsMirror,
|
|
114
|
+
// largest depth for grouping
|
|
115
|
+
depth: groupingDepth,
|
|
116
|
+
// used for expand/collapse grouping values
|
|
117
|
+
trimmed,
|
|
118
|
+
// used for mapping old values to new
|
|
119
|
+
oldNewIndexMap,
|
|
120
|
+
// used to get child items in group
|
|
121
|
+
childrenByGroup: pseudoGroupTest,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function getPseudoGroup(groupValue, value, depth, id, isExpanded = false) {
|
|
125
|
+
return {
|
|
126
|
+
[PSEUDO_GROUP_ITEM]: groupValue,
|
|
127
|
+
[GROUP_DEPTH]: depth,
|
|
128
|
+
[PSEUDO_GROUP_ITEM_ID]: id,
|
|
129
|
+
[PSEUDO_GROUP_ITEM_VALUE]: value,
|
|
130
|
+
[GROUP_EXPANDED]: isExpanded,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function getGroupingName(rgRow) {
|
|
134
|
+
return rgRow && rgRow[PSEUDO_GROUP_ITEM];
|
|
135
|
+
}
|
|
136
|
+
function isGrouping(rgRow) {
|
|
137
|
+
return rgRow && typeof rgRow[PSEUDO_GROUP_ITEM] !== 'undefined';
|
|
138
|
+
}
|
|
139
|
+
function isGroupingColumn(column) {
|
|
140
|
+
return column && typeof column[PSEUDO_GROUP_COLUMN] !== 'undefined';
|
|
141
|
+
}
|
|
142
|
+
function isArray(data) {
|
|
143
|
+
return typeof data.push !== 'undefined';
|
|
144
|
+
}
|
|
145
|
+
function measureEqualDepth(groupA, groupB) {
|
|
146
|
+
const ln = groupA.length;
|
|
147
|
+
let i = 0;
|
|
148
|
+
for (; i < ln; i++) {
|
|
149
|
+
if (groupA[i] !== groupB[i]) {
|
|
150
|
+
return i;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return i;
|
|
154
|
+
}
|
|
155
|
+
function getParsedGroup(id) {
|
|
156
|
+
const parseGroup = JSON.parse(id);
|
|
157
|
+
// extra precaution and type safe guard
|
|
158
|
+
if (!isArray(parseGroup)) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
return parseGroup;
|
|
162
|
+
}
|
|
163
|
+
// check if items is child of current clicked group
|
|
164
|
+
function isSameGroup(currentGroup, currentModel, nextModel) {
|
|
165
|
+
const nextGroup = getParsedGroup(nextModel[PSEUDO_GROUP_ITEM_ID]);
|
|
166
|
+
if (!nextGroup) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
const depth = measureEqualDepth(currentGroup, nextGroup);
|
|
170
|
+
return currentModel[GROUP_DEPTH] < depth;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function isHiddenStore(pos) {
|
|
174
|
+
return pos === EMPTY_INDEX;
|
|
175
|
+
}
|
|
176
|
+
function nextCell(cell, lastCell) {
|
|
177
|
+
const nextItem = {};
|
|
178
|
+
let types = ['x', 'y'];
|
|
179
|
+
// previous item check
|
|
180
|
+
for (let t of types) {
|
|
181
|
+
if (cell[t] < 0) {
|
|
182
|
+
nextItem[t] = cell[t];
|
|
183
|
+
return nextItem;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// next item check
|
|
187
|
+
for (let t of types) {
|
|
188
|
+
if (cell[t] >= lastCell[t]) {
|
|
189
|
+
nextItem[t] = cell[t] - lastCell[t];
|
|
190
|
+
return nextItem;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
function cropCellToMax(cell, lastCell) {
|
|
196
|
+
const newCell = Object.assign({}, cell);
|
|
197
|
+
let types = ['x', 'y'];
|
|
198
|
+
// previous item check
|
|
199
|
+
for (let t of types) {
|
|
200
|
+
if (cell[t] < 0) {
|
|
201
|
+
newCell[t] = 0;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// next item check
|
|
205
|
+
for (let t of types) {
|
|
206
|
+
if (cell[t] >= lastCell[t]) {
|
|
207
|
+
newCell[t] = lastCell[t] - 1;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return newCell;
|
|
211
|
+
}
|
|
212
|
+
function getRange(start, end) {
|
|
213
|
+
return start && end
|
|
214
|
+
? {
|
|
215
|
+
x: Math.min(start.x, end.x),
|
|
216
|
+
y: Math.min(start.y, end.y),
|
|
217
|
+
x1: Math.max(start.x, end.x),
|
|
218
|
+
y1: Math.max(start.y, end.y),
|
|
219
|
+
}
|
|
220
|
+
: null;
|
|
221
|
+
}
|
|
222
|
+
function isRangeSingleCell(a) {
|
|
223
|
+
return a.x === a.x1 && a.y === a.y1;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function defaultState() {
|
|
227
|
+
return {
|
|
228
|
+
range: null,
|
|
229
|
+
tempRange: null,
|
|
230
|
+
tempRangeType: null,
|
|
231
|
+
focus: null,
|
|
232
|
+
edit: null,
|
|
233
|
+
lastCell: null,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
class SelectionStore {
|
|
237
|
+
constructor() {
|
|
238
|
+
this.unsubscribe = [];
|
|
239
|
+
this.store = createStore(defaultState());
|
|
240
|
+
this.store.on('set', (key, newVal) => {
|
|
241
|
+
if (key === 'tempRange' && !newVal) {
|
|
242
|
+
this.store.set('tempRangeType', null);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
onChange(propName, cb) {
|
|
247
|
+
this.unsubscribe.push(this.store.onChange(propName, cb));
|
|
248
|
+
}
|
|
249
|
+
clearFocus() {
|
|
250
|
+
setStore(this.store, { focus: null, range: null, edit: null, tempRange: null });
|
|
251
|
+
}
|
|
252
|
+
setFocus(focus, end) {
|
|
253
|
+
setStore(this.store, {
|
|
254
|
+
focus,
|
|
255
|
+
range: getRange(focus, end),
|
|
256
|
+
edit: null,
|
|
257
|
+
tempRange: null,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
setTempArea(range) {
|
|
261
|
+
setStore(this.store, { tempRange: range === null || range === void 0 ? void 0 : range.area, tempRangeType: range === null || range === void 0 ? void 0 : range.type, edit: null });
|
|
262
|
+
}
|
|
263
|
+
clearTemp() {
|
|
264
|
+
setStore(this.store, { tempRange: null });
|
|
265
|
+
}
|
|
266
|
+
/** Can be applied from selection change or from simple keyboard change clicks */
|
|
267
|
+
setRangeArea(range) {
|
|
268
|
+
setStore(this.store, { range, edit: null, tempRange: null });
|
|
269
|
+
}
|
|
270
|
+
setRange(start, end) {
|
|
271
|
+
this.setRangeArea(getRange(start, end));
|
|
272
|
+
}
|
|
273
|
+
setLastCell(lastCell) {
|
|
274
|
+
setStore(this.store, { lastCell });
|
|
275
|
+
}
|
|
276
|
+
setEdit(val) {
|
|
277
|
+
const focus = this.store.get('focus');
|
|
278
|
+
if (focus && typeof val === 'string') {
|
|
279
|
+
setStore(this.store, {
|
|
280
|
+
edit: { x: focus.x, y: focus.y, val },
|
|
281
|
+
});
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
setStore(this.store, { edit: null });
|
|
285
|
+
}
|
|
286
|
+
dispose() {
|
|
287
|
+
this.unsubscribe.forEach(f => f());
|
|
288
|
+
this.store.dispose();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const EMPTY_INDEX = -1;
|
|
293
|
+
class SelectionStoreConnector {
|
|
294
|
+
constructor() {
|
|
295
|
+
// dirty flag required to cleanup whole store in case visibility of panels changed
|
|
296
|
+
this.dirty = false;
|
|
297
|
+
this.stores = {};
|
|
298
|
+
this.columnStores = {};
|
|
299
|
+
this.rowStores = {};
|
|
300
|
+
this.sections = [];
|
|
301
|
+
}
|
|
302
|
+
get focusedStore() {
|
|
303
|
+
var _a;
|
|
304
|
+
for (let y in this.stores) {
|
|
305
|
+
for (let x in this.stores[y]) {
|
|
306
|
+
const focused = (_a = this.stores[y][x]) === null || _a === void 0 ? void 0 : _a.store.get('focus');
|
|
307
|
+
if (focused) {
|
|
308
|
+
return {
|
|
309
|
+
entity: this.stores[y][x],
|
|
310
|
+
cell: focused,
|
|
311
|
+
position: {
|
|
312
|
+
x: parseInt(x, 10),
|
|
313
|
+
y: parseInt(y, 10)
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
get edit() {
|
|
322
|
+
var _a;
|
|
323
|
+
return (_a = this.focusedStore) === null || _a === void 0 ? void 0 : _a.entity.store.get('edit');
|
|
324
|
+
}
|
|
325
|
+
get focused() {
|
|
326
|
+
var _a;
|
|
327
|
+
return (_a = this.focusedStore) === null || _a === void 0 ? void 0 : _a.entity.store.get('focus');
|
|
328
|
+
}
|
|
329
|
+
get selectedRange() {
|
|
330
|
+
var _a;
|
|
331
|
+
return (_a = this.focusedStore) === null || _a === void 0 ? void 0 : _a.entity.store.get('range');
|
|
332
|
+
}
|
|
333
|
+
registerSection(e) {
|
|
334
|
+
if (!e) {
|
|
335
|
+
this.sections.length = 0;
|
|
336
|
+
// some elements removed, rebuild stores
|
|
337
|
+
this.dirty = true;
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (this.sections.indexOf(e) === -1) {
|
|
341
|
+
this.sections.push(e);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// check if require to cleanup all stores
|
|
345
|
+
beforeUpdate() {
|
|
346
|
+
if (this.dirty) {
|
|
347
|
+
for (let y in this.stores) {
|
|
348
|
+
for (let x in this.stores[y]) {
|
|
349
|
+
this.stores[y][x].dispose();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
this.dirty = false;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
registerColumn(x) {
|
|
356
|
+
// if hidden just create store
|
|
357
|
+
if (isHiddenStore(x)) {
|
|
358
|
+
return new SelectionStore();
|
|
359
|
+
}
|
|
360
|
+
if (this.columnStores[x]) {
|
|
361
|
+
return this.columnStores[x];
|
|
362
|
+
}
|
|
363
|
+
this.columnStores[x] = new SelectionStore();
|
|
364
|
+
return this.columnStores[x];
|
|
365
|
+
}
|
|
366
|
+
registerRow(y) {
|
|
367
|
+
// if hidden just create store
|
|
368
|
+
if (isHiddenStore(y)) {
|
|
369
|
+
return new SelectionStore();
|
|
370
|
+
}
|
|
371
|
+
if (this.rowStores[y]) {
|
|
372
|
+
return this.rowStores[y];
|
|
373
|
+
}
|
|
374
|
+
this.rowStores[y] = new SelectionStore();
|
|
375
|
+
return this.rowStores[y];
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Cross store proxy, based on multiple dimensions
|
|
379
|
+
*/
|
|
380
|
+
register({ x, y }) {
|
|
381
|
+
var _a, _b;
|
|
382
|
+
// if hidden just create store
|
|
383
|
+
if (isHiddenStore(x) || isHiddenStore(y)) {
|
|
384
|
+
return new SelectionStore();
|
|
385
|
+
}
|
|
386
|
+
if (!this.stores[y]) {
|
|
387
|
+
this.stores[y] = {};
|
|
388
|
+
}
|
|
389
|
+
if (this.stores[y][x]) {
|
|
390
|
+
// Store already registered. Do not register twice
|
|
391
|
+
return this.stores[y][x];
|
|
392
|
+
}
|
|
393
|
+
this.stores[y][x] = new SelectionStore();
|
|
394
|
+
// proxy update
|
|
395
|
+
(_a = this.stores[y][x]) === null || _a === void 0 ? void 0 : _a.onChange('range', c => {
|
|
396
|
+
this.columnStores[x].setRangeArea(c);
|
|
397
|
+
this.rowStores[y].setRangeArea(c);
|
|
398
|
+
});
|
|
399
|
+
// clean up on remove
|
|
400
|
+
(_b = this.stores[y][x]) === null || _b === void 0 ? void 0 : _b.store.on('dispose', () => {
|
|
401
|
+
var _a, _b;
|
|
402
|
+
(_a = this.columnStores[x]) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
403
|
+
(_b = this.rowStores[y]) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
404
|
+
delete this.rowStores[y];
|
|
405
|
+
delete this.columnStores[x];
|
|
406
|
+
if (this.stores[y]) {
|
|
407
|
+
delete this.stores[y][x];
|
|
408
|
+
}
|
|
409
|
+
// clear empty rows
|
|
410
|
+
if (!Object.keys(this.stores[y] || {}).length) {
|
|
411
|
+
delete this.stores[y];
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
return this.stores[y][x];
|
|
415
|
+
}
|
|
416
|
+
setEditByCell({ x, y }, editCell) {
|
|
417
|
+
const store = this.stores[y][x];
|
|
418
|
+
this.focus(store, { focus: editCell, end: editCell });
|
|
419
|
+
this.setEdit('');
|
|
420
|
+
}
|
|
421
|
+
focus(store, { focus, end }) {
|
|
422
|
+
let currentStorePointer;
|
|
423
|
+
// clear all stores focus leave only active one
|
|
424
|
+
for (let y in this.stores) {
|
|
425
|
+
for (let x in this.stores[y]) {
|
|
426
|
+
const s = this.stores[y][x];
|
|
427
|
+
// clear other stores, only one area can be selected
|
|
428
|
+
if (s !== store) {
|
|
429
|
+
s.clearFocus();
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
currentStorePointer = { x: parseInt(x, 10), y: parseInt(y, 10) };
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (!currentStorePointer) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
// check is focus in next store
|
|
440
|
+
const lastCell = store.store.get('lastCell');
|
|
441
|
+
// item in new store
|
|
442
|
+
const nextItem = nextCell(focus, lastCell);
|
|
443
|
+
let nextStore;
|
|
444
|
+
if (nextItem) {
|
|
445
|
+
for (let i in nextItem) {
|
|
446
|
+
let type = i;
|
|
447
|
+
let stores;
|
|
448
|
+
switch (type) {
|
|
449
|
+
case 'x':
|
|
450
|
+
stores = this.getXStores(currentStorePointer.y);
|
|
451
|
+
break;
|
|
452
|
+
case 'y':
|
|
453
|
+
stores = this.getYStores(currentStorePointer.x);
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
if (nextItem[type] >= 0) {
|
|
457
|
+
nextStore = stores[++currentStorePointer[type]];
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
nextStore = stores[--currentStorePointer[type]];
|
|
461
|
+
const nextLastCell = nextStore === null || nextStore === void 0 ? void 0 : nextStore.store.get('lastCell');
|
|
462
|
+
if (nextLastCell) {
|
|
463
|
+
nextItem[type] = nextLastCell[type] + nextItem[type];
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
// if next store present - update
|
|
469
|
+
if (nextStore) {
|
|
470
|
+
let item = Object.assign(Object.assign({}, focus), nextItem);
|
|
471
|
+
this.focus(nextStore, { focus: item, end: item });
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
focus = cropCellToMax(focus, lastCell);
|
|
475
|
+
end = cropCellToMax(focus, lastCell);
|
|
476
|
+
store.setFocus(focus, end);
|
|
477
|
+
}
|
|
478
|
+
clearAll() {
|
|
479
|
+
var _a;
|
|
480
|
+
for (let y in this.stores) {
|
|
481
|
+
for (let x in this.stores[y]) {
|
|
482
|
+
(_a = this.stores[y][x]) === null || _a === void 0 ? void 0 : _a.clearFocus();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
setEdit(val) {
|
|
487
|
+
if (!this.focusedStore) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
this.focusedStore.entity.setEdit(val);
|
|
491
|
+
}
|
|
492
|
+
getXStores(y) {
|
|
493
|
+
return this.stores[y];
|
|
494
|
+
}
|
|
495
|
+
getYStores(x) {
|
|
496
|
+
const stores = {};
|
|
497
|
+
for (let i in this.stores) {
|
|
498
|
+
stores[i] = this.stores[i][x];
|
|
499
|
+
}
|
|
500
|
+
return stores;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
class ColumnService {
|
|
505
|
+
constructor(dataStore, source) {
|
|
506
|
+
this.dataStore = dataStore;
|
|
507
|
+
this.source = source;
|
|
508
|
+
this.unsubscribe = [];
|
|
509
|
+
this.hasGrouping = false;
|
|
510
|
+
this.unsubscribe.push(source.onChange('source', s => this.checkGrouping(s)));
|
|
511
|
+
this.checkGrouping(source.get('source'));
|
|
512
|
+
}
|
|
513
|
+
get columns() {
|
|
514
|
+
return getVisibleSourceItem(this.source);
|
|
515
|
+
}
|
|
516
|
+
checkGrouping(cols) {
|
|
517
|
+
for (let rgCol of cols) {
|
|
518
|
+
if (isGroupingColumn(rgCol)) {
|
|
519
|
+
this.hasGrouping = true;
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
this.hasGrouping = false;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
isReadOnly(r, c) {
|
|
526
|
+
var _a;
|
|
527
|
+
const readOnly = (_a = this.columns[c]) === null || _a === void 0 ? void 0 : _a.readonly;
|
|
528
|
+
if (typeof readOnly === 'function') {
|
|
529
|
+
const data = this.rowDataModel(r, c);
|
|
530
|
+
return readOnly(data);
|
|
531
|
+
}
|
|
532
|
+
return readOnly;
|
|
533
|
+
}
|
|
534
|
+
static doMerge(existing, extra) {
|
|
535
|
+
let props = Object.assign(Object.assign({}, extra), existing);
|
|
536
|
+
// extend existing props
|
|
537
|
+
if (extra.class) {
|
|
538
|
+
if (typeof extra.class === 'object' && typeof props.class === 'object') {
|
|
539
|
+
props.class = Object.assign(Object.assign({}, extra.class), props.class);
|
|
540
|
+
}
|
|
541
|
+
else if (typeof extra.class === 'string' && typeof props.class === 'object') {
|
|
542
|
+
props.class[extra.class] = true;
|
|
543
|
+
}
|
|
544
|
+
else if (typeof props.class === 'string') {
|
|
545
|
+
props.class += ' ' + extra.class;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (extra.style) {
|
|
549
|
+
props.style = Object.assign(Object.assign({}, extra.style), props.style);
|
|
550
|
+
}
|
|
551
|
+
return props;
|
|
552
|
+
}
|
|
553
|
+
mergeProperties(r, c, defaultProps) {
|
|
554
|
+
var _a;
|
|
555
|
+
const cellClass = {
|
|
556
|
+
[CELL_CLASS]: true,
|
|
557
|
+
[DISABLED_CLASS]: this.isReadOnly(r, c),
|
|
558
|
+
};
|
|
559
|
+
let props = Object.assign(Object.assign({}, defaultProps), { class: cellClass });
|
|
560
|
+
const extraPropsFunc = (_a = this.columns[c]) === null || _a === void 0 ? void 0 : _a.cellProperties;
|
|
561
|
+
if (extraPropsFunc) {
|
|
562
|
+
const data = this.rowDataModel(r, c);
|
|
563
|
+
const extra = extraPropsFunc(data);
|
|
564
|
+
if (!extra) {
|
|
565
|
+
return props;
|
|
566
|
+
}
|
|
567
|
+
return ColumnService.doMerge(props, extra);
|
|
568
|
+
}
|
|
569
|
+
return props;
|
|
570
|
+
}
|
|
571
|
+
customRenderer(_r, c, model) {
|
|
572
|
+
var _a;
|
|
573
|
+
const tpl = (_a = this.columns[c]) === null || _a === void 0 ? void 0 : _a.cellTemplate;
|
|
574
|
+
if (tpl) {
|
|
575
|
+
return tpl(h, model);
|
|
576
|
+
}
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
getRowClass(r, prop) {
|
|
580
|
+
const model = getSourceItem(this.dataStore, r) || {};
|
|
581
|
+
return model[prop] || '';
|
|
582
|
+
}
|
|
583
|
+
getCellData(r, c) {
|
|
584
|
+
const data = this.rowDataModel(r, c);
|
|
585
|
+
return ColumnService.getData(data.model[data.prop]);
|
|
586
|
+
}
|
|
587
|
+
getSaveData(rowIndex, c, val) {
|
|
588
|
+
if (typeof val === 'undefined') {
|
|
589
|
+
val = this.getCellData(rowIndex, c);
|
|
590
|
+
}
|
|
591
|
+
const data = this.rowDataModel(rowIndex, c);
|
|
592
|
+
return {
|
|
593
|
+
prop: data.prop,
|
|
594
|
+
rowIndex,
|
|
595
|
+
val,
|
|
596
|
+
model: data.model,
|
|
597
|
+
type: this.dataStore.get('type'),
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
getCellEditor(_r, c, editors) {
|
|
601
|
+
var _a;
|
|
602
|
+
const editor = (_a = this.columns[c]) === null || _a === void 0 ? void 0 : _a.editor;
|
|
603
|
+
if (!editor) {
|
|
604
|
+
return undefined;
|
|
605
|
+
}
|
|
606
|
+
// reference
|
|
607
|
+
if (typeof editor === 'string') {
|
|
608
|
+
return editors[editor];
|
|
609
|
+
}
|
|
610
|
+
return editor;
|
|
611
|
+
}
|
|
612
|
+
rowDataModel(rowIndex, c) {
|
|
613
|
+
const column = this.columns[c];
|
|
614
|
+
const prop = column === null || column === void 0 ? void 0 : column.prop;
|
|
615
|
+
const model = getSourceItem(this.dataStore, rowIndex) || {};
|
|
616
|
+
return {
|
|
617
|
+
prop,
|
|
618
|
+
model,
|
|
619
|
+
data: this.dataStore.get('source'),
|
|
620
|
+
column,
|
|
621
|
+
rowIndex,
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
getRangeData(d) {
|
|
625
|
+
const changed = {};
|
|
626
|
+
// get original length sizes
|
|
627
|
+
const copyColLength = d.oldProps.length;
|
|
628
|
+
const copyFrom = this.copyRangeArray(d.oldRange, d.oldProps, this.dataStore);
|
|
629
|
+
const copyRowLength = copyFrom.length;
|
|
630
|
+
// rows
|
|
631
|
+
for (let rowIndex = d.newRange.y, i = 0; rowIndex < d.newRange.y1 + 1; rowIndex++, i++) {
|
|
632
|
+
// copy original data link
|
|
633
|
+
const copyRow = copyFrom[i % copyRowLength];
|
|
634
|
+
// columns
|
|
635
|
+
for (let colIndex = d.newRange.x, j = 0; colIndex < d.newRange.x1 + 1; colIndex++, j++) {
|
|
636
|
+
// check if old range area
|
|
637
|
+
if (rowIndex >= d.oldRange.y && rowIndex <= d.oldRange.y1 && colIndex >= d.oldRange.x && colIndex <= d.oldRange.x1) {
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
const p = this.columns[colIndex].prop;
|
|
641
|
+
const currentCol = j % copyColLength;
|
|
642
|
+
/** if can write */
|
|
643
|
+
if (!this.isReadOnly(rowIndex, colIndex)) {
|
|
644
|
+
/** to show before save */
|
|
645
|
+
if (!changed[rowIndex]) {
|
|
646
|
+
changed[rowIndex] = {};
|
|
647
|
+
}
|
|
648
|
+
changed[rowIndex][p] = copyRow[currentCol];
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return changed;
|
|
653
|
+
}
|
|
654
|
+
getTransformedDataToApply(start, data) {
|
|
655
|
+
const changed = {};
|
|
656
|
+
const copyRowLength = data.length;
|
|
657
|
+
const colLength = this.columns.length;
|
|
658
|
+
const rowLength = this.dataStore.get('items').length;
|
|
659
|
+
// rows
|
|
660
|
+
let rowIndex = start.y;
|
|
661
|
+
let maxCol = 0;
|
|
662
|
+
for (let i = 0; rowIndex < rowLength && i < copyRowLength; rowIndex++, i++) {
|
|
663
|
+
// copy original data link
|
|
664
|
+
const copyRow = data[i % copyRowLength];
|
|
665
|
+
const copyColLength = (copyRow === null || copyRow === void 0 ? void 0 : copyRow.length) || 0;
|
|
666
|
+
// columns
|
|
667
|
+
let colIndex = start.x;
|
|
668
|
+
for (let j = 0; colIndex < colLength && j < copyColLength; colIndex++, j++) {
|
|
669
|
+
const p = this.columns[colIndex].prop;
|
|
670
|
+
const currentCol = j % colLength;
|
|
671
|
+
/** if can write */
|
|
672
|
+
if (!this.isReadOnly(rowIndex, colIndex)) {
|
|
673
|
+
/** to show before save */
|
|
674
|
+
if (!changed[rowIndex]) {
|
|
675
|
+
changed[rowIndex] = {};
|
|
676
|
+
}
|
|
677
|
+
changed[rowIndex][p] = copyRow[currentCol];
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
maxCol = Math.max(maxCol, colIndex - 1);
|
|
681
|
+
}
|
|
682
|
+
const range = getRange(start, {
|
|
683
|
+
y: rowIndex - 1,
|
|
684
|
+
x: maxCol,
|
|
685
|
+
});
|
|
686
|
+
return {
|
|
687
|
+
changed,
|
|
688
|
+
range,
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
applyRangeData(data) {
|
|
692
|
+
const items = {};
|
|
693
|
+
for (let rowIndex in data) {
|
|
694
|
+
const oldModel = (items[rowIndex] = getSourceItem(this.dataStore, parseInt(rowIndex, 10)));
|
|
695
|
+
for (let prop in data[rowIndex]) {
|
|
696
|
+
oldModel[prop] = data[rowIndex][prop];
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
setSourceByVirtualIndex(this.dataStore, items);
|
|
700
|
+
}
|
|
701
|
+
getRangeStaticData(d, value) {
|
|
702
|
+
const changed = {};
|
|
703
|
+
// rows
|
|
704
|
+
for (let rowIndex = d.y, i = 0; rowIndex < d.y1 + 1; rowIndex++, i++) {
|
|
705
|
+
// columns
|
|
706
|
+
for (let colIndex = d.x, j = 0; colIndex < d.x1 + 1; colIndex++, j++) {
|
|
707
|
+
const p = this.columns[colIndex].prop;
|
|
708
|
+
/** if can write */
|
|
709
|
+
if (!this.isReadOnly(rowIndex, colIndex)) {
|
|
710
|
+
/** to show before save */
|
|
711
|
+
if (!changed[rowIndex]) {
|
|
712
|
+
changed[rowIndex] = {};
|
|
713
|
+
}
|
|
714
|
+
changed[rowIndex][p] = value;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return changed;
|
|
719
|
+
}
|
|
720
|
+
copyRangeArray(range, rangeProps, store) {
|
|
721
|
+
const toCopy = [];
|
|
722
|
+
for (let i = range.y; i < range.y1 + 1; i++) {
|
|
723
|
+
const rgRow = [];
|
|
724
|
+
for (let prop of rangeProps) {
|
|
725
|
+
const item = getSourceItem(store, i);
|
|
726
|
+
rgRow.push(item[prop]);
|
|
727
|
+
}
|
|
728
|
+
toCopy.push(rgRow);
|
|
729
|
+
}
|
|
730
|
+
return toCopy;
|
|
731
|
+
}
|
|
732
|
+
static getData(val) {
|
|
733
|
+
if (typeof val === 'undefined' || val === null) {
|
|
734
|
+
return '';
|
|
735
|
+
}
|
|
736
|
+
return val.toString();
|
|
737
|
+
}
|
|
738
|
+
destroy() {
|
|
739
|
+
this.unsubscribe.forEach(f => f());
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
export { ColumnService as C, EMPTY_INDEX as E, GROUP_EXPANDED as G, PSEUDO_GROUP_ITEM_ID as P, SelectionStoreConnector as S, getParsedGroup as a, isSameGroup as b, GROUP_DEPTH as c, GROUPING_ROW_TYPE as d, PSEUDO_GROUP_ITEM_VALUE as e, PSEUDO_GROUP_COLUMN as f, getGroupingName as g, GROUP_EXPAND_EVENT as h, isGrouping as i, gatherGrouping as j, isGroupingColumn as k, GROUP_EXPAND_BTN as l, PSEUDO_GROUP_ITEM as m, getRange as n, isRangeSingleCell as o };
|