@univerjs/sheets-ui 0.5.5-nightly.202501201606 → 0.5.5-nightly.202501210404

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 CHANGED
@@ -9,7 +9,7 @@
9
9
  `,g={...u,body:{dataStream:h,textRuns:c.textRuns,paragraphs:ji(h)}};d==null||d.reset(g),o=d==null?void 0:d.getSnapshot(),r=c.dataStream}else r=vh(i.innerHTML.replace(/[\r\n]/g,""));return{cellText:r,cellRichStyle:o}}_generateDocumentDataModelSnapshot(i){var l;const e=this._getCurrentSkeleton();if(e==null)return null;const{skeleton:t}=e,r=(l=t.getBlankCellDocumentModel())==null?void 0:l.documentModel,s={...r==null?void 0:r.getSnapshot(),...i};return r==null||r.reset(s),r==null?void 0:r.getSnapshot()}process(i,e,t,r){var o,s,l;for(const c of e)if(c.nodeName.toLowerCase()==="table")r.push({index:((o=t==null?void 0:t.paragraphs)==null?void 0:o.length)||0});else if(c.nodeType===Node.TEXT_NODE){if(((s=c.nodeValue)==null?void 0:s.trim())==="")continue;const d=(l=c.nodeValue)==null?void 0:l.replace(/[\r\n]/g,"");let u;i&&this._styleCache.has(i)&&(u=this._styleCache.get(i));const h={dataStream:"",textRuns:[]};t.dataStream+=d,h.dataStream+=d,u&&Object.getOwnPropertyNames(u).length&&(t.textRuns.push({st:t.dataStream.length-d.length,ed:t.dataStream.length,ts:u}),h.textRuns.push({st:t.dataStream.length-d.length,ed:t.dataStream.length,ts:u}))}else{if(a.skipParseTagNames.includes(c.nodeName.toLowerCase()))continue;if(c.nodeName.toLowerCase()==="br")t.paragraphs||(t.paragraphs=[]),t.paragraphs.push({startIndex:t.dataStream.length}),t.dataStream+="\r";else if(c.nodeType===Node.ELEMENT_NODE){if(c.nodeName==="STYLE")continue;const d=c,u=this._processBeforeLink(d,{body:t}),h=i?this._styleCache.get(i):{},g=this._styleRules.find(({filter:v})=>ia(c,v)),S=g?g.getStyle(c):$r(c);this._styleCache.set(c,{...h,...S});const{childNodes:f}=c;this.process(c,f,t,r);const p=this._afterProcessRules.find(({filter:v})=>ia(c,v));p&&p.handler(t,c),this._processAfterLink(d,{body:t},u)}}}_processBeforeLink(i,e){return e.body.dataStream.length}_processAfterLink(i,e,t){var s,l;const r=e.body,o=i;o.tagName.toUpperCase()==="A"&&(r.customRanges=(s=r.customRanges)!=null?s:[],r.customRanges.push({startIndex:t,endIndex:r.dataStream.length-1,rangeId:(l=o.dataset.rangeid)!=null?l:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o.href}}))}dispose(){this._dom=null,this._styleCache.clear(),this._styleMap.clear()}};R(bi,"_pluginList",[]);let En=bi;function fh(n){const i=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,e=n.matchAll(i);if(!e)return{rowProperties:[],rowCount:0};const r=Array.from(e).map(o=>ml(o[1])).map(o=>{if(!o.height){const s=o.style,l=s&&s.match(/height\s*:\s*(\d+(\.\d+)?)px/);o.height=`${l?Number.parseInt(l[1],10):a.DEFAULT_WORKSHEET_ROW_HEIGHT}`}return o});return{rowProperties:r,rowCount:r.length}}function oa(n){const i={};return n.split(";").forEach(t=>{const[r,o]=t.split(":");i[r]=o}),i}function ml(n){if(!n)return{};const i={},e=/([\w-]+)\s*=\s*(?:(['"])([^'"]*)\2|(\S+))/g;let t;for(;(t=e.exec(n))!==null;){const[,r,,o,s]=t,l=o!==void 0?o:s;i[r]=l}return i}function ph(n){const i=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,e=n.match(i),t=/<col([\s\S]*?)>/g;let r;if(e!=null&&e[2]?r=e[2].matchAll(t):r=n.matchAll(t),!r)return null;const o=Array.from(r).map(l=>ml(l[1])),s=[];return o.forEach(l=>{const c=Number(l.span);if(c)for(let d=0;d<c;d++){const u={...l};delete u.span,s.push(u)}else s.push(l)}),s}function vh(n){const i={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":'"',"&#39;":"'","&nbsp;":" "};return n.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g,e=>i[e])}function sa(n,i){if(!n||!i)return null;const e=new RegExp(`(${i}\\s*:\\s*[^;]+);`,"i"),t=n.match(e);return t?t[1]:null}function Ch(n,i,e,t){const{rowSpan:r,colSpan:o,rowIndex:s,colSetValueIndex:l}=t;for(let c=s;c<s+r;c++)for(let d=l;d<l+o;d++)c===s&&d===l?n.setValue(c,d,{...e,style:i}):n.setValue(c,d,{style:i})}const _h={name:"univer-doc-paste-plugin-lark",checkPasteType(n){return/lark-record-clipboard/i.test(n)},stylesRules:[{filter:["s"],getStyle(n){const i=$r(n);return{st:{s:a.BooleanNumber.TRUE},...i}}}],afterProcessRules:[{filter(n){return n.tagName==="DIV"&&/ace-line/i.test(n.className)},handler(n){n.paragraphs==null&&(n.paragraphs=[]),n.paragraphs.push({startIndex:n.dataStream.length}),n.dataStream+="\r"}}]},Ih={name:"univer-doc-paste-plugin-univer",checkPasteType(n){return/UniverNormal/i.test(n)},stylesRules:[],afterProcessRules:[{filter(n){return n.tagName==="P"&&/UniverNormal/i.test(n.className)},handler(n,i){n.paragraphs==null&&(n.paragraphs=[]);const e={startIndex:n.dataStream.length},t=hl(i);t&&(e.paragraphStyle=t),n.paragraphs.push(e),n.dataStream+="\r"}}]},bh={name:"univer-doc-paste-plugin-word",checkPasteType(n){return/word|mso/i.test(n)},stylesRules:[{filter:["b"],getStyle(n){const i=$r(n);return{bl:a.BooleanNumber.TRUE,...i}}}],afterProcessRules:[{filter(n){return n.tagName==="P"&&/mso/i.test(n.className)},handler(n,i){n.paragraphs==null&&(n.paragraphs=[]);const e={startIndex:n.dataStream.length},t=hl(i);t&&(e.paragraphStyle=t),n.paragraphs.push(e),n.dataStream+="\r"}}]};var vt=(n=>(n.COPY="COPY",n.CUT="CUT",n))(vt||{});function Rh(n,i,e,t,r){const o=e.map(d=>{var u;return(u=d.onCopyRow)==null?void 0:u.call(d,n)}).filter(d=>!!d),s=fs(o),l=ps(s),c=i.map(d=>{if(!r.has(`${n}-${d}`)){const u=t.getValue(n,d);if(u!=null&&u.rowSpan&&(u!=null&&u.colSpan))for(let h=n;h<n+u.rowSpan;h++)for(let g=d;g<d+u.colSpan;g++)r.add(`${h}-${g}`);return Eh(n,d,e,t)}return null}).filter(d=>!!d).join("");return`<tr${l}>${c}</tr>`}function Eh(n,i,e,t){const r=t.getValue(n,i),o=e.map(d=>{var u;return(u=d.onCopyCellStyle)==null?void 0:u.call(d,n,i,r==null?void 0:r.rowSpan,r==null?void 0:r.colSpan)}).filter(d=>!!d),s=fs(o),l=ps(s),c=e.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,n,i))||""},"");return`<td${l}>${c}</td>`}function Th(n,i){return`<colgroup>${n.map(t=>{const r=i.map(l=>{var c;return(c=l.onCopyColumn)==null?void 0:c.call(l,t)}).filter(l=>!!l),o=fs(r);return`<col ${ps(o)}>`}).join("")}</colgroup>`}function fs(n){return n.reduce((i,e)=>(Object.keys(e).forEach(r=>{i[r]?i[r]+=`;${e[r]}`:i[r]=e[r]}),i),{})}function ps(n){return Object.keys(n).reduce((i,e)=>(i+=` ${e}="${n[e]}"`,i),"")}class wh{convert(i,e,t){const{cols:r,rows:o}=e;if(!r.length)return"";const s=Th(r,t),l=[],c=new Set;return o.forEach(u=>{l.push(Rh(u,r,t,i,c))}),`<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${s}
10
10
  <tbody>${l.join("")}</tbody></table>`}}const yh=(n,i,e=!1)=>{const t=h=>h.endRow-h.startRow+1,r=h=>h.endColumn-h.startColumn+1,o=t(i)%t(n),s=r(i)%r(n),l={startRow:0,endRow:t(n)-1,startColumn:0,endColumn:r(n)-1},c=Math.floor(t(i)/t(n)),d=Math.floor(r(i)/r(n)),u=[];if(!o&&!s)for(let h=1;h<=c;h++)for(let g=1;g<=d;g++){const S=t(n)*(h-1),f=r(n)*(g-1),p={startRow:S+i.startRow,endRow:S+i.startRow,startColumn:f+i.startColumn,endColumn:f+i.startColumn};u.push({repeatRelativeRange:l,startRange:p})}else if(!o&&s&&!e)for(let h=1;h<=c;h++){const g=t(n)*(h-1),S=0,f={startRow:g+i.startRow,endRow:g+i.startRow,startColumn:S+i.startColumn,endColumn:S+i.startColumn};u.push({repeatRelativeRange:l,startRange:f})}else if(o&&!s&&!e)for(let h=1;h<=d;h++){const S=r(n)*(h-1),f={startRow:0+i.startRow,endRow:0+i.startRow,startColumn:S+i.startColumn,endColumn:S+i.startColumn};u.push({repeatRelativeRange:l,startRange:f})}else{const h={startRow:i.startRow,endRow:i.startRow,startColumn:i.startColumn,endColumn:i.startColumn};u.push({startRange:h,repeatRelativeRange:l})}return u};async function Mh(n){return n?/<td[^>]*class=".*?xl.*?"[^>]*>.*?<\/td>/.test(n):!1}function Ph(...n){if(n.length===1)return n[0];const i=new a.ObjectMatrix;return n.forEach(e=>{e&&new a.ObjectMatrix(e).forValue((r,o,s)=>{i.setValue(r,o,{...i.getValue(r,o),...s})})}),i.getMatrix()}function Oh(n,i){return n.id===i.id&&n.params.unitId===i.params.unitId&&n.params.subUnitId===i.params.subUnitId}function Uo(n){const i=[];for(let e=0;e<n.length;){let t=1;if(n[e].id===m.SetRangeValuesMutation.id){const r=n[e],o=[r];for(;e+t<n.length&&Oh(r,n[e+t]);)o.push(n[e+t]),t+=1;const s=Ph(...o.map(l=>l.params.cellValue||{}));i.push({...r,params:{...r.params,cellValue:s}})}else i.push(n[e]);e+=t}return i}function zi(n,i){const{startRow:e,endRow:t,startColumn:r,endColumn:o}=n;for(let s=e;s<=t;s++)for(let l=r;l<=o;l++)if(i.rows.includes(s)&&i.cols.includes(l))return!0}function aa(n,i){const{startRow:e,endRow:t,startColumn:r,endColumn:o}=i;for(let s=e;s<=t;s++)if(!n.rows.includes(s))return!1;for(let s=r;s<=o;s++)if(!n.cols.includes(s))return!1;return!0}function xh(n){const i=n.trim().split(`
