@eigenpal/docx-editor-react 1.4.0 → 1.6.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 (74) hide show
  1. package/dist/{FindReplaceDialog-ETVJEMEM.js → FindReplaceDialog-HM63BMXE.js} +1 -1
  2. package/dist/{FindReplaceDialog-2ZH4XD5C.mjs → FindReplaceDialog-KU5TEIBJ.mjs} +1 -1
  3. package/dist/FootnotePropertiesDialog-TV2BGQDC.js +1 -0
  4. package/dist/FootnotePropertiesDialog-W3YHM4BV.mjs +1 -0
  5. package/dist/HyperlinkDialog-7MEQJIYP.js +1 -0
  6. package/dist/{HyperlinkDialog-PSJ6P3E3.mjs → HyperlinkDialog-ZYH7ZHRF.mjs} +1 -1
  7. package/dist/ImagePositionDialog-HEWYR6Q3.mjs +1 -0
  8. package/dist/ImagePositionDialog-LSCCQORZ.js +1 -0
  9. package/dist/ImagePropertiesDialog-RAB47C6M.mjs +1 -0
  10. package/dist/ImagePropertiesDialog-Z4M6XKFG.js +1 -0
  11. package/dist/PageSetupDialog-AIGIXO3E.mjs +1 -0
  12. package/dist/{PageSetupDialog-UKXK6X35.js → PageSetupDialog-LWYOYKEU.js} +1 -1
  13. package/dist/SplitCellDialog-45W7SDPY.js +1 -0
  14. package/dist/SplitCellDialog-IFBKYCD6.mjs +1 -0
  15. package/dist/TablePropertiesDialog-TMLKGOOW.mjs +1 -0
  16. package/dist/TablePropertiesDialog-VCDCPM3R.js +1 -0
  17. package/dist/WatermarkDialog-KRL7WMIS.mjs +1 -0
  18. package/dist/WatermarkDialog-XGLAH3TK.js +1 -0
  19. package/dist/chunk-4Y4JFAPY.mjs +2 -0
  20. package/dist/chunk-74OM4KEH.js +2 -0
  21. package/dist/chunk-BABMU5KA.mjs +2 -0
  22. package/dist/chunk-GDJM7SOG.js +2 -0
  23. package/dist/chunk-GWXEFL3H.js +1 -0
  24. package/dist/chunk-J72K2BOS.mjs +2 -0
  25. package/dist/{chunk-B5AYO5OG.js → chunk-LNONBJQM.js} +1 -1
  26. package/dist/{chunk-K5DD2LSK.mjs → chunk-O6M2HAIZ.mjs} +1 -1
  27. package/dist/chunk-OCA7BO3G.mjs +1 -0
  28. package/dist/chunk-OMYLJAPA.mjs +2 -0
  29. package/dist/chunk-P5ZOUQIK.mjs +1 -0
  30. package/dist/{chunk-JGPOALUP.js → chunk-PSBO3UDN.js} +1 -1
  31. package/dist/chunk-QD7BVJV3.js +2 -0
  32. package/dist/{chunk-2YRWZCRK.mjs → chunk-WFGAQC2B.mjs} +1 -1
  33. package/dist/chunk-WNWY6WX7.js +2 -0
  34. package/dist/chunk-YY52FSUR.js +1 -0
  35. package/dist/dialogs.js +1 -1
  36. package/dist/dialogs.mjs +1 -1
  37. package/dist/hooks.js +1 -1
  38. package/dist/hooks.mjs +1 -1
  39. package/dist/index.d.mts +75 -3
  40. package/dist/index.d.ts +75 -3
  41. package/dist/index.js +9 -9
  42. package/dist/index.mjs +9 -9
  43. package/dist/styles.css +1 -1
  44. package/dist/ui.d.mts +106 -32
  45. package/dist/ui.d.ts +106 -32
  46. package/dist/ui.js +7 -7
  47. package/dist/ui.mjs +7 -7
  48. package/package.json +4 -4
  49. package/dist/FootnotePropertiesDialog-INLVLE26.mjs +0 -1
  50. package/dist/FootnotePropertiesDialog-WCGK6MV3.js +0 -1
  51. package/dist/HyperlinkDialog-G5FFKLWY.js +0 -1
  52. package/dist/ImagePositionDialog-DTGYFFAR.js +0 -1
  53. package/dist/ImagePositionDialog-FKBG2MSL.mjs +0 -1
  54. package/dist/ImagePropertiesDialog-SO6RAOT6.js +0 -1
  55. package/dist/ImagePropertiesDialog-T77XMKJF.mjs +0 -1
  56. package/dist/PageSetupDialog-CCJAZEIN.mjs +0 -1
  57. package/dist/SplitCellDialog-NPGW4JGQ.mjs +0 -1
  58. package/dist/SplitCellDialog-RNP37SKZ.js +0 -1
  59. package/dist/TablePropertiesDialog-3QNCWNEG.mjs +0 -1
  60. package/dist/TablePropertiesDialog-AQVM7FGA.js +0 -1
  61. package/dist/WatermarkDialog-6QSGGPXJ.mjs +0 -1
  62. package/dist/WatermarkDialog-CYTWCE75.js +0 -1
  63. package/dist/chunk-3L2QMHNA.mjs +0 -2
  64. package/dist/chunk-4SYDL233.js +0 -1
  65. package/dist/chunk-53P6TCSE.js +0 -2
  66. package/dist/chunk-5BSDRI3Z.js +0 -1
  67. package/dist/chunk-72ZQJWN2.mjs +0 -2
  68. package/dist/chunk-AYHZMFCQ.mjs +0 -1
  69. package/dist/chunk-EKDRHOOJ.js +0 -2
  70. package/dist/chunk-ICVBXT6V.mjs +0 -2
  71. package/dist/chunk-IL65NW44.mjs +0 -2
  72. package/dist/chunk-P3ADI7OT.mjs +0 -1
  73. package/dist/chunk-PGHNUFNT.js +0 -2
  74. package/dist/chunk-UT6DJWGC.js +0 -2
