@neovici/cosmoz-omnitable 7.1.0 → 8.0.0-beta.1
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/README.md +23 -0
- package/cosmoz-omnitable-column-amount.js +89 -320
- package/cosmoz-omnitable-column-autocomplete.js +36 -47
- package/cosmoz-omnitable-column-boolean.js +107 -209
- package/cosmoz-omnitable-column-date.js +89 -102
- package/cosmoz-omnitable-column-datetime.js +86 -119
- package/cosmoz-omnitable-column-list-data.js +4 -1
- package/cosmoz-omnitable-column-list-horizontal.js +20 -38
- package/cosmoz-omnitable-column-list-mixin.js +133 -140
- package/cosmoz-omnitable-column-list.js +19 -28
- package/cosmoz-omnitable-column-mixin.js +69 -447
- package/cosmoz-omnitable-column-number.js +91 -183
- package/cosmoz-omnitable-column-time.js +77 -162
- package/cosmoz-omnitable-column.js +49 -93
- package/cosmoz-omnitable-group-row.js +8 -87
- package/cosmoz-omnitable-header-row.js +9 -6
- package/cosmoz-omnitable-item-expand.js +0 -3
- package/cosmoz-omnitable-item-row.js +18 -127
- package/cosmoz-omnitable-styles.js +22 -5
- package/cosmoz-omnitable.js +73 -811
- package/lib/cosmoz-omnitable-amount-range-input.js +295 -0
- package/{cosmoz-omnitable-column-date-mixin.js → lib/cosmoz-omnitable-date-input-mixin.js} +4 -26
- package/lib/cosmoz-omnitable-date-range-input.js +81 -0
- package/lib/cosmoz-omnitable-datetime-range-input.js +75 -0
- package/lib/cosmoz-omnitable-number-range-input.js +159 -0
- package/{cosmoz-omnitable-column-range-mixin.js → lib/cosmoz-omnitable-range-input-mixin.js} +45 -129
- package/lib/cosmoz-omnitable-settings.js +22 -4
- package/lib/cosmoz-omnitable-time-range-input.js +130 -0
- package/lib/generic-sorter.js +35 -0
- package/lib/invoke.js +1 -0
- package/lib/memoize.js +54 -0
- package/lib/polymer-haunted-render-mixin.js +19 -0
- package/lib/save-as-csv-action.js +32 -0
- package/lib/save-as-xlsx-action.js +25 -0
- package/lib/use-canvas-width.js +1 -1
- package/lib/use-dom-columns.js +133 -0
- package/lib/use-hash-state.js +59 -0
- package/lib/use-layout.js +1 -1
- package/lib/use-omnitable.js +31 -4
- package/lib/use-processed-items.js +132 -0
- package/lib/use-saved-settings.js +12 -3
- package/lib/use-sort-and-group-options.js +30 -0
- package/lib/utils-amount.js +147 -0
- package/lib/utils-data.js +36 -0
- package/lib/utils-date.js +204 -0
- package/lib/utils-datetime.js +71 -0
- package/lib/utils-number.js +112 -0
- package/lib/utils-time.js +115 -0
- package/package.json +1 -1
- package/cosmoz-omnitable-repeater-mixin.js +0 -294
- package/lib/use-force-render.js +0 -8
- package/lib/use-render-on-column-updates.js +0 -18
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin';
|
|
2
|
-
import { render } from 'lit-html';
|
|
3
|
-
import { set } from '@polymer/polymer/lib/utils/path';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Allows manipulation of elements.
|
|
7
|
-
* @callback OmnitableRepeaterMixin~forEachElementCallback
|
|
8
|
-
* @param {HTMLElement} element
|
|
9
|
-
* @param {OmnitableColumn} column
|
|
10
|
-
* @param {TemplateInstance} instance
|
|
11
|
-
* @return {void}
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const editableRegex = /columns\.(\d*)\.editable/iu;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @polymer
|
|
19
|
-
* @mixinFunction
|
|
20
|
-
*/
|
|
21
|
-
export const repeaterMixin = dedupingMixin(base => class extends base { // eslint-disable-line max-lines-per-function
|
|
22
|
-
static get properties() {
|
|
23
|
-
return {
|
|
24
|
-
columns: {
|
|
25
|
-
type: Array
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
groupOnColumn: {
|
|
29
|
-
type: Object,
|
|
30
|
-
observer: '_groupOnColumnChanged'
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
constructor() {
|
|
36
|
-
super();
|
|
37
|
-
this._elements = [];
|
|
38
|
-
this._columnsObserver = null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Adds an observer to render the cells when the columns are changed.
|
|
43
|
-
* @return {void}
|
|
44
|
-
*/
|
|
45
|
-
trackColumns() {
|
|
46
|
-
if (this._columnsObserver) {
|
|
47
|
-
throw new Error('The columns are already tracked.');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this._createMethodObserver('_columnsChanged(columns.*)');
|
|
51
|
-
|
|
52
|
-
// HACK we have to muck around with the property effect references because
|
|
53
|
-
// _createMethodObserver does not provide any reference to the property
|
|
54
|
-
// effect so we can easily remove it
|
|
55
|
-
this._columnsObserver = this[this.PROPERTY_EFFECT_TYPES.OBSERVE]['columns']
|
|
56
|
-
.find(fx => fx.info.methodName === '_columnsChanged');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Stops reacting to column changes.
|
|
61
|
-
* @return {void}
|
|
62
|
-
*/
|
|
63
|
-
stopTrackingColumns() {
|
|
64
|
-
if (!this._columnsObserver) {
|
|
65
|
-
throw new Error('The columns are not tracked.');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
this._removePropertyEffect('columns', this.PROPERTY_EFFECT_TYPES.OBSERVE, this._columnsObserver);
|
|
69
|
-
this._columnsObserver = null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Renders all cells.
|
|
74
|
-
* @return {void}
|
|
75
|
-
*/
|
|
76
|
-
renderCells() {
|
|
77
|
-
this._addElements(0, this.columns.length);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Destroys all cells.
|
|
82
|
-
* @return {void}
|
|
83
|
-
*/
|
|
84
|
-
destroyCells() {
|
|
85
|
-
this._removeElements(0, this.columns);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Forwards a property change to all cells.
|
|
90
|
-
* @param {String} property the property
|
|
91
|
-
* @param {any} value the new value
|
|
92
|
-
* @return {void}
|
|
93
|
-
*/
|
|
94
|
-
forwardChange(property, value) {
|
|
95
|
-
this.forwardPathChange({
|
|
96
|
-
path: property,
|
|
97
|
-
value
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Forwards a path change to all cells.
|
|
103
|
-
* @param {Object} changeRecord the change record
|
|
104
|
-
* @return {void}
|
|
105
|
-
*/
|
|
106
|
-
forwardPathChange(changeRecord) {
|
|
107
|
-
this._elements.forEach(element =>
|
|
108
|
-
this._forwardNotifyPath(element.__instance, changeRecord.path, changeRecord.value, true)
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Runs a callback on each element.
|
|
114
|
-
* @param {OmnitableRepeaterMixin~forEachElementCallback} callback the callback
|
|
115
|
-
* @return {void}
|
|
116
|
-
*/
|
|
117
|
-
forEachElement(callback) {
|
|
118
|
-
this._elements.forEach(element => callback(element, element.__column, element.__instance));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/* eslint-disable no-empty-function, no-unused-vars */
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* The type of element to be repeated.
|
|
125
|
-
* Must be defined in implementors.
|
|
126
|
-
* @return {String} The type of element to be repeated.
|
|
127
|
-
*/
|
|
128
|
-
get _elementType() {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Slot name assigned to the repeated elements.
|
|
134
|
-
* Must be defined in implementors.
|
|
135
|
-
* @return {String} Slot name assigned to the repeated elements.
|
|
136
|
-
*/
|
|
137
|
-
get _slotName() {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Get a render function for the specified column
|
|
143
|
-
* Must be defined in implementors.
|
|
144
|
-
* @abstract
|
|
145
|
-
* @param {OmnitableColumnMixin} column - The column.
|
|
146
|
-
* @return {Function} - The render function.
|
|
147
|
-
*/
|
|
148
|
-
_getRenderFn(column) {}
|
|
149
|
-
|
|
150
|
-
/* eslint-enable no-empty-function, no-unused-vars */
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Configure a newly created repeated element
|
|
154
|
-
*
|
|
155
|
-
* @param {HTMLElement} element the root cell element
|
|
156
|
-
* @param {OmnitableColumnMixin} column the column
|
|
157
|
-
* @param {TemplateInstance} instance the template instance
|
|
158
|
-
* @return {void}
|
|
159
|
-
*/
|
|
160
|
-
_configureElement(element, column, instance) {
|
|
161
|
-
element.__instance = instance;
|
|
162
|
-
element.__column = column;
|
|
163
|
-
|
|
164
|
-
if (column === this.groupOnColumn) {
|
|
165
|
-
element.setAttribute('hidden', true);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
element.setAttribute('slot', this._slotName);
|
|
169
|
-
|
|
170
|
-
column.addEventListener('cosmoz-column-prop-changed', instance.render);
|
|
171
|
-
|
|
172
|
-
element.__cleanup = () => {
|
|
173
|
-
element.__instance = element.__column = element.column = null;
|
|
174
|
-
column.removeEventListener('cosmoz-column-prop-changed', instance.render);
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
_columnsChanged({
|
|
179
|
-
path, base, value
|
|
180
|
-
}) {
|
|
181
|
-
const reMatch = editableRegex.exec(path);
|
|
182
|
-
|
|
183
|
-
if (path === 'columns') {
|
|
184
|
-
if (this._elements && this._elements.length) {
|
|
185
|
-
const removedColumns = this._elements.map(element => {
|
|
186
|
-
return element.__column;
|
|
187
|
-
});
|
|
188
|
-
this._removeElements(0, removedColumns);
|
|
189
|
-
} else {
|
|
190
|
-
this._elements = [];
|
|
191
|
-
}
|
|
192
|
-
this._addElements(0, this.columns.length);
|
|
193
|
-
} else if (path === 'columns.splices') {
|
|
194
|
-
this._renderSplices(value.indexSplices);
|
|
195
|
-
} else if (reMatch) {
|
|
196
|
-
// eslint-disable-next-line no-bitwise
|
|
197
|
-
const index = reMatch[1] >> 0,
|
|
198
|
-
column = base[index];
|
|
199
|
-
this._removeElements(index, [column]);
|
|
200
|
-
this._addElements(index, 1);
|
|
201
|
-
} else if (path !== 'columns.length') {
|
|
202
|
-
// column property change
|
|
203
|
-
// eslint-disable-next-line no-console
|
|
204
|
-
console.warn('column property change', path);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
_renderSplices(splices) {
|
|
209
|
-
splices.forEach(splice => {
|
|
210
|
-
if (splice.removed.length) {
|
|
211
|
-
this._removeElements(splice.index, splice.removed);
|
|
212
|
-
}
|
|
213
|
-
if (splice.addedCount > 0) {
|
|
214
|
-
this._addElements(splice.index, splice.addedCount);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
_getInstance(updateFn) {
|
|
220
|
-
const state = {
|
|
221
|
-
item: this.item,
|
|
222
|
-
selected: this.selected,
|
|
223
|
-
expanded: this.expanded,
|
|
224
|
-
folded: this.folded
|
|
225
|
-
};
|
|
226
|
-
updateFn(state);
|
|
227
|
-
|
|
228
|
-
return {
|
|
229
|
-
_setPendingPropertyOrPath(path, value) {
|
|
230
|
-
set(state, path, value);
|
|
231
|
-
},
|
|
232
|
-
_flushProperties() {
|
|
233
|
-
updateFn(state);
|
|
234
|
-
},
|
|
235
|
-
render() {
|
|
236
|
-
updateFn(state);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
_addElements(start, count) {
|
|
242
|
-
const end = start + count;
|
|
243
|
-
for (let i = start; i < end; i++) {
|
|
244
|
-
const element = document.createElement(this._elementType),
|
|
245
|
-
column = this.columns[i],
|
|
246
|
-
renderFn = this._getRenderFn(column),
|
|
247
|
-
instance = this._getInstance(state => render(renderFn(column, state), element));
|
|
248
|
-
|
|
249
|
-
this._configureElement(element, column, instance);
|
|
250
|
-
|
|
251
|
-
if (i < this._elements.length) {
|
|
252
|
-
this.insertBefore(element, this._elements[i]);
|
|
253
|
-
} else {
|
|
254
|
-
this.appendChild(element);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
this._elements.splice(i, 0, element);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
_removeElements(start, removedColumns) {
|
|
262
|
-
this._elements
|
|
263
|
-
.splice(start, removedColumns.length)
|
|
264
|
-
.forEach(element => {
|
|
265
|
-
element.__cleanup();
|
|
266
|
-
this.removeChild(element);
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
_groupOnColumnChanged(column, previousColumn) {
|
|
271
|
-
if (!this._elements || !this._elements.length) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
if (previousColumn) {
|
|
275
|
-
const previousElement = this._elements.find(e => e.__column === previousColumn);
|
|
276
|
-
if (previousElement) {
|
|
277
|
-
previousElement.removeAttribute('hidden');
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (column) {
|
|
281
|
-
const element = this._elements.find(e => e.__column === column);
|
|
282
|
-
if (element) {
|
|
283
|
-
element.setAttribute('hidden', '');
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
_forwardNotifyPath(instance, path, value, flush = false) {
|
|
289
|
-
instance._setPendingPropertyOrPath(path, value, false, true);
|
|
290
|
-
if (flush) {
|
|
291
|
-
instance._flushProperties(true);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
});
|
package/lib/use-force-render.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'haunted';
|
|
2
|
-
import { useForceRender } from './use-force-render';
|
|
3
|
-
|
|
4
|
-
export const useRenderOnColumnUpdates = columns => {
|
|
5
|
-
const render = useForceRender();
|
|
6
|
-
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
if (columns == null) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// NOTE: this re-renders *all* of the cells when any column prop changes
|
|
13
|
-
// re-rendering costs around 2ms, so we can ignore this for now
|
|
14
|
-
// TODO: revisit this after haunted migration
|
|
15
|
-
columns.forEach(column => column.addEventListener('cosmoz-column-prop-changed', render));
|
|
16
|
-
return () => columns.forEach(column => column.removeEventListener('cosmoz-column-prop-changed', render));
|
|
17
|
-
}, [columns, render]);
|
|
18
|
-
};
|