@stonecrop/stonecrop 0.4.37 → 0.6.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 (78) hide show
  1. package/README.md +92 -3
  2. package/dist/src/composable.d.ts +74 -8
  3. package/dist/src/composable.d.ts.map +1 -1
  4. package/dist/src/composable.js +348 -0
  5. package/dist/src/composables/operation-log.d.ts +136 -0
  6. package/dist/src/composables/operation-log.d.ts.map +1 -0
  7. package/dist/src/composables/operation-log.js +221 -0
  8. package/dist/src/doctype.d.ts +9 -1
  9. package/dist/src/doctype.d.ts.map +1 -1
  10. package/dist/{doctype.js → src/doctype.js} +9 -3
  11. package/dist/src/field-triggers.d.ts +178 -0
  12. package/dist/src/field-triggers.d.ts.map +1 -0
  13. package/dist/src/field-triggers.js +564 -0
  14. package/dist/src/index.d.ts +12 -4
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +18 -0
  17. package/dist/src/plugins/index.d.ts +11 -13
  18. package/dist/src/plugins/index.d.ts.map +1 -1
  19. package/dist/src/plugins/index.js +90 -0
  20. package/dist/src/registry.d.ts +9 -3
  21. package/dist/src/registry.d.ts.map +1 -1
  22. package/dist/{registry.js → src/registry.js} +14 -1
  23. package/dist/src/stonecrop.d.ts +350 -114
  24. package/dist/src/stonecrop.d.ts.map +1 -1
  25. package/dist/src/stonecrop.js +251 -0
  26. package/dist/src/stores/hst.d.ts +157 -0
  27. package/dist/src/stores/hst.d.ts.map +1 -0
  28. package/dist/src/stores/hst.js +483 -0
  29. package/dist/src/stores/index.d.ts +5 -1
  30. package/dist/src/stores/index.d.ts.map +1 -1
  31. package/dist/{stores → src/stores}/index.js +4 -1
  32. package/dist/src/stores/operation-log.d.ts +268 -0
  33. package/dist/src/stores/operation-log.d.ts.map +1 -0
  34. package/dist/src/stores/operation-log.js +571 -0
  35. package/dist/src/types/field-triggers.d.ts +186 -0
  36. package/dist/src/types/field-triggers.d.ts.map +1 -0
  37. package/dist/src/types/field-triggers.js +4 -0
  38. package/dist/src/types/index.d.ts +13 -2
  39. package/dist/src/types/index.d.ts.map +1 -1
  40. package/dist/src/types/index.js +4 -0
  41. package/dist/src/types/operation-log.d.ts +165 -0
  42. package/dist/src/types/operation-log.d.ts.map +1 -0
  43. package/dist/src/types/registry.d.ts +11 -0
  44. package/dist/src/types/registry.d.ts.map +1 -0
  45. package/dist/src/types/registry.js +0 -0
  46. package/dist/stonecrop.d.ts +1555 -159
  47. package/dist/stonecrop.js +1974 -7028
  48. package/dist/stonecrop.js.map +1 -1
  49. package/dist/stonecrop.umd.cjs +4 -8
  50. package/dist/stonecrop.umd.cjs.map +1 -1
  51. package/dist/tests/setup.d.ts +5 -0
  52. package/dist/tests/setup.d.ts.map +1 -0
  53. package/dist/tests/setup.js +15 -0
  54. package/package.json +6 -5
  55. package/src/composable.ts +481 -31
  56. package/src/composables/operation-log.ts +254 -0
  57. package/src/doctype.ts +9 -3
  58. package/src/field-triggers.ts +671 -0
  59. package/src/index.ts +50 -4
  60. package/src/plugins/index.ts +70 -22
  61. package/src/registry.ts +18 -3
  62. package/src/stonecrop.ts +246 -155
  63. package/src/stores/hst.ts +703 -0
  64. package/src/stores/index.ts +6 -1
  65. package/src/stores/operation-log.ts +671 -0
  66. package/src/types/field-triggers.ts +201 -0
  67. package/src/types/index.ts +17 -6
  68. package/src/types/operation-log.ts +205 -0
  69. package/src/types/registry.ts +10 -0
  70. package/dist/composable.js +0 -50
  71. package/dist/index.js +0 -6
  72. package/dist/plugins/index.js +0 -49
  73. package/dist/src/stores/data.d.ts +0 -11
  74. package/dist/src/stores/data.d.ts.map +0 -1
  75. package/dist/stores/data.js +0 -7
  76. package/src/stores/data.ts +0 -8
  77. /package/dist/{exceptions.js → src/exceptions.js} +0 -0
  78. /package/dist/{types/index.js → src/types/operation-log.js} +0 -0
@@ -2,18 +2,61 @@ import type { AnyStateNodeConfig } from 'xstate';
2
2
  import { Component } from 'vue';
3
3
  import { ComputedRef } from 'vue';
4
4
  import { CSSProperties } from 'vue';
5
+ import { HSTOperation as HSTOperation_2 } from './types';
6
+ import { HSTOperation as HSTOperation_3 } from '..';
7
+ import { HSTOperationInput as HSTOperationInput_2 } from './types';
8
+ import { HSTOperationType as HSTOperationType_2 } from './types';
9
+ import { HSTOperationType as HSTOperationType_3 } from '..';
5
10
  import { List } from 'immutable';
6
11
  import { Map as Map_2 } from 'immutable';
12
+ import { OperationLogSnapshot as OperationLogSnapshot_2 } from './types';
13
+ import { OperationLogSnapshot as OperationLogSnapshot_3 } from '..';
14
+ import { OperationSource as OperationSource_2 } from './types';
15
+ import { OperationSource as OperationSource_3 } from '..';
7
16
  import { Plugin as Plugin_2 } from 'vue';
8
17
  import { Ref } from 'vue';
9
18
  import { Router } from 'vue-router';
10
19
  import type { ShallowRef } from 'vue';
11
20
  import { Store } from 'pinia';
12
21
  import { StoreDefinition } from 'pinia';
22
+ import { UndoRedoState as UndoRedoState_2 } from './types';
23
+ import { UndoRedoState as UndoRedoState_3 } from '..';
13
24
  import type { UnknownMachineConfig } from 'xstate';
14
25
  import { useElementBounding } from '@vueuse/core';
15
26
  import { WritableComputedRef } from 'vue';
16
27
 
28
+ /**
29
+ * Result of executing a field action
30
+ * @public
31
+ */
32
+ export declare interface ActionExecutionResult {
33
+ /** Whether the action executed successfully */
34
+ success: boolean;
35
+ /** Error if execution failed */
36
+ error?: Error;
37
+ /** Execution time in milliseconds */
38
+ executionTime: number;
39
+ /** The action that was executed */
40
+ action: FieldAction;
41
+ }
42
+
43
+ /**
44
+ * Registry for storing global action functions
45
+ * @public
46
+ */
47
+ export declare interface ActionRegistry {
48
+ /** Register a global action function */
49
+ register(name: string, fn: FieldActionFunction): void;
50
+ /** Get a registered action function */
51
+ get(name: string): FieldActionFunction | undefined;
52
+ /** Check if an action is registered */
53
+ has(name: string): boolean;
54
+ /** Unregister an action function */
55
+ unregister(name: string): void;
56
+ /** Get all registered action names */
57
+ list(): string[];
58
+ }
59
+
17
60
  /**
18
61
  * Basic field structure for AForm schemas
19
62
  * @public
@@ -41,6 +84,15 @@ export declare type BaseSchema = {
41
84
  value?: any;
42
85
  };
43
86
 
87
+ /**
88
+ * Base Stonecrop composable return type - includes operation log functionality
89
+ * @public
90
+ */
91
+ export declare type BaseStonecropReturn = {
92
+ stonecrop: Ref<Stonecrop | undefined>;
93
+ operationLog: OperationLogAPI;
94
+ };
95
+
44
96
  /**
45
97
  * Base table configuration properties shared across all view types.
46
98
  * @public
@@ -65,6 +117,23 @@ export declare interface BasicTableConfig extends BaseTableConfig {
65
117
  view?: 'uncounted' | 'list' | 'list-expansion';
66
118
  }
67
119
 
120
+ /**
121
+ * Batch operation wrapper
122
+ * @public
123
+ */
124
+ export declare interface BatchOperation {
125
+ /** Unique batch identifier */
126
+ id: string;
127
+ /** Operations included in this batch */
128
+ operations: HSTOperation[];
129
+ /** When the batch was created */
130
+ timestamp: Date;
131
+ /** Optional description of what this batch represents */
132
+ description?: string;
133
+ /** Whether the entire batch can be undone */
134
+ reversible: boolean;
135
+ }
136
+
68
137
  /**
69
138
  * Table cell context definition.
70
139
  * @public
@@ -218,6 +287,19 @@ export declare interface ConnectionPath {
218
287
  label?: string;
219
288
  }
220
289
 
290
+ /**
291
+ * Factory function for HST creation
292
+ * Creates a new HSTNode proxy for hierarchical state tree navigation.
293
+ *
294
+ * @param target - The target object to wrap with HST functionality
295
+ * @param doctype - The document type identifier
296
+ * @param parentDoctype - Optional parent document type identifier
297
+ * @returns A new HSTNode proxy instance
298
+ *
299
+ * @public
300
+ */
301
+ export declare function createHST(target: any, doctype: string, parentDoctype?: string): HSTNode;
302
+
221
303
  /**
222
304
  * Create a table store
223
305
  * @param initData - Initial data for the table store
@@ -1009,6 +1091,29 @@ updateGanttBar: (event: GanttDragEvent) => void;
1009
1091
  updateRows: (newRows: TableRow[]) => void;
1010
1092
  }, "closeModal" | "createConnection" | "deleteConnection" | "getCellData" | "getCellDisplayValue" | "getConnectionsForBar" | "getFormattedValue" | "getHandlesForBar" | "getHeaderCellStyle" | "getIndent" | "getRowExpandSymbol" | "isRowGantt" | "isRowVisible" | "registerConnectionHandle" | "registerGanttBar" | "resizeColumn" | "setCellData" | "setCellText" | "toggleRowExpand" | "unregisterConnectionHandle" | "unregisterGanttBar" | "updateGanttBar" | "updateRows">>;
1011
1093
 
1094
+ /**
1095
+ * Cross-tab message payload
1096
+ * @public
1097
+ */
1098
+ export declare interface CrossTabMessage {
1099
+ /** Type of cross-tab message */
1100
+ type: CrossTabMessageType;
1101
+ /** Single operation for operation/undo/redo messages */
1102
+ operation?: HSTOperation;
1103
+ /** Multiple operations for sync messages */
1104
+ operations?: HSTOperation[];
1105
+ /** Identifier of the client/tab sending the message */
1106
+ clientId: string;
1107
+ /** When the message was sent */
1108
+ timestamp: Date;
1109
+ }
1110
+
1111
+ /**
1112
+ * Cross-tab message types
1113
+ * @public
1114
+ */
1115
+ export declare type CrossTabMessageType = 'operation' | 'undo' | 'redo' | 'sync-request' | 'sync-response';
1116
+
1012
1117
  /**
1013
1118
  * Doctype Meta class
1014
1119
  * @public
@@ -1033,7 +1138,7 @@ export declare class DoctypeMeta {
1033
1138
  */
