@azrico/reactgrid 1.3.39 → 1.3.40

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,318 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ApplyColumnData = ApplyColumnData;
7
- exports.ApplyDataSource = ApplyDataSource;
8
- exports.find_realData = find_realData;
9
- exports.get_col_header = get_col_header;
10
- exports.get_col_name = get_col_name;
11
- exports.get_default_key = get_default_key;
12
- exports.get_row_id = get_row_id;
13
- exports.set_row_id = set_row_id;
14
- exports.to_datasource = to_datasource;
15
- exports.validateCache = validateCache;
16
- var _BoolEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/BoolEditor"));
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
- // import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
22
-
23
- const defaultColumnOptions = {
24
- draggable: false,
25
- lockable: false,
26
- editable: false
27
- };
28
- async function ApplyDataSource(datasource, props) {
29
- let result_data = undefined;
30
- let isUsingCache = false;
31
- const cacheInfo = {
32
- ds: datasource,
33
- skip: props.skip,
34
- limit: props.limit
35
- };
36
- //check if we can used cached data
37
- //if the datasource is changed since last render, we should invalidate cache
38
- if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
39
- props.cached_data.current = undefined;
40
- props.last_cache_info.current = cacheInfo;
41
- }
42
- if (props.cached_data.current) {
43
- //cache is valid, use the cache
44
- isUsingCache = true;
45
- result_data = props.cached_data.current;
46
- } else {
47
- //cache is invalid, use the datasource again
48
- isUsingCache = false;
49
- if (typeof datasource === 'function') {
50
- result_data = await datasource(props);
51
- } else result_data = datasource;
52
- }
53
- //making sure the datasource is a valid object :
54
- if (!result_data) result_data = [];
55
- if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
56
- data: result_data
57
- };
58
- if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
59
- //no need to fix parent/child when using cache (it should be already fixed)
60
- if (!isUsingCache && props.allowChildRows) {
61
- result_data.data = (0, _func_child.fix_parent_child_relations)(result_data.data);
62
- }
63
- if (!result_data.count) {
64
- result_data.count = result_data.data.length;
65
- }
66
- //update cache
67
- props.cached_data.current = result_data;
68
- return result_data;
69
- }
70
- /**
71
- * merges together all different props for columns
72
- * to build a single final column data array
73
- * @param column_data
74
- * @returns
75
- */
76
- function ApplyColumnData(column_data) {
77
- const final_columns = [];
78
- if (!column_data) column_data = {};
79
- if (Array.isArray(column_data)) column_data = {
80
- columns: column_data
81
- };
82
- let mcols = column_data.columns || [];
83
- let mcolExts = column_data.columnExtensions || [];
84
- let rightColumns = column_data.rightColumns || [];
85
- let leftColumns = column_data.leftColumns || [];
86
- let editableColumns = column_data.editableColumns || [];
87
- let customColumns = column_data.customColumns || [];
88
- if (!Array.isArray(mcols)) return [];
89
- /* ------------------------------- fix columns ------------------------------ */
90
- mcols.map(r => {
91
- if (r == null) return null;
92
- if (typeof r === 'string') return {
93
- field: r,
94
- header: r
95
- };
96
- if (typeof r === 'object') {
97
- let final_cl = {
98
- name: get_col_name(r),
99
- header: get_col_header(r),
100
- width: r.width || undefined
101
- };
102
- final_cl = {
103
- ...defaultColumnOptions,
104
- ...r,
105
- ...final_cl
106
- };
107
- return final_cl;
108
- }
109
- return null;
110
- }).forEach(r => {
111
- if (r != null) final_columns.push(r);
112
- });
113
- /* ---------------------------- apply extensions ---------------------------- */
114
- if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
115
- const ext = mcolExts[index];
116
- const ext_cl = get_col_name(ext);
117
- if (!ext_cl) {
118
- console.warn('ColumnExtension must have a name');
119
- continue;
120
- }
121
- const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
122
- if (mcol) {
123
- for (const key in ext) {
124
- if (!mcol[key] && key != 'name') mcol[key] = ext[key];
125
- }
126
- }
127
- // if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
128
- }
129
- /* ------------------------------- frozen cols ------------------------------ */
130
- if (Array.isArray(leftColumns)) {
131
- for (let index = 0; index < leftColumns.length; index++) {
132
- const r = get_col_name(leftColumns[index]);
133
- const mcol = final_columns.find(s => get_col_name(s) === r);
134
- if (mcol) {
135
- mcol.locked = 'start';
136
- }
137
- }
138
- }
139
- if (Array.isArray(rightColumns)) {
140
- for (let index = 0; index < rightColumns.length; index++) {
141
- const r = get_col_name(rightColumns[index]);
142
- const mcol = final_columns.find(s => get_col_name(s) === r);
143
- if (mcol) {
144
- mcol.locked = 'end';
145
- }
146
- }
147
- }
148
- /* -------------------------------- ediatable ------------------------------- */
149
- if (Array.isArray(editableColumns)) {
150
- for (let index = 0; index < editableColumns.length; index++) {
151
- const r = get_col_name(editableColumns[index]);
152
- const mcol = final_columns.find(s => get_col_name(s) === r);
153
- if (mcol) {
154
- mcol.editable = true;
155
- }
156
- }
157
- }
158
- for (let index = 0; index < final_columns.length; index++) {
159
- const col = final_columns[index];
160
- const coltype = col.type;
161
- delete col.type;
162
- if (coltype) {
163
- switch (coltype) {
164
- case 'combo':
165
- case 'select':
166
- //@ts-ignore
167
- col.editor = _SelectEditor.default;
168
- break;
169
- case 'int':
170
- case 'number':
171
- case 'numberic':
172
- col.type = 'number';
173
- break;
174
- case 'truefalse':
175
- case 'bool':
176
- case 'boolean':
177
- //@ts-ignore
178
- col.editor = _BoolEditor.default;
179
- break;
180
- }
181
- if (col.editable != false) col.editable = true;
182
- }
183
- //@ts-ignore
184
- if (!col.editorProps) col.editorProps = {};
185
- if (col.items) {
186
- //@ts-ignore
187
- if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
188
- //@ts-ignore
189
- if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
190
- //@ts-ignore
191
- col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
192
- delete col.items;
193
- }
194
- }
195
- /* -------------------------------------------------------------------------- */
196
- if (Array.isArray(customColumns)) {
197
- for (let index = 0; index < customColumns.length; index++) {
198
- const r = customColumns[index];
199
- const rn = get_col_name(r);
200
- const mcol = final_columns.find(s => get_col_name(s) === rn);
201
- if (mcol) {
202
- //@ts-ignore
203
- mcol.render = r.render;
204
- }
205
- }
206
- }
207
- /* ------------------------------ apply renames ----------------------------- */
208
- for (let index = 0; index < final_columns.length; index++) {
209
- const col = final_columns[index];
210
- if (!col.name) {
211
- col.name = get_col_name(col);
212
- delete col.field;
213
- delete col.key;
214
- delete col.columnName;
215
- if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
216
- }
217
- }
218
- /* -------------------------------------------------------------------------- */
219
- //console.log(final_columns);
220
- return final_columns;
221
- }
222
- function to_datasource(arr, idProperty, valueAsID = true) {
223
- const res = [];
224
- let index = 0;
225
- if (Array.isArray(arr)) {
226
- arr.map(s => {
227
- let elem = {};
228
- if (valueAsID) elem[idProperty] = String(s).toLowerCase();else elem[idProperty] = '_cid_' + index;
229
- if (typeof s === 'object') elem = {
230
- ...elem,
231
- ...s
232
- };else elem['label'] = s;
233
- res.push(elem);
234
- index++;
235
- });
236
- }
237
- return res;
238
- }
239
- /**
240
- * Gets name of a column from its column object
241
- * @param obj
242
- * @returns
243
- */
244
- function get_col_name(obj) {
245
- if (!obj) return '';
246
- if (typeof obj == 'string') return obj;
247
- if (typeof obj != 'object') return '';
248
- return obj.name || obj.field || obj.key || obj.columnName || '';
249
- }
250
- /**
251
- * Gets header of a column
252
- * @param obj
253
- * @returns
254
- */
255
- function get_col_header(obj) {
256
- if (!obj) return '';
257
- if (typeof obj == 'string') return obj;
258
- if (typeof obj != 'object') return '';
259
- return obj.header || obj.title || get_col_name(obj);
260
- }
261
- /**
262
- * Gets name of a column from its column object
263
- * @param obj
264
- * @returns
265
- */
266
- function get_row_id(obj) {
267
- if (typeof obj === 'string') return obj;
268
- if (typeof obj !== 'object' || !obj) return undefined;
269
- return obj.__table_id || obj.id || undefined;
270
- }
271
- function set_row_id(obj, val) {
272
- if (typeof obj != 'object') return false;
273
- if (val === undefined) delete obj.__table_id;else obj.__table_id = val;
274
- return obj.__table_id;
275
- }
276
- /**
277
- * Gets default activation key for grid plugin
278
- * THIS KEY IS FOR DEBUGGING PURPOSE ONLY.
279
- * PROVIDE YOUR OWN KEY
280
- * @returns
281
- */
282
- function get_default_key() {
283
- return 'ExpiryDate=2999-01-01,Z=1040577552';
284
- }
285
- //check if two cache objects are the same
286
- function validateCache(current, old, looseCheck = false) {
287
- if (!old || !(0, _object.object_equals)(current, old)) return false;
288
- if (looseCheck) return true;
289
- if (current.ds != old.ds) return false;
290
- return true;
291
- }
292
- /**
293
- * find the real index of the given row data
294
- * @param view
295
- */
296
- function find_realIndex(view) {
297
- let current_parent = view;
298
- for (let index = 0; index < 3; index++) {
299
- var _current_parent;
300
- current_parent = current_parent.parentElement;
301
- const dataId = (_current_parent = current_parent) === null || _current_parent === void 0 ? void 0 : _current_parent.getAttribute('data-row-id');
302
- if (dataId) return dataId;
303
- }
304
- return -1;
305
- }
306
- /**
307
- * find the real index of the given row data
308
- * sometimes when we scroll the rowData prop becomes invalid
309
- * but we can manually find the correct data by reading the id from clicked item's Html props
310
- * @param view
311
- */
312
- function find_realData(alldata, view, def = undefined) {
313
- if (!Array.isArray(alldata)) return def;
314
- const rid = find_realIndex(view);
315
- if (rid === -1) return def;
316
- // console.log('dataSource', alldata);
317
- return alldata.find(s => get_row_id(s) === rid);
318
- }
@@ -1,4 +0,0 @@
1
- export * from './views/DataGrid';
2
- export { get_row_id, set_row_id, get_col_name, get_col_header } from './func/func_grid';
3
- import AzGrid from './views/DataGrid';
4
- export default AzGrid;
package/dist/src/index.js DELETED
@@ -1,64 +0,0 @@
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
- var _example = _interopRequireDefault(require("./example"));
51
- var _react = _interopRequireDefault(require("react"));
52
- var _client = _interopRequireDefault(require("react-dom/client"));
53
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
54
- 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); }
55
- 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; }
56
- /* -------------------------------------------------------------------------- */
57
- //
58
- var _default = _DataGrid.default;
59
- exports.default = _default;
60
- const testroot = document.getElementById('testroot');
61
- if (testroot) {
62
- const root = _client.default.createRoot(document.getElementById('testroot'));
63
- root.render(_react.default.createElement(_example.default, null));
64
- }
@@ -1,52 +0,0 @@
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-flexed {
16
- flex: 1;
17
- }
18
- .azgrid-flexlayout {
19
- display: flex;
20
- flex-direction: column;
21
- }
22
- .azgrid-testborder {
23
- border: 3px solid red;
24
- }
25
- .azgrid-pad50px {
26
- padding: 50px;
27
- }
28
- .azgrid-nopad {
29
- padding: 0;
30
- }
31
- .azgrid-nomargin {
32
- margin: 0;
33
- }
34
- .azgrid-delayedresize {
35
- transition-property: width, height;
36
- transition-delay: 200ms;
37
- transition-duration: 0ms;
38
- }
39
-
40
- .azgrid-searcharea {
41
- margin: 5px;
42
- font-size: large;
43
- }
44
- .azgrid-searcharea label {
45
- gap: 5px;
46
- display: flex;
47
- align-items: center;
48
- }
49
- .azgrid-searcharea label input {
50
- padding: 5px;
51
- font-size: large;
52
- }
@@ -1,65 +0,0 @@
1
- .InovuaReactDataGrid {
2
-
3
-
4
- z-index: 1000;
5
- font-family: 'Nunito Sans', 'Iran Sans', sans-serif;
6
- }
7
- .InovuaReactDataGrid--theme-amber-dark {
8
- --grid-bg: #313943;
9
- --grid-fg:#c5cae9;
10
- --grid-fg-hover:#ececec;
11
- }
12
-
13
- .InovuaReactDataGrid--theme-default-light {
14
- --grid-bg: #fff;
15
- --grid-fg:#1e1e1e;
16
- --grid-fg-hover:#000000;
17
- }
18
-
19
- .InovuaReactDataGrid__row{
20
- color:var(--grid-fg);
21
- }
22
-
23
-
24
-
25
-
26
- /* --------------------------- selected row color --------------------------- */
27
- .InovuaReactDataGrid
28
- .InovuaReactDataGrid__row--active
29
- .InovuaReactDataGrid__cell:not(.InovuaReactDataGrid__cell--no-background),
30
- .InovuaReactDataGrid
31
- .InovuaReactDataGrid__row--active.InovuaReactDataGrid__row--even
32
- .InovuaReactDataGrid__cell:not(.InovuaReactDataGrid__cell--no-background),
33
- .InovuaReactDataGrid
34
- .InovuaReactDataGrid__row--active.InovuaReactDataGrid__row--odd
35
- .InovuaReactDataGrid__cell:not(.InovuaReactDataGrid__cell--no-background) {
36
- color: var(--grid-fg-hover);
37
- }
38
-
39
- .inovua-react-toolkit-text-input {
40
- font-family: inherit;
41
- }
42
- .inovua-react-toolkit-text-input input {
43
- font-family: inherit;
44
- }
45
-
46
-
47
-
48
- .InovuaReactDataGrid__cell .InovuaReactDataGrid__cell__content {
49
- height: 100%;
50
- display: flex;
51
- align-items: center;
52
- }
53
- .InovuaReactDataGrid__column-header__content {
54
- text-overflow: clip;
55
- }
56
-
57
- .InovuaReactDataGrid__row.deleted:after {
58
- position: absolute;
59
- content: '';
60
- left: 5px;
61
- top: 50%;
62
- right: 5px;
63
- border-top: 1.5px solid;
64
- border-color: gray;
65
- }
@@ -1,80 +0,0 @@
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 { ConvertableToMenuItem } from '@azrico/controls';
7
- import React from 'react';
8
- import { TypeCellSelection, TypeColumn, TypeDataGridProps, TypeDataSource, TypeEditInfo, TypeFilterTypes, TypeFilterValue, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection, TypeComputedProps } from '@inovua/reactdatagrid-community/types';
9
- import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
10
- export type ColumnDefinition = TypeColumn;
11
- export type CellDefinition = any;
12
- export type RowDefinition = any;
13
- export type RowProps = TypeRowProps;
14
- export type RowSelectionValue = TypeRowSelection;
15
- export type CellSelectionValue = TypeCellSelection;
16
- export type DataRowDefinition = any;
17
- export type FilterTypes = TypeFilterTypes;
18
- export type FilterValues = TypeFilterValue;
19
- export type DataSourceDefinition = TypeDataSource;
20
- export type OnSelectionChangeFunc = (config: TypeOnSelectionChangeArg) => void;
21
- export type OnCellSelectionChangeFunc = (s: {
22
- [key: string]: boolean;
23
- }) => void;
24
- export type RowDetailsFunc = (rowDetailsInfo: TypeRowDetailsInfo) => React.ReactNode;
25
- type loose_column_names = {
26
- key: string;
27
- field: string;
28
- columnName: string;
29
- name: string;
30
- };
31
- type loose_column_fields = loose_column_names & {
32
- title: string;
33
- type: string;
34
- items: any[];
35
- };
36
- export type LooseColumnDefinition = Partial<loose_column_fields & ColumnDefinition>;
37
- export type CustomColumnDefinition = {
38
- name: string;
39
- render: (cell: any, formatterParams: any, onRendered: any) => React.ReactNode | undefined | null;
40
- };
41
- export type AzGridOptions = Partial<TypeDataGridProps>;
42
- export type AzGridProps = {
43
- dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
44
- details_dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
45
- details_columns?: LooseColumnDefinition[];
46
- details_filter?: FilterValues;
47
- licenseKey?: string;
48
- gridRef?: React.MutableRefObject<TypeComputedProps>;
49
- gridOptions?: AzGridOptions;
50
- columns?: LooseColumnDefinition[];
51
- columnExtensions?: Partial<LooseColumnDefinition>;
52
- editableColumns?: string[];
53
- leftColumns?: string[];
54
- rightColumns?: string[];
55
- customColumns?: CustomColumnDefinition[];
56
- contextMenuItems?: ConvertableToMenuItem;
57
- highlightedRow?: any;
58
- RowDetail?: RowDetailsFunc;
59
- selected?: RowSelectionValue;
60
- cellSelection?: CellSelectionValue;
61
- onEditComplete?: (editInfo: TypeEditInfo) => void;
62
- onSelectionChange?: OnSelectionChangeFunc;
63
- onCellSelectionChange?: OnCellSelectionChangeFunc;
64
- onRowClick?: (rowIndex: number, row: any) => void;
65
- onRowDoubleClick?: (rowIndex: number, row: any) => void;
66
- onLimitChange?: (v: number) => void;
67
- onSkipChange?: (v: number) => void;
68
- skip?: number;
69
- limit?: number;
70
- editable?: boolean | ((editValue: any, cellProps: any) => boolean);
71
- advancedFilterFields?: string[];
72
- loading?: boolean;
73
- dark?: boolean;
74
- delayedSize?: boolean;
75
- allowChildRows?: boolean;
76
- looseCacheCheck?: boolean;
77
- className?: string;
78
- };
79
- export declare function AzGrid(props: AzGridProps): JSX.Element;
80
- export default AzGrid;