@ecodev/natural 44.0.6 → 45.1.0

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.
Files changed (34) hide show
  1. package/esm2020/lib/classes/abstract-detail.mjs +39 -40
  2. package/esm2020/lib/classes/abstract-navigable-list.mjs +6 -2
  3. package/esm2020/lib/classes/rxjs.mjs +2 -1
  4. package/esm2020/lib/classes/validators.mjs +2 -2
  5. package/esm2020/lib/modules/dropdown-components/type-date/type-date.component.mjs +1 -1
  6. package/esm2020/lib/modules/dropdown-components/type-date-range/type-date-range.component.mjs +1 -1
  7. package/esm2020/lib/modules/dropdown-components/type-number/type-number.component.mjs +7 -3
  8. package/esm2020/lib/modules/dropdown-components/type-select/type-select.component.mjs +8 -4
  9. package/esm2020/lib/modules/file/abstract-file.mjs +26 -29
  10. package/esm2020/lib/modules/file/utils.mjs +12 -1
  11. package/esm2020/lib/modules/fixed-button-detail/fixed-button-detail.component.mjs +22 -9
  12. package/esm2020/lib/modules/hierarchic-selector/hierarchic-selector/hierarchic-selector.component.mjs +3 -3
  13. package/esm2020/lib/modules/hierarchic-selector/hierarchic-selector/hierarchic-selector.service.mjs +3 -9
  14. package/esm2020/lib/services/abstract-model.service.mjs +8 -41
  15. package/esm2020/lib/services/debounce.service.mjs +128 -0
  16. package/esm2020/lib/services/swiss-parsing-date-adapter.service.mjs +21 -13
  17. package/esm2020/public-api.mjs +2 -1
  18. package/fesm2015/ecodev-natural.mjs +266 -141
  19. package/fesm2015/ecodev-natural.mjs.map +1 -1
  20. package/fesm2020/ecodev-natural.mjs +263 -139
  21. package/fesm2020/ecodev-natural.mjs.map +1 -1
  22. package/lib/modules/dropdown-components/type-date/type-date.component.d.ts +1 -1
  23. package/lib/modules/dropdown-components/type-date-range/type-date-range.component.d.ts +1 -1
  24. package/lib/modules/dropdown-components/type-number/type-number.component.d.ts +2 -1
  25. package/lib/modules/dropdown-components/type-select/type-select.component.d.ts +7 -3
  26. package/lib/modules/file/abstract-file.d.ts +0 -3
  27. package/lib/modules/file/utils.d.ts +1 -0
  28. package/lib/modules/fixed-button-detail/fixed-button-detail.component.d.ts +14 -6
  29. package/lib/modules/hierarchic-selector/hierarchic-selector/hierarchic-selector.component.d.ts +5 -6
  30. package/lib/modules/hierarchic-selector/hierarchic-selector/hierarchic-selector.service.d.ts +5 -14
  31. package/lib/services/abstract-model.service.d.ts +4 -6
  32. package/lib/services/debounce.service.d.ts +46 -0
  33. package/package.json +1 -1
  34. package/public-api.d.ts +1 -0
