@signaltree/ng-forms 6.0.5 → 6.0.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signaltree/ng-forms",
3
- "version": "6.0.5",
3
+ "version": "6.0.9",
4
4
  "description": "Complete Angular forms integration for SignalTree. FormTree creation, custom directives, validators, form state tracking, and RxJS bridge.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,74 +0,0 @@
1
- import { getChanges } from '../get-changes.js';
2
-
3
- function createAuditTracker(tree, auditLog, config = {}) {
4
- const {
5
- getMetadata,
6
- includePreviousValues = false,
7
- filter,
8
- maxEntries = 0
9
- } = config;
10
- let previousState = structuredClone(tree());
11
- let isTracking = true;
12
- const handleChange = () => {
13
- if (!isTracking) return;
14
- const currentState = tree();
15
- const changes = getChanges(previousState, currentState);
16
- if (Object.keys(changes).length > 0) {
17
- if (filter && !filter(changes)) {
18
- previousState = structuredClone(currentState);
19
- return;
20
- }
21
- const entry = {
22
- timestamp: Date.now(),
23
- changes,
24
- metadata: getMetadata?.()
25
- };
26
- if (includePreviousValues) {
27
- const prevValues = {};
28
- for (const key of Object.keys(changes)) {
29
- prevValues[key] = previousState[key];
30
- }
31
- entry.previousValues = prevValues;
32
- }
33
- auditLog.push(entry);
34
- if (maxEntries > 0 && auditLog.length > maxEntries) {
35
- auditLog.splice(0, auditLog.length - maxEntries);
36
- }
37
- }
38
- previousState = structuredClone(currentState);
39
- };
40
- let unsubscribe;
41
- let pollingId;
42
- if ('subscribe' in tree && typeof tree.subscribe === 'function') {
43
- try {
44
- unsubscribe = tree.subscribe(handleChange);
45
- } catch {
46
- pollingId = setInterval(handleChange, 100);
47
- }
48
- } else {
49
- pollingId = setInterval(handleChange, 100);
50
- }
51
- return () => {
52
- isTracking = false;
53
- if (unsubscribe) {
54
- unsubscribe();
55
- }
56
- if (pollingId) {
57
- clearInterval(pollingId);
58
- }
59
- };
60
- }
61
- function createAuditCallback(auditLog, getMetadata) {
62
- return (previousState, currentState) => {
63
- const changes = getChanges(previousState, currentState);
64
- if (Object.keys(changes).length > 0) {
65
- auditLog.push({
66
- timestamp: Date.now(),
67
- changes,
68
- metadata: getMetadata?.()
69
- });
70
- }
71
- };
72
- }
73
-
74
- export { createAuditCallback, createAuditTracker };
@@ -1 +0,0 @@
1
- export { createAuditCallback, createAuditTracker } from './audit.js';
@@ -1,11 +0,0 @@
1
- function getChanges(oldState, newState) {
2
- const changes = {};
3
- for (const key in newState) {
4
- if (oldState[key] !== newState[key]) {
5
- changes[key] = newState[key];
6
- }
7
- }
8
- return changes;
9
- }
10
-
11
- export { getChanges };
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- export * from './core/ng-forms.js';
2
- export * from './core/validators.js';
3
- export * from './core/async-validators.js';
4
- export * from './history/index.js';
@@ -1,21 +0,0 @@
1
- import type { ISignalTree } from '@signaltree/core';
2
- export interface AuditEntry<T = unknown> {
3
- timestamp: number;
4
- changes: Partial<T>;
5
- previousValues?: Partial<T>;
6
- metadata?: AuditMetadata;
7
- }
8
- export interface AuditMetadata {
9
- userId?: string;
10
- source?: string;
11
- description?: string;
12
- [key: string]: unknown;
13
- }
14
- export interface AuditTrackerConfig<T> {
15
- getMetadata?: () => AuditMetadata;
16
- includePreviousValues?: boolean;
17
- filter?: (changes: Partial<T>) => boolean;
18
- maxEntries?: number;
19
- }
20
- export declare function createAuditTracker<T extends Record<string, unknown>>(tree: ISignalTree<T>, auditLog: AuditEntry<T>[], config?: AuditTrackerConfig<T>): () => void;
21
- export declare function createAuditCallback<T extends Record<string, unknown>>(auditLog: AuditEntry<T>[], getMetadata?: () => AuditMetadata): (previousState: T, currentState: T) => void;
@@ -1 +0,0 @@
1
- export { createAuditTracker, createAuditCallback, type AuditEntry, type AuditMetadata, type AuditTrackerConfig, } from './audit.js';
@@ -1,3 +0,0 @@
1
- import type { FormTreeAsyncValidatorFn } from './ng-forms';
2
- export declare function unique(checkFn: (value: unknown) => Promise<boolean>, message?: string): FormTreeAsyncValidatorFn<unknown>;
3
- export declare function debounce(validator: FormTreeAsyncValidatorFn<unknown>, delayMs: number): FormTreeAsyncValidatorFn<unknown>;
@@ -1,90 +0,0 @@
1
- import { DestroyRef, EventEmitter, OnInit, Signal, WritableSignal } from '@angular/core';
2
- import { AbstractControl, ControlValueAccessor, FormArray, FormGroup } from '@angular/forms';
3
- import { Observable } from 'rxjs';
4
- import type { ISignalTree, TreeConfig, TreeNode } from '@signaltree/core';
5
- export type FormTreeAsyncValidatorFn<T> = (value: T) => Observable<string | null> | Promise<string | null>;
6
- export type EnhancedArraySignal<T> = WritableSignal<T[]> & {
7
- push: (item: T) => void;
8
- removeAt: (index: number) => void;
9
- setAt: (index: number, value: T) => void;
10
- insertAt: (index: number, item: T) => void;
11
- move: (from: number, to: number) => void;
12
- clear: () => void;
13
- };
14
- export type FieldValidator = (value: unknown) => string | null;
15
- export interface FieldConfig {
16
- debounceMs?: number;
17
- validators?: Record<string, FieldValidator> | FieldValidator[];
18
- asyncValidators?: Record<string, FormTreeAsyncValidatorFn<unknown>> | Array<FormTreeAsyncValidatorFn<unknown>>;
19
- }
20
- export interface ConditionalField<T> {
21
- when: (values: T) => boolean;
22
- fields: string[];
23
- }
24
- export interface FormTreeOptions<T extends Record<string, unknown>> extends TreeConfig {
25
- validators?: SyncValidatorMap;
26
- asyncValidators?: AsyncValidatorMap;
27
- destroyRef?: DestroyRef;
28
- fieldConfigs?: Record<string, FieldConfig>;
29
- conditionals?: Array<ConditionalField<T>>;
30
- persistKey?: string;
31
- storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
32
- persistDebounceMs?: number;
33
- validationBatchMs?: number;
34
- }
35
- export type FormTree<T extends Record<string, unknown>> = {
36
- state: TreeNode<T>;
37
- $: TreeNode<T>;
38
- form: FormGroup;
39
- errors: WritableSignal<Record<string, string>>;
40
- asyncErrors: WritableSignal<Record<string, string>>;
41
- touched: WritableSignal<Record<string, boolean>>;
42
- asyncValidating: WritableSignal<Record<string, boolean>>;
43
- dirty: WritableSignal<boolean>;
44
- valid: WritableSignal<boolean>;
45
- submitting: WritableSignal<boolean>;
46
- unwrap(): T;
47
- setValue(field: string, value: unknown): void;
48
- setValues(values: Partial<T>): void;
49
- reset(): void;
50
- submit<TResult>(submitFn: (values: T) => Promise<TResult>): Promise<TResult>;
51
- validate(field?: string): Promise<void>;
52
- getFieldError(field: string): Signal<string | undefined>;
53
- getFieldAsyncError(field: string): Signal<string | undefined>;
54
- getFieldTouched(field: string): Signal<boolean | undefined>;
55
- isFieldValid(field: string): Signal<boolean>;
56
- isFieldAsyncValidating(field: string): Signal<boolean | undefined>;
57
- fieldErrors: Record<string, Signal<string | undefined>>;
58
- fieldAsyncErrors: Record<string, Signal<string | undefined>>;
59
- values: ISignalTree<T>;
60
- destroy(): void;
61
- };
62
- export declare class FormValidationError extends Error {
63
- readonly errors: Record<string, string>;
64
- readonly asyncErrors: Record<string, string>;
65
- constructor(errors: Record<string, string>, asyncErrors: Record<string, string>);
66
- }
67
- type SyncValidatorMap = Record<string, (value: unknown) => string | null>;
68
- type AsyncValidatorMap = Record<string, FormTreeAsyncValidatorFn<unknown>>;
69
- export declare function createFormTree<T extends Record<string, unknown>>(initialValues: T, config?: FormTreeOptions<T>): FormTree<T>;
70
- export declare function createVirtualFormArray<T>(items: T[], visibleRange: {
71
- start: number;
72
- end: number;
73
- }, controlFactory?: (value: T, index: number) => AbstractControl): FormArray;
74
- export declare class SignalValueDirective implements ControlValueAccessor, OnInit {
75
- signalTreeSignalValue: WritableSignal<unknown>;
76
- signalTreeSignalValueChange: EventEmitter<unknown>;
77
- private elementRef;
78
- private renderer;
79
- private onChange;
80
- private onTouched;
81
- ngOnInit(): void;
82
- handleChange(event: Event): void;
83
- handleBlur(): void;
84
- writeValue(value: unknown): void;
85
- registerOnChange(fn: (value: unknown) => void): void;
86
- registerOnTouched(fn: () => void): void;
87
- setDisabledState?(isDisabled: boolean): void;
88
- }
89
- export declare const SIGNAL_FORM_DIRECTIVES: (typeof SignalValueDirective)[];
90
- export {};
@@ -1,9 +0,0 @@
1
- import type { FieldValidator } from './ng-forms';
2
- export declare function required(message?: string): FieldValidator;
3
- export declare function email(message?: string): FieldValidator;
4
- export declare function minLength(min: number, message?: string): FieldValidator;
5
- export declare function maxLength(max: number, message?: string): FieldValidator;
6
- export declare function pattern(regex: RegExp, message?: string): FieldValidator;
7
- export declare function min(min: number, message?: string): FieldValidator;
8
- export declare function max(max: number, message?: string): FieldValidator;
9
- export declare function compose(validators: FieldValidator[]): FieldValidator;
@@ -1,21 +0,0 @@
1
- import { Signal } from '@angular/core';
2
- interface FormTree<T extends Record<string, unknown>> {
3
- form: any;
4
- unwrap(): T;
5
- destroy(): void;
6
- setValues(values: Partial<T>): void;
7
- }
8
- export interface FormHistory<T> {
9
- past: T[];
10
- present: T;
11
- future: T[];
12
- }
13
- export declare function withFormHistory<T extends Record<string, unknown>>(formTree: FormTree<T>, options?: {
14
- capacity?: number;
15
- }): FormTree<T> & {
16
- undo: () => void;
17
- redo: () => void;
18
- clearHistory: () => void;
19
- history: Signal<FormHistory<T>>;
20
- };
21
- export {};
@@ -1 +0,0 @@
1
- export { withFormHistory, type FormHistory } from './history';
package/src/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './core/ng-forms';
2
- export * from './core/validators';
3
- export * from './core/async-validators';
4
- export * from './history';
@@ -1 +0,0 @@
1
- export * from './public-api';
@@ -1 +0,0 @@
1
- export * from './rxjs-bridge';
@@ -1,3 +0,0 @@
1
- import { Signal } from '@angular/core';
2
- import { Observable } from 'rxjs';
3
- export declare function toObservable<T>(signal: Signal<T>): Observable<T>;
@@ -1 +0,0 @@
1
- export { createWizardForm, type FormStep } from './wizard';
@@ -1,19 +0,0 @@
1
- import { Signal } from '@angular/core';
2
- type FormTreeOptions = Record<string, unknown>;
3
- interface FormTree<T extends Record<string, unknown>> {
4
- unwrap(): T;
5
- }
6
- export interface FormStep<T extends Record<string, unknown>> {
7
- fields: Array<keyof T | string>;
8
- validate?: (form: FormTree<T>) => Promise<boolean> | boolean;
9
- canSkip?: (values: T) => boolean;
10
- }
11
- export declare function createWizardForm<T extends Record<string, unknown>>(steps: FormStep<T>[], initialValues: T, config?: FormTreeOptions): FormTree<T> & {
12
- currentStep: Signal<number>;
13
- nextStep: () => Promise<boolean>;
14
- previousStep: () => void;
15
- goToStep: (index: number) => Promise<boolean>;
16
- canGoToStep: (index: number) => boolean;
17
- isFieldVisible: (field: keyof T | string) => Signal<boolean>;
18
- };
19
- export {};