@univerjs/sheets-note 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1,900 @@
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.20.1`;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' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_sheets = require("@univerjs/sheets");
4
+ let rxjs = require("rxjs");
5
+
6
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
7
+ function _typeof(o) {
8
+ "@babel/helpers - typeof";
9
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
10
+ return typeof o;
11
+ } : function(o) {
12
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
13
+ }, _typeof(o);
14
+ }
15
+
16
+ //#endregion
17
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
18
+ function toPrimitive(t, r) {
19
+ if ("object" != _typeof(t) || !t) return t;
20
+ var e = t[Symbol.toPrimitive];
21
+ if (void 0 !== e) {
22
+ var i = e.call(t, r || "default");
23
+ if ("object" != _typeof(i)) return i;
24
+ throw new TypeError("@@toPrimitive must return a primitive value.");
25
+ }
26
+ return ("string" === r ? String : Number)(t);
27
+ }
28
+
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
31
+ function toPropertyKey(t) {
32
+ var i = toPrimitive(t, "string");
33
+ return "symbol" == _typeof(i) ? i : i + "";
34
+ }
35
+
36
+ //#endregion
37
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
38
+ function _defineProperty(e, r, t) {
39
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
40
+ value: t,
41
+ enumerable: !0,
42
+ configurable: !0,
43
+ writable: !0
44
+ }) : e[r] = t, e;
45
+ }
46
+
47
+ //#endregion
48
+ //#region src/models/sheets-note.model.ts
49
+ var SheetsNoteModel = class extends _univerjs_core.Disposable {
50
+ constructor(..._args) {
51
+ super(..._args);
52
+ _defineProperty(this, "_notesMap", /* @__PURE__ */ new Map());
53
+ _defineProperty(this, "_change$", new rxjs.Subject());
54
+ _defineProperty(this, "change$", this._change$.asObservable());
55
+ }
56
+ _ensureNotesMap(unitId, subUnitId) {
57
+ let unitMap = this._notesMap.get(unitId);
58
+ if (!unitMap) {
59
+ unitMap = /* @__PURE__ */ new Map();
60
+ this._notesMap.set(unitId, unitMap);
61
+ }
62
+ let subUnitMap = unitMap.get(subUnitId);
63
+ if (!subUnitMap) {
64
+ subUnitMap = /* @__PURE__ */ new Map();
65
+ unitMap.set(subUnitId, subUnitMap);
66
+ }
67
+ return subUnitMap;
68
+ }
69
+ _getNoteByPosition(unitId, subUnitId, row, col) {
70
+ const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
71
+ for (const [_, note] of subUnitMap) if (note.row === row && note.col === col) return note;
72
+ }
73
+ _getNoteById(unitId, subUnitId, id) {
74
+ return this._ensureNotesMap(unitId, subUnitId).get(id);
75
+ }
76
+ _getNoteByParams(unitId, subUnitId, params) {
77
+ const { noteId, row, col } = params;
78
+ if (noteId) return this._getNoteById(unitId, subUnitId, noteId);
79
+ if (row !== void 0 && col !== void 0) return this._getNoteByPosition(unitId, subUnitId, row, col);
80
+ return null;
81
+ }
82
+ getSheetShowNotes$(unitId, subUnitId) {
83
+ return this._change$.pipe((0, rxjs.filter)(({ unitId: u, subUnitId: s }) => u === unitId && s === subUnitId), (0, rxjs.map)(() => {
84
+ const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
85
+ const notes = [];
86
+ for (const [_, note] of subUnitMap) if (note.show) notes.push({
87
+ loc: {
88
+ row: note.row,
89
+ col: note.col,
90
+ unitId,
91
+ subUnitId
92
+ },
93
+ note
94
+ });
95
+ return notes;
96
+ }));
97
+ }
98
+ getCellNoteChange$(unitId, subUnitId, row, col) {
99
+ return this._change$.pipe((0, rxjs.filter)(({ unitId: u, subUnitId: s, oldNote }) => {
100
+ if (u !== unitId || s !== subUnitId || !oldNote) return false;
101
+ return oldNote.row === row && oldNote.col === col;
102
+ }), (0, rxjs.map)((newNote) => newNote));
103
+ }
104
+ updateNote(unitId, subUnitId, row, col, note, silent) {
105
+ const oldNote = this._getNoteByParams(unitId, subUnitId, {
106
+ noteId: note === null || note === void 0 ? void 0 : note.id,
107
+ row,
108
+ col
109
+ });
110
+ const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
111
+ const newNote = {
112
+ ...note,
113
+ id: (oldNote === null || oldNote === void 0 ? void 0 : oldNote.id) || note.id || (0, _univerjs_core.generateRandomId)(6),
114
+ row,
115
+ col
116
+ };
117
+ subUnitMap.set(newNote.id, newNote);
118
+ this._change$.next({
119
+ unitId,
120
+ subUnitId,
121
+ oldNote,
122
+ type: "update",
123
+ newNote,
124
+ silent
125
+ });
126
+ }
127
+ removeNote(unitId, subUnitId, params) {
128
+ const { noteId, row, col, silent } = params;
129
+ const oldNote = this._getNoteByParams(unitId, subUnitId, {
130
+ noteId,
131
+ row,
132
+ col
133
+ });
134
+ if (!oldNote) return;
135
+ this._ensureNotesMap(unitId, subUnitId).delete(oldNote.id);
136
+ this._change$.next({
137
+ unitId,
138
+ subUnitId,
139
+ oldNote,
140
+ type: "update",
141
+ newNote: null,
142
+ silent
143
+ });
144
+ }
145
+ toggleNotePopup(unitId, subUnitId, params) {
146
+ const { noteId, row, col, silent } = params;
147
+ const oldNote = this._getNoteByParams(unitId, subUnitId, {
148
+ noteId,
149
+ row,
150
+ col
151
+ });
152
+ if (!oldNote) return;
153
+ const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
154
+ const newNote = {
155
+ ...oldNote,
156
+ show: !oldNote.show
157
+ };
158
+ subUnitMap.set(newNote.id, newNote);
159
+ this._change$.next({
160
+ unitId,
161
+ subUnitId,
162
+ oldNote,
163
+ type: "update",
164
+ newNote,
165
+ silent
166
+ });
167
+ }
168
+ updateNotePosition(unitId, subUnitId, params) {
169
+ const { noteId, row, col, newRow, newCol, silent } = params;
170
+ const oldNote = this._getNoteByParams(unitId, subUnitId, {
171
+ noteId,
172
+ row,
173
+ col
174
+ });
175
+ if (!oldNote) return;
176
+ const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
177
+ const newNote = {
178
+ ...oldNote,
179
+ row: newRow,
180
+ col: newCol
181
+ };
182
+ subUnitMap.set(newNote.id, newNote);
183
+ this._change$.next({
184
+ unitId,
185
+ subUnitId,
186
+ oldNote,
187
+ type: "ref",
188
+ newNote,
189
+ silent
190
+ });
191
+ }
192
+ getNote(unitId, subUnitId, params) {
193
+ return this._getNoteByParams(unitId, subUnitId, params);
194
+ }
195
+ getNotes() {
196
+ return this._notesMap;
197
+ }
198
+ getUnitNotes(unitId) {
199
+ return this._notesMap.get(unitId);
200
+ }
201
+ getSheetNotes(unitId, subUnitId) {
202
+ const unitMap = this._notesMap.get(unitId);
203
+ if (!unitMap) return;
204
+ return unitMap.get(subUnitId);
205
+ }
206
+ deleteUnitNotes(unitId) {
207
+ this._notesMap.delete(unitId);
208
+ }
209
+ };
210
+
211
+ //#endregion
212
+ //#region src/commands/mutations/note.mutation.ts
213
+ const UpdateNoteMutation = {
214
+ id: "sheet.mutation.update-note",
215
+ type: _univerjs_core.CommandType.MUTATION,
216
+ handler: (accessor, params) => {
217
+ const { unitId, sheetId, row, col, note, silent } = params;
218
+ accessor.get(SheetsNoteModel).updateNote(unitId, sheetId, row, col, note, silent);
219
+ return true;
220
+ }
221
+ };
222
+ const RemoveNoteMutation = {
223
+ id: "sheet.mutation.remove-note",
224
+ type: _univerjs_core.CommandType.MUTATION,
225
+ handler: (accessor, params) => {
226
+ const { unitId, sheetId, noteId, row, col, silent } = params;
227
+ accessor.get(SheetsNoteModel).removeNote(unitId, sheetId, {
228
+ noteId,
229
+ row,
230
+ col,
231
+ silent
232
+ });
233
+ return true;
234
+ }
235
+ };
236
+ const ToggleNotePopupMutation = {
237
+ id: "sheet.mutation.toggle-note-popup",
238
+ type: _univerjs_core.CommandType.MUTATION,
239
+ handler: (accessor, params) => {
240
+ const { unitId, sheetId, noteId, row, col, silent } = params;
241
+ accessor.get(SheetsNoteModel).toggleNotePopup(unitId, sheetId, {
242
+ noteId,
243
+ row,
244
+ col,
245
+ silent
246
+ });
247
+ return true;
248
+ }
249
+ };
250
+ const UpdateNotePositionMutation = {
251
+ id: "sheet.mutation.update-note-position",
252
+ type: _univerjs_core.CommandType.MUTATION,
253
+ handler: (accessor, params) => {
254
+ const { unitId, sheetId, noteId, row, col, newPosition, silent } = params;
255
+ accessor.get(SheetsNoteModel).updateNotePosition(unitId, sheetId, {
256
+ noteId,
257
+ row,
258
+ col,
259
+ newRow: newPosition.row,
260
+ newCol: newPosition.col,
261
+ silent
262
+ });
263
+ return true;
264
+ }
265
+ };
266
+
267
+ //#endregion
268
+ //#region src/commands/commands/note.command.ts
269
+ const SheetDeleteNoteCommand = {
270
+ id: "sheet.command.delete-note",
271
+ type: _univerjs_core.CommandType.COMMAND,
272
+ handler: (accessor) => {
273
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService));
274
+ if (!target) return false;
275
+ const selection = accessor.get(_univerjs_sheets.SheetsSelectionsService).getCurrentLastSelection();
276
+ if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
277
+ const sheetsNoteModel = accessor.get(SheetsNoteModel);
278
+ const { unitId, subUnitId } = target;
279
+ const { actualColumn, actualRow } = selection.primary;
280
+ const note = sheetsNoteModel.getNote(unitId, subUnitId, {
281
+ row: actualRow,
282
+ col: actualColumn
283
+ });
284
+ if (!note) return false;
285
+ const commandService = accessor.get(_univerjs_core.ICommandService);
286
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
287
+ const redoMutation = {
288
+ id: RemoveNoteMutation.id,
289
+ params: {
290
+ unitId,
291
+ sheetId: subUnitId,
292
+ noteId: note.id
293
+ }
294
+ };
295
+ const undoMutation = {
296
+ id: UpdateNoteMutation.id,
297
+ params: {
298
+ unitId,
299
+ sheetId: subUnitId,
300
+ row: actualRow,
301
+ col: actualColumn,
302
+ note: { ...note }
303
+ }
304
+ };
305
+ if (commandService.syncExecuteCommand(redoMutation.id, redoMutation.params)) {
306
+ undoRedoService.pushUndoRedo({
307
+ unitID: unitId,
308
+ redoMutations: [redoMutation],
309
+ undoMutations: [undoMutation]
310
+ });
311
+ return true;
312
+ }
313
+ return false;
314
+ }
315
+ };
316
+ const SheetToggleNotePopupCommand = {
317
+ id: "sheet.command.toggle-note-popup",
318
+ type: _univerjs_core.CommandType.COMMAND,
319
+ handler: (accessor) => {
320
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService));
321
+ if (!target) return false;
322
+ const selection = accessor.get(_univerjs_sheets.SheetsSelectionsService).getCurrentLastSelection();
323
+ if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
324
+ const sheetsNoteModel = accessor.get(SheetsNoteModel);
325
+ const { unitId, subUnitId } = target;
326
+ const { actualColumn, actualRow } = selection.primary;
327
+ const note = sheetsNoteModel.getNote(unitId, subUnitId, {
328
+ row: actualRow,
329
+ col: actualColumn
330
+ });
331
+ if (!note) return false;
332
+ const commandService = accessor.get(_univerjs_core.ICommandService);
333
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
334
+ const redoMutation = {
335
+ id: ToggleNotePopupMutation.id,
336
+ params: {
337
+ unitId,
338
+ sheetId: subUnitId,
339
+ noteId: note.id
340
+ }
341
+ };
342
+ const undoMutation = {
343
+ id: ToggleNotePopupMutation.id,
344
+ params: {
345
+ unitId,
346
+ sheetId: subUnitId,
347
+ noteId: note.id
348
+ }
349
+ };
350
+ if (commandService.syncExecuteCommand(redoMutation.id, redoMutation.params)) {
351
+ undoRedoService.pushUndoRedo({
352
+ unitID: unitId,
353
+ redoMutations: [redoMutation],
354
+ undoMutations: [undoMutation]
355
+ });
356
+ return true;
357
+ }
358
+ return false;
359
+ }
360
+ };
361
+ const SheetUpdateNoteCommand = {
362
+ id: "sheet.command.update-note",
363
+ type: _univerjs_core.CommandType.COMMAND,
364
+ handler: (accessor, params) => {
365
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), params);
366
+ if (!target) return false;
367
+ const commandService = accessor.get(_univerjs_core.ICommandService);
368
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
369
+ const sheetsNoteModel = accessor.get(SheetsNoteModel);
370
+ const { unitId, subUnitId } = target;
371
+ const { row, col, note } = params;
372
+ const oldNote = sheetsNoteModel.getNote(unitId, subUnitId, {
373
+ noteId: note.id,
374
+ row,
375
+ col
376
+ });
377
+ const redoMutation = {
378
+ id: UpdateNoteMutation.id,
379
+ params: {
380
+ unitId,
381
+ sheetId: subUnitId,
382
+ row,
383
+ col,
384
+ note
385
+ }
386
+ };
387
+ const undoMutations = [];
388
+ if (oldNote) {
389
+ const undoMutation = {
390
+ id: UpdateNoteMutation.id,
391
+ params: {
392
+ unitId,
393
+ sheetId: subUnitId,
394
+ row,
395
+ col,
396
+ note: { ...oldNote }
397
+ }
398
+ };
399
+ undoMutations.push(undoMutation);
400
+ } else {
401
+ const undoMutation = {
402
+ id: RemoveNoteMutation.id,
403
+ params: {
404
+ unitId,
405
+ sheetId: subUnitId,
406
+ row,
407
+ col
408
+ }
409
+ };
410
+ undoMutations.push(undoMutation);
411
+ }
412
+ if (commandService.syncExecuteCommand(redoMutation.id, redoMutation.params)) {
413
+ undoRedoService.pushUndoRedo({
414
+ unitID: unitId,
415
+ redoMutations: [redoMutation],
416
+ undoMutations
417
+ });
418
+ return true;
419
+ }
420
+ return false;
421
+ }
422
+ };
423
+
424
+ //#endregion
425
+ //#region src/const.ts
426
+ /**
427
+ * Copyright 2023-present DreamNum Co., Ltd.
428
+ *
429
+ * Licensed under the Apache License, Version 2.0 (the "License");
430
+ * you may not use this file except in compliance with the License.
431
+ * You may obtain a copy of the License at
432
+ *
433
+ * http://www.apache.org/licenses/LICENSE-2.0
434
+ *
435
+ * Unless required by applicable law or agreed to in writing, software
436
+ * distributed under the License is distributed on an "AS IS" BASIS,
437
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
438
+ * See the License for the specific language governing permissions and
439
+ * limitations under the License.
440
+ */
441
+ const PLUGIN_NAME = "SHEET_NOTE_PLUGIN";
442
+
443
+ //#endregion
444
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
445
+ function __decorateParam(paramIndex, decorator) {
446
+ return function(target, key) {
447
+ decorator(target, key, paramIndex);
448
+ };
449
+ }
450
+
451
+ //#endregion
452
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
453
+ function __decorate(decorators, target, key, desc) {
454
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
455
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
456
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
457
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
458
+ }
459
+
460
+ //#endregion
461
+ //#region src/controllers/sheets-note-resource.controller.ts
462
+ let SheetsNoteResourceController = class SheetsNoteResourceController extends _univerjs_core.Disposable {
463
+ constructor(_resourceManagerService, _univerInstanceService, _sheetInterceptorService, _sheetsNoteModel) {
464
+ super();
465
+ this._resourceManagerService = _resourceManagerService;
466
+ this._univerInstanceService = _univerInstanceService;
467
+ this._sheetInterceptorService = _sheetInterceptorService;
468
+ this._sheetsNoteModel = _sheetsNoteModel;
469
+ this._initSnapshot();
470
+ this._initSheetChange();
471
+ }
472
+ _initSnapshot() {
473
+ const toJson = (unitId) => {
474
+ const unitMap = this._sheetsNoteModel.getUnitNotes(unitId);
475
+ if (!unitMap) return "";
476
+ const result = {};
477
+ unitMap.forEach((subUnitMap, subUnitId) => {
478
+ const sheetNotes = {};
479
+ subUnitMap.forEach((note) => {
480
+ const { row, col } = note;
481
+ if (!sheetNotes[row]) sheetNotes[row] = {};
482
+ sheetNotes[row][col] = note;
483
+ });
484
+ if (Object.keys(sheetNotes).length > 0) result[subUnitId] = sheetNotes;
485
+ });
486
+ return JSON.stringify(result);
487
+ };
488
+ const parseJson = (json) => {
489
+ if (!json) return {};
490
+ try {
491
+ return JSON.parse(json);
492
+ } catch {
493
+ return {};
494
+ }
495
+ };
496
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource({
497
+ pluginName: PLUGIN_NAME,
498
+ businesses: [_univerjs_core.UniverInstanceType.UNIVER_SHEET],
499
+ toJson: (unitId) => toJson(unitId),
500
+ parseJson: (json) => parseJson(json),
501
+ onUnLoad: (unitId) => {
502
+ this._sheetsNoteModel.deleteUnitNotes(unitId);
503
+ },
504
+ onLoad: (unitId, value) => {
505
+ Object.entries(value).forEach(([sheetId, sheetNotes]) => {
506
+ Object.entries(sheetNotes).forEach(([row, colNotes]) => {
507
+ Object.entries(colNotes).forEach(([col, note]) => {
508
+ this._sheetsNoteModel.updateNote(unitId, sheetId, Number(row), Number(col), note);
509
+ });
510
+ });
511
+ });
512
+ }
513
+ }));
514
+ }
515
+ _initSheetChange() {
516
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
517
+ if (commandInfo.id === _univerjs_sheets.RemoveSheetCommand.id) {
518
+ var _getActiveSheet;
519
+ const params = commandInfo.params;
520
+ const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getUnitId();
521
+ const subUnitId = params.subUnitId || ((_getActiveSheet = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId());
522
+ if (!unitId || !subUnitId) return {
523
+ redos: [],
524
+ undos: []
525
+ };
526
+ const sheetNotes = this._sheetsNoteModel.getSheetNotes(unitId, subUnitId);
527
+ if (!sheetNotes) return {
528
+ redos: [],
529
+ undos: []
530
+ };
531
+ const redos = [];
532
+ const undos = [];
533
+ sheetNotes.forEach((note) => {
534
+ redos.push({
535
+ id: RemoveNoteMutation.id,
536
+ params: {
537
+ unitId,
538
+ sheetId: subUnitId,
539
+ noteId: note.id,
540
+ row: note.row,
541
+ col: note.col
542
+ }
543
+ });
544
+ undos.push({
545
+ id: UpdateNoteMutation.id,
546
+ params: {
547
+ unitId,
548
+ sheetId: subUnitId,
549
+ row: note.row,
550
+ col: note.col,
551
+ note
552
+ }
553
+ });
554
+ });
555
+ return {
556
+ redos,
557
+ undos
558
+ };
559
+ } else if (commandInfo.id === _univerjs_sheets.CopySheetCommand.id) {
560
+ const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
561
+ if (!unitId || !subUnitId || !targetSubUnitId) return {
562
+ redos: [],
563
+ undos: []
564
+ };
565
+ const sheetNotes = this._sheetsNoteModel.getSheetNotes(unitId, subUnitId);
566
+ if (!sheetNotes) return {
567
+ redos: [],
568
+ undos: []
569
+ };
570
+ const redos = [];
571
+ const undos = [];
572
+ sheetNotes.forEach((note) => {
573
+ const newNote = {
574
+ ...note,
575
+ id: (0, _univerjs_core.generateRandomId)(6)
576
+ };
577
+ redos.push({
578
+ id: UpdateNoteMutation.id,
579
+ params: {
580
+ unitId,
581
+ sheetId: targetSubUnitId,
582
+ row: newNote.row,
583
+ col: newNote.col,
584
+ note: newNote
585
+ }
586
+ });
587
+ undos.push({
588
+ id: RemoveNoteMutation.id,
589
+ params: {
590
+ unitId,
591
+ sheetId: targetSubUnitId,
592
+ noteId: newNote.id,
593
+ row: newNote.row,
594
+ col: newNote.col
595
+ }
596
+ });
597
+ });
598
+ return {
599
+ redos,
600
+ undos
601
+ };
602
+ }
603
+ return {
604
+ redos: [],
605
+ undos: []
606
+ };
607
+ } }));
608
+ }
609
+ };
610
+ SheetsNoteResourceController = __decorate([
611
+ __decorateParam(0, _univerjs_core.IResourceManagerService),
612
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
613
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
614
+ __decorateParam(3, (0, _univerjs_core.Inject)(SheetsNoteModel))
615
+ ], SheetsNoteResourceController);
616
+
617
+ //#endregion
618
+ //#region package.json
619
+ var name = "@univerjs/sheets-note";
620
+ var version = "0.21.0";
621
+
622
+ //#endregion
623
+ //#region src/config/config.ts
624
+ /**
625
+ * Copyright 2023-present DreamNum Co., Ltd.
626
+ *
627
+ * Licensed under the Apache License, Version 2.0 (the "License");
628
+ * you may not use this file except in compliance with the License.
629
+ * You may obtain a copy of the License at
630
+ *
631
+ * http://www.apache.org/licenses/LICENSE-2.0
632
+ *
633
+ * Unless required by applicable law or agreed to in writing, software
634
+ * distributed under the License is distributed on an "AS IS" BASIS,
635
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
636
+ * See the License for the specific language governing permissions and
637
+ * limitations under the License.
638
+ */
639
+ const SHEETS_NOTE_PLUGIN_CONFIG_KEY = "sheets-note.config";
640
+ const configSymbol = Symbol(SHEETS_NOTE_PLUGIN_CONFIG_KEY);
641
+ const defaultPluginConfig = {};
642
+
643
+ //#endregion
644
+ //#region src/controllers/sheets-note-ref-range.controller.ts
645
+ let SheetsNoteRefRangeController = class SheetsNoteRefRangeController extends _univerjs_core.Disposable {
646
+ constructor(_refRangeService, _sheetsNoteModel, _selectionManagerService, _commandService) {
647
+ super();
648
+ this._refRangeService = _refRangeService;
649
+ this._sheetsNoteModel = _sheetsNoteModel;
650
+ this._selectionManagerService = _selectionManagerService;
651
+ this._commandService = _commandService;
652
+ _defineProperty(this, "_disposableMap", /* @__PURE__ */ new Map());
653
+ _defineProperty(this, "_watcherMap", /* @__PURE__ */ new Map());
654
+ _defineProperty(this, "_handleRangeChange", (unitId, subUnitId, note, row, col, resultRange, silent) => {
655
+ if (!resultRange) return {
656
+ redos: [{
657
+ id: RemoveNoteMutation.id,
658
+ params: {
659
+ unitId,
660
+ sheetId: subUnitId,
661
+ noteId: note.id
662
+ }
663
+ }],
664
+ undos: [{
665
+ id: UpdateNoteMutation.id,
666
+ params: {
667
+ unitId,
668
+ sheetId: subUnitId,
669
+ row,
670
+ col,
671
+ note
672
+ }
673
+ }]
674
+ };
675
+ return {
676
+ redos: [{
677
+ id: UpdateNotePositionMutation.id,
678
+ params: {
679
+ unitId,
680
+ sheetId: subUnitId,
681
+ noteId: note.id,
682
+ newPosition: {
683
+ row: resultRange.startRow,
684
+ col: resultRange.startColumn
685
+ },
686
+ silent
687
+ }
688
+ }],
689
+ undos: [{
690
+ id: UpdateNotePositionMutation.id,
691
+ params: {
692
+ unitId,
693
+ sheetId: subUnitId,
694
+ noteId: note.id,
695
+ newPosition: {
696
+ row,
697
+ col
698
+ },
699
+ note,
700
+ silent
701
+ }
702
+ }]
703
+ };
704
+ });
705
+ this._initData();
706
+ this._initRefRange();
707
+ }
708
+ _getIdWithUnitId(unitId, subUnitId, row, col) {
709
+ return `${unitId}-${subUnitId}-${row}-${col}`;
710
+ }
711
+ _register(unitId, subUnitId, note, row, col) {
712
+ const oldRange = {
713
+ startColumn: col,
714
+ endColumn: col,
715
+ startRow: row,
716
+ endRow: row
717
+ };
718
+ this._disposableMap.set(this._getIdWithUnitId(unitId, subUnitId, row, col), this._refRangeService.registerRefRange(oldRange, (commandInfo) => {
719
+ const resultRanges = (0, _univerjs_sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
720
+ const resultRange = Array.isArray(resultRanges) ? resultRanges[0] : resultRanges;
721
+ if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) return {
722
+ undos: [],
723
+ redos: []
724
+ };
725
+ return this._handleRangeChange(unitId, subUnitId, note, row, col, resultRange, false);
726
+ }, unitId, subUnitId));
727
+ }
728
+ _watch(unitId, subUnitId, note, row, col) {
729
+ const oldRange = {
730
+ startColumn: col,
731
+ endColumn: col,
732
+ startRow: row,
733
+ endRow: row
734
+ };
735
+ this._watcherMap.set(this._getIdWithUnitId(unitId, subUnitId, row, col), this._refRangeService.watchRange(unitId, subUnitId, oldRange, (before, after) => {
736
+ const { redos } = this._handleRangeChange(unitId, subUnitId, note, before.startRow, before.startColumn, after, true);
737
+ (0, _univerjs_core.sequenceExecuteAsync)(redos, this._commandService, { onlyLocal: true });
738
+ }, true));
739
+ }
740
+ _unwatch(unitId, subUnitId, row, col) {
741
+ var _this$_watcherMap$get;
742
+ const id = this._getIdWithUnitId(unitId, subUnitId, row, col);
743
+ (_this$_watcherMap$get = this._watcherMap.get(id)) === null || _this$_watcherMap$get === void 0 || _this$_watcherMap$get.dispose();
744
+ this._watcherMap.delete(id);
745
+ }
746
+ _unregister(unitId, subUnitId, row, col) {
747
+ var _this$_disposableMap$;
748
+ const id = this._getIdWithUnitId(unitId, subUnitId, row, col);
749
+ (_this$_disposableMap$ = this._disposableMap.get(id)) === null || _this$_disposableMap$ === void 0 || _this$_disposableMap$.dispose();
750
+ this._disposableMap.delete(id);
751
+ }
752
+ _initData() {
753
+ const unitNotes = this._sheetsNoteModel.getNotes();
754
+ for (const [unitId, unitNote] of unitNotes) for (const [subUnitId, notes] of unitNote) notes.forEach((note) => {
755
+ this._register(unitId, subUnitId, note, note.row, note.col);
756
+ this._watch(unitId, subUnitId, note, note.row, note.col);
757
+ });
758
+ }
759
+ _initRefRange() {
760
+ this.disposeWithMe(this._sheetsNoteModel.change$.subscribe((option) => {
761
+ switch (option.type) {
762
+ case "update": {
763
+ const { unitId, subUnitId, oldNote, newNote } = option;
764
+ const row = newNote ? newNote.row : oldNote.row;
765
+ const col = newNote ? newNote.col : oldNote.col;
766
+ const id = this._getIdWithUnitId(unitId, subUnitId, row, col);
767
+ if (newNote) {
768
+ if (!this._disposableMap.has(id)) {
769
+ this._register(unitId, subUnitId, newNote, row, col);
770
+ this._watch(unitId, subUnitId, newNote, row, col);
771
+ }
772
+ } else {
773
+ this._unregister(unitId, subUnitId, row, col);
774
+ this._unwatch(unitId, subUnitId, row, col);
775
+ }
776
+ break;
777
+ }
778
+ case "ref": {
779
+ const { unitId, subUnitId, oldNote, newNote, silent } = option;
780
+ const { row: oldRow, col: oldCol } = oldNote;
781
+ const { row: newRow, col: newCol } = newNote;
782
+ this._unregister(unitId, subUnitId, oldRow, oldCol);
783
+ if (!silent) {
784
+ this._unwatch(unitId, subUnitId, oldRow, oldCol);
785
+ this._watch(unitId, subUnitId, newNote, newRow, newCol);
786
+ }
787
+ this._register(unitId, subUnitId, newNote, newRow, newCol);
788
+ break;
789
+ }
790
+ }
791
+ }));
792
+ }
793
+ };
794
+ SheetsNoteRefRangeController = __decorate([
795
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.RefRangeService)),
796
+ __decorateParam(1, (0, _univerjs_core.Inject)(SheetsNoteModel)),
797
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
798
+ __decorateParam(3, _univerjs_core.ICommandService)
799
+ ], SheetsNoteRefRangeController);
800
+
801
+ //#endregion
802
+ //#region src/controllers/sheets.note.controller.ts
803
+ /**
804
+ * Copyright 2023-present DreamNum Co., Ltd.
805
+ *
806
+ * Licensed under the Apache License, Version 2.0 (the "License");
807
+ * you may not use this file except in compliance with the License.
808
+ * You may obtain a copy of the License at
809
+ *
810
+ * http://www.apache.org/licenses/LICENSE-2.0
811
+ *
812
+ * Unless required by applicable law or agreed to in writing, software
813
+ * distributed under the License is distributed on an "AS IS" BASIS,
814
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
815
+ * See the License for the specific language governing permissions and
816
+ * limitations under the License.
817
+ */
818
+ let SheetsNoteController = class SheetsNoteController extends _univerjs_core.Disposable {
819
+ constructor(_commandService) {
820
+ super();
821
+ this._commandService = _commandService;
822
+ this._initialize();
823
+ }
824
+ _initialize() {
825
+ [
826
+ UpdateNotePositionMutation,
827
+ ToggleNotePopupMutation,
828
+ UpdateNoteMutation,
829
+ RemoveNoteMutation,
830
+ SheetDeleteNoteCommand,
831
+ SheetToggleNotePopupCommand,
832
+ SheetUpdateNoteCommand
833
+ ].forEach((command) => {
834
+ this.disposeWithMe(this._commandService.registerCommand(command));
835
+ });
836
+ }
837
+ };
838
+ SheetsNoteController = __decorate([__decorateParam(0, _univerjs_core.ICommandService)], SheetsNoteController);
839
+
840
+ //#endregion
841
+ //#region src/plugin.ts
842
+ let UniverSheetsNotePlugin = class UniverSheetsNotePlugin extends _univerjs_core.Plugin {
843
+ constructor(_config = defaultPluginConfig, _configService, _injector) {
844
+ super();
845
+ this._config = _config;
846
+ this._configService = _configService;
847
+ this._injector = _injector;
848
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
849
+ this._configService.setConfig(SHEETS_NOTE_PLUGIN_CONFIG_KEY, rest);
850
+ }
851
+ onStarting() {
852
+ [
853
+ [SheetsNoteModel],
854
+ [SheetsNoteController],
855
+ [SheetsNoteResourceController],
856
+ [SheetsNoteRefRangeController]
857
+ ].forEach((dependency) => {
858
+ this._injector.add(dependency);
859
+ });
860
+ (0, _univerjs_core.touchDependencies)(this._injector, [
861
+ [SheetsNoteModel],
862
+ [SheetsNoteController],
863
+ [SheetsNoteResourceController]
864
+ ]);
865
+ }
866
+ onReady() {
867
+ (0, _univerjs_core.touchDependencies)(this._injector, [[SheetsNoteRefRangeController]]);
868
+ }
869
+ };
870
+ _defineProperty(UniverSheetsNotePlugin, "pluginName", PLUGIN_NAME);
871
+ _defineProperty(UniverSheetsNotePlugin, "packageName", name);
872
+ _defineProperty(UniverSheetsNotePlugin, "version", version);
873
+ _defineProperty(UniverSheetsNotePlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
874
+ UniverSheetsNotePlugin = __decorate([
875
+ (0, _univerjs_core.DependentOn)(_univerjs_sheets.UniverSheetsPlugin),
876
+ __decorateParam(1, _univerjs_core.IConfigService),
877
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
878
+ ], UniverSheetsNotePlugin);
879
+
880
+ //#endregion
881
+ exports.RemoveNoteMutation = RemoveNoteMutation;
882
+ exports.SheetDeleteNoteCommand = SheetDeleteNoteCommand;
883
+ exports.SheetToggleNotePopupCommand = SheetToggleNotePopupCommand;
884
+ exports.SheetUpdateNoteCommand = SheetUpdateNoteCommand;
885
+ exports.SheetsNoteModel = SheetsNoteModel;
886
+ Object.defineProperty(exports, 'SheetsNoteResourceController', {
887
+ enumerable: true,
888
+ get: function () {
889
+ return SheetsNoteResourceController;
890
+ }
891
+ });
892
+ exports.ToggleNotePopupMutation = ToggleNotePopupMutation;
893
+ Object.defineProperty(exports, 'UniverSheetsNotePlugin', {
894
+ enumerable: true,
895
+ get: function () {
896
+ return UniverSheetsNotePlugin;
897
+ }
898
+ });
899
+ exports.UpdateNoteMutation = UpdateNoteMutation;
900
+ exports.UpdateNotePositionMutation = UpdateNotePositionMutation;