@case-framework/survey-core 0.3.0 → 0.4.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.
@@ -1,4 +1,4 @@
1
- import { C as SurveyCardContent, L as RawSurveyItem, S as NavigationContent, T as SurveyItemTranslations, W as TemplateValueDefinition, b as JsonComponentContent, j as Content, p as ItemTypeRegistry, t as Survey, y as RawSurvey, z as SurveyItemCore } from "./survey-wnGyIY66.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-DShEOjyz.mjs";
2
2
 
3
3
  //#region src/editor/ai-context.d.ts
4
4
  type SurveyAIContextScope = "tiny" | "focused" | "full";
@@ -169,22 +169,47 @@ interface CommitMeta {
169
169
  label: string;
170
170
  source?: CommitSource;
171
171
  }
172
- interface HistoryEntry {
173
- survey: RawSurvey;
172
+ interface AssetPatch {
173
+ assetId: string;
174
+ prev?: RawSurveyAsset;
175
+ next?: RawSurveyAsset;
176
+ }
177
+ interface BaseHistoryEntry {
174
178
  timestamp: number;
175
179
  meta: CommitMeta;
176
180
  memorySize: number;
177
181
  }
182
+ interface SurveySnapshotHistoryEntry extends BaseHistoryEntry {
183
+ kind: 'survey-snapshot';
184
+ survey: RawSurvey;
185
+ }
186
+ interface AssetChangeHistoryEntry extends BaseHistoryEntry {
187
+ kind: 'asset-change';
188
+ changes: AssetPatch[];
189
+ }
190
+ type HistoryEntry = SurveySnapshotHistoryEntry | AssetChangeHistoryEntry;
191
+ type SerializedHistoryEntry = SurveySnapshotHistoryEntry | AssetChangeHistoryEntry | (BaseHistoryEntry & {
192
+ survey: RawSurvey;
193
+ });
178
194
  declare class SurveyEditorUndoRedo {
179
195
  private history;
180
196
  private currentIndex;
181
197
  private _config;
182
- constructor(initialSurvey: RawSurvey, config?: Partial<UndoRedoConfig>, meta?: CommitMeta);
198
+ private _initialAssets?;
199
+ constructor(initialSurvey: RawSurvey, config?: Partial<UndoRedoConfig>, meta?: CommitMeta, initialAssets?: Record<string, RawSurveyAsset>);
200
+ private saveEntry;
183
201
  private saveSnapshot;
202
+ private getBaseAssetsSize;
184
203
  private cleanupHistory;
204
+ private dropOldestState;
185
205
  private getTotalMemoryUsage;
206
+ private getStateAtIndex;
207
+ private applyAssetPatch;
208
+ private getAssetsAtIndex;
186
209
  commit(survey: RawSurvey, meta: CommitMeta): void;
210
+ commitAssetChange(changes: AssetPatch[], meta: CommitMeta): void;
187
211
  getCurrentState(): RawSurvey;
212
+ getCurrentAssets(): Record<string, RawSurveyAsset> | undefined;
188
213
  undo(): RawSurvey | null;
189
214
  redo(): RawSurvey | null;
190
215
  canUndo(): boolean;
@@ -201,6 +226,7 @@ declare class SurveyEditorUndoRedo {
201
226
  */
202
227
  getHistory(): Array<{
203
228
  index: number;
229
+ kind: HistoryEntry['kind'];
204
230
  meta: CommitMeta;
205
231
  timestamp: number;
206
232
  memorySize: number;
@@ -232,6 +258,7 @@ declare class SurveyEditorUndoRedo {
232
258
  history: Array<HistoryEntry>;
233
259
  currentIndex: number;
234
260
  config: UndoRedoConfig;
261
+ initialAssets?: Record<string, RawSurveyAsset>;
235
262
  };
236
263
  /**
237
264
  * Create a new SurveyEditorUndoRedo instance from JSON data
@@ -239,15 +266,11 @@ declare class SurveyEditorUndoRedo {
239
266
  * @returns A new SurveyEditorUndoRedo instance with the restored state
240
267
  */
241
268
  static deserialize(jsonData: {
242
- history: Array<{
243
- survey: RawSurvey;
244
- timestamp: number;
245
- meta: CommitMeta;
246
- memorySize: number;
247
- }>;
269
+ history: Array<SerializedHistoryEntry>;
248
270
  currentIndex: number;
249
271
  config: UndoRedoConfig;
250
- }): SurveyEditorUndoRedo;
272
+ initialAssets?: Record<string, RawSurveyAsset>;
273
+ }, initialAssetsOverride?: Record<string, RawSurveyAsset>): SurveyEditorUndoRedo;
251
274
  }
252
275
  //#endregion
253
276
  //#region src/editor/survey-editor.d.ts
@@ -272,6 +295,7 @@ declare class SurveyEditor {
272
295
  get hasUncommittedChanges(): boolean;
273
296
  get undoRedo(): SurveyEditorUndoRedo;
274
297
  commit(meta: CommitMeta): void;
298
+ private restoreHistoryState;
275
299
  commitIfNeeded(): void;
276
300
  undo(): boolean;
277
301
  redo(): boolean;
@@ -390,6 +414,22 @@ declare class SurveyEditor {
390
414
  * Remove a template value.
391
415
  */
392
416
  removeTemplateValue(key: string): void;
417
+ /**
418
+ * Get a survey asset immutably.
419
+ */
420
+ getAsset(assetId: string): RawSurveyAsset | undefined;
421
+ /**
422
+ * Get all survey assets immutably.
423
+ */
424
+ getAssets(): Map<string, RawSurveyAsset>;
425
+ /**
426
+ * Add or replace a survey asset.
427
+ */
428
+ setAsset(assetId: string, asset: RawSurveyAsset): void;
429
+ /**
430
+ * Remove a survey asset.
431
+ */
432
+ removeAsset(assetId: string): void;
393
433
  /**
394
434
  * Copy a survey item and all its data to clipboard format
395
435
  * @param itemId - The ID of the item to copy
@@ -405,5 +445,5 @@ declare class SurveyEditor {
405
445
  pasteItem(clipboardData: SurveyItemClipboardData, target: Target): string;
406
446
  }
407
447
  //#endregion
408
- export { BuildSurveyAIContextPackOptions, CommitMeta, CommitSource, ItemCopyPaste, SerializedSurveyEditor, SerializedTranslations, SurveyAIContextIndexes, SurveyAIContextPack, SurveyAIContextPurpose, SurveyAIContextScope, SurveyAIFocus, SurveyAIItemContextNode, SurveyAIKeyIndexEntry, SurveyAIOutlineNode, SurveyAITranslationSnippet, SurveyEditor, SurveyEditorConfig, SurveyEditorUndoRedo, SurveyItemClipboardData, Target, UndoRedoConfig, buildSurveyAIContextPack };
448
+ export { AssetPatch, BuildSurveyAIContextPackOptions, CommitMeta, CommitSource, ItemCopyPaste, SerializedSurveyEditor, SerializedTranslations, SurveyAIContextIndexes, SurveyAIContextPack, SurveyAIContextPurpose, SurveyAIContextScope, SurveyAIFocus, SurveyAIItemContextNode, SurveyAIKeyIndexEntry, SurveyAIOutlineNode, SurveyAITranslationSnippet, SurveyEditor, SurveyEditorConfig, SurveyEditorUndoRedo, SurveyItemClipboardData, Target, UndoRedoConfig, buildSurveyAIContextPack };
409
449
  //# 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,MAAA;EACA,UAAA;EACA,IAAA;AAAA;AAAA,UAGe,uBAAA;EACf,MAAA;EACA,QAAA;EACA,OAAA;EACA,OAAA;EACA,SAAA;EACA,WAAA;EACA,YAAA,EAAc,0BAAA;EACd,WAAA,EAAa,uBAAA;AAAA;AAAA,UAGE,qBAAA;EACf,MAAA;EACA,QAAA;EACA,GAAA;EACA,OAAA;EACA,SAAA;EACA,IAAA;AAAA;AAAA,UAGe,sBAAA;EACf,QAAA,EAAU,qBAAA;EACV,aAAA;AAAA;AAAA,UAGe,mBAAA;EACf,OAAA,EAAS,sBAAA;EACT,KAAA,EAAO,oBAAA;EACP,SAAA;EACA,OAAA;EACA,SAAA;EACA,OAAA,EAAS,mBAAA;EACT,KAAA,GAAQ,aAAA;EACR,SAAA,GAAY,uBAAA;EACZ,OAAA,GAAU,sBAAA;EACV,KAAA;IACE,gBAAA;IACA,iBAAA;IACA,sBAAA;EAAA;EAEF,SAAA,GAAY,SAAA;AAAA;AAAA,UAGG,+BAAA;EACf,OAAA,GAAU,sBAAA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CAAuB,MAAA,UAAgB,cAAA,GAAiB,sBAAA;;;;;EAgBxD,wBAAA,CAAyB,OAAA;IACvB,UAAA;MAAe,MAAA;MAAgB,OAAA,GAAU,iBAAA;IAAA;IACzC,UAAA;MAAe,MAAA;MAAgB,OAAA,GAAU,iBAAA;IAAA;IACzC,kBAAA;MAAuB,MAAA;MAAgB,OAAA;QAAY,eAAA,GAAkB,OAAA;MAAA;IAAA;EAAA;EJhZ/D;;;EIiaR,kBAAA,CAAA;IAAwB,KAAA;IAAe,KAAA;EAAA;EJ5ZrC;;;EIoaF,qBAAA,CAAsB,KAAA;IAAS,KAAA;IAAe,KAAA;EAAA;EJ9ZA;;;EIsa9C,WAAA,CAAA;IAAA,CAAkB,GAAA;EAAA;EJpaV;;;EI4aR,cAAA,CAAe,QAAA;IAAA,CAAa,GAAA;EAAA;EJta5B;;;EI8aA,gBAAA,CAAiB,GAAA,WAAc,uBAAA;EJ5aJ;AAwZ7B;;EI4BE,iBAAA,CAAA,GAAqB,GAAA,SAAY,uBAAA;EJ3BzB;;;EI0CR,gBAAA,CAAiB,GAAA,UAAa,aAAA,EAAe,uBAAA;EJxCzB;;;EIgDpB,mBAAA,CAAoB,GAAA;EJjDpB;;;;;EI2DA,QAAA,CAAS,MAAA,WAAiB,uBAAA;;AHjjB5B;;;;;EG4jBE,SAAA,CAAU,aAAA,EAAe,uBAAA,EAAyB,MAAA,EAAQ,MAAA;AAAA"}
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,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HANGED
@@ -1,4 +1,4 @@
1
- import { I as generateId, R as structuredCloneMethod, l as GroupItemCore, m as ReservedSurveyItemTypes, n as SurveyItemTranslations, t as Survey } from "./survey-DJbgFVPz.mjs";
1
+ import { $ as generateId, a as getContentPlainText, nt as structuredCloneMethod, t as Survey, u as SurveyItemTranslations, v as GroupItemCore } from "./survey-yXdl8xkf.mjs";
2
2
  //#region src/editor/ai-context.ts
3
3
  const DEFAULT_SCOPE_LIMITS = {
4
4
  tiny: 40,
@@ -174,10 +174,7 @@ const normalizeSnippetText = (text, maxChars) => {
174
174
  return text.trim().replace(/\s+/g, " ").slice(0, maxChars);
175
175
  };
176
176
  const getContentText = (content, maxChars) => {
177
- if (!content) return null;
178
- const maybeText = content.content;
179
- if (typeof maybeText !== "string") return null;
180
- const normalized = normalizeSnippetText(maybeText, maxChars);
177
+ const normalized = normalizeSnippetText(getContentPlainText(content), maxChars);
181
178
  return normalized.length > 0 ? normalized : null;
182
179
  };
183
180
  function getItemTranslationSnippets(survey, itemId, maxSnippets, textLimit) {
@@ -439,7 +436,7 @@ var ItemCopyPaste = class ItemCopyPaste {
439
436
  */
440
437
  updateItemIdsInData(itemData, idMapping) {
441
438
  const updatedData = JSON.parse(JSON.stringify(itemData));
442
- if (updatedData.itemType === ReservedSurveyItemTypes.Group && updatedData.config) {
439
+ if (updatedData.itemType === "group" && updatedData.config) {
443
440
  const config = updatedData.config;
444
441
  if (config.items) config.items = config.items.map((childId) => idMapping[childId] ?? childId);
445
442
  }
@@ -460,6 +457,11 @@ var ItemCopyPaste = class ItemCopyPaste {
460
457
  if (itemData.validations) Object.values(itemData.validations).forEach((expr) => {
461
458
  if (expr) this.updateExpressionReferences(expr, idMapping);
462
459
  });
460
+ if (itemData.prefills) itemData.prefills.forEach((prefill) => {
461
+ if (prefill.when) this.updateExpressionReferences(prefill.when, idMapping);
462
+ if (prefill.source.type === "expression") this.updateExpressionReferences(prefill.source.expression, idMapping);
463
+ if (prefill.source.type === "previousResponse") prefill.source.ref.itemId = idMapping[prefill.source.ref.itemId] ?? prefill.source.ref.itemId;
464
+ });
463
465
  }
464
466
  /**
465
467
  * Update references in a single expression (recursive)
@@ -528,52 +530,152 @@ var MemoryCalculator = class {
528
530
  return `${size.toFixed(1)} ${units[unitIndex]}`;
529
531
  }
530
532
  };
533
+ function cloneAssets(assets) {
534
+ if (!assets || Object.keys(assets).length === 0) return;
535
+ return structuredCloneMethod(assets);
536
+ }
537
+ function normalizeHistoryEntry(entry) {
538
+ if ("kind" in entry) {
539
+ if (entry.kind === "survey-snapshot") return {
540
+ kind: "survey-snapshot",
541
+ survey: structuredCloneMethod(entry.survey),
542
+ timestamp: entry.timestamp,
543
+ meta: entry.meta,
544
+ memorySize: entry.memorySize
545
+ };
546
+ return {
547
+ kind: "asset-change",
548
+ changes: structuredCloneMethod(entry.changes),
549
+ timestamp: entry.timestamp,
550
+ meta: entry.meta,
551
+ memorySize: entry.memorySize
552
+ };
553
+ }
554
+ return {
555
+ kind: "survey-snapshot",
556
+ survey: structuredCloneMethod(entry.survey),
557
+ timestamp: entry.timestamp,
558
+ meta: entry.meta,
559
+ memorySize: entry.memorySize
560
+ };
561
+ }
531
562
  var SurveyEditorUndoRedo = class SurveyEditorUndoRedo {
532
563
  history = [];
533
564
  currentIndex = -1;
534
565
  _config;
566
+ _initialAssets;
535
567
  constructor(initialSurvey, config = {}, meta = {
536
568
  label: "Initial state",
537
569
  source: CommitSource.SYSTEM
538
- }) {
570
+ }, initialAssets) {
539
571
  this._config = {
540
572
  maxTotalMemoryMB: 50,
541
573
  minHistorySize: 10,
542
574
  maxHistorySize: 200,
543
575
  ...config
544
576
  };
577
+ this._initialAssets = cloneAssets(initialAssets);
545
578
  this.saveSnapshot(initialSurvey, meta);
546
579
  }
547
- saveSnapshot(survey, meta) {
548
- const memorySize = MemoryCalculator.calculateSize(survey);
580
+ saveEntry(entry) {
581
+ const payload = entry.kind === "survey-snapshot" ? {
582
+ kind: entry.kind,
583
+ survey: entry.survey
584
+ } : {
585
+ kind: entry.kind,
586
+ changes: entry.changes
587
+ };
588
+ const memorySize = MemoryCalculator.calculateSize(payload);
549
589
  this.history = this.history.slice(0, this.currentIndex + 1);
550
590
  this.history.push({
551
- survey: structuredCloneMethod(survey),
591
+ ...structuredCloneMethod(entry),
552
592
  timestamp: Date.now(),
553
- meta,
554
593
  memorySize
555
594
  });
556
595
  this.currentIndex++;
557
596
  this.cleanupHistory();
558
597
  }
598
+ saveSnapshot(survey, meta) {
599
+ this.saveEntry({
600
+ kind: "survey-snapshot",
601
+ survey: structuredCloneMethod(survey),
602
+ meta
603
+ });
604
+ }
605
+ getBaseAssetsSize() {
606
+ return this._initialAssets ? MemoryCalculator.calculateSize(this._initialAssets) : 0;
607
+ }
559
608
  cleanupHistory() {
560
- let totalMemory = this.getTotalMemoryUsage();
561
609
  const maxMemoryBytes = this._config.maxTotalMemoryMB * 1024 * 1024;
562
- while (this.history.length > this._config.minHistorySize && (totalMemory > maxMemoryBytes || this.history.length > this._config.maxHistorySize)) {
563
- const removedSnapshot = this.history.shift();
564
- this.currentIndex--;
565
- if (removedSnapshot) totalMemory -= removedSnapshot.memorySize;
566
- }
610
+ while (this.history.length > this._config.minHistorySize && (this.getTotalMemoryUsage() > maxMemoryBytes || this.history.length > this._config.maxHistorySize)) if (this.dropOldestState() <= 0) break;
611
+ }
612
+ dropOldestState() {
613
+ if (this.history.length <= 1) return 0;
614
+ const nextStateIndex = 1;
615
+ const nextStateSurvey = this.getStateAtIndex(nextStateIndex);
616
+ const nextStateAssets = this.getAssetsAtIndex(nextStateIndex);
617
+ const nextEntry = this.history[nextStateIndex];
618
+ const newFirstEntry = {
619
+ kind: "survey-snapshot",
620
+ survey: nextStateSurvey,
621
+ meta: nextEntry.meta,
622
+ timestamp: nextEntry.timestamp,
623
+ memorySize: MemoryCalculator.calculateSize({
624
+ kind: "survey-snapshot",
625
+ survey: nextStateSurvey
626
+ })
627
+ };
628
+ const removedBytes = this.history[0].memorySize;
629
+ this._initialAssets = cloneAssets(nextStateAssets);
630
+ this.history = [newFirstEntry, ...this.history.slice(nextStateIndex + 1)];
631
+ this.currentIndex--;
632
+ return removedBytes;
567
633
  }
568
634
  getTotalMemoryUsage() {
569
- return this.history.reduce((total, entry) => total + entry.memorySize, 0);
635
+ return this.getBaseAssetsSize() + this.history.reduce((total, entry) => total + entry.memorySize, 0);
636
+ }
637
+ getStateAtIndex(index) {
638
+ if (index < 0 || index >= this.history.length) throw new Error("Invalid history state");
639
+ for (let i = index; i >= 0; i--) {
640
+ const entry = this.history[i];
641
+ if (entry.kind === "survey-snapshot") return structuredCloneMethod(entry.survey);
642
+ }
643
+ throw new Error("Invalid history state");
644
+ }
645
+ applyAssetPatch(assets, patch) {
646
+ const nextAssets = structuredCloneMethod(assets);
647
+ if (patch.next) nextAssets[patch.assetId] = structuredCloneMethod(patch.next);
648
+ else delete nextAssets[patch.assetId];
649
+ return nextAssets;
650
+ }
651
+ getAssetsAtIndex(index) {
652
+ if (index < 0 || index >= this.history.length) throw new Error("Invalid history state");
653
+ let assets = cloneAssets(this._initialAssets) ?? {};
654
+ for (let i = 1; i <= index; i++) {
655
+ const entry = this.history[i];
656
+ if (entry.kind !== "asset-change") continue;
657
+ for (const patch of entry.changes) assets = this.applyAssetPatch(assets, patch);
658
+ }
659
+ return Object.keys(assets).length > 0 ? assets : void 0;
570
660
  }
571
661
  commit(survey, meta) {
572
662
  this.saveSnapshot(survey, meta);
573
663
  }
664
+ commitAssetChange(changes, meta) {
665
+ if (changes.length === 0) return;
666
+ this.saveEntry({
667
+ kind: "asset-change",
668
+ changes: structuredCloneMethod(changes),
669
+ meta
670
+ });
671
+ }
574
672
  getCurrentState() {
575
673
  if (this.currentIndex < 0 || this.currentIndex >= this.history.length) throw new Error("Invalid history state");
576
- return structuredCloneMethod(this.history[this.currentIndex].survey);
674
+ return this.getStateAtIndex(this.currentIndex);
675
+ }
676
+ getCurrentAssets() {
677
+ if (this.currentIndex < 0 || this.currentIndex >= this.history.length) throw new Error("Invalid history state");
678
+ return this.getAssetsAtIndex(this.currentIndex);
577
679
  }
578
680
  undo() {
579
681
  if (!this.canUndo()) return null;
@@ -614,6 +716,7 @@ var SurveyEditorUndoRedo = class SurveyEditorUndoRedo {
614
716
  getHistory() {
615
717
  return this.history.map((entry, index) => ({
616
718
  index,
719
+ kind: entry.kind,
617
720
  meta: entry.meta,
618
721
  timestamp: entry.timestamp,
619
722
  memorySize: entry.memorySize,
@@ -654,14 +757,25 @@ var SurveyEditorUndoRedo = class SurveyEditorUndoRedo {
654
757
  */
655
758
  serialize() {
656
759
  return {
657
- history: this.history.map((entry) => ({
658
- survey: entry.survey,
659
- timestamp: entry.timestamp,
660
- meta: entry.meta,
661
- memorySize: entry.memorySize
662
- })),
760
+ history: this.history.map((entry) => {
761
+ if (entry.kind === "survey-snapshot") return {
762
+ kind: "survey-snapshot",
763
+ survey: entry.survey,
764
+ timestamp: entry.timestamp,
765
+ meta: entry.meta,
766
+ memorySize: entry.memorySize
767
+ };
768
+ return {
769
+ kind: "asset-change",
770
+ changes: entry.changes,
771
+ timestamp: entry.timestamp,
772
+ meta: entry.meta,
773
+ memorySize: entry.memorySize
774
+ };
775
+ }),
663
776
  currentIndex: this.currentIndex,
664
- config: { ...this._config }
777
+ config: { ...this._config },
778
+ initialAssets: cloneAssets(this._initialAssets)
665
779
  };
666
780
  }
667
781
  /**
@@ -669,23 +783,34 @@ var SurveyEditorUndoRedo = class SurveyEditorUndoRedo {
669
783
  * @param jsonData The serialized undo/redo state
670
784
  * @returns A new SurveyEditorUndoRedo instance with the restored state
671
785
  */
672
- static deserialize(jsonData) {
786
+ static deserialize(jsonData, initialAssetsOverride) {
673
787
  if (!jsonData.history || !Array.isArray(jsonData.history) || jsonData.history.length === 0) throw new Error("Invalid object: history must be an array and must not be empty");
674
788
  if (typeof jsonData.currentIndex !== "number" || jsonData.currentIndex < 0 || jsonData.currentIndex >= jsonData.history.length) throw new Error("Invalid object: currentIndex must be a valid index within the history array");
675
789
  if (!jsonData.config) throw new Error("Invalid object: config is required");
676
- const instance = new SurveyEditorUndoRedo(jsonData.history[0].survey, jsonData.config);
677
- instance.history = jsonData.history.map((entry) => ({
678
- survey: structuredCloneMethod(entry.survey),
679
- timestamp: entry.timestamp,
680
- meta: entry.meta,
681
- memorySize: entry.memorySize
682
- }));
790
+ const normalizedHistory = jsonData.history.map(normalizeHistoryEntry);
791
+ const firstEntry = normalizedHistory[0];
792
+ const instance = new SurveyEditorUndoRedo(firstEntry.kind === "survey-snapshot" ? firstEntry.survey : (() => {
793
+ throw new Error("Invalid object: first history entry must resolve to a survey snapshot");
794
+ })(), jsonData.config, firstEntry.meta, initialAssetsOverride ?? jsonData.initialAssets);
795
+ instance.history = normalizedHistory;
683
796
  instance.currentIndex = jsonData.currentIndex;
797
+ instance._initialAssets = cloneAssets(initialAssetsOverride ?? jsonData.initialAssets);
684
798
  return instance;
685
799
  }
686
800
  };
687
801
  //#endregion
688
802
  //#region src/editor/survey-editor.ts
803
+ function stripAssetsFromSurveySnapshot(survey) {
804
+ const snapshot = structuredCloneMethod(survey);
805
+ delete snapshot.assets;
806
+ return snapshot;
807
+ }
808
+ function mergeSurveySnapshotWithAssets(snapshot, assets) {
809
+ const merged = structuredCloneMethod(snapshot);
810
+ if (assets && Object.keys(assets).length > 0) merged.assets = structuredCloneMethod(assets);
811
+ else delete merged.assets;
812
+ return merged;
813
+ }
689
814
  var SurveyEditor = class SurveyEditor {
690
815
  _survey;
691
816
  _undoRedo;
@@ -695,7 +820,8 @@ var SurveyEditor = class SurveyEditor {
695
820
  this._survey = survey;
696
821
  const { pluginRegistry, ...undoRedoConfig } = config;
697
822
  this._pluginRegistry = pluginRegistry;
698
- this._undoRedo = new SurveyEditorUndoRedo(survey.serialize(), undoRedoConfig, meta);
823
+ const serialized = survey.serialize();
824
+ this._undoRedo = new SurveyEditorUndoRedo(stripAssetsFromSurveySnapshot(serialized), undoRedoConfig, meta, serialized.assets);
699
825
  }
700
826
  /** Returns an immutable copy of the current survey state. */
701
827
  get survey() {
@@ -710,9 +836,13 @@ var SurveyEditor = class SurveyEditor {
710
836
  return this._undoRedo;
711
837
  }
712
838
  commit(meta) {
713
- this._undoRedo.commit(this._survey.serialize(), meta);
839
+ if (!this._hasUncommittedChanges) return;
840
+ this._undoRedo.commit(stripAssetsFromSurveySnapshot(this._survey.serialize()), meta);
714
841
  this._hasUncommittedChanges = false;
715
842
  }
843
+ restoreHistoryState(snapshot, assets) {
844
+ this._survey = Survey.fromJson(mergeSurveySnapshotWithAssets(snapshot, assets), this._pluginRegistry);
845
+ }
716
846
  commitIfNeeded() {
717
847
  if (this._hasUncommittedChanges) this.commit({
718
848
  label: "Latest content changes",
@@ -721,13 +851,13 @@ var SurveyEditor = class SurveyEditor {
721
851
  }
722
852
  undo() {
723
853
  if (this._hasUncommittedChanges) {
724
- this._survey = Survey.fromJson(this._undoRedo.getCurrentState(), this._pluginRegistry);
854
+ this.restoreHistoryState(this._undoRedo.getCurrentState(), this._undoRedo.getCurrentAssets());
725
855
  this._hasUncommittedChanges = false;
726
856
  return true;
727
857
  } else {
728
858
  const previousState = this._undoRedo.undo();
729
859
  if (previousState) {
730
- this._survey = Survey.fromJson(previousState, this._pluginRegistry);
860
+ this.restoreHistoryState(previousState, this._undoRedo.getCurrentAssets());
731
861
  this._hasUncommittedChanges = false;
732
862
  return true;
733
863
  }
@@ -738,7 +868,7 @@ var SurveyEditor = class SurveyEditor {
738
868
  if (this._hasUncommittedChanges) return false;
739
869
  const nextState = this._undoRedo.redo();
740
870
  if (nextState) {
741
- this._survey = Survey.fromJson(nextState, this._pluginRegistry);
871
+ this.restoreHistoryState(nextState, this._undoRedo.getCurrentAssets());
742
872
  this._hasUncommittedChanges = false;
743
873
  return true;
744
874
  }
@@ -751,7 +881,7 @@ var SurveyEditor = class SurveyEditor {
751
881
  if (this._hasUncommittedChanges) return false;
752
882
  const targetState = this._undoRedo.jumpToIndex(targetIndex);
753
883
  if (targetState) {
754
- this._survey = Survey.fromJson(targetState, this._pluginRegistry);
884
+ this.restoreHistoryState(targetState, this._undoRedo.getCurrentAssets());
755
885
  this._hasUncommittedChanges = false;
756
886
  return true;
757
887
  }
@@ -804,8 +934,14 @@ var SurveyEditor = class SurveyEditor {
804
934
  if (typeof jsonData.hasUncommittedChanges !== "boolean") throw new Error("Invalid object: hasUncommittedChanges must be a boolean");
805
935
  if (jsonData.version && !jsonData.version.startsWith("1.")) console.warn(`Warning: Loading SurveyEditor with version ${jsonData.version}, current version is 1.0.0`);
806
936
  const editor = new SurveyEditor(Survey.fromJson(jsonData.survey, pluginRegistry), { pluginRegistry });
807
- editor._undoRedo = SurveyEditorUndoRedo.deserialize(jsonData.undoRedo);
808
- editor._hasUncommittedChanges = jsonData.hasUncommittedChanges;
937
+ editor._undoRedo = SurveyEditorUndoRedo.deserialize({
938
+ ...jsonData.undoRedo,
939
+ history: jsonData.undoRedo.history.map((entry) => "survey" in entry ? {
940
+ ...entry,
941
+ survey: stripAssetsFromSurveySnapshot(entry.survey)
942
+ } : entry)
943
+ }, jsonData.survey.assets);
944
+ editor._hasUncommittedChanges = JSON.stringify(stripAssetsFromSurveySnapshot(jsonData.survey)) !== JSON.stringify(editor._undoRedo.getCurrentState());
809
945
  return editor;
810
946
  }
811
947
  markAsModified() {
@@ -919,8 +1055,8 @@ var SurveyEditor = class SurveyEditor {
919
1055
  this.markAsModified();
920
1056
  }
921
1057
  updateItemTranslations(itemId, updatedContent) {
1058
+ if (!this._survey.surveyItems.get(itemId)) return false;
922
1059
  this.markAsModified();
923
- if (!this._survey.surveyItems.get(itemId)) throw new Error(`Item with id '${itemId}' not found`);
924
1060
  this._survey.translations.setItemTranslations(itemId, updatedContent);
925
1061
  return true;
926
1062
  }
@@ -996,6 +1132,49 @@ var SurveyEditor = class SurveyEditor {
996
1132
  this._survey.deleteTemplateValue(key);
997
1133
  }
998
1134
  /**
1135
+ * Get a survey asset immutably.
1136
+ */
1137
+ getAsset(assetId) {
1138
+ const asset = this._survey.getAsset(assetId);
1139
+ return asset ? structuredCloneMethod(asset) : void 0;
1140
+ }
1141
+ /**
1142
+ * Get all survey assets immutably.
1143
+ */
1144
+ getAssets() {
1145
+ return this._survey.getAssets();
1146
+ }
1147
+ /**
1148
+ * Add or replace a survey asset.
1149
+ */
1150
+ setAsset(assetId, asset) {
1151
+ const previousAsset = this._survey.getAsset(assetId);
1152
+ this._survey.setAsset(assetId, structuredCloneMethod(asset));
1153
+ this._undoRedo.commitAssetChange([{
1154
+ assetId,
1155
+ prev: previousAsset,
1156
+ next: structuredCloneMethod(asset)
1157
+ }], {
1158
+ label: `Update asset: ${assetId}`,
1159
+ source: CommitSource.USER
1160
+ });
1161
+ }
1162
+ /**
1163
+ * Remove a survey asset.
1164
+ */
1165
+ removeAsset(assetId) {
1166
+ const previousAsset = this._survey.getAsset(assetId);
1167
+ if (!previousAsset) return;
1168
+ this._survey.deleteAsset(assetId);
1169
+ this._undoRedo.commitAssetChange([{
1170
+ assetId,
1171
+ prev: previousAsset
1172
+ }], {
1173
+ label: `Remove asset: ${assetId}`,
1174
+ source: CommitSource.USER
1175
+ });
1176
+ }
1177
+ /**
999
1178
  * Copy a survey item and all its data to clipboard format
1000
1179
  * @param itemId - The ID of the item to copy
1001
1180
  * @returns Clipboard data that can be serialized to JSON for clipboard