@agnos-ui/react-headless 0.0.1-alpha.1 → 0.0.1-alpha.4

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/Slot.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SlotContent } from './utils';
1
+ import type { SlotContent } from './slotTypes';
2
2
  export declare const Slot: <Props extends object>({ slotContent, props }: {
3
3
  slotContent: SlotContent<Props>;
4
4
  props: Props;
package/config.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { type Partial2Levels, type Widget, type WidgetFactory, type WidgetProps, type WidgetState, type WidgetsConfigStore } from '@agnos-ui/core';
2
+ import type { ReactNode } from 'react';
3
+ import type { AdaptPropsSlots } from './slotTypes';
4
+ export type WidgetsConfig = {
5
+ [WidgetName in keyof import('@agnos-ui/core').WidgetsConfig]: AdaptPropsSlots<import('@agnos-ui/core').WidgetsConfig[WidgetName]>;
6
+ };
7
+ export declare const widgetsConfigFactory: <Config extends {
8
+ [widgetName: string]: object;
9
+ } = WidgetsConfig>(widgetsConfigContext?: import("react").Context<WidgetsConfigStore<Config> | undefined>) => {
10
+ /**
11
+ * React context which can be used to provide or consume the widgets default configuration store.
12
+ */
13
+ widgetsConfigContext: import("react").Context<WidgetsConfigStore<Config> | undefined>;
14
+ useWidgetContext: <Props extends object>(widgetName: keyof Config | null, defaultConfig?: Partial<Props> | undefined) => import("@amadeus-it-group/tansu").ReadableSignal<Partial<Props>>;
15
+ 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];
16
+ WidgetsDefaultConfig: ({ children, adaptParentConfig, ...props }: Partial<{ [Level1 in keyof Config]: Partial<Config[Level1]>; }> & {
17
+ adaptParentConfig?: ((config: Partial<{ [Level1 in keyof Config]: Partial<Config[Level1]>; }>) => Partial<{ [Level1 in keyof Config]: Partial<Config[Level1]>; }>) | undefined;
18
+ children?: ReactNode | undefined;
19
+ }) => import("react/jsx-runtime").JSX.Element;
20
+ };
21
+ export declare const widgetsConfigContext: import("react").Context<WidgetsConfigStore<WidgetsConfig> | undefined>, useWidgetContext: <Props extends object>(widgetName: keyof import("@agnos-ui/core").WidgetsConfig | 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 import("@agnos-ui/core").WidgetsConfig | null, defaultProps?: Partial<WidgetProps<W>> | undefined) => [WidgetState<W>, W], WidgetsDefaultConfig: ({ children, adaptParentConfig, ...props }: Partial<{
22
+ pagination: Partial<AdaptPropsSlots<import("@agnos-ui/core").PaginationProps>>;
23
+ rating: Partial<AdaptPropsSlots<import("@agnos-ui/core").RatingProps>>;
24
+ select: Partial<AdaptPropsSlots<import("@agnos-ui/core").SelectProps<any>>>;
25
+ modal: Partial<AdaptPropsSlots<import("@agnos-ui/core").ModalProps>>;
26
+ alert: Partial<AdaptPropsSlots<import("@agnos-ui/core").AlertProps>>;
27
+ accordion: Partial<AdaptPropsSlots<import("@agnos-ui/core").AccordionProps>>;
28
+ progressbar: Partial<AdaptPropsSlots<import("@agnos-ui/core").ProgressbarProps>>;
29
+ slider: Partial<AdaptPropsSlots<import("@agnos-ui/core").SliderProps>>;
30
+ }> & {
31
+ adaptParentConfig?: ((config: Partial<{
32
+ pagination: Partial<AdaptPropsSlots<import("@agnos-ui/core").PaginationProps>>;
33
+ rating: Partial<AdaptPropsSlots<import("@agnos-ui/core").RatingProps>>;
34
+ select: Partial<AdaptPropsSlots<import("@agnos-ui/core").SelectProps<any>>>;
35
+ modal: Partial<AdaptPropsSlots<import("@agnos-ui/core").ModalProps>>;
36
+ alert: Partial<AdaptPropsSlots<import("@agnos-ui/core").AlertProps>>;
37
+ accordion: Partial<AdaptPropsSlots<import("@agnos-ui/core").AccordionProps>>;
38
+ progressbar: Partial<AdaptPropsSlots<import("@agnos-ui/core").ProgressbarProps>>;
39
+ slider: Partial<AdaptPropsSlots<import("@agnos-ui/core").SliderProps>>;
40
+ }>) => Partial<{
41
+ pagination: Partial<AdaptPropsSlots<import("@agnos-ui/core").PaginationProps>>;
42
+ rating: Partial<AdaptPropsSlots<import("@agnos-ui/core").RatingProps>>;
43
+ select: Partial<AdaptPropsSlots<import("@agnos-ui/core").SelectProps<any>>>;
44
+ modal: Partial<AdaptPropsSlots<import("@agnos-ui/core").ModalProps>>;
45
+ alert: Partial<AdaptPropsSlots<import("@agnos-ui/core").AlertProps>>;
46
+ accordion: Partial<AdaptPropsSlots<import("@agnos-ui/core").AccordionProps>>;
47
+ progressbar: Partial<AdaptPropsSlots<import("@agnos-ui/core").ProgressbarProps>>;
48
+ slider: Partial<AdaptPropsSlots<import("@agnos-ui/core").SliderProps>>;
49
+ }>) | undefined;
50
+ children?: ReactNode | undefined;
51
+ }) => import("react/jsx-runtime").JSX.Element;
package/config.js ADDED
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createWidgetsConfig, } from '@agnos-ui/core';
3
+ import { computed } from '@amadeus-it-group/tansu';
4
+ import { createContext, useContext, useEffect, useMemo } from 'react';
5
+ import { usePropsAsStore, useWidget } from './utils';
6
+ export const widgetsConfigFactory = (widgetsConfigContext = createContext(undefined)) => {
7
+ const useWidgetContext = (widgetName, defaultConfig) => {
8
+ const widgetsConfig = useContext(widgetsConfigContext);
9
+ const defaultConfig$ = usePropsAsStore(defaultConfig);
10
+ return useMemo(() => computed(() => ({ ...defaultConfig$(), ...(widgetName ? widgetsConfig?.()[widgetName] : undefined) })), [widgetsConfig]);
11
+ };
12
+ const useWidgetWithConfig = (factory, props, widgetName, defaultProps) => useWidget(factory, props, { config: useWidgetContext(widgetName, defaultProps) });
13
+ /**
14
+ * React component that provides in the React context (for all AgnosUI descendant widgets) a new widgets default configuration
15
+ * store that inherits from any widgets default configuration store already defined at an upper level in the React context hierarchy.
16
+ * It contains its own set of widgets configuration properties that override the same properties form the parent configuration.
17
+ *
18
+ * @remarks
19
+ * The configuration is computed from the parent configuration in two steps:
20
+ * - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
21
+ * If adaptParentConfig is not specified, this step is skipped.
22
+ * - second step: the configuration from step 1 is merged (2-levels deep) with the properties of the component.
23
+ *
24
+ * @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
25
+ * defined at an upper level in the Svelte context hierarchy (or an empty object if there is none) and returns the widgets
26
+ * default configuration to be used.
27
+ * It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
28
+ * It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
29
+ *
30
+ * @returns the resulting widgets default configuration store, which contains 3 additional properties that are stores:
31
+ * parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties).
32
+ * The resulting store is writable, its set function is actually the set function of the own$ store.
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * <WidgetsDefaultConfig
37
+ * adaptParentConfig={(parentConfig) => {
38
+ * parentConfig.rating = parentConfig.rating ?? {};
39
+ * parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
40
+ * return parentConfig;
41
+ * }}
42
+ * rating={{slotStar: MyCustomSlotStar}}
43
+ * />
44
+ * ```
45
+ */
46
+ const WidgetsDefaultConfig = ({ children, adaptParentConfig, ...props }) => {
47
+ const config$ = useContext(widgetsConfigContext);
48
+ let storeRecreated = false;
49
+ const store$ = useMemo(() => {
50
+ const store = createWidgetsConfig(config$, adaptParentConfig);
51
+ store.set(props);
52
+ storeRecreated = true;
53
+ return store;
54
+ }, [config$, adaptParentConfig]);
55
+ useEffect(() => {
56
+ if (!storeRecreated) {
57
+ store$.set(props);
58
+ }
59
+ }, [props]);
60
+ return _jsx(widgetsConfigContext.Provider, { value: store$, children: children });
61
+ };
62
+ return {
63
+ /**
64
+ * React context which can be used to provide or consume the widgets default configuration store.
65
+ */
66
+ widgetsConfigContext,
67
+ useWidgetContext,
68
+ useWidgetWithConfig,
69
+ WidgetsDefaultConfig,
70
+ };
71
+ };
72
+ export const { widgetsConfigContext, useWidgetContext, useWidgetWithConfig, WidgetsDefaultConfig } = widgetsConfigFactory();
package/index.d.ts CHANGED
@@ -1,34 +1,48 @@
1
1
  export * from '@agnos-ui/core';