package/dist/hooks.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkB5AYO5OG_js=require('./chunk-B5AYO5OG.js'),chunkNIBCC7WQ_js=require('./chunk-NIBCC7WQ.js'),chunkEKDRHOOJ_js=require('./chunk-EKDRHOOJ.js'),chunkL4MDZW2J_js=require('./chunk-L4MDZW2J.js');require('./chunk-GNIO6SOS.js'),require('./chunk-BJ5RZW6Y.js');var re=require('react'),utils=require('@eigenpal/docx-editor-core/utils'),docxEditorCore=require('@eigenpal/docx-editor-core');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var re__default=/*#__PURE__*/_interopDefault(re);function de(n){let{containerRef:e,enabled:r=true,config:s=utils.DEFAULT_SELECTION_STYLE,useOverlay:u=false,debounceMs:c=16,onSelectionChange:f}=n,[h,p]=re.useState(false),[x,v]=re.useState(""),[a,m]=re.useState([]),[d,y]=re.useState(false),S=re.useRef(null),C=re.useRef(0),o=re.useCallback(()=>{let t=e.current,b=utils.hasActiveSelection(),D=utils.getSelectedText(),A=t?utils.isSelectionWithin(t):false;if(p(b),v(D),y(A),u&&A){let $=utils.getMergedSelectionRects(t);m($);}else m([]);f&&f(b&&A,D);},[e,u,f]),i=re.useCallback(()=>{let t=performance.now();if(t-C.current<c){S.current!==null&&clearTimeout(S.current),S.current=window.setTimeout(()=>{C.current=performance.now(),o(),S.current=null;},c);return}C.current=t,o();},[c,o]),l=re.useCallback(()=>{o();},[o]),R=re.useCallback(t=>({position:"absolute",left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,backgroundColor:s.backgroundColor,borderRadius:s.borderRadius?`${s.borderRadius}px`:void 0,border:s.borderColor?`1px solid ${s.borderColor}`:void 0,zIndex:s.zIndex??0,opacity:s.opacity??1,mixBlendMode:s.mixBlendMode,pointerEvents:"none",userSelect:"none"}),[s]);return re.useEffect(()=>(r&&!utils.areSelectionStylesInjected()&&utils.injectSelectionStyles(s),()=>{}),[r,s]),re.useEffect(()=>{if(!r)return;let t=()=>{i();};return document.addEventListener("selectionchange",t),document.addEventListener("mouseup",t),o(),()=>{document.removeEventListener("selectionchange",t),document.removeEventListener("mouseup",t),S.current!==null&&clearTimeout(S.current);}},[r,i,o]),{hasSelection:h,selectedText:x,highlightRects:a,isSelectionInContainer:d,refresh:l,getOverlayStyle:R}}function pe(n,e=utils.DEFAULT_SELECTION_STYLE){return n.map((r,s)=>re__default.default.createElement("div",{key:`selection-overlay-${s}`,style:{position:"absolute",left:`${r.left}px`,top:`${r.top}px`,width:`${r.width}px`,height:`${r.height}px`,backgroundColor:e.backgroundColor,borderRadius:e.borderRadius?`${e.borderRadius}px`:void 0,border:e.borderColor?`1px solid ${e.borderColor}`:void 0,zIndex:e.zIndex??0,opacity:e.opacity??1,mixBlendMode:e.mixBlendMode,pointerEvents:"none",userSelect:"none"}}))}function he(n={}){let{onCopy:e,onCut:r,onPaste:s,cleanWordFormatting:u=true,editable:c=true,onError:f,theme:h}=n,p=re.useRef(false),x=re.useRef(null),v=re.useCallback(async o=>{if(p.current)return false;p.current=true;try{let i=await utils.copyRuns(o.runs,{onError:f,theme:h});return i&&e?.(o),i}finally{p.current=false;}},[e,f,h]),a=re.useCallback(async o=>{if(p.current||!c)return false;p.current=true;try{let i=await utils.copyRuns(o.runs,{onError:f,theme:h});return i&&r?.(o),i}finally{p.current=false;}},[r,c,f,h]),m=re.useCallback(async(o=false)=>{if(p.current||!c)return null;p.current=true;try{if(navigator.clipboard&&navigator.clipboard.read){let i=await navigator.clipboard.read(),l="",R="";for(let b of i)b.types.includes("text/html")&&(l=await(await b.getType("text/html")).text()),b.types.includes("text/plain")&&(R=await(await b.getType("text/plain")).text());o&&(l="");let t=utils.parseClipboardHtml(l,R,u);return x.current=t,s?.(t,o),t}return null}catch(i){return f?.(i),null}finally{p.current=false;}},[c,u,s,f]),d=re.useCallback(o=>{let i=docxEditorCore.createSelectionFromDOM();if(!i)return;o.preventDefault();let l=utils.runsToClipboardContent(i.runs,true,h);o.clipboardData&&(o.clipboardData.setData("text/plain",l.plainText),o.clipboardData.setData("text/html",l.html),l.internal&&o.clipboardData.setData("application/x-docx-editor",l.internal)),e?.(i);},[e,h]),y=re.useCallback(o=>{if(!c)return;let i=docxEditorCore.createSelectionFromDOM();if(!i)return;o.preventDefault();let l=utils.runsToClipboardContent(i.runs,true,h);o.clipboardData&&(o.clipboardData.setData("text/plain",l.plainText),o.clipboardData.setData("text/html",l.html),l.internal&&o.clipboardData.setData("application/x-docx-editor",l.internal)),r?.(i);},[c,r,h]),S=re.useCallback(o=>{if(!c)return;o.preventDefault();let i=utils.handlePasteEvent(o,{cleanWordFormatting:u});if(i){x.current=i;let l=o.shiftKey??false;s?.(i,l);}},[c,u,s]),C=re.useCallback(o=>{},[]);return {copy:v,cut:a,paste:m,handleCopy:d,handleCut:y,handlePaste:S,handleKeyDown:C,isProcessing:p.current,lastPastedContent:x.current}}function Ee(n,e={}){let{storageKey:r,interval:s,enabled:u=true,maxAge:c,onSave:f,onError:h,onRecoveryAvailable:p,saveOnChange:x,debounceDelay:v}=e,a=re.useMemo(()=>new docxEditorCore.AutoSaveManager({storageKey:r,interval:s,maxAge:c,saveOnChange:x,debounceDelay:v,onSave:f,onError:h,onRecoveryAvailable:p}),[r]);re.useEffect(()=>{u?(a.enable(),a.startInterval()):a.disable();},[a,u]),re.useEffect(()=>{a.onDocumentChanged(n??null);},[a,n]),re.useEffect(()=>()=>{a.destroy();},[a]);let m=re.useSyncExternalStore(a.subscribe,a.getSnapshot),d=re.useCallback(()=>a.save(),[a]),y=re.useCallback(()=>a.clear(),[a]),S=re.useCallback(()=>a.getRecoveryData(),[a]),C=re.useCallback(()=>a.acceptRecovery(),[a]),o=re.useCallback(()=>a.dismissRecovery(),[a]),i=re.useCallback(()=>a.enable(),[a]),l=re.useCallback(()=>a.disable(),[a]);return {status:m.status,lastSaveTime:m.lastSaveTime,save:d,clearAutoSave:y,hasRecoveryData:m.hasRecoveryData,getRecoveryData:S,acceptRecovery:C,dismissRecovery:o,isEnabled:m.isEnabled,enable:i,disable:l}}var Pe=1,K=.25,W=4,Ze=.1,g=[.25,.5,.75,1,1.25,1.5,2,3,4];function _(n,e,r){return Math.max(e,Math.min(r,n))}function N(n){return Math.round(n*100)/100}function Ae(n){let e=g[0],r=Math.abs(n-e);for(let s of g){let u=Math.abs(n-s);u<r&&(r=u,e=s);}return e}function Ue(n){for(let e of g)if(e>n+.01)return e;return g[g.length-1]}function Me(n){for(let e=g.length-1;e>=0;e--)if(g[e]<n-.01)return g[e];return g[0]}function He(n={}){let{initialZoom:e=Pe,minZoom:r=K,maxZoom:s=W,zoomStep:u=Ze,enabled:c=true,containerRef:f,onZoomChange:h,enableKeyboardShortcuts:p=true,preventDefault:x=true}=n,[v,a]=re.useState(e),m=re.useRef(v);re.useEffect(()=>{m.current=v;},[v]);let d=re.useCallback(t=>{let b=N(_(t,r,s));b!==m.current&&(a(b),h?.(b));},[r,s,h]),y=re.useCallback(()=>{d(m.current+u);},[u,d]),S=re.useCallback(()=>{d(m.current-u);},[u,d]),C=re.useCallback(()=>{d(e);},[e,d]),o=re.useCallback(()=>{d(1);},[d]),i=re.useCallback((t,b)=>{if(b>0){let D=t/b;d(D);}},[d]),l=re.useCallback(t=>{if(!c||!(t.ctrlKey||t.metaKey))return;x&&t.preventDefault();let D=t.deltaY;D<0?d(m.current+u):D>0&&d(m.current-u);},[c,x,u,d]),R=re.useCallback(t=>{if(!(!c||!p||!(t.ctrlKey||t.metaKey))){if(t.key==="0"){t.preventDefault(),o();return}if(t.key==="+"||t.key==="="){t.preventDefault(),y();return}if(t.key==="-"){t.preventDefault(),S();return}}},[c,p,y,S,o]);return re.useEffect(()=>{if(!c)return;let t=f?.current;if(t)return t.addEventListener("wheel",l,{passive:false}),()=>{t.removeEventListener("wheel",l);}},[c,f,l]),re.useEffect(()=>{if(!(!c||!p))return document.addEventListener("keydown",R),()=>{document.removeEventListener("keydown",R);}},[c,p,R]),{zoom:v,setZoom:d,zoomIn:y,zoomOut:S,resetZoom:C,zoomTo100:o,zoomToFit:i,isMinZoom:v<=r,isMaxZoom:v>=s,zoomPercent:Math.round(v*100),handleWheel:l,handleKeyDown:R}}function we(){return [...g]}function Le(n){return Ae(n)}function ze(n){return Ue(n)}function ke(n){return Me(n)}function Fe(n){return `${Math.round(n*100)}%`}function Ie(n){let e=n.match(/(\d+(\.\d+)?)/);if(e){let r=parseFloat(e[1]);if(!isNaN(r))return r/100}return null}function Ke(n){return g.some(e=>Math.abs(e-n)<.01)}function We(n,e=K,r=W){return N(_(n,e,r))}Object.defineProperty(exports,"HistoryManager",{enumerable:true,get:function(){return chunkB5AYO5OG_js.j}});Object.defineProperty(exports,"TABLE_DATA_ATTRIBUTES",{enumerable:true,get:function(){return chunkB5AYO5OG_js.f}});Object.defineProperty(exports,"extractTrackedChanges",{enumerable:true,get:function(){return chunkB5AYO5OG_js.c}});Object.defineProperty(exports,"useAutoHistory",{enumerable:true,get:function(){return chunkB5AYO5OG_js.h}});Object.defineProperty(exports,"useDocumentHistory",{enumerable:true,get:function(){return chunkB5AYO5OG_js.i}});Object.defineProperty(exports,"useDragAutoScroll",{enumerable:true,get:function(){return chunkB5AYO5OG_js.b}});Object.defineProperty(exports,"useHistory",{enumerable:true,get:function(){return chunkB5AYO5OG_js.g}});Object.defineProperty(exports,"useTableSelection",{enumerable:true,get:function(){return chunkB5AYO5OG_js.e}});Object.defineProperty(exports,"useTrackedChanges",{enumerable:true,get:function(){return chunkB5AYO5OG_js.d}});Object.defineProperty(exports,"useVisualLineNavigation",{enumerable:true,get:function(){return chunkB5AYO5OG_js.a}});Object.defineProperty(exports,"useAspectLockedSize",{enumerable:true,get:function(){return chunkNIBCC7WQ_js.a}});Object.defineProperty(exports,"useFixedDropdown",{enumerable:true,get:function(){return chunkEKDRHOOJ_js.c}});Object.defineProperty(exports,"useFindReplace",{enumerable:true,get:function(){return chunkL4MDZW2J_js.b}});Object.defineProperty(exports,"createSelectionFromDOM",{enumerable:true,get:function(){return docxEditorCore.createSelectionFromDOM}});Object.defineProperty(exports,"formatLastSaveTime",{enumerable:true,get:function(){return docxEditorCore.formatLastSaveTime}});Object.defineProperty(exports,"formatStorageSize",{enumerable:true,get:function(){return docxEditorCore.formatStorageSize}});Object.defineProperty(exports,"getAutoSaveStatusLabel",{enumerable:true,get:function(){return docxEditorCore.getAutoSaveStatusLabel}});Object.defineProperty(exports,"getAutoSaveStorageSize",{enumerable:true,get:function(){return docxEditorCore.getAutoSaveStorageSize}});Object.defineProperty(exports,"getSelectionRuns",{enumerable:true,get:function(){return docxEditorCore.getSelectionRuns}});Object.defineProperty(exports,"isAutoSaveSupported",{enumerable:true,get:function(){return docxEditorCore.isAutoSaveSupported}});exports.ZOOM_PRESETS=g;exports.clampZoom=We;exports.findNearestZoomPreset=Le;exports.formatZoom=Fe;exports.generateOverlayElements=pe;exports.getNextZoomPreset=ze;exports.getPreviousZoomPreset=ke;exports.getZoomPresets=we;exports.isZoomPreset=Ke;exports.parseZoom=Ie;exports.useAutoSave=Ee;exports.useClipboard=he;exports.useSelectionHighlight=de;exports.useWheelZoom=He;
1
+ 'use strict';var chunkLNONBJQM_js=require('./chunk-LNONBJQM.js'),chunkNIBCC7WQ_js=require('./chunk-NIBCC7WQ.js'),chunkWNWY6WX7_js=require('./chunk-WNWY6WX7.js'),chunkL4MDZW2J_js=require('./chunk-L4MDZW2J.js');require('./chunk-GNIO6SOS.js'),require('./chunk-BJ5RZW6Y.js');var re=require('react'),utils=require('@eigenpal/docx-editor-core/utils'),docxEditorCore=require('@eigenpal/docx-editor-core');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var re__default=/*#__PURE__*/_interopDefault(re);function de(n){let{containerRef:e,enabled:r=true,config:s=utils.DEFAULT_SELECTION_STYLE,useOverlay:u=false,debounceMs:c=16,onSelectionChange:f}=n,[h,p]=re.useState(false),[x,v]=re.useState(""),[a,m]=re.useState([]),[d,y]=re.useState(false),S=re.useRef(null),C=re.useRef(0),o=re.useCallback(()=>{let t=e.current,b=utils.hasActiveSelection(),D=utils.getSelectedText(),A=t?utils.isSelectionWithin(t):false;if(p(b),v(D),y(A),u&&A){let $=utils.getMergedSelectionRects(t);m($);}else m([]);f&&f(b&&A,D);},[e,u,f]),i=re.useCallback(()=>{let t=performance.now();if(t-C.current<c){S.current!==null&&clearTimeout(S.current),S.current=window.setTimeout(()=>{C.current=performance.now(),o(),S.current=null;},c);return}C.current=t,o();},[c,o]),l=re.useCallback(()=>{o();},[o]),R=re.useCallback(t=>({position:"absolute",left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,backgroundColor:s.backgroundColor,borderRadius:s.borderRadius?`${s.borderRadius}px`:void 0,border:s.borderColor?`1px solid ${s.borderColor}`:void 0,zIndex:s.zIndex??0,opacity:s.opacity??1,mixBlendMode:s.mixBlendMode,pointerEvents:"none",userSelect:"none"}),[s]);return re.useEffect(()=>(r&&!utils.areSelectionStylesInjected()&&utils.injectSelectionStyles(s),()=>{}),[r,s]),re.useEffect(()=>{if(!r)return;let t=()=>{i();};return document.addEventListener("selectionchange",t),document.addEventListener("mouseup",t),o(),()=>{document.removeEventListener("selectionchange",t),document.removeEventListener("mouseup",t),S.current!==null&&clearTimeout(S.current);}},[r,i,o]),{hasSelection:h,selectedText:x,highlightRects:a,isSelectionInContainer:d,refresh:l,getOverlayStyle:R}}function pe(n,e=utils.DEFAULT_SELECTION_STYLE){return n.map((r,s)=>re__default.default.createElement("div",{key:`selection-overlay-${s}`,style:{position:"absolute",left:`${r.left}px`,top:`${r.top}px`,width:`${r.width}px`,height:`${r.height}px`,backgroundColor:e.backgroundColor,borderRadius:e.borderRadius?`${e.borderRadius}px`:void 0,border:e.borderColor?`1px solid ${e.borderColor}`:void 0,zIndex:e.zIndex??0,opacity:e.opacity??1,mixBlendMode:e.mixBlendMode,pointerEvents:"none",userSelect:"none"}}))}function he(n={}){let{onCopy:e,onCut:r,onPaste:s,cleanWordFormatting:u=true,editable:c=true,onError:f,theme:h}=n,p=re.useRef(false),x=re.useRef(null),v=re.useCallback(async o=>{if(p.current)return false;p.current=true;try{let i=await utils.copyRuns(o.runs,{onError:f,theme:h});return i&&e?.(o),i}finally{p.current=false;}},[e,f,h]),a=re.useCallback(async o=>{if(p.current||!c)return false;p.current=true;try{let i=await utils.copyRuns(o.runs,{onError:f,theme:h});return i&&r?.(o),i}finally{p.current=false;}},[r,c,f,h]),m=re.useCallback(async(o=false)=>{if(p.current||!c)return null;p.current=true;try{if(navigator.clipboard&&navigator.clipboard.read){let i=await navigator.clipboard.read(),l="",R="";for(let b of i)b.types.includes("text/html")&&(l=await(await b.getType("text/html")).text()),b.types.includes("text/plain")&&(R=await(await b.getType("text/plain")).text());o&&(l="");let t=utils.parseClipboardHtml(l,R,u);return x.current=t,s?.(t,o),t}return null}catch(i){return f?.(i),null}finally{p.current=false;}},[c,u,s,f]),d=re.useCallback(o=>{let i=docxEditorCore.createSelectionFromDOM();if(!i)return;o.preventDefault();let l=utils.runsToClipboardContent(i.runs,true,h);o.clipboardData&&(o.clipboardData.setData("text/plain",l.plainText),o.clipboardData.setData("text/html",l.html),l.internal&&o.clipboardData.setData("application/x-docx-editor",l.internal)),e?.(i);},[e,h]),y=re.useCallback(o=>{if(!c)return;let i=docxEditorCore.createSelectionFromDOM();if(!i)return;o.preventDefault();let l=utils.runsToClipboardContent(i.runs,true,h);o.clipboardData&&(o.clipboardData.setData("text/plain",l.plainText),o.clipboardData.setData("text/html",l.html),l.internal&&o.clipboardData.setData("application/x-docx-editor",l.internal)),r?.(i);},[c,r,h]),S=re.useCallback(o=>{if(!c)return;o.preventDefault();let i=utils.handlePasteEvent(o,{cleanWordFormatting:u});if(i){x.current=i;let l=o.shiftKey??false;s?.(i,l);}},[c,u,s]),C=re.useCallback(o=>{},[]);return {copy:v,cut:a,paste:m,handleCopy:d,handleCut:y,handlePaste:S,handleKeyDown:C,isProcessing:p.current,lastPastedContent:x.current}}function Ee(n,e={}){let{storageKey:r,interval:s,enabled:u=true,maxAge:c,onSave:f,onError:h,onRecoveryAvailable:p,saveOnChange:x,debounceDelay:v}=e,a=re.useMemo(()=>new docxEditorCore.AutoSaveManager({storageKey:r,interval:s,maxAge:c,saveOnChange:x,debounceDelay:v,onSave:f,onError:h,onRecoveryAvailable:p}),[r]);re.useEffect(()=>{u?(a.enable(),a.startInterval()):a.disable();},[a,u]),re.useEffect(()=>{a.onDocumentChanged(n??null);},[a,n]),re.useEffect(()=>()=>{a.destroy();},[a]);let m=re.useSyncExternalStore(a.subscribe,a.getSnapshot),d=re.useCallback(()=>a.save(),[a]),y=re.useCallback(()=>a.clear(),[a]),S=re.useCallback(()=>a.getRecoveryData(),[a]),C=re.useCallback(()=>a.acceptRecovery(),[a]),o=re.useCallback(()=>a.dismissRecovery(),[a]),i=re.useCallback(()=>a.enable(),[a]),l=re.useCallback(()=>a.disable(),[a]);return {status:m.status,lastSaveTime:m.lastSaveTime,save:d,clearAutoSave:y,hasRecoveryData:m.hasRecoveryData,getRecoveryData:S,acceptRecovery:C,dismissRecovery:o,isEnabled:m.isEnabled,enable:i,disable:l}}var Pe=1,K=.25,W=4,Ze=.1,g=[.25,.5,.75,1,1.25,1.5,2,3,4];function _(n,e,r){return Math.max(e,Math.min(r,n))}function N(n){return Math.round(n*100)/100}function Ae(n){let e=g[0],r=Math.abs(n-e);for(let s of g){let u=Math.abs(n-s);u<r&&(r=u,e=s);}return e}function Ue(n){for(let e of g)if(e>n+.01)return e;return g[g.length-1]}function Me(n){for(let e=g.length-1;e>=0;e--)if(g[e]<n-.01)return g[e];return g[0]}function He(n={}){let{initialZoom:e=Pe,minZoom:r=K,maxZoom:s=W,zoomStep:u=Ze,enabled:c=true,containerRef:f,onZoomChange:h,enableKeyboardShortcuts:p=true,preventDefault:x=true}=n,[v,a]=re.useState(e),m=re.useRef(v);re.useEffect(()=>{m.current=v;},[v]);let d=re.useCallback(t=>{let b=N(_(t,r,s));b!==m.current&&(a(b),h?.(b));},[r,s,h]),y=re.useCallback(()=>{d(m.current+u);},[u,d]),S=re.useCallback(()=>{d(m.current-u);},[u,d]),C=re.useCallback(()=>{d(e);},[e,d]),o=re.useCallback(()=>{d(1);},[d]),i=re.useCallback((t,b)=>{if(b>0){let D=t/b;d(D);}},[d]),l=re.useCallback(t=>{if(!c||!(t.ctrlKey||t.metaKey))return;x&&t.preventDefault();let D=t.deltaY;D<0?d(m.current+u):D>0&&d(m.current-u);},[c,x,u,d]),R=re.useCallback(t=>{if(!(!c||!p||!(t.ctrlKey||t.metaKey))){if(t.key==="0"){t.preventDefault(),o();return}if(t.key==="+"||t.key==="="){t.preventDefault(),y();return}if(t.key==="-"){t.preventDefault(),S();return}}},[c,p,y,S,o]);return re.useEffect(()=>{if(!c)return;let t=f?.current;if(t)return t.addEventListener("wheel",l,{passive:false}),()=>{t.removeEventListener("wheel",l);}},[c,f,l]),re.useEffect(()=>{if(!(!c||!p))return document.addEventListener("keydown",R),()=>{document.removeEventListener("keydown",R);}},[c,p,R]),{zoom:v,setZoom:d,zoomIn:y,zoomOut:S,resetZoom:C,zoomTo100:o,zoomToFit:i,isMinZoom:v<=r,isMaxZoom:v>=s,zoomPercent:Math.round(v*100),handleWheel:l,handleKeyDown:R}}function we(){return [...g]}function Le(n){return Ae(n)}function ze(n){return Ue(n)}function ke(n){return Me(n)}function Fe(n){return `${Math.round(n*100)}%`}function Ie(n){let e=n.match(/(\d+(\.\d+)?)/);if(e){let r=parseFloat(e[1]);if(!isNaN(r))return r/100}return null}function Ke(n){return g.some(e=>Math.abs(e-n)<.01)}function We(n,e=K,r=W){return N(_(n,e,r))}Object.defineProperty(exports,"HistoryManager",{enumerable:true,get:function(){return chunkLNONBJQM_js.j}});Object.defineProperty(exports,"TABLE_DATA_ATTRIBUTES",{enumerable:true,get:function(){return chunkLNONBJQM_js.f}});Object.defineProperty(exports,"extractTrackedChanges",{enumerable:true,get:function(){return chunkLNONBJQM_js.c}});Object.defineProperty(exports,"useAutoHistory",{enumerable:true,get:function(){return chunkLNONBJQM_js.h}});Object.defineProperty(exports,"useDocumentHistory",{enumerable:true,get:function(){return chunkLNONBJQM_js.i}});Object.defineProperty(exports,"useDragAutoScroll",{enumerable:true,get:function(){return chunkLNONBJQM_js.b}});Object.defineProperty(exports,"useHistory",{enumerable:true,get:function(){return chunkLNONBJQM_js.g}});Object.defineProperty(exports,"useTableSelection",{enumerable:true,get:function(){return chunkLNONBJQM_js.e}});Object.defineProperty(exports,"useTrackedChanges",{enumerable:true,get:function(){return chunkLNONBJQM_js.d}});Object.defineProperty(exports,"useVisualLineNavigation",{enumerable:true,get:function(){return chunkLNONBJQM_js.a}});Object.defineProperty(exports,"useAspectLockedSize",{enumerable:true,get:function(){return chunkNIBCC7WQ_js.a}});Object.defineProperty(exports,"useFixedDropdown",{enumerable:true,get:function(){return chunkWNWY6WX7_js.c}});Object.defineProperty(exports,"useFindReplace",{enumerable:true,get:function(){return chunkL4MDZW2J_js.b}});Object.defineProperty(exports,"createSelectionFromDOM",{enumerable:true,get:function(){return docxEditorCore.createSelectionFromDOM}});Object.defineProperty(exports,"formatLastSaveTime",{enumerable:true,get:function(){return docxEditorCore.formatLastSaveTime}});Object.defineProperty(exports,"formatStorageSize",{enumerable:true,get:function(){return docxEditorCore.formatStorageSize}});Object.defineProperty(exports,"getAutoSaveStatusLabel",{enumerable:true,get:function(){return docxEditorCore.getAutoSaveStatusLabel}});Object.defineProperty(exports,"getAutoSaveStorageSize",{enumerable:true,get:function(){return docxEditorCore.getAutoSaveStorageSize}});Object.defineProperty(exports,"getSelectionRuns",{enumerable:true,get:function(){return docxEditorCore.getSelectionRuns}});Object.defineProperty(exports,"isAutoSaveSupported",{enumerable:true,get:function(){return docxEditorCore.isAutoSaveSupported}});exports.ZOOM_PRESETS=g;exports.clampZoom=We;exports.findNearestZoomPreset=Le;exports.formatZoom=Fe;exports.generateOverlayElements=pe;exports.getNextZoomPreset=ze;exports.getPreviousZoomPreset=ke;exports.getZoomPresets=we;exports.isZoomPreset=Ke;exports.parseZoom=Ie;exports.useAutoSave=Ee;exports.useClipboard=he;exports.useSelectionHighlight=de;exports.useWheelZoom=He;
package/dist/hooks.mjs CHANGED
@@ -1 +1 @@
1
- export{j as HistoryManager,f as TABLE_DATA_ATTRIBUTES,c as extractTrackedChanges,h as useAutoHistory,i as useDocumentHistory,b as useDragAutoScroll,g as useHistory,e as useTableSelection,d as useTrackedChanges,a as useVisualLineNavigation}from'./chunk-2YRWZCRK.mjs';export{a as useAspectLockedSize}from'./chunk-GM2S2WMT.mjs';export{c as useFixedDropdown}from'./chunk-3L2QMHNA.mjs';export{b as useFindReplace}from'./chunk-OHNO4NRQ.mjs';import'./chunk-ZFZJRL2R.mjs';import'./chunk-BMBP5UFA.mjs';import re,{useState,useRef,useCallback,useEffect,useMemo,useSyncExternalStore}from'react';import {DEFAULT_SELECTION_STYLE,hasActiveSelection,getSelectedText,isSelectionWithin,getMergedSelectionRects,areSelectionStylesInjected,injectSelectionStyles,copyRuns,parseClipboardHtml,runsToClipboardContent,handlePasteEvent}from'@eigenpal/docx-editor-core/utils';import {createSelectionFromDOM,AutoSaveManager}from'@eigenpal/docx-editor-core';export{createSelectionFromDOM,formatLastSaveTime,formatStorageSize,getAutoSaveStatusLabel,getAutoSaveStorageSize,getSelectionRuns,isAutoSaveSupported}from'@eigenpal/docx-editor-core';function de(n){let{containerRef:e,enabled:r=true,config:s=DEFAULT_SELECTION_STYLE,useOverlay:u=false,debounceMs:c=16,onSelectionChange:f}=n,[h,p]=useState(false),[x,v]=useState(""),[a,m]=useState([]),[d,y]=useState(false),S=useRef(null),C=useRef(0),o=useCallback(()=>{let t=e.current,b=hasActiveSelection(),D=getSelectedText(),A=t?isSelectionWithin(t):false;if(p(b),v(D),y(A),u&&A){let $=getMergedSelectionRects(t);m($);}else m([]);f&&f(b&&A,D);},[e,u,f]),i=useCallback(()=>{let t=performance.now();if(t-C.current<c){S.current!==null&&clearTimeout(S.current),S.current=window.setTimeout(()=>{C.current=performance.now(),o(),S.current=null;},c);return}C.current=t,o();},[c,o]),l=useCallback(()=>{o();},[o]),R=useCallback(t=>({position:"absolute",left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,backgroundColor:s.backgroundColor,borderRadius:s.borderRadius?`${s.borderRadius}px`:void 0,border:s.borderColor?`1px solid ${s.borderColor}`:void 0,zIndex:s.zIndex??0,opacity:s.opacity??1,mixBlendMode:s.mixBlendMode,pointerEvents:"none",userSelect:"none"}),[s]);return useEffect(()=>(r&&!areSelectionStylesInjected()&&injectSelectionStyles(s),()=>{}),[r,s]),useEffect(()=>{if(!r)return;let t=()=>{i();};return document.addEventListener("selectionchange",t),document.addEventListener("mouseup",t),o(),()=>{document.removeEventListener("selectionchange",t),document.removeEventListener("mouseup",t),S.current!==null&&clearTimeout(S.current);}},[r,i,o]),{hasSelection:h,selectedText:x,highlightRects:a,isSelectionInContainer:d,refresh:l,getOverlayStyle:R}}function pe(n,e=DEFAULT_SELECTION_STYLE){return n.map((r,s)=>re.createElement("div",{key:`selection-overlay-${s}`,style:{position:"absolute",left:`${r.left}px`,top:`${r.top}px`,width:`${r.width}px`,height:`${r.height}px`,backgroundColor:e.backgroundColor,borderRadius:e.borderRadius?`${e.borderRadius}px`:void 0,border:e.borderColor?`1px solid ${e.borderColor}`:void 0,zIndex:e.zIndex??0,opacity:e.opacity??1,mixBlendMode:e.mixBlendMode,pointerEvents:"none",userSelect:"none"}}))}function he(n={}){let{onCopy:e,onCut:r,onPaste:s,cleanWordFormatting:u=true,editable:c=true,onError:f,theme:h}=n,p=useRef(false),x=useRef(null),v=useCallback(async o=>{if(p.current)return false;p.current=true;try{let i=await copyRuns(o.runs,{onError:f,theme:h});return i&&e?.(o),i}finally{p.current=false;}},[e,f,h]),a=useCallback(async o=>{if(p.current||!c)return false;p.current=true;try{let i=await copyRuns(o.runs,{onError:f,theme:h});return i&&r?.(o),i}finally{p.current=false;}},[r,c,f,h]),m=useCallback(async(o=false)=>{if(p.current||!c)return null;p.current=true;try{if(navigator.clipboard&&navigator.clipboard.read){let i=await navigator.clipboard.read(),l="",R="";for(let b of i)b.types.includes("text/html")&&(l=await(await b.getType("text/html")).text()),b.types.includes("text/plain")&&(R=await(await b.getType("text/plain")).text());o&&(l="");let t=parseClipboardHtml(l,R,u);return x.current=t,s?.(t,o),t}return null}catch(i){return f?.(i),null}finally{p.current=false;}},[c,u,s,f]),d=useCallback(o=>{let i=createSelectionFromDOM();if(!i)return;o.preventDefault();let l=runsToClipboardContent(i.runs,true,h);o.clipboardData&&(o.clipboardData.setData("text/plain",l.plainText),o.clipboardData.setData("text/html",l.html),l.internal&&o.clipboardData.setData("application/x-docx-editor",l.internal)),e?.(i);},[e,h]),y=useCallback(o=>{if(!c)return;let i=createSelectionFromDOM();if(!i)return;o.preventDefault();let l=runsToClipboardContent(i.runs,true,h);o.clipboardData&&(o.clipboardData.setData("text/plain",l.plainText),o.clipboardData.setData("text/html",l.html),l.internal&&o.clipboardData.setData("application/x-docx-editor",l.internal)),r?.(i);},[c,r,h]),S=useCallback(o=>{if(!c)return;o.preventDefault();let i=handlePasteEvent(o,{cleanWordFormatting:u});if(i){x.current=i;let l=o.shiftKey??false;s?.(i,l);}},[c,u,s]),C=useCallback(o=>{},[]);return {copy:v,cut:a,paste:m,handleCopy:d,handleCut:y,handlePaste:S,handleKeyDown:C,isProcessing:p.current,lastPastedContent:x.current}}function Ee(n,e={}){let{storageKey:r,interval:s,enabled:u=true,maxAge:c,onSave:f,onError:h,onRecoveryAvailable:p,saveOnChange:x,debounceDelay:v}=e,a=useMemo(()=>new AutoSaveManager({storageKey:r,interval:s,maxAge:c,saveOnChange:x,debounceDelay:v,onSave:f,onError:h,onRecoveryAvailable:p}),[r]);useEffect(()=>{u?(a.enable(),a.startInterval()):a.disable();},[a,u]),useEffect(()=>{a.onDocumentChanged(n??null);},[a,n]),useEffect(()=>()=>{a.destroy();},[a]);let m=useSyncExternalStore(a.subscribe,a.getSnapshot),d=useCallback(()=>a.save(),[a]),y=useCallback(()=>a.clear(),[a]),S=useCallback(()=>a.getRecoveryData(),[a]),C=useCallback(()=>a.acceptRecovery(),[a]),o=useCallback(()=>a.dismissRecovery(),[a]),i=useCallback(()=>a.enable(),[a]),l=useCallback(()=>a.disable(),[a]);return {status:m.status,lastSaveTime:m.lastSaveTime,save:d,clearAutoSave:y,hasRecoveryData:m.hasRecoveryData,getRecoveryData:S,acceptRecovery:C,dismissRecovery:o,isEnabled:m.isEnabled,enable:i,disable:l}}var Pe=1,K=.25,W=4,Ze=.1,g=[.25,.5,.75,1,1.25,1.5,2,3,4];function _(n,e,r){return Math.max(e,Math.min(r,n))}function N(n){return Math.round(n*100)/100}function Ae(n){let e=g[0],r=Math.abs(n-e);for(let s of g){let u=Math.abs(n-s);u<r&&(r=u,e=s);}return e}function Ue(n){for(let e of g)if(e>n+.01)return e;return g[g.length-1]}function Me(n){for(let e=g.length-1;e>=0;e--)if(g[e]<n-.01)return g[e];return g[0]}function He(n={}){let{initialZoom:e=Pe,minZoom:r=K,maxZoom:s=W,zoomStep:u=Ze,enabled:c=true,containerRef:f,onZoomChange:h,enableKeyboardShortcuts:p=true,preventDefault:x=true}=n,[v,a]=useState(e),m=useRef(v);useEffect(()=>{m.current=v;},[v]);let d=useCallback(t=>{let b=N(_(t,r,s));b!==m.current&&(a(b),h?.(b));},[r,s,h]),y=useCallback(()=>{d(m.current+u);},[u,d]),S=useCallback(()=>{d(m.current-u);},[u,d]),C=useCallback(()=>{d(e);},[e,d]),o=useCallback(()=>{d(1);},[d]),i=useCallback((t,b)=>{if(b>0){let D=t/b;d(D);}},[d]),l=useCallback(t=>{if(!c||!(t.ctrlKey||t.metaKey))return;x&&t.preventDefault();let D=t.deltaY;D<0?d(m.current+u):D>0&&d(m.current-u);},[c,x,u,d]),R=useCallback(t=>{if(!(!c||!p||!(t.ctrlKey||t.metaKey))){if(t.key==="0"){t.preventDefault(),o();return}if(t.key==="+"||t.key==="="){t.preventDefault(),y();return}if(t.key==="-"){t.preventDefault(),S();return}}},[c,p,y,S,o]);return useEffect(()=>{if(!c)return;let t=f?.current;if(t)return t.addEventListener("wheel",l,{passive:false}),()=>{t.removeEventListener("wheel",l);}},[c,f,l]),useEffect(()=>{if(!(!c||!p))return document.addEventListener("keydown",R),()=>{document.removeEventListener("keydown",R);}},[c,p,R]),{zoom:v,setZoom:d,zoomIn:y,zoomOut:S,resetZoom:C,zoomTo100:o,zoomToFit:i,isMinZoom:v<=r,isMaxZoom:v>=s,zoomPercent:Math.round(v*100),handleWheel:l,handleKeyDown:R}}function we(){return [...g]}function Le(n){return Ae(n)}function ze(n){return Ue(n)}function ke(n){return Me(n)}function Fe(n){return `${Math.round(n*100)}%`}function Ie(n){let e=n.match(/(\d+(\.\d+)?)/);if(e){let r=parseFloat(e[1]);if(!isNaN(r))return r/100}return null}function Ke(n){return g.some(e=>Math.abs(e-n)<.01)}function We(n,e=K,r=W){return N(_(n,e,r))}export{g as ZOOM_PRESETS,We as clampZoom,Le as findNearestZoomPreset,Fe as formatZoom,pe as generateOverlayElements,ze as getNextZoomPreset,ke as getPreviousZoomPreset,we as getZoomPresets,Ke as isZoomPreset,Ie as parseZoom,Ee as useAutoSave,he as useClipboard,de as useSelectionHighlight,He as useWheelZoom};
1
+ export{j as HistoryManager,f as TABLE_DATA_ATTRIBUTES,c as extractTrackedChanges,h as useAutoHistory,i as useDocumentHistory,b as useDragAutoScroll,g as useHistory,e as useTableSelection,d as useTrackedChanges,a as useVisualLineNavigation}from'./chunk-WFGAQC2B.mjs';export{a as useAspectLockedSize}from'./chunk-GM2S2WMT.mjs';export{c as useFixedDropdown}from'./chunk-BABMU5KA.mjs';export{b as useFindReplace}from'./chunk-OHNO4NRQ.mjs';import'./chunk-ZFZJRL2R.mjs';import'./chunk-BMBP5UFA.mjs';import re,{useState,useRef,useCallback,useEffect,useMemo,useSyncExternalStore}from'react';import {DEFAULT_SELECTION_STYLE,hasActiveSelection,getSelectedText,isSelectionWithin,getMergedSelectionRects,areSelectionStylesInjected,injectSelectionStyles,copyRuns,parseClipboardHtml,runsToClipboardContent,handlePasteEvent}from'@eigenpal/docx-editor-core/utils';import {createSelectionFromDOM,AutoSaveManager}from'@eigenpal/docx-editor-core';export{createSelectionFromDOM,formatLastSaveTime,formatStorageSize,getAutoSaveStatusLabel,getAutoSaveStorageSize,getSelectionRuns,isAutoSaveSupported}from'@eigenpal/docx-editor-core';function de(n){let{containerRef:e,enabled:r=true,config:s=DEFAULT_SELECTION_STYLE,useOverlay:u=false,debounceMs:c=16,onSelectionChange:f}=n,[h,p]=useState(false),[x,v]=useState(""),[a,m]=useState([]),[d,y]=useState(false),S=useRef(null),C=useRef(0),o=useCallback(()=>{let t=e.current,b=hasActiveSelection(),D=getSelectedText(),A=t?isSelectionWithin(t):false;if(p(b),v(D),y(A),u&&A){let $=getMergedSelectionRects(t);m($);}else m([]);f&&f(b&&A,D);},[e,u,f]),i=useCallback(()=>{let t=performance.now();if(t-C.current<c){S.current!==null&&clearTimeout(S.current),S.current=window.setTimeout(()=>{C.current=performance.now(),o(),S.current=null;},c);return}C.current=t,o();},[c,o]),l=useCallback(()=>{o();},[o]),R=useCallback(t=>({position:"absolute",left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,backgroundColor:s.backgroundColor,borderRadius:s.borderRadius?`${s.borderRadius}px`:void 0,border:s.borderColor?`1px solid ${s.borderColor}`:void 0,zIndex:s.zIndex??0,opacity:s.opacity??1,mixBlendMode:s.mixBlendMode,pointerEvents:"none",userSelect:"none"}),[s]);return useEffect(()=>(r&&!areSelectionStylesInjected()&&injectSelectionStyles(s),()=>{}),[r,s]),useEffect(()=>{if(!r)return;let t=()=>{i();};return document.addEventListener("selectionchange",t),document.addEventListener("mouseup",t),o(),()=>{document.removeEventListener("selectionchange",t),document.removeEventListener("mouseup",t),S.current!==null&&clearTimeout(S.current);}},[r,i,o]),{hasSelection:h,selectedText:x,highlightRects:a,isSelectionInContainer:d,refresh:l,getOverlayStyle:R}}function pe(n,e=DEFAULT_SELECTION_STYLE){return n.map((r,s)=>re.createElement("div",{key:`selection-overlay-${s}`,style:{position:"absolute",left:`${r.left}px`,top:`${r.top}px`,width:`${r.width}px`,height:`${r.height}px`,backgroundColor:e.backgroundColor,borderRadius:e.borderRadius?`${e.borderRadius}px`:void 0,border:e.borderColor?`1px solid ${e.borderColor}`:void 0,zIndex:e.zIndex??0,opacity:e.opacity??1,mixBlendMode:e.mixBlendMode,pointerEvents:"none",userSelect:"none"}}))}function he(n={}){let{onCopy:e,onCut:r,onPaste:s,cleanWordFormatting:u=true,editable:c=true,onError:f,theme:h}=n,p=useRef(false),x=useRef(null),v=useCallback(async o=>{if(p.current)return false;p.current=true;try{let i=await copyRuns(o.runs,{onError:f,theme:h});return i&&e?.(o),i}finally{p.current=false;}},[e,f,h]),a=useCallback(async o=>{if(p.current||!c)return false;p.current=true;try{let i=await copyRuns(o.runs,{onError:f,theme:h});return i&&r?.(o),i}finally{p.current=false;}},[r,c,f,h]),m=useCallback(async(o=false)=>{if(p.current||!c)return null;p.current=true;try{if(navigator.clipboard&&navigator.clipboard.read){let i=await navigator.clipboard.read(),l="",R="";for(let b of i)b.types.includes("text/html")&&(l=await(await b.getType("text/html")).text()),b.types.includes("text/plain")&&(R=await(await b.getType("text/plain")).text());o&&(l="");let t=parseClipboardHtml(l,R,u);return x.current=t,s?.(t,o),t}return null}catch(i){return f?.(i),null}finally{p.current=false;}},[c,u,s,f]),d=useCallback(o=>{let i=createSelectionFromDOM();if(!i)return;o.preventDefault();let l=runsToClipboardContent(i.runs,true,h);o.clipboardData&&(o.clipboardData.setData("text/plain",l.plainText),o.clipboardData.setData("text/html",l.html),l.internal&&o.clipboardData.setData("application/x-docx-editor",l.internal)),e?.(i);},[e,h]),y=useCallback(o=>{if(!c)return;let i=createSelectionFromDOM();if(!i)return;o.preventDefault();let l=runsToClipboardContent(i.runs,true,h);o.clipboardData&&(o.clipboardData.setData("text/plain",l.plainText),o.clipboardData.setData("text/html",l.html),l.internal&&o.clipboardData.setData("application/x-docx-editor",l.internal)),r?.(i);},[c,r,h]),S=useCallback(o=>{if(!c)return;o.preventDefault();let i=handlePasteEvent(o,{cleanWordFormatting:u});if(i){x.current=i;let l=o.shiftKey??false;s?.(i,l);}},[c,u,s]),C=useCallback(o=>{},[]);return {copy:v,cut:a,paste:m,handleCopy:d,handleCut:y,handlePaste:S,handleKeyDown:C,isProcessing:p.current,lastPastedContent:x.current}}function Ee(n,e={}){let{storageKey:r,interval:s,enabled:u=true,maxAge:c,onSave:f,onError:h,onRecoveryAvailable:p,saveOnChange:x,debounceDelay:v}=e,a=useMemo(()=>new AutoSaveManager({storageKey:r,interval:s,maxAge:c,saveOnChange:x,debounceDelay:v,onSave:f,onError:h,onRecoveryAvailable:p}),[r]);useEffect(()=>{u?(a.enable(),a.startInterval()):a.disable();},[a,u]),useEffect(()=>{a.onDocumentChanged(n??null);},[a,n]),useEffect(()=>()=>{a.destroy();},[a]);let m=useSyncExternalStore(a.subscribe,a.getSnapshot),d=useCallback(()=>a.save(),[a]),y=useCallback(()=>a.clear(),[a]),S=useCallback(()=>a.getRecoveryData(),[a]),C=useCallback(()=>a.acceptRecovery(),[a]),o=useCallback(()=>a.dismissRecovery(),[a]),i=useCallback(()=>a.enable(),[a]),l=useCallback(()=>a.disable(),[a]);return {status:m.status,lastSaveTime:m.lastSaveTime,save:d,clearAutoSave:y,hasRecoveryData:m.hasRecoveryData,getRecoveryData:S,acceptRecovery:C,dismissRecovery:o,isEnabled:m.isEnabled,enable:i,disable:l}}var Pe=1,K=.25,W=4,Ze=.1,g=[.25,.5,.75,1,1.25,1.5,2,3,4];function _(n,e,r){return Math.max(e,Math.min(r,n))}function N(n){return Math.round(n*100)/100}function Ae(n){let e=g[0],r=Math.abs(n-e);for(let s of g){let u=Math.abs(n-s);u<r&&(r=u,e=s);}return e}function Ue(n){for(let e of g)if(e>n+.01)return e;return g[g.length-1]}function Me(n){for(let e=g.length-1;e>=0;e--)if(g[e]<n-.01)return g[e];return g[0]}function He(n={}){let{initialZoom:e=Pe,minZoom:r=K,maxZoom:s=W,zoomStep:u=Ze,enabled:c=true,containerRef:f,onZoomChange:h,enableKeyboardShortcuts:p=true,preventDefault:x=true}=n,[v,a]=useState(e),m=useRef(v);useEffect(()=>{m.current=v;},[v]);let d=useCallback(t=>{let b=N(_(t,r,s));b!==m.current&&(a(b),h?.(b));},[r,s,h]),y=useCallback(()=>{d(m.current+u);},[u,d]),S=useCallback(()=>{d(m.current-u);},[u,d]),C=useCallback(()=>{d(e);},[e,d]),o=useCallback(()=>{d(1);},[d]),i=useCallback((t,b)=>{if(b>0){let D=t/b;d(D);}},[d]),l=useCallback(t=>{if(!c||!(t.ctrlKey||t.metaKey))return;x&&t.preventDefault();let D=t.deltaY;D<0?d(m.current+u):D>0&&d(m.current-u);},[c,x,u,d]),R=useCallback(t=>{if(!(!c||!p||!(t.ctrlKey||t.metaKey))){if(t.key==="0"){t.preventDefault(),o();return}if(t.key==="+"||t.key==="="){t.preventDefault(),y();return}if(t.key==="-"){t.preventDefault(),S();return}}},[c,p,y,S,o]);return useEffect(()=>{if(!c)return;let t=f?.current;if(t)return t.addEventListener("wheel",l,{passive:false}),()=>{t.removeEventListener("wheel",l);}},[c,f,l]),useEffect(()=>{if(!(!c||!p))return document.addEventListener("keydown",R),()=>{document.removeEventListener("keydown",R);}},[c,p,R]),{zoom:v,setZoom:d,zoomIn:y,zoomOut:S,resetZoom:C,zoomTo100:o,zoomToFit:i,isMinZoom:v<=r,isMaxZoom:v>=s,zoomPercent:Math.round(v*100),handleWheel:l,handleKeyDown:R}}function we(){return [...g]}function Le(n){return Ae(n)}function ze(n){return Ue(n)}function ke(n){return Me(n)}function Fe(n){return `${Math.round(n*100)}%`}function Ie(n){let e=n.match(/(\d+(\.\d+)?)/);if(e){let r=parseFloat(e[1]);if(!isNaN(r))return r/100}return null}function Ke(n){return g.some(e=>Math.abs(e-n)<.01)}function We(n,e=K,r=W){return N(_(n,e,r))}export{g as ZOOM_PRESETS,We as clampZoom,Le as findNearestZoomPreset,Fe as formatZoom,pe as generateOverlayElements,ze as getNextZoomPreset,ke as getPreviousZoomPreset,we as getZoomPresets,Ke as isZoomPreset,Ie as parseZoom,Ee as useAutoSave,he as useClipboard,de as useSelectionHighlight,He as useWheelZoom};
package/dist/index.d.mts CHANGED
@@ -33,7 +33,6 @@ import { Layout } from '@eigenpal/docx-editor-core/layout-engine';
33
33
  import { RenderedDomContext } from '@eigenpal/docx-editor-core/plugin-api';
