@agnos-ui/core 0.9.3 → 0.10.0-next.1

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 (113) hide show
  1. package/{accordion-cR5JqWJ8.cjs → accordion-B5LiN1uy.cjs} +15 -20
  2. package/{accordion-CoM4efp-.js → accordion-_zen-g8l.js} +15 -20
  3. package/{alert-DtDozJal.cjs → alert-B-jQDQcB.cjs} +1 -1
  4. package/{alert-YIlqdEPO.js → alert-gGz2CDS9.js} +1 -1
  5. package/{collapse-DwXz2kNw.js → collapse-BV4kD3j9.js} +2 -2
  6. package/{collapse-DRp53EuG.cjs → collapse-gLiT080Y.cjs} +2 -2
  7. package/{common-BToNPUDq.cjs → common-D3QcdJ6S.cjs} +1 -1
  8. package/{common-BqUjUBPy.js → common-DK0ADNTX.js} +1 -1
  9. package/components/accordion/accordion.d.ts +6 -6
  10. package/components/accordion/index.cjs +1 -1
  11. package/components/accordion/index.js +1 -1
  12. package/components/alert/index.cjs +1 -1
  13. package/components/alert/index.js +1 -1
  14. package/components/carousel/carousel.d.ts +15 -0
  15. package/components/carousel/index.cjs +10 -23
  16. package/components/carousel/index.js +10 -23
  17. package/components/collapse/collapse.d.ts +5 -2
  18. package/components/collapse/index.cjs +1 -1
  19. package/components/collapse/index.js +1 -1
  20. package/components/drawer/drawer.d.ts +242 -0
  21. package/components/drawer/index.cjs +5 -0
  22. package/components/drawer/index.d.ts +1 -0
  23. package/components/drawer/index.js +5 -0
  24. package/components/modal/index.cjs +2 -1
  25. package/components/modal/index.js +2 -1
  26. package/components/modal/modal.d.ts +5 -0
  27. package/components/pagination/index.cjs +1 -1
  28. package/components/pagination/index.js +1 -1
  29. package/components/progressbar/index.cjs +1 -1
  30. package/components/progressbar/index.js +1 -1
  31. package/components/rating/index.cjs +1 -1
  32. package/components/rating/index.js +1 -1
  33. package/components/select/index.cjs +1 -1
  34. package/components/select/index.js +1 -1
  35. package/components/slider/index.cjs +1 -1
  36. package/components/slider/index.js +1 -1
  37. package/components/slider/slider.d.ts +4 -4
  38. package/components/toast/index.cjs +1 -1
  39. package/components/toast/index.js +1 -1
  40. package/components/tree/index.cjs +1 -1
  41. package/components/tree/index.js +1 -1
  42. package/components/tree/tree.d.ts +0 -6
  43. package/config.cjs +2 -2
  44. package/config.d.ts +5 -0
  45. package/config.js +2 -2
  46. package/{dom-gfxqXJpK.js → dom-Bcg9ORcA.js} +64 -54
  47. package/{dom-CuBx1JPZ.cjs → dom-C2gi9OCP.cjs} +47 -37
  48. package/drawer-D5SO73ew.js +251 -0
  49. package/drawer-DP7UPojk.cjs +250 -0
  50. package/index.cjs +19 -13
  51. package/index.d.ts +1 -0
  52. package/index.js +36 -30
  53. package/isFocusable-Ckwus82R.js +32 -0
  54. package/isFocusable-DfzDLeAN.cjs +31 -0
  55. package/{modal-D3wGIDlj.js → modal-CAvQW-vo.js} +26 -32
  56. package/{modal-BEnQ6c5M.cjs → modal-DiXZXYjR.cjs} +27 -33
  57. package/package.json +1 -1
  58. package/{pagination-B97wBLok.js → pagination-BKbMROV6.js} +4 -4
  59. package/{pagination-C1TT-oea.cjs → pagination-DvZ2rLsz.cjs} +4 -4
  60. package/{progressbar-BWBlRk_Y.js → progressbar-D8zIcm9n.js} +2 -2
  61. package/{progressbar-CRvhNB5R.cjs → progressbar-i9xfAxb7.cjs} +2 -2
  62. package/{promise-XSP94FjG.js → promise-Y53vc4Ia.js} +5 -5
  63. package/{rating-BXvy9kXq.js → rating-DEXTGWCU.js} +2 -2
  64. package/{rating-DAb6nR67.cjs → rating-DmG4oUkr.cjs} +2 -2
  65. package/scrollbars-CT87iv_6.cjs +30 -0
  66. package/scrollbars-CcxSrnCx.js +31 -0
  67. package/{select-BdjpnE7_.js → select-Bw68Xdu5.js} +4 -5
  68. package/{select-C0rJJQfl.cjs → select-MFjAnIt7.cjs} +4 -5
  69. package/services/extendWidget.cjs +2 -2
  70. package/services/extendWidget.js +2 -2
  71. package/services/floatingUI.cjs +8 -29
  72. package/services/floatingUI.js +9 -30
  73. package/services/focusElement.cjs +46 -0
  74. package/services/focusElement.d.ts +9 -0
  75. package/services/focusElement.js +46 -0
  76. package/services/focustrack.cjs +1 -1
  77. package/services/focustrack.js +1 -1
  78. package/services/matchMedia.cjs +1 -1
  79. package/services/matchMedia.js +1 -1
  80. package/services/navManager.cjs +7 -37
  81. package/services/navManager.js +6 -36
  82. package/services/portal.cjs +7 -10
  83. package/services/portal.js +7 -10
  84. package/services/resizeObserver.cjs +2 -2
  85. package/services/resizeObserver.js +2 -2
  86. package/services/siblingsInert.cjs +9 -8
  87. package/services/siblingsInert.d.ts +13 -3
  88. package/services/siblingsInert.js +9 -8
  89. package/services/transitions/baseTransitions.cjs +9 -10
  90. package/services/transitions/baseTransitions.js +10 -11
  91. package/services/transitions/collapse.cjs +1 -1
  92. package/services/transitions/collapse.js +1 -1
  93. package/services/transitions/cssTransitions.cjs +1 -1
  94. package/services/transitions/cssTransitions.js +2 -2
  95. package/services/transitions/simpleClassTransition.cjs +1 -1
  96. package/services/transitions/simpleClassTransition.js +1 -1
  97. package/{slider-BmxQ3A_u.js → slider-Cx50Eghd.js} +14 -24
  98. package/{slider-DSx5CAce.cjs → slider-Dl4Trh32.cjs} +14 -24
  99. package/toaster-UDglac7x.cjs +187 -0
  100. package/toaster-_p1GTtHI.js +188 -0
  101. package/{tree-BFrXdJox.js → tree-DV0tfPlZ.js} +7 -11
  102. package/{tree-Pvr2rZ-D.cjs → tree-rGHtmCnS.cjs} +7 -11
  103. package/utils/directive.cjs +3 -1
  104. package/utils/directive.d.ts +47 -0
  105. package/utils/directive.js +14 -12
  106. package/utils/stores.cjs +8 -9
  107. package/utils/stores.js +8 -9
  108. package/utils/writables.cjs +1 -1
  109. package/utils/writables.js +1 -1
  110. package/{writables-Bn3uhKEG.cjs → writables-DcGT98a7.cjs} +1 -1
  111. package/{writables-CgpOQ4hA.js → writables-e0tyaQpe.js} +1 -1
  112. package/toaster-Cayg6Lbq.cjs +0 -209
  113. package/toaster-XfzHDqz_.js +0 -210
