@sme.up/ketchup 8.0.0 → 8.0.2

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 (170) hide show
  1. package/dist/cjs/{f-button-49b2c37c.js → f-button-9524bbf7.js} +2 -2
  2. package/dist/cjs/{f-cell-9a6bc55c.js → f-cell-bcb75ade.js} +22 -13
  3. package/dist/cjs/{f-checkbox-593f72c3.js → f-checkbox-1148e791.js} +1 -1
  4. package/dist/cjs/{f-chip-dee84122.js → f-chip-2249b386.js} +3 -3
  5. package/dist/cjs/{f-image-27f965ff.js → f-image-47d74999.js} +2 -2
  6. package/dist/cjs/{f-paginator-utils-4a30189d.js → f-paginator-utils-b0a9ae5f.js} +64 -63
  7. package/dist/cjs/{f-text-field-04a663b4.js → f-text-field-579c0fc0.js} +83 -9
  8. package/dist/cjs/{index-74433248.js → index-1f177abc.js} +0 -3
  9. package/dist/cjs/ketchup.cjs.js +2 -2
  10. package/dist/cjs/kup-accordion.cjs.entry.js +3 -3
  11. package/dist/cjs/kup-autocomplete_27.cjs.entry.js +798 -815
  12. package/dist/cjs/kup-box.cjs.entry.js +10 -10
  13. package/dist/cjs/kup-calendar.cjs.entry.js +5 -5
  14. package/dist/cjs/kup-cell.cjs.entry.js +7 -7
  15. package/dist/cjs/kup-dash-list.cjs.entry.js +3 -4
  16. package/dist/cjs/kup-dash_2.cjs.entry.js +2 -2
  17. package/dist/cjs/kup-dashboard.cjs.entry.js +6 -6
  18. package/dist/cjs/kup-drawer.cjs.entry.js +2 -2
  19. package/dist/cjs/kup-echart.cjs.entry.js +2 -2
  20. package/dist/cjs/kup-family-tree.cjs.entry.js +4 -4
  21. package/dist/cjs/kup-iframe.cjs.entry.js +2 -2
  22. package/dist/cjs/kup-image-list.cjs.entry.js +8 -8
  23. package/dist/cjs/kup-lazy.cjs.entry.js +2 -2
  24. package/dist/cjs/kup-magic-box.cjs.entry.js +3 -3
  25. package/dist/cjs/{kup-manager-2ff5d258.js → kup-manager-85b2a756.js} +758 -538
  26. package/dist/cjs/kup-nav-bar.cjs.entry.js +2 -2
  27. package/dist/cjs/kup-numeric-picker.cjs.entry.js +3 -3
  28. package/dist/cjs/kup-photo-frame.cjs.entry.js +2 -2
  29. package/dist/cjs/kup-planner.cjs.entry.js +3 -3
  30. package/dist/cjs/kup-probe.cjs.entry.js +2 -2
  31. package/dist/cjs/kup-qlik.cjs.entry.js +2 -2
  32. package/dist/cjs/kup-snackbar.cjs.entry.js +12 -4
  33. package/dist/cjs/loader.cjs.js +2 -2
  34. package/dist/collection/components/kup-card/built-in/kup-card-calendar.js +5 -61
  35. package/dist/collection/components/kup-card/built-in/kup-card-clock.js +1 -1
  36. package/dist/collection/components/kup-dash-list/kup-dash-list.js +1 -3
  37. package/dist/collection/components/kup-data-table/kup-data-table-helper.js +7 -8
  38. package/dist/collection/components/kup-data-table/kup-data-table.js +5 -4
  39. package/dist/collection/components/kup-gauge/kup-gauge.js +4 -4
  40. package/dist/collection/components/kup-snackbar/kup-snackbar.js +27 -0
  41. package/dist/collection/components/kup-text-field/kup-text-field-declarations.js +3 -0
  42. package/dist/collection/components/kup-text-field/kup-text-field.js +107 -9
  43. package/dist/collection/components/kup-time-picker/kup-time-picker.js +7 -7
  44. package/dist/collection/components/kup-tree/kup-tree.js +2 -2
  45. package/dist/collection/f-components/f-cell/f-cell.js +16 -8
  46. package/dist/collection/f-components/f-paginator/f-paginator-utils.js +3 -3
  47. package/dist/collection/f-components/f-text-field/f-text-field.js +80 -6
  48. package/dist/collection/managers/kup-data/kup-data.js +3 -1
  49. package/dist/collection/managers/kup-dates/kup-dates-declarations.js +21 -10
  50. package/dist/collection/managers/kup-dates/kup-dates.js +312 -1
  51. package/dist/collection/managers/kup-math/kup-math.js +258 -6
  52. package/dist/collection/utils/cell-utils.js +5 -6
  53. package/dist/collection/utils/filters/filters.js +11 -13
  54. package/dist/collection/utils/utils.js +18 -444
  55. package/dist/components/kup-autocomplete2.js +1301 -1002
  56. package/dist/components/kup-box2.js +1 -1
  57. package/dist/components/kup-calendar.js +1 -1
  58. package/dist/components/kup-cell.js +1 -1
  59. package/dist/components/kup-dash-list.js +2 -3
  60. package/dist/components/kup-dashboard.js +1 -1
  61. package/dist/components/kup-data-table.js +1 -1
  62. package/dist/components/kup-date-picker.js +1 -1
  63. package/dist/components/kup-dialog.js +1 -1
  64. package/dist/components/kup-dropdown-button.js +1 -1
  65. package/dist/components/kup-echart2.js +1 -1
  66. package/dist/components/kup-family-tree.js +1 -1
  67. package/dist/components/kup-form.js +1 -1
  68. package/dist/components/kup-gauge.js +1 -1
  69. package/dist/components/kup-grid2.js +1 -1
  70. package/dist/components/kup-iframe.js +1 -1
  71. package/dist/components/kup-image-list.js +1 -1
  72. package/dist/components/kup-image.js +1 -1
  73. package/dist/components/kup-list.js +1 -1
  74. package/dist/components/kup-magic-box.js +1 -1
  75. package/dist/components/kup-numeric-picker.js +1 -1
  76. package/dist/components/kup-planner.js +1 -1
  77. package/dist/components/kup-progress-bar.js +1 -1
  78. package/dist/components/kup-radio.js +1 -1
  79. package/dist/components/kup-rating.js +1 -1
  80. package/dist/components/kup-snackbar.js +8 -0
  81. package/dist/components/kup-spinner.js +1 -1
  82. package/dist/components/kup-switch.js +1 -1
  83. package/dist/components/kup-tab-bar.js +1 -1
  84. package/dist/components/kup-text-field.js +1 -1
  85. package/dist/components/kup-time-picker.js +1 -1
  86. package/dist/components/kup-tree.js +1 -1
  87. package/dist/esm/{f-button-744cf1f6.js → f-button-024f0cfe.js} +2 -2
  88. package/dist/esm/{f-cell-b319c869.js → f-cell-90240a8c.js} +22 -13
  89. package/dist/esm/{f-checkbox-ec85b437.js → f-checkbox-9b3f5f5b.js} +1 -1
  90. package/dist/esm/{f-chip-7e3e4180.js → f-chip-2238ad43.js} +3 -3
  91. package/dist/esm/{f-image-098c26ce.js → f-image-f2e9bf79.js} +2 -2
  92. package/dist/esm/{f-paginator-utils-674cb2ae.js → f-paginator-utils-8cb3c023.js} +64 -63
  93. package/dist/esm/{f-text-field-c38ef113.js → f-text-field-d231982c.js} +83 -9
  94. package/dist/esm/{index-b326ffc9.js → index-8bd38435.js} +1 -3
  95. package/dist/esm/ketchup.js +3 -3
  96. package/dist/esm/kup-accordion.entry.js +3 -3
  97. package/dist/esm/kup-autocomplete_27.entry.js +792 -809
  98. package/dist/esm/kup-box.entry.js +10 -10
  99. package/dist/esm/kup-calendar.entry.js +5 -5
  100. package/dist/esm/kup-cell.entry.js +7 -7
  101. package/dist/esm/kup-dash-list.entry.js +3 -4
  102. package/dist/esm/kup-dash_2.entry.js +2 -2
  103. package/dist/esm/kup-dashboard.entry.js +6 -6
  104. package/dist/esm/kup-drawer.entry.js +2 -2
  105. package/dist/esm/kup-echart.entry.js +2 -2
  106. package/dist/esm/kup-family-tree.entry.js +4 -4
  107. package/dist/esm/kup-iframe.entry.js +2 -2
  108. package/dist/esm/kup-image-list.entry.js +8 -8
  109. package/dist/esm/kup-lazy.entry.js +2 -2
  110. package/dist/esm/kup-magic-box.entry.js +3 -3
  111. package/dist/esm/{kup-manager-b41eb2a8.js → kup-manager-d1da769e.js} +758 -529
  112. package/dist/esm/kup-nav-bar.entry.js +2 -2
  113. package/dist/esm/kup-numeric-picker.entry.js +3 -3
  114. package/dist/esm/kup-photo-frame.entry.js +2 -2
  115. package/dist/esm/kup-planner.entry.js +3 -3
  116. package/dist/esm/kup-probe.entry.js +2 -2
  117. package/dist/esm/kup-qlik.entry.js +2 -2
  118. package/dist/esm/kup-snackbar.entry.js +12 -4
  119. package/dist/esm/loader.js +3 -3
  120. package/dist/ketchup/ketchup.esm.js +1 -1
  121. package/dist/ketchup/{p-5ce2b4fc.entry.js → p-063d4c27.entry.js} +1 -1
  122. package/dist/ketchup/{p-4325d965.entry.js → p-0bcda0e2.entry.js} +1 -1
  123. package/dist/ketchup/{p-af82131e.entry.js → p-0d7d59c7.entry.js} +1 -1
  124. package/dist/ketchup/{p-bd42562d.entry.js → p-163b18b9.entry.js} +1 -1
  125. package/dist/ketchup/{p-b244f5ca.entry.js → p-1ad628fb.entry.js} +1 -1
  126. package/dist/ketchup/{p-a9b7533b.entry.js → p-33aff1ca.entry.js} +1 -1
  127. package/dist/ketchup/p-3432ebaf.entry.js +9 -0
  128. package/dist/ketchup/{p-b032f47d.entry.js → p-35b29b22.entry.js} +1 -1
  129. package/dist/ketchup/{p-940a5feb.js → p-36dac88e.js} +3 -3
  130. package/dist/ketchup/{p-395e1960.entry.js → p-37067ee6.entry.js} +1 -1
  131. package/dist/ketchup/p-39a55c47.js +1 -0
  132. package/dist/ketchup/p-3cf64473.js +1 -0
  133. package/dist/ketchup/{p-5d398e42.js → p-410c102a.js} +1 -1
  134. package/dist/ketchup/p-43b67de4.entry.js +1 -0
  135. package/dist/ketchup/{p-a7e19620.entry.js → p-489d55ff.entry.js} +1 -1
  136. package/dist/ketchup/{p-77e3d537.js → p-5f3680f2.js} +1 -1
  137. package/dist/ketchup/p-651d89c8.entry.js +1 -0
  138. package/dist/ketchup/{p-da891093.entry.js → p-73c8d651.entry.js} +1 -1
  139. package/dist/ketchup/{p-bb17c1ba.entry.js → p-83435e6c.entry.js} +1 -1
  140. package/dist/ketchup/{p-3b41aca7.entry.js → p-89743989.entry.js} +1 -1
  141. package/dist/ketchup/{p-ef614656.js → p-8b46e7ce.js} +1 -1
  142. package/dist/ketchup/{p-d4ece435.js → p-9dcfbb1e.js} +2 -2
  143. package/dist/ketchup/{p-c26975bf.js → p-9f9b6656.js} +1 -1
  144. package/dist/ketchup/{p-c968e93d.entry.js → p-a84f1d24.entry.js} +1 -1
  145. package/dist/ketchup/{p-e02b5141.entry.js → p-b2fd2dbf.entry.js} +1 -1
  146. package/dist/ketchup/{p-d739710a.entry.js → p-c42b80c1.entry.js} +1 -1
  147. package/dist/ketchup/p-d1b050d0.entry.js +27 -0
  148. package/dist/ketchup/p-d6ea709e.entry.js +1 -0
  149. package/dist/ketchup/{p-0b91f5f8.entry.js → p-e1f1e661.entry.js} +1 -1
  150. package/dist/ketchup/p-eda7f130.js +1 -0
  151. package/dist/ketchup/{p-4ae2ca6f.entry.js → p-f876125d.entry.js} +1 -1
  152. package/dist/types/components/kup-snackbar/kup-snackbar.d.ts +5 -0
  153. package/dist/types/components/kup-text-field/kup-text-field-declarations.d.ts +3 -0
  154. package/dist/types/components/kup-text-field/kup-text-field.d.ts +20 -2
  155. package/dist/types/components.d.ts +34 -0
  156. package/dist/types/f-components/f-text-field/f-text-field-declarations.d.ts +3 -0
  157. package/dist/types/managers/kup-dates/kup-dates-declarations.d.ts +19 -9
  158. package/dist/types/managers/kup-dates/kup-dates.d.ts +94 -1
  159. package/dist/types/managers/kup-math/kup-math-declarations.d.ts +6 -0
  160. package/dist/types/managers/kup-math/kup-math.d.ts +88 -3
  161. package/dist/types/utils/utils.d.ts +13 -103
  162. package/package.json +1 -1
  163. package/dist/ketchup/p-0b0b61cb.entry.js +0 -1
  164. package/dist/ketchup/p-3efe7f43.entry.js +0 -27
  165. package/dist/ketchup/p-9700eb32.js +0 -1
  166. package/dist/ketchup/p-a877a87b.entry.js +0 -9
  167. package/dist/ketchup/p-c8b7790a.entry.js +0 -1
  168. package/dist/ketchup/p-d98fdb9b.js +0 -1
  169. package/dist/ketchup/p-df316daf.entry.js +0 -1
  170. package/dist/ketchup/p-e714f4dc.js +0 -1
