@rolster/react-components 18.12.10 → 18.13.0

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 (136) hide show
  1. package/dist/cjs/assets/{index-VcI5p9dK.css → index-fykwrWLx.css} +700 -652
  2. package/dist/cjs/index.js +745 -779
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/es/assets/{index-VcI5p9dK.css → index-fykwrWLx.css} +700 -652
  5. package/dist/es/index.js +747 -781
  6. package/dist/es/index.js.map +1 -1
  7. package/dist/esm/components/atoms/Amount/Amount.css +3 -3
  8. package/dist/esm/components/atoms/Avatar/Avatar.css +7 -7
  9. package/dist/esm/components/atoms/Badge/Badge.css +7 -7
  10. package/dist/esm/components/atoms/Breadcrumb/Breadcrumb.css +12 -12
  11. package/dist/esm/components/atoms/Button/Button.css +74 -53
  12. package/dist/esm/components/atoms/Button/Button.d.ts +1 -1
  13. package/dist/esm/components/atoms/Button/Button.js +1 -1
  14. package/dist/esm/components/atoms/Button/Button.js.map +1 -1
  15. package/dist/esm/components/atoms/ButtonAction/ButtonAction.css +22 -22
  16. package/dist/esm/components/atoms/CheckBox/CheckBox.css +8 -8
  17. package/dist/esm/components/atoms/Icon/Icon.css +7 -8
  18. package/dist/esm/components/atoms/Input/Input.css +13 -13
  19. package/dist/esm/components/atoms/InputMoney/InputMoney.css +1 -1
  20. package/dist/esm/components/atoms/InputNumber/InputNumber.css +1 -1
  21. package/dist/esm/components/atoms/InputPassword/InputPassword.css +8 -8
  22. package/dist/esm/components/atoms/InputText/InputText.css +1 -1
  23. package/dist/esm/components/atoms/Label/Label.css +1 -1
  24. package/dist/esm/components/atoms/MessageIcon/MessageIcon.css +6 -6
  25. package/dist/esm/components/atoms/Poster/Poster.css +6 -6
  26. package/dist/esm/components/atoms/ProgressBar/ProgressBar.css +7 -7
  27. package/dist/esm/components/atoms/ProgressCircular/ProgressCircular.css +5 -5
  28. package/dist/esm/components/atoms/RadioButton/RadioButton.css +6 -6
  29. package/dist/esm/components/atoms/SearchInput/SearchInput.css +4 -4
  30. package/dist/esm/components/atoms/Skeleton/Skeleton.css +6 -6
  31. package/dist/esm/components/atoms/SkeletonText/SkeletonText.css +6 -8
  32. package/dist/esm/components/atoms/Switch/Switch.css +16 -16
  33. package/dist/esm/components/atoms/TabularText/TabularText.css +2 -2
  34. package/dist/esm/components/definitions.d.ts +1 -1
  35. package/dist/esm/components/molecules/Ballot/Ballot.css +27 -34
  36. package/dist/esm/components/molecules/ButtonProgress/ButtonProgress.css +1 -1
  37. package/dist/esm/components/molecules/ButtonToggle/ButtonToggle.css +32 -30
  38. package/dist/esm/components/molecules/CheckBoxLabel/CheckBoxLabel.css +8 -8
  39. package/dist/esm/components/molecules/DayPicker/DayPicker.css +39 -27
  40. package/dist/esm/components/molecules/DayPicker/DayPicker.d.ts +3 -1
  41. package/dist/esm/components/molecules/DayPicker/DayPicker.js +32 -24
  42. package/dist/esm/components/molecules/DayPicker/DayPicker.js.map +1 -1
  43. package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.css +28 -28
  44. package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.js +16 -19
  45. package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.js.map +1 -1
  46. package/dist/esm/components/molecules/MoneyField/MoneyField.css +1 -2
  47. package/dist/esm/components/molecules/MonthPicker/MonthPicker.css +34 -19
  48. package/dist/esm/components/molecules/MonthPicker/MonthPicker.d.ts +2 -1
  49. package/dist/esm/components/molecules/MonthPicker/MonthPicker.js +30 -19
  50. package/dist/esm/components/molecules/MonthPicker/MonthPicker.js.map +1 -1
  51. package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.css +6 -6
  52. package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.d.ts +1 -1
  53. package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.js +26 -21
  54. package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.js.map +1 -1
  55. package/dist/esm/components/molecules/NumberField/NumberField.css +1 -2
  56. package/dist/esm/components/molecules/Pagination/Pagination.css +29 -30
  57. package/dist/esm/components/molecules/PasswordField/PasswordField.css +4 -5
  58. package/dist/esm/components/molecules/RadioButtonLabel/RadioButtonLabel.css +8 -10
  59. package/dist/esm/components/molecules/SwitchLabel/SwitchLabel.css +8 -9
  60. package/dist/esm/components/molecules/TextField/TextField.css +1 -2
  61. package/dist/esm/components/molecules/Toolbar/Toolbar.css +10 -10
  62. package/dist/esm/components/molecules/YearPicker/YearPicker.css +42 -28
  63. package/dist/esm/components/molecules/YearPicker/YearPicker.d.ts +1 -1
  64. package/dist/esm/components/molecules/YearPicker/YearPicker.js +33 -26
  65. package/dist/esm/components/molecules/YearPicker/YearPicker.js.map +1 -1
  66. package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.css +22 -22
  67. package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.d.ts +1 -1
  68. package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.js +1 -1
  69. package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.js.map +1 -1
  70. package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.d.ts +1 -1
  71. package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.js +27 -81
  72. package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.js.map +1 -1
  73. package/dist/esm/components/organisms/Card/Card.css +5 -5
  74. package/dist/esm/components/organisms/Confirmation/Confirmation.css +38 -38
  75. package/dist/esm/components/organisms/DateField/DateField.css +15 -15
  76. package/dist/esm/components/organisms/DateField/DateField.d.ts +2 -2
  77. package/dist/esm/components/organisms/DateField/DateField.js +27 -16
  78. package/dist/esm/components/organisms/DateField/DateField.js.map +1 -1
  79. package/dist/esm/components/organisms/DatePicker/DatePicker.css +27 -24
  80. package/dist/esm/components/organisms/DatePicker/DatePicker.d.ts +2 -2
  81. package/dist/esm/components/organisms/DatePicker/DatePicker.js +37 -55
  82. package/dist/esm/components/organisms/DatePicker/DatePicker.js.map +1 -1
  83. package/dist/esm/components/organisms/DateRangeField/DateRangeField.css +13 -15
  84. package/dist/esm/components/organisms/DateRangeField/DateRangeField.js +5 -5
  85. package/dist/esm/components/organisms/DateRangeField/DateRangeField.js.map +1 -1
  86. package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.css +20 -20
  87. package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.d.ts +2 -2
  88. package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.js +13 -33
  89. package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.js.map +1 -1
  90. package/dist/esm/components/organisms/FormNavigation/FormNavigation.css +15 -14
  91. package/dist/esm/components/organisms/Modal/Modal.css +11 -11
  92. package/dist/esm/components/organisms/SelectField/SelectField.css +1 -1
  93. package/dist/esm/components/organisms/SelectField/SelectField.d.ts +1 -1
  94. package/dist/esm/components/organisms/SelectField/SelectField.js +1 -1
  95. package/dist/esm/components/organisms/SelectField/SelectField.js.map +1 -1
  96. package/dist/esm/components/organisms/SelectField/SelectFieldHook.d.ts +1 -1
  97. package/dist/esm/components/organisms/SelectField/SelectFieldHook.js +18 -35
  98. package/dist/esm/components/organisms/SelectField/SelectFieldHook.js.map +1 -1
  99. package/dist/esm/components/organisms/Snackbar/Snackbar.css +26 -26
  100. package/dist/esm/constants/index.d.ts +1 -0
  101. package/dist/esm/constants/index.js +2 -0
  102. package/dist/esm/constants/index.js.map +1 -0
  103. package/dist/esm/constants/picker.constant.d.ts +1 -0
  104. package/dist/esm/constants/picker.constant.js +2 -0
  105. package/dist/esm/constants/picker.constant.js.map +1 -0
  106. package/dist/esm/helpers/date-range-picker.d.ts +1 -12
  107. package/dist/esm/helpers/date-range-picker.js +5 -107
  108. package/dist/esm/helpers/date-range-picker.js.map +1 -1
  109. package/dist/esm/helpers/index.d.ts +2 -0
  110. package/dist/esm/helpers/index.js +3 -0
  111. package/dist/esm/helpers/index.js.map +1 -0
  112. package/dist/esm/hooks/ListControlHook.d.ts +2 -3
  113. package/dist/esm/hooks/ListControlHook.js +22 -92
  114. package/dist/esm/hooks/ListControlHook.js.map +1 -1
  115. package/dist/esm/index.d.ts +1 -2
  116. package/dist/esm/index.js +1 -2
  117. package/dist/esm/index.js.map +1 -1
  118. package/package.json +4 -3
  119. package/dist/esm/helpers/date-picker.d.ts +0 -1
  120. package/dist/esm/helpers/date-picker.js +0 -9
  121. package/dist/esm/helpers/date-picker.js.map +0 -1
  122. package/dist/esm/helpers/day-picker.d.ts +0 -9
  123. package/dist/esm/helpers/day-picker.js +0 -86
  124. package/dist/esm/helpers/day-picker.js.map +0 -1
  125. package/dist/esm/helpers/month-picker.d.ts +0 -14
  126. package/dist/esm/helpers/month-picker.js +0 -78
  127. package/dist/esm/helpers/month-picker.js.map +0 -1
  128. package/dist/esm/helpers/year-picker.d.ts +0 -17
  129. package/dist/esm/helpers/year-picker.js +0 -83
  130. package/dist/esm/helpers/year-picker.js.map +0 -1
  131. package/dist/esm/models.d.ts +0 -58
  132. package/dist/esm/models.js +0 -9
  133. package/dist/esm/models.js.map +0 -1
  134. package/dist/esm/types.d.ts +0 -12
  135. package/dist/esm/types.js +0 -7
  136. package/dist/esm/types.js.map +0 -1
package/dist/cjs/index.js CHANGED
@@ -56,7 +56,7 @@ function RlsIcon({ value, skeleton }) {
56
56
  }
57
57
 
58
58
  function RlsButton({ type, children, disabled, prefixIcon, suffixIcon, rlsTheme, onClick }) {
59
- return (jsxRuntime.jsx("button", { className: "rls-button", onClick: onClick, "rls-theme": rlsTheme, disabled: disabled, children: jsxRuntime.jsxs("div", { className: renderClassStatus('rls-button__content', { type }), children: [prefixIcon && jsxRuntime.jsx(RlsIcon, { value: prefixIcon }), children && (jsxRuntime.jsx("div", { className: "rls-button__label", children: children })), suffixIcon && jsxRuntime.jsx(RlsIcon, { value: suffixIcon })] }) }));
59
+ return (jsxRuntime.jsx("button", { className: "rls-button", onClick: onClick, "rls-theme": rlsTheme, disabled: disabled, children: jsxRuntime.jsxs("div", { className: renderClassStatus('rls-button__content', { type }), children: [prefixIcon && jsxRuntime.jsx(RlsIcon, { value: prefixIcon }), children && jsxRuntime.jsx("div", { className: "rls-button__label", children: children }), suffixIcon && jsxRuntime.jsx(RlsIcon, { value: suffixIcon })] }) }));
60
60
  }
61
61
 
62
62
  function RlsButtonAction({ icon, disabled, tooltip, onClick }) {
@@ -275,245 +275,541 @@ function RlsCheckBoxLabel({ children, disabled, extended, formControl, rlsTheme
275
275
  }), "rls-theme": rlsTheme, children: [jsxRuntime.jsx("div", { className: "rls-checkbox-label__component", onClick: onToggle, children: jsxRuntime.jsx(RlsCheckBox, { checked: checked, disabled: disabled }) }), jsxRuntime.jsx("label", { className: "rls-checkbox-label__text", children: children })] }));
276
276
  }
277
277
 
