@univerjs/sheets-note 0.7.0-nightly.202504301607

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 ADDED
@@ -0,0 +1,439 @@
1
+ var j = Object.defineProperty;
2
+ var A = (i, r, e) => r in i ? j(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
3
+ var d = (i, r, e) => A(i, typeof r != "symbol" ? r + "" : r, e);
4
+ import { Disposable as S, ObjectMatrix as W, CommandType as l, Inject as _, ICommandService as g, sequenceExecuteAsync as L, IResourceManagerService as J, IUniverInstanceService as x, UniverInstanceType as U, DependentOn as H, IConfigService as z, Injector as G, Plugin as q, touchDependencies as y } from "@univerjs/core";
5
+ import { RefRangeService as F, SheetsSelectionsService as R, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as B, getSheetCommandTarget as D, UniverSheetsPlugin as K } from "@univerjs/sheets";
6
+ import { Subject as Q, filter as O, map as $ } from "rxjs";
7
+ class u extends S {
8
+ constructor() {
9
+ super(...arguments);
10
+ d(this, "_noteMatrix", /* @__PURE__ */ new Map());
11
+ d(this, "_change$", new Q());
12
+ d(this, "change$", this._change$.asObservable());
13
+ }
14
+ _ensureNoteMatrix(e, n) {
15
+ let t = this._noteMatrix.get(e);
16
+ t || (t = /* @__PURE__ */ new Map(), this._noteMatrix.set(e, t));
17
+ let s = t.get(n);
18
+ return s || (s = new W(), t.set(n, s)), s;
19
+ }
20
+ getSheetShowNotes$(e, n) {
21
+ return this._change$.pipe(
22
+ O(({ unitId: t, sheetId: s }) => t === e && s === n),
23
+ $(() => {
24
+ const t = this._ensureNoteMatrix(e, n), s = [];
25
+ return t.forValue((o, a, c) => {
26
+ c.show && s.push({ loc: { row: o, col: a, unitId: e, subUnitId: n }, note: c });
27
+ }), s;
28
+ })
29
+ );
30
+ }
31
+ getCellNoteChange$(e, n, t, s) {
32
+ return this._change$.pipe(
33
+ O(({ unitId: o, sheetId: a, row: c, col: h }) => o === e && a === n && c === t && h === s),
34
+ $(({ note: o }) => o)
35
+ );
36
+ }
37
+ updateNote(e, n, t, s, o, a) {
38
+ const c = this._ensureNoteMatrix(e, n), h = c.getValue(t, s);
39
+ c.setValue(t, s, o), this._change$.next({ unitId: e, sheetId: n, row: t, col: s, type: "update", note: o, oldNote: h, silent: a });
40
+ }
41
+ removeNote(e, n, t, s, o) {
42
+ const a = this._ensureNoteMatrix(e, n), c = a.getValue(t, s);
43
+ a.realDeleteValue(t, s), this._change$.next({ unitId: e, sheetId: n, row: t, col: s, type: "update", note: null, oldNote: c, silent: o });
44
+ }
45
+ toggleNotePopup(e, n, t, s, o) {
46
+ const a = this._ensureNoteMatrix(e, n), c = a.getValue(t, s);
47
+ if (c) {
48
+ c.show = !c.show;
49
+ const h = { ...c, show: c.show };
50
+ a.setValue(t, s, h), this._change$.next({
51
+ unitId: e,
52
+ sheetId: n,
53
+ row: t,
54
+ col: s,
55
+ type: "update",
56
+ note: h,
57
+ oldNote: c,
58
+ silent: o
59
+ });
60
+ }
61
+ }
62
+ updateNotePosition(e, n, t, s, o, a, c) {
63
+ const h = this._ensureNoteMatrix(e, n), p = h.getValue(t, s);
64
+ p && (h.realDeleteValue(t, s), h.setValue(o, a, p), this._change$.next({
65
+ unitId: e,
66
+ sheetId: n,
67
+ row: t,
68
+ col: s,
69
+ type: "ref",
70
+ newPosition: { row: o, col: a },
71
+ note: p,
72
+ silent: c
73
+ }));
74
+ }
75
+ getNote(e, n, t, s) {
76
+ return this._ensureNoteMatrix(e, n).getValue(t, s);
77
+ }
78
+ getUnitNotes(e) {
79
+ return this._noteMatrix.get(e);
80
+ }
81
+ getSheetNotes(e, n) {
82
+ const t = this._noteMatrix.get(e);
83
+ if (t)
84
+ return t.get(n);
85
+ }
86
+ getNotes() {
87
+ return this._noteMatrix;
88
+ }
89
+ deleteUnitNotes(e) {
90
+ this._noteMatrix.delete(e);
91
+ }
92
+ }
93
+ const I = {
94
+ id: "sheet.mutation.update-note",
95
+ type: l.MUTATION,
96
+ handler: (i, r) => {
97
+ const { unitId: e, sheetId: n, row: t, col: s, note: o, silent: a } = r;
98
+ return i.get(u).updateNote(e, n, t, s, o, a), !0;
99
+ }
100
+ }, P = {
101
+ id: "sheet.mutation.remove-note",
102
+ type: l.MUTATION,
103
+ handler: (i, r) => {
104
+ const { unitId: e, sheetId: n, row: t, col: s, silent: o } = r;
105
+ return i.get(u).removeNote(e, n, t, s, o), !0;
106
+ }
107
+ }, E = {
108
+ id: "sheet.mutation.toggle-note-popup",
109
+ type: l.MUTATION,
110
+ handler: (i, r) => {
111
+ const { unitId: e, sheetId: n, row: t, col: s, silent: o } = r;
112
+ return i.get(u).toggleNotePopup(e, n, t, s, o), !0;
113
+ }
114
+ }, C = {
115
+ id: "sheet.mutation.update-note-position",
116
+ type: l.MUTATION,
117
+ handler: (i, r) => {
118
+ const { unitId: e, sheetId: n, row: t, col: s, newPosition: o, silent: a } = r;
119
+ return i.get(u).updateNotePosition(e, n, t, s, o.row, o.col, a), !0;
120
+ }
121
+ };
122
+ var X = Object.getOwnPropertyDescriptor, Y = (i, r, e, n) => {
123
+ for (var t = n > 1 ? void 0 : n ? X(r, e) : r, s = i.length - 1, o; s >= 0; s--)
124
+ (o = i[s]) && (t = o(t) || t);
125
+ return t;
126
+ }, m = (i, r) => (e, n) => r(e, n, i);
127
+ let N = class extends S {
128
+ constructor(r, e, n, t) {
129
+ super();
130
+ d(this, "_disposableMap", /* @__PURE__ */ new Map());
131
+ d(this, "_watcherMap", /* @__PURE__ */ new Map());
132
+ d(this, "_handleRangeChange", (r, e, n, t, s, o, a) => o ? {
133
+ redos: [{
134
+ id: C.id,
135
+ params: {
136
+ unitId: r,
137
+ sheetId: e,
138
+ row: t,
139
+ col: s,
140
+ newPosition: {
141
+ row: o.startRow,
142
+ col: o.startColumn
143
+ },
144
+ silent: a
145
+ }
146
+ }],
147
+ undos: [{
148
+ id: C.id,
149
+ params: {
150
+ unitId: r,
151
+ sheetId: e,
152
+ row: o.startRow,
153
+ col: o.startColumn,
154
+ newPosition: {
155
+ row: t,
156
+ col: s
157
+ },
158
+ note: n,
159
+ silent: a
160
+ }
161
+ }]
162
+ } : {
163
+ redos: [{
164
+ id: P.id,
165
+ params: {
166
+ unitId: r,
167
+ sheetId: e,
168
+ row: t,
169
+ col: s
170
+ }
171
+ }],
172
+ undos: [{
173
+ id: I.id,
174
+ params: {
175
+ unitId: r,
176
+ sheetId: e,
177
+ row: t,
178
+ col: s,
179
+ note: n
180
+ }
181
+ }]
182
+ });
183
+ this._refRangeService = r, this._sheetsNoteModel = e, this._selectionManagerService = n, this._commandService = t, this._initData(), this._initRefRange();
184
+ }
185
+ _getIdWithUnitId(r, e, n, t) {
186
+ return `${r}-${e}-${n}-${t}`;
187
+ }
188
+ _register(r, e, n, t, s) {
189
+ const o = {
190
+ startColumn: s,
191
+ endColumn: s,
192
+ startRow: t,
193
+ endRow: t
194
+ };
195
+ this._disposableMap.set(
196
+ this._getIdWithUnitId(r, e, t, s),
197
+ this._refRangeService.registerRefRange(o, (a) => {
198
+ const c = B(o, a, { selectionManagerService: this._selectionManagerService }), h = Array.isArray(c) ? c[0] : c;
199
+ return h && h.startColumn === o.startColumn && h.startRow === o.startRow ? {
200
+ undos: [],
201
+ redos: []
202
+ } : this._handleRangeChange(r, e, n, t, s, h, !1);
203
+ }, r, e)
204
+ );
205
+ }
206
+ _watch(r, e, n, t, s) {
207
+ const o = {
208
+ startColumn: s,
209
+ endColumn: s,
210
+ startRow: t,
211
+ endRow: t
212
+ };
213
+ this._watcherMap.set(
214
+ this._getIdWithUnitId(r, e, t, s),
215
+ this._refRangeService.watchRange(r, e, o, (a, c) => {
216
+ const { redos: h } = this._handleRangeChange(r, e, n, a.startRow, a.startColumn, c, !0);
217
+ L(h, this._commandService, { onlyLocal: !0 });
218
+ }, !0)
219
+ );
220
+ }
221
+ _unwatch(r, e, n, t) {
222
+ var o;
223
+ const s = this._getIdWithUnitId(r, e, n, t);
224
+ (o = this._watcherMap.get(s)) == null || o.dispose(), this._watcherMap.delete(s);
225
+ }
226
+ _unregister(r, e, n, t) {
227
+ var o;
228
+ const s = this._getIdWithUnitId(r, e, n, t);
229
+ (o = this._disposableMap.get(s)) == null || o.dispose(), this._disposableMap.delete(s);
230
+ }
231
+ _initData() {
232
+ const r = this._sheetsNoteModel.getNotes();
233
+ for (const [e, n] of r)
234
+ for (const [t, s] of n)
235
+ s.forValue((o, a, c) => (c && (this._register(e, t, c, o, a), this._watch(e, t, c, o, a)), !0));
236
+ }
237
+ _initRefRange() {
238
+ this.disposeWithMe(
239
+ this._sheetsNoteModel.change$.subscribe((r) => {
240
+ switch (r.type) {
241
+ case "update": {
242
+ const { unitId: e, sheetId: n, row: t, col: s, note: o } = r, a = this._getIdWithUnitId(e, n, t, s);
243
+ o ? this._disposableMap.has(a) || (this._register(e, n, o, t, s), this._watch(e, n, o, t, s)) : (this._unregister(e, n, t, s), this._unwatch(e, n, t, s));
244
+ break;
245
+ }
246
+ case "ref": {
247
+ const { unitId: e, sheetId: n, row: t, col: s, newPosition: o, note: a, silent: c } = r;
248
+ this._unregister(e, n, t, s), c || (this._unwatch(e, n, t, s), this._watch(e, n, a, o.row, o.col)), this._register(e, n, a, o.row, o.col);
249
+ break;
250
+ }
251
+ }
252
+ })
253
+ );
254
+ }
255
+ };
256
+ N = Y([
257
+ m(0, _(F)),
258
+ m(1, _(u)),
259
+ m(2, _(R)),
260
+ m(3, g)
261
+ ], N);
262
+ var Z = Object.getOwnPropertyDescriptor, k = (i, r, e, n) => {
263
+ for (var t = n > 1 ? void 0 : n ? Z(r, e) : r, s = i.length - 1, o; s >= 0; s--)
264
+ (o = i[s]) && (t = o(t) || t);
265
+ return t;
266
+ }, w = (i, r) => (e, n) => r(e, n, i);
267
+ let M = class extends S {
268
+ constructor(i, r, e) {
269
+ super(), this._resourceManagerService = i, this._univerInstanceService = r, this._sheetsNoteModel = e, this._initSnapshot();
270
+ }
271
+ _initSnapshot() {
272
+ const i = (e) => {
273
+ const n = this._sheetsNoteModel.getUnitNotes(e);
274
+ if (!n)
275
+ return "";
276
+ const t = {};
277
+ return n.forEach((s, o) => {
278
+ const a = {};
279
+ s.forValue((c, h, p) => {
280
+ a[c] || (a[c] = {}), a[c][h] = p;
281
+ }), Object.keys(a).length > 0 && (t[o] = a);
282
+ }), JSON.stringify(t);
283
+ }, r = (e) => {
284
+ if (!e)
285
+ return {};
286
+ try {
287
+ return JSON.parse(e);
288
+ } catch {
289
+ return {};
290
+ }
291
+ };
292
+ this.disposeWithMe(
293
+ this._resourceManagerService.registerPluginResource({
294
+ pluginName: V,
295
+ businesses: [U.UNIVER_SHEET],
296
+ toJson: (e) => i(e),
297
+ parseJson: (e) => r(e),
298
+ onUnLoad: (e) => {
299
+ this._sheetsNoteModel.deleteUnitNotes(e);
300
+ },
301
+ onLoad: (e, n) => {
302
+ Object.entries(n).forEach(([t, s]) => {
303
+ Object.entries(s).forEach(([o, a]) => {
304
+ Object.entries(a).forEach(([c, h]) => {
305
+ this._sheetsNoteModel.updateNote(
306
+ e,
307
+ t,
308
+ Number(o),
309
+ Number(c),
310
+ h
311
+ );
312
+ });
313
+ });
314
+ });
315
+ }
316
+ })
317
+ );
318
+ }
319
+ };
320
+ M = k([
321
+ w(0, J),
322
+ w(1, x),
323
+ w(2, _(u))
324
+ ], M);
325
+ const ee = {
326
+ id: "sheet.command.delete-note",
327
+ type: l.COMMAND,
328
+ handler: (i, r) => {
329
+ const e = i.get(x), n = D(e);
330
+ if (!n) return !1;
331
+ const s = i.get(R).getCurrentLastSelection();
332
+ if (!(s != null && s.primary)) return !1;
333
+ const { actualColumn: o, actualRow: a } = s.primary;
334
+ return i.get(g).executeCommand(P.id, {
335
+ unitId: n.unitId,
336
+ sheetId: n.subUnitId,
337
+ row: a,
338
+ col: o
339
+ });
340
+ }
341
+ }, te = {
342
+ id: "sheet.command.toggle-note-popup",
343
+ type: l.COMMAND,
344
+ handler: (i, r) => {
345
+ const e = i.get(x), n = D(e);
346
+ if (!n) return !1;
347
+ const s = i.get(R).getCurrentLastSelection();
348
+ if (!(s != null && s.primary)) return !1;
349
+ const { actualColumn: o, actualRow: a } = s.primary;
350
+ return i.get(g).executeCommand(E.id, {
351
+ unitId: n.unitId,
352
+ sheetId: n.subUnitId,
353
+ row: a,
354
+ col: o
355
+ });
356
+ }
357
+ }, se = {
358
+ id: "sheet.command.update-note",
359
+ type: l.COMMAND,
360
+ handler: (i, r) => i.get(g).syncExecuteCommand(I.id, r)
361
+ };
362
+ var ne = Object.getOwnPropertyDescriptor, re = (i, r, e, n) => {
363
+ for (var t = n > 1 ? void 0 : n ? ne(r, e) : r, s = i.length - 1, o; s >= 0; s--)
364
+ (o = i[s]) && (t = o(t) || t);
365
+ return t;
366
+ }, oe = (i, r) => (e, n) => r(e, n, i);
367
+ let f = class extends S {
368
+ constructor(i) {
369
+ super(), this._commandService = i, this._initialize();
370
+ }
371
+ _initialize() {
372
+ [
373
+ C,
374
+ E,
375
+ I,
376
+ P,
377
+ ee,
378
+ te,
379
+ se
380
+ ].forEach((i) => {
381
+ this.disposeWithMe(
382
+ this._commandService.registerCommand(i)
383
+ );
384
+ });
385
+ }
386
+ };
387
+ f = re([
388
+ oe(0, g)
389
+ ], f);
390
+ var ie = Object.defineProperty, ae = Object.getOwnPropertyDescriptor, ce = (i, r, e) => r in i ? ie(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e, he = (i, r, e, n) => {
391
+ for (var t = n > 1 ? void 0 : n ? ae(r, e) : r, s = i.length - 1, o; s >= 0; s--)
392
+ (o = i[s]) && (t = o(t) || t);
393
+ return t;
394
+ }, b = (i, r) => (e, n) => r(e, n, i), T = (i, r, e) => ce(i, typeof r != "symbol" ? r + "" : r, e);
395
+ const V = "SHEET_NOTE_PLUGIN";
396
+ let v = class extends q {
397
+ constructor(i, r) {
398
+ super(), this._configService = i, this._injector = r;
399
+ }
400
+ onStarting() {
401
+ [
402
+ [u],
403
+ [f],
404
+ [M],
405
+ [N]
406
+ ].forEach((i) => {
407
+ this._injector.add(i);
408
+ }), y(this._injector, [
409
+ [u],
410
+ [f],
411
+ [M]
412
+ ]);
413
+ }
414
+ onReady() {
415
+ y(this._injector, [
416
+ [N]
417
+ ]);
418
+ }
419
+ };
420
+ T(v, "pluginName", V);
421
+ T(v, "type", U.UNIVER_SHEET);
422
+ v = he([
423
+ H(K),
424
+ b(0, z),
425
+ b(1, _(G))
426
+ ], v);
427
+ export {
428
+ V as PLUGIN_NAME,
429
+ P as RemoveNoteMutation,
430
+ ee as SheetDeleteNoteCommand,
431
+ te as SheetToggleNotePopupCommand,
432
+ se as SheetUpdateNoteCommand,
433
+ u as SheetsNoteModel,
434
+ v as SheetsNotePlugin,
435
+ M as SheetsNoteResourceController,
436
+ E as ToggleNotePopupMutation,
437
+ I as UpdateNoteMutation,
438
+ C as UpdateNotePositionMutation
439
+ };
@@ -0,0 +1,5 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ import { IUpdateNoteMutationParams } from '../mutations/note.mutation';
3
+ export declare const SheetDeleteNoteCommand: ICommand;
4
+ export declare const SheetToggleNotePopupCommand: ICommand;
5
+ export declare const SheetUpdateNoteCommand: ICommand<IUpdateNoteMutationParams>;
@@ -0,0 +1,39 @@
1
+ import { IMutation } from '@univerjs/core';
2
+ import { ISheetNote } from '../../models/sheets-note.model';
3
+ export interface IUpdateNoteMutationParams {
4
+ unitId: string;
5
+ sheetId: string;
6
+ row: number;
7
+ col: number;
8
+ note: ISheetNote;
9
+ silent?: boolean;
10
+ }
11
+ export declare const UpdateNoteMutation: IMutation<IUpdateNoteMutationParams>;
12
+ export interface IRemoveNoteMutationParams {
13
+ unitId: string;
14
+ sheetId: string;
15
+ row: number;
16
+ col: number;
17
+ silent?: boolean;
18
+ }
19
+ export declare const RemoveNoteMutation: IMutation<IRemoveNoteMutationParams>;
20
+ export interface IToggleNotePopupMutationParams {
21
+ unitId: string;
22
+ sheetId: string;
23
+ row: number;
24
+ col: number;
25
+ silent?: boolean;
26
+ }
27
+ export declare const ToggleNotePopupMutation: IMutation<IToggleNotePopupMutationParams>;
28
+ export interface IUpdateNotePositionMutationParams {
29
+ unitId: string;
30
+ sheetId: string;
31
+ row: number;
32
+ col: number;
33
+ newPosition: {
34
+ row: number;
35
+ col: number;
36
+ };
37
+ silent?: boolean;
38
+ }
39
+ export declare const UpdateNotePositionMutation: IMutation<IUpdateNotePositionMutationParams>;
@@ -0,0 +1,20 @@
1
+ import { Disposable, ICommandService } from '@univerjs/core';
2
+ import { RefRangeService, SheetsSelectionsService } from '@univerjs/sheets';
3
+ import { SheetsNoteModel } from '../models/sheets-note.model';
4
+ export declare class SheetsNoteRefRangeController extends Disposable {
5
+ private readonly _refRangeService;
6
+ private readonly _sheetsNoteModel;
7
+ private readonly _selectionManagerService;
8
+ private readonly _commandService;
9
+ private _disposableMap;
10
+ private _watcherMap;
11
+ constructor(_refRangeService: RefRangeService, _sheetsNoteModel: SheetsNoteModel, _selectionManagerService: SheetsSelectionsService, _commandService: ICommandService);
12
+ private _getIdWithUnitId;
13
+ private _handleRangeChange;
14
+ private _register;
15
+ private _watch;
16
+ private _unwatch;
17
+ private _unregister;
18
+ private _initData;
19
+ private _initRefRange;
20
+ }
@@ -0,0 +1,9 @@
1
+ import { Disposable, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
2
+ import { SheetsNoteModel } from '../models/sheets-note.model';
3
+ export declare class SheetsNoteResourceController extends Disposable {
4
+ private readonly _resourceManagerService;
5
+ private readonly _univerInstanceService;
6
+ private readonly _sheetsNoteModel;
7
+ constructor(_resourceManagerService: IResourceManagerService, _univerInstanceService: IUniverInstanceService, _sheetsNoteModel: SheetsNoteModel);
8
+ private _initSnapshot;
9
+ }
@@ -0,0 +1,6 @@
1
+ import { Disposable, ICommandService } from '@univerjs/core';
2
+ export declare class SheetsNoteController extends Disposable {
3
+ private readonly _commandService;
4
+ constructor(_commandService: ICommandService);
5
+ private _initialize;
6
+ }