@agnos-ui/react-headless 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/components/accordion/accordion.d.ts +0 -10
  2. package/components/accordion/index.cjs +10 -0
  3. package/components/accordion/index.js +1 -1
  4. package/components/alert/alert.d.ts +0 -6
  5. package/components/alert/index.cjs +10 -0
  6. package/components/alert/index.js +1 -1
  7. package/components/modal/index.cjs +10 -0
  8. package/components/modal/index.js +1 -1
  9. package/components/modal/modal.d.ts +0 -6
  10. package/components/pagination/index.cjs +10 -0
  11. package/components/pagination/index.js +1 -1
  12. package/components/pagination/pagination.d.ts +0 -7
  13. package/components/progressbar/index.cjs +10 -0
  14. package/components/progressbar/index.js +1 -1
  15. package/components/progressbar/progressbar.d.ts +0 -6
  16. package/components/rating/index.cjs +10 -0
  17. package/components/rating/index.js +1 -1
  18. package/components/rating/rating.d.ts +0 -5
  19. package/components/select/index.cjs +10 -0
  20. package/components/select/index.js +1 -1
  21. package/components/select/select.d.ts +0 -7
  22. package/components/slider/index.cjs +10 -0
  23. package/components/slider/index.js +1 -1
  24. package/components/slider/slider.d.ts +0 -8
  25. package/components/toast/index.cjs +10 -0
  26. package/components/toast/index.js +1 -1
  27. package/components/toast/toast.d.ts +0 -6
  28. package/config.cjs +54 -0
  29. package/config.d.ts +2 -2
  30. package/config.js +45 -81
  31. package/directive-4SKmV5bk.cjs +47 -0
  32. package/directive-Kqp31pwt.js +48 -0
  33. package/generated/index.d.ts +4 -4
  34. package/generated/services/extendWidget.cjs +10 -0
  35. package/generated/services/extendWidget.js +1 -1
  36. package/generated/services/floatingUI.cjs +10 -0
  37. package/generated/services/floatingUI.js +1 -1
  38. package/generated/services/focustrack.cjs +10 -0
  39. package/generated/services/focustrack.js +1 -1
  40. package/generated/services/hash.cjs +10 -0
  41. package/generated/services/hash.js +1 -1
  42. package/generated/services/intersection.cjs +10 -0
  43. package/generated/services/intersection.js +1 -1
  44. package/generated/services/matchMedia.cjs +10 -0
  45. package/generated/services/matchMedia.d.ts +1 -0
  46. package/generated/services/matchMedia.js +1 -0
  47. package/generated/services/navManager.cjs +10 -0
  48. package/generated/services/navManager.js +1 -1
  49. package/generated/services/portal.cjs +10 -0
  50. package/generated/services/portal.js +1 -1
  51. package/generated/services/resizeObserver.cjs +10 -0
  52. package/generated/services/resizeObserver.js +1 -1
  53. package/generated/services/siblingsInert.cjs +10 -0
  54. package/generated/services/siblingsInert.js +1 -1
  55. package/generated/services/transitions/baseTransitions.cjs +10 -0
  56. package/generated/services/transitions/baseTransitions.js +1 -1
  57. package/generated/services/transitions/collapse.cjs +10 -0
  58. package/generated/services/transitions/collapse.js +1 -1
  59. package/generated/services/transitions/cssTransitions.cjs +10 -0
  60. package/generated/services/transitions/cssTransitions.js +1 -1
  61. package/generated/services/transitions/simpleClassTransition.cjs +10 -0
  62. package/generated/services/transitions/simpleClassTransition.js +1 -1
  63. package/generated/utils/directive.cjs +15 -0
  64. package/generated/utils/directive.js +8 -1
  65. package/generated/utils/portal.cjs +4 -0
  66. package/generated/utils/portal.js +4 -1
  67. package/generated/utils/stores.cjs +13 -0
  68. package/generated/utils/stores.js +6 -1
  69. package/generated/utils/widget.cjs +4 -0
  70. package/generated/utils/widget.js +4 -1
  71. package/generated/utils/writables.cjs +10 -0
  72. package/generated/utils/writables.js +1 -1
  73. package/index.cjs +246 -0
  74. package/index.js +50 -10
  75. package/package.json +22 -10
  76. package/portal-B0Q5KLrA.cjs +5 -0
  77. package/portal-CX8X69NK.js +6 -0
  78. package/slot.cjs +27 -0
  79. package/slot.js +21 -29
  80. package/stores-B8YEDwZq.js +27 -0
  81. package/stores-DLkDMqBY.cjs +26 -0
  82. package/types.cjs +10 -0
  83. package/types.js +1 -1
  84. package/utils/directive.d.ts +42 -5
  85. package/utils/stores.d.ts +1 -1
  86. package/widget-CqgI0B-w.cjs +18 -0
  87. package/widget-DAs9_HQ1.js +19 -0
  88. package/components/accordion/accordion.js +0 -3
  89. package/components/alert/alert.js +0 -3
  90. package/components/modal/modal.js +0 -3
  91. package/components/pagination/pagination.js +0 -3
  92. package/components/progressbar/progressbar.js +0 -3
  93. package/components/rating/rating.js +0 -3
  94. package/components/select/select.js +0 -3
  95. package/components/slider/slider.js +0 -3
  96. package/components/toast/toast.js +0 -3
  97. package/generated/config.js +0 -1
  98. package/generated/index.js +0 -22
  99. package/generated/services/transitions/bootstrap.d.ts +0 -1
  100. package/generated/services/transitions/bootstrap.js +0 -1
  101. package/generated/slot.js +0 -1
  102. package/generated/types.js +0 -1
  103. package/utils/directive.js +0 -39
  104. package/utils/portal.js +0 -11
  105. package/utils/stores.js +0 -38
  106. package/utils/widget.js +0 -26
