@univerjs/sheets-thread-comment 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.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/es/facade.js CHANGED
@@ -1,6 +1,8 @@
1
- import { CanceledError, ICommandService, IUniverInstanceService, Inject, Injector, Range, RichTextBuilder, RichTextValue, Tools, UniverInstanceType, UserManagerService, generateRandomId } from "@univerjs/core";
1
+ import * as UniverCore from "@univerjs/core";
2
+ import { CanceledError, ICommandService, IUniverInstanceService, Inject, Injector, RichTextBuilder, RichTextValue, Tools, UniverInstanceType, UserManagerService, generateRandomId } from "@univerjs/core";
2
3
  import { SheetsThreadCommentModel } from "@univerjs/sheets-thread-comment";
3
4
  import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
5
+ import * as ThreadComment from "@univerjs/thread-comment";
4
6
  import { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, ResolveCommentCommand, ThreadCommentModel, UpdateCommentCommand, getDT } from "@univerjs/thread-comment";
5
7
  import { deserializeRangeWithSheet } from "@univerjs/engine-formula";
6
8
  import { FEventName, FUniver } from "@univerjs/core/facade";
@@ -605,69 +607,98 @@ FThreadComment = _FThreadComment = __decorate([
605
607
  //#endregion
606
608
  //#region src/facade/f-range.ts
607
609
  /**
610
+ * Copyright 2023-present DreamNum Co., Ltd.
611
+ *
612
+ * Licensed under the Apache License, Version 2.0 (the "License");
613
+ * you may not use this file except in compliance with the License.
614
+ * You may obtain a copy of the License at
615
+ *
616
+ * http://www.apache.org/licenses/LICENSE-2.0
617
+ *
618
+ * Unless required by applicable law or agreed to in writing, software
619
+ * distributed under the License is distributed on an "AS IS" BASIS,
620
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
621
+ * See the License for the specific language governing permissions and
622
+ * limitations under the License.
623
+ */
624
+ function firstNonEmpty(...values) {
625
+ for (const value of values) if (value) return value;
626
+ return UniverCore.generateRandomId();
627
+ }
628
+ /**
608
629
  * @ignore
609
630
  */
610
631
  var FRangeSheetsThreadCommentMixin = class extends FRange {
611
- getComment() {
612
- const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel);
613
- const unitId = this._workbook.getUnitId();
614
- const sheetId = this._worksheet.getSheetId();
615
- const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
616
- if (!commentId) return null;
617
- const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
618
- if (comment) return this._injector.createInstance(FThreadComment, comment);
619
- return null;
632
+ _initialize(injector) {
633
+ let dependencies;
634
+ Object.defineProperty(this, "_dependencies", { get: () => dependencies ??= {
635
+ commandService: injector.get(UniverCore.ICommandService),
636
+ model: injector.get(SheetsThreadCommentModel),
637
+ userManagerService: injector.get(UniverCore.UserManagerService)
638
+ } });
620
639
  }
621
- getComments() {
622
- const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel);
640
+ _getCommentDataInRange() {
641
+ const model = this._dependencies.model;
623
642
  const unitId = this._workbook.getUnitId();
624
643
  const sheetId = this._worksheet.getSheetId();
625
644
  const comments = [];
626
- Range.foreach(this._range, (row, col) => {
627
- const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, row, col);
628
- if (commentId) {
629
- const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
630
- if (comment) comments.push(this._injector.createInstance(FThreadComment, comment));
631
- }
645
+ UniverCore.Range.foreach(this._range, (row, col) => {
646
+ const commentId = model.getByLocation(unitId, sheetId, row, col);
647
+ const comment = commentId ? model.getComment(unitId, sheetId, commentId) : null;
648
+ if (comment) comments.push(comment);
632
649
  });
633
650
  return comments;
634
651
  }
635
- addCommentAsync(content) {
636
- var _this$getComment;
637
- const injector = this._injector;
638
- const currentComment = (_this$getComment = this.getComment()) === null || _this$getComment === void 0 ? void 0 : _this$getComment.getCommentData();
639
- const commentService = injector.get(ICommandService);
640
- const userService = injector.get(UserManagerService);
652
+ _getStartCellCommentData() {
653
+ const model = this._dependencies.model;
654
+ const unitId = this._workbook.getUnitId();
655
+ const sheetId = this._worksheet.getSheetId();
656
+ const commentId = model.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
657
+ return commentId ? model.getComment(unitId, sheetId, commentId) ?? null : null;
658
+ }
659
+ getComment() {
660
+ const comment = this._getStartCellCommentData();
661
+ return comment ? this._injector.createInstance(FThreadComment, comment) : null;
662
+ }
663
+ getComments() {
664
+ return this._getCommentDataInRange().map((comment) => this._injector.createInstance(FThreadComment, comment));
665
+ }
666
+ addCommentAsync(content, options = {}) {
667
+ const { commandService, userManagerService } = this._dependencies;
668
+ const currentComment = this._getStartCellCommentData();
641
669
  const unitId = this._workbook.getUnitId();
642
670
  const sheetId = this._worksheet.getSheetId();
643
- const refStr = `${Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`;
644
- const currentUser = userService.getCurrentUser();
645
- const commentData = content instanceof FTheadCommentBuilder ? content.build() : { text: content };
646
- return commentService.executeCommand(AddCommentCommand.id, {
671
+ const refStr = `${UniverCore.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`;
672
+ const currentUser = userManagerService.getCurrentUser();
673
+ let commentData = null;
674
+ let text;
675
+ if (content instanceof FTheadCommentBuilder) {
676
+ commentData = content.build();
677
+ text = commentData.text;
678
+ } else text = ThreadComment.normalizeThreadCommentContent(content);
679
+ return commandService.executeCommand(ThreadComment.AddCommentCommand.id, {
647
680
  unitId,
648
681
  subUnitId: sheetId,
649
682
  comment: {
650
- text: commentData.text,
651
- dT: commentData.dT || getDT(),
652
- attachments: [],
653
- id: commentData.id || generateRandomId(),
683
+ text,
684
+ dT: options.dateTime ? ThreadComment.getDT(options.dateTime) : (commentData === null || commentData === void 0 ? void 0 : commentData.dT) || ThreadComment.getDT(),
685
+ attachments: options.attachments ?? (commentData === null || commentData === void 0 ? void 0 : commentData.attachments) ?? [],
686
+ id: firstNonEmpty(options.id, commentData === null || commentData === void 0 ? void 0 : commentData.id),
654
687
  ref: refStr,
655
- personId: commentData.personId || currentUser.userID,
688
+ personId: firstNonEmpty(options.personId, commentData === null || commentData === void 0 ? void 0 : commentData.personId, currentUser.userID),
656
689
  parentId: currentComment === null || currentComment === void 0 ? void 0 : currentComment.id,
657
690
  unitId,
658
691
  subUnitId: sheetId,
659
- threadId: (currentComment === null || currentComment === void 0 ? void 0 : currentComment.threadId) || generateRandomId()
692
+ threadId: firstNonEmpty(currentComment === null || currentComment === void 0 ? void 0 : currentComment.threadId, options.threadId, commentData === null || commentData === void 0 ? void 0 : commentData.threadId)
660
693
  }
661
694
  });
662
695
  }
663
696
  clearCommentAsync() {
664
- var _this$getComment2;
665
- const injector = this._injector;
666
- const currentComment = (_this$getComment2 = this.getComment()) === null || _this$getComment2 === void 0 ? void 0 : _this$getComment2.getCommentData();
667
- const commentService = injector.get(ICommandService);
697
+ const { commandService } = this._dependencies;
698
+ const currentComment = this._getStartCellCommentData();
668
699
  const unitId = this._workbook.getUnitId();
669
700
  const sheetId = this._worksheet.getSheetId();
670
- if (currentComment) return commentService.executeCommand(DeleteCommentTreeCommand.id, {
701
+ if (currentComment) return commandService.executeCommand(ThreadComment.DeleteCommentTreeCommand.id, {
671
702
  unitId,
672
703
  subUnitId: sheetId,
673
704
  threadId: currentComment.threadId,
@@ -675,9 +706,16 @@ var FRangeSheetsThreadCommentMixin = class extends FRange {
675
706
  });
676
707
  return Promise.resolve(true);
677
708
  }
678
- clearCommentsAsync() {
679
- const promises = this.getComments().map((comment) => comment.deleteAsync());
680
- return Promise.all(promises).then(() => true);
709
+ async clearCommentsAsync() {
710
+ const { commandService } = this._dependencies;
711
+ const unitId = this._workbook.getUnitId();
712
+ const subUnitId = this._worksheet.getSheetId();
713
+ return (await Promise.all(this._getCommentDataInRange().map((comment) => commandService.executeCommand(ThreadComment.DeleteCommentTreeCommand.id, {
714
+ unitId,
715
+ subUnitId,
716
+ threadId: comment.threadId,
717
+ commentId: comment.id
718
+ })))).every(Boolean);
681
719
  }
682
720
  };
683
721
  FRange.extend(FRangeSheetsThreadCommentMixin);
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { DependentOn, Disposable, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, UniverInstanceType, generateRandomId, merge, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
1
+ import { DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, UniverInstanceType, generateRandomId, merge, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { serializeRange, singleReferenceToGrid } from "@univerjs/engine-formula";
3
3
  import { CopySheetCommand, RefRangeService, RemoveSheetCommand, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests } from "@univerjs/sheets";
4
- import { AddCommentMutation, DeleteCommentMutation, IThreadCommentDataSourceService, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentRefMutation } from "@univerjs/thread-comment";
4
+ import { AddCommentMutation, DeleteCommentMutation, IThreadCommentDataSourceService, TC_PLUGIN_NAME, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentRefMutation, createThreadCommentResourceHook, deserializeThreadCommentAnchor } from "@univerjs/thread-comment";
5
5
  import { Subject } from "rxjs";
6
6
 
7
7
  //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
@@ -136,6 +136,7 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
136
136
  }
137
137
  }
138
138
  _addComment(unitId, subUnitId, comment) {
139
+ if (deserializeThreadCommentAnchor(comment.ref)) return;
139
140
  const location = singleReferenceToGrid(comment.ref);
140
141
  const parentId = comment.parentId;
141
142
  const { row, column } = location;
@@ -170,6 +171,7 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
170
171
  break;
171
172
  case "delete": {
172
173
  const { isRoot, comment } = update.payload;
174
+ if (deserializeThreadCommentAnchor(comment.ref)) return;
173
175
  if (isRoot) {
174
176
  const location = singleReferenceToGrid(comment.ref);
175
177
  const { row, column } = location;
@@ -185,6 +187,7 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
185
187
  const { commentId } = update.payload;
186
188
  const comment = this._threadCommentModel.getComment(unitId, subUnitId, commentId);
187
189
  if (!comment) return;
190
+ if (deserializeThreadCommentAnchor(comment.ref)) return;
188
191
  const location = singleReferenceToGrid(comment.ref);
189
192
  this._commentUpdate$.next({
190
193
  ...update,
@@ -193,6 +196,7 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
193
196
  break;
194
197
  }
195
198
  case "updateRef": {
199
+ if (deserializeThreadCommentAnchor(update.payload.ref)) return;
196
200
  const location = singleReferenceToGrid(update.payload.ref);
197
201
  const { commentId } = update.payload;
198
202
  const currentLoc = locationMap.get(commentId);
@@ -228,8 +232,9 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
228
232
  }));
229
233
  }
230
234
  getByLocation(unitId, subUnitId, row, column) {
231
- var _activeComments$;
232
- return (_activeComments$ = this.getAllByLocation(unitId, subUnitId, row, column).filter((comment) => !comment.resolved)[0]) === null || _activeComments$ === void 0 ? void 0 : _activeComments$.id;
235
+ var _activeComments;
236
+ const activeComments = this.getAllByLocation(unitId, subUnitId, row, column).filter((comment) => !comment.resolved);
237
+ return (_activeComments = activeComments[activeComments.length - 1]) === null || _activeComments === void 0 ? void 0 : _activeComments.id;
233
238
  }
234
239
  getAllByLocation(unitId, subUnitId, row, column) {
235
240
  const current = this._ensureCommentMatrix(unitId, subUnitId).getValue(row, column);
@@ -383,6 +388,7 @@ let SheetsThreadCommentRefRangeController = class SheetsThreadCommentRefRangeCon
383
388
  const datas = this._threadCommentModel.getAll();
384
389
  for (const data of datas) for (const thread of data.threads) {
385
390
  const { unitId, subUnitId, root } = thread;
391
+ if (deserializeThreadCommentAnchor(root.ref)) continue;
386
392
  const pos = singleReferenceToGrid(root.ref);
387
393
  const sheetComment = {
388
394
  ...root,
@@ -446,12 +452,7 @@ SheetsThreadCommentRefRangeController = __decorate([
446
452
  ], SheetsThreadCommentRefRangeController);
447
453
 
448
454
  //#endregion
449
- //#region package.json
450
- var name = "@univerjs/sheets-thread-comment";
451
- var version = "1.0.0-insiders.20260809-70eefdd";
452
-
453
- //#endregion
454
- //#region src/config/config.ts
455
+ //#region src/types/const.ts
455
456
  /**
456
457
  * Copyright 2023-present DreamNum Co., Ltd.
457
458
  *
@@ -467,21 +468,25 @@ var version = "1.0.0-insiders.20260809-70eefdd";
467
468
  * See the License for the specific language governing permissions and
468
469
  * limitations under the License.
469
470
  */
470
- const SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "sheets-thread-comment.config";
471
- const configSymbol = Symbol(SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
472
- const defaultPluginConfig = {};
471
+ const SHEET_THREAD_COMMENT_BASE = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
472
+ const SHEET_UNIVER_THREAD_COMMENT_PLUGIN = `SHEET_${TC_PLUGIN_NAME}`;
473
473
 
474
474
  //#endregion
475
475
  //#region src/controllers/sheets-thread-comment-resource.controller.ts
476
476
  let SheetsThreadCommentResourceController = class SheetsThreadCommentResourceController extends Disposable {
477
- constructor(_univerInstanceService, _sheetInterceptorService, _threadCommentModel, _threadCommentDataSourceService) {
477
+ constructor(_resourceManagerService, _univerInstanceService, _sheetInterceptorService, _threadCommentModel, _threadCommentDataSourceService) {
478
478
  super();
479
+ this._resourceManagerService = _resourceManagerService;
479
480
  this._univerInstanceService = _univerInstanceService;
480
481
  this._sheetInterceptorService = _sheetInterceptorService;
481
482
  this._threadCommentModel = _threadCommentModel;
482
483
  this._threadCommentDataSourceService = _threadCommentDataSourceService;
484
+ this._initSnapshot();
483
485
  this._initSheetChange();
484
486
  }
487
+ _initSnapshot() {
488
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource(createThreadCommentResourceHook(this._threadCommentModel, this._threadCommentDataSourceService, SHEET_UNIVER_THREAD_COMMENT_PLUGIN, [UniverInstanceType.UNIVER_SHEET])));
489
+ }
485
490
  _initSheetChange() {
486
491
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
487
492
  if (commandInfo.id === RemoveSheetCommand.id) {
@@ -577,14 +582,20 @@ let SheetsThreadCommentResourceController = class SheetsThreadCommentResourceCon
577
582
  }
578
583
  };
579
584
  SheetsThreadCommentResourceController = __decorate([
580
- __decorateParam(0, IUniverInstanceService),
581
- __decorateParam(1, Inject(SheetInterceptorService)),
582
- __decorateParam(2, Inject(ThreadCommentModel)),
583
- __decorateParam(3, IThreadCommentDataSourceService)
585
+ __decorateParam(0, IResourceManagerService),
586
+ __decorateParam(1, IUniverInstanceService),
587
+ __decorateParam(2, Inject(SheetInterceptorService)),
588
+ __decorateParam(3, Inject(ThreadCommentModel)),
589
+ __decorateParam(4, IThreadCommentDataSourceService)
584
590
  ], SheetsThreadCommentResourceController);
585
591
 
586
592
  //#endregion
587
- //#region src/types/const.ts
593
+ //#region package.json
594
+ var name = "@univerjs/sheets-thread-comment";
595
+ var version = "1.0.0-rc.0";
596
+
597
+ //#endregion
598
+ //#region src/config/config.ts
588
599
  /**
589
600
  * Copyright 2023-present DreamNum Co., Ltd.
590
601
  *
@@ -600,7 +611,9 @@ SheetsThreadCommentResourceController = __decorate([
600
611
  * See the License for the specific language governing permissions and
601
612
  * limitations under the License.
602
613
  */
603
- const SHEET_THREAD_COMMENT_BASE = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
614
+ const SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "sheets-thread-comment.config";
615
+ const configSymbol = Symbol(SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
616
+ const defaultPluginConfig = {};
604
617
 
605
618
  //#endregion
606
619
  //#region src/plugin.ts
@@ -637,4 +650,4 @@ UniverSheetsThreadCommentPlugin = __decorate([
637
650
  ], UniverSheetsThreadCommentPlugin);
638
651
 
639
652
  //#endregion
640
- export { SheetsThreadCommentModel, SheetsThreadCommentRefRangeController, UniverSheetsThreadCommentPlugin };
653
+ export { SHEET_UNIVER_THREAD_COMMENT_PLUGIN, SheetsThreadCommentModel, SheetsThreadCommentRefRangeController, SheetsThreadCommentResourceController, UniverSheetsThreadCommentPlugin };
package/lib/facade.js CHANGED
@@ -1,6 +1,8 @@
1
- import { CanceledError, ICommandService, IUniverInstanceService, Inject, Injector, Range, RichTextBuilder, RichTextValue, Tools, UniverInstanceType, UserManagerService, generateRandomId } from "@univerjs/core";
1
+ import * as UniverCore from "@univerjs/core";
2
+ import { CanceledError, ICommandService, IUniverInstanceService, Inject, Injector, RichTextBuilder, RichTextValue, Tools, UniverInstanceType, UserManagerService, generateRandomId } from "@univerjs/core";
2
3
  import { SheetsThreadCommentModel } from "@univerjs/sheets-thread-comment";
3
4
  import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
5
+ import * as ThreadComment from "@univerjs/thread-comment";
4
6
  import { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, ResolveCommentCommand, ThreadCommentModel, UpdateCommentCommand, getDT } from "@univerjs/thread-comment";
5
7
  import { deserializeRangeWithSheet } from "@univerjs/engine-formula";
6
8
  import { FEventName, FUniver } from "@univerjs/core/facade";
@@ -605,69 +607,98 @@ FThreadComment = _FThreadComment = __decorate([
605
607
  //#endregion
606
608
  //#region src/facade/f-range.ts
607
609
  /**
610
+ * Copyright 2023-present DreamNum Co., Ltd.
611
+ *
612
+ * Licensed under the Apache License, Version 2.0 (the "License");
613
+ * you may not use this file except in compliance with the License.
614
+ * You may obtain a copy of the License at
615
+ *
616
+ * http://www.apache.org/licenses/LICENSE-2.0
617
+ *
618
+ * Unless required by applicable law or agreed to in writing, software
619
+ * distributed under the License is distributed on an "AS IS" BASIS,
620
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
621
+ * See the License for the specific language governing permissions and
622
+ * limitations under the License.
623
+ */
624
+ function firstNonEmpty(...values) {
625
+ for (const value of values) if (value) return value;
626
+ return UniverCore.generateRandomId();
627
+ }
628
+ /**
608
629
  * @ignore
609
630
  */
610
631
  var FRangeSheetsThreadCommentMixin = class extends FRange {
611
- getComment() {
612
- const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel);
613
- const unitId = this._workbook.getUnitId();
614
- const sheetId = this._worksheet.getSheetId();
615
- const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
616
- if (!commentId) return null;
617
- const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
618
- if (comment) return this._injector.createInstance(FThreadComment, comment);
619
- return null;
632
+ _initialize(injector) {
633
+ let dependencies;
634
+ Object.defineProperty(this, "_dependencies", { get: () => dependencies ??= {
635
+ commandService: injector.get(UniverCore.ICommandService),
636
+ model: injector.get(SheetsThreadCommentModel),
637
+ userManagerService: injector.get(UniverCore.UserManagerService)
638
+ } });
620
639
  }
621
- getComments() {
622
- const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel);
640
+ _getCommentDataInRange() {
641
+ const model = this._dependencies.model;
623
642
  const unitId = this._workbook.getUnitId();
624
643
  const sheetId = this._worksheet.getSheetId();
625
644
  const comments = [];
626
- Range.foreach(this._range, (row, col) => {
627
- const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, row, col);
628
- if (commentId) {
629
- const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
630
- if (comment) comments.push(this._injector.createInstance(FThreadComment, comment));
631
- }
645
+ UniverCore.Range.foreach(this._range, (row, col) => {
646
+ const commentId = model.getByLocation(unitId, sheetId, row, col);
647
+ const comment = commentId ? model.getComment(unitId, sheetId, commentId) : null;
648
+ if (comment) comments.push(comment);
632
649
  });
633
650
  return comments;
634
651
  }
635
- addCommentAsync(content) {
636
- var _this$getComment;
637
- const injector = this._injector;
638
- const currentComment = (_this$getComment = this.getComment()) === null || _this$getComment === void 0 ? void 0 : _this$getComment.getCommentData();
639
- const commentService = injector.get(ICommandService);
640
- const userService = injector.get(UserManagerService);
652
+ _getStartCellCommentData() {
653
+ const model = this._dependencies.model;
654
+ const unitId = this._workbook.getUnitId();
655
+ const sheetId = this._worksheet.getSheetId();
656
+ const commentId = model.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
657
+ return commentId ? model.getComment(unitId, sheetId, commentId) ?? null : null;
658
+ }
659
+ getComment() {
660
+ const comment = this._getStartCellCommentData();
661
+ return comment ? this._injector.createInstance(FThreadComment, comment) : null;
662
+ }
663
+ getComments() {
664
+ return this._getCommentDataInRange().map((comment) => this._injector.createInstance(FThreadComment, comment));
665
+ }
666
+ addCommentAsync(content, options = {}) {
667
+ const { commandService, userManagerService } = this._dependencies;
668
+ const currentComment = this._getStartCellCommentData();
641
669
  const unitId = this._workbook.getUnitId();
642
670
  const sheetId = this._worksheet.getSheetId();
643
- const refStr = `${Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`;
644
- const currentUser = userService.getCurrentUser();
645
- const commentData = content instanceof FTheadCommentBuilder ? content.build() : { text: content };
646
- return commentService.executeCommand(AddCommentCommand.id, {
671
+ const refStr = `${UniverCore.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`;
672
+ const currentUser = userManagerService.getCurrentUser();
673
+ let commentData = null;
674
+ let text;
675
+ if (content instanceof FTheadCommentBuilder) {
676
+ commentData = content.build();
677
+ text = commentData.text;
678
+ } else text = ThreadComment.normalizeThreadCommentContent(content);
679
+ return commandService.executeCommand(ThreadComment.AddCommentCommand.id, {
647
680
  unitId,
648
681
  subUnitId: sheetId,
649
682
  comment: {
650
- text: commentData.text,
651
- dT: commentData.dT || getDT(),
652
- attachments: [],
653
- id: commentData.id || generateRandomId(),
683
+ text,
684
+ dT: options.dateTime ? ThreadComment.getDT(options.dateTime) : (commentData === null || commentData === void 0 ? void 0 : commentData.dT) || ThreadComment.getDT(),
685
+ attachments: options.attachments ?? (commentData === null || commentData === void 0 ? void 0 : commentData.attachments) ?? [],
686
+ id: firstNonEmpty(options.id, commentData === null || commentData === void 0 ? void 0 : commentData.id),
654
687
  ref: refStr,
655
- personId: commentData.personId || currentUser.userID,
688
+ personId: firstNonEmpty(options.personId, commentData === null || commentData === void 0 ? void 0 : commentData.personId, currentUser.userID),
656
689
  parentId: currentComment === null || currentComment === void 0 ? void 0 : currentComment.id,
657
690
  unitId,
658
691
  subUnitId: sheetId,
659
- threadId: (currentComment === null || currentComment === void 0 ? void 0 : currentComment.threadId) || generateRandomId()
692
+ threadId: firstNonEmpty(currentComment === null || currentComment === void 0 ? void 0 : currentComment.threadId, options.threadId, commentData === null || commentData === void 0 ? void 0 : commentData.threadId)
660
693
  }
661
694
  });
662
695
  }
663
696
  clearCommentAsync() {
664
- var _this$getComment2;
665
- const injector = this._injector;
666
- const currentComment = (_this$getComment2 = this.getComment()) === null || _this$getComment2 === void 0 ? void 0 : _this$getComment2.getCommentData();
667
- const commentService = injector.get(ICommandService);
697
+ const { commandService } = this._dependencies;
698
+ const currentComment = this._getStartCellCommentData();
668
699
  const unitId = this._workbook.getUnitId();
669
700
  const sheetId = this._worksheet.getSheetId();
670
- if (currentComment) return commentService.executeCommand(DeleteCommentTreeCommand.id, {
701
+ if (currentComment) return commandService.executeCommand(ThreadComment.DeleteCommentTreeCommand.id, {
671
702
  unitId,
672
703
  subUnitId: sheetId,
673
704
  threadId: currentComment.threadId,
@@ -675,9 +706,16 @@ var FRangeSheetsThreadCommentMixin = class extends FRange {
675
706
  });
676
707
  return Promise.resolve(true);
677
708
  }
678
- clearCommentsAsync() {
679
- const promises = this.getComments().map((comment) => comment.deleteAsync());
680
- return Promise.all(promises).then(() => true);
709
+ async clearCommentsAsync() {
710
+ const { commandService } = this._dependencies;
711
+ const unitId = this._workbook.getUnitId();
712
+ const subUnitId = this._worksheet.getSheetId();
713
+ return (await Promise.all(this._getCommentDataInRange().map((comment) => commandService.executeCommand(ThreadComment.DeleteCommentTreeCommand.id, {
714
+ unitId,
715
+ subUnitId,
716
+ threadId: comment.threadId,
717
+ commentId: comment.id
718
+ })))).every(Boolean);
681
719
  }
682
720
  };
683
721
  FRange.extend(FRangeSheetsThreadCommentMixin);
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { DependentOn, Disposable, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, UniverInstanceType, generateRandomId, merge, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
1
+ import { DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, UniverInstanceType, generateRandomId, merge, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { serializeRange, singleReferenceToGrid } from "@univerjs/engine-formula";
3
3
  import { CopySheetCommand, RefRangeService, RemoveSheetCommand, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests } from "@univerjs/sheets";
4
- import { AddCommentMutation, DeleteCommentMutation, IThreadCommentDataSourceService, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentRefMutation } from "@univerjs/thread-comment";
4
+ import { AddCommentMutation, DeleteCommentMutation, IThreadCommentDataSourceService, TC_PLUGIN_NAME, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentRefMutation, createThreadCommentResourceHook, deserializeThreadCommentAnchor } from "@univerjs/thread-comment";
5
5
  import { Subject } from "rxjs";
6
6
 
7
7
  //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
@@ -136,6 +136,7 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
136
136
  }
137
137
  }
138
138
  _addComment(unitId, subUnitId, comment) {
139
+ if (deserializeThreadCommentAnchor(comment.ref)) return;
139
140
  const location = singleReferenceToGrid(comment.ref);
140
141
  const parentId = comment.parentId;
141
142
  const { row, column } = location;
@@ -170,6 +171,7 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
170
171
  break;
171
172
  case "delete": {
172
173
  const { isRoot, comment } = update.payload;
174
+ if (deserializeThreadCommentAnchor(comment.ref)) return;
173
175
  if (isRoot) {
174
176
  const location = singleReferenceToGrid(comment.ref);
175
177
  const { row, column } = location;
@@ -185,6 +187,7 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
185
187
  const { commentId } = update.payload;
186
188
  const comment = this._threadCommentModel.getComment(unitId, subUnitId, commentId);
187
189
  if (!comment) return;
190
+ if (deserializeThreadCommentAnchor(comment.ref)) return;
188
191
  const location = singleReferenceToGrid(comment.ref);
189
192
  this._commentUpdate$.next({
190
193
  ...update,
@@ -193,6 +196,7 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
193
196
  break;
194
197
  }
195
198
  case "updateRef": {
199
+ if (deserializeThreadCommentAnchor(update.payload.ref)) return;
196
200
  const location = singleReferenceToGrid(update.payload.ref);
197
201
  const { commentId } = update.payload;
198
202
  const currentLoc = locationMap.get(commentId);
@@ -228,8 +232,9 @@ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable
228
232
  }));
229
233
  }
230
234
  getByLocation(unitId, subUnitId, row, column) {
231
- var _activeComments$;
232
- return (_activeComments$ = this.getAllByLocation(unitId, subUnitId, row, column).filter((comment) => !comment.resolved)[0]) === null || _activeComments$ === void 0 ? void 0 : _activeComments$.id;
235
+ var _activeComments;
236
+ const activeComments = this.getAllByLocation(unitId, subUnitId, row, column).filter((comment) => !comment.resolved);
237
+ return (_activeComments = activeComments[activeComments.length - 1]) === null || _activeComments === void 0 ? void 0 : _activeComments.id;
233
238
  }
234
239
  getAllByLocation(unitId, subUnitId, row, column) {
235
240
  const current = this._ensureCommentMatrix(unitId, subUnitId).getValue(row, column);
@@ -383,6 +388,7 @@ let SheetsThreadCommentRefRangeController = class SheetsThreadCommentRefRangeCon
383
388
  const datas = this._threadCommentModel.getAll();
384
389
  for (const data of datas) for (const thread of data.threads) {
385
390
  const { unitId, subUnitId, root } = thread;
391
+ if (deserializeThreadCommentAnchor(root.ref)) continue;
386
392
  const pos = singleReferenceToGrid(root.ref);
387
393
  const sheetComment = {
388
394
  ...root,
@@ -446,12 +452,7 @@ SheetsThreadCommentRefRangeController = __decorate([
446
452
  ], SheetsThreadCommentRefRangeController);
447
453
 
448
454
  //#endregion
449
- //#region package.json
450
- var name = "@univerjs/sheets-thread-comment";
451
- var version = "1.0.0-insiders.20260809-70eefdd";
452
-
453
- //#endregion
454
- //#region src/config/config.ts
455
+ //#region src/types/const.ts
455
456
  /**
456
457
  * Copyright 2023-present DreamNum Co., Ltd.
457
458
  *
@@ -467,21 +468,25 @@ var version = "1.0.0-insiders.20260809-70eefdd";
467
468
  * See the License for the specific language governing permissions and
468
469
  * limitations under the License.
469
470
  */
470
- const SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "sheets-thread-comment.config";
471
- const configSymbol = Symbol(SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
472
- const defaultPluginConfig = {};
471
+ const SHEET_THREAD_COMMENT_BASE = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
472
+ const SHEET_UNIVER_THREAD_COMMENT_PLUGIN = `SHEET_${TC_PLUGIN_NAME}`;
473
473
 
474
474
  //#endregion
475
475
  //#region src/controllers/sheets-thread-comment-resource.controller.ts
476
476
  let SheetsThreadCommentResourceController = class SheetsThreadCommentResourceController extends Disposable {
477
- constructor(_univerInstanceService, _sheetInterceptorService, _threadCommentModel, _threadCommentDataSourceService) {
477
+ constructor(_resourceManagerService, _univerInstanceService, _sheetInterceptorService, _threadCommentModel, _threadCommentDataSourceService) {
478
478
  super();
479
+ this._resourceManagerService = _resourceManagerService;
479
480
  this._univerInstanceService = _univerInstanceService;
480
481
  this._sheetInterceptorService = _sheetInterceptorService;
481
482
  this._threadCommentModel = _threadCommentModel;
482
483
  this._threadCommentDataSourceService = _threadCommentDataSourceService;
484
+ this._initSnapshot();
483
485
  this._initSheetChange();
484
486
  }
487
+ _initSnapshot() {
488
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource(createThreadCommentResourceHook(this._threadCommentModel, this._threadCommentDataSourceService, SHEET_UNIVER_THREAD_COMMENT_PLUGIN, [UniverInstanceType.UNIVER_SHEET])));
489
+ }
485
490
  _initSheetChange() {
486
491
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
487
492
  if (commandInfo.id === RemoveSheetCommand.id) {
@@ -577,14 +582,20 @@ let SheetsThreadCommentResourceController = class SheetsThreadCommentResourceCon
577
582
  }
578
583
  };
579
584
  SheetsThreadCommentResourceController = __decorate([
580
- __decorateParam(0, IUniverInstanceService),
581
- __decorateParam(1, Inject(SheetInterceptorService)),
582
- __decorateParam(2, Inject(ThreadCommentModel)),
583
- __decorateParam(3, IThreadCommentDataSourceService)
585
+ __decorateParam(0, IResourceManagerService),
586
+ __decorateParam(1, IUniverInstanceService),
587
+ __decorateParam(2, Inject(SheetInterceptorService)),
588
+ __decorateParam(3, Inject(ThreadCommentModel)),
589
+ __decorateParam(4, IThreadCommentDataSourceService)
584
590
  ], SheetsThreadCommentResourceController);
585
591
 
586
592
  //#endregion
587
- //#region src/types/const.ts
593
+ //#region package.json
594
+ var name = "@univerjs/sheets-thread-comment";
595
+ var version = "1.0.0-rc.0";
596
+
597
+ //#endregion
598
+ //#region src/config/config.ts
588
599
  /**
589
600
  * Copyright 2023-present DreamNum Co., Ltd.
590
601
  *
@@ -600,7 +611,9 @@ SheetsThreadCommentResourceController = __decorate([
600
611
  * See the License for the specific language governing permissions and
601
612
  * limitations under the License.
602
613
  */
603
- const SHEET_THREAD_COMMENT_BASE = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
614
+ const SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "sheets-thread-comment.config";
615
+ const configSymbol = Symbol(SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
616
+ const defaultPluginConfig = {};
604
617
 
605
618
  //#endregion
606
619
  //#region src/plugin.ts
@@ -637,4 +650,4 @@ UniverSheetsThreadCommentPlugin = __decorate([
637
650
  ], UniverSheetsThreadCommentPlugin);
638
651
 
639
652
  //#endregion
640
- export { SheetsThreadCommentModel, SheetsThreadCommentRefRangeController, UniverSheetsThreadCommentPlugin };
653
+ export { SHEET_UNIVER_THREAD_COMMENT_PLUGIN, SheetsThreadCommentModel, SheetsThreadCommentRefRangeController, SheetsThreadCommentResourceController, UniverSheetsThreadCommentPlugin };
@@ -13,14 +13,16 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Disposable, IUniverInstanceService } from '@univerjs/core';
16
+ import { Disposable, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
17
17
  import { SheetInterceptorService } from '@univerjs/sheets';
18
18
  import { IThreadCommentDataSourceService, ThreadCommentModel } from '@univerjs/thread-comment';
19
19
  export declare class SheetsThreadCommentResourceController extends Disposable {
20
+ private readonly _resourceManagerService;
20
21
  private readonly _univerInstanceService;
21
- private _sheetInterceptorService;
22
- private _threadCommentModel;
23
- private _threadCommentDataSourceService;
24
- constructor(_univerInstanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _threadCommentModel: ThreadCommentModel, _threadCommentDataSourceService: IThreadCommentDataSourceService);
22
+ private readonly _sheetInterceptorService;
23
+ private readonly _threadCommentModel;
24
+ private readonly _threadCommentDataSourceService;
25
+ constructor(_resourceManagerService: IResourceManagerService, _univerInstanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _threadCommentModel: ThreadCommentModel, _threadCommentDataSourceService: IThreadCommentDataSourceService);
26
+ private _initSnapshot;
25
27
  private _initSheetChange;
26
28
  }