@univerjs/sheets-thread-comment-ui 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.
Files changed (77) hide show
  1. package/lib/cjs/index.js +1 -1
  2. package/lib/cjs/locale/ca-ES.js +1 -1
  3. package/lib/cjs/locale/en-US.js +1 -1
  4. package/lib/cjs/locale/es-ES.js +1 -1
  5. package/lib/cjs/locale/fa-IR.js +1 -1
  6. package/lib/cjs/locale/fr-FR.js +1 -1
  7. package/lib/cjs/locale/ja-JP.js +1 -1
  8. package/lib/cjs/locale/ko-KR.js +1 -1
  9. package/lib/cjs/locale/ru-RU.js +1 -1
  10. package/lib/cjs/locale/sk-SK.js +1 -1
  11. package/lib/cjs/locale/vi-VN.js +1 -1
  12. package/lib/cjs/locale/zh-CN.js +1 -1
  13. package/lib/cjs/locale/zh-TW.js +1 -1
  14. package/lib/es/index.js +1 -828
  15. package/lib/es/locale/ca-ES.js +1 -11
  16. package/lib/es/locale/en-US.js +1 -11
  17. package/lib/es/locale/es-ES.js +1 -11
  18. package/lib/es/locale/fa-IR.js +1 -11
  19. package/lib/es/locale/fr-FR.js +1 -11
  20. package/lib/es/locale/ja-JP.js +1 -11
  21. package/lib/es/locale/ko-KR.js +1 -11
  22. package/lib/es/locale/ru-RU.js +1 -11
  23. package/lib/es/locale/sk-SK.js +1 -11
  24. package/lib/es/locale/vi-VN.js +1 -11
  25. package/lib/es/locale/zh-CN.js +1 -11
  26. package/lib/es/locale/zh-TW.js +1 -11
  27. package/lib/index.css +1 -0
  28. package/lib/index.js +1 -828
  29. package/lib/locale/ca-ES.js +1 -11
  30. package/lib/locale/en-US.js +1 -11
  31. package/lib/locale/es-ES.js +1 -11
  32. package/lib/locale/fa-IR.js +1 -11
  33. package/lib/locale/fr-FR.js +1 -11
  34. package/lib/locale/ja-JP.js +1 -11
  35. package/lib/locale/ko-KR.js +1 -11
  36. package/lib/locale/ru-RU.js +1 -11
  37. package/lib/locale/sk-SK.js +1 -11
  38. package/lib/locale/vi-VN.js +1 -11
  39. package/lib/locale/zh-CN.js +1 -11
  40. package/lib/locale/zh-TW.js +1 -11
  41. package/lib/types/commands/operations/comment.operation.d.ts +16 -1
  42. package/lib/types/config/config.d.ts +17 -2
  43. package/lib/types/controllers/render-controllers/render.controller.d.ts +15 -0
  44. package/lib/types/controllers/sheets-thread-comment-copy-paste.controller.d.ts +15 -0
  45. package/lib/types/controllers/sheets-thread-comment-hover.controller.d.ts +15 -0
  46. package/lib/types/controllers/sheets-thread-comment-popup.controller.d.ts +15 -0
  47. package/lib/types/controllers/sheets-thread-comment.controller.d.ts +15 -0
  48. package/lib/types/locale/ca-ES.d.ts +16 -1
  49. package/lib/types/locale/es-ES.d.ts +16 -1
  50. package/lib/types/locale/fa-IR.d.ts +16 -1
  51. package/lib/types/locale/fr-FR.d.ts +16 -1
  52. package/lib/types/locale/ja-JP.d.ts +16 -1
  53. package/lib/types/locale/ko-KR.d.ts +16 -1
  54. package/lib/types/locale/ru-RU.d.ts +16 -1
  55. package/lib/types/locale/sk-SK.d.ts +16 -1
  56. package/lib/types/locale/vi-VN.d.ts +16 -1
  57. package/lib/types/locale/zh-CN.d.ts +16 -1
  58. package/lib/types/locale/zh-TW.d.ts +16 -1
  59. package/lib/types/menu/menu.d.ts +22 -6
  60. package/lib/types/menu/schema.d.ts +16 -1
  61. package/lib/types/plugin.d.ts +16 -1
  62. package/lib/types/services/sheets-thread-comment-popup.service.d.ts +19 -3
  63. package/lib/types/types/interfaces/i-sheet-thread-comment.d.ts +16 -1
  64. package/lib/umd/index.js +1 -1
  65. package/lib/umd/locale/ca-ES.js +1 -1
  66. package/lib/umd/locale/en-US.js +1 -1
  67. package/lib/umd/locale/es-ES.js +1 -1
  68. package/lib/umd/locale/fa-IR.js +1 -1
  69. package/lib/umd/locale/fr-FR.js +1 -1
  70. package/lib/umd/locale/ja-JP.js +1 -1
  71. package/lib/umd/locale/ko-KR.js +1 -1
  72. package/lib/umd/locale/ru-RU.js +1 -1
  73. package/lib/umd/locale/sk-SK.js +1 -1
  74. package/lib/umd/locale/vi-VN.js +1 -1
  75. package/lib/umd/locale/zh-CN.js +1 -1
  76. package/lib/umd/locale/zh-TW.js +1 -1
  77. package/package.json +15 -14
