superdoc 2.0.0-next.33 → 2.0.0-next.34

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.
@@ -5,7 +5,7 @@ import { t as v4_default } from "./chunks/uuid-B2Sqk-3p.es.js";
5
5
  import { a as init_dist, i as global, n as init_dist$1, r as process$1, t as require_jszip_min } from "./chunks/jszip-DzmwAHr3.es.js";
6
6
  import { t as __plugin_vue_export_helper_default } from "./chunks/_plugin-vue_export-helper-CInC0bKI.es.js";
7
7
  import { n as PDF_TO_CSS_UNITS } from "./chunks/constants-CY3R3_kF.es.js";
8
- import { a as createV2ReviewMutationReconciler, i as isV2EditableTextMutationEvent, o as getV2TrackedChangeMutationImpact, t as createSuperDocUI } from "./chunks/create-super-doc-ui-C01vcKRO.es.js";
8
+ import { a as createV2ReviewMutationReconciler, i as isV2EditableTextMutationEvent, o as getV2TrackedChangeMutationImpact, s as composeAuthorColorResolver, t as createSuperDocUI } from "./chunks/create-super-doc-ui-C_kKiKQ4.es.js";
9
9
  import * as Vue from "vue";
10
10
  import { Fragment, Teleport, Transition, computed, createApp, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineAsyncComponent, defineComponent, getCurrentInstance, h, inject, markRaw, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeUnmount, onDeactivated, onMounted, openBlock, reactive, ref, renderList, renderSlot, resolveDirective, resolveDynamicComponent, shallowRef, toDisplayString, toRaw, toRef, unref, useAttrs, vModelText, watch, withCtx, withDirectives, withKeys, withModifiers } from "vue";
11
11
  import "y-websocket";
