@revolist/revogrid 4.9.10 → 4.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/column.drag.plugin-e636b5af.js +1686 -0
- package/dist/cjs/column.drag.plugin-e636b5af.js.map +1 -0
- package/dist/cjs/{column.service-bfaba0e0.js → column.service-15c8352d.js} +443 -56
- package/dist/cjs/column.service-15c8352d.js.map +1 -0
- package/dist/cjs/{toNumber-838e6ff5.js → debounce-cb5f4e35.js} +229 -12
- package/dist/cjs/debounce-cb5f4e35.js.map +1 -0
- package/dist/cjs/{edit.utils-983f1a82.js → edit.utils-1172677c.js} +2 -2
- package/dist/cjs/{edit.utils-983f1a82.js.map → edit.utils-1172677c.js.map} +1 -1
- package/dist/cjs/{header-cell-renderer-53e4fd75.js → header-cell-renderer-375a879f.js} +42 -4
- package/dist/cjs/header-cell-renderer-375a879f.js.map +1 -0
- package/dist/cjs/{index-464d1aaf.js → index-28b6fdfb.js} +31 -31
- package/dist/cjs/{index-464d1aaf.js.map → index-28b6fdfb.js.map} +1 -1
- package/dist/cjs/index.cjs.js +39 -27
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/{key.utils-4455349b.js → key.utils-c62ab1e1.js} +2 -2
- package/dist/cjs/{key.utils-4455349b.js.map → key.utils-c62ab1e1.js.map} +1 -1
- package/dist/cjs/revo-grid.cjs.entry.js +704 -2034
- package/dist/cjs/revo-grid.cjs.entry.js.map +1 -1
- package/dist/cjs/revogr-attribution_6.cjs.entry.js +16 -17
- package/dist/cjs/revogr-attribution_6.cjs.entry.js.map +1 -1
- package/dist/cjs/revogr-clipboard_3.cjs.entry.js +6 -77
- package/dist/cjs/revogr-clipboard_3.cjs.entry.js.map +1 -1
- package/dist/cjs/revogr-data_4.cjs.entry.js +117 -123
- package/dist/cjs/revogr-data_4.cjs.entry.js.map +1 -1
- package/dist/cjs/revogr-filter-panel.cjs.entry.js +1 -2
- package/dist/cjs/revogr-filter-panel.cjs.entry.js.map +1 -1
- package/dist/cjs/{row-header-utils-e71dc7bf.js → row-header-utils-22ffee54.js} +2 -2
- package/dist/cjs/{row-header-utils-e71dc7bf.js.map → row-header-utils-22ffee54.js.map} +1 -1
- package/dist/cjs/sorting.sign-8bf92449.js +19 -0
- package/dist/cjs/sorting.sign-8bf92449.js.map +1 -0
- package/dist/cjs/text-editor-91a9f5b5.js +82 -0
- package/dist/cjs/text-editor-91a9f5b5.js.map +1 -0
- package/dist/cjs/{throttle-c893457e.js → throttle-5da5df51.js} +4 -5
- package/dist/cjs/throttle-5da5df51.js.map +1 -0
- package/dist/cjs/viewport.helpers-e59a544e.js +58 -0
- package/dist/cjs/viewport.helpers-e59a544e.js.map +1 -0
- package/dist/collection/components/editors/text-editor.js.map +1 -1
- package/dist/collection/components/header/revogr-header.js +1 -1
- package/dist/collection/components/revoGrid/revo-grid-style.css +6 -0
- package/dist/collection/index.js +2 -2
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/plugins/index.js +16 -0
- package/dist/collection/plugins/index.js.map +1 -0
- package/dist/collection/plugins/moveColumn/column.drag.plugin.js.map +1 -1
- package/dist/collection/types/selection.js.map +1 -1
- package/dist/esm/column.drag.plugin-30dc4e24.js +1665 -0
- package/dist/esm/column.drag.plugin-30dc4e24.js.map +1 -0
- package/dist/esm/{column.service-6f1faf2d.js → column.service-414e9cba.js} +435 -51
- package/dist/esm/column.service-414e9cba.js.map +1 -0
- package/dist/esm/{toNumber-8de324a7.js → debounce-e8e9464a.js} +229 -13
- package/dist/esm/debounce-e8e9464a.js.map +1 -0
- package/dist/esm/{edit.utils-c3f5c9f4.js → edit.utils-0666e5bd.js} +2 -2
- package/dist/esm/{edit.utils-c3f5c9f4.js.map → edit.utils-0666e5bd.js.map} +1 -1
- package/dist/esm/{header-cell-renderer-66d01daa.js → header-cell-renderer-ca570fcf.js} +40 -4
- package/dist/esm/header-cell-renderer-ca570fcf.js.map +1 -0
- package/dist/esm/{index-c428acf6.js → index-74b9801b.js} +3 -3
- package/dist/esm/{index-c428acf6.js.map → index-74b9801b.js.map} +1 -1
- package/dist/esm/index.js +10 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/{key.utils-35bedfd7.js → key.utils-d3df5db8.js} +2 -2
- package/dist/esm/{key.utils-35bedfd7.js.map → key.utils-d3df5db8.js.map} +1 -1
- package/dist/esm/revo-grid.entry.js +675 -2005
- package/dist/esm/revo-grid.entry.js.map +1 -1
- package/dist/esm/revogr-attribution_6.entry.js +8 -9
- package/dist/esm/revogr-attribution_6.entry.js.map +1 -1
- package/dist/esm/revogr-clipboard_3.entry.js +5 -76
- package/dist/esm/revogr-clipboard_3.entry.js.map +1 -1
- package/dist/esm/revogr-data_4.entry.js +50 -56
- package/dist/esm/revogr-data_4.entry.js.map +1 -1
- package/dist/esm/revogr-filter-panel.entry.js +1 -2
- package/dist/esm/revogr-filter-panel.entry.js.map +1 -1
- package/dist/esm/{row-header-utils-3a6f6adc.js → row-header-utils-c7e3e2d5.js} +2 -2
- package/dist/esm/{row-header-utils-3a6f6adc.js.map → row-header-utils-c7e3e2d5.js.map} +1 -1
- package/dist/esm/sorting.sign-1afddea1.js +15 -0
- package/dist/esm/sorting.sign-1afddea1.js.map +1 -0
- package/dist/esm/text-editor-96d69516.js +80 -0
- package/dist/esm/text-editor-96d69516.js.map +1 -0
- package/dist/esm/{throttle-f9cda5b0.js → throttle-262c3ed2.js} +3 -4
- package/dist/esm/throttle-262c3ed2.js.map +1 -0
- package/dist/esm/viewport.helpers-7e7f9dad.js +52 -0
- package/dist/esm/viewport.helpers-7e7f9dad.js.map +1 -0
- package/dist/revo-grid/column.drag.plugin-30dc4e24.js +5 -0
- package/dist/revo-grid/column.drag.plugin-30dc4e24.js.map +1 -0
- package/dist/revo-grid/column.service-414e9cba.js +5 -0
- package/dist/revo-grid/column.service-414e9cba.js.map +1 -0
- package/dist/revo-grid/debounce-e8e9464a.js +5 -0
- package/dist/revo-grid/debounce-e8e9464a.js.map +1 -0
- package/dist/revo-grid/{edit.utils-c3f5c9f4.js → edit.utils-0666e5bd.js} +2 -2
- package/dist/revo-grid/header-cell-renderer-ca570fcf.js +5 -0
- package/dist/revo-grid/header-cell-renderer-ca570fcf.js.map +1 -0
- package/dist/revo-grid/{index-c428acf6.js → index-74b9801b.js} +2 -2
- package/dist/revo-grid/index.esm.js +1 -1
- package/dist/revo-grid/key.utils-d3df5db8.js +5 -0
- package/dist/revo-grid/{key.utils-35bedfd7.js.map → key.utils-d3df5db8.js.map} +1 -1
- package/dist/revo-grid/revo-grid.entry.js +1 -1
- package/dist/revo-grid/revo-grid.entry.js.map +1 -1
- package/dist/revo-grid/revogr-attribution_6.entry.js +1 -1
- package/dist/revo-grid/revogr-attribution_6.entry.js.map +1 -1
- package/dist/revo-grid/revogr-clipboard_3.entry.js +1 -1
- package/dist/revo-grid/revogr-clipboard_3.entry.js.map +1 -1
- package/dist/revo-grid/revogr-data_4.entry.js +1 -1
- package/dist/revo-grid/revogr-data_4.entry.js.map +1 -1
- package/dist/revo-grid/revogr-filter-panel.entry.js +1 -1
- package/dist/revo-grid/revogr-filter-panel.entry.js.map +1 -1
- package/dist/revo-grid/{row-header-utils-3a6f6adc.js → row-header-utils-c7e3e2d5.js} +2 -2
- package/dist/revo-grid/sorting.sign-1afddea1.js +5 -0
- package/dist/revo-grid/sorting.sign-1afddea1.js.map +1 -0
- package/dist/revo-grid/text-editor-96d69516.js +5 -0
- package/dist/revo-grid/text-editor-96d69516.js.map +1 -0
- package/dist/revo-grid/throttle-262c3ed2.js +5 -0
- package/dist/revo-grid/{throttle-f9cda5b0.js.map → throttle-262c3ed2.js.map} +1 -1
- package/dist/revo-grid/viewport.helpers-7e7f9dad.js +5 -0
- package/dist/revo-grid/viewport.helpers-7e7f9dad.js.map +1 -0
- package/dist/types/components/editors/text-editor.d.ts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +12 -0
- package/dist/types/plugins/moveColumn/column.drag.plugin.d.ts +1 -13
- package/dist/types/types/selection.d.ts +1 -1
- package/hydrate/index.js +1 -1
- package/hydrate/index.mjs +1 -1
- package/package.json +1 -1
- package/standalone/_stringToPath.js +1 -1
- package/standalone/column.service.js +1 -1
- package/standalone/data.store.js +2 -2
- package/standalone/debounce.js +1 -1
- package/standalone/dimension.helpers.js +1 -1
- package/standalone/index.js +7 -5
- package/standalone/index.js.map +1 -1
- package/standalone/isObjectLike.js +1 -1
- package/standalone/revo-grid.js +1947 -1947
- package/standalone/revo-grid.js.map +1 -1
- package/standalone/revogr-edit2.js +1 -1
- package/standalone/revogr-edit2.js.map +1 -1
- package/standalone/revogr-header.js +1 -1
- package/standalone/revogr-header2.js +54 -52
- package/standalone/revogr-header2.js.map +1 -1
- package/standalone/revogr-row-headers2.js +1 -1
- package/standalone/throttle.js +1 -1
- package/standalone/toNumber.js +1 -1
- package/dist/cjs/column.service-bfaba0e0.js.map +0 -1
- package/dist/cjs/column.utils-4a450d27.js +0 -345
- package/dist/cjs/column.utils-4a450d27.js.map +0 -1
- package/dist/cjs/debounce-e2b7c6fb.js +0 -226
- package/dist/cjs/debounce-e2b7c6fb.js.map +0 -1
- package/dist/cjs/dispatcher-998aa470.js +0 -46
- package/dist/cjs/dispatcher-998aa470.js.map +0 -1
- package/dist/cjs/header-cell-renderer-53e4fd75.js.map +0 -1
- package/dist/cjs/selection.helpers-2c90d546.js +0 -450
- package/dist/cjs/selection.helpers-2c90d546.js.map +0 -1
- package/dist/cjs/throttle-c893457e.js.map +0 -1
- package/dist/cjs/toNumber-838e6ff5.js.map +0 -1
- package/dist/esm/column.service-6f1faf2d.js.map +0 -1
- package/dist/esm/column.utils-1a402ff9.js +0 -333
- package/dist/esm/column.utils-1a402ff9.js.map +0 -1
- package/dist/esm/debounce-7781346d.js +0 -224
- package/dist/esm/debounce-7781346d.js.map +0 -1
- package/dist/esm/dispatcher-ea08404f.js +0 -43
- package/dist/esm/dispatcher-ea08404f.js.map +0 -1
- package/dist/esm/header-cell-renderer-66d01daa.js.map +0 -1
- package/dist/esm/selection.helpers-ac4368b0.js +0 -441
- package/dist/esm/selection.helpers-ac4368b0.js.map +0 -1
- package/dist/esm/throttle-f9cda5b0.js.map +0 -1
- package/dist/esm/toNumber-8de324a7.js.map +0 -1
- package/dist/revo-grid/column.service-6f1faf2d.js +0 -5
- package/dist/revo-grid/column.service-6f1faf2d.js.map +0 -1
- package/dist/revo-grid/column.utils-1a402ff9.js +0 -5
- package/dist/revo-grid/column.utils-1a402ff9.js.map +0 -1
- package/dist/revo-grid/debounce-7781346d.js +0 -5
- package/dist/revo-grid/debounce-7781346d.js.map +0 -1
- package/dist/revo-grid/dispatcher-ea08404f.js +0 -5
- package/dist/revo-grid/dispatcher-ea08404f.js.map +0 -1
- package/dist/revo-grid/header-cell-renderer-66d01daa.js +0 -5
- package/dist/revo-grid/header-cell-renderer-66d01daa.js.map +0 -1
- package/dist/revo-grid/key.utils-35bedfd7.js +0 -5
- package/dist/revo-grid/selection.helpers-ac4368b0.js +0 -5
- package/dist/revo-grid/selection.helpers-ac4368b0.js.map +0 -1
- package/dist/revo-grid/throttle-f9cda5b0.js +0 -5
- package/dist/revo-grid/toNumber-8de324a7.js +0 -5
- package/dist/revo-grid/toNumber-8de324a7.js.map +0 -1
- /package/dist/revo-grid/{edit.utils-c3f5c9f4.js.map → edit.utils-0666e5bd.js.map} +0 -0
- /package/dist/revo-grid/{index-c428acf6.js.map → index-74b9801b.js.map} +0 -0
- /package/dist/revo-grid/{row-header-utils-3a6f6adc.js.map → row-header-utils-c7e3e2d5.js.map} +0 -0
|
@@ -0,0 +1,1686 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Built by Revolist OU ❤️
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const index = require('./index-28b6fdfb.js');
|
|
7
|
+
const rowHeaderUtils = require('./row-header-utils-22ffee54.js');
|
|
8
|
+
const debounce = require('./debounce-cb5f4e35.js');
|
|
9
|
+
const index$1 = require('./index-10d10c55.js');
|
|
10
|
+
const column_service = require('./column.service-15c8352d.js');
|
|
11
|
+
const filter_button = require('./filter.button-afb16244.js');
|
|
12
|
+
const headerCellRenderer = require('./header-cell-renderer-375a879f.js');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Storing pre-calculated
|
|
16
|
+
* Dimension information and sizes
|
|
17
|
+
*/
|
|
18
|
+
const trimmedPlugin = (store) => {
|
|
19
|
+
let trimmedSize = {};
|
|
20
|
+
const setTrimmed = (sizes, trimmed) => {
|
|
21
|
+
const newSize = Object.assign({}, sizes);
|
|
22
|
+
trimmedSize = {};
|
|
23
|
+
for (const [index, v] of Object.entries(trimmed)) {
|
|
24
|
+
const i = index;
|
|
25
|
+
if (v && newSize[i]) {
|
|
26
|
+
trimmedSize[i] = newSize[i];
|
|
27
|
+
delete newSize[i];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
store.setDimensionSize(newSize);
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
set(key, val) {
|
|
34
|
+
switch (key) {
|
|
35
|
+
case 'trimmed':
|
|
36
|
+
const trim = val;
|
|
37
|
+
const sizes = store.store.get('sizes');
|
|
38
|
+
// recover trimmed, apply new trim
|
|
39
|
+
setTrimmed(Object.assign(Object.assign({}, sizes), trimmedSize), trim);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const realSizePlugin = (store) => {
|
|
46
|
+
return {
|
|
47
|
+
set(k) {
|
|
48
|
+
switch (k) {
|
|
49
|
+
case 'count':
|
|
50
|
+
case 'sizes':
|
|
51
|
+
case 'originItemSize':
|
|
52
|
+
let realSize = 0;
|
|
53
|
+
const count = store.store.get('count');
|
|
54
|
+
for (let i = 0; i < count; i++) {
|
|
55
|
+
realSize +=
|
|
56
|
+
store.store.get('sizes')[i] || store.store.get('originItemSize');
|
|
57
|
+
}
|
|
58
|
+
store.setStore({ realSize });
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
function initialBase() {
|
|
64
|
+
return {
|
|
65
|
+
indexes: [],
|
|
66
|
+
count: 0,
|
|
67
|
+
// plugin support
|
|
68
|
+
trimmed: {},
|
|
69
|
+
// size operations, this provider stores only changed sizes, not all of them
|
|
70
|
+
// same as indexes but for sizes and positions
|
|
71
|
+
// item index to size
|
|
72
|
+
sizes: {},
|
|
73
|
+
// order in indexes[] to coordinate
|
|
74
|
+
positionIndexToItem: {},
|
|
75
|
+
// initial element to coordinate ^
|
|
76
|
+
indexToItem: {},
|
|
77
|
+
positionIndexes: [],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function initialState() {
|
|
81
|
+
return Object.assign(Object.assign({}, initialBase()), {
|
|
82
|
+
// size which all items can take
|
|
83
|
+
realSize: 0,
|
|
84
|
+
// initial item size if it wasn't changed
|
|
85
|
+
originItemSize: 0 });
|
|
86
|
+
}
|
|
87
|
+
class DimensionStore {
|
|
88
|
+
constructor() {
|
|
89
|
+
this.store = index.createStore(initialState());
|
|
90
|
+
this.store.use(trimmedPlugin(this));
|
|
91
|
+
this.store.use(realSizePlugin(this));
|
|
92
|
+
}
|
|
93
|
+
getCurrentState() {
|
|
94
|
+
const state = initialState();
|
|
95
|
+
const keys = Object.keys(state);
|
|
96
|
+
return index.reduce_1(keys, (r, k) => {
|
|
97
|
+
const data = this.store.get(k);
|
|
98
|
+
r[k] = data;
|
|
99
|
+
return r;
|
|
100
|
+
}, state);
|
|
101
|
+
}
|
|
102
|
+
dispose() {
|
|
103
|
+
index.setStore(this.store, initialState());
|
|
104
|
+
}
|
|
105
|
+
setStore(data) {
|
|
106
|
+
index.setStore(this.store, data);
|
|
107
|
+
}
|
|
108
|
+
drop() {
|
|
109
|
+
index.setStore(this.store, initialBase());
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Set custom dimension sizes and overwrite old
|
|
113
|
+
* Generates new indexes based on sizes
|
|
114
|
+
* @param sizes - sizes to set
|
|
115
|
+
*/
|
|
116
|
+
setDimensionSize(sizes) {
|
|
117
|
+
const dimensionData = index.calculateDimensionData(this.store.get('originItemSize'), sizes);
|
|
118
|
+
index.setStore(this.store, dimensionData);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const rowTypes = ['rowPinStart', 'rgRow', 'rowPinEnd'];
|
|
123
|
+
const columnTypes = [
|
|
124
|
+
'colPinStart',
|
|
125
|
+
'rgCol',
|
|
126
|
+
'colPinEnd',
|
|
127
|
+
];
|
|
128
|
+
function isRowType(type) {
|
|
129
|
+
return rowTypes.indexOf(type) > -1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Base layer for plugins
|
|
134
|
+
* Provide minimal starting core for plugins to work
|
|
135
|
+
* Extend this class to create plugin
|
|
136
|
+
*/
|
|
137
|
+
class BasePlugin {
|
|
138
|
+
constructor(revogrid, providers) {
|
|
139
|
+
this.revogrid = revogrid;
|
|
140
|
+
this.providers = providers;
|
|
141
|
+
this.h = index$1.h;
|
|
142
|
+
this.subscriptions = {};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
*
|
|
146
|
+
* @param eventName - event name to subscribe to in revo-grid component (e.g. 'beforeheaderclick')
|
|
147
|
+
* @param callback - callback function for event
|
|
148
|
+
*/
|
|
149
|
+
addEventListener(eventName, callback) {
|
|
150
|
+
this.revogrid.addEventListener(eventName, callback);
|
|
151
|
+
this.subscriptions[eventName] = callback;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Subscribe to property change in revo-grid component
|
|
155
|
+
* You can return false in callback to prevent default value set
|
|
156
|
+
*
|
|
157
|
+
* @param prop - property name
|
|
158
|
+
* @param callback - callback function
|
|
159
|
+
* @param immediate - trigger callback immediately with current value
|
|
160
|
+
*/
|
|
161
|
+
watch(prop, callback, { immediate } = { immediate: false }) {
|
|
162
|
+
const nativeValueDesc = Object.getOwnPropertyDescriptor(this.revogrid, prop) ||
|
|
163
|
+
Object.getOwnPropertyDescriptor(this.revogrid.constructor.prototype, prop);
|
|
164
|
+
// Overwrite property descriptor for this instance
|
|
165
|
+
Object.defineProperty(this.revogrid, prop, {
|
|
166
|
+
set(val) {
|
|
167
|
+
var _a;
|
|
168
|
+
const keepDefault = callback(val);
|
|
169
|
+
if (keepDefault === false) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Continue with native behavior
|
|
173
|
+
return (_a = nativeValueDesc === null || nativeValueDesc === void 0 ? void 0 : nativeValueDesc.set) === null || _a === void 0 ? void 0 : _a.call(this, val);
|
|
174
|
+
},
|
|
175
|
+
get() {
|
|
176
|
+
var _a;
|
|
177
|
+
// Continue with native behavior
|
|
178
|
+
return (_a = nativeValueDesc === null || nativeValueDesc === void 0 ? void 0 : nativeValueDesc.get) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
if (immediate) {
|
|
182
|
+
callback(nativeValueDesc === null || nativeValueDesc === void 0 ? void 0 : nativeValueDesc.value);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Remove event listener
|
|
187
|
+
* @param eventName
|
|
188
|
+
*/
|
|
189
|
+
removeEventListener(eventName) {
|
|
190
|
+
this.revogrid.removeEventListener(eventName, this.subscriptions[eventName]);
|
|
191
|
+
delete this.subscriptions[eventName];
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Emit event from revo-grid component
|
|
195
|
+
* Event can be cancelled by calling event.preventDefault() in callback
|
|
196
|
+
*/
|
|
197
|
+
emit(eventName, detail) {
|
|
198
|
+
const event = new CustomEvent(eventName, { detail, cancelable: true });
|
|
199
|
+
this.revogrid.dispatchEvent(event);
|
|
200
|
+
return event;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Clear all subscriptions
|
|
204
|
+
*/
|
|
205
|
+
clearSubscriptions() {
|
|
206
|
+
for (let type in this.subscriptions) {
|
|
207
|
+
this.removeEventListener(type);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Destroy plugin and clear all subscriptions
|
|
212
|
+
*/
|
|
213
|
+
destroy() {
|
|
214
|
+
this.clearSubscriptions();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function getColumnType(rgCol) {
|
|
219
|
+
if (rgCol.pin) {
|
|
220
|
+
return rgCol.pin;
|
|
221
|
+
}
|
|
222
|
+
return 'rgCol';
|
|
223
|
+
}
|
|
224
|
+
function getColumnSizes(cols) {
|
|
225
|
+
const res = {};
|
|
226
|
+
for (const [i, c] of cols.entries()) {
|
|
227
|
+
if (c.size) {
|
|
228
|
+
res[i] = c.size;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return res;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Check if column is grouping column
|
|
235
|
+
*/
|
|
236
|
+
function isColGrouping(colData) {
|
|
237
|
+
return !!colData.children;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* This function is used to create a collection of columns.
|
|
241
|
+
*/
|
|
242
|
+
function getColumns(columns, level = 0, types) {
|
|
243
|
+
const collection = {
|
|
244
|
+
// columns as they are in stores per type
|
|
245
|
+
columns: {
|
|
246
|
+
rgCol: [],
|
|
247
|
+
colPinStart: [],
|
|
248
|
+
colPinEnd: [],
|
|
249
|
+
},
|
|
250
|
+
// columns indexed by prop for quick access
|
|
251
|
+
columnByProp: {},
|
|
252
|
+
// column grouping
|
|
253
|
+
columnGrouping: {
|
|
254
|
+
rgCol: [],
|
|
255
|
+
colPinStart: [],
|
|
256
|
+
colPinEnd: [],
|
|
257
|
+
},
|
|
258
|
+
// max depth level for column grouping
|
|
259
|
+
maxLevel: level,
|
|
260
|
+
// sorting
|
|
261
|
+
sort: {},
|
|
262
|
+
};
|
|
263
|
+
return index.reduce_1(columns, (res, colData) => {
|
|
264
|
+
// Grouped column
|
|
265
|
+
if (isColGrouping(colData)) {
|
|
266
|
+
return gatherGroup(res, colData, getColumns(colData.children, level + 1, types), level);
|
|
267
|
+
}
|
|
268
|
+
// Regular column
|
|
269
|
+
const regularColumn = Object.assign(Object.assign({}, (colData.columnType && types && types[colData.columnType])), colData);
|
|
270
|
+
// Regular column, no Pin
|
|
271
|
+
if (!regularColumn.pin) {
|
|
272
|
+
res.columns.rgCol.push(regularColumn);
|
|
273
|
+
// Pin
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
res.columns[regularColumn.pin].push(regularColumn);
|
|
277
|
+
}
|
|
278
|
+
if (regularColumn.order) {
|
|
279
|
+
res.sort[regularColumn.prop] = regularColumn;
|
|
280
|
+
}
|
|
281
|
+
// it's possible that some columns have same prop, but better to avoid it
|
|
282
|
+
if (!res.columnByProp[regularColumn.prop]) {
|
|
283
|
+
res.columnByProp[regularColumn.prop] = [];
|
|
284
|
+
}
|
|
285
|
+
res.columnByProp[regularColumn.prop].push(regularColumn);
|
|
286
|
+
// trigger setup hook if present
|
|
287
|
+
regularColumn.beforeSetup && regularColumn.beforeSetup(regularColumn);
|
|
288
|
+
return res;
|
|
289
|
+
}, collection);
|
|
290
|
+
}
|
|
291
|
+
function gatherGroup(res, colData, collection, level = 0) {
|
|
292
|
+
// group template
|
|
293
|
+
const group = Object.assign(Object.assign({}, colData), { level, ids: [] });
|
|
294
|
+
// check columns for update
|
|
295
|
+
for (let k in collection.columns) {
|
|
296
|
+
const key = k;
|
|
297
|
+
const resultItem = res.columns[key];
|
|
298
|
+
const collectionItem = collection.columns[key];
|
|
299
|
+
// if column data
|
|
300
|
+
if (index.isArray_1(resultItem) && index.isArray_1(collectionItem)) {
|
|
301
|
+
// fill columns
|
|
302
|
+
resultItem.push(...collectionItem);
|
|
303
|
+
// fill grouping
|
|
304
|
+
if (collectionItem.length) {
|
|
305
|
+
res.columnGrouping[key].push(Object.assign(Object.assign({}, group), { ids: collectionItem.map(item => item.prop) }));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// merge column groupings
|
|
310
|
+
for (let k in collection.columnGrouping) {
|
|
311
|
+
const key = k;
|
|
312
|
+
const collectionItem = collection.columnGrouping[key];
|
|
313
|
+
res.columnGrouping[key].push(...collectionItem);
|
|
314
|
+
}
|
|
315
|
+
res.maxLevel = Math.max(res.maxLevel, collection.maxLevel);
|
|
316
|
+
res.sort = Object.assign(Object.assign({}, res.sort), collection.sort);
|
|
317
|
+
return res;
|
|
318
|
+
}
|
|
319
|
+
function findColumn(columns, prop) {
|
|
320
|
+
for (const c of columns) {
|
|
321
|
+
if (isColGrouping(c)) {
|
|
322
|
+
const found = findColumn(c.children, prop);
|
|
323
|
+
if (found) {
|
|
324
|
+
return found;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
else if (c.prop === prop) {
|
|
328
|
+
return c;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
function getColumnByProp(columns, prop) {
|
|
334
|
+
return findColumn(columns, prop);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Plugin module for revo-grid grid system
|
|
339
|
+
* Add support for automatic column resize
|
|
340
|
+
*/
|
|
341
|
+
const LETTER_BLOCK_SIZE = 7;
|
|
342
|
+
var ColumnAutoSizeMode;
|
|
343
|
+
(function (ColumnAutoSizeMode) {
|
|
344
|
+
// increases column width on header click according the largest text value
|
|
345
|
+
ColumnAutoSizeMode["headerClickAutosize"] = "headerClickAutoSize";
|
|
346
|
+
// increases column width on data set and text edit, decreases performance
|
|
347
|
+
ColumnAutoSizeMode["autoSizeOnTextOverlap"] = "autoSizeOnTextOverlap";
|
|
348
|
+
// increases and decreases column width based on all items sizes, worst for performance
|
|
349
|
+
ColumnAutoSizeMode["autoSizeAll"] = "autoSizeAll";
|
|
350
|
+
})(ColumnAutoSizeMode || (ColumnAutoSizeMode = {}));
|
|
351
|
+
class AutoSizeColumnPlugin extends BasePlugin {
|
|
352
|
+
constructor(revogrid, providers, config) {
|
|
353
|
+
super(revogrid, providers);
|
|
354
|
+
this.providers = providers;
|
|
355
|
+
this.config = config;
|
|
356
|
+
this.autoSizeColumns = null;
|
|
357
|
+
/** for edge case when no columns defined before data */
|
|
358
|
+
this.dataResolve = null;
|
|
359
|
+
this.dataReject = null;
|
|
360
|
+
this.letterBlockSize = (config === null || config === void 0 ? void 0 : config.letterBlockSize) || LETTER_BLOCK_SIZE;
|
|
361
|
+
// create test container to check text width
|
|
362
|
+
if (config === null || config === void 0 ? void 0 : config.preciseSize) {
|
|
363
|
+
this.precsizeCalculationArea = this.initiatePresizeElement();
|
|
364
|
+
revogrid.appendChild(this.precsizeCalculationArea);
|
|
365
|
+
}
|
|
366
|
+
const aftersourceset = ({ detail: { source }, }) => {
|
|
367
|
+
this.setSource(source);
|
|
368
|
+
};
|
|
369
|
+
const afteredit = ({ detail }) => {
|
|
370
|
+
this.afteredit(detail);
|
|
371
|
+
};
|
|
372
|
+
const afterEditAll = ({ detail }) => {
|
|
373
|
+
this.afterEditAll(detail);
|
|
374
|
+
};
|
|
375
|
+
const beforecolumnsset = ({ detail: { columns }, }) => {
|
|
376
|
+
this.columnSet(columns);
|
|
377
|
+
};
|
|
378
|
+
const headerDblClick = ({ detail }) => {
|
|
379
|
+
const type = getColumnType(detail.column);
|
|
380
|
+
const size = this.getColumnSize(detail.index, type);
|
|
381
|
+
if (size) {
|
|
382
|
+
this.providers.dimension.setCustomSizes(type, {
|
|
383
|
+
[detail.index]: size,
|
|
384
|
+
}, true);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
this.addEventListener('beforecolumnsset', beforecolumnsset);
|
|
388
|
+
switch (config === null || config === void 0 ? void 0 : config.mode) {
|
|
389
|
+
case ColumnAutoSizeMode.autoSizeOnTextOverlap:
|
|
390
|
+
this.addEventListener('aftersourceset', aftersourceset);
|
|
391
|
+
this.addEventListener('afteredit', afteredit);
|
|
392
|
+
break;
|
|
393
|
+
case ColumnAutoSizeMode.autoSizeAll:
|
|
394
|
+
this.addEventListener('aftersourceset', aftersourceset);
|
|
395
|
+
this.addEventListener('afteredit', afterEditAll);
|
|
396
|
+
break;
|
|
397
|
+
default:
|
|
398
|
+
this.addEventListener('headerdblclick', headerDblClick);
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
async setSource(source) {
|
|
403
|
+
let autoSize = this.autoSizeColumns;
|
|
404
|
+
if (this.dataReject) {
|
|
405
|
+
this.dataReject();
|
|
406
|
+
this.clearPromise();
|
|
407
|
+
}
|
|
408
|
+
/** If data set first and no column provided await until get one */
|
|
409
|
+
if (!autoSize) {
|
|
410
|
+
const request = new Promise((resolve, reject) => {
|
|
411
|
+
this.dataResolve = resolve;
|
|
412
|
+
this.dataReject = reject;
|
|
413
|
+
});
|
|
414
|
+
try {
|
|
415
|
+
autoSize = await request;
|
|
416
|
+
}
|
|
417
|
+
catch (e) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// calculate sizes
|
|
422
|
+
index.each(autoSize, (_v, type) => {
|
|
423
|
+
const sizes = {};
|
|
424
|
+
index.each(autoSize[type], rgCol => {
|
|
425
|
+
// calculate size
|
|
426
|
+
rgCol.size = sizes[rgCol.index] = source.reduce((prev, rgRow) => Math.max(prev, this.getLength(rgRow[rgCol.prop])), this.getLength(rgCol.name || ''));
|
|
427
|
+
});
|
|
428
|
+
this.providers.dimension.setCustomSizes(type, sizes, true);
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
getLength(len) {
|
|
432
|
+
var _a;
|
|
433
|
+
const padding = 15;
|
|
434
|
+
if (!len) {
|
|
435
|
+
return 0;
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
const str = len.toString();
|
|
439
|
+
/**if exact calculation required proxy with html element, slow operation */
|
|
440
|
+
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.preciseSize) {
|
|
441
|
+
this.precsizeCalculationArea.innerText = str;
|
|
442
|
+
return this.precsizeCalculationArea.scrollWidth + padding * 2;
|
|
443
|
+
}
|
|
444
|
+
return str.length * this.letterBlockSize + padding * 2;
|
|
445
|
+
}
|
|
446
|
+
catch (e) {
|
|
447
|
+
return 0;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
afteredit(e) {
|
|
451
|
+
let data;
|
|
452
|
+
if (this.isRangeEdit(e)) {
|
|
453
|
+
data = e.data;
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
data = { 0: { [e.prop]: e.val } };
|
|
457
|
+
}
|
|
458
|
+
index.each(this.autoSizeColumns, (columns, type) => {
|
|
459
|
+
const sizes = {};
|
|
460
|
+
index.each(columns, rgCol => {
|
|
461
|
+
var _a;
|
|
462
|
+
// calculate size
|
|
463
|
+
const size = index.reduce_1(data, (prev, rgRow) => {
|
|
464
|
+
if (typeof rgRow[rgCol.prop] === 'undefined') {
|
|
465
|
+
return prev;
|
|
466
|
+
}
|
|
467
|
+
return Math.max(prev || 0, this.getLength(rgRow[rgCol.prop]));
|
|
468
|
+
}, undefined);
|
|
469
|
+
if (size && ((_a = rgCol.size) !== null && _a !== void 0 ? _a : 0) < size) {
|
|
470
|
+
rgCol.size = sizes[rgCol.index] = size;
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
this.providers.dimension.setCustomSizes(type, sizes, true);
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
afterEditAll(e) {
|
|
477
|
+
const props = {};
|
|
478
|
+
if (this.isRangeEdit(e)) {
|
|
479
|
+
index.each(e.data, r => index.each(r, (_v, p) => (props[p] = true)));
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
props[e.prop] = true;
|
|
483
|
+
}
|
|
484
|
+
index.each(this.autoSizeColumns, (columns, type) => {
|
|
485
|
+
const sizes = {};
|
|
486
|
+
index.each(columns, rgCol => {
|
|
487
|
+
if (props[rgCol.prop]) {
|
|
488
|
+
const size = this.getColumnSize(rgCol.index, type);
|
|
489
|
+
if (size) {
|
|
490
|
+
sizes[rgCol.index] = size;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
this.providers.dimension.setCustomSizes(type, sizes, true);
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
getColumnSize(index$1, type) {
|
|
498
|
+
var _a, _b;
|
|
499
|
+
const rgCol = (_b = (_a = this.autoSizeColumns) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b[index$1];
|
|
500
|
+
if (!rgCol) {
|
|
501
|
+
return 0;
|
|
502
|
+
}
|
|
503
|
+
return index.reduce_1(this.providers.data.stores, (r, s) => {
|
|
504
|
+
const perStore = index.reduce_1(s.store.get('items'), (prev, _row, i) => {
|
|
505
|
+
const item = index.getSourceItem(s.store, i);
|
|
506
|
+
return Math.max(prev || 0, this.getLength(item === null || item === void 0 ? void 0 : item[rgCol.prop]));
|
|
507
|
+
}, 0);
|
|
508
|
+
return Math.max(r, perStore);
|
|
509
|
+
}, rgCol.size || 0);
|
|
510
|
+
}
|
|
511
|
+
columnSet(columns) {
|
|
512
|
+
var _a;
|
|
513
|
+
for (let t of columnTypes) {
|
|
514
|
+
const type = t;
|
|
515
|
+
const cols = columns[type];
|
|
516
|
+
for (let i in cols) {
|
|
517
|
+
if (cols[i].autoSize || ((_a = this.config) === null || _a === void 0 ? void 0 : _a.allColumns)) {
|
|
518
|
+
if (!this.autoSizeColumns) {
|
|
519
|
+
this.autoSizeColumns = {};
|
|
520
|
+
}
|
|
521
|
+
if (!this.autoSizeColumns[type]) {
|
|
522
|
+
this.autoSizeColumns[type] = {};
|
|
523
|
+
}
|
|
524
|
+
this.autoSizeColumns[type][i] = Object.assign(Object.assign({}, cols[i]), { index: parseInt(i, 10) });
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (this.dataResolve) {
|
|
529
|
+
this.dataResolve(this.autoSizeColumns || {});
|
|
530
|
+
this.clearPromise();
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
clearPromise() {
|
|
534
|
+
this.dataResolve = null;
|
|
535
|
+
this.dataReject = null;
|
|
536
|
+
}
|
|
537
|
+
isRangeEdit(e) {
|
|
538
|
+
return !!e.data;
|
|
539
|
+
}
|
|
540
|
+
initiatePresizeElement() {
|
|
541
|
+
var _a;
|
|
542
|
+
const styleForFontTest = {
|
|
543
|
+
position: 'absolute',
|
|
544
|
+
fontSize: '14px',
|
|
545
|
+
height: '0',
|
|
546
|
+
width: '0',
|
|
547
|
+
whiteSpace: 'nowrap',
|
|
548
|
+
top: '0',
|
|
549
|
+
overflowX: 'scroll',
|
|
550
|
+
};
|
|
551
|
+
const el = document.createElement('div');
|
|
552
|
+
for (let s in styleForFontTest) {
|
|
553
|
+
el.style[s] = (_a = styleForFontTest[s]) !== null && _a !== void 0 ? _a : '';
|
|
554
|
+
}
|
|
555
|
+
el.classList.add('revo-test-container');
|
|
556
|
+
return el;
|
|
557
|
+
}
|
|
558
|
+
destroy() {
|
|
559
|
+
var _a;
|
|
560
|
+
super.destroy();
|
|
561
|
+
(_a = this.precsizeCalculationArea) === null || _a === void 0 ? void 0 : _a.remove();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
class StretchColumn extends BasePlugin {
|
|
566
|
+
constructor(revogrid, providers) {
|
|
567
|
+
super(revogrid, providers);
|
|
568
|
+
this.providers = providers;
|
|
569
|
+
this.stretchedColumn = null;
|
|
570
|
+
// calculate scroll bar size for current user session
|
|
571
|
+
this.scrollSize = index.getScrollbarSize(document);
|
|
572
|
+
// subscribe to column changes
|
|
573
|
+
const beforecolumnapplied = ({ detail: { columns }, }) => this.applyStretch(columns);
|
|
574
|
+
this.addEventListener('beforecolumnapplied', beforecolumnapplied);
|
|
575
|
+
}
|
|
576
|
+
setScroll({ type, hasScroll }) {
|
|
577
|
+
var _a;
|
|
578
|
+
if (type === 'rgRow' &&
|
|
579
|
+
this.stretchedColumn &&
|
|
580
|
+
((_a = this.stretchedColumn) === null || _a === void 0 ? void 0 : _a.initialSize) === this.stretchedColumn.size) {
|
|
581
|
+
if (hasScroll) {
|
|
582
|
+
this.stretchedColumn.size -= this.scrollSize;
|
|
583
|
+
this.apply();
|
|
584
|
+
this.dropChanges();
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
activateChanges() {
|
|
589
|
+
const setScroll = ({ detail }) => this.setScroll(detail);
|
|
590
|
+
this.addEventListener('scrollchange', setScroll);
|
|
591
|
+
}
|
|
592
|
+
dropChanges() {
|
|
593
|
+
this.stretchedColumn = null;
|
|
594
|
+
this.removeEventListener('scrollchange');
|
|
595
|
+
}
|
|
596
|
+
apply() {
|
|
597
|
+
if (!this.stretchedColumn) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
const type = 'rgCol';
|
|
601
|
+
const sizes = this.providers.dimension.stores[type].store.get('sizes');
|
|
602
|
+
this.providers.dimension.setCustomSizes(type, Object.assign(Object.assign({}, sizes), { [this.stretchedColumn.index]: this.stretchedColumn.size }), true);
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Apply stretch changes
|
|
606
|
+
*/
|
|
607
|
+
applyStretch(columns) {
|
|
608
|
+
// unsubscribe from all events
|
|
609
|
+
this.dropChanges();
|
|
610
|
+
// calculate grid size
|
|
611
|
+
let sizeDifference = this.revogrid.clientWidth - 1;
|
|
612
|
+
index.each(columns, (_, type) => {
|
|
613
|
+
const realSize = this.providers.dimension.stores[type].store.get('realSize');
|
|
614
|
+
sizeDifference -= realSize;
|
|
615
|
+
});
|
|
616
|
+
if (this.revogrid.rowHeaders) {
|
|
617
|
+
const itemsLength = this.providers.data.stores.rgRow.store.get('source').length;
|
|
618
|
+
const header = this.revogrid.rowHeaders;
|
|
619
|
+
const rowHeaderSize = rowHeaderUtils.calculateRowHeaderSize(itemsLength, typeof header === 'object' ? header : undefined);
|
|
620
|
+
if (rowHeaderSize) {
|
|
621
|
+
sizeDifference -= rowHeaderSize;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (sizeDifference > 0) {
|
|
625
|
+
// currently plugin accepts last column only
|
|
626
|
+
const index = columns.rgCol.length - 1;
|
|
627
|
+
const last = columns.rgCol[index];
|
|
628
|
+
/**
|
|
629
|
+
* has column
|
|
630
|
+
* no auto size applied
|
|
631
|
+
* size for column shouldn't be defined
|
|
632
|
+
*/
|
|
633
|
+
const colSize = (last === null || last === void 0 ? void 0 : last.size) || this.revogrid.colSize || 0;
|
|
634
|
+
const size = sizeDifference + colSize - 1;
|
|
635
|
+
if (last && !last.autoSize && colSize < size) {
|
|
636
|
+
this.stretchedColumn = {
|
|
637
|
+
initialSize: size,
|
|
638
|
+
index,
|
|
639
|
+
size,
|
|
640
|
+
};
|
|
641
|
+
this.apply();
|
|
642
|
+
this.activateChanges();
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Check plugin type is Stretch
|
|
649
|
+
*/
|
|
650
|
+
function isStretchPlugin(plugin) {
|
|
651
|
+
return !!plugin.applyStretch;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* The base implementation of `_.clamp` which doesn't coerce arguments.
|
|
656
|
+
*
|
|
657
|
+
* @private
|
|
658
|
+
* @param {number} number The number to clamp.
|
|
659
|
+
* @param {number} [lower] The lower bound.
|
|
660
|
+
* @param {number} upper The upper bound.
|
|
661
|
+
* @returns {number} Returns the clamped number.
|
|
662
|
+
*/
|
|
663
|
+
|
|
664
|
+
function baseClamp$1(number, lower, upper) {
|
|
665
|
+
if (number === number) {
|
|
666
|
+
if (upper !== undefined) {
|
|
667
|
+
number = number <= upper ? number : upper;
|
|
668
|
+
}
|
|
669
|
+
if (lower !== undefined) {
|
|
670
|
+
number = number >= lower ? number : lower;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return number;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
var _baseClamp = baseClamp$1;
|
|
677
|
+
|
|
678
|
+
var baseClamp = _baseClamp,
|
|
679
|
+
toInteger$1 = index.toInteger_1;
|
|
680
|
+
|
|
681
|
+
/** Used as references for the maximum length and index of an array. */
|
|
682
|
+
var MAX_ARRAY_LENGTH = 4294967295;
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Converts `value` to an integer suitable for use as the length of an
|
|
686
|
+
* array-like object.
|
|
687
|
+
*
|
|
688
|
+
* **Note:** This method is based on
|
|
689
|
+
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|
690
|
+
*
|
|
691
|
+
* @static
|
|
692
|
+
* @memberOf _
|
|
693
|
+
* @since 4.0.0
|
|
694
|
+
* @category Lang
|
|
695
|
+
* @param {*} value The value to convert.
|
|
696
|
+
* @returns {number} Returns the converted integer.
|
|
697
|
+
* @example
|
|
698
|
+
*
|
|
699
|
+
* _.toLength(3.2);
|
|
700
|
+
* // => 3
|
|
701
|
+
*
|
|
702
|
+
* _.toLength(Number.MIN_VALUE);
|
|
703
|
+
* // => 0
|
|
704
|
+
*
|
|
705
|
+
* _.toLength(Infinity);
|
|
706
|
+
* // => 4294967295
|
|
707
|
+
*
|
|
708
|
+
* _.toLength('3.2');
|
|
709
|
+
* // => 3
|
|
710
|
+
*/
|
|
711
|
+
function toLength$1(value) {
|
|
712
|
+
return value ? baseClamp(toInteger$1(value), 0, MAX_ARRAY_LENGTH) : 0;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
var toLength_1 = toLength$1;
|
|
716
|
+
|
|
717
|
+
var toInteger = index.toInteger_1,
|
|
718
|
+
toLength = toLength_1;
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* The base implementation of `_.fill` without an iteratee call guard.
|
|
722
|
+
*
|
|
723
|
+
* @private
|
|
724
|
+
* @param {Array} array The array to fill.
|
|
725
|
+
* @param {*} value The value to fill `array` with.
|
|
726
|
+
* @param {number} [start=0] The start position.
|
|
727
|
+
* @param {number} [end=array.length] The end position.
|
|
728
|
+
* @returns {Array} Returns `array`.
|
|
729
|
+
*/
|
|
730
|
+
function baseFill$1(array, value, start, end) {
|
|
731
|
+
var length = array.length;
|
|
732
|
+
|
|
733
|
+
start = toInteger(start);
|
|
734
|
+
if (start < 0) {
|
|
735
|
+
start = -start > length ? 0 : (length + start);
|
|
736
|
+
}
|
|
737
|
+
end = (end === undefined || end > length) ? length : toInteger(end);
|
|
738
|
+
if (end < 0) {
|
|
739
|
+
end += length;
|
|
740
|
+
}
|
|
741
|
+
end = start > end ? 0 : toLength(end);
|
|
742
|
+
while (start < end) {
|
|
743
|
+
array[start++] = value;
|
|
744
|
+
}
|
|
745
|
+
return array;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
var _baseFill = baseFill$1;
|
|
749
|
+
|
|
750
|
+
var baseFill = _baseFill,
|
|
751
|
+
isIterateeCall = index._isIterateeCall;
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Fills elements of `array` with `value` from `start` up to, but not
|
|
755
|
+
* including, `end`.
|
|
756
|
+
*
|
|
757
|
+
* **Note:** This method mutates `array`.
|
|
758
|
+
*
|
|
759
|
+
* @static
|
|
760
|
+
* @memberOf _
|
|
761
|
+
* @since 3.2.0
|
|
762
|
+
* @category Array
|
|
763
|
+
* @param {Array} array The array to fill.
|
|
764
|
+
* @param {*} value The value to fill `array` with.
|
|
765
|
+
* @param {number} [start=0] The start position.
|
|
766
|
+
* @param {number} [end=array.length] The end position.
|
|
767
|
+
* @returns {Array} Returns `array`.
|
|
768
|
+
* @example
|
|
769
|
+
*
|
|
770
|
+
* var array = [1, 2, 3];
|
|
771
|
+
*
|
|
772
|
+
* _.fill(array, 'a');
|
|
773
|
+
* console.log(array);
|
|
774
|
+
* // => ['a', 'a', 'a']
|
|
775
|
+
*
|
|
776
|
+
* _.fill(Array(3), 2);
|
|
777
|
+
* // => [2, 2, 2]
|
|
778
|
+
*
|
|
779
|
+
* _.fill([4, 6, 8, 10], '*', 1, 3);
|
|
780
|
+
* // => [4, '*', '*', 10]
|
|
781
|
+
*/
|
|
782
|
+
function fill(array, value, start, end) {
|
|
783
|
+
var length = array == null ? 0 : array.length;
|
|
784
|
+
if (!length) {
|
|
785
|
+
return [];
|
|
786
|
+
}
|
|
787
|
+
if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
|
|
788
|
+
start = 0;
|
|
789
|
+
end = length;
|
|
790
|
+
}
|
|
791
|
+
return baseFill(array, value, start, end);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
var fill_1 = fill;
|
|
795
|
+
|
|
796
|
+
const INITIAL = {
|
|
797
|
+
mime: 'text/csv',
|
|
798
|
+
fileKind: 'csv',
|
|
799
|
+
// BOM signature
|
|
800
|
+
bom: true,
|
|
801
|
+
columnDelimiter: ',',
|
|
802
|
+
rowDelimiter: '\r\n',
|
|
803
|
+
encoding: '',
|
|
804
|
+
};
|
|
805
|
+
// The ASCII character code 13 is called a Carriage Return or CR.
|
|
806
|
+
const CARRIAGE_RETURN = String.fromCharCode(13);
|
|
807
|
+
// Chr(13) followed by a Chr(10) that compose a proper CRLF.
|
|
808
|
+
const LINE_FEED = String.fromCharCode(10);
|
|
809
|
+
const DOUBLE_QT = String.fromCharCode(34);
|
|
810
|
+
const NO_BREAK_SPACE = String.fromCharCode(0xfeff);
|
|
811
|
+
const escapeRegex = new RegExp('"', 'g');
|
|
812
|
+
class ExportCsv {
|
|
813
|
+
constructor(options = {}) {
|
|
814
|
+
this.options = Object.assign(Object.assign({}, INITIAL), options);
|
|
815
|
+
}
|
|
816
|
+
doExport({ data, headers, props }) {
|
|
817
|
+
let result = this.options.bom ? NO_BREAK_SPACE : '';
|
|
818
|
+
// any header
|
|
819
|
+
if ((headers === null || headers === void 0 ? void 0 : headers.length) > 0) {
|
|
820
|
+
headers.forEach(header => {
|
|
821
|
+
// ignore empty
|
|
822
|
+
if (!header.length) {
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
result += this.prepareHeader(header, this.options.columnDelimiter);
|
|
826
|
+
result += this.options.rowDelimiter;
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
data.forEach((rgRow, index) => {
|
|
830
|
+
if (index > 0) {
|
|
831
|
+
result += this.options.rowDelimiter;
|
|
832
|
+
}
|
|
833
|
+
// support grouping
|
|
834
|
+
if (column_service.isGrouping(rgRow)) {
|
|
835
|
+
result += this.parseCell(column_service.getGroupingName(rgRow), this.options.columnDelimiter);
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
result += props.map(p => this.parseCell(rgRow[p], this.options.columnDelimiter)).join(this.options.columnDelimiter);
|
|
839
|
+
});
|
|
840
|
+
return result;
|
|
841
|
+
}
|
|
842
|
+
prepareHeader(columnHeaders, columnDelimiter) {
|
|
843
|
+
let result = '';
|
|
844
|
+
const newColumnHeaders = columnHeaders.map(v => this.parseCell(v, columnDelimiter, true));
|
|
845
|
+
result += newColumnHeaders.join(columnDelimiter);
|
|
846
|
+
return result;
|
|
847
|
+
}
|
|
848
|
+
parseCell(value, columnDelimiter, force = false) {
|
|
849
|
+
let escape = value;
|
|
850
|
+
if (typeof value !== 'string') {
|
|
851
|
+
escape = JSON.stringify(value);
|
|
852
|
+
}
|
|
853
|
+
const toEscape = [CARRIAGE_RETURN, DOUBLE_QT, LINE_FEED, columnDelimiter];
|
|
854
|
+
if (typeof escape === 'undefined') {
|
|
855
|
+
return '';
|
|
856
|
+
}
|
|
857
|
+
if (escape !== '' && (force || toEscape.some(i => escape.indexOf(i) >= 0))) {
|
|
858
|
+
return `"${escape.replace(escapeRegex, '""')}"`;
|
|
859
|
+
}
|
|
860
|
+
return escape;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
var ExportTypes;
|
|
865
|
+
(function (ExportTypes) {
|
|
866
|
+
ExportTypes["csv"] = "csv";
|
|
867
|
+
})(ExportTypes || (ExportTypes = {}));
|
|
868
|
+
class ExportFilePlugin extends BasePlugin {
|
|
869
|
+
/** Exports string */
|
|
870
|
+
async exportString(options = {}, t = ExportTypes.csv) {
|
|
871
|
+
const data = await this.beforeexport();
|
|
872
|
+
if (!data) {
|
|
873
|
+
return null;
|
|
874
|
+
}
|
|
875
|
+
return this.formatter(t, options).doExport(data);
|
|
876
|
+
}
|
|
877
|
+
/** Exports Blob */
|
|
878
|
+
async exportBlob(options = {}, t = ExportTypes.csv) {
|
|
879
|
+
return await this.getBlob(this.formatter(t, options));
|
|
880
|
+
}
|
|
881
|
+
/** Export file */
|
|
882
|
+
async exportFile(options = {}, t = ExportTypes.csv) {
|
|
883
|
+
const formatter = this.formatter(t, options);
|
|
884
|
+
// url
|
|
885
|
+
const URL = window.URL || window.webkitURL;
|
|
886
|
+
const a = document.createElement('a');
|
|
887
|
+
const { filename, fileKind } = formatter.options;
|
|
888
|
+
const name = `${filename}.${fileKind}`;
|
|
889
|
+
const blob = await this.getBlob(formatter);
|
|
890
|
+
const url = blob ? URL.createObjectURL(blob) : '';
|
|
891
|
+
a.style.display = 'none';
|
|
892
|
+
a.setAttribute('href', url);
|
|
893
|
+
a.setAttribute('download', name);
|
|
894
|
+
this.revogrid.appendChild(a);
|
|
895
|
+
a.dispatchEvent(new MouseEvent('click'));
|
|
896
|
+
this.revogrid.removeChild(a);
|
|
897
|
+
// delay for revoke, correct for some browsers
|
|
898
|
+
await index.timeout(120);
|
|
899
|
+
URL.revokeObjectURL(url);
|
|
900
|
+
}
|
|
901
|
+
/** Blob object */
|
|
902
|
+
async getBlob(formatter) {
|
|
903
|
+
const type = `${formatter.options.mime};charset=${formatter.options.encoding}`;
|
|
904
|
+
if (typeof Blob !== 'undefined') {
|
|
905
|
+
const data = await this.beforeexport();
|
|
906
|
+
if (!data) {
|
|
907
|
+
return null;
|
|
908
|
+
}
|
|
909
|
+
return new Blob([formatter.doExport(data)], { type });
|
|
910
|
+
}
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
// before event
|
|
914
|
+
async beforeexport() {
|
|
915
|
+
let data = await this.getData();
|
|
916
|
+
const event = this.emit('beforeexport', { data });
|
|
917
|
+
if (event.defaultPrevented) {
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
return event.detail.data;
|
|
921
|
+
}
|
|
922
|
+
async getData() {
|
|
923
|
+
const data = await this.getSource();
|
|
924
|
+
const colSource = [];
|
|
925
|
+
const colPromises = [];
|
|
926
|
+
columnTypes.forEach((t, i) => {
|
|
927
|
+
colPromises.push(this.getColPerSource(t).then(s => (colSource[i] = s)));
|
|
928
|
+
});
|
|
929
|
+
await Promise.all(colPromises);
|
|
930
|
+
const columns = {
|
|
931
|
+
headers: [],
|
|
932
|
+
props: [],
|
|
933
|
+
};
|
|
934
|
+
for (let source of colSource) {
|
|
935
|
+
source.headers.forEach((h, i) => {
|
|
936
|
+
if (!columns.headers[i]) {
|
|
937
|
+
columns.headers[i] = [];
|
|
938
|
+
}
|
|
939
|
+
columns.headers[i].push(...h);
|
|
940
|
+
});
|
|
941
|
+
columns.props.push(...source.props);
|
|
942
|
+
}
|
|
943
|
+
return Object.assign({ data }, columns);
|
|
944
|
+
}
|
|
945
|
+
async getColPerSource(t) {
|
|
946
|
+
const store = await this.revogrid.getColumnStore(t);
|
|
947
|
+
const source = store.get('source');
|
|
948
|
+
const virtualIndexes = store.get('items');
|
|
949
|
+
const depth = store.get('groupingDepth');
|
|
950
|
+
const groups = store.get('groups');
|
|
951
|
+
const colNames = [];
|
|
952
|
+
const colProps = [];
|
|
953
|
+
const visibleItems = virtualIndexes.reduce((r, v, virtualIndex) => {
|
|
954
|
+
const prop = source[v].prop;
|
|
955
|
+
colNames.push(source[v].name || '');
|
|
956
|
+
colProps.push(prop);
|
|
957
|
+
r[prop] = virtualIndex;
|
|
958
|
+
return r;
|
|
959
|
+
}, {});
|
|
960
|
+
const rows = this.getGroupHeaders(depth, groups, virtualIndexes, visibleItems);
|
|
961
|
+
rows.push(colNames);
|
|
962
|
+
return {
|
|
963
|
+
headers: rows,
|
|
964
|
+
props: colProps,
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
getGroupHeaders(depth, groups, items, visibleItems) {
|
|
968
|
+
const rows = [];
|
|
969
|
+
const template = fill_1(new Array(items.length), '');
|
|
970
|
+
for (let d = 0; d < depth; d++) {
|
|
971
|
+
const rgRow = [...template];
|
|
972
|
+
rows.push(rgRow);
|
|
973
|
+
if (!groups[d]) {
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
const levelGroups = groups[d];
|
|
977
|
+
// add names of groups
|
|
978
|
+
levelGroups.forEach((group) => {
|
|
979
|
+
const minIndex = this.findGroupStartIndex(group.ids, visibleItems);
|
|
980
|
+
if (typeof minIndex === 'number') {
|
|
981
|
+
rgRow[minIndex] = group.name;
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
return rows;
|
|
986
|
+
}
|
|
987
|
+
findGroupStartIndex(ids, visibleItems) {
|
|
988
|
+
let min;
|
|
989
|
+
ids.forEach(id => {
|
|
990
|
+
const current = visibleItems[id];
|
|
991
|
+
if (typeof current === 'number') {
|
|
992
|
+
if (typeof min !== 'number' || min > current) {
|
|
993
|
+
min = current;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
return min;
|
|
998
|
+
}
|
|
999
|
+
async getSource() {
|
|
1000
|
+
const data = [];
|
|
1001
|
+
const promisesData = [];
|
|
1002
|
+
rowTypes.forEach(t => {
|
|
1003
|
+
const dataPart = [];
|
|
1004
|
+
data.push(dataPart);
|
|
1005
|
+
const promise = this.revogrid.getVisibleSource(t).then((d) => dataPart.push(...d));
|
|
1006
|
+
promisesData.push(promise);
|
|
1007
|
+
});
|
|
1008
|
+
await Promise.all(promisesData);
|
|
1009
|
+
return data.reduce((r, v) => {
|
|
1010
|
+
r.push(...v);
|
|
1011
|
+
return r;
|
|
1012
|
+
}, []);
|
|
1013
|
+
}
|
|
1014
|
+
// get correct class for future multiple types support
|
|
1015
|
+
formatter(type, options = {}) {
|
|
1016
|
+
switch (type) {
|
|
1017
|
+
case ExportTypes.csv:
|
|
1018
|
+
return new ExportCsv(options);
|
|
1019
|
+
default:
|
|
1020
|
+
throw new Error('Unknown format');
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
const eq = (value, extra) => {
|
|
1026
|
+
if (typeof value === 'undefined' || (value === null && !extra)) {
|
|
1027
|
+
return true;
|
|
1028
|
+
}
|
|
1029
|
+
if (typeof value !== 'string') {
|
|
1030
|
+
value = JSON.stringify(value);
|
|
1031
|
+
}
|
|
1032
|
+
const filterVal = extra === null || extra === void 0 ? void 0 : extra.toString().toLocaleLowerCase();
|
|
1033
|
+
if ((filterVal === null || filterVal === void 0 ? void 0 : filterVal.length) === 0) {
|
|
1034
|
+
return true;
|
|
1035
|
+
}
|
|
1036
|
+
return value.toLocaleLowerCase() === filterVal;
|
|
1037
|
+
};
|
|
1038
|
+
const notEq = (value, extra) => !eq(value, extra);
|
|
1039
|
+
notEq.extra = 'input';
|
|
1040
|
+
eq.extra = 'input';
|
|
1041
|
+
|
|
1042
|
+
const gtThan = function (value, extra) {
|
|
1043
|
+
let conditionValue;
|
|
1044
|
+
if (typeof value === 'number' && typeof extra !== 'undefined' && extra !== null) {
|
|
1045
|
+
conditionValue = parseFloat(extra === null || extra === void 0 ? void 0 : extra.toString());
|
|
1046
|
+
return value > conditionValue;
|
|
1047
|
+
}
|
|
1048
|
+
return false;
|
|
1049
|
+
};
|
|
1050
|
+
gtThan.extra = 'input';
|
|
1051
|
+
|
|
1052
|
+
const gtThanEq = function (value, extra) {
|
|
1053
|
+
return eq(value, extra) || gtThan(value, extra);
|
|
1054
|
+
};
|
|
1055
|
+
gtThanEq.extra = 'input';
|
|
1056
|
+
|
|
1057
|
+
const lt = function (value, extra) {
|
|
1058
|
+
let conditionValue;
|
|
1059
|
+
if (typeof value === 'number' && typeof extra !== 'undefined' && extra !== null) {
|
|
1060
|
+
conditionValue = parseFloat(extra.toString());
|
|
1061
|
+
return value < conditionValue;
|
|
1062
|
+
}
|
|
1063
|
+
else {
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
lt.extra = 'input';
|
|
1068
|
+
|
|
1069
|
+
const lsEq = function (value, extra) {
|
|
1070
|
+
return eq(value, extra) || lt(value, extra);
|
|
1071
|
+
};
|
|
1072
|
+
lsEq.extra = 'input';
|
|
1073
|
+
|
|
1074
|
+
const set = (value) => !(value === '' || value === null || value === void 0);
|
|
1075
|
+
const notSet = (value) => !set(value);
|
|
1076
|
+
|
|
1077
|
+
const beginsWith = (value, extra) => {
|
|
1078
|
+
if (!value) {
|
|
1079
|
+
return false;
|
|
1080
|
+
}
|
|
1081
|
+
if (!extra) {
|
|
1082
|
+
return true;
|
|
1083
|
+
}
|
|
1084
|
+
if (typeof value !== 'string') {
|
|
1085
|
+
value = JSON.stringify(value);
|
|
1086
|
+
}
|
|
1087
|
+
if (typeof extra !== 'string') {
|
|
1088
|
+
extra = JSON.stringify(extra);
|
|
1089
|
+
}
|
|
1090
|
+
return value.toLocaleLowerCase().indexOf(extra.toLocaleLowerCase()) === 0;
|
|
1091
|
+
};
|
|
1092
|
+
beginsWith.extra = 'input';
|
|
1093
|
+
|
|
1094
|
+
const contains = (value, extra) => {
|
|
1095
|
+
if (!extra) {
|
|
1096
|
+
return true;
|
|
1097
|
+
}
|
|
1098
|
+
if (!value) {
|
|
1099
|
+
return false;
|
|
1100
|
+
}
|
|
1101
|
+
if (extra) {
|
|
1102
|
+
if (typeof value !== 'string') {
|
|
1103
|
+
value = JSON.stringify(value);
|
|
1104
|
+
}
|
|
1105
|
+
return value.toLocaleLowerCase().indexOf(extra.toString().toLowerCase()) > -1;
|
|
1106
|
+
}
|
|
1107
|
+
return true;
|
|
1108
|
+
};
|
|
1109
|
+
const notContains = (value, extra) => {
|
|
1110
|
+
return !contains(value, extra);
|
|
1111
|
+
};
|
|
1112
|
+
notContains.extra = 'input';
|
|
1113
|
+
contains.extra = 'input';
|
|
1114
|
+
|
|
1115
|
+
const filterNames = {
|
|
1116
|
+
none: 'None',
|
|
1117
|
+
empty: 'Not set',
|
|
1118
|
+
notEmpty: 'Set',
|
|
1119
|
+
eq: 'Equal',
|
|
1120
|
+
notEq: 'Not equal',
|
|
1121
|
+
begins: 'Begins with',
|
|
1122
|
+
contains: 'Contains',
|
|
1123
|
+
notContains: 'Does not contain',
|
|
1124
|
+
eqN: '=',
|
|
1125
|
+
neqN: '!=',
|
|
1126
|
+
gt: '>',
|
|
1127
|
+
gte: '>=',
|
|
1128
|
+
lt: '<',
|
|
1129
|
+
lte: '<=',
|
|
1130
|
+
};
|
|
1131
|
+
const filterEntities = {
|
|
1132
|
+
none: () => true,
|
|
1133
|
+
empty: notSet,
|
|
1134
|
+
notEmpty: set,
|
|
1135
|
+
eq: eq,
|
|
1136
|
+
notEq: notEq,
|
|
1137
|
+
begins: beginsWith,
|
|
1138
|
+
contains: contains,
|
|
1139
|
+
notContains: notContains,
|
|
1140
|
+
eqN: eq,
|
|
1141
|
+
neqN: notEq,
|
|
1142
|
+
gt: gtThan,
|
|
1143
|
+
gte: gtThanEq,
|
|
1144
|
+
lt: lt,
|
|
1145
|
+
lte: lsEq,
|
|
1146
|
+
};
|
|
1147
|
+
const filterTypes = {
|
|
1148
|
+
string: ['notEmpty', 'empty', 'eq', 'notEq', 'begins', 'contains', 'notContains'],
|
|
1149
|
+
number: ['notEmpty', 'empty', 'eqN', 'neqN', 'gt', 'gte', 'lt', 'lte'],
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
const FILTER_TRIMMED_TYPE = 'filter';
|
|
1153
|
+
const FILTER_CONFIG_CHANGED_EVENT = 'filterconfigchanged';
|
|
1154
|
+
class FilterPlugin extends BasePlugin {
|
|
1155
|
+
constructor(revogrid, providers, config) {
|
|
1156
|
+
var _a;
|
|
1157
|
+
super(revogrid, providers);
|
|
1158
|
+
this.revogrid = revogrid;
|
|
1159
|
+
this.filterCollection = {};
|
|
1160
|
+
this.multiFilterItems = {};
|
|
1161
|
+
this.possibleFilters = Object.assign({}, filterTypes);
|
|
1162
|
+
this.possibleFilterNames = Object.assign({}, filterNames);
|
|
1163
|
+
this.possibleFilterEntities = Object.assign({}, filterEntities);
|
|
1164
|
+
this.filterProp = filter_button.FILTER_PROP;
|
|
1165
|
+
if (config) {
|
|
1166
|
+
this.initConfig(config);
|
|
1167
|
+
}
|
|
1168
|
+
const headerclick = (e) => this.headerclick(e);
|
|
1169
|
+
const aftersourceset = async () => {
|
|
1170
|
+
const filterCollectionProps = Object.keys(this.filterCollection);
|
|
1171
|
+
if (filterCollectionProps.length > 0) {
|
|
1172
|
+
// handle old way of filtering by reworking FilterCollection to new MultiFilterItem
|
|
1173
|
+
filterCollectionProps.forEach((prop, index) => {
|
|
1174
|
+
if (!this.multiFilterItems[prop]) {
|
|
1175
|
+
this.multiFilterItems[prop] = [
|
|
1176
|
+
{
|
|
1177
|
+
id: index,
|
|
1178
|
+
type: this.filterCollection[prop].type,
|
|
1179
|
+
value: this.filterCollection[prop].value,
|
|
1180
|
+
relation: 'and',
|
|
1181
|
+
},
|
|
1182
|
+
];
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
await this.runFiltering();
|
|
1187
|
+
};
|
|
1188
|
+
this.addEventListener('headerclick', headerclick);
|
|
1189
|
+
this.addEventListener(FILTER_CONFIG_CHANGED_EVENT, ({ detail }) => {
|
|
1190
|
+
if (!detail) {
|
|
1191
|
+
this.clearFiltering();
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
if (typeof detail === 'object') {
|
|
1195
|
+
this.initConfig(detail);
|
|
1196
|
+
}
|
|
1197
|
+
aftersourceset();
|
|
1198
|
+
});
|
|
1199
|
+
this.addEventListener('aftersourceset', aftersourceset);
|
|
1200
|
+
this.addEventListener('filter', ({ detail }) => this.onFilterChange(detail));
|
|
1201
|
+
const existingNodes = this.revogrid.registerVNode.filter((n) => n.$tag$ !== 'revogr-filter-panel');
|
|
1202
|
+
this.revogrid.registerVNode = [
|
|
1203
|
+
...existingNodes,
|
|
1204
|
+
index$1.h("revogr-filter-panel", { 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) }),
|
|
1205
|
+
];
|
|
1206
|
+
}
|
|
1207
|
+
initConfig(config) {
|
|
1208
|
+
if (config.multiFilterItems) {
|
|
1209
|
+
this.multiFilterItems = Object.assign({}, config.multiFilterItems);
|
|
1210
|
+
}
|
|
1211
|
+
if (config.customFilters) {
|
|
1212
|
+
for (let cType in config.customFilters) {
|
|
1213
|
+
const cFilter = config.customFilters[cType];
|
|
1214
|
+
if (!this.possibleFilters[cFilter.columnFilterType]) {
|
|
1215
|
+
this.possibleFilters[cFilter.columnFilterType] = [];
|
|
1216
|
+
}
|
|
1217
|
+
this.possibleFilters[cFilter.columnFilterType].push(cType);
|
|
1218
|
+
this.possibleFilterEntities[cType] = cFilter.func;
|
|
1219
|
+
this.possibleFilterNames[cType] = cFilter.name;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
if (config.filterProp) {
|
|
1223
|
+
this.filterProp = config.filterProp;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* which filters has to be included/excluded
|
|
1227
|
+
* convinient way to exclude system filters
|
|
1228
|
+
*/
|
|
1229
|
+
const cfgInlcude = config.include;
|
|
1230
|
+
if (cfgInlcude) {
|
|
1231
|
+
const filters = {};
|
|
1232
|
+
for (let t in this.possibleFilters) {
|
|
1233
|
+
// validate filters, if appropriate function present
|
|
1234
|
+
const newTypes = this.possibleFilters[t].filter(f => cfgInlcude.indexOf(f) > -1);
|
|
1235
|
+
if (newTypes.length) {
|
|
1236
|
+
filters[t] = newTypes;
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
// if any valid filters provided show them
|
|
1240
|
+
if (Object.keys(filters).length > 0) {
|
|
1241
|
+
this.possibleFilters = filters;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
if (config.collection) {
|
|
1245
|
+
this.filterCollection = index.reduce_1(config.collection, (result, item, prop) => {
|
|
1246
|
+
if (this.possibleFilterEntities[item.type]) {
|
|
1247
|
+
result[prop] = item;
|
|
1248
|
+
}
|
|
1249
|
+
else {
|
|
1250
|
+
console.warn(`${item.type} type is not found.`);
|
|
1251
|
+
}
|
|
1252
|
+
return result;
|
|
1253
|
+
}, {});
|
|
1254
|
+
}
|
|
1255
|
+
if (config.localization) {
|
|
1256
|
+
if (config.localization.filterNames) {
|
|
1257
|
+
Object.entries(config.localization.filterNames).forEach(([k, v]) => {
|
|
1258
|
+
if (this.possibleFilterNames[k] != void 0) {
|
|
1259
|
+
this.possibleFilterNames[k] = v;
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
async headerclick(e) {
|
|
1266
|
+
var _a, _b, _c;
|
|
1267
|
+
const el = (_a = e.detail.originalEvent) === null || _a === void 0 ? void 0 : _a.target;
|
|
1268
|
+
if (!filter_button.isFilterBtn(el)) {
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
e.preventDefault();
|
|
1272
|
+
// close if same
|
|
1273
|
+
const changes = await ((_b = this.pop) === null || _b === void 0 ? void 0 : _b.getChanges());
|
|
1274
|
+
if (changes && (changes === null || changes === void 0 ? void 0 : changes.prop) === e.detail.prop) {
|
|
1275
|
+
(_c = this.pop) === null || _c === void 0 ? void 0 : _c.show();
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
if (!this.pop) {
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
// filter button clicked, open filter dialog
|
|
1282
|
+
const gridPos = this.revogrid.getBoundingClientRect();
|
|
1283
|
+
const buttonPos = el.getBoundingClientRect();
|
|
1284
|
+
const prop = e.detail.prop;
|
|
1285
|
+
this.pop.filterTypes = this.getColumnFilter(e.detail.filter);
|
|
1286
|
+
this.pop.show(Object.assign(Object.assign({}, this.filterCollection[prop]), { x: buttonPos.x - gridPos.x, y: buttonPos.y - gridPos.y + buttonPos.height, autoCorrect: true, prop }));
|
|
1287
|
+
}
|
|
1288
|
+
getColumnFilter(type) {
|
|
1289
|
+
let filterType = 'string';
|
|
1290
|
+
if (!type) {
|
|
1291
|
+
return { [filterType]: this.possibleFilters[filterType] };
|
|
1292
|
+
}
|
|
1293
|
+
// if custom column filter
|
|
1294
|
+
if (this.isValidType(type)) {
|
|
1295
|
+
filterType = type;
|
|
1296
|
+
// if multiple filters applied
|
|
1297
|
+
}
|
|
1298
|
+
else if (typeof type === 'object' && type.length) {
|
|
1299
|
+
return type.reduce((r, multiType) => {
|
|
1300
|
+
if (this.isValidType(multiType)) {
|
|
1301
|
+
r[multiType] = this.possibleFilters[multiType];
|
|
1302
|
+
}
|
|
1303
|
+
return r;
|
|
1304
|
+
}, {});
|
|
1305
|
+
}
|
|
1306
|
+
return { [filterType]: this.possibleFilters[filterType] };
|
|
1307
|
+
}
|
|
1308
|
+
isValidType(type) {
|
|
1309
|
+
return !!(typeof type === 'string' && this.possibleFilters[type]);
|
|
1310
|
+
}
|
|
1311
|
+
// called on internal component change
|
|
1312
|
+
async onFilterChange(filterItems) {
|
|
1313
|
+
this.multiFilterItems = filterItems;
|
|
1314
|
+
this.runFiltering();
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Triggers grid filtering
|
|
1318
|
+
*/
|
|
1319
|
+
async doFiltering(collection, items, columns, filterItems) {
|
|
1320
|
+
const columnsToUpdate = [];
|
|
1321
|
+
columns.forEach(rgCol => {
|
|
1322
|
+
const column = Object.assign({}, rgCol);
|
|
1323
|
+
const hasFilter = filterItems[column.prop];
|
|
1324
|
+
if (column[this.filterProp] && !hasFilter) {
|
|
1325
|
+
delete column[this.filterProp];
|
|
1326
|
+
columnsToUpdate.push(column);
|
|
1327
|
+
}
|
|
1328
|
+
if (!column[this.filterProp] && hasFilter) {
|
|
1329
|
+
columnsToUpdate.push(column);
|
|
1330
|
+
column[this.filterProp] = true;
|
|
1331
|
+
}
|
|
1332
|
+
});
|
|
1333
|
+
const itemsToFilter = this.getRowFilter(items, filterItems);
|
|
1334
|
+
// check is filter event prevented
|
|
1335
|
+
const { defaultPrevented, detail } = this.emit('beforefiltertrimmed', {
|
|
1336
|
+
collection,
|
|
1337
|
+
itemsToFilter,
|
|
1338
|
+
source: items,
|
|
1339
|
+
filterItems,
|
|
1340
|
+
});
|
|
1341
|
+
if (defaultPrevented) {
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
// check is trimmed event prevented
|
|
1345
|
+
const isAddedEvent = await this.revogrid.addTrimmed(detail.itemsToFilter, FILTER_TRIMMED_TYPE);
|
|
1346
|
+
if (isAddedEvent.defaultPrevented) {
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
// applies the hasFilter to the columns to show filter icon
|
|
1350
|
+
await this.revogrid.updateColumns(columnsToUpdate);
|
|
1351
|
+
this.emit('afterfilterapply');
|
|
1352
|
+
}
|
|
1353
|
+
async clearFiltering() {
|
|
1354
|
+
this.multiFilterItems = {};
|
|
1355
|
+
await this.runFiltering();
|
|
1356
|
+
}
|
|
1357
|
+
async runFiltering() {
|
|
1358
|
+
const collection = {};
|
|
1359
|
+
// handle old filterCollection to return the first filter only (if any) from multiFilterItems
|
|
1360
|
+
const filterProps = Object.keys(this.multiFilterItems);
|
|
1361
|
+
for (const prop of filterProps) {
|
|
1362
|
+
// check if we have any filter for a column
|
|
1363
|
+
if (this.multiFilterItems[prop].length > 0) {
|
|
1364
|
+
const firstFilterItem = this.multiFilterItems[prop][0];
|
|
1365
|
+
collection[prop] = {
|
|
1366
|
+
filter: filterEntities[firstFilterItem.type],
|
|
1367
|
+
type: firstFilterItem.type,
|
|
1368
|
+
value: firstFilterItem.value,
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
this.filterCollection = collection;
|
|
1373
|
+
const { source, columns } = await this.getData();
|
|
1374
|
+
const { defaultPrevented, detail } = this.emit('beforefilterapply', {
|
|
1375
|
+
collection: this.filterCollection,
|
|
1376
|
+
source,
|
|
1377
|
+
columns,
|
|
1378
|
+
filterItems: this.multiFilterItems,
|
|
1379
|
+
});
|
|
1380
|
+
if (defaultPrevented) {
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
this.doFiltering(detail.collection, detail.source, detail.columns, detail.filterItems);
|
|
1384
|
+
}
|
|
1385
|
+
async getData() {
|
|
1386
|
+
return {
|
|
1387
|
+
source: await this.revogrid.getSource(),
|
|
1388
|
+
columns: await this.revogrid.getColumns(),
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
getRowFilter(rows, filterItems) {
|
|
1392
|
+
const propKeys = Object.keys(filterItems);
|
|
1393
|
+
const trimmed = {};
|
|
1394
|
+
let propFilterSatisfiedCount = 0;
|
|
1395
|
+
let lastFilterResults = [];
|
|
1396
|
+
// each rows
|
|
1397
|
+
rows.forEach((model, rowIndex) => {
|
|
1398
|
+
// working on all props
|
|
1399
|
+
for (const prop of propKeys) {
|
|
1400
|
+
const propFilters = filterItems[prop];
|
|
1401
|
+
propFilterSatisfiedCount = 0;
|
|
1402
|
+
lastFilterResults = [];
|
|
1403
|
+
// testing each filter for a prop
|
|
1404
|
+
for (const [filterIndex, filterData] of propFilters.entries()) {
|
|
1405
|
+
// the filter LogicFunction based on the type
|
|
1406
|
+
const filter = this.possibleFilterEntities[filterData.type];
|
|
1407
|
+
// THE MAGIC OF FILTERING IS HERE
|
|
1408
|
+
if (filterData.relation === 'or') {
|
|
1409
|
+
lastFilterResults = [];
|
|
1410
|
+
if (filter(model[prop], filterData.value)) {
|
|
1411
|
+
continue;
|
|
1412
|
+
}
|
|
1413
|
+
propFilterSatisfiedCount++;
|
|
1414
|
+
}
|
|
1415
|
+
else {
|
|
1416
|
+
// 'and' relation will need to know the next filter
|
|
1417
|
+
// so we save this current filter to include it in the next filter
|
|
1418
|
+
lastFilterResults.push(!filter(model[prop], filterData.value));
|
|
1419
|
+
// check first if we have a filter on the next index to pair it with this current filter
|
|
1420
|
+
const nextFilterData = propFilters[filterIndex + 1];
|
|
1421
|
+
// stop the sequence if there is no next filter or if the next filter is not an 'and' relation
|
|
1422
|
+
if (!nextFilterData || nextFilterData.relation !== 'and') {
|
|
1423
|
+
// let's just continue since for sure propFilterSatisfiedCount cannot be satisfied
|
|
1424
|
+
if (lastFilterResults.indexOf(true) === -1) {
|
|
1425
|
+
lastFilterResults = [];
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
// we need to add all of the lastFilterResults since we need to satisfy all
|
|
1429
|
+
propFilterSatisfiedCount += lastFilterResults.length;
|
|
1430
|
+
lastFilterResults = [];
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
} // end of propFilters forEach
|
|
1434
|
+
// add to the list of removed/trimmed rows of filter condition is satisfied
|
|
1435
|
+
if (propFilterSatisfiedCount === propFilters.length)
|
|
1436
|
+
trimmed[rowIndex] = true;
|
|
1437
|
+
} // end of for-of propKeys
|
|
1438
|
+
});
|
|
1439
|
+
return trimmed;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
const COLUMN_DRAG_CLASS = 'column-drag-start';
|
|
1444
|
+
class ColumnOrderHandler {
|
|
1445
|
+
constructor() {
|
|
1446
|
+
this.offset = 0;
|
|
1447
|
+
}
|
|
1448
|
+
renderAutoscroll(_, parent) {
|
|
1449
|
+
if (!parent) {
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
this.autoscrollEl = document.createElement('div');
|
|
1453
|
+
this.autoscrollEl.classList.add('drag-auto-scroll-y');
|
|
1454
|
+
parent.appendChild(this.autoscrollEl);
|
|
1455
|
+
}
|
|
1456
|
+
autoscroll(pos, dataContainerSize, direction = 'translateX') {
|
|
1457
|
+
if (!this.autoscrollEl) {
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
const helperOffset = 10;
|
|
1461
|
+
// calculate current y position inside of the grid active holder
|
|
1462
|
+
// 3 - size of element + border
|
|
1463
|
+
const maxScroll = Math.min(pos + helperOffset, dataContainerSize - 3);
|
|
1464
|
+
this.autoscrollEl.style.transform = `${direction}(${maxScroll}px)`;
|
|
1465
|
+
this.autoscrollEl.scrollIntoView({
|
|
1466
|
+
block: 'nearest',
|
|
1467
|
+
inline: 'nearest',
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
start(e, { dataEl, gridRect, scrollEl, gridEl }, dir = 'left') {
|
|
1471
|
+
gridEl.classList.add(COLUMN_DRAG_CLASS);
|
|
1472
|
+
const scrollContainerRect = scrollEl.getBoundingClientRect();
|
|
1473
|
+
if (scrollContainerRect) {
|
|
1474
|
+
this.offset = scrollContainerRect[dir] - gridRect[dir];
|
|
1475
|
+
}
|
|
1476
|
+
this.renderAutoscroll(e, dataEl);
|
|
1477
|
+
}
|
|
1478
|
+
stop(gridEl) {
|
|
1479
|
+
var _a;
|
|
1480
|
+
gridEl.classList.remove(COLUMN_DRAG_CLASS);
|
|
1481
|
+
if (this.element) {
|
|
1482
|
+
this.element.hidden = true;
|
|
1483
|
+
}
|
|
1484
|
+
this.offset = 0;
|
|
1485
|
+
(_a = this.autoscrollEl) === null || _a === void 0 ? void 0 : _a.remove();
|
|
1486
|
+
this.autoscrollEl = undefined;
|
|
1487
|
+
}
|
|
1488
|
+
showHandler(pos, size, direction = 'translateX') {
|
|
1489
|
+
if (!this.element) {
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
// do not allow overcross top of the scrollable area, header excluded
|
|
1493
|
+
if (this.offset) {
|
|
1494
|
+
pos = Math.max(pos, this.offset);
|
|
1495
|
+
}
|
|
1496
|
+
// can not be bigger then grid end
|
|
1497
|
+
pos = Math.min(pos, size);
|
|
1498
|
+
this.element.style.transform = `${direction}(${pos}px)`;
|
|
1499
|
+
this.element.hidden = false;
|
|
1500
|
+
}
|
|
1501
|
+
render() {
|
|
1502
|
+
const el = this.element = document.createElement('div');
|
|
1503
|
+
el.classList.add('drag-position-y');
|
|
1504
|
+
el.hidden = true;
|
|
1505
|
+
return el;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* Plugin for column manual move
|
|
1511
|
+
*/
|
|
1512
|
+
const COLUMN_CLICK = headerCellRenderer.ON_COLUMN_CLICK;
|
|
1513
|
+
const MOVE = 'columndragmousemove';
|
|
1514
|
+
const DRAG_END = 'columndragend';
|
|
1515
|
+
const BEFORE_DRAG_END = 'beforecolumndragend';
|
|
1516
|
+
// use this event subscription to drop D&D for particular columns
|
|
1517
|
+
const DRAG_START = 'columndragstart';
|
|
1518
|
+
class ColumnPlugin extends BasePlugin {
|
|
1519
|
+
constructor(revogrid, providers) {
|
|
1520
|
+
super(revogrid, providers);
|
|
1521
|
+
this.revogrid = revogrid;
|
|
1522
|
+
this.providers = providers;
|
|
1523
|
+
this.moveFunc = debounce.debounce_1((e) => this.doMove(e), 5);
|
|
1524
|
+
this.staticDragData = null;
|
|
1525
|
+
this.dragData = null;
|
|
1526
|
+
this.localSubscriptions = {};
|
|
1527
|
+
this.orderUi = new ColumnOrderHandler();
|
|
1528
|
+
revogrid.appendChild(this.orderUi.render());
|
|
1529
|
+
revogrid.classList.add('column-draggable');
|
|
1530
|
+
// Register events
|
|
1531
|
+
this.localSubscriptions['mouseleave'] = {
|
|
1532
|
+
target: document,
|
|
1533
|
+
callback: (e) => this.onMouseOut(e),
|
|
1534
|
+
};
|
|
1535
|
+
this.localSubscriptions['mouseup'] = {
|
|
1536
|
+
target: document,
|
|
1537
|
+
callback: (e) => this.onMouseUp(e),
|
|
1538
|
+
};
|
|
1539
|
+
this.localSubscriptions['mousemove'] = {
|
|
1540
|
+
target: document,
|
|
1541
|
+
callback: (e) => this.move(e),
|
|
1542
|
+
};
|
|
1543
|
+
this.addEventListener(COLUMN_CLICK, ({ detail }) => this.dragStart(detail));
|
|
1544
|
+
}
|
|
1545
|
+
dragStart({ event, data }) {
|
|
1546
|
+
if (event.defaultPrevented) {
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
const { defaultPrevented } = headerCellRenderer.dispatch(this.revogrid, DRAG_START, data);
|
|
1550
|
+
// check if allowed to drag particulat column
|
|
1551
|
+
if (defaultPrevented) {
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
this.clearOrder();
|
|
1555
|
+
const { mouseleave, mouseup, mousemove } = this.localSubscriptions;
|
|
1556
|
+
mouseleave.target.addEventListener('mouseleave', mouseleave.callback);
|
|
1557
|
+
mouseup.target.addEventListener('mouseup', mouseup.callback);
|
|
1558
|
+
const dataEl = event.target.closest('revogr-header');
|
|
1559
|
+
const scrollEl = event.target.closest('revogr-viewport-scroll');
|
|
1560
|
+
if (!dataEl || !scrollEl) {
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
// no grouping drag and no row header column drag
|
|
1564
|
+
if (isColGrouping(data) || data.providers.type === 'rowHeaders') {
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
const cols = this.getDimension(data.pin || 'rgCol');
|
|
1568
|
+
const gridRect = this.revogrid.getBoundingClientRect();
|
|
1569
|
+
const elRect = dataEl.getBoundingClientRect();
|
|
1570
|
+
const startItem = index.getItemByPosition(cols, getLeftRelative(event.x, gridRect.left, elRect.left - gridRect.left));
|
|
1571
|
+
this.staticDragData = {
|
|
1572
|
+
startPos: event.x,
|
|
1573
|
+
startItem,
|
|
1574
|
+
data,
|
|
1575
|
+
dataEl,
|
|
1576
|
+
scrollEl,
|
|
1577
|
+
gridEl: this.revogrid,
|
|
1578
|
+
cols,
|
|
1579
|
+
};
|
|
1580
|
+
this.dragData = this.getData(this.staticDragData);
|
|
1581
|
+
mousemove.target.addEventListener('mousemove', mousemove.callback);
|
|
1582
|
+
this.orderUi.start(event, Object.assign(Object.assign({}, this.dragData), this.staticDragData));
|
|
1583
|
+
}
|
|
1584
|
+
doMove(e) {
|
|
1585
|
+
if (!this.staticDragData) {
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
const dragData = (this.dragData = this.getData(this.staticDragData));
|
|
1589
|
+
if (!dragData) {
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
const start = this.staticDragData.startPos;
|
|
1593
|
+
if (Math.abs(start - e.x) > 10) {
|
|
1594
|
+
const x = getLeftRelative(e.x, this.dragData.gridRect.left, this.dragData.scrollOffset);
|
|
1595
|
+
const rgCol = index.getItemByPosition(this.staticDragData.cols, x);
|
|
1596
|
+
this.orderUi.autoscroll(x, dragData.elRect.width);
|
|
1597
|
+
this.orderUi.showHandler(rgCol.end + dragData.scrollOffset, dragData.gridRect.width);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
move(e) {
|
|
1601
|
+
headerCellRenderer.dispatch(this.revogrid, MOVE, e);
|
|
1602
|
+
// then do move
|
|
1603
|
+
this.moveFunc(e);
|
|
1604
|
+
}
|
|
1605
|
+
onMouseOut(_) {
|
|
1606
|
+
this.clearOrder();
|
|
1607
|
+
}
|
|
1608
|
+
onMouseUp(e) {
|
|
1609
|
+
// apply new positions
|
|
1610
|
+
if (this.dragData && this.staticDragData) {
|
|
1611
|
+
let relativePos = getLeftRelative(e.x, this.dragData.gridRect.left, this.dragData.scrollOffset);
|
|
1612
|
+
if (relativePos < 0) {
|
|
1613
|
+
relativePos = 0;
|
|
1614
|
+
}
|
|
1615
|
+
const newPosition = index.getItemByPosition(this.staticDragData.cols, relativePos);
|
|
1616
|
+
const store = this.providers.column.stores[this.dragData.type].store;
|
|
1617
|
+
const items = [...store.get('items')];
|
|
1618
|
+
// prevent position change if needed
|
|
1619
|
+
const { defaultPrevented: stopDrag } = headerCellRenderer.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]] }));
|
|
1620
|
+
if (!stopDrag) {
|
|
1621
|
+
// todo: if move item out of group remove item from group
|
|
1622
|
+
const toMove = items.splice(this.staticDragData.startItem.itemIndex, 1);
|
|
1623
|
+
items.splice(newPosition.itemIndex, 0, ...toMove);
|
|
1624
|
+
store.set('items', items);
|
|
1625
|
+
}
|
|
1626
|
+
headerCellRenderer.dispatch(this.revogrid, DRAG_END, this.dragData);
|
|
1627
|
+
}
|
|
1628
|
+
this.clearOrder();
|
|
1629
|
+
}
|
|
1630
|
+
clearLocalSubscriptions() {
|
|
1631
|
+
index.each(this.localSubscriptions, ({ target, callback }, key) => target.removeEventListener(key, callback));
|
|
1632
|
+
}
|
|
1633
|
+
clearOrder() {
|
|
1634
|
+
this.staticDragData = null;
|
|
1635
|
+
this.dragData = null;
|
|
1636
|
+
this.clearLocalSubscriptions();
|
|
1637
|
+
this.orderUi.stop(this.revogrid);
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Clearing subscription
|
|
1641
|
+
*/
|
|
1642
|
+
clearSubscriptions() {
|
|
1643
|
+
super.clearSubscriptions();
|
|
1644
|
+
this.clearLocalSubscriptions();
|
|
1645
|
+
}
|
|
1646
|
+
getData({ gridEl, dataEl, data, }) {
|
|
1647
|
+
const gridRect = gridEl.getBoundingClientRect();
|
|
1648
|
+
const elRect = dataEl.getBoundingClientRect();
|
|
1649
|
+
const scrollOffset = elRect.left - gridRect.left;
|
|
1650
|
+
return {
|
|
1651
|
+
elRect,
|
|
1652
|
+
gridRect,
|
|
1653
|
+
type: data.pin || 'rgCol',
|
|
1654
|
+
scrollOffset,
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
getDimension(type) {
|
|
1658
|
+
return this.providers.dimension.stores[type].getCurrentState();
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
function getLeftRelative(absoluteX, gridPos, offset) {
|
|
1662
|
+
return absoluteX - gridPos - offset;
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
exports.AutoSizeColumnPlugin = AutoSizeColumnPlugin;
|
|
1666
|
+
exports.BasePlugin = BasePlugin;
|
|
1667
|
+
exports.ColumnPlugin = ColumnPlugin;
|
|
1668
|
+
exports.DimensionStore = DimensionStore;
|
|
1669
|
+
exports.ExportFilePlugin = ExportFilePlugin;
|
|
1670
|
+
exports.FILTER_CONFIG_CHANGED_EVENT = FILTER_CONFIG_CHANGED_EVENT;
|
|
1671
|
+
exports.FILTER_TRIMMED_TYPE = FILTER_TRIMMED_TYPE;
|
|
1672
|
+
exports.FilterPlugin = FilterPlugin;
|
|
1673
|
+
exports.StretchColumn = StretchColumn;
|
|
1674
|
+
exports.columnTypes = columnTypes;
|
|
1675
|
+
exports.gatherGroup = gatherGroup;
|
|
1676
|
+
exports.getColumnByProp = getColumnByProp;
|
|
1677
|
+
exports.getColumnSizes = getColumnSizes;
|
|
1678
|
+
exports.getColumnType = getColumnType;
|
|
1679
|
+
exports.getColumns = getColumns;
|
|
1680
|
+
exports.getLeftRelative = getLeftRelative;
|
|
1681
|
+
exports.isColGrouping = isColGrouping;
|
|
1682
|
+
exports.isRowType = isRowType;
|
|
1683
|
+
exports.isStretchPlugin = isStretchPlugin;
|
|
1684
|
+
exports.rowTypes = rowTypes;
|
|
1685
|
+
|
|
1686
|
+
//# sourceMappingURL=column.drag.plugin-e636b5af.js.map
|