@agnos-ui/core 0.9.2 → 0.10.0-next.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 (110) hide show
  1. package/{accordion-CoM4efp-.js → accordion-CcirvrjR.js} +10 -15
  2. package/{accordion-cR5JqWJ8.cjs → accordion-yD-czBna.cjs} +10 -15
  3. package/{alert-DtDozJal.cjs → alert-B-jQDQcB.cjs} +1 -1
  4. package/{alert-YIlqdEPO.js → alert-gGz2CDS9.js} +1 -1
  5. package/collapse-BV4kD3j9.js +82 -0
  6. package/collapse-gLiT080Y.cjs +81 -0
  7. package/{common-BToNPUDq.cjs → common-D3QcdJ6S.cjs} +1 -1
  8. package/{common-BqUjUBPy.js → common-DK0ADNTX.js} +1 -1
  9. package/components/accordion/index.cjs +1 -1
  10. package/components/accordion/index.js +1 -1
  11. package/components/alert/index.cjs +1 -1
  12. package/components/alert/index.js +1 -1
  13. package/components/carousel/index.cjs +10 -23
  14. package/components/carousel/index.js +10 -23
  15. package/components/collapse/collapse.d.ts +132 -0
  16. package/components/collapse/index.cjs +5 -0
  17. package/components/collapse/index.d.ts +1 -0
  18. package/components/collapse/index.js +5 -0
  19. package/components/drawer/drawer.d.ts +222 -0
  20. package/components/drawer/index.cjs +5 -0
  21. package/components/drawer/index.d.ts +1 -0
  22. package/components/drawer/index.js +5 -0
  23. package/components/modal/index.cjs +2 -1
  24. package/components/modal/index.js +2 -1
  25. package/components/modal/modal.d.ts +5 -0
  26. package/components/pagination/index.cjs +1 -1
  27. package/components/pagination/index.js +1 -1
  28. package/components/progressbar/index.cjs +1 -1
  29. package/components/progressbar/index.js +1 -1
  30. package/components/rating/index.cjs +1 -1
  31. package/components/rating/index.js +1 -1
  32. package/components/select/index.cjs +1 -1
  33. package/components/select/index.js +1 -1
  34. package/components/slider/index.cjs +1 -1
  35. package/components/slider/index.js +1 -1
  36. package/components/toast/index.cjs +1 -1
  37. package/components/toast/index.js +1 -1
  38. package/components/tree/index.cjs +1 -1
  39. package/components/tree/index.js +1 -1
  40. package/config.cjs +2 -2
  41. package/config.d.ts +10 -0
  42. package/config.js +2 -2
  43. package/{dom-gfxqXJpK.js → dom-Bcg9ORcA.js} +64 -54
  44. package/{dom-CuBx1JPZ.cjs → dom-C2gi9OCP.cjs} +47 -37
  45. package/drawer-D5SO73ew.js +251 -0
  46. package/drawer-DP7UPojk.cjs +250 -0
  47. package/index.cjs +21 -12
  48. package/index.d.ts +2 -0
  49. package/index.js +54 -45
  50. package/isFocusable-Ckwus82R.js +32 -0
  51. package/isFocusable-DfzDLeAN.cjs +31 -0
  52. package/{modal-D3wGIDlj.js → modal-CAvQW-vo.js} +26 -32
  53. package/{modal-BEnQ6c5M.cjs → modal-DiXZXYjR.cjs} +27 -33
  54. package/package.json +1 -1
  55. package/{pagination-B97wBLok.js → pagination-BKbMROV6.js} +4 -4
  56. package/{pagination-C1TT-oea.cjs → pagination-DvZ2rLsz.cjs} +4 -4
  57. package/{progressbar-BWBlRk_Y.js → progressbar-D8zIcm9n.js} +2 -2
  58. package/{progressbar-CRvhNB5R.cjs → progressbar-i9xfAxb7.cjs} +2 -2
  59. package/{promise-XSP94FjG.js → promise-Y53vc4Ia.js} +5 -5
  60. package/{rating-BXvy9kXq.js → rating-DEXTGWCU.js} +2 -2
  61. package/{rating-DAb6nR67.cjs → rating-DmG4oUkr.cjs} +2 -2
  62. package/scrollbars-CT87iv_6.cjs +30 -0
  63. package/scrollbars-CcxSrnCx.js +31 -0
  64. package/{select-BdjpnE7_.js → select-Bw68Xdu5.js} +4 -5
  65. package/{select-C0rJJQfl.cjs → select-MFjAnIt7.cjs} +4 -5
  66. package/services/extendWidget.cjs +2 -2
  67. package/services/extendWidget.js +2 -2
  68. package/services/floatingUI.cjs +8 -29
  69. package/services/floatingUI.js +9 -30
  70. package/services/focusElement.cjs +46 -0
  71. package/services/focusElement.d.ts +9 -0
  72. package/services/focusElement.js +46 -0
  73. package/services/focustrack.cjs +1 -1
  74. package/services/focustrack.js +1 -1
  75. package/services/matchMedia.cjs +1 -1
  76. package/services/matchMedia.js +1 -1
  77. package/services/navManager.cjs +7 -37
  78. package/services/navManager.js +6 -36
  79. package/services/portal.cjs +7 -10
  80. package/services/portal.js +7 -10
  81. package/services/resizeObserver.cjs +2 -2
  82. package/services/resizeObserver.js +2 -2
  83. package/services/siblingsInert.cjs +9 -8
  84. package/services/siblingsInert.d.ts +13 -3
  85. package/services/siblingsInert.js +9 -8
  86. package/services/transitions/baseTransitions.cjs +9 -10
  87. package/services/transitions/baseTransitions.js +10 -11
  88. package/services/transitions/collapse.cjs +1 -1
  89. package/services/transitions/collapse.js +1 -1
  90. package/services/transitions/cssTransitions.cjs +1 -1
  91. package/services/transitions/cssTransitions.js +2 -2
  92. package/services/transitions/simpleClassTransition.cjs +1 -1
  93. package/services/transitions/simpleClassTransition.js +1 -1
  94. package/{slider-BmxQ3A_u.js → slider-Cx50Eghd.js} +14 -24
  95. package/{slider-DSx5CAce.cjs → slider-Dl4Trh32.cjs} +14 -24
  96. package/toaster-UDglac7x.cjs +187 -0
  97. package/toaster-_p1GTtHI.js +188 -0
  98. package/{tree-BFrXdJox.js → tree-DV0tfPlZ.js} +7 -11
  99. package/{tree-Pvr2rZ-D.cjs → tree-rGHtmCnS.cjs} +7 -11
  100. package/utils/directive.cjs +3 -1
  101. package/utils/directive.d.ts +47 -0
  102. package/utils/directive.js +14 -12
  103. package/utils/stores.cjs +8 -9
  104. package/utils/stores.js +8 -9
  105. package/utils/writables.cjs +1 -1
  106. package/utils/writables.js +1 -1
  107. package/{writables-Bn3uhKEG.cjs → writables-DcGT98a7.cjs} +1 -1
  108. package/{writables-CgpOQ4hA.js → writables-e0tyaQpe.js} +1 -1
  109. package/toaster-Cayg6Lbq.cjs +0 -209
  110. package/toaster-XfzHDqz_.js +0 -210
