| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- var E = Object.defineProperty;
- var P = (r, e, t) => e in r ? E(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
- var w = (r, e, t) => P(r, typeof e != "symbol" ? e + "" : e, t);
- import { Inject as v, Injector as F, UserManagerService as S, UniverInstanceType as W, RichTextValue as l, generateRandomId as g, ICommandService as p, IUniverInstanceService as O, RichTextBuilder as $, Tools as B, Range as z, toDisposable as I, FEventName as R } from "@univerjs/core";
- import { SheetsThreadCommentModel as h } from "@univerjs/sheets-thread-comment";
- import { FRange as x, FWorkbook as j, FWorksheet as A } from "@univerjs/sheets/facade";
- import { DeleteCommentTreeCommand as y, DeleteCommentCommand as D, getDT as f, UpdateCommentCommand as M, ResolveCommentCommand as L, AddCommentCommand as b, ThreadCommentModel as N } from "@univerjs/thread-comment";
- import { deserializeRangeWithSheet as V } from "@univerjs/engine-formula";
- import { filter as H } from "rxjs";
- var q = Object.defineProperty, G = Object.getOwnPropertyDescriptor, J = (r, e, t, n) => {
- for (var o = n > 1 ? void 0 : n ? G(e, t) : e, m = r.length - 1, s; m >= 0; m--)
- (s = r[m]) && (o = (n ? s(e, t, o) : s(o)) || o);
- return n && o && q(e, t, o), o;
- }, a = (r, e) => (t, n) => e(t, n, r);
- class T {
- constructor(e) {
- w(this, "_comment", {
- id: g(),
- ref: "",
- threadId: "",
- dT: "",
- personId: "",
- text: $.newEmptyData().body,
- attachments: [],
- unitId: "",
- subUnitId: ""
- });
- e && (this._comment = e);
- }
- /**
- * Create a new FTheadCommentItem
- * @param {IThreadComment|undefined} comment The comment
- * @returns {FTheadCommentItem} A new instance of FTheadCommentItem
- * @example
- * ```ts
- * const comment = univerAPI.newTheadComment();
- * ```
- */
- static create(e) {
- return new T(e);
- }
- /**
- * Get the person id of the comment
- * @returns {string} The person id of the comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const personId = comment.personId;
- * ```
- */
- get personId() {
- return this._comment.personId;
- }
- /**
- * Get the date time of the comment
- * @returns {string} The date time of the comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const dateTime = comment.dateTime;
- * ```
- */
- get dateTime() {
- return this._comment.dT;
- }
- /**
- * Get the content of the comment
- * @returns {RichTextValue} The content of the comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const content = comment.content;
- * ```
- */
- get content() {
- return l.createByBody(this._comment.text);
- }
- /**
- * Get the id of the comment
- * @returns {string} The id of the comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const id = comment.id;
- * ```
- */
- get id() {
- return this._comment.id;
- }
- /**
- * Get the thread id of the comment
- * @returns {string} The thread id of the comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const threadId = comment.threadId;
- * ```
- */
- get threadId() {
- return this._comment.threadId;
- }
- /**
- * Copy the comment
- * @returns {FTheadCommentBuilder} The comment builder
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const newComment = comment.copy();
- * ```
- */
- copy() {
- return U.create(B.deepClone(this._comment));
- }
- }
- class U extends T {
- static create(e) {
- return new U(e);
- }
- /**
- * Set the content of the comment
- * @param {IDocumentBody | RichTextValue} content The content of the comment
- * @returns {FTheadCommentBuilder} The comment builder
- * @example
- * ```ts
- * const comment = univerAPI.newTheadComment()
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
- * ```
- */
- setContent(e) {
- return e instanceof l ? this._comment.text = e.getData().body : this._comment.text = e, this;
- }
- /**
- * Set the person id of the comment
- * @param {string} userId The person id of the comment
- * @returns {FTheadCommentBuilder} The comment builder
- * @example
- * ```ts
- * const comment = univerAPI.newTheadComment()
- * .setPersonId('123');
- * ```
- */
- setPersonId(e) {
- return this._comment.personId = e, this;
- }
- /**
- * Set the date time of the comment
- * @param {Date} date The date time of the comment
- * @returns {FTheadCommentBuilder} The comment builder
- * @example
- * ```ts
- * const comment = univerAPI.newTheadComment()
- * .setDateTime(new Date());
- * ```
- */
- setDateTime(e) {
- return this._comment.dT = f(e), this;
- }
- /**
- * Set the id of the comment
- * @param {string} id The id of the comment
- * @returns {FTheadCommentBuilder} The comment builder
- * @example
- * ```ts
- * const comment = univerAPI.newTheadComment()
- * .setId('123');
- * ```
- */
- setId(e) {
- return this._comment.id = e, this;
- }
- /**
- * Set the thread id of the comment
- * @param {string} threadId The thread id of the comment
- * @returns {FTheadCommentBuilder} The comment builder
- * @example
- * ```ts
- * const comment = univerAPI.newTheadComment()
- * .setThreadId('123');
- * ```
- */
- setThreadId(e) {
- return this._comment.threadId = e, this;
- }
- /**
- * Build the comment
- * @returns {IThreadComment} The comment
- * @example
- * ```ts
- * const comment = univerAPI.newTheadComment()
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'))
- * .build();
- * ```
- */
- build() {
- return this._comment;
- }
- }
- let i = class {
- constructor(r, e, t, n, o, m, s) {
- this._thread = r, this._parent = e, this._injector = t, this._commandService = n, this._univerInstanceService = o, this._threadCommentModel = m, this._userManagerService = s;
- }
- _getRef() {
- var t;
- const r = ((t = this._parent) == null ? void 0 : t.ref) || this._thread.ref;
- return V(r).range;
- }
- /**
- * Whether the comment is a root comment
- * @returns Whether the comment is a root comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const isRoot = comment.getIsRoot();
- * ```
- */
- getIsRoot() {
- return !this._parent;
- }
- /**
- * Get the comment data
- * @returns The comment data
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const commentData = comment.getCommentData();
- * ```
- */
- getCommentData() {
- const { children: r, ...e } = this._thread;
- return e;
- }
- /**
- * Get the replies of the comment
- * @returns the replies of the comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const replies = comment.getReplies();
- * ```
- */
- getReplies() {
- var t;
- const r = this._getRef(), e = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, r.startRow, r.startColumn);
- return (t = e == null ? void 0 : e.children) == null ? void 0 : t.map((n) => this._injector.createInstance(i, n));
- }
- /**
- * Get the range of the comment
- * @returns The range of the comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const range = comment.getRange();
- * ```
- */
- getRange() {
- const r = this._univerInstanceService.getUnit(this._thread.unitId, W.UNIVER_SHEET);
- if (!r)
- return null;
- const e = r.getSheetBySheetId(this._thread.subUnitId);
- if (!e)
- return null;
- const t = this._getRef();
- return this._injector.createInstance(x, r, e, t);
- }
- /**
- * @deprecated use `getRichText` as instead
- */
- getContent() {
- return this._thread.text;
- }
- /**
- * Get the rich text of the comment
- * @returns {RichTextValue} The rich text of the comment
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const richText = comment.getRichText();
- * ```
- */
- getRichText() {
- const r = this._thread.text;
- return l.create({ body: r, documentStyle: {}, id: "d" });
- }
- /**
- * Delete the comment and it's replies
- * @returns {Promise<boolean>} success or not
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const success = await comment.deleteAsync();
- * ```
- */
- deleteAsync() {
- return this._commandService.executeCommand(
- this.getIsRoot() ? y.id : D.id,
- {
- commentId: this._thread.id,
- unitId: this._thread.unitId,
- subUnitId: this._thread.subUnitId
- }
- );
- }
- /**
- * @deprecated use `deleteAsync` as instead.
- */
- delete() {
- return this.deleteAsync();
- }
- /**
- * @param content
- * @deprecated use `updateAsync` as instead
- */
- async update(r) {
- return this.updateAsync(r);
- }
- /**
- * Update the comment content
- * @param content The new content of the comment
- * @returns success or not
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const success = await comment.updateAsync(univerAPI.newRichText().insertText('hello zhangsan'));
- * ```
- */
- async updateAsync(r) {
- const e = r instanceof l ? r.getData().body : r, t = f();
- return await this._commandService.executeCommand(
- M.id,
- {
- unitId: this._thread.unitId,
- subUnitId: this._thread.subUnitId,
- payload: {
- commentId: this._thread.id,
- text: e,
- updated: !0,
- updateT: t
- }
- }
- );
- }
- /**
- * @param resolved
- * @deprecated use `resolveAsync` as instead
- */
- resolve(r) {
- return this.resolveAsync(r);
- }
- /**
- * Resolve the comment
- * @param resolved Whether the comment is resolved
- * @returns success or not
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- * const success = await comment.resolveAsync(true);
- * ```
- */
- resolveAsync(r) {
- return this._commandService.executeCommand(
- L.id,
- {
- unitId: this._thread.unitId,
- subUnitId: this._thread.subUnitId,
- commentId: this._thread.id,
- resolved: r != null ? r : !this._thread.resolved
- }
- );
- }
- /**
- * Reply to the comment
- * @param comment The comment to reply to
- * @returns success or not
- * @example
- * ```ts
- * const comment = univerAPI.getActiveWorkbook()
- * .getSheetById(sheetId)
- * .getCommentById(commentId);
- *
- * const reply = univerAPI.newTheadComment()
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
- *
- * const success = await comment.replyAsync(reply);
- * ```
- */
- async replyAsync(r) {
- var t;
- const e = r.build();
- return this._commandService.executeCommand(
- b.id,
- {
- unitId: this._thread.unitId,
- subUnitId: this._thread.subUnitId,
- comment: {
- id: g(),
- parentId: this._thread.id,
- threadId: this._thread.threadId,
- ref: (t = this._parent) == null ? void 0 : t.ref,
- unitId: this._thread.unitId,
- subUnitId: this._thread.subUnitId,
- text: e.text,
- attachments: e.attachments,
- dT: e.dT || f(),
- personId: e.personId || this._userManagerService.getCurrentUser().userID
- }
- }
- );
- }
- };
- i = J([
- a(2, v(F)),
- a(3, p),
- a(4, O),
- a(5, v(h)),
- a(6, v(S))
- ], i);
- class K extends x {
- getComment() {
- const t = this._injector.get(h), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), m = t.getByLocation(n, o, this._range.startRow, this._range.startColumn);
- if (!m)
- return null;
- const s = t.getComment(n, o, m);
- return s ? this._injector.createInstance(i, s) : null;
- }
- getComments() {
- const t = this._injector.get(h), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), m = [];
- return z.foreach(this._range, (s, c) => {
- const u = t.getByLocation(n, o, s, c);
- if (u) {
- const C = t.getComment(n, o, u);
- C && m.push(this._injector.createInstance(i, C));
- }
- }), m;
- }
- addComment(e) {
- var k;
- const t = this._injector, n = (k = this.getComment()) == null ? void 0 : k.getCommentData(), o = t.get(p), m = t.get(S), s = this._workbook.getUnitId(), c = this._worksheet.getSheetId(), u = `${B.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, C = m.getCurrentUser(), _ = e instanceof U ? e.build() : { text: e };
- return o.executeCommand(b.id, {
- unitId: s,
- subUnitId: c,
- comment: {
- text: _.text,
- dT: _.dT || f(),
- attachments: [],
- id: _.id || g(),
- ref: u,
- personId: _.personId || C.userID,
- parentId: n == null ? void 0 : n.id,
- unitId: s,
- subUnitId: c,
- threadId: (n == null ? void 0 : n.threadId) || g()
- }
- });
- }
- clearComment() {
- var s;
- const e = this._injector, t = (s = this.getComment()) == null ? void 0 : s.getCommentData(), n = e.get(p), o = this._workbook.getUnitId(), m = this._worksheet.getSheetId();
- return t ? n.executeCommand(y.id, {
- unitId: o,
- subUnitId: m,
- threadId: t.threadId,
- commentId: t.id
- }) : Promise.resolve(!0);
- }
- clearComments() {
- const t = this.getComments().map((n) => n.deleteAsync());
- return Promise.all(t).then(() => !0);
- }
- addCommentAsync(e) {
- return this.addComment(e);
- }
- clearCommentAsync() {
- return this.clearComment();
- }
- clearCommentsAsync() {
- return this.clearComments();
- }
- }
- x.extend(K);
- class Q extends j {
- _initialize() {
- Object.defineProperty(this, "_threadCommentModel", {
- get() {
- return this._injector.get(N);
- }
- });
- }
- getComments() {
- return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map((e) => this._injector.createInstance(i, e.root));
- }
- clearComments() {
- const t = this.getComments().map((n) => n.deleteAsync());
- return Promise.all(t).then(() => !0);
- }
- /**
- * @param callback
- * @deprecated
- */
- onThreadCommentChange(e) {
- return I(this._threadCommentModel.commentUpdate$.pipe(H((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
- }
- /**
- * @param callback
- * @deprecated
- */
- onBeforeAddThreadComment(e) {
- return I(this._commandService.beforeCommandExecuted((t, n) => {
- const o = t.params;
- if (t.id === b.id) {
- if (o.unitId !== this._workbook.getUnitId())
- return;
- if (e(o, n) === !1)
- throw new Error("Command is stopped by the hook onBeforeAddThreadComment");
- }
- }));
- }
- /**
- * @param callback
- * @deprecated
- */
- onBeforeUpdateThreadComment(e) {
- return I(this._commandService.beforeCommandExecuted((t, n) => {
- const o = t.params;
- if (t.id === M.id) {
- if (o.unitId !== this._workbook.getUnitId())
- return;
- if (e(o, n) === !1)
- throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment");
- }
- }));
- }
- /**
- * @param callback
- * @deprecated
- */
- onBeforeDeleteThreadComment(e) {
- return I(this._commandService.beforeCommandExecuted((t, n) => {
- const o = t.params;
- if (t.id === D.id || t.id === y.id) {
- if (o.unitId !== this._workbook.getUnitId())
- return;
- if (e(o, n) === !1)
- throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment");
- }
- }));
- }
- }
- j.extend(Q);
- class X extends A {
- getComments() {
- return this._injector.get(h).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((n) => this._injector.createInstance(i, n));
- }
- clearComments() {
- const t = this.getComments().map((n) => n.deleteAsync());
- return Promise.all(t).then(() => !0);
- }
- /**
- * Subscribe to comment events.
- * @param callback Callback function, param contains comment info and target cell.
- */
- onCommented(e) {
- return this._injector.get(p).onCommandExecuted((n) => {
- if (n.id === b.id) {
- const o = n.params;
- e(o);
- }
- });
- }
- getCommentById(e) {
- const n = this._injector.get(h).getComment(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
- if (n)
- return this._injector.createInstance(i, n);
- }
- }
- A.extend(X);
- const d = {
- CommentAdded: "CommentAdded",
- BeforeCommentAdd: "BeforeCommentAdd",
- CommentUpdated: "CommentUpdated",
- BeforeCommentUpdate: "BeforeCommentUpdate",
- CommentDeleted: "CommentDeleted",
- BeforeCommentDeleted: "BeforeCommentDeleted",
- CommentResolved: "CommentResolved",
- BeforeCommentResolve: "BeforeCommentResolve"
- };
- class Y extends R {
- get CommentAdded() {
- return d.CommentAdded;
- }
- get BeforeCommentAdd() {
- return d.BeforeCommentAdd;
- }
- get CommentUpdated() {
- return d.CommentUpdated;
- }
- get BeforeCommentUpdate() {
- return d.BeforeCommentUpdate;
- }
- get CommentDeleted() {
- return d.CommentDeleted;
- }
- get BeforeCommentDeleted() {
- return d.BeforeCommentDeleted;
- }
- get CommentResolved() {
- return d.CommentResolved;
- }
- get BeforeCommentResolve() {
- return d.BeforeCommentResolve;
- }
- }
- R.extend(Y);
- export {
- i as FThreadComment
- };
|