@stonecrop/stonecrop 0.31.0 → 0.33.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 (121) hide show
  1. package/dist/stonecrop.js +3548 -2740
  2. package/dist/stonecrop.js.map +1 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/package.json +33 -27
  5. package/dist/src/client-action.d.ts +0 -31
  6. package/dist/src/client-action.d.ts.map +0 -1
  7. package/dist/src/client-action.js +0 -169
  8. package/dist/src/client-handler.d.ts +0 -43
  9. package/dist/src/client-handler.d.ts.map +0 -1
  10. package/dist/src/client-handler.js +0 -42
  11. package/dist/src/composables/lazy-link.d.ts +0 -25
  12. package/dist/src/composables/lazy-link.d.ts.map +0 -1
  13. package/dist/src/composables/lazy-link.js +0 -124
  14. package/dist/src/composables/operation-log.d.ts +0 -136
  15. package/dist/src/composables/operation-log.d.ts.map +0 -1
  16. package/dist/src/composables/operation-log.js +0 -224
  17. package/dist/src/composables/stonecrop.d.ts +0 -37
  18. package/dist/src/composables/stonecrop.d.ts.map +0 -1
  19. package/dist/src/composables/stonecrop.js +0 -433
  20. package/dist/src/doctype.d.ts +0 -243
  21. package/dist/src/doctype.d.ts.map +0 -1
  22. package/dist/src/doctype.js +0 -325
  23. package/dist/src/draft.d.ts +0 -35
  24. package/dist/src/draft.d.ts.map +0 -1
  25. package/dist/src/draft.js +0 -36
  26. package/dist/src/exceptions.d.ts +0 -14
  27. package/dist/src/exceptions.d.ts.map +0 -1
  28. package/dist/src/exceptions.js +0 -16
  29. package/dist/src/field-triggers.d.ts +0 -184
  30. package/dist/src/field-triggers.d.ts.map +0 -1
  31. package/dist/src/field-triggers.js +0 -577
  32. package/dist/src/index.d.ts +0 -25
  33. package/dist/src/index.d.ts.map +0 -1
  34. package/dist/src/index.js +0 -39
  35. package/dist/src/plugins/index.d.ts +0 -35
  36. package/dist/src/plugins/index.d.ts.map +0 -1
  37. package/dist/src/plugins/index.js +0 -98
  38. package/dist/src/registry.d.ts +0 -161
  39. package/dist/src/registry.d.ts.map +0 -1
  40. package/dist/src/registry.js +0 -384
  41. package/dist/src/schema-validator.d.ts +0 -78
  42. package/dist/src/schema-validator.d.ts.map +0 -1
  43. package/dist/src/schema-validator.js +0 -398
  44. package/dist/src/stonecrop.d.ts +0 -539
  45. package/dist/src/stonecrop.d.ts.map +0 -1
  46. package/dist/src/stonecrop.js +0 -610
  47. package/dist/src/stores/hst.d.ts +0 -92
  48. package/dist/src/stores/hst.d.ts.map +0 -1
  49. package/dist/src/stores/hst.js +0 -487
  50. package/dist/src/stores/index.d.ts +0 -9
  51. package/dist/src/stores/index.d.ts.map +0 -1
  52. package/dist/src/stores/index.js +0 -13
  53. package/dist/src/stores/operation-log.d.ts +0 -262
  54. package/dist/src/stores/operation-log.d.ts.map +0 -1
  55. package/dist/src/stores/operation-log.js +0 -571
  56. package/dist/src/stores/validation.d.ts +0 -83
  57. package/dist/src/stores/validation.d.ts.map +0 -1
  58. package/dist/src/stores/validation.js +0 -104
  59. package/dist/src/types/client-action.d.ts +0 -121
  60. package/dist/src/types/client-action.d.ts.map +0 -1
  61. package/dist/src/types/client-action.js +0 -0
  62. package/dist/src/types/composable.d.ts +0 -268
  63. package/dist/src/types/composable.d.ts.map +0 -1
  64. package/dist/src/types/composable.js +0 -0
  65. package/dist/src/types/doctype.d.ts +0 -34
  66. package/dist/src/types/doctype.d.ts.map +0 -1
  67. package/dist/src/types/doctype.js +0 -0
  68. package/dist/src/types/field-triggers.d.ts +0 -186
  69. package/dist/src/types/field-triggers.d.ts.map +0 -1
  70. package/dist/src/types/field-triggers.js +0 -4
  71. package/dist/src/types/hst.d.ts +0 -70
  72. package/dist/src/types/hst.d.ts.map +0 -1
  73. package/dist/src/types/hst.js +0 -0
  74. package/dist/src/types/index.d.ts +0 -11
  75. package/dist/src/types/index.d.ts.map +0 -1
  76. package/dist/src/types/index.js +0 -11
  77. package/dist/src/types/operation-log.d.ts +0 -163
  78. package/dist/src/types/operation-log.d.ts.map +0 -1
  79. package/dist/src/types/operation-log.js +0 -0
  80. package/dist/src/types/plugin.d.ts +0 -37
  81. package/dist/src/types/plugin.d.ts.map +0 -1
  82. package/dist/src/types/plugin.js +0 -0
  83. package/dist/src/types/registry.d.ts +0 -11
  84. package/dist/src/types/registry.d.ts.map +0 -1
  85. package/dist/src/types/registry.js +0 -0
  86. package/dist/src/types/schema-validator.d.ts +0 -66
  87. package/dist/src/types/schema-validator.d.ts.map +0 -1
  88. package/dist/src/types/schema-validator.js +0 -13
  89. package/dist/src/types/stonecrop.d.ts +0 -32
  90. package/dist/src/types/stonecrop.d.ts.map +0 -1
  91. package/dist/src/types/stonecrop.js +0 -0
  92. package/dist/stonecrop.tsbuildinfo +0 -1
  93. package/src/client-action.ts +0 -207
  94. package/src/client-handler.ts +0 -55
  95. package/src/composables/lazy-link.ts +0 -145
  96. package/src/composables/operation-log.ts +0 -257
  97. package/src/composables/stonecrop.ts +0 -556
  98. package/src/doctype.ts +0 -360
  99. package/src/draft.ts +0 -38
  100. package/src/exceptions.ts +0 -16
  101. package/src/field-triggers.ts +0 -686
  102. package/src/index.ts +0 -81
  103. package/src/plugins/index.ts +0 -113
  104. package/src/registry.ts +0 -433
  105. package/src/schema-validator.ts +0 -476
  106. package/src/stonecrop.ts +0 -721
  107. package/src/stores/hst.ts +0 -626
  108. package/src/stores/index.ts +0 -21
  109. package/src/stores/operation-log.ts +0 -675
  110. package/src/stores/validation.ts +0 -138
  111. package/src/types/client-action.ts +0 -121
  112. package/src/types/composable.ts +0 -288
  113. package/src/types/doctype.ts +0 -35
  114. package/src/types/field-triggers.ts +0 -201
  115. package/src/types/hst.ts +0 -77
  116. package/src/types/index.ts +0 -11
  117. package/src/types/operation-log.ts +0 -202
  118. package/src/types/plugin.ts +0 -38
  119. package/src/types/registry.ts +0 -10
  120. package/src/types/schema-validator.ts +0 -69
  121. package/src/types/stonecrop.ts +0 -33
