@veltdev/superdoc-velt-comments 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.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # @veltdev/superdoc-velt-comments
2
+
3
+ <p>
4
+ <a href="https://www.npmjs.com/package/@veltdev/superdoc-velt-comments">
5
+ <img src="https://img.shields.io/npm/v/@veltdev/superdoc-velt-comments?style=flat&label=npm&color=09f" alt="NPM" />
6
+ </a>
7
+ </p>
8
+
9
+ Add Google Docs-style collaborative comments to your [SuperDoc](https://www.superdoc.dev/) in-browser
10
+ DOCX/Word editor using the [Velt](https://velt.dev) Collaboration SDK.
11
+
12
+ Comment highlights are rendered as **view-only overlay elements** (`<velt-comment-text>`) positioned
13
+ over the commented text — your document is never modified. Each comment is anchored by a durable
14
+ `{ text, occurrence }` and re-resolved against the live ProseMirror document on every render, so the
15
+ highlight follows the text as the document is edited and stays locked through scroll, resize, and reload.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm i @veltdev/superdoc-velt-comments
21
+ npm i @harbour-enterprises/superdoc # peer dependency (the editor; never bundled)
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```tsx
27
+ import {
28
+ SuperDocVeltComments,
29
+ addComment,
30
+ renderComments,
31
+ } from '@veltdev/superdoc-velt-comments';
32
+
33
+ // after the editor is ready (onReady):
34
+ const attached = SuperDocVeltComments.configure({ editorId: 'superdoc' }).attach(superdoc);
35
+
36
+ // create a comment for the current text selection:
37
+ await addComment({ instance: superdoc });
38
+
39
+ // render existing comments (driven by Velt's useCommentAnnotations):
40
+ renderComments({ instance: superdoc, commentAnnotations });
41
+
42
+ // teardown:
43
+ attached.detach();
44
+ ```
45
+
46
+ ## API
47
+
48
+ | Export | Purpose |
49
+ |---|---|
50
+ | `SuperDocVeltComments.configure(config).attach(instance)` | Wire the extension to a SuperDoc instance; returns `{ detach() }`. |
51
+ | `addComment({ instance })` | Create a comment on the current text selection. |
52
+ | `renderComments({ instance, commentAnnotations })` | Render/refresh comment highlights from Velt. |
53
+
54
+ Config (`SuperDocVeltCommentsConfig`): `editorId?` (default `'superdoc'`),
55
+ `scrollToSelectedComment?` (default `true`).
56
+
57
+ Source, tests, and demo: [snippyly/superdoc-velt-comments](https://github.com/snippyly/superdoc-velt-comments).
58
+
59
+ ## About Velt SDK
60
+
61
+ With Velt SDK you can add powerful collaboration features to your product extremely fast — fully
62
+ customizable UI on a fully-managed realtime backend. Features include **Comments** (Figma / Google
63
+ Docs-style), **Recording** (Loom-style), **Huddle** (Slack-style), in-app & off-app
64
+ **notifications**, **@mentions**, **Presence**, **Cursors**, **Live Selection**, and more.
65
+
66
+ ## Documentation
67
+
68
+ - Read the [documentation](https://docs.velt.dev/async-collaboration/comments/overview) for guides and API references.
69
+
70
+ ## Use cases
71
+
72
+ - Explore [use cases](https://velt.dev/use-case) to see what collaboration could look like in your product.
73
+
74
+ ## Releases
75
+
76
+ - See the [latest changes](https://docs.velt.dev/release-notes/).
77
+
78
+ ## Security
79
+
80
+ - Velt is SOC2 Type 2 and HIPAA compliant. [Learn more](https://velt.dev/security).
81
+
82
+ ## Community
83
+
84
+ - [X](https://x.com/veltjs): updates, announcements, and general Velt tips.
85
+ - [Discord](https://discord.gg/GupvcYH27h): ask questions and share tips.
86
+
87
+ ---
88
+ © Velt — Proprietary.
package/cjs/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var t=require("@harbour-enterprises/superdoc/ui");const e="superdoc",n="terminal",o="velt-comment-text",r="[velt-superdoc-comments]",s=new WeakMap,c=(t,e)=>{const n=s.get(t);if(!n)return;const o=e.parentElement??e,r=e.getBoundingClientRect(),c=o.getBoundingClientRect();n.style.setProperty("left",r.left-c.left+"px","important"),n.style.setProperty("top",r.top-c.top+"px","important"),n.style.setProperty("width",`${r.width}px`,"important"),n.style.setProperty("height",`${r.height}px`,"important")},i=t=>{const e=document.createElement(o);return e.setAttribute("annotation-id",t),e.setAttribute("data-velt-comment-annotation-id",t),e.style.setProperty("position","absolute","important"),e.style.setProperty("background-color","rgba(255, 212, 0, 0.30)","important"),e.style.setProperty("border-bottom","2px solid rgba(245, 158, 11, 0.9)","important"),e.style.setProperty("border-radius","2px","important"),e.style.setProperty("box-sizing","border-box","important"),e.style.setProperty("pointer-events","auto","important"),e.style.setProperty("cursor","pointer","important"),e.style.setProperty("display","block","important"),e},l=(t,e)=>{const{container:n,boxes:o,veltAnnotationId:r}=t;if(0!==e.length){for(;o.length<e.length;){const t=i(r);n.appendChild(t),o.push(t)}for(;o.length>e.length;){const t=o.pop();t?.remove()}for(let t=0;t<e.length;t++){const n=e[t],r=o[t];r.style.setProperty("left",`${n.left}px`,"important"),r.style.setProperty("top",`${n.top}px`,"important"),r.style.setProperty("width",`${Math.max(n.width,1)}px`,"important"),r.style.setProperty("height",`${Math.max(n.height,1)}px`,"important"),r.style.setProperty("display","block","important")}n.style.setProperty("display","block","important")}else a(t)},a=t=>{t.container.style.setProperty("display","none","important")},u=t=>{try{t.container.remove()}catch(t){console.warn(`${r} removeCommentOverlay failed`,t)}},p=new WeakMap,d=t=>{try{return t.activeEditor??null}catch{return null}},f=e=>{const n=p.get(e);if(n)return n;try{const n=t.createSuperDocUI({superdoc:e});return p.set(e,n),n}catch(t){return console.warn(`${r} createSuperDocUI failed`,t),null}},m=t=>{const e=f(t);try{return e?.viewport.getHost()??null}catch{return null}},h=()=>window.Velt,y=()=>{try{const t=h();return t?.getCommentElement?.()??null}catch{return null}},g=(t,e)=>{const n=y();if(n)try{n.updateContext?.(t,e)}catch(t){console.warn(`${r} updateAnnotationContext failed`,t)}},w=new Map,x=new WeakMap,v=t=>w.get(t),b=t=>x.get(t)??[],P=new WeakMap,C=new WeakMap,I=new WeakMap,S=(t,e,n)=>{(t=>{let e=C.get(t);return e||(e=new Map,C.set(t,e)),e})(t).set(e,n)},$=(t,e)=>{C.get(t)?.delete(e)},A=(t,e)=>C.get(t)?.get(e),M=t=>{const e=[],n=C.get(t);if(!n)return e;for(const[t,o]of n)o&&e.push([t,o]);return e},k=(t,e)=>{I.set(t,e)},E=(t,e,n=0,o)=>{const r=[];if(!e||!t||e.length>t.length)return r;const s=(t=>{if(!t||0===t.length)return[];const e=new Array(t.length).fill(0);let n=0,o=1;for(;o<t.length;)t[o]===t[n]?(n++,e[o]=n,o++):0!==n?n=e[n-1]:(e[o]=0,o++);return e})(e);let c=0,i=0;for(;c<t.length;)e[i]===t[c]&&(c++,i++),i===e.length?(r.push(n+c-i),i=s[i-1]):c<t.length&&e[i]!==t[c]&&(0!==i?i=s[i-1]:c++);return r},T=t=>t.width>0&&t.height>0,D=(t,e)=>{if(!e)return[];const{textNodes:n,combined:o}=(t=>{const e=[];let n="";try{t.state.doc.descendants((t,o)=>(t.isText&&"string"==typeof t.text&&(e.push({text:t.text,pos:o}),n+=t.text),!0))}catch{}return{textNodes:e,combined:n}})(t);if(!o)return[];return((t,e,n)=>{const o=[];for(const r of e){let e=0,s=-1,c=0,i=-1,l=0;for(let o=0;o<t.length;o++){const a=t[o].text.length;if(-1===s&&r<e+a&&(s=o,c=r-e),-1===i&&r+n<=e+a){i=o,l=r+n-e;break}e+=a}-1!==s&&-1!==i&&o.push({from:t[s].pos+c,to:t[i].pos+l})}return o})(n,E(o,e),e.length)},R=(t,e,n)=>{const o=D(t,e);if(0===o.length)return null;return o[Math.min(Math.max(1,n)-1,o.length-1)]??null},W=(t,e)=>{try{return t.state.doc.textBetween(e.from,e.to)}catch{return""}},_=(t,e,n)=>{const o=D(t,e);for(let t=0;t<o.length;t++){const e=o[t];if(e.from<=n.from&&e.to>=n.to)return t+1;if(e.from===n.from)return t+1}return 1},V=(t,e)=>{try{const n=t.mapping.map(e.from,-1),o=t.mapping.map(e.to,1);return n>=o?null:{from:n,to:o}}catch{return null}},B=new WeakMap,N=(t,e)=>{B.set(t,e)},O=t=>{const e=d(t);if(!e)return void N(t,null);const n=(t=>{try{const{from:e,to:n}=t.state.selection;if(e>=n)return null;const o=t.state.doc.textBetween(e,n);return o&&0!==o.trim().length?{from:e,to:n}:null}catch{return null}})(e);if(!n)return void N(t,null);const o=W(e,n);if(!o)return void N(t,null);const r=_(e,o,n);N(t,{range:n,text:o,occurrence:r})},U=t=>{const n=(t=>B.get(t)??null)(t);if(!n)return null;const o=v(t);return{editorId:o?.config.editorId??e,text:n.text,occurrence:n.occurrence}},z=(t,e,n)=>{try{const o=t.presentationEditor;if(!o)return[];const r=o.getRangeRects(n.from,n.to,e)??[],s=[];for(const t of r){const e=t.left??0,n=t.top??0,o=t.width??(t.right??0)-e,r={left:e,top:n,width:o,height:t.height??(t.bottom??0)-n};T(r)&&s.push(r)}return s}catch{return[]}},F=(t,e,n)=>{if(!(t=>I.get(t)??!1)(t))return;if(((t,e)=>C.get(t)?.has(e)??!1)(t,n))return;const o=d(t),c=o?R(o,e.text,e.occurrence):null,i=((t,e,n,o)=>{const c=s.get(t);if(!c)return null;try{const t=document.createElement("div");return t.className="velt-superdoc-overlay",t.style.setProperty("position","absolute","important"),t.style.setProperty("inset","0","important"),t.style.setProperty("pointer-events","none","important"),t.style.setProperty("display","none","important"),c.appendChild(t),{veltAnnotationId:o,anchor:e,range:n,container:t,boxes:[]}}catch(t){return console.warn(`${r} setCommentOverlay failed`,t),null}})(t,e,c,n);if(!i)return void S(t,n,null);S(t,n,i);const u=m(t);if(c&&o&&u){const t=z(o,u,c);t.length>0?l(i,t):a(i)}else a(i)},q=(t,e)=>{const n=(t=>{const e=t?.context,n=e?.textEditorConfig;return n&&"string"==typeof n.text&&0!==n.text.length&&"number"==typeof n.occurrence?n:null})(t);return n?n.editorId&&n.editorId!==e?null:n:null},H=({instance:t,commentAnnotations:e})=>{const o=v(t);if(!o)return;const r=o.config.editorId,s=Array.isArray(e)?e:[];((t,e)=>{x.set(t,e)})(t,s);const c=(t=>P.get(t)??new Set)(t),i=((t,e)=>t.filter(t=>t?.status?.type!==n||!!t.annotationId&&e.has(t.annotationId)))(s,c),l=new Map;for(const t of i){if(!t?.annotationId)continue;const e=q(t,r);e&&l.set(t.annotationId,e)}const a=(t=>new Set(C.get(t)?.keys()??[]))(t);for(const e of a)if(!l.has(e)){const n=A(t,e);n&&u(n),$(t,e)}for(const[e,n]of l)a.has(e)||F(t,n,e)},K=new WeakMap,j=t=>{if("undefined"==typeof window)return;if(void 0!==K.get(t))return;const e=window.requestAnimationFrame(()=>{K.delete(t),(t=>{const e=d(t),n=m(t);if(e&&n){c(t,n);for(const[,o]of M(t)){if(!o.range){a(o);continue}const t=z(e,n,o.range);t.length>0?l(o,t):a(o)}}})(t)});K.set(t,e)};class G{config;constructor(t){this.config=t}static configure(t={}){return new G(t)}attach(t){((t,n)=>{w.set(t,{instance:t,config:{editorId:e,...n}})})(t,this.config),k(t,!0);const n=m(t);n&&((t,e)=>{const n=s.get(t);if(n)return n;const o=e.parentElement??e,r=document.createElement("div");r.className="velt-superdoc-overlay-root",r.style.setProperty("position","absolute","important"),r.style.setProperty("left","0px","important"),r.style.setProperty("top","0px","important"),r.style.setProperty("overflow","hidden","important"),r.style.setProperty("pointer-events","none","important"),r.style.setProperty("z-index","5","important"),o.appendChild(r),s.set(t,r),c(t,e)})(t,n);let o=!1;const i=d(t),l=!1!==this.config.scrollToSelectedComment;let h=null;const v=e=>((t,e)=>{if(!e.docChanged)return;const n=d(t);for(const[o,r]of M(t)){if(!r.range)continue;const t=V(e,r.range);if(r.range=t,!t){a(r);continue}if(!n)continue;const s=W(n,t);if(!s)continue;const c=_(n,s,t);s===r.anchor.text&&c===r.anchor.occurrence||(r.anchor={...r.anchor,text:s,occurrence:c},g(o,{textEditorConfig:r.anchor}))}j(t)})(t,e.transaction),I=()=>O(t);i?.on("update",v),i?.on("selectionUpdate",I);const S=f(t);let $=null;try{$=S?.viewport.observe(()=>j(t))??null}catch(t){console.warn(`${r} viewport.observe failed`,t)}const A=(t=>{let e=null,n=!1,o=null;const s=()=>{if(n)return;const c=y(),i=c?.getSelectedComments?.();if(i?.subscribe)try{const o=i.subscribe(e=>{if(n)return;const o=new Set;(e??[]).forEach(t=>{t?.annotationId&&o.add(t.annotationId)}),t(o)});e=()=>{try{o?.unsubscribe?.()}catch{}}}catch(t){console.warn(`${r} subscribeToSelectedAnnotations failed`,t)}else o=setTimeout(s,250)};return s(),()=>{n=!0,o&&clearTimeout(o),e?.()}})(e=>{o||(((t,e)=>{P.set(t,e)})(t,e),(t=>{H({instance:t,commentAnnotations:b(t)})})(t),j(t),l&&(h=((t,e,n)=>{if(0===e.size)return null;const o=d(t);for(const[s,c]of M(t))if(e.has(s)){if(s===n)return n;if(o&&c.range)try{const e=f(t)?.viewport.getScrollContainer()??null,n=o.presentationEditor;if(e&&n){const o=(n.getRangeRects(c.range.from,c.range.to,e)??[])[0];if(o){const n=o.top??0,r=e.scrollTop+n-e.clientHeight/2;e.scrollTo({top:Math.max(0,r),behavior:"smooth"}),j(t)}}}catch(t){console.warn(`${r} jumpToSelectedComment failed`,t)}return s}return n})(t,e,h)))});return O(t),j(t),"undefined"!=typeof window&&(window.__veltSuperDocTest={instance:t,recordSelection:N}),{detach:()=>{o=!0,k(t,!1),i?.off("update",v),i?.off("selectionUpdate",I),$?.(),$=null,A(),(t=>{if("undefined"==typeof window)return;const e=K.get(t);void 0!==e&&(window.cancelAnimationFrame(e),K.delete(t))})(t);for(const[,e]of M(t))u(e);(t=>{s.get(t)?.remove(),s.delete(t)})(t),(t=>{const e=p.get(t);if(e)try{e.destroy()}catch{}p.delete(t)})(t),(t=>{P.delete(t)})(t),(t=>{w.delete(t),x.delete(t)})(t),(t=>{C.delete(t)})(t),"undefined"!=typeof window&&window.__veltSuperDocTest?.instance===t&&delete window.__veltSuperDocTest}}}}exports.SuperDocVeltComments=G,exports.addComment=async({instance:t})=>{const e=U(t);if(!e)return console.warn(`${r} addComment: no text selected`),null;if(!(()=>{try{return!!h()?.loaded}catch{return!1}})())return console.warn(`${r} addComment: Velt SDK not loaded — is the user logged in?`),null;const n=await(async({context:t})=>{const e=y();if(!e)return console.warn(`${r} Velt SDK unavailable`),null;try{return await e.addCommentAnnotation({annotation:{context:t}})}catch(t){return console.warn(`${r} addCommentAnnotation failed`,t),null}})({context:{textEditorConfig:e}}),o=n?.annotationId;return o?{veltAnnotationId:o,textEditorConfig:e}:(console.warn(`${r} addComment: Velt did not return an annotationId`),null)},exports.captureSelection=O,exports.computeOccurrenceForRange=_,exports.recordSelection=N,exports.renderComments=H,exports.resolveTextOccurrenceToRange=R;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/constants/common.ts","../../src/adapters/host/overlay.ts","../../src/adapters/host/sdk.ts","../../src/adapters/velt.ts","../../src/core/registry.ts","../../src/core/selectedIdsStore.ts","../../src/core/state.ts","../../src/utils/common.ts","../../src/adapters/host/positions.ts","../../src/features/getCurrentSelectionContext.ts","../../src/features/resolveAnnotation.ts","../../src/features/renderComments.ts","../../src/features/repositionOverlays.ts","../../src/core/extension.ts","../../src/features/updateContent.ts","../../src/features/scrollToComment.ts","../../src/features/addComment.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"names":["Constants","overlayRoots","WeakMap","syncOverlayLayerBounds","instance","host","root","get","parent","parentElement","hostRect","getBoundingClientRect","parentRect","style","setProperty","left","top","width","height","buildHighlightBox","veltAnnotationId","box","document","createElement","setAttribute","positionOverlay","record","rects","container","boxes","length","appendChild","push","pop","remove","i","rect","Math","max","hideOverlay","removeCommentOverlay","error","console","warn","uiControllers","getActiveEditor","activeEditor","getUI","existing","ui","createSuperDocUI","superdoc","set","getPaintedHost","viewport","getHost","getVelt","window","Velt","getCommentElement","velt","updateAnnotationContext","annotationId","context","commentElement","updateContext","registry","Map","lastAnnotations","getRegistered","getLastAnnotations","stores","documentReady","trackAnnotation","overlay","store","getOrCreate","untrackAnnotation","delete","getTrackedAnnotation","getTrackedOverlays","out","veltId","setDocumentReady","ready","kmpSearch","text","pattern","startPos","maxOccurrences","positions","lps","Array","fill","len","computeKMPTable","j","hasArea","r","findAllRanges","editor","textNodes","combined","state","doc","descendants","node","pos","isText","collectTextNodes","textPositions","patternLength","ranges","textPos","currentPos","startNodeIndex","startOffset","endNodeIndex","endOffset","nodeLength","from","to","mapTextPositionsToDocument","resolveTextOccurrenceToRange","occurrence","min","getTextForRange","range","textBetween","computeOccurrenceForRange","remapRange","transaction","mapping","map","selections","recordSelection","snapshot","captureSelection","selection","trim","getSelectionRange","getCurrentSelectionContext","getRecordedSelection","registered","editorId","config","resolveRangeRects","presentation","presentationEditor","getRangeRects","right","bottom","paintAnnotation","cfg","isDocumentReady","has","isTracked","anchor","className","setCommentOverlay","matchesEditor","annotation","expectedEditorId","ctx","textEditorConfig","extractTextEditorConfig","renderComments","commentAnnotations","list","isArray","annotations","setLastAnnotations","selectedIds","Set","getSelectedIds","visible","filter","status","type","filterForRender","incoming","tracked","keys","getTrackedIds","frames","scheduleReposition","undefined","handle","requestAnimationFrame","repositionOverlays","SuperDocVeltComments","constructor","this","configure","attach","registerInstance","createOverlayLayer","detached","scrollEnabled","scrollToSelectedComment","lastJumpedId","onUpdate","payload","docChanged","newRange","handleContentUpdate","onSelectionUpdate","on","unobserveViewport","observe","unsubscribeSelected","onChange","unsubscribe","cancelled","retryHandle","tryAttach","obs","getSelectedComments","subscribe","sub","comments","forEach","c","add","setTimeout","clearTimeout","subscribeToSelectedAnnotations","ids","setSelectedIds","rerenderFromCache","size","scroller","getScrollContainer","first","target","scrollTop","clientHeight","scrollTo","behavior","jumpToSelectedComment","__veltSuperDocTest","detach","off","pending","cancelAnimationFrame","cancelScheduledReposition","destroyOverlayLayer","destroy","destroyUI","clearSelectedIds","unregisterInstance","clearStore","async","loaded","isVeltAvailable","event","addCommentAnnotation"],"mappings":"+DAQO,MAAMA,EAEQ,WAFRA,EAIM,WAJNA,EASD,oBATCA,EAWC,2BCMRC,EAAe,IAAIC,QA6CZC,EAAyB,CACpCC,EACAC,KAEA,MAAMC,EAAOL,EAAaM,IAAIH,GAC9B,IAA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E,CAAEA,mBAAkBgJ,qBANzB1H,QAAQC,KACN,GAAG3C,qDAEE"}
package/esm/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import{createSuperDocUI as t}from"@harbour-enterprises/superdoc/ui";const e="superdoc",n="terminal",o="velt-comment-text",r="[velt-superdoc-comments]",s=new WeakMap,i=(t,e)=>{const n=s.get(t);if(!n)return;const o=e.parentElement??e,r=e.getBoundingClientRect(),i=o.getBoundingClientRect();n.style.setProperty("left",r.left-i.left+"px","important"),n.style.setProperty("top",r.top-i.top+"px","important"),n.style.setProperty("width",`${r.width}px`,"important"),n.style.setProperty("height",`${r.height}px`,"important")},c=t=>{const e=document.createElement(o);return e.setAttribute("annotation-id",t),e.setAttribute("data-velt-comment-annotation-id",t),e.style.setProperty("position","absolute","important"),e.style.setProperty("background-color","rgba(255, 212, 0, 0.30)","important"),e.style.setProperty("border-bottom","2px solid rgba(245, 158, 11, 0.9)","important"),e.style.setProperty("border-radius","2px","important"),e.style.setProperty("box-sizing","border-box","important"),e.style.setProperty("pointer-events","auto","important"),e.style.setProperty("cursor","pointer","important"),e.style.setProperty("display","block","important"),e},l=(t,e)=>{const{container:n,boxes:o,veltAnnotationId:r}=t;if(0!==e.length){for(;o.length<e.length;){const t=c(r);n.appendChild(t),o.push(t)}for(;o.length>e.length;){const t=o.pop();t?.remove()}for(let t=0;t<e.length;t++){const n=e[t],r=o[t];r.style.setProperty("left",`${n.left}px`,"important"),r.style.setProperty("top",`${n.top}px`,"important"),r.style.setProperty("width",`${Math.max(n.width,1)}px`,"important"),r.style.setProperty("height",`${Math.max(n.height,1)}px`,"important"),r.style.setProperty("display","block","important")}n.style.setProperty("display","block","important")}else a(t)},a=t=>{t.container.style.setProperty("display","none","important")},u=t=>{try{t.container.remove()}catch(t){console.warn(`${r} removeCommentOverlay failed`,t)}},p=new WeakMap,d=t=>{try{return t.activeEditor??null}catch{return null}},f=e=>{const n=p.get(e);if(n)return n;try{const n=t({superdoc:e});return p.set(e,n),n}catch(t){return console.warn(`${r} createSuperDocUI failed`,t),null}},m=t=>{const e=f(t);try{return e?.viewport.getHost()??null}catch{return null}},h=()=>window.Velt,y=()=>{try{const t=h();return t?.getCommentElement?.()??null}catch{return null}},g=(t,e)=>{const n=y();if(n)try{n.updateContext?.(t,e)}catch(t){console.warn(`${r} updateAnnotationContext failed`,t)}},w=new Map,x=new WeakMap,v=t=>w.get(t),b=t=>x.get(t)??[],P=new WeakMap,C=new WeakMap,I=new WeakMap,$=(t,e,n)=>{(t=>{let e=C.get(t);return e||(e=new Map,C.set(t,e)),e})(t).set(e,n)},A=(t,e)=>{C.get(t)?.delete(e)},M=(t,e)=>C.get(t)?.get(e),S=t=>{const e=[],n=C.get(t);if(!n)return e;for(const[t,o]of n)o&&e.push([t,o]);return e},k=(t,e)=>{I.set(t,e)},E=(t,e,n=0,o)=>{const r=[];if(!e||!t||e.length>t.length)return r;const s=(t=>{if(!t||0===t.length)return[];const e=new Array(t.length).fill(0);let n=0,o=1;for(;o<t.length;)t[o]===t[n]?(n++,e[o]=n,o++):0!==n?n=e[n-1]:(e[o]=0,o++);return e})(e);let i=0,c=0;for(;i<t.length;)e[c]===t[i]&&(i++,c++),c===e.length?(r.push(n+i-c),c=s[c-1]):i<t.length&&e[c]!==t[i]&&(0!==c?c=s[c-1]:i++);return r},T=t=>t.width>0&&t.height>0,W=(t,e)=>{if(!e)return[];const{textNodes:n,combined:o}=(t=>{const e=[];let n="";try{t.state.doc.descendants((t,o)=>(t.isText&&"string"==typeof t.text&&(e.push({text:t.text,pos:o}),n+=t.text),!0))}catch{}return{textNodes:e,combined:n}})(t);if(!o)return[];return((t,e,n)=>{const o=[];for(const r of e){let e=0,s=-1,i=0,c=-1,l=0;for(let o=0;o<t.length;o++){const a=t[o].text.length;if(-1===s&&r<e+a&&(s=o,i=r-e),-1===c&&r+n<=e+a){c=o,l=r+n-e;break}e+=a}-1!==s&&-1!==c&&o.push({from:t[s].pos+i,to:t[c].pos+l})}return o})(n,E(o,e),e.length)},D=(t,e,n)=>{const o=W(t,e);if(0===o.length)return null;return o[Math.min(Math.max(1,n)-1,o.length-1)]??null},R=(t,e)=>{try{return t.state.doc.textBetween(e.from,e.to)}catch{return""}},_=(t,e,n)=>{const o=W(t,e);for(let t=0;t<o.length;t++){const e=o[t];if(e.from<=n.from&&e.to>=n.to)return t+1;if(e.from===n.from)return t+1}return 1},B=(t,e)=>{try{const n=t.mapping.map(e.from,-1),o=t.mapping.map(e.to,1);return n>=o?null:{from:n,to:o}}catch{return null}},N=new WeakMap,V=(t,e)=>{N.set(t,e)},z=t=>{const e=d(t);if(!e)return void V(t,null);const n=(t=>{try{const{from:e,to:n}=t.state.selection;if(e>=n)return null;const o=t.state.doc.textBetween(e,n);return o&&0!==o.trim().length?{from:e,to:n}:null}catch{return null}})(e);if(!n)return void V(t,null);const o=R(e,n);if(!o)return void V(t,null);const r=_(e,o,n);V(t,{range:n,text:o,occurrence:r})},U=t=>{const n=(t=>N.get(t)??null)(t);if(!n)return null;const o=v(t);return{editorId:o?.config.editorId??e,text:n.text,occurrence:n.occurrence}},F=(t,e,n)=>{try{const o=t.presentationEditor;if(!o)return[];const r=o.getRangeRects(n.from,n.to,e)??[],s=[];for(const t of r){const e=t.left??0,n=t.top??0,o=t.width??(t.right??0)-e,r={left:e,top:n,width:o,height:t.height??(t.bottom??0)-n};T(r)&&s.push(r)}return s}catch{return[]}},H=(t,e,n)=>{if(!(t=>I.get(t)??!1)(t))return;if(((t,e)=>C.get(t)?.has(e)??!1)(t,n))return;const o=d(t),i=o?D(o,e.text,e.occurrence):null,c=((t,e,n,o)=>{const i=s.get(t);if(!i)return null;try{const t=document.createElement("div");return t.className="velt-superdoc-overlay",t.style.setProperty("position","absolute","important"),t.style.setProperty("inset","0","important"),t.style.setProperty("pointer-events","none","important"),t.style.setProperty("display","none","important"),i.appendChild(t),{veltAnnotationId:o,anchor:e,range:n,container:t,boxes:[]}}catch(t){return console.warn(`${r} setCommentOverlay failed`,t),null}})(t,e,i,n);if(!c)return void $(t,n,null);$(t,n,c);const u=m(t);if(i&&o&&u){const t=F(o,u,i);t.length>0?l(c,t):a(c)}else a(c)},K=(t,e)=>{const n=(t=>{const e=t?.context,n=e?.textEditorConfig;return n&&"string"==typeof n.text&&0!==n.text.length&&"number"==typeof n.occurrence?n:null})(t);return n?n.editorId&&n.editorId!==e?null:n:null},O=({instance:t,commentAnnotations:e})=>{const o=v(t);if(!o)return;const r=o.config.editorId,s=Array.isArray(e)?e:[];((t,e)=>{x.set(t,e)})(t,s);const i=(t=>P.get(t)??new Set)(t),c=((t,e)=>t.filter(t=>t?.status?.type!==n||!!t.annotationId&&e.has(t.annotationId)))(s,i),l=new Map;for(const t of c){if(!t?.annotationId)continue;const e=K(t,r);e&&l.set(t.annotationId,e)}const a=(t=>new Set(C.get(t)?.keys()??[]))(t);for(const e of a)if(!l.has(e)){const n=M(t,e);n&&u(n),A(t,e)}for(const[e,n]of l)a.has(e)||H(t,n,e)},j=new WeakMap,q=t=>{if("undefined"==typeof window)return;if(void 0!==j.get(t))return;const e=window.requestAnimationFrame(()=>{j.delete(t),(t=>{const e=d(t),n=m(t);if(e&&n){i(t,n);for(const[,o]of S(t)){if(!o.range){a(o);continue}const t=F(e,n,o.range);t.length>0?l(o,t):a(o)}}})(t)});j.set(t,e)};class G{config;constructor(t){this.config=t}static configure(t={}){return new G(t)}attach(t){((t,n)=>{w.set(t,{instance:t,config:{editorId:e,...n}})})(t,this.config),k(t,!0);const n=m(t);n&&((t,e)=>{const n=s.get(t);if(n)return n;const o=e.parentElement??e,r=document.createElement("div");r.className="velt-superdoc-overlay-root",r.style.setProperty("position","absolute","important"),r.style.setProperty("left","0px","important"),r.style.setProperty("top","0px","important"),r.style.setProperty("overflow","hidden","important"),r.style.setProperty("pointer-events","none","important"),r.style.setProperty("z-index","5","important"),o.appendChild(r),s.set(t,r),i(t,e)})(t,n);let o=!1;const c=d(t),l=!1!==this.config.scrollToSelectedComment;let h=null;const v=e=>((t,e)=>{if(!e.docChanged)return;const n=d(t);for(const[o,r]of S(t)){if(!r.range)continue;const t=B(e,r.range);if(r.range=t,!t){a(r);continue}if(!n)continue;const s=R(n,t);if(!s)continue;const i=_(n,s,t);s===r.anchor.text&&i===r.anchor.occurrence||(r.anchor={...r.anchor,text:s,occurrence:i},g(o,{textEditorConfig:r.anchor}))}q(t)})(t,e.transaction),I=()=>z(t);c?.on("update",v),c?.on("selectionUpdate",I);const $=f(t);let A=null;try{A=$?.viewport.observe(()=>q(t))??null}catch(t){console.warn(`${r} viewport.observe failed`,t)}const M=(t=>{let e=null,n=!1,o=null;const s=()=>{if(n)return;const i=y(),c=i?.getSelectedComments?.();if(c?.subscribe)try{const o=c.subscribe(e=>{if(n)return;const o=new Set;(e??[]).forEach(t=>{t?.annotationId&&o.add(t.annotationId)}),t(o)});e=()=>{try{o?.unsubscribe?.()}catch{}}}catch(t){console.warn(`${r} subscribeToSelectedAnnotations failed`,t)}else o=setTimeout(s,250)};return s(),()=>{n=!0,o&&clearTimeout(o),e?.()}})(e=>{o||(((t,e)=>{P.set(t,e)})(t,e),(t=>{O({instance:t,commentAnnotations:b(t)})})(t),q(t),l&&(h=((t,e,n)=>{if(0===e.size)return null;const o=d(t);for(const[s,i]of S(t))if(e.has(s)){if(s===n)return n;if(o&&i.range)try{const e=f(t)?.viewport.getScrollContainer()??null,n=o.presentationEditor;if(e&&n){const o=(n.getRangeRects(i.range.from,i.range.to,e)??[])[0];if(o){const n=o.top??0,r=e.scrollTop+n-e.clientHeight/2;e.scrollTo({top:Math.max(0,r),behavior:"smooth"}),q(t)}}}catch(t){console.warn(`${r} jumpToSelectedComment failed`,t)}return s}return n})(t,e,h)))});return z(t),q(t),"undefined"!=typeof window&&(window.__veltSuperDocTest={instance:t,recordSelection:V}),{detach:()=>{o=!0,k(t,!1),c?.off("update",v),c?.off("selectionUpdate",I),A?.(),A=null,M(),(t=>{if("undefined"==typeof window)return;const e=j.get(t);void 0!==e&&(window.cancelAnimationFrame(e),j.delete(t))})(t);for(const[,e]of S(t))u(e);(t=>{s.get(t)?.remove(),s.delete(t)})(t),(t=>{const e=p.get(t);if(e)try{e.destroy()}catch{}p.delete(t)})(t),(t=>{P.delete(t)})(t),(t=>{w.delete(t),x.delete(t)})(t),(t=>{C.delete(t)})(t),"undefined"!=typeof window&&window.__veltSuperDocTest?.instance===t&&delete window.__veltSuperDocTest}}}}const J=async({instance:t})=>{const e=U(t);if(!e)return console.warn(`${r} addComment: no text selected`),null;if(!(()=>{try{return!!h()?.loaded}catch{return!1}})())return console.warn(`${r} addComment: Velt SDK not loaded — is the user logged in?`),null;const n=await(async({context:t})=>{const e=y();if(!e)return console.warn(`${r} Velt SDK unavailable`),null;try{return await e.addCommentAnnotation({annotation:{context:t}})}catch(t){return console.warn(`${r} addCommentAnnotation failed`,t),null}})({context:{textEditorConfig:e}}),o=n?.annotationId;return o?{veltAnnotationId:o,textEditorConfig:e}:(console.warn(`${r} addComment: Velt did not return an annotationId`),null)};export{G as SuperDocVeltComments,J as addComment,z as captureSelection,_ as computeOccurrenceForRange,V as recordSelection,O as renderComments,D as resolveTextOccurrenceToRange};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/constants/common.ts","../../src/adapters/host/overlay.ts","../../src/adapters/host/sdk.ts","../../src/adapters/velt.ts","../../src/core/registry.ts","../../src/core/selectedIdsStore.ts","../../src/core/state.ts","../../src/utils/common.ts","../../src/adapters/host/positions.ts","../../src/features/getCurrentSelectionContext.ts","../../src/features/resolveAnnotation.ts","../../src/features/renderComments.ts","../../src/features/repositionOverlays.ts","../../src/core/extension.ts","../../src/features/updateContent.ts","../../src/features/scrollToComment.ts","../../src/features/addComment.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"names":["Constants","overlayRoots","WeakMap","syncOverlayLayerBounds","instance","host","root","get","parent","parentElement","hostRect","getBoundingClientRect","parentRect","style","setProperty","left","top","width","height","buildHighlightBox","veltAnnotationId","box","document","createElement","setAttribute","positionOverlay","record","rects","container","boxes","length","appendChild","push","pop","remove","i","rect","Math","max","hideOverlay","removeCommentOverlay","error","console","warn","uiControllers","getActiveEditor","activeEditor","getUI","existing","ui","createSuperDocUI","superdoc","set","getPaintedHost","viewport","getHost","getVelt","window","Velt","getCommentElement","velt","updateAnnotationContext","annotationId","context","commentElement","updateContext","registry","Map","lastAnnotations","getRegistered","getLastAnnotations","stores","documentReady","trackAnnotation","overlay","store","getOrCreate","untrackAnnotation","delete","getTrackedAnnotation","getTrackedOverlays","out","veltId","setDocumentReady","ready","kmpSearch","text","pattern","startPos","maxOccurrences","positions","lps","Array","fill","len","computeKMPTable","j","hasArea","r","findAllRanges","editor","textNodes","combined","state","doc","descendants","node","pos","isText","collectTextNodes","textPositions","patternLength","ranges","textPos","currentPos","startNodeIndex","startOffset","endNodeIndex","endOffset","nodeLength","from","to","mapTextPositionsToDocument","resolveTextOccurrenceToRange","occurrence","min","getTextForRange","range","textBetween","computeOccurrenceForRange","remapRange","transaction","mapping","map","selections","recordSelection","snapshot","captureSelection","selection","trim","getSelectionRange","getCurrentSelectionContext","getRecordedSelection","registered","editorId","config","resolveRangeRects","presentation","presentationEditor","getRangeRects","right","bottom","paintAnnotation","cfg","isDocumentReady","has","isTracked","anchor","className","setCommentOverlay","matchesEditor","annotation","expectedEditorId","ctx","textEditorConfig","extractTextEditorConfig","renderComments","commentAnnotations","list","isArray","annotations","setLastAnnotations","selectedIds","Set","getSelectedIds","visible","filter","status","type","filterForRender","incoming","tracked","keys","getTrackedIds","frames","scheduleReposition","undefined","handle","requestAnimationFrame","repositionOverlays","SuperDocVeltComments","constructor","this","configure","attach","registerInstance","createOverlayLayer","detached","scrollEnabled","scrollToSelectedComment","lastJumpedId","onUpdate","payload","docChanged","newRange","handleContentUpdate","onSelectionUpdate","on","unobserveViewport","observe","unsubscribeSelected","onChange","unsubscribe","cancelled","retryHandle","tryAttach","obs","getSelectedComments","subscribe","sub","comments","forEach","c","add","setTimeout","clearTimeout","subscribeToSelectedAnnotations","ids","setSelectedIds","rerenderFromCache","size","scroller","getScrollContainer","first","target","scrollTop","clientHeight","scrollTo","behavior","jumpToSelectedComment","__veltSuperDocTest","detach","off","pending","cancelAnimationFrame","cancelScheduledReposition","destroyOverlayLayer","destroy","destroyUI","clearSelectedIds","unregisterInstance","clearStore","addComment","async","loaded","isVeltAvailable","event","addCommentAnnotation"],"mappings":"oEAQO,MAAMA,EAEQ,WAFRA,EAIM,WAJNA,EASD,oBATCA,EAWC,2BCMRC,EAAe,IAAIC,QA6CZC,EAAyB,CACpCC,EACAC,KAEA,MAAMC,EAAOL,EAAaM,IAAIH,GAC9B,IAAKE,EAAM,OACX,MAAME,EAASH,EAAKI,eAAiBJ,EAC/BK,EAAWL,EAAKM,wBAChBC,EAAaJ,EAAOG,wBAC1BL,EAAKO,MAAMC,YAAY,OAAWJ,EAASK,KAAOH,EAAWG,KAA9B,KAAwC,aACvET,EAAKO,MAAMC,YAAY,MAAUJ,EAASM,IAAMJ,EAAWI,IAA7B,KAAsC,aACpEV,EAAKO,MAAMC,YAAY,QAAS,GAAGJ,EAASO,UAAW,aACvDX,EAAKO,MAAMC,YAAY,SAAU,GAAGJ,EAASQ,WAAY,cAYrDC,EAAqBC,IACzB,MAAMC,EAAMC,SAASC,cAAcvB,GAcnC,OAbAqB,EAAIG,aAAa,gBAAiBJ,GAClCC,EAAIG,aAAa,kCAAmCJ,GACpDC,EAAIR,MAAMC,YAAY,WAAY,WAAY,aAC9CO,EAAIR,MAAMC,YAAY,mBAAoB,0BAA2B,aACrEO,EAAIR,MAAMC,YAAY,gBAAiB,oCAAqC,aAC5EO,EAAIR,MAAMC,YAAY,gBAAiB,MAAO,aAC9CO,EAAIR,MAAMC,YAAY,aAAc,aAAc,aAIlDO,EAAIR,MAAMC,YAAY,iBAAkB,OAAQ,aAChDO,EAAIR,MAAMC,YAAY,SAAU,UAAW,aAC3CO,EAAIR,MAAMC,YAAY,UAAW,QAA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AC7B,IACE,QAASwD,KAAWsM,MACtB,CAAE,MACA,OAAO,CACT,GaSKC,GAIH,OAHArN,QAAQC,KACN,GAAG3C,8DAEE,KAGT,MAAMgQ,ObI4BH,QAClC9L,cAIA,MAAMC,EAAiBL,IACvB,IAAKK,EAEH,OADAtB,QAAQC,KAAK,GAAG3C,0BACT,KAET,IAUE,aANEgE,EAKAiM,qBAAqB,CAAEhG,WAAY,CAAElG,YAEzC,CAAE,MAAOtB,GAEP,OADAC,QAAQC,KAAK,GAAG3C,gCAAoDyC,GAC7D,IACT,Ga5BoBwN,CAAqB,CAAElM,QAAS,CAAEqG,sBAEhDhJ,EACJ4O,GACClM,aACH,OAAK1C,EAOE,CAAEA,mBAAkBgJ,qBANzB1H,QAAQC,KACN,GAAG3C,qDAEE"}
package/index.d.ts ADDED
@@ -0,0 +1,198 @@
1
+ import { SuperDoc, Editor } from '@harbour-enterprises/superdoc';
2
+ import { CommentAnnotation } from '@veltdev/types';
3
+
4
+ /**
5
+ * SDK-agnostic domain types shared across the library.
6
+ */
7
+ /**
8
+ * A plain pixel rectangle in the SuperDoc host element's coordinate space
9
+ * (origin top-left, CSS px). Analogue of SpreadJS's `SpreadRect` /
10
+ * Nutrient's `NutrientRect`. Used to position overlay highlights.
11
+ */
12
+ interface SuperDocRect {
13
+ left: number;
14
+ top: number;
15
+ width: number;
16
+ height: number;
17
+ }
18
+ /**
19
+ * Logical, durable anchor for a comment — persisted to Velt and re-resolved to
20
+ * live document positions on load. Designed to survive reload and collaborator
21
+ * round-trips: no pixel coordinates or raw ProseMirror positions are stored.
22
+ *
23
+ * The type name (`TextEditorConfig`) and the Velt context wire key
24
+ * (`textEditorConfig`) are kept identical to the sibling adapters
25
+ * (`tiptap-velt-comments`, `nutrient-velt-comments`, `spreadjs-velt-comments`)
26
+ * so the Velt integration is uniform across editors. SuperDoc, like Tiptap, is
27
+ * a flowing text editor, so the field set matches Tiptap's text anchor.
28
+ */
29
+ interface TextEditorConfig {
30
+ editorId: string;
31
+ /** Optional host document id (Velt already scopes per document). */
32
+ documentId?: string;
33
+ /** Canonical (whitespace-collapsed) selected text. */
34
+ text: string;
35
+ /** 1-based index of this exact text among identical strings in the document. */
36
+ occurrence: number;
37
+ }
38
+ /** Minimal shape of a Velt annotation as consumed by this library. */
39
+ interface VeltAnnotationLike {
40
+ annotationId: string;
41
+ textEditorConfig?: TextEditorConfig;
42
+ }
43
+ /** Configuration passed to `SuperDocVeltComments.configure`. */
44
+ interface SuperDocVeltCommentsConfig {
45
+ editorId?: string;
46
+ /**
47
+ * When a comment thread is selected (e.g. opened from the sidebar), scroll its
48
+ * anchored text into view. Defaults to `true`; set `false` to opt out.
49
+ * (Mirrors the sibling adapters.)
50
+ */
51
+ scrollToSelectedComment?: boolean;
52
+ }
53
+ /**
54
+ * Handle returned by `SuperDocVeltComments.attach`. Call `detach` to remove
55
+ * every listener/subscription and clean up per-instance state + overlay DOM.
56
+ */
57
+ interface AttachedExtension {
58
+ detach: () => void;
59
+ }
60
+
61
+ /**
62
+ * Host adapter type definitions — SuperDoc-specific.
63
+ *
64
+ * This is the ONLY place where @harbour-enterprises/superdoc types are imported,
65
+ * and they are TYPE-ONLY imports. No prosemirror / tiptap packages are imported
66
+ * anywhere in this library: the ProseMirror objects we use at runtime
67
+ * (`editor.state`, the transaction's `mapping`, `editor.presentationEditor`) are
68
+ * handed to us by SuperDoc, and we type them via SuperDoc's own re-exported types
69
+ * (`EditorState`, `Transaction` are re-exported from the package root).
70
+ */
71
+
72
+ /** The SuperDoc instance (`new SuperDoc({...})`) — the public attach() handle. */
73
+ type SuperDocInstance = SuperDoc;
74
+ /** The active ProseMirror-based editor reached via `superdoc.activeEditor`. */
75
+ type SuperDocEditor = Editor;
76
+
77
+ /** A resolved live document range (ProseMirror integer positions). */
78
+ interface DocRange {
79
+ from: number;
80
+ to: number;
81
+ }
82
+
83
+ /**
84
+ * Selection capture + durable-anchor construction.
85
+ *
86
+ * We snapshot the editor's text selection on every `selectionUpdate` (so the
87
+ * value survives the user clicking the Add-Comment button, which moves DOM focus
88
+ * out of the editor), then build the durable `{ editorId, text, occurrence }`
89
+ * anchor from the snapshot.
90
+ */
91
+
92
+ interface SelectionSnapshot {
93
+ range: DocRange;
94
+ text: string;
95
+ occurrence: number;
96
+ }
97
+ declare const recordSelection: (instance: SuperDocInstance, snapshot: SelectionSnapshot | null) => void;
98
+ /** Read the editor's current selection into a snapshot (or null if collapsed). */
99
+ declare const captureSelection: (instance: SuperDocInstance) => void;
100
+
101
+ /**
102
+ * Extension factory — `SuperDocVeltComments`.
103
+ *
104
+ * `SuperDocVeltComments.configure(...)` builds a configured extension;
105
+ * `.attach(superdoc)` wires the editor + UI listeners and overlay layer and
106
+ * returns a handle whose `detach()` tears everything down. Attach AFTER the
107
+ * editor is ready (`onReady` / `superdoc.activeEditor` non-null), so the overlay
108
+ * can anchor against the painted document.
109
+ *
110
+ * Reposition is driven by the single official `ui.viewport.observe` signal
111
+ * (layout / zoom / scroll / resize, coalesced) plus content edits; the editor's
112
+ * `update` event drives position remapping + anchor re-sync, and
113
+ * `selectionUpdate` captures the live selection for addComment.
114
+ */
115
+
116
+ declare global {
117
+ interface Window {
118
+ /** Dev/test hook (mirrors the sibling adapters' `__velt*Test`). */
119
+ __veltSuperDocTest?: {
120
+ instance: SuperDocInstance;
121
+ recordSelection: (instance: SuperDocInstance, snapshot: SelectionSnapshot | null) => void;
122
+ };
123
+ }
124
+ }
125
+ declare class SuperDocVeltComments {
126
+ private readonly config;
127
+ private constructor();
128
+ static configure(config?: SuperDocVeltCommentsConfig): SuperDocVeltComments;
129
+ attach(instance: SuperDocInstance): AttachedExtension;
130
+ }
131
+
132
+ /**
133
+ * Add comment flow (mirror of the sibling adapters):
134
+ * 1. Read the recorded selection → build the durable anchor
135
+ * `{ editorId, text, occurrence }`.
136
+ * 2. Persist via Velt's programmatic `addCommentAnnotation`. The optimistic
137
+ * `useCommentAnnotations` emission during the `await` drives
138
+ * `renderComments`, which paints the pin — we never paint here.
139
+ *
140
+ * The anchor is durable: text + occurrence survive reload + collaborator
141
+ * round-trips. Live positions are tracked in the overlay record and re-derived
142
+ * from the anchor on load.
143
+ */
144
+
145
+ interface AddCommentArgs {
146
+ instance: SuperDocInstance;
147
+ }
148
+ interface AddCommentResult {
149
+ veltAnnotationId: string;
150
+ textEditorConfig: TextEditorConfig;
151
+ }
152
+ declare const addComment: ({ instance, }: AddCommentArgs) => Promise<AddCommentResult | null>;
153
+
154
+ /**
155
+ * Render comments flow.
156
+ *
157
+ * Velt's `useCommentAnnotations` (host app) drives this. We diff the desired set
158
+ * against the tracked overlays — removing stale ones, painting new ones. Painting
159
+ * resolves each anchor's `text`+`occurrence` to a live document range, creates
160
+ * the overlay, and positions it from the painted rects.
161
+ */
162
+
163
+ interface RenderCommentsArgs {
164
+ instance: SuperDocInstance;
165
+ commentAnnotations: CommentAnnotation[] | null | undefined;
166
+ }
167
+ declare const renderComments: ({ instance, commentAnnotations, }: RenderCommentsArgs) => void;
168
+
169
+ /**
170
+ * ProseMirror document position helpers — the SuperDoc analogue of SpreadJS's
171
+ * cell math / Nutrient's text search.
172
+ *
173
+ * Two directions:
174
+ * - resolve a durable anchor (text + occurrence) → live `{from,to}` positions
175
+ * (used on load and re-render), and
176
+ * - keep a live `{from,to}` glued to its text as the document is edited, by
177
+ * remapping through each transaction's `mapping` (the same thing a
178
+ * ProseMirror decoration/mark does internally — done with SuperDoc's own
179
+ * objects, no prosemirror import).
180
+ *
181
+ * All ProseMirror objects here are handed to us by SuperDoc (`editor.state`,
182
+ * the transaction). We never import prosemirror.
183
+ */
184
+
185
+ /**
186
+ * Resolve a durable anchor (text + 1-based occurrence) to a live range. Clamps
187
+ * to the last occurrence if `occurrence` overshoots; null if the text is gone.
188
+ */
189
+ declare const resolveTextOccurrenceToRange: (editor: SuperDocEditor, text: string, occurrence: number) => DocRange | null;
190
+ /**
191
+ * Which 1-based occurrence of `text` the given range corresponds to. Returns the
192
+ * index of the matching range (overlap), else 1. Used to derive the durable
193
+ * occurrence at create time and after edits.
194
+ */
195
+ declare const computeOccurrenceForRange: (editor: SuperDocEditor, text: string, range: DocRange) => number;
196
+
197
+ export { SuperDocVeltComments, addComment, captureSelection, computeOccurrenceForRange, recordSelection, renderComments, resolveTextOccurrenceToRange };
198
+ export type { AddCommentArgs, AddCommentResult, AttachedExtension, RenderCommentsArgs, SuperDocInstance, SuperDocRect, SuperDocVeltCommentsConfig, TextEditorConfig, VeltAnnotationLike };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@veltdev/superdoc-velt-comments",
3
+ "version": "1.0.0",
4
+ "description": "SuperDoc (DOCX editor) wrapper library to add Google Docs-style overlay comments to your SuperDoc editor. Works with the Velt Collaboration SDK.",
5
+ "homepage": "https://velt.dev",
6
+ "keywords": [
7
+ "superdoc",
8
+ "docx",
9
+ "word",
10
+ "prosemirror",
11
+ "editor",
12
+ "rich-text",
13
+ "react",
14
+ "velt",
15
+ "real-time",
16
+ "realtime",
17
+ "toolkit",
18
+ "multiplayer",
19
+ "websockets",
20
+ "collaboration",
21
+ "collaborative",
22
+ "presence",
23
+ "rooms",
24
+ "documents",
25
+ "comment",
26
+ "comments",
27
+ "annotations",
28
+ "cursors",
29
+ "notifications",
30
+ "cord",
31
+ "liveblocks"
32
+ ],
33
+ "scripts": {
34
+ "test": "echo \"Error: no test specified\" && exit 1",
35
+ "version:update": "node ../update-npm-package.mjs",
36
+ "publish:extension": "npm publish --access public"
37
+ },
38
+ "author": "Velt",
39
+ "license": "Proprietary",
40
+ "main": "cjs/index.js",
41
+ "module": "esm/index.js",
42
+ "types": "index.d.ts",
43
+ "peerDependencies": {
44
+ "@harbour-enterprises/superdoc": "^1.41.0"
45
+ }
46
+ }