xt-components 0.4.1 → 0.4.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.
@@ -4,6 +4,8 @@ import { XtComponent, XtComponentOutput } from '../xt-component';
4
4
  import { XtContext, XtDisplayMode } from '../xt-context';
5
5
  import { FormGroup } from '@angular/forms';
6
6
  import { XtResolverService } from '../angular/xt-resolver.service';
7
+ import { XtBaseOutput } from '../output/xt-base-output';
8
+ import { XtBaseInput } from '../output/xt-base-input';
7
9
  import * as i0 from "@angular/core";
8
10
  /**
9
11
  * Offers a nice and easy to dynamically embed a component.
@@ -18,13 +20,17 @@ export declare class XtRenderComponent<T> implements AfterViewInit {
18
20
  value: import("@angular/core").ModelSignal<T | undefined>;
19
21
  formGroup: import("@angular/core").InputSignal<FormGroup<any> | undefined>;
20
22
  subName: import("@angular/core").InputSignal<string | undefined>;
23
+ outputsObject: XtBaseOutput;
24
+ inputs: import("@angular/core").InputSignal<XtBaseInput | undefined>;
21
25
  outputs: import("@angular/core").OutputEmitterRef<XtComponentOutput>;
22
- hasOutputs: boolean;
23
26
  outlet: Signal<NgComponentOutlet<any>>;
24
27
  constructor();
25
28
  context: Signal<XtContext<any>>;
26
29
  type: Signal<Type<XtComponent<T>> | null>;
30
+ /**
31
+ * Transfers the input and outputs from the host to the rendered component
32
+ */
27
33
  ngAfterViewInit(): void;
28
34
  static ɵfac: i0.ɵɵFactoryDeclaration<XtRenderComponent<any>, never>;
29
- static ɵcmp: i0.ɵɵComponentDeclaration<XtRenderComponent<any>, "xt-render", never, { "componentType": { "alias": "componentType"; "required": false; "isSignal": true; }; "displayMode": { "alias": "displayMode"; "required": true; "isSignal": true; }; "valueType": { "alias": "valueType"; "required": false; "isSignal": true; }; "value": { "alias": "value"; "required": false; "isSignal": true; }; "formGroup": { "alias": "formGroup"; "required": false; "isSignal": true; }; "subName": { "alias": "subName"; "required": false; "isSignal": true; }; }, { "value": "valueChange"; "outputs": "outputs"; }, never, never, true, never>;
35
+ static ɵcmp: i0.ɵɵComponentDeclaration<XtRenderComponent<any>, "xt-render", never, { "componentType": { "alias": "componentType"; "required": false; "isSignal": true; }; "displayMode": { "alias": "displayMode"; "required": true; "isSignal": true; }; "valueType": { "alias": "valueType"; "required": false; "isSignal": true; }; "value": { "alias": "value"; "required": false; "isSignal": true; }; "formGroup": { "alias": "formGroup"; "required": false; "isSignal": true; }; "subName": { "alias": "subName"; "required": false; "isSignal": true; }; "inputs": { "alias": "inputs"; "required": false; "isSignal": true; }; }, { "value": "valueChange"; "outputs": "outputs"; }, never, never, true, never>;
30
36
  }
@@ -1,11 +1,11 @@
1
1
  import { XtPluginRegistry } from "../registry/xt-plugin-registry";
2
- import { XtTypeResolver } from "../type/xt-type-resolver";
2
+ import { XtTypeResolver } from "xt-type";
3
3
  import { XtContext } from "../xt-context";
4
4
  import { XtResolvedComponent } from "../xt-resolved-component";
5
5
  import { XtResolver } from "./xt-resolver";
6
6
  export declare class XtRegistryResolver implements XtResolver {
7
7
  registry: XtPluginRegistry;
8
- typeResolver: XtTypeResolver<any>;
9
- constructor(registry: XtPluginRegistry, typeResolver: XtTypeResolver<any>);
8
+ typeResolver: XtTypeResolver;
9
+ constructor(registry: XtPluginRegistry, typeResolver: XtTypeResolver);
10
10
  resolve<T>(baseContext: XtContext<T>, subName?: string): XtResolvedComponent | null;
11
11
  }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Wrapper around xt-store manager: You can use it to check if xt-store is included or not, and decide what to do
