@harbour-enterprises/superdoc 1.0.0-beta.8 → 1.0.0

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.
Files changed (48) hide show
  1. package/dist/chunks/{PdfViewer-DJ7BWUbW.cjs → PdfViewer-C3_5zd7y.cjs} +2 -2
  2. package/dist/chunks/{PdfViewer-BfEwF25T.es.js → PdfViewer-OoqzzuS4.es.js} +2 -2
  3. package/dist/chunks/{eventemitter3-ByBH0NYV.es.js → eventemitter3-CcXAdeql.es.js} +1 -1
  4. package/dist/chunks/{eventemitter3-CFCpOk3d.cjs → eventemitter3-DQmQUge-.cjs} +1 -1
  5. package/dist/chunks/{index-BCZ82zY5.es.js → index-BwFit1xu.es.js} +112 -41
  6. package/dist/chunks/{index-DJrRlj1_-HA-nVwDO.es.js → index-CDIpuWy0-DcqcEnVR.es.js} +1 -1
  7. package/dist/chunks/{index-DJrRlj1_-E5dmStMF.cjs → index-CDIpuWy0-v1ZRfNmH.cjs} +1 -1
  8. package/dist/chunks/{index-DMwWcmrk.cjs → index-CVDEHD5c.cjs} +112 -41
  9. package/dist/chunks/{jszip-BwsONqK5.es.js → jszip-5vvIqAEE.es.js} +1 -1
  10. package/dist/chunks/{jszip-B99MTu59.cjs → jszip-BdEez1WM.cjs} +1 -1
  11. package/dist/chunks/{super-editor.es-Bo_fWMy6.cjs → super-editor.es-CWr0w1Tk.cjs} +37747 -20889
  12. package/dist/chunks/{super-editor.es-MRWI4sfo.es.js → super-editor.es-Ddl20DOa.es.js} +37747 -20889
  13. package/dist/chunks/{vue-CztqUvm1.es.js → vue-Dysv_7z5.es.js} +101 -12
  14. package/dist/chunks/{vue-ARQSyfaw.cjs → vue-jWLMl8Ts.cjs} +89 -0
  15. package/dist/chunks/xml-js-ClO_jHnq.es.js +2 -0
  16. package/dist/chunks/xml-js-Dz51sEbr.cjs +3 -0
  17. package/dist/packages/superdoc/src/components/CommentsLayer/use-comment.d.ts.map +1 -1
  18. package/dist/packages/superdoc/src/composables/use-document.d.ts.map +1 -1
  19. package/dist/packages/superdoc/src/core/SuperDoc.d.ts +2 -2
  20. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  21. package/dist/packages/superdoc/src/core/collaboration/collaboration.d.ts +11 -0
  22. package/dist/packages/superdoc/src/core/collaboration/collaboration.d.ts.map +1 -1
  23. package/dist/packages/superdoc/src/core/types/index.d.ts +66 -3
  24. package/dist/packages/superdoc/src/core/types/index.d.ts.map +1 -1
  25. package/dist/packages/superdoc/src/stores/comments-store.d.ts.map +1 -1
  26. package/dist/style.css +90 -51
  27. package/dist/super-editor/ai-writer.es.js +2 -2
  28. package/dist/super-editor/chunks/{converter-CflxlFnM.js → converter-CuIVo-Y-.js} +7295 -811
  29. package/dist/super-editor/chunks/{docx-zipper-DKWL4mo2.js → docx-zipper-D24ieyrf.js} +15 -11
  30. package/dist/super-editor/chunks/{editor-B9V7oJbW.js → editor-DyocbwIp.js} +18722 -8867
  31. package/dist/super-editor/chunks/{index-DJrRlj1_.js → index-CDIpuWy0.js} +1 -1
  32. package/dist/super-editor/chunks/{toolbar-B5WlPN4s.js → toolbar-WQTQjgeN.js} +36 -22
  33. package/dist/super-editor/converter.es.js +1 -1
  34. package/dist/super-editor/docx-zipper.es.js +2 -2
  35. package/dist/super-editor/editor.es.js +3 -3
  36. package/dist/super-editor/file-zipper.es.js +2 -2
  37. package/dist/super-editor/style.css +57 -18
  38. package/dist/super-editor/super-editor.es.js +1025 -226
  39. package/dist/super-editor/toolbar.es.js +2 -2
  40. package/dist/super-editor.cjs +4 -4
  41. package/dist/super-editor.es.js +2 -2
  42. package/dist/superdoc.cjs +2 -2
  43. package/dist/superdoc.es.js +2 -2
  44. package/dist/superdoc.umd.js +37527 -20522
  45. package/dist/superdoc.umd.js.map +1 -1
  46. package/package.json +1 -1
  47. package/dist/chunks/xml-js-BZPSMmVo.es.js +0 -2
  48. package/dist/chunks/xml-js-DQa4Ye5C.cjs +0 -3
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
- const superEditor_es = require("./super-editor.es-Bo_fWMy6.cjs");
2
+ const superEditor_es = require("./super-editor.es-CWr0w1Tk.cjs");
3
3
  const blankDocx = require("./blank-docx-DfW3Eeh2.cjs");
