@stonecrop/stonecrop 0.10.16 → 0.11.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.
- package/README.md +72 -29
- package/dist/composable.js +1 -0
- package/dist/composables/lazy-link.js +125 -0
- package/dist/composables/stonecrop.js +123 -68
- package/dist/composables/use-lazy-link-state.js +125 -0
- package/dist/composables/use-stonecrop.js +476 -0
- package/dist/doctype.js +10 -2
- package/dist/field-triggers.js +15 -3
- package/dist/index.js +4 -3
- package/dist/operation-log-DB-dGNT9.js +593 -0
- package/dist/operation-log-DB-dGNT9.js.map +1 -0
- package/dist/registry.js +261 -101
- package/dist/schema-validator.js +105 -1
- package/dist/src/composable.d.ts +11 -0
- package/dist/src/composable.d.ts.map +1 -0
- package/dist/src/composable.js +477 -0
- package/dist/src/composables/lazy-link.d.ts +25 -0
- package/dist/src/composables/lazy-link.d.ts.map +1 -0
- package/dist/src/composables/operation-log.d.ts +5 -5
- package/dist/src/composables/operation-log.d.ts.map +1 -1
- package/dist/src/composables/operation-log.js +224 -0
- package/dist/src/composables/stonecrop.d.ts +11 -1
- package/dist/src/composables/stonecrop.d.ts.map +1 -1
- package/dist/src/composables/stonecrop.js +574 -0
- package/dist/src/composables/use-lazy-link-state.d.ts +25 -0
- package/dist/src/composables/use-lazy-link-state.d.ts.map +1 -0
- package/dist/src/composables/use-stonecrop.d.ts +93 -0
- package/dist/src/composables/use-stonecrop.d.ts.map +1 -0
- package/dist/src/composables/useNestedSchema.d.ts +110 -0
- package/dist/src/composables/useNestedSchema.d.ts.map +1 -0
- package/dist/src/composables/useNestedSchema.js +155 -0
- package/dist/src/doctype.d.ts +9 -1
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/src/doctype.js +234 -0
- package/dist/src/exceptions.js +16 -0
- package/dist/src/field-triggers.d.ts +6 -0
- package/dist/src/field-triggers.d.ts.map +1 -1
- package/dist/src/field-triggers.js +567 -0
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +23 -0
- package/dist/src/plugins/index.js +96 -0
- package/dist/src/registry.d.ts +102 -23
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +246 -0
- package/dist/src/schema-validator.d.ts +8 -1
- package/dist/src/schema-validator.d.ts.map +1 -1
- package/dist/src/schema-validator.js +315 -0
- package/dist/src/stonecrop.d.ts +73 -28
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stonecrop.js +339 -0
- package/dist/src/stores/data.d.ts +11 -0
- package/dist/src/stores/data.d.ts.map +1 -0
- package/dist/src/stores/hst.d.ts +5 -75
- package/dist/src/stores/hst.d.ts.map +1 -1
- package/dist/src/stores/hst.js +495 -0
- package/dist/src/stores/index.js +12 -0
- package/dist/src/stores/operation-log.d.ts +14 -14
- package/dist/src/stores/operation-log.d.ts.map +1 -1
- package/dist/src/stores/operation-log.js +568 -0
- package/dist/src/stores/xstate.d.ts +31 -0
- package/dist/src/stores/xstate.d.ts.map +1 -0
- package/dist/src/tsdoc-metadata.json +11 -0
- package/dist/src/types/composable.d.ts +50 -12
- package/dist/src/types/composable.d.ts.map +1 -1
- package/dist/src/types/doctype.d.ts +6 -7
- package/dist/src/types/doctype.d.ts.map +1 -1
- package/dist/src/types/field-triggers.d.ts +1 -1
- package/dist/src/types/field-triggers.d.ts.map +1 -1
- package/dist/src/types/field-triggers.js +4 -0
- package/dist/src/types/hst.d.ts +70 -0
- package/dist/src/types/hst.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +1 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +4 -0
- package/dist/src/types/operation-log.d.ts +4 -4
- package/dist/src/types/operation-log.d.ts.map +1 -1
- package/dist/src/types/operation-log.js +0 -0
- package/dist/src/types/registry.js +0 -0
- package/dist/src/types/schema-validator.d.ts +2 -0
- package/dist/src/types/schema-validator.d.ts.map +1 -1
- package/dist/src/utils.d.ts +24 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/stonecrop.d.ts +317 -99
- package/dist/stonecrop.js +2191 -1897
- package/dist/stonecrop.js.map +1 -1
- package/dist/stonecrop.umd.cjs +6 -0
- package/dist/stonecrop.umd.cjs.map +1 -0
- package/dist/stores/data.js +7 -0
- package/dist/stores/hst.js +27 -25
- package/dist/stores/operation-log.js +59 -47
- package/dist/stores/xstate.js +29 -0
- package/dist/tests/setup.d.ts +5 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +15 -0
- package/dist/types/hst.js +0 -0
- package/dist/types/index.js +1 -0
- package/dist/utils.js +46 -0
- package/package.json +5 -5
- package/src/composables/lazy-link.ts +146 -0
- package/src/composables/operation-log.ts +1 -1
- package/src/composables/stonecrop.ts +142 -73
- package/src/doctype.ts +13 -4
- package/src/field-triggers.ts +18 -4
- package/src/index.ts +4 -2
- package/src/registry.ts +289 -111
- package/src/schema-validator.ts +120 -1
- package/src/stonecrop.ts +230 -106
- package/src/stores/hst.ts +29 -104
- package/src/stores/operation-log.ts +64 -50
- package/src/types/composable.ts +55 -12
- package/src/types/doctype.ts +6 -7
- package/src/types/field-triggers.ts +1 -1
- package/src/types/hst.ts +77 -0
- package/src/types/index.ts +1 -0
- package/src/types/operation-log.ts +4 -4
- package/src/types/schema-validator.ts +2 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { useMagicKeys, whenever } from '@vueuse/core';
|
|
2
|
+
import { storeToRefs } from 'pinia';
|
|
3
|
+
import { getCurrentInstance, inject } from 'vue';
|
|
4
|
+
import { useOperationLogStore } from '../stores/operation-log';
|
|
5
|
+
/**
|
|
6
|
+
* Composable for operation log management
|
|
7
|
+
* Provides easy access to undo/redo functionality and operation history
|
|
8
|
+
*
|
|
9
|
+
* @param config - Optional configuration for the operation log
|
|
10
|
+
* @returns Operation log interface
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const { undo, redo, canUndo, canRedo, operations, configure } = useOperationLog()
|
|
15
|
+
*
|
|
16
|
+
* // Configure the log
|
|
17
|
+
* configure({
|
|
18
|
+
* maxOperations: 50,
|
|
19
|
+
* enableCrossTabSync: true,
|
|
20
|
+
* enablePersistence: true
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* // Undo/redo
|
|
24
|
+
* await undo(hstStore)
|
|
25
|
+
* await redo(hstStore)
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export function useOperationLog(config) {
|
|
31
|
+
// inject() is only valid inside a component setup() context. When this
|
|
32
|
+
// composable is called outside one (e.g. directly in test bodies or plain
|
|
33
|
+
// scripts) skip the injection entirely and fall back to the Pinia store.
|
|
34
|
+
const injectedStore = getCurrentInstance()
|
|
35
|
+
? inject('$operationLogStore', undefined)
|
|
36
|
+
: undefined;
|
|
37
|
+
const store = injectedStore || useOperationLogStore();
|
|
38
|
+
// Apply configuration if provided
|
|
39
|
+
if (config) {
|
|
40
|
+
store.configure(config);
|
|
41
|
+
}
|
|
42
|
+
// Extract reactive state
|
|
43
|
+
const { operations, currentIndex, undoRedoState, canUndo, canRedo, undoCount, redoCount } = storeToRefs(store);
|
|
44
|
+
/**
|
|
45
|
+
* Undo the last operation
|
|
46
|
+
*/
|
|
47
|
+
function undo(hstStore) {
|
|
48
|
+
return store.undo(hstStore);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Redo the next operation
|
|
52
|
+
*/
|
|
53
|
+
function redo(hstStore) {
|
|
54
|
+
return store.redo(hstStore);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Start a batch operation
|
|
58
|
+
*/
|
|
59
|
+
function startBatch() {
|
|
60
|
+
store.startBatch();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Commit the current batch
|
|
64
|
+
*/
|
|
65
|
+
function commitBatch(description) {
|
|
66
|
+
return store.commitBatch(description);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Cancel the current batch
|
|
70
|
+
*/
|
|
71
|
+
function cancelBatch() {
|
|
72
|
+
store.cancelBatch();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Clear all operations
|
|
76
|
+
*/
|
|
77
|
+
function clear() {
|
|
78
|
+
store.clear();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get operations for a specific doctype/record
|
|
82
|
+
*/
|
|
83
|
+
function getOperationsFor(doctype, recordId) {
|
|
84
|
+
return store.getOperationsFor(doctype, recordId);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get a snapshot of the operation log
|
|
88
|
+
*/
|
|
89
|
+
function getSnapshot() {
|
|
90
|
+
return store.getSnapshot();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Mark an operation as irreversible
|
|
94
|
+
* @param operationId - The ID of the operation to mark
|
|
95
|
+
* @param reason - The reason why the operation is irreversible
|
|
96
|
+
*/
|
|
97
|
+
function markIrreversible(operationId, reason) {
|
|
98
|
+
store.markIrreversible(operationId, reason);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Log an action execution (stateless actions like print, email, etc.)
|
|
102
|
+
* @param doctype - The doctype the action was executed on
|
|
103
|
+
* @param actionName - The name of the action that was executed
|
|
104
|
+
* @param recordIds - Optional array of record IDs the action was executed on
|
|
105
|
+
* @param result - The result of the action execution
|
|
106
|
+
* @param error - Optional error message if action failed
|
|
107
|
+
* @returns The operation ID
|
|
108
|
+
*/
|
|
109
|
+
function logAction(doctype, actionName, recordIds, result = 'success', error) {
|
|
110
|
+
return store.logAction(doctype, actionName, recordIds, result, error);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Update configuration
|
|
114
|
+
* @param options - Configuration options to update
|
|
115
|
+
*/
|
|
116
|
+
function configure(options) {
|
|
117
|
+
store.configure(options);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
// State
|
|
121
|
+
operations,
|
|
122
|
+
currentIndex,
|
|
123
|
+
undoRedoState,
|
|
124
|
+
canUndo,
|
|
125
|
+
canRedo,
|
|
126
|
+
undoCount,
|
|
127
|
+
redoCount,
|
|
128
|
+
// Methods
|
|
129
|
+
undo,
|
|
130
|
+
redo,
|
|
131
|
+
startBatch,
|
|
132
|
+
commitBatch,
|
|
133
|
+
cancelBatch,
|
|
134
|
+
clear,
|
|
135
|
+
getOperationsFor,
|
|
136
|
+
getSnapshot,
|
|
137
|
+
markIrreversible,
|
|
138
|
+
logAction,
|
|
139
|
+
configure,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Keyboard shortcut handler for undo/redo
|
|
144
|
+
* Automatically binds Ctrl+Z (undo) and Ctrl+Shift+Z/Ctrl+Y (redo) using VueUse
|
|
145
|
+
*
|
|
146
|
+
* @param hstStore - The HST store to operate on
|
|
147
|
+
* @param enabled - Whether shortcuts are enabled (default: true)
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* import { onMounted } from 'vue'
|
|
152
|
+
*
|
|
153
|
+
* const stonecrop = useStonecrop({ doctype, recordId })
|
|
154
|
+
* useUndoRedoShortcuts(stonecrop.hstStore)
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
159
|
+
export function useUndoRedoShortcuts(hstStore, enabled = true) {
|
|
160
|
+
if (!enabled)
|
|
161
|
+
return;
|
|
162
|
+
const { undo, redo, canUndo, canRedo } = useOperationLog();
|
|
163
|
+
const keys = useMagicKeys();
|
|
164
|
+
// Undo shortcuts: Ctrl+Z or Cmd+Z (Mac)
|
|
165
|
+
whenever(keys['Ctrl+Z'], () => {
|
|
166
|
+
if (canUndo.value) {
|
|
167
|
+
undo(hstStore);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
whenever(keys['Meta+Z'], () => {
|
|
171
|
+
if (canUndo.value) {
|
|
172
|
+
undo(hstStore);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
// Redo shortcuts: Ctrl+Shift+Z, Cmd+Shift+Z (Mac), or Ctrl+Y
|
|
176
|
+
whenever(keys['Ctrl+Shift+Z'], () => {
|
|
177
|
+
if (canRedo.value) {
|
|
178
|
+
redo(hstStore);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
whenever(keys['Meta+Shift+Z'], () => {
|
|
182
|
+
if (canRedo.value) {
|
|
183
|
+
redo(hstStore);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
whenever(keys['Ctrl+Y'], () => {
|
|
187
|
+
if (canRedo.value) {
|
|
188
|
+
redo(hstStore);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Batch operation helper
|
|
194
|
+
* Wraps a function execution in a batch operation
|
|
195
|
+
*
|
|
196
|
+
* @param fn - The function to execute within a batch
|
|
197
|
+
* @param description - Optional description for the batch
|
|
198
|
+
* @returns The batch operation ID
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const { withBatch } = useOperationLog()
|
|
203
|
+
*
|
|
204
|
+
* const batchId = await withBatch(() => {
|
|
205
|
+
* hstStore.set('task.123.title', 'New Title')
|
|
206
|
+
* hstStore.set('task.123.status', 'active')
|
|
207
|
+
* hstStore.set('task.123.priority', 'high')
|
|
208
|
+
* }, 'Update task details')
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
export async function withBatch(fn, description) {
|
|
214
|
+
const { startBatch, commitBatch, cancelBatch } = useOperationLog();
|
|
215
|
+
startBatch();
|
|
216
|
+
try {
|
|
217
|
+
await fn();
|
|
218
|
+
return commitBatch(description);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
cancelBatch();
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -10,7 +10,17 @@ import type { BaseStonecropReturn, HSTStonecropReturn } from '../types/composabl
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function useStonecrop(): BaseStonecropReturn | HSTStonecropReturn;
|
|
12
12
|
/**
|
|
13
|
-
* Unified Stonecrop composable with HST integration for a specific doctype and record
|
|
13
|
+
* Unified Stonecrop composable with HST integration for a specific doctype and record.
|
|
14
|
+
*
|
|
15
|
+
* When a `Doctype` instance is passed, all synchronous initialisation (`hstStore`,
|
|
16
|
+
* `resolvedSchema`, `formData`, `handleHSTChange`, operation-log wiring) is performed
|
|
17
|
+
* during `setup()` — before the first render and without awaiting any lifecycle hook.
|
|
18
|
+
* Callers can read `hstStore.value`, `resolvedSchema.value`, and `formData.value`
|
|
19
|
+
* immediately after calling this composable; no `nextTick`, `flushPromises`, or
|
|
20
|
+
* `setTimeout` is required.
|
|
21
|
+
*
|
|
22
|
+
* The only remaining async work in `onMounted` is fetching an existing record from the
|
|
23
|
+
* server when `recordId` is not `'new'`, and lazy-loading a doctype by slug string.
|
|
14
24
|
*
|
|
15
25
|
* @param options - Configuration with doctype (string slug or Doctype instance) and optional recordId
|
|
16
26
|
* @returns Stonecrop instance with full HST integration utilities
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../../src/composables/stonecrop.ts"],"names":[],"mappings":"AAIA,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,QAAQ,MAAM,aAAa,CAAA;AAGlC,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAkC,MAAM,qBAAqB,CAAA;AAIlH;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,mBAAmB,GAAG,kBAAkB,CAAA;AACxE
|
|
1
|
+
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../../src/composables/stonecrop.ts"],"names":[],"mappings":"AAIA,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,QAAQ,MAAM,aAAa,CAAA;AAGlC,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAkC,MAAM,qBAAqB,CAAA;AAIlH;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,mBAAmB,GAAG,kBAAkB,CAAA;AACxE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE;IACrC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,OAAO,EAAE,OAAO,GAAG,MAAM,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,kBAAkB,CAAA"}
|