@univerjs/sheets-note 0.15.4 → 0.15.5

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