@sme.up/ketchup 5.0.0 → 5.2.1-SNAPSHOT

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 (224) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/{cell-utils-720be0c8.js → cell-utils-d96b2993.js} +4 -4
  3. package/dist/cjs/{f-button-dbf3cd3a.js → f-button-2b9b99b1.js} +2 -2
  4. package/dist/cjs/{f-cell-93d984ad.js → f-cell-8351cb84.js} +8 -96
  5. package/dist/cjs/{f-chip-438213eb.js → f-chip-df59e1b0.js} +3 -3
  6. package/dist/cjs/{f-image-21865ab7.js → f-image-12bab3b5.js} +2 -2
  7. package/dist/cjs/f-text-field-e7c35b5b.js +94 -0
  8. package/dist/cjs/f-text-field-mdc-a67f5dfe.js +2852 -0
  9. package/dist/cjs/{index-ab119fad.js → index-eb556444.js} +6 -1
  10. package/dist/cjs/ketchup.cjs.js +3 -3
  11. package/dist/cjs/kup-accordion.cjs.entry.js +5 -5
  12. package/dist/cjs/kup-autocomplete_27.cjs.entry.js +641 -3331
  13. package/dist/cjs/kup-calendar.cjs.entry.js +8 -8
  14. package/dist/cjs/kup-cell.cjs.entry.js +9 -8
  15. package/dist/cjs/kup-dash-list.cjs.entry.js +5 -5
  16. package/dist/cjs/kup-dash_2.cjs.entry.js +5 -5
  17. package/dist/cjs/kup-drawer.cjs.entry.js +8 -5
  18. package/dist/cjs/kup-echart.cjs.entry.js +210 -60
  19. package/dist/cjs/kup-field.cjs.entry.js +3 -3
  20. package/dist/cjs/kup-iframe.cjs.entry.js +4 -4
  21. package/dist/cjs/kup-lazy.cjs.entry.js +4 -4
  22. package/dist/cjs/kup-magic-box.cjs.entry.js +7 -7
  23. package/dist/cjs/{kup-manager-09c0c1fc.js → kup-manager-5c03da64.js} +3061 -2642
  24. package/dist/cjs/kup-nav-bar.cjs.entry.js +6 -6
  25. package/dist/cjs/kup-numeric-picker.cjs.entry.js +423 -0
  26. package/dist/cjs/kup-photo-frame.cjs.entry.js +179 -0
  27. package/dist/cjs/kup-probe.cjs.entry.js +3 -3
  28. package/dist/cjs/kup-qlik.cjs.entry.js +3 -3
  29. package/dist/cjs/kup-snackbar.cjs.entry.js +6 -6
  30. package/dist/cjs/loader.cjs.js +3 -3
  31. package/dist/cjs/{utils-a60ab5fa.js → utils-e99921c1.js} +4 -38
  32. package/dist/collection/assets/card.js +30 -30
  33. package/dist/collection/assets/data-table.js +24 -74
  34. package/dist/collection/assets/echart.js +481 -0
  35. package/dist/collection/assets/index.js +87 -79
  36. package/dist/collection/assets/kupdata.js +29 -41
  37. package/dist/collection/assets/kuptooltip.js +608 -0
  38. package/dist/collection/assets/list.js +6 -6
  39. package/dist/collection/assets/nav-bar.js +4 -4
  40. package/dist/collection/assets/probe.js +18 -18
  41. package/dist/collection/collection-manifest.json +3 -1
  42. package/dist/collection/components/kup-autocomplete/kup-autocomplete.js +4 -4
  43. package/dist/collection/components/kup-box/kup-box.js +9 -9
  44. package/dist/collection/components/kup-button-list/kup-button-list.js +4 -4
  45. package/dist/collection/components/kup-card/built-in/kup-card-built-in.js +10 -0
  46. package/dist/collection/components/kup-card/built-in/kup-card-column-drop-menu.js +20 -20
  47. package/dist/collection/components/kup-card/built-in/kup-card-numeric.js +153 -0
  48. package/dist/collection/components/kup-card/kup-card.css +35 -0
  49. package/dist/collection/components/kup-card/kup-card.js +1 -0
  50. package/dist/collection/components/kup-chip/kup-chip.js +4 -4
  51. package/dist/collection/components/kup-combobox/kup-combobox.js +5 -5
  52. package/dist/collection/components/kup-data-table/kup-data-table-declarations.js +0 -2
  53. package/dist/collection/components/kup-data-table/kup-data-table-helper.js +31 -32
  54. package/dist/collection/components/kup-data-table/kup-data-table-state.js +1 -1
  55. package/dist/collection/components/kup-data-table/kup-data-table.js +112 -159
  56. package/dist/collection/components/kup-date-picker/kup-date-picker.js +1 -1
  57. package/dist/collection/components/kup-drawer/kup-drawer.js +4 -1
  58. package/dist/collection/components/kup-dropdown-button/kup-dropdown-button.css +3 -3
  59. package/dist/collection/components/kup-dropdown-button/kup-dropdown-button.js +14 -14
  60. package/dist/collection/components/kup-echart/kup-echart-declarations.js +3 -0
  61. package/dist/collection/components/kup-echart/kup-echart.js +246 -58
  62. package/dist/collection/components/kup-image/assets/svg/instagram.svg +1 -0
  63. package/dist/collection/components/kup-image/assets/svg/pinterest.svg +1 -0
  64. package/dist/collection/components/kup-image/assets/svg/reddit.svg +1 -0
  65. package/dist/collection/components/kup-list/kup-list-helper.js +26 -26
  66. package/dist/collection/components/kup-list/kup-list.css +35 -3
  67. package/dist/collection/components/kup-list/kup-list.js +52 -44
  68. package/dist/collection/components/kup-magic-box/kup-magic-box.js +3 -3
  69. package/dist/collection/components/kup-nav-bar/kup-nav-bar.js +2 -2
  70. package/dist/collection/components/kup-numeric-picker/kup-numeric-picker-declarations.js +16 -0
  71. package/dist/collection/components/kup-numeric-picker/kup-numeric-picker.css +50 -0
  72. package/dist/collection/components/kup-numeric-picker/kup-numeric-picker.js +895 -0
  73. package/dist/collection/components/kup-photo-frame/kup-photo-frame-declarations.js +10 -0
  74. package/dist/collection/components/kup-photo-frame/kup-photo-frame.css +70 -0
  75. package/dist/collection/components/kup-photo-frame/kup-photo-frame.js +382 -0
  76. package/dist/collection/components/kup-tab-bar/kup-tab-bar.css +1 -1
  77. package/dist/collection/components/kup-time-picker/kup-time-picker.js +8 -8
  78. package/dist/collection/components/kup-tree/kup-tree.js +25 -38
  79. package/dist/collection/f-components/f-paginator/f-paginator.js +6 -6
  80. package/dist/collection/managers/kup-data/kup-data-cell-helper.js +2 -2
  81. package/dist/collection/managers/kup-data/kup-data-column-helper.js +27 -3
  82. package/dist/collection/managers/kup-data/kup-data-declarations.js +2 -1
  83. package/dist/collection/managers/kup-data/kup-data-node-helper.js +1 -1
  84. package/dist/collection/managers/kup-data/kup-data-row-helper.js +2 -2
  85. package/dist/collection/managers/kup-data/kup-data.js +337 -155
  86. package/dist/collection/managers/kup-dates/kup-dates.js +2 -2
  87. package/dist/collection/managers/kup-debug/kup-debug.js +7 -6
  88. package/dist/collection/managers/kup-dynamic-position/kup-dynamic-position.js +1 -1
  89. package/dist/collection/managers/kup-language/kup-language.js +2 -2
  90. package/dist/collection/managers/kup-manager/kup-manager.js +25 -1
  91. package/dist/collection/managers/kup-math/kup-math-declarations.js +13 -0
  92. package/dist/collection/managers/kup-math/kup-math-helper.js +39 -0
  93. package/dist/collection/managers/kup-math/kup-math.js +161 -0
  94. package/dist/collection/managers/kup-objects/kup-objects.js +48 -1
  95. package/dist/collection/managers/kup-theme/kup-theme-declarations.js +1 -0
  96. package/dist/collection/managers/kup-theme/kup-theme.js +2 -2
  97. package/dist/collection/managers/kup-tooltip/kup-tooltip-declarations.js +1 -0
  98. package/dist/collection/managers/kup-tooltip/kup-tooltip.js +191 -0
  99. package/dist/collection/types/GenericTypes.js +1 -0
  100. package/dist/collection/utils/cell-utils.js +2 -3
  101. package/dist/collection/utils/kup-column-menu/kup-column-menu.js +1 -1
  102. package/dist/collection/utils/utils.js +3 -74
  103. package/dist/esm/{cell-utils-b80ccb8c.js → cell-utils-f4bdbbc8.js} +4 -4
  104. package/dist/esm/{f-button-9e835467.js → f-button-54a49fd8.js} +2 -2
  105. package/dist/esm/{f-cell-f8bb2e04.js → f-cell-d5dac50b.js} +8 -95
  106. package/dist/esm/{f-chip-953c6915.js → f-chip-a3035b4b.js} +3 -3
  107. package/dist/esm/{f-image-78c5265e.js → f-image-d32465e3.js} +2 -2
  108. package/dist/esm/f-text-field-c25cc63f.js +92 -0
  109. package/dist/esm/f-text-field-mdc-9fbbefc3.js +2850 -0
  110. package/dist/esm/{index-78f3699d.js → index-baeab1ac.js} +6 -2
  111. package/dist/esm/ketchup.js +3 -3
  112. package/dist/esm/kup-accordion.entry.js +5 -5
  113. package/dist/esm/kup-autocomplete_27.entry.js +625 -3315
  114. package/dist/esm/kup-calendar.entry.js +8 -8
  115. package/dist/esm/kup-cell.entry.js +9 -8
  116. package/dist/esm/kup-dash-list.entry.js +5 -5
  117. package/dist/esm/kup-dash_2.entry.js +5 -5
  118. package/dist/esm/kup-drawer.entry.js +8 -5
  119. package/dist/esm/kup-echart.entry.js +210 -60
  120. package/dist/esm/kup-field.entry.js +3 -3
  121. package/dist/esm/kup-iframe.entry.js +4 -4
  122. package/dist/esm/kup-lazy.entry.js +4 -4
  123. package/dist/esm/kup-magic-box.entry.js +7 -7
  124. package/dist/esm/{kup-manager-bba62291.js → kup-manager-9316a184.js} +3062 -2642
  125. package/dist/esm/kup-nav-bar.entry.js +6 -6
  126. package/dist/esm/kup-numeric-picker.entry.js +419 -0
  127. package/dist/esm/kup-photo-frame.entry.js +175 -0
  128. package/dist/esm/kup-probe.entry.js +3 -3
  129. package/dist/esm/kup-qlik.entry.js +3 -3
  130. package/dist/esm/kup-snackbar.entry.js +6 -6
  131. package/dist/esm/loader.js +3 -3
  132. package/dist/esm/{utils-d1569956.js → utils-f24319a0.js} +5 -37
  133. package/dist/ketchup/assets/svg/instagram.svg +1 -0
  134. package/dist/ketchup/assets/svg/pinterest.svg +1 -0
  135. package/dist/ketchup/assets/svg/reddit.svg +1 -0
  136. package/dist/ketchup/ketchup.esm.js +1 -1
  137. package/dist/ketchup/p-09d708c4.entry.js +1 -0
  138. package/dist/ketchup/p-11e72a8c.entry.js +1 -0
  139. package/dist/ketchup/p-12773ca8.js +9 -0
  140. package/dist/ketchup/p-203d6295.entry.js +1 -0
  141. package/dist/ketchup/p-34748c91.js +1 -0
  142. package/dist/ketchup/p-34b74425.js +1 -0
  143. package/dist/ketchup/p-40f97429.js +1 -0
  144. package/dist/ketchup/p-4173422f.entry.js +1 -0
  145. package/dist/ketchup/p-41741c28.entry.js +1 -0
  146. package/dist/ketchup/p-44192f30.entry.js +1 -0
  147. package/dist/ketchup/{p-ebf4cf56.js → p-44f8da2a.js} +1 -1
  148. package/dist/ketchup/{p-fa540f82.js → p-4f56932b.js} +1 -1
  149. package/dist/ketchup/p-669bde31.js +1 -0
  150. package/dist/ketchup/p-67842f1e.entry.js +1 -0
  151. package/dist/ketchup/{p-f993f813.js → p-7a74ad17.js} +1 -1
  152. package/dist/ketchup/p-7ba8fa4a.entry.js +39 -0
  153. package/dist/ketchup/p-7de0d7e1.js +1 -0
  154. package/dist/ketchup/p-8418e8fa.entry.js +1 -0
  155. package/dist/ketchup/p-96bf19aa.entry.js +1 -0
  156. package/dist/ketchup/p-9a61d8dc.entry.js +1 -0
  157. package/dist/ketchup/p-b0ddcce9.entry.js +9 -0
  158. package/dist/ketchup/{p-aa27f9f7.entry.js → p-b6c21223.entry.js} +2 -2
  159. package/dist/ketchup/p-bb8844bf.entry.js +1 -0
  160. package/dist/ketchup/p-c58a2a81.entry.js +1 -0
  161. package/dist/ketchup/p-ca3d585b.entry.js +1 -0
  162. package/dist/ketchup/p-e6709c26.entry.js +1 -0
  163. package/dist/ketchup/p-e8e3c9da.entry.js +1 -0
  164. package/dist/ketchup/p-ecb7069b.js +135 -0
  165. package/dist/types/components/kup-button-list/kup-button-list-declarations.d.ts +2 -1
  166. package/dist/types/components/kup-card/built-in/kup-card-built-in.d.ts +7 -0
  167. package/dist/types/components/kup-card/built-in/kup-card-numeric.d.ts +2 -0
  168. package/dist/types/components/kup-card/kup-card-declarations.d.ts +26 -1
  169. package/dist/types/components/kup-data-table/kup-data-table-declarations.d.ts +2 -2
  170. package/dist/types/components/kup-data-table/kup-data-table-state.d.ts +1 -1
  171. package/dist/types/components/kup-data-table/kup-data-table.d.ts +7 -15
  172. package/dist/types/components/kup-dropdown-button/kup-dropdown-button.d.ts +1 -1
  173. package/dist/types/components/kup-echart/kup-echart-declarations.d.ts +3 -0
  174. package/dist/types/components/kup-echart/kup-echart.d.ts +12 -1
  175. package/dist/types/components/kup-list/kup-list-declarations.d.ts +3 -7
  176. package/dist/types/components/kup-list/kup-list-helper.d.ts +6 -6
  177. package/dist/types/components/kup-list/kup-list.d.ts +2 -2
  178. package/dist/types/components/kup-numeric-picker/kup-numeric-picker-declarations.d.ts +19 -0
  179. package/dist/types/components/kup-numeric-picker/kup-numeric-picker.d.ts +121 -0
  180. package/dist/types/components/kup-photo-frame/kup-photo-frame-declarations.d.ts +9 -0
  181. package/dist/types/components/kup-photo-frame/kup-photo-frame.d.ts +61 -0
  182. package/dist/types/components.d.ts +249 -28
  183. package/dist/types/managers/kup-data/kup-data-column-helper.d.ts +9 -1
  184. package/dist/types/managers/kup-data/kup-data-declarations.d.ts +4 -25
  185. package/dist/types/managers/kup-data/kup-data-node-helper.d.ts +1 -1
  186. package/dist/types/managers/kup-data/kup-data.d.ts +63 -27
  187. package/dist/types/managers/kup-manager/kup-manager-declarations.d.ts +21 -0
  188. package/dist/types/managers/kup-manager/kup-manager.d.ts +4 -0
  189. package/dist/types/managers/kup-math/kup-math-declarations.d.ts +27 -0
  190. package/dist/types/managers/kup-math/kup-math-helper.d.ts +17 -0
  191. package/dist/types/managers/kup-math/kup-math.d.ts +61 -0
  192. package/dist/types/managers/kup-objects/kup-objects.d.ts +22 -0
  193. package/dist/types/managers/kup-tooltip/kup-tooltip-declarations.d.ts +8 -0
  194. package/dist/types/managers/kup-tooltip/kup-tooltip.d.ts +40 -0
  195. package/dist/types/types/GenericTypes.d.ts +1 -0
  196. package/dist/types/utils/utils.d.ts +0 -18
  197. package/package.json +3 -3
  198. package/CHANGELOG.md +0 -5
  199. package/dist/collection/managers/kup-data/kup-data-dataset-helper.js +0 -262
  200. package/dist/collection/managers/kup-data/kup-data-helper.js +0 -61
  201. package/dist/collection/utils/state-utils.js +0 -9
  202. package/dist/ketchup/p-0032a782.entry.js +0 -1
  203. package/dist/ketchup/p-18c4d083.entry.js +0 -1
  204. package/dist/ketchup/p-199c972e.entry.js +0 -1
  205. package/dist/ketchup/p-29800a2e.js +0 -1
  206. package/dist/ketchup/p-34aa8d8a.entry.js +0 -1
  207. package/dist/ketchup/p-542279e9.entry.js +0 -1
  208. package/dist/ketchup/p-5b26a7a8.entry.js +0 -39
  209. package/dist/ketchup/p-5c97e7ab.js +0 -1
  210. package/dist/ketchup/p-6817ca85.entry.js +0 -1
  211. package/dist/ketchup/p-76e674ca.entry.js +0 -1
  212. package/dist/ketchup/p-78aa6f1b.js +0 -1
  213. package/dist/ketchup/p-842b66aa.entry.js +0 -1
  214. package/dist/ketchup/p-894981c0.entry.js +0 -143
  215. package/dist/ketchup/p-8ac2fa75.entry.js +0 -1
  216. package/dist/ketchup/p-907c9e11.entry.js +0 -1
  217. package/dist/ketchup/p-9ae9149b.entry.js +0 -1
  218. package/dist/ketchup/p-b0d1bdd8.js +0 -9
  219. package/dist/ketchup/p-e1e4c951.entry.js +0 -1
  220. package/dist/ketchup/p-eba369d9.entry.js +0 -1
  221. package/dist/ketchup/p-ed0b8666.js +0 -1
  222. package/dist/types/managers/kup-data/kup-data-dataset-helper.d.ts +0 -42
  223. package/dist/types/managers/kup-data/kup-data-helper.d.ts +0 -11
  224. package/dist/types/utils/state-utils.d.ts +0 -1
