@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.
Files changed (62) hide show
  1. package/custom-element/_baseIteratee.js +2070 -0
  2. package/custom-element/columnService.js +743 -0
  3. package/custom-element/consts.js +46 -0
  4. package/custom-element/data.store.js +545 -0
  5. package/custom-element/debounce.js +217 -0
  6. package/custom-element/dimension.helpers.js +340 -0
  7. package/custom-element/each.js +180 -0
  8. package/custom-element/filter.button.js +36 -0
  9. package/custom-element/identity.js +26 -0
  10. package/custom-element/index.d.ts +15 -98
  11. package/custom-element/index.js +15 -29221
  12. package/custom-element/isSymbol.js +220 -0
  13. package/custom-element/keys.js +561 -0
  14. package/custom-element/localScrollService.js +86 -0
  15. package/custom-element/revo-grid.d.ts +11 -0
  16. package/custom-element/revo-grid.js +3662 -0
  17. package/custom-element/revogr-clipboard.d.ts +11 -0
  18. package/custom-element/revogr-clipboard.js +72 -0
  19. package/custom-element/revogr-data.d.ts +11 -0
  20. package/custom-element/revogr-data.js +9 -0
  21. package/custom-element/revogr-data2.js +171 -0
  22. package/custom-element/revogr-edit.d.ts +11 -0
  23. package/custom-element/revogr-edit.js +9 -0
  24. package/custom-element/revogr-edit2.js +402 -0
  25. package/custom-element/revogr-filter-panel.d.ts +11 -0
  26. package/custom-element/revogr-filter-panel.js +308 -0
  27. package/custom-element/revogr-focus.d.ts +11 -0
  28. package/custom-element/revogr-focus.js +9 -0
  29. package/custom-element/revogr-focus2.js +64 -0
  30. package/custom-element/revogr-header.d.ts +11 -0
  31. package/custom-element/revogr-header.js +9 -0
  32. package/custom-element/revogr-header2.js +591 -0
  33. package/custom-element/revogr-order-editor.d.ts +11 -0
  34. package/custom-element/revogr-order-editor.js +9 -0
  35. package/custom-element/revogr-order-editor2.js +190 -0
  36. package/custom-element/revogr-overlay-selection.d.ts +11 -0
  37. package/custom-element/revogr-overlay-selection.js +9 -0
  38. package/custom-element/revogr-overlay-selection2.js +741 -0
  39. package/custom-element/revogr-row-headers.d.ts +11 -0
  40. package/custom-element/revogr-row-headers.js +9 -0
  41. package/custom-element/revogr-row-headers2.js +403 -0
  42. package/custom-element/revogr-scroll-virtual.d.ts +11 -0
  43. package/custom-element/revogr-scroll-virtual.js +9 -0
  44. package/custom-element/revogr-scroll-virtual2.js +135 -0
  45. package/custom-element/revogr-temp-range.d.ts +11 -0
  46. package/custom-element/revogr-temp-range.js +9 -0
  47. package/custom-element/revogr-temp-range2.js +17275 -0
  48. package/custom-element/revogr-viewport-scroll.d.ts +11 -0
  49. package/custom-element/revogr-viewport-scroll.js +9 -0
  50. package/custom-element/revogr-viewport-scroll2.js +367 -0
  51. package/custom-element/selection.utils.js +106 -0
  52. package/custom-element/toInteger.js +107 -0
  53. package/custom-element/toNumber.js +105 -0
  54. package/custom-element/utils.js +69 -0
  55. package/dist/cjs/revo-grid_11.cjs.entry.js +1 -1
  56. package/dist/collection/plugins/filter/filter.plugin.js +1 -1
  57. package/dist/collection/utilsExternal/generate-data.js +1 -0
  58. package/dist/esm/revo-grid_11.entry.js +1 -1
  59. package/dist/esm-es5/revo-grid_11.entry.js +1 -1
  60. package/dist/revo-grid/revo-grid_11.entry.js +1 -1
  61. package/dist/revo-grid/revo-grid_11.system.entry.js +1 -1
  62. package/package.json +2 -2