@@ -8,7 +8,7 @@ import 'dayjs/locale/it';
8
8
  import 'dayjs/locale/pl';
9
9
  import 'dayjs/locale/ru';
10
10
  import 'dayjs/locale/zh';
11
- import { KupDatesLocales, KupDatesNormalize } from './kup-dates-declarations';
11
+ import { KupDateTimeFormatOptionsMonth, KupDatesFormats, KupDatesLocales, KupDatesNormalize, } from './kup-dates-declarations';
12
12
  /**
13
13
  * Handles operations and formatting of dates.
14
14
  * @module KupDates
@@ -84,6 +84,59 @@ export class KupDates {
84
84
  .filter((value) => typeof value === 'string');
85
85
  return items;
86
86
  }
87
+ /**
88
+ * Gets date format by browser locale
89
+ * @returns {string} date format pattern, by browser locale
90
+ */
91
+ getDateFormat() {
92
+ const formatObj = new Intl.DateTimeFormat(this.getLocale()).formatToParts(new Date());
93
+ let dateFormat = formatObj
94
+ .map((obj) => {
95
+ switch (obj.type) {
96
+ case 'day':
97
+ return 'DD';
98
+ case 'month':
99
+ return 'MM';
100
+ case 'year':
101
+ return 'YYYY';
102
+ default:
103
+ return obj.value;
104
+ }
105
+ })
106
+ .join('');
107
+ return dateFormat;
108
+ }
109
+ /**
110
+ * Gets time format by browser locale
111
+ * @param {boolean} manageSeconds flag to set seconds managing
112
+ * @returns {string} time format pattern, by browser locale
113
+ */
114
+ getTimeFormat(manageSeconds) {
115
+ const options = {
116
+ hour: '2-digit',
117
+ minute: '2-digit',
118
+ hour12: false,
119
+ };
120
+ if (manageSeconds == true) {
121
+ options.second = '2-digit';
122
+ }
123
+ const formatObj = new Intl.DateTimeFormat(this.getLocale() + '-u-hc-h23', options).formatToParts(new Date());
124
+ let timeFormat = formatObj
125
+ .map((obj) => {
126
+ switch (obj.type) {
127
+ case 'hour':
128
+ return 'HH';
129
+ case 'minute':
130
+ return 'mm';
131
+ case 'second':
132
+ return 'ss';
133
+ default:
134
+ return obj.value;
135
+ }
136
+ })
137
+ .join('');
138
+ return timeFormat;
139
+ }
87
140
  /**
88
141
  * Formats the given date.
89
142
  * @param {dayjs.ConfigType} input - Date to be formatted.
@@ -96,6 +149,23 @@ export class KupDates {
96
149
  }
97
150
  return dayjs(input).format(format);
98
151
  }
152
+ /**
153
+ * Gets the time formatted
154
+ * @param {Date} time time as Date object
155
+ * @param {boolean} manageSeconds flag to set seconds managing
156
+ * @return {string} time as string, formatted
157
+ **/
158
+ formatTime(time, manageSeconds) {
159
+ const options = {
160
+ hour: '2-digit',
161
+ minute: '2-digit',
162
+ hour12: false,
163
+ };
164
+ if (manageSeconds == true) {
165
+ options.second = '2-digit';
166
+ }
167
+ return time.toLocaleTimeString(this.getLocale() + '-u-hc-h23', options);
168
+ }
99
169
  /**
100
170
  * Validates the given date.
101
171
  * @param {dayjs.ConfigType} date - Date to be validated.
@@ -111,6 +181,16 @@ export class KupDates {
111
181
  return dayjs(date, undefined, strict).isValid();
112
182
  }
113
183
  }
184
+ /**
185
+ * Validates the given date as string.
186
+ * @param {string} value time string, formatted by actual browser locale
187
+ * @param {boolean} manageSeconds if manage seconds
188
+ * @returns {boolean} true if time string in input is a valid time
189
+ */
190
+ isValidFormattedStringTime(value, manageSeconds) {
191
+ let format = this.getTimeFormat(manageSeconds);
192
+ return this.isValid(value, format, true);
193
+ }
114
194
  /**
115
195
  * Converts the input in a Date object.
116
196
  * @param {dayjs.ConfigType} input - Input date.
@@ -323,6 +403,237 @@ export class KupDates {
323
403
  subtract(input, value, unit) {
324
404
  return dayjs(input).subtract(value, unit);
325
405
  }
406
+ /**
407
+ * Gets the month formatted
408
+ * @param {number} month month id
409
+ * @param {KupDateTimeFormatOptionsMonth} format format
410
+ * @returns {string} the month formatted, by browser locale
411
+ */
412
+ getMonthAsString(month, format) {
413
+ if (month == null) {
414
+ return '';
415
+ }
416
+ const dateTmp = new Date();
417
+ dateTmp.setDate(1);
418
+ dateTmp.setMonth(month - 1);
419
+ const options = {
420
+ month: format,
421
+ };
422
+ const dateTimeFormat = new Intl.DateTimeFormat(this.getLocale(), options);
423
+ return dateTimeFormat.format(dateTmp);
424
+ }
425
+ /**
426
+ * Gets the year months formatted
427
+ * @param {KupDateTimeFormatOptionsMonth} format format
428
+ * @returns {string[]} the months formatted, by browser locale
429
+ */
430
+ getMonthsAsString(format) {
431
+ if (format == null || format.trim() == '') {
432
+ format = KupDateTimeFormatOptionsMonth.LONG;
433
+ }
434
+ var months = [];
435
+ for (var i = 0; i < 12; i++) {
436
+ months[i] = this.getMonthAsString(i + 1, format);
437
+ }
438
+ return months;
439
+ }
440
+ /**
441
+ * Gets the day formatted
442
+ * @param {Date} date date
443
+ * @returns {string} the day formatted, by browser locale
444
+ */
445
+ getDayAsString(date) {
446
+ if (date == null) {
447
+ return '';
448
+ }
449
+ const options = {
450
+ weekday: 'narrow',
451
+ /** weekday: 'narrow' 'short' 'long' */
452
+ };
453
+ const dateTimeFormat = new Intl.DateTimeFormat(this.getLocale(), options);
454
+ return dateTimeFormat.format(date);
455
+ }
456
+ /**
457
+ * First day of current week
458
+ * @param {number} firstDayIndex first day of week index
459
+ * @returns {Date} the first day of current week
460
+ */
461
+ firstDayThisWeek(firstDayIndex) {
462
+ var d = new Date();
463
+ const day = d.getDay();
464
+ // dayIndex0
465
+ d.setDate(d.getDate() - day);
466
+ // dayIndexX
467
+ d.setDate(d.getDate() + firstDayIndex);
468
+ return d;
469
+ }
470
+ /**
471
+ * Dates of current week
472
+ * @param {number} firstDayIndex first day of week index
473
+ * @returns { startDate: Date; endDate: Date } the dates of current week
474
+ */
475
+ thisWeek(firstDayIndex) {
476
+ const firstDay = this.firstDayThisWeek(firstDayIndex);
477
+ return {
478
+ startDate: firstDay,
479
+ endDate: offsetDate(firstDay, 6),
480
+ };
481
+ function offsetDate(base, count) {
482
+ const date = new Date(base);
483
+ date.setDate(base.getDate() + count);
484
+ return date;
485
+ }
486
+ }
487
+ /**
488
+ * Gets the days of current week as string
489
+ * @param {number} firstDayIndex first day of week index
490
+ * @returns {string[]} the days of current week as string
491
+ */
492
+ getDaysOfWeekAsString(firstDayIndex) {
493
+ var thisWeekDays = this.thisWeek(firstDayIndex);
494
+ var monday = thisWeekDays.startDate;
495
+ var days = [];
496
+ for (var i = 0; i < 7; i++) {
497
+ var date = new Date(monday.toISOString());
498
+ date.setDate(date.getDate() + i);
499
+ days[i] = this.getDayAsString(date);
500
+ }
501
+ return days;
502
+ }
503
+ /**
504
+ * Gets the timestamp formatted
505
+ * @param {string} value date/time as string, formatted ISO
506
+ * @returns {string} date/time as string, formatted by actual browser locale
507
+ **/
508
+ timestampStringToFormattedString(value) {
509
+ const options = {
510
+ day: '2-digit',
511
+ month: '2-digit',
512
+ year: 'numeric',
513
+ hour: '2-digit',
514
+ minute: '2-digit',
515
+ second: '2-digit',
516
+ hour12: false,
517
+ };
518
+ let date = this.toDate(this.normalize(value, KupDatesNormalize.TIMESTAMP));
519
+ return date.toLocaleString(this.getLocale() + '-u-hc-h23', options);
520
+ }
521
+ /**
522
+ * Gets ISO date/time from formatted string, as string
523
+ * @param {string} value date/time as string, formatted by actual browser locale
524
+ * @returns {string} date/time as string, formatted ISO
525
+ **/
526
+ formattedStringToTimestampString(value) {
527
+ return this.formattedStringToCustomDateTime(value, KupDatesFormats.ISO_DATE_TIME, true);
528
+ }
529
+ /**
530
+ * Gets formatted dateTime as customed ISO (see KupDatesFormats)
531
+ * @param {string} value time as string, formatted by actual browser locale
532
+ * @param {string} outputFormat time format to return (see KupDatesFormats)
533
+ * @param {boolean} manageSeconds flag to set seconds managing
534
+ * @returns {string} time as string, formatted
535
+ **/
536
+ formattedStringToCustomDateTime(value, outputFormat, manageSeconds) {
537
+ let inputFormat = this.getTimeFormat(manageSeconds);
538
+ if (this.isValid(value, inputFormat)) {
539
+ return this.format(this.normalize(value, KupDatesNormalize.TIME), outputFormat);
540
+ }
541
+ else {
542
+ return '';
543
+ }
544
+ }
545
+ /**
546
+ * Gets the time formatted
547
+ * @param {string} value time as string, formatted ISO
548
+ * @param {boolean} manageSeconds flag to set seconds managing
549
+ * @param {string} customedFormat time format from smeupObject
550
+ * @returns {string} time as string, formatted by actual browser locale
551
+ **/
552
+ timeStringToFormattedString(value, manageSeconds, customedFormat) {
553
+ const options = {
554
+ hour: '2-digit',
555
+ minute: '2-digit',
556
+ hour12: false,
557
+ };
558
+ if (manageSeconds == true) {
559
+ options.second = '2-digit';
560
+ }
561
+ let date = this.toDate(this.normalize(value, KupDatesNormalize.TIME));
562
+ return formatByCustomedOutputTimeFormat(value, date, options, customedFormat, this);
563
+ function formatByCustomedOutputTimeFormat(valueStr, date, options, customedFormat, kupDates) {
564
+ if (customedFormat == null) {
565
+ return date.toLocaleTimeString(kupDates.getLocale() + '-u-hc-h23', options);
566
+ }
567
+ switch (customedFormat) {
568
+ case 'I13': {
569
+ //hh:mm
570
+ break;
571
+ }
572
+ case 'I12': {
573
+ //hh:mm:ss
574
+ break;
575
+ }
576
+ case 'I11': {
577
+ //???
578
+ //hh:dddd
579
+ //return moment(date).format('HH:DDDD');
580
+ return valueStr;
581
+ }
582
+ case 'I14': {
583
+ //???
584
+ //sssss
585
+ //return moment(date).format('SSSSS');
586
+ return valueStr;
587
+ }
588
+ case 'I1H': {
589
+ //???
590
+ //Ora,Cen/Min HH,xx
591
+ return valueStr;
592
+ }
593
+ case 'I1M': {
594
+ //???
595
+ //Min,Cen/Sec MMMM,xx
596
+ return valueStr;
597
+ }
598
+ case 'I21': {
599
+ //???
600
+ //Giorni,(4 decim)
601
+ return valueStr;
602
+ }
603
+ case 'I22': {
604
+ //???
605
+ //Ore,(4 decim)
606
+ return valueStr;
607
+ }
608
+ case 'I23': {
609
+ //???
610
+ //Minuti,(4 decim)
611
+ return valueStr;
612
+ }
613
+ case 'I24': {
614
+ //???
615
+ //Secondi
616
+ return valueStr;
617
+ }
618
+ case 'I2H': {
619
+ //???
620
+ //Ora,Cen/Min HHHH,xx
621
+ return valueStr;
622
+ }
623
+ case 'I2D': {
624
+ //???
625
+ //Ore Minuti Secondi HHMMS
626
+ return valueStr;
627
+ }
628
+ case 'I2M': {
629
+ //???
630
+ //Min,Cen/Sec MMMM,xx
631
+ return valueStr;
632
+ }
633
+ }
634
+ return date.toLocaleTimeString(kupDates.getLocale() + '-u-hc-h23', options);
635
+ }
636
+ }
326
637
  /**
327
638
  * Registers a KupComponent in KupDates, in order to be properly handled whenever the locale changes.
328
639
  * @param {any} component - The Ketchup component to be registered.
@@ -8,6 +8,7 @@ import 'numeral/locales/ru';
8
8
  import { KupDebugCategory } from '../kup-debug/kup-debug-declarations';
9
9
  import { KupMathLocales, } from './kup-math-declarations';
10
10
  import { customFormula, normalDistributionFormula } from './kup-math-helper';
11
+ import { getRegExpFromString } from '../../utils/utils';
11
12
  const dom = document.documentElement;
12
13
  /**
13
14
  * Handles mathematical operations and number formatting/conversion.
@@ -31,7 +32,7 @@ export class KupMath {
31
32
  const maximumFractionDigits = 14;
32
33
  if (value == null || value == '')
33
34
  return value;
34
- return Number(value).toLocaleString(dom.ketchup.math.locale, {
35
+ return Number(value).toLocaleString(this.locale, {
35
36
  maximumFractionDigits: maximumFractionDigits,
36
37
  });
37
38
  },
@@ -102,10 +103,11 @@ export class KupMath {
102
103
  * Formats the input number with the specified format of the currently set locale.
103
104
  * @param {string | String | number} input - Input number which will be automatically "numberified".
104
105
  * @param {string} format - Desired format. Defaults to '0,0.00' (i.e.: 2,000,000.51).
106
+ * @param {boolean} inputIsLocalized Numberifies assuming the input string is in the current KupMath locale's format.
105
107
  * @returns {string} Formatted number.
106
108
  */
