@univerjs/sheets-thread-comment-ui 0.25.0 → 1.0.0-alpha.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/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { CommandType, DependentOn, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Plugin, RANGE_TYPE, Range, Rectangle, Tools, UniverInstanceType, merge } from "@univerjs/core";
2
2
  import { INTERCEPTOR_POINT, RangeProtectionPermissionViewPoint, SetWorksheetActiveOperation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, WorkbookCommentPermission, WorksheetViewPermission, getSheetCommandTarget } from "@univerjs/sheets";
3
3
  import { SheetsThreadCommentModel, UniverSheetsThreadCommentPlugin } from "@univerjs/sheets-thread-comment";
4
- import { SetActiveCommentOperation, ThreadCommentPanel, ThreadCommentPanelService, ThreadCommentTree, ThreadCommentTreeLocation, UniverThreadCommentUIPlugin, UniverThreadCommentUIPlugin as UniverThreadCommentUIPlugin$1 } from "@univerjs/thread-comment-ui";
5
- import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IShortcutService, ISidebarService, IZenZoneService, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
4
+ import { SetActiveCommentOperation, ThreadCommentPanel, ThreadCommentPanelService, ThreadCommentTree, ThreadCommentTreeLocation, UniverThreadCommentUIPlugin } from "@univerjs/thread-comment-ui";
5
+ import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IShortcutService, ISidebarService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
6
6
  import { COPY_TYPE, CellPopupManagerService, HoverManagerService, IEditorBridgeService, IMarkSelectionService, ISheetClipboardService, ScrollToRangeOperation, SheetCanvasPopManagerService, SheetSkeletonManagerService, getCurrentRangeDisable$, whenSheetEditorFocused } from "@univerjs/sheets-ui";
7
7
  import { BehaviorSubject, debounceTime, map } from "rxjs";
8
- import { IRenderManagerService } from "@univerjs/engine-render";
9
- import { serializeRange, singleReferenceToGrid } from "@univerjs/engine-formula";
10
- import { AddCommentCommand, AddCommentCommand as AddCommentCommand$1, AddCommentMutation, DeleteCommentCommand, DeleteCommentCommand as DeleteCommentCommand$1, DeleteCommentMutation, DeleteCommentTreeCommand, DeleteCommentTreeCommand as DeleteCommentTreeCommand$1, IThreadCommentDataSourceService, IThreadCommentDataSourceService as IThreadCommentDataSourceService$1, ResolveCommentCommand, ResolveCommentCommand as ResolveCommentCommand$1, UpdateCommentCommand, UpdateCommentCommand as UpdateCommentCommand$1 } from "@univerjs/thread-comment";
11
8
  import { CommentIcon } from "@univerjs/icons";
12
9
  import { jsx } from "react/jsx-runtime";
10
+ import { serializeRange, singleReferenceToGrid } from "@univerjs/engine-formula";
13
11
  import { useCallback, useEffect, useMemo, useRef } from "react";
12
+ import { IRenderManagerService } from "@univerjs/engine-render";
13
+ import { AddCommentCommand, AddCommentMutation, DeleteCommentCommand, DeleteCommentMutation, DeleteCommentTreeCommand, IThreadCommentDataSourceService, ResolveCommentCommand, UpdateCommentCommand } from "@univerjs/thread-comment";
14
14
 
15
15
  //#region src/types/const.ts