2
2
  export * from './Portal';
3
3
  export * from './Slot';
4
- export * from './WidgetsDefaultConfig';
4
+ export * from './slotTypes';
5
5
  export * from './utils';
6
- import type { WidgetProps, WidgetState } from '@agnos-ui/core';
7
- import type { AdaptSlotContentProps, AdaptWidgetSlots } from './utils';
8
- export type { SlotContent, WidgetsConfig } from './utils';
6
+ export * from './config';
7
+ import type { PropsConfig, WidgetFactory, WidgetProps, WidgetState } from '@agnos-ui/core';
8
+ import type { AdaptSlotContentProps, AdaptWidgetSlots } from './slotTypes';
9
+ export type { SlotContent } from './slotTypes';
10
+ export type { WidgetsConfig } from './config';
9
11
  export type AccordionWidget = AdaptWidgetSlots<import('@agnos-ui/core').AccordionWidget>;
10
12
  export type AccordionProps = WidgetProps<AccordionWidget>;
11
13
  export type AccordionState = WidgetState<AccordionWidget>;
14
+ export type AccordionApi = AccordionWidget['api'];
12
15
  export type AccordionItemWidget = AdaptWidgetSlots<import('@agnos-ui/core').AccordionItemWidget>;
13
16
  export type AccordionItemProps = WidgetProps<AccordionItemWidget>;
