@harbour-enterprises/superdoc 1.5.0-next.7 → 1.5.0-next.9

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 { B as Buffer$2 } from "./jszip-B1fkPkPJ.es.js";
2
2
  import { t as twipsToInches, i as inchesToTwips, p as ptToTwips, l as linesToTwips, a as twipsToLines, b as pixelsToTwips, h as halfPointToPoints, c as twipsToPixels$2, d as convertSizeToCSS, e as inchesToPixels } from "./helpers-C8e9wR5l.es.js";
3
- import { g as generateDocxRandomId, T as TextSelection$1, o as objectIncludes, w as wrapTextsInRuns, D as DOMParser$1, c as createDocFromMarkdown, a as createDocFromHTML, b as chainableEditorState, d as convertMarkdownToHTML, f as findParentNode, e as findParentNodeClosestToPos, h as generateRandom32BitHex, i as generateRandomSigned32BitIntStrId, P as PluginKey, j as Plugin, M as Mapping, N as NodeSelection, k as Selection, l as Slice, m as DOMSerializer, F as Fragment, n as Mark$1, p as dropPoint, A as AllSelection, q as Schema$1, s as canSplit, t as resolveRunProperties, u as encodeMarksFromRPr, v as liftTarget, x as canJoin, y as joinPoint, z as replaceStep$1, R as ReplaceAroundStep$1, B as htmlHandler, C as ReplaceStep, E as getResolvedParagraphProperties, G as changeListLevel, H as isList$1, I as updateNumberingProperties, L as ListHelpers, J as inputRulesPlugin, K as TrackDeleteMarkName$1, O as TrackInsertMarkName$1, Q as TrackFormatMarkName$1, U as AddMarkStep, V as RemoveMarkStep, W as CommandService, S as SuperConverter, X as EditorState, Y as unflattenListsInHtml, Z as SelectionRange, _ as Transform, $ as createOoxmlResolver, a0 as translator, a1 as translator$1, a2 as resolveDocxFontFamily, a3 as combineIndentProperties, a4 as _getReferencedTableStyles, a5 as decodeRPrFromMarks, a6 as calculateResolvedParagraphProperties, a7 as encodeCSSFromPPr, a8 as encodeCSSFromRPr, a9 as generateOrderedListIndex, aa as docxNumberingHelpers, ab as InputRule, ac as insertNewRelationship, ad as kebabCase$1, ae as getUnderlineCssString } from "./SuperConverter-S5AfMnkn.es.js";
3
+ import { g as generateDocxRandomId, T as TextSelection$1, o as objectIncludes, w as wrapTextsInRuns, D as DOMParser$1, c as createDocFromMarkdown, a as createDocFromHTML, b as chainableEditorState, d as convertMarkdownToHTML, f as findParentNode, e as findParentNodeClosestToPos, h as generateRandom32BitHex, i as generateRandomSigned32BitIntStrId, P as PluginKey, j as Plugin, M as Mapping, N as NodeSelection, k as Selection, l as Slice, m as DOMSerializer, F as Fragment, n as Mark$1, p as dropPoint, A as AllSelection, q as Schema$1, s as canSplit, t as resolveRunProperties, u as encodeMarksFromRPr, v as liftTarget, x as canJoin, y as joinPoint, z as replaceStep$1, R as ReplaceAroundStep$1, B as htmlHandler, C as ReplaceStep, E as getResolvedParagraphProperties, G as changeListLevel, H as isList$1, I as updateNumberingProperties, L as ListHelpers, J as inputRulesPlugin, K as TrackDeleteMarkName$1, O as TrackInsertMarkName$1, Q as TrackFormatMarkName$1, U as AddMarkStep, V as RemoveMarkStep, W as CommandService, S as SuperConverter, X as EditorState, Y as unflattenListsInHtml, Z as SelectionRange, _ as Transform, $ as createOoxmlResolver, a0 as translator, a1 as translator$1, a2 as resolveDocxFontFamily, a3 as combineIndentProperties, a4 as _getReferencedTableStyles, a5 as decodeRPrFromMarks, a6 as calculateResolvedParagraphProperties, a7 as encodeCSSFromPPr, a8 as encodeCSSFromRPr, a9 as generateOrderedListIndex, aa as docxNumberingHelpers, ab as InputRule, ac as insertNewRelationship, ad as kebabCase$1, ae as getUnderlineCssString } from "./SuperConverter-meS8FJqm.es.js";
4
4
  import { p as process$1, r as ref, C as global$1, c as computed, E as createElementBlock, F as Fragment$1, S as renderList, O as withModifiers, G as openBlock, P as normalizeClass, M as createCommentVNode, H as toDisplayString, K as createBaseVNode, U as createApp, f as onMounted, X as onUnmounted, R as withDirectives, v as unref, Y as vModelText, y as nextTick, L as normalizeStyle, u as watch, Z as withKeys, _ as createTextVNode, I as createVNode, h as h$1, $ as readonly, s as getCurrentInstance, o as onBeforeUnmount, j as reactive, b as onBeforeMount, i as inject, a0 as onActivated, a1 as onDeactivated, a2 as Comment, d as defineComponent, a as provide, g as Teleport, t as toRef, a3 as renderSlot, a4 as isVNode, D as shallowRef, w as watchEffect, T as Transition, a5 as mergeProps, a6 as vShow, a7 as cloneVNode, a8 as Text$2, m as markRaw, N as createBlock, J as withCtx, a9 as useCssVars, V as resolveDynamicComponent, aa as normalizeProps, ab as guardReactiveProps } from "./vue-BnBKJwCW.es.js";