@@ -58,13 +58,12 @@ function clsx() {
58
58
  for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
59
59
  return n;
60
60
  }
61
- const isBrowserHTMLElement = esmEnv.BROWSER ? (element) => {
62
- var _a;
63
- const contentWindow = ((_a = element == null ? void 0 : element.ownerDocument) == null ? void 0 : _a.defaultView) ?? window;
61
+ const isBrowserHTMLElement = esmEnv.BROWSER ? ((element) => {
62
+ const contentWindow = element?.ownerDocument?.defaultView ?? window;
64
63
  return element instanceof contentWindow.HTMLElement;
65
- } : (
64
+ }) : (
66
65
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
- (element) => false
66
+ ((element) => false)
68
67
  );
69
68
  const browserDirective = esmEnv.BROWSER ? (directive) => (node, args) => {
70
69
  if (isBrowserHTMLElement(node)) {
@@ -72,24 +71,22 @@ const browserDirective = esmEnv.BROWSER ? (directive) => (node, args) => {
72
71
  }
73
72
  } : (
74
73
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
75
- (directive) => utils_func.noop
74
+ ((directive) => utils_func.noop)
76
75
  );
77
76
  const bindDirective = (directive, directiveArg$) => (element) => {
78
77
  let firstTime = true;
79
78
  let instance;
80
79
  const unsubscribe = directiveArg$.subscribe((value) => {
81
- var _a;
82
80
  if (firstTime) {
83
81
  firstTime = false;
84
82
  instance = directive(element, value);
85
83
  } else {
86
- (_a = instance == null ? void 0 : instance.update) == null ? void 0 : _a.call(instance, value);
84
+ instance?.update?.(value);
87
85
  }
88
86
  });
89
87
  return {
90
88
  destroy() {
91
- var _a;
92
- (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
89
+ instance?.destroy?.();
93
90
  unsubscribe();
94
91
  }
95
92
  };
@@ -100,13 +97,9 @@ const mapDirectiveArg = (directive, fn) => (node, arg) => {
100
97
  const instance = directive(node, fn(arg));
101
98
  return {
102
99
  update: (arg2) => {
103
- var _a;
104
- (_a = instance == null ? void 0 : instance.update) == null ? void 0 : _a.call(instance, fn(arg2));
100
+ instance?.update?.(fn(arg2));
105
101
  },
106
- destroy: () => {
107
- var _a;
108
- return (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
109
- }
102
+ destroy: () => instance?.destroy?.()
110
103
  };
111
104
  };
112
105
  const directiveSubscribe = (store, asyncUnsubscribe = true) => () => {
@@ -155,17 +148,45 @@ const registrationArray = () => {
155
148
  }
156
149
  });
157
150
  };
158
- const createStoreArrayDirective = () => {
151
+ const createConditionalStoreArrayDirective = () => {
159
152
  const elements$ = registrationArray();
160
153
  return {
161
154
  elements$: tansu.asReadable(elements$),
162
- directive: (element) => ({ destroy: elements$.register(element) })
155
+ directive: (element, enabled = true) => {
156
+ let destroyElements;
157
+ const update = (newEnabled = true) => {
158
+ if (!!newEnabled != !!destroyElements) {
159
+ if (newEnabled) {
160
+ destroyElements = elements$.register(element);
161
+ } else {
162
+ destroyElements?.();
163
+ destroyElements = void 0;
164
+ }
165
+ }
166
+ };
167
+ update(enabled);
168
+ return {
169
+ destroy: () => update(false),
170
+ update
171
+ };
172
+ }
173
+ };
174
+ };
175
+ const createStoreArrayDirective = () => {
176
+ const { directive, elements$ } = createConditionalStoreArrayDirective();
177
+ return {
178
+ directive: bindDirectiveNoArg(directive),
179
+ elements$
163
180
  };
164
181
  };
165
182
  const createBrowserStoreArrayDirective = () => {
166
183
  const { directive, elements$ } = createStoreArrayDirective();
167
184
  return { directive: browserDirective(directive), elements$ };
168
185
  };
186
+ const createConditionalBrowserStoreArrayDirective = () => {
187
+ const { directive, elements$ } = createConditionalStoreArrayDirective();
188
+ return { directive: browserDirective(directive), elements$ };
189
+ };
169
190
  const createStoreDirective = () => {
170
191
  const element$ = tansu.writable(null, equalOption);
171
192
  return {
@@ -196,16 +217,10 @@ const mergeDirectives = (...args) => (element, arg) => {
196
217
  const instances = tansu.batch(() => args.map((directive) => directive(element, arg)));
197
218
  return {
198
219
  update(arg2) {
199
- tansu.batch(() => instances.forEach((instance) => {
200
- var _a;
201
- return (_a = instance == null ? void 0 : instance.update) == null ? void 0 : _a.call(instance, arg2);
202
- }));
220
+ tansu.batch(() => instances.forEach((instance) => instance?.update?.(arg2)));
203
221
  },
204
222
  destroy() {
205
- tansu.batch(() => instances.reverse().forEach((instance) => {
206
- var _a;
207
- return (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
208
- }));
223
+ tansu.batch(() => instances.reverse().forEach((instance) => instance?.destroy?.()));
209
224
  }
210
225
  };
211
226
  };
@@ -213,27 +228,23 @@ const multiDirective = (element, directives) => {
213
228
  const instances = [];
214
229
  const update = (directives2) => tansu.batch(() => {
215
230
  directives2.forEach((directiveWithArg, index) => {
216
- var _a, _b, _c, _d;
217
231
  const [directive, arg] = Array.isArray(directiveWithArg) ? directiveWithArg : [directiveWithArg, void 0];
218
232
  const oldInstance = instances[index];
219
233
  if (oldInstance) {
220
234
  if (oldInstance.directive === directive) {
221
235
  if (oldInstance.arg !== arg) {
222
- (_b = (_a = oldInstance.instance) == null ? void 0 : _a.update) == null ? void 0 : _b.call(_a, arg);
236
+ oldInstance.instance?.update?.(arg);
223
237
  oldInstance.arg = arg;
224
238
  }
225
239
  return;
226
240
  }
227
- (_d = (_c = oldInstance.instance) == null ? void 0 : _c.destroy) == null ? void 0 : _d.call(_c);
241
+ oldInstance.instance?.destroy?.();
228
242
  }
229
243
  const instance = directive(element, arg);
230
244
  instances[index] = { directive, instance, arg };
231
245
  });
232
246
  const extraInstances = instances.splice(directives2.length);
233
- extraInstances.reverse().forEach(({ instance }) => {
234
- var _a;
235
- return (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
236
- });
247
+ extraInstances.reverse().forEach(({ instance }) => instance?.destroy?.());
237
248
  });
238
249
  update(directives);
239
250
  return {
@@ -281,10 +292,7 @@ const attributesData = (...directives) => {
281
292
  }
282
293
  return element[ssrHTMLElementAttributesAndStyle]();
283
294
  } finally {
284
- instances.forEach((instance) => {
285
- var _a;
286
- return (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
287
- });
295
+ instances.forEach((instance) => instance?.destroy?.());
288
296
  }
289
297
  };
290
298
  const classDirective = createAttributesDirective((className$) => ({
@@ -406,6 +414,8 @@ exports.computeCommonAncestor = computeCommonAncestor;
406
414
  exports.createAttributesDirective = createAttributesDirective;
407
415
  exports.createBrowserStoreArrayDirective = createBrowserStoreArrayDirective;
408
416
  exports.createBrowserStoreDirective = createBrowserStoreDirective;
417
+ exports.createConditionalBrowserStoreArrayDirective = createConditionalBrowserStoreArrayDirective;
418
+ exports.createConditionalStoreArrayDirective = createConditionalStoreArrayDirective;
409
419
  exports.createStoreArrayDirective = createStoreArrayDirective;
410
420
  exports.createStoreDirective = createStoreDirective;
411
421
  exports.directiveAttributes = directiveAttributes;
@@ -0,0 +1,251 @@
1
+ import { computed, asWritable, writable, readable } from "@amadeus-it-group/tansu";
2
+ import { portal } from "./services/portal.js";
3
+ import { siblingsInert } from "./services/siblingsInert.js";
4
+ import { createTransition } from "./services/transitions/baseTransitions.js";
5
+ import { a as bindDirective, n as mergeDirectives, p as createAttributesDirective } from "./dom-Bcg9ORcA.js";
6
+ import { noop } from "./utils/func.js";
7
+ import { r as removeScrollbars, a as revertScrollbars } from "./scrollbars-CcxSrnCx.js";
8
+ import { writablesForProps, bindableProp, stateStores, true$ } from "./utils/stores.js";
9
+ import { createWidgetFactory } from "./utils/widget.js";
10
+ import { c as typeBoolean, g as typeFunction, b as typeNumberInRangeFactory, h as typeHTMLElementOrNull, e as typeString } from "./writables-e0tyaQpe.js";
11
+ import { focusElement } from "./services/focusElement.js";
12
+ function getDrawerDefaultConfig() {
13
+ return {
14
+ ...defaultDrawerConfig
15
+ };
16
+ }
17
+ const defaultDrawerConfig = {
18
+ animated: true,
19
+ ariaDescribedBy: "",
20
+ ariaLabelledBy: "",
21
+ backdropClass: "",
22
+ backdropTransition: noop,
23
+ className: "w-full",
24
+ visible: false,
25
+ container: typeof window !== "undefined" ? document.body : null,
26
+ transition: noop,
27
+ verticalTransition: noop,
28
+ onHidden: noop,
29
+ onShown: noop,
30
+ width: 200,
31
+ height: 200,
32
+ onWidthChange: noop,
33
+ onHeightChange: noop,
34
+ onVisibleChange: noop,
35
+ resizable: false,
36
+ backdrop: true,
37
+ bodyScroll: false
38
+ };
39
+ const configValidator = {
40
+ animated: typeBoolean,
41
+ ariaDescribedBy: typeString,
42
+ ariaLabelledBy: typeString,
43
+ backdropClass: typeString,
44
+ backdropTransition: typeFunction,
45
+ className: typeString,
46
+ visible: typeBoolean,
47
+ transition: typeFunction,
48
+ verticalTransition: typeFunction,
49
+ container: typeHTMLElementOrNull,
50
+ onHidden: typeFunction,
51
+ onShown: typeFunction,
52
+ width: typeNumberInRangeFactory(0, Infinity),
53
+ height: typeNumberInRangeFactory(0, Infinity),
54
+ onWidthChange: typeFunction,
55
+ onHeightChange: typeFunction,
56
+ onVisibleChange: typeFunction,
57
+ resizable: typeBoolean,
58
+ backdrop: typeBoolean,
59
+ bodyScroll: typeBoolean
60
+ };
61
+ const createDrawer = createWidgetFactory("drawer", (config) => {
62
+ const [
63
+ {
64
+ backdrop$,
65
+ backdropTransition$,
66
+ backdropClass$,
67
+ bodyScroll$,
68
+ transition$,
69
+ verticalTransition$,
70
+ visible$: requestedVisible$,
71
+ container$,
72
+ className$,
73
+ animated$,
74
+ ariaDescribedBy$,
75
+ ariaLabelledBy$,
76
+ onHidden$,
77
+ onShown$,
78
+ width$: _dirtyWidth$,
79
+ height$: _dirtyHeight$,
80
+ onWidthChange$,
81
+ onHeightChange$,
82
+ onVisibleChange$,
83
+ ...stateProps
84
+ },
85
+ patch
86
+ ] = writablesForProps(defaultDrawerConfig, config, configValidator);
87
+ const isVertical = computed(() => {
88
+ const isVertical2 = ["block-start", "block-end"].some((placement) => className$().includes(placement));
89
+ return isVertical2;
90
+ });
91
+ const transition = createTransition({
92
+ props: {
93
+ animated: animated$,
94
+ animatedOnInit: animated$,
95
+ transition: asWritable(computed(() => isVertical() ? verticalTransition$() : transition$())),
96
+ visible: requestedVisible$,
97
+ onVisibleChange: onVisibleChange$,
98
+ onHidden: onHidden$,
99
+ onShown: onShown$
100
+ }
101
+ });
102
+ const width$ = bindableProp(_dirtyWidth$, onWidthChange$);
103
+ const height$ = bindableProp(_dirtyHeight$, onHeightChange$);
104
+ const drawerPortalDirective = bindDirective(
105
+ portal,
106
+ computed(() => ({ container: container$() }))
107
+ );
108
+ const drawerAttributeDirective = createAttributesDirective(() => ({
109
+ attributes: {
110
+ class: className$,
111
+ role: readable("dialog"),
112
+ "aria-describedby": ariaDescribedBy$,
113
+ "aria-labelledby": ariaLabelledBy$,
114
+ "aria-modal": readable("true"),
115
+ tabIndex: readable("-1")
116
+ },
117
+ styles: {
118
+ width: computed(() => isVertical() ? "100%" : `${width$()}px`),
119
+ height: computed(() => isVertical() ? `${height$()}px` : "100%"),
120
+ position: computed(() => container$() !== document.body && container$() !== null ? "relative" : "fixed"),
121
+ outline: readable("none")
122
+ },
123
+ events: {
124
+ keydown: async (e) => {
125
+ const { key } = e;
126
+ if (key === "Escape") {
127
+ await transition.api.hide();
128
+ }
129
+ }
130
+ }
131
+ }));
132
+ const containerDirective = createAttributesDirective(() => ({
133
+ styles: {
134
+ width: computed(() => isVertical() ? "100%" : `${width$()}px`),
135
+ height: computed(() => isVertical() ? `${height$()}px` : "100%")
136
+ }
137
+ }));
138
+ const backdropTransition = createTransition({
139
+ props: {
140
+ animated: animated$,
141
+ transition: backdropTransition$
142
+ }
143
+ });
144
+ const backdropPortalDirective = bindDirective(
145
+ portal,
146
+ computed(() => {
147
+ const container = container$();
148
+ const element = container ? transition.stores.element$() : void 0;
149
+ return {
150
+ container,
151
+ insertBefore: element?.parentElement === container ? element : void 0
152
+ };
153
+ })
154
+ );
155
+ const backdropHidden$ = computed(() => {
156
+ if (!bodyScroll$()) {
157
+ if (hidden$()) {
158
+ revertScrollbars();
159
+ } else {
160
+ removeScrollbars();
161
+ }
162
+ }
163
+ return !backdrop$() || hidden$();
164
+ });
165
+ const backdropAttributeDirective = createAttributesDirective(() => ({
166
+ attributes: {
167
+ class: backdropClass$,
168
+ "data-agnos-ignore-inert": true$
169
+ },
170
+ events: {
171
+ click: async () => {
172
+ await transition.api.hide();
173
+ }
174
+ }
175
+ }));
176
+ const direction = computed(() => ["inline-start", "block-start"].some((placement) => className$().includes(placement)) ? 1 : -1);
177
+ const startDimension = writable(0);
178
+ const startPos = writable(0);
179
+ const dimension = writable(0);
180
+ const splitterDirective = createAttributesDirective(() => ({
181
+ attributes: {
182
+ draggable: readable("true")
183
+ },
184
+ events: {
185
+ dragstart: (e) => {
186
+ startPos.set(isVertical() ? e.clientY : e.clientX);
187
+ startDimension.set(isVertical() ? height$() : width$());
188
+ e.dataTransfer?.setDragImage(new Image(), 0, 0);
189
+ },
190
+ dragend: (e) => {
191
+ document.body.style.cursor = "";
192
+ updateDimension(e);
193
+ },
194
+ dragover: (event) => {
195
+ event.preventDefault();
196
+ },
197
+ drag: (e) => {
198
+ updateDimension(e);
199
+ }
200
+ }
201
+ }));
202
+ const updateDimension = (e) => {
203
+ if (!isVertical() && e.clientX > 0) {
204
+ dimension.set(startDimension() + direction() * (e.clientX - startPos()));
205
+ width$.set(dimension());
206
+ } else if (isVertical() && e.clientY > 0) {
207
+ dimension.set(startDimension() + direction() * (e.clientY - startPos()));
208
+ height$.set(dimension());
209
+ }
210
+ };
211
+ const visible$ = transition.stores.visible$;
212
+ const transitioning$ = computed(() => transition.stores.transitioning$() || backdropTransition.stores.transitioning$());
213
+ const hidden$ = computed(() => !transitioning$() && !visible$());
214
+ const widget = {
215
+ ...stateStores({
216
+ ...stateProps,
217
+ backdropClass$,
218
+ className$,
219
+ container$,
220
+ visible$,
221
+ backdropHidden$,
222
+ hidden$
223
+ }),
224
+ patch,
225
+ api: {
226
+ open: transition.api.show,
227
+ close: transition.api.hide
228
+ },
229
+ directives: {
230
+ containerDirective,
231
+ drawerPortalDirective,
232
+ drawerDirective: mergeDirectives(
233
+ transition.directives.directive,
234
+ bindDirective(
235
+ siblingsInert,
236
+ computed(() => !bodyScroll$())
237
+ ),
238
+ drawerAttributeDirective,
239
+ focusElement
240
+ ),
241
+ backdropPortalDirective,
242
+ backdropDirective: mergeDirectives(backdropTransition.directives.directive, backdropAttributeDirective),
243
+ splitterDirective
244
+ }
245
+ };
246
+ return widget;
247
+ });
248
+ export {
249
+ createDrawer as c,
250
+ getDrawerDefaultConfig as g
251
+ };
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ const tansu = require("@amadeus-it-group/tansu");
3
+ const services_portal = require("./services/portal.cjs");
4
+ const services_siblingsInert = require("./services/siblingsInert.cjs");
5
+ const services_transitions_baseTransitions = require("./services/transitions/baseTransitions.cjs");
6
+ const utils_directive = require("./dom-C2gi9OCP.cjs");
7
+ const utils_func = require("./utils/func.cjs");
8
+ const scrollbars = require("./scrollbars-CT87iv_6.cjs");
9
+ const utils_stores = require("./utils/stores.cjs");
10
+ const utils_widget = require("./utils/widget.cjs");
11
+ const utils_writables = require("./writables-DcGT98a7.cjs");
12
+ const services_focusElement = require("./services/focusElement.cjs");
13
+ function getDrawerDefaultConfig() {
14
+ return {
15
+ ...defaultDrawerConfig
16
+ };
17
+ }
18
+ const defaultDrawerConfig = {
19
+ animated: true,
20
+ ariaDescribedBy: "",
21
+ ariaLabelledBy: "",
22
+ backdropClass: "",
23
+ backdropTransition: utils_func.noop,
24
+ className: "w-full",
25
+ visible: false,
26
+ container: typeof window !== "undefined" ? document.body : null,
27
+ transition: utils_func.noop,
28
+ verticalTransition: utils_func.noop,
29
+ onHidden: utils_func.noop,
30
+ onShown: utils_func.noop,
31
+ width: 200,
32
+ height: 200,
33
+ onWidthChange: utils_func.noop,
34
+ onHeightChange: utils_func.noop,
35
+ onVisibleChange: utils_func.noop,
36
+ resizable: false,
37
+ backdrop: true,
38
+ bodyScroll: false
39
+ };
40
+ const configValidator = {
41
+ animated: utils_writables.typeBoolean,
42
+ ariaDescribedBy: utils_writables.typeString,
43
+ ariaLabelledBy: utils_writables.typeString,
44
+ backdropClass: utils_writables.typeString,
45
+ backdropTransition: utils_writables.typeFunction,
46
+ className: utils_writables.typeString,
47
+ visible: utils_writables.typeBoolean,
48
+ transition: utils_writables.typeFunction,
49
+ verticalTransition: utils_writables.typeFunction,
50
+ container: utils_writables.typeHTMLElementOrNull,
51
+ onHidden: utils_writables.typeFunction,
52
+ onShown: utils_writables.typeFunction,
53
+ width: utils_writables.typeNumberInRangeFactory(0, Infinity),
54
+ height: utils_writables.typeNumberInRangeFactory(0, Infinity),
55
+ onWidthChange: utils_writables.typeFunction,
56
+ onHeightChange: utils_writables.typeFunction,
57
+ onVisibleChange: utils_writables.typeFunction,
58
+ resizable: utils_writables.typeBoolean,
59
+ backdrop: utils_writables.typeBoolean,
60
+ bodyScroll: utils_writables.typeBoolean
61
+ };
62
+ const createDrawer = utils_widget.createWidgetFactory("drawer", (config) => {
63
+ const [
64
+ {
65
+ backdrop$,
66
+ backdropTransition$,
67
+ backdropClass$,
68
+ bodyScroll$,
69
+ transition$,
70
+ verticalTransition$,
71
+ visible$: requestedVisible$,
72
+ container$,
73
+ className$,
74
+ animated$,
75
+ ariaDescribedBy$,
76
+ ariaLabelledBy$,
77
+ onHidden$,
78
+ onShown$,
79
+ width$: _dirtyWidth$,
80
+ height$: _dirtyHeight$,
81
+ onWidthChange$,
82
+ onHeightChange$,
83
+ onVisibleChange$,
84
+ ...stateProps
85
+ },
86
+ patch
87
+ ] = utils_stores.writablesForProps(defaultDrawerConfig, config, configValidator);
88
+ const isVertical = tansu.computed(() => {
89
+ const isVertical2 = ["block-start", "block-end"].some((placement) => className$().includes(placement));
90
+ return isVertical2;
91
+ });
92
+ const transition = services_transitions_baseTransitions.createTransition({
93
+ props: {
94
+ animated: animated$,
95
+ animatedOnInit: animated$,
96
+ transition: tansu.asWritable(tansu.computed(() => isVertical() ? verticalTransition$() : transition$())),
97
+ visible: requestedVisible$,
98
+ onVisibleChange: onVisibleChange$,
99
+ onHidden: onHidden$,
100
+ onShown: onShown$
101
+ }
102
+ });
103
+ const width$ = utils_stores.bindableProp(_dirtyWidth$, onWidthChange$);
104
+ const height$ = utils_stores.bindableProp(_dirtyHeight$, onHeightChange$);
105
+ const drawerPortalDirective = utils_directive.bindDirective(
106
+ services_portal.portal,
107
+ tansu.computed(() => ({ container: container$() }))
108
+ );
109
+ const drawerAttributeDirective = utils_directive.createAttributesDirective(() => ({
110
+ attributes: {
111
+ class: className$,
112
+ role: tansu.readable("dialog"),
113
+ "aria-describedby": ariaDescribedBy$,
114
+ "aria-labelledby": ariaLabelledBy$,
115
+ "aria-modal": tansu.readable("true"),
116
+ tabIndex: tansu.readable("-1")
117
+ },
118
+ styles: {
119
+ width: tansu.computed(() => isVertical() ? "100%" : `${width$()}px`),
120
+ height: tansu.computed(() => isVertical() ? `${height$()}px` : "100%"),
121
+ position: tansu.computed(() => container$() !== document.body && container$() !== null ? "relative" : "fixed"),
122
+ outline: tansu.readable("none")
123
+ },
124
+ events: {
125
+ keydown: async (e) => {
126
+ const { key } = e;
127
+ if (key === "Escape") {
128
+ await transition.api.hide();
129
+ }
130
+ }
131
+ }
132
+ }));
133
+ const containerDirective = utils_directive.createAttributesDirective(() => ({
134
+ styles: {
135
+ width: tansu.computed(() => isVertical() ? "100%" : `${width$()}px`),
136
+ height: tansu.computed(() => isVertical() ? `${height$()}px` : "100%")
137
+ }
138
+ }));
139
+ const backdropTransition = services_transitions_baseTransitions.createTransition({
140
+ props: {
141
+ animated: animated$,
142
+ transition: backdropTransition$
143
+ }
144
+ });
145
+ const backdropPortalDirective = utils_directive.bindDirective(
146
+ services_portal.portal,
147
+ tansu.computed(() => {
148
+ const container = container$();
149
+ const element = container ? transition.stores.element$() : void 0;
150
+ return {
151
+ container,
152
+ insertBefore: element?.parentElement === container ? element : void 0
153
+ };
154
+ })
155
+ );
156
+ const backdropHidden$ = tansu.computed(() => {
157
+ if (!bodyScroll$()) {
158
+ if (hidden$()) {
159
+ scrollbars.revertScrollbars();
160
+ } else {
161
+ scrollbars.removeScrollbars();
162
+ }
163
+ }
164
+ return !backdrop$() || hidden$();
165
+ });
166
+ const backdropAttributeDirective = utils_directive.createAttributesDirective(() => ({
167
+ attributes: {
168
+ class: backdropClass$,
169
+ "data-agnos-ignore-inert": utils_stores.true$
170
+ },
171
+ events: {
172
+ click: async () => {
173
+ await transition.api.hide();
174
+ }
175
+ }
176
+ }));
177
+ const direction = tansu.computed(() => ["inline-start", "block-start"].some((placement) => className$().includes(placement)) ? 1 : -1);
178
+ const startDimension = tansu.writable(0);
179
+ const startPos = tansu.writable(0);
180
+ const dimension = tansu.writable(0);
181
+ const splitterDirective = utils_directive.createAttributesDirective(() => ({
182
+ attributes: {
183
+ draggable: tansu.readable("true")
184
+ },
185
+ events: {
186
+ dragstart: (e) => {
187
+ startPos.set(isVertical() ? e.clientY : e.clientX);
188
+ startDimension.set(isVertical() ? height$() : width$());
189
+ e.dataTransfer?.setDragImage(new Image(), 0, 0);
190
+ },
191
+ dragend: (e) => {
192
+ document.body.style.cursor = "";
193
+ updateDimension(e);
194
+ },
195
+ dragover: (event) => {
196
+ event.preventDefault();
197
+ },
198
+ drag: (e) => {
199
+ updateDimension(e);
200
+ }
201
+ }
202
+ }));
203
+ const updateDimension = (e) => {
204
+ if (!isVertical() && e.clientX > 0) {
205
+ dimension.set(startDimension() + direction() * (e.clientX - startPos()));
206
+ width$.set(dimension());
207
+ } else if (isVertical() && e.clientY > 0) {
208
+ dimension.set(startDimension() + direction() * (e.clientY - startPos()));
209
+ height$.set(dimension());
210
+ }
211
+ };
212
+ const visible$ = transition.stores.visible$;
213
+ const transitioning$ = tansu.computed(() => transition.stores.transitioning$() || backdropTransition.stores.transitioning$());
214
+ const hidden$ = tansu.computed(() => !transitioning$() && !visible$());
215
+ const widget = {
216
+ ...utils_stores.stateStores({
217
+ ...stateProps,
218
+ backdropClass$,
219
+ className$,
220
+ container$,
221
+ visible$,
222
+ backdropHidden$,
223
+ hidden$
224
+ }),
225
+ patch,
226
+ api: {
227
+ open: transition.api.show,
228
+ close: transition.api.hide
229
+ },
230
+ directives: {
231
+ containerDirective,
232
+ drawerPortalDirective,
233
+ drawerDirective: utils_directive.mergeDirectives(
234
+ transition.directives.directive,
235
+ utils_directive.bindDirective(
236
+ services_siblingsInert.siblingsInert,
237
+ tansu.computed(() => !bodyScroll$())
238
+ ),
239
+ drawerAttributeDirective,
240
+ services_focusElement.focusElement
241
+ ),
242
+ backdropPortalDirective,
243
+ backdropDirective: utils_directive.mergeDirectives(backdropTransition.directives.directive, backdropAttributeDirective),
244
+ splitterDirective
245
+ }
246
+ };
247
+ return widget;
248
+ });
249
+ exports.createDrawer = createDrawer;
250
+ exports.getDrawerDefaultConfig = getDrawerDefaultConfig;