@case-framework/survey-core 0.1.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/build/editor.d.mts +245 -0
- package/build/editor.d.mts.map +1 -0
- package/build/editor.mjs +603 -0
- package/build/editor.mjs.map +1 -0
- package/build/index.d.mts +597 -0
- package/build/index.d.mts.map +1 -0
- package/build/index.mjs +1586 -0
- package/build/index.mjs.map +1 -0
- package/build/package.json/package.json +49 -0
- package/build/survey-C3ZHI-5z.mjs +931 -0
- package/build/survey-C3ZHI-5z.mjs.map +1 -0
- package/build/survey-TUPUXiXl.d.mts +614 -0
- package/build/survey-TUPUXiXl.d.mts.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { S as RawSurveyItem, a as JsonComponentContent, i as RawSurvey, n as ItemTypeRegistry, t as Survey, u as SurveyItemTranslations, w as SurveyItemCore } from "./survey-TUPUXiXl.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/editor/types.d.ts
|
|
4
|
+
interface Target {
|
|
5
|
+
parentId: string;
|
|
6
|
+
index?: number;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/editor/item-copy-paste.d.ts
|
|
10
|
+
type SerializedTranslations = {
|
|
11
|
+
[locale: string]: JsonComponentContent;
|
|
12
|
+
};
|
|
13
|
+
interface SurveyItemClipboardData {
|
|
14
|
+
type: 'survey-item';
|
|
15
|
+
version: string;
|
|
16
|
+
items: Array<{
|
|
17
|
+
itemId: string;
|
|
18
|
+
itemData: RawSurveyItem;
|
|
19
|
+
}>;
|
|
20
|
+
translations: {
|
|
21
|
+
[itemId: string]: SerializedTranslations;
|
|
22
|
+
};
|
|
23
|
+
rootItemId: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}
|
|
26
|
+
declare class ItemCopyPaste {
|
|
27
|
+
private survey;
|
|
28
|
+
constructor(survey: Survey);
|
|
29
|
+
/**
|
|
30
|
+
* Copy a survey item and all its data to clipboard format
|
|
31
|
+
* When copying a group, automatically includes all items in the subtree
|
|
32
|
+
* @param itemId - The id of the item to copy
|
|
33
|
+
* @returns Clipboard data that can be serialized to JSON for clipboard
|
|
34
|
+
*/
|
|
35
|
+
copyItem(itemId: string): SurveyItemClipboardData;
|
|
36
|
+
/**
|
|
37
|
+
* Collect all items that should be copied, including subtree for groups
|
|
38
|
+
* @param itemId - The root item id
|
|
39
|
+
* @returns Array of item keys to copy
|
|
40
|
+
*/
|
|
41
|
+
private collectItemsForCopy;
|
|
42
|
+
/**
|
|
43
|
+
* Add an item to its parent group.
|
|
44
|
+
* Ensures key uniqueness among siblings.
|
|
45
|
+
* @param target - Target location information
|
|
46
|
+
* @param item - The item to add (may have key adjusted for uniqueness)
|
|
47
|
+
*/
|
|
48
|
+
private addItemToParentGroup;
|
|
49
|
+
/**
|
|
50
|
+
* Paste a survey item from clipboard data to a target location
|
|
51
|
+
* Handles multiple items and subtrees from the clipboard data
|
|
52
|
+
* @param clipboardData - The clipboard data containing the item(s) to paste
|
|
53
|
+
* @param target - Target location where to paste the item
|
|
54
|
+
* @returns The id of the pasted root item
|
|
55
|
+
*/
|
|
56
|
+
pasteItem(clipboardData: SurveyItemClipboardData, target: Target): string;
|
|
57
|
+
/**
|
|
58
|
+
* Update all item ids in the raw item data recursively
|
|
59
|
+
*/
|
|
60
|
+
private updateItemIdsInData;
|
|
61
|
+
/**
|
|
62
|
+
* Update expressions in item data that reference the old ids
|
|
63
|
+
*/
|
|
64
|
+
private updateExpressionsInItemData;
|
|
65
|
+
/**
|
|
66
|
+
* Update references in a single expression (recursive)
|
|
67
|
+
*/
|
|
68
|
+
private updateExpressionReferences;
|
|
69
|
+
/**
|
|
70
|
+
* Update translation keys for the pasted item
|
|
71
|
+
*/
|
|
72
|
+
private updateTranslations;
|
|
73
|
+
/**
|
|
74
|
+
* Validate clipboard data format
|
|
75
|
+
*/
|
|
76
|
+
static isValidClipboardData(data: unknown): data is SurveyItemClipboardData;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/editor/undo-redo.d.ts
|
|
80
|
+
interface UndoRedoConfig {
|
|
81
|
+
maxTotalMemoryMB: number;
|
|
82
|
+
minHistorySize: number;
|
|
83
|
+
maxHistorySize: number;
|
|
84
|
+
}
|
|
85
|
+
declare const CommitSource: {
|
|
86
|
+
readonly USER: "user";
|
|
87
|
+
readonly SYSTEM: "system";
|
|
88
|
+
};
|
|
89
|
+
type CommitSource = typeof CommitSource[keyof typeof CommitSource];
|
|
90
|
+
interface CommitMeta {
|
|
91
|
+
label: string;
|
|
92
|
+
source?: CommitSource;
|
|
93
|
+
}
|
|
94
|
+
interface HistoryEntry {
|
|
95
|
+
survey: RawSurvey;
|
|
96
|
+
timestamp: number;
|
|
97
|
+
meta: CommitMeta;
|
|
98
|
+
memorySize: number;
|
|
99
|
+
}
|
|
100
|
+
declare class SurveyEditorUndoRedo {
|
|
101
|
+
private history;
|
|
102
|
+
private currentIndex;
|
|
103
|
+
private _config;
|
|
104
|
+
constructor(initialSurvey: RawSurvey, config?: Partial<UndoRedoConfig>, meta?: CommitMeta);
|
|
105
|
+
private saveSnapshot;
|
|
106
|
+
private cleanupHistory;
|
|
107
|
+
private getTotalMemoryUsage;
|
|
108
|
+
commit(survey: RawSurvey, meta: CommitMeta): void;
|
|
109
|
+
getCurrentState(): RawSurvey;
|
|
110
|
+
undo(): RawSurvey | null;
|
|
111
|
+
redo(): RawSurvey | null;
|
|
112
|
+
canUndo(): boolean;
|
|
113
|
+
canRedo(): boolean;
|
|
114
|
+
getUndoMeta(): CommitMeta | null;
|
|
115
|
+
getRedoMeta(): CommitMeta | null;
|
|
116
|
+
getMemoryUsage(): {
|
|
117
|
+
totalMB: number;
|
|
118
|
+
entries: number;
|
|
119
|
+
};
|
|
120
|
+
getConfig(): UndoRedoConfig;
|
|
121
|
+
/**
|
|
122
|
+
* Get the full history list with metadata
|
|
123
|
+
*/
|
|
124
|
+
getHistory(): Array<{
|
|
125
|
+
index: number;
|
|
126
|
+
meta: CommitMeta;
|
|
127
|
+
timestamp: number;
|
|
128
|
+
memorySize: number;
|
|
129
|
+
isCurrent: boolean;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* Get the current index in the history
|
|
133
|
+
*/
|
|
134
|
+
getCurrentIndex(): number;
|
|
135
|
+
/**
|
|
136
|
+
* Get the total number of history entries
|
|
137
|
+
*/
|
|
138
|
+
getHistoryLength(): number;
|
|
139
|
+
/**
|
|
140
|
+
* Jump to a specific index in the history (can go forward or backward)
|
|
141
|
+
* @param targetIndex The index to jump to
|
|
142
|
+
* @returns The survey state at the target index, or null if invalid
|
|
143
|
+
*/
|
|
144
|
+
jumpToIndex(targetIndex: number): RawSurvey | null;
|
|
145
|
+
/**
|
|
146
|
+
* Check if we can jump to a specific index
|
|
147
|
+
*/
|
|
148
|
+
canJumpToIndex(targetIndex: number): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Serialize the undo/redo state to JSON
|
|
151
|
+
* @returns A JSON-serializable object containing the complete state
|
|
152
|
+
*/
|
|
153
|
+
serialize(): {
|
|
154
|
+
history: Array<HistoryEntry>;
|
|
155
|
+
currentIndex: number;
|
|
156
|
+
config: UndoRedoConfig;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Create a new SurveyEditorUndoRedo instance from JSON data
|
|
160
|
+
* @param jsonData The serialized undo/redo state
|
|
161
|
+
* @returns A new SurveyEditorUndoRedo instance with the restored state
|
|
162
|
+
*/
|
|
163
|
+
static deserialize(jsonData: {
|
|
164
|
+
history: Array<{
|
|
165
|
+
survey: RawSurvey;
|
|
166
|
+
timestamp: number;
|
|
167
|
+
meta: CommitMeta;
|
|
168
|
+
memorySize: number;
|
|
169
|
+
}>;
|
|
170
|
+
currentIndex: number;
|
|
171
|
+
config: UndoRedoConfig;
|
|
172
|
+
}): SurveyEditorUndoRedo;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/editor/survey-editor.d.ts
|
|
176
|
+
interface SerializedSurveyEditor {
|
|
177
|
+
version: string;
|
|
178
|
+
survey: RawSurvey;
|
|
179
|
+
undoRedo: ReturnType<SurveyEditorUndoRedo['serialize']>;
|
|
180
|
+
hasUncommittedChanges: boolean;
|
|
181
|
+
}
|
|
182
|
+
interface SurveyEditorConfig extends Partial<UndoRedoConfig> {
|
|
183
|
+
/** Plugin registry for deserializing survey state during undo/redo. Required when survey contains custom item types. */
|
|
184
|
+
pluginRegistry?: ItemTypeRegistry;
|
|
185
|
+
}
|
|
186
|
+
declare class SurveyEditor {
|
|
187
|
+
private _survey;
|
|
188
|
+
private _undoRedo;
|
|
189
|
+
private _hasUncommittedChanges;
|
|
190
|
+
private _pluginRegistry?;
|
|
191
|
+
constructor(survey: Survey, config?: SurveyEditorConfig, meta?: CommitMeta);
|
|
192
|
+
get survey(): Survey;
|
|
193
|
+
get hasUncommittedChanges(): boolean;
|
|
194
|
+
get undoRedo(): SurveyEditorUndoRedo;
|
|
195
|
+
commit(meta: CommitMeta): void;
|
|
196
|
+
commitIfNeeded(): void;
|
|
197
|
+
undo(): boolean;
|
|
198
|
+
redo(): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Jump to a specific index in the history (can go forward or backward)
|
|
201
|
+
*/
|
|
202
|
+
jumpToIndex(targetIndex: number): boolean;
|
|
203
|
+
canUndo(): boolean;
|
|
204
|
+
canRedo(): boolean;
|
|
205
|
+
getUndoMeta(): CommitMeta | null;
|
|
206
|
+
getRedoMeta(): CommitMeta | null;
|
|
207
|
+
getMemoryUsage(): {
|
|
208
|
+
totalMB: number;
|
|
209
|
+
entries: number;
|
|
210
|
+
};
|
|
211
|
+
getUndoRedoConfig(): UndoRedoConfig;
|
|
212
|
+
/**
|
|
213
|
+
* Serialize the SurveyEditor state to JSON
|
|
214
|
+
* @returns A JSON-serializable object containing the complete editor state
|
|
215
|
+
*/
|
|
216
|
+
toJson(): SerializedSurveyEditor;
|
|
217
|
+
/**
|
|
218
|
+
* Create a new SurveyEditor instance from JSON data
|
|
219
|
+
* @param jsonData The serialized editor state
|
|
220
|
+
* @param pluginRegistry Optional plugin registry for deserializing survey state (required when survey contains custom item types)
|
|
221
|
+
* @returns A new SurveyEditor instance with the restored state
|
|
222
|
+
*/
|
|
223
|
+
static fromJson(jsonData: SerializedSurveyEditor, pluginRegistry?: ItemTypeRegistry): SurveyEditor;
|
|
224
|
+
private markAsModified;
|
|
225
|
+
addItem(target: Target, item: SurveyItemCore, content?: SurveyItemTranslations): void;
|
|
226
|
+
removeItem(itemId: string, nested?: boolean): boolean;
|
|
227
|
+
moveItem(itemId: string, newTarget: Target): boolean;
|
|
228
|
+
updateItemTranslations(itemId: string, updatedContent?: SurveyItemTranslations): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Copy a survey item and all its data to clipboard format
|
|
231
|
+
* @param itemKey - The full key of the item to copy
|
|
232
|
+
* @returns Clipboard data that can be serialized to JSON for clipboard
|
|
233
|
+
*/
|
|
234
|
+
copyItem(itemKey: string): SurveyItemClipboardData;
|
|
235
|
+
/**
|
|
236
|
+
* Paste a survey item from clipboard data to a target location
|
|
237
|
+
* @param clipboardData - The clipboard data containing the item to paste
|
|
238
|
+
* @param target - Target location where to paste the item
|
|
239
|
+
* @returns The full key of the pasted item
|
|
240
|
+
*/
|
|
241
|
+
pasteItem(clipboardData: SurveyItemClipboardData, target: Target): string;
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
export { CommitMeta, CommitSource, ItemCopyPaste, SerializedSurveyEditor, SerializedTranslations, SurveyEditor, SurveyEditorConfig, SurveyEditorUndoRedo, SurveyItemClipboardData, Target, UndoRedoConfig };
|
|
245
|
+
//# sourceMappingURL=editor.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.d.mts","names":[],"sources":["../src/editor/types.ts","../src/editor/item-copy-paste.ts","../src/editor/undo-redo.ts","../src/editor/survey-editor.ts"],"mappings":";;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