16
16
  /**
@@ -33,7 +33,7 @@ const SHEETS_THREAD_COMMENT_PANEL = "univer.sheet.thread-comment-panel";
33
33
  const PLUGIN_NAME = "SHEET_THREAD_COMMENT_UI_PLUGIN";
34
34
 
35
35
  //#endregion
36
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
36
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
37
37
  function _typeof(o) {
38
38
  "@babel/helpers - typeof";
39
39
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -44,7 +44,7 @@ function _typeof(o) {
44
44
  }
45
45
 
46
46
  //#endregion
47
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
47
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
48
48
  function toPrimitive(t, r) {
49
49
  if ("object" != _typeof(t) || !t) return t;
50
50
  var e = t[Symbol.toPrimitive];
@@ -57,14 +57,14 @@ function toPrimitive(t, r) {
57
57
  }
58
58
 
59
59
  //#endregion
60
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
60
+ //#region \0@oxc-project+runtime@0.137.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
66
  //#endregion
67
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
67
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
68
68
  function _defineProperty(e, r, t) {
69
69
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
70
70
  value: t,
@@ -75,7 +75,7 @@ function _defineProperty(e, r, t) {
75
75
  }
76
76
 
77
77
  //#endregion
78
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
78
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
79
79
  function __decorateParam(paramIndex, decorator) {
80
80
  return function(target, key) {
81
81
  decorator(target, key, paramIndex);
@@ -83,7 +83,7 @@ function __decorateParam(paramIndex, decorator) {
83
83
  }
84
84
 
85
85
  //#endregion
86
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
86
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
87
87
  function __decorate(decorators, target, key, desc) {
88
88
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
89
89
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -97,25 +97,18 @@ let SheetsThreadCommentPopupService = class SheetsThreadCommentPopupService exte
97
97
  get activePopup() {
98
98
  return this._activePopup;
99
99
  }
100
- constructor(_canvasPopupManagerService, _zenZoneService, _cellPopupManagerService) {
100
+ constructor(_canvasPopupManagerService, _cellPopupManagerService) {
101
101
  super();
102
102
  this._canvasPopupManagerService = _canvasPopupManagerService;
103
- this._zenZoneService = _zenZoneService;
104
103
  this._cellPopupManagerService = _cellPopupManagerService;
105
104
  _defineProperty(this, "_lastPopup", null);
106
105
  _defineProperty(this, "_activePopup", void 0);
107
106
  _defineProperty(this, "_activePopup$", new BehaviorSubject(null));
108
107
  _defineProperty(this, "activePopup$", this._activePopup$.asObservable());
109
- this._initZenVisible();
110
108
  this.disposeWithMe(() => {
111
109
  this._activePopup$.complete();
112
110
  });
113
111
  }
114
- _initZenVisible() {
115
- this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
116
- if (visible) this.hidePopup();
117
- }));
118
- }
119
112
  dispose() {
120
113
  super.dispose();
121
114
  this.hidePopup();
@@ -129,7 +122,6 @@ let SheetsThreadCommentPopupService = class SheetsThreadCommentPopupService exte
129
122
  return;
130
123
  }
131
124
  if (this._lastPopup) this._lastPopup.dispose();
132
- if (this._zenZoneService.visible) return;
133
125
  this._activePopup = location;
134
126
  this._activePopup$.next(location);
135
127
  const popupDisposable = this._cellPopupManagerService.showPopup({
@@ -170,11 +162,7 @@ let SheetsThreadCommentPopupService = class SheetsThreadCommentPopupService exte
170
162
  this._activePopup$.next(this._activePopup);
171
163
  }
172
164
  };
173
- SheetsThreadCommentPopupService = __decorate([
174
- __decorateParam(0, Inject(SheetCanvasPopManagerService)),
175
- __decorateParam(1, IZenZoneService),
176
- __decorateParam(2, Inject(CellPopupManagerService))
177
- ], SheetsThreadCommentPopupService);
165
+ SheetsThreadCommentPopupService = __decorate([__decorateParam(0, Inject(SheetCanvasPopManagerService)), __decorateParam(1, Inject(CellPopupManagerService))], SheetsThreadCommentPopupService);
178
166
 
179
167
  //#endregion
180
168
  //#region src/commands/operations/comment.operation.ts
@@ -236,7 +224,7 @@ const ToggleSheetCommentPanelOperation = {
236
224
  //#endregion
237
225
  //#region package.json
238
226
  var name = "@univerjs/sheets-thread-comment-ui";
239
- var version = "0.25.0";
227
+ var version = "1.0.0-alpha.0";
240
228
 
241
229
  //#endregion
242
230
  //#region src/config/config.ts
@@ -244,6 +232,197 @@ const SHEETS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY = "sheets-thread-comment.config
244
232
  const configSymbol = Symbol(SHEETS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY);
245
233
  const defaultPluginConfig = {};
246
234
 
235
+ //#endregion
236
+ //#region src/views/SheetsThreadCommentCell.tsx
237
+ const SheetsThreadCommentCell = () => {
238
+ const univerInstanceService = useDependency(IUniverInstanceService);
239
+ const sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService);
240
+ const activePopup = useObservable(sheetsThreadCommentPopupService.activePopup$);
241
+ const sheetThreadCommentModel = useDependency(SheetsThreadCommentModel);
242
+ useObservable(sheetThreadCommentModel.commentUpdate$);
243
+ if (!activePopup) return null;
244
+ const { row, col, unitId, subUnitId, trigger } = activePopup;
245
+ const rootId = sheetThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
246
+ const ref = `${Tools.chatAtABC(col)}${row + 1}`;
247
+ const onClose = () => {
248
+ sheetsThreadCommentPopupService.hidePopup();
249
+ };
250
+ const getSubUnitName = (id) => {
251
+ var _univerInstanceServic, _univerInstanceServic2;
252
+ return (_univerInstanceServic = (_univerInstanceServic2 = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET)) === null || _univerInstanceServic2 === void 0 || (_univerInstanceServic2 = _univerInstanceServic2.getSheetBySheetId(id)) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getName()) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : "";
253
+ };
254
+ return /* @__PURE__ */ jsx(ThreadCommentTree, {
255
+ onClick: () => {
256
+ sheetsThreadCommentPopupService.persistPopup();
257
+ },
258
+ location: ThreadCommentTreeLocation.CELL,
259
+ id: rootId,
260
+ unitId,
261
+ subUnitId,
262
+ type: UniverInstanceType.UNIVER_SHEET,
263
+ refStr: ref,
264
+ onClose,
265
+ getSubUnitName,
266
+ autoFocus: trigger === "context-menu"
267
+ });
268
+ };
269
+
270
+ //#endregion
271
+ //#region src/views/SheetsThreadCommentPanel.tsx
272
+ const SheetsThreadCommentPanel = () => {
273
+ var _workbook$getActiveSh;
274
+ const markSelectionService = useDependency(IMarkSelectionService);
275
+ const univerInstanceService = useDependency(IUniverInstanceService);
276
+ const sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService);
277
+ const workbook = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
278
+ const unitId = workbook.getUnitId();
279
+ const commandService = useDependency(ICommandService);
280
+ const subUnitId$ = useMemo(() => workbook.activeSheet$.pipe(map((i) => i === null || i === void 0 ? void 0 : i.getSheetId())), [workbook.activeSheet$]);
281
+ const subUnitId = useObservable(subUnitId$, (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
282
+ const hoverShapeId = useRef(null);
283
+ const panelService = useDependency(ThreadCommentPanelService);
284
+ const activeCommentId = useObservable(panelService.activeCommentId$);
285
+ const panelVisible = useObservable(panelService.panelVisible$, panelService.panelVisible);
286
+ const sortComments = useCallback((comments) => {
287
+ const worksheets = workbook.getSheets();
288
+ const sheetIndex = {};
289
+ worksheets.forEach((sheet, i) => {
290
+ sheetIndex[sheet.getSheetId()] = i;
291
+ });
292
+ const sort = (comments) => {
293
+ return comments.map((comment) => {
294
+ var _sheetIndex$comment$s;
295
+ const ref = singleReferenceToGrid(comment.ref);
296
+ const p = [
297
+ (_sheetIndex$comment$s = sheetIndex[comment.subUnitId]) !== null && _sheetIndex$comment$s !== void 0 ? _sheetIndex$comment$s : 0,
298
+ ref.row,
299
+ ref.column
300
+ ];
301
+ return {
302
+ ...comment,
303
+ p
304
+ };
305
+ }).sort((pre, aft) => {
306
+ if (pre.p[0] === aft.p[0]) {
307
+ if (pre.p[1] === aft.p[1]) return pre.p[2] - aft.p[2];
308
+ return pre.p[1] - aft.p[1];
309
+ }
310
+ return pre.p[0] - aft.p[0];
311
+ });
312
+ };
313
+ return [...sort(comments.filter((comment) => !comment.resolved)), ...sort(comments.filter((comment) => comment.resolved))];
314
+ }, [workbook]);
315
+ const showShape = useCallback((comment) => {
316
+ if (comment.unitId === unitId && comment.subUnitId === subUnitId && !comment.resolved) {
317
+ var _worksheet$getMergedC;
318
+ const { row, column } = singleReferenceToGrid(comment.ref);
319
+ const worksheet = workbook.getSheetBySheetId(comment.subUnitId);
320
+ const mergeInfo = (_worksheet$getMergedC = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getMergedCell(row, column)) !== null && _worksheet$getMergedC !== void 0 ? _worksheet$getMergedC : {
321
+ startColumn: column,
322
+ endColumn: column,
323
+ startRow: row,
324
+ endRow: row
325
+ };
326
+ if (!Number.isNaN(row) && !Number.isNaN(column)) return markSelectionService.addShape({
327
+ range: mergeInfo,
328
+ style: {
329
+ fill: "rgb(255, 189, 55, 0.35)",
330
+ strokeWidth: 1,
331
+ stroke: "#FFBD37",
332
+ widgets: {}
333
+ },
334
+ primary: null
335
+ });
336
+ }
337
+ return null;
338
+ }, [
339
+ markSelectionService,
340
+ subUnitId,
341
+ unitId
342
+ ]);
343
+ const getSubUnitName = (id) => {
344
+ var _workbook$getSheetByS, _workbook$getSheetByS2;
345
+ return (_workbook$getSheetByS = (_workbook$getSheetByS2 = workbook.getSheetBySheetId(id)) === null || _workbook$getSheetByS2 === void 0 ? void 0 : _workbook$getSheetByS2.getName()) !== null && _workbook$getSheetByS !== void 0 ? _workbook$getSheetByS : "";
346
+ };
347
+ const handleAdd = () => {
348
+ commandService.executeCommand(ShowAddSheetCommentModalOperation.id);
349
+ };
350
+ const handleHover = (comment) => {
351
+ if (hoverShapeId.current) {
352
+ markSelectionService.removeShape(hoverShapeId.current);
353
+ hoverShapeId.current = null;
354
+ }
355
+ if (activeCommentId && activeCommentId.unitId === comment.unitId && activeCommentId.subUnitId === comment.subUnitId && activeCommentId.commentId === comment.id) return;
356
+ hoverShapeId.current = showShape(comment);
357
+ };
358
+ const handleLeave = () => {
359
+ if (hoverShapeId.current) {
360
+ markSelectionService.removeShape(hoverShapeId.current);
361
+ hoverShapeId.current = null;
362
+ }
363
+ };
364
+ const handleResolve = (id, resolved) => {
365
+ if (resolved) sheetsThreadCommentPopupService.hidePopup();
366
+ };
367
+ useEffect(() => {
368
+ if (!panelVisible && hoverShapeId.current) {
369
+ markSelectionService.removeShape(hoverShapeId.current);
370
+ hoverShapeId.current = null;
371
+ }
372
+ }, [markSelectionService, panelVisible]);
373
+ return /* @__PURE__ */ jsx(ThreadCommentPanel, {
374
+ unitId,
375
+ subUnitId$,
376
+ type: UniverInstanceType.UNIVER_SHEET,
377
+ onAdd: handleAdd,
378
+ getSubUnitName,
379
+ onResolve: handleResolve,
380
+ sortComments,
381
+ onItemEnter: handleHover,
382
+ onItemLeave: handleLeave,
383
+ onDeleteComment: () => {
384
+ handleLeave();
385
+ return true;
386
+ }
387
+ });
388
+ };
389
+
390
+ //#endregion
391
+ //#region src/controllers/components.controller.ts
392
+ /**
393
+ * Copyright 2023-present DreamNum Co., Ltd.
394
+ *
395
+ * Licensed under the Apache License, Version 2.0 (the "License");
396
+ * you may not use this file except in compliance with the License.
397
+ * You may obtain a copy of the License at
398
+ *
399
+ * http://www.apache.org/licenses/LICENSE-2.0
400
+ *
401
+ * Unless required by applicable law or agreed to in writing, software
402
+ * distributed under the License is distributed on an "AS IS" BASIS,
403
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
404
+ * See the License for the specific language governing permissions and
405
+ * limitations under the License.
406
+ */
407
+ let ComponentsController = class ComponentsController extends Disposable {
408
+ constructor(_componentManager, _iconManager) {
409
+ super();
410
+ this._componentManager = _componentManager;
411
+ this._iconManager = _iconManager;
412
+ this._registerComponents();
413
+ this._registerIcons();
414
+ }
415
+ _registerComponents() {
416
+ [[SHEETS_THREAD_COMMENT_MODAL, SheetsThreadCommentCell], [SHEETS_THREAD_COMMENT_PANEL, SheetsThreadCommentPanel]].forEach(([key, comp]) => {
417
+ this.disposeWithMe(this._componentManager.register(key, comp));
418
+ });
419
+ }
420
+ _registerIcons() {
421
+ this.disposeWithMe(this._iconManager.register({ CommentIcon }));
422
+ }
423
+ };
424
+ ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
425
+
247
426
  //#endregion
248
427
  //#region src/controllers/render-controllers/render.controller.ts
249
428
  let SheetsThreadCommentRenderController = class SheetsThreadCommentRenderController extends Disposable {
@@ -418,7 +597,7 @@ let SheetsThreadCommentCopyPasteController = class SheetsThreadCommentCopyPasteC
418
597
  SheetsThreadCommentCopyPasteController = __decorate([
419
598
  __decorateParam(0, Inject(ISheetClipboardService)),
420
599
  __decorateParam(1, Inject(SheetsThreadCommentModel)),
421
- __decorateParam(2, IThreadCommentDataSourceService$1)
600
+ __decorateParam(2, IThreadCommentDataSourceService)
422
601
  ], SheetsThreadCommentCopyPasteController);
423
602
 
424
603
  //#endregion
@@ -505,7 +684,7 @@ let SheetsThreadCommentPermissionController = class SheetsThreadCommentPermissio
505
684
  workbookTypes: [WorkbookCommentPermission],
506
685
  worksheetTypes: [WorksheetViewPermission]
507
686
  })) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
