@univerjs/sheets-note 0.17.0 → 0.18.0

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