123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682 |
- 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<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() ? 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
|