508
- } else if (id === AddCommentCommand$1.id) {
687
+ } else if (id === AddCommentCommand.id) {
509
688
  const { unitId, subUnitId, comment } = command.params;
510
689
  const { row, column } = singleReferenceToGrid(comment.ref);
511
690
  if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
@@ -518,7 +697,7 @@ let SheetsThreadCommentPermissionController = class SheetsThreadCommentPermissio
518
697
  endRow: row,
519
698
  endColumn: column
520
699
  }], unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
521
- } else if (id === UpdateCommentCommand$1.id) {
700
+ } else if (id === UpdateCommentCommand.id) {
522
701
  const { unitId, subUnitId, payload } = command.params;
523
702
  const { commentId } = payload;
524
703
  const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
@@ -535,7 +714,7 @@ let SheetsThreadCommentPermissionController = class SheetsThreadCommentPermissio
535
714
  endColumn: column
536
715
  }], unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));
537
716
  }
538
- } else if (id === ResolveCommentCommand$1.id || id === DeleteCommentCommand$1.id || id === DeleteCommentTreeCommand$1.id) {
717
+ } else if (id === ResolveCommentCommand.id || id === DeleteCommentCommand.id || id === DeleteCommentTreeCommand.id) {
539
718
  const { unitId, subUnitId, commentId } = command.params;
540
719
  const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
541
720
  if (comment) {
@@ -787,158 +966,6 @@ const menuSchema = {
787
966
  } } }
