@case-framework/survey-core 0.4.1 → 0.5.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.
@@ -0,0 +1,12 @@
1
+ //#region src/editor/item-colors.d.ts
2
+ /**
3
+ * Editor-only item-color swatches persisted in `metadata.editorItemColor`.
4
+ *
5
+ * This is shared survey-editor configuration: hosts may render the editor
6
+ * without enabling the assistant, while assistant proposals must validate
7
+ * against the same values.
8
+ */
9
+ declare const SURVEY_EDITOR_ITEM_COLORS: readonly ["#404040", "#b91c1c", "#c2410c", "#a16207", "#4d7c0f", "#047857", "#0369a1", "#4338ca", "#7e22ce", "#86198f", "#be123c"];
10
+ //#endregion
11
+ export { SURVEY_EDITOR_ITEM_COLORS };
12
+ //# sourceMappingURL=colors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.mts","names":[],"sources":["../../src/editor/item-colors.ts"],"mappings":";;AAOA;;;;;;cAAa,yBAAA"}
@@ -0,0 +1,25 @@
1
+ //#region src/editor/item-colors.ts
2
+ /**
3
+ * Editor-only item-color swatches persisted in `metadata.editorItemColor`.
4
+ *
5
+ * This is shared survey-editor configuration: hosts may render the editor
6
+ * without enabling the assistant, while assistant proposals must validate
7
+ * against the same values.
8
+ */
9
+ const SURVEY_EDITOR_ITEM_COLORS = [
10
+ "#404040",
11
+ "#b91c1c",
12
+ "#c2410c",
13
+ "#a16207",
14
+ "#4d7c0f",
15
+ "#047857",
16
+ "#0369a1",
17
+ "#4338ca",
18
+ "#7e22ce",
19
+ "#86198f",
20
+ "#be123c"
21
+ ];
22
+ //#endregion
23
+ export { SURVEY_EDITOR_ITEM_COLORS };
24
+
25
+ //# sourceMappingURL=colors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.mjs","names":[],"sources":["../../src/editor/item-colors.ts"],"sourcesContent":["/**\n * Editor-only item-color swatches persisted in `metadata.editorItemColor`.\n *\n * This is shared survey-editor configuration: hosts may render the editor\n * without enabling the assistant, while assistant proposals must validate\n * against the same values.\n */\nexport const SURVEY_EDITOR_ITEM_COLORS = [\n \"#404040\",\n \"#b91c1c\",\n \"#c2410c\",\n \"#a16207\",\n \"#4d7c0f\",\n \"#047857\",\n \"#0369a1\",\n \"#4338ca\",\n \"#7e22ce\",\n \"#86198f\",\n \"#be123c\",\n] as const;\n"],"mappings":";;;;;;;;AAOA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -1,83 +1,5 @@
1
- import { D as SurveyCardContent, E as NavigationContent, Gt as SurveyItemCore, Jt as RawSurveyItem, M as Content, S as RawSurveyAsset, k as SurveyItemTranslations, m as ItemTypeRegistry, t as Survey, vt as TemplateValueDefinition, w as JsonComponentContent, x as RawSurvey } from "./survey-BV8YHc3J.mjs";
1
+ import { D as SurveyCardContent, E as NavigationContent, Gt as SurveyItemCore, Jt as RawSurveyItem, M as Content, S as RawSurveyAsset, k as SurveyItemTranslations, m as ItemTypeRegistry, t as Survey, vt as TemplateValueDefinition, w as JsonComponentContent, x as RawSurvey } from "./survey-DZ3RHkd2.mjs";
2
2
 