11
11
  `);let e="<table>";return i.forEach(t=>{const r=t.split(" ");e+="<tr>",r.forEach(o=>{e+=`<td>${o}</td>`}),e+="</tr>"}),e+="</table>",e}var Ah=Object.defineProperty,Nh=Object.getOwnPropertyDescriptor,Dh=(n,i,e,t)=>{for(var r=t>1?void 0:t?Nh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Ah(i,e,r),r},Oe=(n,i)=>(e,t)=>i(e,t,n);const ge={DEFAULT_COPY:"default-copy",DEFAULT_PASTE:"default-paste",SPECIAL_PASTE_VALUE:"special-paste-value",SPECIAL_PASTE_FORMAT:"special-paste-format",SPECIAL_PASTE_COL_WIDTH:"special-paste-col-width",SPECIAL_PASTE_BESIDES_BORDER:"special-paste-besides-border",SPECIAL_PASTE_FORMULA:"special-paste-formula"};En.use(bh);En.use(_h);En.use(Ih);const Ge=a.createIdentifier("sheet.clipboard-service");exports.SheetClipboardService=class extends a.Disposable{constructor(e,t,r,o,s,l,c,d,u,h,g,S,f,p){super();R(this,"_clipboardHooks",[]);R(this,"_clipboardHooks$",new O.BehaviorSubject([]));R(this,"clipboardHooks$",this._clipboardHooks$.asObservable());R(this,"_htmlToUSM");R(this,"_usmToHtml");R(this,"_copyContentCache");R(this,"_copyMarkId",null);R(this,"_pasteOptionsCache$",new O.BehaviorSubject(null));R(this,"pasteOptionsCache$",this._pasteOptionsCache$.asObservable());R(this,"_showMenu$",new O.Subject);R(this,"showMenu$",this._showMenu$.asObservable());this._logService=e,this._univerInstanceService=t,this._selectionManagerService=r,this._clipboardInterfaceService=o,this._undoRedoService=s,this._commandService=l,this._markSelectionService=c,this._notificationService=d,this._platformService=u,this._renderManagerService=h,this._themeService=g,this._localeService=S,this._errorService=f,this._injector=p,this._htmlToUSM=new En({getCurrentSkeleton:()=>{var v;return(v=this._renderManagerService.withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService))==null?void 0:v.getCurrent()}}),this._usmToHtml=new wh,this._copyContentCache=new mh,this.disposeWithMe(this._htmlToUSM),this._initUnitDisposed()}setShowMenu(e){this._showMenu$.next(e)}copyContentCache(){return this._copyContentCache}generateCopyContent(e,t,r){const o=this._clipboardHooks;o.forEach(l=>{var c;return(c=l.onBeforeCopy)==null?void 0:c.call(l,e,t,r)});const s=this._generateCopyContent(e,t,r,o);return o.forEach(l=>{var c;return(c=l.onAfterCopy)==null?void 0:c.call(l)}),s}async copy(e=vt.COPY){const t=this._selectionManagerService.getCurrentLastSelection();if(!t)return!1;const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),o=r.getActiveSheet();if(!o)return!1;const s=this.generateCopyContent(r.getUnitId(),o.getSheetId(),t.range);if(!s)return!1;const{html:l,plain:c,matrixFragment:d,copyId:u,discreteRange:h}=s;this._copyContentCache.set(u,{unitId:r.getUnitId(),subUnitId:o.getSheetId(),range:h,matrix:d,copyType:e}),await this._clipboardInterfaceService.write(c,l),this._markSelectionService.removeAllShapes();const g=ul(this._themeService);return this._copyMarkId=this._markSelectionService.addShape({...t,style:g}),!0}async cut(){return this.copy(vt.CUT)}async paste(e,t=ge.DEFAULT_PASTE){const r=e.types,o=r.indexOf(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(l=>l&&l.text()):"",s=r.indexOf(E.HTML_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(E.HTML_CLIPBOARD_MIME_TYPE).then(l=>l&&l.text()):"";return s?(this._platformService.isWindows&&await Mh(s)&&this._notificationService.show({type:"warning",title:this._localeService.t("clipboard.shortCutNotify.title"),content:this._localeService.t("clipboard.shortCutNotify.useShortCutInstead")}),this._pasteHTML(s,t)):o?this._pastePlainText(o,t):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}legacyPaste(e,t){return e?this._pasteHTML(e,ge.DEFAULT_PASTE):t?/[\n\t]/.test(t)?this._pasteHTML(xh(t),ge.DEFAULT_PASTE):this._pastePlainText(t,ge.DEFAULT_PASTE):Promise.resolve(!1)}rePasteWithPasteType(e){const t=this._pasteOptionsCache$.getValue();if(!t)return!1;const r=this._injector.get(a.IUndoRedoService),o=r.pitchTopUndoElement();o&&a.sequenceExecute(o.undoMutations,this._commandService)&&r.popUndoToRedo();const{cellMatrix:s,rowProperties:l=[],colProperties:c=[],source:d,target:u}=t;return this._pasteUSM({cellMatrix:s,colProperties:c,rowProperties:l},u,ge[e],d),!0}updatePasteOptionsCache(e){this._pasteOptionsCache$.next(e)}addClipboardHook(e){if(this._clipboardHooks.findIndex(r=>r.id===e.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",e.id),{dispose:()=>{}};const t=this._clipboardHooks.findIndex(r=>{const o=r.priority||0;return(e.priority||0)<o});return this._clipboardHooks.splice(t!==-1?t:this._clipboardHooks.length,0,e),this._notifyClipboardHook(),a.toDisposable(()=>{const r=this._clipboardHooks.indexOf(e);r>-1&&(this._clipboardHooks.splice(r,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_generateCopyContent(e,t,r,o){const s=this._univerInstanceService.getUniverSheetInstance(e),l=s==null?void 0:s.getSheetBySheetId(t);if(!s||!l)return null;const c=o.reduce((M,w)=>{var x;const P=(x=w.getFilteredOutRows)==null?void 0:x.call(w,r);return P==null||P.forEach(A=>M.add(A)),M},new Set),{startColumn:d,startRow:u,endColumn:h,endRow:g}=r,S=l.getMatrixWithMergedCells(u,d,g,h,a.CellModeEnum.Both),f=new a.ObjectMatrix;let p=u;const v=new a.ObjectMatrix,C={rows:[],cols:[]};for(let M=u;M<=g;M++)if(!c.has(M)){C.rows.push(M);for(let w=d;w<=h;w++){const P=S.getValue(M,w);if(P){const x=a.Tools.deepClone(P);v.setValue(p-u,w-d,{...Un(),...x}),delete x.displayV,f.setValue(p-u,w-d,{...Un(),...x})}else v.setValue(p-u,w-d,Un()),f.setValue(p-u,w-d,Un()),S.setValue(M,w,Un())}p+=1}for(let M=d;M<=h;M++)C.cols.push(M);let I=this._usmToHtml.convert(S,C,o);const b=gl(v),T=uh();return I=I.replace(/(<[a-z]+)/,(M,w)=>`${w} data-copy-id="${T}"`),{copyId:T,plain:b,html:I,matrixFragment:f,discreteRange:C}}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _pastePlainText(e,t){const r=this._getPastingTarget();if(!r.subUnitId||!r.selection)return!1;const o=this._injector.invoke(f=>hn(r.selection.range,f,r.unitId,r.subUnitId));if(!o)return!1;const{unitId:s,subUnitId:l}=r,c=this._clipboardHooks,d=[];if(c.some(f=>{var p;return d.push(f)&&((p=f.onBeforePaste)==null?void 0:p.call(f,{unitId:s,subUnitId:l,range:o}))===!1}))return d.forEach(f=>{var p;return(p=f.onAfterPaste)==null?void 0:p.call(f,!1)}),!1;const h=[],g=[];d.forEach(f=>{var v;const p=(v=f.onPastePlainText)==null?void 0:v.call(f,{unitId:s,subUnitId:l,range:o},e,{pasteType:t});p&&(h.push(...p.redos),g.push(...p.undos))});const S=h.every(f=>this._commandService.executeCommand(f.id,f.params));return S&&this._undoRedoService.pushUndoRedo({unitID:this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),undoMutations:g,redoMutations:h}),S}async _pasteHTML(e,t){const r=hh(e);return r&&this._copyContentCache.get(r)?this._pasteInternal(r,t):this._pasteExternal(e,t)}async _pasteExternal(e,t){var h;const{rowProperties:r,colProperties:o,cellMatrix:s}=this._htmlToUSM.convert(e);if(!s)return!1;const l=this._getPastedRange(s);if(!l)return!1;const c=(h=this._univerInstanceService.getUniverSheetInstance(l.unitId))==null?void 0:h.getSheetBySheetId(l.subUnitId);if(!c)return!1;const d=c==null?void 0:c.getMergeData();return d.length&&d.some(S=>zi(S,l.pastedRange)&&!aa(l.pastedRange,S))?(this._errorService.emit(this._localeService.t("clipboard.paste.overlappingMergedCells")),!1):this._pasteUSM({rowProperties:r,colProperties:o,cellMatrix:s},l,t)}async _pasteInternal(e,t){var w,P;const r=a.Tools.deepClone(this._copyContentCache.get(e)),{range:o,matrix:s,unitId:l,subUnitId:c}=r||{};if(!s||!r||!o||!l||!c||!s||!r)return!1;const d=(w=this._univerInstanceService.getUniverSheetInstance(l))==null?void 0:w.getStyles();s.forValue((x,A,N)=>{if(typeof N.s=="string"){const D=a.Tools.deepClone(N);D.s=d==null?void 0:d.getStyleByCell(N),s.setValue(x,A,D)}if(N.colSpan||N.rowSpan)for(let D=0;D<N.rowSpan;D++)for(let H=0;H<N.colSpan;H++){if(D===0&&H===0)continue;const U=x+D,k=A+H;s.setValue(U,k,{s:d==null?void 0:d.getStyleByCell(N)})}});const u=this._getPastedRange(s);if(!u)return!1;const h=(P=this._univerInstanceService.getUniverSheetInstance(u.unitId))==null?void 0:P.getSheetBySheetId(u.subUnitId);if(!h)return!1;const g=h==null?void 0:h.getMergeData();if(g&&g.some(A=>zi(A,u.pastedRange)&&!aa(u.pastedRange,A)))return this._errorService.emit(this._localeService.t("clipboard.paste.overlappingMergedCells")),!1;const S=this._univerInstanceService.getUnit(l);if(!S)return!1;const f=S.getSheetBySheetId(c);if(!f)return!1;const p=f.getColumnManager(),v=f.getRowManager(),C=f.getConfig().defaultColumnWidth,I=f.getConfig().defaultRowHeight,b=[],T=[];if(o.cols.forEach(x=>{const A=p.getColumnOrCreate(x);b.push({width:`${A.w||C}`})}),o.rows.forEach(x=>{const A=v.getRowOrCreate(x),{ah:N=I,h:D=I}=A,H=Math.max(N,D);T.push({height:`${H}`})}),r.copyType===vt.CUT){const x=u.pastedRange.rows[0],A=o.rows[o.rows.length-1]-o.rows[0]+x;u.pastedRange.rows=Array.from(new Array(A+1).keys()).slice(x)}const M=this._pasteUSM({cellMatrix:s,colProperties:b,rowProperties:T},u,t,{range:o,unitId:r.unitId,subUnitId:r.subUnitId,copyType:r.copyType,copyId:e});return r.copyType===vt.CUT&&(this._copyContentCache.set(e,{...r,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),M}_pasteUSM(e,t,r,o){const{rowProperties:s,colProperties:l,cellMatrix:c}=e,{unitId:d,subUnitId:u,pastedRange:h}=t,g=h.cols.length,S=this._clipboardHooks,f=[];if(S.some(P=>{var x;return f.push(P)&&((x=P.onBeforePaste)==null?void 0:x.call(P,{unitId:d,subUnitId:u,range:h}))===!1}))return f.forEach(P=>{var x;return(x=P.onAfterPaste)==null?void 0:x.call(P,!1)}),!1;if(!c)return!1;const v=o?{unitId:o.unitId,subUnitId:o.subUnitId,range:o.range}:null,C={copyType:(o==null?void 0:o.copyType)||vt.COPY,copyId:o==null?void 0:o.copyId,pasteType:r};let I=[],b=[];const T=f.filter(P=>!P.specialPasteInfo&&P.id!==ge.DEFAULT_PASTE||r===P.id);T.forEach(P=>{var N,D,H;if(s){const U=(N=P.onPasteRows)==null?void 0:N.call(P,{range:h,unitId:d,subUnitId:u},s,{pasteType:r});U&&(I.push(...U.redos),b.push(...U.undos))}const x=(D=P.onPasteColumns)==null?void 0:D.call(P,{range:h,unitId:d,subUnitId:u},l||new Array(g).map(()=>({})),{pasteType:r});x&&(I.push(...x.redos),b.push(...x.undos));const A=(H=P.onPasteCells)==null?void 0:H.call(P,v,{range:h,unitId:d,subUnitId:u},c,C);A&&(I.push(...A.redos),b.push(...A.undos))});const M=this._getSetSelectionOperation(d,u,h,c,r);M&&I.push(M),I=Uo(I),b=Uo(b),b.push({id:m.SetWorksheetActiveOperation.id,params:{unitId:t.unitId,subUnitId:t.subUnitId}}),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:b,redoMutationsInfo:I});const w=I.every(P=>this._commandService.syncExecuteCommand(P.id,P.params));return w&&(this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:b,redoMutations:I}),this.updatePasteOptionsCache({target:{pastedRange:h,unitId:d,subUnitId:u},cellMatrix:c,rowProperties:s,colProperties:l,pasteType:r,source:o}),this.setShowMenu(!0)),T.forEach(P=>{var x;return(x=P.onAfterPaste)==null?void 0:x.call(P,w)}),w}_getSetSelectionOperation(e,t,r,o,s){var M;const l=(M=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:M.getSheetBySheetId(t);if(!l)return null;const{rows:c,cols:d}=r,u=c[0],h=d[0],g=c[c.length-1],S=d[d.length-1],f={startRow:u,endRow:u,startColumn:h,endColumn:h},p=m.getPrimaryForRange(f,l),v=o.getValue(0,0),C=(v==null?void 0:v.rowSpan)||1,I=(v==null?void 0:v.colSpan)||1;if((s===ge.DEFAULT_PASTE||s===ge.SPECIAL_PASTE_BESIDES_BORDER||s===ge.SPECIAL_PASTE_FORMAT)&&(C>1||I>1)){const w={startRow:u,endRow:u+C-1,startColumn:h,endColumn:h+I-1};p.startRow=w.startRow,p.endRow=w.endRow,p.startColumn=w.startColumn,p.endColumn=w.endColumn,p.isMerged=!0,p.isMergedMainCell=!0}const T={unitId:e,subUnitId:t,selections:[{range:{startRow:u,endRow:g,startColumn:h,endColumn:S},primary:p,style:null}]};return{id:m.SetSelectionsOperation.id,params:T}}_getPastingTarget(){const e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),t=e.getActiveSheet(),r=this._selectionManagerService.getCurrentLastSelection();return{unitId:e.getUnitId(),subUnitId:t==null?void 0:t.getSheetId(),selection:r}}_transformPastedData(e,t,r){const o=this._getPastingTarget(),{selection:s,unitId:l,subUnitId:c}=o;if(!c||!s)return null;const d=this._injector.invoke(D=>hn(s.range,D,l,c));if(!d)return null;const{ranges:[u],mapFunc:h}=Gt([d]),{startRow:g,startColumn:S,endRow:f,endColumn:p}=u,v=f-g+1,C=p-S+1,I=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),b=I==null?void 0:I.getActiveSheet();if(!b)return null;const M=b.getMergeData().filter(D=>d.rows.includes(D.startRow)&&d.cols.includes(D.startColumn)),w=M[0];let P=0,x=0,A=0,N=0;if(w&&(P=w.startRow,x=w.startColumn,A=w.endRow,N=w.endColumn),v%e===0&&C%t===0)if(M.length>0&&(v!==e||C!==t))if(P===d.rows[0]&&x===d.cols[0]&&A===d.rows[v-1]&&N===d.cols[C-1])if(Wh(r))for(let H=0;H<v;H++)for(let U=0;U<C;U++){const k=r.getValue(H%e,U%t);k&&r.setValue(H,U,k)}else r.forValue((H,U,k)=>{k.s=null,delete k.colSpan,delete k.rowSpan});else for(let D=0;D<v;D++)for(let H=0;H<C;H++){const U=r.getValue(D%e,H%t);U&&r.setValue(D,H,U)}else for(let D=0;D<v;D++)for(let H=0;H<C;H++){const U=r.getValue(D%e,H%t);U&&r.setValue(D,H,U)}else if(M.length>0){const{row:D,col:H}=h(g,S);if(this._topLeftCellsMatch(e,t,{topRow:D,leftCol:H})){const k=this._expandOrShrinkRowsCols(l,c,d,t,e);d.rows=k.rows,d.cols=k.cols}else{if(f>w.endRow||p>w.endColumn)return null;r.forValue((k,L,F)=>{F.s=null,delete F.colSpan,delete F.rowSpan})}}else{const D=this._expandOrShrinkRowsCols(l,c,d,t,e);d.rows=D.rows,d.cols=D.cols}return{pastedRange:d,unitId:l,subUnitId:c}}_getPastedRange(e){var b;const t=this._getPastingTarget(),{selection:r,unitId:o,subUnitId:s}=t;if(!s||!r)return null;const l=this._injector.invoke(T=>hn(r.range,T,o,s));if(!l)return null;const{startColumn:c,endColumn:d,startRow:u,endRow:h}=e.getDataRange(),g=h-u+1,S=d-c+1;if(g<=0||S<=0)return null;const f=l.rows.length,p=l.cols.length,v=(b=this._univerInstanceService.getUniverSheetInstance(o))==null?void 0:b.getSheetBySheetId(s);if(!v)return null;const C=v==null?void 0:v.getMergeData();if(f%g===0&&p%S===0&&!(C==null?void 0:C.some(M=>zi(M,l)))){for(let M=0;M<f;M++)for(let w=0;w<p;w++){const P=e.getValue(M%g,w%S);P&&e.setValue(M,w,P)}return{pastedRange:l,unitId:o,subUnitId:s}}const I=this._expandOrShrinkRowsCols(o,s,l,S,g);return l.rows=I.rows,l.cols=I.cols,{pastedRange:l,unitId:o,subUnitId:s}}_expandOrShrinkRowsCols(e,t,r,o,s){const{rows:l,cols:c}=r,d=this._univerInstanceService.getUniverSheetInstance(e),u=d==null?void 0:d.getSheetBySheetId(t);let h,g;if(l.length>=s)h=l.slice(0,s);else{h=l.slice(0);let S=l[l.length-1]+1;for(;h.length<s;)u.getRowFiltered(S)||h.push(S),S++}if(c.length>=o)g=c.slice(0,o);else{g=c.slice(0);let S=c[c.length-1]+1;for(;g.length<o;)g.push(S),S++}return{rows:h,cols:g}}_topLeftCellsMatch(e,t,r){const o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();if(!s)return!1;const{topRow:l,leftCol:c}=r,d=kh(l+e-1,c,c+t-1,s),u=Vh(c+t-1,l,l+e-1,s);return!d&&!u}removeMarkSelection(){this._copyMarkId&&(this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null)}_initUnitDisposed(){this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{e&&this.copyContentCache().clearWithUnitId(e.getUnitId())}))}disposePasteOptionsCache(){this.setShowMenu(!1),this.updatePasteOptionsCache(null)}};exports.SheetClipboardService=Dh([Oe(0,a.ILogService),Oe(1,a.IUniverInstanceService),Oe(2,a.Inject(m.SheetsSelectionsService)),Oe(3,E.IClipboardInterfaceService),Oe(4,a.IUndoRedoService),Oe(5,a.ICommandService),Oe(6,Zt),Oe(7,E.INotificationService),Oe(8,E.IPlatformService),Oe(9,y.IRenderManagerService),Oe(10,a.Inject(a.ThemeService)),Oe(11,a.Inject(a.LocaleService)),Oe(12,a.Inject(a.ErrorService)),Oe(13,a.Inject(a.Injector))],exports.SheetClipboardService);function gl(n){let i="";const e=n.getLength();return n.forRow((t,r)=>{const o=[];r.forEach(s=>{const l=n.getValue(t,s);if(l){const c=Hh(l);o.push(c)}}),i+=o.join(" "),t!==e-1&&(i+=`