14
17
  export type AccordionItemState = WidgetState<AccordionItemWidget>;
15
18
  export type AccordionItemContext = AdaptSlotContentProps<import('@agnos-ui/core').AccordionItemContext>;
19
+ export declare const createAccordion: WidgetFactory<AccordionWidget>;
16
20
  export type AlertWidget = AdaptWidgetSlots<import('@agnos-ui/core').AlertWidget>;
17
21
  export type AlertProps = WidgetProps<AlertWidget>;
18
22
  export type AlertState = WidgetState<AlertWidget>;
19
23
  export type AlertContext = AdaptSlotContentProps<import('@agnos-ui/core').AlertContext>;
24
+ export declare const createAlert: WidgetFactory<AlertWidget>;
20
25
  export type ModalWidget = AdaptWidgetSlots<import('@agnos-ui/core').ModalWidget>;
21
26
  export type ModalProps = WidgetProps<ModalWidget>;
22
27
  export type ModalState = WidgetState<ModalWidget>;
23
28
  export type ModalContext = AdaptSlotContentProps<import('@agnos-ui/core').ModalContext>;
29
+ export declare const createModal: WidgetFactory<ModalWidget>;
24
30
  export type PaginationWidget = AdaptWidgetSlots<import('@agnos-ui/core').PaginationWidget>;
