| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- var x = Object.defineProperty;
- var T = (i, e, n) => e in i ? x(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n;
- var h = (i, e, n) => T(i, typeof e != "symbol" ? e + "" : e, n);
- import { Inject as l, Disposable as R, ObjectMatrix as $, UniverInstanceType as y, IUniverInstanceService as E, sequenceExecuteAsync as P, toDisposable as D, ICommandService as b, DependentOn as O, Injector as A, Plugin as j } from "@univerjs/core";
- import { singleReferenceToGrid as u, serializeRange as M } from "@univerjs/engine-formula";
- import { RefRangeService as W, SheetsSelectionsService as L, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as B } from "@univerjs/sheets";
- import { ThreadCommentModel as S, DeleteCommentMutation as N, AddCommentMutation as V, UpdateCommentRefMutation as C, UniverThreadCommentPlugin as H } from "@univerjs/thread-comment";
- import { Subject as F } from "rxjs";
- var z = Object.defineProperty, G = Object.getOwnPropertyDescriptor, q = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? G(e, n) : e, s = i.length - 1, o; s >= 0; s--)
- (o = i[s]) && (r = (t ? o(e, n, r) : o(r)) || r);
- return t && r && z(e, n, r), r;
- }, w = (i, e) => (n, t) => e(n, t, i);
- let p = class extends R {
- constructor(e, n) {
- super();
- h(this, "_matrixMap", /* @__PURE__ */ new Map());
- h(this, "_locationMap", /* @__PURE__ */ new Map());
- h(this, "_commentUpdate$", new F());
- 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 $(), 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 = u(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) !== y.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 = u(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 = u(a.ref);
- this._commentUpdate$.next({
- ...e,
- ...c
- });
- break;
- }
- case "updateRef": {
- const o = u(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 !1;
- 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, l(S)),
- w(1, E)
- ], p);
- var J = Object.defineProperty, K = Object.getOwnPropertyDescriptor, Q = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? K(e, n) : e, s = i.length - 1, o; s >= 0; s--)
- (o = i[s]) && (r = (t ? o(e, n, r) : o(r)) || r);
- return t && r && J(e, n, r), r;
- }, _ = (i, e) => (n, t) => e(n, t, i);
- let f = class extends R {
- constructor(e, n, t, r, s) {
- super();
- h(this, "_disposableMap", /* @__PURE__ */ new Map());
- h(this, "_watcherMap", /* @__PURE__ */ new Map());
- h(this, "_handleRangeChange", (e, n, t, r, s) => {
- const o = t.id, a = {
- startColumn: t.column,
- endColumn: t.column,
- startRow: t.row,
- endRow: t.row
- };
- return r ? {
- redos: [{
- id: C.id,
- params: {
- unitId: e,
- subUnitId: n,
- payload: {
- ref: M(r),
- commentId: o
- },
- silent: s
- }
- }],
- undos: [{
- id: C.id,
- params: {
- unitId: e,
- subUnitId: n,
- payload: {
- ref: M(a),
- commentId: o
- },
- silent: s
- }
- }]
- } : {
- redos: [{
- id: N.id,
- params: {
- unitId: e,
- subUnitId: n,
- commentId: o
- }
- }],
- undos: [{
- id: V.id,
- params: {
- unitId: e,
- subUnitId: n,
- comment: t,
- sync: !0
- }
- }]
- };
- });
- 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 = B(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, !1);
- }, 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, !0);
- P(c, this._commandService, { onlyLocal: !0 });
- }, !0)
- );
- }
- _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 = u(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(D(() => {
- this._disposableMap.forEach((e) => {
- e.dispose();
- }), this._disposableMap.clear();
- }));
- }
- };
- f = Q([
- _(0, l(W)),
- _(1, l(p)),
- _(2, l(S)),
- _(3, l(L)),
- _(4, b)
- ], f);
- const X = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
- var I = Object.defineProperty, Y = Object.getOwnPropertyDescriptor, Z = (i, e, n) => e in i ? I(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, k = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? Y(e, n) : e, s = i.length - 1, o; s >= 0; s--)
- (o = i[s]) && (r = (t ? o(e, n, r) : o(r)) || r);
- return t && r && I(e, n, r), r;
- }, v = (i, e) => (n, t) => e(n, t, i), U = (i, e, n) => Z(i, typeof e != "symbol" ? e + "" : e, n);
- let g = class extends j {
- constructor(i, e, n) {
- super(), this._injector = e, this._commandService = n;
- }
- onStarting() {
- [
- [p],
- [f]
- ].forEach((i) => {
- this._injector.add(i);
- }), this._injector.get(f);
- }
- };
- U(g, "pluginName", X);
- U(g, "type", y.UNIVER_SHEET);
- g = k([
- O(H),
- v(1, l(A)),
- v(2, l(b))
- ], g);
- export {
- p as SheetsThreadCommentModel,
- f as SheetsThreadCommentRefRangeController,
- g as UniverSheetsThreadCommentPlugin
- };
|