package/lib/es/index.js CHANGED
@@ -1,828 +1 @@
1
- var Ue = Object.defineProperty;
2
- var $e = (n, e, r) => e in n ? Ue(n, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : n[e] = r;
3
- var y = (n, e, r) => $e(n, typeof e != "symbol" ? e + "" : e, r);
4
- import { Inject as p, Disposable as k, DisposableCollection as ke, CommandType as Oe, IUniverInstanceService as A, InterceptorEffectEnum as Ne, UniverInstanceType as M, Range as De, ICommandService as re, RANGE_TYPE as ae, Rectangle as xe, Tools as Ae, DependentOn as Ve, Injector as Be, IConfigService as He, Plugin as Le, merge as je } from "@univerjs/core";
5
- import { SheetsSelectionsService as ue, getSheetCommandTarget as Fe, SheetInterceptorService as We, INTERCEPTOR_POINT as Ze, SheetPermissionCheckController as le, RangeProtectionPermissionViewPoint as G, WorksheetViewPermission as z, WorkbookCommentPermission as K, SetWorksheetActiveOperation as Ge } from "@univerjs/sheets";
6
- import { SheetsThreadCommentModel as O, UniverSheetsThreadCommentPlugin as ze } from "@univerjs/sheets-thread-comment";
7
- import { ThreadCommentPanelService as oe, SetActiveCommentOperation as J, ToggleSheetCommentPanelOperation as pe, ThreadCommentTree as Ke, ThreadCommentPanel as Ye, THREAD_COMMENT_PANEL as qe, UniverThreadCommentUIPlugin as Je } from "@univerjs/thread-comment-ui";
8
- import { UniverThreadCommentUIPlugin as pn } from "@univerjs/thread-comment-ui";
9
- import { SheetCanvasPopManagerService as Qe, CellPopupManagerService as Xe, ISheetClipboardService as et, COPY_TYPE as tt, HoverManagerService as nt, IMarkSelectionService as Ce, IEditorBridgeService as rt, SheetSkeletonManagerService as ot, ScrollToRangeOperation as it, whenSheetEditorFocused as st, getCurrentRangeDisable$ as ve } from "@univerjs/sheets-ui";
10
- import { IZenZoneService as at, KeyCode as ct, MetaKeys as ce, getMenuHiddenObservable as _e, MenuItemType as Se, ContextMenuPosition as ht, ContextMenuGroup as mt, RibbonInsertGroup as dt, useDependency as E, useObservable as D, IMenuManagerService as ut, ComponentManager as lt, IShortcutService as pt } from "@univerjs/ui";
11
- import { BehaviorSubject as Ct, debounceTime as ie, map as vt } from "rxjs";
12
- import { IRenderManagerService as fe } from "@univerjs/engine-render";
13
- import { singleReferenceToGrid as x, serializeRange as _t } from "@univerjs/engine-formula";
14
- import { IThreadCommentDataSourceService as St, DeleteCommentMutation as ne, AddCommentMutation as he } from "@univerjs/thread-comment";
15
- import { AddCommentCommand as vn, DeleteCommentCommand as _n, DeleteCommentTreeCommand as Sn, IThreadCommentDataSourceService as fn, ResolveCommentCommand as gn, UpdateCommentCommand as In } from "@univerjs/thread-comment";
16
- import { useRef as ge, createElement as Ie, forwardRef as ft, useMemo as gt, useCallback as me, useEffect as It } from "react";
17
- import { jsx as Pe } from "react/jsx-runtime";
18
- const Te = "univer.sheet.thread-comment-modal", we = "SHEET_THREAD_COMMENT";
19
- var Pt = Object.getOwnPropertyDescriptor, Tt = (n, e, r, t) => {
20
- for (var o = t > 1 ? void 0 : t ? Pt(e, r) : e, i = n.length - 1, s; i >= 0; i--)
21
- (s = n[i]) && (o = s(o) || o);
22
- return o;
23
- }, Q = (n, e) => (r, t) => e(r, t, n);
24
- let R = class extends k {
25
- constructor(e, r, t) {
26
- super();
27
- y(this, "_lastPopup", null);
28
- y(this, "_activePopup");
29
- y(this, "_activePopup$", new Ct(null));
30
- y(this, "activePopup$", this._activePopup$.asObservable());
31
- this._canvasPopupManagerService = e, this._zenZoneService = r, this._cellPopupManagerService = t, this._initZenVisible(), this.disposeWithMe(() => {
32
- this._activePopup$.complete();
33
- });
34
- }
35
- get activePopup() {
36
- return this._activePopup;
37
- }
38
- _initZenVisible() {
39
- this.disposeWithMe(this._zenZoneService.visible$.subscribe((e) => {
40
- e && this.hidePopup();
41
- }));
42
- }
43
- dispose() {
44
- super.dispose(), this.hidePopup();
45
- }
46
- showPopup(e, r) {
47
- var h;
48
- const { row: t, col: o, unitId: i, subUnitId: s } = e;
49
- if (this._activePopup && t === this._activePopup.row && o === this._activePopup.col && i === this._activePopup.unitId && s === ((h = this.activePopup) == null ? void 0 : h.subUnitId)) {
50
- this._activePopup = e, this._activePopup$.next(e);
51
- return;
52
- }
53
- if (this._lastPopup && this._lastPopup.dispose(), this._zenZoneService.visible)
54
- return;
55
- this._activePopup = e, this._activePopup$.next(e);
56
- const a = this._cellPopupManagerService.showPopup(
57
- {
58
- row: t,
59
- col: o,
60
- unitId: i,
61
- subUnitId: s
62
- },
63
- {
64
- componentKey: Te,
65
- onClickOutside: () => {
66
- this.hidePopup();
67
- },
68
- direction: "horizontal",
69
- excludeOutside: [
70
- ...Array.from(document.querySelectorAll(".univer-thread-comment")),
71
- document.getElementById("thread-comment-add")
72
- ].filter(Boolean),
73
- priority: 2
74
- }
75
- );
76
- if (!a)
77
- throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");
78
- const c = new ke();
79
- c.add(a), c.add({
80
- dispose: () => {
81
- r == null || r();
82
- }
83
- }), this._lastPopup = c;
84
- }
85
- hidePopup() {
86
- this._activePopup && (this._lastPopup && this._lastPopup.dispose(), this._lastPopup = null, this._activePopup = null, this._activePopup$.next(null));
87
- }
88
- persistPopup() {
89
- !this._activePopup || !this._activePopup.temp || (this._activePopup = {
90
- ...this._activePopup,
91
- temp: !1
92
- }, this._activePopup$.next(this._activePopup));
93
- }
94
- };
95
- R = Tt([
96
- Q(0, p(Qe)),
97
- Q(1, at),
98
- Q(2, p(Xe))
99
- ], R);
100
- const V = {
101
- type: Oe.OPERATION,
102
- id: "sheets.operation.show-comment-modal",
103
- handler(n) {
104
- var v;
105
- const e = n.get(ue), r = n.get(A), t = n.get(R), o = n.get(oe), i = (v = e.getCurrentLastSelection()) == null ? void 0 : v.primary, s = n.get(O);
106
- if (!i)
107
- return !1;
108
- const a = Fe(r);
109
- if (!a)
110
- return !1;
111
- const { workbook: c, worksheet: h, unitId: d, subUnitId: m } = a, C = {
112
- workbook: c,
113
- worksheet: h,
114
- unitId: d,
115
- subUnitId: m,
116
- row: i.startRow,
117
- col: i.startColumn
118
- };
119
- t.showPopup(C);
120
- const l = s.getByLocation(d, m, i.startRow, i.startColumn);
121
- return l && o.setActiveComment({
122
- unitId: d,
123
- subUnitId: m,
124
- commentId: l,
125
- trigger: "context-menu"
126
- }), !0;
127
- }
128
- }, wt = "@univerjs/sheets-thread-comment-ui", Mt = "0.17.0", Me = {
129
- name: wt,
130
- version: Mt
131
- }, bt = "sheets-thread-comment.config", de = {};
132
- var yt = Object.getOwnPropertyDescriptor, Et = (n, e, r, t) => {
133
- for (var o = t > 1 ? void 0 : t ? yt(e, r) : e, i = n.length - 1, s; i >= 0; i--)
134
- (s = n[i]) && (o = s(o) || o);
135
- return o;
136
- }, B = (n, e) => (r, t) => e(r, t, n);
137
- let L = class extends k {
138
- constructor(n, e, r, t) {
139
- super(), this._sheetInterceptorService = n, this._sheetsThreadCommentModel = e, this._univerInstanceService = r, this._renderManagerService = t, this._initViewModelIntercept(), this._initSkeletonChange();
140
- }
141
- _initViewModelIntercept() {
142
- this.disposeWithMe(
143
- this._sheetInterceptorService.intercept(
144
- Ze.CELL_CONTENT,
145
- {
146
- effect: Ne.Style,
147
- handler: (n, e, r) => {
148
- const { row: t, col: o, unitId: i, subUnitId: s } = e;
149
- return this._sheetsThreadCommentModel.showCommentMarker(i, s, t, o) && ((!n || n === e.rawData) && (n = { ...e.rawData }), n.markers = {
150
- ...n == null ? void 0 : n.markers,
151
- tr: {
152
- color: "#FFBD37",
153
- size: 6
154
- }
155
- }), r(n);
156
- },
157
- priority: 100
158
- }
159
- )
160
- );
161
- }
162
- _initSkeletonChange() {
163
- const n = () => {
164
- var o;
165
- const e = this._univerInstanceService.getCurrentUnitForType(M.UNIVER_SHEET);
166
- if (!e) return;
167
- const r = e.getUnitId(), t = this._renderManagerService.getRenderById(r);
168
- (o = t == null ? void 0 : t.mainComponent) == null || o.makeForceDirty();
169
- };
170
- this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(ie(16)).subscribe(() => {
171
- n();
172
- }));
173
- }
174
- };
175
- L = Et([
176
- B(0, p(We)),
177
- B(1, p(O)),
178
- B(2, A),
179
- B(3, fe)
180
- ], L);
181
- var Rt = Object.getOwnPropertyDescriptor, Ut = (n, e, r, t) => {
182
- for (var o = t > 1 ? void 0 : t ? Rt(e, r) : e, i = n.length - 1, s; i >= 0; i--)
183
- (s = n[i]) && (o = s(o) || o);
184
- return o;
185
- }, X = (n, e) => (r, t) => e(r, t, n);
186
- const $t = (n, e, r) => {
187
- const t = x(n), o = r.row - e.row, i = r.column - e.column, s = {
188
- startColumn: t.column + i,
189
- startRow: t.row + o,
190
- endColumn: t.column + i,
191
- endRow: t.row + o
192
- };
193
- return _t(s);
194
- };
195
- let j = class extends k {
196
- constructor(e, r, t) {
197
- super();
198
- y(this, "_copyInfo");
199
- this._sheetClipboardService = e, this._sheetsThreadCommentModel = r, this._threadCommentDataSourceService = t, this._initClipboardHook();
200
- }
201
- // eslint-disable-next-line max-lines-per-function
202
- _initClipboardHook() {
203
- this.disposeWithMe(
204
- this._sheetClipboardService.addClipboardHook({
205
- id: we,
206
- onBeforeCopy: (e, r, t) => {
207
- this._copyInfo = {
208
- unitId: e,
209
- subUnitId: r,
210
- range: t
211
- };
212
- },
213
- // eslint-disable-next-line max-lines-per-function
214
- onPasteCells: (e, r, t, o) => {
215
- const { unitId: i, subUnitId: s, range: a } = r, c = {
216
- row: a.rows[0],
217
- column: a.cols[0]
218
- };
219
- if (o.copyType === tt.CUT && this._copyInfo) {
220
- const { range: h, unitId: d, subUnitId: m } = this._copyInfo, C = {
221
- row: h.startRow,
222
- column: h.startColumn
223
- };
224
- if (!(i === d && s === m)) {
225
- const l = [];
226
- De.foreach(h, (g, u) => {
227
- const I = this._sheetsThreadCommentModel.getAllByLocation(d, m, g, u);
228
- this._threadCommentDataSourceService.syncUpdateMutationToColla ? I.forEach((_) => {
229
- l.push(_);
230
- }) : I.forEach(({ children: _, ...T }) => {
231
- T.parentId || l.push(T);
232
- });
233
- });
234
- const v = [], f = [], U = [], N = [], q = (g) => {
235
- v.unshift({
236
- id: ne.id,
237
- params: {
238
- unitId: d,
239
- subUnitId: m,
240
- commentId: g.id
241
- }
242
- }), U.push({
243
- id: he.id,
244
- params: {
245
- unitId: i,
246
- subUnitId: s,
247
- comment: {
248
- ...g,
249
- ref: $t(g.ref, C, c),
250
- unitId: i,
251
- subUnitId: s
252
- },
253
- sync: !0
254
- }
255
- }), f.push({
256
- id: he.id,
257
- params: {
258
- unitId: d,
259
- subUnitId: m,
260
- comment: g,
261
- sync: !0
262
- }
263
- }), N.unshift({
264
- id: ne.id,
265
- params: {
266
- unitId: i,
267
- subUnitId: s,
268
- commentId: g.id
269
- }
270
- });
271
- };
272
- return l.forEach((g) => {
273
- q(g);
274
- }), {
275
- redos: [...v, ...U],
276
- undos: [...N, ...f]
277
- };
278
- }
279
- }
280
- return {
281
- redos: [],
282
- undos: []
283
- };
284
- }
285
- })
286
- );
287
- }
288
- };
289
- j = Ut([
290
- X(0, p(et)),
291
- X(1, p(O)),
292
- X(2, St)
293
- ], j);
294
- var kt = Object.getOwnPropertyDescriptor, Ot = (n, e, r, t) => {
295
- for (var o = t > 1 ? void 0 : t ? kt(e, r) : e, i = n.length - 1, s; i >= 0; i--)
296
- (s = n[i]) && (o = s(o) || o);
297
- return o;
298
- }, H = (n, e) => (r, t) => e(r, t, n);
299
- let F = class extends k {
300
- constructor(n, e, r, t) {
301
- super(), this._hoverManagerService = n, this._sheetsThreadCommentPopupService = e, this._sheetsThreadCommentModel = r, this._sheetPermissionCheckController = t, this._initHoverEvent();
302
- }
303
- _initHoverEvent() {
304
- this.disposeWithMe(
305
- this._hoverManagerService.currentCell$.pipe(ie(100)).subscribe((n) => {
306
- const e = this._sheetsThreadCommentPopupService.activePopup;
307
- if (n && (e && e.temp || !e)) {
308
- const { location: r } = n, { unitId: t, subUnitId: o, row: i, col: s } = r, a = this._sheetsThreadCommentModel.getByLocation(t, o, i, s);
309
- if (a) {
310
- if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
311
- workbookTypes: [K],
312
- worksheetTypes: [z],
313
- rangeTypes: [G]
314
- }, [{ startRow: i, startColumn: s, endRow: i, endColumn: s }], t, o))
315
- return;
316
- const h = this._sheetsThreadCommentModel.getComment(t, o, a);
317
- h && !h.resolved && this._sheetsThreadCommentPopupService.showPopup({
318
- unitId: t,
319
- subUnitId: o,
320
- row: i,
321
- col: s,
322
- commentId: a,
323
- temp: !0
324
- });
325
- } else
326
- e && this._sheetsThreadCommentPopupService.hidePopup();
327
- }
328
- })
329
- );
330
- }
331
- };
332
- F = Ot([
333
- H(0, p(nt)),
334
- H(1, p(R)),
335
- H(2, p(O)),
336
- H(3, p(le))
337
- ], F);
338
- var Nt = Object.getOwnPropertyDescriptor, Dt = (n, e, r, t) => {
339
- for (var o = t > 1 ? void 0 : t ? Nt(e, r) : e, i = n.length - 1, s; i >= 0; i--)
340
- (s = n[i]) && (o = s(o) || o);
341
- return o;
342
- }, w = (n, e) => (r, t) => e(r, t, n);
343
- let W = class extends k {
344
- constructor(e, r, t, o, i, s, a, c, h, d) {
345
- super();
346
- y(this, "_isSwitchToCommenting", !1);
347
- y(this, "_selectionShapeInfo", null);
348
- this._commandService = e, this._sheetsThreadCommentPopupService = r, this._sheetsThreadCommentModel = t, this._threadCommentPanelService = o, this._univerInstanceService = i, this._sheetPermissionCheckController = s, this._markSelectionService = a, this._sheetSelectionService = c, this._editorBridgeService = h, this._renderManagerService = d, this._initCommandListener(), this._initPanelListener(), this._initMarkSelection(), this._initSelectionUpdateListener(), this._initEditorBridge();
349
- }
350
- _handleSelectionChange(e, r, t) {
351
- var C, l, v;
352
- const o = (C = e[0]) == null ? void 0 : C.range, i = this._renderManagerService.getRenderById(r), s = (l = i == null ? void 0 : i.with(ot).getSkeletonParam(t)) == null ? void 0 : l.skeleton;
353
- if (!s || !o)
354
- return;
355
- const a = s.getCellWithCoordByIndex(o.startRow, o.startColumn);
356
- if ((((v = o.rangeType) != null ? v : ae.NORMAL) !== ae.NORMAL || o.endColumn - o.startColumn > 0 || o.endRow - o.startRow > 0) && !((a.isMerged || a.isMergedMainCell) && xe.equals(a.mergeInfo, o))) {
357
- this._threadCommentPanelService.activeCommentId && this._commandService.executeCommand(J.id);
358
- return;
359
- }
360
- const h = a.actualRow, d = a.actualColumn;
361
- if (!this._sheetsThreadCommentModel.showCommentMarker(r, t, h, d)) {
362
- this._threadCommentPanelService.activeCommentId && this._commandService.executeCommand(J.id);
363
- return;
364
- }
365
- const m = this._sheetsThreadCommentModel.getByLocation(r, t, h, d);
366
- m && this._commandService.executeCommand(J.id, {
367
- unitId: r,
368
- subUnitId: t,
369
- commentId: m
370
- });
371
- }
372
- _initSelectionUpdateListener() {
373
- this.disposeWithMe(
374
- this._sheetSelectionService.selectionMoveEnd$.subscribe((e) => {
375
- if (this._isSwitchToCommenting)
376
- return;
377
- const r = this._sheetSelectionService.currentSelectionParam;
378
- r && this._handleSelectionChange(e, r.unitId, r.sheetId);
379
- })
380
- );
381
- }
382
- _initEditorBridge() {
383
- this.disposeWithMe(
384
- this._editorBridgeService.visible$.subscribe((e) => {
385
- e.visible && this._sheetsThreadCommentPopupService.hidePopup();
386
- })
387
- );
388
- }
389
- _initCommandListener() {
390
- this._commandService.onCommandExecuted((e) => {
391
- if (e.id === ne.id) {
392
- const r = e.params, t = this._sheetsThreadCommentPopupService.activePopup;
393
- if (!t)
394
- return;
395
- const { unitId: o, subUnitId: i, commentId: s } = t;
396
- r.unitId === o && r.subUnitId === i && r.commentId === s && this._sheetsThreadCommentPopupService.hidePopup();
397
- }
398
- });
399
- }
400
- _initPanelListener() {
401
- this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async (e) => {
402
- var r;
403
- if (e) {
404
- const { unitId: t, subUnitId: o, commentId: i, trigger: s } = e, a = this._sheetsThreadCommentModel.getComment(t, o, i);
405
- if (!a || a.resolved)
406
- return;
407
- const c = this._univerInstanceService.getCurrentUnitForType(M.UNIVER_SHEET);
408
- if (!c || c.getUnitId() !== t)
409
- return;
410
- this._isSwitchToCommenting = !0, ((r = c.getActiveSheet()) == null ? void 0 : r.getSheetId()) !== o && await this._commandService.executeCommand(Ge.id, {
411
- unitId: t,
412
- subUnitId: o
413
- }), this._isSwitchToCommenting = !1;
414
- const m = x(a.ref), { row: C, column: l } = m;
415
- if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
416
- workbookTypes: [K],
417
- worksheetTypes: [z],
418
- rangeTypes: [G]
419
- }, [{ startRow: C, startColumn: l, endRow: C, endColumn: l }], t, o))
420
- return;
421
- const f = 1;
422
- if (await this._commandService.executeCommand(it.id, {
423
- range: {
424
- startRow: Math.max(m.row - f, 0),
425
- endRow: m.row + f,
426
- startColumn: Math.max(m.column - f, 0),
427
- endColumn: m.column + f
428
- }
429
- }), this._editorBridgeService.isVisible().visible)
430
- return;
431
- this._sheetsThreadCommentPopupService.showPopup({
432
- unitId: t,
433
- subUnitId: o,
434
- row: m.row,
435
- col: m.column,
436
- commentId: a.id,
437
- trigger: s
438
- });
439
- } else
440
- this._sheetsThreadCommentPopupService.hidePopup();
441
- }));
442
- }
443
- _initMarkSelection() {
444
- this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(ie(100)).subscribe((e) => {
445
- var C, l;
446
- if (!e) {
447
- this._selectionShapeInfo && (this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId), this._selectionShapeInfo = null);
448
- return;
449
- }
450
- const { unitId: r, subUnitId: t, commentId: o } = e;
451
- this._selectionShapeInfo && (this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId), this._selectionShapeInfo = null);
452
- const i = this._sheetsThreadCommentModel.getComment(r, t, o);
453
- if (!i)
454
- return;
455
- const s = x(i.ref), { row: a, column: c } = s;
456
- if (Number.isNaN(a) || Number.isNaN(c))
457
- return null;
458
- const h = (C = this._univerInstanceService.getCurrentUnitForType(M.UNIVER_SHEET)) == null ? void 0 : C.getSheetBySheetId(t), d = (l = h == null ? void 0 : h.getMergedCell(a, c)) != null ? l : {
459
- startColumn: c,
460
- endColumn: c,
461
- startRow: a,
462
- endRow: a
463
- }, m = this._markSelectionService.addShape(
464
- {
465
- range: d,
466
- style: {
467
- // hasAutoFill: false,
468
- fill: "rgba(255, 189, 55, 0.35)",
469
- strokeWidth: 1,
470
- stroke: "#FFBD37",
471
- widgets: {}
472
- },
473
- primary: null
474
- },
475
- [],
476
- -1
477
- );
478
- m && (this._selectionShapeInfo = {
479
- ...e,
480
- shapeId: m
481
- });
482
- }));
483
- }
484
- };
485
- W = Dt([
486
- w(0, re),
487
- w(1, p(R)),
488
- w(2, p(O)),
489
- w(3, p(oe)),
490
- w(4, A),
491
- w(5, p(le)),
492
- w(6, Ce),
493
- w(7, p(ue)),
494
- w(8, rt),
495
- w(9, fe)
496
- ], W);
497
- function be({ ref: n, ...e }) {
498
- const { icon: r, id: t, className: o, extend: i, ...s } = e, a = `univerjs-icon univerjs-icon-${t} ${o || ""}`.trim(), c = ge(`_${Vt()}`);
499
- return ye(r, `${t}`, {
500
- defIds: r.defIds,
501
- idSuffix: c.current
502
- }, {
503
- ref: n,
504
- className: a,
505
- ...s
506
- }, i);
507
- }
508
- function ye(n, e, r, t, o) {
509
- return Ie(n.tag, {
510
- key: e,
511
- ...xt(n, r, o),
512
- ...t
513
- }, (At(n, r).children || []).map((i, s) => ye(i, `${e}-${n.tag}-${s}`, r, void 0, o)));
514
- }
515
- function xt(n, e, r) {
516
- const t = { ...n.attrs };
517
- r != null && r.colorChannel1 && t.fill === "colorChannel1" && (t.fill = r.colorChannel1), n.tag === "mask" && t.id && (t.id = t.id + e.idSuffix), Object.entries(t).forEach(([i, s]) => {
518
- i === "mask" && typeof s == "string" && (t[i] = s.replace(/url\(#(.*)\)/, `url(#$1${e.idSuffix})`));
519
- });
520
- const { defIds: o } = e;
521
- return !o || o.length === 0 || (n.tag === "use" && t["xlink:href"] && (t["xlink:href"] = t["xlink:href"] + e.idSuffix), Object.entries(t).forEach(([i, s]) => {
522
- typeof s == "string" && (t[i] = s.replace(/url\(#(.*)\)/, `url(#$1${e.idSuffix})`));
523
- })), t;
524
- }
525
- function At(n, e) {
526
- var t;
527
- const { defIds: r } = e;
528
- return !r || r.length === 0 ? n : n.tag === "defs" && ((t = n.children) != null && t.length) ? {
529
- ...n,
530
- children: n.children.map((o) => typeof o.attrs.id == "string" && r && r.includes(o.attrs.id) ? {
531
- ...o,
532
- attrs: {
533
- ...o.attrs,
534
- id: o.attrs.id + e.idSuffix
535
- }
536
- } : o)
537
- } : n;
538
- }
539
- function Vt() {
540
- return Math.random().toString(36).substring(2, 8);
541
- }
542
- be.displayName = "UniverIcon";
543
- const Bt = {
544
- tag: "svg",
545
- attrs: {
546
- xmlns: "http://www.w3.org/2000/svg",
547
- fill: "none",
548
- viewBox: "0 0 17 17",
549
- width: "1em",
550
- height: "1em"
551
- },
552
- children: [
553
- {
554
- tag: "path",
555
- attrs: {
556
- fill: "currentColor",
557
- 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",
558
- fillRule: "evenodd",
559
- clipRule: "evenodd"
560
- }
561
- },
562
- {
563
- tag: "path",
564
- attrs: {
565
- fill: "currentColor",
566
- 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.78345Z"
567
- }
568
- },
569
- {
570
- tag: "path",
571
- attrs: {
572
- fill: "currentColor",
573
- d: "M8.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.78345Z"
574
- }
575
- },
576
- {
577
- tag: "path",
578
- attrs: {
579
- fill: "currentColor",
580
- d: "M11.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"
581
- }
582
- },
583
- {
584
- tag: "path",
585
- attrs: {
586
- fill: "currentColor",
587
- 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",
588
- fillRule: "evenodd",
589
- clipRule: "evenodd"
590
- }
591
- }
592
- ]
593
- }, Ee = ft(function(e, r) {
594
- return Ie(be, Object.assign({}, e, {
595
- id: "comment-icon",
596
- ref: r,
597
- icon: Bt
598
- }));
599
- });
600
- Ee.displayName = "CommentIcon";
601
- const Ht = (n) => ({
602
- id: V.id,
603
- type: Se.BUTTON,
604
- icon: "CommentIcon",
605
- title: "sheetThreadComment.menu.addComment",
606
- hidden$: _e(n, M.UNIVER_SHEET),
607
- disabled$: ve(n, {
608
- workbookTypes: [K],
609
- worksheetTypes: [z],
610
- rangeTypes: [G]
611
- })
612
- }), Lt = (n) => ({
613
- id: pe.id,
614
- type: Se.BUTTON,
615
- icon: "CommentIcon",
616
- tooltip: "sheetThreadComment.menu.commentManagement",
617
- disabled$: ve(n, {
618
- workbookTypes: [K],
619
- worksheetTypes: [z],
620
- rangeTypes: [G]
621
- }),
622
- hidden$: _e(n, M.UNIVER_SHEET)
623
- }), jt = {
624
- id: V.id,
625
- binding: ct.M | ce.CTRL_COMMAND | ce.ALT,
626
- preconditions: st
627
- }, Ft = {
628
- [dt.MEDIA]: {
629
- [pe.id]: {
630
- order: 2,
631
- menuItemFactory: Lt
632
- }
633
- },
634
- [ht.MAIN_AREA]: {
635
- [mt.OTHERS]: {
636
- [V.id]: {
637
- order: 0,
638
- menuItemFactory: Ht
639
- }
640
- }
641
- }
642
- }, Wt = () => {
643
- const n = E(A), e = E(R), r = D(e.activePopup$), t = E(O);
644
- if (D(t.commentUpdate$), !r)
645
- return null;
646
- const { row: o, col: i, unitId: s, subUnitId: a, trigger: c } = r, h = t.getByLocation(s, a, o, i), d = `${Ae.chatAtABC(i)}${o + 1}`, m = () => {
647
- e.hidePopup();
648
- }, C = (l) => {
649
- var v, f, U;
650
- return (U = (f = (v = n.getCurrentUnitForType(M.UNIVER_SHEET)) == null ? void 0 : v.getSheetBySheetId(l)) == null ? void 0 : f.getName()) != null ? U : "";
651
- };
652
- return /* @__PURE__ */ Pe(
653
- Ke,
654
- {
655
- onClick: () => {
656
- e.persistPopup();
657
- },
658
- prefix: "cell",
659
- id: h,
660
- unitId: s,
661
- subUnitId: a,
662
- type: M.UNIVER_SHEET,
663
- refStr: d,
664
- onClose: m,
665
- getSubUnitName: C,
666
- autoFocus: c === "context-menu"
667
- }
668
- );
669
- }, Zt = () => {
670
- var g;
671
- const n = E(Ce), e = E(A), r = E(R), t = e.getCurrentUnitForType(M.UNIVER_SHEET), o = t.getUnitId(), i = E(re), s = gt(() => t.activeSheet$.pipe(vt((u) => u == null ? void 0 : u.getSheetId())), [t.activeSheet$]), a = D(s, (g = t.getActiveSheet()) == null ? void 0 : g.getSheetId()), c = ge(null), h = E(oe), d = D(h.activeCommentId$), m = D(h.panelVisible$, h.panelVisible), C = me((u) => {
672
- const I = t.getSheets(), _ = {};
673
- I.forEach((P, S) => {
674
- _[P.getSheetId()] = S;
675
- });
676
- const T = (P) => P.map((S) => {
677
- var se;
678
- const b = x(S.ref), Re = [(se = _[S.subUnitId]) != null ? se : 0, b.row, b.column];
679
- return { ...S, p: Re };
680
- }).sort((S, b) => S.p[0] === b.p[0] ? S.p[1] === b.p[1] ? S.p[2] - b.p[2] : S.p[1] - b.p[1] : S.p[0] - b.p[0]);
681
- return [
682
- ...T(u.filter((P) => !P.resolved)),
683
- ...T(u.filter((P) => P.resolved))
684
- ];
685
- }, [t]), l = me((u) => {
686
- var I;
687
- if (u.unitId === o && u.subUnitId === a && !u.resolved) {
688
- const { row: _, column: T } = x(u.ref), P = t.getSheetBySheetId(u.subUnitId), S = (I = P == null ? void 0 : P.getMergedCell(_, T)) != null ? I : {
689
- startColumn: T,
690
- endColumn: T,
691
- startRow: _,
692
- endRow: _
693
- };
694
- if (!Number.isNaN(_) && !Number.isNaN(T))
695
- return n.addShape({
696
- range: S,
697
- style: {
698
- // hasAutoFill: false,
699
- fill: "rgb(255, 189, 55, 0.35)",
700
- strokeWidth: 1,
701
- stroke: "#FFBD37",
702
- widgets: {}
703
- },
704
- primary: null
705
- });
706
- }
707
- return null;
708
- }, [n, a, o]), v = (u) => {
709
- var I, _;
710
- return (_ = (I = t.getSheetBySheetId(u)) == null ? void 0 : I.getName()) != null ? _ : "";
711
- }, f = () => {
712
- i.executeCommand(V.id);
713
- }, U = (u) => {
714
- d && d.unitId === u.unitId && d.subUnitId === u.subUnitId && d.commentId === u.id || (c.current && (n.removeShape(c.current), c.current = null), c.current = l(u));
715
- }, N = () => {
716
- c.current && (n.removeShape(c.current), c.current = null);
717
- }, q = (u, I) => {
718
- I && r.hidePopup();
719
- };
720
- return It(() => {
721
- !m && c.current && n.removeShape(c.current);
722
- }, [n, m]), /* @__PURE__ */ Pe(
723
- Ye,
724
- {
725
- unitId: o,
726
- subUnitId$: s,
727
- type: M.UNIVER_SHEET,
728
- onAdd: f,
729
- getSubUnitName: v,
730
- onResolve: q,
731
- sortComments: C,
732
- onItemEnter: U,
733
- onItemLeave: N,
734
- onDeleteComment: () => (N(), !0)
735
- }
736
- );
737
- };
738
- var Gt = Object.getOwnPropertyDescriptor, zt = (n, e, r, t) => {
739
- for (var o = t > 1 ? void 0 : t ? Gt(e, r) : e, i = n.length - 1, s; i >= 0; i--)
740
- (s = n[i]) && (o = s(o) || o);
741
- return o;
742
- }, ee = (n, e) => (r, t) => e(r, t, n);
743
- let Z = class extends k {
744
- constructor(n, e, r) {
745
- super(), this._menuManagerService = n, this._componentManager = e, this._shortcutService = r, this._initMenu(), this._initShortcut(), this._initComponent();
746
- }
747
- _initShortcut() {
748
- this._shortcutService.registerShortcut(jt);
749
- }
750
- _initMenu() {
751
- this._menuManagerService.mergeMenu(Ft);
752
- }
753
- _initComponent() {
754
- [
755
- [Te, Wt],
756
- [qe, Zt],
757
- ["CommentIcon", Ee]
758
- ].forEach(([n, e]) => {
759
- this.disposeWithMe(
760
- this._componentManager.register(n, e)
761
- );
762
- });
763
- }
764
- };
765
- Z = zt([
766
- ee(0, ut),
767
- ee(1, p(lt)),
768
- ee(2, pt)
769
- ], Z);
770
- var Kt = Object.defineProperty, Yt = Object.getOwnPropertyDescriptor, qt = (n, e, r) => e in n ? Kt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : n[e] = r, Jt = (n, e, r, t) => {
771
- for (var o = t > 1 ? void 0 : t ? Yt(e, r) : e, i = n.length - 1, s; i >= 0; i--)
772
- (s = n[i]) && (o = s(o) || o);
773
- return o;
774
- }, te = (n, e) => (r, t) => e(r, t, n), Y = (n, e, r) => qt(n, typeof e != "symbol" ? e + "" : e, r);
775
- let $ = class extends Le {
776
- constructor(n = de, e, r, t) {
777
- super(), this._config = n, this._injector = e, this._commandService = r, this._configService = t;
778
- const { menu: o, ...i } = je(
779
- {},
780
- de,
781
- this._config
782
- );
783
- o && this._configService.setConfig("menu", o, { merge: !0 }), this._configService.setConfig(bt, i);
784
- }
785
- onStarting() {
786
- [
787
- [Z],
788
- [L],
789
- [j],
790
- [F],
791
- [W],
792
- [R]
793
- ].forEach((n) => {
794
- this._injector.add(n);
795
- }), [V].forEach((n) => {
796
- this._commandService.registerCommand(n);
797
- }), this._injector.get(Z);
798
- }
799
- onReady() {
800
- this._injector.get(L);
801
- }
802
- onRendered() {
803
- this._injector.get(j), this._injector.get(F), this._injector.get(W);
804
- }
805
- };
806
- Y($, "pluginName", we);
807
- Y($, "packageName", Me.name);
808
- Y($, "version", Me.version);
809
- Y($, "type", M.UNIVER_SHEET);
810
- $ = Jt([
811
- Ve(Je, ze),
812
- te(1, p(Be)),
813
- te(2, p(re)),
814
- te(3, He)
815
- ], $);
816
- export {
817
- vn as AddCommentCommand,
818
- _n as DeleteCommentCommand,
819
- Sn as DeleteCommentTreeCommand,
820
- fn as IThreadCommentDataSourceService,
821
- gn as ResolveCommentCommand,
822
- we as SHEETS_THREAD_COMMENT,
823
- R as SheetsThreadCommentPopupService,
824
- V as ShowAddSheetCommentModalOperation,
825
- $ as UniverSheetsThreadCommentUIPlugin,
826
- pn as UniverThreadCommentUIPlugin,
827
- In as UpdateCommentCommand
828
- };
1
+ import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,Plugin as u,RANGE_TYPE as d,Range as f,Rectangle as p,Tools as m,UniverInstanceType as h,merge as g}from"@univerjs/core";import{INTERCEPTOR_POINT as ee,RangeProtectionPermissionViewPoint as _,SetWorksheetActiveOperation as v,SheetInterceptorService as y,SheetPermissionCheckController as b,SheetsSelectionsService as te,WorkbookCommentPermission as x,WorksheetViewPermission as S,getSheetCommandTarget as ne}from"@univerjs/sheets";import{SheetsThreadCommentModel as C,UniverSheetsThreadCommentPlugin as re}from"@univerjs/sheets-thread-comment";import{SetActiveCommentOperation as w,THREAD_COMMENT_PANEL as ie,ThreadCommentPanel as ae,ThreadCommentPanelService as T,ThreadCommentTree as oe,ToggleSheetCommentPanelOperation as E,UniverThreadCommentUIPlugin as se,UniverThreadCommentUIPlugin as ce}from"@univerjs/thread-comment-ui";import{COPY_TYPE as le,CellPopupManagerService as ue,HoverManagerService as de,IEditorBridgeService as fe,IMarkSelectionService as D,ISheetClipboardService as pe,ScrollToRangeOperation as me,SheetCanvasPopManagerService as he,SheetSkeletonManagerService as ge,getCurrentRangeDisable$ as O,whenSheetEditorFocused as _e}from"@univerjs/sheets-ui";import{ComponentManager as ve,ContextMenuGroup as ye,ContextMenuPosition as be,IMenuManagerService as xe,IShortcutService as Se,IZenZoneService as Ce,KeyCode as we,MenuItemType as k,MetaKeys as A,RibbonInsertGroup as Te,getMenuHiddenObservable as j,useDependency as M,useObservable as N}from"@univerjs/ui";import{BehaviorSubject as Ee,debounceTime as P,map as De}from"rxjs";import{IRenderManagerService as F}from"@univerjs/engine-render";import{serializeRange as Oe,singleReferenceToGrid as I}from"@univerjs/engine-formula";import{AddCommentCommand as ke,AddCommentMutation as L,DeleteCommentCommand as Ae,DeleteCommentMutation as R,DeleteCommentTreeCommand as je,IThreadCommentDataSourceService as Me,IThreadCommentDataSourceService as Ne,ResolveCommentCommand as Pe,UpdateCommentCommand as Fe}from"@univerjs/thread-comment";import{CommentIcon as Ie}from"@univerjs/icons";import{jsx as z}from"react/jsx-runtime";import{useCallback as B,useEffect as Le,useMemo as Re,useRef as ze}from"react";const Be=`univer.sheet.thread-comment-modal`,V=`SHEET_THREAD_COMMENT`;function H(e){"@babel/helpers - typeof";return H=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},H(e)}function Ve(e,t){if(H(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(H(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function He(e){var t=Ve(e,`string`);return H(t)==`symbol`?t:t+``}function U(e,t,n){return(t=He(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function W(e,t){return function(n,r){t(n,r,e)}}function G(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 K=class extends n{get activePopup(){return this._activePopup}constructor(e,t,n){super(),this._canvasPopupManagerService=e,this._zenZoneService=t,this._cellPopupManagerService=n,U(this,`_lastPopup`,null),U(this,`_activePopup`,void 0),U(this,`_activePopup$`,new Ee(null)),U(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey:Be,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,excludeOutside:[...Array.from(document.querySelectorAll(`.univer-thread-comment`)),document.getElementById(`thread-comment-add`)].filter(Boolean),priority:2});if(!c)throw Error(`[SheetsThreadCommentPopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(){this._activePopup&&(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};K=G([W(0,s(he)),W(1,Ce),W(2,s(ue))],K);const q={type:e.OPERATION,id:`sheets.operation.show-comment-modal`,handler(e){var t;let n=e.get(te),r=e.get(o),i=e.get(K),a=e.get(T),s=(t=n.getCurrentLastSelection())==null?void 0:t.primary,c=e.get(C);if(!s)return!1;let l=ne(r);if(!l)return!1;let{workbook:u,worksheet:d,unitId:f,subUnitId:p}=l,m={workbook:u,worksheet:d,unitId:f,subUnitId:p,row:s.startRow,col:s.startColumn};i.showPopup(m);let h=c.getByLocation(f,p,s.startRow,s.startColumn);return h&&a.setActiveComment({unitId:f,subUnitId:p,commentId:h,trigger:`context-menu`}),!0}};var Ue=`@univerjs/sheets-thread-comment-ui`,We=`0.18.0`;const Ge=`sheets-thread-comment.config`;Symbol(Ge);const Ke={};let J=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsThreadCommentModel=t,this._univerInstanceService=n,this._renderManagerService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ee.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsThreadCommentModel.showCommentMarker(a,o,r,i)?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(h.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(P(16)).subscribe(()=>{e()}))}};J=G([W(0,s(y)),W(1,s(C)),W(2,o),W(3,F)],J);const qe=(e,t,n)=>{let r=I(e),i=n.row-t.row,a=n.column-t.column;return Oe({startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i})};let Y=class extends n{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=n,U(this,`_copyInfo`,void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:V,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,t,n,r)=>{let{unitId:i,subUnitId:a,range:o}=t,s={row:o.rows[0],column:o.cols[0]};if(r.copyType===le.CUT&&this._copyInfo){let{range:e,unitId:t,subUnitId:n}=this._copyInfo,r={row:e.startRow,column:e.startColumn};if(!(i===t&&a===n)){let o=[];f.foreach(e,(e,r)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(t,n,e,r);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{o.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||o.push(t)})});let c=[],l=[],u=[],d=[],p=e=>{c.unshift({id:R.id,params:{unitId:t,subUnitId:n,commentId:e.id}}),u.push({id:L.id,params:{unitId:i,subUnitId:a,comment:{...e,ref:qe(e.ref,r,s),unitId:i,subUnitId:a},sync:!0}}),l.push({id:L.id,params:{unitId:t,subUnitId:n,comment:e,sync:!0}}),d.unshift({id:R.id,params:{unitId:i,subUnitId:a,commentId:e.id}})};return o.forEach(e=>{p(e)}),{redos:[...c,...u],undos:[...d,...l]}}}return{redos:[],undos:[]}}}))}};Y=G([W(0,s(pe)),W(1,s(C)),W(2,Ne)],Y);let X=class extends n{constructor(e,t,n,r){super(),this._hoverManagerService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._sheetPermissionCheckController=r,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(P(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){let{location:n}=e,{unitId:r,subUnitId:i,row:a,col:o}=n,s=this._sheetsThreadCommentModel.getByLocation(r,i,a,o);if(s){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:a,startColumn:o,endRow:a,endColumn:o}],r,i))return;let e=this._sheetsThreadCommentModel.getComment(r,i,s);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:r,subUnitId:i,row:a,col:o,commentId:s,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};X=G([W(0,s(de)),W(1,s(K)),W(2,s(C)),W(3,s(b))],X);let Z=class extends n{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._commandService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._threadCommentPanelService=r,this._univerInstanceService=i,this._sheetPermissionCheckController=a,this._markSelectionService=o,this._sheetSelectionService=s,this._editorBridgeService=c,this._renderManagerService=l,U(this,`_isSwitchToCommenting`,!1),U(this,`_selectionShapeInfo`,null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(ge).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?d.NORMAL:a)!==d.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&p.equals(l.mergeInfo,o))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let u=l.actualRow,f=l.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,n,u,f)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let m=this._sheetsThreadCommentModel.getByLocation(t,n,u,f);m&&this._commandService.executeCommand(w.id,{unitId:t,subUnitId:n,commentId:m})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchToCommenting)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsThreadCommentPopupService.hidePopup()}))}_initCommandListener(){this._commandService.onCommandExecuted(e=>{if(e.id===R.id){let t=e.params,n=this._sheetsThreadCommentPopupService.activePopup;if(!n)return;let{unitId:r,subUnitId:i,commentId:a}=n;t.unitId===r&&t.subUnitId===i&&t.commentId===a&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async e=>{if(e){var t;let{unitId:n,subUnitId:r,commentId:i,trigger:a}=e,o=this._sheetsThreadCommentModel.getComment(n,r,i);if(!o||o.resolved)return;let s=this._univerInstanceService.getCurrentUnitForType(h.UNIVER_SHEET);if(!s||s.getUnitId()!==n)return;this._isSwitchToCommenting=!0,((t=s.getActiveSheet())==null?void 0:t.getSheetId())!==r&&await this._commandService.executeCommand(v.id,{unitId:n,subUnitId:r}),this._isSwitchToCommenting=!1;let c=I(o.ref),{row:l,column:u}=c;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:l,startColumn:u,endRow:l,endColumn:u}],n,r)||(await this._commandService.executeCommand(me.id,{range:{startRow:Math.max(c.row-1,0),endRow:c.row+1,startColumn:Math.max(c.column-1,0),endColumn:c.column+1}}),this._editorBridgeService.isVisible().visible))return;this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:r,row:c.row,col:c.column,commentId:o.id,trigger:a})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(P(100)).subscribe(e=>{var t,n;if(!e){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}let{unitId:r,subUnitId:i,commentId:a}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);let o=this._sheetsThreadCommentModel.getComment(r,i,a);if(!o)return;let{row:s,column:c}=I(o.ref);if(Number.isNaN(s)||Number.isNaN(c))return null;let l=(t=this._univerInstanceService.getCurrentUnitForType(h.UNIVER_SHEET))==null?void 0:t.getSheetBySheetId(i),u=(n=l==null?void 0:l.getMergedCell(s,c))==null?{startColumn:c,endColumn:c,startRow:s,endRow:s}:n,d=this._markSelectionService.addShape({range:u,style:{fill:`rgba(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1);d&&(this._selectionShapeInfo={...e,shapeId:d})}))}};Z=G([W(0,i),W(1,s(K)),W(2,s(C)),W(3,s(T)),W(4,o),W(5,s(b)),W(6,D),W(7,s(te)),W(8,fe),W(9,F)],Z);const Je=e=>({id:q.id,type:k.BUTTON,icon:`CommentIcon`,title:`sheetThreadComment.menu.addComment`,hidden$:j(e,h.UNIVER_SHEET),disabled$:O(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]})}),Ye=e=>({id:E.id,type:k.BUTTON,icon:`CommentIcon`,tooltip:`sheetThreadComment.menu.commentManagement`,disabled$:O(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]}),hidden$:j(e,h.UNIVER_SHEET)}),Xe={id:q.id,binding:we.M|A.CTRL_COMMAND|A.ALT,preconditions:_e},Ze={[Te.MEDIA]:{[E.id]:{order:2,menuItemFactory:Ye}},[be.MAIN_AREA]:{[ye.OTHERS]:{[q.id]:{order:0,menuItemFactory:Je}}}},Qe=()=>{let e=M(o),t=M(K),n=N(t.activePopup$),r=M(C);if(N(r.commentUpdate$),!n)return null;let{row:i,col:a,unitId:s,subUnitId:c,trigger:l}=n,u=r.getByLocation(s,c,i,a),d=`${m.chatAtABC(a)}${i+1}`;return z(oe,{onClick:()=>{t.persistPopup()},prefix:`cell`,id:u,unitId:s,subUnitId:c,type:h.UNIVER_SHEET,refStr:d,onClose:()=>{t.hidePopup()},getSubUnitName:t=>{var n,r;return(n=(r=e.getCurrentUnitForType(h.UNIVER_SHEET))==null||(r=r.getSheetBySheetId(t))==null?void 0:r.getName())==null?``:n},autoFocus:l===`context-menu`})},$e=()=>{var e;let t=M(D),n=M(o),r=M(K),a=n.getCurrentUnitForType(h.UNIVER_SHEET),s=a.getUnitId(),c=M(i),l=Re(()=>a.activeSheet$.pipe(De(e=>e==null?void 0:e.getSheetId())),[a.activeSheet$]),u=N(l,(e=a.getActiveSheet())==null?void 0:e.getSheetId()),d=ze(null),f=M(T),p=N(f.activeCommentId$),m=N(f.panelVisible$,f.panelVisible),g=B(e=>{let t=a.getSheets(),n={};t.forEach((e,t)=>{n[e.getSheetId()]=t});let r=e=>e.map(e=>{var t;let r=I(e.ref),i=[(t=n[e.subUnitId])==null?0:t,r.row,r.column];return{...e,p:i}}).sort((e,t)=>e.p[0]===t.p[0]?e.p[1]===t.p[1]?e.p[2]-t.p[2]:e.p[1]-t.p[1]:e.p[0]-t.p[0]);return[...r(e.filter(e=>!e.resolved)),...r(e.filter(e=>e.resolved))]},[a]),ee=B(e=>{if(e.unitId===s&&e.subUnitId===u&&!e.resolved){var n;let{row:r,column:i}=I(e.ref),o=a.getSheetBySheetId(e.subUnitId),s=(n=o==null?void 0:o.getMergedCell(r,i))==null?{startColumn:i,endColumn:i,startRow:r,endRow:r}:n;if(!Number.isNaN(r)&&!Number.isNaN(i))return t.addShape({range:s,style:{fill:`rgb(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null})}return null},[t,u,s]),_=e=>{var t,n;return(t=(n=a.getSheetBySheetId(e))==null?void 0:n.getName())==null?``:t},v=()=>{c.executeCommand(q.id)},y=e=>{p&&p.unitId===e.unitId&&p.subUnitId===e.subUnitId&&p.commentId===e.id||(d.current&&(t.removeShape(d.current),d.current=null),d.current=ee(e))},b=()=>{d.current&&(t.removeShape(d.current),d.current=null)};return Le(()=>{!m&&d.current&&t.removeShape(d.current)},[t,m]),z(ae,{unitId:s,subUnitId$:l,type:h.UNIVER_SHEET,onAdd:v,getSubUnitName:_,onResolve:(e,t)=>{t&&r.hidePopup()},sortComments:g,onItemEnter:y,onItemLeave:b,onDeleteComment:()=>(b(),!0)})};let Q=class extends n{constructor(e,t,n){super(),this._menuManagerService=e,this._componentManager=t,this._shortcutService=n,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(Xe)}_initMenu(){this._menuManagerService.mergeMenu(Ze)}_initComponent(){[[Be,Qe],[ie,$e],[`CommentIcon`,Ie]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=G([W(0,xe),W(1,s(ve)),W(2,Se)],Q);let $=class extends u{constructor(e=Ke,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=g({},Ke,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(Ge,a)}onStarting(){[[Q],[J],[Y],[X],[Z],[K]].forEach(e=>{this._injector.add(e)}),[q].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(Q)}onReady(){this._injector.get(J)}onRendered(){this._injector.get(Y),this._injector.get(X),this._injector.get(Z)}};U($,`pluginName`,V),U($,`packageName`,Ue),U($,`version`,We),U($,`type`,h.UNIVER_SHEET),$=G([t(ce,re),W(1,s(c)),W(2,s(i)),W(3,a)],$);export{ke as AddCommentCommand,Ae as DeleteCommentCommand,je as DeleteCommentTreeCommand,Me as IThreadCommentDataSourceService,Pe as ResolveCommentCommand,V as SHEETS_THREAD_COMMENT,K as SheetsThreadCommentPopupService,q as ShowAddSheetCommentModalOperation,$ as UniverSheetsThreadCommentUIPlugin,se as UniverThreadCommentUIPlugin,Fe as UpdateCommentCommand};