12
- `)}),i}function Hh(n){return a.isNotNullOrUndefined(n.displayV)?n.displayV:a.extractPureTextFromCell(n)}function kh(n,i,e,t){return t.getMergeData().some(r=>r.startRow<=n&&n<r.endRow&&i<=r.startColumn&&r.startColumn<=e)}function Vh(n,i,e,t){return t.getMergeData().some(r=>r.startColumn<=n&&n<r.endColumn&&i<=r.startRow&&r.startRow<=e)}function Wh(n){let i=0;return n.forValue((e,t,r)=>{if(r&&i++,i>1)return!1}),i>1}function Un(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const vs=998,ze={id:E.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:vs,preconditions:Ss,handler:async n=>n.get(Ge).copy()},Cs={id:E.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:vs,preconditions:Ss,handler:async n=>n.get(Ge).cut()},Xe={id:E.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:vs,preconditions:Ss,handler:async(n,i)=>{const t=await n.get(E.IClipboardInterfaceService).read(),r=n.get(Ge);return t.length!==0?r.paste(t[0],i==null?void 0:i.value):!1}},ei={id:E.SheetPasteShortKeyCommandName,type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(Ge),{htmlContent:t,textContent:r}=i;return e.legacyPaste(t,r),!0}},mn={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_VALUE})},gn={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_FORMAT})},Ht={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},Sn={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},Sl={id:"sheet.command.optional-paste",type:a.CommandType.COMMAND,handler:async(n,{type:i})=>n.get(Ge).rePasteWithPasteType(i)},mr={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleRows();if(Za(l,e)){const d=n.get(E.IConfirmService),u=n.get(a.LocaleService);return await d.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetRowHiddenCommand.id),!0}},gr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleCols();if(Ka(l,e)){const d=n.get(E.IConfirmService),u=n.get(a.LocaleService);return await d.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetColHiddenCommand.id),!0}},Kt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatBoldCommand.id):i.executeCommand(m.SetBoldCommand.id)}},qt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatItalicCommand.id):i.executeCommand(m.SetItalicCommand.id)}},Qt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatUnderlineCommand.id):i.executeCommand(m.SetUnderlineCommand.id)}},Jt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatStrikethroughCommand.id):i.executeCommand(m.SetStrikeThroughCommand.id)}},_s={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatSubscriptCommand.id):!1}},Is={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatSuperscriptCommand.id):!1}},Sr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontSizeCommand.id,i):e.executeCommand(m.SetFontSizeCommand.id,i)}},fr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontFamilyCommand.id,i):e.executeCommand(m.SetFontFamilyCommand.id,i)}},Tn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatTextColorCommand.id,i):e.executeCommand(m.SetTextColorCommand.id,i)}},bs={type:a.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const i=n.get(a.ICommandService),t=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),r=n.get(a.ThemeService);return t?i.executeCommand(J.SetInlineFormatTextColorCommand.id,{value:null}):i.executeCommand(m.SetTextColorCommand.id,{value:r.getCurrentTheme().textColor})}};var Uh=Object.defineProperty,Lh=Object.getOwnPropertyDescriptor,Bh=(n,i,e,t)=>{for(var r=t>1?void 0:t?Lh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Uh(i,e,r),r},sn=(n,i)=>(e,t)=>i(e,t,n),De=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(De||{});const tt=a.createIdentifier("univer.format-painter-service");let ti=class extends a.Disposable{constructor(i,e,t,r,o,s){super();R(this,"status$");R(this,"_selectionFormat");R(this,"_markId",null);R(this,"_status$");R(this,"_defaultHook",null);R(this,"_extendHooks",[]);this._selectionManagerService=i,this._themeService=e,this._markSelectionService=t,this._logService=r,this._commandService=o,this._undoRedoService=s,this._status$=new O.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}addHook(i){var e,t,r;i.isDefaultHook&&((e=i.priority)!=null?e:0)>((r=(t=this._defaultHook)==null?void 0:t.priority)!=null?r:-1)?this._defaultHook=i:(this._extendHooks.push(i),this._extendHooks.sort((o,s)=>(o.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(i){this._updateRangeMark(i),this._status$.next(i),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(i)})}getStatus(){return this._status$.getValue()}setSelectionFormat(i){this._selectionFormat=i}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(i,e,t){const r=this.getHooks(),o=[],s=[];r.forEach(c=>{if(c.onApply!==void 0){const d=c.onApply(i,e,t,this._selectionFormat);d&&(o.push(...d.redos),s.push(...d.undos))}});for(const c of r)if(c.onBeforeApply!==void 0&&!c.onBeforeApply({unitId:i,subUnitId:e,range:t,redoMutationsInfo:o,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:o});const l=o.every(c=>this._commandService.executeCommand(c.id,c.params));return l&&this._undoRedoService.pushUndoRedo({unitID:i,undoMutations:s,redoMutations:o}),l}_updateRangeMark(i){if(this._markSelectionService.removeAllShapes(),i!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=ul(this._themeService);i===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};ti=Bh([sn(0,a.Inject(m.SheetsSelectionsService)),sn(1,a.Inject(a.ThemeService)),sn(2,Zt),sn(3,a.ILogService),sn(4,a.ICommandService),sn(5,a.IUndoRedoService)],ti);const pr={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(n,i)=>i?(n.get(tt).setStatus(i.status),!0):!1},Mi={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get(tt).getStatus();let t;return e!==De.OFF?t=De.OFF:t=De.INFINITE,n.get(a.ICommandService).executeCommand(pr.id,{status:t})}},An={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get(tt).getStatus();let t;return e!==De.OFF?t=De.OFF:t=De.ONCE,n.get(a.ICommandService).executeCommand(pr.id,{status:t})}},vr={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,i)=>n.get(tt).applyFormatPainter(i.unitId,i.subUnitId,i.range)},ut={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,i)=>{const{type:e}=i||{},t=n.get(a.IUniverInstanceService),r=n.get(a.IUndoRedoService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,c=n.get(a.ICommandService),u=n.get(m.SheetsSelectionsService).getCurrentSelections();if(!u)return!1;const h=u[(u==null?void 0:u.length)-1],{range:g}=h,f=n.get(y.IRenderManagerService).getRenderById(s).with(exports.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,I,b,T;const{startRow:M,startColumn:w,rangeType:P}=g;if(P===a.RANGE_TYPE.ROW||e===1)C=M,b=M-p,I=-1,T=0;else if(P===a.RANGE_TYPE.COLUMN||e===2)C=-1,b=0,I=w,T=w-v;else if(P===a.RANGE_TYPE.NORMAL)C=M,b=M-p,I=w,T=w-v;else return!1;const x={unitId:s,subUnitId:l,startRow:C,startColumn:I,xSplit:I>0?Math.max(1,T):T,ySplit:C>0?Math.max(1,b):b},A=m.SetFrozenMutationFactory(n,x);return c.syncExecuteCommand(m.SetFrozenMutation.id,x)&&r.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:A}],redoMutations:[{id:m.SetFrozenMutation.id,params:x}]}),!0}},Cr={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ut.id,{type:1}),!0)},_r={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ut.id,{type:2}),!0)};var Fh=Object.defineProperty,jh=Object.getOwnPropertyDescriptor,zh=(n,i,e,t)=>{for(var r=t>1?void 0:t?jh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Fh(i,e,r),r},la=(n,i)=>(e,t)=>i(e,t,n);const Xh=(n,i)=>{const{unitId:e,subUnitId:t,ranges:r}=n,o={},s=i.getColumnManager();for(let l=0;l<r.length;l++){const c=r[l];for(let d=c.startColumn;d<c.endColumn+1;d++){const u=s.getColumnOrCreate(d);o[d]=u.w}}return{unitId:e,subUnitId:t,ranges:r,colWidth:o}};exports.AutoWidthController=class extends a.Disposable{constructor(i,e){super(),this._renderManagerService=i,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(i){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,r=m.getSheetCommandTarget(t);if(!r)return e;const{unitId:o,subUnitId:s,worksheet:l}=r,c=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!c.getCurrent())return e;const{skeleton:d}=c.getCurrent(),u=d.calculateAutoWidthInRange(i.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const g={subUnitId:s,unitId:o,ranges:i.ranges,colWidth:h},S=Xh(g,l);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:S}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:g}]}}};exports.AutoWidthController=zh([la(0,y.IRenderManagerService),la(1,a.Inject(a.IUniverInstanceService))],exports.AutoWidthController);const Ir={type:a.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:async(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o,i);if(!s)return!1;const{unitId:l,subUnitId:c}=s;let d=[];if(i!=null&&i.ranges)d=[...i.ranges];else{const f=r.getCurrentSelections();for(let p=0;p<f.length;p++)d.push(f[p].range)}if(!(d!=null&&d.length))return!1;const u={unitId:l,subUnitId:c,ranges:d},{redos:h,undos:g}=n.get(exports.AutoWidthController).getUndoRedoParamsOfColWidth(u);return a.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:l,undoMutations:[...g],redoMutations:[...h]}),!0):!1}},Nn="UI_PLUGIN_SHEETS",br=`${Nn}_COLOR_PICKER_COMPONENT`,Pi=`${Nn}_FONT_FAMILY_COMPONENT`,Oi=`${Nn}_FONT_FAMILY_ITEM_COMPONENT`,xi=`${Nn}_FONT_SIZE_COMPONENT`,Ai=`${Nn}_MENU_ITEM_INPUT_COMPONENT`;var Xi={exports:{}},Ln={};/**
12
+ `)}),i}function Hh(n){return a.isNotNullOrUndefined(n.displayV)?n.displayV:a.extractPureTextFromCell(n)}function kh(n,i,e,t){return t.getMergeData().some(r=>r.startRow<=n&&n<r.endRow&&i<=r.startColumn&&r.startColumn<=e)}function Vh(n,i,e,t){return t.getMergeData().some(r=>r.startColumn<=n&&n<r.endColumn&&i<=r.startRow&&r.startRow<=e)}function Wh(n){let i=0;return n.forValue((e,t,r)=>{if(r&&i++,i>1)return!1}),i>1}function Un(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const vs=998,ze={id:E.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:vs,preconditions:Ss,handler:async n=>n.get(Ge).copy()},Cs={id:E.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:vs,preconditions:Ss,handler:async n=>n.get(Ge).cut()},Xe={id:E.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:vs,preconditions:Ss,handler:async(n,i)=>{const t=await n.get(E.IClipboardInterfaceService).read(),r=n.get(Ge);return t.length!==0?r.paste(t[0],i==null?void 0:i.value):!1}},ei={id:E.SheetPasteShortKeyCommandName,type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(Ge),{htmlContent:t,textContent:r}=i;return e.legacyPaste(t,r),!0}},mn={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_VALUE})},gn={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_FORMAT})},Ht={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},Sn={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},Sl={id:"sheet.command.optional-paste",type:a.CommandType.COMMAND,handler:async(n,{type:i})=>n.get(Ge).rePasteWithPasteType(i)},mr={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleRows();if(Za(l,e)){const d=n.get(E.IConfirmService),u=n.get(a.LocaleService);return await d.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetRowHiddenCommand.id),!0}},gr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleCols();if(Ka(l,e)){const d=n.get(E.IConfirmService),u=n.get(a.LocaleService);return await d.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetColHiddenCommand.id),!0}},Kt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatBoldCommand.id):i.executeCommand(m.SetBoldCommand.id)}},qt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatItalicCommand.id):i.executeCommand(m.SetItalicCommand.id)}},Qt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatUnderlineCommand.id):i.executeCommand(m.SetUnderlineCommand.id)}},Jt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatStrikethroughCommand.id):i.executeCommand(m.SetStrikeThroughCommand.id)}},_s={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatSubscriptCommand.id):!1}},Is={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatSuperscriptCommand.id):!1}},Sr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontSizeCommand.id,i):e.executeCommand(m.SetFontSizeCommand.id,i)}},fr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontFamilyCommand.id,i):e.executeCommand(m.SetFontFamilyCommand.id,i)}},Tn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatTextColorCommand.id,i):e.executeCommand(m.SetTextColorCommand.id,i)}},bs={type:a.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const i=n.get(a.ICommandService),t=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),r=n.get(a.ThemeService);return t?i.executeCommand(J.SetInlineFormatTextColorCommand.id,{value:null}):i.executeCommand(m.SetTextColorCommand.id,{value:r.getCurrentTheme().textColor})}};var Uh=Object.defineProperty,Lh=Object.getOwnPropertyDescriptor,Bh=(n,i,e,t)=>{for(var r=t>1?void 0:t?Lh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Uh(i,e,r),r},sn=(n,i)=>(e,t)=>i(e,t,n),De=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(De||{});const tt=a.createIdentifier("univer.format-painter-service");let ti=class extends a.Disposable{constructor(i,e,t,r,o,s){super();R(this,"status$");R(this,"_selectionFormat");R(this,"_markId",null);R(this,"_status$");R(this,"_defaultHook",null);R(this,"_extendHooks",[]);this._selectionManagerService=i,this._themeService=e,this._markSelectionService=t,this._logService=r,this._commandService=o,this._undoRedoService=s,this._status$=new O.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}addHook(i){var e,t,r;i.isDefaultHook&&((e=i.priority)!=null?e:0)>((r=(t=this._defaultHook)==null?void 0:t.priority)!=null?r:-1)?this._defaultHook=i:(this._extendHooks.push(i),this._extendHooks.sort((o,s)=>(o.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(i){this._updateRangeMark(i),this._status$.next(i),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(i)})}getStatus(){return this._status$.getValue()}setSelectionFormat(i){this._selectionFormat=i}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(i,e,t){const r=this.getHooks(),o=[],s=[];r.forEach(c=>{if(c.onApply!==void 0){const d=c.onApply(i,e,t,this._selectionFormat);d&&(o.push(...d.redos),s.push(...d.undos))}});for(const c of r)if(c.onBeforeApply!==void 0&&!c.onBeforeApply({unitId:i,subUnitId:e,range:t,redoMutationsInfo:o,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:o});const l=o.every(c=>this._commandService.executeCommand(c.id,c.params));return l&&this._undoRedoService.pushUndoRedo({unitID:i,undoMutations:s,redoMutations:o}),l}_updateRangeMark(i){if(this._markSelectionService.removeAllShapes(),i!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=ul(this._themeService);i===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};ti=Bh([sn(0,a.Inject(m.SheetsSelectionsService)),sn(1,a.Inject(a.ThemeService)),sn(2,Zt),sn(3,a.ILogService),sn(4,a.ICommandService),sn(5,a.IUndoRedoService)],ti);const pr={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(n,i)=>i?(n.get(tt).setStatus(i.status),!0):!1},Mi={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get(tt).getStatus();let t;return e!==De.OFF?t=De.OFF:t=De.INFINITE,n.get(a.ICommandService).executeCommand(pr.id,{status:t})}},An={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get(tt).getStatus();let t;return e!==De.OFF?t=De.OFF:t=De.ONCE,n.get(a.ICommandService).executeCommand(pr.id,{status:t})}},vr={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,i)=>n.get(tt).applyFormatPainter(i.unitId,i.subUnitId,i.range)},ut={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,i)=>{const{type:e}=i||{},t=n.get(a.IUniverInstanceService),r=n.get(a.IUndoRedoService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,c=n.get(a.ICommandService),u=n.get(m.SheetsSelectionsService).getCurrentSelections();if(!u)return!1;const h=u[(u==null?void 0:u.length)-1],{range:g}=h,f=n.get(y.IRenderManagerService).getRenderById(s).with(exports.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,I,b,T;const{startRow:M,startColumn:w,rangeType:P}=g;if(P===a.RANGE_TYPE.ROW||e===1)C=M,b=M-p,I=-1,T=0;else if(P===a.RANGE_TYPE.COLUMN||e===2)C=-1,b=0,I=w,T=w-v;else if(P===a.RANGE_TYPE.NORMAL)C=M,b=M-p,I=w,T=w-v;else return!1;const x={unitId:s,subUnitId:l,startRow:C,startColumn:I,xSplit:I>0?Math.max(1,T):T,ySplit:C>0?Math.max(1,b):b},A=m.SetFrozenMutationFactory(n,x);return c.syncExecuteCommand(m.SetFrozenMutation.id,x)&&r.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:A}],redoMutations:[{id:m.SetFrozenMutation.id,params:x}]}),!0}},Cr={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ut.id,{type:1}),!0)},_r={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ut.id,{type:2}),!0)};var Fh=Object.defineProperty,jh=Object.getOwnPropertyDescriptor,zh=(n,i,e,t)=>{for(var r=t>1?void 0:t?jh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Fh(i,e,r),r},la=(n,i)=>(e,t)=>i(e,t,n);const Xh=(n,i)=>{const{unitId:e,subUnitId:t,ranges:r}=n,o={},s=i.getColumnManager();for(let l=0;l<r.length;l++){const c=r[l];for(let d=c.startColumn;d<c.endColumn+1;d++){const u=s.getColumnOrCreate(d);o[d]=u.w}}return{unitId:e,subUnitId:t,ranges:r,colWidth:o}};exports.AutoWidthController=class extends a.Disposable{constructor(i,e){super(),this._renderManagerService=i,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(i){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,r=m.getSheetCommandTarget(t);if(!r)return e;const{unitId:o,subUnitId:s,worksheet:l}=r,c=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!c.getCurrent())return e;const{skeleton:d}=c.getCurrent(),u=d.calculateAutoWidthInRange(i.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const g={subUnitId:s,unitId:o,ranges:i.ranges,colWidth:h},S=Xh(g,l);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:S}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:g}]}}};exports.AutoWidthController=zh([la(0,y.IRenderManagerService),la(1,a.Inject(a.IUniverInstanceService))],exports.AutoWidthController);const Ir={type:a.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o,i);if(!s)return!1;const{unitId:l,subUnitId:c}=s;let d=[];if(i!=null&&i.ranges)d=[...i.ranges];else{const f=r.getCurrentSelections();for(let p=0;p<f.length;p++)d.push(f[p].range)}if(!(d!=null&&d.length))return!1;const u={unitId:l,subUnitId:c,ranges:d},{redos:h,undos:g}=n.get(exports.AutoWidthController).getUndoRedoParamsOfColWidth(u);return a.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:l,undoMutations:[...g],redoMutations:[...h]}),!0):!1}},Nn="UI_PLUGIN_SHEETS",br=`${Nn}_COLOR_PICKER_COMPONENT`,Pi=`${Nn}_FONT_FAMILY_COMPONENT`,Oi=`${Nn}_FONT_FAMILY_ITEM_COMPONENT`,xi=`${Nn}_FONT_SIZE_COMPONENT`,Ai=`${Nn}_MENU_ITEM_INPUT_COMPONENT`;var Xi={exports:{}},Ln={};/**
13
13
  * @license React
14
14
  * react-jsx-runtime.production.min.js
15
15
  *
package/lib/es/index.js CHANGED
@@ -8332,7 +8332,7 @@ us = hb([
8332
8332
  const Ql = {
8333
8333
  type: K.COMMAND,
8334
8334
  id: "sheet.command.set-col-auto-width",
8335
- handler: async (r, e) => {
8335
+ handler: (r, e) => {
8336
8336
  const t = r.get(F), n = r.get(Zt), i = r.get($), s = r.get(L), o = Ue(s, e);
8337
8337
  if (!o) return !1;
8338
8338
  const { unitId: l, subUnitId: a } = o;
package/lib/umd/index.js CHANGED
@@ -9,7 +9,7 @@
9
9
  `,S={...u,body:{dataStream:h,textRuns:c.textRuns,paragraphs:hr(h)}};d==null||d.reset(S),r=d==null?void 0:d.getSnapshot(),i=c.dataStream}else i=gh(o.innerHTML.replace(/[\r\n]/g,""));return{cellText:i,cellRichStyle:r}}_generateDocumentDataModelSnapshot(o){var a;const e=this._getCurrentSkeleton();if(e==null)return null;const{skeleton:t}=e,i=(a=t.getBlankCellDocumentModel())==null?void 0:a.documentModel,s={...i==null?void 0:i.getSnapshot(),...o};return i==null||i.reset(s),i==null?void 0:i.getSnapshot()}process(o,e,t,i){var r,s,a;for(const c of e)if(c.nodeName.toLowerCase()==="table")i.push({index:((r=t==null?void 0:t.paragraphs)==null?void 0:r.length)||0});else if(c.nodeType===Node.TEXT_NODE){if(((s=c.nodeValue)==null?void 0:s.trim())==="")continue;const d=(a=c.nodeValue)==null?void 0:a.replace(/[\r\n]/g,"");let u;o&&this._styleCache.has(o)&&(u=this._styleCache.get(o));const h={dataStream:"",textRuns:[]};t.dataStream+=d,h.dataStream+=d,u&&Object.getOwnPropertyNames(u).length&&(t.textRuns.push({st:t.dataStream.length-d.length,ed:t.dataStream.length,ts:u}),h.textRuns.push({st:t.dataStream.length-d.length,ed:t.dataStream.length,ts:u}))}else{if(l.skipParseTagNames.includes(c.nodeName.toLowerCase()))continue;if(c.nodeName.toLowerCase()==="br")t.paragraphs||(t.paragraphs=[]),t.paragraphs.push({startIndex:t.dataStream.length}),t.dataStream+="\r";else if(c.nodeType===Node.ELEMENT_NODE){if(c.nodeName==="STYLE")continue;const d=c,u=this._processBeforeLink(d,{body:t}),h=o?this._styleCache.get(o):{},S=this._styleRules.find(({filter:v})=>Ml(c,v)),g=S?S.getStyle(c):Yi(c);this._styleCache.set(c,{...h,...g});const{childNodes:f}=c;this.process(c,f,t,i);const p=this._afterProcessRules.find(({filter:v})=>Ml(c,v));p&&p.handler(t,c),this._processAfterLink(d,{body:t},u)}}}_processBeforeLink(o,e){return e.body.dataStream.length}_processAfterLink(o,e,t){var s,a;const i=e.body,r=o;r.tagName.toUpperCase()==="A"&&(i.customRanges=(s=i.customRanges)!=null?s:[],i.customRanges.push({startIndex:t,endIndex:i.dataStream.length-1,rangeId:(a=r.dataset.rangeid)!=null?a:l.generateRandomId(),rangeType:l.CustomRangeType.HYPERLINK,properties:{url:r.href}}))}dispose(){this._dom=null,this._styleCache.clear(),this._styleMap.clear()}};R(Uo,"_pluginList",[]);let fn=Uo;function mh(n){const o=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,e=n.matchAll(o);if(!e)return{rowProperties:[],rowCount:0};const i=Array.from(e).map(r=>Ol(r[1])).map(r=>{if(!r.height){const s=r.style,a=s&&s.match(/height\s*:\s*(\d+(\.\d+)?)px/);r.height=`${a?Number.parseInt(a[1],10):l.DEFAULT_WORKSHEET_ROW_HEIGHT}`}return r});return{rowProperties:i,rowCount:i.length}}function Pl(n){const o={};return n.split(";").forEach(t=>{const[i,r]=t.split(":");o[i]=r}),o}function Ol(n){if(!n)return{};const o={},e=/([\w-]+)\s*=\s*(?:(['"])([^'"]*)\2|(\S+))/g;let t;for(;(t=e.exec(n))!==null;){const[,i,,r,s]=t,a=r!==void 0?r:s;o[i]=a}return o}function Sh(n){const o=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,e=n.match(o),t=/<col([\s\S]*?)>/g;let i;if(e!=null&&e[2]?i=e[2].matchAll(t):i=n.matchAll(t),!i)return null;const r=Array.from(i).map(a=>Ol(a[1])),s=[];return r.forEach(a=>{const c=Number(a.span);if(c)for(let d=0;d<c;d++){const u={...a};delete u.span,s.push(u)}else s.push(a)}),s}function gh(n){const o={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":'"',"&#39;":"'","&nbsp;":" "};return n.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g,e=>o[e])}function Al(n,o){if(!n||!o)return null;const e=new RegExp(`(${o}\\s*:\\s*[^;]+);`,"i"),t=n.match(e);return t?t[1]:null}function fh(n,o,e,t){const{rowSpan:i,colSpan:r,rowIndex:s,colSetValueIndex:a}=t;for(let c=s;c<s+i;c++)for(let d=a;d<a+r;d++)c===s&&d===a?n.setValue(c,d,{...e,style:o}):n.setValue(c,d,{style:o})}const ph={name:"univer-doc-paste-plugin-lark",checkPasteType(n){return/lark-record-clipboard/i.test(n)},stylesRules:[{filter:["s"],getStyle(n){const o=Yi(n);return{st:{s:l.BooleanNumber.TRUE},...o}}}],afterProcessRules:[{filter(n){return n.tagName==="DIV"&&/ace-line/i.test(n.className)},handler(n){n.paragraphs==null&&(n.paragraphs=[]),n.paragraphs.push({startIndex:n.dataStream.length}),n.dataStream+="\r"}}]},vh={name:"univer-doc-paste-plugin-univer",checkPasteType(n){return/UniverNormal/i.test(n)},stylesRules:[],afterProcessRules:[{filter(n){return n.tagName==="P"&&/UniverNormal/i.test(n.className)},handler(n,o){n.paragraphs==null&&(n.paragraphs=[]);const e={startIndex:n.dataStream.length},t=Tl(o);t&&(e.paragraphStyle=t),n.paragraphs.push(e),n.dataStream+="\r"}}]},Ch={name:"univer-doc-paste-plugin-word",checkPasteType(n){return/word|mso/i.test(n)},stylesRules:[{filter:["b"],getStyle(n){const o=Yi(n);return{bl:l.BooleanNumber.TRUE,...o}}}],afterProcessRules:[{filter(n){return n.tagName==="P"&&/mso/i.test(n.className)},handler(n,o){n.paragraphs==null&&(n.paragraphs=[]);const e={startIndex:n.dataStream.length},t=Tl(o);t&&(e.paragraphStyle=t),n.paragraphs.push(e),n.dataStream+="\r"}}]};var It=(n=>(n.COPY="COPY",n.CUT="CUT",n))(It||{});function Ih(n,o,e,t,i){const r=e.map(d=>{var u;return(u=d.onCopyRow)==null?void 0:u.call(d,n)}).filter(d=>!!d),s=mr(r),a=Sr(s),c=o.map(d=>{if(!i.has(`${n}-${d}`)){const u=t.getValue(n,d);if(u!=null&&u.rowSpan&&(u!=null&&u.colSpan))for(let h=n;h<n+u.rowSpan;h++)for(let S=d;S<d+u.colSpan;S++)i.add(`${h}-${S}`);return _h(n,d,e,t)}return null}).filter(d=>!!d).join("");return`<tr${a}>${c}</tr>`}function _h(n,o,e,t){const i=t.getValue(n,o),r=e.map(d=>{var u;return(u=d.onCopyCellStyle)==null?void 0:u.call(d,n,o,i==null?void 0:i.rowSpan,i==null?void 0:i.colSpan)}).filter(d=>!!d),s=mr(r),a=Sr(s),c=e.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,n,o))||""},"");return`<td${a}>${c}</td>`}function bh(n,o){return`<colgroup>${n.map(t=>{const i=o.map(a=>{var c;return(c=a.onCopyColumn)==null?void 0:c.call(a,t)}).filter(a=>!!a),r=mr(i);return`<col ${Sr(r)}>`}).join("")}</colgroup>`}function mr(n){return n.reduce((o,e)=>(Object.keys(e).forEach(i=>{o[i]?o[i]+=`;${e[i]}`:o[i]=e[i]}),o),{})}function Sr(n){return Object.keys(n).reduce((o,e)=>(o+=` ${e}="${n[e]}"`,o),"")}class Rh{convert(o,e,t){const{cols:i,rows:r}=e;if(!i.length)return"";const s=bh(i,t),a=[],c=new Set;return r.forEach(u=>{a.push(Ih(u,i,t,o,c))}),`<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${s}
10
10
  <tbody>${a.join("")}</tbody></table>`}}const Eh=(n,o,e=!1)=>{const t=h=>h.endRow-h.startRow+1,i=h=>h.endColumn-h.startColumn+1,r=t(o)%t(n),s=i(o)%i(n),a={startRow:0,endRow:t(n)-1,startColumn:0,endColumn:i(n)-1},c=Math.floor(t(o)/t(n)),d=Math.floor(i(o)/i(n)),u=[];if(!r&&!s)for(let h=1;h<=c;h++)for(let S=1;S<=d;S++){const g=t(n)*(h-1),f=i(n)*(S-1),p={startRow:g+o.startRow,endRow:g+o.startRow,startColumn:f+o.startColumn,endColumn:f+o.startColumn};u.push({repeatRelativeRange:a,startRange:p})}else if(!r&&s&&!e)for(let h=1;h<=c;h++){const S=t(n)*(h-1),g=0,f={startRow:S+o.startRow,endRow:S+o.startRow,startColumn:g+o.startColumn,endColumn:g+o.startColumn};u.push({repeatRelativeRange:a,startRange:f})}else if(r&&!s&&!e)for(let h=1;h<=d;h++){const g=i(n)*(h-1),f={startRow:0+o.startRow,endRow:0+o.startRow,startColumn:g+o.startColumn,endColumn:g+o.startColumn};u.push({repeatRelativeRange:a,startRange:f})}else{const h={startRow:o.startRow,endRow:o.startRow,startColumn:o.startColumn,endColumn:o.startColumn};u.push({startRange:h,repeatRelativeRange:a})}return u};async function Th(n){return n?/<td[^>]*class=".*?xl.*?"[^>]*>.*?<\/td>/.test(n):!1}function wh(...n){if(n.length===1)return n[0];const o=new l.ObjectMatrix;return n.forEach(e=>{e&&new l.ObjectMatrix(e).forValue((i,r,s)=>{o.setValue(i,r,{...o.getValue(i,r),...s})})}),o.getMatrix()}function yh(n,o){return n.id===o.id&&n.params.unitId===o.params.unitId&&n.params.subUnitId===o.params.subUnitId}function gr(n){const o=[];for(let e=0;e<n.length;){let t=1;if(n[e].id===m.SetRangeValuesMutation.id){const i=n[e],r=[i];for(;e+t<n.length&&yh(i,n[e+t]);)r.push(n[e+t]),t+=1;const s=wh(...r.map(a=>a.params.cellValue||{}));o.push({...i,params:{...i.params,cellValue:s}})}else o.push(n[e]);e+=t}return o}function fr(n,o){const{startRow:e,endRow:t,startColumn:i,endColumn:r}=n;for(let s=e;s<=t;s++)for(let a=i;a<=r;a++)if(o.rows.includes(s)&&o.cols.includes(a))return!0}function Nl(n,o){const{startRow:e,endRow:t,startColumn:i,endColumn:r}=o;for(let s=e;s<=t;s++)if(!n.rows.includes(s))return!1;for(let s=i;s<=r;s++)if(!n.cols.includes(s))return!1;return!0}function Mh(n){const o=n.trim().split(`
11
11
  `);let e="<table>";return o.forEach(t=>{const i=t.split(" ");e+="<tr>",i.forEach(r=>{e+=`<td>${r}</td>`}),e+="</tr>"}),e+="</table>",e}var Ph=Object.defineProperty,Oh=Object.getOwnPropertyDescriptor,Ah=(n,o,e,t)=>{for(var i=t>1?void 0:t?Oh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=(t?s(o,e,i):s(i))||i);return t&&i&&Ph(o,e,i),i},Ne=(n,o)=>(e,t)=>o(e,t,n);const ge={DEFAULT_COPY:"default-copy",DEFAULT_PASTE:"default-paste",SPECIAL_PASTE_VALUE:"special-paste-value",SPECIAL_PASTE_FORMAT:"special-paste-format",SPECIAL_PASTE_COL_WIDTH:"special-paste-col-width",SPECIAL_PASTE_BESIDES_BORDER:"special-paste-besides-border",SPECIAL_PASTE_FORMULA:"special-paste-formula"};fn.use(Ch),fn.use(ph),fn.use(vh);const Xe=l.createIdentifier("sheet.clipboard-service");w.SheetClipboardService=class extends l.Disposable{constructor(e,t,i,r,s,a,c,d,u,h,S,g,f,p){super();R(this,"_clipboardHooks",[]);R(this,"_clipboardHooks$",new A.BehaviorSubject([]));R(this,"clipboardHooks$",this._clipboardHooks$.asObservable());R(this,"_htmlToUSM");R(this,"_usmToHtml");R(this,"_copyContentCache");R(this,"_copyMarkId",null);R(this,"_pasteOptionsCache$",new A.BehaviorSubject(null));R(this,"pasteOptionsCache$",this._pasteOptionsCache$.asObservable());R(this,"_showMenu$",new A.Subject);R(this,"showMenu$",this._showMenu$.asObservable());this._logService=e,this._univerInstanceService=t,this._selectionManagerService=i,this._clipboardInterfaceService=r,this._undoRedoService=s,this._commandService=a,this._markSelectionService=c,this._notificationService=d,this._platformService=u,this._renderManagerService=h,this._themeService=S,this._localeService=g,this._errorService=f,this._injector=p,this._htmlToUSM=new fn({getCurrentSkeleton:()=>{var v;return(v=this._renderManagerService.withCurrentTypeOfUnit(l.UniverInstanceType.UNIVER_SHEET,w.SheetSkeletonManagerService))==null?void 0:v.getCurrent()}}),this._usmToHtml=new Rh,this._copyContentCache=new dh,this.disposeWithMe(this._htmlToUSM),this._initUnitDisposed()}setShowMenu(e){this._showMenu$.next(e)}copyContentCache(){return this._copyContentCache}generateCopyContent(e,t,i){const r=this._clipboardHooks;r.forEach(a=>{var c;return(c=a.onBeforeCopy)==null?void 0:c.call(a,e,t,i)});const s=this._generateCopyContent(e,t,i,r);return r.forEach(a=>{var c;return(c=a.onAfterCopy)==null?void 0:c.call(a)}),s}async copy(e=It.COPY){const t=this._selectionManagerService.getCurrentLastSelection();if(!t)return!1;const i=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),r=i.getActiveSheet();if(!r)return!1;const s=this.generateCopyContent(i.getUnitId(),r.getSheetId(),t.range);if(!s)return!1;const{html:a,plain:c,matrixFragment:d,copyId:u,discreteRange:h}=s;this._copyContentCache.set(u,{unitId:i.getUnitId(),subUnitId:r.getSheetId(),range:h,matrix:d,copyType:e}),await this._clipboardInterfaceService.write(c,a),this._markSelectionService.removeAllShapes();const S=Rl(this._themeService);return this._copyMarkId=this._markSelectionService.addShape({...t,style:S}),!0}async cut(){return this.copy(It.CUT)}async paste(e,t=ge.DEFAULT_PASTE){const i=e.types,r=i.indexOf(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()):"",s=i.indexOf(E.HTML_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(E.HTML_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()):"";return s?(this._platformService.isWindows&&await Th(s)&&this._notificationService.show({type:"warning",title:this._localeService.t("clipboard.shortCutNotify.title"),content:this._localeService.t("clipboard.shortCutNotify.useShortCutInstead")}),this._pasteHTML(s,t)):r?this._pastePlainText(r,t):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}legacyPaste(e,t){return e?this._pasteHTML(e,ge.DEFAULT_PASTE):t?/[\n\t]/.test(t)?this._pasteHTML(Mh(t),ge.DEFAULT_PASTE):this._pastePlainText(t,ge.DEFAULT_PASTE):Promise.resolve(!1)}rePasteWithPasteType(e){const t=this._pasteOptionsCache$.getValue();if(!t)return!1;const i=this._injector.get(l.IUndoRedoService),r=i.pitchTopUndoElement();r&&l.sequenceExecute(r.undoMutations,this._commandService)&&i.popUndoToRedo();const{cellMatrix:s,rowProperties:a=[],colProperties:c=[],source:d,target:u}=t;return this._pasteUSM({cellMatrix:s,colProperties:c,rowProperties:a},u,ge[e],d),!0}updatePasteOptionsCache(e){this._pasteOptionsCache$.next(e)}addClipboardHook(e){if(this._clipboardHooks.findIndex(i=>i.id===e.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",e.id),{dispose:()=>{}};const t=this._clipboardHooks.findIndex(i=>{const r=i.priority||0;return(e.priority||0)<r});return this._clipboardHooks.splice(t!==-1?t:this._clipboardHooks.length,0,e),this._notifyClipboardHook(),l.toDisposable(()=>{const i=this._clipboardHooks.indexOf(e);i>-1&&(this._clipboardHooks.splice(i,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_generateCopyContent(e,t,i,r){const s=this._univerInstanceService.getUniverSheetInstance(e),a=s==null?void 0:s.getSheetBySheetId(t);if(!s||!a)return null;const c=r.reduce((P,y)=>{var N;const O=(N=y.getFilteredOutRows)==null?void 0:N.call(y,i);return O==null||O.forEach(D=>P.add(D)),P},new Set),{startColumn:d,startRow:u,endColumn:h,endRow:S}=i,g=a.getMatrixWithMergedCells(u,d,S,h,l.CellModeEnum.Both),f=new l.ObjectMatrix;let p=u;const v=new l.ObjectMatrix,C={rows:[],cols:[]};for(let P=u;P<=S;P++)if(!c.has(P)){C.rows.push(P);for(let y=d;y<=h;y++){const O=g.getValue(P,y);if(O){const N=l.Tools.deepClone(O);v.setValue(p-u,y-d,{...qn(),...N}),delete N.displayV,f.setValue(p-u,y-d,{...qn(),...N})}else v.setValue(p-u,y-d,qn()),f.setValue(p-u,y-d,qn()),g.setValue(P,y,qn())}p+=1}for(let P=d;P<=h;P++)C.cols.push(P);let _=this._usmToHtml.convert(g,C,r);const b=Dl(v),T=ah();return _=_.replace(/(<[a-z]+)/,(P,y)=>`${y} data-copy-id="${T}"`),{copyId:T,plain:b,html:_,matrixFragment:f,discreteRange:C}}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _pastePlainText(e,t){const i=this._getPastingTarget();if(!i.subUnitId||!i.selection)return!1;const r=this._injector.invoke(f=>on(i.selection.range,f,i.unitId,i.subUnitId));if(!r)return!1;const{unitId:s,subUnitId:a}=i,c=this._clipboardHooks,d=[];if(c.some(f=>{var p;return d.push(f)&&((p=f.onBeforePaste)==null?void 0:p.call(f,{unitId:s,subUnitId:a,range:r}))===!1}))return d.forEach(f=>{var p;return(p=f.onAfterPaste)==null?void 0:p.call(f,!1)}),!1;const h=[],S=[];d.forEach(f=>{var v;const p=(v=f.onPastePlainText)==null?void 0:v.call(f,{unitId:s,subUnitId:a,range:r},e,{pasteType:t});p&&(h.push(...p.redos),S.push(...p.undos))});const g=h.every(f=>this._commandService.executeCommand(f.id,f.params));return g&&this._undoRedoService.pushUndoRedo({unitID:this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET).getUnitId(),undoMutations:S,redoMutations:h}),g}async _pasteHTML(e,t){const i=ch(e);return i&&this._copyContentCache.get(i)?this._pasteInternal(i,t):this._pasteExternal(e,t)}async _pasteExternal(e,t){var h;const{rowProperties:i,colProperties:r,cellMatrix:s}=this._htmlToUSM.convert(e);if(!s)return!1;const a=this._getPastedRange(s);if(!a)return!1;const c=(h=this._univerInstanceService.getUniverSheetInstance(a.unitId))==null?void 0:h.getSheetBySheetId(a.subUnitId);if(!c)return!1;const d=c==null?void 0:c.getMergeData();return d.length&&d.some(g=>fr(g,a.pastedRange)&&!Nl(a.pastedRange,g))?(this._errorService.emit(this._localeService.t("clipboard.paste.overlappingMergedCells")),!1):this._pasteUSM({rowProperties:i,colProperties:r,cellMatrix:s},a,t)}async _pasteInternal(e,t){var y,O;const i=l.Tools.deepClone(this._copyContentCache.get(e)),{range:r,matrix:s,unitId:a,subUnitId:c}=i||{};if(!s||!i||!r||!a||!c||!s||!i)return!1;const d=(y=this._univerInstanceService.getUniverSheetInstance(a))==null?void 0:y.getStyles();s.forValue((N,D,H)=>{if(typeof H.s=="string"){const k=l.Tools.deepClone(H);k.s=d==null?void 0:d.getStyleByCell(H),s.setValue(N,D,k)}if(H.colSpan||H.rowSpan)for(let k=0;k<H.rowSpan;k++)for(let V=0;V<H.colSpan;V++){if(k===0&&V===0)continue;const U=N+k,x=D+V;s.setValue(U,x,{s:d==null?void 0:d.getStyleByCell(H)})}});const u=this._getPastedRange(s);if(!u)return!1;const h=(O=this._univerInstanceService.getUniverSheetInstance(u.unitId))==null?void 0:O.getSheetBySheetId(u.subUnitId);if(!h)return!1;const S=h==null?void 0:h.getMergeData();if(S&&S.some(D=>fr(D,u.pastedRange)&&!Nl(u.pastedRange,D)))return this._errorService.emit(this._localeService.t("clipboard.paste.overlappingMergedCells")),!1;const g=this._univerInstanceService.getUnit(a);if(!g)return!1;const f=g.getSheetBySheetId(c);if(!f)return!1;const p=f.getColumnManager(),v=f.getRowManager(),C=f.getConfig().defaultColumnWidth,_=f.getConfig().defaultRowHeight,b=[],T=[];if(r.cols.forEach(N=>{const D=p.getColumnOrCreate(N);b.push({width:`${D.w||C}`})}),r.rows.forEach(N=>{const D=v.getRowOrCreate(N),{ah:H=_,h:k=_}=D,V=Math.max(H,k);T.push({height:`${V}`})}),i.copyType===It.CUT){const N=u.pastedRange.rows[0],D=r.rows[r.rows.length-1]-r.rows[0]+N;u.pastedRange.rows=Array.from(new Array(D+1).keys()).slice(N)}const P=this._pasteUSM({cellMatrix:s,colProperties:b,rowProperties:T},u,t,{range:r,unitId:i.unitId,subUnitId:i.subUnitId,copyType:i.copyType,copyId:e});return i.copyType===It.CUT&&(this._copyContentCache.set(e,{...i,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),P}_pasteUSM(e,t,i,r){const{rowProperties:s,colProperties:a,cellMatrix:c}=e,{unitId:d,subUnitId:u,pastedRange:h}=t,S=h.cols.length,g=this._clipboardHooks,f=[];if(g.some(O=>{var N;return f.push(O)&&((N=O.onBeforePaste)==null?void 0:N.call(O,{unitId:d,subUnitId:u,range:h}))===!1}))return f.forEach(O=>{var N;return(N=O.onAfterPaste)==null?void 0:N.call(O,!1)}),!1;if(!c)return!1;const v=r?{unitId:r.unitId,subUnitId:r.subUnitId,range:r.range}:null,C={copyType:(r==null?void 0:r.copyType)||It.COPY,copyId:r==null?void 0:r.copyId,pasteType:i};let _=[],b=[];const T=f.filter(O=>!O.specialPasteInfo&&O.id!==ge.DEFAULT_PASTE||i===O.id);T.forEach(O=>{var H,k,V;if(s){const U=(H=O.onPasteRows)==null?void 0:H.call(O,{range:h,unitId:d,subUnitId:u},s,{pasteType:i});U&&(_.push(...U.redos),b.push(...U.undos))}const N=(k=O.onPasteColumns)==null?void 0:k.call(O,{range:h,unitId:d,subUnitId:u},a||new Array(S).map(()=>({})),{pasteType:i});N&&(_.push(...N.redos),b.push(...N.undos));const D=(V=O.onPasteCells)==null?void 0:V.call(O,v,{range:h,unitId:d,subUnitId:u},c,C);D&&(_.push(...D.redos),b.push(...D.undos))});const P=this._getSetSelectionOperation(d,u,h,c,i);P&&_.push(P),_=gr(_),b=gr(b),b.push({id:m.SetWorksheetActiveOperation.id,params:{unitId:t.unitId,subUnitId:t.subUnitId}}),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:b,redoMutationsInfo:_});const y=_.every(O=>this._commandService.syncExecuteCommand(O.id,O.params));return y&&(this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:b,redoMutations:_}),this.updatePasteOptionsCache({target:{pastedRange:h,unitId:d,subUnitId:u},cellMatrix:c,rowProperties:s,colProperties:a,pasteType:i,source:r}),this.setShowMenu(!0)),T.forEach(O=>{var N;return(N=O.onAfterPaste)==null?void 0:N.call(O,y)}),y}_getSetSelectionOperation(e,t,i,r,s){var P;const a=(P=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:P.getSheetBySheetId(t);if(!a)return null;const{rows:c,cols:d}=i,u=c[0],h=d[0],S=c[c.length-1],g=d[d.length-1],f={startRow:u,endRow:u,startColumn:h,endColumn:h},p=m.getPrimaryForRange(f,a),v=r.getValue(0,0),C=(v==null?void 0:v.rowSpan)||1,_=(v==null?void 0:v.colSpan)||1;if((s===ge.DEFAULT_PASTE||s===ge.SPECIAL_PASTE_BESIDES_BORDER||s===ge.SPECIAL_PASTE_FORMAT)&&(C>1||_>1)){const y={startRow:u,endRow:u+C-1,startColumn:h,endColumn:h+_-1};p.startRow=y.startRow,p.endRow=y.endRow,p.startColumn=y.startColumn,p.endColumn=y.endColumn,p.isMerged=!0,p.isMergedMainCell=!0}const T={unitId:e,subUnitId:t,selections:[{range:{startRow:u,endRow:S,startColumn:h,endColumn:g},primary:p,style:null}]};return{id:m.SetSelectionsOperation.id,params:T}}_getPastingTarget(){const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),t=e.getActiveSheet(),i=this._selectionManagerService.getCurrentLastSelection();return{unitId:e.getUnitId(),subUnitId:t==null?void 0:t.getSheetId(),selection:i}}_transformPastedData(e,t,i){const r=this._getPastingTarget(),{selection:s,unitId:a,subUnitId:c}=r;if(!c||!s)return null;const d=this._injector.invoke(k=>on(s.range,k,a,c));if(!d)return null;const{ranges:[u],mapFunc:h}=Mt([d]),{startRow:S,startColumn:g,endRow:f,endColumn:p}=u,v=f-S+1,C=p-g+1,_=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),b=_==null?void 0:_.getActiveSheet();if(!b)return null;const P=b.getMergeData().filter(k=>d.rows.includes(k.startRow)&&d.cols.includes(k.startColumn)),y=P[0];let O=0,N=0,D=0,H=0;if(y&&(O=y.startRow,N=y.startColumn,D=y.endRow,H=y.endColumn),v%e===0&&C%t===0)if(P.length>0&&(v!==e||C!==t))if(O===d.rows[0]&&N===d.cols[0]&&D===d.rows[v-1]&&H===d.cols[C-1])if(kh(i))for(let V=0;V<v;V++)for(let U=0;U<C;U++){const x=i.getValue(V%e,U%t);x&&i.setValue(V,U,x)}else i.forValue((V,U,x)=>{x.s=null,delete x.colSpan,delete x.rowSpan});else for(let k=0;k<v;k++)for(let V=0;V<C;V++){const U=i.getValue(k%e,V%t);U&&i.setValue(k,V,U)}else for(let k=0;k<v;k++)for(let V=0;V<C;V++){const U=i.getValue(k%e,V%t);U&&i.setValue(k,V,U)}else if(P.length>0){const{row:k,col:V}=h(S,g);if(this._topLeftCellsMatch(e,t,{topRow:k,leftCol:V})){const x=this._expandOrShrinkRowsCols(a,c,d,t,e);d.rows=x.rows,d.cols=x.cols}else{if(f>y.endRow||p>y.endColumn)return null;i.forValue((x,B,j)=>{j.s=null,delete j.colSpan,delete j.rowSpan})}}else{const k=this._expandOrShrinkRowsCols(a,c,d,t,e);d.rows=k.rows,d.cols=k.cols}return{pastedRange:d,unitId:a,subUnitId:c}}_getPastedRange(e){var b;const t=this._getPastingTarget(),{selection:i,unitId:r,subUnitId:s}=t;if(!s||!i)return null;const a=this._injector.invoke(T=>on(i.range,T,r,s));if(!a)return null;const{startColumn:c,endColumn:d,startRow:u,endRow:h}=e.getDataRange(),S=h-u+1,g=d-c+1;if(S<=0||g<=0)return null;const f=a.rows.length,p=a.cols.length,v=(b=this._univerInstanceService.getUniverSheetInstance(r))==null?void 0:b.getSheetBySheetId(s);if(!v)return null;const C=v==null?void 0:v.getMergeData();if(f%S===0&&p%g===0&&!(C==null?void 0:C.some(P=>fr(P,a)))){for(let P=0;P<f;P++)for(let y=0;y<p;y++){const O=e.getValue(P%S,y%g);O&&e.setValue(P,y,O)}return{pastedRange:a,unitId:r,subUnitId:s}}const _=this._expandOrShrinkRowsCols(r,s,a,g,S);return a.rows=_.rows,a.cols=_.cols,{pastedRange:a,unitId:r,subUnitId:s}}_expandOrShrinkRowsCols(e,t,i,r,s){const{rows:a,cols:c}=i,d=this._univerInstanceService.getUniverSheetInstance(e),u=d==null?void 0:d.getSheetBySheetId(t);let h,S;if(a.length>=s)h=a.slice(0,s);else{h=a.slice(0);let g=a[a.length-1]+1;for(;h.length<s;)u.getRowFiltered(g)||h.push(g),g++}if(c.length>=r)S=c.slice(0,r);else{S=c.slice(0);let g=c[c.length-1]+1;for(;S.length<r;)S.push(g),g++}return{rows:h,cols:S}}_topLeftCellsMatch(e,t,i){const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),s=r==null?void 0:r.getActiveSheet();if(!s)return!1;const{topRow:a,leftCol:c}=i,d=Dh(a+e-1,c,c+t-1,s),u=Hh(c+t-1,a,a+e-1,s);return!d&&!u}removeMarkSelection(){this._copyMarkId&&(this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null)}_initUnitDisposed(){this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{e&&this.copyContentCache().clearWithUnitId(e.getUnitId())}))}disposePasteOptionsCache(){this.setShowMenu(!1),this.updatePasteOptionsCache(null)}},w.SheetClipboardService=Ah([Ne(0,l.ILogService),Ne(1,l.IUniverInstanceService),Ne(2,l.Inject(m.SheetsSelectionsService)),Ne(3,E.IClipboardInterfaceService),Ne(4,l.IUndoRedoService),Ne(5,l.ICommandService),Ne(6,Ht),Ne(7,E.INotificationService),Ne(8,E.IPlatformService),Ne(9,M.IRenderManagerService),Ne(10,l.Inject(l.ThemeService)),Ne(11,l.Inject(l.LocaleService)),Ne(12,l.Inject(l.ErrorService)),Ne(13,l.Inject(l.Injector))],w.SheetClipboardService);function Dl(n){let o="";const e=n.getLength();return n.forRow((t,i)=>{const r=[];i.forEach(s=>{const a=n.getValue(t,s);if(a){const c=Nh(a);r.push(c)}}),o+=r.join(" "),t!==e-1&&(o+=`
12
- `)}),o}function Nh(n){return l.isNotNullOrUndefined(n.displayV)?n.displayV:l.extractPureTextFromCell(n)}function Dh(n,o,e,t){return t.getMergeData().some(i=>i.startRow<=n&&n<i.endRow&&o<=i.startColumn&&i.startColumn<=e)}function Hh(n,o,e,t){return t.getMergeData().some(i=>i.startColumn<=n&&n<i.endColumn&&o<=i.startRow&&i.startRow<=e)}function kh(n){let o=0;return n.forValue((e,t,i)=>{if(i&&o++,o>1)return!1}),o>1}function qn(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const pr=998,Ye={id:E.CopyCommand.id,name:"sheet.command.copy",type:l.CommandType.COMMAND,multi:!0,priority:pr,preconditions:ar,handler:async n=>n.get(Xe).copy()},vr={id:E.CutCommand.id,name:"sheet.command.cut",type:l.CommandType.COMMAND,multi:!0,priority:pr,preconditions:ar,handler:async n=>n.get(Xe).cut()},Ge={id:E.PasteCommand.id,type:l.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:pr,preconditions:ar,handler:async(n,o)=>{const t=await n.get(E.IClipboardInterfaceService).read(),i=n.get(Xe);return t.length!==0?i.paste(t[0],o==null?void 0:o.value):!1}},Gi={id:E.SheetPasteShortKeyCommandName,type:l.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(Xe),{htmlContent:t,textContent:i}=o;return e.legacyPaste(t,i),!0}},pn={id:"sheet.command.paste-value",type:l.CommandType.COMMAND,handler:async n=>n.get(l.ICommandService).executeCommand(Ge.id,{value:ge.SPECIAL_PASTE_VALUE})},vn={id:"sheet.command.paste-format",type:l.CommandType.COMMAND,handler:async n=>n.get(l.ICommandService).executeCommand(Ge.id,{value:ge.SPECIAL_PASTE_FORMAT})},kt={id:"sheet.command.paste-col-width",type:l.CommandType.COMMAND,handler:async n=>n.get(l.ICommandService).executeCommand(Ge.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},Cn={id:"sheet.command.paste-besides-border",type:l.CommandType.COMMAND,handler:async n=>n.get(l.ICommandService).executeCommand(Ge.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},Hl={id:"sheet.command.optional-paste",type:l.CommandType.COMMAND,handler:async(n,{type:o})=>n.get(Xe).rePasteWithPasteType(o)},Qn={id:"sheet.command.hide-row-confirm",type:l.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(l.ICommandService),i=n.get(l.IUniverInstanceService),r=m.getSheetCommandTarget(i);if(!r)return!1;const{worksheet:s}=r,a=s.getVisibleRows();if(tl(a,e)){const d=n.get(E.IConfirmService),u=n.get(l.LocaleService);return await d.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetRowHiddenCommand.id),!0}},Jn={id:"sheet.command.hide-col-confirm",type:l.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(l.ICommandService),i=n.get(l.IUniverInstanceService),r=m.getSheetCommandTarget(i);if(!r)return!1;const{worksheet:s}=r,a=s.getVisibleCols();if(nl(a,e)){const d=n.get(E.IConfirmService),u=n.get(l.LocaleService);return await d.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetColHiddenCommand.id),!0}},Vt={type:l.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatBoldCommand.id):o.executeCommand(m.SetBoldCommand.id)}},xt={type:l.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatItalicCommand.id):o.executeCommand(m.SetItalicCommand.id)}},Wt={type:l.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatUnderlineCommand.id):o.executeCommand(m.SetUnderlineCommand.id)}},Lt={type:l.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatStrikethroughCommand.id):o.executeCommand(m.SetStrikeThroughCommand.id)}},Cr={type:l.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatSubscriptCommand.id):!1}},Ir={type:l.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatSuperscriptCommand.id):!1}},$n={type:l.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,o)=>{const e=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatFontSizeCommand.id,o):e.executeCommand(m.SetFontSizeCommand.id,o)}},ei={type:l.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,o)=>{const e=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatFontFamilyCommand.id,o):e.executeCommand(m.SetFontFamilyCommand.id,o)}},In={type:l.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,o)=>{const e=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatTextColorCommand.id,o):e.executeCommand(m.SetTextColorCommand.id,o)}},_r={type:l.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const o=n.get(l.ICommandService),t=n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED),i=n.get(l.ThemeService);return t?o.executeCommand(q.SetInlineFormatTextColorCommand.id,{value:null}):o.executeCommand(m.SetTextColorCommand.id,{value:i.getCurrentTheme().textColor})}};var Vh=Object.defineProperty,xh=Object.getOwnPropertyDescriptor,Wh=(n,o,e,t)=>{for(var i=t>1?void 0:t?xh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=(t?s(o,e,i):s(i))||i);return t&&i&&Vh(o,e,i),i},_n=(n,o)=>(e,t)=>o(e,t,n),He=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(He||{});const $e=l.createIdentifier("univer.format-painter-service");let Zi=class extends l.Disposable{constructor(o,e,t,i,r,s){super();R(this,"status$");R(this,"_selectionFormat");R(this,"_markId",null);R(this,"_status$");R(this,"_defaultHook",null);R(this,"_extendHooks",[]);this._selectionManagerService=o,this._themeService=e,this._markSelectionService=t,this._logService=i,this._commandService=r,this._undoRedoService=s,this._status$=new A.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new l.ObjectMatrix,merges:[]}}addHook(o){var e,t,i;o.isDefaultHook&&((e=o.priority)!=null?e:0)>((i=(t=this._defaultHook)==null?void 0:t.priority)!=null?i:-1)?this._defaultHook=o:(this._extendHooks.push(o),this._extendHooks.sort((r,s)=>(r.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(o){this._updateRangeMark(o),this._status$.next(o),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(o)})}getStatus(){return this._status$.getValue()}setSelectionFormat(o){this._selectionFormat=o}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(o,e,t){const i=this.getHooks(),r=[],s=[];i.forEach(c=>{if(c.onApply!==void 0){const d=c.onApply(o,e,t,this._selectionFormat);d&&(r.push(...d.redos),s.push(...d.undos))}});for(const c of i)if(c.onBeforeApply!==void 0&&!c.onBeforeApply({unitId:o,subUnitId:e,range:t,redoMutationsInfo:r,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:r});const a=r.every(c=>this._commandService.executeCommand(c.id,c.params));return a&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:s,redoMutations:r}),a}_updateRangeMark(o){if(this._markSelectionService.removeAllShapes(),o!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=Rl(this._themeService);o===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};Zi=Wh([_n(0,l.Inject(m.SheetsSelectionsService)),_n(1,l.Inject(l.ThemeService)),_n(2,Ht),_n(3,l.ILogService),_n(4,l.ICommandService),_n(5,l.IUndoRedoService)],Zi);const ti={id:"sheet.operation.set-format-painter",type:l.CommandType.OPERATION,handler:(n,o)=>o?(n.get($e).setStatus(o.status),!0):!1},Ki={type:l.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get($e).getStatus();let t;return e!==He.OFF?t=He.OFF:t=He.INFINITE,n.get(l.ICommandService).executeCommand(ti.id,{status:t})}},bn={type:l.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get($e).getStatus();let t;return e!==He.OFF?t=He.OFF:t=He.ONCE,n.get(l.ICommandService).executeCommand(ti.id,{status:t})}},ni={type:l.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,o)=>n.get($e).applyFormatPainter(o.unitId,o.subUnitId,o.range)},ot={type:l.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,o)=>{const{type:e}=o||{},t=n.get(l.IUniverInstanceService),i=n.get(l.IUndoRedoService),r=m.getSheetCommandTarget(t);if(!r)return!1;const{unitId:s,subUnitId:a}=r,c=n.get(l.ICommandService),u=n.get(m.SheetsSelectionsService).getCurrentSelections();if(!u)return!1;const h=u[(u==null?void 0:u.length)-1],{range:S}=h,f=n.get(M.IRenderManagerService).getRenderById(s).with(w.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,_,b,T;const{startRow:P,startColumn:y,rangeType:O}=S;if(O===l.RANGE_TYPE.ROW||e===1)C=P,b=P-p,_=-1,T=0;else if(O===l.RANGE_TYPE.COLUMN||e===2)C=-1,b=0,_=y,T=y-v;else if(O===l.RANGE_TYPE.NORMAL)C=P,b=P-p,_=y,T=y-v;else return!1;const N={unitId:s,subUnitId:a,startRow:C,startColumn:_,xSplit:_>0?Math.max(1,T):T,ySplit:C>0?Math.max(1,b):b},D=m.SetFrozenMutationFactory(n,N);return c.syncExecuteCommand(m.SetFrozenMutation.id,N)&&i.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:D}],redoMutations:[{id:m.SetFrozenMutation.id,params:N}]}),!0}},ii={type:l.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(l.ICommandService).executeCommand(ot.id,{type:1}),!0)},oi={type:l.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(l.ICommandService).executeCommand(ot.id,{type:2}),!0)};var Lh=Object.defineProperty,Uh=Object.getOwnPropertyDescriptor,Bh=(n,o,e,t)=>{for(var i=t>1?void 0:t?Uh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=(t?s(o,e,i):s(i))||i);return t&&i&&Lh(o,e,i),i},kl=(n,o)=>(e,t)=>o(e,t,n);const Fh=(n,o)=>{const{unitId:e,subUnitId:t,ranges:i}=n,r={},s=o.getColumnManager();for(let a=0;a<i.length;a++){const c=i[a];for(let d=c.startColumn;d<c.endColumn+1;d++){const u=s.getColumnOrCreate(d);r[d]=u.w}}return{unitId:e,subUnitId:t,ranges:i,colWidth:r}};w.AutoWidthController=class extends l.Disposable{constructor(o,e){super(),this._renderManagerService=o,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(o){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,i=m.getSheetCommandTarget(t);if(!i)return e;const{unitId:r,subUnitId:s,worksheet:a}=i,c=this._renderManagerService.getRenderById(r).with(w.SheetSkeletonManagerService);if(!c.getCurrent())return e;const{skeleton:d}=c.getCurrent(),u=d.calculateAutoWidthInRange(o.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const S={subUnitId:s,unitId:r,ranges:o.ranges,colWidth:h},g=Fh(S,a);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:g}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:S}]}}},w.AutoWidthController=Bh([kl(0,M.IRenderManagerService),kl(1,l.Inject(l.IUniverInstanceService))],w.AutoWidthController);const ri={type:l.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:async(n,o)=>{const e=n.get(l.ICommandService),t=n.get(l.IUndoRedoService),i=n.get(m.SheetsSelectionsService),r=n.get(l.IUniverInstanceService),s=m.getSheetCommandTarget(r,o);if(!s)return!1;const{unitId:a,subUnitId:c}=s;let d=[];if(o!=null&&o.ranges)d=[...o.ranges];else{const f=i.getCurrentSelections();for(let p=0;p<f.length;p++)d.push(f[p].range)}if(!(d!=null&&d.length))return!1;const u={unitId:a,subUnitId:c,ranges:d},{redos:h,undos:S}=n.get(w.AutoWidthController).getUndoRedoParamsOfColWidth(u);return l.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:a,undoMutations:[...S],redoMutations:[...h]}),!0):!1}},Rn="UI_PLUGIN_SHEETS",si=`${Rn}_COLOR_PICKER_COMPONENT`,qi=`${Rn}_FONT_FAMILY_COMPONENT`,Qi=`${Rn}_FONT_FAMILY_ITEM_COMPONENT`,Ji=`${Rn}_FONT_SIZE_COMPONENT`,$i=`${Rn}_MENU_ITEM_INPUT_COMPONENT`;var br={exports:{}},li={};/**
12
+ `)}),o}function Nh(n){return l.isNotNullOrUndefined(n.displayV)?n.displayV:l.extractPureTextFromCell(n)}function Dh(n,o,e,t){return t.getMergeData().some(i=>i.startRow<=n&&n<i.endRow&&o<=i.startColumn&&i.startColumn<=e)}function Hh(n,o,e,t){return t.getMergeData().some(i=>i.startColumn<=n&&n<i.endColumn&&o<=i.startRow&&i.startRow<=e)}function kh(n){let o=0;return n.forValue((e,t,i)=>{if(i&&o++,o>1)return!1}),o>1}function qn(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const pr=998,Ye={id:E.CopyCommand.id,name:"sheet.command.copy",type:l.CommandType.COMMAND,multi:!0,priority:pr,preconditions:ar,handler:async n=>n.get(Xe).copy()},vr={id:E.CutCommand.id,name:"sheet.command.cut",type:l.CommandType.COMMAND,multi:!0,priority:pr,preconditions:ar,handler:async n=>n.get(Xe).cut()},Ge={id:E.PasteCommand.id,type:l.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:pr,preconditions:ar,handler:async(n,o)=>{const t=await n.get(E.IClipboardInterfaceService).read(),i=n.get(Xe);return t.length!==0?i.paste(t[0],o==null?void 0:o.value):!1}},Gi={id:E.SheetPasteShortKeyCommandName,type:l.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(Xe),{htmlContent:t,textContent:i}=o;return e.legacyPaste(t,i),!0}},pn={id:"sheet.command.paste-value",type:l.CommandType.COMMAND,handler:async n=>n.get(l.ICommandService).executeCommand(Ge.id,{value:ge.SPECIAL_PASTE_VALUE})},vn={id:"sheet.command.paste-format",type:l.CommandType.COMMAND,handler:async n=>n.get(l.ICommandService).executeCommand(Ge.id,{value:ge.SPECIAL_PASTE_FORMAT})},kt={id:"sheet.command.paste-col-width",type:l.CommandType.COMMAND,handler:async n=>n.get(l.ICommandService).executeCommand(Ge.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},Cn={id:"sheet.command.paste-besides-border",type:l.CommandType.COMMAND,handler:async n=>n.get(l.ICommandService).executeCommand(Ge.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},Hl={id:"sheet.command.optional-paste",type:l.CommandType.COMMAND,handler:async(n,{type:o})=>n.get(Xe).rePasteWithPasteType(o)},Qn={id:"sheet.command.hide-row-confirm",type:l.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(l.ICommandService),i=n.get(l.IUniverInstanceService),r=m.getSheetCommandTarget(i);if(!r)return!1;const{worksheet:s}=r,a=s.getVisibleRows();if(tl(a,e)){const d=n.get(E.IConfirmService),u=n.get(l.LocaleService);return await d.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetRowHiddenCommand.id),!0}},Jn={id:"sheet.command.hide-col-confirm",type:l.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(l.ICommandService),i=n.get(l.IUniverInstanceService),r=m.getSheetCommandTarget(i);if(!r)return!1;const{worksheet:s}=r,a=s.getVisibleCols();if(nl(a,e)){const d=n.get(E.IConfirmService),u=n.get(l.LocaleService);return await d.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetColHiddenCommand.id),!0}},Vt={type:l.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatBoldCommand.id):o.executeCommand(m.SetBoldCommand.id)}},xt={type:l.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatItalicCommand.id):o.executeCommand(m.SetItalicCommand.id)}},Wt={type:l.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatUnderlineCommand.id):o.executeCommand(m.SetUnderlineCommand.id)}},Lt={type:l.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatStrikethroughCommand.id):o.executeCommand(m.SetStrikeThroughCommand.id)}},Cr={type:l.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatSubscriptCommand.id):!1}},Ir={type:l.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const o=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?o.executeCommand(q.SetInlineFormatSuperscriptCommand.id):!1}},$n={type:l.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,o)=>{const e=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatFontSizeCommand.id,o):e.executeCommand(m.SetFontSizeCommand.id,o)}},ei={type:l.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,o)=>{const e=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatFontFamilyCommand.id,o):e.executeCommand(m.SetFontFamilyCommand.id,o)}},In={type:l.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,o)=>{const e=n.get(l.ICommandService);return n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatTextColorCommand.id,o):e.executeCommand(m.SetTextColorCommand.id,o)}},_r={type:l.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const o=n.get(l.ICommandService),t=n.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED),i=n.get(l.ThemeService);return t?o.executeCommand(q.SetInlineFormatTextColorCommand.id,{value:null}):o.executeCommand(m.SetTextColorCommand.id,{value:i.getCurrentTheme().textColor})}};var Vh=Object.defineProperty,xh=Object.getOwnPropertyDescriptor,Wh=(n,o,e,t)=>{for(var i=t>1?void 0:t?xh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=(t?s(o,e,i):s(i))||i);return t&&i&&Vh(o,e,i),i},_n=(n,o)=>(e,t)=>o(e,t,n),He=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(He||{});const $e=l.createIdentifier("univer.format-painter-service");let Zi=class extends l.Disposable{constructor(o,e,t,i,r,s){super();R(this,"status$");R(this,"_selectionFormat");R(this,"_markId",null);R(this,"_status$");R(this,"_defaultHook",null);R(this,"_extendHooks",[]);this._selectionManagerService=o,this._themeService=e,this._markSelectionService=t,this._logService=i,this._commandService=r,this._undoRedoService=s,this._status$=new A.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new l.ObjectMatrix,merges:[]}}addHook(o){var e,t,i;o.isDefaultHook&&((e=o.priority)!=null?e:0)>((i=(t=this._defaultHook)==null?void 0:t.priority)!=null?i:-1)?this._defaultHook=o:(this._extendHooks.push(o),this._extendHooks.sort((r,s)=>(r.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(o){this._updateRangeMark(o),this._status$.next(o),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(o)})}getStatus(){return this._status$.getValue()}setSelectionFormat(o){this._selectionFormat=o}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(o,e,t){const i=this.getHooks(),r=[],s=[];i.forEach(c=>{if(c.onApply!==void 0){const d=c.onApply(o,e,t,this._selectionFormat);d&&(r.push(...d.redos),s.push(...d.undos))}});for(const c of i)if(c.onBeforeApply!==void 0&&!c.onBeforeApply({unitId:o,subUnitId:e,range:t,redoMutationsInfo:r,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:r});const a=r.every(c=>this._commandService.executeCommand(c.id,c.params));return a&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:s,redoMutations:r}),a}_updateRangeMark(o){if(this._markSelectionService.removeAllShapes(),o!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=Rl(this._themeService);o===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};Zi=Wh([_n(0,l.Inject(m.SheetsSelectionsService)),_n(1,l.Inject(l.ThemeService)),_n(2,Ht),_n(3,l.ILogService),_n(4,l.ICommandService),_n(5,l.IUndoRedoService)],Zi);const ti={id:"sheet.operation.set-format-painter",type:l.CommandType.OPERATION,handler:(n,o)=>o?(n.get($e).setStatus(o.status),!0):!1},Ki={type:l.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get($e).getStatus();let t;return e!==He.OFF?t=He.OFF:t=He.INFINITE,n.get(l.ICommandService).executeCommand(ti.id,{status:t})}},bn={type:l.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get($e).getStatus();let t;return e!==He.OFF?t=He.OFF:t=He.ONCE,n.get(l.ICommandService).executeCommand(ti.id,{status:t})}},ni={type:l.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,o)=>n.get($e).applyFormatPainter(o.unitId,o.subUnitId,o.range)},ot={type:l.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,o)=>{const{type:e}=o||{},t=n.get(l.IUniverInstanceService),i=n.get(l.IUndoRedoService),r=m.getSheetCommandTarget(t);if(!r)return!1;const{unitId:s,subUnitId:a}=r,c=n.get(l.ICommandService),u=n.get(m.SheetsSelectionsService).getCurrentSelections();if(!u)return!1;const h=u[(u==null?void 0:u.length)-1],{range:S}=h,f=n.get(M.IRenderManagerService).getRenderById(s).with(w.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,_,b,T;const{startRow:P,startColumn:y,rangeType:O}=S;if(O===l.RANGE_TYPE.ROW||e===1)C=P,b=P-p,_=-1,T=0;else if(O===l.RANGE_TYPE.COLUMN||e===2)C=-1,b=0,_=y,T=y-v;else if(O===l.RANGE_TYPE.NORMAL)C=P,b=P-p,_=y,T=y-v;else return!1;const N={unitId:s,subUnitId:a,startRow:C,startColumn:_,xSplit:_>0?Math.max(1,T):T,ySplit:C>0?Math.max(1,b):b},D=m.SetFrozenMutationFactory(n,N);return c.syncExecuteCommand(m.SetFrozenMutation.id,N)&&i.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:D}],redoMutations:[{id:m.SetFrozenMutation.id,params:N}]}),!0}},ii={type:l.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(l.ICommandService).executeCommand(ot.id,{type:1}),!0)},oi={type:l.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(l.ICommandService).executeCommand(ot.id,{type:2}),!0)};var Lh=Object.defineProperty,Uh=Object.getOwnPropertyDescriptor,Bh=(n,o,e,t)=>{for(var i=t>1?void 0:t?Uh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=(t?s(o,e,i):s(i))||i);return t&&i&&Lh(o,e,i),i},kl=(n,o)=>(e,t)=>o(e,t,n);const Fh=(n,o)=>{const{unitId:e,subUnitId:t,ranges:i}=n,r={},s=o.getColumnManager();for(let a=0;a<i.length;a++){const c=i[a];for(let d=c.startColumn;d<c.endColumn+1;d++){const u=s.getColumnOrCreate(d);r[d]=u.w}}return{unitId:e,subUnitId:t,ranges:i,colWidth:r}};w.AutoWidthController=class extends l.Disposable{constructor(o,e){super(),this._renderManagerService=o,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(o){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,i=m.getSheetCommandTarget(t);if(!i)return e;const{unitId:r,subUnitId:s,worksheet:a}=i,c=this._renderManagerService.getRenderById(r).with(w.SheetSkeletonManagerService);if(!c.getCurrent())return e;const{skeleton:d}=c.getCurrent(),u=d.calculateAutoWidthInRange(o.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const S={subUnitId:s,unitId:r,ranges:o.ranges,colWidth:h},g=Fh(S,a);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:g}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:S}]}}},w.AutoWidthController=Bh([kl(0,M.IRenderManagerService),kl(1,l.Inject(l.IUniverInstanceService))],w.AutoWidthController);const ri={type:l.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:(n,o)=>{const e=n.get(l.ICommandService),t=n.get(l.IUndoRedoService),i=n.get(m.SheetsSelectionsService),r=n.get(l.IUniverInstanceService),s=m.getSheetCommandTarget(r,o);if(!s)return!1;const{unitId:a,subUnitId:c}=s;let d=[];if(o!=null&&o.ranges)d=[...o.ranges];else{const f=i.getCurrentSelections();for(let p=0;p<f.length;p++)d.push(f[p].range)}if(!(d!=null&&d.length))return!1;const u={unitId:a,subUnitId:c,ranges:d},{redos:h,undos:S}=n.get(w.AutoWidthController).getUndoRedoParamsOfColWidth(u);return l.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:a,undoMutations:[...S],redoMutations:[...h]}),!0):!1}},Rn="UI_PLUGIN_SHEETS",si=`${Rn}_COLOR_PICKER_COMPONENT`,qi=`${Rn}_FONT_FAMILY_COMPONENT`,Qi=`${Rn}_FONT_FAMILY_ITEM_COMPONENT`,Ji=`${Rn}_FONT_SIZE_COMPONENT`,$i=`${Rn}_MENU_ITEM_INPUT_COMPONENT`;var br={exports:{}},li={};/**
13
13
  * @license React
14
14
  * react-jsx-runtime.production.min.js
15
15
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-ui",
3
- "version": "0.5.5-nightly.202501201606",
3
+ "version": "0.5.5-nightly.202501210404",
4
4
  "private": false,
5
5
  "description": "UniverSheet normal ui-plugin-sheets",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -62,16 +62,16 @@
62
62
  "@univerjs/icons": "^0.2.12",
63
63
  "@univerjs/protocol": "0.1.40",
64
64
  "clsx": "^2.1.1",
65
- "@univerjs/core": "0.5.5-nightly.202501201606",
66
- "@univerjs/design": "0.5.5-nightly.202501201606",
67
- "@univerjs/docs": "0.5.5-nightly.202501201606",
68
- "@univerjs/docs-ui": "0.5.5-nightly.202501201606",
69
- "@univerjs/engine-numfmt": "0.5.5-nightly.202501201606",
70
- "@univerjs/engine-formula": "0.5.5-nightly.202501201606",
71
- "@univerjs/engine-render": "0.5.5-nightly.202501201606",
72
- "@univerjs/ui": "0.5.5-nightly.202501201606",
73
- "@univerjs/sheets": "0.5.5-nightly.202501201606",
74
- "@univerjs/telemetry": "0.5.5-nightly.202501201606"
65
+ "@univerjs/core": "0.5.5-nightly.202501210404",
66
+ "@univerjs/design": "0.5.5-nightly.202501210404",
67
+ "@univerjs/docs": "0.5.5-nightly.202501210404",
68
+ "@univerjs/docs-ui": "0.5.5-nightly.202501210404",
69
+ "@univerjs/engine-formula": "0.5.5-nightly.202501210404",
70
+ "@univerjs/engine-numfmt": "0.5.5-nightly.202501210404",
71
+ "@univerjs/engine-render": "0.5.5-nightly.202501210404",
72
+ "@univerjs/sheets": "0.5.5-nightly.202501210404",
73
+ "@univerjs/telemetry": "0.5.5-nightly.202501210404",
74
+ "@univerjs/ui": "0.5.5-nightly.202501210404"
75
75
  },
76
76
  "devDependencies": {
77
77
  "less": "^4.2.1",