superdoc 2.24.0-next.4 → 2.24.0-next.6

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.
@@ -302,7 +302,7 @@ var awarenessStatesToArray = (context, states) => {
302
302
  var DEFAULT_ENDPOINT = "https://ingest.superdoc.dev/v1/collect";
303
303
  function getSuperdocVersion() {
304
304
  try {
305
- return "2.24.0-next.4";
305
+ return "2.24.0-next.6";
306
306
  } catch {
307
307
  return "unknown";
308
308
  }
@@ -13925,10 +13925,35 @@ var CommentDialog_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
13925
13925
  nextTick(() => emit("resize"));
13926
13926
  });
13927
13927
  };
13928
- const isV2Mode = computed$1(() => proxy.$superdoc?.activeEditor?.editorVersion === 2);
13929
- const v2CommentsAdapter = computed$1(() => isV2Mode.value ? proxy.$superdoc?.activeEditor?.v2Comments ?? null : null);
13930
- const v2TrackedChangesAdapter = computed$1(() => isV2Mode.value ? proxy.$superdoc?.activeEditor?.v2TrackedChanges ?? null : null);
13928
+ const activeEditorRevision = ref(0);
13929
+ const v2CapabilityRevision = ref(0);
13930
+ const refreshActiveEditor = () => {
13931
+ activeEditorRevision.value += 1;
13932
+ };
13933
+ const isV2Mode = computed$1(() => {
13934
+ activeEditorRevision.value;
13935
+ return proxy.$superdoc?.activeEditor?.editorVersion === 2;
13936
+ });
13937
+ const v2CommentsAdapter = computed$1(() => {
13938
+ activeEditorRevision.value;
13939
+ return isV2Mode.value ? proxy.$superdoc?.activeEditor?.v2Comments ?? null : null;
13940
+ });
13941
+ const v2TrackedChangesAdapter = computed$1(() => {
13942
+ activeEditorRevision.value;
13943
+ return isV2Mode.value ? proxy.$superdoc?.activeEditor?.v2TrackedChanges ?? null : null;
13944
+ });
13945
+ watch$1(() => {
13946
+ activeEditorRevision.value;
13947
+ return isV2Mode.value ? proxy.$superdoc?.activeEditor?.host ?? null : null;
13948
+ }, (host, _previous, onCleanup) => {
13949
+ v2CapabilityRevision.value += 1;
13950
+ const unsubscribe = host?.subscribe?.(() => {
13951
+ v2CapabilityRevision.value += 1;
13952
+ });
13953
+ onCleanup(() => unsubscribe?.());
13954
+ }, { immediate: true });
13931
13955
  const v2WriteCapability = computed$1(() => {
13956
+ v2CapabilityRevision.value;
13932
13957
  if (!v2CommentsAdapter.value) return null;
13933
13958
  const documentMode = commentsStore.viewingVisibility.documentMode;
13934
13959
  const command = isPendingNewComment.value ? "comments.createFromSelection" : null;
@@ -13952,6 +13977,7 @@ var CommentDialog_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
13952
13977
  return v2WriteCapability.value?.reason ?? "v2-write-unavailable";
13953
13978
  });
13954
13979
  const v2TrackedChangeCapability = computed$1(() => {
13980
+ v2CapabilityRevision.value;
13955
13981
  if (!v2TrackedChangesAdapter.value) return null;
13956
13982
  const documentMode = commentsStore.viewingVisibility.documentMode;
13957
13983
  const capability = v2TrackedChangesAdapter.value.getCapabilityState?.() ?? null;
@@ -14236,6 +14262,7 @@ var CommentDialog_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
14236
14262
  return users;
14237
14263
  });
14238
14264
  onMounted(() => {
14265
+ proxy.$superdoc?.on?.("active-editor-change", refreshActiveEditor);
14239
14266
  if (props.autoFocus) nextTick(() => setFocus());
14240
14267
  if (isPendingNewComment.value) nextTick(() => {
14241
14268
  commentInput.value?.focus?.({ preventScroll: true });
@@ -14249,6 +14276,9 @@ var CommentDialog_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
14249
14276
  checkOverflow();
14250
14277
  });
14251
14278
  });
14279
+ onBeforeUnmount(() => {
14280
+ proxy.$superdoc?.off?.("active-editor-change", refreshActiveEditor);
14281
+ });
14252
14282
  watch$1(showInputSection, (isVisible) => {
14253
14283
  if (!isVisible) return;
14254
14284
  nextTick(() => {
@@ -14495,7 +14525,7 @@ var CommentDialog_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
14495
14525
  ], 64))], 14, _hoisted_1$26)), [[_directive_click_outside, handleClickOutside]]);
