@agnos-ui/angular-headless
Advanced tools
Comparing version 0.0.1-alpha.1 to 0.0.1-alpha.3
import type { OnChanges, OnDestroy, SimpleChanges } from '@angular/core'; | ||
import type { SlotContent } from './utils'; | ||
import type { SlotContent } from './slotTypes'; | ||
import * as i0 from "@angular/core"; | ||
@@ -4,0 +4,0 @@ export declare class SlotDirective<Props extends Record<string, any>> implements OnChanges, OnDestroy { |
import type { WritableSignal } from '@amadeus-it-group/tansu'; | ||
import type { OnInit } from '@angular/core'; | ||
import { TemplateRef } from '@angular/core'; | ||
import type { SlotContent } from './utils'; | ||
import type { SlotContent } from './slotTypes'; | ||
import * as i0 from "@angular/core"; | ||
@@ -6,0 +6,0 @@ export declare class SlotDefaultDirective<T extends object> implements OnInit { |
@@ -1,95 +0,16 @@ | ||
import type { SlotContent as CoreSlotContent, WidgetsConfig as CoreWidgetsConfig, Partial2Levels, Widget, WidgetFactory, WidgetProps, WidgetSlotContext, WidgetState, WidgetsConfigStore } from '@agnos-ui/core'; | ||
import type { ReadableSignal, SubscribableStore } from '@amadeus-it-group/tansu'; | ||
import type { FactoryProvider, SimpleChanges, TemplateRef, Type } from '@angular/core'; | ||
import { InjectionToken } from '@angular/core'; | ||
export declare class ComponentTemplate<Props, K extends string, T extends { | ||
[key in K]: TemplateRef<Props>; | ||
}> { | ||
readonly component: Type<T>; | ||
readonly templateProp: K; | ||
constructor(component: Type<T>, templateProp: K); | ||
} | ||
export type SlotContent<Props extends object = object> = CoreSlotContent<Props> | TemplateRef<Props> | Type<unknown> | ComponentTemplate<Props, any, any>; | ||
export type AdaptSlotContentProps<Props extends Record<string, any>> = Props extends WidgetSlotContext<infer U> ? WidgetSlotContext<AdaptWidgetSlots<U>> & AdaptPropsSlots<Omit<Props, keyof WidgetSlotContext<any>>> : AdaptPropsSlots<Props>; | ||
export type AdaptPropsSlots<Props> = Omit<Props, `slot${string}`> & { | ||
[K in keyof Props & `slot${string}`]: Props[K] extends CoreSlotContent<infer U> ? SlotContent<AdaptSlotContentProps<U>> : Props[K]; | ||
}; | ||
export type AdaptWidgetSlots<W extends Widget> = Widget<AdaptPropsSlots<WidgetProps<W>>, AdaptPropsSlots<WidgetState<W>>, W['api'], W['actions'], W['directives']>; | ||
export type WidgetsConfig = { | ||
[WidgetName in keyof CoreWidgetsConfig]: AdaptPropsSlots<CoreWidgetsConfig[WidgetName]>; | ||
}; | ||
/** | ||
* Dependency Injection token which can be used to provide or inject the widgets default configuration store. | ||
*/ | ||
export declare const widgetsConfigInjectionToken: InjectionToken<WidgetsConfigStore<WidgetsConfig>>; | ||
/** | ||
* 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. | ||
* | ||
* @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 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 | ||
* {@link injectWidgetsConfig}. | ||
* | ||
* @param adaptParentConfig - 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. | ||
* @returns 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) | ||
* | ||
* @example | ||
* ```typescript | ||
* @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 | ||
* } | ||
* }); | ||
* } | ||
* // ... | ||
* } | ||
* ``` | ||
*/ | ||
export declare const provideWidgetsConfig: (adaptParentConfig?: ((config: Partial2Levels<WidgetsConfig>) => Partial2Levels<WidgetsConfig>) | undefined) => FactoryProvider; | ||
/** | ||
* Returns the widgets default configuration store that was provided in the current injection context. | ||
* Throws if the no widgets default configuration store was provided. | ||
* | ||
* @remarks | ||
* This function must be called from an injection context, such as a constructor, a factory function, a field initializer or | ||
* a function used with {@link https://angular.io/api/core/runInInjectionContext | runInInjectionContext}. | ||
* | ||
* @returns the widgets default configuration store. | ||
*/ | ||
export declare const injectWidgetsConfig: () => WidgetsConfigStore<WidgetsConfig>; | ||
export type WithPatchSlots<W extends Widget> = AdaptWidgetSlots<W> & { | ||
import type { Widget, WidgetFactory, WidgetProps } from '@agnos-ui/core'; | ||
import type { ReadableSignal } from '@amadeus-it-group/tansu'; | ||
import type { SimpleChanges, TemplateRef } from '@angular/core'; | ||
import type { SlotContent } from './slotTypes'; | ||
export type WithPatchSlots<W extends Widget> = W & { | ||
patchSlots(slots: { | ||
[K in keyof WidgetProps<W> & `slot${string}`]: WidgetProps<W>[K] extends CoreSlotContent<infer U> ? TemplateRef<AdaptSlotContentProps<U>> | undefined : never; | ||
[K in keyof WidgetProps<W> & `slot${string}`]: WidgetProps<W>[K] extends SlotContent<infer U> ? TemplateRef<U> | undefined : never; | ||
}): void; | ||
}; | ||
export declare const callWidgetFactory: <W extends Widget<object, object, object, object, object>>(factory: WidgetFactory<W>, widgetName: keyof WidgetsConfig | null, defaultConfig?: Partial<AdaptPropsSlots<WidgetProps<W>>> | ReadableSignal<Partial<AdaptPropsSlots<WidgetProps<W>>>>) => WithPatchSlots<W>; | ||
export declare const callWidgetFactoryWithConfig: <W extends Widget<object, object, object, object, object>>({ factory, defaultConfig, widgetConfig, events, }: { | ||
factory: WidgetFactory<W>; | ||
defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined> | undefined; | ||
widgetConfig?: ReadableSignal<Partial<WidgetProps<W>> | undefined> | null | undefined; | ||
events: Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}`>; | ||
}) => WithPatchSlots<W>; | ||
export declare function patchSimpleChanges(patchFn: (obj: any) => void, changes: SimpleChanges): void; | ||
export type ExtractStoreType<T> = T extends SubscribableStore<infer U> ? U : never; |
@@ -9,8 +9,8 @@ { | ||
"dependencies": { | ||
"@agnos-ui/core": "0.0.1-alpha.1", | ||
"@amadeus-it-group/tansu": "0.0.22", | ||
"@agnos-ui/core": "0.0.1-alpha.3", | ||
"@amadeus-it-group/tansu": "0.0.23", | ||
"tslib": "^2.6.2" | ||
}, | ||
"sideEffects": false, | ||
"version": "0.0.1-alpha.1", | ||
"version": "0.0.1-alpha.3", | ||
"module": "fesm2022/agnos-ui-angular-headless.mjs", | ||
@@ -17,0 +17,0 @@ "typings": "index.d.ts", |
@@ -5,9 +5,13 @@ export * from '@agnos-ui/core'; | ||
export * from './lib/use.directive'; | ||
export * from './lib/slotTypes'; | ||
export * from './lib/utils'; | ||
export type { SlotContent, WidgetsConfig } from './lib/utils'; | ||
import type { WidgetProps, WidgetState } from '@agnos-ui/core'; | ||
import type { AdaptSlotContentProps, AdaptWidgetSlots } from './lib/utils'; | ||
export * from './lib/config'; | ||
import type { PropsConfig, WidgetFactory, WidgetProps, WidgetState } from '@agnos-ui/core'; | ||
import type { AdaptSlotContentProps, AdaptWidgetSlots } from './lib/slotTypes'; | ||
export type { SlotContent } from './lib/slotTypes'; | ||
export type { WidgetsConfig } from './lib/config'; | ||
export type AccordionWidget = AdaptWidgetSlots<import('@agnos-ui/core').AccordionWidget>; | ||
export type AccordionProps = WidgetProps<AccordionWidget>; | ||
export type AccordionState = WidgetState<AccordionWidget>; | ||
export type AccordionApi = AccordionWidget['api']; | ||
export type AccordionItemWidget = AdaptWidgetSlots<import('@agnos-ui/core').AccordionItemWidget>; | ||
@@ -17,2 +21,3 @@ export type AccordionItemProps = WidgetProps<AccordionItemWidget>; | ||
export type AccordionItemContext = AdaptSlotContentProps<import('@agnos-ui/core').AccordionItemContext>; | ||
export declare const createAccordion: WidgetFactory<AccordionWidget>; | ||
export type AlertWidget = AdaptWidgetSlots<import('@agnos-ui/core').AlertWidget>; | ||
@@ -22,2 +27,3 @@ export type AlertProps = WidgetProps<AlertWidget>; | ||
export type AlertContext = AdaptSlotContentProps<import('@agnos-ui/core').AlertContext>; | ||
export declare const createAlert: WidgetFactory<AlertWidget>; | ||
export type ModalWidget = AdaptWidgetSlots<import('@agnos-ui/core').ModalWidget>; | ||
@@ -27,2 +33,3 @@ export type ModalProps = WidgetProps<ModalWidget>; | ||
export type ModalContext = AdaptSlotContentProps<import('@agnos-ui/core').ModalContext>; | ||
export declare const createModal: WidgetFactory<ModalWidget>; | ||
export type PaginationWidget = AdaptWidgetSlots<import('@agnos-ui/core').PaginationWidget>; | ||
@@ -33,7 +40,15 @@ export type PaginationProps = WidgetProps<PaginationWidget>; | ||
export type PaginationNumberContext = AdaptSlotContentProps<import('@agnos-ui/core').PaginationNumberContext>; | ||
export declare const createPagination: WidgetFactory<PaginationWidget>; | ||
export type RatingWidget = AdaptWidgetSlots<import('@agnos-ui/core').RatingWidget>; | ||
export type RatingProps = WidgetProps<RatingWidget>; | ||
export type RatingState = WidgetState<RatingWidget>; | ||
export declare const createRating: WidgetFactory<RatingWidget>; | ||
export type SelectWidget<Item> = AdaptWidgetSlots<import('@agnos-ui/core').SelectWidget<Item>>; | ||
export type SelectProps<Item> = WidgetProps<SelectWidget<Item>>; | ||
export type SelectState<Item> = WidgetState<SelectWidget<Item>>; | ||
export declare const createSelect: <Item>(propsConfig?: PropsConfig<SelectProps<Item>>) => SelectWidget<Item>; | ||
export type ProgressbarWidget = AdaptWidgetSlots<import('@agnos-ui/core').ProgressbarWidget>; | ||
export type ProgressbarProps = WidgetProps<ProgressbarWidget>; | ||
export type ProgressbarState = WidgetState<ProgressbarWidget>; | ||
export type ProgressbarContext = AdaptSlotContentProps<import('@agnos-ui/core').ProgressbarContext>; | ||
export declare const createProgressbar: WidgetFactory<ProgressbarWidget>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
136131
20
1061
+ Added@agnos-ui/core@0.0.1-alpha.3(transitive)
+ Added@amadeus-it-group/tansu@0.0.23(transitive)
- Removed@agnos-ui/core@0.0.1-alpha.1(transitive)
- Removed@amadeus-it-group/tansu@0.0.22(transitive)
Updated@agnos-ui/core@0.0.1-alpha.3