@vuu-ui/vuu-utils 0.8.34 → 0.8.35

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.
Files changed (184) hide show
  1. package/package.json +5 -7
  2. package/cjs/DataWindow.js +0 -71
  3. package/cjs/DataWindow.js.map +0 -1
  4. package/cjs/ThemeProvider.js +0 -85
  5. package/cjs/ThemeProvider.js.map +0 -1
  6. package/cjs/array-utils.js +0 -87
  7. package/cjs/array-utils.js.map +0 -1
  8. package/cjs/box-utils.js +0 -10
  9. package/cjs/box-utils.js.map +0 -1
  10. package/cjs/column-utils.js +0 -810
  11. package/cjs/column-utils.js.map +0 -1
  12. package/cjs/common-types.js +0 -15
  13. package/cjs/common-types.js.map +0 -1
  14. package/cjs/component-registry.js +0 -111
  15. package/cjs/component-registry.js.map +0 -1
  16. package/cjs/cookie-utils.js +0 -10
  17. package/cjs/cookie-utils.js.map +0 -1
  18. package/cjs/data-utils.js +0 -58
  19. package/cjs/data-utils.js.map +0 -1
  20. package/cjs/datasource-action-utils.js +0 -14
  21. package/cjs/datasource-action-utils.js.map +0 -1
  22. package/cjs/datasource-utils.js +0 -178
  23. package/cjs/datasource-utils.js.map +0 -1
  24. package/cjs/date/dateTimePattern.js +0 -25
  25. package/cjs/date/dateTimePattern.js.map +0 -1
  26. package/cjs/date/formatter.js +0 -66
  27. package/cjs/date/formatter.js.map +0 -1
  28. package/cjs/date/types.js +0 -23
  29. package/cjs/date/types.js.map +0 -1
  30. package/cjs/date/utils.js +0 -10
  31. package/cjs/date/utils.js.map +0 -1
  32. package/cjs/debug-utils.js +0 -31
  33. package/cjs/debug-utils.js.map +0 -1
  34. package/cjs/event-emitter.js +0 -119
  35. package/cjs/event-emitter.js.map +0 -1
  36. package/cjs/filters/filterAsQuery.js +0 -76
  37. package/cjs/filters/filterAsQuery.js.map +0 -1
  38. package/cjs/filters/utils.js +0 -89
  39. package/cjs/filters/utils.js.map +0 -1
  40. package/cjs/formatting-utils.js +0 -66
  41. package/cjs/formatting-utils.js.map +0 -1
  42. package/cjs/getUniqueId.js +0 -6
  43. package/cjs/getUniqueId.js.map +0 -1
  44. package/cjs/group-utils.js +0 -12
  45. package/cjs/group-utils.js.map +0 -1
  46. package/cjs/html-utils.js +0 -124
  47. package/cjs/html-utils.js.map +0 -1
  48. package/cjs/index.js.map +0 -1
  49. package/cjs/input-utils.js +0 -10
  50. package/cjs/input-utils.js.map +0 -1
  51. package/cjs/invariant.js +0 -13
  52. package/cjs/invariant.js.map +0 -1
  53. package/cjs/itemToString.js +0 -23
  54. package/cjs/itemToString.js.map +0 -1
  55. package/cjs/json-utils.js +0 -92
  56. package/cjs/json-utils.js.map +0 -1
  57. package/cjs/keyboard-utils.js +0 -28
  58. package/cjs/keyboard-utils.js.map +0 -1
  59. package/cjs/keyset.js +0 -68
  60. package/cjs/keyset.js.map +0 -1
  61. package/cjs/logging-utils.js +0 -61
  62. package/cjs/logging-utils.js.map +0 -1
  63. package/cjs/menu-utils.js +0 -6
  64. package/cjs/menu-utils.js.map +0 -1
  65. package/cjs/module-utils.js +0 -12
  66. package/cjs/module-utils.js.map +0 -1
  67. package/cjs/nanoid/index.js +0 -22
  68. package/cjs/nanoid/index.js.map +0 -1
  69. package/cjs/perf-utils.js +0 -35
  70. package/cjs/perf-utils.js.map +0 -1
  71. package/cjs/range-utils.js +0 -74
  72. package/cjs/range-utils.js.map +0 -1
  73. package/cjs/react-utils.js +0 -21
  74. package/cjs/react-utils.js.map +0 -1
  75. package/cjs/round-decimal.js +0 -86
  76. package/cjs/round-decimal.js.map +0 -1
  77. package/cjs/row-utils.js +0 -84
  78. package/cjs/row-utils.js.map +0 -1
  79. package/cjs/selection-utils.js +0 -236
  80. package/cjs/selection-utils.js.map +0 -1
  81. package/cjs/sort-utils.js +0 -61
  82. package/cjs/sort-utils.js.map +0 -1
  83. package/cjs/text-utils.js +0 -21
  84. package/cjs/text-utils.js.map +0 -1
  85. package/cjs/ts-utils.js +0 -8
  86. package/cjs/ts-utils.js.map +0 -1
  87. package/cjs/url-utils.js +0 -21
  88. package/cjs/url-utils.js.map +0 -1
  89. package/cjs/useId.js +0 -9
  90. package/cjs/useId.js.map +0 -1
  91. package/cjs/useLayoutEffectSkipFirst.js +0 -17
  92. package/cjs/useLayoutEffectSkipFirst.js.map +0 -1
  93. package/esm/DataWindow.js +0 -69
  94. package/esm/DataWindow.js.map +0 -1
  95. package/esm/ThemeProvider.js +0 -78
  96. package/esm/ThemeProvider.js.map +0 -1
  97. package/esm/array-utils.js +0 -79
  98. package/esm/array-utils.js.map +0 -1
  99. package/esm/box-utils.js +0 -8
  100. package/esm/box-utils.js.map +0 -1
  101. package/esm/column-utils.js +0 -738
  102. package/esm/column-utils.js.map +0 -1
  103. package/esm/common-types.js +0 -13
  104. package/esm/common-types.js.map +0 -1
  105. package/esm/component-registry.js +0 -99
  106. package/esm/component-registry.js.map +0 -1
  107. package/esm/cookie-utils.js +0 -8
  108. package/esm/cookie-utils.js.map +0 -1
  109. package/esm/data-utils.js +0 -50
  110. package/esm/data-utils.js.map +0 -1
  111. package/esm/datasource-action-utils.js +0 -8
  112. package/esm/datasource-action-utils.js.map +0 -1
  113. package/esm/datasource-utils.js +0 -158
  114. package/esm/datasource-utils.js.map +0 -1
  115. package/esm/date/dateTimePattern.js +0 -21
  116. package/esm/date/dateTimePattern.js.map +0 -1
  117. package/esm/date/formatter.js +0 -63
  118. package/esm/date/formatter.js.map +0 -1
  119. package/esm/date/types.js +0 -20
  120. package/esm/date/types.js.map +0 -1
  121. package/esm/date/utils.js +0 -8
  122. package/esm/date/utils.js.map +0 -1
  123. package/esm/debug-utils.js +0 -29
  124. package/esm/debug-utils.js.map +0 -1
  125. package/esm/event-emitter.js +0 -117
  126. package/esm/event-emitter.js.map +0 -1
  127. package/esm/filters/filterAsQuery.js +0 -72
  128. package/esm/filters/filterAsQuery.js.map +0 -1
  129. package/esm/filters/utils.js +0 -74
  130. package/esm/filters/utils.js.map +0 -1
  131. package/esm/formatting-utils.js +0 -62
  132. package/esm/formatting-utils.js.map +0 -1
  133. package/esm/getUniqueId.js +0 -4
  134. package/esm/getUniqueId.js.map +0 -1
  135. package/esm/group-utils.js +0 -10
  136. package/esm/group-utils.js.map +0 -1
  137. package/esm/html-utils.js +0 -111
  138. package/esm/html-utils.js.map +0 -1
  139. package/esm/index.js +0 -46
  140. package/esm/index.js.map +0 -1
  141. package/esm/input-utils.js +0 -7
  142. package/esm/input-utils.js.map +0 -1
  143. package/esm/invariant.js +0 -11
  144. package/esm/invariant.js.map +0 -1
  145. package/esm/itemToString.js +0 -21
  146. package/esm/itemToString.js.map +0 -1
  147. package/esm/json-utils.js +0 -90
  148. package/esm/json-utils.js.map +0 -1
  149. package/esm/keyboard-utils.js +0 -15
  150. package/esm/keyboard-utils.js.map +0 -1
  151. package/esm/keyset.js +0 -66
  152. package/esm/keyset.js.map +0 -1
  153. package/esm/logging-utils.js +0 -58
  154. package/esm/logging-utils.js.map +0 -1
  155. package/esm/menu-utils.js +0 -4
  156. package/esm/menu-utils.js.map +0 -1
  157. package/esm/module-utils.js +0 -9
  158. package/esm/module-utils.js.map +0 -1
  159. package/esm/nanoid/index.js +0 -20
  160. package/esm/nanoid/index.js.map +0 -1
  161. package/esm/perf-utils.js +0 -32
  162. package/esm/perf-utils.js.map +0 -1
  163. package/esm/range-utils.js +0 -66
  164. package/esm/range-utils.js.map +0 -1
  165. package/esm/react-utils.js +0 -19
  166. package/esm/react-utils.js.map +0 -1
  167. package/esm/round-decimal.js +0 -84
  168. package/esm/round-decimal.js.map +0 -1
  169. package/esm/row-utils.js +0 -78
  170. package/esm/row-utils.js.map +0 -1
  171. package/esm/selection-utils.js +0 -227
  172. package/esm/selection-utils.js.map +0 -1
  173. package/esm/sort-utils.js +0 -57
  174. package/esm/sort-utils.js.map +0 -1
  175. package/esm/text-utils.js +0 -18
  176. package/esm/text-utils.js.map +0 -1
  177. package/esm/ts-utils.js +0 -6
  178. package/esm/ts-utils.js.map +0 -1
  179. package/esm/url-utils.js +0 -18
  180. package/esm/url-utils.js.map +0 -1
  181. package/esm/useId.js +0 -7
  182. package/esm/useId.js.map +0 -1
  183. package/esm/useLayoutEffectSkipFirst.js +0 -15
  184. package/esm/useLayoutEffectSkipFirst.js.map +0 -1
