@univerjs_sheets-thread-comment_facade.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. import {
  2. p
  3. } from "./chunk-PEI6ACTC.js";
  4. import {
  5. ae,
  6. i,
  7. ne,
  8. oe,
  9. pe,
  10. re as re2,
  11. se
  12. } from "./chunk-PG4GXCOC.js";
  13. import {
  14. S,
  15. f,
  16. m
  17. } from "./chunk-CLOCSTN3.js";
  18. import "./chunk-BW43Z7N3.js";
  19. import {
  20. fn
  21. } from "./chunk-QRYBFJ3R.js";
  22. import {
  23. Fe,
  24. Ot,
  25. Pt,
  26. Ze,
  27. Zt,
  28. _n,
  29. filter,
  30. gn,
  31. hi,
  32. ot,
  33. qt,
  34. re,
  35. rr,
  36. tr
  37. } from "./chunk-23V3HWTR.js";
  38. import "./chunk-GNR2UJZM.js";
  39. import "./chunk-2LSFTFF7.js";
  40. // 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
  41. var E = Object.defineProperty;
  42. var P = (r, e, t) => e in r ? E(r, e, { enumerable: true, configurable: true, writable: true, value: t }) : r[e] = t;
  43. var w = (r, e, t) => P(r, typeof e != "symbol" ? e + "" : e, t);
  44. var q = Object.defineProperty;
  45. var G = Object.getOwnPropertyDescriptor;
  46. var J = (r, e, t, n) => {
  47. for (var o = n > 1 ? void 0 : n ? G(e, t) : e, m2 = r.length - 1, s; m2 >= 0; m2--)
  48. (s = r[m2]) && (o = (n ? s(e, t, o) : s(o)) || o);
  49. return n && o && q(e, t, o), o;
  50. };
  51. var a = (r, e) => (t, n) => e(t, n, r);
  52. var T = class _T {
  53. constructor(e) {
  54. w(this, "_comment", {
  55. id: qt(),
  56. ref: "",
  57. threadId: "",
  58. dT: "",
  59. personId: "",
  60. text: gn.newEmptyData().body,
  61. attachments: [],
  62. unitId: "",
  63. subUnitId: ""
  64. });
  65. e && (this._comment = e);
  66. }
  67. /**
  68. * Create a new FTheadCommentItem
  69. * @param {IThreadComment|undefined} comment The comment
  70. * @returns {FTheadCommentItem} A new instance of FTheadCommentItem
  71. * @example
  72. * ```ts
  73. * const comment = univerAPI.newTheadComment();
  74. * ```
  75. */
  76. static create(e) {
  77. return new _T(e);
  78. }
  79. /**
  80. * Get the person id of the comment
  81. * @returns {string} The person id of the comment
  82. * @example
  83. * ```ts
  84. * const comment = univerAPI.getActiveWorkbook()
  85. * .getSheetById(sheetId)
  86. * .getCommentById(commentId);
  87. * const personId = comment.personId;
  88. * ```
  89. */
  90. get personId() {
  91. return this._comment.personId;
  92. }
  93. /**
  94. * Get the date time of the comment
  95. * @returns {string} The date time of the comment
  96. * @example
  97. * ```ts
  98. * const comment = univerAPI.getActiveWorkbook()
  99. * .getSheetById(sheetId)
  100. * .getCommentById(commentId);
  101. * const dateTime = comment.dateTime;
  102. * ```
  103. */
  104. get dateTime() {
  105. return this._comment.dT;
  106. }
  107. /**
  108. * Get the content of the comment
  109. * @returns {RichTextValue} The content of the comment
  110. * @example
  111. * ```ts
  112. * const comment = univerAPI.getActiveWorkbook()
  113. * .getSheetById(sheetId)
  114. * .getCommentById(commentId);
  115. * const content = comment.content;
  116. * ```
  117. */
  118. get content() {
  119. return Zt.createByBody(this._comment.text);
  120. }
  121. /**
  122. * Get the id of the comment
  123. * @returns {string} The id of the comment
  124. * @example
  125. * ```ts
  126. * const comment = univerAPI.getActiveWorkbook()
  127. * .getSheetById(sheetId)
  128. * .getCommentById(commentId);
  129. * const id = comment.id;
  130. * ```
  131. */
  132. get id() {
  133. return this._comment.id;
  134. }
  135. /**
  136. * Get the thread id of the comment
  137. * @returns {string} The thread id of the comment
  138. * @example
  139. * ```ts
  140. * const comment = univerAPI.getActiveWorkbook()
  141. * .getSheetById(sheetId)
  142. * .getCommentById(commentId);
  143. * const threadId = comment.threadId;
  144. * ```
  145. */
  146. get threadId() {
  147. return this._comment.threadId;
  148. }
  149. /**
  150. * Copy the comment
  151. * @returns {FTheadCommentBuilder} The comment builder
  152. * @example
  153. * ```ts
  154. * const comment = univerAPI.getActiveWorkbook()
  155. * .getSheetById(sheetId)
  156. * .getCommentById(commentId);
  157. * const newComment = comment.copy();
  158. * ```
  159. */
  160. copy() {
  161. return U.create(re.deepClone(this._comment));
  162. }
  163. };
  164. var U = class _U extends T {
  165. static create(e) {
  166. return new _U(e);
  167. }
  168. /**
  169. * Set the content of the comment
  170. * @param {IDocumentBody | RichTextValue} content The content of the comment
  171. * @returns {FTheadCommentBuilder} The comment builder
  172. * @example
  173. * ```ts
  174. * const comment = univerAPI.newTheadComment()
  175. * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
  176. * ```
  177. */
  178. setContent(e) {
  179. return e instanceof Zt ? this._comment.text = e.getData().body : this._comment.text = e, this;
  180. }
  181. /**
  182. * Set the person id of the comment
  183. * @param {string} userId The person id of the comment
  184. * @returns {FTheadCommentBuilder} The comment builder
  185. * @example
  186. * ```ts
  187. * const comment = univerAPI.newTheadComment()
  188. * .setPersonId('123');
  189. * ```
  190. */
  191. setPersonId(e) {
  192. return this._comment.personId = e, this;
  193. }
  194. /**
  195. * Set the date time of the comment
  196. * @param {Date} date The date time of the comment
  197. * @returns {FTheadCommentBuilder} The comment builder
  198. * @example
  199. * ```ts
  200. * const comment = univerAPI.newTheadComment()
  201. * .setDateTime(new Date());
  202. * ```
  203. */
  204. setDateTime(e) {
  205. return this._comment.dT = pe(e), this;
  206. }
  207. /**
  208. * Set the id of the comment
  209. * @param {string} id The id of the comment
  210. * @returns {FTheadCommentBuilder} The comment builder
  211. * @example
  212. * ```ts
  213. * const comment = univerAPI.newTheadComment()
  214. * .setId('123');
  215. * ```
  216. */
  217. setId(e) {
  218. return this._comment.id = e, this;
  219. }
  220. /**
  221. * Set the thread id of the comment
  222. * @param {string} threadId The thread id of the comment
  223. * @returns {FTheadCommentBuilder} The comment builder
  224. * @example
  225. * ```ts
  226. * const comment = univerAPI.newTheadComment()
  227. * .setThreadId('123');
  228. * ```
  229. */
  230. setThreadId(e) {
  231. return this._comment.threadId = e, this;
  232. }
  233. /**
  234. * Build the comment
  235. * @returns {IThreadComment} The comment
  236. * @example
  237. * ```ts
  238. * const comment = univerAPI.newTheadComment()
  239. * .setContent(univerAPI.newRichText().insertText('hello zhangsan'))
  240. * .build();
  241. * ```
  242. */
  243. build() {
  244. return this._comment;
  245. }
  246. };
  247. var i2 = class {
  248. constructor(r, e, t, n, o, m2, s) {
  249. this._thread = r, this._parent = e, this._injector = t, this._commandService = n, this._univerInstanceService = o, this._threadCommentModel = m2, this._userManagerService = s;
  250. }
  251. _getRef() {
  252. var t;
  253. const r = ((t = this._parent) == null ? void 0 : t.ref) || this._thread.ref;
  254. return fn(r).range;
  255. }
  256. /**
  257. * Whether the comment is a root comment
  258. * @returns Whether the comment is a root comment
  259. * @example
  260. * ```ts
  261. * const comment = univerAPI.getActiveWorkbook()
  262. * .getSheetById(sheetId)
  263. * .getCommentById(commentId);
  264. * const isRoot = comment.getIsRoot();
  265. * ```
  266. */
  267. getIsRoot() {
  268. return !this._parent;
  269. }
  270. /**
  271. * Get the comment data
  272. * @returns The comment data
  273. * @example
  274. * ```ts
  275. * const comment = univerAPI.getActiveWorkbook()
  276. * .getSheetById(sheetId)
  277. * .getCommentById(commentId);
  278. * const commentData = comment.getCommentData();
  279. * ```
  280. */
  281. getCommentData() {
  282. const { children: r, ...e } = this._thread;
  283. return e;
  284. }
  285. /**
  286. * Get the replies of the comment
  287. * @returns the replies of the comment
  288. * @example
  289. * ```ts
  290. * const comment = univerAPI.getActiveWorkbook()
  291. * .getSheetById(sheetId)
  292. * .getCommentById(commentId);
  293. * const replies = comment.getReplies();
  294. * ```
  295. */
  296. getReplies() {
  297. var t;
  298. const r = this._getRef(), e = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, r.startRow, r.startColumn);
  299. return (t = e == null ? void 0 : e.children) == null ? void 0 : t.map((n) => this._injector.createInstance(i2, n));
  300. }
  301. /**
  302. * Get the range of the comment
  303. * @returns The range of the comment
  304. * @example
  305. * ```ts
  306. * const comment = univerAPI.getActiveWorkbook()
  307. * .getSheetById(sheetId)
  308. * .getCommentById(commentId);
  309. * const range = comment.getRange();
  310. * ```
  311. */
  312. getRange() {
  313. const r = this._univerInstanceService.getUnit(this._thread.unitId, Fe.UNIVER_SHEET);
  314. if (!r)
  315. return null;
  316. const e = r.getSheetBySheetId(this._thread.subUnitId);
  317. if (!e)
  318. return null;
  319. const t = this._getRef();
  320. return this._injector.createInstance(S, r, e, t);
  321. }
  322. /**
  323. * @deprecated use `getRichText` as instead
  324. */
  325. getContent() {
  326. return this._thread.text;
  327. }
  328. /**
  329. * Get the rich text of the comment
  330. * @returns {RichTextValue} The rich text of the comment
  331. * @example
  332. * ```ts
  333. * const comment = univerAPI.getActiveWorkbook()
  334. * .getSheetById(sheetId)
  335. * .getCommentById(commentId);
  336. * const richText = comment.getRichText();
  337. * ```
  338. */
  339. getRichText() {
  340. const r = this._thread.text;
  341. return Zt.create({ body: r, documentStyle: {}, id: "d" });
  342. }
  343. /**
  344. * Delete the comment and it's replies
  345. * @returns {Promise<boolean>} success or not
  346. * @example
  347. * ```ts
  348. * const comment = univerAPI.getActiveWorkbook()
  349. * .getSheetById(sheetId)
  350. * .getCommentById(commentId);
  351. * const success = await comment.deleteAsync();
  352. * ```
  353. */
  354. deleteAsync() {
  355. return this._commandService.executeCommand(
  356. this.getIsRoot() ? se.id : ae.id,
  357. {
  358. commentId: this._thread.id,
  359. unitId: this._thread.unitId,
  360. subUnitId: this._thread.subUnitId
  361. }
  362. );
  363. }
  364. /**
  365. * @deprecated use `deleteAsync` as instead.
  366. */
  367. delete() {
  368. return this.deleteAsync();
  369. }
  370. /**
  371. * @param content
  372. * @deprecated use `updateAsync` as instead
  373. */
  374. async update(r) {
  375. return this.updateAsync(r);
  376. }
  377. /**
  378. * Update the comment content
  379. * @param content The new content of the comment
  380. * @returns success or not
  381. * @example
  382. * ```ts
  383. * const comment = univerAPI.getActiveWorkbook()
  384. * .getSheetById(sheetId)
  385. * .getCommentById(commentId);
  386. * const success = await comment.updateAsync(univerAPI.newRichText().insertText('hello zhangsan'));
  387. * ```
  388. */
  389. async updateAsync(r) {
  390. const e = r instanceof Zt ? r.getData().body : r, t = pe();
  391. return await this._commandService.executeCommand(
  392. oe.id,
  393. {
  394. unitId: this._thread.unitId,
  395. subUnitId: this._thread.subUnitId,
  396. payload: {
  397. commentId: this._thread.id,
  398. text: e,
  399. updated: true,
  400. updateT: t
  401. }
  402. }
  403. );
  404. }
  405. /**
  406. * @param resolved
  407. * @deprecated use `resolveAsync` as instead
  408. */
  409. resolve(r) {
  410. return this.resolveAsync(r);
  411. }
  412. /**
  413. * Resolve the comment
  414. * @param resolved Whether the comment is resolved
  415. * @returns success or not
  416. * @example
  417. * ```ts
  418. * const comment = univerAPI.getActiveWorkbook()
  419. * .getSheetById(sheetId)
  420. * .getCommentById(commentId);
  421. * const success = await comment.resolveAsync(true);
  422. * ```
  423. */
  424. resolveAsync(r) {
  425. return this._commandService.executeCommand(
  426. re2.id,
  427. {
  428. unitId: this._thread.unitId,
  429. subUnitId: this._thread.subUnitId,
  430. commentId: this._thread.id,
  431. resolved: r != null ? r : !this._thread.resolved
  432. }
  433. );
  434. }
  435. /**
  436. * Reply to the comment
  437. * @param comment The comment to reply to
  438. * @returns success or not
  439. * @example
  440. * ```ts
  441. * const comment = univerAPI.getActiveWorkbook()
  442. * .getSheetById(sheetId)
  443. * .getCommentById(commentId);
  444. *
  445. * const reply = univerAPI.newTheadComment()
  446. * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
  447. *
  448. * const success = await comment.replyAsync(reply);
  449. * ```
  450. */
  451. async replyAsync(r) {
  452. var t;
  453. const e = r.build();
  454. return this._commandService.executeCommand(
  455. ne.id,
  456. {
  457. unitId: this._thread.unitId,
  458. subUnitId: this._thread.subUnitId,
  459. comment: {
  460. id: qt(),
  461. parentId: this._thread.id,
  462. threadId: this._thread.threadId,
  463. ref: (t = this._parent) == null ? void 0 : t.ref,
  464. unitId: this._thread.unitId,
  465. subUnitId: this._thread.subUnitId,
  466. text: e.text,
  467. attachments: e.attachments,
  468. dT: e.dT || pe(),
  469. personId: e.personId || this._userManagerService.getCurrentUser().userID
  470. }
  471. }
  472. );
  473. }
  474. };
  475. i2 = J([
  476. a(2, ot(Ot)),
  477. a(3, Pt),
  478. a(4, _n),
  479. a(5, ot(p)),
  480. a(6, ot(rr))
  481. ], i2);
  482. var K = class extends S {
  483. getComment() {
  484. 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);
  485. if (!m2)
  486. return null;
  487. const s = t.getComment(n, o, m2);
  488. return s ? this._injector.createInstance(i2, s) : null;
  489. }
  490. getComments() {
  491. const t = this._injector.get(p), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), m2 = [];
  492. return tr.foreach(this._range, (s, c) => {
  493. const u = t.getByLocation(n, o, s, c);
  494. if (u) {
  495. const C = t.getComment(n, o, u);
  496. C && m2.push(this._injector.createInstance(i2, C));
  497. }
  498. }), m2;
  499. }
  500. addComment(e) {
  501. var k;
  502. 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 };
  503. return o.executeCommand(ne.id, {
  504. unitId: s,
  505. subUnitId: c,
  506. comment: {
  507. text: _.text,
  508. dT: _.dT || pe(),
  509. attachments: [],
  510. id: _.id || qt(),
  511. ref: u,
  512. personId: _.personId || C.userID,
  513. parentId: n == null ? void 0 : n.id,
  514. unitId: s,
  515. subUnitId: c,
  516. threadId: (n == null ? void 0 : n.threadId) || qt()
  517. }
  518. });
  519. }
  520. clearComment() {
  521. var s;
  522. 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();
  523. return t ? n.executeCommand(se.id, {
  524. unitId: o,
  525. subUnitId: m2,
  526. threadId: t.threadId,
  527. commentId: t.id
  528. }) : Promise.resolve(true);
  529. }
  530. clearComments() {
  531. const t = this.getComments().map((n) => n.deleteAsync());
  532. return Promise.all(t).then(() => true);
  533. }
  534. addCommentAsync(e) {
  535. return this.addComment(e);
  536. }
  537. clearCommentAsync() {
  538. return this.clearComment();
  539. }
  540. clearCommentsAsync() {
  541. return this.clearComments();
  542. }
  543. };
  544. S.extend(K);
  545. var Q = class extends f {
  546. _initialize() {
  547. Object.defineProperty(this, "_threadCommentModel", {
  548. get() {
  549. return this._injector.get(i);
  550. }
  551. });
  552. }
  553. getComments() {
  554. return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map((e) => this._injector.createInstance(i2, e.root));
  555. }
  556. clearComments() {
  557. const t = this.getComments().map((n) => n.deleteAsync());
  558. return Promise.all(t).then(() => true);
  559. }
  560. /**
  561. * @param callback
  562. * @deprecated
  563. */
  564. onThreadCommentChange(e) {
  565. return Ze(this._threadCommentModel.commentUpdate$.pipe(filter((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
  566. }
  567. /**
  568. * @param callback
  569. * @deprecated
  570. */
  571. onBeforeAddThreadComment(e) {
  572. return Ze(this._commandService.beforeCommandExecuted((t, n) => {
  573. const o = t.params;
  574. if (t.id === ne.id) {
  575. if (o.unitId !== this._workbook.getUnitId())
  576. return;
  577. if (e(o, n) === false)
  578. throw new Error("Command is stopped by the hook onBeforeAddThreadComment");
  579. }
  580. }));
  581. }
  582. /**
  583. * @param callback
  584. * @deprecated
  585. */
  586. onBeforeUpdateThreadComment(e) {
  587. return Ze(this._commandService.beforeCommandExecuted((t, n) => {
  588. const o = t.params;
  589. if (t.id === oe.id) {
  590. if (o.unitId !== this._workbook.getUnitId())
  591. return;
  592. if (e(o, n) === false)
  593. throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment");
  594. }
  595. }));
  596. }
  597. /**
  598. * @param callback
  599. * @deprecated
  600. */
  601. onBeforeDeleteThreadComment(e) {
  602. return Ze(this._commandService.beforeCommandExecuted((t, n) => {
  603. const o = t.params;
  604. if (t.id === ae.id || t.id === se.id) {
  605. if (o.unitId !== this._workbook.getUnitId())
  606. return;
  607. if (e(o, n) === false)
  608. throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment");
  609. }
  610. }));
  611. }
  612. };
  613. f.extend(Q);
  614. var X = class extends m {
  615. getComments() {
  616. return this._injector.get(p).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((n) => this._injector.createInstance(i2, n));
  617. }
  618. clearComments() {
  619. const t = this.getComments().map((n) => n.deleteAsync());
  620. return Promise.all(t).then(() => true);
  621. }
  622. /**
  623. * Subscribe to comment events.
  624. * @param callback Callback function, param contains comment info and target cell.
  625. */
  626. onCommented(e) {
  627. return this._injector.get(Pt).onCommandExecuted((n) => {
  628. if (n.id === ne.id) {
  629. const o = n.params;
  630. e(o);
  631. }
  632. });
  633. }
  634. getCommentById(e) {
  635. const n = this._injector.get(p).getComment(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
  636. if (n)
  637. return this._injector.createInstance(i2, n);
  638. }
  639. };
  640. m.extend(X);
  641. var d = {
  642. CommentAdded: "CommentAdded",
  643. BeforeCommentAdd: "BeforeCommentAdd",
  644. CommentUpdated: "CommentUpdated",
  645. BeforeCommentUpdate: "BeforeCommentUpdate",
  646. CommentDeleted: "CommentDeleted",
  647. BeforeCommentDeleted: "BeforeCommentDeleted",
  648. CommentResolved: "CommentResolved",
  649. BeforeCommentResolve: "BeforeCommentResolve"
  650. };
  651. var Y = class extends hi {
  652. get CommentAdded() {
  653. return d.CommentAdded;
  654. }
  655. get BeforeCommentAdd() {
  656. return d.BeforeCommentAdd;
  657. }
  658. get CommentUpdated() {
  659. return d.CommentUpdated;
  660. }
  661. get BeforeCommentUpdate() {
  662. return d.BeforeCommentUpdate;
  663. }
  664. get CommentDeleted() {
  665. return d.CommentDeleted;
  666. }
  667. get BeforeCommentDeleted() {
  668. return d.BeforeCommentDeleted;
  669. }
  670. get CommentResolved() {
  671. return d.CommentResolved;
  672. }
  673. get BeforeCommentResolve() {
  674. return d.BeforeCommentResolve;
  675. }
  676. };
  677. hi.extend(Y);
  678. export {
  679. i2 as FThreadComment
  680. };
  681. //# sourceMappingURL=@univerjs_sheets-thread-comment_facade.js.map