14496
14526
  };
14497
14527
  }
14498
- }, [["__scopeId", "data-v-c189ab35"]]);
14528
+ }, [["__scopeId", "data-v-5ace8cef"]]);
14499
14529
  //#endregion
14500
14530
  //#region src/components/CommentsLayer/commentsList/ReviewDirectoryListItem.vue
14501
14531
  var _hoisted_1$25 = [
@@ -19702,6 +19732,11 @@ function textTargetFromQueryMatch(doc, text, blockId) {
19702
19732
  function isTocEntryLinkElement(element) {
19703
19733
  return Boolean(element && typeof element.closest === "function" && element.closest(".superdoc-toc-entry"));
19704
19734
  }
19735
+ /** @param {Element | null | undefined} element */
19736
+ function isNoteCrossReferenceLinkElement(element) {
19737
+ const kind = element?.getAttribute("data-sd-note-cross-reference");
19738
+ return (kind === "ref" || kind === "noteRef") && Boolean(element?.closest("[data-sd-note-role=\"body\"]"));
19739
+ }
19705
19740
  /**
19706
19741
  * @param {Object} options
19707
19742
  * @param {() => SurfaceManager | null | undefined} options.getSurfaceManager
@@ -19845,9 +19880,9 @@ function useLinkPopover({ getSurfaceManager, getActiveEditor, getUi, getActivati
19845
19880
  * Navigate to a body bookmark through its model address. A mounted-anchor
19846
19881
  * fallback is reserved for runtimes without a callable bookmark model.
19847
19882
  * @param {string | null | undefined} anchorUrl
19848
- * @param {{ placeCaret?: boolean }} [options]
19883
+ * @param {{ placeCaret?: boolean, revalidateCaretAfterReveal?: boolean }} [options]
19849
19884
  */
19850
- async function navigateToAnchor(anchorUrl, { placeCaret = false } = {}) {
19885
+ async function navigateToAnchor(anchorUrl, { placeCaret = false, revalidateCaretAfterReveal = false } = {}) {
19851
19886
  if (typeof anchorUrl !== "string" || !anchorUrl.startsWith("#")) return false;
19852
19887
  const anchorName = decodeAnchorFragment(anchorUrl.slice(1));
19853
19888
  const editor = getActiveEditor();
@@ -19864,48 +19899,65 @@ function useLinkPopover({ getSurfaceManager, getActiveEditor, getUi, getActivati
19864
19899
  });
19865
19900
  return true;
19866
19901
  }
19867
- /** @type {BookmarkGetResult | null} */
19868
- let bookmark = null;
19869
- try {
19870
- const list = doc?.bookmarks?.list;
19871
- if (typeof list === "function") {
19872
- if ((await Promise.resolve(list.call(doc.bookmarks)))?.items?.filter((item) => item.name === anchorName).length !== 1) return false;
19902
+ async function readBodyBookmark() {
19903
+ try {
19904
+ const list = doc?.bookmarks?.list;
19905
+ if (typeof list === "function") {
19906
+ if ((await Promise.resolve(list.call(doc.bookmarks)))?.items?.filter((item) => item.name === anchorName).length !== 1) return null;
19907
+ }
19908
+ const bookmark = await Promise.resolve(bookmarkGet.call(doc.bookmarks, { target: {
19909
+ kind: "entity",
19910
+ entityType: "bookmark",
19911
+ name: anchorName
19912
+ } }));
19913
+ if (editor !== getActiveEditor() || generation !== openGeneration) return null;
19914
+ const story = bookmark?.address?.story;
19915
+ if (story && story.storyType !== "body" || bookmark?.tableColumn) return null;
19916
+ const blockId = bookmark?.range?.from?.blockId;
19917
+ const offset = bookmark?.range?.from?.offset ?? 0;
19918
+ if (typeof blockId !== "string" || !Number.isInteger(offset) || offset < 0) return null;
19919
+ return {
19920
+ blockId,
19921
+ offset
19922
+ };
19923
+ } catch {
19924
+ return null;
19873
19925
  }
19874
- bookmark = await Promise.resolve(bookmarkGet.call(doc.bookmarks, { target: {
19875
- kind: "entity",
19876
- entityType: "bookmark",
19877
- name: anchorName
19878
- } }));
19879
- bookmark ??= null;
19880
- } catch {
19881
- return false;
19882
19926
  }
19883
- if (editor !== getActiveEditor() || generation !== openGeneration) return false;
19884
- const story = bookmark?.address?.story;
19885
- if (story && story.storyType !== "body" || bookmark?.tableColumn) return false;
19886
- const blockId = bookmark?.range?.from?.blockId;
19887
- const offset = bookmark?.range?.from?.offset ?? 0;
19888
- if (typeof blockId !== "string" || !Number.isInteger(offset) || offset < 0) return false;
19889
- if (placeCaret) await placeCaretAtBookmark(blockId, offset);
19927
+ let position = await readBodyBookmark();
19928
+ if (!position) return false;
19929
+ if (placeCaret && !revalidateCaretAfterReveal) await placeCaretAtBookmark(position.blockId, position.offset);
19890
19930
  const viewport = getUi()?.viewport;
19891
19931
  const scrollIntoView = viewport?.scrollIntoView;
19892
19932
  if (typeof scrollIntoView !== "function") return false;
19893
- const target = {
19894
- kind: "text",
19895
- blockId,
19896
- range: {
19897
- start: offset,
19898
- end: offset
19899
- }
19900
- };
19901
19933
  for (let step = 0; step < MAX_ANCHOR_NAVIGATION_STEPS; step += 1) try {
19934
+ const target = {
19935
+ kind: "text",
19936
+ blockId: position.blockId,
19937
+ range: {
19938
+ start: position.offset,
19939
+ end: position.offset
19940
+ }
19941
+ };
19902
19942
  const result = await Promise.resolve(scrollIntoView.call(viewport, {
19903
19943
  target,
19904
19944
  block: "start",
19905
19945
  behavior: "instant"
19906
19946
  }));
19907
19947
  if (editor !== getActiveEditor() || generation !== openGeneration) return false;
19908
- if (result?.success !== false) return true;
19948
+ if (result?.success !== false) {
19949
+ if (revalidateCaretAfterReveal) {
19950
+ const current = await readBodyBookmark();
19951
+ if (!current) return false;
19952
+ if (current.blockId !== position.blockId || current.offset !== position.offset) {
19953
+ position = current;
19954
+ continue;
19955
+ }
19956
+ if (placeCaret) await placeCaretAtBookmark(current.blockId, current.offset);
19957
+ if (editor !== getActiveEditor() || generation !== openGeneration) return false;
19958
+ }
19959
+ return true;
19960
+ }
19909
19961
  } catch {
19910
19962
  return false;
19911
19963
  }
@@ -20031,8 +20083,13 @@ function useLinkPopover({ getSurfaceManager, getActiveEditor, getUi, getActivati
20031
20083
  return;
20032
20084
  }
20033
20085
  if (ctx.defaultAction === "navigate") {
20034
- if (ctx.isAnchorLink) navigateToAnchor(ctx.href);
20035
- else if (ctx.href) {
20086
+ if (ctx.isAnchorLink) {
20087
+ const noteReference = isNoteCrossReferenceLinkElement(ctx.element);
20088
+ navigateToAnchor(ctx.href, {
20089
+ placeCaret: noteReference && ctx.documentMode !== "viewing",
20090
+ revalidateCaretAfterReveal: noteReference && ctx.documentMode !== "viewing"
20091
+ });
20092
+ } else if (ctx.href) {
20036
20093
  const target = ctx.target || "_self";
20037
20094
  const features = linkOpenFeaturesForTarget(ctx.rel, target);
20038
20095
  if (features) window.open(ctx.href, target, features);
@@ -46493,7 +46550,7 @@ var SuperDoc = class extends import_eventemitter3.default {
46493
46550
  }
46494
46551
  this.userColorMap = /* @__PURE__ */ new Map();
46495
46552
  this.colorIndex = 0;
46496
- this.version = "2.24.0-next.4";
46553
+ this.version = "2.24.0-next.6";
46497
46554
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
46498
46555
  this.superdocId = config.superdocId || v4();
46499
46556
  this.colors = this.config.colors ?? [];
@@ -48671,11 +48728,12 @@ var SuperDoc = class extends import_eventemitter3.default {
48671
48728
  async #replaceActiveDocument(source) {
48672
48729
  const activeEditor = this.activeEditor;
48673
48730
  if (isV2ActiveEditorFacade(activeEditor) && typeof activeEditor.replaceFile === "function") {
48674
- const result = await activeEditor.replaceFile(source);
48731
+ const replacementSource = this.#savedDocxToBlob(source);
48732
+ const result = await activeEditor.replaceFile(replacementSource);
48675
48733
  const state = result && typeof result === "object" ? result.state : null;
48676
48734
  const confirmed = state === null || state === "review-ready" || state === "editing-ready";
48677
48735
  if (confirmed) {
48678
- this.#replaceActiveDocumentData(activeEditor, source);
48736
+ this.#replaceActiveDocumentData(activeEditor, replacementSource);
48679
48737
  this.emit("document-replaced", {
48680
48738
  editor: activeEditor,
48681
48739
  host: activeEditor?.host