1034
1139
  readonly workflow: ImmutableDoctype['workflow'];
1035
1140
  /**
1036
- * The doctype actions
1141
+ * The doctype actions and field triggers
1037
1142
  * @public
1038
1143
  * @readonly
1039
1144
  */
@@ -1044,6 +1149,14 @@ export declare class DoctypeMeta {
1044
1149
  * @readonly
1045
1150
  */
1046
1151
  readonly component?: Component;
1152
+ /**
1153
+ * Creates a new DoctypeMeta instance
1154
+ * @param doctype - The doctype name
1155
+ * @param schema - The doctype schema definition
1156
+ * @param workflow - The doctype workflow configuration (XState machine)
1157
+ * @param actions - The doctype actions and field triggers
1158
+ * @param component - Optional Vue component for rendering the doctype
1159
+ */
1047
1160
  constructor(doctype: string, schema: ImmutableDoctype['schema'], workflow: ImmutableDoctype['workflow'], actions: ImmutableDoctype['actions'], component?: Component);
1048
1161
  /**
1049
1162
  * Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
@@ -1064,6 +1177,49 @@ export declare class DoctypeMeta {
1064
1177
  get slug(): string;
1065
1178
  }
1066
1179
 
1180
+ /**
1181
+ * Supported action types for field triggers
1182
+ * @public
1183
+ */
1184
+ export declare type FieldAction = FieldActionFunction | FieldActionString;
1185
+
1186
+ /**
1187
+ * Action function that can be triggered by field changes
1188
+ * @public
1189
+ */
1190
+ export declare type FieldActionFunction = (context: FieldChangeContext) => void | Promise<void>;
1191
+
1192
+ /**
1193
+ * String reference to a globally registered action function or inline function
1194
+ * @public
1195
+ */
1196
+ export declare type FieldActionString = string;
1197
+
1198
+ /**
1199
+ * Context provided to action functions when field changes occur
1200
+ * @public
1201
+ */
1202
+ export declare interface FieldChangeContext {
1203
+ /** The HST path that was changed */
1204
+ path: string;
1205
+ /** The field name (last segment of path) */
1206
+ fieldname: string;
1207
+ /** Value before the change */
1208
+ beforeValue: any;
1209
+ /** Value after the change */
1210
+ afterValue: any;
1211
+ /** The operation type */
1212
+ operation: 'set' | 'delete' | 'patch';
1213
+ /** The doctype of the record being changed */
1214
+ doctype: string;
1215
+ /** The record ID if applicable */
1216
+ recordId?: string;
1217
+ /** Timestamp of the change */
1218
+ timestamp: Date;
1219
+ /** Reference to the HST store for state access (optional) */
1220
+ store?: HSTNode;
1221
+ }
1222
+
1067
1223
  /**
1068
1224
  * Schema structure for defining fieldsets inside AForm
1069
1225
  * @public
@@ -1086,6 +1242,193 @@ export declare type FieldsetSchema = BaseSchema & {
1086
1242
  collapsible?: boolean;
1087
1243
  };
1088
1244
 
1245
+ /**
1246
+ * Configuration for a single field trigger
1247
+ * @public
1248
+ */
1249
+ export declare interface FieldTriggerConfig {
1250
+ /** Array of actions to execute when this field changes */
1251
+ actions: FieldAction[];
1252
+ /** Optional condition function to determine if actions should run */
1253
+ condition?: (context: FieldChangeContext) => boolean | Promise<boolean>;
1254
+ /** Whether to run actions before or after the value is set (default: 'after') */
1255
+ timing?: 'before' | 'after';
1256
+ /** Whether to stop execution on first error (default: true) */
1257
+ stopOnError?: boolean;
1258
+ /** Maximum execution time in milliseconds before timeout */
1259
+ timeout?: number;
1260
+ /** Whether to enable automatic rollback for this field trigger (overrides global setting) */
1261
+ enableRollback?: boolean;
1262
+ }
1263
+
1264
+ /**
1265
+ * Field trigger execution engine integrated with Registry
1266
+ * Singleton pattern following Registry implementation
1267
+ * @public
1268
+ */
1269
+ export declare class FieldTriggerEngine {
1270
+ /**
1271
+ * The root FieldTriggerEngine instance
1272
+ */
1273
+ static _root: FieldTriggerEngine;
1274
+ private options;
1275
+ private doctypeActions;
1276
+ private doctypeTransitions;
1277
+ private fieldRollbackConfig;
1278
+ private globalActions;
1279
+ private globalTransitionActions;
1280
+ /**
1281
+ * Creates a new FieldTriggerEngine instance (singleton pattern)
1282
+ * @param options - Configuration options for the field trigger engine
1283
+ */
1284
+ constructor(options?: FieldTriggerOptions);
1285
+ /**
1286
+ * Register a global action function
1287
+ * @param name - The name of the action
1288
+ * @param fn - The action function
1289
+ */
1290
+ registerAction(name: string, fn: FieldActionFunction): void;
1291
+ /**
1292
+ * Register a global XState transition action function
1293
+ * @param name - The name of the transition action
1294
+ * @param fn - The transition action function
1295
+ */
1296
+ registerTransitionAction(name: string, fn: TransitionActionFunction): void;
1297
+ /**
1298
+ * Configure rollback behavior for a specific field trigger
1299
+ * @param doctype - The doctype name
1300
+ * @param fieldname - The field name
1301
+ * @param enableRollback - Whether to enable rollback
1302
+ */
1303
+ setFieldRollback(doctype: string, fieldname: string, enableRollback: boolean): void;
1304
+ /**
1305
+ * Get rollback configuration for a specific field trigger
1306
+ */
1307
+ private getFieldRollback;
1308
+ /**
1309
+ * Register actions from a doctype - both regular actions and field triggers
1310
+ * Separates XState transitions (uppercase) from field triggers (lowercase)
1311
+ * @param doctype - The doctype name
1312
+ * @param actions - The actions to register (supports Immutable Map, Map, or plain object)
1313
+ */
1314
+ registerDoctypeActions(doctype: string, actions: Map_2<string, string[]> | Map<string, string[]> | Record<string, string[]> | undefined): void;
1315
+ /**
1316
+ * Categorize an action as either a field trigger or XState transition
1317
+ * Uses uppercase convention: UPPERCASE = transition, lowercase/mixed = field trigger
1318
+ */
1319
+ private categorizeAction;
1320
+ /**
1321
+ * Determine if a key represents an XState transition
1322
+ * Transitions are identified by being all uppercase
1323
+ */
1324
+ private isTransitionKey;
1325
+ /**
1326
+ * Execute field triggers for a changed field
1327
+ * @param context - The field change context
1328
+ * @param options - Execution options (timeout and enableRollback)
1329
+ */
1330
+ executeFieldTriggers(context: FieldChangeContext, options?: {
1331
+ timeout?: number;
1332
+ enableRollback?: boolean;
1333
+ }): Promise<FieldTriggerExecutionResult>;
1334
+ /**
1335
+ * Execute XState transition actions
1336
+ * Similar to field triggers but specifically for FSM state transitions
1337
+ * @param context - The transition change context
1338
+ * @param options - Execution options (timeout)
1339
+ */
1340
+ executeTransitionActions(context: TransitionChangeContext, options?: {
1341
+ timeout?: number;
1342
+ }): Promise<TransitionExecutionResult[]>;
1343
+ /**
1344
+ * Find transition actions for a specific doctype and transition
1345
+ */
1346
+ private findTransitionActions;
1347
+ /**
1348
+ * Execute a single transition action by name
1349
+ */
1350
+ private executeTransitionAction;
1351
+ /**
1352
+ * Find field triggers for a specific doctype and field
1353
+ * Field triggers are identified by keys that look like field paths (contain dots or match field names)
1354
+ */
1355
+ private findFieldTriggers;
1356
+ /**
1357
+ * Determine if an action key represents a field trigger
1358
+ * Field triggers can be:
1359
+ * - Exact field name match: "emailAddress"
1360
+ * - Wildcard patterns: "emailAddress.*", "*.is_primary"
1361
+ * - Nested field paths: "address.street", "contact.email"
1362
+ */
1363
+ private isFieldTriggerKey;
1364
+ /**
1365
+ * Match a field pattern against a field name
1366
+ * Supports wildcards (*) for dynamic segments
1367
+ */
1368
+ private matchFieldPattern;
1369
+ /**
1370
+ * Execute a single action by name
1371
+ */
1372
+ private executeAction;
1373
+ /**
1374
+ * Execute a function with timeout
1375
+ */
1376
+ private executeWithTimeout;
1377
+ /**
1378
+ * Capture a snapshot of the record state before executing actions
1379
+ * This creates a deep copy of the record data for potential rollback
1380
+ */
1381
+ private captureSnapshot;
1382
+ /**
1383
+ * Restore a previously captured snapshot
1384
+ * This reverts the record to its state before actions were executed
1385
+ */
1386
+ private restoreSnapshot;
1387
+ }
1388
+
1389
+ /**
1390
+ * Result of executing all actions for a field change
1391
+ * @public
1392
+ */
1393
+ export declare interface FieldTriggerExecutionResult {
1394
+ /** The path that triggered the actions */
1395
+ path: string;
1396
+ /** Results for each action that was executed */
1397
+ actionResults: ActionExecutionResult[];
1398
+ /** Total execution time for all actions */
1399
+ totalExecutionTime: number;
1400
+ /** Whether all actions succeeded */
1401
+ allSucceeded: boolean;
1402
+ /** Whether execution was stopped due to an error */
1403
+ stoppedOnError: boolean;
1404
+ /** Whether a rollback was performed */
1405
+ rolledBack: boolean;
1406
+ /** The snapshot that was captured before execution */
1407
+ snapshot?: any;
1408
+ }
1409
+
1410
+ /**
1411
+ * Map of field paths to trigger configurations
1412
+ * Supports wildcard patterns like 'emailAddress.*.is_primary'
1413
+ * @public
1414
+ */
1415
+ export declare type FieldTriggerMap = Record<string, FieldTriggerConfig | FieldAction[]>;
1416
+
1417
+ /**
1418
+ * Options for the field trigger system
1419
+ * @public
1420
+ */
1421
+ export declare interface FieldTriggerOptions {
1422
+ /** Default timeout for action execution in milliseconds */
1423
+ defaultTimeout?: number;
1424
+ /** Whether to log trigger executions for debugging */
1425
+ debug?: boolean;
1426
+ /** Custom error handler for action failures */
1427
+ errorHandler?: (error: Error, context: FieldChangeContext, action: FieldAction) => void;
1428
+ /** Whether to enable automatic rollback on failure (default: true) */
1429
+ enableRollback?: boolean;
1430
+ }
1431
+
1089
1432
  /**
1090
1433
  * Schema structure for defining forms inside AForm
1091
1434
  * @public
@@ -1261,6 +1604,200 @@ export declare interface GanttTableConfig extends BaseTableConfig {
1261
1604
  dependencyGraph?: boolean;
1262
1605
  }
1263
1606
 
1607
+ /**
1608
+ * Get or create the global field trigger engine singleton
1609
+ * @param options - Optional configuration for the field trigger engine
1610
+ * @public
1611
+ */
1612
+ export declare function getGlobalTriggerEngine(options?: FieldTriggerOptions): FieldTriggerEngine;
1613
+
1614
+ /**
1615
+ * Global HST Manager (Singleton)
1616
+ * Manages hierarchical state trees and provides access to the global registry.
1617
+ *
1618
+ * @public
1619
+ */
1620
+ export declare class HST {
1621
+ private static instance;
1622
+ /**
1623
+ * Gets the singleton instance of HST
1624
+ * @returns The HST singleton instance
1625
+ */
1626
+ static getInstance(): HST;
1627
+ /**
1628
+ * Gets the global registry instance
1629
+ * @returns The global registry object or undefined if not found
1630
+ */
1631
+ getRegistry(): any;
1632
+ /**
1633
+ * Helper method to get doctype metadata from the registry
1634
+ * @param doctype - The name of the doctype to retrieve metadata for
1635
+ * @returns The doctype metadata object or undefined if not found
1636
+ */
1637
+ getDoctypeMeta(doctype: string): any;
1638
+ }
1639
+
1640
+ /**
1641
+ * HST Change data structure
1642
+ * @public
1643
+ */
1644
+ export declare type HSTChangeData = {
1645
+ path: string;
1646
+ value: any;
1647
+ fieldname: string;
1648
+ recordId?: string;
1649
+ };
1650
+
1651
+ /**
1652
+ * Core HST Interface - enhanced with tree navigation
1653
+ * Provides a hierarchical state tree interface for navigating and manipulating nested data structures.
1654
+ *
1655
+ * @public
1656
+ */
1657
+ export declare interface HSTNode {
1658
+ /**
1659
+ * Gets a value at the specified path
1660
+ * @param path - The dot-separated path to the value
1661
+ * @returns The value at the specified path
1662
+ */
1663
+ get(path: string): any;
1664
+ /**
1665
+ * Sets a value at the specified path
1666
+ * @param path - The dot-separated path where to set the value
1667
+ * @param value - The value to set
1668
+ * @param source - Optional source of the operation (user, system, sync, undo, redo)
1669
+ */
1670
+ set(path: string, value: any, source?: 'user' | 'system' | 'sync' | 'undo' | 'redo'): void;
1671
+ /**
1672
+ * Checks if a value exists at the specified path
1673
+ * @param path - The dot-separated path to check
1674
+ * @returns True if the path exists, false otherwise
1675
+ */
1676
+ has(path: string): boolean;
1677
+ /**
1678
+ * Gets the parent node in the tree hierarchy
1679
+ * @returns The parent HSTNode or null if this is the root
1680
+ */
1681
+ getParent(): HSTNode | null;
1682
+ /**
1683
+ * Gets the root node of the tree
1684
+ * @returns The root HSTNode
1685
+ */
1686
+ getRoot(): HSTNode;
1687
+ /**
1688
+ * Gets the full path from root to this node
1689
+ * @returns The dot-separated path string
1690
+ */
1691
+ getPath(): string;
1692
+ /**
1693
+ * Gets the depth level of this node in the tree
1694
+ * @returns The depth as a number (0 for root)
1695
+ */
1696
+ getDepth(): number;
1697
+ /**
1698
+ * Gets an array of path segments from root to this node
1699
+ * @returns Array of path segments representing breadcrumbs
1700
+ */
1701
+ getBreadcrumbs(): string[];
1702
+ /**
1703
+ * Gets a child node at the specified relative path
1704
+ * @param path - The relative path to the child node
1705
+ * @returns The child HSTNode
1706
+ */
1707
+ getNode(path: string): HSTNode;
1708
+ /**
1709
+ * Trigger an XState transition with optional context data
1710
+ * @param transition - The transition name (should be uppercase per convention)
1711
+ * @param context - Optional additional FSM context data
1712
+ * @returns Promise resolving to the transition execution results
1713
+ */
1714
+ triggerTransition(transition: string, context?: {
1715
+ currentState?: string;
1716
+ targetState?: string;
1717
+ fsmContext?: Record<string, any>;
1718
+ }): Promise<any>;
1719
+ }
1720
+
1721
+ /**
1722
+ * Complete metadata for an HST mutation
1723
+ * Enables time travel, synchronization, and audit trails
1724
+ * @public
1725
+ */
1726
+ export declare interface HSTOperation {
1727
+ /** Unique operation identifier */
1728
+ id: string;
1729
+ /** Type of operation performed */
1730
+ type: HSTOperationType;
1731
+ /** Full HST path affected (e.g., "task.123.title") */
1732
+ path: string;
1733
+ /** Field name extracted from path */
1734
+ fieldname: string;
1735
+ /** Value before the operation */
1736
+ beforeValue: any;
1737
+ /** Value after the operation */
1738
+ afterValue: any;
1739
+ /** Doctype this operation affects */
1740
+ doctype: string;
1741
+ /** Record ID if applicable */
1742
+ recordId?: string;
1743
+ /** Timestamp of the operation */
1744
+ timestamp: Date;
1745
+ /** Source of the operation (defaults to 'user' if not specified) */
1746
+ source?: OperationSource;
1747
+ /** Whether this operation can be undone */
1748
+ reversible: boolean;
1749
+ /** Reason if operation is irreversible */
1750
+ irreversibleReason?: string;
1751
+ /** XState transition name if triggered by FSM */
1752
+ transition?: string;
1753
+ /** XState current state before transition */
1754
+ currentState?: string;
1755
+ /** XState target state after transition */
1756
+ targetState?: string;
1757
+ /** Action name if operation is an action execution (type: 'action') */
1758
+ actionName?: string;
1759
+ /** Record IDs that the action was executed on */
1760
+ actionRecordIds?: string[];
1761
+ /** Result or status of the action execution */
1762
+ actionResult?: 'success' | 'failure' | 'pending';
1763
+ /** Error message if action execution failed */
1764
+ actionError?: string;
1765
+ /** User or session identifier */
1766
+ userId?: string;
1767
+ /** Additional metadata for custom use cases */
1768
+ metadata?: Record<string, any>;
1769
+ /** Parent operation ID for batch operations */
1770
+ parentOperationId?: string;
1771
+ /** Child operation IDs for batch operations */
1772
+ childOperationIds?: string[];
1773
+ }
1774
+
1775
+ /**
1776
+ * Input type for adding operations
1777
+ * Excludes system-generated fields (id, timestamp)
1778
+ * @public
1779
+ */
1780
+ export declare type HSTOperationInput = Omit<HSTOperation, 'id' | 'timestamp' | 'source'> & {
1781
+ source?: OperationSource;
1782
+ };
1783
+
1784
+ /**
1785
+ * Type of HST operation
1786
+ * @public
1787
+ */
1788
+ export declare type HSTOperationType = 'set' | 'delete' | 'batch' | 'transition' | 'action';
1789
+
1790
+ /**
1791
+ * HST-enabled Stonecrop composable return type
1792
+ * @public
1793
+ */
1794
+ export declare type HSTStonecropReturn = BaseStonecropReturn & {
1795
+ provideHSTPath: (fieldname: string, recordId?: string) => string;
1796
+ handleHSTChange: (changeData: HSTChangeData) => void;
1797
+ hstStore: Ref<HSTNode | undefined>;
1798
+ formData: Ref<Record<string, any>>;
1799
+ };
1800
+
1264
1801
  /**
1265
1802
  * Immutable Doctype type for Stonecrop instances
1266
1803
  * @public
@@ -1278,19 +1815,168 @@ export declare type ImmutableDoctype = {
1278
1815
  export declare type InstallOptions = {
1279
1816
  router?: Router;
1280
1817
  components?: Record<string, Component>;
1281
- getMeta?: (doctype?: string) => DoctypeMeta | Promise<DoctypeMeta>;
1818
+ getMeta?: (routeContext: RouteContext) => DoctypeMeta | Promise<DoctypeMeta>;
1819
+ /** Automatically run initialization callback after app mounting (default: false) */
1820
+ autoInitializeRouter?: boolean;
1821
+ /** Callback function called after plugin is ready and mounted */
1822
+ onRouterInitialized?: (registry: Registry, stonecrop: Stonecrop) => void | Promise<void>;
1282
1823
  };