278
- class DayPickerFactory {
279
- constructor(props) {
280
- const { date, value, maxDate, minDate } = props;
281
- this.value = value;
282
- this.date = new Date(date.getTime());
283
- this.maxDate = maxDate;
284
- this.minDate = minDate;
285
- this.date.setDate(1);
286
- }
287
- static execute(props) {
288
- const factory = new DayPickerFactory(props);
289
- const firstWeek = factory.createFirstWeek();
290
- const rightWeeks = factory.createRightWeeks();
291
- return [firstWeek, ...rightWeeks];
292
- }
293
- createFirstWeek() {
294
- const dayStart = this.date.getDay();
295
- const days = [];
296
- let day = 1;
297
- for (let start = 0; start < dayStart; start++) {
298
- days.push(this.createDayState());
299
- }
300
- for (let end = dayStart; end < 7; end++) {
301
- days.push(this.createDayState(day));
302
- day++;
303
- }
304
- return { days };
305
- }
306
- createRightWeeks() {
307
- const dayStart = this.date.getDay();
308
- const rightWeeks = [];
309
- const dayCount = helpersDate.getDaysOfMonth(this.date.getFullYear(), this.date.getMonth());
310
- let days = [];
311
- let countDaysWeek = 1;
312
- let day = 8 - dayStart;
313
- do {
314
- days.push(this.createDayState(day));
315
- day++;
316
- countDaysWeek++;
317
- if (countDaysWeek > 7) {
318
- rightWeeks.push({ days });
319
- days = [];
320
- countDaysWeek = 1;
321
- }
322
- } while (day <= dayCount);
323
- const daysPending = this.createDaysPending(days.length);
324
- rightWeeks.push({ days: [...days, ...daysPending] });
325
- return rightWeeks;
326
- }
327
- createDaysPending(daysWeek) {
328
- const daysPending = [];
329
- const length = 7 - daysWeek;
330
- for (let index = 0; index < length; index++) {
331
- daysPending.push(this.createDayState());
332
- }
333
- return daysPending;
334
- }
335
- createDayState(value) {
336
- return {
337
- disabled: this.overflowDay(value || 0),
338
- forbidden: !value,
339
- selected: value === this.value,
340
- value
341
- };
342
- }
343
- overflowDay(day) {
344
- return this.minOverflowDay(day) || this.maxOverflowDay(day);
345
- }
346
- minOverflowDay(day) {
347
- return this.minDate
348
- ? helpersDate.getDateWeight(helpersDate.assignDayInDate(this.date, day)) <
349
- helpersDate.getDateWeight(this.minDate)
350
- : false;
351
- }
352
- maxOverflowDay(day) {
353
- return this.maxDate
354
- ? helpersDate.getDateWeight(helpersDate.assignDayInDate(this.date, day)) >
355
- helpersDate.getDateWeight(this.maxDate)
356
- : false;
357
- }
278
+ function dateIsOutRangeMin(props) {
279
+ const { date, minDate } = props;
280
+ return !!minDate && helpersDate.dateIsBefore(helpersDate.normalizeMinTime(minDate), date);
281
+ }
282
+ function dateIsOutRangeMax(props) {
283
+ const { date, maxDate } = props;
284
+ return !!maxDate && helpersDate.dateIsAfter(helpersDate.normalizeMaxTime(maxDate), date);
285
+ }
286
+ function dateOutRange(props) {
287
+ return dateIsOutRangeMin(props) || dateIsOutRangeMax(props);
288
+ }
289
+ function checkDateRange(props) {
290
+ const { date, maxDate, minDate } = props;
291
+ return minDate && dateIsOutRangeMax(props)
292
+ ? minDate
293
+ : maxDate && dateIsOutRangeMax(props)
294
+ ? maxDate
295
+ : date;
296
+ }
297
+
298
+ const DAYS_WEEK = 7;
299
+ const COUNT_YEAR_RANGE = 4;
300
+
301
+ function createDayState(props, today, value) {
302
+ const { date, day, month, year } = props;
303
+ const dateValue = value && new Date(year, month, value);
304
+ return {
305
+ disabled: dayIsOutside(props, value || 0),
306
+ focused: !!value && day === value,
307
+ forbidden: !value,
308
+ selected: !!dateValue && helpersDate.dateIsEqualsWeight(date, dateValue),
309
+ today: !!dateValue && helpersDate.dateIsEqualsWeight(today, dateValue),
310
+ value
311
+ };
312
+ }
313
+ function createFirstWeek$1(props, date, today) {
314
+ const days = [];
315
+ let day = 1;
316
+ for (let start = 0; start < date.getDay(); start++) {
317
+ days.push(createDayState(props, today));
318
+ }
319
+ for (let end = date.getDay(); end < 7; end++) {
320
+ days.push(createDayState(props, today, day));
321
+ day++;
322
+ }
323
+ return { days };
324
+ }
325
+ function createDaysPending$1(props, today, days) {
326
+ const daysPending = [];
327
+ const length = 7 - days;
328
+ for (let index = 0; index < length; index++) {
329
+ daysPending.push(createDayState(props, today));
330
+ }
331
+ return daysPending;
332
+ }
333
+ function createNextWeeks$1(props, date, today) {
334
+ const daysMonth = helpersDate.getDaysOfMonth(date.getFullYear(), date.getMonth());
335
+ const weeks = [];
336
+ let days = [];
337
+ let countDays = 1;
338
+ let day = DAYS_WEEK - date.getDay() + 1;
339
+ do {
340
+ days.push(createDayState(props, today, day));
341
+ day++;
342
+ countDays++;
343
+ if (countDays > DAYS_WEEK) {
344
+ weeks.push({ days });
345
+ days = [];
346
+ countDays = 1;
347
+ }
348
+ } while (day <= daysMonth);
349
+ if (days.length && days.length < DAYS_WEEK) {
350
+ weeks.push({
351
+ days: [...days, ...createDaysPending$1(props, today, days.length)]
352
+ });
353
+ }
354
+ return weeks;
355
+ }
356
+ function dayIsOutsideMin(props, day) {
357
+ const { month, year, minDate } = props;
358
+ return minDate
359
+ ? helpersDate.getDateWeight(new Date(year, month, day)) < helpersDate.getDateWeight(minDate)
360
+ : false;
361
+ }
362
+ function dayIsOutsideMax(props, day) {
363
+ const { month, year, maxDate } = props;
364
+ return maxDate
365
+ ? helpersDate.getDateWeight(new Date(year, month, day)) > helpersDate.getDateWeight(maxDate)
366
+ : false;
367
+ }
368
+ function dayIsOutside(props, day) {
369
+ return dayIsOutsideMin(props, day) || dayIsOutsideMax(props, day);
370
+ }
371
+ function checkDayPicker(props) {
372
+ const { day, maxDate, minDate } = props;
373
+ return minDate && dayIsOutsideMin(props, day)
374
+ ? minDate.getDate()
375
+ : maxDate && dayIsOutsideMax(props, day)
376
+ ? maxDate.getDate()
377
+ : undefined;
378
+ }
379
+ function createDayPicker(props) {
380
+ const date = new Date(props.year, props.month, 1);
381
+ const today = new Date();
382
+ const firstWeek = createFirstWeek$1(props, date, today);
383
+ const nextWeeks = createNextWeeks$1(props, date, today);
384
+ return [firstWeek, ...nextWeeks];
385
+ }
386
+
387
+ function dateIsSelected(base, date, day) {
388
+ return (date.getFullYear() === base.getFullYear() &&
389
+ date.getMonth() === base.getMonth() &&
390
+ day === date.getDate());
391
+ }
392
+ function sourceIsSelected({ sourceDate }, base, day) {
393
+ return dateIsSelected(base, sourceDate, day);
394
+ }
395
+ function rangeIsSelected({ range }, base, day) {
396
+ return (dateIsSelected(base, range.minDate, day) ||
397
+ dateIsSelected(base, range.maxDate, day));
398
+ }
399
+ function dayIsRange({ range }, base, day) {
400
+ return helpersDate.dateIsBetween(range.minDate, range.maxDate, helpersDate.assignDayInDate(base, day));
401
+ }
402
+ function createDayRangeState(props, base, day) {
403
+ return {
404
+ disabled: dayRangeIsOutside(props, day || 0),
405
+ end: day ? rangeIsSelected(props, base, day) : false,
406
+ forbidden: !day,
407
+ ranged: day ? dayIsRange(props, base, day) : false,
408
+ source: day ? sourceIsSelected(props, base, day) : false,
409
+ value: day
410
+ };
411
+ }
412
+ function createFirstWeek(props, base) {
413
+ const days = [];
414
+ let day = 1;
415
+ for (let start = 0; start < base.getDay(); start++) {
416
+ days.push(createDayRangeState(props, base));
417
+ }
418
+ for (let end = base.getDay(); end < 7; end++) {
419
+ days.push(createDayRangeState(props, base, day));
420
+ day++;
421
+ }
422
+ return { days };
423
+ }
424
+ function createDaysPending(props, base, days) {
425
+ const daysPending = [];
426
+ const length = 7 - days;
427
+ for (let index = 0; index < length; index++) {
428
+ daysPending.push(createDayRangeState(props, base));
429
+ }
430
+ return daysPending;
431
+ }
432
+ function createNextWeeks(props, base) {
433
+ const weeks = [];
434
+ const { date } = props;
435
+ const dayCount = helpersDate.getDaysOfMonth(date.getFullYear(), date.getMonth());
436
+ let days = [];
437
+ let countDays = 1;
438
+ let day = DAYS_WEEK - base.getDay() + 1;
439
+ do {
440
+ days.push(createDayRangeState(props, date, day));
441
+ day++;
442
+ countDays++;
443
+ if (countDays > 7) {
444
+ weeks.push({ days });
445
+ days = [];
446
+ countDays = 1;
447
+ }
448
+ } while (day <= dayCount);
449
+ if (days.length && days.length < DAYS_WEEK) {
450
+ weeks.push({
451
+ days: [...days, ...createDaysPending(props, base, days.length)]
452
+ });
453
+ }
454
+ return weeks;
455
+ }
456
+ function dayRangeIsOutsideMin(props, day) {
457
+ const { date, minDate } = props;
458
+ return minDate
459
+ ? helpersDate.getDateWeight(helpersDate.assignDayInDate(date, day)) < helpersDate.getDateWeight(minDate)
460
+ : false;
461
+ }
462
+ function dayRangeIsOutsideMax(props, day) {
463
+ const { date, maxDate } = props;
464
+ return maxDate
465
+ ? helpersDate.getDateWeight(helpersDate.assignDayInDate(date, day)) > helpersDate.getDateWeight(maxDate)
466
+ : false;
467
+ }
468
+ function dayRangeIsOutside(props, day) {
469
+ return dayRangeIsOutsideMin(props, day) || dayRangeIsOutsideMax(props, day);
470
+ }
471
+ function createDayRangePicker(props) {
472
+ const date = new Date(props.date.getFullYear(), props.date.getMonth(), 1);
473
+ const firstWeek = createFirstWeek(props, date);
474
+ const nextWeeks = createNextWeeks(props, date);
475
+ return [firstWeek, ...nextWeeks];
476
+ }
477
+
478
+ function createMonthState(props, value) {
479
+ const { date, month, year } = props;
480
+ return {
481
+ disabled: monthIsOutside(props, value),
482
+ focused: value === month,
483
+ label: helpersDate.MONTH_NAMES()[value],
484
+ selected: date.getFullYear() === year && value === date.getMonth(),
485
+ value
486
+ };
487
+ }
488
+ function monthIsOutsideMin(props, month) {
489
+ const { year, minDate } = props;
490
+ return minDate
491
+ ? minDate.getFullYear() === year && month < minDate.getMonth()
492
+ : false;
493
+ }
494
+ function monthIsOutsideMax(props, month) {
495
+ const { year, maxDate } = props;
496
+ return maxDate
497
+ ? maxDate.getFullYear() === year && month > maxDate.getMonth()
498
+ : false;
499
+ }
500
+ function monthIsOutside(props, month) {
501
+ return monthIsOutsideMin(props, month) || monthIsOutsideMax(props, month);
502
+ }
503
+ function checkMonthPicker(props) {
504
+ const { maxDate, minDate, month } = props;
505
+ return minDate && monthIsOutsideMin(props, month)
506
+ ? minDate.getMonth()
507
+ : maxDate && monthIsOutsideMax(props, month)
508
+ ? maxDate.getMonth()
509
+ : undefined;
510
+ }
511
+ function createMonthPicker(props) {
512
+ return [
513
+ createMonthState(props, helpersDate.Month.January),
514
+ createMonthState(props, helpersDate.Month.February),
515
+ createMonthState(props, helpersDate.Month.March),
516
+ createMonthState(props, helpersDate.Month.April),
517
+ createMonthState(props, helpersDate.Month.May),
518
+ createMonthState(props, helpersDate.Month.June),
519
+ createMonthState(props, helpersDate.Month.July),
520
+ createMonthState(props, helpersDate.Month.August),
521
+ createMonthState(props, helpersDate.Month.September),
522
+ createMonthState(props, helpersDate.Month.October),
523
+ createMonthState(props, helpersDate.Month.November),
524
+ createMonthState(props, helpersDate.Month.December)
525
+ ];
526
+ }
527
+ function monthIsLimitMin(props) {
528
+ const { month, date, minDate } = props;
529
+ if (helpersAdvanced.itIsDefined(month) && date) {
530
+ const minYear = minDate ? minDate.getFullYear() : 0;
531
+ const minMonth = minDate ? minDate.getMonth() : 0;
532
+ return date.getFullYear() === minYear && month <= minMonth;
533
+ }
534
+ return false;
535
+ }
536
+ function monthIsLimitMax(props) {
537
+ const { month, date, maxDate } = props;
538
+ if (helpersAdvanced.itIsDefined(month) && date) {
539
+ const maxYear = maxDate ? maxDate.getFullYear() : 10000;
540
+ const maxMonth = maxDate ? maxDate.getMonth() : 11;
541
+ return date.getFullYear() === maxYear && month >= maxMonth;
542
+ }
543
+ return false;
544
+ }
545
+ function monthLimitTemplate(props) {
546
+ return {
547
+ limitNext: monthIsLimitMax(props),
548
+ limitPrevious: monthIsLimitMin(props)
549
+ };
550
+ }
551
+
552
+ var PickerListenerType;
553
+ (function (PickerListenerType) {
554
+ PickerListenerType["Select"] = "PickerSelect";
555
+ PickerListenerType["Now"] = "PickerNow";
556
+ PickerListenerType["Cancel"] = "PickerCancel";
557
+ })(PickerListenerType || (PickerListenerType = {}));
558
+
559
+ function createYear(props, value) {
560
+ const { date, year } = props;
561
+ return {
562
+ disabled: !value,
563
+ focused: value === year,
564
+ selected: value === date.getFullYear(),
565
+ value
566
+ };
567
+ }
568
+ function yearIsOutlineMin(props) {
569
+ const { year, minDate } = props;
570
+ return minDate ? year < minDate.getFullYear() : false;
571
+ }
572
+ function yearIsOutlineMax(props) {
573
+ const { year, maxDate } = props;
574
+ return maxDate ? year > maxDate.getFullYear() : false;
575
+ }
576
+ function checkYearPicker(props) {
577
+ const { maxDate, minDate } = props;
578
+ return minDate && yearIsOutlineMin(props)
579
+ ? minDate.getFullYear()
580
+ : maxDate && yearIsOutlineMax(props)
581
+ ? maxDate.getFullYear()
582
+ : undefined;
583
+ }
584
+ function createYearPicker(props) {
585
+ const { year, maxDate, minDate } = props;
586
+ const prevYears = [];
587
+ const nextYears = [];
588
+ let minRange = year;
589
+ let maxRange = year;
590
+ const minYear = minDate?.getFullYear() || 0;
591
+ const maxYear = maxDate?.getFullYear() || 10000;
592
+ for (let index = 0; index < COUNT_YEAR_RANGE; index++) {
593
+ const prevValue = year - COUNT_YEAR_RANGE + index;
594
+ const nextValue = year + index + 1;
595
+ const prevYear = prevValue >= minYear ? prevValue : undefined;
596
+ const nextYear = nextValue <= maxYear ? nextValue : undefined;
597
+ const prevState = createYear(props, prevYear);
598
+ const nextState = createYear(props, nextYear);
599
+ prevYears.push(prevState);
600
+ nextYears.push(nextState);
601
+ if (!!prevState.value && minRange > prevState.value) {
602
+ minRange = prevState.value;
603
+ }
604
+ if (!!nextState.value && maxRange < nextState.value) {
605
+ maxRange = nextState.value;
606
+ }
607
+ }
608
+ const yearCenter = createYear(props, year);
609
+ return {
610
+ canPrevious: minYear < minRange,
611
+ canNext: maxYear > maxRange,
612
+ maxRange,
613
+ minRange,
614
+ years: [...prevYears, yearCenter, ...nextYears]
615
+ };
616
+ }
617
+
618
+ function createEmptyStore() {
619
+ return {
620
+ coincidences: undefined,
621
+ pattern: '',
622
+ previous: null
623
+ };
624
+ }
625
+ function searchForPattern(props) {
626
+ const { pattern, store } = props;
627
+ if (!store?.pattern) {
628
+ return null;
629
+ }
630
+ let newStore = store;
631
+ let search = false;
632
+ while (!search && newStore) {
633
+ search = helpersString.hasPattern(pattern || '', newStore.pattern, true);
634
+ if (!search) {
635
+ newStore = newStore.previous;
636
+ }
637
+ }
638
+ return newStore || createEmptyStore();
639
+ }
640
+ function createStoreAutocomplete(props) {
641
+ const { pattern, suggestions, reboot } = props;
642
+ if (!pattern) {
643
+ return { collection: suggestions, store: createEmptyStore() };
644
+ }
645
+ const store = reboot ? createEmptyStore() : searchForPattern(props);
646
+ const elements = store?.coincidences || suggestions;
647
+ const coincidences = elements.filter((element) => element.hasCoincidence(pattern));
648
+ return {
649
+ collection: coincidences,
650
+ store: {
651
+ coincidences,
652
+ pattern,
653
+ previous: store
654
+ }
655
+ };
656
+ }
657
+
658
+ const classElement = '.rls-list-field__element';
659
+ const POSITION_INITIAL = 0;
660
+ function locationListIsBottom(contentElement, listElement) {
661
+ if (contentElement && listElement) {
662
+ const { top, height } = contentElement.getBoundingClientRect();
663
+ const { clientHeight } = listElement;
664
+ return top + height + clientHeight < window.innerHeight;
665
+ }
666
+ return true;
667
+ }
668
+ function navigationInputDown(props) {
669
+ const { contentElement, listElement } = props;
670
+ if (!locationListIsBottom(contentElement, listElement)) {
671
+ return undefined;
672
+ }
673
+ const elements = listElement?.querySelectorAll(classElement);
674
+ if (elements?.length) {
675
+ elements.item(0).focus();
676
+ setTimeout(() => {
677
+ listElement?.scroll({ top: 0, behavior: 'smooth' });
678
+ }, 100);
679
+ }
680
+ return POSITION_INITIAL;
681
+ }
682
+ function navigationInputUp(props) {
683
+ const { contentElement, listElement } = props;
684
+ if (locationListIsBottom(contentElement, listElement)) {
685
+ return undefined;
686
+ }
687
+ const elements = listElement?.querySelectorAll(classElement);
688
+ if (!elements?.length) {
689
+ return POSITION_INITIAL;
690
+ }
691
+ const position = elements.length - 1;
692
+ const element = elements.item(position);
693
+ element?.focus();
694
+ setTimeout(() => {
695
+ listElement?.scroll({
696
+ top: element?.offsetTop + element?.offsetLeft,
697
+ behavior: 'smooth'
698
+ });
699
+ }, 100);
700
+ return position;
701
+ }
702
+ function navigationElementDown(props) {
703
+ const { contentElement, inputElement, listElement, position } = props;
704
+ const elements = listElement?.querySelectorAll(classElement);
705
+ const newPosition = position + 1;
706
+ if (newPosition < (elements?.length || 0)) {
707
+ elements?.item(newPosition)?.focus();
708
+ return newPosition;
709
+ }
710
+ if (!locationListIsBottom(contentElement, listElement)) {
711
+ inputElement?.focus();
712
+ }
713
+ return position;
714
+ }
715
+ function navigationElementUp(props) {
716
+ const { contentElement, inputElement, listElement, position } = props;
717
+ if (position > 0) {
718
+ const elements = listElement?.querySelectorAll(classElement);
719
+ const newPosition = position - 1;
720
+ elements?.item(newPosition)?.focus();
721
+ return newPosition;
722
+ }
723
+ if (locationListIsBottom(contentElement, listElement)) {
724
+ inputElement?.focus();
725
+ }
726
+ return POSITION_INITIAL;
727
+ }
728
+ function listNavigationInput(props) {
729
+ switch (props.event.code) {
730
+ case 'ArrowDown':
731
+ return navigationInputDown(props);
732
+ case 'ArrowUp':
733
+ return navigationInputUp(props);
734
+ default:
735
+ return undefined;
736
+ }
737
+ }
738
+ function listNavigationElement(props) {
739
+ const { event } = props;
740
+ switch (event.code) {
741
+ case 'ArrowDown':
742
+ return navigationElementDown(props);
743
+ case 'ArrowUp':
744
+ return navigationElementUp(props);
745
+ default:
746
+ return POSITION_INITIAL;
747
+ }
358
748
  }
359
- function createDayPicker(props) {
360
- return DayPickerFactory.execute(props);
749
+
750
+ class ListCollection {
751
+ constructor(value) {
752
+ this.value = value;
753
+ }
754
+ find(element) {
755
+ return this.value.find((current) => current.compareTo(element));
756
+ }
361
757
  }
362
758
 
363
- function RlsDayPicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, rlsTheme, onValue }) {
364
- const initialDate = date || new Date();
365
- const initialDay = formControl?.state || initialDate.getDate();
759
+ function RlsDayPicker({ date, disabled: disabledPicker, formControl, maxDate, month, minDate, onValue, rlsTheme, year }) {
760
+ const currentDate = date || new Date(); // Initial date
366
761
  const [weeks, setWeeks] = react.useState([]);
367
- const [value, setValue] = react.useState(initialDay);
762
+ const [value, setValue] = react.useState(formControl?.state || currentDate.getDate());
763
+ react.useEffect(() => {
764
+ const props = createPickerProps();
765
+ const day = checkDayPicker(props);
766
+ day ? setDayValue(day) : setWeeks(createDayPicker(props));
767
+ }, [date, month, year, value, minDate, maxDate]);
368
768
  react.useEffect(() => {
369
- setWeeks(createDayPicker({
370
- date: initialDate,
371
- value: formControl?.state || value,
769
+ const day = checkDayPicker(createPickerProps());
770
+ day
771
+ ? formControl?.setState(day)
772
+ : setValue(formControl?.state || currentDate.getDate());
773
+ }, [formControl?.state]);
774
+ function createPickerProps() {
775
+ return {
776
+ date: currentDate,
777
+ day: formControl?.state || value,
778
+ month: helpersAdvanced.itIsDefined(month) ? month : currentDate.getMonth(),
779
+ year: year || currentDate.getFullYear(),
372
780
  minDate,
373
781
  maxDate
374
- }));
375
- }, [value, date, minDate, maxDate]);
376
- react.useEffect(() => {
377
- if (date && date.getDate() !== value) {
378
- onChange(date.getDate());
379
- }
380
- }, [date]);
782
+ };
783
+ }
784
+ function setDayValue(value) {
785
+ formControl ? formControl.setState(value) : setValue(value);
786
+ }
381
787
  function onChange(value) {
382
- setValue(value);
383
- formControl?.setState(value);
788
+ setDayValue(value);
384
789
  if (onValue) {
385
790
  onValue(value);
386
791
  }
387
792
  }