@@ -1842,6 +1842,7 @@ function useComment(params) {
1842
1842
  const trackedChangeStoryLabel = ref(params.trackedChangeStoryLabel || "");
1843
1843
  const trackedChangeAnchorKey = ref(params.trackedChangeAnchorKey || null);
1844
1844
  const trackedChangeCanonicalId = ref(params.trackedChangeCanonicalId || null);
1845
+ const trackedChangePositionAliases = ref(params.trackedChangePositionAliases || []);
1845
1846
  const deletedText = ref(params.deletedText || null);
1846
1847
  const trackedChangeLabel = ref(params.trackedChangeLabel || null);
1847
1848
  const trackedChangeDetailLines = ref(params.trackedChangeDetailLines || null);
@@ -2011,6 +2012,7 @@ function useComment(params) {
2011
2012
  trackedChangeStoryLabel: trackedChangeStoryLabel.value,
2012
2013
  trackedChangeAnchorKey: trackedChangeAnchorKey.value,
2013
2014
  trackedChangeCanonicalId: trackedChangeCanonicalId.value,
2015
+ trackedChangePositionAliases: trackedChangePositionAliases.value,
2014
2016
  trackedChangeDecision: trackedChangeDecision.value,
2015
2017
  trackedChangeLabel: trackedChangeLabel.value,
2016
2018
  trackedChangeDetailLines: trackedChangeDetailLines.value,
@@ -2060,6 +2062,7 @@ function useComment(params) {
2060
2062
  trackedChangeStoryLabel,
2061
2063
  trackedChangeAnchorKey,
2062
2064
  trackedChangeCanonicalId,
2065
+ trackedChangePositionAliases,
2063
2066
  trackedChangeDecision,
2064
2067
  trackedChangeLabel,
2065
2068
  trackedChangeDetailLines,
@@ -2513,6 +2516,11 @@ var toFinitePageIndex = (value) => {
2513
2516
  var buildPageScopedInstanceId = (positionKey, pageIndex) => {
2514
2517
  return `${positionKey}::page:${pageIndex}`;
2515
2518
  };
2519
+ var matchesTrackedChangePositionAlias = (positionKey, alias) => {
2520
+ const normalizedPositionKey = String(positionKey);
2521
+ const normalizedAlias = String(alias);
2522
+ return normalizedPositionKey === normalizedAlias || normalizedPositionKey.startsWith("tc::") && normalizedPositionKey.endsWith(`::${normalizedAlias}`);
2523
+ };
2516
2524
  var aggregateRectBounds = (rects) => {
2517
2525
  if (!Array.isArray(rects) || rects.length === 0) return null;
2518
2526
  let left = Number.POSITIVE_INFINITY;
@@ -2619,7 +2627,9 @@ var buildRepeatedHeaderFooterInstances = ({ comment, positionKey, positionEntry,
2619
2627
  });
2620
2628
  };
2621
2629
  const buildFloatingCommentInstances = ({ comment, positionKey, positionEntry, fallbackId }) => {
2622
- const instanceId = comment?.trackedChange && comment?.trackedChangeCanonicalId && positionKey && fallbackId && String(positionKey) !== String(fallbackId) ? fallbackId : positionKey ?? fallbackId;
2630
+ const hasTrackedChangePositionAlias = comment?.trackedChange && positionKey && fallbackId && Array.isArray(comment?.trackedChangePositionAliases) && comment.trackedChangePositionAliases.some((alias) => matchesTrackedChangePositionAlias(positionKey, alias));
2631
+ const hasSharedTrackedChangeAnchor = comment?.trackedChange && comment?.trackedChangeCanonicalId && positionKey && fallbackId && String(positionKey) !== String(fallbackId);
2632
+ const instanceId = hasTrackedChangePositionAlias || hasSharedTrackedChangeAnchor ? fallbackId : positionKey ?? fallbackId;
2623
2633
  if (!instanceId) return [];
2624
2634
  if (isRepeatedHeaderFooterTrackedChange(comment, positionEntry) && positionKey) {
2625
2635
  const repeatedInstances = buildRepeatedHeaderFooterInstances({
@@ -3100,6 +3110,37 @@ const useCommentsStore = defineStore("comments", () => {
3100
3110
  if (config.comments && config.comments.length) commentsList.value = config.comments?.map((c) => useComment(c)) || [];
3101
3111
  };
3102
3112
  const normalizeCommentId = (id) => id === void 0 || id === null ? null : String(id);
3113
+ const normalizeTrackedChangePositionAliases = (aliases) => {
3114
+ if (!Array.isArray(aliases)) return [];
3115
+ return [...new Set(aliases.map((id) => normalizeCommentId(id)).filter(Boolean))];
3116
+ };
3117
+ const getTrackedChangeStoryKey = (comment) => {
3118
+ if (!comment?.trackedChange) return null;
3119
+ const anchorKey = normalizeCommentId(comment.trackedChangeAnchorKey);
3120
+ if (anchorKey?.startsWith("tc::")) {
3121
+ const separatorIndex = anchorKey.indexOf("::", 4);
3122
+ if (separatorIndex > 4) return anchorKey.slice(4, separatorIndex);
3123
+ }
3124
+ const story = comment.trackedChangeStory;
3125
+ switch (story?.storyType) {
3126
+ case "body": return "body";
3127
+ case "headerFooterPart": return story.refId ? `hf:${story.refId}` : null;
3128
+ case "footnote": return story.noteId ? `fn:${story.noteId}` : null;
3129
+ case "endnote": return story.noteId ? `en:${story.noteId}` : null;
3130
+ case "textbox": return story.textboxId ? `textbox:${story.textboxId}` : null;
3131
+ default: return null;
3132
+ }
3133
+ };
3134
+ const normalizeTrackedChangeStoryKey = (storyKey) => {
3135
+ if (storyKey?.startsWith("hf:part:")) return `hf:${storyKey.slice(8)}`;
3136
+ if (storyKey?.startsWith("headerFooterPart:")) return `hf:${storyKey.slice(17)}`;
3137
+ return storyKey;
3138
+ };
3139
+ const positionEntryMatchesTrackedChangeStory = (entry, comment) => {
3140
+ const expectedStoryKey = normalizeTrackedChangeStoryKey(getTrackedChangeStoryKey(comment));
3141
+ const entryStoryKey = normalizeTrackedChangeStoryKey(normalizeCommentId(entry?.storyKey));
3142
+ return !expectedStoryKey || !entryStoryKey || entryStoryKey === expectedStoryKey;
3143
+ };
3103
3144
  const buildTrackedChangeImportedPositionId = (id) => {
3104
3145
  const normalizedId = normalizeCommentId(id);
3105
3146
  if (!normalizedId) return null;
@@ -3223,6 +3264,8 @@ const useCommentsStore = defineStore("comments", () => {
3223
3264
  if (commentOrId === void 0 || commentOrId === null) return [];
3224
3265
  const rawId = typeof commentOrId === "object" ? null : commentOrId;
3225
3266
  const comment = typeof commentOrId === "object" ? commentOrId : getComment(commentOrId);
3267
+ const trackedChangePositionAliases = comment?.trackedChange ? normalizeTrackedChangePositionAliases(comment?.trackedChangePositionAliases) : [];
3268
+ const trackedChangeStoryKey = normalizeTrackedChangeStoryKey(getTrackedChangeStoryKey(comment));
3226
3269
  const seen = /* @__PURE__ */ new Set();
3227
3270
  return [
3228
3271
  rawId,
@@ -3230,7 +3273,11 @@ const useCommentsStore = defineStore("comments", () => {
3230
3273
  comment?.trackedChangeAnchorKey,
3231
3274
  comment?.commentId,
3232
3275
  comment?.importedId,
3233
- comment?.trackedChange ? buildTrackedChangeImportedPositionId(comment?.importedId) : null
3276
+ comment?.trackedChange ? buildTrackedChangeImportedPositionId(comment?.importedId) : null,
3277
+ ...trackedChangePositionAliases.flatMap((id) => [trackedChangeStoryKey && !id.startsWith("tc::") ? makeTrackedChangeAnchorKey({
3278
+ storyKey: trackedChangeStoryKey,
3279
+ rawId: id
3280
+ }) : null, id])
3234
3281
  ].map((id) => normalizeCommentId(id)).filter((id) => {
3235
3282
  if (!id || seen.has(id)) return false;
3236
3283
  seen.add(id);
@@ -3239,12 +3286,13 @@ const useCommentsStore = defineStore("comments", () => {
3239
3286
  };
3240
3287
  const resolveCommentPositionEntry = (commentOrId, preferredId) => {
3241
3288
  const currentPositions = editorCommentPositions.value || {};
3289
+ const comment = typeof commentOrId === "object" ? commentOrId : getComment(commentOrId);
3242
3290
  const seen = /* @__PURE__ */ new Set();
3243
3291
  for (const key of [preferredId, ...getCommentAliasIds(commentOrId)].map((id) => normalizeCommentId(id)).filter(Boolean)) {
3244
3292
  if (seen.has(key)) continue;
3245
3293
  seen.add(key);
3246
3294
  const entry = currentPositions[key];
3247
- if (entry !== void 0) return {
3295
+ if (entry !== void 0 && positionEntryMatchesTrackedChangeStory(entry, comment)) return {
3248
3296
  key,
3249
3297
  entry
3250
3298
  };
@@ -3483,9 +3531,11 @@ const useCommentsStore = defineStore("comments", () => {
3483
3531
  documentId: params?.documentId ?? null
3484
3532
  });
3485
3533
  try {
3486
- const { event, changeId, trackedChangeText, trackedChangeType, trackedChangeDisplayType, semanticColorKey, semanticColor, deletedText, trackedChangeLabel, trackedChangeDetailLines, trackedChangeImagePreview, authorId, authorEmail, authorImage, date, author: authorName, importedAuthor, documentId, coords, trackedChangeStory, trackedChangeStoryKind, trackedChangeStoryLabel, trackedChangeAnchorKey, trackedChangeCanonicalId, importedId } = params;
3534
+ const { event, changeId, trackedChangeText, trackedChangeType, trackedChangeDisplayType, semanticColorKey, semanticColor, deletedText, trackedChangeLabel, trackedChangeDetailLines, trackedChangeImagePreview, authorId, authorEmail, authorImage, date, author: authorName, importedAuthor, documentId, coords, trackedChangeStory, trackedChangeStoryKind, trackedChangeStoryLabel, trackedChangeAnchorKey, trackedChangeCanonicalId, trackedChangePositionAliases, importedId } = params;
3487
3535
  const normalizedChangeId = changeId != null ? String(changeId) : null;
3488
3536
  const normalizedTrackedChangeCanonicalId = trackedChangeCanonicalId != null ? String(trackedChangeCanonicalId) : null;
3537
+ const hasTrackedChangePositionAliases = Object.prototype.hasOwnProperty.call(params, "trackedChangePositionAliases");
3538
+ const normalizedTrackedChangePositionAliases = hasTrackedChangePositionAliases ? normalizeTrackedChangePositionAliases(trackedChangePositionAliases) : void 0;
3489
3539
  const hasImportedId = Object.prototype.hasOwnProperty.call(params, "importedId");
3490
3540
  const normalizedImportedId = hasImportedId ? importedId != null ? String(importedId) : null : void 0;
3491
3541
  const normalizedDocumentId = documentId != null ? String(documentId) : null;
@@ -3543,6 +3593,7 @@ const useCommentsStore = defineStore("comments", () => {
3543
3593
  trackedChangeStoryLabel: normalizedTrackedChangeStoryLabel,
3544
3594
  trackedChangeAnchorKey: normalizedTrackedChangeAnchorKey,
3545
3595
  trackedChangeCanonicalId: normalizedTrackedChangeCanonicalId,
3596
+ ...hasTrackedChangePositionAliases ? { trackedChangePositionAliases: normalizedTrackedChangePositionAliases } : {},
3546
3597
  selection: {
3547
3598
  source: DOCUMENT_EDITOR_SELECTION_SOURCE,
3548
3599
  selectionBounds: coords
@@ -3603,6 +3654,7 @@ const useCommentsStore = defineStore("comments", () => {
3603
3654
  createdTime: date ?? null
3604
3655
  };
3605
3656
  if (hasImportedId) fields.importedId = normalizedImportedId;
3657
+ if (hasTrackedChangePositionAliases) fields.trackedChangePositionAliases = normalizedTrackedChangePositionAliases;
3606
3658
  let didChange = false;
3607
3659
  for (const [key, value] of Object.entries(fields)) didChange = setIfChanged(target, key, value) || didChange;
3608
3660
  if (target && !(target.trackedChangeDetailLines == null && normalizedTrackedChangeDetailLines == null) && !trackedChangeDetailLinesEqual(target.trackedChangeDetailLines, normalizedTrackedChangeDetailLines)) {
@@ -9698,85 +9750,6 @@ var WhiteboardLayer_default = /* @__PURE__ */ __plugin_vue_export_helper_default
9698
9750
  };
9699
9751
  }
9700
9752
  }, [["__scopeId", "data-v-54546c3d"]]);
9701
- var FALLBACK_PALETTE = [
9702
- "#1f6feb",
9703
- "#d1242f",
9704
- "#8250df",
9705
- "#bf3989",
9706
- "#1a7f37",
9707
- "#9a6700",
9708
- "#bc4c00",
9709
- "#0969da",
9710
- "#cf222e",
9711
- "#6639ba",
9712
- "#116329",
9713
- "#7d4e00"
9714
- ];
9715
- const authorIdentityKey = (author) => {
9716
- if (!author) return "";
9717
- return `${typeof author.name === "string" ? author.name : ""} ${typeof author.email === "string" ? author.email : ""}`;
9718
- };
9719
- var hashString = (value) => {
9720
- let hash = 2166136261;
9721
- for (let i = 0; i < value.length; i += 1) {
9722
- hash ^= value.charCodeAt(i);
9723
- hash = Math.imul(hash, 16777619);
9724
- }
9725
- return hash >>> 0;
9726
- };
9727
- const fallbackAuthorColor = (author) => {
9728
- return FALLBACK_PALETTE[hashString(authorIdentityKey(author)) % FALLBACK_PALETTE.length];
9729
- };
9730
- var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
9731
- const composeAuthorColorResolver = (config) => {
9732
- if (!config || config.enabled === false) return void 0;
9733
- const overrides = config.overrides && typeof config.overrides === "object" ? config.overrides : void 0;
9734
- const resolve = typeof config.resolve === "function" ? config.resolve : void 0;
9735
- return (author) => {
9736
- const safeAuthor = author ?? {};
9737
- if (overrides) {
9738
- if (isNonEmptyString(safeAuthor.email) && isNonEmptyString(overrides[safeAuthor.email])) return overrides[safeAuthor.email];
9739
- if (isNonEmptyString(safeAuthor.name) && isNonEmptyString(overrides[safeAuthor.name])) return overrides[safeAuthor.name];
9740
- }
9741
- if (resolve) try {
9742
- const resolved = resolve(safeAuthor);
9743
- if (isNonEmptyString(resolved)) return resolved;
9744
- } catch {}
9745
- return fallbackAuthorColor(safeAuthor);
9746
- };
9747
- };
9748
- const DRAWING_DIAGNOSTIC_CODES = {
9749
- externalImageDeferred: "render.media.external-image-deferred",
9750
- missingRelationship: "render.drawing.missing-relationship",
9751
- missingMediaPart: "render.media.missing-part",
9752
- unsupportedRelationshipType: "render.drawing.unsupported-relationship-type",
9753
- unsupportedMime: "render.media.unsupported-mime",
9754
- imageTooLarge: "render.media.image-too-large",
9755
- unsafeSvg: "render.media.unsafe-svg",
9756
- unsupportedFormat: "render.media.unsupported-format",
9757
- embeddedObjectNotSupported: "render.embedded-object-not-supported",
9758
- unsupportedObject: "render.drawing.unsupported-object",
9759
- vmlUnsupported: "render.drawing.vml-unsupported",
9760
- vmlImageUnsupported: "render.drawing.vml-image-unsupported",
9761
- unsupportedGeometryCommand: "render.drawing.unsupported-geometry-command",
9762
- anchorUnsupported: "render.drawing.anchor-unsupported",
9763
- wrapUnsupported: "render.drawing.wrap-unsupported",
9764
- altContentNoSupportedChoice: "render.drawing.altcontent-no-supported-choice",
9765
- groupChildUnsupported: "render.drawing.group-child-unsupported"
9766
- };
9767
- DRAWING_DIAGNOSTIC_CODES.missingRelationship, DRAWING_DIAGNOSTIC_CODES.unsupportedRelationshipType, DRAWING_DIAGNOSTIC_CODES.unsupportedRelationshipType, DRAWING_DIAGNOSTIC_CODES.imageTooLarge, DRAWING_DIAGNOSTIC_CODES.missingMediaPart, DRAWING_DIAGNOSTIC_CODES.unsupportedObject, DRAWING_DIAGNOSTIC_CODES.vmlUnsupported;
9768
- DRAWING_DIAGNOSTIC_CODES.externalImageDeferred, DRAWING_DIAGNOSTIC_CODES.missingRelationship, DRAWING_DIAGNOSTIC_CODES.missingMediaPart, DRAWING_DIAGNOSTIC_CODES.unsupportedRelationshipType, DRAWING_DIAGNOSTIC_CODES.unsupportedMime, DRAWING_DIAGNOSTIC_CODES.imageTooLarge, DRAWING_DIAGNOSTIC_CODES.unsafeSvg, DRAWING_DIAGNOSTIC_CODES.unsupportedFormat, DRAWING_DIAGNOSTIC_CODES.embeddedObjectNotSupported, DRAWING_DIAGNOSTIC_CODES.unsupportedObject, DRAWING_DIAGNOSTIC_CODES.vmlUnsupported, DRAWING_DIAGNOSTIC_CODES.vmlImageUnsupported, DRAWING_DIAGNOSTIC_CODES.unsupportedGeometryCommand, DRAWING_DIAGNOSTIC_CODES.anchorUnsupported, DRAWING_DIAGNOSTIC_CODES.wrapUnsupported, DRAWING_DIAGNOSTIC_CODES.altContentNoSupportedChoice, DRAWING_DIAGNOSTIC_CODES.groupChildUnsupported;
9769
- Object.freeze([
9770
- "multiple-sections",
9771
- "furniture-page-tokens",
9772
- "non-balanceable-multi-column-sections",
9773
- "body-anchored-objects",
9774
- "footnotes",
9775
- "page-references",
9776
- "keep-constraints",
9777
- "tables",
9778
- "furniture-anchored-objects"
9779
- ]);
9780
9753
  var _hoisted_1$20 = { class: "superdoc-html-viewer" };
9781
9754
  var _hoisted_2$17 = { class: "superdoc-html-viewer__document" };
9782
9755
  var _hoisted_3$14 = ["innerHTML"];
@@ -32320,7 +32293,11 @@ var IconGrid_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
32320
32293
  };
32321
32294
  }
32322
32295
  }, [["__scopeId", "data-v-52b0283a"]]);
32323
- const refocusEditorSurface = (superToolbar) => {
32296
+ const refocusEditorSurface = (superToolbar, preferredEditor = null) => {
32297
+ if (typeof preferredEditor?.focus === "function") {
32298
+ preferredEditor.focus();
32299
+ return;
32300
+ }
32324
32301
  const focusHandle = superToolbar?.superdoc?.focus ?? superToolbar?.activeEditor?.focus;
32325
32302
  if (typeof focusHandle === "function") {
32326
32303
  focusHandle.call(superToolbar?.superdoc ?? superToolbar?.activeEditor);
@@ -33444,6 +33421,7 @@ const makeDefaultItems = ({ superToolbar, toolbarIcons: toolbarIcons$1, toolbarT
33444
33421
  return h(DocumentMode_default, {
33445
33422
  options: getDocumentOptionsAfterRole(role, documentOptions),
33446
33423
  onSelect: (item) => {
33424
+ const selectedEditor = superToolbar.superdoc?.activeEditor ?? superToolbar.activeEditor;
33447
33425
  closeDropdown(renderDocumentButton);
33448
33426
  const { label, icon, value } = item;
33449
33427
  documentMode.label.value = label;
@@ -33452,6 +33430,7 @@ const makeDefaultItems = ({ superToolbar, toolbarIcons: toolbarIcons$1, toolbarT
33452
33430
  item: documentMode,
33453
33431
  argument: value
33454
33432
  });
33433
+ refocusEditorSurface(superToolbar, selectedEditor);
33455
33434
  }
33456
33435
  });
33457
33436
  }
@@ -34653,7 +34632,7 @@ var SuperDoc = class extends import_eventemitter3.default {
34653
34632
  this.config.colors = shuffleArray(this.config.colors);
34654
34633
  this.userColorMap = /* @__PURE__ */ new Map();
34655
34634
  this.colorIndex = 0;
34656
- this.version = "2.0.0-next.33";
34635
+ this.version = "2.0.0-next.34";
34657
34636
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
34658
34637
  this.superdocId = config.superdocId || v4_default();
34659
34638
  this.colors = this.config.colors ?? [];