34
34
  import { EditorHandle } from '@eigenpal/docx-editor-core';
35
35
  export { CreateEmptyDocumentOptions, createDocumentWithText, createEmptyDocument } from '@eigenpal/docx-editor-core';
36
- import * as react_jsx_runtime from 'react/jsx-runtime';
37
36
 
38
37
  /**
39
38
  * Options for the agent panel mount on the right side of the editor.
@@ -108,6 +107,28 @@ interface PagedEditorRef {
108
107
  * No-op if the layout isn't ready yet or pageNumber is out of range.
109
108
  */
110
109
  scrollToPage(pageNumber: number): void;
110
+ /**
111
+ * Scroll to the comment identified by `commentId` and select its range so
112
+ * the selection overlay highlights it. Resolves the id → PM range via the
113
+ * live comment marks; returns `false` (not a throw, not a silent no-op)
114
+ * when the id no longer resolves so the caller can surface a "location no
115
+ * longer exists" affordance.
116
+ */
117
+ scrollToCommentId(commentId: number): boolean;
118
+ /**
119
+ * Scroll to the tracked change identified by `revisionId` and select its
120
+ * range so the selection overlay highlights it. Resolves the id → PM range
121
+ * via the live tracked-change marks; returns `false` when the id no longer
122
+ * resolves (the change was accepted/rejected/deleted).
123
+ */
124
+ scrollToChangeId(revisionId: number): boolean;
125
+ /**
126
+ * Select the PM position range `[from, to]` so the selection overlay
127
+ * highlights it, and scroll its start into view. No-op for a malformed
128
+ * range or a `from` past the document end; `to` is clamped to the document
129
+ * size (raw caller positions, so out-of-range must not throw).
130
+ */
131
+ highlightRange(from: number, to: number): void;
111
132
  /**
112
133
  * Look up the persistent hidden HF PM EditorView for a given HeaderFooter
113
134
  * instance. Returns null when none is mounted (no document, or `hf` is not
@@ -163,7 +184,9 @@ interface DocxEditorProps {
163
184
  externalContent?: boolean;
164
185
  /** Callback when editor view is ready (for PluginHost) */
