@univerjs/sheets-thread-comment-ui 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +45 -57
- package/lib/es/index.js +47 -59
- package/lib/index.js +47 -59
- package/lib/types/controllers/{sheets-thread-comment-permission.controller.d.ts → sheets-thread-comment-operation-permission.controller.d.ts} +14 -7
- package/lib/types/mobile-plugin.d.ts +1 -1
- package/lib/types/plugin.d.ts +1 -1
- package/lib/umd/index.js +3 -3
- package/package.json +16 -16
package/lib/cjs/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const SHEETS_THREAD_COMMENT_PANEL = "univer.sheet.thread-comment-panel";
|
|
|
35
35
|
const SHOW_ADD_SHEET_COMMENT_OPERATION_ID = "sheet.operation.show-comment-modal";
|
|
36
36
|
const PLUGIN_NAME = "SHEET_THREAD_COMMENT_UI_PLUGIN";
|
|
37
37
|
|
|
38
|
-
// \0@oxc-project+runtime@0.
|
|
38
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
39
39
|
function _typeof(o) {
|
|
40
40
|
"@babel/helpers - typeof";
|
|
41
41
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -45,7 +45,7 @@ function _typeof(o) {
|
|
|
45
45
|
}, _typeof(o);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// \0@oxc-project+runtime@0.
|
|
48
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
49
49
|
function toPrimitive(t, e) {
|
|
50
50
|
if ("object" != _typeof(t) || !t) return t;
|
|
51
51
|
var r;
|
|
@@ -57,13 +57,13 @@ function toPrimitive(t, e) {
|
|
|
57
57
|
return ("string" === e ? String : Number)(t);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
// \0@oxc-project+runtime@0.
|
|
60
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
61
61
|
function toPropertyKey(t) {
|
|
62
62
|
var i = toPrimitive(t, "string");
|
|
63
63
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
// \0@oxc-project+runtime@0.
|
|
66
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
67
67
|
function _defineProperty(e, r, t) {
|
|
68
68
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
69
69
|
value: t,
|
|
@@ -73,14 +73,14 @@ function _defineProperty(e, r, t) {
|
|
|
73
73
|
}) : e[r] = t, e;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
// \0@oxc-project+runtime@0.
|
|
76
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
77
77
|
function __decorateParam(paramIndex, decorator) {
|
|
78
78
|
return function(target, key) {
|
|
79
79
|
decorator(target, key, paramIndex);
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
// \0@oxc-project+runtime@0.
|
|
83
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
84
84
|
function __decorate(decorators, target, key, desc) {
|
|
85
85
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
86
86
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -302,9 +302,8 @@ const threadPanelMenuFactory = (accessor) => {
|
|
|
302
302
|
title: "sheets-thread-comment-ui.menu.openComments",
|
|
303
303
|
tooltip: "sheets-thread-comment-ui.menu.openComments",
|
|
304
304
|
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
305
|
-
workbookTypes: [_univerjs_sheets.
|
|
306
|
-
worksheetTypes: [_univerjs_sheets.WorksheetViewPermission]
|
|
307
|
-
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionViewPoint]
|
|
305
|
+
workbookTypes: [_univerjs_sheets.WorkbookViewPermission],
|
|
306
|
+
worksheetTypes: [_univerjs_sheets.WorksheetViewPermission]
|
|
308
307
|
}),
|
|
309
308
|
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
|
|
310
309
|
};
|
|
@@ -353,7 +352,7 @@ const menuSchema = {
|
|
|
353
352
|
|
|
354
353
|
// package.json
|
|
355
354
|
var name = "@univerjs/sheets-thread-comment-ui";
|
|
356
|
-
var version = "1.
|
|
355
|
+
var version = "1.6.0";
|
|
357
356
|
|
|
358
357
|
// src/services/mobile/mobile-sheet-comment-draft.service.ts
|
|
359
358
|
var MobileSheetCommentDraftService = class extends _univerjs_core.Disposable {
|
|
@@ -441,6 +440,7 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = _univerjs_thre
|
|
|
441
440
|
} : null;
|
|
442
441
|
const subUnitId$ = (0, react.useMemo)(() => workbook.activeSheet$.pipe((0, rxjs.map)((i) => i === null || i === void 0 ? void 0 : i.getSheetId())), [workbook.activeSheet$]);
|
|
443
442
|
const subUnitId = (0, _univerjs_ui.useObservable)(subUnitId$, (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
|
|
443
|
+
const authzService = (0, _univerjs_ui.useDependency)(_univerjs_thread_comment.IThreadCommentAuthzService);
|
|
444
444
|
const hoverShapeId = (0, react.useRef)(null);
|
|
445
445
|
const panelService = (0, _univerjs_ui.useDependency)(_univerjs_thread_comment_ui.ThreadCommentPanelService);
|
|
446
446
|
const activeCommentId = (0, _univerjs_ui.useObservable)(panelService.activeCommentId$);
|
|
@@ -517,6 +517,7 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = _univerjs_thre
|
|
|
517
517
|
const handleAdd = () => {
|
|
518
518
|
commandService.executeCommand(ShowAddSheetCommentModalOperation.id);
|
|
519
519
|
};
|
|
520
|
+
const filterComment = (0, react.useCallback)((comment) => authzService.canRead(comment), [authzService]);
|
|
520
521
|
const handleHover = (comment) => {
|
|
521
522
|
if (hoverShapeId.current) {
|
|
522
523
|
markSelectionService.removeShape(hoverShapeId.current);
|
|
@@ -545,6 +546,12 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = _univerjs_thre
|
|
|
545
546
|
subUnitId$,
|
|
546
547
|
type: _univerjs_core.UniverInstanceType.UNIVER_SHEET,
|
|
547
548
|
onAdd: handleAdd,
|
|
549
|
+
disableAdd: !authzService.canWrite("add", {
|
|
550
|
+
unitId,
|
|
551
|
+
subUnitId: subUnitId ?? "",
|
|
552
|
+
ref: ""
|
|
553
|
+
}),
|
|
554
|
+
filterComment,
|
|
548
555
|
getSubUnitName,
|
|
549
556
|
onResolve: handleResolve,
|
|
550
557
|
sortComments,
|
|
@@ -886,65 +893,46 @@ SheetsThreadCommentCopyPasteController = __decorate([
|
|
|
886
893
|
__decorateParam(2, _univerjs_thread_comment.IThreadCommentDataSourceService)
|
|
887
894
|
], SheetsThreadCommentCopyPasteController);
|
|
888
895
|
|
|
889
|
-
// src/controllers/sheets-thread-comment-permission.controller.ts
|
|
890
|
-
let
|
|
891
|
-
constructor(_localeService, _commandService, _sheetPermissionCheckController,
|
|
896
|
+
// src/controllers/sheets-thread-comment-operation-permission.controller.ts
|
|
897
|
+
let SheetsThreadCommentOperationPermissionController = class SheetsThreadCommentOperationPermissionController extends _univerjs_core.Disposable {
|
|
898
|
+
constructor(_localeService, _commandService, _sheetPermissionCheckController, _authzService, _univerInstanceService) {
|
|
892
899
|
super();
|
|
893
900
|
this._localeService = _localeService;
|
|
894
901
|
this._commandService = _commandService;
|
|
895
902
|
this._sheetPermissionCheckController = _sheetPermissionCheckController;
|
|
896
|
-
this.
|
|
903
|
+
this._authzService = _authzService;
|
|
904
|
+
this._univerInstanceService = _univerInstanceService;
|
|
897
905
|
this._commandExecutedListener();
|
|
898
906
|
}
|
|
899
907
|
_commandExecutedListener() {
|
|
900
908
|
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
901
909
|
const { id } = command;
|
|
902
|
-
if (id ===
|
|
903
|
-
if (!this.
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
})) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
907
|
-
} else if (id === _univerjs_thread_comment.AddCommentCommand.id) {
|
|
908
|
-
const { unitId, subUnitId, comment } = command.params;
|
|
909
|
-
if (!this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
910
|
-
} else if (id === _univerjs_thread_comment.UpdateCommentCommand.id) {
|
|
911
|
-
const { unitId, subUnitId, payload } = command.params;
|
|
912
|
-
const { commentId } = payload;
|
|
913
|
-
const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
914
|
-
if (comment && !this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
915
|
-
} else if (id === _univerjs_thread_comment.ResolveCommentCommand.id || id === _univerjs_thread_comment.DeleteCommentCommand.id || id === _univerjs_thread_comment.DeleteCommentTreeCommand.id) {
|
|
916
|
-
const { unitId, subUnitId, commentId } = command.params;
|
|
917
|
-
const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
918
|
-
if (comment && !this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
910
|
+
if (id === ShowAddSheetCommentModalOperation.id || id === AddSheetDrawingCommentOperation.id) {
|
|
911
|
+
if (!this._authzService.canWrite("add", this._getTarget())) this._block();
|
|
912
|
+
} else if (id === ToggleSheetCommentPanelOperation.id) {
|
|
913
|
+
if (!this._authzService.canRead(this._getTarget())) this._block();
|
|
919
914
|
}
|
|
920
915
|
}));
|
|
921
916
|
}
|
|
922
|
-
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
|
|
917
|
+
_getTarget() {
|
|
918
|
+
const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
919
|
+
return {
|
|
920
|
+
unitId: (workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId()) ?? "",
|
|
921
|
+
subUnitId: (workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet().getSheetId()) ?? "",
|
|
922
|
+
ref: ""
|
|
926
923
|
};
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
if (!Number.isFinite(row) || !Number.isFinite(column)) return false;
|
|
931
|
-
return this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
932
|
-
...permissionTypes,
|
|
933
|
-
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionViewPoint]
|
|
934
|
-
}, [{
|
|
935
|
-
startRow: row,
|
|
936
|
-
startColumn: column,
|
|
937
|
-
endRow: row,
|
|
938
|
-
endColumn: column
|
|
939
|
-
}], unitId, subUnitId);
|
|
924
|
+
}
|
|
925
|
+
_block() {
|
|
926
|
+
this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
940
927
|
}
|
|
941
928
|
};
|
|
942
|
-
|
|
929
|
+
SheetsThreadCommentOperationPermissionController = __decorate([
|
|
943
930
|
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
944
931
|
__decorateParam(1, _univerjs_core.ICommandService),
|
|
945
932
|
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetPermissionCheckController)),
|
|
946
|
-
__decorateParam(3, (0, _univerjs_core.Inject)(
|
|
947
|
-
|
|
933
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_thread_comment.IThreadCommentAuthzService)),
|
|
934
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService))
|
|
935
|
+
], SheetsThreadCommentOperationPermissionController);
|
|
948
936
|
|
|
949
937
|
// src/mobile-plugin.ts
|
|
950
938
|
let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMobileUIPlugin extends _univerjs_core.Plugin {
|
|
@@ -965,7 +953,7 @@ let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMob
|
|
|
965
953
|
[SheetsThreadCommentRenderController],
|
|
966
954
|
[SheetsThreadCommentCopyPasteController],
|
|
967
955
|
[SheetsThreadCommentPopupService],
|
|
968
|
-
[
|
|
956
|
+
[SheetsThreadCommentOperationPermissionController],
|
|
969
957
|
[MobileSheetCommentDraftService]
|
|
970
958
|
].forEach((dependency) => this._injector.add(dependency));
|
|
971
959
|
this._injector.get(MobileComponentsController);
|
|
@@ -982,7 +970,7 @@ let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMob
|
|
|
982
970
|
}
|
|
983
971
|
onRendered() {
|
|
984
972
|
this._injector.get(SheetsThreadCommentCopyPasteController);
|
|
985
|
-
this._injector.get(
|
|
973
|
+
this._injector.get(SheetsThreadCommentOperationPermissionController);
|
|
986
974
|
}
|
|
987
975
|
};
|
|
988
976
|
_defineProperty(UniverSheetsThreadCommentMobileUIPlugin, "pluginName", PLUGIN_NAME);
|
|
@@ -1240,7 +1228,7 @@ let SheetsThreadCommentHoverController = class SheetsThreadCommentHoverControlle
|
|
|
1240
1228
|
const commentId = this._sheetsThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
|
|
1241
1229
|
if (commentId) {
|
|
1242
1230
|
if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
1243
|
-
workbookTypes: [_univerjs_sheets.
|
|
1231
|
+
workbookTypes: [_univerjs_sheets.WorkbookViewPermission],
|
|
1244
1232
|
worksheetTypes: [_univerjs_sheets.WorksheetViewPermission],
|
|
1245
1233
|
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionViewPoint]
|
|
1246
1234
|
}, [{
|
|
@@ -1365,7 +1353,7 @@ let SheetsThreadCommentPopupController = class SheetsThreadCommentPopupControlle
|
|
|
1365
1353
|
const location = (0, _univerjs_engine_formula.singleReferenceToGrid)(comment.ref);
|
|
1366
1354
|
const { row, column: col } = location;
|
|
1367
1355
|
if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
1368
|
-
workbookTypes: [_univerjs_sheets.
|
|
1356
|
+
workbookTypes: [_univerjs_sheets.WorkbookViewPermission],
|
|
1369
1357
|
worksheetTypes: [_univerjs_sheets.WorksheetViewPermission],
|
|
1370
1358
|
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionViewPoint]
|
|
1371
1359
|
}, [{
|
|
@@ -1508,7 +1496,7 @@ let UniverSheetsThreadCommentUIPlugin = class UniverSheetsThreadCommentUIPlugin
|
|
|
1508
1496
|
[SheetsThreadCommentHoverController],
|
|
1509
1497
|
[SheetsThreadCommentPopupController],
|
|
1510
1498
|
[SheetsThreadCommentPopupService],
|
|
1511
|
-
[
|
|
1499
|
+
[SheetsThreadCommentOperationPermissionController]
|
|
1512
1500
|
].forEach((dep) => {
|
|
1513
1501
|
this._injector.add(dep);
|
|
1514
1502
|
});
|
|
@@ -1530,7 +1518,7 @@ let UniverSheetsThreadCommentUIPlugin = class UniverSheetsThreadCommentUIPlugin
|
|
|
1530
1518
|
this._injector.get(SheetsThreadCommentCopyPasteController);
|
|
1531
1519
|
this._injector.get(SheetsThreadCommentHoverController);
|
|
1532
1520
|
this._injector.get(SheetsThreadCommentPopupController);
|
|
1533
|
-
this._injector.get(
|
|
1521
|
+
this._injector.get(SheetsThreadCommentOperationPermissionController);
|
|
1534
1522
|
}
|
|
1535
1523
|
};
|
|
1536
1524
|
_defineProperty(UniverSheetsThreadCommentUIPlugin, "pluginName", PLUGIN_NAME);
|
package/lib/es/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CommandType, DependentOn, Disposable, DisposableCollection, ICommandService, IConfigService, IPermissionService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Plugin, RANGE_TYPE, Range, Rectangle, RxDisposable, ThemeService, Tools, UniverInstanceType, UserManagerService, merge, toDisposable } from "@univerjs/core";
|
|
2
2
|
import { IDrawingManagerService, UniverDrawingPlugin, getDrawingShapeKeyByDrawingSearch } from "@univerjs/drawing";
|
|
3
|
-
import { INTERCEPTOR_POINT, RangeProtectionPermissionViewPoint, SetWorksheetActiveOperation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, UniverSheetsPlugin, WorkbookCommentPermission, WorksheetViewPermission, getSheetCommandTarget } from "@univerjs/sheets";
|
|
3
|
+
import { INTERCEPTOR_POINT, RangeProtectionPermissionViewPoint, SetWorksheetActiveOperation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, UniverSheetsPlugin, WorkbookCommentPermission, WorkbookViewPermission, WorksheetViewPermission, getSheetCommandTarget } from "@univerjs/sheets";
|
|
4
4
|
import { SheetsThreadCommentModel, UniverSheetsThreadCommentPlugin } from "@univerjs/sheets-thread-comment";
|
|
5
|
-
import {
|
|
5
|
+
import { AddCommentMutation, DeleteCommentMutation, IThreadCommentAuthzService, IThreadCommentDataSourceService, ThreadCommentAnchorKind, ThreadCommentModel, UniverThreadCommentPlugin, deserializeThreadCommentAnchor, serializeThreadCommentAnchor } from "@univerjs/thread-comment";
|
|
6
6
|
import { MobileThreadCommentPanel, SetActiveCommentOperation, ThreadCommentCanvasOverlay, ThreadCommentDraftService, ThreadCommentPanel, ThreadCommentPanelService, ThreadCommentTree, ThreadCommentTreeLocation, UniverThreadCommentMobileUIPlugin, UniverThreadCommentUIPlugin } from "@univerjs/thread-comment-ui";
|
|
7
7
|
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, FloatingObjectToolbarPosition, IMenuManagerService, IShortcutService, ISidebarService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, UniverMobileUIPlugin, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
|
|
8
8
|
import { COPY_TYPE, CellPopupManagerService, HoverManagerService, IEditorBridgeService, IMarkSelectionService, ISheetClipboardService, ScrollToRangeOperation, SheetCanvasPopManagerService, SheetSkeletonManagerService, UniverSheetsMobileUIPlugin, UniverSheetsUIPlugin, deriveStateFromActiveSheet$, getCurrentRangeDisable$, whenSheetEditorFocused } from "@univerjs/sheets-ui";
|
|
@@ -34,7 +34,7 @@ const SHEETS_THREAD_COMMENT_PANEL = "univer.sheet.thread-comment-panel";
|
|
|
34
34
|
const SHOW_ADD_SHEET_COMMENT_OPERATION_ID = "sheet.operation.show-comment-modal";
|
|
35
35
|
const PLUGIN_NAME = "SHEET_THREAD_COMMENT_UI_PLUGIN";
|
|
36
36
|
|
|
37
|
-
// \0@oxc-project+runtime@0.
|
|
37
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
38
38
|
function _typeof(o) {
|
|
39
39
|
"@babel/helpers - typeof";
|
|
40
40
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -44,7 +44,7 @@ function _typeof(o) {
|
|
|
44
44
|
}, _typeof(o);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// \0@oxc-project+runtime@0.
|
|
47
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
48
48
|
function toPrimitive(t, e) {
|
|
49
49
|
if ("object" != _typeof(t) || !t) return t;
|
|
50
50
|
var r;
|
|
@@ -56,13 +56,13 @@ function toPrimitive(t, e) {
|
|
|
56
56
|
return ("string" === e ? String : Number)(t);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// \0@oxc-project+runtime@0.
|
|
59
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
60
60
|
function toPropertyKey(t) {
|
|
61
61
|
var i = toPrimitive(t, "string");
|
|
62
62
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
// \0@oxc-project+runtime@0.
|
|
65
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
66
66
|
function _defineProperty(e, r, t) {
|
|
67
67
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
68
68
|
value: t,
|
|
@@ -72,14 +72,14 @@ function _defineProperty(e, r, t) {
|
|
|
72
72
|
}) : e[r] = t, e;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
// \0@oxc-project+runtime@0.
|
|
75
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
76
76
|
function __decorateParam(paramIndex, decorator) {
|
|
77
77
|
return function(target, key) {
|
|
78
78
|
decorator(target, key, paramIndex);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// \0@oxc-project+runtime@0.
|
|
82
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
83
83
|
function __decorate(decorators, target, key, desc) {
|
|
84
84
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
85
85
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -301,9 +301,8 @@ const threadPanelMenuFactory = (accessor) => {
|
|
|
301
301
|
title: "sheets-thread-comment-ui.menu.openComments",
|
|
302
302
|
tooltip: "sheets-thread-comment-ui.menu.openComments",
|
|
303
303
|
disabled$: getCurrentRangeDisable$(accessor, {
|
|
304
|
-
workbookTypes: [
|
|
305
|
-
worksheetTypes: [WorksheetViewPermission]
|
|
306
|
-
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
304
|
+
workbookTypes: [WorkbookViewPermission],
|
|
305
|
+
worksheetTypes: [WorksheetViewPermission]
|
|
307
306
|
}),
|
|
308
307
|
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET)
|
|
309
308
|
};
|
|
@@ -352,7 +351,7 @@ const menuSchema = {
|
|
|
352
351
|
|
|
353
352
|
// package.json
|
|
354
353
|
var name = "@univerjs/sheets-thread-comment-ui";
|
|
355
|
-
var version = "1.
|
|
354
|
+
var version = "1.6.0";
|
|
356
355
|
|
|
357
356
|
// src/services/mobile/mobile-sheet-comment-draft.service.ts
|
|
358
357
|
var MobileSheetCommentDraftService = class extends Disposable {
|
|
@@ -440,6 +439,7 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = ThreadCommentP
|
|
|
440
439
|
} : null;
|
|
441
440
|
const subUnitId$ = useMemo(() => workbook.activeSheet$.pipe(map((i) => i === null || i === void 0 ? void 0 : i.getSheetId())), [workbook.activeSheet$]);
|
|
442
441
|
const subUnitId = useObservable(subUnitId$, (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
|
|
442
|
+
const authzService = useDependency(IThreadCommentAuthzService);
|
|
443
443
|
const hoverShapeId = useRef(null);
|
|
444
444
|
const panelService = useDependency(ThreadCommentPanelService);
|
|
445
445
|
const activeCommentId = useObservable(panelService.activeCommentId$);
|
|
@@ -516,6 +516,7 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = ThreadCommentP
|
|
|
516
516
|
const handleAdd = () => {
|
|
517
517
|
commandService.executeCommand(ShowAddSheetCommentModalOperation.id);
|
|
518
518
|
};
|
|
519
|
+
const filterComment = useCallback((comment) => authzService.canRead(comment), [authzService]);
|
|
519
520
|
const handleHover = (comment) => {
|
|
520
521
|
if (hoverShapeId.current) {
|
|
521
522
|
markSelectionService.removeShape(hoverShapeId.current);
|
|
@@ -544,6 +545,12 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = ThreadCommentP
|
|
|
544
545
|
subUnitId$,
|
|
545
546
|
type: UniverInstanceType.UNIVER_SHEET,
|
|
546
547
|
onAdd: handleAdd,
|
|
548
|
+
disableAdd: !authzService.canWrite("add", {
|
|
549
|
+
unitId,
|
|
550
|
+
subUnitId: subUnitId ?? "",
|
|
551
|
+
ref: ""
|
|
552
|
+
}),
|
|
553
|
+
filterComment,
|
|
547
554
|
getSubUnitName,
|
|
548
555
|
onResolve: handleResolve,
|
|
549
556
|
sortComments,
|
|
@@ -885,65 +892,46 @@ SheetsThreadCommentCopyPasteController = __decorate([
|
|
|
885
892
|
__decorateParam(2, IThreadCommentDataSourceService)
|
|
886
893
|
], SheetsThreadCommentCopyPasteController);
|
|
887
894
|
|
|
888
|
-
// src/controllers/sheets-thread-comment-permission.controller.ts
|
|
889
|
-
let
|
|
890
|
-
constructor(_localeService, _commandService, _sheetPermissionCheckController,
|
|
895
|
+
// src/controllers/sheets-thread-comment-operation-permission.controller.ts
|
|
896
|
+
let SheetsThreadCommentOperationPermissionController = class SheetsThreadCommentOperationPermissionController extends Disposable {
|
|
897
|
+
constructor(_localeService, _commandService, _sheetPermissionCheckController, _authzService, _univerInstanceService) {
|
|
891
898
|
super();
|
|
892
899
|
this._localeService = _localeService;
|
|
893
900
|
this._commandService = _commandService;
|
|
894
901
|
this._sheetPermissionCheckController = _sheetPermissionCheckController;
|
|
895
|
-
this.
|
|
902
|
+
this._authzService = _authzService;
|
|
903
|
+
this._univerInstanceService = _univerInstanceService;
|
|
896
904
|
this._commandExecutedListener();
|
|
897
905
|
}
|
|
898
906
|
_commandExecutedListener() {
|
|
899
907
|
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
900
908
|
const { id } = command;
|
|
901
|
-
if (id ===
|
|
902
|
-
if (!this.
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
})) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
906
|
-
} else if (id === AddCommentCommand.id) {
|
|
907
|
-
const { unitId, subUnitId, comment } = command.params;
|
|
908
|
-
if (!this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
909
|
-
} else if (id === UpdateCommentCommand.id) {
|
|
910
|
-
const { unitId, subUnitId, payload } = command.params;
|
|
911
|
-
const { commentId } = payload;
|
|
912
|
-
const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
913
|
-
if (comment && !this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
914
|
-
} else if (id === ResolveCommentCommand.id || id === DeleteCommentCommand.id || id === DeleteCommentTreeCommand.id) {
|
|
915
|
-
const { unitId, subUnitId, commentId } = command.params;
|
|
916
|
-
const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
917
|
-
if (comment && !this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
909
|
+
if (id === ShowAddSheetCommentModalOperation.id || id === AddSheetDrawingCommentOperation.id) {
|
|
910
|
+
if (!this._authzService.canWrite("add", this._getTarget())) this._block();
|
|
911
|
+
} else if (id === ToggleSheetCommentPanelOperation.id) {
|
|
912
|
+
if (!this._authzService.canRead(this._getTarget())) this._block();
|
|
918
913
|
}
|
|
919
914
|
}));
|
|
920
915
|
}
|
|
921
|
-
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
916
|
+
_getTarget() {
|
|
917
|
+
const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
918
|
+
return {
|
|
919
|
+
unitId: (workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId()) ?? "",
|
|
920
|
+
subUnitId: (workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet().getSheetId()) ?? "",
|
|
921
|
+
ref: ""
|
|
925
922
|
};
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
if (!Number.isFinite(row) || !Number.isFinite(column)) return false;
|
|
930
|
-
return this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
931
|
-
...permissionTypes,
|
|
932
|
-
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
933
|
-
}, [{
|
|
934
|
-
startRow: row,
|
|
935
|
-
startColumn: column,
|
|
936
|
-
endRow: row,
|
|
937
|
-
endColumn: column
|
|
938
|
-
}], unitId, subUnitId);
|
|
923
|
+
}
|
|
924
|
+
_block() {
|
|
925
|
+
this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
939
926
|
}
|
|
940
927
|
};
|
|
941
|
-
|
|
928
|
+
SheetsThreadCommentOperationPermissionController = __decorate([
|
|
942
929
|
__decorateParam(0, Inject(LocaleService)),
|
|
943
930
|
__decorateParam(1, ICommandService),
|
|
944
931
|
__decorateParam(2, Inject(SheetPermissionCheckController)),
|
|
945
|
-
__decorateParam(3, Inject(
|
|
946
|
-
|
|
932
|
+
__decorateParam(3, Inject(IThreadCommentAuthzService)),
|
|
933
|
+
__decorateParam(4, Inject(IUniverInstanceService))
|
|
934
|
+
], SheetsThreadCommentOperationPermissionController);
|
|
947
935
|
|
|
948
936
|
// src/mobile-plugin.ts
|
|
949
937
|
let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMobileUIPlugin extends Plugin {
|
|
@@ -964,7 +952,7 @@ let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMob
|
|
|
964
952
|
[SheetsThreadCommentRenderController],
|
|
965
953
|
[SheetsThreadCommentCopyPasteController],
|
|
966
954
|
[SheetsThreadCommentPopupService],
|
|
967
|
-
[
|
|
955
|
+
[SheetsThreadCommentOperationPermissionController],
|
|
968
956
|
[MobileSheetCommentDraftService]
|
|
969
957
|
].forEach((dependency) => this._injector.add(dependency));
|
|
970
958
|
this._injector.get(MobileComponentsController);
|
|
@@ -981,7 +969,7 @@ let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMob
|
|
|
981
969
|
}
|
|
982
970
|
onRendered() {
|
|
983
971
|
this._injector.get(SheetsThreadCommentCopyPasteController);
|
|
984
|
-
this._injector.get(
|
|
972
|
+
this._injector.get(SheetsThreadCommentOperationPermissionController);
|
|
985
973
|
}
|
|
986
974
|
};
|
|
987
975
|
_defineProperty(UniverSheetsThreadCommentMobileUIPlugin, "pluginName", PLUGIN_NAME);
|
|
@@ -1239,7 +1227,7 @@ let SheetsThreadCommentHoverController = class SheetsThreadCommentHoverControlle
|
|
|
1239
1227
|
const commentId = this._sheetsThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
|
|
1240
1228
|
if (commentId) {
|
|
1241
1229
|
if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
1242
|
-
workbookTypes: [
|
|
1230
|
+
workbookTypes: [WorkbookViewPermission],
|
|
1243
1231
|
worksheetTypes: [WorksheetViewPermission],
|
|
1244
1232
|
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
1245
1233
|
}, [{
|
|
@@ -1364,7 +1352,7 @@ let SheetsThreadCommentPopupController = class SheetsThreadCommentPopupControlle
|
|
|
1364
1352
|
const location = singleReferenceToGrid(comment.ref);
|
|
1365
1353
|
const { row, column: col } = location;
|
|
1366
1354
|
if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
1367
|
-
workbookTypes: [
|
|
1355
|
+
workbookTypes: [WorkbookViewPermission],
|
|
1368
1356
|
worksheetTypes: [WorksheetViewPermission],
|
|
1369
1357
|
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
1370
1358
|
}, [{
|
|
@@ -1507,7 +1495,7 @@ let UniverSheetsThreadCommentUIPlugin = class UniverSheetsThreadCommentUIPlugin
|
|
|
1507
1495
|
[SheetsThreadCommentHoverController],
|
|
1508
1496
|
[SheetsThreadCommentPopupController],
|
|
1509
1497
|
[SheetsThreadCommentPopupService],
|
|
1510
|
-
[
|
|
1498
|
+
[SheetsThreadCommentOperationPermissionController]
|
|
1511
1499
|
].forEach((dep) => {
|
|
1512
1500
|
this._injector.add(dep);
|
|
1513
1501
|
});
|
|
@@ -1529,7 +1517,7 @@ let UniverSheetsThreadCommentUIPlugin = class UniverSheetsThreadCommentUIPlugin
|
|
|
1529
1517
|
this._injector.get(SheetsThreadCommentCopyPasteController);
|
|
1530
1518
|
this._injector.get(SheetsThreadCommentHoverController);
|
|
1531
1519
|
this._injector.get(SheetsThreadCommentPopupController);
|
|
1532
|
-
this._injector.get(
|
|
1520
|
+
this._injector.get(SheetsThreadCommentOperationPermissionController);
|
|
1533
1521
|
}
|
|
1534
1522
|
};
|
|
1535
1523
|
_defineProperty(UniverSheetsThreadCommentUIPlugin, "pluginName", PLUGIN_NAME);
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CommandType, DependentOn, Disposable, DisposableCollection, ICommandService, IConfigService, IPermissionService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Plugin, RANGE_TYPE, Range, Rectangle, RxDisposable, ThemeService, Tools, UniverInstanceType, UserManagerService, merge, toDisposable } from "@univerjs/core";
|
|
2
2
|
import { IDrawingManagerService, UniverDrawingPlugin, getDrawingShapeKeyByDrawingSearch } from "@univerjs/drawing";
|
|
3
|
-
import { INTERCEPTOR_POINT, RangeProtectionPermissionViewPoint, SetWorksheetActiveOperation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, UniverSheetsPlugin, WorkbookCommentPermission, WorksheetViewPermission, getSheetCommandTarget } from "@univerjs/sheets";
|
|
3
|
+
import { INTERCEPTOR_POINT, RangeProtectionPermissionViewPoint, SetWorksheetActiveOperation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, UniverSheetsPlugin, WorkbookCommentPermission, WorkbookViewPermission, WorksheetViewPermission, getSheetCommandTarget } from "@univerjs/sheets";
|
|
4
4
|
import { SheetsThreadCommentModel, UniverSheetsThreadCommentPlugin } from "@univerjs/sheets-thread-comment";
|
|
5
|
-
import {
|
|
5
|
+
import { AddCommentMutation, DeleteCommentMutation, IThreadCommentAuthzService, IThreadCommentDataSourceService, ThreadCommentAnchorKind, ThreadCommentModel, UniverThreadCommentPlugin, deserializeThreadCommentAnchor, serializeThreadCommentAnchor } from "@univerjs/thread-comment";
|
|
6
6
|
import { MobileThreadCommentPanel, SetActiveCommentOperation, ThreadCommentCanvasOverlay, ThreadCommentDraftService, ThreadCommentPanel, ThreadCommentPanelService, ThreadCommentTree, ThreadCommentTreeLocation, UniverThreadCommentMobileUIPlugin, UniverThreadCommentUIPlugin } from "@univerjs/thread-comment-ui";
|
|
7
7
|
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, FloatingObjectToolbarPosition, IMenuManagerService, IShortcutService, ISidebarService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, UniverMobileUIPlugin, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
|
|
8
8
|
import { COPY_TYPE, CellPopupManagerService, HoverManagerService, IEditorBridgeService, IMarkSelectionService, ISheetClipboardService, ScrollToRangeOperation, SheetCanvasPopManagerService, SheetSkeletonManagerService, UniverSheetsMobileUIPlugin, UniverSheetsUIPlugin, deriveStateFromActiveSheet$, getCurrentRangeDisable$, whenSheetEditorFocused } from "@univerjs/sheets-ui";
|
|
@@ -34,7 +34,7 @@ const SHEETS_THREAD_COMMENT_PANEL = "univer.sheet.thread-comment-panel";
|
|
|
34
34
|
const SHOW_ADD_SHEET_COMMENT_OPERATION_ID = "sheet.operation.show-comment-modal";
|
|
35
35
|
const PLUGIN_NAME = "SHEET_THREAD_COMMENT_UI_PLUGIN";
|
|
36
36
|
|
|
37
|
-
// \0@oxc-project+runtime@0.
|
|
37
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
38
38
|
function _typeof(o) {
|
|
39
39
|
"@babel/helpers - typeof";
|
|
40
40
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -44,7 +44,7 @@ function _typeof(o) {
|
|
|
44
44
|
}, _typeof(o);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// \0@oxc-project+runtime@0.
|
|
47
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
48
48
|
function toPrimitive(t, e) {
|
|
49
49
|
if ("object" != _typeof(t) || !t) return t;
|
|
50
50
|
var r;
|
|
@@ -56,13 +56,13 @@ function toPrimitive(t, e) {
|
|
|
56
56
|
return ("string" === e ? String : Number)(t);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// \0@oxc-project+runtime@0.
|
|
59
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
60
60
|
function toPropertyKey(t) {
|
|
61
61
|
var i = toPrimitive(t, "string");
|
|
62
62
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
// \0@oxc-project+runtime@0.
|
|
65
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
66
66
|
function _defineProperty(e, r, t) {
|
|
67
67
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
68
68
|
value: t,
|
|
@@ -72,14 +72,14 @@ function _defineProperty(e, r, t) {
|
|
|
72
72
|
}) : e[r] = t, e;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
// \0@oxc-project+runtime@0.
|
|
75
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
76
76
|
function __decorateParam(paramIndex, decorator) {
|
|
77
77
|
return function(target, key) {
|
|
78
78
|
decorator(target, key, paramIndex);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// \0@oxc-project+runtime@0.
|
|
82
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
83
83
|
function __decorate(decorators, target, key, desc) {
|
|
84
84
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
85
85
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -301,9 +301,8 @@ const threadPanelMenuFactory = (accessor) => {
|
|
|
301
301
|
title: "sheets-thread-comment-ui.menu.openComments",
|
|
302
302
|
tooltip: "sheets-thread-comment-ui.menu.openComments",
|
|
303
303
|
disabled$: getCurrentRangeDisable$(accessor, {
|
|
304
|
-
workbookTypes: [
|
|
305
|
-
worksheetTypes: [WorksheetViewPermission]
|
|
306
|
-
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
304
|
+
workbookTypes: [WorkbookViewPermission],
|
|
305
|
+
worksheetTypes: [WorksheetViewPermission]
|
|
307
306
|
}),
|
|
308
307
|
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET)
|
|
309
308
|
};
|
|
@@ -352,7 +351,7 @@ const menuSchema = {
|
|
|
352
351
|
|
|
353
352
|
// package.json
|
|
354
353
|
var name = "@univerjs/sheets-thread-comment-ui";
|
|
355
|
-
var version = "1.
|
|
354
|
+
var version = "1.6.0";
|
|
356
355
|
|
|
357
356
|
// src/services/mobile/mobile-sheet-comment-draft.service.ts
|
|
358
357
|
var MobileSheetCommentDraftService = class extends Disposable {
|
|
@@ -440,6 +439,7 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = ThreadCommentP
|
|
|
440
439
|
} : null;
|
|
441
440
|
const subUnitId$ = useMemo(() => workbook.activeSheet$.pipe(map((i) => i === null || i === void 0 ? void 0 : i.getSheetId())), [workbook.activeSheet$]);
|
|
442
441
|
const subUnitId = useObservable(subUnitId$, (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
|
|
442
|
+
const authzService = useDependency(IThreadCommentAuthzService);
|
|
443
443
|
const hoverShapeId = useRef(null);
|
|
444
444
|
const panelService = useDependency(ThreadCommentPanelService);
|
|
445
445
|
const activeCommentId = useObservable(panelService.activeCommentId$);
|
|
@@ -516,6 +516,7 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = ThreadCommentP
|
|
|
516
516
|
const handleAdd = () => {
|
|
517
517
|
commandService.executeCommand(ShowAddSheetCommentModalOperation.id);
|
|
518
518
|
};
|
|
519
|
+
const filterComment = useCallback((comment) => authzService.canRead(comment), [authzService]);
|
|
519
520
|
const handleHover = (comment) => {
|
|
520
521
|
if (hoverShapeId.current) {
|
|
521
522
|
markSelectionService.removeShape(hoverShapeId.current);
|
|
@@ -544,6 +545,12 @@ const SheetsThreadCommentPanel = ({ ThreadCommentPanelComponent = ThreadCommentP
|
|
|
544
545
|
subUnitId$,
|
|
545
546
|
type: UniverInstanceType.UNIVER_SHEET,
|
|
546
547
|
onAdd: handleAdd,
|
|
548
|
+
disableAdd: !authzService.canWrite("add", {
|
|
549
|
+
unitId,
|
|
550
|
+
subUnitId: subUnitId ?? "",
|
|
551
|
+
ref: ""
|
|
552
|
+
}),
|
|
553
|
+
filterComment,
|
|
547
554
|
getSubUnitName,
|
|
548
555
|
onResolve: handleResolve,
|
|
549
556
|
sortComments,
|
|
@@ -885,65 +892,46 @@ SheetsThreadCommentCopyPasteController = __decorate([
|
|
|
885
892
|
__decorateParam(2, IThreadCommentDataSourceService)
|
|
886
893
|
], SheetsThreadCommentCopyPasteController);
|
|
887
894
|
|
|
888
|
-
// src/controllers/sheets-thread-comment-permission.controller.ts
|
|
889
|
-
let
|
|
890
|
-
constructor(_localeService, _commandService, _sheetPermissionCheckController,
|
|
895
|
+
// src/controllers/sheets-thread-comment-operation-permission.controller.ts
|
|
896
|
+
let SheetsThreadCommentOperationPermissionController = class SheetsThreadCommentOperationPermissionController extends Disposable {
|
|
897
|
+
constructor(_localeService, _commandService, _sheetPermissionCheckController, _authzService, _univerInstanceService) {
|
|
891
898
|
super();
|
|
892
899
|
this._localeService = _localeService;
|
|
893
900
|
this._commandService = _commandService;
|
|
894
901
|
this._sheetPermissionCheckController = _sheetPermissionCheckController;
|
|
895
|
-
this.
|
|
902
|
+
this._authzService = _authzService;
|
|
903
|
+
this._univerInstanceService = _univerInstanceService;
|
|
896
904
|
this._commandExecutedListener();
|
|
897
905
|
}
|
|
898
906
|
_commandExecutedListener() {
|
|
899
907
|
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
900
908
|
const { id } = command;
|
|
901
|
-
if (id ===
|
|
902
|
-
if (!this.
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
})) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
906
|
-
} else if (id === AddCommentCommand.id) {
|
|
907
|
-
const { unitId, subUnitId, comment } = command.params;
|
|
908
|
-
if (!this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
909
|
-
} else if (id === UpdateCommentCommand.id) {
|
|
910
|
-
const { unitId, subUnitId, payload } = command.params;
|
|
911
|
-
const { commentId } = payload;
|
|
912
|
-
const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
913
|
-
if (comment && !this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
914
|
-
} else if (id === ResolveCommentCommand.id || id === DeleteCommentCommand.id || id === DeleteCommentTreeCommand.id) {
|
|
915
|
-
const { unitId, subUnitId, commentId } = command.params;
|
|
916
|
-
const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
917
|
-
if (comment && !this._hasCommentPermission(unitId, subUnitId, comment.ref)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
909
|
+
if (id === ShowAddSheetCommentModalOperation.id || id === AddSheetDrawingCommentOperation.id) {
|
|
910
|
+
if (!this._authzService.canWrite("add", this._getTarget())) this._block();
|
|
911
|
+
} else if (id === ToggleSheetCommentPanelOperation.id) {
|
|
912
|
+
if (!this._authzService.canRead(this._getTarget())) this._block();
|
|
918
913
|
}
|
|
919
914
|
}));
|
|
920
915
|
}
|
|
921
|
-
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
916
|
+
_getTarget() {
|
|
917
|
+
const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
918
|
+
return {
|
|
919
|
+
unitId: (workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId()) ?? "",
|
|
920
|
+
subUnitId: (workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet().getSheetId()) ?? "",
|
|
921
|
+
ref: ""
|
|
925
922
|
};
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
if (!Number.isFinite(row) || !Number.isFinite(column)) return false;
|
|
930
|
-
return this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
931
|
-
...permissionTypes,
|
|
932
|
-
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
933
|
-
}, [{
|
|
934
|
-
startRow: row,
|
|
935
|
-
startColumn: column,
|
|
936
|
-
endRow: row,
|
|
937
|
-
endColumn: column
|
|
938
|
-
}], unitId, subUnitId);
|
|
923
|
+
}
|
|
924
|
+
_block() {
|
|
925
|
+
this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
|
|
939
926
|
}
|
|
940
927
|
};
|
|
941
|
-
|
|
928
|
+
SheetsThreadCommentOperationPermissionController = __decorate([
|
|
942
929
|
__decorateParam(0, Inject(LocaleService)),
|
|
943
930
|
__decorateParam(1, ICommandService),
|
|
944
931
|
__decorateParam(2, Inject(SheetPermissionCheckController)),
|
|
945
|
-
__decorateParam(3, Inject(
|
|
946
|
-
|
|
932
|
+
__decorateParam(3, Inject(IThreadCommentAuthzService)),
|
|
933
|
+
__decorateParam(4, Inject(IUniverInstanceService))
|
|
934
|
+
], SheetsThreadCommentOperationPermissionController);
|
|
947
935
|
|
|
948
936
|
// src/mobile-plugin.ts
|
|
949
937
|
let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMobileUIPlugin extends Plugin {
|
|
@@ -964,7 +952,7 @@ let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMob
|
|
|
964
952
|
[SheetsThreadCommentRenderController],
|
|
965
953
|
[SheetsThreadCommentCopyPasteController],
|
|
966
954
|
[SheetsThreadCommentPopupService],
|
|
967
|
-
[
|
|
955
|
+
[SheetsThreadCommentOperationPermissionController],
|
|
968
956
|
[MobileSheetCommentDraftService]
|
|
969
957
|
].forEach((dependency) => this._injector.add(dependency));
|
|
970
958
|
this._injector.get(MobileComponentsController);
|
|
@@ -981,7 +969,7 @@ let UniverSheetsThreadCommentMobileUIPlugin = class UniverSheetsThreadCommentMob
|
|
|
981
969
|
}
|
|
982
970
|
onRendered() {
|
|
983
971
|
this._injector.get(SheetsThreadCommentCopyPasteController);
|
|
984
|
-
this._injector.get(
|
|
972
|
+
this._injector.get(SheetsThreadCommentOperationPermissionController);
|
|
985
973
|
}
|
|
986
974
|
};
|
|
987
975
|
_defineProperty(UniverSheetsThreadCommentMobileUIPlugin, "pluginName", PLUGIN_NAME);
|
|
@@ -1239,7 +1227,7 @@ let SheetsThreadCommentHoverController = class SheetsThreadCommentHoverControlle
|
|
|
1239
1227
|
const commentId = this._sheetsThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
|
|
1240
1228
|
if (commentId) {
|
|
1241
1229
|
if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
1242
|
-
workbookTypes: [
|
|
1230
|
+
workbookTypes: [WorkbookViewPermission],
|
|
1243
1231
|
worksheetTypes: [WorksheetViewPermission],
|
|
1244
1232
|
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
1245
1233
|
}, [{
|
|
@@ -1364,7 +1352,7 @@ let SheetsThreadCommentPopupController = class SheetsThreadCommentPopupControlle
|
|
|
1364
1352
|
const location = singleReferenceToGrid(comment.ref);
|
|
1365
1353
|
const { row, column: col } = location;
|
|
1366
1354
|
if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
|
|
1367
|
-
workbookTypes: [
|
|
1355
|
+
workbookTypes: [WorkbookViewPermission],
|
|
1368
1356
|
worksheetTypes: [WorksheetViewPermission],
|
|
1369
1357
|
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
1370
1358
|
}, [{
|
|
@@ -1507,7 +1495,7 @@ let UniverSheetsThreadCommentUIPlugin = class UniverSheetsThreadCommentUIPlugin
|
|
|
1507
1495
|
[SheetsThreadCommentHoverController],
|
|
1508
1496
|
[SheetsThreadCommentPopupController],
|
|
1509
1497
|
[SheetsThreadCommentPopupService],
|
|
1510
|
-
[
|
|
1498
|
+
[SheetsThreadCommentOperationPermissionController]
|
|
1511
1499
|
].forEach((dep) => {
|
|
1512
1500
|
this._injector.add(dep);
|
|
1513
1501
|
});
|
|
@@ -1529,7 +1517,7 @@ let UniverSheetsThreadCommentUIPlugin = class UniverSheetsThreadCommentUIPlugin
|
|
|
1529
1517
|
this._injector.get(SheetsThreadCommentCopyPasteController);
|
|
1530
1518
|
this._injector.get(SheetsThreadCommentHoverController);
|
|
1531
1519
|
this._injector.get(SheetsThreadCommentPopupController);
|
|
1532
|
-
this._injector.get(
|
|
1520
|
+
this._injector.get(SheetsThreadCommentOperationPermissionController);
|
|
1533
1521
|
}
|
|
1534
1522
|
};
|
|
1535
1523
|
_defineProperty(UniverSheetsThreadCommentUIPlugin, "pluginName", PLUGIN_NAME);
|
|
@@ -13,15 +13,22 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { Disposable, ICommandService, LocaleService } from '@univerjs/core';
|
|
16
|
+
import { Disposable, ICommandService, IUniverInstanceService, LocaleService } from '@univerjs/core';
|
|
17
17
|
import { SheetPermissionCheckController } from '@univerjs/sheets';
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
import { IThreadCommentAuthzService } from '@univerjs/thread-comment';
|
|
19
|
+
/**
|
|
20
|
+
* Guards the sheet comment entry points. Command writes are enforced in
|
|
21
|
+
* `@univerjs/sheets-thread-comment`; these operations only open UI surfaces, so
|
|
22
|
+
* blocking them early gives feedback before a modal or panel is opened.
|
|
23
|
+
*/
|
|
24
|
+
export declare class SheetsThreadCommentOperationPermissionController extends Disposable {
|
|
25
|
+
private readonly _localeService;
|
|
21
26
|
private readonly _commandService;
|
|
22
27
|
private readonly _sheetPermissionCheckController;
|
|
23
|
-
private readonly
|
|
24
|
-
|
|
28
|
+
private readonly _authzService;
|
|
29
|
+
private readonly _univerInstanceService;
|
|
30
|
+
constructor(_localeService: LocaleService, _commandService: ICommandService, _sheetPermissionCheckController: SheetPermissionCheckController, _authzService: IThreadCommentAuthzService, _univerInstanceService: IUniverInstanceService);
|
|
25
31
|
private _commandExecutedListener;
|
|
26
|
-
private
|
|
32
|
+
private _getTarget;
|
|
33
|
+
private _block;
|
|
27
34
|
}
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IUniverSheetsThreadCommentUIConfig } from './config/config';
|
|
17
16
|
import { ICommandService, IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
17
|
+
import type { IUniverSheetsThreadCommentUIConfig } from './config/config';
|
|
18
18
|
export declare class UniverSheetsThreadCommentMobileUIPlugin extends Plugin {
|
|
19
19
|
private readonly _config;
|
|
20
20
|
protected _injector: Injector;
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IUniverSheetsThreadCommentUIConfig } from './config/config';
|
|
17
16
|
import { ICommandService, IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
18
17
|
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
18
|
+
import type { IUniverSheetsThreadCommentUIConfig } from './config/config';
|
|
19
19
|
export declare class UniverSheetsThreadCommentUIPlugin extends Plugin {
|
|
20
20
|
private readonly _config;
|
|
21
21
|
protected _injector: Injector;
|
package/lib/umd/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-thread-comment"),require("@univerjs/thread-comment"),require("@univerjs/thread-comment-ui"),require("@univerjs/ui"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/engine-formula"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-thread-comment`,`@univerjs/thread-comment`,`@univerjs/thread-comment-ui`,`@univerjs/ui`,`@univerjs/sheets-ui`,`rxjs`,`@univerjs/engine-render`,`react`,`@univerjs/engine-formula`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsThreadCommentUi={},e.UniverCore,e.UniverDrawing,e.UniverSheets,e.UniverSheetsThreadComment,e.UniverThreadComment,e.UniverThreadCommentUi,e.UniverUi,e.UniverSheetsUi,e.rxjs,e.UniverEngineRender,e.React,e.UniverEngineFormula,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let m=`univer.sheet.thread-comment-modal`,h=`univer.sheet.thread-comment-panel`,g=`sheet.operation.show-comment-modal`,_=`SHEET_THREAD_COMMENT_UI_PLUGIN`;function v(e){"@babel/helpers - typeof";return v=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},v(e)}function y(e,t){if(v(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(v(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ee(e){var t=y(e,`string`);return v(t)==`symbol`?t:t+``}function b(e,t,n){return(t=ee(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function x(e,t){return function(n,r){t(n,r,e)}}function S(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 C=class extends t.Disposable{get activePopup(){return this._activePopup}constructor(e,t){super(),this._canvasPopupManagerService=e,this._cellPopupManagerService=t,b(this,`_lastPopup`,null),b(this,`_activePopup`,void 0),b(this,`_activePopup$`,new l.BehaviorSubject(null)),b(this,`activePopup$`,this._activePopup$.asObservable()),this.disposeWithMe(()=>{this._activePopup$.complete()})}dispose(){super.dispose(),this.hidePopup()}showPopup(e,n){var r;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===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}this._lastPopup&&this._lastPopup.dispose(),this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey:m,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 t.DisposableCollection;l.add(c),l.add({dispose:()=>{n==null||n()}}),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))}};C=S([x(0,(0,t.Inject)(c.SheetCanvasPopManagerService)),x(1,(0,t.Inject)(c.CellPopupManagerService))],C);let w={type:t.CommandType.OPERATION,id:g,handler(e){var n;let a=e.get(r.SheetsSelectionsService),s=e.get(t.IUniverInstanceService),c=e.get(C),l=e.get(o.ThreadCommentPanelService),u=(n=a.getCurrentLastSelection())==null?void 0:n.primary,d=e.get(i.SheetsThreadCommentModel);if(!u)return!1;let f=(0,r.getSheetCommandTarget)(s);if(!f)return!1;let{workbook:p,worksheet:m,unitId:h,subUnitId:g}=f,_={workbook:p,worksheet:m,unitId:h,subUnitId:g,row:u.startRow,col:u.startColumn};c.showPopup(_);let v=d.getByLocation(h,g,u.startRow,u.startColumn);return v&&l.setActiveComment({unitId:h,subUnitId:g,commentId:v,trigger:`context-menu`}),!0}},T={id:`sheet.operation.toggle-comment-panel`,type:t.CommandType.OPERATION,handler(e){let t=e.get(s.ISidebarService),n=e.get(o.ThreadCommentPanelService);return n.panelVisible?(t.close(),n.setPanelVisible(!1)):D(t,n),!0}},E={id:`sheet.operation.open-comment-panel`,type:t.CommandType.OPERATION,handler(e){return D(e.get(s.ISidebarService),e.get(o.ThreadCommentPanelService)),!0}};function D(e,t){var n;t.panelVisible&&((n=e.options.children)==null?void 0:n.label)===`univer.sheet.thread-comment-panel`||e.open({header:{title:`sheets-thread-comment-ui.panel.title`},children:{label:h},width:360,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)}let O={id:`sheet.operation.add-drawing-comment`,type:t.CommandType.OPERATION,handler(e){var r;let i=e.get(n.IDrawingManagerService).getFocusDrawings()[0],c=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!i||!c||i.unitId!==c.getUnitId()||i.subUnitId!==((r=c.getActiveSheet())==null?void 0:r.getSheetId()))return!1;e.get(o.ThreadCommentDraftService).place({unitId:i.unitId,subUnitId:i.subUnitId,anchor:{kind:a.ThreadCommentAnchorKind.SHEET_DRAWING,pageId:i.subUnitId,elementId:i.drawingId}});let l=e.get(o.ThreadCommentPanelService);return e.get(s.ISidebarService).open({header:{title:`sheets-thread-comment-ui.panel.title`},children:{label:h},width:360,onClose:()=>l.setPanelVisible(!1)}),l.setPanelVisible(!0),!0}};function k(e){let n=e.get(t.IUniverInstanceService),i=e.get(t.IPermissionService);return(0,c.deriveStateFromActiveSheet$)(n,!0,({workbook:e,worksheet:t})=>{let n=e.getUnitId(),a=t.getSheetId();return i.composePermission$([new r.WorkbookCommentPermission(n).id,new r.WorksheetViewPermission(n,a).id]).pipe((0,l.map)(e=>e.some(e=>e.value===!1)))})}let A=e=>({id:O.id,type:s.MenuItemType.BUTTON,icon:`InsertCommentDoubleIcon`,title:`sheets-thread-comment-ui.menu.addComment`,tooltip:`sheets-thread-comment-ui.menu.addComment`,hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:k(e)}),j=e=>({id:w.id,type:s.MenuItemType.BUTTON,icon:`InsertCommentDoubleIcon`,title:`sheets-thread-comment-ui.menu.addComment`,tooltip:`sheets-thread-comment-ui.menu.addComment`,hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]})}),M=e=>{let n=e.get(s.ISidebarService);return{activated$:(0,l.defer)(()=>n.sidebarOptions$.pipe((0,l.startWith)(n.options),(0,l.map)(e=>{var t;return e.visible===!0&&((t=e.children)==null?void 0:t.label)===`univer.sheet.thread-comment-panel`}),(0,l.distinctUntilChanged)())),id:T.id,type:s.MenuItemType.BUTTON,icon:`CommentIcon`,title:`sheets-thread-comment-ui.menu.openComments`,tooltip:`sheets-thread-comment-ui.menu.openComments`,disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]}),hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}},N={id:w.id,binding:s.KeyCode.M|s.MetaKeys.CTRL_COMMAND|s.MetaKeys.ALT,preconditions:c.whenSheetEditorFocused},te={[s.RibbonInsertGroup.MEDIA]:{[T.id]:{order:2,gridLayout:{row:1,column:3,showLabel:!0},menuItemFactory:M},[w.id]:{order:2.1,gridLayout:{row:2,column:3,showLabel:!0},menuItemFactory:j}},[s.ContextMenuPosition.MAIN_AREA]:{[s.ContextMenuGroup.OTHERS]:{[w.id]:{order:0,menuItemFactory:j}}},[s.FloatingObjectToolbarPosition.SHEET]:{[O.id]:{order:10,menuItemFactory:A}},[s.ContextMenuPosition.DRAWING]:{[s.ContextMenuGroup.OTHERS]:{[O.id]:{order:0,menuItemFactory:A}}}};var ne=`@univerjs/sheets-thread-comment-ui`,re=`1.5.1`,P=class extends t.Disposable{constructor(){super(),b(this,`_draft$`,new l.BehaviorSubject(null)),b(this,`draft$`,this._draft$.asObservable()),this.disposeWithMe(()=>this._draft$.complete())}get draft(){return this._draft$.getValue()}place(e){this._draft$.next(e)}cancel(){this._draft$.next(null)}};let F={type:t.CommandType.OPERATION,id:g,handler(e){var n;let a=(n=e.get(r.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:n.primary;if(!a)return!1;let c=(0,r.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=a.startRow,f=a.startColumn,p=e.get(o.ThreadCommentPanelService),m=e.get(P),h=e.get(i.SheetsThreadCommentModel).getByLocation(l,u,d,f);return e.get(o.ThreadCommentDraftService).cancel(),h?(m.cancel(),p.setActiveComment({unitId:l,subUnitId:u,commentId:h})):(p.setActiveComment(void 0),m.place({unitId:l,subUnitId:u,row:d,column:f})),D(e.get(s.ISidebarService),p),!0}},I=`sheets-thread-comment.config`,L={};function R({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=`_${(0,d.useId)()}`,u=(0,d.useRef)(null);return(0,d.useImperativeHandle)(e,()=>u.current),(0,d.useLayoutEffect)(()=>{if(n&&u.current&&u.current.localName===r.tag)return se(u.current)},[n,r]),ie(r,`${i}`,{defIds:r.defIds,idSuffix:l},{ref:u,className:c,...s},o)}function ie(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...ae(e,n,i),...r},(oe(e,n).children||[]).map((r,a)=>ie(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ae(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0||(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function oe(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function se(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:ce(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=n})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(le(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function ce(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function le(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}R.displayName=`UniverIcon`;let ue={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 17`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.43993 3.31861H15.0381V12.5611H8.65676L5.75498 14.069V12.5611H2.43993V3.31861Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M5.83725 7.50706V8.41159M8.73904 7.50706V8.41159M11.6408 7.50706V8.41159`,strokeLinecap:`round`,strokeWidth:1.39}}]},z=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(R,Object.assign({},e,{id:`comment-icon`,ref:t,icon:ue}))});z.displayName=`CommentIcon`;let de={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.63636 1.99658C1.28491 1.99658 1 2.28149 1 2.63295V10.2693C1 10.6208 1.28491 10.9057 1.63636 10.9057H2.96368L4.05003 11.992C4.29854 12.2405 4.70146 12.2405 4.94997 11.992L6.03632 10.9057H6.72727V12.4128C6.72727 12.7643 7.01218 13.0492 7.36364 13.0492H10.6001L11.3682 13.8173C11.6167 14.0658 12.0196 14.0658 12.2682 13.8173L13.0363 13.0492H14.3636C14.7151 13.0492 15 12.7643 15 12.4128V7.32192C15 6.97047 14.7151 6.68556 14.3636 6.68556H12.4545V2.63295C12.4545 2.28149 12.1696 1.99658 11.8182 1.99658H1.63636ZM12.4545 7.95829V10.2693C12.4545 10.6208 12.1696 10.9057 11.8182 10.9057H8V11.7765H10.8636C11.0324 11.7765 11.1942 11.8435 11.3136 11.9628L11.8182 12.4674L12.3228 11.9628C12.4421 11.8435 12.604 11.7765 12.7727 11.7765H13.7273V7.95829H12.4545ZM11.1818 3.26931H2.27273V9.63295H3.22727C3.39604 9.63295 3.5579 9.70001 3.67725 9.81936L4.5 10.6421L5.32275 9.81936C5.4421 9.70001 5.60396 9.63295 5.77273 9.63295H11.1818V3.26931Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`colorChannel1`,d:`M5.13617 4.54199C4.78472 4.54199 4.49981 4.8269 4.49981 5.17836C4.49981 5.52981 4.78472 5.81472 5.13617 5.81472H8.95435C9.3058 5.81472 9.59072 5.52981 9.59072 5.17836C9.59072 4.8269 9.3058 4.54199 8.95435 4.54199H5.13617ZM4.49981 7.72381C4.49981 7.37236 4.78472 7.08744 5.13617 7.08744H7.04526C7.39671 7.08744 7.68162 7.37236 7.68162 7.72381C7.68162 8.07526 7.39671 8.36018 7.04526 8.36018H5.13617C4.78472 8.36018 4.49981 8.07526 4.49981 7.72381Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},B=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(R,Object.assign({},e,{id:`insert-comment-double-icon`,ref:t,icon:de}))});B.displayName=`InsertCommentDoubleIcon`;let V=({ThreadCommentPanelComponent:e=o.ThreadCommentPanel}={})=>{var n;let r=(0,s.useDependency)(c.IMarkSelectionService),i=(0,s.useDependency)(t.IUniverInstanceService),u=(0,s.useDependency)(C),m=i.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),h=m.getUnitId(),g=(0,s.useDependency)(t.ICommandService),_=(0,s.useDependency)(o.ThreadCommentDraftService),v=(0,s.useDependency)(t.UserManagerService),y=(0,s.useObservable)(_.draft$,_.draft),ee=(y==null?void 0:y.anchor.kind)===a.ThreadCommentAnchorKind.SHEET_DRAWING&&y.unitId===h?{id:``,threadId:``,unitId:y.unitId,subUnitId:y.subUnitId,ref:(0,a.serializeThreadCommentAnchor)(y.anchor),dT:``,personId:v.getCurrentUser().userID,text:{dataStream:`\r
|
|
2
|
-
`}}:null,b=(0,d.useMemo)(()=>m.activeSheet$.pipe((0,l.map)(e=>e==null?void 0:e.getSheetId())),[m.activeSheet$]),x=(0,s.useObservable)(b,(n=m.getActiveSheet())==null?void 0:n.getSheetId()),S=(0,d.useRef)(null),
|
|
3
|
-
`}}:null,c=()=>{var t;n.cancel(),(t=e.onTempCommentClose)==null||t.call(e)};return/* @__PURE__ */ (0,p.jsx)(o.MobileThreadCommentPanel,{...e,tempComment:e.tempComment??a,onTempCommentClose:c,autoFocusActiveComment:!0})}function pe(){return/* @__PURE__ */ (0,p.jsx)(V,{ThreadCommentPanelComponent:fe})}let H=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this.disposeWithMe(this._componentManager.register(h,pe)),this.disposeWithMe(this._iconManager.register({CommentIcon:z,InsertCommentDoubleIcon:B}))}};H=S([x(0,(0,t.Inject)(s.ComponentManager)),x(1,(0,t.Inject)(s.IconManager))],H);function me(e){var t;let n=e.get(r.SheetsSelectionsService),a=(t=n.getCurrentLastSelection())==null?void 0:t.primary,o=n.currentSelectionParam;return!a||!o?`sheets-thread-comment-ui.menu.addComment`:e.get(i.SheetsThreadCommentModel).getByLocation(o.unitId,o.sheetId,a.startRow,a.startColumn)?`sheets-thread-comment-ui.menu.openComments`:`sheets-thread-comment-ui.menu.addComment`}let he=e=>({id:F.id,type:s.MenuItemType.BUTTON,icon:`InsertCommentDoubleIcon`,title:`sheets-thread-comment-ui.menu.addComment`,hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]})}),ge=e=>({...he(e),title:me(e)}),_e={[s.RibbonInsertGroup.MEDIA]:{[T.id]:{order:2,gridLayout:{row:1,column:3,showLabel:!0},menuItemFactory:M},[F.id]:{order:2.1,gridLayout:{row:2,column:3,showLabel:!0},menuItemFactory:he}},[s.ContextMenuPosition.MAIN_AREA]:{[s.ContextMenuGroup.OTHERS]:{[F.id]:{order:0,menuItemFactory:ge}}},[s.FloatingObjectToolbarPosition.SHEET]:{[O.id]:{order:10,menuItemFactory:A}},[s.ContextMenuPosition.DRAWING]:{[s.ContextMenuGroup.OTHERS]:{[O.id]:{order:0,menuItemFactory:A}}}},U=class extends t.Disposable{constructor(e){super(),e.mergeMenu(_e)}};U=S([x(0,s.IMenuManagerService)],U);let W=class extends t.Disposable{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(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.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)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderUnitById(r);i==null||(e=i.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe((0,l.debounceTime)(16)).subscribe(()=>{e()}))}};W=S([x(0,(0,t.Inject)(r.SheetInterceptorService)),x(1,(0,t.Inject)(i.SheetsThreadCommentModel)),x(2,t.IUniverInstanceService),x(3,u.IRenderManagerService)],W);let ve=(e,t,n)=>{let r=(0,f.singleReferenceToGrid)(e),i=n.row-t.row,a=n.column-t.column,o={startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i};return(0,f.serializeRange)(o)},G=class extends t.Disposable{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=n,b(this,`_copyInfo`,void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:_,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,n,r,i)=>{let{unitId:o,subUnitId:s,range:l}=n,u={row:l.rows[0],column:l.cols[0]};if(i.copyType===c.COPY_TYPE.CUT&&this._copyInfo){let{range:e,unitId:n,subUnitId:r}=this._copyInfo,i={row:e.startRow,column:e.startColumn};if(o!==n||s!==r){let c=[];t.Range.foreach(e,(e,t)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(n,r,e,t);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{c.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||c.push(t)})});let l=[],d=[],f=[],p=[],m=e=>{l.unshift({id:a.DeleteCommentMutation.id,params:{unitId:n,subUnitId:r,commentId:e.id}}),f.push({id:a.AddCommentMutation.id,params:{unitId:o,subUnitId:s,comment:{...e,ref:ve(e.ref,i,u),unitId:o,subUnitId:s},sync:!0}}),d.push({id:a.AddCommentMutation.id,params:{unitId:n,subUnitId:r,comment:e,sync:!0}}),p.unshift({id:a.DeleteCommentMutation.id,params:{unitId:o,subUnitId:s,commentId:e.id}})};return c.forEach(e=>{m(e)}),{redos:[...l,...f],undos:[...p,...d]}}}return{redos:[],undos:[]}}}))}};G=S([x(0,(0,t.Inject)(c.ISheetClipboardService)),x(1,(0,t.Inject)(i.SheetsThreadCommentModel)),x(2,a.IThreadCommentDataSourceService)],G);let K=class extends t.Disposable{constructor(e,t,n,r){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._sheetsThreadCommentModel=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let{id:t}=e;if(t===O.id||t===w.id||t===T.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-thread-comment-ui.permission.commentErr`));else if(t===a.AddCommentCommand.id){let{unitId:t,subUnitId:n,comment:r}=e.params;this._hasCommentPermission(t,n,r.ref)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-thread-comment-ui.permission.commentErr`))}else if(t===a.UpdateCommentCommand.id){let{unitId:t,subUnitId:n,payload:r}=e.params,{commentId:i}=r,a=this._sheetsThreadCommentModel.getComment(t,n,i);a&&!this._hasCommentPermission(t,n,a.ref)&&this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-thread-comment-ui.permission.commentErr`))}else if(t===a.ResolveCommentCommand.id||t===a.DeleteCommentCommand.id||t===a.DeleteCommentTreeCommand.id){let{unitId:t,subUnitId:n,commentId:r}=e.params,i=this._sheetsThreadCommentModel.getComment(t,n,r);i&&!this._hasCommentPermission(t,n,i.ref)&&this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-thread-comment-ui.permission.commentErr`))}}))}_hasCommentPermission(e,t,n){let i={workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission]},o=(0,a.deserializeThreadCommentAnchor)(n);if((o==null?void 0:o.kind)===a.ThreadCommentAnchorKind.SHEET_DRAWING)return this._sheetPermissionCheckController.permissionCheckWithoutRange(i,e,t);let{row:s,column:c}=(0,f.singleReferenceToGrid)(n);return!Number.isFinite(s)||!Number.isFinite(c)?!1:this._sheetPermissionCheckController.permissionCheckWithRanges({...i,rangeTypes:[r.RangeProtectionPermissionViewPoint]},[{startRow:s,startColumn:c,endRow:s,endColumn:c}],e,t)}};K=S([x(0,(0,t.Inject)(t.LocaleService)),x(1,t.ICommandService),x(2,(0,t.Inject)(r.SheetPermissionCheckController)),x(3,(0,t.Inject)(i.SheetsThreadCommentModel))],K);let q=class extends t.Plugin{constructor(e=L,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},L,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(I,o)}onStarting(){[[H],[U],[W],[G],[C],[K],[P]].forEach(e=>this._injector.add(e)),this._injector.get(H),[O,E,F,T].forEach(e=>this._commandService.registerCommand(e)),this._injector.get(U)}onReady(){this._injector.get(W)}onRendered(){this._injector.get(G),this._injector.get(K)}};b(q,`pluginName`,_),b(q,`packageName`,ne),b(q,`version`,re),b(q,`type`,t.UniverInstanceType.UNIVER_SHEET),q=S([(0,t.DependentOn)(u.UniverRenderEnginePlugin,a.UniverThreadCommentPlugin,r.UniverSheetsPlugin,o.UniverThreadCommentMobileUIPlugin,i.UniverSheetsThreadCommentPlugin,s.UniverMobileUIPlugin,c.UniverSheetsMobileUIPlugin),x(1,(0,t.Inject)(t.Injector)),x(2,(0,t.Inject)(t.ICommandService)),x(3,t.IConfigService)],q);let ye=()=>{let e=(0,s.useDependency)(t.IUniverInstanceService),n=(0,s.useDependency)(C),r=(0,s.useObservable)(n.activePopup$),a=(0,s.useDependency)(i.SheetsThreadCommentModel),c=()=>{if(!r)return;let{unitId:e,subUnitId:t,row:n,col:i,commentId:o}=r,s=o?a.getAllByLocation(e,t,n,i).find(e=>e.id===o):void 0;return s&&!s.resolved?s.id:a.getByLocation(e,t,n,i)},u=(0,s.useObservable)(r?()=>a.commentUpdate$.pipe((0,l.map)(()=>c()),(0,l.startWith)(c())):null,void 0,!1,[r,a]);if(!r)return null;let{row:d,col:f,unitId:m,subUnitId:h,trigger:g}=r,_=`${t.Tools.chatAtABC(f)}${d+1}`;return/* @__PURE__ */ (0,p.jsx)(o.ThreadCommentTree,{onClick:()=>{n.persistPopup()},location:o.ThreadCommentTreeLocation.CELL,id:u,unitId:m,subUnitId:h,type:t.UniverInstanceType.UNIVER_SHEET,refStr:_,onClose:()=>{n.hidePopup()},getSubUnitName:n=>{var r;return((r=e.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET))==null||(r=r.getSheetBySheetId(n))==null?void 0:r.getName())??``},autoFocus:g===`context-menu`})},J=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[m,ye],[h,V]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({CommentIcon:z,InsertCommentDoubleIcon:B}))}};J=S([x(0,(0,t.Inject)(s.ComponentManager)),x(1,(0,t.Inject)(s.IconManager))],J);let Y=class extends t.RxDisposable{constructor(e,n,r,i,a,s){super(),this._context=e,this._commandService=n,this._drawingManagerService=r,this._commentModel=i,this._panelService=a,this._themeService=s,b(this,`_overlay`,void 0),this._overlay=new o.ThreadCommentCanvasOverlay(`sheet-thread-comment-drawing-overlay`,{...this._getColors(),zoomRatio:1,markers:[],underlines:[]}),this._context.scene.addObject(this._overlay,10100),this.disposeWithMe((0,t.toDisposable)(this._overlay.onPointerDown$.subscribeEvent((e,t)=>this._onOverlayPointerDown(t)))),this.disposeWithMe((0,t.toDisposable)(this._context.engine.onTransformChange$.subscribeEvent(()=>this._syncOverlay()))),this.disposeWithMe(this._context.unit.activeSheet$.subscribe(()=>this._syncOverlay())),this.disposeWithMe(this._commentModel.commentUpdate$.subscribe(e=>{e.unitId===this._context.unitId&&this._syncOverlay()})),[this._panelService.activeCommentId$,this._panelService.hoveredCommentId$].forEach(e=>this.disposeWithMe(e.subscribe(()=>this._syncOverlay()))),[this._drawingManagerService.add$,this._drawingManagerService.update$,this._drawingManagerService.remove$].forEach(e=>this.disposeWithMe(e.subscribe(e=>{e.some(e=>e.unitId===this._context.unitId)&&this._syncOverlay()}))),this.disposeWithMe(this._themeService.currentTheme$.subscribe(()=>this._syncOverlay())),this._syncOverlay()}_onOverlayPointerDown(e){var t;let n=this._overlay.hitCommentId,r=(t=this._context.unit.getActiveSheet())==null?void 0:t.getSheetId();n&&r&&(e.stopPropagation(),this._panelService.setActiveComment({unitId:this._context.unitId,subUnitId:r,commentId:n,trigger:`sheet-canvas`}),this._commandService.executeCommand(E.id).catch(()=>void 0))}_syncOverlay(){let e=this._context.unit.getActiveSheet(),t=e==null?void 0:e.getSheetId();if(!e||!t){this._overlay.updateState({markers:[],underlines:[],focusedCommentIds:[],focusOutlines:[]});return}let n=/* @__PURE__ */ new Map;this._commentModel.query({unitIds:[this._context.unitId],subUnitIds:[t],anchorKinds:[a.ThreadCommentAnchorKind.SHEET_DRAWING],resolved:!1}).forEach(({root:r})=>{let i=(0,a.deserializeThreadCommentAnchor)(r.ref);if((i==null?void 0:i.kind)!==a.ThreadCommentAnchorKind.SHEET_DRAWING)return;let o=this._getDrawingOutline(t,i.elementId);o&&n.set(i.elementId,{commentId:r.id,left:o.left,top:o.top+o.height+2/e.getZoomRatio(),width:o.width})});let r=[],i=/* @__PURE__ */ new Map;[this._panelService.activeCommentId,this._panelService.hoveredCommentId].forEach(e=>{if(!e||e.unitId!==this._context.unitId||e.subUnitId!==t)return;let n=this._commentModel.getComment(e.unitId,e.subUnitId,e.commentId),o=n&&(0,a.deserializeThreadCommentAnchor)(n.ref);if((o==null?void 0:o.kind)!==a.ThreadCommentAnchorKind.SHEET_DRAWING)return;r.push(e.commentId);let s=this._getDrawingOutline(t,o.elementId);s&&i.set(o.elementId,s)}),this._overlay.updateState({...this._getColors(),zoomRatio:e.getZoomRatio(),markers:[],underlines:Array.from(n.values()),focusedCommentIds:r,focusOutlines:Array.from(i.values())})}_getDrawingOutline(e,t){var r,i;let a=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:this._context.unitId,subUnitId:e,drawingId:t}),o=((r=(i=this._context.scene).getObjectIncludeInGroup)==null?void 0:r.call(i,a))??this._context.scene.getObject(a);if(!o)return null;let s=o.getRealBound();return{left:s.left,top:s.top,width:s.width,height:s.height}}_getColors(){return{accentColor:this._themeService.getColorFromTheme(`yellow.400`),foregroundColor:this._themeService.getColorFromTheme(`gray.900`),outlineColor:this._themeService.getColorFromTheme(`white`)}}};Y=S([x(1,t.ICommandService),x(2,n.IDrawingManagerService),x(3,(0,t.Inject)(a.ThreadCommentModel)),x(4,(0,t.Inject)(o.ThreadCommentPanelService)),x(5,(0,t.Inject)(t.ThemeService))],Y);let X=class extends t.Disposable{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((0,l.debounceTime)(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){let{location:n}=e,{unitId:i,subUnitId:a,row:o,col:s}=n,c=this._sheetsThreadCommentModel.getByLocation(i,a,o,s);if(c){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]},[{startRow:o,startColumn:s,endRow:o,endColumn:s}],i,a))return;let e=this._sheetsThreadCommentModel.getComment(i,a,c);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:i,subUnitId:a,row:o,col:s,commentId:c,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};X=S([x(0,(0,t.Inject)(c.HoverManagerService)),x(1,(0,t.Inject)(C)),x(2,(0,t.Inject)(i.SheetsThreadCommentModel)),x(3,(0,t.Inject)(r.SheetPermissionCheckController))],X);function be(e,t,n,r){for(let i of[t,e])if(i&&i.unitId===n&&i.subUnitId===r)return i}let Z=class extends t.Disposable{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,b(this,`_isSwitchToCommenting`,!1),b(this,`_selectionShapeInfo`,null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,n,r){var i,a;let s=(i=e[0])==null?void 0:i.range,l=this._renderManagerService.getRenderUnitById(n),u=l==null||(a=l.with(c.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:a.skeleton;if(!u||!s)return;let d=u.getCellWithCoordByIndex(s.startRow,s.startColumn);if(((s.rangeType??t.RANGE_TYPE.NORMAL)!==t.RANGE_TYPE.NORMAL||s.endColumn-s.startColumn>0||s.endRow-s.startRow>0)&&!((d.isMerged||d.isMergedMainCell)&&t.Rectangle.equals(d.mergeInfo,s))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(o.SetActiveCommentOperation.id);return}let f=d.actualRow,p=d.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(n,r,f,p)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(o.SetActiveCommentOperation.id);return}let m=this._sheetsThreadCommentModel.getByLocation(n,r,f,p);m&&this._commandService.executeCommand(o.SetActiveCommentOperation.id,{unitId:n,subUnitId:r,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===a.DeleteCommentMutation.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 n;let{unitId:i,subUnitId:o,commentId:s,trigger:l}=e,u=this._sheetsThreadCommentModel.getComment(i,o,s);if(!u||u.resolved)return;let d=(0,a.deserializeThreadCommentAnchor)(u.ref);if((d==null?void 0:d.kind)===a.ThreadCommentAnchorKind.SHEET_DRAWING)return;let p=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!p||p.getUnitId()!==i)return;this._isSwitchToCommenting=!0,((n=p.getActiveSheet())==null?void 0:n.getSheetId())!==o&&await this._commandService.executeCommand(r.SetWorksheetActiveOperation.id,{unitId:i,subUnitId:o}),this._isSwitchToCommenting=!1;let m=(0,f.singleReferenceToGrid)(u.ref),{row:h,column:g}=m;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]},[{startRow:h,startColumn:g,endRow:h,endColumn:g}],i,o)||(await this._commandService.executeCommand(c.ScrollToRangeOperation.id,{range:{startRow:Math.max(m.row-1,0),endRow:m.row+1,startColumn:Math.max(m.column-1,0),endColumn:m.column+1}}),this._editorBridgeService.isVisible().visible))return;this._sheetsThreadCommentPopupService.showPopup({unitId:i,subUnitId:o,row:m.row,col:m.column,commentId:u.id,trigger:l})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe((0,l.combineLatest)([this._threadCommentPanelService.activeCommentId$,this._threadCommentPanelService.hoveredCommentId$]).pipe((0,l.debounceTime)(100)).subscribe(([e,n])=>{var r,i;let a=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),o=be(e,n,a==null?void 0:a.getUnitId(),a==null||(r=a.getActiveSheet())==null?void 0:r.getSheetId());if(!o){this._selectionShapeInfo&&=(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),null);return}let{unitId:s,subUnitId:c,commentId:l}=o;this._selectionShapeInfo&&=(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),null);let u=this._sheetsThreadCommentModel.getComment(s,c,l);if(!u)return;let{row:d,column:p}=(0,f.singleReferenceToGrid)(u.ref);if(Number.isNaN(d)||Number.isNaN(p))return null;let m=(i=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetId(c),h=(m==null?void 0:m.getMergedCell(d,p))??{startColumn:p,endColumn:p,startRow:d,endRow:d},g=this._markSelectionService.addShape({range:h,style:{fill:`rgba(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1);g&&(this._selectionShapeInfo={...o,shapeId:g})}))}};Z=S([x(0,t.ICommandService),x(1,(0,t.Inject)(C)),x(2,(0,t.Inject)(i.SheetsThreadCommentModel)),x(3,(0,t.Inject)(o.ThreadCommentPanelService)),x(4,t.IUniverInstanceService),x(5,(0,t.Inject)(r.SheetPermissionCheckController)),x(6,c.IMarkSelectionService),x(7,(0,t.Inject)(r.SheetsSelectionsService)),x(8,c.IEditorBridgeService),x(9,u.IRenderManagerService)],Z);let Q=class extends t.Disposable{constructor(e,t){super(),this._menuManagerService=e,this._shortcutService=t,this._initMenu(),this._initShortcut()}_initShortcut(){this._shortcutService.registerShortcut(N)}_initMenu(){this._menuManagerService.mergeMenu(te)}};Q=S([x(0,s.IMenuManagerService),x(1,s.IShortcutService)],Q);let $=class extends t.Plugin{constructor(e=L,n,r,i,a){super(),this._config=e,this._injector=n,this._commandService=r,this._renderManagerService=i,this._configService=a;let{menu:o,...s}=(0,t.merge)({},L,this._config);o&&this._configService.setConfig(`menu`,o,{merge:!0}),this._configService.setConfig(I,s)}onStarting(){this._injector.add([J]),this._injector.get(J),[[Q],[W],[G],[X],[Z],[C],[K]].forEach(e=>{this._injector.add(e)}),[O,E,w,T].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(Q)}onReady(){this._injector.get(W)}onRendered(){this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,[Y]),this._injector.get(G),this._injector.get(X),this._injector.get(Z),this._injector.get(K)}};b($,`pluginName`,_),b($,`packageName`,ne),b($,`version`,re),b($,`type`,t.UniverInstanceType.UNIVER_SHEET),$=S([(0,t.DependentOn)(u.UniverRenderEnginePlugin,a.UniverThreadCommentPlugin,n.UniverDrawingPlugin,r.UniverSheetsPlugin,o.UniverThreadCommentUIPlugin,i.UniverSheetsThreadCommentPlugin,c.UniverSheetsUIPlugin),x(1,(0,t.Inject)(t.Injector)),x(2,(0,t.Inject)(t.ICommandService)),x(3,u.IRenderManagerService),x(4,t.IConfigService)],$),Object.defineProperty(e,"SheetsThreadCommentPopupService",{enumerable:!0,get:function(){return C}}),e.SheetsThreadCommentUIMenuSchema=te,e.ShowAddSheetCommentModalOperation=w,e.ToggleSheetCommentPanelOperation=T,Object.defineProperty(e,"UniverSheetsThreadCommentMobileUIPlugin",{enumerable:!0,get:function(){return q}}),Object.defineProperty(e,"UniverSheetsThreadCommentUIPlugin",{enumerable:!0,get:function(){return $}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-thread-comment"),require("@univerjs/thread-comment"),require("@univerjs/thread-comment-ui"),require("@univerjs/ui"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/engine-formula"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-thread-comment`,`@univerjs/thread-comment`,`@univerjs/thread-comment-ui`,`@univerjs/ui`,`@univerjs/sheets-ui`,`rxjs`,`@univerjs/engine-render`,`react`,`@univerjs/engine-formula`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsThreadCommentUi={},e.UniverCore,e.UniverDrawing,e.UniverSheets,e.UniverSheetsThreadComment,e.UniverThreadComment,e.UniverThreadCommentUi,e.UniverUi,e.UniverSheetsUi,e.rxjs,e.UniverEngineRender,e.React,e.UniverEngineFormula,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let m=`univer.sheet.thread-comment-modal`,h=`univer.sheet.thread-comment-panel`,g=`sheet.operation.show-comment-modal`,_=`SHEET_THREAD_COMMENT_UI_PLUGIN`;function v(e){"@babel/helpers - typeof";return v=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},v(e)}function y(e,t){if(v(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(v(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ee(e){var t=y(e,`string`);return v(t)==`symbol`?t:t+``}function b(e,t,n){return(t=ee(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function x(e,t){return function(n,r){t(n,r,e)}}function S(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 C=class extends t.Disposable{get activePopup(){return this._activePopup}constructor(e,t){super(),this._canvasPopupManagerService=e,this._cellPopupManagerService=t,b(this,`_lastPopup`,null),b(this,`_activePopup`,void 0),b(this,`_activePopup$`,new l.BehaviorSubject(null)),b(this,`activePopup$`,this._activePopup$.asObservable()),this.disposeWithMe(()=>{this._activePopup$.complete()})}dispose(){super.dispose(),this.hidePopup()}showPopup(e,n){var r;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===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}this._lastPopup&&this._lastPopup.dispose(),this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey:m,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 t.DisposableCollection;l.add(c),l.add({dispose:()=>{n==null||n()}}),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))}};C=S([x(0,(0,t.Inject)(c.SheetCanvasPopManagerService)),x(1,(0,t.Inject)(c.CellPopupManagerService))],C);let w={type:t.CommandType.OPERATION,id:g,handler(e){var n;let a=e.get(r.SheetsSelectionsService),s=e.get(t.IUniverInstanceService),c=e.get(C),l=e.get(o.ThreadCommentPanelService),u=(n=a.getCurrentLastSelection())==null?void 0:n.primary,d=e.get(i.SheetsThreadCommentModel);if(!u)return!1;let f=(0,r.getSheetCommandTarget)(s);if(!f)return!1;let{workbook:p,worksheet:m,unitId:h,subUnitId:g}=f,_={workbook:p,worksheet:m,unitId:h,subUnitId:g,row:u.startRow,col:u.startColumn};c.showPopup(_);let v=d.getByLocation(h,g,u.startRow,u.startColumn);return v&&l.setActiveComment({unitId:h,subUnitId:g,commentId:v,trigger:`context-menu`}),!0}},T={id:`sheet.operation.toggle-comment-panel`,type:t.CommandType.OPERATION,handler(e){let t=e.get(s.ISidebarService),n=e.get(o.ThreadCommentPanelService);return n.panelVisible?(t.close(),n.setPanelVisible(!1)):D(t,n),!0}},E={id:`sheet.operation.open-comment-panel`,type:t.CommandType.OPERATION,handler(e){return D(e.get(s.ISidebarService),e.get(o.ThreadCommentPanelService)),!0}};function D(e,t){var n;t.panelVisible&&((n=e.options.children)==null?void 0:n.label)===`univer.sheet.thread-comment-panel`||e.open({header:{title:`sheets-thread-comment-ui.panel.title`},children:{label:h},width:360,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)}let O={id:`sheet.operation.add-drawing-comment`,type:t.CommandType.OPERATION,handler(e){var r;let i=e.get(n.IDrawingManagerService).getFocusDrawings()[0],c=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!i||!c||i.unitId!==c.getUnitId()||i.subUnitId!==((r=c.getActiveSheet())==null?void 0:r.getSheetId()))return!1;e.get(o.ThreadCommentDraftService).place({unitId:i.unitId,subUnitId:i.subUnitId,anchor:{kind:a.ThreadCommentAnchorKind.SHEET_DRAWING,pageId:i.subUnitId,elementId:i.drawingId}});let l=e.get(o.ThreadCommentPanelService);return e.get(s.ISidebarService).open({header:{title:`sheets-thread-comment-ui.panel.title`},children:{label:h},width:360,onClose:()=>l.setPanelVisible(!1)}),l.setPanelVisible(!0),!0}};function te(e){let n=e.get(t.IUniverInstanceService),i=e.get(t.IPermissionService);return(0,c.deriveStateFromActiveSheet$)(n,!0,({workbook:e,worksheet:t})=>{let n=e.getUnitId(),a=t.getSheetId();return i.composePermission$([new r.WorkbookCommentPermission(n).id,new r.WorksheetViewPermission(n,a).id]).pipe((0,l.map)(e=>e.some(e=>e.value===!1)))})}let k=e=>({id:O.id,type:s.MenuItemType.BUTTON,icon:`InsertCommentDoubleIcon`,title:`sheets-thread-comment-ui.menu.addComment`,tooltip:`sheets-thread-comment-ui.menu.addComment`,hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:te(e)}),A=e=>({id:w.id,type:s.MenuItemType.BUTTON,icon:`InsertCommentDoubleIcon`,title:`sheets-thread-comment-ui.menu.addComment`,tooltip:`sheets-thread-comment-ui.menu.addComment`,hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]})}),j=e=>{let n=e.get(s.ISidebarService);return{activated$:(0,l.defer)(()=>n.sidebarOptions$.pipe((0,l.startWith)(n.options),(0,l.map)(e=>{var t;return e.visible===!0&&((t=e.children)==null?void 0:t.label)===`univer.sheet.thread-comment-panel`}),(0,l.distinctUntilChanged)())),id:T.id,type:s.MenuItemType.BUTTON,icon:`CommentIcon`,title:`sheets-thread-comment-ui.menu.openComments`,tooltip:`sheets-thread-comment-ui.menu.openComments`,disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookViewPermission],worksheetTypes:[r.WorksheetViewPermission]}),hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}},ne={id:w.id,binding:s.KeyCode.M|s.MetaKeys.CTRL_COMMAND|s.MetaKeys.ALT,preconditions:c.whenSheetEditorFocused},M={[s.RibbonInsertGroup.MEDIA]:{[T.id]:{order:2,gridLayout:{row:1,column:3,showLabel:!0},menuItemFactory:j},[w.id]:{order:2.1,gridLayout:{row:2,column:3,showLabel:!0},menuItemFactory:A}},[s.ContextMenuPosition.MAIN_AREA]:{[s.ContextMenuGroup.OTHERS]:{[w.id]:{order:0,menuItemFactory:A}}},[s.FloatingObjectToolbarPosition.SHEET]:{[O.id]:{order:10,menuItemFactory:k}},[s.ContextMenuPosition.DRAWING]:{[s.ContextMenuGroup.OTHERS]:{[O.id]:{order:0,menuItemFactory:k}}}};var N=`@univerjs/sheets-thread-comment-ui`,re=`1.6.0`,P=class extends t.Disposable{constructor(){super(),b(this,`_draft$`,new l.BehaviorSubject(null)),b(this,`draft$`,this._draft$.asObservable()),this.disposeWithMe(()=>this._draft$.complete())}get draft(){return this._draft$.getValue()}place(e){this._draft$.next(e)}cancel(){this._draft$.next(null)}};let F={type:t.CommandType.OPERATION,id:g,handler(e){var n;let a=(n=e.get(r.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:n.primary;if(!a)return!1;let c=(0,r.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=a.startRow,f=a.startColumn,p=e.get(o.ThreadCommentPanelService),m=e.get(P),h=e.get(i.SheetsThreadCommentModel).getByLocation(l,u,d,f);return e.get(o.ThreadCommentDraftService).cancel(),h?(m.cancel(),p.setActiveComment({unitId:l,subUnitId:u,commentId:h})):(p.setActiveComment(void 0),m.place({unitId:l,subUnitId:u,row:d,column:f})),D(e.get(s.ISidebarService),p),!0}},ie=`sheets-thread-comment.config`,I={};function L({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=`_${(0,d.useId)()}`,u=(0,d.useRef)(null);return(0,d.useImperativeHandle)(e,()=>u.current),(0,d.useLayoutEffect)(()=>{if(n&&u.current&&u.current.localName===r.tag)return se(u.current)},[n,r]),R(r,`${i}`,{defIds:r.defIds,idSuffix:l},{ref:u,className:c,...s},o)}function R(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...ae(e,n,i),...r},(oe(e,n).children||[]).map((r,a)=>R(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ae(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0||(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function oe(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function se(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:ce(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=e.element.style.getPropertyValue(`stroke-width`)})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(le(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function ce(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function le(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}L.displayName=`UniverIcon`;let ue={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 17`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.43993 3.31861H15.0381V12.5611H8.65676L5.75498 14.069V12.5611H2.43993V3.31861Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M5.83725 7.50706V8.41159M8.73904 7.50706V8.41159M11.6408 7.50706V8.41159`,strokeLinecap:`round`,strokeWidth:1.39}}]},z=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(L,Object.assign({},e,{id:`comment-icon`,ref:t,icon:ue}))});z.displayName=`CommentIcon`;let de={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.63636 1.99658C1.28491 1.99658 1 2.28149 1 2.63295V10.2693C1 10.6208 1.28491 10.9057 1.63636 10.9057H2.96368L4.05003 11.992C4.29854 12.2405 4.70146 12.2405 4.94997 11.992L6.03632 10.9057H6.72727V12.4128C6.72727 12.7643 7.01218 13.0492 7.36364 13.0492H10.6001L11.3682 13.8173C11.6167 14.0658 12.0196 14.0658 12.2682 13.8173L13.0363 13.0492H14.3636C14.7151 13.0492 15 12.7643 15 12.4128V7.32192C15 6.97047 14.7151 6.68556 14.3636 6.68556H12.4545V2.63295C12.4545 2.28149 12.1696 1.99658 11.8182 1.99658H1.63636ZM12.4545 7.95829V10.2693C12.4545 10.6208 12.1696 10.9057 11.8182 10.9057H8V11.7765H10.8636C11.0324 11.7765 11.1942 11.8435 11.3136 11.9628L11.8182 12.4674L12.3228 11.9628C12.4421 11.8435 12.604 11.7765 12.7727 11.7765H13.7273V7.95829H12.4545ZM11.1818 3.26931H2.27273V9.63295H3.22727C3.39604 9.63295 3.5579 9.70001 3.67725 9.81936L4.5 10.6421L5.32275 9.81936C5.4421 9.70001 5.60396 9.63295 5.77273 9.63295H11.1818V3.26931Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`colorChannel1`,d:`M5.13617 4.54199C4.78472 4.54199 4.49981 4.8269 4.49981 5.17836C4.49981 5.52981 4.78472 5.81472 5.13617 5.81472H8.95435C9.3058 5.81472 9.59072 5.52981 9.59072 5.17836C9.59072 4.8269 9.3058 4.54199 8.95435 4.54199H5.13617ZM4.49981 7.72381C4.49981 7.37236 4.78472 7.08744 5.13617 7.08744H7.04526C7.39671 7.08744 7.68162 7.37236 7.68162 7.72381C7.68162 8.07526 7.39671 8.36018 7.04526 8.36018H5.13617C4.78472 8.36018 4.49981 8.07526 4.49981 7.72381Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},B=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(L,Object.assign({},e,{id:`insert-comment-double-icon`,ref:t,icon:de}))});B.displayName=`InsertCommentDoubleIcon`;let V=({ThreadCommentPanelComponent:e=o.ThreadCommentPanel}={})=>{var n;let r=(0,s.useDependency)(c.IMarkSelectionService),i=(0,s.useDependency)(t.IUniverInstanceService),u=(0,s.useDependency)(C),m=i.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),h=m.getUnitId(),g=(0,s.useDependency)(t.ICommandService),_=(0,s.useDependency)(o.ThreadCommentDraftService),v=(0,s.useDependency)(t.UserManagerService),y=(0,s.useObservable)(_.draft$,_.draft),ee=(y==null?void 0:y.anchor.kind)===a.ThreadCommentAnchorKind.SHEET_DRAWING&&y.unitId===h?{id:``,threadId:``,unitId:y.unitId,subUnitId:y.subUnitId,ref:(0,a.serializeThreadCommentAnchor)(y.anchor),dT:``,personId:v.getCurrentUser().userID,text:{dataStream:`\r
|
|
2
|
+
`}}:null,b=(0,d.useMemo)(()=>m.activeSheet$.pipe((0,l.map)(e=>e==null?void 0:e.getSheetId())),[m.activeSheet$]),x=(0,s.useObservable)(b,(n=m.getActiveSheet())==null?void 0:n.getSheetId()),S=(0,s.useDependency)(a.IThreadCommentAuthzService),T=(0,d.useRef)(null),E=(0,s.useDependency)(o.ThreadCommentPanelService),D=(0,s.useObservable)(E.activeCommentId$),O=(0,s.useObservable)(E.panelVisible$,E.panelVisible),te=(0,d.useCallback)(e=>{let t=m.getSheets(),n={};t.forEach((e,t)=>{n[e.getSheetId()]=t});let r=e=>e.map(e=>{let t=(0,a.deserializeThreadCommentAnchor)(e.ref);if((t==null?void 0:t.kind)===a.ThreadCommentAnchorKind.SHEET_DRAWING)return{...e,p:[n[e.subUnitId]??0,2**53-1,0]};let r=(0,f.singleReferenceToGrid)(e.ref),i=[n[e.subUnitId]??0,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))]},[m]),k=(0,d.useCallback)(e=>{if((0,a.deserializeThreadCommentAnchor)(e.ref))return null;if(e.unitId===h&&e.subUnitId===x&&!e.resolved){let{row:t,column:n}=(0,f.singleReferenceToGrid)(e.ref),i=m.getSheetBySheetId(e.subUnitId),a=(i==null?void 0:i.getMergedCell(t,n))??{startColumn:n,endColumn:n,startRow:t,endRow:t};if(!Number.isNaN(t)&&!Number.isNaN(n))return r.addShape({range:a,style:{fill:`rgb(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null})}return null},[r,x,h]),A=e=>{var t;return((t=m.getSheetBySheetId(e))==null?void 0:t.getName())??``},j=()=>{g.executeCommand(w.id)},ne=(0,d.useCallback)(e=>S.canRead(e),[S]),M=e=>{T.current&&=(r.removeShape(T.current),null),D&&D.unitId===e.unitId&&D.subUnitId===e.subUnitId&&D.commentId===e.id||(T.current=k(e))},N=()=>{T.current&&=(r.removeShape(T.current),null)};return(0,d.useEffect)(()=>{!O&&T.current&&(r.removeShape(T.current),T.current=null)},[r,O]),/* @__PURE__ */ (0,p.jsx)(e,{unitId:h,subUnitId$:b,type:t.UniverInstanceType.UNIVER_SHEET,onAdd:j,disableAdd:!S.canWrite(`add`,{unitId:h,subUnitId:x??``,ref:``}),filterComment:ne,getSubUnitName:A,onResolve:(e,t)=>{t&&u.hidePopup()},sortComments:te,onItemEnter:M,onItemLeave:N,onDeleteComment:()=>(N(),!0),tempComment:ee,onTempCommentClose:()=>_.cancel(),formatRef:e=>{let t=(0,a.deserializeThreadCommentAnchor)(e.ref);return(t==null?void 0:t.kind)===a.ThreadCommentAnchorKind.SHEET_DRAWING?`#${t.elementId}`:e.ref}})};function fe(e){let n=(0,s.useDependency)(P),r=(0,s.useDependency)(t.UserManagerService),i=(0,s.useObservable)(n.draft$,n.draft),a=(i==null?void 0:i.unitId)===e.unitId?{id:``,threadId:``,unitId:i.unitId,subUnitId:i.subUnitId,ref:`${t.Tools.chatAtABC(i.column)}${i.row+1}`,dT:``,personId:r.getCurrentUser().userID,text:{dataStream:`\r
|
|
3
|
+
`}}:null,c=()=>{var t;n.cancel(),(t=e.onTempCommentClose)==null||t.call(e)};return/* @__PURE__ */ (0,p.jsx)(o.MobileThreadCommentPanel,{...e,tempComment:e.tempComment??a,onTempCommentClose:c,autoFocusActiveComment:!0})}function pe(){return/* @__PURE__ */ (0,p.jsx)(V,{ThreadCommentPanelComponent:fe})}let H=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this.disposeWithMe(this._componentManager.register(h,pe)),this.disposeWithMe(this._iconManager.register({CommentIcon:z,InsertCommentDoubleIcon:B}))}};H=S([x(0,(0,t.Inject)(s.ComponentManager)),x(1,(0,t.Inject)(s.IconManager))],H);function me(e){var t;let n=e.get(r.SheetsSelectionsService),a=(t=n.getCurrentLastSelection())==null?void 0:t.primary,o=n.currentSelectionParam;return!a||!o?`sheets-thread-comment-ui.menu.addComment`:e.get(i.SheetsThreadCommentModel).getByLocation(o.unitId,o.sheetId,a.startRow,a.startColumn)?`sheets-thread-comment-ui.menu.openComments`:`sheets-thread-comment-ui.menu.addComment`}let he=e=>({id:F.id,type:s.MenuItemType.BUTTON,icon:`InsertCommentDoubleIcon`,title:`sheets-thread-comment-ui.menu.addComment`,hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookCommentPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]})}),ge=e=>({...he(e),title:me(e)}),_e={[s.RibbonInsertGroup.MEDIA]:{[T.id]:{order:2,gridLayout:{row:1,column:3,showLabel:!0},menuItemFactory:j},[F.id]:{order:2.1,gridLayout:{row:2,column:3,showLabel:!0},menuItemFactory:he}},[s.ContextMenuPosition.MAIN_AREA]:{[s.ContextMenuGroup.OTHERS]:{[F.id]:{order:0,menuItemFactory:ge}}},[s.FloatingObjectToolbarPosition.SHEET]:{[O.id]:{order:10,menuItemFactory:k}},[s.ContextMenuPosition.DRAWING]:{[s.ContextMenuGroup.OTHERS]:{[O.id]:{order:0,menuItemFactory:k}}}},U=class extends t.Disposable{constructor(e){super(),e.mergeMenu(_e)}};U=S([x(0,s.IMenuManagerService)],U);let W=class extends t.Disposable{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(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.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)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderUnitById(r);i==null||(e=i.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe((0,l.debounceTime)(16)).subscribe(()=>{e()}))}};W=S([x(0,(0,t.Inject)(r.SheetInterceptorService)),x(1,(0,t.Inject)(i.SheetsThreadCommentModel)),x(2,t.IUniverInstanceService),x(3,u.IRenderManagerService)],W);let ve=(e,t,n)=>{let r=(0,f.singleReferenceToGrid)(e),i=n.row-t.row,a=n.column-t.column,o={startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i};return(0,f.serializeRange)(o)},G=class extends t.Disposable{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=n,b(this,`_copyInfo`,void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:_,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,n,r,i)=>{let{unitId:o,subUnitId:s,range:l}=n,u={row:l.rows[0],column:l.cols[0]};if(i.copyType===c.COPY_TYPE.CUT&&this._copyInfo){let{range:e,unitId:n,subUnitId:r}=this._copyInfo,i={row:e.startRow,column:e.startColumn};if(o!==n||s!==r){let c=[];t.Range.foreach(e,(e,t)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(n,r,e,t);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{c.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||c.push(t)})});let l=[],d=[],f=[],p=[],m=e=>{l.unshift({id:a.DeleteCommentMutation.id,params:{unitId:n,subUnitId:r,commentId:e.id}}),f.push({id:a.AddCommentMutation.id,params:{unitId:o,subUnitId:s,comment:{...e,ref:ve(e.ref,i,u),unitId:o,subUnitId:s},sync:!0}}),d.push({id:a.AddCommentMutation.id,params:{unitId:n,subUnitId:r,comment:e,sync:!0}}),p.unshift({id:a.DeleteCommentMutation.id,params:{unitId:o,subUnitId:s,commentId:e.id}})};return c.forEach(e=>{m(e)}),{redos:[...l,...f],undos:[...p,...d]}}}return{redos:[],undos:[]}}}))}};G=S([x(0,(0,t.Inject)(c.ISheetClipboardService)),x(1,(0,t.Inject)(i.SheetsThreadCommentModel)),x(2,a.IThreadCommentDataSourceService)],G);let K=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._authzService=r,this._univerInstanceService=i,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let{id:t}=e;t===w.id||t===O.id?this._authzService.canWrite(`add`,this._getTarget())||this._block():t===T.id&&(this._authzService.canRead(this._getTarget())||this._block())}))}_getTarget(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);return{unitId:(e==null?void 0:e.getUnitId())??``,subUnitId:(e==null?void 0:e.getActiveSheet().getSheetId())??``,ref:``}}_block(){this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-thread-comment-ui.permission.commentErr`))}};K=S([x(0,(0,t.Inject)(t.LocaleService)),x(1,t.ICommandService),x(2,(0,t.Inject)(r.SheetPermissionCheckController)),x(3,(0,t.Inject)(a.IThreadCommentAuthzService)),x(4,(0,t.Inject)(t.IUniverInstanceService))],K);let q=class extends t.Plugin{constructor(e=I,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},I,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(ie,o)}onStarting(){[[H],[U],[W],[G],[C],[K],[P]].forEach(e=>this._injector.add(e)),this._injector.get(H),[O,E,F,T].forEach(e=>this._commandService.registerCommand(e)),this._injector.get(U)}onReady(){this._injector.get(W)}onRendered(){this._injector.get(G),this._injector.get(K)}};b(q,`pluginName`,_),b(q,`packageName`,N),b(q,`version`,re),b(q,`type`,t.UniverInstanceType.UNIVER_SHEET),q=S([(0,t.DependentOn)(u.UniverRenderEnginePlugin,a.UniverThreadCommentPlugin,r.UniverSheetsPlugin,o.UniverThreadCommentMobileUIPlugin,i.UniverSheetsThreadCommentPlugin,s.UniverMobileUIPlugin,c.UniverSheetsMobileUIPlugin),x(1,(0,t.Inject)(t.Injector)),x(2,(0,t.Inject)(t.ICommandService)),x(3,t.IConfigService)],q);let ye=()=>{let e=(0,s.useDependency)(t.IUniverInstanceService),n=(0,s.useDependency)(C),r=(0,s.useObservable)(n.activePopup$),a=(0,s.useDependency)(i.SheetsThreadCommentModel),c=()=>{if(!r)return;let{unitId:e,subUnitId:t,row:n,col:i,commentId:o}=r,s=o?a.getAllByLocation(e,t,n,i).find(e=>e.id===o):void 0;return s&&!s.resolved?s.id:a.getByLocation(e,t,n,i)},u=(0,s.useObservable)(r?()=>a.commentUpdate$.pipe((0,l.map)(()=>c()),(0,l.startWith)(c())):null,void 0,!1,[r,a]);if(!r)return null;let{row:d,col:f,unitId:m,subUnitId:h,trigger:g}=r,_=`${t.Tools.chatAtABC(f)}${d+1}`;return/* @__PURE__ */ (0,p.jsx)(o.ThreadCommentTree,{onClick:()=>{n.persistPopup()},location:o.ThreadCommentTreeLocation.CELL,id:u,unitId:m,subUnitId:h,type:t.UniverInstanceType.UNIVER_SHEET,refStr:_,onClose:()=>{n.hidePopup()},getSubUnitName:n=>{var r;return((r=e.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET))==null||(r=r.getSheetBySheetId(n))==null?void 0:r.getName())??``},autoFocus:g===`context-menu`})},J=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[m,ye],[h,V]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({CommentIcon:z,InsertCommentDoubleIcon:B}))}};J=S([x(0,(0,t.Inject)(s.ComponentManager)),x(1,(0,t.Inject)(s.IconManager))],J);let Y=class extends t.RxDisposable{constructor(e,n,r,i,a,s){super(),this._context=e,this._commandService=n,this._drawingManagerService=r,this._commentModel=i,this._panelService=a,this._themeService=s,b(this,`_overlay`,void 0),this._overlay=new o.ThreadCommentCanvasOverlay(`sheet-thread-comment-drawing-overlay`,{...this._getColors(),zoomRatio:1,markers:[],underlines:[]}),this._context.scene.addObject(this._overlay,10100),this.disposeWithMe((0,t.toDisposable)(this._overlay.onPointerDown$.subscribeEvent((e,t)=>this._onOverlayPointerDown(t)))),this.disposeWithMe((0,t.toDisposable)(this._context.engine.onTransformChange$.subscribeEvent(()=>this._syncOverlay()))),this.disposeWithMe(this._context.unit.activeSheet$.subscribe(()=>this._syncOverlay())),this.disposeWithMe(this._commentModel.commentUpdate$.subscribe(e=>{e.unitId===this._context.unitId&&this._syncOverlay()})),[this._panelService.activeCommentId$,this._panelService.hoveredCommentId$].forEach(e=>this.disposeWithMe(e.subscribe(()=>this._syncOverlay()))),[this._drawingManagerService.add$,this._drawingManagerService.update$,this._drawingManagerService.remove$].forEach(e=>this.disposeWithMe(e.subscribe(e=>{e.some(e=>e.unitId===this._context.unitId)&&this._syncOverlay()}))),this.disposeWithMe(this._themeService.currentTheme$.subscribe(()=>this._syncOverlay())),this._syncOverlay()}_onOverlayPointerDown(e){var t;let n=this._overlay.hitCommentId,r=(t=this._context.unit.getActiveSheet())==null?void 0:t.getSheetId();n&&r&&(e.stopPropagation(),this._panelService.setActiveComment({unitId:this._context.unitId,subUnitId:r,commentId:n,trigger:`sheet-canvas`}),this._commandService.executeCommand(E.id).catch(()=>void 0))}_syncOverlay(){let e=this._context.unit.getActiveSheet(),t=e==null?void 0:e.getSheetId();if(!e||!t){this._overlay.updateState({markers:[],underlines:[],focusedCommentIds:[],focusOutlines:[]});return}let n=/* @__PURE__ */ new Map;this._commentModel.query({unitIds:[this._context.unitId],subUnitIds:[t],anchorKinds:[a.ThreadCommentAnchorKind.SHEET_DRAWING],resolved:!1}).forEach(({root:r})=>{let i=(0,a.deserializeThreadCommentAnchor)(r.ref);if((i==null?void 0:i.kind)!==a.ThreadCommentAnchorKind.SHEET_DRAWING)return;let o=this._getDrawingOutline(t,i.elementId);o&&n.set(i.elementId,{commentId:r.id,left:o.left,top:o.top+o.height+2/e.getZoomRatio(),width:o.width})});let r=[],i=/* @__PURE__ */ new Map;[this._panelService.activeCommentId,this._panelService.hoveredCommentId].forEach(e=>{if(!e||e.unitId!==this._context.unitId||e.subUnitId!==t)return;let n=this._commentModel.getComment(e.unitId,e.subUnitId,e.commentId),o=n&&(0,a.deserializeThreadCommentAnchor)(n.ref);if((o==null?void 0:o.kind)!==a.ThreadCommentAnchorKind.SHEET_DRAWING)return;r.push(e.commentId);let s=this._getDrawingOutline(t,o.elementId);s&&i.set(o.elementId,s)}),this._overlay.updateState({...this._getColors(),zoomRatio:e.getZoomRatio(),markers:[],underlines:Array.from(n.values()),focusedCommentIds:r,focusOutlines:Array.from(i.values())})}_getDrawingOutline(e,t){var r,i;let a=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:this._context.unitId,subUnitId:e,drawingId:t}),o=((r=(i=this._context.scene).getObjectIncludeInGroup)==null?void 0:r.call(i,a))??this._context.scene.getObject(a);if(!o)return null;let s=o.getRealBound();return{left:s.left,top:s.top,width:s.width,height:s.height}}_getColors(){return{accentColor:this._themeService.getColorFromTheme(`yellow.400`),foregroundColor:this._themeService.getColorFromTheme(`gray.900`),outlineColor:this._themeService.getColorFromTheme(`white`)}}};Y=S([x(1,t.ICommandService),x(2,n.IDrawingManagerService),x(3,(0,t.Inject)(a.ThreadCommentModel)),x(4,(0,t.Inject)(o.ThreadCommentPanelService)),x(5,(0,t.Inject)(t.ThemeService))],Y);let X=class extends t.Disposable{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((0,l.debounceTime)(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){let{location:n}=e,{unitId:i,subUnitId:a,row:o,col:s}=n,c=this._sheetsThreadCommentModel.getByLocation(i,a,o,s);if(c){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookViewPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]},[{startRow:o,startColumn:s,endRow:o,endColumn:s}],i,a))return;let e=this._sheetsThreadCommentModel.getComment(i,a,c);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:i,subUnitId:a,row:o,col:s,commentId:c,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};X=S([x(0,(0,t.Inject)(c.HoverManagerService)),x(1,(0,t.Inject)(C)),x(2,(0,t.Inject)(i.SheetsThreadCommentModel)),x(3,(0,t.Inject)(r.SheetPermissionCheckController))],X);function be(e,t,n,r){for(let i of[t,e])if(i&&i.unitId===n&&i.subUnitId===r)return i}let Z=class extends t.Disposable{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,b(this,`_isSwitchToCommenting`,!1),b(this,`_selectionShapeInfo`,null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,n,r){var i,a;let s=(i=e[0])==null?void 0:i.range,l=this._renderManagerService.getRenderUnitById(n),u=l==null||(a=l.with(c.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:a.skeleton;if(!u||!s)return;let d=u.getCellWithCoordByIndex(s.startRow,s.startColumn);if(((s.rangeType??t.RANGE_TYPE.NORMAL)!==t.RANGE_TYPE.NORMAL||s.endColumn-s.startColumn>0||s.endRow-s.startRow>0)&&!((d.isMerged||d.isMergedMainCell)&&t.Rectangle.equals(d.mergeInfo,s))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(o.SetActiveCommentOperation.id);return}let f=d.actualRow,p=d.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(n,r,f,p)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(o.SetActiveCommentOperation.id);return}let m=this._sheetsThreadCommentModel.getByLocation(n,r,f,p);m&&this._commandService.executeCommand(o.SetActiveCommentOperation.id,{unitId:n,subUnitId:r,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===a.DeleteCommentMutation.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 n;let{unitId:i,subUnitId:o,commentId:s,trigger:l}=e,u=this._sheetsThreadCommentModel.getComment(i,o,s);if(!u||u.resolved)return;let d=(0,a.deserializeThreadCommentAnchor)(u.ref);if((d==null?void 0:d.kind)===a.ThreadCommentAnchorKind.SHEET_DRAWING)return;let p=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!p||p.getUnitId()!==i)return;this._isSwitchToCommenting=!0,((n=p.getActiveSheet())==null?void 0:n.getSheetId())!==o&&await this._commandService.executeCommand(r.SetWorksheetActiveOperation.id,{unitId:i,subUnitId:o}),this._isSwitchToCommenting=!1;let m=(0,f.singleReferenceToGrid)(u.ref),{row:h,column:g}=m;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookViewPermission],worksheetTypes:[r.WorksheetViewPermission],rangeTypes:[r.RangeProtectionPermissionViewPoint]},[{startRow:h,startColumn:g,endRow:h,endColumn:g}],i,o)||(await this._commandService.executeCommand(c.ScrollToRangeOperation.id,{range:{startRow:Math.max(m.row-1,0),endRow:m.row+1,startColumn:Math.max(m.column-1,0),endColumn:m.column+1}}),this._editorBridgeService.isVisible().visible))return;this._sheetsThreadCommentPopupService.showPopup({unitId:i,subUnitId:o,row:m.row,col:m.column,commentId:u.id,trigger:l})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe((0,l.combineLatest)([this._threadCommentPanelService.activeCommentId$,this._threadCommentPanelService.hoveredCommentId$]).pipe((0,l.debounceTime)(100)).subscribe(([e,n])=>{var r,i;let a=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),o=be(e,n,a==null?void 0:a.getUnitId(),a==null||(r=a.getActiveSheet())==null?void 0:r.getSheetId());if(!o){this._selectionShapeInfo&&=(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),null);return}let{unitId:s,subUnitId:c,commentId:l}=o;this._selectionShapeInfo&&=(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),null);let u=this._sheetsThreadCommentModel.getComment(s,c,l);if(!u)return;let{row:d,column:p}=(0,f.singleReferenceToGrid)(u.ref);if(Number.isNaN(d)||Number.isNaN(p))return null;let m=(i=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetId(c),h=(m==null?void 0:m.getMergedCell(d,p))??{startColumn:p,endColumn:p,startRow:d,endRow:d},g=this._markSelectionService.addShape({range:h,style:{fill:`rgba(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1);g&&(this._selectionShapeInfo={...o,shapeId:g})}))}};Z=S([x(0,t.ICommandService),x(1,(0,t.Inject)(C)),x(2,(0,t.Inject)(i.SheetsThreadCommentModel)),x(3,(0,t.Inject)(o.ThreadCommentPanelService)),x(4,t.IUniverInstanceService),x(5,(0,t.Inject)(r.SheetPermissionCheckController)),x(6,c.IMarkSelectionService),x(7,(0,t.Inject)(r.SheetsSelectionsService)),x(8,c.IEditorBridgeService),x(9,u.IRenderManagerService)],Z);let Q=class extends t.Disposable{constructor(e,t){super(),this._menuManagerService=e,this._shortcutService=t,this._initMenu(),this._initShortcut()}_initShortcut(){this._shortcutService.registerShortcut(ne)}_initMenu(){this._menuManagerService.mergeMenu(M)}};Q=S([x(0,s.IMenuManagerService),x(1,s.IShortcutService)],Q);let $=class extends t.Plugin{constructor(e=I,n,r,i,a){super(),this._config=e,this._injector=n,this._commandService=r,this._renderManagerService=i,this._configService=a;let{menu:o,...s}=(0,t.merge)({},I,this._config);o&&this._configService.setConfig(`menu`,o,{merge:!0}),this._configService.setConfig(ie,s)}onStarting(){this._injector.add([J]),this._injector.get(J),[[Q],[W],[G],[X],[Z],[C],[K]].forEach(e=>{this._injector.add(e)}),[O,E,w,T].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(Q)}onReady(){this._injector.get(W)}onRendered(){this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,[Y]),this._injector.get(G),this._injector.get(X),this._injector.get(Z),this._injector.get(K)}};b($,`pluginName`,_),b($,`packageName`,N),b($,`version`,re),b($,`type`,t.UniverInstanceType.UNIVER_SHEET),$=S([(0,t.DependentOn)(u.UniverRenderEnginePlugin,a.UniverThreadCommentPlugin,n.UniverDrawingPlugin,r.UniverSheetsPlugin,o.UniverThreadCommentUIPlugin,i.UniverSheetsThreadCommentPlugin,c.UniverSheetsUIPlugin),x(1,(0,t.Inject)(t.Injector)),x(2,(0,t.Inject)(t.ICommandService)),x(3,u.IRenderManagerService),x(4,t.IConfigService)],$),Object.defineProperty(e,"SheetsThreadCommentPopupService",{enumerable:!0,get:function(){return C}}),e.SheetsThreadCommentUIMenuSchema=M,e.ShowAddSheetCommentModalOperation=w,e.ToggleSheetCommentPanelOperation=T,Object.defineProperty(e,"UniverSheetsThreadCommentMobileUIPlugin",{enumerable:!0,get:function(){return q}}),Object.defineProperty(e,"UniverSheetsThreadCommentUIPlugin",{enumerable:!0,get:function(){return $}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-thread-comment-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Thread comment UI integration for Univer Sheets.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -58,26 +58,26 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/core": "1.
|
|
62
|
-
"@univerjs/drawing": "1.
|
|
63
|
-
"@univerjs/engine-formula": "1.
|
|
64
|
-
"@univerjs/engine-render": "1.
|
|
65
|
-
"@univerjs/icons": "1.
|
|
66
|
-
"@univerjs/sheets": "1.
|
|
67
|
-
"@univerjs/sheets-thread-comment": "1.
|
|
68
|
-
"@univerjs/sheets-ui": "1.
|
|
69
|
-
"@univerjs/thread-comment": "1.
|
|
70
|
-
"@univerjs/thread-comment-ui": "1.
|
|
71
|
-
"@univerjs/ui": "1.
|
|
61
|
+
"@univerjs/core": "1.6.0",
|
|
62
|
+
"@univerjs/drawing": "1.6.0",
|
|
63
|
+
"@univerjs/engine-formula": "1.6.0",
|
|
64
|
+
"@univerjs/engine-render": "1.6.0",
|
|
65
|
+
"@univerjs/icons": "1.50.0",
|
|
66
|
+
"@univerjs/sheets": "1.6.0",
|
|
67
|
+
"@univerjs/sheets-thread-comment": "1.6.0",
|
|
68
|
+
"@univerjs/sheets-ui": "1.6.0",
|
|
69
|
+
"@univerjs/thread-comment": "1.6.0",
|
|
70
|
+
"@univerjs/thread-comment-ui": "1.6.0",
|
|
71
|
+
"@univerjs/ui": "1.6.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@univerjs-infra/shared": "1.
|
|
75
|
-
"postcss": "^8.5.
|
|
74
|
+
"@univerjs-infra/shared": "1.6.0",
|
|
75
|
+
"postcss": "^8.5.33",
|
|
76
76
|
"react": "18.3.1",
|
|
77
77
|
"rxjs": "7.8.2",
|
|
78
78
|
"tailwindcss": "3.4.18",
|
|
79
|
-
"tsrs": "
|
|
80
|
-
"vitest": "^5.1.
|
|
79
|
+
"tsrs": "7.1.0-beta.tsrs2",
|
|
80
|
+
"vitest": "^5.1.1"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"test": "vitest run",
|