@@ -1,4 +1,4 @@
1
- import { finder } from './kup-data-helper';
1
+ const dom = document.documentElement;
2
2
  /**
3
3
  * Finds all the cells matching the filters criteria in the input dataset.
4
4
  * @param {KupDataDataset} dataset - Input dataset.
@@ -6,7 +6,7 @@ import { finder } from './kup-data-helper';
6
6
  * @returns {KupDataCell[]} Array of cells fetched after applying the filters.
7
7
  */
8
8
  export function findCell(dataset, filters) {
9
- return finder(dataset, filters).cells;
9
+ return dom.ketchup.data.finder(dataset, filters).cells;
10
10
  }
11
11
  /**
12
12
  * Returns all the cells values of the specified columns.
@@ -20,6 +20,9 @@ export function findColumns(dataset, filters) {
20
20
  if (column[key] === filter) {
21
21
  result.push(column);
22
22
  }
23
+ else if (dom.ketchup.objects.deepEqual(column[key], filter)) {
24
+ result.push(column);
25
+ }
23
26
  }
24
27
  }
25
28
  return result;
@@ -55,6 +58,8 @@ export function newColumn(dataset, type, options) {
55
58
  switch (type) {
56
59
  case KupDataNewColumnTypes.CONCATENATE:
57
60
  return newColumnFromConcatenate(dataset, options.columns, options.separator);
61
+ case KupDataNewColumnTypes.DUPLICATE:
62
+ return newColumnFromDuplication(dataset, options.columns, options.newColumn);
58
63
  case KupDataNewColumnTypes.MATH:
59
64
  return newColumnFromMath(dataset, options.operation, options.columns);
60
65
  case KupDataNewColumnTypes.MERGE:
@@ -70,7 +75,7 @@ export function newColumn(dataset, type, options) {
70
75
  * @param {KupDataDataset} dataset - Input dataset.
71
76
  * @param {string[]} columns - Array of column names.
72
77
  * @param {string} separator - Characters used to separate values.
73
- * @returns {string|Column} Returns the new column created or a string containing the error message (if something went wrong).
78
+ * @returns {string|KupDataColumn} Returns the new column created or a string containing the error message (if something went wrong).
74
79
  */
