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.
• T
• parent$?: WidgetsConfigStore
<T
>
optional parent widgets default configuration store.
• adaptParentConfig? = identity
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.
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.
The resulting store has a value computed from the parent store in two steps:
mergeInto<
T
>(destination
,source
,levels
):T
Merges source object into destination object, up to the provided number of levels.
• T
• destination: T
destination object
• source: undefined
| T
source object
• levels: number
= Infinity
number of levels to merge
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<
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.
• T
The object type to be transformed.
widgetsConfigFactory<
Config
>(widgetsConfigInjectionToken
):object
A factory to create the utilities to allow widgets to be context-aware.
It can be used when extending the core and creating new widgets.
• Config extends object
= WidgetsConfig
The type of the widgets configuration object.
• widgetsConfigInjectionToken: InjectionToken
<WidgetsConfigStore
<Config
>> = ...
the widgets config injection token
object
the utilities to create / manage widgets and contexts
callWidgetFactory: <
W
>(params
) =>AngularWidget
<W
>
Creates and initializes a widget using the provided factory and configuration options.
• W extends Widget
<object
, object
, object
, object
>
The type of the widget.
• params
The parameters for creating the widget.
• params.afterInit?
A callback function to be called after the widget is initialized.
• params.defaultConfig?: Partial
<WidgetProps
<W
>> | ReadableSignal
<undefined
| Partial
<WidgetProps
<W
>>> = {}
The default configuration for the widget.
• params.events?: Partial
<Pick
<WidgetProps
<W
>, keyof WidgetProps
<W
> & `on${string}`>>
The event handlers for the widget.
• params.factory: WidgetFactory
<W
>
The factory function to create the widget.
• params.slotChildren?
A function that returns the slot children for the widget.
• params.slotTemplates?
A function that returns the slot templates for the widget.
• params.widgetName?: null
| keyof Config
= null
The name of the widget configuration to inject, if any.
The initialized widget.
injectWidgetConfig: <
N
>(widgetName
) =>ReadableSignal
<undefined
|Partial
<Config
[N
]>>
Injects the configuration for a specific widget.
• N extends string
| number
| symbol
The key of the widget configuration in the Config
type.
• widgetName: N
The name of the widget whose configuration is to be injected.
ReadableSignal
<undefined
| Partial
<Config
[N
]>>
A ReadableSignal
that provides a partial configuration of the specified widget or undefined
if the configuration is not available.
injectWidgetsConfig:
InjectWidgetsConfig
<Config
>
provideWidgetsConfig: (
adaptParentConfig
?) =>FactoryProvider
Creates a provider of widgets default configuration that inherits from any widgets default configuration already defined at an upper level in the Angular dependency injection system. It contains its own set of widgets configuration properties that override the same properties form the parent configuration.
• adaptParentConfig?: AdaptParentConfig
<Config
>
optional function that receives a 2-levels copy of the widgets default configuration defined at an upper level in the Angular dependency injection system (or an empty object if there is none) 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. It is also called in an Angular injection context, so it can call the Angular inject function to get and use dependencies from the Angular dependency injection system.
DI provider to be included a list of providers
(for example at a component level or
any other level of the Angular dependency injection system)
The configuration is computed from the parent configuration in two steps:
@Component({
// ...
providers: [
provideWidgetsConfig((parentConfig) => {
// first step configuration: transforms the parent configuration
parentConfig.rating = parentConfig.rating ?? {};
parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
return parentConfig;
})
]
})
class MyComponent {
widgetsConfig = injectWidgetsConfig();
constructor() {
this.widgetsConfig.set({
// second step configuration: overrides the parent configuration
rating: {
slotStar: MyCustomSlotStar
}
});
}
// ...
}
widgetsConfigInjectionToken:
InjectionToken
<WidgetsConfigStore
<Config
>>
Dependency Injection token which can be used to provide or inject the widgets default configuration store.
widgetsConfigInjectionToken:
InjectionToken
<WidgetsConfigStore
<WidgetsConfig
>>
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.
adaptedParent$:
undefined
|ReadableSignal
<Partial2Levels
<T
>>
own$:
WritableSignal
<Partial2Levels
<T
>>
parent$:
undefined
|WritableSignal
<Partial2Levels
<T
>>
• T
The type of the widget configuration.