@design-factory/core 21.1.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.
- package/README.md +3 -0
- package/accordion-B0vs8JWM.cjs +314 -0
- package/accordion-D9ba0XYq.js +315 -0
- package/alert-AhaliJ17.cjs +9 -0
- package/alert-Cb9FhbFQ.js +10 -0
- package/collapse-Bn8iHKrd.js +95 -0
- package/collapse-BnWw4Hnc.cjs +94 -0
- package/common-B5jS-Ih_.cjs +73 -0
- package/common-DFyZvkII.js +74 -0
- package/components/accordion/accordion.d.ts +333 -0
- package/components/accordion/index.cjs +7 -0
- package/components/accordion/index.d.ts +1 -0
- package/components/accordion/index.js +7 -0
- package/components/alert/alert.d.ts +37 -0
- package/components/alert/common.d.ts +138 -0
- package/components/alert/index.cjs +5 -0
- package/components/alert/index.d.ts +1 -0
- package/components/alert/index.js +5 -0
- package/components/carousel/carousel.d.ts +247 -0
- package/components/carousel/index.cjs +292 -0
- package/components/carousel/index.d.ts +1 -0
- package/components/carousel/index.js +292 -0
- package/components/collapse/collapse.d.ts +135 -0
- package/components/collapse/index.cjs +5 -0
- package/components/collapse/index.d.ts +1 -0
- package/components/collapse/index.js +5 -0
- package/components/commonProps.d.ts +11 -0
- package/components/drawer/drawer.d.ts +279 -0
- package/components/drawer/index.cjs +5 -0
- package/components/drawer/index.d.ts +1 -0
- package/components/drawer/index.js +5 -0
- package/components/modal/index.cjs +8 -0
- package/components/modal/index.d.ts +1 -0
- package/components/modal/index.js +8 -0
- package/components/modal/modal.d.ts +245 -0
- package/components/pagination/index.cjs +5 -0
- package/components/pagination/index.d.ts +1 -0
- package/components/pagination/index.js +5 -0
- package/components/pagination/pagination.d.ts +313 -0
- package/components/progressbar/index.cjs +5 -0
- package/components/progressbar/index.d.ts +1 -0
- package/components/progressbar/index.js +5 -0
- package/components/progressbar/progressbar.d.ts +91 -0
- package/components/rating/index.cjs +5 -0
- package/components/rating/index.d.ts +1 -0
- package/components/rating/index.js +5 -0
- package/components/rating/rating.d.ts +191 -0
- package/components/slider/index.cjs +5 -0
- package/components/slider/index.d.ts +1 -0
- package/components/slider/index.js +5 -0
- package/components/slider/slider-utils.d.ts +25 -0
- package/components/slider/slider.d.ts +383 -0
- package/components/toast/index.cjs +7 -0
- package/components/toast/index.d.ts +2 -0
- package/components/toast/index.js +7 -0
- package/components/toast/toast.d.ts +66 -0
- package/components/toast/toaster.d.ts +128 -0
- package/components/tree/index.cjs +5 -0
- package/components/tree/index.d.ts +1 -0
- package/components/tree/index.js +5 -0
- package/components/tree/tree.d.ts +143 -0
- package/config.cjs +36 -0
- package/config.d.ts +117 -0
- package/config.js +36 -0
- package/directive-CNNSo5Yn.js +524 -0
- package/directive-DyTodNPd.cjs +523 -0
- package/drawer-BIIfJa0F.js +329 -0
- package/drawer-C8ojtwIn.cjs +328 -0
- package/index.cjs +134 -0
- package/index.d.ts +29 -0
- package/index.js +134 -0
- package/isFocusable-Ckwus82R.js +32 -0
- package/isFocusable-DfzDLeAN.cjs +31 -0
- package/modal-C13G13jV.js +253 -0
- package/modal-DWv0VqiG.cjs +252 -0
- package/package.json +56 -0
- package/pagination-BLVa1UsZ.cjs +254 -0
- package/pagination-BQWusWXN.js +255 -0
- package/progressbar-RopgvVeA.cjs +86 -0
- package/progressbar-S1pNn5rM.js +87 -0
- package/promise-CxCD3NYv.cjs +118 -0
- package/promise-D-RZVPuv.js +119 -0
- package/rating-DWgGgwk3.js +184 -0
- package/rating-DZ3OQgtt.cjs +183 -0
- package/scrollbars-CT87iv_6.cjs +30 -0
- package/scrollbars-CcxSrnCx.js +31 -0
- package/services/extendWidget.cjs +41 -0
- package/services/extendWidget.d.ts +31 -0
- package/services/extendWidget.js +41 -0
- package/services/floatingUI.cjs +111 -0
- package/services/floatingUI.d.ts +76 -0
- package/services/floatingUI.js +111 -0
- package/services/focusElement.cjs +46 -0
- package/services/focusElement.d.ts +9 -0
- package/services/focusElement.js +46 -0
- package/services/focustrack.cjs +47 -0
- package/services/focustrack.d.ts +40 -0
- package/services/focustrack.js +47 -0
- package/services/hash.cjs +15 -0
- package/services/hash.d.ts +3 -0
- package/services/hash.js +15 -0
- package/services/intersection.cjs +53 -0
- package/services/intersection.d.ts +30 -0
- package/services/intersection.js +53 -0
- package/services/matchMedia.cjs +14 -0
- package/services/matchMedia.d.ts +8 -0
- package/services/matchMedia.js +14 -0
- package/services/navManager.cjs +166 -0
- package/services/navManager.d.ts +144 -0
- package/services/navManager.js +166 -0
- package/services/pointerdownPosition.cjs +60 -0
- package/services/pointerdownPosition.d.ts +42 -0
- package/services/pointerdownPosition.js +60 -0
- package/services/portal.cjs +42 -0
- package/services/portal.d.ts +16 -0
- package/services/portal.js +42 -0
- package/services/resizeObserver.cjs +54 -0
- package/services/resizeObserver.d.ts +18 -0
- package/services/resizeObserver.js +54 -0
- package/services/siblingsInert.cjs +44 -0
- package/services/siblingsInert.d.ts +16 -0
- package/services/siblingsInert.js +44 -0
- package/services/transitions/baseTransitions.cjs +186 -0
- package/services/transitions/baseTransitions.d.ts +166 -0
- package/services/transitions/baseTransitions.js +186 -0
- package/services/transitions/collapse.cjs +40 -0
- package/services/transitions/collapse.d.ts +49 -0
- package/services/transitions/collapse.js +40 -0
- package/services/transitions/cssTransitions.cjs +32 -0
- package/services/transitions/cssTransitions.d.ts +25 -0
- package/services/transitions/cssTransitions.js +32 -0
- package/services/transitions/simpleClassTransition.cjs +37 -0
- package/services/transitions/simpleClassTransition.d.ts +47 -0
- package/services/transitions/simpleClassTransition.js +37 -0
- package/slider-Br_Qiopx.js +808 -0
- package/slider-pgDq1V5r.cjs +807 -0
- package/textDirection-cNgt24LJ.js +4 -0
- package/textDirection-zqcZ5-eK.cjs +3 -0
- package/toaster-BUBzFeJM.js +162 -0
- package/toaster-Dlube4Ya.cjs +161 -0
- package/tree-Chcy4ulJ.cjs +228 -0
- package/tree-vD7ZkV8Z.js +229 -0
- package/types.cjs +6 -0
- package/types.d.ts +246 -0
- package/types.js +6 -0
- package/utils/directive.cjs +28 -0
- package/utils/directive.d.ts +352 -0
- package/utils/directive.js +28 -0
- package/utils/func.cjs +7 -0
- package/utils/func.d.ts +11 -0
- package/utils/func.js +7 -0
- package/utils/id.cjs +5 -0
- package/utils/id.d.ts +6 -0
- package/utils/id.js +5 -0
- package/utils/internal/assign.d.ts +10 -0
- package/utils/internal/checks.d.ts +57 -0
- package/utils/internal/dom.d.ts +75 -0
- package/utils/internal/isFocusable.d.ts +9 -0
- package/utils/internal/math.d.ts +5 -0
- package/utils/internal/promise.d.ts +98 -0
- package/utils/internal/scrollbars.d.ts +8 -0
- package/utils/internal/sort.d.ts +16 -0
- package/utils/internal/ssrHTMLElement.d.ts +17 -0
- package/utils/internal/textDirection.d.ts +7 -0
- package/utils/internal/traversal.d.ts +54 -0
- package/utils/stores.cjs +172 -0
- package/utils/stores.d.ts +224 -0
- package/utils/stores.js +172 -0
- package/utils/widget.cjs +8 -0
- package/utils/widget.d.ts +11 -0
- package/utils/widget.js +8 -0
- package/utils/writables.cjs +16 -0
- package/utils/writables.d.ts +95 -0
- package/utils/writables.js +16 -0
- package/writables-DYGjj5T3.js +103 -0
- package/writables-Dt68gADJ.cjs +102 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { computed, readable, writable } from "@amadeus-it-group/tansu";
|
|
2
|
+
import { extendWidgetProps } from "./services/extendWidget.js";
|
|
3
|
+
import { o as directiveSubscribe, g as createAttributesDirective } from "./directive-CNNSo5Yn.js";
|
|
4
|
+
import { true$ } from "./utils/stores.js";
|
|
5
|
+
import { h as typeNumberInRangeFactory, b as typeBoolean } from "./writables-DYGjj5T3.js";
|
|
6
|
+
import { g as getCommonAlertDefaultConfig, c as createCommonAlert } from "./common-DFyZvkII.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(
|
|
20
|
+
"toast",
|
|
21
|
+
(config) => {
|
|
22
|
+
let _timeout;
|
|
23
|
+
const extendedAlert = extendWidgetProps(
|
|
24
|
+
createCommonAlert,
|
|
25
|
+
toastDefaultConfig,
|
|
26
|
+
toastConfigValidator
|
|
27
|
+
)(config);
|
|
28
|
+
const time$ = computed(() => {
|
|
29
|
+
clearTimeout(_timeout);
|
|
30
|
+
if (extendedAlert.stores.autoHide$()) {
|
|
31
|
+
_timeout = setTimeout(() => void extendedAlert.api.close(), extendedAlert.stores.delay$());
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const bodyDirective = createAttributesDirective(() => ({
|
|
35
|
+
attributes: {
|
|
36
|
+
role: readable("alert"),
|
|
37
|
+
"aria-atomic": readable("true"),
|
|
38
|
+
class: computed(() => extendedAlert.stores.className$())
|
|
39
|
+
},
|
|
40
|
+
classNames: {
|
|
41
|
+
"au-toast": true$,
|
|
42
|
+
toast: true$
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
const closeButtonDirective = createAttributesDirective(() => ({
|
|
46
|
+
attributes: {
|
|
47
|
+
type: readable("button"),
|
|
48
|
+
"aria-label": computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
|
|
49
|
+
},
|
|
50
|
+
events: {
|
|
51
|
+
click: () => void extendedAlert.api.close()
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
return {
|
|
55
|
+
...extendedAlert,
|
|
56
|
+
directives: {
|
|
57
|
+
...extendedAlert.directives,
|
|
58
|
+
autoHideDirective: directiveSubscribe(time$),
|
|
59
|
+
bodyDirective,
|
|
60
|
+
closeButtonDirective
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
const defaultToasterProps = {
|
|
66
|
+
duration: 5e3,
|
|
67
|
+
position: "bottomRight",
|
|
68
|
+
dismissible: false
|
|
69
|
+
};
|
|
70
|
+
class Toaster {
|
|
71
|
+
constructor(props) {
|
|
72
|
+
this.#idCount = 0;
|
|
73
|
+
this.#toasts = writable([]);
|
|
74
|
+
this.toasts = computed(
|
|
75
|
+
() => this.#toasts().sort((a, b) => b.id - a.id).slice(0, this.options().limit)
|
|
76
|
+
);
|
|
77
|
+
this.options = writable(defaultToasterProps);
|
|
78
|
+
this.#timers = /* @__PURE__ */ new Map();
|
|
79
|
+
this.addTimer = (id, duration = this.options().duration) => {
|
|
80
|
+
if (duration > 0) {
|
|
81
|
+
this.#timers.set(id, {
|
|
82
|
+
timeout: setTimeout(() => this.removeToast(id), duration),
|
|
83
|
+
started: performance.now(),
|
|
84
|
+
duration
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
this.pauseTimer = (id) => {
|
|
89
|
+
if (this.#timers.has(id)) {
|
|
90
|
+
const timer = this.#timers.get(id);
|
|
91
|
+
if (timer && timer.timeout) {
|
|
92
|
+
clearTimeout(timer.timeout);
|
|
93
|
+
timer.timeout = null;
|
|
94
|
+
timer.paused = performance.now();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
this.resumeTimer = (id) => {
|
|
99
|
+
if (this.#timers.has(id)) {
|
|
100
|
+
const timer = this.#timers.get(id);
|
|
101
|
+
if (timer) {
|
|
102
|
+
const paused = timer.paused ?? timer.started;
|
|
103
|
+
const elapsed = paused - timer.started;
|
|
104
|
+
const remaining = (timer.duration ?? 0) - elapsed;
|
|
105
|
+
this.addTimer(id, remaining);
|
|
106
|
+
timer.duration = remaining;
|
|
107
|
+
timer.paused = void 0;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
this.eventsDirective = createAttributesDirective((id) => ({
|
|
112
|
+
events: {
|
|
113
|
+
pointerenter: () => this.options().pauseOnHover && this.pauseTimer(id()),
|
|
114
|
+
pointerleave: () => this.options().pauseOnHover && this.resumeTimer(id())
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
this.addToast = (props2) => {
|
|
118
|
+
const autoHide = props2.autoHide ?? this.options().duration > 0;
|
|
119
|
+
this.#toasts.update((toasts) => [...toasts, { id: this.#idCount++, props: props2 }]);
|
|
120
|
+
if (autoHide) {
|
|
121
|
+
this.addTimer(this.#idCount - 1, props2.delay);
|
|
122
|
+
}
|
|
123
|
+
return this.#idCount - 1;
|
|
124
|
+
};
|
|
125
|
+
this.removeToast = (id) => {
|
|
126
|
+
this.#timers.delete(id);
|
|
127
|
+
this.#toasts.update((toasts) => toasts.filter((toast) => toast.id !== id));
|
|
128
|
+
};
|
|
129
|
+
this.updateToasts = () => {
|
|
130
|
+
if (this.options().duration === 0) {
|
|
131
|
+
this.options().dismissible = true;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
this.closeAll = () => {
|
|
135
|
+
this.#toasts.set([]);
|
|
136
|
+
this.#timers.clear();
|
|
137
|
+
};
|
|
138
|
+
this.options.set({
|
|
139
|
+
...defaultToasterProps,
|
|
140
|
+
...props
|
|
141
|
+
});
|
|
142
|
+
this.options.subscribe(() => {
|
|
143
|
+
this.updateToasts();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
#idCount;
|
|
147
|
+
#toasts;
|
|
148
|
+
#timers;
|
|
149
|
+
/**
|
|
150
|
+
* Get the timers value from the store
|
|
151
|
+
* @returns The map of timers.
|
|
152
|
+
*/
|
|
153
|
+
get timers() {
|
|
154
|
+
return new Map(this.#timers);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
Toaster as T,
|
|
159
|
+
createToast as c,
|
|
160
|
+
defaultToasterProps as d,
|
|
161
|
+
getToastDefaultConfig as g
|
|
162
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
3
|
+
const services_extendWidget = require("./services/extendWidget.cjs");
|
|
4
|
+
const utils_directive = require("./directive-DyTodNPd.cjs");
|
|
5
|
+
const utils_stores = require("./utils/stores.cjs");
|
|
6
|
+
const utils_writables = require("./writables-Dt68gADJ.cjs");
|
|
7
|
+
const common = require("./common-B5jS-Ih_.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(
|
|
21
|
+
"toast",
|
|
22
|
+
(config) => {
|
|
23
|
+
let _timeout;
|
|
24
|
+
const extendedAlert = services_extendWidget.extendWidgetProps(
|
|
25
|
+
common.createCommonAlert,
|
|
26
|
+
toastDefaultConfig,
|
|
27
|
+
toastConfigValidator
|
|
28
|
+
)(config);
|
|
29
|
+
const time$ = tansu.computed(() => {
|
|
30
|
+
clearTimeout(_timeout);
|
|
31
|
+
if (extendedAlert.stores.autoHide$()) {
|
|
32
|
+
_timeout = setTimeout(() => void extendedAlert.api.close(), extendedAlert.stores.delay$());
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const bodyDirective = utils_directive.createAttributesDirective(() => ({
|
|
36
|
+
attributes: {
|
|
37
|
+
role: tansu.readable("alert"),
|
|
38
|
+
"aria-atomic": tansu.readable("true"),
|
|
39
|
+
class: tansu.computed(() => extendedAlert.stores.className$())
|
|
40
|
+
},
|
|
41
|
+
classNames: {
|
|
42
|
+
"au-toast": utils_stores.true$,
|
|
43
|
+
toast: utils_stores.true$
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
const closeButtonDirective = utils_directive.createAttributesDirective(() => ({
|
|
47
|
+
attributes: {
|
|
48
|
+
type: tansu.readable("button"),
|
|
49
|
+
"aria-label": tansu.computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
|
|
50
|
+
},
|
|
51
|
+
events: {
|
|
52
|
+
click: () => void extendedAlert.api.close()
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
return {
|
|
56
|
+
...extendedAlert,
|
|
57
|
+
directives: {
|
|
58
|
+
...extendedAlert.directives,
|
|
59
|
+
autoHideDirective: utils_directive.directiveSubscribe(time$),
|
|
60
|
+
bodyDirective,
|
|
61
|
+
closeButtonDirective
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
const defaultToasterProps = {
|
|
67
|
+
duration: 5e3,
|
|
68
|
+
position: "bottomRight",
|
|
69
|
+
dismissible: false
|
|
70
|
+
};
|
|
71
|
+
class Toaster {
|
|
72
|
+
constructor(props) {
|
|
73
|
+
this.#idCount = 0;
|
|
74
|
+
this.#toasts = tansu.writable([]);
|
|
75
|
+
this.toasts = tansu.computed(
|
|
76
|
+
() => this.#toasts().sort((a, b) => b.id - a.id).slice(0, this.options().limit)
|
|
77
|
+
);
|
|
78
|
+
this.options = tansu.writable(defaultToasterProps);
|
|
79
|
+
this.#timers = /* @__PURE__ */ new Map();
|
|
80
|
+
this.addTimer = (id, duration = this.options().duration) => {
|
|
81
|
+
if (duration > 0) {
|
|
82
|
+
this.#timers.set(id, {
|
|
83
|
+
timeout: setTimeout(() => this.removeToast(id), duration),
|
|
84
|
+
started: performance.now(),
|
|
85
|
+
duration
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
this.pauseTimer = (id) => {
|
|
90
|
+
if (this.#timers.has(id)) {
|
|
91
|
+
const timer = this.#timers.get(id);
|
|
92
|
+
if (timer && timer.timeout) {
|
|
93
|
+
clearTimeout(timer.timeout);
|
|
94
|
+
timer.timeout = null;
|
|
95
|
+
timer.paused = performance.now();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
this.resumeTimer = (id) => {
|
|
100
|
+
if (this.#timers.has(id)) {
|
|
101
|
+
const timer = this.#timers.get(id);
|
|
102
|
+
if (timer) {
|
|
103
|
+
const paused = timer.paused ?? timer.started;
|
|
104
|
+
const elapsed = paused - timer.started;
|
|
105
|
+
const remaining = (timer.duration ?? 0) - elapsed;
|
|
106
|
+
this.addTimer(id, remaining);
|
|
107
|
+
timer.duration = remaining;
|
|
108
|
+
timer.paused = void 0;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
this.eventsDirective = utils_directive.createAttributesDirective((id) => ({
|
|
113
|
+
events: {
|
|
114
|
+
pointerenter: () => this.options().pauseOnHover && this.pauseTimer(id()),
|
|
115
|
+
pointerleave: () => this.options().pauseOnHover && this.resumeTimer(id())
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
this.addToast = (props2) => {
|
|
119
|
+
const autoHide = props2.autoHide ?? this.options().duration > 0;
|
|
120
|
+
this.#toasts.update((toasts) => [...toasts, { id: this.#idCount++, props: props2 }]);
|
|
121
|
+
if (autoHide) {
|
|
122
|
+
this.addTimer(this.#idCount - 1, props2.delay);
|
|
123
|
+
}
|
|
124
|
+
return this.#idCount - 1;
|
|
125
|
+
};
|
|
126
|
+
this.removeToast = (id) => {
|
|
127
|
+
this.#timers.delete(id);
|
|
128
|
+
this.#toasts.update((toasts) => toasts.filter((toast) => toast.id !== id));
|
|
129
|
+
};
|
|
130
|
+
this.updateToasts = () => {
|
|
131
|
+
if (this.options().duration === 0) {
|
|
132
|
+
this.options().dismissible = true;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
this.closeAll = () => {
|
|
136
|
+
this.#toasts.set([]);
|
|
137
|
+
this.#timers.clear();
|
|
138
|
+
};
|
|
139
|
+
this.options.set({
|
|
140
|
+
...defaultToasterProps,
|
|
141
|
+
...props
|
|
142
|
+
});
|
|
143
|
+
this.options.subscribe(() => {
|
|
144
|
+
this.updateToasts();
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
#idCount;
|
|
148
|
+
#toasts;
|
|
149
|
+
#timers;
|
|
150
|
+
/**
|
|
151
|
+
* Get the timers value from the store
|
|
152
|
+
* @returns The map of timers.
|
|
153
|
+
*/
|
|
154
|
+
get timers() {
|
|
155
|
+
return new Map(this.#timers);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.Toaster = Toaster;
|
|
159
|
+
exports.createToast = createToast;
|
|
160
|
+
exports.defaultToasterProps = defaultToasterProps;
|
|
161
|
+
exports.getToastDefaultConfig = getToastDefaultConfig;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
3
|
+
const services_navManager = require("./services/navManager.cjs");
|
|
4
|
+
const utils_directive = require("./directive-DyTodNPd.cjs");
|
|
5
|
+
const utils_func = require("./utils/func.cjs");
|
|
6
|
+
const utils_stores = require("./utils/stores.cjs");
|
|
7
|
+
const utils_writables = require("./writables-Dt68gADJ.cjs");
|
|
8
|
+
const utils_widget = require("./utils/widget.cjs");
|
|
9
|
+
function getTreeDefaultConfig() {
|
|
10
|
+
return {
|
|
11
|
+
...defaultTreeConfig
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const defaultTreeConfig = {
|
|
15
|
+
className: "",
|
|
16
|
+
nodes: [],
|
|
17
|
+
onExpandToggle: utils_func.noop,
|
|
18
|
+
navSelector: (node) => node.querySelectorAll("button"),
|
|
19
|
+
ariaLabelToggleFn: (label) => `Toggle ${label}`
|
|
20
|
+
};
|
|
21
|
+
const configValidator = {
|
|
22
|
+
className: utils_writables.typeString,
|
|
23
|
+
nodes: utils_writables.typeArray,
|
|
24
|
+
onExpandToggle: utils_writables.typeFunction,
|
|
25
|
+
navSelector: utils_writables.typeFunction,
|
|
26
|
+
ariaLabelToggleFn: utils_writables.typeFunction
|
|
27
|
+
};
|
|
28
|
+
const createTree = utils_widget.createWidgetFactory("tree", (config) => {
|
|
29
|
+
const [{ nodes$, onExpandToggle$, navSelector$, ariaLabelToggleFn$, ...stateProps }, patch] = utils_stores.writablesForProps(
|
|
30
|
+
defaultTreeConfig,
|
|
31
|
+
config,
|
|
32
|
+
configValidator
|
|
33
|
+
);
|
|
34
|
+
const treeMap = /* @__PURE__ */ new Map();
|
|
35
|
+
const _expandedMap = {
|
|
36
|
+
get(item) {
|
|
37
|
+
return item.isExpanded;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const _toggleChange$ = tansu.writable({});
|
|
41
|
+
const expandedMap$ = tansu.computed(() => {
|
|
42
|
+
normalizedNodes$();
|
|
43
|
+
_toggleChange$();
|
|
44
|
+
return _expandedMap;
|
|
45
|
+
});
|
|
46
|
+
const {
|
|
47
|
+
elementsInDomOrder$,
|
|
48
|
+
directive: navDirective,
|
|
49
|
+
refreshElements,
|
|
50
|
+
focusIndex,
|
|
51
|
+
focusPrevious,
|
|
52
|
+
focusNext,
|
|
53
|
+
focusFirst,
|
|
54
|
+
focusLast
|
|
55
|
+
} = services_navManager.createNavManager();
|
|
56
|
+
const navManagerConfig$ = tansu.computed(() => ({
|
|
57
|
+
keys: {
|
|
58
|
+
ArrowUp: focusPrevious,
|
|
59
|
+
ArrowDown: focusNext,
|
|
60
|
+
Home: focusFirst,
|
|
61
|
+
End: focusLast
|
|
62
|
+
},
|
|
63
|
+
selector: navSelector$()
|
|
64
|
+
}));
|
|
65
|
+
const traverseTree = (node, level, parent) => {
|
|
66
|
+
const copyNode = {
|
|
67
|
+
...node,
|
|
68
|
+
ariaLabel: node.ariaLabel ?? node.label,
|
|
69
|
+
level,
|
|
70
|
+
children: [],
|
|
71
|
+
isExpanded: node.children?.length ? node.isExpanded ?? false : void 0
|
|
72
|
+
};
|
|
73
|
+
treeMap.set(copyNode, {
|
|
74
|
+
parent
|
|
75
|
+
});
|
|
76
|
+
if (node.children) {
|
|
77
|
+
copyNode.children = node.children.map((child) => traverseTree(child, level + 1, copyNode));
|
|
78
|
+
}
|
|
79
|
+
return copyNode;
|
|
80
|
+
};
|
|
81
|
+
const normalizedNodes$ = tansu.computed(() => {
|
|
82
|
+
treeMap.clear();
|
|
83
|
+
return nodes$().map((node) => traverseTree(node, 0, void 0));
|
|
84
|
+
});
|
|
85
|
+
const _lastFocusedTreeItem$ = tansu.writable(
|
|
86
|
+
normalizedNodes$().find((node) => node.isExpanded !== void 0)
|
|
87
|
+
);
|
|
88
|
+
const getTreeItemInfo = (item) => {
|
|
89
|
+
const treeItem = treeMap.get(item);
|
|
90
|
+
if (!treeItem) {
|
|
91
|
+
console.error(`Node ${item.label} doesn't exist in the map`);
|
|
92
|
+
}
|
|
93
|
+
return treeItem;
|
|
94
|
+
};
|
|
95
|
+
const treeItemElementDirective = utils_directive.browserDirective(
|
|
96
|
+
(toggleItem, args) => {
|
|
97
|
+
let treeItemInfo;
|
|
98
|
+
const destroy = () => {
|
|
99
|
+
if (treeItemInfo && treeItemInfo.htmlElement === toggleItem) {
|
|
100
|
+
treeItemInfo.htmlElement = void 0;
|
|
101
|
+
}
|
|
102
|
+
treeItemInfo = void 0;
|
|
103
|
+
};
|
|
104
|
+
const update = (args2) => {
|
|
105
|
+
destroy();
|
|
106
|
+
treeItemInfo = getTreeItemInfo(args2.item);
|
|
107
|
+
if (treeItemInfo) {
|
|
108
|
+
if (treeItemInfo.htmlElement) {
|
|
109
|
+
console.warn(`The tree item directive should be used once per element`);
|
|
110
|
+
}
|
|
111
|
+
treeItemInfo.htmlElement = toggleItem;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
update(args);
|
|
115
|
+
return {
|
|
116
|
+
update,
|
|
117
|
+
destroy
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
const focusElementIfExists = (itemToFocus) => {
|
|
122
|
+
if (itemToFocus) {
|
|
123
|
+
const mapItemHtml = getTreeItemInfo(itemToFocus)?.htmlElement;
|
|
124
|
+
if (mapItemHtml) {
|
|
125
|
+
const index = elementsInDomOrder$().indexOf(mapItemHtml);
|
|
126
|
+
focusIndex(index, 0);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const itemToggleAttributesDirective = utils_directive.createAttributesDirective(
|
|
131
|
+
(treeItemContext$) => ({
|
|
132
|
+
events: {
|
|
133
|
+
focus: () => {
|
|
134
|
+
const { item } = treeItemContext$();
|
|
135
|
+
_lastFocusedTreeItem$.set(item);
|
|
136
|
+
},
|
|
137
|
+
click: () => {
|
|
138
|
+
const { item } = treeItemContext$();
|
|
139
|
+
toggleExpanded(item);
|
|
140
|
+
},
|
|
141
|
+
keydown: (event) => {
|
|
142
|
+
const { key } = event;
|
|
143
|
+
const { item } = treeItemContext$();
|
|
144
|
+
const isExpanded = item.isExpanded;
|
|
145
|
+
refreshElements();
|
|
146
|
+
switch (key) {
|
|
147
|
+
case "Enter":
|
|
148
|
+
case " ":
|
|
149
|
+
toggleExpanded(item);
|
|
150
|
+
break;
|
|
151
|
+
case "ArrowLeft":
|
|
152
|
+
if (isExpanded) {
|
|
153
|
+
toggleExpanded(item);
|
|
154
|
+
} else {
|
|
155
|
+
focusElementIfExists(getTreeItemInfo(item)?.parent);
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case "ArrowRight":
|
|
159
|
+
if (!isExpanded) {
|
|
160
|
+
toggleExpanded(item);
|
|
161
|
+
} else {
|
|
162
|
+
focusElementIfExists(item.children?.[0]);
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
default:
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
event.stopPropagation();
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
attributes: {
|
|
173
|
+
"aria-label": tansu.computed(() => {
|
|
174
|
+
const { item } = treeItemContext$();
|
|
175
|
+
return ariaLabelToggleFn$()(item.ariaLabel);
|
|
176
|
+
}),
|
|
177
|
+
tabindex: tansu.computed(() => {
|
|
178
|
+
const { item } = treeItemContext$();
|
|
179
|
+
return item === _lastFocusedTreeItem$() ? "0" : "-1";
|
|
180
|
+
}),
|
|
181
|
+
type: tansu.readable("button")
|
|
182
|
+
},
|
|
183
|
+
classNames: {
|
|
184
|
+
"au-tree-expand-icon": utils_stores.true$,
|
|
185
|
+
"au-tree-expand-icon-expanded": tansu.computed(() => {
|
|
186
|
+
_toggleChange$();
|
|
187
|
+
const { item } = treeItemContext$();
|
|
188
|
+
return item.isExpanded ?? false;
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
const toggleExpanded = (node) => {
|
|
194
|
+
const treeItemInfo = getTreeItemInfo(node);
|
|
195
|
+
if (treeItemInfo === void 0 || node.isExpanded === void 0) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
node.isExpanded = !node.isExpanded;
|
|
199
|
+
_toggleChange$.set({});
|
|
200
|
+
onExpandToggle$()(node);
|
|
201
|
+
};
|
|
202
|
+
const widget = {
|
|
203
|
+
...utils_stores.stateStores({ normalizedNodes$, expandedMap$, ...stateProps }),
|
|
204
|
+
patch,
|
|
205
|
+
api: {},
|
|
206
|
+
directives: {
|
|
207
|
+
navigationDirective: utils_directive.bindDirective(navDirective, navManagerConfig$),
|
|
208
|
+
itemToggleDirective: utils_directive.mergeDirectives(treeItemElementDirective, itemToggleAttributesDirective),
|
|
209
|
+
itemAttributesDirective: utils_directive.createAttributesDirective(
|
|
210
|
+
(treeItemContext$) => ({
|
|
211
|
+
attributes: {
|
|
212
|
+
role: tansu.readable("treeitem"),
|
|
213
|
+
"aria-selected": tansu.readable("false"),
|
|
214
|
+
// TODO: adapt aria-selected to the actual selected state
|
|
215
|
+
"aria-expanded": tansu.computed(() => {
|
|
216
|
+
const { item } = treeItemContext$();
|
|
217
|
+
_toggleChange$();
|
|
218
|
+
return item.isExpanded?.toString();
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
return widget;
|
|
226
|
+
});
|
|
227
|
+
exports.createTree = createTree;
|
|
228
|
+
exports.getTreeDefaultConfig = getTreeDefaultConfig;
|