@@ -13,7 +13,7 @@ export declare class TypeDateComponent<D = any> implements DropdownComponent {
13
13
  private dateAdapter;
14
14
  private dateFormats;
15
15
  readonly renderedValue: BehaviorSubject<string>;
16
- readonly configuration: TypeDateConfiguration<D>;
16
+ readonly configuration: Required<TypeDateConfiguration<D>>;
17
17
  readonly operatorCtrl: FormControl<"equal" | "greater" | "greaterOrEqual" | "less" | "lessOrEqual">;
18
18
  readonly valueCtrl: FormControl<D | null>;
19
19
  readonly operators: import("../types").PossibleComparableOperator[];
@@ -21,7 +21,7 @@ export declare class TypeDateRangeComponent<D = any> implements DropdownComponen
21
21
  private dateAdapter;
22
22
  private dateFormats;
23
23
  readonly renderedValue: BehaviorSubject<string>;
24
- readonly configuration: TypeDateRangeConfiguration<D>;
24
+ readonly configuration: Required<TypeDateRangeConfiguration<D>>;
25
25
  readonly matcher: InvalidWithValueStateMatcher;
26
26
  readonly fromCtrl: FormControl<D | null>;
27
27
  readonly toCtrl: FormControl<D | null>;
@@ -14,7 +14,7 @@ export interface TypeNumberConfiguration {
14
14
  export declare class TypeNumberComponent implements DropdownComponent {
15
15
  protected dropdownRef: NaturalDropdownRef;
16
16
  readonly renderedValue: BehaviorSubject<string>;
17
- readonly configuration: TypeNumberConfiguration;
17
+ readonly configuration: Required<TypeNumberConfiguration>;
18
18
  readonly operatorCtrl: FormControl<"equal" | "greater" | "greaterOrEqual" | "less" | "lessOrEqual">;
19
19
  readonly valueCtrl: FormControl<any>;
20
20
  readonly matcher: InvalidWithValueStateMatcher;
@@ -23,6 +23,7 @@ export declare class TypeNumberComponent implements DropdownComponent {
23
23
  value: FormControl<any>;
24
24
  }>;
25
25
  readonly operators: import("../types").PossibleComparableOperator[];
26
+ private readonly defaults;
26
27
  constructor(data: NaturalDropdownData<TypeNumberConfiguration>, dropdownRef: NaturalDropdownRef);
27
28
  getCondition(): FilterGroupConditionField;
28
29
  isValid(): boolean;
@@ -6,7 +6,7 @@ import { NaturalDropdownData } from '../../search/dropdown-container/dropdown.se
6
6
  import { DropdownComponent } from '../../search/types/dropdown-component';
7
7
  import { FormControl, FormGroup } from '@angular/forms';
8
8
  import { NaturalAbstractController } from '../../../classes/abstract-controller';
9
- import { PossibleDiscreteOperator, PossibleDiscreteOperatorKeys } from '../types';
9
+ import { PossibleDiscreteOperatorKeys } from '../types';
10
10
  import * as i0 from "@angular/core";
11
11
  export declare type TypeSelectItem = Scalar | {
12
12
  id: Scalar;
@@ -18,12 +18,16 @@ export declare type TypeSelectItem = Scalar | {
18
18
  export interface TypeSelectConfiguration {
19
19
  items: TypeSelectItem[] | Observable<TypeSelectItem[]>;
20
20
  multiple?: boolean;
21
+ /**
22
+ * If true (default) a selectbox allows to choose an operator. Otherwise, the selectbox is hidden and the operator will always be `is`.
23
+ */
24
+ operators?: boolean;
21
25
  }
22
26
  export declare class TypeSelectComponent extends NaturalAbstractController implements DropdownComponent, AfterViewInit, OnDestroy {
23
27
  readonly renderedValue: BehaviorSubject<string>;
24
28
  list: MatSelectionList;
25
29
  requireValueCtrl: boolean;
26
- readonly operators: PossibleDiscreteOperator[];
30
+ readonly operators: import("../types").PossibleDiscreteOperator[];
27
31
  readonly operatorCtrl: FormControl<PossibleDiscreteOperatorKeys>;
28
32
  readonly valueCtrl: FormControl<any>;
29
33
  readonly form: FormGroup<{
@@ -31,7 +35,7 @@ export declare class TypeSelectComponent extends NaturalAbstractController imple
31
35
  value: FormControl<any>;
32
36
  }>;
33
37
  items: TypeSelectItem[];
34
- private readonly configuration;
38
+ readonly configuration: Required<TypeSelectConfiguration>;
35
39
  private readonly defaults;
36
40
  constructor(data: NaturalDropdownData<TypeSelectConfiguration>);
37
41
  ngAfterViewInit(): void;
@@ -30,7 +30,6 @@ export declare abstract class NaturalAbstractFile extends NaturalAbstractControl
30
30
  protected readonly naturalFileService: NaturalFileService;
31
31
  private readonly document;
32
32
  private fileElement?;
33
- private readonly validators;
34
33
  /**
35
34
  * Whether we should accept a single file or multiple files
36
35
  */
@@ -90,8 +89,6 @@ export declare abstract class NaturalAbstractFile extends NaturalAbstractControl
90
89
  private beforeSelect;
91
90
  onChange(event: Event): void;
92
91
  private validate;
93
- private acceptValidator;
94
- private fileSizeValidator;
95
92
  static ɵfac: i0.ɵɵFactoryDeclaration<NaturalAbstractFile, never>;
96
93
  static ɵdir: i0.ɵɵDirectiveDeclaration<NaturalAbstractFile, never, never, { "multiple": "multiple"; "accept": "accept"; "maxSize": "maxSize"; "fileSelectionDisabled": "fileSelectionDisabled"; "selectable": "selectable"; "broadcast": "broadcast"; }, { "fileChange": "fileChange"; "filesChange": "filesChange"; }, never, never, false>;
97
94
  }
@@ -2,6 +2,7 @@ export declare function acceptType(accept: string, type: string, filename: strin
2
2
  export declare function isFileInput(elm: HTMLElement): elm is HTMLInputElement;
3
3
  export declare function detectSwipe(event: Event | TouchEvent): boolean;
4
4
  export declare function createInvisibleFileInputWrap(document: Document): HTMLLabelElement;
5
+ export declare function isDirectory(file: File): Promise<boolean>;
5
6
  export declare function stopEvent(event: Event): void;
6
7
  export declare function fileListToArray(fileList: FileList): File[];
7
8
  export declare function eventToFiles(event: Event | DragEvent): File[];
@@ -1,18 +1,26 @@
1
1
  import { EventEmitter } from '@angular/core';
2
2
  import { FormGroup } from '@angular/forms';
3
+ import { ActivatedRoute } from '@angular/router';
3
4
  import * as i0 from "@angular/core";
4
- export declare class NaturalFixedButtonDetailComponent {
5
- model: {
6
- id?: string;
7
- permissions?: {
8
- delete: boolean;
9
- };
5
+ declare type Model = {
6
+ id?: string;
7
+ permissions?: {
8
+ delete: boolean;
10
9
  };
10
+ };
11
+ export declare class NaturalFixedButtonDetailComponent {
12
+ private canChange;
13
+ isCreation: boolean;
14
+ get model(): Model;
15
+ set model(value: Model);
16
+ private _model;
11
17
  form: FormGroup;
12
18
  readonly create: EventEmitter<void>;
13
19
  readonly delete: EventEmitter<void>;
20
+ constructor(route: ActivatedRoute);
14
21
  clickCreate(): void;
15
22
  clickDelete(): void;
16
23
  static ɵfac: i0.ɵɵFactoryDeclaration<NaturalFixedButtonDetailComponent, never>;
17
24
  static ɵcmp: i0.ɵɵComponentDeclaration<NaturalFixedButtonDetailComponent, "natural-fixed-button-detail", never, { "model": "model"; "form": "form"; }, { "create": "create"; "delete": "delete"; }, never, never, false>;
18
25
  }
26
+ export {};
@@ -2,7 +2,6 @@ import { SelectionModel } from '@angular/cdk/collections';
2
2
  import { FlatTreeControl } from '@angular/cdk/tree';
3
3
  import { EventEmitter, OnChanges, OnInit, SimpleChanges } from '@angular/core';
4
4
  import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree';
5
- import { Observable } from 'rxjs';
6
5
  import { NaturalAbstractController } from '../../../classes/abstract-controller';
7
6
  import { NaturalSearchFacets } from '../../search/types/facet';
8
7
  import { NaturalSearchSelections } from '../../search/types/values';
@@ -96,20 +95,20 @@ export declare class NaturalHierarchicSelectorComponent extends NaturalAbstractC
96
95
  /**
97
96
  * Created to collapse all children when closing a parent, but not sure it's good.
98
97
  */
99
- getChildren(): (node: HierarchicModelNode) => Observable<HierarchicModelNode[]>;
98
+ private getChildren;
100
99
  /**
101
100
  * Transforms a HierarchicModelNode into a FlatNode
102
101
  */
103
- transformer(): (node: HierarchicModelNode, level: number) => HierarchicFlatNode;
102
+ private transformer;
104
103
  /**
105
104
  * Return deep of the node in the tree
106
105
  */
107
- getLevel(): (node: HierarchicFlatNode) => number;
106
+ private getLevel;
108
107
  /**
109
108
  * Is always expandable because we load on demand, we don't know if there are children yet
110
109
  */
111
- isExpandable(): (node: HierarchicFlatNode) => boolean;
112
- getOrCreateFlatNode(node: HierarchicModelNode, level: number): HierarchicFlatNode;
110
+ private isExpandable;
111
+ private getOrCreateFlatNode;
113
112
  search(selections: NaturalSearchSelections): void;
114
113
  private loadRoots;
115
114
  /**
@@ -1,18 +1,14 @@
1
1
  import { Injector } from '@angular/core';
2
2
  import { BehaviorSubject, Observable } from 'rxjs';
3
- import { NaturalQueryVariablesManager, QueryVariables } from '../../../classes/query-variable-manager';
3
+ import { QueryVariables } from '../../../classes/query-variable-manager';
4
4
  import { HierarchicFlatNode } from '../classes/flat-node';
5
- import { NaturalHierarchicConfiguration, NaturalHierarchicServiceConfiguration } from '../classes/hierarchic-configuration';
5
+ import { NaturalHierarchicConfiguration } from '../classes/hierarchic-configuration';
6
6
  import { HierarchicFiltersConfiguration } from '../classes/hierarchic-filters-configuration';
7
7
  import { HierarchicModelNode } from '../classes/model-node';
8
8
  import * as i0 from "@angular/core";
9
9
  export interface OrganizedModelSelection {
10
10
  [key: string]: any[];
11
11
  }
12
- interface ContextualizedConfig {
13
- configuration: NaturalHierarchicServiceConfiguration;
14
- variablesManager: NaturalQueryVariablesManager;
15
- }
16
12
  export declare class NaturalHierarchicSelectorService {
17
13
  private readonly injector;
18
14
  /**
@@ -20,7 +16,7 @@ export declare class NaturalHierarchicSelectorService {
20
16
  * This observable contains Node.
21
17
  * When it's updated, the TreeController and TreeFlattener process the new array to generate the flat tree.
22
18
  */
23
- dataChange: BehaviorSubject<HierarchicModelNode[]>;
19
+ readonly dataChange: BehaviorSubject<HierarchicModelNode[]>;
24
20
  /**
25
21
  * Configuration for relations and selection constraints
26
22
  *
@@ -43,13 +39,9 @@ export declare class NaturalHierarchicSelectorService {
43
39
  * Retrieve elements from the server
44
40
  * Get root elements if node is null, or child elements if node is given
45
41
  */
46
- getList(node?: HierarchicFlatNode | null, contextFilters?: HierarchicFiltersConfiguration | null, searchVariables?: QueryVariables | null): Observable<HierarchicModelNode[]>;
42
+ private getList;
47
43
  countItems(node: HierarchicFlatNode, contextFilters?: HierarchicFiltersConfiguration | null): void;
48
- getContextualizedConfigs(node?: HierarchicFlatNode | null, contextFilters?: HierarchicFiltersConfiguration | null, searchVariables?: QueryVariables | null): ContextualizedConfig[];
49
- /**
50
- * Check configuration to return a boolean that allows or denies the selection for the given element
51
- */
52
- isSelectable(node: HierarchicFlatNode): boolean;
44
+ private getContextualizedConfigs;
53
45
  /**
54
46
  * Return models matching given FlatNodes
55
47
  * Returns a Literal of models grouped by their configuration attribute "selectableAtKey"
@@ -87,4 +79,3 @@ export declare class NaturalHierarchicSelectorService {
87
79
  static ɵfac: i0.ɵɵFactoryDeclaration<NaturalHierarchicSelectorService, never>;
88
80
  static ɵprov: i0.ɵɵInjectableDeclaration<NaturalHierarchicSelectorService>;
89
81
  }
90
- export {};
@@ -6,6 +6,7 @@ import { Observable, OperatorFunction } from 'rxjs';
6
6
  import { NaturalQueryVariablesManager, QueryVariables } from '../classes/query-variable-manager';
7
7
  import { Literal } from '../types/types';
8
8
  import { PaginatedData } from '../classes/data-source';
9
+ import { NaturalDebounceService } from './debounce.service';
9
10
  export interface FormValidators {
10
11
  [key: string]: ValidatorFn[];
11
12
  }
@@ -33,21 +34,18 @@ export declare abstract class NaturalAbstractModelService<Tone, Vone extends {
33
34
  ids: string[];
34
35
  }> {
35
36
  protected readonly apollo: Apollo;
37
+ protected readonly naturalDebounceService: NaturalDebounceService;
36
38
  protected readonly name: string;
37
39
  protected readonly oneQuery: DocumentNode | null;
38
40
  protected readonly allQuery: DocumentNode | null;
39
41
  protected readonly createMutation: DocumentNode | null;
40
42
  protected readonly updateMutation: DocumentNode | null;
41
43
  protected readonly deleteMutation: DocumentNode | null;
42
- /**
43
- * Stores the debounced update function
44
- */
45
- private debouncedUpdateCache;
46
44
  /**
47
45
  * Store the creation mutations that are pending
48
46
  */
49
47
  private readonly creatingCache;
50
- constructor(apollo: Apollo, name: string, oneQuery: DocumentNode | null, allQuery: DocumentNode | null, createMutation: DocumentNode | null, updateMutation: DocumentNode | null, deleteMutation: DocumentNode | null);
48
+ constructor(apollo: Apollo, naturalDebounceService: NaturalDebounceService, name: string, oneQuery: DocumentNode | null, allQuery: DocumentNode | null, createMutation: DocumentNode | null, updateMutation: DocumentNode | null, deleteMutation: DocumentNode | null);
51
49
  getConsolidatedForClient(): Literal;
52
50
  /**
53
51
  * List of individual fields validators
@@ -139,7 +137,7 @@ export declare abstract class NaturalAbstractModelService<Tone, Vone extends {
139
137
  */
140
138
  getInput(object: Literal): Vcreate['input'] | Vupdate['input'];
141
139
  /**
142
- * Return the number of objects matching the query
140
+ * Return the number of objects matching the query. It may never complete.
143
141
  *
144
142
  * This is used for the unique validator
145
143
  */
@@ -0,0 +1,46 @@
1
+ import { Observable } from 'rxjs';
2
+ import { NaturalAbstractModelService } from './abstract-model.service';
3
+ import * as i0 from "@angular/core";
4
+ declare type Key = NaturalAbstractModelService<unknown, any, any, any, unknown, any, unknown, any, unknown, any>;
5
+ /**
6
+ * Debounce subscriptions to observable, with possibility to cancel one, or flush all of them. Typically,
7
+ * observables are object updates, so `NaturalAbstractModelService.updateNow()`.
8
+ *
9
+ * `key` must be an instance of `NaturalAbstractModelService` to separate objects by their types. So User with ID 1 is
10
+ * not confused with Product with ID 1. It has no other purpose.
11
+ *
12
+ * `id` should be the ID of the object that will be updated.
13
+ */
14
+ export declare class NaturalDebounceService {
15
+ private readonly flusher;
16
+ /**
17
+ * Stores the debounced update function
18
+ */
19
+ private readonly allDebouncedUpdateCache;
20
+ /**
21
+ * Debounce the given source observable for a short time. If called multiple times with the same key and id,
22
+ * it will postpone the subscription to the source observable.
23
+ *
24
+ * Giving the same key and id but a different source observable will replace the original observable, but
25
+ * keep the same debouncing timeline.
26
+ */
27
+ debounce<T>(key: Key, id: string, source: Observable<T>): Observable<T>;
28
+ cancel<T>(key: Key, id: string): void;
29
+ /**
30
+ * Immediately execute all pending updates.
31
+ *
32
+ * It should typically be called before login out.
33
+ *
34
+ * The returned observable will complete when all updates complete, even if some of them error.
35
+ */
36
+ flush(): Observable<void>;
37
+ /**
38
+ * Count of pending updates
39
+ */
40
+ get count(): number;
41
+ private getMap;
42
+ private delete;
43
+ static ɵfac: i0.ɵɵFactoryDeclaration<NaturalDebounceService, never>;
44
+ static ɵprov: i0.ɵɵInjectableDeclaration<NaturalDebounceService>;
45
+ }
46
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecodev/natural",
3
- "version": "44.0.6",
3
+ "version": "45.1.0",
4
4
  "license": "MIT",
5
5
  "repository": "github:Ecodev/natural",
6
6
  "sideEffects": false,
package/public-api.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from './lib/classes/utility';
12
12
  export * from './lib/classes/validators';
13
13
  export { validTlds } from './lib/classes/tld';
14
14
  export * from './lib/services/abstract-model.service';
15
+ export { NaturalDebounceService } from './lib/services/debounce.service';
15
16
  export * from './lib/services/enum.service';
16
17
  export * from './lib/services/link-mutation.service';
17
18
  export * from './lib/services/persistence.service';