@agnos-ui/angular-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.
@@ -0,0 +1,50 @@
1
+ import type { Partial2Levels, Widget, WidgetFactory, WidgetProps, WidgetsConfigStore } from '@agnos-ui/core';
2
+ import type { ReadableSignal } from '@amadeus-it-group/tansu';
3
+ import type { FactoryProvider } from '@angular/core';
4
+ import { InjectionToken } from '@angular/core';
5
+ import type { AdaptPropsSlots } from './slotTypes';
6
+ import type { WithPatchSlots } from './utils';
7
+ export type WidgetsConfig = {
8
+ [WidgetName in keyof import('@agnos-ui/core').WidgetsConfig]: AdaptPropsSlots<import('@agnos-ui/core').WidgetsConfig[WidgetName]>;
9
+ };
10
+ export declare const widgetsConfigFactory: <Config extends {
11
+ [widgetName: string]: object;
12
+ } = WidgetsConfig>(widgetsConfigInjectionToken?: InjectionToken<WidgetsConfigStore<Config>>) => {
13
+ /**
14
+ * Dependency Injection token which can be used to provide or inject the widgets default configuration store.
15
+ */
16
+ widgetsConfigInjectionToken: InjectionToken<WidgetsConfigStore<Config>>;
17
+ provideWidgetsConfig: (adaptParentConfig?: ((config: Partial<{ [Level1 in keyof Config]: Partial<Config[Level1]>; }>) => Partial<{ [Level1 in keyof Config]: Partial<Config[Level1]>; }>) | undefined) => FactoryProvider;
18
+ injectWidgetsConfig: () => WidgetsConfigStore<Config>;
19
+ injectWidgetConfig: <N extends keyof Config>(widgetName: N) => ReadableSignal<Partial<Config[N]> | undefined>;
20
+ callWidgetFactory: <W extends Widget<object, object, object, object, object>>({ factory, widgetName, defaultConfig, events, }: {
21
+ factory: WidgetFactory<W>;
22
+ widgetName?: keyof Config | null | undefined;
23
+ defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined> | undefined;
24
+ events: Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}`>;
25
+ }) => WithPatchSlots<W>;
26
+ };
27
+ export declare const widgetsConfigInjectionToken: InjectionToken<WidgetsConfigStore<WidgetsConfig>>, provideWidgetsConfig: (adaptParentConfig?: ((config: Partial<{
28
+ pagination: Partial<AdaptPropsSlots<import("@agnos-ui/core").PaginationProps>>;
29
+ rating: Partial<AdaptPropsSlots<import("@agnos-ui/core").RatingProps>>;
30
+ select: Partial<AdaptPropsSlots<import("@agnos-ui/core").SelectProps<any>>>;
31
+ modal: Partial<AdaptPropsSlots<import("@agnos-ui/core").ModalProps>>;
32
+ alert: Partial<AdaptPropsSlots<import("@agnos-ui/core").AlertProps>>;
33
+ accordion: Partial<AdaptPropsSlots<import("@agnos-ui/core").AccordionProps>>;
34
+ progressbar: Partial<AdaptPropsSlots<import("@agnos-ui/core").ProgressbarProps>>;
35
+ slider: Partial<AdaptPropsSlots<import("@agnos-ui/core").SliderProps>>;
36
+ }>) => Partial<{
37
+ pagination: Partial<AdaptPropsSlots<import("@agnos-ui/core").PaginationProps>>;
38
+ rating: Partial<AdaptPropsSlots<import("@agnos-ui/core").RatingProps>>;
39
+ select: Partial<AdaptPropsSlots<import("@agnos-ui/core").SelectProps<any>>>;
40
+ modal: Partial<AdaptPropsSlots<import("@agnos-ui/core").ModalProps>>;
41
+ alert: Partial<AdaptPropsSlots<import("@agnos-ui/core").AlertProps>>;
42
+ accordion: Partial<AdaptPropsSlots<import("@agnos-ui/core").AccordionProps>>;
43
+ progressbar: Partial<AdaptPropsSlots<import("@agnos-ui/core").ProgressbarProps>>;
44
+ slider: Partial<AdaptPropsSlots<import("@agnos-ui/core").SliderProps>>;
45
+ }>) | undefined) => FactoryProvider, injectWidgetConfig: <N extends keyof import("@agnos-ui/core").WidgetsConfig>(widgetName: N) => ReadableSignal<Partial<WidgetsConfig[N]> | undefined>, injectWidgetsConfig: () => WidgetsConfigStore<WidgetsConfig>, callWidgetFactory: <W extends Widget<object, object, object, object, object>>({ factory, widgetName, defaultConfig, events, }: {
46
+ factory: WidgetFactory<W>;
47
+ widgetName?: keyof import("@agnos-ui/core").WidgetsConfig | null | undefined;
48
+ defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined> | undefined;
49
+ events: Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}`>;
50
+ }) => WithPatchSlots<W>;
@@ -1,5 +1,5 @@
1
1
  import type { OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
2
- import type { SlotContent } from './utils';
2
+ import type { SlotContent } from './slotTypes';
3
3
  import * as i0 from "@angular/core";
4
4
  export declare class SlotDirective<Props extends Record<string, any>> implements OnChanges, OnDestroy {
5
5
  slot: SlotContent<Props>;
@@ -1,7 +1,7 @@
1
1
  import type { WritableSignal } from '@amadeus-it-group/tansu';
2
2
  import type { OnInit } from '@angular/core';
3
3
  import { TemplateRef } from '@angular/core';
4
- import type { SlotContent } from './utils';
4
+ import type { SlotContent } from './slotTypes';
5
5
  import * as i0 from "@angular/core";
6
6
  export declare class SlotDefaultDirective<T extends object> implements OnInit {
7
7
  auSlotDefault: WritableSignal<{
@@ -0,0 +1,18 @@
1
+ import type { SlotContent as CoreSlotContent, Widget, WidgetFactory, WidgetProps, WidgetSlotContext, WidgetState } from '@agnos-ui/core';
2
+ import type { TemplateRef, Type } from '@angular/core';
3
+ export declare class ComponentTemplate<Props, K extends string, T extends {
4
+ [key in K]: TemplateRef<Props>;
5
+ }> {
6
+ readonly component: Type<T>;
7
+ readonly templateProp: K;
8
+ constructor(component: Type<T>, templateProp: K);
9
+ }
10
+ export type SlotContent<Props extends object = object> = CoreSlotContent<Props> | TemplateRef<Props> | Type<unknown> | ComponentTemplate<Props, any, any>;
11
+ export type AdaptSlotContentProps<Props extends Record<string, any>> = Props extends WidgetSlotContext<infer U> ? WidgetSlotContext<AdaptWidgetSlots<U>> & AdaptPropsSlots<Omit<Props, keyof WidgetSlotContext<any>>> : AdaptPropsSlots<Props>;
12
+ export type AdaptPropsSlots<Props> = Omit<Props, `slot${string}`> & {
13
+ [K in keyof Props & `slot${string}`]: Props[K] extends CoreSlotContent<infer U> ? SlotContent<AdaptSlotContentProps<U>> : Props[K];
14
+ };
15
+ export type AdaptWidgetFactories<T> = {
16
+ [K in keyof T]: T[K] extends WidgetFactory<infer U> ? WidgetFactory<AdaptWidgetSlots<U>> : T[K];
17
+ };
18
+ export type AdaptWidgetSlots<W extends Widget> = Widget<AdaptPropsSlots<WidgetProps<W>>, AdaptPropsSlots<WidgetState<W>>, AdaptWidgetFactories<W['api']>, W['actions'], W['directives']>;
@@ -1,12 +1,14 @@
1
- import type { OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
1
+ import type { OnChanges } from '@angular/core';
2
2
  import type { Directive as AgnosUIDirective } from '@agnos-ui/core';
3
3
  import * as i0 from "@angular/core";
4
- export declare class UseDirective<T> implements OnChanges, OnDestroy {
4
+ export declare const useDirectiveForHost: <T>(use?: AgnosUIDirective<T> | undefined, params?: T | undefined) => {
5
+ update: (newUse?: AgnosUIDirective<T> | undefined, newParams?: T | undefined) => Promise<void>;
6
+ };
7
+ export declare class UseDirective<T> implements OnChanges {
5
8
  #private;
6
9
  use: AgnosUIDirective<T> | undefined;
7
10
  params: T | undefined;
8
- ngOnChanges(changes: SimpleChanges): Promise<void>;
9
- ngOnDestroy(): void;
11
+ ngOnChanges(): void;
10
12
  static ɵfac: i0.ɵɵFactoryDeclaration<UseDirective<any>, never>;
11
13
  static ɵdir: i0.ɵɵDirectiveDeclaration<UseDirective<any>, "[auUse]", never, { "use": { "alias": "auUse"; "required": false; }; "params": { "alias": "auUseParams"; "required": false; }; }, {}, never, never, true, never>;
12
14
  }
package/lib/utils.d.ts CHANGED
@@ -1,95 +1,17 @@
1
- import type { SlotContent as CoreSlotContent, WidgetsConfig as CoreWidgetsConfig, Partial2Levels, Widget, WidgetFactory, WidgetProps, WidgetSlotContext, WidgetState, WidgetsConfigStore } from '@agnos-ui/core';
2
- import type { ReadableSignal, SubscribableStore } from '@amadeus-it-group/tansu';
3
- import type { FactoryProvider, SimpleChanges, TemplateRef, Type } from '@angular/core';
4
- import { InjectionToken } from '@angular/core';
5
- export declare class ComponentTemplate<Props, K extends string, T extends {
6
- [key in K]: TemplateRef<Props>;
7
- }> {
8
- readonly component: Type<T>;
9
- readonly templateProp: K;
10
- constructor(component: Type<T>, templateProp: K);
11
- }
12
- export type SlotContent<Props extends object = object> = CoreSlotContent<Props> | TemplateRef<Props> | Type<unknown> | ComponentTemplate<Props, any, any>;
13
- export type AdaptSlotContentProps<Props extends Record<string, any>> = Props extends WidgetSlotContext<infer U> ? WidgetSlotContext<AdaptWidgetSlots<U>> & AdaptPropsSlots<Omit<Props, keyof WidgetSlotContext<any>>> : AdaptPropsSlots<Props>;
14
- export type AdaptPropsSlots<Props> = Omit<Props, `slot${string}`> & {
15
- [K in keyof Props & `slot${string}`]: Props[K] extends CoreSlotContent<infer U> ? SlotContent<AdaptSlotContentProps<U>> : Props[K];
16
- };
17
- export type AdaptWidgetSlots<W extends Widget> = Widget<AdaptPropsSlots<WidgetProps<W>>, AdaptPropsSlots<WidgetState<W>>, W['api'], W['actions'], W['directives']>;
18
- export type WidgetsConfig = {
19
- [WidgetName in keyof CoreWidgetsConfig]: AdaptPropsSlots<CoreWidgetsConfig[WidgetName]>;
20
- };
21
- /**
22
- * Dependency Injection token which can be used to provide or inject the widgets default configuration store.
23
- */
24
- export declare const widgetsConfigInjectionToken: InjectionToken<WidgetsConfigStore<WidgetsConfig>>;
25
- /**
26
- * Creates a provider of widgets default configuration that inherits from any widgets default configuration already defined at an upper level
27
- * in the Angular dependency injection system. It contains its own set of widgets configuration properties that override the same properties form
28
- * the parent configuration.
29
- *
30
- * @remarks
31
- * The configuration is computed from the parent configuration in two steps:
32
- * - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
33
- * If adaptParentConfig is not specified, this step is skipped.
34
- * - second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains
35
- * an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by
36
- * {@link injectWidgetsConfig}.
37
- *
38
- * @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
39
- * defined at an upper level in the Angular dependency injection system (or an empty object if there is none) and returns the widgets
40
- * default configuration to be used.
41
- * It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
42
- * It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
43
- * It is also called in an Angular injection context, so it can call the Angular inject function to get and use dependencies from the
44
- * Angular dependency injection system.
45
-
46
- * @returns DI provider to be included a list of `providers` (for example at a component level or
47
- * any other level of the Angular dependency injection system)
48
- *
49
- * @example
50
- * ```typescript
51
- * @Component({
52
- * // ...
53
- * providers: [
54
- * provideWidgetsConfig((parentConfig) => {
55
- * // first step configuration: transforms the parent configuration
56
- * parentConfig.rating = parentConfig.rating ?? {};
57
- * parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
58
- * return parentConfig;
59
- * })
60
- * ]
61
- * })
62
- * class MyComponent {
63
- * widgetsConfig = injectWidgetsConfig();
64
- * constructor() {
65
- * this.widgetsConfig.set({
66
- * // second step configuration: overrides the parent configuration
67
- * rating: {
68
- * slotStar: MyCustomSlotStar
69
- * }
70
- * });
71
- * }
72
- * // ...
73
- * }
74
- * ```
75
- */
76
- export declare const provideWidgetsConfig: (adaptParentConfig?: ((config: Partial2Levels<WidgetsConfig>) => Partial2Levels<WidgetsConfig>) | undefined) => FactoryProvider;
77
- /**
78
- * Returns the widgets default configuration store that was provided in the current injection context.
79
- * Throws if the no widgets default configuration store was provided.
80
- *
81
- * @remarks
82
- * This function must be called from an injection context, such as a constructor, a factory function, a field initializer or
83
- * a function used with {@link https://angular.io/api/core/runInInjectionContext | runInInjectionContext}.
84
- *
85
- * @returns the widgets default configuration store.
86
- */
87
- export declare const injectWidgetsConfig: () => WidgetsConfigStore<WidgetsConfig>;
88
- export type WithPatchSlots<W extends Widget> = AdaptWidgetSlots<W> & {
1
+ import type { Widget, WidgetFactory, WidgetProps } from '@agnos-ui/core';
2
+ import type { ReadableSignal } from '@amadeus-it-group/tansu';
3
+ import type { Signal, SimpleChanges, TemplateRef } from '@angular/core';
4
+ import type { SlotContent } from './slotTypes';
5
+ export declare const toAngularSignal: <T>(tansuSignal: ReadableSignal<T>) => Signal<T>;
6
+ export type WithPatchSlots<W extends Widget> = W & {
89
7
  patchSlots(slots: {
90
- [K in keyof WidgetProps<W> & `slot${string}`]: WidgetProps<W>[K] extends CoreSlotContent<infer U> ? TemplateRef<AdaptSlotContentProps<U>> | undefined : never;
8
+ [K in keyof WidgetProps<W> & `slot${string}`]: WidgetProps<W>[K] extends SlotContent<infer U> ? TemplateRef<U> | undefined : never;
91
9
  }): void;
92
10
  };
93
- 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>;
11
+ export declare const callWidgetFactoryWithConfig: <W extends Widget<object, object, object, object, object>>({ factory, defaultConfig, widgetConfig, events, }: {
12
+ factory: WidgetFactory<W>;
13
+ defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined> | undefined;
14
+ widgetConfig?: ReadableSignal<Partial<WidgetProps<W>> | undefined> | null | undefined;
15
+ events: Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}`>;
16
+ }) => WithPatchSlots<W>;
94
17
  export declare function patchSimpleChanges(patchFn: (obj: any) => void, changes: SimpleChanges): void;
95
- export type ExtractStoreType<T> = T extends SubscribableStore<infer U> ? U : never;
package/package.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "@angular/core": "*"
7
7
  },
8
8
  "dependencies": {
9
- "@agnos-ui/core": "0.0.1-alpha.1",
10
- "@amadeus-it-group/tansu": "0.0.22",
9
+ "@agnos-ui/core": "0.0.1-alpha.4",
10
+ "@amadeus-it-group/tansu": "0.0.23",
11
11
  "tslib": "^2.6.2"
12
12
  },
13
13
  "sideEffects": false,
14
- "version": "0.0.1-alpha.1",
14
+ "version": "0.0.1-alpha.4",
15
15
  "module": "fesm2022/agnos-ui-angular-headless.mjs",
16
16
  "typings": "index.d.ts",
17
17
  "exports": {
@@ -42,6 +42,7 @@
42
42
  "alert",
43
43
  "modal",
44
44
  "pagination",
45
- "rating"
45
+ "rating",
46
+ "slider"
46
47
  ]
47
48
  }
package/public-api.d.ts CHANGED
@@ -1,34 +1,52 @@
1
1
  export * from '@agnos-ui/core';
2
+ export * from './lib/config';
3
+ export type { WidgetsConfig } from './lib/config';
2
4
  export * from './lib/slot.directive';
3
5
  export * from './lib/slotDefault.directive';
6
+ export * from './lib/slotTypes';
7
+ export type { SlotContent } from './lib/slotTypes';
4
8
  export * from './lib/use.directive';
5
9
  export * from './lib/utils';
6
- export type { SlotContent, WidgetsConfig } from './lib/utils';
7
- import type { WidgetProps, WidgetState } from '@agnos-ui/core';
8
- import type { AdaptSlotContentProps, AdaptWidgetSlots } from './lib/utils';
10
+ import type { PropsConfig, WidgetFactory, WidgetProps, WidgetState } from '@agnos-ui/core';
11
+ import type { AdaptSlotContentProps, AdaptWidgetSlots } from './lib/slotTypes';
9
12
  export type AccordionWidget = AdaptWidgetSlots<import('@agnos-ui/core').AccordionWidget>;
10
13
  export type AccordionProps = WidgetProps<AccordionWidget>;
11
14
  export type AccordionState = WidgetState<AccordionWidget>;
15
+ export type AccordionApi = AccordionWidget['api'];
12
16
  export type AccordionItemWidget = AdaptWidgetSlots<import('@agnos-ui/core').AccordionItemWidget>;
13
17
  export type AccordionItemProps = WidgetProps<AccordionItemWidget>;
14
18
  export type AccordionItemState = WidgetState<AccordionItemWidget>;
15
19
  export type AccordionItemContext = AdaptSlotContentProps<import('@agnos-ui/core').AccordionItemContext>;
20
+ export declare const createAccordion: WidgetFactory<AccordionWidget>;
16
21
  export type AlertWidget = AdaptWidgetSlots<import('@agnos-ui/core').AlertWidget>;
17
22
  export type AlertProps = WidgetProps<AlertWidget>;
18
23
  export type AlertState = WidgetState<AlertWidget>;
19
24
  export type AlertContext = AdaptSlotContentProps<import('@agnos-ui/core').AlertContext>;
25
+ export declare const createAlert: WidgetFactory<AlertWidget>;
20
26
  export type ModalWidget = AdaptWidgetSlots<import('@agnos-ui/core').ModalWidget>;
21
27
  export type ModalProps = WidgetProps<ModalWidget>;
22
28
  export type ModalState = WidgetState<ModalWidget>;
23
29
  export type ModalContext = AdaptSlotContentProps<import('@agnos-ui/core').ModalContext>;
30
+ export declare const createModal: WidgetFactory<ModalWidget>;
24
31
  export type PaginationWidget = AdaptWidgetSlots<import('@agnos-ui/core').PaginationWidget>;
25
32
  export type PaginationProps = WidgetProps<PaginationWidget>;
26
33
  export type PaginationState = WidgetState<PaginationWidget>;
27
34
  export type PaginationContext = AdaptSlotContentProps<import('@agnos-ui/core').PaginationContext>;
28
35
  export type PaginationNumberContext = AdaptSlotContentProps<import('@agnos-ui/core').PaginationNumberContext>;
36
+ export declare const createPagination: WidgetFactory<PaginationWidget>;
29
37
  export type RatingWidget = AdaptWidgetSlots<import('@agnos-ui/core').RatingWidget>;
30
38
  export type RatingProps = WidgetProps<RatingWidget>;
31
39
  export type RatingState = WidgetState<RatingWidget>;
40
+ export declare const createRating: WidgetFactory<RatingWidget>;
32
41
  export type SelectWidget<Item> = AdaptWidgetSlots<import('@agnos-ui/core').SelectWidget<Item>>;
33
42
  export type SelectProps<Item> = WidgetProps<SelectWidget<Item>>;
34
43
  export type SelectState<Item> = WidgetState<SelectWidget<Item>>;
44
+ export declare const createSelect: <Item>(propsConfig?: PropsConfig<SelectProps<Item>>) => SelectWidget<Item>;
45
+ export type SliderWidget = AdaptWidgetSlots<import('@agnos-ui/core').SliderWidget>;
46
+ export type SliderProps = WidgetProps<SliderWidget>;
47
+ export type SliderState = WidgetState<SliderWidget>;
48
+ export type ProgressbarWidget = AdaptWidgetSlots<import('@agnos-ui/core').ProgressbarWidget>;
49
+ export type ProgressbarProps = WidgetProps<ProgressbarWidget>;
50
+ export type ProgressbarState = WidgetState<ProgressbarWidget>;
51
+ export type ProgressbarContext = AdaptSlotContentProps<import('@agnos-ui/core').ProgressbarContext>;
52
+ export declare const createProgressbar: WidgetFactory<ProgressbarWidget>;