@@ -0,0 +1,3662 @@
1
+ /*!
2
+ * Built by Revolist
3
+ */
4
+ import { h, proxyCustomElement, HTMLElement, createEvent, Host } from '@stencil/core/internal/client';
5
+ import { r as reduce_1, c as calculateDimensionData, g as getItemByIndex, a as getItemByPosition } from './dimension.helpers.js';
6
+ import { _ as _baseEach, e as each } from './each.js';
7
+ import { _ as _baseIteratee, a as _baseProperty, b as _getTag } from './_baseIteratee.js';
8
+ import { i as isArrayLike_1, k as keys_1, a as isArray_1, _ as _baseKeys } from './keys.js';
9
+ import { f as findIndex_1, g as getSourceItem, a as getSourceItemVirtualIndexByProp, s as setSourceByVirtualIndex, D as DataStore, b as getVisibleSourceItem, c as createStore, d as setStore, _ as _isIterateeCall, e as getPhysical, h as setItems } from './data.store.js';
10
+ import { _ as _arrayMap, U as UUID } from './consts.js';
11
+ import { V as ViewportStore, d as defineCustomElement$5 } from './revogr-row-headers2.js';
12
+ import { t as timeout, g as getScrollbarWidth } from './utils.js';
13
+ import { i as isFilterBtn, F as FILTER_PROP } from './filter.button.js';
14
+ import { i as isString_1, d as defineCustomElement$a } from './revogr-edit2.js';
15
+ import { t as toInteger_1 } from './toInteger.js';
16
+ import { i as isGrouping, g as getGroupingName, P as PSEUDO_GROUP_ITEM_ID, G as GROUP_EXPANDED, a as getParsedGroup, b as isSameGroup, c as GROUP_DEPTH, d as GROUPING_ROW_TYPE, e as PSEUDO_GROUP_ITEM_VALUE, f as PSEUDO_GROUP_COLUMN, h as GROUP_EXPAND_EVENT, j as gatherGrouping, k as isGroupingColumn, E as EMPTY_INDEX, S as SelectionStoreConnector } from './columnService.js';
17
+ import { g as getLastCell, H as HEADER_SLOT, C as CONTENT_SLOT, F as FOOTER_SLOT, D as DATA_SLOT, d as defineCustomElement$2 } from './revogr-viewport-scroll2.js';
18
+ import { l as lodash, d as defineCustomElement$3 } from './revogr-temp-range2.js';
19
+ import { d as debounce_1 } from './debounce.js';
20
+ import { d as dispatch, a as defineCustomElement$8 } from './revogr-header2.js';
21
+ import { d as defineCustomElement$b } from './revogr-data2.js';
22
+ import { d as defineCustomElement$9 } from './revogr-focus2.js';
23
+ import { d as defineCustomElement$7 } from './revogr-order-editor2.js';
24
+ import { d as defineCustomElement$6 } from './revogr-overlay-selection2.js';
25
+ import { d as defineCustomElement$4 } from './revogr-scroll-virtual2.js';
26
+
27
+ class ThemeCompact {
28
+ constructor() {
29
+ this.defaultRowSize = 32;
30
+ }
31
+ }
32
+
33
+ class ThemeDefault {
34
+ constructor() {
35
+ this.defaultRowSize = 27;
36
+ }
37
+ }
38
+
39
+ class ThemeMaterial {
40
+ constructor() {
41
+ this.defaultRowSize = 42;
42
+ }
43
+ }
44
+
45
+ const DEFAULT_THEME = 'default';
46
+ const allowedThemes = [DEFAULT_THEME, 'material', 'compact', 'darkMaterial', 'darkCompact'];
47
+ class ThemeService {
48
+ constructor(cfg) {
49
+ this.customRowSize = 0;
50
+ this.customRowSize = cfg.rowSize;
51
+ this.register('default');
52
+ }
53
+ get theme() {
54
+ return this.currentTheme;
55
+ }
56
+ get rowSize() {
57
+ return this.customRowSize || this.currentTheme.defaultRowSize;
58
+ }
59
+ set rowSize(size) {
60
+ this.customRowSize = size;
61
+ }
62
+ register(theme) {
63
+ const parsedTheme = ThemeService.getTheme(theme);
64
+ switch (parsedTheme) {
65
+ case 'material':
66
+ case 'darkMaterial':
67
+ this.currentTheme = new ThemeMaterial();
68
+ break;
69
+ case 'compact':
70
+ case 'darkCompact':
71
+ this.currentTheme = new ThemeCompact();
72
+ break;
73
+ default:
74
+ this.currentTheme = new ThemeDefault();
75
+ break;
76
+ }
77
+ }
78
+ static getTheme(theme) {
79
+ if (allowedThemes.indexOf(theme) > -1) {
80
+ return theme;
81
+ }
82
+ return DEFAULT_THEME;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Creates a `_.find` or `_.findLast` function.
88
+ *
89
+ * @private
90
+ * @param {Function} findIndexFunc The function to find the collection index.
91
+ * @returns {Function} Returns the new find function.
92
+ */
93
+ function createFind(findIndexFunc) {
94
+ return function(collection, predicate, fromIndex) {
95
+ var iterable = Object(collection);
96
+ if (!isArrayLike_1(collection)) {
97
+ var iteratee = _baseIteratee(predicate);
98
+ collection = keys_1(collection);
99
+ predicate = function(key) { return iteratee(iterable[key], key, iterable); };
100
+ }
101
+ var index = findIndexFunc(collection, predicate, fromIndex);
102
+ return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
103
+ };
104
+ }
105
+
106
+ var _createFind = createFind;
107
+
108
+ /**
109
+ * Iterates over elements of `collection`, returning the first element
110
+ * `predicate` returns truthy for. The predicate is invoked with three
111
+ * arguments: (value, index|key, collection).
112
+ *
113
+ * @static
114
+ * @memberOf _
115
+ * @since 0.1.0
116
+ * @category Collection
117
+ * @param {Array|Object} collection The collection to inspect.
118
+ * @param {Function} [predicate=_.identity] The function invoked per iteration.
119
+ * @param {number} [fromIndex=0] The index to search from.
120
+ * @returns {*} Returns the matched element, else `undefined`.
121
+ * @example
122
+ *
123
+ * var users = [
124
+ * { 'user': 'barney', 'age': 36, 'active': true },
125
+ * { 'user': 'fred', 'age': 40, 'active': false },
126
+ * { 'user': 'pebbles', 'age': 1, 'active': true }
127
+ * ];
128
+ *
129
+ * _.find(users, function(o) { return o.age < 40; });
130
+ * // => object for 'barney'
131
+ *
132
+ * // The `_.matches` iteratee shorthand.
133
+ * _.find(users, { 'age': 1, 'active': true });
134
+ * // => object for 'pebbles'
135
+ *
136
+ * // The `_.matchesProperty` iteratee shorthand.
137
+ * _.find(users, ['active', false]);
138
+ * // => object for 'fred'
139
+ *
140
+ * // The `_.property` iteratee shorthand.
141
+ * _.find(users, 'active');
142
+ * // => object for 'barney'
143
+ */
144
+ var find = _createFind(findIndex_1);
145
+
146
+ var find_1 = find;
147
+
148
+ const rowTypes = ['rowPinStart', 'rgRow', 'rowPinEnd'];
149
+ const columnTypes = ['colPinStart', 'rgCol', 'colPinEnd'];
150
+ function isRowType(type) {
151
+ return rowTypes.indexOf(type) > -1;
152
+ }
153
+
154
+ /**
155
+ * The base implementation of `_.map` without support for iteratee shorthands.
156
+ *
157
+ * @private
158
+ * @param {Array|Object} collection The collection to iterate over.
159
+ * @param {Function} iteratee The function invoked per iteration.
160
+ * @returns {Array} Returns the new mapped array.
161
+ */
162
+ function baseMap(collection, iteratee) {
163
+ var index = -1,
164
+ result = isArrayLike_1(collection) ? Array(collection.length) : [];
165
+
166
+ _baseEach(collection, function(value, key, collection) {
167
+ result[++index] = iteratee(value, key, collection);
168
+ });
169
+ return result;
170
+ }
171
+
172
+ var _baseMap = baseMap;
173
+
174
+ /**
175
+ * Creates an array of values by running each element in `collection` thru
176
+ * `iteratee`. The iteratee is invoked with three arguments:
177
+ * (value, index|key, collection).
178
+ *
179
+ * Many lodash methods are guarded to work as iteratees for methods like
180
+ * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
181
+ *
182
+ * The guarded methods are:
183
+ * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
184
+ * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
185
+ * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
186
+ * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
187
+ *
188
+ * @static
189
+ * @memberOf _
190
+ * @since 0.1.0
191
+ * @category Collection
192
+ * @param {Array|Object} collection The collection to iterate over.
193
+ * @param {Function} [iteratee=_.identity] The function invoked per iteration.
194
+ * @returns {Array} Returns the new mapped array.
195
+ * @example
196
+ *
197
+ * function square(n) {
198
+ * return n * n;
199
+ * }
200
+ *
201
+ * _.map([4, 8], square);
202
+ * // => [16, 64]
203
+ *
204
+ * _.map({ 'a': 4, 'b': 8 }, square);
205
+ * // => [16, 64] (iteration order is not guaranteed)
206
+ *
207
+ * var users = [
208
+ * { 'user': 'barney' },
209
+ * { 'user': 'fred' }
210
+ * ];
211
+ *
212
+ * // The `_.property` iteratee shorthand.
213
+ * _.map(users, 'user');
214
+ * // => ['barney', 'fred']
215
+ */
216
+ function map(collection, iteratee) {
217
+ var func = isArray_1(collection) ? _arrayMap : _baseMap;
218
+ return func(collection, _baseIteratee(iteratee));
219
+ }
220
+
221
+ var map_1 = map;
222
+
223
+ class BasePlugin {
224
+ constructor(revogrid) {
225
+ this.revogrid = revogrid;
226
+ this.subscriptions = {};
227
+ }
228
+ addEventListener(name, func) {
229
+ this.revogrid.addEventListener(name, func);
230
+ this.subscriptions[name] = func;
231
+ }
232
+ removeEventListener(type) {
233
+ this.revogrid.removeEventListener(type, this.subscriptions[type]);
234
+ delete this.subscriptions[type];
235
+ }
236
+ emit(eventName, detail) {
237
+ const event = new CustomEvent(eventName, { detail: detail, cancelable: true });
238
+ this.revogrid.dispatchEvent(event);
239
+ return event;
240
+ }
241
+ clearSubscriptions() {
242
+ for (let type in this.subscriptions) {
243
+ this.removeEventListener(type);
244
+ }
245
+ }
246
+ destroy() {
247
+ this.clearSubscriptions();
248
+ }
249
+ }
250
+
251
+ class GroupingColumnPlugin extends BasePlugin {
252
+ static gatherGroup(res, colData, collection, level = 0) {
253
+ // group template
254
+ const group = Object.assign(Object.assign({}, colData), { level, ids: [] });
255
+ // check columns for update
256
+ for (let k in collection.columns) {
257
+ const key = k;
258
+ const resultItem = res.columns[key];
259
+ const collectionItem = collection.columns[key];
260
+ // if column data
261
+ if (isArray_1(resultItem) && isArray_1(collectionItem)) {
262
+ // fill columns
263
+ resultItem.push(...collectionItem);
264
+ // fill grouping
265
+ if (collectionItem.length) {
266
+ res.columnGrouping[key].push(Object.assign(Object.assign({}, group), { ids: map_1(collectionItem, 'prop') }));
267
+ }
268
+ }
269
+ }
270
+ // merge column groupings
271
+ for (let k in collection.columnGrouping) {
272
+ const key = k;
273
+ const collectionItem = collection.columnGrouping[key];
274
+ res.columnGrouping[key].push(...collectionItem);
275
+ }
276
+ res.maxLevel = Math.max(res.maxLevel, collection.maxLevel);
277
+ res.sort = Object.assign(Object.assign({}, res.sort), collection.sort);
278
+ return res;
279
+ }
280
+ }
281
+ function isColGrouping(colData) {
282
+ return !!colData.children;
283
+ }
284
+
285
+ class ColumnDataProvider {
286
+ constructor() {
287
+ this.sorting = null;
288
+ this.dataSources = reduce_1(columnTypes, (sources, k) => {
289
+ sources[k] = new DataStore(k);
290
+ return sources;
291
+ }, {});
292
+ }
293
+ get order() {
294
+ return reduce_1(this.sorting, (r, c, prop) => {
295
+ r[prop] = c.order;
296
+ return r;
297
+ }, {});
298
+ }
299
+ get stores() {
300
+ return this.dataSources;
301
+ }
302
+ column(c, pin) {
303
+ return this.getColumn(c, pin || 'rgCol');
304
+ }
305
+ getColumn(virtualIndex, type) {
306
+ return getSourceItem(this.dataSources[type].store, virtualIndex);
307
+ }
308
+ getRawColumns() {
309
+ return reduce_1(this.dataSources, (result, item, type) => {
310
+ result[type] = item.store.get('source');
311
+ return result;
312
+ }, {
313
+ rgCol: [],
314
+ colPinStart: [],
315
+ colPinEnd: []
316
+ });
317
+ }
318
+ getColumns(type = 'all') {
319
+ if (type !== 'all') {
320
+ return this.dataSources[type].store.get('source');
321
+ }
322
+ return columnTypes.reduce((r, t) => {
323
+ r.push(...this.dataSources[t].store.get('source'));
324
+ return r;
325
+ }, []);
326
+ }
327
+ getColumnIndexByProp(prop, type) {
328
+ return getSourceItemVirtualIndexByProp(this.dataSources[type].store, prop);
329
+ }
330
+ getColumnByProp(prop, type) {
331
+ const items = this.dataSources[type].store.get('source');
332
+ return find_1(items, { prop });
333
+ }
334
+ refreshByType(type) {
335
+ this.dataSources[type].refresh();
336
+ }
337
+ setColumns(data) {
338
+ each(columnTypes, k => {
339
+ // set columns data
340
+ this.dataSources[k].updateData(data.columns[k], {
341
+ // max depth level
342
+ depth: data.maxLevel,
343
+ // groups
344
+ groups: reduce_1(data.columnGrouping[k], (res, g) => {
345
+ if (!res[g.level]) {
346
+ res[g.level] = [];
347
+ }
348
+ res[g.level].push(g);
349
+ return res;
350
+ }, {}),
351
+ });
352
+ });
353
+ this.sorting = data.sort;
354
+ return data;
355
+ }
356
+ updateColumns(cols) {
357
+ // collect column by type and propert
358
+ const columnByKey = cols.reduce((res, c) => {
359
+ const type = ColumnDataProvider.getColumnType(c);
360
+ if (!res[type]) {
361
+ res[type] = {};
362
+ }
363
+ res[type][c.prop] = c;
364
+ return res;
365
+ }, {});
366
+ // find indexes in source
367
+ const colByIndex = {};
368
+ each(columnByKey, (colsToUpdate, type) => {
369
+ const items = this.dataSources[type].store.get('source');
370
+ colByIndex[type] = items.reduce((result, rgCol, index) => {
371
+ const colToUpdateIfExists = colsToUpdate[rgCol.prop];
372
+ if (colToUpdateIfExists) {
373
+ result[index] = colToUpdateIfExists;
374
+ }
375
+ return result;
376
+ }, {});
377
+ });
378
+ each(colByIndex, (colsToUpdate, type) => setSourceByVirtualIndex(this.dataSources[type].store, colsToUpdate));
379
+ }
380
+ updateColumn(column, index) {
381
+ const type = ColumnDataProvider.getColumnType(column);
382
+ setSourceByVirtualIndex(this.dataSources[type].store, { [index]: column });
383
+ }
384
+ updateColumnSorting(column, index, sorting, additive) {
385
+ if (!additive) {
386
+ this.clearSorting();
387
+ }
388
+ column.order = sorting;
389
+ this.sorting[column.prop] = column;
390
+ this.updateColumn(column, index);
391
+ return column;
392
+ }
393
+ clearSorting() {
394
+ const types = reduce_1(this.sorting, (r, c) => {
395
+ const k = ColumnDataProvider.getColumnType(c);
396
+ r[k] = true;
397
+ return r;
398
+ }, {});
399
+ each(types, (_, type) => {
400
+ const cols = this.dataSources[type].store.get('source');
401
+ each(cols, (c) => (c.order = undefined));
402
+ this.dataSources[type].setData({ source: [...cols] });
403
+ });
404
+ this.sorting = {};
405
+ }
406
+ static getSizes(cols) {
407
+ return reduce_1(cols, (res, c, i) => {
408
+ if (c.size) {
409
+ res[i] = c.size;
410
+ }
411
+ return res;
412
+ }, {});
413
+ }
414
+ static getColumnByProp(columns, prop) {
415
+ return find_1(columns, c => {
416
+ if (isColGrouping(c)) {
417
+ return ColumnDataProvider.getColumnByProp(c.children, prop);
418
+ }
419
+ return c.prop === prop;
420
+ });
421
+ }
422
+ // columns processing
423
+ static getColumns(columns, level = 0, types) {
424
+ return reduce_1(columns, (res, colData) => {
425
+ /** Grouped column */
426
+ if (isColGrouping(colData)) {
427
+ return GroupingColumnPlugin.gatherGroup(res, colData, ColumnDataProvider.getColumns(colData.children, level + 1, types), level);
428
+ }
429
+ /** Regular column */
430
+ const regularColumn = Object.assign(Object.assign({}, (colData.columnType && types && types[colData.columnType])), colData);
431
+ // not pin
432
+ if (!regularColumn.pin) {
433
+ res.columns.rgCol.push(regularColumn);
434
+ // pin
435
+ }
436
+ else {
437
+ res.columns[regularColumn.pin].push(regularColumn);
438
+ }
439
+ if (regularColumn.order) {
440
+ res.sort[regularColumn.prop] = regularColumn;
441
+ }
442
+ // trigger setup hook if present
443
+ regularColumn.beforeSetup && regularColumn.beforeSetup(regularColumn);
444
+ return res;
445
+ }, {
446
+ columns: {
447
+ rgCol: [],
448
+ colPinStart: [],
449
+ colPinEnd: [],
450
+ },
451
+ columnGrouping: {
452
+ rgCol: [],
453
+ colPinStart: [],
454
+ colPinEnd: [],
455
+ },
456
+ maxLevel: level,
457
+ sort: {},
458
+ });
459
+ }
460
+ static getColumnType(rgCol) {
461
+ if (rgCol.pin) {
462
+ return rgCol.pin;
463
+ }
464
+ return 'rgCol';
465
+ }
466
+ }
467
+
468
+ class DataProvider {
469
+ constructor(dimensionProvider) {
470
+ this.dimensionProvider = dimensionProvider;
471
+ this.stores = reduce_1(rowTypes, (sources, k) => {
472
+ sources[k] = new DataStore(k);
473
+ return sources;
474
+ }, {});
475
+ }
476
+ setData(data, type = 'rgRow', grouping, silent = false) {
477
+ // set rgRow data
478
+ this.stores[type].updateData([...data], grouping, silent);
479
+ this.dimensionProvider.setData(data, type, type !== 'rgRow');
480
+ return data;
481
+ }
482
+ getModel(virtualIndex, type = 'rgRow') {
483
+ const store = this.stores[type].store;
484
+ return getSourceItem(store, virtualIndex);
485
+ }
486
+ setCellData({ type, rowIndex, prop, val }) {
487
+ const model = this.getModel(rowIndex, type);
488
+ model[prop] = val;
489
+ setSourceByVirtualIndex(this.stores[type].store, { [rowIndex]: model });
490
+ }
491
+ refresh(type = 'all') {
492
+ if (isRowType(type)) {
493
+ this.refreshItems(type);
494
+ }
495
+ rowTypes.forEach((t) => this.refreshItems(t));
496
+ }
497
+ refreshItems(type = 'rgRow') {
498
+ const items = this.stores[type].store.get('items');
499
+ this.stores[type].setData({ items: [...items] });
500
+ }
501
+ setGrouping({ depth }, type = 'rgRow') {
502
+ this.stores[type].setData({ groupingDepth: depth });
503
+ }
504
+ setTrimmed(trimmed, type = 'rgRow') {
505
+ const store = this.stores[type];
506
+ store.addTrimmed(trimmed);
507
+ if (type === 'rgRow') {
508
+ this.dimensionProvider.setData(getVisibleSourceItem(store.store), type);
509
+ }
510
+ }
511
+ }
512
+
513
+ /**
514
+ * Storing pre-calculated
515
+ * Dimension information and sizes
516
+ */
517
+ function initialBase() {
518
+ return {
519
+ indexes: [],
520
+ // item index to size
521
+ sizes: {},
522
+ // order in indexes[] to coordinate
523
+ positionIndexToItem: {},
524
+ // initial element to coordinate ^
525
+ indexToItem: {},
526
+ positionIndexes: []
527
+ };
528
+ }
529
+ function initialState() {
530
+ return Object.assign(Object.assign({}, initialBase()), {
531
+ // size which all items can take
532
+ realSize: 0,
533
+ // initial item size if it wasn't changed
534
+ originItemSize: 0, frameOffset: 0 });
535
+ }
536
+ class DimensionStore {
537
+ constructor() {
538
+ this.store = createStore(initialState());
539
+ }
540
+ getCurrentState() {
541
+ const state = initialState();
542
+ const keys = Object.keys(state);
543
+ return reduce_1(keys, (r, k) => {
544
+ const data = this.store.get(k);
545
+ r[k] = data;
546
+ return r;
547
+ }, state);
548
+ }
549
+ setRealSize(count) {
550
+ let realSize = 0;
551
+ for (let i = 0; i < count; i++) {
552
+ realSize += this.store.get('sizes')[i] || this.store.get('originItemSize');
553
+ }
554
+ setStore(this.store, { realSize });
555
+ }
556
+ setStore(data) {
557
+ setStore(this.store, data);
558
+ }
559
+ drop() {
560
+ setStore(this.store, initialBase());
561
+ }
562
+ setDimensionSize(sizes) {
563
+ const dimensionData = calculateDimensionData(this.getCurrentState(), sizes);
564
+ setStore(this.store, dimensionData);
565
+ return dimensionData;
566
+ }
567
+ }
568
+
569
+ class DimensionProvider {
570
+ constructor(viewports) {
571
+ this.viewports = viewports;
572
+ this.stores = reduce_1([...rowTypes, ...columnTypes], (sources, k) => {
573
+ sources[k] = new DimensionStore();
574
+ return sources;
575
+ }, {});
576
+ }
577
+ setDimensionSize(dimensionType, sizes) {
578
+ this.stores[dimensionType].setDimensionSize(sizes);
579
+ this.viewports.stores[dimensionType].setViewPortDimension(sizes);
580
+ }
581
+ setRealSize(realCount, type) {
582
+ this.viewports.stores[type].setViewport({ realCount });
583
+ this.stores[type].setRealSize(realCount);
584
+ }
585
+ /**
586
+ * Sets dimension data and view port coordinate
587
+ * @param items - data/column items
588
+ * @param type - dimension type
589
+ */
590
+ setData(items, type, noVirtual = false) {
591
+ this.setRealSize(items.length, type);
592
+ if (noVirtual) {
593
+ this.setNoVirtual(type);
594
+ }
595
+ this.setViewPortCoordinate({
596
+ coordinate: this.viewports.stores[type].store.get('lastCoordinate'),
597
+ type,
598
+ });
599
+ }
600
+ setNoVirtual(type) {
601
+ const dimension = this.stores[type].getCurrentState();
602
+ this.viewports.stores[type].setViewport({ virtualSize: dimension.realSize });
603
+ }
604
+ drop() {
605
+ for (let type of columnTypes) {
606
+ this.stores[type].drop();
607
+ }
608
+ }
609
+ setColumns(type, sizes, noVirtual = false) {
610
+ this.stores[type].setDimensionSize(sizes);
611
+ if (noVirtual) {
612
+ this.setNoVirtual(type);
613
+ }
614
+ this.setViewPortCoordinate({
615
+ coordinate: this.viewports.stores[type].store.get('lastCoordinate'),
616
+ type,
617
+ });
618
+ }
619
+ setViewPortCoordinate({ coordinate, type }) {
620
+ const dimension = this.stores[type].getCurrentState();
621
+ this.viewports.stores[type].setViewPortCoordinate(coordinate, dimension);
622
+ }
623
+ getViewPortPos(e) {
624
+ const dimension = this.stores[e.dimension].getCurrentState();
625
+ const item = getItemByIndex(dimension, e.coordinate);
626
+ return item.start;
627
+ }
628
+ setSettings(data, dimensionType) {
629
+ let stores = [];
630
+ switch (dimensionType) {
631
+ case 'rgCol':
632
+ stores = columnTypes;
633
+ break;
634
+ case 'rgRow':
635
+ stores = rowTypes;
636
+ break;
637
+ }
638
+ for (let s of stores) {
639
+ this.stores[s].setStore(data);
640
+ }
641
+ }
642
+ }
643
+
644
+ class ViewportProvider {
645
+ constructor() {
646
+ this.stores = reduce_1([...rowTypes, ...columnTypes], (sources, k) => {
647
+ sources[k] = new ViewportStore();
648
+ return sources;
649
+ }, {});
650
+ }
651
+ setViewport(dimensionType, data) {
652
+ this.stores[dimensionType].setViewport(data);
653
+ }
654
+ }
655
+
656
+ /**
657
+ * Plugin module for revo-grid grid system
658
+ * Add support for automatic column resize
659
+ */
660
+ const LETTER_BLOCK_SIZE = 7;
661
+ var ColumnAutoSizeMode;
662
+ (function (ColumnAutoSizeMode) {
663
+ // increases column width on header click according the largest text value
664
+ ColumnAutoSizeMode["headerClickAutosize"] = "headerClickAutoSize";
665
+ // increases column width on data set and text edit, decreases performance
666
+ ColumnAutoSizeMode["autoSizeOnTextOverlap"] = "autoSizeOnTextOverlap";
667
+ // increases and decreases column width based on all items sizes, worst for performance
668
+ ColumnAutoSizeMode["autoSizeAll"] = "autoSizeAll";
669
+ })(ColumnAutoSizeMode || (ColumnAutoSizeMode = {}));
670
+ class AutoSizeColumn extends BasePlugin {
671
+ constructor(revogrid, providers, config) {
672
+ super(revogrid);
673
+ this.providers = providers;
674
+ this.config = config;
675
+ this.autoSizeColumns = null;
676
+ /** for edge case when no columns defined before data */
677
+ this.dataResolve = null;
678
+ this.dataReject = null;
679
+ this.letterBlockSize = (config === null || config === void 0 ? void 0 : config.letterBlockSize) || LETTER_BLOCK_SIZE;
680
+ // create test container to check text width
681
+ if (config === null || config === void 0 ? void 0 : config.preciseSize) {
682
+ this.precsizeCalculationArea = this.initiatePresizeElement();
683
+ revogrid.appendChild(this.precsizeCalculationArea);
684
+ }
685
+ const aftersourceset = ({ detail: { source } }) => {
686
+ this.setSource(source);
687
+ };
688
+ const afteredit = ({ detail }) => {
689
+ this.afteredit(detail);
690
+ };
691
+ const afterEditAll = ({ detail }) => {
692
+ this.afterEditAll(detail);
693
+ };
694
+ const beforecolumnsset = ({ detail: { columns } }) => {
695
+ this.columnSet(columns);
696
+ };
697
+ const headerDblClick = ({ detail }) => {
698
+ const type = ColumnDataProvider.getColumnType(detail);
699
+ const size = this.getColumnSize(detail.index, type);
700
+ if (size) {
701
+ this.providers.dimensionProvider.setDimensionSize(type, {
702
+ [detail.index]: size,
703
+ });
704
+ }
705
+ };
706
+ this.addEventListener('beforecolumnsset', beforecolumnsset);
707
+ switch (config === null || config === void 0 ? void 0 : config.mode) {
708
+ case ColumnAutoSizeMode.autoSizeOnTextOverlap:
709
+ this.addEventListener('aftersourceset', aftersourceset);
710
+ this.addEventListener('afteredit', afteredit);
711
+ break;
712
+ case ColumnAutoSizeMode.autoSizeAll:
713
+ this.addEventListener('aftersourceset', aftersourceset);
714
+ this.addEventListener('afteredit', afterEditAll);
715
+ break;
716
+ default:
717
+ this.addEventListener('headerdblClick', headerDblClick);
718
+ break;
719
+ }
720
+ }
721
+ async setSource(source) {
722
+ let autoSize = this.autoSizeColumns;
723
+ if (this.dataReject) {
724
+ this.dataReject();
725
+ this.clearPromise();
726
+ }
727
+ /** If data set first and no column provided await until get one */
728
+ if (!autoSize) {
729
+ const request = new Promise((resolve, reject) => {
730
+ this.dataResolve = resolve;
731
+ this.dataReject = reject;
732
+ });
733
+ try {
734
+ autoSize = await request;
735
+ }
736
+ catch (e) {
737
+ return;
738
+ }
739
+ }
740
+ // calculate sizes
741
+ each(autoSize, (_v, type) => {
742
+ const sizes = {};
743
+ each(autoSize[type], rgCol => {
744
+ // calculate size
745
+ rgCol.size = sizes[rgCol.index] = source.reduce((prev, rgRow) => Math.max(prev, this.getLength(rgRow[rgCol.prop])), this.getLength(rgCol.name || ''));
746
+ });
747
+ this.providers.dimensionProvider.setDimensionSize(type, sizes);
748
+ });
749
+ }
750
+ getLength(len) {
751
+ var _a;
752
+ const padding = 15;
753
+ if (!len) {
754
+ return 0;
755
+ }
756
+ try {
757
+ const str = len.toString();
758
+ /**if exact calculation required proxy with html element, slow operation */
759
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.preciseSize) {
760
+ this.precsizeCalculationArea.innerText = str;
761
+ return this.precsizeCalculationArea.scrollWidth + padding * 2;
762
+ }
763
+ return str.length * this.letterBlockSize + padding * 2;
764
+ }
765
+ catch (e) {
766
+ return 0;
767
+ }
768
+ }
769
+ afteredit(e) {
770
+ let data;
771
+ if (this.isRangeEdit(e)) {
772
+ data = e.data;
773
+ }
774
+ else {
775
+ data = { 0: { [e.prop]: e.val } };
776
+ }
777
+ each(this.autoSizeColumns, (columns, type) => {
778
+ const sizes = {};
779
+ each(columns, rgCol => {
780
+ // calculate size
781
+ const size = reduce_1(data, (prev, rgRow) => {
782
+ if (typeof rgRow[rgCol.prop] === 'undefined') {
783
+ return prev;
784
+ }
785
+ return Math.max(prev || 0, this.getLength(rgRow[rgCol.prop]));
786
+ }, undefined);
787
+ if (size && rgCol.size < size) {
788
+ rgCol.size = sizes[rgCol.index] = size;
789
+ }
790
+ });
791
+ this.providers.dimensionProvider.setDimensionSize(type, sizes);
792
+ });
793
+ }
794
+ afterEditAll(e) {
795
+ const props = {};
796
+ if (this.isRangeEdit(e)) {
797
+ each(e.data, r => each(r, (_v, p) => (props[p] = true)));
798
+ }
799
+ else {
800
+ props[e.prop] = true;
801
+ }
802
+ each(this.autoSizeColumns, (columns, type) => {
803
+ const sizes = {};
804
+ each(columns, rgCol => {
805
+ if (props[rgCol.prop]) {
806
+ const size = this.getColumnSize(rgCol.index, type);
807
+ if (size) {
808
+ sizes[rgCol.index] = size;
809
+ }
810
+ }
811
+ });
812
+ this.providers.dimensionProvider.setDimensionSize(type, sizes);
813
+ });
814
+ }
815
+ getColumnSize(index, type) {
816
+ const rgCol = this.autoSizeColumns[type][index];
817
+ if (!rgCol) {
818
+ return 0;
819
+ }
820
+ return reduce_1(this.providers.dataProvider.stores, (r, s) => {
821
+ const perStore = reduce_1(s.store.get('items'), (prev, _row, i) => {
822
+ const item = getSourceItem(s.store, i);
823
+ return Math.max(prev || 0, this.getLength(item[rgCol.prop]));
824
+ }, 0);
825
+ return Math.max(r, perStore);
826
+ }, rgCol.size || 0);
827
+ }
828
+ columnSet(columns) {
829
+ var _a;
830
+ for (let t of columnTypes) {
831
+ const type = t;
832
+ const cols = columns[type];
833
+ for (let i in cols) {
834
+ if (cols[i].autoSize || ((_a = this.config) === null || _a === void 0 ? void 0 : _a.allColumns)) {
835
+ if (!this.autoSizeColumns) {
836
+ this.autoSizeColumns = {};
837
+ }
838
+ if (!this.autoSizeColumns[type]) {
839
+ this.autoSizeColumns[type] = {};
840
+ }
841
+ this.autoSizeColumns[type][i] = Object.assign(Object.assign({}, cols[i]), { index: parseInt(i, 10) });
842
+ }
843
+ }
844
+ }
845
+ if (this.dataResolve) {
846
+ this.dataResolve(this.autoSizeColumns);
847
+ this.clearPromise();
848
+ }
849
+ }
850
+ clearPromise() {
851
+ this.dataResolve = null;
852
+ this.dataReject = null;
853
+ }
854
+ isRangeEdit(e) {
855
+ return !!e.data;
856
+ }
857
+ initiatePresizeElement() {
858
+ const styleForFontTest = {
859
+ position: 'absolute',
860
+ fontSize: '14px',
861
+ height: '0',
862
+ width: '0',
863
+ whiteSpace: 'nowrap',
864
+ top: '0',
865
+ overflowX: 'scroll',
866
+ };
867
+ const el = document.createElement('div');
868
+ for (let s in styleForFontTest) {
869
+ el.style[s] = styleForFontTest[s];
870
+ }
871
+ el.classList.add('revo-test-container');
872
+ return el;
873
+ }
874
+ destroy() {
875
+ var _a;
876
+ super.destroy();
877
+ (_a = this.precsizeCalculationArea) === null || _a === void 0 ? void 0 : _a.remove();
878
+ }
879
+ }
880
+
881
+ const eq = (value, extra) => {
882
+ if (typeof value === 'undefined' || (value === null && !extra)) {
883
+ return true;
884
+ }
885
+ if (typeof value !== 'string') {
886
+ value = JSON.stringify(value);
887
+ }
888
+ const filterVal = extra.toString().toLocaleLowerCase();
889
+ if (filterVal.length === 0) {
890
+ return true;
891
+ }
892
+ return value.toLocaleLowerCase() === filterVal;
893
+ };
894
+ const notEq = (value, extra) => !eq(value, extra);
895
+ notEq.extra = 'input';
896
+ eq.extra = 'input';
897
+
898
+ const gtThan = function (value, extra) {
899
+ let conditionValue;
900
+ if (typeof value === 'number') {
901
+ conditionValue = parseFloat(extra === null || extra === void 0 ? void 0 : extra.toString());
902
+ return value > conditionValue;
903
+ }
904
+ return false;
905
+ };
906
+ gtThan.extra = 'input';
907
+
908
+ const gtThanEq = function (value, extra) {
909
+ return eq(value, extra) || gtThan(value, extra);
910
+ };
911
+ gtThanEq.extra = 'input';
912
+
913
+ const lt = function (value, extra) {
914
+ let conditionValue;
915
+ if (typeof value === 'number') {
916
+ conditionValue = parseFloat(extra === null || extra === void 0 ? void 0 : extra.toString());
917
+ return value < conditionValue;
918
+ }
919
+ else {
920
+ return false;
921
+ }
922
+ };
923
+ lt.extra = 'input';
924
+
925
+ const lsEq = function (value, extra) {
926
+ return eq(value, extra) || lt(value, extra);
927
+ };
928
+ lsEq.extra = 'input';
929
+
930
+ const set = (value) => !(value === '' || value === null || value === void 0);
931
+ const notSet = (value) => !set(value);
932
+
933
+ const beginsWith = (value, extra) => {
934
+ if (!value) {
935
+ return false;
936
+ }
937
+ if (!extra) {
938
+ return true;
939
+ }
940
+ if (typeof value !== 'string') {
941
+ value = JSON.stringify(value);
942
+ }
943
+ if (typeof extra !== 'string') {
944
+ extra = JSON.stringify(extra);
945
+ }
946
+ return value.toLocaleLowerCase().indexOf(extra.toLocaleLowerCase()) === 0;
947
+ };
948
+ beginsWith.extra = 'input';
949
+
950
+ const contains = (value, extra) => {
951
+ if (!value) {
952
+ return false;
953
+ }
954
+ if (extra) {
955
+ if (typeof value !== 'string') {
956
+ value = JSON.stringify(value);
957
+ }
958
+ return value.toLocaleLowerCase().indexOf(extra.toString().toLowerCase()) > -1;
959
+ }
960
+ return true;
961
+ };
962
+ const notContains = (value, extra) => {
963
+ return !contains(value, extra);
964
+ };
965
+ notContains.extra = 'input';
966
+ contains.extra = 'input';
967
+
968
+ const filterNames = {
969
+ none: 'None',
970
+ empty: 'Not set',
971
+ notEmpty: 'Set',
972
+ eq: 'Equal',
973
+ notEq: 'Not equal',
974
+ begins: 'Begins with',
975
+ contains: 'Contains',
976
+ notContains: 'Does not contain',
977
+ eqN: '=',
978
+ neqN: '!=',
979
+ gt: '>',
980
+ gte: '>=',
981
+ lt: '<',
982
+ lte: '<=',
983
+ };
984
+ const filterEntities = {
985
+ none: () => true,
986
+ empty: notSet,
987
+ notEmpty: set,
988
+ eq: eq,
989
+ notEq: notEq,
990
+ begins: beginsWith,
991
+ contains: contains,
992
+ notContains: notContains,
993
+ eqN: eq,
994
+ neqN: notEq,
995
+ gt: gtThan,
996
+ gte: gtThanEq,
997
+ lt: lt,
998
+ lte: lsEq,
999
+ };
1000
+ const filterTypes = {
1001
+ string: ['notEmpty', 'empty', 'eq', 'notEq', 'begins', 'contains', 'notContains'],
1002
+ number: ['notEmpty', 'empty', 'eqN', 'neqN', 'gt', 'gte', 'lt', 'lte'],
1003
+ };
1004
+
1005
+ const FILTER_TRIMMED_TYPE = 'filter';
1006
+ class FilterPlugin extends BasePlugin {
1007
+ constructor(revogrid, uiid, config) {
1008
+ var _a;
1009
+ super(revogrid);
1010
+ this.revogrid = revogrid;
1011
+ this.filterCollection = {};
1012
+ this.multiFilterItems = {};
1013
+ this.possibleFilters = Object.assign({}, filterTypes);
1014
+ this.possibleFilterNames = Object.assign({}, filterNames);
1015
+ this.possibleFilterEntities = Object.assign({}, filterEntities);
1016
+ if (config) {
1017
+ this.initConfig(config);
1018
+ }
1019
+ const headerclick = (e) => this.headerclick(e);
1020
+ const aftersourceset = async () => {
1021
+ const filterCollectionProps = Object.keys(this.filterCollection);
1022
+ if (filterCollectionProps.length > 0) {
1023
+ // handle old way of filtering by reworking FilterCollection to new MultiFilterItem
1024
+ filterCollectionProps.forEach((prop, index) => {
1025
+ if (!this.multiFilterItems[prop]) {
1026
+ this.multiFilterItems[prop] = [
1027
+ {
1028
+ id: index,
1029
+ type: this.filterCollection[prop].type,
1030
+ value: this.filterCollection[prop].value,
1031
+ relation: 'and',
1032
+ },
1033
+ ];
1034
+ }
1035
+ });
1036
+ }
1037
+ await this.runFiltering();
1038
+ };
1039
+ this.addEventListener('headerclick', headerclick);
1040
+ this.addEventListener('aftersourceset', aftersourceset);
1041
+ this.revogrid.registerVNode([
1042
+ h("revogr-filter-panel", { uuid: `filter-${uiid}`, filterItems: this.multiFilterItems, filterNames: this.possibleFilterNames, filterEntities: this.possibleFilterEntities, filterCaptions: (_a = config === null || config === void 0 ? void 0 : config.localization) === null || _a === void 0 ? void 0 : _a.captions, onFilterChange: e => this.onFilterChange(e.detail), disableDynamicFiltering: config === null || config === void 0 ? void 0 : config.disableDynamicFiltering, ref: e => (this.pop = e) }),
1043
+ ]);
1044
+ }
1045
+ initConfig(config) {
1046
+ if (config.collection) {
1047
+ this.filterCollection = Object.assign({}, config.collection);
1048
+ }
1049
+ if (config.multiFilterItems) {
1050
+ this.multiFilterItems = Object.assign({}, config.multiFilterItems);
1051
+ }
1052
+ if (config.customFilters) {
1053
+ for (let cType in config.customFilters) {
1054
+ const cFilter = config.customFilters[cType];
1055
+ if (!this.possibleFilters[cFilter.columnFilterType]) {
1056
+ this.possibleFilters[cFilter.columnFilterType] = [];
1057
+ }
1058
+ this.possibleFilters[cFilter.columnFilterType].push(cType);
1059
+ this.possibleFilterEntities[cType] = cFilter.func;
1060
+ this.possibleFilterNames[cType] = cFilter.name;
1061
+ }
1062
+ }
1063
+ /**
1064
+ * which filters has to be included/excluded
1065
+ * convinient way to exclude system filters
1066
+ */
1067
+ if (config.include) {
1068
+ const filters = {};
1069
+ for (let t in this.possibleFilters) {
1070
+ // validate filters, if appropriate function present
1071
+ const newTypes = this.possibleFilters[t].filter(f => config.include.indexOf(f) > -1);
1072
+ if (newTypes.length) {
1073
+ filters[t] = newTypes;
1074
+ }
1075
+ }
1076
+ // if any valid filters provided show them
1077
+ if (Object.keys(filters).length > 0) {
1078
+ this.possibleFilters = filters;
1079
+ }
1080
+ }
1081
+ if (config.localization) {
1082
+ if (config.localization.filterNames) {
1083
+ Object.entries(config.localization.filterNames).forEach(([k, v]) => {
1084
+ if (this.possibleFilterNames[k] != void 0) {
1085
+ this.possibleFilterNames[k] = v;
1086
+ }
1087
+ });
1088
+ }
1089
+ }
1090
+ }
1091
+ async headerclick(e) {
1092
+ var _a;
1093
+ const el = (_a = e.detail.originalEvent) === null || _a === void 0 ? void 0 : _a.target;
1094
+ if (!isFilterBtn(el)) {
1095
+ return;
1096
+ }
1097
+ e.preventDefault();
1098
+ // close if same
1099
+ const changes = await this.pop.getChanges();
1100
+ if (changes && (changes === null || changes === void 0 ? void 0 : changes.prop) === e.detail.prop) {
1101
+ this.pop.show();
1102
+ return;
1103
+ }
1104
+ // filter button clicked, open filter dialog
1105
+ const gridPos = this.revogrid.getBoundingClientRect();
1106
+ const buttonPos = el.getBoundingClientRect();
1107
+ const prop = e.detail.prop;
1108
+ this.pop.filterTypes = this.getColumnFilter(e.detail.filter);
1109
+ this.pop.show(Object.assign(Object.assign({}, this.filterCollection[prop]), { x: buttonPos.x - gridPos.x, y: buttonPos.y - gridPos.y + buttonPos.height, prop }));
1110
+ }
1111
+ getColumnFilter(type) {
1112
+ let filterType = 'string';
1113
+ if (!type) {
1114
+ return { [filterType]: this.possibleFilters[filterType] };
1115
+ }
1116
+ // if custom column filter
1117
+ if (this.isValidType(type)) {
1118
+ filterType = type;
1119
+ // if multiple filters applied
1120
+ }
1121
+ else if (typeof type === 'object' && type.length) {
1122
+ return type.reduce((r, multiType) => {
1123
+ if (this.isValidType(multiType)) {
1124
+ r[multiType] = this.possibleFilters[multiType];
1125
+ }
1126
+ return r;
1127
+ }, {});
1128
+ }
1129
+ return { [filterType]: this.possibleFilters[filterType] };
1130
+ }
1131
+ isValidType(type) {
1132
+ return !!(typeof type === 'string' && this.possibleFilters[type]);
1133
+ }
1134
+ // called on internal component change
1135
+ async onFilterChange(filterItems) {
1136
+ this.multiFilterItems = filterItems;
1137
+ this.runFiltering();
1138
+ }
1139
+ /**
1140
+ * Triggers grid filtering
1141
+ */
1142
+ async doFiltering(collection, items, columns, filterItems) {
1143
+ const columnsToUpdate = [];
1144
+ columns.forEach(rgCol => {
1145
+ const column = Object.assign({}, rgCol);
1146
+ const hasFilter = filterItems[column.prop];
1147
+ if (column[FILTER_PROP] && !hasFilter) {
1148
+ delete column[FILTER_PROP];
1149
+ columnsToUpdate.push(column);
1150
+ }
1151
+ if (!column[FILTER_PROP] && hasFilter) {
1152
+ columnsToUpdate.push(column);
1153
+ column[FILTER_PROP] = true;
1154
+ }
1155
+ });
1156
+ const itemsToFilter = this.getRowFilter(items, filterItems);
1157
+ // check is filter event prevented
1158
+ const { defaultPrevented, detail } = this.emit('beforefiltertrimmed', { collection, itemsToFilter, source: items, filterItems });
1159
+ if (defaultPrevented) {
1160
+ return;
1161
+ }
1162
+ // check is trimmed event prevented
1163
+ const isAddedEvent = await this.revogrid.addTrimmed(detail.itemsToFilter, FILTER_TRIMMED_TYPE);
1164
+ if (isAddedEvent.defaultPrevented) {
1165
+ return;
1166
+ }
1167
+ // applies the hasFilter to the columns to show filter icon
1168
+ await this.revogrid.updateColumns(columnsToUpdate);
1169
+ this.emit('afterFilterApply');
1170
+ }
1171
+ async clearFiltering() {
1172
+ this.multiFilterItems = {};
1173
+ await this.runFiltering();
1174
+ }
1175
+ async runFiltering() {
1176
+ const collection = {};
1177
+ // handle old filterCollection to return the first filter only (if any) from multiFilterItems
1178
+ const filterProps = Object.keys(this.multiFilterItems);
1179
+ for (const prop of filterProps) {
1180
+ // check if we have any filter for a column
1181
+ if (this.multiFilterItems[prop].length > 0) {
1182
+ const firstFilterItem = this.multiFilterItems[prop][0];
1183
+ collection[prop] = {
1184
+ filter: filterEntities[firstFilterItem.type],
1185
+ type: firstFilterItem.type,
1186
+ value: firstFilterItem.value,
1187
+ };
1188
+ }
1189
+ }
1190
+ this.filterCollection = collection;
1191
+ const { source, columns } = await this.getData();
1192
+ const { defaultPrevented, detail } = this.emit('beforefilterapply', { collection: this.filterCollection, source, columns, filterItems: this.multiFilterItems });
1193
+ if (defaultPrevented) {
1194
+ return;
1195
+ }
1196
+ this.doFiltering(detail.collection, detail.source, detail.columns, detail.filterItems);
1197
+ }
1198
+ async getData() {
1199
+ const source = await this.revogrid.getSource();
1200
+ const columns = await this.revogrid.getColumns();
1201
+ return {
1202
+ source,
1203
+ columns,
1204
+ };
1205
+ }
1206
+ getRowFilter(rows, filterItems) {
1207
+ const propKeys = Object.keys(filterItems);
1208
+ const trimmed = {};
1209
+ let propFilterSatisfiedCount = 0;
1210
+ let lastFilterResults = [];
1211
+ // each rows
1212
+ rows.forEach((model, rowIndex) => {
1213
+ // working on all props
1214
+ for (const prop of propKeys) {
1215
+ const propFilters = filterItems[prop];
1216
+ propFilterSatisfiedCount = 0;
1217
+ lastFilterResults = [];
1218
+ // testing each filter for a prop
1219
+ for (const [filterIndex, filterData] of propFilters.entries()) {
1220
+ // the filter LogicFunction based on the type
1221
+ const filter = this.possibleFilterEntities[filterData.type];
1222
+ // THE MAGIC OF FILTERING IS HERE
1223
+ if (filterData.relation === 'or') {
1224
+ lastFilterResults = [];
1225
+ if (filter(model[prop], filterData.value)) {
1226
+ continue;
1227
+ }
1228
+ propFilterSatisfiedCount++;
1229
+ }
1230
+ else {
1231
+ // 'and' relation will need to know the next filter
1232
+ // so we save this current filter to include it in the next filter
1233
+ lastFilterResults.push(!filter(model[prop], filterData.value));
1234
+ // check first if we have a filter on the next index to pair it with this current filter
1235
+ const nextFilterData = propFilters[filterIndex + 1];
1236
+ // stop the sequence if there is no next filter or if the next filter is not an 'and' relation
1237
+ if (!nextFilterData || nextFilterData.relation !== 'and') {
1238
+ // let's just continue since for sure propFilterSatisfiedCount cannot be satisfied
1239
+ if (lastFilterResults.indexOf(true) === -1) {
1240
+ lastFilterResults = [];
1241
+ continue;
1242
+ }
1243
+ // we need to add all of the lastFilterResults since we need to satisfy all
1244
+ propFilterSatisfiedCount += lastFilterResults.length;
1245
+ lastFilterResults = [];
1246
+ }
1247
+ }
1248
+ } // end of propFilters forEach
1249
+ // add to the list of removed/trimmed rows of filter condition is satisfied
1250
+ if (propFilterSatisfiedCount === propFilters.length)
1251
+ trimmed[rowIndex] = true;
1252
+ } // end of for-of propKeys
1253
+ });
1254
+ return trimmed;
1255
+ }
1256
+ }
1257
+
1258
+ /**
1259
+ * Gets the size of an ASCII `string`.
1260
+ *
1261
+ * @private
1262
+ * @param {string} string The string inspect.
1263
+ * @returns {number} Returns the string size.
1264
+ */
1265
+ var asciiSize = _baseProperty('length');
1266
+
1267
+ var _asciiSize = asciiSize;
1268
+
1269
+ /** Used to compose unicode character classes. */
1270
+ var rsAstralRange$1 = '\\ud800-\\udfff',
1271
+ rsComboMarksRange$1 = '\\u0300-\\u036f',
1272
+ reComboHalfMarksRange$1 = '\\ufe20-\\ufe2f',
1273
+ rsComboSymbolsRange$1 = '\\u20d0-\\u20ff',
1274
+ rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1,
1275
+ rsVarRange$1 = '\\ufe0e\\ufe0f';
1276
+
1277
+ /** Used to compose unicode capture groups. */
1278
+ var rsZWJ$1 = '\\u200d';
1279
+
1280
+ /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
1281
+ var reHasUnicode = RegExp('[' + rsZWJ$1 + rsAstralRange$1 + rsComboRange$1 + rsVarRange$1 + ']');
1282
+
1283
+ /**
1284
+ * Checks if `string` contains Unicode symbols.
1285
+ *
1286
+ * @private
1287
+ * @param {string} string The string to inspect.
1288
+ * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1289
+ */
1290
+ function hasUnicode(string) {
1291
+ return reHasUnicode.test(string);
1292
+ }
1293
+
1294
+ var _hasUnicode = hasUnicode;
1295
+
1296
+ /** Used to compose unicode character classes. */
1297
+ var rsAstralRange = '\\ud800-\\udfff',
1298
+ rsComboMarksRange = '\\u0300-\\u036f',
1299
+ reComboHalfMarksRange = '\\ufe20-\\ufe2f',
1300
+ rsComboSymbolsRange = '\\u20d0-\\u20ff',
1301
+ rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
1302
+ rsVarRange = '\\ufe0e\\ufe0f';
1303
+
1304
+ /** Used to compose unicode capture groups. */
1305
+ var rsAstral = '[' + rsAstralRange + ']',
1306
+ rsCombo = '[' + rsComboRange + ']',
1307
+ rsFitz = '\\ud83c[\\udffb-\\udfff]',
1308
+ rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
1309
+ rsNonAstral = '[^' + rsAstralRange + ']',
1310
+ rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
1311
+ rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
1312
+ rsZWJ = '\\u200d';
1313
+
1314
+ /** Used to compose unicode regexes. */
1315
+ var reOptMod = rsModifier + '?',
1316
+ rsOptVar = '[' + rsVarRange + ']?',
1317
+ rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
1318
+ rsSeq = rsOptVar + reOptMod + rsOptJoin,
1319
+ rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
1320
+
1321
+ /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
1322
+ var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
1323
+
1324
+ /**
1325
+ * Gets the size of a Unicode `string`.
1326
+ *
1327
+ * @private
1328
+ * @param {string} string The string inspect.
1329
+ * @returns {number} Returns the string size.
1330
+ */
1331
+ function unicodeSize(string) {
1332
+ var result = reUnicode.lastIndex = 0;
1333
+ while (reUnicode.test(string)) {
1334
+ ++result;
1335
+ }
1336
+ return result;
1337
+ }
1338
+
1339
+ var _unicodeSize = unicodeSize;
1340
+
1341
+ /**
1342
+ * Gets the number of symbols in `string`.
1343
+ *
1344
+ * @private
1345
+ * @param {string} string The string to inspect.
1346
+ * @returns {number} Returns the string size.
1347
+ */
1348
+ function stringSize(string) {
1349
+ return _hasUnicode(string)
1350
+ ? _unicodeSize(string)
1351
+ : _asciiSize(string);
1352
+ }
1353
+
1354
+ var _stringSize = stringSize;
1355
+
1356
+ /** `Object#toString` result references. */
1357
+ var mapTag = '[object Map]',
1358
+ setTag = '[object Set]';
1359
+
1360
+ /**
1361
+ * Gets the size of `collection` by returning its length for array-like
1362
+ * values or the number of own enumerable string keyed properties for objects.
1363
+ *
1364
+ * @static
1365
+ * @memberOf _
1366
+ * @since 0.1.0
1367
+ * @category Collection
1368
+ * @param {Array|Object|string} collection The collection to inspect.
1369
+ * @returns {number} Returns the collection size.
1370
+ * @example
1371
+ *
1372
+ * _.size([1, 2, 3]);
1373
+ * // => 3
1374
+ *
1375
+ * _.size({ 'a': 1, 'b': 2 });
1376
+ * // => 2
1377
+ *
1378
+ * _.size('pebbles');
1379
+ * // => 7
1380
+ */
1381
+ function size(collection) {
1382
+ if (collection == null) {
1383
+ return 0;
1384
+ }
1385
+ if (isArrayLike_1(collection)) {
1386
+ return isString_1(collection) ? _stringSize(collection) : collection.length;
1387
+ }
1388
+ var tag = _getTag(collection);
1389
+ if (tag == mapTag || tag == setTag) {
1390
+ return collection.size;
1391
+ }
1392
+ return _baseKeys(collection).length;
1393
+ }
1394
+
1395
+ var size_1 = size;
1396
+
1397
+ /**
1398
+ * lifecycle
1399
+ * 1) @event beforesorting - sorting just started, nothing happened yet
1400
+ * 2) @metod updateColumnSorting - column sorting icon applied to grid and column get updated, data still untiuched
1401
+ * 3) @event beforesortingapply - before we applied sorting data to data source, you can prevent data apply from here
1402
+ * 4) @event afterSortingApply - sorting applied, just finished event
1403
+ *
1404
+ * If you prevent event it'll not reach farther steps
1405
+ */
1406
+ class SortingPlugin extends BasePlugin {
1407
+ constructor(revogrid) {
1408
+ super(revogrid);
1409
+ this.revogrid = revogrid;
1410
+ this.sorting = null;
1411
+ this.sortingFunc = null;
1412
+ const beforesourceset = ({ detail }) => {
1413
+ if (this.hasSorting) {
1414
+ // is sorting allowed
1415
+ const event = this.emit('beforesourcesortingapply');
1416
+ // sorting prevented
1417
+ if (event.defaultPrevented) {
1418
+ return;
1419
+ }
1420
+ }
1421
+ const data = this.setData(detail.source, detail.type);
1422
+ if (data) {
1423
+ detail.source = data;
1424
+ }
1425
+ };
1426
+ const aftercolumnsset = async ({ detail: { order } }) => {
1427
+ const columns = await this.revogrid.getColumns();
1428
+ const sortingFunc = {};
1429
+ for (let prop in order) {
1430
+ const column = ColumnDataProvider.getColumnByProp(columns, prop);
1431
+ const cmp = (column === null || column === void 0 ? void 0 : column.cellCompare) || this.defaultCellCompare;
1432
+ sortingFunc[prop] = order[prop] == 'desc' ? this.descCellCompare(cmp) : cmp;
1433
+ }
1434
+ this.sort(order, sortingFunc);
1435
+ };
1436
+ const headerclick = async (e) => {
1437
+ var _a, _b;
1438
+ if (e.defaultPrevented) {
1439
+ return;
1440
+ }
1441
+ if (!e.detail.column.sortable) {
1442
+ return;
1443
+ }
1444
+ this.headerclick(e.detail.column, e.detail.index, (_b = (_a = e.detail) === null || _a === void 0 ? void 0 : _a.originalEvent) === null || _b === void 0 ? void 0 : _b.shiftKey);
1445
+ };
1446
+ this.addEventListener('beforesourceset', beforesourceset);
1447
+ this.addEventListener('aftercolumnsset', aftercolumnsset);
1448
+ this.addEventListener('initialHeaderClick', headerclick);
1449
+ }
1450
+ get hasSorting() {
1451
+ return !!this.sorting;
1452
+ }
1453
+ async headerclick(column, index, additive) {
1454
+ let order = this.getNextOrder(column.order);
1455
+ const beforeEvent = this.emit('beforesorting', { column, order, additive });
1456
+ if (beforeEvent.defaultPrevented) {
1457
+ return;
1458
+ }
1459
+ order = beforeEvent.detail.order;
1460
+ const newCol = await this.revogrid.updateColumnSorting(beforeEvent.detail.column, index, order, additive);
1461
+ // apply sort data
1462
+ const beforeApplyEvent = this.emit('beforesortingapply', { column: newCol, order, additive });
1463
+ if (beforeApplyEvent.defaultPrevented) {
1464
+ return;
1465
+ }
1466
+ order = beforeApplyEvent.detail.order;
1467
+ const cellCmp = (column === null || column === void 0 ? void 0 : column.cellCompare) || this.defaultCellCompare;
1468
+ const cmp = order == 'asc' ? cellCmp : order == 'desc' ? this.descCellCompare(cellCmp) : undefined;
1469
+ if (additive && this.sorting) {
1470
+ const sorting = {};
1471
+ const sortingFunc = {};
1472
+ Object.assign(sorting, this.sorting);
1473
+ Object.assign(sortingFunc, this.sortingFunc);
1474
+ if (column.prop in sorting && size_1(sorting) > 1 && order === undefined) {
1475
+ delete sorting[column.prop];
1476
+ delete sortingFunc[column.prop];
1477
+ }
1478
+ else {
1479
+ sorting[column.prop] = order;
1480
+ sortingFunc[column.prop] = cmp;
1481
+ }
1482
+ this.sort(sorting, sortingFunc);
1483
+ }
1484
+ else {
1485
+ this.sort({ [column.prop]: order }, { [column.prop]: cmp });
1486
+ }
1487
+ }
1488
+ setData(data, type) {
1489
+ // sorting available for rgRow type only
1490
+ if (type === 'rgRow' && this.sortingFunc) {
1491
+ return this.sortItems(data, this.sortingFunc);
1492
+ }
1493
+ }
1494
+ /**
1495
+ * Sorting apply, available for rgRow type only
1496
+ * @param sorting - per column sorting
1497
+ * @param data - this.stores['rgRow'].store.get('source')
1498
+ */
1499
+ async sort(sorting, sortingFunc) {
1500
+ if (!size_1(sorting)) {
1501
+ this.sorting = null;
1502
+ this.sortingFunc = null;
1503
+ return;
1504
+ }
1505
+ this.sorting = sorting;
1506
+ this.sortingFunc = sortingFunc;
1507
+ const store = await this.revogrid.getSourceStore();
1508
+ const source = store.get('source');
1509
+ const proxyItems = this.sortIndexByItems([...store.get('proxyItems')], source, this.sortingFunc);
1510
+ setStore(store, {
1511
+ proxyItems,
1512
+ source: [...source],
1513
+ });
1514
+ this.emit('afterSortingApply');
1515
+ }
1516
+ defaultCellCompare(prop, a, b) {
1517
+ var _a, _b;
1518
+ const av = (_a = a[prop]) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase();
1519
+ const bv = (_b = b[prop]) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase();
1520
+ return av == bv ? 0 : av > bv ? 1 : -1;
1521
+ }
1522
+ descCellCompare(cmp) {
1523
+ return (prop, a, b) => { return -1 * cmp(prop, a, b); };
1524
+ }
1525
+ sortIndexByItems(indexes, source, sortingFunc) {
1526
+ // TODO - is there a situation where multiple kvps in the `sorting` object would cause this to break?
1527
+ for (let prop in sortingFunc) {
1528
+ if (typeof sortingFunc[prop] === 'undefined') {
1529
+ // Unsort indexes
1530
+ return [...Array(indexes.length).keys()];
1531
+ }
1532
+ }
1533
+ return indexes.sort((a, b) => {
1534
+ let sorted = 0;
1535
+ for (let prop in sortingFunc) {
1536
+ const cmp = sortingFunc[prop];
1537
+ const itemA = source[a];
1538
+ const itemB = source[b];
1539
+ sorted = cmp(prop, itemA, itemB);
1540
+ if (sorted) {
1541
+ break;
1542
+ }
1543
+ }
1544
+ return sorted;
1545
+ });
1546
+ }
1547
+ sortItems(source, sortingFunc) {
1548
+ return source.sort((a, b) => {
1549
+ let sorted = 0;
1550
+ for (let prop in sortingFunc) {
1551
+ const cmp = sortingFunc[prop];
1552
+ if (!cmp) {
1553
+ continue;
1554
+ }
1555
+ sorted = cmp(prop, a, b);
1556
+ if (sorted) {
1557
+ break;
1558
+ }
1559
+ }
1560
+ return sorted;
1561
+ });
1562
+ }
1563
+ getNextOrder(currentOrder) {
1564
+ switch (currentOrder) {
1565
+ case undefined:
1566
+ return 'asc';
1567
+ case 'asc':
1568
+ return 'desc';
1569
+ case 'desc':
1570
+ return undefined;
1571
+ }
1572
+ }
1573
+ }
1574
+
1575
+ /**
1576
+ * The base implementation of `_.clamp` which doesn't coerce arguments.
1577
+ *
1578
+ * @private
1579
+ * @param {number} number The number to clamp.
1580
+ * @param {number} [lower] The lower bound.
1581
+ * @param {number} upper The upper bound.
1582
+ * @returns {number} Returns the clamped number.
1583
+ */
1584
+ function baseClamp(number, lower, upper) {
1585
+ if (number === number) {
1586
+ if (upper !== undefined) {
1587
+ number = number <= upper ? number : upper;
1588
+ }
1589
+ if (lower !== undefined) {
1590
+ number = number >= lower ? number : lower;
1591
+ }
1592
+ }
1593
+ return number;
1594
+ }
1595
+
1596
+ var _baseClamp = baseClamp;
1597
+
1598
+ /** Used as references for the maximum length and index of an array. */
1599
+ var MAX_ARRAY_LENGTH = 4294967295;
1600
+
1601
+ /**
1602
+ * Converts `value` to an integer suitable for use as the length of an
1603
+ * array-like object.
1604
+ *
1605
+ * **Note:** This method is based on
1606
+ * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
1607
+ *
1608
+ * @static
1609
+ * @memberOf _
1610
+ * @since 4.0.0
1611
+ * @category Lang
1612
+ * @param {*} value The value to convert.
1613
+ * @returns {number} Returns the converted integer.
1614
+ * @example
1615
+ *
1616
+ * _.toLength(3.2);
1617
+ * // => 3
1618
+ *
1619
+ * _.toLength(Number.MIN_VALUE);
1620
+ * // => 0
1621
+ *
1622
+ * _.toLength(Infinity);
1623
+ * // => 4294967295
1624
+ *
1625
+ * _.toLength('3.2');
1626
+ * // => 3
1627
+ */
1628
+ function toLength(value) {
1629
+ return value ? _baseClamp(toInteger_1(value), 0, MAX_ARRAY_LENGTH) : 0;
1630
+ }
1631
+
1632
+ var toLength_1 = toLength;
1633
+
1634
+ /**
1635
+ * The base implementation of `_.fill` without an iteratee call guard.
1636
+ *
1637
+ * @private
1638
+ * @param {Array} array The array to fill.
1639
+ * @param {*} value The value to fill `array` with.
1640
+ * @param {number} [start=0] The start position.
1641
+ * @param {number} [end=array.length] The end position.
1642
+ * @returns {Array} Returns `array`.
1643
+ */
1644
+ function baseFill(array, value, start, end) {
1645
+ var length = array.length;
1646
+
1647
+ start = toInteger_1(start);
1648
+ if (start < 0) {
1649
+ start = -start > length ? 0 : (length + start);
1650
+ }
1651
+ end = (end === undefined || end > length) ? length : toInteger_1(end);
1652
+ if (end < 0) {
1653
+ end += length;
1654
+ }
1655
+ end = start > end ? 0 : toLength_1(end);
1656
+ while (start < end) {
1657
+ array[start++] = value;
1658
+ }
1659
+ return array;
1660
+ }
1661
+
1662
+ var _baseFill = baseFill;
1663
+
1664
+ /**
1665
+ * Fills elements of `array` with `value` from `start` up to, but not
1666
+ * including, `end`.
1667
+ *
1668
+ * **Note:** This method mutates `array`.
1669
+ *
1670
+ * @static
1671
+ * @memberOf _
1672
+ * @since 3.2.0
1673
+ * @category Array
1674
+ * @param {Array} array The array to fill.
1675
+ * @param {*} value The value to fill `array` with.
1676
+ * @param {number} [start=0] The start position.
1677
+ * @param {number} [end=array.length] The end position.
1678
+ * @returns {Array} Returns `array`.
1679
+ * @example
1680
+ *
1681
+ * var array = [1, 2, 3];
1682
+ *
1683
+ * _.fill(array, 'a');
1684
+ * console.log(array);
1685
+ * // => ['a', 'a', 'a']
1686
+ *
1687
+ * _.fill(Array(3), 2);
1688
+ * // => [2, 2, 2]
1689
+ *
1690
+ * _.fill([4, 6, 8, 10], '*', 1, 3);
1691
+ * // => [4, '*', '*', 10]
1692
+ */
1693
+ function fill(array, value, start, end) {
1694
+ var length = array == null ? 0 : array.length;
1695
+ if (!length) {
1696
+ return [];
1697
+ }
1698
+ if (start && typeof start != 'number' && _isIterateeCall(array, value, start)) {
1699
+ start = 0;
1700
+ end = length;
1701
+ }
1702
+ return _baseFill(array, value, start, end);
1703
+ }
1704
+
1705
+ var fill_1 = fill;
1706
+
1707
+ const INITIAL = {
1708
+ mime: 'text/csv',
1709
+ fileKind: 'csv',
1710
+ // BOM signature
1711
+ bom: true,
1712
+ columnDelimiter: ',',
1713
+ rowDelimiter: '\r\n',
1714
+ encoding: '',
1715
+ };
1716
+ // The ASCII character code 13 is called a Carriage Return or CR.
1717
+ const CARRIAGE_RETURN = String.fromCharCode(13);
1718
+ // Chr(13) followed by a Chr(10) that compose a proper CRLF.
1719
+ const LINE_FEED = String.fromCharCode(10);
1720
+ const DOUBLE_QT = String.fromCharCode(34);
1721
+ const NO_BREAK_SPACE = String.fromCharCode(0xfeff);
1722
+ const escapeRegex = new RegExp('"', 'g');
1723
+ class ExportCsv {
1724
+ constructor(options = {}) {
1725
+ this.options = Object.assign(Object.assign({}, INITIAL), options);
1726
+ }
1727
+ doExport({ data, headers, props }) {
1728
+ let result = this.options.bom ? NO_BREAK_SPACE : '';
1729
+ // any header
1730
+ if ((headers === null || headers === void 0 ? void 0 : headers.length) > 0) {
1731
+ headers.forEach(header => {
1732
+ // ignore empty
1733
+ if (!header.length) {
1734
+ return;
1735
+ }
1736
+ result += this.prepareHeader(header, this.options.columnDelimiter);
1737
+ result += this.options.rowDelimiter;
1738
+ });
1739
+ }
1740
+ data.forEach((rgRow, index) => {
1741
+ if (index > 0) {
1742
+ result += this.options.rowDelimiter;
1743
+ }
1744
+ // support grouping
1745
+ if (isGrouping(rgRow)) {
1746
+ result += this.parseCell(getGroupingName(rgRow), this.options.columnDelimiter);
1747
+ return;
1748
+ }
1749
+ result += props.map(p => this.parseCell(rgRow[p], this.options.columnDelimiter)).join(this.options.columnDelimiter);
1750
+ });
1751
+ return result;
1752
+ }
1753
+ prepareHeader(columnHeaders, columnDelimiter) {
1754
+ let result = '';
1755
+ const newColumnHeaders = columnHeaders.map(v => this.parseCell(v, columnDelimiter, true));
1756
+ result += newColumnHeaders.join(columnDelimiter);
1757
+ return result;
1758
+ }
1759
+ parseCell(value, columnDelimiter, force = false) {
1760
+ let escape = value;
1761
+ if (typeof value !== 'string') {
1762
+ escape = JSON.stringify(value);
1763
+ }
1764
+ const toEscape = [CARRIAGE_RETURN, DOUBLE_QT, LINE_FEED, columnDelimiter];
1765
+ if (typeof escape === 'undefined') {
1766
+ return '';
1767
+ }
1768
+ if (escape !== '' && (force || toEscape.some(i => escape.indexOf(i) >= 0))) {
1769
+ return `"${escape.replace(escapeRegex, '""')}"`;
1770
+ }
1771
+ return escape;
1772
+ }
1773
+ }
1774
+
1775
+ var ExportTypes;
1776
+ (function (ExportTypes) {
1777
+ ExportTypes["csv"] = "csv";
1778
+ })(ExportTypes || (ExportTypes = {}));
1779
+ class ExportFilePlugin extends BasePlugin {
1780
+ /** Exports string */
1781
+ async exportString(options = {}, t = ExportTypes.csv) {
1782
+ const data = await this.beforeexport();
1783
+ if (!data) {
1784
+ return null;
1785
+ }
1786
+ return this.formatter(t, options).doExport(data);
1787
+ }
1788
+ /** Exports Blob */
1789
+ async exportBlob(options = {}, t = ExportTypes.csv) {
1790
+ return await this.getBlob(this.formatter(t, options));
1791
+ }
1792
+ /** Export file */
1793
+ async exportFile(options = {}, t = ExportTypes.csv) {
1794
+ const formatter = this.formatter(t, options);
1795
+ const blob = await this.getBlob(formatter);
1796
+ // url
1797
+ const URL = window.URL || window.webkitURL;
1798
+ const a = document.createElement('a');
1799
+ const { filename, fileKind } = formatter.options;
1800
+ const name = `${filename}.${fileKind}`;
1801
+ const url = URL.createObjectURL(blob);
1802
+ a.style.display = 'none';
1803
+ a.setAttribute('href', url);
1804
+ a.setAttribute('download', name);
1805
+ this.revogrid.appendChild(a);
1806
+ a.dispatchEvent(new MouseEvent('click'));
1807
+ this.revogrid.removeChild(a);
1808
+ // delay for revoke, correct for some browsers
1809
+ await timeout(120);
1810
+ URL.revokeObjectURL(url);
1811
+ }
1812
+ /** Blob object */
1813
+ async getBlob(formatter) {
1814
+ const type = `${formatter.options.mime};charset=${formatter.options.encoding}`;
1815
+ if (typeof Blob !== 'undefined') {
1816
+ const data = await this.beforeexport();
1817
+ if (!data) {
1818
+ return null;
1819
+ }
1820
+ return new Blob([formatter.doExport(data)], { type });
1821
+ }
1822
+ return null;
1823
+ }
1824
+ // before event
1825
+ async beforeexport() {
1826
+ let data = await this.getData();
1827
+ const event = this.emit('beforeexport', { data });
1828
+ if (event.defaultPrevented) {
1829
+ return null;
1830
+ }
1831
+ return event.detail.data;
1832
+ }
1833
+ async getData() {
1834
+ const data = await this.getSource();
1835
+ const colSource = [];
1836
+ const colPromises = [];
1837
+ columnTypes.forEach((t, i) => {
1838
+ colPromises.push(this.getColPerSource(t).then(s => (colSource[i] = s)));
1839
+ });
1840
+ await Promise.all(colPromises);
1841
+ const columns = {
1842
+ headers: [],
1843
+ props: [],
1844
+ };
1845
+ for (let source of colSource) {
1846
+ source.headers.forEach((h, i) => {
1847
+ if (!columns.headers[i]) {
1848
+ columns.headers[i] = [];
1849
+ }
1850
+ columns.headers[i].push(...h);
1851
+ });
1852
+ columns.props.push(...source.props);
1853
+ }
1854
+ return Object.assign({ data }, columns);
1855
+ }
1856
+ async getColPerSource(t) {
1857
+ const store = await this.revogrid.getColumnStore(t);
1858
+ const source = store.get('source');
1859
+ const virtualIndexes = store.get('items');
1860
+ const depth = store.get('groupingDepth');
1861
+ const groups = store.get('groups');
1862
+ const colNames = [];
1863
+ const colProps = [];
1864
+ const visibleItems = virtualIndexes.reduce((r, v, virtualIndex) => {
1865
+ const prop = source[v].prop;
1866
+ colNames.push(source[v].name || '');
1867
+ colProps.push(prop);
1868
+ r[prop] = virtualIndex;
1869
+ return r;
1870
+ }, {});
1871
+ const rows = this.getGroupHeaders(depth, groups, virtualIndexes, visibleItems);
1872
+ rows.push(colNames);
1873
+ return {
1874
+ headers: rows,
1875
+ props: colProps,
1876
+ };
1877
+ }
1878
+ getGroupHeaders(depth, groups, items, visibleItems) {
1879
+ const rows = [];
1880
+ const template = fill_1(new Array(items.length), '');
1881
+ for (let d = 0; d < depth; d++) {
1882
+ const rgRow = [...template];
1883
+ rows.push(rgRow);
1884
+ if (!groups[d]) {
1885
+ continue;
1886
+ }
1887
+ const levelGroups = groups[d];
1888
+ // add names of groups
1889
+ levelGroups.forEach((group) => {
1890
+ const minIndex = this.findGroupStartIndex(group.ids, visibleItems);
1891
+ if (typeof minIndex === 'number') {
1892
+ rgRow[minIndex] = group.name;
1893
+ }
1894
+ });
1895
+ }
1896
+ return rows;
1897
+ }
1898
+ findGroupStartIndex(ids, visibleItems) {
1899
+ let min;
1900
+ ids.forEach(id => {
1901
+ const current = visibleItems[id];
1902
+ if (typeof current === 'number') {
1903
+ if (typeof min !== 'number' || min > current) {
1904
+ min = current;
1905
+ }
1906
+ }
1907
+ });
1908
+ return min;
1909
+ }
1910
+ async getSource() {
1911
+ const data = [];
1912
+ const promisesData = [];
1913
+ rowTypes.forEach(t => {
1914
+ const dataPart = [];
1915
+ data.push(dataPart);
1916
+ const promise = this.revogrid.getVisibleSource(t).then((d) => dataPart.push(...d));
1917
+ promisesData.push(promise);
1918
+ });
1919
+ await Promise.all(promisesData);
1920
+ return data.reduce((r, v) => {
1921
+ r.push(...v);
1922
+ return r;
1923
+ }, []);
1924
+ }
1925
+ // get correct class for future multiple types support
1926
+ formatter(type, options = {}) {
1927
+ switch (type) {
1928
+ case ExportTypes.csv:
1929
+ return new ExportCsv(options);
1930
+ default:
1931
+ throw new Error('Unknown format');
1932
+ }
1933
+ }
1934
+ }
1935
+
1936
+ // provide collapse data
1937
+ function doCollapse(pIndex, source) {
1938
+ const model = source[pIndex];
1939
+ const currentId = model[PSEUDO_GROUP_ITEM_ID];
1940
+ const trimmed = {};
1941
+ let i = pIndex + 1;
1942
+ const total = source.length;
1943
+ while (i < total) {
1944
+ const currentModel = source[i];
1945
+ if (isGrouping(currentModel)) {
1946
+ if (currentId !== currentModel[PSEUDO_GROUP_ITEM_ID]) {
1947
+ break;
1948
+ }
1949
+ else {
1950
+ currentModel[GROUP_EXPANDED] = false;
1951
+ }
1952
+ }
1953
+ trimmed[i++] = true;
1954
+ }
1955
+ model[GROUP_EXPANDED] = false;
1956
+ return { trimmed };
1957
+ }
1958
+ /**
1959
+ *
1960
+ * @param pIndex - physical index
1961
+ * @param vIndex - virtual index, need to update item collection
1962
+ * @param source - data source
1963
+ * @param rowItemsIndexes - rgRow indexes
1964
+ */
1965
+ function doExpand(vIndex, source, rowItemsIndexes) {
1966
+ const physicalIndex = rowItemsIndexes[vIndex];
1967
+ const model = source[physicalIndex];
1968
+ const currentGroup = getParsedGroup(model[PSEUDO_GROUP_ITEM_ID]);
1969
+ const trimmed = {};
1970
+ // no group found
1971
+ if (!currentGroup) {
1972
+ return { trimmed };
1973
+ }
1974
+ const groupItems = [];
1975
+ model[GROUP_EXPANDED] = true;
1976
+ let i = physicalIndex + 1;
1977
+ const total = source.length;
1978
+ let groupLevelOnly = 0;
1979
+ // go through all rows
1980
+ while (i < total) {
1981
+ const currentModel = source[i];
1982
+ const isGroup = isGrouping(currentModel);
1983
+ // group found
1984
+ if (isGroup) {
1985
+ if (!isSameGroup(currentGroup, model, currentModel)) {
1986
+ break;
1987
+ }
1988
+ else if (!groupLevelOnly) {
1989
+ // if get group first it's group only level
1990
+ groupLevelOnly = currentModel[GROUP_DEPTH];
1991
+ }
1992
+ }
1993
+ // level 0 or same depth
1994
+ if (!groupLevelOnly || (isGroup && groupLevelOnly === currentModel[GROUP_DEPTH])) {
1995
+ trimmed[i] = false;
1996
+ groupItems.push(i);
1997
+ }
1998
+ i++;
1999
+ }
2000
+ const result = {
2001
+ trimmed,
2002
+ };
2003
+ if (groupItems.length) {
2004
+ const items = [...rowItemsIndexes];
2005
+ items.splice(vIndex + 1, 0, ...groupItems);
2006
+ result.items = items;
2007
+ }
2008
+ return result;
2009
+ }
2010
+
2011
+ const TRIMMED_GROUPING = 'grouping';
2012
+ /**
2013
+ * Prepare trimming updated indexes for grouping
2014
+ * @param initiallyTrimed
2015
+ * @param firstLevelMap
2016
+ * @param secondLevelMap
2017
+ */
2018
+ function processDoubleConversionTrimmed(initiallyTrimed, firstLevelMap, secondLevelMap) {
2019
+ const trimemedOptionsToUpgrade = {};
2020
+ /**
2021
+ * go through all groups except grouping
2022
+ */
2023
+ for (let type in initiallyTrimed) {
2024
+ if (type === TRIMMED_GROUPING) {
2025
+ continue;
2026
+ }
2027
+ const items = initiallyTrimed[type];
2028
+ const newItems = {};
2029
+ for (let initialIndex in items) {
2030
+ /**
2031
+ * if item exists we find it in collection
2032
+ * we support 2 level of conversions
2033
+ */
2034
+ let newConversionIndex = firstLevelMap[initialIndex];
2035
+ if (secondLevelMap) {
2036
+ newConversionIndex = secondLevelMap[newConversionIndex];
2037
+ }
2038
+ /**
2039
+ * if item was trimmed previously
2040
+ * trimming makes sense to apply
2041
+ */
2042
+ if (items[initialIndex]) {
2043
+ newItems[newConversionIndex] = true;
2044
+ /**
2045
+ * If changes present apply changes to new source
2046
+ */
2047
+ if (newConversionIndex !== parseInt(initialIndex, 10)) {
2048
+ trimemedOptionsToUpgrade[type] = newItems;
2049
+ }
2050
+ }
2051
+ }
2052
+ }
2053
+ return trimemedOptionsToUpgrade;
2054
+ }
2055
+
2056
+ class GroupingRowPlugin extends BasePlugin {
2057
+ constructor(revogrid, providers) {
2058
+ super(revogrid);
2059
+ this.revogrid = revogrid;
2060
+ this.providers = providers;
2061
+ }
2062
+ get hasProps() {
2063
+ var _a, _b, _c;
2064
+ return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.props) && ((_c = (_b = this.options) === null || _b === void 0 ? void 0 : _b.props) === null || _c === void 0 ? void 0 : _c.length);
2065
+ }
2066
+ get store() {
2067
+ return this.providers.dataProvider.stores[GROUPING_ROW_TYPE].store;
2068
+ }
2069
+ // proxy for items get
2070
+ get rowItems() {
2071
+ return this.store.get('items');
2072
+ }
2073
+ get trimmed() {
2074
+ return this.store.get('trimmed');
2075
+ }
2076
+ // befoce cell focus
2077
+ onFocus(e) {
2078
+ if (isGrouping(e.detail.model)) {
2079
+ e.preventDefault();
2080
+ }
2081
+ }
2082
+ // expand event triggered
2083
+ onExpand({ virtualIndex }) {
2084
+ const { source } = this.getSource();
2085
+ let newTrimmed = this.trimmed[TRIMMED_GROUPING];
2086
+ let i = getPhysical(this.store, virtualIndex);
2087
+ const model = source[i];
2088
+ const prevExpanded = model[GROUP_EXPANDED];
2089
+ if (!prevExpanded) {
2090
+ const { trimmed, items } = doExpand(virtualIndex, source, this.rowItems);
2091
+ newTrimmed = Object.assign(Object.assign({}, newTrimmed), trimmed);
2092
+ if (items) {
2093
+ setItems(this.store, items);
2094
+ }
2095
+ }
2096
+ else {
2097
+ const { trimmed } = doCollapse(i, source);
2098
+ newTrimmed = Object.assign(Object.assign({}, newTrimmed), trimmed);
2099
+ this.revogrid.clearFocus();
2100
+ }
2101
+ this.store.set('source', source);
2102
+ this.revogrid.addTrimmed(newTrimmed, TRIMMED_GROUPING);
2103
+ }
2104
+ // get source based on proxy item collection to preserve rgRow order
2105
+ getSource(withoutGrouping = false) {
2106
+ const source = this.store.get('source');
2107
+ const items = this.store.get('proxyItems');
2108
+ let index = 0;
2109
+ // order important here, expected parent is first, then others
2110
+ return items.reduce((result, i) => {
2111
+ const model = source[i];
2112
+ if (!withoutGrouping) {
2113
+ result.source.push(model);
2114
+ return result;
2115
+ }
2116
+ // grouping filter
2117
+ if (!isGrouping(model)) {
2118
+ result.source.push(model);
2119
+ result.oldNewIndexes[i] = index;
2120
+ index++;
2121
+ }
2122
+ else {
2123
+ if (model[GROUP_EXPANDED]) {
2124
+ result.prevExpanded[model[PSEUDO_GROUP_ITEM_VALUE]] = true;
2125
+ }
2126
+ }
2127
+ return result;
2128
+ }, {
2129
+ source: [],
2130
+ prevExpanded: {},
2131
+ oldNewIndexes: {},
2132
+ });
2133
+ }
2134
+ setColumnGrouping(cols) {
2135
+ // if 0 column as holder
2136
+ if (cols === null || cols === void 0 ? void 0 : cols.length) {
2137
+ cols[0][PSEUDO_GROUP_COLUMN] = true;
2138
+ return true;
2139
+ }
2140
+ return false;
2141
+ }
2142
+ setColumns({ columns }) {
2143
+ for (let type of columnTypes) {
2144
+ if (this.setColumnGrouping(columns[type])) {
2145
+ break;
2146
+ }
2147
+ }
2148
+ }
2149
+ // evaluate drag between groups
2150
+ onDrag(e) {
2151
+ const { from, to } = e.detail;
2152
+ const isDown = to - from >= 0;
2153
+ const { source } = this.getSource();
2154
+ const items = this.rowItems;
2155
+ let i = isDown ? from : to;
2156
+ const end = isDown ? to : from;
2157
+ for (; i < end; i++) {
2158
+ const model = source[items[i]];
2159
+ const isGroup = isGrouping(model);
2160
+ if (isGroup) {
2161
+ e.preventDefault();
2162
+ return;
2163
+ }
2164
+ }
2165
+ }
2166
+ beforeTrimmedApply(trimmed, type) {
2167
+ /** Before filter apply remove grouping filtering */
2168
+ if (type === FILTER_TRIMMED_TYPE) {
2169
+ const source = this.store.get('source');
2170
+ for (let index in trimmed) {
2171
+ if (trimmed[index] && isGrouping(source[index])) {
2172
+ trimmed[index] = false;
2173
+ }
2174
+ }
2175
+ }
2176
+ }
2177
+ // subscribe to grid events to process them accordingly
2178
+ subscribe() {
2179
+ /** if grouping present and new data source arrived */
2180
+ this.addEventListener('beforesourceset', ({ detail }) => this.onDataSet(detail));
2181
+ this.addEventListener('beforecolumnsset', ({ detail }) => this.setColumns(detail));
2182
+ /**
2183
+ * filter applied need to clear grouping and apply again
2184
+ * based on new results can be new grouping
2185
+ */
2186
+ this.addEventListener('beforetrimmed', ({ detail: { trimmed, trimmedType } }) => this.beforeTrimmedApply(trimmed, trimmedType));
2187
+ /**
2188
+ * sorting applied need to clear grouping and apply again
2189
+ * based on new results whole grouping order will changed
2190
+ */
2191
+ this.addEventListener('afterSortingApply', () => this.doSourceUpdate());
2192
+ /**
2193
+ * Apply logic for focus inside of grouping
2194
+ * We can't focus on grouping rows, navigation only inside of groups for now
2195
+ */
2196
+ this.addEventListener('beforecellfocus', e => this.onFocus(e));
2197
+ /**
2198
+ * Prevent rgRow drag outside the group
2199
+ */
2200
+ this.addEventListener('roworderchanged', e => this.onDrag(e));
2201
+ /**
2202
+ * When grouping expand icon was clicked
2203
+ */
2204
+ this.addEventListener(GROUP_EXPAND_EVENT, ({ detail }) => this.onExpand(detail));
2205
+ }
2206
+ /**
2207
+ * Starts global source update with group clearing and applying new one
2208
+ * Initiated when need to reapply grouping
2209
+ */
2210
+ doSourceUpdate(options) {
2211
+ if (!this.hasProps) {
2212
+ return;
2213
+ }
2214
+ /**
2215
+ * Get source without grouping
2216
+ * @param newOldIndexMap - provides us mapping with new indexes vs old indexes, we would use it for trimmed mapping
2217
+ */
2218
+ const { source, prevExpanded, oldNewIndexes } = this.getSource(true);
2219
+ /**
2220
+ * Group again
2221
+ * @param oldNewIndexMap - provides us mapping with new indexes vs old indexes
2222
+ */
2223
+ const { sourceWithGroups, depth, trimmed, oldNewIndexMap, childrenByGroup } = gatherGrouping(source,
2224
+ // filter
2225
+ item => { var _a; return (_a = this.options) === null || _a === void 0 ? void 0 : _a.props.map(key => item[key]); }, Object.assign({ prevExpanded }, options));
2226
+ // setup source
2227
+ this.providers.dataProvider.setData(sourceWithGroups, GROUPING_ROW_TYPE, { depth }, true);
2228
+ this.updateTrimmed(trimmed, childrenByGroup, oldNewIndexes, oldNewIndexMap);
2229
+ }
2230
+ /**
2231
+ * Apply grouping on data set
2232
+ * Clear grouping from source
2233
+ * If source came from other plugin
2234
+ */
2235
+ onDataSet(data) {
2236
+ if (!this.hasProps || !(data === null || data === void 0 ? void 0 : data.source) || !data.source.length) {
2237
+ return;
2238
+ }
2239
+ const source = data.source.filter(s => !isGrouping(s));
2240
+ const expanded = this.revogrid.grouping || {};
2241
+ const { sourceWithGroups, depth, trimmed, oldNewIndexMap, childrenByGroup } = gatherGrouping(source,
2242
+ // filter
2243
+ item => { var _a; return (_a = this.options) === null || _a === void 0 ? void 0 : _a.props.map(key => item[key]); }, Object.assign({}, (expanded || {})));
2244
+ data.source = sourceWithGroups;
2245
+ this.providers.dataProvider.setGrouping({ depth });
2246
+ this.updateTrimmed(trimmed, childrenByGroup, oldNewIndexMap);
2247
+ }
2248
+ // apply grouping
2249
+ setGrouping(options) {
2250
+ // unsubscribe from all events when group applied
2251
+ this.clearSubscriptions();
2252
+ this.options = options;
2253
+ // clear props, no grouping exists
2254
+ if (!options.props || !Object.keys(options.props).length) {
2255
+ this.clearGrouping();
2256
+ return;
2257
+ }
2258
+ // props exist and source inited
2259
+ const { source } = this.getSource();
2260
+ if (source.length) {
2261
+ this.doSourceUpdate(Object.assign({}, options));
2262
+ }
2263
+ // props exist and columns inited
2264
+ for (let t of columnTypes) {
2265
+ if (this.setColumnGrouping(this.providers.columnProvider.getColumns(t))) {
2266
+ this.providers.columnProvider.refreshByType(t);
2267
+ break;
2268
+ }
2269
+ }
2270
+ // if has any grouping subscribe to events again
2271
+ this.subscribe();
2272
+ }
2273
+ // clear grouping
2274
+ clearGrouping() {
2275
+ // clear columns
2276
+ columnTypes.forEach(t => {
2277
+ const cols = this.providers.columnProvider.getColumns(t);
2278
+ let deleted = false;
2279
+ cols.forEach(c => {
2280
+ if (isGroupingColumn(c)) {
2281
+ delete c[PSEUDO_GROUP_COLUMN];
2282
+ deleted = true;
2283
+ }
2284
+ });
2285
+ // if column store had grouping clear and refresh
2286
+ if (deleted) {
2287
+ this.providers.columnProvider.refreshByType(t);
2288
+ }
2289
+ });
2290
+ // clear rows
2291
+ const { source, oldNewIndexes } = this.getSource(true);
2292
+ this.providers.dataProvider.setData(source, GROUPING_ROW_TYPE, undefined, true);
2293
+ this.updateTrimmed(undefined, undefined, oldNewIndexes);
2294
+ }
2295
+ updateTrimmed(trimmedGroup = {}, _childrenByGroup = {}, firstLevelMap, secondLevelMap) {
2296
+ // map previously trimmed data
2297
+ const trimemedOptionsToUpgrade = processDoubleConversionTrimmed(this.trimmed, firstLevelMap, secondLevelMap);
2298
+ for (let type in trimemedOptionsToUpgrade) {
2299
+ this.revogrid.addTrimmed(trimemedOptionsToUpgrade[type], type);
2300
+ }
2301
+ // const emptyGroups = this.filterOutEmptyGroups(trimemedOptionsToUpgrade, childrenByGroup);
2302
+ // setup trimmed data for grouping
2303
+ this.revogrid.addTrimmed(Object.assign({}, trimmedGroup), TRIMMED_GROUPING);
2304
+ }
2305
+ }
2306
+
2307
+ /**
2308
+ * Draw drag
2309
+ */
2310
+ class OrdererService {
2311
+ constructor() {
2312
+ this.parentY = 0;
2313
+ }
2314
+ start(parent, { pos, text, event }) {
2315
+ var _a;
2316
+ const { top } = parent.getBoundingClientRect();
2317
+ this.parentY = top;
2318
+ if (this.text) {
2319
+ this.text.innerText = text;
2320
+ }
2321
+ this.move(pos);
2322
+ this.moveTip({ x: event.x, y: event.y });
2323
+ (_a = this.el) === null || _a === void 0 ? void 0 : _a.classList.remove('hidden');
2324
+ }
2325
+ end() {
2326
+ var _a;
2327
+ (_a = this.el) === null || _a === void 0 ? void 0 : _a.classList.add('hidden');
2328
+ }
2329
+ move(pos) {
2330
+ this.moveElement(pos.end - this.parentY);
2331
+ }
2332
+ moveTip({ x, y }) {
2333
+ if (!this.draggable) {
2334
+ return;
2335
+ }
2336
+ this.draggable.style.left = `${x}px`;
2337
+ this.draggable.style.top = `${y}px`;
2338
+ }
2339
+ moveElement(y) {
2340
+ if (!this.rgRow) {
2341
+ return;
2342
+ }
2343
+ this.rgRow.style.transform = `translateY(${y}px)`;
2344
+ }
2345
+ }
2346
+ const OrderRenderer = ({ ref }) => {
2347
+ const service = new OrdererService();
2348
+ ref(service);
2349
+ return (h("div", { class: "draggable-wrapper hidden", ref: e => (service.el = e) },
2350
+ h("div", { class: "draggable", ref: el => (service.draggable = el) },
2351
+ h("span", { class: "revo-alt-icon" }),
2352
+ h("span", { ref: e => (service.text = e) })),
2353
+ h("div", { class: "drag-position", ref: e => (service.rgRow = e) })));
2354
+ };
2355
+
2356
+ const RevoViewPort = ({ viewports, dimensions, orderRef, nakedClick, registerElement, onScroll }, children) => {
2357
+ const viewPortClick = (e, el) => {
2358
+ if (el === e.target) {
2359
+ nakedClick(e);
2360
+ }
2361
+ };
2362
+ let el;
2363
+ return [
2364
+ h("div", { class: "main-viewport", ref: e => el = e, onClick: e => viewPortClick(e, el) },
2365
+ h("div", { class: "viewports" },
2366
+ children,
2367
+ h("revogr-scroll-virtual", { class: "vertical", dimension: "rgRow", viewportStore: viewports['rgRow'].store, dimensionStore: dimensions['rgRow'].store, ref: el => registerElement(el, 'rowScroll'), onScrollVirtual: e => onScroll(e.detail) }),
2368
+ h(OrderRenderer, { ref: orderRef }))),
2369
+ h("revogr-scroll-virtual", { class: "horizontal", dimension: "rgCol", viewportStore: viewports['rgCol'].store, dimensionStore: dimensions['rgCol'].store, ref: el => registerElement(el, 'colScroll'), onScrollVirtual: e => onScroll(e.detail) }),
2370
+ ];
2371
+ };
2372
+
2373
+ class ViewportService {
2374
+ constructor(sv, contentHeight) {
2375
+ var _a, _b;
2376
+ this.sv = sv;
2377
+ this.storesByType = {};
2378
+ this.storesXToType = {};
2379
+ this.storesYToType = {};
2380
+ (_a = this.sv.selectionStoreConnector) === null || _a === void 0 ? void 0 : _a.beforeUpdate();
2381
+ this.columns = this.getViewportColumnData(contentHeight);
2382
+ (_b = this.sv.scrollingService) === null || _b === void 0 ? void 0 : _b.unregister();
2383
+ }
2384
+ onColumnResize(type, e, store) {
2385
+ var _a;
2386
+ (_a = this.sv.dimensionProvider) === null || _a === void 0 ? void 0 : _a.setDimensionSize(type, e.detail);
2387
+ const changedItems = lodash.reduce(e.detail || {}, (r, size, index) => {
2388
+ const item = getSourceItem(store, parseInt(index, 10));
2389
+ if (item) {
2390
+ r[item.prop] = Object.assign(Object.assign({}, item), { size });
2391
+ }
2392
+ return r;
2393
+ }, {});
2394
+ this.sv.resize(changedItems);
2395
+ }
2396
+ /**
2397
+ * Transform data from stores and apply it to different components
2398
+ */
2399
+ getViewportColumnData(contentHeight) {
2400
+ const columns = [];
2401
+ let x = 0; // we increase x only if column present
2402
+ columnTypes.forEach(val => {
2403
+ const colStore = this.sv.columnProvider.stores[val].store;
2404
+ // only columns that have data show
2405
+ if (!colStore.get('items').length) {
2406
+ return;
2407
+ }
2408
+ const column = {
2409
+ colType: val,
2410
+ position: { x, y: 1 },
2411
+ contentHeight,
2412
+ fixWidth: val !== 'rgCol',
2413
+ uuid: `${this.sv.uuid}-${x}`,
2414
+ viewports: this.sv.viewportProvider.stores,
2415
+ dimensions: this.sv.dimensionProvider.stores,
2416
+ rowStores: this.sv.dataProvider.stores,
2417
+ colStore,
2418
+ onHeaderresize: e => this.onColumnResize(val, e, colStore)
2419
+ };
2420
+ if (val === 'rgCol') {
2421
+ column.onResizeViewport = (e) => { var _a; return (_a = this.sv.viewportProvider) === null || _a === void 0 ? void 0 : _a.setViewport(e.detail.dimension, { virtualSize: e.detail.size }); };
2422
+ }
2423
+ const colData = this.gatherColumnData(column);
2424
+ const columnSelectionStore = this.registerCol(colData.position.x, val);
2425
+ // render per each column data collections vertically
2426
+ const dataPorts = this.dataViewPort(column).reduce((r, rgRow) => {
2427
+ // register selection store for Segment
2428
+ const segmentSelection = this.registerSegment(rgRow.position);
2429
+ segmentSelection.setLastCell(rgRow.lastCell);
2430
+ // register selection store for Row
2431
+ const rowSelectionStore = this.registerRow(rgRow.position.y, rgRow.type);
2432
+ const rowDef = Object.assign(Object.assign({}, rgRow), { rowSelectionStore, segmentSelectionStore: segmentSelection.store, ref: (e) => this.sv.selectionStoreConnector.registerSection(e), onSetRange: e => segmentSelection.setRangeArea(e.detail), onSetTempRange: e => segmentSelection.setTempArea(e.detail), onFocusCell: e => {
2433
+ segmentSelection.clearFocus();
2434
+ this.sv.selectionStoreConnector.focus(segmentSelection, e.detail);
2435
+ } });
2436
+ r.push(rowDef);
2437
+ return r;
2438
+ }, []);
2439
+ columns.push(Object.assign(Object.assign({}, colData), { columnSelectionStore,
2440
+ dataPorts }));
2441
+ x++;
2442
+ });
2443
+ return columns;
2444
+ }
2445
+ /** register selection store for Segment */
2446
+ registerSegment(position) {
2447
+ return this.sv.selectionStoreConnector.register(position);
2448
+ }
2449
+ /** register selection store for Row */
2450
+ registerRow(y, type) {
2451
+ // link to position
2452
+ this.storesByType[type] = y;
2453
+ this.storesYToType[y] = type;
2454
+ return this.sv.selectionStoreConnector.registerRow(y).store;
2455
+ }
2456
+ /** register selection store for Column */
2457
+ registerCol(x, type) {
2458
+ // link to position
2459
+ this.storesByType[type] = x;
2460
+ this.storesXToType[x] = type;
2461
+ return this.sv.selectionStoreConnector.registerColumn(x).store;
2462
+ }
2463
+ /** Collect Column data */
2464
+ gatherColumnData(data) {
2465
+ const parent = data.uuid;
2466
+ const realSize = data.dimensions[data.colType].store.get('realSize');
2467
+ const prop = {
2468
+ contentWidth: realSize,
2469
+ class: data.colType,
2470
+ [`${UUID}`]: data.uuid,
2471
+ contentHeight: data.contentHeight,
2472
+ key: data.colType,
2473
+ onResizeViewport: data.onResizeViewport,
2474
+ };
2475
+ if (data.fixWidth) {
2476
+ prop.style = { minWidth: `${realSize}px` };
2477
+ }
2478
+ const headerProp = {
2479
+ parent,
2480
+ colData: getVisibleSourceItem(data.colStore),
2481
+ dimensionCol: data.dimensions[data.colType].store,
2482
+ groups: data.colStore.get('groups'),
2483
+ groupingDepth: data.colStore.get('groupingDepth'),
2484
+ onHeaderresize: data.onHeaderresize,
2485
+ };
2486
+ return {
2487
+ prop,
2488
+ position: data.position,
2489
+ headerProp,
2490
+ parent,
2491
+ viewportCol: data.viewports[data.colType].store,
2492
+ };
2493
+ }
2494
+ /** Collect Row data */
2495
+ dataViewPort(data) {
2496
+ const slots = {
2497
+ rowPinStart: HEADER_SLOT,
2498
+ rgRow: CONTENT_SLOT,
2499
+ rowPinEnd: FOOTER_SLOT,
2500
+ };
2501
+ // y position for selection
2502
+ let y = 0;
2503
+ return rowTypes.reduce((r, type) => {
2504
+ // filter out empty sources, we still need to return source to keep slot working
2505
+ const isPresent = data.viewports[type].store.get('realCount') || type === 'rgRow';
2506
+ const rgCol = Object.assign(Object.assign({}, data), { position: Object.assign(Object.assign({}, data.position), { y: isPresent ? y : EMPTY_INDEX }) });
2507
+ r.push(this.dataPartition(rgCol, type, slots[type], type !== 'rgRow'));
2508
+ if (isPresent) {
2509
+ y++;
2510
+ }
2511
+ return r;
2512
+ }, []);
2513
+ }
2514
+ dataPartition(data, type, slot, fixed) {
2515
+ return {
2516
+ colData: data.colStore,
2517
+ viewportCol: data.viewports[data.colType].store,
2518
+ viewportRow: data.viewports[type].store,
2519
+ lastCell: getLastCell(data, type),
2520
+ slot,
2521
+ type,
2522
+ canDrag: !fixed,
2523
+ position: data.position,
2524
+ uuid: `${data.uuid}-${data.position.x}-${data.position.y}`,
2525
+ dataStore: data.rowStores[type].store,
2526
+ dimensionCol: data.dimensions[data.colType].store,
2527
+ dimensionRow: data.dimensions[type].store,
2528
+ style: fixed ? { height: `${data.dimensions[type].store.get('realSize')}px` } : undefined,
2529
+ };
2530
+ }
2531
+ scrollToCell(cell) {
2532
+ for (let key in cell) {
2533
+ const coordinate = cell[key];
2534
+ this.sv.scrollingService.onScroll({ dimension: key === 'x' ? 'rgCol' : 'rgRow', coordinate });
2535
+ }
2536
+ }
2537
+ /**
2538
+ * Clear current grid focus
2539
+ */
2540
+ clearFocused() {
2541
+ this.sv.selectionStoreConnector.clearAll();
2542
+ }
2543
+ clearEdit() {
2544
+ this.sv.selectionStoreConnector.setEdit(false);
2545
+ }
2546
+ getFocused() {
2547
+ const focused = this.sv.selectionStoreConnector.focusedStore;
2548
+ if (!focused) {
2549
+ return null;
2550
+ }
2551
+ const colType = this.storesXToType[focused.position.x];
2552
+ const column = this.sv.columnProvider.getColumn(focused.cell.x, colType);
2553
+ const rowType = this.storesYToType[focused.position.x];
2554
+ const model = this.sv.dataProvider.getModel(focused.cell.x, rowType);
2555
+ return {
2556
+ column,
2557
+ model,
2558
+ cell: focused.cell,
2559
+ colType,
2560
+ rowType
2561
+ };
2562
+ }
2563
+ getSelectedRange() {
2564
+ return this.sv.selectionStoreConnector.selectedRange;
2565
+ }
2566
+ setEdit(rowIndex, colIndex, colType, rowType) {
2567
+ var _a;
2568
+ const stores = this.storesByType;
2569
+ const storeCoordinate = {
2570
+ x: stores[colType],
2571
+ y: stores[rowType],
2572
+ };
2573
+ (_a = this.sv.selectionStoreConnector) === null || _a === void 0 ? void 0 : _a.setEditByCell(storeCoordinate, { x: colIndex, y: rowIndex });
2574
+ }
2575
+ }
2576
+
2577
+ /**
2578
+ * All render based on sections
2579
+ * First we render vertical parts - pinned start, data, pinned end
2580
+ * Per each column we render data collections: headers, pinned top, center data, pinned bottom
2581
+ */
2582
+ const ViewPortSections = ({ resize, editors, rowClass, readonly, range, columns, useClipboard, columnFilter, registerElement, onEdit, onScroll }) => {
2583
+ const viewPortHtml = [];
2584
+ /** render viewports columns */
2585
+ for (let view of columns) {
2586
+ /** render viewports rows */
2587
+ const dataViews = [
2588
+ h("revogr-header", Object.assign({ viewportCol: view.viewportCol }, view.headerProp, { selectionStore: view.columnSelectionStore, slot: HEADER_SLOT, columnFilter: columnFilter, canResize: resize })),
2589
+ ];
2590
+ view.dataPorts.forEach((data, j) => {
2591
+ const key = view.prop.key + (j + 1);
2592
+ const dataView = (h("revogr-overlay-selection", Object.assign({}, data, { slot: data.slot, selectionStore: data.segmentSelectionStore, editors: editors, readonly: readonly, range: range, useClipboard: useClipboard, onSetEdit: ({ detail }) => onEdit(detail) }),
2593
+ h("revogr-data", Object.assign({}, data, { [UUID]: data.uuid }, { key: key, readonly: readonly, range: range, rowClass: rowClass, rowSelectionStore: data.rowSelectionStore, slot: DATA_SLOT })),
2594
+ h("revogr-temp-range", { selectionStore: data.segmentSelectionStore, dimensionRow: data.dimensionRow, dimensionCol: data.dimensionCol }),
2595
+ h("revogr-focus", { colData: data.colData, dataStore: data.dataStore, selectionStore: data.segmentSelectionStore, dimensionRow: data.dimensionRow, dimensionCol: data.dimensionCol })));
2596
+ dataViews.push(dataView);
2597
+ });
2598
+ viewPortHtml.push(h("revogr-viewport-scroll", Object.assign({}, view.prop, { ref: el => registerElement(el, view.prop.key), onScrollViewport: e => onScroll(e.detail, view.prop.key) }), dataViews));
2599
+ }
2600
+ return viewPortHtml;
2601
+ };
2602
+
2603
+ class GridScrollingService {
2604
+ constructor(setViewport) {
2605
+ this.setViewport = setViewport;
2606
+ this.elements = {};
2607
+ }
2608
+ async onScroll(e, key) {
2609
+ let newEvent;
2610
+ for (let elKey in this.elements) {
2611
+ if (this.isPinnedColumn(key) && e.dimension === 'rgCol') {
2612
+ if (elKey === key || !e.delta) {
2613
+ continue;
2614
+ }
2615
+ for (let el of this.elements[elKey]) {
2616
+ el.changeScroll && (newEvent = el.changeScroll(e));
2617
+ }
2618
+ }
2619
+ else if (e.dimension === 'rgCol' && elKey === 'headerRow') {
2620
+ continue;
2621
+ }
2622
+ else {
2623
+ for (let el of this.elements[elKey]) {
2624
+ el.setScroll(e);
2625
+ }
2626
+ }
2627
+ }
2628
+ let event = e;
2629
+ if (newEvent) {
2630
+ event = await newEvent;
2631
+ }
2632
+ this.setViewport(event);
2633
+ }
2634
+ isPinnedColumn(key) {
2635
+ return ['colPinStart', 'colPinEnd'].indexOf(key) > -1;
2636
+ }
2637
+ registerElements(els) {
2638
+ this.elements = els;
2639
+ }
2640
+ /**
2641
+ * Register new element for farther scroll support
2642
+ * @param el - can be null if holder removed
2643
+ * @param key - element key
2644
+ */
2645
+ registerElement(el, key) {
2646
+ if (!this.elements[key]) {
2647
+ this.elements[key] = [];
2648
+ }
2649
+ // new element added
2650
+ if (el) {
2651
+ this.elements[key].push(el);
2652
+ }
2653
+ else if (this.elements[key]) {
2654
+ // element removed
2655
+ delete this.elements[key];
2656
+ }
2657
+ }
2658
+ unregister() {
2659
+ delete this.elements;
2660
+ this.elements = {};
2661
+ }
2662
+ }
2663
+
2664
+ class StretchColumn extends BasePlugin {
2665
+ constructor(revogrid, dimensionProvider) {
2666
+ super(revogrid);
2667
+ this.dimensionProvider = dimensionProvider;
2668
+ this.stretchedColumn = null;
2669
+ this.scrollSize = getScrollbarWidth(document);
2670
+ const beforecolumnapplied = ({ detail: { columns } }) => this.applyStretch(columns);
2671
+ this.addEventListener('beforecolumnapplied', beforecolumnapplied);
2672
+ }
2673
+ setScroll({ type, hasScroll }) {
2674
+ var _a;
2675
+ if (type === 'rgRow' && this.stretchedColumn && ((_a = this.stretchedColumn) === null || _a === void 0 ? void 0 : _a.initialSize) === this.stretchedColumn.size) {
2676
+ if (hasScroll) {
2677
+ this.stretchedColumn.size -= this.scrollSize;
2678
+ this.apply();
2679
+ this.dropChanges();
2680
+ }
2681
+ }
2682
+ }
2683
+ activateChanges() {
2684
+ const setScroll = ({ detail }) => this.setScroll(detail);
2685
+ this.addEventListener('scrollchange', setScroll);
2686
+ }
2687
+ dropChanges() {
2688
+ this.stretchedColumn = null;
2689
+ this.removeEventListener('scrollchange');
2690
+ }
2691
+ apply() {
2692
+ if (!this.stretchedColumn) {
2693
+ return;
2694
+ }
2695
+ const type = 'rgCol';
2696
+ this.dimensionProvider.setDimensionSize(type, { [this.stretchedColumn.index]: this.stretchedColumn.size });
2697
+ }
2698
+ applyStretch(columns) {
2699
+ this.dropChanges();
2700
+ let sizeDifference = this.revogrid.clientWidth - 1;
2701
+ lodash.each(columns, (_c, type) => {
2702
+ const realSize = this.dimensionProvider.stores[type].store.get('realSize');
2703
+ sizeDifference -= realSize;
2704
+ });
2705
+ if (sizeDifference > 0) {
2706
+ // currently plugin accepts last column
2707
+ const index = columns.rgCol.length - 1;
2708
+ const last = columns.rgCol[index];
2709
+ // has column
2710
+ // no auto size applied
2711
+ // size for column shouldn't be defined
2712
+ const colSize = (last === null || last === void 0 ? void 0 : last.size) || this.revogrid.colSize || 0;
2713
+ const size = sizeDifference + colSize - 1;
2714
+ if (last && !last.autoSize && (colSize < size)) {
2715
+ this.stretchedColumn = {
2716
+ initialSize: size,
2717
+ index,
2718
+ size
2719
+ };
2720
+ this.apply();
2721
+ this.activateChanges();
2722
+ }
2723
+ }
2724
+ }
2725
+ }
2726
+ function isStretchPlugin(plugin) {
2727
+ return !!plugin.applyStretch;
2728
+ }
2729
+
2730
+ class ColumnOrderHandler {
2731
+ constructor() {
2732
+ this.offset = 0;
2733
+ }
2734
+ renderAutoscroll(_, parent) {
2735
+ if (!parent) {
2736
+ return;
2737
+ }
2738
+ this.autoscrollEl = document.createElement('div');
2739
+ this.autoscrollEl.classList.add('drag-auto-scroll-y');
2740
+ parent.appendChild(this.autoscrollEl);
2741
+ }
2742
+ autoscroll(pos, dataContainerSize, direction = 'translateX') {
2743
+ if (!this.autoscrollEl) {
2744
+ return;
2745
+ }
2746
+ const helperOffset = 10;
2747
+ // calculate current y position inside of the grid active holder
2748
+ // 3 - size of element + border
2749
+ const maxScroll = Math.min(pos + helperOffset, dataContainerSize - 3);
2750
+ this.autoscrollEl.style.transform = `${direction}(${maxScroll}px)`;
2751
+ this.autoscrollEl.scrollIntoView({
2752
+ block: 'nearest',
2753
+ inline: 'nearest',
2754
+ });
2755
+ }
2756
+ start(e, { dataEl, gridRect, scrollEl }, dir = 'left') {
2757
+ const scrollContainerRect = scrollEl.getBoundingClientRect();
2758
+ if (scrollContainerRect) {
2759
+ this.offset = scrollContainerRect[dir] - gridRect[dir];
2760
+ }
2761
+ this.renderAutoscroll(e, dataEl);
2762
+ }
2763
+ stop() {
2764
+ var _a;
2765
+ if (this.element) {
2766
+ this.element.hidden = true;
2767
+ }
2768
+ this.offset = 0;
2769
+ (_a = this.autoscrollEl) === null || _a === void 0 ? void 0 : _a.remove();
2770
+ this.autoscrollEl = undefined;
2771
+ }
2772
+ showHandler(pos, size, direction = 'translateX') {
2773
+ if (!this.element) {
2774
+ return;
2775
+ }
2776
+ // do not allow overcross top of the scrollable area, header excluded
2777
+ if (this.offset) {
2778
+ pos = Math.max(pos, this.offset);
2779
+ }
2780
+ // can not be bigger then grid end
2781
+ pos = Math.min(pos, size);
2782
+ this.element.style.transform = `${direction}(${pos}px)`;
2783
+ this.element.hidden = false;
2784
+ }
2785
+ render() {
2786
+ return h("div", { class: "drag-position-y", hidden: true, ref: (el) => (this.element = el) });
2787
+ }
2788
+ }
2789
+
2790
+ /**
2791
+ * Plugin for column manual move
2792
+ */
2793
+ const COLUMN_CLICK = 'column-click';
2794
+ const MOVE = 'column-mouse-move';
2795
+ const DRAG_END = 'column-drag-end';
2796
+ const BEFORE_DRAG_END = 'before-column-drag-end';
2797
+ // use this event subscription to drop D&D for particular columns
2798
+ const DRAG_START = 'column-drag-start';
2799
+ class ColumnPlugin extends BasePlugin {
2800
+ constructor(revogrid, providers) {
2801
+ super(revogrid);
2802
+ this.revogrid = revogrid;
2803
+ this.providers = providers;
2804
+ this.moveFunc = debounce_1((e) => this.doMove(e), 5);
2805
+ this.staticDragData = null;
2806
+ this.dragData = null;
2807
+ this.localSubscriptions = {};
2808
+ this.orderUi = new ColumnOrderHandler();
2809
+ revogrid.registerVNode([this.orderUi.render()]);
2810
+ /** Register events */
2811
+ this.localSubscriptions['mouseleave'] = {
2812
+ target: document,
2813
+ callback: (e) => this.onMouseOut(e),
2814
+ };
2815
+ this.localSubscriptions['mouseup'] = {
2816
+ target: document,
2817
+ callback: (e) => this.onMouseUp(e),
2818
+ };
2819
+ this.localSubscriptions['mousemove'] = {
2820
+ target: document,
2821
+ callback: (e) => this.move(e),
2822
+ };
2823
+ this.addEventListener(COLUMN_CLICK, ({ detail }) => this.dragStart(detail));
2824
+ }
2825
+ dragStart({ event, data }) {
2826
+ if (event.defaultPrevented) {
2827
+ return;
2828
+ }
2829
+ const { defaultPrevented } = dispatch(this.revogrid, DRAG_START, data);
2830
+ // check if allowed to drag particulat column
2831
+ if (defaultPrevented) {
2832
+ return;
2833
+ }
2834
+ this.clearOrder();
2835
+ const { mouseleave, mouseup, mousemove } = this.localSubscriptions;
2836
+ mouseleave.target.addEventListener('mouseleave', mouseleave.callback);
2837
+ mouseup.target.addEventListener('mouseup', mouseup.callback);
2838
+ const dataEl = event.target.closest('revogr-header');
2839
+ const scrollEl = event.target.closest('revogr-viewport-scroll');
2840
+ if (!dataEl || !scrollEl) {
2841
+ return;
2842
+ }
2843
+ if (isColGrouping(data)) {
2844
+ return;
2845
+ }
2846
+ const cols = this.getDimension(data.pin || 'rgCol');
2847
+ const gridRect = this.revogrid.getBoundingClientRect();
2848
+ const elRect = dataEl.getBoundingClientRect();
2849
+ const startItem = getItemByPosition(cols, getLeftRelative(event.x, gridRect.left, elRect.left - gridRect.left));
2850
+ this.staticDragData = {
2851
+ startPos: event.x,
2852
+ startItem,
2853
+ data,
2854
+ dataEl,
2855
+ scrollEl,
2856
+ gridEl: this.revogrid,
2857
+ cols,
2858
+ };
2859
+ this.dragData = this.getData(this.staticDragData);
2860
+ mousemove.target.addEventListener('mousemove', mousemove.callback);
2861
+ this.orderUi.start(event, Object.assign(Object.assign({}, this.dragData), this.staticDragData));
2862
+ }
2863
+ doMove(e) {
2864
+ if (!this.staticDragData) {
2865
+ return;
2866
+ }
2867
+ const dragData = (this.dragData = this.getData(this.staticDragData));
2868
+ if (!dragData) {
2869
+ return;
2870
+ }
2871
+ const start = this.staticDragData.startPos;
2872
+ if (Math.abs(start - e.x) > 10) {
2873
+ const x = getLeftRelative(e.x, this.dragData.gridRect.left, this.dragData.scrollOffset);
2874
+ const rgCol = getItemByPosition(this.staticDragData.cols, x);
2875
+ this.orderUi.autoscroll(x, dragData.elRect.width);
2876
+ this.orderUi.showHandler(rgCol.end + dragData.scrollOffset, dragData.gridRect.width);
2877
+ }
2878
+ }
2879
+ move(e) {
2880
+ dispatch(this.revogrid, MOVE, Object.assign({}, e));
2881
+ // then do move
2882
+ this.moveFunc(e);
2883
+ }
2884
+ onMouseOut(_) {
2885
+ this.clearOrder();
2886
+ }
2887
+ onMouseUp(e) {
2888
+ // apply new positions
2889
+ if (this.dragData) {
2890
+ let relativePos = getLeftRelative(e.x, this.dragData.gridRect.left, this.dragData.scrollOffset);
2891
+ if (relativePos < 0) {
2892
+ relativePos = 0;
2893
+ }
2894
+ const newPosition = getItemByPosition(this.staticDragData.cols, relativePos);
2895
+ const store = this.providers.column.stores[this.dragData.type].store;
2896
+ const items = [...store.get('items')];
2897
+ // prevent position change if needed
2898
+ const { defaultPrevented: stopDrag } = dispatch(this.revogrid, BEFORE_DRAG_END, Object.assign(Object.assign({}, this.staticDragData), { startPosition: this.staticDragData.startItem, newPosition, newItem: store.get('source')[items[this.staticDragData.startItem.itemIndex]] }));
2899
+ if (!stopDrag) {
2900
+ // todo: if move item out of group remove item from group
2901
+ const toMove = items.splice(this.staticDragData.startItem.itemIndex, 1);
2902
+ items.splice(newPosition.itemIndex, 0, ...toMove);
2903
+ store.set('items', items);
2904
+ }
2905
+ dispatch(this.revogrid, DRAG_END, this.dragData);
2906
+ }
2907
+ this.clearOrder();
2908
+ }
2909
+ clearLocalSubscriptions() {
2910
+ each(this.localSubscriptions, ({ target, callback }, key) => target.removeEventListener(key, callback));
2911
+ }
2912
+ clearOrder() {
2913
+ this.staticDragData = null;
2914
+ this.dragData = null;
2915
+ this.clearLocalSubscriptions();
2916
+ this.orderUi.stop();
2917
+ }
2918
+ /**
2919
+ * Clearing subscription
2920
+ */
2921
+ clearSubscriptions() {
2922
+ super.clearSubscriptions();
2923
+ this.clearLocalSubscriptions();
2924
+ }
2925
+ getData({ gridEl, dataEl, data, }) {
2926
+ const gridRect = gridEl.getBoundingClientRect();
2927
+ const elRect = dataEl.getBoundingClientRect();
2928
+ const scrollOffset = elRect.left - gridRect.left;
2929
+ return {
2930
+ elRect,
2931
+ gridRect,
2932
+ type: data.pin || 'rgCol',
2933
+ scrollOffset,
2934
+ };
2935
+ }
2936
+ getDimension(type) {
2937
+ return this.providers.dimension.stores[type].getCurrentState();
2938
+ }
2939
+ }
2940
+ function getLeftRelative(absoluteX, gridPos, offset) {
2941
+ return absoluteX - gridPos - offset;
2942
+ }
2943
+
2944
+ const revoGridStyleCss = ".revo-drag-icon{-webkit-mask-image:url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg viewBox='0 0 438 383' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg%3E%3Cpath d='M421.875,70.40625 C426.432292,70.40625 430.175781,68.9414062 433.105469,66.0117188 C436.035156,63.0820312 437.5,59.3385417 437.5,54.78125 L437.5,54.78125 L437.5,15.71875 C437.5,11.1614583 436.035156,7.41796875 433.105469,4.48828125 C430.175781,1.55859375 426.432292,0.09375 421.875,0.09375 L421.875,0.09375 L15.625,0.09375 C11.0677083,0.09375 7.32421875,1.55859375 4.39453125,4.48828125 C1.46484375,7.41796875 0,11.1614583 0,15.71875 L0,15.71875 L0,54.78125 C0,59.3385417 1.46484375,63.0820312 4.39453125,66.0117188 C7.32421875,68.9414062 11.0677083,70.40625 15.625,70.40625 L15.625,70.40625 L421.875,70.40625 Z M421.875,226.65625 C426.432292,226.65625 430.175781,225.191406 433.105469,222.261719 C436.035156,219.332031 437.5,215.588542 437.5,211.03125 L437.5,211.03125 L437.5,171.96875 C437.5,167.411458 436.035156,163.667969 433.105469,160.738281 C430.175781,157.808594 426.432292,156.34375 421.875,156.34375 L421.875,156.34375 L15.625,156.34375 C11.0677083,156.34375 7.32421875,157.808594 4.39453125,160.738281 C1.46484375,163.667969 0,167.411458 0,171.96875 L0,171.96875 L0,211.03125 C0,215.588542 1.46484375,219.332031 4.39453125,222.261719 C7.32421875,225.191406 11.0677083,226.65625 15.625,226.65625 L15.625,226.65625 L421.875,226.65625 Z M421.875,382.90625 C426.432292,382.90625 430.175781,381.441406 433.105469,378.511719 C436.035156,375.582031 437.5,371.838542 437.5,367.28125 L437.5,367.28125 L437.5,328.21875 C437.5,323.661458 436.035156,319.917969 433.105469,316.988281 C430.175781,314.058594 426.432292,312.59375 421.875,312.59375 L421.875,312.59375 L15.625,312.59375 C11.0677083,312.59375 7.32421875,314.058594 4.39453125,316.988281 C1.46484375,319.917969 0,323.661458 0,328.21875 L0,328.21875 L0,367.28125 C0,371.838542 1.46484375,375.582031 4.39453125,378.511719 C7.32421875,381.441406 11.0677083,382.90625 15.625,382.90625 L15.625,382.90625 L421.875,382.90625 Z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E\");mask-image:url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg viewBox='0 0 438 383' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg%3E%3Cpath d='M421.875,70.40625 C426.432292,70.40625 430.175781,68.9414062 433.105469,66.0117188 C436.035156,63.0820312 437.5,59.3385417 437.5,54.78125 L437.5,54.78125 L437.5,15.71875 C437.5,11.1614583 436.035156,7.41796875 433.105469,4.48828125 C430.175781,1.55859375 426.432292,0.09375 421.875,0.09375 L421.875,0.09375 L15.625,0.09375 C11.0677083,0.09375 7.32421875,1.55859375 4.39453125,4.48828125 C1.46484375,7.41796875 0,11.1614583 0,15.71875 L0,15.71875 L0,54.78125 C0,59.3385417 1.46484375,63.0820312 4.39453125,66.0117188 C7.32421875,68.9414062 11.0677083,70.40625 15.625,70.40625 L15.625,70.40625 L421.875,70.40625 Z M421.875,226.65625 C426.432292,226.65625 430.175781,225.191406 433.105469,222.261719 C436.035156,219.332031 437.5,215.588542 437.5,211.03125 L437.5,211.03125 L437.5,171.96875 C437.5,167.411458 436.035156,163.667969 433.105469,160.738281 C430.175781,157.808594 426.432292,156.34375 421.875,156.34375 L421.875,156.34375 L15.625,156.34375 C11.0677083,156.34375 7.32421875,157.808594 4.39453125,160.738281 C1.46484375,163.667969 0,167.411458 0,171.96875 L0,171.96875 L0,211.03125 C0,215.588542 1.46484375,219.332031 4.39453125,222.261719 C7.32421875,225.191406 11.0677083,226.65625 15.625,226.65625 L15.625,226.65625 L421.875,226.65625 Z M421.875,382.90625 C426.432292,382.90625 430.175781,381.441406 433.105469,378.511719 C436.035156,375.582031 437.5,371.838542 437.5,367.28125 L437.5,367.28125 L437.5,328.21875 C437.5,323.661458 436.035156,319.917969 433.105469,316.988281 C430.175781,314.058594 426.432292,312.59375 421.875,312.59375 L421.875,312.59375 L15.625,312.59375 C11.0677083,312.59375 7.32421875,314.058594 4.39453125,316.988281 C1.46484375,319.917969 0,323.661458 0,328.21875 L0,328.21875 L0,367.28125 C0,371.838542 1.46484375,375.582031 4.39453125,378.511719 C7.32421875,381.441406 11.0677083,382.90625 15.625,382.90625 L15.625,382.90625 L421.875,382.90625 Z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E\");width:11px;height:7px;background-size:cover;background-repeat:no-repeat}.revo-alt-icon{-webkit-mask-image:url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg viewBox='0 0 384 383' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg%3E%3Cpath d='M192.4375,383 C197.424479,383 201.663411,381.254557 205.154297,377.763672 L205.154297,377.763672 L264.25,318.667969 C270.234375,312.683594 271.605794,306.075846 268.364258,298.844727 C265.122721,291.613607 259.51237,287.998047 251.533203,287.998047 L251.533203,287.998047 L213.382812,287.998047 L213.382812,212.445312 L288.935547,212.445312 L288.935547,250.595703 C288.935547,258.57487 292.551107,264.185221 299.782227,267.426758 C307.013346,270.668294 313.621094,269.296875 319.605469,263.3125 L319.605469,263.3125 L378.701172,204.216797 C382.192057,200.725911 383.9375,196.486979 383.9375,191.5 C383.9375,186.513021 382.192057,182.274089 378.701172,178.783203 L378.701172,178.783203 L319.605469,119.6875 C313.621094,114.201823 307.013346,112.955078 299.782227,115.947266 C292.551107,118.939453 288.935547,124.42513 288.935547,132.404297 L288.935547,132.404297 L288.935547,170.554688 L213.382812,170.554688 L213.382812,95.0019531 L251.533203,95.0019531 C259.51237,95.0019531 264.998047,91.3863932 267.990234,84.1552734 C270.982422,76.9241536 269.735677,70.3164062 264.25,64.3320312 L264.25,64.3320312 L205.154297,5.23632812 C201.663411,1.74544271 197.424479,0 192.4375,0 C187.450521,0 183.211589,1.74544271 179.720703,5.23632812 L179.720703,5.23632812 L120.625,64.3320312 C114.640625,70.3164062 113.269206,76.9241536 116.510742,84.1552734 C119.752279,91.3863932 125.36263,95.0019531 133.341797,95.0019531 L133.341797,95.0019531 L171.492188,95.0019531 L171.492188,170.554688 L95.9394531,170.554688 L95.9394531,132.404297 C95.9394531,124.42513 92.3238932,118.814779 85.0927734,115.573242 C77.8616536,112.331706 71.2539062,113.703125 65.2695312,119.6875 L65.2695312,119.6875 L6.17382812,178.783203 C2.68294271,182.274089 0.9375,186.513021 0.9375,191.5 C0.9375,196.486979 2.68294271,200.725911 6.17382812,204.216797 L6.17382812,204.216797 L65.2695312,263.3125 C71.2539062,268.798177 77.8616536,270.044922 85.0927734,267.052734 C92.3238932,264.060547 95.9394531,258.57487 95.9394531,250.595703 L95.9394531,250.595703 L95.9394531,212.445312 L171.492188,212.445312 L171.492188,287.998047 L133.341797,287.998047 C125.36263,287.998047 119.876953,291.613607 116.884766,298.844727 C113.892578,306.075846 115.139323,312.683594 120.625,318.667969 L120.625,318.667969 L179.720703,377.763672 C183.211589,381.254557 187.450521,383 192.4375,383 Z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E\");mask-image:url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg viewBox='0 0 384 383' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg%3E%3Cpath d='M192.4375,383 C197.424479,383 201.663411,381.254557 205.154297,377.763672 L205.154297,377.763672 L264.25,318.667969 C270.234375,312.683594 271.605794,306.075846 268.364258,298.844727 C265.122721,291.613607 259.51237,287.998047 251.533203,287.998047 L251.533203,287.998047 L213.382812,287.998047 L213.382812,212.445312 L288.935547,212.445312 L288.935547,250.595703 C288.935547,258.57487 292.551107,264.185221 299.782227,267.426758 C307.013346,270.668294 313.621094,269.296875 319.605469,263.3125 L319.605469,263.3125 L378.701172,204.216797 C382.192057,200.725911 383.9375,196.486979 383.9375,191.5 C383.9375,186.513021 382.192057,182.274089 378.701172,178.783203 L378.701172,178.783203 L319.605469,119.6875 C313.621094,114.201823 307.013346,112.955078 299.782227,115.947266 C292.551107,118.939453 288.935547,124.42513 288.935547,132.404297 L288.935547,132.404297 L288.935547,170.554688 L213.382812,170.554688 L213.382812,95.0019531 L251.533203,95.0019531 C259.51237,95.0019531 264.998047,91.3863932 267.990234,84.1552734 C270.982422,76.9241536 269.735677,70.3164062 264.25,64.3320312 L264.25,64.3320312 L205.154297,5.23632812 C201.663411,1.74544271 197.424479,0 192.4375,0 C187.450521,0 183.211589,1.74544271 179.720703,5.23632812 L179.720703,5.23632812 L120.625,64.3320312 C114.640625,70.3164062 113.269206,76.9241536 116.510742,84.1552734 C119.752279,91.3863932 125.36263,95.0019531 133.341797,95.0019531 L133.341797,95.0019531 L171.492188,95.0019531 L171.492188,170.554688 L95.9394531,170.554688 L95.9394531,132.404297 C95.9394531,124.42513 92.3238932,118.814779 85.0927734,115.573242 C77.8616536,112.331706 71.2539062,113.703125 65.2695312,119.6875 L65.2695312,119.6875 L6.17382812,178.783203 C2.68294271,182.274089 0.9375,186.513021 0.9375,191.5 C0.9375,196.486979 2.68294271,200.725911 6.17382812,204.216797 L6.17382812,204.216797 L65.2695312,263.3125 C71.2539062,268.798177 77.8616536,270.044922 85.0927734,267.052734 C92.3238932,264.060547 95.9394531,258.57487 95.9394531,250.595703 L95.9394531,250.595703 L95.9394531,212.445312 L171.492188,212.445312 L171.492188,287.998047 L133.341797,287.998047 C125.36263,287.998047 119.876953,291.613607 116.884766,298.844727 C113.892578,306.075846 115.139323,312.683594 120.625,318.667969 L120.625,318.667969 L179.720703,377.763672 C183.211589,381.254557 187.450521,383 192.4375,383 Z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E\");width:11px;height:11px;background-size:cover;background-repeat:no-repeat}.arrow-down{position:absolute;right:5px;top:0}.arrow-down svg{width:8px;margin-top:5px;margin-left:5px;opacity:0.4}.cell-value-wrapper{margin-right:10px;overflow:hidden;text-overflow:ellipsis}.revo-button{position:relative;overflow:hidden;color:#fff;background-color:#6200ee;height:34px;line-height:34px;padding:0 15px;outline:0;border:0;border-radius:7px;box-sizing:border-box;cursor:pointer}.revo-button.green{background-color:#2ee072;border:1px solid #20d565}.revo-button.red{background-color:#E0662E;border:1px solid #d55920}.revo-button:disabled,.revo-button[disabled]{cursor:not-allowed !important;filter:opacity(0.35) !important}.revo-button.light{border:2px solid #cedefa;line-height:32px;background:none;color:#4876ca;box-shadow:none}revo-grid[theme=default]{font-size:12px}revo-grid[theme=default] revogr-header{text-align:center;line-height:30px;background-color:#f8f9fa}revo-grid[theme=default] revogr-header .group-rgRow{box-shadow:none}revo-grid[theme=default] revogr-header .header-rgRow,revo-grid[theme=default] revogr-header .group-rgRow{text-transform:uppercase;font-size:12px;color:#61656a}revo-grid[theme=default] revogr-header .header-rgRow{height:30px;box-shadow:0 -1px 0 0 #c0c0c0 inset}revo-grid[theme=default] revogr-header .rgHeaderCell{box-shadow:-1px 0 0 0 #c0c0c0, -1px 0 0 0 #c0c0c0 inset, 0 -1px 0 0 #c0c0c0, 0 -1px 0 0 #c0c0c0 inset}revo-grid[theme=default] revogr-header .rgHeaderCell.focused-cell{background:rgba(233, 234, 237, 0.5)}revo-grid[theme=default] .rowHeaders{background-color:#f8f9fa}revo-grid[theme=default] .rowHeaders revogr-data .rgCell{color:#61656a;box-shadow:0 -1px 0 0 #c0c0c0 inset, -1px 0 0 0 #c0c0c0 inset}revo-grid[theme=default] .rowHeaders revogr-header{box-shadow:0 -1px 0 0 #c0c0c0 inset, -1px 0 0 0 #c0c0c0 inset}revo-grid[theme=default] revogr-viewport-scroll.colPinStart revogr-data .rgRow .rgCell:last-child{box-shadow:0 -1px 0 0 #e2e3e3 inset, -1px 0 0 0 #c0c0c0 inset}revo-grid[theme=default] revogr-viewport-scroll.colPinStart .footer-wrapper revogr-data .rgRow:first-child .rgCell{box-shadow:0 1px 0 0 #c0c0c0 inset, -1px 0 0 0 #c0c0c0 inset}revo-grid[theme=default] revogr-viewport-scroll.colPinEnd,revo-grid[theme=default] revogr-viewport-scroll.colPinEnd revogr-header{box-shadow:1px 0 0 #c0c0c0 inset}revo-grid[theme=default] .footer-wrapper revogr-data .rgRow:first-child .rgCell{box-shadow:0 1px 0 0 #e2e3e3 inset, -1px 0 0 0 #e2e3e3 inset, 0 -1px 0 0 #e2e3e3 inset}revo-grid[theme=default] revogr-data{text-align:center}revo-grid[theme=default] revogr-data .rgRow{line-height:27px;box-shadow:0 -1px 0 0 #e2e3e3 inset, -1px 0 0 0 #e2e3e3 inset}revo-grid[theme=default] revogr-data .rgRow.focused-rgRow{background-color:rgba(233, 234, 237, 0.5)}revo-grid[theme=default] revogr-data .rgCell{box-shadow:0 -1px 0 0 #e2e3e3 inset, -1px 0 0 0 #e2e3e3 inset}revo-grid[theme=default] revogr-data .rgCell.disabled{background-color:0 -1px 0 0 #e2e3e3 inset, -1px 0 0 0 #e2e3e3 inset}revo-grid[theme=material]{font-family:Nunito, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}revo-grid[theme=material] revogr-header{line-height:50px;font-weight:600;text-align:left}revo-grid[theme=material] revogr-header .rgHeaderCell{padding:0 15px;text-overflow:ellipsis}revo-grid[theme=material] revogr-header .header-rgRow{height:50px}revo-grid[theme=material] revogr-data{text-align:left}revo-grid[theme=material] revogr-data .rgRow{line-height:42px}revo-grid[theme=material] revogr-data .rgCell{padding:0 15px}revo-grid[theme=material] .viewports{width:100%}revo-grid[theme=material] .rowHeaders{background-color:#f7faff}revo-grid[theme=material] .rowHeaders revogr-data .rgCell{color:#757a82}revo-grid[theme=material] revogr-header .header-rgRow.group{box-shadow:0 -1px 0 0 #f1f1f1 inset}revo-grid[theme=material] revogr-header .header-rgRow:not(.group){box-shadow:0 -1px 0 0 #f1f1f1, 0 -1px 0 0 #f1f1f1 inset}revo-grid[theme=material] revogr-header .rgHeaderCell.sortable:hover{background-color:#f1f1f1}revo-grid[theme=material] revogr-header .rgHeaderCell.focused-cell{background:rgba(233, 234, 237, 0.5)}revo-grid[theme=material] .footer-wrapper revogr-data{box-shadow:0 -1px 0 #f1f1f1}revo-grid[theme=material] revogr-viewport-scroll.colPinStart{box-shadow:-1px 0 0 #f1f1f1 inset}revo-grid[theme=material] revogr-viewport-scroll.colPinEnd{box-shadow:-1px 0 0 #f1f1f1}revo-grid[theme=material] revogr-data .rgRow{box-shadow:0 -1px 0 0 #f1f1f1 inset}revo-grid[theme=material] revogr-data .rgRow.focused-rgRow{background-color:rgba(233, 234, 237, 0.5)}revo-grid[theme=material] revogr-data .rgCell{color:rgba(0, 0, 0, 0.87)}revo-grid[theme=material] revogr-data .rgCell.disabled{background-color:#f7f7f7}revo-grid[theme=material] revogr-data .revo-draggable>.revo-drag-icon{background-color:#d4d4d4}revo-grid[theme=material] revogr-data .revo-draggable:hover>.revo-drag-icon{background-color:black}revo-grid[theme=darkMaterial]{font-family:Nunito, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";color:#d8d8d8}revo-grid[theme=darkMaterial] revogr-header{line-height:50px;font-weight:600;text-align:left}revo-grid[theme=darkMaterial] revogr-header .rgHeaderCell{padding:0 15px;text-overflow:ellipsis}revo-grid[theme=darkMaterial] revogr-header .header-rgRow{height:50px}revo-grid[theme=darkMaterial] revogr-data{text-align:left}revo-grid[theme=darkMaterial] revogr-data .rgRow{line-height:42px}revo-grid[theme=darkMaterial] revogr-data .rgCell{padding:0 15px}revo-grid[theme=darkMaterial] .viewports{width:100%}revo-grid[theme=darkMaterial] .rowHeaders{background-color:rgba(40, 39, 43, 0.8)}revo-grid[theme=darkMaterial] .rowHeaders revogr-data .rgCell{color:rgba(216, 216, 216, 0.8)}revo-grid[theme=darkMaterial] revogr-header .header-rgRow.group{box-shadow:0 -1px 0 0 #404040 inset}revo-grid[theme=darkMaterial] revogr-header .header-rgRow:not(.group){box-shadow:0 -1px 0 0 #404040, 0 -1px 0 0 #404040 inset}revo-grid[theme=darkMaterial] revogr-header .rgHeaderCell.sortable:hover{background-color:rgba(64, 64, 64, 0.5)}revo-grid[theme=darkMaterial] revogr-header .rgHeaderCell.focused-cell{background:rgba(115, 148, 160, 0.15)}revo-grid[theme=darkMaterial] .footer-wrapper revogr-data{box-shadow:0 -1px 0 #404040}revo-grid[theme=darkMaterial] revogr-data .rgCell{color:rgba(216, 216, 216, 0.9)}revo-grid[theme=darkMaterial] revogr-data .rgRow{box-shadow:0 -1px 0 0 #404040 inset}revo-grid[theme=darkMaterial] revogr-data .rgRow.focused-rgRow{background-color:rgba(115, 148, 160, 0.15)}revo-grid[theme=darkMaterial] revogr-data .revo-draggable>.revo-drag-icon{background-color:rgba(216, 216, 216, 0.5)}revo-grid[theme=darkMaterial] revogr-data .revo-draggable:hover>.revo-drag-icon{background-color:rgba(216, 216, 216, 0.7)}revo-grid[theme=darkMaterial] revogr-viewport-scroll.colPinStart{box-shadow:-1px 0 0 #404040 inset}revo-grid[theme=darkMaterial] revogr-viewport-scroll.colPinEnd{box-shadow:-1px 0 0 #404040}revo-grid[theme=darkCompact]{font-family:Nunito, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";color:#d8d8d8}revo-grid[theme=darkCompact] revogr-header{line-height:45px;font-weight:600;text-align:left}revo-grid[theme=darkCompact] revogr-header .rgHeaderCell{padding:0 15px;text-overflow:ellipsis}revo-grid[theme=darkCompact] revogr-header .header-rgRow{height:45px}revo-grid[theme=darkCompact] revogr-data{text-align:left}revo-grid[theme=darkCompact] revogr-data .rgRow{line-height:32px}revo-grid[theme=darkCompact] revogr-data .rgCell{padding:0 15px}revo-grid[theme=darkCompact] .viewports{width:100%}revo-grid[theme=darkCompact] .rowHeaders{background-color:rgba(40, 39, 43, 0.8)}revo-grid[theme=darkCompact] .rowHeaders revogr-data .rgCell{color:rgba(216, 216, 216, 0.8)}revo-grid[theme=darkCompact] revogr-header .header-rgRow.group{box-shadow:0 -1px 0 0 #404040 inset}revo-grid[theme=darkCompact] revogr-header .header-rgRow:not(.group){box-shadow:0 -1px 0 0 #404040, 0 -1px 0 0 #404040 inset}revo-grid[theme=darkCompact] revogr-header .rgHeaderCell.sortable:hover{background-color:rgba(64, 64, 64, 0.5)}revo-grid[theme=darkCompact] revogr-header .rgHeaderCell.focused-cell{background:rgba(115, 148, 160, 0.15)}revo-grid[theme=darkCompact] .footer-wrapper revogr-data{box-shadow:0 -1px 0 #404040}revo-grid[theme=darkCompact] revogr-data .rgCell{color:rgba(216, 216, 216, 0.9)}revo-grid[theme=darkCompact] revogr-data .rgRow{box-shadow:0 -1px 0 0 #404040 inset}revo-grid[theme=darkCompact] revogr-data .rgRow.focused-rgRow{background-color:rgba(115, 148, 160, 0.15)}revo-grid[theme=darkCompact] revogr-data .revo-draggable>.revo-drag-icon{background-color:rgba(216, 216, 216, 0.5)}revo-grid[theme=darkCompact] revogr-data .revo-draggable:hover>.revo-drag-icon{background-color:rgba(216, 216, 216, 0.7)}revo-grid[theme=darkCompact] revogr-viewport-scroll.colPinStart{box-shadow:-1px 0 0 #404040 inset}revo-grid[theme=darkCompact] revogr-viewport-scroll.colPinEnd{box-shadow:-1px 0 0 #404040}revo-grid[theme=compact]{font-family:Nunito, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}revo-grid[theme=compact] revogr-header{line-height:45px;font-weight:600;text-align:left}revo-grid[theme=compact] revogr-header .rgHeaderCell{padding:0 15px;text-overflow:ellipsis}revo-grid[theme=compact] revogr-header .header-rgRow{height:45px}revo-grid[theme=compact] revogr-data{text-align:left}revo-grid[theme=compact] revogr-data .rgRow{line-height:32px}revo-grid[theme=compact] revogr-data .rgCell{padding:0 15px}revo-grid[theme=compact] .viewports{width:100%}revo-grid[theme=compact] .rowHeaders{background-color:#f7faff}revo-grid[theme=compact] .rowHeaders revogr-data .rgCell{color:#757a82}revo-grid[theme=compact] revogr-header .header-rgRow.group{box-shadow:0 -1px 0 0 #f1f1f1 inset}revo-grid[theme=compact] revogr-header .header-rgRow:not(.group){box-shadow:0 -1px 0 0 #f1f1f1, 0 -1px 0 0 #f1f1f1 inset}revo-grid[theme=compact] revogr-header .rgHeaderCell.sortable:hover{background-color:#f1f1f1}revo-grid[theme=compact] revogr-header .rgHeaderCell.focused-cell{background:rgba(233, 234, 237, 0.5)}revo-grid[theme=compact] .footer-wrapper revogr-data{box-shadow:0 -1px 0 #f1f1f1}revo-grid[theme=compact] revogr-viewport-scroll.colPinStart{box-shadow:-1px 0 0 #f1f1f1 inset}revo-grid[theme=compact] revogr-viewport-scroll.colPinEnd{box-shadow:-1px 0 0 #f1f1f1}revo-grid[theme=compact] revogr-data .rgRow{box-shadow:0 -1px 0 0 #f1f1f1 inset}revo-grid[theme=compact] revogr-data .rgRow.focused-rgRow{background-color:rgba(233, 234, 237, 0.5)}revo-grid[theme=compact] revogr-data .rgCell{color:rgba(0, 0, 0, 0.87)}revo-grid[theme=compact] revogr-data .rgCell.disabled{background-color:#f7f7f7}revo-grid[theme=compact] revogr-data .revo-draggable>.revo-drag-icon{background-color:#d4d4d4}revo-grid[theme=compact] revogr-data .revo-draggable:hover>.revo-drag-icon{background-color:black}revo-grid[theme=compact] revo-dropdown .rv-dr-root{padding:0px 9px}revo-grid{display:block;height:100%;font-family:Helvetica, Arial, Sans-Serif, serif;font-size:14px;position:relative;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;display:flex;flex-direction:column;width:100%;height:100%}revo-grid .footer-wrapper,revo-grid .header-wrapper{width:100%}revo-grid .footer-wrapper revogr-data,revo-grid .header-wrapper revogr-data{z-index:3}revo-grid revo-dropdown{width:100%}revo-grid revo-dropdown .rv-dr-root{max-height:100%}revo-grid revo-dropdown.shrink label{opacity:0}revo-grid .viewports{max-height:100%;display:flex;flex-direction:row;align-items:flex-start;max-width:100%}revo-grid .main-viewport{flex-grow:1;height:0;display:flex;flex-direction:row}revo-grid .draggable{position:fixed;height:30px;line-height:30px;background:#fff;border-radius:3px;display:block;z-index:100;margin-top:5px;margin-right:-20px;box-shadow:0 4px 20px 0 rgba(0, 0, 0, 0.15);padding-left:20px;padding-right:5px}revo-grid .draggable.hidden{display:none}revo-grid .draggable .revo-alt-icon{background-color:black;position:absolute;left:5px;top:10px}revo-grid .draggable-wrapper.hidden{display:none}revo-grid .drag-position{position:absolute;left:0;right:0;height:1px;z-index:2;background:gray}revo-grid .drag-position-y{position:absolute;top:0;left:0;bottom:0;width:1px;z-index:2;background:gray}revo-grid .drag-auto-scroll-y{pointer-events:none;position:absolute;left:0;top:0;height:50px;width:1px}revo-grid .clipboard{position:absolute;left:0;top:0}revo-grid revogr-scroll-virtual{position:relative}revo-grid revogr-scroll-virtual.vertical,revo-grid revogr-scroll-virtual.horizontal{z-index:3}";
2945
+
2946
+ const RevoGridComponent = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
2947
+ constructor() {
2948
+ super();
2949
+ this.__registerHost();
2950
+ this.beforeedit = createEvent(this, "beforeedit", 7);
2951
+ this.beforerangeedit = createEvent(this, "beforerangeedit", 7);
2952
+ this.afteredit = createEvent(this, "afteredit", 7);
2953
+ this.beforeautofill = createEvent(this, "beforeautofill", 7);
2954
+ this.beforeaange = createEvent(this, "beforeaange", 7);
2955
+ this.afterfocus = createEvent(this, "afterfocus", 7);
2956
+ this.roworderchanged = createEvent(this, "roworderchanged", 7);
2957
+ this.beforesourcesortingapply = createEvent(this, "beforesourcesortingapply", 7);
2958
+ this.beforesortingapply = createEvent(this, "beforesortingapply", 7);
2959
+ this.beforesorting = createEvent(this, "beforesorting", 7);
2960
+ this.rowdragstart = createEvent(this, "rowdragstart", 7);
2961
+ this.headerclick = createEvent(this, "headerclick", 7);
2962
+ this.beforecellfocus = createEvent(this, "beforecellfocus", 7);
2963
+ this.beforefocuslost = createEvent(this, "beforefocuslost", 7);
2964
+ this.beforesourceset = createEvent(this, "beforesourceset", 7);
2965
+ this.aftersourceset = createEvent(this, "aftersourceset", 7);
2966
+ this.beforecolumnsset = createEvent(this, "beforecolumnsset", 7);
2967
+ this.beforecolumnapplied = createEvent(this, "beforecolumnapplied", 7);
2968
+ this.aftercolumnsset = createEvent(this, "aftercolumnsset", 7);
2969
+ this.beforefilterapply = createEvent(this, "beforefilterapply", 7);
2970
+ this.beforefiltertrimmed = createEvent(this, "beforefiltertrimmed", 7);
2971
+ this.beforetrimmed = createEvent(this, "beforetrimmed", 7);
2972
+ this.aftertrimmed = createEvent(this, "aftertrimmed", 7);
2973
+ this.viewportscroll = createEvent(this, "viewportscroll", 7);
2974
+ this.beforeexport = createEvent(this, "beforeexport", 7);
2975
+ this.beforeeditstart = createEvent(this, "beforeeditstart", 7);
2976
+ this.aftercolumnresize = createEvent(this, "aftercolumnresize", 7);
2977
+ /**
2978
+ * Defines how many rows/columns should be rendered outside visible area.
2979
+ */
2980
+ this.frameSize = 1;
2981
+ /**
2982
+ * Indicates default rgRow size.
2983
+ * By default 0, means theme package size will be applied
2984
+ */
2985
+ this.rowSize = 0;
2986
+ /** Indicates default column size. */
2987
+ this.colSize = 100;
2988
+ /** When true, user can range selection. */
2989
+ this.range = false;
2990
+ /** When true, grid in read only mode. */
2991
+ this.readonly = false;
2992
+ /** When true, columns are resizable. */
2993
+ this.resize = false;
2994
+ /** When true cell focus appear. */
2995
+ this.canFocus = true;
2996
+ /** When true enable clipboard. */
2997
+ this.useClipboard = true;
2998
+ /**
2999
+ * Columns - defines an array of grid columns.
3000
+ * Can be column or grouped column.
3001
+ */
3002
+ this.columns = [];
3003
+ /**
3004
+ * Source - defines main data source.
3005
+ * Can be an Object or 2 dimensional array([][]);
3006
+ * Keys/indexes referenced from columns Prop
3007
+ */
3008
+ this.source = [];
3009
+ /** Pinned top Source: {[T in ColumnProp]: any} - defines pinned top rows data source. */
3010
+ this.pinnedTopSource = [];
3011
+ /** Pinned bottom Source: {[T in ColumnProp]: any} - defines pinned bottom rows data source. */
3012
+ this.pinnedBottomSource = [];
3013
+ /** Row properies applied */
3014
+ this.rowDefinitions = [];
3015
+ /** Custom editors register */
3016
+ this.editors = {};
3017
+ /** Types
3018
+ * Every type represent multiple column properties
3019
+ * Types will be merged but can be replaced with column properties
3020
+ */
3021
+ this.columnTypes = {};
3022
+ /** Theme name */
3023
+ this.theme = 'default';
3024
+ /**
3025
+ * Row class property
3026
+ * Define this property in rgRow object and this will be mapped as rgRow class
3027
+ */
3028
+ this.rowClass = '';
3029
+ /**
3030
+ * Autosize config
3031
+ * Enable columns autoSize, for more details check @autoSizeColumn plugin
3032
+ * By default disabled, hence operation is not resource efficient
3033
+ * true to enable with default params (double header separator click for autosize)
3034
+ * or provide config
3035
+ */
3036
+ this.autoSizeColumn = false;
3037
+ /**
3038
+ * Enables filter plugin
3039
+ * Can be boolean
3040
+ * Can be filter collection
3041
+ */
3042
+ this.filter = false;
3043
+ /**
3044
+ * Enables column move plugin
3045
+ * Can be boolean
3046
+ */
3047
+ this.canMoveColumns = false;
3048
+ /**
3049
+ * Trimmed rows
3050
+ * Functionality which allows to hide rows from main data set
3051
+ * @trimmedRows are physical rgRow indexes to hide
3052
+ */
3053
+ this.trimmedRows = {};
3054
+ /**
3055
+ * Enables export plugin
3056
+ * Can be boolean
3057
+ * Can be export options
3058
+ */
3059
+ this.exporting = false;
3060
+ /**
3061
+ * Defines stretch strategy for columns with @StretchColumn plugin
3062
+ * if there are more space on the right last column size would be increased
3063
+ */
3064
+ this.stretch = true;
3065
+ // --------------------------------------------------------------------------
3066
+ //
3067
+ // Private Properties
3068
+ //
3069
+ // --------------------------------------------------------------------------
3070
+ // for internal plugin usage
3071
+ this.extraElements = [];
3072
+ this.uuid = null;
3073
+ this.viewport = null;
3074
+ /**
3075
+ * Plugins
3076
+ * Define plugins collection
3077
+ */
3078
+ this.internalPlugins = [];
3079
+ this.subscribers = {};
3080
+ }
3081
+ // --------------------------------------------------------------------------
3082
+ //
3083
+ // Methods
3084
+ //
3085
+ // --------------------------------------------------------------------------
3086
+ /**
3087
+ * Refreshes data viewport.
3088
+ * Can be specific part as rgRow or pinned rgRow or 'all' by default.
3089
+ */
3090
+ async refresh(type = 'all') {
3091
+ this.dataProvider.refresh(type);
3092
+ }
3093
+ /** Scrolls view port to specified rgRow index */
3094
+ async scrollToRow(coordinate = 0) {
3095
+ const y = this.dimensionProvider.getViewPortPos({
3096
+ coordinate,
3097
+ dimension: 'rgRow',
3098
+ });
3099
+ await this.scrollToCoordinate({ y });
3100
+ }
3101
+ /** Scrolls view port to specified column index */
3102
+ async scrollToColumnIndex(coordinate = 0) {
3103
+ const x = this.dimensionProvider.getViewPortPos({
3104
+ coordinate,
3105
+ dimension: 'rgCol',
3106
+ });
3107
+ await this.scrollToCoordinate({ x });
3108
+ }
3109
+ /** Scrolls view port to specified column prop */
3110
+ async scrollToColumnProp(prop) {
3111
+ const coordinate = this.columnProvider.getColumnIndexByProp(prop, 'rgCol');
3112
+ if (coordinate < 0) {
3113
+ // already on the screen
3114
+ return;
3115
+ }
3116
+ const x = this.dimensionProvider.getViewPortPos({
3117
+ coordinate,
3118
+ dimension: 'rgCol',
3119
+ });
3120
+ await this.scrollToCoordinate({ x });
3121
+ }
3122
+ /** Update columns */
3123
+ async updateColumns(cols) {
3124
+ this.columnProvider.updateColumns(cols);
3125
+ }
3126
+ /** Add trimmed by type */
3127
+ async addTrimmed(trimmed, trimmedType = 'external', type = 'rgRow') {
3128
+ const event = this.beforetrimmed.emit({
3129
+ trimmed,
3130
+ trimmedType,
3131
+ type,
3132
+ });
3133
+ if (event.defaultPrevented) {
3134
+ return event;
3135
+ }
3136
+ this.dataProvider.setTrimmed({ [trimmedType]: event.detail.trimmed }, type);
3137
+ this.aftertrimmed.emit();
3138
+ return event;
3139
+ }
3140
+ /** Scrolls view port to coordinate */
3141
+ async scrollToCoordinate(cell) {
3142
+ var _a;
3143
+ (_a = this.viewport) === null || _a === void 0 ? void 0 : _a.scrollToCell(cell);
3144
+ }
3145
+ /** Bring cell to edit mode */
3146
+ async setCellEdit(rgRow, prop, rowSource = 'rgRow') {
3147
+ var _a;
3148
+ const rgCol = ColumnDataProvider.getColumnByProp(this.columns, prop);
3149
+ if (!rgCol) {
3150
+ return;
3151
+ }
3152
+ await timeout();
3153
+ (_a = this.viewport) === null || _a === void 0 ? void 0 : _a.setEdit(rgRow, this.columnProvider.getColumnIndexByProp(prop, 'rgCol'), rgCol.pin || 'rgCol', rowSource);
3154
+ }
3155
+ /**
3156
+ * Register new virtual node inside of grid
3157
+ * Used for additional items creation such as plugin elements
3158
+ */
3159
+ async registerVNode(elements) {
3160
+ this.extraElements.push(...elements);
3161
+ this.extraElements = [...this.extraElements];
3162
+ }
3163
+ /** Get data from source */
3164
+ async getSource(type = 'rgRow') {
3165
+ return this.dataProvider.stores[type].store.get('source');
3166
+ }
3167
+ /**
3168
+ * Get data from visible part of source
3169
+ * Trimmed/filtered rows will be excluded
3170
+ * @param type - type of source
3171
+ */
3172
+ async getVisibleSource(type = 'rgRow') {
3173
+ return getVisibleSourceItem(this.dataProvider.stores[type].store);
3174
+ }
3175
+ /**
3176
+ * Provides access to rows internal store observer
3177
+ * Can be used for plugin support
3178
+ * @param type - type of source
3179
+ */
3180
+ async getSourceStore(type = 'rgRow') {
3181
+ return this.dataProvider.stores[type].store;
3182
+ }
3183
+ /**
3184
+ * Provides access to column internal store observer
3185
+ * Can be used for plugin support
3186
+ * @param type - type of column
3187
+ */
3188
+ async getColumnStore(type = 'rgCol') {
3189
+ return this.columnProvider.stores[type].store;
3190
+ }
3191
+ /**
3192
+ * Update column sorting
3193
+ * @param column - full column details to update
3194
+ * @param index - virtual column index
3195
+ * @param order - order to apply
3196
+ */
3197
+ async updateColumnSorting(column, index, order, additive) {
3198
+ return this.columnProvider.updateColumnSorting(column, index, order, additive);
3199
+ }
3200
+ /**
3201
+ * Clears column sorting
3202
+ */
3203
+ async clearSorting() {
3204
+ this.columnProvider.clearSorting();
3205
+ }
3206
+ /**
3207
+ * Receive all columns in data source
3208
+ */
3209
+ async getColumns() {
3210
+ return this.columnProvider.getColumns();
3211
+ }
3212
+ /**
3213
+ * Clear current grid focus
3214
+ */
3215
+ async clearFocus() {
3216
+ var _a;
3217
+ const focused = await this.getFocused();
3218
+ const event = this.beforefocuslost.emit(focused);
3219
+ if (event.defaultPrevented) {
3220
+ return;
3221
+ }
3222
+ this.selectionStoreConnector.clearAll();
3223
+ (_a = this.viewport) === null || _a === void 0 ? void 0 : _a.clearFocused();
3224
+ }
3225
+ /**
3226
+ * Get all active plugins instances
3227
+ */
3228
+ async getPlugins() {
3229
+ return [...this.internalPlugins];
3230
+ }
3231
+ /**
3232
+ * Get the currently focused cell.
3233
+ */
3234
+ async getFocused() {
3235
+ var _a;
3236
+ return (_a = this.viewport) === null || _a === void 0 ? void 0 : _a.getFocused();
3237
+ }
3238
+ /**
3239
+ * Get the currently selected Range.
3240
+ */
3241
+ async getSelectedRange() {
3242
+ var _a;
3243
+ return (_a = this.viewport) === null || _a === void 0 ? void 0 : _a.getSelectedRange();
3244
+ }
3245
+ // --------------------------------------------------------------------------
3246
+ //
3247
+ // Listeners outside scope
3248
+ //
3249
+ // --------------------------------------------------------------------------
3250
+ /** Clear data which is outside of grid container */
3251
+ handleOutsideClick({ target }) {
3252
+ if (!(target === null || target === void 0 ? void 0 : target.closest(`[${UUID}="${this.uuid}"]`))) {
3253
+ this.clearFocus();
3254
+ }
3255
+ }
3256
+ // --------------------------------------------------------------------------
3257
+ //
3258
+ // Listeners
3259
+ //
3260
+ // --------------------------------------------------------------------------
3261
+ /** DRAG AND DROP */
3262
+ onRowDragStarted(e) {
3263
+ var _a;
3264
+ e.cancelBubble = true;
3265
+ const dragStart = this.rowdragstart.emit(e.detail);
3266
+ if (dragStart.defaultPrevented) {
3267
+ e.preventDefault();
3268
+ return;
3269
+ }
3270
+ (_a = this.orderService) === null || _a === void 0 ? void 0 : _a.start(this.element, Object.assign(Object.assign({}, e.detail), dragStart.detail));
3271
+ }
3272
+ onRowDragEnd() {
3273
+ var _a;
3274
+ (_a = this.orderService) === null || _a === void 0 ? void 0 : _a.end();
3275
+ }
3276
+ onRowDrag({ detail }) {
3277
+ var _a;
3278
+ (_a = this.orderService) === null || _a === void 0 ? void 0 : _a.move(detail);
3279
+ }
3280
+ onRowMouseMove(e) {
3281
+ var _a;
3282
+ e.cancelBubble = true;
3283
+ (_a = this.orderService) === null || _a === void 0 ? void 0 : _a.moveTip(e.detail);
3284
+ }
3285
+ async onBeforeEdit(e) {
3286
+ e.cancelBubble = true;
3287
+ const { defaultPrevented, detail } = this.beforeedit.emit(e.detail);
3288
+ await timeout();
3289
+ // apply data
3290
+ if (!defaultPrevented) {
3291
+ this.dataProvider.setCellData(detail);
3292
+ this.afteredit.emit(detail);
3293
+ }
3294
+ }
3295
+ onBeforeRangeEdit(e) {
3296
+ e.cancelBubble = true;
3297
+ const { defaultPrevented } = this.beforerangeedit.emit(e.detail);
3298
+ if (defaultPrevented) {
3299
+ e.preventDefault();
3300
+ return;
3301
+ }
3302
+ this.afteredit.emit(e.detail);
3303
+ }
3304
+ onRangeChanged(e) {
3305
+ e.cancelBubble = true;
3306
+ const beforeaange = this.beforeaange.emit(e.detail);
3307
+ if (beforeaange.defaultPrevented) {
3308
+ e.preventDefault();
3309
+ }
3310
+ const beforeFill = this.beforeautofill.emit(e.detail);
3311
+ if (beforeFill.defaultPrevented) {
3312
+ return;
3313
+ }
3314
+ }
3315
+ onRowDropped(e) {
3316
+ e.cancelBubble = true;
3317
+ const { defaultPrevented } = this.roworderchanged.emit(e.detail);
3318
+ if (defaultPrevented) {
3319
+ e.preventDefault();
3320
+ }
3321
+ }
3322
+ onHeaderClick(e) {
3323
+ const { defaultPrevented } = this.headerclick.emit(Object.assign(Object.assign({}, e.detail.column), { originalEvent: e.detail.originalEvent }));
3324
+ if (defaultPrevented) {
3325
+ e.preventDefault();
3326
+ }
3327
+ }
3328
+ onCellFocus(e) {
3329
+ e.cancelBubble = true;
3330
+ const { defaultPrevented } = this.beforecellfocus.emit(e.detail);
3331
+ if (!this.canFocus || defaultPrevented) {
3332
+ e.preventDefault();
3333
+ }
3334
+ }
3335
+ columnChanged(newVal = []) {
3336
+ this.dimensionProvider.drop();
3337
+ const columnGather = ColumnDataProvider.getColumns(newVal, 0, this.columnTypes);
3338
+ this.beforecolumnsset.emit(columnGather);
3339
+ for (let type of columnTypes) {
3340
+ const items = columnGather.columns[type];
3341
+ this.dimensionProvider.setRealSize(items.length, type);
3342
+ this.dimensionProvider.setColumns(type, ColumnDataProvider.getSizes(items), type !== 'rgCol');
3343
+ }
3344
+ this.beforecolumnapplied.emit(columnGather);
3345
+ const columns = this.columnProvider.setColumns(columnGather);
3346
+ this.aftercolumnsset.emit({
3347
+ columns,
3348
+ order: this.columnProvider.order,
3349
+ });
3350
+ }
3351
+ themeChanged(t) {
3352
+ this.themeService.register(t);
3353
+ this.dimensionProvider.setSettings({ originItemSize: this.themeService.rowSize, frameOffset: this.frameSize || 0 }, 'rgRow');
3354
+ this.dimensionProvider.setSettings({ originItemSize: this.colSize, frameOffset: this.frameSize || 0 }, 'rgCol');
3355
+ }
3356
+ dataChanged(source = []) {
3357
+ let newSource = [...source];
3358
+ const beforesourceset = this.beforesourceset.emit({
3359
+ type: 'rgRow',
3360
+ source: newSource,
3361
+ });
3362
+ newSource = beforesourceset.detail.source;
3363
+ newSource = this.dataProvider.setData(newSource, 'rgRow');
3364
+ this.aftersourceset.emit({
3365
+ type: 'rgRow',
3366
+ source: newSource,
3367
+ });
3368
+ }
3369
+ dataBottomChanged(newVal = []) {
3370
+ this.dataProvider.setData(newVal, 'rowPinEnd');
3371
+ }
3372
+ dataTopChanged(newVal = []) {
3373
+ this.dataProvider.setData(newVal, 'rowPinStart');
3374
+ }
3375
+ rowDefChanged(newVal = []) {
3376
+ if (!newVal.length) {
3377
+ return;
3378
+ }
3379
+ const rows = reduce_1(newVal, (r, v) => {
3380
+ if (!r[v.type]) {
3381
+ r[v.type] = {};
3382
+ }
3383
+ if (v.size) {
3384
+ if (!r[v.type].sizes) {
3385
+ r[v.type].sizes = {};
3386
+ }
3387
+ r[v.type].sizes[v.index] = v.size;
3388
+ }
3389
+ return r;
3390
+ }, {});
3391
+ each(rows, (r, k) => {
3392
+ if (r.sizes) {
3393
+ this.dimensionProvider.setDimensionSize(k, r.sizes);
3394
+ }
3395
+ });
3396
+ }
3397
+ trimmedRowsChanged(newVal = {}) {
3398
+ this.addTrimmed(newVal);
3399
+ }
3400
+ groupingChanged(newVal = {}) {
3401
+ let grPlugin;
3402
+ for (let p of this.internalPlugins) {
3403
+ const isGrouping = p;
3404
+ if (isGrouping.setGrouping) {
3405
+ grPlugin = isGrouping;
3406
+ break;
3407
+ }
3408
+ }
3409
+ if (!grPlugin) {
3410
+ return;
3411
+ }
3412
+ grPlugin.setGrouping(newVal || {});
3413
+ }
3414
+ applyStretch(isStretch) {
3415
+ if (isStretch === 'false') {
3416
+ isStretch = false;
3417
+ }
3418
+ let stretch = this.internalPlugins.filter(p => isStretchPlugin(p))[0];
3419
+ if (isStretch) {
3420
+ if (!stretch) {
3421
+ this.internalPlugins.push(new StretchColumn(this.element, this.dimensionProvider));
3422
+ }
3423
+ else {
3424
+ stretch.applyStretch(this.columnProvider.getRawColumns());
3425
+ }
3426
+ }
3427
+ else if (stretch) {
3428
+ const index = this.internalPlugins.indexOf(stretch);
3429
+ this.internalPlugins.splice(index, 1);
3430
+ }
3431
+ }
3432
+ connectedCallback() {
3433
+ this.viewportProvider = new ViewportProvider();
3434
+ this.themeService = new ThemeService({
3435
+ rowSize: this.rowSize,
3436
+ });
3437
+ this.dimensionProvider = new DimensionProvider(this.viewportProvider);
3438
+ this.columnProvider = new ColumnDataProvider();
3439
+ this.dataProvider = new DataProvider(this.dimensionProvider);
3440
+ this.uuid = `${new Date().getTime()}-rvgrid`;
3441
+ const pluginData = {
3442
+ data: this.dataProvider,
3443
+ column: this.columnProvider,
3444
+ dimension: this.dimensionProvider,
3445
+ viewport: this.viewportProvider,
3446
+ selection: this.selectionStoreConnector,
3447
+ };
3448
+ if (this.autoSizeColumn) {
3449
+ this.internalPlugins.push(new AutoSizeColumn(this.element, {
3450
+ dataProvider: this.dataProvider,
3451
+ columnProvider: this.columnProvider,
3452
+ dimensionProvider: this.dimensionProvider,
3453
+ }, typeof this.autoSizeColumn === 'object' ? this.autoSizeColumn : undefined));
3454
+ }
3455
+ if (this.filter) {
3456
+ this.internalPlugins.push(new FilterPlugin(this.element, this.uuid, typeof this.filter === 'object' ? this.filter : undefined));
3457
+ }
3458
+ if (this.exporting) {
3459
+ this.internalPlugins.push(new ExportFilePlugin(this.element));
3460
+ }
3461
+ this.internalPlugins.push(new SortingPlugin(this.element));
3462
+ if (this.plugins) {
3463
+ this.plugins.forEach(p => {
3464
+ this.internalPlugins.push(new p(this.element, pluginData));
3465
+ });
3466
+ }
3467
+ if (this.canMoveColumns) {
3468
+ this.internalPlugins.push(new ColumnPlugin(this.element, pluginData));
3469
+ }
3470
+ this.internalPlugins.push(new GroupingRowPlugin(this.element, {
3471
+ dataProvider: this.dataProvider,
3472
+ columnProvider: this.columnProvider,
3473
+ }));
3474
+ this.applyStretch(this.stretch);
3475
+ this.themeChanged(this.theme);
3476
+ this.columnChanged(this.columns);
3477
+ this.dataChanged(this.source);
3478
+ this.dataTopChanged(this.pinnedTopSource);
3479
+ this.dataBottomChanged(this.pinnedBottomSource);
3480
+ this.trimmedRowsChanged(this.trimmedRows);
3481
+ this.rowDefChanged(this.rowDefinitions);
3482
+ this.groupingChanged(this.grouping);
3483
+ this.selectionStoreConnector = new SelectionStoreConnector();
3484
+ this.scrollingService = new GridScrollingService((e) => {
3485
+ this.dimensionProvider.setViewPortCoordinate({
3486
+ coordinate: e.coordinate,
3487
+ type: e.dimension,
3488
+ });
3489
+ this.viewportscroll.emit(e);
3490
+ });
3491
+ this.subscribers = { 'click': this.handleOutsideClick.bind(this) };
3492
+ for (let type in this.subscribers) {
3493
+ document.addEventListener(type, this.subscribers[type]);
3494
+ }
3495
+ }
3496
+ disconnectedCallback() {
3497
+ // destroy plugins on element disconnect
3498
+ each(this.internalPlugins, p => p.destroy());
3499
+ this.internalPlugins = [];
3500
+ // clear events
3501
+ for (let type in this.subscribers) {
3502
+ document.removeEventListener(type, this.subscribers[type]);
3503
+ delete this.subscribers[type];
3504
+ }
3505
+ }
3506
+ render() {
3507
+ const contentHeight = this.dimensionProvider.stores['rgRow'].store.get('realSize');
3508
+ this.viewport = new ViewportService({
3509
+ columnProvider: this.columnProvider,
3510
+ dataProvider: this.dataProvider,
3511
+ dimensionProvider: this.dimensionProvider,
3512
+ viewportProvider: this.viewportProvider,
3513
+ uuid: this.uuid,
3514
+ scrollingService: this.scrollingService,
3515
+ orderService: this.orderService,
3516
+ selectionStoreConnector: this.selectionStoreConnector,
3517
+ resize: c => this.aftercolumnresize.emit(c)
3518
+ }, contentHeight);
3519
+ const views = [];
3520
+ if (this.rowHeaders) {
3521
+ const anyView = this.viewport.columns[0];
3522
+ views.push(h("revogr-row-headers", { height: contentHeight, resize: this.resize, dataPorts: anyView.dataPorts, headerProp: anyView.headerProp, uiid: anyView.prop[UUID], rowHeaderColumn: typeof this.rowHeaders === 'object' ? this.rowHeaders : undefined, onScrollViewport: ({ detail: e }) => this.scrollingService.onScroll(e, 'headerRow'), onElementToScroll: ({ detail: e }) => this.scrollingService.registerElement(e, 'headerRow') }));
3523
+ }
3524
+ views.push(h(ViewPortSections, { columnFilter: !!this.filter, resize: this.resize, readonly: this.readonly, range: this.range, rowClass: this.rowClass, editors: this.editors, useClipboard: this.useClipboard, columns: this.viewport.columns, onEdit: detail => {
3525
+ const event = this.beforeeditstart.emit(detail);
3526
+ if (!event.defaultPrevented) {
3527
+ this.selectionStoreConnector.setEdit(detail.isCancel ? false : detail.val);
3528
+ }
3529
+ }, registerElement: (e, k) => this.scrollingService.registerElement(e, k), onScroll: details => this.scrollingService.onScroll(details) }));
3530
+ return (h(Host, Object.assign({}, { [`${UUID}`]: this.uuid }), h(RevoViewPort, { viewports: this.viewportProvider.stores, dimensions: this.dimensionProvider.stores, orderRef: e => (this.orderService = e), registerElement: (e, k) => this.scrollingService.registerElement(e, k), nakedClick: () => this.viewport.clearEdit(), onScroll: details => this.scrollingService.onScroll(details) }, views), this.extraElements));
3531
+ }
3532
+ get element() { return this; }
3533
+ static get watchers() { return {
3534
+ "columns": ["columnChanged"],
3535
+ "theme": ["themeChanged"],
3536
+ "source": ["dataChanged"],
3537
+ "pinnedBottomSource": ["dataBottomChanged"],
3538
+ "pinnedTopSource": ["dataTopChanged"],
3539
+ "rowDefinitions": ["rowDefChanged"],
3540
+ "trimmedRows": ["trimmedRowsChanged"],
3541
+ "grouping": ["groupingChanged"],
3542
+ "stretch": ["applyStretch"]
3543
+ }; }
3544
+ static get style() { return revoGridStyleCss; }
3545
+ }, [0, "revo-grid", {
3546
+ "rowHeaders": [4, "row-headers"],
3547
+ "frameSize": [2, "frame-size"],
3548
+ "rowSize": [2, "row-size"],
3549
+ "colSize": [2, "col-size"],
3550
+ "range": [4],
3551
+ "readonly": [4],
3552
+ "resize": [4],
3553
+ "canFocus": [4, "can-focus"],
3554
+ "useClipboard": [4, "use-clipboard"],
3555
+ "columns": [16],
3556
+ "source": [16],
3557
+ "pinnedTopSource": [16],
3558
+ "pinnedBottomSource": [16],
3559
+ "rowDefinitions": [16],
3560
+ "editors": [16],
3561
+ "plugins": [16],
3562
+ "columnTypes": [16],
3563
+ "theme": [1537],
3564
+ "rowClass": [513, "row-class"],
3565
+ "autoSizeColumn": [4, "auto-size-column"],
3566
+ "filter": [4],
3567
+ "canMoveColumns": [4, "can-move-columns"],
3568
+ "trimmedRows": [16],
3569
+ "exporting": [4],
3570
+ "grouping": [16],
3571
+ "stretch": [8],
3572
+ "extraElements": [32],
3573
+ "refresh": [64],
3574
+ "scrollToRow": [64],
3575
+ "scrollToColumnIndex": [64],
3576
+ "scrollToColumnProp": [64],
3577
+ "updateColumns": [64],
3578
+ "addTrimmed": [64],
3579
+ "scrollToCoordinate": [64],
3580
+ "setCellEdit": [64],
3581
+ "registerVNode": [64],
3582
+ "getSource": [64],
3583
+ "getVisibleSource": [64],
3584
+ "getSourceStore": [64],
3585
+ "getColumnStore": [64],
3586
+ "updateColumnSorting": [64],
3587
+ "clearSorting": [64],
3588
+ "getColumns": [64],
3589
+ "clearFocus": [64],
3590
+ "getPlugins": [64],
3591
+ "getFocused": [64],
3592
+ "getSelectedRange": [64]
3593
+ }, [[0, "internalRowDragStart", "onRowDragStarted"], [0, "internalRowDragEnd", "onRowDragEnd"], [0, "internalRowDrag", "onRowDrag"], [0, "internalRowMouseMove", "onRowMouseMove"], [0, "internalCellEdit", "onBeforeEdit"], [0, "internalRangeDataApply", "onBeforeRangeEdit"], [0, "internalSelectionChanged", "onRangeChanged"], [0, "initialRowDropped", "onRowDropped"], [0, "initialHeaderClick", "onHeaderClick"], [0, "internalFocusCell", "onCellFocus"]]]);
3594
+ function defineCustomElement$1() {
3595
+ if (typeof customElements === "undefined") {
3596
+ return;
3597
+ }
3598
+ const components = ["revo-grid", "revogr-data", "revogr-edit", "revogr-focus", "revogr-header", "revogr-order-editor", "revogr-overlay-selection", "revogr-row-headers", "revogr-scroll-virtual", "revogr-temp-range", "revogr-viewport-scroll"];
3599
+ components.forEach(tagName => { switch (tagName) {
3600
+ case "revo-grid":
3601
+ if (!customElements.get(tagName)) {
3602
+ customElements.define(tagName, RevoGridComponent);
3603
+ }
3604
+ break;
3605
+ case "revogr-data":
3606
+ if (!customElements.get(tagName)) {
3607
+ defineCustomElement$b();
3608
+ }
3609
+ break;
3610
+ case "revogr-edit":
3611
+ if (!customElements.get(tagName)) {
3612
+ defineCustomElement$a();
3613
+ }
3614
+ break;
3615
+ case "revogr-focus":
3616
+ if (!customElements.get(tagName)) {
3617
+ defineCustomElement$9();
3618
+ }
3619
+ break;
3620
+ case "revogr-header":
3621
+ if (!customElements.get(tagName)) {
3622
+ defineCustomElement$8();
3623
+ }
3624
+ break;
3625
+ case "revogr-order-editor":
3626
+ if (!customElements.get(tagName)) {
3627
+ defineCustomElement$7();
3628
+ }
3629
+ break;
3630
+ case "revogr-overlay-selection":
3631
+ if (!customElements.get(tagName)) {
3632
+ defineCustomElement$6();
3633
+ }
3634
+ break;
3635
+ case "revogr-row-headers":
3636
+ if (!customElements.get(tagName)) {
3637
+ defineCustomElement$5();
3638
+ }
3639
+ break;
3640
+ case "revogr-scroll-virtual":
3641
+ if (!customElements.get(tagName)) {
3642
+ defineCustomElement$4();
3643
+ }
3644
+ break;
3645
+ case "revogr-temp-range":
3646
+ if (!customElements.get(tagName)) {
3647
+ defineCustomElement$3();
3648
+ }
3649
+ break;
3650
+ case "revogr-viewport-scroll":
3651
+ if (!customElements.get(tagName)) {
3652
+ defineCustomElement$2();
3653
+ }
3654
+ break;
3655
+ } });
3656
+ }
3657
+ defineCustomElement$1();
3658
+
3659
+ const RevoGrid = RevoGridComponent;
3660
+ const defineCustomElement = defineCustomElement$1;
3661
+
3662
+ export { RevoGrid, ThemeService as T, defineCustomElement };