4
- const eventemitter3 = require("./eventemitter3-CFCpOk3d.cjs");
4
+ const eventemitter3 = require("./eventemitter3-DQmQUge-.cjs");
5
5
  const provider = require("@hocuspocus/provider");
6
- const vue = require("./vue-ARQSyfaw.cjs");
6
+ const vue = require("./vue-jWLMl8Ts.cjs");
7
7
  const Y = require("yjs");
8
- const jszip = require("./jszip-B99MTu59.cjs");
8
+ const jszip = require("./jszip-BdEez1WM.cjs");
9
9
  const uuid = require("./uuid-R7L08bOx.cjs");
10
10
  function _interopNamespaceDefault(e) {
11
11
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -3252,6 +3252,9 @@ function awarenessHandler(context, { changes = {}, states }) {
3252
3252
  context.emit("awareness-update", payload);
3253
3253
  }
3254
3254
  function createProvider({ config, user, documentId, socket, superdocInstance }) {
3255
+ console.warn(
3256
+ "[superdoc] Internal provider creation is deprecated. Pass { ydoc, provider } to modules.collaboration instead."
3257
+ );
3255
3258
  if (!config.providerType) config.providerType = "superdoc";
3256
3259
  const providers = {
3257
3260
  hocuspocus: () => createHocuspocusProvider({ config, user, documentId, socket, superdocInstance }),
@@ -3308,6 +3311,22 @@ const onDisconnect = (superdocInstance, documentId) => {
3308
3311
  const onDestroy = (superdocInstance, documentId) => {
3309
3312
  console.warn("🔌 [superdoc] Destroyed", documentId);
3310
3313
  };
3314
+ function setupAwarenessHandler(provider2, superdocInstance, user) {
3315
+ const awareness = provider2.awareness;
3316
+ if (!awareness) {
3317
+ console.warn("[superdoc] External provider missing awareness property");
3318
+ return;
3319
+ }
3320
+ if (user && awareness.setLocalStateField) {
3321
+ awareness.setLocalStateField("user", user);
3322
+ }
3323
+ awareness.on("change", (changes = {}) => {
3324
+ awarenessHandler(superdocInstance, {
3325
+ changes,
3326
+ states: awareness.getStates()
3327
+ });
3328
+ });
3329
+ }
3311
3330
  const addYComment = (yArray, ydoc, event) => {
3312
3331
  const { comment } = event;
3313
3332
  const yComment = new Y.Map(Object.entries(comment));
@@ -3482,6 +3501,7 @@ function useComment(params2) {
3482
3501
  const creatorImage = params2.creatorImage;
3483
3502
  const createdTime = params2.createdTime || Date.now();
3484
3503
  const importedAuthor = vue.ref(params2.importedAuthor || null);
3504
+ const docxCommentJSON = params2.docxCommentJSON || null;
3485
3505
  const commentText = vue.ref(params2.commentText || "");
3486
3506
  const selection = params2.selection ? useSelection(params2.selection) : useSelection({
3487
3507
  documentId: fileId,
@@ -3596,6 +3616,7 @@ function useComment(params2) {
3596
3616
  creatorImage,
3597
3617
  createdTime,
3598
3618
  importedAuthor: importedAuthor.value,
3619
+ docxCommentJSON,
3599
3620
  isInternal: isInternal.value,
3600
3621
  commentText: commentText.value,
3601
3622
  selection: selection ? selection.getValues() : null,
@@ -3634,6 +3655,7 @@ function useComment(params2) {
3634
3655
  resolvedByEmail,
3635
3656
  resolvedByName,
3636
3657
  importedAuthor,
3658
+ docxCommentJSON,
3637
3659
  // Actions
3638
3660
  setText,
3639
3661
  getValues,
@@ -3669,8 +3691,8 @@ function useDocument(params2, superdocConfig) {
3669
3691
  const getPresentationEditor = () => presentationEditorRef.value;
3670
3692
  function initDocumentType({ type: type2, data: data2 }) {
3671
3693
  if (data2?.type) return data2.type;
3672
- if (type2) return type2 in documentTypes ? documentTypes[type2] : null;
3673
- throw new Error("Document type not specified for doc:", params2);
3694
+ if (type2) return documentTypes[type2] || type2;
3695
+ throw new Error("Document type not specified");
3674
3696
  }
3675
3697
  const removeComments = () => {
3676
3698
  conversationsBackup.value = conversations.value;
@@ -4215,6 +4237,7 @@ const useCommentsStore = /* @__PURE__ */ defineStore("comments", () => {
4215
4237
  const newComment = useComment({
4216
4238
  fileId: documentId,
4217
4239
  fileType: document2.type,
4240
+ docxCommentJSON: comment.textJson,
4218
4241
  commentId: comment.commentId,
4219
4242
  isInternal: false,
4220
4243
  parentCommentId: comment.parentCommentId,
@@ -4275,7 +4298,7 @@ const useCommentsStore = /* @__PURE__ */ defineStore("comments", () => {
4275
4298
  commentsList.value.forEach((comment) => {
4276
4299
  const values = comment.getValues();
4277
4300
  const richText = values.commentText;
4278
- const schema = convertHtmlToSchema(richText);
4301
+ const schema = values.docxCommentJSON || convertHtmlToSchema(richText);
4279
4302
  processedComments.push({
4280
4303
  ...values,
4281
4304
  commentJSON: schema
@@ -16462,26 +16485,14 @@ const _sfc_main$9 = {
16462
16485
  const firstGroupRendered = vue.ref(false);
16463
16486
  const verticalOffset = vue.ref(0);
16464
16487
  const commentsRenderKey = vue.ref(0);
16488
+ const measurementTimeoutId = vue.ref(null);
16465
16489
  const getCommentPosition = vue.computed(() => (comment) => {
16466
16490
  if (!floatingCommentsContainer.value) return { top: "0px" };
16467
- floatingCommentsContainer.value.getBoundingClientRect();
16468
16491
  if (typeof comment.top !== "number" || isNaN(comment.top)) {
16469
16492
  return { display: "none" };
16470
16493
  }
16471
16494
  return { top: `${comment.top}px` };
16472
16495
  });
16473
- const findScrollParent = (element) => {
16474
- if (!element) return window;
16475
- let parent = element.parentNode;
16476
- while (parent && parent !== document) {
16477
- const style2 = getComputedStyle(parent);
16478
- if (/(auto|scroll|overlay)/.test(style2.overflow + style2.overflowY + style2.overflowX)) {
16479
- return parent;
16480
- }
16481
- parent = parent.parentNode;
16482
- }
16483
- return window;
16484
- };
16485
16496
  const handleDialog = (dialog) => {
16486
16497
  if (!dialog) return;
16487
16498
  const { elementRef, commentId } = dialog;
@@ -16489,44 +16500,68 @@ const _sfc_main$9 = {
16489
16500
  vue.nextTick(() => {
16490
16501
  const id = commentId;
16491
16502
  if (renderedSizes.value.some((item) => item.id == id)) return;
16492
- const editorBounds = props.parent.getBoundingClientRect();
16493
16503
  const comment = getFloatingComments.value.find((c2) => c2.commentId === id || c2.importedId == id);
16494
16504
  const positionKey = id || comment?.importedId;
16495
- let position = editorCommentPositions.value[positionKey]?.bounds || {};
16505
+ const positionEntry = editorCommentPositions.value[positionKey];
16506
+ const position = positionEntry?.bounds || {};
16496
16507
  if (props.currentDocument.type === "application/pdf") {
16497
16508
  Object.entries(comment.selection?.selectionBounds).forEach(([key, value]) => {
16498
16509
  position[key] = Number(value);
16499
16510
  });
16500
- position.top += editorBounds.top;
16501
16511
  }
16502
16512
  if (!position) return;
16503
- const scrollParent = findScrollParent(props.parent);
16504
- scrollParent === window ? window.scrollY : scrollParent.scrollTop;
16505
16513
  const bounds = elementRef.value?.getBoundingClientRect();
16514
+ const top = Number(position.top);
16515
+ if (!Number.isFinite(top)) return;
16506
16516
  const placement = {
16507
16517
  id,
16508
- top: position.top - editorBounds.top,
16518
+ top,
16509
16519
  height: bounds.height,
16510
16520
  commentRef: comment,
16511
- elementRef
16521
+ elementRef,
16522
+ pageIndex: positionEntry?.pageIndex ?? 0
16512
16523
  };
16513
16524
  renderedSizes.value.push(placement);
16514
16525
  });
16515
16526
  };
16516
16527
  const processLocations = async () => {
16517
- let currentBottom = 0;
16518
- renderedSizes.value.sort((a, b) => a.top - b.top).forEach((comment) => {
16519
- if (comment.top <= currentBottom + 15) {
16520
- comment.top = currentBottom + 15;
16521
- }
16522
- currentBottom = comment.top + comment.height;
16528
+ const groupedByPage = renderedSizes.value.reduce((acc, comment) => {
16529
+ const key = comment.pageIndex ?? 0;
16530
+ if (!acc[key]) acc[key] = [];
16531
+ acc[key].push(comment);
16532
+ return acc;
16533
+ }, {});
16534
+ Object.values(groupedByPage).forEach((comments) => {
16535
+ comments.sort((a, b) => a.top - b.top).forEach((comment, idx, arr) => {
16536
+ if (idx === 0) return;
16537
+ const prev = arr[idx - 1];
16538
+ const minTop = prev.top + prev.height + 15;
16539
+ if (comment.top < minTop) {
16540
+ comment.top = minTop;
16541
+ }
16542
+ });
16523
16543
  });
16524
16544
  await vue.nextTick();
16525
16545
  firstGroupRendered.value = true;
16526
16546
  };
16527
16547
  vue.watchEffect(() => {
16528
- if (renderedSizes.value.length === getFloatingComments.value.length) {
16548
+ if (measurementTimeoutId.value) {
16549
+ clearTimeout(measurementTimeoutId.value);
16550
+ measurementTimeoutId.value = null;
16551
+ }
16552
+ const totalComments = getFloatingComments.value.length;
16553
+ const measuredComments = renderedSizes.value.length;
16554
+ if (totalComments === 0) {
16555
+ return;
16556
+ }
16557
+ if (measuredComments === totalComments) {
16529
16558
  vue.nextTick(processLocations);
16559
+ } else if (measuredComments > 0 && !firstGroupRendered.value) {
16560
+ measurementTimeoutId.value = setTimeout(() => {
16561
+ if (!firstGroupRendered.value && renderedSizes.value.length > 0) {
16562
+ processLocations();
16563
+ }
16564
+ }, 100);
16530
16565
  }
16531
16566
  });
16532
16567
  vue.watch(activeComment, (newVal, oldVal) => {
@@ -16549,6 +16584,12 @@ const _sfc_main$9 = {
16549
16584
  }, 200);
16550
16585
  });
16551
16586
  });
16587
+ vue.onBeforeUnmount(() => {
16588
+ if (measurementTimeoutId.value) {
16589
+ clearTimeout(measurementTimeoutId.value);
16590
+ measurementTimeoutId.value = null;
16591
+ }
16592
+ });
16552
16593
  return (_ctx, _cache) => {
16553
16594
  return vue.openBlock(), vue.createElementBlock("div", {
16554
16595
  class: "section-wrapper",
@@ -16599,7 +16640,7 @@ const _sfc_main$9 = {
16599
16640
  };
16600
16641
  }
16601
16642
  };
16602
- const FloatingComments = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["__scopeId", "data-v-91de2350"]]);
16643
+ const FloatingComments = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["__scopeId", "data-v-eab6fbfa"]]);
16603
16644
  const _sfc_main$8 = {
16604
16645
  __name: "TextField",
16605
16646
  props: {
@@ -17227,7 +17268,7 @@ const _sfc_main = {
17227
17268
  __name: "SuperDoc",
17228
17269
  emits: ["selection-update"],
17229
17270
  setup(__props, { emit: __emit }) {
17230
- const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-DJ7BWUbW.cjs")));
17271
+ const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-C3_5zd7y.cjs")));
17231
17272
  const superdocStore = useSuperdocStore();
17232
17273
  const commentsStore = useCommentsStore();
17233
17274
  const {
@@ -17354,6 +17395,13 @@ const _sfc_main = {
17354
17395
  presentationEditor.onTelemetry((telemetryPayload) => {
17355
17396
  proxy.$superdoc.captureLayoutPipelineEvent(telemetryPayload);
17356
17397
  });
17398
+ presentationEditor.on("commentPositions", ({ positions }) => {
17399
+ const commentsConfig = proxy.$superdoc.config.modules?.comments;
17400
+ if (!commentsConfig || commentsConfig === false) return;
17401
+ if (!positions || Object.keys(positions).length === 0) return;
17402
+ const mappedPositions = presentationEditor.getCommentBounds(positions, layers.value);
17403
+ handleEditorLocationsUpdate(mappedPositions);
17404
+ });
17357
17405
  };
17358
17406
  const onEditorDestroy = () => {
17359
17407
  proxy.$superdoc.broadcastEditorDestroy();
@@ -17900,7 +17948,7 @@ const _sfc_main = {
17900
17948
  };
17901
17949
  }
17902
17950
  };
17903
- const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-3fafc837"]]);
17951
+ const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-3c3356b6"]]);
17904
17952
  const createSuperdocVueApp = () => {
17905
17953
  const app = vue.createApp(App);
17906
17954
  const pinia = createPinia();
@@ -18080,7 +18128,7 @@ class SuperDoc extends eventemitter3.EventEmitter {
18080
18128
  this.config.colors = shuffleArray(this.config.colors);
18081
18129
  this.userColorMap = /* @__PURE__ */ new Map();
18082
18130
  this.colorIndex = 0;
18083
- this.version = "1.0.0-beta.8";
18131
+ this.version = "1.0.0";
18084
18132
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
18085
18133
  this.superdocId = config.superdocId || uuid.v4();
18086
18134
  this.colors = this.config.colors;
@@ -18241,6 +18289,28 @@ class SuperDoc extends eventemitter3.EventEmitter {
18241
18289
  async #initCollaboration({ collaboration: collaborationModuleConfig, comments: commentsConfig = {} } = {}) {
18242
18290
  if (!collaborationModuleConfig) return this.config.documents;
18243
18291
  this.isCollaborative = true;
18292
+ const { ydoc: externalYdoc, provider: externalProvider } = collaborationModuleConfig;
18293
+ if (externalYdoc && externalProvider) {
18294
+ this.ydoc = externalYdoc;
18295
+ this.provider = externalProvider;
18296
+ setupAwarenessHandler(externalProvider, this, this.config.user);
18297
+ if (!this.config.documents || this.config.documents.length === 0) {
18298
+ this.config.documents = [
18299
+ {
18300
+ id: uuid.v4(),
18301
+ type: DOCX,
18302
+ name: "document.docx"
18303
+ }
18304
+ ];
18305
+ }
18306
+ this.config.documents.forEach((doc) => {
18307
+ doc.ydoc = externalYdoc;
18308
+ doc.provider = externalProvider;
18309
+ doc.role = this.config.role;
18310
+ });
18311
+ initCollaborationComments(this);
18312
+ return this.config.documents;
18313
+ }
18244
18314
  if (collaborationModuleConfig.providerType === "hocuspocus") {
18245
18315
  this.config.socket = new provider.HocuspocusProviderWebsocket({
18246
18316
  url: collaborationModuleConfig.url
@@ -18428,7 +18498,6 @@ class SuperDoc extends eventemitter3.EventEmitter {
18428
18498
  */
18429
18499
  addCommentsList(element) {
18430
18500
  if (!this.config?.modules?.comments || this.config.role === "viewer") return;
18431
- this.#log("🦋 [superdoc] Adding comments list to:", element);
18432
18501
  if (element) this.config.modules.comments.element = element;
18433
18502
  this.commentsList = new SuperComments(this.config.modules?.comments, this);
18434
18503
  if (this.config.onCommentsListChange) this.config.onCommentsListChange({ isRendered: true });
@@ -18491,7 +18560,9 @@ class SuperDoc extends eventemitter3.EventEmitter {
18491
18560
  editing: () => this.#setModeEditing(),
18492
18561
  suggesting: () => this.#setModeSuggesting()
18493
18562
  };
18494
- if (types[type]) types[type]();
18563
+ if (types[type]) {
18564
+ types[type]();
18565
+ }
18495
18566
  }
18496
18567
  /**
18497
18568
  * Set the document mode on a document's editor (PresentationEditor or Editor).
@@ -18563,7 +18634,7 @@ class SuperDoc extends eventemitter3.EventEmitter {
18563
18634
  }
18564
18635
  #setModeViewing() {
18565
18636
  this.toolbar.activeEditor = null;
18566
- this.setTrackedChangesPreferences({ mode: "final", enabled: false });
18637
+ this.setTrackedChangesPreferences({ mode: "original", enabled: false });
18567
18638
  this.superdocStore.documents.forEach((doc) => {
18568
18639
  doc.removeComments();
18569
18640
  this.#applyDocumentMode(doc, "viewing");
@@ -1,4 +1,4 @@
1
- import "./vue-CztqUvm1.es.js";
1
+ import "./vue-Dysv_7z5.es.js";
2
2
  function getDefaultExportFromCjs(x) {
3
3
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4
4
  }
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- require("./vue-ARQSyfaw.cjs");
2
+ require("./vue-jWLMl8Ts.cjs");
3
3
  function getDefaultExportFromCjs(x) {
4
4
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
5
5
  }