3
+ *
4
+ * This allow plugins to potentially use xt-store whenever included in the applications running the plugin
5
+ */
6
+ import { Observable } from 'rxjs';
7
+ export declare class StoreSupport {
8
+ protected static testStoreManager?: IStoreManager;
9
+ static isStoreManagerAvailable(): boolean;
10
+ static getStoreManager(): IStoreManager;
11
+ static setTestStoreManager(testStoreManager: IStoreManager): void;
12
+ }
13
+ /**
14
+ * Interface definition for xt-store component.
15
+ * We re-define them here to avoid importing xt-store in all plugins that don't need it.
16
+ */
17
+ export interface IDataTransformer<T> {
18
+ /**
19
+ * Enable transformation of data right after it has been loaded from the store
20
+ * @param source
21
+ */
22
+ postLoadingTransformation(source: any[]): T[];
23
+ }
24
+ export interface IDocumentInfo {
25
+ documentName: string;
26
+ isUrl: boolean;
27
+ documentId?: string;
28
+ }
29
+ export interface IStoreProvider<T> {
30
+ storeEntity(name: string, entity: T): Promise<T>;
31
+ /**
32
+ * Rejects the promise if the entity is not found
33
+ * @param name
34
+ * @param key
35
+ */
36
+ safeLoadEntity(name: string, key: any): Promise<T>;
37
+ loadEntity(name: string, key: any): Promise<T | undefined>;
38
+ deleteEntity(name: string, key: any): Promise<boolean>;
39
+ searchEntities(name: string, ...criteria: any[]): Observable<Array<T>>;
40
+ searchAndPrepareEntities(name: string, sort?: any, groupBy?: any, transformer?: IDataTransformer<T>, ...criteria: any[]): Observable<any>;
41
+ canStoreDocument(): boolean;
42
+ /**
43
+ * Upload one document to a server store and returns the url or the id needed to retrieve them.
44
+ * @param toStore
45
+ * @param position
46
+ */
47
+ storeDocument(toStore: File): Promise<IDocumentInfo>;
48
+ /**
49
+ * Upload documents to a server store and returns the url or the id needed to retrieve them.
50
+ * @param toStore
51
+ * @param position
52
+ */
53
+ storeDocuments(toStore: File[]): Observable<IDocumentInfo>;
54
+ }
55
+ export interface IStoreManager {
56
+ getProvider<T = never>(name?: string): IStoreProvider<T> | undefined;
57
+ getProviderSafe<T = never>(name?: string): IStoreProvider<T>;
58
+ getDefaultProvider<T = never>(): IStoreProvider<T> | undefined;
59
+ getDefaultProviderSafe<T = never>(): IStoreProvider<T>;
60
+ }
@@ -0,0 +1,36 @@
1
+ import { Observable } from 'rxjs';
2
+ import { IDataTransformer, IDocumentInfo, IStoreManager, IStoreProvider } from '../store/store-support';
3
+ /**
4
+ * A very light and not 100% compatible storemanager in case you are not using xt-store.
5
+ * It can emulate XtStoreManager to some extends for doing some tests
6
+ */
7
+ export declare class StoreTestHelper {
8
+ static ensureTestProviderOnly(): void;
9
+ }
10
+ export declare class TestStoreManager implements IStoreManager {
11
+ protected defaultProvider: TestStoreProvider<never>;
12
+ getProvider<T = never>(name?: string): IStoreProvider<T> | undefined;
13
+ getProviderSafe<T = never>(name?: string): IStoreProvider<T>;
14
+ getDefaultProvider<T = never>(): IStoreProvider<T> | undefined;
15
+ getDefaultProviderSafe<T = never>(): IStoreProvider<T>;
16
+ }
17
+ export declare class TestStoreProvider<T = never> implements IStoreProvider<T> {
18
+ protected data: Map<string, Map<string, any>>;
19
+ protected getOrCreateArray(name: string): Map<string, any>;
20
+ protected extractKey(value: any): string;
21
+ storeEntity(name: string, entity: T): Promise<T>;
22
+ safeLoadEntity(name: string, key: any): Promise<T>;
23
+ loadEntity(name: string, key: any): Promise<T | undefined>;
24
+ deleteEntity(name: string, key: any): Promise<boolean>;
25
+ searchEntities(name: string, ...criteria: any[]): Observable<T[]>;
26
+ searchAndPrepareEntities(name: string, sort?: any, groupBy?: any, transformer?: IDataTransformer<T> | undefined, ...criteria: any[]): Observable<any>;
27
+ canStoreDocument(): boolean;
28
+ storeDocument(toStore: File): Promise<IDocumentInfo>;
29
+ storeDocuments(toStore: File[]): Observable<IDocumentInfo>;
30
+ }
31
+ export declare class TestDocumentInfo implements IDocumentInfo {
32
+ documentName: string;
33
+ isUrl: boolean;
34
+ documentId?: string;
35
+ constructor(documentName: string, isUrl: boolean, documentId?: string);
36
+ }
@@ -0,0 +1,4 @@
1
+ import { FormGroup } from '@angular/forms';
2
+ export declare function updateFormGroupWithValue(formGroup: FormGroup, value: {
3
+ [key: string]: any;
4
+ }): void;
@@ -1,20 +1,22 @@
1
- import { InputSignal, OutputEmitterRef, Signal } from '@angular/core';
1
+ import { InputSignal, OutputEmitterRef } from '@angular/core';
2
2
  import { XtContext } from './xt-context';