5
5
  import "./jszip.min-DCl8qkFO.es.js";
6
6
  import { E as EventEmitter$1 } from "./eventemitter3-CwrdEv8r.es.js";
@@ -15507,7 +15507,7 @@ const canUseDOM = () => {
15507
15507
  return false;
15508
15508
  }
15509
15509
  };
15510
- const summaryVersion = "1.5.0-next.7";
15510
+ const summaryVersion = "1.5.0-next.9";
15511
15511
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
15512
15512
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
15513
15513
  function mapAttributes(attrs) {
@@ -18164,7 +18164,7 @@ class Editor extends EventEmitter {
18164
18164
  * Process collaboration migrations
18165
18165
  */
18166
18166
  processCollaborationMigrations() {
18167
- console.debug("[checkVersionMigrations] Current editor version", "1.5.0-next.7");
18167
+ console.debug("[checkVersionMigrations] Current editor version", "1.5.0-next.9");
18168
18168
  if (!this.options.ydoc) return;
18169
18169
  const metaMap = this.options.ydoc.getMap("meta");
18170
18170
  let docVersion = metaMap.get("version");
@@ -23452,7 +23452,8 @@ const lineStyles = (lineHeight2) => ({
23452
23452
  // The primary fix uses accurate font metrics from Canvas API, but this
23453
23453
  // provides defense-in-depth against any remaining sub-pixel rendering
23454
23454
  // differences between measurement and display.
23455
- overflow: "visible"
23455
+ overflow: "visible",
23456
+ zIndex: "10"
23456
23457
  });
23457
23458
  const PRINT_STYLES = `
23458
23459
  @media print {
@@ -23758,6 +23759,7 @@ const SDT_CONTAINER_STYLES = `
23758
23759
  border: 1px solid #629be7;
23759
23760
  position: relative;
23760
23761
  display: inline;
23762
+ z-index: 10;
23761
23763
  }
23762
23764
 
23763
23765
  /* Hover effect for inline structured content */
@@ -28945,11 +28947,6 @@ class DomPainter {
28945
28947
  } else {
28946
28948
  delete el.dataset.pmEnd;
28947
28949
  }
28948
- if (fragment.pmStart != null && fragment.pmEnd != null) {
28949
- el.title = `PM ${fragment.pmStart}–${fragment.pmEnd}`;
28950
- } else {
28951
- el.removeAttribute("title");
28952
- }
28953
28950
  if (fragment.continuesFromPrev) {
28954
28951
  el.dataset.continuesFromPrev = "true";
28955
28952
  } else {
@@ -49091,8 +49088,6 @@ class EditorOverlayManager {
49091
49088
  #activeRegion = null;
49092
49089
  /** Full-width border line element (MS Word style) */
49093
49090
  #borderLine = null;
49094
- /** Dimming overlay element (for dimming body content during editing) */
49095
- #dimmingOverlay = null;
49096
49091
  /**
49097
49092
  * Creates a new EditorOverlayManager instance.
49098
49093
  *
@@ -49386,17 +49381,6 @@ class EditorOverlayManager {
49386
49381
  }
49387
49382
  }
49388
49383
  }
49389
- /**
49390
- * Hides and removes the dimming overlay.
49391
- * @internal Reserved for future implementation of body dimming during header/footer editing.
49392
- */
49393
- // eslint-disable-next-line no-unused-private-class-members
49394
- #hideDimmingOverlay() {
49395
- if (this.#dimmingOverlay) {
49396
- this.#dimmingOverlay.remove();
49397
- this.#dimmingOverlay = null;
49398
- }
49399
- }
49400
49384
  /**
49401
49385
  * Shows a full-width border line at the bottom of the header or top of the footer.
49402
49386
  * This creates the MS Word style visual indicator spanning edge-to-edge of the page.
@@ -51569,6 +51553,7 @@ class PresentationEditor extends EventEmitter {
51569
51553
  #viewportHost;
51570
51554
  #painterHost;
51571
51555
  #selectionOverlay;
51556
+ #permissionOverlay = null;
51572
51557
  #hiddenHost;
51573
51558
  #layoutOptions;
51574
51559
  #layoutState = { blocks: [], measures: [], layout: null, bookmarks: /* @__PURE__ */ new Map() };
@@ -51728,6 +51713,16 @@ class PresentationEditor extends EventEmitter {
51728
51713
  });
51729
51714
  this.#domIndexObserverManager.setup();
51730
51715
  this.#selectionSync.on("render", () => this.#updateSelection());
51716
+ this.#selectionSync.on("render", () => this.#updatePermissionOverlay());
51717
+ this.#permissionOverlay = doc2.createElement("div");
51718
+ this.#permissionOverlay.className = "presentation-editor__permission-overlay";
51719
+ Object.assign(this.#permissionOverlay.style, {
51720
+ position: "absolute",
51721
+ inset: "0",
51722
+ pointerEvents: "none",
51723
+ zIndex: "5"
51724
+ });
51725
+ this.#viewportHost.appendChild(this.#permissionOverlay);
51731
51726
  this.#selectionOverlay = doc2.createElement("div");
51732
51727
  this.#selectionOverlay.className = "presentation-editor__selection-overlay";
