@univerjs/sheets-thread-comment-ui 0.4.0-nightly.202410290723

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 (34) hide show
  1. package/README.md +98 -0
  2. package/lib/cjs/index.js +1 -0
  3. package/lib/es/index.js +818 -0
  4. package/lib/locale/en-US.json +8 -0
  5. package/lib/locale/fa-IR.json +8 -0
  6. package/lib/locale/ru-RU.json +8 -0
  7. package/lib/locale/vi-VN.json +8 -0
  8. package/lib/locale/zh-CN.json +8 -0
  9. package/lib/locale/zh-TW.json +8 -0
  10. package/lib/types/commands/operations/comment.operation.d.ts +2 -0
  11. package/lib/types/controllers/config.schema.d.ts +9 -0
  12. package/lib/types/controllers/menu.d.ts +12 -0
  13. package/lib/types/controllers/menu.schema.d.ts +2 -0
  14. package/lib/types/controllers/render-controllers/render.controller.d.ts +13 -0
  15. package/lib/types/controllers/sheets-thread-comment-copy-paste.controller.d.ts +12 -0
  16. package/lib/types/controllers/sheets-thread-comment-hover.controller.d.ts +12 -0
  17. package/lib/types/controllers/sheets-thread-comment-popup.controller.d.ts +28 -0
  18. package/lib/types/controllers/sheets-thread-comment-remove.controller.d.ts +11 -0
  19. package/lib/types/controllers/sheets-thread-comment.controller.d.ts +11 -0
  20. package/lib/types/index.d.ts +24 -0
  21. package/lib/types/locale/en-US.d.ts +24 -0
  22. package/lib/types/locale/fa-IR.d.ts +24 -0
  23. package/lib/types/locale/ru-RU.d.ts +24 -0
  24. package/lib/types/locale/vi-VN.d.ts +24 -0
  25. package/lib/types/locale/zh-CN.d.ts +24 -0
  26. package/lib/types/locale/zh-TW.d.ts +24 -0
  27. package/lib/types/plugin.d.ts +14 -0
  28. package/lib/types/services/sheets-thread-comment-popup.service.d.ts +23 -0
  29. package/lib/types/types/const.d.ts +18 -0
  30. package/lib/types/types/interfaces/i-sheet-thread-comment.d.ts +5 -0
  31. package/lib/types/views/sheets-thread-comment-cell/index.d.ts +2 -0
  32. package/lib/types/views/sheets-thread-comment-panel/index.d.ts +2 -0
  33. package/lib/umd/index.js +1 -0
  34. package/package.json +95 -0
