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

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 (102) hide show
  1. package/{accordion-_zen-g8l.js → accordion-47EpOD36.js} +4 -3
  2. package/{accordion-B5LiN1uy.cjs → accordion-nxveC0GZ.cjs} +4 -3
  3. package/{alert-B-jQDQcB.cjs → alert-AhaliJ17.cjs} +1 -1
  4. package/{alert-gGz2CDS9.js → alert-anMaigvi.js} +1 -1
  5. package/{collapse-BV4kD3j9.js → collapse-CrfvGo_T.js} +2 -2
  6. package/{collapse-gLiT080Y.cjs → collapse-Da_27YUU.cjs} +2 -2
  7. package/{common-D3QcdJ6S.cjs → common-B5jS-Ih_.cjs} +1 -1
  8. package/{common-DK0ADNTX.js → common-CCxNtFNM.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 +2 -2
  14. package/components/carousel/index.js +2 -2
  15. package/components/collapse/index.cjs +1 -1
  16. package/components/collapse/index.js +1 -1
  17. package/components/drawer/drawer.d.ts +32 -25
  18. package/components/drawer/index.cjs +1 -1
  19. package/components/drawer/index.js +1 -1
  20. package/components/modal/index.cjs +1 -1
  21. package/components/modal/index.js +1 -1
  22. package/components/pagination/index.cjs +1 -1
  23. package/components/pagination/index.js +1 -1
  24. package/components/progressbar/index.cjs +1 -1
  25. package/components/progressbar/index.js +1 -1
  26. package/components/rating/index.cjs +1 -1
  27. package/components/rating/index.js +1 -1
  28. package/components/select/index.cjs +1 -1
  29. package/components/select/index.js +1 -1
  30. package/components/slider/index.cjs +1 -1
  31. package/components/slider/index.js +1 -1
  32. package/components/toast/index.cjs +1 -1
  33. package/components/toast/index.js +1 -1
  34. package/components/tree/index.cjs +1 -1
  35. package/components/tree/index.js +1 -1
  36. package/{dom-C2gi9OCP.cjs → dom-Cm9_uROp.cjs} +76 -6
  37. package/{dom-Bcg9ORcA.js → dom-DD1hAVZy.js} +76 -6
  38. package/drawer-Caz4Uypu.js +291 -0
  39. package/{drawer-DP7UPojk.cjs → drawer-DOi0TqZC.cjs} +131 -91
  40. package/index.cjs +16 -14
  41. package/index.js +21 -19
  42. package/{modal-DiXZXYjR.cjs → modal-B_3Uxplo.cjs} +5 -5
  43. package/{modal-CAvQW-vo.js → modal-cKd3qUn1.js} +5 -5
  44. package/package.json +1 -1
  45. package/{pagination-DvZ2rLsz.cjs → pagination-2Vor6JPZ.cjs} +2 -2
  46. package/{pagination-BKbMROV6.js → pagination-DlOyP_2C.js} +2 -2
  47. package/{progressbar-D8zIcm9n.js → progressbar-B5g76eMV.js} +2 -2
  48. package/{progressbar-i9xfAxb7.cjs → progressbar-DyBRINco.cjs} +2 -2
  49. package/{rating-DmG4oUkr.cjs → rating-C0y1j4SC.cjs} +2 -2
  50. package/{rating-DEXTGWCU.js → rating-C7C4-p4B.js} +2 -2
  51. package/{select-MFjAnIt7.cjs → select-Dhsb9msC.cjs} +1 -1
  52. package/{select-Bw68Xdu5.js → select-nnl00UWY.js} +1 -1
  53. package/services/floatingUI.cjs +1 -1
  54. package/services/floatingUI.js +1 -1
  55. package/services/focusElement.cjs +1 -1
  56. package/services/focusElement.js +1 -1
  57. package/services/focustrack.cjs +1 -1
  58. package/services/focustrack.js +1 -1
  59. package/services/matchMedia.cjs +1 -1
  60. package/services/matchMedia.js +1 -1
  61. package/services/navManager.cjs +1 -1
  62. package/services/navManager.js +1 -1
  63. package/services/pointerdownPosition.cjs +60 -0
  64. package/services/pointerdownPosition.d.ts +42 -0
  65. package/services/pointerdownPosition.js +60 -0
  66. package/services/portal.cjs +1 -1
  67. package/services/portal.js +1 -1
  68. package/services/resizeObserver.cjs +40 -20
  69. package/services/resizeObserver.d.ts +10 -2
  70. package/services/resizeObserver.js +41 -21
  71. package/services/siblingsInert.cjs +1 -1
  72. package/services/siblingsInert.js +1 -1
  73. package/services/transitions/baseTransitions.cjs +2 -2
  74. package/services/transitions/baseTransitions.js +2 -2
  75. package/services/transitions/collapse.cjs +11 -15
  76. package/services/transitions/collapse.js +11 -15
  77. package/services/transitions/cssTransitions.cjs +1 -1
  78. package/services/transitions/cssTransitions.js +1 -1
  79. package/services/transitions/simpleClassTransition.cjs +1 -1
  80. package/services/transitions/simpleClassTransition.js +1 -1
  81. package/{slider-Cx50Eghd.js → slider-B4WrdTeE.js} +121 -170
  82. package/{slider-Dl4Trh32.cjs → slider-DTO58syz.cjs} +120 -169
  83. package/{toaster-_p1GTtHI.js → toaster-CRPErgI2.js} +3 -3
  84. package/{toaster-UDglac7x.cjs → toaster-CT148JSJ.cjs} +3 -3
  85. package/{tree-rGHtmCnS.cjs → tree-C4l2Wqny.cjs} +2 -2
  86. package/{tree-DV0tfPlZ.js → tree-CHpFqJPx.js} +2 -2
  87. package/types.cjs +2 -2
  88. package/types.d.ts +22 -3
  89. package/types.js +2 -2
  90. package/utils/directive.cjs +1 -1
  91. package/utils/directive.d.ts +2 -2
  92. package/utils/directive.js +1 -1
  93. package/utils/internal/dom.d.ts +2 -0
  94. package/utils/internal/ssrHTMLElement.d.ts +7 -1
  95. package/utils/stores.cjs +1 -1
  96. package/utils/stores.js +1 -1
  97. package/utils/writables.cjs +2 -1
  98. package/utils/writables.d.ts +7 -0
  99. package/utils/writables.js +6 -5
  100. package/{writables-DcGT98a7.cjs → writables-Dt68gADJ.cjs} +4 -0
  101. package/{writables-e0tyaQpe.js → writables-Is1bF1Vt.js} +10 -6
  102. package/drawer-D5SO73ew.js +0 -251
@@ -1,11 +1,73 @@
1
1
  import { BROWSER } from "esm-env";
2
- import { noop } from "./utils/func.js";
3
2
  import { readable, batch, asReadable, writable, computed } from "@amadeus-it-group/tansu";
4
- const ssrHTMLElementAttributesAndStyle = Symbol("attributesAndStyle");
3
+ import { noop } from "./utils/func.js";
4
+ const importantSuffixRegExp = /\s*!important$/;
5
+ const withoutImportant = (value) => value?.replace(importantSuffixRegExp, "") ?? "";
6
+ const toKebabCase = (str) => str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
7
+ const getStyleKeyFromDirectProp = (str) => {
8
+ if (typeof str !== "string" || str.startsWith("--")) {
9
+ return void 0;
10
+ }
11
+ return toKebabCase(str);
12
+ };
13
+ const getStyleKeyFromMethods = (str) => {
14
+ if (!str.startsWith("--") && str !== toKebabCase(str)) {
15
+ return void 0;
16
+ }
17
+ return str;
18
+ };
19
+ const ssrHTMLElementStyle = /* @__PURE__ */ Symbol("style");
20
+ class SSRStyle {
21
+ // all styles in kebab-case, including custom properties:
22
+ [ssrHTMLElementStyle] = {};
23
+ constructor() {
24
+ return new Proxy(this, {
25
+ get: (target, prop) => {
26
+ const styleKey = prop in target ? void 0 : getStyleKeyFromDirectProp(prop);
27
+ if (styleKey) {
28
+ return withoutImportant(target[ssrHTMLElementStyle][styleKey]);
29
+ } else {
30
+ return target[prop];
31
+ }
32
+ },
33
+ set: (target, prop, value) => {
34
+ const styleKey = prop in target ? void 0 : getStyleKeyFromDirectProp(prop);
35
+ if (styleKey) {
36
+ target.setProperty(styleKey, value);
37
+ } else {
38
+ target[prop] = value;
39
+ }
40
+ return true;
41
+ }
42
+ });
43
+ }
44
+ setProperty(property, value, priority) {
45
+ if (!value) {
46
+ this.removeProperty(property);
47
+ return;
48
+ }
49
+ const key = getStyleKeyFromMethods(property);
50
+ if (!key || priority !== "important" && priority !== "" && priority != null || importantSuffixRegExp.test(value)) {
51
+ return;
52
+ }
53
+ this[ssrHTMLElementStyle][key] = value + (priority ? " !important" : "");
54
+ }
55
+ removeProperty(property) {
56
+ const key = getStyleKeyFromMethods(property);
57
+ if (!key) {
58
+ return "";
59
+ }
60
+ const style = this[ssrHTMLElementStyle];
61
+ const value = style[key];
62
+ delete style[key];
63
+ return withoutImportant(value);
64
+ }
65
+ }
66
+ const ssrHTMLElementAttributesAndStyle = /* @__PURE__ */ Symbol("attributesAndStyle");
5
67
  const spaceRegExp = /\s+/;
6
68
  const ssrHTMLElement = () => {
7
69
  const attributes = {};
8
- const style = {};
70
+ const style = new SSRStyle();
9
71
  let classNames = /* @__PURE__ */ new Set();
10
72
  const toggleClass = (className, force = !classNames.has(className)) => {
11
73
  if (force) {
@@ -40,10 +102,12 @@ const ssrHTMLElement = () => {
40
102
  }
41
103
  },
42
104
  [ssrHTMLElementAttributesAndStyle]() {
43
- return { attributes: { ...attributes }, classNames: [...classNames], style: { ...style } };
105
+ return { attributes: { ...attributes }, classNames: [...classNames], style: { ...style[ssrHTMLElementStyle] } };
44
106
  }
45
107
  };
46
108
  };
109
+ const cssEscapeStyleName = (styleName) => styleName.replace(/([^\w-])/gi, "\\$1");
110
+ const cssTextFromObject = (style) => Object.entries(style).filter(([, value]) => !!value).map(([name, value]) => `${cssEscapeStyleName(name)}: ${value};`).join("");
47
111
  function r(e) {
48
112
  var t, f, n = "";
49
113
  if ("string" == typeof e || "number" == typeof e) n += e;
@@ -302,7 +366,7 @@ function directiveAttributes(...directives) {
302
366
  if (classNames.length) {
303
367
  attributes["class"] = classNames.join(" ");
304
368
  }
305
- const stringStyle = Object.entries(style).filter(([, value]) => !!value).map(([name, value]) => `${name}: ${value};`).join("");
369
+ const stringStyle = cssTextFromObject(style);
306
370
  if (stringStyle.length) {
307
371
  attributes["style"] = stringStyle;
308
372
  }
@@ -387,10 +451,16 @@ function bindAttribute(node, attributeName, value$) {
387
451
  const isClass = attributeName === "class";
388
452
  return isClass ? classNamesSubscribe(node, value$) : attributeSubscribe(node, attributeName, value$);
389
453
  }
454
+ const isCustomProperty = (styleName) => styleName.startsWith("--");
390
455
  function bindStyle(node, styleName, value$) {
391
456
  return value$.subscribe((value) => {
392
457
  const style = node.style;
393
- style[styleName] = "" + (notEmpty(value) ? value : "");
458
+ value = "" + (notEmpty(value) ? value : "");
459
+ if (isCustomProperty(styleName)) {
460
+ style.setProperty(styleName, value);
461
+ } else {
462
+ style[styleName] = value;
463
+ }
394
464
  });
395
465
  }
396
466
  function bindClassName(node, className, value$) {
@@ -0,0 +1,291 @@
1
+ import { computed, asWritable, writable, untrack, readable } from "@amadeus-it-group/tansu";
2
+ import { focusElement } from "./services/focusElement.js";
3
+ import { createPointerdownPositionDirective } from "./services/pointerdownPosition.js";
4
+ import { portal } from "./services/portal.js";
5
+ import { siblingsInert } from "./services/siblingsInert.js";
6
+ import { createTransition } from "./services/transitions/baseTransitions.js";
7
+ import { a as bindDirective, l as createBrowserStoreDirective, n as mergeDirectives, p as createAttributesDirective, d as directiveSubscribe, i as isBrowserHTMLElement } from "./dom-DD1hAVZy.js";
8
+ import { noop } from "./utils/func.js";
9
+ import { r as removeScrollbars, a as revertScrollbars } from "./scrollbars-CcxSrnCx.js";
10
+ import { writablesForProps, bindableProp, stateStores, true$ } from "./utils/stores.js";
11
+ import { createWidgetFactory } from "./utils/widget.js";
12
+ import { g as typeNumberOrNull, c as typeBoolean, h as typeFunction, i as typeHTMLElementOrNull, e as typeString } from "./writables-Is1bF1Vt.js";
13
+ function getDrawerDefaultConfig() {
14
+ return {
15
+ ...defaultDrawerConfig
16
+ };
17
+ }
18
+ const defaultDrawerConfig = {
19
+ animated: true,
20
+ ariaDescribedBy: "",
21
+ ariaLabelledBy: "",
22
+ backdropClass: "",
23
+ backdropTransition: noop,
24
+ className: "w-full",
25
+ visible: false,
26
+ container: typeof window !== "undefined" ? document.body : null,
27
+ transition: noop,
28
+ verticalTransition: noop,
29
+ onHidden: noop,
30
+ onShown: noop,
31
+ onSizeChange: noop,
32
+ onVisibleChange: noop,
33
+ onMinimizedChange: noop,
34
+ onMaximizedChange: noop,
35
+ onResizingChange: noop,
36
+ resizable: false,
37
+ backdrop: true,
38
+ bodyScroll: false,
39
+ size: null
40
+ };
41
+ const configValidator = {
42
+ animated: typeBoolean,
43
+ ariaDescribedBy: typeString,
44
+ ariaLabelledBy: typeString,
45
+ backdropClass: typeString,
46
+ backdropTransition: typeFunction,
47
+ className: typeString,
48
+ visible: typeBoolean,
49
+ transition: typeFunction,
50
+ verticalTransition: typeFunction,
51
+ container: typeHTMLElementOrNull,
52
+ onHidden: typeFunction,
53
+ onShown: typeFunction,
54
+ onSizeChange: typeFunction,
55
+ onVisibleChange: typeFunction,
56
+ onMinimizedChange: typeFunction,
57
+ onMaximizedChange: typeFunction,
58
+ onResizingChange: typeFunction,
59
+ resizable: typeBoolean,
60
+ backdrop: typeBoolean,
61
+ bodyScroll: typeBoolean,
62
+ size: typeNumberOrNull
63
+ };
64
+ const createDrawer = createWidgetFactory("drawer", (config) => {
65
+ const [
66
+ {
67
+ backdrop$,
68
+ backdropTransition$,
69
+ backdropClass$,
70
+ bodyScroll$,
71
+ transition$,
72
+ verticalTransition$,
73
+ visible$: requestedVisible$,
74
+ container$,
75
+ className$,
76
+ size$: _dirtySize$,
77
+ animated$,
78
+ ariaDescribedBy$,
79
+ ariaLabelledBy$,
80
+ onHidden$,
81
+ onShown$,
82
+ onSizeChange$,
83
+ onVisibleChange$,
84
+ onMinimizedChange$,
85
+ onMaximizedChange$,
86
+ onResizingChange$,
87
+ ...stateProps
88
+ },
89
+ patch
90
+ ] = writablesForProps(defaultDrawerConfig, config, configValidator);
91
+ const size$ = bindableProp(_dirtySize$, onSizeChange$, (value) => value ? Math.round(value) : value);
92
+ const isVertical$ = computed(() => {
93
+ const isVertical = ["block-start", "block-end"].some((placement) => className$().includes(placement));
94
+ return isVertical;
95
+ });
96
+ const transition = createTransition({
97
+ props: {
98
+ animated: animated$,
99
+ animatedOnInit: animated$,
100
+ transition: asWritable(computed(() => isVertical$() ? verticalTransition$() : transition$())),
101
+ visible: requestedVisible$,
102
+ onVisibleChange: onVisibleChange$,
103
+ onHidden: onHidden$,
104
+ onShown: onShown$
105
+ }
106
+ });
107
+ const drawerPortalDirective = bindDirective(
108
+ portal,
109
+ computed(() => ({ container: container$() }))
110
+ );
111
+ const { directive: drawerElementDirective, element$: drawerElement$ } = createBrowserStoreDirective();
112
+ const drawerAttributeDirective = mergeDirectives(
113
+ drawerElementDirective,
114
+ createAttributesDirective(() => ({
115
+ attributes: {
116
+ class: className$,
117
+ role: readable("dialog"),
118
+ "aria-describedby": ariaDescribedBy$,
119
+ "aria-labelledby": ariaLabelledBy$,
120
+ "aria-modal": readable("true"),
121
+ tabIndex: readable("-1")
122
+ },
123
+ styles: {
124
+ position: computed(() => {
125
+ const container = container$();
126
+ return container && isBrowserHTMLElement(container) && container !== document.body ? "relative" : "fixed";
127
+ }),
128
+ outline: readable("none")
129
+ },
130
+ events: {
131
+ keydown: async (e) => {
132
+ if (e.key === "Escape") {
133
+ await transition.api.hide();
134
+ }
135
+ }
136
+ }
137
+ }))
138
+ );
139
+ const backdropTransition = createTransition({
140
+ props: {
141
+ animated: animated$,
142
+ transition: backdropTransition$
143
+ }
144
+ });
145
+ const backdropPortalDirective = bindDirective(
146
+ portal,
147
+ 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$ = computed(() => {
157
+ if (!bodyScroll$()) {
158
+ if (hidden$()) {
159
+ revertScrollbars();
160
+ } else {
161
+ removeScrollbars();
162
+ }
163
+ }
164
+ return !backdrop$() || hidden$();
165
+ });
166
+ const backdropAttributeDirective = createAttributesDirective(() => ({
167
+ attributes: {
168
+ class: backdropClass$,
169
+ "data-agnos-ignore-inert": true$
170
+ },
171
+ events: {
172
+ click: async () => await transition.api.hide()
173
+ }
174
+ }));
175
+ const direction$ = computed(() => ["inline-start", "block-start"].some((placement) => className$().includes(placement)) ? 1 : -1);
176
+ const isMinimized$ = writable(void 0);
177
+ const isMaximized$ = writable(void 0);
178
+ function setSize(size) {
179
+ const drawerElement = drawerElement$();
180
+ const isVertical = isVertical$();
181
+ size = Math.round(Math.max(0, size));
182
+ drawerElement.style[isVertical ? "height" : "width"] = `${size}px`;
183
+ const elementSize = Math.round(drawerElement[isVertical ? "offsetHeight" : "offsetWidth"]);
184
+ size$.set(elementSize);
185
+ isMinimized$.set(size != null && (size < elementSize || size === 0));
186
+ isMaximized$.set(!!size && size > elementSize);
187
+ return elementSize;
188
+ }
189
+ const splitterDirective = mergeDirectives(
190
+ createPointerdownPositionDirective((event) => {
191
+ const drawerElement = drawerElement$();
192
+ const isVertical = isVertical$();
193
+ const startSize = drawerElement[isVertical ? "offsetHeight" : "offsetWidth"];
194
+ const clientXorY = isVertical ? "clientY" : "clientX";
195
+ const startPos = event[clientXorY];
196
+ const direction = direction$();
197
+ onResizingChange$()(true);
198
+ return {
199
+ onMove(event2) {
200
+ setSize(startSize + direction * (event2[clientXorY] - startPos));
201
+ },
202
+ onEnd() {
203
+ drawerElement.style[isVertical ? "height" : "width"] = "";
204
+ onResizingChange$()(false);
205
+ }
206
+ };
207
+ }),
208
+ createAttributesDirective(() => ({
209
+ events: {
210
+ keydown: (e) => {
211
+ const { key } = e;
212
+ const size = size$() || drawerElement$()?.[isVertical$() ? "offsetHeight" : "offsetWidth"];
213
+ if (size != null) {
214
+ switch (key) {
215
+ case "ArrowLeft":
216
+ case "ArrowDown":
217
+ onResizingChange$()(true);
218
+ setSize(size - 10);
219
+ onResizingChange$()(false);
220
+ break;
221
+ case "ArrowRight":
222
+ case "ArrowUp":
223
+ onResizingChange$()(true);
224
+ setSize(size + 10);
225
+ onResizingChange$()(false);
226
+ break;
227
+ }
228
+ }
229
+ }
230
+ }
231
+ }))
232
+ );
233
+ const visible$ = transition.stores.visible$;
234
+ const transitioning$ = computed(() => transition.stores.transitioning$() || backdropTransition.stores.transitioning$());
235
+ const hidden$ = computed(() => !transitioning$() && !visible$());
236
+ const minSizeAction$ = computed(() => {
237
+ const isMinimized = isMinimized$();
238
+ if (isMinimized != null) {
239
+ untrack(() => onMinimizedChange$()(isMinimized));
240
+ }
241
+ });
242
+ const maxSizeAction$ = computed(() => {
243
+ const isMaximized = isMaximized$();
244
+ if (isMaximized != null) {
245
+ untrack(() => onMaximizedChange$()(isMaximized));
246
+ }
247
+ });
248
+ const action$ = computed(() => {
249
+ minSizeAction$();
250
+ maxSizeAction$();
251
+ });
252
+ const widget = {
253
+ ...stateStores({
254
+ ...stateProps,
255
+ backdropClass$,
256
+ className$,
257
+ container$,
258
+ size$,
259
+ visible$,
260
+ backdropHidden$,
261
+ hidden$
262
+ }),
263
+ patch,
264
+ api: {
265
+ open: transition.api.show,
266
+ close: transition.api.hide
267
+ },
268
+ directives: {
269
+ drawerPortalDirective,
270
+ drawerDirective: mergeDirectives(
271
+ directiveSubscribe(action$),
272
+ drawerAttributeDirective,
273
+ bindDirective(
274
+ siblingsInert,
275
+ computed(() => !bodyScroll$())
276
+ ),
277
+ // This directive must come after the attribute directive, to ensure that all the classes and attributes are applied for the transition
278
+ transition.directives.directive,
279
+ focusElement
280
+ ),
281
+ backdropPortalDirective,
282
+ backdropDirective: mergeDirectives(backdropTransition.directives.directive, backdropAttributeDirective),
283
+ splitterDirective
284
+ }
285
+ };
286
+ return widget;
287
+ });
288
+ export {
289
+ createDrawer as c,
290
+ getDrawerDefaultConfig as g
291
+ };