@univerjs/sheets-note 0.15.4 → 0.15.5

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 w=require("@univerjs/core/facade"),l=require("@univerjs/sheets-note"),u=require("@univerjs/sheets/facade"),g=require("@univerjs/core");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"}}w.FEventName.extend(E);class v extends u.FRange{createOrUpdateNote(c){return this._commandService.syncExecuteCommand(l.UpdateNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:c}),this}deleteNote(){return this._commandService.syncExecuteCommand(l.RemoveNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(l.SheetsNoteModel).getNote(this.getUnitId(),this.getSheetId(),this.getRow(),this.getColumn())}}u.FRange.extend(v);class m extends w.FUniver{_initialize(c){const N=c.get(g.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteAdd,()=>c.get(l.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&!e.oldNote&&e.note){const{unitId:t,sheetId:o,row:r,col:i,note:s}=e,n=this.getSheetTarget(t,o);if(!n)return;const{workbook:d,worksheet:S}=n;this.fireEvent(this.Event.SheetNoteAdd,{workbook:d,worksheet:S,row:r,col:i,note:s})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteDelete,()=>c.get(l.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&!e.note){const{unitId:t,sheetId:o,row:r,col:i,oldNote:s}=e,n=this.getSheetTarget(t,o);if(!n)return;const{workbook:d,worksheet:S}=n;this.fireEvent(this.Event.SheetNoteDelete,{workbook:d,worksheet:S,row:r,col:i,oldNote:s})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteUpdate,()=>c.get(l.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note){const{unitId:t,sheetId:o,row:r,col:i,note:s,oldNote:n}=e,d=this.getSheetTarget(t,o);if(!d)return;const{workbook:S,worksheet:a}=d;this.fireEvent(this.Event.SheetNoteUpdate,{workbook:S,worksheet:a,row:r,col:i,note:s,oldNote:n})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteShow,()=>c.get(l.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note&&!e.oldNote.show&&e.note.show){const{unitId:t,sheetId:o,row:r,col:i}=e,s=this.getSheetTarget(t,o);if(!s)return;const{workbook:n,worksheet:d}=s;this.fireEvent(this.Event.SheetNoteShow,{workbook:n,worksheet:d,row:r,col:i})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteHide,()=>c.get(l.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note&&e.oldNote.show&&!e.note.show){const{unitId:t,sheetId:o,row:r,col:i}=e,s=this.getSheetTarget(t,o);if(!s)return;const{workbook:n,worksheet:d}=s;this.fireEvent(this.Event.SheetNoteHide,{workbook:n,worksheet:d,row:r,col:i})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteAdd,()=>N.beforeCommandExecuted(h=>{if(h.id===l.SheetUpdateNoteCommand.id){const e=c.get(l.SheetsNoteModel),{unitId:t,sheetId:o,row:r,col:i,note:s}=h.params;if(e.getNote(t,o,r,i))return;const d=this.getSheetTarget(t,o);if(!d)return;const{workbook:S,worksheet:a}=d;if(this.fireEvent(this.Event.BeforeSheetNoteAdd,{workbook:S,worksheet:a,row:r,col:i,note:s}))throw new g.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>N.beforeCommandExecuted(h=>{if(h.id===l.SheetDeleteNoteCommand.id){const e=c.get(l.SheetsNoteModel),{unitId:t,sheetId:o,row:r,col:i}=h.params,s=e.getNote(t,o,r,i);if(!s)return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:d,worksheet:S}=n;if(this.fireEvent(this.Event.BeforeSheetNoteDelete,{workbook:d,worksheet:S,row:r,col:i,oldNote:s}))throw new g.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>N.beforeCommandExecuted(h=>{if(h.id===l.SheetUpdateNoteCommand.id){const e=c.get(l.SheetsNoteModel),{unitId:t,sheetId:o,row:r,col:i,note:s}=h.params,n=e.getNote(t,o,r,i);if(!n)return;const d=this.getSheetTarget(t,o);if(!d)return;const{workbook:S,worksheet:a}=d;if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,{workbook:S,worksheet:a,row:r,col:i,note:s,oldNote:n}))throw new g.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>N.beforeCommandExecuted(h=>{if(h.id===l.SheetToggleNotePopupCommand.id){const e=c.get(l.SheetsNoteModel),{unitId:t,sheetId:o,row:r,col:i}=h.params,s=e.getNote(t,o,r,i);if(s!=null&&s.show)return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:d,worksheet:S}=n;if(this.fireEvent(this.Event.BeforeSheetNoteShow,{workbook:d,worksheet:S,row:r,col:i}))throw new g.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>N.beforeCommandExecuted(h=>{if(h.id===l.SheetToggleNotePopupCommand.id){const e=c.get(l.SheetsNoteModel),{unitId:t,sheetId:o,row:r,col:i}=h.params,s=e.getNote(t,o,r,i);if(!(s!=null&&s.show))return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:d,worksheet:S}=n;if(this.fireEvent(this.Event.BeforeSheetNoteHide,{workbook:d,worksheet:S,row:r,col:i}))throw new g.CanceledError}})))}}w.FUniver.extend(m);class p extends u.FWorksheet{getNotes(){const N=this._injector.get(l.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId()),h=[];return N==null||N.forValue((e,t,o)=>{h.push({...o,row:e,col:t})}),h}}u.FWorksheet.extend(p);exports.FSheetNoteEvent=E;exports.FSheetsNoteRangeMixin=v;exports.FSheetsNoteWorksheet=p;exports.FUniverSheetNoteMixin=m;
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 k, FUniver as m } from "@univerjs/core/facade";
2
- import { UpdateNoteMutation as I, RemoveNoteMutation as b, SheetsNoteModel as g, SheetUpdateNoteCommand as f, SheetDeleteNoteCommand as B, SheetToggleNotePopupCommand as w } from "@univerjs/sheets-note";
3
- import { FRange as E, FWorksheet as v } from "@univerjs/sheets/facade";
4
- import { ICommandService as H, 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
- k.extend(x);
38
- class U extends E {
39
- createOrUpdateNote(c) {
38
+ B.extend(y);
39
+ class W extends k {
40
+ createOrUpdateNote(n) {
40
41
  return this._commandService.syncExecuteCommand(
41
- I.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: c
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,29 +61,29 @@ class U extends E {
60
61
  ), this;
61
62
  }
62
63
  getNote() {
63
- return this._injector.get(g).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 m {
67
+ k.extend(W);
68
+ class T extends I {
68
69
  // eslint-disable-next-line max-lines-per-function
69
- _initialize(c) {
70
- const a = c.get(H);
70
+ _initialize(n) {
71
+ const a = n.get(M);
71
72
  this.disposeWithMe(
72
73
  this.registerEventHandler(
73
74
  this.Event.SheetNoteAdd,
74
- () => c.get(g).change$.subscribe((e) => {
75
- if (e.type === "update" && !e.oldNote && e.note) {
76
- const { unitId: t, sheetId: o, row: r, col: i, note: s } = e, n = this.getSheetTarget(t, o);
77
- if (!n)
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)
78
79
  return;
79
- const { workbook: d, worksheet: l } = n;
80
+ const { workbook: d, worksheet: i } = o;
80
81
  this.fireEvent(this.Event.SheetNoteAdd, {
81
82
  workbook: d,
82
- worksheet: l,
83
- row: r,
84
- col: i,
85
- note: s
83
+ worksheet: i,
84
+ row: t.row,
85
+ col: t.col,
86
+ note: t
86
87
  });
87
88
  }
88
89
  })
@@ -90,18 +91,18 @@ class C extends m {
90
91
  ), this.disposeWithMe(
91
92
  this.registerEventHandler(
92
93
  this.Event.SheetNoteDelete,
93
- () => c.get(g).change$.subscribe((e) => {
94
- if (e.type === "update" && e.oldNote && !e.note) {
95
- const { unitId: t, sheetId: o, row: r, col: i, oldNote: s } = e, n = this.getSheetTarget(t, o);
96
- if (!n)
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)
97
98
  return;
98
- const { workbook: d, worksheet: l } = n;
99
+ const { workbook: d, worksheet: i } = o;
99
100
  this.fireEvent(this.Event.SheetNoteDelete, {
100
101
  workbook: d,
101
- worksheet: l,
102
- row: r,
103
- col: i,
104
- oldNote: s
102
+ worksheet: i,
103
+ row: t.row,
104
+ col: t.col,
105
+ oldNote: t
105
106
  });
106
107
  }
107
108
  })
@@ -109,19 +110,19 @@ class C extends m {
109
110
  ), this.disposeWithMe(
110
111
  this.registerEventHandler(
111
112
  this.Event.SheetNoteUpdate,
112
- () => c.get(g).change$.subscribe((e) => {
113
- if (e.type === "update" && e.oldNote && e.note) {
114
- const { unitId: t, sheetId: o, row: r, col: i, note: s, oldNote: n } = e, d = this.getSheetTarget(t, o);
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);
115
116
  if (!d)
116
117
  return;
117
- const { workbook: l, worksheet: S } = d;
118
+ const { workbook: i, worksheet: l } = d;
118
119
  this.fireEvent(this.Event.SheetNoteUpdate, {
119
- workbook: l,
120
- worksheet: S,
121
- row: r,
122
- col: i,
123
- note: s,
124
- oldNote: n
120
+ workbook: i,
121
+ worksheet: l,
122
+ row: o.row,
123
+ col: o.col,
124
+ note: o,
125
+ oldNote: t
125
126
  });
126
127
  }
127
128
  })
@@ -129,17 +130,17 @@ class C extends m {
129
130
  ), this.disposeWithMe(
130
131
  this.registerEventHandler(
131
132
  this.Event.SheetNoteShow,
132
- () => c.get(g).change$.subscribe((e) => {
133
- if (e.type === "update" && e.oldNote && e.note && !e.oldNote.show && e.note.show) {
134
- const { unitId: t, sheetId: o, row: r, col: i } = e, s = this.getSheetTarget(t, o);
135
- if (!s)
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)
136
137
  return;
137
- const { workbook: n, worksheet: d } = s;
138
+ const { workbook: d, worksheet: i } = o;
138
139
  this.fireEvent(this.Event.SheetNoteShow, {
139
- workbook: n,
140
- worksheet: d,
141
- row: r,
142
- col: i
140
+ workbook: d,
141
+ worksheet: i,
142
+ row: t.row,
143
+ col: t.col
143
144
  });
144
145
  }
145
146
  })
@@ -147,17 +148,17 @@ class C extends m {
147
148
  ), this.disposeWithMe(
148
149
  this.registerEventHandler(
149
150
  this.Event.SheetNoteHide,
150
- () => c.get(g).change$.subscribe((e) => {
151
- if (e.type === "update" && e.oldNote && e.note && e.oldNote.show && !e.note.show) {
152
- const { unitId: t, sheetId: o, row: r, col: i } = e, s = this.getSheetTarget(t, o);
153
- if (!s)
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)
154
155
  return;
155
- const { workbook: n, worksheet: d } = s;
156
+ const { workbook: d, worksheet: i } = o;
156
157
  this.fireEvent(this.Event.SheetNoteHide, {
157
- workbook: n,
158
- worksheet: d,
159
- row: r,
160
- col: i
158
+ workbook: d,
159
+ worksheet: i,
160
+ row: t.row,
161
+ col: t.col
161
162
  });
162
163
  }
163
164
  })
@@ -167,20 +168,17 @@ class C extends m {
167
168
  this.Event.BeforeSheetNoteAdd,
168
169
  () => a.beforeCommandExecuted((h) => {
169
170
  if (h.id === f.id) {
170
- const e = c.get(g), { unitId: t, sheetId: o, row: r, col: i, note: s } = h.params;
171
- if (e.getNote(t, o, r, i)) return;
172
- const d = this.getSheetTarget(t, o);
173
- if (!d)
174
- return;
175
- const { workbook: l, worksheet: S } = d;
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;
176
174
  if (this.fireEvent(this.Event.BeforeSheetNoteAdd, {
177
- workbook: l,
178
- worksheet: S,
175
+ workbook: S,
176
+ worksheet: u,
179
177
  row: r,
180
- col: i,
181
- note: s
178
+ col: t,
179
+ note: o
182
180
  }))
183
- throw new N();
181
+ throw new g();
184
182
  }
185
183
  })
186
184
  )
@@ -188,21 +186,20 @@ class C extends m {
188
186
  this.registerEventHandler(
189
187
  this.Event.BeforeSheetNoteDelete,
190
188
  () => a.beforeCommandExecuted((h) => {
191
- if (h.id === B.id) {
192
- const e = c.get(g), { unitId: t, sheetId: o, row: r, col: i } = h.params, s = e.getNote(t, o, r, i);
193
- if (!s) return;
194
- const n = this.getSheetTarget(t, o);
195
- if (!n)
196
- return;
197
- const { workbook: d, worksheet: l } = n;
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;
198
195
  if (this.fireEvent(this.Event.BeforeSheetNoteDelete, {
199
- workbook: d,
200
- worksheet: l,
196
+ workbook: l,
197
+ worksheet: S,
201
198
  row: r,
202
- col: i,
203
- oldNote: s
199
+ col: t,
200
+ oldNote: i
204
201
  }))
205
- throw new N();
202
+ throw new g();
206
203
  }
207
204
  })
208
205
  )
@@ -211,21 +208,20 @@ class C extends m {
211
208
  this.Event.BeforeSheetNoteUpdate,
212
209
  () => a.beforeCommandExecuted((h) => {
213
210
  if (h.id === f.id) {
214
- const e = c.get(g), { unitId: t, sheetId: o, row: r, col: i, note: s } = h.params, n = e.getNote(t, o, r, i);
215
- if (!n) return;
216
- const d = this.getSheetTarget(t, o);
217
- if (!d)
218
- return;
219
- const { workbook: l, worksheet: S } = d;
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;
220
216
  if (this.fireEvent(this.Event.BeforeSheetNoteUpdate, {
221
- workbook: l,
222
- worksheet: S,
217
+ workbook: S,
218
+ worksheet: u,
223
219
  row: r,
224
- col: i,
225
- note: s,
226
- oldNote: n
220
+ col: t,
221
+ note: o,
222
+ oldNote: l
227
223
  }))
228
- throw new N();
224
+ throw new g();
229
225
  }
230
226
  })
231
227
  )
@@ -233,20 +229,24 @@ class C extends m {
233
229
  this.registerEventHandler(
234
230
  this.Event.BeforeSheetNoteShow,
235
231
  () => a.beforeCommandExecuted((h) => {
236
- if (h.id === w.id) {
237
- const e = c.get(g), { unitId: t, sheetId: o, row: r, col: i } = h.params, s = e.getNote(t, o, r, i);
238
- if (s != null && s.show) return;
239
- const n = this.getSheetTarget(t, o);
240
- if (!n)
241
- return;
242
- const { workbook: d, worksheet: l } = n;
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
243
  if (this.fireEvent(this.Event.BeforeSheetNoteShow, {
244
- workbook: d,
245
- worksheet: l,
246
- row: r,
247
- col: i
244
+ workbook: t,
245
+ worksheet: o,
246
+ row: u,
247
+ col: S
248
248
  }))
249
- throw new N();
249
+ throw new g();
250
250
  }
251
251
  })
252
252
  )
@@ -254,43 +254,41 @@ class C extends m {
254
254
  this.registerEventHandler(
255
255
  this.Event.BeforeSheetNoteHide,
256
256
  () => a.beforeCommandExecuted((h) => {
257
- if (h.id === w.id) {
258
- const e = c.get(g), { unitId: t, sheetId: o, row: r, col: i } = h.params, s = e.getNote(t, o, r, i);
259
- if (!(s != null && s.show)) return;
260
- const n = this.getSheetTarget(t, o);
261
- if (!n)
262
- return;
263
- const { workbook: d, worksheet: l } = n;
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;
264
268
  if (this.fireEvent(this.Event.BeforeSheetNoteHide, {
265
- workbook: d,
266
- worksheet: l,
267
- row: r,
268
- col: i
269
+ workbook: t,
270
+ worksheet: o,
271
+ row: u,
272
+ col: S
269
273
  }))
270
- throw new N();
274
+ throw new g();
271
275
  }
272
276
  })
273
277
  )
274
278
  );
275
279
  }
276
280
  }
277
- m.extend(C);
278
- class M extends v {
281
+ I.extend(T);
282
+ class A extends b {
279
283
  getNotes() {
280
- const a = this._injector.get(g).getSheetNotes(this.getWorkbook().getUnitId(), this.getSheetId()), h = [];
281
- return a == null || a.forValue((e, t, o) => {
282
- h.push({
283
- ...o,
284
- row: e,
285
- col: t
286
- });
287
- }), h;
284
+ const a = this._injector.get(c).getSheetNotes(this.getWorkbook().getUnitId(), this.getSheetId());
285
+ return a ? Array.from(a.values()).map((h) => ({ ...h })) : [];
288
286
  }
289
287
  }
290
- v.extend(M);
288
+ b.extend(A);
291
289
  export {
292
- x as FSheetNoteEvent,
293
- U as FSheetsNoteRangeMixin,
294
- M as FSheetsNoteWorksheet,
295
- C as FUniverSheetNoteMixin
290
+ y as FSheetNoteEvent,
291
+ W as FSheetsNoteRangeMixin,
292
+ A as FSheetsNoteWorksheet,
293
+ T as FUniverSheetNoteMixin
296
294
  };