107
- format(input, format) {
108
- const n = this.numberify(input);
109
+ format(input, format, inputIsLocalized) {
110
+ const n = this.numberify(input, inputIsLocalized);
109
111
  if (!format) {
110
112
  const positiveN = Math.abs(n);
111
113
  const decimals = positiveN - Math.floor(positiveN);
@@ -116,16 +118,111 @@ export class KupMath {
116
118
  format = '0,0';
117
119
  }
118
120
  }
119
- const formatted = this.numeral(n).format(format);
120
- return formatted;
121
+ return this.numeral(n).format(format);
122
+ }
123
+ /**
124
+ * Create the pattern string for format a number
125
+ * @param {boolean} thousandPoint - show thousandPoint
126
+ * @param {number} decimals - number of decimals
127
+ * @returns {string} - formatter pattern
128
+ */
129
+ createFormatPattern(thousandPoint, decimals) {
130
+ var format = '0';
131
+ if (thousandPoint) {
132
+ format += ',0';
133
+ }
134
+ if (decimals && decimals > 0) {
135
+ format += '.';
136
+ for (let i = 0; i < decimals; i++) {
137
+ format += '0';
138
+ }
139
+ }
140
+ return format;
141
+ }
142
+ /**
143
+ * Returns the decimal separator of current browser
144
+ * @returns {string} current decimal separator, by locale
145
+ */
146
+ decimalSeparator() {
147
+ const numberWithGroupAndDecimalSeparator = 1000.1;
148
+ return Intl.NumberFormat(this.locale)
149
+ .formatToParts(numberWithGroupAndDecimalSeparator)
150
+ .find((part) => part.type === 'decimal').value;
151
+ }
152
+ /**
153
+ * Returns the group separator of current browser
154
+ * @returns {string} current group separator, by locale
155
+ */
156
+ groupSeparator() {
157
+ const numberWithGroupAndDecimalSeparator = 1000.1;
158
+ return Intl.NumberFormat(this.locale)
159
+ .formatToParts(numberWithGroupAndDecimalSeparator)
160
+ .find((part) => part.type === 'group').value;
161
+ }
162
+ /**
163
+ * Checks if an input string matches options, for desired formatted decimal number (integer digits, decimal digits)
164
+ * @param {string} value the input value to check
165
+ * @param {NumericFieldFormatOptions} options options for customize the check
166
+ * @returns {RegExpMatchArray} an object from applying the regular expression for check
167
+ */
168
+ matchNumericValueWithOptions(value, options) {
169
+ value = value.replace(getRegExpFromString(this.groupSeparator(), 'g'), '');
170
+ // see https://github.com/24eme/jquery-input-number-format.git
171
+ let found = undefined;
172
+ let integerPartSuffix = '+';
173
+ if (options.integer && options.integer > 0) {
174
+ integerPartSuffix = '{0,' + options.integer + '}';
175
+ }
176
+ let regexp = '^[0-9]' + integerPartSuffix;
177
+ if (options.allowNegative) {
178
+ regexp = '^-{0,1}[0-9]' + integerPartSuffix;
179
+ }
180
+ if (options.decimal && options.decimal > 0) {
181
+ regexp +=
182
+ '([' +
183
+ this.decimalSeparator() +
184
+ '][0-9]{0,' +
185
+ options.decimal +
186
+ '})?';
187
+ let regexpObj = new RegExp(regexp + '$');
188
+ found = value.match(regexpObj);
189
+ if (!found) {
190
+ regexp =
191
+ '^[' +
192
+ this.decimalSeparator() +
193
+ '][0-9]{0,' +
194
+ options.decimal +
195
+ '}';
196
+ regexpObj = new RegExp(regexp + '$');
197
+ found = value.match(regexpObj);
198
+ }
199
+ }
200
+ else {
201
+ let regexpObj = new RegExp(regexp + '$');
202
+ found = value.match(regexpObj);
203
+ }
204
+ return found;
121
205
  }
122
206
  /**
123
207
  * Returns a number from a non-specified input type between string, number, or String.
124
208
  * @param {string | String | number} input - Input value to numberify.
125
209
  * @param {boolean} inputIsLocalized - Numberifies assuming the input string is in the current KupMath locale's format.
210
+ * @param {string} type - type of number for calculate suffix
126
211
  * @returns {number} Resulting number or NaN (when not a number).
127
212
  */
128
- numberify(input, inputIsLocalized) {
213
+ numberify(input, inputIsLocalized, type) {
214
+ if (typeof input != 'number') {
215
+ if (type) {
216
+ let suffix = this.getNumericValueSuffix(type);
217
+ if (suffix != '') {
218
+ input = input.replace(getRegExpFromString(suffix, 'g'), '');
219
+ }
220
+ }
221
+ const groupSeparator = inputIsLocalized
222
+ ? this.groupSeparator()
223
+ : ',';
224
+ input = input.replace(getRegExpFromString(groupSeparator, 'g'), '');
225
+ }
129
226
  let n = NaN;
130
227
  if (inputIsLocalized) {
131
228
  n = this.numeral(input).value();
@@ -141,6 +238,161 @@ export class KupMath {
141
238
  }
142
239
  return n;
143
240
  }
241
+ /**
242
+ * Returns a number from a non-specified input type between string, number, or String.
243
+ * If value in is null, undefined or blank, returns 0
244
+ * @param {string} input number as string, formatted by locale US, decimal separator . (like java decimal numbers)
245
+ * @param {boolean} inputIsLocalized - Numberifies assuming the input string is in the current KupMath locale's format.
246
+ * @param {string} type - type of number for calculate suffix
247
+ * @returns {number} Resulting number
248
+ **/
249
+ numberifySafe(input, inputIsLocalized, type) {
250
+ if (!input || input == null || input.trim() == '') {
251
+ input = '0';
252
+ }
253
+ return this.numberify(input, inputIsLocalized, type);
254
+ }
255
+ /**
256
+ * Checks if input is a valid number
257
+ * @param {any} value input value to check
258
+ * @returns {boolean} if input value is valid number
259
+ */
260
+ isNumber(value) {
261
+ //return typeof value === 'number';
262
+ return !isNaN(value);
263
+ }
264
+ /**
265
+ * Checks if string in input is a valid formatted number
266
+ * @param {string} value number as string, formatted by actual browser locale
267
+ * @param {string} type - type of number for calculate suffix
268
+ * @returns {boolean} true if number string in input is a valid number
269
+ */
270
+ isStringNumber(value, type) {
271
+ if (value == null || value.trim() == '') {
272
+ return false;
273
+ }
274
+ let tmpStr = this.formattedStringToNumberString(value, type);
275
+ if (this.isNumber(tmpStr)) {
276
+ return true;
277
+ }
278
+ return false;
279
+ }
280
+ /**
281
+ * Gets number as string, formatted by locale US, decimal separator . (like java decimal numbers)
282
+ * @param {string} input number as string, formatted by actual browser locale (maybe)
283
+ * @param {string} type - type of number for calculate suffix
284
+ * @param {string} decSeparator - decimal serparator of input string
285
+ * @returns {string} number as string, formatted by locale US, decimal separator . (like java decimal numbers), without group separator
286
+ **/
287
+ formattedStringToNumberString(input, type, decSeparator) {
288
+ return numberStringToNumberString(input, type, decSeparator !== null && decSeparator !== void 0 ? decSeparator : this.decimalSeparator(), this);
289
+ function numberStringToNumberString(input, type, decFmt, kupMath) {
290
+ if (!input || input == null || input.trim() == '') {
291
+ return '';
292
+ }
293
+ let unf = kupMath.numberifySafe(input, decFmt != '.', type);
294
+ if (unf == null || isNaN(unf)) {
295
+ return input;
296
+ }
297
+ return numberToString(unf, -1, 'en-US', kupMath);
298
+ }
299
+ function numberToString(input, decimals, locale, kupMath) {
300
+ if (input == null) {
301
+ input = 0;
302
+ }
303
+ if (decimals == null || decimals == -1) {
304
+ decimals = kupMath.countDecimals(input);
305
+ }
306
+ let n = Number(input);
307
+ let f = decimals > -1
308
+ ? {
309
+ minimumFractionDigits: decimals,
310
+ maximumFractionDigits: decimals,
311
+ useGrouping: false,
312
+ }
313
+ : { useGrouping: false };
314
+ return n.toLocaleString(locale, f);
315
+ }
316
+ }
317
+ /**
318
+ * Gets the number of decimals for current number
319
+ * @param {number} value numer input
320
+ * @returns {number} the number of decimals
321
+ */
322
+ countDecimals(value) {
323
+ var _a;
324
+ if (Math.floor(value) === value)
325
+ return 0;
326
+ let stringValue = value.toString().split('.')[1];
327
+ if (stringValue) {
328
+ return (_a = stringValue.length) !== null && _a !== void 0 ? _a : 0;
329
+ }
330
+ else {
331
+ return 0;
332
+ }
333
+ }
334
+ /**
335
+ * Gets the suffix for number, by type
336
+ * @param {string} type - type of number for calculate suffix
337
+ * @returns {string} suffix for number, by type
338
+ **/
339
+ getNumericValueSuffix(type) {
340
+ type = type.toUpperCase();
341
+ let nstr = '';
342
+ if (type == 'P') {
343
+ nstr = ' %';
344
+ }
345
+ else if (type == 'VE') {
346
+ nstr = ' €';
347
+ }
348
+ else if (type == 'VL') {
349
+ nstr = ' £';
350
+ }
351
+ else if (type == 'VV') {
352
+ nstr = ' $';
353
+ }
354
+ return nstr;
355
+ }
356
+ /**
357
+ * Gets the number as string, formatted by actual browser locale, with suffix by type
358
+ * @param {number} input number
359
+ * @param {number} decimals number of significant decimal digits for output
360
+ * @param {string} type - type of number for calculate suffix
361
+ * @returns {string} number as string, formatted by actual browser locale, with suffix by type
362
+ **/
363
+ numberToFormattedString(input, decimals, type) {
364
+ if (input == null || isNaN(input)) {
365
+ return '';
366
+ }
367
+ if (decimals == null || decimals == -1) {
368
+ decimals = this.countDecimals(input);
369
+ }
370
+ let nstr = this.format(input, this.createFormatPattern(true, decimals));
371
+ nstr = nstr + this.getNumericValueSuffix(type);
372
+ return nstr;
373
+ }
374
+ /**
375
+ * Gets the number as string, formatted by actual browser locale, with suffix by type
376
+ * @param {string} input number as string, formatted by locale US, decimal separator . (like java decimal numbers)
377
+ * @param {number} decimals number of significant decimal digits for output
378
+ * @param {string} type - type of number for calculate suffix
379
+ * @param {string} decSeparator decimal separator for outpu string
380
+ * @returns {string} number as string, formatted by actual browser locale (or using decimal separator param), with suffix by type
381
+ **/
382
+ numberStringToFormattedString(input, decimals, type, decSeparator) {
383
+ let value = this.numberToFormattedString(this.numberifySafe(input), decimals, type);
384
+ if (!decSeparator) {
385
+ return value;
386
+ }
387
+ const browserDecSeparator = this.decimalSeparator();
388
+ if (browserDecSeparator == decSeparator) {
389
+ return value;
390
+ }
391
+ const browserGroupSeparator = this.groupSeparator();
392
+ value = value.replace(getRegExpFromString(browserGroupSeparator, 'g'), '');
393
+ value = value.replace(getRegExpFromString(browserDecSeparator, 'g'), decSeparator);
394
+ return value;
395
+ }
144
396
  /**
145
397
  * Registers a KupComponent in KupMath, in order to be properly handled whenever the locale changes.
146
398
  * @param {any} component - The Ketchup component to be registered.
@@ -1,4 +1,3 @@
1
- import { stringToNumber, unformattedStringToFormattedStringNumber, unformattedStringToFormattedStringTime, unformattedStringToFormattedStringTimestamp, } from './utils';
2
1
  import { KupDatesFormats } from '../managers/kup-dates/kup-dates-declarations';
3
2
  const dom = document.documentElement;
4
3
  // -------------
@@ -43,17 +42,17 @@ export function getValueForDisplay(value, obj, decimals) {
43
42
  return value;
44
43
  }
45
44
  if (dom.ketchup.objects.isNumber(obj)) {
46
- return unformattedStringToFormattedStringNumber(value, decimals ? decimals : -1, obj ? obj.p : '');
45
+ return dom.ketchup.math.numberStringToFormattedString(value, decimals ? decimals : -1, obj ? obj.p : '');
47
46
  }
48
47
  if (dom.ketchup.objects.isDate(obj) &&
49
48
  dom.ketchup.dates.isValid(value, KupDatesFormats.ISO_DATE)) {
50
49
  return dom.ketchup.dates.format(value);
51
50
  }
52
51
  if (dom.ketchup.objects.isTime(obj)) {
53
- return unformattedStringToFormattedStringTime(value, dom.ketchup.objects.isTimeWithSeconds(obj), obj.t + obj.p);
52
+ return dom.ketchup.dates.timeStringToFormattedString(value, dom.ketchup.objects.isTimeWithSeconds(obj), obj.t + obj.p);
54
53
  }
55
54
  if (dom.ketchup.objects.isTimestamp(obj)) {
56
- return unformattedStringToFormattedStringTimestamp(value);
55
+ return dom.ketchup.dates.timestampStringToFormattedString(value);
57
56
  }
58
57
  return value;
59
58
  }
@@ -98,8 +97,8 @@ export function compareValues(obj1, value1, obj2, value2, sortMode) {
98
97
  let v1 = s1;
99
98
  let v2 = s2;
100
99
  if (dom.ketchup.objects.isNumber(obj1)) {
101
- v1 = stringToNumber(s1);
102
- v2 = stringToNumber(s2);
100
+ v1 = dom.ketchup.math.numberifySafe(s1);
101
+ v2 = dom.ketchup.math.numberifySafe(s2);
103
102
  }
104
103
  else if (dom.ketchup.objects.isDate(obj1)) {
105
104
  v1 = dom.ketchup.dates.toDate(dom.ketchup.dates.format(s1, KupDatesFormats.ISO_DATE));