@@ -0,0 +1,818 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
+ import { Inject, Disposable, DisposableCollection, CommandType, IUniverInstanceService, InterceptorEffectEnum, UniverInstanceType, useDependency, Tools, ICommandService, Range, RANGE_TYPE, Rectangle, DependentOn, Injector, Plugin, IConfigService } from "@univerjs/core";
6
+ import { SheetsSelectionsService, getSheetCommandTarget, SheetInterceptorService, INTERCEPTOR_POINT, WorkbookCommentPermission, WorksheetViewPermission, RangeProtectionPermissionViewPoint, SetWorksheetActiveOperation, RemoveSheetCommand } from "@univerjs/sheets";
7
+ import { SheetsThreadCommentModel, UniverSheetsThreadCommentPlugin } from "@univerjs/sheets-thread-comment";
8
+ import { ThreadCommentPanelService, ThreadCommentTree, ThreadCommentPanel, ToggleSheetCommentPanelOperation, THREAD_COMMENT_PANEL, SetActiveCommentOperation, UniverThreadCommentUIPlugin } from "@univerjs/thread-comment-ui";
9
+ import { IThreadCommentMentionDataService, UniverThreadCommentUIPlugin as UniverThreadCommentUIPlugin2 } from "@univerjs/thread-comment-ui";
10
+ import { SheetCanvasPopManagerService, IMarkSelectionService, whenSheetEditorFocused, getCurrentRangeDisable$, ISheetClipboardService, COPY_TYPE, HoverManagerService, SheetPermissionInterceptorBaseController, IEditorBridgeService, SheetSkeletonManagerService, ScrollToRangeOperation } from "@univerjs/sheets-ui";
11
+ import { IZenZoneService, useObservable, KeyCode, MetaKeys, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IMenuManagerService, IShortcutService } from "@univerjs/ui";
12
+ import { BehaviorSubject, debounceTime, map } from "rxjs";
13
+ import { IRenderManagerService } from "@univerjs/engine-render";
14
+ import React, { forwardRef, useRef, createElement, useMemo, useCallback, useEffect } from "react";
15
+ import { singleReferenceToGrid, serializeRange } from "@univerjs/engine-formula";
16
+ import { IThreadCommentDataSourceService, DeleteCommentMutation, AddCommentMutation, ThreadCommentModel } from "@univerjs/thread-comment";
17
+ import { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, IThreadCommentDataSourceService as IThreadCommentDataSourceService2, ResolveCommentCommand, UpdateCommentCommand } from "@univerjs/thread-comment";
18
+ const SHEETS_THREAD_COMMENT_MODAL = "univer.sheet.thread-comment-modal", COMMENT_SINGLE_ICON = "comment-single", SHEETS_THREAD_COMMENT = "SHEET_THREAD_COMMENT";
19
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
20
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
21
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
22
+ return kind && result && __defProp$7(target, key, result), result;
23
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a;
24
+ let SheetsThreadCommentPopupService = (_a = class extends Disposable {
25
+ constructor(_canvasPopupManagerService, _zenZoneService) {
26
+ super();
27
+ __publicField(this, "_lastPopup", null);
28
+ __publicField(this, "_activePopup");
29
+ __publicField(this, "_activePopup$", new BehaviorSubject(null));
30
+ __publicField(this, "activePopup$", this._activePopup$.asObservable());
31
+ this._canvasPopupManagerService = _canvasPopupManagerService, this._zenZoneService = _zenZoneService, 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((visible) => {
40
+ visible && this.hidePopup();
41
+ }));
42
+ }
43
+ showPopup(location, onHide) {
44
+ var _a9;
45
+ const { row, col, unitId, subUnitId } = location;
46
+ if (this._activePopup && row === this._activePopup.row && col === this._activePopup.col && unitId === this._activePopup.unitId && subUnitId === ((_a9 = this.activePopup) == null ? void 0 : _a9.subUnitId)) {
47
+ this._activePopup = location, this._activePopup$.next(location);
48
+ return;
49
+ }
50
+ if (this._lastPopup && this._lastPopup.dispose(), this._zenZoneService.visible)
51
+ return;
52
+ this._activePopup = location, this._activePopup$.next(location);
53
+ const popupDisposable = this._canvasPopupManagerService.attachPopupToCell(
54
+ row,
55
+ col,
56
+ {
57
+ componentKey: SHEETS_THREAD_COMMENT_MODAL,
58
+ onClickOutside: /* @__PURE__ */ __name(() => {
59
+ this.hidePopup();
60
+ }, "onClickOutside"),
61
+ direction: "horizontal",
62
+ excludeOutside: [
63
+ ...Array.from(document.querySelectorAll(".univer-thread-comment")),
64
+ document.getElementById("thread-comment-add")
65
+ ].filter(Boolean)
66
+ }
67
+ );
68
+ if (!popupDisposable)
69
+ throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");
70
+ const disposableCollection = new DisposableCollection();
71
+ disposableCollection.add(popupDisposable), disposableCollection.add({
72
+ dispose: /* @__PURE__ */ __name(() => {
73
+ onHide == null || onHide();
74
+ }, "dispose")
75
+ }), this._lastPopup = disposableCollection;
76
+ }
77
+ hidePopup() {
78
+ this._activePopup && (this._lastPopup && this._lastPopup.dispose(), this._lastPopup = null, this._activePopup = null, this._activePopup$.next(null));
79
+ }
80
+ persistPopup() {
81
+ !this._activePopup || !this._activePopup.temp || (this._activePopup = {
82
+ ...this._activePopup,
83
+ temp: !1
84
+ }, this._activePopup$.next(this._activePopup));
85
+ }
86
+ }, __name(_a, "SheetsThreadCommentPopupService"), _a);
87
+ SheetsThreadCommentPopupService = __decorateClass$7([
88
+ __decorateParam$7(0, Inject(SheetCanvasPopManagerService)),
89
+ __decorateParam$7(1, IZenZoneService)
90
+ ], SheetsThreadCommentPopupService);
91
+ const ShowAddSheetCommentModalOperation = {
92
+ type: CommandType.OPERATION,
93
+ id: "sheets.operation.show-comment-modal",
94
+ handler(accessor) {
95
+ var _a9;
96
+ const selectionManagerService = accessor.get(SheetsSelectionsService), univerInstanceService = accessor.get(IUniverInstanceService), sheetsThreadCommentPopupService = accessor.get(SheetsThreadCommentPopupService), threadCommentPanelService = accessor.get(ThreadCommentPanelService), activeCell = (_a9 = selectionManagerService.getCurrentLastSelection()) == null ? void 0 : _a9.primary, model = accessor.get(SheetsThreadCommentModel);
97
+ if (!activeCell)
98
+ return !1;
99
+ const result = getSheetCommandTarget(univerInstanceService);
100
+ if (!result)
101
+ return !1;
102
+ const { workbook, worksheet, unitId, subUnitId } = result, location = {
103
+ workbook,
104
+ worksheet,
105
+ unitId,
106
+ subUnitId,
107
+ row: activeCell.startRow,
108
+ col: activeCell.startColumn
109
+ };
110
+ sheetsThreadCommentPopupService.showPopup(location);
111
+ const rootId = model.getByLocation(unitId, subUnitId, activeCell.startRow, activeCell.startColumn);
112
+ return rootId && threadCommentPanelService.setActiveComment({
113
+ unitId,
114
+ subUnitId,
115
+ commentId: rootId,
116
+ trigger: "context-menu"
117
+ }), !0;
118
+ }
119
+ }, PLUGIN_CONFIG_KEY = "sheets-thread-comment.config", defaultPluginConfig = {};
120
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
121
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
122
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
123
+ return kind && result && __defProp$6(target, key, result), result;
124
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a2;
125
+ let SheetsThreadCommentRenderController = (_a2 = class extends Disposable {
126
+ constructor(_sheetInterceptorService, _sheetsThreadCommentModel, _univerInstanceService, _renderManagerService) {
127
+ super(), this._sheetInterceptorService = _sheetInterceptorService, this._sheetsThreadCommentModel = _sheetsThreadCommentModel, this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._initViewModelIntercept(), this._initSkeletonChange();
128
+ }
129
+ _initViewModelIntercept() {
130
+ this.disposeWithMe(
131
+ this._sheetInterceptorService.intercept(
132
+ INTERCEPTOR_POINT.CELL_CONTENT,
133
+ {
134
+ effect: InterceptorEffectEnum.Style,
135
+ handler: /* @__PURE__ */ __name((cell, pos, next) => {
136
+ const { row, col, unitId, subUnitId } = pos;
137
+ return this._sheetsThreadCommentModel.showCommentMarker(unitId, subUnitId, row, col) ? next({
138
+ ...cell,
139
+ markers: {
140
+ ...cell == null ? void 0 : cell.markers,
141
+ tr: {
142
+ color: "#FFBD37",
143
+ size: 6
144
+ }
145
+ }
146
+ }) : next(cell);
147
+ }, "handler"),
148
+ priority: 100
149
+ }
150
+ )
151
+ );
152
+ }
153
+ _initSkeletonChange() {
154
+ const markSkeletonDirty = /* @__PURE__ */ __name(() => {
155
+ var _a9;
156
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
157
+ if (!workbook) return;
158
+ const unitId = workbook.getUnitId(), currentRender = this._renderManagerService.getRenderById(unitId);
159
+ (_a9 = currentRender == null ? void 0 : currentRender.mainComponent) == null || _a9.makeForceDirty();
160
+ }, "markSkeletonDirty");
161
+ this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(debounceTime(16)).subscribe(() => {
162
+ markSkeletonDirty();
163
+ }));
164
+ }
165
+ }, __name(_a2, "SheetsThreadCommentRenderController"), _a2);
166
+ SheetsThreadCommentRenderController = __decorateClass$6([
167
+ __decorateParam$6(0, Inject(SheetInterceptorService)),
168
+ __decorateParam$6(1, Inject(SheetsThreadCommentModel)),
169
+ __decorateParam$6(2, IUniverInstanceService),
170
+ __decorateParam$6(3, IRenderManagerService)
171
+ ], SheetsThreadCommentRenderController);
172
+ var __assign = function() {
173
+ return __assign = Object.assign || function(t) {
174
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
175
+ s = arguments[i];
176
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
177
+ }
178
+ return t;
179
+ }, __assign.apply(this, arguments);
180
+ }, __rest = function(s, e) {
181
+ var t = {};
182
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
183
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
184
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
185
+ e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
186
+ return t;
187
+ }, IconBase = forwardRef(function(props, ref) {
188
+ var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
189
+ return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
190
+ });
191
+ function render(node, id, runtimeProps, rootProps, extend) {
192
+ return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
193
+ return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
194
+ }));
195
+ }
196
+ __name(render, "render");
197
+ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
198
+ var attrs = __assign({}, node.attrs);
199
+ extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
200
+ var defIds = runtimeProps.defIds;
201
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a9) {
202
+ var key = _a9[0], value = _a9[1];
203
+ typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
204
+ })), attrs;
205
+ }
206
+ __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
207
+ function replaceRuntimeIdsInDefs(node, runtimeProps) {
208
+ var _a9, defIds = runtimeProps.defIds;
209
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a9 = node.children) === null || _a9 === void 0) && _a9.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
210
+ return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
211
+ }) }) : node;
212
+ }
213
+ __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
214
+ function generateShortUuid() {
215
+ return Math.random().toString(36).substring(2, 8);
216
+ }
217
+ __name(generateShortUuid, "generateShortUuid");
218
+ IconBase.displayName = "UniverIcon";
219
+ var element = { 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" } }] }, CommentSingle = forwardRef(function(props, ref) {
220
+ return createElement(IconBase, Object.assign({}, props, {
221
+ id: "comment-single",
222
+ ref,
223
+ icon: element
224
+ }));
225
+ });
226
+ CommentSingle.displayName = "CommentSingle";
227
+ const SheetsThreadCommentCell = /* @__PURE__ */ __name(() => {
228
+ const univerInstanceService = useDependency(IUniverInstanceService), sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService), activePopup = useObservable(sheetsThreadCommentPopupService.activePopup$), sheetThreadCommentModel = useDependency(SheetsThreadCommentModel);
229
+ if (useObservable(sheetThreadCommentModel.commentUpdate$), !activePopup)
230
+ return null;
231
+ const { row, col, unitId, subUnitId, trigger } = activePopup, rootId = sheetThreadCommentModel.getByLocation(unitId, subUnitId, row, col), ref = `${Tools.chatAtABC(col)}${row + 1}`, onClose = /* @__PURE__ */ __name(() => {
232
+ sheetsThreadCommentPopupService.hidePopup();
233
+ }, "onClose"), getSubUnitName = /* @__PURE__ */ __name((id) => {
234
+ var _a9, _b, _c;
235
+ return (_c = (_b = (_a9 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a9.getSheetBySheetId(id)) == null ? void 0 : _b.getName()) != null ? _c : "";
236
+ }, "getSubUnitName");
237
+ return /* @__PURE__ */ React.createElement(
238
+ ThreadCommentTree,
239
+ {
240
+ onClick: /* @__PURE__ */ __name(() => {
241
+ sheetsThreadCommentPopupService.persistPopup();
242
+ }, "onClick"),
243
+ prefix: "cell",
244
+ id: rootId,
245
+ unitId,
246
+ subUnitId,
247
+ type: UniverInstanceType.UNIVER_SHEET,
248
+ refStr: ref,
249
+ onClose,
250
+ getSubUnitName,
251
+ autoFocus: trigger === "context-menu"
252
+ }
253
+ );
254
+ }, "SheetsThreadCommentCell"), SheetsThreadCommentPanel = /* @__PURE__ */ __name(() => {
255
+ var _a9;
256
+ const markSelectionService = useDependency(IMarkSelectionService), univerInstanceService = useDependency(IUniverInstanceService), sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService), workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), commandService = useDependency(ICommandService), subUnitId$ = useMemo(() => workbook.activeSheet$.pipe(map((i) => i == null ? void 0 : i.getSheetId())), [workbook.activeSheet$]), subUnitId = useObservable(subUnitId$, (_a9 = workbook.getActiveSheet()) == null ? void 0 : _a9.getSheetId()), hoverShapeId = useRef(), panelService = useDependency(ThreadCommentPanelService), activeCommentId = useObservable(panelService.activeCommentId$), panelVisible = useObservable(panelService.panelVisible$, panelService.panelVisible), sortComments = useCallback((comments) => {
257
+ const worksheets = workbook.getSheets(), sheetIndex = {};
258
+ worksheets.forEach((sheet, i) => {
259
+ sheetIndex[sheet.getSheetId()] = i;
260
+ });
261
+ const sort = /* @__PURE__ */ __name((comments2) => comments2.map((comment) => {
262
+ var _a10;
263
+ const ref = singleReferenceToGrid(comment.ref), p = [(_a10 = sheetIndex[comment.subUnitId]) != null ? _a10 : 0, ref.row, ref.column];
264
+ return { ...comment, p };
265
+ }).sort((pre, aft) => pre.p[0] === aft.p[0] ? pre.p[1] === aft.p[1] ? pre.p[2] - aft.p[2] : pre.p[1] - aft.p[1] : pre.p[0] - aft.p[0]), "sort");
266
+ return [
267
+ ...sort(comments.filter((comment) => !comment.resolved)),
268
+ ...sort(comments.filter((comment) => comment.resolved))
269
+ ];
270
+ }, [workbook]), showShape = useCallback((comment) => {
271
+ var _a10;
272
+ if (comment.unitId === unitId && comment.subUnitId === subUnitId && !comment.resolved) {
273
+ const { row, column } = singleReferenceToGrid(comment.ref), worksheet = workbook.getSheetBySheetId(comment.subUnitId), mergeInfo = (_a10 = worksheet == null ? void 0 : worksheet.getMergedCell(row, column)) != null ? _a10 : {
274
+ startColumn: column,
275
+ endColumn: column,
276
+ startRow: row,
277
+ endRow: row
278
+ };
279
+ if (!Number.isNaN(row) && !Number.isNaN(column))
280
+ return markSelectionService.addShape({
281
+ range: mergeInfo,
282
+ style: {
283
+ hasAutoFill: !1,
284
+ fill: "rgb(255, 189, 55, 0.35)",
285
+ strokeWidth: 1,
286
+ stroke: "#FFBD37",
287
+ widgets: {}
288
+ },
289
+ primary: null
290
+ });
291
+ }
292
+ }, [markSelectionService, subUnitId, unitId]), getSubUnitName = /* @__PURE__ */ __name((id) => {
293
+ var _a10, _b;
294
+ return (_b = (_a10 = workbook.getSheetBySheetId(id)) == null ? void 0 : _a10.getName()) != null ? _b : "";
295
+ }, "getSubUnitName"), handleAdd = /* @__PURE__ */ __name(() => {
296
+ commandService.executeCommand(ShowAddSheetCommentModalOperation.id);
297
+ }, "handleAdd"), handleHover = /* @__PURE__ */ __name((comment) => {
298
+ activeCommentId && activeCommentId.unitId === comment.unitId && activeCommentId.subUnitId === comment.subUnitId && activeCommentId.commentId === comment.id || (hoverShapeId.current && (markSelectionService.removeShape(hoverShapeId.current), hoverShapeId.current = null), hoverShapeId.current = showShape(comment));
299
+ }, "handleHover"), handleLeave = /* @__PURE__ */ __name(() => {
300
+ hoverShapeId.current && (markSelectionService.removeShape(hoverShapeId.current), hoverShapeId.current = null);
301
+ }, "handleLeave"), handleResolve = /* @__PURE__ */ __name((id, resolved) => {
302
+ resolved && sheetsThreadCommentPopupService.hidePopup();
303
+ }, "handleResolve");
304
+ return useEffect(() => {
305
+ !panelVisible && hoverShapeId.current && markSelectionService.removeShape(hoverShapeId.current);
306
+ }, [markSelectionService, panelVisible]), /* @__PURE__ */ React.createElement(
307
+ ThreadCommentPanel,
308
+ {
309
+ unitId,
310
+ subUnitId$,
311
+ type: UniverInstanceType.UNIVER_SHEET,
312
+ onAdd: handleAdd,
313
+ getSubUnitName,
314
+ onResolve: handleResolve,
315
+ sortComments,
316
+ onItemEnter: handleHover,
317
+ onItemLeave: handleLeave,
318
+ onDeleteComment: /* @__PURE__ */ __name(() => (handleLeave(), !0), "onDeleteComment")
319
+ }
320
+ );
321
+ }, "SheetsThreadCommentPanel"), threadCommentMenuFactory = /* @__PURE__ */ __name((accessor) => ({
322
+ id: ShowAddSheetCommentModalOperation.id,
323
+ type: MenuItemType.BUTTON,
324
+ icon: COMMENT_SINGLE_ICON,
325
+ title: "sheetThreadComment.menu.addComment",
326
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
327
+ disabled$: getCurrentRangeDisable$(accessor, {
328
+ workbookTypes: [WorkbookCommentPermission],
329
+ worksheetTypes: [WorksheetViewPermission],
330
+ rangeTypes: [RangeProtectionPermissionViewPoint]
331
+ })
332
+ }), "threadCommentMenuFactory"), threadPanelMenuFactory = /* @__PURE__ */ __name((accessor) => ({
333
+ id: ToggleSheetCommentPanelOperation.id,
334
+ type: MenuItemType.BUTTON,
335
+ icon: COMMENT_SINGLE_ICON,
336
+ tooltip: "sheetThreadComment.menu.commentManagement",
337
+ disabled$: getCurrentRangeDisable$(accessor, {
338
+ workbookTypes: [WorkbookCommentPermission],
339
+ worksheetTypes: [WorksheetViewPermission],
340
+ rangeTypes: [RangeProtectionPermissionViewPoint]
341
+ }),
342
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET)
343
+ }), "threadPanelMenuFactory"), AddCommentShortcut = {
344
+ id: ShowAddSheetCommentModalOperation.id,
345
+ binding: KeyCode.M | MetaKeys.CTRL_COMMAND | MetaKeys.ALT,
346
+ preconditions: whenSheetEditorFocused
347
+ }, menuSchema = {
348
+ [RibbonStartGroup.OTHERS]: {
349
+ [ToggleSheetCommentPanelOperation.id]: {
350
+ order: 1,
351
+ menuItemFactory: threadPanelMenuFactory
352
+ }
353
+ },
354
+ [ContextMenuPosition.MAIN_AREA]: {
355
+ [ContextMenuGroup.OTHERS]: {
356
+ [ShowAddSheetCommentModalOperation.id]: {
357
+ order: 0,
358
+ menuItemFactory: threadCommentMenuFactory
359
+ }
360
+ }
361
+ }
362
+ };
363
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
364
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
365
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
366
+ return kind && result && __defProp$5(target, key, result), result;
367
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a3;
368
+ let SheetsThreadCommentController = (_a3 = class extends Disposable {
369
+ constructor(_menuManagerService, _componentManager, _shortcutService) {
370
+ super(), this._menuManagerService = _menuManagerService, this._componentManager = _componentManager, this._shortcutService = _shortcutService, this._initMenu(), this._initShortcut(), this._initComponent();
371
+ }
372
+ _initShortcut() {
373
+ this._shortcutService.registerShortcut(AddCommentShortcut);
374
+ }
375
+ _initMenu() {
376
+ this._menuManagerService.mergeMenu(menuSchema);
377
+ }
378
+ _initComponent() {
379
+ [
380
+ [SHEETS_THREAD_COMMENT_MODAL, SheetsThreadCommentCell],
381
+ [THREAD_COMMENT_PANEL, SheetsThreadCommentPanel],
382
+ [COMMENT_SINGLE_ICON, CommentSingle]
383
+ ].forEach(([key, comp]) => {
384
+ this._componentManager.register(key, comp);
385
+ });
386
+ }
387
+ }, __name(_a3, "SheetsThreadCommentController"), _a3);
388
+ SheetsThreadCommentController = __decorateClass$5([
389
+ __decorateParam$5(0, IMenuManagerService),
390
+ __decorateParam$5(1, Inject(ComponentManager)),
391
+ __decorateParam$5(2, IShortcutService)
392
+ ], SheetsThreadCommentController);
393
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
394
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
395
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
396
+ return kind && result && __defProp$4(target, key, result), result;
397
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4");
398
+ const transformRef = /* @__PURE__ */ __name((ref, source, target) => {
399
+ const refObj = singleReferenceToGrid(ref), offsetRow = target.row - source.row, offsetCol = target.column - source.column, targetRange = {
400
+ startColumn: refObj.column + offsetCol,
401
+ startRow: refObj.row + offsetRow,
402
+ endColumn: refObj.column + offsetCol,
403
+ endRow: refObj.row + offsetRow
404
+ };
405
+ return serializeRange(targetRange);
406
+ }, "transformRef");
407
+ var _a4;
408
+ let SheetsThreadCommentCopyPasteController = (_a4 = class extends Disposable {
409
+ constructor(_sheetClipboardService, _sheetsThreadCommentModel, _threadCommentDataSourceService) {
410
+ super();
411
+ __publicField(this, "_copyInfo");
412
+ this._sheetClipboardService = _sheetClipboardService, this._sheetsThreadCommentModel = _sheetsThreadCommentModel, this._threadCommentDataSourceService = _threadCommentDataSourceService, this._initClipboardHook();
413
+ }
414
+ // eslint-disable-next-line max-lines-per-function
415
+ _initClipboardHook() {
416
+ this.disposeWithMe(
417
+ this._sheetClipboardService.addClipboardHook({
418
+ id: SHEETS_THREAD_COMMENT,
419
+ onBeforeCopy: /* @__PURE__ */ __name((unitId, subUnitId, range) => {
420
+ this._copyInfo = {
421
+ unitId,
422
+ subUnitId,
423
+ range
424
+ };
425
+ }, "onBeforeCopy"),
426
+ // eslint-disable-next-line max-lines-per-function
427
+ onPasteCells: /* @__PURE__ */ __name((_pasteFrom, pasteTo, _data, payload) => {
428
+ const { unitId: targetUnitId, subUnitId: targetSubUnitId, range } = pasteTo, targetPos = {
429
+ row: range.rows[0],
430
+ column: range.cols[0]
431
+ };
432
+ if (payload.copyType === COPY_TYPE.CUT && this._copyInfo) {
433
+ const { range: range2, unitId: sourceUnitId, subUnitId: sourceSubUnitId } = this._copyInfo, sourcePos = {
434
+ row: range2.startRow,
435
+ column: range2.startColumn
436
+ };
437
+ if (!(targetUnitId === sourceUnitId && targetSubUnitId === sourceSubUnitId)) {
438
+ const roots = [];
439
+ Range.foreach(range2, (row, col) => {
440
+ const comments = this._sheetsThreadCommentModel.getAllByLocation(sourceUnitId, sourceSubUnitId, row, col);
441
+ this._threadCommentDataSourceService.syncUpdateMutationToColla ? comments.forEach((comment) => {
442
+ roots.push(comment);
443
+ }) : comments.forEach(({ children, ...comment }) => {
444
+ comment.parentId || roots.push(comment);
445
+ });
446
+ });
447
+ const sourceRedos = [], sourceUndos = [], targetRedos = [], targetUndos = [], handleCommentItem = /* @__PURE__ */ __name((item) => {
448
+ sourceRedos.unshift({
449
+ id: DeleteCommentMutation.id,
450
+ params: {
451
+ unitId: sourceUnitId,
452
+ subUnitId: sourceSubUnitId,
453
+ commentId: item.id
454
+ }
455
+ }), targetRedos.push({
456
+ id: AddCommentMutation.id,
457
+ params: {
458
+ unitId: targetUnitId,
459
+ subUnitId: targetSubUnitId,
460
+ comment: {
461
+ ...item,
462
+ ref: transformRef(item.ref, sourcePos, targetPos),
463
+ unitId: targetUnitId,
464
+ subUnitId: targetSubUnitId
465
+ },
466
+ sync: !0
467
+ }
468
+ }), sourceUndos.push({
469
+ id: AddCommentMutation.id,
470
+ params: {
471
+ unitId: sourceUnitId,
472
+ subUnitId: sourceSubUnitId,
473
+ comment: item,
474
+ sync: !0
475
+ }
476
+ }), targetUndos.unshift({
477
+ id: DeleteCommentMutation.id,
478
+ params: {
479
+ unitId: targetUnitId,
480
+ subUnitId: targetSubUnitId,
481
+ commentId: item.id
482
+ }
483
+ });
484
+ }, "handleCommentItem");
485
+ return roots.forEach((root) => {
486
+ handleCommentItem(root);
487
+ }), {
488
+ redos: [...sourceRedos, ...targetRedos],
489
+ undos: [...targetUndos, ...sourceUndos]
490
+ };
491
+ }
492
+ }
493
+ return {
494
+ redos: [],
495
+ undos: []
496
+ };
497
+ }, "onPasteCells")
498
+ })
499
+ );
500
+ }
501
+ }, __name(_a4, "SheetsThreadCommentCopyPasteController"), _a4);
502
+ SheetsThreadCommentCopyPasteController = __decorateClass$4([
503
+ __decorateParam$4(0, Inject(ISheetClipboardService)),
504
+ __decorateParam$4(1, Inject(SheetsThreadCommentModel)),
505
+ __decorateParam$4(2, IThreadCommentDataSourceService)
506
+ ], SheetsThreadCommentCopyPasteController);
507
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
508
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
509
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
510
+ return kind && result && __defProp$3(target, key, result), result;
511
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a5;
512
+ let SheetsThreadCommentHoverController = (_a5 = class extends Disposable {
513
+ constructor(_hoverManagerService, _sheetsThreadCommentPopupService, _sheetsThreadCommentModel, _sheetPermissionInterceptorBaseController) {
514
+ super(), this._hoverManagerService = _hoverManagerService, this._sheetsThreadCommentPopupService = _sheetsThreadCommentPopupService, this._sheetsThreadCommentModel = _sheetsThreadCommentModel, this._sheetPermissionInterceptorBaseController = _sheetPermissionInterceptorBaseController, this._initHoverEvent();
515
+ }
516
+ _initHoverEvent() {
517
+ this.disposeWithMe(
518
+ this._hoverManagerService.currentCell$.pipe(debounceTime(100)).subscribe((cell) => {
519
+ const currentPopup = this._sheetsThreadCommentPopupService.activePopup;
520
+ if (cell && (currentPopup && currentPopup.temp || !currentPopup)) {
521
+ const { location } = cell, { unitId, subUnitId, row, col } = location, commentId = this._sheetsThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
522
+ if (commentId) {
523
+ if (!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
524
+ workbookTypes: [WorkbookCommentPermission],
525
+ worksheetTypes: [WorksheetViewPermission],
526
+ rangeTypes: [RangeProtectionPermissionViewPoint]
527
+ }, [{ startRow: row, startColumn: col, endRow: row, endColumn: col }]))
528
+ return;
529
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
530
+ comment && !comment.resolved && this._sheetsThreadCommentPopupService.showPopup({
531
+ unitId,
532
+ subUnitId,
533
+ row,
534
+ col,
535
+ commentId,
536
+ temp: !0
537
+ });
538
+ } else
539
+ currentPopup && this._sheetsThreadCommentPopupService.hidePopup();
540
+ }
541
+ })
542
+ );
543
+ }
544
+ }, __name(_a5, "SheetsThreadCommentHoverController"), _a5);
545
+ SheetsThreadCommentHoverController = __decorateClass$3([
546
+ __decorateParam$3(0, Inject(HoverManagerService)),
547
+ __decorateParam$3(1, Inject(SheetsThreadCommentPopupService)),
548
+ __decorateParam$3(2, Inject(SheetsThreadCommentModel)),
549
+ __decorateParam$3(3, Inject(SheetPermissionInterceptorBaseController))
550
+ ], SheetsThreadCommentHoverController);
551
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
552
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
553
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
554
+ return kind && result && __defProp$2(target, key, result), result;
555
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a6;
556
+ let SheetsThreadCommentPopupController = (_a6 = class extends Disposable {
557
+ constructor(_commandService, _sheetsThreadCommentPopupService, _sheetsThreadCommentModel, _threadCommentPanelService, _univerInstanceService, _sheetPermissionInterceptorBaseController, _markSelectionService, _sheetSelectionService, _editorBridgeService, _renderManagerService) {
558
+ super();
559
+ __publicField(this, "_isSwitchToCommenting", !1);
560
+ __publicField(this, "_selectionShapeInfo", null);
561
+ this._commandService = _commandService, this._sheetsThreadCommentPopupService = _sheetsThreadCommentPopupService, this._sheetsThreadCommentModel = _sheetsThreadCommentModel, this._threadCommentPanelService = _threadCommentPanelService, this._univerInstanceService = _univerInstanceService, this._sheetPermissionInterceptorBaseController = _sheetPermissionInterceptorBaseController, this._markSelectionService = _markSelectionService, this._sheetSelectionService = _sheetSelectionService, this._editorBridgeService = _editorBridgeService, this._renderManagerService = _renderManagerService, this._initCommandListener(), this._initPanelListener(), this._initMarkSelection(), this._initSelectionUpdateListener(), this._initEditorBridge();
562
+ }
563
+ _handleSelectionChange(selections, unitId, subUnitId) {
564
+ var _a9, _b, _c;
565
+ const range = (_a9 = selections[0]) == null ? void 0 : _a9.range, render2 = this._renderManagerService.getRenderById(unitId), skeleton = (_b = render2 == null ? void 0 : render2.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId)) == null ? void 0 : _b.skeleton;
566
+ if (!skeleton || !range)
567
+ return;
568
+ const actualCell = skeleton.getCellByIndex(range.startRow, range.startColumn);
569
+ if ((((_c = range.rangeType) != null ? _c : RANGE_TYPE.NORMAL) !== RANGE_TYPE.NORMAL || range.endColumn - range.startColumn > 0 || range.endRow - range.startRow > 0) && !((actualCell.isMerged || actualCell.isMergedMainCell) && Rectangle.equals(actualCell.mergeInfo, range))) {
570
+ this._threadCommentPanelService.activeCommentId && this._commandService.executeCommand(SetActiveCommentOperation.id);
571
+ return;
572
+ }
573
+ const row = actualCell.actualRow, col = actualCell.actualColumn;
574
+ if (!this._sheetsThreadCommentModel.showCommentMarker(unitId, subUnitId, row, col)) {
575
+ this._threadCommentPanelService.activeCommentId && this._commandService.executeCommand(SetActiveCommentOperation.id);
576
+ return;
577
+ }
578
+ const commentId = this._sheetsThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
579
+ commentId && this._commandService.executeCommand(SetActiveCommentOperation.id, {
580
+ unitId,
581
+ subUnitId,
582
+ commentId
583
+ });
584
+ }
585
+ _initSelectionUpdateListener() {
586
+ this.disposeWithMe(
587
+ this._sheetSelectionService.selectionMoveEnd$.subscribe((selections) => {
588
+ if (this._isSwitchToCommenting)
589
+ return;
590
+ const current = this._sheetSelectionService.currentSelectionParam;
591
+ current && this._handleSelectionChange(selections, current.unitId, current.sheetId);
592
+ })
593
+ );
594
+ }
595
+ _initEditorBridge() {
596
+ this.disposeWithMe(
597
+ this._editorBridgeService.visible$.subscribe((visible) => {
598
+ visible.visible && this._sheetsThreadCommentPopupService.hidePopup();
599
+ })
600
+ );
601
+ }
602
+ _initCommandListener() {
603
+ this._commandService.onCommandExecuted((commandInfo) => {
604
+ if (commandInfo.id === DeleteCommentMutation.id) {
605
+ const params = commandInfo.params, active = this._sheetsThreadCommentPopupService.activePopup;
606
+ if (!active)
607
+ return;
608
+ const { unitId, subUnitId, commentId } = active;
609
+ params.unitId === unitId && params.subUnitId === subUnitId && params.commentId === commentId && this._sheetsThreadCommentPopupService.hidePopup();
610
+ }
611
+ });
612
+ }
613
+ _initPanelListener() {
614
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async (commentInfo) => {
615
+ var _a9;
616
+ if (commentInfo) {
617
+ const { unitId, subUnitId, commentId, trigger } = commentInfo, comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
618
+ if (!comment || comment.resolved)
619
+ return;
620
+ const currentUnit = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
621
+ if (!currentUnit || currentUnit.getUnitId() !== unitId)
622
+ return;
623
+ this._isSwitchToCommenting = !0, ((_a9 = currentUnit.getActiveSheet()) == null ? void 0 : _a9.getSheetId()) !== subUnitId && await this._commandService.executeCommand(SetWorksheetActiveOperation.id, {
624
+ unitId,
625
+ subUnitId
626
+ }), this._isSwitchToCommenting = !1;
627
+ const location = singleReferenceToGrid(comment.ref), { row, column: col } = location;
628
+ if (!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
629
+ workbookTypes: [WorkbookCommentPermission],
630
+ worksheetTypes: [WorksheetViewPermission],
631
+ rangeTypes: [RangeProtectionPermissionViewPoint]
632
+ }, [{ startRow: row, startColumn: col, endRow: row, endColumn: col }]))
633
+ return;
634
+ const GAP = 1;
635
+ if (await this._commandService.executeCommand(ScrollToRangeOperation.id, {
636
+ range: {
637
+ startRow: Math.max(location.row - GAP, 0),
638
+ endRow: location.row + GAP,
639
+ startColumn: Math.max(location.column - GAP, 0),
640
+ endColumn: location.column + GAP
641
+ }
642
+ }), this._editorBridgeService.isVisible().visible)
643
+ return;
644
+ this._sheetsThreadCommentPopupService.showPopup({
645
+ unitId,
646
+ subUnitId,
647
+ row: location.row,
648
+ col: location.column,
649
+ commentId: comment.id,
650
+ trigger
651
+ });
652
+ } else
653
+ this._sheetsThreadCommentPopupService.hidePopup();
654
+ }));
655
+ }
656
+ _initMarkSelection() {
657
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(debounceTime(100)).subscribe((activeComment) => {
658
+ var _a9, _b;
659
+ if (!activeComment) {
660
+ this._selectionShapeInfo && (this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId), this._selectionShapeInfo = null);
661
+ return;
662
+ }
663
+ const { unitId, subUnitId, commentId } = activeComment;
664
+ this._selectionShapeInfo && (this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId), this._selectionShapeInfo = null);
665
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
666
+ if (!comment)
667
+ return;
668
+ const location = singleReferenceToGrid(comment.ref), { row, column } = location;
669
+ if (Number.isNaN(row) || Number.isNaN(column))
670
+ return null;
671
+ const worksheet = (_a9 = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a9.getSheetBySheetId(subUnitId), mergeInfo = (_b = worksheet == null ? void 0 : worksheet.getMergedCell(row, column)) != null ? _b : {
672
+ startColumn: column,
673
+ endColumn: column,
674
+ startRow: row,
675
+ endRow: row
676
+ }, shapeId = this._markSelectionService.addShape(
677
+ {
678
+ range: mergeInfo,
679
+ style: {
680
+ hasAutoFill: !1,
681
+ fill: "rgb(255, 189, 55, 0.35)",
682
+ strokeWidth: 1,
683
+ stroke: "#FFBD37",
684
+ widgets: {}
685
+ },
686
+ primary: null
687
+ },
688
+ [],
689
+ -1
690
+ );
691
+ shapeId && (this._selectionShapeInfo = {
692
+ ...activeComment,
693
+ shapeId
694
+ });
695
+ }));
696
+ }
697
+ }, __name(_a6, "SheetsThreadCommentPopupController"), _a6);
698
+ SheetsThreadCommentPopupController = __decorateClass$2([
699
+ __decorateParam$2(0, ICommandService),
700
+ __decorateParam$2(1, Inject(SheetsThreadCommentPopupService)),
701
+ __decorateParam$2(2, Inject(SheetsThreadCommentModel)),
702
+ __decorateParam$2(3, Inject(ThreadCommentPanelService)),
703
+ __decorateParam$2(4, IUniverInstanceService),
704
+ __decorateParam$2(5, Inject(SheetPermissionInterceptorBaseController)),
705
+ __decorateParam$2(6, IMarkSelectionService),
706
+ __decorateParam$2(7, Inject(SheetsSelectionsService)),
707
+ __decorateParam$2(8, IEditorBridgeService),
708
+ __decorateParam$2(9, IRenderManagerService)
709
+ ], SheetsThreadCommentPopupController);
710
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
711
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
712
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
713
+ return kind && result && __defProp$1(target, key, result), result;
714
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a7;
715
+ let ThreadCommentRemoveSheetsController = (_a7 = class extends Disposable {
716
+ constructor(_sheetInterceptorService, _univerInstanceService, _threadCommentModel, _threadCommentDataSourceService) {
717
+ super(), this._sheetInterceptorService = _sheetInterceptorService, this._univerInstanceService = _univerInstanceService, this._threadCommentModel = _threadCommentModel, this._threadCommentDataSourceService = _threadCommentDataSourceService, this._initSheetChange();
718
+ }
719
+ _initSheetChange() {
720
+ this.disposeWithMe(
721
+ this._sheetInterceptorService.interceptCommand({
722
+ getMutations: /* @__PURE__ */ __name((commandInfo) => {
723
+ var _a9;
724
+ if (commandInfo.id === RemoveSheetCommand.id) {
725
+ const params = commandInfo.params, workbook = params.unitId ? this._univerInstanceService.getUnit(params.unitId) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
726
+ if (!workbook)
727
+ return { redos: [], undos: [] };
728
+ const unitId = workbook.getUnitId(), subUnitId = params.subUnitId || ((_a9 = workbook.getActiveSheet()) == null ? void 0 : _a9.getSheetId());
729
+ if (!subUnitId)
730
+ return { redos: [], undos: [] };
731
+ const { commentMap } = this._threadCommentModel.ensureMap(unitId, subUnitId), comments = Array.from(Object.values(commentMap)).filter((comment) => !comment.parentId), ids = comments.map((comment) => comment.id), shouldSync = this._threadCommentDataSourceService.syncUpdateMutationToColla, redos = ids.map((id) => ({
732
+ id: DeleteCommentMutation.id,
733
+ params: {
734
+ unitId,
735
+ subUnitId,
736
+ commentId: id
737
+ }
738
+ })), undos = comments.map(({ children, ...comment }) => ({
739
+ id: AddCommentMutation.id,
740
+ params: {
741
+ unitId,
742
+ subUnitId,
743
+ comment: {
744
+ ...comment,
745
+ children: shouldSync ? children : void 0
746
+ },
747
+ sync: !shouldSync
748
+ }
749
+ }));
750
+ return { redos, undos };
751
+ }
752
+ return { redos: [], undos: [] };
753
+ }, "getMutations")
754
+ })
755
+ );
756
+ }
757
+ }, __name(_a7, "ThreadCommentRemoveSheetsController"), _a7);
758
+ ThreadCommentRemoveSheetsController = __decorateClass$1([
759
+ __decorateParam$1(0, Inject(SheetInterceptorService)),
760
+ __decorateParam$1(1, IUniverInstanceService),
761
+ __decorateParam$1(2, Inject(ThreadCommentModel)),
762
+ __decorateParam$1(3, IThreadCommentDataSourceService)
763
+ ], ThreadCommentRemoveSheetsController);
764
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
765
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
766
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
767
+ return kind && result && __defProp2(target, key, result), result;
768
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a8;
769
+ let UniverSheetsThreadCommentUIPlugin = (_a8 = class extends Plugin {
770
+ constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
771
+ super(), this._config = _config, this._injector = _injector, this._commandService = _commandService, this._configService = _configService;
772
+ const { menu, ...rest } = this._config;
773
+ menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
774
+ }
775
+ onStarting() {
776
+ [
777
+ [SheetsThreadCommentController],
778
+ [SheetsThreadCommentRenderController],
779
+ [SheetsThreadCommentCopyPasteController],
780
+ [SheetsThreadCommentHoverController],
781
+ [ThreadCommentRemoveSheetsController],
782
+ [SheetsThreadCommentPopupController],
783
+ [SheetsThreadCommentPopupService]
784
+ ].forEach((dep) => {
785
+ this._injector.add(dep);
786
+ }), [ShowAddSheetCommentModalOperation].forEach((command) => {
787
+ this._commandService.registerCommand(command);
788
+ }), this._injector.get(SheetsThreadCommentController);
789
+ }
790
+ onReady() {
791
+ this._injector.get(SheetsThreadCommentRenderController), this._injector.get(ThreadCommentRemoveSheetsController);
792
+ }
793
+ onRendered() {
794
+ this._injector.get(SheetsThreadCommentCopyPasteController), this._injector.get(SheetsThreadCommentHoverController), this._injector.get(SheetsThreadCommentPopupController);
795
+ }
796
+ }, __name(_a8, "UniverSheetsThreadCommentUIPlugin"), _a8);
797
+ __publicField2(UniverSheetsThreadCommentUIPlugin, "pluginName", SHEETS_THREAD_COMMENT);
798
+ __publicField2(UniverSheetsThreadCommentUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
799
+ UniverSheetsThreadCommentUIPlugin = __decorateClass([
800
+ DependentOn(UniverThreadCommentUIPlugin, UniverSheetsThreadCommentPlugin),
801
+ __decorateParam(1, Inject(Injector)),
802
+ __decorateParam(2, Inject(ICommandService)),
803
+ __decorateParam(3, IConfigService)
804
+ ], UniverSheetsThreadCommentUIPlugin);
805
+ export {
806
+ AddCommentCommand,
807
+ DeleteCommentCommand,
808
+ DeleteCommentTreeCommand,
809
+ IThreadCommentDataSourceService2 as IThreadCommentDataSourceService,
810
+ IThreadCommentMentionDataService,
811
+ ResolveCommentCommand,
812
+ SHEETS_THREAD_COMMENT,
813
+ SheetsThreadCommentPopupService,
814
+ ShowAddSheetCommentModalOperation,
815
+ UniverSheetsThreadCommentUIPlugin,
816
+ UniverThreadCommentUIPlugin2 as UniverThreadCommentUIPlugin,
817
+ UpdateCommentCommand
818
+ };