1283
1824
 
1825
+ /**
1826
+ * Mark a specific operation as irreversible.
1827
+ * Used to prevent undo of critical operations like publishing or deletion.
1828
+ * @param operationId - The ID of the operation to mark as irreversible
1829
+ * @param reason - Human-readable reason why the operation cannot be undone
1830
+ * @public
1831
+ */
1832
+ export declare function markOperationIrreversible(operationId: string | undefined, reason: string): void;
1833
+
1284
1834
  /**
1285
1835
  * Mutable Doctype type for Stonecrop instances
1286
1836
  * @public
1287
1837
  */
1288
1838
  export declare type MutableDoctype = {
1839
+ doctype?: string;
1289
1840
  schema?: SchemaTypes[];
1290
1841
  workflow?: UnknownMachineConfig | AnyStateNodeConfig;
1291
1842
  actions?: Record<string, string[]>;
1292
1843
  };
1293
1844
 
1845
+ /**
1846
+ * Operation Log API - nested object containing all operation log functionality
1847
+ * @public
1848
+ */
1849
+ export declare type OperationLogAPI = {
1850
+ operations: Ref<HSTOperation[]>;
1851
+ currentIndex: Ref<number>;
1852
+ undoRedoState: ComputedRef<{
1853
+ canUndo: boolean;
1854
+ canRedo: boolean;
1855
+ undoCount: number;
1856
+ redoCount: number;
1857
+ currentIndex: number;
1858
+ }>;
1859
+ canUndo: ComputedRef<boolean>;
1860
+ canRedo: ComputedRef<boolean>;
1861
+ undoCount: ComputedRef<number>;
1862
+ redoCount: ComputedRef<number>;
1863
+ undo: (hstStore: HSTNode) => boolean;
1864
+ redo: (hstStore: HSTNode) => boolean;
1865
+ startBatch: () => void;
1866
+ commitBatch: (description?: string) => string | null;
1867
+ cancelBatch: () => void;
1868
+ clear: () => void;
1869
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
1870
+ getSnapshot: () => OperationLogSnapshot;
1871
+ markIrreversible: (operationId: string, reason: string) => void;
1872
+ logAction: (doctype: string, actionName: string, recordIds?: string[], result?: 'success' | 'failure' | 'pending', error?: string) => string;
1873
+ configure: (options: Partial<OperationLogConfig>) => void;
1874
+ };
1875
+
1876
+ /**
1877
+ * Operation log configuration
1878
+ * @public
1879
+ */
1880
+ export declare interface OperationLogConfig {
1881
+ /** Maximum operations to store (default: 100) */
1882
+ maxOperations?: number;
1883
+ /** Enable cross-tab synchronization (default: true) */
1884
+ enableCrossTabSync?: boolean;
1885
+ /** Auto-sync interval in milliseconds (default: 30000) */
1886
+ autoSyncInterval?: number;
1887
+ /** Enable operation persistence to localStorage (default: false) */
1888
+ enablePersistence?: boolean;
1889
+ /** Persistence key prefix */
1890
+ persistenceKeyPrefix?: string;
1891
+ /** User identifier for multi-user scenarios */
1892
+ userId?: string;
1893
+ /** Custom operation filter */
1894
+ operationFilter?: (operation: HSTOperation) => boolean;
1895
+ }
1896
+
1897
+ /**
1898
+ * Operation log snapshot for debugging
1899
+ * @public
1900
+ */
1901
+ export declare interface OperationLogSnapshot {
1902
+ /** All operations in the log */
1903
+ operations: HSTOperation[];
1904
+ /** Current operation index in the history */
1905
+ currentIndex: number;
1906
+ /** Total number of operations */
1907
+ totalOperations: number;
1908
+ /** Number of operations that can be undone */
1909
+ reversibleOperations: number;
1910
+ /** Number of operations that cannot be undone */
1911
+ irreversibleOperations: number;
1912
+ /** Timestamp of the oldest operation */
1913
+ oldestOperation?: Date;
1914
+ /** Timestamp of the newest operation */
1915
+ newestOperation?: Date;
1916
+ }
1917
+
1918
+ /**
1919
+ * Operation source - where the change originated
1920
+ * @public
1921
+ */
1922
+ export declare type OperationSource = 'user' | 'system' | 'sync' | 'undo' | 'redo';
1923
+
1924
+ /**
1925
+ * Pattern matching result for wildcard paths
1926
+ * @internal
1927
+ */
1928
+ export declare interface _PathMatchResult {
1929
+ /** Whether the path matches the pattern */
1930
+ matches: boolean;
1931
+ /** Captured wildcard values */
1932
+ captures: Record<string, string>;
1933
+ }
1934
+
1935
+ /**
1936
+ * Stonecrop Vue plugin
1937
+ * @param app - The Vue app instance
1938
+ * @param options - The plugin options
1939
+ * @example
1940
+ * ```ts
1941
+ * import { createApp } from 'vue'
1942
+ * import Stonecrop from '@stonecrop/stonecrop'
1943
+ * import router from './router'
1944
+ *
1945
+ * const app = createApp(App)
1946
+ * app.use(Stonecrop, {
1947
+ * router,
1948
+ * getMeta: async (routeContext) => {
1949
+ * // routeContext contains: { path, segments }
1950
+ * // fetch doctype meta from your API using the route context
1951
+ * },
1952
+ * autoInitializeRouter: true,
1953
+ * onRouterInitialized: async (registry, stonecrop) => {
1954
+ * // your custom initialization logic here
1955
+ * }
1956
+ * })
1957
+ * app.mount('#app')
1958
+ * ```
1959
+ * @public
1960
+ */
1961
+ declare const plugin: Plugin_2;
1962
+ export default plugin;
1963
+
1964
+ /**
1965
+ * Register a global action function that can be used in field triggers
1966
+ * @param name - The name of the action to register
1967
+ * @param fn - The action function to execute when the trigger fires
1968
+ * @public
1969
+ */
1970
+ export declare function registerGlobalAction(name: string, fn: FieldActionFunction): void;
1971
+
1972
+ /**
1973
+ * Register a global XState transition action function
1974
+ * @param name - The name of the transition action to register
1975
+ * @param fn - The transition action function to execute
1976
+ * @public
1977
+ */
1978
+ export declare function registerTransitionAction(name: string, fn: TransitionActionFunction): void;
1979
+
1294
1980
  /**
1295
1981
  * Stonecrop Registry class
1296
1982
  * @public
@@ -1316,12 +2002,17 @@ export declare class Registry {
1316
2002
  * @see {@link https://router.vuejs.org/}
1317
2003
  */
