@univerjs/docs-thread-comment-ui 0.25.1 → 1.0.0-alpha.1

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 CHANGED
@@ -88,7 +88,7 @@ const DeleteDocCommentComment = {
88
88
  };
89
89
 
90
90
  //#endregion
91
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
91
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
92
92
  function _typeof(o) {
93
93
  "@babel/helpers - typeof";
94
94
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -99,7 +99,7 @@ function _typeof(o) {
99
99
  }
100
100
 
101
101
  //#endregion
102
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
102
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
103
103
  function toPrimitive(t, r) {
104
104
  if ("object" != _typeof(t) || !t) return t;
105
105
  var e = t[Symbol.toPrimitive];
@@ -112,14 +112,14 @@ function toPrimitive(t, r) {
112
112
  }
113
113
 
114
114
  //#endregion
115
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
115
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
116
116
  function toPropertyKey(t) {
117
117
  var i = toPrimitive(t, "string");
118
118
  return "symbol" == _typeof(i) ? i : i + "";
119
119
  }
120
120
 
121
121
  //#endregion
122
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
122
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
123
123
  function _defineProperty(e, r, t) {
124
124
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
125
125
  value: t,
@@ -130,7 +130,7 @@ function _defineProperty(e, r, t) {
130
130
  }
131
131
 
132
132
  //#endregion
133
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
133
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
134
134
  function __decorateParam(paramIndex, decorator) {
135
135
  return function(target, key) {
136
136
  decorator(target, key, paramIndex);
@@ -138,7 +138,7 @@ function __decorateParam(paramIndex, decorator) {
138
138
  }
139
139
 
140
140
  //#endregion
141
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
141
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
142
142
  function __decorate(decorators, target, key, desc) {
143
143
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
144
144
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -273,7 +273,7 @@ const StartAddCommentOperation = {
273
273
  //#endregion
274
274
  //#region package.json
275
275
  var name = "@univerjs/docs-thread-comment-ui";
276
- var version = "0.25.1";
276
+ var version = "1.0.0-alpha.1";
277
277
 
278
278
  //#endregion
279
279
  //#region src/config/config.ts
@@ -281,87 +281,6 @@ const DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY = "docs-thread-comment-ui.config"
281
281
  const configSymbol = Symbol(DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY);
282
282
  const defaultPluginConfig = {};
283
283
 
284
- //#endregion
285
- //#region src/controllers/doc-thread-comment-selection.controller.ts
286
- let DocThreadCommentSelectionController = class DocThreadCommentSelectionController extends _univerjs_core.Disposable {
287
- constructor(_threadCommentPanelService, _univerInstanceService, _commandService, _docThreadCommentService, _renderManagerService, _threadCommentModel) {
288
- super();
289
- this._threadCommentPanelService = _threadCommentPanelService;
290
- this._univerInstanceService = _univerInstanceService;
291
- this._commandService = _commandService;
292
- this._docThreadCommentService = _docThreadCommentService;
293
- this._renderManagerService = _renderManagerService;
294
- this._threadCommentModel = _threadCommentModel;
295
- this._initSelectionChange();
296
- this._initActiveCommandChange();
297
- }
298
- _initSelectionChange() {
299
- let lastSelection;
300
- this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
301
- if (commandInfo.id === _univerjs_docs.SetTextSelectionsOperation.id) {
302
- const { unitId, ranges } = commandInfo.params;
303
- if ((0, _univerjs_core.isInternalEditorID)(unitId)) return;
304
- const doc = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
305
- const primary = ranges[0];
306
- if ((lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.startOffset) === (primary === null || primary === void 0 ? void 0 : primary.startOffset) && (lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.endOffset) === (primary === null || primary === void 0 ? void 0 : primary.endOffset)) return;
307
- lastSelection = primary;
308
- if (primary && doc) {
309
- const { startOffset, endOffset, collapsed } = primary;
310
- let customRange;
311
- if (collapsed) {
312
- var _doc$getBody;
313
- customRange = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 || (_doc$getBody = _doc$getBody.customDecorations) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1);
314
- } else {
315
- var _doc$getBody2;
316
- customRange = (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 || (_doc$getBody2 = _doc$getBody2.customDecorations) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1);
317
- }
318
- if (customRange) {
319
- const comment = this._threadCommentModel.getComment(unitId, DEFAULT_DOC_SUBUNIT_ID, customRange.id);
320
- if (comment && !comment.resolved) this._commandService.executeCommand(ShowCommentPanelOperation.id, { activeComment: {
321
- unitId,
322
- subUnitId: DEFAULT_DOC_SUBUNIT_ID,
323
- commentId: customRange.id
324
- } });
325
- return;
326
- }
327
- }
328
- if (!this._threadCommentPanelService.activeCommentId) return;
329
- const addingComment = this._docThreadCommentService.addingComment;
330
- const activeComment = this._threadCommentPanelService.activeCommentId;
331
- if (addingComment && (activeComment === null || activeComment === void 0 ? void 0 : activeComment.unitId) === addingComment.unitId && (activeComment === null || activeComment === void 0 ? void 0 : activeComment.subUnitId) === "default_doc" && (activeComment === null || activeComment === void 0 ? void 0 : activeComment.commentId) === addingComment.id) return;
332
- this._commandService.executeCommand(_univerjs_thread_comment_ui.SetActiveCommentOperation.id);
333
- }
334
- }));
335
- }
336
- _initActiveCommandChange() {
337
- this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe((activeComment) => {
338
- var _this$_docThreadComme;
339
- if (activeComment) {
340
- const doc = this._univerInstanceService.getUnit(activeComment.unitId);
341
- if (doc) {
342
- var _this$_renderManagerS, _doc$getBody3;
343
- const backScrollController = (_this$_renderManagerS = this._renderManagerService.getRenderById(activeComment.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs_ui.DocBackScrollRenderController);
344
- const customRange = (_doc$getBody3 = doc.getBody()) === null || _doc$getBody3 === void 0 || (_doc$getBody3 = _doc$getBody3.customDecorations) === null || _doc$getBody3 === void 0 ? void 0 : _doc$getBody3.find((range) => range.id === activeComment.commentId);
345
- if (customRange && backScrollController) backScrollController.scrollToRange({
346
- startOffset: customRange.startIndex,
347
- endOffset: customRange.endIndex,
348
- collapsed: false
349
- });
350
- }
351
- }
352
- if (!activeComment || activeComment.commentId !== ((_this$_docThreadComme = this._docThreadCommentService.addingComment) === null || _this$_docThreadComme === void 0 ? void 0 : _this$_docThreadComme.id)) this._docThreadCommentService.endAdd();
353
- }));
354
- }
355
- };
356
- DocThreadCommentSelectionController = __decorate([
357
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_thread_comment_ui.ThreadCommentPanelService)),
358
- __decorateParam(1, _univerjs_core.IUniverInstanceService),
359
- __decorateParam(2, _univerjs_core.ICommandService),
360
- __decorateParam(3, (0, _univerjs_core.Inject)(DocThreadCommentService)),
361
- __decorateParam(4, _univerjs_engine_render.IRenderManagerService),
362
- __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_thread_comment.ThreadCommentModel))
363
- ], DocThreadCommentSelectionController);
364
-
365
284
  //#endregion
