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