165
186
  onEditorViewReady?: (view: prosemirror_view.EditorView) => void;
166
- /** Theme for styling */
187
+ /** Color theme mode for UI styling. `'system'` follows the OS preference. */
188
+ colorMode?: 'light' | 'dark' | 'system';
189
+ /** Document theme schema object */
167
190
  theme?: Theme | null;
168
191
  /** Whether to show toolbar (default: true) */
169
192
  showToolbar?: boolean;
@@ -230,6 +253,15 @@ interface DocxEditorProps {
230
253
  * ]}
231
254
  */
232
255
  fonts?: ReadonlyArray<FontDefinition>;
256
+ /**
257
+ * Text-watermark presets shown in the watermark dialog's preset dropdown.
258
+ * Omit to use the built-in MS Word phrases (`DEFAULT_WATERMARK_PRESETS`:
259
+ * CONFIDENTIAL, DRAFT, DO NOT COPY, SAMPLE, URGENT, ASAP). Pass an empty
260
+ * array to hide the preset dropdown and require custom text.
261
+ *
262
+ * @example watermarkPresets={['INTERNAL', 'PROPRIETARY', 'COPY']}
263
+ */
264
+ watermarkPresets?: readonly string[];
233
265
  /** Print options for print preview */
234
266
  printOptions?: PrintOptions;
