@univerjs/sheets-thread-comment 0.1.12

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.
@@ -0,0 +1,966 @@
1
+ var Re = Object.defineProperty;
2
+ var Ee = (o, e, n) => e in o ? Re(o, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[e] = n;
3
+ var _ = (o, e, n) => (Ee(o, typeof e != "symbol" ? e + "" : e, n), n);
4
+ import { Inject as h, Injector as pe } from "@wendellhu/redi";
5
+ import { Inject as Sn, Injector as gn } from "@wendellhu/redi";
6
+ import { Disposable as O, ObjectMatrix as $e, UniverInstanceType as S, IUniverInstanceService as $, DisposableCollection as xe, Tools as _e, CommandType as Ne, ICommandService as Q, OnLifecycle as x, LifecycleStages as N, LocaleService as De, toDisposable as je, Range as Ve } from "@univerjs/core";
7
+ import { ICommandService as Mn, Plugin as Pn, UniverInstanceType as bn } from "@univerjs/core";
8
+ import { ThreadCommentTree as Ae, ThreadCommentPanelService as ee, ThreadCommentPanel as Le, ToggleSheetCommentPanelOperation as He, SetActiveCommentOperation as re, THREAD_COMMENT_PANEL as Be, UniverThreadCommentUIPlugin as We } from "@univerjs/thread-comment-ui";
9
+ import { IThreadCommentMentionDataService as wn, UniverThreadCommentUIPlugin as yn } from "@univerjs/thread-comment-ui";
10
+ import { IZenZoneService as Fe, useObservable as oe, KeyCode as Ze, MetaKeys as ie, MenuItemType as ve, MenuPosition as fe, getMenuHiddenObservable as Ce, ComponentManager as ze, IMenuService as Ke, IShortcutService as Ge } from "@univerjs/ui";
11
+ import { SelectionManagerService as Ye, getSheetCommandTarget as ke, SetSelectionsOperation as qe, SelectionMoveType as Xe, SetWorksheetActiveOperation as Je, RefRangeService as Qe, handleDefaultRangeChangeWithEffectRefCommands as et, SheetInterceptorService as Se, INTERCEPTOR_POINT as tt, RemoveSheetCommand as nt } from "@univerjs/sheets";
12
+ import { singleReferenceToGrid as y, serializeRange as J } from "@univerjs/engine-formula";
13
+ import { SheetCanvasPopManagerService as rt, IMarkSelectionService as ot, whenSheetEditorFocused as it, ScrollToCellCommand as st, SheetSkeletonManagerService as at, ISheetClipboardService as ct, COPY_TYPE as mt, HoverManagerService as dt } from "@univerjs/sheets-ui";
14
+ import { ThreadCommentModel as G, DeleteCommentMutation as V, AddCommentMutation as K, UpdateCommentRefMutation as se } from "@univerjs/thread-comment";
15
+ import { IThreadCommentDataSourceService as On } from "@univerjs/thread-comment";
16
+ import { useDependency as w, useObservable as ae } from "@wendellhu/redi/react-bindings";
17
+ import ge, { forwardRef as Ie, useRef as Me, createElement as Pe, useMemo as ut, useCallback as ce, useEffect as ht } from "react";
18
+ import { Subject as lt, BehaviorSubject as pt, map as _t } from "rxjs";
19
+ import { IRenderManagerService as vt } from "@univerjs/engine-render";
20
+ var f = function() {
21
+ return f = Object.assign || function(o) {
22
+ for (var e, n = 1, r = arguments.length; n < r; n++) {
23
+ e = arguments[n];
24
+ for (var t in e)
25
+ Object.prototype.hasOwnProperty.call(e, t) && (o[t] = e[t]);
26
+ }
27
+ return o;
28
+ }, f.apply(this, arguments);
29
+ }, ft = function(o, e) {
30
+ var n = {};
31
+ for (var r in o)
32
+ Object.prototype.hasOwnProperty.call(o, r) && e.indexOf(r) < 0 && (n[r] = o[r]);
33
+ if (o != null && typeof Object.getOwnPropertySymbols == "function")
34
+ for (var t = 0, r = Object.getOwnPropertySymbols(o); t < r.length; t++)
35
+ e.indexOf(r[t]) < 0 && Object.prototype.propertyIsEnumerable.call(o, r[t]) && (n[r[t]] = o[r[t]]);
36
+ return n;
37
+ }, be = Ie(function(o, e) {
38
+ var n = o.icon, r = o.id, t = o.className, i = o.extend, s = ft(o, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(r, " ").concat(t || "").trim(), c = Me("_".concat(gt()));
39
+ return Te(n, "".concat(r), { defIds: n.defIds, idSuffix: c.current }, f({ ref: e, className: a }, s), i);
40
+ });
41
+ function Te(o, e, n, r, t) {
42
+ return Pe(o.tag, f(f({ key: e }, Ct(o, n, t)), r), (St(o, n).children || []).map(function(i, s) {
43
+ return Te(i, "".concat(e, "-").concat(o.tag, "-").concat(s), n, void 0, t);
44
+ }));
45
+ }
46
+ function Ct(o, e, n) {
47
+ var r = f({}, o.attrs);
48
+ n != null && n.colorChannel1 && r.fill === "colorChannel1" && (r.fill = n.colorChannel1);
49
+ var t = e.defIds;
50
+ return !t || t.length === 0 || (o.tag === "use" && r["xlink:href"] && (r["xlink:href"] = r["xlink:href"] + e.idSuffix), Object.entries(r).forEach(function(i) {
51
+ var s = i[0], a = i[1];
52
+ typeof a == "string" && (r[s] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
53
+ })), r;
54
+ }
55
+ function St(o, e) {
56
+ var n, r = e.defIds;
57
+ return !r || r.length === 0 ? o : o.tag === "defs" && (!((n = o.children) === null || n === void 0) && n.length) ? f(f({}, o), { children: o.children.map(function(t) {
58
+ return typeof t.attrs.id == "string" && r && r.indexOf(t.attrs.id) > -1 ? f(f({}, t), { attrs: f(f({}, t.attrs), { id: t.attrs.id + e.idSuffix }) }) : t;
59
+ }) }) : o;
60
+ }
61
+ function gt() {
62
+ return Math.random().toString(36).substring(2, 8);
63
+ }
64
+ be.displayName = "UniverIcon";
65
+ var It = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, we = Ie(function(o, e) {
66
+ return Pe(be, Object.assign({}, o, {
67
+ id: "comment-single",
68
+ ref: e,
69
+ icon: It
70
+ }));
71
+ });
72
+ we.displayName = "CommentSingle";
73
+ var Mt = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, bt = (o, e, n, r) => {
74
+ for (var t = r > 1 ? void 0 : r ? Pt(e, n) : e, i = o.length - 1, s; i >= 0; i--)
75
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
76
+ return r && t && Mt(e, n, t), t;
77
+ }, me = (o, e) => (n, r) => e(n, r, o);
78
+ let T = class extends O {
79
+ constructor(e, n) {
80
+ super();
81
+ _(this, "_matrixMap", /* @__PURE__ */ new Map());
82
+ _(this, "_locationMap", /* @__PURE__ */ new Map());
83
+ _(this, "_commentUpdate$", new lt());
84
+ _(this, "commentUpdate$", this._commentUpdate$.asObservable());
85
+ this._threadCommentModel = e, this._univerInstanceService = n, this._init();
86
+ }
87
+ _init() {
88
+ this._initData(), this._initUpdateTransform();
89
+ }
90
+ _ensureCommentMatrix(e, n) {
91
+ let r = this._matrixMap.get(e);
92
+ r || (r = /* @__PURE__ */ new Map(), this._matrixMap.set(e, r));
93
+ let t = r.get(n);
94
+ return t || (t = new $e(), r.set(n, t)), t;
95
+ }
96
+ _ensureCommentLocationMap(e, n) {
97
+ let r = this._locationMap.get(e);
98
+ r || (r = /* @__PURE__ */ new Map(), this._locationMap.set(e, r));
99
+ let t = r.get(n);
100
+ return t || (t = /* @__PURE__ */ new Map(), r.set(n, t)), t;
101
+ }
102
+ _ensure(e, n) {
103
+ const r = this._ensureCommentMatrix(e, n), t = this._ensureCommentLocationMap(e, n);
104
+ return { matrix: r, locationMap: t };
105
+ }
106
+ _initData() {
107
+ const e = this._threadCommentModel.getAll();
108
+ for (const n in e) {
109
+ const r = e[n];
110
+ for (const t in r) {
111
+ const i = r[t];
112
+ for (const s in i) {
113
+ const a = i[s];
114
+ this._addComment(n, t, a);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ _addComment(e, n, r) {
120
+ const t = y(r.ref), i = r.parentId, { row: s, column: a } = t, c = r.id, { matrix: m, locationMap: u } = this._ensure(e, n);
121
+ !i && s >= 0 && a >= 0 && (m.setValue(s, a, c), u.set(c, { row: s, column: a })), this._commentUpdate$.next({
122
+ unitId: e,
123
+ subUnitId: n,
124
+ payload: r,
125
+ type: "add",
126
+ ...t
127
+ });
128
+ }
129
+ _initUpdateTransform() {
130
+ this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((e) => {
131
+ const { unitId: n, subUnitId: r } = e;
132
+ try {
133
+ if (this._univerInstanceService.getUnitType(n) !== S.UNIVER_SHEET)
134
+ return;
135
+ } catch {
136
+ }
137
+ const { matrix: t, locationMap: i } = this._ensure(n, r);
138
+ switch (e.type) {
139
+ case "add": {
140
+ this._addComment(e.unitId, e.subUnitId, e.payload);
141
+ break;
142
+ }
143
+ case "delete": {
144
+ const { isRoot: s, comment: a } = e.payload, c = y(a.ref);
145
+ if (s) {
146
+ const { row: m, column: u } = c;
147
+ m >= 0 && u >= 0 && t.realDeleteValue(m, u);
148
+ }
149
+ this._commentUpdate$.next({
150
+ ...e,
151
+ ...c
152
+ });
153
+ break;
154
+ }
155
+ case "update": {
156
+ const { commentId: s } = e.payload, a = this._threadCommentModel.getComment(n, r, s);
157
+ if (!a)
158
+ return;
159
+ const c = y(a.ref);
160
+ this._commentUpdate$.next({
161
+ ...e,
162
+ ...c
163
+ });
164
+ break;
165
+ }
166
+ case "updateRef": {
167
+ const s = y(e.payload.ref), { commentId: a } = e.payload, c = i.get(a);
168
+ if (!c)
169
+ return;
170
+ const { row: m, column: u } = c;
171
+ t.getValue(m, u) === a && (t.realDeleteValue(m, u), i.delete(a)), s.row >= 0 && s.column >= 0 && (t.setValue(s.row, s.column, a), i.set(a, { row: s.row, column: s.column })), this._commentUpdate$.next({
172
+ ...e,
173
+ ...s
174
+ });
175
+ break;
176
+ }
177
+ }
178
+ }));
179
+ }
180
+ getByLocation(e, n, r, t) {
181
+ return this._ensureCommentMatrix(e, n).getValue(r, t);
182
+ }
183
+ getComment(e, n, r) {
184
+ return this._threadCommentModel.getComment(e, n, r);
185
+ }
186
+ getCommentWithChildren(e, n, r, t) {
187
+ const s = this._ensureCommentMatrix(e, n).getValue(r, t);
188
+ if (s)
189
+ return this._threadCommentModel.getCommentWithChildren(e, n, s);
190
+ }
191
+ showCommentMarker(e, n, r, t) {
192
+ const i = this.getByLocation(e, n, r, t);
193
+ if (!i)
194
+ return !1;
195
+ const s = this.getComment(e, n, i);
196
+ return !!(s && !s.resolved);
197
+ }
198
+ };
199
+ T = bt([
200
+ me(0, h(G)),
201
+ me(1, $)
202
+ ], T);
203
+ const ye = "univer.sheet.thread-comment-modal", te = "comment-single", Ue = "univer.sheet.thread-comment";
204
+ var Tt = Object.defineProperty, wt = Object.getOwnPropertyDescriptor, yt = (o, e, n, r) => {
205
+ for (var t = r > 1 ? void 0 : r ? wt(e, n) : e, i = o.length - 1, s; i >= 0; i--)
206
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
207
+ return r && t && Tt(e, n, t), t;
208
+ }, de = (o, e) => (n, r) => e(n, r, o);
209
+ let U = class extends O {
210
+ constructor(e, n) {
211
+ super();
212
+ _(this, "_lastPopup", null);
213
+ _(this, "_activePopup");
214
+ _(this, "_activePopup$", new pt(null));
215
+ _(this, "activePopup$", this._activePopup$.asObservable());
216
+ this._canvasPopupManagerService = e, this._zenZoneService = n, this._initZenVisible();
217
+ }
218
+ get activePopup() {
219
+ return this._activePopup;
220
+ }
221
+ _initZenVisible() {
222
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((e) => {
223
+ e && this.hidePopup();
224
+ }));
225
+ }
226
+ showPopup(e, n) {
227
+ var m;
228
+ const { row: r, col: t, unitId: i, subUnitId: s } = e;
229
+ if (this._activePopup && r === this._activePopup.row && t === this._activePopup.col && i === this._activePopup.unitId && s === ((m = this.activePopup) == null ? void 0 : m.subUnitId)) {
230
+ this._activePopup = e, this._activePopup$.next(e);
231
+ return;
232
+ }
233
+ if (this._lastPopup && this._lastPopup.dispose(), this._zenZoneService.visible)
234
+ return;
235
+ this._activePopup = e, this._activePopup$.next(e);
236
+ const a = this._canvasPopupManagerService.attachPopupToCell(
237
+ r,
238
+ t,
239
+ {
240
+ componentKey: ye,
241
+ onClickOutside: () => {
242
+ this.hidePopup();
243
+ },
244
+ direction: "horizontal",
245
+ excludeOutside: [
246
+ ...Array.from(document.querySelectorAll(".univer-thread-comment")),
247
+ document.getElementById("thread-comment-add")
248
+ ].filter(Boolean)
249
+ }
250
+ );
251
+ if (!a)
252
+ throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");
253
+ const c = new xe();
254
+ c.add(a), c.add({
255
+ dispose: () => {
256
+ n == null || n();
257
+ }
258
+ }), this._lastPopup = c;
259
+ }
260
+ hidePopup() {
261
+ this._activePopup && (this._lastPopup && this._lastPopup.dispose(), this._lastPopup = null, this._activePopup = null, this._activePopup$.next(null));
262
+ }
263
+ persistPopup() {
264
+ !this._activePopup || !this._activePopup.temp || (this._activePopup = {
265
+ ...this._activePopup,
266
+ temp: !1
267
+ }, this._activePopup$.next(this._activePopup));
268
+ }
269
+ };
270
+ U = yt([
271
+ de(0, h(rt)),
272
+ de(1, Fe)
273
+ ], U);
274
+ const Ut = () => {
275
+ const o = w($), e = w(U), n = oe(e.activePopup$), r = w(T);
276
+ if (oe(r.commentUpdate$), !n)
277
+ return null;
278
+ const { row: t, col: i, unitId: s, subUnitId: a, trigger: c } = n, m = r.getByLocation(s, a, t, i), u = `${_e.chatAtABC(i)}${t + 1}`, l = () => {
279
+ e.hidePopup();
280
+ }, R = (g) => {
281
+ var I, M, E;
282
+ return (E = (M = (I = o.getCurrentUnitForType(S.UNIVER_SHEET)) == null ? void 0 : I.getSheetBySheetId(g)) == null ? void 0 : M.getName()) != null ? E : "";
283
+ };
284
+ return /* @__PURE__ */ ge.createElement(
285
+ Ae,
286
+ {
287
+ onClick: () => {
288
+ e.persistPopup();
289
+ },
290
+ prefix: "cell",
291
+ id: m,
292
+ unitId: s,
293
+ subUnitId: a,
294
+ type: S.UNIVER_SHEET,
295
+ refStr: u,
296
+ onClose: l,
297
+ getSubUnitName: R,
298
+ autoFocus: c === "context-menu"
299
+ }
300
+ );
301
+ }, Y = {
302
+ type: Ne.OPERATION,
303
+ id: "sheets.operation.show-comment-modal",
304
+ handler(o) {
305
+ var M;
306
+ const e = o.get(Ye), n = o.get($), r = o.get(U), t = o.get(ee), i = (M = e.getFirst()) == null ? void 0 : M.primary, s = e.getCurrent(), a = o.get(T);
307
+ if (!s || !i)
308
+ return !1;
309
+ const { unitId: c, sheetId: m } = s, u = ke(n, { unitId: c, subUnitId: m });
310
+ if (!u)
311
+ return !1;
312
+ const { workbook: l, worksheet: R } = u, g = {
313
+ workbook: l,
314
+ worksheet: R,
315
+ unitId: c,
316
+ subUnitId: m,
317
+ row: i.actualRow,
318
+ col: i.startColumn
319
+ };
320
+ r.showPopup(g);
321
+ const I = a.getByLocation(c, m, i.actualRow, i.startColumn);
322
+ return I && t.setActiveComment({
323
+ unitId: c,
324
+ subUnitId: m,
325
+ commentId: I,
326
+ trigger: "context-menu"
327
+ }), !0;
328
+ }
329
+ }, Ot = () => {
330
+ const o = w(ot), e = w($), n = w(G), r = w(U), t = e.getCurrentUnitForType(S.UNIVER_SHEET);
331
+ if (!t)
332
+ return null;
333
+ const i = t.getUnitId(), s = w(Q), a = ut(() => t.activeSheet$.pipe(_t((d) => d == null ? void 0 : d.getSheetId())), [t.activeSheet$]), c = ae(a, t.getActiveSheet().getSheetId()), m = Me(), u = w(ee), l = ae(u.activeCommentId$), R = ce((d) => {
334
+ const p = t.getSheets(), v = {};
335
+ return p.forEach((C, P) => {
336
+ v[C.getSheetId()] = P;
337
+ }), d.map((C) => {
338
+ var ne;
339
+ const P = y(C.ref), Oe = [(ne = v[C.subUnitId]) != null ? ne : 0, P.row, P.column];
340
+ return { ...C, p: Oe };
341
+ }).sort((C, P) => C.p[0] === P.p[0] ? C.p[1] === P.p[1] ? C.p[2] - P.p[2] : C.p[1] - P.p[1] : C.p[0] - P.p[0]);
342
+ }, [t]), g = ce((d) => {
343
+ if (d.unitId === i && d.subUnitId === c && !d.resolved) {
344
+ const { row: p, column: v } = y(d.ref);
345
+ if (!Number.isNaN(p) && !Number.isNaN(v))
346
+ return o.addShape({
347
+ range: {
348
+ startColumn: v,
349
+ endColumn: v,
350
+ startRow: p,
351
+ endRow: p
352
+ },
353
+ style: {
354
+ hasAutoFill: !1,
355
+ fill: "rgb(255, 189, 55, 0.35)",
356
+ strokeWidth: 1,
357
+ stroke: "#FFBD37",
358
+ widgets: {}
359
+ },
360
+ primary: null
361
+ });
362
+ }
363
+ }, [o, c, i]), I = (d) => {
364
+ var p, v;
365
+ return (v = (p = t.getSheetBySheetId(d)) == null ? void 0 : p.getName()) != null ? v : "";
366
+ }, M = () => {
367
+ s.executeCommand(Y.id);
368
+ }, E = () => {
369
+ r.hidePopup();
370
+ }, A = (d) => {
371
+ l && l.unitId === d.unitId && l.subUnitId === d.subUnitId && l.commentId === d.id || (m.current && (o.removeShape(m.current), m.current = null), m.current = g(d));
372
+ }, L = () => {
373
+ m.current && (o.removeShape(m.current), m.current = null);
374
+ };
375
+ return ht(() => {
376
+ if (!l)
377
+ return;
378
+ const d = n.getComment(l.unitId, l.subUnitId, l.commentId);
379
+ if (!d)
380
+ return;
381
+ const p = g(d);
382
+ return () => {
383
+ p && o.removeShape(p);
384
+ };
385
+ }, [g, l, n, o]), /* @__PURE__ */ ge.createElement(
386
+ Le,
387
+ {
388
+ unitId: i,
389
+ subUnitId$: a,
390
+ type: S.UNIVER_SHEET,
391
+ onAdd: M,
392
+ getSubUnitName: I,
393
+ onResolve: E,
394
+ sortComments: R,
395
+ onItemEnter: A,
396
+ onItemLeave: L
397
+ }
398
+ );
399
+ }, Rt = {
400
+ sheetThreadComment: {
401
+ menu: {
402
+ addComment: "添加评论",
403
+ commentManagement: "评论管理"
404
+ }
405
+ }
406
+ }, Et = (o) => ({
407
+ id: Y.id,
408
+ type: ve.BUTTON,
409
+ positions: [fe.CONTEXT_MENU],
410
+ icon: te,
411
+ title: "sheetThreadComment.menu.addComment",
412
+ hidden$: Ce(o, S.UNIVER_SHEET)
413
+ }), $t = (o) => ({
414
+ id: He.id,
415
+ type: ve.BUTTON,
416
+ icon: te,
417
+ tooltip: "sheetThreadComment.menu.commentManagement",
418
+ positions: fe.TOOLBAR_START,
419
+ hidden$: Ce(o, S.UNIVER_SHEET)
420
+ }), xt = {
421
+ id: Y.id,
422
+ binding: Ze.M | ie.CTRL_COMMAND | ie.ALT,
423
+ preconditions: it
424
+ };
425
+ var Nt = Object.defineProperty, Dt = Object.getOwnPropertyDescriptor, jt = (o, e, n, r) => {
426
+ for (var t = r > 1 ? void 0 : r ? Dt(e, n) : e, i = o.length - 1, s; i >= 0; i--)
427
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
428
+ return r && t && Nt(e, n, t), t;
429
+ }, b = (o, e) => (n, r) => e(n, r, o);
430
+ const Vt = {};
431
+ let j = class extends O {
432
+ constructor(o, e, n, r, t, i, s, a, c, m, u) {
433
+ super(), this._config = o, this._menuService = e, this._injector = n, this._componentManager = r, this._localeService = t, this._commandService = i, this._sheetsThreadCommentPopupService = s, this._sheetsThreadCommentModel = a, this._threadCommentPanelService = c, this._shortcutService = m, this._univerInstanceService = u, this._initMenu(), this._initShortcut(), this._initComponent(), this._initLocale(), this._initCommandListener(), this._initPanelListener();
434
+ }
435
+ _initShortcut() {
436
+ this._shortcutService.registerShortcut(xt);
437
+ }
438
+ _initCommandListener() {
439
+ this._commandService.onCommandExecuted((o) => {
440
+ if (o.id === qe.id) {
441
+ const e = o.params, { unitId: n, subUnitId: r, selections: t, type: i } = e;
442
+ if ((i === Xe.MOVE_END || i === void 0) && t[0].primary) {
443
+ const s = t[0].primary.actualRow, a = t[0].primary.actualColumn;
444
+ if (!this._sheetsThreadCommentModel.showCommentMarker(n, r, s, a)) {
445
+ this._threadCommentPanelService.activeCommentId && this._commandService.executeCommand(re.id);
446
+ return;
447
+ }
448
+ const c = this._sheetsThreadCommentModel.getByLocation(n, r, s, a);
449
+ c && this._commandService.executeCommand(re.id, {
450
+ unitId: n,
451
+ subUnitId: r,
452
+ commentId: c
453
+ });
454
+ }
455
+ }
456
+ if (o.id === V.id) {
457
+ const e = o.params, n = this._sheetsThreadCommentPopupService.activePopup;
458
+ if (!n)
459
+ return;
460
+ const { unitId: r, subUnitId: t, commentId: i } = n;
461
+ e.unitId === r && e.subUnitId === t && e.commentId === i && this._sheetsThreadCommentPopupService.hidePopup();
462
+ }
463
+ });
464
+ }
465
+ _initMenu() {
466
+ const { menu: o = {} } = this._config;
467
+ [
468
+ Et,
469
+ $t
470
+ ].forEach((e) => {
471
+ this._menuService.addMenuItem(e(this._injector), o);
472
+ });
473
+ }
474
+ _initComponent() {
475
+ [
476
+ [ye, Ut],
477
+ [Be, Ot],
478
+ [te, we]
479
+ ].forEach(([o, e]) => {
480
+ this._componentManager.register(o, e);
481
+ });
482
+ }
483
+ _initLocale() {
484
+ this._localeService.load({ zhCN: Rt });
485
+ }
486
+ _initPanelListener() {
487
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async (o) => {
488
+ if (o) {
489
+ const { unitId: e, subUnitId: n, commentId: r, trigger: t } = o, i = this._sheetsThreadCommentModel.getComment(e, n, r);
490
+ if (!i || i.resolved)
491
+ return;
492
+ const s = this._univerInstanceService.getCurrentUnitForType(S.UNIVER_SHEET);
493
+ if (!s || s.getUnitId() !== e)
494
+ return;
495
+ s.getActiveSheet().getSheetId() !== n && await this._commandService.executeCommand(Je.id, {
496
+ unitId: e,
497
+ subUnitId: n
498
+ });
499
+ const m = y(i.ref);
500
+ await this._commandService.executeCommand(st.id, {
501
+ range: {
502
+ startColumn: m.column,
503
+ endColumn: m.column,
504
+ startRow: m.row,
505
+ endRow: m.row
506
+ }
507
+ }), this._sheetsThreadCommentPopupService.showPopup({
508
+ unitId: e,
509
+ subUnitId: n,
510
+ row: m.row,
511
+ col: m.column,
512
+ commentId: i.id,
513
+ trigger: t
514
+ });
515
+ } else
516
+ this._sheetsThreadCommentPopupService.hidePopup();
517
+ }));
518
+ }
519
+ };
520
+ j = jt([
521
+ x(N.Starting, j),
522
+ b(1, Ke),
523
+ b(2, h(pe)),
524
+ b(3, h(ze)),
525
+ b(4, h(De)),
526
+ b(5, Q),
527
+ b(6, h(U)),
528
+ b(7, h(T)),
529
+ b(8, h(ee)),
530
+ b(9, Ge),
531
+ b(10, $)
532
+ ], j);
533
+ var At = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, Ht = (o, e, n, r) => {
534
+ for (var t = r > 1 ? void 0 : r ? Lt(e, n) : e, i = o.length - 1, s; i >= 0; i--)
535
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
536
+ return r && t && At(e, n, t), t;
537
+ }, k = (o, e) => (n, r) => e(n, r, o);
538
+ let B = class extends O {
539
+ constructor(e, n, r) {
540
+ super();
541
+ _(this, "_disposableMap", /* @__PURE__ */ new Map());
542
+ this._refRangeService = e, this._sheetsThreadCommentModel = n, this._threadCommentModel = r, this._initData(), this._initRefRange();
543
+ }
544
+ _getIdWithUnitId(e, n, r) {
545
+ return `${e}-${n}-${r}`;
546
+ }
547
+ _register(e, n, r) {
548
+ const t = r.id, i = {
549
+ startColumn: r.column,
550
+ endColumn: r.column,
551
+ startRow: r.row,
552
+ endRow: r.row
553
+ }, s = (a) => {
554
+ const c = et(i, a);
555
+ return c && c.startColumn === i.startColumn && c.startRow === i.startRow ? {
556
+ undos: [],
557
+ redos: []
558
+ } : c ? {
559
+ redos: [{
560
+ id: se.id,
561
+ params: {
562
+ unitId: e,
563
+ subUnitId: n,
564
+ payload: {
565
+ ref: J(c),
566
+ commentId: t
567
+ }
568
+ }
569
+ }],
570
+ undos: [{
571
+ id: se.id,
572
+ params: {
573
+ unitId: e,
574
+ subUnitId: n,
575
+ payload: {
576
+ ref: J(i),
577
+ commentId: t
578
+ }
579
+ }
580
+ }]
581
+ } : {
582
+ redos: [{
583
+ id: V.id,
584
+ params: {
585
+ unitId: e,
586
+ subUnitId: n,
587
+ commentId: t
588
+ }
589
+ }],
590
+ undos: [{
591
+ id: K.id,
592
+ params: {
593
+ unitId: e,
594
+ subUnitId: n,
595
+ comment: r
596
+ }
597
+ }]
598
+ };
599
+ };
600
+ this._disposableMap.set(
601
+ this._getIdWithUnitId(e, n, t),
602
+ this._refRangeService.registerRefRange(i, s, e, n)
603
+ );
604
+ }
605
+ _initData() {
606
+ const e = this._threadCommentModel.getAll();
607
+ for (const n in e) {
608
+ const r = e[n];
609
+ for (const t in r) {
610
+ const i = r[t];
611
+ for (const s in i) {
612
+ const a = i[s], c = a.ref, m = y(c);
613
+ this._register(n, t, {
614
+ ...a,
615
+ ...m
616
+ });
617
+ }
618
+ }
619
+ }
620
+ }
621
+ _initRefRange() {
622
+ this.disposeWithMe(
623
+ this._sheetsThreadCommentModel.commentUpdate$.subscribe((e) => {
624
+ const { unitId: n, subUnitId: r } = e;
625
+ switch (e.type) {
626
+ case "add": {
627
+ const t = e.payload;
628
+ this._register(e.unitId, e.subUnitId, {
629
+ ...t,
630
+ row: e.row,
631
+ column: e.column
632
+ });
633
+ break;
634
+ }
635
+ case "delete": {
636
+ const t = this._disposableMap.get(this._getIdWithUnitId(n, r, e.payload.commentId));
637
+ t == null || t.dispose();
638
+ break;
639
+ }
640
+ case "updateRef": {
641
+ const t = this._sheetsThreadCommentModel.getComment(n, r, e.payload.commentId);
642
+ if (!t)
643
+ return;
644
+ const i = this._disposableMap.get(this._getIdWithUnitId(n, r, t.id));
645
+ i == null || i.dispose(), this._register(e.unitId, e.subUnitId, {
646
+ ...t,
647
+ row: e.row,
648
+ column: e.column
649
+ });
650
+ break;
651
+ }
652
+ }
653
+ })
654
+ ), this.disposeWithMe(je(() => {
655
+ this._disposableMap.forEach((e) => {
656
+ e.dispose();
657
+ }), this._disposableMap.clear();
658
+ }));
659
+ }
660
+ };
661
+ B = Ht([
662
+ x(N.Starting, B),
663
+ k(0, h(Qe)),
664
+ k(1, h(T)),
665
+ k(2, h(G))
666
+ ], B);
667
+ var Bt = Object.defineProperty, Wt = Object.getOwnPropertyDescriptor, Ft = (o, e, n, r) => {
668
+ for (var t = r > 1 ? void 0 : r ? Wt(e, n) : e, i = o.length - 1, s; i >= 0; i--)
669
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
670
+ return r && t && Bt(e, n, t), t;
671
+ }, D = (o, e) => (n, r) => e(n, r, o);
672
+ let W = class extends O {
673
+ constructor(o, e, n, r, t) {
674
+ super(), this._sheetInterceptorService = o, this._sheetsThreadCommentModel = e, this._univerInstanceService = n, this._sheetSkeletonManagerService = r, this._renderManagerService = t, this._initViewModelIntercept(), this._initSkeletonChange();
675
+ }
676
+ _initViewModelIntercept() {
677
+ this.disposeWithMe(
678
+ this._sheetInterceptorService.intercept(
679
+ tt.CELL_CONTENT,
680
+ {
681
+ handler: (o, e, n) => {
682
+ const { row: r, col: t, unitId: i, subUnitId: s } = e;
683
+ return this._sheetsThreadCommentModel.showCommentMarker(i, s, r, t) ? n({
684
+ ...o,
685
+ markers: {
686
+ ...o == null ? void 0 : o.markers,
687
+ tr: {
688
+ color: "#FFBD37",
689
+ size: 6
690
+ }
691
+ }
692
+ }) : n(o);
693
+ },
694
+ priority: 100
695
+ }
696
+ )
697
+ );
698
+ }
699
+ _initSkeletonChange() {
700
+ const o = () => {
701
+ const e = this._univerInstanceService.getCurrentUnitForType(S.UNIVER_SHEET);
702
+ if (!e)
703
+ return;
704
+ const n = e.getUnitId(), r = e.getActiveSheet().getSheetId(), t = this._sheetSkeletonManagerService.getOrCreateSkeleton({ unitId: n, sheetId: r }), i = this._renderManagerService.getRenderById(n);
705
+ t == null || t.makeDirty(!0), t == null || t.calculate(), i && i.mainComponent.makeForceDirty();
706
+ };
707
+ this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(() => {
708
+ o();
709
+ }));
710
+ }
711
+ };
712
+ W = Ft([
713
+ x(N.Ready, W),
714
+ D(0, h(Se)),
715
+ D(1, h(T)),
716
+ D(2, $),
717
+ D(3, h(at)),
718
+ D(4, vt)
719
+ ], W);
720
+ var Zt = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, Kt = (o, e, n, r) => {
721
+ for (var t = r > 1 ? void 0 : r ? zt(e, n) : e, i = o.length - 1, s; i >= 0; i--)
722
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
723
+ return r && t && Zt(e, n, t), t;
724
+ }, ue = (o, e) => (n, r) => e(n, r, o);
725
+ const Gt = (o, e, n) => {
726
+ const r = y(o), t = n.row - e.row, i = n.column - e.column, s = {
727
+ startColumn: r.column + i,
728
+ startRow: r.row + t,
729
+ endColumn: r.column + i,
730
+ endRow: r.row + t
731
+ };
732
+ return J(s);
733
+ };
734
+ let F = class extends O {
735
+ constructor(e, n) {
736
+ super();
737
+ _(this, "_copyInfo");
738
+ this._sheetClipboardService = e, this._sheetsThreadCommentModel = n, this._initClipboardHook();
739
+ }
740
+ // eslint-disable-next-line max-lines-per-function
741
+ _initClipboardHook() {
742
+ this.disposeWithMe(
743
+ this._sheetClipboardService.addClipboardHook({
744
+ id: Ue,
745
+ onBeforeCopy: (e, n, r) => {
746
+ this._copyInfo = {
747
+ unitId: e,
748
+ subUnitId: n,
749
+ range: r
750
+ };
751
+ },
752
+ // eslint-disable-next-line max-lines-per-function
753
+ onPasteCells: (e, n, r, t) => {
754
+ const { unitId: i, subUnitId: s, range: a } = n, c = {
755
+ row: a.rows[0],
756
+ column: a.cols[0]
757
+ };
758
+ if (t.copyType === mt.CUT && this._copyInfo) {
759
+ const { range: m, unitId: u, subUnitId: l } = this._copyInfo, R = {
760
+ row: m.startRow,
761
+ column: m.startColumn
762
+ };
763
+ if (!(i === u && s === l)) {
764
+ const g = [];
765
+ Ve.foreach(m, (d, p) => {
766
+ const v = this._sheetsThreadCommentModel.getCommentWithChildren(u, l, d, p);
767
+ v && g.push(v);
768
+ });
769
+ const I = [], M = [], E = [], A = [], L = (d) => {
770
+ I.unshift({
771
+ id: V.id,
772
+ params: {
773
+ unitId: u,
774
+ subUnitId: l,
775
+ commentId: d.id
776
+ }
777
+ }), E.push({
778
+ id: K.id,
779
+ params: {
780
+ unitId: i,
781
+ subUnitId: s,
782
+ comment: {
783
+ ...d,
784
+ ref: Gt(d.ref, R, c),
785
+ unitId: i,
786
+ subUnitId: s
787
+ }
788
+ }
789
+ }), M.push({
790
+ id: K.id,
791
+ params: {
792
+ unitId: u,
793
+ subUnitId: l,
794
+ comment: d
795
+ }
796
+ }), A.unshift({
797
+ id: V.id,
798
+ params: {
799
+ unitId: i,
800
+ subUnitId: s,
801
+ commentId: d.id
802
+ }
803
+ });
804
+ };
805
+ return g.forEach((d) => {
806
+ L(d.root), d.children.forEach((p) => {
807
+ L(p);
808
+ });
809
+ }), {
810
+ redos: [...I, ...E],
811
+ undos: [...A, ...M]
812
+ };
813
+ }
814
+ }
815
+ return {
816
+ redos: [],
817
+ undos: []
818
+ };
819
+ }
820
+ })
821
+ );
822
+ }
823
+ };
824
+ F = Kt([
825
+ x(N.Rendered, F),
826
+ ue(0, h(ct)),
827
+ ue(1, h(T))
828
+ ], F);
829
+ var Yt = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, qt = (o, e, n, r) => {
830
+ for (var t = r > 1 ? void 0 : r ? kt(e, n) : e, i = o.length - 1, s; i >= 0; i--)
831
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
832
+ return r && t && Yt(e, n, t), t;
833
+ }, q = (o, e) => (n, r) => e(n, r, o);
834
+ let Z = class extends O {
835
+ constructor(o, e, n) {
836
+ super(), this._hoverManagerService = o, this._sheetsThreadCommentPopupService = e, this._sheetsThreadCommentModel = n, this._initHoverEvent();
837
+ }
838
+ _initHoverEvent() {
839
+ this._hoverManagerService.currentCell$.subscribe((o) => {
840
+ const e = this._sheetsThreadCommentPopupService.activePopup;
841
+ if (o && (e && e.temp || !e)) {
842
+ const { location: n } = o, { unitId: r, subUnitId: t, row: i, col: s } = n, a = this._sheetsThreadCommentModel.getByLocation(r, t, i, s);
843
+ if (a) {
844
+ const c = this._sheetsThreadCommentModel.getComment(r, t, a);
845
+ c && !c.resolved && this._sheetsThreadCommentPopupService.showPopup({
846
+ unitId: r,
847
+ subUnitId: t,
848
+ row: i,
849
+ col: s,
850
+ commentId: a,
851
+ temp: !0
852
+ });
853
+ } else
854
+ e && this._sheetsThreadCommentPopupService.hidePopup();
855
+ }
856
+ });
857
+ }
858
+ };
859
+ Z = qt([
860
+ x(N.Rendered, Z),
861
+ q(0, h(dt)),
862
+ q(1, h(U)),
863
+ q(2, h(T))
864
+ ], Z);
865
+ var Xt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, Qt = (o, e, n, r) => {
866
+ for (var t = r > 1 ? void 0 : r ? Jt(e, n) : e, i = o.length - 1, s; i >= 0; i--)
867
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
868
+ return r && t && Xt(e, n, t), t;
869
+ }, X = (o, e) => (n, r) => e(n, r, o);
870
+ let z = class extends O {
871
+ constructor(o, e, n) {
872
+ super(), this._sheetInterceptorService = o, this._univerInstanceService = e, this._threadCommentModel = n, this._initSheetChange();
873
+ }
874
+ _initSheetChange() {
875
+ this.disposeWithMe(
876
+ this._sheetInterceptorService.interceptCommand({
877
+ getMutations: (o) => {
878
+ if (o.id === nt.id) {
879
+ const e = o.params, n = e.unitId ? this._univerInstanceService.getUnit(e.unitId) : this._univerInstanceService.getCurrentUnitForType(S.UNIVER_SHEET);
880
+ if (!n)
881
+ return { redos: [], undos: [] };
882
+ const r = n.getUnitId(), t = e.subUnitId || n.getActiveSheet().getSheetId(), { commentMap: i } = this._threadCommentModel.ensureMap(r, t), s = Array.from(Object.keys(i)), a = Array.from(Object.values(i)), c = s.map((u) => ({
883
+ id: V.id,
884
+ params: {
885
+ unitId: r,
886
+ subUnitId: t,
887
+ commentId: u
888
+ }
889
+ })), m = a.map((u) => ({
890
+ id: K.id,
891
+ params: {
892
+ unitId: r,
893
+ subUnitId: t,
894
+ comment: u
895
+ }
896
+ }));
897
+ return { redos: c, undos: m };
898
+ }
899
+ return { redos: [], undos: [] };
900
+ }
901
+ })
902
+ );
903
+ }
904
+ };
905
+ z = Qt([
906
+ x(N.Ready, z),
907
+ X(0, h(Se)),
908
+ X(1, $),
909
+ X(2, h(G))
910
+ ], z);
911
+ var en = Object.defineProperty, tn = Object.getOwnPropertyDescriptor, nn = (o, e, n, r) => {
912
+ for (var t = r > 1 ? void 0 : r ? tn(e, n) : e, i = o.length - 1, s; i >= 0; i--)
913
+ (s = o[i]) && (t = (r ? s(e, n, t) : s(t)) || t);
914
+ return r && t && en(e, n, t), t;
915
+ }, he = (o, e) => (n, r) => e(n, r, o), H;
916
+ let le = (H = class extends We {
917
+ constructor(e = {}, n, r) {
918
+ super(e, n, r);
919
+ _(this, "_pluginConfig");
920
+ this._injector = n, this._commandService = r, this._pluginConfig = _e.deepMerge({}, Vt, e);
921
+ }
922
+ onStarting(e) {
923
+ super.onStarting(e), [
924
+ [T],
925
+ [
926
+ j,
927
+ {
928
+ useFactory: () => this._injector.createInstance(j, this._pluginConfig)
929
+ }
930
+ ],
931
+ [B],
932
+ [W],
933
+ [F],
934
+ [Z],
935
+ [z],
936
+ [U]
937
+ ].forEach((n) => {
938
+ this._injector.add(n);
939
+ }), [Y].forEach((n) => {
940
+ this._commandService.registerCommand(n);
941
+ });
942
+ }
943
+ }, _(H, "pluginName", Ue), _(H, "type", S.UNIVER_SHEET), H);
944
+ le = nn([
945
+ he(1, h(pe)),
946
+ he(2, h(Q))
947
+ ], le);
948
+ export {
949
+ Mn as ICommandService,
950
+ On as IThreadCommentDataSourceService,
951
+ wn as IThreadCommentMentionDataService,
952
+ Sn as Inject,
953
+ gn as Injector,
954
+ Pn as Plugin,
955
+ Ue as SHEETS_THREAD_COMMENT,
956
+ j as SheetsThreadCommentController,
957
+ F as SheetsThreadCommentCopyPasteController,
958
+ Z as SheetsThreadCommentHoverController,
959
+ T as SheetsThreadCommentModel,
960
+ U as SheetsThreadCommentPopupService,
961
+ B as SheetsThreadCommentRefRangeController,
962
+ z as ThreadCommentRemoveSheetsController,
963
+ bn as UniverInstanceType,
964
+ le as UniverSheetsThreadCommentPlugin,
965
+ yn as UniverThreadCommentUIPlugin
966
+ };