3
- //#region src/editor/ai-context.d.ts
4
- type SurveyAIContextScope = "tiny" | "focused" | "full";
5
- type SurveyAIContextPurpose = "generic" | "key-suggestion" | "label-suggestion" | "item-generation" | "translation" | "condition-management";
6
- interface SurveyAIOutlineNode {
7
- itemId: string;
8
- parentId?: string;
9
- depth: number;
10
- itemType: string;
11
- key: string;
12
- fullKey: string;
13
- itemLabel?: string;
14
- childCount: number;
15
- }
16
- interface SurveyAIFocus {
17
- focusItemId: string;
18
- parentItemId?: string;
19
- pathItemIds: string[];
20
- siblingItemIds: string[];
21
- childItemIds: string[];
22
- }
23
- interface SurveyAITranslationSnippet {
24
- locale: string;
25
- contentKey: string;
26
- text: string;
27
- }
28
- interface SurveyAIItemContextNode {
29
- itemId: string;
30
- itemType: string;
31
- itemKey: string;
32
- fullKey: string;
33
- itemLabel?: string;
34
- siblingKeys: string[];
35
- translations: SurveyAITranslationSnippet[];
36
- descendants: SurveyAIItemContextNode[];
37
- }
38
- interface SurveyAIKeyIndexEntry {
39
- itemId: string;
40
- itemType: string;
41
- key: string;
42
- fullKey: string;
43
- itemLabel?: string;
44
- path: string[];
45
- }
46
- interface SurveyAIContextIndexes {
47
- keyIndex: SurveyAIKeyIndexEntry[];
48
- responseSlots?: string[];
49
- }
50
- interface SurveyAIContextPack {
51
- purpose: SurveyAIContextPurpose;
52
- scope: SurveyAIContextScope;
53
- surveyKey?: string;
54
- locales: string[];
55
- itemCount: number;
56
- outline: SurveyAIOutlineNode[];
57
- focus?: SurveyAIFocus;
58
- focusItem?: SurveyAIItemContextNode;
59
- indexes?: SurveyAIContextIndexes;
60
- flags: {
61
- outlineTruncated: boolean;
62
- rawSurveyIncluded: boolean;
63
- focusItemTreeTruncated: boolean;
64
- };
65
- rawSurvey?: RawSurvey;
66
- }
67
- interface BuildSurveyAIContextPackOptions {
68
- purpose?: SurveyAIContextPurpose;
69
- scope?: SurveyAIContextScope;
70
- focusItemId?: string;
71
- includeRawSurvey?: boolean;
72
- outlineLimit?: number;
73
- includeIndexes?: boolean;
74
- includeFocusItemTree?: boolean;
75
- focusItemTreeLimit?: number;
76
- translationSnippetsPerItemLimit?: number;
77
- translationSnippetTextLimit?: number;
78
- }
79
- declare function buildSurveyAIContextPack(survey: Survey, options?: BuildSurveyAIContextPackOptions): SurveyAIContextPack;
80
- //#endregion
81
3
  //#region src/editor/types.d.ts
