@agnos-ui/react-headless 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/components/accordion/accordion.d.ts +0 -10
- package/components/accordion/index.cjs +10 -0
- package/components/accordion/index.js +1 -1
- package/components/alert/alert.d.ts +0 -6
- package/components/alert/index.cjs +10 -0
- package/components/alert/index.js +1 -1
- package/components/modal/index.cjs +10 -0
- package/components/modal/index.js +1 -1
- package/components/modal/modal.d.ts +0 -6
- package/components/pagination/index.cjs +10 -0
- package/components/pagination/index.js +1 -1
- package/components/pagination/pagination.d.ts +0 -7
- package/components/progressbar/index.cjs +10 -0
- package/components/progressbar/index.js +1 -1
- package/components/progressbar/progressbar.d.ts +0 -6
- package/components/rating/index.cjs +10 -0
- package/components/rating/index.js +1 -1
- package/components/rating/rating.d.ts +0 -5
- package/components/select/index.cjs +10 -0
- package/components/select/index.js +1 -1
- package/components/select/select.d.ts +0 -7
- package/components/slider/index.cjs +10 -0
- package/components/slider/index.js +1 -1
- package/components/toast/index.cjs +10 -0
- package/components/toast/index.d.ts +1 -0
- package/components/toast/index.js +1 -0
- package/components/toast/toast.d.ts +1 -0
- package/config.cjs +54 -0
- package/config.d.ts +2 -2
- package/config.js +45 -81
- package/directive-4SKmV5bk.cjs +47 -0
- package/directive-Kqp31pwt.js +48 -0
- package/generated/index.d.ts +3 -1
- package/generated/services/extendWidget.cjs +10 -0
- package/generated/services/extendWidget.js +1 -1
- package/generated/services/floatingUI.cjs +10 -0
- package/generated/services/floatingUI.js +1 -1
- package/generated/services/focustrack.cjs +10 -0
- package/generated/services/focustrack.js +1 -1
- package/generated/services/hash.cjs +10 -0
- package/generated/services/hash.d.ts +1 -0
- package/generated/services/hash.js +1 -0
- package/generated/services/intersection.cjs +10 -0
- package/generated/services/intersection.js +1 -1
- package/generated/services/matchMedia.cjs +10 -0
- package/generated/services/matchMedia.d.ts +1 -0
- package/generated/services/matchMedia.js +1 -0
- package/generated/services/navManager.cjs +10 -0
- package/generated/services/navManager.js +1 -1
- package/generated/services/portal.cjs +10 -0
- package/generated/services/portal.js +1 -1
- package/generated/services/resizeObserver.cjs +10 -0
- package/generated/services/resizeObserver.d.ts +1 -0
- package/generated/services/resizeObserver.js +1 -0
- package/generated/services/siblingsInert.cjs +10 -0
- package/generated/services/siblingsInert.js +1 -1
- package/generated/services/transitions/baseTransitions.cjs +10 -0
- package/generated/services/transitions/baseTransitions.js +1 -1
- package/generated/services/transitions/collapse.cjs +10 -0
- package/generated/services/transitions/collapse.js +1 -1
- package/generated/services/transitions/cssTransitions.cjs +10 -0
- package/generated/services/transitions/cssTransitions.js +1 -1
- package/generated/services/transitions/simpleClassTransition.cjs +10 -0
- package/generated/services/transitions/simpleClassTransition.js +1 -1
- package/generated/utils/directive.cjs +15 -0
- package/generated/utils/directive.js +8 -1
- package/generated/utils/portal.cjs +4 -0
- package/generated/utils/portal.js +4 -1
- package/generated/utils/stores.cjs +13 -0
- package/generated/utils/stores.js +6 -1
- package/generated/utils/widget.cjs +4 -0
- package/generated/utils/widget.js +4 -1
- package/generated/utils/writables.cjs +10 -0
- package/generated/utils/writables.js +1 -1
- package/index.cjs +246 -0
- package/index.d.ts +1 -0
- package/index.js +50 -9
- package/package.json +23 -11
- package/portal-B0Q5KLrA.cjs +5 -0
- package/portal-CX8X69NK.js +6 -0
- package/slot.cjs +27 -0
- package/slot.js +21 -29
- package/stores-B8YEDwZq.js +27 -0
- package/stores-DLkDMqBY.cjs +26 -0
- package/types.cjs +10 -0
- package/types.js +1 -1
- package/utils/directive.d.ts +42 -5
- package/utils/stores.d.ts +1 -1
- package/widget-CqgI0B-w.cjs +18 -0
- package/widget-DAs9_HQ1.js +19 -0
- package/components/accordion/accordion.js +0 -3
- package/components/alert/alert.js +0 -3
- package/components/modal/modal.js +0 -3
- package/components/pagination/pagination.js +0 -3
- package/components/progressbar/progressbar.js +0 -3
- package/components/rating/rating.js +0 -3
- package/components/select/select.js +0 -3
- package/components/slider/slider.js +0 -1
- package/generated/config.js +0 -1
- package/generated/index.js +0 -20
- package/generated/services/transitions/bootstrap.d.ts +0 -1
- package/generated/services/transitions/bootstrap.js +0 -1
- package/generated/slot.js +0 -1
- package/generated/types.js +0 -1
- package/utils/directive.js +0 -39
- package/utils/portal.js +0 -11
- package/utils/stores.js +0 -38
- package/utils/widget.js +0 -26
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const reactDom = require("react-dom");
|
|
4
|
+
const Portal = ({ children, container }) => container ? reactDom.createPortal(children, container) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
5
|
+
exports.Portal = Portal;
|
package/slot.cjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const slotWrapperCache = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
const slotWrapperFactory = (slotContent) => {
|
|
7
|
+
const SlotWrapper = (props) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: slotContent(props) });
|
|
8
|
+
return SlotWrapper;
|
|
9
|
+
};
|
|
10
|
+
const slotWrapper = (slotContent) => {
|
|
11
|
+
let res = slotWrapperCache.get(slotContent);
|
|
12
|
+
if (!res) {
|
|
13
|
+
res = slotWrapperFactory(slotContent);
|
|
14
|
+
slotWrapperCache.set(slotContent, res);
|
|
15
|
+
}
|
|
16
|
+
return res;
|
|
17
|
+
};
|
|
18
|
+
const isReactComponent = (item) => item.prototype instanceof react.Component;
|
|
19
|
+
const Slot = ({ slotContent, props }) => {
|
|
20
|
+
const isFunction = typeof slotContent === "function";
|
|
21
|
+
if (isFunction) {
|
|
22
|
+
const SlotComponent = isReactComponent(slotContent) ? slotContent : slotWrapper(slotContent);
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsx(SlotComponent, { ...props });
|
|
24
|
+
}
|
|
25
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: slotContent });
|
|
26
|
+
};
|
|
27
|
+
exports.Slot = Slot;
|
package/slot.js
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Component } from
|
|
3
|
-
const slotWrapperCache = new WeakMap();
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Component } from "react";
|
|
3
|
+
const slotWrapperCache = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
const slotWrapperFactory = (slotContent) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const SlotWrapper = (props) => /* @__PURE__ */ jsx(Fragment, { children: slotContent(props) });
|
|
6
|
+
return SlotWrapper;
|
|
7
7
|
};
|
|
8
8
|
const slotWrapper = (slotContent) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
let res = slotWrapperCache.get(slotContent);
|
|
10
|
+
if (!res) {
|
|
11
|
+
res = slotWrapperFactory(slotContent);
|
|
12
|
+
slotWrapperCache.set(slotContent, res);
|
|
13
|
+
}
|
|
14
|
+
return res;
|
|
15
15
|
};
|
|
16
|
-
/* eslint-disable-next-line @typescript-eslint/ban-types */
|
|
17
16
|
const isReactComponent = (item) => item.prototype instanceof Component;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export const Slot = ({ slotContent, props }) => {
|
|
29
|
-
const isFunction = typeof slotContent === 'function';
|
|
30
|
-
if (isFunction) {
|
|
31
|
-
const SlotComponent = isReactComponent(slotContent) ? slotContent : slotWrapper(slotContent);
|
|
32
|
-
return _jsx(SlotComponent, { ...props });
|
|
33
|
-
}
|
|
34
|
-
return _jsx(_Fragment, { children: slotContent });
|
|
17
|
+
const Slot = ({ slotContent, props }) => {
|
|
18
|
+
const isFunction = typeof slotContent === "function";
|
|
19
|
+
if (isFunction) {
|
|
20
|
+
const SlotComponent = isReactComponent(slotContent) ? slotContent : slotWrapper(slotContent);
|
|
21
|
+
return /* @__PURE__ */ jsx(SlotComponent, { ...props });
|
|
22
|
+
}
|
|
23
|
+
return /* @__PURE__ */ jsx(Fragment, { children: slotContent });
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
Slot
|
|
35
27
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
package/types.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const types = require("@agnos-ui/core/types");
|
|
4
|
+
Object.keys(types).forEach((k) => {
|
|
5
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
|
|
6
|
+
Object.defineProperty(exports, k, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: () => types[k]
|
|
9
|
+
});
|
|
10
|
+
});
|
package/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "@agnos-ui/core/types";
|
package/utils/directive.d.ts
CHANGED
|
@@ -1,7 +1,44 @@
|
|
|
1
|
-
import type { Directive } from '@agnos-ui/core/types';
|
|
1
|
+
import type { Directive, DirectivesAndOptParam } from '@agnos-ui/core/types';
|
|
2
2
|
import type { RefCallback } from 'react';
|
|
3
3
|
export * from '@agnos-ui/core/utils/directive';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Returns an object with the key/value attributes for JSX, derived from a list of directives.
|
|
6
|
+
*
|
|
7
|
+
* @param directives - List of directives to generate attributes from. Each parameter can be the directive or an array with the directive and its parameter
|
|
8
|
+
* @returns JSON object with key/value pairs to be applied on a JSX node.
|
|
9
|
+
*/
|
|
10
|
+
export declare function directiveAttributes<T extends any[]>(...directives: DirectivesAndOptParam<T>): Record<string, any>;
|
|
11
|
+
/**
|
|
12
|
+
* Same as {@link directiveAttributes}, but returns an empty object when run in a browser environement.
|
|
13
|
+
*
|
|
14
|
+
* @returns JSON object with name/value for the attributes
|
|
15
|
+
*/
|
|
16
|
+
export declare const ssrAttributes: typeof directiveAttributes;
|
|
17
|
+
/**
|
|
18
|
+
* The useDirective function.
|
|
19
|
+
*
|
|
20
|
+
* Allows to attach a provided directive to the current react component.
|
|
21
|
+
*
|
|
22
|
+
* @param directive - the directive
|
|
23
|
+
* @param args - the args to pass to the directive
|
|
24
|
+
* @returns the ref callback
|
|
25
|
+
*/
|
|
26
|
+
export declare const useDirective: {
|
|
27
|
+
(directive: Directive): {
|
|
28
|
+
ref: RefCallback<HTMLElement>;
|
|
29
|
+
};
|
|
30
|
+
<T>(directive: Directive<T>, args: T): {
|
|
31
|
+
ref: RefCallback<HTMLElement>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The useDirectives function.
|
|
36
|
+
*
|
|
37
|
+
* Allows to attach multiple directives to the current react component.
|
|
38
|
+
*
|
|
39
|
+
* @param directives - directives
|
|
40
|
+
* @returns the ref callback
|
|
41
|
+
*/
|
|
42
|
+
export declare const useDirectives: <T extends any[]>(...directives: DirectivesAndOptParam<T>) => {
|
|
43
|
+
ref: RefCallback<HTMLElement>;
|
|
44
|
+
};
|
package/utils/stores.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ export declare function useObservable<T>(store$: ReadableSignal<T>): T;
|
|
|
13
13
|
* @param props - the props
|
|
14
14
|
* @returns the readable stores
|
|
15
15
|
*/
|
|
16
|
-
export declare const usePropsAsStore: <T extends object>(props?: Partial<T>
|
|
16
|
+
export declare const usePropsAsStore: <T extends object>(props?: Partial<T>) => ReadableSignal<Partial<T>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const stores = require("@agnos-ui/core/utils/stores");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const stores$1 = require("./stores-DLkDMqBY.cjs");
|
|
5
|
+
function useWidget(createWidget, props = {}, propsConfig) {
|
|
6
|
+
const api = react.useMemo(() => createWidget({ ...propsConfig, props: { ...propsConfig == null ? void 0 : propsConfig.props, ...props } }), []);
|
|
7
|
+
const previousProps = react.useRef(props);
|
|
8
|
+
react.useEffect(() => {
|
|
9
|
+
const changedProps = stores.findChangedProperties(previousProps.current, props);
|
|
10
|
+
previousProps.current = props;
|
|
11
|
+
if (changedProps) {
|
|
12
|
+
api.patch(changedProps);
|
|
13
|
+
}
|
|
14
|
+
}, [props]);
|
|
15
|
+
const state = stores$1.useObservable(api.state$);
|
|
16
|
+
return [state, api];
|
|
17
|
+
}
|
|
18
|
+
exports.useWidget = useWidget;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { findChangedProperties } from "@agnos-ui/core/utils/stores";
|
|
2
|
+
import { useMemo, useRef, useEffect } from "react";
|
|
3
|
+
import { u as useObservable } from "./stores-B8YEDwZq.js";
|
|
4
|
+
function useWidget(createWidget, props = {}, propsConfig) {
|
|
5
|
+
const api = useMemo(() => createWidget({ ...propsConfig, props: { ...propsConfig == null ? void 0 : propsConfig.props, ...props } }), []);
|
|
6
|
+
const previousProps = useRef(props);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const changedProps = findChangedProperties(previousProps.current, props);
|
|
9
|
+
previousProps.current = props;
|
|
10
|
+
if (changedProps) {
|
|
11
|
+
api.patch(changedProps);
|
|
12
|
+
}
|
|
13
|
+
}, [props]);
|
|
14
|
+
const state = useObservable(api.state$);
|
|
15
|
+
return [state, api];
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
useWidget as u
|
|
19
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@agnos-ui/core/components/slider';
|
package/generated/config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './../config';
|
package/generated/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export * from './services/siblingsInert';
|
|
2
|
-
export * from './services/portal';
|
|
3
|
-
export * from './services/navManager';
|
|
4
|
-
export * from './services/intersection';
|
|
5
|
-
export * from './services/focustrack';
|
|
6
|
-
export * from './services/floatingUI';
|
|
7
|
-
export * from './services/extendWidget';
|
|
8
|
-
export * from './services/transitions/simpleClassTransition';
|
|
9
|
-
export * from './services/transitions/cssTransitions';
|
|
10
|
-
export * from './services/transitions/collapse';
|
|
11
|
-
export * from './services/transitions/bootstrap';
|
|
12
|
-
export * from './services/transitions/baseTransitions';
|
|
13
|
-
export * from './utils/writables';
|
|
14
|
-
export * from './utils/stores';
|
|
15
|
-
export * from './utils/directive';
|
|
16
|
-
export * from './types';
|
|
17
|
-
export * from './config';
|
|
18
|
-
export * from './utils/widget';
|
|
19
|
-
export * from './utils/portal';
|
|
20
|
-
export * from './slot';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@agnos-ui/core/services/transitions/bootstrap';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@agnos-ui/core/services/transitions/bootstrap';
|
package/generated/slot.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './../slot';
|
package/generated/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './../types';
|
package/utils/directive.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { mergeDirectives } from '@agnos-ui/core/utils/directive';
|
|
2
|
-
import { useCallback, useMemo, useRef } from 'react';
|
|
3
|
-
export * from '@agnos-ui/core/utils/directive';
|
|
4
|
-
/**
|
|
5
|
-
* The useDirective function.
|
|
6
|
-
*
|
|
7
|
-
* Allows to attach a provided directive to the current react component.
|
|
8
|
-
*
|
|
9
|
-
* @param directive - the directive
|
|
10
|
-
* @param args - the args to pass to the directive
|
|
11
|
-
* @returns the ref callback
|
|
12
|
-
*/
|
|
13
|
-
export function useDirective(directive, args) {
|
|
14
|
-
const instance = useRef();
|
|
15
|
-
const propsRef = useRef();
|
|
16
|
-
const ref = useCallback((element) => {
|
|
17
|
-
instance.current?.destroy?.();
|
|
18
|
-
instance.current = undefined;
|
|
19
|
-
if (element) {
|
|
20
|
-
instance.current = directive(element, propsRef.current);
|
|
21
|
-
}
|
|
22
|
-
}, [directive]);
|
|
23
|
-
propsRef.current = args;
|
|
24
|
-
instance.current?.update?.(args);
|
|
25
|
-
return ref;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* The useDirectives function.
|
|
29
|
-
*
|
|
30
|
-
* Allows to attach multiple directives to the current react component.
|
|
31
|
-
*
|
|
32
|
-
* @param directives - directives
|
|
33
|
-
* @param args - the args to pass to the directives
|
|
34
|
-
* @returns the ref callback
|
|
35
|
-
*/
|
|
36
|
-
export function useDirectives(directives, args) {
|
|
37
|
-
const mergedDirectives = useMemo(() => mergeDirectives(...directives), directives);
|
|
38
|
-
return useDirective(mergedDirectives, args);
|
|
39
|
-
}
|
package/utils/portal.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
|
-
/**
|
|
4
|
-
* A Portal component, allowing to attach content to an external container.
|
|
5
|
-
*
|
|
6
|
-
* @param param - the react component inputs
|
|
7
|
-
* @param param.children - the react component children
|
|
8
|
-
* @param param.container - the container to attach the portal to
|
|
9
|
-
* @returns the portal component
|
|
10
|
-
*/
|
|
11
|
-
export const Portal = ({ children, container }) => container ? createPortal(children, container) : _jsx(_Fragment, { children: children });
|
package/utils/stores.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { findChangedProperties } from '@agnos-ui/core/utils/stores';
|
|
2
|
-
import { asReadable, writable } from '@amadeus-it-group/tansu';
|
|
3
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
export * from '@agnos-ui/core/utils/stores';
|
|
5
|
-
/**
|
|
6
|
-
* Observe a readable store inside of a react component.
|
|
7
|
-
*
|
|
8
|
-
* @param store$ - the readable store
|
|
9
|
-
* @returns the observed value of the store
|
|
10
|
-
*/
|
|
11
|
-
export function useObservable(store$) {
|
|
12
|
-
const [value, setValue] = useState(() => store$());
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
return store$.subscribe((arg) => {
|
|
15
|
-
// We're passing an update function to setValue here instead of just doing setValue(arg) so that
|
|
16
|
-
// if arg is a function, it is properly used as the value instead of being called as an update function
|
|
17
|
-
setValue(() => arg);
|
|
18
|
-
});
|
|
19
|
-
}, [store$]);
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
const propsEqual = (a, b) => !findChangedProperties(a, b);
|
|
23
|
-
/**
|
|
24
|
-
* Turn react props into readable stores.
|
|
25
|
-
*
|
|
26
|
-
* @param props - the props
|
|
27
|
-
* @returns the readable stores
|
|
28
|
-
*/
|
|
29
|
-
export const usePropsAsStore = (props) => {
|
|
30
|
-
const storeRef = useRef();
|
|
31
|
-
if (!storeRef.current) {
|
|
32
|
-
storeRef.current = writable({ ...props }, { equal: propsEqual });
|
|
33
|
-
}
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
storeRef.current.set({ ...props });
|
|
36
|
-
}, [props]);
|
|
37
|
-
return useMemo(() => asReadable(storeRef.current), [storeRef.current]);
|
|
38
|
-
};
|
package/utils/widget.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { findChangedProperties } from '@agnos-ui/core/utils/stores';
|
|
2
|
-
import { useEffect, useMemo, useRef } from 'react';
|
|
3
|
-
import { useObservable } from './stores';
|
|
4
|
-
/**
|
|
5
|
-
* The useWidget function.
|
|
6
|
-
*
|
|
7
|
-
* Allows to create and attach an agnos-ui/core widget to the current react component.
|
|
8
|
-
*
|
|
9
|
-
* @param createWidget - the widget factory
|
|
10
|
-
* @param props - the props
|
|
11
|
-
* @param propsConfig - the props config
|
|
12
|
-
* @returns the state and api to track and interact with the widget
|
|
13
|
-
*/
|
|
14
|
-
export function useWidget(createWidget, props = {}, propsConfig) {
|
|
15
|
-
const api = useMemo(() => createWidget({ ...propsConfig, props: { ...propsConfig?.props, ...props } }), []);
|
|
16
|
-
const previousProps = useRef(props);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const changedProps = findChangedProperties(previousProps.current, props);
|
|
19
|
-
previousProps.current = props;
|
|
20
|
-
if (changedProps) {
|
|
21
|
-
api.patch(changedProps);
|
|
22
|
-
}
|
|
23
|
-
}, [props]);
|
|
24
|
-
const state = useObservable(api.state$);
|
|
25
|
-
return [state, api];
|
|
26
|
-
}
|