@univerjs/sheets-note 1.4.0 → 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 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/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
- // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
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,25 +13,25 @@ function _typeof(o) {
13
13
  }, _typeof(o);
14
14
  }
15
15
 
16
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
17
- function toPrimitive(t, r) {
16
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
17
+ function toPrimitive(t, e) {
18
18
  if ("object" != _typeof(t) || !t) return t;
19
- var e = t[Symbol.toPrimitive];
20
- if (void 0 !== e) {
21
- var i = e.call(t, r || "default");
19
+ var r;
20
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
21
+ var i = r.call(t, e || "default");
22
22
  if ("object" != _typeof(i)) return i;
23
23
  throw new TypeError("@@toPrimitive must return a primitive value.");
24
24
  }
25
- return ("string" === r ? String : Number)(t);
25
+ return ("string" === e ? String : Number)(t);
26
26
  }
27
27
 
28
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
28
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
29
29
  function toPropertyKey(t) {
30
30
  var i = toPrimitive(t, "string");
31
31
  return "symbol" == _typeof(i) ? i : i + "";
32
32
  }
33
33
 
34
- // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
34
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
35
35
  function _defineProperty(e, r, t) {
36
36
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
37
37
  value: t,
@@ -46,9 +46,16 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
46
46
  constructor(..._args) {
47
47
  super(..._args);
48
48
  _defineProperty(this, "_notesMap", /* @__PURE__ */ new Map());
49
+ _defineProperty(this, "_notePositionCache", /* @__PURE__ */ new WeakMap());
49
50
  _defineProperty(this, "_change$", new rxjs.Subject());
50
51
  _defineProperty(this, "change$", this._change$.asObservable());
51
52
  }
53
+ dispose() {
54
+ this._notePositionCache = /* @__PURE__ */ new WeakMap();
55
+ this._notesMap.clear();
56
+ this._change$.complete();
57
+ super.dispose();
58
+ }
52
59
  _ensureNotesMap(unitId, subUnitId) {
53
60
  let unitMap = this._notesMap.get(unitId);
54
61
  if (!unitMap) {
@@ -64,7 +71,14 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
64
71
  }
65
72
  _getNoteByPosition(unitId, subUnitId, row, col) {
66
73
  const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
67
- for (const [_, note] of subUnitMap) if (note.row === row && note.col === col) return note;
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;
68
82
  }
69
83
  _getNoteById(unitId, subUnitId, id) {
70
84
  return this._ensureNotesMap(unitId, subUnitId).get(id);
@@ -111,6 +125,7 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
111
125
  col
112
126
  };
113
127
  subUnitMap.set(newNote.id, newNote);
128
+ this._notePositionCache.delete(subUnitMap);
114
129
  this._change$.next({
115
130
  unitId,
116
131
  subUnitId,
@@ -128,7 +143,9 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
128
143
  col
129
144
  });
130
145
  if (!oldNote) return;
131
- this._ensureNotesMap(unitId, subUnitId).delete(oldNote.id);
146
+ const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
147
+ subUnitMap.delete(oldNote.id);
148
+ this._notePositionCache.delete(subUnitMap);
132
149
  this._change$.next({
133
150
  unitId,
134
151
  subUnitId,
@@ -152,6 +169,7 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
152
169
  show: !oldNote.show
153
170
  };
154
171
  subUnitMap.set(newNote.id, newNote);
172
+ this._notePositionCache.delete(subUnitMap);
155
173
  this._change$.next({
156
174
  unitId,
157
175
  subUnitId,
@@ -176,6 +194,7 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
176
194
  col: newCol
177
195
  };
178
196
  subUnitMap.set(newNote.id, newNote);
197
+ this._notePositionCache.delete(subUnitMap);
179
198
  this._change$.next({
180
199
  unitId,
181
200
  subUnitId,
@@ -200,6 +219,8 @@ var SheetsNoteModel = class extends _univerjs_core.Disposable {
200
219
  return unitMap.get(subUnitId);
201
220
  }
202
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));
203
224
  this._notesMap.delete(unitId);
204
225
  }
205
226
  };
@@ -433,14 +454,14 @@ const SheetUpdateNoteCommand = {
433
454
  */
434
455
  const PLUGIN_NAME = "SHEET_NOTE_PLUGIN";
435
456
 
436
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorateParam.js
457
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
437
458
  function __decorateParam(paramIndex, decorator) {
438
459
  return function(target, key) {
439
460
  decorator(target, key, paramIndex);
440
461
  };
441
462
  }
442
463
 
443
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorate.js
464
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
444
465
  function __decorate(decorators, target, key, desc) {
445
466
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
446
467
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -606,7 +627,7 @@ SheetsNoteResourceController = __decorate([
606
627
 
607
628
  // package.json
608
629
  var name = "@univerjs/sheets-note";
609
- var version = "1.4.0";
630
+ var version = "1.5.0";
610
631
 
611
632
  // src/config/config.ts
612
633
  /**
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
- // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
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,25 +12,25 @@ function _typeof(o) {
12
12
  }, _typeof(o);
13
13
  }
14
14
 
15
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
16
- function toPrimitive(t, r) {
15
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
16
+ function toPrimitive(t, e) {
17
17
  if ("object" != _typeof(t) || !t) return t;
18
- var e = t[Symbol.toPrimitive];
19
- if (void 0 !== e) {
20
- var i = e.call(t, r || "default");
18
+ var r;
19
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
20
+ var i = r.call(t, e || "default");
21
21
  if ("object" != _typeof(i)) return i;
22
22
  throw new TypeError("@@toPrimitive must return a primitive value.");
23
23
  }
24
- return ("string" === r ? String : Number)(t);
24
+ return ("string" === e ? String : Number)(t);
25
25
  }
26
26
 
27
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
27
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
28
28
  function toPropertyKey(t) {
29
29
  var i = toPrimitive(t, "string");
30
30
  return "symbol" == _typeof(i) ? i : i + "";
31
31
  }
32
32
 
33
- // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
33
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
34
34
  function _defineProperty(e, r, t) {
35
35
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
36
36
  value: t,
@@ -45,9 +45,16 @@ var SheetsNoteModel = class extends Disposable {
45
45
  constructor(..._args) {
46
46
  super(..._args);
47
47
  _defineProperty(this, "_notesMap", /* @__PURE__ */ new Map());
48
+ _defineProperty(this, "_notePositionCache", /* @__PURE__ */ new WeakMap());
48
49
  _defineProperty(this, "_change$", new Subject());
49
50
  _defineProperty(this, "change$", this._change$.asObservable());
50
51
  }
52
+ dispose() {
53
+ this._notePositionCache = /* @__PURE__ */ new WeakMap();
54
+ this._notesMap.clear();
55
+ this._change$.complete();
56
+ super.dispose();
57
+ }
51
58
  _ensureNotesMap(unitId, subUnitId) {
52
59
  let unitMap = this._notesMap.get(unitId);
53
60
  if (!unitMap) {
@@ -63,7 +70,14 @@ var SheetsNoteModel = class extends Disposable {
63
70
  }
64
71
  _getNoteByPosition(unitId, subUnitId, row, col) {
65
72
  const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
66
- for (const [_, note] of subUnitMap) if (note.row === row && note.col === col) return note;
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;
67
81
  }
68
82
  _getNoteById(unitId, subUnitId, id) {
69
83
  return this._ensureNotesMap(unitId, subUnitId).get(id);
@@ -110,6 +124,7 @@ var SheetsNoteModel = class extends Disposable {
110
124
  col
111
125
  };
112
126
  subUnitMap.set(newNote.id, newNote);
127
+ this._notePositionCache.delete(subUnitMap);
113
128
  this._change$.next({
114
129
  unitId,
115
130
  subUnitId,
@@ -127,7 +142,9 @@ var SheetsNoteModel = class extends Disposable {
127
142
  col
128
143
  });
129
144
  if (!oldNote) return;
130
- this._ensureNotesMap(unitId, subUnitId).delete(oldNote.id);
145
+ const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
146
+ subUnitMap.delete(oldNote.id);
147
+ this._notePositionCache.delete(subUnitMap);
131
148
  this._change$.next({
132
149
  unitId,
133
150
  subUnitId,
@@ -151,6 +168,7 @@ var SheetsNoteModel = class extends Disposable {
151
168
  show: !oldNote.show
152
169
  };
153
170
  subUnitMap.set(newNote.id, newNote);
171
+ this._notePositionCache.delete(subUnitMap);
154
172
  this._change$.next({
155
173
  unitId,
156
174
  subUnitId,
@@ -175,6 +193,7 @@ var SheetsNoteModel = class extends Disposable {
175
193
  col: newCol
176
194
  };
177
195
  subUnitMap.set(newNote.id, newNote);
196
+ this._notePositionCache.delete(subUnitMap);
178
197
  this._change$.next({
179
198
  unitId,
180
199
  subUnitId,
@@ -199,6 +218,8 @@ var SheetsNoteModel = class extends Disposable {
199
218
  return unitMap.get(subUnitId);
200
219
  }
201
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));
202
223
  this._notesMap.delete(unitId);
203
224
  }
204
225
  };
@@ -432,14 +453,14 @@ const SheetUpdateNoteCommand = {
432
453
  */
433
454
  const PLUGIN_NAME = "SHEET_NOTE_PLUGIN";
434
455
 
435
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorateParam.js
456
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
436
457
  function __decorateParam(paramIndex, decorator) {
437
458
  return function(target, key) {
438
459
  decorator(target, key, paramIndex);
439
460
  };
440
461
  }
441
462
 
442
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorate.js
463
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
443
464
  function __decorate(decorators, target, key, desc) {
444
465
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
445
466
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -605,7 +626,7 @@ SheetsNoteResourceController = __decorate([
605
626
 
606
627
  // package.json
607
628
  var name = "@univerjs/sheets-note";
608
- var version = "1.4.0";
629
+ var version = "1.5.0";
609
630
 
610
631
  // src/config/config.ts
611
632
  /**
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
- // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
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,25 +12,25 @@ function _typeof(o) {
12
12
  }, _typeof(o);
13
13
  }
14
14
 
15
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
16
- function toPrimitive(t, r) {
15
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
16
+ function toPrimitive(t, e) {
17
17
  if ("object" != _typeof(t) || !t) return t;
18
- var e = t[Symbol.toPrimitive];
19
- if (void 0 !== e) {
20
- var i = e.call(t, r || "default");
18
+ var r;
19
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
20
+ var i = r.call(t, e || "default");
21
21
  if ("object" != _typeof(i)) return i;
22
22
  throw new TypeError("@@toPrimitive must return a primitive value.");
23
23
  }
24
- return ("string" === r ? String : Number)(t);
24
+ return ("string" === e ? String : Number)(t);
25
25
  }
26
26
 
27
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
27
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
28
28
  function toPropertyKey(t) {
29
29
  var i = toPrimitive(t, "string");
30
30
  return "symbol" == _typeof(i) ? i : i + "";
31
31
  }
32
32
 
33
- // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
33
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
34
34
  function _defineProperty(e, r, t) {
35
35
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
36
36
  value: t,
@@ -45,9 +45,16 @@ var SheetsNoteModel = class extends Disposable {
45
45
  constructor(..._args) {
46
46
  super(..._args);
47
47
  _defineProperty(this, "_notesMap", /* @__PURE__ */ new Map());
48
+ _defineProperty(this, "_notePositionCache", /* @__PURE__ */ new WeakMap());
48
49
  _defineProperty(this, "_change$", new Subject());
49
50
  _defineProperty(this, "change$", this._change$.asObservable());
50
51
  }
52
+ dispose() {
53
+ this._notePositionCache = /* @__PURE__ */ new WeakMap();
54
+ this._notesMap.clear();
55
+ this._change$.complete();
56
+ super.dispose();
57
+ }
51
58
  _ensureNotesMap(unitId, subUnitId) {
52
59
  let unitMap = this._notesMap.get(unitId);
53
60
  if (!unitMap) {
@@ -63,7 +70,14 @@ var SheetsNoteModel = class extends Disposable {
63
70
  }
64
71
  _getNoteByPosition(unitId, subUnitId, row, col) {
65
72
  const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
66
- for (const [_, note] of subUnitMap) if (note.row === row && note.col === col) return note;
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;
67
81
  }
68
82
  _getNoteById(unitId, subUnitId, id) {
69
83
  return this._ensureNotesMap(unitId, subUnitId).get(id);
@@ -110,6 +124,7 @@ var SheetsNoteModel = class extends Disposable {
110
124
  col
111
125
  };
112
126
  subUnitMap.set(newNote.id, newNote);
127
+ this._notePositionCache.delete(subUnitMap);
113
128
  this._change$.next({
114
129
  unitId,
115
130
  subUnitId,
@@ -127,7 +142,9 @@ var SheetsNoteModel = class extends Disposable {
127
142
  col
128
143
  });
129
144
  if (!oldNote) return;
130
- this._ensureNotesMap(unitId, subUnitId).delete(oldNote.id);
145
+ const subUnitMap = this._ensureNotesMap(unitId, subUnitId);
146
+ subUnitMap.delete(oldNote.id);
147
+ this._notePositionCache.delete(subUnitMap);
131
148
  this._change$.next({
132
149
  unitId,
133
150
  subUnitId,
@@ -151,6 +168,7 @@ var SheetsNoteModel = class extends Disposable {
151
168
  show: !oldNote.show
152
169
  };
153
170
  subUnitMap.set(newNote.id, newNote);
171
+ this._notePositionCache.delete(subUnitMap);
154
172
  this._change$.next({
155
173
  unitId,
156
174
  subUnitId,
@@ -175,6 +193,7 @@ var SheetsNoteModel = class extends Disposable {
175
193
  col: newCol
176
194
  };
177
195
  subUnitMap.set(newNote.id, newNote);
196
+ this._notePositionCache.delete(subUnitMap);
178
197
  this._change$.next({
179
198
  unitId,
180
199
  subUnitId,
@@ -199,6 +218,8 @@ var SheetsNoteModel = class extends Disposable {
199
218
  return unitMap.get(subUnitId);
200
219
  }
201
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));
202
223
  this._notesMap.delete(unitId);
203
224
  }
204
225
  };
@@ -432,14 +453,14 @@ const SheetUpdateNoteCommand = {
432
453
  */
433
454
  const PLUGIN_NAME = "SHEET_NOTE_PLUGIN";
434
455
 
435
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorateParam.js
456
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
436
457
  function __decorateParam(paramIndex, decorator) {
437
458
  return function(target, key) {
438
459
  decorator(target, key, paramIndex);
439
460
  };
440
461
  }
441
462
 
442
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorate.js
463
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
443
464
  function __decorate(decorators, target, key, desc) {
444
465
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
445
466
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -605,7 +626,7 @@ SheetsNoteResourceController = __decorate([
605
626
 
606
627
  // package.json
607
628
  var name = "@univerjs/sheets-note";
608
- var version = "1.4.0";
629
+ var version = "1.5.0";
609
630
 
610
631
  // src/config/config.ts
611
632
  /**
@@ -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.4.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});
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.4.0",
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,17 +62,17 @@
62
62
  "rxjs": ">=7.0.0"
63
63
  },
64
64
  "dependencies": {
65
- "@univerjs/core": "1.4.0",
66
- "@univerjs/sheets": "1.4.0"
65
+ "@univerjs/core": "1.5.0",
66
+ "@univerjs/sheets": "1.5.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@univerjs-infra/shared": "1.4.0",
70
- "@univerjs/engine-formula": "1.4.0",
71
- "@univerjs/engine-render": "1.4.0",
72
- "@univerjs/network": "1.4.0",
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
- "tsrs": "0.20.1-ts7.1.0-beta",
75
- "vitest": "^5.0.5"
74
+ "tsrs": "0.23.0-ts7.1.0-beta",
75
+ "vitest": "^5.1.0"
76
76
  },
77
77
  "scripts": {
78
78
  "test": "vitest run",