@univerjs/sheets-note 0.18.0 → 0.19.0-insiders.20260403-3e0e122

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
- 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;
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 extends e.FEventName{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,s={workbook:a,worksheet:o,row:r.row,col:r.col,note:r};this.fireEvent(this.Event.SheetNoteAdd,s)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col,oldNote:r};this.fireEvent(this.Event.SheetNoteDelete,s)}}))),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,c={workbook:o,worksheet:s,row:i.row,col:i.col,note:i,oldNote:r};this.fireEvent(this.Event.SheetNoteUpdate,c)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteShow,s)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteHide,s)}}))),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,f={workbook:u,worksheet:d,row:o,col:s,note:c};if(this.fireEvent(this.Event.BeforeSheetNoteAdd,f))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,f={workbook:u,worksheet:d,row:o,col:s,oldNote:l};if(this.fireEvent(this.Event.BeforeSheetNoteDelete,f))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,p={workbook:d,worksheet:f,row:o,col:s,note:c,oldNote:u};if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,p))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;let m={workbook:s,worksheet:c,row:f,col:d};if(this.fireEvent(this.Event.BeforeSheetNoteShow,m))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;let m={workbook:s,worksheet:c,row:f,col:d};if(this.fireEvent(this.Event.BeforeSheetNoteHide,m))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.FRangeSheetsNoteMixin=o,exports.FSheetsNoteEventNameMixin=a,exports.FUniverSheetsNoteMixin=s,exports.FWorksheetNoteMixin=c;
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
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;
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.19.0-insiders.20260403-3e0e122`;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 +1 @@
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};
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 extends 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`}};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,s={workbook:a,worksheet:o,row:r.row,col:r.col,note:r};this.fireEvent(this.Event.SheetNoteAdd,s)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col,oldNote:r};this.fireEvent(this.Event.SheetNoteDelete,s)}}))),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,c={workbook:o,worksheet:s,row:i.row,col:i.col,note:i,oldNote:r};this.fireEvent(this.Event.SheetNoteUpdate,c)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteShow,s)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteHide,s)}}))),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,f={workbook:l,worksheet:d,row:i,col:a,note:s};if(this.fireEvent(this.Event.BeforeSheetNoteAdd,f))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,f={workbook:l,worksheet:d,row:i,col:a,oldNote:c};if(this.fireEvent(this.Event.BeforeSheetNoteDelete,f))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,p={workbook:d,worksheet:f,row:i,col:a,note:s,oldNote:l};if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,p))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;let g={workbook:i,worksheet:a,row:d,col:l};if(this.fireEvent(this.Event.BeforeSheetNoteShow,g))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;let g={workbook:i,worksheet:a,row:d,col:l};if(this.fireEvent(this.Event.BeforeSheetNoteHide,g))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{g as FRangeSheetsNoteMixin,h as FSheetsNoteEventNameMixin,_ as FUniverSheetsNoteMixin,v as FWorksheetNoteMixin};
package/lib/es/index.js CHANGED
@@ -1 +1 @@
1
- import{CommandType as e,DependentOn as t,Disposable as n,ICommandService as r,IConfigService as i,IResourceManagerService as a,IUndoRedoService as o,IUniverInstanceService as s,Inject as c,Injector as l,Plugin as u,UniverInstanceType as d,generateRandomId as f,merge as p,sequenceExecuteAsync as m,touchDependencies as h}from"@univerjs/core";import{CopySheetCommand as g,RefRangeService as _,RemoveSheetCommand as v,SheetInterceptorService as y,SheetsSelectionsService as b,UniverSheetsPlugin as x,getSheetCommandTarget as S,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as C}from"@univerjs/sheets";import{Subject as w,filter as T,map as E}from"rxjs";function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j=class extends n{constructor(...e){super(...e),A(this,`_notesMap`,new Map),A(this,`_change$`,new w),A(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(T(({unitId:n,subUnitId:r})=>n===e&&r===t),E(()=>{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,n,r){return this._change$.pipe(T(({unitId:i,subUnitId:a,oldNote:o})=>i!==e||a!==t||!o?!1:o.row===n&&o.col===r),E(e=>e))}updateNote(e,t,n,r,i,a){let o=this._getNoteByParams(e,t,{noteId:i==null?void 0:i.id,row:n,col:r}),s=this._ensureNotesMap(e,t),c={...i,id:(o==null?void 0:o.id)||i.id||f(6),row:n,col:r};s.set(c.id,c),this._change$.next({unitId:e,subUnitId:t,oldNote:o,type:`update`,newNote:c,silent:a})}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 M={id:`sheet.mutation.update-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(j).updateNote(n,r,i,a,o,s),!0}},N={id:`sheet.mutation.remove-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},P={id:`sheet.mutation.toggle-note-popup`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},F={id:`sheet.mutation.update-note-position`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:c}=t;return e.get(j).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:c}),!0}},I={id:`sheet.command.delete-note`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:N.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:M.id,params:{unitId:a,sheetId:c,row:u,col:l,note:{...d}}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},L={id:`sheet.command.toggle-note-popup`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},R={id:`sheet.command.update-note`,type:e.COMMAND,handler:(e,t)=>{let n=S(e.get(s),t);if(!n)return!1;let i=e.get(r),a=e.get(o),c=e.get(j),{unitId:l,subUnitId:u}=n,{row:d,col:f,note:p}=t,m=c.getNote(l,u,{noteId:p.id,row:d,col:f}),h={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:p}},g=[];if(m){let e={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:{...m}}};g.push(e)}else{let e={id:N.id,params:{unitId:l,sheetId:u,row:d,col:f}};g.push(e)}return i.syncExecuteCommand(h.id,h.params)?(a.pushUndoRedo({unitID:l,redoMutations:[h],undoMutations:g}),!0):!1}},z=`SHEET_NOTE_PLUGIN`;function B(e,t){return function(n,r){t(n,r,e)}}function V(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 H=class extends n{constructor(e,t,n,r){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._sheetInterceptorService=n,this._sheetsNoteModel=r,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){let e=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)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:z,businesses:[d.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>t(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:e=>{if(e.id===v.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(r,i);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{o.push({id:N.id,params:{unitId:r,sheetId:i,noteId:e.id,row:e.row,col:e.col}}),s.push({id:M.id,params:{unitId:r,sheetId:i,row:e.row,col:e.col,note:e}})}),{redos:o,undos:s}}else if(e.id===g.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._sheetsNoteModel.getSheetNotes(t,n);if(!i)return{redos:[],undos:[]};let a=[],o=[];return i.forEach(e=>{let n={...e,id:f(6)};a.push({id:M.id,params:{unitId:t,sheetId:r,row:n.row,col:n.col,note:n}}),o.push({id:N.id,params:{unitId:t,sheetId:r,noteId:n.id,row:n.row,col:n.col}})}),{redos:a,undos:o}}return{redos:[],undos:[]}}}))}};H=V([B(0,a),B(1,s),B(2,c(y)),B(3,c(j))],H);var U=`@univerjs/sheets-note`,W=`0.18.0`;const G=`sheets-note.config`;Symbol(G);const K={};let q=class extends n{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,A(this,`_disposableMap`,new Map),A(this,`_watcherMap`,new Map),A(this,`_handleRangeChange`,(e,t,n,r,i,a,o)=>a?{redos:[{id:F.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:a.startRow,col:a.startColumn},silent:o}}],undos:[{id:F.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:r,col:i},note:n,silent:o}}]}:{redos:[{id:N.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:M.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,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._disposableMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.registerRefRange(a,o=>{let s=C(a,o,{selectionManagerService:this._selectionManagerService}),c=Array.isArray(s)?s[0]:s;return c&&c.startColumn===a.startColumn&&c.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,r,i,c,!1)},e,t))}_watch(e,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._watcherMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.watchRange(e,t,a,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,r.startRow,r.startColumn,i,!0);m(a,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}}}))}};q=V([B(0,c(_)),B(1,c(j)),B(2,c(b)),B(3,r)],q);let J=class extends n{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[F,P,M,N,I,L,R].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};J=V([B(0,r)],J);let Y=class extends u{constructor(e=K,t,n){super(),this._config=e,this._configService=t,this._injector=n;let{...r}=p({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[j],[J],[H],[q]].forEach(e=>{this._injector.add(e)}),h(this._injector,[[j],[J],[H]])}onReady(){h(this._injector,[[q]])}};A(Y,`pluginName`,z),A(Y,`packageName`,U),A(Y,`version`,W),A(Y,`type`,d.UNIVER_SHEET),Y=V([t(x),B(1,i),B(2,c(l))],Y);export{N as RemoveNoteMutation,I as SheetDeleteNoteCommand,L as SheetToggleNotePopupCommand,R as SheetUpdateNoteCommand,j as SheetsNoteModel,H as SheetsNoteResourceController,P as ToggleNotePopupMutation,Y as UniverSheetsNotePlugin,M as UpdateNoteMutation,F as UpdateNotePositionMutation};
1
+ import{CommandType as e,DependentOn as t,Disposable as n,ICommandService as r,IConfigService as i,IResourceManagerService as a,IUndoRedoService as o,IUniverInstanceService as s,Inject as c,Injector as l,Plugin as u,UniverInstanceType as d,generateRandomId as f,merge as p,sequenceExecuteAsync as m,touchDependencies as h}from"@univerjs/core";import{CopySheetCommand as g,RefRangeService as _,RemoveSheetCommand as v,SheetInterceptorService as y,SheetsSelectionsService as b,UniverSheetsPlugin as x,getSheetCommandTarget as S,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as C}from"@univerjs/sheets";import{Subject as w,filter as T,map as E}from"rxjs";function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j=class extends n{constructor(...e){super(...e),A(this,`_notesMap`,new Map),A(this,`_change$`,new w),A(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(T(({unitId:n,subUnitId:r})=>n===e&&r===t),E(()=>{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,n,r){return this._change$.pipe(T(({unitId:i,subUnitId:a,oldNote:o})=>i!==e||a!==t||!o?!1:o.row===n&&o.col===r),E(e=>e))}updateNote(e,t,n,r,i,a){let o=this._getNoteByParams(e,t,{noteId:i==null?void 0:i.id,row:n,col:r}),s=this._ensureNotesMap(e,t),c={...i,id:(o==null?void 0:o.id)||i.id||f(6),row:n,col:r};s.set(c.id,c),this._change$.next({unitId:e,subUnitId:t,oldNote:o,type:`update`,newNote:c,silent:a})}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 M={id:`sheet.mutation.update-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(j).updateNote(n,r,i,a,o,s),!0}},N={id:`sheet.mutation.remove-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},P={id:`sheet.mutation.toggle-note-popup`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},F={id:`sheet.mutation.update-note-position`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:c}=t;return e.get(j).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:c}),!0}},I={id:`sheet.command.delete-note`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:N.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:M.id,params:{unitId:a,sheetId:c,row:u,col:l,note:{...d}}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},L={id:`sheet.command.toggle-note-popup`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},R={id:`sheet.command.update-note`,type:e.COMMAND,handler:(e,t)=>{let n=S(e.get(s),t);if(!n)return!1;let i=e.get(r),a=e.get(o),c=e.get(j),{unitId:l,subUnitId:u}=n,{row:d,col:f,note:p}=t,m=c.getNote(l,u,{noteId:p.id,row:d,col:f}),h={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:p}},g=[];if(m){let e={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:{...m}}};g.push(e)}else{let e={id:N.id,params:{unitId:l,sheetId:u,row:d,col:f}};g.push(e)}return i.syncExecuteCommand(h.id,h.params)?(a.pushUndoRedo({unitID:l,redoMutations:[h],undoMutations:g}),!0):!1}},z=`SHEET_NOTE_PLUGIN`;function B(e,t){return function(n,r){t(n,r,e)}}function V(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 H=class extends n{constructor(e,t,n,r){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._sheetInterceptorService=n,this._sheetsNoteModel=r,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){let e=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)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:z,businesses:[d.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>t(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:e=>{if(e.id===v.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(r,i);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{o.push({id:N.id,params:{unitId:r,sheetId:i,noteId:e.id,row:e.row,col:e.col}}),s.push({id:M.id,params:{unitId:r,sheetId:i,row:e.row,col:e.col,note:e}})}),{redos:o,undos:s}}else if(e.id===g.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._sheetsNoteModel.getSheetNotes(t,n);if(!i)return{redos:[],undos:[]};let a=[],o=[];return i.forEach(e=>{let n={...e,id:f(6)};a.push({id:M.id,params:{unitId:t,sheetId:r,row:n.row,col:n.col,note:n}}),o.push({id:N.id,params:{unitId:t,sheetId:r,noteId:n.id,row:n.row,col:n.col}})}),{redos:a,undos:o}}return{redos:[],undos:[]}}}))}};H=V([B(0,a),B(1,s),B(2,c(y)),B(3,c(j))],H);var U=`@univerjs/sheets-note`,W=`0.19.0-insiders.20260403-3e0e122`;const G=`sheets-note.config`;Symbol(G);const K={};let q=class extends n{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,A(this,`_disposableMap`,new Map),A(this,`_watcherMap`,new Map),A(this,`_handleRangeChange`,(e,t,n,r,i,a,o)=>a?{redos:[{id:F.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:a.startRow,col:a.startColumn},silent:o}}],undos:[{id:F.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:r,col:i},note:n,silent:o}}]}:{redos:[{id:N.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:M.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,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._disposableMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.registerRefRange(a,o=>{let s=C(a,o,{selectionManagerService:this._selectionManagerService}),c=Array.isArray(s)?s[0]:s;return c&&c.startColumn===a.startColumn&&c.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,r,i,c,!1)},e,t))}_watch(e,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._watcherMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.watchRange(e,t,a,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,r.startRow,r.startColumn,i,!0);m(a,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}}}))}};q=V([B(0,c(_)),B(1,c(j)),B(2,c(b)),B(3,r)],q);let J=class extends n{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[F,P,M,N,I,L,R].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};J=V([B(0,r)],J);let Y=class extends u{constructor(e=K,t,n){super(),this._config=e,this._configService=t,this._injector=n;let{...r}=p({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[j],[J],[H],[q]].forEach(e=>{this._injector.add(e)}),h(this._injector,[[j],[J],[H]])}onReady(){h(this._injector,[[q]])}};A(Y,`pluginName`,z),A(Y,`packageName`,U),A(Y,`version`,W),A(Y,`type`,d.UNIVER_SHEET),Y=V([t(x),B(1,i),B(2,c(l))],Y);export{N as RemoveNoteMutation,I as SheetDeleteNoteCommand,L as SheetToggleNotePopupCommand,R as SheetUpdateNoteCommand,j as SheetsNoteModel,H as SheetsNoteResourceController,P as ToggleNotePopupMutation,Y as UniverSheetsNotePlugin,M as UpdateNoteMutation,F as UpdateNotePositionMutation};
package/lib/facade.js CHANGED
@@ -1 +1 @@
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};
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 extends 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`}};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,s={workbook:a,worksheet:o,row:r.row,col:r.col,note:r};this.fireEvent(this.Event.SheetNoteAdd,s)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col,oldNote:r};this.fireEvent(this.Event.SheetNoteDelete,s)}}))),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,c={workbook:o,worksheet:s,row:i.row,col:i.col,note:i,oldNote:r};this.fireEvent(this.Event.SheetNoteUpdate,c)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteShow,s)}}))),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,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteHide,s)}}))),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,f={workbook:l,worksheet:d,row:i,col:a,note:s};if(this.fireEvent(this.Event.BeforeSheetNoteAdd,f))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,f={workbook:l,worksheet:d,row:i,col:a,oldNote:c};if(this.fireEvent(this.Event.BeforeSheetNoteDelete,f))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,p={workbook:d,worksheet:f,row:i,col:a,note:s,oldNote:l};if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,p))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;let g={workbook:i,worksheet:a,row:d,col:l};if(this.fireEvent(this.Event.BeforeSheetNoteShow,g))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;let g={workbook:i,worksheet:a,row:d,col:l};if(this.fireEvent(this.Event.BeforeSheetNoteHide,g))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{g as FRangeSheetsNoteMixin,h as FSheetsNoteEventNameMixin,_ as FUniverSheetsNoteMixin,v as FWorksheetNoteMixin};
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import{CommandType as e,DependentOn as t,Disposable as n,ICommandService as r,IConfigService as i,IResourceManagerService as a,IUndoRedoService as o,IUniverInstanceService as s,Inject as c,Injector as l,Plugin as u,UniverInstanceType as d,generateRandomId as f,merge as p,sequenceExecuteAsync as m,touchDependencies as h}from"@univerjs/core";import{CopySheetCommand as g,RefRangeService as _,RemoveSheetCommand as v,SheetInterceptorService as y,SheetsSelectionsService as b,UniverSheetsPlugin as x,getSheetCommandTarget as S,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as C}from"@univerjs/sheets";import{Subject as w,filter as T,map as E}from"rxjs";function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j=class extends n{constructor(...e){super(...e),A(this,`_notesMap`,new Map),A(this,`_change$`,new w),A(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(T(({unitId:n,subUnitId:r})=>n===e&&r===t),E(()=>{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,n,r){return this._change$.pipe(T(({unitId:i,subUnitId:a,oldNote:o})=>i!==e||a!==t||!o?!1:o.row===n&&o.col===r),E(e=>e))}updateNote(e,t,n,r,i,a){let o=this._getNoteByParams(e,t,{noteId:i==null?void 0:i.id,row:n,col:r}),s=this._ensureNotesMap(e,t),c={...i,id:(o==null?void 0:o.id)||i.id||f(6),row:n,col:r};s.set(c.id,c),this._change$.next({unitId:e,subUnitId:t,oldNote:o,type:`update`,newNote:c,silent:a})}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 M={id:`sheet.mutation.update-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(j).updateNote(n,r,i,a,o,s),!0}},N={id:`sheet.mutation.remove-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},P={id:`sheet.mutation.toggle-note-popup`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},F={id:`sheet.mutation.update-note-position`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:c}=t;return e.get(j).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:c}),!0}},I={id:`sheet.command.delete-note`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:N.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:M.id,params:{unitId:a,sheetId:c,row:u,col:l,note:{...d}}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},L={id:`sheet.command.toggle-note-popup`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},R={id:`sheet.command.update-note`,type:e.COMMAND,handler:(e,t)=>{let n=S(e.get(s),t);if(!n)return!1;let i=e.get(r),a=e.get(o),c=e.get(j),{unitId:l,subUnitId:u}=n,{row:d,col:f,note:p}=t,m=c.getNote(l,u,{noteId:p.id,row:d,col:f}),h={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:p}},g=[];if(m){let e={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:{...m}}};g.push(e)}else{let e={id:N.id,params:{unitId:l,sheetId:u,row:d,col:f}};g.push(e)}return i.syncExecuteCommand(h.id,h.params)?(a.pushUndoRedo({unitID:l,redoMutations:[h],undoMutations:g}),!0):!1}},z=`SHEET_NOTE_PLUGIN`;function B(e,t){return function(n,r){t(n,r,e)}}function V(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 H=class extends n{constructor(e,t,n,r){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._sheetInterceptorService=n,this._sheetsNoteModel=r,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){let e=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)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:z,businesses:[d.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>t(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:e=>{if(e.id===v.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(r,i);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{o.push({id:N.id,params:{unitId:r,sheetId:i,noteId:e.id,row:e.row,col:e.col}}),s.push({id:M.id,params:{unitId:r,sheetId:i,row:e.row,col:e.col,note:e}})}),{redos:o,undos:s}}else if(e.id===g.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._sheetsNoteModel.getSheetNotes(t,n);if(!i)return{redos:[],undos:[]};let a=[],o=[];return i.forEach(e=>{let n={...e,id:f(6)};a.push({id:M.id,params:{unitId:t,sheetId:r,row:n.row,col:n.col,note:n}}),o.push({id:N.id,params:{unitId:t,sheetId:r,noteId:n.id,row:n.row,col:n.col}})}),{redos:a,undos:o}}return{redos:[],undos:[]}}}))}};H=V([B(0,a),B(1,s),B(2,c(y)),B(3,c(j))],H);var U=`@univerjs/sheets-note`,W=`0.18.0`;const G=`sheets-note.config`;Symbol(G);const K={};let q=class extends n{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,A(this,`_disposableMap`,new Map),A(this,`_watcherMap`,new Map),A(this,`_handleRangeChange`,(e,t,n,r,i,a,o)=>a?{redos:[{id:F.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:a.startRow,col:a.startColumn},silent:o}}],undos:[{id:F.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:r,col:i},note:n,silent:o}}]}:{redos:[{id:N.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:M.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,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._disposableMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.registerRefRange(a,o=>{let s=C(a,o,{selectionManagerService:this._selectionManagerService}),c=Array.isArray(s)?s[0]:s;return c&&c.startColumn===a.startColumn&&c.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,r,i,c,!1)},e,t))}_watch(e,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._watcherMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.watchRange(e,t,a,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,r.startRow,r.startColumn,i,!0);m(a,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}}}))}};q=V([B(0,c(_)),B(1,c(j)),B(2,c(b)),B(3,r)],q);let J=class extends n{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[F,P,M,N,I,L,R].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};J=V([B(0,r)],J);let Y=class extends u{constructor(e=K,t,n){super(),this._config=e,this._configService=t,this._injector=n;let{...r}=p({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[j],[J],[H],[q]].forEach(e=>{this._injector.add(e)}),h(this._injector,[[j],[J],[H]])}onReady(){h(this._injector,[[q]])}};A(Y,`pluginName`,z),A(Y,`packageName`,U),A(Y,`version`,W),A(Y,`type`,d.UNIVER_SHEET),Y=V([t(x),B(1,i),B(2,c(l))],Y);export{N as RemoveNoteMutation,I as SheetDeleteNoteCommand,L as SheetToggleNotePopupCommand,R as SheetUpdateNoteCommand,j as SheetsNoteModel,H as SheetsNoteResourceController,P as ToggleNotePopupMutation,Y as UniverSheetsNotePlugin,M as UpdateNoteMutation,F as UpdateNotePositionMutation};
1
+ import{CommandType as e,DependentOn as t,Disposable as n,ICommandService as r,IConfigService as i,IResourceManagerService as a,IUndoRedoService as o,IUniverInstanceService as s,Inject as c,Injector as l,Plugin as u,UniverInstanceType as d,generateRandomId as f,merge as p,sequenceExecuteAsync as m,touchDependencies as h}from"@univerjs/core";import{CopySheetCommand as g,RefRangeService as _,RemoveSheetCommand as v,SheetInterceptorService as y,SheetsSelectionsService as b,UniverSheetsPlugin as x,getSheetCommandTarget as S,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as C}from"@univerjs/sheets";import{Subject as w,filter as T,map as E}from"rxjs";function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j=class extends n{constructor(...e){super(...e),A(this,`_notesMap`,new Map),A(this,`_change$`,new w),A(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(T(({unitId:n,subUnitId:r})=>n===e&&r===t),E(()=>{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,n,r){return this._change$.pipe(T(({unitId:i,subUnitId:a,oldNote:o})=>i!==e||a!==t||!o?!1:o.row===n&&o.col===r),E(e=>e))}updateNote(e,t,n,r,i,a){let o=this._getNoteByParams(e,t,{noteId:i==null?void 0:i.id,row:n,col:r}),s=this._ensureNotesMap(e,t),c={...i,id:(o==null?void 0:o.id)||i.id||f(6),row:n,col:r};s.set(c.id,c),this._change$.next({unitId:e,subUnitId:t,oldNote:o,type:`update`,newNote:c,silent:a})}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 M={id:`sheet.mutation.update-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(j).updateNote(n,r,i,a,o,s),!0}},N={id:`sheet.mutation.remove-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},P={id:`sheet.mutation.toggle-note-popup`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},F={id:`sheet.mutation.update-note-position`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:c}=t;return e.get(j).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:c}),!0}},I={id:`sheet.command.delete-note`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:N.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:M.id,params:{unitId:a,sheetId:c,row:u,col:l,note:{...d}}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},L={id:`sheet.command.toggle-note-popup`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},R={id:`sheet.command.update-note`,type:e.COMMAND,handler:(e,t)=>{let n=S(e.get(s),t);if(!n)return!1;let i=e.get(r),a=e.get(o),c=e.get(j),{unitId:l,subUnitId:u}=n,{row:d,col:f,note:p}=t,m=c.getNote(l,u,{noteId:p.id,row:d,col:f}),h={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:p}},g=[];if(m){let e={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:{...m}}};g.push(e)}else{let e={id:N.id,params:{unitId:l,sheetId:u,row:d,col:f}};g.push(e)}return i.syncExecuteCommand(h.id,h.params)?(a.pushUndoRedo({unitID:l,redoMutations:[h],undoMutations:g}),!0):!1}},z=`SHEET_NOTE_PLUGIN`;function B(e,t){return function(n,r){t(n,r,e)}}function V(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 H=class extends n{constructor(e,t,n,r){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._sheetInterceptorService=n,this._sheetsNoteModel=r,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){let e=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)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:z,businesses:[d.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>t(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:e=>{if(e.id===v.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(r,i);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{o.push({id:N.id,params:{unitId:r,sheetId:i,noteId:e.id,row:e.row,col:e.col}}),s.push({id:M.id,params:{unitId:r,sheetId:i,row:e.row,col:e.col,note:e}})}),{redos:o,undos:s}}else if(e.id===g.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._sheetsNoteModel.getSheetNotes(t,n);if(!i)return{redos:[],undos:[]};let a=[],o=[];return i.forEach(e=>{let n={...e,id:f(6)};a.push({id:M.id,params:{unitId:t,sheetId:r,row:n.row,col:n.col,note:n}}),o.push({id:N.id,params:{unitId:t,sheetId:r,noteId:n.id,row:n.row,col:n.col}})}),{redos:a,undos:o}}return{redos:[],undos:[]}}}))}};H=V([B(0,a),B(1,s),B(2,c(y)),B(3,c(j))],H);var U=`@univerjs/sheets-note`,W=`0.19.0-insiders.20260403-3e0e122`;const G=`sheets-note.config`;Symbol(G);const K={};let q=class extends n{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,A(this,`_disposableMap`,new Map),A(this,`_watcherMap`,new Map),A(this,`_handleRangeChange`,(e,t,n,r,i,a,o)=>a?{redos:[{id:F.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:a.startRow,col:a.startColumn},silent:o}}],undos:[{id:F.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:r,col:i},note:n,silent:o}}]}:{redos:[{id:N.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:M.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,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._disposableMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.registerRefRange(a,o=>{let s=C(a,o,{selectionManagerService:this._selectionManagerService}),c=Array.isArray(s)?s[0]:s;return c&&c.startColumn===a.startColumn&&c.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,r,i,c,!1)},e,t))}_watch(e,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._watcherMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.watchRange(e,t,a,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,r.startRow,r.startColumn,i,!0);m(a,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}}}))}};q=V([B(0,c(_)),B(1,c(j)),B(2,c(b)),B(3,r)],q);let J=class extends n{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[F,P,M,N,I,L,R].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};J=V([B(0,r)],J);let Y=class extends u{constructor(e=K,t,n){super(),this._config=e,this._configService=t,this._injector=n;let{...r}=p({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[j],[J],[H],[q]].forEach(e=>{this._injector.add(e)}),h(this._injector,[[j],[J],[H]])}onReady(){h(this._injector,[[q]])}};A(Y,`pluginName`,z),A(Y,`packageName`,U),A(Y,`version`,W),A(Y,`type`,d.UNIVER_SHEET),Y=V([t(x),B(1,i),B(2,c(l))],Y);export{N as RemoveNoteMutation,I as SheetDeleteNoteCommand,L as SheetToggleNotePopupCommand,R as SheetUpdateNoteCommand,j as SheetsNoteModel,H as SheetsNoteResourceController,P as ToggleNotePopupMutation,Y as UniverSheetsNotePlugin,M as UpdateNoteMutation,F as UpdateNotePositionMutation};
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import type { ISheetNote } from '@univerjs/sheets-note';
17
17
  import type { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
18
+ import { FEventName } from '@univerjs/core/facade';
18
19
  export interface ISheetNoteAddEventParams {
19
20
  workbook: FWorkbook;
20
21
  worksheet: FWorksheet;
@@ -72,7 +73,7 @@ export interface ISheetsNoteEventParamConfig {
72
73
  /**
73
74
  * @ignore
74
75
  */
75
- interface ISheetNoteEvent {
76
+ interface IFSheetsNoteEventNameMixin {
76
77
  /**
77
78
  * Event fired when a note is added
78
79
  * @see {@link ISheetNoteAddEventParams}
@@ -86,7 +87,7 @@ interface ISheetNoteEvent {
86
87
  * // Remove the event listener, use `disposable.dispose()`
87
88
  * ```
88
89
  */
89
- SheetNoteAdd: 'SheetNoteAdd';
90
+ readonly SheetNoteAdd: 'SheetNoteAdd';
90
91
  /**
91
92
  * Event fired when a note is deleted
92
93
  * @see {@link ISheetNoteDeleteEventParams}
@@ -100,7 +101,7 @@ interface ISheetNoteEvent {
100
101
  * // Remove the event listener, use `disposable.dispose()`
101
102
  * ```
102
103
  */
103
- SheetNoteDelete: 'SheetNoteDelete';
104
+ readonly SheetNoteDelete: 'SheetNoteDelete';
104
105
  /**
105
106
  * Event fired when a note is updated
106
107
  * @see {@link ISheetNoteUpdateEventParams}
@@ -114,7 +115,7 @@ interface ISheetNoteEvent {
114
115
  * // Remove the event listener, use `disposable.dispose()`
115
116
  * ```
116
117
  */
117
- SheetNoteUpdate: 'SheetNoteUpdate';
118
+ readonly SheetNoteUpdate: 'SheetNoteUpdate';
118
119
  /**
119
120
  * Event fired when a note is shown
120
121
  * @see {@link ISheetNoteShowEventParams}
@@ -128,7 +129,7 @@ interface ISheetNoteEvent {
128
129
  * // Remove the event listener, use `disposable.dispose()`
129
130
  * ```
130
131
  */
131
- SheetNoteShow: 'SheetNoteShow';
132
+ readonly SheetNoteShow: 'SheetNoteShow';
132
133
  /**
133
134
  * Event fired when a note is hidden
134
135
  * @see {@link ISheetNoteHideEventParams}
@@ -142,7 +143,7 @@ interface ISheetNoteEvent {
142
143
  * // Remove the event listener, use `disposable.dispose()`
143
144
  * ```
144
145
  */
145
- SheetNoteHide: 'SheetNoteHide';
146
+ readonly SheetNoteHide: 'SheetNoteHide';
146
147
  /**
147
148
  * Event fired before a note is added
148
149
  * @see {@link ISheetNoteAddEventParams}
@@ -159,7 +160,7 @@ interface ISheetNoteEvent {
159
160
  * // Remove the event listener, use `disposable.dispose()`
160
161
  * ```
161
162
  */
162
- BeforeSheetNoteAdd: 'BeforeSheetNoteAdd';
163
+ readonly BeforeSheetNoteAdd: 'BeforeSheetNoteAdd';
163
164
  /**
164
165
  * Event fired before a note is deleted
165
166
  * @see {@link ISheetNoteDeleteEventParams}
@@ -176,7 +177,7 @@ interface ISheetNoteEvent {
176
177
  * // Remove the event listener, use `disposable.dispose()`
177
178
  * ```
178
179
  */
179
- BeforeSheetNoteDelete: 'BeforeSheetNoteDelete';
180
+ readonly BeforeSheetNoteDelete: 'BeforeSheetNoteDelete';
180
181
  /**
181
182
  * Event fired before a note is updated
182
183
  * @see {@link ISheetNoteUpdateEventParams}
@@ -193,7 +194,7 @@ interface ISheetNoteEvent {
193
194
  * // Remove the event listener, use `disposable.dispose()`
194
195
  * ```
195
196
  */
196
- BeforeSheetNoteUpdate: 'BeforeSheetNoteUpdate';
197
+ readonly BeforeSheetNoteUpdate: 'BeforeSheetNoteUpdate';
197
198
  /**
198
199
  * Event fired before a note is shown
199
200
  * @see {@link ISheetNoteShowEventParams}
@@ -210,7 +211,7 @@ interface ISheetNoteEvent {
210
211
  * // Remove the event listener, use `disposable.dispose()`
211
212
  * ```
212
213
  */
213
- BeforeSheetNoteShow: 'BeforeSheetNoteShow';
214
+ readonly BeforeSheetNoteShow: 'BeforeSheetNoteShow';
214
215
  /**
215
216
  * Event fired before a note is hidden
216
217
  * @see {@link ISheetNoteHideEventParams}
@@ -227,12 +228,12 @@ interface ISheetNoteEvent {
227
228
  * // Remove the event listener, use `disposable.dispose()`
228
229
  * ```
229
230
  */
230
- BeforeSheetNoteHide: 'BeforeSheetNoteHide';
231
+ readonly BeforeSheetNoteHide: 'BeforeSheetNoteHide';
231
232
  }
