chunk-PG4GXCOC.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. import {
  2. Bi,
  3. Ct,
  4. Fe,
  5. Ht,
  6. Ot,
  7. Pt,
  8. Ra,
  9. SE,
  10. Subject,
  11. Ve,
  12. ar,
  13. kE,
  14. nt,
  15. nu,
  16. ot,
  17. rn
  18. } from "./chunk-23V3HWTR.js";
  19. // node_modules/.pnpm/@univerjs+thread-comment@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/thread-comment/lib/es/index.js
  20. var A = Object.defineProperty;
  21. var j = (s, t, e) => t in s ? A(s, t, { enumerable: true, configurable: true, writable: true, value: e }) : s[t] = e;
  22. var u = (s, t, e) => j(s, typeof t != "symbol" ? t + "" : t, e);
  23. var F = class extends nt {
  24. constructor() {
  25. super();
  26. u(this, "_dataSource", null);
  27. u(this, "syncUpdateMutationToColla", true);
  28. }
  29. set dataSource(e) {
  30. this._dataSource = e;
  31. }
  32. get dataSource() {
  33. return this._dataSource;
  34. }
  35. async getThreadComment(e, n, o) {
  36. return this._dataSource ? (await this._dataSource.listComments(e, n, [o]))[0] : null;
  37. }
  38. async addComment(e) {
  39. var n;
  40. return this._dataSource ? this._dataSource.addComment(e) : { ...e, threadId: (n = e.threadId) != null ? n : e.id };
  41. }
  42. async updateComment(e) {
  43. return this._dataSource ? this._dataSource.updateComment(e) : true;
  44. }
  45. async resolveComment(e) {
  46. return this._dataSource ? this._dataSource.resolveComment(e) : true;
  47. }
  48. async deleteComment(e, n, o, r) {
  49. return this._dataSource ? this._dataSource.deleteComment(e, n, o, r) : true;
  50. }
  51. async listThreadComments(e, n, o) {
  52. return this.dataSource ? this.dataSource.listComments(e, n, o) : false;
  53. }
  54. saveToSnapshot(e, n) {
  55. if (this._dataSource) {
  56. const o = {};
  57. return Object.keys(e).forEach((r) => {
  58. const a = e[r];
  59. o[r] = a.map(this.dataSource.saveCommentToSnapshot);
  60. }), o;
  61. }
  62. return e;
  63. }
  64. };
  65. var p = Ct("univer.thread-comment.data-source-service");
  66. var q = Object.defineProperty;
  67. var z = Object.getOwnPropertyDescriptor;
  68. var Q = (s, t, e, n) => {
  69. for (var o = n > 1 ? void 0 : n ? z(t, e) : t, r = s.length - 1, a; r >= 0; r--)
  70. (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
  71. return n && o && q(t, e, o), o;
  72. };
  73. var I = (s, t) => (e, n) => t(e, n, s);
  74. var i = class extends nt {
  75. constructor(t, e) {
  76. super();
  77. u(this, "_commentsMap", /* @__PURE__ */ new Map());
  78. u(this, "_threadMap", /* @__PURE__ */ new Map());
  79. u(this, "_commentUpdate$", new Subject());
  80. u(this, "commentUpdate$", this._commentUpdate$.asObservable());
  81. u(this, "_tasks", []);
  82. this._dataSourceService = t, this._lifecycleService = e, this.disposeWithMe(() => {
  83. this._commentUpdate$.complete();
  84. }), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((n) => {
  85. const o = /* @__PURE__ */ new Map();
  86. n === Ve.Rendered && (this._tasks.forEach(({ unitId: r, subUnitId: a, threadIds: d }) => {
  87. let m = o.get(r);
  88. m || (m = /* @__PURE__ */ new Map(), o.set(r, m));
  89. let c = m.get(a);
  90. c || (c = /* @__PURE__ */ new Set(), m.set(a, c));
  91. for (const h of d)
  92. c.add(h);
  93. }), this._tasks = [], o.forEach((r, a) => {
  94. r.forEach((d, m) => {
  95. this.syncThreadComments(a, m, Array.from(d));
  96. });
  97. }));
  98. }));
  99. }
  100. _ensureCommentMap(t, e) {
  101. let n = this._commentsMap.get(t);
  102. n || (n = /* @__PURE__ */ new Map(), this._commentsMap.set(t, n));
  103. let o = n.get(e);
  104. return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
  105. }
  106. ensureMap(t, e) {
  107. return this._ensureCommentMap(t, e);
  108. }
  109. _ensureThreadMap(t, e) {
  110. let n = this._threadMap.get(t);
  111. n || (n = /* @__PURE__ */ new Map(), this._threadMap.set(t, n));
  112. let o = n.get(e);
  113. return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
  114. }
  115. _replaceComment(t, e, n) {
  116. const o = this._ensureCommentMap(t, e), r = o.get(n.id);
  117. if (r) {
  118. const { children: a, ...d } = n, m = {
  119. ...d,
  120. ref: r.ref
  121. };
  122. o.set(n.id, m), a == null || a.forEach((c) => {
  123. o.set(c.id, {
  124. ...c,
  125. ref: ""
  126. });
  127. }), this._commentUpdate$.next({
  128. unitId: t,
  129. subUnitId: e,
  130. type: "syncUpdate",
  131. payload: m
  132. }), !!n.resolved != !!r.resolved && this._commentUpdate$.next({
  133. unitId: t,
  134. subUnitId: e,
  135. type: "resolve",
  136. payload: {
  137. commentId: n.id,
  138. resolved: !!n.resolved
  139. }
  140. });
  141. }
  142. }
  143. async syncThreadComments(t, e, n) {
  144. if (this._lifecycleService.stage < Ve.Rendered) {
  145. this._tasks.push({ unitId: t, subUnitId: e, threadIds: n });
  146. return;
  147. }
  148. const o = this._ensureThreadMap(t, e), r = this._ensureCommentMap(t, e), a = await this._dataSourceService.listThreadComments(t, e, n);
  149. if (!a)
  150. return;
  151. const d = new Set(n);
  152. a.forEach((m) => {
  153. this._replaceComment(t, e, m), d.delete(m.threadId);
  154. }), d.forEach((m) => {
  155. o.delete(m), r.forEach((c, h) => {
  156. c.threadId === m && r.delete(h);
  157. });
  158. });
  159. }
  160. addComment(t, e, n, o) {
  161. const r = this._ensureCommentMap(t, e), { parentId: a, children: d = [], ...m } = n, c = {
  162. ...m,
  163. parentId: a === n.id ? void 0 : a
  164. };
  165. c.threadId || (c.threadId = c.parentId || c.id);
  166. const h = (f) => {
  167. r.set(f.id, f), this._commentUpdate$.next({
  168. unitId: t,
  169. subUnitId: e,
  170. type: "add",
  171. payload: f,
  172. isRoot: !f.parentId
  173. });
  174. };
  175. h(c);
  176. const _ = this._ensureThreadMap(t, e);
  177. if (!c.parentId) {
  178. _.set(c.threadId, c);
  179. for (const f of d)
  180. h(f);
  181. }
  182. return o && this.syncThreadComments(t, e, [c.threadId]), true;
  183. }
  184. updateComment(t, e, n, o) {
  185. const a = this._ensureCommentMap(t, e).get(n.commentId);
  186. return a && (a.updated = true, a.text = n.text, a.attachments = n.attachments, a.updateT = n.updateT, this._commentUpdate$.next({
  187. unitId: t,
  188. subUnitId: e,
  189. type: "update",
  190. payload: n,
  191. silent: o
  192. })), true;
  193. }
  194. updateCommentRef(t, e, n, o) {
  195. const a = this._ensureCommentMap(t, e).get(n.commentId);
  196. return a ? (a.ref = n.ref, this._commentUpdate$.next({
  197. unitId: t,
  198. subUnitId: e,
  199. type: "updateRef",
  200. payload: n,
  201. silent: o,
  202. threadId: a.threadId
  203. }), true) : false;
  204. }
  205. resolveComment(t, e, n, o) {
  206. const a = this._ensureCommentMap(t, e).get(n);
  207. return a ? (a.resolved = o, this._commentUpdate$.next({
  208. unitId: t,
  209. subUnitId: e,
  210. type: "resolve",
  211. payload: {
  212. commentId: n,
  213. resolved: o
  214. }
  215. }), true) : false;
  216. }
  217. getComment(t, e, n) {
  218. return this._ensureCommentMap(t, e).get(n);
  219. }
  220. getRootComment(t, e, n) {
  221. return this._ensureThreadMap(t, e).get(n);
  222. }
  223. getThread(t, e, n) {
  224. const o = this._ensureCommentMap(t, e), r = Array.from(o.values()).filter((c) => c.threadId === n);
  225. let a;
  226. const d = [], m = /* @__PURE__ */ new Set();
  227. for (const c of r)
  228. c.parentId ? d.push(c) : a = c, m.add(c.personId);
  229. if (a)
  230. return {
  231. root: a,
  232. children: d,
  233. relativeUsers: m,
  234. unitId: t,
  235. subUnitId: e,
  236. threadId: n
  237. };
  238. }
  239. getCommentWithChildren(t, e, n) {
  240. const o = this.getComment(t, e, n);
  241. if (o)
  242. return this.getThread(t, e, o.threadId);
  243. }
  244. _deleteComment(t, e, n) {
  245. const o = this._ensureCommentMap(t, e), r = o.get(n);
  246. r && (o.delete(n), this._commentUpdate$.next({
  247. unitId: t,
  248. subUnitId: e,
  249. type: "delete",
  250. payload: {
  251. commentId: n,
  252. isRoot: !r.parentId,
  253. comment: r
  254. }
  255. }));
  256. }
  257. deleteThread(t, e, n) {
  258. this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((a) => {
  259. a.threadId === n && this._deleteComment(t, e, a.id);
  260. });
  261. }
  262. deleteComment(t, e, n) {
  263. const r = this._ensureCommentMap(t, e).get(n);
  264. return r && (r.parentId ? this._deleteComment(t, e, n) : this.deleteThread(t, e, r.threadId)), true;
  265. }
  266. deleteUnit(t) {
  267. const e = this._commentsMap.get(t);
  268. e && e.forEach((n, o) => {
  269. n.forEach((r) => {
  270. this.deleteComment(t, o, r.id);
  271. });
  272. });
  273. }
  274. getUnit(t) {
  275. const e = this._threadMap.get(t);
  276. if (!e)
  277. return [];
  278. const n = [];
  279. return e.forEach((o, r) => {
  280. o.forEach((a, d) => {
  281. const m = this.getThread(t, r, d);
  282. m && n.push(m);
  283. });
  284. }), n;
  285. }
  286. getAll() {
  287. const t = [];
  288. return this._commentsMap.forEach((e, n) => {
  289. t.push({
  290. unitId: n,
  291. threads: this.getUnit(n)
  292. });
  293. }), t;
  294. }
  295. };
  296. i = Q([
  297. I(0, ot(p)),
  298. I(1, ot(Ht))
  299. ], i);
  300. var T = ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(T || {});
  301. var w = "UNIVER_THREAD_COMMENT_PLUGIN";
  302. var X = Object.defineProperty;
  303. var k = Object.getOwnPropertyDescriptor;
  304. var ee = (s, t, e, n) => {
  305. for (var o = n > 1 ? void 0 : n ? k(t, e) : t, r = s.length - 1, a; r >= 0; r--)
  306. (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
  307. return n && o && X(t, e, o), o;
  308. };
  309. var v = (s, t) => (e, n) => t(e, n, s);
  310. var S = class extends nt {
  311. constructor(s, t, e) {
  312. super(), this._resourceManagerService = s, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot();
  313. }
  314. _initSnapshot() {
  315. const s = (e) => {
  316. const n = this._threadCommentModel.getUnit(e), o = {};
  317. return n ? (n.forEach((r) => {
  318. var d;
  319. const a = (d = o[r.subUnitId]) != null ? d : [];
  320. a.push({
  321. ...r.root,
  322. children: r.children
  323. }), o[r.subUnitId] = a;
  324. }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o, e))) : "";
  325. }, t = (e) => {
  326. if (!e)
  327. return {};
  328. try {
  329. return JSON.parse(e);
  330. } catch {
  331. return {};
  332. }
  333. };
  334. this.disposeWithMe(
  335. this._resourceManagerService.registerPluginResource({
  336. pluginName: `SHEET_${w}`,
  337. businesses: [T.UNIVER_SHEET, T.UNIVER_DOC],
  338. toJson: (e) => s(e),
  339. parseJson: (e) => t(e),
  340. onUnLoad: (e) => {
  341. this._threadCommentModel.deleteUnit(e);
  342. },
  343. onLoad: async (e, n) => {
  344. Object.keys(n).forEach((o) => {
  345. const r = n[o];
  346. r.forEach((a) => {
  347. this._threadCommentModel.addComment(e, o, a);
  348. }), this._threadCommentModel.syncThreadComments(e, o, r.map((a) => a.threadId));
  349. });
  350. }
  351. })
  352. );
  353. }
  354. };
  355. S = ee([
  356. v(0, Bi),
  357. v(1, ot(i)),
  358. v(2, p)
  359. ], S);
  360. var P = {
  361. id: "thread-comment.mutation.add-comment",
  362. type: ar.MUTATION,
  363. handler(s, t, e) {
  364. if (!t)
  365. return false;
  366. const n = s.get(i), { unitId: o, subUnitId: r, comment: a, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !a.parentId;
  367. return n.addComment(o, r, a, m);
  368. }
  369. };
  370. var $ = {
  371. id: "thread-comment.mutation.update-comment",
  372. type: ar.MUTATION,
  373. handler(s, t) {
  374. if (!t)
  375. return false;
  376. const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
  377. return e.updateComment(n, o, r, a);
  378. }
  379. };
  380. var te = {
  381. id: "thread-comment.mutation.update-comment-ref",
  382. type: ar.MUTATION,
  383. handler(s, t) {
  384. if (!t)
  385. return false;
  386. const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
  387. return e.updateCommentRef(n, o, r, a);
  388. }
  389. };
  390. var x = {
  391. id: "thread-comment.mutation.resolve-comment",
  392. type: ar.MUTATION,
  393. handler(s, t) {
  394. if (!t)
  395. return false;
  396. const e = s.get(i), { unitId: n, subUnitId: o, resolved: r, commentId: a } = t;
  397. return e.resolveComment(n, o, a, r);
  398. }
  399. };
  400. var N = {
  401. id: "thread-comment.mutation.delete-comment",
  402. type: ar.MUTATION,
  403. handler(s, t) {
  404. if (!t)
  405. return false;
  406. const e = s.get(i), { unitId: n, subUnitId: o, commentId: r } = t;
  407. return e.deleteComment(n, o, r);
  408. }
  409. };
  410. var ne = {
  411. id: "thread-comment.command.add-comment",
  412. type: ar.COMMAND,
  413. async handler(s, t) {
  414. if (!t)
  415. return false;
  416. const e = s.get(Pt), n = s.get(p), { comment: o } = t, r = await n.addComment(o), a = n.syncUpdateMutationToColla, d = !o.parentId, m = {
  417. id: P.id,
  418. params: {
  419. ...t,
  420. comment: r
  421. }
  422. };
  423. return d ? await e.executeCommand(m.id, m.params) : e.executeCommand(m.id, m.params, {
  424. onlyLocal: !a
  425. });
  426. }
  427. };
  428. var oe = {
  429. id: "thread-comment.command.update-comment",
  430. type: ar.COMMAND,
  431. async handler(s, t) {
  432. if (!t)
  433. return false;
  434. const { unitId: e, subUnitId: n, payload: o } = t, r = s.get(Pt), a = s.get(i), d = s.get(p), m = d.syncUpdateMutationToColla, c = a.getComment(
  435. e,
  436. n,
  437. o.commentId
  438. );
  439. if (!c)
  440. return false;
  441. const { children: h, ..._ } = c;
  442. if (!await d.updateComment({
  443. ..._,
  444. ...o
  445. }))
  446. return false;
  447. const E = {
  448. id: $.id,
  449. params: t
  450. };
  451. return r.executeCommand(E.id, E.params, { onlyLocal: !m }), true;
  452. }
  453. };
  454. var re = {
  455. id: "thread-comment.command.resolve-comment",
  456. type: ar.COMMAND,
  457. async handler(s, t) {
  458. if (!t)
  459. return false;
  460. const { unitId: e, subUnitId: n, resolved: o, commentId: r } = t, a = s.get(p), m = s.get(i).getComment(e, n, r), c = a.syncUpdateMutationToColla;
  461. return !m || !await a.resolveComment({
  462. ...m,
  463. resolved: o
  464. }) ? false : s.get(Pt).executeCommand(
  465. x.id,
  466. t,
  467. { onlyLocal: !c }
  468. );
  469. }
  470. };
  471. var ae = {
  472. id: "thread-comment.command.delete-comment",
  473. type: ar.COMMAND,
  474. async handler(s, t) {
  475. if (!t)
  476. return false;
  477. const e = s.get(i), n = s.get(p), o = s.get(Pt), { unitId: r, subUnitId: a, commentId: d } = t, m = n.syncUpdateMutationToColla, c = e.getComment(r, a, d);
  478. if (!c || !await n.deleteComment(r, a, c.threadId, d))
  479. return false;
  480. const h = {
  481. id: N.id,
  482. params: t
  483. };
  484. return o.executeCommand(h.id, h.params, { onlyLocal: !m });
  485. }
  486. };
  487. var se = {
  488. id: "thread-comment.command.delete-comment-tree",
  489. type: ar.COMMAND,
  490. async handler(s, t) {
  491. if (!t)
  492. return false;
  493. const e = s.get(i), n = s.get(Pt), o = s.get(p), { unitId: r, subUnitId: a, commentId: d } = t, m = e.getCommentWithChildren(r, a, d);
  494. return !m || !await o.deleteComment(r, a, m.root.threadId, d) ? false : await n.executeCommand(N.id, {
  495. unitId: r,
  496. subUnitId: a,
  497. commentId: m.root.id
  498. });
  499. }
  500. };
  501. var me = "thread-comment.config";
  502. var R = {};
  503. var ce = Object.defineProperty;
  504. var de = Object.getOwnPropertyDescriptor;
  505. var ie = (s, t, e, n) => {
  506. for (var o = n > 1 ? void 0 : n ? de(t, e) : t, r = s.length - 1, a; r >= 0; r--)
  507. (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
  508. return n && o && ce(t, e, o), o;
  509. };
  510. var y = (s, t) => (e, n) => t(e, n, s);
  511. var M;
  512. var D = (M = class extends Ra {
  513. constructor(s = R, t, e, n) {
  514. super(), this._config = s, this._injector = t, this._commandService = e, this._configService = n;
  515. const { ...o } = nu(
  516. {},
  517. R,
  518. this._config
  519. );
  520. this._configService.setConfig(me, o);
  521. }
  522. onStarting() {
  523. var s;
  524. kE([
  525. [p, { useClass: F }],
  526. [i],
  527. [S]
  528. ], (s = this._config) == null ? void 0 : s.overrides).forEach(
  529. (t) => {
  530. this._injector.add(t);
  531. }
  532. ), [
  533. ne,
  534. oe,
  535. ae,
  536. re,
  537. se,
  538. P,
  539. $,
  540. te,
  541. N,
  542. x
  543. ].forEach((t) => {
  544. this._commandService.registerCommand(t);
  545. }), this._injector.get(S);
  546. }
  547. }, u(M, "pluginName", w), u(M, "type", Fe.UNIVER_UNKNOWN), M);
  548. D = ie([
  549. y(1, ot(Ot)),
  550. y(2, Pt),
  551. y(3, SE)
  552. ], D);
  553. function pe(s) {
  554. return rn(s).format("YYYY/MM/DD HH:mm");
  555. }
  556. export {
  557. F,
  558. p,
  559. i,
  560. w,
  561. S,
  562. P,
  563. $,
  564. te,
  565. x,
  566. N,
  567. ne,
  568. oe,
  569. re,
  570. ae,
  571. se,
  572. D,
  573. pe
  574. };
  575. //# sourceMappingURL=chunk-PG4GXCOC.js.map