@univerjs/sheets-note 0.16.1 → 0.17.0-insiders.20260318-d69dc16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,594 +1 @@
1
- var z = Object.defineProperty;
2
- var F = (i, r, e) => r in i ? z(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
3
- var _ = (i, r, e) => F(i, typeof r != "symbol" ? r + "" : r, e);
4
- import { Disposable as U, generateRandomId as J, CommandType as m, IUniverInstanceService as E, ICommandService as w, IUndoRedoService as T, IResourceManagerService as q, Inject as f, UniverInstanceType as I, sequenceExecuteAsync as K, DependentOn as Y, IConfigService as Q, Injector as X, Plugin as Z, merge as k, touchDependencies as A } from "@univerjs/core";
5
- import { getSheetCommandTarget as D, SheetsSelectionsService as x, SheetInterceptorService as ee, RemoveSheetCommand as te, CopySheetCommand as se, RefRangeService as oe, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as ne, UniverSheetsPlugin as re } from "@univerjs/sheets";
6
- import { Subject as ie, filter as W, map as B } from "rxjs";
7
- class g extends U {
8
- constructor() {
9
- super(...arguments);
10
- _(this, "_notesMap", /* @__PURE__ */ new Map());
11
- _(this, "_change$", new ie());
12
- _(this, "change$", this._change$.asObservable());
13
- }
14
- _ensureNotesMap(e, t) {
15
- let s = this._notesMap.get(e);
16
- s || (s = /* @__PURE__ */ new Map(), this._notesMap.set(e, s));
17
- let o = s.get(t);
18
- return o || (o = /* @__PURE__ */ new Map(), s.set(t, o)), o;
19
- }
20
- _getNoteByPosition(e, t, s, o) {
21
- const n = this._ensureNotesMap(e, t);
22
- for (const [a, c] of n)
23
- if (c.row === s && c.col === o)
24
- return c;
25
- }
26
- _getNoteById(e, t, s) {
27
- return this._ensureNotesMap(e, t).get(s);
28
- }
29
- _getNoteByParams(e, t, s) {
30
- const { noteId: o, row: n, col: a } = s;
31
- return o ? this._getNoteById(e, t, o) : n !== void 0 && a !== void 0 ? this._getNoteByPosition(e, t, n, a) : null;
32
- }
33
- getSheetShowNotes$(e, t) {
34
- return this._change$.pipe(
35
- W(({ unitId: s, subUnitId: o }) => s === e && o === t),
36
- B(() => {
37
- const s = this._ensureNotesMap(e, t), o = [];
38
- for (const [n, a] of s)
39
- a.show && o.push({ loc: { row: a.row, col: a.col, unitId: e, subUnitId: t }, note: a });
40
- return o;
41
- })
42
- );
43
- }
44
- getCellNoteChange$(e, t, s, o) {
45
- return this._change$.pipe(
46
- W(({ unitId: n, subUnitId: a, oldNote: c }) => n !== e || a !== t || !c ? !1 : c.row === s && c.col === o),
47
- B((n) => n)
48
- );
49
- }
50
- updateNote(e, t, s, o, n, a) {
51
- const c = this._getNoteByParams(e, t, { noteId: n == null ? void 0 : n.id, row: s, col: o }), d = this._ensureNotesMap(e, t), h = {
52
- ...n,
53
- id: (c == null ? void 0 : c.id) || n.id || J(6),
54
- row: s,
55
- col: o
56
- };
57
- d.set(h.id, h), this._change$.next({ unitId: e, subUnitId: t, oldNote: c, type: "update", newNote: h, silent: a });
58
- }
59
- removeNote(e, t, s) {
60
- const { noteId: o, row: n, col: a, silent: c } = s, d = this._getNoteByParams(e, t, { noteId: o, row: n, col: a });
61
- if (!d)
62
- return;
63
- this._ensureNotesMap(e, t).delete(d.id), this._change$.next({ unitId: e, subUnitId: t, oldNote: d, type: "update", newNote: null, silent: c });
64
- }
65
- toggleNotePopup(e, t, s) {
66
- const { noteId: o, row: n, col: a, silent: c } = s, d = this._getNoteByParams(e, t, { noteId: o, row: n, col: a });
67
- if (!d)
68
- return;
69
- const h = this._ensureNotesMap(e, t), u = { ...d, show: !d.show };
70
- h.set(u.id, u), this._change$.next({ unitId: e, subUnitId: t, oldNote: d, type: "update", newNote: u, silent: c });
71
- }
72
- updateNotePosition(e, t, s) {
73
- const { noteId: o, row: n, col: a, newRow: c, newCol: d, silent: h } = s, u = this._getNoteByParams(e, t, { noteId: o, row: n, col: a });
74
- if (!u)
75
- return;
76
- const l = this._ensureNotesMap(e, t), p = { ...u, row: c, col: d };
77
- l.set(p.id, p), this._change$.next({ unitId: e, subUnitId: t, oldNote: u, type: "ref", newNote: p, silent: h });
78
- }
79
- getNote(e, t, s) {
80
- return this._getNoteByParams(e, t, s);
81
- }
82
- getNotes() {
83
- return this._notesMap;
84
- }
85
- getUnitNotes(e) {
86
- return this._notesMap.get(e);
87
- }
88
- getSheetNotes(e, t) {
89
- const s = this._notesMap.get(e);
90
- if (s)
91
- return s.get(t);
92
- }
93
- deleteUnitNotes(e) {
94
- this._notesMap.delete(e);
95
- }
96
- }
97
- const N = {
98
- id: "sheet.mutation.update-note",
99
- type: m.MUTATION,
100
- handler: (i, r) => {
101
- const { unitId: e, sheetId: t, row: s, col: o, note: n, silent: a } = r;
102
- return i.get(g).updateNote(e, t, s, o, n, a), !0;
103
- }
104
- }, M = {
105
- id: "sheet.mutation.remove-note",
106
- type: m.MUTATION,
107
- handler: (i, r) => {
108
- const { unitId: e, sheetId: t, noteId: s, row: o, col: n, silent: a } = r;
109
- return i.get(g).removeNote(e, t, { noteId: s, row: o, col: n, silent: a }), !0;
110
- }
111
- }, b = {
112
- id: "sheet.mutation.toggle-note-popup",
113
- type: m.MUTATION,
114
- handler: (i, r) => {
115
- const { unitId: e, sheetId: t, noteId: s, row: o, col: n, silent: a } = r;
116
- return i.get(g).toggleNotePopup(e, t, { noteId: s, row: o, col: n, silent: a }), !0;
117
- }
118
- }, $ = {
119
- id: "sheet.mutation.update-note-position",
120
- type: m.MUTATION,
121
- handler: (i, r) => {
122
- const { unitId: e, sheetId: t, noteId: s, row: o, col: n, newPosition: a, silent: c } = r;
123
- return i.get(g).updateNotePosition(e, t, { noteId: s, row: o, col: n, newRow: a.row, newCol: a.col, silent: c }), !0;
124
- }
125
- }, ae = {
126
- id: "sheet.command.delete-note",
127
- type: m.COMMAND,
128
- handler: (i) => {
129
- const r = D(i.get(E));
130
- if (!r) return !1;
131
- const t = i.get(x).getCurrentLastSelection();
132
- if (!(t != null && t.primary)) return !1;
133
- const s = i.get(g), { unitId: o, subUnitId: n } = r, { actualColumn: a, actualRow: c } = t.primary, d = s.getNote(o, n, { row: c, col: a });
134
- if (!d) return !1;
135
- const h = i.get(w), u = i.get(T), l = {
136
- id: M.id,
137
- params: {
138
- unitId: o,
139
- sheetId: n,
140
- noteId: d.id
141
- }
142
- }, p = {
143
- id: N.id,
144
- params: {
145
- unitId: o,
146
- sheetId: n,
147
- row: c,
148
- col: a,
149
- note: { ...d }
150
- }
151
- };
152
- return h.syncExecuteCommand(l.id, l.params) ? (u.pushUndoRedo({
153
- unitID: o,
154
- redoMutations: [l],
155
- undoMutations: [p]
156
- }), !0) : !1;
157
- }
158
- }, ce = {
159
- id: "sheet.command.toggle-note-popup",
160
- type: m.COMMAND,
161
- handler: (i) => {
162
- const r = D(i.get(E));
163
- if (!r) return !1;
164
- const t = i.get(x).getCurrentLastSelection();
165
- if (!(t != null && t.primary)) return !1;
166
- const s = i.get(g), { unitId: o, subUnitId: n } = r, { actualColumn: a, actualRow: c } = t.primary, d = s.getNote(o, n, { row: c, col: a });
167
- if (!d) return !1;
168
- const h = i.get(w), u = i.get(T), l = {
169
- id: b.id,
170
- params: {
171
- unitId: o,
172
- sheetId: n,
173
- noteId: d.id
174
- }
175
- }, p = {
176
- id: b.id,
177
- params: {
178
- unitId: o,
179
- sheetId: n,
180
- noteId: d.id
181
- }
182
- };
183
- return h.syncExecuteCommand(l.id, l.params) ? (u.pushUndoRedo({
184
- unitID: o,
185
- redoMutations: [l],
186
- undoMutations: [p]
187
- }), !0) : !1;
188
- }
189
- }, de = {
190
- id: "sheet.command.update-note",
191
- type: m.COMMAND,
192
- handler: (i, r) => {
193
- const e = D(i.get(E), r);
194
- if (!e) return !1;
195
- const t = i.get(w), s = i.get(T), o = i.get(g), { unitId: n, subUnitId: a } = e, { row: c, col: d, note: h } = r, u = o.getNote(n, a, { noteId: h.id, row: c, col: d }), l = {
196
- id: N.id,
197
- params: {
198
- unitId: n,
199
- sheetId: a,
200
- row: c,
201
- col: d,
202
- note: h
203
- }
204
- }, p = [];
205
- if (u) {
206
- const O = {
207
- id: N.id,
208
- params: {
209
- unitId: n,
210
- sheetId: a,
211
- row: c,
212
- col: d,
213
- note: { ...u }
214
- }
215
- };
216
- p.push(O);
217
- } else {
218
- const O = {
219
- id: M.id,
220
- params: {
221
- unitId: n,
222
- sheetId: a,
223
- row: c,
224
- col: d
225
- }
226
- };
227
- p.push(O);
228
- }
229
- return t.syncExecuteCommand(l.id, l.params) ? (s.pushUndoRedo({
230
- unitID: n,
231
- redoMutations: [l],
232
- undoMutations: p
233
- }), !0) : !1;
234
- }
235
- }, G = "SHEET_NOTE_PLUGIN";
236
- var he = Object.getOwnPropertyDescriptor, ue = (i, r, e, t) => {
237
- for (var s = t > 1 ? void 0 : t ? he(r, e) : r, o = i.length - 1, n; o >= 0; o--)
238
- (n = i[o]) && (s = n(s) || s);
239
- return s;
240
- }, S = (i, r) => (e, t) => r(e, t, i);
241
- let C = class extends U {
242
- constructor(i, r, e, t) {
243
- super(), this._resourceManagerService = i, this._univerInstanceService = r, this._sheetInterceptorService = e, this._sheetsNoteModel = t, this._initSnapshot(), this._initSheetChange();
244
- }
245
- _initSnapshot() {
246
- const i = (e) => {
247
- const t = this._sheetsNoteModel.getUnitNotes(e);
248
- if (!t)
249
- return "";
250
- const s = {};
251
- return t.forEach((o, n) => {
252
- const a = {};
253
- o.forEach((c) => {
254
- const { row: d, col: h } = c;
255
- a[d] || (a[d] = {}), a[d][h] = c;
256
- }), Object.keys(a).length > 0 && (s[n] = a);
257
- }), JSON.stringify(s);
258
- }, r = (e) => {
259
- if (!e)
260
- return {};
261
- try {
262
- return JSON.parse(e);
263
- } catch {
264
- return {};
265
- }
266
- };
267
- this.disposeWithMe(
268
- this._resourceManagerService.registerPluginResource({
269
- pluginName: G,
270
- businesses: [I.UNIVER_SHEET],
271
- toJson: (e) => i(e),
272
- parseJson: (e) => r(e),
273
- onUnLoad: (e) => {
274
- this._sheetsNoteModel.deleteUnitNotes(e);
275
- },
276
- onLoad: (e, t) => {
277
- Object.entries(t).forEach(([s, o]) => {
278
- Object.entries(o).forEach(([n, a]) => {
279
- Object.entries(a).forEach(([c, d]) => {
280
- this._sheetsNoteModel.updateNote(
281
- e,
282
- s,
283
- Number(n),
284
- Number(c),
285
- d
286
- );
287
- });
288
- });
289
- });
290
- }
291
- })
292
- );
293
- }
294
- // eslint-disable-next-line max-lines-per-function
295
- _initSheetChange() {
296
- this.disposeWithMe(
297
- this._sheetInterceptorService.interceptCommand({
298
- // eslint-disable-next-line max-lines-per-function
299
- getMutations: (i) => {
300
- var r;
301
- if (i.id === te.id) {
302
- const e = i.params, t = e.unitId || this._univerInstanceService.getCurrentUnitOfType(I.UNIVER_SHEET).getUnitId(), s = e.subUnitId || ((r = this._univerInstanceService.getCurrentUnitOfType(I.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : r.getSheetId());
303
- if (!t || !s)
304
- return { redos: [], undos: [] };
305
- const o = this._sheetsNoteModel.getSheetNotes(t, s);
306
- if (!o)
307
- return { redos: [], undos: [] };
308
- const n = [], a = [];
309
- return o.forEach((c) => {
310
- n.push({
311
- id: M.id,
312
- params: {
313
- unitId: t,
314
- sheetId: s,
315
- noteId: c.id,
316
- row: c.row,
317
- col: c.col
318
- }
319
- }), a.push({
320
- id: N.id,
321
- params: {
322
- unitId: t,
323
- sheetId: s,
324
- row: c.row,
325
- col: c.col,
326
- note: c
327
- }
328
- });
329
- }), { redos: n, undos: a };
330
- } else if (i.id === se.id) {
331
- const e = i.params, { unitId: t, subUnitId: s, targetSubUnitId: o } = e;
332
- if (!t || !s || !o)
333
- return { redos: [], undos: [] };
334
- const n = this._sheetsNoteModel.getSheetNotes(t, s);
335
- if (!n)
336
- return { redos: [], undos: [] };
337
- const a = [], c = [];
338
- return n.forEach((d) => {
339
- const h = { ...d, id: J(6) };
340
- a.push({
341
- id: N.id,
342
- params: {
343
- unitId: t,
344
- sheetId: o,
345
- row: h.row,
346
- col: h.col,
347
- note: h
348
- }
349
- }), c.push({
350
- id: M.id,
351
- params: {
352
- unitId: t,
353
- sheetId: o,
354
- noteId: h.id,
355
- row: h.row,
356
- col: h.col
357
- }
358
- });
359
- }), { redos: a, undos: c };
360
- }
361
- return { redos: [], undos: [] };
362
- }
363
- })
364
- );
365
- }
366
- };
367
- C = ue([
368
- S(0, q),
369
- S(1, E),
370
- S(2, f(ee)),
371
- S(3, f(g))
372
- ], C);
373
- const le = "sheets-note.config", L = {};
374
- var pe = Object.getOwnPropertyDescriptor, ge = (i, r, e, t) => {
375
- for (var s = t > 1 ? void 0 : t ? pe(r, e) : r, o = i.length - 1, n; o >= 0; o--)
376
- (n = i[o]) && (s = n(s) || s);
377
- return s;
378
- }, v = (i, r) => (e, t) => r(e, t, i);
379
- let R = class extends U {
380
- constructor(r, e, t, s) {
381
- super();
382
- _(this, "_disposableMap", /* @__PURE__ */ new Map());
383
- _(this, "_watcherMap", /* @__PURE__ */ new Map());
384
- _(this, "_handleRangeChange", (r, e, t, s, o, n, a) => n ? {
385
- redos: [{
386
- id: $.id,
387
- params: {
388
- unitId: r,
389
- sheetId: e,
390
- noteId: t.id,
391
- newPosition: {
392
- row: n.startRow,
393
- col: n.startColumn
394
- },
395
- silent: a
396
- }
397
- }],
398
- undos: [{
399
- id: $.id,
400
- params: {
401
- unitId: r,
402
- sheetId: e,
403
- noteId: t.id,
404
- newPosition: {
405
- row: s,
406
- col: o
407
- },
408
- note: t,
409
- silent: a
410
- }
411
- }]
412
- } : {
413
- redos: [{
414
- id: M.id,
415
- params: {
416
- unitId: r,
417
- sheetId: e,
418
- noteId: t.id
419
- }
420
- }],
421
- undos: [{
422
- id: N.id,
423
- params: {
424
- unitId: r,
425
- sheetId: e,
426
- row: s,
427
- col: o,
428
- note: t
429
- }
430
- }]
431
- });
432
- this._refRangeService = r, this._sheetsNoteModel = e, this._selectionManagerService = t, this._commandService = s, this._initData(), this._initRefRange();
433
- }
434
- _getIdWithUnitId(r, e, t, s) {
435
- return `${r}-${e}-${t}-${s}`;
436
- }
437
- _register(r, e, t, s, o) {
438
- const n = {
439
- startColumn: o,
440
- endColumn: o,
441
- startRow: s,
442
- endRow: s
443
- };
444
- this._disposableMap.set(
445
- this._getIdWithUnitId(r, e, s, o),
446
- this._refRangeService.registerRefRange(n, (a) => {
447
- const c = ne(n, a, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
448
- return d && d.startColumn === n.startColumn && d.startRow === n.startRow ? {
449
- undos: [],
450
- redos: []
451
- } : this._handleRangeChange(r, e, t, s, o, d, !1);
452
- }, r, e)
453
- );
454
- }
455
- _watch(r, e, t, s, o) {
456
- const n = {
457
- startColumn: o,
458
- endColumn: o,
459
- startRow: s,
460
- endRow: s
461
- };
462
- this._watcherMap.set(
463
- this._getIdWithUnitId(r, e, s, o),
464
- this._refRangeService.watchRange(r, e, n, (a, c) => {
465
- const { redos: d } = this._handleRangeChange(r, e, t, a.startRow, a.startColumn, c, !0);
466
- K(d, this._commandService, { onlyLocal: !0 });
467
- }, !0)
468
- );
469
- }
470
- _unwatch(r, e, t, s) {
471
- var n;
472
- const o = this._getIdWithUnitId(r, e, t, s);
473
- (n = this._watcherMap.get(o)) == null || n.dispose(), this._watcherMap.delete(o);
474
- }
475
- _unregister(r, e, t, s) {
476
- var n;
477
- const o = this._getIdWithUnitId(r, e, t, s);
478
- (n = this._disposableMap.get(o)) == null || n.dispose(), this._disposableMap.delete(o);
479
- }
480
- _initData() {
481
- const r = this._sheetsNoteModel.getNotes();
482
- for (const [e, t] of r)
483
- for (const [s, o] of t)
484
- o.forEach((n) => {
485
- this._register(e, s, n, n.row, n.col), this._watch(e, s, n, n.row, n.col);
486
- });
487
- }
488
- _initRefRange() {
489
- this.disposeWithMe(
490
- this._sheetsNoteModel.change$.subscribe((r) => {
491
- switch (r.type) {
492
- case "update": {
493
- const { unitId: e, subUnitId: t, oldNote: s, newNote: o } = r, n = o ? o.row : s.row, a = o ? o.col : s.col, c = this._getIdWithUnitId(e, t, n, a);
494
- o ? this._disposableMap.has(c) || (this._register(e, t, o, n, a), this._watch(e, t, o, n, a)) : (this._unregister(e, t, n, a), this._unwatch(e, t, n, a));
495
- break;
496
- }
497
- case "ref": {
498
- const { unitId: e, subUnitId: t, oldNote: s, newNote: o, silent: n } = r, { row: a, col: c } = s, { row: d, col: h } = o;
499
- this._unregister(e, t, a, c), n || (this._unwatch(e, t, a, c), this._watch(e, t, o, d, h)), this._register(e, t, o, d, h);
500
- break;
501
- }
502
- }
503
- })
504
- );
505
- }
506
- };
507
- R = ge([
508
- v(0, f(oe)),
509
- v(1, f(g)),
510
- v(2, f(x)),
511
- v(3, w)
512
- ], R);
513
- var _e = Object.getOwnPropertyDescriptor, Ne = (i, r, e, t) => {
514
- for (var s = t > 1 ? void 0 : t ? _e(r, e) : r, o = i.length - 1, n; o >= 0; o--)
515
- (n = i[o]) && (s = n(s) || s);
516
- return s;
517
- }, me = (i, r) => (e, t) => r(e, t, i);
518
- let y = class extends U {
519
- constructor(i) {
520
- super(), this._commandService = i, this._initialize();
521
- }
522
- _initialize() {
523
- [
524
- $,
525
- b,
526
- N,
527
- M,
528
- ae,
529
- ce,
530
- de
531
- ].forEach((i) => {
532
- this.disposeWithMe(
533
- this._commandService.registerCommand(i)
534
- );
535
- });
536
- }
537
- };
538
- y = Ne([
539
- me(0, w)
540
- ], y);
541
- var fe = Object.defineProperty, Me = Object.getOwnPropertyDescriptor, we = (i, r, e) => r in i ? fe(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e, Se = (i, r, e, t) => {
542
- for (var s = t > 1 ? void 0 : t ? Me(r, e) : r, o = i.length - 1, n; o >= 0; o--)
543
- (n = i[o]) && (s = n(s) || s);
544
- return s;
545
- }, H = (i, r) => (e, t) => r(e, t, i), V = (i, r, e) => we(i, typeof r != "symbol" ? r + "" : r, e);
546
- let P = class extends Z {
547
- constructor(i = L, r, e) {
548
- super(), this._config = i, this._configService = r, this._injector = e;
549
- const { ...t } = k(
550
- {},
551
- L,
552
- this._config
553
- );
554
- this._configService.setConfig(le, t);
555
- }
556
- onStarting() {
557
- [
558
- [g],
559
- [y],
560
- [C],
561
- [R]
562
- ].forEach((i) => {
563
- this._injector.add(i);
564
- }), A(this._injector, [
565
- [g],
566
- [y],
567
- [C]
568
- ]);
569
- }
570
- onReady() {
571
- A(this._injector, [
572
- [R]
573
- ]);
574
- }
575
- };
576
- V(P, "pluginName", G);
577
- V(P, "type", I.UNIVER_SHEET);
578
- P = Se([
579
- Y(re),
580
- H(1, Q),
581
- H(2, f(X))
582
- ], P);
583
- export {
584
- M as RemoveNoteMutation,
585
- ae as SheetDeleteNoteCommand,
586
- ce as SheetToggleNotePopupCommand,
587
- de as SheetUpdateNoteCommand,
588
- g as SheetsNoteModel,
589
- C as SheetsNoteResourceController,
590
- b as ToggleNotePopupMutation,
591
- P as UniverSheetsNotePlugin,
592
- N as UpdateNoteMutation,
593
- $ as UpdateNotePositionMutation
594
- };
1
+ import{CommandType as e,DependentOn as t,Disposable as n,ICommandService as r,IConfigService as i,IResourceManagerService as a,IUndoRedoService as o,IUniverInstanceService as s,Inject as c,Injector as l,Plugin as u,UniverInstanceType as d,generateRandomId as f,merge as p,sequenceExecuteAsync as m,touchDependencies as h}from"@univerjs/core";import{CopySheetCommand as g,RefRangeService as _,RemoveSheetCommand as v,SheetInterceptorService as y,SheetsSelectionsService as b,UniverSheetsPlugin as x,getSheetCommandTarget as S,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as C}from"@univerjs/sheets";import{Subject as w,filter as T,map as E}from"rxjs";function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j=class extends n{constructor(...e){super(...e),A(this,`_notesMap`,new Map),A(this,`_change$`,new w),A(this,`change$`,this._change$.asObservable())}_ensureNotesMap(e,t){let n=this._notesMap.get(e);n||(n=new Map,this._notesMap.set(e,n));let r=n.get(t);return r||(r=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(T(({unitId:n,subUnitId:r})=>n===e&&r===t),E(()=>{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,r){return this._change$.pipe(T(({unitId:i,subUnitId:a,oldNote:o})=>i!==e||a!==t||!o?!1:o.row===n&&o.col===r),E(e=>e))}updateNote(e,t,n,r,i,a){let o=this._getNoteByParams(e,t,{noteId:i==null?void 0:i.id,row:n,col:r}),s=this._ensureNotesMap(e,t),c={...i,id:(o==null?void 0:o.id)||i.id||f(6),row:n,col:r};s.set(c.id,c),this._change$.next({unitId:e,subUnitId:t,oldNote:o,type:`update`,newNote:c,silent:a})}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)}};const M={id:`sheet.mutation.update-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(j).updateNote(n,r,i,a,o,s),!0}},N={id:`sheet.mutation.remove-note`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},P={id:`sheet.mutation.toggle-note-popup`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(j).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},F={id:`sheet.mutation.update-note-position`,type:e.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:c}=t;return e.get(j).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:c}),!0}},I={id:`sheet.command.delete-note`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:N.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:M.id,params:{unitId:a,sheetId:c,row:u,col:l,note:{...d}}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},L={id:`sheet.command.toggle-note-popup`,type:e.COMMAND,handler:e=>{let t=S(e.get(s));if(!t)return!1;let n=e.get(b).getCurrentLastSelection();if(!(n!=null&&n.primary))return!1;let i=e.get(j),{unitId:a,subUnitId:c}=t,{actualColumn:l,actualRow:u}=n.primary,d=i.getNote(a,c,{row:u,col:l});if(!d)return!1;let f=e.get(r),p=e.get(o),m={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}},h={id:P.id,params:{unitId:a,sheetId:c,noteId:d.id}};return f.syncExecuteCommand(m.id,m.params)?(p.pushUndoRedo({unitID:a,redoMutations:[m],undoMutations:[h]}),!0):!1}},R={id:`sheet.command.update-note`,type:e.COMMAND,handler:(e,t)=>{let n=S(e.get(s),t);if(!n)return!1;let i=e.get(r),a=e.get(o),c=e.get(j),{unitId:l,subUnitId:u}=n,{row:d,col:f,note:p}=t,m=c.getNote(l,u,{noteId:p.id,row:d,col:f}),h={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:p}},g=[];if(m){let e={id:M.id,params:{unitId:l,sheetId:u,row:d,col:f,note:{...m}}};g.push(e)}else{let e={id:N.id,params:{unitId:l,sheetId:u,row:d,col:f}};g.push(e)}return i.syncExecuteCommand(h.id,h.params)?(a.pushUndoRedo({unitID:l,redoMutations:[h],undoMutations:g}),!0):!1}},z=`SHEET_NOTE_PLUGIN`;function B(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 H=class extends n{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)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:z,businesses:[d.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>t(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===v.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(d.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(r,i);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{o.push({id:N.id,params:{unitId:r,sheetId:i,noteId:e.id,row:e.row,col:e.col}}),s.push({id:M.id,params:{unitId:r,sheetId:i,row:e.row,col:e.col,note:e}})}),{redos:o,undos:s}}else if(e.id===g.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._sheetsNoteModel.getSheetNotes(t,n);if(!i)return{redos:[],undos:[]};let a=[],o=[];return i.forEach(e=>{let n={...e,id:f(6)};a.push({id:M.id,params:{unitId:t,sheetId:r,row:n.row,col:n.col,note:n}}),o.push({id:N.id,params:{unitId:t,sheetId:r,noteId:n.id,row:n.row,col:n.col}})}),{redos:a,undos:o}}return{redos:[],undos:[]}}}))}};H=V([B(0,a),B(1,s),B(2,c(y)),B(3,c(j))],H);var U=`@univerjs/sheets-note`,W=`0.17.0-insiders.20260318-d69dc16`;const G=`sheets-note.config`;Symbol(G);const K={};let q=class extends n{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,A(this,`_disposableMap`,new Map),A(this,`_watcherMap`,new Map),A(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:N.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:M.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,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._disposableMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.registerRefRange(a,o=>{let s=C(a,o,{selectionManagerService:this._selectionManagerService}),c=Array.isArray(s)?s[0]:s;return c&&c.startColumn===a.startColumn&&c.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,r,i,c,!1)},e,t))}_watch(e,t,n,r,i){let a={startColumn:i,endColumn:i,startRow:r,endRow:r};this._watcherMap.set(this._getIdWithUnitId(e,t,r,i),this._refRangeService.watchRange(e,t,a,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,r.startRow,r.startColumn,i,!0);m(a,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}}}))}};q=V([B(0,c(_)),B(1,c(j)),B(2,c(b)),B(3,r)],q);let J=class extends n{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[F,P,M,N,I,L,R].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};J=V([B(0,r)],J);let Y=class extends u{constructor(e=K,t,n){super(),this._config=e,this._configService=t,this._injector=n;let{...r}=p({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[j],[J],[H],[q]].forEach(e=>{this._injector.add(e)}),h(this._injector,[[j],[J],[H]])}onReady(){h(this._injector,[[q]])}};A(Y,`pluginName`,z),A(Y,`packageName`,U),A(Y,`version`,W),A(Y,`type`,d.UNIVER_SHEET),Y=V([t(x),B(1,i),B(2,c(l))],Y);export{N as RemoveNoteMutation,I as SheetDeleteNoteCommand,L as SheetToggleNotePopupCommand,R as SheetUpdateNoteCommand,j as SheetsNoteModel,H as SheetsNoteResourceController,P as ToggleNotePopupMutation,Y as UniverSheetsNotePlugin,M as UpdateNoteMutation,F as UpdateNotePositionMutation};
@@ -1,5 +1,20 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { IUpdateNoteMutationParams } from '../mutations/note.mutation';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICommand } from '@univerjs/core';
17
+ import type { IUpdateNoteMutationParams } from '../mutations/note.mutation';
3
18
  export declare const SheetDeleteNoteCommand: ICommand;
4
19
  export declare const SheetToggleNotePopupCommand: ICommand;
5
20
  export declare const SheetUpdateNoteCommand: ICommand<IUpdateNoteMutationParams>;
@@ -1,5 +1,20 @@
1
- import { IMutation } from '@univerjs/core';
2
- import { ISheetNote } from '../../models/sheets-note.model';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IMutation } from '@univerjs/core';
17
+ import type { ISheetNote } from '../../models/sheets-note.model';
3
18
  export interface IUpdateNoteMutationParams {
4
19
  unitId: string;
5
20
  sheetId: string;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  import { Disposable, ICommandService } from '@univerjs/core';
2
17
  import { RefRangeService, SheetsSelectionsService } from '@univerjs/sheets';
3
18
  import { SheetsNoteModel } from '../models/sheets-note.model';