75
80
  function newColumnFromConcatenate(dataset, columns, separator) {
76
81
  if (!columns || columns.length === 0) {
@@ -130,6 +135,25 @@ function newColumnFromConcatenate(dataset, columns, separator) {
130
135
  dataset.columns.splice(dataset.columns.indexOf(firstColumn) + 1, 0, newColumn);
131
136
  return newColumn;
132
137
  }
138
+ /**
139
+ * Creates a duplicate of the specified column.
140
+ * @param {KupDataDataset} dataset - Input dataset.
141
+ * @param {string[]} column2duplicate - Name of the column to duplicate (the first occurrence of the array will be used).
142
+ * @param {KupDataColumn} newColumn - Column created.
143
+ * @returns {KupDataColumn} Resulting column.
144
+ */
145
+ export function newColumnFromDuplication(dataset, column2duplicate, newColumn) {
146
+ const duplicatedName = column2duplicate[0];
147
+ for (let index = 0; index < dataset.rows.length; index++) {
148
+ const row = dataset.rows[index];
149
+ const cells = row.cells;
150
+ if (cells && cells[duplicatedName]) {
151
+ cells[newColumn.name] = Object.assign({}, cells[duplicatedName]);
152
+ }
153
+ }
154
+ dataset.columns.push(newColumn);
155
+ return newColumn;
156
+ }
133
157
  /**
134
158
  * This method is used to create a new column from a mathematical formula.
135
159
  * @param {KupDataDataset} dataset - Input dataset.
@@ -219,11 +243,11 @@ function newColumnFromMath(dataset, operation, columns) {
219
243
  if (!base) {
220
244
  base = cell;
221
245
  }
222
- formulaRow[column] = dom.ketchup.data.numberify(cell.value);
246
+ formulaRow[column] = dom.ketchup.math.numberify(cell.value);
223
247
  }
224
248
  }
225
249
  }
226
- const value = dom.ketchup.data.formulas
250
+ const value = dom.ketchup.math.formulas
227
251
  .custom(formula, formulaRow)
228
252
  .toString();
229
253
  cells[newName] = Object.assign(Object.assign({}, base), { displayedValue: null, obj: Object.assign(Object.assign({}, newObj), { k: value }), value: value });
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Types of column creation when invoking datasetOperations.column.new.
2
+ * Types of column creation when invoking column.new.
3
3
  */
4
4
  export var KupDataNewColumnTypes;
5
5
  (function (KupDataNewColumnTypes) {
6
6
  KupDataNewColumnTypes["CONCATENATE"] = "concatenate";
7
+ KupDataNewColumnTypes["DUPLICATE"] = "duplicate";
7
8
  KupDataNewColumnTypes["MATH"] = "math";
8
9
  KupDataNewColumnTypes["MERGE"] = "merge";
9
10
  })(KupDataNewColumnTypes || (KupDataNewColumnTypes = {}));
@@ -25,7 +25,7 @@ export function removeNode(nodes, node2remove) {
25
25
  return removed;
26
26
  }
27
27
  /**
28
- * Sets the values specified in the filters to every node of the input array.
28
+ * Sets the values specified in the properties to every node of the input array.
29
29
  * @param {KupDataNode[]} nodes - Input array of nodes.
30
30
  * @param {Partial<KupDataNode>} properties - New properties values to set.
31
31
  * @param {boolean} recursively - Sets values to every child node.
@@ -1,4 +1,4 @@
1
- import { finder } from './kup-data-helper';
1
+ const dom = document.documentElement;
2
2
  /**
3
3
  * Finds all the rows containing cells matching the filters criteria in the input dataset.
4
4
  * @param {KupDataDataset} dataset - Input dataset.
@@ -6,7 +6,7 @@ import { finder } from './kup-data-helper';
6
6
  * @returns {KupDataRow[]} Array of rows fetched after applying the filters.
7
7
  */
8
8
  export function findRow(dataset, filters) {
9
- return finder(dataset, filters).rows;
9
+ return dom.ketchup.data.finder(dataset, filters).rows;
10
10
  }
11
11
  /**
12
12
  * Converts the rows of the input dataset to tree nodes.
@@ -1,200 +1,382 @@
1
- import numeral from 'numeral';
2
- import 'numeral/locales/chs';
3
- import 'numeral/locales/es';
4
- import 'numeral/locales/fr';
5
- import 'numeral/locales/it';
6
- import 'numeral/locales/pl';
7
- import 'numeral/locales/ru';
8
- import { KupDebugCategory } from '../kup-debug/kup-debug-declarations';
9
- import { distinctDataset, newDataset, rangedDistinctDataset, sortDataset, transposeDataset, } from './kup-data-dataset-helper';
1
+ import { KupDataNewColumnTypes, } from './kup-data-declarations';
10
2
  import { findCell, getCellValue, replaceCell } from './kup-data-cell-helper';
11
3
  import { findColumns, hideColumns, newColumn } from './kup-data-column-helper';
12
4
  import { findRow, toNode } from './kup-data-row-helper';
13
5
  import { removeNode, setPropertiesNode, toStreamNode, } from './kup-data-node-helper';
6
+ import { fieldColumn } from '../../components/kup-data-table/kup-data-table-declarations';
7
+ import { KupDebugCategory } from '../kup-debug/kup-debug-declarations';
14
8
  const dom = document.documentElement;
15
9
  /**
16
10
  * Handles data operations.
17
11
  * @module KupData
18
12
  */
19
13
  export class KupData {
20
- /**
21
- * Initializes KupData.
22
- */
23
14
  constructor() {
24
- this.datasetOperations = null;
25
- this.formulas = null;
26
- this.numeral = numeral;
27
- this.datasetOperations = {
28
- cell: {
29
- find(dataset, filters) {
30
- return findCell(dataset, filters);
31
- },
32
- getValue(dataset, columns) {
33
- return getCellValue(dataset, columns);
34
- },
35
- replace(dataset, cell, columns) {
36
- return replaceCell(dataset, cell, columns);
37
- },
15
+ this.cell = {
16
+ find(dataset, filters) {
17
+ return findCell(dataset, filters);
38
18
  },
39
- column: {
40
- find(dataset, filters) {
41
- return findColumns(dataset, filters);
42
- },
43
- hide(dataset, columns2hide) {
44
- return hideColumns(dataset, columns2hide);
45
- },
46
- new(dataset, type, options) {
47
- return newColumn(dataset, type, options);
48
- },
19
+ getValue(dataset, columns) {
20
+ return getCellValue(dataset, columns);
49
21
  },
50
- node: {
51
- remove(nodes, node2remove) {
52
- return removeNode(nodes, node2remove);
53
- },
54
- setProperties(nodes, properties, recursively, exclude) {
55
- return setPropertiesNode(nodes, properties, recursively, exclude);
56
- },
57
- toStream(nodes) {
58
- return toStreamNode(nodes);
59
- },
22
+ replace(dataset, cell, columns) {
23
+ return replaceCell(dataset, cell, columns);
60
24
  },
61
- row: {
62
- find(dataset, filters) {
63
- return findRow(dataset, filters);
64
- },
65
- toNode(dataset) {
66
- return toNode(dataset);
67
- },
25
+ };
26
+ this.column = {
27
+ find(dataset, filters) {
28
+ return findColumns(dataset, filters);
68
29
  },
69
- distinct(dataset, columns, valuesColumn) {
70
- return distinctDataset(dataset, columns, valuesColumn);
30
+ hide(dataset, columns2hide) {
31
+ return hideColumns(dataset, columns2hide);
71
32
  },
72
- new(dataset, newColumns) {
73
- return newDataset(dataset, newColumns);
33
+ new(dataset, type, options) {
34
+ return newColumn(dataset, type, options);
74
35
  },
75
- rangedDistinct(dataset, rangeColumns, resultingColumn, valuesColumn) {
76
- return rangedDistinctDataset(dataset, rangeColumns, resultingColumn, valuesColumn);
36
+ };
37
+ this.node = {
38
+ remove(nodes, node2remove) {
39
+ return removeNode(nodes, node2remove);
77
40
  },
78
- sort(dataset, sortType, headerColumn) {
79
- return sortDataset(dataset, sortType, headerColumn);
41
+ setProperties(nodes, properties, recursively, exclude) {
42
+ return setPropertiesNode(nodes, properties, recursively, exclude);
80
43
  },
81
- transpose(dataset, headerColumn) {
82
- return transposeDataset(dataset, headerColumn);
44
+ toStream(nodes) {
45
+ return toStreamNode(nodes);
83
46
  },
84
47
  };
85
- this.formulas = {
86
- /**
87
- * Takes a mathematical formula as string in input, with column names between brackets, and returns the result as a number.
88
- * @param {string} formula - Mathematical operation (i.e.: ([COL1] - [COL2]) * 100 / [COL3]).
89
- * @param {{ [index: string]: number }} row - Object containing column names as indexes and the related values as keys.
90
- * @returns {number} Result of the formula.
91
- */
92
- custom(formula, row) {
93
- const keys = Object.keys(row);
94
- for (let i = 0; i < keys.length; i++) {
95
- let key = keys[i];
96
- let value = row[key];
97
- if (value != null && !isNaN(value)) {
98
- let re = new RegExp(key, 'g');
99
- formula = formula.replace(re, value.toString());
100
- }
101
- }
102
- formula = formula.replace(/[\[\]']+/g, '');
103
- try {
104
- const result = Function('"use strict"; return (' + formula + ')')();
105
- return result;
106
- }
107
- catch (e) {
108
- dom.ketchup.debug.logMessage('kup-data', 'Error while evaluating the following formula!(' +
109
- formula +
110
- ')', KupDebugCategory.ERROR);
111
- return NaN;
112
- }
48
+ this.row = {
49
+ find(dataset, filters) {
50
+ return findRow(dataset, filters);
113
51
  },
114
- /**
115
- * Calculates a single Y point of a normal distribution.
116
- * @param {number} average - Average.
117
- * @param {number} variance - Variance.
118
- * @param {number} x - X coordinate.
119
- * @returns {number} Result.
120
- */
121
- normalDistribution(average, variance, x) {
122
- return ((1 / Math.sqrt(variance * 2 * Math.PI)) *
123
- Math.exp(-Math.pow(x - average, 2) / (2 * variance)));
52
+ toNode(dataset) {
53
+ return toNode(dataset);
124
54
  },
125
55
  };
126
56
  }
127
57
  /**
128
- * Calculates the normal distribution on a set of values.
129
- * @param {string[] | number[] | String[]} values - Array of values.
130
- * @param {number} precision - Number of iterations to run (points). When not specified, defaults to 201.
131
- * @returns {number[][]} Returns an array of arrays containing numbers, which are the representation of the calculated normal distribution.
58
+ * Utility used by findRow and findCell.
59
+ * @param {KupDataDataset} dataset - Input dataset.
60
+ * @param {KupDataFindCellFilters} filters - Filters of the research.
61
+ * @returns {{cells: KupDataCell[], rows: KupDataRow[]}} Object containing rows and cells.
62
+ */
63
+ finder(dataset, filters) {
64
+ const columns = filters ? filters.columns : null;
65
+ const range = filters ? filters.range : null;
66
+ const value = filters ? filters.value : null;
67
+ const min = range && range.min ? range.min : null;
68
+ const max = range && range.max ? range.max : null;
69
+ const result = {
70
+ cells: [],
71
+ rows: [],
72
+ };
73
+ for (let index = 0; index < dataset.rows.length; index++) {
74
+ const row = dataset.rows[index];
75
+ const cells = row.cells;
76
+ for (const key in cells) {
77
+ const cell = cells[key];
78
+ if (!columns || !columns.length || columns.includes(key)) {
79
+ if (min && max) {
80
+ let d = null, s = '', n = 0;
81
+ if (dom.ketchup.objects.isDate(cell.obj)) {
82
+ d = dom.ketchup.dates.toDate(cell.value);
83
+ const dMax = dom.ketchup.dates.toDate(max instanceof String ? max.valueOf() : max);
84
+ const dMin = dom.ketchup.dates.toDate(min instanceof String ? min.valueOf() : min);
85
+ if (d === dMax ||
86
+ d === dMin ||
87
+ (d < dMax && d > dMin)) {
88
+ result.cells.push(cell);
89
+ result.rows.push(row);
90
+ }
91
+ }
92
+ else if (typeof min === 'string' ||
93
+ min instanceof String) {
94
+ s = cell.value;
95
+ if (s === max ||
96
+ s === min ||
97
+ (s < max && s > min)) {
98
+ result.cells.push(cell);
99
+ result.rows.push(row);
100
+ }
101
+ }
102
+ else {
103
+ n = dom.ketchup.math.numberify(cell.value);
104
+ if (n === max ||
105
+ n === min ||
106
+ (n < max && n > min)) {
107
+ result.cells.push(cell);
108
+ result.rows.push(row);
109
+ }
110
+ }
111
+ }
112
+ else if (value === cell.value) {
113
+ result.cells.push(cell);
114
+ result.rows.push(row);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ return result;
120
+ }
121
+ /**
122
+ * Creates a new dataset with an amount of cells equal to a distinct calculation applied to the given columns.
123
+ * The original value of cells will be stored in the title property of the new cells.
124
+ * @param {KupDataDataset} dataset - Input dataset.
125
+ * @param {string[]} columns - Column names to manage. When missing, defaults to all columns.
126
+ * @param {KupDataColumn} valuesColumn - When present, this column will be included in the final dataset containing the original values of the cells.
127
+ * @returns {KupDataDataset} New dataset with processed data.
132
128
  */
133
- normalDistribution(values, precision) {
134
- if (!precision) {
135
- precision = 201;
129
+ distinct(dataset, columns, valuesColumn) {
130
+ const occurrencies = {};
131
+ const rows = dataset.rows;
132
+ for (let index = 0; index < rows.length; index++) {
133
+ const row = rows[index];
134
+ const cells = row.cells;
135
+ for (const key in cells) {
136
+ const cell = cells[key];
137
+ if (!columns ||
138
+ !columns.length ||
139
+ (columns && columns.includes(key))) {
140
+ if (!occurrencies[key]) {
141
+ occurrencies[key] = {};
142
+ }
143
+ const occurrency = occurrencies[key];
144
+ occurrency[cell.value] = occurrency[cell.value]
145
+ ? occurrency[cell.value] + 1
146
+ : 1;
147
+ }
148
+ }
136
149
  }
137
- const data = [];
138
- let max = Math.max.apply(Math, values);
139
- let min = Math.min.apply(Math, values);
140
- let average = 0;
141
- let variance = 0;
142
- for (let index = 0; index < values.length; index++) {
143
- const value = values[index];
144
- average += this.numberify(value);
150
+ const newColumns = [];
151
+ const newRows = [];
152
+ if (valuesColumn) {
153
+ newColumns.push(valuesColumn);
145
154
  }
146
- average = average / values.length;
147
- for (let index = 0; index < values.length; index++) {
148
- const value = values[index];
149
- variance += Math.pow(this.numberify(value) - average, 2);
155
+ for (const key in occurrencies) {
156
+ const occurrency = occurrencies[key];
157
+ const column = Object.assign({}, dataset.columns.find((col) => col.name === key));
158
+ column.obj = {
159
+ t: 'NR',
160
+ p: '',
161
+ k: '',
162
+ };
163
+ let rowIndex = 0;
164
+ newColumns.push(column);
165
+ for (const j in occurrency) {
166
+ const value = occurrency[j];
167
+ let row = null;
168
+ if (!newRows[rowIndex]) {
169
+ newRows[rowIndex] = { cells: {} };
170
+ }
171
+ row = newRows[rowIndex];
172
+ row.cells[key] = {
173
+ obj: {
174
+ t: 'NR',
175
+ p: '',
176
+ k: value.toString(),
177
+ },
178
+ title: j,
179
+ value: value.toString(),
180
+ };
181
+ if (valuesColumn) {
182
+ row.cells[valuesColumn.name] = {
183
+ value: j,
184
+ };
185
+ }
186
+ rowIndex++;
187
+ }
150
188
  }
151
- variance = variance / values.length;
152
- if (!variance) {
153
- variance = 0.001;
189
+ return {
190
+ columns: newColumns,
191
+ rows: newRows,
192
+ };
193
+ }
194
+ /**
195
+ * Creates a new dataset from the input one.
196
+ * The new columns are to be specified in the columns argument along with their creation criteria.
197
+ * @param {KupDataDataset} dataset - Input dataset.
198
+ * @param {KupDataNewColumn[]} newColumns - Array containing the specifics of the new columns to be created.
199
+ * @returns {KupDataDataset} Resulting dataset.
200
+ */
201
+ new(dataset, newColumns) {
202
+ const outputColumns = [];
203
+ const outputRows = [];
204
+ for (let index = 0; index < newColumns.length; index++) {
205
+ const newColumn = newColumns[index].column;
206
+ const criteria = newColumns[index].criteria;
207
+ const cells = findCell(dataset, criteria);
208
+ let rowIndex = 0;
209
+ for (let index = 0; index < cells.length; index++) {
210
+ const cell = cells[index];
211
+ let outputRow = null;
212
+ if (!outputRows[rowIndex]) {
213
+ outputRows[rowIndex] = { cells: {} };
214
+ }
215
+ outputRow = outputRows[rowIndex];
216
+ outputRow.cells[newColumn.name] = JSON.parse(JSON.stringify(cell));
217
+ rowIndex++;
218
+ }
219
+ outputColumns.push(newColumn);
154
220
  }
155
- max = max + ((average / 100) * 50 + (variance / average) * 3);
156
- min = min - ((average / 100) * 50 + (variance / average) * 3);
157
- for (let i = 0; i < precision; i++) {
158
- const x = ((max - min) * i) / precision + min;
159
- data.push([
160
- x,
161
- this.formulas.normalDistribution(average, variance, x),
162
- ]);
221
+ return {
222
+ columns: outputColumns,
223
+ rows: outputRows,
224
+ };
225
+ }
226
+ /**
227
+ * Performs a distinct/count after previously grouping columns by ranges.
228
+ * @param {KupDataDataset} dataset - Input dataset.
229
+ * @param {KupDataNewColumn[]} rangeColumns - A list of columns coupled with their criteria for creation. These are used to define ranges.
230
+ * @param {KupDataColumn} resultingColumn - The resulting column.
231
+ * @param {KupDataColumn} valuesColumn - When present, this column will be included in the final dataset containing the original values of the cells.
232
+ * @returns {KupDataDataset} New dataset with processed data.
233
+ */
234
+ rangedDistinct(dataset, rangeColumns, resultingColumn, valuesColumn) {
235
+ const newD = this.new(dataset, rangeColumns);
236
+ const columnNames = [];
237
+ for (let index = 0; index < rangeColumns.length; index++) {
238
+ const newColumn = rangeColumns[index].column;
239
+ columnNames.push(newColumn.name);
240
+ replaceCell(newD, { value: newColumn.title }, [newColumn.name]);
163
241
  }
164
- return data;
242
+ newColumn(newD, KupDataNewColumnTypes.MERGE, {
243
+ columns: columnNames,
244
+ newColumn: resultingColumn,
245
+ });
246
+ return this.distinct(newD, null, valuesColumn);
165
247
  }
166
248
  /**
167
- * Returns a number from a non-specified input type between string, number, or String.
168
- * @param {string | String | number} input - Input value to numberify.
169
- * @returns {number} Resulting number or NaN (when not a number).
249
+ * Creates a new dataset with sorted elements.
250
+ * @param {KupDataDataset} dataset Input dataset.
251
+ * @param {KupDataDatasetSort} sortType Type of sort to apply.
252
+ * @param {string} headerColumn The column used for sorting.
253
+ * @returns {KupDataDataset} Sorted dataset.
170
254
  */
171
- numberify(input) {
172
- const n = this.numeral(input).value();
173
- if (n === null) {
174
- return NaN;
255
+ sort(dataset, sortType, headerColumn) {
256
+ if (sortType != 'normalDistribution') {
257
+ const message = 'Wrong sort type! (' + sortType + ')';
258
+ dom.ketchup.debug.logMessage('kup-data', message, KupDebugCategory.WARNING);
259
+ return dataset;
260
+ }
261
+ const output = {
262
+ columns: JSON.parse(JSON.stringify(dataset.columns)),
263
+ rows: [],
264
+ };
265
+ const length = dataset.rows.length;
266
+ // sort all columns values by descending
267
+ let values = getCellValue(dataset, [headerColumn]);
268
+ values.sort(function (a, b) {
269
+ return Number(a) - Number(b);
270
+ });
271
+ values.reverse();
272
+ // excluding duplicates values.
273
+ values = [...new Set(values)];
274
+ // calculating middle index
275
+ const idx = Math.floor(length / 2);
276
+ let lastIdx = idx - 1;
277
+ let leftIdx = idx - 1;
278
+ let rightIdx = idx + 1;
279
+ // sort the rows like a "mountain", the greatest is in the middle and the other ones are splitted left and right
280
+ for (let i = 0; i < length; i++) {
281
+ const value = values[i];
282
+ // looping the rows because we have many rows with same value.
283
+ this.finder(dataset, {
284
+ columns: [headerColumn],
285
+ value: value,
286
+ }).rows.forEach((row) => {
287
+ const xC = output.rows[idx];
288
+ if (xC == null) {
289
+ output.rows[idx] = JSON.parse(JSON.stringify(row));
290
+ }
291
+ else {
292
+ output.rows[lastIdx] = JSON.parse(JSON.stringify(row));
293
+ if (lastIdx > idx) {
294
+ // right from the middle index.
295
+ lastIdx = leftIdx;
296
+ rightIdx++;
297
+ }
298
+ else {
299
+ // left from the middle index.
300
+ lastIdx = rightIdx;
301
+ leftIdx--;
302
+ }
303
+ }
304
+ });
175
305
  }
176
- return n;
306
+ return output;
177
307
  }
178
308
  /**
179
- * Formats the input number with the specified format of the currently set locale.
180
- * @param {string | String | number} input - Input number which will be automatically "numberified".
181
- * @param {string} format - Desired format. Defaults to '0,0.0' (i.e.: 2,000,000.51)
182
- * @returns {string} Formatted number.
309
+ * Creates a new dataset with transposed columns and rows.
310
+ * @param {KupDataDataset} dataset - Input dataset.
311
+ * @param {string} headerColumn - When specified, it will be the column used as header. When missing, the header will be a series of progressive numbers.
312
+ * @returns {KupDataDataset} Transposed dataset.
183
313
  */
184
- format(input, format) {
185
- const n = this.numberify(input);
186
- if (!format) {
187
- const positiveN = Math.abs(n);
188
- const decimals = positiveN - Math.floor(positiveN);
189
- if (decimals) {
190
- format = '0,0.0';
314
+ transpose(dataset, headerColumn) {
315
+ const transposed = { columns: [], rows: [] };
316
+ let firstColumn = null;
317
+ if (headerColumn) {
318
+ firstColumn = findColumns(dataset, { name: headerColumn })[0];
319
+ transposed.columns.push(firstColumn);
320
+ for (let index = 0; index < dataset.rows.length; index++) {
321
+ const row = dataset.rows[index];
322
+ const cell = row.cells[firstColumn.name];
323
+ const title = cell.displayedValue
324
+ ? cell.displayedValue
325
+ : cell.value;
326
+ transposed.columns.push({
327
+ name: cell.value + '_' + row.id,
328
+ title,
329
+ });
330
+ }
331
+ }
332
+ else {
333
+ firstColumn = {
334
+ name: fieldColumn.toUpperCase(),
335
+ title: fieldColumn,
336
+ };
337
+ transposed.columns.push(firstColumn);
338
+ for (let index = 0; index < dataset.rows.length; index++) {
339
+ const row = dataset.rows[index];
340
+ transposed.columns.push({
341
+ name: row.id,
342
+ title: '#' + index,
343
+ });
344
+ }
345
+ }
346
+ for (let index = headerColumn ? 1 : 0; index < dataset.columns.length; index++) {
347
+ const oldColumn = dataset.columns[index];
348
+ const cells = {};
349
+ cells[firstColumn.name] = {
350
+ value: oldColumn.title,
351
+ };
352
+ for (let index = 1; index < transposed.columns.length; index++) {
353
+ const newColumn = transposed.columns[index];
354
+ const oldRow = dataset.rows[index - 1];
355
+ const cellName = headerColumn ? newColumn.name : oldRow.id;
356
+ cells[cellName] = oldRow.cells[oldColumn.name];
357
+ if (oldColumn.icon && !cells[cellName].icon) {
358
+ cells[cellName].icon = oldColumn.icon;
359
+ }
360
+ if (oldColumn.shape && !cells[cellName].shape) {
361
+ cells[cellName].shape = oldColumn.shape;
362
+ }
363
+ }
364
+ // If a record is key and no column argument is provided, it will be placed on top
365
+ if (!headerColumn && oldColumn.isKey) {
366
+ transposed.rows.unshift({
367
+ id: String(index),
368
+ cells,
369
+ transposedColumnName: oldColumn.name,
370
+ });
191
371
  }
192
372
  else {
193
- format = '0,0';
373
+ transposed.rows.push({
374
+ id: String(index),
375
+ cells,
376
+ transposedColumnName: oldColumn.name,
377
+ });
194
378
  }
195
379
  }
196
- const formatted = this.numeral(n).format(format);
197
- this.numeral.locale('en'); // TODO: Remove when KupData locale is handled [KupDataLocale]
198
- return formatted;
380
+ return transposed;
199
381
  }
200
382
  }
@@ -314,7 +314,7 @@ export class KupDates {
314
314
  * @param {any} component - The Ketchup component to be registered.
315
315
  */
316
316
  register(component) {
317
- this.managedComponents.add(component.rootElement);
317
+ this.managedComponents.add(component.rootElement ? component.rootElement : component);
318
318
  }
319
319
  /**
320
320
  * Unregisters a KupComponent, so it won't be refreshed when the locale changes.
@@ -323,7 +323,7 @@ export class KupDates {
323
323
  */
324
324
  unregister(component) {
325
325
  if (this.managedComponents) {
326
- this.managedComponents.delete(component.rootElement);
326
+ this.managedComponents.delete(component.rootElement ? component.rootElement : component);
327
327
  }
328
328
  }
329
329
  }