123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- import {
- Bi,
- Ct,
- Fe,
- Ht,
- Ot,
- Pt,
- Ra,
- SE,
- Subject,
- Ve,
- ar,
- kE,
- nt,
- nu,
- ot,
- rn
- } from "./chunk-23V3HWTR.js";
- // node_modules/.pnpm/@univerjs+thread-comment@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/thread-comment/lib/es/index.js
- var A = Object.defineProperty;
- var j = (s, t, e) => t in s ? A(s, t, { enumerable: true, configurable: true, writable: true, value: e }) : s[t] = e;
- var u = (s, t, e) => j(s, typeof t != "symbol" ? t + "" : t, e);
- var F = class extends nt {
- constructor() {
- super();
- u(this, "_dataSource", null);
- u(this, "syncUpdateMutationToColla", true);
- }
- set dataSource(e) {
- this._dataSource = e;
- }
- get dataSource() {
- return this._dataSource;
- }
- async getThreadComment(e, n, o) {
- return this._dataSource ? (await this._dataSource.listComments(e, n, [o]))[0] : null;
- }
- async addComment(e) {
- var n;
- return this._dataSource ? this._dataSource.addComment(e) : { ...e, threadId: (n = e.threadId) != null ? n : e.id };
- }
- async updateComment(e) {
- return this._dataSource ? this._dataSource.updateComment(e) : true;
- }
- async resolveComment(e) {
- return this._dataSource ? this._dataSource.resolveComment(e) : true;
- }
- async deleteComment(e, n, o, r) {
- return this._dataSource ? this._dataSource.deleteComment(e, n, o, r) : true;
- }
- async listThreadComments(e, n, o) {
- return this.dataSource ? this.dataSource.listComments(e, n, o) : false;
- }
- saveToSnapshot(e, n) {
- if (this._dataSource) {
- const o = {};
- return Object.keys(e).forEach((r) => {
- const a = e[r];
- o[r] = a.map(this.dataSource.saveCommentToSnapshot);
- }), o;
- }
- return e;
- }
- };
- var p = Ct("univer.thread-comment.data-source-service");
- var q = Object.defineProperty;
- var z = Object.getOwnPropertyDescriptor;
- var Q = (s, t, e, n) => {
- for (var o = n > 1 ? void 0 : n ? z(t, e) : t, r = s.length - 1, a; r >= 0; r--)
- (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
- return n && o && q(t, e, o), o;
- };
- var I = (s, t) => (e, n) => t(e, n, s);
- var i = class extends nt {
- constructor(t, e) {
- super();
- u(this, "_commentsMap", /* @__PURE__ */ new Map());
- u(this, "_threadMap", /* @__PURE__ */ new Map());
- u(this, "_commentUpdate$", new Subject());
- u(this, "commentUpdate$", this._commentUpdate$.asObservable());
- u(this, "_tasks", []);
- this._dataSourceService = t, this._lifecycleService = e, this.disposeWithMe(() => {
- this._commentUpdate$.complete();
- }), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((n) => {
- const o = /* @__PURE__ */ new Map();
- n === Ve.Rendered && (this._tasks.forEach(({ unitId: r, subUnitId: a, threadIds: d }) => {
- let m = o.get(r);
- m || (m = /* @__PURE__ */ new Map(), o.set(r, m));
- let c = m.get(a);
- c || (c = /* @__PURE__ */ new Set(), m.set(a, c));
- for (const h of d)
- c.add(h);
- }), this._tasks = [], o.forEach((r, a) => {
- r.forEach((d, m) => {
- this.syncThreadComments(a, m, Array.from(d));
- });
- }));
- }));
- }
- _ensureCommentMap(t, e) {
- let n = this._commentsMap.get(t);
- n || (n = /* @__PURE__ */ new Map(), this._commentsMap.set(t, n));
- let o = n.get(e);
- return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
- }
- ensureMap(t, e) {
- return this._ensureCommentMap(t, e);
- }
- _ensureThreadMap(t, e) {
- let n = this._threadMap.get(t);
- n || (n = /* @__PURE__ */ new Map(), this._threadMap.set(t, n));
- let o = n.get(e);
- return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
- }
- _replaceComment(t, e, n) {
- const o = this._ensureCommentMap(t, e), r = o.get(n.id);
- if (r) {
- const { children: a, ...d } = n, m = {
- ...d,
- ref: r.ref
- };
- o.set(n.id, m), a == null || a.forEach((c) => {
- o.set(c.id, {
- ...c,
- ref: ""
- });
- }), this._commentUpdate$.next({
- unitId: t,
- subUnitId: e,
- type: "syncUpdate",
- payload: m
- }), !!n.resolved != !!r.resolved && this._commentUpdate$.next({
- unitId: t,
- subUnitId: e,
- type: "resolve",
- payload: {
- commentId: n.id,
- resolved: !!n.resolved
- }
- });
- }
- }
- async syncThreadComments(t, e, n) {
- if (this._lifecycleService.stage < Ve.Rendered) {
- this._tasks.push({ unitId: t, subUnitId: e, threadIds: n });
- return;
- }
- const o = this._ensureThreadMap(t, e), r = this._ensureCommentMap(t, e), a = await this._dataSourceService.listThreadComments(t, e, n);
- if (!a)
- return;
- const d = new Set(n);
- a.forEach((m) => {
- this._replaceComment(t, e, m), d.delete(m.threadId);
- }), d.forEach((m) => {
- o.delete(m), r.forEach((c, h) => {
- c.threadId === m && r.delete(h);
- });
- });
- }
- addComment(t, e, n, o) {
- const r = this._ensureCommentMap(t, e), { parentId: a, children: d = [], ...m } = n, c = {
- ...m,
- parentId: a === n.id ? void 0 : a
- };
- c.threadId || (c.threadId = c.parentId || c.id);
- const h = (f) => {
- r.set(f.id, f), this._commentUpdate$.next({
- unitId: t,
- subUnitId: e,
- type: "add",
- payload: f,
- isRoot: !f.parentId
- });
- };
- h(c);
- const _ = this._ensureThreadMap(t, e);
- if (!c.parentId) {
- _.set(c.threadId, c);
- for (const f of d)
- h(f);
- }
- return o && this.syncThreadComments(t, e, [c.threadId]), true;
- }
- updateComment(t, e, n, o) {
- const a = this._ensureCommentMap(t, e).get(n.commentId);
- return a && (a.updated = true, a.text = n.text, a.attachments = n.attachments, a.updateT = n.updateT, this._commentUpdate$.next({
- unitId: t,
- subUnitId: e,
- type: "update",
- payload: n,
- silent: o
- })), true;
- }
- updateCommentRef(t, e, n, o) {
- const a = this._ensureCommentMap(t, e).get(n.commentId);
- return a ? (a.ref = n.ref, this._commentUpdate$.next({
- unitId: t,
- subUnitId: e,
- type: "updateRef",
- payload: n,
- silent: o,
- threadId: a.threadId
- }), true) : false;
- }
- resolveComment(t, e, n, o) {
- const a = this._ensureCommentMap(t, e).get(n);
- return a ? (a.resolved = o, this._commentUpdate$.next({
- unitId: t,
- subUnitId: e,
- type: "resolve",
- payload: {
- commentId: n,
- resolved: o
- }
- }), true) : false;
- }
- getComment(t, e, n) {
- return this._ensureCommentMap(t, e).get(n);
- }
- getRootComment(t, e, n) {
- return this._ensureThreadMap(t, e).get(n);
- }
- getThread(t, e, n) {
- const o = this._ensureCommentMap(t, e), r = Array.from(o.values()).filter((c) => c.threadId === n);
- let a;
- const d = [], m = /* @__PURE__ */ new Set();
- for (const c of r)
- c.parentId ? d.push(c) : a = c, m.add(c.personId);
- if (a)
- return {
- root: a,
- children: d,
- relativeUsers: m,
- unitId: t,
- subUnitId: e,
- threadId: n
- };
- }
- getCommentWithChildren(t, e, n) {
- const o = this.getComment(t, e, n);
- if (o)
- return this.getThread(t, e, o.threadId);
- }
- _deleteComment(t, e, n) {
- const o = this._ensureCommentMap(t, e), r = o.get(n);
- r && (o.delete(n), this._commentUpdate$.next({
- unitId: t,
- subUnitId: e,
- type: "delete",
- payload: {
- commentId: n,
- isRoot: !r.parentId,
- comment: r
- }
- }));
- }
- deleteThread(t, e, n) {
- this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((a) => {
- a.threadId === n && this._deleteComment(t, e, a.id);
- });
- }
- deleteComment(t, e, n) {
- const r = this._ensureCommentMap(t, e).get(n);
- return r && (r.parentId ? this._deleteComment(t, e, n) : this.deleteThread(t, e, r.threadId)), true;
- }
- deleteUnit(t) {
- const e = this._commentsMap.get(t);
- e && e.forEach((n, o) => {
- n.forEach((r) => {
- this.deleteComment(t, o, r.id);
- });
- });
- }
- getUnit(t) {
- const e = this._threadMap.get(t);
- if (!e)
- return [];
- const n = [];
- return e.forEach((o, r) => {
- o.forEach((a, d) => {
- const m = this.getThread(t, r, d);
- m && n.push(m);
- });
- }), n;
- }
- getAll() {
- const t = [];
- return this._commentsMap.forEach((e, n) => {
- t.push({
- unitId: n,
- threads: this.getUnit(n)
- });
- }), t;
- }
- };
- i = Q([
- I(0, ot(p)),
- I(1, ot(Ht))
- ], i);
- var T = ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(T || {});
- var w = "UNIVER_THREAD_COMMENT_PLUGIN";
- var X = Object.defineProperty;
- var k = Object.getOwnPropertyDescriptor;
- var ee = (s, t, e, n) => {
- for (var o = n > 1 ? void 0 : n ? k(t, e) : t, r = s.length - 1, a; r >= 0; r--)
- (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
- return n && o && X(t, e, o), o;
- };
- var v = (s, t) => (e, n) => t(e, n, s);
- var S = class extends nt {
- constructor(s, t, e) {
- super(), this._resourceManagerService = s, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot();
- }
- _initSnapshot() {
- const s = (e) => {
- const n = this._threadCommentModel.getUnit(e), o = {};
- return n ? (n.forEach((r) => {
- var d;
- const a = (d = o[r.subUnitId]) != null ? d : [];
- a.push({
- ...r.root,
- children: r.children
- }), o[r.subUnitId] = a;
- }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o, e))) : "";
- }, t = (e) => {
- if (!e)
- return {};
- try {
- return JSON.parse(e);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- pluginName: `SHEET_${w}`,
- businesses: [T.UNIVER_SHEET, T.UNIVER_DOC],
- toJson: (e) => s(e),
- parseJson: (e) => t(e),
- onUnLoad: (e) => {
- this._threadCommentModel.deleteUnit(e);
- },
- onLoad: async (e, n) => {
- Object.keys(n).forEach((o) => {
- const r = n[o];
- r.forEach((a) => {
- this._threadCommentModel.addComment(e, o, a);
- }), this._threadCommentModel.syncThreadComments(e, o, r.map((a) => a.threadId));
- });
- }
- })
- );
- }
- };
- S = ee([
- v(0, Bi),
- v(1, ot(i)),
- v(2, p)
- ], S);
- var P = {
- id: "thread-comment.mutation.add-comment",
- type: ar.MUTATION,
- handler(s, t, e) {
- if (!t)
- return false;
- const n = s.get(i), { unitId: o, subUnitId: r, comment: a, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !a.parentId;
- return n.addComment(o, r, a, m);
- }
- };
- var $ = {
- id: "thread-comment.mutation.update-comment",
- type: ar.MUTATION,
- handler(s, t) {
- if (!t)
- return false;
- const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
- return e.updateComment(n, o, r, a);
- }
- };
- var te = {
- id: "thread-comment.mutation.update-comment-ref",
- type: ar.MUTATION,
- handler(s, t) {
- if (!t)
- return false;
- const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
- return e.updateCommentRef(n, o, r, a);
- }
- };
- var x = {
- id: "thread-comment.mutation.resolve-comment",
- type: ar.MUTATION,
- handler(s, t) {
- if (!t)
- return false;
- const e = s.get(i), { unitId: n, subUnitId: o, resolved: r, commentId: a } = t;
- return e.resolveComment(n, o, a, r);
- }
- };
- var N = {
- id: "thread-comment.mutation.delete-comment",
- type: ar.MUTATION,
- handler(s, t) {
- if (!t)
- return false;
- const e = s.get(i), { unitId: n, subUnitId: o, commentId: r } = t;
- return e.deleteComment(n, o, r);
- }
- };
- var ne = {
- id: "thread-comment.command.add-comment",
- type: ar.COMMAND,
- async handler(s, t) {
- if (!t)
- return false;
- const e = s.get(Pt), n = s.get(p), { comment: o } = t, r = await n.addComment(o), a = n.syncUpdateMutationToColla, d = !o.parentId, m = {
- id: P.id,
- params: {
- ...t,
- comment: r
- }
- };
- return d ? await e.executeCommand(m.id, m.params) : e.executeCommand(m.id, m.params, {
- onlyLocal: !a
- });
- }
- };
- var oe = {
- id: "thread-comment.command.update-comment",
- type: ar.COMMAND,
- async handler(s, t) {
- if (!t)
- return false;
- const { unitId: e, subUnitId: n, payload: o } = t, r = s.get(Pt), a = s.get(i), d = s.get(p), m = d.syncUpdateMutationToColla, c = a.getComment(
- e,
- n,
- o.commentId
- );
- if (!c)
- return false;
- const { children: h, ..._ } = c;
- if (!await d.updateComment({
- ..._,
- ...o
- }))
- return false;
- const E = {
- id: $.id,
- params: t
- };
- return r.executeCommand(E.id, E.params, { onlyLocal: !m }), true;
- }
- };
- var re = {
- id: "thread-comment.command.resolve-comment",
- type: ar.COMMAND,
- async handler(s, t) {
- if (!t)
- return false;
- const { unitId: e, subUnitId: n, resolved: o, commentId: r } = t, a = s.get(p), m = s.get(i).getComment(e, n, r), c = a.syncUpdateMutationToColla;
- return !m || !await a.resolveComment({
- ...m,
- resolved: o
- }) ? false : s.get(Pt).executeCommand(
- x.id,
- t,
- { onlyLocal: !c }
- );
- }
- };
- var ae = {
- id: "thread-comment.command.delete-comment",
- type: ar.COMMAND,
- async handler(s, t) {
- if (!t)
- return false;
- const e = s.get(i), n = s.get(p), o = s.get(Pt), { unitId: r, subUnitId: a, commentId: d } = t, m = n.syncUpdateMutationToColla, c = e.getComment(r, a, d);
- if (!c || !await n.deleteComment(r, a, c.threadId, d))
- return false;
- const h = {
- id: N.id,
- params: t
- };
- return o.executeCommand(h.id, h.params, { onlyLocal: !m });
- }
- };
- var se = {
- id: "thread-comment.command.delete-comment-tree",
- type: ar.COMMAND,
- async handler(s, t) {
- if (!t)
- return false;
- const e = s.get(i), n = s.get(Pt), o = s.get(p), { unitId: r, subUnitId: a, commentId: d } = t, m = e.getCommentWithChildren(r, a, d);
- return !m || !await o.deleteComment(r, a, m.root.threadId, d) ? false : await n.executeCommand(N.id, {
- unitId: r,
- subUnitId: a,
- commentId: m.root.id
- });
- }
- };
- var me = "thread-comment.config";
- var R = {};
- var ce = Object.defineProperty;
- var de = Object.getOwnPropertyDescriptor;
- var ie = (s, t, e, n) => {
- for (var o = n > 1 ? void 0 : n ? de(t, e) : t, r = s.length - 1, a; r >= 0; r--)
- (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
- return n && o && ce(t, e, o), o;
- };
- var y = (s, t) => (e, n) => t(e, n, s);
- var M;
- var D = (M = class extends Ra {
- constructor(s = R, t, e, n) {
- super(), this._config = s, this._injector = t, this._commandService = e, this._configService = n;
- const { ...o } = nu(
- {},
- R,
- this._config
- );
- this._configService.setConfig(me, o);
- }
- onStarting() {
- var s;
- kE([
- [p, { useClass: F }],
- [i],
- [S]
- ], (s = this._config) == null ? void 0 : s.overrides).forEach(
- (t) => {
- this._injector.add(t);
- }
- ), [
- ne,
- oe,
- ae,
- re,
- se,
- P,
- $,
- te,
- N,
- x
- ].forEach((t) => {
- this._commandService.registerCommand(t);
- }), this._injector.get(S);
- }
- }, u(M, "pluginName", w), u(M, "type", Fe.UNIVER_UNKNOWN), M);
- D = ie([
- y(1, ot(Ot)),
- y(2, Pt),
- y(3, SE)
- ], D);
- function pe(s) {
- return rn(s).format("YYYY/MM/DD HH:mm");
- }
- export {
- F,
- p,
- i,
- w,
- S,
- P,
- $,
- te,
- x,
- N,
- ne,
- oe,
- re,
- ae,
- se,
- D,
- pe
- };
- //# sourceMappingURL=chunk-PG4GXCOC.js.map
|