@ethlete/cdk 4.37.1 → 4.38.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.
@@ -0,0 +1,47 @@
1
+ import { Signal } from '@angular/core';
2
+ import { AbstractControl } from '@angular/forms';
3
+ export interface FormChangesTrackerRef<T> {
4
+ /**
5
+ * Set the default form value to the current form value.
6
+ * Useful when the form value changes.
7
+ *
8
+ * (e.g. when a http request was needed to fill the remaining form fields to their default values)
9
+ */
10
+ refreshDefaultFormValue: () => void;
11
+ /**
12
+ * Restore the default form value to the form.
13
+ */
14
+ restoreDefaultFormValue: () => void;
15
+ /**
16
+ * Checks if the form has changes compared to the default form value.
17
+ * @returns `true` if the form has changes.
18
+ */
19
+ hasChanges: Signal<boolean>;
20
+ /**
21
+ * The default form value to compare the current form value to
22
+ */
23
+ defaultFormValue: Signal<T>;
24
+ }
25
+ export type CreateFormChangesTrackerConfig<T extends AbstractControl> = {
26
+ /**
27
+ * The form to check for changes
28
+ */
29
+ form: T;
30
+ /**
31
+ * The default value to compare the current form value to
32
+ *
33
+ * @default form.getRawValue()
34
+ */
35
+ defaultValue?: ReturnType<T['getRawValue']>;
36
+ /**
37
+ * A custom compare function to compare the current form value to the default value.
38
+ * By default, a deep comparison will be used.
39
+ *
40
+ * @default (currentValue, defaultValue) => equal(currentValue, defaultValue)
41
+ */
42
+ compareFn?: (currentValue: ReturnType<T['getRawValue']>, defaultValue: ReturnType<T['getRawValue']>) => boolean;
43
+ };
44
+ /**
45
+ * A utility function to enhance form usage by providing methods to manage form state and detect changes.
46
+ */
47
+ export declare const createFormChangesTracker: <T extends AbstractControl>(config: CreateFormChangesTrackerConfig<T>) => FormChangesTrackerRef<ReturnType<T["getRawValue"]>>;
@@ -1,3 +1,4 @@
1
1
  export * from './decorated-form-field.base';
2
2
  export * from './decorated-input.base';
3
+ export * from './form-changes-tracker.util';
3
4
  export * from './input.base';
@@ -6,6 +6,7 @@ import { Sort, SortDefaultOptions, Sortable } from './sort.types';
6
6
  import * as i0 from "@angular/core";
7
7
  export declare const SORT_DEFAULT_OPTIONS: InjectionToken<SortDefaultOptions>;
8
8
  export declare class SortDirective implements OnChanges, OnDestroy, OnInit {
9
+ destroy$: Observable<boolean>;
9
10
  private readonly _defaultOptions;
10
11
  sortables: Map<string, Sortable>;
11
12
  readonly _stateChanges: Subject<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethlete/cdk",
3
- "version": "4.37.1",
3
+ "version": "4.38.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "css": "./src/lib/styles/index.css",