1318
2004
  readonly router?: Router;
1319
- constructor(router?: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>);
1320
2005
  /**
1321
- * The getMeta function fetches doctype metadata from an API
2006
+ * Creates a new Registry instance (singleton pattern)
2007
+ * @param router - Optional Vue router instance for route management
2008
+ * @param getMeta - Optional function to fetch doctype metadata from an API
2009
+ */
2010
+ constructor(router?: Router, getMeta?: (routeContext: RouteContext) => DoctypeMeta | Promise<DoctypeMeta>);
2011
+ /**
2012
+ * The getMeta function fetches doctype metadata from an API based on route context
1322
2013
  * @see {@link DoctypeMeta}
1323
2014
  */
1324
- getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>;
2015
+ getMeta?: (routeContext: RouteContext) => DoctypeMeta | Promise<DoctypeMeta>;
1325
2016
  /**
1326
2017
  * Get doctype metadata
1327
2018
  * @param doctype - The doctype to fetch metadata for
@@ -1331,6 +2022,17 @@ export declare class Registry {
1331
2022
  addDoctype(doctype: DoctypeMeta): void;
1332
2023
  }
1333
2024
 
2025
+ /**
2026
+ * Route context passed to getMeta function
2027
+ * @public
2028
+ */
2029
+ export declare interface RouteContext {
2030
+ /** The full route path (e.g., "/todo/1" or "/todo") */
2031
+ path: string;
2032
+ /** Path segments split by "/" (e.g., ["todo", "1"] or ["todo"]) */
2033
+ segments: string[];
2034
+ }
2035
+
1334
2036
  /**
1335
2037
  * Schema type for Stonecrop instances
1336
2038
  * @public
@@ -1347,175 +2049,380 @@ export declare type Schema = {
1347
2049
  export declare type SchemaTypes = FormSchema | TableSchema | FieldsetSchema;
1348
2050
 
1349
2051
  /**
1350
- * Stonecrop Vue plugin
1351
- * @param app - The Vue app instance
1352
- * @param options - The plugin options
1353
- * @example
1354
- * ```ts
1355
- *
1356
- * import { createApp } from 'vue'
1357
- * import Stonecrop from 'stonecrop'
1358
- *
1359
- * import App from './App.vue'
1360
- *
1361
- * const app = createApp(App)
1362
- * app.use(Stonecrop, {
1363
- * router,
1364
- * components: {
1365
- * // register custom components
1366
- * },
1367
- * getMeta: async (doctype: string) => {
1368
- * // fetch doctype meta from API
1369
- * },
1370
- * })
1371
- *
1372
- * app.mount('#app')
1373
- * ```
1374
- *
2052
+ * Configure rollback behavior for a specific field trigger
2053
+ * @param doctype - The doctype name
2054
+ * @param fieldname - The field name
2055
+ * @param enableRollback - Whether to enable automatic rollback for this field
1375
2056
  * @public
1376
2057
  */
1377
- export declare const Stonecrop: Plugin_2;
2058
+ export declare function setFieldRollback(doctype: string, fieldname: string, enableRollback: boolean): void;
1378
2059
 
1379
2060
  /**
1380
- * Stonecrop class
2061
+ * Main Stonecrop class with HST integration and built-in Operation Log
1381
2062
  * @public
1382
2063
  */
