@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.
- package/README.md +3 -3
- package/accordion-BaWN0_n-.js +330 -0
- package/accordion-BuIgxZ0S.cjs +329 -0
- package/alert-C4jCg9Pl.cjs +8 -0
- package/alert-Dlf-BV98.js +9 -0
- package/common-DRdsw5m8.js +76 -0
- package/common-nJRMXbwj.cjs +75 -0
- package/components/accordion/accordion.d.ts +57 -64
- package/components/accordion/index.cjs +7 -0
- package/components/accordion/index.js +7 -1
- package/components/alert/alert.d.ts +3 -12
- package/components/alert/common.d.ts +4 -13
- package/components/alert/index.cjs +10 -0
- package/components/alert/index.js +10 -2
- package/components/modal/index.cjs +7 -0
- package/components/modal/index.js +7 -1
- package/components/modal/modal.d.ts +7 -49
- package/components/pagination/index.cjs +5 -0
- package/components/pagination/index.d.ts +0 -1
- package/components/pagination/index.js +5 -2
- package/components/pagination/pagination.d.ts +107 -128
- package/components/progressbar/index.cjs +5 -0
- package/components/progressbar/index.js +5 -1
- package/components/progressbar/progressbar.d.ts +6 -22
- package/components/rating/index.cjs +5 -0
- package/components/rating/index.js +5 -1
- package/components/rating/rating.d.ts +16 -11
- package/components/select/index.cjs +6 -0
- package/components/select/index.js +6 -1
- package/components/select/select.d.ts +45 -57
- package/components/slider/index.cjs +5 -0
- package/components/slider/index.js +5 -1
- package/components/slider/slider.d.ts +63 -5
- package/components/toast/index.cjs +5 -0
- package/components/toast/index.d.ts +1 -0
- package/components/toast/index.js +5 -0
- package/components/toast/toast.d.ts +47 -0
- package/config.cjs +38 -0
- package/config.d.ts +6 -1
- package/config.js +35 -50
- package/directive-BTSEYLF3.cjs +404 -0
- package/directive-DCYlDznf.js +405 -0
- package/func-DR0n-ShK.js +7 -0
- package/func-Qd3cD9a3.cjs +6 -0
- package/index.cjs +119 -0
- package/index.d.ts +3 -1
- package/index.js +119 -31
- package/modal-BI2qUu1M.js +251 -0
- package/modal-rzMpATf5.cjs +250 -0
- package/package.json +30 -22
- package/pagination--GkwduJn.js +263 -0
- package/pagination-EWSWQT1I.cjs +262 -0
- package/progressbar-DH7DHYMp.cjs +83 -0
- package/progressbar-DuRX7_my.js +84 -0
- package/promise-BMJ8qhA8.cjs +118 -0
- package/promise-CY2U8bTP.js +119 -0
- package/rating-BR5wD7y2.js +173 -0
- package/rating-CmuYUSxy.cjs +172 -0
- package/select-BCs6HQWn.js +358 -0
- package/select-CCIKn8WR.cjs +357 -0
- package/services/extendWidget.cjs +32 -0
- package/services/extendWidget.d.ts +10 -5
- package/services/extendWidget.js +31 -34
- package/services/floatingUI.cjs +131 -0
- package/services/floatingUI.d.ts +30 -14
- package/services/floatingUI.js +128 -102
- package/services/focustrack.cjs +47 -0
- package/services/focustrack.js +45 -44
- package/services/hash.cjs +15 -0
- package/services/hash.d.ts +2 -0
- package/services/hash.js +15 -0
- package/services/intersection.cjs +53 -0
- package/services/intersection.js +48 -50
- package/services/matchMedia.cjs +13 -0
- package/services/matchMedia.d.ts +7 -0
- package/services/matchMedia.js +13 -0
- package/services/navManager.cjs +196 -0
- package/services/navManager.d.ts +24 -17
- package/services/navManager.js +186 -162
- package/services/portal.cjs +43 -0
- package/services/portal.js +41 -42
- package/services/resizeObserver.cjs +32 -0
- package/services/resizeObserver.d.ts +14 -0
- package/services/resizeObserver.js +32 -0
- package/services/siblingsInert.cjs +40 -0
- package/services/siblingsInert.js +31 -31
- package/services/transitions/baseTransitions.cjs +171 -0
- package/services/transitions/baseTransitions.d.ts +16 -16
- package/services/transitions/baseTransitions.js +159 -170
- package/services/transitions/collapse.cjs +44 -0
- package/services/transitions/collapse.js +41 -49
- package/services/transitions/cssTransitions.cjs +32 -0
- package/services/transitions/cssTransitions.d.ts +2 -1
- package/services/transitions/cssTransitions.js +29 -39
- package/services/transitions/simpleClassTransition.cjs +31 -0
- package/services/transitions/simpleClassTransition.js +30 -41
- package/slider-CA_fszn7.js +536 -0
- package/slider-DsLvT87U.cjs +535 -0
- package/toast-8tWp6x89.js +63 -0
- package/toast-Aw8o0Iwe.cjs +62 -0
- package/types.cjs +12 -0
- package/types.d.ts +21 -1
- package/types.js +11 -13
- package/utils/directive.cjs +26 -0
- package/utils/directive.d.ts +155 -4
- package/utils/directive.js +25 -189
- package/utils/internal/dom.d.ts +57 -3
- package/utils/internal/promise.d.ts +2 -2
- package/utils/internal/ssrHTMLElement.d.ts +7 -0
- package/utils/internal/textDirection.d.ts +1 -1
- package/utils/stores.cjs +163 -0
- package/utils/stores.d.ts +23 -20
- package/utils/stores.js +151 -269
- package/utils/writables.cjs +13 -0
- package/utils/writables.js +12 -71
- package/writables-D46sFgGK.cjs +85 -0
- package/writables-DoU_XYTX.js +86 -0
- package/components/accordion/accordion.js +0 -267
- package/components/alert/alert.js +0 -22
- package/components/alert/common.js +0 -69
- package/components/commonProps.js +0 -1
- package/components/modal/modal.js +0 -186
- package/components/pagination/bootstrap.d.ts +0 -8
- package/components/pagination/bootstrap.js +0 -110
- package/components/pagination/pagination.js +0 -149
- package/components/progressbar/progressbar.js +0 -78
- package/components/rating/rating.js +0 -138
- package/components/select/select.js +0 -266
- package/components/slider/slider.js +0 -415
- package/services/transitions/bootstrap/collapse.d.ts +0 -2
- package/services/transitions/bootstrap/collapse.js +0 -15
- package/services/transitions/bootstrap/fade.d.ts +0 -1
- package/services/transitions/bootstrap/fade.js +0 -7
- package/services/transitions/bootstrap.d.ts +0 -2
- package/services/transitions/bootstrap.js +0 -2
- package/utils/internal/checks.js +0 -60
- package/utils/internal/dom.js +0 -61
- package/utils/internal/func.js +0 -11
- package/utils/internal/isFocusable.js +0 -35
- package/utils/internal/math.js +0 -13
- package/utils/internal/promise.js +0 -169
- package/utils/internal/scrollbars.js +0 -33
- package/utils/internal/sort.js +0 -28
- package/utils/internal/textDirection.js +0 -7
- 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
|
|
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>>;
|
package/services/extendWidget.js
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
import { batch } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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;
|
package/services/floatingUI.d.ts
CHANGED
|
@@ -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<
|
|
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<
|
|
52
|
-
placement$: import("@amadeus-it-group/tansu").ReadableSignal<
|
|
53
|
-
middlewareData$: import("@amadeus-it-group/tansu").ReadableSignal<
|
|
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
|
};
|
package/services/floatingUI.js
CHANGED
|
@@ -1,105 +1,131 @@
|
|
|
1
|
-
import { computed, derived } from
|
|
2
|
-
import { arrow, autoUpdate, computePosition } from
|
|
3
|
-
import {
|
|
4
|
-
import { promiseStoreToValueStore } from
|
|
5
|
-
import {
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
computePositionOptions: {},
|
|
8
|
+
autoUpdateOptions: {},
|
|
9
|
+
arrowOptions: {}
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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;
|