@agnos-ui/core 0.1.1 → 0.3.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 (145) 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 +57 -64
  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 +107 -128
  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 +45 -57
  31. package/components/slider/index.cjs +5 -0
  32. package/components/slider/index.js +5 -1
  33. package/components/slider/slider.d.ts +63 -5
  34. package/components/toast/index.cjs +5 -0
  35. package/components/toast/index.d.ts +1 -0
  36. package/components/toast/index.js +5 -0
  37. package/components/toast/toast.d.ts +47 -0
  38. package/config.cjs +38 -0
  39. package/config.d.ts +6 -1
  40. package/config.js +35 -50
  41. package/directive-BTSEYLF3.cjs +404 -0
  42. package/directive-DCYlDznf.js +405 -0
  43. package/func-DR0n-ShK.js +7 -0
  44. package/func-Qd3cD9a3.cjs +6 -0
  45. package/index.cjs +119 -0
  46. package/index.d.ts +3 -1
  47. package/index.js +119 -31
  48. package/modal-BI2qUu1M.js +251 -0
  49. package/modal-rzMpATf5.cjs +250 -0
  50. package/package.json +30 -22
  51. package/pagination--GkwduJn.js +263 -0
  52. package/pagination-EWSWQT1I.cjs +262 -0
  53. package/progressbar-DH7DHYMp.cjs +83 -0
  54. package/progressbar-DuRX7_my.js +84 -0
  55. package/promise-BMJ8qhA8.cjs +118 -0
  56. package/promise-CY2U8bTP.js +119 -0
  57. package/rating-BR5wD7y2.js +173 -0
  58. package/rating-CmuYUSxy.cjs +172 -0
  59. package/select-BCs6HQWn.js +358 -0
  60. package/select-CCIKn8WR.cjs +357 -0
  61. package/services/extendWidget.cjs +32 -0
  62. package/services/extendWidget.d.ts +10 -5
  63. package/services/extendWidget.js +31 -34
  64. package/services/floatingUI.cjs +131 -0
  65. package/services/floatingUI.d.ts +30 -14
  66. package/services/floatingUI.js +128 -102
  67. package/services/focustrack.cjs +47 -0
  68. package/services/focustrack.js +45 -44
  69. package/services/hash.cjs +15 -0
  70. package/services/hash.d.ts +2 -0
  71. package/services/hash.js +15 -0
  72. package/services/intersection.cjs +53 -0
  73. package/services/intersection.js +48 -50
  74. package/services/matchMedia.cjs +13 -0
  75. package/services/matchMedia.d.ts +7 -0
  76. package/services/matchMedia.js +13 -0
  77. package/services/navManager.cjs +196 -0
  78. package/services/navManager.d.ts +24 -17
  79. package/services/navManager.js +186 -162
  80. package/services/portal.cjs +43 -0
  81. package/services/portal.js +41 -42
  82. package/services/resizeObserver.cjs +32 -0
  83. package/services/resizeObserver.d.ts +14 -0
  84. package/services/resizeObserver.js +32 -0
  85. package/services/siblingsInert.cjs +40 -0
  86. package/services/siblingsInert.js +31 -31
  87. package/services/transitions/baseTransitions.cjs +171 -0
  88. package/services/transitions/baseTransitions.d.ts +16 -16
  89. package/services/transitions/baseTransitions.js +159 -170
  90. package/services/transitions/collapse.cjs +44 -0
  91. package/services/transitions/collapse.js +41 -49
  92. package/services/transitions/cssTransitions.cjs +32 -0
  93. package/services/transitions/cssTransitions.d.ts +2 -1
  94. package/services/transitions/cssTransitions.js +29 -39
  95. package/services/transitions/simpleClassTransition.cjs +31 -0
  96. package/services/transitions/simpleClassTransition.js +30 -41
  97. package/slider-CA_fszn7.js +536 -0
  98. package/slider-DsLvT87U.cjs +535 -0
  99. package/toast-8tWp6x89.js +63 -0
  100. package/toast-Aw8o0Iwe.cjs +62 -0
  101. package/types.cjs +12 -0
  102. package/types.d.ts +21 -1
  103. package/types.js +11 -13
  104. package/utils/directive.cjs +26 -0
  105. package/utils/directive.d.ts +155 -4
  106. package/utils/directive.js +25 -189
  107. package/utils/internal/dom.d.ts +57 -3
  108. package/utils/internal/promise.d.ts +2 -2
  109. package/utils/internal/ssrHTMLElement.d.ts +7 -0
  110. package/utils/internal/textDirection.d.ts +1 -1
  111. package/utils/stores.cjs +163 -0
  112. package/utils/stores.d.ts +23 -20
  113. package/utils/stores.js +151 -269
  114. package/utils/writables.cjs +13 -0
  115. package/utils/writables.js +12 -71
  116. package/writables-D46sFgGK.cjs +85 -0
  117. package/writables-DoU_XYTX.js +86 -0
  118. package/components/accordion/accordion.js +0 -267
  119. package/components/alert/alert.js +0 -22
  120. package/components/alert/common.js +0 -69
  121. package/components/commonProps.js +0 -1
  122. package/components/modal/modal.js +0 -186
  123. package/components/pagination/bootstrap.d.ts +0 -8
  124. package/components/pagination/bootstrap.js +0 -110
  125. package/components/pagination/pagination.js +0 -149
  126. package/components/progressbar/progressbar.js +0 -78
  127. package/components/rating/rating.js +0 -138
  128. package/components/select/select.js +0 -266
  129. package/components/slider/slider.js +0 -415
  130. package/services/transitions/bootstrap/collapse.d.ts +0 -2
  131. package/services/transitions/bootstrap/collapse.js +0 -15
  132. package/services/transitions/bootstrap/fade.d.ts +0 -1
  133. package/services/transitions/bootstrap/fade.js +0 -7
  134. package/services/transitions/bootstrap.d.ts +0 -2
  135. package/services/transitions/bootstrap.js +0 -2
  136. package/utils/internal/checks.js +0 -60
  137. package/utils/internal/dom.js +0 -61
  138. package/utils/internal/func.js +0 -11
  139. package/utils/internal/isFocusable.js +0 -35
  140. package/utils/internal/math.js +0 -13
  141. package/utils/internal/promise.js +0 -169
  142. package/utils/internal/scrollbars.js +0 -33
  143. package/utils/internal/sort.js +0 -28
  144. package/utils/internal/textDirection.js +0 -7
  145. package/utils/internal/traversal.js +0 -105
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const utils_stores = require("../utils/stores.cjs");
5
+ const extendWidgetProps = (factory, extraPropsDefaults, extraPropsConfig, overrideDefaults) => (propsConfig) => {
6
+ const extraPropsWritables = utils_stores.writablesWithDefault(extraPropsDefaults, propsConfig, extraPropsConfig);
7
+ const propsConfigConfig = propsConfig == null ? void 0 : propsConfig.config;
8
+ const config = utils_stores.isStore(propsConfigConfig) ? tansu.computed(() => ({ ...overrideDefaults, ...propsConfigConfig() })) : { ...overrideDefaults, ...propsConfigConfig ?? {} };
9
+ const widget = factory({ props: propsConfig == null ? void 0 : propsConfig.props, config });
10
+ return {
11
+ ...widget,
12
+ ...utils_stores.stateStores({ ...widget.stores, ...extraPropsWritables }),
13
+ patch: (storesValues) => tansu.batch(() => {
14
+ let widgetProps;
15
+ for (const [name, value] of Object.entries(storesValues ?? {})) {
16
+ const extraPropsStore = extraPropsWritables[`${name}$`];
17
+ if (extraPropsStore) {
18
+ extraPropsStore.set(value);
19
+ } else {
20
+ if (!widgetProps) {
21
+ widgetProps = {};
22
+ }
23
+ widgetProps[name] = value;
24
+ }
25
+ }
26
+ if (widgetProps) {
27
+ widget.patch(widgetProps);
28
+ }
29
+ })
30
+ };
31
+ };
32
+ exports.extendWidgetProps = extendWidgetProps;
@@ -2,22 +2,27 @@ import type { ConfigValidator, SlotContent, Widget, WidgetFactory, WidgetProps,
2
2
  /**
3
3
  * Type extending the original Widget props and state with ExtraProps
4
4
  */
5
- export type ExtendWidgetProps<W extends Widget, ExtraProps extends object> = Widget<ExtendWidgetAdaptSlotWidgetProps<WidgetProps<W>, ExtraProps>, ExtendWidgetAdaptSlotWidgetProps<WidgetState<W>, ExtraProps>, W['api'], W['actions'], W['directives']>;
5
+ export type ExtendWidgetProps<W extends Widget, ExtraProps extends object, ExtraDirectives extends object = object> = Widget<ExtendWidgetAdaptSlotWidgetProps<WidgetProps<W>, ExtraProps, ExtraDirectives>, ExtendWidgetAdaptSlotWidgetProps<WidgetState<W>, ExtraProps, ExtraDirectives>, W['api'], W['actions'], ExtendWidgetInterfaces<W['directives'], ExtraDirectives>>;
6
+ /**
7
+ * Type merging the passed interfaces together
8
+ */
9
+ export type ExtendWidgetInterfaces<Interfaces, ExtraInterfaces> = Interfaces & ExtraInterfaces;
6
10
  /**
7
11
  * Type replacing the original Props with WidgetSlotContext contaning ExtraProps
8
12
  */
9
- export type ExtendWidgetAdaptSlotContentProps<Props extends Record<string, any>, ExtraProps extends object> = Props extends WidgetSlotContext<infer U> ? WidgetSlotContext<ExtendWidgetProps<U, ExtraProps>> & Omit<Props, keyof WidgetSlotContext<any>> : Props;
13
+ export type ExtendWidgetAdaptSlotContentProps<Props extends Record<string, any>, ExtraProps extends object, ExtraDirectives extends object> = Props extends WidgetSlotContext<infer U> ? WidgetSlotContext<ExtendWidgetProps<U, ExtraProps, ExtraDirectives>> & Omit<Props, keyof WidgetSlotContext<any>> : Props;
10
14
  /**
11
15
  * Type enriching the original widget slot Props with ExtraProps slots
12
16
  */
13
- export type ExtendWidgetAdaptSlotWidgetProps<Props, ExtraProps extends object> = Omit<Props, `slot${string}`> & ExtraProps & {
14
- [K in keyof Props & `slot${string}`]: Props[K] extends SlotContent<infer U> ? SlotContent<ExtendWidgetAdaptSlotContentProps<U, ExtraProps>> : Props[K];
17
+ export type ExtendWidgetAdaptSlotWidgetProps<Props, ExtraProps extends object, ExtraDirectives extends object> = Omit<Props, `slot${string}`> & ExtraProps & {
18
+ [K in keyof Props & `slot${string}`]: Props[K] extends SlotContent<infer U> ? SlotContent<ExtendWidgetAdaptSlotContentProps<U, ExtraProps, ExtraDirectives>> : Props[K];
15
19
  };
16
20
  /**
17
21
  * Method to extend the original widget with extra props with validator
18
22
  * @param factory - original widget factory
19
23
  * @param extraPropsDefaults - object containing default value for each extra prop
20
24
  * @param extraPropsConfig - object verifying the type of each extra prop
25
+ * @param overrideDefaults - object overriding some default props of the widget to extend
21
26
  * @returns widget factory with the extra props
22
27
  */
23
- export declare const extendWidgetProps: <W extends Widget<object, object, object, object, object>, ExtraProps extends object>(factory: WidgetFactory<W>, extraPropsDefaults: ExtraProps, extraPropsConfig?: ConfigValidator<ExtraProps> | undefined) => WidgetFactory<ExtendWidgetProps<W, ExtraProps>>;
28
+ export declare const extendWidgetProps: <W extends Widget<object, object, object, object, object>, ExtraProps extends object, ExtraDirectives extends object = object>(factory: WidgetFactory<W>, extraPropsDefaults: ExtraProps, extraPropsConfig?: ConfigValidator<ExtraProps>, overrideDefaults?: Partial<WidgetState<W>>) => WidgetFactory<ExtendWidgetProps<W, ExtraProps, ExtraDirectives>>;
@@ -1,35 +1,32 @@
1
- import { batch } from '@amadeus-it-group/tansu';
2
- import { stateStores, writablesWithDefault } from '../utils/stores';
3
- /**
4
- * Method to extend the original widget with extra props with validator
5
- * @param factory - original widget factory
6
- * @param extraPropsDefaults - object containing default value for each extra prop
7
- * @param extraPropsConfig - object verifying the type of each extra prop
8
- * @returns widget factory with the extra props
9
- */
10
- export const extendWidgetProps = (factory, extraPropsDefaults, extraPropsConfig) => (propsConfig) => {
11
- const extraPropsWritables = writablesWithDefault(extraPropsDefaults, propsConfig, extraPropsConfig);
12
- const widget = factory(propsConfig);
13
- return {
14
- ...widget,
15
- ...stateStores({ ...widget.stores, ...extraPropsWritables }),
16
- patch: (storesValues) => batch(() => {
17
- let widgetProps;
18
- for (const [name, value] of Object.entries(storesValues ?? {})) {
19
- const extraPropsStore = extraPropsWritables[`${name}$`];
20
- if (extraPropsStore) {
21
- extraPropsStore.set(value);
22
- }
23
- else {
24
- if (!widgetProps) {
25
- widgetProps = {};
26
- }
27
- widgetProps[name] = value;
28
- }
29
- }
30
- if (widgetProps) {
31
- widget.patch(widgetProps);
32
- }
33
- }),
34
- };
1
+ import { computed, batch } from "@amadeus-it-group/tansu";
2
+ import { writablesWithDefault, isStore, stateStores } from "../utils/stores.js";
3
+ const extendWidgetProps = (factory, extraPropsDefaults, extraPropsConfig, overrideDefaults) => (propsConfig) => {
4
+ const extraPropsWritables = writablesWithDefault(extraPropsDefaults, propsConfig, extraPropsConfig);
5
+ const propsConfigConfig = propsConfig == null ? void 0 : propsConfig.config;
6
+ const config = isStore(propsConfigConfig) ? computed(() => ({ ...overrideDefaults, ...propsConfigConfig() })) : { ...overrideDefaults, ...propsConfigConfig ?? {} };
7
+ const widget = factory({ props: propsConfig == null ? void 0 : propsConfig.props, config });
8
+ return {
9
+ ...widget,
10
+ ...stateStores({ ...widget.stores, ...extraPropsWritables }),
11
+ patch: (storesValues) => batch(() => {
12
+ let widgetProps;
13
+ for (const [name, value] of Object.entries(storesValues ?? {})) {
14
+ const extraPropsStore = extraPropsWritables[`${name}$`];
15
+ if (extraPropsStore) {
16
+ extraPropsStore.set(value);
17
+ } else {
18
+ if (!widgetProps) {
19
+ widgetProps = {};
20
+ }
21
+ widgetProps[name] = value;
22
+ }
23
+ }
24
+ if (widgetProps) {
25
+ widget.patch(widgetProps);
26
+ }
27
+ })
28
+ };
29
+ };
30
+ export {
31
+ extendWidgetProps
35
32
  };
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const dom = require("@floating-ui/dom");
5
+ const utils_directive = require("../directive-BTSEYLF3.cjs");
6
+ const promise = require("../promise-BMJ8qhA8.cjs");
7
+ const utils_stores = require("../utils/stores.cjs");
8
+ const defaultConfig = {
9
+ computePositionOptions: {},
10
+ autoUpdateOptions: {},
11
+ arrowOptions: {}
12
+ };
13
+ const createFloatingUI = (propsConfig) => {
14
+ const [{ autoUpdateOptions$, computePositionOptions$: computePositionInputOptions$, arrowOptions$: arrowInputOptions$ }, patch] = utils_stores.writablesForProps(
15
+ defaultConfig,
16
+ propsConfig
17
+ );
18
+ const { directive: floatingDirective, element$: floatingElement$ } = utils_directive.createBrowserStoreDirective();
19
+ const { directive: referenceDirective, element$: referenceElement$ } = utils_directive.createBrowserStoreDirective();
20
+ const { directive: arrowDirective, element$: arrowElement$ } = utils_directive.createBrowserStoreDirective();
21
+ const arrowOptions$ = tansu.computed(() => {
22
+ const arrowElement = arrowElement$();
23
+ if (!arrowElement) {
24
+ return null;
25
+ }
26
+ const arrowInputOptions = arrowInputOptions$();
27
+ return typeof arrowInputOptions === "function" ? (state) => ({ ...arrowInputOptions(state), element: arrowElement }) : { ...arrowInputOptions, element: arrowElement };
28
+ });
29
+ const computePositionOptions$ = tansu.computed(() => {
30
+ let options = computePositionInputOptions$();
31
+ const arrowOptions = arrowOptions$();
32
+ if (arrowOptions) {
33
+ options = {
34
+ ...options,
35
+ middleware: [...options.middleware ?? [], dom.arrow(arrowOptions)]
36
+ };
37
+ }
38
+ return options;
39
+ });
40
+ const promisePosition$ = tansu.derived(
41
+ [floatingElement$, referenceElement$, computePositionOptions$, autoUpdateOptions$],
42
+ ([floatingElement, referenceElement, computePositionOptions, autoUpdateOptions], set) => {
43
+ if (floatingElement && referenceElement) {
44
+ const clean = dom.autoUpdate(
45
+ referenceElement,
46
+ floatingElement,
47
+ () => {
48
+ set(dom.computePosition(referenceElement, floatingElement, computePositionOptions));
49
+ },
50
+ autoUpdateOptions
51
+ );
52
+ return () => {
53
+ set(null);
54
+ clean();
55
+ };
56
+ }
57
+ return void 0;
58
+ },
59
+ null
60
+ );
61
+ const position$ = promise.promiseStoreToValueStore(promisePosition$, null);
62
+ const placement$ = tansu.computed(() => {
63
+ var _a;
64
+ return (_a = position$()) == null ? void 0 : _a.placement;
65
+ });
66
+ const middlewareData$ = tansu.computed(() => {
67
+ var _a;
68
+ return (_a = position$()) == null ? void 0 : _a.middlewareData;
69
+ });
70
+ const x$ = tansu.computed(() => {
71
+ var _a;
72
+ return (_a = position$()) == null ? void 0 : _a.x;
73
+ });
74
+ const y$ = tansu.computed(() => {
75
+ var _a;
76
+ return (_a = position$()) == null ? void 0 : _a.y;
77
+ });
78
+ const strategy$ = tansu.computed(() => {
79
+ var _a;
80
+ return (_a = position$()) == null ? void 0 : _a.strategy;
81
+ });
82
+ const arrowX$ = tansu.computed(() => {
83
+ var _a, _b;
84
+ return (_b = (_a = middlewareData$()) == null ? void 0 : _a.arrow) == null ? void 0 : _b.x;
85
+ });
86
+ const arrowY$ = tansu.computed(() => {
87
+ var _a, _b;
88
+ return (_b = (_a = middlewareData$()) == null ? void 0 : _a.arrow) == null ? void 0 : _b.y;
89
+ });
90
+ const floatingStyleApplyAction$ = tansu.computed(() => {
91
+ const floatingElement = floatingElement$();
92
+ if (floatingElement) {
93
+ floatingElement.style.left = `${x$() ?? 0}px`;
94
+ floatingElement.style.top = `${y$() ?? 0}px`;
95
+ }
96
+ });
97
+ const arrowStyleApplyAction$ = tansu.computed(() => {
98
+ const arrowElement = arrowElement$();
99
+ if (arrowElement) {
100
+ const arrowX = arrowX$();
101
+ const arrowY = arrowY$();
102
+ arrowElement.style.left = arrowX != null ? `${arrowX}px` : "";
103
+ arrowElement.style.top = arrowY != null ? `${arrowY}px` : "";
104
+ }
105
+ });
106
+ return {
107
+ patch,
108
+ ...utils_stores.stateStores({
109
+ x$,
110
+ y$,
111
+ strategy$,
112
+ placement$,
113
+ middlewareData$
114
+ }),
115
+ directives: {
116
+ /**
117
+ * Directive to be used on the reference element from where the floating element will be positioned
118
+ */
119
+ referenceDirective,
120
+ /**
121
+ * Directive to be used on the floating element
122
+ */
123
+ floatingDirective: utils_directive.mergeDirectives(floatingDirective, utils_directive.directiveSubscribe(floatingStyleApplyAction$)),
124
+ /**
125
+ * Directive to be used on the arrow element, if any
126
+ */
127
+ arrowDirective: utils_directive.mergeDirectives(arrowDirective, utils_directive.directiveSubscribe(arrowStyleApplyAction$))
128
+ }
129
+ };
130
+ };
131
+ exports.createFloatingUI = createFloatingUI;
@@ -1,4 +1,4 @@
1
- import type { ArrowOptions, AutoUpdateOptions, ComputePositionConfig, Derivable } from '@floating-ui/dom';
1
+ import type { ArrowOptions, AutoUpdateOptions, ComputePositionConfig, Derivable, MiddlewareData, Placement, Strategy } from '@floating-ui/dom';
2
2
  import type { PropsConfig } from '../types';
3
3
  export interface FloatingUIProps {
4
4
  /**
@@ -14,6 +14,28 @@ export interface FloatingUIProps {
14
14
  */
15
15
  arrowOptions: Omit<ArrowOptions, 'element'> | Derivable<Omit<ArrowOptions, 'element'>>;
16
16
  }
17
+ export interface FloatingUIState {
18
+ /**
19
+ * The x coordinate of the floating ui
20
+ */
21
+ x: number | undefined;
22
+ /**
23
+ * The y coordinate of the floating ui
24
+ */
25
+ y: number | undefined;
26
+ /**
27
+ * The strategy used to position the floating element
28
+ */
29
+ strategy: Strategy | undefined;
30
+ /**
31
+ * The final chosen placement of the floating element
32
+ */
33
+ placement: Placement | undefined;
34
+ /**
35
+ * Object containing data returned from all middleware, keyed by their name
36
+ */
37
+ middlewareData: MiddlewareData | undefined;
38
+ }
17
39
  export type FloatingUI = ReturnType<typeof createFloatingUI>;
18
40
  /**
19
41
  * Create a floating UI service.
@@ -28,29 +50,23 @@ export declare const createFloatingUI: (propsConfig?: PropsConfig<FloatingUIProp
28
50
  /**
29
51
  * Directive to be used on the reference element from where the floating element will be positioned
30
52
  */
31
- referenceDirective: import("../types").Directive;
53
+ referenceDirective: import("../types").Directive<void, import("../types").SSRHTMLElement>;
32
54
  /**
33
55
  * Directive to be used on the floating element
34
56
  */
35
- floatingDirective: import("../types").Directive<void>;
57
+ floatingDirective: import("../types").Directive<void, import("../types").SSRHTMLElement>;
36
58
  /**
37
59
  * Directive to be used on the arrow element, if any
38
60
  */
39
- arrowDirective: import("../types").Directive<void>;
61
+ arrowDirective: import("../types").Directive<void, import("../types").SSRHTMLElement>;
40
62
  };
41
- state$: import("@amadeus-it-group/tansu").ReadableSignal<import("../utils/stores").ToState<{
42
- x$: import("@amadeus-it-group/tansu").ReadableSignal<number | undefined>;
43
- y$: import("@amadeus-it-group/tansu").ReadableSignal<number | undefined>;
44
- strategy$: import("@amadeus-it-group/tansu").ReadableSignal<import("@floating-ui/utils").Strategy | undefined>;
45
- placement$: import("@amadeus-it-group/tansu").ReadableSignal<import("@floating-ui/utils").Placement | undefined>;
46
- middlewareData$: import("@amadeus-it-group/tansu").ReadableSignal<import("@floating-ui/core").MiddlewareData | undefined>;
47
- }>>;
63
+ state$: import("@amadeus-it-group/tansu").ReadableSignal<FloatingUIState>;
48
64
  stores: {
49
65
  x$: import("@amadeus-it-group/tansu").ReadableSignal<number | undefined>;
50
66
  y$: import("@amadeus-it-group/tansu").ReadableSignal<number | undefined>;
51
- strategy$: import("@amadeus-it-group/tansu").ReadableSignal<import("@floating-ui/utils").Strategy | undefined>;
52
- placement$: import("@amadeus-it-group/tansu").ReadableSignal<import("@floating-ui/utils").Placement | undefined>;
53
- middlewareData$: import("@amadeus-it-group/tansu").ReadableSignal<import("@floating-ui/core").MiddlewareData | undefined>;
67
+ strategy$: import("@amadeus-it-group/tansu").ReadableSignal<Strategy | undefined>;
68
+ placement$: import("@amadeus-it-group/tansu").ReadableSignal<Placement | undefined>;
69
+ middlewareData$: import("@amadeus-it-group/tansu").ReadableSignal<MiddlewareData | undefined>;
54
70
  };
55
71
  patch: <U extends Partial<FloatingUIProps>>(storesValues?: void | U | undefined) => void;
56
72
  };
@@ -1,105 +1,131 @@
1
- import { computed, derived } from '@amadeus-it-group/tansu';
2
- import { arrow, autoUpdate, computePosition } from '@floating-ui/dom';
3
- import { createStoreDirective, directiveSubscribe, mergeDirectives } from '../utils/directive';
4
- import { promiseStoreToValueStore } from '../utils/internal/promise';
5
- import { stateStores, writablesForProps } from '../utils/stores';
1
+ import { computed, derived } from "@amadeus-it-group/tansu";
2
+ import { arrow, autoUpdate, computePosition } from "@floating-ui/dom";
3
+ import { j as createBrowserStoreDirective, k as mergeDirectives, d as directiveSubscribe } from "../directive-DCYlDznf.js";
4
+ import { p as promiseStoreToValueStore } from "../promise-CY2U8bTP.js";
5
+ import { writablesForProps, stateStores } from "../utils/stores.js";
6
6
  const defaultConfig = {
7
- computePositionOptions: {},
8
- autoUpdateOptions: {},
9
- arrowOptions: {},
7
+ computePositionOptions: {},
8
+ autoUpdateOptions: {},
9
+ arrowOptions: {}
10
10
  };
11
- /**
12
- * Create a floating UI service.
13
- *
14
- * The returned service includes the patch method to patch the states, the stores to track the states and directives to apply.
15
- *
16
- * @param propsConfig - the props config for the floating UI service
17
- * @returns the floating UI service
18
- */
19
- export const createFloatingUI = (propsConfig) => {
20
- const [{ autoUpdateOptions$, computePositionOptions$: computePositionInputOptions$, arrowOptions$: arrowInputOptions$ }, patch] = writablesForProps(defaultConfig, propsConfig);
21
- const { directive: floatingDirective, element$: floatingElement$ } = createStoreDirective();
22
- const { directive: referenceDirective, element$: referenceElement$ } = createStoreDirective();
23
- const { directive: arrowDirective, element$: arrowElement$ } = createStoreDirective();
24
- const arrowOptions$ = computed(() => {
25
- const arrowElement = arrowElement$();
26
- if (!arrowElement) {
27
- return null;
28
- }
29
- const arrowInputOptions = arrowInputOptions$();
30
- return typeof arrowInputOptions === 'function'
31
- ? (state) => ({ ...arrowInputOptions(state), element: arrowElement })
32
- : { ...arrowInputOptions, element: arrowElement };
33
- });
34
- const computePositionOptions$ = computed(() => {
35
- let options = computePositionInputOptions$();
36
- const arrowOptions = arrowOptions$();
37
- if (arrowOptions) {
38
- options = {
39
- ...options,
40
- middleware: [...(options.middleware ?? []), arrow(arrowOptions)],
41
- };
42
- }
43
- return options;
44
- });
45
- const promisePosition$ = derived([floatingElement$, referenceElement$, computePositionOptions$, autoUpdateOptions$], ([floatingElement, referenceElement, computePositionOptions, autoUpdateOptions], set) => {
46
- if (floatingElement && referenceElement) {
47
- const clean = autoUpdate(referenceElement, floatingElement, () => {
48
- set(computePosition(referenceElement, floatingElement, computePositionOptions));
49
- }, autoUpdateOptions);
50
- return () => {
51
- set(null);
52
- clean();
53
- };
54
- }
55
- return undefined;
56
- }, null);
57
- const position$ = promiseStoreToValueStore(promisePosition$, null);
58
- const placement$ = computed(() => position$()?.placement);
59
- const middlewareData$ = computed(() => position$()?.middlewareData);
60
- const x$ = computed(() => position$()?.x);
61
- const y$ = computed(() => position$()?.y);
62
- const strategy$ = computed(() => position$()?.strategy);
63
- const arrowX$ = computed(() => middlewareData$()?.arrow?.x);
64
- const arrowY$ = computed(() => middlewareData$()?.arrow?.y);
65
- const floatingStyleApplyAction$ = computed(() => {
66
- const floatingElement = floatingElement$();
67
- if (floatingElement) {
68
- floatingElement.style.left = `${x$() ?? 0}px`;
69
- floatingElement.style.top = `${y$() ?? 0}px`;
70
- }
71
- });
72
- const arrowStyleApplyAction$ = computed(() => {
73
- const arrowElement = arrowElement$();
74
- if (arrowElement) {
75
- const arrowX = arrowX$();
76
- const arrowY = arrowY$();
77
- arrowElement.style.left = arrowX != null ? `${arrowX}px` : '';
78
- arrowElement.style.top = arrowY != null ? `${arrowY}px` : '';
79
- }
80
- });
81
- return {
82
- patch,
83
- ...stateStores({
84
- x$,
85
- y$,
86
- strategy$,
87
- placement$,
88
- middlewareData$,
89
- }),
90
- directives: {
91
- /**
92
- * Directive to be used on the reference element from where the floating element will be positioned
93
- */
94
- referenceDirective,
95
- /**
96
- * Directive to be used on the floating element
97
- */
98
- floatingDirective: mergeDirectives(floatingDirective, directiveSubscribe(floatingStyleApplyAction$)),
99
- /**
100
- * Directive to be used on the arrow element, if any
101
- */
102
- arrowDirective: mergeDirectives(arrowDirective, directiveSubscribe(arrowStyleApplyAction$)),
103
- },
104
- };
11
+ const createFloatingUI = (propsConfig) => {
12
+ const [{ autoUpdateOptions$, computePositionOptions$: computePositionInputOptions$, arrowOptions$: arrowInputOptions$ }, patch] = writablesForProps(
13
+ defaultConfig,
14
+ propsConfig
15
+ );
16
+ const { directive: floatingDirective, element$: floatingElement$ } = createBrowserStoreDirective();
17
+ const { directive: referenceDirective, element$: referenceElement$ } = createBrowserStoreDirective();
18
+ const { directive: arrowDirective, element$: arrowElement$ } = createBrowserStoreDirective();
19
+ const arrowOptions$ = computed(() => {
20
+ const arrowElement = arrowElement$();
21
+ if (!arrowElement) {
22
+ return null;
23
+ }
24
+ const arrowInputOptions = arrowInputOptions$();
25
+ return typeof arrowInputOptions === "function" ? (state) => ({ ...arrowInputOptions(state), element: arrowElement }) : { ...arrowInputOptions, element: arrowElement };
26
+ });
27
+ const computePositionOptions$ = computed(() => {
28
+ let options = computePositionInputOptions$();
29
+ const arrowOptions = arrowOptions$();
30
+ if (arrowOptions) {
31
+ options = {
32
+ ...options,
33
+ middleware: [...options.middleware ?? [], arrow(arrowOptions)]
34
+ };
35
+ }
36
+ return options;
37
+ });
38
+ const promisePosition$ = derived(
39
+ [floatingElement$, referenceElement$, computePositionOptions$, autoUpdateOptions$],
40
+ ([floatingElement, referenceElement, computePositionOptions, autoUpdateOptions], set) => {
41
+ if (floatingElement && referenceElement) {
42
+ const clean = autoUpdate(
43
+ referenceElement,
44
+ floatingElement,
45
+ () => {
46
+ set(computePosition(referenceElement, floatingElement, computePositionOptions));
47
+ },
48
+ autoUpdateOptions
49
+ );
50
+ return () => {
51
+ set(null);
52
+ clean();
53
+ };
54
+ }
55
+ return void 0;
56
+ },
57
+ null
58
+ );
59
+ const position$ = promiseStoreToValueStore(promisePosition$, null);
60
+ const placement$ = computed(() => {
61
+ var _a;
62
+ return (_a = position$()) == null ? void 0 : _a.placement;
63
+ });
64
+ const middlewareData$ = computed(() => {
65
+ var _a;
66
+ return (_a = position$()) == null ? void 0 : _a.middlewareData;
67
+ });
68
+ const x$ = computed(() => {
69
+ var _a;
70
+ return (_a = position$()) == null ? void 0 : _a.x;
71
+ });
72
+ const y$ = computed(() => {
73
+ var _a;
74
+ return (_a = position$()) == null ? void 0 : _a.y;
75
+ });
76
+ const strategy$ = computed(() => {
77
+ var _a;
78
+ return (_a = position$()) == null ? void 0 : _a.strategy;
79
+ });
80
+ const arrowX$ = computed(() => {
81
+ var _a, _b;
82
+ return (_b = (_a = middlewareData$()) == null ? void 0 : _a.arrow) == null ? void 0 : _b.x;
83
+ });
84
+ const arrowY$ = computed(() => {
85
+ var _a, _b;
86
+ return (_b = (_a = middlewareData$()) == null ? void 0 : _a.arrow) == null ? void 0 : _b.y;
87
+ });
88
+ const floatingStyleApplyAction$ = computed(() => {
89
+ const floatingElement = floatingElement$();
90
+ if (floatingElement) {
91
+ floatingElement.style.left = `${x$() ?? 0}px`;
92
+ floatingElement.style.top = `${y$() ?? 0}px`;
93
+ }
94
+ });
95
+ const arrowStyleApplyAction$ = computed(() => {
96
+ const arrowElement = arrowElement$();
97
+ if (arrowElement) {
98
+ const arrowX = arrowX$();
99
+ const arrowY = arrowY$();
100
+ arrowElement.style.left = arrowX != null ? `${arrowX}px` : "";
101
+ arrowElement.style.top = arrowY != null ? `${arrowY}px` : "";
102
+ }
103
+ });
104
+ return {
105
+ patch,
106
+ ...stateStores({
107
+ x$,
108
+ y$,
109
+ strategy$,
110
+ placement$,
111
+ middlewareData$
112
+ }),
113
+ directives: {
114
+ /**
115
+ * Directive to be used on the reference element from where the floating element will be positioned
116
+ */
117
+ referenceDirective,
118
+ /**
119
+ * Directive to be used on the floating element
120
+ */
121
+ floatingDirective: mergeDirectives(floatingDirective, directiveSubscribe(floatingStyleApplyAction$)),
122
+ /**
123
+ * Directive to be used on the arrow element, if any
124
+ */
125
+ arrowDirective: mergeDirectives(arrowDirective, directiveSubscribe(arrowStyleApplyAction$))
126
+ }
127
+ };
128
+ };
129
+ export {
130
+ createFloatingUI
105
131
  };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const utils_directive = require("../directive-BTSEYLF3.cjs");
5
+ const esmEnv = require("esm-env");
6
+ const evtFocusIn = "focusin";
7
+ const evtFocusOut = "focusout";
8
+ const activeElement$ = !esmEnv.BROWSER ? tansu.readable(null) : tansu.readable(null, {
9
+ onUse({ set }) {
10
+ function setActiveElement() {
11
+ set(document.activeElement);
12
+ }
13
+ setActiveElement();
14
+ const container = document.documentElement;
15
+ function onFocusOut() {
16
+ setTimeout(setActiveElement);
17
+ }
18
+ container.addEventListener(evtFocusIn, setActiveElement, { capture: true });
19
+ container.addEventListener(evtFocusOut, onFocusOut, { capture: true });
20
+ return () => {
21
+ container.removeEventListener(evtFocusIn, setActiveElement, { capture: true });
22
+ container.removeEventListener(evtFocusOut, onFocusOut, { capture: true });
23
+ };
24
+ },
25
+ equal: Object.is
26
+ });
27
+ function createHasFocus() {
28
+ const { elements$, directive } = utils_directive.createBrowserStoreArrayDirective();
29
+ const hasFocus$ = tansu.computed(() => {
30
+ const activeElement = activeElement$();
31
+ if (!activeElement) {
32
+ return false;
33
+ }
34
+ for (const element of elements$()) {
35
+ if (element === activeElement || element.contains(activeElement)) {
36
+ return true;
37
+ }
38
+ }
39
+ return false;
40
+ });
41
+ return {
42
+ directive,
43
+ hasFocus$
44
+ };
45
+ }
46
+ exports.activeElement$ = activeElement$;
47
+ exports.createHasFocus = createHasFocus;