@univerjs/docs-ui 0.4.2-nightly.202411061606 → 0.4.2-nightly.202411081606
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/lib/cjs/facade.js +19 -0
- package/lib/cjs/index.js +29 -0
- package/lib/cjs/locale/en-US.js +1 -0
- package/lib/cjs/locale/fa-IR.js +1 -0
- package/lib/cjs/locale/ru-RU.js +1 -0
- package/lib/cjs/locale/vi-VN.js +1 -0
- package/lib/cjs/locale/zh-CN.js +1 -0
- package/lib/cjs/locale/zh-TW.js +1 -0
- package/lib/es/facade.js +1820 -61
- package/lib/es/index.js +8071 -6412
- package/lib/{locale → es/locale}/en-US.js +2 -2
- package/lib/{locale → es/locale}/fa-IR.js +2 -2
- package/lib/{locale → es/locale}/ru-RU.js +2 -2
- package/lib/{locale → es/locale}/vi-VN.js +2 -2
- package/lib/{locale → es/locale}/zh-CN.js +2 -2
- package/lib/{locale → es/locale}/zh-TW.js +2 -2
- package/lib/types/commands/commands/doc-select-all.command.d.ts +5 -0
- package/lib/types/controllers/doc-header-footer.controller.d.ts +0 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/umd/facade.js +3 -3
- package/lib/umd/index.js +13 -21
- package/package.json +24 -16
- package/lib/core-editing.command-CfzMbVxq.mjs +0 -1894
- package/lib/types/commands/operations/select-all.operation.d.ts +0 -5
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";var Nt=Object.defineProperty;var wt=(a,t,e)=>t in a?Nt(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var _=(a,t,e)=>wt(a,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),v=require("@univerjs/engine-render"),K=require("@univerjs/docs"),At=require("@univerjs/ui"),N=require("rxjs");var Tt=(a=>(a[a.LEFT=0]="LEFT",a[a.RIGHT=1]="RIGHT",a))(Tt||{});function ut(a,t=""){if(!t)return["body"];const{headers:e,footers:s}=a.getSnapshot();if(e==null&&s==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[t])!=null)return["headers",t,"body"];if((s==null?void 0:s[t])!=null)return["footers",t,"body"];throw new Error("Segment id not found in headers or footers")}const Lt="doc.command.insert-text",Dt={id:Lt,type:d.CommandType.COMMAND,handler:async(a,t)=>{var y;const e=a.get(d.ICommandService),{range:s,segmentId:n,body:o,unitId:i,cursorOffset:r}=t,c=a.get(K.DocSelectionManagerService),u=a.get(d.IUniverInstanceService).getUnit(i,d.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const h=c.getActiveTextRange(),g=u.getSelfOrHeaderFooterModel((y=h==null?void 0:h.segmentId)!=null?y:"").getBody();if(g==null)return!1;const{startOffset:f,collapsed:m}=s,S=r!=null?r:o.dataStream.length,I=[{startOffset:f+S,endOffset:f+S,style:h==null?void 0:h.style,collapsed:m}],p={id:K.RichTextEditingMutation.id,params:{unitId:i,actions:[],textRanges:I,debounce:!0}},R=new d.TextX,b=d.JSONX.getInstance();if(m)f>0&&R.push({t:d.TextXActionType.RETAIN,len:f}),R.push({t:d.TextXActionType.INSERT,body:o,len:o.dataStream.length});else{const T=d.BuildTextUtils.selection.delete([s],g,0,o);R.push(...T)}p.params.textRanges=[{startOffset:f+S,endOffset:f+S,collapsed:m}];const E=ut(u,n);return p.params.actions=b.editOp(R.serialize(),E),!!e.syncExecuteCommand(p.id,p.params)}};d.CommandType.COMMAND;d.CommandType.COMMAND;var Q=(a=>(a[a.page=0]="page",a[a.section=1]="section",a[a.column=2]="column",a[a.line=3]="line",a[a.divide=4]="divide",a[a.glyph=5]="glyph",a))(Q||{});const H={page:0,section:1,column:2,line:3,divide:4,glyph:5};function dt(a,t){return a.page>t.page?!1:a.page<t.page?!0:a.section>t.section?!1:a.section<t.section?!0:a.column>t.column?!1:a.column<t.column?!0:a.line>t.line?!1:a.line<t.line?!0:a.divide>t.divide?!1:a.divide<t.divide?!0:a.glyph>t.glyph?!1:(a.glyph<t.glyph,!0)}function ot(a,t){return dt(a,t)?{start:a,end:t}:{start:t,end:a}}function mt(a){const t=a.length;if(t===0)return;const e=a[0],s=a[t-1],n=a.length===1&&e.collapsed;return{startOffset:e.startOffset,endOffset:s.endOffset,collapsed:n}}function Bt(a,t,e,s){let n=s,o=s;for(let i=0;i<a.length;i++){const c=a[i].count;i<t&&(n+=c),i<e&&(o+=c)}return{startOffset:n,endOffset:o}}function it(a){const{startX:t,startY:e,endX:s,endY:n}=a,o=[];return o.push({x:t,y:e}),o.push({x:s,y:e}),o.push({x:s,y:n}),o.push({x:t,y:n}),o.push({x:t,y:e}),o}class St{constructor(t,e){_(this,"_liquid",new v.Liquid);_(this,"_currentStartState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});_(this,"_currentEndState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const s=[],n=[],o=[];if(t==null||e==null)return{borderBoxPointGroup:s,contentBoxPointGroup:n,cursorList:o};if(!this._isValidPosition(t,e))throw new Error(`
|
|
2
|
+
Invalid positions in NodePositionConvertToCursor,
|
|
3
|
+
they are not in the same segment page when in header or footer.`);const{start:r,end:c}=ot(t,e);return this._selectionIterator(r,c,(l,u,h,g,f,m)=>{const{lineHeight:S,asc:I,paddingTop:p,marginTop:R,marginBottom:b}=m,{glyphGroup:E,st:F}=f;if(E.length===0)return;const{x:y,y:T}=this._liquid;let L,$;const C=E[l],P=E[u],D=E[l-1],x=(C==null?void 0:C.left)||0,A=(C==null?void 0:C.width)||0,O=(P==null?void 0:P.left)||0,B=(P==null?void 0:P.width)||0,w=(C==null?void 0:C.glyphType)===v.GlyphType.LIST,{startOffset:M,endOffset:G}=Bt(E,l,u,F),k=r.glyph===l&&h?r.isBack:!0,X=c.glyph===u&&g?c.isBack:!1,z=r===c,U=k&&D!=null?D:C;if(l===0&&u===E.length-1)L={startX:y+x+(w?A:0),startY:T,endX:y+O+(X?0:B),endY:T+S-R-b},$={startX:y+x+(w?A:0),startY:T+p+I-U.bBox.ba,endX:y+O+(X?0:B),endY:T+p+I+U.bBox.bd};else{const V=k&&!w;L={startX:y+x+(V?0:A),startY:T,endX:y+O+(X?0:B),endY:T+S-R-b},$={startX:y+x+(V?0:A),startY:T+p+I-U.bBox.ba,endX:y+O+(X?0:B),endY:T+p+I+U.bBox.bd}}s.push(it(L)),n.push(it($)),o.push({startOffset:k?M:M+C.count,endOffset:X?G:G+P.count,collapsed:z})}),{borderBoxPointGroup:s,contentBoxPointGroup:n,cursorList:o}}_isValidPosition(t,e){const{segmentPage:s,pageType:n}=t,{segmentPage:o,pageType:i}=e;return n!==i?!1:n===v.DocumentSkeletonPageType.HEADER||n===v.DocumentSkeletonPageType.FOOTER?s===o:!0}_resetCurrentNodePositionState(){this._currentStartState={page:0,section:0,column:0,line:0,divide:0,glyph:0},this._currentEndState={page:0,section:0,column:0,line:0,divide:0,glyph:0}}_setNodePositionState(t=0,e,s,n){n===e?this._currentStartState[t]=1:this._currentStartState[t]=0,n===s?this._currentEndState[t]=2:this._currentEndState[t]=0}_checkPreviousNodePositionState(t,e=!0){let s=t,n;for(;s>=0;){const o=Q[s];let i;if(e?i=this._currentStartState[o]:i=this._currentEndState[o],i===void 0)return;if(n===void 0&&(n=i),i!==n)return 0;s--}return n}_getSelectionRuler(t,e,s,n,o){let i=0,r=n;const c=Q[t],l=Q[t+1];if(l===null||c===null)return{start_next:i,end_next:r};const u=e[c],h=s[c];this._setNodePositionState(c,u,h,o);const g=this._checkPreviousNodePositionState(t),f=this._checkPreviousNodePositionState(t,!1);return g===1&&(i=e[l]),f===2&&(r=s[l]),{start_next:i,end_next:r}}_selectionIterator(t,e,s){var E,F;const n=this._docSkeleton;if(!n)return[];const{pageType:o,path:i}=t;this._liquid.reset();const r=n.getSkeletonData();if(r==null)return[];const{pages:c,skeHeaders:l,skeFooters:u}=r,{page:h,segmentPage:g}=t,{page:f,segmentPage:m}=e;if(this._resetCurrentNodePositionState(),this._documentOffsetConfig==null)return[];const{pageLayoutType:S,pageMarginLeft:I,pageMarginTop:p}=this._documentOffsetConfig,R=o===v.DocumentSkeletonPageType.BODY||o===v.DocumentSkeletonPageType.CELL?h:g;for(let y=0;y<R;y++){const T=c[y];this._liquid.translatePage(T,S,I,p)}const b=o===v.DocumentSkeletonPageType.BODY||o===v.DocumentSkeletonPageType.CELL?f:m;for(let y=R;y<=b;y++){const T=c[y],{headerId:L,footerId:$,pageWidth:C}=T;let P=T;if(o===v.DocumentSkeletonPageType.HEADER?P=(E=l.get(L))==null?void 0:E.get(C):o===v.DocumentSkeletonPageType.FOOTER?P=(F=u.get($))==null?void 0:F.get(C):o===v.DocumentSkeletonPageType.CELL&&(P=v.getPageFromPath(r,i)),P==null){this._liquid.translatePage(T,S,I,p);continue}const D=P.sections,{start_next:x,end_next:A}=this._getSelectionRuler(H.page,t,e,D.length-1,o===v.DocumentSkeletonPageType.BODY||o===v.DocumentSkeletonPageType.CELL?y:0);switch(this._liquid.translateSave(),o){case v.DocumentSkeletonPageType.HEADER:this._liquid.translatePagePadding({...P,marginLeft:T.marginLeft});break;case v.DocumentSkeletonPageType.FOOTER:{const O=T.pageHeight-P.height-P.marginBottom;this._liquid.translate(T.marginLeft,O);break}case v.DocumentSkeletonPageType.CELL:{this._liquid.translatePagePadding(T);const O=P.parent,B=O.parent,{left:w}=P,{top:M,left:G}=B,{top:k}=O;this._liquid.translate(G+w,M+k),this._liquid.translatePagePadding(P);break}default:this._liquid.translatePagePadding(T);break}for(let O=x;O<=A;O++){const B=D[O],w=B.columns,{start_next:M,end_next:G}=this._getSelectionRuler(H.section,t,e,w.length-1,O);this._liquid.translateSection(B);for(let k=M;k<=G;k++){const X=w[k],z=X.lines,{start_next:U,end_next:V}=this._getSelectionRuler(H.column,t,e,z.length-1,k);this._liquid.translateColumn(X);for(let Y=U;Y<=V;Y++){const tt=z[Y],{divides:ht}=tt,{start_next:gt,end_next:ft}=this._getSelectionRuler(H.line,t,e,ht.length-1,Y);this._liquid.translateSave(),this._liquid.translateLine(tt,!0,!1);for(let q=gt;q<=ft;q++){const et=ht[q];this._liquid.translateSave(),this._liquid.translateDivide(et);const{glyphGroup:bt}=et,{start_next:Et,end_next:Ot}=this._getSelectionRuler(H.divide,t,e,bt.length-1,q);let _t=!1,pt=!1;y===R&&O===x&&k===M&&Y===U&&q===gt&&(_t=!0),y===b&&O===A&&k===G&&Y===V&&q===ft&&(pt=!0),s&&s(Et,Ot,_t,pt,et,tt,X,B,P),this._liquid.translateRestore()}this._liquid.translateRestore()}}}this._liquid.translateRestore(),this._liquid.translatePage(T,S,I,p)}}}function kt(a,t){const{path:e}=a,{path:s}=t;if(e.length!==s.length||e.indexOf("cells")===-1)return!1;const n=e.indexOf("skeTables")+1,o=e.indexOf("rows")+1,i=e.indexOf("cells")+1,{tableId:r,sliceIndex:c}=v.getTableIdAndSliceIndex(e[n]),{tableId:l,sliceIndex:u}=v.getTableIdAndSliceIndex(s[n]);if(r!==l)return!1;const h=e[o],g=s[o],f=e[i],m=s[i];return!(h===g&&f===m&&c===u)}function Ct(a,t){const{path:e}=a,{path:s}=t;return e.indexOf("cells")===-1||s.indexOf("cells")===-1?!1:d.Tools.diffValue(e,s)}function Z(a,t){if(Ct(a,t))return dt(a,t);const{path:e}=a,{path:s}=t,n=e[e.length-5],o=s[s.length-5];if(n!==o&&typeof n=="string"&&typeof o=="string"){const u=n.split("#-#")[1],h=o.split("#-#")[1];return+u<+h}const i=e[e.length-3],r=s[s.length-3],c=e[e.length-1],l=s[s.length-1];return i<r?!0:i>r?!1:c<=l}function Mt(a){return a.sections[0].columns[0].lines[0].divides[0].glyphGroup[0]}function $t(a){const{sections:t}=a,e=t[t.length-1],s=e.columns[e.columns.length-1],n=s.lines[s.lines.length-1],i=n.divides[n.divides.length-1].glyphGroup;return i[i.length-2]}class xt{constructor(t,e){_(this,"_liquid",new v.Liquid);this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const s=[],o=this._docSkeleton.getSkeletonData();if(o==null)return;const{pages:i}=o,{segmentPage:r,page:c,pageType:l}=t,{segmentPage:u,page:h}=e,g=this._getTableRectRangeInfo(t,e);if(g==null)return;const{tableId:f,startRowIndex:m,startColumnIndex:S,endRowIndex:I,endColumnIndex:p}=g;this._liquid.reset();const{pageLayoutType:R,pageMarginLeft:b,pageMarginTop:E}=this._documentOffsetConfig,F=l===v.DocumentSkeletonPageType.BODY||l===v.DocumentSkeletonPageType.CELL?c:r;for(let T=0;T<F;T++){const L=i[T];this._liquid.translatePage(L,R,b,E)}const y=l===v.DocumentSkeletonPageType.BODY||l===v.DocumentSkeletonPageType.CELL?h:u;for(let T=F;T<=y;T++){const L=i[T];this._liquid.translatePagePadding(L);const{skeTables:$}=L;let C=null;for(const[x,A]of $.entries())x.startsWith(f)&&(C=A);if(C==null){this._liquid.restorePagePadding(L),this._liquid.translatePage(L,R,b,E);continue}this._liquid.translateSave(),this._liquid.translate(0,C.top);const{x:P,y:D}=this._liquid;for(const x of C.rows)if(x.index>=m&&x.index<=I){const A=x.cells[S],O=x.cells[p],B={startX:P+A.left,startY:D+x.top,endX:P+O.left+O.pageWidth,endY:D+x.top+x.height};s.push(it(B))}this._liquid.translateRestore(),this._liquid.restorePagePadding(L),this._liquid.translatePage(L,R,b,E)}return{pointGroup:s,startRow:m,startColumn:S,endRow:I,endColumn:p,tableId:f}}getNodePositionGroup(t,e){const s=[],n=Z(t,e),o=n?t:e,i=n?e:t,{segmentPage:r}=o,c=this._getTableRectRangeInfo(o,i);if(c==null)return;const{tableId:l,pages:u,startRowIndex:h,startColumnIndex:g,endRowIndex:f,endColumnIndex:m}=c,S=[];for(const p of u){const{skeTables:R}=p;for(const[b,E]of R.entries())b.startsWith(l)&&S.push(E)}if(S.length===0)return;for(const p of S)this._collectPositionGroup(p,s,h,f,g,m,r,n);const I=S[0].rows[0].cells.length;if(g===0&&m===I-1){const p=s[0],R=s[s.length-1];s.length=0,s.push({anchor:n?p.anchor:R.anchor,focus:n?R.focus:p.focus})}return s}_collectPositionGroup(t,e,s,n,o,i,r,c){for(let l=0;l<t.rows.length;l++){const u=t.rows[l];if(u.index<s)continue;if(u.index>n)break;const h=u.cells[o],g=u.cells[i],f=Mt(h),m=$t(g);if(f==null||m==null)continue;const S=this._docSkeleton.findPositionByGlyph(f,r),I=this._docSkeleton.findPositionByGlyph(m,r);if(S==null||I==null)continue;const p=c?S:I,R=c?I:S;e.push({anchor:{...p,isBack:!0},focus:{...R,isBack:!0}})}}_getTableRectRangeInfo(t,e){const n=this._docSkeleton.getSkeletonData();if(n==null)return;const{pages:o}=n,{path:i}=t,{path:r}=e,c=v.getPageFromPath(n,i),l=v.getPageFromPath(n,r);if(c==null||l==null)return;const u=c.segmentId,h=c.parent.index,g=c.parent.cells.indexOf(c),f=(l==null?void 0:l.parent).index,m=(l==null?void 0:l.parent).cells.indexOf(l);return{pages:o,tableId:u,startCell:c,endCell:l,startRowIndex:h,startColumnIndex:g,endRowIndex:f,endColumnIndex:m}}}const Ft="__TestSelectionRange__",Gt="__TestSelectionAnchor__",Rt=6,nt=500,Xt=500,rt=3;function st(a){const t=a[0],e=t[0],s=t[2],{x:n,y:o}=e,{x:i,y:r}=s;return{left:n,top:o,width:i-n,height:r-o}}class j{constructor(t,e,s,n,o,i=v.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,r="",c=-1){_(this,"rangeType",d.DOC_RANGE_TYPE.TEXT);_(this,"_current",!1);_(this,"_rangeShape");_(this,"_anchorShape");_(this,"_cursorList",[]);_(this,"_anchorBlinkTimer",null);this._scene=t,this._document=e,this._docSkeleton=s,this.anchorNodePosition=n,this.focusNodePosition=o,this.style=i,this._segmentId=r,this._segmentPage=c,this._anchorBlink(),this.refresh()}_anchorBlink(){setTimeout(()=>{this._anchorShape&&this._anchorShape.visible&&this.deactivateStatic()},nt),this._anchorBlinkTimer=setInterval(()=>{this._anchorShape&&this._anchorShape.visible&&(this.activeStatic(),setTimeout(()=>{this.deactivateStatic()},nt))},Xt+nt)}get startOffset(){var n;const{startOffset:t}=(n=mt(this._cursorList))!=null?n:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const s=e.dataStream.length-2;return Math.min(s,t)}get endOffset(){var n;const{endOffset:t}=(n=mt(this._cursorList))!=null?n:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const s=e.dataStream.length-2;return Math.min(t,s)}get collapsed(){const{startOffset:t,endOffset:e}=this;return t!=null&&t===e}get startNodePosition(){if(this.anchorNodePosition==null)return null;if(this.focusNodePosition==null)return this.anchorNodePosition;const{start:t}=ot(this.anchorNodePosition,this.focusNodePosition);return t}get endNodePosition(){if(this.anchorNodePosition==null)return this.focusNodePosition;if(this.focusNodePosition==null)return null;const{end:t}=ot(this.anchorNodePosition,this.focusNodePosition);return t}get direction(){const{collapsed:t,anchorNodePosition:e,focusNodePosition:s}=this;return t||e==null||s==null?d.RANGE_DIRECTION.NONE:dt(e,s)?d.RANGE_DIRECTION.FORWARD:d.RANGE_DIRECTION.BACKWARD}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}getAbsolutePosition(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(this._isEmpty())return;const s=this._document.getOffsetConfig(),{docsLeft:n,docsTop:o}=s,i=new St(s,this._docSkeleton);if(this._isCollapsed()){const{contentBoxPointGroup:u,cursorList:h}=i.getRangePointData(t,t);if(this._setCursorList(h),u.length===0)return;const g=st(u);return{...g,left:g.left+n,top:g.top+o}}const{borderBoxPointGroup:r,cursorList:c}=i.getRangePointData(t,e);if(this._setCursorList(c),r.length===0)return;const l=st(r);return{...l,left:l.left+n,top:l.top+o}}getAnchor(){return this._anchorShape}activeStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.strokeActive)||v.getColor(d.COLORS.black,1)})}deactivateStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.stroke)||v.getColor(d.COLORS.black,0)})}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t,e;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null,(e=this._anchorShape)==null||e.dispose(),this._anchorShape=null,this._anchorBlinkTimer&&(clearInterval(this._anchorBlinkTimer),this._anchorBlinkTimer=null)}isIntersection(t){const{startOffset:e,endOffset:s}=this,{startOffset:n,endOffset:o}=t;return e==null||s==null||n==null||o==null?!1:e<=o&&s>=n}refresh(){var h,g;const{_document:t,_docSkeleton:e}=this,s=this.anchorNodePosition,n=this.focusNodePosition;if((h=this._anchorShape)==null||h.hide(),(g=this._rangeShape)==null||g.hide(),this._isEmpty())return;const o=t.getOffsetConfig(),{docsLeft:i,docsTop:r}=o,c=new St(o,e);if(this._isCollapsed()){const{contentBoxPointGroup:f,cursorList:m}=c.getRangePointData(s,s);if(this._setCursorList(m),f.length>0){const S=e.findGlyphByPosition(s);this._createOrUpdateAnchor(f,i,r,S)}return}const{borderBoxPointGroup:l,cursorList:u}=c.getRangePointData(s,n);this._setCursorList(u),l.length>0&&this._createOrUpdateRange(l,i,r)}_isEmpty(){return this.anchorNodePosition==null&&this.focusNodePosition==null}_isCollapsed(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(t!=null&&e==null)return!0;if(t==null||e==null)return!1;const s=Object.keys(H);for(const n of s){const o=t[n],i=e[n];if(o!==i)return!1}return t.isBack===e.isBack}_createOrUpdateRange(t,e,s){var i;if(this._rangeShape){this._rangeShape.translate(e,s),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const n=.3,o=new v.RegularPolygon(Ft+d.Tools.generateRandomId(Rt),{pointsGroup:t,fill:((i=this.style)==null?void 0:i.fill)||v.getColor(d.COLORS.black,n),left:e,top:s,evented:!1,debounceParentDirty:!1});this._rangeShape=o,this._scene.addObject(o,rt)}_createOrUpdateAnchor(t,e,s,n){var S,I,p;const o=st(t),{left:i}=o;let{top:r,height:c}=o;const l=14;c<l&&(r-=l-c,c=l);const u=12;let h=i+e;const g=r+s,f=((S=n==null?void 0:n.ts)==null?void 0:S.it)===d.BooleanNumber.TRUE;if(f&&(h+=c*Math.tan(u*Math.PI/180)/2),this._anchorShape){this._anchorShape.transformByState({left:h,top:g,height:c}),this._anchorShape.show(),f?this._anchorShape.skew(-u,0):this._anchorShape.skew(0,0);return}const m=new v.Rect(Gt+d.Tools.generateRandomId(Rt),{left:h,top:g,height:c,strokeWidth:((I=this.style)==null?void 0:I.strokeWidth)||1.5,stroke:((p=this.style)==null?void 0:p.strokeActive)||v.getColor(d.COLORS.black,1),evented:!1});f&&m.skew(-u,0),this._anchorShape=m,this._scene.addObject(m,rt)}_setCursorList(t){t.length!==0&&(this._cursorList=t)}}const Ut="__DocTableRectRange__",Yt=6;function vt(a,t,e,s,n,o=v.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,i="",r=-1){const c=t.getOffsetConfig(),u=new xt(c,e).getNodePositionGroup(s,n);return(u!=null?u:[]).map(h=>new yt(a,t,e,h.anchor,h.focus,o,i,r))}class yt{constructor(t,e,s,n,o,i=v.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,r="",c=-1){_(this,"rangeType",d.DOC_RANGE_TYPE.RECT);_(this,"_rangeShape");_(this,"_current",!1);_(this,"_startRow");_(this,"_startCol");_(this,"_endRow");_(this,"_endCol");_(this,"_tableId");this._scene=t,this._document=e,this._docSkeleton=s,this.anchorNodePosition=n,this.focusNodePosition=o,this.style=i,this._segmentId=r,this._segmentPage=c,this.refresh()}get startOffset(){const{startNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get endOffset(){const{endNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get collapsed(){return!1}get startRow(){return this._startRow}get startColumn(){return this._startCol}get endRow(){return this._endRow}get endColumn(){return this._endCol}get tableId(){return this._tableId}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}get spanEntireRow(){var i;const e=(i=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:i[this._tableId],{_startCol:s,_endCol:n}=this;if(e==null)throw new Error("Table is not found.");const{tableColumns:o}=e;return s===0&&n===o.length-1}get spanEntireColumn(){var i;const e=(i=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:i[this._tableId],{_startRow:s,_endRow:n}=this;if(e==null)throw new Error("Table is not found.");const{tableRows:o}=e;return s===0&&n===o.length-1}get spanEntireTable(){return this.spanEntireRow&&this.spanEntireColumn}get startNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Z(t,e)?t:e}get endNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Z(t,e)?e:t}get direction(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Z(t,e)?d.RANGE_DIRECTION.FORWARD:d.RANGE_DIRECTION.BACKWARD}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null}isIntersection(t){const{startRow:e,startColumn:s,endRow:n,endColumn:o}=this,{startRow:i,startColumn:r,endRow:c,endColumn:l}=t,u={left:s,top:e,right:o,bottom:n},h={left:r,top:i,right:l,bottom:c};return d.Rectangle.hasIntersectionBetweenTwoRect(u,h)}refresh(){var I;(I=this._rangeShape)==null||I.hide();const{startNodePosition:t,endNodePosition:e,_document:s,_docSkeleton:n}=this,o=s.getOffsetConfig(),{docsLeft:i,docsTop:r}=o,l=new xt(o,n).getRangePointData(t,e);if(l==null)return;const{pointGroup:u=[],startRow:h,endRow:g,startColumn:f,endColumn:m,tableId:S}=l;(u==null?void 0:u.length)>0&&this._createOrUpdateRange(u,i,r),this._updateTableInfo(h,g,f,m,S)}_updateTableInfo(t,e,s,n,o){this._startRow=t,this._endRow=e,this._startCol=s,this._endCol=n,this._tableId=o}_createOrUpdateRange(t,e,s){var i;if(this._rangeShape){this._rangeShape.translate(e,s),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const n=.3,o=new v.RegularPolygon(Ut+d.Tools.generateRandomId(Yt),{pointsGroup:t,fill:((i=this.style)==null?void 0:i.fill)||v.getColor(d.COLORS.black,n),left:e,top:s,evented:!1,debounceParentDirty:!1});this._rangeShape=o,this._scene.addObject(o,rt)}}function It(a,t,e,s,n,o,i,r,c=!0,l=!0){const u=n.findNodePositionByCharIndex(a,c,i,r),h=n.findNodePositionByCharIndex(t,l,i,r);if(!(u==null||h==null))return new j(e,s,n,u,h,o,i,r)}function qt(a,t,e,s,n,o,i,r){const c=n.findNodePositionByCharIndex(a,!0,i,r),l=n.findNodePositionByCharIndex(t,!0,i,r);if(!(c==null||l==null))return new yt(e,s,n,c,l,o,i,r)}function Ht(a,t,e,s,n,o,i,r){const c=n.findNodePositionByCharIndex(a,!0,i,r),l=n.findNodePositionByCharIndex(t,!0,i,r);if(!(c==null||l==null))return at(c,l,e,s,n,o,i,r)}function at(a,t,e,s,n,o,i,r){const c=[],l=[],u=[e,s,n,a,t,o,i,r];if(Ct(a,t))return c.push(new j(...u)),{textRanges:c,rectRanges:l};if(kt(a,t)){const b=vt(...u);return l.push(...b),{textRanges:c,rectRanges:l}}const h=n.getViewModel().getSelfOrHeaderFooterViewModel(i),g=n.findCharIndexByPosition(a),f=n.findCharIndexByPosition(t);if(g==null||f==null)return;const m=g<=f?d.RANGE_DIRECTION.FORWARD:d.RANGE_DIRECTION.BACKWARD,S=Math.min(g,f),I=Math.max(g,f);let p=S,R=I;for(const b of h.children)for(const E of b.children){const{startIndex:F,endIndex:y,children:T}=E,L=T[0];let $=!1;if(L){const{startIndex:C,endIndex:P,children:D}=L;let x=null,A=null;const O=D.find(w=>w.startIndex<=S&&w.endIndex>=S),B=D.find(w=>w.startIndex<=I&&w.endIndex>=I);if(S>C&&S<P)x=n.findNodePositionByCharIndex(O.startIndex+2,!0,i,r),A=n.findNodePositionByCharIndex(P-4,!0,i,r),p=P+1;else if(I>C&&I<P)x=n.findNodePositionByCharIndex(C+3,!0,i,r),A=n.findNodePositionByCharIndex(B.endIndex-3,!0,i,r),R=C-1,$=!0;else if(C>S&&P<I){if(x=n.findNodePositionByCharIndex(C+3,!0,i,r),A=n.findNodePositionByCharIndex(P-4,!0,i,r),p<=C-1){const w=n.findNodePositionByCharIndex(p,!0,i,r),M=n.findNodePositionByCharIndex(C-1,!1,i,r),G=m===d.RANGE_DIRECTION.FORWARD?w:M,k=m===d.RANGE_DIRECTION.FORWARD?M:w;c.push(new j(e,s,n,G,k,o,i,r))}p=P+1}if(x&&A){const w=m===d.RANGE_DIRECTION.FORWARD?x:A,M=m===d.RANGE_DIRECTION.FORWARD?A:x;l.push(...vt(e,s,n,w,M,o,i,r))}}if(R>=F&&R<=y||$){const C=n.findNodePositionByCharIndex(p,!0,i,r),P=n.findNodePositionByCharIndex(R,!$,i,r),D=m===d.RANGE_DIRECTION.FORWARD?C:P,x=m===d.RANGE_DIRECTION.FORWARD?P:C;if(l.length&&d.Tools.diffValue(D,x))continue;c.push(new j(e,s,n,D,x,o,i,r))}}return{textRanges:c,rectRanges:l}}function jt(a){const t=a==null?void 0:a.getCanvasElement();if(!t)return{left:0,top:0};const{top:e,left:s}=v.getOffsetRectForDom(t);return{left:s,top:e}}function Pt(a){var c;const t=(c=a.parent)==null?void 0:c.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;const{paragraphIndex:s}=t,n=e.lines.filter(l=>l.paragraphIndex===s);let o=-1,i="",r=!1;for(const l of n)for(const u of l.divides)for(const h of u.glyphGroup)r||(o+=h.count),h===a&&(r=!0),i+=h.count>0?h.content:"";return{st:n[0].st,ed:s,content:i,nodeIndex:o}}function ct(a){const{startOffset:t,endOffset:e,collapsed:s,rangeType:n,startNodePosition:o,endNodePosition:i,direction:r,segmentId:c,segmentPage:l}=a;return{startOffset:t,endOffset:e,collapsed:s,rangeType:n,startNodePosition:o,endNodePosition:i,direction:r,segmentId:c,segmentPage:l,isActive:a.isActive()}}function Vt(a){const t=ct(a),{startRow:e,startColumn:s,endRow:n,endColumn:o,tableId:i,spanEntireRow:r,spanEntireColumn:c,spanEntireTable:l}=a;return{...t,startRow:e,startColumn:s,endRow:n,endColumn:o,tableId:i,spanEntireRow:r,spanEntireColumn:c,spanEntireTable:l}}var Wt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,zt=(a,t,e,s)=>{for(var n=s>1?void 0:s?Kt(t,e):t,o=a.length-1,i;o>=0;o--)(i=a[o])&&(n=(s?i(t,e,n):i(n))||n);return s&&n&&Wt(t,e,n),n},J=(a,t)=>(e,s)=>t(e,s,a);let lt=class extends d.RxDisposable{constructor(t,e,s,n,o){super();_(this,"_onInputBefore$",new N.Subject);_(this,"onInputBefore$",this._onInputBefore$.asObservable());_(this,"_onKeydown$",new N.Subject);_(this,"onKeydown$",this._onKeydown$.asObservable());_(this,"_onInput$",new N.Subject);_(this,"onInput$",this._onInput$.asObservable());_(this,"_onCompositionstart$",new N.BehaviorSubject(null));_(this,"onCompositionstart$",this._onCompositionstart$.asObservable());_(this,"_onCompositionupdate$",new N.BehaviorSubject(null));_(this,"onCompositionupdate$",this._onCompositionupdate$.asObservable());_(this,"_onCompositionend$",new N.BehaviorSubject(null));_(this,"onCompositionend$",this._onCompositionend$.asObservable());_(this,"_onSelectionStart$",new N.BehaviorSubject(null));_(this,"onSelectionStart$",this._onSelectionStart$.asObservable());_(this,"_onPaste$",new N.Subject);_(this,"onPaste$",this._onPaste$.asObservable());_(this,"_textSelectionInner$",new N.BehaviorSubject(null));_(this,"textSelectionInner$",this._textSelectionInner$.asObservable());_(this,"_onFocus$",new N.Subject);_(this,"onFocus$",this._onFocus$.asObservable());_(this,"_onBlur$",new N.Subject);_(this,"onBlur$",this._onBlur$.asObservable());_(this,"_onPointerDown$",new N.Subject);_(this,"onPointerDown$",this._onPointerDown$.asObservable());_(this,"_container");_(this,"_inputParent");_(this,"_input");_(this,"_scrollTimers",[]);_(this,"_rangeList",[]);_(this,"_rangeListCache",[]);_(this,"_rectRangeList",[]);_(this,"_rectRangeListCache",[]);_(this,"_anchorNodePosition",null);_(this,"_focusNodePosition",null);_(this,"_currentSegmentId","");_(this,"_currentSegmentPage",-1);_(this,"_selectionStyle",v.NORMAL_TEXT_SELECTION_PLUGIN_STYLE);_(this,"_viewPortObserverMap",new Map);_(this,"_isIMEInputApply",!1);_(this,"_scenePointerMoveSubs",[]);_(this,"_scenePointerUpSubs",[]);_(this,"_editorFocusing",!0);_(this,"_reserveRanges",!1);this._context=t,this._layoutService=e,this._logService=s,this._univerInstanceService=n,this._docSkeletonManagerService=o,this._initDOM(),this._registerContainer(),this._setSystemHighlightColorToStyle(),this._listenCurrentUnitChange()}_listenCurrentUnitChange(){this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_DOC).pipe(N.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;t.getUnitId()!==this._context.unitId&&!this._reserveRanges&&this.removeAllRanges()})}get activeViewPort(){return this._context.scene.getViewports()[0]}setSegment(t){this._currentSegmentId=t}getSegment(){return this._currentSegmentId}setSegmentPage(t){this._currentSegmentPage=t}getSegmentPage(){return this._currentSegmentPage}setReserveRangesStatus(t){this._reserveRanges=t}_setRangeStyle(t=v.NORMAL_TEXT_SELECTION_PLUGIN_STYLE){this._selectionStyle=t}addDocRanges(t,e=!0,s){const{_currentSegmentId:n,_currentSegmentPage:o,_selectionStyle:i}=this,{scene:r,mainComponent:c}=this._context,l=c,u=this._docSkeletonManagerService.getSkeleton();for(const h of t){const{startOffset:g,endOffset:f,rangeType:m,startNodePosition:S,endNodePosition:I}=h;if(m===d.DOC_RANGE_TYPE.RECT){const p=qt(g,f,r,l,u,i,n,o);p&&this._addRectRanges([p])}else if(m===d.DOC_RANGE_TYPE.TEXT){let p=null;S&&I?p=It(S.isBack?g:g-1,I.isBack?f:f-1,r,l,u,i,n,o,S.isBack,I.isBack):p=It(g,f,r,l,u,i,n,o),p&&this._addTextRange(p)}else{const p=Ht(g,f,r,l,u,i,n,o);if(p==null)continue;const{textRanges:R,rectRanges:b}=p;for(const E of R)this._addTextRange(E);this._addRectRanges(b)}}this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:n,segmentPage:o,style:i,isEditing:e,options:s}),this._updateInputPosition(s==null?void 0:s.forceFocus)}setCursorManually(t,e){const s=this._findNodeByCoord(t,e,{strict:!0,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),n=this._getNodePosition(s);if(n==null){this._removeAllRanges();return}(s==null?void 0:s.node.streamType)===d.DataStreamTreeTokenType.PARAGRAPH&&(n.isBack=!0),this._createTextRangeByAnchorPosition(n),this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1})}sync(){this._updateInputPosition()}activate(t,e,s=!1){const n=this._input===document.activeElement||document.activeElement===document.body||document.activeElement===null;this._container.style.left=`${t}px`,this._container.style.top=`${e}px`,this._container.style.zIndex="1000",(n||s)&&this.focus()}hasFocus(){return document.activeElement===this._input}focus(){this._editorFocusing&&this._input.focus()}blur(){this._input.blur()}focusEditor(){this._editorFocusing=!0,this.focus()}blurEditor(){this._editorFocusing=!1,this.blur()}deactivate(){this._container.style.left="0px",this._container.style.top="0px"}__handleDblClick(t){const{offsetX:e,offsetY:s}=t,n=this._findNodeByCoord(e,s,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(n==null||n.node==null)return;const o=Pt(n.node);if(o==null)return;const{content:i,st:r,nodeIndex:c}=o;if(c===-1||Intl.Segmenter==null)return;const u=new Intl.Segmenter(void 0,{granularity:"word"}).segment(i);let h=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;for(const{segment:f,index:m,isWordLike:S}of u)if(m<=c&&c<m+f.length&&S){h=m+r,g=m+r+f.length;break}if(Number.isFinite(h)&&Number.isFinite(g)){this.removeAllRanges();const f=[{startOffset:h,endOffset:g}];this.addDocRanges(f,!1,{forceFocus:!0})}}__handleTripleClick(t){const{offsetX:e,offsetY:s}=t,n=this._findNodeByCoord(e,s,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(n==null||n.node==null)return;const o=Pt(n.node);if(o==null)return;this.removeAllRanges();const{st:i,ed:r}=o,c=[{startOffset:i,endOffset:r}];this.addDocRanges(c,!1,{forceFocus:!0})}__onPointDown(t){var S,I;this._editorFocusing=!0;const{scene:e,mainComponent:s}=this._context,n=this._docSkeletonManagerService.getSkeleton(),{offsetX:o,offsetY:i}=t,r=this._findNodeByCoord(o,i,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),c=this._getNodePosition(r);if(c==null||r==null){this._removeAllRanges();return}(r==null?void 0:r.node.streamType)===d.DataStreamTreeTokenType.PARAGRAPH&&(c.isBack=!0);const l=this._textSelectionInner$.value;if(r&&t.button===2&&l){const p=n.findCharIndexByPosition(c);if(typeof p=="number"&&l.textRanges.some(R=>R.startOffset<=p&&R.endOffset>p)||typeof p=="number"&&l.rectRanges.some(R=>R.startOffset<=p&&R.endOffset>=p))return}const{segmentId:u,segmentPage:h}=r;u&&this._currentSegmentId&&u!==this._currentSegmentId&&this.setSegment(u),u&&h!==this._currentSegmentPage&&this.setSegmentPage(h),this._anchorNodePosition=c,t.shiftKey&&this._getActiveRangeInstance()?this._updateActiveRangePosition(c):t.ctrlKey?this._removeAllCollapsedTextRanges():this._isEmpty()||this._removeAllRanges(),e.disableObjectsEvent();const g=v.ScrollTimer.create(e);this._scrollTimers.push(g),g.startScroll(o,i),this._onSelectionStart$.next((S=this._getActiveRangeInstance())==null?void 0:S.startNodePosition),(I=e.getTransformer())==null||I.clearSelectedObjects();let f=o,m=i;this._scenePointerMoveSubs.push(e.onPointerMove$.subscribeEvent(p=>{const{offsetX:R,offsetY:b}=p;e.setCursor(v.CURSOR_TYPE.TEXT),!(Math.sqrt((R-f)**2+(b-m)**2)<3)&&(this._moving(R,b),g.scrolling(R,b,()=>{this._moving(R,b)}),f=R,m=b)})),this._scenePointerUpSubs.push(e.onPointerUp$.subscribeEvent(()=>{if([...this._scenePointerMoveSubs,...this._scenePointerUpSubs].forEach(R=>{R.unsubscribe()}),e.enableObjectsEvent(),this._anchorNodePosition&&!this._focusNodePosition){if(t.ctrlKey){this._disposeScrollTimers();return}const R=new j(e,s,n,this._anchorNodePosition,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(R)}else if(this._anchorNodePosition&&this._focusNodePosition){for(const R of this._rangeListCache)t.ctrlKey?R.collapsed?R.dispose():this._addTextRange(R):this._addTextRange(R);this._addRectRanges(this._rectRangeListCache),this._rangeListCache=[],this._rectRangeListCache=[]}this._anchorNodePosition=null,this._focusNodePosition=null;const p={textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1};this._textSelectionInner$.next(p),this._disposeScrollTimers(),this._updateInputPosition(!0)}))}removeAllRanges(){this._removeAllRanges(),this.deactivate()}getActiveTextRange(){return this._getActiveRangeInstance()}_disposeScrollTimers(){this._scrollTimers.forEach(t=>{t==null||t.dispose()}),this._scrollTimers=[]}_setSystemHighlightColorToStyle(){const{r:t,g:e,b:s,a:n}=v.getSystemHighlightColor(),o={strokeWidth:1.5,stroke:"rgba(0, 0, 0, 0)",strokeActive:"rgba(0, 0, 0, 1)",fill:`rgba(${t}, ${e}, ${s}, ${n!=null?n:.3})`};this._setRangeStyle(o)}_getAllTextRanges(){return this._rangeList.map(ct)}_getAllRectRanges(){return this._rectRangeList.map(Vt)}_getActiveRange(){const t=this._rangeList.find(n=>n.isActive());if(t==null)return null;const{startOffset:e,endOffset:s}=t;return e==null||s==null?null:ct(t)}_getActiveRangeInstance(){return this._rangeList.find(t=>t.isActive())}dispose(){super.dispose(),this._detachEvent(),this._removeAllRanges(),this._container.remove()}_initDOM(){const{unitId:t}=this._context,e=document.createElement("div");e.style.position="fixed",e.style.left="0px",e.style.top="0px",e.id=`univer-doc-selection-container-${t}`;const s=document.createElement("div"),n=document.createElement("div");s.appendChild(n),e.appendChild(s),this._container=e,this._inputParent=s,this._input=n,this._initInput(),this._initInputEvents(),document.body.appendChild(e)}_registerContainer(){this.disposeWithMe(this._layoutService.registerContainerElement(this._container))}_initInput(){this._inputParent.style.cssText=`
|
|
4
|
+
position:absolute;
|
|
5
|
+
height:1px;
|
|
6
|
+
width:1px;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
`,this._input.contentEditable="true",this._input.classList.add("univer-editor"),this._input.style.cssText=`
|
|
9
|
+
position: absolute;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
opacity: 1;
|
|
12
|
+
background: #000;
|
|
13
|
+
color: transparent;
|
|
14
|
+
outline: none;
|
|
15
|
+
z-index: -2;
|
|
16
|
+
caret-color: transparent;
|
|
17
|
+
white-space: pre-wrap;
|
|
18
|
+
user-select: text;
|
|
19
|
+
`}_getNodePosition(t){if(t==null)return;const{node:e,ratioX:s,segmentPage:n}=t,i=this._docSkeletonManagerService.getSkeleton().findPositionByGlyph(e,n);if(i==null)return;const c=s<.5;return{...i,isBack:c}}_interactTextRanges(t){const e=[];for(const s of this._rangeList){if(t.some(n=>n.isIntersection(s))){s.dispose();continue}e.push(s)}this._rangeList=e}_interactRectRanges(t){const e=[];for(const s of this._rectRangeList){if(t.some(n=>n.isIntersection(s))){s.dispose();continue}e.push(s)}this._rectRangeList=e}_removeCollapsedTextRange(){const t=this._rangeList;this._rangeList=[];for(const e of t)e.collapsed?e.dispose():this._rangeList.push(e)}_removeAllRanges(){this._removeAllTextRanges(),this._removeAllRectRanges()}_removeAllCacheRanges(){this._rangeListCache.forEach(t=>{t.dispose()}),this._rectRangeListCache.forEach(t=>{t.dispose()}),this._rangeListCache=[],this._rectRangeListCache=[]}_removeAllTextRanges(){this._rangeList.forEach(t=>{t.dispose()}),this._rangeList=[]}_removeAllRectRanges(){this._rectRangeList.forEach(t=>{t.dispose()}),this._rectRangeList=[]}_removeAllCollapsedTextRanges(){for(const t of this._rangeList)t.collapsed&&t.dispose()}_deactivateAllTextRanges(){this._rangeList.forEach(t=>{t.deactivate()})}_deactivateAllRectRanges(){this._rectRangeList.forEach(t=>{t.deactivate()})}_addTextRangesToCache(t){this._rangeListCache.push(...t)}_addTextRange(t){this._deactivateAllTextRanges(),t.activate(),this._rangeList.push(t)}_addRectRangesToCache(t){this._rectRangeListCache.push(...t)}_addRectRanges(t){t.length!==0&&(this._deactivateAllRectRanges(),t[t.length-1].activate(),this._rectRangeList.push(...t))}_createTextRangeByAnchorPosition(t){this._removeAllRanges();const{scene:e,mainComponent:s}=this._context,n=this._docSkeletonManagerService.getSkeleton(),o=new j(e,s,n,t,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(o)}_updateActiveRangePosition(t){const e=this._getActiveRangeInstance();if(e==null||e.anchorNodePosition==null){this._logService.error("[DocSelectionRenderService] _updateActiveRangeFocusPosition: active range has no anchor");return}this._removeAllRanges(),this._anchorNodePosition=e.anchorNodePosition,this._focusNodePosition=t;const{scene:s,mainComponent:n}=this._context,o=this._docSkeletonManagerService.getSkeleton(),{_anchorNodePosition:i,_focusNodePosition:r,_selectionStyle:c,_currentSegmentId:l,_currentSegmentPage:u}=this;if(i==null||r==null||n==null)return;const h=at(i,r,s,n,o,c,l,u);if(h==null)return;const{textRanges:g,rectRanges:f}=h;this._addTextRangesToCache(g),this._addRectRangesToCache(f),this.deactivate()}_isEmpty(){return this._rangeList.length===0&&this._rectRangeList.length===0}_getCanvasOffset(){var e;const t=(e=this._context.scene)==null?void 0:e.getEngine();return jt(t)}_updateInputPosition(t=!1){const e=this._getActiveRangeInstance(),s=e==null?void 0:e.getAnchor();if(!s||s&&!s.visible||this.activeViewPort==null){this.focus();return}const{left:n,top:o}=s,i=this.activeViewPort.getAbsoluteVector(v.Vector2.FromArray([n,o])),{x:r,y:c}=i;let{left:l,top:u}=this._getCanvasOffset();l+=r,u+=c,this.activate(l,u,t)}_moving(t,e){var p,R;const{_currentSegmentId:s,_currentSegmentPage:n}=this,o=this._findNodeByCoord(t,e,{strict:!0,segmentId:s,segmentPage:n}),i=this._getNodePosition(o);if(i==null||o==null)return;const r=o==null?void 0:o.node.parent,c=r==null?void 0:r.glyphGroup[r.glyphGroup.indexOf(o.node)+1];(o==null?void 0:o.node.streamType)===d.DataStreamTreeTokenType.PARAGRAPH&&(c==null?void 0:c.streamType)===d.DataStreamTreeTokenType.SECTION_BREAK&&(i.isBack=!0),this._focusNodePosition=i,this._removeAllCacheRanges();const{_anchorNodePosition:l,_selectionStyle:u}=this,{scene:h,mainComponent:g}=this._context,f=this._docSkeletonManagerService.getSkeleton();if(l==null||g==null)return;const m=at(l,i,h,g,f,u,s,n);if(m==null)return;const{textRanges:S,rectRanges:I}=m;this._rangeList.length>0&&S.length>0&&this._interactTextRanges(S),this._rectRangeList.length>0&&I.length>0&&this._interactRectRanges(I),this._addTextRangesToCache(S),this._addRectRangesToCache(I),this.deactivate(),(R=(p=this._context.scene)==null?void 0:p.getEngine())==null||R.setRemainCapture()}__attachScrollEvent(){const t=this.activeViewPort;if(!t)return;const{unitId:e}=this._context;if(this._viewPortObserverMap.has(e))return;const s=t.onScrollAfter$.subscribeEvent(o=>{if(!o.viewport)return;const r=this._getActiveRangeInstance();r==null||r.activeStatic()}),n=t.onScrollEnd$.subscribeEvent(o=>{const i=o.viewport;if(!i)return;const r=i.getBounding(),c=this._getActiveRangeInstance(),l=c==null?void 0:c.getAnchor();if(!(!l||l&&!l.visible)){if(r){const{left:u,top:h,right:g,bottom:f}=r.viewBound;if(l.left<u||l.left>g||l.top<h||l.top>f){c==null||c.deactivateStatic();return}}this._updateInputPosition()}});this._viewPortObserverMap.set(e,{scrollBefore:s,scrollStop:n})}_initInputEvents(){this.disposeWithMe(N.fromEvent(this._input,"keydown").subscribe(t=>{this._isIMEInputApply||this._eventHandle(t,e=>{this._onKeydown$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"input").subscribe(t=>{if(!(t.inputType==="historyUndo"||t.inputType==="historyRedo")){if(this._rectRangeList.length>0)return t.stopPropagation(),t.preventDefault();this._isIMEInputApply||this._eventHandle(t,e=>{this._onInputBefore$.next(e),this._onInput$.next(e)})}})),this.disposeWithMe(N.fromEvent(this._input,"compositionstart").subscribe(t=>{if(this._rectRangeList.length>0)return t.stopPropagation(),t.preventDefault();this._isIMEInputApply=!0,this._eventHandle(t,e=>{this._onCompositionstart$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"compositionend").subscribe(t=>{this._isIMEInputApply=!1,this._eventHandle(t,e=>{this._onCompositionend$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"compositionupdate").subscribe(t=>{this._eventHandle(t,e=>{this._onInputBefore$.next(e),this._onCompositionupdate$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"paste").subscribe(t=>{this._eventHandle(t,e=>{this._onPaste$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"focus").subscribe(t=>{this._eventHandle(t,e=>{this._onFocus$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"blur").subscribe(t=>{this._eventHandle(t,e=>{this._onBlur$.next(e)})}))}_eventHandle(t,e){const s=this._input.textContent||"";this._input.innerHTML="";const n=this._getActiveRange(),o=this._getAllTextRanges();e({event:t,content:s,activeRange:n,rangeList:o})}_getTransformCoordForDocumentOffset(t,e){const s=this._context.mainComponent,{documentTransform:n}=s.getOffsetConfig();if(this.activeViewPort==null||n==null)return;const o=this.activeViewPort.transformVector2SceneCoord(v.Vector2.FromArray([t,e]));if(o)return n.clone().invert().applyPoint(o)}_findNodeByCoord(t,e,s){const n=this._getTransformCoordForDocumentOffset(t,e);if(n==null)return;const o=this._context.mainComponent,i=this._docSkeletonManagerService.getSkeleton(),{pageLayoutType:r=v.PageLayoutType.VERTICAL,pageMarginLeft:c,pageMarginTop:l}=o.getOffsetConfig();return i.findNodeByCoord(n,r,c,l,s)}_detachEvent(){this._onInputBefore$.complete(),this._onKeydown$.complete(),this._onInput$.complete(),this._onCompositionstart$.complete(),this._onCompositionupdate$.complete(),this._onCompositionend$.complete(),this._onSelectionStart$.complete(),this._textSelectionInner$.complete(),this._onPaste$.complete(),this._onFocus$.complete(),this._onBlur$.complete(),this._onPointerDown$.complete()}};lt=zt([J(1,At.ILayoutService),J(2,d.ILogService),J(3,d.IUniverInstanceService),J(4,d.Inject(K.DocSkeletonManagerService))],lt);var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,Zt=(a,t,e,s)=>{for(var n=s>1?void 0:s?Qt(t,e):t,o=a.length-1,i;o>=0;o--)(i=a[o])&&(n=(s?i(t,e,n):i(n))||n);return s&&n&&Jt(t,e,n),n},W=(a,t)=>(e,s)=>t(e,s,a);exports.FDocument=class{constructor(t,e,s,n,o,i){_(this,"id");this._documentDataModel=t,this._injector=e,this._univerInstanceService=s,this._commandService=n,this._resourceManagerService=o,this._renderManagerService=i,this.id=this._documentDataModel.getUnitId()}getId(){return this._documentDataModel.getUnitId()}getName(){return this.getSnapshot().title||""}getSnapshot(){const t=this._resourceManagerService.getResourcesByType(this.id,d.UniverInstanceType.UNIVER_DOC),e=this._documentDataModel.getSnapshot();return e.resources=t,e}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(d.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(d.RedoCommand.id)}appendText(t){const e=this.id,{body:s}=this.getSnapshot();if(!s)throw new Error("The document body is empty");const n=s.dataStream.length-2,o={startOffset:n,endOffset:n,collapsed:!0,segmentId:""},{segmentId:i}=o;return this._commandService.executeCommand(Dt.id,{unitId:e,body:{dataStream:t},range:o,segmentId:i})}setSelection(t,e){var n;const s=(n=this._renderManagerService.getRenderById(this.getId()))==null?void 0:n.with(lt);s==null||s.removeAllRanges(),s==null||s.addDocRanges([{startOffset:t,endOffset:e,rangeType:d.DOC_RANGE_TYPE.TEXT}],!0)}};exports.FDocument=Zt([W(1,d.Inject(d.Injector)),W(2,d.IUniverInstanceService),W(3,d.ICommandService),W(4,d.IResourceManagerService),W(5,v.IRenderManagerService)],exports.FDocument);class te extends d.FUniver{createUniverDoc(t){const e=this._univerInstanceService.createUnit(d.UniverInstanceType.UNIVER_DOC,t);return this._injector.createInstance(exports.FDocument,e)}getActiveDocument(){const t=this._univerInstanceService.getCurrentUnitForType(d.UniverInstanceType.UNIVER_DOC);return t?this._injector.createInstance(exports.FDocument,t):null}getUniverDoc(t){const e=this._univerInstanceService.getUniverDocInstance(t);return e?this._injector.createInstance(exports.FDocument,e):null}}d.FUniver.extend(te);
|