superdoc 2.28.0-next.12 → 2.28.0-next.14

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,6 +1,6 @@
1
1
  import { i as __toESM$2 } from "./chunks/rolldown-runtime-0pSA04fp.es.js";
2
2
  import { t as blank_default } from "./chunks/blank-docx-DzQccOlW.es.js";
3
- import { _ as createInteractionHistory, a as registerFirstPartyCommandMutation, b as recordInteraction, c as applyV2CommentInvalidationFromMutation, d as createImageFilePicker, f as resolveImageSrc, g as closeInteractionHistory, h as DOM_CLASS_NAMES, i as readFirstPartyPageNumbers, l as getV2TrackedChangeMutationImpact, m as isSyntheticTrackedChangeCommentLaneItem, n as executeFirstPartyCommandAsync, o as isRecord, r as executeFirstPartyShortcutAsync, t as createSuperDocUI, u as isPlainObject$1, v as getWorkflowRecording, y as isWorkflowRecordingEnabled } from "./chunks/create-super-doc-ui-B6Va_J_0.es.js";
3
+ import { _ as createInteractionHistory, a as registerFirstPartyCommandMutation, b as recordInteraction, c as applyV2CommentInvalidationFromMutation, d as createImageFilePicker, f as resolveImageSrc, g as closeInteractionHistory, h as DOM_CLASS_NAMES, i as readFirstPartyPageNumbers, l as getV2TrackedChangeMutationImpact, m as isSyntheticTrackedChangeCommentLaneItem, n as executeFirstPartyCommandAsync, o as isRecord, r as executeFirstPartyShortcutAsync, t as createSuperDocUI, u as isPlainObject$1, v as getWorkflowRecording, y as isWorkflowRecordingEnabled } from "./chunks/create-super-doc-ui-BRahDsch.es.js";
4
4
  import { t as import_eventemitter3 } from "./chunks/eventemitter3-DEIiXiH2.es.js";
5
5
  import { t as v4 } from "./chunks/uuid-H0Xcmmhy.es.js";
6
6
  import { $ as vModelText, A as onActivated, B as renderSlot, C as isRef$1, D as normalizeClass, E as nextTick, F as openBlock, G as toRaw$2, H as resolveDynamicComponent, I as provide$1, J as unref, K as toRef, L as reactive, M as onDeactivated, N as onMounted, O as normalizeProps, P as onScopeDispose$1, Q as vModelSelect, R as ref, S as isReactive$1, T as mergeProps, U as shallowRef$1, V as resolveDirective, W as toDisplayString, X as useSlots, Y as useAttrs, Z as vModelCheckbox, _ as getCurrentInstance, a as computed$1, b as hasInjectionContext, c as createCommentVNode, d as createStaticVNode, et as watch$1, f as createTextVNode, g as effectScope, h as defineComponent, i as Transition, it as withModifiers, j as onBeforeUnmount, k as normalizeStyle, l as createElementBlock, m as defineAsyncComponent, n as Fragment, nt as withDirectives, o as createApp, p as createVNode, q as toRefs, r as Teleport, rt as withKeys, s as createBlock, t as _plugin_vue_export_helper_default, tt as withCtx, u as createElementVNode, v as getCurrentScope, w as markRaw, x as inject$1, y as h, z as renderList } from "./chunks/_plugin-vue_export-helper-7ZiLY07t.es.js";