388
- return (jsxRuntime.jsxs("div", { className: "rls-day-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsx("div", { className: "rls-day-picker__header", children: helpersDate.DAY_LABELS().map((title, index) => (jsxRuntime.jsx("label", { className: "rls-day-picker__label", children: title }, index))) }), jsxRuntime.jsx("div", { className: "rls-day-picker__component", children: weeks.map(({ days }, index) => (jsxRuntime.jsx("div", { className: "rls-day-picker__week", children: days.map(({ value, disabled, forbidden, selected }, index) => (jsxRuntime.jsx("div", { className: renderClassStatus('rls-day-picker__day', {
793
+ return (jsxRuntime.jsxs("div", { className: "rls-day-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsx("div", { className: "rls-day-picker__header", children: helpersDate.DAY_LABELS().map((title, index) => (jsxRuntime.jsx("label", { className: "rls-day-picker__label", children: title }, index))) }), jsxRuntime.jsx("div", { className: "rls-day-picker__component", children: weeks.map(({ days }, index) => (jsxRuntime.jsx("div", { className: "rls-day-picker__week", children: days.map(({ value, disabled, focused, forbidden, selected, today }, index) => (jsxRuntime.jsx("div", { className: renderClassStatus('rls-day-picker__day', {
389
794
  disabled: disabled || disabledPicker,
795
+ focused,
390
796
  forbidden,
391
- selected
392
- }), onClick: () => {
393
- if (value && !disabled) {
394
- onChange(value);
395
- }
396
- }, children: jsxRuntime.jsx("span", { className: "rls-day-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
797
+ selected,
798
+ today
799
+ }), onClick: value && !disabledPicker ? () => onChange(value) : undefined, children: jsxRuntime.jsx("span", { className: "rls-day-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
397
800
  }
398
801
 
399
802
  const DATE_RANGE_FORMAT = '{dd}/{mx}/{aa}';
400
- class DateRangePickerFactory {
401
- constructor(props) {
402
- const { date, range, sourceDate, maxDate, minDate } = props;
403
- this.date = new Date(date.getTime());
404
- this.range = range;
405
- this.sourceDate = sourceDate;
406
- this.maxDate = maxDate;
407
- this.minDate = minDate;
408
- this.date.setDate(1);
409
- }
410
- static execute(props) {
411
- const factory = new DateRangePickerFactory(props);
412
- const firstWeek = factory.createFirstWeek();
413
- const rightWeeks = factory.createRightWeeks();
414
- return [firstWeek, ...rightWeeks];
415
- }
416
- createFirstWeek() {
417
- const dayStart = this.date.getDay();
418
- const days = [];
419
- let day = 1;
420
- for (let start = 0; start < dayStart; start++) {
421
- days.push(this.createDayRangeState());
422
- }
423
- for (let end = dayStart; end < 7; end++) {
424
- days.push(this.createDayRangeState(day));
425
- day++;
426
- }
427
- return { days };
428
- }
429
- createRightWeeks() {
430
- const rightWeeks = [];
431
- const dayStart = this.date.getDay();
432
- const dayCount = helpersDate.getDaysOfMonth(this.date.getFullYear(), this.date.getMonth());
433
- let days = [];
434
- let countDaysWeek = 1;
435
- let day = 8 - dayStart;
436
- do {
437
- days.push(this.createDayRangeState(day));
438
- day++;
439
- countDaysWeek++;
440
- if (countDaysWeek > 7) {
441
- rightWeeks.push({ days });
442
- days = [];
443
- countDaysWeek = 1;
444
- }
445
- } while (day <= dayCount);
446
- const daysPending = this.createDaysPending(days.length);
447
- rightWeeks.push({ days: [...days, ...daysPending] });
448
- return rightWeeks;
449
- }
450
- createDaysPending(daysWeek) {
451
- const daysPending = [];
452
- const length = 7 - daysWeek;
453
- for (let index = 0; index < length; index++) {
454
- daysPending.push(this.createDayRangeState());
455
- }
456
- return daysPending;
457
- }
458
- isSelectedSource(day) {
459
- return this.isSelectedForDate(this.sourceDate, day);
460
- }
461
- isSelectedEnd(day) {
462
- return (this.isSelectedForDate(this.range.minDate, day) ||
463
- this.isSelectedForDate(this.range.maxDate, day));
464
- }
465
- isSelectedForDate(date, day) {
466
- return (date.getFullYear() === this.date.getFullYear() &&
467
- date.getMonth() === this.date.getMonth() &&
468
- day === date.getDate());
469
- }
470
- isRangedFromDate(day) {
471
- return helpersDate.dateIsBetween(this.range.minDate, this.range.maxDate, helpersDate.assignDayInDate(this.date, day));
472
- }
473
- overflowDay(day) {
474
- return this.minOverflowDay(day) || this.maxOverflowDay(day);
475
- }
476
- minOverflowDay(day) {
477
- return this.minDate
478
- ? helpersDate.getDateWeight(helpersDate.assignDayInDate(this.date, day)) <
479
- helpersDate.getDateWeight(this.minDate)
480
- : false;
481
- }
482
- maxOverflowDay(day) {
483
- return this.maxDate
484
- ? helpersDate.getDateWeight(helpersDate.assignDayInDate(this.date, day)) >
485
- helpersDate.getDateWeight(this.maxDate)
486
- : false;
487
- }
488
- createDayRangeState(day) {
489
- return {
490
- value: day,
491
- disabled: this.overflowDay(day || 0),
492
- forbidden: !day,
493
- ranged: day ? this.isRangedFromDate(day) : false,
494
- end: day ? this.isSelectedEnd(day) : false,
495
- source: day ? this.isSelectedSource(day) : false
496
- };
497
- }
498
- }
499
- function rangeFormatTemplate(range) {
500
- const minFormat = helpersDate.dateFormatTemplate(range.minDate, DATE_RANGE_FORMAT);
501
- const maxFormat = helpersDate.dateFormatTemplate(range.maxDate, DATE_RANGE_FORMAT);
502
- return `${minFormat} - ${maxFormat}`;
503
- }
504
- function createRangePicker(props) {
505
- return DateRangePickerFactory.execute(props);
506
- }
507
803
 
508
804
  function RlsDayRangePicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, rlsTheme }) {
509
- const initialRange = formControl?.state || helpersDate.DateRange.now();
510
- const initialDate = helpersDate.normalizeMinTime(date || initialRange.minDate);
511
- const sourceDate = react.useRef(initialRange.minDate);
805
+ const currentRange = formControl?.state || helpersDate.DateRange.now();
806
+ const currentDate = helpersDate.normalizeMinTime(date || currentRange.minDate);
807
+ const sourceDate = react.useRef(currentRange.minDate);
512
808
  const [weeks, setWeeks] = react.useState([]);
513
- const [range, setRange] = react.useState(initialRange);
809
+ const [range, setRange] = react.useState(currentRange);
514
810
  react.useEffect(() => {
515
- setWeeks(createRangePicker({
516
- date: initialDate,
811
+ setWeeks(createDayRangePicker({
812
+ date: currentDate,
517
813
  range,
518
814
  sourceDate: sourceDate.current,
519
815
  minDate,
@@ -521,13 +817,13 @@ function RlsDayRangePicker({ date, disabled: disabledPicker, formControl, maxDat
521
817
  }));
522
818
  }, [range, date, minDate, maxDate]);
523
819
  function onChange(value) {
524
- const newDate = helpersDate.assignDayInDate(initialDate, value);
525
- const newRange = helpersDate.dateIsBefore(newDate, sourceDate.current)
526
- ? new helpersDate.DateRange(sourceDate.current, newDate)
527
- : new helpersDate.DateRange(newDate, sourceDate.current);
528
- sourceDate.current = newDate;
529
- setRange(newRange);
530
- formControl?.setState(newRange);
820
+ const date = helpersDate.assignDayInDate(currentDate, value);
821
+ const range = helpersDate.dateIsBefore(date, sourceDate.current)
822
+ ? new helpersDate.DateRange(sourceDate.current, date)
823
+ : new helpersDate.DateRange(date, sourceDate.current);
824
+ sourceDate.current = date;
825
+ setRange(range);
826
+ formControl?.setState(range);
531
827
  }
532
828
  return (jsxRuntime.jsxs("div", { className: "rls-day-range-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsx("div", { className: "rls-day-range-picker__title", children: helpersDate.dateFormatTemplate(sourceDate.current, DATE_RANGE_FORMAT) }), jsxRuntime.jsx("div", { className: "rls-day-range-picker__header", children: helpersDate.DAY_LABELS().map((title, index) => (jsxRuntime.jsx("label", { className: "rls-day-range-picker__label", children: title }, index))) }), jsxRuntime.jsx("div", { className: "rls-day-range-picker__component", children: weeks.map(({ days }, index) => (jsxRuntime.jsx("div", { className: "rls-day-range-picker__week", children: days.map(({ disabled, end, forbidden, source, ranged, value }, index) => (jsxRuntime.jsx("div", { className: renderClassStatus('rls-day-range-picker__day', {
533
829
  disabled: disabled || disabledPicker,
@@ -535,11 +831,7 @@ function RlsDayRangePicker({ date, disabled: disabledPicker, formControl, maxDat
535
831
  forbidden,
536
832
  ranged,
537
833
  source
538
- }), onClick: () => {
539
- if (value && !disabled) {
540
- onChange(value);
541
- }
542
- }, children: jsxRuntime.jsx("span", { className: "rls-day-range-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
834
+ }), onClick: value && !disabledPicker ? () => onChange(value) : undefined, children: jsxRuntime.jsx("span", { className: "rls-day-range-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
543
835
  }
544
836
 
545
837
  function RlsMoneyField({ children, decimals, disabled, formControl, placeholder, symbol, rlsTheme, value, onValue }) {
@@ -550,156 +842,93 @@ function RlsMoneyField({ children, decimals, disabled, formControl, placeholder,
550
842
  }, 'rls-money-field'), "rls-theme": rlsTheme, children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsx("div", { className: "rls-box-field__body", children: jsxRuntime.jsx(RlsInputMoney, { formControl: formControl, value: value, disabled: disabled, placeholder: placeholder, symbol: symbol, decimals: decimals, onValue: onValue }) }) }), formControl?.touched && formControl?.error && (jsxRuntime.jsx("div", { className: "rls-box-field__error", children: jsxRuntime.jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }));
551
843
  }
552
844
 
553
- const MONTH_MAX_VALUE = helpersDate.Month.December;
554
- const MONTH_MIN_VALUE = helpersDate.Month.January;
555
- class MonthPickerFactory {
556
- constructor(props) {
557
- const { date, value, maxDate, minDate } = props;
558
- this.value = value;
559
- this.date = new Date(date.getTime());
560
- this.maxDate = maxDate;
561
- this.minDate = minDate;
562
- }
563
- static execute(props) {
564
- const factory = new MonthPickerFactory(props);
565
- return [
566
- factory.createMonth(helpersDate.Month.January),
567
- factory.createMonth(helpersDate.Month.February),
568
- factory.createMonth(helpersDate.Month.March),
569
- factory.createMonth(helpersDate.Month.April),
570
- factory.createMonth(helpersDate.Month.May),
571
- factory.createMonth(helpersDate.Month.June),
572
- factory.createMonth(helpersDate.Month.July),
573
- factory.createMonth(helpersDate.Month.August),
574
- factory.createMonth(helpersDate.Month.September),
575
- factory.createMonth(helpersDate.Month.October),
576
- factory.createMonth(helpersDate.Month.November),
577
- factory.createMonth(helpersDate.Month.December)
578
- ];
579
- }
580
- createMonth(value) {
581
- return {
582
- value,
583
- label: helpersDate.MONTH_NAMES()[value],
584
- disabled: this.overflowMonth(value),
585
- selected: value === this.value
586
- };
587
- }
588
- get minYear() {
589
- return this.minDate?.getFullYear() || 0;
590
- }
591
- get maxYear() {
592
- return this.maxDate?.getFullYear() || 10000;
593
- }
594
- get minMonth() {
595
- return this.minDate ? this.minDate.getMonth() : MONTH_MIN_VALUE;
596
- }
597
- get maxMonth() {
598
- return this.maxDate ? this.maxDate.getMonth() : MONTH_MAX_VALUE;
599
- }
600
- overflowMonth(month) {
601
- return this.minOverflowMonth(month) || this.maxOverflowMonth(month);
602
- }
603
- minOverflowMonth(month) {
604
- return this.date.getFullYear() === this.minYear && month < this.minMonth;
605
- }
606
- maxOverflowMonth(month) {
607
- return this.date.getFullYear() === this.maxYear && month > this.maxMonth;
608
- }
609
- }
610
- function isMinLimitMonth(month, date, minDate) {
611
- if (typeof month === 'number' && date) {
612
- const minMonth = minDate ? minDate.getMonth() : MONTH_MIN_VALUE;
613
- const minYear = minDate ? minDate.getFullYear() : 0;
614
- return date.getFullYear() === minYear && month <= minMonth;
615
- }
616
- return false;
617
- }
618
- function isMaxLimitMonth(month, date, maxDate) {
619
- if (typeof month === 'number' && date) {
620
- const maxMonth = maxDate ? maxDate.getMonth() : MONTH_MAX_VALUE;
621
- const maxYear = maxDate ? maxDate.getFullYear() : 10000;
622
- return date.getFullYear() === maxYear && month >= maxMonth;
623
- }
624
- return false;
625
- }
626
- function createMonthPicker(props) {
627
- return MonthPickerFactory.execute(props);
628
- }
629
-
630
- function RlsMonthPicker({ formControl, date, disabled: disabledPicker, maxDate, minDate, rlsTheme, onValue }) {
631
- const initialDate = date || new Date();
632
- const initialMonth = formControl?.state || initialDate.getMonth();
845
+ function RlsMonthPicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, onValue, rlsTheme, year }) {
846
+ const currentDate = date || new Date();
633
847
  const [months, setMonths] = react.useState([]);
634
- const [value, setValue] = react.useState(initialMonth);
848
+ const [value, setValue] = react.useState(formControl?.state || currentDate.getMonth());
849
+ react.useEffect(() => {
850
+ const props = createPickerProps(); // MonthPickerProps
851
+ const month = checkMonthPicker(props);
852
+ month ? setMonthValue(month) : setMonths(createMonthPicker(props));
853
+ }, [date, year, value, minDate, maxDate]);
635
854
  react.useEffect(() => {
636
- setMonths(createMonthPicker({
637
- date: initialDate,
638
- value: formControl?.state || value,
855
+ const month = checkMonthPicker(createPickerProps());
856
+ helpersAdvanced.itIsDefined(month)
857
+ ? formControl?.setState(month)
858
+ : setValue(formControl?.state || currentDate.getMonth());
859
+ }, [formControl?.state]);
860
+ function createPickerProps() {
861
+ return {
862
+ date: currentDate,
863
+ month: helpersAdvanced.itIsDefined(formControl?.state) ? formControl?.state : value,
864
+ year: year || currentDate.getFullYear(),
639
865
  minDate,
640
866
  maxDate
641
- }));
642
- }, [value, date, minDate, maxDate]);
867
+ };
868
+ }
869
+ function setMonthValue(value) {
870
+ formControl ? formControl.setState(value) : setValue(value);
871
+ }
643
872
  function onChange(value) {
644
- formControl?.setState(value);
645
- setValue(value);
873
+ setMonthValue(value);
646
874
  if (onValue) {
647
875
  onValue(value);
648
876
  }
649
877
  }
650
- return (jsxRuntime.jsx("div", { className: "rls-month-picker", "rls-theme": rlsTheme, children: months.map(({ label, value, disabled, selected }, index) => (jsxRuntime.jsx("div", { className: renderClassStatus('rls-month-picker__component', {
651
- disabled: disabled || disabledPicker || false,
878
+ return (jsxRuntime.jsx("div", { className: "rls-month-picker", "rls-theme": rlsTheme, children: months.map(({ label, value, disabled, focused, selected }, index) => (jsxRuntime.jsx("div", { className: renderClassStatus('rls-month-picker__component', {
879
+ disabled: disabled || disabledPicker,
880
+ focused,
652
881
  selected
653
- }), onClick: () => {
654
- if (!disabled) {
655
- onChange(value);
656
- }
657
- }, children: jsxRuntime.jsx("span", { className: "rls-month-picker__span", children: label }) }, index))) }));
882
+ }), onClick: !(disabled || disabledPicker) ? () => onChange(value) : undefined, children: jsxRuntime.jsx("span", { className: "rls-month-picker__span", children: label }) }, index))) }));
658
883
  }
659
884
 
660
- function RlsMonthTitlePicker({ date, disabled, monthControl, maxDate, minDate, onClick, type, yearControl }) {
661
- const { state: month } = monthControl;
662
- const { state: year } = yearControl;
663
- const monthName = helpersDate.MONTH_NAMES()[month || 0];
885
+ function RlsMonthTitlePicker({ monthControl, type, yearControl, date, disabled, maxDate, minDate, onClick }) {
886
+ const { limitNext, limitPrevious } = monthLimitTemplate({
887
+ date,
888
+ maxDate,
889
+ minDate,
890
+ month: monthControl.state
891
+ });
892
+ const monthName = helpersDate.MONTH_NAMES()[monthControl.state || 0];
664
893
  function onPreviousMonth() {
665
- if (typeof month === 'number' && typeof year === 'number') {
666
- if (month > MONTH_MIN_VALUE) {
667
- monthControl.setState(month - 1);
894
+ if (helpersAdvanced.itIsDefined(monthControl.state) && helpersAdvanced.itIsDefined(yearControl.state)) {
895
+ if (monthControl.state > helpersDate.Month.January) {
896
+ monthControl.setState(monthControl.state - 1);
668
897
  }
669
898
  else {
670
- monthControl.setState(MONTH_MAX_VALUE);
671
- yearControl.setState(year - 1);
899
+ monthControl.setState(helpersDate.Month.December);
900
+ yearControl.setState(yearControl.state - 1);
672
901
  }
673
902
  }
674
903
  }
675
904
  function onPreviousYear() {
676
- if (typeof year === 'number') {
677
- yearControl.setState(year - 1);
905
+ if (helpersAdvanced.itIsDefined(yearControl.state)) {
906
+ yearControl.setState(yearControl.state - 1);
678
907
  }
679
908
  }
680
909
  function onPrevious() {
681
910
  type === 'month' ? onPreviousMonth() : onPreviousYear();
682
911
  }
683
912
  function onNextMonth() {
684
- if (typeof month === 'number' && typeof year === 'number') {
685
- if (month < MONTH_MAX_VALUE) {
686
- monthControl.setState(month + 1);
913
+ if (helpersAdvanced.itIsDefined(monthControl.state) && helpersAdvanced.itIsDefined(yearControl.state)) {
914
+ if (monthControl.state < helpersDate.Month.December) {
915
+ monthControl.setState(monthControl.state + 1);
687
916
  }
688
917
  else {
689
- monthControl.setState(MONTH_MIN_VALUE);
690
- yearControl.setState(year + 1);
918
+ monthControl.setState(helpersDate.Month.January);
919
+ yearControl.setState(yearControl.state + 1);
691
920
  }
692
921
  }
693
922
  }
694
923
  function onNextYear() {
695
- if (typeof year === 'number') {
696
- yearControl.setState(year + 1);
924
+ if (helpersAdvanced.itIsDefined(yearControl.state)) {
925
+ yearControl.setState(yearControl.state + 1);
697
926
  }
698
927
  }
699
928
  function onNext() {
700
929
  type === 'month' ? onNextMonth() : onNextYear();
701
930
  }
702
- return (jsxRuntime.jsxs("div", { className: "rls-month-title-picker", children: [jsxRuntime.jsx(RlsButtonAction, { icon: "arrow-ios-left", onClick: onPrevious, disabled: isMinLimitMonth(month, date, minDate) || disabled }), jsxRuntime.jsx("span", { onClick: onClick, children: monthName }), jsxRuntime.jsx(RlsButtonAction, { icon: "arrow-ios-right", onClick: onNext, disabled: isMaxLimitMonth(month, date, maxDate) || disabled })] }));
931
+ return (jsxRuntime.jsxs("div", { className: "rls-month-title-picker", children: [jsxRuntime.jsx(RlsButtonAction, { icon: "arrow-ios-left", onClick: onPrevious, disabled: limitPrevious || disabled }), jsxRuntime.jsx("span", { onClick: onClick, children: monthName }), jsxRuntime.jsx(RlsButtonAction, { icon: "arrow-ios-right", onClick: onNext, disabled: limitNext || disabled })] }));
703
932
  }
704
933
 
705
934
  function RlsNumberField({ children, disabled, formControl, placeholder, rlsTheme, value, onValue }) {
@@ -979,108 +1208,36 @@ function RlsToolbar({ actions, children, subtitle }) {
979
1208
  return (jsxRuntime.jsxs("div", { className: "rls-toolbar", children: [jsxRuntime.jsxs("div", { className: "rls-toolbar__description", children: [children && jsxRuntime.jsx("label", { className: "rls-toolbar__title", children: children }), subtitle && (jsxRuntime.jsx("label", { className: "rls-toolbar__subtitle smalltext-semibold", children: subtitle }))] }), actions && (jsxRuntime.jsx("div", { className: "rls-toolbar__actions", children: actions.map((action, index) => (jsxRuntime.jsx("div", { children: action }, index))) }))] }));
980
1209
  }
981
1210
 
982
- const COUNT_YEAR_RANGE = 4;
983
- class YearPickerFactory {
984
- constructor(props) {
985
- const { value, maxDate, minDate } = props;
986
- this.value = value;
987
- this.maxDate = maxDate;
988
- this.minDate = minDate;
989
- }
990
- static execute(props) {
991
- const factory = new YearPickerFactory(props);
992
- let year = props.year;
993
- if (factory.minOverflowYear(year)) {
994
- year = factory.minYear;
995
- }
996
- else if (factory.maxOverflowYear(year)) {
997
- year = factory.maxYear;
998
- }
999
- const years = factory.createYears(year);
1000
- return {
1001
- hasNext: factory.hasNext,
1002
- hasPrevious: factory.hasPrevious,
1003
- maxRange: factory.maxYearRange,
1004
- minRange: factory.minYearRange,
1005
- years
1006
- };
1007
- }
1008
- createYears(year) {
1009
- const prevYears = [];
1010
- const nextYears = [];
1011
- this.minYearRange = year;
1012
- this.maxYearRange = year;
1013
- for (let index = 0; index < COUNT_YEAR_RANGE; index++) {
1014
- const yearPrev = year - COUNT_YEAR_RANGE + index;
1015
- const yearNext = year + index + 1;
1016
- const valuePrev = yearPrev >= this.minYear ? yearPrev : undefined;
1017
- const valueNext = yearNext <= this.maxYear ? yearNext : undefined;
1018
- const prevState = this.createYear(valuePrev);
1019
- const nextState = this.createYear(valueNext);
1020
- prevYears.push(prevState);
1021
- nextYears.push(nextState);
1022
- this.recalculateRange(prevState, nextState);
1023
- }
1024
- const yearCenter = this.createYear(year);
1025
- return [...prevYears, yearCenter, ...nextYears];
1026
- }
1027
- minOverflowYear(year) {
1028
- return year < this.minYear;
1029
- }
1030
- maxOverflowYear(year) {
1031
- return year > this.maxYear;
1032
- }
1033
- get minYear() {
1034
- return this.minDate?.getFullYear() || 0;
1035
- }
1036
- get maxYear() {
1037
- return this.maxDate?.getFullYear() || 10000;
1038
- }
1039
- get hasPrevious() {
1040
- return this.minYear < this.minYearRange;
1041
- }
1042
- get hasNext() {
1043
- return this.maxYear > this.maxYearRange;
1044
- }
1045
- createYear(value) {
1046
- return {
1047
- value,
1048
- disabled: !value,
1049
- selected: value === this.value
1050
- };
1051
- }
1052
- recalculateRange(prev, next) {
1053
- if (!!prev.value && this.minYearRange > prev.value) {
1054
- this.minYearRange = prev.value;
1055
- }
1056
- if (!!next.value && this.maxYearRange < next.value) {
1057
- this.maxYearRange = next.value;
1058
- }
1059
- }
1060
- }
1061
- function createYearPicker(props) {
1062
- return YearPickerFactory.execute(props);
1063
- }
1064
-
1065
- function RlsYearPicker({ formControl, date, disabled: disabledPicker, maxDate, minDate, rlsTheme, onValue }) {
1066
- const initialDate = date || new Date();
1067
- const initialYear = formControl?.state || initialDate.getFullYear();
1068
- const [value, setValue] = react.useState(initialYear);
1069
- const [year, setYear] = react.useState(initialYear);
1070
- const [template, setTemplate] = react.useState(createYearPicker({
1071
- value: formControl?.state || value,
1072
- year: initialYear,
1073
- minDate,
1074
- maxDate
1075
- }));
1211
+ function RlsYearPicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, onValue, rlsTheme }) {
1212
+ const currentDate = date || new Date();
1213
+ const [value, setValue] = react.useState(formControl?.state || currentDate.getFullYear());
1214
+ const [year, setYear] = react.useState(formControl?.state || currentDate.getFullYear());
1215
+ const [template, setTemplate] = react.useState(createYearPicker(createPickerProps()));
1076
1216
  react.useEffect(() => {
1077
- setTemplate(createYearPicker({
1078
- value: formControl?.state || value,
1217
+ const props = createPickerProps(); // YearPickerProps
1218
+ const year = checkYearPicker(props);
1219
+ year
1220
+ ? setYearValue(year)
1221
+ : setTemplate(createYearPicker(createPickerProps()));
1222
+ }, [date, year, value, minDate, maxDate]);
1223
+ react.useEffect(() => {
1224
+ const year = checkYearPicker(createPickerProps());
1225
+ helpersAdvanced.itIsDefined(year)
1226
+ ? formControl?.setState(year)
1227
+ : setValue(formControl?.state || currentDate.getFullYear());
1228
+ }, [formControl?.state]);
1229
+ function createPickerProps() {
1230
+ return {
1231
+ date: currentDate,
1079
1232
  year,
1080
1233
  minDate,
1081
1234
  maxDate
1082
- }));
1083
- }, [value, year, minDate, maxDate]);
1235
+ };
1236
+ }
1237
+ function setYearValue(value) {
1238
+ formControl ? formControl.setState(value) : setValue(value);
1239
+ setYear(value);
1240
+ }
1084
1241
  function onClickPrev() {
1085
1242
  setYear(year - 8);
1086
1243
  }
@@ -1088,21 +1245,16 @@ function RlsYearPicker({ formControl, date, disabled: disabledPicker, maxDate, m
1088
1245
  setYear(year + 8);
1089
1246
  }
1090
1247
  function onChange(value) {
1091
- formControl?.setState(value);
1092
- setYear(value);
1093
- setValue(value);
1248
+ setYearValue(value);
1094
1249
  if (onValue) {
1095
1250
  onValue(value);
1096
1251
  }
1097
1252
  }
1098
- return (jsxRuntime.jsxs("div", { className: "rls-year-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-year-picker__header", children: [jsxRuntime.jsx("div", { className: "rls-year-picker__action rls-year-picker__action--prev", children: jsxRuntime.jsx("button", { disabled: !template.hasPrevious || disabledPicker, onClick: onClickPrev, children: jsxRuntime.jsx(RlsIcon, { value: "arrow-ios-left" }) }) }), jsxRuntime.jsxs("label", { className: "title-bold", children: [template.minRange, " - ", template.maxRange] }), jsxRuntime.jsx("div", { className: "rls-year-picker__action rls-year-picker__action--next", children: jsxRuntime.jsx("button", { disabled: !template.hasNext || disabledPicker, onClick: onClickNext, children: jsxRuntime.jsx(RlsIcon, { value: "arrow-ios-right" }) }) })] }), jsxRuntime.jsx("div", { className: "rls-year-picker__component", children: template.years.map(({ value, disabled, selected }, index) => (jsxRuntime.jsx("div", { className: renderClassStatus('rls-year-picker__year', {
1253
+ return (jsxRuntime.jsxs("div", { className: "rls-year-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-year-picker__header", children: [jsxRuntime.jsx("div", { className: "rls-year-picker__action rls-year-picker__action--prev", children: jsxRuntime.jsx(RlsButtonAction, { icon: "arrow-ios-left", onClick: onClickPrev, disabled: !template.canPrevious || disabledPicker }) }), jsxRuntime.jsxs("label", { className: "rls-title-bold", children: [template.minRange, " - ", template.maxRange] }), jsxRuntime.jsx("div", { className: "rls-year-picker__action rls-year-picker__action--next", children: jsxRuntime.jsx(RlsButtonAction, { icon: "arrow-ios-right", onClick: onClickNext, disabled: !template.canNext || disabledPicker }) })] }), jsxRuntime.jsx("div", { className: "rls-year-picker__component", children: template.years.map(({ value, disabled, focused, selected }, index) => (jsxRuntime.jsx("div", { className: renderClassStatus('rls-year-picker__year', {
1099
1254
  disabled: disabled || disabledPicker,
1255
+ focused,
1100
1256
  selected
1101
- }), onClick: () => {
1102
- if (value && !disabled) {
1103
- onChange(value);
1104
- }
1105
- }, children: jsxRuntime.jsx("span", { className: "rls-year-picker__year__span body1-medium", children: value || '????' }) }, index))) })] }));
1257
+ }), onClick: value && !disabledPicker ? () => onChange(value) : undefined, children: jsxRuntime.jsx("span", { className: "rls-year-picker__year__span rls-body1-medium", children: value || '????' }) }, index))) })] }));
1106
1258
  }
1107
1259
 
1108
1260
  const reactI18n = i18n.i18n({
@@ -1144,23 +1296,7 @@ function useDatatable() {
1144
1296
  return { bodyRef, scrolleable };
1145
1297
  }
1146
1298
 
1147
- class ListCollection {
1148
- constructor(value) {
1149
- this.value = value;
1150
- }
1151
- find(element) {
1152
- return this.value.find((current) => current.compareTo(element));
1153
- }
1154
- }
1155
-
1156
- const classElement = '.rls-list-field__element';
1157
- const MAX_POSITION_VISIBLE = 4;
1158
- const LIST_SIZE_REM = 16;
1159
- const ELEMENT_SIZE_REM = 4;
1160
- const BASE_SIZE_PX = 16;
1161
- const ELEMENT_SIZE_PX = BASE_SIZE_PX * ELEMENT_SIZE_REM;
1162
- const MAZ_LIST_SIZE_PX = BASE_SIZE_PX * LIST_SIZE_REM;
1163
- function useListControl({ suggestions, formControl, higher: withHigher = false }) {
1299
+ function useListControl({ suggestions, formControl }) {
1164
1300
  const boxContentRef = react.useRef(null);
1165
1301
  const listRef = react.useRef(null);
1166
1302
  const inputRef = react.useRef(null);
@@ -1170,11 +1306,10 @@ function useListControl({ suggestions, formControl, higher: withHigher = false }
1170
1306
  const [visible, setVisible] = react.useState(false);
1171
1307
  const [higher, setHigher] = react.useState(false);
1172
1308
  const [focused, setFocused] = react.useState(false);
1173
- const [positionElement, setPositionElement] = react.useState(0);
1174
- const [listElements, setListElements] = react.useState(undefined);
1309
+ const position = react.useRef(0);
1175
1310
  react.useEffect(() => {
1176
- function onCloseSuggestions(event) {
1177
- if (!boxContentRef?.current?.contains(event.target)) {
1311
+ function onCloseSuggestions({ target }) {
1312
+ if (!boxContentRef?.current?.contains(target)) {
1178
1313
  setVisible(false);
1179
1314
  }
1180
1315
  }
@@ -1187,95 +1322,32 @@ function useListControl({ suggestions, formControl, higher: withHigher = false }
1187
1322
  if (visible && !opened) {
1188
1323
  setOpened(true);
1189
1324
  }
1190
- if (!visible && opened && formControl && !formControl.touched) {
1325
+ if (!visible && opened && !!formControl?.touched) {
1191
1326
  formControl.touch();
1192
1327
  }
1193
- setLocationList();
1328
+ setHigher(!locationListIsBottom(boxContentRef.current, listRef.current));
1194
1329
  }, [visible]);
1195
1330
  react.useEffect(() => {
1196
1331
  setCollection(new ListCollection(suggestions));
1197
1332
  }, [suggestions]);
1198
- function setLocationList() {
1199
- if (boxContentRef?.current) {
1200
- const { top, height } = boxContentRef.current.getBoundingClientRect();
1201
- const overflow = BASE_SIZE_PX / 2;
1202
- const positionEnd = top + height + MAZ_LIST_SIZE_PX + overflow;
1203
- setHigher(positionEnd > window.innerHeight);
1204
- }
1205
- }
1206
1333
  function navigationInput(event) {
1207
- switch (event.code) {
1208
- case 'ArrowUp':
1209
- if (visible && higher) {
1210
- navigationInputUp();
1211
- }
1212
- break;
1213
- case 'ArrowDown':
1214
- if (visible && (withHigher || !higher)) {
1215
- navigationInputDown();
1216
- }
1217
- break;
1334
+ if (visible) {
1335
+ const newPosition = listNavigationInput({
1336
+ contentElement: boxContentRef.current,
1337
+ event: event,
1338
+ listElement: listRef.current
1339
+ });
1340
+ position.current = helpersAdvanced.itIsDefined(newPosition) ? newPosition : 0;
1218
1341
  }
1219
1342
  }
1220
1343
  function navigationElement(event) {
1221
- switch (event.code) {
1222
- case 'ArrowUp':
1223
- navigationElementUp();
1224
- break;
1225
- case 'ArrowDown':
1226
- navigationElementDown();
1227
- break;
1228
- }
1229
- }
1230
- function navigationInputUp() {
1231
- const elements = listRef?.current?.querySelectorAll(classElement);
1232
- if (elements?.length) {
1233
- const newPosition = elements.length - 1;
1234
- setListElements(elements);
1235
- setPositionElement(newPosition);
1236
- elements.item(newPosition).focus();
1237
- if (positionElement > MAX_POSITION_VISIBLE) {
1238
- const elementPosition = elements.length - MAX_POSITION_VISIBLE;
1239
- setTimeout(() => {
1240
- listRef?.current?.scroll({
1241
- top: ELEMENT_SIZE_PX * elementPosition,
1242
- behavior: 'smooth'
1243
- });
1244
- }, 100);
1245
- }
1246
- }
1247
- }
1248
- function navigationInputDown() {
1249
- const elements = listRef?.current?.querySelectorAll(classElement);
1250
- if (elements?.length) {
1251
- setListElements(elements);
1252
- setPositionElement(0);
1253
- elements.item(0).focus();
1254
- setTimeout(() => {
1255
- listRef?.current?.scroll({ top: 0, behavior: 'smooth' });
1256
- }, 100);
1257
- }
1258
- }
1259
- function navigationElementUp() {
1260
- if (positionElement > 0) {
1261
- const newPosition = positionElement - 1;
1262
- setPositionElement(newPosition);
1263
- listElements?.item(newPosition).focus();
1264
- }
1265
- else if (withHigher || !higher) {
1266
- inputRef?.current?.focus();
1267
- }
1268
- }
1269
- function navigationElementDown() {
1270
- const newPosition = positionElement + 1;
1271
- const length = listElements?.length || 0;
1272
- if (newPosition < length) {
1273
- setPositionElement(newPosition);
1274
- listElements?.item(newPosition).focus();
1275
- }
1276
- else if (higher && !withHigher) {
1277
- inputRef?.current?.focus();
1278
- }
1344
+ position.current = listNavigationElement({
1345
+ contentElement: boxContentRef.current,
1346
+ event: event,
1347
+ inputElement: inputRef.current,
1348
+ listElement: listRef.current,
1349
+ position: position.current
1350
+ });
1279
1351
  }
1280
1352
  return {
1281
1353
  boxContentRef,
@@ -1304,39 +1376,31 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1304
1376
  coincidences: [],
1305
1377
  previous: null
1306
1378
  });
1307
- const listControl = useListControl({
1308
- suggestions,
1309
- formControl,
1310
- higher: true
1311
- });
1379
+ const listControl = useListControl({ suggestions, formControl });
1312
1380
  const { collection, inputRef, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1313
- const [changeInternal, setChangeInternal] = react.useState(false);
1381
+ const changeInternal = react.useRef(false);
1314
1382
  react.useEffect(() => filterSuggestions(pattern, true), [suggestions]);
1315
1383
  react.useEffect(() => filterSuggestions(pattern), [pattern]);
1316
1384
  react.useEffect(() => {
1317
- changeInternal ? setChangeInternal(false) : resetState(formControl?.state);
1385
+ if (changeInternal.current) {
1386
+ changeInternal.current = false;
1387
+ }
1388
+ else {
1389
+ resetState(formControl?.state);
1390
+ }
1318
1391
  }, [formControl?.state]);
1319
1392
  react.useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1320
1393
  function setFormState(value) {
1321
- setChangeInternal(true);
1322
- formControl?.setState(value);
1394
+ if (formControl) {
1395
+ changeInternal.current = true;
1396
+ formControl.setState(value);
1397
+ }
1323
1398
  }
1324
1399
  function resetCollection(collection, state) {
1325
- if (state) {
1326
- const element = collection.find(state);
1327
- if (element) {
1328
- setValue(element.description);
1329
- }
1330
- else {
1331
- setValue('');
1332
- }
1333
- }
1334
- else {
1335
- setValue('');
1336
- }
1400
+ setValue(state ? collection.find(state)?.description || '' : '');
1337
1401
  }
1338
1402
  function resetState(state) {
1339
- setValue(state ? collection.find(state)?.description || '' : '');
1403
+ resetCollection(collection, state);
1340
1404
  }
1341
1405
  function onClickControl() {
1342
1406
  if (!disabled) {
@@ -1353,8 +1417,6 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1353
1417
  function onKeydownInput(event) {
1354
1418
  switch (event.code) {
1355
1419
  case 'Escape':
1356
- setVisible(false);
1357
- break;
1358
1420
  case 'Tab':
1359
1421
  setVisible(false);
1360
1422
  break;
@@ -1366,9 +1428,7 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1366
1428
  function onClickAction() {
1367
1429
  setVisible(false);
1368
1430
  setValue('');
1369
- if (formControl) {
1370
- setFormState(undefined);
1371
- }
1431
+ setFormState(undefined);
1372
1432
  if (onValue) {
1373
1433
  onValue(undefined);
1374
1434
  }
@@ -1383,14 +1443,7 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1383
1443
  }
1384
1444
  function onKeydownElement(element) {
1385
1445
  return (event) => {
1386
- switch (event.code) {
1387
- case 'Enter':
1388
- onChange(element);
1389
- break;
1390
- default:
1391
- navigationElement(event);
1392
- break;
1393
- }
1446
+ event.code === 'Enter' ? onChange(element) : navigationElement(event);
1394
1447
  };
1395
1448
  }
1396
1449
  function onChange({ description, value }) {
@@ -1399,9 +1452,7 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1399
1452
  onSelect(value);
1400
1453
  }
1401
1454
  else {
1402
- if (formControl) {
1403
- setFormState(value);
1404
- }
1455
+ setFormState(value);
1405
1456
  setValue(description);
1406
1457
  }
1407
1458
  if (onValue) {
@@ -1409,47 +1460,14 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1409
1460
  }
1410
1461
  }
1411
1462
  function filterSuggestions(pattern, reboot = false) {
1412
- if (pattern) {
1413
- const store = reboot ? createStoreEmpty() : searchForPattern(pattern);
1414
- const elements = store?.coincidences || suggestions;
1415
- const coincidences = elements.filter((element) => element.hasCoincidence(pattern));
1416
- setCoincidences(coincidences.slice(0, MAX_ELEMENTS));
1417
- setStore({
1418
- coincidences,
1419
- pattern,
1420
- previous: store
1421
- });
1422
- }
1423
- else {
1424
- setCoincidences(suggestions.slice(0, MAX_ELEMENTS));
1425
- rebootStore();
1426
- }
1427
- }
1428
- function searchForPattern(value) {
1429
- if (!store.pattern) {
1430
- return null;
1431
- }
1432
- let newStore = store;
1433
- let search = false;
1434
- while (!search && newStore) {
1435
- search = helpersString.hasPattern(value, newStore.pattern, true);
1436
- if (!search) {
1437
- newStore = newStore.previous;
1438
- }
1439
- }
1440
- return newStore || rebootStore();
1441
- }
1442
- function rebootStore() {
1443
- const store = createStoreEmpty();
1444
- setStore(store);
1445
- return store;
1446
- }
1447
- function createStoreEmpty() {
1448
- return {
1449
- coincidences: undefined,
1450
- pattern: '',
1451
- previous: null
1452
- };
1463
+ const result = createStoreAutocomplete({
1464
+ pattern,
1465
+ suggestions,
1466
+ reboot,
1467
+ store
1468
+ });
1469
+ setCoincidences(result.collection.slice(0, MAX_ELEMENTS));
1470
+ setStore(result.store);
1453
1471
  }
1454
1472
  return {
1455
1473
  coincidences,
@@ -1487,7 +1505,7 @@ function RlsAutocompleteFieldTemplate({ suggestions, children, disabled, formCon
1487
1505
  setPattern(value);
1488
1506
  }, disabled: disabled || searching, onFocus: onFocusInput, onBlur: onBlurInput, onKeyDown: onKeydownInput }), onSearch && (jsxRuntime.jsx("button", { disabled: disabled || searching, onClick: () => {
1489
1507
  onSearch(pattern);
1490
- }, children: jsxRuntime.jsx(RlsIcon, { value: "search" }) }))] }), searching && jsxRuntime.jsx(RlsProgressBar, { indeterminate: true }), coincidences.map((element, index) => (jsxRuntime.jsx("li", { className: "rls-list-field__element", tabIndex: -1, onClick: onClickElement(element), onKeyDown: onKeydownElement(element), children: render(element) }, index))), !coincidences.length && (jsxRuntime.jsx("li", { className: "rls-list-field__empty", children: jsxRuntime.jsxs("div", { className: "rls-list-field__empty__description", children: [jsxRuntime.jsx("label", { className: "label-bold truncate", children: reactI18n('listEmptyTitle') }), jsxRuntime.jsx("p", { className: "caption-regular", children: reactI18n('listEmptyDescription') })] }) }))] }) }), jsxRuntime.jsx("div", { className: "rls-list-field__backdrop", onClick: onClickBackdrop })] })] }));
1508
+ }, children: jsxRuntime.jsx(RlsIcon, { value: "search" }) }))] }), searching && jsxRuntime.jsx(RlsProgressBar, { indeterminate: true }), coincidences.map((element, index) => (jsxRuntime.jsx("li", { className: "rls-list-field__element", tabIndex: -1, onClick: onClickElement(element), onKeyDown: onKeydownElement(element), children: render(element) }, index))), !coincidences.length && (jsxRuntime.jsx("li", { className: "rls-list-field__empty", children: jsxRuntime.jsxs("div", { className: "rls-list-field__empty__description", children: [jsxRuntime.jsx("label", { className: "rls-label-bold truncate", children: reactI18n('listEmptyTitle') }), jsxRuntime.jsx("p", { className: "rls-caption-regular", children: reactI18n('listEmptyDescription') })] }) }))] }) }), jsxRuntime.jsx("div", { className: "rls-list-field__backdrop", onClick: onClickBackdrop })] })] }));
1491
1509
  }