@@ -1,738 +0,0 @@
1
- import { moveItem } from './array-utils.js';
2
-
3
- const SORT_ASC = "asc";
4
- const NO_HEADINGS = [];
5
- const DEFAULT_COL_WIDTH = 100;
6
- const DEFAULT_MAX_WIDTH = 250;
7
- const DEFAULT_MIN_WIDTH = 50;
8
- const AggregationType = {
9
- Average: 2,
10
- Count: 3,
11
- Distinct: 6,
12
- Sum: 1,
13
- High: 4,
14
- Low: 5
15
- };
16
- function mapSortCriteria(sortCriteria, columnMap, metadataOffset = 0) {
17
- return sortCriteria.map((s) => {
18
- if (typeof s === "string") {
19
- return [columnMap[s] + metadataOffset, "asc"];
20
- } else if (Array.isArray(s)) {
21
- const [columnName, sortDir] = s;
22
- return [columnMap[columnName] + metadataOffset, sortDir || SORT_ASC];
23
- } else {
24
- throw Error("columnUtils.mapSortCriteria invalid input");
25
- }
26
- });
27
- }
28
- const numericTypes = ["int", "long", "double"];
29
- const getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? "left" : numericTypes.includes(serverDataType) ? "right" : "left";
30
- const isValidColumnAlignment = (v) => v === "left" || v === "right";
31
- const isValidPinLocation = (v) => isValidColumnAlignment(v) || v === "floating" || v === "";
32
- const VUU_COLUMN_DATA_TYPES = [
33
- "long",
34
- "double",
35
- "int",
36
- "string",
37
- "char",
38
- "boolean"
39
- ];
40
- const isVuuColumnDataType = (value) => VUU_COLUMN_DATA_TYPES.includes(value);
41
- const fromServerDataType = (serverDataType) => {
42
- switch (serverDataType) {
43
- case "double":
44
- case "int":
45
- case "long":
46
- return "number";
47
- case "boolean":
48
- return "boolean";
49
- default:
50
- return "string";
51
- }
52
- };
53
- const isNumericColumn = ({ serverDataType, type }) => {
54
- if (serverDataType === "int" || serverDataType === "long" || serverDataType === "double") {
55
- return true;
56
- }
57
- if (typeof type === "string") {
58
- return type === "number";
59
- }
60
- if (typeof type?.name === "string") {
61
- return type?.name === "number";
62
- }
63
- return false;
64
- };
65
- const isDateTimeColumn = (column) => (isTypeDescriptor(column.type) ? column.type.name : column.type) === "date/time";
66
- const isPinned = (column) => typeof column.pin === "string";
67
- const hasHeadings = (column) => Array.isArray(column.heading) && column.heading.length > 0;
68
- const isResizing = (column) => column.resizing;
69
- const isTextColumn = ({ serverDataType }) => serverDataType === void 0 ? false : serverDataType === "char" || serverDataType === "string";
70
- const toColumnDescriptor = (name) => ({
71
- name
72
- });
73
- const isTypeDescriptor = (type) => typeof type !== "undefined" && typeof type !== "string";
74
- const EMPTY_COLUMN_MAP = {};
75
- const isColumnTypeRenderer = (renderer) => typeof renderer?.name !== "undefined";
76
- const isLookupRenderer = (renderer) => typeof renderer?.name !== "undefined" && "lookup" in renderer;
77
- const isValueListRenderer = (renderer) => typeof renderer?.name !== "undefined" && Array.isArray(renderer.values);
78
- const hasValidationRules = (type) => isTypeDescriptor(type) && isColumnTypeRenderer(type.renderer) && Array.isArray(type.renderer.rules) && type.renderer.rules.length > 0;
79
- const isMappedValueTypeRenderer = (renderer) => renderer !== void 0 && typeof renderer?.map !== "undefined";
80
- function buildColumnMap(columns) {
81
- const start = metadataKeys.count;
82
- if (columns) {
83
- return columns.reduce((map, column, i) => {
84
- if (typeof column === "string") {
85
- map[column] = start + i;
86
- } else {
87
- map[column.name] = start + i;
88
- }
89
- return map;
90
- }, {});
91
- } else {
92
- return EMPTY_COLUMN_MAP;
93
- }
94
- }
95
- function projectUpdates(updates) {
96
- const results = [];
97
- const metadataOffset = metadataKeys.count - 2;
98
- for (let i = 0; i < updates.length; i += 3) {
99
- results[i] = updates[i] + metadataOffset;
100
- results[i + 1] = updates[i + 1];
101
- results[i + 2] = updates[i + 2];
102
- }
103
- return results;
104
- }
105
- const KEY = 6;
106
- const metadataKeys = {
107
- IDX: 0,
108
- RENDER_IDX: 1,
109
- IS_LEAF: 2,
110
- IS_EXPANDED: 3,
111
- DEPTH: 4,
112
- COUNT: 5,
113
- KEY,
114
- SELECTED: 7,
115
- count: 8,
116
- // TODO following only used in datamodel
117
- PARENT_IDX: "parent_idx",
118
- IDX_POINTER: "idx_pointer",
119
- FILTER_COUNT: "filter_count",
120
- NEXT_FILTER_IDX: "next_filter_idx"
121
- };
122
- const insertColumn = (columns, column) => {
123
- const { originalIdx } = column;
124
- if (typeof originalIdx === "number") {
125
- for (let i = 0; i < columns.length; i++) {
126
- const { originalIdx: colIdx = -1 } = columns[i];
127
- if (colIdx > originalIdx) {
128
- columns.splice(i, 0, column);
129
- return columns;
130
- }
131
- }
132
- }
133
- columns.push(column);
134
- return columns;
135
- };
136
- const flattenColumnGroup = (columns) => {
137
- if (columns[0]?.isGroup) {
138
- const [groupColumn, ...nonGroupedColumns] = columns;
139
- groupColumn.columns.forEach((groupColumn2) => {
140
- insertColumn(nonGroupedColumns, groupColumn2);
141
- });
142
- return nonGroupedColumns;
143
- } else {
144
- return columns;
145
- }
146
- };
147
- function extractGroupColumn(columns, groupBy, confirmed = true) {
148
- if (groupBy && groupBy.length > 0) {
149
- const flattenedColumns = flattenColumnGroup(columns);
150
- const [groupedColumns, rest] = flattenedColumns.reduce(
151
- (result, column, i) => {
152
- const [g, r] = result;
153
- if (groupBy.includes(column.name)) {
154
- g.push({
155
- ...column,
156
- originalIdx: i
157
- });
158
- } else {
159
- r.push(column);
160
- }
161
- return result;
162
- },
163
- [[], []]
164
- );
165
- if (groupedColumns.length !== groupBy.length) {
166
- throw Error(
167
- `extractGroupColumn: no column definition found for all groupBy cols ${JSON.stringify(
168
- groupBy
169
- )} `
170
- );
171
- }
172
- const groupCount = groupBy.length;
173
- const groupCols = groupBy.map((name, idx) => {
174
- const column = groupedColumns.find(
175
- (col) => col.name === name
176
- );
177
- return {
178
- ...column,
179
- groupLevel: groupCount - idx
180
- };
181
- });
182
- const groupCol = {
183
- name: "group-col",
184
- heading: ["group-col"],
185
- isGroup: true,
186
- columns: groupCols,
187
- groupConfirmed: confirmed,
188
- width: groupCols.map((c) => c.width).reduce((a, b) => a + b) + 100
189
- };
190
- return [groupCol, rest];
191
- }
192
- return [null, flattenColumnGroup(columns)];
193
- }
194
- const isGroupColumn = (column) => column.isGroup === true;
195
- const isJsonAttribute = (value) => typeof value === "string" && value.endsWith("+");
196
- const isJsonGroup = (column, row, columnMap) => column.type?.name === "json" && isJsonAttribute(row[columnMap[column.name]]);
197
- const isJsonColumn = (column) => column.type?.name === "json";
198
- const sortPinnedColumns = (columns) => {
199
- const leftPinnedColumns = [];
200
- const rightPinnedColumns = [];
201
- const restColumns = [];
202
- let pinnedWidthLeft = 4;
203
- for (const column of columns) {
204
- switch (column.pin) {
205
- case "left":
206
- {
207
- leftPinnedColumns.push({
208
- ...column,
209
- endPin: void 0,
210
- pinnedOffset: pinnedWidthLeft
211
- });
212
- pinnedWidthLeft += column.width;
213
- }
214
- break;
215
- case "right":
216
- rightPinnedColumns.unshift(column);
217
- break;
218
- default:
219
- restColumns.push(column);
220
- }
221
- }
222
- if (leftPinnedColumns.length) {
223
- leftPinnedColumns.push({
224
- ...leftPinnedColumns.pop(),
225
- endPin: true
226
- });
227
- }
228
- const allColumns = leftPinnedColumns.length ? leftPinnedColumns.concat(restColumns) : restColumns;
229
- if (rightPinnedColumns.length) {
230
- const measuredRightPinnedColumns = [];
231
- let pinnedWidthRight = 0;
232
- for (const column of rightPinnedColumns) {
233
- measuredRightPinnedColumns.unshift({
234
- ...column,
235
- pinnedOffset: pinnedWidthRight
236
- });
237
- pinnedWidthRight += column.width;
238
- }
239
- measuredRightPinnedColumns[0].endPin = true;
240
- return allColumns.concat(measuredRightPinnedColumns);
241
- } else {
242
- return allColumns;
243
- }
244
- };
245
- const measurePinnedColumns = (columns, selectionEndSize) => {
246
- let pinnedWidthLeft = 0;
247
- let pinnedWidthRight = 0;
248
- let unpinnedWidth = 0;
249
- for (const column of columns) {
250
- const { hidden, pin, width } = column;
251
- const visibleWidth = hidden ? 0 : width;
252
- if (pin === "left") {
253
- pinnedWidthLeft += visibleWidth;
254
- } else if (pin === "right") {
255
- pinnedWidthRight += visibleWidth;
256
- } else {
257
- unpinnedWidth += visibleWidth;
258
- }
259
- }
260
- return {
261
- pinnedWidthLeft: pinnedWidthLeft + selectionEndSize,
262
- pinnedWidthRight: pinnedWidthRight + selectionEndSize,
263
- unpinnedWidth
264
- };
265
- };
266
- const getTableHeadings = (columns) => {
267
- if (columns.some(hasHeadings)) {
268
- const maxHeadingDepth = columns.reduce(
269
- (max, { heading: heading2 }) => Math.max(max, heading2?.length ?? 0),
270
- 0
271
- );
272
- let heading = void 0;
273
- const tableHeadings = [];
274
- let tableHeadingsRow;
275
- for (let level = 0; level < maxHeadingDepth; level++) {
276
- tableHeadingsRow = [];
277
- columns.forEach(({ heading: columnHeading = NO_HEADINGS, width }) => {
278
- const label = columnHeading[level] ?? "";
279
- if (heading && heading.label === label) {
280
- heading.width += width;
281
- } else {
282
- heading = { label, width };
283
- tableHeadingsRow.push(heading);
284
- }
285
- });
286
- tableHeadings.push(tableHeadingsRow);
287
- }
288
- return tableHeadings;
289
- }
290
- return NO_HEADINGS;
291
- };
292
- const getColumnStyle = ({
293
- pin,
294
- // the 4 is `selectionEndSize`, unfortunate if we need to be passed it from cell
295
- // need to think about how to make this available
296
- pinnedOffset = pin === "left" ? 0 : 4,
297
- width
298
- }) => pin === "left" ? {
299
- left: pinnedOffset,
300
- width,
301
- "--pin-width": `${pinnedOffset + width - 3}px`
302
- } : pin === "right" ? {
303
- right: pinnedOffset,
304
- width,
305
- "--pin-width": `${pinnedOffset + width}px`
306
- } : { width };
307
- const setAggregations = (aggregations, column, aggType) => {
308
- return aggregations.filter((agg) => agg.column !== column.name).concat({ column: column.name, aggType });
309
- };
310
- const applyGroupByToColumns = (columns, groupBy, confirmed = true) => {
311
- if (groupBy.length) {
312
- const [groupColumn, nonGroupedColumns] = extractGroupColumn(
313
- columns,
314
- groupBy,
315
- confirmed
316
- );
317
- if (groupColumn) {
318
- return [groupColumn].concat(nonGroupedColumns);
319
- }
320
- } else if (columns[0]?.isGroup) {
321
- return flattenColumnGroup(columns);
322
- }
323
- return columns;
324
- };
325
- const applySortToColumns = (columns, sort) => columns.map((column) => {
326
- const sorted = getSortType(column, sort);
327
- if (sorted !== void 0) {
328
- return {
329
- ...column,
330
- sorted
331
- };
332
- } else if (column.sorted) {
333
- return {
334
- ...column,
335
- sorted: void 0
336
- };
337
- } else {
338
- return column;
339
- }
340
- });
341
- const removeSort = (columns) => columns.map((col) => col.sorted ? { ...col, sorted: void 0 } : col);
342
- const existingSort = (columns) => columns.some((col) => col.sorted);
343
- const getSortType = (column, { sortDefs }) => {
344
- const sortDef = sortDefs.find((sortCol) => sortCol.column === column.name);
345
- if (sortDef) {
346
- return sortDefs.length > 1 ? (sortDefs.indexOf(sortDef) + 1) * (sortDef.sortType === "A" ? 1 : -1) : sortDef.sortType;
347
- }
348
- };
349
- const getColumnName = (name) => {
350
- const pos = name.indexOf(":");
351
- if (pos === -1) {
352
- return name;
353
- } else {
354
- return name.slice(0, pos);
355
- }
356
- };
357
- const getColumnLabel = (column) => {
358
- if (column.label) {
359
- return column.label;
360
- } else if (isCalculatedColumn(column.name)) {
361
- return getCalculatedColumnName(column);
362
- } else {
363
- return column.name;
364
- }
365
- };
366
- const findColumn = (columns, columnName) => {
367
- const column = columns.find((col) => col.name === columnName);
368
- if (column) {
369
- return column;
370
- } else {
371
- const groupColumn = columns.find(
372
- (col) => col.isGroup
373
- );
374
- if (groupColumn) {
375
- return findColumn(groupColumn.columns, columnName);
376
- }
377
- }
378
- };
379
- function updateColumn(columns, column, options) {
380
- const targetColumn = typeof column === "string" ? columns.find((col) => col.name === column) : column;
381
- if (targetColumn) {
382
- const replacementColumn = options ? { ...targetColumn, ...options } : targetColumn;
383
- return columns.map(
384
- (col) => col.name === replacementColumn.name ? replacementColumn : col
385
- );
386
- } else {
387
- throw Error("column-utils.replaceColun, column not found");
388
- }
389
- }
390
- const toDataSourceColumns = (column) => column.name;
391
- const getRowRecord = (row, columnMap) => {
392
- return Object.entries(columnMap).reduce(
393
- (map, [colName, key]) => {
394
- map[colName] = row[key];
395
- return map;
396
- },
397
- {}
398
- );
399
- };
400
- const isDataLoading = (columns) => {
401
- return isGroupColumn(columns[0]) && columns[0].groupConfirmed === false;
402
- };
403
- const getColumnsInViewport = (columns, vpStart, vpEnd) => {
404
- const visibleColumns = [];
405
- let preSpan = 0;
406
- let rightPinnedOnly = false;
407
- for (let columnOffset = 0, i = 0; i < columns.length; i++) {
408
- const column = columns[i];
409
- if (column.hidden) {
410
- continue;
411
- } else if (rightPinnedOnly) {
412
- if (column.pin === "right") {
413
- visibleColumns.push(column);
414
- }
415
- } else if (columnOffset + column.width < vpStart) {
416
- if (column.pin === "left") {
417
- visibleColumns.push(column);
418
- } else if (columnOffset + column.width + columns[i + 1]?.width > vpStart) {
419
- visibleColumns.push(column);
420
- } else {
421
- preSpan += column.width;
422
- }
423
- } else if (columnOffset > vpEnd) {
424
- rightPinnedOnly = true;
425
- } else {
426
- visibleColumns.push(column);
427
- }
428
- columnOffset += column.width;
429
- }
430
- return [visibleColumns, preSpan];
431
- };
432
- const isNotHidden = (column) => column.hidden !== true;
433
- const visibleColumnAtIndex = (columns, index) => {
434
- if (columns.every(isNotHidden)) {
435
- return columns[index];
436
- } else {
437
- return columns.filter(isNotHidden).at(index);
438
- }
439
- };
440
- const { DEPTH, IS_LEAF } = metadataKeys;
441
- const getGroupValueAndOffset = (columns, row, columnMap) => {
442
- const { [DEPTH]: depth, [IS_LEAF]: isLeaf } = row;
443
- if (isLeaf || depth > columns.length) {
444
- return [null, depth === null ? 0 : Math.max(0, depth - 1)];
445
- } else if (depth === 0) {
446
- return ["$root", 0];
447
- } else {
448
- const { name, valueFormatter } = columns[depth - 1];
449
- const value = valueFormatter(row[columnMap[name]]);
450
- return [value, depth - 1];
451
- }
452
- };
453
- const getDefaultColumnType = (serverDataType) => {
454
- switch (serverDataType) {
455
- case "int":
456
- case "long":
457
- case "double":
458
- return "number";
459
- case "boolean":
460
- return "boolean";
461
- default:
462
- return "string";
463
- }
464
- };
465
- const updateColumnFormatting = (column, formatting) => {
466
- const { serverDataType, type = getDefaultColumnType(serverDataType) } = column;
467
- if (isTypeDescriptor(type)) {
468
- return { ...column, type: { ...type, formatting } };
469
- } else {
470
- return { ...column, type: { name: type, formatting } };
471
- }
472
- };
473
- function updateColumnType(column, type) {
474
- return isTypeDescriptor(column.type) ? { ...column, type: { ...column.type, name: type } } : { ...column, type };
475
- }
476
- const updateColumnRenderProps = (column, renderer) => {
477
- const { serverDataType, type = getDefaultColumnType(serverDataType) } = column;
478
- if (isTypeDescriptor(type)) {
479
- return {
480
- ...column,
481
- type: {
482
- ...type,
483
- // TODO do we need to preserve any existing attributes from renderer ?
484
- renderer
485
- }
486
- };
487
- } else {
488
- return { ...column, type: { name: type, renderer } };
489
- }
490
- };
491
- const NO_TYPE_SETTINGS = {};
492
- const getTypeFormattingFromColumn = (column) => {
493
- if (isTypeDescriptor(column.type)) {
494
- return column.type.formatting ?? NO_TYPE_SETTINGS;
495
- } else {
496
- return NO_TYPE_SETTINGS;
497
- }
498
- };
499
- const subscribedOnly = (columnNames) => (column) => columnNames?.includes(column.name);
500
- const addColumnToSubscribedColumns = (subscribedColumns, availableColumns, columnName) => {
501
- const byColName = (n = columnName) => (column) => column.name === n;
502
- if (subscribedColumns.findIndex(byColName()) !== -1) {
503
- throw Error(
504
- `column-utils, addColumnToSubscribedColumns column ${columnName} is already subscribed`
505
- );
506
- }
507
- const indexOfAvailableColumn = availableColumns.findIndex(byColName());
508
- if (indexOfAvailableColumn === -1) {
509
- throw Error(
510
- `column-utils, addColumnToSubscribedColumns column ${columnName} is not available`
511
- );
512
- }
513
- const newColumn = {
514
- ...availableColumns[indexOfAvailableColumn]
515
- };
516
- let index = -1;
517
- for (let i = indexOfAvailableColumn - 1; i >= 0; i--) {
518
- const { name } = availableColumns[i];
519
- index = subscribedColumns.findIndex(byColName(name));
520
- if (index !== -1) {
521
- break;
522
- }
523
- }
524
- if (index === -1) {
525
- return [newColumn].concat(subscribedColumns);
526
- } else {
527
- const results = [];
528
- for (let i = 0; i < subscribedColumns.length; i++) {
529
- results.push(subscribedColumns[i]);
530
- if (i === index) {
531
- results.push(newColumn);
532
- index = Number.MAX_SAFE_INTEGER;
533
- }
534
- }
535
- return results;
536
- }
537
- };
538
- const CalculatedColumnPattern = /.*:.*:.*/;
539
- const isCalculatedColumn = (columnName) => columnName !== void 0 && CalculatedColumnPattern.test(columnName);
540
- const getCalculatedColumnDetails = (column) => {
541
- if (isCalculatedColumn(column.name)) {
542
- return column.name.split(/:=?/);
543
- } else {
544
- throw Error(
545
- `column-utils, getCalculatedColumnDetails column name ${column.name} is not valid calculated column`
546
- );
547
- }
548
- };
549
- const getCalculatedColumnName = (column) => getCalculatedColumnDetails(column)[0];
550
- const getCalculatedColumnType = (column) => getCalculatedColumnDetails(column)[1];
551
- const getCalculatedColumnExpression = (column) => getCalculatedColumnDetails(column)[2];
552
- const setCalculatedColumnName = (column, name) => {
553
- const [, type, expression] = column.name.split(":");
554
- return {
555
- ...column,
556
- name: `${name}:${type}:${expression}`
557
- };
558
- };
559
- const setCalculatedColumnType = (column, type) => {
560
- const [name, , expression] = column.name.split(":");
561
- return {
562
- ...column,
563
- name: `${name}:${type}:${expression}`
564
- };
565
- };
566
- const setCalculatedColumnExpression = (column, expression) => {
567
- const [name, type] = column.name.split(":");
568
- return {
569
- ...column,
570
- name: `${name}:${type}:=${expression}`
571
- };
572
- };
573
- const moveColumnTo = (columns, column, newIndex) => {
574
- const index = columns.findIndex((col) => col.name === column.name);
575
- return moveItem(columns, index, newIndex);
576
- };
577
- function replaceColumn(columns, column) {
578
- return columns.map((col) => col.name === column.name ? column : col);
579
- }
580
- const applyDefaultColumnConfig = ({ columns, table }, getDefaultColumnConfig) => {
581
- if (typeof getDefaultColumnConfig === "function") {
582
- return columns.map((column) => {
583
- const config = getDefaultColumnConfig(table.table, column.name);
584
- if (config) {
585
- return {
586
- ...column,
587
- ...config
588
- };
589
- } else {
590
- return column;
591
- }
592
- });
593
- } else {
594
- return columns;
595
- }
596
- };
597
- const getColumnByName = (schema, name) => {
598
- if (name === void 0) {
599
- return void 0;
600
- } else {
601
- const column = schema.columns.find((col) => col.name === name);
602
- if (column) {
603
- return column;
604
- } else {
605
- throw Error(
606
- `getColumnByName no column '${name}' in schema for ${schema.table.table}`
607
- );
608
- }
609
- }
610
- };
611
- function applyWidthToColumns(columns, options) {
612
- const {
613
- availableWidth = 0,
614
- columnLayout = "Static",
615
- defaultWidth = DEFAULT_COL_WIDTH,
616
- defaultMinWidth = DEFAULT_MIN_WIDTH,
617
- defaultMaxWidth = DEFAULT_MAX_WIDTH
618
- // defaultFlex = DEFAULT_FLEX,
619
- } = options;
620
- if (columnLayout === "Static") {
621
- return columns.map((column) => {
622
- if (typeof column.width === "number") {
623
- return column;
624
- } else {
625
- return {
626
- ...column,
627
- width: defaultWidth
628
- };
629
- }
630
- });
631
- } else if (columnLayout === "Fit") {
632
- const { totalMinWidth, totalMaxWidth, totalWidth, flexCount } = columns.reduce(
633
- (aggregated, column) => {
634
- const { totalMinWidth: totalMinWidth2, totalMaxWidth: totalMaxWidth2, totalWidth: totalWidth2, flexCount: flexCount2 } = aggregated;
635
- const {
636
- minWidth = defaultMinWidth,
637
- maxWidth = defaultMaxWidth,
638
- width = defaultWidth,
639
- flex = 0
640
- } = column;
641
- return {
642
- totalMinWidth: totalMinWidth2 + minWidth,
643
- totalMaxWidth: totalMaxWidth2 + maxWidth,
644
- totalWidth: totalWidth2 + width,
645
- flexCount: flexCount2 + flex
646
- };
647
- },
648
- { totalMinWidth: 0, totalMaxWidth: 0, totalWidth: 0, flexCount: 0 }
649
- );
650
- if (totalMinWidth > availableWidth || totalMaxWidth < availableWidth) {
651
- return columns;
652
- } else if (totalWidth > availableWidth) {
653
- const excessWidth = totalWidth - availableWidth;
654
- const inFlexMode = flexCount > 0;
655
- let excessWidthPerColumn = excessWidth / (flexCount || columns.length);
656
- let columnsNotYetAtMinWidth = columns.length;
657
- let unassignedExcess = 0;
658
- let newColumns = columns.map((column) => {
659
- const {
660
- minWidth = defaultMinWidth,
661
- width = defaultWidth,
662
- flex = 0
663
- } = column;
664
- if (inFlexMode && flex === 0) {
665
- return column;
666
- }
667
- const adjustedWidth = width - excessWidthPerColumn;
668
- if (adjustedWidth < minWidth) {
669
- columnsNotYetAtMinWidth -= 1;
670
- unassignedExcess += minWidth - adjustedWidth;
671
- return { ...column, width: minWidth };
672
- } else {
673
- return { ...column, width: adjustedWidth };
674
- }
675
- });
676
- if (unassignedExcess === 0) {
677
- return newColumns;
678
- } else {
679
- excessWidthPerColumn = unassignedExcess / columnsNotYetAtMinWidth;
680
- newColumns = newColumns.map((column) => {
681
- const adjustedWidth = column.width - excessWidthPerColumn;
682
- if (column.width !== column.minWidth) {
683
- return { ...column, width: adjustedWidth };
684
- } else {
685
- return column;
686
- }
687
- });
688
- return newColumns;
689
- }
690
- } else if (totalWidth < availableWidth) {
691
- {
692
- const additionalWidth = availableWidth - totalWidth;
693
- const inFlexMode = flexCount > 0;
694
- let additionalWidthPerColumn = additionalWidth / (flexCount || columns.length);
695
- let newColumns = columns.map((column) => {
696
- const {
697
- maxWidth = defaultMaxWidth,
698
- width = defaultWidth,
699
- flex = 0
700
- } = column;
701
- if (inFlexMode && flex === 0) {
702
- return column;
703
- }
704
- const adjustedWidth = width + additionalWidthPerColumn;
705
- if (adjustedWidth > maxWidth) {
706
- return { ...column, width: maxWidth };
707
- } else {
708
- return { ...column, width: adjustedWidth, canStretch: true };
709
- }
710
- });
711
- const unassignedAdditionalColumnWidth = additionalWidth - newColumns.reduce((sum, col) => sum + col.width, 0);
712
- const columnsNotYetAtMaxWidth = newColumns.filter(
713
- (col) => col.canStretch
714
- ).length;
715
- if (unassignedAdditionalColumnWidth > columnsNotYetAtMaxWidth) {
716
- additionalWidthPerColumn = unassignedAdditionalColumnWidth / columnsNotYetAtMaxWidth;
717
- newColumns = newColumns.map((column) => {
718
- if (column.canStretch) {
719
- const adjustedWidth = Math.min(
720
- column.width + additionalWidthPerColumn
721
- );
722
- return { ...column, width: adjustedWidth };
723
- } else {
724
- return column;
725
- }
726
- });
727
- }
728
- return newColumns.map(({ canStretch, ...column }) => column);
729
- }
730
- }
731
- }
732
- return columns;
733
- }
734
- const dataAndColumnUnchanged = (p, p1) => p.column === p1.column && p.column.valueFormatter(p.row[p.columnMap[p.column.name]]) === p1.column.valueFormatter(p1.row[p1.columnMap[p1.column.name]]);
735
- const dataColumnAndKeyUnchanged = (p, p1) => p.column === p1.column && p.row[KEY] === p1.row[KEY] && p.column.valueFormatter(p.row[p.columnMap[p.column.name]]) === p1.column.valueFormatter(p1.row[p1.columnMap[p1.column.name]]);
736
-
737
- export { AggregationType, addColumnToSubscribedColumns, applyDefaultColumnConfig, applyGroupByToColumns, applySortToColumns, applyWidthToColumns, buildColumnMap, dataAndColumnUnchanged, dataColumnAndKeyUnchanged, existingSort, extractGroupColumn, findColumn, flattenColumnGroup, fromServerDataType, getCalculatedColumnDetails, getCalculatedColumnExpression, getCalculatedColumnName, getCalculatedColumnType, getColumnByName, getColumnLabel, getColumnName, getColumnStyle, getColumnsInViewport, getDefaultAlignment, getDefaultColumnType, getGroupValueAndOffset, getRowRecord, getTableHeadings, getTypeFormattingFromColumn, hasHeadings, hasValidationRules, isCalculatedColumn, isColumnTypeRenderer, isDataLoading, isDateTimeColumn, isGroupColumn, isJsonAttribute, isJsonColumn, isJsonGroup, isLookupRenderer, isMappedValueTypeRenderer, isNotHidden, isNumericColumn, isPinned, isResizing, isTextColumn, isTypeDescriptor, isValidColumnAlignment, isValidPinLocation, isValueListRenderer, isVuuColumnDataType, mapSortCriteria, measurePinnedColumns, metadataKeys, moveColumnTo, projectUpdates, removeSort, replaceColumn, setAggregations, setCalculatedColumnExpression, setCalculatedColumnName, setCalculatedColumnType, sortPinnedColumns, subscribedOnly, toColumnDescriptor, toDataSourceColumns, updateColumn, updateColumnFormatting, updateColumnRenderProps, updateColumnType, visibleColumnAtIndex };
738
- //# sourceMappingURL=column-utils.js.map