@@ -1,18 +1,17 @@
1
1
  import { computed, writable, readable } from "@amadeus-it-group/tansu";
2
- import { j as createBrowserStoreDirective, g as createBrowserStoreArrayDirective, k as mergeDirectives, n as createAttributesDirective, b as browserDirective } from "./dom-gfxqXJpK.js";
2
+ import { l as createBrowserStoreDirective, h as createBrowserStoreArrayDirective, n as mergeDirectives, p as createAttributesDirective, b as browserDirective } from "./dom-Bcg9ORcA.js";
3
3
  import { noop } from "./utils/func.js";
4
4
  import { writablesForProps, bindableProp, stateStores, true$ } from "./utils/stores.js";
5
- import { i as typeArray, c as typeBoolean, b as typeNumberInRangeFactory, e as typeString, g as typeFunction, a as typeNumber } from "./writables-CgpOQ4hA.js";
5
+ import { i as typeArray, c as typeBoolean, b as typeNumberInRangeFactory, e as typeString, g as typeFunction, a as typeNumber } from "./writables-e0tyaQpe.js";
6
6
  import { createResizeObserver } from "./services/resizeObserver.js";
7
7
  import { createWidgetFactory } from "./utils/widget.js";
8
8
  const decimalRegExp = /(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/;
9
9
  function getDecimalPrecision(number) {
10
- var _a;
11
10
  const matches = ("" + number).match(decimalRegExp);
12
11
  return Math.max(
13
12
  0,
14
13
  // Number of digits right of decimal point.
15
- (((_a = matches[1]) == null ? void 0 : _a.length) ?? 0) - // Adjust for exponential notation.
14
+ (matches[1]?.length ?? 0) - // Adjust for exponential notation.
16
15
  (+matches[2] || 0)
17
16
  );
18
17
  }
@@ -255,10 +254,9 @@ const createSlider = createWidgetFactory("slider", (config) => {
255
254
  );
256
255
  const sliderDomRect$ = computed(
257
256
  () => {
258
- var _a;
259
257
  dimensions$();
260
258
  updateSliderSize$();
261
- return ((_a = sliderDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
259
+ return sliderDom$()?.getBoundingClientRect() ?? {};
262
260
  },
263
261
  {
264
262
  equal: Object.is
@@ -266,10 +264,9 @@ const createSlider = createWidgetFactory("slider", (config) => {
266
264
  );
267
265
  const minLabelDomRect$ = computed(
268
266
  () => {
269
- var _a;
270
267
  dimensions$();
271
268
  updateSliderSize$();
272
- return ((_a = minLabelDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
269
+ return minLabelDom$()?.getBoundingClientRect() ?? {};
273
270
  },
274
271
  {
275
272
  equal: (a, b) => Object.is(a, b)
@@ -277,10 +274,9 @@ const createSlider = createWidgetFactory("slider", (config) => {
277
274
  );
278
275
  const maxLabelDomRect$ = computed(
279
276
  () => {
280
- var _a;
281
277
  dimensions$();
282
278
  updateSliderSize$();
283
- return ((_a = maxLabelDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
279
+ return maxLabelDom$()?.getBoundingClientRect() ?? {};
284
280
  },
285
281
  {
286
282
  equal: (a, b) => Object.is(a, b)
@@ -318,16 +314,10 @@ const createSlider = createWidgetFactory("slider", (config) => {
318
314
  const adjustedShowValueLabels$ = computed(() => showValueLabels$() && (!showTicks$() || !showTickValues$()));
319
315
  const pixelToPercent = (pixels) => pixels ? pixels / sliderDomRectSize$() * 100 : 0;
320
316
  const combinedLabelSize$ = computed(
321
- () => {
322
- var _a, _b;
323
- return pixelToPercent(vertical$() ? (_a = combinedLabelDom$()) == null ? void 0 : _a.getBoundingClientRect().height : (_b = combinedLabelDom$()) == null ? void 0 : _b.getBoundingClientRect().width);
324
- }
317
+ () => pixelToPercent(vertical$() ? combinedLabelDom$()?.getBoundingClientRect().height : combinedLabelDom$()?.getBoundingClientRect().width)
325
318
  );
326
319
  const combinedLabelPosition$ = computed(() => vertical$() ? combinedLabelPositionTop$() : combinedLabelPositionLeft$());
327
- const currentLabelSizeByIndex = (index) => {
328
- var _a, _b;
329
- return pixelToPercent(vertical$() ? (_a = currentLabelDomsRect$()[index]) == null ? void 0 : _a.height : (_b = currentLabelDomsRect$()[index]) == null ? void 0 : _b.width);
330
- };
320
+ const currentLabelSizeByIndex = (index) => pixelToPercent(vertical$() ? currentLabelDomsRect$()[index]?.height : currentLabelDomsRect$()[index]?.width);
331
321
  const minValueLabelDisplay$ = computed(() => {
332
322
  if (!showMinMaxLabels$() || showTicks$() && showTickValues$()) {
333
323
  return false;
@@ -369,8 +359,8 @@ const createSlider = createWidgetFactory("slider", (config) => {
369
359
  storedLabelSize$.set(values.map((_, index) => currentLabelSizeByIndex(index) / 2));
370
360
  }
371
361
  const storedLabelSize = storedLabelSize$();
372
- const firstLabelSize = (storedLabelSize == null ? void 0 : storedLabelSize[0]) ?? 0;
373
- const secondLabelSize = (storedLabelSize == null ? void 0 : storedLabelSize[1]) ?? 0;
362
+ const firstLabelSize = storedLabelSize?.[0] ?? 0;
363
+ const secondLabelSize = storedLabelSize?.[1] ?? 0;
374
364
  const biggestLabelSize = Math.max(firstLabelSize, secondLabelSize);
375
365
  const intersectionLimit = biggestLabelSize !== 50 ? biggestLabelSize * 2 + 2 : 15;
376
366
  return values.length == 2 && values[1] - secondLabelSize - values[0] + firstLabelSize < intersectionLimit;
@@ -567,7 +557,7 @@ const createSlider = createWidgetFactory("slider", (config) => {
567
557
  const handleDrag = (e) => {
568
558
  e.preventDefault();
569
559
  const newCoord = vertical$() ? e.clientY : e.clientX;
570
- currentTarget == null ? void 0 : currentTarget.focus();
560
+ currentTarget?.focus();
571
561
  if (_prevCoordinate !== newCoord) {
572
562
  _prevCoordinate = newCoord;
573
563
  adjustCoordinate(newCoord, handleId);
@@ -575,7 +565,7 @@ const createSlider = createWidgetFactory("slider", (config) => {
575
565
  };
576
566
  if (interactive$()) {
577
567
  updateSliderSize$.set({});
578
- currentTarget == null ? void 0 : currentTarget.focus();
568
+ currentTarget?.focus();
579
569
  document.addEventListener("mousemove", handleDrag);
580
570
  document.addEventListener(
581
571
  "mouseup",
@@ -591,7 +581,7 @@ const createSlider = createWidgetFactory("slider", (config) => {
591
581
  const handleDrag = (e) => {
592
582
  e.preventDefault();
593
583
  const newCoord = vertical$() ? e.touches[0].clientY : e.touches[0].clientX;
594
- currentTarget == null ? void 0 : currentTarget.focus();
584
+ currentTarget?.focus();
595
585
  if (_prevCoordinate !== newCoord) {
596
586
  _prevCoordinate = newCoord;
597
587
  adjustCoordinate(newCoord, handleId);
@@ -599,7 +589,7 @@ const createSlider = createWidgetFactory("slider", (config) => {
599
589
  };
600
590
  if (interactive$()) {
601
591
  updateSliderSize$.set({});
602
- currentTarget == null ? void 0 : currentTarget.focus();
592
+ currentTarget?.focus();
603
593
  document.addEventListener("touchmove", handleDrag, { passive: false });
604
594
  document.addEventListener(
605
595
  "touchend",
@@ -1,19 +1,18 @@
1
1
  "use strict";
2
2
  const tansu = require("@amadeus-it-group/tansu");
3
- const utils_directive = require("./dom-CuBx1JPZ.cjs");
3
+ const utils_directive = require("./dom-C2gi9OCP.cjs");
4
4
  const utils_func = require("./utils/func.cjs");
5
5
  const utils_stores = require("./utils/stores.cjs");
6
- const utils_writables = require("./writables-Bn3uhKEG.cjs");
6
+ const utils_writables = require("./writables-DcGT98a7.cjs");
7
7
  const services_resizeObserver = require("./services/resizeObserver.cjs");
8
8
  const utils_widget = require("./utils/widget.cjs");
9
9
  const decimalRegExp = /(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/;
10
10
  function getDecimalPrecision(number) {
11
- var _a;
12
11
  const matches = ("" + number).match(decimalRegExp);
13
12
  return Math.max(
14
13
  0,
15
14
  // Number of digits right of decimal point.
16
- (((_a = matches[1]) == null ? void 0 : _a.length) ?? 0) - // Adjust for exponential notation.
15
+ (matches[1]?.length ?? 0) - // Adjust for exponential notation.
17
16
  (+matches[2] || 0)
18
17
  );
19
18
  }
@@ -256,10 +255,9 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
256
255
  );
257
256
  const sliderDomRect$ = tansu.computed(
258
257
  () => {
259
- var _a;
260
258
  dimensions$();
261
259
  updateSliderSize$();
262
- return ((_a = sliderDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
260
+ return sliderDom$()?.getBoundingClientRect() ?? {};
263
261
  },
264
262
  {
265
263
  equal: Object.is
@@ -267,10 +265,9 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
267
265
  );
268
266
  const minLabelDomRect$ = tansu.computed(
269
267
  () => {
270
- var _a;
271
268
  dimensions$();
272
269
  updateSliderSize$();
273
- return ((_a = minLabelDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
270
+ return minLabelDom$()?.getBoundingClientRect() ?? {};
274
271
  },
275
272
  {
276
273
  equal: (a, b) => Object.is(a, b)
@@ -278,10 +275,9 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
278
275
  );
279
276
  const maxLabelDomRect$ = tansu.computed(
280
277
  () => {
281
- var _a;
282
278
  dimensions$();
283
279
  updateSliderSize$();
284
- return ((_a = maxLabelDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
280
+ return maxLabelDom$()?.getBoundingClientRect() ?? {};
285
281
  },
286
282
  {
287
283
  equal: (a, b) => Object.is(a, b)
@@ -319,16 +315,10 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
319
315
  const adjustedShowValueLabels$ = tansu.computed(() => showValueLabels$() && (!showTicks$() || !showTickValues$()));
320
316
  const pixelToPercent = (pixels) => pixels ? pixels / sliderDomRectSize$() * 100 : 0;
321
317
  const combinedLabelSize$ = tansu.computed(
322
- () => {
323
- var _a, _b;
324
- return pixelToPercent(vertical$() ? (_a = combinedLabelDom$()) == null ? void 0 : _a.getBoundingClientRect().height : (_b = combinedLabelDom$()) == null ? void 0 : _b.getBoundingClientRect().width);
325
- }
318
+ () => pixelToPercent(vertical$() ? combinedLabelDom$()?.getBoundingClientRect().height : combinedLabelDom$()?.getBoundingClientRect().width)
326
319
  );
327
320
  const combinedLabelPosition$ = tansu.computed(() => vertical$() ? combinedLabelPositionTop$() : combinedLabelPositionLeft$());
328
- const currentLabelSizeByIndex = (index) => {
329
- var _a, _b;
330
- return pixelToPercent(vertical$() ? (_a = currentLabelDomsRect$()[index]) == null ? void 0 : _a.height : (_b = currentLabelDomsRect$()[index]) == null ? void 0 : _b.width);
331
- };
321
+ const currentLabelSizeByIndex = (index) => pixelToPercent(vertical$() ? currentLabelDomsRect$()[index]?.height : currentLabelDomsRect$()[index]?.width);
332
322
  const minValueLabelDisplay$ = tansu.computed(() => {
333
323
  if (!showMinMaxLabels$() || showTicks$() && showTickValues$()) {
334
324
  return false;
@@ -370,8 +360,8 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
370
360
  storedLabelSize$.set(values.map((_, index) => currentLabelSizeByIndex(index) / 2));
371
361
  }
372
362
  const storedLabelSize = storedLabelSize$();
373
- const firstLabelSize = (storedLabelSize == null ? void 0 : storedLabelSize[0]) ?? 0;
374
- const secondLabelSize = (storedLabelSize == null ? void 0 : storedLabelSize[1]) ?? 0;
363
+ const firstLabelSize = storedLabelSize?.[0] ?? 0;
364
+ const secondLabelSize = storedLabelSize?.[1] ?? 0;
375
365
  const biggestLabelSize = Math.max(firstLabelSize, secondLabelSize);
376
366
  const intersectionLimit = biggestLabelSize !== 50 ? biggestLabelSize * 2 + 2 : 15;
377
367
  return values.length == 2 && values[1] - secondLabelSize - values[0] + firstLabelSize < intersectionLimit;
@@ -568,7 +558,7 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
568
558
  const handleDrag = (e) => {
569
559
  e.preventDefault();
570
560
  const newCoord = vertical$() ? e.clientY : e.clientX;
571
- currentTarget == null ? void 0 : currentTarget.focus();
561
+ currentTarget?.focus();
572
562
  if (_prevCoordinate !== newCoord) {
573
563
  _prevCoordinate = newCoord;
574
564
  adjustCoordinate(newCoord, handleId);
@@ -576,7 +566,7 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
576
566
  };
577
567
  if (interactive$()) {
578
568
  updateSliderSize$.set({});
579
- currentTarget == null ? void 0 : currentTarget.focus();
569
+ currentTarget?.focus();
580
570
  document.addEventListener("mousemove", handleDrag);
581
571
  document.addEventListener(
582
572
  "mouseup",
@@ -592,7 +582,7 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
592
582
  const handleDrag = (e) => {
593
583
  e.preventDefault();
594
584
  const newCoord = vertical$() ? e.touches[0].clientY : e.touches[0].clientX;
595
- currentTarget == null ? void 0 : currentTarget.focus();
585
+ currentTarget?.focus();
596
586
  if (_prevCoordinate !== newCoord) {
597
587
  _prevCoordinate = newCoord;
598
588
  adjustCoordinate(newCoord, handleId);
@@ -600,7 +590,7 @@ const createSlider = utils_widget.createWidgetFactory("slider", (config) => {
600
590
  };
601
591
  if (interactive$()) {
602
592
  updateSliderSize$.set({});
603
- currentTarget == null ? void 0 : currentTarget.focus();
593
+ currentTarget?.focus();
604
594
  document.addEventListener("touchmove", handleDrag, { passive: false });
605
595
  document.addEventListener(
606
596
  "touchend",
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ const tansu = require("@amadeus-it-group/tansu");
3
+ const services_extendWidget = require("./services/extendWidget.cjs");
4
+ const utils_directive = require("./dom-C2gi9OCP.cjs");
5
+ const utils_stores = require("./utils/stores.cjs");
6
+ const utils_writables = require("./writables-DcGT98a7.cjs");
7
+ const common = require("./common-D3QcdJ6S.cjs");
8
+ const utils_widget = require("./utils/widget.cjs");
9
+ const toastDefaultConfig = {
10
+ autoHide: true,
11
+ delay: 5e3
12
+ };
13
+ const toastConfigValidator = {
14
+ autoHide: utils_writables.typeBoolean,
15
+ delay: utils_writables.typeNumberInRangeFactory(0, Infinity, { strict: true })
16
+ };
17
+ function getToastDefaultConfig() {
18
+ return { ...common.getCommonAlertDefaultConfig(), ...toastDefaultConfig };
19
+ }
20
+ const createToast = utils_widget.createWidgetFactory("toast", (config) => {
21
+ let _timeout;
22
+ const extendedAlert = services_extendWidget.extendWidgetProps(
23
+ common.createCommonAlert,
24
+ toastDefaultConfig,
25
+ toastConfigValidator
26
+ )(config);
27
+ const time$ = tansu.computed(() => {
28
+ clearTimeout(_timeout);
29
+ if (extendedAlert.stores.autoHide$()) {
30
+ _timeout = setTimeout(() => extendedAlert.api.close(), extendedAlert.stores.delay$());
31
+ }
32
+ });
33
+ const bodyDirective = utils_directive.createAttributesDirective(() => ({
34
+ attributes: {
35
+ role: tansu.readable("alert"),
36
+ "aria-atomic": tansu.readable("true"),
37
+ class: tansu.computed(() => extendedAlert.stores.className$())
38
+ },
39
+ classNames: {
40
+ "au-toast": utils_stores.true$,
41
+ toast: utils_stores.true$
42
+ }
43
+ }));
44
+ const closeButtonDirective = utils_directive.createAttributesDirective(() => ({
45
+ attributes: {
46
+ type: tansu.readable("button"),
47
+ "aria-label": tansu.computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
48
+ },
49
+ events: {
50
+ click: extendedAlert.api.close
51
+ }
52
+ }));
53
+ return {
54
+ ...extendedAlert,
55
+ directives: {
56
+ ...extendedAlert.directives,
57
+ autoHideDirective: utils_directive.directiveSubscribe(time$),
58
+ bodyDirective,
59
+ closeButtonDirective
60
+ }
61
+ };
62
+ });
63
+ const defaultToasterProps = {
64
+ duration: 5e3,
65
+ position: "bottomRight",
66
+ dismissible: false
67
+ };
68
+ class Toaster {
69
+ #idCount = 0;
70
+ #toasts = tansu.writable([]);
71
+ /**
72
+ * Get the toasts value from the store
73
+ * @returns The array of toasts.
74
+ */
75
+ toasts = tansu.computed(
76
+ () => this.#toasts().sort((a, b) => b.id - a.id).slice(0, this.options().limit)
77
+ );
78
+ options = tansu.writable(defaultToasterProps);
79
+ #timers = /* @__PURE__ */ new Map();
80
+ /**
81
+ * Get the timers value from the store
82
+ * @returns The map of timers.
83
+ */
84
+ get timers() {
85
+ return new Map(this.#timers);
86
+ }
87
+ constructor(props) {
88
+ this.options.set({
89
+ ...defaultToasterProps,
90
+ ...props
91
+ });
92
+ this.options.subscribe(() => {
93
+ this.updateToasts();
94
+ });
95
+ }
96
+ /**
97
+ * Add timer for a toast
98
+ * @param id Id of the toast
99
+ * @param duration Duration of the timer, by default taken from options
100
+ */
101
+ addTimer = (id, duration = this.options().duration) => {
102
+ if (duration > 0) {
103
+ this.#timers.set(id, {
104
+ timeout: setTimeout(() => this.removeToast(id), duration),
105
+ started: performance.now(),
106
+ duration
107
+ });
108
+ }
109
+ };
110
+ /**
111
+ * Pause a timer for a toast
112
+ * @param id Id of the toast
113
+ */
114
+ pauseTimer = (id) => {
115
+ if (this.#timers.has(id)) {
116
+ const timer = this.#timers.get(id);
117
+ if (timer && timer.timeout) {
118
+ clearTimeout(timer.timeout);
119
+ timer.timeout = null;
120
+ timer.paused = performance.now();
121
+ }
122
+ }
123
+ };
124
+ /**
125
+ * Resume a timer for a toast
126
+ * @param id Id of the toast
127
+ */
128
+ resumeTimer = (id) => {
129
+ if (this.#timers.has(id)) {
130
+ const timer = this.#timers.get(id);
131
+ if (timer) {
132
+ const paused = timer.paused ?? timer.started;
133
+ const elapsed = paused - timer.started;
134
+ const remaining = (timer.duration ?? 0) - elapsed;
135
+ this.addTimer(id, remaining);
136
+ timer.duration = remaining;
137
+ timer.paused = void 0;
138
+ }
139
+ }
140
+ };
141
+ /**
142
+ * Events directive is used to set events on the Toast component, to keep track for example of pointer enter/leave,
143
+ * used to pause / resume the timer in case of duration and pauseOnHover are specified.
144
+ */
145
+ eventsDirective = utils_directive.createAttributesDirective((id) => ({
146
+ events: {
147
+ pointerenter: () => this.options().pauseOnHover && this.pauseTimer(id()),
148
+ pointerleave: () => this.options().pauseOnHover && this.resumeTimer(id())
149
+ }
150
+ }));
151
+ /**
152
+ * Helper to add a toast to the viewport.
153
+ * @param props Options for the toast.
154
+ * @returns The ID of the added toast.
155
+ */
156
+ addToast = (props) => {
157
+ const autoHide = props.autoHide ?? this.options().duration > 0;
158
+ this.#toasts.update((toasts) => [...toasts, { id: this.#idCount++, props }]);
159
+ if (autoHide) {
160
+ this.addTimer(this.#idCount - 1, props.delay);
161
+ }
162
+ return this.#idCount - 1;
163
+ };
164
+ /**
165
+ * Helper to remove a toast to the viewport.
166
+ * @param id Id of the toast to remove.
167
+ */
168
+ removeToast = (id) => {
169
+ this.#timers.delete(id);
170
+ this.#toasts.update((toasts) => toasts.filter((toast) => toast.id !== id));
171
+ };
172
+ /** Helper to update toasts when options change */
173
+ updateToasts = () => {
174
+ if (this.options().duration === 0) {
175
+ this.options().dismissible = true;
176
+ }
177
+ };
178
+ /** Helper to close all toasts at once */
179
+ closeAll = () => {
180
+ this.#toasts.set([]);
181
+ this.#timers.clear();
182
+ };
183
+ }
184
+ exports.Toaster = Toaster;
185
+ exports.createToast = createToast;
186
+ exports.defaultToasterProps = defaultToasterProps;
187
+ exports.getToastDefaultConfig = getToastDefaultConfig;
@@ -0,0 +1,188 @@
1
+ import { computed, readable, writable } from "@amadeus-it-group/tansu";
2
+ import { extendWidgetProps } from "./services/extendWidget.js";
3
+ import { p as createAttributesDirective, d as directiveSubscribe } from "./dom-Bcg9ORcA.js";
4
+ import { true$ } from "./utils/stores.js";
5
+ import { b as typeNumberInRangeFactory, c as typeBoolean } from "./writables-e0tyaQpe.js";
6
+ import { g as getCommonAlertDefaultConfig, c as createCommonAlert } from "./common-DK0ADNTX.js";
7
+ import { createWidgetFactory } from "./utils/widget.js";
8
+ const toastDefaultConfig = {
9
+ autoHide: true,
10
+ delay: 5e3
11
+ };
12
+ const toastConfigValidator = {
13
+ autoHide: typeBoolean,
14
+ delay: typeNumberInRangeFactory(0, Infinity, { strict: true })
15
+ };
16
+ function getToastDefaultConfig() {
17
+ return { ...getCommonAlertDefaultConfig(), ...toastDefaultConfig };
18
+ }
19
+ const createToast = createWidgetFactory("toast", (config) => {
20
+ let _timeout;
21
+ const extendedAlert = extendWidgetProps(
22
+ createCommonAlert,
23
+ toastDefaultConfig,
24
+ toastConfigValidator
25
+ )(config);
26
+ const time$ = computed(() => {
27
+ clearTimeout(_timeout);
28
+ if (extendedAlert.stores.autoHide$()) {
29
+ _timeout = setTimeout(() => extendedAlert.api.close(), extendedAlert.stores.delay$());
30
+ }
31
+ });
32
+ const bodyDirective = createAttributesDirective(() => ({
33
+ attributes: {
34
+ role: readable("alert"),
35
+ "aria-atomic": readable("true"),
36
+ class: computed(() => extendedAlert.stores.className$())
37
+ },
38
+ classNames: {
39
+ "au-toast": true$,
40
+ toast: true$
41
+ }
42
+ }));
43
+ const closeButtonDirective = createAttributesDirective(() => ({
44
+ attributes: {
45
+ type: readable("button"),
46
+ "aria-label": computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
47
+ },
48
+ events: {
49
+ click: extendedAlert.api.close
50
+ }
51
+ }));
52
+ return {
53
+ ...extendedAlert,
54
+ directives: {
55
+ ...extendedAlert.directives,
56
+ autoHideDirective: directiveSubscribe(time$),
57
+ bodyDirective,
58
+ closeButtonDirective
59
+ }
60
+ };
61
+ });
62
+ const defaultToasterProps = {
63
+ duration: 5e3,
64
+ position: "bottomRight",
65
+ dismissible: false
66
+ };
67
+ class Toaster {
68
+ #idCount = 0;
69
+ #toasts = writable([]);
70
+ /**
71
+ * Get the toasts value from the store
72
+ * @returns The array of toasts.
73
+ */
74
+ toasts = computed(
75
+ () => this.#toasts().sort((a, b) => b.id - a.id).slice(0, this.options().limit)
76
+ );
77
+ options = writable(defaultToasterProps);
78
+ #timers = /* @__PURE__ */ new Map();
79
+ /**
80
+ * Get the timers value from the store
81
+ * @returns The map of timers.
82
+ */
83
+ get timers() {
84
+ return new Map(this.#timers);
85
+ }
86
+ constructor(props) {
87
+ this.options.set({
88
+ ...defaultToasterProps,
89
+ ...props
90
+ });
91
+ this.options.subscribe(() => {
92
+ this.updateToasts();
93
+ });
94
+ }
95
+ /**
96
+ * Add timer for a toast
97
+ * @param id Id of the toast
98
+ * @param duration Duration of the timer, by default taken from options
99
+ */
100
+ addTimer = (id, duration = this.options().duration) => {
101
+ if (duration > 0) {
102
+ this.#timers.set(id, {
103
+ timeout: setTimeout(() => this.removeToast(id), duration),
104
+ started: performance.now(),
105
+ duration
106
+ });
107
+ }
108
+ };
109
+ /**
110
+ * Pause a timer for a toast
111
+ * @param id Id of the toast
112
+ */
113
+ pauseTimer = (id) => {
114
+ if (this.#timers.has(id)) {
115
+ const timer = this.#timers.get(id);
116
+ if (timer && timer.timeout) {
117
+ clearTimeout(timer.timeout);
118
+ timer.timeout = null;
119
+ timer.paused = performance.now();
120
+ }
121
+ }
122
+ };
123
+ /**
124
+ * Resume a timer for a toast
125
+ * @param id Id of the toast
126
+ */
127
+ resumeTimer = (id) => {
128
+ if (this.#timers.has(id)) {
129
+ const timer = this.#timers.get(id);
130
+ if (timer) {
131
+ const paused = timer.paused ?? timer.started;
132
+ const elapsed = paused - timer.started;
133
+ const remaining = (timer.duration ?? 0) - elapsed;
134
+ this.addTimer(id, remaining);
135
+ timer.duration = remaining;
136
+ timer.paused = void 0;
137
+ }
138
+ }
139
+ };
140
+ /**
141
+ * Events directive is used to set events on the Toast component, to keep track for example of pointer enter/leave,
142
+ * used to pause / resume the timer in case of duration and pauseOnHover are specified.
143
+ */
144
+ eventsDirective = createAttributesDirective((id) => ({
145
+ events: {
146
+ pointerenter: () => this.options().pauseOnHover && this.pauseTimer(id()),
147
+ pointerleave: () => this.options().pauseOnHover && this.resumeTimer(id())
148
+ }
149
+ }));
150
+ /**
151
+ * Helper to add a toast to the viewport.
152
+ * @param props Options for the toast.
153
+ * @returns The ID of the added toast.
154
+ */
155
+ addToast = (props) => {
156
+ const autoHide = props.autoHide ?? this.options().duration > 0;
157
+ this.#toasts.update((toasts) => [...toasts, { id: this.#idCount++, props }]);
158
+ if (autoHide) {
159
+ this.addTimer(this.#idCount - 1, props.delay);
160
+ }
161
+ return this.#idCount - 1;
162
+ };
163
+ /**
164
+ * Helper to remove a toast to the viewport.
165
+ * @param id Id of the toast to remove.
166
+ */
167
+ removeToast = (id) => {
168
+ this.#timers.delete(id);
169
+ this.#toasts.update((toasts) => toasts.filter((toast) => toast.id !== id));
170
+ };
171
+ /** Helper to update toasts when options change */
172
+ updateToasts = () => {
173
+ if (this.options().duration === 0) {
174
+ this.options().dismissible = true;
175
+ }
176
+ };
177
+ /** Helper to close all toasts at once */
178
+ closeAll = () => {
179
+ this.#toasts.set([]);
180
+ this.#timers.clear();
181
+ };
182
+ }
183
+ export {
184
+ Toaster as T,
185
+ createToast as c,
186
+ defaultToasterProps as d,
187
+ getToastDefaultConfig as g
188
+ };