1492
1510
  function RlsAutocompleteField(props) {
1493
1511
  return (jsxRuntime.jsx(RlsAutocompleteFieldTemplate, { ...props, render: (element) => (jsxRuntime.jsx(RlsBallot, { subtitle: element.subtitle, img: element.img, initials: element.initials, children: element.title })) }));
@@ -1578,12 +1596,11 @@ function RlsDatatable({ children, datatable, footer, header, rlsTheme, summary }
1578
1596
  }), "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("table", { children: [header && jsxRuntime.jsx("thead", { className: "rls-datatable__thead", children: header }), jsxRuntime.jsx("tbody", { ref: datatable?.bodyRef, className: "rls-datatable__tbody", children: children })] }), summary && jsxRuntime.jsx("div", { className: "rls-datatable__tsummary", children: summary }), footer && jsxRuntime.jsx("div", { className: "rls-datatable__tfooter", children: footer })] }));
1579
1597
  }
1580
1598
 
1581
- var PickerListenerType;
1582
- (function (PickerListenerType) {
1583
- PickerListenerType["Select"] = "PickerSelect";
1584
- PickerListenerType["Now"] = "PickerNow";
1585
- PickerListenerType["Cancel"] = "PickerCancel";
1586
- })(PickerListenerType || (PickerListenerType = {}));
1599
+ function rangeFormatTemplate({ maxDate, minDate }) {
1600
+ const minFormat = helpersDate.dateFormatTemplate(minDate, DATE_RANGE_FORMAT);
1601
+ const maxFormat = helpersDate.dateFormatTemplate(maxDate, DATE_RANGE_FORMAT);
1602
+ return `${minFormat} - ${maxFormat}`;
1603
+ }
1587
1604
 
