@eigenpal/docx-editor-react 1.0.3 → 1.2.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/LICENSE CHANGED
@@ -55,7 +55,7 @@
55
55
  to the Licensor or its representatives, including but not limited to
56
56
  communication on electronic mailing lists, source code control systems,
57
57
  and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of tracking or improving the Work, but
58
+ Licensor for the purpose of discussing and improving the Work, but
59
59
  excluding communication that is conspicuously marked or otherwise
60
60
  designated in writing by the copyright owner as "Not a Contribution."
61
61
 
@@ -137,8 +137,8 @@
137
137
 
138
138
  6. Trademarks. This License does not grant permission to use the trade
139
139
  names, trademarks, service marks, or product names of the Licensor,
140
- except as required for describing the origin of the Work and
141
- reproducing the content of the NOTICE file.
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
142
 
143
143
  7. Disclaimer of Warranty. Unless required by applicable law or
144
144
  agreed to in writing, Licensor provides the Work (and each
@@ -162,7 +162,7 @@
162
162
  other commercial damages or losses), even if such Contributor
163
163
  has been advised of the possibility of such damages.
164
164
 
165
- 9. Accepting Warranty or Support. While redistributing
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
166
  the Work or Derivative Works thereof, You may choose to offer,
167
167
  and charge a fee for, acceptance of support, warranty, indemnity,
168
168
  or other liability obligations and/or rights consistent with this
@@ -171,7 +171,7 @@
171
171
  of any other Contributor, and only if You agree to indemnify,
172
172
  defend, and hold each Contributor harmless for any liability
173
173
  incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or support.
174
+ of your accepting any such warranty or additional liability.
175
175
 
176
176
  END OF TERMS AND CONDITIONS
177
177
 
@@ -181,13 +181,12 @@
181
181
  boilerplate notice, with the fields enclosed by brackets "[]"
