@univerjs/sheets-note 0.16.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
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;
1
+ "use strict";var A=Object.defineProperty;var W=(i,r,t)=>r in i?A(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var S=(i,r,t)=>W(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@univerjs/core"),g=require("@univerjs/sheets"),M=require("rxjs");class _ extends h.Disposable{constructor(){super(...arguments);S(this,"_notesMap",new Map);S(this,"_change$",new M.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(M.filter(({unitId:o,subUnitId:s})=>o===t&&s===e),M.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(M.filter(({unitId:n,subUnitId:a,oldNote:c})=>n!==t||a!==e||!c?!1:c.row===o&&c.col===s),M.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}},v={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}},O={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:v.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}},D={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}},$={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 P={id:N.id,params:{unitId:n,sheetId:a,row:c,col:d,note:{...l}}};m.push(P)}else{const P={id:v.id,params:{unitId:n,sheetId:a,row:c,col:d}};m.push(P)}return e.syncExecuteCommand(p.id,p.params)?(o.pushUndoRedo({unitID:n,redoMutations:[p],undoMutations:m}),!0):!1}},j="SHEET_NOTE_PLUGIN";var B=Object.getOwnPropertyDescriptor,L=(i,r,t,e)=>{for(var o=e>1?void 0:e?B(r,t):r,s=i.length-1,n;s>=0;s--)(n=i[s])&&(o=n(o)||o);return o},f=(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:j,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:v.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:v.id,params:{unitId:o,sheetId:n,noteId:l.id,row:l.row,col:l.col}})}),{redos:c,undos:d}}return{redos:[],undos:[]}}}))}};exports.SheetsNoteResourceController=L([f(0,h.IResourceManagerService),f(1,h.IUniverInstanceService),f(2,h.Inject(g.SheetInterceptorService)),f(3,h.Inject(_))],exports.SheetsNoteResourceController);const H="@univerjs/sheets-note",J="0.17.0",x={name:H,version:J},q="sheets-note.config",b={};var G=Object.getOwnPropertyDescriptor,V=(i,r,t,e)=>{for(var o=e>1?void 0:e?G(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:v.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=V([I(0,h.Inject(g.RefRangeService)),I(1,h.Inject(_)),I(2,h.Inject(g.SheetsSelectionsService)),I(3,h.ICommandService)],R);var z=Object.getOwnPropertyDescriptor,F=(i,r,t,e)=>{for(var o=e>1?void 0:e?z(r,t):r,s=i.length-1,n;s>=0;s--)(n=i[s])&&(o=n(o)||o);return o},K=(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,v,O,D,$].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}};y=F([K(0,h.ICommandService)],y);var Y=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(i,r,t)=>r in i?Y(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Z=(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},E=(i,r)=>(t,e)=>r(t,e,i),U=(i,r,t)=>X(i,typeof r!="symbol"?r+"":r,t);exports.UniverSheetsNotePlugin=class extends h.Plugin{constructor(r=b,t,e){super(),this._config=r,this._configService=t,this._injector=e;const{...o}=h.merge({},b,this._config);this._configService.setConfig(q,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]])}};U(exports.UniverSheetsNotePlugin,"pluginName",j);U(exports.UniverSheetsNotePlugin,"packageName",x.name);U(exports.UniverSheetsNotePlugin,"version",x.version);U(exports.UniverSheetsNotePlugin,"type",h.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNotePlugin=Z([h.DependentOn(g.UniverSheetsPlugin),E(1,h.IConfigService),E(2,h.Inject(h.Injector))],exports.UniverSheetsNotePlugin);exports.RemoveNoteMutation=v;exports.SheetDeleteNoteCommand=O;exports.SheetToggleNotePopupCommand=D;exports.SheetUpdateNoteCommand=$;exports.SheetsNoteModel=_;exports.ToggleNotePopupMutation=w;exports.UpdateNoteMutation=N;exports.UpdateNotePositionMutation=C;
package/lib/es/index.js CHANGED
@@ -1,14 +1,14 @@
1
- var z = Object.defineProperty;
2
- var F = (i, r, e) => r in i ? z(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
3
- var _ = (i, r, e) => F(i, typeof r != "symbol" ? r + "" : r, e);
4
- import { Disposable as U, generateRandomId as J, CommandType as m, IUniverInstanceService as E, ICommandService as w, IUndoRedoService as T, IResourceManagerService as q, Inject as f, UniverInstanceType as I, sequenceExecuteAsync as K, DependentOn as Y, IConfigService as Q, Injector as X, Plugin as Z, merge as k, touchDependencies as A } from "@univerjs/core";
5
- import { getSheetCommandTarget as D, SheetsSelectionsService as x, SheetInterceptorService as ee, RemoveSheetCommand as te, CopySheetCommand as se, RefRangeService as oe, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as ne, UniverSheetsPlugin as re } from "@univerjs/sheets";
6
- import { Subject as ie, filter as W, map as B } from "rxjs";
1
+ var F = Object.defineProperty;
2
+ var q = (i, r, e) => r in i ? F(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
3
+ var _ = (i, r, e) => q(i, typeof r != "symbol" ? r + "" : r, e);
4
+ import { Disposable as U, generateRandomId as G, CommandType as N, IUniverInstanceService as E, ICommandService as v, IUndoRedoService as D, IResourceManagerService as K, Inject as f, UniverInstanceType as C, sequenceExecuteAsync as Y, DependentOn as Q, IConfigService as X, Injector as Z, Plugin as k, merge as ee, touchDependencies as W } from "@univerjs/core";
5
+ import { getSheetCommandTarget as j, SheetsSelectionsService as x, SheetInterceptorService as te, RemoveSheetCommand as se, CopySheetCommand as oe, RefRangeService as ne, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as re, UniverSheetsPlugin as ie } from "@univerjs/sheets";
6
+ import { Subject as ae, filter as B, map as L } from "rxjs";
7
7
  class g extends U {
8
8
  constructor() {
9
9
  super(...arguments);
10
10
  _(this, "_notesMap", /* @__PURE__ */ new Map());
11
- _(this, "_change$", new ie());
11
+ _(this, "_change$", new ae());
12
12
  _(this, "change$", this._change$.asObservable());
13
13
  }
14
14
  _ensureNotesMap(e, t) {
@@ -32,8 +32,8 @@ class g extends U {
32
32
  }
33
33
  getSheetShowNotes$(e, t) {
34
34
  return this._change$.pipe(
35
- W(({ unitId: s, subUnitId: o }) => s === e && o === t),
36
- B(() => {
35
+ B(({ unitId: s, subUnitId: o }) => s === e && o === t),
36
+ L(() => {
37
37
  const s = this._ensureNotesMap(e, t), o = [];
38
38
  for (const [n, a] of s)
39
39
  a.show && o.push({ loc: { row: a.row, col: a.col, unitId: e, subUnitId: t }, note: a });
@@ -43,14 +43,14 @@ class g extends U {
43
43
  }
44
44
  getCellNoteChange$(e, t, s, o) {
45
45
  return this._change$.pipe(
46
- W(({ unitId: n, subUnitId: a, oldNote: c }) => n !== e || a !== t || !c ? !1 : c.row === s && c.col === o),
47
- B((n) => n)
46
+ B(({ unitId: n, subUnitId: a, oldNote: c }) => n !== e || a !== t || !c ? !1 : c.row === s && c.col === o),
47
+ L((n) => n)
48
48
  );
49
49
  }
50
50
  updateNote(e, t, s, o, n, a) {
51
51
  const c = this._getNoteByParams(e, t, { noteId: n == null ? void 0 : n.id, row: s, col: o }), d = this._ensureNotesMap(e, t), h = {
52
52
  ...n,
53
- id: (c == null ? void 0 : c.id) || n.id || J(6),
53
+ id: (c == null ? void 0 : c.id) || n.id || G(6),
54
54
  row: s,
55
55
  col: o
56
56
  };
@@ -94,45 +94,45 @@ class g extends U {
94
94
  this._notesMap.delete(e);
95
95
  }
96
96
  }
97
- const N = {
97
+ const m = {
98
98
  id: "sheet.mutation.update-note",
99
- type: m.MUTATION,
99
+ type: N.MUTATION,
100
100
  handler: (i, r) => {
101
101
  const { unitId: e, sheetId: t, row: s, col: o, note: n, silent: a } = r;
102
102
  return i.get(g).updateNote(e, t, s, o, n, a), !0;
103
103
  }
104
104
  }, M = {
105
105
  id: "sheet.mutation.remove-note",
106
- type: m.MUTATION,
106
+ type: N.MUTATION,
107
107
  handler: (i, r) => {
108
108
  const { unitId: e, sheetId: t, noteId: s, row: o, col: n, silent: a } = r;
109
109
  return i.get(g).removeNote(e, t, { noteId: s, row: o, col: n, silent: a }), !0;
110
110
  }
111
- }, b = {
111
+ }, $ = {
112
112
  id: "sheet.mutation.toggle-note-popup",
113
- type: m.MUTATION,
113
+ type: N.MUTATION,
114
114
  handler: (i, r) => {
115
115
  const { unitId: e, sheetId: t, noteId: s, row: o, col: n, silent: a } = r;
116
116
  return i.get(g).toggleNotePopup(e, t, { noteId: s, row: o, col: n, silent: a }), !0;
117
117
  }
118
- }, $ = {
118
+ }, T = {
119
119
  id: "sheet.mutation.update-note-position",
120
- type: m.MUTATION,
120
+ type: N.MUTATION,
121
121
  handler: (i, r) => {
122
122
  const { unitId: e, sheetId: t, noteId: s, row: o, col: n, newPosition: a, silent: c } = r;
123
123
  return i.get(g).updateNotePosition(e, t, { noteId: s, row: o, col: n, newRow: a.row, newCol: a.col, silent: c }), !0;
124
124
  }
125
- }, ae = {
125
+ }, ce = {
126
126
  id: "sheet.command.delete-note",
127
- type: m.COMMAND,
127
+ type: N.COMMAND,
128
128
  handler: (i) => {
129
- const r = D(i.get(E));
129
+ const r = j(i.get(E));
130
130
  if (!r) return !1;
131
131
  const t = i.get(x).getCurrentLastSelection();
132
132
  if (!(t != null && t.primary)) return !1;
133
133
  const s = i.get(g), { unitId: o, subUnitId: n } = r, { actualColumn: a, actualRow: c } = t.primary, d = s.getNote(o, n, { row: c, col: a });
134
134
  if (!d) return !1;
135
- const h = i.get(w), u = i.get(T), l = {
135
+ const h = i.get(v), u = i.get(D), l = {
136
136
  id: M.id,
137
137
  params: {
138
138
  unitId: o,
@@ -140,7 +140,7 @@ const N = {
140
140
  noteId: d.id
141
141
  }
142
142
  }, p = {
143
- id: N.id,
143
+ id: m.id,
144
144
  params: {
145
145
  unitId: o,
146
146
  sheetId: n,
@@ -155,25 +155,25 @@ const N = {
155
155
  undoMutations: [p]
156
156
  }), !0) : !1;
157
157
  }
158
- }, ce = {
158
+ }, de = {
159
159
  id: "sheet.command.toggle-note-popup",
160
- type: m.COMMAND,
160
+ type: N.COMMAND,
161
161
  handler: (i) => {
162
- const r = D(i.get(E));
162
+ const r = j(i.get(E));
163
163
  if (!r) return !1;
164
164
  const t = i.get(x).getCurrentLastSelection();
165
165
  if (!(t != null && t.primary)) return !1;
166
166
  const s = i.get(g), { unitId: o, subUnitId: n } = r, { actualColumn: a, actualRow: c } = t.primary, d = s.getNote(o, n, { row: c, col: a });
167
167
  if (!d) return !1;
168
- const h = i.get(w), u = i.get(T), l = {
169
- id: b.id,
168
+ const h = i.get(v), u = i.get(D), l = {
169
+ id: $.id,
170
170
  params: {
171
171
  unitId: o,
172
172
  sheetId: n,
173
173
  noteId: d.id
174
174
  }
175
175
  }, p = {
176
- id: b.id,
176
+ id: $.id,
177
177
  params: {
178
178
  unitId: o,
179
179
  sheetId: n,
@@ -186,14 +186,14 @@ const N = {
186
186
  undoMutations: [p]
187
187
  }), !0) : !1;
188
188
  }
189
- }, de = {
189
+ }, he = {
190
190
  id: "sheet.command.update-note",
191
- type: m.COMMAND,
191
+ type: N.COMMAND,
192
192
  handler: (i, r) => {
193
- const e = D(i.get(E), r);
193
+ const e = j(i.get(E), r);
194
194
  if (!e) return !1;
195
- const t = i.get(w), s = i.get(T), o = i.get(g), { unitId: n, subUnitId: a } = e, { row: c, col: d, note: h } = r, u = o.getNote(n, a, { noteId: h.id, row: c, col: d }), l = {
196
- id: N.id,
195
+ const t = i.get(v), s = i.get(D), o = i.get(g), { unitId: n, subUnitId: a } = e, { row: c, col: d, note: h } = r, u = o.getNote(n, a, { noteId: h.id, row: c, col: d }), l = {
196
+ id: m.id,
197
197
  params: {
198
198
  unitId: n,
199
199
  sheetId: a,
@@ -203,8 +203,8 @@ const N = {
203
203
  }
204
204
  }, p = [];
205
205
  if (u) {
206
- const O = {
207
- id: N.id,
206
+ const b = {
207
+ id: m.id,
208
208
  params: {
209
209
  unitId: n,
210
210
  sheetId: a,
@@ -213,9 +213,9 @@ const N = {
213
213
  note: { ...u }
214
214
  }
215
215
  };
216
- p.push(O);
216
+ p.push(b);
217
217
  } else {
218
- const O = {
218
+ const b = {
219
219
  id: M.id,
220
220
  params: {
221
221
  unitId: n,
@@ -224,7 +224,7 @@ const N = {
224
224
  col: d
225
225
  }
226
226
  };
227
- p.push(O);
227
+ p.push(b);
228
228
  }
229
229
  return t.syncExecuteCommand(l.id, l.params) ? (s.pushUndoRedo({
230
230
  unitID: n,
@@ -232,13 +232,13 @@ const N = {
232
232
  undoMutations: p
233
233
  }), !0) : !1;
234
234
  }
235
- }, G = "SHEET_NOTE_PLUGIN";
236
- var he = Object.getOwnPropertyDescriptor, ue = (i, r, e, t) => {
237
- for (var s = t > 1 ? void 0 : t ? he(r, e) : r, o = i.length - 1, n; o >= 0; o--)
235
+ }, V = "SHEET_NOTE_PLUGIN";
236
+ var ue = Object.getOwnPropertyDescriptor, le = (i, r, e, t) => {
237
+ for (var s = t > 1 ? void 0 : t ? ue(r, e) : r, o = i.length - 1, n; o >= 0; o--)
238
238
  (n = i[o]) && (s = n(s) || s);
239
239
  return s;
240
240
  }, S = (i, r) => (e, t) => r(e, t, i);
241
- let C = class extends U {
241
+ let R = class extends U {
242
242
  constructor(i, r, e, t) {
243
243
  super(), this._resourceManagerService = i, this._univerInstanceService = r, this._sheetInterceptorService = e, this._sheetsNoteModel = t, this._initSnapshot(), this._initSheetChange();
244
244
  }
@@ -266,8 +266,8 @@ let C = class extends U {
266
266
  };
267
267
  this.disposeWithMe(
268
268
  this._resourceManagerService.registerPluginResource({
269
- pluginName: G,
270
- businesses: [I.UNIVER_SHEET],
269
+ pluginName: V,
270
+ businesses: [C.UNIVER_SHEET],
271
271
  toJson: (e) => i(e),
272
272
  parseJson: (e) => r(e),
273
273
  onUnLoad: (e) => {
@@ -298,8 +298,8 @@ let C = class extends U {
298
298
  // eslint-disable-next-line max-lines-per-function
299
299
  getMutations: (i) => {
300
300
  var r;
301
- if (i.id === te.id) {
302
- const e = i.params, t = e.unitId || this._univerInstanceService.getCurrentUnitOfType(I.UNIVER_SHEET).getUnitId(), s = e.subUnitId || ((r = this._univerInstanceService.getCurrentUnitOfType(I.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : r.getSheetId());
301
+ if (i.id === se.id) {
302
+ const e = i.params, t = e.unitId || this._univerInstanceService.getCurrentUnitOfType(C.UNIVER_SHEET).getUnitId(), s = e.subUnitId || ((r = this._univerInstanceService.getCurrentUnitOfType(C.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : r.getSheetId());
303
303
  if (!t || !s)
304
304
  return { redos: [], undos: [] };
305
305
  const o = this._sheetsNoteModel.getSheetNotes(t, s);
@@ -317,7 +317,7 @@ let C = class extends U {
317
317
  col: c.col
318
318
  }
319
319
  }), a.push({
320
- id: N.id,
320
+ id: m.id,
321
321
  params: {
322
322
  unitId: t,
323
323
  sheetId: s,
@@ -327,7 +327,7 @@ let C = class extends U {
327
327
  }
328
328
  });
329
329
  }), { redos: n, undos: a };
330
- } else if (i.id === se.id) {
330
+ } else if (i.id === oe.id) {
331
331
  const e = i.params, { unitId: t, subUnitId: s, targetSubUnitId: o } = e;
332
332
  if (!t || !s || !o)
333
333
  return { redos: [], undos: [] };
@@ -336,9 +336,9 @@ let C = class extends U {
336
336
  return { redos: [], undos: [] };
337
337
  const a = [], c = [];
338
338
  return n.forEach((d) => {
339
- const h = { ...d, id: J(6) };
339
+ const h = { ...d, id: G(6) };
340
340
  a.push({
341
- id: N.id,
341
+ id: m.id,
342
342
  params: {
343
343
  unitId: t,
344
344
  sheetId: o,
@@ -364,26 +364,29 @@ let C = class extends U {
364
364
  );
365
365
  }
366
366
  };
367
- C = ue([
368
- S(0, q),
367
+ R = le([
368
+ S(0, K),
369
369
  S(1, E),
370
- S(2, f(ee)),
370
+ S(2, f(te)),
371
371
  S(3, f(g))
372
- ], C);
373
- const le = "sheets-note.config", L = {};
374
- var pe = Object.getOwnPropertyDescriptor, ge = (i, r, e, t) => {
375
- for (var s = t > 1 ? void 0 : t ? pe(r, e) : r, o = i.length - 1, n; o >= 0; o--)
372
+ ], R);
373
+ const pe = "@univerjs/sheets-note", ge = "0.17.0", z = {
374
+ name: pe,
375
+ version: ge
376
+ }, _e = "sheets-note.config", H = {};
377
+ var me = Object.getOwnPropertyDescriptor, Ne = (i, r, e, t) => {
378
+ for (var s = t > 1 ? void 0 : t ? me(r, e) : r, o = i.length - 1, n; o >= 0; o--)
376
379
  (n = i[o]) && (s = n(s) || s);
377
380
  return s;
378
- }, v = (i, r) => (e, t) => r(e, t, i);
379
- let R = class extends U {
381
+ }, I = (i, r) => (e, t) => r(e, t, i);
382
+ let y = class extends U {
380
383
  constructor(r, e, t, s) {
381
384
  super();
382
385
  _(this, "_disposableMap", /* @__PURE__ */ new Map());
383
386
  _(this, "_watcherMap", /* @__PURE__ */ new Map());
384
387
  _(this, "_handleRangeChange", (r, e, t, s, o, n, a) => n ? {
385
388
  redos: [{
386
- id: $.id,
389
+ id: T.id,
387
390
  params: {
388
391
  unitId: r,
389
392
  sheetId: e,
@@ -396,7 +399,7 @@ let R = class extends U {
396
399
  }
397
400
  }],
398
401
  undos: [{
399
- id: $.id,
402
+ id: T.id,
400
403
  params: {
401
404
  unitId: r,
402
405
  sheetId: e,
@@ -419,7 +422,7 @@ let R = class extends U {
419
422
  }
420
423
  }],
421
424
  undos: [{
422
- id: N.id,
425
+ id: m.id,
423
426
  params: {
424
427
  unitId: r,
425
428
  sheetId: e,
@@ -444,7 +447,7 @@ let R = class extends U {
444
447
  this._disposableMap.set(
445
448
  this._getIdWithUnitId(r, e, s, o),
446
449
  this._refRangeService.registerRefRange(n, (a) => {
447
- const c = ne(n, a, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
450
+ const c = re(n, a, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
448
451
  return d && d.startColumn === n.startColumn && d.startRow === n.startRow ? {
449
452
  undos: [],
450
453
  redos: []
@@ -463,7 +466,7 @@ let R = class extends U {
463
466
  this._getIdWithUnitId(r, e, s, o),
464
467
  this._refRangeService.watchRange(r, e, n, (a, c) => {
465
468
  const { redos: d } = this._handleRangeChange(r, e, t, a.startRow, a.startColumn, c, !0);
466
- K(d, this._commandService, { onlyLocal: !0 });
469
+ Y(d, this._commandService, { onlyLocal: !0 });
467
470
  }, !0)
468
471
  );
469
472
  }
@@ -504,30 +507,30 @@ let R = class extends U {
504
507
  );
505
508
  }
506
509
  };
507
- R = ge([
508
- v(0, f(oe)),
509
- v(1, f(g)),
510
- v(2, f(x)),
511
- v(3, w)
512
- ], R);
513
- var _e = Object.getOwnPropertyDescriptor, Ne = (i, r, e, t) => {
514
- for (var s = t > 1 ? void 0 : t ? _e(r, e) : r, o = i.length - 1, n; o >= 0; o--)
510
+ y = Ne([
511
+ I(0, f(ne)),
512
+ I(1, f(g)),
513
+ I(2, f(x)),
514
+ I(3, v)
515
+ ], y);
516
+ var fe = Object.getOwnPropertyDescriptor, Me = (i, r, e, t) => {
517
+ for (var s = t > 1 ? void 0 : t ? fe(r, e) : r, o = i.length - 1, n; o >= 0; o--)
515
518
  (n = i[o]) && (s = n(s) || s);
516
519
  return s;
517
- }, me = (i, r) => (e, t) => r(e, t, i);
518
- let y = class extends U {
520
+ }, we = (i, r) => (e, t) => r(e, t, i);
521
+ let P = class extends U {
519
522
  constructor(i) {
520
523
  super(), this._commandService = i, this._initialize();
521
524
  }
522
525
  _initialize() {
523
526
  [
527
+ T,
524
528
  $,
525
- b,
526
- N,
529
+ m,
527
530
  M,
528
- ae,
529
531
  ce,
530
- de
532
+ de,
533
+ he
531
534
  ].forEach((i) => {
532
535
  this.disposeWithMe(
533
536
  this._commandService.registerCommand(i)
@@ -535,60 +538,62 @@ let y = class extends U {
535
538
  });
536
539
  }
537
540
  };
538
- y = Ne([
539
- me(0, w)
540
- ], y);
541
- var fe = Object.defineProperty, Me = Object.getOwnPropertyDescriptor, we = (i, r, e) => r in i ? fe(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e, Se = (i, r, e, t) => {
542
- for (var s = t > 1 ? void 0 : t ? Me(r, e) : r, o = i.length - 1, n; o >= 0; o--)
541
+ P = Me([
542
+ we(0, v)
543
+ ], P);
544
+ var ve = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, Ie = (i, r, e) => r in i ? ve(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e, Ce = (i, r, e, t) => {
545
+ for (var s = t > 1 ? void 0 : t ? Se(r, e) : r, o = i.length - 1, n; o >= 0; o--)
543
546
  (n = i[o]) && (s = n(s) || s);
544
547
  return s;
545
- }, H = (i, r) => (e, t) => r(e, t, i), V = (i, r, e) => we(i, typeof r != "symbol" ? r + "" : r, e);
546
- let P = class extends Z {
547
- constructor(i = L, r, e) {
548
+ }, J = (i, r) => (e, t) => r(e, t, i), O = (i, r, e) => Ie(i, typeof r != "symbol" ? r + "" : r, e);
549
+ let w = class extends k {
550
+ constructor(i = H, r, e) {
548
551
  super(), this._config = i, this._configService = r, this._injector = e;
549
- const { ...t } = k(
552
+ const { ...t } = ee(
550
553
  {},
551
- L,
554
+ H,
552
555
  this._config
553
556
  );
554
- this._configService.setConfig(le, t);
557
+ this._configService.setConfig(_e, t);
555
558
  }
556
559
  onStarting() {
557
560
  [
558
561
  [g],
559
- [y],
560
- [C],
561
- [R]
562
+ [P],
563
+ [R],
564
+ [y]
562
565
  ].forEach((i) => {
563
566
  this._injector.add(i);
564
- }), A(this._injector, [
567
+ }), W(this._injector, [
565
568
  [g],
566
- [y],
567
- [C]
569
+ [P],
570
+ [R]
568
571
  ]);
569
572
  }
570
573
  onReady() {
571
- A(this._injector, [
572
- [R]
574
+ W(this._injector, [
575
+ [y]
573
576
  ]);
574
577
  }
575
578
  };
576
- V(P, "pluginName", G);
577
- V(P, "type", I.UNIVER_SHEET);
578
- P = Se([
579
- Y(re),
580
- H(1, Q),
581
- H(2, f(X))
582
- ], P);
579
+ O(w, "pluginName", V);
580
+ O(w, "packageName", z.name);
581
+ O(w, "version", z.version);
582
+ O(w, "type", C.UNIVER_SHEET);
583
+ w = Ce([
584
+ Q(ie),
585
+ J(1, X),
586
+ J(2, f(Z))
587
+ ], w);
583
588
  export {
584
589
  M as RemoveNoteMutation,
585
- ae as SheetDeleteNoteCommand,
586
- ce as SheetToggleNotePopupCommand,
587
- de as SheetUpdateNoteCommand,
590
+ ce as SheetDeleteNoteCommand,
591
+ de as SheetToggleNotePopupCommand,
592
+ he as SheetUpdateNoteCommand,
588
593
  g as SheetsNoteModel,
589
- C as SheetsNoteResourceController,
590
- b as ToggleNotePopupMutation,
591
- P as UniverSheetsNotePlugin,
592
- N as UpdateNoteMutation,
593
- $ as UpdateNotePositionMutation
594
+ R as SheetsNoteResourceController,
595
+ $ as ToggleNotePopupMutation,
596
+ w as UniverSheetsNotePlugin,
597
+ m as UpdateNoteMutation,
598
+ T as UpdateNotePositionMutation
594
599
  };
package/lib/index.js CHANGED
@@ -1,14 +1,14 @@
1
- var z = Object.defineProperty;
2
- var F = (i, r, e) => r in i ? z(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
3
- var _ = (i, r, e) => F(i, typeof r != "symbol" ? r + "" : r, e);
4
- import { Disposable as U, generateRandomId as J, CommandType as m, IUniverInstanceService as E, ICommandService as w, IUndoRedoService as T, IResourceManagerService as q, Inject as f, UniverInstanceType as I, sequenceExecuteAsync as K, DependentOn as Y, IConfigService as Q, Injector as X, Plugin as Z, merge as k, touchDependencies as A } from "@univerjs/core";
5
- import { getSheetCommandTarget as D, SheetsSelectionsService as x, SheetInterceptorService as ee, RemoveSheetCommand as te, CopySheetCommand as se, RefRangeService as oe, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as ne, UniverSheetsPlugin as re } from "@univerjs/sheets";
6
- import { Subject as ie, filter as W, map as B } from "rxjs";
1
+ var F = Object.defineProperty;
2
+ var q = (i, r, e) => r in i ? F(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
3
+ var _ = (i, r, e) => q(i, typeof r != "symbol" ? r + "" : r, e);
4
+ import { Disposable as U, generateRandomId as G, CommandType as N, IUniverInstanceService as E, ICommandService as v, IUndoRedoService as D, IResourceManagerService as K, Inject as f, UniverInstanceType as C, sequenceExecuteAsync as Y, DependentOn as Q, IConfigService as X, Injector as Z, Plugin as k, merge as ee, touchDependencies as W } from "@univerjs/core";
5
+ import { getSheetCommandTarget as j, SheetsSelectionsService as x, SheetInterceptorService as te, RemoveSheetCommand as se, CopySheetCommand as oe, RefRangeService as ne, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as re, UniverSheetsPlugin as ie } from "@univerjs/sheets";
6
+ import { Subject as ae, filter as B, map as L } from "rxjs";
7
7
  class g extends U {
8
8
  constructor() {
9
9
  super(...arguments);
10
10
  _(this, "_notesMap", /* @__PURE__ */ new Map());
11
- _(this, "_change$", new ie());
11
+ _(this, "_change$", new ae());
12
12
  _(this, "change$", this._change$.asObservable());
13
13
  }
14
14
  _ensureNotesMap(e, t) {
@@ -32,8 +32,8 @@ class g extends U {
32
32
  }
33
33
  getSheetShowNotes$(e, t) {
34
34
  return this._change$.pipe(
35
- W(({ unitId: s, subUnitId: o }) => s === e && o === t),
36
- B(() => {
35
+ B(({ unitId: s, subUnitId: o }) => s === e && o === t),
36
+ L(() => {
37
37
  const s = this._ensureNotesMap(e, t), o = [];
38
38
  for (const [n, a] of s)
39
39
  a.show && o.push({ loc: { row: a.row, col: a.col, unitId: e, subUnitId: t }, note: a });
@@ -43,14 +43,14 @@ class g extends U {
43
43
  }
44
44
  getCellNoteChange$(e, t, s, o) {
45
45
  return this._change$.pipe(
46
- W(({ unitId: n, subUnitId: a, oldNote: c }) => n !== e || a !== t || !c ? !1 : c.row === s && c.col === o),
47
- B((n) => n)
46
+ B(({ unitId: n, subUnitId: a, oldNote: c }) => n !== e || a !== t || !c ? !1 : c.row === s && c.col === o),
47
+ L((n) => n)
48
48
  );
49
49
  }
50
50
  updateNote(e, t, s, o, n, a) {
51
51
  const c = this._getNoteByParams(e, t, { noteId: n == null ? void 0 : n.id, row: s, col: o }), d = this._ensureNotesMap(e, t), h = {
52
52
  ...n,
53
- id: (c == null ? void 0 : c.id) || n.id || J(6),
53
+ id: (c == null ? void 0 : c.id) || n.id || G(6),
54
54
  row: s,
55
55
  col: o
56
56
  };
@@ -94,45 +94,45 @@ class g extends U {
94
94
  this._notesMap.delete(e);
95
95
  }
96
96
  }
97
- const N = {
97
+ const m = {
98
98
  id: "sheet.mutation.update-note",
99
- type: m.MUTATION,
99
+ type: N.MUTATION,
100
100
  handler: (i, r) => {
101
101
  const { unitId: e, sheetId: t, row: s, col: o, note: n, silent: a } = r;
102
102
  return i.get(g).updateNote(e, t, s, o, n, a), !0;
103
103
  }
104
104
  }, M = {
105
105
  id: "sheet.mutation.remove-note",
106
- type: m.MUTATION,
106
+ type: N.MUTATION,
107
107
  handler: (i, r) => {
108
108
  const { unitId: e, sheetId: t, noteId: s, row: o, col: n, silent: a } = r;
109
109
  return i.get(g).removeNote(e, t, { noteId: s, row: o, col: n, silent: a }), !0;
110
110
  }
111
- }, b = {
111
+ }, $ = {
112
112
  id: "sheet.mutation.toggle-note-popup",
113
- type: m.MUTATION,
113
+ type: N.MUTATION,
114
114
  handler: (i, r) => {
115
115
  const { unitId: e, sheetId: t, noteId: s, row: o, col: n, silent: a } = r;
116
116
  return i.get(g).toggleNotePopup(e, t, { noteId: s, row: o, col: n, silent: a }), !0;
117
117
  }
118
- }, $ = {
118
+ }, T = {
119
119
  id: "sheet.mutation.update-note-position",
120
- type: m.MUTATION,
120
+ type: N.MUTATION,
121
121
  handler: (i, r) => {
122
122
  const { unitId: e, sheetId: t, noteId: s, row: o, col: n, newPosition: a, silent: c } = r;
123
123
  return i.get(g).updateNotePosition(e, t, { noteId: s, row: o, col: n, newRow: a.row, newCol: a.col, silent: c }), !0;
124
124
  }
125
- }, ae = {
125
+ }, ce = {
126
126
  id: "sheet.command.delete-note",
127
- type: m.COMMAND,
127
+ type: N.COMMAND,
128
128
  handler: (i) => {
129
- const r = D(i.get(E));
129
+ const r = j(i.get(E));
130
130
  if (!r) return !1;
131
131
  const t = i.get(x).getCurrentLastSelection();
132
132
  if (!(t != null && t.primary)) return !1;
133
133
  const s = i.get(g), { unitId: o, subUnitId: n } = r, { actualColumn: a, actualRow: c } = t.primary, d = s.getNote(o, n, { row: c, col: a });
134
134
  if (!d) return !1;
135
- const h = i.get(w), u = i.get(T), l = {
135
+ const h = i.get(v), u = i.get(D), l = {
136
136
  id: M.id,
137
137
  params: {
138
138
  unitId: o,
@@ -140,7 +140,7 @@ const N = {
140
140
  noteId: d.id
141
141
  }
142
142
  }, p = {
143
- id: N.id,
143
+ id: m.id,
144
144
  params: {
145
145
  unitId: o,
146
146
  sheetId: n,
@@ -155,25 +155,25 @@ const N = {
155
155
  undoMutations: [p]
156
156
  }), !0) : !1;
157
157
  }
158
- }, ce = {
158
+ }, de = {
159
159
  id: "sheet.command.toggle-note-popup",
160
- type: m.COMMAND,
160
+ type: N.COMMAND,
161
161
  handler: (i) => {
162
- const r = D(i.get(E));
162
+ const r = j(i.get(E));
163
163
  if (!r) return !1;
164
164
  const t = i.get(x).getCurrentLastSelection();
165
165
  if (!(t != null && t.primary)) return !1;
166
166
  const s = i.get(g), { unitId: o, subUnitId: n } = r, { actualColumn: a, actualRow: c } = t.primary, d = s.getNote(o, n, { row: c, col: a });
167
167
  if (!d) return !1;
168
- const h = i.get(w), u = i.get(T), l = {
169
- id: b.id,
168
+ const h = i.get(v), u = i.get(D), l = {
169
+ id: $.id,
170
170
  params: {
171
171
  unitId: o,
172
172
  sheetId: n,
173
173
  noteId: d.id
174
174
  }
175
175
  }, p = {
176
- id: b.id,
176
+ id: $.id,
177
177
  params: {
178
178
  unitId: o,
179
179
  sheetId: n,
@@ -186,14 +186,14 @@ const N = {
186
186
  undoMutations: [p]
187
187
  }), !0) : !1;
188
188
  }
189
- }, de = {
189
+ }, he = {
190
190
  id: "sheet.command.update-note",
191
- type: m.COMMAND,
191
+ type: N.COMMAND,
192
192
  handler: (i, r) => {
193
- const e = D(i.get(E), r);
193
+ const e = j(i.get(E), r);
194
194
  if (!e) return !1;
195
- const t = i.get(w), s = i.get(T), o = i.get(g), { unitId: n, subUnitId: a } = e, { row: c, col: d, note: h } = r, u = o.getNote(n, a, { noteId: h.id, row: c, col: d }), l = {
196
- id: N.id,
195
+ const t = i.get(v), s = i.get(D), o = i.get(g), { unitId: n, subUnitId: a } = e, { row: c, col: d, note: h } = r, u = o.getNote(n, a, { noteId: h.id, row: c, col: d }), l = {
196
+ id: m.id,
197
197
  params: {
198
198
  unitId: n,
199
199
  sheetId: a,
@@ -203,8 +203,8 @@ const N = {
203
203
  }
204
204
  }, p = [];
205
205
  if (u) {
206
- const O = {
207
- id: N.id,
206
+ const b = {
207
+ id: m.id,
208
208
  params: {
209
209
  unitId: n,
210
210
  sheetId: a,
@@ -213,9 +213,9 @@ const N = {
213
213
  note: { ...u }
214
214
  }
215
215
  };
216
- p.push(O);
216
+ p.push(b);
217
217
  } else {
218
- const O = {
218
+ const b = {
219
219
  id: M.id,
220
220
  params: {
221
221
  unitId: n,
@@ -224,7 +224,7 @@ const N = {
224
224
  col: d
225
225
  }
226
226
  };
227
- p.push(O);
227
+ p.push(b);
228
228
  }
229
229
  return t.syncExecuteCommand(l.id, l.params) ? (s.pushUndoRedo({
230
230
  unitID: n,
@@ -232,13 +232,13 @@ const N = {
232
232
  undoMutations: p
233
233
  }), !0) : !1;
234
234
  }
235
- }, G = "SHEET_NOTE_PLUGIN";
236
- var he = Object.getOwnPropertyDescriptor, ue = (i, r, e, t) => {
237
- for (var s = t > 1 ? void 0 : t ? he(r, e) : r, o = i.length - 1, n; o >= 0; o--)
235
+ }, V = "SHEET_NOTE_PLUGIN";
236
+ var ue = Object.getOwnPropertyDescriptor, le = (i, r, e, t) => {
237
+ for (var s = t > 1 ? void 0 : t ? ue(r, e) : r, o = i.length - 1, n; o >= 0; o--)
238
238
  (n = i[o]) && (s = n(s) || s);
239
239
  return s;
240
240
  }, S = (i, r) => (e, t) => r(e, t, i);
241
- let C = class extends U {
241
+ let R = class extends U {
242
242
  constructor(i, r, e, t) {
243
243
  super(), this._resourceManagerService = i, this._univerInstanceService = r, this._sheetInterceptorService = e, this._sheetsNoteModel = t, this._initSnapshot(), this._initSheetChange();
244
244
  }
@@ -266,8 +266,8 @@ let C = class extends U {
266
266
  };
267
267
  this.disposeWithMe(
268
268
  this._resourceManagerService.registerPluginResource({
269
- pluginName: G,
270
- businesses: [I.UNIVER_SHEET],
269
+ pluginName: V,
270
+ businesses: [C.UNIVER_SHEET],
271
271
  toJson: (e) => i(e),
272
272
  parseJson: (e) => r(e),
273
273
  onUnLoad: (e) => {
@@ -298,8 +298,8 @@ let C = class extends U {
298
298
  // eslint-disable-next-line max-lines-per-function
299
299
  getMutations: (i) => {
300
300
  var r;
301
- if (i.id === te.id) {
302
- const e = i.params, t = e.unitId || this._univerInstanceService.getCurrentUnitOfType(I.UNIVER_SHEET).getUnitId(), s = e.subUnitId || ((r = this._univerInstanceService.getCurrentUnitOfType(I.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : r.getSheetId());
301
+ if (i.id === se.id) {
302
+ const e = i.params, t = e.unitId || this._univerInstanceService.getCurrentUnitOfType(C.UNIVER_SHEET).getUnitId(), s = e.subUnitId || ((r = this._univerInstanceService.getCurrentUnitOfType(C.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : r.getSheetId());
303
303
  if (!t || !s)
304
304
  return { redos: [], undos: [] };
305
305
  const o = this._sheetsNoteModel.getSheetNotes(t, s);
@@ -317,7 +317,7 @@ let C = class extends U {
317
317
  col: c.col
318
318
  }
319
319
  }), a.push({
320
- id: N.id,
320
+ id: m.id,
321
321
  params: {
322
322
  unitId: t,
323
323
  sheetId: s,
@@ -327,7 +327,7 @@ let C = class extends U {
327
327
  }
328
328
  });
329
329
  }), { redos: n, undos: a };
330
- } else if (i.id === se.id) {
330
+ } else if (i.id === oe.id) {
331
331
  const e = i.params, { unitId: t, subUnitId: s, targetSubUnitId: o } = e;
332
332
  if (!t || !s || !o)
333
333
  return { redos: [], undos: [] };
@@ -336,9 +336,9 @@ let C = class extends U {
336
336
  return { redos: [], undos: [] };
337
337
  const a = [], c = [];
338
338
  return n.forEach((d) => {
339
- const h = { ...d, id: J(6) };
339
+ const h = { ...d, id: G(6) };
340
340
  a.push({
341
- id: N.id,
341
+ id: m.id,
342
342
  params: {
343
343
  unitId: t,
344
344
  sheetId: o,
@@ -364,26 +364,29 @@ let C = class extends U {
364
364
  );
365
365
  }
366
366
  };
367
- C = ue([
368
- S(0, q),
367
+ R = le([
368
+ S(0, K),
369
369
  S(1, E),
370
- S(2, f(ee)),
370
+ S(2, f(te)),
371
371
  S(3, f(g))
372
- ], C);
373
- const le = "sheets-note.config", L = {};
374
- var pe = Object.getOwnPropertyDescriptor, ge = (i, r, e, t) => {
375
- for (var s = t > 1 ? void 0 : t ? pe(r, e) : r, o = i.length - 1, n; o >= 0; o--)
372
+ ], R);
373
+ const pe = "@univerjs/sheets-note", ge = "0.17.0", z = {
374
+ name: pe,
375
+ version: ge
376
+ }, _e = "sheets-note.config", H = {};
377
+ var me = Object.getOwnPropertyDescriptor, Ne = (i, r, e, t) => {
378
+ for (var s = t > 1 ? void 0 : t ? me(r, e) : r, o = i.length - 1, n; o >= 0; o--)
376
379
  (n = i[o]) && (s = n(s) || s);
377
380
  return s;
378
- }, v = (i, r) => (e, t) => r(e, t, i);
379
- let R = class extends U {
381
+ }, I = (i, r) => (e, t) => r(e, t, i);
382
+ let y = class extends U {
380
383
  constructor(r, e, t, s) {
381
384
  super();
382
385
  _(this, "_disposableMap", /* @__PURE__ */ new Map());
383
386
  _(this, "_watcherMap", /* @__PURE__ */ new Map());
384
387
  _(this, "_handleRangeChange", (r, e, t, s, o, n, a) => n ? {
385
388
  redos: [{
386
- id: $.id,
389
+ id: T.id,
387
390
  params: {
388
391
  unitId: r,
389
392
  sheetId: e,
@@ -396,7 +399,7 @@ let R = class extends U {
396
399
  }
397
400
  }],
398
401
  undos: [{
399
- id: $.id,
402
+ id: T.id,
400
403
  params: {
401
404
  unitId: r,
402
405
  sheetId: e,
@@ -419,7 +422,7 @@ let R = class extends U {
419
422
  }
420
423
  }],
421
424
  undos: [{
422
- id: N.id,
425
+ id: m.id,
423
426
  params: {
424
427
  unitId: r,
425
428
  sheetId: e,
@@ -444,7 +447,7 @@ let R = class extends U {
444
447
  this._disposableMap.set(
445
448
  this._getIdWithUnitId(r, e, s, o),
446
449
  this._refRangeService.registerRefRange(n, (a) => {
447
- const c = ne(n, a, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
450
+ const c = re(n, a, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
448
451
  return d && d.startColumn === n.startColumn && d.startRow === n.startRow ? {
449
452
  undos: [],
450
453
  redos: []
@@ -463,7 +466,7 @@ let R = class extends U {
463
466
  this._getIdWithUnitId(r, e, s, o),
464
467
  this._refRangeService.watchRange(r, e, n, (a, c) => {
465
468
  const { redos: d } = this._handleRangeChange(r, e, t, a.startRow, a.startColumn, c, !0);
466
- K(d, this._commandService, { onlyLocal: !0 });
469
+ Y(d, this._commandService, { onlyLocal: !0 });
467
470
  }, !0)
468
471
  );
469
472
  }
@@ -504,30 +507,30 @@ let R = class extends U {
504
507
  );
505
508
  }
506
509
  };
507
- R = ge([
508
- v(0, f(oe)),
509
- v(1, f(g)),
510
- v(2, f(x)),
511
- v(3, w)
512
- ], R);
513
- var _e = Object.getOwnPropertyDescriptor, Ne = (i, r, e, t) => {
514
- for (var s = t > 1 ? void 0 : t ? _e(r, e) : r, o = i.length - 1, n; o >= 0; o--)
510
+ y = Ne([
511
+ I(0, f(ne)),
512
+ I(1, f(g)),
513
+ I(2, f(x)),
514
+ I(3, v)
515
+ ], y);
516
+ var fe = Object.getOwnPropertyDescriptor, Me = (i, r, e, t) => {
517
+ for (var s = t > 1 ? void 0 : t ? fe(r, e) : r, o = i.length - 1, n; o >= 0; o--)
515
518
  (n = i[o]) && (s = n(s) || s);
516
519
  return s;
517
- }, me = (i, r) => (e, t) => r(e, t, i);
518
- let y = class extends U {
520
+ }, we = (i, r) => (e, t) => r(e, t, i);
521
+ let P = class extends U {
519
522
  constructor(i) {
520
523
  super(), this._commandService = i, this._initialize();
521
524
  }
522
525
  _initialize() {
523
526
  [
527
+ T,
524
528
  $,
525
- b,
526
- N,
529
+ m,
527
530
  M,
528
- ae,
529
531
  ce,
530
- de
532
+ de,
533
+ he
531
534
  ].forEach((i) => {
532
535
  this.disposeWithMe(
533
536
  this._commandService.registerCommand(i)
@@ -535,60 +538,62 @@ let y = class extends U {
535
538
  });
536
539
  }
537
540
  };
538
- y = Ne([
539
- me(0, w)
540
- ], y);
541
- var fe = Object.defineProperty, Me = Object.getOwnPropertyDescriptor, we = (i, r, e) => r in i ? fe(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e, Se = (i, r, e, t) => {
542
- for (var s = t > 1 ? void 0 : t ? Me(r, e) : r, o = i.length - 1, n; o >= 0; o--)
541
+ P = Me([
542
+ we(0, v)
543
+ ], P);
544
+ var ve = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, Ie = (i, r, e) => r in i ? ve(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e, Ce = (i, r, e, t) => {
545
+ for (var s = t > 1 ? void 0 : t ? Se(r, e) : r, o = i.length - 1, n; o >= 0; o--)
543
546
  (n = i[o]) && (s = n(s) || s);
544
547
  return s;
545
- }, H = (i, r) => (e, t) => r(e, t, i), V = (i, r, e) => we(i, typeof r != "symbol" ? r + "" : r, e);
546
- let P = class extends Z {
547
- constructor(i = L, r, e) {
548
+ }, J = (i, r) => (e, t) => r(e, t, i), O = (i, r, e) => Ie(i, typeof r != "symbol" ? r + "" : r, e);
549
+ let w = class extends k {
550
+ constructor(i = H, r, e) {
548
551
  super(), this._config = i, this._configService = r, this._injector = e;
549
- const { ...t } = k(
552
+ const { ...t } = ee(
550
553
  {},
551
- L,
554
+ H,
552
555
  this._config
553
556
  );
554
- this._configService.setConfig(le, t);
557
+ this._configService.setConfig(_e, t);
555
558
  }
556
559
  onStarting() {
557
560
  [
558
561
  [g],
559
- [y],
560
- [C],
561
- [R]
562
+ [P],
563
+ [R],
564
+ [y]
562
565
  ].forEach((i) => {
563
566
  this._injector.add(i);
564
- }), A(this._injector, [
567
+ }), W(this._injector, [
565
568
  [g],
566
- [y],
567
- [C]
569
+ [P],
570
+ [R]
568
571
  ]);
569
572
  }
570
573
  onReady() {
571
- A(this._injector, [
572
- [R]
574
+ W(this._injector, [
575
+ [y]
573
576
  ]);
574
577
  }
575
578
  };
576
- V(P, "pluginName", G);
577
- V(P, "type", I.UNIVER_SHEET);
578
- P = Se([
579
- Y(re),
580
- H(1, Q),
581
- H(2, f(X))
582
- ], P);
579
+ O(w, "pluginName", V);
580
+ O(w, "packageName", z.name);
581
+ O(w, "version", z.version);
582
+ O(w, "type", C.UNIVER_SHEET);
583
+ w = Ce([
584
+ Q(ie),
585
+ J(1, X),
586
+ J(2, f(Z))
587
+ ], w);
583
588
  export {
584
589
  M as RemoveNoteMutation,
585
- ae as SheetDeleteNoteCommand,
586
- ce as SheetToggleNotePopupCommand,
587
- de as SheetUpdateNoteCommand,
590
+ ce as SheetDeleteNoteCommand,
591
+ de as SheetToggleNotePopupCommand,
592
+ he as SheetUpdateNoteCommand,
588
593
  g as SheetsNoteModel,
589
- C as SheetsNoteResourceController,
590
- b as ToggleNotePopupMutation,
591
- P as UniverSheetsNotePlugin,
592
- N as UpdateNoteMutation,
593
- $ as UpdateNotePositionMutation
594
+ R as SheetsNoteResourceController,
595
+ $ as ToggleNotePopupMutation,
596
+ w as UniverSheetsNotePlugin,
597
+ m as UpdateNoteMutation,
598
+ T as UpdateNotePositionMutation
594
599
  };
@@ -15,7 +15,7 @@
15
15
  */
16
16
  export * from './commands/commands/note.command';
17
17
  export * from './commands/mutations/note.mutation';
18
- export type { IUniverSheetsNoteConfig } from './controllers/config.schema';
18
+ export type { IUniverSheetsNoteConfig } from './config/config';
19
19
  export * from './controllers/sheets-note-resource.controller';
20
20
  export * from './models/sheets-note.model';
21
21
  export { UniverSheetsNotePlugin } from './plugin';
@@ -1,10 +1,12 @@
1
- import { IUniverSheetsNoteConfig } from './controllers/config.schema';
1
+ import { IUniverSheetsNoteConfig } from './config/config';
2
2
  import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
3
  export declare class UniverSheetsNotePlugin extends Plugin {
4
4
  private readonly _config;
5
5
  private readonly _configService;
6
6
  protected readonly _injector: Injector;
7
7
  static pluginName: string;
8
+ static packageName: string;
9
+ static version: string;
8
10
  static type: UniverInstanceType;
9
11
  constructor(_config: IUniverSheetsNoteConfig | undefined, _configService: IConfigService, _injector: Injector);
10
12
  onStarting(): void;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(u,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],c):(u=typeof globalThis<"u"?globalThis:u||self,c(u.UniverSheetsNote={},u.UniverCore,u.UniverSheets,u.rxjs))})(this,(function(u,c,g,M){"use strict";var Q=Object.defineProperty;var X=(u,c,g)=>c in u?Q(u,c,{enumerable:!0,configurable:!0,writable:!0,value:g}):u[c]=g;var v=(u,c,g)=>X(u,typeof c!="symbol"?c+"":c,g);class m extends c.Disposable{constructor(){super(...arguments);v(this,"_notesMap",new Map);v(this,"_change$",new M.Subject);v(this,"change$",this._change$.asObservable())}_ensureNotesMap(t,e){let n=this._notesMap.get(t);n||(n=new Map,this._notesMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}_getNoteByPosition(t,e,n,o){const s=this._ensureNotesMap(t,e);for(const[r,d]of s)if(d.row===n&&d.col===o)return d}_getNoteById(t,e,n){return this._ensureNotesMap(t,e).get(n)}_getNoteByParams(t,e,n){const{noteId:o,row:s,col:r}=n;return o?this._getNoteById(t,e,o):s!==void 0&&r!==void 0?this._getNoteByPosition(t,e,s,r):null}getSheetShowNotes$(t,e){return this._change$.pipe(M.filter(({unitId:n,subUnitId:o})=>n===t&&o===e),M.map(()=>{const n=this._ensureNotesMap(t,e),o=[];for(const[s,r]of n)r.show&&o.push({loc:{row:r.row,col:r.col,unitId:t,subUnitId:e},note:r});return o}))}getCellNoteChange$(t,e,n,o){return this._change$.pipe(M.filter(({unitId:s,subUnitId:r,oldNote:d})=>s!==t||r!==e||!d?!1:d.row===n&&d.col===o),M.map(s=>s))}updateNote(t,e,n,o,s,r){const d=this._getNoteByParams(t,e,{noteId:s==null?void 0:s.id,row:n,col:o}),h=this._ensureNotesMap(t,e),l={...s,id:(d==null?void 0:d.id)||s.id||c.generateRandomId(6),row:n,col:o};h.set(l.id,l),this._change$.next({unitId:t,subUnitId:e,oldNote:d,type:"update",newNote:l,silent:r})}removeNote(t,e,n){const{noteId:o,row:s,col:r,silent:d}=n,h=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!h)return;this._ensureNotesMap(t,e).delete(h.id),this._change$.next({unitId:t,subUnitId:e,oldNote:h,type:"update",newNote:null,silent:d})}toggleNotePopup(t,e,n){const{noteId:o,row:s,col:r,silent:d}=n,h=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!h)return;const l=this._ensureNotesMap(t,e),p={...h,show:!h.show};l.set(p.id,p),this._change$.next({unitId:t,subUnitId:e,oldNote:h,type:"update",newNote:p,silent:d})}updateNotePosition(t,e,n){const{noteId:o,row:s,col:r,newRow:d,newCol:h,silent:l}=n,p=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!p)return;const _=this._ensureNotesMap(t,e),N={...p,row:d,col:h};_.set(N.id,N),this._change$.next({unitId:t,subUnitId:e,oldNote:p,type:"ref",newNote:N,silent:l})}getNote(t,e,n){return this._getNoteByParams(t,e,n)}getNotes(){return this._notesMap}getUnitNotes(t){return this._notesMap.get(t)}getSheetNotes(t,e){const n=this._notesMap.get(t);if(n)return n.get(e)}deleteUnitNotes(t){this._notesMap.delete(t)}}const S={id:"sheet.mutation.update-note",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,row:n,col:o,note:s,silent:r}=i;return a.get(m).updateNote(t,e,n,o,s,r),!0}},f={id:"sheet.mutation.remove-note",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,silent:r}=i;return a.get(m).removeNote(t,e,{noteId:n,row:o,col:s,silent:r}),!0}},I={id:"sheet.mutation.toggle-note-popup",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,silent:r}=i;return a.get(m).toggleNotePopup(t,e,{noteId:n,row:o,col:s,silent:r}),!0}},w={id:"sheet.mutation.update-note-position",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,newPosition:r,silent:d}=i;return a.get(m).updateNotePosition(t,e,{noteId:n,row:o,col:s,newRow:r.row,newCol:r.col,silent:d}),!0}},T={id:"sheet.command.delete-note",type:c.CommandType.COMMAND,handler:a=>{const i=g.getSheetCommandTarget(a.get(c.IUniverInstanceService));if(!i)return!1;const e=a.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;const n=a.get(m),{unitId:o,subUnitId:s}=i,{actualColumn:r,actualRow:d}=e.primary,h=n.getNote(o,s,{row:d,col:r});if(!h)return!1;const l=a.get(c.ICommandService),p=a.get(c.IUndoRedoService),_={id:f.id,params:{unitId:o,sheetId:s,noteId:h.id}},N={id:S.id,params:{unitId:o,sheetId:s,row:d,col:r,note:{...h}}};return l.syncExecuteCommand(_.id,_.params)?(p.pushUndoRedo({unitID:o,redoMutations:[_],undoMutations:[N]}),!0):!1}},E={id:"sheet.command.toggle-note-popup",type:c.CommandType.COMMAND,handler:a=>{const i=g.getSheetCommandTarget(a.get(c.IUniverInstanceService));if(!i)return!1;const e=a.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;const n=a.get(m),{unitId:o,subUnitId:s}=i,{actualColumn:r,actualRow:d}=e.primary,h=n.getNote(o,s,{row:d,col:r});if(!h)return!1;const l=a.get(c.ICommandService),p=a.get(c.IUndoRedoService),_={id:I.id,params:{unitId:o,sheetId:s,noteId:h.id}},N={id:I.id,params:{unitId:o,sheetId:s,noteId:h.id}};return l.syncExecuteCommand(_.id,_.params)?(p.pushUndoRedo({unitID:o,redoMutations:[_],undoMutations:[N]}),!0):!1}},O={id:"sheet.command.update-note",type:c.CommandType.COMMAND,handler:(a,i)=>{const t=g.getSheetCommandTarget(a.get(c.IUniverInstanceService),i);if(!t)return!1;const e=a.get(c.ICommandService),n=a.get(c.IUndoRedoService),o=a.get(m),{unitId:s,subUnitId:r}=t,{row:d,col:h,note:l}=i,p=o.getNote(s,r,{noteId:l.id,row:d,col:h}),_={id:S.id,params:{unitId:s,sheetId:r,row:d,col:h,note:l}},N=[];if(p){const P={id:S.id,params:{unitId:s,sheetId:r,row:d,col:h,note:{...p}}};N.push(P)}else{const P={id:f.id,params:{unitId:s,sheetId:r,row:d,col:h}};N.push(P)}return e.syncExecuteCommand(_.id,_.params)?(n.pushUndoRedo({unitID:s,redoMutations:[_],undoMutations:N}),!0):!1}},b="SHEET_NOTE_PLUGIN";var W=Object.getOwnPropertyDescriptor,B=(a,i,t,e)=>{for(var n=e>1?void 0:e?W(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},C=(a,i)=>(t,e)=>i(t,e,a);u.SheetsNoteResourceController=class extends c.Disposable{constructor(i,t,e,n){super(),this._resourceManagerService=i,this._univerInstanceService=t,this._sheetInterceptorService=e,this._sheetsNoteModel=n,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){const i=e=>{const n=this._sheetsNoteModel.getUnitNotes(e);if(!n)return"";const o={};return n.forEach((s,r)=>{const d={};s.forEach(h=>{const{row:l,col:p}=h;d[l]||(d[l]={}),d[l][p]=h}),Object.keys(d).length>0&&(o[r]=d)}),JSON.stringify(o)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:b,businesses:[c.UniverInstanceType.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._sheetsNoteModel.deleteUnitNotes(e)},onLoad:(e,n)=>{Object.entries(n).forEach(([o,s])=>{Object.entries(s).forEach(([r,d])=>{Object.entries(d).forEach(([h,l])=>{this._sheetsNoteModel.updateNote(e,o,Number(r),Number(h),l)})})})}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===g.RemoveSheetCommand.id){const e=i.params,n=e.unitId||this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=e.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!n||!o)return{redos:[],undos:[]};const s=this._sheetsNoteModel.getSheetNotes(n,o);if(!s)return{redos:[],undos:[]};const r=[],d=[];return s.forEach(h=>{r.push({id:f.id,params:{unitId:n,sheetId:o,noteId:h.id,row:h.row,col:h.col}}),d.push({id:S.id,params:{unitId:n,sheetId:o,row:h.row,col:h.col,note:h}})}),{redos:r,undos:d}}else if(i.id===g.CopySheetCommand.id){const e=i.params,{unitId:n,subUnitId:o,targetSubUnitId:s}=e;if(!n||!o||!s)return{redos:[],undos:[]};const r=this._sheetsNoteModel.getSheetNotes(n,o);if(!r)return{redos:[],undos:[]};const d=[],h=[];return r.forEach(l=>{const p={...l,id:c.generateRandomId(6)};d.push({id:S.id,params:{unitId:n,sheetId:s,row:p.row,col:p.col,note:p}}),h.push({id:f.id,params:{unitId:n,sheetId:s,noteId:p.id,row:p.row,col:p.col}})}),{redos:d,undos:h}}return{redos:[],undos:[]}}}))}},u.SheetsNoteResourceController=B([C(0,c.IResourceManagerService),C(1,c.IUniverInstanceService),C(2,c.Inject(g.SheetInterceptorService)),C(3,c.Inject(m))],u.SheetsNoteResourceController);const L="sheets-note.config",D={};var H=Object.getOwnPropertyDescriptor,J=(a,i,t,e)=>{for(var n=e>1?void 0:e?H(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},R=(a,i)=>(t,e)=>i(t,e,a);let y=class extends c.Disposable{constructor(i,t,e,n){super();v(this,"_disposableMap",new Map);v(this,"_watcherMap",new Map);v(this,"_handleRangeChange",(i,t,e,n,o,s,r)=>s?{redos:[{id:w.id,params:{unitId:i,sheetId:t,noteId:e.id,newPosition:{row:s.startRow,col:s.startColumn},silent:r}}],undos:[{id:w.id,params:{unitId:i,sheetId:t,noteId:e.id,newPosition:{row:n,col:o},note:e,silent:r}}]}:{redos:[{id:f.id,params:{unitId:i,sheetId:t,noteId:e.id}}],undos:[{id:S.id,params:{unitId:i,sheetId:t,row:n,col:o,note:e}}]});this._refRangeService=i,this._sheetsNoteModel=t,this._selectionManagerService=e,this._commandService=n,this._initData(),this._initRefRange()}_getIdWithUnitId(i,t,e,n){return`${i}-${t}-${e}-${n}`}_register(i,t,e,n,o){const s={startColumn:o,endColumn:o,startRow:n,endRow:n};this._disposableMap.set(this._getIdWithUnitId(i,t,n,o),this._refRangeService.registerRefRange(s,r=>{const d=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,r,{selectionManagerService:this._selectionManagerService}),h=Array.isArray(d)?d[0]:d;return h&&h.startColumn===s.startColumn&&h.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(i,t,e,n,o,h,!1)},i,t))}_watch(i,t,e,n,o){const s={startColumn:o,endColumn:o,startRow:n,endRow:n};this._watcherMap.set(this._getIdWithUnitId(i,t,n,o),this._refRangeService.watchRange(i,t,s,(r,d)=>{const{redos:h}=this._handleRangeChange(i,t,e,r.startRow,r.startColumn,d,!0);c.sequenceExecuteAsync(h,this._commandService,{onlyLocal:!0})},!0))}_unwatch(i,t,e,n){var s;const o=this._getIdWithUnitId(i,t,e,n);(s=this._watcherMap.get(o))==null||s.dispose(),this._watcherMap.delete(o)}_unregister(i,t,e,n){var s;const o=this._getIdWithUnitId(i,t,e,n);(s=this._disposableMap.get(o))==null||s.dispose(),this._disposableMap.delete(o)}_initData(){const i=this._sheetsNoteModel.getNotes();for(const[t,e]of i)for(const[n,o]of e)o.forEach(s=>{this._register(t,n,s,s.row,s.col),this._watch(t,n,s,s.row,s.col)})}_initRefRange(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(i=>{switch(i.type){case"update":{const{unitId:t,subUnitId:e,oldNote:n,newNote:o}=i,s=o?o.row:n.row,r=o?o.col:n.col,d=this._getIdWithUnitId(t,e,s,r);o?this._disposableMap.has(d)||(this._register(t,e,o,s,r),this._watch(t,e,o,s,r)):(this._unregister(t,e,s,r),this._unwatch(t,e,s,r));break}case"ref":{const{unitId:t,subUnitId:e,oldNote:n,newNote:o,silent:s}=i,{row:r,col:d}=n,{row:h,col:l}=o;this._unregister(t,e,r,d),s||(this._unwatch(t,e,r,d),this._watch(t,e,o,h,l)),this._register(t,e,o,h,l);break}}}))}};y=J([R(0,c.Inject(g.RefRangeService)),R(1,c.Inject(m)),R(2,c.Inject(g.SheetsSelectionsService)),R(3,c.ICommandService)],y);var q=Object.getOwnPropertyDescriptor,G=(a,i,t,e)=>{for(var n=e>1?void 0:e?q(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},V=(a,i)=>(t,e)=>i(t,e,a);let U=class extends c.Disposable{constructor(a){super(),this._commandService=a,this._initialize()}_initialize(){[w,I,S,f,T,E,O].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}};U=G([V(0,c.ICommandService)],U);var z=Object.defineProperty,F=Object.getOwnPropertyDescriptor,K=(a,i,t)=>i in a?z(a,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[i]=t,Y=(a,i,t,e)=>{for(var n=e>1?void 0:e?F(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},$=(a,i)=>(t,e)=>i(t,e,a),j=(a,i,t)=>K(a,typeof i!="symbol"?i+"":i,t);u.UniverSheetsNotePlugin=class extends c.Plugin{constructor(i=D,t,e){super(),this._config=i,this._configService=t,this._injector=e;const{...n}=c.merge({},D,this._config);this._configService.setConfig(L,n)}onStarting(){[[m],[U],[u.SheetsNoteResourceController],[y]].forEach(i=>{this._injector.add(i)}),c.touchDependencies(this._injector,[[m],[U],[u.SheetsNoteResourceController]])}onReady(){c.touchDependencies(this._injector,[[y]])}},j(u.UniverSheetsNotePlugin,"pluginName",b),j(u.UniverSheetsNotePlugin,"type",c.UniverInstanceType.UNIVER_SHEET),u.UniverSheetsNotePlugin=Y([c.DependentOn(g.UniverSheetsPlugin),$(1,c.IConfigService),$(2,c.Inject(c.Injector))],u.UniverSheetsNotePlugin),u.RemoveNoteMutation=f,u.SheetDeleteNoteCommand=T,u.SheetToggleNotePopupCommand=E,u.SheetUpdateNoteCommand=O,u.SheetsNoteModel=m,u.ToggleNotePopupMutation=I,u.UpdateNoteMutation=S,u.UpdateNotePositionMutation=w,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(u,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],c):(u=typeof globalThis<"u"?globalThis:u||self,c(u.UniverSheetsNote={},u.UniverCore,u.UniverSheets,u.rxjs))})(this,(function(u,c,g,M){"use strict";var X=Object.defineProperty;var Z=(u,c,g)=>c in u?X(u,c,{enumerable:!0,configurable:!0,writable:!0,value:g}):u[c]=g;var f=(u,c,g)=>Z(u,typeof c!="symbol"?c+"":c,g);class m extends c.Disposable{constructor(){super(...arguments);f(this,"_notesMap",new Map);f(this,"_change$",new M.Subject);f(this,"change$",this._change$.asObservable())}_ensureNotesMap(t,e){let n=this._notesMap.get(t);n||(n=new Map,this._notesMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}_getNoteByPosition(t,e,n,o){const s=this._ensureNotesMap(t,e);for(const[r,d]of s)if(d.row===n&&d.col===o)return d}_getNoteById(t,e,n){return this._ensureNotesMap(t,e).get(n)}_getNoteByParams(t,e,n){const{noteId:o,row:s,col:r}=n;return o?this._getNoteById(t,e,o):s!==void 0&&r!==void 0?this._getNoteByPosition(t,e,s,r):null}getSheetShowNotes$(t,e){return this._change$.pipe(M.filter(({unitId:n,subUnitId:o})=>n===t&&o===e),M.map(()=>{const n=this._ensureNotesMap(t,e),o=[];for(const[s,r]of n)r.show&&o.push({loc:{row:r.row,col:r.col,unitId:t,subUnitId:e},note:r});return o}))}getCellNoteChange$(t,e,n,o){return this._change$.pipe(M.filter(({unitId:s,subUnitId:r,oldNote:d})=>s!==t||r!==e||!d?!1:d.row===n&&d.col===o),M.map(s=>s))}updateNote(t,e,n,o,s,r){const d=this._getNoteByParams(t,e,{noteId:s==null?void 0:s.id,row:n,col:o}),h=this._ensureNotesMap(t,e),l={...s,id:(d==null?void 0:d.id)||s.id||c.generateRandomId(6),row:n,col:o};h.set(l.id,l),this._change$.next({unitId:t,subUnitId:e,oldNote:d,type:"update",newNote:l,silent:r})}removeNote(t,e,n){const{noteId:o,row:s,col:r,silent:d}=n,h=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!h)return;this._ensureNotesMap(t,e).delete(h.id),this._change$.next({unitId:t,subUnitId:e,oldNote:h,type:"update",newNote:null,silent:d})}toggleNotePopup(t,e,n){const{noteId:o,row:s,col:r,silent:d}=n,h=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!h)return;const l=this._ensureNotesMap(t,e),p={...h,show:!h.show};l.set(p.id,p),this._change$.next({unitId:t,subUnitId:e,oldNote:h,type:"update",newNote:p,silent:d})}updateNotePosition(t,e,n){const{noteId:o,row:s,col:r,newRow:d,newCol:h,silent:l}=n,p=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!p)return;const _=this._ensureNotesMap(t,e),N={...p,row:d,col:h};_.set(N.id,N),this._change$.next({unitId:t,subUnitId:e,oldNote:p,type:"ref",newNote:N,silent:l})}getNote(t,e,n){return this._getNoteByParams(t,e,n)}getNotes(){return this._notesMap}getUnitNotes(t){return this._notesMap.get(t)}getSheetNotes(t,e){const n=this._notesMap.get(t);if(n)return n.get(e)}deleteUnitNotes(t){this._notesMap.delete(t)}}const S={id:"sheet.mutation.update-note",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,row:n,col:o,note:s,silent:r}=i;return a.get(m).updateNote(t,e,n,o,s,r),!0}},v={id:"sheet.mutation.remove-note",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,silent:r}=i;return a.get(m).removeNote(t,e,{noteId:n,row:o,col:s,silent:r}),!0}},I={id:"sheet.mutation.toggle-note-popup",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,silent:r}=i;return a.get(m).toggleNotePopup(t,e,{noteId:n,row:o,col:s,silent:r}),!0}},w={id:"sheet.mutation.update-note-position",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,newPosition:r,silent:d}=i;return a.get(m).updateNotePosition(t,e,{noteId:n,row:o,col:s,newRow:r.row,newCol:r.col,silent:d}),!0}},E={id:"sheet.command.delete-note",type:c.CommandType.COMMAND,handler:a=>{const i=g.getSheetCommandTarget(a.get(c.IUniverInstanceService));if(!i)return!1;const e=a.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;const n=a.get(m),{unitId:o,subUnitId:s}=i,{actualColumn:r,actualRow:d}=e.primary,h=n.getNote(o,s,{row:d,col:r});if(!h)return!1;const l=a.get(c.ICommandService),p=a.get(c.IUndoRedoService),_={id:v.id,params:{unitId:o,sheetId:s,noteId:h.id}},N={id:S.id,params:{unitId:o,sheetId:s,row:d,col:r,note:{...h}}};return l.syncExecuteCommand(_.id,_.params)?(p.pushUndoRedo({unitID:o,redoMutations:[_],undoMutations:[N]}),!0):!1}},O={id:"sheet.command.toggle-note-popup",type:c.CommandType.COMMAND,handler:a=>{const i=g.getSheetCommandTarget(a.get(c.IUniverInstanceService));if(!i)return!1;const e=a.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;const n=a.get(m),{unitId:o,subUnitId:s}=i,{actualColumn:r,actualRow:d}=e.primary,h=n.getNote(o,s,{row:d,col:r});if(!h)return!1;const l=a.get(c.ICommandService),p=a.get(c.IUndoRedoService),_={id:I.id,params:{unitId:o,sheetId:s,noteId:h.id}},N={id:I.id,params:{unitId:o,sheetId:s,noteId:h.id}};return l.syncExecuteCommand(_.id,_.params)?(p.pushUndoRedo({unitID:o,redoMutations:[_],undoMutations:[N]}),!0):!1}},b={id:"sheet.command.update-note",type:c.CommandType.COMMAND,handler:(a,i)=>{const t=g.getSheetCommandTarget(a.get(c.IUniverInstanceService),i);if(!t)return!1;const e=a.get(c.ICommandService),n=a.get(c.IUndoRedoService),o=a.get(m),{unitId:s,subUnitId:r}=t,{row:d,col:h,note:l}=i,p=o.getNote(s,r,{noteId:l.id,row:d,col:h}),_={id:S.id,params:{unitId:s,sheetId:r,row:d,col:h,note:l}},N=[];if(p){const T={id:S.id,params:{unitId:s,sheetId:r,row:d,col:h,note:{...p}}};N.push(T)}else{const T={id:v.id,params:{unitId:s,sheetId:r,row:d,col:h}};N.push(T)}return e.syncExecuteCommand(_.id,_.params)?(n.pushUndoRedo({unitID:s,redoMutations:[_],undoMutations:N}),!0):!1}},D="SHEET_NOTE_PLUGIN";var B=Object.getOwnPropertyDescriptor,L=(a,i,t,e)=>{for(var n=e>1?void 0:e?B(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},C=(a,i)=>(t,e)=>i(t,e,a);u.SheetsNoteResourceController=class extends c.Disposable{constructor(i,t,e,n){super(),this._resourceManagerService=i,this._univerInstanceService=t,this._sheetInterceptorService=e,this._sheetsNoteModel=n,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){const i=e=>{const n=this._sheetsNoteModel.getUnitNotes(e);if(!n)return"";const o={};return n.forEach((s,r)=>{const d={};s.forEach(h=>{const{row:l,col:p}=h;d[l]||(d[l]={}),d[l][p]=h}),Object.keys(d).length>0&&(o[r]=d)}),JSON.stringify(o)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:D,businesses:[c.UniverInstanceType.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._sheetsNoteModel.deleteUnitNotes(e)},onLoad:(e,n)=>{Object.entries(n).forEach(([o,s])=>{Object.entries(s).forEach(([r,d])=>{Object.entries(d).forEach(([h,l])=>{this._sheetsNoteModel.updateNote(e,o,Number(r),Number(h),l)})})})}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===g.RemoveSheetCommand.id){const e=i.params,n=e.unitId||this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=e.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!n||!o)return{redos:[],undos:[]};const s=this._sheetsNoteModel.getSheetNotes(n,o);if(!s)return{redos:[],undos:[]};const r=[],d=[];return s.forEach(h=>{r.push({id:v.id,params:{unitId:n,sheetId:o,noteId:h.id,row:h.row,col:h.col}}),d.push({id:S.id,params:{unitId:n,sheetId:o,row:h.row,col:h.col,note:h}})}),{redos:r,undos:d}}else if(i.id===g.CopySheetCommand.id){const e=i.params,{unitId:n,subUnitId:o,targetSubUnitId:s}=e;if(!n||!o||!s)return{redos:[],undos:[]};const r=this._sheetsNoteModel.getSheetNotes(n,o);if(!r)return{redos:[],undos:[]};const d=[],h=[];return r.forEach(l=>{const p={...l,id:c.generateRandomId(6)};d.push({id:S.id,params:{unitId:n,sheetId:s,row:p.row,col:p.col,note:p}}),h.push({id:v.id,params:{unitId:n,sheetId:s,noteId:p.id,row:p.row,col:p.col}})}),{redos:d,undos:h}}return{redos:[],undos:[]}}}))}},u.SheetsNoteResourceController=L([C(0,c.IResourceManagerService),C(1,c.IUniverInstanceService),C(2,c.Inject(g.SheetInterceptorService)),C(3,c.Inject(m))],u.SheetsNoteResourceController);const $={name:"@univerjs/sheets-note",version:"0.17.0"},H="sheets-note.config",j={};var J=Object.getOwnPropertyDescriptor,q=(a,i,t,e)=>{for(var n=e>1?void 0:e?J(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},R=(a,i)=>(t,e)=>i(t,e,a);let U=class extends c.Disposable{constructor(i,t,e,n){super();f(this,"_disposableMap",new Map);f(this,"_watcherMap",new Map);f(this,"_handleRangeChange",(i,t,e,n,o,s,r)=>s?{redos:[{id:w.id,params:{unitId:i,sheetId:t,noteId:e.id,newPosition:{row:s.startRow,col:s.startColumn},silent:r}}],undos:[{id:w.id,params:{unitId:i,sheetId:t,noteId:e.id,newPosition:{row:n,col:o},note:e,silent:r}}]}:{redos:[{id:v.id,params:{unitId:i,sheetId:t,noteId:e.id}}],undos:[{id:S.id,params:{unitId:i,sheetId:t,row:n,col:o,note:e}}]});this._refRangeService=i,this._sheetsNoteModel=t,this._selectionManagerService=e,this._commandService=n,this._initData(),this._initRefRange()}_getIdWithUnitId(i,t,e,n){return`${i}-${t}-${e}-${n}`}_register(i,t,e,n,o){const s={startColumn:o,endColumn:o,startRow:n,endRow:n};this._disposableMap.set(this._getIdWithUnitId(i,t,n,o),this._refRangeService.registerRefRange(s,r=>{const d=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,r,{selectionManagerService:this._selectionManagerService}),h=Array.isArray(d)?d[0]:d;return h&&h.startColumn===s.startColumn&&h.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(i,t,e,n,o,h,!1)},i,t))}_watch(i,t,e,n,o){const s={startColumn:o,endColumn:o,startRow:n,endRow:n};this._watcherMap.set(this._getIdWithUnitId(i,t,n,o),this._refRangeService.watchRange(i,t,s,(r,d)=>{const{redos:h}=this._handleRangeChange(i,t,e,r.startRow,r.startColumn,d,!0);c.sequenceExecuteAsync(h,this._commandService,{onlyLocal:!0})},!0))}_unwatch(i,t,e,n){var s;const o=this._getIdWithUnitId(i,t,e,n);(s=this._watcherMap.get(o))==null||s.dispose(),this._watcherMap.delete(o)}_unregister(i,t,e,n){var s;const o=this._getIdWithUnitId(i,t,e,n);(s=this._disposableMap.get(o))==null||s.dispose(),this._disposableMap.delete(o)}_initData(){const i=this._sheetsNoteModel.getNotes();for(const[t,e]of i)for(const[n,o]of e)o.forEach(s=>{this._register(t,n,s,s.row,s.col),this._watch(t,n,s,s.row,s.col)})}_initRefRange(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(i=>{switch(i.type){case"update":{const{unitId:t,subUnitId:e,oldNote:n,newNote:o}=i,s=o?o.row:n.row,r=o?o.col:n.col,d=this._getIdWithUnitId(t,e,s,r);o?this._disposableMap.has(d)||(this._register(t,e,o,s,r),this._watch(t,e,o,s,r)):(this._unregister(t,e,s,r),this._unwatch(t,e,s,r));break}case"ref":{const{unitId:t,subUnitId:e,oldNote:n,newNote:o,silent:s}=i,{row:r,col:d}=n,{row:h,col:l}=o;this._unregister(t,e,r,d),s||(this._unwatch(t,e,r,d),this._watch(t,e,o,h,l)),this._register(t,e,o,h,l);break}}}))}};U=q([R(0,c.Inject(g.RefRangeService)),R(1,c.Inject(m)),R(2,c.Inject(g.SheetsSelectionsService)),R(3,c.ICommandService)],U);var G=Object.getOwnPropertyDescriptor,V=(a,i,t,e)=>{for(var n=e>1?void 0:e?G(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},z=(a,i)=>(t,e)=>i(t,e,a);let y=class extends c.Disposable{constructor(a){super(),this._commandService=a,this._initialize()}_initialize(){[w,I,S,v,E,O,b].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}};y=V([z(0,c.ICommandService)],y);var F=Object.defineProperty,K=Object.getOwnPropertyDescriptor,Y=(a,i,t)=>i in a?F(a,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[i]=t,Q=(a,i,t,e)=>{for(var n=e>1?void 0:e?K(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},A=(a,i)=>(t,e)=>i(t,e,a),P=(a,i,t)=>Y(a,typeof i!="symbol"?i+"":i,t);u.UniverSheetsNotePlugin=class extends c.Plugin{constructor(i=j,t,e){super(),this._config=i,this._configService=t,this._injector=e;const{...n}=c.merge({},j,this._config);this._configService.setConfig(H,n)}onStarting(){[[m],[y],[u.SheetsNoteResourceController],[U]].forEach(i=>{this._injector.add(i)}),c.touchDependencies(this._injector,[[m],[y],[u.SheetsNoteResourceController]])}onReady(){c.touchDependencies(this._injector,[[U]])}},P(u.UniverSheetsNotePlugin,"pluginName",D),P(u.UniverSheetsNotePlugin,"packageName",$.name),P(u.UniverSheetsNotePlugin,"version",$.version),P(u.UniverSheetsNotePlugin,"type",c.UniverInstanceType.UNIVER_SHEET),u.UniverSheetsNotePlugin=Q([c.DependentOn(g.UniverSheetsPlugin),A(1,c.IConfigService),A(2,c.Inject(c.Injector))],u.UniverSheetsNotePlugin),u.RemoveNoteMutation=v,u.SheetDeleteNoteCommand=E,u.SheetToggleNotePopupCommand=O,u.SheetUpdateNoteCommand=b,u.SheetsNoteModel=m,u.ToggleNotePopupMutation=I,u.UpdateNoteMutation=S,u.UpdateNotePositionMutation=w,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-note",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "description": "Univer sheets note base plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,15 +56,15 @@
56
56
  "rxjs": ">=7.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@univerjs/sheets": "0.16.1",
60
- "@univerjs/core": "0.16.1"
59
+ "@univerjs/core": "0.17.0",
60
+ "@univerjs/sheets": "0.17.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "rxjs": "^7.8.2",
64
64
  "typescript": "^5.9.3",
65
65
  "vite": "^7.3.1",
66
66
  "vitest": "^4.0.18",
67
- "@univerjs-infra/shared": "0.16.1"
67
+ "@univerjs-infra/shared": "0.17.0"
68
68
  },
69
69
  "scripts": {
70
70
  "test": "vitest run",