1588
1605
  const controlIsValid = (props) => {
1589
1606
  const { state, validators } = props;
@@ -1681,71 +1698,47 @@ function useReactControl(controlProps, controlValidators) {
1681
1698
  return useControl(controlProps, controlValidators);
1682
1699
  }
1683
1700
 
1684
- function dateIsRange(date, min, max) {
1685
- return min && helpersDate.dateIsBefore(min, date)
1686
- ? min
1687
- : max && helpersDate.dateIsAfter(max, date)
1688
- ? max
1689
- : date;
1690
- }
1691
-
1692
1701
  const FORMAT_DESCRIPTION = '{dw}, {mx} {dd} de {aa}';
1693
- const VISIBILITY_STATE$1 = {
1694
- month: false,
1695
- day: false,
1696
- year: false
1697
- };
1698
- const VISIBILITY$1 = {
1699
- DAY: {
1700
- ...VISIBILITY_STATE$1,
1701
- day: true
1702
- },
1703
- MONTH: {
1704
- ...VISIBILITY_STATE$1,
1705
- month: true
1706
- },
1707
- YEAR: {
1708
- ...VISIBILITY_STATE$1,
1709
- year: true
1710
- }
1711
- };
1712
- function RlsDatePicker({ automatic, date, formControl, disabled, maxDate, minDate, rlsTheme, onListener }) {
1713
- const dateInitial = formControl?.state || date || new Date();
1702
+ function RlsDatePicker({ automatic, date, disabled, formControl, maxDate, minDate, onListener, rlsTheme }) {
1703
+ const today = new Date(); // Initial current date in component
1704
+ const dateInitial = formControl?.state || date || today;
1714
1705
  const yearControl = useReactControl(dateInitial.getFullYear());
1715
1706
  const dayControl = useReactControl(dateInitial.getDate());
1716
1707
  const monthControl = useReactControl(dateInitial.getMonth());
1717
1708
  const [value, setValue] = react.useState(dateInitial);
1718
- const [{ day, month, year }, setVisibility] = react.useState(VISIBILITY$1.DAY);
1719
- const title = helpersDate.dateFormatTemplate(value, FORMAT_DESCRIPTION);
1709
+ const [visibility, setVisibility] = react.useState('DAY');
1720
1710
  react.useEffect(() => {
1721
- setValue((prevValue) => {
1722
- return typeof yearControl.state === 'number'
1723
- ? dateIsRange(helpersDate.assignYearInDate(prevValue, yearControl.state), minDate, maxDate)
1724
- : prevValue;
1711
+ const dateCheck = checkDateRange({
1712
+ date: formControl?.state || date || today,
1713
+ minDate,
1714
+ maxDate
1725
1715
  });
1716
+ setValue(dateCheck);
1717
+ formControl?.setState(dateCheck);
1718
+ }, []);
1719
+ react.useEffect(() => {
1720
+ setValue((prevValue) => helpersAdvanced.itIsDefined(yearControl.state)
1721
+ ? helpersDate.assignYearInDate(prevValue, yearControl.state)
1722
+ : prevValue);
1726
1723
  }, [yearControl.state]);
1727
1724
  react.useEffect(() => {
1728
- setValue((prevValue) => {
1729
- return typeof monthControl.state === 'number'
1730
- ? dateIsRange(helpersDate.assignMonthInDate(prevValue, monthControl.state), minDate, maxDate)
1731
- : prevValue;
1732
- });
1725
+ setValue((prevValue) => helpersAdvanced.itIsDefined(monthControl.state)
1726
+ ? helpersDate.assignMonthInDate(prevValue, monthControl.state)
1727
+ : prevValue);
1733
1728
  }, [monthControl.state]);
1734
1729
  react.useEffect(() => {
1735
- setValue((prevValue) => {
1736
- return typeof dayControl.state === 'number'
1737
- ? dateIsRange(helpersDate.assignDayInDate(prevValue, dayControl.state), minDate, maxDate)
1738
- : prevValue;
1739
- });
1730
+ setValue((prevValue) => helpersAdvanced.itIsDefined(dayControl.state)
1731
+ ? helpersDate.assignDayInDate(prevValue, dayControl.state)
1732
+ : prevValue);
1740
1733
  }, [dayControl.state]);
1741
1734
  function onVisibilityDay() {
1742
- setVisibility(VISIBILITY$1.DAY);
1735
+ setVisibility('DAY');
1743
1736
  }
1744
1737
  function onVisibilityMonth() {
1745
- setVisibility(VISIBILITY$1.MONTH);
1738
+ setVisibility('MONTH');
1746
1739
  }
1747
1740
  function onVisibilityYear() {
1748
- setVisibility(VISIBILITY$1.YEAR);
1741
+ setVisibility('YEAR');
1749
1742
  }
1750
1743
  function onCancel() {
1751
1744
  if (onListener) {
@@ -1753,14 +1746,12 @@ function RlsDatePicker({ automatic, date, formControl, disabled, maxDate, minDat
1753
1746
  }
1754
1747
  }
1755
1748
  function onToday() {
1756
- const value = new Date(); // Today date
1757
- formControl?.setState(value);
1758
- setValue(value);
1759
- yearControl.setState(value.getFullYear());
1760
- dayControl.setState(value.getDate());
1761
- monthControl.setState(value.getMonth());
1749
+ yearControl.setState(today.getFullYear());
1750
+ dayControl.setState(today.getDate());
1751
+ monthControl.setState(today.getMonth());
1752
+ formControl?.setState(today);
1762
1753
  if (onListener) {
1763
- onListener({ type: PickerListenerType.Now, value });
1754
+ onListener({ type: PickerListenerType.Now, value: today });
1764
1755
  }
1765
1756
  }
1766
1757
  function onSelect() {
@@ -1769,27 +1760,38 @@ function RlsDatePicker({ automatic, date, formControl, disabled, maxDate, minDat
1769
1760
  onListener({ type: PickerListenerType.Select, value });
1770
1761
  }
1771
1762
  }
1772
- return (jsxRuntime.jsxs("div", { className: "rls-date-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-date-picker__header", children: [jsxRuntime.jsx("div", { className: "rls-date-picker__title rls-date-picker__title--description", children: jsxRuntime.jsx("span", { onClick: onVisibilityDay, children: title }) }), jsxRuntime.jsx("div", { className: "rls-date-picker__title rls-date-picker__title--year", children: jsxRuntime.jsx("span", { onClick: onVisibilityYear, children: yearControl.value }) }), jsxRuntime.jsx(RlsMonthTitlePicker, { monthControl: monthControl, yearControl: yearControl, date: value, maxDate: maxDate, minDate: minDate, disabled: year, type: month ? 'year' : 'month', onClick: onVisibilityMonth })] }), jsxRuntime.jsxs("div", { className: renderClassStatus('rls-date-picker__component', {
1773
- year,
1774
- day,
1775
- month
1776
- }), children: [jsxRuntime.jsx(RlsDayPicker, { formControl: dayControl, date: value, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsxRuntime.jsx(RlsMonthPicker, { formControl: monthControl, date: value, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay }), jsxRuntime.jsx(RlsYearPicker, { formControl: yearControl, date: value, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay })] }), jsxRuntime.jsx("div", { className: renderClassStatus('rls-date-picker__footer', { automatic }), children: jsxRuntime.jsxs("div", { className: "rls-date-picker__actions", children: [jsxRuntime.jsx("div", { className: "rls-date-picker__actions--cancel", children: jsxRuntime.jsx(RlsButton, { type: "ghost", onClick: onCancel, children: reactI18n('dateActionCancel') }) }), jsxRuntime.jsx("div", { className: "rls-date-picker__actions--today", children: jsxRuntime.jsx(RlsButton, { type: "ghost", onClick: onToday, children: reactI18n('dateActionToday') }) }), jsxRuntime.jsx("div", { className: "rls-date-picker__actions--ok", children: jsxRuntime.jsx(RlsButton, { type: "raised", onClick: onSelect, children: reactI18n('dateActionSelect') }) })] }) })] }));
1763
+ return (jsxRuntime.jsxs("div", { className: "rls-date-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-date-picker__header", children: [jsxRuntime.jsx("div", { className: "rls-date-picker__title rls-date-picker__title--description", children: jsxRuntime.jsx("span", { onClick: onVisibilityDay, children: helpersDate.dateFormatTemplate(dateInitial, FORMAT_DESCRIPTION) }) }), jsxRuntime.jsx("div", { className: "rls-date-picker__title rls-date-picker__title--year", children: jsxRuntime.jsx("span", { onClick: onVisibilityYear, children: yearControl.value }) }), jsxRuntime.jsx(RlsMonthTitlePicker, { monthControl: monthControl, yearControl: yearControl, date: value, maxDate: maxDate, minDate: minDate, disabled: visibility === 'YEAR', type: 'month', onClick: onVisibilityMonth })] }), jsxRuntime.jsxs("div", { className: renderClassStatus('rls-date-picker__component', {
1764
+ day: visibility === 'DAY',
1765
+ month: visibility === 'MONTH',
1766
+ year: visibility === 'YEAR'
1767
+ }), children: [jsxRuntime.jsx(RlsDayPicker, { formControl: dayControl, date: dateInitial, month: monthControl.state, year: yearControl.state, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsxRuntime.jsx(RlsMonthPicker, { formControl: monthControl, date: dateInitial, year: yearControl.state, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay }), jsxRuntime.jsx(RlsYearPicker, { formControl: yearControl, date: dateInitial, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay })] }), jsxRuntime.jsx("div", { className: renderClassStatus('rls-date-picker__footer', { automatic }), children: jsxRuntime.jsxs("div", { className: "rls-date-picker__actions", children: [jsxRuntime.jsx("div", { className: "rls-date-picker__actions--cancel", children: jsxRuntime.jsx(RlsButton, { type: "ghost", onClick: onCancel, children: reactI18n('dateActionCancel') }) }), jsxRuntime.jsx("div", { className: "rls-date-picker__actions--today", children: jsxRuntime.jsx(RlsButton, { type: "ghost", onClick: onToday, disabled: dateOutRange({ date: today, maxDate, minDate }), children: reactI18n('dateActionToday') }) }), jsxRuntime.jsx("div", { className: "rls-date-picker__actions--ok", children: jsxRuntime.jsx(RlsButton, { type: "raised", onClick: onSelect, children: reactI18n('dateActionSelect') }) })] }) })] }));
1777
1768
  }
1778
1769
 
1779
1770
  function RlsModal({ children, visible, rlsTheme }) {
1780
1771
  return ReactDOM.createPortal(jsxRuntime.jsxs("div", { className: renderClassStatus('rls-modal', { visible }), "rls-theme": rlsTheme, children: [jsxRuntime.jsx("div", { className: "rls-modal__component", children: children }), jsxRuntime.jsx("div", { className: "rls-modal__backdrop" })] }), document.body);
1781
1772
  }
1782
1773
 
1783
- function RlsDateField({ children, date, disabled, formControl, maxDate, minDate, placeholder, rlsTheme, onValue }) {
1784
- const dateInitial = formControl?.state || date || new Date();
1785
- const [value, setValue] = react.useState(dateInitial);
1786
- const [show, setShow] = react.useState(false);
1787
- const [description, setDescription] = react.useState('');
1774
+ function RlsDateField({ children, date, disabled, formControl, maxDate, minDate, onValue, placeholder, rlsTheme }) {
1775
+ const today = new Date(); // Initial current date in component
1776
+ const [value, setValue] = react.useState();
1777
+ const [modalIsVisible, setModalIsVisible] = react.useState(false);
1778
+ const description = react.useRef('');
1788
1779
  react.useEffect(() => {
1789
- setDescription(value ? helpersDate.dateFormatTemplate(value, DATE_RANGE_FORMAT) : '');
1780
+ const dateCheck = checkDateRange({
1781
+ date: formControl?.state || date || today,
1782
+ minDate,
1783
+ maxDate
1784
+ });
1785
+ setValue(dateCheck);
1786
+ formControl?.setState(dateCheck);
1787
+ }, []);
1788
+ react.useEffect(() => {
1789
+ description.current = value
1790
+ ? helpersDate.dateFormatTemplate(value, DATE_RANGE_FORMAT)
1791
+ : '';
1790
1792
  }, [value]);
1791
1793
  function onClickInput() {
1792
- setShow(true);
1794
+ setModalIsVisible(true);
1793
1795
  }
1794
1796
  function onChange(value, ignoreControl = false) {
1795
1797
  if (!ignoreControl) {
@@ -1808,40 +1810,21 @@ function RlsDateField({ children, date, disabled, formControl, maxDate, minDate,
1808
1810
  }
1809
1811
  }
1810
1812
  else {
1811
- setShow(true);
1813
+ setModalIsVisible(true);
1812
1814
  }
1813
1815
  }
1814
- return (jsxRuntime.jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: renderClassStatus('rls-box-field', { disabled }), children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsxs("div", { className: "rls-box-field__body", children: [jsxRuntime.jsx("input", { className: "rls-date-field__control", type: "text", value: description, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsxRuntime.jsx("button", { className: "rls-date-field__action", onClick: onClean, disabled: disabled, children: jsxRuntime.jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) }), formControl?.touched && formControl?.error && (jsxRuntime.jsx("div", { className: "rls-box-field__error", children: jsxRuntime.jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }), jsxRuntime.jsx(RlsModal, { visible: show, rlsTheme: rlsTheme, children: jsxRuntime.jsx(RlsDatePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value, type }) => {
1816
+ return (jsxRuntime.jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: renderClassStatus('rls-box-field', { disabled }), children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsxs("div", { className: "rls-box-field__body", children: [jsxRuntime.jsx("input", { className: "rls-date-field__control", type: "text", value: description.current, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsxRuntime.jsx("button", { className: "rls-date-field__action", onClick: onClean, disabled: disabled, children: jsxRuntime.jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) }), formControl?.touched && formControl?.error && (jsxRuntime.jsx("div", { className: "rls-box-field__error", children: jsxRuntime.jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }), jsxRuntime.jsx(RlsModal, { visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntime.jsx(RlsDatePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value, type }) => {
1815
1817
  if (type !== PickerListenerType.Cancel) {
1816
1818
  onChange(value, true);
1817
1819
  }
1818
- setShow(false);
1819
- if (formControl && !formControl.touched) {
1820
- formControl.touch();
1820
+ setModalIsVisible(false);
1821
+ if (!formControl?.touched) {
1822
+ formControl?.touch();
1821
1823
  }
1822
1824
  } }) })] }));
1823
1825
  }
1824
1826
 
1825
- const VISIBILITY_STATE = {
1826
- month: false,
1827
- day: false,
1828
- year: false
1829
- };
1830
- const VISIBILITY = {
1831
- DAY: {
1832
- ...VISIBILITY_STATE,
1833
- day: true
1834
- },
1835
- MONTH: {
1836
- ...VISIBILITY_STATE,
1837
- month: true
1838
- },
1839
- YEAR: {
1840
- ...VISIBILITY_STATE,
1841
- year: true
1842
- }
1843
- };
1844
- function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl, maxDate, minDate, rlsTheme, onListener }) {
1827
+ function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl, maxDate, minDate, onListener, rlsTheme }) {
1845
1828
  const dateInitial = helpersDate.normalizeMinTime(datePicker || new Date());
1846
1829
  const rangeInitial = formControl?.state || helpersDate.DateRange.now();
1847
1830
  const yearControl = useReactControl(dateInitial.getFullYear());
@@ -1849,7 +1832,7 @@ function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl
1849
1832
  const dayControl = useReactControl(rangeInitial);
1850
1833
  const [value, setValue] = react.useState(rangeInitial);
1851
1834
  const [date, setDate] = react.useState(dateInitial);
1852
- const [{ day, month, year }, setVisibility] = react.useState(VISIBILITY.DAY);
1835
+ const [visibility, setVisibility] = react.useState('DAY');
1853
1836
  react.useEffect(() => {
1854
1837
  setDate((prevValue) => {
1855
1838
  return typeof yearControl.state === 'number'
@@ -1868,16 +1851,16 @@ function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl
1868
1851
  if (dayControl.state) {
1869
1852
  setValue(dayControl.state);
1870
1853
  }
1871
- setVisibility(VISIBILITY.DAY);
1854
+ setVisibility('DAY');
1872
1855
  }, [dayControl.state]);
1873
1856
  function onVisibilityDay() {
1874
- setVisibility(VISIBILITY.DAY);
1857
+ setVisibility('DAY');
1875
1858
  }
1876
1859
  function onVisibilityMonth() {
1877
- setVisibility(VISIBILITY.MONTH);
1860
+ setVisibility('MONTH');
1878
1861
  }
1879
1862
  function onVisibilityYear() {
1880
- setVisibility(VISIBILITY.YEAR);
1863
+ setVisibility('YEAR');
1881
1864
  }
1882
1865
  function onCancel() {
1883
1866
  if (onListener) {
@@ -1890,11 +1873,11 @@ function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl
1890
1873
  onListener({ type: PickerListenerType.Select, value });
1891
1874
  }
1892
1875
  }
1893
- return (jsxRuntime.jsxs("div", { className: "rls-date-range-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-date-range-picker__header", children: [jsxRuntime.jsx("div", { className: "rls-date-range-picker__title rls-date-range-picker__title--description", children: jsxRuntime.jsx("span", { onClick: onVisibilityDay, children: rangeFormatTemplate(value) }) }), jsxRuntime.jsx("div", { className: "rls-date-range-picker__title rls-date-range-picker__title--year", children: jsxRuntime.jsx("span", { onClick: onVisibilityYear, children: yearControl.state }) }), jsxRuntime.jsx(RlsMonthTitlePicker, { monthControl: monthControl, yearControl: yearControl, date: date, maxDate: maxDate, minDate: minDate, disabled: year, type: month ? 'year' : 'month', onClick: onVisibilityMonth })] }), jsxRuntime.jsxs("div", { className: renderClassStatus('rls-date-range-picker__component', {
1894
- year,
1895
- day,
1896
- month
1897
- }), children: [jsxRuntime.jsx(RlsDayRangePicker, { formControl: dayControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsxRuntime.jsx(RlsMonthPicker, { formControl: monthControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay }), jsxRuntime.jsx(RlsYearPicker, { formControl: yearControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay })] }), jsxRuntime.jsx("div", { className: renderClassStatus('rls-date-range-picker__footer', {
1876
+ return (jsxRuntime.jsxs("div", { className: "rls-date-range-picker", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-date-range-picker__header", children: [jsxRuntime.jsx("div", { className: "rls-date-range-picker__title rls-date-range-picker__title--description", children: jsxRuntime.jsx("span", { onClick: onVisibilityDay, children: rangeFormatTemplate(value) }) }), jsxRuntime.jsx("div", { className: "rls-date-range-picker__title rls-date-range-picker__title--year", children: jsxRuntime.jsx("span", { onClick: onVisibilityYear, children: yearControl.state }) }), jsxRuntime.jsx(RlsMonthTitlePicker, { monthControl: monthControl, yearControl: yearControl, date: date, maxDate: maxDate, minDate: minDate, disabled: visibility === 'YEAR', type: visibility === 'MONTH' ? 'year' : 'month', onClick: onVisibilityMonth })] }), jsxRuntime.jsxs("div", { className: renderClassStatus('rls-date-range-picker__component', {
1877
+ day: visibility === 'DAY',
1878
+ month: visibility === 'MONTH',
1879
+ year: visibility === 'YEAR'
1880
+ }), children: [jsxRuntime.jsx(RlsDayRangePicker, { formControl: dayControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsxRuntime.jsx(RlsMonthPicker, { formControl: monthControl, year: yearControl.state, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay }), jsxRuntime.jsx(RlsYearPicker, { formControl: yearControl, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay })] }), jsxRuntime.jsx("div", { className: renderClassStatus('rls-date-range-picker__footer', {
1898
1881
  automatic
1899
1882
  }), children: jsxRuntime.jsxs("div", { className: "rls-date-range-picker__actions", children: [jsxRuntime.jsx("div", { className: "rls-date-range-picker__actions--cancel", children: jsxRuntime.jsx(RlsButton, { type: "ghost", onClick: onCancel, children: reactI18n('dateActionCancel') }) }), jsxRuntime.jsx("div", { className: "rls-date-range-picker__actions--ok", children: jsxRuntime.jsx(RlsButton, { type: "raised", onClick: onSelect, children: reactI18n('dateActionSelect') }) })] }) })] }));
1900
1883
  }
@@ -1905,9 +1888,9 @@ function RlsDateRangeField({ children, date: datePicker, disabled, formControl,
1905
1888
  const [value, setValue] = react.useState(rangeInitial);
1906
1889
  const [date] = react.useState(dateInitial);
1907
1890
  const [show, setShow] = react.useState(false);
1908
- const [description, setDescription] = react.useState('');
1891
+ const description = react.useRef('');
1909
1892
  react.useEffect(() => {
1910
- setDescription(value ? rangeFormatTemplate(value) : '');
1893
+ description.current = value ? rangeFormatTemplate(value) : '';
1911
1894
  }, [value]);
1912
1895
  function onClickInput() {
1913
1896
  setShow(true);
@@ -1921,7 +1904,7 @@ function RlsDateRangeField({ children, date: datePicker, disabled, formControl,
1921
1904
  setShow(true);
1922
1905
  }
1923
1906
  }
1924
- return (jsxRuntime.jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-box-field", children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsxs("div", { className: "rls-box-field__body", children: [jsxRuntime.jsx("input", { className: "rls-date-field__control", type: "text", value: description, readOnly: true, placeholder: placeholder, onClick: onClickInput }), jsxRuntime.jsx("button", { className: "rls-date-field__action", onClick: onClickAction, children: jsxRuntime.jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) })] }), jsxRuntime.jsx(RlsModal, { visible: show, rlsTheme: rlsTheme, children: jsxRuntime.jsx(RlsDateRangePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
1907
+ return (jsxRuntime.jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-box-field", children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsxs("div", { className: "rls-box-field__body", children: [jsxRuntime.jsx("input", { className: "rls-date-field__control", type: "text", value: description.current, readOnly: true, placeholder: placeholder, onClick: onClickInput }), jsxRuntime.jsx("button", { className: "rls-date-field__action", onClick: onClickAction, children: jsxRuntime.jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) })] }), jsxRuntime.jsx(RlsModal, { visible: show, rlsTheme: rlsTheme, children: jsxRuntime.jsx(RlsDateRangePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
1925
1908
  if (value) {
1926
1909
  setValue(value);
1927
1910
  }
@@ -1936,31 +1919,27 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
1936
1919
  function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1937
1920
  const listControl = useListControl({ suggestions, formControl });
1938
1921
  const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1939
- const [changeInternal, setChangeInternal] = react.useState(false);
1922
+ const changeInternal = react.useRef(false);
1940
1923
  react.useEffect(() => {
1941
- changeInternal ? setChangeInternal(false) : resetState(formControl?.state);
1924
+ if (changeInternal.current) {
1925
+ changeInternal.current = false;
1926
+ }
1927
+ else {
1928
+ resetState(formControl?.state);
1929
+ }
1942
1930
  }, [formControl?.state]);
1943
1931
  react.useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1944
1932
  function setFormState(value) {
1945
- setChangeInternal(true);
1946
- formControl?.setState(value);
1933
+ if (formControl) {
1934
+ changeInternal.current = true;
1935
+ formControl.setState(value);
1936
+ }
1947
1937
  }
1948
1938
  function resetCollection(collection, state) {
1949
- if (state) {
1950
- const element = collection.find(state);
1951
- if (element) {
1952
- setValue(element.description);
1953
- }
1954
- else {
1955
- setValue('');
1956
- }
1957
- }
1958
- else {
1959
- setValue('');
1960
- }
1939
+ setValue(state ? collection.find(state)?.description || '' : '');
1961
1940
  }
1962
1941
  function resetState(state) {
1963
- setValue(state ? collection.find(state)?.description || '' : '');
1942
+ resetCollection(collection, state);
1964
1943
  }
1965
1944
  function onFocusInput() {
1966
1945
  setFocused(true);
@@ -1968,20 +1947,16 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1968
1947
  function onBlurInput() {
1969
1948
  setFocused(false);
1970
1949
  }
1971
- function onClickControl() {
1950
+ function onClickInput() {
1972
1951
  setVisible(true);
1973
1952
  }
1974
1953
  function onKeydownInput(event) {
1975
1954
  switch (event.code) {
1976
1955
  case 'Space':
1977
- setVisible(true);
1978
- break;
1979
1956
  case 'Enter':
1980
1957
  setVisible(true);
1981
1958
  break;
1982
1959
  case 'Escape':
1983
- setVisible(false);
1984
- break;
1985
1960
  case 'Tab':
1986
1961
  setVisible(false);
1987
1962
  break;
@@ -2007,14 +1982,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
2007
1982
  }
2008
1983
  function onKeydownElement(element) {
2009
1984
  return (event) => {
2010
- switch (event.code) {
2011
- case 'Enter':
2012
- onChange(element);
2013
- break;
2014
- default:
2015
- navigationElement(event);
2016
- break;
2017
- }
1985
+ event.code === 'Enter' ? onChange(element) : navigationElement(event);
2018
1986
  };
2019
1987
  }
2020
1988
  function onChange({ description, value }) {
@@ -2024,9 +1992,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
2024
1992
  onSelect(value);
2025
1993
  }
2026
1994
  else {
2027
- if (formControl) {
2028
- setFormState(value);
2029
- }
1995
+ setFormState(value);
2030
1996
  setValue(description);
2031
1997
  }
2032
1998
  if (onValue) {
@@ -2038,7 +2004,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
2038
2004
  onBlurInput,
2039
2005
  onClickAction,
2040
2006
  onClickBackdrop,
2041
- onClickInput: onClickControl,
2007
+ onClickInput,
2042
2008
  onClickElement,
2043
2009
  onFocusInput,
2044
2010
  onKeydownElement,
@@ -2060,7 +2026,7 @@ function RlsSelectFieldTemplate({ suggestions, children, disabled, formControl,
2060
2026
  visible: listControl.visible,
2061
2027
  hide: !listControl.visible,
2062
2028
  higher: listControl.higher
2063
- }), children: [jsxRuntime.jsx("div", { className: "rls-list-field__suggestions__body", children: jsxRuntime.jsxs("ul", { ref: listControl.listRef, className: "rls-list-field__ul", children: [suggestions.map((element, index) => (jsxRuntime.jsx("li", { className: "rls-list-field__element", tabIndex: -1, onClick: onClickElement(element), onKeyDown: onKeydownElement(element), children: render(element) }, index))), !suggestions.length && (jsxRuntime.jsx("li", { className: "rls-list-field__empty", children: jsxRuntime.jsxs("div", { className: "rls-list-field__empty__description", children: [jsxRuntime.jsx("label", { className: "label-bold truncate", children: reactI18n('listEmptyTitle') }), jsxRuntime.jsx("p", { className: "caption-regular", children: reactI18n('listEmptyDescription') })] }) }))] }) }), jsxRuntime.jsx("div", { className: "rls-list-field__backdrop", onClick: onClickBackdrop })] })] }));
2029
+ }), children: [jsxRuntime.jsx("div", { className: "rls-list-field__suggestions__body", children: jsxRuntime.jsxs("ul", { ref: listControl.listRef, className: "rls-list-field__ul", children: [suggestions.map((element, index) => (jsxRuntime.jsx("li", { className: "rls-list-field__element", tabIndex: -1, onClick: onClickElement(element), onKeyDown: onKeydownElement(element), children: render(element) }, index))), !suggestions.length && (jsxRuntime.jsx("li", { className: "rls-list-field__empty", children: jsxRuntime.jsxs("div", { className: "rls-list-field__empty__description", children: [jsxRuntime.jsx("label", { className: "rls-label-bold truncate", children: reactI18n('listEmptyTitle') }), jsxRuntime.jsx("p", { className: "rls-caption-regular", children: reactI18n('listEmptyDescription') })] }) }))] }) }), jsxRuntime.jsx("div", { className: "rls-list-field__backdrop", onClick: onClickBackdrop })] })] }));
2064
2030
  }
2065
2031
  function RlsSelectField(props) {
2066
2032
  return (jsxRuntime.jsx(RlsSelectFieldTemplate, { ...props, render: (element) => (jsxRuntime.jsx(RlsBallot, { subtitle: element.subtitle, img: element.img, initials: element.initials, children: element.title })) }));
@@ -2128,7 +2094,6 @@ function RlsApplication({ children }) {
2128
2094
  }
2129
2095
 
2130
2096
  exports.ConfirmationResult = ConfirmationResult;
2131
- exports.ListCollection = ListCollection;
2132
2097
  exports.RlsAmount = RlsAmount;
2133
2098
  exports.RlsApplication = RlsApplication;
2134
2099
  exports.RlsAutocompleteField = RlsAutocompleteField;
@@ -2194,6 +2159,7 @@ exports.RlsTabularText = RlsTabularText;
2194
2159
  exports.RlsTextField = RlsTextField;
2195
2160
  exports.RlsToolbar = RlsToolbar;
2196
2161
  exports.RlsYearPicker = RlsYearPicker;
2162
+ exports.rangeFormatTemplate = rangeFormatTemplate;
2197
2163
  exports.renderClassStatus = renderClassStatus;
2198
2164
  exports.useConfirmationService = useConfirmationService;
2199
2165
  exports.useDatatable = useDatatable;