@univerjs/sheets-note 1.3.1 → 1.5.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/README.md +6 -5
- package/lib/cjs/facade.js +4 -8
- package/lib/cjs/index.js +45 -40
- package/lib/es/facade.js +4 -8
- package/lib/es/index.js +46 -41
- package/lib/facade.js +4 -8
- package/lib/index.js +46 -41
- package/lib/types/models/sheets-note.model.d.ts +2 -0
- package/lib/umd/index.js +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
## Package Overview
|
|
10
10
|
|
|
11
|
-
| Package | UMD global | CSS | Locales | Facade entry |
|
|
12
|
-
| --- | --- | :---: | :---: | :---: |
|
|
13
|
-
| `@univerjs/sheets-note` | `UniverSheetsNote` | No | No | Yes |
|
|
11
|
+
| Package | UMD global | CSS | Locales | Facade entry | Worker entry |
|
|
12
|
+
| --- | --- | :---: | :---: | :---: | :---: |
|
|
13
|
+
| `@univerjs/sheets-note` | `UniverSheetsNote` | No | No | Yes | No |
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -20,10 +20,10 @@ pnpm add @univerjs/sheets-note
|
|
|
20
20
|
npm install @univerjs/sheets-note
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Keep all `@univerjs/*` packages on the same version.
|
|
24
|
-
|
|
25
23
|
## Usage
|
|
26
24
|
|
|
25
|
+
Start with the [integration setup](https://docs.univer.ai/) for your document type, including its required plugins, styles, and locale resources. The snippet below assumes that setup is complete.
|
|
26
|
+
|
|
27
27
|
```ts
|
|
28
28
|
import { UniverSheetsNotePlugin } from '@univerjs/sheets-note';
|
|
29
29
|
|
|
@@ -33,6 +33,7 @@ univer.registerPlugin(UniverSheetsNotePlugin);
|
|
|
33
33
|
## Integration Notes
|
|
34
34
|
|
|
35
35
|
Use this package with `@univerjs/sheets-note-ui` when users need note editing UI.
|
|
36
|
+
- Import `@univerjs/sheets-note/facade` when using this package through Univer Facade APIs.
|
|
36
37
|
|
|
37
38
|
## Resources
|
|
38
39
|
|
package/lib/cjs/facade.js
CHANGED
|
@@ -5,7 +5,7 @@ let _univerjs_sheets_facade = require("@univerjs/sheets/facade");
|
|
|
5
5
|
let _univerjs_core = require("@univerjs/core");
|
|
6
6
|
let _univerjs_sheets = require("@univerjs/sheets");
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// src/facade/f-event.ts
|
|
9
9
|
/**
|
|
10
10
|
* @ignore
|
|
11
11
|
*/
|
|
@@ -43,8 +43,7 @@ var FSheetsNoteEventNameMixin = class extends _univerjs_core_facade.FEventName {
|
|
|
43
43
|
};
|
|
44
44
|
_univerjs_core_facade.FEventName.extend(FSheetsNoteEventNameMixin);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
//#region src/facade/f-range.ts
|
|
46
|
+
// src/facade/f-range.ts
|
|
48
47
|
var FRangeSheetsNoteMixin = class extends _univerjs_sheets_facade.FRange {
|
|
49
48
|
createOrUpdateNote(note) {
|
|
50
49
|
this._commandService.syncExecuteCommand(_univerjs_sheets_note.UpdateNoteMutation.id, {
|
|
@@ -74,8 +73,7 @@ var FRangeSheetsNoteMixin = class extends _univerjs_sheets_facade.FRange {
|
|
|
74
73
|
};
|
|
75
74
|
_univerjs_sheets_facade.FRange.extend(FRangeSheetsNoteMixin);
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
//#region src/facade/f-univer.ts
|
|
76
|
+
// src/facade/f-univer.ts
|
|
79
77
|
var FUniverSheetsNoteMixin = class extends _univerjs_core_facade.FUniver {
|
|
80
78
|
_initialize(injector) {
|
|
81
79
|
const commandService = injector.get(_univerjs_core.ICommandService);
|
|
@@ -299,8 +297,7 @@ var FUniverSheetsNoteMixin = class extends _univerjs_core_facade.FUniver {
|
|
|
299
297
|
};
|
|
300
298
|
_univerjs_core_facade.FUniver.extend(FUniverSheetsNoteMixin);
|
|
301
299
|
|
|
302
|
-
|
|
303
|
-
//#region src/facade/f-worksheet.ts
|
|
300
|
+
// src/facade/f-worksheet.ts
|
|
304
301
|
var FWorksheetNoteMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
305
302
|
getNotes() {
|
|
306
303
|
const notes = this._injector.get(_univerjs_sheets_note.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(), this.getSheetId());
|
|
@@ -310,7 +307,6 @@ var FWorksheetNoteMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
|
310
307
|
};
|
|
311
308
|
_univerjs_sheets_facade.FWorksheet.extend(FWorksheetNoteMixin);
|
|
312
309
|
|
|
313
|
-
//#endregion
|
|
314
310
|
exports.FRangeSheetsNoteMixin = FRangeSheetsNoteMixin;
|
|
315
311
|
exports.FSheetsNoteEventNameMixin = FSheetsNoteEventNameMixin;
|
|
316
312
|
exports.FUniverSheetsNoteMixin = FUniverSheetsNoteMixin;
|
package/lib/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@ let _univerjs_core = require("@univerjs/core");
|
|
|
3
3
|
let _univerjs_sheets = require("@univerjs/sheets");
|
|
4
4
|
let rxjs = require("rxjs");
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
7
7
|
function _typeof(o) {
|
|
8
8
|
"@babel/helpers - typeof";
|
|
9
9
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -13,28 +13,25 @@ function _typeof(o) {
|
|
|
13
13
|
}, _typeof(o);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function toPrimitive(t, r) {
|
|
16
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
17
|
+
function toPrimitive(t, e) {
|
|
19
18
|
if ("object" != _typeof(t) || !t) return t;
|
|
20
|
-
var
|
|
21
|
-
if (void 0 !==
|
|
22
|
-
var i =
|
|
19
|
+
var r;
|
|
20
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
21
|
+
var i = r.call(t, e || "default");
|
|
23
22
|
if ("object" != _typeof(i)) return i;
|
|
24
23
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
25
24
|
}
|
|
26
|
-
return ("string" ===
|
|
25
|
+
return ("string" === e ? String : Number)(t);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
28
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
31
29
|
function toPropertyKey(t) {
|
|
32
30
|
var i = toPrimitive(t, "string");
|
|
33
31
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
34
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
38
35
|
function _defineProperty(e, r, t) {
|
|
39
36
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
40
37
|
value: t,
|
|
@@ -44,15 +41,21 @@ function _defineProperty(e, r, t) {
|
|
|
44
41
|
}) : e[r] = t, e;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
//#region src/models/sheets-note.model.ts
|
|
44
|
+
// src/models/sheets-note.model.ts
|
|
49
45
|
var SheetsNoteModel = class extends _univerjs_core.Disposable {
|
|
50
46
|
constructor(..._args) {
|
|
51
47
|
super(..._args);
|
|
52
48
|
_defineProperty(this, "_notesMap", /* @__PURE__ */ new Map());
|
|
49
|
+
_defineProperty(this, "_notePositionCache", /* @__PURE__ */ new WeakMap());
|
|
53
50
|
_defineProperty(this, "_change$", new rxjs.Subject());
|
|
54
51
|
_defineProperty(this, "change$", this._change$.asObservable());
|
|
55
52
|
}
|
|
53
|
+
dispose() {
|
|
54
|
+
this._notePositionCache = /* @__PURE__ */ new WeakMap();
|
|
55
|
+
this._notesMap.clear();
|
|
56
|
+
this._change$.complete();
|
|
57
|
+
super.dispose();
|
|
58
|
+
}
|
|
56
59
|
_ensureNotesMap(unitId, subUnitId) {
|
|
57
60
|
let unitMap = this._notesMap.get(unitId);
|
|
58
61
|
if (!unitMap) {
|
|
@@ -68,7 +71,14 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
|
|
|
68
71
|
}
|
|
69
72
|
_getNoteByPosition(unitId, subUnitId, row, col) {
|
|
70
73
|
const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
|
|
71
|
-
|
|
74
|
+
let positions = this._notePositionCache.get(subUnitMap);
|
|
75
|
+
if (!positions) {
|
|
76
|
+
positions = new _univerjs_core.ObjectMatrix();
|
|
77
|
+
for (const note of subUnitMap.values()) if (!positions.getValue(note.row, note.col)) positions.setValue(note.row, note.col, note);
|
|
78
|
+
this._notePositionCache.set(subUnitMap, positions);
|
|
79
|
+
}
|
|
80
|
+
const note = positions.getValue(row, col);
|
|
81
|
+
return (note === null || note === void 0 ? void 0 : note.row) === row && note.col === col ? note : void 0;
|
|
72
82
|
}
|
|
73
83
|
_getNoteById(unitId, subUnitId, id) {
|
|
74
84
|
return this._ensureNotesMap(unitId, subUnitId).get(id);
|
|
@@ -115,6 +125,7 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
|
|
|
115
125
|
col
|
|
116
126
|
};
|
|
117
127
|
subUnitMap.set(newNote.id, newNote);
|
|
128
|
+
this._notePositionCache.delete(subUnitMap);
|
|
118
129
|
this._change$.next({
|
|
119
130
|
unitId,
|
|
120
131
|
subUnitId,
|
|
@@ -132,7 +143,9 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
|
|
|
132
143
|
col
|
|
133
144
|
});
|
|
134
145
|
if (!oldNote) return;
|
|
135
|
-
this._ensureNotesMap(unitId, subUnitId)
|
|
146
|
+
const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
|
|
147
|
+
subUnitMap.delete(oldNote.id);
|
|
148
|
+
this._notePositionCache.delete(subUnitMap);
|
|
136
149
|
this._change$.next({
|
|
137
150
|
unitId,
|
|
138
151
|
subUnitId,
|
|
@@ -156,6 +169,7 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
|
|
|
156
169
|
show: !oldNote.show
|
|
157
170
|
};
|
|
158
171
|
subUnitMap.set(newNote.id, newNote);
|
|
172
|
+
this._notePositionCache.delete(subUnitMap);
|
|
159
173
|
this._change$.next({
|
|
160
174
|
unitId,
|
|
161
175
|
subUnitId,
|
|
@@ -180,6 +194,7 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
|
|
|
180
194
|
col: newCol
|
|
181
195
|
};
|
|
182
196
|
subUnitMap.set(newNote.id, newNote);
|
|
197
|
+
this._notePositionCache.delete(subUnitMap);
|
|
183
198
|
this._change$.next({
|
|
184
199
|
unitId,
|
|
185
200
|
subUnitId,
|
|
@@ -204,12 +219,13 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
|
|
|
204
219
|
return unitMap.get(subUnitId);
|
|
205
220
|
}
|
|
206
221
|
deleteUnitNotes(unitId) {
|
|
222
|
+
var _this$_notesMap$get;
|
|
223
|
+
(_this$_notesMap$get = this._notesMap.get(unitId)) === null || _this$_notesMap$get === void 0 || _this$_notesMap$get.forEach((notes) => this._notePositionCache.delete(notes));
|
|
207
224
|
this._notesMap.delete(unitId);
|
|
208
225
|
}
|
|
209
226
|
};
|
|
210
227
|
|
|
211
|
-
|
|
212
|
-
//#region src/commands/mutations/note.mutation.ts
|
|
228
|
+
// src/commands/mutations/note.mutation.ts
|
|
213
229
|
const UpdateNoteMutation = {
|
|
214
230
|
id: "sheet.mutation.update-note",
|
|
215
231
|
type: _univerjs_core.CommandType.MUTATION,
|
|
@@ -264,8 +280,7 @@ const UpdateNotePositionMutation = {
|
|
|
264
280
|
}
|
|
265
281
|
};
|
|
266
282
|
|
|
267
|
-
|
|
268
|
-
//#region src/commands/commands/note.command.ts
|
|
283
|
+
// src/commands/commands/note.command.ts
|
|
269
284
|
const SheetDeleteNoteCommand = {
|
|
270
285
|
id: "sheet.command.delete-note",
|
|
271
286
|
type: _univerjs_core.CommandType.COMMAND,
|
|
@@ -421,8 +436,7 @@ const SheetUpdateNoteCommand = {
|
|
|
421
436
|
}
|
|
422
437
|
};
|
|
423
438
|
|
|
424
|
-
|
|
425
|
-
//#region src/const.ts
|
|
439
|
+
// src/const.ts
|
|
426
440
|
/**
|
|
427
441
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
428
442
|
*
|
|
@@ -440,16 +454,14 @@ const SheetUpdateNoteCommand = {
|
|
|
440
454
|
*/
|
|
441
455
|
const PLUGIN_NAME = "SHEET_NOTE_PLUGIN";
|
|
442
456
|
|
|
443
|
-
|
|
444
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
457
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
445
458
|
function __decorateParam(paramIndex, decorator) {
|
|
446
459
|
return function(target, key) {
|
|
447
460
|
decorator(target, key, paramIndex);
|
|
448
461
|
};
|
|
449
462
|
}
|
|
450
463
|
|
|
451
|
-
|
|
452
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
464
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
453
465
|
function __decorate(decorators, target, key, desc) {
|
|
454
466
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
455
467
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -457,8 +469,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
457
469
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
458
470
|
}
|
|
459
471
|
|
|
460
|
-
|
|
461
|
-
//#region src/controllers/sheets-note-resource.controller.ts
|
|
472
|
+
// src/controllers/sheets-note-resource.controller.ts
|
|
462
473
|
let SheetsNoteResourceController = class SheetsNoteResourceController extends _univerjs_core.Disposable {
|
|
463
474
|
constructor(_resourceManagerService, _univerInstanceService, _sheetInterceptorService, _sheetsNoteModel) {
|
|
464
475
|
super();
|
|
@@ -614,13 +625,11 @@ SheetsNoteResourceController = __decorate([
|
|
|
614
625
|
__decorateParam(3, (0, _univerjs_core.Inject)(SheetsNoteModel))
|
|
615
626
|
], SheetsNoteResourceController);
|
|
616
627
|
|
|
617
|
-
|
|
618
|
-
//#region package.json
|
|
628
|
+
// package.json
|
|
619
629
|
var name = "@univerjs/sheets-note";
|
|
620
|
-
var version = "1.
|
|
630
|
+
var version = "1.5.0";
|
|
621
631
|
|
|
622
|
-
|
|
623
|
-
//#region src/config/config.ts
|
|
632
|
+
// src/config/config.ts
|
|
624
633
|
/**
|
|
625
634
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
626
635
|
*
|
|
@@ -640,8 +649,7 @@ const SHEETS_NOTE_PLUGIN_CONFIG_KEY = "sheets-note.config";
|
|
|
640
649
|
const configSymbol = Symbol(SHEETS_NOTE_PLUGIN_CONFIG_KEY);
|
|
641
650
|
const defaultPluginConfig = {};
|
|
642
651
|
|
|
643
|
-
|
|
644
|
-
//#region src/controllers/sheets-note-ref-range.controller.ts
|
|
652
|
+
// src/controllers/sheets-note-ref-range.controller.ts
|
|
645
653
|
let SheetsNoteRefRangeController = class SheetsNoteRefRangeController extends _univerjs_core.Disposable {
|
|
646
654
|
constructor(_refRangeService, _sheetsNoteModel, _selectionManagerService, _commandService) {
|
|
647
655
|
super();
|
|
@@ -798,8 +806,7 @@ SheetsNoteRefRangeController = __decorate([
|
|
|
798
806
|
__decorateParam(3, _univerjs_core.ICommandService)
|
|
799
807
|
], SheetsNoteRefRangeController);
|
|
800
808
|
|
|
801
|
-
|
|
802
|
-
//#region src/controllers/sheets.note.controller.ts
|
|
809
|
+
// src/controllers/sheets.note.controller.ts
|
|
803
810
|
/**
|
|
804
811
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
805
812
|
*
|
|
@@ -837,8 +844,7 @@ let SheetsNoteController = class SheetsNoteController extends _univerjs_core.Dis
|
|
|
837
844
|
};
|
|
838
845
|
SheetsNoteController = __decorate([__decorateParam(0, _univerjs_core.ICommandService)], SheetsNoteController);
|
|
839
846
|
|
|
840
|
-
|
|
841
|
-
//#region src/plugin.ts
|
|
847
|
+
// src/plugin.ts
|
|
842
848
|
let UniverSheetsNotePlugin = class UniverSheetsNotePlugin extends _univerjs_core.Plugin {
|
|
843
849
|
constructor(_config = defaultPluginConfig, _configService, _injector) {
|
|
844
850
|
super();
|
|
@@ -877,7 +883,6 @@ UniverSheetsNotePlugin = __decorate([
|
|
|
877
883
|
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
|
|
878
884
|
], UniverSheetsNotePlugin);
|
|
879
885
|
|
|
880
|
-
//#endregion
|
|
881
886
|
exports.RemoveNoteMutation = RemoveNoteMutation;
|
|
882
887
|
exports.SheetDeleteNoteCommand = SheetDeleteNoteCommand;
|
|
883
888
|
exports.SheetToggleNotePopupCommand = SheetToggleNotePopupCommand;
|
package/lib/es/facade.js
CHANGED
|
@@ -4,7 +4,7 @@ import { FRange, FWorksheet } from "@univerjs/sheets/facade";
|
|
|
4
4
|
import { CanceledError, ICommandService } from "@univerjs/core";
|
|
5
5
|
import { SheetsSelectionsService } from "@univerjs/sheets";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/facade/f-event.ts
|
|
8
8
|
/**
|
|
9
9
|
* @ignore
|
|
10
10
|
*/
|
|
@@ -42,8 +42,7 @@ var FSheetsNoteEventNameMixin = class extends FEventName {
|
|
|
42
42
|
};
|
|
43
43
|
FEventName.extend(FSheetsNoteEventNameMixin);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
//#region src/facade/f-range.ts
|
|
45
|
+
// src/facade/f-range.ts
|
|
47
46
|
var FRangeSheetsNoteMixin = class extends FRange {
|
|
48
47
|
createOrUpdateNote(note) {
|
|
49
48
|
this._commandService.syncExecuteCommand(UpdateNoteMutation.id, {
|
|
@@ -73,8 +72,7 @@ var FRangeSheetsNoteMixin = class extends FRange {
|
|
|
73
72
|
};
|
|
74
73
|
FRange.extend(FRangeSheetsNoteMixin);
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
//#region src/facade/f-univer.ts
|
|
75
|
+
// src/facade/f-univer.ts
|
|
78
76
|
var FUniverSheetsNoteMixin = class extends FUniver {
|
|
79
77
|
_initialize(injector) {
|
|
80
78
|
const commandService = injector.get(ICommandService);
|
|
@@ -298,8 +296,7 @@ var FUniverSheetsNoteMixin = class extends FUniver {
|
|
|
298
296
|
};
|
|
299
297
|
FUniver.extend(FUniverSheetsNoteMixin);
|
|
300
298
|
|
|
301
|
-
|
|
302
|
-
//#region src/facade/f-worksheet.ts
|
|
299
|
+
// src/facade/f-worksheet.ts
|
|
303
300
|
var FWorksheetNoteMixin = class extends FWorksheet {
|
|
304
301
|
getNotes() {
|
|
305
302
|
const notes = this._injector.get(SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(), this.getSheetId());
|
|
@@ -309,5 +306,4 @@ var FWorksheetNoteMixin = class extends FWorksheet {
|
|
|
309
306
|
};
|
|
310
307
|
FWorksheet.extend(FWorksheetNoteMixin);
|
|
311
308
|
|
|
312
|
-
//#endregion
|
|
313
309
|
export { FRangeSheetsNoteMixin, FSheetsNoteEventNameMixin, FUniverSheetsNoteMixin, FWorksheetNoteMixin };
|
package/lib/es/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CommandType, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, generateRandomId, merge, sequenceExecuteAsync, touchDependencies } from "@univerjs/core";
|
|
1
|
+
import { CommandType, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, UniverInstanceType, generateRandomId, merge, sequenceExecuteAsync, touchDependencies } from "@univerjs/core";
|
|
2
2
|
import { CopySheetCommand, RefRangeService, RemoveSheetCommand, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, getSheetCommandTarget, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests } from "@univerjs/sheets";
|
|
3
3
|
import { Subject, filter, map } from "rxjs";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
6
6
|
function _typeof(o) {
|
|
7
7
|
"@babel/helpers - typeof";
|
|
8
8
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -12,28 +12,25 @@ function _typeof(o) {
|
|
|
12
12
|
}, _typeof(o);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function toPrimitive(t, r) {
|
|
15
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
16
|
+
function toPrimitive(t, e) {
|
|
18
17
|
if ("object" != _typeof(t) || !t) return t;
|
|
19
|
-
var
|
|
20
|
-
if (void 0 !==
|
|
21
|
-
var i =
|
|
18
|
+
var r;
|
|
19
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
20
|
+
var i = r.call(t, e || "default");
|
|
22
21
|
if ("object" != _typeof(i)) return i;
|
|
23
22
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
24
23
|
}
|
|
25
|
-
return ("string" ===
|
|
24
|
+
return ("string" === e ? String : Number)(t);
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
27
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
30
28
|
function toPropertyKey(t) {
|
|
31
29
|
var i = toPrimitive(t, "string");
|
|
32
30
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
33
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
37
34
|
function _defineProperty(e, r, t) {
|
|
38
35
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
39
36
|
value: t,
|
|
@@ -43,15 +40,21 @@ function _defineProperty(e, r, t) {
|
|
|
43
40
|
}) : e[r] = t, e;
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
//#region src/models/sheets-note.model.ts
|
|
43
|
+
// src/models/sheets-note.model.ts
|
|
48
44
|
var SheetsNoteModel = class extends Disposable {
|
|
49
45
|
constructor(..._args) {
|
|
50
46
|
super(..._args);
|
|
51
47
|
_defineProperty(this, "_notesMap", /* @__PURE__ */ new Map());
|
|
48
|
+
_defineProperty(this, "_notePositionCache", /* @__PURE__ */ new WeakMap());
|
|
52
49
|
_defineProperty(this, "_change$", new Subject());
|
|
53
50
|
_defineProperty(this, "change$", this._change$.asObservable());
|
|
54
51
|
}
|
|
52
|
+
dispose() {
|
|
53
|
+
this._notePositionCache = /* @__PURE__ */ new WeakMap();
|
|
54
|
+
this._notesMap.clear();
|
|
55
|
+
this._change$.complete();
|
|
56
|
+
super.dispose();
|
|
57
|
+
}
|
|
55
58
|
_ensureNotesMap(unitId, subUnitId) {
|
|
56
59
|
let unitMap = this._notesMap.get(unitId);
|
|
57
60
|
if (!unitMap) {
|
|
@@ -67,7 +70,14 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
67
70
|
}
|
|
68
71
|
_getNoteByPosition(unitId, subUnitId, row, col) {
|
|
69
72
|
const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
|
|
70
|
-
|
|
73
|
+
let positions = this._notePositionCache.get(subUnitMap);
|
|
74
|
+
if (!positions) {
|
|
75
|
+
positions = new ObjectMatrix();
|
|
76
|
+
for (const note of subUnitMap.values()) if (!positions.getValue(note.row, note.col)) positions.setValue(note.row, note.col, note);
|
|
77
|
+
this._notePositionCache.set(subUnitMap, positions);
|
|
78
|
+
}
|
|
79
|
+
const note = positions.getValue(row, col);
|
|
80
|
+
return (note === null || note === void 0 ? void 0 : note.row) === row && note.col === col ? note : void 0;
|
|
71
81
|
}
|
|
72
82
|
_getNoteById(unitId, subUnitId, id) {
|
|
73
83
|
return this._ensureNotesMap(unitId, subUnitId).get(id);
|
|
@@ -114,6 +124,7 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
114
124
|
col
|
|
115
125
|
};
|
|
116
126
|
subUnitMap.set(newNote.id, newNote);
|
|
127
|
+
this._notePositionCache.delete(subUnitMap);
|
|
117
128
|
this._change$.next({
|
|
118
129
|
unitId,
|
|
119
130
|
subUnitId,
|
|
@@ -131,7 +142,9 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
131
142
|
col
|
|
132
143
|
});
|
|
133
144
|
if (!oldNote) return;
|
|
134
|
-
this._ensureNotesMap(unitId, subUnitId)
|
|
145
|
+
const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
|
|
146
|
+
subUnitMap.delete(oldNote.id);
|
|
147
|
+
this._notePositionCache.delete(subUnitMap);
|
|
135
148
|
this._change$.next({
|
|
136
149
|
unitId,
|
|
137
150
|
subUnitId,
|
|
@@ -155,6 +168,7 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
155
168
|
show: !oldNote.show
|
|
156
169
|
};
|
|
157
170
|
subUnitMap.set(newNote.id, newNote);
|
|
171
|
+
this._notePositionCache.delete(subUnitMap);
|
|
158
172
|
this._change$.next({
|
|
159
173
|
unitId,
|
|
160
174
|
subUnitId,
|
|
@@ -179,6 +193,7 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
179
193
|
col: newCol
|
|
180
194
|
};
|
|
181
195
|
subUnitMap.set(newNote.id, newNote);
|
|
196
|
+
this._notePositionCache.delete(subUnitMap);
|
|
182
197
|
this._change$.next({
|
|
183
198
|
unitId,
|
|
184
199
|
subUnitId,
|
|
@@ -203,12 +218,13 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
203
218
|
return unitMap.get(subUnitId);
|
|
204
219
|
}
|
|
205
220
|
deleteUnitNotes(unitId) {
|
|
221
|
+
var _this$_notesMap$get;
|
|
222
|
+
(_this$_notesMap$get = this._notesMap.get(unitId)) === null || _this$_notesMap$get === void 0 || _this$_notesMap$get.forEach((notes) => this._notePositionCache.delete(notes));
|
|
206
223
|
this._notesMap.delete(unitId);
|
|
207
224
|
}
|
|
208
225
|
};
|
|
209
226
|
|
|
210
|
-
|
|
211
|
-
//#region src/commands/mutations/note.mutation.ts
|
|
227
|
+
// src/commands/mutations/note.mutation.ts
|
|
212
228
|
const UpdateNoteMutation = {
|
|
213
229
|
id: "sheet.mutation.update-note",
|
|
214
230
|
type: CommandType.MUTATION,
|
|
@@ -263,8 +279,7 @@ const UpdateNotePositionMutation = {
|
|
|
263
279
|
}
|
|
264
280
|
};
|
|
265
281
|
|
|
266
|
-
|
|
267
|
-
//#region src/commands/commands/note.command.ts
|
|
282
|
+
// src/commands/commands/note.command.ts
|
|
268
283
|
const SheetDeleteNoteCommand = {
|
|
269
284
|
id: "sheet.command.delete-note",
|
|
270
285
|
type: CommandType.COMMAND,
|
|
@@ -420,8 +435,7 @@ const SheetUpdateNoteCommand = {
|
|
|
420
435
|
}
|
|
421
436
|
};
|
|
422
437
|
|
|
423
|
-
|
|
424
|
-
//#region src/const.ts
|
|
438
|
+
// src/const.ts
|
|
425
439
|
/**
|
|
426
440
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
427
441
|
*
|
|
@@ -439,16 +453,14 @@ const SheetUpdateNoteCommand = {
|
|
|
439
453
|
*/
|
|
440
454
|
const PLUGIN_NAME = "SHEET_NOTE_PLUGIN";
|
|
441
455
|
|
|
442
|
-
|
|
443
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
456
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
444
457
|
function __decorateParam(paramIndex, decorator) {
|
|
445
458
|
return function(target, key) {
|
|
446
459
|
decorator(target, key, paramIndex);
|
|
447
460
|
};
|
|
448
461
|
}
|
|
449
462
|
|
|
450
|
-
|
|
451
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
463
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
452
464
|
function __decorate(decorators, target, key, desc) {
|
|
453
465
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
454
466
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -456,8 +468,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
456
468
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
457
469
|
}
|
|
458
470
|
|
|
459
|
-
|
|
460
|
-
//#region src/controllers/sheets-note-resource.controller.ts
|
|
471
|
+
// src/controllers/sheets-note-resource.controller.ts
|
|
461
472
|
let SheetsNoteResourceController = class SheetsNoteResourceController extends Disposable {
|
|
462
473
|
constructor(_resourceManagerService, _univerInstanceService, _sheetInterceptorService, _sheetsNoteModel) {
|
|
463
474
|
super();
|
|
@@ -613,13 +624,11 @@ SheetsNoteResourceController = __decorate([
|
|
|
613
624
|
__decorateParam(3, Inject(SheetsNoteModel))
|
|
614
625
|
], SheetsNoteResourceController);
|
|
615
626
|
|
|
616
|
-
|
|
617
|
-
//#region package.json
|
|
627
|
+
// package.json
|
|
618
628
|
var name = "@univerjs/sheets-note";
|
|
619
|
-
var version = "1.
|
|
629
|
+
var version = "1.5.0";
|
|
620
630
|
|
|
621
|
-
|
|
622
|
-
//#region src/config/config.ts
|
|
631
|
+
// src/config/config.ts
|
|
623
632
|
/**
|
|
624
633
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
625
634
|
*
|
|
@@ -639,8 +648,7 @@ const SHEETS_NOTE_PLUGIN_CONFIG_KEY = "sheets-note.config";
|
|
|
639
648
|
const configSymbol = Symbol(SHEETS_NOTE_PLUGIN_CONFIG_KEY);
|
|
640
649
|
const defaultPluginConfig = {};
|
|
641
650
|
|
|
642
|
-
|
|
643
|
-
//#region src/controllers/sheets-note-ref-range.controller.ts
|
|
651
|
+
// src/controllers/sheets-note-ref-range.controller.ts
|
|
644
652
|
let SheetsNoteRefRangeController = class SheetsNoteRefRangeController extends Disposable {
|
|
645
653
|
constructor(_refRangeService, _sheetsNoteModel, _selectionManagerService, _commandService) {
|
|
646
654
|
super();
|
|
@@ -797,8 +805,7 @@ SheetsNoteRefRangeController = __decorate([
|
|
|
797
805
|
__decorateParam(3, ICommandService)
|
|
798
806
|
], SheetsNoteRefRangeController);
|
|
799
807
|
|
|
800
|
-
|
|
801
|
-
//#region src/controllers/sheets.note.controller.ts
|
|
808
|
+
// src/controllers/sheets.note.controller.ts
|
|
802
809
|
/**
|
|
803
810
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
804
811
|
*
|
|
@@ -836,8 +843,7 @@ let SheetsNoteController = class SheetsNoteController extends Disposable {
|
|
|
836
843
|
};
|
|
837
844
|
SheetsNoteController = __decorate([__decorateParam(0, ICommandService)], SheetsNoteController);
|
|
838
845
|
|
|
839
|
-
|
|
840
|
-
//#region src/plugin.ts
|
|
846
|
+
// src/plugin.ts
|
|
841
847
|
let UniverSheetsNotePlugin = class UniverSheetsNotePlugin extends Plugin {
|
|
842
848
|
constructor(_config = defaultPluginConfig, _configService, _injector) {
|
|
843
849
|
super();
|
|
@@ -876,5 +882,4 @@ UniverSheetsNotePlugin = __decorate([
|
|
|
876
882
|
__decorateParam(2, Inject(Injector))
|
|
877
883
|
], UniverSheetsNotePlugin);
|
|
878
884
|
|
|
879
|
-
//#endregion
|
|
880
885
|
export { RemoveNoteMutation, SheetDeleteNoteCommand, SheetToggleNotePopupCommand, SheetUpdateNoteCommand, SheetsNoteModel, SheetsNoteResourceController, ToggleNotePopupMutation, UniverSheetsNotePlugin, UpdateNoteMutation, UpdateNotePositionMutation };
|
package/lib/facade.js
CHANGED
|
@@ -4,7 +4,7 @@ import { FRange, FWorksheet } from "@univerjs/sheets/facade";
|
|
|
4
4
|
import { CanceledError, ICommandService } from "@univerjs/core";
|
|
5
5
|
import { SheetsSelectionsService } from "@univerjs/sheets";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/facade/f-event.ts
|
|
8
8
|
/**
|
|
9
9
|
* @ignore
|
|
10
10
|
*/
|
|
@@ -42,8 +42,7 @@ var FSheetsNoteEventNameMixin = class extends FEventName {
|
|
|
42
42
|
};
|
|
43
43
|
FEventName.extend(FSheetsNoteEventNameMixin);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
//#region src/facade/f-range.ts
|
|
45
|
+
// src/facade/f-range.ts
|
|
47
46
|
var FRangeSheetsNoteMixin = class extends FRange {
|
|
48
47
|
createOrUpdateNote(note) {
|
|
49
48
|
this._commandService.syncExecuteCommand(UpdateNoteMutation.id, {
|
|
@@ -73,8 +72,7 @@ var FRangeSheetsNoteMixin = class extends FRange {
|
|
|
73
72
|
};
|
|
74
73
|
FRange.extend(FRangeSheetsNoteMixin);
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
//#region src/facade/f-univer.ts
|
|
75
|
+
// src/facade/f-univer.ts
|
|
78
76
|
var FUniverSheetsNoteMixin = class extends FUniver {
|
|
79
77
|
_initialize(injector) {
|
|
80
78
|
const commandService = injector.get(ICommandService);
|
|
@@ -298,8 +296,7 @@ var FUniverSheetsNoteMixin = class extends FUniver {
|
|
|
298
296
|
};
|
|
299
297
|
FUniver.extend(FUniverSheetsNoteMixin);
|
|
300
298
|
|
|
301
|
-
|
|
302
|
-
//#region src/facade/f-worksheet.ts
|
|
299
|
+
// src/facade/f-worksheet.ts
|
|
303
300
|
var FWorksheetNoteMixin = class extends FWorksheet {
|
|
304
301
|
getNotes() {
|
|
305
302
|
const notes = this._injector.get(SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(), this.getSheetId());
|
|
@@ -309,5 +306,4 @@ var FWorksheetNoteMixin = class extends FWorksheet {
|
|
|
309
306
|
};
|
|
310
307
|
FWorksheet.extend(FWorksheetNoteMixin);
|
|
311
308
|
|
|
312
|
-
//#endregion
|
|
313
309
|
export { FRangeSheetsNoteMixin, FSheetsNoteEventNameMixin, FUniverSheetsNoteMixin, FWorksheetNoteMixin };
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CommandType, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, generateRandomId, merge, sequenceExecuteAsync, touchDependencies } from "@univerjs/core";
|
|
1
|
+
import { CommandType, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, UniverInstanceType, generateRandomId, merge, sequenceExecuteAsync, touchDependencies } from "@univerjs/core";
|
|
2
2
|
import { CopySheetCommand, RefRangeService, RemoveSheetCommand, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, getSheetCommandTarget, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests } from "@univerjs/sheets";
|
|
3
3
|
import { Subject, filter, map } from "rxjs";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
6
6
|
function _typeof(o) {
|
|
7
7
|
"@babel/helpers - typeof";
|
|
8
8
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -12,28 +12,25 @@ function _typeof(o) {
|
|
|
12
12
|
}, _typeof(o);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function toPrimitive(t, r) {
|
|
15
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
16
|
+
function toPrimitive(t, e) {
|
|
18
17
|
if ("object" != _typeof(t) || !t) return t;
|
|
19
|
-
var
|
|
20
|
-
if (void 0 !==
|
|
21
|
-
var i =
|
|
18
|
+
var r;
|
|
19
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
20
|
+
var i = r.call(t, e || "default");
|
|
22
21
|
if ("object" != _typeof(i)) return i;
|
|
23
22
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
24
23
|
}
|
|
25
|
-
return ("string" ===
|
|
24
|
+
return ("string" === e ? String : Number)(t);
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
27
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
30
28
|
function toPropertyKey(t) {
|
|
31
29
|
var i = toPrimitive(t, "string");
|
|
32
30
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
33
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
37
34
|
function _defineProperty(e, r, t) {
|
|
38
35
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
39
36
|
value: t,
|
|
@@ -43,15 +40,21 @@ function _defineProperty(e, r, t) {
|
|
|
43
40
|
}) : e[r] = t, e;
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
//#region src/models/sheets-note.model.ts
|
|
43
|
+
// src/models/sheets-note.model.ts
|
|
48
44
|
var SheetsNoteModel = class extends Disposable {
|
|
49
45
|
constructor(..._args) {
|
|
50
46
|
super(..._args);
|
|
51
47
|
_defineProperty(this, "_notesMap", /* @__PURE__ */ new Map());
|
|
48
|
+
_defineProperty(this, "_notePositionCache", /* @__PURE__ */ new WeakMap());
|
|
52
49
|
_defineProperty(this, "_change$", new Subject());
|
|
53
50
|
_defineProperty(this, "change$", this._change$.asObservable());
|
|
54
51
|
}
|
|
52
|
+
dispose() {
|
|
53
|
+
this._notePositionCache = /* @__PURE__ */ new WeakMap();
|
|
54
|
+
this._notesMap.clear();
|
|
55
|
+
this._change$.complete();
|
|
56
|
+
super.dispose();
|
|
57
|
+
}
|
|
55
58
|
_ensureNotesMap(unitId, subUnitId) {
|
|
56
59
|
let unitMap = this._notesMap.get(unitId);
|
|
57
60
|
if (!unitMap) {
|
|
@@ -67,7 +70,14 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
67
70
|
}
|
|
68
71
|
_getNoteByPosition(unitId, subUnitId, row, col) {
|
|
69
72
|
const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
|
|
70
|
-
|
|
73
|
+
let positions = this._notePositionCache.get(subUnitMap);
|
|
74
|
+
if (!positions) {
|
|
75
|
+
positions = new ObjectMatrix();
|
|
76
|
+
for (const note of subUnitMap.values()) if (!positions.getValue(note.row, note.col)) positions.setValue(note.row, note.col, note);
|
|
77
|
+
this._notePositionCache.set(subUnitMap, positions);
|
|
78
|
+
}
|
|
79
|
+
const note = positions.getValue(row, col);
|
|
80
|
+
return (note === null || note === void 0 ? void 0 : note.row) === row && note.col === col ? note : void 0;
|
|
71
81
|
}
|
|
72
82
|
_getNoteById(unitId, subUnitId, id) {
|
|
73
83
|
return this._ensureNotesMap(unitId, subUnitId).get(id);
|
|
@@ -114,6 +124,7 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
114
124
|
col
|
|
115
125
|
};
|
|
116
126
|
subUnitMap.set(newNote.id, newNote);
|
|
127
|
+
this._notePositionCache.delete(subUnitMap);
|
|
117
128
|
this._change$.next({
|
|
118
129
|
unitId,
|
|
119
130
|
subUnitId,
|
|
@@ -131,7 +142,9 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
131
142
|
col
|
|
132
143
|
});
|
|
133
144
|
if (!oldNote) return;
|
|
134
|
-
this._ensureNotesMap(unitId, subUnitId)
|
|
145
|
+
const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
|
|
146
|
+
subUnitMap.delete(oldNote.id);
|
|
147
|
+
this._notePositionCache.delete(subUnitMap);
|
|
135
148
|
this._change$.next({
|
|
136
149
|
unitId,
|
|
137
150
|
subUnitId,
|
|
@@ -155,6 +168,7 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
155
168
|
show: !oldNote.show
|
|
156
169
|
};
|
|
157
170
|
subUnitMap.set(newNote.id, newNote);
|
|
171
|
+
this._notePositionCache.delete(subUnitMap);
|
|
158
172
|
this._change$.next({
|
|
159
173
|
unitId,
|
|
160
174
|
subUnitId,
|
|
@@ -179,6 +193,7 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
179
193
|
col: newCol
|
|
180
194
|
};
|
|
181
195
|
subUnitMap.set(newNote.id, newNote);
|
|
196
|
+
this._notePositionCache.delete(subUnitMap);
|
|
182
197
|
this._change$.next({
|
|
183
198
|
unitId,
|
|
184
199
|
subUnitId,
|
|
@@ -203,12 +218,13 @@ var SheetsNoteModel = class extends Disposable {
|
|
|
203
218
|
return unitMap.get(subUnitId);
|
|
204
219
|
}
|
|
205
220
|
deleteUnitNotes(unitId) {
|
|
221
|
+
var _this$_notesMap$get;
|
|
222
|
+
(_this$_notesMap$get = this._notesMap.get(unitId)) === null || _this$_notesMap$get === void 0 || _this$_notesMap$get.forEach((notes) => this._notePositionCache.delete(notes));
|
|
206
223
|
this._notesMap.delete(unitId);
|
|
207
224
|
}
|
|
208
225
|
};
|
|
209
226
|
|
|
210
|
-
|
|
211
|
-
//#region src/commands/mutations/note.mutation.ts
|
|
227
|
+
// src/commands/mutations/note.mutation.ts
|
|
212
228
|
const UpdateNoteMutation = {
|
|
213
229
|
id: "sheet.mutation.update-note",
|
|
214
230
|
type: CommandType.MUTATION,
|
|
@@ -263,8 +279,7 @@ const UpdateNotePositionMutation = {
|
|
|
263
279
|
}
|
|
264
280
|
};
|
|
265
281
|
|
|
266
|
-
|
|
267
|
-
//#region src/commands/commands/note.command.ts
|
|
282
|
+
// src/commands/commands/note.command.ts
|
|
268
283
|
const SheetDeleteNoteCommand = {
|
|
269
284
|
id: "sheet.command.delete-note",
|
|
270
285
|
type: CommandType.COMMAND,
|
|
@@ -420,8 +435,7 @@ const SheetUpdateNoteCommand = {
|
|
|
420
435
|
}
|
|
421
436
|
};
|
|
422
437
|
|
|
423
|
-
|
|
424
|
-
//#region src/const.ts
|
|
438
|
+
// src/const.ts
|
|
425
439
|
/**
|
|
426
440
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
427
441
|
*
|
|
@@ -439,16 +453,14 @@ const SheetUpdateNoteCommand = {
|
|
|
439
453
|
*/
|
|
440
454
|
const PLUGIN_NAME = "SHEET_NOTE_PLUGIN";
|
|
441
455
|
|
|
442
|
-
|
|
443
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
456
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
444
457
|
function __decorateParam(paramIndex, decorator) {
|
|
445
458
|
return function(target, key) {
|
|
446
459
|
decorator(target, key, paramIndex);
|
|
447
460
|
};
|
|
448
461
|
}
|
|
449
462
|
|
|
450
|
-
|
|
451
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
463
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
452
464
|
function __decorate(decorators, target, key, desc) {
|
|
453
465
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
454
466
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -456,8 +468,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
456
468
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
457
469
|
}
|
|
458
470
|
|
|
459
|
-
|
|
460
|
-
//#region src/controllers/sheets-note-resource.controller.ts
|
|
471
|
+
// src/controllers/sheets-note-resource.controller.ts
|
|
461
472
|
let SheetsNoteResourceController = class SheetsNoteResourceController extends Disposable {
|
|
462
473
|
constructor(_resourceManagerService, _univerInstanceService, _sheetInterceptorService, _sheetsNoteModel) {
|
|
463
474
|
super();
|
|
@@ -613,13 +624,11 @@ SheetsNoteResourceController = __decorate([
|
|
|
613
624
|
__decorateParam(3, Inject(SheetsNoteModel))
|
|
614
625
|
], SheetsNoteResourceController);
|
|
615
626
|
|
|
616
|
-
|
|
617
|
-
//#region package.json
|
|
627
|
+
// package.json
|
|
618
628
|
var name = "@univerjs/sheets-note";
|
|
619
|
-
var version = "1.
|
|
629
|
+
var version = "1.5.0";
|
|
620
630
|
|
|
621
|
-
|
|
622
|
-
//#region src/config/config.ts
|
|
631
|
+
// src/config/config.ts
|
|
623
632
|
/**
|
|
624
633
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
625
634
|
*
|
|
@@ -639,8 +648,7 @@ const SHEETS_NOTE_PLUGIN_CONFIG_KEY = "sheets-note.config";
|
|
|
639
648
|
const configSymbol = Symbol(SHEETS_NOTE_PLUGIN_CONFIG_KEY);
|
|
640
649
|
const defaultPluginConfig = {};
|
|
641
650
|
|
|
642
|
-
|
|
643
|
-
//#region src/controllers/sheets-note-ref-range.controller.ts
|
|
651
|
+
// src/controllers/sheets-note-ref-range.controller.ts
|
|
644
652
|
let SheetsNoteRefRangeController = class SheetsNoteRefRangeController extends Disposable {
|
|
645
653
|
constructor(_refRangeService, _sheetsNoteModel, _selectionManagerService, _commandService) {
|
|
646
654
|
super();
|
|
@@ -797,8 +805,7 @@ SheetsNoteRefRangeController = __decorate([
|
|
|
797
805
|
__decorateParam(3, ICommandService)
|
|
798
806
|
], SheetsNoteRefRangeController);
|
|
799
807
|
|
|
800
|
-
|
|
801
|
-
//#region src/controllers/sheets.note.controller.ts
|
|
808
|
+
// src/controllers/sheets.note.controller.ts
|
|
802
809
|
/**
|
|
803
810
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
804
811
|
*
|
|
@@ -836,8 +843,7 @@ let SheetsNoteController = class SheetsNoteController extends Disposable {
|
|
|
836
843
|
};
|
|
837
844
|
SheetsNoteController = __decorate([__decorateParam(0, ICommandService)], SheetsNoteController);
|
|
838
845
|
|
|
839
|
-
|
|
840
|
-
//#region src/plugin.ts
|
|
846
|
+
// src/plugin.ts
|
|
841
847
|
let UniverSheetsNotePlugin = class UniverSheetsNotePlugin extends Plugin {
|
|
842
848
|
constructor(_config = defaultPluginConfig, _configService, _injector) {
|
|
843
849
|
super();
|
|
@@ -876,5 +882,4 @@ UniverSheetsNotePlugin = __decorate([
|
|
|
876
882
|
__decorateParam(2, Inject(Injector))
|
|
877
883
|
], UniverSheetsNotePlugin);
|
|
878
884
|
|
|
879
|
-
//#endregion
|
|
880
885
|
export { RemoveNoteMutation, SheetDeleteNoteCommand, SheetToggleNotePopupCommand, SheetUpdateNoteCommand, SheetsNoteModel, SheetsNoteResourceController, ToggleNotePopupMutation, UniverSheetsNotePlugin, UpdateNoteMutation, UpdateNotePositionMutation };
|
|
@@ -39,8 +39,10 @@ export type ISheetNoteChange = {
|
|
|
39
39
|
});
|
|
40
40
|
export declare class SheetsNoteModel extends Disposable {
|
|
41
41
|
private _notesMap;
|
|
42
|
+
private _notePositionCache;
|
|
42
43
|
private readonly _change$;
|
|
43
44
|
readonly change$: import("rxjs").Observable<ISheetNoteChange>;
|
|
45
|
+
dispose(): void;
|
|
44
46
|
private _ensureNotesMap;
|
|
45
47
|
private _getNoteByPosition;
|
|
46
48
|
private _getNoteById;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNote={},e.UniverCore,e.UniverSheets,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e){"@babel/helpers - typeof";return i=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},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=class extends t.Disposable{constructor(...e){super(...e),s(this,`_notesMap`,/* @__PURE__ */ new Map),s(this,`_change$`,new r.Subject),s(this,`change$`,this._change$.asObservable())}_ensureNotesMap(e,t){let n=this._notesMap.get(e);n||(n=/* @__PURE__ */ new Map,this._notesMap.set(e,n));let r=n.get(t);return r||(r=/* @__PURE__ */ 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((0,r.filter)(({unitId:n,subUnitId:r})=>n===e&&r===t),(0,r.map)(()=>{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,i){return this._change$.pipe((0,r.filter)(({unitId:r,subUnitId:a,oldNote:o})=>r!==e||a!==t||!o?!1:o.row===n&&o.col===i),(0,r.map)(e=>e))}updateNote(e,n,r,i,a,o){let s=this._getNoteByParams(e,n,{noteId:a==null?void 0:a.id,row:r,col:i}),c=this._ensureNotesMap(e,n),l={...a,id:(s==null?void 0:s.id)||a.id||(0,t.generateRandomId)(6),row:r,col:i};c.set(l.id,l),this._change$.next({unitId:e,subUnitId:n,oldNote:s,type:`update`,newNote:l,silent:o})}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)}};let l={id:`sheet.mutation.update-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(c).updateNote(n,r,i,a,o,s),!0}},u={id:`sheet.mutation.remove-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},d={id:`sheet.mutation.toggle-note-popup`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},f={id:`sheet.mutation.update-note-position`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:l}=t;return e.get(c).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:l}),!0}},p={id:`sheet.command.delete-note`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:d,actualRow:f}=i.primary,p=a.getNote(o,s,{row:f,col:d});if(!p)return!1;let m=e.get(t.ICommandService),h=e.get(t.IUndoRedoService),g={id:u.id,params:{unitId:o,sheetId:s,noteId:p.id}},_={id:l.id,params:{unitId:o,sheetId:s,row:f,col:d,note:{...p}}};return m.syncExecuteCommand(g.id,g.params)?(h.pushUndoRedo({unitID:o,redoMutations:[g],undoMutations:[_]}),!0):!1}},m={id:`sheet.command.toggle-note-popup`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:l,actualRow:u}=i.primary,f=a.getNote(o,s,{row:u,col:l});if(!f)return!1;let p=e.get(t.ICommandService),m=e.get(t.IUndoRedoService),h={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}},g={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}};return p.syncExecuteCommand(h.id,h.params)?(m.pushUndoRedo({unitID:o,redoMutations:[h],undoMutations:[g]}),!0):!1}},h={id:`sheet.command.update-note`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(c),{unitId:d,subUnitId:f}=i,{row:p,col:m,note:h}=r,g=s.getNote(d,f,{noteId:h.id,row:p,col:m}),_={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:h}},v=[];if(g){let e={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:{...g}}};v.push(e)}else{let e={id:u.id,params:{unitId:d,sheetId:f,row:p,col:m}};v.push(e)}return a.syncExecuteCommand(_.id,_.params)?(o.pushUndoRedo({unitID:d,redoMutations:[_],undoMutations:v}),!0):!1}},g=`SHEET_NOTE_PLUGIN`;function _(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 y=class extends t.Disposable{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)},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:g,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>n(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===n.RemoveSheetCommand.id){var r;let n=e.params,i=n.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=n.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetsNoteModel.getSheetNotes(i,a);if(!o)return{redos:[],undos:[]};let s=[],c=[];return o.forEach(e=>{s.push({id:u.id,params:{unitId:i,sheetId:a,noteId:e.id,row:e.row,col:e.col}}),c.push({id:l.id,params:{unitId:i,sheetId:a,row:e.row,col:e.col,note:e}})}),{redos:s,undos:c}}if(e.id===n.CopySheetCommand.id){let{unitId:n,subUnitId:r,targetSubUnitId:i}=e.params;if(!n||!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(n,r);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{let r={...e,id:(0,t.generateRandomId)(6)};o.push({id:l.id,params:{unitId:n,sheetId:i,row:r.row,col:r.col,note:r}}),s.push({id:u.id,params:{unitId:n,sheetId:i,noteId:r.id,row:r.row,col:r.col}})}),{redos:o,undos:s}}return{redos:[],undos:[]}}}))}};y=v([_(0,t.IResourceManagerService),_(1,t.IUniverInstanceService),_(2,(0,t.Inject)(n.SheetInterceptorService)),_(3,(0,t.Inject)(c))],y);var b=`@univerjs/sheets-note`,x=`1.3.1`;let S={},C=class extends t.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,s(this,`_disposableMap`,/* @__PURE__ */ new Map),s(this,`_watcherMap`,/* @__PURE__ */ new Map),s(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:u.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:l.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,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._disposableMap.set(this._getIdWithUnitId(e,t,i,a),this._refRangeService.registerRefRange(o,s=>{let c=(0,n.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(o,s,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===o.startColumn&&l.startRow===o.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,r,i,a,l,!1)},e,t))}_watch(e,n,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._watcherMap.set(this._getIdWithUnitId(e,n,i,a),this._refRangeService.watchRange(e,n,o,(i,a)=>{let{redos:o}=this._handleRangeChange(e,n,r,i.startRow,i.startColumn,a,!0);(0,t.sequenceExecuteAsync)(o,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}}}))}};C=v([_(0,(0,t.Inject)(n.RefRangeService)),_(1,(0,t.Inject)(c)),_(2,(0,t.Inject)(n.SheetsSelectionsService)),_(3,t.ICommandService)],C);let w=class extends t.Disposable{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[f,d,l,u,p,m,h].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};w=v([_(0,t.ICommandService)],w);let T=class extends t.Plugin{constructor(e=S,n,r){super(),this._config=e,this._configService=n,this._injector=r;let{...i}=(0,t.merge)({},S,this._config);this._configService.setConfig(`sheets-note.config`,i)}onStarting(){[[c],[w],[y],[C]].forEach(e=>{this._injector.add(e)}),(0,t.touchDependencies)(this._injector,[[c],[w],[y]])}onReady(){(0,t.touchDependencies)(this._injector,[[C]])}};s(T,`pluginName`,g),s(T,`packageName`,b),s(T,`version`,x),s(T,`type`,t.UniverInstanceType.UNIVER_SHEET),T=v([(0,t.DependentOn)(n.UniverSheetsPlugin),_(1,t.IConfigService),_(2,(0,t.Inject)(t.Injector))],T),e.RemoveNoteMutation=u,e.SheetDeleteNoteCommand=p,e.SheetToggleNotePopupCommand=m,e.SheetUpdateNoteCommand=h,e.SheetsNoteModel=c,Object.defineProperty(e,"SheetsNoteResourceController",{enumerable:!0,get:function(){return y}}),e.ToggleNotePopupMutation=d,Object.defineProperty(e,"UniverSheetsNotePlugin",{enumerable:!0,get:function(){return T}}),e.UpdateNoteMutation=l,e.UpdateNotePositionMutation=f});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNote={},e.UniverCore,e.UniverSheets,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e){"@babel/helpers - typeof";return i=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},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=class extends t.Disposable{constructor(...e){super(...e),s(this,`_notesMap`,/* @__PURE__ */ new Map),s(this,`_notePositionCache`,/* @__PURE__ */ new WeakMap),s(this,`_change$`,new r.Subject),s(this,`change$`,this._change$.asObservable())}dispose(){this._notePositionCache=/* @__PURE__ */ new WeakMap,this._notesMap.clear(),this._change$.complete(),super.dispose()}_ensureNotesMap(e,t){let n=this._notesMap.get(e);n||(n=/* @__PURE__ */ new Map,this._notesMap.set(e,n));let r=n.get(t);return r||(r=/* @__PURE__ */ new Map,n.set(t,r)),r}_getNoteByPosition(e,n,r,i){let a=this._ensureNotesMap(e,n),o=this._notePositionCache.get(a);if(!o){o=new t.ObjectMatrix;for(let e of a.values())o.getValue(e.row,e.col)||o.setValue(e.row,e.col,e);this._notePositionCache.set(a,o)}let s=o.getValue(r,i);return(s==null?void 0:s.row)===r&&s.col===i?s:void 0}_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((0,r.filter)(({unitId:n,subUnitId:r})=>n===e&&r===t),(0,r.map)(()=>{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,i){return this._change$.pipe((0,r.filter)(({unitId:r,subUnitId:a,oldNote:o})=>r!==e||a!==t||!o?!1:o.row===n&&o.col===i),(0,r.map)(e=>e))}updateNote(e,n,r,i,a,o){let s=this._getNoteByParams(e,n,{noteId:a==null?void 0:a.id,row:r,col:i}),c=this._ensureNotesMap(e,n),l={...a,id:(s==null?void 0:s.id)||a.id||(0,t.generateRandomId)(6),row:r,col:i};c.set(l.id,l),this._notePositionCache.delete(c),this._change$.next({unitId:e,subUnitId:n,oldNote:s,type:`update`,newNote:l,silent:o})}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});if(!s)return;let c=this._ensureNotesMap(e,t);c.delete(s.id),this._notePositionCache.delete(c),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._notePositionCache.delete(c),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._notePositionCache.delete(u),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){var t;(t=this._notesMap.get(e))==null||t.forEach(e=>this._notePositionCache.delete(e)),this._notesMap.delete(e)}};let l={id:`sheet.mutation.update-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(c).updateNote(n,r,i,a,o,s),!0}},u={id:`sheet.mutation.remove-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},d={id:`sheet.mutation.toggle-note-popup`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},f={id:`sheet.mutation.update-note-position`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:l}=t;return e.get(c).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:l}),!0}},p={id:`sheet.command.delete-note`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:d,actualRow:f}=i.primary,p=a.getNote(o,s,{row:f,col:d});if(!p)return!1;let m=e.get(t.ICommandService),h=e.get(t.IUndoRedoService),g={id:u.id,params:{unitId:o,sheetId:s,noteId:p.id}},_={id:l.id,params:{unitId:o,sheetId:s,row:f,col:d,note:{...p}}};return m.syncExecuteCommand(g.id,g.params)?(h.pushUndoRedo({unitID:o,redoMutations:[g],undoMutations:[_]}),!0):!1}},m={id:`sheet.command.toggle-note-popup`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:l,actualRow:u}=i.primary,f=a.getNote(o,s,{row:u,col:l});if(!f)return!1;let p=e.get(t.ICommandService),m=e.get(t.IUndoRedoService),h={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}},g={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}};return p.syncExecuteCommand(h.id,h.params)?(m.pushUndoRedo({unitID:o,redoMutations:[h],undoMutations:[g]}),!0):!1}},h={id:`sheet.command.update-note`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(c),{unitId:d,subUnitId:f}=i,{row:p,col:m,note:h}=r,g=s.getNote(d,f,{noteId:h.id,row:p,col:m}),_={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:h}},v=[];if(g){let e={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:{...g}}};v.push(e)}else{let e={id:u.id,params:{unitId:d,sheetId:f,row:p,col:m}};v.push(e)}return a.syncExecuteCommand(_.id,_.params)?(o.pushUndoRedo({unitID:d,redoMutations:[_],undoMutations:v}),!0):!1}},g=`SHEET_NOTE_PLUGIN`;function _(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 y=class extends t.Disposable{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)},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:g,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>n(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===n.RemoveSheetCommand.id){var r;let n=e.params,i=n.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=n.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetsNoteModel.getSheetNotes(i,a);if(!o)return{redos:[],undos:[]};let s=[],c=[];return o.forEach(e=>{s.push({id:u.id,params:{unitId:i,sheetId:a,noteId:e.id,row:e.row,col:e.col}}),c.push({id:l.id,params:{unitId:i,sheetId:a,row:e.row,col:e.col,note:e}})}),{redos:s,undos:c}}if(e.id===n.CopySheetCommand.id){let{unitId:n,subUnitId:r,targetSubUnitId:i}=e.params;if(!n||!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(n,r);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{let r={...e,id:(0,t.generateRandomId)(6)};o.push({id:l.id,params:{unitId:n,sheetId:i,row:r.row,col:r.col,note:r}}),s.push({id:u.id,params:{unitId:n,sheetId:i,noteId:r.id,row:r.row,col:r.col}})}),{redos:o,undos:s}}return{redos:[],undos:[]}}}))}};y=v([_(0,t.IResourceManagerService),_(1,t.IUniverInstanceService),_(2,(0,t.Inject)(n.SheetInterceptorService)),_(3,(0,t.Inject)(c))],y);var b=`@univerjs/sheets-note`,x=`1.5.0`;let S={},C=class extends t.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,s(this,`_disposableMap`,/* @__PURE__ */ new Map),s(this,`_watcherMap`,/* @__PURE__ */ new Map),s(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:u.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:l.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,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._disposableMap.set(this._getIdWithUnitId(e,t,i,a),this._refRangeService.registerRefRange(o,s=>{let c=(0,n.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(o,s,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===o.startColumn&&l.startRow===o.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,r,i,a,l,!1)},e,t))}_watch(e,n,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._watcherMap.set(this._getIdWithUnitId(e,n,i,a),this._refRangeService.watchRange(e,n,o,(i,a)=>{let{redos:o}=this._handleRangeChange(e,n,r,i.startRow,i.startColumn,a,!0);(0,t.sequenceExecuteAsync)(o,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}}}))}};C=v([_(0,(0,t.Inject)(n.RefRangeService)),_(1,(0,t.Inject)(c)),_(2,(0,t.Inject)(n.SheetsSelectionsService)),_(3,t.ICommandService)],C);let w=class extends t.Disposable{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[f,d,l,u,p,m,h].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};w=v([_(0,t.ICommandService)],w);let T=class extends t.Plugin{constructor(e=S,n,r){super(),this._config=e,this._configService=n,this._injector=r;let{...i}=(0,t.merge)({},S,this._config);this._configService.setConfig(`sheets-note.config`,i)}onStarting(){[[c],[w],[y],[C]].forEach(e=>{this._injector.add(e)}),(0,t.touchDependencies)(this._injector,[[c],[w],[y]])}onReady(){(0,t.touchDependencies)(this._injector,[[C]])}};s(T,`pluginName`,g),s(T,`packageName`,b),s(T,`version`,x),s(T,`type`,t.UniverInstanceType.UNIVER_SHEET),T=v([(0,t.DependentOn)(n.UniverSheetsPlugin),_(1,t.IConfigService),_(2,(0,t.Inject)(t.Injector))],T),e.RemoveNoteMutation=u,e.SheetDeleteNoteCommand=p,e.SheetToggleNotePopupCommand=m,e.SheetUpdateNoteCommand=h,e.SheetsNoteModel=c,Object.defineProperty(e,"SheetsNoteResourceController",{enumerable:!0,get:function(){return y}}),e.ToggleNotePopupMutation=d,Object.defineProperty(e,"UniverSheetsNotePlugin",{enumerable:!0,get:function(){return T}}),e.UpdateNoteMutation=l,e.UpdateNotePositionMutation=f});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-note",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Cell note model and commands for Univer Sheets.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -62,25 +62,25 @@
|
|
|
62
62
|
"rxjs": ">=7.0.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@univerjs/core": "1.
|
|
66
|
-
"@univerjs/sheets": "1.
|
|
65
|
+
"@univerjs/core": "1.5.0",
|
|
66
|
+
"@univerjs/sheets": "1.5.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@univerjs-infra/shared": "1.
|
|
70
|
-
"@univerjs/engine-formula": "1.
|
|
71
|
-
"@univerjs/engine-render": "1.
|
|
72
|
-
"@univerjs/network": "1.
|
|
69
|
+
"@univerjs-infra/shared": "1.5.0",
|
|
70
|
+
"@univerjs/engine-formula": "1.5.0",
|
|
71
|
+
"@univerjs/engine-render": "1.5.0",
|
|
72
|
+
"@univerjs/network": "1.5.0",
|
|
73
73
|
"rxjs": "7.8.2",
|
|
74
|
-
"
|
|
75
|
-
"vitest": "^5.0
|
|
74
|
+
"tsrs": "0.23.0-ts7.1.0-beta",
|
|
75
|
+
"vitest": "^5.1.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"test": "vitest run",
|
|
79
79
|
"test:watch": "vitest",
|
|
80
80
|
"coverage": "vitest run --coverage",
|
|
81
|
-
"typecheck": "
|
|
81
|
+
"typecheck": "tsrs --noEmit",
|
|
82
82
|
"build:bundle": "univer-cli build",
|
|
83
|
-
"build:types": "
|
|
83
|
+
"build:types": "tsrs -p tsconfig.node.json",
|
|
84
84
|
"build": "pnpm run build:bundle && pnpm run build:types"
|
|
85
85
|
},
|
|
86
86
|
"module": "./lib/es/index.js"
|