235
267
  /**
@@ -360,6 +392,36 @@ interface DocxEditorRef {
360
392
  * @example ref.current?.scrollToPosition(42)
361
393
  */
362
394
  scrollToPosition: (pmPos: number) => void;
395
+ /**
396
+ * Scroll the paginated view to the comment with the given id and select its
397
+ * anchored range so the selection overlay highlights it. Resolves the id
398
+ * against the live comment marks at call time.
399
+ * @returns `false` when the id no longer resolves (the comment was deleted
400
+ * or its anchored text removed between render and click), so the caller
401
+ * can surface a "location no longer exists" affordance rather than
402
+ * silently no-op'ing.
403
+ * @example ref.current?.scrollToCommentId(3)
404
+ */
405
+ scrollToCommentId: (commentId: number) => boolean;
406
+ /**
407
+ * Scroll the paginated view to the tracked change with the given Word
408
+ * revision `w:id` and select its range so the selection overlay highlights
409
+ * it. Resolves the id against the live tracked-change marks at call time
410
+ * (matching coalesced revisions the way the changes sidebar does).
411
+ * @returns `false` when the id no longer resolves (the change was
412
+ * accepted, rejected, or deleted between render and click).
413
+ * @example ref.current?.scrollToChangeId(42)
414
+ */
415
+ scrollToChangeId: (revisionId: number) => boolean;
416
+ /**
417
+ * Select the ProseMirror position range `[from, to]` so the selection
418
+ * overlay highlights it, and scroll its start into view. The selection
419
+ * persists until it next changes (there is no auto-clearing flash). No-op
420
+ * for a malformed range or a `from` past the document end; `to` is clamped
421
+ * to the document size.
422
+ * @example ref.current?.highlightRange(10, 24)
423
+ */
424
+ highlightRange: (from: number, to: number) => void;
363
425
  /** Open print preview */