3
3
  import { FormGroup } from '@angular/forms';
4
4
  export type XtComponent<T = any> = {
5
5
  context: InputSignal<XtContext<T>>;
6
+ inputsObject?: XtComponentInput;
7
+ outputsObject?: XtComponentOutput;
8
+ inputs?: InputSignal<XtComponentInput>;
6
9
  outputs?: OutputEmitterRef<XtComponentOutput>;
7
- /**
8
- * Does the component provides Output or not ?
9
- * @protected
10
- */
11
- hasOutputs?: boolean;
12
10
  isInForm(): boolean;
13
11
  formControlName(): string | undefined;
14
12
  formGroup(): FormGroup;
15
13
  formGroupIfAny(): FormGroup | undefined;
16
14
  };
17
15
  export type XtOutputType = 'valueSelected';
16
+ export type XtInputType = 'valueSelected';
18
17
  export type XtComponentOutput = {
19
- [key in XtOutputType]: Signal<any | null> | undefined;
18
+ [key in XtOutputType]: OutputEmitterRef<any> | undefined;
19
+ };
20
+ export type XtComponentInput = {
21
+ [key in XtInputType]: InputSignal<any> | undefined;
20
22
  };
@@ -1,5 +1,5 @@
1
1
  import { FormGroup } from '@angular/forms';
2
- import { XtTypeResolver } from './type/xt-type-resolver';
2
+ import { XtTypeResolver } from 'xt-type';
3
3
  import { Signal, WritableSignal } from '@angular/core';
4
4
  /**
5
5
  * A XtContext provides all the necessary information for an ng-extended component to operate. It is passed from parent to child component and pass
@@ -20,10 +20,11 @@ export type XtContext<T> = {
20
20
  formControlNameOrNull(): string | null;
21
21
  formControlValue(): any | null;
22
22
  subValue(subName?: string): T | null | undefined;
23
- subContext(subName: string | undefined | null, subType?: string, typeResolver?: XtTypeResolver<XtContext<T>> | null): XtContext<any>;
23
+ subContext(subName: string | undefined | null, subType?: string, typeResolver?: XtTypeResolver | null): XtContext<any>;
24
24
  elementSetContext(subElement: any): XtContext<any>;
25
25
  displayValue: Signal<T | null>;
26
26
  setDisplayValue(newValue: T | null | undefined, type?: string): XtContext<T>;
27
+ setFormValue(newValue: T | null | undefined): boolean;
27
28
  value(): T | null | undefined;
28
29
  valueType?: string;
29
30
  toString(): string;
@@ -72,13 +73,14 @@ export declare class XtBaseContext<T> implements XtContext<T> {
72
73
  */
