@azrico/reactgrid 1.2.14 → 1.2.15

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.
@@ -1,291 +1,280 @@
1
- import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';
2
- import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
3
- import SelectEditor from '@inovua/reactdatagrid-community/SelectEditor';
4
- import { fix_parent_child_relations } from './func_child';
5
- import { object_equals } from '@azrico/object';
6
- const defaultColumnOptions = {
7
- draggable: false,
8
- lockable: false,
9
- editable: false,
10
- };
11
- export async function ApplyDataSource(datasource, props) {
12
- let result_data = undefined;
13
- let isUsingCache = false;
14
- const cacheInfo = { ds: datasource, skip: props.skip, limit: props.limit };
15
- //check if we can used cached data
16
- //if the datasource is changed since last render, we should invalidate cache
17
- if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
18
- props.cached_data.current = undefined;
19
- props.last_cache_info.current = cacheInfo;
20
- }
21
- if (props.cached_data.current) {
22
- //cache is valid, use the cache
23
- isUsingCache = true;
24
- result_data = props.cached_data.current;
25
- }
26
- else {
27
- //cache is invalid, use the datasource again
28
- isUsingCache = false;
29
- if (typeof datasource === 'function') {
30
- result_data = await datasource(props);
31
- }
32
- else
33
- result_data = datasource;
34
- }
35
- //making sure the datasource is a valid object :
36
- if (!result_data)
37
- result_data = [];
38
- if (Array.isArray(result_data) || typeof result_data !== 'object')
39
- result_data = { data: result_data };
40
- if (!Array.isArray(result_data.data))
41
- result_data.data = [result_data.data];
42
- //no need to fix parent/child when using cache (it should be already fixed)
43
- if (!isUsingCache && props.allowChildRows) {
44
- result_data.data = fix_parent_child_relations(result_data.data);
45
- }
46
- if (!result_data.count) {
47
- result_data.count = result_data.data.length;
48
- }
49
- //update cache
50
- props.cached_data.current = result_data;
51
- return result_data;
52
- }
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ApplyColumnData = ApplyColumnData;
7
+ exports.ApplyDataSource = ApplyDataSource;
8
+ exports.get_col_header = get_col_header;
9
+ exports.get_col_name = get_col_name;
10
+ exports.get_default_key = get_default_key;
11
+ exports.get_row_id = get_row_id;
12
+ exports.to_datasource = to_datasource;
13
+ exports.validateCache = validateCache;
14
+ var _BoolEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/BoolEditor"));
15
+ var _NumericEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/NumericEditor"));
16
+ var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
17
+ var _func_child = require("./func_child");
18
+ var _object = require("@azrico/object");
19
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+ const defaultColumnOptions = {
21
+ draggable: false,
22
+ lockable: false,
23
+ editable: false
24
+ };
25
+ async function ApplyDataSource(datasource, props) {
26
+ let result_data = undefined;
27
+ let isUsingCache = false;
28
+ const cacheInfo = {
29
+ ds: datasource,
30
+ skip: props.skip,
31
+ limit: props.limit
32
+ };
33
+ //check if we can used cached data
34
+ //if the datasource is changed since last render, we should invalidate cache
35
+ if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
36
+ props.cached_data.current = undefined;
37
+ props.last_cache_info.current = cacheInfo;
38
+ }
39
+ if (props.cached_data.current) {
40
+ //cache is valid, use the cache
41
+ isUsingCache = true;
42
+ result_data = props.cached_data.current;
43
+ } else {
44
+ //cache is invalid, use the datasource again
45
+ isUsingCache = false;
46
+ if (typeof datasource === 'function') {
47
+ result_data = await datasource(props);
48
+ } else result_data = datasource;
49
+ }
50
+ //making sure the datasource is a valid object :
51
+ if (!result_data) result_data = [];
52
+ if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
53
+ data: result_data
54
+ };
55
+ if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
56
+ //no need to fix parent/child when using cache (it should be already fixed)
57
+ if (!isUsingCache && props.allowChildRows) {
58
+ result_data.data = (0, _func_child.fix_parent_child_relations)(result_data.data);
59
+ }
60
+ if (!result_data.count) {
61
+ result_data.count = result_data.data.length;
62
+ }
63
+ //update cache
64
+ props.cached_data.current = result_data;
65
+ return result_data;
66
+ }
53
67
  /**
54
68
  * merges together all different props for columns
55
69
  * to build a single final column data array
56
70
  * @param column_data
57
71
  * @returns
58
- */
59
- export function ApplyColumnData(column_data) {
60
- const final_columns = [];
61
- if (!column_data)
62
- column_data = {};
63
- if (Array.isArray(column_data))
64
- column_data = { columns: column_data };
65
- let mcols = column_data.columns || [];
66
- let mcolExts = column_data.columnExtensions || [];
67
- let rightColumns = column_data.rightColumns || [];
68
- let leftColumns = column_data.leftColumns || [];
69
- let editableColumns = column_data.editableColumns || [];
70
- let customColumns = column_data.customColumns || [];
71
- if (!Array.isArray(mcols))
72
- return [];
73
- /* ------------------------------- fix columns ------------------------------ */
74
- mcols
75
- .map((r) => {
76
- if (r == null)
77
- return null;
78
- if (typeof r === 'string')
79
- return { field: r, header: r };
80
- if (typeof r === 'object') {
81
- let final_cl = {
82
- name: get_col_name(r),
83
- header: get_col_header(r),
84
- width: r.width || undefined,
85
- };
86
- final_cl = {
87
- ...defaultColumnOptions,
88
- ...r,
89
- ...final_cl,
90
- };
91
- return final_cl;
92
- }
93
- return null;
94
- })
95
- .forEach((r) => {
96
- if (r != null)
97
- final_columns.push(r);
98
- });
99
- /* ---------------------------- apply extensions ---------------------------- */
100
- if (mcolExts && Array.isArray(mcolExts))
101
- for (let index = 0; index < mcolExts.length; index++) {
102
- const ext = mcolExts[index];
103
- const ext_cl = get_col_name(ext);
104
- if (!ext_cl) {
105
- console.warn('ColumnExtension must have a name');
106
- continue;
107
- }
108
- const mcol = final_columns.find((s) => get_col_name(s) === ext_cl);
109
- if (mcol) {
110
- for (const key in ext) {
111
- if (!mcol[key] && key != 'name')
112
- mcol[key] = ext[key];
113
- }
114
- }
115
- // if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
116
- }
117
- /* ------------------------------- frozen cols ------------------------------ */
118
- if (Array.isArray(leftColumns)) {
119
- for (let index = 0; index < leftColumns.length; index++) {
120
- const r = get_col_name(leftColumns[index]);
121
- const mcol = final_columns.find((s) => get_col_name(s) === r);
122
- if (mcol) {
123
- mcol.locked = 'start';
124
- }
125
- }
126
- }
127
- if (Array.isArray(rightColumns)) {
128
- for (let index = 0; index < rightColumns.length; index++) {
129
- const r = get_col_name(rightColumns[index]);
130
- const mcol = final_columns.find((s) => get_col_name(s) === r);
131
- if (mcol) {
132
- mcol.locked = 'end';
133
- }
134
- }
135
- }
136
- /* -------------------------------- ediatable ------------------------------- */
137
- if (Array.isArray(editableColumns)) {
138
- for (let index = 0; index < editableColumns.length; index++) {
139
- const r = get_col_name(editableColumns[index]);
140
- const mcol = final_columns.find((s) => get_col_name(s) === r);
141
- if (mcol) {
142
- mcol.editable = true;
143
- }
144
- }
145
- }
146
- for (let index = 0; index < final_columns.length; index++) {
147
- const col = final_columns[index];
148
- if (col.type) {
149
- switch (col.type) {
150
- case 'combo':
151
- case 'select':
152
- //@ts-ignore
153
- col.editor = SelectEditor;
154
- break;
155
- case 'number':
156
- case 'numberic':
157
- //@ts-ignore
158
- col.editor = NumericEditor;
159
- break;
160
- case 'truefalse':
161
- case 'bool':
162
- //@ts-ignore
163
- col.editor = BoolEditor;
164
- break;
165
- }
166
- if (col.editable != false)
167
- col.editable = true;
168
- delete col.type;
169
- }
170
- //@ts-ignore
171
- if (!col.editorProps)
172
- col.editorProps = {};
173
- if (col.items) {
174
- //@ts-ignore
175
- if (!col.editorProps.idProperty)
176
- col.editorProps.idProperty = 'id';
177
- //@ts-ignore
178
- if (!col.editorProps.collapseOnSelect)
179
- col.editorProps.collapseOnSelect = true;
180
- //@ts-ignore
181
- col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
182
- delete col.items;
183
- }
184
- }
185
- /* -------------------------------------------------------------------------- */
186
- if (Array.isArray(customColumns)) {
187
- for (let index = 0; index < customColumns.length; index++) {
188
- const r = customColumns[index];
189
- const rn = get_col_name(r);
190
- const mcol = final_columns.find((s) => get_col_name(s) === rn);
191
- if (mcol) {
192
- //@ts-ignore
193
- mcol.render = r.render;
194
- }
195
- }
196
- }
197
- /* ------------------------------ apply renames ----------------------------- */
198
- for (let index = 0; index < final_columns.length; index++) {
199
- const col = final_columns[index];
200
- if (!col.name) {
201
- col.name = get_col_name(col);
202
- delete col.field;
203
- delete col.key;
204
- delete col.columnName;
205
- if (col.flex && !col.defaultFlex)
206
- col.defaultFlex = col.flex;
207
- }
208
- }
209
- /* -------------------------------------------------------------------------- */
210
- //console.log(final_columns);
211
- return final_columns;
212
- }
213
- export function to_datasource(arr, idProperty, valueAsID = true) {
214
- const res = [];
215
- let index = 0;
216
- if (Array.isArray(arr)) {
217
- arr.map((s) => {
218
- let elem = {};
219
- if (valueAsID)
220
- elem[idProperty] = String(s).toLowerCase();
221
- else
222
- elem[idProperty] = '_cid_' + index;
223
- if (typeof s === 'object')
224
- elem = { ...elem, ...s };
225
- else
226
- elem['label'] = s;
227
- res.push(elem);
228
- index++;
229
- });
230
- }
231
- return res;
232
- }
72
+ */
73
+ function ApplyColumnData(column_data) {
74
+ const final_columns = [];
75
+ if (!column_data) column_data = {};
76
+ if (Array.isArray(column_data)) column_data = {
77
+ columns: column_data
78
+ };
79
+ let mcols = column_data.columns || [];
80
+ let mcolExts = column_data.columnExtensions || [];
81
+ let rightColumns = column_data.rightColumns || [];
82
+ let leftColumns = column_data.leftColumns || [];
83
+ let editableColumns = column_data.editableColumns || [];
84
+ let customColumns = column_data.customColumns || [];
85
+ if (!Array.isArray(mcols)) return [];
86
+ /* ------------------------------- fix columns ------------------------------ */
87
+ mcols.map(r => {
88
+ if (r == null) return null;
89
+ if (typeof r === 'string') return {
90
+ field: r,
91
+ header: r
92
+ };
93
+ if (typeof r === 'object') {
94
+ let final_cl = {
95
+ name: get_col_name(r),
96
+ header: get_col_header(r),
97
+ width: r.width || undefined
98
+ };
99
+ final_cl = {
100
+ ...defaultColumnOptions,
101
+ ...r,
102
+ ...final_cl
103
+ };
104
+ return final_cl;
105
+ }
106
+ return null;
107
+ }).forEach(r => {
108
+ if (r != null) final_columns.push(r);
109
+ });
110
+ /* ---------------------------- apply extensions ---------------------------- */
111
+ if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
112
+ const ext = mcolExts[index];
113
+ const ext_cl = get_col_name(ext);
114
+ if (!ext_cl) {
115
+ console.warn('ColumnExtension must have a name');
116
+ continue;
117
+ }
118
+ const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
119
+ if (mcol) {
120
+ for (const key in ext) {
121
+ if (!mcol[key] && key != 'name') mcol[key] = ext[key];
122
+ }
123
+ }
124
+ // if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
125
+ }
126
+ /* ------------------------------- frozen cols ------------------------------ */
127
+ if (Array.isArray(leftColumns)) {
128
+ for (let index = 0; index < leftColumns.length; index++) {
129
+ const r = get_col_name(leftColumns[index]);
130
+ const mcol = final_columns.find(s => get_col_name(s) === r);
131
+ if (mcol) {
132
+ mcol.locked = 'start';
133
+ }
134
+ }
135
+ }
136
+ if (Array.isArray(rightColumns)) {
137
+ for (let index = 0; index < rightColumns.length; index++) {
138
+ const r = get_col_name(rightColumns[index]);
139
+ const mcol = final_columns.find(s => get_col_name(s) === r);
140
+ if (mcol) {
141
+ mcol.locked = 'end';
142
+ }
143
+ }
144
+ }
145
+ /* -------------------------------- ediatable ------------------------------- */
146
+ if (Array.isArray(editableColumns)) {
147
+ for (let index = 0; index < editableColumns.length; index++) {
148
+ const r = get_col_name(editableColumns[index]);
149
+ const mcol = final_columns.find(s => get_col_name(s) === r);
150
+ if (mcol) {
151
+ mcol.editable = true;
152
+ }
153
+ }
154
+ }
155
+ for (let index = 0; index < final_columns.length; index++) {
156
+ const col = final_columns[index];
157
+ if (col.type) {
158
+ switch (col.type) {
159
+ case 'combo':
160
+ case 'select':
161
+ //@ts-ignore
162
+ col.editor = _SelectEditor.default;
163
+ break;
164
+ case 'number':
165
+ case 'numberic':
166
+ //@ts-ignore
167
+ col.editor = _NumericEditor.default;
168
+ break;
169
+ case 'truefalse':
170
+ case 'bool':
171
+ //@ts-ignore
172
+ col.editor = _BoolEditor.default;
173
+ break;
174
+ }
175
+ if (col.editable != false) col.editable = true;
176
+ delete col.type;
177
+ }
178
+ //@ts-ignore
179
+ if (!col.editorProps) col.editorProps = {};
180
+ if (col.items) {
181
+ //@ts-ignore
182
+ if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
183
+ //@ts-ignore
184
+ if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
185
+ //@ts-ignore
186
+ col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
187
+ delete col.items;
188
+ }
189
+ }
190
+ /* -------------------------------------------------------------------------- */
191
+ if (Array.isArray(customColumns)) {
192
+ for (let index = 0; index < customColumns.length; index++) {
193
+ const r = customColumns[index];
194
+ const rn = get_col_name(r);
195
+ const mcol = final_columns.find(s => get_col_name(s) === rn);
196
+ if (mcol) {
197
+ //@ts-ignore
198
+ mcol.render = r.render;
199
+ }
200
+ }
201
+ }
202
+ /* ------------------------------ apply renames ----------------------------- */
203
+ for (let index = 0; index < final_columns.length; index++) {
204
+ const col = final_columns[index];
205
+ if (!col.name) {
206
+ col.name = get_col_name(col);
207
+ delete col.field;
208
+ delete col.key;
209
+ delete col.columnName;
210
+ if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
211
+ }
212
+ }
213
+ /* -------------------------------------------------------------------------- */
214
+ //console.log(final_columns);
215
+ return final_columns;
216
+ }
217
+ function to_datasource(arr, idProperty, valueAsID = true) {
218
+ const res = [];
219
+ let index = 0;
220
+ if (Array.isArray(arr)) {
221
+ arr.map(s => {
222
+ let elem = {};
223
+ if (valueAsID) elem[idProperty] = String(s).toLowerCase();else elem[idProperty] = '_cid_' + index;
224
+ if (typeof s === 'object') elem = {
225
+ ...elem,
226
+ ...s
227
+ };else elem['label'] = s;
228
+ res.push(elem);
229
+ index++;
230
+ });
231
+ }
232
+ return res;
233
+ }
233
234
  /**
234
235
  * Gets name of a column from its column object
235
236
  * @param obj
236
237
  * @returns
237
- */
238
- export function get_col_name(obj) {
239
- if (!obj)
240
- return '';
241
- if (typeof obj == 'string')
242
- return obj;
243
- if (typeof obj != 'object')
244
- return '';
245
- return obj.name || obj.field || obj.key || obj.columnName || '';
246
- }
238
+ */
239
+ function get_col_name(obj) {
240
+ if (!obj) return '';
241
+ if (typeof obj == 'string') return obj;
242
+ if (typeof obj != 'object') return '';
243
+ return obj.name || obj.field || obj.key || obj.columnName || '';
244
+ }
247
245
  /**
248
246
  * Gets header of a column
249
247
  * @param obj
250
248
  * @returns
251
- */
252
- export function get_col_header(obj) {
253
- if (!obj)
254
- return '';
255
- if (typeof obj == 'string')
256
- return obj;
257
- if (typeof obj != 'object')
258
- return '';
259
- return obj.header || obj.title || get_col_name(obj);
260
- }
249
+ */
250
+ function get_col_header(obj) {
251
+ if (!obj) return '';
252
+ if (typeof obj == 'string') return obj;
253
+ if (typeof obj != 'object') return '';
254
+ return obj.header || obj.title || get_col_name(obj);
255
+ }
261
256
  /**
262
257
  * Gets name of a column from its column object
263
258
  * @param obj
264
259
  * @returns
265
- */
266
- export function get_row_id(obj) {
267
- if (!obj)
268
- return '-1';
269
- if (typeof obj == 'string')
270
- return obj;
271
- if (typeof obj != 'object')
272
- return '-1';
273
- return obj.__table_id || obj.id || '-1';
274
- }
260
+ */
261
+ function get_row_id(obj) {
262
+ if (!obj) return '-1';
263
+ if (typeof obj == 'string') return obj;
264
+ if (typeof obj != 'object') return '-1';
265
+ return obj.__table_id || obj.id || '-1';
266
+ }
275
267
  /**
276
268
  * Gets default activation key for grid plugin
277
269
  * @returns
278
- */
279
- export function get_default_key() {
280
- return 'ExpiryDate=2999-01-01,Z=1040577552';
281
- }
282
- //check if two cache objects are the same
283
- export function validateCache(current, old, looseCheck = false) {
284
- if (!old || !object_equals(current, old))
285
- return false;
286
- if (looseCheck)
287
- return true;
288
- if (current.ds != old.ds)
289
- return false;
290
- return true;
291
- }
270
+ */
271
+ function get_default_key() {
272
+ return 'ExpiryDate=2999-01-01,Z=1040577552';
273
+ }
274
+ //check if two cache objects are the same
275
+ function validateCache(current, old, looseCheck = false) {
276
+ if (!old || !(0, _object.object_equals)(current, old)) return false;
277
+ if (looseCheck) return true;
278
+ if (current.ds != old.ds) return false;
279
+ return true;
280
+ }
package/dist/src/index.js CHANGED
@@ -1,6 +1,25 @@
1
- export * from './views/DataGrid';
2
- import AzGrid from './views/DataGrid';
3
- /* -------------------------------------------------------------------------- */
4
- export default AzGrid;
5
- // const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
6
- // root.render(<ExampleGrid />);
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {};
7
+ exports.default = void 0;
8
+ var _DataGrid = _interopRequireWildcard(require("./views/DataGrid"));
9
+ Object.keys(_DataGrid).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
12
+ if (key in exports && exports[key] === _DataGrid[key]) return;
13
+ Object.defineProperty(exports, key, {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _DataGrid[key];
17
+ }
18
+ });
19
+ });
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
+ /* -------------------------------------------------------------------------- */
23
+ var _default = _DataGrid.default; // const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
24
+ // root.render(<ExampleGrid />);
25
+ exports.default = _default;
@@ -0,0 +1,30 @@
1
+ .azgrid-container {
2
+ height: 100%;
3
+ width: 100%;
4
+ }
5
+ .azgrid-borderbox {
6
+ box-sizing: border-box;
7
+ }
8
+ .azgrid-filler {
9
+ height: 100%;
10
+ width: 100%;
11
+ }
12
+ .azgrid-nooverflow {
13
+ overflow: hidden;
14
+ }
15
+ .azgrid-testborder {
16
+ border: 3px solid red;
17
+ }
18
+ .azgrid-pad50px {
19
+ padding: 50px;
20
+ }
21
+ .azgrid-nopad {
22
+ padding: 0;
23
+ }
24
+ .azgrid-nomargin {
25
+ margin: 0;
26
+ }
27
+ .azgrid-delayedresize {
28
+ transition-property: 'width,height';
29
+ transition-delay: 200ms;
30
+ }
@@ -0,0 +1,20 @@
1
+ /* .InovuaReactDataGrid {
2
+ --grid-bg: '#fff';
3
+ }
4
+ .InovuaReactDataGrid {
5
+ background: var(--grid-bg) !important;
6
+ }
7
+ .InovuaReactDataGrid__header {
8
+ background: var(--grid-bg) !important;
9
+ }
10
+ .InovuaReactDataGrid__row {
11
+ background: var(--grid-bg) !important;
12
+ }
13
+ .InovuaReactDataGrid__cell {
14
+ background: var(--grid-bg) !important;
15
+ } */
16
+ .InovuaReactDataGrid__cell .InovuaReactDataGrid__cell__content {
17
+ height: 100%;
18
+ display: flex;
19
+ align-items: center;
20
+ }