182
182
  replaced with your own identifying information. (Don't include
183
183
  the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recognize that some
185
- additional formatting may help newer readers. Notice that the
186
- License also requires the Source form to retain the original
187
- copyright notice, and that the License also requires the License
188
- to be reproduced in any Derivative Works.
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
189
188
 
190
- Copyright 2024-2026 EigenPal
189
+ Copyright 2026 EigenPal Inc.
191
190
 
192
191
  Licensed under the Apache License, Version 2.0 (the "License");
193
192
  you may not use this file except in compliance with the License.
@@ -197,8 +196,6 @@
197
196
 
198
197
  Unless required by applicable law or agreed to in writing, software
199
198
  distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
201
- implied, including, without limitation, any warranties or conditions
202
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
203
- PARTICULAR PURPOSE. See the License for the specific language governing
204
- permissions and limitations under the License.
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1 +1 @@
1
- export{a as FindReplaceDialog,b as default}from'./chunk-AJ2BNSGR.mjs';import {a}from'./chunk-OHNO4NRQ.mjs';export{b as useFindReplace}from'./chunk-OHNO4NRQ.mjs';import'./chunk-ZFZJRL2R.mjs';import'./chunk-BMBP5UFA.mjs';var export_createDefaultFindOptions=a.createDefaultFindOptions;var export_createSearchPattern=a.createSearchPattern;var export_escapeRegexString=a.escapeRegexString;var export_findAllMatches=a.findAllMatches;var export_findInDocument=a.findInDocument;var export_findInParagraph=a.findInParagraph;var export_getDefaultHighlightOptions=a.getDefaultHighlightOptions;var export_getMatchCountText=a.getMatchCountText;var export_isEmptySearch=a.isEmptySearch;var export_replaceAllInContent=a.replaceAllInContent;var export_replaceFirstInContent=a.replaceFirstInContent;var export_scrollToMatch=a.scrollToMatch;export{export_createDefaultFindOptions as createDefaultFindOptions,export_createSearchPattern as createSearchPattern,export_escapeRegexString as escapeRegexString,export_findAllMatches as findAllMatches,export_findInDocument as findInDocument,export_findInParagraph as findInParagraph,export_getDefaultHighlightOptions as getDefaultHighlightOptions,export_getMatchCountText as getMatchCountText,export_isEmptySearch as isEmptySearch,export_replaceAllInContent as replaceAllInContent,export_replaceFirstInContent as replaceFirstInContent,export_scrollToMatch as scrollToMatch};
1
+ export{a as FindReplaceDialog,b as default}from'./chunk-AYHZMFCQ.mjs';import {a}from'./chunk-OHNO4NRQ.mjs';export{b as useFindReplace}from'./chunk-OHNO4NRQ.mjs';import'./chunk-ZFZJRL2R.mjs';import'./chunk-BMBP5UFA.mjs';var export_createDefaultFindOptions=a.createDefaultFindOptions;var export_createSearchPattern=a.createSearchPattern;var export_escapeRegexString=a.escapeRegexString;var export_findAllMatches=a.findAllMatches;var export_findInDocument=a.findInDocument;var export_findInParagraph=a.findInParagraph;var export_getDefaultHighlightOptions=a.getDefaultHighlightOptions;var export_getMatchCountText=a.getMatchCountText;var export_isEmptySearch=a.isEmptySearch;var export_replaceAllInContent=a.replaceAllInContent;var export_replaceFirstInContent=a.replaceFirstInContent;var export_scrollToMatch=a.scrollToMatch;export{export_createDefaultFindOptions as createDefaultFindOptions,export_createSearchPattern as createSearchPattern,export_escapeRegexString as escapeRegexString,export_findAllMatches as findAllMatches,export_findInDocument as findInDocument,export_findInParagraph as findInParagraph,export_getDefaultHighlightOptions as getDefaultHighlightOptions,export_getMatchCountText as getMatchCountText,export_isEmptySearch as isEmptySearch,export_replaceAllInContent as replaceAllInContent,export_replaceFirstInContent as replaceFirstInContent,export_scrollToMatch as scrollToMatch};
@@ -1 +1 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var chunkTKMHUFSP_js=require('./chunk-TKMHUFSP.js'),chunkL4MDZW2J_js=require('./chunk-L4MDZW2J.js');require('./chunk-GNIO6SOS.js'),require('./chunk-BJ5RZW6Y.js');var export_createDefaultFindOptions=chunkL4MDZW2J_js.a.createDefaultFindOptions;var export_createSearchPattern=chunkL4MDZW2J_js.a.createSearchPattern;var export_escapeRegexString=chunkL4MDZW2J_js.a.escapeRegexString;var export_findAllMatches=chunkL4MDZW2J_js.a.findAllMatches;var export_findInDocument=chunkL4MDZW2J_js.a.findInDocument;var export_findInParagraph=chunkL4MDZW2J_js.a.findInParagraph;var export_getDefaultHighlightOptions=chunkL4MDZW2J_js.a.getDefaultHighlightOptions;var export_getMatchCountText=chunkL4MDZW2J_js.a.getMatchCountText;var export_isEmptySearch=chunkL4MDZW2J_js.a.isEmptySearch;var export_replaceAllInContent=chunkL4MDZW2J_js.a.replaceAllInContent;var export_replaceFirstInContent=chunkL4MDZW2J_js.a.replaceFirstInContent;var export_scrollToMatch=chunkL4MDZW2J_js.a.scrollToMatch;Object.defineProperty(exports,"FindReplaceDialog",{enumerable:true,get:function(){return chunkTKMHUFSP_js.a}});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return chunkTKMHUFSP_js.b}});Object.defineProperty(exports,"useFindReplace",{enumerable:true,get:function(){return chunkL4MDZW2J_js.b}});exports.createDefaultFindOptions=export_createDefaultFindOptions;exports.createSearchPattern=export_createSearchPattern;exports.escapeRegexString=export_escapeRegexString;exports.findAllMatches=export_findAllMatches;exports.findInDocument=export_findInDocument;exports.findInParagraph=export_findInParagraph;exports.getDefaultHighlightOptions=export_getDefaultHighlightOptions;exports.getMatchCountText=export_getMatchCountText;exports.isEmptySearch=export_isEmptySearch;exports.replaceAllInContent=export_replaceAllInContent;exports.replaceFirstInContent=export_replaceFirstInContent;exports.scrollToMatch=export_scrollToMatch;
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var chunk4SYDL233_js=require('./chunk-4SYDL233.js'),chunkL4MDZW2J_js=require('./chunk-L4MDZW2J.js');require('./chunk-GNIO6SOS.js'),require('./chunk-BJ5RZW6Y.js');var export_createDefaultFindOptions=chunkL4MDZW2J_js.a.createDefaultFindOptions;var export_createSearchPattern=chunkL4MDZW2J_js.a.createSearchPattern;var export_escapeRegexString=chunkL4MDZW2J_js.a.escapeRegexString;var export_findAllMatches=chunkL4MDZW2J_js.a.findAllMatches;var export_findInDocument=chunkL4MDZW2J_js.a.findInDocument;var export_findInParagraph=chunkL4MDZW2J_js.a.findInParagraph;var export_getDefaultHighlightOptions=chunkL4MDZW2J_js.a.getDefaultHighlightOptions;var export_getMatchCountText=chunkL4MDZW2J_js.a.getMatchCountText;var export_isEmptySearch=chunkL4MDZW2J_js.a.isEmptySearch;var export_replaceAllInContent=chunkL4MDZW2J_js.a.replaceAllInContent;var export_replaceFirstInContent=chunkL4MDZW2J_js.a.replaceFirstInContent;var export_scrollToMatch=chunkL4MDZW2J_js.a.scrollToMatch;Object.defineProperty(exports,"FindReplaceDialog",{enumerable:true,get:function(){return chunk4SYDL233_js.a}});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return chunk4SYDL233_js.b}});Object.defineProperty(exports,"useFindReplace",{enumerable:true,get:function(){return chunkL4MDZW2J_js.b}});exports.createDefaultFindOptions=export_createDefaultFindOptions;exports.createSearchPattern=export_createSearchPattern;exports.escapeRegexString=export_escapeRegexString;exports.findAllMatches=export_findAllMatches;exports.findInDocument=export_findInDocument;exports.findInParagraph=export_findInParagraph;exports.getDefaultHighlightOptions=export_getDefaultHighlightOptions;exports.getMatchCountText=export_getMatchCountText;exports.isEmptySearch=export_isEmptySearch;exports.replaceAllInContent=export_replaceAllInContent;exports.replaceFirstInContent=export_replaceFirstInContent;exports.scrollToMatch=export_scrollToMatch;
@@ -0,0 +1 @@
1
+ 'use strict';var chunkYVYT3JWY_js=require('./chunk-YVYT3JWY.js'),chunkBJ5RZW6Y_js=require('./chunk-BJ5RZW6Y.js'),react=require('react'),prosemirrorState=require('prosemirror-state'),layoutBridge=require('@eigenpal/docx-editor-core/layout-bridge'),findVerticalScrollParent=require('@eigenpal/docx-editor-core/utils/findVerticalScrollParent'),extractTrackedChanges=require('@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges'),docxEditorCore=require('@eigenpal/docx-editor-core');var W=".layout-page-content .layout-line";function at(o){let a=findVerticalScrollParent.findVerticalScrollParent(o);if(!a)return;let u=o.getBoundingClientRect(),m=a.getBoundingClientRect(),t=40;u.bottom>m.bottom-t?a.scrollTop+=u.bottom-m.bottom+t:u.top<m.top+t&&(a.scrollTop-=m.top-u.top+t);}function xt({pagesContainerRef:o}){let a=react.useRef(null),u=react.useRef(-1),m=react.useCallback(b=>{if(!o.current)return null;let i=layoutBridge.findBodyPmSpans(o.current);for(let d of i){let l=Number(d.dataset.pmStart),r=Number(d.dataset.pmEnd);if(d.classList.contains("layout-run-tab")){if(b>=l&&b<r)return d.getBoundingClientRect().left;continue}if(b>=l&&b<=r&&d.firstChild?.nodeType===Node.TEXT_NODE){let n=d.firstChild,e=Math.min(b-l,n.length),s=d.ownerDocument;if(!s)continue;let c=s.createRange();return c.setStart(n,e),c.setEnd(n,e),c.getBoundingClientRect().left}}let f=o.current.querySelectorAll(".layout-empty-run");for(let d of Array.from(f)){let l=d.closest(".layout-paragraph");if(!l)continue;let r=Number(l.dataset.pmStart),n=Number(l.dataset.pmEnd);if(b>=r&&b<=n)return d.getBoundingClientRect().left}return null},[o]),t=react.useCallback(b=>{if(!o.current)return null;let i=o.current.querySelectorAll(W);for(let f of Array.from(i)){let d=f,l=d.querySelectorAll("span[data-pm-start][data-pm-end]");for(let r of Array.from(l)){let n=r,e=Number(n.dataset.pmStart),s=Number(n.dataset.pmEnd);if(b>=e&&b<=s)return d}}for(let f of Array.from(i)){let d=f,l=d.closest(".layout-paragraph");if(!l)continue;let r=Number(l.dataset.pmStart),n=Number(l.dataset.pmEnd);if(b>=r&&b<=n&&l.querySelector(".layout-line")===d)return d}return null},[o]),S=react.useCallback((b,i)=>{let f=b.querySelectorAll("span[data-pm-start][data-pm-end]");if(f.length===0){let n=b.closest(".layout-paragraph");return n?.dataset.pmStart?Number(n.dataset.pmStart)+1:null}for(let n of Array.from(f)){let e=n,s=e.getBoundingClientRect(),c=Number(e.dataset.pmStart),y=Number(e.dataset.pmEnd);if(e.classList.contains("layout-run-tab")){if(i>=s.left&&i<=s.right){let E=(s.left+s.right)/2;return i<E?c:y}continue}if(i>=s.left&&i<=s.right){let E=e.firstChild;if(!E||E.nodeType!==Node.TEXT_NODE)return c;let p=E,L=e.ownerDocument;if(!L)return c;let k=0,M=p.length;for(;k<M;){let w=Math.floor((k+M)/2),A=L.createRange();A.setStart(p,w),A.setEnd(p,w),i<A.getBoundingClientRect().left?M=w:k=w+1;}if(k>0&&k<=p.length){let w=L.createRange();w.setStart(p,k-1),w.setEnd(p,k-1);let A=w.getBoundingClientRect().left;w.setStart(p,Math.min(k,p.length)),w.setEnd(p,Math.min(k,p.length));let h=w.getBoundingClientRect().left;if(Math.abs(i-A)<Math.abs(i-h))return c+(k-1)}return c+Math.min(k,y-c)}}let d=null,l=1/0;for(let n of Array.from(f)){let e=n,s=e.getBoundingClientRect(),c=i<s.left?s.left-i:i-s.right;c<l&&(l=c,d=e);}if(!d)return null;let r=d.getBoundingClientRect();return i<r.left?Number(d.dataset.pmStart):Number(d.dataset.pmEnd)},[]),x=react.useCallback((b,i)=>{if(i.key!=="ArrowUp"&&i.key!=="ArrowDown")return (["ArrowLeft","ArrowRight","Home","End"].includes(i.key)||i.key.length===1&&!i.ctrlKey&&!i.metaKey)&&(a.current=null,u.current=-1),false;if(i.ctrlKey||i.metaKey)return a.current=null,u.current=-1,false;if(!o.current)return false;let f=Array.from(o.current.querySelectorAll(W));if(f.length===0)return false;let{from:d,anchor:l}=b.state.selection;if(a.current===null){let p=m(d);if(p===null)return false;a.current=p;}let r;if(u.current>=0&&u.current<f.length)r=u.current;else {let p=t(d);if(!p||(r=f.indexOf(p),r===-1))return false}let n=i.key==="ArrowUp"?r-1:r+1;if(n<0||n>=f.length)return u.current=-1,false;let e=f[n],s=S(e,a.current);if(s===null)return false;u.current=n;let{state:c,dispatch:y}=b,E=Math.max(0,Math.min(s,c.doc.content.size));try{let p=i.shiftKey?prosemirrorState.TextSelection.create(c.doc,l,E):prosemirrorState.TextSelection.create(c.doc,E);y(c.tr.setSelection(p));}catch{let p=c.doc.resolve(E),L=i.shiftKey?prosemirrorState.TextSelection.between(c.doc.resolve(l),p):prosemirrorState.TextSelection.near(p);y(c.tr.setSelection(L));}return at(e),true},[o,m,t,S]);return {stickyXRef:a,lastVisualLineIndexRef:u,getCaretClientX:m,findLineElementAtPosition:t,findPositionOnLineAtClientX:S,handlePMKeyDown:x}}var R=40,q=12;function wt({pagesContainerRef:o,onScrollExtendSelection:a}){let u=react.useRef(null),m=react.useRef({x:0,y:0}),t=react.useRef(false),S=react.useRef(null),x=react.useCallback(()=>{if(S.current)return S.current;let l=o.current;return l?(S.current=findVerticalScrollParent.findVerticalScrollParent(l),S.current):null},[o]),b=react.useCallback(()=>{t.current=false,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null);},[]),i=react.useCallback(()=>{if(!t.current)return;let l=x();if(!l)return;let r=l.getBoundingClientRect(),{x:n,y:e}=m.current,s=0;if(e<r.top+R){let c=Math.max(0,r.top+R-e);s=-Math.min(q,c/R*q);}else if(e>r.bottom-R){let c=Math.max(0,e-(r.bottom-R));s=Math.min(q,c/R*q);}s!==0&&(l.scrollTop+=s,a(n,e)),u.current=requestAnimationFrame(i);},[x,a]),f=react.useCallback(()=>{t.current||(t.current=true,u.current=requestAnimationFrame(i));},[i]);return {updateMousePosition:react.useCallback((l,r)=>{if(m.current={x:l,y:r},!t.current){let n=x();if(!n)return;let e=n.getBoundingClientRect();(r<e.top+R||r>e.bottom-R)&&f();}},[x,f]),stopAutoScroll:b}}function Lt(o){return react.useMemo(()=>extractTrackedChanges.extractTrackedChanges(o),[o])}function Nt({document:o,onChange:a,onSelectionChange:u}){let m=react.useMemo(()=>new docxEditorCore.TableSelectionManager,[]),[t,S]=react.useState({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),x=react.useCallback((r,n,e)=>{if(!o)return;let s=docxEditorCore.getTableFromDocument(o,r);if(!s){m.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null});return}m.selectCell({tableIndex:r,rowIndex:n,columnIndex:e});let y=chunkYVYT3JWY_js.d(s,{tableIndex:r,rowIndex:n,columnIndex:e});S({context:y,table:s,tableIndex:r,rowIndex:n,columnIndex:e}),u?.(y);},[o,m,u]),b=react.useCallback(()=>{m.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),u?.(null);},[m,u]),i=react.useCallback(()=>!t.table||t.rowIndex===null||t.columnIndex===null?null:chunkYVYT3JWY_js.g(t.table,t.rowIndex,t.columnIndex),[t.columnIndex,t.rowIndex,t.table]),f=react.useCallback((r,n)=>{if(!o||!t.table||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let e=chunkYVYT3JWY_js.h(t.table,t.rowIndex,t.columnIndex,r,n);if(e===t.table)return;let s=docxEditorCore.updateTableInDocument(o,t.tableIndex,e);a?.(s),s&&x(t.tableIndex,t.rowIndex,t.columnIndex);},[o,x,a,t.columnIndex,t.rowIndex,t.table,t.tableIndex]),d=react.useCallback(r=>{if(!o||!t.context||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let n=t.table;if(!n)return;let e=null,s=null,c=t.rowIndex,y=t.columnIndex;switch(r){case "addRowAbove":e=chunkYVYT3JWY_js.i(n,t.rowIndex,"before"),c=t.rowIndex+1;break;case "addRowBelow":e=chunkYVYT3JWY_js.i(n,t.rowIndex,"after");break;case "addColumnLeft":e=chunkYVYT3JWY_js.k(n,t.columnIndex,"before"),y=t.columnIndex+1;break;case "addColumnRight":e=chunkYVYT3JWY_js.k(n,t.columnIndex,"after");break;case "deleteRow":n.rows.length>1&&(e=chunkYVYT3JWY_js.j(n,t.rowIndex),c>=e.rows.length&&(c=e.rows.length-1));break;case "deleteColumn":{if(chunkYVYT3JWY_js.e(n)>1){e=chunkYVYT3JWY_js.l(n,t.columnIndex);let p=chunkYVYT3JWY_js.e(e);y>=p&&(y=p-1);}break}case "mergeCells":t.context.selection.selectedCells&&(e=chunkYVYT3JWY_js.m(n,t.context.selection));break;case "splitCell":break;case "deleteTable":s=docxEditorCore.deleteTableFromDocument(o,t.tableIndex),b(),a?.(s);return}e&&(s=docxEditorCore.updateTableInDocument(o,t.tableIndex,e),a?.(s),s&&x(t.tableIndex,c,y));},[o,t,a,b,x]),l=react.useCallback((r,n,e)=>m.isCellSelected(r,n,e),[m,t]);return {state:t,handleCellClick:x,handleAction:d,getSplitCellConfig:i,applySplitCell:f,clearSelection:b,isCellSelected:l,tableContext:t.context}}function nt(o,a){return JSON.stringify(o)===JSON.stringify(a)}function rt(o,a={}){let{maxEntries:u=100,groupingInterval:m=500,enableKeyboardShortcuts:t=true,isEqual:S=nt,onUndo:x,onRedo:b,containerRef:i}=a,[f,d]=react.useState(o),[l,r]=react.useState([]),[n,e]=react.useState([]),s=react.useRef(0),c=react.useRef(false),y=react.useCallback((h,g)=>{if(S(f,h))return;if(c.current){d(h);return}let T=Date.now();T-s.current<m&&l.length>0?r(B=>{let D=[...B];return D[D.length-1]={state:f,timestamp:T,description:g||D[D.length-1].description},D}):r(B=>{let D={state:f,timestamp:T,description:g},O=[...B,D];return O.length>u?O.slice(O.length-u):O}),e([]),d(h),s.current=T;},[f,S,m,u,l.length]),E=react.useCallback(()=>{if(l.length===0)return;c.current=true;let h=l[l.length-1];return r(g=>g.slice(0,-1)),e(g=>[...g,{state:f,timestamp:Date.now()}]),d(h.state),setTimeout(()=>{c.current=false;},0),x?.(h.state),h.state},[l,f,x]),p=react.useCallback(()=>{if(n.length===0)return;c.current=true;let h=n[n.length-1];return e(g=>g.slice(0,-1)),r(g=>[...g,{state:f,timestamp:Date.now()}]),d(h.state),setTimeout(()=>{c.current=false;},0),b?.(h.state),h.state},[n,f,b]),L=react.useCallback(()=>{r([]),e([]);},[]),k=react.useCallback(h=>{d(h??o),r([]),e([]),s.current=0;},[o]),M=react.useCallback(()=>[...l],[l]),w=react.useCallback(()=>[...n],[n]),A=react.useCallback(h=>{d(g=>h(g)),r(g=>g.map(T=>({...T,state:h(T.state)}))),e(g=>g.map(T=>({...T,state:h(T.state)})));},[]);return react.useEffect(()=>{if(!t)return;let h=T=>{if((T.ctrlKey||T.metaKey)&&T.key==="z"&&!T.shiftKey){T.preventDefault(),E();return}if((T.ctrlKey||T.metaKey)&&T.key==="y"||(T.ctrlKey||T.metaKey)&&T.key==="z"&&T.shiftKey){T.preventDefault(),p();return}},g=i?.current||document;return g.addEventListener("keydown",h),()=>{g.removeEventListener("keydown",h);}},[t,E,p,i]),{state:f,canUndo:l.length>0,canRedo:n.length>0,undoCount:l.length,redoCount:n.length,push:y,undo:E,redo:p,clear:L,reset:k,getUndoStack:M,getRedoStack:w,transformAll:A}}function Ft(o,a={}){let u=rt(o,a);return react.useEffect(()=>{u.push(o);},[o]),u}function _t(o,a={}){let u=react.useCallback((m,t)=>!(m?.package?.document!==t?.package?.document&&JSON.stringify(m?.package?.document)!==JSON.stringify(t?.package?.document)||m?.package?.headers!==t?.package?.headers||m?.package?.footers!==t?.package?.footers),[]);return rt(o,{...a,isEqual:u})}var tt=class{constructor(a,u={}){chunkBJ5RZW6Y_js.b(this,"undoStack",[]);chunkBJ5RZW6Y_js.b(this,"redoStack",[]);chunkBJ5RZW6Y_js.b(this,"currentState");chunkBJ5RZW6Y_js.b(this,"maxEntries");chunkBJ5RZW6Y_js.b(this,"groupingInterval");chunkBJ5RZW6Y_js.b(this,"lastPushTime",0);chunkBJ5RZW6Y_js.b(this,"isEqual");this.currentState=a,this.maxEntries=u.maxEntries??100,this.groupingInterval=u.groupingInterval??500,this.isEqual=u.isEqual??nt;}get state(){return this.currentState}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}push(a,u){if(this.isEqual(this.currentState,a))return;let m=Date.now();m-this.lastPushTime<this.groupingInterval&&this.undoStack.length>0?this.undoStack[this.undoStack.length-1].timestamp=m:(this.undoStack.push({state:this.currentState,timestamp:m,description:u}),this.undoStack.length>this.maxEntries&&(this.undoStack=this.undoStack.slice(-this.maxEntries))),this.redoStack=[],this.currentState=a,this.lastPushTime=m;}undo(){if(this.undoStack.length===0)return;let a=this.undoStack.pop();return this.redoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=a.state,a.state}redo(){if(this.redoStack.length===0)return;let a=this.redoStack.pop();return this.undoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=a.state,a.state}clear(){this.undoStack=[],this.redoStack=[];}reset(a){this.currentState=a??this.currentState,this.undoStack=[],this.redoStack=[],this.lastPushTime=0;}};Object.defineProperty(exports,"c",{enumerable:true,get:function(){return extractTrackedChanges.extractTrackedChanges}});Object.defineProperty(exports,"f",{enumerable:true,get:function(){return docxEditorCore.TABLE_DATA_ATTRIBUTES}});exports.a=xt;exports.b=wt;exports.d=Lt;exports.e=Nt;exports.g=rt;exports.h=Ft;exports.i=_t;exports.j=tt;
@@ -0,0 +1 @@
1
+ 'use strict';require('./chunk-L4MDZW2J.js');var chunkGNIO6SOS_js=require('./chunk-GNIO6SOS.js'),react=require('react'),jsxRuntime=require('react/jsx-runtime');var be={position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"transparent",display:"flex",alignItems:"flex-start",justifyContent:"flex-end",zIndex:1e4,pointerEvents:"none"},me={backgroundColor:"white",borderRadius:"4px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.2)",minWidth:"360px",maxWidth:"440px",width:"100%",margin:"60px 20px 20px 20px",pointerEvents:"auto"},Re={display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 16px",borderBottom:"1px solid var(--doc-border)",backgroundColor:"var(--doc-bg-subtle)",borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},ve={margin:0,fontSize:"14px",fontWeight:600,color:"var(--doc-text)"},ye={background:"none",border:"none",fontSize:"18px",cursor:"pointer",color:"var(--doc-text-muted)",padding:"2px 6px",lineHeight:1},Ce={padding:"16px"},J={display:"flex",alignItems:"center",gap:"8px",marginBottom:"12px"},Q={width:"60px",fontSize:"13px",color:"var(--doc-text)",flexShrink:0},O={flex:1,padding:"8px 10px",border:"1px solid var(--doc-border-input)",borderRadius:"3px",fontSize:"13px",boxSizing:"border-box",outline:"none"},Z={...O,borderColor:"var(--doc-link)",boxShadow:"0 0 0 2px rgba(5, 99, 193, 0.1)"},Te={display:"flex",flexDirection:"column",gap:"6px",marginLeft:"8px"},D={padding:"6px 12px",borderRadius:"3px",fontSize:"12px",fontWeight:500,cursor:"pointer",border:"1px solid var(--doc-border-input)",backgroundColor:"var(--doc-bg-input)",color:"var(--doc-text)",minWidth:"80px",textAlign:"center"},ee={...D,backgroundColor:"var(--doc-bg-hover)",color:"var(--doc-text-placeholder)",cursor:"not-allowed"},A={padding:"6px 10px",borderRadius:"3px",fontSize:"14px",cursor:"pointer",border:"1px solid var(--doc-border-input)",backgroundColor:"var(--doc-bg-input)",color:"var(--doc-text)"},te={...A,color:"var(--doc-border-input)",cursor:"not-allowed"},Ee={display:"flex",gap:"16px",marginTop:"4px",marginLeft:"68px"},w={display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",color:"var(--doc-text-muted)",cursor:"pointer"},oe={width:"14px",height:"14px",cursor:"pointer"},ne={marginLeft:"68px",fontSize:"12px",color:"var(--doc-text-muted)",marginBottom:"8px"},Le={...ne,color:"var(--doc-error)"},ke=220,Ie=({style:u})=>jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:u,children:jsxRuntime.jsx("polyline",{points:"18 15 12 9 6 15"})}),Ne=({style:u})=>jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:u,children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})});function _e({isOpen:u,onClose:S,onFind:b,onFindNext:B,onFindPrevious:Y,onReplace:M,onReplaceAll:U,onHighlightMatches:h,onClearHighlights:T,initialSearchText:K="",replaceMode:E=false,currentResult:L,className:le,style:re}){let{t:n}=chunkGNIO6SOS_js.b(),[l,W]=react.useState(""),[m,z]=react.useState(""),[k,H]=react.useState(E),[r,ae]=react.useState(false),[a,ie]=react.useState(false),[t,f]=react.useState(null),[ce,G]=react.useState(false),[se,V]=react.useState(false),I=react.useRef(null),j=react.useRef(null),X=react.useRef(b),$=react.useRef(h),R=react.useRef(T);react.useEffect(()=>{X.current=b,$.current=h,R.current=T;},[b,h,T]),react.useEffect(()=>{L!==void 0&&f(L);},[L]),react.useEffect(()=>{u?(W(K),z(""),H(E),f(null),setTimeout(()=>{I.current?.focus(),I.current?.select();},100)):R.current?.();},[u,K,E]);let y=react.useCallback(()=>{f(null),R.current?.();},[]),d=react.useCallback((e,c)=>{if(!e.trim()){y();return}let P=X.current(e,c);f(P),P?.matches?$.current?.(P.matches):R.current?.();},[y]);react.useEffect(()=>{if(!u)return;if(!l.trim()){y();return}let e=window.setTimeout(()=>{d(l,{matchCase:r,matchWholeWord:a});},ke);return ()=>window.clearTimeout(e)},[u,l,r,a,d,y]);let de=react.useCallback(e=>{W(e.target.value),f(null);},[]),N=react.useCallback(()=>{if(!l.trim()){d(l,{matchCase:r,matchWholeWord:a});return}if(!t){d(l,{matchCase:r,matchWholeWord:a});return}if(B()&&t){let c=(t.currentIndex+1)%t.totalCount;f({...t,currentIndex:c});}},[l,r,a,t,d,B]),_=react.useCallback(()=>{if(!l.trim()){d(l,{matchCase:r,matchWholeWord:a});return}if(!t){d(l,{matchCase:r,matchWholeWord:a});return}if(Y()&&t){let c=t.currentIndex===0?t.totalCount-1:t.currentIndex-1;f({...t,currentIndex:c});}},[l,r,a,t,d,Y]),pe=react.useCallback(e=>{e.key==="Enter"?(e.preventDefault(),e.shiftKey?_():t?N():d(l,{matchCase:r,matchWholeWord:a})):e.key==="Escape"&&S();},[t,l,r,a,d,N,_,S]),F=react.useCallback(()=>{if(!t||t.totalCount===0)return;if(M(m)){let c=b(l,{matchCase:r,matchWholeWord:a});f(c),c?.matches&&h&&h(c.matches);}},[t,m,l,r,a,M,b,h]),ue=react.useCallback(e=>{e.key==="Enter"?(e.preventDefault(),F()):e.key==="Escape"&&S();},[F,S]),fe=react.useCallback(()=>{if(!l.trim())return;U(l,m,{matchCase:r,matchWholeWord:a})>0&&(f(null),R.current?.());},[l,m,r,a,U]),xe=react.useCallback(()=>{H(e=>{let c=!e;return c&&setTimeout(()=>j.current?.focus(),100),c});},[]),ge=react.useCallback(e=>{e.target,e.currentTarget;},[]),Se=react.useCallback(e=>{e.key==="Escape"&&S();},[S]);if(!u)return null;let x=t&&t.totalCount>0,he=t&&t.totalCount===0&&l.trim();return jsxRuntime.jsx("div",{className:`docx-find-replace-dialog-overlay ${le||""}`,style:{...be,...re},onClick:ge,onKeyDown:Se,children:jsxRuntime.jsxs("div",{className:"docx-find-replace-dialog","data-testid":"find-replace-dialog",style:me,role:"dialog","aria-modal":"false","aria-labelledby":"find-replace-dialog-title",children:[jsxRuntime.jsxs("div",{className:"docx-find-replace-dialog-header",style:Re,children:[jsxRuntime.jsx("h2",{id:"find-replace-dialog-title",style:ve,children:n(k?"dialogs.findReplace.titleFindReplace":"dialogs.findReplace.titleFind")}),jsxRuntime.jsx("button",{type:"button",className:"docx-find-replace-dialog-close",style:ye,onClick:S,"aria-label":n("common.closeDialog"),children:"\xD7"})]}),jsxRuntime.jsxs("div",{className:"docx-find-replace-dialog-body",style:Ce,children:[jsxRuntime.jsxs("div",{className:"docx-find-replace-dialog-row",style:J,children:[jsxRuntime.jsx("label",{htmlFor:"find-text",style:Q,children:n("dialogs.findReplace.findLabel")}),jsxRuntime.jsx("input",{ref:I,id:"find-text",type:"text",className:"docx-find-replace-dialog-input",style:ce?Z:O,value:l,onChange:de,onKeyDown:pe,onFocus:()=>G(true),onBlur:()=>{G(false),l.trim()&&!t&&d(l,{matchCase:r,matchWholeWord:a});},placeholder:n("dialogs.findReplace.findPlaceholder"),"aria-label":n("dialogs.findReplace.findAriaLabel")}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px"},children:[jsxRuntime.jsx("button",{type:"button",className:"docx-find-replace-dialog-nav",style:x?A:te,onClick:_,disabled:!x,"aria-label":n("dialogs.findReplace.findPrevious"),title:n("dialogs.findReplace.findPreviousTitle"),children:jsxRuntime.jsx(Ie,{})}),jsxRuntime.jsx("button",{type:"button",className:"docx-find-replace-dialog-nav",style:x?A:te,onClick:N,disabled:!x,"aria-label":n("dialogs.findReplace.findNext"),title:n("dialogs.findReplace.findNextTitle"),children:jsxRuntime.jsx(Ne,{})})]})]}),x&&jsxRuntime.jsx("div",{className:"docx-find-replace-dialog-status",style:ne,children:n("dialogs.findReplace.matchCount",{current:t.currentIndex+1,total:t.totalCount})}),he&&jsxRuntime.jsx("div",{className:"docx-find-replace-dialog-status",style:Le,children:n("dialogs.findReplace.noResults")}),k&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"docx-find-replace-dialog-row",style:J,children:[jsxRuntime.jsx("label",{htmlFor:"replace-text",style:Q,children:n("dialogs.findReplace.replaceLabel")}),jsxRuntime.jsx("input",{ref:j,id:"replace-text",type:"text",className:"docx-find-replace-dialog-input",style:se?Z:O,value:m,onChange:e=>z(e.target.value),onKeyDown:ue,onFocus:()=>V(true),onBlur:()=>V(false),placeholder:n("dialogs.findReplace.replacePlaceholder"),"aria-label":n("dialogs.findReplace.replaceAriaLabel")}),jsxRuntime.jsxs("div",{style:Te,children:[jsxRuntime.jsx("button",{type:"button",className:"docx-find-replace-dialog-button",style:x?D:ee,onClick:F,disabled:!x,title:n("dialogs.findReplace.replaceCurrentTitle"),children:n("dialogs.findReplace.replaceButton")}),jsxRuntime.jsx("button",{type:"button",className:"docx-find-replace-dialog-button",style:x?D:ee,onClick:fe,disabled:!x,title:n("dialogs.findReplace.replaceAllTitle"),children:n("dialogs.findReplace.replaceAllButton")})]})]})}),jsxRuntime.jsxs("div",{className:"docx-find-replace-dialog-options",style:Ee,children:[jsxRuntime.jsxs("label",{className:"docx-find-replace-dialog-option",style:w,children:[jsxRuntime.jsx("input",{type:"checkbox",style:oe,checked:r,onChange:e=>ae(e.target.checked)}),n("dialogs.findReplace.matchCase")]}),jsxRuntime.jsxs("label",{className:"docx-find-replace-dialog-option",style:w,children:[jsxRuntime.jsx("input",{type:"checkbox",style:oe,checked:a,onChange:e=>ie(e.target.checked)}),n("dialogs.findReplace.wholeWords")]}),!k&&jsxRuntime.jsx("button",{type:"button",style:{...w,background:"none",border:"none",cursor:"pointer",color:"var(--doc-link)",padding:0},onClick:xe,children:n("dialogs.findReplace.toggleReplace")})]})]})]})})}var Ae=_e;exports.a=_e;exports.b=Ae;
@@ -0,0 +1 @@
1
+ import'./chunk-OHNO4NRQ.mjs';import {b}from'./chunk-ZFZJRL2R.mjs';import {useState,useRef,useEffect,useCallback}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var be={position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"transparent",display:"flex",alignItems:"flex-start",justifyContent:"flex-end",zIndex:1e4,pointerEvents:"none"},me={backgroundColor:"white",borderRadius:"4px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.2)",minWidth:"360px",maxWidth:"440px",width:"100%",margin:"60px 20px 20px 20px",pointerEvents:"auto"},Re={display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 16px",borderBottom:"1px solid var(--doc-border)",backgroundColor:"var(--doc-bg-subtle)",borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},ve={margin:0,fontSize:"14px",fontWeight:600,color:"var(--doc-text)"},ye={background:"none",border:"none",fontSize:"18px",cursor:"pointer",color:"var(--doc-text-muted)",padding:"2px 6px",lineHeight:1},Ce={padding:"16px"},J={display:"flex",alignItems:"center",gap:"8px",marginBottom:"12px"},Q={width:"60px",fontSize:"13px",color:"var(--doc-text)",flexShrink:0},O={flex:1,padding:"8px 10px",border:"1px solid var(--doc-border-input)",borderRadius:"3px",fontSize:"13px",boxSizing:"border-box",outline:"none"},Z={...O,borderColor:"var(--doc-link)",boxShadow:"0 0 0 2px rgba(5, 99, 193, 0.1)"},Te={display:"flex",flexDirection:"column",gap:"6px",marginLeft:"8px"},D={padding:"6px 12px",borderRadius:"3px",fontSize:"12px",fontWeight:500,cursor:"pointer",border:"1px solid var(--doc-border-input)",backgroundColor:"var(--doc-bg-input)",color:"var(--doc-text)",minWidth:"80px",textAlign:"center"},ee={...D,backgroundColor:"var(--doc-bg-hover)",color:"var(--doc-text-placeholder)",cursor:"not-allowed"},A={padding:"6px 10px",borderRadius:"3px",fontSize:"14px",cursor:"pointer",border:"1px solid var(--doc-border-input)",backgroundColor:"var(--doc-bg-input)",color:"var(--doc-text)"},te={...A,color:"var(--doc-border-input)",cursor:"not-allowed"},Ee={display:"flex",gap:"16px",marginTop:"4px",marginLeft:"68px"},w={display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",color:"var(--doc-text-muted)",cursor:"pointer"},oe={width:"14px",height:"14px",cursor:"pointer"},ne={marginLeft:"68px",fontSize:"12px",color:"var(--doc-text-muted)",marginBottom:"8px"},Le={...ne,color:"var(--doc-error)"},ke=220,Ie=({style:u})=>jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:u,children:jsx("polyline",{points:"18 15 12 9 6 15"})}),Ne=({style:u})=>jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:u,children:jsx("polyline",{points:"6 9 12 15 18 9"})});function _e({isOpen:u,onClose:S,onFind:b$1,onFindNext:B,onFindPrevious:Y,onReplace:M,onReplaceAll:U,onHighlightMatches:h,onClearHighlights:T,initialSearchText:K="",replaceMode:E=false,currentResult:L,className:le,style:re}){let{t:n}=b(),[l,W]=useState(""),[m,z]=useState(""),[k,H]=useState(E),[r,ae]=useState(false),[a,ie]=useState(false),[t,f]=useState(null),[ce,G]=useState(false),[se,V]=useState(false),I=useRef(null),j=useRef(null),X=useRef(b$1),$=useRef(h),R=useRef(T);useEffect(()=>{X.current=b$1,$.current=h,R.current=T;},[b$1,h,T]),useEffect(()=>{L!==void 0&&f(L);},[L]),useEffect(()=>{u?(W(K),z(""),H(E),f(null),setTimeout(()=>{I.current?.focus(),I.current?.select();},100)):R.current?.();},[u,K,E]);let y=useCallback(()=>{f(null),R.current?.();},[]),d=useCallback((e,c)=>{if(!e.trim()){y();return}let P=X.current(e,c);f(P),P?.matches?$.current?.(P.matches):R.current?.();},[y]);useEffect(()=>{if(!u)return;if(!l.trim()){y();return}let e=window.setTimeout(()=>{d(l,{matchCase:r,matchWholeWord:a});},ke);return ()=>window.clearTimeout(e)},[u,l,r,a,d,y]);let de=useCallback(e=>{W(e.target.value),f(null);},[]),N=useCallback(()=>{if(!l.trim()){d(l,{matchCase:r,matchWholeWord:a});return}if(!t){d(l,{matchCase:r,matchWholeWord:a});return}if(B()&&t){let c=(t.currentIndex+1)%t.totalCount;f({...t,currentIndex:c});}},[l,r,a,t,d,B]),_=useCallback(()=>{if(!l.trim()){d(l,{matchCase:r,matchWholeWord:a});return}if(!t){d(l,{matchCase:r,matchWholeWord:a});return}if(Y()&&t){let c=t.currentIndex===0?t.totalCount-1:t.currentIndex-1;f({...t,currentIndex:c});}},[l,r,a,t,d,Y]),pe=useCallback(e=>{e.key==="Enter"?(e.preventDefault(),e.shiftKey?_():t?N():d(l,{matchCase:r,matchWholeWord:a})):e.key==="Escape"&&S();},[t,l,r,a,d,N,_,S]),F=useCallback(()=>{if(!t||t.totalCount===0)return;if(M(m)){let c=b$1(l,{matchCase:r,matchWholeWord:a});f(c),c?.matches&&h&&h(c.matches);}},[t,m,l,r,a,M,b$1,h]),ue=useCallback(e=>{e.key==="Enter"?(e.preventDefault(),F()):e.key==="Escape"&&S();},[F,S]),fe=useCallback(()=>{if(!l.trim())return;U(l,m,{matchCase:r,matchWholeWord:a})>0&&(f(null),R.current?.());},[l,m,r,a,U]),xe=useCallback(()=>{H(e=>{let c=!e;return c&&setTimeout(()=>j.current?.focus(),100),c});},[]),ge=useCallback(e=>{e.target,e.currentTarget;},[]),Se=useCallback(e=>{e.key==="Escape"&&S();},[S]);if(!u)return null;let x=t&&t.totalCount>0,he=t&&t.totalCount===0&&l.trim();return jsx("div",{className:`docx-find-replace-dialog-overlay ${le||""}`,style:{...be,...re},onClick:ge,onKeyDown:Se,children:jsxs("div",{className:"docx-find-replace-dialog","data-testid":"find-replace-dialog",style:me,role:"dialog","aria-modal":"false","aria-labelledby":"find-replace-dialog-title",children:[jsxs("div",{className:"docx-find-replace-dialog-header",style:Re,children:[jsx("h2",{id:"find-replace-dialog-title",style:ve,children:n(k?"dialogs.findReplace.titleFindReplace":"dialogs.findReplace.titleFind")}),jsx("button",{type:"button",className:"docx-find-replace-dialog-close",style:ye,onClick:S,"aria-label":n("common.closeDialog"),children:"\xD7"})]}),jsxs("div",{className:"docx-find-replace-dialog-body",style:Ce,children:[jsxs("div",{className:"docx-find-replace-dialog-row",style:J,children:[jsx("label",{htmlFor:"find-text",style:Q,children:n("dialogs.findReplace.findLabel")}),jsx("input",{ref:I,id:"find-text",type:"text",className:"docx-find-replace-dialog-input",style:ce?Z:O,value:l,onChange:de,onKeyDown:pe,onFocus:()=>G(true),onBlur:()=>{G(false),l.trim()&&!t&&d(l,{matchCase:r,matchWholeWord:a});},placeholder:n("dialogs.findReplace.findPlaceholder"),"aria-label":n("dialogs.findReplace.findAriaLabel")}),jsxs("div",{style:{display:"flex",gap:"4px"},children:[jsx("button",{type:"button",className:"docx-find-replace-dialog-nav",style:x?A:te,onClick:_,disabled:!x,"aria-label":n("dialogs.findReplace.findPrevious"),title:n("dialogs.findReplace.findPreviousTitle"),children:jsx(Ie,{})}),jsx("button",{type:"button",className:"docx-find-replace-dialog-nav",style:x?A:te,onClick:N,disabled:!x,"aria-label":n("dialogs.findReplace.findNext"),title:n("dialogs.findReplace.findNextTitle"),children:jsx(Ne,{})})]})]}),x&&jsx("div",{className:"docx-find-replace-dialog-status",style:ne,children:n("dialogs.findReplace.matchCount",{current:t.currentIndex+1,total:t.totalCount})}),he&&jsx("div",{className:"docx-find-replace-dialog-status",style:Le,children:n("dialogs.findReplace.noResults")}),k&&jsx(Fragment,{children:jsxs("div",{className:"docx-find-replace-dialog-row",style:J,children:[jsx("label",{htmlFor:"replace-text",style:Q,children:n("dialogs.findReplace.replaceLabel")}),jsx("input",{ref:j,id:"replace-text",type:"text",className:"docx-find-replace-dialog-input",style:se?Z:O,value:m,onChange:e=>z(e.target.value),onKeyDown:ue,onFocus:()=>V(true),onBlur:()=>V(false),placeholder:n("dialogs.findReplace.replacePlaceholder"),"aria-label":n("dialogs.findReplace.replaceAriaLabel")}),jsxs("div",{style:Te,children:[jsx("button",{type:"button",className:"docx-find-replace-dialog-button",style:x?D:ee,onClick:F,disabled:!x,title:n("dialogs.findReplace.replaceCurrentTitle"),children:n("dialogs.findReplace.replaceButton")}),jsx("button",{type:"button",className:"docx-find-replace-dialog-button",style:x?D:ee,onClick:fe,disabled:!x,title:n("dialogs.findReplace.replaceAllTitle"),children:n("dialogs.findReplace.replaceAllButton")})]})]})}),jsxs("div",{className:"docx-find-replace-dialog-options",style:Ee,children:[jsxs("label",{className:"docx-find-replace-dialog-option",style:w,children:[jsx("input",{type:"checkbox",style:oe,checked:r,onChange:e=>ae(e.target.checked)}),n("dialogs.findReplace.matchCase")]}),jsxs("label",{className:"docx-find-replace-dialog-option",style:w,children:[jsx("input",{type:"checkbox",style:oe,checked:a,onChange:e=>ie(e.target.checked)}),n("dialogs.findReplace.wholeWords")]}),!k&&jsx("button",{type:"button",style:{...w,background:"none",border:"none",cursor:"pointer",color:"var(--doc-link)",padding:0},onClick:xe,children:n("dialogs.findReplace.toggleReplace")})]})]})]})})}var Ae=_e;export{_e as a,Ae as b};
@@ -0,0 +1 @@
1
+ import {d,g,h,m,e,l,j,k,i}from'./chunk-TN5C2ZYV.mjs';import {b}from'./chunk-BMBP5UFA.mjs';import {useRef,useCallback,useMemo,useState,useEffect}from'react';import {TextSelection}from'prosemirror-state';import {findBodyPmSpans}from'@eigenpal/docx-editor-core/layout-bridge';import {findVerticalScrollParent}from'@eigenpal/docx-editor-core/utils/findVerticalScrollParent';import {extractTrackedChanges}from'@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges';export{extractTrackedChanges as c}from'@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges';import {TableSelectionManager,getTableFromDocument,updateTableInDocument,deleteTableFromDocument}from'@eigenpal/docx-editor-core';export{TABLE_DATA_ATTRIBUTES as f}from'@eigenpal/docx-editor-core';var W=".layout-page-content .layout-line";function at(o){let a=findVerticalScrollParent(o);if(!a)return;let u=o.getBoundingClientRect(),m=a.getBoundingClientRect(),t=40;u.bottom>m.bottom-t?a.scrollTop+=u.bottom-m.bottom+t:u.top<m.top+t&&(a.scrollTop-=m.top-u.top+t);}function xt({pagesContainerRef:o}){let a=useRef(null),u=useRef(-1),m=useCallback(b=>{if(!o.current)return null;let i=findBodyPmSpans(o.current);for(let d of i){let l=Number(d.dataset.pmStart),r=Number(d.dataset.pmEnd);if(d.classList.contains("layout-run-tab")){if(b>=l&&b<r)return d.getBoundingClientRect().left;continue}if(b>=l&&b<=r&&d.firstChild?.nodeType===Node.TEXT_NODE){let n=d.firstChild,e=Math.min(b-l,n.length),s=d.ownerDocument;if(!s)continue;let c=s.createRange();return c.setStart(n,e),c.setEnd(n,e),c.getBoundingClientRect().left}}let f=o.current.querySelectorAll(".layout-empty-run");for(let d of Array.from(f)){let l=d.closest(".layout-paragraph");if(!l)continue;let r=Number(l.dataset.pmStart),n=Number(l.dataset.pmEnd);if(b>=r&&b<=n)return d.getBoundingClientRect().left}return null},[o]),t=useCallback(b=>{if(!o.current)return null;let i=o.current.querySelectorAll(W);for(let f of Array.from(i)){let d=f,l=d.querySelectorAll("span[data-pm-start][data-pm-end]");for(let r of Array.from(l)){let n=r,e=Number(n.dataset.pmStart),s=Number(n.dataset.pmEnd);if(b>=e&&b<=s)return d}}for(let f of Array.from(i)){let d=f,l=d.closest(".layout-paragraph");if(!l)continue;let r=Number(l.dataset.pmStart),n=Number(l.dataset.pmEnd);if(b>=r&&b<=n&&l.querySelector(".layout-line")===d)return d}return null},[o]),S=useCallback((b,i)=>{let f=b.querySelectorAll("span[data-pm-start][data-pm-end]");if(f.length===0){let n=b.closest(".layout-paragraph");return n?.dataset.pmStart?Number(n.dataset.pmStart)+1:null}for(let n of Array.from(f)){let e=n,s=e.getBoundingClientRect(),c=Number(e.dataset.pmStart),y=Number(e.dataset.pmEnd);if(e.classList.contains("layout-run-tab")){if(i>=s.left&&i<=s.right){let E=(s.left+s.right)/2;return i<E?c:y}continue}if(i>=s.left&&i<=s.right){let E=e.firstChild;if(!E||E.nodeType!==Node.TEXT_NODE)return c;let p=E,L=e.ownerDocument;if(!L)return c;let k=0,M=p.length;for(;k<M;){let w=Math.floor((k+M)/2),A=L.createRange();A.setStart(p,w),A.setEnd(p,w),i<A.getBoundingClientRect().left?M=w:k=w+1;}if(k>0&&k<=p.length){let w=L.createRange();w.setStart(p,k-1),w.setEnd(p,k-1);let A=w.getBoundingClientRect().left;w.setStart(p,Math.min(k,p.length)),w.setEnd(p,Math.min(k,p.length));let h=w.getBoundingClientRect().left;if(Math.abs(i-A)<Math.abs(i-h))return c+(k-1)}return c+Math.min(k,y-c)}}let d=null,l=1/0;for(let n of Array.from(f)){let e=n,s=e.getBoundingClientRect(),c=i<s.left?s.left-i:i-s.right;c<l&&(l=c,d=e);}if(!d)return null;let r=d.getBoundingClientRect();return i<r.left?Number(d.dataset.pmStart):Number(d.dataset.pmEnd)},[]),x=useCallback((b,i)=>{if(i.key!=="ArrowUp"&&i.key!=="ArrowDown")return (["ArrowLeft","ArrowRight","Home","End"].includes(i.key)||i.key.length===1&&!i.ctrlKey&&!i.metaKey)&&(a.current=null,u.current=-1),false;if(i.ctrlKey||i.metaKey)return a.current=null,u.current=-1,false;if(!o.current)return false;let f=Array.from(o.current.querySelectorAll(W));if(f.length===0)return false;let{from:d,anchor:l}=b.state.selection;if(a.current===null){let p=m(d);if(p===null)return false;a.current=p;}let r;if(u.current>=0&&u.current<f.length)r=u.current;else {let p=t(d);if(!p||(r=f.indexOf(p),r===-1))return false}let n=i.key==="ArrowUp"?r-1:r+1;if(n<0||n>=f.length)return u.current=-1,false;let e=f[n],s=S(e,a.current);if(s===null)return false;u.current=n;let{state:c,dispatch:y}=b,E=Math.max(0,Math.min(s,c.doc.content.size));try{let p=i.shiftKey?TextSelection.create(c.doc,l,E):TextSelection.create(c.doc,E);y(c.tr.setSelection(p));}catch{let p=c.doc.resolve(E),L=i.shiftKey?TextSelection.between(c.doc.resolve(l),p):TextSelection.near(p);y(c.tr.setSelection(L));}return at(e),true},[o,m,t,S]);return {stickyXRef:a,lastVisualLineIndexRef:u,getCaretClientX:m,findLineElementAtPosition:t,findPositionOnLineAtClientX:S,handlePMKeyDown:x}}var R=40,q=12;function wt({pagesContainerRef:o,onScrollExtendSelection:a}){let u=useRef(null),m=useRef({x:0,y:0}),t=useRef(false),S=useRef(null),x=useCallback(()=>{if(S.current)return S.current;let l=o.current;return l?(S.current=findVerticalScrollParent(l),S.current):null},[o]),b=useCallback(()=>{t.current=false,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null);},[]),i=useCallback(()=>{if(!t.current)return;let l=x();if(!l)return;let r=l.getBoundingClientRect(),{x:n,y:e}=m.current,s=0;if(e<r.top+R){let c=Math.max(0,r.top+R-e);s=-Math.min(q,c/R*q);}else if(e>r.bottom-R){let c=Math.max(0,e-(r.bottom-R));s=Math.min(q,c/R*q);}s!==0&&(l.scrollTop+=s,a(n,e)),u.current=requestAnimationFrame(i);},[x,a]),f=useCallback(()=>{t.current||(t.current=true,u.current=requestAnimationFrame(i));},[i]);return {updateMousePosition:useCallback((l,r)=>{if(m.current={x:l,y:r},!t.current){let n=x();if(!n)return;let e=n.getBoundingClientRect();(r<e.top+R||r>e.bottom-R)&&f();}},[x,f]),stopAutoScroll:b}}function Lt(o){return useMemo(()=>extractTrackedChanges(o),[o])}function Nt({document:o,onChange:a,onSelectionChange:u}){let m$1=useMemo(()=>new TableSelectionManager,[]),[t,S]=useState({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),x=useCallback((r,n,e)=>{if(!o)return;let s=getTableFromDocument(o,r);if(!s){m$1.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null});return}m$1.selectCell({tableIndex:r,rowIndex:n,columnIndex:e});let y=d(s,{tableIndex:r,rowIndex:n,columnIndex:e});S({context:y,table:s,tableIndex:r,rowIndex:n,columnIndex:e}),u?.(y);},[o,m$1,u]),b=useCallback(()=>{m$1.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),u?.(null);},[m$1,u]),i$1=useCallback(()=>!t.table||t.rowIndex===null||t.columnIndex===null?null:g(t.table,t.rowIndex,t.columnIndex),[t.columnIndex,t.rowIndex,t.table]),f=useCallback((r,n)=>{if(!o||!t.table||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let e=h(t.table,t.rowIndex,t.columnIndex,r,n);if(e===t.table)return;let s=updateTableInDocument(o,t.tableIndex,e);a?.(s),s&&x(t.tableIndex,t.rowIndex,t.columnIndex);},[o,x,a,t.columnIndex,t.rowIndex,t.table,t.tableIndex]),d$1=useCallback(r=>{if(!o||!t.context||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let n=t.table;if(!n)return;let e$1=null,s=null,c=t.rowIndex,y=t.columnIndex;switch(r){case "addRowAbove":e$1=i(n,t.rowIndex,"before"),c=t.rowIndex+1;break;case "addRowBelow":e$1=i(n,t.rowIndex,"after");break;case "addColumnLeft":e$1=k(n,t.columnIndex,"before"),y=t.columnIndex+1;break;case "addColumnRight":e$1=k(n,t.columnIndex,"after");break;case "deleteRow":n.rows.length>1&&(e$1=j(n,t.rowIndex),c>=e$1.rows.length&&(c=e$1.rows.length-1));break;case "deleteColumn":{if(e(n)>1){e$1=l(n,t.columnIndex);let p=e(e$1);y>=p&&(y=p-1);}break}case "mergeCells":t.context.selection.selectedCells&&(e$1=m(n,t.context.selection));break;case "splitCell":break;case "deleteTable":s=deleteTableFromDocument(o,t.tableIndex),b(),a?.(s);return}e$1&&(s=updateTableInDocument(o,t.tableIndex,e$1),a?.(s),s&&x(t.tableIndex,c,y));},[o,t,a,b,x]),l$1=useCallback((r,n,e)=>m$1.isCellSelected(r,n,e),[m$1,t]);return {state:t,handleCellClick:x,handleAction:d$1,getSplitCellConfig:i$1,applySplitCell:f,clearSelection:b,isCellSelected:l$1,tableContext:t.context}}function nt(o,a){return JSON.stringify(o)===JSON.stringify(a)}function rt(o,a={}){let{maxEntries:u=100,groupingInterval:m=500,enableKeyboardShortcuts:t=true,isEqual:S=nt,onUndo:x,onRedo:b,containerRef:i}=a,[f,d]=useState(o),[l,r]=useState([]),[n,e]=useState([]),s=useRef(0),c=useRef(false),y=useCallback((h,g)=>{if(S(f,h))return;if(c.current){d(h);return}let T=Date.now();T-s.current<m&&l.length>0?r(B=>{let D=[...B];return D[D.length-1]={state:f,timestamp:T,description:g||D[D.length-1].description},D}):r(B=>{let D={state:f,timestamp:T,description:g},O=[...B,D];return O.length>u?O.slice(O.length-u):O}),e([]),d(h),s.current=T;},[f,S,m,u,l.length]),E=useCallback(()=>{if(l.length===0)return;c.current=true;let h=l[l.length-1];return r(g=>g.slice(0,-1)),e(g=>[...g,{state:f,timestamp:Date.now()}]),d(h.state),setTimeout(()=>{c.current=false;},0),x?.(h.state),h.state},[l,f,x]),p=useCallback(()=>{if(n.length===0)return;c.current=true;let h=n[n.length-1];return e(g=>g.slice(0,-1)),r(g=>[...g,{state:f,timestamp:Date.now()}]),d(h.state),setTimeout(()=>{c.current=false;},0),b?.(h.state),h.state},[n,f,b]),L=useCallback(()=>{r([]),e([]);},[]),k=useCallback(h=>{d(h??o),r([]),e([]),s.current=0;},[o]),M=useCallback(()=>[...l],[l]),w=useCallback(()=>[...n],[n]),A=useCallback(h=>{d(g=>h(g)),r(g=>g.map(T=>({...T,state:h(T.state)}))),e(g=>g.map(T=>({...T,state:h(T.state)})));},[]);return useEffect(()=>{if(!t)return;let h=T=>{if((T.ctrlKey||T.metaKey)&&T.key==="z"&&!T.shiftKey){T.preventDefault(),E();return}if((T.ctrlKey||T.metaKey)&&T.key==="y"||(T.ctrlKey||T.metaKey)&&T.key==="z"&&T.shiftKey){T.preventDefault(),p();return}},g=i?.current||document;return g.addEventListener("keydown",h),()=>{g.removeEventListener("keydown",h);}},[t,E,p,i]),{state:f,canUndo:l.length>0,canRedo:n.length>0,undoCount:l.length,redoCount:n.length,push:y,undo:E,redo:p,clear:L,reset:k,getUndoStack:M,getRedoStack:w,transformAll:A}}function Ft(o,a={}){let u=rt(o,a);return useEffect(()=>{u.push(o);},[o]),u}function _t(o,a={}){let u=useCallback((m,t)=>!(m?.package?.document!==t?.package?.document&&JSON.stringify(m?.package?.document)!==JSON.stringify(t?.package?.document)||m?.package?.headers!==t?.package?.headers||m?.package?.footers!==t?.package?.footers),[]);return rt(o,{...a,isEqual:u})}var tt=class{constructor(a,u={}){b(this,"undoStack",[]);b(this,"redoStack",[]);b(this,"currentState");b(this,"maxEntries");b(this,"groupingInterval");b(this,"lastPushTime",0);b(this,"isEqual");this.currentState=a,this.maxEntries=u.maxEntries??100,this.groupingInterval=u.groupingInterval??500,this.isEqual=u.isEqual??nt;}get state(){return this.currentState}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}push(a,u){if(this.isEqual(this.currentState,a))return;let m=Date.now();m-this.lastPushTime<this.groupingInterval&&this.undoStack.length>0?this.undoStack[this.undoStack.length-1].timestamp=m:(this.undoStack.push({state:this.currentState,timestamp:m,description:u}),this.undoStack.length>this.maxEntries&&(this.undoStack=this.undoStack.slice(-this.maxEntries))),this.redoStack=[],this.currentState=a,this.lastPushTime=m;}undo(){if(this.undoStack.length===0)return;let a=this.undoStack.pop();return this.redoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=a.state,a.state}redo(){if(this.redoStack.length===0)return;let a=this.redoStack.pop();return this.undoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=a.state,a.state}clear(){this.undoStack=[],this.redoStack=[];}reset(a){this.currentState=a??this.currentState,this.undoStack=[],this.redoStack=[],this.lastPushTime=0;}};export{xt as a,wt as b,Lt as d,Nt as e,rt as g,Ft as h,_t as i,tt as j};
package/dist/dialogs.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunk5BSDRI3Z_js=require('./chunk-5BSDRI3Z.js'),chunkPGHNUFNT_js=require('./chunk-PGHNUFNT.js'),chunkJGPOALUP_js=require('./chunk-JGPOALUP.js'),chunkTKMHUFSP_js=require('./chunk-TKMHUFSP.js'),chunkL4MDZW2J_js=require('./chunk-L4MDZW2J.js'),chunkUT6DJWGC_js=require('./chunk-UT6DJWGC.js');require('./chunk-GNIO6SOS.js'),require('./chunk-BJ5RZW6Y.js');var export_createDefaultFindOptions=chunkL4MDZW2J_js.a.createDefaultFindOptions;var export_createSearchPattern=chunkL4MDZW2J_js.a.createSearchPattern;var export_escapeRegexString=chunkL4MDZW2J_js.a.escapeRegexString;var export_findAllMatches=chunkL4MDZW2J_js.a.findAllMatches;var export_getDefaultHighlightOptions=chunkL4MDZW2J_js.a.getDefaultHighlightOptions;var export_getMatchCountText=chunkL4MDZW2J_js.a.getMatchCountText;var export_isEmptySearch=chunkL4MDZW2J_js.a.isEmptySearch;var export_replaceAllInContent=chunkL4MDZW2J_js.a.replaceAllInContent;var export_replaceFirstInContent=chunkL4MDZW2J_js.a.replaceFirstInContent;Object.defineProperty(exports,"PageSetupDialog",{enumerable:true,get:function(){return chunk5BSDRI3Z_js.a}});Object.defineProperty(exports,"KeyboardShortcutsDialog",{enumerable:true,get:function(){return chunkPGHNUFNT_js.l}});Object.defineProperty(exports,"PasteSpecialDialog",{enumerable:true,get:function(){return chunkPGHNUFNT_js.a}});Object.defineProperty(exports,"getAllCategories",{enumerable:true,get:function(){return chunkPGHNUFNT_js.k}});Object.defineProperty(exports,"getAllPasteOptions",{enumerable:true,get:function(){return chunkPGHNUFNT_js.d}});Object.defineProperty(exports,"getCategoryLabel",{enumerable:true,get:function(){return chunkPGHNUFNT_js.j}});Object.defineProperty(exports,"getCommonShortcuts",{enumerable:true,get:function(){return chunkPGHNUFNT_js.i}});Object.defineProperty(exports,"getDefaultPasteOption",{enumerable:true,get:function(){return chunkPGHNUFNT_js.e}});Object.defineProperty(exports,"getDefaultShortcuts",{enumerable:true,get:function(){return chunkPGHNUFNT_js.g}});Object.defineProperty(exports,"getPasteOption",{enumerable:true,get:function(){return chunkPGHNUFNT_js.c}});Object.defineProperty(exports,"getShortcutsByCategory",{enumerable:true,get:function(){return chunkPGHNUFNT_js.h}});Object.defineProperty(exports,"isPasteSpecialShortcut",{enumerable:true,get:function(){return chunkPGHNUFNT_js.f}});Object.defineProperty(exports,"useKeyboardShortcutsDialog",{enumerable:true,get:function(){return chunkPGHNUFNT_js.m}});Object.defineProperty(exports,"usePasteSpecial",{enumerable:true,get:function(){return chunkPGHNUFNT_js.b}});Object.defineProperty(exports,"formatShortcutKeys",{enumerable:true,get:function(){return chunkJGPOALUP_js.a}});Object.defineProperty(exports,"FindReplaceDialog",{enumerable:true,get:function(){return chunkTKMHUFSP_js.a}});Object.defineProperty(exports,"HyperlinkDialog",{enumerable:true,get:function(){return chunkUT6DJWGC_js.d}});Object.defineProperty(exports,"createBookmarkLinkData",{enumerable:true,get:function(){return chunkUT6DJWGC_js.f}});Object.defineProperty(exports,"createHyperlinkData",{enumerable:true,get:function(){return chunkUT6DJWGC_js.e}});Object.defineProperty(exports,"emailToMailto",{enumerable:true,get:function(){return chunkUT6DJWGC_js.j}});Object.defineProperty(exports,"extractBookmarksForDialog",{enumerable:true,get:function(){return chunkUT6DJWGC_js.l}});Object.defineProperty(exports,"getDisplayText",{enumerable:true,get:function(){return chunkUT6DJWGC_js.i}});Object.defineProperty(exports,"getUrlType",{enumerable:true,get:function(){return chunkUT6DJWGC_js.c}});Object.defineProperty(exports,"isBookmarkHyperlinkData",{enumerable:true,get:function(){return chunkUT6DJWGC_js.h}});Object.defineProperty(exports,"isExternalHyperlinkData",{enumerable:true,get:function(){return chunkUT6DJWGC_js.g}});Object.defineProperty(exports,"isValidUrl",{enumerable:true,get:function(){return chunkUT6DJWGC_js.a}});Object.defineProperty(exports,"normalizeUrl",{enumerable:true,get:function(){return chunkUT6DJWGC_js.b}});Object.defineProperty(exports,"phoneToTel",{enumerable:true,get:function(){return chunkUT6DJWGC_js.k}});exports.createDefaultFindOptions=export_createDefaultFindOptions;exports.createSearchPattern=export_createSearchPattern;exports.escapeRegexString=export_escapeRegexString;exports.findAllMatches=export_findAllMatches;exports.getDefaultHighlightOptions=export_getDefaultHighlightOptions;exports.getMatchCountText=export_getMatchCountText;exports.isEmptySearch=export_isEmptySearch;exports.replaceAllInContent=export_replaceAllInContent;exports.replaceFirstInContent=export_replaceFirstInContent;
1
+ 'use strict';var chunk5BSDRI3Z_js=require('./chunk-5BSDRI3Z.js'),chunkPGHNUFNT_js=require('./chunk-PGHNUFNT.js'),chunkJGPOALUP_js=require('./chunk-JGPOALUP.js'),chunk4SYDL233_js=require('./chunk-4SYDL233.js'),chunkL4MDZW2J_js=require('./chunk-L4MDZW2J.js'),chunkUT6DJWGC_js=require('./chunk-UT6DJWGC.js');require('./chunk-GNIO6SOS.js'),require('./chunk-BJ5RZW6Y.js');var export_createDefaultFindOptions=chunkL4MDZW2J_js.a.createDefaultFindOptions;var export_createSearchPattern=chunkL4MDZW2J_js.a.createSearchPattern;var export_escapeRegexString=chunkL4MDZW2J_js.a.escapeRegexString;var export_findAllMatches=chunkL4MDZW2J_js.a.findAllMatches;var export_getDefaultHighlightOptions=chunkL4MDZW2J_js.a.getDefaultHighlightOptions;var export_getMatchCountText=chunkL4MDZW2J_js.a.getMatchCountText;var export_isEmptySearch=chunkL4MDZW2J_js.a.isEmptySearch;var export_replaceAllInContent=chunkL4MDZW2J_js.a.replaceAllInContent;var export_replaceFirstInContent=chunkL4MDZW2J_js.a.replaceFirstInContent;Object.defineProperty(exports,"PageSetupDialog",{enumerable:true,get:function(){return chunk5BSDRI3Z_js.a}});Object.defineProperty(exports,"KeyboardShortcutsDialog",{enumerable:true,get:function(){return chunkPGHNUFNT_js.l}});Object.defineProperty(exports,"PasteSpecialDialog",{enumerable:true,get:function(){return chunkPGHNUFNT_js.a}});Object.defineProperty(exports,"getAllCategories",{enumerable:true,get:function(){return chunkPGHNUFNT_js.k}});Object.defineProperty(exports,"getAllPasteOptions",{enumerable:true,get:function(){return chunkPGHNUFNT_js.d}});Object.defineProperty(exports,"getCategoryLabel",{enumerable:true,get:function(){return chunkPGHNUFNT_js.j}});Object.defineProperty(exports,"getCommonShortcuts",{enumerable:true,get:function(){return chunkPGHNUFNT_js.i}});Object.defineProperty(exports,"getDefaultPasteOption",{enumerable:true,get:function(){return chunkPGHNUFNT_js.e}});Object.defineProperty(exports,"getDefaultShortcuts",{enumerable:true,get:function(){return chunkPGHNUFNT_js.g}});Object.defineProperty(exports,"getPasteOption",{enumerable:true,get:function(){return chunkPGHNUFNT_js.c}});Object.defineProperty(exports,"getShortcutsByCategory",{enumerable:true,get:function(){return chunkPGHNUFNT_js.h}});Object.defineProperty(exports,"isPasteSpecialShortcut",{enumerable:true,get:function(){return chunkPGHNUFNT_js.f}});Object.defineProperty(exports,"useKeyboardShortcutsDialog",{enumerable:true,get:function(){return chunkPGHNUFNT_js.m}});Object.defineProperty(exports,"usePasteSpecial",{enumerable:true,get:function(){return chunkPGHNUFNT_js.b}});Object.defineProperty(exports,"formatShortcutKeys",{enumerable:true,get:function(){return chunkJGPOALUP_js.a}});Object.defineProperty(exports,"FindReplaceDialog",{enumerable:true,get:function(){return chunk4SYDL233_js.a}});Object.defineProperty(exports,"HyperlinkDialog",{enumerable:true,get:function(){return chunkUT6DJWGC_js.d}});Object.defineProperty(exports,"createBookmarkLinkData",{enumerable:true,get:function(){return chunkUT6DJWGC_js.f}});Object.defineProperty(exports,"createHyperlinkData",{enumerable:true,get:function(){return chunkUT6DJWGC_js.e}});Object.defineProperty(exports,"emailToMailto",{enumerable:true,get:function(){return chunkUT6DJWGC_js.j}});Object.defineProperty(exports,"extractBookmarksForDialog",{enumerable:true,get:function(){return chunkUT6DJWGC_js.l}});Object.defineProperty(exports,"getDisplayText",{enumerable:true,get:function(){return chunkUT6DJWGC_js.i}});Object.defineProperty(exports,"getUrlType",{enumerable:true,get:function(){return chunkUT6DJWGC_js.c}});Object.defineProperty(exports,"isBookmarkHyperlinkData",{enumerable:true,get:function(){return chunkUT6DJWGC_js.h}});Object.defineProperty(exports,"isExternalHyperlinkData",{enumerable:true,get:function(){return chunkUT6DJWGC_js.g}});Object.defineProperty(exports,"isValidUrl",{enumerable:true,get:function(){return chunkUT6DJWGC_js.a}});Object.defineProperty(exports,"normalizeUrl",{enumerable:true,get:function(){return chunkUT6DJWGC_js.b}});Object.defineProperty(exports,"phoneToTel",{enumerable:true,get:function(){return chunkUT6DJWGC_js.k}});exports.createDefaultFindOptions=export_createDefaultFindOptions;exports.createSearchPattern=export_createSearchPattern;exports.escapeRegexString=export_escapeRegexString;exports.findAllMatches=export_findAllMatches;exports.getDefaultHighlightOptions=export_getDefaultHighlightOptions;exports.getMatchCountText=export_getMatchCountText;exports.isEmptySearch=export_isEmptySearch;exports.replaceAllInContent=export_replaceAllInContent;exports.replaceFirstInContent=export_replaceFirstInContent;
package/dist/dialogs.mjs CHANGED
@@ -1 +1 @@
1
- export{a as PageSetupDialog}from'./chunk-P3ADI7OT.mjs';export{l as KeyboardShortcutsDialog,a as PasteSpecialDialog,k as getAllCategories,d as getAllPasteOptions,j as getCategoryLabel,i as getCommonShortcuts,e as getDefaultPasteOption,g as getDefaultShortcuts,c as getPasteOption,h as getShortcutsByCategory,f as isPasteSpecialShortcut,m as useKeyboardShortcutsDialog,b as usePasteSpecial}from'./chunk-IL65NW44.mjs';export{a as formatShortcutKeys}from'./chunk-K5DD2LSK.mjs';export{a as FindReplaceDialog}from'./chunk-AJ2BNSGR.mjs';import {a}from'./chunk-OHNO4NRQ.mjs';export{d as HyperlinkDialog,f as createBookmarkLinkData,e as createHyperlinkData,j as emailToMailto,l as extractBookmarksForDialog,i as getDisplayText,c as getUrlType,h as isBookmarkHyperlinkData,g as isExternalHyperlinkData,a as isValidUrl,b as normalizeUrl,k as phoneToTel}from'./chunk-ICVBXT6V.mjs';import'./chunk-ZFZJRL2R.mjs';import'./chunk-BMBP5UFA.mjs';var export_createDefaultFindOptions=a.createDefaultFindOptions;var export_createSearchPattern=a.createSearchPattern;var export_escapeRegexString=a.escapeRegexString;var export_findAllMatches=a.findAllMatches;var export_getDefaultHighlightOptions=a.getDefaultHighlightOptions;var export_getMatchCountText=a.getMatchCountText;var export_isEmptySearch=a.isEmptySearch;var export_replaceAllInContent=a.replaceAllInContent;var export_replaceFirstInContent=a.replaceFirstInContent;export{export_createDefaultFindOptions as createDefaultFindOptions,export_createSearchPattern as createSearchPattern,export_escapeRegexString as escapeRegexString,export_findAllMatches as findAllMatches,export_getDefaultHighlightOptions as getDefaultHighlightOptions,export_getMatchCountText as getMatchCountText,export_isEmptySearch as isEmptySearch,export_replaceAllInContent as replaceAllInContent,export_replaceFirstInContent as replaceFirstInContent};
1
+ export{a as PageSetupDialog}from'./chunk-P3ADI7OT.mjs';export{l as KeyboardShortcutsDialog,a as PasteSpecialDialog,k as getAllCategories,d as getAllPasteOptions,j as getCategoryLabel,i as getCommonShortcuts,e as getDefaultPasteOption,g as getDefaultShortcuts,c as getPasteOption,h as getShortcutsByCategory,f as isPasteSpecialShortcut,m as useKeyboardShortcutsDialog,b as usePasteSpecial}from'./chunk-IL65NW44.mjs';export{a as formatShortcutKeys}from'./chunk-K5DD2LSK.mjs';export{a as FindReplaceDialog}from'./chunk-AYHZMFCQ.mjs';import {a}from'./chunk-OHNO4NRQ.mjs';export{d as HyperlinkDialog,f as createBookmarkLinkData,e as createHyperlinkData,j as emailToMailto,l as extractBookmarksForDialog,i as getDisplayText,c as getUrlType,h as isBookmarkHyperlinkData,g as isExternalHyperlinkData,a as isValidUrl,b as normalizeUrl,k as phoneToTel}from'./chunk-ICVBXT6V.mjs';import'./chunk-ZFZJRL2R.mjs';import'./chunk-BMBP5UFA.mjs';var export_createDefaultFindOptions=a.createDefaultFindOptions;var export_createSearchPattern=a.createSearchPattern;var export_escapeRegexString=a.escapeRegexString;var export_findAllMatches=a.findAllMatches;var export_getDefaultHighlightOptions=a.getDefaultHighlightOptions;var export_getMatchCountText=a.getMatchCountText;var export_isEmptySearch=a.isEmptySearch;var export_replaceAllInContent=a.replaceAllInContent;var export_replaceFirstInContent=a.replaceFirstInContent;export{export_createDefaultFindOptions as createDefaultFindOptions,export_createSearchPattern as createSearchPattern,export_escapeRegexString as escapeRegexString,export_findAllMatches as findAllMatches,export_getDefaultHighlightOptions as getDefaultHighlightOptions,export_getMatchCountText as getMatchCountText,export_isEmptySearch as isEmptySearch,export_replaceAllInContent as replaceAllInContent,export_replaceFirstInContent as replaceFirstInContent};
package/dist/hooks.d.mts CHANGED
@@ -21,6 +21,9 @@ import { HighlightRect, SelectionHighlightConfig, ParsedClipboardContent } from
21
21
  import { ClipboardSelection, Theme, SavedDocumentData, AutoSaveStatus } from '@eigenpal/docx-editor-core';
22
22
  export { AutoSaveStatus, ClipboardSelection, SavedDocumentData, TABLE_DATA_ATTRIBUTES, createSelectionFromDOM, formatLastSaveTime, formatStorageSize, getAutoSaveStatusLabel, getAutoSaveStorageSize, getSelectionRuns, isAutoSaveSupported } from '@eigenpal/docx-editor-core';
23
23
  import { EditorView } from 'prosemirror-view';
24
+ import { EditorState } from 'prosemirror-state';
25
+ import { TrackedChangesResult } from '@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges';
26
+ export { TrackedChangesResult, extractTrackedChanges } from '@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges';
24
27
  import '@eigenpal/docx-editor-core/utils/findReplace';
25
28
 
26
29
  /**
@@ -494,4 +497,17 @@ declare function isZoomPreset(zoom: number): boolean;
494
497
  */
495
498
  declare function clampZoom(zoom: number, minZoom?: number, maxZoom?: number): number;
496
499
 
497
- export { type DragAutoScrollOptions, type HistoryEntry, HistoryManager, type SelectionOverlayProps, type TableSelectionState, type UseAspectLockedSizeReturn, type UseAutoSaveOptions, type UseAutoSaveReturn, type UseClipboardOptions, type UseClipboardReturn, type UseFixedDropdownOptions, type UseFixedDropdownReturn, type UseHistoryOptions, type UseHistoryReturn, type UseSelectionHighlightOptions, type UseSelectionHighlightReturn, type UseTableSelectionOptions, type UseTableSelectionReturn, type UseWheelZoomOptions, type UseWheelZoomReturn, type VisualLineNavigationOptions, ZOOM_PRESETS, clampZoom, findNearestZoomPreset, formatZoom, generateOverlayElements, getNextZoomPreset, getPreviousZoomPreset, getZoomPresets, isZoomPreset, parseZoom, useAspectLockedSize, useAutoHistory, useAutoSave, useClipboard, useDocumentHistory, useDragAutoScroll, useFixedDropdown, useHistory, useSelectionHighlight, useTableSelection, useVisualLineNavigation, useWheelZoom };
500
+ /**
501
+ * Returns tracked changes (and the comment→revision overlap map for threading)
502
+ * derived from the latest PM state. Memoized on state identity, so derivation
503
+ * only re-runs when PM state changes (which happens on every doc-changing
504
+ * transaction, including remote ones via ySyncPlugin).
505
+ *
506
+ * No debounce: a single O(N) doc walk, cheap enough to run per transaction.
507
+ * If you see jank on huge documents, wrap the setter that drives the state
508
+ * argument in `requestAnimationFrame` rather than reintroducing a delay here —
509
+ * a delay makes the sidebar feel laggy.
510
+ */
511
+ declare function useTrackedChanges(state: EditorState | null): TrackedChangesResult;
512
+
513
+ export { type DragAutoScrollOptions, type HistoryEntry, HistoryManager, type SelectionOverlayProps, type TableSelectionState, type UseAspectLockedSizeReturn, type UseAutoSaveOptions, type UseAutoSaveReturn, type UseClipboardOptions, type UseClipboardReturn, type UseFixedDropdownOptions, type UseFixedDropdownReturn, type UseHistoryOptions, type UseHistoryReturn, type UseSelectionHighlightOptions, type UseSelectionHighlightReturn, type UseTableSelectionOptions, type UseTableSelectionReturn, type UseWheelZoomOptions, type UseWheelZoomReturn, type VisualLineNavigationOptions, ZOOM_PRESETS, clampZoom, findNearestZoomPreset, formatZoom, generateOverlayElements, getNextZoomPreset, getPreviousZoomPreset, getZoomPresets, isZoomPreset, parseZoom, useAspectLockedSize, useAutoHistory, useAutoSave, useClipboard, useDocumentHistory, useDragAutoScroll, useFixedDropdown, useHistory, useSelectionHighlight, useTableSelection, useTrackedChanges, useVisualLineNavigation, useWheelZoom };
package/dist/hooks.d.ts CHANGED
@@ -21,6 +21,9 @@ import { HighlightRect, SelectionHighlightConfig, ParsedClipboardContent } from
21
21
  import { ClipboardSelection, Theme, SavedDocumentData, AutoSaveStatus } from '@eigenpal/docx-editor-core';
22
22
  export { AutoSaveStatus, ClipboardSelection, SavedDocumentData, TABLE_DATA_ATTRIBUTES, createSelectionFromDOM, formatLastSaveTime, formatStorageSize, getAutoSaveStatusLabel, getAutoSaveStorageSize, getSelectionRuns, isAutoSaveSupported } from '@eigenpal/docx-editor-core';
23
23
  import { EditorView } from 'prosemirror-view';
24
+ import { EditorState } from 'prosemirror-state';
25
+ import { TrackedChangesResult } from '@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges';
26
+ export { TrackedChangesResult, extractTrackedChanges } from '@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges';
24
27
  import '@eigenpal/docx-editor-core/utils/findReplace';
25
28
 
26
29
  /**
@@ -494,4 +497,17 @@ declare function isZoomPreset(zoom: number): boolean;
494
497
  */
495
498
  declare function clampZoom(zoom: number, minZoom?: number, maxZoom?: number): number;
496
499
 
497
- export { type DragAutoScrollOptions, type HistoryEntry, HistoryManager, type SelectionOverlayProps, type TableSelectionState, type UseAspectLockedSizeReturn, type UseAutoSaveOptions, type UseAutoSaveReturn, type UseClipboardOptions, type UseClipboardReturn, type UseFixedDropdownOptions, type UseFixedDropdownReturn, type UseHistoryOptions, type UseHistoryReturn, type UseSelectionHighlightOptions, type UseSelectionHighlightReturn, type UseTableSelectionOptions, type UseTableSelectionReturn, type UseWheelZoomOptions, type UseWheelZoomReturn, type VisualLineNavigationOptions, ZOOM_PRESETS, clampZoom, findNearestZoomPreset, formatZoom, generateOverlayElements, getNextZoomPreset, getPreviousZoomPreset, getZoomPresets, isZoomPreset, parseZoom, useAspectLockedSize, useAutoHistory, useAutoSave, useClipboard, useDocumentHistory, useDragAutoScroll, useFixedDropdown, useHistory, useSelectionHighlight, useTableSelection, useVisualLineNavigation, useWheelZoom };
500
+ /**
501
+ * Returns tracked changes (and the comment→revision overlap map for threading)
502
+ * derived from the latest PM state. Memoized on state identity, so derivation
503
+ * only re-runs when PM state changes (which happens on every doc-changing
504
+ * transaction, including remote ones via ySyncPlugin).
505
+ *
506
+ * No debounce: a single O(N) doc walk, cheap enough to run per transaction.
507
+ * If you see jank on huge documents, wrap the setter that drives the state
508
+ * argument in `requestAnimationFrame` rather than reintroducing a delay here —
509
+ * a delay makes the sidebar feel laggy.
510
+ */
511
+ declare function useTrackedChanges(state: EditorState | null): TrackedChangesResult;
512
+
513
+ export { type DragAutoScrollOptions, type HistoryEntry, HistoryManager, type SelectionOverlayProps, type TableSelectionState, type UseAspectLockedSizeReturn, type UseAutoSaveOptions, type UseAutoSaveReturn, type UseClipboardOptions, type UseClipboardReturn, type UseFixedDropdownOptions, type UseFixedDropdownReturn, type UseHistoryOptions, type UseHistoryReturn, type UseSelectionHighlightOptions, type UseSelectionHighlightReturn, type UseTableSelectionOptions, type UseTableSelectionReturn, type UseWheelZoomOptions, type UseWheelZoomReturn, type VisualLineNavigationOptions, ZOOM_PRESETS, clampZoom, findNearestZoomPreset, formatZoom, generateOverlayElements, getNextZoomPreset, getPreviousZoomPreset, getZoomPresets, isZoomPreset, parseZoom, useAspectLockedSize, useAutoHistory, useAutoSave, useClipboard, useDocumentHistory, useDragAutoScroll, useFixedDropdown, useHistory, useSelectionHighlight, useTableSelection, useTrackedChanges, useVisualLineNavigation, useWheelZoom };
package/dist/hooks.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkJHSXIGTQ_js=require('./chunk-JHSXIGTQ.js'),chunkNIBCC7WQ_js=require('./chunk-NIBCC7WQ.js'),chunkYVYT3JWY_js=require('./chunk-YVYT3JWY.js'),chunkL4MDZW2J_js=require('./chunk-L4MDZW2J.js');require('./chunk-GNIO6SOS.js'),require('./chunk-BJ5RZW6Y.js');var oe=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 oe__default=/*#__PURE__*/_interopDefault(oe);function ue(n){let{containerRef:e,enabled:r=true,config:s=utils.DEFAULT_SELECTION_STYLE,useOverlay:c=false,debounceMs:u=16,onSelectionChange:f}=n,[S,p]=oe.useState(false),[x,v]=oe.useState(""),[a,m]=oe.useState([]),[d,y]=oe.useState(false),h=oe.useRef(null),C=oe.useRef(0),o=oe.useCallback(()=>{let t=e.current,b=utils.hasActiveSelection(),D=utils.getSelectedText(),A=t?utils.isSelectionWithin(t):false;if(p(b),v(D),y(A),c&&A){let $=utils.getMergedSelectionRects(t);m($);}else m([]);f&&f(b&&A,D);},[e,c,f]),i=oe.useCallback(()=>{let t=performance.now();if(t-C.current<u){h.current!==null&&clearTimeout(h.current),h.current=window.setTimeout(()=>{C.current=performance.now(),o(),h.current=null;},u);return}C.current=t,o();},[u,o]),l=oe.useCallback(()=>{o();},[o]),R=oe.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 oe.useEffect(()=>(r&&!utils.areSelectionStylesInjected()&&utils.injectSelectionStyles(s),()=>{}),[r,s]),oe.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),h.current!==null&&clearTimeout(h.current);}},[r,i,o]),{hasSelection:S,selectedText:x,highlightRects:a,isSelectionInContainer:d,refresh:l,getOverlayStyle:R}}function ce(n,e=utils.DEFAULT_SELECTION_STYLE){return n.map((r,s)=>oe__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 be(n={}){let{onCopy:e,onCut:r,onPaste:s,cleanWordFormatting:c=true,editable:u=true,onError:f,theme:S}=n,p=oe.useRef(false),x=oe.useRef(null),v=oe.useCallback(async o=>{if(p.current)return false;p.current=true;try{let i=await utils.copyRuns(o.runs,{onError:f,theme:S});return i&&e?.(o),i}finally{p.current=false;}},[e,f,S]),a=oe.useCallback(async o=>{if(p.current||!u)return false;p.current=true;try{let i=await utils.copyRuns(o.runs,{onError:f,theme:S});return i&&r?.(o),i}finally{p.current=false;}},[r,u,f,S]),m=oe.useCallback(async(o=false)=>{if(p.current||!u)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,c);return x.current=t,s?.(t,o),t}return null}catch(i){return f?.(i),null}finally{p.current=false;}},[u,c,s,f]),d=oe.useCallback(o=>{let i=docxEditorCore.createSelectionFromDOM();if(!i)return;o.preventDefault();let l=utils.runsToClipboardContent(i.runs,true,S);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,S]),y=oe.useCallback(o=>{if(!u)return;let i=docxEditorCore.createSelectionFromDOM();if(!i)return;o.preventDefault();let l=utils.runsToClipboardContent(i.runs,true,S);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);},[u,r,S]),h=oe.useCallback(o=>{if(!u)return;o.preventDefault();let i=utils.handlePasteEvent(o,{cleanWordFormatting:c});if(i){x.current=i;let l=o.shiftKey??false;s?.(i,l);}},[u,c,s]),C=oe.useCallback(o=>{},[]);return {copy:v,cut:a,paste:m,handleCopy:d,handleCut:y,handlePaste:h,handleKeyDown:C,isProcessing:p.current,lastPastedContent:x.current}}function Re(n,e={}){let{storageKey:r,interval:s,enabled:c=true,maxAge:u,onSave:f,onError:S,onRecoveryAvailable:p,saveOnChange:x,debounceDelay:v}=e,a=oe.useMemo(()=>new docxEditorCore.AutoSaveManager({storageKey:r,interval:s,maxAge:u,saveOnChange:x,debounceDelay:v,onSave:f,onError:S,onRecoveryAvailable:p}),[r]);oe.useEffect(()=>{c?(a.enable(),a.startInterval()):a.disable();},[a,c]),oe.useEffect(()=>{a.onDocumentChanged(n??null);},[a,n]),oe.useEffect(()=>()=>{a.destroy();},[a]);let m=oe.useSyncExternalStore(a.subscribe,a.getSnapshot),d=oe.useCallback(()=>a.save(),[a]),y=oe.useCallback(()=>a.clear(),[a]),h=oe.useCallback(()=>a.getRecoveryData(),[a]),C=oe.useCallback(()=>a.acceptRecovery(),[a]),o=oe.useCallback(()=>a.dismissRecovery(),[a]),i=oe.useCallback(()=>a.enable(),[a]),l=oe.useCallback(()=>a.disable(),[a]);return {status:m.status,lastSaveTime:m.lastSaveTime,save:d,clearAutoSave:y,hasRecoveryData:m.hasRecoveryData,getRecoveryData:h,acceptRecovery:C,dismissRecovery:o,isEnabled:m.isEnabled,enable:i,disable:l}}var Oe=1,K=.25,W=4,Pe=.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 Ze(n){let e=g[0],r=Math.abs(n-e);for(let s of g){let c=Math.abs(n-s);c<r&&(r=c,e=s);}return e}function Te(n){for(let e of g)if(e>n+.01)return e;return g[g.length-1]}function Ae(n){for(let e=g.length-1;e>=0;e--)if(g[e]<n-.01)return g[e];return g[0]}function Ue(n={}){let{initialZoom:e=Oe,minZoom:r=K,maxZoom:s=W,zoomStep:c=Pe,enabled:u=true,containerRef:f,onZoomChange:S,enableKeyboardShortcuts:p=true,preventDefault:x=true}=n,[v,a]=oe.useState(e),m=oe.useRef(v);oe.useEffect(()=>{m.current=v;},[v]);let d=oe.useCallback(t=>{let b=N(_(t,r,s));b!==m.current&&(a(b),S?.(b));},[r,s,S]),y=oe.useCallback(()=>{d(m.current+c);},[c,d]),h=oe.useCallback(()=>{d(m.current-c);},[c,d]),C=oe.useCallback(()=>{d(e);},[e,d]),o=oe.useCallback(()=>{d(1);},[d]),i=oe.useCallback((t,b)=>{if(b>0){let D=t/b;d(D);}},[d]),l=oe.useCallback(t=>{if(!u||!(t.ctrlKey||t.metaKey))return;x&&t.preventDefault();let D=t.deltaY;D<0?d(m.current+c):D>0&&d(m.current-c);},[u,x,c,d]),R=oe.useCallback(t=>{if(!(!u||!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(),h();return}}},[u,p,y,h,o]);return oe.useEffect(()=>{if(!u)return;let t=f?.current;if(t)return t.addEventListener("wheel",l,{passive:false}),()=>{t.removeEventListener("wheel",l);}},[u,f,l]),oe.useEffect(()=>{if(!(!u||!p))return document.addEventListener("keydown",R),()=>{document.removeEventListener("keydown",R);}},[u,p,R]),{zoom:v,setZoom:d,zoomIn:y,zoomOut:h,resetZoom:C,zoomTo100:o,zoomToFit:i,isMinZoom:v<=r,isMaxZoom:v>=s,zoomPercent:Math.round(v*100),handleWheel:l,handleKeyDown:R}}function Me(){return [...g]}function He(n){return Ze(n)}function we(n){return Te(n)}function Le(n){return Ae(n)}function ze(n){return `${Math.round(n*100)}%`}function Fe(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 Ie(n,e=K,r=W){return N(_(n,e,r))}Object.defineProperty(exports,"HistoryManager",{enumerable:true,get:function(){return chunkJHSXIGTQ_js.h}});Object.defineProperty(exports,"TABLE_DATA_ATTRIBUTES",{enumerable:true,get:function(){return chunkJHSXIGTQ_js.d}});Object.defineProperty(exports,"useAutoHistory",{enumerable:true,get:function(){return chunkJHSXIGTQ_js.f}});Object.defineProperty(exports,"useDocumentHistory",{enumerable:true,get:function(){return chunkJHSXIGTQ_js.g}});Object.defineProperty(exports,"useDragAutoScroll",{enumerable:true,get:function(){return chunkJHSXIGTQ_js.b}});Object.defineProperty(exports,"useHistory",{enumerable:true,get:function(){return chunkJHSXIGTQ_js.e}});Object.defineProperty(exports,"useTableSelection",{enumerable:true,get:function(){return chunkJHSXIGTQ_js.c}});Object.defineProperty(exports,"useVisualLineNavigation",{enumerable:true,get:function(){return chunkJHSXIGTQ_js.a}});Object.defineProperty(exports,"useAspectLockedSize",{enumerable:true,get:function(){return chunkNIBCC7WQ_js.a}});Object.defineProperty(exports,"useFixedDropdown",{enumerable:true,get:function(){return chunkYVYT3JWY_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=Ie;exports.findNearestZoomPreset=He;exports.formatZoom=ze;exports.generateOverlayElements=ce;exports.getNextZoomPreset=we;exports.getPreviousZoomPreset=Le;exports.getZoomPresets=Me;exports.isZoomPreset=ke;exports.parseZoom=Fe;exports.useAutoSave=Re;exports.useClipboard=be;exports.useSelectionHighlight=ue;exports.useWheelZoom=Ue;
1
+ 'use strict';var chunk2WKOPOCC_js=require('./chunk-2WKOPOCC.js'),chunkNIBCC7WQ_js=require('./chunk-NIBCC7WQ.js'),chunkYVYT3JWY_js=require('./chunk-YVYT3JWY.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 chunk2WKOPOCC_js.j}});Object.defineProperty(exports,"TABLE_DATA_ATTRIBUTES",{enumerable:true,get:function(){return chunk2WKOPOCC_js.f}});Object.defineProperty(exports,"extractTrackedChanges",{enumerable:true,get:function(){return chunk2WKOPOCC_js.c}});Object.defineProperty(exports,"useAutoHistory",{enumerable:true,get:function(){return chunk2WKOPOCC_js.h}});Object.defineProperty(exports,"useDocumentHistory",{enumerable:true,get:function(){return chunk2WKOPOCC_js.i}});Object.defineProperty(exports,"useDragAutoScroll",{enumerable:true,get:function(){return chunk2WKOPOCC_js.b}});Object.defineProperty(exports,"useHistory",{enumerable:true,get:function(){return chunk2WKOPOCC_js.g}});Object.defineProperty(exports,"useTableSelection",{enumerable:true,get:function(){return chunk2WKOPOCC_js.e}});Object.defineProperty(exports,"useTrackedChanges",{enumerable:true,get:function(){return chunk2WKOPOCC_js.d}});Object.defineProperty(exports,"useVisualLineNavigation",{enumerable:true,get:function(){return chunk2WKOPOCC_js.a}});Object.defineProperty(exports,"useAspectLockedSize",{enumerable:true,get:function(){return chunkNIBCC7WQ_js.a}});Object.defineProperty(exports,"useFixedDropdown",{enumerable:true,get:function(){return chunkYVYT3JWY_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{h as HistoryManager,d as TABLE_DATA_ATTRIBUTES,f as useAutoHistory,g as useDocumentHistory,b as useDragAutoScroll,e as useHistory,c as useTableSelection,a as useVisualLineNavigation}from'./chunk-6AX4I76A.mjs';export{a as useAspectLockedSize}from'./chunk-GM2S2WMT.mjs';export{c as useFixedDropdown}from'./chunk-TN5C2ZYV.mjs';export{b as useFindReplace}from'./chunk-OHNO4NRQ.mjs';import'./chunk-ZFZJRL2R.mjs';import'./chunk-BMBP5UFA.mjs';import oe,{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 ue(n){let{containerRef:e,enabled:r=true,config:s=DEFAULT_SELECTION_STYLE,useOverlay:c=false,debounceMs:u=16,onSelectionChange:f}=n,[S,p]=useState(false),[x,v]=useState(""),[a,m]=useState([]),[d,y]=useState(false),h=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),c&&A){let $=getMergedSelectionRects(t);m($);}else m([]);f&&f(b&&A,D);},[e,c,f]),i=useCallback(()=>{let t=performance.now();if(t-C.current<u){h.current!==null&&clearTimeout(h.current),h.current=window.setTimeout(()=>{C.current=performance.now(),o(),h.current=null;},u);return}C.current=t,o();},[u,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),h.current!==null&&clearTimeout(h.current);}},[r,i,o]),{hasSelection:S,selectedText:x,highlightRects:a,isSelectionInContainer:d,refresh:l,getOverlayStyle:R}}function ce(n,e=DEFAULT_SELECTION_STYLE){return n.map((r,s)=>oe.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 be(n={}){let{onCopy:e,onCut:r,onPaste:s,cleanWordFormatting:c=true,editable:u=true,onError:f,theme:S}=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:S});return i&&e?.(o),i}finally{p.current=false;}},[e,f,S]),a=useCallback(async o=>{if(p.current||!u)return false;p.current=true;try{let i=await copyRuns(o.runs,{onError:f,theme:S});return i&&r?.(o),i}finally{p.current=false;}},[r,u,f,S]),m=useCallback(async(o=false)=>{if(p.current||!u)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,c);return x.current=t,s?.(t,o),t}return null}catch(i){return f?.(i),null}finally{p.current=false;}},[u,c,s,f]),d=useCallback(o=>{let i=createSelectionFromDOM();if(!i)return;o.preventDefault();let l=runsToClipboardContent(i.runs,true,S);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,S]),y=useCallback(o=>{if(!u)return;let i=createSelectionFromDOM();if(!i)return;o.preventDefault();let l=runsToClipboardContent(i.runs,true,S);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);},[u,r,S]),h=useCallback(o=>{if(!u)return;o.preventDefault();let i=handlePasteEvent(o,{cleanWordFormatting:c});if(i){x.current=i;let l=o.shiftKey??false;s?.(i,l);}},[u,c,s]),C=useCallback(o=>{},[]);return {copy:v,cut:a,paste:m,handleCopy:d,handleCut:y,handlePaste:h,handleKeyDown:C,isProcessing:p.current,lastPastedContent:x.current}}function Re(n,e={}){let{storageKey:r,interval:s,enabled:c=true,maxAge:u,onSave:f,onError:S,onRecoveryAvailable:p,saveOnChange:x,debounceDelay:v}=e,a=useMemo(()=>new AutoSaveManager({storageKey:r,interval:s,maxAge:u,saveOnChange:x,debounceDelay:v,onSave:f,onError:S,onRecoveryAvailable:p}),[r]);useEffect(()=>{c?(a.enable(),a.startInterval()):a.disable();},[a,c]),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]),h=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:h,acceptRecovery:C,dismissRecovery:o,isEnabled:m.isEnabled,enable:i,disable:l}}var Oe=1,K=.25,W=4,Pe=.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 Ze(n){let e=g[0],r=Math.abs(n-e);for(let s of g){let c=Math.abs(n-s);c<r&&(r=c,e=s);}return e}function Te(n){for(let e of g)if(e>n+.01)return e;return g[g.length-1]}function Ae(n){for(let e=g.length-1;e>=0;e--)if(g[e]<n-.01)return g[e];return g[0]}function Ue(n={}){let{initialZoom:e=Oe,minZoom:r=K,maxZoom:s=W,zoomStep:c=Pe,enabled:u=true,containerRef:f,onZoomChange:S,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),S?.(b));},[r,s,S]),y=useCallback(()=>{d(m.current+c);},[c,d]),h=useCallback(()=>{d(m.current-c);},[c,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(!u||!(t.ctrlKey||t.metaKey))return;x&&t.preventDefault();let D=t.deltaY;D<0?d(m.current+c):D>0&&d(m.current-c);},[u,x,c,d]),R=useCallback(t=>{if(!(!u||!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(),h();return}}},[u,p,y,h,o]);return useEffect(()=>{if(!u)return;let t=f?.current;if(t)return t.addEventListener("wheel",l,{passive:false}),()=>{t.removeEventListener("wheel",l);}},[u,f,l]),useEffect(()=>{if(!(!u||!p))return document.addEventListener("keydown",R),()=>{document.removeEventListener("keydown",R);}},[u,p,R]),{zoom:v,setZoom:d,zoomIn:y,zoomOut:h,resetZoom:C,zoomTo100:o,zoomToFit:i,isMinZoom:v<=r,isMaxZoom:v>=s,zoomPercent:Math.round(v*100),handleWheel:l,handleKeyDown:R}}function Me(){return [...g]}function He(n){return Ze(n)}function we(n){return Te(n)}function Le(n){return Ae(n)}function ze(n){return `${Math.round(n*100)}%`}function Fe(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 Ie(n,e=K,r=W){return N(_(n,e,r))}export{g as ZOOM_PRESETS,Ie as clampZoom,He as findNearestZoomPreset,ze as formatZoom,ce as generateOverlayElements,we as getNextZoomPreset,Le as getPreviousZoomPreset,Me as getZoomPresets,ke as isZoomPreset,Fe as parseZoom,Re as useAutoSave,be as useClipboard,ue as useSelectionHighlight,Ue 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-T65QFB7S.mjs';export{a as useAspectLockedSize}from'./chunk-GM2S2WMT.mjs';export{c as useFixedDropdown}from'./chunk-TN5C2ZYV.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
@@ -20,15 +20,15 @@ import * as prosemirror_view from 'prosemirror-view';
20
20
  import { EditorView } from 'prosemirror-view';
21
21
  import * as prosemirror_state from 'prosemirror-state';
22
22
  import { EditorState, Transaction } from 'prosemirror-state';
23
- import { Document, Theme } from '@eigenpal/docx-editor-core/types/document';
23
+ import { Document, HeaderFooter, Theme } from '@eigenpal/docx-editor-core/types/document';
24
24
  import { FontOption } from '@eigenpal/docx-editor-core/utils/fontOptions';
25
25
  import { R as ReactSidebarItem } from './types-D35gNE-_.mjs';
26
26
  import { Comment } from '@eigenpal/docx-editor-core/types/content';
27
27
  import { Translations, TFunction } from '@eigenpal/docx-editor-i18n';
28
28
  import { P as PrintOptions } from './PrintPreview-DEhwRBC_.mjs';
29
- import { DocumentAgent } from '@eigenpal/docx-editor-core/agent';
30
- import { DocxInput } from '@eigenpal/docx-editor-core/utils';
31
- import { SelectionState } from '@eigenpal/docx-editor-core/prosemirror';
29
+ import { DocumentAgent, ContentControlFilter, ContentControlValue } from '@eigenpal/docx-editor-core/agent';
30
+ import { DocxInput, FontDefinition } from '@eigenpal/docx-editor-core/utils';
31
+ import { SelectionState, PMContentControl } from '@eigenpal/docx-editor-core/prosemirror';
32
32
  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';
@@ -108,6 +108,17 @@ interface PagedEditorRef {
108
108
  * No-op if the layout isn't ready yet or pageNumber is out of range.
109
109
  */
110
110
  scrollToPage(pageNumber: number): void;
111
+ /**
112
+ * Look up the persistent hidden HF PM EditorView for a given HeaderFooter
113
+ * instance. Returns null when none is mounted (no document, or `hf` is not
114
+ * present in `Document.package.headers/footers`). Phase 2 of the HF
115
+ * unification: the inline overlay uses this to replicate edits into the
116
+ * persistent PM so the painter — which reads from the persistent PM per
117
+ * phase 1 — re-renders live during typing. Phase 5 deletes the inline
118
+ * overlay's PM and this method's only remaining caller is the click /
119
+ * focus router (phase 3).
120
+ */
121
+ getHfPmView(hf: HeaderFooter): EditorView | null;
111
122
  }
112
123
 
113
124
  /**
@@ -202,6 +213,23 @@ interface DocxEditorProps {
202
213
  * @example fontFamilies={[{ name: 'Roboto', fontFamily: 'Roboto, sans-serif', category: 'sans-serif' }]}
203
214
  */
204
215
  fontFamilies?: ReadonlyArray<string | FontOption>;
216
+ /**
217
+ * Custom font faces to register with the browser before the editor measures
218
+ * text. Each entry injects an `@font-face` rule. Pass a URL (woff2/woff/
219
+ * ttf/otf), an ArrayBuffer, or omit `src` to load by name from Google Fonts.
220
+ * Multiple entries can share `family` to register different weights/styles.
221
+ *
222
+ * Pass a stable reference — inline arrays re-register faces on each render
223
+ * (the loader dedupes by `family|weight|style`, so it's harmless but wastes
224
+ * work).
225
+ *
226
+ * @example
227
+ * fonts={[
228
+ * { family: 'Custom Sans', src: '/fonts/CustomSans-Regular.woff2' },
229
+ * { family: 'Custom Sans', src: '/fonts/CustomSans-Bold.woff2', weight: 700 },
230
+ * ]}
231
+ */
232
+ fonts?: ReadonlyArray<FontDefinition>;
205
233
  /** Print options for print preview */
206
234
  printOptions?: PrintOptions;
207
235
  /**
@@ -434,6 +462,41 @@ interface DocxEditorRef {
434
462
  } | null;
435
463
  /** Get all comments. */
436
464
  getComments: () => Comment[];
465
+ /**
466
+ * List block-level content controls (SDTs) in the live document, optionally
467
+ * filtered by `tag`/`alias`/`id`/`type`. Each result includes the control's
468
+ * text and PM position. Anchors for templates and document automation.
469
+ */
470
+ getContentControls: (filter?: ContentControlFilter) => PMContentControl[];
471
+ /** Scroll the first content control matching `filter` into view. Returns false if none. */
472
+ scrollToContentControl: (filter: ContentControlFilter) => boolean;
473
+ /**
474
+ * Replace the content of the first control matching `filter` with `text`
475
+ * (newlines become paragraphs). Returns false if no match. Throws if the
476
+ * control is content-locked unless `{ force: true }`.
477
+ */
478
+ setContentControlContent: (filter: ContentControlFilter, text: string, options?: {
479
+ force?: boolean;
480
+ }) => boolean;
481
+ /**
482
+ * Remove the first control matching `filter`. With `{ keepContent: true }`
483
+ * the inner blocks are unwrapped in place. Returns false if no match. Throws
484
+ * if the control is deletion-locked unless `{ force: true }`.
485
+ */
486
+ removeContentControl: (filter: ContentControlFilter, options?: {
487
+ force?: boolean;
488
+ keepContent?: boolean;
489
+ }) => boolean;
490
+ /**
491
+ * Set a typed value on the first control matching `filter`: a dropdown
492
+ * selection (`{ kind: 'dropdown', value }`), checkbox (`{ kind: 'checkbox',
493
+ * checked }`), or date (`{ kind: 'date', date }`). Updates the visible
494
+ * content and structured state. Returns false if no match; throws if
495
+ * content-locked (unless `force`) or the value doesn't fit the control type.
496
+ */
497
+ setContentControlValue: (filter: ContentControlFilter, value: ContentControlValue, options?: {
498
+ force?: boolean;
499
+ }) => boolean;
437
500
  /** Subscribe to document changes. Fires after every committed edit. Returns unsubscribe. */
438
501
  onContentChange: (listener: (document: Document) => void) => () => void;
439
502
  /** Subscribe to selection changes (cursor moves / selection changes). Returns unsubscribe. */