@agnos-ui/react-headless 0.4.4 → 0.5.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 +2 -2
- package/config.cjs +2 -2
- package/config.d.ts +3 -3
- package/config.js +2 -2
- package/{directive-4SKmV5bk.cjs → directive-BePQvMpx.cjs} +4 -1
- package/{directive-Kqp31pwt.js → directive-DNXkB1Wc.js} +4 -1
- package/generated/utils/directive.cjs +1 -1
- package/generated/utils/directive.js +1 -1
- package/generated/utils/stores.cjs +2 -1
- package/generated/utils/stores.js +3 -2
- package/generated/utils/widget.cjs +1 -1
- package/generated/utils/widget.js +1 -1
- package/index.cjs +4 -3
- package/index.js +5 -4
- package/package.json +6 -5
- package/stores-B90XF8Sy.js +78 -0
- package/stores-skeXwTXt.cjs +77 -0
- package/types.d.ts +12 -0
- package/utils/stores.d.ts +13 -0
- package/utils/widget.d.ts +3 -3
- package/{widget-DAs9_HQ1.js → widget-DaA-pe23.js} +5 -5
- package/{widget-CqgI0B-w.cjs → widget-e5vBb0i4.cjs} +5 -5
- package/stores-B8YEDwZq.js +0 -27
- package/stores-DLkDMqBY.cjs +0 -26
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@agnos-ui/react-headless)
|
|
4
4
|
|
|
5
|
-
Headless
|
|
5
|
+
Headless component library for [React](https://react.dev/).
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -12,4 +12,4 @@ npm install @agnos-ui/react-headless
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
Please check [our demo site](https://
|
|
15
|
+
Please check [our demo site](https://www.agnosui.dev/latest/) to see all the available components and how to use them.
|
package/config.cjs
CHANGED
|
@@ -4,8 +4,8 @@ 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-
|
|
7
|
+
const widget = require("./widget-e5vBb0i4.cjs");
|
|
8
|
+
const stores = require("./stores-skeXwTXt.cjs");
|
|
9
9
|
const widgetsConfigFactory = (widgetsConfigContext2 = react.createContext(void 0)) => {
|
|
10
10
|
const useWidgetContext2 = (widgetName, defaultConfig) => {
|
|
11
11
|
const widgetsConfig = react.useContext(widgetsConfigContext2);
|
package/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Widget, WidgetFactory, WidgetProps
|
|
1
|
+
import type { Widget, WidgetFactory, WidgetProps } from '@agnos-ui/core/types';
|
|
2
2
|
import { type WidgetsConfigStore, type WidgetsConfig, type Partial2Levels } from '@agnos-ui/core/config';
|
|
3
3
|
import type { ReactNode } from 'react';
|
|
4
4
|
export * from '@agnos-ui/core/config';
|
|
@@ -20,7 +20,7 @@ export declare const widgetsConfigFactory: <Config extends Record<string, object
|
|
|
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
|
-
useWidgetWithConfig: <W extends Widget>(factory: WidgetFactory<W>, props: Partial<WidgetProps<W>> | undefined, widgetName: keyof Config | null, defaultProps?: Partial<WidgetProps<W>>) =>
|
|
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 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) =>
|
|
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
|
@@ -3,8 +3,8 @@ 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
5
|
import { createContext, useContext, useMemo, useEffect } from "react";
|
|
6
|
-
import { u as useWidget } from "./widget-
|
|
7
|
-
import {
|
|
6
|
+
import { u as useWidget } from "./widget-DaA-pe23.js";
|
|
7
|
+
import { b as usePropsAsStore } from "./stores-B90XF8Sy.js";
|
|
8
8
|
const widgetsConfigFactory = (widgetsConfigContext2 = createContext(void 0)) => {
|
|
9
9
|
const useWidgetContext2 = (widgetName, defaultConfig) => {
|
|
10
10
|
const widgetsConfig = useContext(widgetsConfigContext2);
|
|
@@ -4,7 +4,10 @@ const esmEnv = require("esm-env");
|
|
|
4
4
|
const react = require("react");
|
|
5
5
|
const attributesMap = /* @__PURE__ */ new Map([
|
|
6
6
|
["tabindex", "tabIndex"],
|
|
7
|
-
["for", "htmlFor"]
|
|
7
|
+
["for", "htmlFor"],
|
|
8
|
+
["autocomplete", "autoComplete"],
|
|
9
|
+
["autocapitalize", "autoCapitalize"],
|
|
10
|
+
["autocorrect", "autoCorrect"]
|
|
8
11
|
]);
|
|
9
12
|
function directiveAttributes(...directives) {
|
|
10
13
|
const reactAttributes = {};
|
|
@@ -3,7 +3,10 @@ import { BROWSER } from "esm-env";
|
|
|
3
3
|
import { useRef, useCallback } from "react";
|
|
4
4
|
const attributesMap = /* @__PURE__ */ new Map([
|
|
5
5
|
["tabindex", "tabIndex"],
|
|
6
|
-
["for", "htmlFor"]
|
|
6
|
+
["for", "htmlFor"],
|
|
7
|
+
["autocomplete", "autoComplete"],
|
|
8
|
+
["autocapitalize", "autoCapitalize"],
|
|
9
|
+
["autocorrect", "autoCorrect"]
|
|
7
10
|
]);
|
|
8
11
|
function directiveAttributes(...directives) {
|
|
9
12
|
const reactAttributes = {};
|
|
@@ -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-BePQvMpx.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,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const stores = require("../../stores-
|
|
3
|
+
const stores = require("../../stores-skeXwTXt.cjs");
|
|
4
4
|
const stores$1 = require("@agnos-ui/core/utils/stores");
|
|
5
5
|
exports.useObservable = stores.useObservable;
|
|
6
|
+
exports.useObservablesProxy = stores.useObservablesProxy;
|
|
6
7
|
exports.usePropsAsStore = stores.usePropsAsStore;
|
|
7
8
|
Object.keys(stores$1).forEach((k) => {
|
|
8
9
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
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-skeXwTXt.cjs");
|
|
20
20
|
const directive$1 = require("@agnos-ui/core/utils/directive");
|
|
21
|
-
const directive = require("./directive-
|
|
21
|
+
const directive = require("./directive-BePQvMpx.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-e5vBb0i4.cjs");
|
|
26
26
|
const portal$1 = require("./portal-B0Q5KLrA.cjs");
|
|
27
27
|
const slot = require("./slot.cjs");
|
|
28
28
|
const toast = require("@agnos-ui/core/components/toast");
|
|
@@ -35,6 +35,7 @@ const modal = require("@agnos-ui/core/components/modal");
|
|
|
35
35
|
const alert = require("@agnos-ui/core/components/alert");
|
|
36
36
|
const accordion = require("@agnos-ui/core/components/accordion");
|
|
37
37
|
exports.useObservable = stores.useObservable;
|
|
38
|
+
exports.useObservablesProxy = stores.useObservablesProxy;
|
|
38
39
|
exports.usePropsAsStore = stores.usePropsAsStore;
|
|
39
40
|
exports.directiveAttributes = directive.directiveAttributes;
|
|
40
41
|
exports.ssrAttributes = directive.ssrAttributes;
|
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 } from "./stores-
|
|
17
|
+
import { u, a, b } from "./stores-B90XF8Sy.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-DNXkB1Wc.js";
|
|
20
20
|
export * from "@agnos-ui/core/types";
|
|
21
21
|
export * from "@agnos-ui/core/config";
|
|
22
22
|
import { WidgetsDefaultConfig, useWidgetContext, useWidgetWithConfig, widgetsConfigContext, widgetsConfigFactory } from "./config.js";
|
|
23
|
-
import { u as u3 } from "./widget-
|
|
23
|
+
import { u as u3 } from "./widget-DaA-pe23.js";
|
|
24
24
|
import { P } from "./portal-CX8X69NK.js";
|
|
25
25
|
import { Slot } from "./slot.js";
|
|
26
26
|
export * from "@agnos-ui/core/components/toast";
|
|
@@ -41,7 +41,8 @@ export {
|
|
|
41
41
|
u2 as useDirective,
|
|
42
42
|
a2 as useDirectives,
|
|
43
43
|
u as useObservable,
|
|
44
|
-
a as
|
|
44
|
+
a as useObservablesProxy,
|
|
45
|
+
b as usePropsAsStore,
|
|
45
46
|
u3 as useWidget,
|
|
46
47
|
useWidgetContext,
|
|
47
48
|
useWidgetWithConfig,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnos-ui/react-headless",
|
|
3
|
-
"description": "Headless
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "Headless component library for React.",
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"module": "./index.js",
|
|
@@ -49,17 +49,17 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@agnos-ui/core": "0.
|
|
52
|
+
"@agnos-ui/core": "0.5.0",
|
|
53
53
|
"classnames": "^2.5.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@amadeus-it-group/tansu": "^1.0.0",
|
|
57
|
-
"esm-env": "^1.
|
|
57
|
+
"esm-env": "^1.1.4",
|
|
58
58
|
"react": "^18.3.1",
|
|
59
59
|
"react-dom": "^18.3.1"
|
|
60
60
|
},
|
|
61
61
|
"sideEffects": false,
|
|
62
|
-
"homepage": "https://
|
|
62
|
+
"homepage": "https://www.agnosui.dev/latest/",
|
|
63
63
|
"bugs": "https://github.com/AmadeusITGroup/AgnosUI/issues",
|
|
64
64
|
"license": "MIT",
|
|
65
65
|
"repository": {
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"accordion",
|
|
74
74
|
"AgnosUI",
|
|
75
75
|
"alert",
|
|
76
|
+
"collapse",
|
|
76
77
|
"components",
|
|
77
78
|
"modal",
|
|
78
79
|
"pagination",
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
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;
|
package/types.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
export * from '@agnos-ui/core/types';
|
|
2
2
|
import type { SlotContent as CoreSlotContent } from '@agnos-ui/core/types';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the content that can be rendered within a slot.
|
|
5
|
+
*
|
|
6
|
+
* @template Props - The type of the props that can be passed to the slot content.
|
|
7
|
+
*
|
|
8
|
+
* This type can be one of the following:
|
|
9
|
+
* - A nullish value, i.e. `null` or `undefined`
|
|
10
|
+
* - A static `string`
|
|
11
|
+
* - A function that takes `props` of type `Props` and returns a `React.ReactNode`.
|
|
12
|
+
* - A `React.ComponentType<Props>`, which is a React component that accepts `Props`.
|
|
13
|
+
* - A `React.ReactNode`, which is any renderable React node.
|
|
14
|
+
*/
|
|
3
15
|
export type SlotContent<Props extends object = object> = CoreSlotContent<Props> | ((props: Props) => React.ReactNode) | React.ComponentType<Props> | React.ReactNode;
|
package/utils/stores.d.ts
CHANGED
|
@@ -3,13 +3,26 @@ export * from '@agnos-ui/core/utils/stores';
|
|
|
3
3
|
/**
|
|
4
4
|
* Observe a readable store inside of a react component.
|
|
5
5
|
*
|
|
6
|
+
* @template T - The type of the value emitted by the ReadableSignal.
|
|
6
7
|
* @param store$ - the readable store
|
|
7
8
|
* @returns the observed value of the store
|
|
8
9
|
*/
|
|
9
10
|
export declare function useObservable<T>(store$: ReadableSignal<T>): T;
|
|
11
|
+
/**
|
|
12
|
+
* Hook to create a proxy object that subscribes to observable stores and triggers re-renders on updates.
|
|
13
|
+
*
|
|
14
|
+
* @template State - The shape of the state object.
|
|
15
|
+
* @param stores - An object where keys are suffixed with `$` and values are readable signals.
|
|
16
|
+
* @returns - A proxy object that reflects the current state of the observables.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export declare function useObservablesProxy<State>(stores: {
|
|
20
|
+
[K in keyof State & string as `${K}$`]: ReadableSignal<State[K]>;
|
|
21
|
+
}): State;
|
|
10
22
|
/**
|
|
11
23
|
* Turn react props into readable stores.
|
|
12
24
|
*
|
|
25
|
+
* @template T - The type of the props object.
|
|
13
26
|
* @param props - the props
|
|
14
27
|
* @returns the readable stores
|
|
15
28
|
*/
|
package/utils/widget.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { PropsConfig, Widget, WidgetFactory, WidgetProps,
|
|
1
|
+
import type { PropsConfig, Widget, WidgetFactory, WidgetProps, WidgetSlotContext } from '@agnos-ui/core/types';
|
|
2
2
|
/**
|
|
3
3
|
* The useWidget function.
|
|
4
4
|
*
|
|
5
5
|
* Allows to create and attach an agnos-ui/core widget to the current react component.
|
|
6
|
-
*
|
|
6
|
+
* @template W - The type of the widget.
|
|
7
7
|
* @param createWidget - the widget factory
|
|
8
8
|
* @param props - the props
|
|
9
9
|
* @param propsConfig - the props config
|
|
10
10
|
* @returns the state and api to track and interact with the widget
|
|
11
11
|
*/
|
|
12
|
-
export declare function useWidget<W extends Widget>(createWidget: WidgetFactory<W>, props?: Partial<WidgetProps<W>>, propsConfig?: PropsConfig<WidgetProps<W>>):
|
|
12
|
+
export declare function useWidget<W extends Widget>(createWidget: WidgetFactory<W>, props?: Partial<WidgetProps<W>>, propsConfig?: PropsConfig<WidgetProps<W>>): WidgetSlotContext<W>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { findChangedProperties } from "@agnos-ui/core/utils/stores";
|
|
2
2
|
import { useMemo, useRef, useEffect } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { a as useObservablesProxy } from "./stores-B90XF8Sy.js";
|
|
4
4
|
function useWidget(createWidget, props = {}, propsConfig) {
|
|
5
|
-
const
|
|
5
|
+
const coreWidget = useMemo(() => createWidget({ ...propsConfig, props: { ...propsConfig == null ? void 0 : propsConfig.props, ...props } }), []);
|
|
6
6
|
const previousProps = useRef(props);
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
const changedProps = findChangedProperties(previousProps.current, props);
|
|
9
9
|
previousProps.current = props;
|
|
10
10
|
if (changedProps) {
|
|
11
|
-
|
|
11
|
+
coreWidget.patch(changedProps);
|
|
12
12
|
}
|
|
13
13
|
}, [props]);
|
|
14
|
-
const state =
|
|
15
|
-
return
|
|
14
|
+
const state = useObservablesProxy(coreWidget.stores);
|
|
15
|
+
return { state, api: coreWidget.api, directives: coreWidget.directives };
|
|
16
16
|
}
|
|
17
17
|
export {
|
|
18
18
|
useWidget as u
|
|
@@ -1,18 +1,18 @@
|
|
|
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-skeXwTXt.cjs");
|
|
5
5
|
function useWidget(createWidget, props = {}, propsConfig) {
|
|
6
|
-
const
|
|
6
|
+
const coreWidget = react.useMemo(() => createWidget({ ...propsConfig, props: { ...propsConfig == null ? void 0 : propsConfig.props, ...props } }), []);
|
|
7
7
|
const previousProps = react.useRef(props);
|
|
8
8
|
react.useEffect(() => {
|
|
9
9
|
const changedProps = stores.findChangedProperties(previousProps.current, props);
|
|
10
10
|
previousProps.current = props;
|
|
11
11
|
if (changedProps) {
|
|
12
|
-
|
|
12
|
+
coreWidget.patch(changedProps);
|
|
13
13
|
}
|
|
14
14
|
}, [props]);
|
|
15
|
-
const state = stores$1.
|
|
16
|
-
return
|
|
15
|
+
const state = stores$1.useObservablesProxy(coreWidget.stores);
|
|
16
|
+
return { state, api: coreWidget.api, directives: coreWidget.directives };
|
|
17
17
|
}
|
|
18
18
|
exports.useWidget = useWidget;
|
package/stores-B8YEDwZq.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { findChangedProperties } from "@agnos-ui/core/utils/stores";
|
|
2
|
-
import { writable, asReadable } from "@amadeus-it-group/tansu";
|
|
3
|
-
import { useState, useEffect, useRef, useMemo } 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
|
-
const propsEqual = (a, b) => !findChangedProperties(a, b);
|
|
14
|
-
const usePropsAsStore = (props) => {
|
|
15
|
-
const storeRef = useRef();
|
|
16
|
-
if (!storeRef.current) {
|
|
17
|
-
storeRef.current = writable({ ...props }, { equal: propsEqual });
|
|
18
|
-
}
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
storeRef.current.set({ ...props });
|
|
21
|
-
}, [props]);
|
|
22
|
-
return useMemo(() => asReadable(storeRef.current), [storeRef.current]);
|
|
23
|
-
};
|
|
24
|
-
export {
|
|
25
|
-
usePropsAsStore as a,
|
|
26
|
-
useObservable as u
|
|
27
|
-
};
|
package/stores-DLkDMqBY.cjs
DELETED
|
@@ -1,26 +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
|
-
const propsEqual = (a, b) => !stores.findChangedProperties(a, b);
|
|
15
|
-
const usePropsAsStore = (props) => {
|
|
16
|
-
const storeRef = react.useRef();
|
|
17
|
-
if (!storeRef.current) {
|
|
18
|
-
storeRef.current = tansu.writable({ ...props }, { equal: propsEqual });
|
|
19
|
-
}
|
|
20
|
-
react.useEffect(() => {
|
|
21
|
-
storeRef.current.set({ ...props });
|
|
22
|
-
}, [props]);
|
|
23
|
-
return react.useMemo(() => tansu.asReadable(storeRef.current), [storeRef.current]);
|
|
24
|
-
};
|
|
25
|
-
exports.useObservable = useObservable;
|
|
26
|
-
exports.usePropsAsStore = usePropsAsStore;
|