364
426
  openPrintPreview: () => void;
365
427
  /** Print the document directly */
@@ -438,6 +500,16 @@ interface DocxEditorRef {
438
500
  paraId: string;
439
501
  styleId: string;
440
502
  }) => boolean;
503
+ /**
504
+ * Insert a page or section break after the paragraph identified by `paraId`.
505
+ * `'page'` adds a page break; `'sectionNextPage'` / `'sectionContinuous'`
506
+ * start a new section on a new page / the same page. Direct edit, not a
507
+ * tracked change. Returns false if paraId is unknown.
508
+ */
509
+ insertBreak: (options: {
510
+ paraId: string;
511
+ type: 'page' | 'sectionNextPage' | 'sectionContinuous';
512
+ }) => boolean;
441
513
  /**
442
514
  * Read the contents of a single page. 1-indexed; returns null if the page
443
515
  * does not exist. Each paragraph is returned with its stable paraId so the
@@ -562,7 +634,7 @@ interface LocaleProviderProps {
562
634
  i18n?: Translations;
563
635
  children: ReactNode;
564
636
  }
565
- declare function LocaleProvider({ i18n, children }: LocaleProviderProps): react_jsx_runtime.JSX.Element;
637
+ declare function LocaleProvider({ i18n, children }: LocaleProviderProps): React.JSX.Element;
566
638
  declare function useTranslation(): {
567
639
  t: TFunction;
568
640
  };
package/dist/index.d.ts CHANGED
@@ -33,7 +33,6 @@ import { Layout } from '@eigenpal/docx-editor-core/layout-engine';
33
33
  import { RenderedDomContext } from '@eigenpal/docx-editor-core/plugin-api';
34
34
  import { EditorHandle } from '@eigenpal/docx-editor-core';
35
35
  export { CreateEmptyDocumentOptions, createDocumentWithText, createEmptyDocument } from '@eigenpal/docx-editor-core';
36
- import * as react_jsx_runtime from 'react/jsx-runtime';
37
36
 
38
37
  /**
39
38
  * Options for the agent panel mount on the right side of the editor.
@@ -108,6 +107,28 @@ interface PagedEditorRef {
108
107
  * No-op if the layout isn't ready yet or pageNumber is out of range.
109
108
  */
