@signaltree/core 7.1.3 → 7.1.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.
Files changed (100) hide show
  1. package/README.md +28 -13
  2. package/package.json +2 -2
  3. package/dist/constants.js +0 -6
  4. package/dist/deep-equal.js +0 -41
  5. package/dist/enhancers/batching/batching.js +0 -230
  6. package/dist/enhancers/devtools/devtools.js +0 -318
  7. package/dist/enhancers/effects/effects.js +0 -66
  8. package/dist/enhancers/entities/entities.js +0 -7
  9. package/dist/enhancers/index.js +0 -72
  10. package/dist/enhancers/memoization/memoization.js +0 -420
  11. package/dist/enhancers/presets/lib/presets.js +0 -27
  12. package/dist/enhancers/serialization/constants.js +0 -15
  13. package/dist/enhancers/serialization/serialization.js +0 -656
  14. package/dist/enhancers/time-travel/time-travel.js +0 -283
  15. package/dist/enhancers/time-travel/utils.js +0 -11
  16. package/dist/enhancers/utils/copy-tree-properties.js +0 -20
  17. package/dist/index.js +0 -26
  18. package/dist/is-built-in-object.js +0 -23
  19. package/dist/lib/async-helpers.js +0 -77
  20. package/dist/lib/constants.js +0 -56
  21. package/dist/lib/edit-session.js +0 -84
  22. package/dist/lib/entity-signal.js +0 -544
  23. package/dist/lib/internals/batch-scope.js +0 -8
  24. package/dist/lib/internals/derived-types.js +0 -5
  25. package/dist/lib/internals/materialize-markers.js +0 -72
  26. package/dist/lib/internals/merge-derived.js +0 -59
  27. package/dist/lib/markers/derived.js +0 -6
  28. package/dist/lib/markers/entity-map.js +0 -20
  29. package/dist/lib/markers/status.js +0 -71
  30. package/dist/lib/markers/stored.js +0 -111
  31. package/dist/lib/memory/memory-manager.js +0 -164
  32. package/dist/lib/path-notifier.js +0 -178
  33. package/dist/lib/presets.js +0 -20
  34. package/dist/lib/security/security-validator.js +0 -121
  35. package/dist/lib/signal-tree.js +0 -415
  36. package/dist/lib/types.js +0 -3
  37. package/dist/lib/utils.js +0 -264
  38. package/dist/lru-cache.js +0 -64
  39. package/dist/parse-path.js +0 -13
  40. package/src/enhancers/batching/batching.d.ts +0 -10
  41. package/src/enhancers/batching/batching.types.d.ts +0 -1
  42. package/src/enhancers/batching/index.d.ts +0 -1
  43. package/src/enhancers/batching/test-setup.d.ts +0 -3
  44. package/src/enhancers/devtools/devtools.d.ts +0 -68
  45. package/src/enhancers/devtools/devtools.types.d.ts +0 -1
  46. package/src/enhancers/devtools/index.d.ts +0 -1
  47. package/src/enhancers/devtools/test-setup.d.ts +0 -3
  48. package/src/enhancers/effects/effects.d.ts +0 -9
  49. package/src/enhancers/effects/effects.types.d.ts +0 -1
  50. package/src/enhancers/effects/index.d.ts +0 -1
  51. package/src/enhancers/entities/entities.d.ts +0 -7
  52. package/src/enhancers/entities/entities.types.d.ts +0 -1
  53. package/src/enhancers/entities/index.d.ts +0 -1
  54. package/src/enhancers/entities/test-setup.d.ts +0 -3
  55. package/src/enhancers/index.d.ts +0 -3
  56. package/src/enhancers/memoization/index.d.ts +0 -1
  57. package/src/enhancers/memoization/memoization.d.ts +0 -54
  58. package/src/enhancers/memoization/memoization.types.d.ts +0 -1
  59. package/src/enhancers/memoization/test-setup.d.ts +0 -3
  60. package/src/enhancers/presets/index.d.ts +0 -1
  61. package/src/enhancers/presets/lib/presets.d.ts +0 -8
  62. package/src/enhancers/serialization/constants.d.ts +0 -14
  63. package/src/enhancers/serialization/index.d.ts +0 -2
  64. package/src/enhancers/serialization/serialization.d.ts +0 -68
  65. package/src/enhancers/serialization/test-setup.d.ts +0 -3
  66. package/src/enhancers/test-helpers/types-equals.d.ts +0 -2
  67. package/src/enhancers/time-travel/index.d.ts +0 -1
  68. package/src/enhancers/time-travel/test-setup.d.ts +0 -3
  69. package/src/enhancers/time-travel/time-travel.d.ts +0 -10
  70. package/src/enhancers/time-travel/time-travel.types.d.ts +0 -1
  71. package/src/enhancers/time-travel/utils.d.ts +0 -2
  72. package/src/enhancers/types.d.ts +0 -1
  73. package/src/enhancers/typing/helpers-types.d.ts +0 -2
  74. package/src/enhancers/utils/copy-tree-properties.d.ts +0 -1
  75. package/src/index.d.ts +0 -26
  76. package/src/lib/async-helpers.d.ts +0 -8
  77. package/src/lib/constants.d.ts +0 -41
  78. package/src/lib/dev-proxy.d.ts +0 -3
  79. package/src/lib/edit-session.d.ts +0 -21
  80. package/src/lib/entity-signal.d.ts +0 -1
  81. package/src/lib/internals/batch-scope.d.ts +0 -3
  82. package/src/lib/internals/builder-types.d.ts +0 -13
  83. package/src/lib/internals/derived-types.d.ts +0 -18
  84. package/src/lib/internals/materialize-markers.d.ts +0 -5
  85. package/src/lib/internals/merge-derived.d.ts +0 -4
  86. package/src/lib/markers/derived.d.ts +0 -9
  87. package/src/lib/markers/entity-map.d.ts +0 -4
  88. package/src/lib/markers/index.d.ts +0 -3
  89. package/src/lib/markers/status.d.ts +0 -32
  90. package/src/lib/markers/stored.d.ts +0 -23
  91. package/src/lib/memory/memory-manager.d.ts +0 -30
  92. package/src/lib/path-notifier.d.ts +0 -34
  93. package/src/lib/performance/diff-engine.d.ts +0 -33
  94. package/src/lib/performance/path-index.d.ts +0 -25
  95. package/src/lib/performance/update-engine.d.ts +0 -32
  96. package/src/lib/presets.d.ts +0 -34
  97. package/src/lib/security/security-validator.d.ts +0 -33
  98. package/src/lib/signal-tree.d.ts +0 -6
  99. package/src/lib/types.d.ts +0 -300
  100. package/src/lib/utils.d.ts +0 -25
