@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/es/facade.js
CHANGED
|
@@ -1 +1,305 @@
|
|
|
1
|
-
import
|
|
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 };
|