@azrico/reactgrid 1.1.11 → 1.1.13

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,355 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.AzGrid = AzGrid;
7
- exports.default = void 0;
8
- require("@inovua/reactdatagrid-enterprise/index.css");
9
- require("@inovua/reactdatagrid-enterprise/theme/default-dark.css");
10
- require("@inovua/reactdatagrid-enterprise/theme/amber-dark.css");
11
- require("../themes/base_styles.css");
12
- require("../themes/grid.css");
13
- var _controls = require("@azrico/controls");
14
- var _react = _interopRequireDefault(require("react"));
15
- var _helpers = require("../func/helpers");
16
- var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
17
- var _clsx = _interopRequireDefault(require("clsx"));
18
- var _object = require("@azrico/object");
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
- /* -------------------------------------------------------------------------- */
21
- // const defaultfilterTypes: FilterTypes = {
22
- // string: {
23
- // type: 'string',
24
- // emptyValue: '',
25
- // operators: [
26
- // {
27
- // name: 'contains',
28
- // fn: ({ value, filterValue, data }) => {
29
- // console.log('fn');
30
- // return !filterValue ? true : value.indexOf(filterValue) != -1;
31
- // },
32
- // },
33
- // ],
34
- // },
35
- // };
36
- const defaultOptions = {
37
- //filterTypes: defaultfilterTypes,
38
- remoteFilter: false,
39
- remoteSort: false,
40
- rowReorderColumn: false,
41
- resizable: true,
42
- rowIndexColumn: true
43
- };
44
- const forcedOptions = {
45
- idProperty: '__table_id',
46
- nodesProperty: '__children'
47
- };
48
- const defaultColumnOptions = {
49
- draggable: false,
50
- lockable: false
51
- };
52
- const dynamic_option_names = ['selected', 'loading', 'limit', 'skip'];
53
- /* -------------------------------------------------------------------------- */
54
- function AzGrid(props) {
55
- /* -------------------------------------------------------------------------- */
56
- /* Columns */
57
- /* -------------------------------------------------------------------------- */
58
- const cached_columns = _react.default.useMemo(() => {
59
- return ApplyColumnData(props);
60
- }, [props.columns, props.leftColumns, props.rightColumns, props.editableColumns, props.columnExtensions, props.customColumns]);
61
- /* -------------------------------------------------------------------------- */
62
- /* Row changes */
63
- /* -------------------------------------------------------------------------- */
64
- const cached_data = _react.default.useRef();
65
- const last_cache_info = _react.default.useRef();
66
- const dataSource = _react.default.useCallback(async dt => {
67
- let result_data = undefined;
68
- let isUsingCache = false;
69
- const cacheInfo = {
70
- ds: props.dataSource,
71
- skip: dt.skip,
72
- limit: dt.limit
73
- };
74
- //check if we can used cached data
75
- //if the datasource is changed since last render, we should invalidate cache
76
- if (!validateCache(last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
77
- cached_data.current = undefined;
78
- last_cache_info.current = cacheInfo;
79
- }
80
- if (cached_data.current) {
81
- //cache is valid, use the cache
82
- isUsingCache = true;
83
- result_data = cached_data.current;
84
- } else {
85
- //cache is invalid, use the datasource again
86
- isUsingCache = false;
87
- if (typeof props.dataSource === 'function') {
88
- result_data = await props.dataSource(dt);
89
- } else result_data = props.dataSource;
90
- }
91
- //making sure the datasource is a valid object :
92
- if (!result_data) result_data = [];
93
- if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
94
- data: result_data
95
- };
96
- if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
97
- //no need to fix parent/child when using cache (it should be already fixed)
98
- if (!isUsingCache && props.allowChildRows) result_data.data = (0, _helpers.fix_parent_child_relations)(result_data.data);
99
- if (!result_data.count) result_data.count = result_data.data.length;
100
- //update cache
101
- cached_data.current = result_data;
102
- return result_data;
103
- }, [props.dataSource]);
104
- return _react.default.createElement(DataGrid, {
105
- ...props,
106
- columns: cached_columns,
107
- dataSource: dataSource,
108
- highlightedRow: props.highlightedRow
109
- });
110
- }
111
- /* -------------------------------------------------------------------------- */
112
- function DataGrid(props) {
113
- const {
114
- columns,
115
- dataSource,
116
- dark,
117
- contextMenuItems
118
- } = props;
119
- /* -------------------------------------------------------------------------- */
120
- const gridRef = _react.default.useRef(null);
121
- const click_data = _react.default.useRef(null);
122
- const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
123
- const [menuRow, set_menuRow] = _react.default.useState(null);
124
- _react.default.useEffect(() => {
125
- click_data.current = {};
126
- }, [dataSource]);
127
- /* --------------------------------- events --------------------------------- */
128
- const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
129
- if (_helpers.func_selection.has_selection()) return;
130
- update_menuAnchorEl(_helpers.func_selection.getVirtualElement(event.clientX, event.clientY));
131
- update_menuRow(rowProps.data);
132
- event.preventDefault();
133
- }, []);
134
- const onRowClick = _react.default.useCallback((rowProps, event) => {
135
- const nowDate = Date.now();
136
- const lastclick = click_data.current[get_row_id(rowProps)];
137
- if (lastclick) {
138
- const diffTime = Math.abs(nowDate - lastclick);
139
- if (diffTime < 400) {
140
- props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
141
- }
142
- }
143
- click_data.current[get_row_id(rowProps)] = nowDate;
144
- props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
145
- }, []);
146
- /* ------------------------------- ContextMenu ------------------------------ */
147
- const update_menuAnchorEl = _react.default.useCallback(el => {
148
- if (el) {
149
- set_menuAnchorEl(el);
150
- } else set_menuAnchorEl(null);
151
- }, []);
152
- const update_menuRow = _react.default.useCallback(r => {
153
- if (r) {
154
- set_menuRow(r);
155
- } else set_menuRow(null);
156
- }, []);
157
- /* -------------------------------------------------------------------------- */
158
- /* Create the grid */
159
- /* -------------------------------------------------------------------------- */
160
- const base_gridOptions = _react.default.useMemo(() => {
161
- const firstcolumn = columns[0];
162
- const licenseKey = props.licenseKey || get_default_key();
163
- const events = {
164
- onRowClick: onRowClick,
165
- onSkipChange: props.onSkipChange,
166
- onLimitChange: props.onLimitChange,
167
- onRowContextMenu: onRowContextMenu
168
- };
169
- const extra_ops = {
170
- onSelectionChange: props.onSelectionChange,
171
- licenseKey: licenseKey,
172
- treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
173
- renderRowDetails: props.RowDetail,
174
- theme: dark ? 'amber-dark' : 'default-light'
175
- };
176
- return {
177
- ...defaultOptions,
178
- ...events,
179
- ...extra_ops
180
- };
181
- }, [columns, props.allowChildRows, props.RowDetail]);
182
- const static_gridOptions = _react.default.useMemo(() => {
183
- return {
184
- ...base_gridOptions,
185
- ...props.gridOptions,
186
- ...forcedOptions
187
- };
188
- }, [props.gridOptions, base_gridOptions, forcedOptions]);
189
- const dynamic_gridOptions = _react.default.useMemo(() => {
190
- const res = {};
191
- dynamic_option_names.map(r => {
192
- res[r] = props[r];
193
- });
194
- return res;
195
- }, dynamic_option_names.map(r => props[r]));
196
- // const { width, height, ref: resize_ref } = useResizeDetector();
197
- return _react.default.createElement("div", {
198
- className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
199
- }, _react.default.createElement(_reactdatagridEnterprise.default, {
200
- ...static_gridOptions,
201
- ...dynamic_gridOptions,
202
- handle: ref => gridRef.current = ref ? ref.current : null,
203
- className: 'azgrid-filler',
204
- columns: columns,
205
- dataSource: dataSource
206
- }), _react.default.createElement(_controls.ContextMenu, {
207
- menuAnchorEl: menuAnchorEl,
208
- set_menuAnchorEl: update_menuAnchorEl,
209
- menuRow: menuRow,
210
- items: contextMenuItems
211
- }));
212
- }
213
- /* -------------------------------------------------------------------------- */
214
- /* -------------------------------------------------------------------------- */
215
- /* -------------------------------------------------------------------------- */
216
- /* -------------------------------------------------------------------------- */
217
- /**
218
- * Gets name of a column from its column object
219
- * @param obj
220
- * @returns
221
- */
222
- function get_col_name(obj) {
223
- if (!obj) return 'default';
224
- if (typeof obj == 'string') return obj;
225
- if (typeof obj != 'object') return 'default';
226
- return obj.name || obj.field || obj.key || obj.columnName || 'default';
227
- }
228
- /**
229
- * Gets name of a column from its column object
230
- * @param obj
231
- * @returns
232
- */
233
- function get_row_id(obj) {
234
- if (!obj) return 'default';
235
- if (typeof obj == 'string') return obj;
236
- if (typeof obj != 'object') return 'default';
237
- return obj.__table_id || obj.id || 'default';
238
- }
239
- /**
240
- * Gets default activation key for grid plugin
241
- * @returns
242
- */
243
- function get_default_key() {
244
- return 'ExpiryDate=2999-01-01,Z=1040577552';
245
- }
246
- //check if two cache objects are the same
247
- function validateCache(current, old, looseCheck = false) {
248
- if (!old || !(0, _object.object_equals)(current, old)) return false;
249
- if (looseCheck) return true;
250
- if (current.ds != old.ds) return false;
251
- return true;
252
- }
253
- /**
254
- * merges together all different props for columns
255
- * to build a single final column data array
256
- * @param props
257
- * @returns
258
- */
259
- function ApplyColumnData(props) {
260
- const final_columns = [];
261
- let mcols = props.columns || [];
262
- let mcolExts = props.columnExtensions || [];
263
- let rightColumns = props.rightColumns || [];
264
- let leftColumns = props.leftColumns || [];
265
- let editableColumns = props.editableColumns || [];
266
- let customColumns = props.customColumns || [];
267
- if (!Array.isArray(mcols)) return [];
268
- /* ------------------------------- fix columns ------------------------------ */
269
- mcols.map(r => {
270
- if (r == null) return null;
271
- if (typeof r === 'string') return {
272
- field: r,
273
- header: r
274
- };
275
- if (typeof r === 'object') {
276
- let final_cl = {
277
- name: get_col_name(r),
278
- header: r.header || r.title || r.name || '-',
279
- width: r.width || undefined
280
- };
281
- delete r.field;
282
- delete r.key;
283
- delete r.columnName;
284
- final_cl = {
285
- ...defaultColumnOptions,
286
- ...r,
287
- ...final_cl
288
- };
289
- return final_cl;
290
- }
291
- return null;
292
- }).forEach(r => {
293
- if (r != null) final_columns.push(r);
294
- });
295
- /* ---------------------------- apply extensions ---------------------------- */
296
- if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
297
- const ext = mcolExts[index];
298
- const ext_cl = get_col_name(ext);
299
- const mcol = final_columns.find(s => s.name === ext_cl);
300
- if (mcol) {
301
- for (const key in ext) {
302
- if (!mcol[key] && key != 'name') mcol[key] = ext[key];
303
- }
304
- }
305
- // if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
306
- }
307
- /* ------------------------------- frozen cols ------------------------------ */
308
- if (Array.isArray(leftColumns)) {
309
- for (let index = 0; index < leftColumns.length; index++) {
310
- const r = get_col_name(leftColumns[index]);
311
- const mcol = final_columns.find(s => s.name === r);
312
- if (mcol) {
313
- mcol.locked = 'start';
314
- }
315
- }
316
- }
317
- if (Array.isArray(rightColumns)) {
318
- for (let index = 0; index < rightColumns.length; index++) {
319
- const r = get_col_name(rightColumns[index]);
320
- const mcol = final_columns.find(s => s.name === r);
321
- if (mcol) {
322
- mcol.locked = 'end';
323
- }
324
- }
325
- }
326
- /* -------------------------------- ediatable ------------------------------- */
327
- if (Array.isArray(editableColumns)) {
328
- for (let index = 0; index < editableColumns.length; index++) {
329
- const r = get_col_name(editableColumns[index]);
330
- const mcol = final_columns.find(s => s.name === r);
331
- if (mcol) {
332
- // mcol.editor = editorWrapper;
333
- // mcol.editorOptions = {
334
- // editOnClick: true,
335
- // };
336
- }
337
- }
338
- }
339
- if (Array.isArray(customColumns)) {
340
- for (let index = 0; index < customColumns.length; index++) {
341
- const r = customColumns[index];
342
- const rn = get_col_name(r);
343
- const mcol = final_columns.find(s => s.name === rn);
344
- if (mcol) {
345
- //@ts-ignore
346
- mcol.render = r.render;
347
- }
348
- }
349
- }
350
- if (!Array.isArray(final_columns) || final_columns.length <= 0) return [];
351
- return final_columns;
352
- }
353
- /* -------------------------------------------------------------------------- */
354
- var _default = AzGrid;
355
- exports.default = _default;
@@ -1,3 +0,0 @@
1
- export * from './DataGrid';
2
- import AzGrid from './DataGrid';
3
- export default AzGrid;
@@ -1,23 +0,0 @@
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("./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
- var _default = _DataGrid.default;
23
- exports.default = _default;