Bootstrap

API config

createWidgetsConfig

function

createWidgetsConfig<T>(parent$?, adaptParentConfig?): WidgetsConfigStore<T>

Creates a new widgets default configuration store, optionally inheriting from a parent store, and containing its own set of widgets configuration properties that override the same properties form the parent configuration.

Type Parameters
T

T

Parameters
parent$?

WidgetsConfigStore<T>

optional parent widgets default configuration store.

adaptParentConfig?

(config) => Partial2Levels<T>

optional function that receives a 2-levels copy of the widgets default configuration from parent$ (or an empty object if parent$ is not specified) and returns the widgets default configuration to be used. It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration. It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.

Returns

WidgetsConfigStore<T>

the resulting widgets default configuration store, which contains 3 additional properties that are stores: parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties). The resulting store is writable, its set function is actually the set function of the own$ store.

Remarks

The resulting store has a value computed from the parent store in two steps:

  • first step: the parent configuration is transformed by the adaptParentConfig function (if specified). If adaptParentConfig is not specified, this step is skipped.
  • second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by this function.

mergeInto

function

mergeInto<T>(destination, source, levels): T

Merges source object into destination object, up to the provided number of levels.

Type Parameters
T

T

Parameters
destination

T

destination object

source

source object

undefined | T

levels

number = Infinity

number of levels to merge

Returns

T

the destination object in most cases, or the source in some cases (if the source is not undefined and either levels is smaller than 1 or the source is not an object)


Partial2Levels

type alias

Partial2Levels<T> = Partial<{ [Level1 in keyof T]: Partial<T[Level1]> }>

A utility type that makes all properties of an object type T optional, and also makes all properties of the nested objects within T optional.

Type Parameters
T

T

The object type to be transformed.


useWidget

constant

const useWidget: <W>(factory, props, defaultProps?) => WidgetSlotContext<W> = widgetFactories.useWidget

Allows to create and attach an agnos-ui/core widget to the current react component.

Type Parameters
W

W extends Widget<object, object, object, object>

Parameters
factory

WidgetFactory<W>

the widget factory

props

the widget props

undefined | Partial<WidgetProps<W>>

defaultProps?

Partial<WidgetProps<W>>

the default widget props

Returns

WidgetSlotContext<W>

the state, api and directives to track and interact with the widget


useWidgetContext

constant

const useWidgetContext: <Props>(widgetName?, defaultConfig?) => ReadableSignal<Partial<Props>> = widgetFactories.useWidgetContext

React hook that returns the widgets default configuration store.

Type Parameters
Props

Props extends object

Parameters
widgetName?

string

the name of the widget to get the configuration for

defaultConfig?

Partial<Props>

the default configuration of the widget

Returns

ReadableSignal<Partial<Props>>

the widgets default configuration store


WidgetsConfigContext

constant

const WidgetsConfigContext: Context<undefined | WidgetsConfigStore<WidgetsConfig>> = widgetFactories.WidgetsConfigContext

React context which can be used to provide or consume the widgets default configuration store.


widgetsConfigFactory

function

widgetsConfigFactory<Config>(WidgetsConfigContext): object

A factory to create the use functions and react component to allow widgets to be context-aware.

It can be used when extending the core and creating new widgets.

Type Parameters
Config

Config extends Record<string, object> = WidgetsConfig

Parameters
WidgetsConfigContext

Context<undefined | WidgetsConfigStore<Config>> = ...

the widgets config context

Returns

the use functions and react component

useWidget

useWidget: <W>(factory, props?, defaultProps?) => WidgetSlotContext<W>

Create and attach an agnos-ui/core widget to the current react component.

Type Parameters
W

W extends Widget<object, object, object, object>

Parameters
factory

WidgetFactory<W>

the widget factory

props?

Partial<WidgetProps<W>>

the widget props

defaultProps?

Partial<WidgetProps<W>>

the default widget props

Returns

WidgetSlotContext<W>

the state, api and directives to track and interact with the widget

useWidgetContext

useWidgetContext: <Props>(widgetName?, defaultConfig?) => ReadableSignal<Partial<Props>>

React hook that returns the widgets default configuration store.

Type Parameters
Props

Props extends object

Parameters
widgetName?

string

the name of the widget to get the configuration for

defaultConfig?

Partial<Props>

the default configuration of the widget

Returns

ReadableSignal<Partial<Props>>

the widgets default configuration store

WidgetsConfigContext

WidgetsConfigContext: Context<undefined | WidgetsConfigStore<Config>>

React context which can be used to provide or consume the widgets default configuration store.

WidgetsDefaultConfig

WidgetsDefaultConfig: (componentInputs) => Element

React component that provides in the React context (for all AgnosUI descendant widgets) a new widgets default configuration store that inherits from any widgets default configuration store already defined at an upper level in the React context hierarchy. It contains its own set of widgets configuration properties that override the same properties form the parent configuration.

Parameters
componentInputs

DefaultConfigInput<Config>

the react component inputs

Returns

Element

the resulting widgets default configuration store, which contains 3 additional properties that are stores: parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties). The resulting store is writable, its set function is actually the set function of the own$ store.

Remarks

The configuration is computed from the parent configuration in two steps:

  • first step: the parent configuration is transformed by the adaptParentConfig function (if specified). If adaptParentConfig is not specified, this step is skipped.
  • second step: the configuration from step 1 is merged (2-levels deep) with the properties of the component.
Example
<WidgetsDefaultConfig
  adaptParentConfig={(parentConfig) => {
    parentConfig.rating = parentConfig.rating ?? {};
    parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
    return parentConfig;
  }}
  rating={{slotStar: MyCustomSlotStar}}
/>

WidgetsConfigStore

type alias

WidgetsConfigStore<T> = WritableSignal<Partial2Levels<T>> & object

Represents a store for widget configurations with support for partial updates at two levels of depth. This store includes signals for its own state, an optional parent state, and an optional adapted parent state.

Type declaration
adaptedParent$

adaptedParent$: undefined | ReadableSignal<Partial2Levels<T>>

own$

own$: WritableSignal<Partial2Levels<T>>

parent$

parent$: undefined | WritableSignal<Partial2Levels<T>>

Type Parameters
T

T

The type of the widget configuration.


WidgetsDefaultConfig

constant

const WidgetsDefaultConfig: (componentInputs) => Element = widgetFactories.WidgetsDefaultConfig

React component that provides in the React context (for all AgnosUI descendant widgets) a new widgets default configuration store that inherits from any widgets default configuration store already defined at an upper level in the React context hierarchy. It contains its own set of widgets configuration properties that override the same properties form the parent configuration.

Parameters
componentInputs

DefaultConfigInput

the react component inputs

Returns

Element

the resulting widgets default configuration store, which contains 3 additional properties that are stores: parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties). The resulting store is writable, its set function is actually the set function of the own$ store.

Remarks

The configuration is computed from the parent configuration in two steps:

  • first step: the parent configuration is transformed by the adaptParentConfig function (if specified). If adaptParentConfig is not specified, this step is skipped.
  • second step: the configuration from step 1 is merged (2-levels deep) with the properties of the component.
Example
<WidgetsDefaultConfig
  adaptParentConfig={(parentConfig) => {
    parentConfig.rating = parentConfig.rating ?? {};
    parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
    return parentConfig;
  }}
  rating={{slotStar: MyCustomSlotStar}}
/>