@@ -258,7 +258,7 @@ var v_click_outside_default = {
258
258
  var DEFAULT_ENDPOINT = "https://ingest.superdoc.dev/v1/collect";
259
259
  function getSuperdocVersion() {
260
260
  try {
261
- return "2.28.0-next.12";
261
+ return "2.28.0-next.14";
262
262
  } catch {
263
263
  return "unknown";
264
264
  }
@@ -6841,87 +6841,6 @@ var useSuperdocStore = defineStore("superdoc", () => {
6841
6841
  };
6842
6842
  });
6843
6843
  //#endregion
6844
- //#region src/helpers/group-changes.js
6845
- /**
6846
- * Track changes helper
6847
- * Combines replace transactions which are represented by insertion + deletion
6848
- *
6849
- * @param {Array} changes - Array of tracked changes from the editor
6850
- * @returns {Array} Grouped track changes array with combined replacements
6851
- */
6852
- var groupChanges = (changes) => {
6853
- const markMetaKeys = {
6854
- trackInsert: "insertedMark",
6855
- trackDelete: "deletionMark",
6856
- trackFormat: "formatMark"
6857
- };
6858
- const byId = /* @__PURE__ */ new Map();
6859
- for (const change of changes) {
6860
- const id = change.mark.attrs.id;
6861
- if (!byId.has(id)) byId.set(id, []);
6862
- byId.get(id).push(change);
6863
- }
6864
- const grouped = [];
6865
- for (const [, group] of byId) {
6866
- if (group.length === 1) {
6867
- const c = group[0];
6868
- const key = markMetaKeys[c.mark.type.name];
6869
- grouped.push({
6870
- from: c.from,
6871
- to: c.to,
6872
- [key]: c
6873
- });
6874
- continue;
6875
- }
6876
- const processed = /* @__PURE__ */ new Set();
6877
- for (let i = 0; i < group.length; i++) {
6878
- if (processed.has(i)) continue;
6879
- const c1 = group[i];
6880
- const c1Key = markMetaKeys[c1.mark.type.name];
6881
- const c2 = group[i + 1];
6882
- if (c2 && !processed.has(i + 1) && c1.to === c2.from && c1.mark.type.name !== c2.mark.type.name) {
6883
- const c2Key = markMetaKeys[c2.mark.type.name];
6884
- grouped.push({
6885
- from: c1.from,
6886
- to: c2.to,
6887
- [c1Key]: c1,
6888
- [c2Key]: c2
6889
- });
6890
- processed.add(i);
6891
- processed.add(i + 1);
6892
- continue;
6893
- }
6894
- let foundMatch = false;
6895
- for (let j = i + 1; j < group.length; j++) {
6896
- if (processed.has(j)) continue;
6897
- const cj = group[j];
6898
- if (c1.mark.type.name !== cj.mark.type.name) {
6899
- const cjKey = markMetaKeys[cj.mark.type.name];
6900
- grouped.push({
6901
- from: Math.min(c1.from, cj.from),
6902
- to: Math.max(c1.to, cj.to),
6903
- [c1Key]: c1,
6904
- [cjKey]: cj
6905
- });
6906
- processed.add(i);
6907
- processed.add(j);
6908
- foundMatch = true;
6909
- break;
6910
- }
6911
- }
6912
- if (!foundMatch) {
6913
- grouped.push({
6914
- from: c1.from,
6915
- to: c1.to,
6916
- [c1Key]: c1
6917
- });
6918
- processed.add(i);
6919
- }
6920
- }
6921
- }
6922
- return grouped;
6923
- };
6924
- //#endregion
6925
6844
  //#region src/stores/helpers/floating-comment-instances.js
6926
6845
  var HEADER_FOOTER_TRACKED_CHANGE_STORY_TYPE = "headerFooterPart";
6927
6846
  var toFinitePageIndex = (value) => {
@@ -7482,20 +7401,6 @@ var buildTrackedChangeDecisionLinkIndex = (allComments, previous = /* @__PURE__
7482
7401
  };
7483
7402
  //#endregion
7484
7403
  //#region src/stores/comments-store.js
7485
- var Editor = class {
7486
- constructor() {
7487
- throw new Error("SuperDoc v2 beta: v1 editor-backed comment import paths are not available.");
7488
- }
7489
- };
7490
- var trackChangesHelpers = {
7491
- getTrackChanges: () => [],
7492
- enumerateStructuralRowChanges: () => []
7493
- };
7494
- var CommentsPluginKey = Symbol("comments-plugin-disabled");
7495
- var getRichTextExtensions = () => [];
7496
- var createOrUpdateTrackedChangeComment = () => null;
7497
- var getTrackedChangeIndex = () => null;
7498
- var resolveTrackedChangeInStory = () => null;
7499
7404
  var makeTrackedChangeAnchorKey = ({ storyKey, rawId }) => `tc::${storyKey}::${rawId}`;
7500
7405
  var COMMENT_DRAFT_BR_TAG = /<br(?:\s[^>]*)?\s*\/?>/gi;
7501
7406
  var COMMENT_DRAFT_BLOCK_BOUNDARY = /(?:<\/(?:p|div|li|blockquote|pre|h[1-6])\s*>\s*)+(?:<(?:p|div|li|blockquote|pre|h[1-6])(?:\s[^>]*)?\s*\/?>)+/gi;
@@ -7640,25 +7545,6 @@ var useCommentsStore = defineStore("comments", () => {
7640
7545
  rawId: String(rawId)
7641
7546
  });
7642
7547
  };
7643
- /**
7644
- * Compute the stable public id for a structural (whole-table) tracked change.
7645
- *
7646
- * This MUST match the public id the document-api projects for the same change
7647
- * (`tracked-change-resolver.groupTrackedChanges`), otherwise the right-rail
7648
- * accept/reject would route `trackChanges.decide` to a change that does not
7649
- * exist. The doc-api derives the public id as `word:structural:<sourceId>`
7650
- * for imported Word revisions, falling back to the per-import logical id.
7651
- * Reuse the exact rule here so the bubble id is the decide id.
7652
- *
7653
- * @param {{ sourceId?: string, id?: string }} structural
7654
- * @returns {string | null}
7655
- */
7656
- const buildStructuralTrackedChangeId = (structural) => {
7657
- if (!structural) return null;
7658
- const sourceId = structural.sourceId ? String(structural.sourceId) : "";
7659
- if (sourceId) return `word:structural:${sourceId}`;
7660
- return structural.id ? String(structural.id) : null;
7661
- };
7662
7548
  const superdocStore = useSuperdocStore();
7663
7549
  const commentsConfig = reactive({
7664
7550
  name: "comments",
@@ -7690,8 +7576,6 @@ var useCommentsStore = defineStore("comments", () => {
7690
7576
  const isDebugging = false;
7691
7577
  const debounceTimers = {};
7692
7578
  const trackedChangeResolutionSnapshots = /* @__PURE__ */ new WeakMap();
7693
- const importedTrackedChangeBootstrapTasks = /* @__PURE__ */ new Map();
7694
- let importedTrackedChangeBootstrapGeneration = 0;
7695
7579
  const isBenchmarkCommentsDebugEnabled = () => {
7696
7580
  if (typeof window === "undefined") return false;
7697
7581
  return "__labsSuperDocV2BenchmarkDebug" in window;
@@ -8076,72 +7960,6 @@ var useCommentsStore = defineStore("comments", () => {
8076
7960
  return source === DOCUMENT_EDITOR_SELECTION_SOURCE;
8077
7961
  };
8078
7962
  const isTrackedChangeThread = (comment) => Boolean(comment?.trackedChange) || Boolean(trackedChangeThreadParentIdForComment$1(comment));
8079
- const syncTrackedChangePositionsWithDocument = ({ documentId, editor } = {}) => {
8080
- if (!editor?.state) return 0;
8081
- if (!commentsList.value?.length) return 0;
8082
- const currentPositions = editorCommentPositions.value || {};
8083
- if (!Object.keys(currentPositions).length) return 0;
8084
- const resolveExistingPositionKey = (aliasIds) => aliasIds.find((key) => currentPositions[key] !== void 0) ?? null;
8085
- const candidateRootPositionKeys = /* @__PURE__ */ new Set();
8086
- const rootAliasesByPositionKey = /* @__PURE__ */ new Map();
8087
- commentsList.value.forEach((comment) => {
8088
- if (!comment?.trackedChange) return;
8089
- if (documentId) {
8090
- const resolvedDocumentId = comment?.fileId ?? null;
8091
- if (resolvedDocumentId && resolvedDocumentId !== documentId) return;
8092
- }
8093
- const aliasIds = getCommentAliasIds(comment);
8094
- const normalizedPositionKey = resolveExistingPositionKey(aliasIds);
8095
- if (!normalizedPositionKey) return;
8096
- candidateRootPositionKeys.add(normalizedPositionKey);
8097
- rootAliasesByPositionKey.set(normalizedPositionKey, new Set(aliasIds));
8098
- });
8099
- if (!candidateRootPositionKeys.size) return 0;
8100
- const trackedIds = new Set(trackChangesHelpers.getTrackChanges(editor.state).map(({ mark }) => mark?.attrs?.id).filter((id) => id !== void 0 && id !== null).map((id) => String(id)));
8101
- const trackedChangeIndex = typeof getTrackedChangeIndex === "function" ? getTrackedChangeIndex(editor) : null;
8102
- let liveAnchorKeySource = [];
8103
- try {
8104
- liveAnchorKeySource = trackedChangeIndex?.getAll?.() ?? [];
8105
- } catch {}
8106
- const liveAnchorKeys = new Set(liveAnchorKeySource.map((snapshot) => snapshot?.anchorKey).filter((anchorKey) => typeof anchorKey === "string" && anchorKey.length > 0));
8107
- const staleRootPositionKeys = new Set(Array.from(candidateRootPositionKeys).filter((positionKey) => {
8108
- const aliases = rootAliasesByPositionKey.get(positionKey) ?? /* @__PURE__ */ new Set([positionKey]);
8109
- if (Array.from(aliases).some((alias) => liveAnchorKeys.has(alias))) return false;
8110
- return !Array.from(aliases).some((alias) => trackedIds.has(alias));
8111
- }));
8112
- if (!staleRootPositionKeys.size) return 0;
8113
- const staleRootAliasIds = /* @__PURE__ */ new Set();
8114
- staleRootPositionKeys.forEach((positionKey) => {
8115
- (rootAliasesByPositionKey.get(positionKey) ?? /* @__PURE__ */ new Set([positionKey])).forEach((alias) => staleRootAliasIds.add(alias));
8116
- });
8117
- const stalePositionKeys = new Set(staleRootPositionKeys);
8118
- commentsList.value.forEach((comment) => {
8119
- const aliasIds = getCommentAliasIds(comment);
8120
- const normalizedPositionKey = resolveExistingPositionKey(aliasIds);
8121
- if (!normalizedPositionKey) return;
8122
- if ([
8123
- trackedChangeThreadParentIdForComment$1(comment),
8124
- comment?.threadingParentCommentId,
8125
- comment?.parentCommentId
8126
- ].map((id) => normalizeCommentId(id)).filter(Boolean).some((id) => staleRootAliasIds.has(id))) stalePositionKeys.add(normalizedPositionKey);
8127
- });
8128
- const nextPositions = { ...currentPositions };
8129
- stalePositionKeys.forEach((key) => {
8130
- delete nextPositions[key];
8131
- });
8132
- editorCommentPositions.value = nextPositions;
8133
- if (activeComment.value !== void 0 && activeComment.value !== null) {
8134
- const activeCommentModel = getComment(activeComment.value);
8135
- const activeAliases = new Set(getCommentAliasIds(activeCommentModel ?? activeComment.value));
8136
- const activeParentKeys = [
8137
- trackedChangeThreadParentIdForComment$1(activeCommentModel),
8138
- activeCommentModel?.threadingParentCommentId,
8139
- activeCommentModel?.parentCommentId
8140
- ].map((id) => normalizeCommentId(id)).filter(Boolean);
8141
- if (Array.from(activeAliases).some((id) => staleRootAliasIds.has(id)) || activeParentKeys.some((id) => staleRootAliasIds.has(id))) clearActiveCommentSelection();
8142
- }
8143
- return stalePositionKeys.size;
8144
- };
8145
7963
  const collectStandardCommentDocumentState = (editor) => {
8146
7964
  const doc = editor?.state?.doc;
8147
7965
  if (!doc || typeof doc.descendants !== "function") return null;
@@ -8323,7 +8141,7 @@ var useCommentsStore = defineStore("comments", () => {
8323
8141
  * @param {Object} param0.params The tracked change params
8324
8142
  * @returns {void}
8325
8143
  */
8326
- const handleTrackedChangeUpdate = ({ superdoc, params, broadcastChanges = true, documentState = void 0, trackedChangeIdentityIndex = null }) => {
8144
+ const handleTrackedChangeUpdate = ({ superdoc, params, broadcastChanges = true, trackedChangeIdentityIndex = null }) => {
8327
8145
  const span = startInteractionSpan("store.trackedChanges.handleUpdate", "store-reconciliation", {
8328
8146
  event: params?.event ?? null,
8329
8147
  changeId: params?.changeId ?? null,
@@ -8340,26 +8158,6 @@ var useCommentsStore = defineStore("comments", () => {
8340
8158
  const normalizedCustomAttributes = hasCustomAttributes ? normalizeTrackedChangeCustomAttributes(customAttributes) : void 0;
8341
8159
  const normalizedImportedId = hasImportedId ? importedId != null ? String(importedId) : null : void 0;
8342
8160
  const normalizedDocumentId = documentId != null ? String(documentId) : null;
8343
- if (!(trackedChangeDisplayType === "tableInsert" || trackedChangeDisplayType === "tableDelete") && normalizedChangeId) {
8344
- const effectiveDocumentId = normalizedDocumentId ?? (superdoc?.activeEditor?.options?.documentId != null ? String(superdoc.activeEditor.options.documentId) : null);
8345
- const docEditor = effectiveDocumentId ? superdocStore.getDocument(effectiveDocumentId)?.getEditor?.() : null;
8346
- const docState = documentState !== void 0 ? documentState : docEditor?.state ?? superdoc?.activeEditor?.state ?? null;
8347
- if (docState) {
8348
- const { ranges: tableRanges, ids: structuralIds } = computeTrackedTableSummaryForState(docState);
8349
- const ranges = trackChangesHelpers.getTrackChanges(docState, normalizedChangeId);
8350
- const inRange = tableRanges.length > 0 && ranges.length > 0 && isInlineRangeInsideTrackedTable(ranges, tableRanges);
8351
- const isStructuralRowIdEcho = ranges.length === 0 && structuralIds.has(normalizedChangeId);
8352
- if (inRange || isStructuralRowIdEcho) {
8353
- pruneSuppressedInlineTableComments({
8354
- suppressedIds: /* @__PURE__ */ new Set([normalizedChangeId]),
8355
- activeDocumentId: effectiveDocumentId,
8356
- superdoc,
8357
- broadcastChanges
8358
- });
8359
- return;
8360
- }
8361
- }
8362
- }
8363
8161
  const hasStoryMetadata = trackedChangeStory !== void 0 || trackedChangeStoryKind !== void 0 || trackedChangeStoryLabel !== void 0 || trackedChangeAnchorKey !== void 0;
8364
8162
  const normalizedTrackedChangeStory = hasStoryMetadata ? trackedChangeStory ?? null : BODY_TRACKED_CHANGE_STORY;
8365
8163
  const normalizedTrackedChangeStoryKind = hasStoryMetadata ? trackedChangeStoryKind ?? null : "body";
@@ -8553,38 +8351,6 @@ var useCommentsStore = defineStore("comments", () => {
8553
8351
  endInteractionSpan(span);
8554
8352
  }
8555
8353
  };
8556
- const collectTrackedChangeMarksByType = (trackedChanges = []) => ({
8557
- insertedMark: trackedChanges.find(({ mark }) => mark?.type?.name === "trackInsert")?.mark ?? null,
8558
- deletionMark: trackedChanges.find(({ mark }) => mark?.type?.name === "trackDelete")?.mark ?? null,
8559
- formatMark: trackedChanges.find(({ mark }) => mark?.type?.name === "trackFormat")?.mark ?? null
8560
- });
8561
- const refreshTrackedChangeCommentsByIds = ({ superdoc, editor, changeIds, broadcastChanges = true }) => {
8562
- if (!superdoc || !editor?.state || !Array.isArray(changeIds) || !changeIds.length) return;
8563
- const documentId = editor?.options?.documentId != null ? String(editor.options.documentId) : null;
8564
- if (!documentId) return;
8565
- for (const changeId of new Set(changeIds.map((id) => id != null ? String(id) : null).filter(Boolean))) {
8566
- const trackedChangesForId = trackChangesHelpers.getTrackChanges(editor.state, changeId);
8567
- if (!trackedChangesForId.length) continue;
8568
- const params = createOrUpdateTrackedChangeComment({
8569
- event: "update",
8570
- marks: collectTrackedChangeMarksByType(trackedChangesForId),
8571
- nodes: [],
8572
- newEditorState: editor.state,
8573
- documentId,
8574
- trackedChangesForId
8575
- });
8576
- if (!params) continue;
8577
- params.trackedChangeStory = BODY_TRACKED_CHANGE_STORY;
8578
- params.trackedChangeStoryKind = "body";
8579
- params.trackedChangeStoryLabel = "";
8580
- params.trackedChangeAnchorKey = buildBodyTrackedChangeAnchorKey(params.changeId ?? changeId);
8581
- handleTrackedChangeUpdate({
8582
- superdoc,
8583
- params,
8584
- broadcastChanges
8585
- });
8586
- }
8587
- };
8588
8354
  const requestInstantSidebarAlignment = (targetY = null, threadId = null, instanceId = null) => {
8589
8355
  const hasTargetY = Number.isFinite(targetY);
8590
8356
  instantSidebarAlignmentTargetY.value = hasTargetY ? targetY : null;
@@ -10194,178 +9960,6 @@ var useCommentsStore = defineStore("comments", () => {
10194
9960
  removePendingComment(superdoc);
10195
9961
  };
10196
9962
  /**
10197
- * Imported DOCX comments can omit the normalized author string.
10198
- * Strip the exporter suffix when present and tolerate missing metadata.
10199
- *
10200
- * @param {string | null | undefined} creatorName
10201
- * @returns {string | null}
10202
- */
10203
- const normalizeImportedCreatorName = (creatorName) => {
10204
- if (typeof creatorName !== "string") return null;
10205
- return creatorName.replace(/\s*\(imported\)\s*$/u, "").trim() || null;
10206
- };
10207
- /**
10208
- * Read the mounted editor view and state without touching `editor.state`.
10209
- * The editor convenience getter delegates to `view.state` and throws after
10210
- * teardown, which is precisely when a deferred import callback can run.
10211
- *
10212
- * @param {Object | null | undefined} editor
10213
- * @returns {{ view: Object, state: Object } | null}
10214
- */
10215
- const readMountedEditorSnapshot = (editor) => {
10216
- if (!editor) return null;
10217
- try {
10218
- if (editor.isDestroyed === true) return null;
10219
- const view = editor.view;
10220
- if (!view || view.isDestroyed === true || view.destroyed === true) return null;
10221
- const state = view.state;
10222
- if (!state) return null;
10223
- return {
10224
- view,
10225
- state
10226
- };
10227
- } catch {
10228
- return null;
10229
- }
10230
- };
10231
- const normalizeBootstrapDocumentId = (documentId) => documentId !== void 0 && documentId !== null && String(documentId).length > 0 ? String(documentId) : null;
10232
- /**
10233
- * Cancel deferred imported tracked-change comment work. Passing a document
10234
- * id cancels only that document; omitting it cancels every pending task.
10235
- *
10236
- * @param {string | null | undefined} documentId
10237
- * @returns {number} number of invalidated tasks
10238
- */
10239
- const cancelImportedTrackedChangeBootstrap = (documentId) => {
10240
- const normalizedDocumentId = normalizeBootstrapDocumentId(documentId);
10241
- const entries = normalizedDocumentId ? [[normalizedDocumentId, importedTrackedChangeBootstrapTasks.get(normalizedDocumentId)]] : Array.from(importedTrackedChangeBootstrapTasks.entries());
10242
- let canceled = 0;
10243
- for (const [taskDocumentId, task] of entries) {
10244
- if (!task) continue;
10245
- importedTrackedChangeBootstrapTasks.delete(taskDocumentId);
10246
- if (task.timeoutHandle !== null && task.timeoutHandle !== void 0) clearTimeout(task.timeoutHandle);
10247
- canceled += 1;
10248
- }
10249
- return canceled;
10250
- };
10251
- const captureImportedTrackedChangeBootstrapSnapshot = (editor) => {
10252
- const mountedEditor = readMountedEditorSnapshot(editor);
10253
- if (!mountedEditor) return null;
10254
- let trackedChanges = [];
10255
- try {
10256
- trackedChanges = trackChangesHelpers.getTrackChanges(mountedEditor.state) ?? [];
10257
- } catch {
10258
- return null;
10259
- }
10260
- const enumerateStructuralChanges = trackChangesHelpers?.enumerateStructuralRowChanges;
10261
- let structuralChanges = [];
10262
- if (typeof enumerateStructuralChanges === "function") try {
10263
- structuralChanges = enumerateStructuralChanges(mountedEditor.state) ?? [];
10264
- } catch {
10265
- structuralChanges = [];
10266
- }
10267
- let storySnapshots = [];
10268
- if (typeof getTrackedChangeIndex === "function") try {
10269
- storySnapshots = getTrackedChangeIndex(editor)?.getAll?.() ?? [];
10270
- } catch {
10271
- storySnapshots = [];
10272
- }
10273
- return {
10274
- ...mountedEditor,
10275
- trackedChanges,
10276
- structuralChanges,
10277
- storySnapshots
10278
- };
10279
- };
10280
- /**
10281
- * Bootstrap tracked-change comment threads after a DOCX import finishes.
10282
- *
10283
- * Initial import historically rebuilt only body tracked-change threads so
10284
- * resolved imported body comments stayed resolved. Header/footer and note
10285
- * tracked changes live outside the body PM state, so they need an additional
10286
- * story-aware bootstrap pass here.
10287
- *
10288
- * We intentionally keep the existing body-only rebuild instead of switching
10289
- * to the broader syncTrackedChangeComments() path so imported resolved body
10290
- * tracked-change threads preserve their initial resolved state.
10291
- *
10292
- * @param {Object | null | undefined} editor
10293
- * @param {Object | null | undefined} superdoc
10294
- * @param {Object | null | undefined} snapshot
10295
- * @returns {boolean}
10296
- */
10297
- const bootstrapImportedTrackedChangeComments = (editor, superdoc, snapshot = null) => {
10298
- if (!editor || !superdoc) return false;
10299
- const captured = snapshot ?? captureImportedTrackedChangeBootstrapSnapshot(editor);
10300
- if (!captured) return false;
10301
- createCommentForTrackChanges(editor, superdoc, captured.trackedChanges, {
10302
- editorState: captured.state,
10303
- editorView: captured.view
10304
- });
10305
- syncStoryTrackedChangeComments({
10306
- superdoc,
10307
- editor,
10308
- snapshots: captured.storySnapshots,
10309
- documentState: captured.state,
10310
- resolveFromEditor: false
10311
- });
10312
- syncStructuralTrackedChangeComments({
10313
- superdoc,
10314
- editor,
10315
- structuralChanges: captured.structuralChanges
10316
- });
10317
- return true;
10318
- };
10319
- const isCurrentImportedTrackedChangeBootstrap = (task) => {
10320
- if (!task) return false;
10321
- if (importedTrackedChangeBootstrapTasks.get(task.documentId) !== task) return false;
10322
- try {
10323
- const editorDocumentId = task.editor?.options?.documentId;
10324
- if (editorDocumentId != null && String(editorDocumentId) !== task.documentId) return false;
10325
- const mountedDocument = superdocStore.getDocument(task.documentId);
10326
- if (!mountedDocument) return false;
10327
- if (mountedDocument.getEditor?.() !== task.editor) return false;
10328
- } catch {
10329
- return false;
10330
- }
10331
- return true;
10332
- };
10333
- const runImportedTrackedChangeBootstrap = (task) => {
10334
- if (!isCurrentImportedTrackedChangeBootstrap(task)) {
10335
- if (importedTrackedChangeBootstrapTasks.get(task?.documentId) === task) importedTrackedChangeBootstrapTasks.delete(task.documentId);
10336
- return false;
10337
- }
10338
- const snapshot = captureImportedTrackedChangeBootstrapSnapshot(task.editor);
10339
- if (!snapshot || !isCurrentImportedTrackedChangeBootstrap(task)) {
10340
- if (importedTrackedChangeBootstrapTasks.get(task.documentId) === task) importedTrackedChangeBootstrapTasks.delete(task.documentId);
10341
- return false;
10342
- }
10343
- try {
10344
- return bootstrapImportedTrackedChangeComments(task.editor, task.superdoc, snapshot);
10345
- } finally {
10346
- if (importedTrackedChangeBootstrapTasks.get(task.documentId) === task) importedTrackedChangeBootstrapTasks.delete(task.documentId);
10347
- }
10348
- };
10349
- const scheduleImportedTrackedChangeBootstrap = ({ editor, superdoc, documentId, defer = true }) => {
10350
- const normalizedDocumentId = normalizeBootstrapDocumentId(documentId);
10351
- if (!normalizedDocumentId || !editor || !superdoc) return false;
10352
- cancelImportedTrackedChangeBootstrap(normalizedDocumentId);
10353
- const task = {
10354
- documentId: normalizedDocumentId,
10355
- editor,
10356
- superdoc,
10357
- generation: ++importedTrackedChangeBootstrapGeneration,
10358
- timeoutHandle: null
10359
- };
10360
- importedTrackedChangeBootstrapTasks.set(normalizedDocumentId, task);
10361
- if (!defer) return runImportedTrackedChangeBootstrap(task);
10362
- task.timeoutHandle = setTimeout(() => {
10363
- task.timeoutHandle = null;
10364
- runImportedTrackedChangeBootstrap(task);
10365
- }, 0);
10366
- return true;
10367
- };
10368
- /**
10369
9963
  * Drop imported threads and cached positions for one document id.
10370
9964
  *
10371
9965
  * Replace-file swaps call this before hydrating the replacement so stale
@@ -10382,7 +9976,6 @@ var useCommentsStore = defineStore("comments", () => {
10382
9976
  delete next[activeDocumentId];
10383
9977
  committedReviewPresentations.value = next;
10384
9978
  }
10385
- cancelImportedTrackedChangeBootstrap(activeDocumentId);
10386
9979
  const removedComments = commentsList.value.filter((comment) => belongsToDocument(comment, activeDocumentId, { allowSingleDocumentMismatch: true }));
10387
9980
  if (!removedComments.length) return;
10388
9981
  const removedAliasIds = /* @__PURE__ */ new Set();
@@ -10400,217 +9993,6 @@ var useCommentsStore = defineStore("comments", () => {
10400
9993
  const activeCommentId = activeComment.value != null ? String(activeComment.value) : null;
10401
9994
  if (activeCommentId && removedAliasIds.has(activeCommentId)) clearActiveCommentSelection();
10402
9995
  }
10403
- function resetCommentsForReplacedDocument(documentId) {
10404
- removeCommentsForDocument(documentId);
10405
- }
10406
- /**
10407
- * Initialize loaded comments into SuperDoc by mapping the imported
10408
- * comment data to SuperDoc useComment objects.
10409
- *
10410
- * Updates the commentsList ref with the new comments.
10411
- *
10412
- * @param {Object} param0
10413
- * @param {Array} param0.comments The comments to be loaded
10414
- * @param {String} param0.documentId The document ID
10415
- * @param {boolean} [param0.replacedFile] Whether this load replaces an existing document in place
10416
- * @returns {void}
10417
- */
10418
- const processLoadedDocxComments = async ({ superdoc, editor, comments, documentId, replacedFile = false }) => {
10419
- const document = superdocStore.getDocument(documentId);
10420
- if (document?.commentThreadingProfile) document.commentThreadingProfile.value = editor?.converter?.commentThreadingProfile || null;
10421
- if (replacedFile) resetCommentsForReplacedDocument(documentId);
10422
- comments.forEach((comment) => {
10423
- const textElements = Array.isArray(comment.elements) ? comment.elements : [];
10424
- const htmlContent = getHtmlFromComment(textElements);
10425
- if (!htmlContent && !comment.trackedChange) return;
10426
- const creatorName = normalizeImportedCreatorName(comment.creatorName);
10427
- const importedName = creatorName ? `${creatorName} (imported)` : null;
10428
- const newComment = useComment({
10429
- fileId: documentId,
10430
- fileType: document.type,
10431
- docxCommentJSON: textElements.length ? textElements : null,
10432
- commentId: comment.commentId,
10433
- isInternal: false,
10434
- parentCommentId: comment.parentCommentId,
10435
- trackedChangeParentId: comment.trackedChangeParentId,
10436
- trackedChangeThreadParentId: comment.trackedChangeThreadParentId,
10437
- creatorId: null,
10438
- creatorName,
10439
- createdTime: comment.createdTime,
10440
- creatorEmail: comment.creatorEmail,
10441
- importedAuthor: {
10442
- ...importedName ? { name: importedName } : {},
10443
- email: comment.creatorEmail
10444
- },
10445
- commentText: htmlContent,
10446
- resolvedTime: comment.isDone ? Date.now() : null,
10447
- resolvedById: null,
10448
- resolvedByEmail: comment.isDone ? comment.creatorEmail : null,
10449
- resolvedByName: comment.isDone ? importedName || "(Imported)" : null,
10450
- trackedChange: comment.trackedChange || false,
10451
- trackedChangeText: comment.trackedChangeText,
10452
- trackedChangeType: comment.trackedChangeType,
10453
- trackedChangeDisplayType: comment.trackedChangeDisplayType,
10454
- deletedText: comment.trackedDeletedText,
10455
- origin: comment.origin || "word",
10456
- threadingMethod: comment.threadingMethod,
10457
- threadingStyleOverride: comment.threadingStyleOverride,
10458
- threadingParentCommentId: comment.threadingParentCommentId,
10459
- originalXmlStructure: comment.originalXmlStructure
10460
- });
10461
- addHydratedComment({
10462
- superdoc,
10463
- comment: newComment
10464
- });
10465
- });
10466
- if (replacedFile) {
10467
- scheduleImportedTrackedChangeBootstrap({
10468
- editor,
10469
- superdoc,
10470
- documentId,
10471
- defer: false
10472
- });
10473
- return;
10474
- }
10475
- scheduleImportedTrackedChangeBootstrap({
10476
- editor,
10477
- superdoc,
10478
- documentId
10479
- });
10480
- };
10481
- const createCommentForTrackChanges = (editor, superdoc, trackedChangesOverride = null, options = {}) => {
10482
- const { reopenResolved = false, refreshExisting = false, broadcastChanges = true, editorState: editorStateOverride = null, editorView: editorViewOverride = null } = options;
10483
- const mountedEditor = editorStateOverride ? {
10484
- state: editorStateOverride,
10485
- view: editorViewOverride
10486
- } : readMountedEditorSnapshot(editor);
10487
- if (!mountedEditor?.state) return;
10488
- const editorState = mountedEditor.state;
10489
- const trackedChanges = trackedChangesOverride ?? trackChangesHelpers.getTrackChanges(editorState);
10490
- const groupedChanges = groupChanges(trackedChanges);
10491
- const activeDocumentId = editor?.options?.documentId != null ? String(editor.options.documentId) : null;
10492
- if (!activeDocumentId) return;
10493
- const skipIds = /* @__PURE__ */ new Set();
10494
- const existingTrackedChangeById = /* @__PURE__ */ new Map();
10495
- commentsList.value.forEach((comment) => {
10496
- if (!comment?.trackedChange) return;
10497
- if (!belongsToTrackedChangeSyncDocument(comment, activeDocumentId)) return;
10498
- if (!isBodyTrackedChangeComment(comment)) return;
10499
- const commentIds = [comment.commentId, comment.importedId].map((id) => id != null ? String(id) : null).filter(Boolean);
10500
- if (comment.resolvedTime) {
10501
- if (!reopenResolved) commentIds.forEach((id) => skipIds.add(id));
10502
- return;
10503
- }
10504
- commentIds.forEach((id) => {
10505
- existingTrackedChangeById.set(id, comment);
10506
- if (!refreshExisting) skipIds.add(id);
10507
- });
10508
- });
10509
- const changesByIdMap = /* @__PURE__ */ new Map();
10510
- for (const change of trackedChanges) {
10511
- const id = change.mark.attrs.id;
10512
- if (!changesByIdMap.has(id)) changesByIdMap.set(id, []);
10513
- changesByIdMap.get(id).push(change);
10514
- }
10515
- const documentId = activeDocumentId;
10516
- const processedIds = /* @__PURE__ */ new Set();
10517
- groupedChanges.forEach(({ insertedMark, deletionMark, formatMark }) => {
10518
- const id = insertedMark?.mark.attrs.id || deletionMark?.mark.attrs.id || formatMark?.mark.attrs.id;
10519
- if (id == null) return;
10520
- const normalizedId = String(id);
10521
- if (processedIds.has(normalizedId)) return;
10522
- processedIds.add(normalizedId);
10523
- if (!refreshExisting && skipIds.has(normalizedId)) return;
10524
- const existingTrackedChange = existingTrackedChangeById.get(normalizedId);
10525
- const marks = {
10526
- ...insertedMark && { insertedMark: insertedMark.mark },
10527
- ...deletionMark && { deletionMark: deletionMark.mark },
10528
- ...formatMark && { formatMark: formatMark.mark }
10529
- };
10530
- const params = createOrUpdateTrackedChangeComment({
10531
- event: existingTrackedChange ? "update" : "add",
10532
- marks,
10533
- nodes: [],
10534
- newEditorState: editorState,
10535
- documentId,
10536
- trackedChangesForId: changesByIdMap.get(id) || []
10537
- });
10538
- if (params) {
10539
- const anchorKey = buildBodyTrackedChangeAnchorKey(params.changeId ?? id);
10540
- params.trackedChangeStory = BODY_TRACKED_CHANGE_STORY;
10541
- params.trackedChangeStoryKind = "body";
10542
- params.trackedChangeStoryLabel = "";
10543
- params.trackedChangeAnchorKey = anchorKey;
10544
- handleTrackedChangeUpdate({
10545
- superdoc,
10546
- params,
10547
- broadcastChanges,
10548
- documentState: editorState
10549
- });
10550
- if (!existingTrackedChange) {
10551
- skipIds.add(normalizedId);
10552
- if (params.changeId != null) skipIds.add(String(params.changeId));
10553
- if (params.importedId != null) skipIds.add(String(params.importedId));
10554
- }
10555
- }
10556
- });
10557
- const editorView = mountedEditor.view;
10558
- try {
10559
- if (!editorView || editor.view !== editorView || editorView.isDestroyed === true || editorView.destroyed === true) return;
10560
- } catch {
10561
- return;
10562
- }
10563
- const { tr } = editorState;
10564
- tr.setMeta(CommentsPluginKey, { type: "force" });
10565
- editorView.dispatch(tr);
10566
- };
10567
- /**
10568
- * Remove inline tracked-change comments whose change id is subsumed by a
10569
- * tracked whole-table change. Mirrors the deletion-event emission of
10570
- * `pruneStaleTrackedChangeComments` but is keyed on an explicit suppressed-id
10571
- * set rather than mark liveness (the mark is still live; only the review item
10572
- * is unwanted). Also clears the active-comment selection if it pointed at a
10573
- * now-suppressed change, so no stale active-on-click dialog can reference it.
10574
- *
10575
- * @param {{ suppressedIds: Set<string>, activeDocumentId: string, superdoc: any, broadcastChanges?: boolean }} input
10576
- */
10577
- const pruneSuppressedInlineTableComments = ({ suppressedIds, activeDocumentId, superdoc = null, broadcastChanges = true }) => {
10578
- if (!(suppressedIds instanceof Set) || !suppressedIds.size || !activeDocumentId) return;
10579
- const removedComments = [];
10580
- commentsList.value = commentsList.value.filter((comment) => {
10581
- if (!comment?.trackedChange) return true;
10582
- if (!isBodyTrackedChangeComment(comment)) return true;
10583
- if (isStructuralTableBubble(comment)) return true;
10584
- if (!belongsToTrackedChangeSyncDocument(comment, activeDocumentId)) return true;
10585
- const commentId = comment.commentId != null ? String(comment.commentId) : null;
10586
- const importedId = comment.importedId != null ? String(comment.importedId) : null;
10587
- if (!(commentId && suppressedIds.has(commentId) || importedId && suppressedIds.has(importedId))) return true;
10588
- removedComments.push(comment);
10589
- return false;
10590
- });
10591
- if (!removedComments.length) return;
10592
- const removedIds = /* @__PURE__ */ new Set();
10593
- removedComments.forEach((comment) => {
10594
- if (comment.commentId != null) removedIds.add(String(comment.commentId));
10595
- if (comment.importedId != null) removedIds.add(String(comment.importedId));
10596
- const payload = getCommentEventPayload(comment);
10597
- const event = {
10598
- type: COMMENT_EVENTS.DELETED,
10599
- comment: payload,
10600
- changes: [{
10601
- key: "deleted",
10602
- commentId: payload.commentId,
10603
- fileId: payload.fileId
10604
- }]
10605
- };
10606
- if (broadcastChanges) {
10607
- syncCommentsToClients(superdoc, event);
10608
- superdoc?.emit?.("comments-update", event);
10609
- }
10610
- });
10611
- const activeCommentId = activeComment.value != null ? String(activeComment.value) : null;
10612
- if (activeCommentId && removedIds.has(activeCommentId)) clearActiveCommentSelection();
10613
- };
10614
9996
  const getCommentDocumentId = (comment) => {
10615
9997
  if (!comment) return null;
10616
9998
  if (comment.fileId != null) return String(comment.fileId);
@@ -11466,286 +10848,6 @@ var useCommentsStore = defineStore("comments", () => {
11466
10848
  return rowDocumentId != null && String(rowDocumentId) === normalizedDocumentId;
11467
10849
  }).length;
11468
10850
  };
11469
- const syncTrackedChangeComments = ({ superdoc, editor, broadcastChanges = true }) => {
11470
- if (!superdoc || !editor) return;
11471
- const activeDocumentId = editor?.options?.documentId != null ? String(editor.options.documentId) : null;
11472
- if (!activeDocumentId) return;
11473
- const captured = captureImportedTrackedChangeBootstrapSnapshot(editor);
11474
- if (!captured) return;
11475
- const trackedChanges = captured.trackedChanges;
11476
- const liveTrackedChangeIds = /* @__PURE__ */ new Set();
11477
- trackedChanges.forEach((change) => {
11478
- const id = change?.mark?.attrs?.id;
11479
- if (id == null) return;
11480
- liveTrackedChangeIds.add(String(id));
11481
- });
11482
- const storySnapshots = captured.storySnapshots;
11483
- const liveTrackedChangeAnchorKeys = new Set(storySnapshots.map((snapshot) => snapshot?.anchorKey).filter((anchorKey) => typeof anchorKey === "string" && anchorKey.length > 0));
11484
- pruneStaleTrackedChangeComments(liveTrackedChangeIds, liveTrackedChangeAnchorKeys, activeDocumentId, superdoc, { broadcastChanges });
11485
- createCommentForTrackChanges(editor, superdoc, trackedChanges, {
11486
- reopenResolved: true,
11487
- refreshExisting: true,
11488
- broadcastChanges,
11489
- editorState: captured.state,
11490
- editorView: captured.view
11491
- });
11492
- syncStoryTrackedChangeComments({
11493
- superdoc,
11494
- editor,
11495
- broadcastChanges,
11496
- snapshots: storySnapshots,
11497
- documentState: captured.state
11498
- });
11499
- syncStructuralTrackedChangeComments({
11500
- superdoc,
11501
- editor,
11502
- broadcastChanges,
11503
- structuralChanges: captured.structuralChanges
11504
- });
11505
- };
11506
- /**
11507
- * Surface decidable whole-table structural tracked changes (table insert /
11508
- * table delete) as right-rail bubbles, mirroring the inline tracked-change
11509
- * path. Structural row revisions live on node attrs (not inline marks), so
11510
- * the inline `getTrackChanges` enumerator never sees them — they are
11511
- * enumerated separately here.
11512
- *
11513
- * Only `decidable` whole-table changes are surfaced; partial/mixed shapes are
11514
- * not actionable (the decision engine fails them closed) so they get no
11515
- * bubble. The bubble id is the document-api public id so accept/reject in the
11516
- * sidebar routes `trackChanges.decide` to the same change.
11517
- *
11518
- * Positioning: the bubble carries a body-story anchorKey (matching the
11519
- * tracked-change index snapshot) and a body PM range (table start/end). The
11520
- * DocumentRendererRuntime position pass emits a body-story position entry for that
11521
- * anchorKey, whose bounds resolve through the same `getRangeRects` path inline
11522
- * body comments/TC use — so it lines up with the table in layout-engine
11523
- * viewing mode.
11524
- */
11525
- const syncStructuralTrackedChangeComments = ({ superdoc, editor, broadcastChanges = true, structuralChanges: structuralChangesOverride = null }) => {
11526
- const activeDocumentId = editor?.options?.documentId != null ? String(editor.options.documentId) : null;
11527
- if (!activeDocumentId) return;
11528
- const enumerate = trackChangesHelpers?.enumerateStructuralRowChanges;
11529
- if (typeof enumerate !== "function") return;
11530
- let structuralChanges = structuralChangesOverride;
11531
- if (!Array.isArray(structuralChanges)) {
11532
- const mountedEditor = readMountedEditorSnapshot(editor);
11533
- if (!mountedEditor) return;
11534
- try {
11535
- structuralChanges = enumerate(mountedEditor.state) ?? [];
11536
- } catch {
11537
- structuralChanges = [];
11538
- }
11539
- }
11540
- for (const structural of structuralChanges) {
11541
- if (!structural?.decidable || !structural?.wholeTable) continue;
11542
- const publicId = buildStructuralTrackedChangeId(structural);
11543
- if (!publicId) continue;
11544
- const anchorKey = buildBodyTrackedChangeAnchorKey(publicId);
11545
- const displayType = structural.subtype === "table-insert" ? "tableInsert" : "tableDelete";
11546
- const trackedChangeType = structural.side === "insertion" ? "trackInsert" : "trackDelete";
11547
- const normalizedPublicId = String(publicId);
11548
- const normalizedAnchorKey = anchorKey != null ? String(anchorKey) : null;
11549
- const params = {
11550
- event: commentsList.value.find((comment) => {
11551
- if (!comment?.trackedChange) return false;
11552
- if (!belongsToTrackedChangeSyncDocument(comment, activeDocumentId)) return false;
11553
- const commentAnchorKey = comment.trackedChangeAnchorKey != null ? String(comment.trackedChangeAnchorKey) : null;
11554
- if (normalizedAnchorKey && commentAnchorKey) return commentAnchorKey === normalizedAnchorKey;
11555
- const commentId = comment.commentId != null ? String(comment.commentId) : null;
11556
- const importedId = comment.importedId != null ? String(comment.importedId) : null;
11557
- return commentId === normalizedPublicId || importedId === normalizedPublicId;
11558
- }) ? "update" : "add",
11559
- changeId: publicId,
11560
- trackedChangeText: "",
11561
- trackedChangeType,
11562
- trackedChangeDisplayType: displayType,
11563
- deletedText: null,
11564
- authorId: null,
11565
- authorEmail: structural.authorEmail || null,
11566
- authorImage: structural.authorImage || null,
11567
- date: structural.date || null,
11568
- author: structural.author || null,
11569
- importedAuthor: structural.importedAuthor ? { name: structural.importedAuthor } : null,
11570
- semanticColorKey: structural.semanticColorKey ?? null,
11571
- semanticColor: structural.semanticColor ?? null,
11572
- documentId: activeDocumentId,
11573
- coords: null,
11574
- trackedChangeStory: BODY_TRACKED_CHANGE_STORY,
11575
- trackedChangeStoryKind: "body",
11576
- trackedChangeStoryLabel: "",
11577
- trackedChangeAnchorKey: anchorKey
11578
- };
11579
- handleTrackedChangeUpdate({
11580
- superdoc,
11581
- params,
11582
- broadcastChanges
11583
- });
11584
- }
11585
- };
11586
- const syncStoryTrackedChangeComments = ({ superdoc, editor, broadcastChanges = true, snapshots = null, documentState = void 0, resolveFromEditor = true }) => {
11587
- const activeDocumentId = editor?.options?.documentId != null ? String(editor.options.documentId) : null;
11588
- if (!activeDocumentId) return;
11589
- let resolvedSnapshots = snapshots;
11590
- if (!Array.isArray(resolvedSnapshots)) {
11591
- if (typeof getTrackedChangeIndex !== "function") return;
11592
- if (!readMountedEditorSnapshot(editor)) return;
11593
- let index = null;
11594
- try {
11595
- index = getTrackedChangeIndex(editor);
11596
- } catch {
11597
- return;
11598
- }
11599
- if (!index) return;
11600
- try {
11601
- resolvedSnapshots = index.getAll();
11602
- } catch {
11603
- return;
11604
- }
11605
- }
11606
- for (const snapshot of resolvedSnapshots) {
11607
- if (snapshot.storyKind === "body") continue;
11608
- upsertStoryTrackedChangeComment({
11609
- superdoc,
11610
- editor,
11611
- snapshot,
11612
- documentId: activeDocumentId,
11613
- broadcastChanges,
11614
- documentState,
11615
- resolveFromEditor
11616
- });
11617
- }
11618
- };
11619
- const getStoryTrackedChangeDisplayType = (snapshot) => {
11620
- if (snapshot?.type !== "structural") return snapshot?.type ?? null;
11621
- return snapshot?.subtype === "table-delete" ? "tableDelete" : "tableInsert";
11622
- };
11623
- const getStoryTrackedChangeType = (snapshot) => {
11624
- if (snapshot?.type !== "structural") return snapshot?.type ?? null;
11625
- return snapshot?.subtype === "table-delete" ? "trackDelete" : "trackInsert";
11626
- };
11627
- const isStoryTrackedChangeDeletion = (snapshot) => {
11628
- if (!snapshot) return false;
11629
- if (snapshot.type === "delete") return true;
11630
- return snapshot.type === "structural" && snapshot.subtype === "table-delete";
11631
- };
11632
- const buildStoryTrackedChangeParams = ({ editor, snapshot, documentId, event, resolveFromEditor = true }) => {
11633
- const trackedChangeType = getStoryTrackedChangeType(snapshot);
11634
- const trackedChangeDisplayType = getStoryTrackedChangeDisplayType(snapshot);
11635
- const fallbackParams = {
11636
- event,
11637
- changeId: snapshot.runtimeRef.rawId,
11638
- trackedChangeText: isStoryTrackedChangeDeletion(snapshot) ? "" : snapshot.excerpt ?? "",
11639
- trackedChangeType,
11640
- trackedChangeDisplayType,
11641
- semanticColorKey: snapshot.semanticColorKey ?? null,
11642
- semanticColor: snapshot.semanticColor ?? null,
11643
- deletedText: isStoryTrackedChangeDeletion(snapshot) ? snapshot.excerpt ?? "" : null,
11644
- authorId: snapshot.authorId,
11645
- authorEmail: snapshot.authorEmail,
11646
- authorImage: snapshot.authorImage,
11647
- date: snapshot.date,
11648
- author: snapshot.author,
11649
- documentId,
11650
- coords: null,
11651
- trackedChangeStory: snapshot.story,
11652
- trackedChangeStoryKind: snapshot.storyKind,
11653
- trackedChangeStoryLabel: snapshot.storyLabel,
11654
- trackedChangeAnchorKey: snapshot.anchorKey
11655
- };
11656
- if (!resolveFromEditor || typeof resolveTrackedChangeInStory !== "function") return fallbackParams;
11657
- let resolvedChange = null;
11658
- try {
11659
- resolvedChange = resolveTrackedChangeInStory(editor, {
11660
- kind: "entity",
11661
- entityType: "trackedChange",
11662
- entityId: snapshot.runtimeRef.rawId,
11663
- story: snapshot.story
11664
- });
11665
- } catch {
11666
- resolvedChange = null;
11667
- }
11668
- const storyEditorState = resolvedChange?.editor?.state ?? null;
11669
- if (!storyEditorState) return fallbackParams;
11670
- let trackedChangesForId = [];
11671
- try {
11672
- trackedChangesForId = trackChangesHelpers.getTrackChanges(storyEditorState, resolvedChange.change.rawId) ?? [];
11673
- } catch {
11674
- trackedChangesForId = [];
11675
- }
11676
- const resolvedParams = createOrUpdateTrackedChangeComment({
11677
- event,
11678
- marks: collectTrackedChangeMarksByType(trackedChangesForId),
11679
- nodes: [],
11680
- newEditorState: storyEditorState,
11681
- documentId,
11682
- trackedChangesForId
11683
- });
11684
- if (!resolvedParams) return fallbackParams;
11685
- if (resolvedParams.semanticColorKey == null && snapshot.semanticColorKey != null) resolvedParams.semanticColorKey = snapshot.semanticColorKey;
11686
- if (resolvedParams.semanticColor == null && snapshot.semanticColor != null) resolvedParams.semanticColor = snapshot.semanticColor;
11687
- resolvedParams.trackedChangeStory = snapshot.story;
11688
- resolvedParams.trackedChangeStoryKind = snapshot.storyKind;
11689
- resolvedParams.trackedChangeStoryLabel = snapshot.storyLabel;
11690
- resolvedParams.trackedChangeAnchorKey = snapshot.anchorKey;
11691
- return resolvedParams;
11692
- };
11693
- const upsertStoryTrackedChangeComment = ({ superdoc, editor, snapshot, documentId, broadcastChanges, documentState, resolveFromEditor }) => {
11694
- if (!snapshot?.runtimeRef?.rawId) return;
11695
- const existingComment = commentsList.value.find((comment) => {
11696
- if (!comment?.trackedChange) return false;
11697
- const commentAnchorKey = comment.trackedChangeAnchorKey != null ? String(comment.trackedChangeAnchorKey) : null;
11698
- if (commentAnchorKey && snapshot.anchorKey) return commentAnchorKey === snapshot.anchorKey;
11699
- if (commentAnchorKey || snapshot.anchorKey) return false;
11700
- return comment.commentId === snapshot.runtimeRef.rawId || comment.importedId === snapshot.runtimeRef.rawId;
11701
- });
11702
- const params = buildStoryTrackedChangeParams({
11703
- editor,
11704
- snapshot,
11705
- documentId,
11706
- event: existingComment ? "update" : "add",
11707
- resolveFromEditor
11708
- });
11709
- handleTrackedChangeUpdate({
11710
- superdoc,
11711
- params,
11712
- broadcastChanges,
11713
- documentState
11714
- });
11715
- if (existingComment) {
11716
- existingComment.trackedChangeStory = snapshot.story;
11717
- existingComment.trackedChangeStoryKind = snapshot.storyKind;
11718
- existingComment.trackedChangeStoryLabel = snapshot.storyLabel;
11719
- existingComment.trackedChangeAnchorKey = snapshot.anchorKey;
11720
- }
11721
- };
11722
- const normalizeDocxSchemaForExport = (value) => {
11723
- if (!value) return [];
11724
- return (Array.isArray(value) ? value : [value]).filter(Boolean);
11725
- };
11726
- const translateCommentsForExport = () => {
11727
- const processedComments = [];
11728
- commentsList.value.forEach((comment) => {
11729
- const values = comment.getValues();
11730
- const richText = values.commentText;
11731
- const docxSchema = normalizeDocxSchemaForExport(values.docxCommentJSON);
11732
- const schema = docxSchema.length ? docxSchema : convertHtmlToSchema(richText);
11733
- processedComments.push({
11734
- ...values,
11735
- commentJSON: schema
11736
- });
11737
- });
11738
- return processedComments;
11739
- };
11740
- const convertHtmlToSchema = (commentHTML) => {
11741
- const json = new Editor({
11742
- mode: "text",
11743
- isHeadless: true,
11744
- content: commentHTML,
11745
- extensions: getRichTextExtensions()
11746
- }).getJSON();
11747
- return Array.isArray(json?.content) ? json.content.filter(Boolean) : [];
11748
- };
11749
10851
  /**
11750
10852
  * Triggered when the editor locations are updated
11751
10853
  * Updates floating comment locations from the editor
@@ -11808,150 +10910,12 @@ var useCommentsStore = defineStore("comments", () => {
11808
10910
  const clearEditorCommentPositions = () => {
11809
10911
  editorCommentPositions.value = {};
11810
10912
  };
11811
- /**
11812
- * Identify the single structural (whole-table) bubble for a tracked table so
11813
- * it is NEVER suppressed by the table-subsume filter below. The structural
11814
- * bubble is the parent "Added table" / "Deleted table" change; its public
11815
- * id is `word:structural:<id>` (or a bare structural fallback) and its display
11816
- * type is `tableInsert` / `tableDelete`.
11817
- *
11818
- * @param {Object} comment
11819
- * @returns {boolean}
11820
- */
11821
- const isStructuralTableBubble = (comment) => {
11822
- if (!comment?.trackedChange) return false;
11823
- const displayType = comment?.trackedChangeDisplayType;
11824
- if (displayType === "tableInsert" || displayType === "tableDelete") return true;
11825
- return [
11826
- comment?.commentId,
11827
- comment?.importedId,
11828
- comment?.trackedChangeAnchorKey
11829
- ].map((id) => id != null ? String(id) : "").filter(Boolean).some((id) => id.includes("word:structural:"));
11830
- };
11831
- /**
11832
- * Compute the decidable whole-table tracked-change ranges for a comment's
11833
- * document, memoized per editor state so the filter does not re-enumerate the
11834
- * document once per comment. Returns `[]` when the document has no tracked
11835
- * whole-table change (the common case), so non-tracked tables and inline-only
11836
- * tracked changes are never affected.
11837
- *
11838
- * @param {string | null | undefined} fileId
11839
- * @returns {Array<{ from: number, to: number }>}
11840
- */
11841
- const trackedTableSummaryCache = /* @__PURE__ */ new WeakMap();
11842
- /**
11843
- * Single source of truth for the decidable whole-table tracked changes in an
11844
- * editor state, enumerated and memoized ONCE per state. Returns:
11845
- * - `ranges`: each tracked whole-table's `{ from, to }` document span. Used to
11846
- * test whether an inline tracked change falls inside a tracked table.
11847
- * - `ids`: every change id associated with those tables (the change's public
11848
- * id / revisionId / revisionGroupId / sourceId plus each row's trackChange
11849
- * id / sourceId). Text typed inside a tracked-inserted row inherits that
11850
- * row's revision id, so such an inline change reports a changeId that is one
11851
- * of these — it must be subsumed by the structural bubble, not get its own
11852
- * review item.
11853
- *
11854
- * @param {object | null | undefined} state
11855
- * @returns {{ ranges: Array<{ from: number, to: number }>, ids: Set<string> }}
11856
- */
11857
- const computeTrackedTableSummaryForState = (state) => {
11858
- if (!state) return {
11859
- ranges: [],
11860
- ids: /* @__PURE__ */ new Set()
11861
- };
11862
- const cached = trackedTableSummaryCache.get(state);
11863
- if (cached) return cached;
11864
- const ranges = [];
11865
- const ids = /* @__PURE__ */ new Set();
11866
- const add = (value) => {
11867
- if (value != null && value !== "") ids.add(String(value));
11868
- };
11869
- const enumerate = trackChangesHelpers?.enumerateStructuralRowChanges;
11870
- if (typeof enumerate === "function") {
11871
- let structuralChanges = [];
11872
- try {
11873
- structuralChanges = enumerate(state) ?? [];
11874
- } catch {
11875
- structuralChanges = [];
11876
- }
11877
- for (const change of structuralChanges) {
11878
- if (!change?.decidable || !change?.wholeTable) continue;
11879
- const from = Number(change.tableFrom);
11880
- const to = Number(change.tableTo);
11881
- if (Number.isFinite(from) && Number.isFinite(to)) ranges.push({
11882
- from,
11883
- to
11884
- });
11885
- add(change.id);
11886
- add(change.revisionId);
11887
- add(change.revisionGroupId);
11888
- add(change.sourceId);
11889
- for (const row of change.rows || []) {
11890
- const tc = row?.node?.attrs?.trackChange;
11891
- add(tc?.id);
11892
- add(tc?.sourceId);
11893
- }
11894
- }
11895
- }
11896
- const summary = {
11897
- ranges,
11898
- ids
11899
- };
11900
- trackedTableSummaryCache.set(state, summary);
11901
- return summary;
11902
- };
11903
- const getTrackedTableRangesForDocument = (fileId) => {
11904
- const editor = superdocStore.getDocument(fileId)?.getEditor?.();
11905
- return computeTrackedTableSummaryForState(editor?.state).ranges;
11906
- };
11907
- /**
11908
- * True when every `{ from, to }` range of an inline tracked change is wholly
11909
- * contained within some decidable whole-table tracked-change range. Such an
11910
- * inline change is subsumed by the structural "Inserted/Deleted table" review
11911
- * item and must NOT become an independent review item (no comment object →
11912
- * no floating bubble and no active-on-click dialog). The underlying
11913
- * trackInsert/trackDelete mark (the green highlight) is untouched — only the
11914
- * review-item comment is suppressed.
11915
- *
11916
- * @param {Array<{ from?: number, to?: number }>} changeRanges
11917
- * @param {Array<{ from: number, to: number }>} tableRanges
11918
- * @returns {boolean}
11919
- */
11920
- const isInlineRangeInsideTrackedTable = (changeRanges, tableRanges) => {
11921
- if (!tableRanges?.length || !changeRanges?.length) return false;
11922
- return changeRanges.every((seg) => {
11923
- const start = Number(seg?.from);
11924
- const end = Number(seg?.to);
11925
- if (!Number.isFinite(start) || !Number.isFinite(end)) return false;
11926
- return tableRanges.some((table) => start >= table.from && end <= table.to);
11927
- });
11928
- };
11929
- /**
11930
- * Suppress an inline tracked-change bubble whose document range falls within a
11931
- * tracked whole-table change's range, so only the structural "Added table"
11932
- * / "Deleted table" bubble shows for that table (matching Word / Google Docs).
11933
- * The structural bubble itself, real user comments, and inline tracked changes
11934
- * inside a NON-tracked table are never suppressed.
11935
- *
11936
- * @param {Object} comment
11937
- * @returns {boolean} True when the bubble must NOT render.
11938
- */
11939
- const isInlineTrackedChangeInsideTrackedTable = (comment) => {
11940
- if (!comment?.trackedChange) return false;
11941
- if (isStructuralTableBubble(comment)) return false;
11942
- const ranges = getTrackedTableRangesForDocument(comment?.fileId);
11943
- if (!ranges.length) return false;
11944
- const entry = resolveCommentPositionEntry(comment).entry;
11945
- const range = getCommentPositionRange(entry);
11946
- if (!range) return false;
11947
- return ranges.some((table) => range.start >= table.from && range.end <= table.to);
11948
- };
11949
10913
  const getFloatingComments = computed$1(() => {
11950
10914
  return getGroupedComments.value?.parentComments.filter((c) => !c.resolvedTime).filter((c) => {
11951
10915
  if (!isEditorBackedComment(c)) return true;
11952
10916
  if (isTrackedChangeThread(c)) return true;
11953
10917
  return Boolean(resolveCommentPositionEntry(c).entry);
11954
- }).filter((c) => !isInlineTrackedChangeInsideTrackedTable(c));
10918
+ });
11955
10919
  });
11956
10920
  const getFloatingCommentInstances = computed$1(() => {
11957
10921
  return getFloatingComments.value.flatMap((comment) => {
@@ -11996,75 +10960,6 @@ var useCommentsStore = defineStore("comments", () => {
11996
10960
  if (typeof commentsVisible === "boolean") viewingVisibility.commentsVisible = commentsVisible;
11997
10961
  if (typeof trackChangesVisible === "boolean") viewingVisibility.trackChangesVisible = trackChangesVisible;
11998
10962
  };
11999
- /**
12000
- * Get HTML content from the comment text JSON (which uses DOCX schema)
12001
- *
12002
- * @param {Object} commentTextJson The comment text JSON
12003
- * @returns {string} The HTML content
12004
- */
12005
- const normalizeCommentForEditor = (node) => {
12006
- if (Array.isArray(node)) return node.map((child) => normalizeCommentForEditor(child)).flat().filter(Boolean);
12007
- if (!node || typeof node !== "object") return node;
12008
- const stripTextStyleAttrs = (attrs) => {
12009
- if (!attrs) return attrs;
12010
- const rest = { ...attrs };
12011
- delete rest.fontSize;
12012
- delete rest.fontFamily;
12013
- delete rest.eastAsiaFontFamily;
12014
- return Object.keys(rest).length ? rest : void 0;
12015
- };
12016
- const normalizeMark = (mark) => {
12017
- if (!mark) return mark;
12018
- const typeName = typeof mark.type === "string" ? mark.type : mark.type?.name;
12019
- const attrs = mark?.attrs ? { ...mark.attrs } : void 0;
12020
- if (typeName === "textStyle" && attrs) return {
12021
- ...mark,
12022
- attrs: stripTextStyleAttrs(attrs)
12023
- };
12024
- return {
12025
- ...mark,
12026
- attrs
12027
- };
12028
- };
12029
- const cloneMarks = (marks) => Array.isArray(marks) ? marks.filter(Boolean).map((mark) => normalizeMark(mark)) : void 0;
12030
- const cloneAttrs = (attrs) => attrs && typeof attrs === "object" ? { ...attrs } : void 0;
12031
- if (!Array.isArray(node.content)) return {
12032
- type: node.type,
12033
- ...node.text !== void 0 ? { text: node.text } : {},
12034
- ...node.attrs ? { attrs: cloneAttrs(node.attrs) } : {},
12035
- ...node.marks ? { marks: cloneMarks(node.marks) } : {}
12036
- };
12037
- const normalizedChildren = node.content.map((child) => normalizeCommentForEditor(child)).flat().filter(Boolean);
12038
- if (node.type === "run") return normalizedChildren;
12039
- return {
12040
- type: node.type,
12041
- ...node.attrs ? { attrs: cloneAttrs(node.attrs) } : {},
12042
- ...node.marks ? { marks: cloneMarks(node.marks) } : {},
12043
- content: normalizedChildren
12044
- };
12045
- };
12046
- const getHtmlFromComment = (commentTextElements) => {
12047
- const elementsArray = Array.isArray(commentTextElements) ? commentTextElements : commentTextElements ? [commentTextElements] : [];
12048
- if (!elementsArray.some((element) => element?.content?.length)) return;
12049
- try {
12050
- const normalizedContent = normalizeCommentForEditor(elementsArray);
12051
- const contentArray = Array.isArray(normalizedContent) ? normalizedContent : normalizedContent ? [normalizedContent] : [];
12052
- if (!contentArray.length) return null;
12053
- return new Editor({
12054
- mode: "text",
12055
- isHeadless: true,
12056
- content: {
12057
- type: "doc",
12058
- content: contentArray
12059
- },
12060
- loadFromSchema: true,
12061
- extensions: getRichTextExtensions()
12062
- }).getHTML();
12063
- } catch (error) {
12064
- console.warn("Failed to convert comment", error);
12065
- return;
12066
- }
12067
- };
12068
10963
  return {
12069
10964
  COMMENT_EVENTS,
12070
10965
  isDebugging,
@@ -12133,23 +11028,17 @@ var useCommentsStore = defineStore("comments", () => {
12133
11028
  cancelComment,
12134
11029
  deleteComment,
12135
11030
  removePendingComment,
12136
- cancelImportedTrackedChangeBootstrap,
12137
11031
  removeCommentsForDocument,
12138
11032
  setReviewDirectoryFromV2,
12139
11033
  clearReviewDirectory,
12140
- processLoadedDocxComments,
12141
- translateCommentsForExport,
12142
11034
  handleEditorLocationsUpdate,
12143
11035
  clearEditorCommentPositions,
12144
11036
  handleTrackedChangeUpdate,
12145
- refreshTrackedChangeCommentsByIds,
12146
11037
  syncResolvedCommentsWithDocument,
12147
- syncTrackedChangePositionsWithDocument,
12148
11038
  setActiveFloatingCommentInstance,
12149
11039
  requestInstantSidebarAlignment,
12150
11040
  peekInstantSidebarAlignment,
12151
11041
  clearInstantSidebarAlignment,
12152
- syncTrackedChangeComments,
12153
11042
  decideTrackedChangeFromSidebar,
12154
11043
  v2CommentsAdapter,
12155
11044
  setV2CommentsAdapter,
@@ -22128,7 +21017,7 @@ var SuperDoc_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
22128
21017
  }
22129
21018
  });
22130
21019
  const { getConfig, documentsWithConverations, commentsList, pendingComment, activeComment, skipSelectionUpdate, commentsByDocument, isCommentsListVisible, isFloatingCommentsReady, generalCommentIds, hasSyncedCollaborationComments, editorCommentPositions, hasInitializedLocations, isCommentHighlighted, hasOpenTrackedChanges } = storeToRefs(commentsStore);
22131
- const { showAddComment, handleEditorLocationsUpdate, handleTrackedChangeUpdate, refreshTrackedChangeCommentsByIds, syncTrackedChangePositionsWithDocument, syncTrackedChangeComments, addComment, addHydratedComment, getComment, resolveCommentPositionEntry, belongsToDocument, COMMENT_EVENTS, requestInstantSidebarAlignment, peekInstantSidebarAlignment, clearInstantSidebarAlignment } = commentsStore;
21020
+ const { showAddComment, handleEditorLocationsUpdate, handleTrackedChangeUpdate, addComment, addHydratedComment, getComment, resolveCommentPositionEntry, belongsToDocument, COMMENT_EVENTS, requestInstantSidebarAlignment, peekInstantSidebarAlignment, clearInstantSidebarAlignment } = commentsStore;
22132
21021
  const { proxy } = getCurrentInstance();
22133
21022
  commentsStore.proxy = proxy;
22134
21023
  const documentOpenTelemetry = createDocumentOpenTelemetry(proxy.$superdoc.config);
@@ -22180,7 +21069,6 @@ var SuperDoc_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
22180
21069
  const layers = ref(null);
22181
21070
  const rightSidebarRef = ref(null);
22182
21071
  const pdfViewerRef = ref(null);
22183
- const pendingReplayTrackedChangeSync = ref(false);
22184
21072
  const toolsMenuPosition = reactive({
22185
21073
  top: null,
22186
21074
  right: "-25px",
@@ -22243,20 +21131,6 @@ var SuperDoc_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
22243
21131
  }
22244
21132
  });
22245
21133
  const pdfConfig = proxy.$superdoc.config.modules?.pdf || {};
22246
- const flushPendingReplayTrackedChangeSync = () => {
22247
- if (!pendingReplayTrackedChangeSync.value) return;
22248
- pendingReplayTrackedChangeSync.value = false;
22249
- syncTrackedChangeComments({
22250
- superdoc: proxy.$superdoc,
22251
- editor: proxy.$superdoc?.activeEditor
22252
- });
22253
- };
22254
- const scheduleReplayTrackedChangeSync = () => {
22255
- pendingReplayTrackedChangeSync.value = true;
22256
- nextTick(() => {
22257
- flushPendingReplayTrackedChangeSync();
22258
- });
22259
- };
22260
21134
  const handleDocumentReady = (documentId, container) => {
22261
21135
  const doc = getDocument(documentId);
22262
21136
  if (!doc || doc.loadScope && !doc.loadScope.finish()) return;
@@ -23256,7 +22130,6 @@ var SuperDoc_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
23256
22130
  v2PageMetricsSnapshot.value = null;
23257
22131
  const clearedDocumentId = payload?.documentId == null ? null : String(payload.documentId);
23258
22132
  clearV2MutationRejectionNotifications(clearedDocumentId);
23259
- commentsStore.cancelImportedTrackedChangeBootstrap?.(clearedDocumentId ?? void 0);
23260
22133
  if (clearedDocumentId) v2MountStagesByDocumentId.delete(clearedDocumentId);
23261
22134
  if (latestV2MountStage && (clearedDocumentId == null || latestV2MountStage.dataset?.superdocV2DocumentId === clearedDocumentId)) latestV2MountStage = null;
23262
22135
  v2ReviewWindowController.reset("render-cleared");
@@ -23272,7 +22145,7 @@ var SuperDoc_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
23272
22145
  ...event,
23273
22146
  documentId: document?.id ?? null
23274
22147
  }));
23275
- if (event.type === "mutation:committed" && event.origin === "extension") return;
22148
+ if (event.type === "mutation:committed" && event.dryRun) return;
23276
22149
  const documentId = document?.id ?? null;
23277
22150
  if (event.type === "history:changed" && event.state) {
23278
22151
  proxy.$superdoc.emit("history-change", {
@@ -23790,7 +22663,6 @@ var SuperDoc_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
23790
22663
  existingComment: null
23791
22664
  };
23792
22665
  };
23793
- if (type === "replayCompleted") scheduleReplayTrackedChangeSync();
23794
22666
  if (COMMENT_EVENTS?.ADD && type === COMMENT_EVENTS.ADD && commentPayload) {
23795
22667
  commentPayload = normalizeReplayCommentModelPayload(commentPayload);
23796
22668
  const currentUser = proxy.$superdoc?.user;
@@ -24099,7 +22971,6 @@ var SuperDoc_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
24099
22971
  handleFormattingMarksShortcut(e);
24100
22972
  }
24101
22973
  onBeforeUnmount(() => {
24102
- commentsStore.cancelImportedTrackedChangeBootstrap?.();
24103
22974
  passwordPrompt.destroy();
24104
22975
  findReplace.destroy();
24105
22976
  linkPopover.destroy();
@@ -24715,7 +23586,7 @@ var SuperDoc_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
24715
23586
  ], 46, _hoisted_1$17);
24716
23587
  };
24717
23588
  }
24718
- }, [["__scopeId", "data-v-3ac816de"]]);
23589
+ }, [["__scopeId", "data-v-9c1ff6d7"]]);
24719
23590
  //#endregion
24720
23591
  //#region src/core/create-app.js
24721
23592
  var PINIA_DEVTOOLS_SETUP_EVENT = "devtools-plugin:setup";
@@ -46415,7 +45286,7 @@ var SuperDoc = class extends import_eventemitter3.default {
46415
45286
  }
46416
45287
  this.userColorMap = /* @__PURE__ */ new Map();
46417
45288
  this.colorIndex = 0;
46418
- this.version = "2.28.0-next.12";
45289
+ this.version = "2.28.0-next.14";
46419
45290
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
46420
45291
  this.superdocId = config.superdocId || v4();
46421
45292
  this.colors = this.config.colors ?? [];
@@ -48439,23 +47310,6 @@ var SuperDoc = class extends import_eventemitter3.default {
48439
47310
  confirmed
48440
47311
  };
48441
47312
  }
48442
- const legacyReplaceFile = activeEditor && !isV2ActiveEditorFacade(activeEditor) ? activeEditor.replaceFile : null;
48443
- if (typeof legacyReplaceFile === "function") {
48444
- const result = await legacyReplaceFile.call(activeEditor, source);
48445
- const legacyState = result && typeof result === "object" ? result.state : void 0;
48446
- const legacyConfirmed = legacyState === void 0 || legacyState === null || legacyState === "review-ready" || legacyState === "editing-ready";
48447
- if (legacyConfirmed) {
48448
- this.#replaceActiveDocumentData(activeEditor, source);
48449
- this.emit("document-replaced", {
48450
- editor: activeEditor,
48451
- host: activeEditor?.host
48452
- });
48453
- }
48454
- return {
48455
- raw: result,
48456
- confirmed: legacyConfirmed
48457
- };
48458
- }
48459
47313
  throw new Error("SuperDoc: replaceFile is unavailable for the active editor");
48460
47314
  }
48461
47315
  /**
@@ -48468,19 +47322,6 @@ var SuperDoc = class extends import_eventemitter3.default {
48468
47322
  commentsType,
48469
47323
  isFinalDoc
48470
47324
  });
48471
- const uiStoreHydrated = this.config?.modules?.comments !== false;
48472
- let legacyComments;
48473
- let legacyCommentsComputed = false;
48474
- const getLegacyCommentsForV1 = () => {
48475
- if (legacyCommentsComputed) return legacyComments;
48476
- legacyCommentsComputed = true;
48477
- if (commentsType === "clean") legacyComments = [];
48478
- else if (uiStoreHydrated && this.commentsStore && typeof this.commentsStore.translateCommentsForExport === "function") {
48479
- legacyComments = this.commentsStore.translateCommentsForExport();
48480
- if (!Array.isArray(legacyComments)) legacyComments = [];
48481
- }
48482
- return legacyComments;
48483
- };
48484
47325
  const bridgedExportErrors = /* @__PURE__ */ new WeakSet();
48485
47326
  const rememberBridgedExportError = (payload) => {
48486
47327
  if ("editor" in payload && payload.error && typeof payload.error === "object") bridgedExportErrors.add(payload.error);
@@ -48491,7 +47332,7 @@ var SuperDoc = class extends import_eventemitter3.default {
48491
47332
  if (policies !== void 0 && documents.some((doc) => {
48492
47333
  if (doc.type !== "application/vnd.openxmlformats-officedocument.wordprocessingml.document") return false;
48493
47334
  const editor = doc.getEditor?.();
48494
- return editor?.editorVersion !== 2 || typeof editor.exportDocx !== "function";
47335
+ return !isV2ActiveEditorFacade(editor) || typeof editor.exportDocx !== "function";
48495
47336
  })) throw new Error("Independent DOCX export policies require a mounted V2 exporter for every document.");
48496
47337
  const docxPromises = documents.map(async (doc) => {
48497
47338
  if (!doc || doc.type !== "application/vnd.openxmlformats-officedocument.wordprocessingml.document") return null;
@@ -48504,19 +47345,13 @@ var SuperDoc = class extends import_eventemitter3.default {
48504
47345
  if (isDocumentByteSource(doc.data)) return this.#savedDocxToBlob(doc.data);
48505
47346
  return null;
48506
47347
  };
48507
- if (!editor || typeof editor.exportDocx !== "function") return fallbackDocx();
48508
- const isV2Editor = editor.editorVersion === 2;
47348
+ if (!isV2ActiveEditorFacade(editor) || typeof editor.exportDocx !== "function") return fallbackDocx();
48509
47349
  try {
48510
- const exported = await editor.exportDocx(isV2Editor ? {
47350
+ const exported = await editor.exportDocx({
48511
47351
  isFinalDoc,
48512
47352
  commentsType,
48513
47353
  policies,
48514
47354
  fieldsHighlightColor
48515
- } : {
48516
- isFinalDoc,
48517
- comments: getLegacyCommentsForV1(),
48518
- commentsType,
48519
- fieldsHighlightColor
48520
47355
  });
48521
47356
  if (exported) return exported;
48522
47357
  } catch (error) {
@@ -48530,7 +47365,7 @@ var SuperDoc = class extends import_eventemitter3.default {
48530
47365
  editor: null
48531
47366
  }));
48532
47367
  }
48533
- if (isV2Editor) throw error;
47368
+ throw error;
48534
47369
  }
48535
47370
  return fallbackDocx();
48536
47371
  });