@stonecrop/stonecrop 0.13.4 → 0.13.6

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.
@@ -87,6 +87,24 @@ function deserializeFromBroadcast(serialized: SerializedCrossTabMessage): CrossT
87
87
  return message
88
88
  }
89
89
 
90
+ /**
91
+ * Revert an operation (apply beforeValue)
92
+ */
93
+ function revertOperation(operation: HSTOperation, store: HSTNode) {
94
+ if ((operation.type === 'set' || operation.type === 'delete') && store && typeof store.set === 'function') {
95
+ store.set(operation.path, operation.beforeValue, 'undo')
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Apply an operation (apply afterValue)
101
+ */
102
+ function applyOperation(operation: HSTOperation, store: HSTNode) {
103
+ if ((operation.type === 'set' || operation.type === 'delete') && store && typeof store.set === 'function') {
104
+ store.set(operation.path, operation.afterValue, 'redo')
105
+ }
106
+ }
107
+
90
108
  /**
91
109
  * Global HST Operation Log Store
92
110
  * Tracks all mutations with full metadata for undo/redo, sync, and audit
@@ -312,7 +330,6 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
312
330
  if (!operation.reversible) {
313
331
  // Warn about irreversible operation
314
332
  if (typeof console !== 'undefined' && operation.irreversibleReason) {
315
- // eslint-disable-next-line no-console
316
333
  console.warn('Cannot undo irreversible operation:', operation.irreversibleReason)
317
334
  }
318
335
  return false
@@ -345,7 +362,6 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
345
362
  } catch (error) {
346
363
  // Log error in development
347
364
  if (typeof console !== 'undefined') {
348
- // eslint-disable-next-line no-console
349
365
  console.error('Undo failed:', error)
350
366
  }
351
367
  return false
@@ -386,37 +402,12 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
386
402
  } catch (error) {
387
403
  // Log error in development
388
404
  if (typeof console !== 'undefined') {
389
- // eslint-disable-next-line no-console
390
405
  console.error('Redo failed:', error)
391
406
  }
392
407
  return false
393
408
  }
394
409
  }
395
410
 
396
- /**
397
- * Revert an operation (apply beforeValue)
398
- */
399
- function revertOperation(operation: HSTOperation, store: HSTNode) {
400
- // Both 'set' and 'delete' operations can be reverted by setting to beforeValue
401
- if ((operation.type === 'set' || operation.type === 'delete') && store && typeof store.set === 'function') {
402
- store.set(operation.path, operation.beforeValue, 'undo')
403
- }
404
- // Note: 'transition' operations are marked as non-reversible, so they won't reach here
405
- // Note: 'batch' operations are handled separately in the undo function
406
- }
407
-
408
- /**
409
- * Apply an operation (apply afterValue)
410
- */
411
- function applyOperation(operation: HSTOperation, store: HSTNode) {
412
- // Both 'set' and 'delete' operations can be applied by setting to afterValue
413
- if ((operation.type === 'set' || operation.type === 'delete') && store && typeof store.set === 'function') {
414
- store.set(operation.path, operation.afterValue, 'redo')
415
- }
416
- // Note: 'transition' operations are marked as non-reversible, so they won't reach here
417
- // Note: 'batch' operations are handled separately in the redo function
418
- }
419
-
420
411
  /**
421
412
  * Get operation log snapshot for debugging
422
413
  */
@@ -511,7 +502,6 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
511
502
 
512
503
  if (!rawMessage || typeof rawMessage !== 'object') return
513
504
 
514
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
515
505
  const message = deserializeFromBroadcast(rawMessage)
516
506
 
517
507
  // Ignore messages from this tab
@@ -523,7 +513,9 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
523
513
  currentIndex.value = operations.value.length - 1
524
514
  } else if (message.type === 'operation' && message.operations) {
525
515
  // Add batch operations from another tab
526
- operations.value.push(...message.operations.map((op): HSTOperation => ({ ...op, source: 'sync' })))
516
+ operations.value.push(
517
+ ...message.operations.map((op): HSTOperation => Object.assign({}, op, { source: 'sync' as const }))
518
+ )
527
519
  currentIndex.value = operations.value.length - 1
528
520
  }
529
521
  })
@@ -538,6 +530,7 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
538
530
  clientId: clientId.value,
539
531
  timestamp: new Date(),
540
532
  }
533
+ // oxlint-disable-next-line unicorn/require-post-message-target-origin -- BroadcastChannel.postMessage does not accept targetOrigin; rule only applies to window.postMessage
541
534
  broadcastChannel.postMessage(serializeForBroadcast(message))
542
535
  }
543
536
 
@@ -550,6 +543,7 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
550
543
  clientId: clientId.value,
551
544
  timestamp: new Date(),
552
545
  }
546
+ // oxlint-disable-next-line unicorn/require-post-message-target-origin -- BroadcastChannel.postMessage does not accept targetOrigin; rule only applies to window.postMessage
553
547
  broadcastChannel.postMessage(serializeForBroadcast(message))
554
548
  }
555
549
 
@@ -562,6 +556,7 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
562
556
  clientId: clientId.value,
563
557
  timestamp: new Date(),
564
558
  }
559
+ // oxlint-disable-next-line unicorn/require-post-message-target-origin -- BroadcastChannel.postMessage does not accept targetOrigin; rule only applies to window.postMessage
565
560
  broadcastChannel.postMessage(serializeForBroadcast(message))
566
561
  }
567
562
 
@@ -574,6 +569,7 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
574
569
  clientId: clientId.value,
575
570
  timestamp: new Date(),
576
571
  }
572
+ // oxlint-disable-next-line unicorn/require-post-message-target-origin -- BroadcastChannel.postMessage does not accept targetOrigin; rule only applies to window.postMessage
577
573
  broadcastChannel.postMessage(serializeForBroadcast(message))
578
574
  }
579
575
 
@@ -615,7 +611,6 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
615
611
  } catch (error) {
616
612
  // Log error in development
617
613
  if (typeof console !== 'undefined') {
618
- // eslint-disable-next-line no-console
619
614
  console.error('Failed to load operations from persistence:', error)
620
615
  }
621
616
  }
@@ -635,7 +630,6 @@ export const useOperationLogStore = defineStore('hst-operation-log', () => {
635
630
  } catch (error) {
636
631
  // Log error in development
637
632
  if (typeof console !== 'undefined') {
638
- // eslint-disable-next-line no-console
639
633
  console.error('Failed to save operations to persistence:', error)
640
634
  }
641
635
  }
@@ -284,5 +284,5 @@ export type LazyLink = {
284
284
  /** Explicitly trigger a fetch for this link */
285
285
  reload: () => Promise<void>
286
286
  /** The loaded data from HST, or undefined if not loaded */
287
- data: ComputedRef<any>
287
+ data: ComputedRef
288
288
  }