@signaltree/ng-forms 4.2.1 → 5.0.2

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.
@@ -1,56 +0,0 @@
1
- function required(message = 'Required') {
2
- return value => !value ? message : null;
3
- }
4
- function email(message = 'Invalid email') {
5
- return value => {
6
- const strValue = value;
7
- return strValue && !strValue.includes('@') ? message : null;
8
- };
9
- }
10
- function minLength(min, message) {
11
- return value => {
12
- const strValue = value;
13
- const errorMsg = message ?? `Min ${min} characters`;
14
- return strValue && strValue.length < min ? errorMsg : null;
15
- };
16
- }
17
- function maxLength(max, message) {
18
- return value => {
19
- const strValue = value;
20
- const errorMsg = message ?? `Max ${max} characters`;
21
- return strValue && strValue.length > max ? errorMsg : null;
22
- };
23
- }
24
- function pattern(regex, message = 'Invalid format') {
25
- return value => {
26
- const strValue = value;
27
- return strValue && !regex.test(strValue) ? message : null;
28
- };
29
- }
30
- function min(min, message) {
31
- return value => {
32
- const numValue = value;
33
- const errorMsg = message ?? `Must be at least ${min}`;
34
- return numValue < min ? errorMsg : null;
35
- };
36
- }
37
- function max(max, message) {
38
- return value => {
39
- const numValue = value;
40
- const errorMsg = message ?? `Must be at most ${max}`;
41
- return numValue > max ? errorMsg : null;
42
- };
43
- }
44
- function compose(validators) {
45
- return value => {
46
- for (const validator of validators) {
47
- const error = validator(value);
48
- if (error) {
49
- return error;
50
- }
51
- }
52
- return null;
53
- };
54
- }
55
-
56
- export { compose, email, max, maxLength, min, minLength, pattern, required };
@@ -1,80 +0,0 @@
1
- const globalStructuredClone = typeof globalThis === 'object' && globalThis !== null ? globalThis.structuredClone : undefined;
2
- function deepClone(value) {
3
- if (globalStructuredClone) {
4
- try {
5
- return globalStructuredClone(value);
6
- } catch (_a) {}
7
- }
8
- return cloneValue(value, new WeakMap());
9
- }
10
- function cloneValue(value, seen) {
11
- if (value === null || typeof value !== 'object') {
12
- return value;
13
- }
14
- if (typeof value === 'function') {
15
- return value;
16
- }
17
- const existing = seen.get(value);
18
- if (existing) {
19
- return existing;
20
- }
21
- if (value instanceof Date) {
22
- return new Date(value.getTime());
23
- }
24
- if (value instanceof RegExp) {
25
- return new RegExp(value.source, value.flags);
26
- }
27
- if (value instanceof Map) {
28
- const result = new Map();
29
- seen.set(value, result);
30
- for (const [key, entryValue] of value) {
31
- result.set(cloneValue(key, seen), cloneValue(entryValue, seen));
32
- }
33
- return result;
34
- }
35
- if (value instanceof Set) {
36
- const result = new Set();
37
- seen.set(value, result);
38
- for (const entry of value) {
39
- result.add(cloneValue(entry, seen));
40
- }
41
- return result;
42
- }
43
- if (Array.isArray(value)) {
44
- const result = new Array(value.length);
45
- seen.set(value, result);
46
- for (let i = 0; i < value.length; i++) {
47
- result[i] = cloneValue(value[i], seen);
48
- }
49
- return result;
50
- }
51
- if (ArrayBuffer.isView(value)) {
52
- if (value instanceof DataView) {
53
- const bufferClone = cloneValue(value.buffer, seen);
54
- return new DataView(bufferClone, value.byteOffset, value.byteLength);
55
- }
56
- const viewWithSlice = value;
57
- if (typeof viewWithSlice.slice === 'function') {
58
- return viewWithSlice.slice();
59
- }
60
- const bufferClone = cloneValue(value.buffer, seen);
61
- return new value.constructor(bufferClone, value.byteOffset, value.length);
62
- }
63
- if (value instanceof ArrayBuffer) {
64
- return value.slice(0);
65
- }
66
- const proto = Object.getPrototypeOf(value);
67
- const result = proto ? Object.create(proto) : {};
68
- seen.set(value, result);
69
- for (const key of Reflect.ownKeys(value)) {
70
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
71
- if (!descriptor) continue;
72
- if ('value' in descriptor) {
73
- descriptor.value = cloneValue(descriptor.value, seen);
74
- }
75
- Object.defineProperty(result, key, descriptor);
76
- }
77
- return result;
78
- }
79
-
80
- export { deepClone };
@@ -1,113 +0,0 @@
1
- import { signal } from '@angular/core';
2
- import { deepClone } from '../deep-clone.js';
3
- import { snapshotsEqual } from '../snapshots-equal.js';
4
-
5
- function withFormHistory(formTree, options = {}) {
6
- const capacity = Math.max(1, options.capacity ?? 10);
7
- const historySignal = signal({
8
- past: [],
9
- present: deepClone(formTree.form.getRawValue()),
10
- future: []
11
- });
12
- let recording = true;
13
- let suppressUpdates = 0;
14
- let internalHistory = {
15
- past: [],
16
- present: deepClone(formTree.form.getRawValue()),
17
- future: []
18
- };
19
- const subscription = formTree.form.valueChanges.subscribe(() => {
20
- if (suppressUpdates > 0) {
21
- suppressUpdates--;
22
- return;
23
- }
24
- if (!recording) {
25
- internalHistory = {
26
- ...internalHistory,
27
- present: deepClone(formTree.form.getRawValue())
28
- };
29
- return;
30
- }
31
- const snapshot = deepClone(formTree.form.getRawValue());
32
- if (snapshotsEqual(internalHistory.present, snapshot)) {
33
- internalHistory = {
34
- ...internalHistory,
35
- present: snapshot
36
- };
37
- historySignal.set(cloneHistory(internalHistory));
38
- return;
39
- }
40
- const updatedPast = [...internalHistory.past, internalHistory.present];
41
- if (updatedPast.length > capacity) {
42
- updatedPast.shift();
43
- }
44
- internalHistory = {
45
- past: updatedPast,
46
- present: snapshot,
47
- future: []
48
- };
49
- historySignal.set(cloneHistory(internalHistory));
50
- });
51
- const originalDestroy = formTree.destroy;
52
- formTree.destroy = () => {
53
- subscription.unsubscribe();
54
- originalDestroy();
55
- };
56
- const undo = () => {
57
- const history = historySignal();
58
- if (history.past.length === 0) {
59
- return;
60
- }
61
- const previous = deepClone(history.past[history.past.length - 1]);
62
- recording = false;
63
- suppressUpdates++;
64
- formTree.setValues(previous);
65
- recording = true;
66
- internalHistory = {
67
- past: history.past.slice(0, -1),
68
- present: previous,
69
- future: [history.present, ...history.future]
70
- };
71
- historySignal.set(cloneHistory(internalHistory));
72
- };
73
- const redo = () => {
74
- const history = historySignal();
75
- if (history.future.length === 0) {
76
- return;
77
- }
78
- const next = deepClone(history.future[0]);
79
- recording = false;
80
- suppressUpdates++;
81
- formTree.setValues(next);
82
- recording = true;
83
- internalHistory = {
84
- past: [...history.past, history.present],
85
- present: next,
86
- future: history.future.slice(1)
87
- };
88
- historySignal.set(cloneHistory(internalHistory));
89
- };
90
- const clearHistory = () => {
91
- internalHistory = {
92
- past: [],
93
- present: deepClone(formTree.form.getRawValue()),
94
- future: []
95
- };
96
- historySignal.set(cloneHistory(internalHistory));
97
- };
98
- function cloneHistory(state) {
99
- return {
100
- past: state.past.map(entry => deepClone(entry)),
101
- present: deepClone(state.present),
102
- future: state.future.map(entry => deepClone(entry))
103
- };
104
- }
105
- return Object.assign(formTree, {
106
- undo,
107
- redo,
108
- clearHistory,
109
- history: historySignal.asReadonly()
110
- });
111
- }
112
-
113
- export { withFormHistory };
package/dist/lru-cache.js DELETED
@@ -1,64 +0,0 @@
1
- class LRUCache {
2
- constructor(maxSize) {
3
- this.maxSize = maxSize;
4
- this.cache = new Map();
5
- if (!Number.isFinite(maxSize) || maxSize <= 0) {
6
- throw new Error('LRUCache maxSize must be a positive, finite number');
7
- }
8
- }
9
- set(key, value) {
10
- if (this.cache.has(key)) {
11
- this.cache.delete(key);
12
- }
13
- this.cache.set(key, value);
14
- if (this.cache.size > this.maxSize) {
15
- const oldestKey = this.cache.keys().next().value;
16
- if (oldestKey !== undefined) {
17
- this.cache.delete(oldestKey);
18
- }
19
- }
20
- }
21
- get(key) {
22
- if (!this.cache.has(key)) return undefined;
23
- const value = this.cache.get(key);
24
- if (value !== undefined) {
25
- this.cache.delete(key);
26
- this.cache.set(key, value);
27
- }
28
- return value;
29
- }
30
- delete(key) {
31
- this.cache.delete(key);
32
- }
33
- has(key) {
34
- return this.cache.has(key);
35
- }
36
- clear() {
37
- this.cache.clear();
38
- }
39
- size() {
40
- return this.cache.size;
41
- }
42
- forEach(callback) {
43
- this.cache.forEach((value, key) => callback(value, key));
44
- }
45
- entries() {
46
- return this.cache.entries();
47
- }
48
- keys() {
49
- return this.cache.keys();
50
- }
51
- resize(newSize) {
52
- if (!Number.isFinite(newSize) || newSize <= 0) {
53
- throw new Error('LRUCache newSize must be a positive, finite number');
54
- }
55
- this.maxSize = newSize;
56
- while (this.cache.size > this.maxSize) {
57
- const oldestKey = this.cache.keys().next().value;
58
- if (oldestKey === undefined) break;
59
- this.cache.delete(oldestKey);
60
- }
61
- }
62
- }
63
-
64
- export { LRUCache };
@@ -1,13 +0,0 @@
1
- function matchPath(pattern, path) {
2
- if (pattern === path) {
3
- return true;
4
- }
5
- const patternSegments = pattern.split('.');
6
- const pathSegments = path.split('.');
7
- if (patternSegments.length !== pathSegments.length) {
8
- return false;
9
- }
10
- return patternSegments.every((segment, index) => segment === '*' || segment === pathSegments[index]);
11
- }
12
-
13
- export { matchPath };
@@ -1,26 +0,0 @@
1
- import { deepClone } from './deep-clone.js';
2
-
3
- function mergeDeep(target, source) {
4
- if (!source || typeof source !== 'object') {
5
- return target;
6
- }
7
- const targetObj = target;
8
- const sourceObj = source;
9
- for (const [key, value] of Object.entries(sourceObj)) {
10
- if (value === undefined) {
11
- continue;
12
- }
13
- const current = targetObj[key];
14
- if (isPlainObject(current) && isPlainObject(value)) {
15
- targetObj[key] = mergeDeep(deepClone(current), value);
16
- continue;
17
- }
18
- targetObj[key] = deepClone(value);
19
- }
20
- return target;
21
- }
22
- function isPlainObject(value) {
23
- return !!value && typeof value === 'object' && !Array.isArray(value) && Object.prototype.toString.call(value) === '[object Object]';
24
- }
25
-
26
- export { mergeDeep };
@@ -1,13 +0,0 @@
1
- import { DEFAULT_PATH_CACHE_SIZE } from './constants.js';
2
- import { LRUCache } from './lru-cache.js';
3
-
4
- const pathCache = new LRUCache(DEFAULT_PATH_CACHE_SIZE);
5
- function parsePath(path) {
6
- const cached = pathCache.get(path);
7
- if (cached) return cached;
8
- const segments = path.split('.');
9
- pathCache.set(path, segments);
10
- return segments;
11
- }
12
-
13
- export { parsePath };
@@ -1,5 +0,0 @@
1
- function snapshotsEqual(a, b) {
2
- return JSON.stringify(a) === JSON.stringify(b);
3
- }
4
-
5
- export { snapshotsEqual };
package/dist/tslib.es6.js DELETED
@@ -1,34 +0,0 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
16
-
17
-
18
- function __decorate(decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- }
24
-
25
- function __metadata(metadataKey, metadataValue) {
26
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
27
- }
28
-
29
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
30
- var e = new Error(message);
31
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
- };
33
-
34
- export { __decorate, __metadata };