@agnos-ui/react-headless 0.6.0 → 0.7.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/config.cjs +11 -22
- package/config.d.ts +4 -4
- package/config.js +12 -23
- package/{directive-BePQvMpx.cjs → directive-3diaW3tS.cjs} +36 -7
- package/{directive-DNXkB1Wc.js → directive-CEErjM5c.js} +38 -9
- package/generated/utils/directive.cjs +1 -1
- package/generated/utils/directive.js +1 -1
- package/generated/utils/stores.cjs +1 -1
- package/generated/utils/stores.js +1 -1
- package/generated/utils/widget.cjs +1 -1
- package/generated/utils/widget.js +1 -1
- package/index.cjs +4 -4
- package/index.js +5 -5
- package/package.json +5 -5
- package/stores-DD819q-h.cjs +141 -0
- package/stores-DtfLvXAE.js +142 -0
- package/{widget-DaA-pe23.js → widget-6VfcHB3W.js} +3 -3
- package/{widget-e5vBb0i4.cjs → widget-CuLHUzFd.cjs} +2 -2
- package/components/tree/index.d.ts +0 -1
- package/components/tree/tree.d.ts +0 -1
- package/stores-B90XF8Sy.js +0 -78
- package/stores-skeXwTXt.cjs +0 -77
package/config.cjs
CHANGED
|
@@ -4,11 +4,11 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const config = require("@agnos-ui/core/config");
|
|
5
5
|
const tansu = require("@amadeus-it-group/tansu");
|
|
6
6
|
const react = require("react");
|
|
7
|
-
const widget = require("./widget-
|
|
8
|
-
const stores = require("./stores-
|
|
9
|
-
const widgetsConfigFactory = (
|
|
7
|
+
const widget = require("./widget-CuLHUzFd.cjs");
|
|
8
|
+
const stores = require("./stores-DD819q-h.cjs");
|
|
9
|
+
const widgetsConfigFactory = (WidgetsConfigContext2 = react.createContext(void 0)) => {
|
|
10
10
|
const useWidgetContext2 = (widgetName, defaultConfig) => {
|
|
11
|
-
const widgetsConfig = react.useContext(
|
|
11
|
+
const widgetsConfig = react.useContext(WidgetsConfigContext2);
|
|
12
12
|
const defaultConfig$ = stores.usePropsAsStore(defaultConfig);
|
|
13
13
|
return react.useMemo(
|
|
14
14
|
() => tansu.computed(() => ({ ...defaultConfig$(), ...widgetName ? widgetsConfig == null ? void 0 : widgetsConfig()[widgetName] : void 0 })),
|
|
@@ -17,37 +17,26 @@ const widgetsConfigFactory = (widgetsConfigContext2 = react.createContext(void 0
|
|
|
17
17
|
};
|
|
18
18
|
const useWidgetWithConfig2 = (factory, props, widgetName, defaultProps) => widget.useWidget(factory, props, { config: useWidgetContext2(widgetName, defaultProps) });
|
|
19
19
|
const WidgetsDefaultConfig2 = ({ children, adaptParentConfig, ...props }) => {
|
|
20
|
-
const config$ = react.useContext(
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const store = config.createWidgetsConfig(config$, adaptParentConfig);
|
|
25
|
-
store.set(props);
|
|
26
|
-
storeRecreated.current = true;
|
|
27
|
-
return store;
|
|
28
|
-
}, [config$, adaptParentConfig]);
|
|
29
|
-
react.useEffect(() => {
|
|
30
|
-
if (!storeRecreated.current) {
|
|
31
|
-
store$.set(props);
|
|
32
|
-
}
|
|
33
|
-
}, [props]);
|
|
34
|
-
return /* @__PURE__ */ jsxRuntime.jsx(widgetsConfigContext2.Provider, { value: store$, children });
|
|
20
|
+
const config$ = react.useContext(WidgetsConfigContext2);
|
|
21
|
+
const store$ = react.useMemo(() => config.createWidgetsConfig(config$, adaptParentConfig), [config$, adaptParentConfig]);
|
|
22
|
+
react.useMemo(() => store$.set(props), [props, store$]);
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WidgetsConfigContext2, { value: store$, children });
|
|
35
24
|
};
|
|
36
25
|
return {
|
|
37
26
|
/**
|
|
38
27
|
* React context which can be used to provide or consume the widgets default configuration store.
|
|
39
28
|
*/
|
|
40
|
-
|
|
29
|
+
WidgetsConfigContext: WidgetsConfigContext2,
|
|
41
30
|
useWidgetContext: useWidgetContext2,
|
|
42
31
|
useWidgetWithConfig: useWidgetWithConfig2,
|
|
43
32
|
WidgetsDefaultConfig: WidgetsDefaultConfig2
|
|
44
33
|
};
|
|
45
34
|
};
|
|
46
|
-
const {
|
|
35
|
+
const { WidgetsConfigContext, WidgetsDefaultConfig, useWidgetContext, useWidgetWithConfig } = widgetsConfigFactory();
|
|
36
|
+
exports.WidgetsConfigContext = WidgetsConfigContext;
|
|
47
37
|
exports.WidgetsDefaultConfig = WidgetsDefaultConfig;
|
|
48
38
|
exports.useWidgetContext = useWidgetContext;
|
|
49
39
|
exports.useWidgetWithConfig = useWidgetWithConfig;
|
|
50
|
-
exports.widgetsConfigContext = widgetsConfigContext;
|
|
51
40
|
exports.widgetsConfigFactory = widgetsConfigFactory;
|
|
52
41
|
Object.keys(config).forEach((k) => {
|
|
53
42
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
package/config.d.ts
CHANGED
|
@@ -11,16 +11,16 @@ type DefaultConfigInput<Config> = Partial2Levels<Config> & {
|
|
|
11
11
|
*
|
|
12
12
|
* It can be used when extending the core and creating new widgets.
|
|
13
13
|
*
|
|
14
|
-
* @param
|
|
14
|
+
* @param WidgetsConfigContext - the widgets config context
|
|
15
15
|
* @returns the use functions and react component
|
|
16
16
|
*/
|
|
17
|
-
export declare const widgetsConfigFactory: <Config extends Record<string, object> = WidgetsConfig>(
|
|
17
|
+
export declare const widgetsConfigFactory: <Config extends Record<string, object> = WidgetsConfig>(WidgetsConfigContext?: import("react").Context<WidgetsConfigStore<Config> | undefined>) => {
|
|
18
18
|
/**
|
|
19
19
|
* React context which can be used to provide or consume the widgets default configuration store.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
WidgetsConfigContext: import("react").Context<WidgetsConfigStore<Config> | undefined>;
|
|
22
22
|
useWidgetContext: <Props extends object>(widgetName: keyof Config | null, defaultConfig?: Partial<Props>) => import("@amadeus-it-group/tansu").ReadableSignal<Partial<Props>>;
|
|
23
23
|
useWidgetWithConfig: <W extends Widget>(factory: WidgetFactory<W>, props: Partial<WidgetProps<W>> | undefined, widgetName: keyof Config | null, defaultProps?: Partial<WidgetProps<W>>) => import("@agnos-ui/core/types").WidgetSlotContext<W>;
|
|
24
24
|
WidgetsDefaultConfig: ({ children, adaptParentConfig, ...props }: DefaultConfigInput<Config>) => import("react/jsx-runtime").JSX.Element;
|
|
25
25
|
};
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const WidgetsConfigContext: import("react").Context<WidgetsConfigStore<WidgetsConfig> | undefined>, WidgetsDefaultConfig: ({ children, adaptParentConfig, ...props }: DefaultConfigInput<WidgetsConfig>) => import("react/jsx-runtime").JSX.Element, useWidgetContext: <Props extends object>(widgetName: keyof WidgetsConfig | null, defaultConfig?: Partial<Props> | undefined) => import("@amadeus-it-group/tansu").ReadableSignal<Partial<Props>>, useWidgetWithConfig: <W extends Widget>(factory: WidgetFactory<W>, props: Partial<WidgetProps<W>> | undefined, widgetName: keyof WidgetsConfig | null, defaultProps?: Partial<WidgetProps<W>> | undefined) => import("@agnos-ui/core/types").WidgetSlotContext<W>;
|
package/config.js
CHANGED
|
@@ -2,12 +2,12 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { createWidgetsConfig } from "@agnos-ui/core/config";
|
|
3
3
|
export * from "@agnos-ui/core/config";
|
|
4
4
|
import { computed } from "@amadeus-it-group/tansu";
|
|
5
|
-
import { createContext, useContext, useMemo
|
|
6
|
-
import { u as useWidget } from "./widget-
|
|
7
|
-
import { b as usePropsAsStore } from "./stores-
|
|
8
|
-
const widgetsConfigFactory = (
|
|
5
|
+
import { createContext, useContext, useMemo } from "react";
|
|
6
|
+
import { u as useWidget } from "./widget-6VfcHB3W.js";
|
|
7
|
+
import { b as usePropsAsStore } from "./stores-DtfLvXAE.js";
|
|
8
|
+
const widgetsConfigFactory = (WidgetsConfigContext2 = createContext(void 0)) => {
|
|
9
9
|
const useWidgetContext2 = (widgetName, defaultConfig) => {
|
|
10
|
-
const widgetsConfig = useContext(
|
|
10
|
+
const widgetsConfig = useContext(WidgetsConfigContext2);
|
|
11
11
|
const defaultConfig$ = usePropsAsStore(defaultConfig);
|
|
12
12
|
return useMemo(
|
|
13
13
|
() => computed(() => ({ ...defaultConfig$(), ...widgetName ? widgetsConfig == null ? void 0 : widgetsConfig()[widgetName] : void 0 })),
|
|
@@ -16,37 +16,26 @@ const widgetsConfigFactory = (widgetsConfigContext2 = createContext(void 0)) =>
|
|
|
16
16
|
};
|
|
17
17
|
const useWidgetWithConfig2 = (factory, props, widgetName, defaultProps) => useWidget(factory, props, { config: useWidgetContext2(widgetName, defaultProps) });
|
|
18
18
|
const WidgetsDefaultConfig2 = ({ children, adaptParentConfig, ...props }) => {
|
|
19
|
-
const config$ = useContext(
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const store = createWidgetsConfig(config$, adaptParentConfig);
|
|
24
|
-
store.set(props);
|
|
25
|
-
storeRecreated.current = true;
|
|
26
|
-
return store;
|
|
27
|
-
}, [config$, adaptParentConfig]);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!storeRecreated.current) {
|
|
30
|
-
store$.set(props);
|
|
31
|
-
}
|
|
32
|
-
}, [props]);
|
|
33
|
-
return /* @__PURE__ */ jsx(widgetsConfigContext2.Provider, { value: store$, children });
|
|
19
|
+
const config$ = useContext(WidgetsConfigContext2);
|
|
20
|
+
const store$ = useMemo(() => createWidgetsConfig(config$, adaptParentConfig), [config$, adaptParentConfig]);
|
|
21
|
+
useMemo(() => store$.set(props), [props, store$]);
|
|
22
|
+
return /* @__PURE__ */ jsx(WidgetsConfigContext2, { value: store$, children });
|
|
34
23
|
};
|
|
35
24
|
return {
|
|
36
25
|
/**
|
|
37
26
|
* React context which can be used to provide or consume the widgets default configuration store.
|
|
38
27
|
*/
|
|
39
|
-
|
|
28
|
+
WidgetsConfigContext: WidgetsConfigContext2,
|
|
40
29
|
useWidgetContext: useWidgetContext2,
|
|
41
30
|
useWidgetWithConfig: useWidgetWithConfig2,
|
|
42
31
|
WidgetsDefaultConfig: WidgetsDefaultConfig2
|
|
43
32
|
};
|
|
44
33
|
};
|
|
45
|
-
const {
|
|
34
|
+
const { WidgetsConfigContext, WidgetsDefaultConfig, useWidgetContext, useWidgetWithConfig } = widgetsConfigFactory();
|
|
46
35
|
export {
|
|
36
|
+
WidgetsConfigContext,
|
|
47
37
|
WidgetsDefaultConfig,
|
|
48
38
|
useWidgetContext,
|
|
49
39
|
useWidgetWithConfig,
|
|
50
|
-
widgetsConfigContext,
|
|
51
40
|
widgetsConfigFactory
|
|
52
41
|
};
|
|
@@ -24,18 +24,47 @@ function directiveAttributes(...directives) {
|
|
|
24
24
|
return reactAttributes;
|
|
25
25
|
}
|
|
26
26
|
const ssrAttributes = esmEnv.BROWSER ? () => ({}) : directiveAttributes;
|
|
27
|
-
const useDirective = esmEnv.BROWSER ? (directive2, args) => {
|
|
27
|
+
const useDirective = esmEnv.BROWSER ? esmEnv.DEV ? (directive2, args) => {
|
|
28
28
|
var _a, _b;
|
|
29
|
-
const instance = react.useRef();
|
|
30
|
-
const propsRef = react.useRef();
|
|
29
|
+
const instance = react.useRef(void 0);
|
|
30
|
+
const propsRef = react.useRef(void 0);
|
|
31
|
+
const refCalledOnce = react.useRef(false);
|
|
32
|
+
react.useEffect(() => {
|
|
33
|
+
queueMicrotask(() => {
|
|
34
|
+
refCalledOnce.current = false;
|
|
35
|
+
});
|
|
36
|
+
}, [directive2]);
|
|
31
37
|
const ref = react.useCallback(
|
|
32
38
|
(element) => {
|
|
33
|
-
|
|
34
|
-
(_b2 = (_a2 = instance.current) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
|
|
35
|
-
instance.current = void 0;
|
|
36
|
-
if (element) {
|
|
39
|
+
if (!refCalledOnce.current) {
|
|
37
40
|
instance.current = directive2(element, propsRef.current);
|
|
41
|
+
refCalledOnce.current = true;
|
|
38
42
|
}
|
|
43
|
+
return () => {
|
|
44
|
+
var _a2, _b2;
|
|
45
|
+
if (!refCalledOnce.current) {
|
|
46
|
+
(_b2 = (_a2 = instance.current) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
|
|
47
|
+
instance.current = void 0;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
[directive2]
|
|
52
|
+
);
|
|
53
|
+
propsRef.current = args;
|
|
54
|
+
(_b = (_a = instance.current) == null ? void 0 : _a.update) == null ? void 0 : _b.call(_a, args);
|
|
55
|
+
return { ref };
|
|
56
|
+
} : (directive2, args) => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const instance = react.useRef(void 0);
|
|
59
|
+
const propsRef = react.useRef(void 0);
|
|
60
|
+
const ref = react.useCallback(
|
|
61
|
+
(element) => {
|
|
62
|
+
instance.current = directive2(element, propsRef.current);
|
|
63
|
+
return () => {
|
|
64
|
+
var _a2, _b2;
|
|
65
|
+
(_b2 = (_a2 = instance.current) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
|
|
66
|
+
instance.current = void 0;
|
|
67
|
+
};
|
|
39
68
|
},
|
|
40
69
|
[directive2]
|
|
41
70
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { attributesData, multiDirective } from "@agnos-ui/core/utils/directive";
|
|
2
|
-
import { BROWSER } from "esm-env";
|
|
3
|
-
import { useRef, useCallback } from "react";
|
|
2
|
+
import { BROWSER, DEV } from "esm-env";
|
|
3
|
+
import { useRef, useEffect, useCallback } from "react";
|
|
4
4
|
const attributesMap = /* @__PURE__ */ new Map([
|
|
5
5
|
["tabindex", "tabIndex"],
|
|
6
6
|
["for", "htmlFor"],
|
|
@@ -23,18 +23,47 @@ function directiveAttributes(...directives) {
|
|
|
23
23
|
return reactAttributes;
|
|
24
24
|
}
|
|
25
25
|
const ssrAttributes = BROWSER ? () => ({}) : directiveAttributes;
|
|
26
|
-
const useDirective = BROWSER ? (directive, args) => {
|
|
26
|
+
const useDirective = BROWSER ? DEV ? (directive, args) => {
|
|
27
27
|
var _a, _b;
|
|
28
|
-
const instance = useRef();
|
|
29
|
-
const propsRef = useRef();
|
|
28
|
+
const instance = useRef(void 0);
|
|
29
|
+
const propsRef = useRef(void 0);
|
|
30
|
+
const refCalledOnce = useRef(false);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
queueMicrotask(() => {
|
|
33
|
+
refCalledOnce.current = false;
|
|
34
|
+
});
|
|
35
|
+
}, [directive]);
|
|
30
36
|
const ref = useCallback(
|
|
31
37
|
(element) => {
|
|
32
|
-
|
|
33
|
-
(_b2 = (_a2 = instance.current) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
|
|
34
|
-
instance.current = void 0;
|
|
35
|
-
if (element) {
|
|
38
|
+
if (!refCalledOnce.current) {
|
|
36
39
|
instance.current = directive(element, propsRef.current);
|
|
40
|
+
refCalledOnce.current = true;
|
|
37
41
|
}
|
|
42
|
+
return () => {
|
|
43
|
+
var _a2, _b2;
|
|
44
|
+
if (!refCalledOnce.current) {
|
|
45
|
+
(_b2 = (_a2 = instance.current) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
|
|
46
|
+
instance.current = void 0;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
[directive]
|
|
51
|
+
);
|
|
52
|
+
propsRef.current = args;
|
|
53
|
+
(_b = (_a = instance.current) == null ? void 0 : _a.update) == null ? void 0 : _b.call(_a, args);
|
|
54
|
+
return { ref };
|
|
55
|
+
} : (directive, args) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const instance = useRef(void 0);
|
|
58
|
+
const propsRef = useRef(void 0);
|
|
59
|
+
const ref = useCallback(
|
|
60
|
+
(element) => {
|
|
61
|
+
instance.current = directive(element, propsRef.current);
|
|
62
|
+
return () => {
|
|
63
|
+
var _a2, _b2;
|
|
64
|
+
(_b2 = (_a2 = instance.current) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
|
|
65
|
+
instance.current = void 0;
|
|
66
|
+
};
|
|
38
67
|
},
|
|
39
68
|
[directive]
|
|
40
69
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const directive = require("../../directive-
|
|
3
|
+
const directive = require("../../directive-3diaW3tS.cjs");
|
|
4
4
|
const directive$1 = require("@agnos-ui/core/utils/directive");
|
|
5
5
|
exports.directiveAttributes = directive.directiveAttributes;
|
|
6
6
|
exports.ssrAttributes = directive.ssrAttributes;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const stores = require("../../stores-
|
|
3
|
+
const stores = require("../../stores-DD819q-h.cjs");
|
|
4
4
|
const stores$1 = require("@agnos-ui/core/utils/stores");
|
|
5
5
|
exports.useObservable = stores.useObservable;
|
|
6
6
|
exports.useObservablesProxy = stores.useObservablesProxy;
|
package/index.cjs
CHANGED
|
@@ -16,13 +16,13 @@ const collapse = require("@agnos-ui/core/services/transitions/collapse");
|
|
|
16
16
|
const baseTransitions = require("@agnos-ui/core/services/transitions/baseTransitions");
|
|
17
17
|
const writables = require("@agnos-ui/core/utils/writables");
|
|
18
18
|
const stores$1 = require("@agnos-ui/core/utils/stores");
|
|
19
|
-
const stores = require("./stores-
|
|
19
|
+
const stores = require("./stores-DD819q-h.cjs");
|
|
20
20
|
const directive$1 = require("@agnos-ui/core/utils/directive");
|
|
21
|
-
const directive = require("./directive-
|
|
21
|
+
const directive = require("./directive-3diaW3tS.cjs");
|
|
22
22
|
const types = require("@agnos-ui/core/types");
|
|
23
23
|
const config$1 = require("@agnos-ui/core/config");
|
|
24
24
|
const config = require("./config.cjs");
|
|
25
|
-
const widget = require("./widget-
|
|
25
|
+
const widget = require("./widget-CuLHUzFd.cjs");
|
|
26
26
|
const portal$1 = require("./portal-B0Q5KLrA.cjs");
|
|
27
27
|
const slot = require("./slot.cjs");
|
|
28
28
|
const tree = require("@agnos-ui/core/components/tree");
|
|
@@ -42,10 +42,10 @@ exports.directiveAttributes = directive.directiveAttributes;
|
|
|
42
42
|
exports.ssrAttributes = directive.ssrAttributes;
|
|
43
43
|
exports.useDirective = directive.useDirective;
|
|
44
44
|
exports.useDirectives = directive.useDirectives;
|
|
45
|
+
exports.WidgetsConfigContext = config.WidgetsConfigContext;
|
|
45
46
|
exports.WidgetsDefaultConfig = config.WidgetsDefaultConfig;
|
|
46
47
|
exports.useWidgetContext = config.useWidgetContext;
|
|
47
48
|
exports.useWidgetWithConfig = config.useWidgetWithConfig;
|
|
48
|
-
exports.widgetsConfigContext = config.widgetsConfigContext;
|
|
49
49
|
exports.widgetsConfigFactory = config.widgetsConfigFactory;
|
|
50
50
|
exports.useWidget = widget.useWidget;
|
|
51
51
|
exports.Portal = portal$1.Portal;
|
package/index.js
CHANGED
|
@@ -14,13 +14,13 @@ export * from "@agnos-ui/core/services/transitions/collapse";
|
|
|
14
14
|
export * from "@agnos-ui/core/services/transitions/baseTransitions";
|
|
15
15
|
export * from "@agnos-ui/core/utils/writables";
|
|
16
16
|
export * from "@agnos-ui/core/utils/stores";
|
|
17
|
-
import { u, a, b } from "./stores-
|
|
17
|
+
import { u, a, b } from "./stores-DtfLvXAE.js";
|
|
18
18
|
export * from "@agnos-ui/core/utils/directive";
|
|
19
|
-
import { d, s, u as u2, a as a2 } from "./directive-
|
|
19
|
+
import { d, s, u as u2, a as a2 } from "./directive-CEErjM5c.js";
|
|
20
20
|
export * from "@agnos-ui/core/types";
|
|
21
21
|
export * from "@agnos-ui/core/config";
|
|
22
|
-
import { WidgetsDefaultConfig, useWidgetContext, useWidgetWithConfig,
|
|
23
|
-
import { u as u3 } from "./widget-
|
|
22
|
+
import { WidgetsConfigContext, WidgetsDefaultConfig, useWidgetContext, useWidgetWithConfig, widgetsConfigFactory } from "./config.js";
|
|
23
|
+
import { u as u3 } from "./widget-6VfcHB3W.js";
|
|
24
24
|
import { P } from "./portal-CX8X69NK.js";
|
|
25
25
|
import { Slot } from "./slot.js";
|
|
26
26
|
export * from "@agnos-ui/core/components/tree";
|
|
@@ -36,6 +36,7 @@ export * from "@agnos-ui/core/components/accordion";
|
|
|
36
36
|
export {
|
|
37
37
|
P as Portal,
|
|
38
38
|
Slot,
|
|
39
|
+
WidgetsConfigContext,
|
|
39
40
|
WidgetsDefaultConfig,
|
|
40
41
|
d as directiveAttributes,
|
|
41
42
|
s as ssrAttributes,
|
|
@@ -47,6 +48,5 @@ export {
|
|
|
47
48
|
u3 as useWidget,
|
|
48
49
|
useWidgetContext,
|
|
49
50
|
useWidgetWithConfig,
|
|
50
|
-
widgetsConfigContext,
|
|
51
51
|
widgetsConfigFactory
|
|
52
52
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnos-ui/react-headless",
|
|
3
3
|
"description": "Headless component library for React.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"module": "./index.js",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@agnos-ui/core": "0.
|
|
52
|
+
"@agnos-ui/core": "0.7.0",
|
|
53
53
|
"classnames": "^2.5.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@amadeus-it-group/tansu": "^
|
|
56
|
+
"@amadeus-it-group/tansu": "^2.0.0",
|
|
57
57
|
"esm-env": "^1.2.1",
|
|
58
|
-
"react": "^
|
|
59
|
-
"react-dom": "^
|
|
58
|
+
"react": "^19.0.0",
|
|
59
|
+
"react-dom": "^19.0.0"
|
|
60
60
|
},
|
|
61
61
|
"sideEffects": false,
|
|
62
62
|
"homepage": "https://www.agnosui.dev/latest/",
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const stores = require("@agnos-ui/core/utils/stores");
|
|
3
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
let queue;
|
|
6
|
+
const processQueue = () => {
|
|
7
|
+
if (queue) {
|
|
8
|
+
try {
|
|
9
|
+
for (let i = 0; i < queue.length; i++) {
|
|
10
|
+
const { rerender, state, obj } = queue[i];
|
|
11
|
+
if (state.notified === obj && state.hasEffect) {
|
|
12
|
+
rerender(obj);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
} finally {
|
|
16
|
+
queue = void 0;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const createOnStoreChange = (rerender, internalState) => () => {
|
|
21
|
+
if (internalState.changed && !internalState.notified) {
|
|
22
|
+
const obj = {};
|
|
23
|
+
internalState.notified = obj;
|
|
24
|
+
if (!queue) {
|
|
25
|
+
queueMicrotask(processQueue);
|
|
26
|
+
queue = [];
|
|
27
|
+
}
|
|
28
|
+
queue.push({ rerender, state: internalState, obj });
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function useObservable(store$) {
|
|
32
|
+
const [, rerender] = react.useState({});
|
|
33
|
+
const internalState = react.useMemo(() => {
|
|
34
|
+
const internalState2 = {
|
|
35
|
+
hasEffect: false,
|
|
36
|
+
changed: false,
|
|
37
|
+
notified: false,
|
|
38
|
+
store$: tansu.computed(() => {
|
|
39
|
+
internalState2.changed = true;
|
|
40
|
+
return store$();
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
return internalState2;
|
|
44
|
+
}, [store$]);
|
|
45
|
+
react.useEffect(() => {
|
|
46
|
+
internalState.hasEffect = true;
|
|
47
|
+
const unsubscribe = internalState.store$.subscribe(createOnStoreChange(rerender, internalState));
|
|
48
|
+
return () => {
|
|
49
|
+
internalState.hasEffect = false;
|
|
50
|
+
unsubscribe();
|
|
51
|
+
};
|
|
52
|
+
}, [internalState]);
|
|
53
|
+
const value = internalState.store$();
|
|
54
|
+
internalState.changed = false;
|
|
55
|
+
internalState.notified = false;
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
const createComputed = (store, internalState) => {
|
|
59
|
+
let firstComputation = true;
|
|
60
|
+
return tansu.computed(() => {
|
|
61
|
+
if (firstComputation) {
|
|
62
|
+
firstComputation = false;
|
|
63
|
+
} else {
|
|
64
|
+
internalState.changed = true;
|
|
65
|
+
}
|
|
66
|
+
return store();
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
function useObservablesProxy(stores2) {
|
|
70
|
+
const [, rerender] = react.useState({});
|
|
71
|
+
const internalState = react.useMemo(() => {
|
|
72
|
+
const internalState2 = {
|
|
73
|
+
hasEffect: false,
|
|
74
|
+
notified: false,
|
|
75
|
+
changed: false,
|
|
76
|
+
storeInfo: {},
|
|
77
|
+
checkStoreSubscribed: (key) => {
|
|
78
|
+
const store = stores2[`${key}$`];
|
|
79
|
+
if (store) {
|
|
80
|
+
let storeInfo = internalState2.storeInfo[key];
|
|
81
|
+
if (!storeInfo || storeInfo.store !== store) {
|
|
82
|
+
const unsubscribe = storeInfo == null ? void 0 : storeInfo.unsubscribe;
|
|
83
|
+
storeInfo = {
|
|
84
|
+
store,
|
|
85
|
+
computedStore: createComputed(store, internalState2),
|
|
86
|
+
unsubscribe: null
|
|
87
|
+
};
|
|
88
|
+
internalState2.storeInfo[key] = storeInfo;
|
|
89
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
90
|
+
}
|
|
91
|
+
if (internalState2.hasEffect && !storeInfo.unsubscribe) {
|
|
92
|
+
storeInfo.unsubscribe = storeInfo.computedStore.subscribe(onStoreChange);
|
|
93
|
+
}
|
|
94
|
+
return storeInfo.computedStore;
|
|
95
|
+
}
|
|
96
|
+
return void 0;
|
|
97
|
+
},
|
|
98
|
+
proxy: new Proxy(
|
|
99
|
+
{},
|
|
100
|
+
{
|
|
101
|
+
get(_target, name) {
|
|
102
|
+
const store = typeof name === "string" ? internalState2.checkStoreSubscribed(name) : null;
|
|
103
|
+
return store == null ? void 0 : store();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
};
|
|
108
|
+
const onStoreChange = createOnStoreChange(rerender, internalState2);
|
|
109
|
+
return internalState2;
|
|
110
|
+
}, []);
|
|
111
|
+
internalState.notified = false;
|
|
112
|
+
internalState.changed = false;
|
|
113
|
+
react.useEffect(() => {
|
|
114
|
+
internalState.hasEffect = true;
|
|
115
|
+
for (const key of Object.keys(internalState.storeInfo)) {
|
|
116
|
+
internalState.checkStoreSubscribed(key);
|
|
117
|
+
}
|
|
118
|
+
return () => {
|
|
119
|
+
internalState.hasEffect = false;
|
|
120
|
+
for (const info of Object.values(internalState.storeInfo)) {
|
|
121
|
+
const unsubscribe = info.unsubscribe;
|
|
122
|
+
info.unsubscribe = null;
|
|
123
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}, [stores2]);
|
|
127
|
+
return internalState.proxy;
|
|
128
|
+
}
|
|
129
|
+
const propsEqual = (a, b) => !stores.findChangedProperties(a, b);
|
|
130
|
+
const usePropsAsStore = (props) => {
|
|
131
|
+
const storeRef = react.useRef(void 0);
|
|
132
|
+
if (!storeRef.current) {
|
|
133
|
+
storeRef.current = tansu.writable({ ...props }, { equal: propsEqual });
|
|
134
|
+
} else {
|
|
135
|
+
storeRef.current.set({ ...props });
|
|
136
|
+
}
|
|
137
|
+
return react.useMemo(() => tansu.asReadable(storeRef.current), [storeRef.current]);
|
|
138
|
+
};
|
|
139
|
+
exports.useObservable = useObservable;
|
|
140
|
+
exports.useObservablesProxy = useObservablesProxy;
|
|
141
|
+
exports.usePropsAsStore = usePropsAsStore;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { findChangedProperties } from "@agnos-ui/core/utils/stores";
|
|
2
|
+
import { computed, writable, asReadable } from "@amadeus-it-group/tansu";
|
|
3
|
+
import { useState, useMemo, useEffect, useRef } from "react";
|
|
4
|
+
let queue;
|
|
5
|
+
const processQueue = () => {
|
|
6
|
+
if (queue) {
|
|
7
|
+
try {
|
|
8
|
+
for (let i = 0; i < queue.length; i++) {
|
|
9
|
+
const { rerender, state, obj } = queue[i];
|
|
10
|
+
if (state.notified === obj && state.hasEffect) {
|
|
11
|
+
rerender(obj);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
} finally {
|
|
15
|
+
queue = void 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const createOnStoreChange = (rerender, internalState) => () => {
|
|
20
|
+
if (internalState.changed && !internalState.notified) {
|
|
21
|
+
const obj = {};
|
|
22
|
+
internalState.notified = obj;
|
|
23
|
+
if (!queue) {
|
|
24
|
+
queueMicrotask(processQueue);
|
|
25
|
+
queue = [];
|
|
26
|
+
}
|
|
27
|
+
queue.push({ rerender, state: internalState, obj });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function useObservable(store$) {
|
|
31
|
+
const [, rerender] = useState({});
|
|
32
|
+
const internalState = useMemo(() => {
|
|
33
|
+
const internalState2 = {
|
|
34
|
+
hasEffect: false,
|
|
35
|
+
changed: false,
|
|
36
|
+
notified: false,
|
|
37
|
+
store$: computed(() => {
|
|
38
|
+
internalState2.changed = true;
|
|
39
|
+
return store$();
|
|
40
|
+
})
|
|
41
|
+
};
|
|
42
|
+
return internalState2;
|
|
43
|
+
}, [store$]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
internalState.hasEffect = true;
|
|
46
|
+
const unsubscribe = internalState.store$.subscribe(createOnStoreChange(rerender, internalState));
|
|
47
|
+
return () => {
|
|
48
|
+
internalState.hasEffect = false;
|
|
49
|
+
unsubscribe();
|
|
50
|
+
};
|
|
51
|
+
}, [internalState]);
|
|
52
|
+
const value = internalState.store$();
|
|
53
|
+
internalState.changed = false;
|
|
54
|
+
internalState.notified = false;
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
const createComputed = (store, internalState) => {
|
|
58
|
+
let firstComputation = true;
|
|
59
|
+
return computed(() => {
|
|
60
|
+
if (firstComputation) {
|
|
61
|
+
firstComputation = false;
|
|
62
|
+
} else {
|
|
63
|
+
internalState.changed = true;
|
|
64
|
+
}
|
|
65
|
+
return store();
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
function useObservablesProxy(stores) {
|
|
69
|
+
const [, rerender] = useState({});
|
|
70
|
+
const internalState = useMemo(() => {
|
|
71
|
+
const internalState2 = {
|
|
72
|
+
hasEffect: false,
|
|
73
|
+
notified: false,
|
|
74
|
+
changed: false,
|
|
75
|
+
storeInfo: {},
|
|
76
|
+
checkStoreSubscribed: (key) => {
|
|
77
|
+
const store = stores[`${key}$`];
|
|
78
|
+
if (store) {
|
|
79
|
+
let storeInfo = internalState2.storeInfo[key];
|
|
80
|
+
if (!storeInfo || storeInfo.store !== store) {
|
|
81
|
+
const unsubscribe = storeInfo == null ? void 0 : storeInfo.unsubscribe;
|
|
82
|
+
storeInfo = {
|
|
83
|
+
store,
|
|
84
|
+
computedStore: createComputed(store, internalState2),
|
|
85
|
+
unsubscribe: null
|
|
86
|
+
};
|
|
87
|
+
internalState2.storeInfo[key] = storeInfo;
|
|
88
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
89
|
+
}
|
|
90
|
+
if (internalState2.hasEffect && !storeInfo.unsubscribe) {
|
|
91
|
+
storeInfo.unsubscribe = storeInfo.computedStore.subscribe(onStoreChange);
|
|
92
|
+
}
|
|
93
|
+
return storeInfo.computedStore;
|
|
94
|
+
}
|
|
95
|
+
return void 0;
|
|
96
|
+
},
|
|
97
|
+
proxy: new Proxy(
|
|
98
|
+
{},
|
|
99
|
+
{
|
|
100
|
+
get(_target, name) {
|
|
101
|
+
const store = typeof name === "string" ? internalState2.checkStoreSubscribed(name) : null;
|
|
102
|
+
return store == null ? void 0 : store();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
};
|
|
107
|
+
const onStoreChange = createOnStoreChange(rerender, internalState2);
|
|
108
|
+
return internalState2;
|
|
109
|
+
}, []);
|
|
110
|
+
internalState.notified = false;
|
|
111
|
+
internalState.changed = false;
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
internalState.hasEffect = true;
|
|
114
|
+
for (const key of Object.keys(internalState.storeInfo)) {
|
|
115
|
+
internalState.checkStoreSubscribed(key);
|
|
116
|
+
}
|
|
117
|
+
return () => {
|
|
118
|
+
internalState.hasEffect = false;
|
|
119
|
+
for (const info of Object.values(internalState.storeInfo)) {
|
|
120
|
+
const unsubscribe = info.unsubscribe;
|
|
121
|
+
info.unsubscribe = null;
|
|
122
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}, [stores]);
|
|
126
|
+
return internalState.proxy;
|
|
127
|
+
}
|
|
128
|
+
const propsEqual = (a, b) => !findChangedProperties(a, b);
|
|
129
|
+
const usePropsAsStore = (props) => {
|
|
130
|
+
const storeRef = useRef(void 0);
|
|
131
|
+
if (!storeRef.current) {
|
|
132
|
+
storeRef.current = writable({ ...props }, { equal: propsEqual });
|
|
133
|
+
} else {
|
|
134
|
+
storeRef.current.set({ ...props });
|
|
135
|
+
}
|
|
136
|
+
return useMemo(() => asReadable(storeRef.current), [storeRef.current]);
|
|
137
|
+
};
|
|
138
|
+
export {
|
|
139
|
+
useObservablesProxy as a,
|
|
140
|
+
usePropsAsStore as b,
|
|
141
|
+
useObservable as u
|
|
142
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { findChangedProperties } from "@agnos-ui/core/utils/stores";
|
|
2
|
-
import { useMemo, useRef
|
|
3
|
-
import { a as useObservablesProxy } from "./stores-
|
|
2
|
+
import { useMemo, useRef } from "react";
|
|
3
|
+
import { a as useObservablesProxy } from "./stores-DtfLvXAE.js";
|
|
4
4
|
function useWidget(createWidget, props = {}, propsConfig) {
|
|
5
5
|
const coreWidget = useMemo(() => createWidget({ ...propsConfig, props: { ...propsConfig == null ? void 0 : propsConfig.props, ...props } }), []);
|
|
6
6
|
const previousProps = useRef(props);
|
|
7
|
-
|
|
7
|
+
useMemo(() => {
|
|
8
8
|
const changedProps = findChangedProperties(previousProps.current, props);
|
|
9
9
|
previousProps.current = props;
|
|
10
10
|
if (changedProps) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const stores = require("@agnos-ui/core/utils/stores");
|
|
3
3
|
const react = require("react");
|
|
4
|
-
const stores$1 = require("./stores-
|
|
4
|
+
const stores$1 = require("./stores-DD819q-h.cjs");
|
|
5
5
|
function useWidget(createWidget, props = {}, propsConfig) {
|
|
6
6
|
const coreWidget = react.useMemo(() => createWidget({ ...propsConfig, props: { ...propsConfig == null ? void 0 : propsConfig.props, ...props } }), []);
|
|
7
7
|
const previousProps = react.useRef(props);
|
|
8
|
-
react.
|
|
8
|
+
react.useMemo(() => {
|
|
9
9
|
const changedProps = stores.findChangedProperties(previousProps.current, props);
|
|
10
10
|
previousProps.current = props;
|
|
11
11
|
if (changedProps) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './tree';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@agnos-ui/core/components/tree';
|
package/stores-B90XF8Sy.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { findChangedProperties } from "@agnos-ui/core/utils/stores";
|
|
2
|
-
import { writable, asReadable } from "@amadeus-it-group/tansu";
|
|
3
|
-
import { useState, useEffect, useMemo, useRef } from "react";
|
|
4
|
-
function useObservable(store$) {
|
|
5
|
-
const [value, setValue] = useState(() => store$());
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
return store$.subscribe((arg) => {
|
|
8
|
-
setValue(() => arg);
|
|
9
|
-
});
|
|
10
|
-
}, [store$]);
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
function useObservablesProxy(stores) {
|
|
14
|
-
const [, triggerRerender] = useState({});
|
|
15
|
-
const internalState = useMemo(() => {
|
|
16
|
-
const internalState2 = {
|
|
17
|
-
hasEffect: false,
|
|
18
|
-
storeInfo: {},
|
|
19
|
-
checkStoreSubscribed: (key) => {
|
|
20
|
-
const store = stores[`${key}$`];
|
|
21
|
-
if (store) {
|
|
22
|
-
let storeInfo = internalState2.storeInfo[key];
|
|
23
|
-
if (!storeInfo) {
|
|
24
|
-
storeInfo = { unsubscribe: null };
|
|
25
|
-
internalState2.storeInfo[key] = storeInfo;
|
|
26
|
-
}
|
|
27
|
-
if (internalState2.hasEffect && !storeInfo.unsubscribe) {
|
|
28
|
-
storeInfo.unsubscribe = store.subscribe(() => {
|
|
29
|
-
triggerRerender({});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return store;
|
|
34
|
-
},
|
|
35
|
-
proxy: new Proxy(
|
|
36
|
-
{},
|
|
37
|
-
{
|
|
38
|
-
get(_target, name) {
|
|
39
|
-
const store = typeof name === "string" ? internalState2.checkStoreSubscribed(name) : null;
|
|
40
|
-
return store == null ? void 0 : store();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
)
|
|
44
|
-
};
|
|
45
|
-
return internalState2;
|
|
46
|
-
}, []);
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
internalState.hasEffect = true;
|
|
49
|
-
for (const key of Object.keys(internalState.storeInfo)) {
|
|
50
|
-
internalState.checkStoreSubscribed(key);
|
|
51
|
-
}
|
|
52
|
-
return () => {
|
|
53
|
-
internalState.hasEffect = false;
|
|
54
|
-
for (const info of Object.values(internalState.storeInfo)) {
|
|
55
|
-
const unsubscribe = info.unsubscribe;
|
|
56
|
-
info.unsubscribe = null;
|
|
57
|
-
unsubscribe == null ? void 0 : unsubscribe();
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}, [stores]);
|
|
61
|
-
return internalState.proxy;
|
|
62
|
-
}
|
|
63
|
-
const propsEqual = (a, b) => !findChangedProperties(a, b);
|
|
64
|
-
const usePropsAsStore = (props) => {
|
|
65
|
-
const storeRef = useRef();
|
|
66
|
-
if (!storeRef.current) {
|
|
67
|
-
storeRef.current = writable({ ...props }, { equal: propsEqual });
|
|
68
|
-
}
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
storeRef.current.set({ ...props });
|
|
71
|
-
}, [props]);
|
|
72
|
-
return useMemo(() => asReadable(storeRef.current), [storeRef.current]);
|
|
73
|
-
};
|
|
74
|
-
export {
|
|
75
|
-
useObservablesProxy as a,
|
|
76
|
-
usePropsAsStore as b,
|
|
77
|
-
useObservable as u
|
|
78
|
-
};
|
package/stores-skeXwTXt.cjs
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const stores = require("@agnos-ui/core/utils/stores");
|
|
3
|
-
const tansu = require("@amadeus-it-group/tansu");
|
|
4
|
-
const react = require("react");
|
|
5
|
-
function useObservable(store$) {
|
|
6
|
-
const [value, setValue] = react.useState(() => store$());
|
|
7
|
-
react.useEffect(() => {
|
|
8
|
-
return store$.subscribe((arg) => {
|
|
9
|
-
setValue(() => arg);
|
|
10
|
-
});
|
|
11
|
-
}, [store$]);
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
function useObservablesProxy(stores2) {
|
|
15
|
-
const [, triggerRerender] = react.useState({});
|
|
16
|
-
const internalState = react.useMemo(() => {
|
|
17
|
-
const internalState2 = {
|
|
18
|
-
hasEffect: false,
|
|
19
|
-
storeInfo: {},
|
|
20
|
-
checkStoreSubscribed: (key) => {
|
|
21
|
-
const store = stores2[`${key}$`];
|
|
22
|
-
if (store) {
|
|
23
|
-
let storeInfo = internalState2.storeInfo[key];
|
|
24
|
-
if (!storeInfo) {
|
|
25
|
-
storeInfo = { unsubscribe: null };
|
|
26
|
-
internalState2.storeInfo[key] = storeInfo;
|
|
27
|
-
}
|
|
28
|
-
if (internalState2.hasEffect && !storeInfo.unsubscribe) {
|
|
29
|
-
storeInfo.unsubscribe = store.subscribe(() => {
|
|
30
|
-
triggerRerender({});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return store;
|
|
35
|
-
},
|
|
36
|
-
proxy: new Proxy(
|
|
37
|
-
{},
|
|
38
|
-
{
|
|
39
|
-
get(_target, name) {
|
|
40
|
-
const store = typeof name === "string" ? internalState2.checkStoreSubscribed(name) : null;
|
|
41
|
-
return store == null ? void 0 : store();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
)
|
|
45
|
-
};
|
|
46
|
-
return internalState2;
|
|
47
|
-
}, []);
|
|
48
|
-
react.useEffect(() => {
|
|
49
|
-
internalState.hasEffect = true;
|
|
50
|
-
for (const key of Object.keys(internalState.storeInfo)) {
|
|
51
|
-
internalState.checkStoreSubscribed(key);
|
|
52
|
-
}
|
|
53
|
-
return () => {
|
|
54
|
-
internalState.hasEffect = false;
|
|
55
|
-
for (const info of Object.values(internalState.storeInfo)) {
|
|
56
|
-
const unsubscribe = info.unsubscribe;
|
|
57
|
-
info.unsubscribe = null;
|
|
58
|
-
unsubscribe == null ? void 0 : unsubscribe();
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}, [stores2]);
|
|
62
|
-
return internalState.proxy;
|
|
63
|
-
}
|
|
64
|
-
const propsEqual = (a, b) => !stores.findChangedProperties(a, b);
|
|
65
|
-
const usePropsAsStore = (props) => {
|
|
66
|
-
const storeRef = react.useRef();
|
|
67
|
-
if (!storeRef.current) {
|
|
68
|
-
storeRef.current = tansu.writable({ ...props }, { equal: propsEqual });
|
|
69
|
-
}
|
|
70
|
-
react.useEffect(() => {
|
|
71
|
-
storeRef.current.set({ ...props });
|
|
72
|
-
}, [props]);
|
|
73
|
-
return react.useMemo(() => tansu.asReadable(storeRef.current), [storeRef.current]);
|
|
74
|
-
};
|
|
75
|
-
exports.useObservable = useObservable;
|
|
76
|
-
exports.useObservablesProxy = useObservablesProxy;
|
|
77
|
-
exports.usePropsAsStore = usePropsAsStore;
|