@azrico/reactgrid 1.2.2 → 1.2.3

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,481 +1,493 @@
1
- import '@inovua/reactdatagrid-enterprise/index.css';
2
- import '@inovua/reactdatagrid-enterprise/theme/default-dark.css';
3
- import '@inovua/reactdatagrid-enterprise/theme/amber-dark.css';
4
- import '../themes/base_styles.css';
5
- import '../themes/grid.css';
6
- import { ContextMenu } from '@azrico/controls';
7
- import React from 'react';
8
- import { fix_parent_child_relations, func_selection } from '../func/helpers';
9
- import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';
10
- import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
11
- import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
12
- import SelectEditor from '@inovua/reactdatagrid-community/SelectEditor';
13
- import clsx from 'clsx';
14
- import { object_equals } from '@azrico/object';
15
- import { useComponentSize } from 'react-use-size';
16
- /* -------------------------------------------------------------------------- */
17
- // const defaultfilterTypes: FilterTypes = {
18
- // string: {
19
- // type: 'string',
20
- // emptyValue: '',
21
- // operators: [
22
- // {
23
- // name: 'contains',
24
- // fn: ({ value, filterValue, data }) => {
25
- // console.log('fn');
26
- // return !filterValue ? true : value.indexOf(filterValue) != -1;
27
- // },
28
- // },
29
- // ],
30
- // },
31
- // };
32
- const defaultOptions = {
33
- //filterTypes: defaultfilterTypes,
34
- remoteFilter: false,
35
- remoteSort: false,
36
- editStartEvent: 'click',
37
- rowReorderColumn: false,
38
- resizable: true,
39
- columnUserSelect: true,
40
- rowIndexColumn: true,
41
- rowHeight: 35,
42
- maxRowHeight: 40,
43
- minRowHeight: 30,
44
- };
45
- const forcedOptions = {
46
- idProperty: '__table_id',
47
- nodesProperty: '__children',
48
- };
49
- const defaultColumnOptions = {
50
- draggable: false,
51
- lockable: false,
52
- editable: false,
53
- };
54
- const dynamic_option_names = ['selected', 'loading', 'limit', 'skip'];
55
- /* -------------------------------------------------------------------------- */
56
- export function AzGrid(props) {
57
- /* -------------------------------------------------------------------------- */
58
- /* Columns */
59
- /* -------------------------------------------------------------------------- */
60
- const cached_columns = React.useMemo(() => {
61
- return ApplyColumnData(props);
62
- }, [
63
- props.columns,
64
- props.leftColumns,
65
- props.rightColumns,
66
- props.editableColumns,
67
- props.columnExtensions,
68
- props.customColumns,
69
- ]);
70
- /* -------------------------------------------------------------------------- */
71
- /* Row changes */
72
- /* -------------------------------------------------------------------------- */
73
- const cached_data = React.useRef();
74
- const last_cache_info = React.useRef();
75
- const dataSource = React.useCallback(async (dt) => {
76
- let result_data = undefined;
77
- let isUsingCache = false;
78
- const cacheInfo = { ds: props.dataSource, skip: dt.skip, limit: dt.limit };
79
- //check if we can used cached data
80
- //if the datasource is changed since last render, we should invalidate cache
81
- if (!validateCache(last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
82
- cached_data.current = undefined;
83
- last_cache_info.current = cacheInfo;
84
- }
85
- if (cached_data.current) {
86
- //cache is valid, use the cache
87
- isUsingCache = true;
88
- result_data = cached_data.current;
89
- }
90
- else {
91
- //cache is invalid, use the datasource again
92
- isUsingCache = false;
93
- if (typeof props.dataSource === 'function') {
94
- result_data = await props.dataSource(dt);
95
- }
96
- else
97
- result_data = props.dataSource;
98
- }
99
- //making sure the datasource is a valid object :
100
- if (!result_data)
101
- result_data = [];
102
- if (Array.isArray(result_data) || typeof result_data !== 'object')
103
- result_data = { data: result_data };
104
- if (!Array.isArray(result_data.data))
105
- result_data.data = [result_data.data];
106
- //no need to fix parent/child when using cache (it should be already fixed)
107
- if (!isUsingCache && props.allowChildRows)
108
- result_data.data = fix_parent_child_relations(result_data.data);
109
- if (!result_data.count)
110
- result_data.count = result_data.data.length;
111
- //update cache
112
- cached_data.current = result_data;
113
- return result_data;
114
- }, [props.dataSource]);
115
- const base_gridOptions = React.useMemo(() => {
116
- const firstcolumn = cached_columns[0];
117
- const licenseKey = props.licenseKey || get_default_key();
118
- const events = {
119
- onSkipChange: props.onSkipChange,
120
- onLimitChange: props.onLimitChange,
121
- onEditComplete: props.onEditComplete,
122
- };
123
- const extra_ops = {
124
- onSelectionChange: props.onSelectionChange,
125
- licenseKey: licenseKey,
126
- editable: props.editable,
127
- treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
128
- renderRowDetails: props.RowDetail,
129
- theme: props.dark ? 'amber-dark' : 'default-light',
130
- };
131
- return { ...defaultOptions, ...events, ...extra_ops };
132
- }, [
133
- cached_columns,
134
- props.allowChildRows,
135
- props.editable,
136
- props.RowDetail,
137
- props.onEditComplete,
138
- ]);
139
- const static_gridOptions = React.useMemo(() => {
140
- return { ...base_gridOptions, ...props.gridOptions, ...forcedOptions };
141
- }, [props.gridOptions, base_gridOptions, forcedOptions]);
142
- const dynamic_gridOptions = React.useMemo(() => {
143
- const res = {};
144
- dynamic_option_names.map((r) => {
145
- res[r] = props[r];
146
- });
147
- return res;
148
- }, dynamic_option_names.map((r) => props[r]));
149
- return (React.createElement(DataGridEventsWrapper, { ...props, static_gridOptions: static_gridOptions, dynamic_gridOptions: dynamic_gridOptions, columns: cached_columns, dataSource: dataSource, highlightedRow: props.highlightedRow }));
150
- }
151
- /* -------------------------------------------------------------------------- */
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AzGrid = AzGrid;
7
+ exports.default = void 0;
8
+ exports.get_col_header = get_col_header;
9
+ exports.get_col_name = get_col_name;
10
+ require("@inovua/reactdatagrid-enterprise/index.css");
11
+ require("@inovua/reactdatagrid-enterprise/theme/default-dark.css");
12
+ require("@inovua/reactdatagrid-enterprise/theme/amber-dark.css");
13
+ require("../themes/base_styles.css");
14
+ require("../themes/grid.css");
15
+ var _controls = require("@azrico/controls");
16
+ var _react = _interopRequireDefault(require("react"));
17
+ var _helpers = require("../func/helpers");
18
+ var _BoolEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/BoolEditor"));
19
+ var _NumericEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/NumericEditor"));
20
+ var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
21
+ var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
22
+ var _clsx = _interopRequireDefault(require("clsx"));
23
+ var _object = require("@azrico/object");
24
+ var _reactUseSize = require("react-use-size");
25
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
+ /* -------------------------------------------------------------------------- */
27
+ // const defaultfilterTypes: FilterTypes = {
28
+ // string: {
29
+ // type: 'string',
30
+ // emptyValue: '',
31
+ // operators: [
32
+ // {
33
+ // name: 'contains',
34
+ // fn: ({ value, filterValue, data }) => {
35
+ // console.log('fn');
36
+ // return !filterValue ? true : value.indexOf(filterValue) != -1;
37
+ // },
38
+ // },
39
+ // ],
40
+ // },
41
+ // };
42
+ const defaultOptions = {
43
+ //filterTypes: defaultfilterTypes,
44
+ remoteFilter: false,
45
+ remoteSort: false,
46
+ editStartEvent: 'click',
47
+ rowReorderColumn: false,
48
+ resizable: true,
49
+ columnUserSelect: true,
50
+ rowIndexColumn: true,
51
+ rowHeight: 35,
52
+ maxRowHeight: 40,
53
+ minRowHeight: 30
54
+ };
55
+ const forcedOptions = {
56
+ idProperty: '__table_id',
57
+ nodesProperty: '__children'
58
+ };
59
+ const defaultColumnOptions = {
60
+ draggable: false,
61
+ lockable: false,
62
+ editable: false
63
+ };
64
+ const dynamic_option_names = ['selected', 'loading', 'limit', 'skip'];
65
+ /* -------------------------------------------------------------------------- */
66
+ function AzGrid(props) {
67
+ /* -------------------------------------------------------------------------- */
68
+ /* Columns */
69
+ /* -------------------------------------------------------------------------- */
70
+ const cached_columns = _react.default.useMemo(() => {
71
+ return ApplyColumnData(props);
72
+ }, [props.columns, props.leftColumns, props.rightColumns, props.editableColumns, props.columnExtensions, props.customColumns]);
73
+ /* -------------------------------------------------------------------------- */
74
+ /* Row changes */
75
+ /* -------------------------------------------------------------------------- */
76
+ const cached_data = _react.default.useRef();
77
+ const last_cache_info = _react.default.useRef();
78
+ const dataSource = _react.default.useCallback(async dt => {
79
+ let result_data = undefined;
80
+ let isUsingCache = false;
81
+ const cacheInfo = {
82
+ ds: props.dataSource,
83
+ skip: dt.skip,
84
+ limit: dt.limit
85
+ };
86
+ //check if we can used cached data
87
+ //if the datasource is changed since last render, we should invalidate cache
88
+ if (!validateCache(last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
89
+ cached_data.current = undefined;
90
+ last_cache_info.current = cacheInfo;
91
+ }
92
+ if (cached_data.current) {
93
+ //cache is valid, use the cache
94
+ isUsingCache = true;
95
+ result_data = cached_data.current;
96
+ } else {
97
+ //cache is invalid, use the datasource again
98
+ isUsingCache = false;
99
+ if (typeof props.dataSource === 'function') {
100
+ result_data = await props.dataSource(dt);
101
+ } else result_data = props.dataSource;
102
+ }
103
+ //making sure the datasource is a valid object :
104
+ if (!result_data) result_data = [];
105
+ if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
106
+ data: result_data
107
+ };
108
+ if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
109
+ //no need to fix parent/child when using cache (it should be already fixed)
110
+ if (!isUsingCache && props.allowChildRows) result_data.data = (0, _helpers.fix_parent_child_relations)(result_data.data);
111
+ if (!result_data.count) result_data.count = result_data.data.length;
112
+ //update cache
113
+ cached_data.current = result_data;
114
+ return result_data;
115
+ }, [props.dataSource]);
116
+ const base_gridOptions = _react.default.useMemo(() => {
117
+ const firstcolumn = cached_columns[0];
118
+ const licenseKey = props.licenseKey || get_default_key();
119
+ const events = {
120
+ onSkipChange: props.onSkipChange,
121
+ onLimitChange: props.onLimitChange,
122
+ onEditComplete: props.onEditComplete
123
+ };
124
+ const extra_ops = {
125
+ onSelectionChange: props.onSelectionChange,
126
+ licenseKey: licenseKey,
127
+ editable: props.editable,
128
+ treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
129
+ renderRowDetails: props.RowDetail,
130
+ theme: props.dark ? 'amber-dark' : 'default-light'
131
+ };
132
+ return {
133
+ ...defaultOptions,
134
+ ...events,
135
+ ...extra_ops
136
+ };
137
+ }, [cached_columns, props.allowChildRows, props.editable, props.RowDetail, props.onEditComplete]);
138
+ const static_gridOptions = _react.default.useMemo(() => {
139
+ return {
140
+ ...base_gridOptions,
141
+ ...props.gridOptions,
142
+ ...forcedOptions
143
+ };
144
+ }, [props.gridOptions, base_gridOptions, forcedOptions]);
145
+ const dynamic_gridOptions = _react.default.useMemo(() => {
146
+ const res = {};
147
+ dynamic_option_names.map(r => {
148
+ res[r] = props[r];
149
+ });
150
+ return res;
151
+ }, dynamic_option_names.map(r => props[r]));
152
+ return _react.default.createElement(DataGridEventsWrapper, {
153
+ ...props,
154
+ static_gridOptions: static_gridOptions,
155
+ dynamic_gridOptions: dynamic_gridOptions,
156
+ columns: cached_columns,
157
+ dataSource: dataSource,
158
+ highlightedRow: props.highlightedRow
159
+ });
160
+ }
161
+ /* -------------------------------------------------------------------------- */
152
162
  /**
153
163
  * Wrapper for menu events
154
164
  * @param props
155
165
  * @returns
156
- */
157
- function DataGridEventsWrapper(props) {
158
- /* -------------------------------------------------------------------------- */
159
- const click_data = React.useRef(null);
160
- const [menuAnchorEl, set_menuAnchorEl] = React.useState(null);
161
- const [menuRow, set_menuRow] = React.useState(null);
162
- /* --------------------------------- events --------------------------------- */
163
- const onRowContextMenu = React.useCallback((rowProps, event) => {
164
- if (func_selection.has_selection())
165
- return;
166
- update_menuRow(rowProps.data);
167
- update_menuAnchorEl(func_selection.getVirtualElement(event.clientX, event.clientY));
168
- event.preventDefault();
169
- }, []);
170
- const onRowClick = React.useCallback((rowProps, event) => {
171
- const nowDate = Date.now();
172
- const lastclick = click_data.current[get_row_id(rowProps)];
173
- if (lastclick) {
174
- const diffTime = Math.abs(nowDate - lastclick);
175
- if (diffTime < 400) {
176
- click_data.current[get_row_id(rowProps)] = null;
177
- return (props.onRowDoubleClick &&
178
- props.onRowDoubleClick(rowProps.rowIndex, rowProps.data));
179
- }
180
- }
181
- click_data.current[get_row_id(rowProps)] = nowDate;
182
- return props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
183
- }, [props.onRowClick, props.onRowDoubleClick]);
184
- React.useEffect(() => {
185
- click_data.current = {};
186
- }, [props.dataSource]);
187
- /* ------------------------------- ContextMenu ------------------------------ */
188
- const update_menuAnchorEl = React.useCallback((el) => {
189
- if (el) {
190
- set_menuAnchorEl(el);
191
- }
192
- else
193
- set_menuAnchorEl(null);
194
- }, []);
195
- const update_menuRow = React.useCallback((r) => {
196
- if (r) {
197
- set_menuRow(r);
198
- }
199
- else
200
- set_menuRow(null);
201
- }, []);
202
- /**
203
- * Merge click events into grid options
204
- */
205
- const static_gridOptions = React.useMemo(() => {
206
- const events = {
207
- onRowClick: onRowClick,
208
- onRowContextMenu: onRowContextMenu,
209
- };
210
- return { ...props.static_gridOptions, ...events };
211
- }, [props.static_gridOptions, onRowClick]);
212
- return (React.createElement(DataGridSizeWrapper, { ...props, static_gridOptions: static_gridOptions },
213
- React.createElement(ContextMenu, { menuAnchorEl: menuAnchorEl, set_menuAnchorEl: update_menuAnchorEl, menuRow: menuRow, items: props.contextMenuItems }),
214
- props.children));
215
- }
216
- function DataGridSizeWrapper(props) {
217
- // console.log(props);
218
- if (props.delayedSize) {
219
- return React.createElement(DataGridDelayedSize, { ...props });
220
- }
221
- else {
222
- return React.createElement(DataGridFlexSize, { ...props });
223
- }
224
- }
225
- function DataGridDelayedSize(props) {
226
- const gridRef = React.useRef(null);
227
- const { ref, height, width } = useComponentSize();
228
- return (React.createElement("div", { ref: ref, className: clsx(props.className, 'azgrid-nooverflow', 'azgrid-filler') },
229
- React.createElement(ReactDataGrid, { ...props.static_gridOptions, ...props.dynamic_gridOptions, handle: (ref) => (gridRef.current = ref ? ref.current : null), className: 'azgrid-delayedresize', style: {
230
- height: height,
231
- width: width,
232
- }, columns: props.columns, dataSource: props.dataSource }),
233
- props.children));
234
- }
235
- function DataGridFlexSize(props) {
236
- const gridRef = React.useRef(null);
237
- return (React.createElement("div", { className: clsx(props.className, 'azgrid-nooverflow', 'azgrid-filler') },
238
- React.createElement(ReactDataGrid, { ...props.static_gridOptions, ...props.dynamic_gridOptions, handle: (ref) => (gridRef.current = ref ? ref.current : null), className: 'azgrid-filler', columns: props.columns, dataSource: props.dataSource }),
239
- props.children));
240
- }
241
- /* -------------------------------------------------------------------------- */
242
- /* -------------------------------------------------------------------------- */
243
- /* -------------------------------------------------------------------------- */
244
- /* -------------------------------------------------------------------------- */
166
+ */
167
+ function DataGridEventsWrapper(props) {
168
+ /* -------------------------------------------------------------------------- */
169
+ const click_data = _react.default.useRef(null);
170
+ const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
171
+ const [menuRow, set_menuRow] = _react.default.useState(null);
172
+ /* --------------------------------- events --------------------------------- */
173
+ const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
174
+ if (_helpers.func_selection.has_selection()) return;
175
+ update_menuRow(rowProps.data);
176
+ update_menuAnchorEl(_helpers.func_selection.getVirtualElement(event.clientX, event.clientY));
177
+ event.preventDefault();
178
+ }, []);
179
+ const onRowClick = _react.default.useCallback((rowProps, event) => {
180
+ const nowDate = Date.now();
181
+ const lastclick = click_data.current[get_row_id(rowProps)];
182
+ if (lastclick) {
183
+ const diffTime = Math.abs(nowDate - lastclick);
184
+ if (diffTime < 400) {
185
+ click_data.current[get_row_id(rowProps)] = null;
186
+ return props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
187
+ }
188
+ }
189
+ click_data.current[get_row_id(rowProps)] = nowDate;
190
+ return props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
191
+ }, [props.onRowClick, props.onRowDoubleClick]);
192
+ _react.default.useEffect(() => {
193
+ click_data.current = {};
194
+ }, [props.dataSource]);
195
+ /* ------------------------------- ContextMenu ------------------------------ */
196
+ const update_menuAnchorEl = _react.default.useCallback(el => {
197
+ if (el) {
198
+ set_menuAnchorEl(el);
199
+ } else set_menuAnchorEl(null);
200
+ }, []);
201
+ const update_menuRow = _react.default.useCallback(r => {
202
+ if (r) {
203
+ set_menuRow(r);
204
+ } else set_menuRow(null);
205
+ }, []);
206
+ /**
207
+ * Merge click events into grid options
208
+ */
209
+ const static_gridOptions = _react.default.useMemo(() => {
210
+ const events = {
211
+ onRowClick: onRowClick,
212
+ onRowContextMenu: onRowContextMenu
213
+ };
214
+ return {
215
+ ...props.static_gridOptions,
216
+ ...events
217
+ };
218
+ }, [props.static_gridOptions, onRowClick]);
219
+ return _react.default.createElement(DataGridSizeWrapper, {
220
+ ...props,
221
+ static_gridOptions: static_gridOptions
222
+ }, _react.default.createElement(_controls.ContextMenu, {
223
+ menuAnchorEl: menuAnchorEl,
224
+ set_menuAnchorEl: update_menuAnchorEl,
225
+ menuRow: menuRow,
226
+ items: props.contextMenuItems
227
+ }), props.children);
228
+ }
229
+ function DataGridSizeWrapper(props) {
230
+ // console.log(props);
231
+ if (props.delayedSize) {
232
+ return _react.default.createElement(DataGridDelayedSize, {
233
+ ...props
234
+ });
235
+ } else {
236
+ return _react.default.createElement(DataGridFlexSize, {
237
+ ...props
238
+ });
239
+ }
240
+ }
241
+ function DataGridDelayedSize(props) {
242
+ const gridRef = _react.default.useRef(null);
243
+ const {
244
+ ref,
245
+ height,
246
+ width
247
+ } = (0, _reactUseSize.useComponentSize)();
248
+ return _react.default.createElement("div", {
249
+ ref: ref,
250
+ className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
251
+ }, _react.default.createElement(_reactdatagridEnterprise.default, {
252
+ ...props.static_gridOptions,
253
+ ...props.dynamic_gridOptions,
254
+ handle: ref => gridRef.current = ref ? ref.current : null,
255
+ className: 'azgrid-delayedresize',
256
+ style: {
257
+ height: height,
258
+ width: width
259
+ },
260
+ columns: props.columns,
261
+ dataSource: props.dataSource
262
+ }), props.children);
263
+ }
264
+ function DataGridFlexSize(props) {
265
+ const gridRef = _react.default.useRef(null);
266
+ return _react.default.createElement("div", {
267
+ className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
268
+ }, _react.default.createElement(_reactdatagridEnterprise.default, {
269
+ ...props.static_gridOptions,
270
+ ...props.dynamic_gridOptions,
271
+ handle: ref => gridRef.current = ref ? ref.current : null,
272
+ className: 'azgrid-filler',
273
+ columns: props.columns,
274
+ dataSource: props.dataSource
275
+ }), props.children);
276
+ }
277
+ /* -------------------------------------------------------------------------- */
278
+ /* -------------------------------------------------------------------------- */
279
+ /* -------------------------------------------------------------------------- */
280
+ /* -------------------------------------------------------------------------- */
245
281
  /**
246
282
  * merges together all different props for columns
247
283
  * to build a single final column data array
248
284
  * @param props
249
285
  * @returns
250
- */
251
- function ApplyColumnData(props) {
252
- const final_columns = [];
253
- let mcols = props.columns || [];
254
- let mcolExts = props.columnExtensions || [];
255
- let rightColumns = props.rightColumns || [];
256
- let leftColumns = props.leftColumns || [];
257
- let editableColumns = props.editableColumns || [];
258
- let customColumns = props.customColumns || [];
259
- if (!Array.isArray(mcols))
260
- return [];
261
- /* ------------------------------- fix columns ------------------------------ */
262
- mcols
263
- .map((r) => {
264
- if (r == null)
265
- return null;
266
- if (typeof r === 'string')
267
- return { field: r, header: r };
268
- if (typeof r === 'object') {
269
- let final_cl = {
270
- name: get_col_name(r),
271
- header: get_col_header(r),
272
- width: r.width || undefined,
273
- };
274
- final_cl = {
275
- ...defaultColumnOptions,
276
- ...r,
277
- ...final_cl,
278
- };
279
- return final_cl;
280
- }
281
- return null;
282
- })
283
- .forEach((r) => {
284
- if (r != null)
285
- final_columns.push(r);
286
- });
287
- /* ---------------------------- apply extensions ---------------------------- */
288
- if (mcolExts && Array.isArray(mcolExts))
289
- for (let index = 0; index < mcolExts.length; index++) {
290
- const ext = mcolExts[index];
291
- const ext_cl = get_col_name(ext);
292
- if (!ext_cl) {
293
- console.warn('ColumnExtension must have a name');
294
- continue;
295
- }
296
- const mcol = final_columns.find((s) => get_col_name(s) === ext_cl);
297
- if (mcol) {
298
- for (const key in ext) {
299
- if (!mcol[key] && key != 'name')
300
- mcol[key] = ext[key];
301
- }
302
- }
303
- // if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
304
- }
305
- /* ------------------------------- frozen cols ------------------------------ */
306
- if (Array.isArray(leftColumns)) {
307
- for (let index = 0; index < leftColumns.length; index++) {
308
- const r = get_col_name(leftColumns[index]);
309
- const mcol = final_columns.find((s) => get_col_name(s) === r);
310
- if (mcol) {
311
- mcol.locked = 'start';
312
- }
313
- }
314
- }
315
- if (Array.isArray(rightColumns)) {
316
- for (let index = 0; index < rightColumns.length; index++) {
317
- const r = get_col_name(rightColumns[index]);
318
- const mcol = final_columns.find((s) => get_col_name(s) === r);
319
- if (mcol) {
320
- mcol.locked = 'end';
321
- }
322
- }
323
- }
324
- /* -------------------------------- ediatable ------------------------------- */
325
- if (Array.isArray(editableColumns)) {
326
- for (let index = 0; index < editableColumns.length; index++) {
327
- const r = get_col_name(editableColumns[index]);
328
- const mcol = final_columns.find((s) => get_col_name(s) === r);
329
- if (mcol) {
330
- mcol.editable = true;
331
- }
332
- }
333
- }
334
- for (let index = 0; index < final_columns.length; index++) {
335
- const col = final_columns[index];
336
- if (col.type) {
337
- switch (col.type) {
338
- case 'combo':
339
- case 'select':
340
- //@ts-ignore
341
- col.editor = SelectEditor;
342
- break;
343
- case 'number':
344
- case 'numberic':
345
- //@ts-ignore
346
- col.editor = NumericEditor;
347
- break;
348
- case 'truefalse':
349
- case 'bool':
350
- //@ts-ignore
351
- col.editor = BoolEditor;
352
- break;
353
- }
354
- if (col.editable != false)
355
- col.editable = true;
356
- delete col.type;
357
- }
358
- //@ts-ignore
359
- if (!col.editorProps)
360
- col.editorProps = {};
361
- if (col.items) {
362
- //@ts-ignore
363
- if (!col.editorProps.idProperty)
364
- col.editorProps.idProperty = 'id';
365
- //@ts-ignore
366
- if (!col.editorProps.collapseOnSelect)
367
- col.editorProps.collapseOnSelect = true;
368
- //@ts-ignore
369
- col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
370
- delete col.items;
371
- }
372
- }
373
- /* -------------------------------------------------------------------------- */
374
- if (Array.isArray(customColumns)) {
375
- for (let index = 0; index < customColumns.length; index++) {
376
- const r = customColumns[index];
377
- const rn = get_col_name(r);
378
- const mcol = final_columns.find((s) => get_col_name(s) === rn);
379
- if (mcol) {
380
- //@ts-ignore
381
- mcol.render = r.render;
382
- }
383
- }
384
- }
385
- /* ------------------------------ apply renames ----------------------------- */
386
- for (let index = 0; index < final_columns.length; index++) {
387
- const col = final_columns[index];
388
- if (!col.name) {
389
- col.name = get_col_name(col);
390
- delete col.field;
391
- delete col.key;
392
- delete col.columnName;
393
- if (col.flex && !col.defaultFlex)
394
- col.defaultFlex = col.flex;
395
- }
396
- }
397
- /* -------------------------------------------------------------------------- */
398
- //console.log(final_columns);
399
- return final_columns;
400
- }
401
- function to_datasource(arr, idProperty, valueAsID = true) {
402
- const res = [];
403
- let index = 0;
404
- if (Array.isArray(arr)) {
405
- arr.map((s) => {
406
- let elem = {};
407
- if (valueAsID)
408
- elem[idProperty] = String(s).toLowerCase();
409
- else
410
- elem[idProperty] = '_cid_' + index;
411
- if (typeof s === 'object')
412
- elem = { ...elem, ...s };
413
- else
414
- elem['label'] = s;
415
- res.push(elem);
416
- index++;
417
- });
418
- }
419
- return res;
420
- }
286
+ */
287
+ function ApplyColumnData(props) {
288
+ const final_columns = [];
289
+ let mcols = props.columns || [];
290
+ let mcolExts = props.columnExtensions || [];
291
+ let rightColumns = props.rightColumns || [];
292
+ let leftColumns = props.leftColumns || [];
293
+ let editableColumns = props.editableColumns || [];
294
+ let customColumns = props.customColumns || [];
295
+ if (!Array.isArray(mcols)) return [];
296
+ /* ------------------------------- fix columns ------------------------------ */
297
+ mcols.map(r => {
298
+ if (r == null) return null;
299
+ if (typeof r === 'string') return {
300
+ field: r,
301
+ header: r
302
+ };
303
+ if (typeof r === 'object') {
304
+ let final_cl = {
305
+ name: get_col_name(r),
306
+ header: get_col_header(r),
307
+ width: r.width || undefined
308
+ };
309
+ final_cl = {
310
+ ...defaultColumnOptions,
311
+ ...r,
312
+ ...final_cl
313
+ };
314
+ return final_cl;
315
+ }
316
+ return null;
317
+ }).forEach(r => {
318
+ if (r != null) final_columns.push(r);
319
+ });
320
+ /* ---------------------------- apply extensions ---------------------------- */
321
+ if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
322
+ const ext = mcolExts[index];
323
+ const ext_cl = get_col_name(ext);
324
+ if (!ext_cl) {
325
+ console.warn('ColumnExtension must have a name');
326
+ continue;
327
+ }
328
+ const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
329
+ if (mcol) {
330
+ for (const key in ext) {
331
+ if (!mcol[key] && key != 'name') mcol[key] = ext[key];
332
+ }
333
+ }
334
+ // if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
335
+ }
336
+ /* ------------------------------- frozen cols ------------------------------ */
337
+ if (Array.isArray(leftColumns)) {
338
+ for (let index = 0; index < leftColumns.length; index++) {
339
+ const r = get_col_name(leftColumns[index]);
340
+ const mcol = final_columns.find(s => get_col_name(s) === r);
341
+ if (mcol) {
342
+ mcol.locked = 'start';
343
+ }
344
+ }
345
+ }
346
+ if (Array.isArray(rightColumns)) {
347
+ for (let index = 0; index < rightColumns.length; index++) {
348
+ const r = get_col_name(rightColumns[index]);
349
+ const mcol = final_columns.find(s => get_col_name(s) === r);
350
+ if (mcol) {
351
+ mcol.locked = 'end';
352
+ }
353
+ }
354
+ }
355
+ /* -------------------------------- ediatable ------------------------------- */
356
+ if (Array.isArray(editableColumns)) {
357
+ for (let index = 0; index < editableColumns.length; index++) {
358
+ const r = get_col_name(editableColumns[index]);
359
+ const mcol = final_columns.find(s => get_col_name(s) === r);
360
+ if (mcol) {
361
+ mcol.editable = true;
362
+ }
363
+ }
364
+ }
365
+ for (let index = 0; index < final_columns.length; index++) {
366
+ const col = final_columns[index];
367
+ if (col.type) {
368
+ switch (col.type) {
369
+ case 'combo':
370
+ case 'select':
371
+ //@ts-ignore
372
+ col.editor = _SelectEditor.default;
373
+ break;
374
+ case 'number':
375
+ case 'numberic':
376
+ //@ts-ignore
377
+ col.editor = _NumericEditor.default;
378
+ break;
379
+ case 'truefalse':
380
+ case 'bool':
381
+ //@ts-ignore
382
+ col.editor = _BoolEditor.default;
383
+ break;
384
+ }
385
+ if (col.editable != false) col.editable = true;
386
+ delete col.type;
387
+ }
388
+ //@ts-ignore
389
+ if (!col.editorProps) col.editorProps = {};
390
+ if (col.items) {
391
+ //@ts-ignore
392
+ if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
393
+ //@ts-ignore
394
+ if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
395
+ //@ts-ignore
396
+ col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
397
+ delete col.items;
398
+ }
399
+ }
400
+ /* -------------------------------------------------------------------------- */
401
+ if (Array.isArray(customColumns)) {
402
+ for (let index = 0; index < customColumns.length; index++) {
403
+ const r = customColumns[index];
404
+ const rn = get_col_name(r);
405
+ const mcol = final_columns.find(s => get_col_name(s) === rn);
406
+ if (mcol) {
407
+ //@ts-ignore
408
+ mcol.render = r.render;
409
+ }
410
+ }
411
+ }
412
+ /* ------------------------------ apply renames ----------------------------- */
413
+ for (let index = 0; index < final_columns.length; index++) {
414
+ const col = final_columns[index];
415
+ if (!col.name) {
416
+ col.name = get_col_name(col);
417
+ delete col.field;
418
+ delete col.key;
419
+ delete col.columnName;
420
+ if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
421
+ }
422
+ }
423
+ /* -------------------------------------------------------------------------- */
424
+ //console.log(final_columns);
425
+ return final_columns;
426
+ }
427
+ function to_datasource(arr, idProperty, valueAsID = true) {
428
+ const res = [];
429
+ let index = 0;
430
+ if (Array.isArray(arr)) {
431
+ arr.map(s => {
432
+ let elem = {};
433
+ if (valueAsID) elem[idProperty] = String(s).toLowerCase();else elem[idProperty] = '_cid_' + index;
434
+ if (typeof s === 'object') elem = {
435
+ ...elem,
436
+ ...s
437
+ };else elem['label'] = s;
438
+ res.push(elem);
439
+ index++;
440
+ });
441
+ }
442
+ return res;
443
+ }
421
444
  /**
422
445
  * Gets name of a column from its column object
423
446
  * @param obj
424
447
  * @returns
425
- */
426
- export function get_col_name(obj) {
427
- if (!obj)
428
- return '';
429
- if (typeof obj == 'string')
430
- return obj;
431
- if (typeof obj != 'object')
432
- return '';
433
- return obj.name || obj.field || obj.key || obj.columnName || '';
434
- }
448
+ */
449
+ function get_col_name(obj) {
450
+ if (!obj) return '';
451
+ if (typeof obj == 'string') return obj;
452
+ if (typeof obj != 'object') return '';
453
+ return obj.name || obj.field || obj.key || obj.columnName || '';
454
+ }
435
455
  /**
436
456
  * Gets header of a column
437
457
  * @param obj
438
458
  * @returns
439
- */
440
- export function get_col_header(obj) {
441
- if (!obj)
442
- return '';
443
- if (typeof obj == 'string')
444
- return obj;
445
- if (typeof obj != 'object')
446
- return '';
447
- return obj.header || obj.title || get_col_name(obj);
448
- }
459
+ */
460
+ function get_col_header(obj) {
461
+ if (!obj) return '';
462
+ if (typeof obj == 'string') return obj;
463
+ if (typeof obj != 'object') return '';
464
+ return obj.header || obj.title || get_col_name(obj);
465
+ }
449
466
  /**
450
467
  * Gets name of a column from its column object
451
468
  * @param obj
452
469
  * @returns
453
- */
454
- function get_row_id(obj) {
455
- if (!obj)
456
- return '-1';
457
- if (typeof obj == 'string')
458
- return obj;
459
- if (typeof obj != 'object')
460
- return '-1';
461
- return obj.__table_id || obj.id || '-1';
462
- }
470
+ */
471
+ function get_row_id(obj) {
472
+ if (!obj) return '-1';
473
+ if (typeof obj == 'string') return obj;
474
+ if (typeof obj != 'object') return '-1';
475
+ return obj.__table_id || obj.id || '-1';
476
+ }
463
477
  /**
464
478
  * Gets default activation key for grid plugin
465
479
  * @returns
466
- */
467
- function get_default_key() {
468
- return 'ExpiryDate=2999-01-01,Z=1040577552';
469
- }
470
- //check if two cache objects are the same
471
- function validateCache(current, old, looseCheck = false) {
472
- if (!old || !object_equals(current, old))
473
- return false;
474
- if (looseCheck)
475
- return true;
476
- if (current.ds != old.ds)
477
- return false;
478
- return true;
479
- }
480
- /* -------------------------------------------------------------------------- */
481
- export default AzGrid;
480
+ */
481
+ function get_default_key() {
482
+ return 'ExpiryDate=2999-01-01,Z=1040577552';
483
+ }
484
+ //check if two cache objects are the same
485
+ function validateCache(current, old, looseCheck = false) {
486
+ if (!old || !(0, _object.object_equals)(current, old)) return false;
487
+ if (looseCheck) return true;
488
+ if (current.ds != old.ds) return false;
489
+ return true;
490
+ }
491
+ /* -------------------------------------------------------------------------- */
492
+ var _default = AzGrid;
493
+ exports.default = _default;