package/package.json CHANGED
@@ -1,72 +1,84 @@
1
1
  {
2
2
  "name": "@agnos-ui/react-headless",
3
+ "description": "Headless widget library for React.",
4
+ "version": "0.3.1",
3
5
  "type": "module",
4
- "main": "./index.js",
6
+ "main": "./index.cjs",
5
7
  "module": "./index.js",
6
8
  "types": "./index.d.ts",
7
9
  "exports": {
8
10
  ".": {
9
11
  "types": "./index.d.ts",
12
+ "require": "./index.cjs",
10
13
  "default": "./index.js"
11
14
  },
12
15
  "./components/*": {
13
- "types": "./components/*/*.d.ts",
14
- "default": "./components/*/*.js"
16
+ "types": "./components/*/index.d.ts",
17
+ "require": "./components/*/index.cjs",
18
+ "default": "./components/*/index.js"
15
19
  },
16
20
  "./config": {
17
21
  "types": "./config.d.ts",
22
+ "require": "./config.cjs",
18
23
  "default": "./config.js"
19
24
  },
20
25
  "./slot": {
21
26
  "types": "./slot.d.ts",
27
+ "require": "./slot.cjs",
22
28
  "default": "./slot.js"
23
29
  },
24
30
  "./types": {
25
31
  "types": "./types.d.ts",
32
+ "require": "./types.cjs",
26
33
  "default": "./types.js"
27
34
  },
28
35
  "./services/*": {
29
36
  "types": "./generated/services/*.d.ts",
37
+ "require": "./generated/services/*.cjs",
30
38
  "default": "./generated/services/*.js"
31
39
  },
32
40
  "./services/transitions/*": {
33
41
  "types": "./generated/services/transitions/*.d.ts",
42
+ "require": "./generated/services/transitions/*.cjs",
34
43
  "default": "./generated/services/transitions/*.js"
35
44
  },
36
45
  "./utils/*": {
37
46
  "types": "./generated/utils/*.d.ts",
47
+ "require": "./generated/utils/*.cjs",
38
48
  "default": "./generated/utils/*.js"
39
49
  }
40
50
  },
41
51
  "dependencies": {
42
- "@agnos-ui/core": "0.2.0",
52
+ "@agnos-ui/core": "0.3.1",
43
53
  "classnames": "^2.5.1"
44
54
  },
45
55
  "peerDependencies": {
46
56
  "@amadeus-it-group/tansu": "*",
57
+ "esm-env": "*",
47
58
  "react": "*",
48
59
  "react-dom": "*"
49
60
  },
50
61
  "sideEffects": false,
51
- "version": "0.2.0",
52
62
  "homepage": "https://amadeusitgroup.github.io/AgnosUI/latest/",
53
63
  "bugs": "https://github.com/AmadeusITGroup/AgnosUI/issues",
54
64
  "license": "MIT",
55
65
  "repository": {
56
66
  "type": "git",
57
- "url": "https://github.com/AmadeusITGroup/AgnosUI.git",
67
+ "url": "git+https://github.com/AmadeusITGroup/AgnosUI.git",
58
68
  "directory": "react/headless"
59
69
  },
60
70
  "keywords": [
61
71
  "react",
62
- "headless",
63
- "components",
64
- "widgets",
72
+ "AgnosUI",
65
73
  "accordion",
66
74
  "alert",
75
+ "components",
67
76
  "modal",
68
77
  "pagination",
78
+ "progressbar",
69
79
  "rating",
70
- "slider"
80
+ "slider",
81
+ "toast",
82
+ "widgets"
71
83
  ]
72
84
  }