25
31
  export type PaginationProps = WidgetProps<PaginationWidget>;
26
32
  export type PaginationState = WidgetState<PaginationWidget>;
27
33
  export type PaginationContext = AdaptSlotContentProps<import('@agnos-ui/core').PaginationContext>;
28
34
  export type PaginationNumberContext = AdaptSlotContentProps<import('@agnos-ui/core').PaginationNumberContext>;
35
+ export declare const createPagination: WidgetFactory<PaginationWidget>;
29
36
  export type RatingWidget = AdaptWidgetSlots<import('@agnos-ui/core').RatingWidget>;
30
37
  export type RatingProps = WidgetProps<RatingWidget>;
31
38
  export type RatingState = WidgetState<RatingWidget>;
39
+ export declare const createRating: WidgetFactory<RatingWidget>;
32
40
  export type SelectWidget<Item> = AdaptWidgetSlots<import('@agnos-ui/core').SelectWidget<Item>>;
33
41
  export type SelectProps<Item> = WidgetProps<SelectWidget<Item>>;
34
42
  export type SelectState<Item> = WidgetState<SelectWidget<Item>>;
43
+ export declare const createSelect: <Item>(propsConfig?: PropsConfig<SelectProps<Item>>) => SelectWidget<Item>;
44
+ export type ProgressbarWidget = AdaptWidgetSlots<import('@agnos-ui/core').ProgressbarWidget>;
45
+ export type ProgressbarProps = WidgetProps<ProgressbarWidget>;
46
+ export type ProgressbarState = WidgetState<ProgressbarWidget>;
47
+ export type ProgressbarContext = AdaptSlotContentProps<import('@agnos-ui/core').ProgressbarContext>;
48
+ export declare const createProgressbar: WidgetFactory<ProgressbarWidget>;
package/index.js CHANGED
@@ -1,5 +1,20 @@
1
1
  export * from '@agnos-ui/core';
2
2
  export * from './Portal';
3
3
  export * from './Slot';
4
- export * from './WidgetsDefaultConfig';
4
+ export * from './slotTypes';
5
5
  export * from './utils';
6
+ export * from './config';
7
+ import { createAccordion as coreCreateAccordion } from '@agnos-ui/core';
8
+ export const createAccordion = coreCreateAccordion;
9
+ import { createAlert as coreCreateAlert } from '@agnos-ui/core';
10
+ export const createAlert = coreCreateAlert;
11
+ import { createModal as coreCreateModal } from '@agnos-ui/core';
12
+ export const createModal = coreCreateModal;
13
+ import { createPagination as coreCreatePagination } from '@agnos-ui/core';
14
+ export const createPagination = coreCreatePagination;
15
+ import { createRating as coreCreateRating } from '@agnos-ui/core';
16
+ export const createRating = coreCreateRating;
17
+ import { createSelect as coreCreateSelect } from '@agnos-ui/core';
18
+ export const createSelect = coreCreateSelect;
19
+ import { createProgressbar as coreCreateProgressbar } from '@agnos-ui/core';
20
+ export const createProgressbar = coreCreateProgressbar;
package/package.json CHANGED
@@ -11,8 +11,8 @@
11
11
  }
12
12
  },
13
13
  "dependencies": {
14
- "@agnos-ui/core": "0.0.1-alpha.1",
15
- "@amadeus-it-group/tansu": "0.0.22",
14
+ "@agnos-ui/core": "0.0.1-alpha.4",
15
+ "@amadeus-it-group/tansu": "0.0.23",
16
16
  "classnames": "^2.3.2"
17
17
  },
18
18
  "peerDependencies": {
@@ -20,7 +20,7 @@
20
20
  "react-dom": "*"
21
21
  },
22
22
  "sideEffects": false,