51733
51728
  this.#selectionOverlay.id = `presentation-overlay-${options.documentId || "default"}`;
@@ -51813,7 +51808,7 @@ class PresentationEditor extends EventEmitter {
51813
51808
  const normalizedEditorProps = {
51814
51809
  ...editorOptions.editorProps ?? {},
51815
51810
  editable: () => {
51816
- return this.#documentMode !== "viewing";
51811
+ return !this.#isViewLocked();
51817
51812
  }
51818
51813
  };
51819
51814
  try {
@@ -52255,6 +52250,7 @@ class PresentationEditor extends EventEmitter {
52255
52250
  this.#pendingDocChange = true;
52256
52251
  this.#scheduleRerender();
52257
52252
  }
52253
+ this.#updatePermissionOverlay();
52258
52254
  }
52259
52255
  #syncDocumentModeClass() {
52260
52256
  if (!this.#visibleHost) return;
@@ -53644,7 +53640,7 @@ class PresentationEditor extends EventEmitter {
53644
53640
  win,
53645
53641
  this.#visibleHost,
53646
53642
  () => this.#getActiveDomTarget(),
53647
- () => this.#documentMode !== "viewing"
53643
+ () => !this.#isViewLocked()
53648
53644
  );
53649
53645
  this.#inputBridge.bind();
53650
53646
  }
@@ -54569,7 +54565,7 @@ class PresentationEditor extends EventEmitter {
54569
54565
  this.#dragUsedPageNotMountedFallback = false;
54570
54566
  return;
54571
54567
  }
54572
- if (this.#session.mode !== "body" || this.#documentMode === "viewing") {
54568
+ if (this.#session.mode !== "body" || this.#isViewLocked()) {
54573
54569
  this.#dragLastPointer = null;
54574
54570
  this.#dragLastRawHit = null;
54575
54571
  this.#dragUsedPageNotMountedFallback = false;
@@ -54919,6 +54915,7 @@ class PresentationEditor extends EventEmitter {
54919
54915
  this.#epochMapper.onLayoutComplete(layoutEpoch);
54920
54916
  this.#selectionSync.onLayoutComplete(layoutEpoch);
54921
54917
  layoutCompleted = true;
54918
+ this.#updatePermissionOverlay();
54922
54919
  this.#layoutError = null;
54923
54920
  this.#layoutErrorState = "healthy";
54924
54921
  this.#dismissErrorBanner();
@@ -55007,7 +55004,7 @@ class PresentationEditor extends EventEmitter {
55007
55004
  if (!this.#localSelectionLayer) {
55008
55005
  return;
55009
55006
  }
55010
- if (this.#documentMode === "viewing") {
55007
+ if (this.#isViewLocked()) {
55011
55008
  try {
55012
55009
  this.#localSelectionLayer.innerHTML = "";
55013
55010
  } catch (error) {
@@ -55089,6 +55086,76 @@ class PresentationEditor extends EventEmitter {
55089
55086
  }
55090
55087
  }
55091
55088
  }
55089
+ /**
55090
+ * Updates the permission overlay (w:permStart/w:permEnd) to match the current editor permission ranges.
55091
+ *
55092
+ * This method is called after layout completes to ensure permission overlay
55093
+ * is based on stable permission ranges data.
55094
+ */
55095
+ #updatePermissionOverlay() {
55096
+ const overlay2 = this.#permissionOverlay;
55097
+ if (!overlay2) {
55098
+ return;
55099
+ }
55100
+ if (this.#session.mode !== "body") {
55101
+ overlay2.innerHTML = "";
55102
+ return;
55103
+ }
55104
+ const permissionStorage = this.#editor?.storage?.permissionRanges;
55105
+ const ranges = permissionStorage?.ranges ?? [];
55106
+ const shouldRender = ranges.length > 0;
55107
+ if (!shouldRender) {
55108
+ overlay2.innerHTML = "";
55109
+ return;
55110
+ }
55111
+ const layout = this.#layoutState.layout;
55112
+ if (!layout) {
55113
+ overlay2.innerHTML = "";
55114
+ return;
55115
+ }
55116
+ const docEpoch = this.#epochMapper.getCurrentEpoch();
55117
+ if (this.#layoutEpoch < docEpoch) {
55118
+ return;
55119
+ }
55120
+ const pageHeight = this.#getBodyPageHeight();
55121
+ const pageGap = layout.pageGap ?? this.#getEffectivePageGap();
55122
+ const fragment = overlay2.ownerDocument?.createDocumentFragment();
55123
+ if (!fragment) {
55124
+ overlay2.innerHTML = "";
55125
+ return;
55126
+ }
55127
+ ranges.forEach(({ from: from3, to }) => {
55128
+ const rects = this.#computeSelectionRectsFromDom(from3, to);
55129
+ if (!rects?.length) {
55130
+ return;
55131
+ }
55132
+ rects.forEach((rect) => {
55133
+ const pageLocalY = rect.y - rect.pageIndex * (pageHeight + pageGap);
55134
+ const coords = this.#convertPageLocalToOverlayCoords(rect.pageIndex, rect.x, pageLocalY);
55135
+ if (!coords) {
55136
+ return;
55137
+ }
55138
+ const highlight = overlay2.ownerDocument?.createElement("div");
55139
+ if (!highlight) {
55140
+ return;
55141
+ }
55142
+ highlight.className = "presentation-editor__permission-highlight";
55143
+ Object.assign(highlight.style, {
55144
+ position: "absolute",
55145
+ left: `${coords.x}px`,
55146
+ top: `${coords.y}px`,
55147
+ width: `${Math.max(1, rect.width)}px`,
55148
+ height: `${Math.max(1, rect.height)}px`,
55149
+ borderRadius: "2px",
55150
+ pointerEvents: "none",
55151
+ zIndex: 1
55152
+ });
55153
+ fragment.appendChild(highlight);
55154
+ });
55155
+ });
55156
+ overlay2.innerHTML = "";
55157
+ overlay2.appendChild(fragment);
55158
+ }
55092
55159
  #resolveLayoutOptions(blocks, sectionMetadata) {
55093
55160
  const defaults = this.#computeDefaultLayoutDefaults();
55094
55161
  const firstSection = blocks?.find(
@@ -55834,7 +55901,7 @@ class PresentationEditor extends EventEmitter {
55834
55901
  this.#announce(announcement.message);
55835
55902
  }
55836
55903
  #validateHeaderFooterEditPermission() {
55837
- if (this.#documentMode === "viewing") {
55904
+ if (this.#isViewLocked()) {
55838
55905
  return { allowed: false, reason: "documentMode" };
55839
55906
  }
55840
55907
  if (!this.#editor.isEditable) {
@@ -56697,6 +56764,17 @@ class PresentationEditor extends EventEmitter {
56697
56764
  this.#errorBanner = null;
56698
56765
  this.#errorBannerMessage = null;
56699
56766
  }
56767
+ /**
56768
+ * Determines whether the current viewing mode should block edits.
56769
+ * When documentMode is viewing but the active editor has been toggled
56770
+ * back to editable (e.g. permission ranges), we treat the view as editable.
56771
+ */
56772
+ #isViewLocked() {
56773
+ if (this.#documentMode !== "viewing") return false;
56774
+ const hasPermissionOverride = !!this.#editor?.storage?.permissionRanges?.hasAllowedRanges;
56775
+ if (hasPermissionOverride) return false;
56776
+ return this.#documentMode === "viewing";
56777
+ }
56700
56778
  /**
56701
56779
  * Applies vertical alignment and font scaling to layout DOM elements for subscript/superscript rendering.
56702
56780
  *
@@ -58576,6 +58654,11 @@ const structuredContentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ O
58576
58654
  parseTagObject
58577
58655
  }, Symbol.toStringTag, { value: "Module" }));
58578
58656
  const STRUCTURED_CONTENT_NAMES = ["structuredContent", "structuredContentBlock"];
58657
+ function isValidIntegerId(id) {
58658
+ if (id === null || id === void 0) return true;
58659
+ const str = String(id);
58660
+ return /^-?\d+$/.test(str);
58661
+ }
58579
58662
  const findFirstTextNode = (node) => {
58580
58663
  let firstTextNode = null;
58581
58664
  node.descendants((child) => {
@@ -58617,6 +58700,9 @@ const StructuredContentCommands = Extension.create({
58617
58700
  * });
58618
58701
  */
58619
58702
  insertStructuredContentInline: (options = {}) => ({ editor, dispatch, state, tr }) => {
58703
+ if (options.attrs?.id !== void 0 && !isValidIntegerId(options.attrs.id)) {
58704
+ throw new Error("Invalid structured content id - must be an integer, got: " + options.attrs.id);
58705
+ }
58620
58706
  const { schema } = editor;
58621
58707
  let { from: from3, to } = state.selection;
58622
58708
  if (dispatch) {
@@ -58679,6 +58765,9 @@ const StructuredContentCommands = Extension.create({
58679
58765
  * });
58680
58766
  */
58681
58767
  insertStructuredContentBlock: (options = {}) => ({ editor, dispatch, state, tr }) => {
58768
+ if (options.attrs?.id !== void 0 && !isValidIntegerId(options.attrs.id)) {
58769
+ throw new Error("Invalid structured content id - must be an integer, got: " + options.attrs.id);
58770
+ }
58682
58771
  const { schema } = editor;
58683
58772
  let { from: from3, to } = state.selection;
58684
58773
  if (dispatch) {
@@ -58736,6 +58825,9 @@ const StructuredContentCommands = Extension.create({
58736
58825
  * });
58737
58826
  */
58738
58827
  updateStructuredContentById: (id, options = {}) => ({ editor, dispatch, state, tr }) => {
58828
+ if (options.attrs?.id !== void 0 && !isValidIntegerId(options.attrs.id)) {
58829
+ throw new Error("Invalid structured content id - must be an integer, got: " + options.attrs.id);
58830
+ }
58739
58831
  const structuredContentTags = getStructuredContentTagsById(id, state);
58740
58832
  if (!structuredContentTags.length) {
58741
58833
  return true;
@@ -58863,6 +58955,9 @@ const StructuredContentCommands = Extension.create({
58863
58955
  * });
58864
58956
  */
58865
58957
  updateStructuredContentByGroup: (group, options = {}) => ({ editor, dispatch, state, tr }) => {
58958
+ if (options.attrs?.id !== void 0 && !isValidIntegerId(options.attrs.id)) {
58959
+ throw new Error("Invalid structured content id - must be an integer, got: " + options.attrs.id);
58960
+ }
58866
58961
  const structuredContentTags = getStructuredContentByGroup(group, state);
58867
58962
  if (!structuredContentTags.length) {
58868
58963
  return true;
@@ -59540,7 +59635,7 @@ const mergeRanges$2 = (ranges, docSize) => {
59540
59635
  }
59541
59636
  return merged;
59542
59637
  };
59543
- const collectChangedRanges = (trs, docSize) => {
59638
+ const collectChangedRanges$1 = (trs, docSize) => {
59544
59639
  const ranges = [];
59545
59640
  trs.forEach((tr) => {
59546
59641
  if (!tr.docChanged) return;
@@ -59743,7 +59838,7 @@ const wrapTextInRunsPlugin = (editor) => {
59743
59838
  const runType = newState.schema.nodes.run;
59744
59839
  if (!runType) return null;
59745
59840
  pendingRanges = mapRangesThroughTransactions(pendingRanges, transactions, docSize);
59746
- const changedRanges = collectChangedRanges(transactions, docSize);
59841
+ const changedRanges = collectChangedRanges$1(transactions, docSize);
59747
59842
  pendingRanges = mergeRanges$2([...pendingRanges, ...changedRanges], docSize);
59748
59843
  if (view?.composing) {
59749
59844
  return null;
@@ -74618,6 +74713,283 @@ const NodeResizer = Extension.create({
74618
74713
  return [nodeResizer(["image"], this.editor)];
74619
74714
  }
74620
74715
  });
74716
+ const PERMISSION_PLUGIN_KEY = new PluginKey("permissionRanges");
74717
+ const EVERYONE_GROUP = "everyone";
74718
+ const EMPTY_IDENTIFIER_SET = Object.freeze(/* @__PURE__ */ new Set());
74719
+ const normalizeIdentifier = (value) => typeof value === "string" ? value.trim().toLowerCase() : "";
74720
+ const buildAllowedIdentifierSet = (editor) => {
74721
+ const email = normalizeIdentifier(editor?.options?.user?.email);
74722
+ if (!email) {
74723
+ return EMPTY_IDENTIFIER_SET;
74724
+ }
74725
+ const [localPart, domain] = email.split("@");
74726
+ if (!localPart || !domain) {
74727
+ return EMPTY_IDENTIFIER_SET;
74728
+ }
74729
+ const formatted = `${domain}\\${localPart}`;
74730
+ return formatted ? /* @__PURE__ */ new Set([formatted]) : EMPTY_IDENTIFIER_SET;
74731
+ };
74732
+ const isEveryoneGroup = (value) => normalizeIdentifier(value) === EVERYONE_GROUP;
74733
+ const isRangeAllowedForUser = (attrs, allowedIdentifiers) => {
74734
+ if (!attrs) return false;
74735
+ if (isEveryoneGroup(attrs.edGrp)) {
74736
+ return true;
74737
+ }
74738
+ if (!allowedIdentifiers?.size) {
74739
+ return false;
74740
+ }
74741
+ const normalizedEd = normalizeIdentifier(attrs.ed);
74742
+ return normalizedEd && allowedIdentifiers.has(normalizedEd);
74743
+ };
74744
+ const getPermissionNodeId = (node, pos, fallbackPrefix) => String(node.attrs?.id ?? `${fallbackPrefix}-${pos}`);
74745
+ const buildPermissionState = (doc2, allowedIdentifiers = EMPTY_IDENTIFIER_SET) => {
74746
+ const ranges = [];
74747
+ const openRanges = /* @__PURE__ */ new Map();
74748
+ doc2.descendants((node, pos) => {
74749
+ if (node.type?.name === "permStart") {
74750
+ const id = getPermissionNodeId(node, pos, "permStart");
74751
+ openRanges.set(id, {
74752
+ from: pos + node.nodeSize,
74753
+ attrs: node.attrs ?? {}
74754
+ });
74755
+ return false;
74756
+ }
74757
+ if (node.type?.name === "permEnd") {
74758
+ const id = getPermissionNodeId(node, pos, "permEnd");
74759
+ const start2 = openRanges.get(id);
74760
+ if (start2 && isRangeAllowedForUser(start2.attrs, allowedIdentifiers)) {
74761
+ const to = Math.max(pos, start2.from);
74762
+ if (to > start2.from) {
74763
+ ranges.push({
74764
+ id,
74765
+ from: start2.from,
74766
+ to
74767
+ });
74768
+ }
74769
+ }
74770
+ if (start2) {
74771
+ openRanges.delete(id);
74772
+ }
74773
+ return false;
74774
+ }
74775
+ });
74776
+ return {
74777
+ ranges,
74778
+ hasAllowedRanges: ranges.length > 0
74779
+ };
74780
+ };
74781
+ const collectPermissionTags = (doc2, permStartType, permEndType) => {
74782
+ const tags = /* @__PURE__ */ new Map();
74783
+ doc2.descendants((node, pos) => {
74784
+ if (node.type !== permStartType && node.type !== permEndType) {
74785
+ return;
74786
+ }
74787
+ const id = node.attrs?.id;
74788
+ if (!id) {
74789
+ return;
74790
+ }
74791
+ const entry = tags.get(id) ?? {};
74792
+ if (node.type === permStartType) {
74793
+ entry.start = { pos, attrs: node.attrs ?? {} };
74794
+ } else if (node.type === permEndType) {
74795
+ entry.end = { pos, attrs: node.attrs ?? {} };
74796
+ }
74797
+ tags.set(id, entry);
74798
+ });
74799
+ return tags;
74800
+ };
74801
+ const clampPosition = (pos, size2) => {
74802
+ if (Number.isNaN(pos) || !Number.isFinite(pos)) {
74803
+ return 0;
74804
+ }
74805
+ return Math.max(0, Math.min(pos, size2));
74806
+ };
74807
+ const trimPermissionTagsFromRange = (doc2, range, permStartType, permEndType) => {
74808
+ let from3 = range.from;
74809
+ let to = range.to;
74810
+ while (from3 < to) {
74811
+ const node = doc2.nodeAt(from3);
74812
+ if (!node || node.type !== permStartType && node.type !== permEndType) {
74813
+ break;
74814
+ }
74815
+ from3 += node.nodeSize;
74816
+ }
74817
+ while (to > from3) {
74818
+ const $pos = doc2.resolve(to);
74819
+ const nodeBefore = $pos.nodeBefore;
74820
+ if (!nodeBefore || nodeBefore.type !== permStartType && nodeBefore.type !== permEndType) {
74821
+ break;
74822
+ }
74823
+ to -= nodeBefore.nodeSize;
74824
+ }
74825
+ return { from: from3, to };
74826
+ };
74827
+ const collectChangedRanges = (tr) => {
74828
+ const ranges = [];
74829
+ tr.mapping.maps.forEach((map3) => {
74830
+ map3.forEach((oldStart, oldEnd) => {
74831
+ const from3 = Math.min(oldStart, oldEnd);
74832
+ const to = Math.max(oldStart, oldEnd);
74833
+ ranges.push({ from: from3, to });
74834
+ });
74835
+ });
74836
+ return ranges;
74837
+ };
74838
+ const isRangeAllowed = (range, allowedRanges) => {
74839
+ if (!allowedRanges?.length) return false;
74840
+ return allowedRanges.some((allowed) => range.from >= allowed.from && range.to <= allowed.to);
74841
+ };
74842
+ const PermissionRanges = Extension.create({
74843
+ name: "permissionRanges",
74844
+ addStorage() {
74845
+ return {
74846
+ ranges: [],
74847
+ hasAllowedRanges: false
74848
+ };
74849
+ },
74850
+ addPmPlugins() {
74851
+ const editor = this.editor;
74852
+ const storage = this.storage;
74853
+ let originalSetDocumentMode = null;
74854
+ const getAllowedIdentifiers = () => buildAllowedIdentifierSet(editor);
74855
+ const toggleEditableIfAllowed = (hasAllowedRanges) => {
74856
+ if (!editor || editor.isDestroyed) return;
74857
+ if (editor.options.documentMode !== "viewing") return;
74858
+ if (hasAllowedRanges && !editor.isEditable) {
74859
+ editor.setEditable(true, false);
74860
+ } else if (!hasAllowedRanges && editor.isEditable) {
74861
+ editor.setEditable(false, false);
74862
+ }
74863
+ };
74864
+ const updateEditableState = (hasAllowedRanges) => {
74865
+ const nextValue = Boolean(hasAllowedRanges);
74866
+ const previousValue = storage.hasAllowedRanges;
74867
+ storage.hasAllowedRanges = nextValue;
74868
+ if (previousValue === nextValue) {
74869
+ return;
74870
+ }
74871
+ toggleEditableIfAllowed(nextValue);
74872
+ };
74873
+ if (editor && typeof editor.setDocumentMode === "function") {
74874
+ originalSetDocumentMode = editor.setDocumentMode.bind(editor);
74875
+ editor.setDocumentMode = (mode, caller) => {
74876
+ originalSetDocumentMode(mode, caller);
74877
+ const state = editor.state;
74878
+ if (!state) return;
74879
+ const pluginState = PERMISSION_PLUGIN_KEY.getState(state);
74880
+ if (pluginState) {
74881
+ toggleEditableIfAllowed(pluginState.hasAllowedRanges);
74882
+ }
74883
+ };
74884
+ }
74885
+ return [
74886
+ new Plugin({
74887
+ key: PERMISSION_PLUGIN_KEY,
74888
+ state: {
74889
+ init(_2, state) {
74890
+ const permissionState = buildPermissionState(state.doc, getAllowedIdentifiers());
74891
+ storage.ranges = permissionState.ranges;
74892
+ updateEditableState(permissionState.hasAllowedRanges);
74893
+ return permissionState;
74894
+ },
74895
+ apply(tr, value, _oldState, newState) {
74896
+ let permissionState = value;
74897
+ if (tr.docChanged) {
74898
+ permissionState = buildPermissionState(newState.doc, getAllowedIdentifiers());
74899
+ storage.ranges = permissionState.ranges;
74900
+ updateEditableState(permissionState.hasAllowedRanges);
74901
+ }
74902
+ return permissionState;
74903
+ }
74904
+ },
74905
+ view() {
74906
+ return {
74907
+ destroy() {
74908
+ if (editor && originalSetDocumentMode) {
74909
+ editor.setDocumentMode = originalSetDocumentMode;
74910
+ }
74911
+ }
74912
+ };
74913
+ },
74914
+ // Appends transactions to the document to ensure permission ranges are updated.
74915
+ appendTransaction(transactions, oldState, newState) {
74916
+ if (!transactions.some((tr2) => tr2.docChanged)) return null;
74917
+ const permStartType = newState.schema.nodes["permStart"];
74918
+ const permEndType = newState.schema.nodes["permEnd"];
74919
+ if (!permStartType || !permEndType) return null;
74920
+ const oldTags = collectPermissionTags(oldState.doc, permStartType, permEndType);
74921
+ if (!oldTags.size) {
74922
+ return null;
74923
+ }
74924
+ const newTags = collectPermissionTags(newState.doc, permStartType, permEndType);
74925
+ const mappingToNew = new Mapping();
74926
+ transactions.forEach((tr2) => {
74927
+ mappingToNew.appendMapping(tr2.mapping);
74928
+ });
74929
+ const pendingInsertions = [];
74930
+ oldTags.forEach((tag, id) => {
74931
+ const current = newTags.get(id);
74932
+ if (tag.start && !current?.start) {
74933
+ const mapped = mappingToNew.mapResult(tag.start.pos, -1);
74934
+ pendingInsertions.push({
74935
+ pos: mapped.pos,
74936
+ nodeType: permStartType,
74937
+ attrs: tag.start.attrs,
74938
+ priority: 0
74939
+ });
74940
+ }
74941
+ if (tag.end && !current?.end) {
74942
+ const mapped = mappingToNew.mapResult(tag.end.pos, 1);
74943
+ pendingInsertions.push({
74944
+ pos: mapped.pos,
74945
+ nodeType: permEndType,
74946
+ attrs: tag.end.attrs,
74947
+ priority: 1
74948
+ });
74949
+ }
74950
+ });
74951
+ if (!pendingInsertions.length) {
74952
+ return null;
74953
+ }
74954
+ pendingInsertions.sort((a, b2) => {
74955
+ if (a.pos === b2.pos) {
74956
+ return a.priority - b2.priority;
74957
+ }
74958
+ return a.pos - b2.pos;
74959
+ });
74960
+ const tr = newState.tr;
74961
+ let offset2 = 0;
74962
+ pendingInsertions.forEach((item) => {
74963
+ const node = item.nodeType.create(item.attrs);
74964
+ const insertPos = clampPosition(item.pos + offset2, tr.doc.content.size);
74965
+ tr.insert(insertPos, node);
74966
+ offset2 += node.nodeSize;
74967
+ });
74968
+ return tr.docChanged ? tr : null;
74969
+ },
74970
+ // Filters transactions to ensure only allowed edits are applied.
74971
+ filterTransaction(tr, state) {
74972
+ if (!tr.docChanged) return true;
74973
+ if (!editor || editor.options.documentMode !== "viewing") return true;
74974
+ const pluginState = PERMISSION_PLUGIN_KEY.getState(state);
74975
+ if (!pluginState?.hasAllowedRanges) {
74976
+ return true;
74977
+ }
74978
+ const changedRanges = collectChangedRanges(tr);
74979
+ if (!changedRanges.length) return true;
74980
+ const permStartType = state.schema.nodes["permStart"];
74981
+ const permEndType = state.schema.nodes["permEnd"];
74982
+ if (!permStartType || !permEndType) return true;
74983
+ const allRangesAllowed = changedRanges.every((range) => {
74984
+ const trimmed = trimPermissionTagsFromRange(state.doc, range, permStartType, permEndType);
74985
+ return isRangeAllowed(trimmed, pluginState.ranges);
74986
+ });
74987
+ return allRangesAllowed;
74988
+ }
74989
+ })
74990
+ ];
74991
+ }
74992
+ });
74621
74993
  const PermStart = Node$1.create({
74622
74994
  name: "permStart",
74623
74995
  group: "inline",
@@ -74777,6 +75149,7 @@ const getStarterExtensions = () => {
74777
75149
  ShapeGroup,
74778
75150
  PermStart,
74779
75151
  PermEnd,
75152
+ PermissionRanges,
74780
75153
  PassthroughInline,
74781
75154
  PassthroughBlock
74782
75155
  ];
@@ -1,5 +1,5 @@
1
- import { B as BIT8, M as MAX_SAFE_INTEGER, c as create, a as BITS7, u as utf8TextDecoder, b as create$1, s as setIfUndefined, d as create$2, f as from, e as floor$1, g as equalityDeep, w as writeVarUint, h as writeVarString, t as toUint8Array, i as createEncoder, j as createInjectionKey, k as toString, l as throwError, m as useSsrAdapter, n as configProviderInjectionKey, o as cssrAnchorMetaName, p as globalStyle, q as cB, r as c, v as isMounted, x as commonVariables$2, y as cM, z as cNotM, A as cE, C as derived, D as changeColor, E as insideModal, F as insidePopover, G as resolveWrappedSlot, H as on, I as warnOnce, J as useConfig, K as useMergedState, L as useMemo, N as useTheme, O as useRtl, P as createKey, Q as useThemeClass, R as createId, S as call, T as render, U as messageProviderInjectionKey, V as messageApiInjectionKey, W as fromBase64, X as onChange, Y as varStorage, Z as toBase64, _ as createUint8ArrayFromArrayBuffer, $ as offChange, a0 as writeVarUint8Array, a1 as map, a2 as length, a3 as isNode, a4 as min, a5 as pow, a6 as comments_module_events, a7 as getFileObject, a8 as getTrackChanges, a9 as CommentsPluginKey, aa as TrackChangesBasePluginKey, ab as Editor, ac as getRichTextExtensions, ad as ellipsisVerticalSvg, ae as xmarkIconSvg, af as checkIconSvg, ag as caretDownIconSvg, ah as commentIconSvg, ai as _export_sfc, aj as NDropdown, ak as SuperInput, al as vClickOutside, am as PresentationEditor, an as SuperEditor, ao as AIWriter, ap as NConfigProvider, aq as SuperToolbar } from "./index-7ebfCUN0.es.js";
2
- import "./SuperConverter-S5AfMnkn.es.js";
1
+ import { B as BIT8, M as MAX_SAFE_INTEGER, c as create, a as BITS7, u as utf8TextDecoder, b as create$1, s as setIfUndefined, d as create$2, f as from, e as floor$1, g as equalityDeep, w as writeVarUint, h as writeVarString, t as toUint8Array, i as createEncoder, j as createInjectionKey, k as toString, l as throwError, m as useSsrAdapter, n as configProviderInjectionKey, o as cssrAnchorMetaName, p as globalStyle, q as cB, r as c, v as isMounted, x as commonVariables$2, y as cM, z as cNotM, A as cE, C as derived, D as changeColor, E as insideModal, F as insidePopover, G as resolveWrappedSlot, H as on, I as warnOnce, J as useConfig, K as useMergedState, L as useMemo, N as useTheme, O as useRtl, P as createKey, Q as useThemeClass, R as createId, S as call, T as render, U as messageProviderInjectionKey, V as messageApiInjectionKey, W as fromBase64, X as onChange, Y as varStorage, Z as toBase64, _ as createUint8ArrayFromArrayBuffer, $ as offChange, a0 as writeVarUint8Array, a1 as map, a2 as length, a3 as isNode, a4 as min, a5 as pow, a6 as comments_module_events, a7 as getFileObject, a8 as getTrackChanges, a9 as CommentsPluginKey, aa as TrackChangesBasePluginKey, ab as Editor, ac as getRichTextExtensions, ad as ellipsisVerticalSvg, ae as xmarkIconSvg, af as checkIconSvg, ag as caretDownIconSvg, ah as commentIconSvg, ai as _export_sfc, aj as NDropdown, ak as SuperInput, al as vClickOutside, am as PresentationEditor, an as SuperEditor, ao as AIWriter, ap as NConfigProvider, aq as SuperToolbar } from "./index-CfwhHibT.es.js";
2
+ import "./SuperConverter-meS8FJqm.es.js";
3
3
  import { B as BlankDOCX } from "./blank-docx-ABm6XYAA.es.js";
4
4
  import { E as EventEmitter } from "./eventemitter3-CwrdEv8r.es.js";
5
5
  import { HocuspocusProvider, HocuspocusProviderWebsocket } from "@hocuspocus/provider";
@@ -7513,7 +7513,7 @@ const _sfc_main = {
7513
7513
  __name: "SuperDoc",
7514
7514
  emits: ["selection-update"],
7515
7515
  setup(__props, { emit: __emit }) {
7516
- const PdfViewer = defineAsyncComponent(() => import("./PdfViewer-ClST5VR6.es.js"));
7516
+ const PdfViewer = defineAsyncComponent(() => import("./PdfViewer-CYai_OkL.es.js"));
7517
7517
  const superdocStore = useSuperdocStore();
7518
7518
  const commentsStore = useCommentsStore();
7519
7519
  const {
@@ -8467,7 +8467,7 @@ class SuperDoc extends EventEmitter {
8467
8467
  this.config.colors = shuffleArray(this.config.colors);
8468
8468
  this.userColorMap = /* @__PURE__ */ new Map();
8469
8469
  this.colorIndex = 0;
8470
- this.version = "1.5.0-next.7";
8470
+ this.version = "1.5.0-next.9";
8471
8471
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
8472
8472
  this.superdocId = config.superdocId || v4();
8473
8473
  this.colors = this.config.colors;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const index = require("./index-LpMObyDy.cjs");
3
- require("./SuperConverter-CIjArITT.cjs");
2
+ const index = require("./index-3B3UnhZ-.cjs");
3
+ require("./SuperConverter-Ck9J4dUw.cjs");
4
4
  const blankDocx = require("./blank-docx-DfW3Eeh2.cjs");
5
5
  const eventemitter3 = require("./eventemitter3-BQuRcMPI.cjs");
6
6
  const provider = require("@hocuspocus/provider");
@@ -7530,7 +7530,7 @@ const _sfc_main = {
7530
7530
  __name: "SuperDoc",
7531
7531
  emits: ["selection-update"],
7532
7532
  setup(__props, { emit: __emit }) {
7533
- const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-Cli6IR-X.cjs")));
7533
+ const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-CJrP6IEy.cjs")));
7534
7534
  const superdocStore = useSuperdocStore();
7535
7535
  const commentsStore = useCommentsStore();
7536
7536
  const {
@@ -8484,7 +8484,7 @@ class SuperDoc extends eventemitter3.EventEmitter {
8484
8484
  this.config.colors = shuffleArray(this.config.colors);
8485
8485
  this.userColorMap = /* @__PURE__ */ new Map();
8486
8486
  this.colorIndex = 0;
8487
- this.version = "1.5.0-next.7";
8487
+ this.version = "1.5.0-next.9";
8488
8488
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
8489
8489
  this.superdocId = config.superdocId || uuid.v4();
8490
8490
  this.colors = this.config.colors;