@@ -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;
@@ -0,0 +1,6 @@
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { createPortal } from "react-dom";
3
+ const Portal = ({ children, container }) => container ? createPortal(children, container) : /* @__PURE__ */ jsx(Fragment, { children });
4
+ export {
5
+ Portal as P
6
+ };
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 { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import { Component } from 'react';
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
- const SlotWrapper = (props) => _jsx(_Fragment, { children: slotContent(props) });
6
- return SlotWrapper;
5
+ const SlotWrapper = (props) => /* @__PURE__ */ jsx(Fragment, { children: slotContent(props) });
6
+ return SlotWrapper;
7
7
  };
8
8
  const slotWrapper = (slotContent) => {
9
- let res = slotWrapperCache.get(slotContent);
10
- if (!res) {
11
- res = slotWrapperFactory(slotContent);
12
- slotWrapperCache.set(slotContent, res);
13
- }
14
- return res;
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
- * The React Slot component, allowing to extensively customize widgets.
20
- *
21
- * The input slotContent can be a react component, a function or jsx.
22
- *
23
- * @param parameter - the react component parameter
24
- * @param parameter.slotContent - the slot content
25
- * @param parameter.props - the react component props
26
- * @returns the slot component
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 '@agnos-ui/core/types';
1
+ export * from "@agnos-ui/core/types";
@@ -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
- export declare function useDirective(directive: Directive<void>): RefCallback<HTMLElement>;
5
- export declare function useDirective<T>(directive: Directive<T>, args: T): RefCallback<HTMLElement>;
6
- export declare function useDirectives(directives: Directive<void>[]): RefCallback<HTMLElement>;
7
- export declare function useDirectives<T>(directives: Directive<T>[], args: T): RefCallback<HTMLElement>;
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> | undefined) => ReadableSignal<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,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/accordion';
2
- import { createAccordion as coreCreateAccordion } from '@agnos-ui/core/components/accordion';
3
- export const createAccordion = coreCreateAccordion;
@@ -1,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/alert';
2
- import { createAlert as coreCreateAlert } from '@agnos-ui/core/components/alert';
3
- export const createAlert = coreCreateAlert;
@@ -1,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/modal';
2
- import { createModal as coreCreateModal } from '@agnos-ui/core/components/modal';
3
- export const createModal = coreCreateModal;
@@ -1,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/pagination';
2
- import { createPagination as coreCreatePagination } from '@agnos-ui/core/components/pagination';
3
- export const createPagination = coreCreatePagination;
@@ -1,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/progressbar';
2
- import { createProgressbar as coreCreateProgressbar } from '@agnos-ui/core/components/progressbar';
3
- export const createProgressbar = coreCreateProgressbar;
@@ -1,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/rating';
2
- import { createRating as coreCreateRating } from '@agnos-ui/core/components/rating';
3
- export const createRating = coreCreateRating;
@@ -1,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/select';
2
- import { createSelect as coreCreateSelect } from '@agnos-ui/core/components/select';
3
- export const createSelect = coreCreateSelect;
@@ -1,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/slider';
2
- import { createSlider as coreCreateSlider } from '@agnos-ui/core/components/slider';
3
- export const createSlider = coreCreateSlider;
@@ -1,3 +0,0 @@
1
- export * from '@agnos-ui/core/components/toast';
2
- import { createToast as coreCreateToast } from '@agnos-ui/core/components/toast';
3
- export const createToast = coreCreateToast;
@@ -1 +0,0 @@
1
- export * from './../config';
@@ -1,22 +0,0 @@
1
- export * from './services/siblingsInert';
2
- export * from './services/resizeObserver';
3
- export * from './services/portal';
4
- export * from './services/navManager';
5
- export * from './services/intersection';
6
- export * from './services/hash';
7
- export * from './services/focustrack';
8
- export * from './services/floatingUI';
9
- export * from './services/extendWidget';
10
- export * from './services/transitions/simpleClassTransition';
11
- export * from './services/transitions/cssTransitions';
12
- export * from './services/transitions/collapse';
13
- export * from './services/transitions/bootstrap';
14
- export * from './services/transitions/baseTransitions';
15
- export * from './utils/writables';
16
- export * from './utils/stores';
17
- export * from './utils/directive';
18
- export * from './types';
19
- export * from './config';
20
- export * from './utils/widget';
21
- export * from './utils/portal';
22
- 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';
@@ -1 +0,0 @@
1
- export * from './../types';
@@ -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
- }