@univerjs/docs-ui 0.5.2 → 0.5.3
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 +1 -1
- package/lib/es/index.js +12 -12
- package/lib/index.css +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +12 -36
package/lib/cjs/index.js
CHANGED
|
@@ -36,7 +36,7 @@ ${i.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
36
36
|
`)||(r+=`\r
|
|
37
37
|
`,e.push({startIndex:r.length-2}),n.push({startIndex:r.length-1}),t.dataStream=r,t.paragraphs=e,t.sectionBreaks=n);const s={html:""},a=x.parseDataStreamToTree(r).sectionList;for(const c of a)gt(c,o,s);return s.html}function gt(o,t,e){var n,r;switch(o.nodeType){case i.DataStreamTreeNodeType.SECTION_BREAK:{for(const s of o.children)gt(s,t,e);break}case i.DataStreamTreeNodeType.PARAGRAPH:{const{children:s,startIndex:a,endIndex:c}=o,l=(r=(n=t.body)==null?void 0:n.paragraphs.find(f=>f.startIndex===c))!=null?r:{},{paragraphStyle:A={}}=l,{spaceAbove:d,spaceBelow:u,lineSpacing:m}=A,g=[];if(d!=null&&(typeof d=="number"?g.push(`margin-top: ${d}px`):g.push(`margin-top: ${d.v}px`)),u!=null&&(typeof u=="number"?g.push(`margin-bottom: ${u}px`):g.push(`margin-bottom: ${u.v}px`)),m!=null&&g.push(`line-height: ${m}`),e.html+=`<p class="UniverNormal" ${g.length?`style="${g.join("; ")};"`:""}>`,s.length)for(const f of s)gt(f,t,e);e.html+=`${wc(t,a,c)}</p>`;break}case i.DataStreamTreeNodeType.TABLE:{const{children:s}=o;e.html+='<table class="UniverTable" style="width: 100%; border-collapse: collapse;"><tbody>';for(const a of s)gt(a,t,e);e.html+="</tbody></table>";break}case i.DataStreamTreeNodeType.TABLE_ROW:{const{children:s}=o;e.html+='<tr class="UniverTableRow">';for(const a of s)gt(a,t,e);e.html+="</tr>";break}case i.DataStreamTreeNodeType.TABLE_CELL:{const{children:s}=o;e.html+='<td class="UniverTableCell">';for(const a of s)gt(a,t,e);e.html+="</td>";break}default:throw new Error(`Unknown node type: ${o.nodeType}`)}}class Qc{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");let e="";for(const n of i.Tools.deepClone(t))e+=Lc(n);return e}}var Fc=Object.defineProperty,Hc=Object.getOwnPropertyDescriptor,kc=(o,t,e,n)=>{for(var r=n>1?void 0:n?Hc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fc(t,e,r),r},yt=(o,t)=>(e,n)=>t(e,n,o);ft.use(Li);ft.use(Pi);ft.use(wi);function Br(o,t,e){var s,a,c;const n=i.getBodySlice(o,t,e+2),r=i.DataStreamTreeTokenType.TABLE_START+i.DataStreamTreeTokenType.TABLE_ROW_START+i.DataStreamTreeTokenType.TABLE_CELL_START+n.dataStream+i.DataStreamTreeTokenType.TABLE_CELL_END+i.DataStreamTreeTokenType.TABLE_ROW_END+i.DataStreamTreeTokenType.TABLE_END;return n.dataStream=r,(s=n.textRuns)==null||s.forEach(l=>{const{st:A,ed:d}=l;l.st=A+3,l.ed=d+3}),(a=n.tables)==null||a.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 Ct=i.createIdentifier("doc.clipboard-service");let Ao=class extends i.Disposable{constructor(t,e,n,r,s){super();R(this,"_clipboardHooks",[]);R(this,"_htmlToUDM",new ft);R(this,"_umdToHtml",new Qc);this._univerInstanceService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=r,this._docSelectionManagerService=s}async copy(t=i.SliceBodyType.copy){var s;const{newSnapshotList:e=[],needCache:n=!1,snapshot:r}=(s=this._getDocumentBodyInRanges(t))!=null?s:{};if(e.length===0||r==null)return!1;try{const a=this._docSelectionManagerService.getActiveTextRange(),c=!!(a!=null&&a.segmentId);this._setClipboardData(e,!c&&n)}catch(a){return this._logService.error("[DocClipboardService] copy failed",a),!1}return!0}async cut(){return this._cut()}async paste(t){const e=await this._genDocDataFromClipboardItems(t);return this._paste(e)}async legacyPaste(t){let{html:e,text:n,files:r}=t;const s=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),a=(s==null?void 0:s.getUnitId())||"";!e&&!n&&r.length&&(e=await this._createImagePasteHtml(r));const c=this._genDocDataFromHtmlAndText(e,n,a);if(a===i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)if(n){const l=i.BuildTextUtils.transform.fromPlainText(n);return this._paste({body:l})}else c.body.textRuns=[];return this._paste(c)}async _cut(){var a,c,l;const{segmentId:t,endOffset:e,style:n}=(a=this._docSelectionManagerService.getActiveTextRange())!=null?a:{},r=(c=this._docSelectionManagerService.getTextRanges())!=null?c:[],s=(l=this._docSelectionManagerService.getRectRanges())!=null?l:[];if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),r.length===0&&s.length===0)return!1;this.copy(i.SliceBodyType.cut);try{let A=0;if(s.length>0)A=Mn(r,s);else if(e!=null){A=e;for(const u of r){const{startOffset:m,endOffset:g}=u;m==null||g==null||g<=e&&(A-=g-m)}}const d=[{startOffset:A,endOffset:A,style:n}];return this._commandService.executeCommand(et.id,{segmentId:t,textRanges:d})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var d,u;const{body:e}=t;if(e==null)return!1;let n=i.normalizeBody(e);if(!((d=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC))==null?void 0:d.getUnitId()))return!1;this._clipboardHooks.forEach(m=>{m.onBeforePaste&&(n=m.onBeforePaste(n))}),n.customRanges=(u=n.customRanges)==null?void 0:u.map(i.BuildTextUtils.customRange.copyCustomRange);const s=this._docSelectionManagerService.getActiveTextRange(),{segmentId:a,endOffset:c,style:l}=s||{},A=this._docSelectionManagerService.getTextRanges();if(a==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),c==null||A==null)return!1;try{let m=c;for(const f of A){const{startOffset:h,endOffset:p}=f;h==null||p==null||p<=c&&(m+=n.dataStream.length-(p-h))}const g=[{startOffset:m,endOffset:m,style:l}];return this._commandService.executeCommand(Fo.id,{doc:{...t,body:n},segmentId:a,textRanges:g})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t,e=!0){var a,c,l,A;const n=Dc(),r=(t.length>1?t.map(d=>{var u;return((u=d.body)==null?void 0:u.dataStream)||""}).join(`
|
|
38
38
|
`):((a=t[0].body)==null?void 0:a.dataStream)||"").replaceAll(i.DataStreamTreeTokenType.TABLE_START,"").replaceAll(i.DataStreamTreeTokenType.TABLE_END,"").replaceAll(i.DataStreamTreeTokenType.TABLE_ROW_START,"").replaceAll(i.DataStreamTreeTokenType.TABLE_ROW_END,"").replaceAll(i.DataStreamTreeTokenType.TABLE_CELL_START,"").replaceAll(i.DataStreamTreeTokenType.TABLE_CELL_END,"").replaceAll(`\r
|
|
39
|
-
`," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,g)=>`${g} 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:g}=m,f=(A=d.drawings)==null?void 0:A[g];if(f){const h=i.Tools.generateRandomId(6);m.blockId=h,u.drawings[h]={...i.Tools.deepClone(f),drawingId:h}}}}Kn.set(n,u)}return this._clipboardInterfaceService.write(r,s)}addClipboardHook(t){return this._clipboardHooks.push(t),i.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t){var A;const e=this._univerInstanceService.getCurrentUniverDocInstance(),n=this._docSelectionManagerService.getDocRanges(),r=[];let s=!0;if(e==null||n.length===0)return;const a=n[0].segmentId,c=(A=e==null?void 0:e.getSelfOrHeaderFooterModel(a))==null?void 0:A.getBody(),l=e.getSnapshot();if(c!=null){for(const d of n){const{startOffset:u,endOffset:m,collapsed:g,rangeType:f}=d;if(g||u==null||m==null)continue;if(f===i.DOC_RANGE_TYPE.RECT){s=!1;const{spanEntireRow:S}=d;let I;I=Br(c,u,m),r.push(I);continue}const h={startOffset:u,endOffset:m,collapsed:g},p=e.getSelfOrHeaderFooterModel(a).sliceBody(h.startOffset,h.endOffset,t);p!=null&&r.push(p)}return{newSnapshotList:r.map(d=>({...l,body:d})),needCache:s,snapshot:l}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const r=[];for(const s of t)for(const a of s.types)switch(a){case b.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(a).then(c=>c&&c.text());break}case b.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(a).then(c=>c&&c.text());break}case b.FILE__BMP_CLIPBOARD_MIME_TYPE:case b.FILE__JPEG_CLIPBOARD_MIME_TYPE:case b.FILE__WEBP_CLIPBOARD_MIME_TYPE:case b.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await s.getType(a),l=new File([c],`pasted_image.${a.split("/")[1]}`,{type:a});r.push(l);break}}return!e&&!n&&r.length&&(e=await this._createImagePasteHtml(r)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:i.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const r=_c(t);if(r){const a=Kn.get(r);if(a)return a}if(!n){const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n=(a==null?void 0:a.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return r&&Kn.set(r,s),s}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:vo.ImageSourceType.BASE64})},d.readAsDataURL(A)})},r=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const g=Math.min(u,d.naturalWidth),f=d.naturalHeight/d.naturalWidth;m({width:g,height:g*f})}})},s=(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 s(A);if(!u)return Promise.resolve();const{width:m=100,height:g=100}=await r(A),f=`paste_image_id_${d}`,h=e.body,p=e.drawings;h.dataStream+="\b",(S=h.customBlocks)==null||S.push({startIndex:d,blockId:f}),p[f]={drawingId:f,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:i.PositionedObjectLayoutType.INLINE,drawingType:i.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:g,angle:0},docTransform:{angle:0,size:{width:m,height:g},positionH:{relativeFrom:i.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:i.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};Ao=kc([yt(0,i.IUniverInstanceService),yt(1,i.ILogService),yt(2,i.ICommandService),yt(3,b.IClipboardInterfaceService),yt(4,i.Inject(D.DocSelectionManagerService))],Ao);function Bn(o){return o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED)}const jo=999,Nt={id:b.CopyCommand.id,name:"doc.command.copy",type:i.CommandType.COMMAND,multi:!0,priority:jo,preconditions:Bn,handler:async o=>o.get(Ct).copy()},Dn={id:b.CutCommand.id,name:"doc.command.cut",type:i.CommandType.COMMAND,multi:!0,priority:jo,preconditions:Bn,handler:async o=>o.get(Ct).cut()},_n={id:b.PasteCommand.id,name:"doc.command.paste",type:i.CommandType.COMMAND,multi:!0,priority:jo,preconditions:Bn,handler:async o=>{const t=o.get(Ct),n=await o.get(b.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}},Nn={id:"doc.command.switch-mode",type:i.CommandType.COMMAND,handler:async o=>{var I,E,C,y,v;const t=o.get(i.ICommandService),e=o.get(x.IRenderManagerService),n=o.get(D.DocSelectionManagerService),s=o.get(i.IUniverInstanceService).getCurrentUniverDocInstance();if(s==null)return!1;const a=s.getUnitId(),c=(I=e.getRenderById(a))==null?void 0:I.with(D.DocSkeletonManagerService).getSkeleton(),l=(E=e.getRenderById(a))==null?void 0:E.with(exports.DocSelectionRenderService);if(c==null||l==null)return!1;const A=l==null?void 0:l.getSegment(),d=l==null?void 0:l.getSegmentPage(),u=s.getSnapshot().documentStyle.documentFlavor,m=n.getDocRanges(),g={id:D.RichTextEditingMutation.id,params:{unitId:a,actions:[],textRanges:u===i.DocumentFlavor.TRADITIONAL&&A?[]:m}},f=i.JSONX.getInstance(),h=[];let p;if(u===void 0?p=f.insertOp(["documentStyle","documentFlavor"],i.DocumentFlavor.MODERN):u===i.DocumentFlavor.MODERN?p=f.replaceOp(["documentStyle","documentFlavor"],u,i.DocumentFlavor.TRADITIONAL):p=f.replaceOp(["documentStyle","documentFlavor"],u,i.DocumentFlavor.MODERN),p)h.push(p);else return!1;if(u!==i.DocumentFlavor.MODERN){const T=s.getSnapshot(),{drawings:B={},body:M}=T,U=(C=M==null?void 0:M.customBlocks)!=null?C:[];for(const O in B){const P=B[O],w=U.find(G=>G.blockId===O);if(w==null)continue;const Q=P.docTransform.positionV,{relativeFrom:F,posOffset:H}=Q;if(F===i.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:Y}=w,z=c.findNodeByCharIndex(Y,A,d),j=(y=z==null?void 0:z.parent)==null?void 0:y.parent,k=j==null?void 0:j.parent,X=k==null?void 0:k.lines.find(G=>G.paragraphIndex===(j==null?void 0:j.paragraphIndex)&&G.paragraphStart),$=(v=k==null?void 0:k.parent)==null?void 0:v.parent;if(z==null||j==null||X==null||k==null||$==null)continue;let q=0;F===i.ObjectRelativeFromV.LINE?q-=j.top:F===i.ObjectRelativeFromV.PAGE&&(q+=$.marginTop),q+=X.top;const V={...Q,relativeFrom:i.ObjectRelativeFromV.PARAGRAPH,posOffset:(H!=null?H:0)-q},W=f.replaceOp(["drawings",O,"docTransform","positionV"],Q,V);W&&h.push(W)}}return g.params.actions=h.reduce((T,B)=>i.JSONX.compose(T,B),null),!!t.syncExecuteCommand(g.id,g.params)}},Pn={id:"doc.table.delete-rows",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=jt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=pe(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,f=i.JSONX.getInstance(),h=xi(a,u);if(h==null)return!1;const{offset:p,rowIndexes:S,len:I,tableId:E,cursor:C,selectWholeTable:y}=h;if(y)return n.executeCommand(Tt.id);const v=[],T=[{startOffset:C,endOffset:C,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:T}};p>0&&g.push({t:i.TextXActionType.RETAIN,len:p}),g.push({t:i.TextXActionType.DELETE,len:I});const M=ee(l,c);v.push(f.editOp(g.serialize(),M));for(const O of S.reverse()){const P=f.removeOp(["tableSource",E,"tableRows",O]);v.push(P)}return B.params.actions=v.reduce((O,P)=>i.JSONX.compose(O,P),null),!!n.syncExecuteCommand(B.id,B.params)}},Un={id:"doc.table.delete-columns",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=jt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=pe(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,f=i.JSONX.getInstance(),h=Cc(a,u);if(h==null)return!1;const{offsets:p,columnIndexes:S,tableId:I,cursor:E,rowCount:C,selectWholeTable:y}=h;if(y)return n.executeCommand(Tt.id);const v=[],T=[{startOffset:E,endOffset:E,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:T}};for(const O of p){const{retain:P,delete:w}=O;P>0&&g.push({t:i.TextXActionType.RETAIN,len:P}),g.push({t:i.TextXActionType.DELETE,len:w})}const M=ee(l,c);v.push(f.editOp(g.serialize(),M)),S.reverse();for(let O=0;O<C;O++)for(const P of S){const w=f.removeOp(["tableSource",I,"tableRows",O,"tableCells",P]);v.push(w)}for(const O of S){const P=f.removeOp(["tableSource",I,"tableColumns",O]);v.push(P)}return B.params.actions=v.reduce((O,P)=>i.JSONX.compose(O,P),null),!!n.syncExecuteCommand(B.id,B.params)}},Tt={id:"doc.table.delete-table",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=jt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=pe(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,f=i.JSONX.getInstance(),h=Mi(a,u);if(h==null)return!1;const{offset:p,len:S,tableId:I,cursor:E}=h,C=[],y=[{startOffset:E,endOffset:E,collapsed:!0}],v={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:y}};p>0&&g.push({t:i.TextXActionType.RETAIN,len:p}),g.push({t:i.TextXActionType.DELETE,len:S});const T=ee(l,c);C.push(f.editOp(g.serialize(),T));const B=f.removeOp(["tableSource",I]);return C.push(B),v.params.actions=C.reduce((U,O)=>i.JSONX.compose(U,O),null),!!n.syncExecuteCommand(v.id,v.params)}},Wo="doc.command.table-insert-row",zo="doc.command.table-insert-column",Vc="doc.command.table-insert-row-above",jc="doc.command.table-insert-row-bellow",Wc="doc.command.table-insert-column-left",zc="doc.command.table-insert-column-right",wn={id:Vc,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(Wo,{position:Cn.ABOVE})},Ln={id:jc,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(Wo,{position:Cn.BELLOW})},Qn={id:Wc,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(zo,{position:Lo.LEFT})},Fn={id:zc,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(zo,{position:Lo.RIGHT})},Go={id:Wo,type:i.CommandType.COMMAND,handler:async(o,t)=>{const{position:e}=t,n=o.get(D.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=n.getRectRanges(),c=n.getActiveTextRange(),l=jt(c,a);if(l==null)return!1;const{segmentId:A}=l,d=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=pe(o,d.getUnitId());if(m==null)return!1;const g=m.getViewModel(),f=d==null?void 0:d.getUnitId(),h=new i.TextX,p=i.JSONX.getInstance(),S=Ic(l,e,g);if(S==null)return!1;const{offset:I,colCount:E,tableId:C,insertRowIndex:y}=S,v=[],T=I+2,B=[{startOffset:T,endOffset:T,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:f,actions:[],textRanges:B}};I>0&&h.push({t:i.TextXActionType.RETAIN,len:I});const U=pc(E);h.push({t:i.TextXActionType.INSERT,body:U,len:U.dataStream.length});const O=ee(d,A);v.push(p.editOp(h.serialize(),O));const P=bn(E),w=p.insertOp(["tableSource",C,"tableRows",y],P);return v.push(w),M.params.actions=v.reduce((F,H)=>i.JSONX.compose(F,H),null),!!s.syncExecuteCommand(M.id,M.params)}},Qi={id:zo,type:i.CommandType.COMMAND,handler:async(o,t)=>{var $,q,V;const{position:e}=t,n=o.get(D.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=n.getRectRanges(),c=n.getActiveTextRange(),l=jt(c,a);if(l==null)return!1;const{segmentId:A}=l,d=r.getCurrentUniverDocInstance(),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=pe(o,d.getUnitId());if(m==null)return!1;const g=m.getViewModel(),f=d==null?void 0:d.getUnitId(),h=new i.TextX,p=i.JSONX.getInstance(),S=Ec(l,e,g);if(S==null)return!1;const{offsets:I,columnIndex:E,tableId:C,rowCount:y}=S,v=[],T=I[0]+1,B=[{startOffset:T,endOffset:T,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:f,actions:[],textRanges:B}};for(const W of I){h.push({t:i.TextXActionType.RETAIN,len:W});const G=Sc();h.push({t:i.TextXActionType.INSERT,body:G,len:G.dataStream.length})}const U=ee(d,A);v.push(p.editOp(h.serialize(),U));for(let W=0;W<y;W++){const G=Tn(),ne=p.insertOp(["tableSource",C,"tableRows",W,"tableCells",E],G);v.push(ne)}const O=d.getSnapshot(),P=O.documentStyle,{marginLeft:w=0,marginRight:Q=0}=P,F=((q=($=P.pageSize)==null?void 0:$.width)!=null?q:800)-w-Q,H=(V=O==null?void 0:O.tableSource)==null?void 0:V[C].tableColumns,{newColWidth:Y,widths:z}=vc(F,H,E);for(let W=0;W<z.length;W++){const G=p.replaceOp(["tableSource",C,"tableColumns",W,"size","width","v"],H[W].size.width.v,z[W]);v.push(G)}const j=Rn(Y),k=p.insertOp(["tableSource",C,"tableColumns",E],j);return v.push(k),M.params.actions=v.reduce((W,G)=>i.JSONX.compose(W,G),null),!!s.syncExecuteCommand(M.id,M.params)}},Fi="COMPONENT_DOC_CREATE_TABLE_CONFIRM";function Yo(o,t){const e=[];for(let n=0,r=o.length;n<r;n++)o[n]===i.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=i.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=i.Tools.deepClone(t.paragraphStyle));return e}const Xo={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:async o=>{var v,T,B;const t=o.get(D.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=o.get(Pe),s=t.getActiveTextRange(),a=t.getRectRanges();if(s==null)return!1;if(a&&a.length){const{startOffset:M}=s;return t.replaceDocRanges([{startOffset:M,endOffset:M}]),!0}const{segmentId:c}=s,l=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c!=null?c:"").getBody();if(l==null||A==null)return!1;const d=l.getUnitId(),{startOffset:u,endOffset:m}=s,f=((v=A.paragraphs)!=null?v:[]).find(M=>M.startIndex>=u);if(!f)return!1;const h=f.startIndex,p=r.getDefaultStyle(),S=r.getStyleCache(),I=pn((T=A.textRuns)!=null?T:[],m,p,S),E={dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Yo(i.DataStreamTreeTokenType.PARAGRAPH,f),textRuns:[{st:0,ed:1,ts:{...I.ts}}]},C={startOffset:u,endOffset:m,collapsed:u===m},y=await n.executeCommand(yn.id,{unitId:d,body:E,range:C,segmentId:c});if(((B=f.bullet)==null?void 0:B.listType)===i.PresetListType.CHECK_LIST_CHECKED){const M={index:h+1-(m-u),segmentId:c,textRanges:[{startOffset:u+1,endOffset:u+1}]};return!!await n.executeCommand(En.id,M)&&y}return y}},Gc="doc.command.create-table",Ko={id:Gc,type:i.CommandType.COMMAND,handler:async(o,t)=>{var V,W,G,ne,se,ue;const{rowCount:e,colCount:n}=t,r=o.get(D.DocSelectionManagerService),s=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),c=o.get(Pe),l=r.getActiveTextRange();if(l==null)return!1;const{segmentId:A,segmentPage:d}=l,u=s.getCurrentUniverDocInstance(),m=u==null?void 0:u.getSelfOrHeaderFooterModel(A).getBody();if(u==null||m==null)return!1;const g=u.getUnitId(),f=pe(o,g),h=f==null?void 0:f.getSkeleton();if(h==null)return!1;const{startOffset:p}=l,I=((V=m.paragraphs)!=null?V:[]).find(ae=>ae.startIndex>=p),E=h.findNodeByCharIndex(p,A,d);if(E==null)return!1;const C=new i.TextX,y=i.JSONX.getInstance(),v=[],T=p+4,B=[{startOffset:T,endOffset:T,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:B}};p>0&&C.push({t:i.TextXActionType.RETAIN,len:p}),C.push({t:i.TextXActionType.INSERT,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Yo(i.DataStreamTreeTokenType.PARAGRAPH,I)},len:1});const U=c.getDefaultStyle(),O=c.getStyleCache(),P=pn((W=m.textRuns)!=null?W:[],p,U,O),{dataStream:w,paragraphs:Q,sectionBreaks:F}=fc(e,n),H=(ue=(se=(ne=(G=E.parent)==null?void 0:G.parent)==null?void 0:ne.parent)==null?void 0:se.parent)==null?void 0:ue.parent;if(H==null)return!1;const{pageWidth:Y,marginLeft:z,marginRight:j}=H,k=Qo(e,n,Y-z-j);C.push({t:i.TextXActionType.INSERT,body:{dataStream:w,paragraphs:Q,sectionBreaks:F,textRuns:[{...P,st:0,ed:w.length}],tables:[{startIndex:0,endIndex:w.length,tableId:k.tableId}]},len:w.length});const X=ee(u,A);v.push(y.editOp(C.serialize(),X));const $=y.insertOp(["tableSource",k.tableId],k);return v.push($),M.params.actions=v.reduce((ae,Se)=>i.JSONX.compose(ae,Se),null),!!a.syncExecuteCommand(M.id,M.params)}},Jn="doc.component.create-table-confirm",Hn={id:"doc.operation.create-table",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(i.LocaleService),e=o.get(b.IConfirmService),n=o.get(i.ICommandService),r={rowCount:3,colCount:5},s=(a,c)=>{r.rowCount=a,r.colCount=c};return await e.open({id:Jn,children:{label:{name:Fi,props:{handleRowColChange:s,tableCreateParams:r}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(Ko.id,r),e.close(Jn)},onClose:()=>{e.close(Jn)}}),!0}},Oe={id:"doc-paragraph-setting.command",type:i.CommandType.COMMAND,handler:async(o,t)=>{var S,I,E;const e=o.get(D.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),a=e.getDocRanges();if(!s||a.length===0||!t)return!1;const c=a[0].segmentId,l=s.getUnitId(),A=(I=(S=s.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:S.paragraphs)!=null?I:[],d=(E=vt(a,A))!=null?E:[],u={id:D.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:a}},m=new i.MemoryCursor;m.reset();const g=new i.TextX,f=i.JSONX.getInstance();for(const C of d){const{startIndex:y}=C;g.push({t:i.TextXActionType.RETAIN,len:y-m.cursor});const v={...C.paragraphStyle,...t.paragraph};g.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...C,paragraphStyle:v,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),m.moveCursorTo(y+1)}const h=ee(s,c);return u.params.actions=f.editOp(g.serialize(),h),!!r.syncExecuteCommand(u.id,u.params)}},Yc=()=>{const o=i.useDependency(D.DocSelectionManagerService),t=i.useDependency(pt),e=L.useMemo(()=>o.getDocRanges(),[]);return L.useEffect(()=>{e.length||t.closePanel()},[e]),e},Xc=()=>{var a,c,l;const t=i.useDependency(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),e=Yc();if(!t||e.length===0)return[];const n=e[0].segmentId,r=(c=(a=t.getSelfOrHeaderFooterModel(n).getBody())==null?void 0:a.paragraphs)!=null?c:[];return(l=vt(e,r))!=null?l:[]},Kc=(o,t)=>{const e=i.useDependency(i.ICommandService),[n,r]=L.useState(()=>{var c,l;const a=o[0];return a?String((l=(c=a.paragraphStyle)==null?void 0:c.horizontalAlign)!=null?l:t):t});return[n,a=>(r(a),e.executeCommand(Oe.id,{paragraph:{horizontalAlign:Number(a)}}))]},qc=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentStart,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{indentStart:{v:s}}}))]},Jc=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentEnd,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{indentEnd:{v:s}}}))]},Zc=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentFirstLine,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{indentFirstLine:{v:s}}}))]},$c=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.hanging,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{hanging:{v:s}}}))]},el=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.spaceAbove,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{spaceAbove:{v:s}}}))]},tl=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.spaceBelow,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{spaceBelow:{v:s}}}))]},nl=o=>{const t=i.useDependency(i.ICommandService),e=i.useDependency(x.IRenderManagerService),n=i.useDependency(i.IUniverInstanceService),r=L.useMemo(()=>{var f;const g=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(g)return(f=e.getRenderById(g==null?void 0:g.getUnitId()))==null?void 0:f.with(D.DocSkeletonManagerService).getSkeleton()},[]),s=L.useMemo(()=>new N.BehaviorSubject({}),[]),[a,c]=L.useState(()=>{var f,h;const g=o[0];return g&&(h=(f=g.paragraphStyle)==null?void 0:f.lineSpacing)!=null?h:1}),l=L.useRef(a),[A,d]=L.useState(()=>{var f,h;const g=o[0];return g&&(h=(f=g.paragraphStyle)==null?void 0:f.spacingRule)!=null?h:i.SpacingRule.AUTO}),u=async g=>{c(g),s.next({lineSpacing:g,spacingRule:A})},m=async g=>{if(g!==A){let f=l.current;if(g===i.SpacingRule.AT_LEAST){const h=r==null?void 0:r.findNodeByCharIndex(o[0].startIndex),p=h==null?void 0:h.parent,S=p==null?void 0:p.parent;(S==null?void 0:S.contentHeight)!==void 0&&(f=Math.max(S.contentHeight,f))}else f>5&&(f=2);l.current=a,u(f),d(g),s.next({spacingRule:g})}};return L.useEffect(()=>{const g=s.pipe(Bt.filter(f=>!!Object.keys(f).length),Bt.bufferTime(16),Bt.filter(f=>!!f.length),Bt.map(f=>f.reduce((h,p)=>(Object.keys(p).forEach(S=>{h[S]=p[S]}),h),{}))).subscribe(f=>t.executeCommand(Oe.id,{paragraph:{...f}}));return()=>g.unsubscribe()},[]),{lineSpacing:[a,u],spacingRule:[A,m]}},ol="univer-paragraph-setting-icon-list",rl="univer-paragraph-setting-icon-list-item",il="univer-paragraph-setting-icon-list-active",sl="univer-paragraph-setting-title",al="univer-paragraph-setting-label",cl="univer-paragraph-setting-mt-base",ll="univer-paragraph-setting-flex-col",Al="univer-paragraph-setting-space-line",J={paragraphSettingIconList:ol,paragraphSettingIconListItem:rl,paragraphSettingIconListActive:il,paragraphSettingTitle:sl,paragraphSettingLabel:al,paragraphSettingMtBase:cl,paragraphSettingFlexCol:ll,paragraphSettingSpaceLine:Al},ze=o=>{const{value:t,onChange:e,className:n="",min:r=0,max:s=100,step:a=1}=o,c=Zi.useRef(null);return _.jsx(ie.InputNumber,{step:a,ref:c,min:r,max:s,value:t,onChange:l=>{e(l!=null?l:0).finally(()=>{setTimeout(()=>{var A;(A=c.current)==null||A.focus()},30)})},className:n})};function dl(){const o=i.useDependency(i.LocaleService),t=L.useMemo(()=>[{label:o.t("toolbar.alignLeft"),value:String(i.HorizontalAlign.LEFT),icon:_.jsx(di,{})},{label:o.t("toolbar.alignCenter"),value:String(i.HorizontalAlign.CENTER),icon:_.jsx(li,{})},{label:o.t("toolbar.alignRight"),value:String(i.HorizontalAlign.RIGHT),icon:_.jsx(ui,{})},{label:o.t("toolbar.alignJustify"),value:String(i.HorizontalAlign.JUSTIFIED),icon:_.jsx(si,{})}],[]),e=Xc(),[n,r]=Kc(e,t[0].value),[s,a]=qc(e),[c,l]=Jc(e),[A,d]=Zc(e),[u,m]=$c(e),[g,f]=el(e),[h,p]=tl(e),{lineSpacing:[S,I],spacingRule:[E,C]}=nl(e),y=L.useMemo(()=>E===i.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[E,S]);return _.jsxs("div",{className:J.paragraphSetting,children:[_.jsx("div",{className:J.paragraphSettingTitle,children:o.t("doc.paragraphSetting.alignment")}),_.jsx("div",{className:`
|
|
39
|
+
`," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,g)=>`${g} 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:g}=m,f=(A=d.drawings)==null?void 0:A[g];if(f){const h=i.Tools.generateRandomId(6);m.blockId=h,u.drawings[h]={...i.Tools.deepClone(f),drawingId:h}}}}Kn.set(n,u)}return this._clipboardInterfaceService.write(r,s)}addClipboardHook(t){return this._clipboardHooks.push(t),i.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t){var A;const e=this._univerInstanceService.getCurrentUniverDocInstance(),n=this._docSelectionManagerService.getDocRanges(),r=[];let s=!0;if(e==null||n.length===0)return;const a=n[0].segmentId,c=(A=e==null?void 0:e.getSelfOrHeaderFooterModel(a))==null?void 0:A.getBody(),l=e.getSnapshot();if(c!=null){for(const d of n){const{startOffset:u,endOffset:m,collapsed:g,rangeType:f}=d;if(g||u==null||m==null)continue;if(f===i.DOC_RANGE_TYPE.RECT){s=!1;const{spanEntireRow:S}=d;let I;I=Br(c,u,m),r.push(I);continue}const h={startOffset:u,endOffset:m,collapsed:g},p=e.getSelfOrHeaderFooterModel(a).sliceBody(h.startOffset,h.endOffset,t);p!=null&&r.push(p)}return{newSnapshotList:r.map(d=>({...l,body:d})),needCache:s,snapshot:l}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const r=[];for(const s of t)for(const a of s.types)switch(a){case b.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(a).then(c=>c&&c.text());break}case b.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(a).then(c=>c&&c.text());break}case b.FILE__BMP_CLIPBOARD_MIME_TYPE:case b.FILE__JPEG_CLIPBOARD_MIME_TYPE:case b.FILE__WEBP_CLIPBOARD_MIME_TYPE:case b.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await s.getType(a),l=new File([c],`pasted_image.${a.split("/")[1]}`,{type:a});r.push(l);break}}return!e&&!n&&r.length&&(e=await this._createImagePasteHtml(r)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:i.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const r=_c(t);if(r){const a=Kn.get(r);if(a)return a}if(!n){const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n=(a==null?void 0:a.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return r&&Kn.set(r,s),s}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:vo.ImageSourceType.BASE64})},d.readAsDataURL(A)})},r=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const g=Math.min(u,d.naturalWidth),f=d.naturalHeight/d.naturalWidth;m({width:g,height:g*f})}})},s=(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 s(A);if(!u)return Promise.resolve();const{width:m=100,height:g=100}=await r(A),f=`paste_image_id_${d}`,h=e.body,p=e.drawings;h.dataStream+="\b",(S=h.customBlocks)==null||S.push({startIndex:d,blockId:f}),p[f]={drawingId:f,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:i.PositionedObjectLayoutType.INLINE,drawingType:i.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:g,angle:0},docTransform:{angle:0,size:{width:m,height:g},positionH:{relativeFrom:i.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:i.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};Ao=kc([yt(0,i.IUniverInstanceService),yt(1,i.ILogService),yt(2,i.ICommandService),yt(3,b.IClipboardInterfaceService),yt(4,i.Inject(D.DocSelectionManagerService))],Ao);function Bn(o){return o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED)}const jo=999,Nt={id:b.CopyCommand.id,name:"doc.command.copy",type:i.CommandType.COMMAND,multi:!0,priority:jo,preconditions:Bn,handler:async o=>o.get(Ct).copy()},Dn={id:b.CutCommand.id,name:"doc.command.cut",type:i.CommandType.COMMAND,multi:!0,priority:jo,preconditions:Bn,handler:async o=>o.get(Ct).cut()},_n={id:b.PasteCommand.id,name:"doc.command.paste",type:i.CommandType.COMMAND,multi:!0,priority:jo,preconditions:Bn,handler:async o=>{const t=o.get(Ct),n=await o.get(b.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}},Nn={id:"doc.command.switch-mode",type:i.CommandType.COMMAND,handler:async o=>{var I,E,C,y,v;const t=o.get(i.ICommandService),e=o.get(x.IRenderManagerService),n=o.get(D.DocSelectionManagerService),s=o.get(i.IUniverInstanceService).getCurrentUniverDocInstance();if(s==null)return!1;const a=s.getUnitId(),c=(I=e.getRenderById(a))==null?void 0:I.with(D.DocSkeletonManagerService).getSkeleton(),l=(E=e.getRenderById(a))==null?void 0:E.with(exports.DocSelectionRenderService);if(c==null||l==null)return!1;const A=l==null?void 0:l.getSegment(),d=l==null?void 0:l.getSegmentPage(),u=s.getSnapshot().documentStyle.documentFlavor,m=n.getDocRanges(),g={id:D.RichTextEditingMutation.id,params:{unitId:a,actions:[],textRanges:u===i.DocumentFlavor.TRADITIONAL&&A?[]:m}},f=i.JSONX.getInstance(),h=[];let p;if(u===void 0?p=f.insertOp(["documentStyle","documentFlavor"],i.DocumentFlavor.MODERN):u===i.DocumentFlavor.MODERN?p=f.replaceOp(["documentStyle","documentFlavor"],u,i.DocumentFlavor.TRADITIONAL):p=f.replaceOp(["documentStyle","documentFlavor"],u,i.DocumentFlavor.MODERN),p)h.push(p);else return!1;if(u!==i.DocumentFlavor.MODERN){const T=s.getSnapshot(),{drawings:B={},body:M}=T,U=(C=M==null?void 0:M.customBlocks)!=null?C:[];for(const O in B){const P=B[O],w=U.find(G=>G.blockId===O);if(w==null)continue;const Q=P.docTransform.positionV,{relativeFrom:F,posOffset:H}=Q;if(F===i.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:Y}=w,z=c.findNodeByCharIndex(Y,A,d),j=(y=z==null?void 0:z.parent)==null?void 0:y.parent,k=j==null?void 0:j.parent,X=k==null?void 0:k.lines.find(G=>G.paragraphIndex===(j==null?void 0:j.paragraphIndex)&&G.paragraphStart),$=(v=k==null?void 0:k.parent)==null?void 0:v.parent;if(z==null||j==null||X==null||k==null||$==null)continue;let q=0;F===i.ObjectRelativeFromV.LINE?q-=j.top:F===i.ObjectRelativeFromV.PAGE&&(q+=$.marginTop),q+=X.top;const V={...Q,relativeFrom:i.ObjectRelativeFromV.PARAGRAPH,posOffset:(H!=null?H:0)-q},W=f.replaceOp(["drawings",O,"docTransform","positionV"],Q,V);W&&h.push(W)}}return g.params.actions=h.reduce((T,B)=>i.JSONX.compose(T,B),null),!!t.syncExecuteCommand(g.id,g.params)}},Pn={id:"doc.table.delete-rows",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=jt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=pe(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,f=i.JSONX.getInstance(),h=xi(a,u);if(h==null)return!1;const{offset:p,rowIndexes:S,len:I,tableId:E,cursor:C,selectWholeTable:y}=h;if(y)return n.executeCommand(Tt.id);const v=[],T=[{startOffset:C,endOffset:C,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:T}};p>0&&g.push({t:i.TextXActionType.RETAIN,len:p}),g.push({t:i.TextXActionType.DELETE,len:I});const M=ee(l,c);v.push(f.editOp(g.serialize(),M));for(const O of S.reverse()){const P=f.removeOp(["tableSource",E,"tableRows",O]);v.push(P)}return B.params.actions=v.reduce((O,P)=>i.JSONX.compose(O,P),null),!!n.syncExecuteCommand(B.id,B.params)}},Un={id:"doc.table.delete-columns",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=jt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=pe(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,f=i.JSONX.getInstance(),h=Cc(a,u);if(h==null)return!1;const{offsets:p,columnIndexes:S,tableId:I,cursor:E,rowCount:C,selectWholeTable:y}=h;if(y)return n.executeCommand(Tt.id);const v=[],T=[{startOffset:E,endOffset:E,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:T}};for(const O of p){const{retain:P,delete:w}=O;P>0&&g.push({t:i.TextXActionType.RETAIN,len:P}),g.push({t:i.TextXActionType.DELETE,len:w})}const M=ee(l,c);v.push(f.editOp(g.serialize(),M)),S.reverse();for(let O=0;O<C;O++)for(const P of S){const w=f.removeOp(["tableSource",I,"tableRows",O,"tableCells",P]);v.push(w)}for(const O of S){const P=f.removeOp(["tableSource",I,"tableColumns",O]);v.push(P)}return B.params.actions=v.reduce((O,P)=>i.JSONX.compose(O,P),null),!!n.syncExecuteCommand(B.id,B.params)}},Tt={id:"doc.table.delete-table",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=jt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=pe(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,f=i.JSONX.getInstance(),h=Mi(a,u);if(h==null)return!1;const{offset:p,len:S,tableId:I,cursor:E}=h,C=[],y=[{startOffset:E,endOffset:E,collapsed:!0}],v={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:y}};p>0&&g.push({t:i.TextXActionType.RETAIN,len:p}),g.push({t:i.TextXActionType.DELETE,len:S});const T=ee(l,c);C.push(f.editOp(g.serialize(),T));const B=f.removeOp(["tableSource",I]);return C.push(B),v.params.actions=C.reduce((U,O)=>i.JSONX.compose(U,O),null),!!n.syncExecuteCommand(v.id,v.params)}},Wo="doc.command.table-insert-row",zo="doc.command.table-insert-column",Vc="doc.command.table-insert-row-above",jc="doc.command.table-insert-row-bellow",Wc="doc.command.table-insert-column-left",zc="doc.command.table-insert-column-right",wn={id:Vc,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(Wo,{position:Cn.ABOVE})},Ln={id:jc,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(Wo,{position:Cn.BELLOW})},Qn={id:Wc,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(zo,{position:Lo.LEFT})},Fn={id:zc,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(zo,{position:Lo.RIGHT})},Go={id:Wo,type:i.CommandType.COMMAND,handler:async(o,t)=>{const{position:e}=t,n=o.get(D.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=n.getRectRanges(),c=n.getActiveTextRange(),l=jt(c,a);if(l==null)return!1;const{segmentId:A}=l,d=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=pe(o,d.getUnitId());if(m==null)return!1;const g=m.getViewModel(),f=d==null?void 0:d.getUnitId(),h=new i.TextX,p=i.JSONX.getInstance(),S=Ic(l,e,g);if(S==null)return!1;const{offset:I,colCount:E,tableId:C,insertRowIndex:y}=S,v=[],T=I+2,B=[{startOffset:T,endOffset:T,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:f,actions:[],textRanges:B}};I>0&&h.push({t:i.TextXActionType.RETAIN,len:I});const U=pc(E);h.push({t:i.TextXActionType.INSERT,body:U,len:U.dataStream.length});const O=ee(d,A);v.push(p.editOp(h.serialize(),O));const P=bn(E),w=p.insertOp(["tableSource",C,"tableRows",y],P);return v.push(w),M.params.actions=v.reduce((F,H)=>i.JSONX.compose(F,H),null),!!s.syncExecuteCommand(M.id,M.params)}},Qi={id:zo,type:i.CommandType.COMMAND,handler:async(o,t)=>{var $,q,V;const{position:e}=t,n=o.get(D.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=n.getRectRanges(),c=n.getActiveTextRange(),l=jt(c,a);if(l==null)return!1;const{segmentId:A}=l,d=r.getCurrentUniverDocInstance(),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=pe(o,d.getUnitId());if(m==null)return!1;const g=m.getViewModel(),f=d==null?void 0:d.getUnitId(),h=new i.TextX,p=i.JSONX.getInstance(),S=Ec(l,e,g);if(S==null)return!1;const{offsets:I,columnIndex:E,tableId:C,rowCount:y}=S,v=[],T=I[0]+1,B=[{startOffset:T,endOffset:T,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:f,actions:[],textRanges:B}};for(const W of I){h.push({t:i.TextXActionType.RETAIN,len:W});const G=Sc();h.push({t:i.TextXActionType.INSERT,body:G,len:G.dataStream.length})}const U=ee(d,A);v.push(p.editOp(h.serialize(),U));for(let W=0;W<y;W++){const G=Tn(),ne=p.insertOp(["tableSource",C,"tableRows",W,"tableCells",E],G);v.push(ne)}const O=d.getSnapshot(),P=O.documentStyle,{marginLeft:w=0,marginRight:Q=0}=P,F=((q=($=P.pageSize)==null?void 0:$.width)!=null?q:800)-w-Q,H=(V=O==null?void 0:O.tableSource)==null?void 0:V[C].tableColumns,{newColWidth:Y,widths:z}=vc(F,H,E);for(let W=0;W<z.length;W++){const G=p.replaceOp(["tableSource",C,"tableColumns",W,"size","width","v"],H[W].size.width.v,z[W]);v.push(G)}const j=Rn(Y),k=p.insertOp(["tableSource",C,"tableColumns",E],j);return v.push(k),M.params.actions=v.reduce((W,G)=>i.JSONX.compose(W,G),null),!!s.syncExecuteCommand(M.id,M.params)}},Fi="COMPONENT_DOC_CREATE_TABLE_CONFIRM";function Yo(o,t){const e=[];for(let n=0,r=o.length;n<r;n++)o[n]===i.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=i.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=i.Tools.deepClone(t.paragraphStyle));return e}const Xo={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:async o=>{var v,T,B;const t=o.get(D.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=o.get(Pe),s=t.getActiveTextRange(),a=t.getRectRanges();if(s==null)return!1;if(a&&a.length){const{startOffset:M}=s;return t.replaceDocRanges([{startOffset:M,endOffset:M}]),!0}const{segmentId:c}=s,l=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c!=null?c:"").getBody();if(l==null||A==null)return!1;const d=l.getUnitId(),{startOffset:u,endOffset:m}=s,f=((v=A.paragraphs)!=null?v:[]).find(M=>M.startIndex>=u);if(!f)return!1;const h=f.startIndex,p=r.getDefaultStyle(),S=r.getStyleCache(),I=pn((T=A.textRuns)!=null?T:[],m,p,S),E={dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Yo(i.DataStreamTreeTokenType.PARAGRAPH,f),textRuns:[{st:0,ed:1,ts:{...I.ts}}]},C={startOffset:u,endOffset:m,collapsed:u===m},y=await n.executeCommand(yn.id,{unitId:d,body:E,range:C,segmentId:c});if(((B=f.bullet)==null?void 0:B.listType)===i.PresetListType.CHECK_LIST_CHECKED){const M={index:h+1-(m-u),segmentId:c,textRanges:[{startOffset:u+1,endOffset:u+1}]};return!!await n.executeCommand(En.id,M)&&y}return y}},Gc="doc.command.create-table",Ko={id:Gc,type:i.CommandType.COMMAND,handler:async(o,t)=>{var V,W,G,ne,se,ue;const{rowCount:e,colCount:n}=t,r=o.get(D.DocSelectionManagerService),s=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),c=o.get(Pe),l=r.getActiveTextRange();if(l==null)return!1;const{segmentId:A,segmentPage:d}=l,u=s.getCurrentUniverDocInstance(),m=u==null?void 0:u.getSelfOrHeaderFooterModel(A).getBody();if(u==null||m==null)return!1;const g=u.getUnitId(),f=pe(o,g),h=f==null?void 0:f.getSkeleton();if(h==null)return!1;const{startOffset:p}=l,I=((V=m.paragraphs)!=null?V:[]).find(ae=>ae.startIndex>=p),E=h.findNodeByCharIndex(p,A,d);if(E==null)return!1;const C=new i.TextX,y=i.JSONX.getInstance(),v=[],T=p+4,B=[{startOffset:T,endOffset:T,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:B}};p>0&&C.push({t:i.TextXActionType.RETAIN,len:p}),C.push({t:i.TextXActionType.INSERT,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Yo(i.DataStreamTreeTokenType.PARAGRAPH,I)},len:1});const U=c.getDefaultStyle(),O=c.getStyleCache(),P=pn((W=m.textRuns)!=null?W:[],p,U,O),{dataStream:w,paragraphs:Q,sectionBreaks:F}=fc(e,n),H=(ue=(se=(ne=(G=E.parent)==null?void 0:G.parent)==null?void 0:ne.parent)==null?void 0:se.parent)==null?void 0:ue.parent;if(H==null)return!1;const{pageWidth:Y,marginLeft:z,marginRight:j}=H,k=Qo(e,n,Y-z-j);C.push({t:i.TextXActionType.INSERT,body:{dataStream:w,paragraphs:Q,sectionBreaks:F,textRuns:[{...P,st:0,ed:w.length}],tables:[{startIndex:0,endIndex:w.length,tableId:k.tableId}]},len:w.length});const X=ee(u,A);v.push(y.editOp(C.serialize(),X));const $=y.insertOp(["tableSource",k.tableId],k);return v.push($),M.params.actions=v.reduce((ae,Se)=>i.JSONX.compose(ae,Se),null),!!a.syncExecuteCommand(M.id,M.params)}},Jn="doc.component.create-table-confirm",Hn={id:"doc.operation.create-table",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(i.LocaleService),e=o.get(b.IConfirmService),n=o.get(i.ICommandService),r={rowCount:3,colCount:5},s=(a,c)=>{r.rowCount=a,r.colCount=c};return await e.open({id:Jn,children:{label:{name:Fi,props:{handleRowColChange:s,tableCreateParams:r}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(Ko.id,r),e.close(Jn)},onClose:()=>{e.close(Jn)}}),!0}},Oe={id:"doc-paragraph-setting.command",type:i.CommandType.COMMAND,handler:async(o,t)=>{var S,I;const e=o.get(D.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),a=e.getDocRanges();if(!s||a.length===0||!t)return!1;const c=a[0].segmentId,l=s.getUnitId(),A=(I=(S=s.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:S.paragraphs)!=null?I:[],d=vt(a,A),u={id:D.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:a}},m=new i.MemoryCursor;m.reset();const g=new i.TextX,f=i.JSONX.getInstance();for(const E of d){const{startIndex:C}=E;g.push({t:i.TextXActionType.RETAIN,len:C-m.cursor});const y={...E.paragraphStyle,...t.paragraph};g.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...E,paragraphStyle:y,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),m.moveCursorTo(C+1)}const h=ee(s,c);return u.params.actions=f.editOp(g.serialize(),h),!!r.syncExecuteCommand(u.id,u.params)}},Yc=()=>{const o=i.useDependency(D.DocSelectionManagerService),t=i.useDependency(pt),e=L.useMemo(()=>o.getDocRanges(),[]);return L.useEffect(()=>{e.length||t.closePanel()},[e]),e},Xc=()=>{var a,c;const t=i.useDependency(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),e=Yc();if(!t||e.length===0)return[];const n=e[0].segmentId,r=(c=(a=t.getSelfOrHeaderFooterModel(n).getBody())==null?void 0:a.paragraphs)!=null?c:[];return vt(e,r)},Kc=(o,t)=>{const e=i.useDependency(i.ICommandService),[n,r]=L.useState(()=>{var c,l;const a=o[0];return a?String((l=(c=a.paragraphStyle)==null?void 0:c.horizontalAlign)!=null?l:t):t});return[n,a=>(r(a),e.executeCommand(Oe.id,{paragraph:{horizontalAlign:Number(a)}}))]},qc=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentStart,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{indentStart:{v:s}}}))]},Jc=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentEnd,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{indentEnd:{v:s}}}))]},Zc=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentFirstLine,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{indentFirstLine:{v:s}}}))]},$c=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.hanging,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{hanging:{v:s}}}))]},el=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.spaceAbove,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{spaceAbove:{v:s}}}))]},tl=o=>{const t=i.useDependency(i.ICommandService),[e,n]=L.useState(()=>{var a;const s=o[0];return s?x.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.spaceBelow,0):0});return[e,s=>(n(s),t.executeCommand(Oe.id,{paragraph:{spaceBelow:{v:s}}}))]},nl=o=>{const t=i.useDependency(i.ICommandService),e=i.useDependency(x.IRenderManagerService),n=i.useDependency(i.IUniverInstanceService),r=L.useMemo(()=>{var f;const g=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(g)return(f=e.getRenderById(g==null?void 0:g.getUnitId()))==null?void 0:f.with(D.DocSkeletonManagerService).getSkeleton()},[]),s=L.useMemo(()=>new N.BehaviorSubject({}),[]),[a,c]=L.useState(()=>{var f,h;const g=o[0];return g&&(h=(f=g.paragraphStyle)==null?void 0:f.lineSpacing)!=null?h:1}),l=L.useRef(a),[A,d]=L.useState(()=>{var f,h;const g=o[0];return g&&(h=(f=g.paragraphStyle)==null?void 0:f.spacingRule)!=null?h:i.SpacingRule.AUTO}),u=async g=>{c(g),s.next({lineSpacing:g,spacingRule:A})},m=async g=>{if(g!==A){let f=l.current;if(g===i.SpacingRule.AT_LEAST){const h=r==null?void 0:r.findNodeByCharIndex(o[0].startIndex),p=h==null?void 0:h.parent,S=p==null?void 0:p.parent;(S==null?void 0:S.contentHeight)!==void 0&&(f=Math.max(S.contentHeight,f))}else f>5&&(f=2);l.current=a,u(f),d(g),s.next({spacingRule:g})}};return L.useEffect(()=>{const g=s.pipe(Bt.filter(f=>!!Object.keys(f).length),Bt.bufferTime(16),Bt.filter(f=>!!f.length),Bt.map(f=>f.reduce((h,p)=>(Object.keys(p).forEach(S=>{h[S]=p[S]}),h),{}))).subscribe(f=>t.executeCommand(Oe.id,{paragraph:{...f}}));return()=>g.unsubscribe()},[]),{lineSpacing:[a,u],spacingRule:[A,m]}},ol="univer-paragraph-setting-icon-list",rl="univer-paragraph-setting-icon-list-item",il="univer-paragraph-setting-icon-list-active",sl="univer-paragraph-setting-title",al="univer-paragraph-setting-label",cl="univer-paragraph-setting-mt-base",ll="univer-paragraph-setting-flex-col",Al="univer-paragraph-setting-space-line",J={paragraphSettingIconList:ol,paragraphSettingIconListItem:rl,paragraphSettingIconListActive:il,paragraphSettingTitle:sl,paragraphSettingLabel:al,paragraphSettingMtBase:cl,paragraphSettingFlexCol:ll,paragraphSettingSpaceLine:Al},ze=o=>{const{value:t,onChange:e,className:n="",min:r=0,max:s=100,step:a=1}=o,c=Zi.useRef(null);return _.jsx(ie.InputNumber,{step:a,ref:c,min:r,max:s,value:t,onChange:l=>{e(l!=null?l:0).finally(()=>{setTimeout(()=>{var A;(A=c.current)==null||A.focus()},30)})},className:n})};function dl(){const o=i.useDependency(i.LocaleService),t=L.useMemo(()=>[{label:o.t("toolbar.alignLeft"),value:String(i.HorizontalAlign.LEFT),icon:_.jsx(di,{})},{label:o.t("toolbar.alignCenter"),value:String(i.HorizontalAlign.CENTER),icon:_.jsx(li,{})},{label:o.t("toolbar.alignRight"),value:String(i.HorizontalAlign.RIGHT),icon:_.jsx(ui,{})},{label:o.t("toolbar.alignJustify"),value:String(i.HorizontalAlign.JUSTIFIED),icon:_.jsx(si,{})}],[]),e=Xc(),[n,r]=Kc(e,t[0].value),[s,a]=qc(e),[c,l]=Jc(e),[A,d]=Zc(e),[u,m]=$c(e),[g,f]=el(e),[h,p]=tl(e),{lineSpacing:[S,I],spacingRule:[E,C]}=nl(e),y=L.useMemo(()=>E===i.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[E,S]);return _.jsxs("div",{className:J.paragraphSetting,children:[_.jsx("div",{className:J.paragraphSettingTitle,children:o.t("doc.paragraphSetting.alignment")}),_.jsx("div",{className:`
|
|
40
40
|
${J.paragraphSettingIconList}
|
|
41
41
|
${J.paragraphSettingMtBase}
|
|
42
42
|
`,children:t.map(v=>_.jsx(ie.Tooltip,{title:v.label,placement:"bottom",children:_.jsx("span",{className:sn(J.paragraphSettingIconListItem,{[J.paragraphSettingIconListActive]:n===v.value}),onClick:()=>r(v.value),children:v.icon})},v.value))}),_.jsx("div",{className:J.paragraphSettingTitle,children:o.t("doc.paragraphSetting.indentation")}),_.jsxs("div",{children:[_.jsxs("div",{className:J.paragraphSettingFlexCol,children:[_.jsxs("div",{className:J.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.left"),"(px)"]}),_.jsx(ze,{className:J.paragraphSettingMtBase,value:s,onChange:v=>a(v!=null?v:0)})]}),_.jsxs("div",{className:J.paragraphSettingFlexCol,children:[_.jsxs("div",{className:J.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.right"),"(px)"]}),_.jsx(ze,{className:J.paragraphSettingMtBase,value:c,onChange:v=>l(v!=null?v:0)})]}),_.jsxs("div",{className:J.paragraphSettingFlexCol,children:[_.jsxs("div",{className:J.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.firstLine"),"(px)"]}),_.jsx(ze,{className:J.paragraphSettingMtBase,value:A,onChange:v=>d(v!=null?v:0)})]}),_.jsxs("div",{className:J.paragraphSettingFlexCol,children:[_.jsxs("div",{className:J.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.hanging"),"(px)"]}),_.jsx(ze,{className:J.paragraphSettingMtBase,value:u,onChange:v=>m(v!=null?v:0)})]})]}),_.jsx("div",{className:J.paragraphSettingTitle,children:o.t("doc.paragraphSetting.spacing")}),_.jsxs("div",{children:[_.jsxs("div",{className:J.paragraphSettingFlexCol,children:[_.jsxs("div",{className:J.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.before"),"(px)"]}),_.jsx(ze,{className:J.paragraphSettingMtBase,value:g,onChange:v=>f(v!=null?v:0)})]}),_.jsxs("div",{className:J.paragraphSettingFlexCol,children:[_.jsxs("div",{className:J.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.after"),"(px)"]}),_.jsx(ze,{className:J.paragraphSettingMtBase,value:h,onChange:v=>p(v!=null?v:0)})]}),_.jsxs("div",{className:J.paragraphSettingFlexCol,children:[_.jsx("div",{className:J.paragraphSettingLabel,children:o.t("doc.paragraphSetting.lineSpace")}),_.jsxs("div",{className:`
|
package/lib/es/index.js
CHANGED
|
@@ -7330,11 +7330,11 @@ const Va = {
|
|
|
7330
7330
|
id: "doc-paragraph-setting.command",
|
|
7331
7331
|
type: N.COMMAND,
|
|
7332
7332
|
handler: async (n, e) => {
|
|
7333
|
-
var m, S
|
|
7333
|
+
var m, S;
|
|
7334
7334
|
const t = n.get(W), o = n.get(Q), s = n.get(T), r = o.getCurrentUnitForType(P.UNIVER_DOC), i = t.getDocRanges();
|
|
7335
7335
|
if (!r || i.length === 0 || !e)
|
|
7336
7336
|
return !1;
|
|
7337
|
-
const a = i[0].segmentId, c = r.getUnitId(), l = (S = (m = r.getSelfOrHeaderFooterModel(a).getBody()) == null ? void 0 : m.paragraphs) != null ? S : [], A =
|
|
7337
|
+
const a = i[0].segmentId, c = r.getUnitId(), l = (S = (m = r.getSelfOrHeaderFooterModel(a).getBody()) == null ? void 0 : m.paragraphs) != null ? S : [], A = Pn(i, l), d = {
|
|
7338
7338
|
id: X.id,
|
|
7339
7339
|
params: {
|
|
7340
7340
|
unitId: c,
|
|
@@ -7344,14 +7344,14 @@ const Va = {
|
|
|
7344
7344
|
}, h = new Qt();
|
|
7345
7345
|
h.reset();
|
|
7346
7346
|
const u = new Ce(), f = V.getInstance();
|
|
7347
|
-
for (const
|
|
7348
|
-
const { startIndex:
|
|
7347
|
+
for (const I of A) {
|
|
7348
|
+
const { startIndex: C } = I;
|
|
7349
7349
|
u.push({
|
|
7350
7350
|
t: j.RETAIN,
|
|
7351
|
-
len:
|
|
7351
|
+
len: C - h.cursor
|
|
7352
7352
|
});
|
|
7353
|
-
const
|
|
7354
|
-
...
|
|
7353
|
+
const R = {
|
|
7354
|
+
...I.paragraphStyle,
|
|
7355
7355
|
...e.paragraph
|
|
7356
7356
|
};
|
|
7357
7357
|
u.push({
|
|
@@ -7361,14 +7361,14 @@ const Va = {
|
|
|
7361
7361
|
dataStream: "",
|
|
7362
7362
|
paragraphs: [
|
|
7363
7363
|
{
|
|
7364
|
-
...
|
|
7365
|
-
paragraphStyle:
|
|
7364
|
+
...I,
|
|
7365
|
+
paragraphStyle: R,
|
|
7366
7366
|
startIndex: 0
|
|
7367
7367
|
}
|
|
7368
7368
|
]
|
|
7369
7369
|
},
|
|
7370
7370
|
coverType: fo.REPLACE
|
|
7371
|
-
}), h.moveCursorTo(
|
|
7371
|
+
}), h.moveCursorTo(C + 1);
|
|
7372
7372
|
}
|
|
7373
7373
|
const g = fe(r, a);
|
|
7374
7374
|
return d.params.actions = f.editOp(u.serialize(), g), !!s.syncExecuteCommand(d.id, d.params);
|
|
@@ -7379,12 +7379,12 @@ const Va = {
|
|
|
7379
7379
|
t.length || e.closePanel();
|
|
7380
7380
|
}, [t]), t;
|
|
7381
7381
|
}, _u = () => {
|
|
7382
|
-
var i, a
|
|
7382
|
+
var i, a;
|
|
7383
7383
|
const e = se(Q).getCurrentUnitForType(P.UNIVER_DOC), t = Bu();
|
|
7384
7384
|
if (!e || t.length === 0)
|
|
7385
7385
|
return [];
|
|
7386
7386
|
const o = t[0].segmentId, s = (a = (i = e.getSelfOrHeaderFooterModel(o).getBody()) == null ? void 0 : i.paragraphs) != null ? a : [];
|
|
7387
|
-
return
|
|
7387
|
+
return Pn(t, s);
|
|
7388
7388
|
}, Mu = (n, e) => {
|
|
7389
7389
|
const t = se(T), [o, s] = he(() => {
|
|
7390
7390
|
var a, c;
|
package/lib/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
.univer-text-editor-container{position:relative;width:100%;height:30px;-webkit-user-select:none;-moz-user-select:none;user-select:none;border:1px solid rgb(var(--border-color));transition:all .15s;border-radius:var(--border-radius-base)}.univer-text-editor-container:hover,.univer-text-editor-container:active,.univer-text-editor-container-active,.univer-text-editor-container-active:hover{border:1px solid rgb(var(--hyacinth-500))}.univer-text-editor-container-error,.univer-text-editor-container-error:hover{border:1px solid rgb(var(--red-400))}.univer-text-editor-container-disabled,.univer-text-editor-container-disabled:hover{border-color:rgb(var(--grey-100))}.univer-text-editor-container-placeholder{position:absolute;top:49%;left:5px;transform:translateY(-50%);color:rgb(var(--grey-400));font-size:var(--font-size-xs);pointer-events:none}.univer-text-editor-validation-error{position:absolute;top:-16px;font-size:10px;color:rgb(var(--red-400))}.univer-range-selector{overflow:hidden;display:flex;align-items:center;justify-content:space-between;color:rgb(var(--grey-600));border:1px solid rgb(var(--border-color));border-radius:var(--border-radius-base);width:220px;height:28px}.univer-range-selector-editor{position:relative;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:100%;height:100%;border:0;outline:0}.univer-range-selector-icon{cursor:pointer;display:flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;margin-right:4px;font-size:var(--font-size-lg);color:rgb(var(--text-color));background-color:transparent;border:none;border-radius:var(--border-radius-base);outline:none}.univer-range-selector-icon:not([disabled]):hover{background-color:rgb(var(--grey-100))}.univer-range-selector-icon[disabled]{cursor:not-allowed;color:rgb(var(--grey-200))}.univer-range-selector:hover,.univer-range-selector-active{border-color:rgb(var(--hyacinth-500))}.univer-range-selector-active .univer-range-selector-icon{color:rgb(var(--hyacinth-500))}.univer-range-selector-error{border-color:rgb(var(--red-400))}.univer-range-selector-error .univer-range-selector-icon{color:rgb(var(--red-400))}.univer-range-selector-error:hover{border-color:rgb(var(--red-400))}.univer-range-selector-disabled{border-color:rgb(var(--grey-100))}.univer-range-selector-disabled .univer-range-selector-icon{color:rgb(var(--grey-100))}.univer-range-selector-disabled:hover{border-color:rgb(var(--grey-100))}.univer-range-selector-modal{position:relative;max-height:500px;overflow:hidden;overflow-y:auto}.univer-range-selector-modal-container{display:flex;flex-direction:row;align-items:center;margin-bottom:10px}.univer-range-selector-modal-container-input{display:inline-block;width:280px}.univer-range-selector-modal-container-input-active{border-color:rgb(var(--hyacinth-500))}.univer-range-selector-modal-container-button{display:inline-block;text-align:center;width:28px}.univer-range-selector-modal-container-button:hover{cursor:pointer;color:rgb(var(--hyacinth-500))}.univer-range-selector-modal-container-delete-button{margin:auto}.univer-range-selector-modal-add{position:relative;width:300px;margin-top:5px;text-align:left;color:rgb(var(--hyacinth-500));font-size:var(--font-size-xs)}.univer-range-selector-modal-add .univer-range-selector-modal-add-button{display:flex;align-items:center;justify-content:center}.univer-range-selector-modal-add .univer-range-selector-modal-add-button:hover{cursor:pointer;background-color:rgb(var(--hyacinth-500),.05)}.univer-panel{padding-top:20px;font-size:var(--font-size-sm)}.univer-options-section{margin-top:10px;padding-bottom:10px}.univer-options-form-item{display:block;margin-bottom:5px}.univer-options-input{width:80%;margin-top:5px}.univer-options-margin-setting{display:flex}.univer-doc-list-type-picker{display:flex;flex-direction:row;justify-content:space-between;flex-wrap:wrap;padding:var(--padding-sm);width:240px;margin-bottom:-var(--margin-xs)}.univer-doc-list-type-picker-item{width:72px;height:81px;border-radius:4px;border:1px solid rgb(var(--border-color));margin-bottom:var(--margin-xs)}.univer-doc-list-type-picker-item:hover,.univer-doc-list-type-picker-item-active{border:1px solid rgb(var(--blue-400))}.univer-doc-count-bar{display:flex;flex:0 0 260px;justify-content:flex-end}.univer-doc-footer-container{display:flex;flex-direction:row;align-items:center;justify-content:space-between;padding:0 var(--padding-xl)}.univer-paragraph-setting-icon-list{display:flex;width:100%;padding:4px;align-items:center;gap:4px;justify-content:space-between;border:1px solid var(---Grey-200, #e5e5e5);border-radius:var(--radius-m, 6px)}.univer-paragraph-setting-icon-list-item{padding:4px 14px;border-radius:4px;background:none;display:flex;justify-content:center;align-items:center;cursor:pointer}.univer-paragraph-setting-icon-list-item:hover{background:var(--black-6, rgba(30, 34, 43, .06))}.univer-paragraph-setting-icon-list-item.univer-paragraph-setting-icon-list-active{background:var(--black-9, rgba(30, 34, 43, .09))}.univer-paragraph-setting-title{margin-top:var(--margin-base);font-size:13px;color:#1e222b;font-weight:500}.univer-paragraph-setting-label{font-size:12px;margin-top:var(--margin-sm);color:#1e222b;font-weight:400}.univer-paragraph-setting-mt-base{margin-top:var(--margin-base)}.univer-paragraph-setting-flex-col{display:flex;justify-content:space-between;align-items:center}.univer-paragraph-setting-space-line{display:flex;flex-direction:column;gap:6px}.univer-create{padding:20px auto;display:flex;align-content:center;justify-content:space-between}.univer-create-item{display:flex;align-items:center}.univer-create-label{margin-right:5px}.univer-create-input{width:110px}
|
package/lib/umd/index.js
CHANGED
|
@@ -36,7 +36,7 @@ ${s.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
36
36
|
`)||(o+=`\r
|
|
37
37
|
`,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=M.parseDataStreamToTree(o).sectionList;for(const c of r)pt(c,i,a);return a.html}function pt(i,t,e){var n,o;switch(i.nodeType){case s.DataStreamTreeNodeType.SECTION_BREAK:{for(const a of i.children)pt(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(f=>f.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 f of a)pt(f,t,e);e.html+=`${ic(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)pt(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)pt(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)pt(r,t,e);e.html+="</td>";break}default:throw new Error(`Unknown node type: ${i.nodeType}`)}}class sc{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+=oc(n);return e}}var ac=Object.defineProperty,rc=Object.getOwnPropertyDescriptor,cc=(i,t,e,n)=>{for(var o=n>1?void 0:n?rc(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=(n?r(t,e,o):r(o))||o);return n&&o&&ac(t,e,o),o},Ft=(i,t)=>(e,n)=>t(e,n,i);ft.use(vs),ft.use(Ss),ft.use(Es);function Ts(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 St=s.createIdentifier("doc.clipboard-service");let Mi=class extends s.Disposable{constructor(t,e,n,o,a){super();R(this,"_clipboardHooks",[]);R(this,"_htmlToUDM",new ft);R(this,"_umdToHtml",new sc);this._univerInstanceService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=o,this._docSelectionManagerService=a}async copy(t=s.SliceBodyType.copy){var a;const{newSnapshotList:e=[],needCache:n=!1,snapshot:o}=(a=this._getDocumentBodyInRanges(t))!=null?a:{};if(e.length===0||o==null)return!1;try{const r=this._docSelectionManagerService.getActiveTextRange(),c=!!(r!=null&&r.segmentId);this._setClipboardData(e,!c&&n)}catch(r){return this._logService.error("[DocClipboardService] copy failed",r),!1}return!0}async cut(){return this._cut()}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(){var r,c,l;const{segmentId:t,endOffset:e,style:n}=(r=this._docSelectionManagerService.getActiveTextRange())!=null?r:{},o=(c=this._docSelectionManagerService.getTextRanges())!=null?c:[],a=(l=this._docSelectionManagerService.getRectRanges())!=null?l:[];if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),o.length===0&&a.length===0)return!1;this.copy(s.SliceBodyType.cut);try{let A=0;if(a.length>0)A=fn(o,a);else if(e!=null){A=e;for(const u of o){const{startOffset:m,endOffset:h}=u;m==null||h==null||h<=e&&(A-=h-m)}}const d=[{startOffset:A,endOffset:A,style:n}];return this._commandService.executeCommand(tt.id,{segmentId:t,textRanges:d})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var d,u;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(m=>{m.onBeforePaste&&(n=m.onBeforePaste(n))}),n.customRanges=(u=n.customRanges)==null?void 0:u.map(s.BuildTextUtils.customRange.copyCustomRange);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 m=c;for(const f of A){const{startOffset:g,endOffset:p}=f;g==null||p==null||p<=c&&(m+=n.dataStream.length-(p-g))}const h=[{startOffset:m,endOffset:m,style:l}];return this._commandService.executeCommand(Ti.id,{doc:{...t,body:n},segmentId:r,textRanges:h})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t,e=!0){var r,c,l,A;const n=qr(),o=(t.length>1?t.map(d=>{var u;return((u=d.body)==null?void 0:u.dataStream)||""}).join(`
|
|
38
38
|
`):((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
|
|
39
|
-
`," ");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,f=(A=d.drawings)==null?void 0:A[h];if(f){const g=s.Tools.generateRandomId(6);m.blockId=g,u.drawings[g]={...s.Tools.deepClone(f),drawingId:g}}}}Ri.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){var A;const e=this._univerInstanceService.getCurrentUniverDocInstance(),n=this._docSelectionManagerService.getDocRanges(),o=[];let a=!0;if(e==null||n.length===0)return;const r=n[0].segmentId,c=(A=e==null?void 0:e.getSelfOrHeaderFooterModel(r))==null?void 0:A.getBody(),l=e.getSnapshot();if(c!=null){for(const d of n){const{startOffset:u,endOffset:m,collapsed:h,rangeType:f}=d;if(h||u==null||m==null)continue;if(f===s.DOC_RANGE_TYPE.RECT){a=!1;const{spanEntireRow:S}=d;let I;I=Ts(c,u,m),o.push(I);continue}const g={startOffset:u,endOffset:m,collapsed:h},p=e.getSelfOrHeaderFooterModel(r).sliceBody(g.startOffset,g.endOffset,t);p!=null&&o.push(p)}return{newSnapshotList:o.map(d=>({...l,body:d})),needCache:a,snapshot:l}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const o=[];for(const a of t)for(const r of a.types)switch(r){case y.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await a.getType(r).then(c=>c&&c.text());break}case y.HTML_CLIPBOARD_MIME_TYPE:{e=await a.getType(r).then(c=>c&&c.text());break}case y.FILE__BMP_CLIPBOARD_MIME_TYPE:case y.FILE__JPEG_CLIPBOARD_MIME_TYPE:case y.FILE__WEBP_CLIPBOARD_MIME_TYPE:case y.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=$r(t);if(o){const r=Ri.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&&Ri.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:jn.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),f=d.naturalHeight/d.naturalWidth;m({width:h,height:h*f})}})},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),f=`paste_image_id_${d}`,g=e.body,p=e.drawings;g.dataStream+="\b",(S=g.customBlocks)==null||S.push({startIndex:d,blockId:f}),p[f]={drawingId:f,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])}};Mi=cc([Ft(0,s.IUniverInstanceService),Ft(1,s.ILogService),Ft(2,s.ICommandService),Ft(3,y.IClipboardInterfaceService),Ft(4,s.Inject(D.DocSelectionManagerService))],Mi);function pn(i){return i.getContextValue(s.FOCUSING_DOC)||i.getContextValue(s.EDITOR_ACTIVATED)}const Bi=999,Ht={id:y.CopyCommand.id,name:"doc.command.copy",type:s.CommandType.COMMAND,multi:!0,priority:Bi,preconditions:pn,handler:async i=>i.get(St).copy()},Sn={id:y.CutCommand.id,name:"doc.command.cut",type:s.CommandType.COMMAND,multi:!0,priority:Bi,preconditions:pn,handler:async i=>i.get(St).cut()},In={id:y.PasteCommand.id,name:"doc.command.paste",type:s.CommandType.COMMAND,multi:!0,priority:Bi,preconditions:pn,handler:async i=>{const t=i.get(St),n=await i.get(y.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}},En={id:"doc.command.switch-mode",type:s.CommandType.COMMAND,handler:async i=>{var I,E,T,O,v;const t=i.get(s.ICommandService),e=i.get(M.IRenderManagerService),n=i.get(D.DocSelectionManagerService),a=i.get(s.IUniverInstanceService).getCurrentUniverDocInstance();if(a==null)return!1;const r=a.getUnitId(),c=(I=e.getRenderById(r))==null?void 0:I.with(D.DocSkeletonManagerService).getSkeleton(),l=(E=e.getRenderById(r))==null?void 0:E.with(C.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}},f=s.JSONX.getInstance(),g=[];let p;if(u===void 0?p=f.insertOp(["documentStyle","documentFlavor"],s.DocumentFlavor.MODERN):u===s.DocumentFlavor.MODERN?p=f.replaceOp(["documentStyle","documentFlavor"],u,s.DocumentFlavor.TRADITIONAL):p=f.replaceOp(["documentStyle","documentFlavor"],u,s.DocumentFlavor.MODERN),p)g.push(p);else return!1;if(u!==s.DocumentFlavor.MODERN){const b=a.getSnapshot(),{drawings:_={},body:B}=b,w=(T=B==null?void 0:B.customBlocks)!=null?T:[];for(const x in _){const U=_[x],L=w.find(Y=>Y.blockId===x);if(L==null)continue;const F=U.docTransform.positionV,{relativeFrom:H,posOffset:k}=F;if(H===s.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:X}=L,G=c.findNodeByCharIndex(X,A,d),W=(O=G==null?void 0:G.parent)==null?void 0:O.parent,V=W==null?void 0:W.parent,K=V==null?void 0:V.lines.find(Y=>Y.paragraphIndex===(W==null?void 0:W.paragraphIndex)&&Y.paragraphStart),ee=(v=V==null?void 0:V.parent)==null?void 0:v.parent;if(G==null||W==null||K==null||V==null||ee==null)continue;let Z=0;H===s.ObjectRelativeFromV.LINE?Z-=W.top:H===s.ObjectRelativeFromV.PAGE&&(Z+=ee.marginTop),Z+=K.top;const j={...F,relativeFrom:s.ObjectRelativeFromV.PARAGRAPH,posOffset:(k!=null?k:0)-Z},z=f.replaceOp(["drawings",x,"docTransform","positionV"],F,j);z&&g.push(z)}}return h.params.actions=g.reduce((b,_)=>s.JSONX.compose(b,_),null),!!t.syncExecuteCommand(h.id,h.params)}},vn={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=Lt(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=me(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,f=s.JSONX.getInstance(),g=ls(r,u);if(g==null)return!1;const{offset:p,rowIndexes:S,len:I,tableId:E,cursor:T,selectWholeTable:O}=g;if(O)return n.executeCommand(It.id);const v=[],b=[{startOffset:T,endOffset:T,collapsed:!0}],_={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:b}};p>0&&h.push({t:s.TextXActionType.RETAIN,len:p}),h.push({t:s.TextXActionType.DELETE,len:I});const B=te(l,c);v.push(f.editOp(h.serialize(),B));for(const x of S.reverse()){const U=f.removeOp(["tableSource",E,"tableRows",x]);v.push(U)}return _.params.actions=v.reduce((x,U)=>s.JSONX.compose(x,U),null),!!n.syncExecuteCommand(_.id,_.params)}},Cn={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=Lt(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=me(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,f=s.JSONX.getInstance(),g=jr(r,u);if(g==null)return!1;const{offsets:p,columnIndexes:S,tableId:I,cursor:E,rowCount:T,selectWholeTable:O}=g;if(O)return n.executeCommand(It.id);const v=[],b=[{startOffset:E,endOffset:E,collapsed:!0}],_={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:b}};for(const x of p){const{retain:U,delete:L}=x;U>0&&h.push({t:s.TextXActionType.RETAIN,len:U}),h.push({t:s.TextXActionType.DELETE,len:L})}const B=te(l,c);v.push(f.editOp(h.serialize(),B)),S.reverse();for(let x=0;x<T;x++)for(const U of S){const L=f.removeOp(["tableSource",I,"tableRows",x,"tableCells",U]);v.push(L)}for(const x of S){const U=f.removeOp(["tableSource",I,"tableColumns",x]);v.push(U)}return _.params.actions=v.reduce((x,U)=>s.JSONX.compose(x,U),null),!!n.syncExecuteCommand(_.id,_.params)}},It={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=Lt(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=me(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,f=s.JSONX.getInstance(),g=As(r,u);if(g==null)return!1;const{offset:p,len:S,tableId:I,cursor:E}=g,T=[],O=[{startOffset:E,endOffset:E,collapsed:!0}],v={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:O}};p>0&&h.push({t:s.TextXActionType.RETAIN,len:p}),h.push({t:s.TextXActionType.DELETE,len:S});const b=te(l,c);T.push(f.editOp(h.serialize(),b));const _=f.removeOp(["tableSource",I]);return T.push(_),v.params.actions=T.reduce((w,x)=>s.JSONX.compose(w,x),null),!!n.syncExecuteCommand(v.id,v.params)}},Di="doc.command.table-insert-row",_i="doc.command.table-insert-column",lc="doc.command.table-insert-row-above",Ac="doc.command.table-insert-row-bellow",dc="doc.command.table-insert-column-left",uc="doc.command.table-insert-column-right",Tn={id:lc,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Di,{position:ln.ABOVE})},bn={id:Ac,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Di,{position:ln.BELLOW})},yn={id:dc,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(_i,{position:Ei.LEFT})},Rn={id:uc,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(_i,{position:Ei.RIGHT})},Ni={id:Di,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=Lt(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=me(i,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),f=d==null?void 0:d.getUnitId(),g=new s.TextX,p=s.JSONX.getInstance(),S=Hr(l,e,h);if(S==null)return!1;const{offset:I,colCount:E,tableId:T,insertRowIndex:O}=S,v=[],b=I+2,_=[{startOffset:b,endOffset:b,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:f,actions:[],textRanges:_}};I>0&&g.push({t:s.TextXActionType.RETAIN,len:I});const w=Qr(E);g.push({t:s.TextXActionType.INSERT,body:w,len:w.dataStream.length});const x=te(d,A);v.push(p.editOp(g.serialize(),x));const U=dn(E),L=p.insertOp(["tableSource",T,"tableRows",O],U);return v.push(L),B.params.actions=v.reduce((H,k)=>s.JSONX.compose(H,k),null),!!a.syncExecuteCommand(B.id,B.params)}},bs={id:_i,type:s.CommandType.COMMAND,handler:async(i,t)=>{var ee,Z,j;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=Lt(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=me(i,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),f=d==null?void 0:d.getUnitId(),g=new s.TextX,p=s.JSONX.getInstance(),S=kr(l,e,h);if(S==null)return!1;const{offsets:I,columnIndex:E,tableId:T,rowCount:O}=S,v=[],b=I[0]+1,_=[{startOffset:b,endOffset:b,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:f,actions:[],textRanges:_}};for(const z of I){g.push({t:s.TextXActionType.RETAIN,len:z});const Y=Fr();g.push({t:s.TextXActionType.INSERT,body:Y,len:Y.dataStream.length})}const w=te(d,A);v.push(p.editOp(g.serialize(),w));for(let z=0;z<O;z++){const Y=An(),ie=p.insertOp(["tableSource",T,"tableRows",z,"tableCells",E],Y);v.push(ie)}const x=d.getSnapshot(),U=x.documentStyle,{marginLeft:L=0,marginRight:F=0}=U,H=((Z=(ee=U.pageSize)==null?void 0:ee.width)!=null?Z:800)-L-F,k=(j=x==null?void 0:x.tableSource)==null?void 0:j[T].tableColumns,{newColWidth:X,widths:G}=Vr(H,k,E);for(let z=0;z<G.length;z++){const Y=p.replaceOp(["tableSource",T,"tableColumns",z,"size","width","v"],k[z].size.width.v,G[z]);v.push(Y)}const W=un(X),V=p.insertOp(["tableSource",T,"tableColumns",E],W);return v.push(V),B.params.actions=v.reduce((z,Y)=>s.JSONX.compose(z,Y),null),!!a.syncExecuteCommand(B.id,B.params)}},ys="COMPONENT_DOC_CREATE_TABLE_CONFIRM";function Pi(i,t){const e=[];for(let n=0,o=i.length;n<o;n++)i[n]===s.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=s.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=s.Tools.deepClone(t.paragraphStyle));return e}const Ui={id:"doc.command.break-line",type:s.CommandType.COMMAND,handler:async i=>{var v,b,_;const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=i.get(_e),a=t.getActiveTextRange(),r=t.getRectRanges();if(a==null)return!1;if(r&&r.length){const{startOffset:B}=a;return t.replaceDocRanges([{startOffset:B,endOffset:B}]),!0}const{segmentId:c}=a,l=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c!=null?c:"").getBody();if(l==null||A==null)return!1;const d=l.getUnitId(),{startOffset:u,endOffset:m}=a,f=((v=A.paragraphs)!=null?v:[]).find(B=>B.startIndex>=u);if(!f)return!1;const g=f.startIndex,p=o.getDefaultStyle(),S=o.getStyleCache(),I=Xt((b=A.textRuns)!=null?b:[],m,p,S),E={dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Pi(s.DataStreamTreeTokenType.PARAGRAPH,f),textRuns:[{st:0,ed:1,ts:{...I.ts}}]},T={startOffset:u,endOffset:m,collapsed:u===m},O=await n.executeCommand(hn.id,{unitId:d,body:E,range:T,segmentId:c});if(((_=f.bullet)==null?void 0:_.listType)===s.PresetListType.CHECK_LIST_CHECKED){const B={index:g+1-(m-u),segmentId:c,textRanges:[{startOffset:u+1,endOffset:u+1}]};return!!await n.executeCommand(rn.id,B)&&O}return O}},wi={id:"doc.command.create-table",type:s.CommandType.COMMAND,handler:async(i,t)=>{var j,z,Y,ie,ce,ge;const{rowCount:e,colCount:n}=t,o=i.get(D.DocSelectionManagerService),a=i.get(s.IUniverInstanceService),r=i.get(s.ICommandService),c=i.get(_e),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(),f=me(i,h),g=f==null?void 0:f.getSkeleton();if(g==null)return!1;const{startOffset:p}=l,I=((j=m.paragraphs)!=null?j:[]).find(le=>le.startIndex>=p),E=g.findNodeByCharIndex(p,A,d);if(E==null)return!1;const T=new s.TextX,O=s.JSONX.getInstance(),v=[],b=p+4,_=[{startOffset:b,endOffset:b,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:_}};p>0&&T.push({t:s.TextXActionType.RETAIN,len:p}),T.push({t:s.TextXActionType.INSERT,body:{dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Pi(s.DataStreamTreeTokenType.PARAGRAPH,I)},len:1});const w=c.getDefaultStyle(),x=c.getStyleCache(),U=Xt((z=m.textRuns)!=null?z:[],p,w,x),{dataStream:L,paragraphs:F,sectionBreaks:H}=Lr(e,n),k=(ge=(ce=(ie=(Y=E.parent)==null?void 0:Y.parent)==null?void 0:ie.parent)==null?void 0:ce.parent)==null?void 0:ge.parent;if(k==null)return!1;const{pageWidth:X,marginLeft:G,marginRight:W}=k,V=vi(e,n,X-G-W);T.push({t:s.TextXActionType.INSERT,body:{dataStream:L,paragraphs:F,sectionBreaks:H,textRuns:[{...U,st:0,ed:L.length}],tables:[{startIndex:0,endIndex:L.length,tableId:V.tableId}]},len:L.length});const K=te(u,A);v.push(O.editOp(T.serialize(),K));const ee=O.insertOp(["tableSource",V.tableId],V);return v.push(ee),B.params.actions=v.reduce((le,Ce)=>s.JSONX.compose(le,Ce),null),!!r.syncExecuteCommand(B.id,B.params)}},Li="doc.component.create-table-confirm",On={id:"doc.operation.create-table",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(s.LocaleService),e=i.get(y.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:Li,children:{label:{name:ys,props:{handleRowColChange:a,tableCreateParams:o}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(wi.id,o),e.close(Li)},onClose:()=>{e.close(Li)}}),!0}},Oe={id:"doc-paragraph-setting.command",type:s.CommandType.COMMAND,handler:async(i,t)=>{var S,I,E;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=(I=(S=a.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:S.paragraphs)!=null?I:[],d=(E=gt(r,A))!=null?E:[],u={id:D.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:r}},m=new s.MemoryCursor;m.reset();const h=new s.TextX,f=s.JSONX.getInstance();for(const T of d){const{startIndex:O}=T;h.push({t:s.TextXActionType.RETAIN,len:O-m.cursor});const v={...T.paragraphStyle,...t.paragraph};h.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...T,paragraphStyle:v,startIndex:0}]},coverType:s.UpdateDocsAttributeType.REPLACE}),m.moveCursorTo(O+1)}const g=te(a,c);return u.params.actions=f.editOp(h.serialize(),g),!!o.syncExecuteCommand(u.id,u.params)}},hc=()=>{const i=s.useDependency(D.DocSelectionManagerService),t=s.useDependency(Et),e=Q.useMemo(()=>i.getDocRanges(),[]);return Q.useEffect(()=>{e.length||t.closePanel()},[e]),e},gc=()=>{var r,c,l;const t=s.useDependency(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),e=hc();if(!t||e.length===0)return[];const n=e[0].segmentId,o=(c=(r=t.getSelfOrHeaderFooterModel(n).getBody())==null?void 0:r.paragraphs)!=null?c:[];return(l=gt(e,o))!=null?l:[]},mc=(i,t)=>{const e=s.useDependency(s.ICommandService),[n,o]=Q.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(Oe.id,{paragraph:{horizontalAlign:Number(r)}}))]},fc=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentStart,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{indentStart:{v:a}}}))]},pc=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentEnd,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{indentEnd:{v:a}}}))]},Sc=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentFirstLine,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{indentFirstLine:{v:a}}}))]},Ic=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.hanging,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{hanging:{v:a}}}))]},Ec=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.spaceAbove,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{spaceAbove:{v:a}}}))]},vc=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.spaceBelow,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{spaceBelow:{v:a}}}))]},Cc=i=>{const t=s.useDependency(s.ICommandService),e=s.useDependency(M.IRenderManagerService),n=s.useDependency(s.IUniverInstanceService),o=Q.useMemo(()=>{var f;const h=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(h)return(f=e.getRenderById(h==null?void 0:h.getUnitId()))==null?void 0:f.with(D.DocSkeletonManagerService).getSkeleton()},[]),a=Q.useMemo(()=>new N.BehaviorSubject({}),[]),[r,c]=Q.useState(()=>{var f,g;const h=i[0];return h&&(g=(f=h.paragraphStyle)==null?void 0:f.lineSpacing)!=null?g:1}),l=Q.useRef(r),[A,d]=Q.useState(()=>{var f,g;const h=i[0];return h&&(g=(f=h.paragraphStyle)==null?void 0:f.spacingRule)!=null?g:s.SpacingRule.AUTO}),u=async h=>{c(h),a.next({lineSpacing:h,spacingRule:A})},m=async h=>{if(h!==A){let f=l.current;if(h===s.SpacingRule.AT_LEAST){const g=o==null?void 0:o.findNodeByCharIndex(i[0].startIndex),p=g==null?void 0:g.parent,S=p==null?void 0:p.parent;(S==null?void 0:S.contentHeight)!==void 0&&(f=Math.max(S.contentHeight,f))}else f>5&&(f=2);l.current=r,u(f),d(h),a.next({spacingRule:h})}};return Q.useEffect(()=>{const h=a.pipe(yt.filter(f=>!!Object.keys(f).length),yt.bufferTime(16),yt.filter(f=>!!f.length),yt.map(f=>f.reduce((g,p)=>(Object.keys(p).forEach(S=>{g[S]=p[S]}),g),{}))).subscribe(f=>t.executeCommand(Oe.id,{paragraph:{...f}}));return()=>h.unsubscribe()},[]),{lineSpacing:[r,u],spacingRule:[A,m]}},q={paragraphSettingIconList:"univer-paragraph-setting-icon-list",paragraphSettingIconListItem:"univer-paragraph-setting-icon-list-item",paragraphSettingIconListActive:"univer-paragraph-setting-icon-list-active",paragraphSettingTitle:"univer-paragraph-setting-title",paragraphSettingLabel:"univer-paragraph-setting-label",paragraphSettingMtBase:"univer-paragraph-setting-mt-base",paragraphSettingFlexCol:"univer-paragraph-setting-flex-col",paragraphSettingSpaceLine:"univer-paragraph-setting-space-line"},nt=i=>{const{value:t,onChange:e,className:n="",min:o=0,max:a=100,step:r=1}=i,c=Zs.useRef(null);return P.jsx(se.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 Tc(){const i=s.useDependency(s.LocaleService),t=Q.useMemo(()=>[{label:i.t("toolbar.alignLeft"),value:String(s.HorizontalAlign.LEFT),icon:P.jsx(Mo,{})},{label:i.t("toolbar.alignCenter"),value:String(s.HorizontalAlign.CENTER),icon:P.jsx(Oo,{})},{label:i.t("toolbar.alignRight"),value:String(s.HorizontalAlign.RIGHT),icon:P.jsx(Bo,{})},{label:i.t("toolbar.alignJustify"),value:String(s.HorizontalAlign.JUSTIFIED),icon:P.jsx(bo,{})}],[]),e=gc(),[n,o]=mc(e,t[0].value),[a,r]=fc(e),[c,l]=pc(e),[A,d]=Sc(e),[u,m]=Ic(e),[h,f]=Ec(e),[g,p]=vc(e),{lineSpacing:[S,I],spacingRule:[E,T]}=Cc(e),O=Q.useMemo(()=>E===s.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[E,S]);return P.jsxs("div",{className:q.paragraphSetting,children:[P.jsx("div",{className:q.paragraphSettingTitle,children:i.t("doc.paragraphSetting.alignment")}),P.jsx("div",{className:`
|
|
39
|
+
`," ");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,f=(A=d.drawings)==null?void 0:A[h];if(f){const g=s.Tools.generateRandomId(6);m.blockId=g,u.drawings[g]={...s.Tools.deepClone(f),drawingId:g}}}}Ri.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){var A;const e=this._univerInstanceService.getCurrentUniverDocInstance(),n=this._docSelectionManagerService.getDocRanges(),o=[];let a=!0;if(e==null||n.length===0)return;const r=n[0].segmentId,c=(A=e==null?void 0:e.getSelfOrHeaderFooterModel(r))==null?void 0:A.getBody(),l=e.getSnapshot();if(c!=null){for(const d of n){const{startOffset:u,endOffset:m,collapsed:h,rangeType:f}=d;if(h||u==null||m==null)continue;if(f===s.DOC_RANGE_TYPE.RECT){a=!1;const{spanEntireRow:S}=d;let I;I=Ts(c,u,m),o.push(I);continue}const g={startOffset:u,endOffset:m,collapsed:h},p=e.getSelfOrHeaderFooterModel(r).sliceBody(g.startOffset,g.endOffset,t);p!=null&&o.push(p)}return{newSnapshotList:o.map(d=>({...l,body:d})),needCache:a,snapshot:l}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const o=[];for(const a of t)for(const r of a.types)switch(r){case y.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await a.getType(r).then(c=>c&&c.text());break}case y.HTML_CLIPBOARD_MIME_TYPE:{e=await a.getType(r).then(c=>c&&c.text());break}case y.FILE__BMP_CLIPBOARD_MIME_TYPE:case y.FILE__JPEG_CLIPBOARD_MIME_TYPE:case y.FILE__WEBP_CLIPBOARD_MIME_TYPE:case y.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=$r(t);if(o){const r=Ri.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&&Ri.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:jn.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),f=d.naturalHeight/d.naturalWidth;m({width:h,height:h*f})}})},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),f=`paste_image_id_${d}`,g=e.body,p=e.drawings;g.dataStream+="\b",(S=g.customBlocks)==null||S.push({startIndex:d,blockId:f}),p[f]={drawingId:f,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])}};Mi=cc([Ft(0,s.IUniverInstanceService),Ft(1,s.ILogService),Ft(2,s.ICommandService),Ft(3,y.IClipboardInterfaceService),Ft(4,s.Inject(D.DocSelectionManagerService))],Mi);function pn(i){return i.getContextValue(s.FOCUSING_DOC)||i.getContextValue(s.EDITOR_ACTIVATED)}const Bi=999,Ht={id:y.CopyCommand.id,name:"doc.command.copy",type:s.CommandType.COMMAND,multi:!0,priority:Bi,preconditions:pn,handler:async i=>i.get(St).copy()},Sn={id:y.CutCommand.id,name:"doc.command.cut",type:s.CommandType.COMMAND,multi:!0,priority:Bi,preconditions:pn,handler:async i=>i.get(St).cut()},In={id:y.PasteCommand.id,name:"doc.command.paste",type:s.CommandType.COMMAND,multi:!0,priority:Bi,preconditions:pn,handler:async i=>{const t=i.get(St),n=await i.get(y.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}},En={id:"doc.command.switch-mode",type:s.CommandType.COMMAND,handler:async i=>{var I,E,T,O,v;const t=i.get(s.ICommandService),e=i.get(M.IRenderManagerService),n=i.get(D.DocSelectionManagerService),a=i.get(s.IUniverInstanceService).getCurrentUniverDocInstance();if(a==null)return!1;const r=a.getUnitId(),c=(I=e.getRenderById(r))==null?void 0:I.with(D.DocSkeletonManagerService).getSkeleton(),l=(E=e.getRenderById(r))==null?void 0:E.with(C.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}},f=s.JSONX.getInstance(),g=[];let p;if(u===void 0?p=f.insertOp(["documentStyle","documentFlavor"],s.DocumentFlavor.MODERN):u===s.DocumentFlavor.MODERN?p=f.replaceOp(["documentStyle","documentFlavor"],u,s.DocumentFlavor.TRADITIONAL):p=f.replaceOp(["documentStyle","documentFlavor"],u,s.DocumentFlavor.MODERN),p)g.push(p);else return!1;if(u!==s.DocumentFlavor.MODERN){const b=a.getSnapshot(),{drawings:_={},body:B}=b,w=(T=B==null?void 0:B.customBlocks)!=null?T:[];for(const x in _){const U=_[x],L=w.find(Y=>Y.blockId===x);if(L==null)continue;const F=U.docTransform.positionV,{relativeFrom:H,posOffset:k}=F;if(H===s.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:X}=L,G=c.findNodeByCharIndex(X,A,d),W=(O=G==null?void 0:G.parent)==null?void 0:O.parent,V=W==null?void 0:W.parent,K=V==null?void 0:V.lines.find(Y=>Y.paragraphIndex===(W==null?void 0:W.paragraphIndex)&&Y.paragraphStart),ee=(v=V==null?void 0:V.parent)==null?void 0:v.parent;if(G==null||W==null||K==null||V==null||ee==null)continue;let Z=0;H===s.ObjectRelativeFromV.LINE?Z-=W.top:H===s.ObjectRelativeFromV.PAGE&&(Z+=ee.marginTop),Z+=K.top;const j={...F,relativeFrom:s.ObjectRelativeFromV.PARAGRAPH,posOffset:(k!=null?k:0)-Z},z=f.replaceOp(["drawings",x,"docTransform","positionV"],F,j);z&&g.push(z)}}return h.params.actions=g.reduce((b,_)=>s.JSONX.compose(b,_),null),!!t.syncExecuteCommand(h.id,h.params)}},vn={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=Lt(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=me(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,f=s.JSONX.getInstance(),g=ls(r,u);if(g==null)return!1;const{offset:p,rowIndexes:S,len:I,tableId:E,cursor:T,selectWholeTable:O}=g;if(O)return n.executeCommand(It.id);const v=[],b=[{startOffset:T,endOffset:T,collapsed:!0}],_={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:b}};p>0&&h.push({t:s.TextXActionType.RETAIN,len:p}),h.push({t:s.TextXActionType.DELETE,len:I});const B=te(l,c);v.push(f.editOp(h.serialize(),B));for(const x of S.reverse()){const U=f.removeOp(["tableSource",E,"tableRows",x]);v.push(U)}return _.params.actions=v.reduce((x,U)=>s.JSONX.compose(x,U),null),!!n.syncExecuteCommand(_.id,_.params)}},Cn={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=Lt(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=me(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,f=s.JSONX.getInstance(),g=jr(r,u);if(g==null)return!1;const{offsets:p,columnIndexes:S,tableId:I,cursor:E,rowCount:T,selectWholeTable:O}=g;if(O)return n.executeCommand(It.id);const v=[],b=[{startOffset:E,endOffset:E,collapsed:!0}],_={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:b}};for(const x of p){const{retain:U,delete:L}=x;U>0&&h.push({t:s.TextXActionType.RETAIN,len:U}),h.push({t:s.TextXActionType.DELETE,len:L})}const B=te(l,c);v.push(f.editOp(h.serialize(),B)),S.reverse();for(let x=0;x<T;x++)for(const U of S){const L=f.removeOp(["tableSource",I,"tableRows",x,"tableCells",U]);v.push(L)}for(const x of S){const U=f.removeOp(["tableSource",I,"tableColumns",x]);v.push(U)}return _.params.actions=v.reduce((x,U)=>s.JSONX.compose(x,U),null),!!n.syncExecuteCommand(_.id,_.params)}},It={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=Lt(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=me(i,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new s.TextX,f=s.JSONX.getInstance(),g=As(r,u);if(g==null)return!1;const{offset:p,len:S,tableId:I,cursor:E}=g,T=[],O=[{startOffset:E,endOffset:E,collapsed:!0}],v={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:O}};p>0&&h.push({t:s.TextXActionType.RETAIN,len:p}),h.push({t:s.TextXActionType.DELETE,len:S});const b=te(l,c);T.push(f.editOp(h.serialize(),b));const _=f.removeOp(["tableSource",I]);return T.push(_),v.params.actions=T.reduce((w,x)=>s.JSONX.compose(w,x),null),!!n.syncExecuteCommand(v.id,v.params)}},Di="doc.command.table-insert-row",_i="doc.command.table-insert-column",lc="doc.command.table-insert-row-above",Ac="doc.command.table-insert-row-bellow",dc="doc.command.table-insert-column-left",uc="doc.command.table-insert-column-right",Tn={id:lc,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Di,{position:ln.ABOVE})},bn={id:Ac,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(Di,{position:ln.BELLOW})},yn={id:dc,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(_i,{position:Ei.LEFT})},Rn={id:uc,type:s.CommandType.COMMAND,handler:async i=>i.get(s.ICommandService).executeCommand(_i,{position:Ei.RIGHT})},Ni={id:Di,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=Lt(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=me(i,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),f=d==null?void 0:d.getUnitId(),g=new s.TextX,p=s.JSONX.getInstance(),S=Hr(l,e,h);if(S==null)return!1;const{offset:I,colCount:E,tableId:T,insertRowIndex:O}=S,v=[],b=I+2,_=[{startOffset:b,endOffset:b,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:f,actions:[],textRanges:_}};I>0&&g.push({t:s.TextXActionType.RETAIN,len:I});const w=Qr(E);g.push({t:s.TextXActionType.INSERT,body:w,len:w.dataStream.length});const x=te(d,A);v.push(p.editOp(g.serialize(),x));const U=dn(E),L=p.insertOp(["tableSource",T,"tableRows",O],U);return v.push(L),B.params.actions=v.reduce((H,k)=>s.JSONX.compose(H,k),null),!!a.syncExecuteCommand(B.id,B.params)}},bs={id:_i,type:s.CommandType.COMMAND,handler:async(i,t)=>{var ee,Z,j;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=Lt(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=me(i,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),f=d==null?void 0:d.getUnitId(),g=new s.TextX,p=s.JSONX.getInstance(),S=kr(l,e,h);if(S==null)return!1;const{offsets:I,columnIndex:E,tableId:T,rowCount:O}=S,v=[],b=I[0]+1,_=[{startOffset:b,endOffset:b,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:f,actions:[],textRanges:_}};for(const z of I){g.push({t:s.TextXActionType.RETAIN,len:z});const Y=Fr();g.push({t:s.TextXActionType.INSERT,body:Y,len:Y.dataStream.length})}const w=te(d,A);v.push(p.editOp(g.serialize(),w));for(let z=0;z<O;z++){const Y=An(),ie=p.insertOp(["tableSource",T,"tableRows",z,"tableCells",E],Y);v.push(ie)}const x=d.getSnapshot(),U=x.documentStyle,{marginLeft:L=0,marginRight:F=0}=U,H=((Z=(ee=U.pageSize)==null?void 0:ee.width)!=null?Z:800)-L-F,k=(j=x==null?void 0:x.tableSource)==null?void 0:j[T].tableColumns,{newColWidth:X,widths:G}=Vr(H,k,E);for(let z=0;z<G.length;z++){const Y=p.replaceOp(["tableSource",T,"tableColumns",z,"size","width","v"],k[z].size.width.v,G[z]);v.push(Y)}const W=un(X),V=p.insertOp(["tableSource",T,"tableColumns",E],W);return v.push(V),B.params.actions=v.reduce((z,Y)=>s.JSONX.compose(z,Y),null),!!a.syncExecuteCommand(B.id,B.params)}},ys="COMPONENT_DOC_CREATE_TABLE_CONFIRM";function Pi(i,t){const e=[];for(let n=0,o=i.length;n<o;n++)i[n]===s.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=s.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=s.Tools.deepClone(t.paragraphStyle));return e}const Ui={id:"doc.command.break-line",type:s.CommandType.COMMAND,handler:async i=>{var v,b,_;const t=i.get(D.DocSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),o=i.get(_e),a=t.getActiveTextRange(),r=t.getRectRanges();if(a==null)return!1;if(r&&r.length){const{startOffset:B}=a;return t.replaceDocRanges([{startOffset:B,endOffset:B}]),!0}const{segmentId:c}=a,l=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c!=null?c:"").getBody();if(l==null||A==null)return!1;const d=l.getUnitId(),{startOffset:u,endOffset:m}=a,f=((v=A.paragraphs)!=null?v:[]).find(B=>B.startIndex>=u);if(!f)return!1;const g=f.startIndex,p=o.getDefaultStyle(),S=o.getStyleCache(),I=Xt((b=A.textRuns)!=null?b:[],m,p,S),E={dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Pi(s.DataStreamTreeTokenType.PARAGRAPH,f),textRuns:[{st:0,ed:1,ts:{...I.ts}}]},T={startOffset:u,endOffset:m,collapsed:u===m},O=await n.executeCommand(hn.id,{unitId:d,body:E,range:T,segmentId:c});if(((_=f.bullet)==null?void 0:_.listType)===s.PresetListType.CHECK_LIST_CHECKED){const B={index:g+1-(m-u),segmentId:c,textRanges:[{startOffset:u+1,endOffset:u+1}]};return!!await n.executeCommand(rn.id,B)&&O}return O}},wi={id:"doc.command.create-table",type:s.CommandType.COMMAND,handler:async(i,t)=>{var j,z,Y,ie,ce,ge;const{rowCount:e,colCount:n}=t,o=i.get(D.DocSelectionManagerService),a=i.get(s.IUniverInstanceService),r=i.get(s.ICommandService),c=i.get(_e),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(),f=me(i,h),g=f==null?void 0:f.getSkeleton();if(g==null)return!1;const{startOffset:p}=l,I=((j=m.paragraphs)!=null?j:[]).find(le=>le.startIndex>=p),E=g.findNodeByCharIndex(p,A,d);if(E==null)return!1;const T=new s.TextX,O=s.JSONX.getInstance(),v=[],b=p+4,_=[{startOffset:b,endOffset:b,collapsed:!0}],B={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:_}};p>0&&T.push({t:s.TextXActionType.RETAIN,len:p}),T.push({t:s.TextXActionType.INSERT,body:{dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Pi(s.DataStreamTreeTokenType.PARAGRAPH,I)},len:1});const w=c.getDefaultStyle(),x=c.getStyleCache(),U=Xt((z=m.textRuns)!=null?z:[],p,w,x),{dataStream:L,paragraphs:F,sectionBreaks:H}=Lr(e,n),k=(ge=(ce=(ie=(Y=E.parent)==null?void 0:Y.parent)==null?void 0:ie.parent)==null?void 0:ce.parent)==null?void 0:ge.parent;if(k==null)return!1;const{pageWidth:X,marginLeft:G,marginRight:W}=k,V=vi(e,n,X-G-W);T.push({t:s.TextXActionType.INSERT,body:{dataStream:L,paragraphs:F,sectionBreaks:H,textRuns:[{...U,st:0,ed:L.length}],tables:[{startIndex:0,endIndex:L.length,tableId:V.tableId}]},len:L.length});const K=te(u,A);v.push(O.editOp(T.serialize(),K));const ee=O.insertOp(["tableSource",V.tableId],V);return v.push(ee),B.params.actions=v.reduce((le,Ce)=>s.JSONX.compose(le,Ce),null),!!r.syncExecuteCommand(B.id,B.params)}},Li="doc.component.create-table-confirm",On={id:"doc.operation.create-table",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(s.LocaleService),e=i.get(y.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:Li,children:{label:{name:ys,props:{handleRowColChange:a,tableCreateParams:o}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(wi.id,o),e.close(Li)},onClose:()=>{e.close(Li)}}),!0}},Oe={id:"doc-paragraph-setting.command",type:s.CommandType.COMMAND,handler:async(i,t)=>{var S,I;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=(I=(S=a.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:S.paragraphs)!=null?I:[],d=gt(r,A),u={id:D.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:r}},m=new s.MemoryCursor;m.reset();const h=new s.TextX,f=s.JSONX.getInstance();for(const E of d){const{startIndex:T}=E;h.push({t:s.TextXActionType.RETAIN,len:T-m.cursor});const O={...E.paragraphStyle,...t.paragraph};h.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...E,paragraphStyle:O,startIndex:0}]},coverType:s.UpdateDocsAttributeType.REPLACE}),m.moveCursorTo(T+1)}const g=te(a,c);return u.params.actions=f.editOp(h.serialize(),g),!!o.syncExecuteCommand(u.id,u.params)}},hc=()=>{const i=s.useDependency(D.DocSelectionManagerService),t=s.useDependency(Et),e=Q.useMemo(()=>i.getDocRanges(),[]);return Q.useEffect(()=>{e.length||t.closePanel()},[e]),e},gc=()=>{var r,c;const t=s.useDependency(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),e=hc();if(!t||e.length===0)return[];const n=e[0].segmentId,o=(c=(r=t.getSelfOrHeaderFooterModel(n).getBody())==null?void 0:r.paragraphs)!=null?c:[];return gt(e,o)},mc=(i,t)=>{const e=s.useDependency(s.ICommandService),[n,o]=Q.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(Oe.id,{paragraph:{horizontalAlign:Number(r)}}))]},fc=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentStart,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{indentStart:{v:a}}}))]},pc=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentEnd,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{indentEnd:{v:a}}}))]},Sc=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.indentFirstLine,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{indentFirstLine:{v:a}}}))]},Ic=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.hanging,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{hanging:{v:a}}}))]},Ec=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.spaceAbove,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{spaceAbove:{v:a}}}))]},vc=i=>{const t=s.useDependency(s.ICommandService),[e,n]=Q.useState(()=>{var r;const a=i[0];return a?M.getNumberUnitValue((r=a.paragraphStyle)==null?void 0:r.spaceBelow,0):0});return[e,a=>(n(a),t.executeCommand(Oe.id,{paragraph:{spaceBelow:{v:a}}}))]},Cc=i=>{const t=s.useDependency(s.ICommandService),e=s.useDependency(M.IRenderManagerService),n=s.useDependency(s.IUniverInstanceService),o=Q.useMemo(()=>{var f;const h=n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(h)return(f=e.getRenderById(h==null?void 0:h.getUnitId()))==null?void 0:f.with(D.DocSkeletonManagerService).getSkeleton()},[]),a=Q.useMemo(()=>new N.BehaviorSubject({}),[]),[r,c]=Q.useState(()=>{var f,g;const h=i[0];return h&&(g=(f=h.paragraphStyle)==null?void 0:f.lineSpacing)!=null?g:1}),l=Q.useRef(r),[A,d]=Q.useState(()=>{var f,g;const h=i[0];return h&&(g=(f=h.paragraphStyle)==null?void 0:f.spacingRule)!=null?g:s.SpacingRule.AUTO}),u=async h=>{c(h),a.next({lineSpacing:h,spacingRule:A})},m=async h=>{if(h!==A){let f=l.current;if(h===s.SpacingRule.AT_LEAST){const g=o==null?void 0:o.findNodeByCharIndex(i[0].startIndex),p=g==null?void 0:g.parent,S=p==null?void 0:p.parent;(S==null?void 0:S.contentHeight)!==void 0&&(f=Math.max(S.contentHeight,f))}else f>5&&(f=2);l.current=r,u(f),d(h),a.next({spacingRule:h})}};return Q.useEffect(()=>{const h=a.pipe(yt.filter(f=>!!Object.keys(f).length),yt.bufferTime(16),yt.filter(f=>!!f.length),yt.map(f=>f.reduce((g,p)=>(Object.keys(p).forEach(S=>{g[S]=p[S]}),g),{}))).subscribe(f=>t.executeCommand(Oe.id,{paragraph:{...f}}));return()=>h.unsubscribe()},[]),{lineSpacing:[r,u],spacingRule:[A,m]}},q={paragraphSettingIconList:"univer-paragraph-setting-icon-list",paragraphSettingIconListItem:"univer-paragraph-setting-icon-list-item",paragraphSettingIconListActive:"univer-paragraph-setting-icon-list-active",paragraphSettingTitle:"univer-paragraph-setting-title",paragraphSettingLabel:"univer-paragraph-setting-label",paragraphSettingMtBase:"univer-paragraph-setting-mt-base",paragraphSettingFlexCol:"univer-paragraph-setting-flex-col",paragraphSettingSpaceLine:"univer-paragraph-setting-space-line"},nt=i=>{const{value:t,onChange:e,className:n="",min:o=0,max:a=100,step:r=1}=i,c=Zs.useRef(null);return P.jsx(se.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 Tc(){const i=s.useDependency(s.LocaleService),t=Q.useMemo(()=>[{label:i.t("toolbar.alignLeft"),value:String(s.HorizontalAlign.LEFT),icon:P.jsx(Mo,{})},{label:i.t("toolbar.alignCenter"),value:String(s.HorizontalAlign.CENTER),icon:P.jsx(Oo,{})},{label:i.t("toolbar.alignRight"),value:String(s.HorizontalAlign.RIGHT),icon:P.jsx(Bo,{})},{label:i.t("toolbar.alignJustify"),value:String(s.HorizontalAlign.JUSTIFIED),icon:P.jsx(bo,{})}],[]),e=gc(),[n,o]=mc(e,t[0].value),[a,r]=fc(e),[c,l]=pc(e),[A,d]=Sc(e),[u,m]=Ic(e),[h,f]=Ec(e),[g,p]=vc(e),{lineSpacing:[S,I],spacingRule:[E,T]}=Cc(e),O=Q.useMemo(()=>E===s.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[E,S]);return P.jsxs("div",{className:q.paragraphSetting,children:[P.jsx("div",{className:q.paragraphSettingTitle,children:i.t("doc.paragraphSetting.alignment")}),P.jsx("div",{className:`
|
|
40
40
|
${q.paragraphSettingIconList}
|
|
41
41
|
${q.paragraphSettingMtBase}
|
|
42
42
|
`,children:t.map(v=>P.jsx(se.Tooltip,{title:v.label,placement:"bottom",children:P.jsx("span",{className:en(q.paragraphSettingIconListItem,{[q.paragraphSettingIconListActive]:n===v.value}),onClick:()=>o(v.value),children:v.icon})},v.value))}),P.jsx("div",{className:q.paragraphSettingTitle,children:i.t("doc.paragraphSetting.indentation")}),P.jsxs("div",{children:[P.jsxs("div",{className:q.paragraphSettingFlexCol,children:[P.jsxs("div",{className:q.paragraphSettingLabel,children:[i.t("doc.paragraphSetting.left"),"(px)"]}),P.jsx(nt,{className:q.paragraphSettingMtBase,value:a,onChange:v=>r(v!=null?v:0)})]}),P.jsxs("div",{className:q.paragraphSettingFlexCol,children:[P.jsxs("div",{className:q.paragraphSettingLabel,children:[i.t("doc.paragraphSetting.right"),"(px)"]}),P.jsx(nt,{className:q.paragraphSettingMtBase,value:c,onChange:v=>l(v!=null?v:0)})]}),P.jsxs("div",{className:q.paragraphSettingFlexCol,children:[P.jsxs("div",{className:q.paragraphSettingLabel,children:[i.t("doc.paragraphSetting.firstLine"),"(px)"]}),P.jsx(nt,{className:q.paragraphSettingMtBase,value:A,onChange:v=>d(v!=null?v:0)})]}),P.jsxs("div",{className:q.paragraphSettingFlexCol,children:[P.jsxs("div",{className:q.paragraphSettingLabel,children:[i.t("doc.paragraphSetting.hanging"),"(px)"]}),P.jsx(nt,{className:q.paragraphSettingMtBase,value:u,onChange:v=>m(v!=null?v:0)})]})]}),P.jsx("div",{className:q.paragraphSettingTitle,children:i.t("doc.paragraphSetting.spacing")}),P.jsxs("div",{children:[P.jsxs("div",{className:q.paragraphSettingFlexCol,children:[P.jsxs("div",{className:q.paragraphSettingLabel,children:[i.t("doc.paragraphSetting.before"),"(px)"]}),P.jsx(nt,{className:q.paragraphSettingMtBase,value:h,onChange:v=>f(v!=null?v:0)})]}),P.jsxs("div",{className:q.paragraphSettingFlexCol,children:[P.jsxs("div",{className:q.paragraphSettingLabel,children:[i.t("doc.paragraphSetting.after"),"(px)"]}),P.jsx(nt,{className:q.paragraphSettingMtBase,value:g,onChange:v=>p(v!=null?v:0)})]}),P.jsxs("div",{className:q.paragraphSettingFlexCol,children:[P.jsx("div",{className:q.paragraphSettingLabel,children:i.t("doc.paragraphSetting.lineSpace")}),P.jsxs("div",{className:`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-ui",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer normal ui-plugin-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -59,50 +59,26 @@
|
|
|
59
59
|
"rxjs": ">=7.0.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@univerjs/icons": "^0.2.
|
|
62
|
+
"@univerjs/icons": "^0.2.10",
|
|
63
63
|
"clsx": "^2.1.1",
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/docs": "0.5.
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/engine-
|
|
69
|
-
"@univerjs/
|
|
70
|
-
"@univerjs/
|
|
64
|
+
"@univerjs/core": "0.5.3",
|
|
65
|
+
"@univerjs/design": "0.5.3",
|
|
66
|
+
"@univerjs/docs": "0.5.3",
|
|
67
|
+
"@univerjs/engine-formula": "0.5.3",
|
|
68
|
+
"@univerjs/engine-render": "0.5.3",
|
|
69
|
+
"@univerjs/ui": "0.5.3",
|
|
70
|
+
"@univerjs/drawing": "0.5.3"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"less": "^4.2.1",
|
|
74
74
|
"postcss": "^8.4.49",
|
|
75
75
|
"react": "18.3.1",
|
|
76
76
|
"rxjs": "^7.8.1",
|
|
77
|
-
"tailwindcss": "^3.4.16",
|
|
78
77
|
"typescript": "^5.7.2",
|
|
79
|
-
"vite": "^6.0.
|
|
78
|
+
"vite": "^6.0.6",
|
|
80
79
|
"vitest": "^2.1.8",
|
|
81
|
-
"@univerjs-infra/shared": "0.5.
|
|
82
|
-
"@univerjs/docs-drawing": "0.5.
|
|
83
|
-
},
|
|
84
|
-
"space": {
|
|
85
|
-
".": {
|
|
86
|
-
"import": "./lib/es/index.js",
|
|
87
|
-
"require": "./lib/cjs/index.js",
|
|
88
|
-
"types": "./lib/types/index.d.ts"
|
|
89
|
-
},
|
|
90
|
-
"./*": {
|
|
91
|
-
"import": "./lib/es/*",
|
|
92
|
-
"require": "./lib/cjs/*",
|
|
93
|
-
"types": "./lib/types/index.d.ts"
|
|
94
|
-
},
|
|
95
|
-
"./locale/*": {
|
|
96
|
-
"import": "./lib/es/locale/*.js",
|
|
97
|
-
"require": "./lib/cjs/locale/*.js",
|
|
98
|
-
"types": "./lib/types/locale/*.d.ts"
|
|
99
|
-
},
|
|
100
|
-
"./facade": {
|
|
101
|
-
"import": "./lib/es/facade.js",
|
|
102
|
-
"require": "./lib/cjs/facade.js",
|
|
103
|
-
"types": "./lib/types/facade/index.d.ts"
|
|
104
|
-
},
|
|
105
|
-
"./lib/*": "./lib/*"
|
|
80
|
+
"@univerjs-infra/shared": "0.5.3",
|
|
81
|
+
"@univerjs/docs-drawing": "0.5.3"
|
|
106
82
|
},
|
|
107
83
|
"scripts": {
|
|
108
84
|
"test": "vitest run",
|