366
285
  //#region src/menu/menu.ts
367
286
  const shouldDisableAddComment = (accessor) => {
@@ -405,20 +324,7 @@ function ToolbarDocCommentMenuItemFactory(accessor) {
405
324
  }
406
325
 
407
326
  //#endregion
408
- //#region src/menu/schema.ts
409
- const menuSchema = {
410
- [_univerjs_ui.RibbonInsertGroup.MEDIA]: { [ToggleCommentPanelOperation.id]: {
411
- order: 3,
412
- menuItemFactory: ToolbarDocCommentMenuItemFactory
413
- } },
414
- [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.DATA]: { [StartAddCommentOperation.id]: {
415
- order: 1,
416
- menuItemFactory: AddDocCommentMenuItemFactory
417
- } } }
418
- };
419
-
420
- //#endregion
421
- //#region src/views/doc-thread-comment-panel/index.tsx
327
+ //#region src/views/DocThreadCommentPanel.tsx
422
328
  const DocThreadCommentPanel = () => {
423
329
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
424
330
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
@@ -497,7 +403,7 @@ const DocThreadCommentPanel = () => {
497
403
  };
498
404
 
499
405
  //#endregion
500
- //#region src/controllers/doc-thread-comment-ui.controller.ts
406
+ //#region src/controllers/components.controller.ts
501
407
  /**
502
408
  * Copyright 2023-present DreamNum Co., Ltd.
503
409
  *
@@ -513,41 +419,105 @@ const DocThreadCommentPanel = () => {
513
419
  * See the License for the specific language governing permissions and
514
420
  * limitations under the License.
515
421
  */
516
- let DocThreadCommentUIController = class DocThreadCommentUIController extends _univerjs_core.Disposable {
517
- constructor(_commandService, _menuManagerService, _componentManager) {
422
+ let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
423
+ constructor(_componentManager, _iconManager) {
518
424
  super();
519
- this._commandService = _commandService;
520
- this._menuManagerService = _menuManagerService;
521
425
  this._componentManager = _componentManager;
522
- this._initCommands();
523
- this._initMenus();
524
- this._initComponents();
426
+ this._iconManager = _iconManager;
427
+ this._registerComponents();
428
+ this._registerIcons();
525
429
  }
526
- _initCommands() {
527
- [
528
- AddDocCommentComment,
529
- DeleteDocCommentComment,
530
- ShowCommentPanelOperation,
531
- StartAddCommentOperation,
532
- ToggleCommentPanelOperation
533
- ].forEach((command) => {
534
- this.disposeWithMe(this._commandService.registerCommand(command));
430
+ _registerComponents() {
431
+ [[DOCS_THREAD_COMMENT_PANEL, DocThreadCommentPanel]].forEach(([id, comp]) => {
432
+ this.disposeWithMe(this._componentManager.register(id, comp));
535
433
  });
536
434
  }
537
- _initMenus() {
538
- this._menuManagerService.mergeMenu(menuSchema);
435
+ _registerIcons() {
436
+ this.disposeWithMe(this._iconManager.register({ CommentIcon: _univerjs_icons.CommentIcon }));
539
437
  }
540
- _initComponents() {
541
- [[DOCS_THREAD_COMMENT_PANEL, DocThreadCommentPanel], ["CommentIcon", _univerjs_icons.CommentIcon]].forEach(([id, comp]) => {
542
- this.disposeWithMe(this._componentManager.register(id, comp));
543
- });
438
+ };
439
+ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
440
+
441
+ //#endregion
442
+ //#region src/controllers/doc-thread-comment-selection.controller.ts
443
+ let DocThreadCommentSelectionController = class DocThreadCommentSelectionController extends _univerjs_core.Disposable {
444
+ constructor(_threadCommentPanelService, _univerInstanceService, _commandService, _docThreadCommentService, _renderManagerService, _threadCommentModel) {
445
+ super();
446
+ this._threadCommentPanelService = _threadCommentPanelService;
447
+ this._univerInstanceService = _univerInstanceService;
448
+ this._commandService = _commandService;
449
+ this._docThreadCommentService = _docThreadCommentService;
450
+ this._renderManagerService = _renderManagerService;
451
+ this._threadCommentModel = _threadCommentModel;
452
+ this._initSelectionChange();
453
+ this._initActiveCommandChange();
454
+ }
455
+ _initSelectionChange() {
456
+ let lastSelection;
457
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
458
+ if (commandInfo.id === _univerjs_docs.SetTextSelectionsOperation.id) {
459
+ const { unitId, ranges } = commandInfo.params;
460
+ if ((0, _univerjs_core.isInternalEditorID)(unitId)) return;
461
+ const doc = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
462
+ const primary = ranges[0];
463
+ if ((lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.startOffset) === (primary === null || primary === void 0 ? void 0 : primary.startOffset) && (lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.endOffset) === (primary === null || primary === void 0 ? void 0 : primary.endOffset)) return;
464
+ lastSelection = primary;
465
+ if (primary && doc) {
466
+ const { startOffset, endOffset, collapsed } = primary;
467
+ let customRange;
468
+ if (collapsed) {
469
+ var _doc$getBody;
470
+ customRange = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 || (_doc$getBody = _doc$getBody.customDecorations) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1);
471
+ } else {
472
+ var _doc$getBody2;
473
+ customRange = (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 || (_doc$getBody2 = _doc$getBody2.customDecorations) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1);
474
+ }
475
+ if (customRange) {
476
+ const comment = this._threadCommentModel.getComment(unitId, DEFAULT_DOC_SUBUNIT_ID, customRange.id);
477
+ if (comment && !comment.resolved) this._commandService.executeCommand(ShowCommentPanelOperation.id, { activeComment: {
478
+ unitId,
479
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
480
+ commentId: customRange.id
481
+ } });
482
+ return;
483
+ }
484
+ }
485
+ if (!this._threadCommentPanelService.activeCommentId) return;
486
+ const addingComment = this._docThreadCommentService.addingComment;
487
+ const activeComment = this._threadCommentPanelService.activeCommentId;
488
+ if (addingComment && (activeComment === null || activeComment === void 0 ? void 0 : activeComment.unitId) === addingComment.unitId && (activeComment === null || activeComment === void 0 ? void 0 : activeComment.subUnitId) === "default_doc" && (activeComment === null || activeComment === void 0 ? void 0 : activeComment.commentId) === addingComment.id) return;
489
+ this._commandService.executeCommand(_univerjs_thread_comment_ui.SetActiveCommentOperation.id);
490
+ }
491
+ }));
492
+ }
493
+ _initActiveCommandChange() {
494
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe((activeComment) => {
495
+ var _this$_docThreadComme;
496
+ if (activeComment) {
497
+ const doc = this._univerInstanceService.getUnit(activeComment.unitId);
498
+ if (doc) {
499
+ var _this$_renderManagerS, _doc$getBody3;
500
+ const backScrollController = (_this$_renderManagerS = this._renderManagerService.getRenderById(activeComment.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs_ui.DocBackScrollRenderController);
501
+ const customRange = (_doc$getBody3 = doc.getBody()) === null || _doc$getBody3 === void 0 || (_doc$getBody3 = _doc$getBody3.customDecorations) === null || _doc$getBody3 === void 0 ? void 0 : _doc$getBody3.find((range) => range.id === activeComment.commentId);
502
+ if (customRange && backScrollController) backScrollController.scrollToRange({
503
+ startOffset: customRange.startIndex,
504
+ endOffset: customRange.endIndex,
505
+ collapsed: false
506
+ });
507
+ }
508
+ }
509
+ if (!activeComment || activeComment.commentId !== ((_this$_docThreadComme = this._docThreadCommentService.addingComment) === null || _this$_docThreadComme === void 0 ? void 0 : _this$_docThreadComme.id)) this._docThreadCommentService.endAdd();
510
+ }));
544
511
  }
545
512
  };
546
- DocThreadCommentUIController = __decorate([
547
- __decorateParam(0, _univerjs_core.ICommandService),
548
- __decorateParam(1, _univerjs_ui.IMenuManagerService),
549
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))
550
- ], DocThreadCommentUIController);
513
+ DocThreadCommentSelectionController = __decorate([
514
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_thread_comment_ui.ThreadCommentPanelService)),
515
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
516
+ __decorateParam(2, _univerjs_core.ICommandService),
517
+ __decorateParam(3, (0, _univerjs_core.Inject)(DocThreadCommentService)),
518
+ __decorateParam(4, _univerjs_engine_render.IRenderManagerService),
519
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_thread_comment.ThreadCommentModel))
520
+ ], DocThreadCommentSelectionController);
551
521
 