788
967
  };
789
968
 
790
- //#endregion
791
- //#region src/views/sheets-thread-comment-cell/index.tsx
792
- const SheetsThreadCommentCell = () => {
793
- const univerInstanceService = useDependency(IUniverInstanceService);
794
- const sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService);
795
- const activePopup = useObservable(sheetsThreadCommentPopupService.activePopup$);
796
- const sheetThreadCommentModel = useDependency(SheetsThreadCommentModel);
797
- useObservable(sheetThreadCommentModel.commentUpdate$);
798
- if (!activePopup) return null;
799
- const { row, col, unitId, subUnitId, trigger } = activePopup;
800
- const rootId = sheetThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
801
- const ref = `${Tools.chatAtABC(col)}${row + 1}`;
802
- const onClose = () => {
803
- sheetsThreadCommentPopupService.hidePopup();
804
- };
805
- const getSubUnitName = (id) => {
806
- var _univerInstanceServic, _univerInstanceServic2;
807
- return (_univerInstanceServic = (_univerInstanceServic2 = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET)) === null || _univerInstanceServic2 === void 0 || (_univerInstanceServic2 = _univerInstanceServic2.getSheetBySheetId(id)) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getName()) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : "";
808
- };
809
- return /* @__PURE__ */ jsx(ThreadCommentTree, {
810
- onClick: () => {
811
- sheetsThreadCommentPopupService.persistPopup();
812
- },
813
- location: ThreadCommentTreeLocation.CELL,
814
- id: rootId,
815
- unitId,
816
- subUnitId,
817
- type: UniverInstanceType.UNIVER_SHEET,
818
- refStr: ref,
819
- onClose,
820
- getSubUnitName,
821
- autoFocus: trigger === "context-menu"
822
- });
823
- };
824
-
825
- //#endregion
826
- //#region src/views/sheets-thread-comment-panel/index.tsx
827
- const SheetsThreadCommentPanel = () => {
828
- var _workbook$getActiveSh;
829
- const markSelectionService = useDependency(IMarkSelectionService);
830
- const univerInstanceService = useDependency(IUniverInstanceService);
831
- const sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService);
832
- const workbook = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
833
- const unitId = workbook.getUnitId();
834
- const commandService = useDependency(ICommandService);
835
- const subUnitId$ = useMemo(() => workbook.activeSheet$.pipe(map((i) => i === null || i === void 0 ? void 0 : i.getSheetId())), [workbook.activeSheet$]);
836
- const subUnitId = useObservable(subUnitId$, (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
837
- const hoverShapeId = useRef(null);
838
- const panelService = useDependency(ThreadCommentPanelService);
839
- const activeCommentId = useObservable(panelService.activeCommentId$);
840
- const panelVisible = useObservable(panelService.panelVisible$, panelService.panelVisible);
841
- const sortComments = useCallback((comments) => {
842
- const worksheets = workbook.getSheets();
843
- const sheetIndex = {};
844
- worksheets.forEach((sheet, i) => {
845
- sheetIndex[sheet.getSheetId()] = i;
846
- });
847
- const sort = (comments) => {
848
- return comments.map((comment) => {
849
- var _sheetIndex$comment$s;
850
- const ref = singleReferenceToGrid(comment.ref);
851
- const p = [
852
- (_sheetIndex$comment$s = sheetIndex[comment.subUnitId]) !== null && _sheetIndex$comment$s !== void 0 ? _sheetIndex$comment$s : 0,
853
- ref.row,
854
- ref.column
855
- ];
856
- return {
857
- ...comment,
858
- p
859
- };
860
- }).sort((pre, aft) => {
861
- if (pre.p[0] === aft.p[0]) {
862
- if (pre.p[1] === aft.p[1]) return pre.p[2] - aft.p[2];
863
- return pre.p[1] - aft.p[1];
864
- }
865
- return pre.p[0] - aft.p[0];
866
- });
867
- };
868
- return [...sort(comments.filter((comment) => !comment.resolved)), ...sort(comments.filter((comment) => comment.resolved))];
869
- }, [workbook]);
870
- const showShape = useCallback((comment) => {
871
- if (comment.unitId === unitId && comment.subUnitId === subUnitId && !comment.resolved) {
872
- var _worksheet$getMergedC;
873
- const { row, column } = singleReferenceToGrid(comment.ref);
874
- const worksheet = workbook.getSheetBySheetId(comment.subUnitId);
875
- const mergeInfo = (_worksheet$getMergedC = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getMergedCell(row, column)) !== null && _worksheet$getMergedC !== void 0 ? _worksheet$getMergedC : {
876
- startColumn: column,
877
- endColumn: column,
878
- startRow: row,
879
- endRow: row
880
- };
881
- if (!Number.isNaN(row) && !Number.isNaN(column)) return markSelectionService.addShape({
882
- range: mergeInfo,
883
- style: {
884
- fill: "rgb(255, 189, 55, 0.35)",
885
- strokeWidth: 1,
886
- stroke: "#FFBD37",
887
- widgets: {}
888
- },
889
- primary: null
890
- });
891
- }
892
- return null;
893
- }, [
894
- markSelectionService,
895
- subUnitId,
896
- unitId
897
- ]);
898
- const getSubUnitName = (id) => {
899
- var _workbook$getSheetByS, _workbook$getSheetByS2;
900
- return (_workbook$getSheetByS = (_workbook$getSheetByS2 = workbook.getSheetBySheetId(id)) === null || _workbook$getSheetByS2 === void 0 ? void 0 : _workbook$getSheetByS2.getName()) !== null && _workbook$getSheetByS !== void 0 ? _workbook$getSheetByS : "";
901
- };
902
- const handleAdd = () => {
903
- commandService.executeCommand(ShowAddSheetCommentModalOperation.id);
904
- };
905
- const handleHover = (comment) => {
906
- if (activeCommentId && activeCommentId.unitId === comment.unitId && activeCommentId.subUnitId === comment.subUnitId && activeCommentId.commentId === comment.id) return;
907
- if (hoverShapeId.current) {
908
- markSelectionService.removeShape(hoverShapeId.current);
909
- hoverShapeId.current = null;
910
- }
911
- hoverShapeId.current = showShape(comment);
912
- };
913
- const handleLeave = () => {
914
- if (hoverShapeId.current) {
915
- markSelectionService.removeShape(hoverShapeId.current);
916
- hoverShapeId.current = null;
917
- }
918
- };
919
- const handleResolve = (id, resolved) => {
920
- if (resolved) sheetsThreadCommentPopupService.hidePopup();
921
- };
922
- useEffect(() => {
923
- if (!panelVisible && hoverShapeId.current) markSelectionService.removeShape(hoverShapeId.current);
924
- }, [markSelectionService, panelVisible]);
925
- return /* @__PURE__ */ jsx(ThreadCommentPanel, {
926
- unitId,
927
- subUnitId$,
928
- type: UniverInstanceType.UNIVER_SHEET,
929
- onAdd: handleAdd,
930
- getSubUnitName,
931
- onResolve: handleResolve,
932
- sortComments,
933
- onItemEnter: handleHover,
934
- onItemLeave: handleLeave,
935
- onDeleteComment: () => {
936
- handleLeave();
937
- return true;
938
- }
939
- });
940
- };
941
-
942
969
  //#endregion
943
970
  //#region src/controllers/sheets-thread-comment.controller.ts
944
971
  /**
@@ -957,14 +984,12 @@ const SheetsThreadCommentPanel = () => {
957
984
  * limitations under the License.
958
985
  */
959
986
  let SheetsThreadCommentController = class SheetsThreadCommentController extends Disposable {
960
- constructor(_menuManagerService, _componentManager, _shortcutService) {
987
+ constructor(_menuManagerService, _shortcutService) {
961
988
  super();
962
989
  this._menuManagerService = _menuManagerService;
963
- this._componentManager = _componentManager;
964
990
  this._shortcutService = _shortcutService;
965
991
  this._initMenu();
966
992
  this._initShortcut();
967
- this._initComponent();
968
993
  }
969
994
  _initShortcut() {
970
995
  this._shortcutService.registerShortcut(AddCommentShortcut);
@@ -972,21 +997,8 @@ let SheetsThreadCommentController = class SheetsThreadCommentController extends
972
997
  _initMenu() {
973
998
  this._menuManagerService.mergeMenu(menuSchema);
974
999
  }
975
- _initComponent() {
976
- [
977
- [SHEETS_THREAD_COMMENT_MODAL, SheetsThreadCommentCell],
978
- [SHEETS_THREAD_COMMENT_PANEL, SheetsThreadCommentPanel],
979
- ["CommentIcon", CommentIcon]
980
- ].forEach(([key, comp]) => {
981
- this.disposeWithMe(this._componentManager.register(key, comp));
982
- });
983
- }
984
1000
  };
985
- SheetsThreadCommentController = __decorate([
986
- __decorateParam(0, IMenuManagerService),
987
- __decorateParam(1, Inject(ComponentManager)),
988
- __decorateParam(2, IShortcutService)
989
- ], SheetsThreadCommentController);
1001
+ SheetsThreadCommentController = __decorate([__decorateParam(0, IMenuManagerService), __decorateParam(1, IShortcutService)], SheetsThreadCommentController);
990
1002
 
991
1003
  //#endregion
992
1004
  //#region src/plugin.ts
@@ -1002,6 +1014,8 @@ let UniverSheetsThreadCommentUIPlugin = class UniverSheetsThreadCommentUIPlugin
1002
1014
  this._configService.setConfig(SHEETS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY, rest);
1003
1015
  }
1004
1016
  onStarting() {
1017
+ this._injector.add([ComponentsController]);
1018
+ this._injector.get(ComponentsController);
1005
1019
  [
1006
1020
  [SheetsThreadCommentController],
1007
1021
  [SheetsThreadCommentRenderController],
@@ -1033,11 +1047,11 @@ _defineProperty(UniverSheetsThreadCommentUIPlugin, "packageName", name);
1033
1047
  _defineProperty(UniverSheetsThreadCommentUIPlugin, "version", version);
1034
1048
  _defineProperty(UniverSheetsThreadCommentUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
1035
1049
  UniverSheetsThreadCommentUIPlugin = __decorate([
1036
- DependentOn(UniverThreadCommentUIPlugin$1, UniverSheetsThreadCommentPlugin),
1050
+ DependentOn(UniverThreadCommentUIPlugin, UniverSheetsThreadCommentPlugin),
1037
1051
  __decorateParam(1, Inject(Injector)),
1038
1052
  __decorateParam(2, Inject(ICommandService)),
1039
1053
  __decorateParam(3, IConfigService)
1040
1054
  ], UniverSheetsThreadCommentUIPlugin);
1041
1055
 
1042
1056
  //#endregion
1043
- export { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, IThreadCommentDataSourceService, ResolveCommentCommand, SheetsThreadCommentPopupService, ShowAddSheetCommentModalOperation, ToggleSheetCommentPanelOperation, UniverSheetsThreadCommentUIPlugin, UniverThreadCommentUIPlugin, UpdateCommentCommand };
1057
+ export { SheetsThreadCommentPopupService, ShowAddSheetCommentModalOperation, ToggleSheetCommentPanelOperation, UniverSheetsThreadCommentUIPlugin };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Disposable } from '@univerjs/core';
17
+ import { ComponentManager, IconManager } from '@univerjs/ui';
18
+ export declare class ComponentsController extends Disposable {
19
+ private readonly _componentManager;
20
+ private readonly _iconManager;
21
+ constructor(_componentManager: ComponentManager, _iconManager: IconManager);
22
+ private _registerComponents;
23
+ private _registerIcons;
24
+ }
@@ -14,13 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Disposable } from '@univerjs/core';
17
- import { ComponentManager, IMenuManagerService, IShortcutService } from '@univerjs/ui';
17
+ import { IMenuManagerService, IShortcutService } from '@univerjs/ui';
18
18
  export declare class SheetsThreadCommentController extends Disposable {
19
19
  private readonly _menuManagerService;
20
- private readonly _componentManager;
21
20
  private readonly _shortcutService;
22
- constructor(_menuManagerService: IMenuManagerService, _componentManager: ComponentManager, _shortcutService: IShortcutService);
21
+ constructor(_menuManagerService: IMenuManagerService, _shortcutService: IShortcutService);
23
22
  private _initShortcut;
24
23
  private _initMenu;
25
- private _initComponent;
26
24
  }
@@ -14,11 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import './global.css';
17
- export { ShowAddSheetCommentModalOperation, ToggleSheetCommentPanelOperation } from './commands/operations/comment.operation';
17
+ export { ShowAddSheetCommentModalOperation, ToggleSheetCommentPanelOperation, } from './commands/operations/comment.operation';
18
18
  export type { IUniverSheetsThreadCommentUIConfig } from './config/config';
19
19
  export { UniverSheetsThreadCommentUIPlugin } from './plugin';
20
20
  export { SheetsThreadCommentPopupService } from './services/sheets-thread-comment-popup.service';
21
- export { IThreadCommentDataSourceService } from '@univerjs/thread-comment';
22
- export { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, ResolveCommentCommand, UpdateCommentCommand, } from '@univerjs/thread-comment';
23
- export type { IAddCommentCommandParams, IDeleteCommentCommandParams, IDeleteCommentTreeCommandParams, IResolveCommentCommandParams, IUpdateCommentCommandParams, } from '@univerjs/thread-comment';
24
- export { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { LocaleLeafKeys } from '@univerjs/core';
17
+ import type enUS from './en-US';
18
+ export type LocaleKey = LocaleLeafKeys<typeof enUS>;