@agnos-ui/core 0.2.0 → 0.3.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 (143) hide show
  1. package/README.md +3 -3
  2. package/accordion-BaWN0_n-.js +330 -0
  3. package/accordion-BuIgxZ0S.cjs +329 -0
  4. package/alert-C4jCg9Pl.cjs +8 -0
  5. package/alert-Dlf-BV98.js +9 -0
  6. package/common-DRdsw5m8.js +76 -0
  7. package/common-nJRMXbwj.cjs +75 -0
  8. package/components/accordion/accordion.d.ts +38 -49
  9. package/components/accordion/index.cjs +7 -0
  10. package/components/accordion/index.js +7 -1
  11. package/components/alert/alert.d.ts +3 -12
  12. package/components/alert/common.d.ts +4 -13
  13. package/components/alert/index.cjs +10 -0
  14. package/components/alert/index.js +10 -2
  15. package/components/modal/index.cjs +7 -0
  16. package/components/modal/index.js +7 -1
  17. package/components/modal/modal.d.ts +7 -49
  18. package/components/pagination/index.cjs +5 -0
  19. package/components/pagination/index.d.ts +0 -1
  20. package/components/pagination/index.js +5 -2
  21. package/components/pagination/pagination.d.ts +68 -139
  22. package/components/progressbar/index.cjs +5 -0
  23. package/components/progressbar/index.js +5 -1
  24. package/components/progressbar/progressbar.d.ts +6 -22
  25. package/components/rating/index.cjs +5 -0
  26. package/components/rating/index.js +5 -1
  27. package/components/rating/rating.d.ts +16 -11
  28. package/components/select/index.cjs +6 -0
  29. package/components/select/index.js +6 -1
  30. package/components/select/select.d.ts +15 -33
  31. package/components/slider/index.cjs +5 -0
  32. package/components/slider/index.js +5 -1
  33. package/components/slider/slider.d.ts +29 -35
  34. package/components/toast/index.cjs +5 -0
  35. package/components/toast/index.js +5 -1
  36. package/components/toast/toast.d.ts +11 -8
  37. package/config.cjs +38 -0
  38. package/config.d.ts +1 -1
  39. package/config.js +35 -50
  40. package/directive-BTSEYLF3.cjs +404 -0
  41. package/directive-DCYlDznf.js +405 -0
  42. package/func-DR0n-ShK.js +7 -0
  43. package/func-Qd3cD9a3.cjs +6 -0
  44. package/index.cjs +119 -0
  45. package/index.d.ts +1 -1
  46. package/index.js +119 -33
  47. package/modal-BI2qUu1M.js +251 -0
  48. package/modal-rzMpATf5.cjs +250 -0
  49. package/package.json +29 -19
  50. package/pagination--GkwduJn.js +263 -0
  51. package/pagination-EWSWQT1I.cjs +262 -0
  52. package/progressbar-DH7DHYMp.cjs +83 -0
  53. package/progressbar-DuRX7_my.js +84 -0
  54. package/promise-BMJ8qhA8.cjs +118 -0
  55. package/promise-CY2U8bTP.js +119 -0
  56. package/rating-BR5wD7y2.js +173 -0
  57. package/rating-CmuYUSxy.cjs +172 -0
  58. package/select-BCs6HQWn.js +358 -0
  59. package/select-CCIKn8WR.cjs +357 -0
  60. package/services/extendWidget.cjs +32 -0
  61. package/services/extendWidget.d.ts +2 -1
  62. package/services/extendWidget.js +31 -34
  63. package/services/floatingUI.cjs +131 -0
  64. package/services/floatingUI.d.ts +30 -14
  65. package/services/floatingUI.js +128 -102
  66. package/services/focustrack.cjs +47 -0
  67. package/services/focustrack.js +45 -44
  68. package/services/hash.cjs +15 -0
  69. package/services/hash.js +14 -12
  70. package/services/intersection.cjs +53 -0
  71. package/services/intersection.js +48 -50
  72. package/services/matchMedia.cjs +13 -0
  73. package/services/matchMedia.d.ts +7 -0
  74. package/services/matchMedia.js +13 -0
  75. package/services/navManager.cjs +196 -0
  76. package/services/navManager.d.ts +9 -9
  77. package/services/navManager.js +186 -168
  78. package/services/portal.cjs +43 -0
  79. package/services/portal.js +41 -42
  80. package/services/resizeObserver.cjs +32 -0
  81. package/services/resizeObserver.d.ts +1 -1
  82. package/services/resizeObserver.js +31 -28
  83. package/services/siblingsInert.cjs +40 -0
  84. package/services/siblingsInert.js +31 -31
  85. package/services/transitions/baseTransitions.cjs +171 -0
  86. package/services/transitions/baseTransitions.d.ts +16 -16
  87. package/services/transitions/baseTransitions.js +159 -170
  88. package/services/transitions/collapse.cjs +44 -0
  89. package/services/transitions/collapse.js +41 -49
  90. package/services/transitions/cssTransitions.cjs +32 -0
  91. package/services/transitions/cssTransitions.d.ts +2 -1
  92. package/services/transitions/cssTransitions.js +29 -39
  93. package/services/transitions/simpleClassTransition.cjs +31 -0
  94. package/services/transitions/simpleClassTransition.js +30 -41
  95. package/slider-CA_fszn7.js +536 -0
  96. package/slider-DsLvT87U.cjs +535 -0
  97. package/toast-8tWp6x89.js +63 -0
  98. package/toast-Aw8o0Iwe.cjs +62 -0
  99. package/types.cjs +12 -0
  100. package/types.d.ts +21 -1
  101. package/types.js +11 -13
  102. package/utils/directive.cjs +26 -0
  103. package/utils/directive.d.ts +148 -5
  104. package/utils/directive.js +25 -205
  105. package/utils/internal/dom.d.ts +43 -4
  106. package/utils/internal/promise.d.ts +2 -2
  107. package/utils/internal/ssrHTMLElement.d.ts +7 -0
  108. package/utils/stores.cjs +163 -0
  109. package/utils/stores.d.ts +9 -17
  110. package/utils/stores.js +149 -284
  111. package/utils/writables.cjs +13 -0
  112. package/utils/writables.js +12 -71
  113. package/writables-D46sFgGK.cjs +85 -0
  114. package/writables-DoU_XYTX.js +86 -0
  115. package/components/accordion/accordion.js +0 -264
  116. package/components/alert/alert.js +0 -22
  117. package/components/alert/common.js +0 -69
  118. package/components/commonProps.js +0 -1
  119. package/components/modal/modal.js +0 -186
  120. package/components/pagination/bootstrap.d.ts +0 -8
  121. package/components/pagination/bootstrap.js +0 -110
  122. package/components/pagination/pagination.js +0 -195
  123. package/components/progressbar/progressbar.js +0 -78
  124. package/components/rating/rating.js +0 -137
  125. package/components/select/select.js +0 -297
  126. package/components/slider/slider.js +0 -420
  127. package/components/toast/toast.js +0 -43
  128. package/services/transitions/bootstrap/collapse.d.ts +0 -2
  129. package/services/transitions/bootstrap/collapse.js +0 -15
  130. package/services/transitions/bootstrap/fade.d.ts +0 -1
  131. package/services/transitions/bootstrap/fade.js +0 -7
  132. package/services/transitions/bootstrap.d.ts +0 -2
  133. package/services/transitions/bootstrap.js +0 -2
  134. package/utils/internal/checks.js +0 -60
  135. package/utils/internal/dom.js +0 -82
  136. package/utils/internal/func.js +0 -11
  137. package/utils/internal/isFocusable.js +0 -37
  138. package/utils/internal/math.js +0 -13
  139. package/utils/internal/promise.js +0 -169
  140. package/utils/internal/scrollbars.js +0 -33
  141. package/utils/internal/sort.js +0 -28
  142. package/utils/internal/textDirection.js +0 -7
  143. package/utils/internal/traversal.js +0 -105
