import { p } from "./chunk-PEI6ACTC.js"; import { ae, i, ne, oe, pe, re as re2, se } from "./chunk-PG4GXCOC.js"; import { S, f, m } from "./chunk-CLOCSTN3.js"; import "./chunk-BW43Z7N3.js"; import { fn } from "./chunk-QRYBFJ3R.js"; import { Fe, Ot, Pt, Ze, Zt, _n, filter, gn, hi, ot, qt, re, rr, tr } from "./chunk-23V3HWTR.js"; import "./chunk-GNR2UJZM.js"; import "./chunk-2LSFTFF7.js"; // node_modules/.pnpm/@univerjs+sheets-thread-comment@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets-thread-comment/lib/es/facade.js var E = Object.defineProperty; var P = (r, e, t) => e in r ? E(r, e, { enumerable: true, configurable: true, writable: true, value: t }) : r[e] = t; var w = (r, e, t) => P(r, typeof e != "symbol" ? e + "" : e, t); var q = Object.defineProperty; var G = Object.getOwnPropertyDescriptor; var J = (r, e, t, n) => { for (var o = n > 1 ? void 0 : n ? G(e, t) : e, m2 = r.length - 1, s; m2 >= 0; m2--) (s = r[m2]) && (o = (n ? s(e, t, o) : s(o)) || o); return n && o && q(e, t, o), o; }; var a = (r, e) => (t, n) => e(t, n, r); var T = class _T { constructor(e) { w(this, "_comment", { id: qt(), ref: "", threadId: "", dT: "", personId: "", text: gn.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 Zt.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(re.deepClone(this._comment)); } }; var U = 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 Zt ? 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 = pe(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; } }; var i2 = class { constructor(r, e, t, n, o, m2, s) { this._thread = r, this._parent = e, this._injector = t, this._commandService = n, this._univerInstanceService = o, this._threadCommentModel = m2, this._userManagerService = s; } _getRef() { var t; const r = ((t = this._parent) == null ? void 0 : t.ref) || this._thread.ref; return fn(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(i2, 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, Fe.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(S, 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 Zt.create({ body: r, documentStyle: {}, id: "d" }); } /** * Delete the comment and it's replies * @returns {Promise} 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() ? se.id : ae.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 Zt ? r.getData().body : r, t = pe(); return await this._commandService.executeCommand( oe.id, { unitId: this._thread.unitId, subUnitId: this._thread.subUnitId, payload: { commentId: this._thread.id, text: e, updated: true, 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( re2.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( ne.id, { unitId: this._thread.unitId, subUnitId: this._thread.subUnitId, comment: { id: qt(), 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 || pe(), personId: e.personId || this._userManagerService.getCurrentUser().userID } } ); } }; i2 = J([ a(2, ot(Ot)), a(3, Pt), a(4, _n), a(5, ot(p)), a(6, ot(rr)) ], i2); var K = class extends S { getComment() { const t = this._injector.get(p), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), m2 = t.getByLocation(n, o, this._range.startRow, this._range.startColumn); if (!m2) return null; const s = t.getComment(n, o, m2); return s ? this._injector.createInstance(i2, s) : null; } getComments() { const t = this._injector.get(p), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), m2 = []; return tr.foreach(this._range, (s, c) => { const u = t.getByLocation(n, o, s, c); if (u) { const C = t.getComment(n, o, u); C && m2.push(this._injector.createInstance(i2, C)); } }), m2; } addComment(e) { var k; const t = this._injector, n = (k = this.getComment()) == null ? void 0 : k.getCommentData(), o = t.get(Pt), m2 = t.get(rr), s = this._workbook.getUnitId(), c = this._worksheet.getSheetId(), u = `${re.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, C = m2.getCurrentUser(), _ = e instanceof U ? e.build() : { text: e }; return o.executeCommand(ne.id, { unitId: s, subUnitId: c, comment: { text: _.text, dT: _.dT || pe(), attachments: [], id: _.id || qt(), ref: u, personId: _.personId || C.userID, parentId: n == null ? void 0 : n.id, unitId: s, subUnitId: c, threadId: (n == null ? void 0 : n.threadId) || qt() } }); } clearComment() { var s; const e = this._injector, t = (s = this.getComment()) == null ? void 0 : s.getCommentData(), n = e.get(Pt), o = this._workbook.getUnitId(), m2 = this._worksheet.getSheetId(); return t ? n.executeCommand(se.id, { unitId: o, subUnitId: m2, threadId: t.threadId, commentId: t.id }) : Promise.resolve(true); } clearComments() { const t = this.getComments().map((n) => n.deleteAsync()); return Promise.all(t).then(() => true); } addCommentAsync(e) { return this.addComment(e); } clearCommentAsync() { return this.clearComment(); } clearCommentsAsync() { return this.clearComments(); } }; S.extend(K); var Q = class extends f { _initialize() { Object.defineProperty(this, "_threadCommentModel", { get() { return this._injector.get(i); } }); } getComments() { return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map((e) => this._injector.createInstance(i2, e.root)); } clearComments() { const t = this.getComments().map((n) => n.deleteAsync()); return Promise.all(t).then(() => true); } /** * @param callback * @deprecated */ onThreadCommentChange(e) { return Ze(this._threadCommentModel.commentUpdate$.pipe(filter((t) => t.unitId === this._workbook.getUnitId())).subscribe(e)); } /** * @param callback * @deprecated */ onBeforeAddThreadComment(e) { return Ze(this._commandService.beforeCommandExecuted((t, n) => { const o = t.params; if (t.id === ne.id) { if (o.unitId !== this._workbook.getUnitId()) return; if (e(o, n) === false) throw new Error("Command is stopped by the hook onBeforeAddThreadComment"); } })); } /** * @param callback * @deprecated */ onBeforeUpdateThreadComment(e) { return Ze(this._commandService.beforeCommandExecuted((t, n) => { const o = t.params; if (t.id === oe.id) { if (o.unitId !== this._workbook.getUnitId()) return; if (e(o, n) === false) throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment"); } })); } /** * @param callback * @deprecated */ onBeforeDeleteThreadComment(e) { return Ze(this._commandService.beforeCommandExecuted((t, n) => { const o = t.params; if (t.id === ae.id || t.id === se.id) { if (o.unitId !== this._workbook.getUnitId()) return; if (e(o, n) === false) throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment"); } })); } }; f.extend(Q); var X = class extends m { getComments() { return this._injector.get(p).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((n) => this._injector.createInstance(i2, n)); } clearComments() { const t = this.getComments().map((n) => n.deleteAsync()); return Promise.all(t).then(() => true); } /** * Subscribe to comment events. * @param callback Callback function, param contains comment info and target cell. */ onCommented(e) { return this._injector.get(Pt).onCommandExecuted((n) => { if (n.id === ne.id) { const o = n.params; e(o); } }); } getCommentById(e) { const n = this._injector.get(p).getComment(this._workbook.getUnitId(), this._worksheet.getSheetId(), e); if (n) return this._injector.createInstance(i2, n); } }; m.extend(X); var d = { CommentAdded: "CommentAdded", BeforeCommentAdd: "BeforeCommentAdd", CommentUpdated: "CommentUpdated", BeforeCommentUpdate: "BeforeCommentUpdate", CommentDeleted: "CommentDeleted", BeforeCommentDeleted: "BeforeCommentDeleted", CommentResolved: "CommentResolved", BeforeCommentResolve: "BeforeCommentResolve" }; var Y = class extends hi { 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; } }; hi.extend(Y); export { i2 as FThreadComment }; //# sourceMappingURL=@univerjs_sheets-thread-comment_facade.js.map