1383
- export declare class StonecropClass {
2064
+ export declare class Stonecrop {
2065
+ private hstStore;
2066
+ private _operationLogStore?;
2067
+ private _operationLogConfig?;
2068
+ /** The registry instance containing all doctype definitions */
2069
+ readonly registry: Registry;
1384
2070
  /**
1385
- * The root Stonecrop instance
2071
+ * Creates a new Stonecrop instance with HST integration
2072
+ * @param registry - The Registry instance containing doctype definitions
2073
+ * @param operationLogConfig - Optional configuration for the operation log
1386
2074
  */
1387
- static _root: StonecropClass;
2075
+ constructor(registry: Registry, operationLogConfig?: Partial<OperationLogConfig>);
1388
2076
  /**
1389
- * The name of the Stonecrop instance
1390
- * @readonly
1391
- *
1392
- * @defaultValue 'Stonecrop'
2077
+ * Get the operation log store (lazy initialization)
2078
+ * @internal
1393
2079
  */
1394
- readonly name = "Stonecrop";
2080
+ getOperationLogStore(): Store<"hst-operation-log", Pick<{
2081
+ operations: Ref< {
2082
+ id: string;
2083
+ type: HSTOperationType_2;
2084
+ path: string;
2085
+ fieldname: string;
2086
+ beforeValue: any;
2087
+ afterValue: any;
2088
+ doctype: string;
2089
+ recordId?: string | undefined;
2090
+ timestamp: Date;
2091
+ source?: OperationSource_2 | undefined;
2092
+ reversible: boolean;
2093
+ irreversibleReason?: string | undefined;
2094
+ transition?: string | undefined;
2095
+ currentState?: string | undefined;
2096
+ targetState?: string | undefined;
2097
+ actionName?: string | undefined;
2098
+ actionRecordIds?: string[] | undefined;
2099
+ actionResult?: "success" | "failure" | "pending" | undefined;
2100
+ actionError?: string | undefined;
2101
+ userId?: string | undefined;
2102
+ metadata?: Record<string, any> | undefined;
2103
+ parentOperationId?: string | undefined;
2104
+ childOperationIds?: string[] | undefined;
2105
+ }[], HSTOperation_2[] | {
2106
+ id: string;
2107
+ type: HSTOperationType_2;
2108
+ path: string;
2109
+ fieldname: string;
2110
+ beforeValue: any;
2111
+ afterValue: any;
2112
+ doctype: string;
2113
+ recordId?: string | undefined;
2114
+ timestamp: Date;
2115
+ source?: OperationSource_2 | undefined;
2116
+ reversible: boolean;
2117
+ irreversibleReason?: string | undefined;
2118
+ transition?: string | undefined;
2119
+ currentState?: string | undefined;
2120
+ targetState?: string | undefined;
2121
+ actionName?: string | undefined;
2122
+ actionRecordIds?: string[] | undefined;
2123
+ actionResult?: "success" | "failure" | "pending" | undefined;
2124
+ actionError?: string | undefined;
2125
+ userId?: string | undefined;
2126
+ metadata?: Record<string, any> | undefined;
2127
+ parentOperationId?: string | undefined;
2128
+ childOperationIds?: string[] | undefined;
2129
+ }[]>;
2130
+ currentIndex: Ref<number, number>;
2131
+ config: Ref< {
2132
+ maxOperations?: number | undefined;
2133
+ enableCrossTabSync?: boolean | undefined;
2134
+ autoSyncInterval?: number | undefined;
2135
+ enablePersistence?: boolean | undefined;
2136
+ persistenceKeyPrefix?: string | undefined;
2137
+ userId?: string | undefined;
2138
+ operationFilter?: ((operation: HSTOperation_2) => boolean) | undefined;
2139
+ }, OperationLogConfig | {
2140
+ maxOperations?: number | undefined;
2141
+ enableCrossTabSync?: boolean | undefined;
2142
+ autoSyncInterval?: number | undefined;
2143
+ enablePersistence?: boolean | undefined;
2144
+ persistenceKeyPrefix?: string | undefined;
2145
+ userId?: string | undefined;
2146
+ operationFilter?: ((operation: HSTOperation_2) => boolean) | undefined;
2147
+ }>;
2148
+ clientId: Ref<string, string>;
2149
+ undoRedoState: ComputedRef<UndoRedoState_2>;
2150
+ canUndo: ComputedRef<boolean>;
2151
+ canRedo: ComputedRef<boolean>;
2152
+ undoCount: ComputedRef<number>;
2153
+ redoCount: ComputedRef<number>;
2154
+ configure: (options: Partial<OperationLogConfig>) => void;
2155
+ addOperation: (operation: HSTOperationInput_2, source?: OperationSource_2) => string;
2156
+ startBatch: () => void;
2157
+ commitBatch: (description?: string) => string | null;
2158
+ cancelBatch: () => void;
2159
+ undo: (store: HSTNode) => boolean;
2160
+ redo: (store: HSTNode) => boolean;
2161
+ clear: () => void;
2162
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation_2[];
2163
+ getSnapshot: () => OperationLogSnapshot_2;
2164
+ markIrreversible: (operationId: string, reason: string) => void;
2165
+ logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
2166
+ }, "operations" | "clientId" | "currentIndex" | "config">, Pick<{
2167
+ operations: Ref< {
2168
+ id: string;
2169
+ type: HSTOperationType_2;
2170
+ path: string;
2171
+ fieldname: string;
2172
+ beforeValue: any;
2173
+ afterValue: any;
2174
+ doctype: string;
2175
+ recordId?: string | undefined;
2176
+ timestamp: Date;
2177
+ source?: OperationSource_2 | undefined;
2178
+ reversible: boolean;
2179
+ irreversibleReason?: string | undefined;
2180
+ transition?: string | undefined;
2181
+ currentState?: string | undefined;
2182
+ targetState?: string | undefined;
2183
+ actionName?: string | undefined;
2184
+ actionRecordIds?: string[] | undefined;
2185
+ actionResult?: "success" | "failure" | "pending" | undefined;
2186
+ actionError?: string | undefined;
2187
+ userId?: string | undefined;
2188
+ metadata?: Record<string, any> | undefined;
2189
+ parentOperationId?: string | undefined;
2190
+ childOperationIds?: string[] | undefined;
2191
+ }[], HSTOperation_2[] | {
2192
+ id: string;
2193
+ type: HSTOperationType_2;
2194
+ path: string;
2195
+ fieldname: string;
2196
+ beforeValue: any;
2197
+ afterValue: any;
2198
+ doctype: string;
2199
+ recordId?: string | undefined;
2200
+ timestamp: Date;
2201
+ source?: OperationSource_2 | undefined;
2202
+ reversible: boolean;
2203
+ irreversibleReason?: string | undefined;
2204
+ transition?: string | undefined;
2205
+ currentState?: string | undefined;
2206
+ targetState?: string | undefined;
2207
+ actionName?: string | undefined;
2208
+ actionRecordIds?: string[] | undefined;
2209
+ actionResult?: "success" | "failure" | "pending" | undefined;
2210
+ actionError?: string | undefined;
2211
+ userId?: string | undefined;
2212
+ metadata?: Record<string, any> | undefined;
2213
+ parentOperationId?: string | undefined;
2214
+ childOperationIds?: string[] | undefined;
2215
+ }[]>;
2216
+ currentIndex: Ref<number, number>;
2217
+ config: Ref< {
2218
+ maxOperations?: number | undefined;
2219
+ enableCrossTabSync?: boolean | undefined;
2220
+ autoSyncInterval?: number | undefined;
2221
+ enablePersistence?: boolean | undefined;
2222
+ persistenceKeyPrefix?: string | undefined;
2223
+ userId?: string | undefined;
2224
+ operationFilter?: ((operation: HSTOperation_2) => boolean) | undefined;
2225
+ }, OperationLogConfig | {
2226
+ maxOperations?: number | undefined;
2227
+ enableCrossTabSync?: boolean | undefined;
2228
+ autoSyncInterval?: number | undefined;
2229
+ enablePersistence?: boolean | undefined;
2230
+ persistenceKeyPrefix?: string | undefined;
2231
+ userId?: string | undefined;
2232
+ operationFilter?: ((operation: HSTOperation_2) => boolean) | undefined;
2233
+ }>;
2234
+ clientId: Ref<string, string>;
2235
+ undoRedoState: ComputedRef<UndoRedoState_2>;
2236
+ canUndo: ComputedRef<boolean>;
2237
+ canRedo: ComputedRef<boolean>;
2238
+ undoCount: ComputedRef<number>;
2239
+ redoCount: ComputedRef<number>;
2240
+ configure: (options: Partial<OperationLogConfig>) => void;
2241
+ addOperation: (operation: HSTOperationInput_2, source?: OperationSource_2) => string;
2242
+ startBatch: () => void;
2243
+ commitBatch: (description?: string) => string | null;
2244
+ cancelBatch: () => void;
2245
+ undo: (store: HSTNode) => boolean;
2246
+ redo: (store: HSTNode) => boolean;
2247
+ clear: () => void;
2248
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation_2[];
2249
+ getSnapshot: () => OperationLogSnapshot_2;
2250
+ markIrreversible: (operationId: string, reason: string) => void;
2251
+ logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
2252
+ }, "undoRedoState" | "canUndo" | "canRedo" | "undoCount" | "redoCount">, Pick<{
2253
+ operations: Ref< {
2254
+ id: string;
2255
+ type: HSTOperationType_2;
2256
+ path: string;
2257
+ fieldname: string;
2258
+ beforeValue: any;
2259
+ afterValue: any;
2260
+ doctype: string;
2261
+ recordId?: string | undefined;
2262
+ timestamp: Date;
2263
+ source?: OperationSource_2 | undefined;
2264
+ reversible: boolean;
2265
+ irreversibleReason?: string | undefined;
2266
+ transition?: string | undefined;
2267
+ currentState?: string | undefined;
2268
+ targetState?: string | undefined;
2269
+ actionName?: string | undefined;
2270
+ actionRecordIds?: string[] | undefined;
2271
+ actionResult?: "success" | "failure" | "pending" | undefined;
2272
+ actionError?: string | undefined;
2273
+ userId?: string | undefined;
2274
+ metadata?: Record<string, any> | undefined;
2275
+ parentOperationId?: string | undefined;
2276
+ childOperationIds?: string[] | undefined;
2277
+ }[], HSTOperation_2[] | {
2278
+ id: string;
2279
+ type: HSTOperationType_2;
2280
+ path: string;
2281
+ fieldname: string;
2282
+ beforeValue: any;
2283
+ afterValue: any;
2284
+ doctype: string;
2285
+ recordId?: string | undefined;
2286
+ timestamp: Date;
2287
+ source?: OperationSource_2 | undefined;
2288
+ reversible: boolean;
2289
+ irreversibleReason?: string | undefined;
2290
+ transition?: string | undefined;
2291
+ currentState?: string | undefined;
2292
+ targetState?: string | undefined;
2293
+ actionName?: string | undefined;
2294
+ actionRecordIds?: string[] | undefined;
2295
+ actionResult?: "success" | "failure" | "pending" | undefined;
2296
+ actionError?: string | undefined;
2297
+ userId?: string | undefined;
2298
+ metadata?: Record<string, any> | undefined;
2299
+ parentOperationId?: string | undefined;
2300
+ childOperationIds?: string[] | undefined;
2301
+ }[]>;
2302
+ currentIndex: Ref<number, number>;
2303
+ config: Ref< {
2304
+ maxOperations?: number | undefined;
2305
+ enableCrossTabSync?: boolean | undefined;
2306
+ autoSyncInterval?: number | undefined;
2307
+ enablePersistence?: boolean | undefined;
2308
+ persistenceKeyPrefix?: string | undefined;
2309
+ userId?: string | undefined;
2310
+ operationFilter?: ((operation: HSTOperation_2) => boolean) | undefined;
2311
+ }, OperationLogConfig | {
2312
+ maxOperations?: number | undefined;
2313
+ enableCrossTabSync?: boolean | undefined;
2314
+ autoSyncInterval?: number | undefined;
2315
+ enablePersistence?: boolean | undefined;
2316
+ persistenceKeyPrefix?: string | undefined;
2317
+ userId?: string | undefined;
2318
+ operationFilter?: ((operation: HSTOperation_2) => boolean) | undefined;
2319
+ }>;
2320
+ clientId: Ref<string, string>;
2321
+ undoRedoState: ComputedRef<UndoRedoState_2>;
2322
+ canUndo: ComputedRef<boolean>;
2323
+ canRedo: ComputedRef<boolean>;
2324
+ undoCount: ComputedRef<number>;
2325
+ redoCount: ComputedRef<number>;
2326
+ configure: (options: Partial<OperationLogConfig>) => void;
2327
+ addOperation: (operation: HSTOperationInput_2, source?: OperationSource_2) => string;
2328
+ startBatch: () => void;
2329
+ commitBatch: (description?: string) => string | null;
2330
+ cancelBatch: () => void;
2331
+ undo: (store: HSTNode) => boolean;
2332
+ redo: (store: HSTNode) => boolean;
2333
+ clear: () => void;
2334
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation_2[];
2335
+ getSnapshot: () => OperationLogSnapshot_2;
2336
+ markIrreversible: (operationId: string, reason: string) => void;
2337
+ logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
2338
+ }, "undo" | "redo" | "configure" | "addOperation" | "startBatch" | "commitBatch" | "cancelBatch" | "clear" | "getOperationsFor" | "getSnapshot" | "markIrreversible" | "logAction">>;
2339
+ /**
2340
+ * Initialize the HST store structure
2341
+ */
2342
+ private initializeHSTStore;
2343
+ /**
2344
+ * Setup automatic sync with Registry when doctypes are added
2345
+ */
2346
+ private setupRegistrySync;
2347
+ /**
2348
+ * Get records hash for a doctype
2349
+ * @param doctype - The doctype to get records for
2350
+ * @returns HST node containing records hash
2351
+ */
2352
+ records(doctype: string | DoctypeMeta): HSTNode;
1395
2353
  /**
1396
- * The registry is an immutable collection of doctypes
1397
- * @example
1398
- * ```ts
1399
- * {
1400
- * 'task': {
1401
- * doctype: 'Task',
1402
- * schema: {
1403
- * title: 'string',
1404
- * description: 'string',
1405
- * ...
1406
- * }
1407
- * },
1408
- * ...
1409
- * }
1410
- * ```
1411
- * @see {@link Registry}
1412
- * @see {@link DoctypeMeta}
2354
+ * Add a record to the store
2355
+ * @param doctype - The doctype
2356
+ * @param recordId - The record ID
2357
+ * @param recordData - The record data
1413
2358
  */
1414
- readonly registry: Registry;
2359
+ addRecord(doctype: string | DoctypeMeta, recordId: string, recordData: any): void;
1415
2360
  /**
1416
- * The Pinia store that manages the mutable records
2361
+ * Get a specific record
2362
+ * @param doctype - The doctype
2363
+ * @param recordId - The record ID
2364
+ * @returns HST node for the record or undefined
1417
2365
  */
1418
- store: ReturnType<typeof useDataStore>;
2366
+ getRecordById(doctype: string | DoctypeMeta, recordId: string): HSTNode | undefined;
1419
2367
  /**
1420
- * @param registry - The immutable registry
1421
- * @param store - The mutable Pinia store
1422
- * @returns The Stonecrop instance with the given registry and store. If a Stonecrop instance has already been created, it returns the existing instance instead of creating a new one.
1423
- * @example
1424
- * ```ts
1425
- * const registry = new Registry()
1426
- * const store = useDataStore()
1427
- * const stonecrop = new Stonecrop(registry, store)
1428
- * ```
2368
+ * Remove a record from the store
2369
+ * @param doctype - The doctype
2370
+ * @param recordId - The record ID
2371
+ */
2372
+ removeRecord(doctype: string | DoctypeMeta, recordId: string): void;
2373
+ /**
2374
+ * Get all record IDs for a doctype
2375
+ * @param doctype - The doctype
2376
+ * @returns Array of record IDs
2377
+ */
2378
+ getRecordIds(doctype: string | DoctypeMeta): string[];
2379
+ /**
2380
+ * Clear all records for a doctype
2381
+ * @param doctype - The doctype
1429
2382
  */
1430
- constructor(registry: Registry, store: ReturnType<typeof useDataStore>);
2383
+ clearRecords(doctype: string | DoctypeMeta): void;
1431
2384
  /**
1432
- * Sets up the Stonecrop instance with the given doctype
2385
+ * Setup method for doctype initialization
1433
2386
  * @param doctype - The doctype to setup
1434
- * @example
1435
- * ```ts
1436
- * const doctype = await registry.getMeta('Task')
1437
- * stonecrop.setup(doctype)
1438
- * ```
1439
2387
  */
1440
2388
  setup(doctype: DoctypeMeta): void;
1441
2389
  /**
1442
- * Gets the meta for the given doctype
1443
- * @param doctype - The doctype to get meta for
1444
- * @returns The meta for the given doctype
1445
- * @throws `NotImplementedError` if the `getMeta` function is not implemented for the doctype in the registry
1446
- * @example
1447
- * ```ts
1448
- * const doctype = await registry.getMeta('Task')
1449
- * const meta = stonecrop.getMeta(doctype)
1450
- * ```
1451
- * @see {@link DoctypeMeta}
2390
+ * Run action on doctype
2391
+ * Executes the action and logs it to the operation log for audit tracking
2392
+ * @param doctype - The doctype
2393
+ * @param action - The action to run
2394
+ * @param args - Action arguments (typically record IDs)
1452
2395
  */
1453
- getMeta(doctype: string): Promise<DoctypeMeta> | never;
2396
+ runAction(doctype: DoctypeMeta, action: string, args?: any[]): void;
1454
2397
  /**
1455
- * Gets the records for the given doctype
1456
- * @param doctype - The doctype to get records for
1457
- * @param filters - The filters to apply to the records
1458
- * @example
1459
- * ```ts
1460
- * const doctype = await registry.getMeta('Task')
1461
- * await stonecrop.getRecords(doctype)
1462
- * ```
1463
- * @example
1464
- * ```ts
1465
- * const doctype = await registry.getMeta('Task')
1466
- * const filters = JSON.stringify({ status: 'Open' })
1467
- * await stonecrop.getRecords(doctype, { body: filters })
1468
- * ```
2398
+ * Get records from server (maintains compatibility)
2399
+ * @param doctype - The doctype
1469
2400
  */
1470
- getRecords(doctype: DoctypeMeta, filters?: RequestInit): Promise<void>;
2401
+ getRecords(doctype: DoctypeMeta): Promise<void>;
1471
2402
  /**
1472
- * Gets the record for the given doctype and id
1473
- * @param doctype - The doctype to get record for
1474
- * @param id - The id of the record to get
1475
- * @example
1476
- * ```ts
1477
- * const doctype = await registry.getMeta('Task')
1478
- * await stonecrop.getRecord(doctype, 'TASK-00001')
1479
- * ```
2403
+ * Get single record from server (maintains compatibility)
2404
+ * @param doctype - The doctype
2405
+ * @param recordId - The record ID
1480
2406
  */
1481
- getRecord(doctype: DoctypeMeta, id: string): Promise<void>;
2407
+ getRecord(doctype: DoctypeMeta, recordId: string): Promise<void>;
1482
2408
  /**
1483
- * Runs the action for the given doctype and id
1484
- * @param doctype - The doctype to run action for
1485
- * @param action - The action to run
1486
- * @param id - The id(s) of the record(s) to run action on
1487
- * @example
1488
- * ```ts
1489
- * const doctype = await registry.getMeta('Task')
1490
- * stonecrop.runAction(doctype, 'create')
1491
- * ```
1492
- * @example
1493
- * ```ts
1494
- * const doctype = await registry.getMeta('Task')
1495
- * stonecrop.runAction(doctype, 'update', ['TASK-00001'])
1496
- * ```
1497
- * @example
1498
- * ```ts
1499
- * const doctype = await registry.getMeta('Task')
1500
- * stonecrop.runAction(doctype, 'delete', ['TASK-00001'])
1501
- * ```
1502
- * @example
1503
- * ```ts
1504
- * const doctype = await registry.getMeta('Task')
1505
- * stonecrop.runAction(doctype, 'merge', ['TASK-00001', 'TASK-00002'])
1506
- * ```
2409
+ * Ensure doctype section exists in HST store
2410
+ * @param slug - The doctype slug
2411
+ */
2412
+ private ensureDoctypeExists;
2413
+ /**
2414
+ * Get doctype metadata from the registry
2415
+ * @param context - The route context
2416
+ * @returns The doctype metadata
1507
2417
  */
1508
- runAction(doctype: DoctypeMeta, action: string, id?: string[]): void;
2418
+ getMeta(context: RouteContext): Promise<any>;
2419
+ /**
2420
+ * Get the root HST store node for advanced usage
2421
+ * @returns Root HST node
2422
+ */
2423
+ getStore(): HSTNode;
1509
2424
  }
1510
2425
 
1511
- /**
1512
- * Stonecrop composable return type
1513
- * @public
1514
- */
1515
- export declare type StonecropReturn = {
1516
- stonecrop: Ref<StonecropClass | undefined>;
1517
- };
1518
-
1519
2426
  /**
1520
2427
  * Table column definition.
1521
2428
  * @public
@@ -1571,6 +2478,11 @@ export declare interface TableColumn {
1571
2478
  * @defaultValue false
1572
2479
  */
1573
2480
  pinned?: boolean;
2481
+ /**
2482
+ * Control whether the column can be resized by the user.
2483
+ *
2484
+ * @defaultValue false
2485
+ */
1574
2486
  resizable?: boolean;
1575
2487
  /**
1576
2488
  * The component to use to render the cell for the column. If not provided, the table will
@@ -1862,6 +2774,53 @@ export declare type TableSchema = BaseSchema & {
1862
2774
  rows?: TableRow[];
1863
2775
  };
1864
2776
 
2777
+ /**
2778
+ * Supported action types for XState transitions
2779
+ * Can be either a transition-specific function or a string reference
2780
+ * @public
2781
+ */
2782
+ export declare type TransitionAction = TransitionActionFunction | FieldActionString;
2783
+
2784
+ /**
2785
+ * Action function for XState transition triggers
2786
+ * Receives enhanced context with FSM state information
2787
+ * @public
2788
+ */
2789
+ export declare type TransitionActionFunction = (context: TransitionChangeContext) => void | Promise<void>;
2790
+
2791
+ /**
2792
+ * Context provided to XState transition action functions
2793
+ * Extends FieldChangeContext with FSM-specific data
2794
+ * @public
2795
+ */
2796
+ export declare interface TransitionChangeContext extends FieldChangeContext {
2797
+ /** The XState transition name that triggered this action */
2798
+ transition: string;
2799
+ /** Current workflow state before transition */
2800
+ currentState?: string;
2801
+ /** Target workflow state after transition */
2802
+ targetState?: string;
2803
+ /** Additional FSM context data */
2804
+ fsmContext?: Record<string, any>;
2805
+ }
2806
+
2807
+ /**
2808
+ * Result of executing an XState transition action
2809
+ * @public
2810
+ */
2811
+ export declare interface TransitionExecutionResult {
2812
+ /** Whether the action executed successfully */
2813
+ success: boolean;
2814
+ /** Error if execution failed */
2815
+ error?: Error;
2816
+ /** Execution time in milliseconds */
2817
+ executionTime: number;
2818
+ /** The action that was executed */
2819
+ action: TransitionAction;
2820
+ /** The transition name that was executed */
2821
+ transition: string;
2822
+ }
2823
+
1865
2824
  /**
1866
2825
  * Table configuration for tree-gantt view types.
1867
2826
  * @public
@@ -1909,24 +2868,461 @@ export declare interface TreeTableConfig extends BaseTableConfig {
1909
2868
  defaultTreeExpansion?: 'root' | 'branch' | 'leaf';
1910
2869
  }
1911
2870
 
1912
- declare const useDataStore: StoreDefinition<"data", Pick<{
1913
- records: Ref<Record<string, any>[], Record<string, any>[]>;
1914
- record: Ref<Record<string, any>, Record<string, any>>;
1915
- }, "records" | "record">, Pick<{
1916
- records: Ref<Record<string, any>[], Record<string, any>[]>;
1917
- record: Ref<Record<string, any>, Record<string, any>>;
1918
- }, never>, Pick<{
1919
- records: Ref<Record<string, any>[], Record<string, any>[]>;
1920
- record: Ref<Record<string, any>, Record<string, any>>;
1921
- }, never>>;
2871
+ /**
2872
+ * Manually trigger an XState transition for a specific doctype/record
2873
+ * This can be called directly when you need to execute transition actions programmatically
2874
+ * @param doctype - The doctype name
2875
+ * @param transition - The XState transition name to trigger
2876
+ * @param options - Optional configuration for the transition
2877
+ * @public
2878
+ */
2879
+ export declare function triggerTransition(doctype: string, transition: string, options?: {
2880
+ recordId?: string;
2881
+ currentState?: string;
2882
+ targetState?: string;
2883
+ fsmContext?: Record<string, any>;
2884
+ path?: string;
2885
+ }): Promise<any>;
1922
2886
 
1923
2887
  /**
1924
- * Stonecrop composable
1925
- * @param registry - An existing Stonecrop Registry instance
1926
- * @returns The Stonecrop instance and a boolean indicating if Stonecrop is setup and ready
1927
- * @throws Error if the Stonecrop plugin is not enabled before using the composable
2888
+ * Undo/Redo state
2889
+ * @public
2890
+ */
2891
+ export declare interface UndoRedoState {
2892
+ /** Can undo */
2893
+ canUndo: boolean;
2894
+ /** Can redo */
2895
+ canRedo: boolean;
2896
+ /** Number of operations available for undo */
2897
+ undoCount: number;
2898
+ /** Number of operations available for redo */
2899
+ redoCount: number;
2900
+ /** Current operation index */
2901
+ currentIndex: number;
2902
+ }
2903
+
2904
+ /**
2905
+ * Composable for operation log management
2906
+ * Provides easy access to undo/redo functionality and operation history
2907
+ *
2908
+ * @param config - Optional configuration for the operation log
2909
+ * @returns Operation log interface
2910
+ *
2911
+ * @example
2912
+ * ```typescript
2913
+ * const { undo, redo, canUndo, canRedo, operations, configure } = useOperationLog()
2914
+ *
2915
+ * // Configure the log
2916
+ * configure({
2917
+ * maxOperations: 50,
2918
+ * enableCrossTabSync: true,
2919
+ * enablePersistence: true
2920
+ * })
2921
+ *
2922
+ * // Undo/redo
2923
+ * await undo(hstStore)
2924
+ * await redo(hstStore)
2925
+ * ```
2926
+ *
2927
+ * @public
2928
+ */
2929
+ export declare function useOperationLog(config?: Partial<OperationLogConfig>): {
2930
+ operations: Ref< {
2931
+ id: string;
2932
+ type: HSTOperationType_3;
2933
+ path: string;
2934
+ fieldname: string;
2935
+ beforeValue: any;
2936
+ afterValue: any;
2937
+ doctype: string;
2938
+ recordId?: string | undefined;
2939
+ timestamp: Date;
2940
+ source?: OperationSource_3 | undefined;
2941
+ reversible: boolean;
2942
+ irreversibleReason?: string | undefined;
2943
+ transition?: string | undefined;
2944
+ currentState?: string | undefined;
2945
+ targetState?: string | undefined;
2946
+ actionName?: string | undefined;
2947
+ actionRecordIds?: string[] | undefined;
2948
+ actionResult?: "success" | "failure" | "pending" | undefined;
2949
+ actionError?: string | undefined;
2950
+ userId?: string | undefined;
2951
+ metadata?: Record<string, any> | undefined;
2952
+ parentOperationId?: string | undefined;
2953
+ childOperationIds?: string[] | undefined;
2954
+ }[], HSTOperation_3[] | {
2955
+ id: string;
2956
+ type: HSTOperationType_3;
2957
+ path: string;
2958
+ fieldname: string;
2959
+ beforeValue: any;
2960
+ afterValue: any;
2961
+ doctype: string;
2962
+ recordId?: string | undefined;
2963
+ timestamp: Date;
2964
+ source?: OperationSource_3 | undefined;
2965
+ reversible: boolean;
2966
+ irreversibleReason?: string | undefined;
2967
+ transition?: string | undefined;
2968
+ currentState?: string | undefined;
2969
+ targetState?: string | undefined;
2970
+ actionName?: string | undefined;
2971
+ actionRecordIds?: string[] | undefined;
2972
+ actionResult?: "success" | "failure" | "pending" | undefined;
2973
+ actionError?: string | undefined;
2974
+ userId?: string | undefined;
2975
+ metadata?: Record<string, any> | undefined;
2976
+ parentOperationId?: string | undefined;
2977
+ childOperationIds?: string[] | undefined;
2978
+ }[]>;
2979
+ currentIndex: Ref<number, number>;
2980
+ undoRedoState: ComputedRef<UndoRedoState_3>;
2981
+ canUndo: ComputedRef<boolean>;
2982
+ canRedo: ComputedRef<boolean>;
2983
+ undoCount: ComputedRef<number>;
2984
+ redoCount: ComputedRef<number>;
2985
+ undo: (hstStore: HSTNode) => boolean;
2986
+ redo: (hstStore: HSTNode) => boolean;
2987
+ startBatch: () => void;
2988
+ commitBatch: (description?: string) => string | null;
2989
+ cancelBatch: () => void;
2990
+ clear: () => void;
2991
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation_3[];
2992
+ getSnapshot: () => OperationLogSnapshot_3;
2993
+ markIrreversible: (operationId: string, reason: string) => void;
2994
+ logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
2995
+ configure: (options: Partial<OperationLogConfig>) => void;
2996
+ };
2997
+
2998
+ /**
2999
+ * Global HST Operation Log Store
3000
+ * Tracks all mutations with full metadata for undo/redo, sync, and audit
3001
+ *
3002
+ * @public
3003
+ */
3004
+ export declare const useOperationLogStore: StoreDefinition<"hst-operation-log", Pick<{
3005
+ operations: Ref< {
3006
+ id: string;
3007
+ type: HSTOperationType_3;
3008
+ path: string;
3009
+ fieldname: string;
3010
+ beforeValue: any;
3011
+ afterValue: any;
3012
+ doctype: string;
3013
+ recordId?: string | undefined;
3014
+ timestamp: Date;
3015
+ source?: OperationSource | undefined;
3016
+ reversible: boolean;
3017
+ irreversibleReason?: string | undefined;
3018
+ transition?: string | undefined;
3019
+ currentState?: string | undefined;
3020
+ targetState?: string | undefined;
3021
+ actionName?: string | undefined;
3022
+ actionRecordIds?: string[] | undefined;
3023
+ actionResult?: "success" | "failure" | "pending" | undefined;
3024
+ actionError?: string | undefined;
3025
+ userId?: string | undefined;
3026
+ metadata?: Record<string, any> | undefined;
3027
+ parentOperationId?: string | undefined;
3028
+ childOperationIds?: string[] | undefined;
3029
+ }[], HSTOperation[] | {
3030
+ id: string;
3031
+ type: HSTOperationType_3;
3032
+ path: string;
3033
+ fieldname: string;
3034
+ beforeValue: any;
3035
+ afterValue: any;
3036
+ doctype: string;
3037
+ recordId?: string | undefined;
3038
+ timestamp: Date;
3039
+ source?: OperationSource | undefined;
3040
+ reversible: boolean;
3041
+ irreversibleReason?: string | undefined;
3042
+ transition?: string | undefined;
3043
+ currentState?: string | undefined;
3044
+ targetState?: string | undefined;
3045
+ actionName?: string | undefined;
3046
+ actionRecordIds?: string[] | undefined;
3047
+ actionResult?: "success" | "failure" | "pending" | undefined;
3048
+ actionError?: string | undefined;
3049
+ userId?: string | undefined;
3050
+ metadata?: Record<string, any> | undefined;
3051
+ parentOperationId?: string | undefined;
3052
+ childOperationIds?: string[] | undefined;
3053
+ }[]>;
3054
+ currentIndex: Ref<number, number>;
3055
+ config: Ref< {
3056
+ maxOperations?: number | undefined;
3057
+ enableCrossTabSync?: boolean | undefined;
3058
+ autoSyncInterval?: number | undefined;
3059
+ enablePersistence?: boolean | undefined;
3060
+ persistenceKeyPrefix?: string | undefined;
3061
+ userId?: string | undefined;
3062
+ operationFilter?: ((operation: HSTOperation) => boolean) | undefined;
3063
+ }, OperationLogConfig | {
3064
+ maxOperations?: number | undefined;
3065
+ enableCrossTabSync?: boolean | undefined;
3066
+ autoSyncInterval?: number | undefined;
3067
+ enablePersistence?: boolean | undefined;
3068
+ persistenceKeyPrefix?: string | undefined;
3069
+ userId?: string | undefined;
3070
+ operationFilter?: ((operation: HSTOperation) => boolean) | undefined;
3071
+ }>;
3072
+ clientId: Ref<string, string>;
3073
+ undoRedoState: ComputedRef<UndoRedoState>;
3074
+ canUndo: ComputedRef<boolean>;
3075
+ canRedo: ComputedRef<boolean>;
3076
+ undoCount: ComputedRef<number>;
3077
+ redoCount: ComputedRef<number>;
3078
+ configure: (options: Partial<OperationLogConfig>) => void;
3079
+ addOperation: (operation: HSTOperationInput, source?: OperationSource) => string;
3080
+ startBatch: () => void;
3081
+ commitBatch: (description?: string) => string | null;
3082
+ cancelBatch: () => void;
3083
+ undo: (store: HSTNode) => boolean;
3084
+ redo: (store: HSTNode) => boolean;
3085
+ clear: () => void;
3086
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
3087
+ getSnapshot: () => OperationLogSnapshot;
3088
+ markIrreversible: (operationId: string, reason: string) => void;
3089
+ logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
3090
+ }, "operations" | "clientId" | "currentIndex" | "config">, Pick<{
3091
+ operations: Ref< {
3092
+ id: string;
3093
+ type: HSTOperationType_3;
3094
+ path: string;
3095
+ fieldname: string;
3096
+ beforeValue: any;
3097
+ afterValue: any;
3098
+ doctype: string;
3099
+ recordId?: string | undefined;
3100
+ timestamp: Date;
3101
+ source?: OperationSource | undefined;
3102
+ reversible: boolean;
3103
+ irreversibleReason?: string | undefined;
3104
+ transition?: string | undefined;
3105
+ currentState?: string | undefined;
3106
+ targetState?: string | undefined;
3107
+ actionName?: string | undefined;
3108
+ actionRecordIds?: string[] | undefined;
3109
+ actionResult?: "success" | "failure" | "pending" | undefined;
3110
+ actionError?: string | undefined;
3111
+ userId?: string | undefined;
3112
+ metadata?: Record<string, any> | undefined;
3113
+ parentOperationId?: string | undefined;
3114
+ childOperationIds?: string[] | undefined;
3115
+ }[], HSTOperation[] | {
3116
+ id: string;
3117
+ type: HSTOperationType_3;
3118
+ path: string;
3119
+ fieldname: string;
3120
+ beforeValue: any;
3121
+ afterValue: any;
3122
+ doctype: string;
3123
+ recordId?: string | undefined;
3124
+ timestamp: Date;
3125
+ source?: OperationSource | undefined;
3126
+ reversible: boolean;
3127
+ irreversibleReason?: string | undefined;
3128
+ transition?: string | undefined;
3129
+ currentState?: string | undefined;
3130
+ targetState?: string | undefined;
3131
+ actionName?: string | undefined;
3132
+ actionRecordIds?: string[] | undefined;
3133
+ actionResult?: "success" | "failure" | "pending" | undefined;
3134
+ actionError?: string | undefined;
3135
+ userId?: string | undefined;
3136
+ metadata?: Record<string, any> | undefined;
3137
+ parentOperationId?: string | undefined;
3138
+ childOperationIds?: string[] | undefined;
3139
+ }[]>;
3140
+ currentIndex: Ref<number, number>;
3141
+ config: Ref< {
3142
+ maxOperations?: number | undefined;
3143
+ enableCrossTabSync?: boolean | undefined;
3144
+ autoSyncInterval?: number | undefined;
3145
+ enablePersistence?: boolean | undefined;
3146
+ persistenceKeyPrefix?: string | undefined;
3147
+ userId?: string | undefined;
3148
+ operationFilter?: ((operation: HSTOperation) => boolean) | undefined;
3149
+ }, OperationLogConfig | {
3150
+ maxOperations?: number | undefined;
3151
+ enableCrossTabSync?: boolean | undefined;
3152
+ autoSyncInterval?: number | undefined;
3153
+ enablePersistence?: boolean | undefined;
3154
+ persistenceKeyPrefix?: string | undefined;
3155
+ userId?: string | undefined;
3156
+ operationFilter?: ((operation: HSTOperation) => boolean) | undefined;
3157
+ }>;
3158
+ clientId: Ref<string, string>;
3159
+ undoRedoState: ComputedRef<UndoRedoState>;
3160
+ canUndo: ComputedRef<boolean>;
3161
+ canRedo: ComputedRef<boolean>;
3162
+ undoCount: ComputedRef<number>;
3163
+ redoCount: ComputedRef<number>;
3164
+ configure: (options: Partial<OperationLogConfig>) => void;
3165
+ addOperation: (operation: HSTOperationInput, source?: OperationSource) => string;
3166
+ startBatch: () => void;
3167
+ commitBatch: (description?: string) => string | null;
3168
+ cancelBatch: () => void;
3169
+ undo: (store: HSTNode) => boolean;
3170
+ redo: (store: HSTNode) => boolean;
3171
+ clear: () => void;
3172
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
3173
+ getSnapshot: () => OperationLogSnapshot;
3174
+ markIrreversible: (operationId: string, reason: string) => void;
3175
+ logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
3176
+ }, "undoRedoState" | "canUndo" | "canRedo" | "undoCount" | "redoCount">, Pick<{
3177
+ operations: Ref< {
3178
+ id: string;
3179
+ type: HSTOperationType_3;
3180
+ path: string;
3181
+ fieldname: string;
3182
+ beforeValue: any;
3183
+ afterValue: any;
3184
+ doctype: string;
3185
+ recordId?: string | undefined;
3186
+ timestamp: Date;
3187
+ source?: OperationSource | undefined;
3188
+ reversible: boolean;
3189
+ irreversibleReason?: string | undefined;
3190
+ transition?: string | undefined;
3191
+ currentState?: string | undefined;
3192
+ targetState?: string | undefined;
3193
+ actionName?: string | undefined;
3194
+ actionRecordIds?: string[] | undefined;
3195
+ actionResult?: "success" | "failure" | "pending" | undefined;
3196
+ actionError?: string | undefined;
3197
+ userId?: string | undefined;
3198
+ metadata?: Record<string, any> | undefined;
3199
+ parentOperationId?: string | undefined;
3200
+ childOperationIds?: string[] | undefined;
3201
+ }[], HSTOperation[] | {
3202
+ id: string;
3203
+ type: HSTOperationType_3;
3204
+ path: string;
3205
+ fieldname: string;
3206
+ beforeValue: any;
3207
+ afterValue: any;
3208
+ doctype: string;
3209
+ recordId?: string | undefined;
3210
+ timestamp: Date;
3211
+ source?: OperationSource | undefined;
3212
+ reversible: boolean;
3213
+ irreversibleReason?: string | undefined;
3214
+ transition?: string | undefined;
3215
+ currentState?: string | undefined;
3216
+ targetState?: string | undefined;
3217
+ actionName?: string | undefined;
3218
+ actionRecordIds?: string[] | undefined;
3219
+ actionResult?: "success" | "failure" | "pending" | undefined;
3220
+ actionError?: string | undefined;
3221
+ userId?: string | undefined;
3222
+ metadata?: Record<string, any> | undefined;
3223
+ parentOperationId?: string | undefined;
3224
+ childOperationIds?: string[] | undefined;
3225
+ }[]>;
3226
+ currentIndex: Ref<number, number>;
3227
+ config: Ref< {
3228
+ maxOperations?: number | undefined;
3229
+ enableCrossTabSync?: boolean | undefined;
3230
+ autoSyncInterval?: number | undefined;
3231
+ enablePersistence?: boolean | undefined;
3232
+ persistenceKeyPrefix?: string | undefined;
3233
+ userId?: string | undefined;
3234
+ operationFilter?: ((operation: HSTOperation) => boolean) | undefined;
3235
+ }, OperationLogConfig | {
3236
+ maxOperations?: number | undefined;
3237
+ enableCrossTabSync?: boolean | undefined;
3238
+ autoSyncInterval?: number | undefined;
3239
+ enablePersistence?: boolean | undefined;
3240
+ persistenceKeyPrefix?: string | undefined;
3241
+ userId?: string | undefined;
3242
+ operationFilter?: ((operation: HSTOperation) => boolean) | undefined;
3243
+ }>;
3244
+ clientId: Ref<string, string>;
3245
+ undoRedoState: ComputedRef<UndoRedoState>;
3246
+ canUndo: ComputedRef<boolean>;
3247
+ canRedo: ComputedRef<boolean>;
3248
+ undoCount: ComputedRef<number>;
3249
+ redoCount: ComputedRef<number>;
3250
+ configure: (options: Partial<OperationLogConfig>) => void;
3251
+ addOperation: (operation: HSTOperationInput, source?: OperationSource) => string;
3252
+ startBatch: () => void;
3253
+ commitBatch: (description?: string) => string | null;
3254
+ cancelBatch: () => void;
3255
+ undo: (store: HSTNode) => boolean;
3256
+ redo: (store: HSTNode) => boolean;
3257
+ clear: () => void;
3258
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
3259
+ getSnapshot: () => OperationLogSnapshot;
3260
+ markIrreversible: (operationId: string, reason: string) => void;
3261
+ logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
3262
+ }, "undo" | "redo" | "configure" | "addOperation" | "startBatch" | "commitBatch" | "cancelBatch" | "clear" | "getOperationsFor" | "getSnapshot" | "markIrreversible" | "logAction">>;
3263
+
3264
+ /**
3265
+ * Unified Stonecrop composable - handles both general operations and HST reactive integration
3266
+ *
3267
+ * @param options - Configuration options for the composable
3268
+ * @returns Stonecrop instance and optional HST integration utilities
3269
+ * @public
3270
+ */
3271
+ export declare function useStonecrop(): BaseStonecropReturn | HSTStonecropReturn;
3272
+
3273
+ /**
3274
+ * Unified Stonecrop composable with HST integration for a specific doctype and record
3275
+ *
3276
+ * @param options - Configuration with doctype and optional recordId
3277
+ * @returns Stonecrop instance with full HST integration utilities
3278
+ * @public
3279
+ */
3280
+ export declare function useStonecrop(options: {
3281
+ registry?: Registry;
3282
+ doctype: DoctypeMeta;
3283
+ recordId?: string;
3284
+ }): HSTStonecropReturn;
3285
+
3286
+ /**
3287
+ * Keyboard shortcut handler for undo/redo
3288
+ * Automatically binds Ctrl+Z (undo) and Ctrl+Shift+Z/Ctrl+Y (redo) using VueUse
3289
+ *
3290
+ * @param hstStore - The HST store to operate on
3291
+ * @param enabled - Whether shortcuts are enabled (default: true)
3292
+ *
3293
+ * @example
3294
+ * ```typescript
3295
+ * import { onMounted } from 'vue'
3296
+ *
3297
+ * const stonecrop = useStonecrop({ doctype, recordId })
3298
+ * useUndoRedoShortcuts(stonecrop.hstStore)
3299
+ * ```
3300
+ *
3301
+ * @public
3302
+ */
3303
+ export declare function useUndoRedoShortcuts(hstStore: HSTNode, enabled?: boolean): void;
3304
+
3305
+ /**
3306
+ * Batch operation helper
3307
+ * Wraps a function execution in a batch operation
3308
+ *
3309
+ * @param fn - The function to execute within a batch
3310
+ * @param description - Optional description for the batch
3311
+ * @returns The batch operation ID
3312
+ *
3313
+ * @example
3314
+ * ```typescript
3315
+ * const { withBatch } = useOperationLog()
3316
+ *
3317
+ * const batchId = await withBatch(() => {
3318
+ * hstStore.set('task.123.title', 'New Title')
3319
+ * hstStore.set('task.123.status', 'active')
3320
+ * hstStore.set('task.123.priority', 'high')
3321
+ * }, 'Update task details')
3322
+ * ```
3323
+ *
1928
3324
  * @public
1929
3325
  */
1930
- export declare function useStonecrop(registry?: Registry): StonecropReturn;
3326
+ export declare function withBatch<T>(fn: () => T | Promise<T>, description?: string): Promise<string | null>;
1931
3327
 
1932
3328
  export { }