package/index.js CHANGED
@@ -1,33 +1,119 @@
1
- // types
2
- export * from './components/commonProps';
3
- export * from './types';
4
- // components
5
- export * from './components/accordion';
6
- export * from './components/alert';
7
- export * from './components/modal';
8
- export * from './components/pagination';
9
- export * from './components/progressbar';
10
- export * from './components/rating';
11
- export * from './components/select';
12
- export * from './components/slider';
13
- export * from './components/toast';
14
- // config
15
- export * from './config';
16
- // services
17
- export * from './services/extendWidget';
18
- export * from './services/floatingUI';
19
- export * from './services/focustrack';
20
- export * from './services/intersection';
21
- export * from './services/navManager';
22
- export * from './services/portal';
23
- export * from './services/resizeObserver';
24
- export * from './services/siblingsInert';
25
- // services transitions
26
- export * from './services/transitions/baseTransitions';
27
- export * from './services/transitions/cssTransitions';
28
- export * from './services/transitions/simpleClassTransition';
29
- export * from './services/transitions/bootstrap';
30
- // public utils
31
- export * from './utils/directive';
32
- export * from './utils/stores';
33
- export * from './utils/writables';
1
+ import { INVALID_VALUE, toSlotContextWidget } from "./types.js";
2
+ import { a, c, f, g } from "./accordion-BaWN0_n-.js";
3
+ import { c as c2, a as a2, d, g as g2 } from "./common-DRdsw5m8.js";
4
+ import { c as c3, g as g3 } from "./alert-Dlf-BV98.js";
5
+ import { c as c4, g as g4, a as a3, m } from "./modal-BI2qUu1M.js";
6
+ import { c as c5, g as g5 } from "./pagination--GkwduJn.js";
7
+ import { c as c6, g as g6 } from "./progressbar-DuRX7_my.js";
8
+ import { c as c7, g as g7 } from "./rating-BR5wD7y2.js";
9
+ import { c as c8, d as d2, g as g8 } from "./select-BCs6HQWn.js";
10
+ import { c as c9, g as g9 } from "./slider-CA_fszn7.js";
11
+ import { c as c10, g as g10 } from "./toast-8tWp6x89.js";
12
+ import { createWidgetsConfig, mergeInto } from "./config.js";
13
+ import { extendWidgetProps } from "./services/extendWidget.js";
14
+ import { createFloatingUI } from "./services/floatingUI.js";
15
+ import { activeElement$, createHasFocus } from "./services/focustrack.js";
16
+ import { createIntersection } from "./services/intersection.js";
17
+ import { createMatchMedia } from "./services/matchMedia.js";
18
+ import { createNavManager, getKeyName, isInternalInputNavigation } from "./services/navManager.js";
19
+ import { portal } from "./services/portal.js";
20
+ import { createResizeObserver } from "./services/resizeObserver.js";
21
+ import { sliblingsInert } from "./services/siblingsInert.js";
22
+ import { createTransition, noAnimation } from "./services/transitions/baseTransitions.js";
23
+ import { createCSSTransition, getTransitionDurationMs, hasTransition } from "./services/transitions/cssTransitions.js";
24
+ import { createSimpleClassTransition } from "./services/transitions/simpleClassTransition.js";
25
+ import { o, a as a4, c as c11, b, p, n, g as g11, j, f as f2, h, q, d as d3, e, i, m as m2, k, l, r, s } from "./directive-DCYlDznf.js";
26
+ import { bindableDerived, bindableProp, createPatch, findChangedProperties, isStore, mergeConfigStores, normalizeConfigStores, stateStores, toReadableStore, toWritableStore, writableWithDefault, writablesForProps, writablesWithDefault } from "./utils/stores.js";
27
+ import { t, h as h2, c as c12, d as d4, f as f3, g as g12, a as a5, b as b2, e as e2 } from "./writables-DoU_XYTX.js";
28
+ export {
29
+ INVALID_VALUE,
30
+ activeElement$,
31
+ o as attributesData,
32
+ a4 as bindDirective,
33
+ c11 as bindDirectiveNoArg,
34
+ bindableDerived,
35
+ bindableProp,
36
+ b as browserDirective,
37
+ p as classDirective,
38
+ c2 as commonAlertConfigValidator,
39
+ a as createAccordion,
40
+ c as createAccordionItem,
41
+ c3 as createAlert,
42
+ n as createAttributesDirective,
43
+ g11 as createBrowserStoreArrayDirective,
44
+ j as createBrowserStoreDirective,
45
+ createCSSTransition,
46
+ a2 as createCommonAlert,
47
+ createFloatingUI,
48
+ createHasFocus,
49
+ createIntersection,
50
+ createMatchMedia,
51
+ c4 as createModal,
52
+ createNavManager,
53
+ c5 as createPagination,
54
+ createPatch,
55
+ c6 as createProgressbar,
56
+ c7 as createRating,
57
+ createResizeObserver,
58
+ c8 as createSelect,
59
+ createSimpleClassTransition,
60
+ c9 as createSlider,
61
+ f2 as createStoreArrayDirective,
62
+ h as createStoreDirective,
63
+ c10 as createToast,
64
+ createTransition,
65
+ createWidgetsConfig,
66
+ d as defaultCommonAlertConfig,
67
+ d2 as defaultConfig,
68
+ q as directiveAttributes,
69
+ d3 as directiveSubscribe,
70
+ e as directiveUpdate,
71
+ extendWidgetProps,
72
+ f as factoryCreateAccordion,
73
+ findChangedProperties,
74
+ g as getAccordionDefaultConfig,
75
+ g3 as getAlertDefaultConfig,
76
+ g2 as getCommonAlertDefaultConfig,
77
+ getKeyName,
78
+ g4 as getModalDefaultConfig,
79
+ g5 as getPaginationDefaultConfig,
80
+ g6 as getProgressbarDefaultConfig,
81
+ g7 as getRatingDefaultConfig,
82
+ g8 as getSelectDefaultConfig,
83
+ g9 as getSliderDefaultConfig,
84
+ g10 as getToastDefaultConfig,
85
+ getTransitionDurationMs,
86
+ hasTransition,
87
+ i as isBrowserHTMLElement,
88
+ isInternalInputNavigation,
89
+ isStore,
90
+ m2 as mapDirectiveArg,
91
+ mergeConfigStores,
92
+ k as mergeDirectives,
93
+ mergeInto,
94
+ a3 as modalCloseButtonClick,
95
+ m as modalOutsideClick,
96
+ l as multiDirective,
97
+ noAnimation,
98
+ normalizeConfigStores,
99
+ portal,
100
+ r as registrationArray,
101
+ sliblingsInert,
102
+ s as ssrAttributes,
103
+ stateStores,
104
+ t as testToNormalizeValue,
105
+ toReadableStore,
106
+ toSlotContextWidget,
107
+ toWritableStore,
108
+ h2 as typeArray,
109
+ c12 as typeBoolean,
110
+ d4 as typeBooleanOrNull,
111
+ f3 as typeFunction,
112
+ g12 as typeHTMLElementOrNull,
113
+ a5 as typeNumber,
114
+ b2 as typeNumberInRangeFactory,
115
+ e2 as typeString,
116
+ writableWithDefault,
117
+ writablesForProps,
118
+ writablesWithDefault
119
+ };
@@ -0,0 +1,251 @@
1
+ import { computed, readable } from "@amadeus-it-group/tansu";
2
+ import { c as typeBoolean, e as typeString, f as typeFunction, g as typeHTMLElementOrNull } from "./writables-DoU_XYTX.js";
3
+ import { writablesForProps, stateStores } from "./utils/stores.js";
4
+ import { createTransition } from "./services/transitions/baseTransitions.js";
5
+ import { d as promiseFromStore } from "./promise-CY2U8bTP.js";
6
+ import { n as noop } from "./func-DR0n-ShK.js";
7
+ import { r as registrationArray, a as bindDirective, k as mergeDirectives, c as bindDirectiveNoArg, d as directiveSubscribe, n as createAttributesDirective } from "./directive-DCYlDznf.js";
8
+ import { portal } from "./services/portal.js";
9
+ import { sliblingsInert } from "./services/siblingsInert.js";
10
+ const internalRemoveScrollbars = () => {
11
+ const scrollbarWidth = Math.abs(window.innerWidth - document.documentElement.clientWidth);
12
+ const body = document.body;
13
+ const bodyStyle = body.style;
14
+ const { overflow, paddingRight } = bodyStyle;
15
+ if (scrollbarWidth > 0) {
16
+ const actualPadding = parseFloat(window.getComputedStyle(body).paddingRight);
17
+ bodyStyle.paddingRight = `${actualPadding + scrollbarWidth}px`;
18
+ }
19
+ bodyStyle.overflow = "hidden";
20
+ return () => {
21
+ if (scrollbarWidth > 0) {
22
+ bodyStyle.paddingRight = paddingRight;
23
+ }
24
+ bodyStyle.overflow = overflow;
25
+ };
26
+ };
27
+ let internalRevert = noop;
28
+ const removeScrollbars = () => {
29
+ internalRevert();
30
+ internalRevert = internalRemoveScrollbars();
31
+ };
32
+ const revertScrollbars = () => {
33
+ internalRevert();
34
+ internalRevert = noop;
35
+ };
36
+ const modalOutsideClick = Symbol();
37
+ const modalCloseButtonClick = Symbol();
38
+ const defaultConfig = {
39
+ animated: true,
40
+ ariaCloseButtonLabel: "Close",
41
+ backdrop: true,
42
+ backdropClass: "",
43
+ backdropTransition: async () => {
44
+ },
45
+ closeButton: true,
46
+ closeOnOutsideClick: true,
47
+ container: typeof window !== "undefined" ? document.body : null,
48
+ className: "",
49
+ modalTransition: async () => {
50
+ },
51
+ onBeforeClose: noop,
52
+ onVisibleChange: noop,
53
+ onHidden: noop,
54
+ onShown: noop,
55
+ visible: false,
56
+ contentData: void 0
57
+ };
58
+ const configValidator = {
59
+ animated: typeBoolean,
60
+ ariaCloseButtonLabel: typeString,
61
+ backdrop: typeBoolean,
62
+ backdropClass: typeString,
63
+ backdropTransition: typeFunction,
64
+ closeButton: typeBoolean,
65
+ closeOnOutsideClick: typeBoolean,
66
+ container: typeHTMLElementOrNull,
67
+ className: typeString,
68
+ modalTransition: typeFunction,
69
+ onBeforeClose: typeFunction,
70
+ onVisibleChange: typeFunction,
71
+ onHidden: typeFunction,
72
+ onShown: typeFunction,
73
+ visible: typeBoolean
74
+ };
75
+ function getModalDefaultConfig() {
76
+ return { ...defaultConfig };
77
+ }
78
+ const modals$ = registrationArray();
79
+ const hasModals$ = computed(() => modals$().length > 0);
80
+ const scrollbarsAction$ = computed(() => {
81
+ if (hasModals$()) {
82
+ removeScrollbars();
83
+ } else {
84
+ revertScrollbars();
85
+ }
86
+ });
87
+ const modalsAction$ = computed(() => {
88
+ scrollbarsAction$();
89
+ });
90
+ function createModal(config$) {
91
+ const [
92
+ {
93
+ animated$,
94
+ backdrop$,
95
+ backdropTransition$,
96
+ closeOnOutsideClick$,
97
+ container$,
98
+ modalTransition$,
99
+ onBeforeClose$,
100
+ onVisibleChange$,
101
+ onHidden$,
102
+ onShown$,
103
+ ariaCloseButtonLabel$,
104
+ className$,
105
+ backdropClass$,
106
+ visible$: requestedVisible$,
107
+ ...stateProps
108
+ },
109
+ patch
110
+ ] = writablesForProps(defaultConfig, config$, configValidator);
111
+ const modalTransition = createTransition({
112
+ props: {
113
+ transition: modalTransition$,
114
+ visible: requestedVisible$,
115
+ animated: animated$,
116
+ animatedOnInit: animated$,
117
+ onVisibleChange: onVisibleChange$,
118
+ // TODO: for onHidden and onShown, should we combine with information from the backdrop transition?
119
+ // (especially in case one of the two transitions takes more time than the other)
120
+ onHidden: onHidden$,
121
+ onShown: onShown$
122
+ }
123
+ });
124
+ const visible$ = modalTransition.stores.visible$;
125
+ const backdropTransition = createTransition({
126
+ props: {
127
+ transition: backdropTransition$,
128
+ visible: requestedVisible$,
129
+ animated: animated$,
130
+ animatedOnInit: animated$
131
+ }
132
+ });
133
+ const transitioning$ = computed(() => modalTransition.stores.transitioning$() || backdrop$() && backdropTransition.stores.transitioning$());
134
+ const hidden$ = computed(() => !transitioning$() && !visible$());
135
+ const backdropHidden$ = computed(() => !backdrop$() || hidden$());
136
+ let hideResult;
137
+ const close = (result) => {
138
+ hideResult = result;
139
+ const beforeCloseEvent = {
140
+ get result() {
141
+ return hideResult;
142
+ },
143
+ set result(value) {
144
+ hideResult = value;
145
+ },
146
+ cancel: false
147
+ };
148
+ onBeforeClose$()(beforeCloseEvent);
149
+ if (beforeCloseEvent.cancel) {
150
+ return;
151
+ }
152
+ patch({ visible: false });
153
+ };
154
+ const modalPortalDirective = bindDirective(
155
+ portal,
156
+ computed(() => ({ container: container$() }))
157
+ );
158
+ const backdropPortalDirective = bindDirective(
159
+ portal,
160
+ computed(() => {
161
+ const container = container$();
162
+ const element = container ? modalTransition.stores.element$() : void 0;
163
+ return {
164
+ container,
165
+ insertBefore: (element == null ? void 0 : element.parentElement) === container ? element : void 0
166
+ };
167
+ })
168
+ );
169
+ const registerModalAction$ = readable(void 0, () => modals$.register(res));
170
+ const action$ = computed(() => {
171
+ if (modalTransition.stores.elementPresent$() && !hidden$()) {
172
+ registerModalAction$();
173
+ }
174
+ modalsAction$();
175
+ });
176
+ const closeButtonDirective = createAttributesDirective(() => ({
177
+ attributes: {
178
+ type: "button",
179
+ "aria-label": ariaCloseButtonLabel$
180
+ },
181
+ events: {
182
+ click: res.actions.closeButtonClick
183
+ }
184
+ }));
185
+ const backdropAttributeDirective = createAttributesDirective(() => ({
186
+ attributes: {
187
+ class: backdropClass$
188
+ }
189
+ }));
190
+ const modalAttributeDirective = createAttributesDirective(() => ({
191
+ attributes: {
192
+ class: className$
193
+ },
194
+ events: {
195
+ click: res.actions.modalClick
196
+ }
197
+ }));
198
+ const res = {
199
+ ...stateStores({
200
+ backdropHidden$,
201
+ container$,
202
+ hidden$,
203
+ transitioning$,
204
+ visible$,
205
+ modalElement$: modalTransition.stores.element$,
206
+ ariaCloseButtonLabel$,
207
+ className$,
208
+ backdropClass$,
209
+ ...stateProps
210
+ }),
211
+ directives: {
212
+ modalPortalDirective,
213
+ backdropPortalDirective,
214
+ backdropDirective: mergeDirectives(bindDirectiveNoArg(backdropTransition.directives.directive), backdropAttributeDirective),
215
+ modalDirective: mergeDirectives(
216
+ bindDirectiveNoArg(modalTransition.directives.directive),
217
+ sliblingsInert,
218
+ directiveSubscribe(action$),
219
+ modalAttributeDirective
220
+ ),
221
+ closeButtonDirective
222
+ },
223
+ patch,
224
+ api: {
225
+ close,
226
+ async open() {
227
+ patch({ visible: true });
228
+ await promiseFromStore(hidden$).promise;
229
+ return hideResult;
230
+ },
231
+ patch
232
+ },
233
+ actions: {
234
+ modalClick(event) {
235
+ if (event.currentTarget === event.target && closeOnOutsideClick$()) {
236
+ close(modalOutsideClick);
237
+ }
238
+ },
239
+ closeButtonClick(event) {
240
+ close(modalCloseButtonClick);
241
+ }
242
+ }
243
+ };
244
+ return res;
245
+ }
246
+ export {
247
+ modalCloseButtonClick as a,
248
+ createModal as c,
249
+ getModalDefaultConfig as g,
250
+ modalOutsideClick as m
251
+ };
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ const tansu = require("@amadeus-it-group/tansu");
3
+ const utils_writables = require("./writables-D46sFgGK.cjs");
4
+ const utils_stores = require("./utils/stores.cjs");
5
+ const services_transitions_baseTransitions = require("./services/transitions/baseTransitions.cjs");
6
+ const promise = require("./promise-BMJ8qhA8.cjs");
7
+ const func = require("./func-Qd3cD9a3.cjs");
8
+ const utils_directive = require("./directive-BTSEYLF3.cjs");
9
+ const services_portal = require("./services/portal.cjs");
10
+ const services_siblingsInert = require("./services/siblingsInert.cjs");
11
+ const internalRemoveScrollbars = () => {
12
+ const scrollbarWidth = Math.abs(window.innerWidth - document.documentElement.clientWidth);
13
+ const body = document.body;
14
+ const bodyStyle = body.style;
15
+ const { overflow, paddingRight } = bodyStyle;
16
+ if (scrollbarWidth > 0) {
17
+ const actualPadding = parseFloat(window.getComputedStyle(body).paddingRight);
18
+ bodyStyle.paddingRight = `${actualPadding + scrollbarWidth}px`;
19
+ }
20
+ bodyStyle.overflow = "hidden";
21
+ return () => {
22
+ if (scrollbarWidth > 0) {
23
+ bodyStyle.paddingRight = paddingRight;
24
+ }
25
+ bodyStyle.overflow = overflow;
26
+ };
27
+ };
28
+ let internalRevert = func.noop;
29
+ const removeScrollbars = () => {
30
+ internalRevert();
31
+ internalRevert = internalRemoveScrollbars();
32
+ };
33
+ const revertScrollbars = () => {
34
+ internalRevert();
35
+ internalRevert = func.noop;
36
+ };
37
+ const modalOutsideClick = Symbol();
38
+ const modalCloseButtonClick = Symbol();
39
+ const defaultConfig = {
40
+ animated: true,
41
+ ariaCloseButtonLabel: "Close",
42
+ backdrop: true,
43
+ backdropClass: "",
44
+ backdropTransition: async () => {
45
+ },
46
+ closeButton: true,
47
+ closeOnOutsideClick: true,
48
+ container: typeof window !== "undefined" ? document.body : null,
49
+ className: "",
50
+ modalTransition: async () => {
51
+ },
52
+ onBeforeClose: func.noop,
53
+ onVisibleChange: func.noop,
54
+ onHidden: func.noop,
55
+ onShown: func.noop,
56
+ visible: false,
57
+ contentData: void 0
58
+ };
59
+ const configValidator = {
60
+ animated: utils_writables.typeBoolean,
61
+ ariaCloseButtonLabel: utils_writables.typeString,
62
+ backdrop: utils_writables.typeBoolean,
63
+ backdropClass: utils_writables.typeString,
64
+ backdropTransition: utils_writables.typeFunction,
65
+ closeButton: utils_writables.typeBoolean,
66
+ closeOnOutsideClick: utils_writables.typeBoolean,
67
+ container: utils_writables.typeHTMLElementOrNull,
68
+ className: utils_writables.typeString,
69
+ modalTransition: utils_writables.typeFunction,
70
+ onBeforeClose: utils_writables.typeFunction,
71
+ onVisibleChange: utils_writables.typeFunction,
72
+ onHidden: utils_writables.typeFunction,
73
+ onShown: utils_writables.typeFunction,
74
+ visible: utils_writables.typeBoolean
75
+ };
76
+ function getModalDefaultConfig() {
77
+ return { ...defaultConfig };
78
+ }
79
+ const modals$ = utils_directive.registrationArray();
80
+ const hasModals$ = tansu.computed(() => modals$().length > 0);
81
+ const scrollbarsAction$ = tansu.computed(() => {
82
+ if (hasModals$()) {
83
+ removeScrollbars();
84
+ } else {
85
+ revertScrollbars();
86
+ }
87
+ });
88
+ const modalsAction$ = tansu.computed(() => {
89
+ scrollbarsAction$();
90
+ });
91
+ function createModal(config$) {
92
+ const [
93
+ {
94
+ animated$,
95
+ backdrop$,
96
+ backdropTransition$,
97
+ closeOnOutsideClick$,
98
+ container$,
99
+ modalTransition$,
100
+ onBeforeClose$,
101
+ onVisibleChange$,
102
+ onHidden$,
103
+ onShown$,
104
+ ariaCloseButtonLabel$,
105
+ className$,
106
+ backdropClass$,
107
+ visible$: requestedVisible$,
108
+ ...stateProps
109
+ },
110
+ patch
111
+ ] = utils_stores.writablesForProps(defaultConfig, config$, configValidator);
112
+ const modalTransition = services_transitions_baseTransitions.createTransition({
113
+ props: {
114
+ transition: modalTransition$,
115
+ visible: requestedVisible$,
116
+ animated: animated$,
117
+ animatedOnInit: animated$,
118
+ onVisibleChange: onVisibleChange$,
119
+ // TODO: for onHidden and onShown, should we combine with information from the backdrop transition?
120
+ // (especially in case one of the two transitions takes more time than the other)
121
+ onHidden: onHidden$,
122
+ onShown: onShown$
123
+ }
124
+ });
125
+ const visible$ = modalTransition.stores.visible$;
126
+ const backdropTransition = services_transitions_baseTransitions.createTransition({
127
+ props: {
128
+ transition: backdropTransition$,
129
+ visible: requestedVisible$,
130
+ animated: animated$,
131
+ animatedOnInit: animated$
132
+ }
133
+ });
134
+ const transitioning$ = tansu.computed(() => modalTransition.stores.transitioning$() || backdrop$() && backdropTransition.stores.transitioning$());
135
+ const hidden$ = tansu.computed(() => !transitioning$() && !visible$());
136
+ const backdropHidden$ = tansu.computed(() => !backdrop$() || hidden$());
137
+ let hideResult;
138
+ const close = (result) => {
139
+ hideResult = result;
140
+ const beforeCloseEvent = {
141
+ get result() {
142
+ return hideResult;
143
+ },
144
+ set result(value) {
145
+ hideResult = value;
146
+ },
147
+ cancel: false
148
+ };
149
+ onBeforeClose$()(beforeCloseEvent);
150
+ if (beforeCloseEvent.cancel) {
151
+ return;
152
+ }
153
+ patch({ visible: false });
154
+ };
155
+ const modalPortalDirective = utils_directive.bindDirective(
156
+ services_portal.portal,
157
+ tansu.computed(() => ({ container: container$() }))
158
+ );
159
+ const backdropPortalDirective = utils_directive.bindDirective(
160
+ services_portal.portal,
161
+ tansu.computed(() => {
162
+ const container = container$();
163
+ const element = container ? modalTransition.stores.element$() : void 0;
164
+ return {
165
+ container,
166
+ insertBefore: (element == null ? void 0 : element.parentElement) === container ? element : void 0
167
+ };
168
+ })
169
+ );
170
+ const registerModalAction$ = tansu.readable(void 0, () => modals$.register(res));
171
+ const action$ = tansu.computed(() => {
172
+ if (modalTransition.stores.elementPresent$() && !hidden$()) {
173
+ registerModalAction$();
174
+ }
175
+ modalsAction$();
176
+ });
177
+ const closeButtonDirective = utils_directive.createAttributesDirective(() => ({
178
+ attributes: {
179
+ type: "button",
180
+ "aria-label": ariaCloseButtonLabel$
181
+ },
182
+ events: {
183
+ click: res.actions.closeButtonClick
184
+ }
185
+ }));
186
+ const backdropAttributeDirective = utils_directive.createAttributesDirective(() => ({
187
+ attributes: {
188
+ class: backdropClass$
189
+ }
190
+ }));
191
+ const modalAttributeDirective = utils_directive.createAttributesDirective(() => ({
192
+ attributes: {
193
+ class: className$
194
+ },
195
+ events: {
196
+ click: res.actions.modalClick
197
+ }
198
+ }));
199
+ const res = {
200
+ ...utils_stores.stateStores({
201
+ backdropHidden$,
202
+ container$,
203
+ hidden$,
204
+ transitioning$,
205
+ visible$,
206
+ modalElement$: modalTransition.stores.element$,
207
+ ariaCloseButtonLabel$,
208
+ className$,
209
+ backdropClass$,
210
+ ...stateProps
211
+ }),
212
+ directives: {
213
+ modalPortalDirective,
214
+ backdropPortalDirective,
215
+ backdropDirective: utils_directive.mergeDirectives(utils_directive.bindDirectiveNoArg(backdropTransition.directives.directive), backdropAttributeDirective),
216
+ modalDirective: utils_directive.mergeDirectives(
217
+ utils_directive.bindDirectiveNoArg(modalTransition.directives.directive),
218
+ services_siblingsInert.sliblingsInert,
219
+ utils_directive.directiveSubscribe(action$),
220
+ modalAttributeDirective
221
+ ),
222
+ closeButtonDirective
223
+ },
224
+ patch,
225
+ api: {
226
+ close,
227
+ async open() {
228
+ patch({ visible: true });
229
+ await promise.promiseFromStore(hidden$).promise;
230
+ return hideResult;
231
+ },
232
+ patch
233
+ },
234
+ actions: {
235
+ modalClick(event) {
236
+ if (event.currentTarget === event.target && closeOnOutsideClick$()) {
237
+ close(modalOutsideClick);
238
+ }
239
+ },
240
+ closeButtonClick(event) {
241
+ close(modalCloseButtonClick);
242
+ }
243
+ }
244
+ };
245
+ return res;
246
+ }
247
+ exports.createModal = createModal;
248
+ exports.getModalDefaultConfig = getModalDefaultConfig;
249
+ exports.modalCloseButtonClick = modalCloseButtonClick;
250
+ exports.modalOutsideClick = modalOutsideClick;