23
- "version": "0.0.1-alpha.1",
23
+ "version": "0.0.1-alpha.4",
24
24
  "homepage": "https://amadeusitgroup.github.io/AgnosUI/latest/",
25
25
  "bugs": "https://github.com/AmadeusITGroup/AgnosUI/issues",
26
26
  "license": "MIT",
@@ -38,6 +38,7 @@
38
38
  "alert",
39
39
  "modal",
40
40
  "pagination",
41
- "rating"
41
+ "rating",
42
+ "slider"
42
43
  ]
43
44
  }
package/slotTypes.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import type { SlotContent as CoreSlotContent, Widget, WidgetFactory, WidgetProps, WidgetSlotContext, WidgetState } from '@agnos-ui/core';
3
+ export type SlotContent<Props extends object = object> = CoreSlotContent<Props> | ((props: Props) => React.ReactNode) | React.ComponentType<Props> | React.ReactNode;
4
+ export type AdaptSlotContentProps<Props extends Record<string, any>> = Props extends WidgetSlotContext<infer U> ? WidgetSlotContext<AdaptWidgetSlots<U>> & AdaptPropsSlots<Omit<Props, keyof WidgetSlotContext<any>>> : AdaptPropsSlots<Props>;
5
+ export type AdaptPropsSlots<Props> = Omit<Props, `slot${string}`> & {
6
+ [K in keyof Props & `slot${string}`]: Props[K] extends CoreSlotContent<infer U> ? SlotContent<AdaptSlotContentProps<U>> : Props[K];
7
+ };
8
+ export type AdaptWidgetFactories<T> = {
9
+ [K in keyof T]: T[K] extends WidgetFactory<infer U> ? WidgetFactory<AdaptWidgetSlots<U>> : T[K];
10
+ };
11
+ export type AdaptWidgetSlots<W extends Widget> = Widget<AdaptPropsSlots<WidgetProps<W>>, AdaptPropsSlots<WidgetState<W>>, AdaptWidgetFactories<W['api']>, W['actions'], W['directives']>;
package/slotTypes.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/utils.d.ts CHANGED
@@ -1,22 +1,8 @@
1
- import type { Directive, Widget, WidgetFactory, WidgetProps, WidgetState, WidgetsConfigStore } from '@agnos-ui/core';
1
+ import type { Directive, Widget, WidgetProps, WidgetState } from '@agnos-ui/core';
2
2
  import type { ReadableSignal } from '@amadeus-it-group/tansu';
3
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
4
  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
5
  export declare function useObservable<T>(store$: ReadableSignal<T>): T;
16
6
  export declare function useDirective(directive: Directive<void>): RefCallback<HTMLElement>;
17
7
  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>];
8
+ export declare const usePropsAsStore: <T extends object>(props?: Partial<T> | undefined) => ReadableSignal<Partial<T>>;
package/utils.js CHANGED
@@ -1,6 +1,6 @@
1
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';
2
+ import { asReadable, writable } from '@amadeus-it-group/tansu';
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  export function useWidget(createWidget, props = {}, ...initProps) {
5
5
  const apiRef = useRef(undefined);
6
6
  if (!apiRef.current) {
@@ -44,12 +44,8 @@ export function useDirective(directive, args) {
44
44
  instance.current?.update?.(args);
45
45
  return ref;
46
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
47
  const propsEqual = (a, b) => !findChangedProperties(a, b);
52
- const usePropsAsStore = (props) => {
48
+ export const usePropsAsStore = (props) => {
53
49
  const storeRef = useRef();
54
50
  if (!storeRef.current) {
55
51
  storeRef.current = writable({ ...props }, { equal: propsEqual });
@@ -59,9 +55,3 @@ const usePropsAsStore = (props) => {
59
55
  }, [props]);
60
56
  return useMemo(() => asReadable(storeRef.current), [storeRef.current]);
61
57
  };
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));
@@ -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;
@@ -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
- };