import { D, N, P, i, te } from "./chunk-PG4GXCOC.js"; import { F, _t, hh } from "./chunk-BW43Z7N3.js"; import { fr, ns } from "./chunk-QRYBFJ3R.js"; import { Fe, OR, Ot, Pt, Q0, Ra, Subject, Ze, _n, kt, nt, ot } from "./chunk-23V3HWTR.js"; // node_modules/.pnpm/@univerjs+sheets-thread-comment@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets-thread-comment/lib/es/index.js var x = Object.defineProperty; var T = (i2, e, n) => e in i2 ? x(i2, e, { enumerable: true, configurable: true, writable: true, value: n }) : i2[e] = n; var h = (i2, e, n) => T(i2, typeof e != "symbol" ? e + "" : e, n); var z = Object.defineProperty; var G = Object.getOwnPropertyDescriptor; var q = (i2, e, n, t) => { for (var r = t > 1 ? void 0 : t ? G(e, n) : e, s = i2.length - 1, o; s >= 0; s--) (o = i2[s]) && (r = (t ? o(e, n, r) : o(r)) || r); return t && r && z(e, n, r), r; }; var w = (i2, e) => (n, t) => e(n, t, i2); var p = class extends nt { constructor(e, n) { super(); h(this, "_matrixMap", /* @__PURE__ */ new Map()); h(this, "_locationMap", /* @__PURE__ */ new Map()); h(this, "_commentUpdate$", new Subject()); h(this, "commentUpdate$", this._commentUpdate$.asObservable()); this._threadCommentModel = e, this._univerInstanceService = n, this._init(), this.disposeWithMe(() => { this._commentUpdate$.complete(); }); } _init() { this._initData(), this._initUpdateTransform(); } _ensureCommentMatrix(e, n) { let t = this._matrixMap.get(e); t || (t = /* @__PURE__ */ new Map(), this._matrixMap.set(e, t)); let r = t.get(n); return r || (r = new kt(), t.set(n, r)), r; } _ensureCommentLocationMap(e, n) { let t = this._locationMap.get(e); t || (t = /* @__PURE__ */ new Map(), this._locationMap.set(e, t)); let r = t.get(n); return r || (r = /* @__PURE__ */ new Map(), t.set(n, r)), r; } _addCommentToMatrix(e, n, t, r) { var o; const s = (o = e.getValue(n, t)) != null ? o : /* @__PURE__ */ new Set(); s.add(r), e.setValue(n, t, s); } _deleteCommentFromMatrix(e, n, t, r) { if (n >= 0 && t >= 0) { const s = e.getValue(n, t); s && s.has(r) && (s.delete(r), s.size === 0 && e.realDeleteValue(n, t)); } } _ensure(e, n) { const t = this._ensureCommentMatrix(e, n), r = this._ensureCommentLocationMap(e, n); return { matrix: t, locationMap: r }; } _initData() { const e = this._threadCommentModel.getAll(); for (const n of e) for (const t of n.threads) { const { unitId: r, subUnitId: s, root: o } = t; this._addComment(r, s, o); } } _addComment(e, n, t) { const r = ns(t.ref), s = t.parentId, { row: o, column: a } = r, c = t.id, { matrix: m, locationMap: d } = this._ensure(e, n); !s && o >= 0 && a >= 0 && (this._addCommentToMatrix(m, o, a, c), d.set(c, { row: o, column: a })), s || this._commentUpdate$.next({ unitId: e, subUnitId: n, payload: t, type: "add", isRoot: !s, ...r }); } // eslint-disable-next-line max-lines-per-function _initUpdateTransform() { this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((e) => { const { unitId: n, subUnitId: t } = e; try { if (this._univerInstanceService.getUnitType(n) !== Fe.UNIVER_SHEET) return; } catch { } const { matrix: r, locationMap: s } = this._ensure(n, t); switch (e.type) { case "add": { this._addComment(e.unitId, e.subUnitId, e.payload); break; } case "delete": { const { isRoot: o, comment: a } = e.payload; if (o) { const c = ns(a.ref), { row: m, column: d } = c; this._deleteCommentFromMatrix(r, m, d, a.id), this._commentUpdate$.next({ ...e, ...c }); } break; } case "update": { const { commentId: o } = e.payload, a = this._threadCommentModel.getComment(n, t, o); if (!a) return; const c = ns(a.ref); this._commentUpdate$.next({ ...e, ...c }); break; } case "updateRef": { const o = ns(e.payload.ref), { commentId: a } = e.payload, c = s.get(a); if (!c) return; const { row: m, column: d } = c; 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({ ...e, ...o }); break; } case "resolve": { const { unitId: o, subUnitId: a, payload: c } = e, { locationMap: m } = this._ensure(o, a), d = m.get(c.commentId); d && this._commentUpdate$.next({ ...e, ...d }); break; } } })); } getByLocation(e, n, t, r) { var a; return (a = this.getAllByLocation(e, n, t, r).filter((c) => !c.resolved)[0]) == null ? void 0 : a.id; } getAllByLocation(e, n, t, r) { const o = this._ensureCommentMatrix(e, n).getValue(t, r); return o ? Array.from(o).map((a) => this.getComment(e, n, a)).filter(Boolean) : []; } getComment(e, n, t) { return this._threadCommentModel.getComment(e, n, t); } getCommentWithChildren(e, n, t, r) { const s = this.getByLocation(e, n, t, r); if (!s) return; const o = this.getComment(e, n, s); if (o) return this._threadCommentModel.getThread(e, n, o.threadId); } showCommentMarker(e, n, t, r) { const s = this.getByLocation(e, n, t, r); if (!s) return false; const o = this.getComment(e, n, s); return !!(o && !o.resolved); } getSubUnitAll(e, n) { return this._threadCommentModel.getUnit(e).filter((t) => t.subUnitId === n).map((t) => t.root); } }; p = q([ w(0, ot(i)), w(1, _n) ], p); var J = Object.defineProperty; var K = Object.getOwnPropertyDescriptor; var Q = (i2, e, n, t) => { for (var r = t > 1 ? void 0 : t ? K(e, n) : e, s = i2.length - 1, o; s >= 0; s--) (o = i2[s]) && (r = (t ? o(e, n, r) : o(r)) || r); return t && r && J(e, n, r), r; }; var _ = (i2, e) => (n, t) => e(n, t, i2); var f = class extends nt { constructor(e, n, t, r, s) { super(); h(this, "_disposableMap", /* @__PURE__ */ new Map()); h(this, "_watcherMap", /* @__PURE__ */ new Map()); h(this, "_handleRangeChange", (e2, n2, t2, r2, s2) => { const o = t2.id, a = { startColumn: t2.column, endColumn: t2.column, startRow: t2.row, endRow: t2.row }; return r2 ? { redos: [{ id: te.id, params: { unitId: e2, subUnitId: n2, payload: { ref: fr(r2), commentId: o }, silent: s2 } }], undos: [{ id: te.id, params: { unitId: e2, subUnitId: n2, payload: { ref: fr(a), commentId: o }, silent: s2 } }] } : { redos: [{ id: N.id, params: { unitId: e2, subUnitId: n2, commentId: o } }], undos: [{ id: P.id, params: { unitId: e2, subUnitId: n2, comment: t2, sync: true } }] }; }); this._refRangeService = e, this._sheetsThreadCommentModel = n, this._threadCommentModel = t, this._selectionManagerService = r, this._commandService = s, this._initData(), this._initRefRange(); } _getIdWithUnitId(e, n, t) { return `${e}-${n}-${t}`; } _register(e, n, t) { const r = t.id, s = { startColumn: t.column, endColumn: t.column, startRow: t.row, endRow: t.row }; this._disposableMap.set( this._getIdWithUnitId(e, n, r), this._refRangeService.registerRefRange(s, (o) => { const a = hh(s, o, { selectionManagerService: this._selectionManagerService }), c = Array.isArray(a) ? a[0] : a; return c && c.startColumn === s.startColumn && c.startRow === s.startRow ? { undos: [], redos: [] } : this._handleRangeChange(e, n, t, c, false); }, e, n) ); } _watch(e, n, t) { const r = t.id, s = { startColumn: t.column, endColumn: t.column, startRow: t.row, endRow: t.row }; this._watcherMap.set( this._getIdWithUnitId(e, n, r), this._refRangeService.watchRange(e, n, s, (o, a) => { const { redos: c } = this._handleRangeChange(e, n, t, a, true); Q0(c, this._commandService, { onlyLocal: true }); }, true) ); } _unwatch(e, n, t) { var s; const r = this._getIdWithUnitId(e, n, t); (s = this._watcherMap.get(r)) == null || s.dispose(), this._watcherMap.delete(r); } _unregister(e, n, t) { var s; const r = this._getIdWithUnitId(e, n, t); (s = this._disposableMap.get(r)) == null || s.dispose(), this._disposableMap.delete(r); } _initData() { const e = this._threadCommentModel.getAll(); for (const n of e) for (const t of n.threads) { const { unitId: r, subUnitId: s, root: o } = t, a = ns(o.ref), c = { ...o, ...a }; this._register(r, s, c), this._watch(r, s, c); } } _initRefRange() { this.disposeWithMe( this._sheetsThreadCommentModel.commentUpdate$.subscribe((e) => { const { unitId: n, subUnitId: t } = e; switch (e.type) { case "add": { if (e.payload.parentId) return; const r = { ...e.payload, row: e.row, column: e.column }; this._register(e.unitId, e.subUnitId, r), this._watch(e.unitId, e.subUnitId, r); break; } case "delete": { this._unregister(n, t, e.payload.commentId), this._unwatch(n, t, e.payload.commentId); break; } case "updateRef": { const r = this._sheetsThreadCommentModel.getComment(n, t, e.payload.commentId); if (!r) return; this._unregister(n, t, e.payload.commentId); const s = { ...r, row: e.row, column: e.column }; e.silent || (this._unwatch(n, t, e.payload.commentId), this._watch(n, t, s)), this._register(e.unitId, e.subUnitId, s); break; } } }) ), this.disposeWithMe(Ze(() => { this._disposableMap.forEach((e) => { e.dispose(); }), this._disposableMap.clear(); })); } }; f = Q([ _(0, ot(_t)), _(1, ot(p)), _(2, ot(i)), _(3, ot(F)), _(4, Pt) ], f); var X = "SHEET_THREAD_COMMENT_BASE_PLUGIN"; var I = Object.defineProperty; var Y = Object.getOwnPropertyDescriptor; var Z = (i2, e, n) => e in i2 ? I(i2, e, { enumerable: true, configurable: true, writable: true, value: n }) : i2[e] = n; var k = (i2, e, n, t) => { for (var r = t > 1 ? void 0 : t ? Y(e, n) : e, s = i2.length - 1, o; s >= 0; s--) (o = i2[s]) && (r = (t ? o(e, n, r) : o(r)) || r); return t && r && I(e, n, r), r; }; var v = (i2, e) => (n, t) => e(n, t, i2); var U = (i2, e, n) => Z(i2, typeof e != "symbol" ? e + "" : e, n); var g = class extends Ra { constructor(i2, e, n) { super(), this._injector = e, this._commandService = n; } onStarting() { [ [p], [f] ].forEach((i2) => { this._injector.add(i2); }), this._injector.get(f); } }; U(g, "pluginName", X); U(g, "type", Fe.UNIVER_SHEET); g = k([ OR(D), v(1, ot(Ot)), v(2, ot(Pt)) ], g); export { p, f, g }; //# sourceMappingURL=chunk-PEI6ACTC.js.map