@azrico/reactgrid 1.2.18 → 1.2.20

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