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