@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/facade.js CHANGED
@@ -1 +1,305 @@
1
- import{FEventName as e,FUniver as t}from"@univerjs/core/facade";import{RemoveNoteMutation as n,SheetDeleteNoteCommand as r,SheetToggleNotePopupCommand as i,SheetUpdateNoteCommand as a,SheetsNoteModel as o,UpdateNoteMutation as s}from"@univerjs/sheets-note";import{FRange as c,FWorksheet as l}from"@univerjs/sheets/facade";import{CanceledError as u,ICommandService as d,IUniverInstanceService as f}from"@univerjs/core";import{SheetsSelectionsService as p,getSheetCommandTarget as m}from"@univerjs/sheets";var h=class extends e{get SheetNoteAdd(){return`SheetNoteAdd`}get SheetNoteDelete(){return`SheetNoteDelete`}get SheetNoteUpdate(){return`SheetNoteUpdate`}get SheetNoteShow(){return`SheetNoteShow`}get SheetNoteHide(){return`SheetNoteHide`}get BeforeSheetNoteAdd(){return`BeforeSheetNoteAdd`}get BeforeSheetNoteDelete(){return`BeforeSheetNoteDelete`}get BeforeSheetNoteUpdate(){return`BeforeSheetNoteUpdate`}get BeforeSheetNoteShow(){return`BeforeSheetNoteShow`}get BeforeSheetNoteHide(){return`BeforeSheetNoteHide`}};e.extend(h);var g=class extends c{createOrUpdateNote(e){return this._commandService.syncExecuteCommand(s.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:e}),this}deleteNote(){return this._commandService.syncExecuteCommand(n.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(o).getNote(this.getUnitId(),this.getSheetId(),{row:this.getRow(),col:this.getColumn()})}};c.extend(g);var _=class extends t{_initialize(e){let t=e.get(d);this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteAdd,()=>e.get(o).change$.subscribe(e=>{if(e.type===`update`&&!e.oldNote&&e.newNote){let{unitId:t,subUnitId:n,newNote:r}=e,i=this.getSheetTarget(t,n);if(!i)return;let{workbook:a,worksheet:o}=i,s={workbook:a,worksheet:o,row:r.row,col:r.col,note:r};this.fireEvent(this.Event.SheetNoteAdd,s)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteDelete,()=>e.get(o).change$.subscribe(e=>{if(e.type===`update`&&e.oldNote&&!e.newNote){let{unitId:t,subUnitId:n,oldNote:r}=e,i=this.getSheetTarget(t,n);if(!i)return;let{workbook:a,worksheet:o}=i,s={workbook:a,worksheet:o,row:r.row,col:r.col,oldNote:r};this.fireEvent(this.Event.SheetNoteDelete,s)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteUpdate,()=>e.get(o).change$.subscribe(e=>{if(e.type===`update`&&e.oldNote&&e.newNote){let{unitId:t,subUnitId:n,oldNote:r,newNote:i}=e,a=this.getSheetTarget(t,n);if(!a)return;let{workbook:o,worksheet:s}=a,c={workbook:o,worksheet:s,row:i.row,col:i.col,note:i,oldNote:r};this.fireEvent(this.Event.SheetNoteUpdate,c)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteShow,()=>e.get(o).change$.subscribe(e=>{if(e.type===`update`&&e.oldNote&&e.newNote&&!e.oldNote.show&&e.newNote.show){let{unitId:t,subUnitId:n,newNote:r}=e,i=this.getSheetTarget(t,n);if(!i)return;let{workbook:a,worksheet:o}=i,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteShow,s)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteHide,()=>e.get(o).change$.subscribe(e=>{if(e.type===`update`&&e.oldNote&&e.newNote&&e.oldNote.show&&!e.newNote.show){let{unitId:t,subUnitId:n,newNote:r}=e,i=this.getSheetTarget(t,n);if(!i)return;let{workbook:a,worksheet:o}=i,s={workbook:a,worksheet:o,row:r.row,col:r.col};this.fireEvent(this.Event.SheetNoteHide,s)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteAdd,()=>t.beforeCommandExecuted(t=>{if(t.id===a.id){let{unitId:n,sheetId:r,row:i,col:a,note:s}=t.params,c=this.getSheetTarget(n,r);if(!c||e.get(o).getNote(n,r,{noteId:s.id,row:i,col:a}))return;let{workbook:l,worksheet:d}=c,f={workbook:l,worksheet:d,row:i,col:a,note:s};if(this.fireEvent(this.Event.BeforeSheetNoteAdd,f))throw new u}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>t.beforeCommandExecuted(t=>{if(t.id===r.id){let{unitId:n,sheetId:r,row:i,col:a}=t.params,s=this.getSheetTarget(n,r);if(!s||i===void 0||a===void 0)return;let c=e.get(o).getNote(n,r,{row:i,col:a});if(!c)return;let{workbook:l,worksheet:d}=s,f={workbook:l,worksheet:d,row:i,col:a,oldNote:c};if(this.fireEvent(this.Event.BeforeSheetNoteDelete,f))throw new u}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>t.beforeCommandExecuted(t=>{if(t.id===a.id){let{unitId:n,sheetId:r,row:i,col:a,note:s}=t.params,c=this.getSheetTarget(n,r);if(!c)return;let l=e.get(o).getNote(n,r,{row:i,col:a});if(!l)return;let{workbook:d,worksheet:f}=c,p={workbook:d,worksheet:f,row:i,col:a,note:s,oldNote:l};if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,p))throw new u}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>t.beforeCommandExecuted(t=>{if(t.id===i.id){let t=m(e.get(f));if(!t)return;let{unitId:n,subUnitId:r}=t,i=this.getUniverSheet(n);if(!i)return;let a=i.getSheetBySheetId(r);if(!a)return;let s=e.get(p).getCurrentLastSelection();if(!(s!=null&&s.primary))return;let c=e.get(o),{actualColumn:l,actualRow:d}=s.primary,h=c.getNote(n,r,{row:d,col:l});if(!h||h.show)return;let g={workbook:i,worksheet:a,row:d,col:l};if(this.fireEvent(this.Event.BeforeSheetNoteShow,g))throw new u}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>t.beforeCommandExecuted(t=>{if(t.id===i.id){let t=m(e.get(f));if(!t)return;let{unitId:n,subUnitId:r}=t,i=this.getUniverSheet(n);if(!i)return;let a=i.getSheetBySheetId(r);if(!a)return;let s=e.get(p).getCurrentLastSelection();if(!(s!=null&&s.primary))return;let c=e.get(o),{actualColumn:l,actualRow:d}=s.primary,h=c.getNote(n,r,{row:d,col:l});if(!h||!h.show)return;let g={workbook:i,worksheet:a,row:d,col:l};if(this.fireEvent(this.Event.BeforeSheetNoteHide,g))throw new u}})))}};t.extend(_);var v=class extends l{getNotes(){let e=this._injector.get(o).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId());return e?Array.from(e.values()).map(e=>({...e})):[]}};l.extend(v);export{g as FRangeSheetsNoteMixin,h as FSheetsNoteEventNameMixin,_ as FUniverSheetsNoteMixin,v as FWorksheetNoteMixin};
1
+ import { FEventName, FUniver } from "@univerjs/core/facade";
2
+ import { RemoveNoteMutation, SheetDeleteNoteCommand, SheetToggleNotePopupCommand, SheetUpdateNoteCommand, SheetsNoteModel, UpdateNoteMutation } from "@univerjs/sheets-note";
3
+ import { FRange, FWorksheet } from "@univerjs/sheets/facade";
4
+ import { CanceledError, ICommandService, IUniverInstanceService } from "@univerjs/core";
5
+ import { SheetsSelectionsService, getSheetCommandTarget } from "@univerjs/sheets";
6
+
7
+ //#region src/facade/f-event.ts
8
+ /**
9
+ * @ignore
10
+ */
11
+ var FSheetsNoteEventNameMixin = class extends FEventName {
12
+ get SheetNoteAdd() {
13
+ return "SheetNoteAdd";
14
+ }
15
+ get SheetNoteDelete() {
16
+ return "SheetNoteDelete";
17
+ }
18
+ get SheetNoteUpdate() {
19
+ return "SheetNoteUpdate";
20
+ }
21
+ get SheetNoteShow() {
22
+ return "SheetNoteShow";
23
+ }
24
+ get SheetNoteHide() {
25
+ return "SheetNoteHide";
26
+ }
27
+ get BeforeSheetNoteAdd() {
28
+ return "BeforeSheetNoteAdd";
29
+ }
30
+ get BeforeSheetNoteDelete() {
31
+ return "BeforeSheetNoteDelete";
32
+ }
33
+ get BeforeSheetNoteUpdate() {
34
+ return "BeforeSheetNoteUpdate";
35
+ }
36
+ get BeforeSheetNoteShow() {
37
+ return "BeforeSheetNoteShow";
38
+ }
39
+ get BeforeSheetNoteHide() {
40
+ return "BeforeSheetNoteHide";
41
+ }
42
+ };
43
+ FEventName.extend(FSheetsNoteEventNameMixin);
44
+
45
+ //#endregion
46
+ //#region src/facade/f-range.ts
47
+ var FRangeSheetsNoteMixin = class extends FRange {
48
+ createOrUpdateNote(note) {
49
+ this._commandService.syncExecuteCommand(UpdateNoteMutation.id, {
50
+ unitId: this.getUnitId(),
51
+ sheetId: this.getSheetId(),
52
+ row: this.getRow(),
53
+ col: this.getColumn(),
54
+ note
55
+ });
56
+ return this;
57
+ }
58
+ deleteNote() {
59
+ this._commandService.syncExecuteCommand(RemoveNoteMutation.id, {
60
+ unitId: this.getUnitId(),
61
+ sheetId: this.getSheetId(),
62
+ row: this.getRow(),
63
+ col: this.getColumn()
64
+ });
65
+ return this;
66
+ }
67
+ getNote() {
68
+ return this._injector.get(SheetsNoteModel).getNote(this.getUnitId(), this.getSheetId(), {
69
+ row: this.getRow(),
70
+ col: this.getColumn()
71
+ });
72
+ }
73
+ };
74
+ FRange.extend(FRangeSheetsNoteMixin);
75
+
76
+ //#endregion
77
+ //#region src/facade/f-univer.ts
78
+ var FUniverSheetsNoteMixin = class extends FUniver {
79
+ _initialize(injector) {
80
+ const commandService = injector.get(ICommandService);
81
+ this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteAdd, () => {
82
+ return injector.get(SheetsNoteModel).change$.subscribe((change) => {
83
+ if (change.type === "update" && !change.oldNote && change.newNote) {
84
+ const { unitId, subUnitId, newNote } = change;
85
+ const target = this.getSheetTarget(unitId, subUnitId);
86
+ if (!target) return;
87
+ const { workbook, worksheet } = target;
88
+ const eventParams = {
89
+ workbook,
90
+ worksheet,
91
+ row: newNote.row,
92
+ col: newNote.col,
93
+ note: newNote
94
+ };
95
+ this.fireEvent(this.Event.SheetNoteAdd, eventParams);
96
+ }
97
+ });
98
+ }));
99
+ this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteDelete, () => {
100
+ return injector.get(SheetsNoteModel).change$.subscribe((change) => {
101
+ if (change.type === "update" && change.oldNote && !change.newNote) {
102
+ const { unitId, subUnitId, oldNote } = change;
103
+ const target = this.getSheetTarget(unitId, subUnitId);
104
+ if (!target) return;
105
+ const { workbook, worksheet } = target;
106
+ const eventParams = {
107
+ workbook,
108
+ worksheet,
109
+ row: oldNote.row,
110
+ col: oldNote.col,
111
+ oldNote
112
+ };
113
+ this.fireEvent(this.Event.SheetNoteDelete, eventParams);
114
+ }
115
+ });
116
+ }));
117
+ this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteUpdate, () => {
118
+ return injector.get(SheetsNoteModel).change$.subscribe((change) => {
119
+ if (change.type === "update" && change.oldNote && change.newNote) {
120
+ const { unitId, subUnitId, oldNote, newNote } = change;
121
+ const target = this.getSheetTarget(unitId, subUnitId);
122
+ if (!target) return;
123
+ const { workbook, worksheet } = target;
124
+ const eventParams = {
125
+ workbook,
126
+ worksheet,
127
+ row: newNote.row,
128
+ col: newNote.col,
129
+ note: newNote,
130
+ oldNote
131
+ };
132
+ this.fireEvent(this.Event.SheetNoteUpdate, eventParams);
133
+ }
134
+ });
135
+ }));
136
+ this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteShow, () => {
137
+ return injector.get(SheetsNoteModel).change$.subscribe((change) => {
138
+ if (change.type === "update" && change.oldNote && change.newNote && !change.oldNote.show && change.newNote.show) {
139
+ const { unitId, subUnitId, newNote } = change;
140
+ const target = this.getSheetTarget(unitId, subUnitId);
141
+ if (!target) return;
142
+ const { workbook, worksheet } = target;
143
+ const eventParams = {
144
+ workbook,
145
+ worksheet,
146
+ row: newNote.row,
147
+ col: newNote.col
148
+ };
149
+ this.fireEvent(this.Event.SheetNoteShow, eventParams);
150
+ }
151
+ });
152
+ }));
153
+ this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteHide, () => {
154
+ return injector.get(SheetsNoteModel).change$.subscribe((change) => {
155
+ if (change.type === "update" && change.oldNote && change.newNote && change.oldNote.show && !change.newNote.show) {
156
+ const { unitId, subUnitId, newNote } = change;
157
+ const target = this.getSheetTarget(unitId, subUnitId);
158
+ if (!target) return;
159
+ const { workbook, worksheet } = target;
160
+ const eventParams = {
161
+ workbook,
162
+ worksheet,
163
+ row: newNote.row,
164
+ col: newNote.col
165
+ };
166
+ this.fireEvent(this.Event.SheetNoteHide, eventParams);
167
+ }
168
+ });
169
+ }));
170
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteAdd, () => commandService.beforeCommandExecuted((command) => {
171
+ if (command.id === SheetUpdateNoteCommand.id) {
172
+ const { unitId, sheetId, row, col, note } = command.params;
173
+ const target = this.getSheetTarget(unitId, sheetId);
174
+ if (!target) return;
175
+ if (injector.get(SheetsNoteModel).getNote(unitId, sheetId, {
176
+ noteId: note.id,
177
+ row,
178
+ col
179
+ })) return;
180
+ const { workbook, worksheet } = target;
181
+ const eventParams = {
182
+ workbook,
183
+ worksheet,
184
+ row,
185
+ col,
186
+ note
187
+ };
188
+ if (this.fireEvent(this.Event.BeforeSheetNoteAdd, eventParams)) throw new CanceledError();
189
+ }
190
+ })));
191
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteDelete, () => commandService.beforeCommandExecuted((command) => {
192
+ if (command.id === SheetDeleteNoteCommand.id) {
193
+ const { unitId, sheetId, row, col } = command.params;
194
+ const target = this.getSheetTarget(unitId, sheetId);
195
+ if (!target) return;
196
+ if (row === void 0 || col === void 0) return;
197
+ const oldNote = injector.get(SheetsNoteModel).getNote(unitId, sheetId, {
198
+ row,
199
+ col
200
+ });
201
+ if (!oldNote) return;
202
+ const { workbook, worksheet } = target;
203
+ const eventParams = {
204
+ workbook,
205
+ worksheet,
206
+ row,
207
+ col,
208
+ oldNote
209
+ };
210
+ if (this.fireEvent(this.Event.BeforeSheetNoteDelete, eventParams)) throw new CanceledError();
211
+ }
212
+ })));
213
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteUpdate, () => commandService.beforeCommandExecuted((command) => {
214
+ if (command.id === SheetUpdateNoteCommand.id) {
215
+ const { unitId, sheetId, row, col, note } = command.params;
216
+ const target = this.getSheetTarget(unitId, sheetId);
217
+ if (!target) return;
218
+ const oldNote = injector.get(SheetsNoteModel).getNote(unitId, sheetId, {
219
+ row,
220
+ col
221
+ });
222
+ if (!oldNote) return;
223
+ const { workbook, worksheet } = target;
224
+ const eventParams = {
225
+ workbook,
226
+ worksheet,
227
+ row,
228
+ col,
229
+ note,
230
+ oldNote
231
+ };
232
+ if (this.fireEvent(this.Event.BeforeSheetNoteUpdate, eventParams)) throw new CanceledError();
233
+ }
234
+ })));
235
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteShow, () => commandService.beforeCommandExecuted((command) => {
236
+ if (command.id === SheetToggleNotePopupCommand.id) {
237
+ const target = getSheetCommandTarget(injector.get(IUniverInstanceService));
238
+ if (!target) return;
239
+ const { unitId, subUnitId } = target;
240
+ const workbook = this.getUniverSheet(unitId);
241
+ if (!workbook) return;
242
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
243
+ if (!worksheet) return;
244
+ const selection = injector.get(SheetsSelectionsService).getCurrentLastSelection();
245
+ if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return;
246
+ const sheetsNoteModel = injector.get(SheetsNoteModel);
247
+ const { actualColumn, actualRow } = selection.primary;
248
+ const note = sheetsNoteModel.getNote(unitId, subUnitId, {
249
+ row: actualRow,
250
+ col: actualColumn
251
+ });
252
+ if (!note || note.show) return;
253
+ const eventParams = {
254
+ workbook,
255
+ worksheet,
256
+ row: actualRow,
257
+ col: actualColumn
258
+ };
259
+ if (this.fireEvent(this.Event.BeforeSheetNoteShow, eventParams)) throw new CanceledError();
260
+ }
261
+ })));
262
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteHide, () => commandService.beforeCommandExecuted((command) => {
263
+ if (command.id === SheetToggleNotePopupCommand.id) {
264
+ const target = getSheetCommandTarget(injector.get(IUniverInstanceService));
265
+ if (!target) return;
266
+ const { unitId, subUnitId } = target;
267
+ const workbook = this.getUniverSheet(unitId);
268
+ if (!workbook) return;
269
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
270
+ if (!worksheet) return;
271
+ const selection = injector.get(SheetsSelectionsService).getCurrentLastSelection();
272
+ if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return;
273
+ const sheetsNoteModel = injector.get(SheetsNoteModel);
274
+ const { actualColumn, actualRow } = selection.primary;
275
+ const note = sheetsNoteModel.getNote(unitId, subUnitId, {
276
+ row: actualRow,
277
+ col: actualColumn
278
+ });
279
+ if (!note || !note.show) return;
280
+ const eventParams = {
281
+ workbook,
282
+ worksheet,
283
+ row: actualRow,
284
+ col: actualColumn
285
+ };
286
+ if (this.fireEvent(this.Event.BeforeSheetNoteHide, eventParams)) throw new CanceledError();
287
+ }
288
+ })));
289
+ }
290
+ };
291
+ FUniver.extend(FUniverSheetsNoteMixin);
292
+
293
+ //#endregion
294
+ //#region src/facade/f-worksheet.ts
295
+ var FWorksheetNoteMixin = class extends FWorksheet {
296
+ getNotes() {
297
+ const notes = this._injector.get(SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(), this.getSheetId());
298
+ if (!notes) return [];
299
+ return Array.from(notes.values()).map((note) => ({ ...note }));
300
+ }
301
+ };
302
+ FWorksheet.extend(FWorksheetNoteMixin);
303
+
304
+ //#endregion
305
+ export { FRangeSheetsNoteMixin, FSheetsNoteEventNameMixin, FUniverSheetsNoteMixin, FWorksheetNoteMixin };