@@ -1,283 +0,0 @@
1
- import { snapshotState } from '../../lib/utils.js';
2
- import { deepEqual, deepClone } from './utils.js';
3
-
4
- class TimeTravelManager {
5
- tree;
6
- config;
7
- restoreStateFn;
8
- history = [];
9
- currentIndex = -1;
10
- maxHistorySize;
11
- includePayload;
12
- actionNames;
13
- constructor(tree, config = {}, restoreStateFn) {
14
- this.tree = tree;
15
- this.config = config;
16
- this.restoreStateFn = restoreStateFn;
17
- this.maxHistorySize = config.maxHistorySize ?? 50;
18
- this.includePayload = config.includePayload ?? true;
19
- this.actionNames = {
20
- update: 'UPDATE',
21
- set: 'SET',
22
- batch: 'BATCH',
23
- ...config.actionNames
24
- };
25
- this.addEntry('INIT', this.tree());
26
- }
27
- addEntry(action, state, payload, provisional = false) {
28
- if (this.currentIndex < this.history.length - 1) {
29
- this.history = this.history.slice(0, this.currentIndex + 1);
30
- }
31
- const plain = snapshotState(this.tree.state);
32
- let cloned;
33
- try {
34
- cloned = typeof structuredClone !== 'undefined' ? structuredClone(plain) : JSON.parse(JSON.stringify(plain));
35
- } catch {
36
- cloned = JSON.parse(JSON.stringify(plain));
37
- }
38
- const entry = {
39
- state: cloned,
40
- timestamp: Date.now(),
41
- action: this.actionNames[action] || action,
42
- ...(this.includePayload && payload !== undefined && {
43
- payload
44
- })
45
- };
46
- if (provisional) entry.__provisional = true;
47
- const last = this.history[this.history.length - 1];
48
- if (last && deepEqual(last.state, entry.state)) {
49
- if (last.__provisional) delete last.__provisional;
50
- return;
51
- }
52
- this.history.push(entry);
53
- this.currentIndex = this.history.length - 1;
54
- if (this.history.length > this.maxHistorySize) {
55
- this.history.shift();
56
- this.currentIndex--;
57
- }
58
- }
59
- undo() {
60
- if (!this.canUndo()) {
61
- return false;
62
- }
63
- this.currentIndex--;
64
- const entry = this.history[this.currentIndex];
65
- this.restoreState(entry.state);
66
- return true;
67
- }
68
- finalizeProvisional(state) {
69
- const last = this.history[this.history.length - 1];
70
- if (last && last.__provisional) {
71
- if (deepEqual(last.state, state)) {
72
- delete last.__provisional;
73
- return;
74
- }
75
- last.state = deepClone(state);
76
- last.timestamp = Date.now();
77
- delete last.__provisional;
78
- return;
79
- }
80
- this.addEntry('update', state);
81
- }
82
- redo() {
83
- if (!this.canRedo()) {
84
- return false;
85
- }
86
- this.currentIndex++;
87
- const entry = this.history[this.currentIndex];
88
- this.restoreState(entry.state);
89
- return true;
90
- }
91
- getHistory() {
92
- return this.history.map(entry => ({
93
- ...entry,
94
- state: deepClone(entry.state)
95
- }));
96
- }
97
- resetHistory() {
98
- const currentState = this.tree();
99
- this.history = [];
100
- this.currentIndex = -1;
101
- this.addEntry('RESET', currentState);
102
- }
103
- jumpTo(index) {
104
- if (index < 0 || index >= this.history.length) {
105
- return false;
106
- }
107
- this.currentIndex = index;
108
- const entry = this.history[index];
109
- this.restoreState(entry.state);
110
- return true;
111
- }
112
- getCurrentIndex() {
113
- return this.currentIndex;
114
- }
115
- canUndo() {
116
- return this.currentIndex > 0;
117
- }
118
- canRedo() {
119
- return this.currentIndex < this.history.length - 1;
120
- }
121
- restoreState(state) {
122
- if (this.restoreStateFn) {
123
- this.restoreStateFn(state);
124
- } else {
125
- this.tree(state);
126
- }
127
- }
128
- }
129
- function timeTravel(config = {}) {
130
- const {
131
- enabled = true
132
- } = config;
133
- return tree => {
134
- if (!enabled) {
135
- const noopMethods = {
136
- undo() {},
137
- redo() {},
138
- canUndo() {
139
- return false;
140
- },
141
- canRedo() {
142
- return false;
143
- },
144
- getHistory() {
145
- return [];
146
- },
147
- resetHistory() {},
148
- jumpTo(_index) {
149
- },
150
- getCurrentIndex() {
151
- return -1;
152
- }
153
- };
154
- return Object.assign(tree, noopMethods);
155
- }
156
- const originalTreeCall = tree.bind(tree);
157
- let isRestoring = false;
158
- const timeTravelManager = new TimeTravelManager(tree, config, state => {
159
- isRestoring = true;
160
- try {
161
- originalTreeCall(state);
162
- } finally {
163
- isRestoring = false;
164
- }
165
- });
166
- try {
167
- const req = globalThis['require'];
168
- if (typeof req === 'function') {
169
- const {
170
- getPathNotifier
171
- } = req('../../lib/path-notifier');
172
- const notifier = getPathNotifier();
173
- if (notifier && typeof notifier.onFlush === 'function') {
174
- notifier.onFlush(() => {
175
- if (isRestoring) return;
176
- const afterState = originalTreeCall();
177
- timeTravelManager.addEntry('batch', afterState);
178
- });
179
- }
180
- }
181
- } catch {}
182
- const enhancedTree = function (...args) {
183
- if (args.length === 0) {
184
- return originalTreeCall();
185
- } else {
186
- if (isRestoring) {
187
- if (args.length === 1) {
188
- const arg = args[0];
189
- if (typeof arg === 'function') {
190
- return originalTreeCall(arg);
191
- } else {
192
- return originalTreeCall(arg);
193
- }
194
- }
195
- return;
196
- }
197
- const beforeState = originalTreeCall();
198
- let result;
199
- if (args.length === 1) {
200
- const arg = args[0];
201
- if (typeof arg === 'function') {
202
- result = originalTreeCall(arg);
203
- } else {
204
- result = originalTreeCall(arg);
205
- }
206
- }
207
- const afterState = originalTreeCall();
208
- if (!deepEqual(beforeState, afterState)) {
209
- timeTravelManager.addEntry('update', afterState);
210
- }
211
- return result;
212
- }
213
- };
214
- Object.setPrototypeOf(enhancedTree, Object.getPrototypeOf(tree));
215
- Object.assign(enhancedTree, tree);
216
- Object.defineProperty(enhancedTree, 'with', {
217
- value: function (enhancer) {
218
- if (typeof enhancer !== 'function') {
219
- throw new Error('Enhancer must be a function');
220
- }
221
- return enhancer(enhancedTree);
222
- },
223
- writable: false,
224
- enumerable: false,
225
- configurable: true
226
- });
227
- if ('state' in tree) {
228
- Object.defineProperty(enhancedTree, 'state', {
229
- value: tree.state,
230
- enumerable: false,
231
- configurable: true
232
- });
233
- }
234
- if ('$' in tree) {
235
- Object.defineProperty(enhancedTree, '$', {
236
- value: tree.$,
237
- enumerable: false,
238
- configurable: true
239
- });
240
- }
241
- enhancedTree['undo'] = () => {
242
- timeTravelManager.undo();
243
- };
244
- enhancedTree['redo'] = () => {
245
- timeTravelManager.redo();
246
- };
247
- enhancedTree['getHistory'] = () => timeTravelManager.getHistory();
248
- enhancedTree['resetHistory'] = () => {
249
- timeTravelManager.resetHistory();
250
- };
251
- enhancedTree['jumpTo'] = index => {
252
- timeTravelManager.jumpTo(index);
253
- };
254
- enhancedTree['canUndo'] = () => timeTravelManager.canUndo();
255
- enhancedTree['canRedo'] = () => timeTravelManager.canRedo();
256
- enhancedTree['getCurrentIndex'] = () => timeTravelManager.getCurrentIndex();
257
- enhancedTree['__timeTravel'] = timeTravelManager;
258
- return enhancedTree;
259
- };
260
- }
261
- function enableTimeTravel() {
262
- return timeTravel({
263
- enabled: true
264
- });
265
- }
266
- function timeTravelHistory(maxHistorySize) {
267
- return timeTravel({
268
- maxHistorySize
269
- });
270
- }
271
- Object.assign((config = {}) => timeTravel(config), {
272
- minimal: () => timeTravel({
273
- maxHistorySize: 20,
274
- includePayload: false
275
- }),
276
- debug: () => timeTravel({
277
- maxHistorySize: 200,
278
- includePayload: true
279
- }),
280
- history: timeTravelHistory
281
- });
282
-
283
- export { enableTimeTravel, timeTravel, timeTravelHistory };
@@ -1,11 +0,0 @@
1
- function deepClone(obj) {
2
- if (typeof structuredClone === 'function') {
3
- return structuredClone(obj);
4
- }
5
- return JSON.parse(JSON.stringify(obj));
6
- }
7
- function deepEqual(a, b) {
8
- return JSON.stringify(a) === JSON.stringify(b);
9
- }
10
-
11
- export { deepClone, deepEqual };
@@ -1,20 +0,0 @@
1
- function copyTreeProperties(source, target) {
2
- const skipKeys = new Set(['state', '$']);
3
- for (const key of Object.getOwnPropertyNames(source)) {
4
- if (skipKeys.has(key)) continue;
5
- if (Object.prototype.hasOwnProperty.call(target, key)) continue;
6
- const descriptor = Object.getOwnPropertyDescriptor(source, key);
7
- if (!descriptor) continue;
8
- if (descriptor.configurable === false) continue;
9
- Object.defineProperty(target, key, descriptor);
10
- }
11
- for (const sym of Object.getOwnPropertySymbols(source)) {
12
- if (Object.prototype.hasOwnProperty.call(target, sym)) continue;
13
- const descriptor = Object.getOwnPropertyDescriptor(source, sym);
14
- if (!descriptor) continue;
15
- if (descriptor.configurable === false) continue;
16
- Object.defineProperty(target, sym, descriptor);
17
- }
18
- }
19
-
20
- export { copyTreeProperties };
package/dist/index.js DELETED
@@ -1,26 +0,0 @@
1
- export { signalTree } from './lib/signal-tree.js';
2
- export { ENHANCER_META } from './lib/types.js';
3
- export { externalDerived } from './lib/internals/derived-types.js';
4
- export { isDerivedMarker } from './lib/markers/derived.js';
5
- export { LoadingState, isStatusMarker, status } from './lib/markers/status.js';
6
- export { isStoredMarker, stored } from './lib/markers/stored.js';
7
- export { registerMarkerProcessor } from './lib/internals/materialize-markers.js';
8
- export { composeEnhancers, createLazySignalTree, isAnySignal, isNodeAccessor, toWritableSignal } from './lib/utils.js';
9
- export { createEditSession } from './lib/edit-session.js';
10
- export { getPathNotifier } from './lib/path-notifier.js';
11
- export { SecurityPresets, SecurityValidator } from './lib/security/security-validator.js';
12
- export { createEnhancer, resolveEnhancerOrder } from './enhancers/index.js';
13
- export { batching, batchingWithConfig, flushBatchedUpdates, getBatchQueueSize, hasPendingUpdates, highPerformanceBatching } from './enhancers/batching/batching.js';
14
- export { clearAllCaches, computedMemoization, deepStateMemoization, getGlobalCacheStats, highFrequencyMemoization, highPerformanceMemoization, lightweightMemoization, memoization, memoize, memoizeReference, memoizeShallow, selectorMemoization, shallowMemoization } from './enhancers/memoization/memoization.js';
15
- export { enableTimeTravel, timeTravel } from './enhancers/time-travel/time-travel.js';
16
- export { enableEntities, entities, highPerformanceEntities } from './enhancers/entities/entities.js';
17
- export { applyPersistence, applySerialization, createIndexedDBAdapter, createStorageAdapter, enableSerialization, persistence, serialization } from './enhancers/serialization/serialization.js';
18
- export { devTools, enableDevTools, fullDevTools, productionDevTools } from './enhancers/devtools/devtools.js';
19
- export { createAsyncOperation, trackAsync } from './lib/async-helpers.js';
20
- export { TREE_PRESETS, combinePresets, createPresetConfig, getAvailablePresets, validatePreset } from './enhancers/presets/lib/presets.js';
21
- export { SIGNAL_TREE_CONSTANTS, SIGNAL_TREE_MESSAGES } from './lib/constants.js';
22
- export { entityMap } from './lib/markers/entity-map.js';
23
- export { deepEqual, deepEqual as equal } from './deep-equal.js';
24
- export { parsePath } from './parse-path.js';
25
- export { isBuiltInObject } from './is-built-in-object.js';
26
- export { createDevTree } from './lib/presets.js';
@@ -1,23 +0,0 @@
1
- function isBuiltInObject(value) {
2
- if (value === null || value === undefined) return false;
3
- if (value instanceof Date || value instanceof RegExp || typeof value === 'function' || value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet || value instanceof ArrayBuffer || value instanceof DataView || value instanceof Error || value instanceof Promise) {
4
- return true;
5
- }
6
- if (value instanceof Int8Array || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int16Array || value instanceof Uint16Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Float32Array || value instanceof Float64Array || value instanceof BigInt64Array || value instanceof BigUint64Array) {
7
- return true;
8
- }
9
- if (typeof window !== 'undefined') {
10
- if (value instanceof URL || value instanceof URLSearchParams || value instanceof FormData || value instanceof Blob || typeof File !== 'undefined' && value instanceof File || typeof FileList !== 'undefined' && value instanceof FileList || typeof Headers !== 'undefined' && value instanceof Headers || typeof Request !== 'undefined' && value instanceof Request || typeof Response !== 'undefined' && value instanceof Response || typeof AbortController !== 'undefined' && value instanceof AbortController || typeof AbortSignal !== 'undefined' && value instanceof AbortSignal) {
11
- return true;
12
- }
13
- }
14
- try {
15
- const NodeBuffer = globalThis === null || globalThis === void 0 ? void 0 : globalThis.Buffer;
16
- if (NodeBuffer && value instanceof NodeBuffer) {
17
- return true;
18
- }
19
- } catch (_a) {}
20
- return false;
21
- }
22
-
23
- export { isBuiltInObject };
@@ -1,77 +0,0 @@
1
- import { signal } from '@angular/core';
2
-
3
- function createAsyncOperation(name, operation) {
4
- return async tree => {
5
- if (typeof tree['batchUpdate'] === 'function') {
6
- const pendingPatch = {
7
- [`${name}_PENDING`]: true
8
- };
9
- tree['batchUpdate'](() => pendingPatch);
10
- } else if ('$' in tree) {
11
- try {
12
- tree['$'][`${name}_PENDING`]?.set?.(true);
13
- } catch (e) {
14
- }
15
- }
16
- try {
17
- const result = await operation();
18
- if (typeof tree['batchUpdate'] === 'function') {
19
- const resultPatch = {
20
- [`${name}_RESULT`]: result,
21
- [`${name}_PENDING`]: false
22
- };
23
- tree['batchUpdate'](() => resultPatch);
24
- } else if ('$' in tree) {
25
- try {
26
- tree['$'][`${name}_RESULT`]?.set?.(result);
27
- tree['$'][`${name}_PENDING`]?.set?.(false);
28
- } catch (e) {
29
- void e;
30
- }
31
- }
32
- return result;
33
- } catch (error) {
34
- if (typeof tree['batchUpdate'] === 'function') {
35
- const errorPatch = {
36
- [`${name}_ERROR`]: error,
37
- [`${name}_PENDING`]: false
38
- };
39
- tree['batchUpdate'](() => errorPatch);
40
- } else if ('$' in tree) {
41
- try {
42
- tree['$'][`${name}_ERROR`]?.set?.(error);
43
- tree['$'][`${name}_PENDING`]?.set?.(false);
44
- } catch (e) {
45
- }
46
- }
47
- throw error;
48
- }
49
- };
50
- }
51
- function trackAsync(operation) {
52
- const pending = signal(false);
53
- const error = signal(null);
54
- const result = signal(null);
55
- return {
56
- pending: pending.asReadonly(),
57
- error: error.asReadonly(),
58
- result: result.asReadonly(),
59
- execute: async () => {
60
- pending.set(true);
61
- error.set(null);
62
- try {
63
- const res = await operation();
64
- result.set(res);
65
- return res;
66
- } catch (e) {
67
- const err = e instanceof Error ? e : new Error(String(e));
68
- error.set(err);
69
- throw err;
70
- } finally {
71
- pending.set(false);
72
- }
73
- }
74
- };
75
- }
76
-
77
- export { createAsyncOperation, trackAsync };
@@ -1,56 +0,0 @@
1
- import { DEFAULT_PATH_CACHE_SIZE } from '../constants.js';
2
-
3
- const SIGNAL_TREE_CONSTANTS = {
4
- MAX_PATH_CACHE_SIZE: DEFAULT_PATH_CACHE_SIZE,
5
- LAZY_THRESHOLD: 50,
6
- ESTIMATE_MAX_DEPTH: 3,
7
- ESTIMATE_SAMPLE_SIZE_ARRAY: 3,
8
- ESTIMATE_SAMPLE_SIZE_OBJECT: 5,
9
- DEFAULT_CACHE_SIZE: 100,
10
- DEFAULT_BATCH_SIZE: 10
11
- };
12
- const DEV_MESSAGES = {
13
- NULL_OR_UNDEFINED: 'null/undefined',
14
- CIRCULAR_REF: 'circular ref',
15
- UPDATER_INVALID: 'updater invalid',
16
- LAZY_FALLBACK: 'lazy fallback',
17
- SIGNAL_CREATION_FAILED: 'signal creation failed',
18
- UPDATE_PATH_NOT_FOUND: 'update path not found',
19
- UPDATE_FAILED: 'update failed',
20
- ROLLBACK_FAILED: 'rollback failed',
21
- CLEANUP_ERROR: 'cleanup error',
22
- PRESET_UNKNOWN: 'unknown preset',
23
- STRATEGY_SELECTION: 'strategy select',
24
- TREE_DESTROYED: 'destroyed',
25
- UPDATE_TRANSACTION: 'update tx',
26
- BATCH_NOT_ENABLED: 'batching disabled',
27
- MEMOIZE_NOT_ENABLED: 'memoize disabled',
28
- MIDDLEWARE_NOT_AVAILABLE: 'middleware missing',
29
- ENTITY_HELPERS_NOT_AVAILABLE: 'entity helpers missing',
30
- TIME_TRAVEL_NOT_AVAILABLE: 'time travel missing',
31
- OPTIMIZE_NOT_AVAILABLE: 'optimize missing',
32
- UPDATE_OPTIMIZED_NOT_AVAILABLE: 'update optimized missing',
33
- CACHE_NOT_AVAILABLE: 'cache missing',
34
- PERFORMANCE_NOT_ENABLED: 'performance disabled',
35
- ENHANCER_ORDER_FAILED: 'enhancer order failed',
36
- ENHANCER_CYCLE_DETECTED: 'enhancer cycle',
37
- ENHANCER_REQUIREMENT_MISSING: 'enhancer req missing',
38
- ENHANCER_PROVIDES_MISSING: 'enhancer provides missing',
39
- ENHANCER_FAILED: 'enhancer failed',
40
- ENHANCER_NOT_FUNCTION: 'enhancer not function',
41
- EFFECT_NO_CONTEXT: 'no angular context',
42
- SUBSCRIBE_NO_CONTEXT: 'no angular context'
43
- };
44
- const PROD_MESSAGES = (() => {
45
- const out = {};
46
- let i = 0;
47
- for (const k of Object.keys(DEV_MESSAGES)) {
48
- out[k] = String(i++);
49
- }
50
- return out;
51
- })();
52
- const _isProdByEnv = Boolean(typeof globalThis === 'object' && globalThis !== null && 'process' in globalThis && typeof globalThis.process === 'object' && 'env' in globalThis.process && globalThis.process.env.NODE_ENV === 'production');
53
- const _isDev = typeof ngDevMode !== 'undefined' ? Boolean(ngDevMode) : !_isProdByEnv;
54
- const SIGNAL_TREE_MESSAGES = Object.freeze(_isDev ? DEV_MESSAGES : PROD_MESSAGES);
55
-
56
- export { SIGNAL_TREE_CONSTANTS, SIGNAL_TREE_MESSAGES };
@@ -1,84 +0,0 @@
1
- import { signal } from '@angular/core';
2
- import { deepEqual } from '../deep-equal.js';
3
-
4
- function clone(value) {
5
- try {
6
- return globalThis.structuredClone ? globalThis.structuredClone(value) : JSON.parse(JSON.stringify(value));
7
- } catch {
8
- return JSON.parse(JSON.stringify(value));
9
- }
10
- }
11
- function createEditSession(initial) {
12
- const original = signal(clone(initial));
13
- const present = signal(clone(initial));
14
- const pastCount = signal(0);
15
- const futureCount = signal(0);
16
- let past = [];
17
- let future = [];
18
- function updateCounts() {
19
- pastCount.set(past.length);
20
- futureCount.set(future.length);
21
- }
22
- const canUndo = () => pastCount() > 0;
23
- const canRedo = () => futureCount() > 0;
24
- const isDirty = () => !deepEqual(original(), present());
25
- function setOriginal(value) {
26
- const v = clone(value);
27
- original.set(v);
28
- present.set(clone(v));
29
- past = [];
30
- future = [];
31
- updateCounts();
32
- }
33
- function applyChanges(valueOrUpdater) {
34
- const current = present();
35
- const next = typeof valueOrUpdater === 'function' ? valueOrUpdater(clone(current)) : valueOrUpdater;
36
- if (deepEqual(current, next)) return;
37
- past.push(clone(current));
38
- present.set(clone(next));
39
- future = [];
40
- updateCounts();
41
- }
42
- function undo() {
43
- if (past.length === 0) return;
44
- const prev = past.pop();
45
- future.push(clone(present()));
46
- present.set(clone(prev));
47
- updateCounts();
48
- }
49
- function redo() {
50
- if (future.length === 0) return;
51
- const next = future.pop();
52
- past.push(clone(present()));
53
- present.set(clone(next));
54
- updateCounts();
55
- }
56
- function reset() {
57
- present.set(clone(original()));
58
- past = [];
59
- future = [];
60
- updateCounts();
61
- }
62
- function getHistory() {
63
- return {
64
- past: past.map(p => clone(p)),
65
- present: clone(present()),
66
- future: future.map(f => clone(f))
67
- };
68
- }
69
- return {
70
- original,
71
- modified: present,
72
- canUndo,
73
- canRedo,
74
- isDirty,
75
- setOriginal,
76
- applyChanges,
77
- undo,
78
- redo,
79
- reset,
80
- getHistory
81
- };
82
- }
83
-
84
- export { createEditSession, createEditSession as default };