@univerjs/docs-ui 0.7.0-beta.0 → 0.7.0-beta.1
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/index.js +5 -7
- package/lib/es/index.js +156 -158
- package/lib/index.css +1 -1
- package/lib/index.js +156 -158
- package/lib/umd/index.js +5 -7
- package/package.json +12 -12
package/lib/umd/index.js
CHANGED
|
@@ -39,16 +39,15 @@ ${s.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
39
39
|
`)||(o+=`\r
|
|
40
40
|
`,e.push({startIndex:o.length-2}),n.push({startIndex:o.length-1}),t.dataStream=o,t.paragraphs=e,t.sectionBreaks=n);const a={html:""},r=_.parseDataStreamToTree(o).sectionList;for(const c of r)et(c,i,a);return a.html}function et(i,t,e){var n,o;switch(i.nodeType){case s.DataStreamTreeNodeType.SECTION_BREAK:{for(const a of i.children)et(a,t,e);break}case s.DataStreamTreeNodeType.PARAGRAPH:{const{children:a,startIndex:r,endIndex:c}=i,l=(o=(n=t.body)==null?void 0:n.paragraphs.find(g=>g.startIndex===c))!=null?o:{},{paragraphStyle:A={}}=l,{spaceAbove:d,spaceBelow:u,lineSpacing:m}=A,h=[];if(d!=null&&(typeof d=="number"?h.push(`margin-top: ${d}px`):h.push(`margin-top: ${d.v}px`)),u!=null&&(typeof u=="number"?h.push(`margin-bottom: ${u}px`):h.push(`margin-bottom: ${u.v}px`)),m!=null&&h.push(`line-height: ${m}`),e.html+=`<p class="UniverNormal" ${h.length?`style="${h.join("; ")};"`:""}>`,a.length)for(const g of a)et(g,t,e);e.html+=`${Xr(t,r,c)}</p>`;break}case s.DataStreamTreeNodeType.TABLE:{const{children:a}=i;e.html+='<table class="UniverTable" style="width: 100%; border-collapse: collapse;"><tbody>';for(const r of a)et(r,t,e);e.html+="</tbody></table>";break}case s.DataStreamTreeNodeType.TABLE_ROW:{const{children:a}=i;e.html+='<tr class="UniverTableRow">';for(const r of a)et(r,t,e);e.html+="</tr>";break}case s.DataStreamTreeNodeType.TABLE_CELL:{const{children:a}=i;e.html+='<td class="UniverTableCell">';for(const r of a)et(r,t,e);e.html+="</td>";break}default:throw new Error(`Unknown node type: ${i.nodeType}`)}}class Kr{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");let e="";for(const n of s.Tools.deepClone(t))e+=fs(n);return e}}var Yr=Object.getOwnPropertyDescriptor,qr=(i,t,e,n)=>{for(var o=n>1?void 0:n?Yr(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},ft=(i,t)=>(e,n)=>t(e,n,i);$e.use(ms),$e.use(us),$e.use(gs);function Ss(i,t,e){var a,r,c;const n=s.getBodySlice(i,t,e+2),o=s.DataStreamTreeTokenType.TABLE_START+s.DataStreamTreeTokenType.TABLE_ROW_START+s.DataStreamTreeTokenType.TABLE_CELL_START+n.dataStream+s.DataStreamTreeTokenType.TABLE_CELL_END+s.DataStreamTreeTokenType.TABLE_ROW_END+s.DataStreamTreeTokenType.TABLE_END;return n.dataStream=o,(a=n.textRuns)==null||a.forEach(l=>{const{st:A,ed:d}=l;l.st=A+3,l.ed=d+3}),(r=n.tables)==null||r.forEach(l=>{const{startIndex:A,endIndex:d}=l;l.startIndex=A+3,l.endIndex=d+3}),(c=n.paragraphs)==null||c.forEach(l=>{const{startIndex:A}=l;l.startIndex=A+3}),n}const xe=s.createIdentifier("doc.clipboard-service");let ui=class extends s.Disposable{constructor(t,e,n,o,a){super();B(this,"_clipboardHooks",[]);B(this,"_htmlToUDM",new $e);B(this,"_umdToHtml",new Kr);this._univerInstanceService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=o,this._docSelectionManagerService=a}async copy(t=s.SliceBodyType.copy,e){var c,l;const{newSnapshotList:n=[],needCache:o=!1,snapshot:a,ranges:r}=(c=this._getDocumentBodyInRanges(t,e))!=null?c:{};if(n.length===0||a==null)return!1;try{const A=!!((l=r==null?void 0:r[0])!=null&&l.segmentId);this._setClipboardData(n,!A&&o)}catch(A){return this._logService.error("[DocClipboardService] copy failed",A),!1}return!0}async cut(t){return this._cut(t)}async paste(t){const e=await this._genDocDataFromClipboardItems(t);return this._paste(e)}async legacyPaste(t){let{html:e,text:n,files:o}=t;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),r=(a==null?void 0:a.getUnitId())||"";!e&&!n&&o.length&&(e=await this._createImagePasteHtml(o));const c=this._genDocDataFromHtmlAndText(e,n,r);if(r===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)if(n){const l=s.BuildTextUtils.transform.fromPlainText(n);return this._paste({body:l})}else c.body.textRuns=[];return this._paste(c)}async _cut(t){var c,l,A,d,u;const e=(l=(c=t==null?void 0:t.filter(m=>m.rangeType===s.DOC_RANGE_TYPE.TEXT))!=null?c:this._docSelectionManagerService.getTextRanges())!=null?l:[],n=(d=(A=t==null?void 0:t.filter(m=>m.rangeType===s.DOC_RANGE_TYPE.RECT))!=null?A:this._docSelectionManagerService.getRectRanges())!=null?d:[],{segmentId:o,endOffset:a,style:r}=(u=e[0])!=null?u:{};if(o==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),e.length===0&&n.length===0)return!1;this.copy(s.SliceBodyType.cut,t);try{let m=0;if(n.length>0)m=Zt(e,n);else if(a!=null){m=a;for(const g of e){const{startOffset:p,endOffset:f}=g;p==null||f==null||f<=a&&(m-=f-p)}}const h=[{startOffset:m,endOffset:m,style:r}];return this._commandService.executeCommand(Ve.id,{segmentId:o,textRanges:h,rectRanges:n,selections:e})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var d,u,m;const{body:e}=t;if(e==null)return!1;let n=s.normalizeBody(e);if(!((d=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC))==null?void 0:d.getUnitId()))return!1;this._clipboardHooks.forEach(h=>{h.onBeforePaste&&(n=h.onBeforePaste(n))}),n.customRanges=(u=n.customRanges)==null?void 0:u.map(s.BuildTextUtils.customRange.copyCustomRange),(m=n.paragraphs)==null||m.forEach(h=>{var g;(g=h.paragraphStyle)!=null&&g.headingId&&(h.paragraphStyle.headingId=s.generateRandomId(6))});const a=this._docSelectionManagerService.getActiveTextRange(),{segmentId:r,endOffset:c,style:l}=a||{},A=this._docSelectionManagerService.getTextRanges();if(r==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),c==null||A==null)return!1;try{let h=c;for(const p of A){const{startOffset:f,endOffset:S}=p;f==null||S==null||S<=c&&(h+=n.dataStream.length-(S-f))}const g=[{startOffset:h,endOffset:h,style:l}];return this._commandService.executeCommand(oi.id,{doc:{...t,body:n},segmentId:r,textRanges:g})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t,e=!0){var r,c,l,A;const n=Vr(),o=(t.length>1?t.map(d=>{var u;return((u=d.body)==null?void 0:u.dataStream)||""}).join(`
|
|
41
41
|
`):((r=t[0].body)==null?void 0:r.dataStream)||"").replaceAll(s.DataStreamTreeTokenType.TABLE_START,"").replaceAll(s.DataStreamTreeTokenType.TABLE_END,"").replaceAll(s.DataStreamTreeTokenType.TABLE_ROW_START,"").replaceAll(s.DataStreamTreeTokenType.TABLE_ROW_END,"").replaceAll(s.DataStreamTreeTokenType.TABLE_CELL_START,"").replaceAll(s.DataStreamTreeTokenType.TABLE_CELL_END,"").replaceAll(`\r
|
|
42
|
-
`," ");let a=this._umdToHtml.convert(t);if(t.length===1&&e){a=a.replace(/(<[a-z]+)/,(m,h)=>`${h} data-copy-id="${n}"`);const d=t[0],u={body:d.body};if((l=(c=d.body)==null?void 0:c.customBlocks)!=null&&l.length){u.drawings={};for(const m of d.body.customBlocks){const{blockId:h}=m,g=(A=d.drawings)==null?void 0:A[h];if(g){const p=s.Tools.generateRandomId(6);m.blockId=p,u.drawings[p]={...s.Tools.deepClone(g),drawingId:p}}}}li.set(n,u)}return this._clipboardInterfaceService.write(o,a)}addClipboardHook(t){return this._clipboardHooks.push(t),s.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),o=e!=null?e:this._docSelectionManagerService.getDocRanges(),a=[];let r=!0;if(n==null||o.length===0)return;const c=o[0].segmentId,l=(d=n==null?void 0:n.getSelfOrHeaderFooterModel(c))==null?void 0:d.getBody(),A=n.getSnapshot();if(l!=null){for(const u of o){const{startOffset:m,endOffset:h,collapsed:g,rangeType:p}=u;if(g||m==null||h==null)continue;if(p===s.DOC_RANGE_TYPE.RECT){r=!1;const{spanEntireRow:E}=u;let C;C=Ss(l,m,h),a.push(C);continue}const f={startOffset:m,endOffset:h},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&a.push(S)}return{newSnapshotList:a.map(u=>({...A,body:u})),needCache:r,snapshot:A,ranges:o}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const o=[];for(const a of t)for(const r of a.types)switch(r){case v.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await a.getType(r).then(c=>c&&c.text());break}case v.HTML_CLIPBOARD_MIME_TYPE:{e=await a.getType(r).then(c=>c&&c.text());break}case v.FILE__BMP_CLIPBOARD_MIME_TYPE:case v.FILE__JPEG_CLIPBOARD_MIME_TYPE:case v.FILE__WEBP_CLIPBOARD_MIME_TYPE:case v.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await a.getType(r),l=new File([c],`pasted_image.${r.split("/")[1]}`,{type:r});o.push(l);break}}return!e&&!n&&o.length&&(e=await this._createImagePasteHtml(o)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:s.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const o=Wr(t);if(o){const r=li.get(o);if(r)return r}if(!n){const r=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);n=(r==null?void 0:r.getUnitId())||""}const a=this._htmlToUDM.convert(t,{unitId:n});return o&&li.set(o,a),a}async _createImagePasteHtml(t){var c,l;const e={id:"",documentStyle:{},body:{dataStream:"",customBlocks:[]},drawings:{}},n=async A=>{const d=new FileReader;return new Promise(u=>{d.onloadend=function(){u({source:d.result,imageSourceType:Dn.ImageSourceType.BASE64})},d.readAsDataURL(A)})},o=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const h=Math.min(u,d.naturalWidth),g=d.naturalHeight/d.naturalWidth;m({width:h,height:h*g})}})},a=(l=(c=this._clipboardHooks.find(A=>A.onBeforePasteImage))==null?void 0:c.onBeforePasteImage)!=null?l:n;return await Promise.all(t.map(async(A,d)=>{var S;const u=await a(A);if(!u)return Promise.resolve();const{width:m=100,height:h=100}=await o(A),g=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:g}),f[g]={drawingId:g,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:s.PositionedObjectLayoutType.INLINE,drawingType:s.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:h,angle:0},docTransform:{angle:0,size:{width:m,height:h},positionH:{relativeFrom:s.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:s.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};ui=qr([ft(0,s.IUniverInstanceService),ft(1,s.ILogService),ft(2,s.ICommandService),ft(3,v.IClipboardInterfaceService),ft(4,s.Inject(D.DocSelectionManagerService))],ui);function $t(i){return i.getContextValue(s.FOCUSING_DOC)||i.getContextValue(s.EDITOR_ACTIVATED)}const hi=999,St={id:v.CopyCommand.id,name:"doc.command.copy",type:s.CommandType.COMMAND,multi:!0,priority:hi,preconditions:$t,handler:async i=>i.get(xe).copy()},gi={id:"doc.command.copy-current-paragraph",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(xe),e=mt(i);return e?t.copy(s.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},en={id:v.CutCommand.id,name:"doc.command.cut",type:s.CommandType.COMMAND,multi:!0,priority:hi,preconditions:$t,handler:async i=>i.get(xe).cut()},mi={id:"doc.command.cut-current-paragraph",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(xe),e=mt(i);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:s.DOC_RANGE_TYPE.TEXT}]):!1}},tn={id:v.PasteCommand.id,name:"doc.command.paste",type:s.CommandType.COMMAND,multi:!0,priority:hi,preconditions:$t,handler:async i=>{const t=i.get(xe),n=await i.get(v.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var Jr=Object.getOwnPropertyDescriptor,Zr=(i,t,e,n)=>{for(var o=n>1?void 0:n?Jr(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},pi=(i,t)=>(e,n)=>t(e,n,i);const $r=11,ec=9,nn={ff:"Arial",fs:$r};let Te=class extends s.Disposable{constructor(t,e,n){super();B(this,"_cacheStyle",null);this._textSelectionManagerService=t,this._univerInstanceService=e,this._renderManagerService=n,this._init()}_init(){this._listenDocRangeChange()}_listenDocRangeChange(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(()=>{this._clearStyleCache()}))}getStyleCache(){return this._cacheStyle}getDefaultStyle(){var r;const t=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(t==null)return{...nn};const e=t==null?void 0:t.getUnitId(),n=(r=this._renderManagerService.getRenderById(e))==null?void 0:r.with(D.DocSkeletonManagerService),o=n==null?void 0:n.getViewModel();return o==null?{...nn}:o.getEditArea()===_.DocumentEditArea.BODY?{...nn}:{...nn,fs:ec}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};Te=Zr([pi(0,s.Inject(D.DocSelectionManagerService)),pi(1,s.IUniverInstanceService),pi(2,_.IRenderManagerService)],Te);function fi(i,t,e){const n=[];for(let o=0,a=i.length;o<a;o++)i[o]===s.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:o});if(t)for(const o of n)t.bullet&&(o.bullet=s.Tools.deepClone(t.bullet)),t.paragraphStyle&&(o.paragraphStyle=s.Tools.deepClone(t.paragraphStyle),delete o.paragraphStyle.borderBottom,t.paragraphStyle.headingId&&(o.paragraphStyle.headingId=s.generateRandomId(6)));if(e)for(const o of n)o.paragraphStyle||(o.paragraphStyle={}),o.paragraphStyle.borderBottom=e;return n}const on={id:"doc.command.break-line",type:s.CommandType.COMMAND,handler:(i,t)=>{var Q,j,G,k,W;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),a=i.get(Te),r=(Q=t==null?void 0:t.textRange)!=null?Q:e.getActiveTextRange(),c=e.getRectRanges();if(r==null)return!1;if(c&&c.length){const{startOffset:z}=r;return e.replaceDocRanges([{startOffset:z,endOffset:z}]),!0}const{horizontalLine:l}=t!=null?t:{},{segmentId:A}=r,d=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A!=null?A:"").getBody();if(d==null||u==null)return!1;const m=d.getUnitId(),{startOffset:h,endOffset:g}=r,f=((j=u.paragraphs)!=null?j:[]).find(z=>z.startIndex>=h);if(!f)return!1;const S=h===f.startIndex,E=f.startIndex,C=a.getDefaultStyle(),b=a.getStyleCache(),R=Qt(u,g,C,b),I={dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:fi(s.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...R.ts}}]};if(d==null)return!1;const O=e.getActiveTextRange();if(u==null)return!1;const{collapsed:M}=r,y=I.dataStream.length,N=[{startOffset:h+y,endOffset:h+y,style:O==null?void 0:O.style,collapsed:M}],x={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:N,debounce:!0}},w=new s.TextX,H=s.JSONX.getInstance();if(M)h>0&&w.push({t:s.TextXActionType.RETAIN,len:h}),w.push({t:s.TextXActionType.INSERT,body:I,len:I.dataStream.length});else{const z=s.BuildTextUtils.selection.delete([r],u,0,I);w.push(...z)}(((G=f.bullet)==null?void 0:G.listType)===s.PresetListType.CHECK_LIST_CHECKED||(k=f.paragraphStyle)!=null&&k.headingId)&&(r.endOffset<E&&w.push({t:s.TextXActionType.RETAIN,len:E-r.endOffset}),w.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...f,paragraphStyle:{...f.paragraphStyle,...S?{headingId:void 0,namedStyleType:void 0}:null},startIndex:0,bullet:(W=f.paragraphStyle)!=null&&W.headingId?void 0:{...f.bullet,listType:s.PresetListType.CHECK_LIST}}]},coverType:s.UpdateDocsAttributeType.REPLACE})),x.params.textRanges=[{startOffset:h+y,endOffset:h+y,collapsed:M}];const V=J(d,A);return x.params.actions=H.editOp(w.serialize(),V),!!o.syncExecuteCommand(x.id,x.params)}},vt={id:"doc.command.horizontal-line",type:s.CommandType.COMMAND,handler:(i,t)=>i.get(s.ICommandService).syncExecuteCommand(on.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:s.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},Si={id:"doc.command.insert-horizontal-line-bellow",type:s.CommandType.COMMAND,handler:i=>{const t=i.get(s.ICommandService),e=mt(i);return e?t.syncExecuteCommand(vt.id,{insertRange:{startOffset:e.startIndex+1,endOffset:e.startIndex+1}}):!1}};function ue(i,t,e){return e.executeCommand(be.id,{preCommandId:i,...t!=null?t:{}})}const vs="doc.command.set-inline-format-bold",De={id:vs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(vs,t,e)}},Is="doc.command.set-inline-format-italic",Be={id:Is,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Is,t,e)}},Es="doc.command.set-inline-format-underline",_e={id:Es,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Es,t,e)}},Cs="doc.command.set-inline-format-strikethrough",Ne={id:Cs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Cs,t,e)}},Ts="doc.command.set-inline-format-subscript",ye={id:Ts,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Ts,t,e)}},ys="doc.command.set-inline-format-superscript",Pe={id:ys,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(ys,t,e)}},bs="doc.command.set-inline-format-fontsize",ge={id:bs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(bs,t,e)}},Os="doc.command.set-inline-format-font-family",We={id:Os,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Os,t,e)}},Rs="doc.command.set-inline-format-text-color",Ue={id:Rs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Rs,t,e)}},Ms="doc.command.set-inline-format-text-background-color",we={id:Ms,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Ms,t,e)}},xs="doc.command.reset-inline-format-text-background-color",tt={id:xs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(xs,t,e)}},vi={[De.id]:"bl",[Be.id]:"it",[_e.id]:"ul",[Ne.id]:"st",[ge.id]:"fs",[We.id]:"ff",[Ue.id]:"cl",[we.id]:"bg",[tt.id]:"bg",[ye.id]:"va",[Pe.id]:"va"},be={id:"doc.command.set-inline-format",type:s.CommandType.COMMAND,handler:async(i,t)=>{var R;const{value:e,preCommandId:n}=t,o=i.get(s.ICommandService),a=i.get(D.DocSelectionManagerService),r=i.get(s.IUniverInstanceService),c=i.get(Te),l=a.getDocRanges(),A=(R=l.find(I=>I.isActive))!=null?R:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=r.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const h=u.getUnitId();let g;switch(n){case De.id:case Be.id:case _e.id:case Ne.id:case ye.id:case Pe.id:{const I=c.getDefaultStyle(),O=Bs(m,A,I);g=nc(O,n);break}case ge.id:case We.id:{g=e;break}case Ue.id:case we.id:{g={rgb:e};break}case tt.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:l}},f=new s.TextX,S=s.JSONX.getInstance(),E=new s.MemoryCursor;E.reset();for(const I of l){let{startOffset:O,endOffset:M,rangeType:y}=I;if(O==null||M==null)continue;if(y===s.DOC_RANGE_TYPE.RECT&&(O=O-1),O===M){const w=c.getStyleCache(),H=vi[n];c.setStyleCache({[H]:(w==null?void 0:w[H])!==void 0?Ds(w,H,n):g});continue}const N={dataStream:"",textRuns:[{st:0,ed:M-O,ts:{[vi[n]]:g}}]},x=O-E.cursor;x!==0&&f.push({t:s.TextXActionType.RETAIN,len:x}),f.push({t:s.TextXActionType.RETAIN,body:N,len:M-O}),E.reset(),E.moveCursor(M)}const C=J(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!o.syncExecuteCommand(p.id,p.params)}};function tc(i){return i!==null&&typeof i=="object"}function Ds(i,t,e){if(/bl|it/.test(t))return(i==null?void 0:i[t])===s.BooleanNumber.TRUE?s.BooleanNumber.FALSE:s.BooleanNumber.TRUE;if(/ul|st/.test(t))return tc(i==null?void 0:i[t])&&(i==null?void 0:i[t]).s===s.BooleanNumber.TRUE?{s:s.BooleanNumber.FALSE}:{s:s.BooleanNumber.TRUE};if(/va/.test(t))return e===ye.id?(i==null?void 0:i[t])===s.BaselineOffset.SUBSCRIPT?s.BaselineOffset.NORMAL:s.BaselineOffset.SUBSCRIPT:(i==null?void 0:i[t])===s.BaselineOffset.SUPERSCRIPT?s.BaselineOffset.NORMAL:s.BaselineOffset.SUPERSCRIPT}function Bs(i,t,e){var d,u,m,h,g,p,f,S,E,C,b,R,I,O;const{startOffset:n,endOffset:o,collapsed:a}=t;if(a){const M=(d=i.textRuns)!=null?d:[];let y=null;for(let N=M.length-1;N>=0;N--){const x=M[N];if(x.st<n&&n<=x.ed){y=x;break}}return y!=null&&y.ts?{...e,...y.ts}:e}const{textRuns:r=[]}=s.getBodySlice(i,n,o),c=s.Tools.deepClone(e),l=r.map(M=>{var y;return(y=M==null?void 0:M.ts)==null?void 0:y.fs}).filter(Boolean);c.fs=c.fs?Math.max(c.fs,...l):l.length?Math.max(...l):void 0,c.fs=!c.fs||Number.isNaN(c.fs)?void 0:c.fs,c.ff=(h=(m=(u=r.find(M=>{var y;return((y=M.ts)==null?void 0:y.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?h:c.ff,c.it=r.length&&r.every(M=>{var y;return((y=M.ts)==null?void 0:y.it)===s.BooleanNumber.TRUE})?s.BooleanNumber.TRUE:s.BooleanNumber.FALSE,c.bl=r.length&&r.every(M=>{var y;return((y=M.ts)==null?void 0:y.bl)===s.BooleanNumber.TRUE})?s.BooleanNumber.TRUE:s.BooleanNumber.FALSE,c.ul=r.length&&r.every(M=>{var y,N;return((N=(y=M.ts)==null?void 0:y.ul)==null?void 0:N.s)===s.BooleanNumber.TRUE})?(g=r[0].ts)==null?void 0:g.ul:c.ul,c.st=r.length&&r.every(M=>{var y,N;return((N=(y=M.ts)==null?void 0:y.st)==null?void 0:N.s)===s.BooleanNumber.TRUE})?(p=r[0].ts)==null?void 0:p.st:c.st,c.bg=(E=(S=(f=r.find(M=>{var y;return((y=M.ts)==null?void 0:y.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(b=(C=r.find(M=>{var y;return((y=M.ts)==null?void 0:y.cl)!=null}))==null?void 0:C.ts)==null?void 0:b.cl)!=null?R:c.cl;const A=r.filter(M=>{var y;return((y=M==null?void 0:M.ts)==null?void 0:y.va)!=null});if(A.length>0&&A.length===r.length){const M=(I=A[0].ts)==null?void 0:I.va;let y=!0;for(let N=1;N<A.length;N++)if(((O=A[N].ts)==null?void 0:O.va)!==M){y=!1;break}y&&(c.va=M)}return c}function nc(i,t){const e=vi[t];return Ds(i,e,t)}const nt={id:"doc.command.list-operation",type:s.CommandType.COMMAND,handler:(i,t)=>{var b,R,I,O,M,y;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),a=t.listType,r=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),c=(R=(b=t.docRange)!=null?b:e.getDocRanges())!=null?R:[];if(r==null||c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(O=(I=A.getBody())==null?void 0:I.paragraphs)!=null?O:[],u=(y=(M=A.getBody())==null?void 0:M.dataStream)!=null?y:"";if(!d.length)return!1;const m=s.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}};new s.MemoryCursor().reset();const f=s.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:a,document:r,segmentId:l}),S=s.JSONX.getInstance(),E=J(r,l);return g.params.actions=S.editOp(f.serialize(),E),!!o.syncExecuteCommand(g.id,g.params)}},It={id:"doc.command.change-list-type",type:s.CommandType.COMMAND,handler:(i,t)=>{var C,b,R,I,O;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),{listType:a}=t,r=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(r==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=r.getSelfOrHeaderFooterModel(l),d=(R=(b=A.getBody())==null?void 0:b.paragraphs)!=null?R:[],u=(O=(I=A.getBody())==null?void 0:I.dataStream)!=null?O:"";if(!d.length)return!1;const m=s.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=s.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:a,segmentId:l,document:r});if(!g)return!1;const p=s.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}},S=J(r,l);return f.params.actions=p.editOp(g.serialize(),S),!!o.syncExecuteCommand(f.id,f.params)}};var Et=(i=>(i[i.increase=1]="increase",i[i.decrease=-1]="decrease",i))(Et||{});const sn={id:"doc.command.change-list-nesting-level",type:s.CommandType.COMMAND,handler:(i,t)=>{var b,R,I,O,M;if(!t)return!1;const{type:e}=t,n=i.get(D.DocSelectionManagerService),o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),r=o.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null)return!1;const{segmentId:l}=c,A=(b=n.getDocRanges())!=null?b:[],d=r.getSelfOrHeaderFooterModel(l),u=(I=(R=d.getBody())==null?void 0:R.paragraphs)!=null?I:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"";if(!u.length)return!1;const h=s.BuildTextUtils.range.getParagraphsInRange(c,u,m),g=r.getUnitId(),p=s.JSONX.getInstance(),f=s.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:h,type:e,segmentId:l,document:r}),S={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:A,isEditing:!1}},E=J(r,l);return S.params.actions=p.editOp(f.serialize(),E),!!a.syncExecuteCommand(S.id,S.params)}},it={id:"doc.command.bullet-list",type:s.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(s.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(nt.id,{listType:s.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Ct={id:"doc.command.check-list",type:s.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(s.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(nt.id,{listType:s.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},Ii={id:"doc.command.toggle-check-list",type:s.CommandType.COMMAND,handler:(i,t)=>{var p;if(!t)return!1;const e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),{index:o,segmentId:a,textRanges:r}=t,c=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(c==null||((p=c.getSelfOrHeaderFooterModel(a).getBody())==null?void 0:p.paragraphs)==null)return!1;const A=c.getUnitId(),d={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:r!=null?r:[],segmentId:a,isEditing:!1}},u=s.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:o,segmentId:a});if(!u)return!1;const m=s.JSONX.getInstance(),h=J(c,a);return d.params.actions=m.editOp(u.serialize(),h),!!n.syncExecuteCommand(d.id,d.params)}},ot={id:"doc.command.order-list",type:s.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(s.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value}):e.syncExecuteCommand(nt.id,{listType:s.PresetListType.ORDER_LIST})}},Ei={id:"doc.command.quick-list",type:s.CommandType.COMMAND,handler(i,t){var X,Y,q,K,Z;if(!t)return!1;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),a=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),r=e.getActiveTextRange();if(a==null||r==null)return!1;const{segmentId:c,startOffset:l}=r,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,h=new s.TextX,g=s.JSONX.getInstance(),{defaultTabStop:p=36}=a.getSnapshot().documentStyle,f=(Y=(X=a.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:X.sectionBreaks)!=null?Y:[],{startIndex:S,paragraphStyle:E={}}=d,{indentFirstLine:C,snapToGrid:b,indentStart:R}=E,I=s.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{},{hanging:O,indentStart:M}=I,y=I.textStyle,{charSpace:N,gridType:x}=ic(S,f)||{charSpace:0,gridType:s.GridType.LINES},w=_.getCharSpaceApply(N,p,x,b);let V=s.Tools.generateRandomId(6);const F=(K=(q=a.getBody())==null?void 0:q.paragraphs)!=null?K:[],Q=F.findIndex(ie=>ie.startIndex===d.startIndex),j=F[Q-1],G=F[Q+1];j&&j.bullet&&j.bullet.listType.indexOf(A)===0?V=j.bullet.listId:G&&G.bullet&&G.bullet.listType.indexOf(A)===0&&(V=G.bullet.listId);const k={id:D.RichTextEditingMutation.id,params:{unitId:a.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};h.push({t:s.TextXActionType.RETAIN,len:u}),h.push({t:s.TextXActionType.DELETE,len:l-u}),m>l&&h.push({t:s.TextXActionType.RETAIN,len:m-l}),h.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...E,textStyle:{...E.textStyle,...y},indentFirstLine:void 0,hanging:O,indentStart:{v:_.getNumberUnitValue(M,w)-_.getNumberUnitValue(O,w)+_.getNumberUnitValue(C,w)+_.getNumberUnitValue(R,w)}},bullet:{...(Z=d.bullet)!=null?Z:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:V}}]}});const W=J(a,c);return k.params.actions=g.editOp(h.serialize(),W),!!o.syncExecuteCommand(k.id,k.params)}};function Ci(i,t){var d,u;const e=i.get(s.ICommandService),n=mt(i);if(!n)return!1;const o=i.get(s.IUniverInstanceService).getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC);if(!o)return!1;const a=s.BuildTextUtils.selection.replace({doc:o,selection:{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0},body:{dataStream:"\r",paragraphs:[{startIndex:0,paragraphStyle:{...n.paragraphStyle},bullet:{listType:t,listId:((d=n.bullet)==null?void 0:d.listType)===t?n.bullet.listId:s.Tools.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!a)return!1;const r={id:D.RichTextEditingMutation.id,params:{unitId:o.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=s.JSONX.getInstance(),l=J(o);return r.params.actions=c.editOp(a.serialize(),l),!!e.syncExecuteCommand(r.id,r.params)}const Ti={id:"doc.command.insert-bullet-list-bellow",type:s.CommandType.COMMAND,handler:i=>Ci(i,s.PresetListType.BULLET_LIST)},yi={id:"doc.command.insert-order-list-bellow",type:s.CommandType.COMMAND,handler:i=>Ci(i,s.PresetListType.ORDER_LIST)},bi={id:"doc.command.insert-check-list-bellow",type:s.CommandType.COMMAND,handler:i=>Ci(i,s.PresetListType.CHECK_LIST)};function ic(i,t){const e=t.sort(s.sortRulesFactory("startIndex"));for(let n=0;n<e.length;n++){const o=t[n];if(o.startIndex>=i)return o}}const de={id:"doc.command.set-paragraph-named-style",type:s.CommandType.COMMAND,handler(i,t){var g;if(!t)return!1;const n=i.get(s.IUniverInstanceService).getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const o=n.getUnitId(),a=i.get(D.DocSelectionManagerService),r=(g=t.textRanges)!=null?g:a.getTextRanges({unitId:o,subUnitId:o});if(!(r!=null&&r.length))return!1;const c=r[0].segmentId,l=s.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:r,style:{namedStyleType:t.value,headingId:!t.value||t.value===s.NamedStyleType.NORMAL_TEXT?void 0:s.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0},paragraphTextRun:{}}),A={id:D.RichTextEditingMutation.id,params:{actions:[],textRanges:r,unitId:o,segmentId:c}},d=s.JSONX.getInstance(),u=J(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!i.get(s.ICommandService).syncExecuteCommand(A.id,A.params)}},_s={id:"doc.command.quick-heading",type:s.CommandType.COMMAND,handler(i,t){var R,I,O,M;if(!t)return!1;const{value:e}=t,n=i.get(D.DocSelectionManagerService),o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),r=o.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=r.getSelfOrHeaderFooterModel(l),u=(I=(R=d.getBody())==null?void 0:R.paragraphs)!=null?I:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"",h=s.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!h)return!1;const{paragraphStart:g}=h,p=new s.TextX,f=s.JSONX.getInstance(),{paragraphStyle:S={}}=h,E={id:D.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:g,endOffset:g,collapsed:!0}],isEditing:!1}};p.push({t:s.TextXActionType.RETAIN,len:g}),s.BuildTextUtils.paragraph.style.set({textRanges:[c],document:r,style:{...S,headingId:s.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-g,textX:p,paragraphTextRun:{}});const C=J(r,l);return E.params.actions=f.editOp(p.serialize(),C),!!a.syncExecuteCommand(E.id,E.params)}},Oi={"#":s.NamedStyleType.HEADING_1,"##":s.NamedStyleType.HEADING_2,"###":s.NamedStyleType.HEADING_3,"####":s.NamedStyleType.HEADING_4,"#####":s.NamedStyleType.HEADING_5},Ri={id:"doc.command.h1-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_1})},Mi={id:"doc.command.h2-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_2})},xi={id:"doc.command.h3-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_3})},Di={id:"doc.command.h4-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_4})},Bi={id:"doc.command.h5-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_5})},an={id:"doc.command.normal-text-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.NORMAL_TEXT})},Ns={id:"doc.command.title",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.TITLE})},Ps={id:"doc.command.subtitle-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.SUBTITLE})},me={id:"doc.command.align-action",type:s.CommandType.COMMAND,handler:(i,t)=>{var R,I,O,M;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),{alignType:a}=t,r=n.getCurrentUniverDocInstance();if(r==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(I=(R=A.getBody())==null?void 0:R.paragraphs)!=null?I:[],u=(M=(O=A.getBody())==null?void 0:O.dataStream)!=null?M:"";if(d==null)return!1;const m=s.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=m.every(y=>{var N;return((N=y.paragraphStyle)==null?void 0:N.horizontalAlign)===a}),p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c}},f=new s.MemoryCursor;f.reset();const S=new s.TextX,E=s.JSONX.getInstance();for(const y of m){const{startIndex:N}=y;S.push({t:s.TextXActionType.RETAIN,len:N-f.cursor});const x={...y.paragraphStyle,horizontalAlign:g?s.HorizontalAlign.UNSPECIFIED:a};S.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...y,paragraphStyle:x,startIndex:0}]},coverType:s.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(N+1)}const C=J(r,l);return p.params.actions=E.editOp(S.serialize(),C),!!o.syncExecuteCommand(p.id,p.params)}},Tt={id:"doc.command.align-left",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(me.id,{alignType:s.HorizontalAlign.LEFT})},yt={id:"doc.command.align-center",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(me.id,{alignType:s.HorizontalAlign.CENTER})},bt={id:"doc.command.align-right",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(me.id,{alignType:s.HorizontalAlign.RIGHT})},Ot={id:"doc.command.align-justify",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(me.id,{alignType:s.HorizontalAlign.JUSTIFIED})},Rt={id:"doc.command.switch-mode",type:s.CommandType.COMMAND,handler:i=>{var E,C,b,R,I;const t=i.get(s.ICommandService),e=i.get(_.IRenderManagerService),n=i.get(D.DocSelectionManagerService),a=i.get(s.IUniverInstanceService).getCurrentUniverDocInstance();if(a==null)return!1;const r=a.getUnitId(),c=(E=e.getRenderById(r))==null?void 0:E.with(D.DocSkeletonManagerService).getSkeleton(),l=(C=e.getRenderById(r))==null?void 0:C.with(T.DocSelectionRenderService);if(c==null||l==null)return!1;const A=l==null?void 0:l.getSegment(),d=l==null?void 0:l.getSegmentPage(),u=a.getSnapshot().documentStyle.documentFlavor,m=n.getDocRanges(),h={id:D.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:u===s.DocumentFlavor.TRADITIONAL&&A?[]:m}},g=s.JSONX.getInstance(),p=[];let f;if(u===void 0?f=g.insertOp(["documentStyle","documentFlavor"],s.DocumentFlavor.MODERN):u===s.DocumentFlavor.MODERN?f=g.replaceOp(["documentStyle","documentFlavor"],u,s.DocumentFlavor.TRADITIONAL):f=g.replaceOp(["documentStyle","documentFlavor"],u,s.DocumentFlavor.MODERN),f)p.push(f);else return!1;if(u!==s.DocumentFlavor.MODERN){const O=a.getSnapshot(),{drawings:M={},body:y}=O,N=(b=y==null?void 0:y.customBlocks)!=null?b:[];for(const x in M){const w=M[x],H=N.find(Z=>Z.blockId===x);if(H==null)continue;const V=w.docTransform.positionV,{relativeFrom:F,posOffset:Q}=V;if(F===s.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:j}=H,G=c.findNodeByCharIndex(j,A,d),k=(R=G==null?void 0:G.parent)==null?void 0:R.parent,W=k==null?void 0:k.parent,z=W==null?void 0:W.lines.find(Z=>Z.paragraphIndex===(k==null?void 0:k.paragraphIndex)&&Z.paragraphStart),X=(I=W==null?void 0:W.parent)==null?void 0:I.parent;if(G==null||k==null||z==null||W==null||X==null)continue;let Y=0;F===s.ObjectRelativeFromV.LINE?Y-=k.top:F===s.ObjectRelativeFromV.PAGE&&(Y+=X.marginTop),Y+=z.top;const q={...V,relativeFrom:s.ObjectRelativeFromV.PARAGRAPH,posOffset:(Q!=null?Q:0)-Y},K=g.replaceOp(["drawings",x,"docTransform","positionV"],V,q);K&&p.push(K)}}return h.params.actions=p.reduce((O,M)=>s.JSONX.compose(O,M),null),!!t.syncExecuteCommand(h.id,h.params)}},Us="COMPONENT_DOC_CREATE_TABLE_CONFIRM",_i={id:"doc.command.create-table",type:s.CommandType.COMMAND,handler:async(i,t)=>{var q,K,Z,ie,fe;const{rowCount:e,colCount:n}=t,o=i.get(D.DocSelectionManagerService),a=i.get(s.IUniverInstanceService),r=i.get(s.ICommandService),c=i.get(Te),l=o.getActiveTextRange();if(l==null)return!1;const{segmentId:A,segmentPage:d}=l,u=a.getCurrentUniverDocInstance(),m=u==null?void 0:u.getSelfOrHeaderFooterModel(A).getBody();if(u==null||m==null)return!1;const h=u.getUnitId(),g=re(i,h),p=g==null?void 0:g.getSkeleton();if(p==null)return!1;const{startOffset:f}=l,E=((q=m.paragraphs)!=null?q:[]).find(Fe=>Fe.startIndex>=f),C=p.findNodeByCharIndex(f,A,d);if(C==null)return!1;const b=new s.TextX,R=s.JSONX.getInstance(),I=[],O=f+4,M=[{startOffset:O,endOffset:O,collapsed:!0}],y={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:M}};f>0&&b.push({t:s.TextXActionType.RETAIN,len:f}),b.push({t:s.TextXActionType.INSERT,body:{dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:fi(s.DataStreamTreeTokenType.PARAGRAPH,E)},len:1});const N=c.getDefaultStyle(),x=c.getStyleCache(),w=Qt(m,f,N,x),{dataStream:H,paragraphs:V,sectionBreaks:F}=Rr(e,n),Q=(fe=(ie=(Z=(K=C.parent)==null?void 0:K.parent)==null?void 0:Z.parent)==null?void 0:ie.parent)==null?void 0:fe.parent;if(Q==null)return!1;const{pageWidth:j,marginLeft:G,marginRight:k}=Q,W=ni(e,n,j-G-k);b.push({t:s.TextXActionType.INSERT,body:{dataStream:H,paragraphs:V,sectionBreaks:F,textRuns:[{...w,st:0,ed:H.length}],tables:[{startIndex:0,endIndex:H.length,tableId:W.tableId}]},len:H.length});const z=J(u,A);I.push(R.editOp(b.serialize(),z));const X=R.insertOp(["tableSource",W.tableId],W);return I.push(X),y.params.actions=I.reduce((Fe,Se)=>s.JSONX.compose(Fe,Se),null),!!r.syncExecuteCommand(y.id,y.params)}},Ni="doc.component.create-table-confirm",rn={id:"doc.operation.create-table",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(s.LocaleService),e=i.get(v.IConfirmService),n=i.get(s.ICommandService),o={rowCount:3,colCount:5},a=(r,c)=>{o.rowCount=r,o.colCount=c};return await e.open({id:Ni,children:{label:{name:Us,props:{handleRowColChange:a,tableCreateParams:o}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(_i.id,o),e.close(Ni)},onClose:()=>{e.close(Ni)}}),!0}},oc=i=>{const e=Object.keys(s.PAGE_SIZE).find(n=>{const{width:o,height:a}=s.PAGE_SIZE[n];return i.width===o&&i.height===a});return e!=null?e:"A4"};function sc(i){const{hooks:t}=i,o=v.useDependency(s.IUniverInstanceService).getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC).getDocumentStyle(),a=v.useDependency(s.LocaleService),[r,c]=U.useState(()=>{var d,u,m,h,g;return{paperSize:oc(o.pageSize),orientation:(d=o.pageOrient)!=null?d:s.PageOrientType.PORTRAIT,margins:{top:(u=o.marginTop)!=null?u:0,bottom:(m=o.marginBottom)!=null?m:0,left:(h=o.marginLeft)!=null?h:0,right:(g=o.marginRight)!=null?g:0}}});U.useEffect(()=>{t.beforeClose=()=>r,t.beforeConfirm=()=>r},[r]);const l=d=>{c(u=>({...u,paperSize:d}))},A=(d,u)=>{c(m=>({...m,margins:{...m.margins,[d]:u||0}}))};return P.jsxs("div",{className:"univer-theme univer-flex univer-flex-col univer-gap-4",children:[P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-[#0E111E]",children:a.t("page-settings.paper-size")}),P.jsx(ee.Select,{value:r.paperSize,onChange:l,options:s.PAPER_TYPES.map(d=>({label:a.t(`page-settings.page-size.${d.toLocaleLowerCase()}`),value:d}))})]}),P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-[#0E111E]",children:a.t("page-settings.custom-paper-size")}),P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:a.t("page-settings.top")}),P.jsx(ee.InputNumber,{value:r.margins.top,onChange:d=>A("top",d)})]}),P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:a.t("page-settings.bottom")}),P.jsx(ee.InputNumber,{value:r.margins.bottom,onChange:d=>A("bottom",d)})]})]}),P.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:a.t("page-settings.left")}),P.jsx(ee.InputNumber,{value:r.margins.left,onChange:d=>A("left",d)})]}),P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:a.t("page-settings.right")}),P.jsx(ee.InputNumber,{value:r.margins.right,onChange:d=>A("right",d)})]})]})]})]})]})}const Pi="docs.component.page-setting",ws={id:"docs.command.page-setup",type:s.CommandType.COMMAND,handler:(i,t)=>{if(!t)return!1;const e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=e.getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC);if(!o)return!1;const{marginLeft:a,marginRight:r,marginBottom:c,marginTop:l,pageOrient:A,pageSize:d}=t,u=s.JSONX.getInstance(),m=o.getDocumentStyle(),{marginBottom:h,marginLeft:g,marginRight:p,marginTop:f,pageOrient:S,pageSize:E}=m,C=[];if(h===void 0){const I=u.insertOp(["documentStyle","marginBottom"],c);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","marginBottom"],h,c);I&&C.push(I)}if(g===void 0){const I=u.insertOp(["documentStyle","marginLeft"],a);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","marginLeft"],g,a);I&&C.push(I)}if(p===void 0){const I=u.insertOp(["documentStyle","marginRight"],r);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","marginRight"],p,r);I&&C.push(I)}if(f===void 0){const I=u.insertOp(["documentStyle","marginTop"],l);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","marginTop"],f,l);I&&C.push(I)}if(E===void 0){const I=u.insertOp(["documentStyle","pageSize"],d);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","pageSize"],E,d);I&&C.push(I)}if(S===void 0){const I=u.insertOp(["documentStyle","pageOrient"],A);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","pageOrient"],S,A);I&&C.push(I)}const b={id:D.RichTextEditingMutation.id,params:{unitId:o.getUnitId(),actions:[],textRanges:void 0}};return b.params.actions=C.reduce((I,O)=>s.JSONX.compose(I,O),null),!!n.syncExecuteCommand(b.id,b.params)}},Ui={id:"docs.operation.open-page-setting",type:s.CommandType.OPERATION,handler:i=>{const t=i.get(v.IConfirmService),e=i.get(s.ICommandService),n=i.get(s.LocaleService),o=t.open({id:Pi,title:{label:n.t("page-settings.document-setting")},children:{label:Pi},width:528,onClose:()=>{o.dispose()},onConfirm:a=>{if(o.dispose(),!a)return;const r=s.PAGE_SIZE[a.paperSize];e.executeCommand(ws.id,{pageOrient:a.orientation,marginTop:a.margins.top,marginBottom:a.margins.bottom,marginLeft:a.margins.left,marginRight:a.margins.right,pageSize:r})}});return!0}};function ac(i){const t=i.get(s.IUniverInstanceService),e=i.get(_.IRenderManagerService);return new L.Observable(n=>{const o=t.focused$.subscribe(a=>{if(a==null||t.getUnitType(a)!==s.UniverInstanceType.UNIVER_DOC)return n.next(!0);const c=e.getRenderById(a);if(c==null)return n.next(!0);c.with(D.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(A=>{n.next(A===_.DocumentEditArea.HEADER||A===_.DocumentEditArea.FOOTER)})});return()=>o.unsubscribe()})}function rc(i){const t=i.get(s.IUniverInstanceService),e=i.get(s.ICommandService);return new L.Observable(n=>{const o=e.onCommandExecuted(l=>{if(l.id===D.RichTextEditingMutation.id){const{unitId:A}=l.params,d=t.getUnit(A);if(d==null){n.next(!0);return}const{documentStyle:u}=d.getSnapshot();n.next((u==null?void 0:u.documentFlavor)!==s.DocumentFlavor.TRADITIONAL)}}),a=t.focused$.subscribe(l=>{if(l==null)return n.next(!0);const A=t.getUniverDocInstance(l),d=A==null?void 0:A.getSnapshot().documentStyle.documentFlavor;n.next(d!==s.DocumentFlavor.TRADITIONAL)}),r=t.getCurrentUniverDocInstance();if(r==null)return n.next(!0);const c=r==null?void 0:r.getSnapshot().documentStyle.documentFlavor;return n.next(c!==s.DocumentFlavor.TRADITIONAL),()=>{o.dispose(),a.unsubscribe()}})}function cc(i){const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService);return new L.Observable(n=>{const o=t.textSelection$.subscribe(a=>{if(a==null){n.next(!0);return}const{textRanges:r}=a;if(r.length!==1){n.next(!0);return}const c=r[0],{collapsed:l,startNodePosition:A,startOffset:d}=c;if(!l||d==null){n.next(!0);return}const u=e.getCurrentUniverDocInstance();if(u==null){n.next(!0);return}const m=re(i,u.getUnitId());if(m==null){n.next(!0);return}if(m.getViewModel().getCustomRangeRaw(d)){n.next(!0);return}if(A!=null){const{path:p}=A;if(p.indexOf("cells")!==-1){n.next(!0);return}}n.next(!1)});return()=>o.unsubscribe()})}function te(i){const t=i.get(D.DocSelectionManagerService);return new L.Observable(e=>{const n=t.textSelection$.subscribe(o=>{if(o==null){e.next(!0);return}const{textRanges:a,rectRanges:r}=o;if(a.length===0&&r.length===0){e.next(!0);return}e.next(!1)});return()=>n.unsubscribe()})}function lc(i){const t=i.get(s.ICommandService);return{id:De.id,type:v.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.bl;e.next(r===s.BooleanNumber.TRUE)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function dc(i){const t=i.get(s.ICommandService);return{id:Be.id,type:v.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.it;e.next(r===s.BooleanNumber.TRUE)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function Ac(i){const t=i.get(s.ICommandService);return{id:_e.id,type:v.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.ul;e.next((r==null?void 0:r.s)===s.BooleanNumber.TRUE)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function uc(i){const t=i.get(s.ICommandService);return{id:Ne.id,type:v.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.st;e.next((r==null?void 0:r.s)===s.BooleanNumber.TRUE)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function hc(i){const t=i.get(s.ICommandService);return{id:ye.id,type:v.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.va;e.next(r===s.BaselineOffset.SUBSCRIPT)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function gc(i){const t=i.get(s.ICommandService);return{id:Pe.id,type:v.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.va;e.next(r===s.BaselineOffset.SUPERSCRIPT)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function mc(i){const t=i.get(s.ICommandService);return{id:We.id,tooltip:"toolbar.font",type:v.MenuItemType.SELECTOR,label:qo,selections:v.FONT_FAMILY_LIST.map(e=>({label:{name:Jo},value:e.value})),value$:new L.Observable(e=>{const n=s.DEFAULT_STYLES.ff,o=()=>{var l;const r=Le(i);if(r==null){e.next(n);return}const c=(l=r.ts)==null?void 0:l.ff;e.next(c!=null?c:n)},a=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===We.id)&&o()});return o(),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function pc(i){const t=i.get(s.ICommandService);return{id:ge.id,type:v.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Zo,props:{min:1,max:400}},selections:v.FONT_SIZE_LIST,value$:new L.Observable(e=>{const n=s.DEFAULT_STYLES.fs,o=()=>{var l;const r=Le(i);if(r==null){e.next(n);return}const c=(l=r.ts)==null?void 0:l.fs;e.next(c!=null?c:n)},a=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===ge.id)&&o()});return o(),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function fc(i){const t=i.get(s.ICommandService);return{id:de.id,type:v.MenuItemType.SELECTOR,tooltip:"toolbar.heading.tooltip",label:{name:v.COMMON_LABEL_COMPONENT,props:{selections:v.HEADING_LIST}},selections:v.HEADING_LIST.map(e=>({label:{name:v.HEADING_ITEM_COMPONENT,props:{value:e.value,text:e.label}},value:e.value})),value$:new L.Observable(e=>{const n=s.NamedStyleType.NORMAL_TEXT,o=()=>{var l,A;const r=ze(i);if(r==null){e.next(n);return}const c=(A=(l=r.paragraphStyle)==null?void 0:l.namedStyleType)!=null?A:n;e.next(c)},a=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===ge.id)&&o()});return o(),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function Sc(i){const t=i.get(s.ICommandService),e=i.get(s.ThemeService);return{id:Ue.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:v.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:ei,hoverable:!1,selectable:!1}}],value$:new L.Observable(n=>{const o=e.getCurrentTheme().textColor,a=t.onCommandExecuted(r=>{if(r.id===Ue.id){const c=r.params.value;n.next(c!=null?c:o)}});return n.next(o),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function vc(i){return{id:Zn.id,type:v.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:L.combineLatest(v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),rc(i),(t,e)=>t||e)}}const Ic="GridSingle",Ls="doc.menu.table";function Ec(i){return{id:Ls,type:v.MenuItemType.SUBITEMS,icon:Ic,tooltip:"toolbar.table.main",disabled$:cc(i),hidden$:L.combineLatest(v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),ac(i),(t,e)=>t||e)}}function Cc(i){return{id:rn.id,title:"toolbar.table.insert",type:v.MenuItemType.BUTTON,hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function Tc(i){const t=i.get(s.ICommandService);return{id:Tt.id,type:v.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:te(i),activated$:new L.Observable(e=>{const n=t.onCommandExecuted(o=>{var r;const a=o.id;if(a===D.SetTextSelectionsOperation.id||a===me.id){const c=ze(i);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===s.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function yc(i){const t=i.get(s.ICommandService);return{id:yt.id,type:v.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(o=>{var r;const a=o.id;if(a===D.SetTextSelectionsOperation.id||a===me.id){const c=ze(i);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===s.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function bc(i){const t=i.get(s.ICommandService);return{id:bt.id,type:v.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(o=>{var r;const a=o.id;if(a===D.SetTextSelectionsOperation.id||a===me.id){const c=ze(i);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===s.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Oc(i){const t=i.get(s.ICommandService);return{id:Ot.id,type:v.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(o=>{var r;const a=o.id;if(a===D.SetTextSelectionsOperation.id||a===me.id){const c=ze(i);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===s.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Rc(i){return{id:vt.id,type:v.MenuItemType.BUTTON,icon:"ReduceSingle",tooltip:"toolbar.horizontalLine",disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const Mt=i=>new L.Observable(t=>{const e=i.get(s.IUniverInstanceService),n=i.get(D.DocSelectionManagerService);let o;const a=e.focused$.subscribe(r=>{if(o==null||o.unsubscribe(),r==null)return;const c=e.getUniverDocInstance(r);c!=null&&(o=n.textSelection$.subscribe(()=>{var d,u,m,h,g;const l=n.getDocRanges(),A=(d=l.find(p=>p.isActive))!=null?d:l[0];if(A){const p=c.getSelfOrHeaderFooterModel(A==null?void 0:A.segmentId),f=s.BuildTextUtils.range.getParagraphsInRange(A,(m=(u=p.getBody())==null?void 0:u.paragraphs)!=null?m:[],(g=(h=p.getBody())==null?void 0:h.dataStream)!=null?g:"");let S;if(f.every(E=>{var C;return S||(S=(C=E.bullet)==null?void 0:C.listType),E.bullet&&E.bullet.listType===S})){t.next(S);return}}t.next(void 0)}))});return()=>{a.unsubscribe(),o==null||o.unsubscribe()}});function Qs(i){return{id:ot.id,type:v.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:es,hoverable:!1,selectable:!1},value$:Mt(i)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC),disabled$:te(i),activated$:Mt(i).pipe(L.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function Fs(i){return{id:it.id,type:v.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:ts,hoverable:!1,selectable:!1},value$:Mt(i)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC),activated$:Mt(i).pipe(L.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function Hs(i){return{id:Ct.id,type:v.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC),activated$:Mt(i).pipe(L.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Mc(i){const t=i.get(s.ICommandService),e=i.get(s.IUniverInstanceService);return{id:Rt.id,type:v.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new L.Observable(n=>{var r;const o=t.onCommandExecuted(c=>{var l;if(c.id===D.RichTextEditingMutation.id){const A=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);n.next(((l=A==null?void 0:A.getSnapshot())==null?void 0:l.documentStyle.documentFlavor)===s.DocumentFlavor.MODERN)}}),a=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);return n.next(((r=a==null?void 0:a.getSnapshot())==null?void 0:r.documentStyle.documentFlavor)===s.DocumentFlavor.MODERN),()=>o.dispose()})}}function xc(i){return{id:tt.id,type:v.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function Dc(i){const t=i.get(s.ICommandService),e=i.get(s.ThemeService);return{id:we.id,tooltip:"toolbar.fillColor.main",type:v.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:ei,hoverable:!1,selectable:!1}}],value$:new L.Observable(n=>{const o=e.getCurrentTheme().primaryColor,a=t.onCommandExecuted(r=>{if(r.id===we.id){const c=r.params.value;n.next(c!=null?c:o)}});return n.next(o),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function Le(i){var g,p,f,S;const t=i.get(s.IUniverInstanceService),e=i.get(D.DocSelectionManagerService),n=i.get(Te),o=t.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),a=e.getDocRanges(),r=(g=a.find(E=>E.isActive))!=null?g:a[0],c=n.getDefaultStyle(),l=(p=n.getStyleCache())!=null?p:{},A=ze(i),d=(f=A==null?void 0:A.paragraphStyle)!=null&&f.namedStyleType?s.NAMED_STYLE_MAP[(S=A==null?void 0:A.paragraphStyle)==null?void 0:S.namedStyleType]:null;if(o==null||r==null)return{ts:{...c,...d,...l}};const{segmentId:u}=r,m=o.getSelfOrHeaderFooterModel(u).getBody();if(m==null)return{ts:{...c,...d,...l}};const h=Bs(m,r,{});return s.Tools.deleteNull(h),{ts:{...c,...d,...h,...l}}}function ze(i){var d,u;const t=i.get(s.IUniverInstanceService),e=i.get(D.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),o=e.getDocRanges(),a=(d=o.find(m=>m.isActive))!=null?d:o[0];if(n==null||a==null)return;const{startOffset:r,segmentId:c}=a,l=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(l==null)return;let A=-1;for(const m of l){const{startIndex:h}=m;if(r>A&&r<=h)return m;A=h}return null}function Bc(i){return{id:Ui.id,type:v.MenuItemType.BUTTON,icon:"DocumentSettingSingle",tooltip:"toolbar.pageSetup",hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}const _c={[s.NamedStyleType.HEADING_1]:Ri,[s.NamedStyleType.HEADING_2]:Mi,[s.NamedStyleType.HEADING_3]:xi,[s.NamedStyleType.HEADING_4]:Di,[s.NamedStyleType.HEADING_5]:Bi,[s.NamedStyleType.NORMAL_TEXT]:an,[s.NamedStyleType.TITLE]:Ns,[s.NamedStyleType.SUBTITLE]:Ps,[s.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:an},ks={[s.NamedStyleType.HEADING_1]:{key:"H1Single",component:No},[s.NamedStyleType.HEADING_2]:{key:"H2Single",component:Po},[s.NamedStyleType.HEADING_3]:{key:"H3Single",component:Uo},[s.NamedStyleType.HEADING_4]:{key:"H4Single",component:wo},[s.NamedStyleType.HEADING_5]:{key:"H5Single",component:Lo},[s.NamedStyleType.NORMAL_TEXT]:{key:"TextTypeSingle",component:ht},[s.NamedStyleType.TITLE]:{key:"TextTypeSingle",component:ht},[s.NamedStyleType.SUBTITLE]:{key:"TextTypeSingle",component:ht},[s.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:{key:"TextTypeSingle",component:ht}},Qe=i=>t=>{const e=t.get(s.ICommandService),n=t.get(v.ComponentManager),o=ks[i];return n.get(o.key)||n.register(o.key,o.component),{id:_c[i].id,type:v.MenuItemType.BUTTON,icon:o.key,tooltip:"toolbar.heading.tooltip",disabled$:te(t),hidden$:v.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC),activated$:new L.Observable(a=>{const r=s.NamedStyleType.NORMAL_TEXT,c=()=>{var u,m;const A=ze(t);if(A==null){a.next(r===i);return}const d=(m=(u=A.paragraphStyle)==null?void 0:u.namedStyleType)!=null?m:r;a.next(d===i)},l=e.onCommandExecuted(A=>{const d=A.id;(d===D.SetTextSelectionsOperation.id||d===ge.id)&&c()});return c(),l.dispose})}},Nc=Qe(s.NamedStyleType.HEADING_1),Pc=Qe(s.NamedStyleType.HEADING_2),Uc=Qe(s.NamedStyleType.HEADING_3),wc=Qe(s.NamedStyleType.HEADING_4),Lc=Qe(s.NamedStyleType.HEADING_5),Qc=Qe(s.NamedStyleType.NORMAL_TEXT);Qe(s.NamedStyleType.TITLE),Qe(s.NamedStyleType.SUBTITLE);const Fc=i=>({id:gi.id,type:v.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy"}),Hc=i=>({id:mi.id,type:v.MenuItemType.BUTTON,icon:"CutSingle",title:"rightClick.cut"}),kc=i=>({id:ci.id,type:v.MenuItemType.BUTTON,icon:"DeleteSingle",title:"rightClick.delete"}),Vc=i=>({id:Ti.id,type:v.MenuItemType.BUTTON,icon:"UnorderSingle",title:"rightClick.bulletList"}),Wc=i=>({id:yi.id,type:v.MenuItemType.BUTTON,icon:"OrderSingle",title:"rightClick.orderList"}),zc=i=>({id:bi.id,type:v.MenuItemType.BUTTON,icon:"TodoList",title:"rightClick.checkList"}),Gc=i=>({id:Si.id,type:v.MenuItemType.BUTTON,icon:"ReduceSingle",title:"toolbar.horizontalLine"}),Vs="doc.menu.insert-bellow";function jc(i){return{id:Vs,type:v.MenuItemType.SUBITEMS,title:"rightClick.insertBellow"}}const wi=4,Xc=(i,t)=>{const e=i.get(s.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...s.Tools.deepClone(t),zoomRatio:n}},he={id:"doc.operation.set-zoom-ratio",type:s.CommandType.OPERATION,handler:(i,t)=>{const e=i.get(s.IUniverInstanceService).getUniverDocInstance(t.unitId);if(!e)return!1;const n=e.getSnapshot();return n.settings==null?n.settings={zoomRatio:t.zoomRatio}:n.settings.zoomRatio=t.zoomRatio,!0}};var Kc=Object.getOwnPropertyDescriptor,Yc=(i,t,e,n)=>{for(var o=n>1?void 0:n?Kc(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},cn=(i,t)=>(e,n)=>t(e,n,i);function Ws(i,t){const e=zs(i.left,i.top,t),n=zs(i.right,i.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function zs(i,t,e){const{scaleX:n,scaleY:o}=e.getAncestorScale(),a=e.getViewport(ae.VIEW_MAIN);if(!a)return{x:i,y:t};const{viewportScrollX:r,viewportScrollY:c}=a,l=(i-r)*n,A=(t-c)*o;return{x:l,y:A}}function Gs(i,t,e){const{scaleX:n,scaleY:o}=e.getAncestorScale(),a=e.getViewport(ae.VIEW_MAIN);if(!a)return{x:i,y:t};const{viewportScrollX:r,viewportScrollY:c}=a,l=i/n+r,A=t/o+c;return{x:l,y:A}}const ln=(i,t)=>{const{scene:e,mainComponent:n,engine:o}=t,a=t.with(D.DocSkeletonManagerService).getSkeleton(),r=a.findNodePositionByCharIndex(i.startOffset,!0,i.segmentId,i.segmentPage),c=i.collapsed?i.startOffset:i.endOffset-1,l=a.findNodePositionByCharIndex(c,!0,i.segmentId,i.segmentPage),A=n;if(!l||!r)return;const d=A.getOffsetConfig(),{docsLeft:u,docsTop:m}=d,h=o.getCanvasElement(),g=h.getBoundingClientRect(),p=_.pxToNum(h.style.width),{top:f,left:S,width:E}=g,C=E/p,{scaleX:b,scaleY:R}=e.getAncestorScale(),I=new Ie(d,a),{borderBoxPointGroup:O}=I.getRangePointData(r,l);return kt(O).map(N=>Ws(N,e)).map(N=>({left:(N.left+u*b)*C+S,right:(N.right+u*b)*C+S,top:(N.top+m*R)*C+f,bottom:(N.bottom+m*R)*C+f}))};T.DocCanvasPopManagerService=class extends s.Disposable{constructor(t,e,n,o){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=o}_createRectPositionObserver(t,e){const n=()=>{const{scene:l,engine:A}=e,d=typeof t=="function"?t():t,u=A.getCanvasElement(),m=u.getBoundingClientRect(),h=_.pxToNum(u.style.width),g=Ws(d,l),{top:p,left:f,width:S}=m,E=S/h;return{left:g.left*E+f,right:g.right*E+f,top:g.top*E+p,bottom:g.bottom*E+p}},o=n(),a=new L.BehaviorSubject(o),r=new s.DisposableCollection;r.add(this._commandService.onCommandExecuted(l=>{if(l.id===he.id||l.id===D.RichTextEditingMutation.id){const A=n();A&&a.next(A)}}));const c=e.scene.getViewport(ae.VIEW_MAIN);return c&&r.add(c.onScrollAfter$.subscribeEvent(()=>{a.next(n())})),{position:o,position$:a,disposable:r}}_createObjectPositionObserver(t,e){const n=()=>{const{left:o,top:a,width:r,height:c}=t;return{left:o,right:o+r,top:a,bottom:a+c}};return this._createRectPositionObserver(n,e)}_createRangePositionObserver(t,e){var c;const n=(c=ln(t,e))!=null?c:[],o=new L.BehaviorSubject(n),a=new s.DisposableCollection;a.add(this._commandService.onCommandExecuted(l=>{if((l.id===he.id||l.id===D.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=ln(t,e);d&&o.next(d)}}));const r=e.scene.getViewport(ae.VIEW_MAIN);return r&&a.add(r.onScrollAfter$.subscribeEvent(()=>{const l=ln(t,e);l&&o.next(l)})),{positions:n,positions$:o,disposable:a}}attachPopupToRect(t,e,n){const o=this._renderManagerService.getRenderById(n);if(!o)throw new Error(`Current render not found, unitId: ${n}`);const{position:a,position$:r,disposable:c}=this._createRectPositionObserver(t,o),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:a,anchorRect$:r,canvasElement:o.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),r.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}attachPopupToObject(t,e,n){const o=this._renderManagerService.getRenderById(n);if(!o)throw new Error(`Current render not found, unitId: ${n}`);const{position:a,position$:r,disposable:c}=this._createObjectPositionObserver(t,o),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:a,anchorRect$:r,canvasElement:o.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),r.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}attachPopupToRange(t,e,n){if(!this._univerInstanceService.getUnit(n))throw new Error(`Document not found, unitId: ${n}`);const{direction:a="top",multipleDirection:r}=e,c=this._renderManagerService.getRenderById(n);if(!c)throw new Error(`Current render not found, unitId: ${n}`);const{positions:l,positions$:A,disposable:d}=this._createRangePositionObserver(t,c),u=A.pipe(L.map(h=>a.includes("top")?h[0]:h[h.length-1])),m=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:a.includes("top")?l[0]:l[l.length-1],anchorRect$:u,excludeRects:l,excludeRects$:A,direction:["top","bottom","horizontal"].some(h=>a.includes(h))&&l.length>1&&r!=null?r:a,canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(m),A.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==m}}},T.DocCanvasPopManagerService=Yc([cn(0,s.Inject(v.ICanvasPopupService)),cn(1,_.IRenderManagerService),cn(2,s.IUniverInstanceService),cn(3,s.ICommandService)],T.DocCanvasPopManagerService);var qc=Object.getOwnPropertyDescriptor,Jc=(i,t,e,n)=>{for(var o=n>1?void 0:n?qc(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},Zc=(i,t)=>(e,n)=>t(e,n,i);const $c=(i,t,e,n)=>{var m,h,g,p,f;const o=e.findNodePositionByCharIndex(i.startOffset,!0,i.segmentId,n),a=e.getSkeletonData();let r=i.endOffset-1;if(i.segmentId){const S=(f=Array.from((h=(m=a==null?void 0:a.skeFooters.get(i.segmentId))==null?void 0:m.values())!=null?h:[])[0])!=null?f:Array.from((p=(g=a==null?void 0:a.skeHeaders.get(i.segmentId))==null?void 0:g.values())!=null?p:[])[0];S&&(r=Math.min(S.ed,r))}const c=e.findNodePositionByCharIndex(r,!0,i.segmentId,n);if(!c||!o)return;const l=t.getOffsetConfig(),A=new Ie(l,e),{borderBoxPointGroup:d}=A.getRangePointData(o,c);return kt(d).map(S=>({top:S.top+l.docsTop-wi,bottom:S.bottom+l.docsTop+wi,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},js=(i,t,e,n)=>{const o=[];for(const a of i){const r=a.top;for(const c of a.columns){const l=c.left,A=a.colCount===1?n:c.width;let d=null;for(const u of c.lines){const m=u.paragraphIndex;if(u.paragraphStart){d&&(o.push(d),d=null);const h={top:t+r+u.top,left:e+l,right:e+l+A,bottom:t+r+u.top+u.lineHeight};d={paragraphStart:u.st,paragraphEnd:m,startIndex:m,rect:h,fisrtLine:{top:t+r+u.top+u.marginTop+u.paddingTop,left:e+l,right:e+l+A,bottom:t+r+u.top+u.marginTop+u.paddingTop+u.contentHeight}}}else d&&d.startIndex===m&&(d.rect.bottom=t+r+u.top+u.lineHeight)}d&&o.push(d)}}return o},el=(i,t,e,n=-1)=>{const o=e.findPositionByGlyph(i,n);if(!o)return;const a=t.getOffsetConfig(),r={...o,isBack:!0},c=new Ie(a,e),{borderBoxPointGroup:l}=c.getRangePointData(r,r),d=kt(l)[0];return{top:d.top+a.docsTop,bottom:d.bottom+a.docsTop,left:d.left+a.docsLeft,right:d.left+a.docsLeft+i.width}};function Ge(i,t,e){const{left:n,right:o,top:a,bottom:r}=e;return i>=n&&i<=o&&t>=a&&t<=r}T.DocEventManagerService=class extends s.Disposable{constructor(e,n){super();B(this,"_hoverCustomRanges$",new L.BehaviorSubject([]));B(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(L.distinctUntilChanged((e,n)=>e.length===n.length&&e.every((o,a)=>n[a].range.rangeId===o.range.rangeId&&n[a].segmentId===o.segmentId&&n[a].segmentPageIndex===o.segmentPageIndex&&n[a].range.startIndex===o.range.startIndex))));B(this,"_clickCustomRanges$",new L.Subject);B(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());B(this,"_hoverBullet$",new L.Subject);B(this,"hoverBullet$",this._hoverBullet$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.paragraph.startIndex)===(n==null?void 0:n.paragraph.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.segmentPageIndex)===(n==null?void 0:n.segmentPageIndex))));B(this,"_clickBullet$",new L.Subject);B(this,"clickBullets$",this._clickBullet$.asObservable());B(this,"_hoverParagraph$",new L.BehaviorSubject(null));B(this,"hoverParagraph$",this._hoverParagraph$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverParagraphRealTime$",this._hoverParagraph$.asObservable());B(this,"_hoverParagraphLeft$",new L.BehaviorSubject(null));B(this,"hoverParagraphLeft$",this._hoverParagraphLeft$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverParagraphLeftRealTime$",this._hoverParagraphLeft$.asObservable());B(this,"_hoverTableCell$",new L.Subject);B(this,"hoverTableCell$",this._hoverTableCell$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.rowIndex)===(n==null?void 0:n.rowIndex)&&(e==null?void 0:e.colIndex)===(n==null?void 0:n.colIndex)&&(e==null?void 0:e.tableId)===(n==null?void 0:n.tableId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverTableCellRealTime$",this._hoverTableCell$.asObservable());B(this,"_hoverTable$",new L.Subject);B(this,"hoverTable$",this._hoverTable$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.tableId)===(n==null?void 0:n.tableId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverTableRealTime$",this._hoverTable$.asObservable());B(this,"_customRangeDirty",!0);B(this,"_bulletDirty",!0);B(this,"_paragraphDirty",!0);B(this,"_customRangeBounds",[]);B(this,"_bulletBounds",[]);B(this,"_paragraphBounds",new Map);B(this,"_paragraphLeftBounds",[]);B(this,"_tableParagraphBounds",new Map);B(this,"_segmentParagraphBounds",new Map);B(this,"_tableCellBounds",new Map);B(this,"_tableBounds",new Map);this._context=e,this._docSkeletonManagerService=n,this._initResetDirty(),this._initEvents(),this._initPointer()}get hoverParagraph(){return this._hoverParagraph$.value}get hoverParagraphLeft(){return this._hoverParagraphLeft$.value}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}get _documents(){return this._context.mainComponent}dispose(){this._hoverCustomRanges$.complete(),this._clickCustomRanges$.complete(),super.dispose()}_initPointer(){let e=_.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(_.CURSOR_TYPE.POINTER)):this._context.scene.setCursor(e)}))}_initResetDirty(){this.disposeWithMe(this._skeleton.dirty$.subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0})),this.disposeWithMe(s.fromEventSubject(this._context.engine.onTransformChange$).pipe(L.filter(e=>e.type===_.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0}))}_initEvents(){this.disposeWithMe(s.fromEventSubject(this._context.scene.onPointerMove$).pipe(L.throttleTime(30)).subscribe(o=>{if(o.buttons>0){this._hoverBullet$.next(null),this._hoverCustomRanges$.next([]),this._hoverParagraph$.next(null),this._hoverParagraphLeft$.next(null),this._hoverTableCell$.next(null),this._hoverTable$.next(null);return}const{x:a,y:r}=Gs(o.offsetX,o.offsetY,this._context.scene);this._hoverCustomRanges$.next(this._calcActiveRanges({x:a,y:r})),this._hoverParagraph$.next(this._calcActiveParagraph({x:a,y:r})),this._hoverParagraphLeft$.next(this._calcActiveParagraphLeft({x:a,y:r})),this._hoverBullet$.next(this._calcActiveBullet({x:a,y:r}))})),this.disposeWithMe(this._context.scene.onPointerEnter$.subscribeEvent(()=>{this._hoverBullet$.next(null),this._hoverCustomRanges$.next([])}));const e=s.fromEventSubject(this._context.mainComponent.onPointerDown$),n=s.fromEventSubject(this._context.scene.onPointerUp$);this.disposeWithMe(e.pipe(L.switchMap(o=>n.pipe(L.take(1),L.map(a=>({down:o,up:a})))),L.filter(({down:o,up:a})=>o.target===a.target&&a.timeStamp-o.timeStamp<300)).subscribe(({down:o})=>{if(o.button===2)return;const a=Gs(o.offsetX,o.offsetY,this._context.scene),r=this._calcActiveRanges(a);r.length&&this._clickCustomRanges$.next(r.pop());const c=this._calcActiveBullet(a);c&&this._clickBullet$.next(c)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var r,c,l;const o=(l=(c=(r=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:r.getBody())==null?void 0:c.customRanges)!=null?l:[],a=[];return o.forEach(A=>{const d={startOffset:A.startIndex,endOffset:A.endIndex+1,segmentId:e},u=$c(d,this._documents,this._skeleton,n);if(!u)return null;a.push({customRange:A,rects:u,segmentId:e,segmentPageIndex:n})}),a}_buildCustomRangeBounds(){var n;if(!this._customRangeDirty)return;this._customRangeDirty=!1;const e=[];e.push(...this._buildCustomRangeBoundsBySegment()),(n=this._skeleton.getSkeletonData())==null||n.pages.forEach((o,a)=>{o.headerId&&e.push(...this._buildCustomRangeBoundsBySegment(o.headerId,a)),o.footerId&&e.push(...this._buildCustomRangeBoundsBySegment(o.footerId,a))}),this._customRangeBounds=e}_calcActiveRanges(e){this._buildCustomRangeBounds();const{x:n,y:o}=e;return this._customRangeBounds.filter(r=>r.rects.some(c=>Ge(n,o,c))).map(r=>({segmentId:r.segmentId,range:r.customRange,segmentPageIndex:r.segmentPageIndex,rects:r.rects}))}_buildBulletBoundsBySegment(e,n=-1){var A,d,u,m,h;const o=(A=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:A.getBody(),a=((d=o==null?void 0:o.paragraphs)!=null?d:[]).filter(g=>g.bullet&&g.bullet.listType.indexOf("CHECK_LIST")===0),r=[],c=this._skeleton.getSkeletonData();if(!c)return r;const l=g=>{var p,f,S;for(const E of g){const C=[...E.sections];if(E.skeTables){const b=Array.from(E.skeTables.values());C.push(...b.map(R=>R.rows.map(I=>I.cells.map(O=>O.sections))).flat(4))}for(const b of C)for(const R of b.columns)for(const I of R.lines)if(I.paragraphStart){const O=a.find(M=>M.startIndex===I.paragraphIndex);if(O){const M=I,y=(S=(f=(p=M==null?void 0:M.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!y)continue;const N=el(y,this._documents,this._skeleton,n);if(!N)continue;r.push({rect:N,segmentId:e,segmentPageIndex:n,paragraph:O})}}}return r};if(e){const g=(h=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?h:(m=c.skeHeaders.get(e))==null?void 0:m.values();return g?l(Array.from(g)):r}return l(c.pages)}_buildBulletBounds(){var e;this._bulletDirty&&(this._bulletDirty=!1,this._bulletBounds=[],this._bulletBounds.push(...this._buildBulletBoundsBySegment()),(e=this._skeleton.getSkeletonData())==null||e.pages.forEach((n,o)=>{n.headerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.headerId,o)),n.footerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.footerId,o))}))}_calcActiveBullet(e){this._buildBulletBounds();const{x:n,y:o}=e;return this._bulletBounds.find(r=>Ge(n,o,r.rect))}_buildParagraphBoundsBySegment(e){var c,l,A;const n=this._skeleton.getSkeletonData(),a=this._documents.getOffsetConfig();if(!n)return null;const r=d=>{const u=new Map,m=(h,g,p,f)=>{js(h.sections,p,f,h.pageWidth-h.marginLeft-h.marginRight).forEach(E=>{if(!u.has(E.startIndex))u.set(E.startIndex,{rect:E.rect,paragraphStart:E.paragraphStart,paragraphEnd:E.paragraphEnd,startIndex:E.startIndex,rects:[E.rect],pageIndex:g,segmentId:e,firstLine:E.fisrtLine});else{const C=u.get(E.startIndex);C&&(C.rect.bottom=E.rect.bottom,C.rects.push(E.rect))}})};for(let h=0;h<d.length;h++){const g=d[h],p=((g.pageHeight===1/0?0:g.pageHeight)+a.pageMarginTop)*h+g.marginTop+a.docsTop,f=g.marginLeft+a.docsLeft;g.skeTables&&Array.from(g.skeTables.values()).forEach(S=>{const E=S.left+f,C=S.top+p,b=E+S.width,R=C+S.height,I=S.tableId;this._tableBounds.set(I,{rect:{left:E,top:C,right:b,bottom:R},pageIndex:h,tableId:I}),S.rows.forEach((O,M)=>{O.cells.forEach((y,N)=>{const x=((g.pageHeight===1/0?0:g.pageHeight)+a.pageMarginTop)*h+S.top+a.docsTop+g.marginTop+O.top+y.marginTop,w=S.left+a.docsLeft+g.marginLeft+y.left+y.marginLeft,H=js(y.sections,x,w,y.pageWidth-y.marginLeft-y.marginRight);let V=this._tableParagraphBounds.get(I);V||(V=[],this._tableParagraphBounds.set(I,V)),V.push(...H.map(Q=>({rect:Q.rect,paragraphStart:Q.paragraphStart,paragraphEnd:Q.paragraphEnd,startIndex:Q.startIndex,pageIndex:h,segmentId:e,rowIndex:M,colIndex:N,firstLine:Q.fisrtLine,tableId:I})));let F=this._tableCellBounds.get(I);F||(F=[],this._tableCellBounds.set(I,F)),F.push({rect:{top:x,left:w,right:w+y.pageWidth-y.marginLeft-y.marginRight,bottom:x+y.pageHeight-y.marginBottom-y.marginTop},pageIndex:h,rowIndex:M,colIndex:N,tableId:I})})})}),m(g,h,p,f)}return u};if(e){const d=(A=(c=n.skeFooters.get(e))==null?void 0:c.values())!=null?A:(l=n.skeHeaders.get(e))==null?void 0:l.values();return d?r(Array.from(d)):null}return r(n.pages)}_buildParagraphBounds(){var n,o;if(!this._paragraphDirty)return;this._paragraphDirty=!1,this._tableParagraphBounds=new Map,this._tableCellBounds=new Map,this._tableBounds=new Map,this._paragraphBounds=(n=this._buildParagraphBoundsBySegment())!=null?n:new Map,this._paragraphLeftBounds=Array.from(this._paragraphBounds.values()).map(a=>({...a,rect:{left:a.rect.left-60,right:a.rect.left,top:a.rect.top,bottom:a.rect.bottom}}));const e=a=>{var r;this._segmentParagraphBounds.set(a,(r=this._buildParagraphBoundsBySegment(a))!=null?r:new Map)};(o=this._skeleton.getSkeletonData())==null||o.pages.forEach(a=>{a.headerId&&e(a.headerId),a.footerId&&e(a.footerId)})}_calcActiveParagraph(e){var c,l;this._buildParagraphBounds();const{x:n,y:o}=e,a=Array.from(this._tableBounds.values()).find(A=>Ge(n,o,A.rect));if(this._hoverTable$.next(a),a){const A=(c=this._tableCellBounds.get(a.tableId))==null?void 0:c.find(m=>Ge(n,o,m.rect));if(this._hoverTableCell$.next(A),!A)return null;const d=(l=this._tableParagraphBounds.get(A.tableId))==null?void 0:l.filter(m=>m.colIndex===A.colIndex&&m.rowIndex===A.rowIndex),u=d==null?void 0:d.find(m=>Ge(n,o,m.rect));return u&&{...u,rects:[u.rect]}}return this._paragraphBounds.values().find(A=>A.rects.some(d=>Ge(n,o,d)))}_calcActiveParagraphLeft(e){this._buildParagraphBounds();const{x:n,y:o}=e;return this._paragraphLeftBounds.find(r=>Ge(n,o,r.rect))}get paragraphBounds(){return this._buildParagraphBounds(),this._paragraphBounds}findParagraphBoundByIndex(e){this._buildParagraphBounds();const n=this._paragraphBounds.get(e);return n||Array.from(this._tableParagraphBounds.values()).flat().find(a=>a.startIndex===e)}},T.DocEventManagerService=Jc([Zc(1,s.Inject(D.DocSkeletonManagerService))],T.DocEventManagerService);const tl=[ge.id,De.id,Be.id,_e.id,Ne.id,ye.id,Pe.id,Ue.id,we.id];function nl(i){const{avaliableMenus:t=tl}=i,e=v.useDependency(v.IMenuManagerService),[n,o]=U.useState([]);return U.useEffect(()=>{function a(){const c=e.getFlatMenuByPositionKey(v.MenuManagerPosition.RIBBON),l=[];for(const A of t){const d=c.find(u=>u.key===A);d&&l.push(d)}o(l)}a();const r=e.menuChanged$.subscribe(a);return()=>{r.unsubscribe()}},[e]),P.jsx("div",{className:`
|
|
42
|
+
`," ");let a=this._umdToHtml.convert(t);if(t.length===1&&e){a=a.replace(/(<[a-z]+)/,(m,h)=>`${h} data-copy-id="${n}"`);const d=t[0],u={body:d.body};if((l=(c=d.body)==null?void 0:c.customBlocks)!=null&&l.length){u.drawings={};for(const m of d.body.customBlocks){const{blockId:h}=m,g=(A=d.drawings)==null?void 0:A[h];if(g){const p=s.Tools.generateRandomId(6);m.blockId=p,u.drawings[p]={...s.Tools.deepClone(g),drawingId:p}}}}li.set(n,u)}return this._clipboardInterfaceService.write(o,a)}addClipboardHook(t){return this._clipboardHooks.push(t),s.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),o=e!=null?e:this._docSelectionManagerService.getDocRanges(),a=[];let r=!0;if(n==null||o.length===0)return;const c=o[0].segmentId,l=(d=n==null?void 0:n.getSelfOrHeaderFooterModel(c))==null?void 0:d.getBody(),A=n.getSnapshot();if(l!=null){for(const u of o){const{startOffset:m,endOffset:h,collapsed:g,rangeType:p}=u;if(g||m==null||h==null)continue;if(p===s.DOC_RANGE_TYPE.RECT){r=!1;const{spanEntireRow:E}=u;let C;C=Ss(l,m,h),a.push(C);continue}const f={startOffset:m,endOffset:h},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&a.push(S)}return{newSnapshotList:a.map(u=>({...A,body:u})),needCache:r,snapshot:A,ranges:o}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const o=[];for(const a of t)for(const r of a.types)switch(r){case v.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await a.getType(r).then(c=>c&&c.text());break}case v.HTML_CLIPBOARD_MIME_TYPE:{e=await a.getType(r).then(c=>c&&c.text());break}case v.FILE__BMP_CLIPBOARD_MIME_TYPE:case v.FILE__JPEG_CLIPBOARD_MIME_TYPE:case v.FILE__WEBP_CLIPBOARD_MIME_TYPE:case v.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await a.getType(r),l=new File([c],`pasted_image.${r.split("/")[1]}`,{type:r});o.push(l);break}}return!e&&!n&&o.length&&(e=await this._createImagePasteHtml(o)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:s.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const o=Wr(t);if(o){const r=li.get(o);if(r)return r}if(!n){const r=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);n=(r==null?void 0:r.getUnitId())||""}const a=this._htmlToUDM.convert(t,{unitId:n});return o&&li.set(o,a),a}async _createImagePasteHtml(t){var c,l;const e={id:"",documentStyle:{},body:{dataStream:"",customBlocks:[]},drawings:{}},n=async A=>{const d=new FileReader;return new Promise(u=>{d.onloadend=function(){u({source:d.result,imageSourceType:Dn.ImageSourceType.BASE64})},d.readAsDataURL(A)})},o=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const h=Math.min(u,d.naturalWidth),g=d.naturalHeight/d.naturalWidth;m({width:h,height:h*g})}})},a=(l=(c=this._clipboardHooks.find(A=>A.onBeforePasteImage))==null?void 0:c.onBeforePasteImage)!=null?l:n;return await Promise.all(t.map(async(A,d)=>{var S;const u=await a(A);if(!u)return Promise.resolve();const{width:m=100,height:h=100}=await o(A),g=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:g}),f[g]={drawingId:g,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:s.PositionedObjectLayoutType.INLINE,drawingType:s.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:h,angle:0},docTransform:{angle:0,size:{width:m,height:h},positionH:{relativeFrom:s.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:s.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};ui=qr([ft(0,s.IUniverInstanceService),ft(1,s.ILogService),ft(2,s.ICommandService),ft(3,v.IClipboardInterfaceService),ft(4,s.Inject(D.DocSelectionManagerService))],ui);function $t(i){return i.getContextValue(s.FOCUSING_DOC)||i.getContextValue(s.EDITOR_ACTIVATED)}const hi=999,St={id:v.CopyCommand.id,name:"doc.command.copy",type:s.CommandType.COMMAND,multi:!0,priority:hi,preconditions:$t,handler:async i=>i.get(xe).copy()},gi={id:"doc.command.copy-current-paragraph",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(xe),e=mt(i);return e?t.copy(s.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},en={id:v.CutCommand.id,name:"doc.command.cut",type:s.CommandType.COMMAND,multi:!0,priority:hi,preconditions:$t,handler:async i=>i.get(xe).cut()},mi={id:"doc.command.cut-current-paragraph",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(xe),e=mt(i);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:s.DOC_RANGE_TYPE.TEXT}]):!1}},tn={id:v.PasteCommand.id,name:"doc.command.paste",type:s.CommandType.COMMAND,multi:!0,priority:hi,preconditions:$t,handler:async i=>{const t=i.get(xe),n=await i.get(v.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var Jr=Object.getOwnPropertyDescriptor,Zr=(i,t,e,n)=>{for(var o=n>1?void 0:n?Jr(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},pi=(i,t)=>(e,n)=>t(e,n,i);const $r=11,ec=9,nn={ff:"Arial",fs:$r};let Te=class extends s.Disposable{constructor(t,e,n){super();B(this,"_cacheStyle",null);this._textSelectionManagerService=t,this._univerInstanceService=e,this._renderManagerService=n,this._init()}_init(){this._listenDocRangeChange()}_listenDocRangeChange(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(()=>{this._clearStyleCache()}))}getStyleCache(){return this._cacheStyle}getDefaultStyle(){var r;const t=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(t==null)return{...nn};const e=t==null?void 0:t.getUnitId(),n=(r=this._renderManagerService.getRenderById(e))==null?void 0:r.with(D.DocSkeletonManagerService),o=n==null?void 0:n.getViewModel();return o==null?{...nn}:o.getEditArea()===_.DocumentEditArea.BODY?{...nn}:{...nn,fs:ec}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};Te=Zr([pi(0,s.Inject(D.DocSelectionManagerService)),pi(1,s.IUniverInstanceService),pi(2,_.IRenderManagerService)],Te);function fi(i,t,e){const n=[];for(let o=0,a=i.length;o<a;o++)i[o]===s.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:o});if(t)for(const o of n)t.bullet&&(o.bullet=s.Tools.deepClone(t.bullet)),t.paragraphStyle&&(o.paragraphStyle=s.Tools.deepClone(t.paragraphStyle),delete o.paragraphStyle.borderBottom,t.paragraphStyle.headingId&&(o.paragraphStyle.headingId=s.generateRandomId(6)));if(e)for(const o of n)o.paragraphStyle||(o.paragraphStyle={}),o.paragraphStyle.borderBottom=e;return n}const on={id:"doc.command.break-line",type:s.CommandType.COMMAND,handler:(i,t)=>{var Q,j,G,k,W;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),a=i.get(Te),r=(Q=t==null?void 0:t.textRange)!=null?Q:e.getActiveTextRange(),c=e.getRectRanges();if(r==null)return!1;if(c&&c.length){const{startOffset:z}=r;return e.replaceDocRanges([{startOffset:z,endOffset:z}]),!0}const{horizontalLine:l}=t!=null?t:{},{segmentId:A}=r,d=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A!=null?A:"").getBody();if(d==null||u==null)return!1;const m=d.getUnitId(),{startOffset:h,endOffset:g}=r,f=((j=u.paragraphs)!=null?j:[]).find(z=>z.startIndex>=h);if(!f)return!1;const S=h===f.startIndex,E=f.startIndex,C=a.getDefaultStyle(),b=a.getStyleCache(),R=Qt(u,g,C,b),I={dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:fi(s.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...R.ts}}]};if(d==null)return!1;const O=e.getActiveTextRange();if(u==null)return!1;const{collapsed:M}=r,y=I.dataStream.length,N=[{startOffset:h+y,endOffset:h+y,style:O==null?void 0:O.style,collapsed:M}],x={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:N,debounce:!0}},w=new s.TextX,H=s.JSONX.getInstance();if(M)h>0&&w.push({t:s.TextXActionType.RETAIN,len:h}),w.push({t:s.TextXActionType.INSERT,body:I,len:I.dataStream.length});else{const z=s.BuildTextUtils.selection.delete([r],u,0,I);w.push(...z)}(((G=f.bullet)==null?void 0:G.listType)===s.PresetListType.CHECK_LIST_CHECKED||(k=f.paragraphStyle)!=null&&k.headingId)&&(r.endOffset<E&&w.push({t:s.TextXActionType.RETAIN,len:E-r.endOffset}),w.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...f,paragraphStyle:{...f.paragraphStyle,...S?{headingId:void 0,namedStyleType:void 0}:null},startIndex:0,bullet:(W=f.paragraphStyle)!=null&&W.headingId?void 0:{...f.bullet,listType:s.PresetListType.CHECK_LIST}}]},coverType:s.UpdateDocsAttributeType.REPLACE})),x.params.textRanges=[{startOffset:h+y,endOffset:h+y,collapsed:M}];const V=J(d,A);return x.params.actions=H.editOp(w.serialize(),V),!!o.syncExecuteCommand(x.id,x.params)}},vt={id:"doc.command.horizontal-line",type:s.CommandType.COMMAND,handler:(i,t)=>i.get(s.ICommandService).syncExecuteCommand(on.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:s.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},Si={id:"doc.command.insert-horizontal-line-bellow",type:s.CommandType.COMMAND,handler:i=>{const t=i.get(s.ICommandService),e=mt(i);return e?t.syncExecuteCommand(vt.id,{insertRange:{startOffset:e.startIndex+1,endOffset:e.startIndex+1}}):!1}};function ue(i,t,e){return e.executeCommand(be.id,{preCommandId:i,...t!=null?t:{}})}const vs="doc.command.set-inline-format-bold",De={id:vs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(vs,t,e)}},Is="doc.command.set-inline-format-italic",Be={id:Is,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Is,t,e)}},Es="doc.command.set-inline-format-underline",_e={id:Es,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Es,t,e)}},Cs="doc.command.set-inline-format-strikethrough",Ne={id:Cs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Cs,t,e)}},Ts="doc.command.set-inline-format-subscript",ye={id:Ts,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Ts,t,e)}},ys="doc.command.set-inline-format-superscript",Pe={id:ys,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(ys,t,e)}},bs="doc.command.set-inline-format-fontsize",ge={id:bs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(bs,t,e)}},Os="doc.command.set-inline-format-font-family",We={id:Os,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Os,t,e)}},Rs="doc.command.set-inline-format-text-color",Ue={id:Rs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Rs,t,e)}},Ms="doc.command.set-inline-format-text-background-color",we={id:Ms,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(Ms,t,e)}},xs="doc.command.reset-inline-format-text-background-color",tt={id:xs,type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService);return ue(xs,t,e)}},vi={[De.id]:"bl",[Be.id]:"it",[_e.id]:"ul",[Ne.id]:"st",[ge.id]:"fs",[We.id]:"ff",[Ue.id]:"cl",[we.id]:"bg",[tt.id]:"bg",[ye.id]:"va",[Pe.id]:"va"},be={id:"doc.command.set-inline-format",type:s.CommandType.COMMAND,handler:async(i,t)=>{var R;const{value:e,preCommandId:n}=t,o=i.get(s.ICommandService),a=i.get(D.DocSelectionManagerService),r=i.get(s.IUniverInstanceService),c=i.get(Te),l=a.getDocRanges(),A=(R=l.find(I=>I.isActive))!=null?R:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=r.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const h=u.getUnitId();let g;switch(n){case De.id:case Be.id:case _e.id:case Ne.id:case ye.id:case Pe.id:{const I=c.getDefaultStyle(),O=Bs(m,A,I);g=nc(O,n);break}case ge.id:case We.id:{g=e;break}case Ue.id:case we.id:{g={rgb:e};break}case tt.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:l}},f=new s.TextX,S=s.JSONX.getInstance(),E=new s.MemoryCursor;E.reset();for(const I of l){let{startOffset:O,endOffset:M,rangeType:y}=I;if(O==null||M==null)continue;if(y===s.DOC_RANGE_TYPE.RECT&&(O=O-1),O===M){const w=c.getStyleCache(),H=vi[n];c.setStyleCache({[H]:(w==null?void 0:w[H])!==void 0?Ds(w,H,n):g});continue}const N={dataStream:"",textRuns:[{st:0,ed:M-O,ts:{[vi[n]]:g}}]},x=O-E.cursor;x!==0&&f.push({t:s.TextXActionType.RETAIN,len:x}),f.push({t:s.TextXActionType.RETAIN,body:N,len:M-O}),E.reset(),E.moveCursor(M)}const C=J(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!o.syncExecuteCommand(p.id,p.params)}};function tc(i){return i!==null&&typeof i=="object"}function Ds(i,t,e){if(/bl|it/.test(t))return(i==null?void 0:i[t])===s.BooleanNumber.TRUE?s.BooleanNumber.FALSE:s.BooleanNumber.TRUE;if(/ul|st/.test(t))return tc(i==null?void 0:i[t])&&(i==null?void 0:i[t]).s===s.BooleanNumber.TRUE?{s:s.BooleanNumber.FALSE}:{s:s.BooleanNumber.TRUE};if(/va/.test(t))return e===ye.id?(i==null?void 0:i[t])===s.BaselineOffset.SUBSCRIPT?s.BaselineOffset.NORMAL:s.BaselineOffset.SUBSCRIPT:(i==null?void 0:i[t])===s.BaselineOffset.SUPERSCRIPT?s.BaselineOffset.NORMAL:s.BaselineOffset.SUPERSCRIPT}function Bs(i,t,e){var d,u,m,h,g,p,f,S,E,C,b,R,I,O;const{startOffset:n,endOffset:o,collapsed:a}=t;if(a){const M=(d=i.textRuns)!=null?d:[];let y=null;for(let N=M.length-1;N>=0;N--){const x=M[N];if(x.st<n&&n<=x.ed){y=x;break}}return y!=null&&y.ts?{...e,...y.ts}:e}const{textRuns:r=[]}=s.getBodySlice(i,n,o),c=s.Tools.deepClone(e),l=r.map(M=>{var y;return(y=M==null?void 0:M.ts)==null?void 0:y.fs}).filter(Boolean);c.fs=c.fs?Math.max(c.fs,...l):l.length?Math.max(...l):void 0,c.fs=!c.fs||Number.isNaN(c.fs)?void 0:c.fs,c.ff=(h=(m=(u=r.find(M=>{var y;return((y=M.ts)==null?void 0:y.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?h:c.ff,c.it=r.length&&r.every(M=>{var y;return((y=M.ts)==null?void 0:y.it)===s.BooleanNumber.TRUE})?s.BooleanNumber.TRUE:s.BooleanNumber.FALSE,c.bl=r.length&&r.every(M=>{var y;return((y=M.ts)==null?void 0:y.bl)===s.BooleanNumber.TRUE})?s.BooleanNumber.TRUE:s.BooleanNumber.FALSE,c.ul=r.length&&r.every(M=>{var y,N;return((N=(y=M.ts)==null?void 0:y.ul)==null?void 0:N.s)===s.BooleanNumber.TRUE})?(g=r[0].ts)==null?void 0:g.ul:c.ul,c.st=r.length&&r.every(M=>{var y,N;return((N=(y=M.ts)==null?void 0:y.st)==null?void 0:N.s)===s.BooleanNumber.TRUE})?(p=r[0].ts)==null?void 0:p.st:c.st,c.bg=(E=(S=(f=r.find(M=>{var y;return((y=M.ts)==null?void 0:y.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(b=(C=r.find(M=>{var y;return((y=M.ts)==null?void 0:y.cl)!=null}))==null?void 0:C.ts)==null?void 0:b.cl)!=null?R:c.cl;const A=r.filter(M=>{var y;return((y=M==null?void 0:M.ts)==null?void 0:y.va)!=null});if(A.length>0&&A.length===r.length){const M=(I=A[0].ts)==null?void 0:I.va;let y=!0;for(let N=1;N<A.length;N++)if(((O=A[N].ts)==null?void 0:O.va)!==M){y=!1;break}y&&(c.va=M)}return c}function nc(i,t){const e=vi[t];return Ds(i,e,t)}const nt={id:"doc.command.list-operation",type:s.CommandType.COMMAND,handler:(i,t)=>{var b,R,I,O,M,y;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),a=t.listType,r=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),c=(R=(b=t.docRange)!=null?b:e.getDocRanges())!=null?R:[];if(r==null||c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(O=(I=A.getBody())==null?void 0:I.paragraphs)!=null?O:[],u=(y=(M=A.getBody())==null?void 0:M.dataStream)!=null?y:"";if(!d.length)return!1;const m=s.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}};new s.MemoryCursor().reset();const f=s.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:a,document:r,segmentId:l}),S=s.JSONX.getInstance(),E=J(r,l);return g.params.actions=S.editOp(f.serialize(),E),!!o.syncExecuteCommand(g.id,g.params)}},It={id:"doc.command.change-list-type",type:s.CommandType.COMMAND,handler:(i,t)=>{var C,b,R,I,O;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),{listType:a}=t,r=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(r==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=r.getSelfOrHeaderFooterModel(l),d=(R=(b=A.getBody())==null?void 0:b.paragraphs)!=null?R:[],u=(O=(I=A.getBody())==null?void 0:I.dataStream)!=null?O:"";if(!d.length)return!1;const m=s.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=s.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:a,segmentId:l,document:r});if(!g)return!1;const p=s.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}},S=J(r,l);return f.params.actions=p.editOp(g.serialize(),S),!!o.syncExecuteCommand(f.id,f.params)}};var Et=(i=>(i[i.increase=1]="increase",i[i.decrease=-1]="decrease",i))(Et||{});const sn={id:"doc.command.change-list-nesting-level",type:s.CommandType.COMMAND,handler:(i,t)=>{var b,R,I,O,M;if(!t)return!1;const{type:e}=t,n=i.get(D.DocSelectionManagerService),o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),r=o.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null)return!1;const{segmentId:l}=c,A=(b=n.getDocRanges())!=null?b:[],d=r.getSelfOrHeaderFooterModel(l),u=(I=(R=d.getBody())==null?void 0:R.paragraphs)!=null?I:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"";if(!u.length)return!1;const h=s.BuildTextUtils.range.getParagraphsInRange(c,u,m),g=r.getUnitId(),p=s.JSONX.getInstance(),f=s.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:h,type:e,segmentId:l,document:r}),S={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:A,isEditing:!1}},E=J(r,l);return S.params.actions=p.editOp(f.serialize(),E),!!a.syncExecuteCommand(S.id,S.params)}},it={id:"doc.command.bullet-list",type:s.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(s.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(nt.id,{listType:s.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Ct={id:"doc.command.check-list",type:s.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(s.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(nt.id,{listType:s.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},Ii={id:"doc.command.toggle-check-list",type:s.CommandType.COMMAND,handler:(i,t)=>{var p;if(!t)return!1;const e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),{index:o,segmentId:a,textRanges:r}=t,c=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(c==null||((p=c.getSelfOrHeaderFooterModel(a).getBody())==null?void 0:p.paragraphs)==null)return!1;const A=c.getUnitId(),d={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:r!=null?r:[],segmentId:a,isEditing:!1}},u=s.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:o,segmentId:a});if(!u)return!1;const m=s.JSONX.getInstance(),h=J(c,a);return d.params.actions=m.editOp(u.serialize(),h),!!n.syncExecuteCommand(d.id,d.params)}},ot={id:"doc.command.order-list",type:s.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(s.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value}):e.syncExecuteCommand(nt.id,{listType:s.PresetListType.ORDER_LIST})}},Ei={id:"doc.command.quick-list",type:s.CommandType.COMMAND,handler(i,t){var X,Y,q,K,Z;if(!t)return!1;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),a=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),r=e.getActiveTextRange();if(a==null||r==null)return!1;const{segmentId:c,startOffset:l}=r,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,h=new s.TextX,g=s.JSONX.getInstance(),{defaultTabStop:p=36}=a.getSnapshot().documentStyle,f=(Y=(X=a.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:X.sectionBreaks)!=null?Y:[],{startIndex:S,paragraphStyle:E={}}=d,{indentFirstLine:C,snapToGrid:b,indentStart:R}=E,I=s.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{},{hanging:O,indentStart:M}=I,y=I.textStyle,{charSpace:N,gridType:x}=ic(S,f)||{charSpace:0,gridType:s.GridType.LINES},w=_.getCharSpaceApply(N,p,x,b);let V=s.Tools.generateRandomId(6);const F=(K=(q=a.getBody())==null?void 0:q.paragraphs)!=null?K:[],Q=F.findIndex(ie=>ie.startIndex===d.startIndex),j=F[Q-1],G=F[Q+1];j&&j.bullet&&j.bullet.listType.indexOf(A)===0?V=j.bullet.listId:G&&G.bullet&&G.bullet.listType.indexOf(A)===0&&(V=G.bullet.listId);const k={id:D.RichTextEditingMutation.id,params:{unitId:a.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};h.push({t:s.TextXActionType.RETAIN,len:u}),h.push({t:s.TextXActionType.DELETE,len:l-u}),m>l&&h.push({t:s.TextXActionType.RETAIN,len:m-l}),h.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...E,textStyle:{...E.textStyle,...y},indentFirstLine:void 0,hanging:O,indentStart:{v:_.getNumberUnitValue(M,w)-_.getNumberUnitValue(O,w)+_.getNumberUnitValue(C,w)+_.getNumberUnitValue(R,w)}},bullet:{...(Z=d.bullet)!=null?Z:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:V}}]}});const W=J(a,c);return k.params.actions=g.editOp(h.serialize(),W),!!o.syncExecuteCommand(k.id,k.params)}};function Ci(i,t){var d,u;const e=i.get(s.ICommandService),n=mt(i);if(!n)return!1;const o=i.get(s.IUniverInstanceService).getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC);if(!o)return!1;const a=s.BuildTextUtils.selection.replace({doc:o,selection:{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0},body:{dataStream:"\r",paragraphs:[{startIndex:0,paragraphStyle:{...n.paragraphStyle},bullet:{listType:t,listId:((d=n.bullet)==null?void 0:d.listType)===t?n.bullet.listId:s.Tools.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!a)return!1;const r={id:D.RichTextEditingMutation.id,params:{unitId:o.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=s.JSONX.getInstance(),l=J(o);return r.params.actions=c.editOp(a.serialize(),l),!!e.syncExecuteCommand(r.id,r.params)}const Ti={id:"doc.command.insert-bullet-list-bellow",type:s.CommandType.COMMAND,handler:i=>Ci(i,s.PresetListType.BULLET_LIST)},yi={id:"doc.command.insert-order-list-bellow",type:s.CommandType.COMMAND,handler:i=>Ci(i,s.PresetListType.ORDER_LIST)},bi={id:"doc.command.insert-check-list-bellow",type:s.CommandType.COMMAND,handler:i=>Ci(i,s.PresetListType.CHECK_LIST)};function ic(i,t){const e=t.sort(s.sortRulesFactory("startIndex"));for(let n=0;n<e.length;n++){const o=t[n];if(o.startIndex>=i)return o}}const de={id:"doc.command.set-paragraph-named-style",type:s.CommandType.COMMAND,handler(i,t){var g;if(!t)return!1;const n=i.get(s.IUniverInstanceService).getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const o=n.getUnitId(),a=i.get(D.DocSelectionManagerService),r=(g=t.textRanges)!=null?g:a.getTextRanges({unitId:o,subUnitId:o});if(!(r!=null&&r.length))return!1;const c=r[0].segmentId,l=s.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:r,style:{namedStyleType:t.value,headingId:!t.value||t.value===s.NamedStyleType.NORMAL_TEXT?void 0:s.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0},paragraphTextRun:{}}),A={id:D.RichTextEditingMutation.id,params:{actions:[],textRanges:r,unitId:o,segmentId:c}},d=s.JSONX.getInstance(),u=J(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!i.get(s.ICommandService).syncExecuteCommand(A.id,A.params)}},_s={id:"doc.command.quick-heading",type:s.CommandType.COMMAND,handler(i,t){var R,I,O,M;if(!t)return!1;const{value:e}=t,n=i.get(D.DocSelectionManagerService),o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),r=o.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=r.getSelfOrHeaderFooterModel(l),u=(I=(R=d.getBody())==null?void 0:R.paragraphs)!=null?I:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"",h=s.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!h)return!1;const{paragraphStart:g}=h,p=new s.TextX,f=s.JSONX.getInstance(),{paragraphStyle:S={}}=h,E={id:D.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:g,endOffset:g,collapsed:!0}],isEditing:!1}};p.push({t:s.TextXActionType.RETAIN,len:g}),s.BuildTextUtils.paragraph.style.set({textRanges:[c],document:r,style:{...S,headingId:s.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-g,textX:p,paragraphTextRun:{}});const C=J(r,l);return E.params.actions=f.editOp(p.serialize(),C),!!a.syncExecuteCommand(E.id,E.params)}},Oi={"#":s.NamedStyleType.HEADING_1,"##":s.NamedStyleType.HEADING_2,"###":s.NamedStyleType.HEADING_3,"####":s.NamedStyleType.HEADING_4,"#####":s.NamedStyleType.HEADING_5},Ri={id:"doc.command.h1-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_1})},Mi={id:"doc.command.h2-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_2})},xi={id:"doc.command.h3-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_3})},Di={id:"doc.command.h4-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_4})},Bi={id:"doc.command.h5-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.HEADING_5})},an={id:"doc.command.normal-text-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.NORMAL_TEXT})},Ns={id:"doc.command.title",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.TITLE})},Ps={id:"doc.command.subtitle-heading",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(de.id,{value:s.NamedStyleType.SUBTITLE})},me={id:"doc.command.align-action",type:s.CommandType.COMMAND,handler:(i,t)=>{var R,I,O,M;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),{alignType:a}=t,r=n.getCurrentUniverDocInstance();if(r==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(I=(R=A.getBody())==null?void 0:R.paragraphs)!=null?I:[],u=(M=(O=A.getBody())==null?void 0:O.dataStream)!=null?M:"";if(d==null)return!1;const m=s.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=m.every(y=>{var N;return((N=y.paragraphStyle)==null?void 0:N.horizontalAlign)===a}),p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c}},f=new s.MemoryCursor;f.reset();const S=new s.TextX,E=s.JSONX.getInstance();for(const y of m){const{startIndex:N}=y;S.push({t:s.TextXActionType.RETAIN,len:N-f.cursor});const x={...y.paragraphStyle,horizontalAlign:g?s.HorizontalAlign.UNSPECIFIED:a};S.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...y,paragraphStyle:x,startIndex:0}]},coverType:s.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(N+1)}const C=J(r,l);return p.params.actions=E.editOp(S.serialize(),C),!!o.syncExecuteCommand(p.id,p.params)}},Tt={id:"doc.command.align-left",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(me.id,{alignType:s.HorizontalAlign.LEFT})},yt={id:"doc.command.align-center",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(me.id,{alignType:s.HorizontalAlign.CENTER})},bt={id:"doc.command.align-right",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(me.id,{alignType:s.HorizontalAlign.RIGHT})},Ot={id:"doc.command.align-justify",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(me.id,{alignType:s.HorizontalAlign.JUSTIFIED})},Rt={id:"doc.command.switch-mode",type:s.CommandType.COMMAND,handler:i=>{var E,C,b,R,I;const t=i.get(s.ICommandService),e=i.get(_.IRenderManagerService),n=i.get(D.DocSelectionManagerService),a=i.get(s.IUniverInstanceService).getCurrentUniverDocInstance();if(a==null)return!1;const r=a.getUnitId(),c=(E=e.getRenderById(r))==null?void 0:E.with(D.DocSkeletonManagerService).getSkeleton(),l=(C=e.getRenderById(r))==null?void 0:C.with(T.DocSelectionRenderService);if(c==null||l==null)return!1;const A=l==null?void 0:l.getSegment(),d=l==null?void 0:l.getSegmentPage(),u=a.getSnapshot().documentStyle.documentFlavor,m=n.getDocRanges(),h={id:D.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:u===s.DocumentFlavor.TRADITIONAL&&A?[]:m}},g=s.JSONX.getInstance(),p=[];let f;if(u===void 0?f=g.insertOp(["documentStyle","documentFlavor"],s.DocumentFlavor.MODERN):u===s.DocumentFlavor.MODERN?f=g.replaceOp(["documentStyle","documentFlavor"],u,s.DocumentFlavor.TRADITIONAL):f=g.replaceOp(["documentStyle","documentFlavor"],u,s.DocumentFlavor.MODERN),f)p.push(f);else return!1;if(u!==s.DocumentFlavor.MODERN){const O=a.getSnapshot(),{drawings:M={},body:y}=O,N=(b=y==null?void 0:y.customBlocks)!=null?b:[];for(const x in M){const w=M[x],H=N.find(Z=>Z.blockId===x);if(H==null)continue;const V=w.docTransform.positionV,{relativeFrom:F,posOffset:Q}=V;if(F===s.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:j}=H,G=c.findNodeByCharIndex(j,A,d),k=(R=G==null?void 0:G.parent)==null?void 0:R.parent,W=k==null?void 0:k.parent,z=W==null?void 0:W.lines.find(Z=>Z.paragraphIndex===(k==null?void 0:k.paragraphIndex)&&Z.paragraphStart),X=(I=W==null?void 0:W.parent)==null?void 0:I.parent;if(G==null||k==null||z==null||W==null||X==null)continue;let Y=0;F===s.ObjectRelativeFromV.LINE?Y-=k.top:F===s.ObjectRelativeFromV.PAGE&&(Y+=X.marginTop),Y+=z.top;const q={...V,relativeFrom:s.ObjectRelativeFromV.PARAGRAPH,posOffset:(Q!=null?Q:0)-Y},K=g.replaceOp(["drawings",x,"docTransform","positionV"],V,q);K&&p.push(K)}}return h.params.actions=p.reduce((O,M)=>s.JSONX.compose(O,M),null),!!t.syncExecuteCommand(h.id,h.params)}},Us="COMPONENT_DOC_CREATE_TABLE_CONFIRM",_i={id:"doc.command.create-table",type:s.CommandType.COMMAND,handler:async(i,t)=>{var q,K,Z,ie,fe;const{rowCount:e,colCount:n}=t,o=i.get(D.DocSelectionManagerService),a=i.get(s.IUniverInstanceService),r=i.get(s.ICommandService),c=i.get(Te),l=o.getActiveTextRange();if(l==null)return!1;const{segmentId:A,segmentPage:d}=l,u=a.getCurrentUniverDocInstance(),m=u==null?void 0:u.getSelfOrHeaderFooterModel(A).getBody();if(u==null||m==null)return!1;const h=u.getUnitId(),g=re(i,h),p=g==null?void 0:g.getSkeleton();if(p==null)return!1;const{startOffset:f}=l,E=((q=m.paragraphs)!=null?q:[]).find(Fe=>Fe.startIndex>=f),C=p.findNodeByCharIndex(f,A,d);if(C==null)return!1;const b=new s.TextX,R=s.JSONX.getInstance(),I=[],O=f+4,M=[{startOffset:O,endOffset:O,collapsed:!0}],y={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:M}};f>0&&b.push({t:s.TextXActionType.RETAIN,len:f}),b.push({t:s.TextXActionType.INSERT,body:{dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:fi(s.DataStreamTreeTokenType.PARAGRAPH,E)},len:1});const N=c.getDefaultStyle(),x=c.getStyleCache(),w=Qt(m,f,N,x),{dataStream:H,paragraphs:V,sectionBreaks:F}=Rr(e,n),Q=(fe=(ie=(Z=(K=C.parent)==null?void 0:K.parent)==null?void 0:Z.parent)==null?void 0:ie.parent)==null?void 0:fe.parent;if(Q==null)return!1;const{pageWidth:j,marginLeft:G,marginRight:k}=Q,W=ni(e,n,j-G-k);b.push({t:s.TextXActionType.INSERT,body:{dataStream:H,paragraphs:V,sectionBreaks:F,textRuns:[{...w,st:0,ed:H.length}],tables:[{startIndex:0,endIndex:H.length,tableId:W.tableId}]},len:H.length});const z=J(u,A);I.push(R.editOp(b.serialize(),z));const X=R.insertOp(["tableSource",W.tableId],W);return I.push(X),y.params.actions=I.reduce((Fe,Se)=>s.JSONX.compose(Fe,Se),null),!!r.syncExecuteCommand(y.id,y.params)}},Ni="doc.component.create-table-confirm",rn={id:"doc.operation.create-table",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(s.LocaleService),e=i.get(v.IConfirmService),n=i.get(s.ICommandService),o={rowCount:3,colCount:5},a=(r,c)=>{o.rowCount=r,o.colCount=c};return await e.open({id:Ni,children:{label:{name:Us,props:{handleRowColChange:a,tableCreateParams:o}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(_i.id,o),e.close(Ni)},onClose:()=>{e.close(Ni)}}),!0}},oc=i=>{const e=Object.keys(s.PAGE_SIZE).find(n=>{const{width:o,height:a}=s.PAGE_SIZE[n];return i.width===o&&i.height===a});return e!=null?e:"A4"};function sc(i){const{hooks:t}=i,o=v.useDependency(s.IUniverInstanceService).getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC).getDocumentStyle(),a=v.useDependency(s.LocaleService),[r,c]=U.useState(()=>{var d,u,m,h,g;return{paperSize:oc(o.pageSize),orientation:(d=o.pageOrient)!=null?d:s.PageOrientType.PORTRAIT,margins:{top:(u=o.marginTop)!=null?u:0,bottom:(m=o.marginBottom)!=null?m:0,left:(h=o.marginLeft)!=null?h:0,right:(g=o.marginRight)!=null?g:0}}});U.useEffect(()=>{t.beforeClose=()=>r,t.beforeConfirm=()=>r},[r]);const l=d=>{c(u=>({...u,paperSize:d}))},A=(d,u)=>{c(m=>({...m,margins:{...m.margins,[d]:u||0}}))};return P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-4",children:[P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-900",children:a.t("page-settings.paper-size")}),P.jsx(ee.Select,{value:r.paperSize,onChange:l,options:s.PAPER_TYPES.map(d=>({label:a.t(`page-settings.page-size.${d.toLocaleLowerCase()}`),value:d}))})]}),P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-[#0E111E]",children:a.t("page-settings.custom-paper-size")}),P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:a.t("page-settings.top")}),P.jsx(ee.InputNumber,{value:r.margins.top,onChange:d=>A("top",d)})]}),P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:a.t("page-settings.bottom")}),P.jsx(ee.InputNumber,{value:r.margins.bottom,onChange:d=>A("bottom",d)})]})]}),P.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:a.t("page-settings.left")}),P.jsx(ee.InputNumber,{value:r.margins.left,onChange:d=>A("left",d)})]}),P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:a.t("page-settings.right")}),P.jsx(ee.InputNumber,{value:r.margins.right,onChange:d=>A("right",d)})]})]})]})]})]})}const Pi="docs.component.page-setting",ws={id:"docs.command.page-setup",type:s.CommandType.COMMAND,handler:(i,t)=>{if(!t)return!1;const e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=e.getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC);if(!o)return!1;const{marginLeft:a,marginRight:r,marginBottom:c,marginTop:l,pageOrient:A,pageSize:d}=t,u=s.JSONX.getInstance(),m=o.getDocumentStyle(),{marginBottom:h,marginLeft:g,marginRight:p,marginTop:f,pageOrient:S,pageSize:E}=m,C=[];if(h===void 0){const I=u.insertOp(["documentStyle","marginBottom"],c);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","marginBottom"],h,c);I&&C.push(I)}if(g===void 0){const I=u.insertOp(["documentStyle","marginLeft"],a);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","marginLeft"],g,a);I&&C.push(I)}if(p===void 0){const I=u.insertOp(["documentStyle","marginRight"],r);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","marginRight"],p,r);I&&C.push(I)}if(f===void 0){const I=u.insertOp(["documentStyle","marginTop"],l);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","marginTop"],f,l);I&&C.push(I)}if(E===void 0){const I=u.insertOp(["documentStyle","pageSize"],d);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","pageSize"],E,d);I&&C.push(I)}if(S===void 0){const I=u.insertOp(["documentStyle","pageOrient"],A);I&&C.push(I)}else{const I=u.replaceOp(["documentStyle","pageOrient"],S,A);I&&C.push(I)}const b={id:D.RichTextEditingMutation.id,params:{unitId:o.getUnitId(),actions:[],textRanges:void 0}};return b.params.actions=C.reduce((I,O)=>s.JSONX.compose(I,O),null),!!n.syncExecuteCommand(b.id,b.params)}},Ui={id:"docs.operation.open-page-setting",type:s.CommandType.OPERATION,handler:i=>{const t=i.get(v.IConfirmService),e=i.get(s.ICommandService),n=i.get(s.LocaleService),o=t.open({id:Pi,title:{label:n.t("page-settings.document-setting")},children:{label:Pi},width:528,onClose:()=>{o.dispose()},onConfirm:a=>{if(o.dispose(),!a)return;const r=s.PAGE_SIZE[a.paperSize];e.executeCommand(ws.id,{pageOrient:a.orientation,marginTop:a.margins.top,marginBottom:a.margins.bottom,marginLeft:a.margins.left,marginRight:a.margins.right,pageSize:r})}});return!0}};function ac(i){const t=i.get(s.IUniverInstanceService),e=i.get(_.IRenderManagerService);return new L.Observable(n=>{const o=t.focused$.subscribe(a=>{if(a==null||t.getUnitType(a)!==s.UniverInstanceType.UNIVER_DOC)return n.next(!0);const c=e.getRenderById(a);if(c==null)return n.next(!0);c.with(D.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(A=>{n.next(A===_.DocumentEditArea.HEADER||A===_.DocumentEditArea.FOOTER)})});return()=>o.unsubscribe()})}function rc(i){const t=i.get(s.IUniverInstanceService),e=i.get(s.ICommandService);return new L.Observable(n=>{const o=e.onCommandExecuted(l=>{if(l.id===D.RichTextEditingMutation.id){const{unitId:A}=l.params,d=t.getUnit(A);if(d==null){n.next(!0);return}const{documentStyle:u}=d.getSnapshot();n.next((u==null?void 0:u.documentFlavor)!==s.DocumentFlavor.TRADITIONAL)}}),a=t.focused$.subscribe(l=>{if(l==null)return n.next(!0);const A=t.getUniverDocInstance(l),d=A==null?void 0:A.getSnapshot().documentStyle.documentFlavor;n.next(d!==s.DocumentFlavor.TRADITIONAL)}),r=t.getCurrentUniverDocInstance();if(r==null)return n.next(!0);const c=r==null?void 0:r.getSnapshot().documentStyle.documentFlavor;return n.next(c!==s.DocumentFlavor.TRADITIONAL),()=>{o.dispose(),a.unsubscribe()}})}function cc(i){const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService);return new L.Observable(n=>{const o=t.textSelection$.subscribe(a=>{if(a==null){n.next(!0);return}const{textRanges:r}=a;if(r.length!==1){n.next(!0);return}const c=r[0],{collapsed:l,startNodePosition:A,startOffset:d}=c;if(!l||d==null){n.next(!0);return}const u=e.getCurrentUniverDocInstance();if(u==null){n.next(!0);return}const m=re(i,u.getUnitId());if(m==null){n.next(!0);return}if(m.getViewModel().getCustomRangeRaw(d)){n.next(!0);return}if(A!=null){const{path:p}=A;if(p.indexOf("cells")!==-1){n.next(!0);return}}n.next(!1)});return()=>o.unsubscribe()})}function te(i){const t=i.get(D.DocSelectionManagerService);return new L.Observable(e=>{const n=t.textSelection$.subscribe(o=>{if(o==null){e.next(!0);return}const{textRanges:a,rectRanges:r}=o;if(a.length===0&&r.length===0){e.next(!0);return}e.next(!1)});return()=>n.unsubscribe()})}function lc(i){const t=i.get(s.ICommandService);return{id:De.id,type:v.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.bl;e.next(r===s.BooleanNumber.TRUE)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function dc(i){const t=i.get(s.ICommandService);return{id:Be.id,type:v.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.it;e.next(r===s.BooleanNumber.TRUE)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function Ac(i){const t=i.get(s.ICommandService);return{id:_e.id,type:v.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.ul;e.next((r==null?void 0:r.s)===s.BooleanNumber.TRUE)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function uc(i){const t=i.get(s.ICommandService);return{id:Ne.id,type:v.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.st;e.next((r==null?void 0:r.s)===s.BooleanNumber.TRUE)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function hc(i){const t=i.get(s.ICommandService);return{id:ye.id,type:v.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.va;e.next(r===s.BaselineOffset.SUBSCRIPT)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function gc(i){const t=i.get(s.ICommandService);return{id:Pe.id,type:v.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new L.Observable(e=>{const n=()=>{var c;const a=Le(i);if(a==null){e.next(!1);return}const r=(c=a.ts)==null?void 0:c.va;e.next(r===s.BaselineOffset.SUPERSCRIPT)},o=t.onCommandExecuted(a=>{const r=a.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),o.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function mc(i){const t=i.get(s.ICommandService);return{id:We.id,tooltip:"toolbar.font",type:v.MenuItemType.SELECTOR,label:qo,selections:v.FONT_FAMILY_LIST.map(e=>({label:{name:Jo},value:e.value})),value$:new L.Observable(e=>{const n=s.DEFAULT_STYLES.ff,o=()=>{var l;const r=Le(i);if(r==null){e.next(n);return}const c=(l=r.ts)==null?void 0:l.ff;e.next(c!=null?c:n)},a=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===We.id)&&o()});return o(),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function pc(i){const t=i.get(s.ICommandService);return{id:ge.id,type:v.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Zo,props:{min:1,max:400}},selections:v.FONT_SIZE_LIST,value$:new L.Observable(e=>{const n=s.DEFAULT_STYLES.fs,o=()=>{var l;const r=Le(i);if(r==null){e.next(n);return}const c=(l=r.ts)==null?void 0:l.fs;e.next(c!=null?c:n)},a=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===ge.id)&&o()});return o(),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function fc(i){const t=i.get(s.ICommandService);return{id:de.id,type:v.MenuItemType.SELECTOR,tooltip:"toolbar.heading.tooltip",label:{name:v.COMMON_LABEL_COMPONENT,props:{selections:v.HEADING_LIST}},selections:v.HEADING_LIST.map(e=>({label:{name:v.HEADING_ITEM_COMPONENT,props:{value:e.value,text:e.label}},value:e.value})),value$:new L.Observable(e=>{const n=s.NamedStyleType.NORMAL_TEXT,o=()=>{var l,A;const r=ze(i);if(r==null){e.next(n);return}const c=(A=(l=r.paragraphStyle)==null?void 0:l.namedStyleType)!=null?A:n;e.next(c)},a=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===ge.id)&&o()});return o(),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function Sc(i){const t=i.get(s.ICommandService),e=i.get(s.ThemeService);return{id:Ue.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:v.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:ei,hoverable:!1,selectable:!1}}],value$:new L.Observable(n=>{const o=e.getColorFromTheme("gray.900"),a=t.onCommandExecuted(r=>{if(r.id===Ue.id){const c=r.params.value;n.next(c!=null?c:o)}});return n.next(o),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function vc(i){return{id:Zn.id,type:v.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:L.combineLatest(v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),rc(i),(t,e)=>t||e)}}const Ic="GridSingle",Ls="doc.menu.table";function Ec(i){return{id:Ls,type:v.MenuItemType.SUBITEMS,icon:Ic,tooltip:"toolbar.table.main",disabled$:cc(i),hidden$:L.combineLatest(v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),ac(i),(t,e)=>t||e)}}function Cc(i){return{id:rn.id,title:"toolbar.table.insert",type:v.MenuItemType.BUTTON,hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function Tc(i){const t=i.get(s.ICommandService);return{id:Tt.id,type:v.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:te(i),activated$:new L.Observable(e=>{const n=t.onCommandExecuted(o=>{var r;const a=o.id;if(a===D.SetTextSelectionsOperation.id||a===me.id){const c=ze(i);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===s.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function yc(i){const t=i.get(s.ICommandService);return{id:yt.id,type:v.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(o=>{var r;const a=o.id;if(a===D.SetTextSelectionsOperation.id||a===me.id){const c=ze(i);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===s.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function bc(i){const t=i.get(s.ICommandService);return{id:bt.id,type:v.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(o=>{var r;const a=o.id;if(a===D.SetTextSelectionsOperation.id||a===me.id){const c=ze(i);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===s.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Oc(i){const t=i.get(s.ICommandService);return{id:Ot.id,type:v.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(o=>{var r;const a=o.id;if(a===D.SetTextSelectionsOperation.id||a===me.id){const c=ze(i);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===s.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Rc(i){return{id:vt.id,type:v.MenuItemType.BUTTON,icon:"ReduceSingle",tooltip:"toolbar.horizontalLine",disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const Mt=i=>new L.Observable(t=>{const e=i.get(s.IUniverInstanceService),n=i.get(D.DocSelectionManagerService);let o;const a=e.focused$.subscribe(r=>{if(o==null||o.unsubscribe(),r==null)return;const c=e.getUniverDocInstance(r);c!=null&&(o=n.textSelection$.subscribe(()=>{var d,u,m,h,g;const l=n.getDocRanges(),A=(d=l.find(p=>p.isActive))!=null?d:l[0];if(A){const p=c.getSelfOrHeaderFooterModel(A==null?void 0:A.segmentId),f=s.BuildTextUtils.range.getParagraphsInRange(A,(m=(u=p.getBody())==null?void 0:u.paragraphs)!=null?m:[],(g=(h=p.getBody())==null?void 0:h.dataStream)!=null?g:"");let S;if(f.every(E=>{var C;return S||(S=(C=E.bullet)==null?void 0:C.listType),E.bullet&&E.bullet.listType===S})){t.next(S);return}}t.next(void 0)}))});return()=>{a.unsubscribe(),o==null||o.unsubscribe()}});function Qs(i){return{id:ot.id,type:v.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:es,hoverable:!1,selectable:!1},value$:Mt(i)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC),disabled$:te(i),activated$:Mt(i).pipe(L.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function Fs(i){return{id:it.id,type:v.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:ts,hoverable:!1,selectable:!1},value$:Mt(i)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC),activated$:Mt(i).pipe(L.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function Hs(i){return{id:Ct.id,type:v.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC),activated$:Mt(i).pipe(L.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Mc(i){const t=i.get(s.ICommandService),e=i.get(s.IUniverInstanceService);return{id:Rt.id,type:v.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC,void 0,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new L.Observable(n=>{var r;const o=t.onCommandExecuted(c=>{var l;if(c.id===D.RichTextEditingMutation.id){const A=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);n.next(((l=A==null?void 0:A.getSnapshot())==null?void 0:l.documentStyle.documentFlavor)===s.DocumentFlavor.MODERN)}}),a=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);return n.next(((r=a==null?void 0:a.getSnapshot())==null?void 0:r.documentStyle.documentFlavor)===s.DocumentFlavor.MODERN),()=>o.dispose()})}}function xc(i){return{id:tt.id,type:v.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function Dc(i){const t=i.get(s.ICommandService),e=i.get(s.ThemeService);return{id:we.id,tooltip:"toolbar.fillColor.main",type:v.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:ei,hoverable:!1,selectable:!1}}],value$:new L.Observable(n=>{const o=e.getColorFromTheme("primary.600"),a=t.onCommandExecuted(r=>{if(r.id===we.id){const c=r.params.value;n.next(c!=null?c:o)}});return n.next(o),a.dispose}),disabled$:te(i),hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}function Le(i){var g,p,f,S;const t=i.get(s.IUniverInstanceService),e=i.get(D.DocSelectionManagerService),n=i.get(Te),o=t.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),a=e.getDocRanges(),r=(g=a.find(E=>E.isActive))!=null?g:a[0],c=n.getDefaultStyle(),l=(p=n.getStyleCache())!=null?p:{},A=ze(i),d=(f=A==null?void 0:A.paragraphStyle)!=null&&f.namedStyleType?s.NAMED_STYLE_MAP[(S=A==null?void 0:A.paragraphStyle)==null?void 0:S.namedStyleType]:null;if(o==null||r==null)return{ts:{...c,...d,...l}};const{segmentId:u}=r,m=o.getSelfOrHeaderFooterModel(u).getBody();if(m==null)return{ts:{...c,...d,...l}};const h=Bs(m,r,{});return s.Tools.deleteNull(h),{ts:{...c,...d,...h,...l}}}function ze(i){var d,u;const t=i.get(s.IUniverInstanceService),e=i.get(D.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),o=e.getDocRanges(),a=(d=o.find(m=>m.isActive))!=null?d:o[0];if(n==null||a==null)return;const{startOffset:r,segmentId:c}=a,l=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(l==null)return;let A=-1;for(const m of l){const{startIndex:h}=m;if(r>A&&r<=h)return m;A=h}return null}function Bc(i){return{id:Ui.id,type:v.MenuItemType.BUTTON,icon:"DocumentSettingSingle",tooltip:"toolbar.pageSetup",hidden$:v.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_DOC)}}const _c={[s.NamedStyleType.HEADING_1]:Ri,[s.NamedStyleType.HEADING_2]:Mi,[s.NamedStyleType.HEADING_3]:xi,[s.NamedStyleType.HEADING_4]:Di,[s.NamedStyleType.HEADING_5]:Bi,[s.NamedStyleType.NORMAL_TEXT]:an,[s.NamedStyleType.TITLE]:Ns,[s.NamedStyleType.SUBTITLE]:Ps,[s.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:an},ks={[s.NamedStyleType.HEADING_1]:{key:"H1Single",component:No},[s.NamedStyleType.HEADING_2]:{key:"H2Single",component:Po},[s.NamedStyleType.HEADING_3]:{key:"H3Single",component:Uo},[s.NamedStyleType.HEADING_4]:{key:"H4Single",component:wo},[s.NamedStyleType.HEADING_5]:{key:"H5Single",component:Lo},[s.NamedStyleType.NORMAL_TEXT]:{key:"TextTypeSingle",component:ht},[s.NamedStyleType.TITLE]:{key:"TextTypeSingle",component:ht},[s.NamedStyleType.SUBTITLE]:{key:"TextTypeSingle",component:ht},[s.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:{key:"TextTypeSingle",component:ht}},Qe=i=>t=>{const e=t.get(s.ICommandService),n=t.get(v.ComponentManager),o=ks[i];return n.get(o.key)||n.register(o.key,o.component),{id:_c[i].id,type:v.MenuItemType.BUTTON,icon:o.key,tooltip:"toolbar.heading.tooltip",disabled$:te(t),hidden$:v.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC),activated$:new L.Observable(a=>{const r=s.NamedStyleType.NORMAL_TEXT,c=()=>{var u,m;const A=ze(t);if(A==null){a.next(r===i);return}const d=(m=(u=A.paragraphStyle)==null?void 0:u.namedStyleType)!=null?m:r;a.next(d===i)},l=e.onCommandExecuted(A=>{const d=A.id;(d===D.SetTextSelectionsOperation.id||d===ge.id)&&c()});return c(),l.dispose})}},Nc=Qe(s.NamedStyleType.HEADING_1),Pc=Qe(s.NamedStyleType.HEADING_2),Uc=Qe(s.NamedStyleType.HEADING_3),wc=Qe(s.NamedStyleType.HEADING_4),Lc=Qe(s.NamedStyleType.HEADING_5),Qc=Qe(s.NamedStyleType.NORMAL_TEXT);Qe(s.NamedStyleType.TITLE),Qe(s.NamedStyleType.SUBTITLE);const Fc=i=>({id:gi.id,type:v.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy"}),Hc=i=>({id:mi.id,type:v.MenuItemType.BUTTON,icon:"CutSingle",title:"rightClick.cut"}),kc=i=>({id:ci.id,type:v.MenuItemType.BUTTON,icon:"DeleteSingle",title:"rightClick.delete"}),Vc=i=>({id:Ti.id,type:v.MenuItemType.BUTTON,icon:"UnorderSingle",title:"rightClick.bulletList"}),Wc=i=>({id:yi.id,type:v.MenuItemType.BUTTON,icon:"OrderSingle",title:"rightClick.orderList"}),zc=i=>({id:bi.id,type:v.MenuItemType.BUTTON,icon:"TodoList",title:"rightClick.checkList"}),Gc=i=>({id:Si.id,type:v.MenuItemType.BUTTON,icon:"ReduceSingle",title:"toolbar.horizontalLine"}),Vs="doc.menu.insert-bellow";function jc(i){return{id:Vs,type:v.MenuItemType.SUBITEMS,title:"rightClick.insertBellow"}}const wi=4,Xc=(i,t)=>{const e=i.get(s.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...s.Tools.deepClone(t),zoomRatio:n}},he={id:"doc.operation.set-zoom-ratio",type:s.CommandType.OPERATION,handler:(i,t)=>{const e=i.get(s.IUniverInstanceService).getUniverDocInstance(t.unitId);if(!e)return!1;const n=e.getSnapshot();return n.settings==null?n.settings={zoomRatio:t.zoomRatio}:n.settings.zoomRatio=t.zoomRatio,!0}};var Kc=Object.getOwnPropertyDescriptor,Yc=(i,t,e,n)=>{for(var o=n>1?void 0:n?Kc(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},cn=(i,t)=>(e,n)=>t(e,n,i);function Ws(i,t){const e=zs(i.left,i.top,t),n=zs(i.right,i.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function zs(i,t,e){const{scaleX:n,scaleY:o}=e.getAncestorScale(),a=e.getViewport(ae.VIEW_MAIN);if(!a)return{x:i,y:t};const{viewportScrollX:r,viewportScrollY:c}=a,l=(i-r)*n,A=(t-c)*o;return{x:l,y:A}}function Gs(i,t,e){const{scaleX:n,scaleY:o}=e.getAncestorScale(),a=e.getViewport(ae.VIEW_MAIN);if(!a)return{x:i,y:t};const{viewportScrollX:r,viewportScrollY:c}=a,l=i/n+r,A=t/o+c;return{x:l,y:A}}const ln=(i,t)=>{const{scene:e,mainComponent:n,engine:o}=t,a=t.with(D.DocSkeletonManagerService).getSkeleton(),r=a.findNodePositionByCharIndex(i.startOffset,!0,i.segmentId,i.segmentPage),c=i.collapsed?i.startOffset:i.endOffset-1,l=a.findNodePositionByCharIndex(c,!0,i.segmentId,i.segmentPage),A=n;if(!l||!r)return;const d=A.getOffsetConfig(),{docsLeft:u,docsTop:m}=d,h=o.getCanvasElement(),g=h.getBoundingClientRect(),p=_.pxToNum(h.style.width),{top:f,left:S,width:E}=g,C=E/p,{scaleX:b,scaleY:R}=e.getAncestorScale(),I=new Ie(d,a),{borderBoxPointGroup:O}=I.getRangePointData(r,l);return kt(O).map(N=>Ws(N,e)).map(N=>({left:(N.left+u*b)*C+S,right:(N.right+u*b)*C+S,top:(N.top+m*R)*C+f,bottom:(N.bottom+m*R)*C+f}))};T.DocCanvasPopManagerService=class extends s.Disposable{constructor(t,e,n,o){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=o}_createRectPositionObserver(t,e){const n=()=>{const{scene:l,engine:A}=e,d=typeof t=="function"?t():t,u=A.getCanvasElement(),m=u.getBoundingClientRect(),h=_.pxToNum(u.style.width),g=Ws(d,l),{top:p,left:f,width:S}=m,E=S/h;return{left:g.left*E+f,right:g.right*E+f,top:g.top*E+p,bottom:g.bottom*E+p}},o=n(),a=new L.BehaviorSubject(o),r=new s.DisposableCollection;r.add(this._commandService.onCommandExecuted(l=>{if(l.id===he.id||l.id===D.RichTextEditingMutation.id){const A=n();A&&a.next(A)}}));const c=e.scene.getViewport(ae.VIEW_MAIN);return c&&r.add(c.onScrollAfter$.subscribeEvent(()=>{a.next(n())})),{position:o,position$:a,disposable:r}}_createObjectPositionObserver(t,e){const n=()=>{const{left:o,top:a,width:r,height:c}=t;return{left:o,right:o+r,top:a,bottom:a+c}};return this._createRectPositionObserver(n,e)}_createRangePositionObserver(t,e){var c;const n=(c=ln(t,e))!=null?c:[],o=new L.BehaviorSubject(n),a=new s.DisposableCollection;a.add(this._commandService.onCommandExecuted(l=>{if((l.id===he.id||l.id===D.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=ln(t,e);d&&o.next(d)}}));const r=e.scene.getViewport(ae.VIEW_MAIN);return r&&a.add(r.onScrollAfter$.subscribeEvent(()=>{const l=ln(t,e);l&&o.next(l)})),{positions:n,positions$:o,disposable:a}}attachPopupToRect(t,e,n){const o=this._renderManagerService.getRenderById(n);if(!o)throw new Error(`Current render not found, unitId: ${n}`);const{position:a,position$:r,disposable:c}=this._createRectPositionObserver(t,o),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:a,anchorRect$:r,canvasElement:o.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),r.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}attachPopupToObject(t,e,n){const o=this._renderManagerService.getRenderById(n);if(!o)throw new Error(`Current render not found, unitId: ${n}`);const{position:a,position$:r,disposable:c}=this._createObjectPositionObserver(t,o),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:a,anchorRect$:r,canvasElement:o.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),r.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}attachPopupToRange(t,e,n){if(!this._univerInstanceService.getUnit(n))throw new Error(`Document not found, unitId: ${n}`);const{direction:a="top",multipleDirection:r}=e,c=this._renderManagerService.getRenderById(n);if(!c)throw new Error(`Current render not found, unitId: ${n}`);const{positions:l,positions$:A,disposable:d}=this._createRangePositionObserver(t,c),u=A.pipe(L.map(h=>a.includes("top")?h[0]:h[h.length-1])),m=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:a.includes("top")?l[0]:l[l.length-1],anchorRect$:u,excludeRects:l,excludeRects$:A,direction:["top","bottom","horizontal"].some(h=>a.includes(h))&&l.length>1&&r!=null?r:a,canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(m),A.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==m}}},T.DocCanvasPopManagerService=Yc([cn(0,s.Inject(v.ICanvasPopupService)),cn(1,_.IRenderManagerService),cn(2,s.IUniverInstanceService),cn(3,s.ICommandService)],T.DocCanvasPopManagerService);var qc=Object.getOwnPropertyDescriptor,Jc=(i,t,e,n)=>{for(var o=n>1?void 0:n?qc(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},Zc=(i,t)=>(e,n)=>t(e,n,i);const $c=(i,t,e,n)=>{var m,h,g,p,f;const o=e.findNodePositionByCharIndex(i.startOffset,!0,i.segmentId,n),a=e.getSkeletonData();let r=i.endOffset-1;if(i.segmentId){const S=(f=Array.from((h=(m=a==null?void 0:a.skeFooters.get(i.segmentId))==null?void 0:m.values())!=null?h:[])[0])!=null?f:Array.from((p=(g=a==null?void 0:a.skeHeaders.get(i.segmentId))==null?void 0:g.values())!=null?p:[])[0];S&&(r=Math.min(S.ed,r))}const c=e.findNodePositionByCharIndex(r,!0,i.segmentId,n);if(!c||!o)return;const l=t.getOffsetConfig(),A=new Ie(l,e),{borderBoxPointGroup:d}=A.getRangePointData(o,c);return kt(d).map(S=>({top:S.top+l.docsTop-wi,bottom:S.bottom+l.docsTop+wi,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},js=(i,t,e,n)=>{const o=[];for(const a of i){const r=a.top;for(const c of a.columns){const l=c.left,A=a.colCount===1?n:c.width;let d=null;for(const u of c.lines){const m=u.paragraphIndex;if(u.paragraphStart){d&&(o.push(d),d=null);const h={top:t+r+u.top,left:e+l,right:e+l+A,bottom:t+r+u.top+u.lineHeight};d={paragraphStart:u.st,paragraphEnd:m,startIndex:m,rect:h,fisrtLine:{top:t+r+u.top+u.marginTop+u.paddingTop,left:e+l,right:e+l+A,bottom:t+r+u.top+u.marginTop+u.paddingTop+u.contentHeight}}}else d&&d.startIndex===m&&(d.rect.bottom=t+r+u.top+u.lineHeight)}d&&o.push(d)}}return o},el=(i,t,e,n=-1)=>{const o=e.findPositionByGlyph(i,n);if(!o)return;const a=t.getOffsetConfig(),r={...o,isBack:!0},c=new Ie(a,e),{borderBoxPointGroup:l}=c.getRangePointData(r,r),d=kt(l)[0];return{top:d.top+a.docsTop,bottom:d.bottom+a.docsTop,left:d.left+a.docsLeft,right:d.left+a.docsLeft+i.width}};function Ge(i,t,e){const{left:n,right:o,top:a,bottom:r}=e;return i>=n&&i<=o&&t>=a&&t<=r}T.DocEventManagerService=class extends s.Disposable{constructor(e,n){super();B(this,"_hoverCustomRanges$",new L.BehaviorSubject([]));B(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(L.distinctUntilChanged((e,n)=>e.length===n.length&&e.every((o,a)=>n[a].range.rangeId===o.range.rangeId&&n[a].segmentId===o.segmentId&&n[a].segmentPageIndex===o.segmentPageIndex&&n[a].range.startIndex===o.range.startIndex))));B(this,"_clickCustomRanges$",new L.Subject);B(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());B(this,"_hoverBullet$",new L.Subject);B(this,"hoverBullet$",this._hoverBullet$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.paragraph.startIndex)===(n==null?void 0:n.paragraph.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.segmentPageIndex)===(n==null?void 0:n.segmentPageIndex))));B(this,"_clickBullet$",new L.Subject);B(this,"clickBullets$",this._clickBullet$.asObservable());B(this,"_hoverParagraph$",new L.BehaviorSubject(null));B(this,"hoverParagraph$",this._hoverParagraph$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverParagraphRealTime$",this._hoverParagraph$.asObservable());B(this,"_hoverParagraphLeft$",new L.BehaviorSubject(null));B(this,"hoverParagraphLeft$",this._hoverParagraphLeft$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverParagraphLeftRealTime$",this._hoverParagraphLeft$.asObservable());B(this,"_hoverTableCell$",new L.Subject);B(this,"hoverTableCell$",this._hoverTableCell$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.rowIndex)===(n==null?void 0:n.rowIndex)&&(e==null?void 0:e.colIndex)===(n==null?void 0:n.colIndex)&&(e==null?void 0:e.tableId)===(n==null?void 0:n.tableId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverTableCellRealTime$",this._hoverTableCell$.asObservable());B(this,"_hoverTable$",new L.Subject);B(this,"hoverTable$",this._hoverTable$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.tableId)===(n==null?void 0:n.tableId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverTableRealTime$",this._hoverTable$.asObservable());B(this,"_customRangeDirty",!0);B(this,"_bulletDirty",!0);B(this,"_paragraphDirty",!0);B(this,"_customRangeBounds",[]);B(this,"_bulletBounds",[]);B(this,"_paragraphBounds",new Map);B(this,"_paragraphLeftBounds",[]);B(this,"_tableParagraphBounds",new Map);B(this,"_segmentParagraphBounds",new Map);B(this,"_tableCellBounds",new Map);B(this,"_tableBounds",new Map);this._context=e,this._docSkeletonManagerService=n,this._initResetDirty(),this._initEvents(),this._initPointer()}get hoverParagraph(){return this._hoverParagraph$.value}get hoverParagraphLeft(){return this._hoverParagraphLeft$.value}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}get _documents(){return this._context.mainComponent}dispose(){this._hoverCustomRanges$.complete(),this._clickCustomRanges$.complete(),super.dispose()}_initPointer(){let e=_.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(_.CURSOR_TYPE.POINTER)):this._context.scene.setCursor(e)}))}_initResetDirty(){this.disposeWithMe(this._skeleton.dirty$.subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0})),this.disposeWithMe(s.fromEventSubject(this._context.engine.onTransformChange$).pipe(L.filter(e=>e.type===_.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0}))}_initEvents(){this.disposeWithMe(s.fromEventSubject(this._context.scene.onPointerMove$).pipe(L.throttleTime(30)).subscribe(o=>{if(o.buttons>0){this._hoverBullet$.next(null),this._hoverCustomRanges$.next([]),this._hoverParagraph$.next(null),this._hoverParagraphLeft$.next(null),this._hoverTableCell$.next(null),this._hoverTable$.next(null);return}const{x:a,y:r}=Gs(o.offsetX,o.offsetY,this._context.scene);this._hoverCustomRanges$.next(this._calcActiveRanges({x:a,y:r})),this._hoverParagraph$.next(this._calcActiveParagraph({x:a,y:r})),this._hoverParagraphLeft$.next(this._calcActiveParagraphLeft({x:a,y:r})),this._hoverBullet$.next(this._calcActiveBullet({x:a,y:r}))})),this.disposeWithMe(this._context.scene.onPointerEnter$.subscribeEvent(()=>{this._hoverBullet$.next(null),this._hoverCustomRanges$.next([])}));const e=s.fromEventSubject(this._context.mainComponent.onPointerDown$),n=s.fromEventSubject(this._context.scene.onPointerUp$);this.disposeWithMe(e.pipe(L.switchMap(o=>n.pipe(L.take(1),L.map(a=>({down:o,up:a})))),L.filter(({down:o,up:a})=>o.target===a.target&&a.timeStamp-o.timeStamp<300)).subscribe(({down:o})=>{if(o.button===2)return;const a=Gs(o.offsetX,o.offsetY,this._context.scene),r=this._calcActiveRanges(a);r.length&&this._clickCustomRanges$.next(r.pop());const c=this._calcActiveBullet(a);c&&this._clickBullet$.next(c)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var r,c,l;const o=(l=(c=(r=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:r.getBody())==null?void 0:c.customRanges)!=null?l:[],a=[];return o.forEach(A=>{const d={startOffset:A.startIndex,endOffset:A.endIndex+1,segmentId:e},u=$c(d,this._documents,this._skeleton,n);if(!u)return null;a.push({customRange:A,rects:u,segmentId:e,segmentPageIndex:n})}),a}_buildCustomRangeBounds(){var n;if(!this._customRangeDirty)return;this._customRangeDirty=!1;const e=[];e.push(...this._buildCustomRangeBoundsBySegment()),(n=this._skeleton.getSkeletonData())==null||n.pages.forEach((o,a)=>{o.headerId&&e.push(...this._buildCustomRangeBoundsBySegment(o.headerId,a)),o.footerId&&e.push(...this._buildCustomRangeBoundsBySegment(o.footerId,a))}),this._customRangeBounds=e}_calcActiveRanges(e){this._buildCustomRangeBounds();const{x:n,y:o}=e;return this._customRangeBounds.filter(r=>r.rects.some(c=>Ge(n,o,c))).map(r=>({segmentId:r.segmentId,range:r.customRange,segmentPageIndex:r.segmentPageIndex,rects:r.rects}))}_buildBulletBoundsBySegment(e,n=-1){var A,d,u,m,h;const o=(A=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:A.getBody(),a=((d=o==null?void 0:o.paragraphs)!=null?d:[]).filter(g=>g.bullet&&g.bullet.listType.indexOf("CHECK_LIST")===0),r=[],c=this._skeleton.getSkeletonData();if(!c)return r;const l=g=>{var p,f,S;for(const E of g){const C=[...E.sections];if(E.skeTables){const b=Array.from(E.skeTables.values());C.push(...b.map(R=>R.rows.map(I=>I.cells.map(O=>O.sections))).flat(4))}for(const b of C)for(const R of b.columns)for(const I of R.lines)if(I.paragraphStart){const O=a.find(M=>M.startIndex===I.paragraphIndex);if(O){const M=I,y=(S=(f=(p=M==null?void 0:M.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!y)continue;const N=el(y,this._documents,this._skeleton,n);if(!N)continue;r.push({rect:N,segmentId:e,segmentPageIndex:n,paragraph:O})}}}return r};if(e){const g=(h=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?h:(m=c.skeHeaders.get(e))==null?void 0:m.values();return g?l(Array.from(g)):r}return l(c.pages)}_buildBulletBounds(){var e;this._bulletDirty&&(this._bulletDirty=!1,this._bulletBounds=[],this._bulletBounds.push(...this._buildBulletBoundsBySegment()),(e=this._skeleton.getSkeletonData())==null||e.pages.forEach((n,o)=>{n.headerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.headerId,o)),n.footerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.footerId,o))}))}_calcActiveBullet(e){this._buildBulletBounds();const{x:n,y:o}=e;return this._bulletBounds.find(r=>Ge(n,o,r.rect))}_buildParagraphBoundsBySegment(e){var c,l,A;const n=this._skeleton.getSkeletonData(),a=this._documents.getOffsetConfig();if(!n)return null;const r=d=>{const u=new Map,m=(h,g,p,f)=>{js(h.sections,p,f,h.pageWidth-h.marginLeft-h.marginRight).forEach(E=>{if(!u.has(E.startIndex))u.set(E.startIndex,{rect:E.rect,paragraphStart:E.paragraphStart,paragraphEnd:E.paragraphEnd,startIndex:E.startIndex,rects:[E.rect],pageIndex:g,segmentId:e,firstLine:E.fisrtLine});else{const C=u.get(E.startIndex);C&&(C.rect.bottom=E.rect.bottom,C.rects.push(E.rect))}})};for(let h=0;h<d.length;h++){const g=d[h],p=((g.pageHeight===1/0?0:g.pageHeight)+a.pageMarginTop)*h+g.marginTop+a.docsTop,f=g.marginLeft+a.docsLeft;g.skeTables&&Array.from(g.skeTables.values()).forEach(S=>{const E=S.left+f,C=S.top+p,b=E+S.width,R=C+S.height,I=S.tableId;this._tableBounds.set(I,{rect:{left:E,top:C,right:b,bottom:R},pageIndex:h,tableId:I}),S.rows.forEach((O,M)=>{O.cells.forEach((y,N)=>{const x=((g.pageHeight===1/0?0:g.pageHeight)+a.pageMarginTop)*h+S.top+a.docsTop+g.marginTop+O.top+y.marginTop,w=S.left+a.docsLeft+g.marginLeft+y.left+y.marginLeft,H=js(y.sections,x,w,y.pageWidth-y.marginLeft-y.marginRight);let V=this._tableParagraphBounds.get(I);V||(V=[],this._tableParagraphBounds.set(I,V)),V.push(...H.map(Q=>({rect:Q.rect,paragraphStart:Q.paragraphStart,paragraphEnd:Q.paragraphEnd,startIndex:Q.startIndex,pageIndex:h,segmentId:e,rowIndex:M,colIndex:N,firstLine:Q.fisrtLine,tableId:I})));let F=this._tableCellBounds.get(I);F||(F=[],this._tableCellBounds.set(I,F)),F.push({rect:{top:x,left:w,right:w+y.pageWidth-y.marginLeft-y.marginRight,bottom:x+y.pageHeight-y.marginBottom-y.marginTop},pageIndex:h,rowIndex:M,colIndex:N,tableId:I})})})}),m(g,h,p,f)}return u};if(e){const d=(A=(c=n.skeFooters.get(e))==null?void 0:c.values())!=null?A:(l=n.skeHeaders.get(e))==null?void 0:l.values();return d?r(Array.from(d)):null}return r(n.pages)}_buildParagraphBounds(){var n,o;if(!this._paragraphDirty)return;this._paragraphDirty=!1,this._tableParagraphBounds=new Map,this._tableCellBounds=new Map,this._tableBounds=new Map,this._paragraphBounds=(n=this._buildParagraphBoundsBySegment())!=null?n:new Map,this._paragraphLeftBounds=Array.from(this._paragraphBounds.values()).map(a=>({...a,rect:{left:a.rect.left-60,right:a.rect.left,top:a.rect.top,bottom:a.rect.bottom}}));const e=a=>{var r;this._segmentParagraphBounds.set(a,(r=this._buildParagraphBoundsBySegment(a))!=null?r:new Map)};(o=this._skeleton.getSkeletonData())==null||o.pages.forEach(a=>{a.headerId&&e(a.headerId),a.footerId&&e(a.footerId)})}_calcActiveParagraph(e){var c,l;this._buildParagraphBounds();const{x:n,y:o}=e,a=Array.from(this._tableBounds.values()).find(A=>Ge(n,o,A.rect));if(this._hoverTable$.next(a),a){const A=(c=this._tableCellBounds.get(a.tableId))==null?void 0:c.find(m=>Ge(n,o,m.rect));if(this._hoverTableCell$.next(A),!A)return null;const d=(l=this._tableParagraphBounds.get(A.tableId))==null?void 0:l.filter(m=>m.colIndex===A.colIndex&&m.rowIndex===A.rowIndex),u=d==null?void 0:d.find(m=>Ge(n,o,m.rect));return u&&{...u,rects:[u.rect]}}return this._paragraphBounds.values().find(A=>A.rects.some(d=>Ge(n,o,d)))}_calcActiveParagraphLeft(e){this._buildParagraphBounds();const{x:n,y:o}=e;return this._paragraphLeftBounds.find(r=>Ge(n,o,r.rect))}get paragraphBounds(){return this._buildParagraphBounds(),this._paragraphBounds}findParagraphBoundByIndex(e){this._buildParagraphBounds();const n=this._paragraphBounds.get(e);return n||Array.from(this._tableParagraphBounds.values()).flat().find(a=>a.startIndex===e)}},T.DocEventManagerService=Jc([Zc(1,s.Inject(D.DocSkeletonManagerService))],T.DocEventManagerService);const tl=[ge.id,De.id,Be.id,_e.id,Ne.id,ye.id,Pe.id,Ue.id,we.id];function nl(i){const{avaliableMenus:t=tl}=i,e=v.useDependency(v.IMenuManagerService),[n,o]=U.useState([]);return U.useEffect(()=>{function a(){const c=e.getFlatMenuByPositionKey(v.MenuManagerPosition.RIBBON),l=[];for(const A of t){const d=c.find(u=>u.key===A);d&&l.push(d)}o(l)}a();const r=e.menuChanged$.subscribe(a);return()=>{r.unsubscribe()}},[e]),P.jsx("div",{className:`
|
|
43
43
|
univer-box-border univer-flex univer-rounded univer-border univer-border-solid univer-border-gray-200
|
|
44
|
-
univer-bg-white univer-py-1.5
|
|
45
|
-
univer-shadow-[0_1px_6px_-2px_rgba(30,40,77,0.08),0_2px_6px_-1px_rgba(30,40,77,0.10)]
|
|
44
|
+
univer-bg-white univer-py-1.5 univer-shadow-sm
|
|
46
45
|
`,children:n.map(a=>a.item&&P.jsx("div",{className:"univer-flex univer-flex-nowrap univer-gap-2 univer-px-2",children:P.jsx(v.ToolbarItem,{...a.item},a.key)},a.key))})}var il=Object.getOwnPropertyDescriptor,ol=(i,t,e,n)=>{for(var o=n>1?void 0:n?il(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},xt=(i,t)=>(e,n)=>t(e,n,i);const Xs="univer.doc.float-menu";function sl(i,t){if(i==null||t==null)return!1;const{glyph:e,...n}=i,{glyph:o,...a}=t;return s.deepCompare(n,a)}const al=[s.DataStreamTreeTokenType.CUSTOM_BLOCK,s.DataStreamTreeTokenType.PARAGRAPH];let dn=class extends s.Disposable{constructor(t,e,n,o,a,r){super();B(this,"_floatMenu",null);this._context=t,this._docSelectionManagerService=e,this._docCanvasPopManagerService=n,this._componentManager=o,this._univerInstanceService=a,this._docSelectionRenderService=r,!s.isInternalEditorID(this._context.unitId)&&(this._registerFloatMenu(),this._initSelectionChange(),this.disposeWithMe(()=>{this._hideFloatMenu()}))}get floatMenu(){return this._floatMenu}_registerFloatMenu(){this.disposeWithMe(this._componentManager.register(Xs,nl))}_initSelectionChange(){this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(()=>{this._hideFloatMenu()})),this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(t=>{var a,r;const{unitId:e,textRanges:n}=t;if(e!==this._context.unitId)return;const o=n.length>0&&n.find(c=>!c.collapsed);if(o){if(o.startOffset===((a=this._floatMenu)==null?void 0:a.start)&&o.endOffset===((r=this._floatMenu)==null?void 0:r.end))return;this._hideFloatMenu(),this._showFloatMenu(e,o);return}this._hideFloatMenu()}))}_hideFloatMenu(){var t;(t=this._floatMenu)==null||t.disposable.dispose(),this._floatMenu=null}_showFloatMenu(t,e){var r,c,l;const n=this._univerInstanceService.getUnit(t,s.UniverInstanceType.UNIVER_DOC);if(!n||n.getDisabled())return;const o=(r=n.getBody())==null?void 0:r.dataStream[e.startOffset];if(e.endOffset-e.startOffset===1&&o&&al.includes(o))return;const a=(l=(c=n.getBody())==null?void 0:c.customRanges)==null?void 0:l.filter(A=>A.wholeEntity);if(!(a!=null&&a.some(A=>A.startIndex===e.startOffset&&A.endIndex===e.endOffset-1)))return this._floatMenu={disposable:this._docCanvasPopManagerService.attachPopupToRange(e,{componentKey:Xs,direction:e.direction==="backward"||sl(e.startNodePosition,e.endNodePosition)?"top-center":"bottom-center",offset:[0,4]},t),start:e.startOffset,end:e.endOffset},s.toDisposable(()=>this._hideFloatMenu())}};dn=ol([xt(1,s.Inject(D.DocSelectionManagerService)),xt(2,s.Inject(T.DocCanvasPopManagerService)),xt(3,s.Inject(v.ComponentManager)),xt(4,s.Inject(s.IUniverInstanceService)),xt(5,s.Inject(T.DocSelectionRenderService))],dn);var rl=Object.getOwnPropertyDescriptor,cl=(i,t,e,n)=>{for(var o=n>1?void 0:n?rl(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},Dt=(i,t)=>(e,n)=>t(e,n,i);let An=class extends s.Disposable{constructor(t,e,n,o,a,r){super();B(this,"_paragrahMenu",null);this._context=t,this._docSelectionManagerService=e,this._docEventManagerService=n,this._docPopupManagerService=o,this._docSkeletonManagerService=a,this._floatMenuService=r,!s.isInternalEditorID(this._context.unitId)&&this._init()}get activeParagraph(){var t;return(t=this._paragrahMenu)==null?void 0:t.paragraph}_isCursorInActiveParagraph(){if(!this._paragrahMenu)return!1;const t=this._docSelectionManagerService.getActiveTextRange();return!(!(t!=null&&t.collapsed)||!(t!=null&&t.collapsed)||t.startOffset<this._paragrahMenu.paragraph.paragraphStart||t.startOffset>this._paragrahMenu.paragraph.paragraphEnd)}setParagraphMenuActive(t){this._paragrahMenu&&(this._paragrahMenu.active=t,this._isCursorInActiveParagraph()||this._docSelectionManagerService.replaceDocRanges([{startOffset:this._paragrahMenu.paragraph.paragraphStart,endOffset:this._paragrahMenu.paragraph.paragraphStart}]))}_init(){const t=n=>{var a;if(this._docSkeletonManagerService.getViewModel().getEditArea()===_.DocumentEditArea.BODY&&!this._floatMenuService.floatMenu&&!this._context.unit.getDisabled()){if((a=this._paragrahMenu)!=null&&a.active)return;if(n){this.showParagraphMenu(n);return}}this.hideParagraphMenu(!0)};this.disposeWithMe(L.combineLatest([this._docEventManagerService.hoverParagraphRealTime$,this._docEventManagerService.hoverParagraphLeft$]).pipe(L.throttleTime(16)).subscribe(([n,o])=>{const a=n!=null?n:o;t(a)}));let e=0;this.disposeWithMe(this._context.scene.getViewport(ae.VIEW_MAIN).onScrollAfter$.subscribeEvent(n=>{e!==n.scrollY&&(e=n.scrollY,this.hideParagraphMenu(!0))})),this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(()=>{this.hideParagraphMenu(!0)}))}showParagraphMenu(t){var l,A,d;if(((l=this._paragrahMenu)==null?void 0:l.paragraph.startIndex)===t.startIndex)return;this.hideParagraphMenu(!0);const e=(d=(A=this._context.unit.getBody())==null?void 0:A.dataStream)!=null?d:"",n=t?e.slice(t.paragraphStart,t.paragraphEnd):"";if(n==="\b"||n==="")return;const c=this._docPopupManagerService.attachPopupToRect(t.firstLine,{componentKey:"doc.paragraph.menu",direction:"left-center",onClickOutside:()=>{this._docSelectionManagerService.textSelection$.pipe(L.first()).subscribe(()=>{this._isCursorInActiveParagraph()||this.hideParagraphMenu(!0)})},zIndex:101},this._context.unitId);this._paragrahMenu={paragraph:t,disposable:c,active:!1}}hideParagraphMenu(t=!1){this._paragrahMenu&&(this._paragrahMenu.disposable.canDispose()||t)&&(this._paragrahMenu.disposable.dispose(),this._paragrahMenu=null)}};An=cl([Dt(1,s.Inject(D.DocSelectionManagerService)),Dt(2,s.Inject(T.DocEventManagerService)),Dt(3,s.Inject(T.DocCanvasPopManagerService)),Dt(4,s.Inject(D.DocSkeletonManagerService)),Dt(5,s.Inject(dn))],An);const ll=({popup:i})=>{var I,O;const[t,e]=U.useState(!1),n=U.useRef(null),o=v.useDependency(s.ICommandService),a=v.useDependency(v.ILayoutService),r=U.useRef(null),c=U.useRef(!1),l=v.useDependency(_.IRenderManagerService),A=v.useDependency(s.IUniverInstanceService),d=l.getRenderById(i.unitId),u=A.getUnit(i.unitId,s.UniverInstanceType.UNIVER_DOC),m=d==null?void 0:d.with(An),h=d==null?void 0:d.with(T.DocEventManagerService),g=v.useObservable(h==null?void 0:h.hoverParagraph$),p=v.useObservable(h==null?void 0:h.hoverParagraphLeft$),f=(I=g!=null?g:p)==null?void 0:I.startIndex,S=U.useMemo(()=>{var M,y;return(y=(M=u==null?void 0:u.getBody())==null?void 0:M.paragraphs)==null?void 0:y.find(N=>N.startIndex===f)},[u,g]),E=(O=S==null?void 0:S.paragraphStyle)==null?void 0:O.namedStyleType,C=ks[E!=null?E:s.NamedStyleType.NORMAL_TEXT],b=U.useMemo(()=>new L.BehaviorSubject({left:0,right:0,top:0,bottom:0}),[]),R=()=>{e(!1),m==null||m.hideParagraphMenu(!0)};return P.jsxs(P.Fragment,{children:[P.jsxs("div",{ref:r,className:`
|
|
47
46
|
univer-mr-1 univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1
|
|
48
47
|
univer-rounded-full univer-border univer-border-solid univer-border-gray-200 univer-px-2.5 univer-py-0
|
|
49
48
|
hover:univer-bg-gray-100
|
|
50
49
|
${t?"univer-bg-gray-100":"univer-bg-white"}
|
|
51
|
-
`,onMouseEnter:M=>{var N,x,w,H,V,F;(N=i.onPointerEnter)==null||N.call(i,M),c.current=!0;const y=(x=r.current)==null?void 0:x.getBoundingClientRect();b.next({left:((w=y==null?void 0:y.left)!=null?w:0)-4,right:(H=y==null?void 0:y.right)!=null?H:0,top:(V=y==null?void 0:y.top)!=null?V:0,bottom:(F=y==null?void 0:y.bottom)!=null?F:0})},onMouseLeave:()=>{c.current=!1},onClick:()=>{e(!0),m==null||m.setParagraphMenuActive(!0)},children:[P.jsx(C.component,{className:"univer-h-4 univer-w-4 univer-text-[#181C2A]"}),P.jsx(_o,{className:"univer-h-3 univer-w-3 univer-text-[#979DAC]"})]}),t&&P.jsx(v.RectPopup,{portal:!0,mask:!0,maskZIndex:100,anchorRect$:b,direction:"left",onMaskClick:R,children:P.jsx("section",{ref:n,onMouseEnter:M=>{var y;(y=i.onPointerEnter)==null||y.call(i,M),c.current=!0},onMouseLeave:()=>{c.current=!1},children:P.jsx(v.DesktopMenu,{style:{width:212},menuType:v.ContextMenuPosition.PARAGRAPH,onOptionSelect:M=>{const{label:y,commandId:N,value:x}=M;o&&o.executeCommand(N!=null?N:y,{value:x}),a.focus(),R()}})})})]})},je={id:"doc.command.tab",type:s.CommandType.COMMAND,async handler(i,t){const n=i.get(T.DocAutoFormatService).onAutoFormat(je.id,t);return(await s.sequenceExecuteAsync(n,i.get(s.ICommandService))).result}},Bt={id:"doc.command.after-space",type:s.CommandType.COMMAND,async handler(i){const e=i.get(T.DocAutoFormatService).onAutoFormat(Bt.id);return(await s.sequenceExecuteAsync(e,i.get(s.ICommandService))).result}},st={id:"doc.command.enter",type:s.CommandType.COMMAND,async handler(i){const e=i.get(T.DocAutoFormatService).onAutoFormat(st.id);return(await s.sequenceExecuteAsync(e,i.get(s.ICommandService))).result}};function $(i){return i.getContextValue(s.FOCUSING_DOC)&&i.getContextValue(s.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(s.FOCUSING_COMMON_DRAWINGS)}function dl(i){return i.getContextValue(s.FOCUSING_DOC)&&i.getContextValue(s.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(s.FOCUSING_COMMON_DRAWINGS)}const Al={id:je.id,binding:v.KeyCode.TAB,preconditions:$},ul={id:je.id,binding:v.KeyCode.TAB|v.MetaKeys.SHIFT,preconditions:$,staticParameters:{shift:!0}},hl={id:De.id,binding:v.KeyCode.B|v.MetaKeys.CTRL_COMMAND,preconditions:$},gl={id:Be.id,binding:v.KeyCode.I|v.MetaKeys.CTRL_COMMAND,preconditions:$},ml={id:_e.id,binding:v.KeyCode.U|v.MetaKeys.CTRL_COMMAND,preconditions:$},pl={id:Ne.id,binding:v.KeyCode.X|v.MetaKeys.SHIFT|v.MetaKeys.CTRL_COMMAND,preconditions:$},fl={id:ye.id,binding:v.KeyCode.COMMA|v.MetaKeys.CTRL_COMMAND,preconditions:$},Sl={id:Pe.id,binding:v.KeyCode.PERIOD|v.MetaKeys.CTRL_COMMAND,preconditions:$},vl={id:Tt.id,binding:v.KeyCode.L|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},Il={id:bt.id,binding:v.KeyCode.R|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},El={id:yt.id,binding:v.KeyCode.E|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},Cl={id:Ot.id,binding:v.KeyCode.J|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},Tl={id:ot.id,binding:v.KeyCode.Digit7|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},yl={id:it.id,binding:v.KeyCode.Digit8|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},un="docs-ui.config",Ks={layout:{docContainerConfig:ao,toolbarConfig:so}},bl=[50,80,100,130,150,170,200,400],Ol=[10,400];function Rl(){const i=v.useDependency(s.ICommandService),t=v.useDependency(s.IUniverInstanceService),e=U.useMemo(()=>t.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC),[]),n=v.useObservable(e),o=U.useCallback(()=>{var A,d;if(!n)return 100;const l=((d=(A=n.getSettings())==null?void 0:A.zoomRatio)!=null?d:1)*100;return Math.round(l)},[n]),[a,r]=U.useState(()=>o());U.useEffect(()=>(r(o()),i.onCommandExecuted(A=>{if(A.id===he.id){const d=o();r(d)}}).dispose),[i,o]);function c(l){if(r(l),n==null)return;const A=l/100;i.executeCommand(he.id,{unitId:n.getUnitId(),zoomRatio:A})}return P.jsx(v.Slider,{min:Ol[0],value:a,shortcuts:bl,onChange:c})}function Ml(i){return P.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-
|
|
50
|
+
`,onMouseEnter:M=>{var N,x,w,H,V,F;(N=i.onPointerEnter)==null||N.call(i,M),c.current=!0;const y=(x=r.current)==null?void 0:x.getBoundingClientRect();b.next({left:((w=y==null?void 0:y.left)!=null?w:0)-4,right:(H=y==null?void 0:y.right)!=null?H:0,top:(V=y==null?void 0:y.top)!=null?V:0,bottom:(F=y==null?void 0:y.bottom)!=null?F:0})},onMouseLeave:()=>{c.current=!1},onClick:()=>{e(!0),m==null||m.setParagraphMenuActive(!0)},children:[P.jsx(C.component,{className:"univer-h-4 univer-w-4 univer-text-[#181C2A]"}),P.jsx(_o,{className:"univer-h-3 univer-w-3 univer-text-[#979DAC]"})]}),t&&P.jsx(v.RectPopup,{portal:!0,mask:!0,maskZIndex:100,anchorRect$:b,direction:"left",onMaskClick:R,children:P.jsx("section",{ref:n,onMouseEnter:M=>{var y;(y=i.onPointerEnter)==null||y.call(i,M),c.current=!0},onMouseLeave:()=>{c.current=!1},children:P.jsx(v.DesktopMenu,{style:{width:212},menuType:v.ContextMenuPosition.PARAGRAPH,onOptionSelect:M=>{const{label:y,commandId:N,value:x}=M;o&&o.executeCommand(N!=null?N:y,{value:x}),a.focus(),R()}})})})]})},je={id:"doc.command.tab",type:s.CommandType.COMMAND,async handler(i,t){const n=i.get(T.DocAutoFormatService).onAutoFormat(je.id,t);return(await s.sequenceExecuteAsync(n,i.get(s.ICommandService))).result}},Bt={id:"doc.command.after-space",type:s.CommandType.COMMAND,async handler(i){const e=i.get(T.DocAutoFormatService).onAutoFormat(Bt.id);return(await s.sequenceExecuteAsync(e,i.get(s.ICommandService))).result}},st={id:"doc.command.enter",type:s.CommandType.COMMAND,async handler(i){const e=i.get(T.DocAutoFormatService).onAutoFormat(st.id);return(await s.sequenceExecuteAsync(e,i.get(s.ICommandService))).result}};function $(i){return i.getContextValue(s.FOCUSING_DOC)&&i.getContextValue(s.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(s.FOCUSING_COMMON_DRAWINGS)}function dl(i){return i.getContextValue(s.FOCUSING_DOC)&&i.getContextValue(s.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(s.FOCUSING_COMMON_DRAWINGS)}const Al={id:je.id,binding:v.KeyCode.TAB,preconditions:$},ul={id:je.id,binding:v.KeyCode.TAB|v.MetaKeys.SHIFT,preconditions:$,staticParameters:{shift:!0}},hl={id:De.id,binding:v.KeyCode.B|v.MetaKeys.CTRL_COMMAND,preconditions:$},gl={id:Be.id,binding:v.KeyCode.I|v.MetaKeys.CTRL_COMMAND,preconditions:$},ml={id:_e.id,binding:v.KeyCode.U|v.MetaKeys.CTRL_COMMAND,preconditions:$},pl={id:Ne.id,binding:v.KeyCode.X|v.MetaKeys.SHIFT|v.MetaKeys.CTRL_COMMAND,preconditions:$},fl={id:ye.id,binding:v.KeyCode.COMMA|v.MetaKeys.CTRL_COMMAND,preconditions:$},Sl={id:Pe.id,binding:v.KeyCode.PERIOD|v.MetaKeys.CTRL_COMMAND,preconditions:$},vl={id:Tt.id,binding:v.KeyCode.L|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},Il={id:bt.id,binding:v.KeyCode.R|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},El={id:yt.id,binding:v.KeyCode.E|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},Cl={id:Ot.id,binding:v.KeyCode.J|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},Tl={id:ot.id,binding:v.KeyCode.Digit7|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},yl={id:it.id,binding:v.KeyCode.Digit8|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT,preconditions:$},un="docs-ui.config",Ks={layout:{docContainerConfig:ao,toolbarConfig:so}},bl=[50,80,100,130,150,170,200,400],Ol=[10,400];function Rl(){const i=v.useDependency(s.ICommandService),t=v.useDependency(s.IUniverInstanceService),e=U.useMemo(()=>t.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC),[]),n=v.useObservable(e),o=U.useCallback(()=>{var A,d;if(!n)return 100;const l=((d=(A=n.getSettings())==null?void 0:A.zoomRatio)!=null?d:1)*100;return Math.round(l)},[n]),[a,r]=U.useState(()=>o());U.useEffect(()=>(r(o()),i.onCommandExecuted(A=>{if(A.id===he.id){const d=o();r(d)}}).dispose),[i,o]);function c(l){if(r(l),n==null)return;const A=l/100;i.executeCommand(he.id,{unitId:n.getUnitId(),zoomRatio:A})}return P.jsx(v.Slider,{min:Ol[0],value:a,shortcuts:bl,onChange:c})}function Ml(i){return P.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-justify-end",children:P.jsx(Rl,{})})}function xl(){var o,a,r;const i=v.useDependency(s.IUniverInstanceService),t=v.useConfigValue(un),e=v.useObservable(()=>i.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),n=(r=(a=(o=t==null?void 0:t.layout)==null?void 0:o.docContainerConfig)==null?void 0:a.footer)!=null?r:!0;return e?null:n&&P.jsxs("div",{className:"univer-box-border univer-flex univer-items-center univer-justify-between univer-px-5",children:[P.jsx("div",{}),P.jsx(Ml,{})]})}const Dl="univer-overflow-hidden univer-font-[500] univer-truncate univer-h-[24px] univer-mb-2 univer-leading-[24px] univer-ellipsis univer-cursor-pointer",Bl="univer-text-base univer-font-semibold",_l="univer-text-sm univer-font-semibold",Nl="univer-text-sm",Pl=U.forwardRef((i,t)=>{const{menus:e,onClick:n,className:o,style:a,mode:r,maxHeight:c,activeId:l,open:A,onOpenChange:d,maxWidth:u,wrapperClass:m,wrapperStyle:h,iconClass:g,iconStyle:p}=i,f=r==="side-bar",S=U.useRef(null),E=U.useRef(e);E.current=e;const C=U.useMemo(()=>({scrollTo:b=>{var x;if(!E.current||E.current.findIndex(w=>w.id===b)===-1||!S.current)return;const I=document.getElementById(`univer-side-menu-${b}`);if(!I)return;const O=I.offsetTop,M=S.current.clientHeight,y=S.current.scrollHeight-M,N=Math.max(0,Math.min(O-M/2+I.clientHeight/2,y));(x=S.current)==null||x.scrollTo({behavior:"smooth",top:N})}}),[]);return U.useImperativeHandle(t,()=>C),U.useEffect(()=>{l&&C.scrollTo(l)},[l,C]),P.jsxs("div",{className:ee.clsx("univer-relative",m),style:h,children:[P.jsx("div",{onClick:()=>d==null?void 0:d(!A),className:ee.clsx(`
|
|
52
51
|
univer-absolute univer-left-5 univer-top-4 univer-z-[100] univer-flex univer-h-8 univer-w-8
|
|
53
52
|
univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white
|
|
54
53
|
univer-text-gray-800
|
|
@@ -57,10 +56,9 @@ ${s.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
57
56
|
univer-absolute univer-left-0 univer-top-0 univer-box-border univer-flex univer-min-w-[180px]
|
|
58
57
|
univer-flex-col univer-pb-4 univer-pl-5 univer-pr-5 univer-pt-14 univer-transition-all
|
|
59
58
|
univer-duration-300
|
|
60
|
-
`,f?"":["univer-bg-white","univer-rounded-r-2xl","univer-shadow-[0px_1px_6px_-2px_rgba(30,40,77,0.08),0px_2px_6px_-1px_rgba(30,40,77,0.10)]","univer-backdrop-blur-[10px]"]),style:{...a,transform:A?"translateX(0)":"translateX(-100%)",maxHeight:c,opacity:A?1:0,maxWidth:u!=null?u:r==="side-bar"?480:180,paddingRight:r==="float"?void 0:0},children:P.jsx("div",{ref:S,className
|
|
59
|
+
`,f?"":["univer-bg-white","univer-rounded-r-2xl","univer-shadow-[0px_1px_6px_-2px_rgba(30,40,77,0.08),0px_2px_6px_-1px_rgba(30,40,77,0.10)]","univer-backdrop-blur-[10px]"]),style:{...a,transform:A?"translateX(0)":"translateX(-100%)",maxHeight:c,opacity:A?1:0,maxWidth:u!=null?u:r==="side-bar"?480:180,paddingRight:r==="float"?void 0:0},children:P.jsx("div",{ref:S,className:ee.clsx(`
|
|
61
60
|
univer-flex-1 univer-overflow-y-auto univer-overflow-x-hidden univer-scrollbar-none
|
|
62
|
-
[&::-webkit-scrollbar]:univer-hidden
|
|
63
|
-
`,children:e==null?void 0:e.map(b=>P.jsx("div",{id:`univer-side-menu-${b.id}`,className:ee.clsx(Dl,{[Bl]:b.isTitle,[_l]:b.level===1,[Nl]:b.level>1,"univer-text-gray-500":b.id!==l,"univer-text-gray-800":b.id===l}),style:{paddingLeft:(b.level-1)*12},onClick:()=>{n==null||n(b)},children:b.text},b.id))})})]})}),Ul=i=>{switch(i){case s.NamedStyleType.HEADING_1:return 1;case s.NamedStyleType.HEADING_2:return 2;case s.NamedStyleType.HEADING_3:return 3;case s.NamedStyleType.HEADING_4:return 4;case s.NamedStyleType.HEADING_5:return 5;case s.NamedStyleType.TITLE:return 1;default:return 1}};function wl(i,t,e,n){var c,l;if(!i)return;const o=Array.from(i.values()),a=o.findIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);if(a===-1)return;const r=o==null?void 0:o.findLastIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);for(let A=a;A<=r;A++){const d=o[A],u=t.get(d.startIndex);if((c=u==null?void 0:u.paragraphStyle)!=null&&c.headingId)return u.paragraphStyle.headingId}for(let A=a;A>=0;A--){const d=o[A],u=t.get(d.startIndex);if((l=u==null?void 0:u.paragraphStyle)!=null&&l.headingId)return u.paragraphStyle.headingId}}const Ys="__title";function Ll(){var t,e,n;const i=v.useConfigValue(un);return(n=(e=(t=i==null?void 0:i.layout)==null?void 0:t.docContainerConfig)==null?void 0:e.sideMenu)==null||n?P.jsx(Ql,{}):null}function Ql(){var N,x,w,H,V,F,Q,j,G;const i=v.useDependency(s.ICommandService),t=v.useDependency(s.IUniverInstanceService),e=v.useObservable(U.useMemo(()=>t.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC),[])),n=v.useDependency(_.IRenderManagerService),o=(x=(N=e==null?void 0:e.getBody())==null?void 0:N.dataStream)!=null?x:"",[a,r]=U.useState(0),[c,l]=U.useState(void 0),A=(w=e==null?void 0:e.getUnitId())!=null?w:"",d=n.getRenderById(A),u=e==null?void 0:e.getTitle(),m=d==null?void 0:d.with(T.DocEventManagerService),h=m==null?void 0:m.paragraphBounds,g=(V=(H=d==null?void 0:d.mainComponent)==null?void 0:H.left)!=null?V:0,p=(F=d==null?void 0:d.engine.height)!=null?F:0,f=(Q=d==null?void 0:d.scene.scaleY)!=null?Q:1,S=(G=(j=e==null?void 0:e.getBody())==null?void 0:j.paragraphs)!=null?G:[],E=U.useMemo(()=>{const k=new Map;return S.forEach(W=>{k.set(W.startIndex,W)}),k},[S]);v.useObservable(U.useMemo(()=>d!=null&&d.engine.onTransformChange$?s.fromEventSubject(d==null?void 0:d.engine.onTransformChange$).pipe(L.throttleTime(33)):L.of(null),[d==null?void 0:d.engine.onTransformChange$]));const C=g<180?"float":"side-bar",b=S==null?void 0:S.filter(k=>{var W;return((W=k.paragraphStyle)==null?void 0:W.namedStyleType)!==void 0&&k.paragraphStyle.namedStyleType!==s.NamedStyleType.SUBTITLE&&k.paragraphStyle.namedStyleType!==s.NamedStyleType.NORMAL_TEXT}).map(k=>{var q;const W=Ul(k.paragraphStyle.namedStyleType),z=h==null?void 0:h.get(k.startIndex);if(!z)return null;const{paragraphStart:X,paragraphEnd:Y}=z;return{id:k.paragraphStyle.headingId,text:s.getPlainText(o.slice(X,Y)),level:W,isTitle:((q=k.paragraphStyle)==null?void 0:q.namedStyleType)===s.NamedStyleType.TITLE}}).filter(k=>k==null?void 0:k.text),R=v.useEvent(k=>{const W=k.viewportScrollY,z=W+p/f,X=wl(h,E,W,z);X&&l(X)}),I=b!=null&&b.find(k=>k.isTitle)?b:[...u?[{id:Ys,text:u,level:1,isTitle:!0}]:[],...b!=null?b:[]].filter(Boolean),[O,M]=U.useState(!0);U.useEffect(()=>{const k=s.debounce(r,100),W=i.onCommandExecuted(z=>{z.id===D.RichTextEditingMutation.id&&z.params.unitId===(e==null?void 0:e.getUnitId())&&k(Y=>Y+1)});return()=>{W.dispose()}},[i,e]),U.useEffect(()=>{const k=d==null?void 0:d.scene.getViewport(ae.VIEW_MAIN);if(!k)return;const W=s.fromEventSubject(k.onScrollAfter$).pipe(L.throttleTime(33)).subscribe(R);return()=>{W.unsubscribe()}},[d]);const y=v.useEvent(k=>{const W=d==null?void 0:d.scene.getViewport(ae.VIEW_MAIN);if(!W)return;if(k.id===Ys){W.scrollToViewportPos({viewportScrollY:0});return}const z=S.find(Y=>{var q;return((q=Y.paragraphStyle)==null?void 0:q.headingId)===k.id});if(!z)return;const X=h==null?void 0:h.get(z.startIndex);X&&(W.scrollToViewportPos({viewportScrollY:X.rect.top}),l(k.id))});return!e||s.isInternalEditorID(A)||!(I!=null&&I.length)?null:P.jsx("div",{className:"univer-absolute univer-bottom-0 univer-left-0 univer-top-0 univer-z-[100] univer-w-[0px]",children:P.jsx(Pl,{menus:I,open:O,onOpenChange:M,mode:C,maxWidth:C==="float"?void 0:Math.floor(g),wrapperClass:"univer-mt-12",activeId:c,onClick:y,maxHeight:p-48})})}const hn={id:"doc.table.delete-rows",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=t.getRectRanges(),a=t.getActiveTextRange(),r=gt(a,o);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,g=s.JSONX.getInstance(),p=ns(r,u);if(p==null)return!1;const{offset:f,rowIndexes:S,len:E,tableId:C,cursor:b,selectWholeTable:R}=p;if(R)return n.executeCommand(at.id);const I=[],O=[{startOffset:b,endOffset:b,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:O}};f>0&&h.push({t:s.TextXActionType.RETAIN,len:f}),h.push({t:s.TextXActionType.DELETE,len:E});const y=J(l,c);I.push(g.editOp(h.serialize(),y));for(const x of S.reverse()){const w=g.removeOp(["tableSource",C,"tableRows",x]);I.push(w)}return M.params.actions=I.reduce((x,w)=>s.JSONX.compose(x,w),null),!!n.syncExecuteCommand(M.id,M.params)}},gn={id:"doc.table.delete-columns",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=t.getRectRanges(),a=t.getActiveTextRange(),r=gt(a,o);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,g=s.JSONX.getInstance(),p=Nr(r,u);if(p==null)return!1;const{offsets:f,columnIndexes:S,tableId:E,cursor:C,rowCount:b,selectWholeTable:R}=p;if(R)return n.executeCommand(at.id);const I=[],O=[{startOffset:C,endOffset:C,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:O}};for(const x of f){const{retain:w,delete:H}=x;w>0&&h.push({t:s.TextXActionType.RETAIN,len:w}),h.push({t:s.TextXActionType.DELETE,len:H})}const y=J(l,c);I.push(g.editOp(h.serialize(),y)),S.reverse();for(let x=0;x<b;x++)for(const w of S){const H=g.removeOp(["tableSource",E,"tableRows",x,"tableCells",w]);I.push(H)}for(const x of S){const w=g.removeOp(["tableSource",E,"tableColumns",x]);I.push(w)}return M.params.actions=I.reduce((x,w)=>s.JSONX.compose(x,w),null),!!n.syncExecuteCommand(M.id,M.params)}},at={id:"doc.table.delete-table",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=t.getRectRanges(),a=t.getActiveTextRange(),r=gt(a,o);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,g=s.JSONX.getInstance(),p=is(r,u);if(p==null)return!1;const{offset:f,len:S,tableId:E,cursor:C}=p,b=[],R=[{startOffset:C,endOffset:C,collapsed:!0}],I={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:R}};f>0&&h.push({t:s.TextXActionType.RETAIN,len:f}),h.push({t:s.TextXActionType.DELETE,len:S});const O=J(l,c);b.push(g.editOp(h.serialize(),O));const M=g.removeOp(["tableSource",E]);return b.push(M),I.params.actions=b.reduce((N,x)=>s.JSONX.compose(N,x),null),!!n.syncExecuteCommand(I.id,I.params)}},Li="doc.command.table-insert-row",Qi="doc.command.table-insert-column",Fl="doc.command.table-insert-row-above",Hl="doc.command.table-insert-row-bellow",kl="doc.command.table-insert-column-left",Vl="doc.command.table-insert-column-right",mn={id:Fl,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Li,{position:jt.ABOVE})},pn={id:Hl,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Li,{position:jt.BELLOW})},fn={id:kl,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Qi,{position:ti.LEFT})},Sn={id:Vl,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Qi,{position:ti.RIGHT})},Fi={id:Li,type:s.CommandType.COMMAND,handler:async(i,t)=>{const{position:e}=t,n=i.get(D.DocSelectionManagerService),o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),r=n.getRectRanges(),c=n.getActiveTextRange(),l=gt(c,r);if(l==null)return!1;const{segmentId:A}=l,d=o.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=re(i,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),g=d==null?void 0:d.getUnitId(),p=new s.TextX,f=s.JSONX.getInstance(),S=Dr(l,e,h);if(S==null)return!1;const{offset:E,colCount:C,tableId:b,insertRowIndex:R}=S,I=[],O=E+2,M=[{startOffset:O,endOffset:O,collapsed:!0}],y={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:M}};E>0&&p.push({t:s.TextXActionType.RETAIN,len:E});const N=Mr(C);p.push({t:s.TextXActionType.INSERT,body:N,len:N.dataStream.length});const x=J(d,A);I.push(f.editOp(p.serialize(),x));const w=Kt(C),H=f.insertOp(["tableSource",b,"tableRows",R],w);return I.push(H),y.params.actions=I.reduce((F,Q)=>s.JSONX.compose(F,Q),null),!!a.syncExecuteCommand(y.id,y.params)}},qs={id:Qi,type:s.CommandType.COMMAND,handler:async(i,t)=>{var X,Y,q;const{position:e}=t,n=i.get(D.DocSelectionManagerService),o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),r=n.getRectRanges(),c=n.getActiveTextRange(),l=gt(c,r);if(l==null)return!1;const{segmentId:A}=l,d=o.getCurrentUniverDocInstance(),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=re(i,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),g=d==null?void 0:d.getUnitId(),p=new s.TextX,f=s.JSONX.getInstance(),S=Br(l,e,h);if(S==null)return!1;const{offsets:E,columnIndex:C,tableId:b,rowCount:R}=S,I=[],O=E[0]+1,M=[{startOffset:O,endOffset:O,collapsed:!0}],y={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:M}};for(const K of E){p.push({t:s.TextXActionType.RETAIN,len:K});const Z=xr();p.push({t:s.TextXActionType.INSERT,body:Z,len:Z.dataStream.length})}const N=J(d,A);I.push(f.editOp(p.serialize(),N));for(let K=0;K<R;K++){const Z=Xt(),ie=f.insertOp(["tableSource",b,"tableRows",K,"tableCells",C],Z);I.push(ie)}const x=d.getSnapshot(),w=x.documentStyle,{marginLeft:H=0,marginRight:V=0}=w,F=((Y=(X=w.pageSize)==null?void 0:X.width)!=null?Y:800)-H-V,Q=(q=x==null?void 0:x.tableSource)==null?void 0:q[b].tableColumns,{newColWidth:j,widths:G}=_r(F,Q,C);for(let K=0;K<G.length;K++){const Z=f.replaceOp(["tableSource",b,"tableColumns",K,"size","width","v"],Q[K].size.width.v,G[K]);I.push(Z)}const k=Yt(j),W=f.insertOp(["tableSource",b,"tableColumns",C],k);return I.push(W),y.params.actions=I.reduce((K,Z)=>s.JSONX.compose(K,Z),null),!!a.syncExecuteCommand(y.id,y.params)}},pe={id:"doc-paragraph-setting.command",type:s.CommandType.COMMAND,handler:async(i,t)=>{var C,b,R,I,O;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),a=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),r=e.getDocRanges();if(!a||r.length===0||!t)return!1;const c=r[0].segmentId,l=a.getUnitId(),A=a.getSelfOrHeaderFooterModel(c),d=(b=(C=A.getBody())==null?void 0:C.paragraphs)!=null?b:[],u=(I=(R=A.getBody())==null?void 0:R.dataStream)!=null?I:"",m=(O=s.BuildTextUtils.range.getParagraphsInRanges(r,d,u))!=null?O:[],h={id:D.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:r}},g=new s.MemoryCursor;g.reset();const p=new s.TextX,f=s.JSONX.getInstance();for(const M of m){const{startIndex:y}=M;p.push({t:s.TextXActionType.RETAIN,len:y-g.cursor});const N={...M.paragraphStyle,...t.paragraph};p.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...M,paragraphStyle:N,startIndex:0}]},coverType:s.UpdateDocsAttributeType.REPLACE}),g.moveCursorTo(y+1)}const S=J(a,c);return h.params.actions=f.editOp(p.serialize(),S),!!o.syncExecuteCommand(h.id,h.params)}},Wl=()=>{const i=v.useDependency(D.DocSelectionManagerService),t=v.useDependency(rt),e=U.useMemo(()=>i.getDocRanges(),[]);return U.useEffect(()=>{e.length||t.closePanel()},[e]),e},zl=()=>{var l,A,d,u,m;const t=v.useDependency(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),e=Wl();if(!t||e.length===0)return[];const n=e[0].segmentId,o=t.getSelfOrHeaderFooterModel(n),a=(A=(l=o.getBody())==null?void 0:l.paragraphs)!=null?A:[],r=(u=(d=o.getBody())==null?void 0:d.dataStream)!=null?u:"";return(m=s.BuildTextUtils.range.getParagraphsInRanges(e,a,r))!=null?m:[]},Gl=(i,t)=>{const e=v.useDependency(s.ICommandService),[n,o]=U.useState(()=>{var c,l;const r=i[0];return r?String((l=(c=r.paragraphStyle)==null?void 0:c.horizontalAlign)!=null?l:t):t});return[n,r=>(o(r),e.executeCommand(pe.id,{paragraph:{horizontalAlign:Number(r)}}))]},jl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentStart,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{indentStart:{v:a}}}))]},Xl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentEnd,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{indentEnd:{v:a}}}))]},Kl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentFirstLine,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{indentFirstLine:{v:a}}}))]},Yl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.hanging,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{hanging:{v:a}}}))]},ql=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.spaceAbove,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{spaceAbove:{v:a}}}))]},Jl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.spaceBelow,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{spaceBelow:{v:a}}}))]},Zl=i=>{const t=v.useDependency(s.ICommandService),e=v.useDependency(_.IRenderManagerService),n=v.useDependency(s.IUniverInstanceService),o=U.useMemo(()=>{var g;const h=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(h)return(g=e.getRenderById(h==null?void 0:h.getUnitId()))==null?void 0:g.with(D.DocSkeletonManagerService).getSkeleton()},[]),a=U.useMemo(()=>new L.BehaviorSubject({}),[]),[r,c]=U.useState(()=>{var g,p;const h=i[0];return h&&(p=(g=h.paragraphStyle)==null?void 0:g.lineSpacing)!=null?p:1}),l=U.useRef(r),[A,d]=U.useState(()=>{var g,p;const h=i[0];return h&&(p=(g=h.paragraphStyle)==null?void 0:g.spacingRule)!=null?p:s.SpacingRule.AUTO}),u=async h=>{c(h),a.next({lineSpacing:h,spacingRule:A})},m=async h=>{if(h!==A){let g=l.current;if(h===s.SpacingRule.AT_LEAST){const p=o==null?void 0:o.findNodeByCharIndex(i[0].startIndex),f=p==null?void 0:p.parent,S=f==null?void 0:f.parent;(S==null?void 0:S.contentHeight)!==void 0&&(g=Math.max(S.contentHeight,g))}else g>5&&(g=2);l.current=r,u(g),d(h),a.next({spacingRule:h})}};return U.useEffect(()=>{const h=a.pipe(At.filter(g=>!!Object.keys(g).length),At.bufferTime(16),At.filter(g=>!!g.length),At.map(g=>g.reduce((p,f)=>(Object.keys(f).forEach(S=>{p[S]=f[S]}),p),{}))).subscribe(g=>t.executeCommand(pe.id,{paragraph:{...g}}));return()=>h.unsubscribe()},[]),{lineSpacing:[r,u],spacingRule:[A,m]}},Xe=i=>{const{value:t,onChange:e,className:n="",min:o=0,max:a=100,step:r=1}=i,c=U.useRef(null);return P.jsx(ee.InputNumber,{step:r,ref:c,min:o,max:a,value:t,onChange:l=>{e(l!=null?l:0).finally(()=>{setTimeout(()=>{var A;(A=c.current)==null||A.focus()},30)})},className:n})};function $l(){const i=v.useDependency(s.LocaleService),t=U.useMemo(()=>[{label:i.t("toolbar.alignLeft"),value:String(s.HorizontalAlign.LEFT),icon:P.jsx(Fo,{})},{label:i.t("toolbar.alignCenter"),value:String(s.HorizontalAlign.CENTER),icon:P.jsx(Qo,{})},{label:i.t("toolbar.alignRight"),value:String(s.HorizontalAlign.RIGHT),icon:P.jsx(ko,{})},{label:i.t("toolbar.alignJustify"),value:String(s.HorizontalAlign.JUSTIFIED),icon:P.jsx(Ro,{})}],[]),e=zl(),[n,o]=Gl(e,t[0].value),[a,r]=jl(e),[c,l]=Xl(e),[A,d]=Kl(e),[u,m]=Yl(e),[h,g]=ql(e),[p,f]=Jl(e),{lineSpacing:[S,E],spacingRule:[C,b]}=Zl(e),R=U.useMemo(()=>C===s.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[C,S]);return P.jsxs("div",{children:[P.jsx("div",{className:"univer-t-4 univer-text-[13px] univer-font-medium",children:i.t("doc.paragraphSetting.alignment")}),P.jsx("div",{className:`
|
|
61
|
+
`),children:e==null?void 0:e.map(b=>P.jsx("div",{id:`univer-side-menu-${b.id}`,className:ee.clsx(Dl,{[Bl]:b.isTitle,[_l]:b.level===1,[Nl]:b.level>1,"univer-text-gray-500":b.id!==l,"univer-text-gray-800":b.id===l}),style:{paddingLeft:(b.level-1)*12},onClick:()=>{n==null||n(b)},children:b.text},b.id))})})]})}),Ul=i=>{switch(i){case s.NamedStyleType.HEADING_1:return 1;case s.NamedStyleType.HEADING_2:return 2;case s.NamedStyleType.HEADING_3:return 3;case s.NamedStyleType.HEADING_4:return 4;case s.NamedStyleType.HEADING_5:return 5;case s.NamedStyleType.TITLE:return 1;default:return 1}};function wl(i,t,e,n){var c,l;if(!i)return;const o=Array.from(i.values()),a=o.findIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);if(a===-1)return;const r=o==null?void 0:o.findLastIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);for(let A=a;A<=r;A++){const d=o[A],u=t.get(d.startIndex);if((c=u==null?void 0:u.paragraphStyle)!=null&&c.headingId)return u.paragraphStyle.headingId}for(let A=a;A>=0;A--){const d=o[A],u=t.get(d.startIndex);if((l=u==null?void 0:u.paragraphStyle)!=null&&l.headingId)return u.paragraphStyle.headingId}}const Ys="__title";function Ll(){var t,e,n;const i=v.useConfigValue(un);return(n=(e=(t=i==null?void 0:i.layout)==null?void 0:t.docContainerConfig)==null?void 0:e.sideMenu)==null||n?P.jsx(Ql,{}):null}function Ql(){var N,x,w,H,V,F,Q,j,G;const i=v.useDependency(s.ICommandService),t=v.useDependency(s.IUniverInstanceService),e=v.useObservable(U.useMemo(()=>t.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC),[])),n=v.useDependency(_.IRenderManagerService),o=(x=(N=e==null?void 0:e.getBody())==null?void 0:N.dataStream)!=null?x:"",[a,r]=U.useState(0),[c,l]=U.useState(void 0),A=(w=e==null?void 0:e.getUnitId())!=null?w:"",d=n.getRenderById(A),u=e==null?void 0:e.getTitle(),m=d==null?void 0:d.with(T.DocEventManagerService),h=m==null?void 0:m.paragraphBounds,g=(V=(H=d==null?void 0:d.mainComponent)==null?void 0:H.left)!=null?V:0,p=(F=d==null?void 0:d.engine.height)!=null?F:0,f=(Q=d==null?void 0:d.scene.scaleY)!=null?Q:1,S=(G=(j=e==null?void 0:e.getBody())==null?void 0:j.paragraphs)!=null?G:[],E=U.useMemo(()=>{const k=new Map;return S.forEach(W=>{k.set(W.startIndex,W)}),k},[S]);v.useObservable(U.useMemo(()=>d!=null&&d.engine.onTransformChange$?s.fromEventSubject(d==null?void 0:d.engine.onTransformChange$).pipe(L.throttleTime(33)):L.of(null),[d==null?void 0:d.engine.onTransformChange$]));const C=g<180?"float":"side-bar",b=S==null?void 0:S.filter(k=>{var W;return((W=k.paragraphStyle)==null?void 0:W.namedStyleType)!==void 0&&k.paragraphStyle.namedStyleType!==s.NamedStyleType.SUBTITLE&&k.paragraphStyle.namedStyleType!==s.NamedStyleType.NORMAL_TEXT}).map(k=>{var q;const W=Ul(k.paragraphStyle.namedStyleType),z=h==null?void 0:h.get(k.startIndex);if(!z)return null;const{paragraphStart:X,paragraphEnd:Y}=z;return{id:k.paragraphStyle.headingId,text:s.getPlainText(o.slice(X,Y)),level:W,isTitle:((q=k.paragraphStyle)==null?void 0:q.namedStyleType)===s.NamedStyleType.TITLE}}).filter(k=>k==null?void 0:k.text),R=v.useEvent(k=>{const W=k.viewportScrollY,z=W+p/f,X=wl(h,E,W,z);X&&l(X)}),I=b!=null&&b.find(k=>k.isTitle)?b:[...u?[{id:Ys,text:u,level:1,isTitle:!0}]:[],...b!=null?b:[]].filter(Boolean),[O,M]=U.useState(!0);U.useEffect(()=>{const k=s.debounce(r,100),W=i.onCommandExecuted(z=>{z.id===D.RichTextEditingMutation.id&&z.params.unitId===(e==null?void 0:e.getUnitId())&&k(Y=>Y+1)});return()=>{W.dispose()}},[i,e]),U.useEffect(()=>{const k=d==null?void 0:d.scene.getViewport(ae.VIEW_MAIN);if(!k)return;const W=s.fromEventSubject(k.onScrollAfter$).pipe(L.throttleTime(33)).subscribe(R);return()=>{W.unsubscribe()}},[d]);const y=v.useEvent(k=>{const W=d==null?void 0:d.scene.getViewport(ae.VIEW_MAIN);if(!W)return;if(k.id===Ys){W.scrollToViewportPos({viewportScrollY:0});return}const z=S.find(Y=>{var q;return((q=Y.paragraphStyle)==null?void 0:q.headingId)===k.id});if(!z)return;const X=h==null?void 0:h.get(z.startIndex);X&&(W.scrollToViewportPos({viewportScrollY:X.rect.top}),l(k.id))});return!e||s.isInternalEditorID(A)||!(I!=null&&I.length)?null:P.jsx("div",{className:"univer-absolute univer-bottom-0 univer-left-0 univer-top-0 univer-z-[100] univer-w-[0px]",children:P.jsx(Pl,{menus:I,open:O,onOpenChange:M,mode:C,maxWidth:C==="float"?void 0:Math.floor(g),wrapperClass:"univer-mt-12",activeId:c,onClick:y,maxHeight:p-48})})}const hn={id:"doc.table.delete-rows",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=t.getRectRanges(),a=t.getActiveTextRange(),r=gt(a,o);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,g=s.JSONX.getInstance(),p=ns(r,u);if(p==null)return!1;const{offset:f,rowIndexes:S,len:E,tableId:C,cursor:b,selectWholeTable:R}=p;if(R)return n.executeCommand(at.id);const I=[],O=[{startOffset:b,endOffset:b,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:O}};f>0&&h.push({t:s.TextXActionType.RETAIN,len:f}),h.push({t:s.TextXActionType.DELETE,len:E});const y=J(l,c);I.push(g.editOp(h.serialize(),y));for(const x of S.reverse()){const w=g.removeOp(["tableSource",C,"tableRows",x]);I.push(w)}return M.params.actions=I.reduce((x,w)=>s.JSONX.compose(x,w),null),!!n.syncExecuteCommand(M.id,M.params)}},gn={id:"doc.table.delete-columns",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=t.getRectRanges(),a=t.getActiveTextRange(),r=gt(a,o);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,g=s.JSONX.getInstance(),p=Nr(r,u);if(p==null)return!1;const{offsets:f,columnIndexes:S,tableId:E,cursor:C,rowCount:b,selectWholeTable:R}=p;if(R)return n.executeCommand(at.id);const I=[],O=[{startOffset:C,endOffset:C,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:O}};for(const x of f){const{retain:w,delete:H}=x;w>0&&h.push({t:s.TextXActionType.RETAIN,len:w}),h.push({t:s.TextXActionType.DELETE,len:H})}const y=J(l,c);I.push(g.editOp(h.serialize(),y)),S.reverse();for(let x=0;x<b;x++)for(const w of S){const H=g.removeOp(["tableSource",E,"tableRows",x,"tableCells",w]);I.push(H)}for(const x of S){const w=g.removeOp(["tableSource",E,"tableColumns",x]);I.push(w)}return M.params.actions=I.reduce((x,w)=>s.JSONX.compose(x,w),null),!!n.syncExecuteCommand(M.id,M.params)}},at={id:"doc.table.delete-table",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=t.getRectRanges(),a=t.getActiveTextRange(),r=gt(a,o);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,g=s.JSONX.getInstance(),p=is(r,u);if(p==null)return!1;const{offset:f,len:S,tableId:E,cursor:C}=p,b=[],R=[{startOffset:C,endOffset:C,collapsed:!0}],I={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:R}};f>0&&h.push({t:s.TextXActionType.RETAIN,len:f}),h.push({t:s.TextXActionType.DELETE,len:S});const O=J(l,c);b.push(g.editOp(h.serialize(),O));const M=g.removeOp(["tableSource",E]);return b.push(M),I.params.actions=b.reduce((N,x)=>s.JSONX.compose(N,x),null),!!n.syncExecuteCommand(I.id,I.params)}},Li="doc.command.table-insert-row",Qi="doc.command.table-insert-column",Fl="doc.command.table-insert-row-above",Hl="doc.command.table-insert-row-bellow",kl="doc.command.table-insert-column-left",Vl="doc.command.table-insert-column-right",mn={id:Fl,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Li,{position:jt.ABOVE})},pn={id:Hl,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Li,{position:jt.BELLOW})},fn={id:kl,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Qi,{position:ti.LEFT})},Sn={id:Vl,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Qi,{position:ti.RIGHT})},Fi={id:Li,type:s.CommandType.COMMAND,handler:async(i,t)=>{const{position:e}=t,n=i.get(D.DocSelectionManagerService),o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),r=n.getRectRanges(),c=n.getActiveTextRange(),l=gt(c,r);if(l==null)return!1;const{segmentId:A}=l,d=o.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=re(i,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),g=d==null?void 0:d.getUnitId(),p=new s.TextX,f=s.JSONX.getInstance(),S=Dr(l,e,h);if(S==null)return!1;const{offset:E,colCount:C,tableId:b,insertRowIndex:R}=S,I=[],O=E+2,M=[{startOffset:O,endOffset:O,collapsed:!0}],y={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:M}};E>0&&p.push({t:s.TextXActionType.RETAIN,len:E});const N=Mr(C);p.push({t:s.TextXActionType.INSERT,body:N,len:N.dataStream.length});const x=J(d,A);I.push(f.editOp(p.serialize(),x));const w=Kt(C),H=f.insertOp(["tableSource",b,"tableRows",R],w);return I.push(H),y.params.actions=I.reduce((F,Q)=>s.JSONX.compose(F,Q),null),!!a.syncExecuteCommand(y.id,y.params)}},qs={id:Qi,type:s.CommandType.COMMAND,handler:async(i,t)=>{var X,Y,q;const{position:e}=t,n=i.get(D.DocSelectionManagerService),o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),r=n.getRectRanges(),c=n.getActiveTextRange(),l=gt(c,r);if(l==null)return!1;const{segmentId:A}=l,d=o.getCurrentUniverDocInstance(),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=re(i,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),g=d==null?void 0:d.getUnitId(),p=new s.TextX,f=s.JSONX.getInstance(),S=Br(l,e,h);if(S==null)return!1;const{offsets:E,columnIndex:C,tableId:b,rowCount:R}=S,I=[],O=E[0]+1,M=[{startOffset:O,endOffset:O,collapsed:!0}],y={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:M}};for(const K of E){p.push({t:s.TextXActionType.RETAIN,len:K});const Z=xr();p.push({t:s.TextXActionType.INSERT,body:Z,len:Z.dataStream.length})}const N=J(d,A);I.push(f.editOp(p.serialize(),N));for(let K=0;K<R;K++){const Z=Xt(),ie=f.insertOp(["tableSource",b,"tableRows",K,"tableCells",C],Z);I.push(ie)}const x=d.getSnapshot(),w=x.documentStyle,{marginLeft:H=0,marginRight:V=0}=w,F=((Y=(X=w.pageSize)==null?void 0:X.width)!=null?Y:800)-H-V,Q=(q=x==null?void 0:x.tableSource)==null?void 0:q[b].tableColumns,{newColWidth:j,widths:G}=_r(F,Q,C);for(let K=0;K<G.length;K++){const Z=f.replaceOp(["tableSource",b,"tableColumns",K,"size","width","v"],Q[K].size.width.v,G[K]);I.push(Z)}const k=Yt(j),W=f.insertOp(["tableSource",b,"tableColumns",C],k);return I.push(W),y.params.actions=I.reduce((K,Z)=>s.JSONX.compose(K,Z),null),!!a.syncExecuteCommand(y.id,y.params)}},pe={id:"doc-paragraph-setting.command",type:s.CommandType.COMMAND,handler:async(i,t)=>{var C,b,R,I,O;const e=i.get(D.DocSelectionManagerService),n=i.get(s.IUniverInstanceService),o=i.get(s.ICommandService),a=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),r=e.getDocRanges();if(!a||r.length===0||!t)return!1;const c=r[0].segmentId,l=a.getUnitId(),A=a.getSelfOrHeaderFooterModel(c),d=(b=(C=A.getBody())==null?void 0:C.paragraphs)!=null?b:[],u=(I=(R=A.getBody())==null?void 0:R.dataStream)!=null?I:"",m=(O=s.BuildTextUtils.range.getParagraphsInRanges(r,d,u))!=null?O:[],h={id:D.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:r}},g=new s.MemoryCursor;g.reset();const p=new s.TextX,f=s.JSONX.getInstance();for(const M of m){const{startIndex:y}=M;p.push({t:s.TextXActionType.RETAIN,len:y-g.cursor});const N={...M.paragraphStyle,...t.paragraph};p.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...M,paragraphStyle:N,startIndex:0}]},coverType:s.UpdateDocsAttributeType.REPLACE}),g.moveCursorTo(y+1)}const S=J(a,c);return h.params.actions=f.editOp(p.serialize(),S),!!o.syncExecuteCommand(h.id,h.params)}},Wl=()=>{const i=v.useDependency(D.DocSelectionManagerService),t=v.useDependency(rt),e=U.useMemo(()=>i.getDocRanges(),[]);return U.useEffect(()=>{e.length||t.closePanel()},[e]),e},zl=()=>{var l,A,d,u,m;const t=v.useDependency(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),e=Wl();if(!t||e.length===0)return[];const n=e[0].segmentId,o=t.getSelfOrHeaderFooterModel(n),a=(A=(l=o.getBody())==null?void 0:l.paragraphs)!=null?A:[],r=(u=(d=o.getBody())==null?void 0:d.dataStream)!=null?u:"";return(m=s.BuildTextUtils.range.getParagraphsInRanges(e,a,r))!=null?m:[]},Gl=(i,t)=>{const e=v.useDependency(s.ICommandService),[n,o]=U.useState(()=>{var c,l;const r=i[0];return r?String((l=(c=r.paragraphStyle)==null?void 0:c.horizontalAlign)!=null?l:t):t});return[n,r=>(o(r),e.executeCommand(pe.id,{paragraph:{horizontalAlign:Number(r)}}))]},jl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentStart,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{indentStart:{v:a}}}))]},Xl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentEnd,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{indentEnd:{v:a}}}))]},Kl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentFirstLine,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{indentFirstLine:{v:a}}}))]},Yl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.hanging,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{hanging:{v:a}}}))]},ql=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.spaceAbove,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{spaceAbove:{v:a}}}))]},Jl=i=>{const t=v.useDependency(s.ICommandService),[e,n]=U.useState(()=>{var r;const a=i[0];return a?_.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.spaceBelow,0):0});return[e,a=>(n(a),t.executeCommand(pe.id,{paragraph:{spaceBelow:{v:a}}}))]},Zl=i=>{const t=v.useDependency(s.ICommandService),e=v.useDependency(_.IRenderManagerService),n=v.useDependency(s.IUniverInstanceService),o=U.useMemo(()=>{var g;const h=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(h)return(g=e.getRenderById(h==null?void 0:h.getUnitId()))==null?void 0:g.with(D.DocSkeletonManagerService).getSkeleton()},[]),a=U.useMemo(()=>new L.BehaviorSubject({}),[]),[r,c]=U.useState(()=>{var g,p;const h=i[0];return h&&(p=(g=h.paragraphStyle)==null?void 0:g.lineSpacing)!=null?p:1}),l=U.useRef(r),[A,d]=U.useState(()=>{var g,p;const h=i[0];return h&&(p=(g=h.paragraphStyle)==null?void 0:g.spacingRule)!=null?p:s.SpacingRule.AUTO}),u=async h=>{c(h),a.next({lineSpacing:h,spacingRule:A})},m=async h=>{if(h!==A){let g=l.current;if(h===s.SpacingRule.AT_LEAST){const p=o==null?void 0:o.findNodeByCharIndex(i[0].startIndex),f=p==null?void 0:p.parent,S=f==null?void 0:f.parent;(S==null?void 0:S.contentHeight)!==void 0&&(g=Math.max(S.contentHeight,g))}else g>5&&(g=2);l.current=r,u(g),d(h),a.next({spacingRule:h})}};return U.useEffect(()=>{const h=a.pipe(At.filter(g=>!!Object.keys(g).length),At.bufferTime(16),At.filter(g=>!!g.length),At.map(g=>g.reduce((p,f)=>(Object.keys(f).forEach(S=>{p[S]=f[S]}),p),{}))).subscribe(g=>t.executeCommand(pe.id,{paragraph:{...g}}));return()=>h.unsubscribe()},[]),{lineSpacing:[r,u],spacingRule:[A,m]}},Xe=i=>{const{value:t,onChange:e,className:n="",min:o=0,max:a=100,step:r=1}=i,c=U.useRef(null);return P.jsx(ee.InputNumber,{step:r,ref:c,min:o,max:a,value:t,onChange:l=>{e(l!=null?l:0).finally(()=>{setTimeout(()=>{var A;(A=c.current)==null||A.focus()},30)})},className:n})};function $l(){const i=v.useDependency(s.LocaleService),t=U.useMemo(()=>[{label:i.t("toolbar.alignLeft"),value:String(s.HorizontalAlign.LEFT),icon:P.jsx(Fo,{})},{label:i.t("toolbar.alignCenter"),value:String(s.HorizontalAlign.CENTER),icon:P.jsx(Qo,{})},{label:i.t("toolbar.alignRight"),value:String(s.HorizontalAlign.RIGHT),icon:P.jsx(ko,{})},{label:i.t("toolbar.alignJustify"),value:String(s.HorizontalAlign.JUSTIFIED),icon:P.jsx(Ro,{})}],[]),e=zl(),[n,o]=Gl(e,t[0].value),[a,r]=jl(e),[c,l]=Xl(e),[A,d]=Kl(e),[u,m]=Yl(e),[h,g]=ql(e),[p,f]=Jl(e),{lineSpacing:[S,E],spacingRule:[C,b]}=Zl(e),R=U.useMemo(()=>C===s.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[C,S]);return P.jsxs("div",{children:[P.jsx("div",{className:"univer-t-4 univer-text-[13px] univer-font-medium",children:i.t("doc.paragraphSetting.alignment")}),P.jsx("div",{className:`
|
|
64
62
|
univer-mt-4 univer-box-border univer-flex univer-w-full univer-items-center univer-justify-between
|
|
65
63
|
univer-gap-1 univer-rounded-md univer-border univer-border-solid univer-border-gray-200 univer-p-1
|
|
66
64
|
`,children:t.map(I=>P.jsx(ee.Tooltip,{title:I.label,placement:"bottom",children:P.jsx("span",{className:ee.clsx(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-ui",
|
|
3
|
-
"version": "0.7.0-beta.
|
|
3
|
+
"version": "0.7.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer normal ui-plugin-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"rxjs": ">=7.0.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@univerjs/icons": "^0.3.
|
|
68
|
-
"@univerjs/core": "0.7.0-beta.
|
|
69
|
-
"@univerjs/
|
|
70
|
-
"@univerjs/
|
|
71
|
-
"@univerjs/engine-render": "0.7.0-beta.
|
|
72
|
-
"@univerjs/
|
|
73
|
-
"@univerjs/ui": "0.7.0-beta.
|
|
67
|
+
"@univerjs/icons": "^0.3.24",
|
|
68
|
+
"@univerjs/core": "0.7.0-beta.1",
|
|
69
|
+
"@univerjs/drawing": "0.7.0-beta.1",
|
|
70
|
+
"@univerjs/design": "0.7.0-beta.1",
|
|
71
|
+
"@univerjs/engine-render": "0.7.0-beta.1",
|
|
72
|
+
"@univerjs/docs": "0.7.0-beta.1",
|
|
73
|
+
"@univerjs/ui": "0.7.0-beta.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"jest-canvas-mock": "^2.5.2",
|
|
@@ -80,10 +80,10 @@
|
|
|
80
80
|
"rxjs": "^7.8.1",
|
|
81
81
|
"tailwindcss": "^3.4.17",
|
|
82
82
|
"typescript": "^5.8.3",
|
|
83
|
-
"vite": "^6.3.
|
|
84
|
-
"vitest": "^3.1.
|
|
85
|
-
"@univerjs-infra/shared": "0.7.0-beta.
|
|
86
|
-
"@univerjs/docs-drawing": "0.7.0-beta.
|
|
83
|
+
"vite": "^6.3.5",
|
|
84
|
+
"vitest": "^3.1.3",
|
|
85
|
+
"@univerjs-infra/shared": "0.7.0-beta.1",
|
|
86
|
+
"@univerjs/docs-drawing": "0.7.0-beta.1"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
89
|
"test": "vitest run",
|