82
4
  interface Target {
83
5
  parentId: string;
@@ -163,6 +85,7 @@ interface UndoRedoConfig {
163
85
  declare const CommitSource: {
164
86
  readonly USER: "user";
165
87
  readonly SYSTEM: "system";
88
+ readonly ASSISTANT: "assistant";
166
89
  };
167
90
  type CommitSource = (typeof CommitSource)[keyof typeof CommitSource];
168
91
  interface CommitMeta {
@@ -344,6 +267,8 @@ declare class SurveyEditor {
344
267
  */
345
268
  static fromJson(jsonData: SerializedSurveyEditor, pluginRegistry?: ItemTypeRegistry): SurveyEditor;
346
269
  private markAsModified;
270
+ private createEditorTimestamp;
271
+ private touchItemModifiedMetadata;
347
272
  addItem(target: Target, item: SurveyItemCore, content?: SurveyItemTranslations): void;
348
273
  removeItem(itemId: string, nested?: boolean): boolean;
349
274
  moveItem(itemId: string, newTarget: Target): boolean;
@@ -464,5 +389,5 @@ declare class SurveyEditor {
464
389
  pasteItem(clipboardData: SurveyItemClipboardData, target: Target): string;
465
390
  }
466
391
  //#endregion
467
- export { AssetPatch, BuildSurveyAIContextPackOptions, CommitMeta, CommitSource, ItemCopyPaste, SerializedSurveyEditor, SerializedTranslations, SurveyAIContextIndexes, SurveyAIContextPack, SurveyAIContextPurpose, SurveyAIContextScope, SurveyAIFocus, SurveyAIItemContextNode, SurveyAIKeyIndexEntry, SurveyAIOutlineNode, SurveyAITranslationSnippet, SurveyEditor, SurveyEditorConfig, SurveyEditorHistoryCommit, SurveyEditorUndoRedo, SurveyItemClipboardData, Target, UndoRedoConfig, buildSurveyAIContextPack };
392
+ export { AssetPatch, CommitMeta, CommitSource, ItemCopyPaste, SerializedSurveyEditor, SerializedTranslations, SurveyEditor, SurveyEditorConfig, SurveyEditorHistoryCommit, SurveyEditorUndoRedo, SurveyItemClipboardData, Target, UndoRedoConfig };
468
393
  //# sourceMappingURL=editor.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.mts","names":[],"sources":["../src/editor/ai-context.ts","../src/editor/types.ts","../src/editor/item-copy-paste.ts","../src/editor/undo-redo.ts","../src/editor/survey-editor.ts"],"mappings":";;;KAKY,oBAAA;AAAA,KACA,sBAAA;AAAA,UAQK,mBAAA;EACf,MAAA;EACA,QAAA;EACA,KAAA;EACA,QAAA;EACA,GAAA;EACA,OAAA;EACA,SAAA;EACA,UAAA;AAAA;AAAA,UAGe,aAAA;EACf,WAAA;EACA,YAAA;EACA,WAAA;EACA,cAAA;EACA,YAAA;AAAA;AAAA,UAGe,0BAAA;EACf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AAA;EF9oB0B;;;;;EEuqBtC,QAAA,CAAS,MAAA,WAAiB,uBAAA;EFhqB8B;;;;;;EE2qBxD,SAAA,CAAU,aAAA,EAAe,uBAAA,EAAyB,MAAA,EAAQ,MAAA;AAAA"}
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":";;;UAAiB,MAAA;EACf,QAAA;EACA,KAAA;AAAA;;;KCQU,sBAAA;EAAA,CACT,MAAA,WAAiB,oBAAA;AAAA;AAAA,UAIH,uBAAA;EACf,IAAA;EACA,OAAA;EACA,KAAA,EAAO,KAAA;IACL,MAAA;IACA,QAAA,EAAU,aAAA;EAAA;EAEZ,YAAA;IAAA,CAAiB,MAAA,WAAiB,sBAAA;EAAA;EAClC,UAAA;EACA,SAAA;AAAA;AAAA,cAGW,aAAA;EAAA,QACH,MAAA;cAEI,MAAA,EAAQ,MAAA;EARoC;;;;;;EAkBxD,QAAA,CAAS,MAAA,WAAiB,uBAAA;EApBd;;;;;EAAA,QA4EJ,mBAAA;EAxEC;;AAGX;;;;EAHW,QAoGD,oBAAA;EAiDiB;;;;;;;EAAzB,SAAA,CAAU,aAAA,EAAe,uBAAA,EAAyB,MAAA,EAAQ,MAAA;EA/I9C;;;EAAA,QA8LJ,mBAAA;EA5HA;;;EAAA,QAgJA,2BAAA;EAnEE;;;EAAA,QAoHF,0BAAA;EAjDA;;;EAAA,QAoFA,kBAAA;EAuBoB;;;EAAA,OAArB,oBAAA,CAAqB,IAAA,YAAgB,IAAA,IAAQ,uBAAA;AAAA;;;UCxVrC,cAAA;EACf,gBAAA;EACA,cAAA;EACA,cAAA;AAAA;AAAA,cAGW,YAAA;EAAA;;;;KAKD,YAAA,WAAuB,YAAA,eAA2B,YAAA;AAAA,UAE7C,UAAA;EACf,KAAA;EACA,MAAA,GAAS,YAAA;AAAA;AAAA,UAGM,UAAA;EACf,OAAA;EACA,IA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MAAA;IAAA;EAAA;ED9iBhE;;;ECwkBP,kBAAA,CAAA;IAAwB,KAAA;IAAe,KAAA;EAAA;;;;EAQvC,qBAAA,CAAsB,KAAA;IAAS,KAAA;IAAe,KAAA;EAAA;EDzkBpC;AAAA;;ECilBV,WAAA,CAAA;IAAA,CAAkB,GAAA;EAAA;ED7kBlB;;;ECqlBA,cAAA,CAAe,QAAA;IAAA,CAAa,GAAA;EAAA;EDjlBI;;;ECylBhC,gBAAA,CAAiB,GAAA,WAAc,uBAAA;EDxlB/B;;;ECgmBA,iBAAA,CAAA,GAAqB,GAAA,SAAY,uBAAA;ED/lBd;AAAA;;EC8mBnB,gBAAA,CAAiB,GAAA,UAAa,aAAA,EAAe,uBAAA;ED3mB3B;;AAKpB;EC8mBE,mBAAA,CAAoB,GAAA;;;;EAQpB,QAAA,CAAS,OAAA,WAAkB,cAAA;EDpnBrB;;;EC4nBN,SAAA,CAAA,GAAa,GAAA,SAAY,cAAA;EDznBzB;;;ECgoBA,QAAA,CAAS,OAAA,UAAiB,KAAA,EAAO,cAAA;ED5nB9B;;;ECipBH,WAAA,CAAY,OAAA;ED/oBV;;;;;ECwqBF,QAAA,CAAS,MAAA,WAAiB,uBAAA;EDxqBxB;;;;;;ECmrBF,SAAA,CAAU,aAAA,EAAe,uBAAA,EAAyB,MAAA,EAAQ,MAAA;AAAA"}
package/build/editor.mjs CHANGED
@@ -1,302 +1,4 @@
1
- import { $ as generateId, a as getContentPlainText, nt as structuredCloneMethod, t as Survey, u as SurveyItemTranslations, v as GroupItemCore } from "./survey-DnLtf19j.mjs";
2
- //#region src/editor/ai-context.ts
3
- const DEFAULT_SCOPE_LIMITS = {
4
- tiny: 40,
5
- focused: 150,
6
- full: 500
7
- };
8
- const DEFAULT_FOCUS_TREE_LIMIT = 120;
9
- const DEFAULT_TRANSLATION_SNIPPETS_PER_ITEM = 8;
10
- const DEFAULT_TRANSLATION_SNIPPET_TEXT_LIMIT = 120;
11
- const PURPOSE_DEFAULTS = {
12
- generic: {
13
- scope: "tiny",
14
- includeRawSurvey: false,
15
- includeIndexes: false,
16
- includeFocusItemTree: false
17
- },
18
- "key-suggestion": {
19
- scope: "tiny",
20
- includeRawSurvey: false,
21
- includeIndexes: false,
22
- includeFocusItemTree: true
23
- },
24
- "label-suggestion": {
25
- scope: "tiny",
26
- includeRawSurvey: false,
27
- includeIndexes: false,
28
- includeFocusItemTree: true
29
- },
30
- "item-generation": {
31
- scope: "focused",
32
- includeRawSurvey: false,
33
- includeIndexes: true,
34
- includeFocusItemTree: true
35
- },
36
- translation: {
37
- scope: "focused",
38
- includeRawSurvey: false,
39
- includeIndexes: true,
40
- includeFocusItemTree: true
41
- },
42
- "condition-management": {
43
- scope: "full",
44
- includeRawSurvey: true,
45
- includeIndexes: true,
46
- includeFocusItemTree: true
47
- }
48
- };
49
- const sortByItemId = (items) => [...items].sort((a, b) => a.itemId.localeCompare(b.itemId));
50
- function getChildIds(survey, itemId) {
51
- const item = survey.surveyItems.get(itemId);
52
- if (!(item instanceof GroupItemCore)) return [];
53
- return [...item.items ?? []];
54
- }
55
- function buildParentLookup(survey) {
56
- const lookup = /* @__PURE__ */ new Map();
57
- for (const item of survey.surveyItems.values()) {
58
- if (!(item instanceof GroupItemCore)) continue;
59
- for (const childId of item.items ?? []) lookup.set(childId, item.id);
60
- }
61
- return lookup;
62
- }
63
- function createFullKeyGetter(survey, parentLookup) {
64
- const fullKeyCache = /* @__PURE__ */ new Map();
65
- const getFullKey = (itemId, stack = /* @__PURE__ */ new Set()) => {
66
- const cached = fullKeyCache.get(itemId);
67
- if (cached) return cached;
68
- const item = survey.surveyItems.get(itemId);
69
- if (!item) return itemId;
70
- if (stack.has(itemId)) return item.key;
71
- const parentId = parentLookup.get(itemId);
72
- if (!parentId) {
73
- fullKeyCache.set(itemId, item.key);
74
- return item.key;
75
- }
76
- stack.add(itemId);
77
- const parentFullKey = getFullKey(parentId, stack);
78
- stack.delete(itemId);
79
- const fullKey = `${parentFullKey}.${item.key}`;
80
- fullKeyCache.set(itemId, fullKey);
81
- return fullKey;
82
- };
83
- return getFullKey;
84
- }
85
- function buildFullOutline(survey, parentLookup, getFullKey) {
86
- const outline = [];
87
- const visited = /* @__PURE__ */ new Set();
88
- const toNode = (itemId, depth) => {
89
- const item = survey.surveyItems.get(itemId);
90
- if (!item) return;
91
- const childCount = item instanceof GroupItemCore ? item.items.length : 0;
92
- return {
93
- itemId,
94
- parentId: parentLookup.get(itemId),
95
- depth,
96
- itemType: item.type,
97
- key: item.key,
98
- fullKey: getFullKey(itemId),
99
- itemLabel: item.metadata?.itemLabel,
100
- childCount
101
- };
102
- };
103
- const visit = (itemId, depth) => {
104
- if (visited.has(itemId)) return;
105
- visited.add(itemId);
106
- const node = toNode(itemId, depth);
107
- if (node) outline.push(node);
108
- for (const childId of getChildIds(survey, itemId)) visit(childId, depth + 1);
109
- };
110
- const root = survey.rootItem;
111
- if (root) visit(root.id, 0);
112
- const remaining = sortByItemId(Array.from(survey.surveyItems.values()).filter((item) => !visited.has(item.id)).map((item) => ({ itemId: item.id })));
113
- for (const item of remaining) visit(item.itemId, 0);
114
- return outline;
115
- }
116
- function collectTinyScopeIds(survey, focusItemId) {
117
- const ids = /* @__PURE__ */ new Set();
118
- const rootItem = survey.rootItem;
119
- if (rootItem) ids.add(rootItem.id);
120
- ids.add(focusItemId);
121
- for (const id of survey.getItemPath(focusItemId)) ids.add(id);
122
- for (const sibling of survey.getSiblings(focusItemId)) ids.add(sibling.id);
123
- for (const childId of getChildIds(survey, focusItemId)) ids.add(childId);
124
- return ids;
125
- }
126
- function addDescendants(survey, itemId, set, maxDepth) {
127
- const queue = [{
128
- id: itemId,
129
- depth: 0
130
- }];
131
- while (queue.length > 0) {
132
- const current = queue.shift();
133
- if (!current) continue;
134
- if (current.depth >= maxDepth) continue;
135
- for (const childId of getChildIds(survey, current.id)) {
136
- set.add(childId);
137
- queue.push({
138
- id: childId,
139
- depth: current.depth + 1
140
- });
141
- }
142
- }
143
- }
144
- function collectFocusedScopeIds(survey, focusItemId) {
145
- const ids = collectTinyScopeIds(survey, focusItemId);
146
- const ancestors = survey.getItemPath(focusItemId);
147
- addDescendants(survey, focusItemId, ids, 2);
148
- for (const sibling of survey.getSiblings(focusItemId)) {
149
- if (sibling.id === focusItemId) continue;
150
- ids.add(sibling.id);
151
- addDescendants(survey, sibling.id, ids, 1);
152
- }
153
- for (const ancestorId of ancestors) {
154
- const siblingIds = (survey.getParentItem(ancestorId)?.items ?? []).filter((id) => id !== ancestorId);
155
- for (const siblingId of siblingIds) {
156
- ids.add(siblingId);
157
- addDescendants(survey, siblingId, ids, 1);
158
- }
159
- }
160
- return ids;
161
- }
162
- function buildFocusInfo(survey, focusItemId) {
163
- if (!survey.surveyItems.has(focusItemId)) return;
164
- const pathItemIds = [...survey.getItemPath(focusItemId), focusItemId];
165
- return {
166
- focusItemId,
167
- parentItemId: survey.getParentItem(focusItemId)?.id,
168
- pathItemIds,
169
- siblingItemIds: survey.getSiblings(focusItemId).filter((item) => item.id !== focusItemId).map((item) => item.id),
170
- childItemIds: getChildIds(survey, focusItemId)
171
- };
172
- }
173
- const normalizeSnippetText = (text, maxChars) => {
174
- return text.trim().replace(/\s+/g, " ").slice(0, maxChars);
175
- };
176
- const getContentText = (content, maxChars) => {
177
- const normalized = normalizeSnippetText(getContentPlainText(content), maxChars);
178
- return normalized.length > 0 ? normalized : null;
179
- };
180
- function getItemTranslationSnippets(survey, itemId, maxSnippets, textLimit) {
181
- const snippets = [];
182
- const translations = survey.getItemTranslations(itemId);
183
- if (!translations) return snippets;
184
- for (const locale of translations.locales) {
185
- const localeContent = translations.getAllForLocale(locale);
186
- if (!localeContent) continue;
187
- for (const [contentKey, content] of Object.entries(localeContent)) {
188
- const text = getContentText(content, textLimit);
189
- if (!text) continue;
190
- snippets.push({
191
- locale,
192
- contentKey,
193
- text
194
- });
195
- if (snippets.length >= maxSnippets) return snippets;
196
- }
197
- }
198
- return snippets;
199
- }
200
- function buildFocusItemTree(survey, focusItemId, getFullKey, options) {
201
- if (!survey.surveyItems.has(focusItemId)) return { truncated: false };
202
- let remainingBudget = options.treeLimit;
203
- let truncated = false;
204
- const visit = (itemId) => {
205
- if (remainingBudget <= 0) {
206
- truncated = true;
207
- return;
208
- }
209
- const item = survey.surveyItems.get(itemId);
210
- if (!item) return;
211
- remainingBudget -= 1;
212
- const siblingKeys = survey.getSiblings(itemId).filter((sibling) => sibling.id !== itemId).map((sibling) => sibling.key);
213
- const descendants = [];
214
- if (item instanceof GroupItemCore) for (const childId of item.items) {
215
- const childNode = visit(childId);
216
- if (childNode) descendants.push(childNode);
217
- }
218
- return {
219
- itemId: item.id,
220
- itemType: item.type,
221
- itemKey: item.key,
222
- fullKey: getFullKey(item.id),
223
- itemLabel: item.metadata?.itemLabel,
224
- siblingKeys,
225
- translations: getItemTranslationSnippets(survey, item.id, options.snippetsPerItem, options.snippetTextLimit),
226
- descendants
227
- };
228
- };
229
- return {
230
- focusItem: visit(focusItemId),
231
- truncated
232
- };
233
- }
234
- function buildContextIndexes(survey, fullOutline, purpose) {
235
- const indexes = { keyIndex: fullOutline.map((node) => ({
236
- itemId: node.itemId,
237
- itemType: node.itemType,
238
- key: node.key,
239
- fullKey: node.fullKey,
240
- itemLabel: node.itemLabel,
241
- path: node.fullKey.split(".").slice(0, -1)
242
- })) };
243
- if (purpose === "condition-management") indexes.responseSlots = Object.keys(survey.getAvailableResponseValueSlots());
244
- return indexes;
245
- }
246
- function buildSurveyAIContextPack(survey, options = {}) {
247
- const purpose = options.purpose ?? "generic";
248
- const purposeDefaults = PURPOSE_DEFAULTS[purpose];
249
- const scope = options.scope ?? purposeDefaults.scope;
250
- const defaultLimit = DEFAULT_SCOPE_LIMITS[scope];
251
- const outlineLimit = Math.max(1, options.outlineLimit ?? defaultLimit);
252
- const includeRawSurvey = options.includeRawSurvey ?? purposeDefaults.includeRawSurvey;
253
- const includeIndexes = options.includeIndexes ?? purposeDefaults.includeIndexes;
254
- const includeFocusItemTree = options.includeFocusItemTree ?? purposeDefaults.includeFocusItemTree;
255
- const focusItemId = options.focusItemId;
256
- const focusExists = Boolean(focusItemId && survey.surveyItems.has(focusItemId));
257
- const parentLookup = buildParentLookup(survey);
258
- const getFullKey = createFullKeyGetter(survey, parentLookup);
259
- const fullOutline = buildFullOutline(survey, parentLookup, getFullKey);
260
- let scopedOutline = fullOutline;
261
- if (scope === "tiny" && focusItemId && focusExists) {
262
- const includedIds = collectTinyScopeIds(survey, focusItemId);
263
- scopedOutline = fullOutline.filter((node) => includedIds.has(node.itemId));
264
- } else if (scope === "focused" && focusItemId && focusExists) {
265
- const includedIds = collectFocusedScopeIds(survey, focusItemId);
266
- scopedOutline = fullOutline.filter((node) => includedIds.has(node.itemId));
267
- }
268
- const outlineTruncated = scopedOutline.length > outlineLimit;
269
- const outline = outlineTruncated ? scopedOutline.slice(0, outlineLimit) : scopedOutline;
270
- let focusItemTreeTruncated = false;
271
- let focusItem;
272
- if (includeFocusItemTree && focusItemId && focusExists) {
273
- const focusTreeResult = buildFocusItemTree(survey, focusItemId, getFullKey, {
274
- treeLimit: Math.max(1, options.focusItemTreeLimit ?? DEFAULT_FOCUS_TREE_LIMIT),
275
- snippetsPerItem: Math.max(1, options.translationSnippetsPerItemLimit ?? DEFAULT_TRANSLATION_SNIPPETS_PER_ITEM),
276
- snippetTextLimit: Math.max(1, options.translationSnippetTextLimit ?? DEFAULT_TRANSLATION_SNIPPET_TEXT_LIMIT)
277
- });
278
- focusItemTreeTruncated = focusTreeResult.truncated;
279
- focusItem = focusTreeResult.focusItem;
280
- }
281
- return {
282
- purpose,
283
- scope,
284
- surveyKey: survey.surveyKey,
285
- locales: [...survey.locales],
286
- itemCount: survey.surveyItems.size,
287
- outline,
288
- focus: focusItemId ? buildFocusInfo(survey, focusItemId) : void 0,
289
- focusItem,
290
- indexes: includeIndexes ? buildContextIndexes(survey, fullOutline, purpose) : void 0,
291
- flags: {
292
- outlineTruncated,
293
- rawSurveyIncluded: includeRawSurvey,
294
- focusItemTreeTruncated
295
- },
296
- rawSurvey: includeRawSurvey ? survey.serialize() : void 0
297
- };
298
- }
299
- //#endregion
1
+ import { $ as generateId, nt as structuredCloneMethod, t as Survey, u as SurveyItemTranslations, v as GroupItemCore } from "./survey-Dxt6iolo.mjs";
300
2
  //#region src/editor/item-copy-paste.ts
301
3
  var ItemCopyPaste = class ItemCopyPaste {
302
4
  survey;
@@ -499,14 +201,16 @@ var ItemCopyPaste = class ItemCopyPaste {
499
201
  static isValidClipboardData(data) {
500
202
  if (typeof data !== "object" || data === null || data === void 0) return false;
501
203
  const clipboardData = data;
502
- return clipboardData.type === "survey-item" && clipboardData.version === "1.0.0" && clipboardData.rootItemId !== void 0;
204
+ if (clipboardData.rootItemId === void 0 || typeof clipboardData.rootItemId !== "string" || !Array.isArray(clipboardData.items) || clipboardData.items.length === 0 || typeof clipboardData.translations !== "object" || clipboardData.translations === null || Array.isArray(clipboardData.translations)) return false;
205
+ return clipboardData.type === "survey-item" && clipboardData.version === "1.0.0" && clipboardData.items.every((item) => typeof item === "object" && item !== null && typeof item.itemId === "string" && item.itemId.length > 0 && typeof item.itemData === "object" && item.itemData !== null && !Array.isArray(item.itemData) && typeof item.itemData.itemType === "string") && clipboardData.items.some((item) => item.itemId === clipboardData.rootItemId);
503
206
  }
504
207
  };
505
208
  //#endregion
506
209
  //#region src/editor/undo-redo.ts
507
210
  const CommitSource = {
508
211
  USER: "user",
509
- SYSTEM: "system"
212
+ SYSTEM: "system",
213
+ ASSISTANT: "assistant"
510
214
  };
511
215
  var MemoryCalculator = class {
512
216
  static encoder = new TextEncoder();
@@ -972,8 +676,17 @@ var SurveyEditor = class SurveyEditor {
972
676
  markAsModified() {
973
677
  this._hasUncommittedChanges = true;
974
678
  }
679
+ createEditorTimestamp() {
680
+ return (/* @__PURE__ */ new Date()).toISOString();
681
+ }
682
+ touchItemModifiedMetadata(itemId, timestamp = this.createEditorTimestamp()) {
683
+ const item = this._survey.surveyItems.get(itemId);
684
+ if (!item) return;
685
+ item.setModifiedAt(timestamp);
686
+ }
975
687
  addItem(target, item, content) {
976
688
  this.markAsModified();
689
+ const timestamp = this.createEditorTimestamp();
977
690
  let parentGroup;
978
691
  if (!target) {
979
692
  const rootItem = this._survey.rootItem;
@@ -989,19 +702,29 @@ var SurveyEditor = class SurveyEditor {
989
702
  if (parentGroup.hasChild(item.id)) throw new Error(`Item ${item.id} already in this group`);
990
703
  const siblings = Array.from(this._survey.surveyItems.values()).filter((sItem) => parentGroup.items?.includes(sItem.id));
991
704
  let counter = 1;
992
- while (siblings.some((sibling) => sibling.key === item.key)) {
993
- item.key += `_${counter}`;
705
+ const originalKey = item.key;
706
+ let uniqueKey = originalKey;
707
+ while (siblings.some((sibling) => sibling.key === uniqueKey)) {
708
+ uniqueKey = `${originalKey}_${counter}`;
994
709
  counter++;
995
710
  }
996
711
  let insertIndex;
997
712
  if (target?.index !== void 0) insertIndex = Math.min(target.index, parentGroup.items.length);
998
713
  else insertIndex = parentGroup.items.length;
714
+ item.updateRawItem({
715
+ ...item.rawItem,
716
+ key: uniqueKey
717
+ });
718
+ item.setCreatedAt(timestamp);
719
+ item.setModifiedAt(timestamp);
999
720
  this._survey.surveyItems.set(item.id, item);
1000
721
  parentGroup.addChild(item.id, insertIndex);
722
+ this.touchItemModifiedMetadata(parentGroup.id, timestamp);
1001
723
  if (content) this._survey.translations.setItemTranslations(item.id, content);
1002
724
  }
1003
725
  removeItem(itemId, nested = false) {
1004
726
  this.markAsModified();
727
+ const timestamp = this.createEditorTimestamp();
1005
728
  const item = this._survey.surveyItems.get(itemId);
1006
729
  if (!item) return false;
1007
730
  const parentItem = this._survey.getParentItem(itemId);
@@ -1009,11 +732,15 @@ var SurveyEditor = class SurveyEditor {
1009
732
  if (item instanceof GroupItemCore) for (const childId of item.getChildrenIds()) this.removeItem(childId, true);
1010
733
  this._survey.surveyItems.delete(itemId);
1011
734
  this._survey.translations?.onItemDeleted(itemId);
1012
- if (!nested) parentItem.removeChild(itemId);
735
+ if (!nested) {
736
+ parentItem.removeChild(itemId);
737
+ this.touchItemModifiedMetadata(parentItem.id, timestamp);
738
+ }
1013
739
  return true;
1014
740
  }
1015
741
  moveItem(itemId, newTarget) {
1016
742
  this.markAsModified();
743
+ const timestamp = this.createEditorTimestamp();
1017
744
  const item = this._survey.surveyItems.get(itemId);
1018
745
  if (!item) throw new Error(`Item with id '${itemId}' not found`);
1019
746
  const targetItem = this._survey.surveyItems.get(newTarget.parentId);
@@ -1022,16 +749,27 @@ var SurveyEditor = class SurveyEditor {
1022
749
  if (this._survey.isDescendantOf(newTarget.parentId, itemId)) throw new Error(`Cannot move item '${itemId}' to its descendant '${newTarget.parentId}'`);
1023
750
  const currentParentItem = this._survey.getParentItem(itemId);
1024
751
  if (currentParentItem?.id === newTarget.parentId) throw new Error(`Item '${itemId}' is already in the target parent '${newTarget.parentId}'`);
1025
- if (currentParentItem) currentParentItem.removeChild(itemId);
752
+ if (currentParentItem) {
753
+ const currentParentGroup = currentParentItem;
754
+ currentParentGroup.removeChild(itemId);
755
+ this.touchItemModifiedMetadata(currentParentGroup.id, timestamp);
756
+ }
1026
757
  const targetGroup = targetItem;
1027
758
  const siblings = Array.from(this._survey.surveyItems.values()).filter((sItem) => targetGroup.hasChild(sItem.id));
1028
759
  let counter = 1;
1029
- while (siblings.some((sibling) => sibling.key === item.key)) {
1030
- item.key += `_${counter}`;
760
+ let uniqueKey = item.key;
761
+ while (siblings.some((sibling) => sibling.key === uniqueKey)) {
762
+ uniqueKey = `${item.key}_${counter}`;
1031
763
  counter++;
1032
764
  }
765
+ if (uniqueKey !== item.key) item.updateRawItem({
766
+ ...item.rawItem,
767
+ key: uniqueKey
768
+ });
1033
769
  const insertIndex = newTarget.index !== void 0 ? Math.min(newTarget.index, targetGroup.items.length) : targetGroup.items.length;
1034
- targetGroup.items.splice(insertIndex, 0, itemId);
770
+ targetGroup.addChild(itemId, insertIndex);
771
+ this.touchItemModifiedMetadata(targetGroup.id, timestamp);
772
+ this.touchItemModifiedMetadata(itemId, timestamp);
1035
773
  return true;
1036
774
  }
1037
775
  /**
@@ -1075,13 +813,19 @@ var SurveyEditor = class SurveyEditor {
1075
813
  const siblingWithSameKey = (parentGroup.items ?? []).filter((id) => id !== itemId).map((id) => this._survey.surveyItems.get(id)).find((s) => s !== void 0 && s.key === newKey);
1076
814
  if (siblingWithSameKey) throw new Error(`Key '${newKey}' is already in use by sibling item '${siblingWithSameKey.id}'`);
1077
815
  }
1078
- const newItem = this._survey.createItemFromRaw(merged);
816
+ const newItem = this._survey.createItemFromRaw({
817
+ ...merged,
818
+ editorMetadata: existingItem.rawItem.editorMetadata
819
+ });
820
+ newItem.setModifiedAt(this.createEditorTimestamp());
1079
821
  this._survey.surveyItems.set(itemId, newItem);
1080
822
  this.markAsModified();
1081
823
  }
1082
824
  updateItemTranslations(itemId, updatedContent) {
1083
- if (!this._survey.surveyItems.get(itemId)) return false;
825
+ const item = this._survey.surveyItems.get(itemId);
826
+ if (!item) return false;
1084
827
  this.markAsModified();
828
+ item.setModifiedAt(this.createEditorTimestamp());
1085
829
  this._survey.translations.setItemTranslations(itemId, updatedContent);
1086
830
  return true;
1087
831
  }
@@ -1215,10 +959,22 @@ var SurveyEditor = class SurveyEditor {
1215
959
  */
1216
960
  pasteItem(clipboardData, target) {
1217
961
  this.markAsModified();
1218
- return new ItemCopyPaste(this._survey).pasteItem(clipboardData, target);
962
+ const timestamp = this.createEditorTimestamp();
963
+ const itemIdsBeforePaste = new Set(this._survey.surveyItems.keys());
964
+ const newItemId = new ItemCopyPaste(this._survey).pasteItem(clipboardData, target);
965
+ const pastedItemIds = Array.from(this._survey.surveyItems.keys()).filter((itemId) => !itemIdsBeforePaste.has(itemId));
966
+ for (const itemId of pastedItemIds) {
967
+ const item = this._survey.surveyItems.get(itemId);
968
+ if (item) {
969
+ item.setCreatedAt(timestamp);
970
+ item.setModifiedAt(timestamp);
971
+ }
972
+ }
973
+ this.touchItemModifiedMetadata(target.parentId, timestamp);
974
+ return newItemId;
1219
975
  }
1220
976
  };
1221
977
  //#endregion
1222
- export { CommitSource, ItemCopyPaste, SurveyEditor, SurveyEditorUndoRedo, buildSurveyAIContextPack };
978
+ export { CommitSource, ItemCopyPaste, SurveyEditor, SurveyEditorUndoRedo };
1223
979
 
1224
980
  //# sourceMappingURL=editor.mjs.map