73
74
  protected updateSubDisplayValue(subName: string, subValue: any): void;
74
75
  formControlValue(): T | null | undefined;
76
+ setFormValue(newValue: T | null | undefined): boolean;
75
77
  /**
76
78
  * Returns the context associated with a specific element in a set.
77
79
  * Value must be an array.
78
80
  * @param elementIndex
79
81
  */
80
82
  elementSetContext(elementIndex: number): XtContext<any>;
81
- subContext(subName: string | undefined | null, subType?: string, typeResolver?: XtTypeResolver<XtContext<T>> | null): XtContext<any>;
83
+ subContext(subName: string | undefined | null, subType?: string, typeResolver?: XtTypeResolver | null): XtContext<any>;
82
84
  formGroup(): FormGroup | undefined;
83
85
  toString(): string;
84
86
  }
@@ -1,22 +1,19 @@
1
- import { InputSignal, OutputEmitterRef } from '@angular/core';
1
+ import { OnInit } from '@angular/core';
2
2
  import { AbstractControl, FormGroup } from '@angular/forms';
3
3
  import { XtContext } from '../xt-context';
4
- import { XtComponent, XtComponentOutput, XtOutputType } from '../xt-component';
4
+ import { XtComponent, XtComponentOutput } from '../xt-component';
5
5
  import { XtBaseOutput } from '../output/xt-base-output';
6
+ import { XtBaseInput } from '../output/xt-base-input';
6
7
  import * as i0 from "@angular/core";
7
8
  /**
8
9
  * An XtSimpleComponent just displays the given value or element in a form.
9
10
  * If you need to dynamically embed other XtComponents to display sub elements, then please use the XtCompositeComponent
10
11
  */