232
233
  /**
233
234
  * @ignore
234
235
  */
235
- export declare class FSheetNoteEvent implements ISheetNoteEvent {
236
+ export declare class FSheetsNoteEventNameMixin extends FEventName implements IFSheetsNoteEventNameMixin {
236
237
  get SheetNoteAdd(): 'SheetNoteAdd';
237
238
  get SheetNoteDelete(): 'SheetNoteDelete';
238
239
  get SheetNoteUpdate(): 'SheetNoteUpdate';
@@ -247,7 +248,7 @@ export declare class FSheetNoteEvent implements ISheetNoteEvent {
247
248
  /**
248
249
  * @ignore
249
250
  */
250
- export interface ISheetNoteEventConfig {
251
+ export interface ISheetsNoteEventParamConfig {
251
252
  SheetNoteAdd: ISheetNoteAddEventParams;
252
253
  SheetNoteDelete: ISheetNoteDeleteEventParams;
253
254
  SheetNoteUpdate: ISheetNoteUpdateEventParams;
@@ -260,9 +261,9 @@ export interface ISheetNoteEventConfig {
260
261
  BeforeSheetNoteHide: ISheetNoteHideEventParams;
261
262
  }
262
263
  declare module '@univerjs/core/facade' {
263
- interface FEventName extends ISheetNoteEvent {
264
+ interface FEventName extends IFSheetsNoteEventNameMixin {
264
265
  }
265
- interface IEventParamConfig extends ISheetNoteEventConfig {
266
+ interface IEventParamConfig extends ISheetsNoteEventParamConfig {
266
267
  }
267
268
  }
268
269
  export {};
@@ -19,7 +19,7 @@ import { FRange } from '@univerjs/sheets/facade';
19
19
  /**
20
20
  * @ignore
21
21
  */
22
- export interface IFSheetsNoteRange {
22
+ export interface IFRangeSheetsNoteMixin {
23
23
  /**
24
24
  * Get the annotation of the top-left cell in the range
25
25
  * @returns {Nullable<ISheetNote>} The annotation of the top-left cell in the range
@@ -70,12 +70,12 @@ export interface IFSheetsNoteRange {
70
70
  */
71
71
  deleteNote(): FRange;
72
72
  }
73
- export declare class FSheetsNoteRangeMixin extends FRange implements IFSheetsNoteRange {
73
+ export declare class FRangeSheetsNoteMixin extends FRange implements IFRangeSheetsNoteMixin {
74
74
  createOrUpdateNote(note: ISheetNote): FRange;
75
75
  deleteNote(): FRange;
76
76
  getNote(): Nullable<ISheetNote>;
77
77
  }
78
78
  declare module '@univerjs/sheets/facade' {
79
- interface FRange extends IFSheetsNoteRange {
79
+ interface FRange extends IFRangeSheetsNoteMixin {
80
80
  }
81
81
  }
@@ -15,15 +15,6 @@
15
15
  */
16
16
  import type { Injector } from '@univerjs/core';
17
17
  import { FUniver } from '@univerjs/core/facade';
18
- /**
19
- * @ignore
20
- */
21
- export interface IFUniverSheetNoteMixin {
22
- }
23
- export declare class FUniverSheetNoteMixin extends FUniver implements IFUniverSheetNoteMixin {
18
+ export declare class FUniverSheetsNoteMixin extends FUniver {
24
19
  _initialize(injector: Injector): void;
25
20
  }
26
- declare module '@univerjs/core/facade' {
27
- interface FUniver extends IFUniverSheetNoteMixin {
28
- }
29
- }
@@ -18,7 +18,7 @@ import { FWorksheet } from '@univerjs/sheets/facade';
18
18
  /**
19
19
  * @ignore
20
20
  */
21
- export interface IFSheetsNoteWorksheet {
21
+ export interface IFWorksheetNoteMixin {
22
22
  /**
23
23
  * Get all annotations in the worksheet
24
24
  * @returns {ISheetNote[]} An array of all annotations in the worksheet
@@ -37,10 +37,10 @@ export interface IFSheetsNoteWorksheet {
37
37
  */
38
38
  getNotes(): ISheetNote[];
39
39
  }
40
- export declare class FSheetsNoteWorksheet extends FWorksheet implements IFSheetsNoteWorksheet {
40
+ export declare class FWorksheetNoteMixin extends FWorksheet implements IFWorksheetNoteMixin {
41
41
  getNotes(): ISheetNote[];
42
42
  }
43
43
  declare module '@univerjs/sheets/facade' {
44
- interface FWorksheet extends IFSheetsNoteWorksheet {
44
+ interface FWorksheet extends IFWorksheetNoteMixin {
45
45
  }
46
46
  }
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core/facade`),require(`@univerjs/sheets-note`),require(`@univerjs/sheets/facade`),require(`@univerjs/core`),require(`@univerjs/sheets`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core/facade`,`@univerjs/sheets-note`,`@univerjs/sheets/facade`,`@univerjs/core`,`@univerjs/sheets`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNoteFacade={},e.UniverCoreFacade,e.UniverSheetsNote,e.UniverSheetsFacade,e.UniverCore,e.UniverSheets))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=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`}};t.FEventName.extend(o);var s=class extends r.FRange{createOrUpdateNote(e){return this._commandService.syncExecuteCommand(n.UpdateNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:e}),this}deleteNote(){return this._commandService.syncExecuteCommand(n.RemoveNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(n.SheetsNoteModel).getNote(this.getUnitId(),this.getSheetId(),{row:this.getRow(),col:this.getColumn()})}};r.FRange.extend(s);var c=class extends t.FUniver{_initialize(e){let t=e.get(i.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteAdd,()=>e.get(n.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(n.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(n.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(n.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(n.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,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetUpdateNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s,note:c}=t.params,l=this.getSheetTarget(r,a);if(!l||e.get(n.SheetsNoteModel).getNote(r,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 i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetDeleteNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s}=t.params,c=this.getSheetTarget(r,a);if(!c||o===void 0||s===void 0)return;let l=e.get(n.SheetsNoteModel).getNote(r,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 i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetUpdateNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s,note:c}=t.params,l=this.getSheetTarget(r,a);if(!l)return;let u=e.get(n.SheetsNoteModel).getNote(r,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 i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetToggleNotePopupCommand.id){let t=(0,a.getSheetCommandTarget)(e.get(i.IUniverInstanceService));if(!t)return;let{unitId:r,subUnitId:o}=t,s=this.getUniverSheet(r);if(!s)return;let c=s.getSheetBySheetId(o);if(!c)return;let l=e.get(a.SheetsSelectionsService).getCurrentLastSelection();if(!(l!=null&&l.primary))return;let u=e.get(n.SheetsNoteModel),{actualColumn:d,actualRow:f}=l.primary,p=u.getNote(r,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 i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetToggleNotePopupCommand.id){let t=(0,a.getSheetCommandTarget)(e.get(i.IUniverInstanceService));if(!t)return;let{unitId:r,subUnitId:o}=t,s=this.getUniverSheet(r);if(!s)return;let c=s.getSheetBySheetId(o);if(!c)return;let l=e.get(a.SheetsSelectionsService).getCurrentLastSelection();if(!(l!=null&&l.primary))return;let u=e.get(n.SheetsNoteModel),{actualColumn:d,actualRow:f}=l.primary,p=u.getNote(r,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 i.CanceledError}})))}};t.FUniver.extend(c);var l=class extends r.FWorksheet{getNotes(){let e=this._injector.get(n.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId());return e?Array.from(e.values()).map(e=>({...e})):[]}};r.FWorksheet.extend(l),e.FSheetNoteEvent=o,e.FSheetsNoteRangeMixin=s,e.FSheetsNoteWorksheet=l,e.FUniverSheetNoteMixin=c});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core/facade`),require(`@univerjs/sheets-note`),require(`@univerjs/sheets/facade`),require(`@univerjs/core`),require(`@univerjs/sheets`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core/facade`,`@univerjs/sheets-note`,`@univerjs/sheets/facade`,`@univerjs/core`,`@univerjs/sheets`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNoteFacade={},e.UniverCoreFacade,e.UniverSheetsNote,e.UniverSheetsFacade,e.UniverCore,e.UniverSheets))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=class extends t.FEventName{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`}};t.FEventName.extend(o);var s=class extends r.FRange{createOrUpdateNote(e){return this._commandService.syncExecuteCommand(n.UpdateNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:e}),this}deleteNote(){return this._commandService.syncExecuteCommand(n.RemoveNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(n.SheetsNoteModel).getNote(this.getUnitId(),this.getSheetId(),{row:this.getRow(),col:this.getColumn()})}};r.FRange.extend(s);var c=class extends t.FUniver{_initialize(e){let t=e.get(i.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteAdd,()=>e.get(n.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,s={workbook:a,worksheet:o,row:r.row,col:r.col,note:r};this.fireEvent(this.Event.SheetNoteAdd,s)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteDelete,()=>e.get(n.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,s={workbook:a,worksheet:o,row:r.row,col:r.col,oldNote:r};this.fireEvent(this.Event.SheetNoteDelete,s)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteUpdate,()=>e.get(n.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,c={workbook:o,worksheet:s,row:i.row,col:i.col,note:i,oldNote:r};this.fireEvent(this.Event.SheetNoteUpdate,c)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteShow,()=>e.get(n.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,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteShow,s)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteHide,()=>e.get(n.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,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteHide,s)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteAdd,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetUpdateNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s,note:c}=t.params,l=this.getSheetTarget(r,a);if(!l||e.get(n.SheetsNoteModel).getNote(r,a,{noteId:c.id,row:o,col:s}))return;let{workbook:u,worksheet:d}=l,f={workbook:u,worksheet:d,row:o,col:s,note:c};if(this.fireEvent(this.Event.BeforeSheetNoteAdd,f))throw new i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetDeleteNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s}=t.params,c=this.getSheetTarget(r,a);if(!c||o===void 0||s===void 0)return;let l=e.get(n.SheetsNoteModel).getNote(r,a,{row:o,col:s});if(!l)return;let{workbook:u,worksheet:d}=c,f={workbook:u,worksheet:d,row:o,col:s,oldNote:l};if(this.fireEvent(this.Event.BeforeSheetNoteDelete,f))throw new i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetUpdateNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s,note:c}=t.params,l=this.getSheetTarget(r,a);if(!l)return;let u=e.get(n.SheetsNoteModel).getNote(r,a,{row:o,col:s});if(!u)return;let{workbook:d,worksheet:f}=l,p={workbook:d,worksheet:f,row:o,col:s,note:c,oldNote:u};if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,p))throw new i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetToggleNotePopupCommand.id){let t=(0,a.getSheetCommandTarget)(e.get(i.IUniverInstanceService));if(!t)return;let{unitId:r,subUnitId:o}=t,s=this.getUniverSheet(r);if(!s)return;let c=s.getSheetBySheetId(o);if(!c)return;let l=e.get(a.SheetsSelectionsService).getCurrentLastSelection();if(!(l!=null&&l.primary))return;let u=e.get(n.SheetsNoteModel),{actualColumn:d,actualRow:f}=l.primary,p=u.getNote(r,o,{row:f,col:d});if(!p||p.show)return;let m={workbook:s,worksheet:c,row:f,col:d};if(this.fireEvent(this.Event.BeforeSheetNoteShow,m))throw new i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetToggleNotePopupCommand.id){let t=(0,a.getSheetCommandTarget)(e.get(i.IUniverInstanceService));if(!t)return;let{unitId:r,subUnitId:o}=t,s=this.getUniverSheet(r);if(!s)return;let c=s.getSheetBySheetId(o);if(!c)return;let l=e.get(a.SheetsSelectionsService).getCurrentLastSelection();if(!(l!=null&&l.primary))return;let u=e.get(n.SheetsNoteModel),{actualColumn:d,actualRow:f}=l.primary,p=u.getNote(r,o,{row:f,col:d});if(!p||!p.show)return;let m={workbook:s,worksheet:c,row:f,col:d};if(this.fireEvent(this.Event.BeforeSheetNoteHide,m))throw new i.CanceledError}})))}};t.FUniver.extend(c);var l=class extends r.FWorksheet{getNotes(){let e=this._injector.get(n.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId());return e?Array.from(e.values()).map(e=>({...e})):[]}};r.FWorksheet.extend(l),e.FRangeSheetsNoteMixin=s,e.FSheetsNoteEventNameMixin=o,e.FUniverSheetsNoteMixin=c,e.FWorksheetNoteMixin=l});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNote={},e.UniverCore,e.UniverSheets,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e){"@babel/helpers - typeof";return i=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},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=class extends t.Disposable{constructor(...e){super(...e),s(this,`_notesMap`,new Map),s(this,`_change$`,new r.Subject),s(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,r.filter)(({unitId:n,subUnitId:r})=>n===e&&r===t),(0,r.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,n,i){return this._change$.pipe((0,r.filter)(({unitId:r,subUnitId:a,oldNote:o})=>r!==e||a!==t||!o?!1:o.row===n&&o.col===i),(0,r.map)(e=>e))}updateNote(e,n,r,i,a,o){let s=this._getNoteByParams(e,n,{noteId:a==null?void 0:a.id,row:r,col:i}),c=this._ensureNotesMap(e,n),l={...a,id:(s==null?void 0:s.id)||a.id||(0,t.generateRandomId)(6),row:r,col:i};c.set(l.id,l),this._change$.next({unitId:e,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)}};let l={id:`sheet.mutation.update-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(c).updateNote(n,r,i,a,o,s),!0}},u={id:`sheet.mutation.remove-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},d={id:`sheet.mutation.toggle-note-popup`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},f={id:`sheet.mutation.update-note-position`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:l}=t;return e.get(c).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:l}),!0}},p={id:`sheet.command.delete-note`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:d,actualRow:f}=i.primary,p=a.getNote(o,s,{row:f,col:d});if(!p)return!1;let m=e.get(t.ICommandService),h=e.get(t.IUndoRedoService),g={id:u.id,params:{unitId:o,sheetId:s,noteId:p.id}},_={id:l.id,params:{unitId:o,sheetId:s,row:f,col:d,note:{...p}}};return m.syncExecuteCommand(g.id,g.params)?(h.pushUndoRedo({unitID:o,redoMutations:[g],undoMutations:[_]}),!0):!1}},m={id:`sheet.command.toggle-note-popup`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:l,actualRow:u}=i.primary,f=a.getNote(o,s,{row:u,col:l});if(!f)return!1;let p=e.get(t.ICommandService),m=e.get(t.IUndoRedoService),h={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}},g={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}};return p.syncExecuteCommand(h.id,h.params)?(m.pushUndoRedo({unitID:o,redoMutations:[h],undoMutations:[g]}),!0):!1}},h={id:`sheet.command.update-note`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(c),{unitId:d,subUnitId:f}=i,{row:p,col:m,note:h}=r,g=s.getNote(d,f,{noteId:h.id,row:p,col:m}),_={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:h}},v=[];if(g){let e={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:{...g}}};v.push(e)}else{let e={id:u.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}},g=`SHEET_NOTE_PLUGIN`;function _(e,t){return function(n,r){t(n,r,e)}}function v(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 y=class extends t.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 e=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:g,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),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:e=>{if(e.id===n.RemoveSheetCommand.id){var r;let n=e.params,i=n.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=n.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(t.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=[],c=[];return o.forEach(e=>{s.push({id:u.id,params:{unitId:i,sheetId:a,noteId:e.id,row:e.row,col:e.col}}),c.push({id:l.id,params:{unitId:i,sheetId:a,row:e.row,col:e.col,note:e}})}),{redos:s,undos:c}}else if(e.id===n.CopySheetCommand.id){let{unitId:n,subUnitId:r,targetSubUnitId:i}=e.params;if(!n||!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(n,r);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{let r={...e,id:(0,t.generateRandomId)(6)};o.push({id:l.id,params:{unitId:n,sheetId:i,row:r.row,col:r.col,note:r}}),s.push({id:u.id,params:{unitId:n,sheetId:i,noteId:r.id,row:r.row,col:r.col}})}),{redos:o,undos:s}}return{redos:[],undos:[]}}}))}};y=v([_(0,t.IResourceManagerService),_(1,t.IUniverInstanceService),_(2,(0,t.Inject)(n.SheetInterceptorService)),_(3,(0,t.Inject)(c))],y);var b=`@univerjs/sheets-note`,x=`0.18.0`;let S=`sheets-note.config`;Symbol(S);let C={},w=class extends t.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,s(this,`_disposableMap`,new Map),s(this,`_watcherMap`,new Map),s(this,`_handleRangeChange`,(e,t,n,r,i,a,o)=>a?{redos:[{id:f.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:a.startRow,col:a.startColumn},silent:o}}],undos:[{id:f.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:r,col:i},note:n,silent:o}}]}:{redos:[{id:u.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:l.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,t,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._disposableMap.set(this._getIdWithUnitId(e,t,i,a),this._refRangeService.registerRefRange(o,s=>{let c=(0,n.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,t,r,i,a,l,!1)},e,t))}_watch(e,n,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._watcherMap.set(this._getIdWithUnitId(e,n,i,a),this._refRangeService.watchRange(e,n,o,(i,a)=>{let{redos:o}=this._handleRangeChange(e,n,r,i.startRow,i.startColumn,a,!0);(0,t.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}}}))}};w=v([_(0,(0,t.Inject)(n.RefRangeService)),_(1,(0,t.Inject)(c)),_(2,(0,t.Inject)(n.SheetsSelectionsService)),_(3,t.ICommandService)],w);let T=class extends t.Disposable{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[f,d,l,u,p,m,h].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};T=v([_(0,t.ICommandService)],T);let E=class extends t.Plugin{constructor(e=C,n,r){super(),this._config=e,this._configService=n,this._injector=r;let{...i}=(0,t.merge)({},C,this._config);this._configService.setConfig(S,i)}onStarting(){[[c],[T],[y],[w]].forEach(e=>{this._injector.add(e)}),(0,t.touchDependencies)(this._injector,[[c],[T],[y]])}onReady(){(0,t.touchDependencies)(this._injector,[[w]])}};s(E,`pluginName`,g),s(E,`packageName`,b),s(E,`version`,x),s(E,`type`,t.UniverInstanceType.UNIVER_SHEET),E=v([(0,t.DependentOn)(n.UniverSheetsPlugin),_(1,t.IConfigService),_(2,(0,t.Inject)(t.Injector))],E),e.RemoveNoteMutation=u,e.SheetDeleteNoteCommand=p,e.SheetToggleNotePopupCommand=m,e.SheetUpdateNoteCommand=h,e.SheetsNoteModel=c,Object.defineProperty(e,`SheetsNoteResourceController`,{enumerable:!0,get:function(){return y}}),e.ToggleNotePopupMutation=d,Object.defineProperty(e,`UniverSheetsNotePlugin`,{enumerable:!0,get:function(){return E}}),e.UpdateNoteMutation=l,e.UpdateNotePositionMutation=f});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNote={},e.UniverCore,e.UniverSheets,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e){"@babel/helpers - typeof";return i=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},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=class extends t.Disposable{constructor(...e){super(...e),s(this,`_notesMap`,new Map),s(this,`_change$`,new r.Subject),s(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,r.filter)(({unitId:n,subUnitId:r})=>n===e&&r===t),(0,r.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,n,i){return this._change$.pipe((0,r.filter)(({unitId:r,subUnitId:a,oldNote:o})=>r!==e||a!==t||!o?!1:o.row===n&&o.col===i),(0,r.map)(e=>e))}updateNote(e,n,r,i,a,o){let s=this._getNoteByParams(e,n,{noteId:a==null?void 0:a.id,row:r,col:i}),c=this._ensureNotesMap(e,n),l={...a,id:(s==null?void 0:s.id)||a.id||(0,t.generateRandomId)(6),row:r,col:i};c.set(l.id,l),this._change$.next({unitId:e,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)}};let l={id:`sheet.mutation.update-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(c).updateNote(n,r,i,a,o,s),!0}},u={id:`sheet.mutation.remove-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},d={id:`sheet.mutation.toggle-note-popup`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},f={id:`sheet.mutation.update-note-position`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:l}=t;return e.get(c).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:l}),!0}},p={id:`sheet.command.delete-note`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:d,actualRow:f}=i.primary,p=a.getNote(o,s,{row:f,col:d});if(!p)return!1;let m=e.get(t.ICommandService),h=e.get(t.IUndoRedoService),g={id:u.id,params:{unitId:o,sheetId:s,noteId:p.id}},_={id:l.id,params:{unitId:o,sheetId:s,row:f,col:d,note:{...p}}};return m.syncExecuteCommand(g.id,g.params)?(h.pushUndoRedo({unitID:o,redoMutations:[g],undoMutations:[_]}),!0):!1}},m={id:`sheet.command.toggle-note-popup`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:l,actualRow:u}=i.primary,f=a.getNote(o,s,{row:u,col:l});if(!f)return!1;let p=e.get(t.ICommandService),m=e.get(t.IUndoRedoService),h={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}},g={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}};return p.syncExecuteCommand(h.id,h.params)?(m.pushUndoRedo({unitID:o,redoMutations:[h],undoMutations:[g]}),!0):!1}},h={id:`sheet.command.update-note`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(c),{unitId:d,subUnitId:f}=i,{row:p,col:m,note:h}=r,g=s.getNote(d,f,{noteId:h.id,row:p,col:m}),_={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:h}},v=[];if(g){let e={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:{...g}}};v.push(e)}else{let e={id:u.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}},g=`SHEET_NOTE_PLUGIN`;function _(e,t){return function(n,r){t(n,r,e)}}function v(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 y=class extends t.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 e=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:g,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),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:e=>{if(e.id===n.RemoveSheetCommand.id){var r;let n=e.params,i=n.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=n.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(t.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=[],c=[];return o.forEach(e=>{s.push({id:u.id,params:{unitId:i,sheetId:a,noteId:e.id,row:e.row,col:e.col}}),c.push({id:l.id,params:{unitId:i,sheetId:a,row:e.row,col:e.col,note:e}})}),{redos:s,undos:c}}else if(e.id===n.CopySheetCommand.id){let{unitId:n,subUnitId:r,targetSubUnitId:i}=e.params;if(!n||!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(n,r);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{let r={...e,id:(0,t.generateRandomId)(6)};o.push({id:l.id,params:{unitId:n,sheetId:i,row:r.row,col:r.col,note:r}}),s.push({id:u.id,params:{unitId:n,sheetId:i,noteId:r.id,row:r.row,col:r.col}})}),{redos:o,undos:s}}return{redos:[],undos:[]}}}))}};y=v([_(0,t.IResourceManagerService),_(1,t.IUniverInstanceService),_(2,(0,t.Inject)(n.SheetInterceptorService)),_(3,(0,t.Inject)(c))],y);var b=`@univerjs/sheets-note`,x=`0.19.0-insiders.20260403-3e0e122`;let S=`sheets-note.config`;Symbol(S);let C={},w=class extends t.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,s(this,`_disposableMap`,new Map),s(this,`_watcherMap`,new Map),s(this,`_handleRangeChange`,(e,t,n,r,i,a,o)=>a?{redos:[{id:f.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:a.startRow,col:a.startColumn},silent:o}}],undos:[{id:f.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:r,col:i},note:n,silent:o}}]}:{redos:[{id:u.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:l.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,t,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._disposableMap.set(this._getIdWithUnitId(e,t,i,a),this._refRangeService.registerRefRange(o,s=>{let c=(0,n.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,t,r,i,a,l,!1)},e,t))}_watch(e,n,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._watcherMap.set(this._getIdWithUnitId(e,n,i,a),this._refRangeService.watchRange(e,n,o,(i,a)=>{let{redos:o}=this._handleRangeChange(e,n,r,i.startRow,i.startColumn,a,!0);(0,t.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}}}))}};w=v([_(0,(0,t.Inject)(n.RefRangeService)),_(1,(0,t.Inject)(c)),_(2,(0,t.Inject)(n.SheetsSelectionsService)),_(3,t.ICommandService)],w);let T=class extends t.Disposable{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[f,d,l,u,p,m,h].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};T=v([_(0,t.ICommandService)],T);let E=class extends t.Plugin{constructor(e=C,n,r){super(),this._config=e,this._configService=n,this._injector=r;let{...i}=(0,t.merge)({},C,this._config);this._configService.setConfig(S,i)}onStarting(){[[c],[T],[y],[w]].forEach(e=>{this._injector.add(e)}),(0,t.touchDependencies)(this._injector,[[c],[T],[y]])}onReady(){(0,t.touchDependencies)(this._injector,[[w]])}};s(E,`pluginName`,g),s(E,`packageName`,b),s(E,`version`,x),s(E,`type`,t.UniverInstanceType.UNIVER_SHEET),E=v([(0,t.DependentOn)(n.UniverSheetsPlugin),_(1,t.IConfigService),_(2,(0,t.Inject)(t.Injector))],E),e.RemoveNoteMutation=u,e.SheetDeleteNoteCommand=p,e.SheetToggleNotePopupCommand=m,e.SheetUpdateNoteCommand=h,e.SheetsNoteModel=c,Object.defineProperty(e,`SheetsNoteResourceController`,{enumerable:!0,get:function(){return y}}),e.ToggleNotePopupMutation=d,Object.defineProperty(e,`UniverSheetsNotePlugin`,{enumerable:!0,get:function(){return E}}),e.UpdateNoteMutation=l,e.UpdateNotePositionMutation=f});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-note",
3
- "version": "0.18.0",
3
+ "version": "0.19.0-insiders.20260403-3e0e122",
4
4
  "private": false,
