@univerjs/sheets-note 0.15.3 → 0.15.4-insiders.20260211-f06b0a7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/facade.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@univerjs/core/facade"),c=require("@univerjs/sheets-note"),u=require("@univerjs/sheets/facade"),N=require("@univerjs/core");class v{get SheetNoteAdd(){return"SheetNoteAdd"}get SheetNoteDelete(){return"SheetNoteDelete"}get SheetNoteUpdate(){return"SheetNoteUpdate"}get SheetNoteShow(){return"SheetNoteShow"}get SheetNoteHide(){return"SheetNoteHide"}get BeforeSheetNoteAdd(){return"BeforeSheetNoteAdd"}get BeforeSheetNoteDelete(){return"BeforeSheetNoteDelete"}get BeforeSheetNoteUpdate(){return"BeforeSheetNoteUpdate"}get BeforeSheetNoteShow(){return"BeforeSheetNoteShow"}get BeforeSheetNoteHide(){return"BeforeSheetNoteHide"}}f.FEventName.extend(v);class w extends u.FRange{createOrUpdateNote(h){return this._commandService.syncExecuteCommand(c.UpdateNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:h}),this}deleteNote(){return this._commandService.syncExecuteCommand(c.RemoveNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(c.SheetsNoteModel).getNote(this.getUnitId(),this.getSheetId(),this.getRow(),this.getColumn())}}u.FRange.extend(w);class E extends f.FUniver{_initialize(h){this.registerEventHandler(this.Event.SheetNoteAdd,()=>h.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&!e.oldNote&&e.note){const{unitId:d,sheetId:t,row:o,col:s,note:r,oldNote:i}=e,n=this.getSheetTarget(d,t);if(!n)return;const{workbook:S,worksheet:l}=n;this.fireEvent(this.Event.SheetNoteAdd,{workbook:S,worksheet:l,row:o,col:s,note:r})}})),this.registerEventHandler(this.Event.SheetNoteDelete,()=>h.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&!e.note){const{unitId:d,sheetId:t,row:o,col:s,note:r,oldNote:i}=e,n=this.getSheetTarget(d,t);if(!n)return;const{workbook:S,worksheet:l}=n;this.fireEvent(this.Event.SheetNoteDelete,{workbook:S,worksheet:l,row:o,col:s,oldNote:i})}})),this.registerEventHandler(this.Event.SheetNoteUpdate,()=>h.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note){const{unitId:d,sheetId:t,row:o,col:s,note:r,oldNote:i}=e,n=this.getSheetTarget(d,t);if(!n)return;const{workbook:S,worksheet:l}=n;this.fireEvent(this.Event.SheetNoteUpdate,{workbook:S,worksheet:l,row:o,col:s,note:r,oldNote:i})}})),this.registerEventHandler(this.Event.SheetNoteShow,()=>h.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note&&!e.oldNote.show&&e.note.show){const{unitId:d,sheetId:t,row:o,col:s}=e,r=this.getSheetTarget(d,t);if(!r)return;const{workbook:i,worksheet:n}=r;this.fireEvent(this.Event.SheetNoteShow,{workbook:i,worksheet:n,row:o,col:s})}})),this.registerEventHandler(this.Event.SheetNoteHide,()=>h.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note&&e.oldNote.show&&!e.note.show){const{unitId:d,sheetId:t,row:o,col:s}=e,r=this.getSheetTarget(d,t);if(!r)return;const{workbook:i,worksheet:n}=r;this.fireEvent(this.Event.SheetNoteHide,{workbook:i,worksheet:n,row:o,col:s})}})),this.registerEventHandler(this.Event.BeforeSheetNoteAdd,()=>h.get(N.ICommandService).beforeCommandExecuted(e=>{if(e.id===c.SheetUpdateNoteCommand.id){const d=h.get(c.SheetsNoteModel),{unitId:t,sheetId:o,row:s,col:r,note:i}=e.params;if(d.getNote(t,o,s,r))return;const S=this.getSheetTarget(t,o);if(!S)return;const{workbook:l,worksheet:g}=S;if(this.fireEvent(this.Event.BeforeSheetNoteAdd,{workbook:l,worksheet:g,row:s,col:r,note:i}))throw new N.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>h.get(N.ICommandService).beforeCommandExecuted(e=>{if(e.id===c.SheetDeleteNoteCommand.id){const d=h.get(c.SheetsNoteModel),{unitId:t,sheetId:o,row:s,col:r}=e.params,i=d.getNote(t,o,s,r);if(!i)return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:S,worksheet:l}=n;if(this.fireEvent(this.Event.BeforeSheetNoteDelete,{workbook:S,worksheet:l,row:s,col:r,oldNote:i}))throw new N.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>h.get(N.ICommandService).beforeCommandExecuted(e=>{if(e.id===c.SheetUpdateNoteCommand.id){const d=h.get(c.SheetsNoteModel),{unitId:t,sheetId:o,row:s,col:r,note:i}=e.params,n=d.getNote(t,o,s,r);if(!n)return;const S=this.getSheetTarget(t,o);if(!S)return;const{workbook:l,worksheet:g}=S;if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,{workbook:l,worksheet:g,row:s,col:r,note:i,oldNote:n}))throw new N.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>h.get(N.ICommandService).beforeCommandExecuted(e=>{if(e.id===c.SheetToggleNotePopupCommand.id){const d=h.get(c.SheetsNoteModel),{unitId:t,sheetId:o,row:s,col:r}=e.params,i=d.getNote(t,o,s,r);if(i!=null&&i.show)return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:S,worksheet:l}=n;if(this.fireEvent(this.Event.BeforeSheetNoteShow,{workbook:S,worksheet:l,row:s,col:r}))throw new N.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>h.get(N.ICommandService).beforeCommandExecuted(e=>{if(e.id===c.SheetToggleNotePopupCommand.id){const d=h.get(c.SheetsNoteModel),{unitId:t,sheetId:o,row:s,col:r}=e.params,i=d.getNote(t,o,s,r);if(!(i!=null&&i.show))return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:S,worksheet:l}=n;if(this.fireEvent(this.Event.BeforeSheetNoteHide,{workbook:S,worksheet:l,row:s,col:r}))throw new N.CanceledError}}))}}f.FUniver.extend(E);class I extends u.FWorksheet{getNotes(){const a=this._injector.get(c.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId()),e=[];return a==null||a.forValue((d,t,o)=>{e.push({...o,row:d,col:t})}),e}}u.FWorksheet.extend(I);exports.FSheetNoteEvent=v;exports.FSheetsNoteRangeMixin=w;exports.FSheetsNoteWorksheet=I;exports.FUniverSheetNoteMixin=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core/facade"),c=require("@univerjs/sheets-note"),f=require("@univerjs/sheets/facade"),u=require("@univerjs/core"),w=require("@univerjs/sheets");class E{get SheetNoteAdd(){return"SheetNoteAdd"}get SheetNoteDelete(){return"SheetNoteDelete"}get SheetNoteUpdate(){return"SheetNoteUpdate"}get SheetNoteShow(){return"SheetNoteShow"}get SheetNoteHide(){return"SheetNoteHide"}get BeforeSheetNoteAdd(){return"BeforeSheetNoteAdd"}get BeforeSheetNoteDelete(){return"BeforeSheetNoteDelete"}get BeforeSheetNoteUpdate(){return"BeforeSheetNoteUpdate"}get BeforeSheetNoteShow(){return"BeforeSheetNoteShow"}get BeforeSheetNoteHide(){return"BeforeSheetNoteHide"}}m.FEventName.extend(E);class p extends f.FRange{createOrUpdateNote(i){return this._commandService.syncExecuteCommand(c.UpdateNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:i}),this}deleteNote(){return this._commandService.syncExecuteCommand(c.RemoveNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(c.SheetsNoteModel).getNote(this.getUnitId(),this.getSheetId(),{row:this.getRow(),col:this.getColumn()})}}f.FRange.extend(p);class I extends m.FUniver{_initialize(i){const N=i.get(u.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteAdd,()=>i.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&!e.oldNote&&e.newNote){const{unitId:r,subUnitId:s,newNote:t}=e,o=this.getSheetTarget(r,s);if(!o)return;const{workbook:d,worksheet:n}=o;this.fireEvent(this.Event.SheetNoteAdd,{workbook:d,worksheet:n,row:t.row,col:t.col,note:t})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteDelete,()=>i.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&!e.newNote){const{unitId:r,subUnitId:s,oldNote:t}=e,o=this.getSheetTarget(r,s);if(!o)return;const{workbook:d,worksheet:n}=o;this.fireEvent(this.Event.SheetNoteDelete,{workbook:d,worksheet:n,row:t.row,col:t.col,oldNote:t})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteUpdate,()=>i.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.newNote){const{unitId:r,subUnitId:s,oldNote:t,newNote:o}=e,d=this.getSheetTarget(r,s);if(!d)return;const{workbook:n,worksheet:l}=d;this.fireEvent(this.Event.SheetNoteUpdate,{workbook:n,worksheet:l,row:o.row,col:o.col,note:o,oldNote:t})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteShow,()=>i.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.newNote&&!e.oldNote.show&&e.newNote.show){const{unitId:r,subUnitId:s,newNote:t}=e,o=this.getSheetTarget(r,s);if(!o)return;const{workbook:d,worksheet:n}=o;this.fireEvent(this.Event.SheetNoteShow,{workbook:d,worksheet:n,row:t.row,col:t.col})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteHide,()=>i.get(c.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.newNote&&e.oldNote.show&&!e.newNote.show){const{unitId:r,subUnitId:s,newNote:t}=e,o=this.getSheetTarget(r,s);if(!o)return;const{workbook:d,worksheet:n}=o;this.fireEvent(this.Event.SheetNoteHide,{workbook:d,worksheet:n,row:t.row,col:t.col})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteAdd,()=>N.beforeCommandExecuted(h=>{if(h.id===c.SheetUpdateNoteCommand.id){const{unitId:e,sheetId:r,row:s,col:t,note:o}=h.params,d=this.getSheetTarget(e,r);if(!d||i.get(c.SheetsNoteModel).getNote(e,r,{noteId:o.id,row:s,col:t}))return;const{workbook:S,worksheet:a}=d;if(this.fireEvent(this.Event.BeforeSheetNoteAdd,{workbook:S,worksheet:a,row:s,col:t,note:o}))throw new u.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>N.beforeCommandExecuted(h=>{if(h.id===c.SheetDeleteNoteCommand.id){const{unitId:e,sheetId:r,row:s,col:t}=h.params,o=this.getSheetTarget(e,r);if(!o||s===void 0||t===void 0)return;const n=i.get(c.SheetsNoteModel).getNote(e,r,{row:s,col:t});if(!n)return;const{workbook:l,worksheet:S}=o;if(this.fireEvent(this.Event.BeforeSheetNoteDelete,{workbook:l,worksheet:S,row:s,col:t,oldNote:n}))throw new u.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>N.beforeCommandExecuted(h=>{if(h.id===c.SheetUpdateNoteCommand.id){const{unitId:e,sheetId:r,row:s,col:t,note:o}=h.params,d=this.getSheetTarget(e,r);if(!d)return;const l=i.get(c.SheetsNoteModel).getNote(e,r,{row:s,col:t});if(!l)return;const{workbook:S,worksheet:a}=d;if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,{workbook:S,worksheet:a,row:s,col:t,note:o,oldNote:l}))throw new u.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>N.beforeCommandExecuted(h=>{if(h.id===c.SheetToggleNotePopupCommand.id){const e=w.getSheetCommandTarget(i.get(u.IUniverInstanceService));if(!e)return;const{unitId:r,subUnitId:s}=e,t=this.getUniverSheet(r);if(!t)return;const o=t.getSheetBySheetId(s);if(!o)return;const n=i.get(w.SheetsSelectionsService).getCurrentLastSelection();if(!(n!=null&&n.primary))return;const l=i.get(c.SheetsNoteModel),{actualColumn:S,actualRow:a}=n.primary,g=l.getNote(r,s,{row:a,col:S});if(!g||g.show)return;if(this.fireEvent(this.Event.BeforeSheetNoteShow,{workbook:t,worksheet:o,row:a,col:S}))throw new u.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>N.beforeCommandExecuted(h=>{if(h.id===c.SheetToggleNotePopupCommand.id){const e=w.getSheetCommandTarget(i.get(u.IUniverInstanceService));if(!e)return;const{unitId:r,subUnitId:s}=e,t=this.getUniverSheet(r);if(!t)return;const o=t.getSheetBySheetId(s);if(!o)return;const n=i.get(w.SheetsSelectionsService).getCurrentLastSelection();if(!(n!=null&&n.primary))return;const l=i.get(c.SheetsNoteModel),{actualColumn:S,actualRow:a}=n.primary,g=l.getNote(r,s,{row:a,col:S});if(!g||!g.show)return;if(this.fireEvent(this.Event.BeforeSheetNoteHide,{workbook:t,worksheet:o,row:a,col:S}))throw new u.CanceledError}})))}}m.FUniver.extend(I);class k extends f.FWorksheet{getNotes(){const N=this._injector.get(c.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId());return N?Array.from(N.values()).map(h=>({...h})):[]}}f.FWorksheet.extend(k);exports.FSheetNoteEvent=E;exports.FSheetsNoteRangeMixin=p;exports.FSheetsNoteWorksheet=k;exports.FUniverSheetNoteMixin=I;
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var E=Object.defineProperty;var $=(i,o,t)=>o in i?E(i,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[o]=t;var g=(i,o,t)=>$(i,typeof o!="symbol"?o+"":o,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@univerjs/core"),l=require("@univerjs/sheets"),N=require("rxjs");class p extends h.Disposable{constructor(){super(...arguments);g(this,"_noteMatrix",new Map);g(this,"_change$",new N.Subject);g(this,"change$",this._change$.asObservable())}_ensureNoteMatrix(t,s){let e=this._noteMatrix.get(t);e||(e=new Map,this._noteMatrix.set(t,e));let n=e.get(s);return n||(n=new h.ObjectMatrix,e.set(s,n)),n}getSheetShowNotes$(t,s){return this._change$.pipe(N.filter(({unitId:e,sheetId:n})=>e===t&&n===s),N.map(()=>{const e=this._ensureNoteMatrix(t,s),n=[];return e.forValue((r,a,c)=>{c.show&&n.push({loc:{row:r,col:a,unitId:t,subUnitId:s},note:c})}),n}))}getCellNoteChange$(t,s,e,n){return this._change$.pipe(N.filter(({unitId:r,sheetId:a,row:c,col:d})=>r===t&&a===s&&c===e&&d===n),N.map(({note:r})=>r))}updateNote(t,s,e,n,r,a){const c=this._ensureNoteMatrix(t,s),d=c.getValue(e,n);c.setValue(e,n,r),this._change$.next({unitId:t,sheetId:s,row:e,col:n,type:"update",note:r,oldNote:d,silent:a})}removeNote(t,s,e,n,r){const a=this._ensureNoteMatrix(t,s),c=a.getValue(e,n);a.realDeleteValue(e,n),this._change$.next({unitId:t,sheetId:s,row:e,col:n,type:"update",note:null,oldNote:c,silent:r})}toggleNotePopup(t,s,e,n,r){const a=this._ensureNoteMatrix(t,s),c=a.getValue(e,n);if(c){c.show=!c.show;const d={...c,show:c.show};a.setValue(e,n,d),this._change$.next({unitId:t,sheetId:s,row:e,col:n,type:"update",note:d,oldNote:c,silent:r})}}updateNotePosition(t,s,e,n,r,a,c){const d=this._ensureNoteMatrix(t,s),u=d.getValue(e,n);u&&(d.realDeleteValue(e,n),d.setValue(r,a,u),this._change$.next({unitId:t,sheetId:s,row:e,col:n,type:"ref",newPosition:{row:r,col:a},note:u,silent:c}))}getNote(t,s,e,n){return this._ensureNoteMatrix(t,s).getValue(e,n)}getUnitNotes(t){return this._noteMatrix.get(t)}getSheetNotes(t,s){const e=this._noteMatrix.get(t);if(e)return e.get(s)}getNotes(){return this._noteMatrix}deleteUnitNotes(t){this._noteMatrix.delete(t)}}const _={id:"sheet.mutation.update-note",type:h.CommandType.MUTATION,handler:(i,o)=>{const{unitId:t,sheetId:s,row:e,col:n,note:r,silent:a}=o;return i.get(p).updateNote(t,s,e,n,r,a),!0}},S={id:"sheet.mutation.remove-note",type:h.CommandType.MUTATION,handler:(i,o)=>{const{unitId:t,sheetId:s,row:e,col:n,silent:r}=o;return i.get(p).removeNote(t,s,e,n,r),!0}},y={id:"sheet.mutation.toggle-note-popup",type:h.CommandType.MUTATION,handler:(i,o)=>{const{unitId:t,sheetId:s,row:e,col:n,silent:r}=o;return i.get(p).toggleNotePopup(t,s,e,n,r),!0}},M={id:"sheet.mutation.update-note-position",type:h.CommandType.MUTATION,handler:(i,o)=>{const{unitId:t,sheetId:s,row:e,col:n,newPosition:r,silent:a}=o;return i.get(p).updateNotePosition(t,s,e,n,r.row,r.col,a),!0}},P={id:"sheet.command.delete-note",type:h.CommandType.COMMAND,handler:(i,o)=>{const t=i.get(h.IUniverInstanceService),s=l.getSheetCommandTarget(t);if(!s)return!1;const n=i.get(l.SheetsSelectionsService).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;const{actualColumn:r,actualRow:a}=n.primary;return i.get(h.ICommandService).executeCommand(S.id,{unitId:s.unitId,sheetId:s.subUnitId,row:a,col:r})}},w={id:"sheet.command.toggle-note-popup",type:h.CommandType.COMMAND,handler:(i,o)=>{const t=i.get(h.IUniverInstanceService),s=l.getSheetCommandTarget(t);if(!s)return!1;const n=i.get(l.SheetsSelectionsService).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;const{actualColumn:r,actualRow:a}=n.primary;return i.get(h.ICommandService).executeCommand(y.id,{unitId:s.unitId,sheetId:s.subUnitId,row:a,col:r})}},x={id:"sheet.command.update-note",type:h.CommandType.COMMAND,handler:(i,o)=>i.get(h.ICommandService).syncExecuteCommand(_.id,o)},T="SHEET_NOTE_PLUGIN";var D=Object.getOwnPropertyDescriptor,j=(i,o,t,s)=>{for(var e=s>1?void 0:s?D(o,t):o,n=i.length-1,r;n>=0;n--)(r=i[n])&&(e=r(e)||e);return e},v=(i,o)=>(t,s)=>o(t,s,i);exports.SheetsNoteResourceController=class extends h.Disposable{constructor(o,t,s,e){super(),this._resourceManagerService=o,this._univerInstanceService=t,this._sheetInterceptorService=s,this._sheetsNoteModel=e,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){const o=s=>{const e=this._sheetsNoteModel.getUnitNotes(s);if(!e)return"";const n={};return e.forEach((r,a)=>{const c={};r.forValue((d,u,m)=>{c[d]||(c[d]={}),c[d][u]=m}),Object.keys(c).length>0&&(n[a]=c)}),JSON.stringify(n)},t=s=>{if(!s)return{};try{return JSON.parse(s)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:T,businesses:[h.UniverInstanceType.UNIVER_SHEET],toJson:s=>o(s),parseJson:s=>t(s),onUnLoad:s=>{this._sheetsNoteModel.deleteUnitNotes(s)},onLoad:(s,e)=>{Object.entries(e).forEach(([n,r])=>{Object.entries(r).forEach(([a,c])=>{Object.entries(c).forEach(([d,u])=>{this._sheetsNoteModel.updateNote(s,n,Number(a),Number(d),u)})})})}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{var t;if(o.id===l.RemoveSheetCommand.id){const s=o.params,e=s.unitId||this._univerInstanceService.getCurrentUnitOfType(h.UniverInstanceType.UNIVER_SHEET).getUnitId(),n=s.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(h.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!e||!n)return{redos:[],undos:[]};const r=this._sheetsNoteModel.getSheetNotes(e,n);if(!r)return{redos:[],undos:[]};const a=[],c=[];return r.forValue((d,u,m)=>{a.push({id:S.id,params:{unitId:e,sheetId:n,row:d,col:u}}),c.push({id:_.id,params:{unitId:e,sheetId:n,row:d,col:u,note:m}})}),{redos:a,undos:c}}else if(o.id===l.CopySheetCommand.id){const s=o.params,{unitId:e,subUnitId:n,targetSubUnitId:r}=s;if(!e||!n||!r)return{redos:[],undos:[]};const a=this._sheetsNoteModel.getSheetNotes(e,n);if(!a)return{redos:[],undos:[]};const c=[],d=[];return a.forValue((u,m,b)=>{c.push({id:_.id,params:{unitId:e,sheetId:r,row:u,col:m,note:b}}),d.push({id:S.id,params:{unitId:e,sheetId:r,row:u,col:m}})}),{redos:c,undos:d}}return{redos:[],undos:[]}}}))}};exports.SheetsNoteResourceController=j([v(0,h.IResourceManagerService),v(1,h.IUniverInstanceService),v(2,h.Inject(l.SheetInterceptorService)),v(3,h.Inject(p))],exports.SheetsNoteResourceController);const V="sheets-note.config",R={};var A=Object.getOwnPropertyDescriptor,W=(i,o,t,s)=>{for(var e=s>1?void 0:s?A(o,t):o,n=i.length-1,r;n>=0;n--)(r=i[n])&&(e=r(e)||e);return e},f=(i,o)=>(t,s)=>o(t,s,i);let C=class extends h.Disposable{constructor(o,t,s,e){super();g(this,"_disposableMap",new Map);g(this,"_watcherMap",new Map);g(this,"_handleRangeChange",(o,t,s,e,n,r,a)=>r?{redos:[{id:M.id,params:{unitId:o,sheetId:t,row:e,col:n,newPosition:{row:r.startRow,col:r.startColumn},silent:a}}],undos:[{id:M.id,params:{unitId:o,sheetId:t,row:r.startRow,col:r.startColumn,newPosition:{row:e,col:n},note:s,silent:a}}]}:{redos:[{id:S.id,params:{unitId:o,sheetId:t,row:e,col:n}}],undos:[{id:_.id,params:{unitId:o,sheetId:t,row:e,col:n,note:s}}]});this._refRangeService=o,this._sheetsNoteModel=t,this._selectionManagerService=s,this._commandService=e,this._initData(),this._initRefRange()}_getIdWithUnitId(o,t,s,e){return`${o}-${t}-${s}-${e}`}_register(o,t,s,e,n){const r={startColumn:n,endColumn:n,startRow:e,endRow:e};this._disposableMap.set(this._getIdWithUnitId(o,t,e,n),this._refRangeService.registerRefRange(r,a=>{const c=l.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(r,a,{selectionManagerService:this._selectionManagerService}),d=Array.isArray(c)?c[0]:c;return d&&d.startColumn===r.startColumn&&d.startRow===r.startRow?{undos:[],redos:[]}:this._handleRangeChange(o,t,s,e,n,d,!1)},o,t))}_watch(o,t,s,e,n){const r={startColumn:n,endColumn:n,startRow:e,endRow:e};this._watcherMap.set(this._getIdWithUnitId(o,t,e,n),this._refRangeService.watchRange(o,t,r,(a,c)=>{const{redos:d}=this._handleRangeChange(o,t,s,a.startRow,a.startColumn,c,!0);h.sequenceExecuteAsync(d,this._commandService,{onlyLocal:!0})},!0))}_unwatch(o,t,s,e){var r;const n=this._getIdWithUnitId(o,t,s,e);(r=this._watcherMap.get(n))==null||r.dispose(),this._watcherMap.delete(n)}_unregister(o,t,s,e){var r;const n=this._getIdWithUnitId(o,t,s,e);(r=this._disposableMap.get(n))==null||r.dispose(),this._disposableMap.delete(n)}_initData(){const o=this._sheetsNoteModel.getNotes();for(const[t,s]of o)for(const[e,n]of s)n.forValue((r,a,c)=>(c&&(this._register(t,e,c,r,a),this._watch(t,e,c,r,a)),!0))}_initRefRange(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(o=>{switch(o.type){case"update":{const{unitId:t,sheetId:s,row:e,col:n,note:r}=o,a=this._getIdWithUnitId(t,s,e,n);r?this._disposableMap.has(a)||(this._register(t,s,r,e,n),this._watch(t,s,r,e,n)):(this._unregister(t,s,e,n),this._unwatch(t,s,e,n));break}case"ref":{const{unitId:t,sheetId:s,row:e,col:n,newPosition:r,note:a,silent:c}=o;this._unregister(t,s,e,n),c||(this._unwatch(t,s,e,n),this._watch(t,s,a,r.row,r.col)),this._register(t,s,a,r.row,r.col);break}}}))}};C=W([f(0,h.Inject(l.RefRangeService)),f(1,h.Inject(p)),f(2,h.Inject(l.SheetsSelectionsService)),f(3,h.ICommandService)],C);var L=Object.getOwnPropertyDescriptor,H=(i,o,t,s)=>{for(var e=s>1?void 0:s?L(o,t):o,n=i.length-1,r;n>=0;n--)(r=i[n])&&(e=r(e)||e);return e},J=(i,o)=>(t,s)=>o(t,s,i);let I=class extends h.Disposable{constructor(i){super(),this._commandService=i,this._initialize()}_initialize(){[M,y,_,S,P,w,x].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}};I=H([J(0,h.ICommandService)],I);var q=Object.defineProperty,G=Object.getOwnPropertyDescriptor,z=(i,o,t)=>o in i?q(i,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[o]=t,F=(i,o,t,s)=>{for(var e=s>1?void 0:s?G(o,t):o,n=i.length-1,r;n>=0;n--)(r=i[n])&&(e=r(e)||e);return e},U=(i,o)=>(t,s)=>o(t,s,i),O=(i,o,t)=>z(i,typeof o!="symbol"?o+"":o,t);exports.UniverSheetsNotePlugin=class extends h.Plugin{constructor(o=R,t,s){super(),this._config=o,this._configService=t,this._injector=s;const{...e}=h.merge({},R,this._config);this._configService.setConfig(V,e)}onStarting(){[[p],[I],[exports.SheetsNoteResourceController],[C]].forEach(o=>{this._injector.add(o)}),h.touchDependencies(this._injector,[[p],[I],[exports.SheetsNoteResourceController]])}onReady(){h.touchDependencies(this._injector,[[C]])}};O(exports.UniverSheetsNotePlugin,"pluginName",T);O(exports.UniverSheetsNotePlugin,"type",h.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNotePlugin=F([h.DependentOn(l.UniverSheetsPlugin),U(1,h.IConfigService),U(2,h.Inject(h.Injector))],exports.UniverSheetsNotePlugin);exports.RemoveNoteMutation=S;exports.SheetDeleteNoteCommand=P;exports.SheetToggleNotePopupCommand=w;exports.SheetUpdateNoteCommand=x;exports.SheetsNoteModel=p;exports.ToggleNotePopupMutation=y;exports.UpdateNoteMutation=_;exports.UpdateNotePositionMutation=M;
1
+ "use strict";var x=Object.defineProperty;var A=(i,r,t)=>r in i?x(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var S=(i,r,t)=>A(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@univerjs/core"),g=require("@univerjs/sheets"),f=require("rxjs");class _ extends h.Disposable{constructor(){super(...arguments);S(this,"_notesMap",new Map);S(this,"_change$",new f.Subject);S(this,"change$",this._change$.asObservable())}_ensureNotesMap(t,e){let o=this._notesMap.get(t);o||(o=new Map,this._notesMap.set(t,o));let s=o.get(e);return s||(s=new Map,o.set(e,s)),s}_getNoteByPosition(t,e,o,s){const n=this._ensureNotesMap(t,e);for(const[a,c]of n)if(c.row===o&&c.col===s)return c}_getNoteById(t,e,o){return this._ensureNotesMap(t,e).get(o)}_getNoteByParams(t,e,o){const{noteId:s,row:n,col:a}=o;return s?this._getNoteById(t,e,s):n!==void 0&&a!==void 0?this._getNoteByPosition(t,e,n,a):null}getSheetShowNotes$(t,e){return this._change$.pipe(f.filter(({unitId:o,subUnitId:s})=>o===t&&s===e),f.map(()=>{const o=this._ensureNotesMap(t,e),s=[];for(const[n,a]of o)a.show&&s.push({loc:{row:a.row,col:a.col,unitId:t,subUnitId:e},note:a});return s}))}getCellNoteChange$(t,e,o,s){return this._change$.pipe(f.filter(({unitId:n,subUnitId:a,oldNote:c})=>n!==t||a!==e||!c?!1:c.row===o&&c.col===s),f.map(n=>n))}updateNote(t,e,o,s,n,a){const c=this._getNoteByParams(t,e,{noteId:n==null?void 0:n.id,row:o,col:s}),d=this._ensureNotesMap(t,e),u={...n,id:(c==null?void 0:c.id)||n.id||h.generateRandomId(6),row:o,col:s};d.set(u.id,u),this._change$.next({unitId:t,subUnitId:e,oldNote:c,type:"update",newNote:u,silent:a})}removeNote(t,e,o){const{noteId:s,row:n,col:a,silent:c}=o,d=this._getNoteByParams(t,e,{noteId:s,row:n,col:a});if(!d)return;this._ensureNotesMap(t,e).delete(d.id),this._change$.next({unitId:t,subUnitId:e,oldNote:d,type:"update",newNote:null,silent:c})}toggleNotePopup(t,e,o){const{noteId:s,row:n,col:a,silent:c}=o,d=this._getNoteByParams(t,e,{noteId:s,row:n,col:a});if(!d)return;const u=this._ensureNotesMap(t,e),l={...d,show:!d.show};u.set(l.id,l),this._change$.next({unitId:t,subUnitId:e,oldNote:d,type:"update",newNote:l,silent:c})}updateNotePosition(t,e,o){const{noteId:s,row:n,col:a,newRow:c,newCol:d,silent:u}=o,l=this._getNoteByParams(t,e,{noteId:s,row:n,col:a});if(!l)return;const p=this._ensureNotesMap(t,e),m={...l,row:c,col:d};p.set(m.id,m),this._change$.next({unitId:t,subUnitId:e,oldNote:l,type:"ref",newNote:m,silent:u})}getNote(t,e,o){return this._getNoteByParams(t,e,o)}getNotes(){return this._notesMap}getUnitNotes(t){return this._notesMap.get(t)}getSheetNotes(t,e){const o=this._notesMap.get(t);if(o)return o.get(e)}deleteUnitNotes(t){this._notesMap.delete(t)}}const N={id:"sheet.mutation.update-note",type:h.CommandType.MUTATION,handler:(i,r)=>{const{unitId:t,sheetId:e,row:o,col:s,note:n,silent:a}=r;return i.get(_).updateNote(t,e,o,s,n,a),!0}},M={id:"sheet.mutation.remove-note",type:h.CommandType.MUTATION,handler:(i,r)=>{const{unitId:t,sheetId:e,noteId:o,row:s,col:n,silent:a}=r;return i.get(_).removeNote(t,e,{noteId:o,row:s,col:n,silent:a}),!0}},w={id:"sheet.mutation.toggle-note-popup",type:h.CommandType.MUTATION,handler:(i,r)=>{const{unitId:t,sheetId:e,noteId:o,row:s,col:n,silent:a}=r;return i.get(_).toggleNotePopup(t,e,{noteId:o,row:s,col:n,silent:a}),!0}},C={id:"sheet.mutation.update-note-position",type:h.CommandType.MUTATION,handler:(i,r)=>{const{unitId:t,sheetId:e,noteId:o,row:s,col:n,newPosition:a,silent:c}=r;return i.get(_).updateNotePosition(t,e,{noteId:o,row:s,col:n,newRow:a.row,newCol:a.col,silent:c}),!0}},E={id:"sheet.command.delete-note",type:h.CommandType.COMMAND,handler:i=>{const r=g.getSheetCommandTarget(i.get(h.IUniverInstanceService));if(!r)return!1;const e=i.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;const o=i.get(_),{unitId:s,subUnitId:n}=r,{actualColumn:a,actualRow:c}=e.primary,d=o.getNote(s,n,{row:c,col:a});if(!d)return!1;const u=i.get(h.ICommandService),l=i.get(h.IUndoRedoService),p={id:M.id,params:{unitId:s,sheetId:n,noteId:d.id}},m={id:N.id,params:{unitId:s,sheetId:n,row:c,col:a,note:{...d}}};return u.syncExecuteCommand(p.id,p.params)?(l.pushUndoRedo({unitID:s,redoMutations:[p],undoMutations:[m]}),!0):!1}},O={id:"sheet.command.toggle-note-popup",type:h.CommandType.COMMAND,handler:i=>{const r=g.getSheetCommandTarget(i.get(h.IUniverInstanceService));if(!r)return!1;const e=i.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;const o=i.get(_),{unitId:s,subUnitId:n}=r,{actualColumn:a,actualRow:c}=e.primary,d=o.getNote(s,n,{row:c,col:a});if(!d)return!1;const u=i.get(h.ICommandService),l=i.get(h.IUndoRedoService),p={id:w.id,params:{unitId:s,sheetId:n,noteId:d.id}},m={id:w.id,params:{unitId:s,sheetId:n,noteId:d.id}};return u.syncExecuteCommand(p.id,p.params)?(l.pushUndoRedo({unitID:s,redoMutations:[p],undoMutations:[m]}),!0):!1}},D={id:"sheet.command.update-note",type:h.CommandType.COMMAND,handler:(i,r)=>{const t=g.getSheetCommandTarget(i.get(h.IUniverInstanceService),r);if(!t)return!1;const e=i.get(h.ICommandService),o=i.get(h.IUndoRedoService),s=i.get(_),{unitId:n,subUnitId:a}=t,{row:c,col:d,note:u}=r,l=s.getNote(n,a,{noteId:u.id,row:c,col:d}),p={id:N.id,params:{unitId:n,sheetId:a,row:c,col:d,note:u}},m=[];if(l){const U={id:N.id,params:{unitId:n,sheetId:a,row:c,col:d,note:{...l}}};m.push(U)}else{const U={id:M.id,params:{unitId:n,sheetId:a,row:c,col:d}};m.push(U)}return e.syncExecuteCommand(p.id,p.params)?(o.pushUndoRedo({unitID:n,redoMutations:[p],undoMutations:m}),!0):!1}},$="SHEET_NOTE_PLUGIN";var W=Object.getOwnPropertyDescriptor,B=(i,r,t,e)=>{for(var o=e>1?void 0:e?W(r,t):r,s=i.length-1,n;s>=0;s--)(n=i[s])&&(o=n(o)||o);return o},v=(i,r)=>(t,e)=>r(t,e,i);exports.SheetsNoteResourceController=class extends h.Disposable{constructor(r,t,e,o){super(),this._resourceManagerService=r,this._univerInstanceService=t,this._sheetInterceptorService=e,this._sheetsNoteModel=o,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){const r=e=>{const o=this._sheetsNoteModel.getUnitNotes(e);if(!o)return"";const s={};return o.forEach((n,a)=>{const c={};n.forEach(d=>{const{row:u,col:l}=d;c[u]||(c[u]={}),c[u][l]=d}),Object.keys(c).length>0&&(s[a]=c)}),JSON.stringify(s)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:$,businesses:[h.UniverInstanceType.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._sheetsNoteModel.deleteUnitNotes(e)},onLoad:(e,o)=>{Object.entries(o).forEach(([s,n])=>{Object.entries(n).forEach(([a,c])=>{Object.entries(c).forEach(([d,u])=>{this._sheetsNoteModel.updateNote(e,s,Number(a),Number(d),u)})})})}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===g.RemoveSheetCommand.id){const e=r.params,o=e.unitId||this._univerInstanceService.getCurrentUnitOfType(h.UniverInstanceType.UNIVER_SHEET).getUnitId(),s=e.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(h.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!o||!s)return{redos:[],undos:[]};const n=this._sheetsNoteModel.getSheetNotes(o,s);if(!n)return{redos:[],undos:[]};const a=[],c=[];return n.forEach(d=>{a.push({id:M.id,params:{unitId:o,sheetId:s,noteId:d.id,row:d.row,col:d.col}}),c.push({id:N.id,params:{unitId:o,sheetId:s,row:d.row,col:d.col,note:d}})}),{redos:a,undos:c}}else if(r.id===g.CopySheetCommand.id){const e=r.params,{unitId:o,subUnitId:s,targetSubUnitId:n}=e;if(!o||!s||!n)return{redos:[],undos:[]};const a=this._sheetsNoteModel.getSheetNotes(o,s);if(!a)return{redos:[],undos:[]};const c=[],d=[];return a.forEach(u=>{const l={...u,id:h.generateRandomId(6)};c.push({id:N.id,params:{unitId:o,sheetId:n,row:l.row,col:l.col,note:l}}),d.push({id:M.id,params:{unitId:o,sheetId:n,noteId:l.id,row:l.row,col:l.col}})}),{redos:c,undos:d}}return{redos:[],undos:[]}}}))}};exports.SheetsNoteResourceController=B([v(0,h.IResourceManagerService),v(1,h.IUniverInstanceService),v(2,h.Inject(g.SheetInterceptorService)),v(3,h.Inject(_))],exports.SheetsNoteResourceController);const L="sheets-note.config",T={};var H=Object.getOwnPropertyDescriptor,J=(i,r,t,e)=>{for(var o=e>1?void 0:e?H(r,t):r,s=i.length-1,n;s>=0;s--)(n=i[s])&&(o=n(o)||o);return o},I=(i,r)=>(t,e)=>r(t,e,i);let R=class extends h.Disposable{constructor(r,t,e,o){super();S(this,"_disposableMap",new Map);S(this,"_watcherMap",new Map);S(this,"_handleRangeChange",(r,t,e,o,s,n,a)=>n?{redos:[{id:C.id,params:{unitId:r,sheetId:t,noteId:e.id,newPosition:{row:n.startRow,col:n.startColumn},silent:a}}],undos:[{id:C.id,params:{unitId:r,sheetId:t,noteId:e.id,newPosition:{row:o,col:s},note:e,silent:a}}]}:{redos:[{id:M.id,params:{unitId:r,sheetId:t,noteId:e.id}}],undos:[{id:N.id,params:{unitId:r,sheetId:t,row:o,col:s,note:e}}]});this._refRangeService=r,this._sheetsNoteModel=t,this._selectionManagerService=e,this._commandService=o,this._initData(),this._initRefRange()}_getIdWithUnitId(r,t,e,o){return`${r}-${t}-${e}-${o}`}_register(r,t,e,o,s){const n={startColumn:s,endColumn:s,startRow:o,endRow:o};this._disposableMap.set(this._getIdWithUnitId(r,t,o,s),this._refRangeService.registerRefRange(n,a=>{const c=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(n,a,{selectionManagerService:this._selectionManagerService}),d=Array.isArray(c)?c[0]:c;return d&&d.startColumn===n.startColumn&&d.startRow===n.startRow?{undos:[],redos:[]}:this._handleRangeChange(r,t,e,o,s,d,!1)},r,t))}_watch(r,t,e,o,s){const n={startColumn:s,endColumn:s,startRow:o,endRow:o};this._watcherMap.set(this._getIdWithUnitId(r,t,o,s),this._refRangeService.watchRange(r,t,n,(a,c)=>{const{redos:d}=this._handleRangeChange(r,t,e,a.startRow,a.startColumn,c,!0);h.sequenceExecuteAsync(d,this._commandService,{onlyLocal:!0})},!0))}_unwatch(r,t,e,o){var n;const s=this._getIdWithUnitId(r,t,e,o);(n=this._watcherMap.get(s))==null||n.dispose(),this._watcherMap.delete(s)}_unregister(r,t,e,o){var n;const s=this._getIdWithUnitId(r,t,e,o);(n=this._disposableMap.get(s))==null||n.dispose(),this._disposableMap.delete(s)}_initData(){const r=this._sheetsNoteModel.getNotes();for(const[t,e]of r)for(const[o,s]of e)s.forEach(n=>{this._register(t,o,n,n.row,n.col),this._watch(t,o,n,n.row,n.col)})}_initRefRange(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(r=>{switch(r.type){case"update":{const{unitId:t,subUnitId:e,oldNote:o,newNote:s}=r,n=s?s.row:o.row,a=s?s.col:o.col,c=this._getIdWithUnitId(t,e,n,a);s?this._disposableMap.has(c)||(this._register(t,e,s,n,a),this._watch(t,e,s,n,a)):(this._unregister(t,e,n,a),this._unwatch(t,e,n,a));break}case"ref":{const{unitId:t,subUnitId:e,oldNote:o,newNote:s,silent:n}=r,{row:a,col:c}=o,{row:d,col:u}=s;this._unregister(t,e,a,c),n||(this._unwatch(t,e,a,c),this._watch(t,e,s,d,u)),this._register(t,e,s,d,u);break}}}))}};R=J([I(0,h.Inject(g.RefRangeService)),I(1,h.Inject(_)),I(2,h.Inject(g.SheetsSelectionsService)),I(3,h.ICommandService)],R);var q=Object.getOwnPropertyDescriptor,G=(i,r,t,e)=>{for(var o=e>1?void 0:e?q(r,t):r,s=i.length-1,n;s>=0;s--)(n=i[s])&&(o=n(o)||o);return o},V=(i,r)=>(t,e)=>r(t,e,i);let y=class extends h.Disposable{constructor(i){super(),this._commandService=i,this._initialize()}_initialize(){[C,w,N,M,E,O,D].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}};y=G([V(0,h.ICommandService)],y);var z=Object.defineProperty,F=Object.getOwnPropertyDescriptor,K=(i,r,t)=>r in i?z(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Y=(i,r,t,e)=>{for(var o=e>1?void 0:e?F(r,t):r,s=i.length-1,n;s>=0;s--)(n=i[s])&&(o=n(o)||o);return o},b=(i,r)=>(t,e)=>r(t,e,i),j=(i,r,t)=>K(i,typeof r!="symbol"?r+"":r,t);exports.UniverSheetsNotePlugin=class extends h.Plugin{constructor(r=T,t,e){super(),this._config=r,this._configService=t,this._injector=e;const{...o}=h.merge({},T,this._config);this._configService.setConfig(L,o)}onStarting(){[[_],[y],[exports.SheetsNoteResourceController],[R]].forEach(r=>{this._injector.add(r)}),h.touchDependencies(this._injector,[[_],[y],[exports.SheetsNoteResourceController]])}onReady(){h.touchDependencies(this._injector,[[R]])}};j(exports.UniverSheetsNotePlugin,"pluginName",$);j(exports.UniverSheetsNotePlugin,"type",h.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNotePlugin=Y([h.DependentOn(g.UniverSheetsPlugin),b(1,h.IConfigService),b(2,h.Inject(h.Injector))],exports.UniverSheetsNotePlugin);exports.RemoveNoteMutation=M;exports.SheetDeleteNoteCommand=E;exports.SheetToggleNotePopupCommand=O;exports.SheetUpdateNoteCommand=D;exports.SheetsNoteModel=_;exports.ToggleNotePopupMutation=w;exports.UpdateNoteMutation=N;exports.UpdateNotePositionMutation=C;
package/lib/es/facade.js CHANGED
@@ -1,8 +1,9 @@
1
- import { FEventName as I, FUniver as v } from "@univerjs/core/facade";
2
- import { UpdateNoteMutation as b, RemoveNoteMutation as B, SheetsNoteModel as S, SheetUpdateNoteCommand as f, SheetDeleteNoteCommand as H, SheetToggleNotePopupCommand as w } from "@univerjs/sheets-note";
3
- import { FRange as E, FWorksheet as k } from "@univerjs/sheets/facade";
4
- import { ICommandService as u, CanceledError as N } from "@univerjs/core";
5
- class x {
1
+ import { FEventName as B, FUniver as I } from "@univerjs/core/facade";
2
+ import { UpdateNoteMutation as C, RemoveNoteMutation as H, SheetsNoteModel as c, SheetUpdateNoteCommand as f, SheetDeleteNoteCommand as x, SheetToggleNotePopupCommand as m } from "@univerjs/sheets-note";
3
+ import { FRange as k, FWorksheet as b } from "@univerjs/sheets/facade";
4
+ import { ICommandService as M, CanceledError as g, IUniverInstanceService as v } from "@univerjs/core";
5
+ import { getSheetCommandTarget as E, SheetsSelectionsService as p } from "@univerjs/sheets";
6
+ class y {
6
7
  get SheetNoteAdd() {
7
8
  return "SheetNoteAdd";
8
9
  }
@@ -34,23 +35,23 @@ class x {
34
35
  return "BeforeSheetNoteHide";
35
36
  }
36
37
  }
37
- I.extend(x);
38
- class U extends E {
39
- createOrUpdateNote(d) {
38
+ B.extend(y);
39
+ class W extends k {
40
+ createOrUpdateNote(n) {
40
41
  return this._commandService.syncExecuteCommand(
41
- b.id,
42
+ C.id,
42
43
  {
43
44
  unitId: this.getUnitId(),
44
45
  sheetId: this.getSheetId(),
45
46
  row: this.getRow(),
46
47
  col: this.getColumn(),
47
- note: d
48
+ note: n
48
49
  }
49
50
  ), this;
50
51
  }
51
52
  deleteNote() {
52
53
  return this._commandService.syncExecuteCommand(
53
- B.id,
54
+ H.id,
54
55
  {
55
56
  unitId: this.getUnitId(),
56
57
  sheetId: this.getSheetId(),
@@ -60,216 +61,234 @@ class U extends E {
60
61
  ), this;
61
62
  }
62
63
  getNote() {
63
- return this._injector.get(S).getNote(this.getUnitId(), this.getSheetId(), this.getRow(), this.getColumn());
64
+ return this._injector.get(c).getNote(this.getUnitId(), this.getSheetId(), { row: this.getRow(), col: this.getColumn() });
64
65
  }
65
66
  }
66
- E.extend(U);
67
- class C extends v {
67
+ k.extend(W);
68
+ class T extends I {
68
69
  // eslint-disable-next-line max-lines-per-function
69
- _initialize(d) {
70
- this.registerEventHandler(
71
- this.Event.SheetNoteAdd,
72
- () => d.get(S).change$.subscribe((e) => {
73
- if (e.type === "update" && !e.oldNote && e.note) {
74
- const { unitId: h, sheetId: t, row: o, col: s, note: r, oldNote: i } = e, n = this.getSheetTarget(h, t);
75
- if (!n)
76
- return;
77
- const { workbook: c, worksheet: l } = n;
78
- this.fireEvent(this.Event.SheetNoteAdd, {
79
- workbook: c,
80
- worksheet: l,
81
- row: o,
82
- col: s,
83
- note: r
84
- });
85
- }
86
- })
87
- ), this.registerEventHandler(
88
- this.Event.SheetNoteDelete,
89
- () => d.get(S).change$.subscribe((e) => {
90
- if (e.type === "update" && e.oldNote && !e.note) {
91
- const { unitId: h, sheetId: t, row: o, col: s, note: r, oldNote: i } = e, n = this.getSheetTarget(h, t);
92
- if (!n)
93
- return;
94
- const { workbook: c, worksheet: l } = n;
95
- this.fireEvent(this.Event.SheetNoteDelete, {
96
- workbook: c,
97
- worksheet: l,
98
- row: o,
99
- col: s,
100
- oldNote: i
101
- });
102
- }
103
- })
104
- ), this.registerEventHandler(
105
- this.Event.SheetNoteUpdate,
106
- () => d.get(S).change$.subscribe((e) => {
107
- if (e.type === "update" && e.oldNote && e.note) {
108
- const { unitId: h, sheetId: t, row: o, col: s, note: r, oldNote: i } = e, n = this.getSheetTarget(h, t);
109
- if (!n)
110
- return;
111
- const { workbook: c, worksheet: l } = n;
112
- this.fireEvent(this.Event.SheetNoteUpdate, {
113
- workbook: c,
114
- worksheet: l,
115
- row: o,
116
- col: s,
117
- note: r,
118
- oldNote: i
119
- });
120
- }
121
- })
122
- ), this.registerEventHandler(
123
- this.Event.SheetNoteShow,
124
- () => d.get(S).change$.subscribe((e) => {
125
- if (e.type === "update" && e.oldNote && e.note && !e.oldNote.show && e.note.show) {
126
- const { unitId: h, sheetId: t, row: o, col: s } = e, r = this.getSheetTarget(h, t);
127
- if (!r)
128
- return;
129
- const { workbook: i, worksheet: n } = r;
130
- this.fireEvent(this.Event.SheetNoteShow, {
131
- workbook: i,
132
- worksheet: n,
133
- row: o,
134
- col: s
135
- });
136
- }
137
- })
138
- ), this.registerEventHandler(
139
- this.Event.SheetNoteHide,
140
- () => d.get(S).change$.subscribe((e) => {
141
- if (e.type === "update" && e.oldNote && e.note && e.oldNote.show && !e.note.show) {
142
- const { unitId: h, sheetId: t, row: o, col: s } = e, r = this.getSheetTarget(h, t);
143
- if (!r)
144
- return;
145
- const { workbook: i, worksheet: n } = r;
146
- this.fireEvent(this.Event.SheetNoteHide, {
147
- workbook: i,
148
- worksheet: n,
149
- row: o,
150
- col: s
151
- });
152
- }
153
- })
154
- ), this.registerEventHandler(
155
- this.Event.BeforeSheetNoteAdd,
156
- () => d.get(u).beforeCommandExecuted((e) => {
157
- if (e.id === f.id) {
158
- const h = d.get(S), { unitId: t, sheetId: o, row: s, col: r, note: i } = e.params;
159
- if (h.getNote(t, o, s, r)) return;
160
- const c = this.getSheetTarget(t, o);
161
- if (!c)
162
- return;
163
- const { workbook: l, worksheet: g } = c;
164
- if (this.fireEvent(this.Event.BeforeSheetNoteAdd, {
165
- workbook: l,
166
- worksheet: g,
167
- row: s,
168
- col: r,
169
- note: i
170
- }))
171
- throw new N();
172
- }
173
- })
174
- ), this.registerEventHandler(
175
- this.Event.BeforeSheetNoteDelete,
176
- () => d.get(u).beforeCommandExecuted((e) => {
177
- if (e.id === H.id) {
178
- const h = d.get(S), { unitId: t, sheetId: o, row: s, col: r } = e.params, i = h.getNote(t, o, s, r);
179
- if (!i) return;
180
- const n = this.getSheetTarget(t, o);
181
- if (!n)
182
- return;
183
- const { workbook: c, worksheet: l } = n;
184
- if (this.fireEvent(this.Event.BeforeSheetNoteDelete, {
185
- workbook: c,
186
- worksheet: l,
187
- row: s,
188
- col: r,
189
- oldNote: i
190
- }))
191
- throw new N();
192
- }
193
- })
194
- ), this.registerEventHandler(
195
- this.Event.BeforeSheetNoteUpdate,
196
- () => d.get(u).beforeCommandExecuted((e) => {
197
- if (e.id === f.id) {
198
- const h = d.get(S), { unitId: t, sheetId: o, row: s, col: r, note: i } = e.params, n = h.getNote(t, o, s, r);
199
- if (!n) return;
200
- const c = this.getSheetTarget(t, o);
201
- if (!c)
202
- return;
203
- const { workbook: l, worksheet: g } = c;
204
- if (this.fireEvent(this.Event.BeforeSheetNoteUpdate, {
205
- workbook: l,
206
- worksheet: g,
207
- row: s,
208
- col: r,
209
- note: i,
210
- oldNote: n
211
- }))
212
- throw new N();
213
- }
214
- })
215
- ), this.registerEventHandler(
216
- this.Event.BeforeSheetNoteShow,
217
- () => d.get(u).beforeCommandExecuted((e) => {
218
- if (e.id === w.id) {
219
- const h = d.get(S), { unitId: t, sheetId: o, row: s, col: r } = e.params, i = h.getNote(t, o, s, r);
220
- if (i != null && i.show) return;
221
- const n = this.getSheetTarget(t, o);
222
- if (!n)
223
- return;
224
- const { workbook: c, worksheet: l } = n;
225
- if (this.fireEvent(this.Event.BeforeSheetNoteShow, {
226
- workbook: c,
227
- worksheet: l,
228
- row: s,
229
- col: r
230
- }))
231
- throw new N();
232
- }
233
- })
234
- ), this.registerEventHandler(
235
- this.Event.BeforeSheetNoteHide,
236
- () => d.get(u).beforeCommandExecuted((e) => {
237
- if (e.id === w.id) {
238
- const h = d.get(S), { unitId: t, sheetId: o, row: s, col: r } = e.params, i = h.getNote(t, o, s, r);
239
- if (!(i != null && i.show)) return;
240
- const n = this.getSheetTarget(t, o);
241
- if (!n)
242
- return;
243
- const { workbook: c, worksheet: l } = n;
244
- if (this.fireEvent(this.Event.BeforeSheetNoteHide, {
245
- workbook: c,
246
- worksheet: l,
247
- row: s,
248
- col: r
249
- }))
250
- throw new N();
251
- }
252
- })
70
+ _initialize(n) {
71
+ const a = n.get(M);
72
+ this.disposeWithMe(
73
+ this.registerEventHandler(
74
+ this.Event.SheetNoteAdd,
75
+ () => n.get(c).change$.subscribe((e) => {
76
+ if (e.type === "update" && !e.oldNote && e.newNote) {
77
+ const { unitId: s, subUnitId: r, newNote: t } = e, o = this.getSheetTarget(s, r);
78
+ if (!o)
79
+ return;
80
+ const { workbook: d, worksheet: i } = o;
81
+ this.fireEvent(this.Event.SheetNoteAdd, {
82
+ workbook: d,
83
+ worksheet: i,
84
+ row: t.row,
85
+ col: t.col,
86
+ note: t
87
+ });
88
+ }
89
+ })
90
+ )
91
+ ), this.disposeWithMe(
92
+ this.registerEventHandler(
93
+ this.Event.SheetNoteDelete,
94
+ () => n.get(c).change$.subscribe((e) => {
95
+ if (e.type === "update" && e.oldNote && !e.newNote) {
96
+ const { unitId: s, subUnitId: r, oldNote: t } = e, o = this.getSheetTarget(s, r);
97
+ if (!o)
98
+ return;
99
+ const { workbook: d, worksheet: i } = o;
100
+ this.fireEvent(this.Event.SheetNoteDelete, {
101
+ workbook: d,
102
+ worksheet: i,
103
+ row: t.row,
104
+ col: t.col,
105
+ oldNote: t
106
+ });
107
+ }
108
+ })
109
+ )
110
+ ), this.disposeWithMe(
111
+ this.registerEventHandler(
112
+ this.Event.SheetNoteUpdate,
113
+ () => n.get(c).change$.subscribe((e) => {
114
+ if (e.type === "update" && e.oldNote && e.newNote) {
115
+ const { unitId: s, subUnitId: r, oldNote: t, newNote: o } = e, d = this.getSheetTarget(s, r);
116
+ if (!d)
117
+ return;
118
+ const { workbook: i, worksheet: l } = d;
119
+ this.fireEvent(this.Event.SheetNoteUpdate, {
120
+ workbook: i,
121
+ worksheet: l,
122
+ row: o.row,
123
+ col: o.col,
124
+ note: o,
125
+ oldNote: t
126
+ });
127
+ }
128
+ })
129
+ )
130
+ ), this.disposeWithMe(
131
+ this.registerEventHandler(
132
+ this.Event.SheetNoteShow,
133
+ () => n.get(c).change$.subscribe((e) => {
134
+ if (e.type === "update" && e.oldNote && e.newNote && !e.oldNote.show && e.newNote.show) {
135
+ const { unitId: s, subUnitId: r, newNote: t } = e, o = this.getSheetTarget(s, r);
136
+ if (!o)
137
+ return;
138
+ const { workbook: d, worksheet: i } = o;
139
+ this.fireEvent(this.Event.SheetNoteShow, {
140
+ workbook: d,
141
+ worksheet: i,
142
+ row: t.row,
143
+ col: t.col
144
+ });
145
+ }
146
+ })
147
+ )
148
+ ), this.disposeWithMe(
149
+ this.registerEventHandler(
150
+ this.Event.SheetNoteHide,
151
+ () => n.get(c).change$.subscribe((e) => {
152
+ if (e.type === "update" && e.oldNote && e.newNote && e.oldNote.show && !e.newNote.show) {
153
+ const { unitId: s, subUnitId: r, newNote: t } = e, o = this.getSheetTarget(s, r);
154
+ if (!o)
155
+ return;
156
+ const { workbook: d, worksheet: i } = o;
157
+ this.fireEvent(this.Event.SheetNoteHide, {
158
+ workbook: d,
159
+ worksheet: i,
160
+ row: t.row,
161
+ col: t.col
162
+ });
163
+ }
164
+ })
165
+ )
166
+ ), this.disposeWithMe(
167
+ this.registerEventHandler(
168
+ this.Event.BeforeSheetNoteAdd,
169
+ () => a.beforeCommandExecuted((h) => {
170
+ if (h.id === f.id) {
171
+ const { unitId: e, sheetId: s, row: r, col: t, note: o } = h.params, d = this.getSheetTarget(e, s);
172
+ if (!d || n.get(c).getNote(e, s, { noteId: o.id, row: r, col: t })) return;
173
+ const { workbook: S, worksheet: u } = d;
174
+ if (this.fireEvent(this.Event.BeforeSheetNoteAdd, {
175
+ workbook: S,
176
+ worksheet: u,
177
+ row: r,
178
+ col: t,
179
+ note: o
180
+ }))
181
+ throw new g();
182
+ }
183
+ })
184
+ )
185
+ ), this.disposeWithMe(
186
+ this.registerEventHandler(
187
+ this.Event.BeforeSheetNoteDelete,
188
+ () => a.beforeCommandExecuted((h) => {
189
+ if (h.id === x.id) {
190
+ const { unitId: e, sheetId: s, row: r, col: t } = h.params, o = this.getSheetTarget(e, s);
191
+ if (!o || r === void 0 || t === void 0) return;
192
+ const i = n.get(c).getNote(e, s, { row: r, col: t });
193
+ if (!i) return;
194
+ const { workbook: l, worksheet: S } = o;
195
+ if (this.fireEvent(this.Event.BeforeSheetNoteDelete, {
196
+ workbook: l,
197
+ worksheet: S,
198
+ row: r,
199
+ col: t,
200
+ oldNote: i
201
+ }))
202
+ throw new g();
203
+ }
204
+ })
205
+ )
206
+ ), this.disposeWithMe(
207
+ this.registerEventHandler(
208
+ this.Event.BeforeSheetNoteUpdate,
209
+ () => a.beforeCommandExecuted((h) => {
210
+ if (h.id === f.id) {
211
+ const { unitId: e, sheetId: s, row: r, col: t, note: o } = h.params, d = this.getSheetTarget(e, s);
212
+ if (!d) return;
213
+ const l = n.get(c).getNote(e, s, { row: r, col: t });
214
+ if (!l) return;
215
+ const { workbook: S, worksheet: u } = d;
216
+ if (this.fireEvent(this.Event.BeforeSheetNoteUpdate, {
217
+ workbook: S,
218
+ worksheet: u,
219
+ row: r,
220
+ col: t,
221
+ note: o,
222
+ oldNote: l
223
+ }))
224
+ throw new g();
225
+ }
226
+ })
227
+ )
228
+ ), this.disposeWithMe(
229
+ this.registerEventHandler(
230
+ this.Event.BeforeSheetNoteShow,
231
+ () => a.beforeCommandExecuted((h) => {
232
+ if (h.id === m.id) {
233
+ const e = E(n.get(v));
234
+ if (!e) return;
235
+ const { unitId: s, subUnitId: r } = e, t = this.getUniverSheet(s);
236
+ if (!t) return;
237
+ const o = t.getSheetBySheetId(r);
238
+ if (!o) return;
239
+ const i = n.get(p).getCurrentLastSelection();
240
+ if (!(i != null && i.primary)) return;
241
+ const l = n.get(c), { actualColumn: S, actualRow: u } = i.primary, N = l.getNote(s, r, { row: u, col: S });
242
+ if (!N || N.show) return;
243
+ if (this.fireEvent(this.Event.BeforeSheetNoteShow, {
244
+ workbook: t,
245
+ worksheet: o,
246
+ row: u,
247
+ col: S
248
+ }))
249
+ throw new g();
250
+ }
251
+ })
252
+ )
253
+ ), this.disposeWithMe(
254
+ this.registerEventHandler(
255
+ this.Event.BeforeSheetNoteHide,
256
+ () => a.beforeCommandExecuted((h) => {
257
+ if (h.id === m.id) {
258
+ const e = E(n.get(v));
259
+ if (!e) return;
260
+ const { unitId: s, subUnitId: r } = e, t = this.getUniverSheet(s);
261
+ if (!t) return;
262
+ const o = t.getSheetBySheetId(r);
263
+ if (!o) return;
264
+ const i = n.get(p).getCurrentLastSelection();
265
+ if (!(i != null && i.primary)) return;
266
+ const l = n.get(c), { actualColumn: S, actualRow: u } = i.primary, N = l.getNote(s, r, { row: u, col: S });
267
+ if (!N || !N.show) return;
268
+ if (this.fireEvent(this.Event.BeforeSheetNoteHide, {
269
+ workbook: t,
270
+ worksheet: o,
271
+ row: u,
272
+ col: S
273
+ }))
274
+ throw new g();
275
+ }
276
+ })
277
+ )
253
278
  );
254
279
  }
255
280
  }
256
- v.extend(C);
257
- class T extends k {
281
+ I.extend(T);
282
+ class A extends b {
258
283
  getNotes() {
259
- const a = this._injector.get(S).getSheetNotes(this.getWorkbook().getUnitId(), this.getSheetId()), e = [];
260
- return a == null || a.forValue((h, t, o) => {
261
- e.push({
262
- ...o,
263
- row: h,
264
- col: t
265
- });
266
- }), e;
284
+ const a = this._injector.get(c).getSheetNotes(this.getWorkbook().getUnitId(), this.getSheetId());
285
+ return a ? Array.from(a.values()).map((h) => ({ ...h })) : [];
267
286
  }
268
287
  }
269
- k.extend(T);
288
+ b.extend(A);
270
289
  export {
271
- x as FSheetNoteEvent,
272
- U as FSheetsNoteRangeMixin,
273
- T as FSheetsNoteWorksheet,
274
- C as FUniverSheetNoteMixin
290
+ y as FSheetNoteEvent,
291
+ W as FSheetsNoteRangeMixin,
292
+ A as FSheetsNoteWorksheet,
293
+ T as FUniverSheetNoteMixin
275
294
  };