552
522
  //#endregion
553
523
  //#region src/controllers/render-controllers/render.controller.ts
@@ -634,6 +604,66 @@ DocThreadCommentRenderController = __decorate([
634
604
  __decorateParam(6, _univerjs_core.ICommandService)
635
605
  ], DocThreadCommentRenderController);
636
606
 
607
+ //#endregion
608
+ //#region src/menu/schema.ts
609
+ const menuSchema = {
610
+ [_univerjs_ui.RibbonInsertGroup.MEDIA]: { [ToggleCommentPanelOperation.id]: {
611
+ order: 3,
612
+ menuItemFactory: ToolbarDocCommentMenuItemFactory
613
+ } },
614
+ [_univerjs_docs_ui.FLOAT_TOOLBAR_MENU_POSITION]: { [StartAddCommentOperation.id]: {
615
+ order: 21,
616
+ menuItemFactory: AddDocCommentMenuItemFactory
617
+ } },
618
+ [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.DATA]: { [StartAddCommentOperation.id]: {
619
+ order: 1,
620
+ menuItemFactory: AddDocCommentMenuItemFactory
621
+ } } }
622
+ };
623
+
624
+ //#endregion
625
+ //#region src/controllers/ui.controller.ts
626
+ /**
627
+ * Copyright 2023-present DreamNum Co., Ltd.
628
+ *
629
+ * Licensed under the Apache License, Version 2.0 (the "License");
630
+ * you may not use this file except in compliance with the License.
631
+ * You may obtain a copy of the License at
632
+ *
633
+ * http://www.apache.org/licenses/LICENSE-2.0
634
+ *
635
+ * Unless required by applicable law or agreed to in writing, software
636
+ * distributed under the License is distributed on an "AS IS" BASIS,
637
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
638
+ * See the License for the specific language governing permissions and
639
+ * limitations under the License.
640
+ */
641
+ let DocThreadCommentUIController = class DocThreadCommentUIController extends _univerjs_core.Disposable {
642
+ constructor(_commandService, _menuManagerService) {
643
+ super();
644
+ this._commandService = _commandService;
645
+ this._menuManagerService = _menuManagerService;
646
+ this._initCommands();
647
+ this._initMenus();
648
+ }
649
+ _initCommands() {
650
+ [
651
+ AddDocCommentComment,
652
+ DeleteDocCommentComment,
653
+ ShowCommentPanelOperation,
654
+ StartAddCommentOperation,
655
+ ToggleCommentPanelOperation
656
+ ].forEach((command) => {
657
+ this.disposeWithMe(this._commandService.registerCommand(command));
658
+ });
659
+ }
660
+ _initMenus() {
661
+ this._menuManagerService.appendRootMenu({ [_univerjs_docs_ui.FLOAT_TOOLBAR_MENU_POSITION]: {} });
662
+ this._menuManagerService.mergeMenu(menuSchema);
663
+ }
664
+ };
665
+ DocThreadCommentUIController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, _univerjs_ui.IMenuManagerService)], DocThreadCommentUIController);
666
+
637
667
  //#endregion
638
668
  //#region src/plugin.ts
639
669
  let UniverDocsThreadCommentUIPlugin = class UniverDocsThreadCommentUIPlugin extends _univerjs_core.Plugin {
@@ -648,6 +678,8 @@ let UniverDocsThreadCommentUIPlugin = class UniverDocsThreadCommentUIPlugin exte
648
678
  this._configService.setConfig(DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY, rest);
649
679
  }
650
680
  onStarting() {
681
+ this._injector.add([ComponentsController]);
682
+ this._injector.get(ComponentsController);
651
683
  [
652
684
  [DocThreadCommentUIController],
653
685
  [DocThreadCommentSelectionController],