chunk-PEI6ACTC.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. import {
  2. D,
  3. N,
  4. P,
  5. i,
  6. te
  7. } from "./chunk-PG4GXCOC.js";
  8. import {
  9. F,
  10. _t,
  11. hh
  12. } from "./chunk-BW43Z7N3.js";
  13. import {
  14. fr,
  15. ns
  16. } from "./chunk-QRYBFJ3R.js";
  17. import {
  18. Fe,
  19. OR,
  20. Ot,
  21. Pt,
  22. Q0,
  23. Ra,
  24. Subject,
  25. Ze,
  26. _n,
  27. kt,
  28. nt,
  29. ot
  30. } from "./chunk-23V3HWTR.js";
  31. // 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/index.js
  32. var x = Object.defineProperty;
  33. var T = (i2, e, n) => e in i2 ? x(i2, e, { enumerable: true, configurable: true, writable: true, value: n }) : i2[e] = n;
  34. var h = (i2, e, n) => T(i2, typeof e != "symbol" ? e + "" : e, n);
  35. var z = Object.defineProperty;
  36. var G = Object.getOwnPropertyDescriptor;
  37. var q = (i2, e, n, t) => {
  38. for (var r = t > 1 ? void 0 : t ? G(e, n) : e, s = i2.length - 1, o; s >= 0; s--)
  39. (o = i2[s]) && (r = (t ? o(e, n, r) : o(r)) || r);
  40. return t && r && z(e, n, r), r;
  41. };
  42. var w = (i2, e) => (n, t) => e(n, t, i2);
  43. var p = class extends nt {
  44. constructor(e, n) {
  45. super();
  46. h(this, "_matrixMap", /* @__PURE__ */ new Map());
  47. h(this, "_locationMap", /* @__PURE__ */ new Map());
  48. h(this, "_commentUpdate$", new Subject());
  49. h(this, "commentUpdate$", this._commentUpdate$.asObservable());
  50. this._threadCommentModel = e, this._univerInstanceService = n, this._init(), this.disposeWithMe(() => {
  51. this._commentUpdate$.complete();
  52. });
  53. }
  54. _init() {
  55. this._initData(), this._initUpdateTransform();
  56. }
  57. _ensureCommentMatrix(e, n) {
  58. let t = this._matrixMap.get(e);
  59. t || (t = /* @__PURE__ */ new Map(), this._matrixMap.set(e, t));
  60. let r = t.get(n);
  61. return r || (r = new kt(), t.set(n, r)), r;
  62. }
  63. _ensureCommentLocationMap(e, n) {
  64. let t = this._locationMap.get(e);
  65. t || (t = /* @__PURE__ */ new Map(), this._locationMap.set(e, t));
  66. let r = t.get(n);
  67. return r || (r = /* @__PURE__ */ new Map(), t.set(n, r)), r;
  68. }
  69. _addCommentToMatrix(e, n, t, r) {
  70. var o;
  71. const s = (o = e.getValue(n, t)) != null ? o : /* @__PURE__ */ new Set();
  72. s.add(r), e.setValue(n, t, s);
  73. }
  74. _deleteCommentFromMatrix(e, n, t, r) {
  75. if (n >= 0 && t >= 0) {
  76. const s = e.getValue(n, t);
  77. s && s.has(r) && (s.delete(r), s.size === 0 && e.realDeleteValue(n, t));
  78. }
  79. }
  80. _ensure(e, n) {
  81. const t = this._ensureCommentMatrix(e, n), r = this._ensureCommentLocationMap(e, n);
  82. return { matrix: t, locationMap: r };
  83. }
  84. _initData() {
  85. const e = this._threadCommentModel.getAll();
  86. for (const n of e)
  87. for (const t of n.threads) {
  88. const { unitId: r, subUnitId: s, root: o } = t;
  89. this._addComment(r, s, o);
  90. }
  91. }
  92. _addComment(e, n, t) {
  93. const r = ns(t.ref), s = t.parentId, { row: o, column: a } = r, c = t.id, { matrix: m, locationMap: d } = this._ensure(e, n);
  94. !s && o >= 0 && a >= 0 && (this._addCommentToMatrix(m, o, a, c), d.set(c, { row: o, column: a })), s || this._commentUpdate$.next({
  95. unitId: e,
  96. subUnitId: n,
  97. payload: t,
  98. type: "add",
  99. isRoot: !s,
  100. ...r
  101. });
  102. }
  103. // eslint-disable-next-line max-lines-per-function
  104. _initUpdateTransform() {
  105. this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((e) => {
  106. const { unitId: n, subUnitId: t } = e;
  107. try {
  108. if (this._univerInstanceService.getUnitType(n) !== Fe.UNIVER_SHEET)
  109. return;
  110. } catch {
  111. }
  112. const { matrix: r, locationMap: s } = this._ensure(n, t);
  113. switch (e.type) {
  114. case "add": {
  115. this._addComment(e.unitId, e.subUnitId, e.payload);
  116. break;
  117. }
  118. case "delete": {
  119. const { isRoot: o, comment: a } = e.payload;
  120. if (o) {
  121. const c = ns(a.ref), { row: m, column: d } = c;
  122. this._deleteCommentFromMatrix(r, m, d, a.id), this._commentUpdate$.next({
  123. ...e,
  124. ...c
  125. });
  126. }
  127. break;
  128. }
  129. case "update": {
  130. const { commentId: o } = e.payload, a = this._threadCommentModel.getComment(n, t, o);
  131. if (!a)
  132. return;
  133. const c = ns(a.ref);
  134. this._commentUpdate$.next({
  135. ...e,
  136. ...c
  137. });
  138. break;
  139. }
  140. case "updateRef": {
  141. const o = ns(e.payload.ref), { commentId: a } = e.payload, c = s.get(a);
  142. if (!c)
  143. return;
  144. const { row: m, column: d } = c;
  145. this._deleteCommentFromMatrix(r, m, d, a), s.delete(a), o.row >= 0 && o.column >= 0 && (this._addCommentToMatrix(r, o.row, o.column, a), s.set(a, { row: o.row, column: o.column })), this._commentUpdate$.next({
  146. ...e,
  147. ...o
  148. });
  149. break;
  150. }
  151. case "resolve": {
  152. const { unitId: o, subUnitId: a, payload: c } = e, { locationMap: m } = this._ensure(o, a), d = m.get(c.commentId);
  153. d && this._commentUpdate$.next({
  154. ...e,
  155. ...d
  156. });
  157. break;
  158. }
  159. }
  160. }));
  161. }
  162. getByLocation(e, n, t, r) {
  163. var a;
  164. return (a = this.getAllByLocation(e, n, t, r).filter((c) => !c.resolved)[0]) == null ? void 0 : a.id;
  165. }
  166. getAllByLocation(e, n, t, r) {
  167. const o = this._ensureCommentMatrix(e, n).getValue(t, r);
  168. return o ? Array.from(o).map((a) => this.getComment(e, n, a)).filter(Boolean) : [];
  169. }
  170. getComment(e, n, t) {
  171. return this._threadCommentModel.getComment(e, n, t);
  172. }
  173. getCommentWithChildren(e, n, t, r) {
  174. const s = this.getByLocation(e, n, t, r);
  175. if (!s)
  176. return;
  177. const o = this.getComment(e, n, s);
  178. if (o)
  179. return this._threadCommentModel.getThread(e, n, o.threadId);
  180. }
  181. showCommentMarker(e, n, t, r) {
  182. const s = this.getByLocation(e, n, t, r);
  183. if (!s)
  184. return false;
  185. const o = this.getComment(e, n, s);
  186. return !!(o && !o.resolved);
  187. }
  188. getSubUnitAll(e, n) {
  189. return this._threadCommentModel.getUnit(e).filter((t) => t.subUnitId === n).map((t) => t.root);
  190. }
  191. };
  192. p = q([
  193. w(0, ot(i)),
  194. w(1, _n)
  195. ], p);
  196. var J = Object.defineProperty;
  197. var K = Object.getOwnPropertyDescriptor;
  198. var Q = (i2, e, n, t) => {
  199. for (var r = t > 1 ? void 0 : t ? K(e, n) : e, s = i2.length - 1, o; s >= 0; s--)
  200. (o = i2[s]) && (r = (t ? o(e, n, r) : o(r)) || r);
  201. return t && r && J(e, n, r), r;
  202. };
  203. var _ = (i2, e) => (n, t) => e(n, t, i2);
  204. var f = class extends nt {
  205. constructor(e, n, t, r, s) {
  206. super();
  207. h(this, "_disposableMap", /* @__PURE__ */ new Map());
  208. h(this, "_watcherMap", /* @__PURE__ */ new Map());
  209. h(this, "_handleRangeChange", (e2, n2, t2, r2, s2) => {
  210. const o = t2.id, a = {
  211. startColumn: t2.column,
  212. endColumn: t2.column,
  213. startRow: t2.row,
  214. endRow: t2.row
  215. };
  216. return r2 ? {
  217. redos: [{
  218. id: te.id,
  219. params: {
  220. unitId: e2,
  221. subUnitId: n2,
  222. payload: {
  223. ref: fr(r2),
  224. commentId: o
  225. },
  226. silent: s2
  227. }
  228. }],
  229. undos: [{
  230. id: te.id,
  231. params: {
  232. unitId: e2,
  233. subUnitId: n2,
  234. payload: {
  235. ref: fr(a),
  236. commentId: o
  237. },
  238. silent: s2
  239. }
  240. }]
  241. } : {
  242. redos: [{
  243. id: N.id,
  244. params: {
  245. unitId: e2,
  246. subUnitId: n2,
  247. commentId: o
  248. }
  249. }],
  250. undos: [{
  251. id: P.id,
  252. params: {
  253. unitId: e2,
  254. subUnitId: n2,
  255. comment: t2,
  256. sync: true
  257. }
  258. }]
  259. };
  260. });
  261. this._refRangeService = e, this._sheetsThreadCommentModel = n, this._threadCommentModel = t, this._selectionManagerService = r, this._commandService = s, this._initData(), this._initRefRange();
  262. }
  263. _getIdWithUnitId(e, n, t) {
  264. return `${e}-${n}-${t}`;
  265. }
  266. _register(e, n, t) {
  267. const r = t.id, s = {
  268. startColumn: t.column,
  269. endColumn: t.column,
  270. startRow: t.row,
  271. endRow: t.row
  272. };
  273. this._disposableMap.set(
  274. this._getIdWithUnitId(e, n, r),
  275. this._refRangeService.registerRefRange(s, (o) => {
  276. const a = hh(s, o, { selectionManagerService: this._selectionManagerService }), c = Array.isArray(a) ? a[0] : a;
  277. return c && c.startColumn === s.startColumn && c.startRow === s.startRow ? {
  278. undos: [],
  279. redos: []
  280. } : this._handleRangeChange(e, n, t, c, false);
  281. }, e, n)
  282. );
  283. }
  284. _watch(e, n, t) {
  285. const r = t.id, s = {
  286. startColumn: t.column,
  287. endColumn: t.column,
  288. startRow: t.row,
  289. endRow: t.row
  290. };
  291. this._watcherMap.set(
  292. this._getIdWithUnitId(e, n, r),
  293. this._refRangeService.watchRange(e, n, s, (o, a) => {
  294. const { redos: c } = this._handleRangeChange(e, n, t, a, true);
  295. Q0(c, this._commandService, { onlyLocal: true });
  296. }, true)
  297. );
  298. }
  299. _unwatch(e, n, t) {
  300. var s;
  301. const r = this._getIdWithUnitId(e, n, t);
  302. (s = this._watcherMap.get(r)) == null || s.dispose(), this._watcherMap.delete(r);
  303. }
  304. _unregister(e, n, t) {
  305. var s;
  306. const r = this._getIdWithUnitId(e, n, t);
  307. (s = this._disposableMap.get(r)) == null || s.dispose(), this._disposableMap.delete(r);
  308. }
  309. _initData() {
  310. const e = this._threadCommentModel.getAll();
  311. for (const n of e)
  312. for (const t of n.threads) {
  313. const { unitId: r, subUnitId: s, root: o } = t, a = ns(o.ref), c = {
  314. ...o,
  315. ...a
  316. };
  317. this._register(r, s, c), this._watch(r, s, c);
  318. }
  319. }
  320. _initRefRange() {
  321. this.disposeWithMe(
  322. this._sheetsThreadCommentModel.commentUpdate$.subscribe((e) => {
  323. const { unitId: n, subUnitId: t } = e;
  324. switch (e.type) {
  325. case "add": {
  326. if (e.payload.parentId)
  327. return;
  328. const r = {
  329. ...e.payload,
  330. row: e.row,
  331. column: e.column
  332. };
  333. this._register(e.unitId, e.subUnitId, r), this._watch(e.unitId, e.subUnitId, r);
  334. break;
  335. }
  336. case "delete": {
  337. this._unregister(n, t, e.payload.commentId), this._unwatch(n, t, e.payload.commentId);
  338. break;
  339. }
  340. case "updateRef": {
  341. const r = this._sheetsThreadCommentModel.getComment(n, t, e.payload.commentId);
  342. if (!r)
  343. return;
  344. this._unregister(n, t, e.payload.commentId);
  345. const s = {
  346. ...r,
  347. row: e.row,
  348. column: e.column
  349. };
  350. e.silent || (this._unwatch(n, t, e.payload.commentId), this._watch(n, t, s)), this._register(e.unitId, e.subUnitId, s);
  351. break;
  352. }
  353. }
  354. })
  355. ), this.disposeWithMe(Ze(() => {
  356. this._disposableMap.forEach((e) => {
  357. e.dispose();
  358. }), this._disposableMap.clear();
  359. }));
  360. }
  361. };
  362. f = Q([
  363. _(0, ot(_t)),
  364. _(1, ot(p)),
  365. _(2, ot(i)),
  366. _(3, ot(F)),
  367. _(4, Pt)
  368. ], f);
  369. var X = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
  370. var I = Object.defineProperty;
  371. var Y = Object.getOwnPropertyDescriptor;
  372. var Z = (i2, e, n) => e in i2 ? I(i2, e, { enumerable: true, configurable: true, writable: true, value: n }) : i2[e] = n;
  373. var k = (i2, e, n, t) => {
  374. for (var r = t > 1 ? void 0 : t ? Y(e, n) : e, s = i2.length - 1, o; s >= 0; s--)
  375. (o = i2[s]) && (r = (t ? o(e, n, r) : o(r)) || r);
  376. return t && r && I(e, n, r), r;
  377. };
  378. var v = (i2, e) => (n, t) => e(n, t, i2);
  379. var U = (i2, e, n) => Z(i2, typeof e != "symbol" ? e + "" : e, n);
  380. var g = class extends Ra {
  381. constructor(i2, e, n) {
  382. super(), this._injector = e, this._commandService = n;
  383. }
  384. onStarting() {
  385. [
  386. [p],
  387. [f]
  388. ].forEach((i2) => {
  389. this._injector.add(i2);
  390. }), this._injector.get(f);
  391. }
  392. };
  393. U(g, "pluginName", X);
  394. U(g, "type", Fe.UNIVER_SHEET);
  395. g = k([
  396. OR(D),
  397. v(1, ot(Ot)),
  398. v(2, ot(Pt))
  399. ], g);
  400. export {
  401. p,
  402. f,
  403. g
  404. };
  405. //# sourceMappingURL=chunk-PEI6ACTC.js.map