11
- export declare class XtSimpleComponent<T = any> implements XtComponent<T> {
12
- context: InputSignal<XtContext<T>>;
13
- outputs: OutputEmitterRef<XtComponentOutput>;
14
- /**
15
- * Does the component provides Output or not ?
16
- * @protected
17
- */
18
- hasOutputs: boolean;
19
- protected outputElement?: XtBaseOutput;
12
+ export declare class XtSimpleComponent<T = any> implements XtComponent<T>, OnInit {
13
+ context: import("@angular/core").InputSignal<XtContext<T>>;
14
+ outputsObject: XtBaseOutput;
15
+ inputsObject: XtBaseInput;
16
+ outputs: import("@angular/core").OutputEmitterRef<XtComponentOutput>;
20
17
  isInForm: import("@angular/core").Signal<boolean>;
21
18
  formControlNameIfAny: import("@angular/core").Signal<string | undefined>;
22
19
  formGroupIfAny: import("@angular/core").Signal<FormGroup<any> | undefined>;
@@ -26,6 +23,7 @@ export declare class XtSimpleComponent<T = any> implements XtComponent<T> {
26
23
  */
27
24
  componentNameInForm: import("@angular/core").Signal<string>;
28
25
  constructor();
26
+ ngOnInit(): void;
29
27
  manageFormControl<T>(ctrlName: string): AbstractControl<T> | undefined;
30
28
  safelyGetSubName: import("@angular/core").Signal<string>;
31
29
  /**
@@ -36,7 +34,11 @@ export declare class XtSimpleComponent<T = any> implements XtComponent<T> {
36
34
  componentDescriptor(): string;
37
35
  getValue: import("@angular/core").Signal<T | null | undefined>;
38
36
  displayValue: import("@angular/core").Signal<T | null>;
39
- protected emitOutput(outputName: XtOutputType, newValue: any): void;
37
+ /**
38
+ * This is where components can assign their output() and input() into the XtComponent inputs and outputs member
39
+ * @protected
40
+ */
41
+ protected setupInputOutput(): void;
40
42
  static ɵfac: i0.ɵɵFactoryDeclaration<XtSimpleComponent<any>, never>;
41
43
  static ɵcmp: i0.ɵɵComponentDeclaration<XtSimpleComponent<any>, "ng-component", never, { "context": { "alias": "context"; "required": true; "isSignal": true; }; }, { "outputs": "outputs"; }, never, never, true, never>;
42
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xt-components",
3
- "version": "0.4.1",
3
+ "version": "0.4.4",
4
4
  "peerDependencies": {
5
5
  "@angular/animations": "^18.1.2",
6
6
  "@angular/common": "^18.1.2",
package/public-api.d.ts CHANGED
@@ -4,12 +4,16 @@ export * from './lib/xt-resolved-component';
4
4
  export * from './lib/resolver/xt-resolver';
5
5
  export * from './lib/registry/xt-plugin-registry';
6
6
  export * from './lib/plugin/xt-plugin-info';
7
+ export * from './globals';
7
8
  export * from './lib/angular/xt-tokens';
8
9
  export * from './lib/angular/xt-resolver.service';
9
10
  export * from './lib/render/xt-render.component';
10
11
  export * from './lib/render/xt-render-sub.component';
11
12
  export * from './lib/xt-simple/xt-simple.component';
12
13
  export * from './lib/xt-composite/xt-composite.component';
13
- export * from './lib/type/xt-type-resolver';
14
+ export * from './lib/angular/message-handler';
15
+ export * from './lib/store/store-support';
16
+ export * from './lib/type/type-helper';
14
17
  export * from './lib/test/xt-unit-test-helper';
15
18
  export * from './lib/test/xt-test-helper-components';
19
+ export * from './lib/test/store-test-helper';
@@ -1,42 +0,0 @@
1
- import { FormGroup } from '@angular/forms';
2
- import { XtTypeInfo } from "../plugin/xt-plugin-info";
3
- import { XtContext } from '../xt-context';
4
- /**
5
- * Determines the type of elements based on a hierarchy of type
6
- */
7
- export type XtTypeResolver<TypeContext> = {
8
- findType(typeInfo: TypeContext | null | undefined, subName?: string, value?: any): string | null | undefined;
9
- listSubNames(typeInfo: TypeContext | null | undefined, value?: any): string[];
10
- canUpdate(): boolean;
11
- };
12
- export type XtUpdatableTypeResolver<TypeContext> = XtTypeResolver<TypeContext> & {
13
- addType(typeName: string, type: XtTypeInfo | string): void;
14
- };
15
- export declare class XtTypeHierarchyResolver<T> implements XtUpdatableTypeResolver<XtContext<T>> {
16
- types: Map<string, XtTypeHierarchy>;
17
- addType(typeName: string, type: XtTypeInfo | string): void;
18
- canUpdate(): boolean;
19
- findType(typeInfo: XtContext<T> | null | undefined, subName?: string, value?: any): string | null | undefined;
20
- listSubNames(context: XtContext<T> | null | undefined, value?: any): string[];
21
- }
22
- export type XtTypeHierarchy = {
23
- type?: string;
24
- children?: {
25
- [key: string]: XtTypeHierarchy;
26
- };
27
- parent?: XtTypeHierarchy;
28
- addChild(key: string, child: XtTypeHierarchy): void;
29
- };
30
- export declare class XtBaseTypeHierarchy implements XtTypeHierarchy {
31
- type?: string;
32
- children?: {
33
- [key: string]: XtTypeHierarchy;
34
- };
35
- parent?: XtTypeHierarchy;
36
- constructor(type?: string, parent?: XtTypeHierarchy);
37
- addChild(key: string, child: XtTypeHierarchy): void;
38
- }
39
- export declare function fromDescription(typeHierarchy: XtTypeInfo | string, name?: string, parent?: XtTypeHierarchy): XtTypeHierarchy;
40
- export declare function updateFormGroupWithValue(formGroup: FormGroup, value: {
41
- [key: string]: any;
42
- }): void;