5
5
  "description": "Univer sheets note base plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,17 +56,17 @@
56
56
  "rxjs": ">=7.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@univerjs/core": "0.18.0",
60
- "@univerjs/sheets": "0.18.0"
59
+ "@univerjs/core": "0.19.0-insiders.20260403-3e0e122",
60
+ "@univerjs/sheets": "0.19.0-insiders.20260403-3e0e122"
61
61
  },
62
62
  "devDependencies": {
63
63
  "rxjs": "^7.8.2",
64
- "typescript": "^5.9.3",
65
- "vitest": "^4.1.0",
66
- "@univerjs-infra/shared": "0.18.0",
67
- "@univerjs/engine-formula": "0.18.0",
68
- "@univerjs/engine-render": "0.18.0",
69
- "@univerjs/network": "0.18.0"
64
+ "typescript": "^6.0.2",
65
+ "vitest": "^4.1.1",
66
+ "@univerjs-infra/shared": "0.19.0",
67
+ "@univerjs/engine-render": "0.19.0-insiders.20260403-3e0e122",
68
+ "@univerjs/engine-formula": "0.19.0-insiders.20260403-3e0e122",
69
+ "@univerjs/network": "0.19.0-insiders.20260403-3e0e122"
70
70
  },
71
71
  "scripts": {
72
72
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS