import { D, ae, i, ne, oe, pe, re as re2, se } from "./chunk-PG4GXCOC.js"; import { He, Ra as Ra2, cf } from "./chunk-MIOQ566M.js"; import { I1, rt } from "./chunk-POAJ2YNP.js"; import { Gf, Po, UO, qO, r_, sC } from "./chunk-GBYP4PB2.js"; import { BehaviorSubject, Dt, Fe, OR, Ot, Pt, Ra, SE, Vr, W0, _n, ar, debounceTime, filter, kE, mn, nt, nu, ot, qt, re, rr, st, su, z0 } from "./chunk-23V3HWTR.js"; import { require_react } from "./chunk-GNR2UJZM.js"; import { __toESM } from "./chunk-2LSFTFF7.js"; // node_modules/.pnpm/@univerjs+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/thread-comment-ui/lib/es/index.js var import_react = __toESM(require_react()); var qe = Object.defineProperty; var Ze = (t, e, n) => e in t ? qe(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n; var V = (t, e, n) => Ze(t, typeof e != "symbol" ? e + "" : e, n); var St = Object.defineProperty; var yt = Object.getOwnPropertyDescriptor; var Tt = (t, e, n, r) => { for (var o = r > 1 ? void 0 : r ? yt(e, n) : e, s = t.length - 1, l; s >= 0; s--) (l = t[s]) && (o = (r ? l(e, n, o) : l(o)) || o); return r && o && St(e, n, o), o; }; var Se = (t, e) => (n, r) => e(n, r, t); var J = class extends nt { constructor(e, n) { super(); V(this, "_panelVisible", false); V(this, "_panelVisible$", new BehaviorSubject(false)); V(this, "_activeCommentId"); V(this, "_activeCommentId$", new BehaviorSubject(void 0)); V(this, "panelVisible$", this._panelVisible$.asObservable()); V(this, "activeCommentId$", this._activeCommentId$.asObservable()); this._sidebarService = e, this._univerInstanceService = n, this._init(), this.disposeWithMe(() => { this._activeCommentId$.complete(), this._panelVisible$.complete(); }); } _init() { this.disposeWithMe( this._sidebarService.sidebarOptions$.subscribe((e) => { e.visible || this.setPanelVisible(false); }) ), this.disposeWithMe( this._univerInstanceService.getCurrentTypeOfUnit$(Fe.UNIVER_SHEET).pipe(filter((e) => !e)).subscribe(() => { this._sidebarService.close(); }) ); } get panelVisible() { return this._panelVisible; } get activeCommentId() { return this._activeCommentId; } setPanelVisible(e) { this._panelVisible = e, this._panelVisible$.next(e); } setActiveComment(e) { this._activeCommentId = e, this._activeCommentId$.next(e); } }; J = Tt([ Se(0, ot(rt)), Se(1, _n) ], J); var jt = "thread-comment-panel"; var Nt = "UNIVER_THREAD_COMMENT_UI_PLUGIN"; var Et = { id: "thread-comment-ui.operation.toggle-panel", type: ar.OPERATION, handler(t) { const e = t.get(rt), n = t.get(J); return n.panelVisible ? (e.close(), n.setPanelVisible(false)) : (e.open({ header: { title: "threadCommentUI.panel.title" }, children: { label: jt }, width: 330 }), n.setPanelVisible(true)), true; } }; var F = { id: "thread-comment-ui.operation.set-active-comment", type: ar.OPERATION, handler(t, e) { return t.get(J).setActiveComment(e), true; } }; var Ut = "thread-comment-ui.config"; var ye = {}; var De = Object.defineProperty; var Pt2 = Object.getOwnPropertyDescriptor; var Ot2 = (t, e, n) => e in t ? De(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n; var Rt = (t, e, n, r) => { for (var o = r > 1 ? void 0 : r ? Pt2(e, n) : e, s = t.length - 1, l; s >= 0; s--) (l = t[s]) && (o = (r ? l(e, n, o) : l(o)) || o); return r && o && De(e, n, o), o; }; var fe = (t, e) => (n, r) => e(n, r, t); var He2 = (t, e, n) => Ot2(t, typeof e != "symbol" ? e + "" : e, n); var ue = class extends Ra { constructor(t = ye, e, n, r) { super(), this._config = t, this._injector = e, this._commandService = n, this._configService = r; const { menu: o, ...s } = nu( {}, ye, this._config ); o && this._configService.setConfig("menu", o, { merge: true }), this._configService.setConfig(Ut, s); } onStarting() { var t; kE([ [J] ], (t = this._config) == null ? void 0 : t.overrides).forEach((e) => { this._injector.add(e); }), [Et, F].forEach((e) => { this._commandService.registerCommand(e); }); } }; He2(ue, "pluginName", Nt); He2(ue, "type", Fe.UNIVER_UNKNOWN); ue = Rt([ OR(D), fe(1, ot(Ot)), fe(2, Pt), fe(3, SE) ], ue); var ve = { exports: {} }; var ee = {}; var Te; function $t() { if (Te) return ee; Te = 1; var t = import_react.default, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), r = Object.prototype.hasOwnProperty, o = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: true, ref: true, __self: true, __source: true }; function l(h, c, x) { var C, T = {}, b = null, _ = null; x !== void 0 && (b = "" + x), c.key !== void 0 && (b = "" + c.key), c.ref !== void 0 && (_ = c.ref); for (C in c) r.call(c, C) && !s.hasOwnProperty(C) && (T[C] = c[C]); if (h && h.defaultProps) for (C in c = h.defaultProps, c) T[C] === void 0 && (T[C] = c[C]); return { $$typeof: e, type: h, key: b, ref: _, props: T, _owner: o.current }; } return ee.Fragment = n, ee.jsx = l, ee.jsxs = l, ee; } var je; function Dt2() { return je || (je = 1, ve.exports = $t()), ve.exports; } var i2 = Dt2(); var $ = function() { return $ = Object.assign || function(t) { for (var e, n = 1, r = arguments.length; n < r; n++) { e = arguments[n]; for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]); } return t; }, $.apply(this, arguments); }; var Ht = function(t, e) { var n = {}; for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && e.indexOf(r) < 0 && (n[r] = t[r]); if (t != null && typeof Object.getOwnPropertySymbols == "function") for (var o = 0, r = Object.getOwnPropertySymbols(t); o < r.length; o++) e.indexOf(r[o]) < 0 && Object.prototype.propertyIsEnumerable.call(t, r[o]) && (n[r[o]] = t[r[o]]); return n; }; var z = (0, import_react.forwardRef)(function(t, e) { var n = t.icon, r = t.id, o = t.className, s = t.extend, l = Ht(t, ["icon", "id", "className", "extend"]), h = "univerjs-icon univerjs-icon-".concat(r, " ").concat(o || "").trim(), c = (0, import_react.useRef)("_".concat(kt())); return Me(n, "".concat(r), { defIds: n.defIds, idSuffix: c.current }, $({ ref: e, className: h }, l), s); }); function Me(t, e, n, r, o) { return (0, import_react.createElement)(t.tag, $($({ key: e }, Mt(t, n, o)), r), (wt(t, n).children || []).map(function(s, l) { return Me(s, "".concat(e, "-").concat(t.tag, "-").concat(l), n, void 0, o); })); } function Mt(t, e, n) { var r = $({}, t.attrs); n != null && n.colorChannel1 && r.fill === "colorChannel1" && (r.fill = n.colorChannel1); var o = e.defIds; return !o || o.length === 0 || (t.tag === "use" && r["xlink:href"] && (r["xlink:href"] = r["xlink:href"] + e.idSuffix), Object.entries(r).forEach(function(s) { var l = s[0], h = s[1]; typeof h == "string" && (r[l] = h.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")"))); })), r; } function wt(t, e) { var n, r = e.defIds; return !r || r.length === 0 ? t : t.tag === "defs" && (!((n = t.children) === null || n === void 0) && n.length) ? $($({}, t), { children: t.children.map(function(o) { return typeof o.attrs.id == "string" && r && r.indexOf(o.attrs.id) > -1 ? $($({}, o), { attrs: $($({}, o.attrs), { id: o.attrs.id + e.idSuffix }) }) : o; }) }) : t; } function kt() { return Math.random().toString(36).substring(2, 8); } z.displayName = "UniverIcon"; var Lt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.3313 1.4667C5.3313 1.13533 5.59993.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z", fillRule: "evenodd", clipRule: "evenodd" } }] }; var we = (0, import_react.forwardRef)(function(t, e) { return (0, import_react.createElement)(z, Object.assign({}, t, { id: "delete-single", ref: e, icon: Lt })); }); we.displayName = "DeleteSingle"; var At = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z" } }] }; var ke = (0, import_react.forwardRef)(function(t, e) { return (0, import_react.createElement)(z, Object.assign({}, t, { id: "increase-single", ref: e, icon: At })); }); ke.displayName = "IncreaseSingle"; var Vt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M3 9C3.55228 9 4 8.55228 4 8 4 7.44772 3.55228 7 3 7 2.44772 7 2 7.44772 2 8 2 8.55228 2.44772 9 3 9zM8 9C8.55228 9 9 8.55228 9 8 9 7.44772 8.55228 7 8 7 7.44772 7 7 7.44772 7 8 7 8.55228 7.44772 9 8 9zM13 9C13.5523 9 14 8.55228 14 8 14 7.44772 13.5523 7 13 7 12.4477 7 12 7.44772 12 8 12 8.55228 12.4477 9 13 9z" } }] }; var Le = (0, import_react.forwardRef)(function(t, e) { return (0, import_react.createElement)(z, Object.assign({}, t, { id: "more-horizontal-single", ref: e, icon: Vt })); }); Le.displayName = "MoreHorizontalSingle"; var Bt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { stroke: "currentColor", d: "M7.48389 10.3267V12.1905C7.48389 12.7428 7.9316 13.1905 8.48389 13.1905H11.2216L12.2955 14.2644L13.3695 13.1905H14.1593C14.7116 13.1905 15.1593 12.7428 15.1593 12.1905V8.46289C15.1593 7.91061 14.7116 7.46289 14.1593 7.46289H12.2955", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.2 } }, { tag: "path", attrs: { stroke: "currentColor", d: "M0.840332 3.73535C0.840332 2.63078 1.73576 1.73535 2.84033 1.73535H10.2955C11.4001 1.73535 12.2955 2.63078 12.2955 3.73535V8.32676C12.2955 9.43132 11.4001 10.3268 10.2955 10.3268H5.6014L4.1695 11.7587L3.05978 10.3268H2.84033C1.73576 10.3268 0.840332 9.43133 0.840332 8.32676V3.73535Z", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.2 } }, { tag: "path", attrs: { stroke: "currentColor", d: "M6.41016 6.1311H6.76813M8.91626 6.1311H9.27424M3.90454 6.1311H4.26252", strokeLinecap: "round", strokeWidth: 1.2 } }] }; var Ae = (0, import_react.forwardRef)(function(t, e) { return (0, import_react.createElement)(z, Object.assign({}, t, { id: "reply-to-comment-single", ref: e, icon: Bt })); }); Ae.displayName = "ReplyToCommentSingle"; var Ft = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M8.6106 15.4036C12.4766 15.4036 15.6106 12.2696 15.6106 8.40356C15.6106 4.53757 12.4766 1.40356 8.6106 1.40356C4.7446 1.40356 1.6106 4.53757 1.6106 8.40356C1.6106 12.2696 4.7446 15.4036 8.6106 15.4036ZM12.3351 6.82773C12.5694 6.59342 12.5694 6.21352 12.3351 5.9792C12.1007 5.74489 11.7208 5.74489 11.4865 5.9792L7.91079 9.55494L6.33506 7.9792C6.10074 7.74489 5.72084 7.74489 5.48653 7.9792C5.25221 8.21352 5.25221 8.59342 5.48653 8.82773L7.48653 10.8277C7.72084 11.062 8.10074 11.062 8.33506 10.8277L12.3351 6.82773Z", fillRule: "evenodd", clipRule: "evenodd" } }] }; var Ve = (0, import_react.forwardRef)(function(t, e) { return (0, import_react.createElement)(z, Object.assign({}, t, { id: "resolved-single", ref: e, icon: Ft })); }); Ve.displayName = "ResolvedSingle"; var Wt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" }, children: [{ tag: "circle", attrs: { cx: 8.73, cy: 8.4, r: 6.4, stroke: "currentColor", strokeWidth: 1.2 } }, { tag: "path", attrs: { stroke: "currentColor", d: "M6.02637 8.40356L8.02637 10.4036L12.0264 6.40356", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.2 } }] }; var Be = (0, import_react.forwardRef)(function(t, e) { return (0, import_react.createElement)(z, Object.assign({}, t, { id: "solve-single", ref: e, icon: Wt })); }); Be.displayName = "SolveSingle"; function Fe2(t) { var e, n, r = ""; if (typeof t == "string" || typeof t == "number") r += t; else if (typeof t == "object") if (Array.isArray(t)) { var o = t.length; for (e = 0; e < o; e++) t[e] && (n = Fe2(t[e])) && (r && (r += " "), r += n); } else for (n in t) t[n] && (r && (r += " "), r += n); return r; } function zt() { for (var t, e, n = 0, r = "", o = arguments.length; n < o; n++) (t = arguments[n]) && (e = Fe2(t)) && (r && (r += " "), r += e); return r; } var qt2 = "univer-thread-comment-editor-buttons"; var Zt = "univer-thread-comment-editor-suggestion"; var Jt = "univer-thread-comment-editor-suggestionActive"; var Kt = "univer-thread-comment-editor-suggestion-icon"; var Ne = { threadCommentEditorButtons: qt2, threadCommentEditorSuggestion: Zt, threadCommentEditorSuggestionActive: Jt, threadCommentEditorSuggestionIcon: Kt }; function Ee(t) { return { id: "d", body: t, documentStyle: {} }; } var We = (0, import_react.forwardRef)((t, e) => { var M; const { comment: n, onSave: r, id: o, onCancel: s, autoFocus: l, unitId: h, type: c } = t, x = W0(Pt), C = W0(Vr), [T, b] = (0, import_react.useState)(false), _ = W0(He), u = (0, import_react.useRef)(null), g = c === Fe.UNIVER_SHEET ? su : h, [O, j] = (0, import_react.useState)(() => { var m, f, I; return st.transform.getPlainText((I = (f = (m = u.current) == null ? void 0 : m.getDocumentData().body) == null ? void 0 : f.dataStream) != null ? I : ""); }); (0, import_react.useEffect)(() => { var f, I, d, v; j(st.transform.getPlainText((d = (I = (f = u.current) == null ? void 0 : f.getDocumentData().body) == null ? void 0 : I.dataStream) != null ? d : "")); const m = (v = u.current) == null ? void 0 : v.selectionChange$.subscribe(() => { var q, N, y; j(st.transform.getPlainText((y = (N = (q = u.current) == null ? void 0 : q.getDocumentData().body) == null ? void 0 : N.dataStream) != null ? y : "")); }); return () => m == null ? void 0 : m.unsubscribe(); }, [(M = u.current) == null ? void 0 : M.selectionChange$]); const D2 = (0, import_react.useMemo)(() => ({ keyCodes: [{ keyCode: I1.ENTER }], handler: (m) => { m === I1.ENTER && x.executeCommand( Ra2.id ); } }), [x]); (0, import_react.useImperativeHandle)(e, () => ({ reply(m) { var f, I; (f = u.current) == null || f.focus(), (I = u.current) == null || I.setDocumentData(Ee(m)); } })); const S = () => { if (u.current) { const m = re.deepClone(u.current.getDocumentData().body); b(false), r == null || r({ ...n, text: m }), u.current.replaceText(""), setTimeout(() => { var f, I; (f = u.current) == null || f.setSelectionRanges([]), (I = u.current) == null || I.blur(); }, 10); } }; return i2.jsxs("div", { className: Ne.threadCommentEditor, onClick: (m) => m.preventDefault(), children: [ i2.jsx( cf, { ref: u, autoFocus: l, style: { width: "100%" }, keyboardEventConfig: D2, placeholder: C.t("threadCommentUI.editor.placeholder"), initialValue: (n == null ? void 0 : n.text) && Ee(n.text), onFocusChange: (m) => m && b(m), isSingle: false, maxHeight: 64, onClickOutside: () => { setTimeout(() => { _.focus(g); }, 30); } } ), T ? i2.jsxs("div", { className: Ne.threadCommentEditorButtons, children: [ i2.jsx( Po, { style: { marginRight: 12 }, onClick: () => { var m; s == null || s(), b(false), (m = u.current) == null || m.replaceText("", true), x.executeCommand(F.id); }, children: C.t("threadCommentUI.editor.cancel") } ), i2.jsx( Po, { type: "primary", disabled: !O, onClick: S, children: C.t(o ? "threadCommentUI.editor.save" : "threadCommentUI.editor.reply") } ) ] }) : null ] }); }); var Gt = (t) => { const { dataStream: e, customRanges: n } = t, r = e.endsWith(`\r `) ? e.length - 2 : e.length, o = []; let s = 0; return n == null || n.forEach((l) => { s < l.startIndex && o.push({ type: "text", content: e.slice(s, l.startIndex) }), o.push({ type: "mention", content: { label: e.slice(l.startIndex, l.endIndex + 1), id: l.rangeId } }), s = l.endIndex + 1; }), o.push({ type: "text", content: e.slice(s, r) }), o; }; var Yt = (t) => { const { paragraphs: e = [] } = t; let n = 0; return e.map((r) => { const o = Dt(t, n, r.startIndex); return n = r.startIndex + 1, Gt(o); }); }; var Qt = (t) => { let e = ""; const n = []; return t.forEach((r) => { switch (r.type) { case "text": e += r.content; break; case "mention": { const o = e.length; e += r.content.label; const s = e.length - 1; n.push({ rangeId: r.content.id, rangeType: mn.MENTION, startIndex: o, endIndex: s, properties: {} }); break; } } }), e += ` \r`, { textRuns: [], paragraphs: [ { startIndex: e.length - 2, paragraphStyle: {} } ], sectionBreaks: [ { startIndex: e.length - 1 } ], dataStream: e, customRanges: n }; }; var Xt = "univer-thread-comment"; var en = "univer-thread-comment-active"; var tn = "univer-thread-comment-content"; var nn = "univer-thread-comment-highlight"; var rn = "univer-thread-comment-icon-container"; var on = "univer-thread-comment-icon"; var an = "univer-thread-comment-title"; var sn = "univer-thread-comment-title-position"; var dn = "univer-thread-comment-title-highlight"; var ln = "univer-thread-comment-title-position-text"; var mn2 = "univer-thread-comment-username"; var cn = "univer-thread-comment-item"; var un = "univer-thread-comment-item-head"; var hn = "univer-thread-comment-item-title"; var Cn = "univer-thread-comment-item-title-position"; var fn = "univer-thread-comment-item-title-highlight"; var vn = "univer-thread-comment-item-time"; var pn = "univer-thread-comment-item-content"; var gn = "univer-thread-comment-item-at"; var p = { threadComment: Xt, threadCommentActive: en, threadCommentContent: tn, threadCommentHighlight: nn, threadCommentIconContainer: rn, threadCommentIcon: on, threadCommentTitle: an, threadCommentTitlePosition: sn, threadCommentTitleHighlight: dn, threadCommentTitlePositionText: ln, threadCommentUsername: mn2, threadCommentItem: cn, threadCommentItemHead: un, threadCommentItemTitle: hn, threadCommentItemTitlePosition: Cn, threadCommentItemTitleHighlight: fn, threadCommentItemTime: vn, threadCommentItemContent: pn, threadCommentItemAt: gn }; var ze = "__mock__"; var In = (t) => { const { item: e, unitId: n, subUnitId: r, editing: o, onEditingChange: s, onReply: l, resolved: h, isRoot: c, onClose: x, onDeleteComment: C, type: T } = t, b = W0(Pt), _ = W0(Vr), u = W0(rr), g = u.getUser(e.personId), O = z0(u.currentUser$), j = (O == null ? void 0 : O.userID) === e.personId, D2 = e.id === ze, [S, M] = (0, import_react.useState)(false), m = () => { (C == null ? void 0 : C(e)) !== false && (b.executeCommand( c ? se.id : ae.id, { unitId: n, subUnitId: r, commentId: e.id } ), c && (x == null || x())); }; return i2.jsxs("div", { className: p.threadCommentItem, onMouseLeave: () => M(false), onMouseEnter: () => M(true), children: [ i2.jsx("img", { className: p.threadCommentItemHead, src: g == null ? void 0 : g.avatar }), i2.jsxs("div", { className: p.threadCommentItemTitle, children: [ i2.jsx("div", { className: p.threadCommentUsername, children: (g == null ? void 0 : g.name) || " " }), i2.jsxs("div", { children: [ D2 || h ? null : S ? i2.jsx("div", { className: p.threadCommentIcon, onClick: () => l(g), children: i2.jsx(Ae, {}) }) : null, j && !D2 && !h ? i2.jsx( sC, { overlay: i2.jsxs(UO, { children: [ i2.jsx(qO, { onClick: () => s == null ? void 0 : s(true), children: _.t("threadCommentUI.item.edit") }, "edit"), i2.jsx(qO, { onClick: m, children: _.t("threadCommentUI.item.delete") }, "delete") ] }), children: i2.jsx("div", { className: p.threadCommentIcon, children: i2.jsx(Le, {}) }) } ) : null ] }) ] }), i2.jsx("div", { className: p.threadCommentItemTime, children: e.dT }), o ? i2.jsx( We, { type: T, id: e.id, comment: e, onCancel: () => s == null ? void 0 : s(false), autoFocus: true, unitId: n, subUnitId: r, onSave: ({ text: f, attachments: I }) => { s == null || s(false), b.executeCommand( oe.id, { unitId: n, subUnitId: r, payload: { commentId: e.id, text: f, attachments: I } } ); } } ) : i2.jsx("div", { className: p.threadCommentItemContent, children: Yt(e.text).map((f, I) => i2.jsx("div", { children: f.map((d, v) => { switch (d.type) { case "mention": return i2.jsxs("a", { className: p.threadCommentItemAt, children: [ d.content.label, " " ] }, v); default: return d.content; } }) }, I)) }) ] }); }; var xn = (t) => { var Q, X, se2; const { id: e, unitId: n, subUnitId: r, refStr: o, showEdit: s = true, onClick: l, showHighlight: h, onClose: c, getSubUnitName: x, prefix: C, autoFocus: T, onMouseEnter: b, onMouseLeave: _, onAddComment: u, onDeleteComment: g, onResolve: O, type: j } = t, D2 = W0(i), [S, M] = (0, import_react.useState)(false), [m, f] = (0, import_react.useState)(""), I = (0, import_react.useMemo)(() => D2.commentUpdate$.pipe(debounceTime(16)), [D2]); z0(I); const d = e ? D2.getCommentWithChildren(n, r, e) : null, v = W0(Pt), q = W0(rr), N = d == null ? void 0 : d.root.resolved, y = z0(q.currentUser$), Z = (0, import_react.useRef)(null), ie = [ ...d ? [d.root] : ( // mock empty comment [{ id: ze, text: { dataStream: ` \r` }, personId: (Q = y == null ? void 0 : y.userID) != null ? Q : "", ref: o != null ? o : "", dT: "", unitId: n, subUnitId: r, threadId: "" }] ), ...(X = d == null ? void 0 : d.children) != null ? X : [] ], R = (0, import_react.useRef)(null), K = (E) => { E.stopPropagation(), N ? v.executeCommand(F.id, { unitId: n, subUnitId: r, commentId: e }) : v.executeCommand(F.id), v.executeCommand(re2.id, { unitId: n, subUnitId: r, commentId: e, resolved: !N }), O == null || O(!N); }, w = (E) => { E.stopPropagation(), v.executeCommand(F.id), !(d != null && d.root && (g == null ? void 0 : g(d.root)) === false) && (v.executeCommand( se.id, { unitId: n, subUnitId: r, commentId: e } ), c == null || c()); }; (0, import_react.useEffect)(() => _ == null ? void 0 : _(), []); const G = x((se2 = d == null ? void 0 : d.root.subUnitId) != null ? se2 : r), Y = s && !m && !N, ae2 = `${o || (d == null ? void 0 : d.root.ref) || ""}${G ? " · " : ""}${G}`; return i2.jsxs( "div", { className: zt(p.threadComment, { [p.threadCommentActive]: !N && (h || S || C === "cell") }), onClick: l, id: `${C}-${n}-${r}-${e}`, onMouseEnter: () => { b == null || b(), M(true); }, onMouseLeave: () => { _ == null || _(), M(false); }, children: [ !N && h ? i2.jsx("div", { className: p.threadCommentHighlight }) : null, i2.jsxs("div", { className: p.threadCommentTitle, children: [ i2.jsxs("div", { className: p.threadCommentTitlePosition, children: [ i2.jsx("div", { className: p.threadCommentTitleHighlight }), i2.jsx(Gf, { showIfEllipsis: true, title: ae2, children: i2.jsx("div", { className: p.threadCommentTitlePositionText, children: ae2 }) }) ] }), d ? i2.jsxs("div", { className: p.threadCommentIconContainer, children: [ i2.jsx( "div", { onClick: K, className: p.threadCommentIcon, style: { color: N ? "rgb(var(--green-500))" : "" }, children: N ? i2.jsx(Ve, {}) : i2.jsx(Be, {}) } ), (y == null ? void 0 : y.userID) === d.root.personId ? i2.jsx("div", { className: p.threadCommentIcon, onClick: w, children: i2.jsx(we, {}) }) : null ] }) : null ] }), i2.jsx("div", { className: p.threadCommentContent, ref: R, children: ie.map( (E) => i2.jsx( In, { onClose: c, unitId: n, subUnitId: r, item: E, isRoot: E.id === (d == null ? void 0 : d.root.id), editing: m === E.id, resolved: d == null ? void 0 : d.root.resolved, type: j, onEditingChange: (a) => { f(a ? E.id : ""); }, onReply: (a) => { a && requestAnimationFrame(() => { var H; (H = Z.current) == null || H.reply(Qt([{ type: "mention", content: { id: a.userID, label: a.name } }])); }); }, onAddComment: u, onDeleteComment: g }, E.id ) ) }), Y ? i2.jsx("div", { children: i2.jsx( We, { ref: Z, type: j, unitId: n, subUnitId: r, onSave: async ({ text: E, attachments: a }) => { const H = { text: E, attachments: a, dT: pe(), id: qt(), ref: o, personId: y == null ? void 0 : y.userID, parentId: d == null ? void 0 : d.root.id, unitId: n, subUnitId: r, threadId: d == null ? void 0 : d.root.threadId }; (u == null ? void 0 : u(H)) !== false && (await v.executeCommand( ne.id, { unitId: n, subUnitId: r, comment: H } ), R.current && (R.current.scrollTop = R.current.scrollHeight)); }, autoFocus: T || !d, onCancel: () => { d || c == null || c(); } }, `${T}` ) }) : null ] } ); }; var bn = "univer-thread-comment-panel"; var _n2 = "univer-thread-comment"; var Sn = "univer-thread-comment-panel-forms"; var yn = "univer-select"; var Tn = "univer-thread-comment-panel-empty"; var jn = "univer-thread-comment-panel-add"; var Nn = "univer-thread-comment-panel-solved"; var te = { threadCommentPanel: bn, threadComment: _n2, threadCommentPanelForms: Sn, select: yn, threadCommentPanelEmpty: Tn, threadCommentPanelAdd: jn, threadCommentPanelSolved: Nn }; var Mn = (t) => { const { unitId: e, subUnitId$: n, type: r, onAdd: o, getSubUnitName: s, onResolve: l, sortComments: h, onItemLeave: c, onItemEnter: x, disableAdd: C, tempComment: T, onAddComment: b, onDeleteComment: _, showComments: u } = t, [g, O] = (0, import_react.useState)("all"), [j, D2] = (0, import_react.useState)("all"), S = W0(Vr), M = W0(rr), m = W0(i), [f, I] = (0, import_react.useState)(() => m.getUnit(e)), d = W0(J), v = z0(d.activeCommentId$), q = z0(m.commentUpdate$), N = W0(Pt), y = z0(n), Z = (0, import_react.useRef)(true), ie = "panel", R = z0(M.currentUser$), K = (0, import_react.useMemo)(() => { var le; const a = g === "all" ? f : (le = f.filter((P) => P.subUnitId === y)) != null ? le : [], H = h != null ? h : (P) => P, de = a.map((P) => { var A; return { ...P.root, children: (A = P.children) != null ? A : [], users: P.relativeUsers }; }); if (u) { const P = /* @__PURE__ */ new Map(); return de.forEach((A) => { P.set(A.id, A); }), [...u, ""].map((A) => P.get(A)).filter(Boolean); } else return H(de); }, [u, g, f, h, y]), w = (0, import_react.useMemo)(() => [ ...K.filter((a) => !a.resolved), ...K.filter((a) => a.resolved) ], [K]), G = (0, import_react.useMemo)(() => j === "resolved" ? w.filter((a) => a.resolved) : j === "unsolved" ? w.filter((a) => !a.resolved) : j === "concern_me" && R != null && R.userID ? w.filter((a) => a == null ? void 0 : a.users.has(R.userID)) : w, [w, R == null ? void 0 : R.userID, j]), Y = T ? [T, ...G] : G, ae2 = Y.filter((a) => !a.resolved), Q = Y.filter((a) => a.resolved), X = j !== "all" || g !== "all", se2 = () => { D2("all"), O("all"); }; (0, import_react.useEffect)(() => { e && I( m.getUnit(e) ); }, [e, m, q]), (0, import_react.useEffect)(() => { var P; if (!v) return; if (!Z.current) { Z.current = true; return; } const { unitId: a, subUnitId: H, commentId: de } = v, le = `${ie}-${a}-${H}-${de}`; (P = document.getElementById(le)) == null || P.scrollIntoView({ block: "center" }); }, [v]); const E = (a) => i2.jsx( xn, { prefix: ie, getSubUnitName: s, id: a.id, unitId: a.unitId, subUnitId: a.subUnitId, refStr: a.ref, type: r, showEdit: (v == null ? void 0 : v.commentId) === a.id, showHighlight: (v == null ? void 0 : v.commentId) === a.id, onClick: () => { Z.current = false, a.resolved ? N.executeCommand(F.id) : N.executeCommand( F.id, { unitId: a.unitId, subUnitId: a.subUnitId, commentId: a.id, temp: false } ); }, onMouseEnter: () => x == null ? void 0 : x(a), onMouseLeave: () => c == null ? void 0 : c(a), onAddComment: b, onDeleteComment: _, onResolve: (H) => l == null ? void 0 : l(a.id, H) }, a.id ); return i2.jsxs("div", { className: te.threadCommentPanel, children: [ i2.jsxs("div", { className: te.threadCommentPanelForms, children: [ r === Fe.UNIVER_SHEET ? i2.jsx( r_, { borderless: true, value: g, onChange: (a) => O(a), options: [ { value: "current", label: S.t("threadCommentUI.filter.sheet.current") }, { value: "all", label: S.t("threadCommentUI.filter.sheet.all") } ] } ) : null, i2.jsx( r_, { borderless: true, value: j, onChange: (a) => D2(a), options: [ { value: "all", label: S.t("threadCommentUI.filter.status.all") }, { value: "resolved", label: S.t("threadCommentUI.filter.status.resolved") }, { value: "unsolved", label: S.t("threadCommentUI.filter.status.unsolved") }, { value: "concern_me", label: S.t("threadCommentUI.filter.status.concernMe") } ] } ) ] }), ae2.map(E), Q.length ? i2.jsx("div", { className: te.threadCommentPanelSolved, children: "已解决" }) : null, Q.map(E), Y.length ? null : i2.jsxs("div", { className: te.threadCommentPanelEmpty, children: [ X ? S.t("threadCommentUI.panel.filterEmpty") : S.t("threadCommentUI.panel.empty"), X ? i2.jsx( Po, { onClick: se2, type: "link", children: S.t("threadCommentUI.panel.reset") } ) : i2.jsxs( Po, { id: "thread-comment-add", className: te.threadCommentPanelAdd, type: "primary", onClick: o, disabled: C, children: [ i2.jsx(ke, {}), S.t("threadCommentUI.panel.addComment") ] } ) ] }) ] }); }; export { J, jt, Et, F, ue, xn, Mn }; /*! Bundled license information: @univerjs/thread-comment-ui/lib/es/index.js: (** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. *) */ //# sourceMappingURL=chunk-VMR7OHHI.js.map