@agnos-ui/react-headless 0.0.1-alpha.1 → 0.0.1-alpha.11
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 +11 -0
- package/components/accordion/accordion.js +3 -0
- package/components/accordion/index.d.ts +1 -0
- package/components/accordion/index.js +1 -0
- package/components/alert/alert.d.ts +7 -0
- package/components/alert/alert.js +3 -0
- package/components/alert/index.d.ts +1 -0
- package/components/alert/index.js +1 -0
- package/components/modal/index.d.ts +1 -0
- package/components/modal/index.js +1 -0
- package/components/modal/modal.d.ts +7 -0
- package/components/modal/modal.js +3 -0
- package/components/pagination/index.d.ts +1 -0
- package/components/pagination/index.js +1 -0
- package/components/pagination/pagination.d.ts +8 -0
- package/components/pagination/pagination.js +3 -0
- package/components/progressbar/index.d.ts +1 -0
- package/components/progressbar/index.js +1 -0
- package/components/progressbar/progressbar.d.ts +7 -0
- package/components/progressbar/progressbar.js +3 -0
- package/components/rating/index.d.ts +1 -0
- package/components/rating/index.js +1 -0
- package/components/rating/rating.d.ts +6 -0
- package/components/rating/rating.js +3 -0
- package/components/select/index.d.ts +1 -0
- package/components/select/index.js +1 -0
- package/components/select/select.d.ts +8 -0
- package/components/select/select.js +3 -0
- package/components/slider/index.d.ts +1 -0
- package/components/slider/index.js +1 -0
- package/components/slider/slider.d.ts +1 -0
- package/components/slider/slider.js +1 -0
- package/config.d.ts +32 -0
- package/config.js +84 -0
- package/generated/config.d.ts +1 -0
- package/generated/config.js +1 -0
- package/generated/index.d.ts +20 -0
- package/generated/index.js +20 -0
- package/generated/services/extendWidget.d.ts +1 -0
- package/generated/services/extendWidget.js +1 -0
- package/generated/services/floatingUI.d.ts +1 -0
- package/generated/services/floatingUI.js +1 -0
- package/generated/services/focustrack.d.ts +1 -0
- package/generated/services/focustrack.js +1 -0
- package/generated/services/intersection.d.ts +1 -0
- package/generated/services/intersection.js +1 -0
- package/generated/services/navManager.d.ts +1 -0
- package/generated/services/navManager.js +1 -0
- package/generated/services/portal.d.ts +1 -0
- package/generated/services/portal.js +1 -0
- package/generated/services/siblingsInert.d.ts +1 -0
- package/generated/services/siblingsInert.js +1 -0
- package/generated/services/transitions/baseTransitions.d.ts +1 -0
- package/generated/services/transitions/baseTransitions.js +1 -0
- package/generated/services/transitions/bootstrap.d.ts +1 -0
- package/generated/services/transitions/bootstrap.js +1 -0
- package/generated/services/transitions/collapse.d.ts +1 -0
- package/generated/services/transitions/collapse.js +1 -0
- package/generated/services/transitions/cssTransitions.d.ts +1 -0
- package/generated/services/transitions/cssTransitions.js +1 -0
- package/generated/services/transitions/simpleClassTransition.d.ts +1 -0
- package/generated/services/transitions/simpleClassTransition.js +1 -0
- package/generated/slot.d.ts +1 -0
- package/generated/slot.js +1 -0
- package/generated/types.d.ts +1 -0
- package/generated/types.js +1 -0
- package/generated/utils/directive.d.ts +1 -0
- package/generated/utils/directive.js +1 -0
- package/generated/utils/portal.d.ts +1 -0
- package/generated/utils/portal.js +1 -0
- package/generated/utils/stores.d.ts +1 -0
- package/generated/utils/stores.js +1 -0
- package/generated/utils/widget.d.ts +1 -0
- package/generated/utils/widget.js +1 -0
- package/generated/utils/writables.d.ts +1 -0
- package/generated/utils/writables.js +1 -0
- package/index.d.ts +9 -34
- package/index.js +9 -5
- package/package.json +34 -5
- package/slot.d.ts +15 -0
- package/{Slot.js → slot.js} +10 -0
- package/types.d.ts +12 -0
- package/types.js +1 -0
- package/utils/directive.d.ts +7 -0
- package/utils/directive.js +39 -0
- package/utils/portal.d.ts +12 -0
- package/utils/portal.js +11 -0
- package/utils/stores.d.ts +16 -0
- package/utils/stores.js +38 -0
- package/utils/widget.d.ts +12 -0
- package/utils/widget.js +26 -0
- package/Portal.d.ts +0 -4
- package/Portal.js +0 -3
- package/Slot.d.ts +0 -5
- package/WidgetsDefaultConfig.d.ts +0 -48
- package/WidgetsDefaultConfig.js +0 -53
- package/utils.d.ts +0 -22
- package/utils.js +0 -67
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/accordion';
|
|
2
|
+
import type { AdaptSlotContentProps, AdaptWidgetSlots, WidgetFactory, WidgetProps, WidgetState } from '../../types';
|
|
3
|
+
export type AccordionWidget = AdaptWidgetSlots<import('@agnos-ui/core/components/accordion').AccordionWidget>;
|
|
4
|
+
export type AccordionProps = WidgetProps<AccordionWidget>;
|
|
5
|
+
export type AccordionState = WidgetState<AccordionWidget>;
|
|
6
|
+
export type AccordionApi = AccordionWidget['api'];
|
|
7
|
+
export type AccordionItemWidget = AdaptWidgetSlots<import('@agnos-ui/core/components/accordion').AccordionItemWidget>;
|
|
8
|
+
export type AccordionItemProps = WidgetProps<AccordionItemWidget>;
|
|
9
|
+
export type AccordionItemState = WidgetState<AccordionItemWidget>;
|
|
10
|
+
export type AccordionItemContext = AdaptSlotContentProps<import('@agnos-ui/core/components/accordion').AccordionItemContext>;
|
|
11
|
+
export declare const createAccordion: WidgetFactory<AccordionWidget>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './accordion';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './accordion';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/alert';
|
|
2
|
+
import type { AdaptSlotContentProps, AdaptWidgetSlots, WidgetFactory, WidgetProps, WidgetState } from '../../types';
|
|
3
|
+
export type AlertWidget = AdaptWidgetSlots<import('@agnos-ui/core/components/alert').AlertWidget>;
|
|
4
|
+
export type AlertProps = WidgetProps<AlertWidget>;
|
|
5
|
+
export type AlertState = WidgetState<AlertWidget>;
|
|
6
|
+
export type AlertContext = AdaptSlotContentProps<import('@agnos-ui/core/components/alert').AlertContext>;
|
|
7
|
+
export declare const createAlert: WidgetFactory<AlertWidget>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './alert';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './alert';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './modal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './modal';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/modal';
|
|
2
|
+
import type { AdaptSlotContentProps, AdaptWidgetSlots, PropsConfig, WidgetProps, WidgetState } from '../../types';
|
|
3
|
+
export type ModalWidget<Data> = AdaptWidgetSlots<import('@agnos-ui/core/components/modal').ModalWidget<Data>>;
|
|
4
|
+
export type ModalProps<Data> = WidgetProps<ModalWidget<Data>>;
|
|
5
|
+
export type ModalState<Data> = WidgetState<ModalWidget<Data>>;
|
|
6
|
+
export type ModalContext<Data> = AdaptSlotContentProps<import('@agnos-ui/core/components/modal').ModalContext<Data>>;
|
|
7
|
+
export declare const createModal: <Data>(propsConfig?: PropsConfig<ModalProps<Data>>) => ModalWidget<Data>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/pagination';
|
|
2
|
+
import type { AdaptSlotContentProps, AdaptWidgetSlots, WidgetFactory, WidgetProps, WidgetState } from '../../types';
|
|
3
|
+
export type PaginationWidget = AdaptWidgetSlots<import('@agnos-ui/core/components/pagination').PaginationWidget>;
|
|
4
|
+
export type PaginationProps = WidgetProps<PaginationWidget>;
|
|
5
|
+
export type PaginationState = WidgetState<PaginationWidget>;
|
|
6
|
+
export type PaginationContext = AdaptSlotContentProps<import('@agnos-ui/core/components/pagination').PaginationContext>;
|
|
7
|
+
export type PaginationNumberContext = AdaptSlotContentProps<import('@agnos-ui/core/components/pagination').PaginationNumberContext>;
|
|
8
|
+
export declare const createPagination: WidgetFactory<PaginationWidget>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './progressbar';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './progressbar';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/progressbar';
|
|
2
|
+
import type { AdaptSlotContentProps, AdaptWidgetSlots, WidgetFactory, WidgetProps, WidgetState } from '../../types';
|
|
3
|
+
export type ProgressbarWidget = AdaptWidgetSlots<import('@agnos-ui/core/components/progressbar').ProgressbarWidget>;
|
|
4
|
+
export type ProgressbarProps = WidgetProps<ProgressbarWidget>;
|
|
5
|
+
export type ProgressbarState = WidgetState<ProgressbarWidget>;
|
|
6
|
+
export type ProgressbarContext = AdaptSlotContentProps<import('@agnos-ui/core/components/progressbar').ProgressbarContext>;
|
|
7
|
+
export declare const createProgressbar: WidgetFactory<ProgressbarWidget>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rating';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rating';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/rating';
|
|
2
|
+
import type { AdaptWidgetSlots, WidgetFactory, WidgetProps, WidgetState } from '../../types';
|
|
3
|
+
export type RatingWidget = AdaptWidgetSlots<import('@agnos-ui/core/components/rating').RatingWidget>;
|
|
4
|
+
export type RatingProps = WidgetProps<RatingWidget>;
|
|
5
|
+
export type RatingState = WidgetState<RatingWidget>;
|
|
6
|
+
export declare const createRating: WidgetFactory<RatingWidget>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './select';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './select';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/select';
|
|
2
|
+
import type { AdaptSlotContentProps, AdaptWidgetSlots, PropsConfig, WidgetProps, WidgetState } from '../../types';
|
|
3
|
+
export type SelectWidget<Item> = AdaptWidgetSlots<import('@agnos-ui/core/components/select').SelectWidget<Item>>;
|
|
4
|
+
export type SelectProps<Item> = WidgetProps<SelectWidget<Item>>;
|
|
5
|
+
export type SelectState<Item> = WidgetState<SelectWidget<Item>>;
|
|
6
|
+
export type SelectContext<Item> = AdaptSlotContentProps<import('@agnos-ui/core/components/select').SelectContext<Item>>;
|
|
7
|
+
export type SelectItemContext<Item> = AdaptSlotContentProps<import('@agnos-ui/core/components/select').SelectItemContext<Item>>;
|
|
8
|
+
export declare const createSelect: <Item>(propsConfig?: PropsConfig<SelectProps<Item>>) => SelectWidget<Item>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/slider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/components/slider';
|
package/config.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Widget, WidgetFactory, WidgetProps, WidgetState } from '@agnos-ui/core/types';
|
|
2
|
+
import { type WidgetsConfigStore, type WidgetsConfig as CoreWidgetsConfig, type Partial2Levels } from '@agnos-ui/core/config';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import type { AdaptPropsSlots } from './types';
|
|
5
|
+
export * from '@agnos-ui/core/config';
|
|
6
|
+
export type WidgetsConfig = {
|
|
7
|
+
[WidgetName in keyof CoreWidgetsConfig]: AdaptPropsSlots<CoreWidgetsConfig[WidgetName]>;
|
|
8
|
+
};
|
|
9
|
+
type DefaultConfigInput<Config> = Partial2Levels<Config> & {
|
|
10
|
+
adaptParentConfig?: (config: Partial2Levels<Config>) => Partial2Levels<Config>;
|
|
11
|
+
children?: ReactNode | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A factory to create the use functions and react component to allow widgets to be context-aware.
|
|
15
|
+
*
|
|
16
|
+
* It can be used when extending the core and creating new widgets.
|
|
17
|
+
*
|
|
18
|
+
* @param widgetsConfigContext - the widgets config context
|
|
19
|
+
* @returns the use functions and react component
|
|
20
|
+
*/
|
|
21
|
+
export declare const widgetsConfigFactory: <Config extends {
|
|
22
|
+
[widgetName: string]: object;
|
|
23
|
+
} = WidgetsConfig>(widgetsConfigContext?: import("react").Context<WidgetsConfigStore<Config> | undefined>) => {
|
|
24
|
+
/**
|
|
25
|
+
* React context which can be used to provide or consume the widgets default configuration store.
|
|
26
|
+
*/
|
|
27
|
+
widgetsConfigContext: import("react").Context<WidgetsConfigStore<Config> | undefined>;
|
|
28
|
+
useWidgetContext: <Props extends object>(widgetName: keyof Config | null, defaultConfig?: Partial<Props> | undefined) => import("@amadeus-it-group/tansu").ReadableSignal<Partial<Props>>;
|
|
29
|
+
useWidgetWithConfig: <W extends Widget<object, object, object, object, object>>(factory: WidgetFactory<W>, props: Partial<WidgetProps<W>> | undefined, widgetName: keyof Config | null, defaultProps?: Partial<WidgetProps<W>> | undefined) => [WidgetState<W>, W];
|
|
30
|
+
WidgetsDefaultConfig: ({ children, adaptParentConfig, ...props }: DefaultConfigInput<Config>) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
};
|
|
32
|
+
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 CoreWidgetsConfig | null, defaultConfig?: Partial<Props> | undefined) => import("@amadeus-it-group/tansu").ReadableSignal<Partial<Props>>, useWidgetWithConfig: <W extends Widget<object, object, object, object, object>>(factory: WidgetFactory<W>, props: Partial<WidgetProps<W>> | undefined, widgetName: keyof CoreWidgetsConfig | null, defaultProps?: Partial<WidgetProps<W>> | undefined) => [WidgetState<W>, W];
|
package/config.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createWidgetsConfig } from '@agnos-ui/core/config';
|
|
3
|
+
import { computed } from '@amadeus-it-group/tansu';
|
|
4
|
+
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
5
|
+
import { useWidget } from './utils/widget';
|
|
6
|
+
import { usePropsAsStore } from './utils/stores';
|
|
7
|
+
export * from '@agnos-ui/core/config';
|
|
8
|
+
/**
|
|
9
|
+
* A factory to create the use functions and react component to allow widgets to be context-aware.
|
|
10
|
+
*
|
|
11
|
+
* It can be used when extending the core and creating new widgets.
|
|
12
|
+
*
|
|
13
|
+
* @param widgetsConfigContext - the widgets config context
|
|
14
|
+
* @returns the use functions and react component
|
|
15
|
+
*/
|
|
16
|
+
export const widgetsConfigFactory = (widgetsConfigContext = createContext(undefined)) => {
|
|
17
|
+
const useWidgetContext = (widgetName, defaultConfig) => {
|
|
18
|
+
const widgetsConfig = useContext(widgetsConfigContext);
|
|
19
|
+
const defaultConfig$ = usePropsAsStore(defaultConfig);
|
|
20
|
+
return useMemo(() => computed(() => ({ ...defaultConfig$(), ...(widgetName ? widgetsConfig?.()[widgetName] : undefined) })), [widgetsConfig]);
|
|
21
|
+
};
|
|
22
|
+
const useWidgetWithConfig = (factory, props, widgetName, defaultProps) => useWidget(factory, props, { config: useWidgetContext(widgetName, defaultProps) });
|
|
23
|
+
/**
|
|
24
|
+
* React component that provides in the React context (for all AgnosUI descendant widgets) a new widgets default configuration
|
|
25
|
+
* store that inherits from any widgets default configuration store already defined at an upper level in the React context hierarchy.
|
|
26
|
+
* It contains its own set of widgets configuration properties that override the same properties form the parent configuration.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* The configuration is computed from the parent configuration in two steps:
|
|
30
|
+
* - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
|
|
31
|
+
* If adaptParentConfig is not specified, this step is skipped.
|
|
32
|
+
* - second step: the configuration from step 1 is merged (2-levels deep) with the properties of the component.
|
|
33
|
+
*
|
|
34
|
+
* @param componentInputs - the react component inputs
|
|
35
|
+
* @param componentInputs.children - the react component children
|
|
36
|
+
* @param componentInputs.adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
|
|
37
|
+
* defined at an upper level in the Svelte context hierarchy (or an empty object if there is none) and returns the widgets
|
|
38
|
+
* default configuration to be used.
|
|
39
|
+
* It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
|
|
40
|
+
* It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
|
|
41
|
+
*
|
|
42
|
+
* @returns the resulting widgets default configuration store, which contains 3 additional properties that are stores:
|
|
43
|
+
* parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties).
|
|
44
|
+
* The resulting store is writable, its set function is actually the set function of the own$ store.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* <WidgetsDefaultConfig
|
|
49
|
+
* adaptParentConfig={(parentConfig) => {
|
|
50
|
+
* parentConfig.rating = parentConfig.rating ?? {};
|
|
51
|
+
* parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
|
|
52
|
+
* return parentConfig;
|
|
53
|
+
* }}
|
|
54
|
+
* rating={{slotStar: MyCustomSlotStar}}
|
|
55
|
+
* />
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const WidgetsDefaultConfig = ({ children, adaptParentConfig, ...props }) => {
|
|
59
|
+
const config$ = useContext(widgetsConfigContext);
|
|
60
|
+
let storeRecreated = false;
|
|
61
|
+
const store$ = useMemo(() => {
|
|
62
|
+
const store = createWidgetsConfig(config$, adaptParentConfig);
|
|
63
|
+
store.set(props);
|
|
64
|
+
storeRecreated = true;
|
|
65
|
+
return store;
|
|
66
|
+
}, [config$, adaptParentConfig]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!storeRecreated) {
|
|
69
|
+
store$.set(props);
|
|
70
|
+
}
|
|
71
|
+
}, [props]);
|
|
72
|
+
return _jsx(widgetsConfigContext.Provider, { value: store$, children: children });
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
/**
|
|
76
|
+
* React context which can be used to provide or consume the widgets default configuration store.
|
|
77
|
+
*/
|
|
78
|
+
widgetsConfigContext,
|
|
79
|
+
useWidgetContext,
|
|
80
|
+
useWidgetWithConfig,
|
|
81
|
+
WidgetsDefaultConfig,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export const { widgetsConfigContext, WidgetsDefaultConfig, useWidgetContext, useWidgetWithConfig } = widgetsConfigFactory();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../config';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../config';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './services/transitions/simpleClassTransition';
|
|
2
|
+
export * from './services/transitions/cssTransitions';
|
|
3
|
+
export * from './services/transitions/collapse';
|
|
4
|
+
export * from './services/transitions/bootstrap';
|
|
5
|
+
export * from './services/transitions/baseTransitions';
|
|
6
|
+
export * from './utils/writables';
|
|
7
|
+
export * from './utils/stores';
|
|
8
|
+
export * from './utils/directive';
|
|
9
|
+
export * from './types';
|
|
10
|
+
export * from './config';
|
|
11
|
+
export * from './services/siblingsInert';
|
|
12
|
+
export * from './services/portal';
|
|
13
|
+
export * from './services/navManager';
|
|
14
|
+
export * from './services/intersection';
|
|
15
|
+
export * from './services/focustrack';
|
|
16
|
+
export * from './services/floatingUI';
|
|
17
|
+
export * from './services/extendWidget';
|
|
18
|
+
export * from './utils/widget';
|
|
19
|
+
export * from './utils/portal';
|
|
20
|
+
export * from './slot';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './services/transitions/simpleClassTransition';
|
|
2
|
+
export * from './services/transitions/cssTransitions';
|
|
3
|
+
export * from './services/transitions/collapse';
|
|
4
|
+
export * from './services/transitions/bootstrap';
|
|
5
|
+
export * from './services/transitions/baseTransitions';
|
|
6
|
+
export * from './utils/writables';
|
|
7
|
+
export * from './utils/stores';
|
|
8
|
+
export * from './utils/directive';
|
|
9
|
+
export * from './types';
|
|
10
|
+
export * from './config';
|
|
11
|
+
export * from './services/siblingsInert';
|
|
12
|
+
export * from './services/portal';
|
|
13
|
+
export * from './services/navManager';
|
|
14
|
+
export * from './services/intersection';
|
|
15
|
+
export * from './services/focustrack';
|
|
16
|
+
export * from './services/floatingUI';
|
|
17
|
+
export * from './services/extendWidget';
|
|
18
|
+
export * from './utils/widget';
|
|
19
|
+
export * from './utils/portal';
|
|
20
|
+
export * from './slot';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/extendWidget';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/extendWidget';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/floatingUI';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/floatingUI';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/focustrack';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/focustrack';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/intersection';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/intersection';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/navManager';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/navManager';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/portal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/portal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/siblingsInert';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/siblingsInert';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/baseTransitions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/baseTransitions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/bootstrap';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/bootstrap';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/collapse';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/collapse';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/cssTransitions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/cssTransitions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/simpleClassTransition';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/services/transitions/simpleClassTransition';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../slot';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../slot';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../../utils/directive';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../../utils/directive';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../../utils/portal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../../utils/portal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../../utils/stores';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../../utils/stores';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../../utils/widget';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './../../utils/widget';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/utils/writables';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/utils/writables';
|
package/index.d.ts
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export type AccordionProps = WidgetProps<AccordionWidget>;
|
|
11
|
-
export type AccordionState = WidgetState<AccordionWidget>;
|
|
12
|
-
export type AccordionItemWidget = AdaptWidgetSlots<import('@agnos-ui/core').AccordionItemWidget>;
|
|
13
|
-
export type AccordionItemProps = WidgetProps<AccordionItemWidget>;
|
|
14
|
-
export type AccordionItemState = WidgetState<AccordionItemWidget>;
|
|
15
|
-
export type AccordionItemContext = AdaptSlotContentProps<import('@agnos-ui/core').AccordionItemContext>;
|
|
16
|
-
export type AlertWidget = AdaptWidgetSlots<import('@agnos-ui/core').AlertWidget>;
|
|
17
|
-
export type AlertProps = WidgetProps<AlertWidget>;
|
|
18
|
-
export type AlertState = WidgetState<AlertWidget>;
|
|
19
|
-
export type AlertContext = AdaptSlotContentProps<import('@agnos-ui/core').AlertContext>;
|
|
20
|
-
export type ModalWidget = AdaptWidgetSlots<import('@agnos-ui/core').ModalWidget>;
|
|
21
|
-
export type ModalProps = WidgetProps<ModalWidget>;
|
|
22
|
-
export type ModalState = WidgetState<ModalWidget>;
|
|
23
|
-
export type ModalContext = AdaptSlotContentProps<import('@agnos-ui/core').ModalContext>;
|
|
24
|
-
export type PaginationWidget = AdaptWidgetSlots<import('@agnos-ui/core').PaginationWidget>;
|
|
25
|
-
export type PaginationProps = WidgetProps<PaginationWidget>;
|
|
26
|
-
export type PaginationState = WidgetState<PaginationWidget>;
|
|
27
|
-
export type PaginationContext = AdaptSlotContentProps<import('@agnos-ui/core').PaginationContext>;
|
|
28
|
-
export type PaginationNumberContext = AdaptSlotContentProps<import('@agnos-ui/core').PaginationNumberContext>;
|
|
29
|
-
export type RatingWidget = AdaptWidgetSlots<import('@agnos-ui/core').RatingWidget>;
|
|
30
|
-
export type RatingProps = WidgetProps<RatingWidget>;
|
|
31
|
-
export type RatingState = WidgetState<RatingWidget>;
|
|
32
|
-
export type SelectWidget<Item> = AdaptWidgetSlots<import('@agnos-ui/core').SelectWidget<Item>>;
|
|
33
|
-
export type SelectProps<Item> = WidgetProps<SelectWidget<Item>>;
|
|
34
|
-
export type SelectState<Item> = WidgetState<SelectWidget<Item>>;
|
|
1
|
+
export * from './components/accordion';
|
|
2
|
+
export * from './components/alert';
|
|
3
|
+
export * from './components/modal';
|
|
4
|
+
export * from './components/pagination';
|
|
5
|
+
export * from './components/progressbar';
|
|
6
|
+
export * from './components/rating';
|
|
7
|
+
export * from './components/select';
|
|
8
|
+
export * from './components/slider';
|
|
9
|
+
export * from './generated';
|
package/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './components/accordion';
|
|
2
|
+
export * from './components/alert';
|
|
3
|
+
export * from './components/modal';
|
|
4
|
+
export * from './components/pagination';
|
|
5
|
+
export * from './components/progressbar';
|
|
6
|
+
export * from './components/rating';
|
|
7
|
+
export * from './components/select';
|
|
8
|
+
export * from './components/slider';
|
|
9
|
+
export * from './generated';
|
package/package.json
CHANGED
|
@@ -8,19 +8,47 @@
|
|
|
8
8
|
".": {
|
|
9
9
|
"types": "./index.d.ts",
|
|
10
10
|
"default": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"./components/*": {
|
|
13
|
+
"types": "./components/*/*.d.ts",
|
|
14
|
+
"default": "./components/*/*.js"
|
|
15
|
+
},
|
|
16
|
+
"./config": {
|
|
17
|
+
"types": "./config.d.ts",
|
|
18
|
+
"default": "./config.js"
|
|
19
|
+
},
|
|
20
|
+
"./slot": {
|
|
21
|
+
"types": "./slot.d.ts",
|
|
22
|
+
"default": "./slot.js"
|
|
23
|
+
},
|
|
24
|
+
"./types": {
|
|
25
|
+
"types": "./types.d.ts",
|
|
26
|
+
"default": "./types.js"
|
|
27
|
+
},
|
|
28
|
+
"./services/*": {
|
|
29
|
+
"types": "./generated/services/*.d.ts",
|
|
30
|
+
"default": "./generated/services/*.js"
|
|
31
|
+
},
|
|
32
|
+
"./services/transitions/*": {
|
|
33
|
+
"types": "./generated/services/transitions/*.d.ts",
|
|
34
|
+
"default": "./generated/services/transitions/*.js"
|
|
35
|
+
},
|
|
36
|
+
"./utils/*": {
|
|
37
|
+
"types": "./generated/utils/*.d.ts",
|
|
38
|
+
"default": "./generated/utils/*.js"
|
|
11
39
|
}
|
|
12
40
|
},
|
|
13
41
|
"dependencies": {
|
|
14
|
-
"@agnos-ui/core": "0.0.1-alpha.
|
|
15
|
-
"@amadeus-it-group/tansu": "0.0
|
|
16
|
-
"classnames": "^2.
|
|
42
|
+
"@agnos-ui/core": "0.0.1-alpha.11",
|
|
43
|
+
"@amadeus-it-group/tansu": "1.0.0",
|
|
44
|
+
"classnames": "^2.5.1"
|
|
17
45
|
},
|
|
18
46
|
"peerDependencies": {
|
|
19
47
|
"react": "*",
|
|
20
48
|
"react-dom": "*"
|
|
21
49
|
},
|
|
22
50
|
"sideEffects": false,
|
|
23
|
-
"version": "0.0.1-alpha.
|
|
51
|
+
"version": "0.0.1-alpha.11",
|
|
24
52
|
"homepage": "https://amadeusitgroup.github.io/AgnosUI/latest/",
|
|
25
53
|
"bugs": "https://github.com/AmadeusITGroup/AgnosUI/issues",
|
|
26
54
|
"license": "MIT",
|
|
@@ -38,6 +66,7 @@
|
|
|
38
66
|
"alert",
|
|
39
67
|
"modal",
|
|
40
68
|
"pagination",
|
|
41
|
-
"rating"
|
|
69
|
+
"rating",
|
|
70
|
+
"slider"
|
|
42
71
|
]
|
|
43
72
|
}
|
package/slot.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SlotContent } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The React Slot component, allowing to extensively customize widgets.
|
|
4
|
+
*
|
|
5
|
+
* The input slotContent can be a react component, a function or jsx.
|
|
6
|
+
*
|
|
7
|
+
* @param parameter - the react component parameter
|
|
8
|
+
* @param parameter.slotContent - the slot content
|
|
9
|
+
* @param parameter.props - the react component props
|
|
10
|
+
* @returns the slot component
|
|
11
|
+
*/
|
|
12
|
+
export declare const Slot: <Props extends object>({ slotContent, props }: {
|
|
13
|
+
slotContent: SlotContent<Props>;
|
|
14
|
+
props: Props;
|
|
15
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
package/{Slot.js → slot.js}
RENAMED
|
@@ -15,6 +15,16 @@ const slotWrapper = (slotContent) => {
|
|
|
15
15
|
};
|
|
16
16
|
/* eslint-disable-next-line @typescript-eslint/ban-types */
|
|
17
17
|
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
|
+
*/
|
|
18
28
|
export const Slot = ({ slotContent, props }) => {
|
|
19
29
|
const isFunction = typeof slotContent === 'function';
|
|
20
30
|
if (isFunction) {
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export * from '@agnos-ui/core/types';
|
|
3
|
+
import type { SlotContent as CoreSlotContent, Widget, WidgetFactory, WidgetProps, WidgetSlotContext, WidgetState } from '@agnos-ui/core/types';
|
|
4
|
+
export type SlotContent<Props extends object = object> = CoreSlotContent<Props> | ((props: Props) => React.ReactNode) | React.ComponentType<Props> | React.ReactNode;
|
|
5
|
+
export type AdaptSlotContentProps<Props extends Record<string, any>> = Props extends WidgetSlotContext<infer U> ? WidgetSlotContext<AdaptWidgetSlots<U>> & AdaptPropsSlots<Omit<Props, keyof WidgetSlotContext<any>>> : AdaptPropsSlots<Props>;
|
|
6
|
+
export type AdaptPropsSlots<Props> = Omit<Props, `slot${string}`> & {
|
|
7
|
+
[K in keyof Props & `slot${string}`]: Props[K] extends CoreSlotContent<infer U> ? SlotContent<AdaptSlotContentProps<U>> : Props[K];
|
|
8
|
+
};
|
|
9
|
+
export type AdaptWidgetFactories<T> = {
|
|
10
|
+
[K in keyof T]: T[K] extends WidgetFactory<infer U> ? WidgetFactory<AdaptWidgetSlots<U>> : T[K];
|
|
11
|
+
};
|
|
12
|
+
export type AdaptWidgetSlots<W extends Widget> = Widget<AdaptPropsSlots<WidgetProps<W>>, AdaptPropsSlots<WidgetState<W>>, AdaptWidgetFactories<W['api']>, W['actions'], W['directives']>;
|
package/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/types';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Directive } from '@agnos-ui/core/types';
|
|
2
|
+
import type { RefCallback } from 'react';
|
|
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>;
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PropsWithChildren } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A Portal component, allowing to attach content to an external container.
|
|
4
|
+
*
|
|
5
|
+
* @param param - the react component inputs
|
|
6
|
+
* @param param.children - the react component children
|
|
7
|
+
* @param param.container - the container to attach the portal to
|
|
8
|
+
* @returns the portal component
|
|
9
|
+
*/
|
|
10
|
+
export declare const Portal: ({ children, container }: PropsWithChildren<{
|
|
11
|
+
container: Element | DocumentFragment | null | undefined;
|
|
12
|
+
}>) => import("react/jsx-runtime").JSX.Element;
|
package/utils/portal.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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 });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReadableSignal } from '@amadeus-it-group/tansu';
|
|
2
|
+
export * from '@agnos-ui/core/utils/stores';
|
|
3
|
+
/**
|
|
4
|
+
* Observe a readable store inside of a react component.
|
|
5
|
+
*
|
|
6
|
+
* @param store$ - the readable store
|
|
7
|
+
* @returns the observed value of the store
|
|
8
|
+
*/
|
|
9
|
+
export declare function useObservable<T>(store$: ReadableSignal<T>): T;
|
|
10
|
+
/**
|
|
11
|
+
* Turn react props into readable stores.
|
|
12
|
+
*
|
|
13
|
+
* @param props - the props
|
|
14
|
+
* @returns the readable stores
|
|
15
|
+
*/
|
|
16
|
+
export declare const usePropsAsStore: <T extends object>(props?: Partial<T> | undefined) => ReadableSignal<Partial<T>>;
|
package/utils/stores.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PropsConfig, Widget, WidgetFactory, WidgetProps, WidgetState } from '@agnos-ui/core/types';
|
|
2
|
+
/**
|
|
3
|
+
* The useWidget function.
|
|
4
|
+
*
|
|
5
|
+
* Allows to create and attach an agnos-ui/core widget to the current react component.
|
|
6
|
+
*
|
|
7
|
+
* @param createWidget - the widget factory
|
|
8
|
+
* @param props - the props
|
|
9
|
+
* @param propsConfig - the props config
|
|
10
|
+
* @returns the state and api to track and interact with the widget
|
|
11
|
+
*/
|
|
12
|
+
export declare function useWidget<W extends Widget>(createWidget: WidgetFactory<W>, props?: Partial<WidgetProps<W>>, propsConfig?: PropsConfig<WidgetProps<W>>): [WidgetState<W>, W];
|
package/utils/widget.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
package/Portal.d.ts
DELETED
package/Portal.js
DELETED
package/Slot.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Partial2Levels } from '@agnos-ui/core';
|
|
2
|
-
import type { PropsWithChildren } from 'react';
|
|
3
|
-
import type { WidgetsConfig } from './utils';
|
|
4
|
-
/**
|
|
5
|
-
* React component that provides in the React context (for all AgnosUI descendant widgets) a new widgets default configuration
|
|
6
|
-
* store that inherits from any widgets default configuration store already defined at an upper level in the React context hierarchy.
|
|
7
|
-
* It contains its own set of widgets configuration properties that override the same properties form the parent configuration.
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* The configuration is computed from the parent configuration in two steps:
|
|
11
|
-
* - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
|
|
12
|
-
* If adaptParentConfig is not specified, this step is skipped.
|
|
13
|
-
* - second step: the configuration from step 1 is merged (2-levels deep) with the properties of the component.
|
|
14
|
-
*
|
|
15
|
-
* @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
|
|
16
|
-
* defined at an upper level in the Svelte context hierarchy (or an empty object if there is none) and returns the widgets
|
|
17
|
-
* default configuration to be used.
|
|
18
|
-
* It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
|
|
19
|
-
* It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
|
|
20
|
-
*
|
|
21
|
-
* @returns the resulting widgets default configuration store, which contains 3 additional properties that are stores:
|
|
22
|
-
* parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties).
|
|
23
|
-
* The resulting store is writable, its set function is actually the set function of the own$ store.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```tsx
|
|
27
|
-
* <WidgetsDefaultConfig
|
|
28
|
-
* adaptParentConfig={(parentConfig) => {
|
|
29
|
-
* parentConfig.rating = parentConfig.rating ?? {};
|
|
30
|
-
* parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
|
|
31
|
-
* return parentConfig;
|
|
32
|
-
* }}
|
|
33
|
-
* rating={{slotStar: MyCustomSlotStar}}
|
|
34
|
-
* />
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare const WidgetsDefaultConfig: ({ children, adaptParentConfig, ...props }: Partial<{
|
|
38
|
-
pagination: Partial<import("./utils").AdaptPropsSlots<import("@agnos-ui/core").PaginationProps>>;
|
|
39
|
-
rating: Partial<import("./utils").AdaptPropsSlots<import("@agnos-ui/core").RatingProps>>;
|
|
40
|
-
select: Partial<import("./utils").AdaptPropsSlots<import("@agnos-ui/core").SelectProps<any>>>;
|
|
41
|
-
modal: Partial<import("./utils").AdaptPropsSlots<import("@agnos-ui/core").ModalProps>>;
|
|
42
|
-
alert: Partial<import("./utils").AdaptPropsSlots<import("@agnos-ui/core").AlertProps>>;
|
|
43
|
-
accordion: Partial<import("./utils").AdaptPropsSlots<import("@agnos-ui/core").AccordionProps>>;
|
|
44
|
-
}> & {
|
|
45
|
-
children?: import("react").ReactNode;
|
|
46
|
-
} & {
|
|
47
|
-
adaptParentConfig?: ((config: Partial2Levels<WidgetsConfig>) => Partial2Levels<WidgetsConfig>) | undefined;
|
|
48
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
package/WidgetsDefaultConfig.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createWidgetsConfig } from '@agnos-ui/core';
|
|
3
|
-
import { useContext, useEffect, useMemo } from 'react';
|
|
4
|
-
import { widgetsConfigContext } from './utils';
|
|
5
|
-
/**
|
|
6
|
-
* React component that provides in the React context (for all AgnosUI descendant widgets) a new widgets default configuration
|
|
7
|
-
* store that inherits from any widgets default configuration store already defined at an upper level in the React context hierarchy.
|
|
8
|
-
* It contains its own set of widgets configuration properties that override the same properties form the parent configuration.
|
|
9
|
-
*
|
|
10
|
-
* @remarks
|
|
11
|
-
* The configuration is computed from the parent configuration in two steps:
|
|
12
|
-
* - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
|
|
13
|
-
* If adaptParentConfig is not specified, this step is skipped.
|
|
14
|
-
* - second step: the configuration from step 1 is merged (2-levels deep) with the properties of the component.
|
|
15
|
-
*
|
|
16
|
-
* @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
|
|
17
|
-
* defined at an upper level in the Svelte context hierarchy (or an empty object if there is none) and returns the widgets
|
|
18
|
-
* default configuration to be used.
|
|
19
|
-
* It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
|
|
20
|
-
* It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
|
|
21
|
-
*
|
|
22
|
-
* @returns the resulting widgets default configuration store, which contains 3 additional properties that are stores:
|
|
23
|
-
* parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties).
|
|
24
|
-
* The resulting store is writable, its set function is actually the set function of the own$ store.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```tsx
|
|
28
|
-
* <WidgetsDefaultConfig
|
|
29
|
-
* adaptParentConfig={(parentConfig) => {
|
|
30
|
-
* parentConfig.rating = parentConfig.rating ?? {};
|
|
31
|
-
* parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
|
|
32
|
-
* return parentConfig;
|
|
33
|
-
* }}
|
|
34
|
-
* rating={{slotStar: MyCustomSlotStar}}
|
|
35
|
-
* />
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export const WidgetsDefaultConfig = ({ children, adaptParentConfig, ...props }) => {
|
|
39
|
-
const config$ = useContext(widgetsConfigContext);
|
|
40
|
-
let storeRecreated = false;
|
|
41
|
-
const store$ = useMemo(() => {
|
|
42
|
-
const store = createWidgetsConfig(config$, adaptParentConfig);
|
|
43
|
-
store.set(props);
|
|
44
|
-
storeRecreated = true;
|
|
45
|
-
return store;
|
|
46
|
-
}, [config$, adaptParentConfig]);
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (!storeRecreated) {
|
|
49
|
-
store$.set(props);
|
|
50
|
-
}
|
|
51
|
-
}, [props]);
|
|
52
|
-
return _jsx(widgetsConfigContext.Provider, { value: store$, children: children });
|
|
53
|
-
};
|
package/utils.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Directive, Widget, WidgetFactory, WidgetProps, WidgetState, WidgetsConfigStore } from '@agnos-ui/core';
|
|
2
|
-
import type { ReadableSignal } from '@amadeus-it-group/tansu';
|
|
3
|
-
import type { RefCallback } from 'react';
|
|
4
|
-
import type { SlotContent as CoreSlotContent, WidgetsConfig as CoreWidgetsConfig, WidgetSlotContext } from '@agnos-ui/core';
|
|
5
|
-
export type SlotContent<Props extends object = object> = CoreSlotContent<Props> | ((props: Props) => React.ReactNode) | React.ComponentType<Props> | React.ReactNode;
|
|
6
|
-
export type AdaptSlotContentProps<Props extends Record<string, any>> = Props extends WidgetSlotContext<infer U> ? WidgetSlotContext<AdaptWidgetSlots<U>> & AdaptPropsSlots<Omit<Props, keyof WidgetSlotContext<any>>> : AdaptPropsSlots<Props>;
|
|
7
|
-
export type AdaptPropsSlots<Props> = Omit<Props, `slot${string}`> & {
|
|
8
|
-
[K in keyof Props & `slot${string}`]: Props[K] extends CoreSlotContent<infer U> ? SlotContent<AdaptSlotContentProps<U>> : Props[K];
|
|
9
|
-
};
|
|
10
|
-
export type WidgetsConfig = {
|
|
11
|
-
[WidgetName in keyof CoreWidgetsConfig]: AdaptPropsSlots<CoreWidgetsConfig[WidgetName]>;
|
|
12
|
-
};
|
|
13
|
-
export type AdaptWidgetSlots<W extends Widget> = Widget<AdaptPropsSlots<WidgetProps<W>>, AdaptPropsSlots<WidgetState<W>>, W['api'], W['actions'], W['directives']>;
|
|
14
|
-
export declare function useWidget<Factory extends (...arg: any[]) => Widget>(createWidget: Factory, props?: Partial<WidgetProps<ReturnType<Factory>>>, ...initProps: Parameters<Factory>): [WidgetState<ReturnType<Factory>>, ReturnType<Factory>];
|
|
15
|
-
export declare function useObservable<T>(store$: ReadableSignal<T>): T;
|
|
16
|
-
export declare function useDirective(directive: Directive<void>): RefCallback<HTMLElement>;
|
|
17
|
-
export declare function useDirective<T>(directive: Directive<T>, args: T): RefCallback<HTMLElement>;
|
|
18
|
-
/**
|
|
19
|
-
* React context which can be used to provide or consume the widgets default configuration store.
|
|
20
|
-
*/
|
|
21
|
-
export declare const widgetsConfigContext: import("react").Context<WidgetsConfigStore<WidgetsConfig> | undefined>;
|
|
22
|
-
export declare const useWidgetWithConfig: <W extends Widget<object, object, object, object, object>>(factory: WidgetFactory<W>, props: Partial<AdaptPropsSlots<WidgetProps<W>>> | undefined, widgetName: keyof WidgetsConfig | null, defaultProps?: Partial<AdaptPropsSlots<WidgetProps<W>>> | undefined) => [AdaptPropsSlots<WidgetState<W>>, AdaptWidgetSlots<W>];
|
package/utils.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { findChangedProperties } from '@agnos-ui/core';
|
|
2
|
-
import { asReadable, computed, writable } from '@amadeus-it-group/tansu';
|
|
3
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
export function useWidget(createWidget, props = {}, ...initProps) {
|
|
5
|
-
const apiRef = useRef(undefined);
|
|
6
|
-
if (!apiRef.current) {
|
|
7
|
-
apiRef.current = createWidget(...initProps);
|
|
8
|
-
apiRef.current.patch(props);
|
|
9
|
-
}
|
|
10
|
-
const api = apiRef.current;
|
|
11
|
-
const previousProps = useRef(props);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const changedProps = findChangedProperties(previousProps.current, props);
|
|
14
|
-
previousProps.current = props;
|
|
15
|
-
if (changedProps) {
|
|
16
|
-
api.patch(changedProps);
|
|
17
|
-
}
|
|
18
|
-
}, [props]);
|
|
19
|
-
const state = useObservable(api.state$);
|
|
20
|
-
return [state, api];
|
|
21
|
-
}
|
|
22
|
-
export function useObservable(store$) {
|
|
23
|
-
const [value, setValue] = useState(() => store$());
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
return store$.subscribe((arg) => {
|
|
26
|
-
// We're passing an update function to setValue here instead of just doing setValue(arg) so that
|
|
27
|
-
// if arg is a function, it is properly used as the value instead of being called as an update function
|
|
28
|
-
setValue(() => arg);
|
|
29
|
-
});
|
|
30
|
-
}, [store$]);
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
export function useDirective(directive, args) {
|
|
34
|
-
const instance = useRef();
|
|
35
|
-
const propsRef = useRef();
|
|
36
|
-
const ref = useCallback((element) => {
|
|
37
|
-
instance.current?.destroy?.();
|
|
38
|
-
instance.current = undefined;
|
|
39
|
-
if (element) {
|
|
40
|
-
instance.current = directive(element, propsRef.current);
|
|
41
|
-
}
|
|
42
|
-
}, [directive]);
|
|
43
|
-
propsRef.current = args;
|
|
44
|
-
instance.current?.update?.(args);
|
|
45
|
-
return ref;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* React context which can be used to provide or consume the widgets default configuration store.
|
|
49
|
-
*/
|
|
50
|
-
export const widgetsConfigContext = createContext(undefined);
|
|
51
|
-
const propsEqual = (a, b) => !findChangedProperties(a, b);
|
|
52
|
-
const usePropsAsStore = (props) => {
|
|
53
|
-
const storeRef = useRef();
|
|
54
|
-
if (!storeRef.current) {
|
|
55
|
-
storeRef.current = writable({ ...props }, { equal: propsEqual });
|
|
56
|
-
}
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
storeRef.current.set({ ...props });
|
|
59
|
-
}, [props]);
|
|
60
|
-
return useMemo(() => asReadable(storeRef.current), [storeRef.current]);
|
|
61
|
-
};
|
|
62
|
-
const useWidgetContext = (widgetName, defaultConfig) => {
|
|
63
|
-
const widgetsConfig = useContext(widgetsConfigContext);
|
|
64
|
-
const defaultConfig$ = usePropsAsStore(defaultConfig);
|
|
65
|
-
return useMemo(() => computed(() => ({ ...defaultConfig$(), ...(widgetName ? widgetsConfig?.()[widgetName] : undefined) })), [widgetsConfig]);
|
|
66
|
-
};
|
|
67
|
-
export const useWidgetWithConfig = (factory, props, widgetName, defaultProps) => useWidget(factory, props, useWidgetContext(widgetName, defaultProps));
|