@univerjs/sheets-note 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,599 +1 @@
1
- var F = Object.defineProperty;
2
- var q = (i, r, e) => r in i ? F(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
3
- var _ = (i, r, e) => q(i, typeof r != "symbol" ? r + "" : r, e);
4
- import { Disposable as U, generateRandomId as G, CommandType as N, IUniverInstanceService as E, ICommandService as v, IUndoRedoService as D, IResourceManagerService as K, Inject as f, UniverInstanceType as C, sequenceExecuteAsync as Y, DependentOn as Q, IConfigService as X, Injector as Z, Plugin as k, merge as ee, touchDependencies as W } from "@univerjs/core";
5
- import { getSheetCommandTarget as j, SheetsSelectionsService as x, SheetInterceptorService as te, RemoveSheetCommand as se, CopySheetCommand as oe, RefRangeService as ne, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as re, UniverSheetsPlugin as ie } from "@univerjs/sheets";
6
- import { Subject as ae, filter as B, map as L } from "rxjs";
7
- class g extends U {
8
- constructor() {
9
- super(...arguments);
10
- _(this, "_notesMap", /* @__PURE__ */ new Map());
11
- _(this, "_change$", new ae());
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
- B(({ unitId: s, subUnitId: o }) => s === e && o === t),
36
- L(() => {
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
- B(({ unitId: n, subUnitId: a, oldNote: c }) => n !== e || a !== t || !c ? !1 : c.row === s && c.col === o),
47
- L((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 || G(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 m = {
98
- id: "sheet.mutation.update-note",
99
- type: N.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: N.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
- }, $ = {
112
- id: "sheet.mutation.toggle-note-popup",
113
- type: N.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
- }, T = {
119
- id: "sheet.mutation.update-note-position",
120
- type: N.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
- }, ce = {
126
- id: "sheet.command.delete-note",
127
- type: N.COMMAND,
128
- handler: (i) => {
129
- const r = j(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(v), u = i.get(D), l = {
136
- id: M.id,
137
- params: {
138
- unitId: o,
139
- sheetId: n,
140
- noteId: d.id
141
- }
142
- }, p = {
143
- id: m.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
- }, de = {
159
- id: "sheet.command.toggle-note-popup",
160
- type: N.COMMAND,
161
- handler: (i) => {
162
- const r = j(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(v), u = i.get(D), l = {
169
- id: $.id,
170
- params: {
171
- unitId: o,
172
- sheetId: n,
173
- noteId: d.id
174
- }
175
- }, p = {
176
- id: $.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
- }, he = {
190
- id: "sheet.command.update-note",
191
- type: N.COMMAND,
192
- handler: (i, r) => {
193
- const e = j(i.get(E), r);
194
- if (!e) return !1;
195
- const t = i.get(v), s = i.get(D), 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: m.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 b = {
207
- id: m.id,
208
- params: {
209
- unitId: n,
210
- sheetId: a,
211
- row: c,
212
- col: d,
213
- note: { ...u }
214
- }
215
- };
216
- p.push(b);
217
- } else {
218
- const b = {
219
- id: M.id,
220
- params: {
221
- unitId: n,
222
- sheetId: a,
223
- row: c,
224
- col: d
225
- }
226
- };
227
- p.push(b);
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
- }, V = "SHEET_NOTE_PLUGIN";
236
- var ue = Object.getOwnPropertyDescriptor, le = (i, r, e, t) => {
237
- for (var s = t > 1 ? void 0 : t ? ue(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 R = 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: V,
270
- businesses: [C.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 === se.id) {
302
- const e = i.params, t = e.unitId || this._univerInstanceService.getCurrentUnitOfType(C.UNIVER_SHEET).getUnitId(), s = e.subUnitId || ((r = this._univerInstanceService.getCurrentUnitOfType(C.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: m.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 === oe.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: G(6) };
340
- a.push({
341
- id: m.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
- R = le([
368
- S(0, K),
369
- S(1, E),
370
- S(2, f(te)),
371
- S(3, f(g))
372
- ], R);
373
- const pe = "@univerjs/sheets-note", ge = "0.17.0", z = {
374
- name: pe,
375
- version: ge
376
- }, _e = "sheets-note.config", H = {};
377
- var me = Object.getOwnPropertyDescriptor, Ne = (i, r, e, t) => {
378
- for (var s = t > 1 ? void 0 : t ? me(r, e) : r, o = i.length - 1, n; o >= 0; o--)
379
- (n = i[o]) && (s = n(s) || s);
380
- return s;
381
- }, I = (i, r) => (e, t) => r(e, t, i);
382
- let y = class extends U {
383
- constructor(r, e, t, s) {
384
- super();
385
- _(this, "_disposableMap", /* @__PURE__ */ new Map());
386
- _(this, "_watcherMap", /* @__PURE__ */ new Map());
387
- _(this, "_handleRangeChange", (r, e, t, s, o, n, a) => n ? {
388
- redos: [{
389
- id: T.id,
390
- params: {
391
- unitId: r,
392
- sheetId: e,
393
- noteId: t.id,
394
- newPosition: {
395
- row: n.startRow,
396
- col: n.startColumn
397
- },
398
- silent: a
399
- }
400
- }],
401
- undos: [{
402
- id: T.id,
403
- params: {
404
- unitId: r,
405
- sheetId: e,
406
- noteId: t.id,
407
- newPosition: {
408
- row: s,
409
- col: o
410
- },
411
- note: t,
412
- silent: a
413
- }
414
- }]
415
- } : {
416
- redos: [{
417
- id: M.id,
418
- params: {
419
- unitId: r,
420
- sheetId: e,
421
- noteId: t.id
422
- }
423
- }],
424
- undos: [{
425
- id: m.id,
426
- params: {
427
- unitId: r,
428
- sheetId: e,
429
- row: s,
430
- col: o,
431
- note: t
432
- }
433
- }]
434
- });
435
- this._refRangeService = r, this._sheetsNoteModel = e, this._selectionManagerService = t, this._commandService = s, this._initData(), this._initRefRange();
436
- }
437
- _getIdWithUnitId(r, e, t, s) {
438
- return `${r}-${e}-${t}-${s}`;
439
- }
440
- _register(r, e, t, s, o) {
441
- const n = {
442
- startColumn: o,
443
- endColumn: o,
444
- startRow: s,
445
- endRow: s
446
- };
447
- this._disposableMap.set(
448
- this._getIdWithUnitId(r, e, s, o),
449
- this._refRangeService.registerRefRange(n, (a) => {
450
- const c = re(n, a, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
451
- return d && d.startColumn === n.startColumn && d.startRow === n.startRow ? {
452
- undos: [],
453
- redos: []
454
- } : this._handleRangeChange(r, e, t, s, o, d, !1);
455
- }, r, e)
456
- );
457
- }
458
- _watch(r, e, t, s, o) {
459
- const n = {
460
- startColumn: o,
461
- endColumn: o,
462
- startRow: s,
463
- endRow: s
464
- };
465
- this._watcherMap.set(
466
- this._getIdWithUnitId(r, e, s, o),
467
- this._refRangeService.watchRange(r, e, n, (a, c) => {
468
- const { redos: d } = this._handleRangeChange(r, e, t, a.startRow, a.startColumn, c, !0);
469
- Y(d, this._commandService, { onlyLocal: !0 });
470
- }, !0)
471
- );
472
- }
473
- _unwatch(r, e, t, s) {
474
- var n;
475
- const o = this._getIdWithUnitId(r, e, t, s);
476
- (n = this._watcherMap.get(o)) == null || n.dispose(), this._watcherMap.delete(o);
477
- }
478
- _unregister(r, e, t, s) {
479
- var n;
480
- const o = this._getIdWithUnitId(r, e, t, s);
481
- (n = this._disposableMap.get(o)) == null || n.dispose(), this._disposableMap.delete(o);
482
- }
483
- _initData() {
484
- const r = this._sheetsNoteModel.getNotes();
485
- for (const [e, t] of r)
486
- for (const [s, o] of t)
487
- o.forEach((n) => {
488
- this._register(e, s, n, n.row, n.col), this._watch(e, s, n, n.row, n.col);
489
- });
490
- }
491
- _initRefRange() {
492
- this.disposeWithMe(
493
- this._sheetsNoteModel.change$.subscribe((r) => {
494
- switch (r.type) {
495
- case "update": {
496
- 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);
497
- 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));
498
- break;
499
- }
500
- case "ref": {
501
- const { unitId: e, subUnitId: t, oldNote: s, newNote: o, silent: n } = r, { row: a, col: c } = s, { row: d, col: h } = o;
502
- 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);
503
- break;
504
- }
505
- }
506
- })
507
- );
508
- }
509
- };
510
- y = Ne([
511
- I(0, f(ne)),
512
- I(1, f(g)),
513
- I(2, f(x)),
514
- I(3, v)
515
- ], y);
516
- var fe = Object.getOwnPropertyDescriptor, Me = (i, r, e, t) => {
517
- for (var s = t > 1 ? void 0 : t ? fe(r, e) : r, o = i.length - 1, n; o >= 0; o--)
518
- (n = i[o]) && (s = n(s) || s);
519
- return s;
520
- }, we = (i, r) => (e, t) => r(e, t, i);
521
- let P = class extends U {
522
- constructor(i) {
523
- super(), this._commandService = i, this._initialize();
524
- }
525
- _initialize() {
526
- [
527
- T,
528
- $,
529
- m,
530
- M,
531
- ce,
532
- de,
533
- he
534
- ].forEach((i) => {
535
- this.disposeWithMe(
536
- this._commandService.registerCommand(i)
537
- );
538
- });
539
- }
540
- };
541
- P = Me([
542
- we(0, v)
543
- ], P);
544
- var ve = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, Ie = (i, r, e) => r in i ? ve(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e, Ce = (i, r, e, t) => {
545
- for (var s = t > 1 ? void 0 : t ? Se(r, e) : r, o = i.length - 1, n; o >= 0; o--)
546
- (n = i[o]) && (s = n(s) || s);
547
- return s;
548
- }, J = (i, r) => (e, t) => r(e, t, i), O = (i, r, e) => Ie(i, typeof r != "symbol" ? r + "" : r, e);
549
- let w = class extends k {
550
- constructor(i = H, r, e) {
551
- super(), this._config = i, this._configService = r, this._injector = e;
552
- const { ...t } = ee(
553
- {},
554
- H,
555
- this._config
556
- );
557
- this._configService.setConfig(_e, t);
558
- }
559
- onStarting() {
560
- [
561
- [g],
562
- [P],
563
- [R],
564
- [y]
565
- ].forEach((i) => {
566
- this._injector.add(i);
567
- }), W(this._injector, [
568
- [g],
569
- [P],
570
- [R]
571
- ]);
572
- }
573
- onReady() {
574
- W(this._injector, [
575
- [y]
576
- ]);
577
- }
578
- };
579
- O(w, "pluginName", V);
580
- O(w, "packageName", z.name);
581
- O(w, "version", z.version);
582
- O(w, "type", C.UNIVER_SHEET);
583
- w = Ce([
584
- Q(ie),
585
- J(1, X),
586
- J(2, f(Z))
587
- ], w);
588
- export {
589
- M as RemoveNoteMutation,
590
- ce as SheetDeleteNoteCommand,
591
- de as SheetToggleNotePopupCommand,
592
- he as SheetUpdateNoteCommand,
593
- g as SheetsNoteModel,
594
- R as SheetsNoteResourceController,
595
- $ as ToggleNotePopupMutation,
596
- w as UniverSheetsNotePlugin,
597
- m as UpdateNoteMutation,
598
- T as UpdateNotePositionMutation
599
- };
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.18.0`;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';