@harbour-enterprises/superdoc 1.7.0-next.8 → 1.7.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,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const vue = require("./vue-De9wkgLl.cjs");
4
- const superdoc = require("./index-FiJG3jxE.cjs");
5
- const index = require("./index-CYnDWjvg.cjs");
4
+ const superdoc = require("./index-CDRAe8oj.cjs");
5
+ const index = require("./index-nEA2vtLH.cjs");
6
6
  function self(vars) {
7
7
  const {
8
8
  opacityDisabled,
@@ -1,6 +1,6 @@
1
1
  import { d as defineComponent, h, T as Transition, p as process$1, w as watchEffect, c as computed, r as ref, f as onMounted, X as onUnmounted, E as createElementBlock, G as openBlock, K as createBaseVNode, M as createCommentVNode, I as createVNode, v as unref } from "./vue-BnBKJwCW.es.js";
2
- import { N as NBaseLoading, u as useSuperdocStore, s as storeToRefs, a as useSelection } from "./index-DGCJio0S.es.js";
3
- import { C as derived, r as c, q as cB, aF as fadeInTransition, y as cM, I as warnOnce, J as useConfig, N as useTheme, aG as pxfy, P as createKey, Q as useThemeClass, aH as useCompitable, ai as _export_sfc } from "./index-DTJCOo2w.es.js";
2
+ import { N as NBaseLoading, u as useSuperdocStore, s as storeToRefs, a as useSelection } from "./index-Dho4ex7D.es.js";
3
+ import { C as derived, r as c, q as cB, aF as fadeInTransition, y as cM, I as warnOnce, J as useConfig, N as useTheme, aG as pxfy, P as createKey, Q as useThemeClass, aH as useCompitable, ai as _export_sfc } from "./index-C070FBOz.es.js";
4
4
  function self(vars) {
5
5
  const {
6
6
  opacityDisabled,
@@ -27557,7 +27557,46 @@ const decode$l = (params) => {
27557
27557
  };
27558
27558
  commentSchema = [commentSchema, commentReference];
27559
27559
  }
27560
- return commentSchema;
27560
+ const usesRangeThreading = originalComment.threadingStyleOverride === "range-based" || originalComment.threadingMethod === "range-based" || originalComment.originalXmlStructure?.hasCommentsExtended === false;
27561
+ if (!usesRangeThreading) {
27562
+ return commentSchema;
27563
+ }
27564
+ const trackedMark = node.marks?.find((mark) => mark.type === "trackInsert" || mark.type === "trackDelete");
27565
+ if (trackedMark) {
27566
+ const wrapperName2 = trackedMark.type === "trackDelete" ? "w:del" : "w:ins";
27567
+ const markAttrs = trackedMark.attrs || {};
27568
+ const date2 = markAttrs.date || new Date(Date.now()).toISOString().replace(/\.\d{3}Z$/, "Z");
27569
+ const wrapperAttributes2 = {
27570
+ ...markAttrs.id ? { "w:id": String(markAttrs.id) } : {},
27571
+ ...markAttrs.author ? { "w:author": markAttrs.author } : {},
27572
+ ...markAttrs.authorEmail ? { "w:authorEmail": markAttrs.authorEmail } : {},
27573
+ "w:date": date2
27574
+ };
27575
+ return {
27576
+ name: wrapperName2,
27577
+ attributes: wrapperAttributes2,
27578
+ elements: Array.isArray(commentSchema) ? commentSchema : [commentSchema]
27579
+ };
27580
+ }
27581
+ if (!parentComment?.trackedChange) {
27582
+ return commentSchema;
27583
+ }
27584
+ const trackedChangeType = parentComment.trackedChangeType;
27585
+ const isReplace = trackedChangeType === "both";
27586
+ const wrapperName = type === "commentRangeStart" ? "w:ins" : isReplace ? "w:del" : trackedChangeType === "trackDelete" ? "w:del" : "w:ins";
27587
+ const createdTime = parentComment.createdTime || Date.now();
27588
+ const date = new Date(createdTime).toISOString().replace(/\.\d{3}Z$/, "Z");
27589
+ const wrapperAttributes = {
27590
+ "w:id": String(parentComment.commentId),
27591
+ ...parentComment.creatorName ? { "w:author": parentComment.creatorName } : {},
27592
+ ...parentComment.creatorEmail ? { "w:authorEmail": parentComment.creatorEmail } : {},
27593
+ "w:date": date
27594
+ };
27595
+ return {
27596
+ name: wrapperName,
27597
+ attributes: wrapperAttributes,
27598
+ elements: Array.isArray(commentSchema) ? commentSchema : [commentSchema]
27599
+ };
27561
27600
  };
27562
27601
  const getCommentSchema = (type, commentIndex) => {
27563
27602
  return {
@@ -29160,6 +29199,15 @@ function importCommentData({ docx, editor, converter }) {
29160
29199
  const nodeListHandler = defaultNodeListHandler();
29161
29200
  const comments = docx["word/comments.xml"];
29162
29201
  if (!comments) return;
29202
+ const commentThreadingProfile = converter?.commentThreadingProfile || {
29203
+ defaultStyle: docx["word/commentsExtended.xml"] ? "commentsExtended" : "range-based",
29204
+ mixed: false,
29205
+ fileSet: {
29206
+ hasCommentsExtended: !!docx["word/commentsExtended.xml"],
29207
+ hasCommentsExtensible: !!docx["word/commentsExtensible.xml"],
29208
+ hasCommentsIds: !!docx["word/commentsIds.xml"]
29209
+ }
29210
+ };
29163
29211
  const { elements } = comments;
29164
29212
  if (!elements || !elements.length) return;
29165
29213
  const { elements: allComments = [] } = elements[0];
@@ -29187,8 +29235,7 @@ function importCommentData({ docx, editor, converter }) {
29187
29235
  });
29188
29236
  const lastElement = parsedElements[parsedElements.length - 1];
29189
29237
  const paraId = lastElement?.attrs?.["w14:paraId"];
29190
- const commentsExtended = docx["word/commentsExtended.xml"];
29191
- const threadingMethod = commentsExtended ? "commentsExtended" : "range-based";
29238
+ const threadingMethod = commentThreadingProfile.defaultStyle;
29192
29239
  return {
29193
29240
  commentId: internalId || v4(),
29194
29241
  importedId,
@@ -29206,21 +29253,45 @@ function importCommentData({ docx, editor, converter }) {
29206
29253
  isDone: false,
29207
29254
  origin: converter?.documentOrigin || "word",
29208
29255
  threadingMethod,
29256
+ threadingStyleOverride: void 0,
29209
29257
  originalXmlStructure: {
29210
- hasCommentsExtended: !!commentsExtended,
29211
- hasCommentsExtensible: !!docx["word/commentsExtensible.xml"],
29212
- hasCommentsIds: !!docx["word/commentsIds.xml"]
29258
+ ...commentThreadingProfile.fileSet
29213
29259
  }
29214
29260
  };
29215
29261
  });
29216
- const extendedComments = generateCommentsWithExtendedData({ docx, comments: extractedComments, converter });
29262
+ const extendedComments = generateCommentsWithExtendedData({
29263
+ docx,
29264
+ comments: extractedComments,
29265
+ converter,
29266
+ threadingProfile: commentThreadingProfile
29267
+ });
29268
+ if (converter) {
29269
+ const hasOverride = extendedComments.some(
29270
+ (comment) => comment.threadingStyleOverride && comment.threadingStyleOverride !== commentThreadingProfile.defaultStyle
29271
+ );
29272
+ converter.commentThreadingProfile = {
29273
+ ...commentThreadingProfile,
29274
+ mixed: hasOverride || commentThreadingProfile.mixed
29275
+ };
29276
+ }
29217
29277
  return extendedComments;
29218
29278
  }
29219
- const generateCommentsWithExtendedData = ({ docx, comments, converter }) => {
29279
+ const generateCommentsWithExtendedData = ({ docx, comments, converter, threadingProfile }) => {
29220
29280
  if (!comments?.length) return [];
29221
29281
  const rangeData = extractCommentRangesFromDocument(docx, converter);
29222
29282
  const { commentsInTrackedChanges } = rangeData;
29223
29283
  const trackedChangeParentMap = detectThreadingFromTrackedChanges(comments, commentsInTrackedChanges);
29284
+ const rangeThreadedComments = detectThreadingFromRanges(comments, {
29285
+ ...rangeData,
29286
+ commentsInTrackedChanges: /* @__PURE__ */ new Map()
29287
+ });
29288
+ const commentIdSet = new Set(comments.map((comment) => comment.commentId));
29289
+ const rangeParentMap = /* @__PURE__ */ new Map();
29290
+ rangeThreadedComments.forEach((comment) => {
29291
+ if (comment.parentCommentId && commentIdSet.has(comment.parentCommentId)) {
29292
+ rangeParentMap.set(comment.commentId, comment.parentCommentId);
29293
+ }
29294
+ });
29224
29295
  const commentsExtended = docx["word/commentsExtended.xml"];
29225
29296
  if (!commentsExtended) {
29226
29297
  const commentsWithThreading = detectThreadingFromRanges(comments, rangeData);
@@ -29239,25 +29310,43 @@ const generateCommentsWithExtendedData = ({ docx, comments, converter }) => {
29239
29310
  });
29240
29311
  let isDone = comment.isDone ?? false;
29241
29312
  let parentCommentId = void 0;
29313
+ let threadingParentCommentId = void 0;
29314
+ let threadingStyleOverride = void 0;
29242
29315
  const trackedChangeParent = trackedChangeParentMap.get(comment.importedId);
29243
29316
  const isInsideTrackedChange = trackedChangeParent?.isTrackedChangeParent;
29244
29317
  if (extendedDef) {
29245
29318
  const details = getExtendedDetails(extendedDef);
29246
29319
  isDone = details.isDone ?? false;
29247
- if (!isInsideTrackedChange && details.paraIdParent) {
29320
+ if (details.paraIdParent) {
29248
29321
  const parentComment = comments.find(
29249
29322
  (c) => c.paraId === details.paraIdParent || c.elements?.some((el) => el.attrs?.["w14:paraId"] === details.paraIdParent)
29250
29323
  );
29251
- parentCommentId = parentComment?.commentId;
29324
+ const rangeParent = rangeParentMap.get(comment.commentId);
29325
+ if (parentComment?.trackedChange && rangeParent) {
29326
+ threadingParentCommentId = rangeParent;
29327
+ } else {
29328
+ threadingParentCommentId = parentComment?.commentId;
29329
+ }
29330
+ if (!isInsideTrackedChange) {
29331
+ parentCommentId = threadingParentCommentId;
29332
+ }
29252
29333
  }
29253
29334
  }
29254
29335
  if (isInsideTrackedChange) {
29255
29336
  parentCommentId = trackedChangeParent.trackedChangeId;
29256
29337
  }
29338
+ if (!parentCommentId && rangeParentMap.has(comment.commentId)) {
29339
+ parentCommentId = rangeParentMap.get(comment.commentId);
29340
+ if (threadingProfile?.defaultStyle === "commentsExtended") {
29341
+ threadingStyleOverride = "range-based";
29342
+ }
29343
+ }
29257
29344
  return {
29258
29345
  ...comment,
29259
29346
  isDone,
29260
- parentCommentId
29347
+ parentCommentId,
29348
+ threadingStyleOverride,
29349
+ threadingParentCommentId
29261
29350
  };
29262
29351
  });
29263
29352
  };
@@ -30133,12 +30222,27 @@ const detectDocumentOrigin = (docx) => {
30133
30222
  }
30134
30223
  return "unknown";
30135
30224
  };
30225
+ const detectCommentThreadingProfile = (docx) => {
30226
+ const hasCommentsExtended = !!docx["word/commentsExtended.xml"];
30227
+ const hasCommentsExtensible = !!docx["word/commentsExtensible.xml"];
30228
+ const hasCommentsIds = !!docx["word/commentsIds.xml"];
30229
+ return {
30230
+ defaultStyle: hasCommentsExtended ? "commentsExtended" : "range-based",
30231
+ mixed: false,
30232
+ fileSet: {
30233
+ hasCommentsExtended,
30234
+ hasCommentsExtensible,
30235
+ hasCommentsIds
30236
+ }
30237
+ };
30238
+ };
30136
30239
  const createDocumentJson = (docx, converter, editor) => {
30137
30240
  const json = carbonCopy(getInitialJSON(docx));
30138
30241
  if (!json) return null;
30139
30242
  if (converter) {
30140
30243
  importFootnotePropertiesFromSettings(docx, converter);
30141
30244
  converter.documentOrigin = detectDocumentOrigin(docx);
30245
+ converter.commentThreadingProfile = detectCommentThreadingProfile(docx);
30142
30246
  }
30143
30247
  if (converter?.telemetry) {
30144
30248
  const files = Object.keys(docx).map((filePath) => {
@@ -32296,8 +32400,18 @@ const determineExportStrategy = (comments) => {
32296
32400
  }
32297
32401
  return "word";
32298
32402
  };
32299
- const updateCommentsExtendedXml = (comments = [], commentsExtendedXml, exportStrategy = "word") => {
32300
- const shouldGenerateCommentsExtended = exportStrategy === "word" || comments.some((c) => c.originalXmlStructure?.hasCommentsExtended);
32403
+ const resolveThreadingStyle = (comment, threadingProfile) => {
32404
+ if (comment?.threadingStyleOverride) return comment.threadingStyleOverride;
32405
+ if (threadingProfile?.defaultStyle) return threadingProfile.defaultStyle;
32406
+ return comment?.originalXmlStructure?.hasCommentsExtended ? "commentsExtended" : "range-based";
32407
+ };
32408
+ const updateCommentsExtendedXml = (comments = [], commentsExtendedXml, threadingProfile = null) => {
32409
+ if (!commentsExtendedXml) {
32410
+ return null;
32411
+ }
32412
+ const exportStrategy = typeof threadingProfile === "string" ? threadingProfile : "word";
32413
+ const profile = typeof threadingProfile === "string" ? null : threadingProfile;
32414
+ const shouldGenerateCommentsExtended = profile ? profile.defaultStyle === "commentsExtended" || profile.mixed || comments.some((comment) => resolveThreadingStyle(comment, profile) === "commentsExtended") : exportStrategy === "word" || comments.some((c) => c.originalXmlStructure?.hasCommentsExtended);
32301
32415
  if (!shouldGenerateCommentsExtended && exportStrategy === "google-docs") {
32302
32416
  return null;
32303
32417
  }
@@ -32308,10 +32422,12 @@ const updateCommentsExtendedXml = (comments = [], commentsExtendedXml, exportStr
32308
32422
  "w15:paraId": comment.commentParaId,
32309
32423
  "w15:done": isResolved ? "1" : "0"
32310
32424
  };
32311
- const parentId = comment.parentCommentId;
32312
- if (parentId && (exportStrategy === "word" || comment.originalXmlStructure?.hasCommentsExtended)) {
32425
+ const parentId = comment.threadingParentCommentId || comment.parentCommentId;
32426
+ const threadingStyle = resolveThreadingStyle(comment, profile);
32427
+ if (parentId && threadingStyle === "commentsExtended") {
32313
32428
  const parentComment = comments.find((c) => c.commentId === parentId);
32314
- if (parentComment && !parentComment.trackedChange) {
32429
+ const allowTrackedParent = profile?.defaultStyle === "commentsExtended";
32430
+ if (parentComment && (allowTrackedParent || !parentComment.trackedChange)) {
32315
32431
  attributes["w15:paraIdParent"] = parentComment.commentParaId;
32316
32432
  }
32317
32433
  }
@@ -32355,12 +32471,15 @@ const updateCommentsIdsAndExtensible = (comments = [], commentsIds, extensible)
32355
32471
  extensibleUpdated
32356
32472
  };
32357
32473
  };
32358
- const generateConvertedXmlWithCommentFiles = (convertedXml) => {
32474
+ const generateConvertedXmlWithCommentFiles = (convertedXml, fileSet = null) => {
32359
32475
  const newXml = carbonCopy(convertedXml);
32360
32476
  newXml["word/comments.xml"] = COMMENTS_XML_DEFINITIONS.COMMENTS_XML_DEF;
32361
- newXml["word/commentsExtended.xml"] = COMMENTS_XML_DEFINITIONS.COMMENTS_EXTENDED_XML_DEF;
32362
- newXml["word/commentsExtensible.xml"] = COMMENTS_XML_DEFINITIONS.COMMENTS_EXTENSIBLE_XML_DEF;
32363
- newXml["word/commentsIds.xml"] = COMMENTS_XML_DEFINITIONS.COMMENTS_IDS_XML_DEF;
32477
+ const includeExtended = fileSet ? fileSet.hasCommentsExtended : true;
32478
+ const includeExtensible = fileSet ? fileSet.hasCommentsExtensible : true;
32479
+ const includeIds = fileSet ? fileSet.hasCommentsIds : true;
32480
+ if (includeExtended) newXml["word/commentsExtended.xml"] = COMMENTS_XML_DEFINITIONS.COMMENTS_EXTENDED_XML_DEF;
32481
+ if (includeExtensible) newXml["word/commentsExtensible.xml"] = COMMENTS_XML_DEFINITIONS.COMMENTS_EXTENSIBLE_XML_DEF;
32482
+ if (includeIds) newXml["word/commentsIds.xml"] = COMMENTS_XML_DEFINITIONS.COMMENTS_IDS_XML_DEF;
32364
32483
  newXml["[Content_Types].xml"] = COMMENTS_XML_DEFINITIONS.CONTENT_TYPES;
32365
32484
  return newXml;
32366
32485
  };
@@ -32377,20 +32496,26 @@ const generateRelationship = (target) => {
32377
32496
  const rel = relsDefault.find((rel2) => rel2.attributes.Target === target);
32378
32497
  return { ...rel };
32379
32498
  };
32380
- const prepareCommentsXmlFilesForExport = ({ convertedXml, defs, commentsWithParaIds, exportType }) => {
32499
+ const prepareCommentsXmlFilesForExport = ({
32500
+ convertedXml,
32501
+ defs,
32502
+ commentsWithParaIds,
32503
+ exportType,
32504
+ threadingProfile
32505
+ }) => {
32381
32506
  const relationships = [];
32382
32507
  if (exportType === "clean") {
32383
32508
  const documentXml = removeCommentsFilesFromConvertedXml(convertedXml);
32384
32509
  return { documentXml, relationships };
32385
32510
  }
32386
32511
  const exportStrategy = determineExportStrategy(commentsWithParaIds);
32387
- const updatedXml = generateConvertedXmlWithCommentFiles(convertedXml);
32512
+ const updatedXml = generateConvertedXmlWithCommentFiles(convertedXml, threadingProfile?.fileSet);
32388
32513
  updatedXml["word/comments.xml"] = updateCommentsXml(defs, updatedXml["word/comments.xml"]);
32389
32514
  relationships.push(generateRelationship("comments.xml"));
32390
32515
  const commentsExtendedXml = updateCommentsExtendedXml(
32391
32516
  commentsWithParaIds,
32392
32517
  updatedXml["word/commentsExtended.xml"],
32393
- exportStrategy
32518
+ threadingProfile || exportStrategy
32394
32519
  );
32395
32520
  if (commentsExtendedXml !== null) {
32396
32521
  updatedXml["word/commentsExtended.xml"] = commentsExtendedXml;
@@ -32398,15 +32523,17 @@ const prepareCommentsXmlFilesForExport = ({ convertedXml, defs, commentsWithPara
32398
32523
  } else {
32399
32524
  delete updatedXml["word/commentsExtended.xml"];
32400
32525
  }
32401
- const { documentIdsUpdated, extensibleUpdated } = updateCommentsIdsAndExtensible(
32402
- commentsWithParaIds,
32403
- updatedXml["word/commentsIds.xml"],
32404
- updatedXml["word/commentsExtensible.xml"]
32405
- );
32406
- updatedXml["word/commentsIds.xml"] = documentIdsUpdated;
32407
- updatedXml["word/commentsExtensible.xml"] = extensibleUpdated;
32408
- relationships.push(generateRelationship("commentsIds.xml"));
32409
- relationships.push(generateRelationship("commentsExtensible.xml"));
32526
+ if (updatedXml["word/commentsIds.xml"] && updatedXml["word/commentsExtensible.xml"]) {
32527
+ const { documentIdsUpdated, extensibleUpdated } = updateCommentsIdsAndExtensible(
32528
+ commentsWithParaIds,
32529
+ updatedXml["word/commentsIds.xml"],
32530
+ updatedXml["word/commentsExtensible.xml"]
32531
+ );
32532
+ updatedXml["word/commentsIds.xml"] = documentIdsUpdated;
32533
+ updatedXml["word/commentsExtensible.xml"] = extensibleUpdated;
32534
+ relationships.push(generateRelationship("commentsIds.xml"));
32535
+ relationships.push(generateRelationship("commentsExtensible.xml"));
32536
+ }
32410
32537
  return {
32411
32538
  relationships,
32412
32539
  documentXml: updatedXml
@@ -32757,6 +32884,7 @@ class SuperConverter {
32757
32884
  this.footnotes = [];
32758
32885
  this.footnoteProperties = null;
32759
32886
  this.inlineDocumentFonts = [];
32887
+ this.commentThreadingProfile = null;
32760
32888
  this.docHiglightColors = /* @__PURE__ */ new Set([]);
32761
32889
  this.xml = params?.xml;
32762
32890
  this.declaration = null;
@@ -33071,7 +33199,7 @@ class SuperConverter {
33071
33199
  static getStoredSuperdocVersion(docx) {
33072
33200
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
33073
33201
  }
33074
- static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.7.0-next.8") {
33202
+ static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.7.0-next.9") {
33075
33203
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version, false);
33076
33204
  }
33077
33205
  /**
@@ -33471,7 +33599,8 @@ class SuperConverter {
33471
33599
  exportType,
33472
33600
  convertedXml: this.convertedXml,
33473
33601
  defs,
33474
- commentsWithParaIds
33602
+ commentsWithParaIds,
33603
+ threadingProfile: this.commentThreadingProfile
33475
33604
  });
33476
33605
  return { documentXml, relationships };
33477
33606
  }