@@ -1,571 +0,0 @@
1
- import { defineStore } from 'pinia';
2
- import { ref, computed, watch } from 'vue';
3
- import { useLocalStorage } from '@vueuse/core';
4
- /**
5
- * Generate a UUID using crypto API or fallback
6
- */
7
- function generateId() {
8
- if (typeof crypto !== 'undefined' && crypto.randomUUID) {
9
- return crypto.randomUUID();
10
- }
11
- // Fallback for environments without crypto.randomUUID
12
- return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
13
- }
14
- function serializeForBroadcast(message) {
15
- const serialized = {
16
- type: message.type,
17
- clientId: message.clientId,
18
- timestamp: message.timestamp.toISOString(),
19
- };
20
- if (message.operation) {
21
- serialized.operation = {
22
- ...message.operation,
23
- timestamp: message.operation.timestamp.toISOString(),
24
- };
25
- }
26
- if (message.operations) {
27
- serialized.operations = message.operations.map(op => ({
28
- ...op,
29
- timestamp: op.timestamp.toISOString(),
30
- }));
31
- }
32
- return serialized;
33
- }
34
- /**
35
- * Deserialize a message from BroadcastChannel
36
- * Converts ISO strings back to Date objects
37
- */
38
- function deserializeFromBroadcast(serialized) {
39
- const message = {
40
- type: serialized.type,
41
- clientId: serialized.clientId,
42
- timestamp: new Date(serialized.timestamp),
43
- };
44
- if (serialized.operation) {
45
- message.operation = {
46
- ...serialized.operation,
47
- timestamp: new Date(serialized.operation.timestamp),
48
- };
49
- }
50
- if (serialized.operations) {
51
- message.operations = serialized.operations.map(op => ({
52
- ...op,
53
- timestamp: new Date(op.timestamp),
54
- }));
55
- }
56
- return message;
57
- }
58
- /**
59
- * Revert an operation (apply beforeValue)
60
- */
61
- function revertOperation(operation, store) {
62
- if ((operation.type === 'set' || operation.type === 'delete') && store && typeof store.set === 'function') {
63
- store.set(operation.path, operation.beforeValue, 'undo');
64
- }
65
- }
66
- /**
67
- * Apply an operation (apply afterValue)
68
- */
69
- function applyOperation(operation, store) {
70
- if ((operation.type === 'set' || operation.type === 'delete') && store && typeof store.set === 'function') {
71
- store.set(operation.path, operation.afterValue, 'redo');
72
- }
73
- }
74
- /**
75
- * Global HST Operation Log Store
76
- * Tracks all mutations with full metadata for undo/redo, sync, and audit
77
- *
78
- * @public
79
- */
80
- export const useOperationLogStore = defineStore('hst-operation-log', () => {
81
- // Configuration
82
- const config = ref({
83
- maxOperations: 100,
84
- enableCrossTabSync: true,
85
- enablePersistence: false,
86
- persistenceKeyPrefix: 'stonecrop-ops',
87
- });
88
- // State
89
- const operations = ref([]);
90
- const currentIndex = ref(-1); // Points to the last applied operation
91
- const clientId = ref(generateId());
92
- const batchMode = ref(false);
93
- const batchStack = ref([]);
94
- // Computed
95
- const canUndo = computed(() => {
96
- // Can undo if there are operations and we're not at the beginning
97
- if (currentIndex.value < 0)
98
- return false;
99
- // Check if the operation at currentIndex is reversible
100
- const operation = operations.value[currentIndex.value];
101
- return operation?.reversible ?? false;
102
- });
103
- const canRedo = computed(() => {
104
- // Can redo if there are operations ahead of current index
105
- return currentIndex.value < operations.value.length - 1;
106
- });
107
- const undoCount = computed(() => {
108
- let count = 0;
109
- for (let i = currentIndex.value; i >= 0; i--) {
110
- if (operations.value[i]?.reversible)
111
- count++;
112
- else
113
- break;
114
- }
115
- return count;
116
- });
117
- const redoCount = computed(() => {
118
- return operations.value.length - 1 - currentIndex.value;
119
- });
120
- const undoRedoState = computed(() => ({
121
- canUndo: canUndo.value,
122
- canRedo: canRedo.value,
123
- undoCount: undoCount.value,
124
- redoCount: redoCount.value,
125
- currentIndex: currentIndex.value,
126
- }));
127
- // Core Methods
128
- /**
129
- * Configure the operation log
130
- */
131
- function configure(options) {
132
- config.value = { ...config.value, ...options };
133
- // Set up persistence if enabled
134
- if (config.value.enablePersistence) {
135
- loadFromPersistence();
136
- setupPersistenceWatcher();
137
- }
138
- // Set up cross-tab sync if enabled
139
- if (config.value.enableCrossTabSync) {
140
- setupCrossTabSync();
141
- }
142
- }
143
- /**
144
- * Add an operation to the log
145
- */
146
- function addOperation(operation, source = 'user') {
147
- const fullOperation = {
148
- ...operation,
149
- id: generateId(),
150
- timestamp: new Date(),
151
- source: source,
152
- userId: config.value.userId,
153
- };
154
- // Apply filter if configured
155
- if (config.value.operationFilter && !config.value.operationFilter(fullOperation)) {
156
- return fullOperation.id;
157
- }
158
- // If in batch mode, collect operations in current batch
159
- if (batchMode.value && batchStack.value.length > 0) {
160
- batchStack.value[batchStack.value.length - 1].operations.push(fullOperation);
161
- return fullOperation.id;
162
- }
163
- // Remove any operations after current index (they become invalid after new operation)
164
- if (currentIndex.value < operations.value.length - 1) {
165
- operations.value = operations.value.slice(0, currentIndex.value + 1);
166
- }
167
- // Add new operation
168
- operations.value.push(fullOperation);
169
- currentIndex.value++;
170
- // Enforce max operations limit
171
- if (config.value.maxOperations && operations.value.length > config.value.maxOperations) {
172
- const overflow = operations.value.length - config.value.maxOperations;
173
- operations.value = operations.value.slice(overflow);
174
- currentIndex.value -= overflow;
175
- }
176
- // Broadcast to other tabs
177
- if (config.value.enableCrossTabSync) {
178
- broadcastOperation(fullOperation);
179
- }
180
- return fullOperation.id;
181
- }
182
- /**
183
- * Start batch mode - collect multiple operations
184
- */
185
- function startBatch() {
186
- batchMode.value = true;
187
- batchStack.value.push({
188
- id: generateId(),
189
- operations: [],
190
- });
191
- }
192
- /**
193
- * Commit batch - create a single batch operation
194
- */
195
- function commitBatch(description) {
196
- if (!batchMode.value || batchStack.value.length === 0) {
197
- return null;
198
- }
199
- const currentBatchData = batchStack.value.pop();
200
- const batchOperations = currentBatchData.operations;
201
- if (batchOperations.length === 0) {
202
- // Empty batch - just pop and continue if there are outer batches
203
- if (batchStack.value.length === 0) {
204
- batchMode.value = false;
205
- }
206
- return null;
207
- }
208
- const batchId = currentBatchData.id;
209
- const allReversible = batchOperations.every(op => op.reversible);
210
- // Create ancestor batch operation
211
- const batchOperation = {
212
- id: batchId,
213
- type: 'batch',
214
- path: '', // Batch doesn't have a single path
215
- fieldname: '',
216
- beforeValue: null,
217
- afterValue: null,
218
- doctype: batchOperations[0]?.doctype || '',
219
- timestamp: new Date(),
220
- source: 'user',
221
- reversible: allReversible,
222
- irreversibleReason: allReversible ? undefined : 'Contains irreversible operations',
223
- descendantOperationIds: batchOperations.map(op => op.id),
224
- metadata: { description },
225
- };
226
- // Add ancestor operation ID to all descendants
227
- batchOperations.forEach(op => {
228
- op.ancestorOperationId = batchId;
229
- });
230
- // If we're inside a ancestor batch, add this batch as a descendant of the ancestor
231
- if (batchStack.value.length > 0) {
232
- // Nested batch - add the batch operation to the ancestor batch
233
- batchStack.value[batchStack.value.length - 1].operations.push(batchOperation);
234
- }
235
- else {
236
- // Top-level batch - add to the operations log
237
- operations.value.push(...batchOperations, batchOperation);
238
- currentIndex.value = operations.value.length - 1;
239
- }
240
- // Broadcast batch
241
- if (config.value.enableCrossTabSync) {
242
- broadcastBatch(batchOperations, batchOperation);
243
- }
244
- // If no more batches on stack, exit batch mode
245
- if (batchStack.value.length === 0) {
246
- batchMode.value = false;
247
- }
248
- return batchId;
249
- }
250
- /**
251
- * Cancel batch mode without committing
252
- */
253
- function cancelBatch() {
254
- batchStack.value = [];
255
- batchMode.value = false;
256
- }
257
- /**
258
- * Undo the last operation
259
- */
260
- function undo(store) {
261
- if (!canUndo.value)
262
- return false;
263
- const operation = operations.value[currentIndex.value];
264
- if (!operation.reversible) {
265
- // Warn about irreversible operation
266
- if (typeof console !== 'undefined' && operation.irreversibleReason) {
267
- console.warn('Cannot undo irreversible operation:', operation.irreversibleReason);
268
- }
269
- return false;
270
- }
271
- try {
272
- // Handle batch operations
273
- if (operation.type === 'batch' && operation.descendantOperationIds) {
274
- // Undo all descendant operations in reverse order
275
- for (let i = operation.descendantOperationIds.length - 1; i >= 0; i--) {
276
- const descendantId = operation.descendantOperationIds[i];
277
- const descendantOp = operations.value.find(op => op.id === descendantId);
278
- if (descendantOp) {
279
- revertOperation(descendantOp, store);
280
- }
281
- }
282
- }
283
- else {
284
- // Undo single operation
285
- revertOperation(operation, store);
286
- }
287
- currentIndex.value--;
288
- // Broadcast undo to other tabs
289
- if (config.value.enableCrossTabSync) {
290
- broadcastUndo(operation);
291
- }
292
- return true;
293
- }
294
- catch (error) {
295
- // Log error in development
296
- if (typeof console !== 'undefined') {
297
- console.error('Undo failed:', error);
298
- }
299
- return false;
300
- }
301
- }
302
- /**
303
- * Redo the next operation
304
- */
305
- function redo(store) {
306
- if (!canRedo.value)
307
- return false;
308
- const operation = operations.value[currentIndex.value + 1];
309
- try {
310
- // Handle batch operations
311
- if (operation.type === 'batch' && operation.descendantOperationIds) {
312
- // Redo all descendant operations in order
313
- for (const descendantId of operation.descendantOperationIds) {
314
- const descendantOp = operations.value.find(op => op.id === descendantId);
315
- if (descendantOp) {
316
- applyOperation(descendantOp, store);
317
- }
318
- }
319
- }
320
- else {
321
- // Redo single operation
322
- applyOperation(operation, store);
323
- }
324
- currentIndex.value++;
325
- // Broadcast redo to other tabs
326
- if (config.value.enableCrossTabSync) {
327
- broadcastRedo(operation);
328
- }
329
- return true;
330
- }
331
- catch (error) {
332
- // Log error in development
333
- if (typeof console !== 'undefined') {
334
- console.error('Redo failed:', error);
335
- }
336
- return false;
337
- }
338
- }
339
- /**
340
- * Get operation log snapshot for debugging
341
- */
342
- function getSnapshot() {
343
- const reversibleOps = operations.value.filter(op => op.reversible).length;
344
- const timestamps = operations.value.map(op => op.timestamp);
345
- return {
346
- operations: [...operations.value],
347
- currentIndex: currentIndex.value,
348
- totalOperations: operations.value.length,
349
- reversibleOperations: reversibleOps,
350
- irreversibleOperations: operations.value.length - reversibleOps,
351
- oldestOperation: timestamps.length > 0 ? new Date(Math.min(...timestamps.map(t => t.getTime()))) : undefined,
352
- newestOperation: timestamps.length > 0 ? new Date(Math.max(...timestamps.map(t => t.getTime()))) : undefined,
353
- };
354
- }
355
- /**
356
- * Clear all operations
357
- */
358
- function clear() {
359
- operations.value = [];
360
- currentIndex.value = -1;
361
- }
362
- /**
363
- * Get operations for a specific doctype and recordId
364
- */
365
- function getOperationsFor(doctype, recordId) {
366
- return operations.value.filter(op => op.doctype === doctype && (recordId === undefined || op.recordId === recordId));
367
- }
368
- /**
369
- * Mark an operation as irreversible
370
- * @param operationId - The ID of the operation to mark
371
- * @param reason - The reason why the operation is irreversible
372
- */
373
- function markIrreversible(operationId, reason) {
374
- const operation = operations.value.find(op => op.id === operationId);
375
- if (operation) {
376
- operation.reversible = false;
377
- operation.irreversibleReason = reason;
378
- }
379
- }
380
- /**
381
- * Log an action execution (stateless actions like print, email, etc.)
382
- * These operations are tracked but typically not reversible
383
- * @param doctype - The doctype the action was executed on
384
- * @param actionName - The name of the action that was executed
385
- * @param recordIds - Optional array of record IDs the action was executed on
386
- * @param result - The result of the action execution
387
- * @param error - Optional error message if action failed
388
- * @returns The operation ID
389
- */
390
- function logAction(doctype, actionName, recordIds, result = 'success', error) {
391
- const operation = {
392
- type: 'action',
393
- path: recordIds && recordIds.length > 0 ? `${doctype}.${recordIds[0]}` : doctype,
394
- fieldname: '',
395
- beforeValue: null,
396
- afterValue: null,
397
- doctype,
398
- recordId: recordIds && recordIds.length > 0 ? recordIds[0] : undefined,
399
- reversible: false, // Actions are typically not reversible
400
- actionName,
401
- actionRecordIds: recordIds,
402
- actionResult: result,
403
- actionError: error,
404
- };
405
- return addOperation(operation);
406
- }
407
- // Cross-tab synchronization
408
- let broadcastChannel = null;
409
- function setupCrossTabSync() {
410
- if (typeof window === 'undefined' || !window.BroadcastChannel)
411
- return;
412
- broadcastChannel = new BroadcastChannel('stonecrop-operation-log');
413
- broadcastChannel.addEventListener('message', (event) => {
414
- const rawMessage = event.data;
415
- if (!rawMessage || typeof rawMessage !== 'object')
416
- return;
417
- const message = deserializeFromBroadcast(rawMessage);
418
- // Ignore messages from this tab
419
- if (message.clientId === clientId.value)
420
- return;
421
- if (message.type === 'operation' && message.operation) {
422
- // Add operation from another tab
423
- operations.value.push({ ...message.operation, source: 'sync' });
424
- currentIndex.value = operations.value.length - 1;
425
- }
426
- else if (message.type === 'operation' && message.operations) {
427
- // Add batch operations from another tab
428
- operations.value.push(...message.operations.map((op) => Object.assign({}, op, { source: 'sync' })));
429
- currentIndex.value = operations.value.length - 1;
430
- }
431
- });
432
- }
433
- function broadcastOperation(operation) {
434
- if (!broadcastChannel)
435
- return;
436
- const message = {
437
- type: 'operation',
438
- operation,
439
- clientId: clientId.value,
440
- timestamp: new Date(),
441
- };
442
- // oxlint-disable-next-line unicorn/require-post-message-target-origin -- BroadcastChannel.postMessage does not accept targetOrigin; rule only applies to window.postMessage
443
- broadcastChannel.postMessage(serializeForBroadcast(message));
444
- }
445
- function broadcastBatch(descendantOps, batchOp) {
446
- if (!broadcastChannel)
447
- return;
448
- const message = {
449
- type: 'operation',
450
- operations: [...descendantOps, batchOp],
451
- clientId: clientId.value,
452
- timestamp: new Date(),
453
- };
454
- // oxlint-disable-next-line unicorn/require-post-message-target-origin -- BroadcastChannel.postMessage does not accept targetOrigin; rule only applies to window.postMessage
455
- broadcastChannel.postMessage(serializeForBroadcast(message));
456
- }
457
- function broadcastUndo(operation) {
458
- if (!broadcastChannel)
459
- return;
460
- const message = {
461
- type: 'undo',
462
- operation,
463
- clientId: clientId.value,
464
- timestamp: new Date(),
465
- };
466
- // oxlint-disable-next-line unicorn/require-post-message-target-origin -- BroadcastChannel.postMessage does not accept targetOrigin; rule only applies to window.postMessage
467
- broadcastChannel.postMessage(serializeForBroadcast(message));
468
- }
469
- function broadcastRedo(operation) {
470
- if (!broadcastChannel)
471
- return;
472
- const message = {
473
- type: 'redo',
474
- operation,
475
- clientId: clientId.value,
476
- timestamp: new Date(),
477
- };
478
- // oxlint-disable-next-line unicorn/require-post-message-target-origin -- BroadcastChannel.postMessage does not accept targetOrigin; rule only applies to window.postMessage
479
- broadcastChannel.postMessage(serializeForBroadcast(message));
480
- }
481
- const persistedData = useLocalStorage('stonecrop-operations', null, {
482
- serializer: {
483
- read: (v) => {
484
- try {
485
- const data = JSON.parse(v);
486
- return data;
487
- }
488
- catch {
489
- return null;
490
- }
491
- },
492
- write: (v) => {
493
- if (!v)
494
- return '';
495
- return JSON.stringify(v);
496
- },
497
- },
498
- });
499
- function loadFromPersistence() {
500
- if (typeof window === 'undefined')
501
- return;
502
- try {
503
- const data = persistedData.value;
504
- if (data && Array.isArray(data.operations)) {
505
- operations.value = data.operations.map(op => ({
506
- ...op,
507
- timestamp: new Date(op.timestamp),
508
- }));
509
- currentIndex.value = data.currentIndex ?? -1;
510
- }
511
- }
512
- catch (error) {
513
- // Log error in development
514
- if (typeof console !== 'undefined') {
515
- console.error('Failed to load operations from persistence:', error);
516
- }
517
- }
518
- }
519
- function saveToPersistence() {
520
- if (typeof window === 'undefined')
521
- return;
522
- try {
523
- persistedData.value = {
524
- operations: operations.value.map(op => ({
525
- ...op,
526
- timestamp: op.timestamp.toISOString(),
527
- })),
528
- currentIndex: currentIndex.value,
529
- };
530
- }
531
- catch (error) {
532
- // Log error in development
533
- if (typeof console !== 'undefined') {
534
- console.error('Failed to save operations to persistence:', error);
535
- }
536
- }
537
- }
538
- function setupPersistenceWatcher() {
539
- watch([operations, currentIndex], () => {
540
- if (config.value.enablePersistence) {
541
- saveToPersistence();
542
- }
543
- }, { deep: true });
544
- }
545
- return {
546
- // State
547
- operations,
548
- currentIndex,
549
- config,
550
- clientId,
551
- undoRedoState,
552
- // Computed
553
- canUndo,
554
- canRedo,
555
- undoCount,
556
- redoCount,
557
- // Methods
558
- configure,
559
- addOperation,
560
- startBatch,
561
- commitBatch,
562
- cancelBatch,
563
- undo,
564
- redo,
565
- clear,
566
- getOperationsFor,
567
- getSnapshot,
568
- markIrreversible,
569
- logAction,
570
- };
571
- });
@@ -1,83 +0,0 @@
1
- import type { TriggerDefinition } from '@stonecrop/schema';
2
- /**
3
- * A single validation error contributed by a trigger, displayed on a field.
4
- * @public
5
- */
6
- export interface ValidationError {
7
- /** The trigger that produced this error — the namespace a re-run clears before repopulating */
8
- trigger: string;
9
- /** The fieldname the error displays on (the `setError` target, not necessarily a fired field) */
10
- field: string;
11
- /** The message to display */
12
- message: string;
13
- }
14
- /**
15
- * Reactive per-field validation error store + the advisory field-validation trigger engine.
16
- *
17
- * Holds the errors produced by field-validation triggers (see `TriggerDefinition` in
18
- * `@stonecrop/schema`) and runs a trigger's `clientHandler` on demand. Errors are **namespaced
19
- * by trigger**: re-running a trigger clears its own prior contributions before repopulating, so a
20
- * corrected value clears its stale error without disturbing other triggers.
21
- *
22
- * The engine is **advisory** and does **no rollback** — an invalid value stays in the record so the
23
- * user can fix it; validity is reported separately via `isValid` (read by the save gate) and
24
- * the per-field messages are surfaced via `errorsByField` / `errorsFor` for display.
25
- *
26
- * @public
27
- */
28
- export declare const useValidationStore: import("pinia").StoreDefinition<"stonecrop-validation", Pick<{
29
- errors: import("vue").Ref<{
30
- trigger: string;
31
- field: string;
32
- message: string;
33
- }[], ValidationError[] | {
34
- trigger: string;
35
- field: string;
36
- message: string;
37
- }[]>;
38
- isValid: import("vue").ComputedRef<boolean>;
39
- errorsByField: import("vue").ComputedRef<Record<string, string[]>>;
40
- errorsFor: (field: string) => string[];
41
- setError: (trigger: string, field: string, message: string) => void;
42
- clearTrigger: (trigger: string) => void;
43
- clearAll: () => void;
44
- validateField: (triggers: Record<string, TriggerDefinition>, changedField: string, record: Record<string, unknown>) => Promise<void>;
45
- validateRecord: (triggers: Record<string, TriggerDefinition>, record: Record<string, unknown>) => Promise<void>;
46
- }, "errors">, Pick<{
47
- errors: import("vue").Ref<{
48
- trigger: string;
49
- field: string;
50
- message: string;
51
- }[], ValidationError[] | {
52
- trigger: string;
53
- field: string;
54
- message: string;
55
- }[]>;
56
- isValid: import("vue").ComputedRef<boolean>;
57
- errorsByField: import("vue").ComputedRef<Record<string, string[]>>;
58
- errorsFor: (field: string) => string[];
59
- setError: (trigger: string, field: string, message: string) => void;
60
- clearTrigger: (trigger: string) => void;
61
- clearAll: () => void;
62
- validateField: (triggers: Record<string, TriggerDefinition>, changedField: string, record: Record<string, unknown>) => Promise<void>;
63
- validateRecord: (triggers: Record<string, TriggerDefinition>, record: Record<string, unknown>) => Promise<void>;
64
- }, "isValid" | "errorsByField">, Pick<{
65
- errors: import("vue").Ref<{
66
- trigger: string;
67
- field: string;
68
- message: string;
69
- }[], ValidationError[] | {
70
- trigger: string;
71
- field: string;
72
- message: string;
73
- }[]>;
74
- isValid: import("vue").ComputedRef<boolean>;
75
- errorsByField: import("vue").ComputedRef<Record<string, string[]>>;
76
- errorsFor: (field: string) => string[];
77
- setError: (trigger: string, field: string, message: string) => void;
78
- clearTrigger: (trigger: string) => void;
79
- clearAll: () => void;
80
- validateField: (triggers: Record<string, TriggerDefinition>, changedField: string, record: Record<string, unknown>) => Promise<void>;
81
- validateRecord: (triggers: Record<string, TriggerDefinition>, record: Record<string, unknown>) => Promise<void>;
82
- }, "errorsFor" | "setError" | "clearTrigger" | "clearAll" | "validateField" | "validateRecord">>;
83
- //# sourceMappingURL=validation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/stores/validation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAG1D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,+FAA+F;IAC/F,OAAO,EAAE,MAAM,CAAA;IACf,iGAAiG;IACjG,KAAK,EAAE,MAAM,CAAA;IACb,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB;;iBArBrB,MAAM;eAER,MAAM;iBAEJ,MAAM;;iBAJN,MAAM;eAER,MAAM;iBAEJ,MAAM;;;;uBAkCW,MAAM,KAAG,MAAM,EAAE;wBAKhB,MAAM,SAAS,MAAM,WAAW,MAAM;4BAKlC,MAAM;;8BA0C1B,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,gBAC7B,MAAM,UACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC;+BAeL,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,UACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC;;;iBA9GP,MAAM;eAER,MAAM;iBAEJ,MAAM;;iBAJN,MAAM;eAER,MAAM;iBAEJ,MAAM;;;;uBAkCW,MAAM,KAAG,MAAM,EAAE;wBAKhB,MAAM,SAAS,MAAM,WAAW,MAAM;4BAKlC,MAAM;;8BA0C1B,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,gBAC7B,MAAM,UACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC;+BAeL,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,UACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC;;;iBA9GP,MAAM;eAER,MAAM;iBAEJ,MAAM;;iBAJN,MAAM;eAER,MAAM;iBAEJ,MAAM;;;;uBAkCW,MAAM,KAAG,MAAM,EAAE;wBAKhB,MAAM,SAAS,MAAM,WAAW,MAAM;4BAKlC,MAAM;;8BA0C1B,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,gBAC7B,MAAM,UACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC;+BAeL,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,UACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC;gGAef,CAAA"}