110
109
  scrollToPage(pageNumber: number): void;
110
+ /**
111
+ * Scroll to the comment identified by `commentId` and select its range so
112
+ * the selection overlay highlights it. Resolves the id → PM range via the
113
+ * live comment marks; returns `false` (not a throw, not a silent no-op)
114
+ * when the id no longer resolves so the caller can surface a "location no
115
+ * longer exists" affordance.
116
+ */
117
+ scrollToCommentId(commentId: number): boolean;
118
+ /**
119
+ * Scroll to the tracked change identified by `revisionId` and select its
120
+ * range so the selection overlay highlights it. Resolves the id → PM range
121
+ * via the live tracked-change marks; returns `false` when the id no longer
122
+ * resolves (the change was accepted/rejected/deleted).
123
+ */
124
+ scrollToChangeId(revisionId: number): boolean;
125
+ /**
126
+ * Select the PM position range `[from, to]` so the selection overlay
127
+ * highlights it, and scroll its start into view. No-op for a malformed
128
+ * range or a `from` past the document end; `to` is clamped to the document
129
+ * size (raw caller positions, so out-of-range must not throw).
130
+ */
131
+ highlightRange(from: number, to: number): void;
111
132
  /**
112
133
  * Look up the persistent hidden HF PM EditorView for a given HeaderFooter
113
134
  * instance. Returns null when none is mounted (no document, or `hf` is not
@@ -163,7 +184,9 @@ interface DocxEditorProps {
163
184
  externalContent?: boolean;
164
185
  /** Callback when editor view is ready (for PluginHost) */
