@univerjs_sheets-thread-comment-ui.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. import {
  2. Et,
  3. F as F2,
  4. J,
  5. Mn,
  6. jt,
  7. ue as ue2,
  8. xn
  9. } from "./chunk-VMR7OHHI.js";
  10. import {
  11. g,
  12. p as p2
  13. } from "./chunk-PEI6ACTC.js";
  14. import {
  15. N as N2,
  16. P,
  17. ae,
  18. i,
  19. ne,
  20. oe,
  21. p,
  22. re as re2,
  23. se
  24. } from "./chunk-PG4GXCOC.js";
  25. import {
  26. De as De2,
  27. Er,
  28. Sn,
  29. gr,
  30. lf,
  31. me,
  32. tt,
  33. ue,
  34. vi,
  35. ws
  36. } from "./chunk-T4NNB5UY.js";
  37. import {
  38. F,
  39. Hn,
  40. Io,
  41. N,
  42. Nn,
  43. V,
  44. Ws,
  45. an,
  46. et,
  47. ko
  48. } from "./chunk-BW43Z7N3.js";
  49. import {
  50. fr,
  51. ns
  52. } from "./chunk-QRYBFJ3R.js";
  53. import "./chunk-MIOQ566M.js";
  54. import {
  55. $e,
  56. Ae,
  57. Fa,
  58. He,
  59. I1,
  60. P1,
  61. it,
  62. l1,
  63. m1,
  64. n1,
  65. u3
  66. } from "./chunk-POAJ2YNP.js";
  67. import "./chunk-GBYP4PB2.js";
  68. import "./chunk-PZD7N4BC.js";
  69. import {
  70. Yx
  71. } from "./chunk-2MK3Q52E.js";
  72. import "./chunk-BSDDCPAW.js";
  73. import "./chunk-QG2HZMYH.js";
  74. import {
  75. BehaviorSubject,
  76. De,
  77. Fe,
  78. Mi,
  79. OR,
  80. Ot,
  81. Pt,
  82. Ra,
  83. SE,
  84. Vn,
  85. W0,
  86. _n,
  87. ar,
  88. debounceTime,
  89. en,
  90. map,
  91. nt,
  92. nu,
  93. ot,
  94. re,
  95. tr,
  96. z0
  97. } from "./chunk-23V3HWTR.js";
  98. import {
  99. require_react
  100. } from "./chunk-GNR2UJZM.js";
  101. import {
  102. __toESM
  103. } from "./chunk-2LSFTFF7.js";
  104. // node_modules/.pnpm/@univerjs+sheets-thread-comment-ui@0.5.5_@grpc+grpc-js@1.13.4_react-dom@18.3.1_react@18.3.1_rxjs@7.8.1_typescript@5.4.5/node_modules/@univerjs/sheets-thread-comment-ui/lib/es/index.js
  105. var import_react = __toESM(require_react());
  106. var Be = Object.defineProperty;
  107. var ke = (o, e, n) => e in o ? Be(o, e, { enumerable: true, configurable: true, writable: true, value: n }) : o[e] = n;
  108. var E = (o, e, n) => ke(o, typeof e != "symbol" ? e + "" : e, n);
  109. var $e2 = "univer.sheet.thread-comment-modal";
  110. var de = "comment-single";
  111. var Ne = "SHEET_THREAD_COMMENT";
  112. var $t = Object.defineProperty;
  113. var Nt = Object.getOwnPropertyDescriptor;
  114. var xt = (o, e, n, t) => {
  115. for (var r = t > 1 ? void 0 : t ? Nt(e, n) : e, i2 = o.length - 1, s; i2 >= 0; i2--)
  116. (s = o[i2]) && (r = (t ? s(e, n, r) : s(r)) || r);
  117. return t && r && $t(e, n, r), r;
  118. };
  119. var _e = (o, e) => (n, t) => e(n, t, o);
  120. var O = class extends nt {
  121. constructor(e, n) {
  122. super();
  123. E(this, "_lastPopup", null);
  124. E(this, "_activePopup");
  125. E(this, "_activePopup$", new BehaviorSubject(null));
  126. E(this, "activePopup$", this._activePopup$.asObservable());
  127. this._canvasPopupManagerService = e, this._zenZoneService = n, this._initZenVisible(), this.disposeWithMe(() => {
  128. this._activePopup$.complete();
  129. });
  130. }
  131. get activePopup() {
  132. return this._activePopup;
  133. }
  134. _initZenVisible() {
  135. this.disposeWithMe(this._zenZoneService.visible$.subscribe((e) => {
  136. e && this.hidePopup();
  137. }));
  138. }
  139. showPopup(e, n) {
  140. var m;
  141. const { row: t, col: r, unitId: i2, subUnitId: s } = e;
  142. if (this._activePopup && t === this._activePopup.row && r === this._activePopup.col && i2 === this._activePopup.unitId && s === ((m = this.activePopup) == null ? void 0 : m.subUnitId)) {
  143. this._activePopup = e, this._activePopup$.next(e);
  144. return;
  145. }
  146. if (this._lastPopup && this._lastPopup.dispose(), this._zenZoneService.visible)
  147. return;
  148. this._activePopup = e, this._activePopup$.next(e);
  149. const c = this._canvasPopupManagerService.attachPopupToCell(
  150. t,
  151. r,
  152. {
  153. componentKey: $e2,
  154. onClickOutside: () => {
  155. this.hidePopup();
  156. },
  157. direction: "horizontal",
  158. excludeOutside: [
  159. ...Array.from(document.querySelectorAll(".univer-thread-comment")),
  160. document.getElementById("thread-comment-add")
  161. ].filter(Boolean)
  162. }
  163. );
  164. if (!c)
  165. throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");
  166. const a = new Mi();
  167. a.add(c), a.add({
  168. dispose: () => {
  169. n == null || n();
  170. }
  171. }), this._lastPopup = a;
  172. }
  173. hidePopup() {
  174. this._activePopup && (this._lastPopup && this._lastPopup.dispose(), this._lastPopup = null, this._activePopup = null, this._activePopup$.next(null));
  175. }
  176. persistPopup() {
  177. !this._activePopup || !this._activePopup.temp || (this._activePopup = {
  178. ...this._activePopup,
  179. temp: false
  180. }, this._activePopup$.next(this._activePopup));
  181. }
  182. };
  183. O = xt([
  184. _e(0, ot(vi)),
  185. _e(1, u3)
  186. ], O);
  187. var H = {
  188. type: ar.OPERATION,
  189. id: "sheets.operation.show-comment-modal",
  190. handler(o) {
  191. var f;
  192. const e = o.get(F), n = o.get(_n), t = o.get(O), r = o.get(J), i2 = (f = e.getCurrentLastSelection()) == null ? void 0 : f.primary, s = o.get(p2);
  193. if (!i2)
  194. return false;
  195. const c = N(n);
  196. if (!c)
  197. return false;
  198. const { workbook: a, worksheet: m, unitId: u, subUnitId: d } = c, h = {
  199. workbook: a,
  200. worksheet: m,
  201. unitId: u,
  202. subUnitId: d,
  203. row: i2.startRow,
  204. col: i2.startColumn
  205. };
  206. t.showPopup(h);
  207. const l = s.getByLocation(u, d, i2.startRow, i2.startColumn);
  208. return l && r.setActiveComment({
  209. unitId: u,
  210. subUnitId: d,
  211. commentId: l,
  212. trigger: "context-menu"
  213. }), true;
  214. }
  215. };
  216. var Dt = "sheets-thread-comment.config";
  217. var fe = {};
  218. var jt2 = Object.defineProperty;
  219. var At = Object.getOwnPropertyDescriptor;
  220. var Vt = (o, e, n, t) => {
  221. for (var r = t > 1 ? void 0 : t ? At(e, n) : e, i2 = o.length - 1, s; i2 >= 0; i2--)
  222. (s = o[i2]) && (r = (t ? s(e, n, r) : s(r)) || r);
  223. return t && r && jt2(e, n, r), r;
  224. };
  225. var L = (o, e) => (n, t) => e(n, t, o);
  226. var W = class extends nt {
  227. constructor(o, e, n, t) {
  228. super(), this._sheetInterceptorService = o, this._sheetsThreadCommentModel = e, this._univerInstanceService = n, this._renderManagerService = t, this._initViewModelIntercept(), this._initSkeletonChange();
  229. }
  230. _initViewModelIntercept() {
  231. this.disposeWithMe(
  232. this._sheetInterceptorService.intercept(
  233. et.CELL_CONTENT,
  234. {
  235. effect: Vn.Style,
  236. handler: (o, e, n) => {
  237. const { row: t, col: r, unitId: i2, subUnitId: s } = e;
  238. return this._sheetsThreadCommentModel.showCommentMarker(i2, s, t, r) ? n({
  239. ...o,
  240. markers: {
  241. ...o == null ? void 0 : o.markers,
  242. tr: {
  243. color: "#FFBD37",
  244. size: 6
  245. }
  246. }
  247. }) : n(o);
  248. },
  249. priority: 100
  250. }
  251. )
  252. );
  253. }
  254. _initSkeletonChange() {
  255. const o = () => {
  256. var r;
  257. const e = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
  258. if (!e)
  259. return;
  260. const n = e.getUnitId(), t = this._renderManagerService.getRenderById(n);
  261. (r = t == null ? void 0 : t.mainComponent) == null || r.makeForceDirty();
  262. };
  263. this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(debounceTime(16)).subscribe(() => {
  264. o();
  265. }));
  266. }
  267. };
  268. W = Vt([
  269. L(0, ot(V)),
  270. L(1, ot(p2)),
  271. L(2, _n),
  272. L(3, Yx)
  273. ], W);
  274. var Ht = Object.defineProperty;
  275. var Lt = Object.getOwnPropertyDescriptor;
  276. var Bt = (o, e, n, t) => {
  277. for (var r = t > 1 ? void 0 : t ? Lt(e, n) : e, i2 = o.length - 1, s; i2 >= 0; i2--)
  278. (s = o[i2]) && (r = (t ? s(e, n, r) : s(r)) || r);
  279. return t && r && Ht(e, n, r), r;
  280. };
  281. var ne2 = (o, e) => (n, t) => e(n, t, o);
  282. var kt = (o, e, n) => {
  283. const t = ns(o), r = n.row - e.row, i2 = n.column - e.column, s = {
  284. startColumn: t.column + i2,
  285. startRow: t.row + r,
  286. endColumn: t.column + i2,
  287. endRow: t.row + r
  288. };
  289. return fr(s);
  290. };
  291. var Z = class extends nt {
  292. constructor(e, n, t) {
  293. super();
  294. E(this, "_copyInfo");
  295. this._sheetClipboardService = e, this._sheetsThreadCommentModel = n, this._threadCommentDataSourceService = t, this._initClipboardHook();
  296. }
  297. // eslint-disable-next-line max-lines-per-function
  298. _initClipboardHook() {
  299. this.disposeWithMe(
  300. this._sheetClipboardService.addClipboardHook({
  301. id: Ne,
  302. onBeforeCopy: (e, n, t) => {
  303. this._copyInfo = {
  304. unitId: e,
  305. subUnitId: n,
  306. range: t
  307. };
  308. },
  309. // eslint-disable-next-line max-lines-per-function
  310. onPasteCells: (e, n, t, r) => {
  311. const { unitId: i2, subUnitId: s, range: c } = n, a = {
  312. row: c.rows[0],
  313. column: c.cols[0]
  314. };
  315. if (r.copyType === gr.CUT && this._copyInfo) {
  316. const { range: m, unitId: u, subUnitId: d } = this._copyInfo, h = {
  317. row: m.startRow,
  318. column: m.startColumn
  319. };
  320. if (!(i2 === u && s === d)) {
  321. const l = [];
  322. tr.foreach(m, (g2, p3) => {
  323. const I = this._sheetsThreadCommentModel.getAllByLocation(u, d, g2, p3);
  324. this._threadCommentDataSourceService.syncUpdateMutationToColla ? I.forEach((v) => {
  325. l.push(v);
  326. }) : I.forEach(({ children: v, ...M }) => {
  327. M.parentId || l.push(M);
  328. });
  329. });
  330. const f = [], S = [], U = [], D = [], ee = (g2) => {
  331. f.unshift({
  332. id: N2.id,
  333. params: {
  334. unitId: u,
  335. subUnitId: d,
  336. commentId: g2.id
  337. }
  338. }), U.push({
  339. id: P.id,
  340. params: {
  341. unitId: i2,
  342. subUnitId: s,
  343. comment: {
  344. ...g2,
  345. ref: kt(g2.ref, h, a),
  346. unitId: i2,
  347. subUnitId: s
  348. },
  349. sync: true
  350. }
  351. }), S.push({
  352. id: P.id,
  353. params: {
  354. unitId: u,
  355. subUnitId: d,
  356. comment: g2,
  357. sync: true
  358. }
  359. }), D.unshift({
  360. id: N2.id,
  361. params: {
  362. unitId: i2,
  363. subUnitId: s,
  364. commentId: g2.id
  365. }
  366. });
  367. };
  368. return l.forEach((g2) => {
  369. ee(g2);
  370. }), {
  371. redos: [...f, ...U],
  372. undos: [...D, ...S]
  373. };
  374. }
  375. }
  376. return {
  377. redos: [],
  378. undos: []
  379. };
  380. }
  381. })
  382. );
  383. }
  384. };
  385. Z = Bt([
  386. ne2(0, ot(Sn)),
  387. ne2(1, ot(p2)),
  388. ne2(2, p)
  389. ], Z);
  390. var Ft = Object.defineProperty;
  391. var Wt = Object.getOwnPropertyDescriptor;
  392. var Zt = (o, e, n, t) => {
  393. for (var r = t > 1 ? void 0 : t ? Wt(e, n) : e, i2 = o.length - 1, s; i2 >= 0; i2--)
  394. (s = o[i2]) && (r = (t ? s(e, n, r) : s(r)) || r);
  395. return t && r && Ft(e, n, r), r;
  396. };
  397. var B = (o, e) => (n, t) => e(n, t, o);
  398. var z = class extends nt {
  399. constructor(o, e, n, t) {
  400. super(), this._hoverManagerService = o, this._sheetsThreadCommentPopupService = e, this._sheetsThreadCommentModel = n, this._sheetPermissionCheckController = t, this._initHoverEvent();
  401. }
  402. _initHoverEvent() {
  403. this.disposeWithMe(
  404. this._hoverManagerService.currentCell$.pipe(debounceTime(100)).subscribe((o) => {
  405. const e = this._sheetsThreadCommentPopupService.activePopup;
  406. if (o && (e && e.temp || !e)) {
  407. const { location: n } = o, { unitId: t, subUnitId: r, row: i2, col: s } = n, c = this._sheetsThreadCommentModel.getByLocation(t, r, i2, s);
  408. if (c) {
  409. if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
  410. workbookTypes: [Ws],
  411. worksheetTypes: [Hn],
  412. rangeTypes: [Io]
  413. }, [{ startRow: i2, startColumn: s, endRow: i2, endColumn: s }]))
  414. return;
  415. const m = this._sheetsThreadCommentModel.getComment(t, r, c);
  416. m && !m.resolved && this._sheetsThreadCommentPopupService.showPopup({
  417. unitId: t,
  418. subUnitId: r,
  419. row: i2,
  420. col: s,
  421. commentId: c,
  422. temp: true
  423. });
  424. } else
  425. e && this._sheetsThreadCommentPopupService.hidePopup();
  426. }
  427. })
  428. );
  429. }
  430. };
  431. z = Zt([
  432. B(0, ot(Er)),
  433. B(1, ot(O)),
  434. B(2, ot(p2)),
  435. B(3, ot(Nn))
  436. ], z);
  437. var zt = Object.defineProperty;
  438. var qt = Object.getOwnPropertyDescriptor;
  439. var Gt = (o, e, n, t) => {
  440. for (var r = t > 1 ? void 0 : t ? qt(e, n) : e, i2 = o.length - 1, s; i2 >= 0; i2--)
  441. (s = o[i2]) && (r = (t ? s(e, n, r) : s(r)) || r);
  442. return t && r && zt(e, n, r), r;
  443. };
  444. var w = (o, e) => (n, t) => e(n, t, o);
  445. var q = class extends nt {
  446. constructor(e, n, t, r, i2, s, c, a, m, u) {
  447. super();
  448. E(this, "_isSwitchToCommenting", false);
  449. E(this, "_selectionShapeInfo", null);
  450. this._commandService = e, this._sheetsThreadCommentPopupService = n, this._sheetsThreadCommentModel = t, this._threadCommentPanelService = r, this._univerInstanceService = i2, this._sheetPermissionCheckController = s, this._markSelectionService = c, this._sheetSelectionService = a, this._editorBridgeService = m, this._renderManagerService = u, this._initCommandListener(), this._initPanelListener(), this._initMarkSelection(), this._initSelectionUpdateListener(), this._initEditorBridge();
  451. }
  452. _handleSelectionChange(e, n, t) {
  453. var h, l, f;
  454. const r = (h = e[0]) == null ? void 0 : h.range, i2 = this._renderManagerService.getRenderById(n), s = (l = i2 == null ? void 0 : i2.with(me).getWorksheetSkeleton(t)) == null ? void 0 : l.skeleton;
  455. if (!s || !r)
  456. return;
  457. const c = s.getCellWithCoordByIndex(r.startRow, r.startColumn);
  458. if ((((f = r.rangeType) != null ? f : De.NORMAL) !== De.NORMAL || r.endColumn - r.startColumn > 0 || r.endRow - r.startRow > 0) && !((c.isMerged || c.isMergedMainCell) && en.equals(c.mergeInfo, r))) {
  459. this._threadCommentPanelService.activeCommentId && this._commandService.executeCommand(F2.id);
  460. return;
  461. }
  462. const m = c.actualRow, u = c.actualColumn;
  463. if (!this._sheetsThreadCommentModel.showCommentMarker(n, t, m, u)) {
  464. this._threadCommentPanelService.activeCommentId && this._commandService.executeCommand(F2.id);
  465. return;
  466. }
  467. const d = this._sheetsThreadCommentModel.getByLocation(n, t, m, u);
  468. d && this._commandService.executeCommand(F2.id, {
  469. unitId: n,
  470. subUnitId: t,
  471. commentId: d
  472. });
  473. }
  474. _initSelectionUpdateListener() {
  475. this.disposeWithMe(
  476. this._sheetSelectionService.selectionMoveEnd$.subscribe((e) => {
  477. if (this._isSwitchToCommenting)
  478. return;
  479. const n = this._sheetSelectionService.currentSelectionParam;
  480. n && this._handleSelectionChange(e, n.unitId, n.sheetId);
  481. })
  482. );
  483. }
  484. _initEditorBridge() {
  485. this.disposeWithMe(
  486. this._editorBridgeService.visible$.subscribe((e) => {
  487. e.visible && this._sheetsThreadCommentPopupService.hidePopup();
  488. })
  489. );
  490. }
  491. _initCommandListener() {
  492. this._commandService.onCommandExecuted((e) => {
  493. if (e.id === N2.id) {
  494. const n = e.params, t = this._sheetsThreadCommentPopupService.activePopup;
  495. if (!t)
  496. return;
  497. const { unitId: r, subUnitId: i2, commentId: s } = t;
  498. n.unitId === r && n.subUnitId === i2 && n.commentId === s && this._sheetsThreadCommentPopupService.hidePopup();
  499. }
  500. });
  501. }
  502. _initPanelListener() {
  503. this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async (e) => {
  504. var n;
  505. if (e) {
  506. const { unitId: t, subUnitId: r, commentId: i2, trigger: s } = e, c = this._sheetsThreadCommentModel.getComment(t, r, i2);
  507. if (!c || c.resolved)
  508. return;
  509. const a = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
  510. if (!a || a.getUnitId() !== t)
  511. return;
  512. this._isSwitchToCommenting = true, ((n = a.getActiveSheet()) == null ? void 0 : n.getSheetId()) !== r && await this._commandService.executeCommand(an.id, {
  513. unitId: t,
  514. subUnitId: r
  515. }), this._isSwitchToCommenting = false;
  516. const d = ns(c.ref), { row: h, column: l } = d;
  517. if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
  518. workbookTypes: [Ws],
  519. worksheetTypes: [Hn],
  520. rangeTypes: [Io]
  521. }, [{ startRow: h, startColumn: l, endRow: h, endColumn: l }]))
  522. return;
  523. const S = 1;
  524. if (await this._commandService.executeCommand(lf.id, {
  525. range: {
  526. startRow: Math.max(d.row - S, 0),
  527. endRow: d.row + S,
  528. startColumn: Math.max(d.column - S, 0),
  529. endColumn: d.column + S
  530. }
  531. }), this._editorBridgeService.isVisible().visible)
  532. return;
  533. this._sheetsThreadCommentPopupService.showPopup({
  534. unitId: t,
  535. subUnitId: r,
  536. row: d.row,
  537. col: d.column,
  538. commentId: c.id,
  539. trigger: s
  540. });
  541. } else
  542. this._sheetsThreadCommentPopupService.hidePopup();
  543. }));
  544. }
  545. _initMarkSelection() {
  546. this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(debounceTime(100)).subscribe((e) => {
  547. var h, l;
  548. if (!e) {
  549. this._selectionShapeInfo && (this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId), this._selectionShapeInfo = null);
  550. return;
  551. }
  552. const { unitId: n, subUnitId: t, commentId: r } = e;
  553. this._selectionShapeInfo && (this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId), this._selectionShapeInfo = null);
  554. const i2 = this._sheetsThreadCommentModel.getComment(n, t, r);
  555. if (!i2)
  556. return;
  557. const s = ns(i2.ref), { row: c, column: a } = s;
  558. if (Number.isNaN(c) || Number.isNaN(a))
  559. return null;
  560. const m = (h = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET)) == null ? void 0 : h.getSheetBySheetId(t), u = (l = m == null ? void 0 : m.getMergedCell(c, a)) != null ? l : {
  561. startColumn: a,
  562. endColumn: a,
  563. startRow: c,
  564. endRow: c
  565. }, d = this._markSelectionService.addShape(
  566. {
  567. range: u,
  568. style: {
  569. // hasAutoFill: false,
  570. fill: "rgb(255, 189, 55, 0.35)",
  571. strokeWidth: 1,
  572. stroke: "#FFBD37",
  573. widgets: {}
  574. },
  575. primary: null
  576. },
  577. [],
  578. -1
  579. );
  580. d && (this._selectionShapeInfo = {
  581. ...e,
  582. shapeId: d
  583. });
  584. }));
  585. }
  586. };
  587. q = Gt([
  588. w(0, Pt),
  589. w(1, ot(O)),
  590. w(2, ot(p2)),
  591. w(3, ot(J)),
  592. w(4, _n),
  593. w(5, ot(Nn)),
  594. w(6, ws),
  595. w(7, ot(F)),
  596. w(8, tt),
  597. w(9, Yx)
  598. ], q);
  599. var Jt = Object.defineProperty;
  600. var Yt = Object.getOwnPropertyDescriptor;
  601. var Kt = (o, e, n, t) => {
  602. for (var r = t > 1 ? void 0 : t ? Yt(e, n) : e, i2 = o.length - 1, s; i2 >= 0; i2--)
  603. (s = o[i2]) && (r = (t ? s(e, n, r) : s(r)) || r);
  604. return t && r && Jt(e, n, r), r;
  605. };
  606. var k = (o, e) => (n, t) => e(n, t, o);
  607. var G = class extends nt {
  608. constructor(o, e, n, t) {
  609. super(), this._sheetInterceptorService = o, this._univerInstanceService = e, this._threadCommentModel = n, this._threadCommentDataSourceService = t, this._initSheetChange();
  610. }
  611. _initSheetChange() {
  612. this.disposeWithMe(
  613. this._sheetInterceptorService.interceptCommand({
  614. getMutations: (o) => {
  615. var e;
  616. if (o.id === ko.id) {
  617. const n = o.params, t = n.unitId ? this._univerInstanceService.getUnit(n.unitId) : this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
  618. if (!t)
  619. return { redos: [], undos: [] };
  620. const r = t.getUnitId(), i2 = n.subUnitId || ((e = t.getActiveSheet()) == null ? void 0 : e.getSheetId());
  621. if (!i2)
  622. return { redos: [], undos: [] };
  623. const s = this._threadCommentModel.ensureMap(r, i2), c = Array.from(s.values()).filter((h) => !h.parentId), a = c.map((h) => h.id), m = this._threadCommentDataSourceService.syncUpdateMutationToColla, u = a.map((h) => ({
  624. id: N2.id,
  625. params: {
  626. unitId: r,
  627. subUnitId: i2,
  628. commentId: h
  629. }
  630. })), d = c.map(({ children: h, ...l }) => ({
  631. id: P.id,
  632. params: {
  633. unitId: r,
  634. subUnitId: i2,
  635. comment: {
  636. ...l,
  637. children: m ? h : void 0
  638. },
  639. sync: !m
  640. }
  641. }));
  642. return { redos: u, undos: d };
  643. }
  644. return { redos: [], undos: [] };
  645. }
  646. })
  647. );
  648. }
  649. };
  650. G = Kt([
  651. k(0, ot(V)),
  652. k(1, _n),
  653. k(2, ot(i)),
  654. k(3, p)
  655. ], G);
  656. var P2 = function() {
  657. return P2 = Object.assign || function(o) {
  658. for (var e, n = 1, t = arguments.length; n < t; n++) {
  659. e = arguments[n];
  660. for (var r in e)
  661. Object.prototype.hasOwnProperty.call(e, r) && (o[r] = e[r]);
  662. }
  663. return o;
  664. }, P2.apply(this, arguments);
  665. };
  666. var Qt = function(o, e) {
  667. var n = {};
  668. for (var t in o)
  669. Object.prototype.hasOwnProperty.call(o, t) && e.indexOf(t) < 0 && (n[t] = o[t]);
  670. if (o != null && typeof Object.getOwnPropertySymbols == "function")
  671. for (var r = 0, t = Object.getOwnPropertySymbols(o); r < t.length; r++)
  672. e.indexOf(t[r]) < 0 && Object.prototype.propertyIsEnumerable.call(o, t[r]) && (n[t[r]] = o[t[r]]);
  673. return n;
  674. };
  675. var xe = (0, import_react.forwardRef)(function(o, e) {
  676. var n = o.icon, t = o.id, r = o.className, i2 = o.extend, s = Qt(o, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(t, " ").concat(r || "").trim(), a = (0, import_react.useRef)("_".concat(tn()));
  677. return De3(n, "".concat(t), { defIds: n.defIds, idSuffix: a.current }, P2({ ref: e, className: c }, s), i2);
  678. });
  679. function De3(o, e, n, t, r) {
  680. return (0, import_react.createElement)(o.tag, P2(P2({ key: e }, Xt(o, n, r)), t), (en2(o, n).children || []).map(function(i2, s) {
  681. return De3(i2, "".concat(e, "-").concat(o.tag, "-").concat(s), n, void 0, r);
  682. }));
  683. }
  684. function Xt(o, e, n) {
  685. var t = P2({}, o.attrs);
  686. n != null && n.colorChannel1 && t.fill === "colorChannel1" && (t.fill = n.colorChannel1);
  687. var r = e.defIds;
  688. return !r || r.length === 0 || (o.tag === "use" && t["xlink:href"] && (t["xlink:href"] = t["xlink:href"] + e.idSuffix), Object.entries(t).forEach(function(i2) {
  689. var s = i2[0], c = i2[1];
  690. typeof c == "string" && (t[s] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
  691. })), t;
  692. }
  693. function en2(o, e) {
  694. var n, t = e.defIds;
  695. return !t || t.length === 0 ? o : o.tag === "defs" && (!((n = o.children) === null || n === void 0) && n.length) ? P2(P2({}, o), { children: o.children.map(function(r) {
  696. return typeof r.attrs.id == "string" && t && t.indexOf(r.attrs.id) > -1 ? P2(P2({}, r), { attrs: P2(P2({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
  697. }) }) : o;
  698. }
  699. function tn() {
  700. return Math.random().toString(36).substring(2, 8);
  701. }
  702. xe.displayName = "UniverIcon";
  703. var nn = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z", fillRule: "evenodd", clipRule: "evenodd" } }] };
  704. var je = (0, import_react.forwardRef)(function(o, e) {
  705. return (0, import_react.createElement)(xe, Object.assign({}, o, {
  706. id: "comment-single",
  707. ref: e,
  708. icon: nn
  709. }));
  710. });
  711. je.displayName = "CommentSingle";
  712. var re3 = { exports: {} };
  713. var j = {};
  714. var ve;
  715. function rn() {
  716. if (ve)
  717. return j;
  718. ve = 1;
  719. var o = import_react.default, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), t = Object.prototype.hasOwnProperty, r = o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, i2 = { key: true, ref: true, __self: true, __source: true };
  720. function s(c, a, m) {
  721. var u, d = {}, h = null, l = null;
  722. m !== void 0 && (h = "" + m), a.key !== void 0 && (h = "" + a.key), a.ref !== void 0 && (l = a.ref);
  723. for (u in a)
  724. t.call(a, u) && !i2.hasOwnProperty(u) && (d[u] = a[u]);
  725. if (c && c.defaultProps)
  726. for (u in a = c.defaultProps, a)
  727. d[u] === void 0 && (d[u] = a[u]);
  728. return { $$typeof: e, type: c, key: h, ref: l, props: d, _owner: r.current };
  729. }
  730. return j.Fragment = n, j.jsx = s, j.jsxs = s, j;
  731. }
  732. var Ce;
  733. function on() {
  734. return Ce || (Ce = 1, re3.exports = rn()), re3.exports;
  735. }
  736. var Ae2 = on();
  737. var sn = () => {
  738. const o = W0(_n), e = W0(O), n = z0(e.activePopup$), t = W0(p2);
  739. if (z0(t.commentUpdate$), !n)
  740. return null;
  741. const { row: r, col: i2, unitId: s, subUnitId: c, trigger: a } = n, m = t.getByLocation(s, c, r, i2), u = `${re.chatAtABC(i2)}${r + 1}`, d = () => {
  742. e.hidePopup();
  743. }, h = (l) => {
  744. var f, S, U;
  745. return (U = (S = (f = o.getCurrentUnitForType(Fe.UNIVER_SHEET)) == null ? void 0 : f.getSheetBySheetId(l)) == null ? void 0 : S.getName()) != null ? U : "";
  746. };
  747. return Ae2.jsx(
  748. xn,
  749. {
  750. onClick: () => {
  751. e.persistPopup();
  752. },
  753. prefix: "cell",
  754. id: m,
  755. unitId: s,
  756. subUnitId: c,
  757. type: Fe.UNIVER_SHEET,
  758. refStr: u,
  759. onClose: d,
  760. getSubUnitName: h,
  761. autoFocus: a === "context-menu"
  762. }
  763. );
  764. };
  765. var cn = () => {
  766. var g2;
  767. const o = W0(ws), e = W0(_n), n = W0(O), t = e.getCurrentUnitForType(Fe.UNIVER_SHEET), r = t.getUnitId(), i2 = W0(Pt), s = (0, import_react.useMemo)(() => t.activeSheet$.pipe(map((p3) => p3 == null ? void 0 : p3.getSheetId())), [t.activeSheet$]), c = z0(s, (g2 = t.getActiveSheet()) == null ? void 0 : g2.getSheetId()), a = (0, import_react.useRef)(), m = W0(J), u = z0(m.activeCommentId$), d = z0(m.panelVisible$, m.panelVisible), h = (0, import_react.useCallback)((p3) => {
  768. const I = t.getSheets(), v = {};
  769. I.forEach((T, C) => {
  770. v[T.getSheetId()] = C;
  771. });
  772. const M = (T) => T.map((C) => {
  773. var me2;
  774. const y = ns(C.ref), Le = [(me2 = v[C.subUnitId]) != null ? me2 : 0, y.row, y.column];
  775. return { ...C, p: Le };
  776. }).sort((C, y) => C.p[0] === y.p[0] ? C.p[1] === y.p[1] ? C.p[2] - y.p[2] : C.p[1] - y.p[1] : C.p[0] - y.p[0]);
  777. return [
  778. ...M(p3.filter((T) => !T.resolved)),
  779. ...M(p3.filter((T) => T.resolved))
  780. ];
  781. }, [t]), l = (0, import_react.useCallback)((p3) => {
  782. var I;
  783. if (p3.unitId === r && p3.subUnitId === c && !p3.resolved) {
  784. const { row: v, column: M } = ns(p3.ref), T = t.getSheetBySheetId(p3.subUnitId), C = (I = T == null ? void 0 : T.getMergedCell(v, M)) != null ? I : {
  785. startColumn: M,
  786. endColumn: M,
  787. startRow: v,
  788. endRow: v
  789. };
  790. if (!Number.isNaN(v) && !Number.isNaN(M))
  791. return o.addShape({
  792. range: C,
  793. style: {
  794. // hasAutoFill: false,
  795. fill: "rgb(255, 189, 55, 0.35)",
  796. strokeWidth: 1,
  797. stroke: "#FFBD37",
  798. widgets: {}
  799. },
  800. primary: null
  801. });
  802. }
  803. }, [o, c, r]), f = (p3) => {
  804. var I, v;
  805. return (v = (I = t.getSheetBySheetId(p3)) == null ? void 0 : I.getName()) != null ? v : "";
  806. }, S = () => {
  807. i2.executeCommand(H.id);
  808. }, U = (p3) => {
  809. u && u.unitId === p3.unitId && u.subUnitId === p3.subUnitId && u.commentId === p3.id || (a.current && (o.removeShape(a.current), a.current = null), a.current = l(p3));
  810. }, D = () => {
  811. a.current && (o.removeShape(a.current), a.current = null);
  812. }, ee = (p3, I) => {
  813. I && n.hidePopup();
  814. };
  815. return (0, import_react.useEffect)(() => {
  816. !d && a.current && o.removeShape(a.current);
  817. }, [o, d]), Ae2.jsx(
  818. Mn,
  819. {
  820. unitId: r,
  821. subUnitId$: s,
  822. type: Fe.UNIVER_SHEET,
  823. onAdd: S,
  824. getSubUnitName: f,
  825. onResolve: ee,
  826. sortComments: h,
  827. onItemEnter: U,
  828. onItemLeave: D,
  829. onDeleteComment: () => (D(), true)
  830. }
  831. );
  832. };
  833. var an2 = (o) => ({
  834. id: H.id,
  835. type: $e.BUTTON,
  836. icon: de,
  837. title: "sheetThreadComment.menu.addComment",
  838. hidden$: Fa(o, Fe.UNIVER_SHEET),
  839. disabled$: ue(o, {
  840. workbookTypes: [Ws],
  841. worksheetTypes: [Hn],
  842. rangeTypes: [Io]
  843. })
  844. });
  845. var un = (o) => ({
  846. id: Et.id,
  847. type: $e.BUTTON,
  848. icon: de,
  849. tooltip: "sheetThreadComment.menu.commentManagement",
  850. disabled$: ue(o, {
  851. workbookTypes: [Ws],
  852. worksheetTypes: [Hn],
  853. rangeTypes: [Io]
  854. }),
  855. hidden$: Fa(o, Fe.UNIVER_SHEET)
  856. });
  857. var dn = {
  858. id: H.id,
  859. binding: I1.M | Ae.CTRL_COMMAND | Ae.ALT,
  860. preconditions: De2
  861. };
  862. var mn = {
  863. [l1.OTHERS]: {
  864. [Et.id]: {
  865. order: 1,
  866. menuItemFactory: un
  867. }
  868. },
  869. [P1.MAIN_AREA]: {
  870. [He.OTHERS]: {
  871. [H.id]: {
  872. order: 0,
  873. menuItemFactory: an2
  874. }
  875. }
  876. }
  877. };
  878. var hn = Object.defineProperty;
  879. var ln = Object.getOwnPropertyDescriptor;
  880. var pn = (o, e, n, t) => {
  881. for (var r = t > 1 ? void 0 : t ? ln(e, n) : e, i2 = o.length - 1, s; i2 >= 0; i2--)
  882. (s = o[i2]) && (r = (t ? s(e, n, r) : s(r)) || r);
  883. return t && r && hn(e, n, r), r;
  884. };
  885. var oe2 = (o, e) => (n, t) => e(n, t, o);
  886. var J2 = class extends nt {
  887. constructor(o, e, n) {
  888. super(), this._menuManagerService = o, this._componentManager = e, this._shortcutService = n, this._initMenu(), this._initShortcut(), this._initComponent();
  889. }
  890. _initShortcut() {
  891. this._shortcutService.registerShortcut(dn);
  892. }
  893. _initMenu() {
  894. this._menuManagerService.mergeMenu(mn);
  895. }
  896. _initComponent() {
  897. [
  898. [$e2, sn],
  899. [jt, cn],
  900. [de, je]
  901. ].forEach(([o, e]) => {
  902. this._componentManager.register(o, e);
  903. });
  904. }
  905. };
  906. J2 = pn([
  907. oe2(0, m1),
  908. oe2(1, ot(n1)),
  909. oe2(2, it)
  910. ], J2);
  911. var Ve = Object.defineProperty;
  912. var _n2 = Object.getOwnPropertyDescriptor;
  913. var fn = (o, e, n) => e in o ? Ve(o, e, { enumerable: true, configurable: true, writable: true, value: n }) : o[e] = n;
  914. var vn = (o, e, n, t) => {
  915. for (var r = t > 1 ? void 0 : t ? _n2(e, n) : e, i2 = o.length - 1, s; i2 >= 0; i2--)
  916. (s = o[i2]) && (r = (t ? s(e, n, r) : s(r)) || r);
  917. return t && r && Ve(e, n, r), r;
  918. };
  919. var ie = (o, e) => (n, t) => e(n, t, o);
  920. var He2 = (o, e, n) => fn(o, typeof e != "symbol" ? e + "" : e, n);
  921. var Y = class extends Ra {
  922. constructor(o = fe, e, n, t) {
  923. super(), this._config = o, this._injector = e, this._commandService = n, this._configService = t;
  924. const { menu: r, ...i2 } = nu(
  925. {},
  926. fe,
  927. this._config
  928. );
  929. r && this._configService.setConfig("menu", r, { merge: true }), this._configService.setConfig(Dt, i2);
  930. }
  931. onStarting() {
  932. [
  933. [J2],
  934. [W],
  935. [Z],
  936. [z],
  937. [G],
  938. [q],
  939. [O]
  940. ].forEach((o) => {
  941. this._injector.add(o);
  942. }), [H].forEach((o) => {
  943. this._commandService.registerCommand(o);
  944. }), this._injector.get(J2);
  945. }
  946. onReady() {
  947. this._injector.get(W), this._injector.get(G);
  948. }
  949. onRendered() {
  950. this._injector.get(Z), this._injector.get(z), this._injector.get(q);
  951. }
  952. };
  953. He2(Y, "pluginName", Ne);
  954. He2(Y, "type", Fe.UNIVER_SHEET);
  955. Y = vn([
  956. OR(ue2, g),
  957. ie(1, ot(Ot)),
  958. ie(2, ot(Pt)),
  959. ie(3, SE)
  960. ], Y);
  961. export {
  962. ne as AddCommentCommand,
  963. ae as DeleteCommentCommand,
  964. se as DeleteCommentTreeCommand,
  965. p as IThreadCommentDataSourceService,
  966. re2 as ResolveCommentCommand,
  967. Ne as SHEETS_THREAD_COMMENT,
  968. O as SheetsThreadCommentPopupService,
  969. H as ShowAddSheetCommentModalOperation,
  970. Y as UniverSheetsThreadCommentUIPlugin,
  971. ue2 as UniverThreadCommentUIPlugin,
  972. oe as UpdateCommentCommand
  973. };
  974. /*! Bundled license information:
  975. @univerjs/sheets-thread-comment-ui/lib/es/index.js:
  976. (**
  977. * @license React
  978. * react-jsx-runtime.production.min.js
  979. *
  980. * Copyright (c) Facebook, Inc. and its affiliates.
  981. *
  982. * This source code is licensed under the MIT license found in the
  983. * LICENSE file in the root directory of this source tree.
  984. *)
  985. */
  986. //# sourceMappingURL=@univerjs_sheets-thread-comment-ui.js.map