165
186
  onEditorViewReady?: (view: prosemirror_view.EditorView) => void;
166
- /** Theme for styling */
187
+ /** Color theme mode for UI styling. `'system'` follows the OS preference. */
188
+ colorMode?: 'light' | 'dark' | 'system';
189
+ /** Document theme schema object */
167
190
  theme?: Theme | null;
168
191
  /** Whether to show toolbar (default: true) */
169
192
  showToolbar?: boolean;
@@ -230,6 +253,15 @@ interface DocxEditorProps {
230
253
  * ]}
231
254
  */
232
255
  fonts?: ReadonlyArray<FontDefinition>;
256
+ /**
257
+ * Text-watermark presets shown in the watermark dialog's preset dropdown.
258
+ * Omit to use the built-in MS Word phrases (`DEFAULT_WATERMARK_PRESETS`:
259
+ * CONFIDENTIAL, DRAFT, DO NOT COPY, SAMPLE, URGENT, ASAP). Pass an empty
260
+ * array to hide the preset dropdown and require custom text.
261
+ *
262
+ * @example watermarkPresets={['INTERNAL', 'PROPRIETARY', 'COPY']}
263
+ */
264
+ watermarkPresets?: readonly string[];
233
265
  /** Print options for print preview */
234
266
  printOptions?: PrintOptions;
235
267
  /**
@@ -360,6 +392,36 @@ interface DocxEditorRef {
360
392
  * @example ref.current?.scrollToPosition(42)
361
393
  */
362
394
  scrollToPosition: (pmPos: number) => void;
395
+ /**
396
+ * Scroll the paginated view to the comment with the given id and select its
397
+ * anchored range so the selection overlay highlights it. Resolves the id
398
+ * against the live comment marks at call time.
399
+ * @returns `false` when the id no longer resolves (the comment was deleted
400
+ * or its anchored text removed between render and click), so the caller
401
+ * can surface a "location no longer exists" affordance rather than
402
+ * silently no-op'ing.
403
+ * @example ref.current?.scrollToCommentId(3)
404
+ */
405
+ scrollToCommentId: (commentId: number) => boolean;
406
+ /**
407
+ * Scroll the paginated view to the tracked change with the given Word
408
+ * revision `w:id` and select its range so the selection overlay highlights
409
+ * it. Resolves the id against the live tracked-change marks at call time
410
+ * (matching coalesced revisions the way the changes sidebar does).
411
+ * @returns `false` when the id no longer resolves (the change was
412
+ * accepted, rejected, or deleted between render and click).
413
+ * @example ref.current?.scrollToChangeId(42)
414
+ */
415
+ scrollToChangeId: (revisionId: number) => boolean;
416
+ /**
417
+ * Select the ProseMirror position range `[from, to]` so the selection
418
+ * overlay highlights it, and scroll its start into view. The selection
419
+ * persists until it next changes (there is no auto-clearing flash). No-op
420
+ * for a malformed range or a `from` past the document end; `to` is clamped
421
+ * to the document size.
422
+ * @example ref.current?.highlightRange(10, 24)
423
+ */
424
+ highlightRange: (from: number, to: number) => void;
363
425
  /** Open print preview */
364
426
  openPrintPreview: () => void;
365
427
  /** Print the document directly */
@@ -438,6 +500,16 @@ interface DocxEditorRef {
438
500
  paraId: string;
439
501
  styleId: string;
440
502
  }) => boolean;
503
+ /**
504
+ * Insert a page or section break after the paragraph identified by `paraId`.
505
+ * `'page'` adds a page break; `'sectionNextPage'` / `'sectionContinuous'`
506
+ * start a new section on a new page / the same page. Direct edit, not a
507
+ * tracked change. Returns false if paraId is unknown.
508
+ */
509
+ insertBreak: (options: {
510
+ paraId: string;
511
+ type: 'page' | 'sectionNextPage' | 'sectionContinuous';
512
+ }) => boolean;
441
513
  /**
442
514
  * Read the contents of a single page. 1-indexed; returns null if the page
443
515
  * does not exist. Each paragraph is returned with its stable paraId so the
@@ -562,7 +634,7 @@ interface LocaleProviderProps {
562
634
  i18n?: Translations;
563
635
  children: ReactNode;
564
636
  }
565
- declare function LocaleProvider({ i18n, children }: LocaleProviderProps): react_jsx_runtime.JSX.Element;
637
+ declare function LocaleProvider({ i18n, children }: LocaleProviderProps): React.JSX.Element;
566
638
  declare function useTranslation(): {
567
639
  t: TFunction;
568
640
  };