123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664 |
- import {
- LS,
- V2,
- Yx,
- k3
- } from "./chunk-2MK3Q52E.js";
- import {
- BehaviorSubject,
- Fe,
- J0,
- Mi,
- Ot,
- Pt,
- Ra,
- SE,
- Subject,
- Vr,
- Ze,
- _n,
- ar,
- cs,
- iu,
- nR,
- nt,
- nu,
- ot,
- st,
- su,
- takeUntil,
- tn,
- x_,
- zd
- } from "./chunk-23V3HWTR.js";
- // node_modules/.pnpm/@univerjs+docs@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/docs/lib/es/index.js
- var ie = Object.defineProperty;
- var re = (i, e, t) => e in i ? ie(i, e, { enumerable: true, configurable: true, writable: true, value: t }) : i[e] = t;
- var u = (i, e, t) => re(i, typeof e != "symbol" ? e + "" : e, t);
- var j = {
- id: "doc.operation.set-selections",
- type: ar.OPERATION,
- handler: () => true
- };
- var Oe = Object.defineProperty;
- var xe = Object.getOwnPropertyDescriptor;
- var Ce = (i, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? xe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
- (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && Oe(e, t, s), s;
- };
- var W = (i, e) => (t, n) => e(t, n, i);
- var m = class extends J0 {
- constructor(e, t) {
- super();
- u(this, "_currentSelection", null);
- u(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
- u(this, "_textSelection$", new Subject());
- u(this, "textSelection$", this._textSelection$.asObservable());
- u(this, "_refreshSelection$", new BehaviorSubject(null));
- u(this, "refreshSelection$", this._refreshSelection$.asObservable());
- this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
- }
- _listenCurrentUnit() {
- this._univerInstanceService.getCurrentTypeOfUnit$(Fe.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((e) => {
- if (e == null)
- return;
- const t = e.getUnitId();
- this._setCurrentSelectionNotRefresh({
- unitId: t,
- subUnitId: t
- });
- });
- }
- __getCurrentSelection() {
- return this._currentSelection;
- }
- getSelectionInfo(e = this._currentSelection) {
- return this._getTextRanges(e);
- }
- refreshSelection(e = this._currentSelection) {
- e != null && this._refresh(e);
- }
- // **Only used in test case** because this does not go through the render layer.
- __TEST_ONLY_setCurrentSelection(e) {
- this._currentSelection = e, this._refresh(e);
- }
- getTextRanges(e = this._currentSelection) {
- var t;
- return (t = this._getTextRanges(e)) == null ? void 0 : t.textRanges;
- }
- getRectRanges(e = this._currentSelection) {
- var t;
- return (t = this._getTextRanges(e)) == null ? void 0 : t.rectRanges;
- }
- getDocRanges(e = this._currentSelection) {
- var r, o;
- const t = (r = this.getTextRanges(e)) != null ? r : [], n = (o = this.getRectRanges(e)) != null ? o : [];
- return [...t, ...n].filter((c) => c.startOffset != null && c.endOffset != null).sort((c, a) => c.startOffset > a.startOffset ? 1 : c.startOffset < a.startOffset ? -1 : 0);
- }
- getActiveTextRange() {
- const e = this._getTextRanges(this._currentSelection);
- if (e == null)
- return;
- const { textRanges: t } = e;
- return t.find((n) => n.isActive);
- }
- /**
- *
- * @deprecated
- */
- getActiveRectRange() {
- const e = this._getTextRanges(this._currentSelection);
- if (e == null)
- return;
- const { rectRanges: t } = e;
- return t.find((n) => n.isActive);
- }
- // **Only used in test case** because this does not go through the render layer.
- __TEST_ONLY_add(e, t = true) {
- this._currentSelection != null && this._addByParam({
- ...this._currentSelection,
- textRanges: e,
- rectRanges: [],
- segmentId: "",
- segmentPage: -1,
- isEditing: t,
- style: LS
- // mock style.
- });
- }
- // Use to replace the current editor selection.
- /**
- * @deprecated pls use replaceDocRanges.
- */
- replaceTextRanges(e, t = true, n) {
- return this.replaceDocRanges(
- e,
- this._currentSelection,
- t,
- n
- );
- }
- replaceDocRanges(e, t = this._currentSelection, n = true, s) {
- if (t == null)
- return;
- const { unitId: r, subUnitId: o } = t;
- this._refreshSelection$.next({
- unitId: r,
- subUnitId: o,
- docRanges: e,
- isEditing: n,
- options: s
- });
- }
- // Only use in doc-selection-render.controller.ts
- __replaceTextRangesWithNoRefresh(e, t) {
- if (this._currentSelection == null)
- return;
- const n = {
- ...e,
- ...t
- };
- this._replaceByParam(n), this._textSelection$.next(n);
- const { unitId: s, subUnitId: r, segmentId: o, style: c, textRanges: a, rectRanges: l, isEditing: d } = n, _ = [...a, ...l].filter((g) => g.startOffset != null && g.endOffset != null).sort((g, f) => g.startOffset > f.startOffset ? 1 : g.startOffset < f.startOffset ? -1 : 0);
- this._commandService.executeCommand(j.id, {
- unitId: s,
- subUnitId: r,
- segmentId: o,
- style: c,
- isEditing: d,
- ranges: _
- });
- }
- dispose() {
- this._textSelection$.complete();
- }
- _setCurrentSelectionNotRefresh(e) {
- this._currentSelection = e;
- }
- _getTextRanges(e) {
- var s;
- if (e == null)
- return;
- const { unitId: t, subUnitId: n = "" } = e;
- return (s = this._textSelectionInfo.get(t)) == null ? void 0 : s.get(n);
- }
- _refresh(e) {
- const t = this._getTextRanges(e);
- if (t == null)
- return;
- const { textRanges: n, rectRanges: s } = t, r = [...n, ...s], { unitId: o, subUnitId: c } = e;
- this._refreshSelection$.next({
- unitId: o,
- subUnitId: c,
- docRanges: r,
- isEditing: false
- });
- }
- _replaceByParam(e) {
- const { unitId: t, subUnitId: n, ...s } = e;
- this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, { ...s });
- }
- _addByParam(e) {
- const { unitId: t, subUnitId: n, ...s } = e;
- this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map());
- const r = this._textSelectionInfo.get(t);
- r.has(n) ? r.get(n).textRanges.push(...e.textRanges) : r.set(n, { ...s });
- }
- };
- m = Ce([
- W(0, Pt),
- W(1, _n)
- ], m);
- var Me = Object.defineProperty;
- var De = Object.getOwnPropertyDescriptor;
- var Te = (i, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? De(e, t) : e, r = i.length - 1, o; r >= 0; r--)
- (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && Me(e, t, s), s;
- };
- var Y = (i, e) => (t, n) => e(t, n, i);
- var D = class extends J0 {
- constructor(e, t, n) {
- super();
- u(this, "_skeleton");
- u(this, "_docViewModel");
- u(this, "_currentSkeleton$", new BehaviorSubject(null));
- u(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
- u(this, "_currentSkeletonBefore$", new BehaviorSubject(null));
- u(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
- u(this, "_currentViewModel$", new BehaviorSubject(null));
- u(this, "currentViewModel$", this._currentViewModel$.asObservable());
- this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(Fe.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((s) => {
- s && s.getUnitId() === this._context.unitId && this._update(s);
- });
- }
- dispose() {
- super.dispose(), this._currentSkeletonBefore$.complete(), this._currentSkeleton$.complete();
- }
- getSkeleton() {
- return this._skeleton;
- }
- getViewModel() {
- return this._docViewModel;
- }
- _init() {
- const e = this._context.unit;
- this._update(e);
- }
- _update(e) {
- const t = this._context.unitId;
- if (e.getBody() == null)
- return;
- this._docViewModel && zd(t) ? (this._docViewModel.reset(e), this._context.unit = e) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(e)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
- const n = this._skeleton;
- n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n), this._currentViewModel$.next(this._docViewModel);
- }
- _buildSkeleton(e) {
- return k3.create(e, this._localeService);
- }
- _buildDocViewModel(e) {
- return new V2(e);
- }
- };
- D = Te([
- Y(1, ot(Vr)),
- Y(2, _n)
- ], D);
- var te = class extends J0 {
- constructor() {
- super();
- u(this, "_docStateChangeParams$", new BehaviorSubject(null));
- u(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
- }
- emitStateChangeInfo(t) {
- this._docStateChangeParams$.next(t);
- }
- dispose() {
- super.dispose(), this._docStateChangeParams$.complete();
- }
- };
- var K = "doc.mutation.rich-text-editing";
- var M = {
- id: K,
- type: ar.MUTATION,
- // eslint-disable-next-line max-lines-per-function
- handler: (i, e) => {
- var z, F;
- const {
- unitId: t,
- segmentId: n = "",
- actions: s,
- textRanges: r,
- prevTextRanges: o,
- trigger: c,
- noHistory: a,
- isCompositionEnd: l,
- noNeedSetTextRange: d,
- debounce: _,
- isEditing: g = true,
- isSync: f,
- syncer: h
- } = e, R = i.get(_n), I = i.get(Yx), v = i.get(te), S = R.getUniverDocInstance(t), L = (z = I.getRenderById(t)) == null ? void 0 : z.with(D).getViewModel();
- if (S == null || L == null)
- throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
- const X = i.get(m), y = (F = X.getDocRanges()) != null ? F : [], ne = !!S.getSnapshot().disabled;
- if (tn.isNoop(s) || s && s.length === 0 || ne)
- return {
- unitId: t,
- actions: [],
- textRanges: y
- };
- const G = tn.invertWithDoc(s, S.getSnapshot());
- S.apply(s), L.reset(S), !d && r && c != null && !f && queueMicrotask(() => {
- X.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
- });
- const se = {
- commandId: K,
- unitId: t,
- segmentId: n,
- trigger: c,
- noHistory: a,
- debounce: _,
- redoState: {
- actions: s,
- textRanges: r
- },
- undoState: {
- actions: G,
- textRanges: o != null ? o : y
- },
- isCompositionEnd: l,
- isSync: f,
- syncer: h
- };
- return v.emitStateChangeInfo(se), {
- unitId: t,
- actions: G,
- textRanges: y
- };
- }
- };
- var be = {
- id: "doc.mutation.rename-doc",
- type: ar.MUTATION,
- handler: (i, e) => {
- const n = i.get(_n).getUnit(e.unitId, Fe.UNIVER_DOC);
- return n ? (n.setName(e.name), true) : false;
- }
- };
- var we = "docs.config";
- var H = {};
- var ye = Object.defineProperty;
- var $e = Object.getOwnPropertyDescriptor;
- var Ue = (i, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? $e(e, t) : e, r = i.length - 1, o; r >= 0; r--)
- (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && ye(e, t, s), s;
- };
- var U = (i, e) => (t, n) => e(t, n, i);
- var T = class extends nt {
- constructor(i, e, t) {
- super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
- }
- _transformCustomRange(i, e) {
- var o;
- const { startOffset: t, endOffset: n, collapsed: s } = e, r = (o = i.getCustomRanges()) == null ? void 0 : o.filter((c) => !c.wholeEntity || t <= c.startIndex && n > c.endIndex ? false : s ? c.startIndex < t && c.endIndex >= n : st.range.isIntersects(t, n - 1, c.startIndex, c.endIndex));
- if (r != null && r.length) {
- let c = t, a = n;
- return r.forEach((l) => {
- c = Math.min(l.startIndex, c), a = Math.max(l.endIndex + 1, a);
- }), {
- ...e,
- startOffset: c,
- endOffset: a,
- collapsed: c === a
- };
- }
- return e;
- }
- _initSelectionChange() {
- this.disposeWithMe(this._commandService.onCommandExecuted((i) => {
- if (i.id === j.id) {
- const e = i.params, { unitId: t, ranges: n, isEditing: s } = e, r = this._univerInstanceService.getUnit(t);
- if (!r)
- return;
- const o = n.map((c) => this._transformCustomRange(r, c));
- o.some((c, a) => n[a] !== c) && this._textSelectionManagerService.replaceTextRanges(o, s);
- }
- }));
- }
- };
- T = Ue([
- U(0, Pt),
- U(1, ot(m)),
- U(2, _n)
- ], T);
- var Ee = Object.defineProperty;
- var Pe = Object.getOwnPropertyDescriptor;
- var Ne = (i, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? Pe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
- (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && Ee(e, t, s), s;
- };
- var k = (i, e) => (t, n) => e(t, n, i);
- var Ve = "DOCS_PLUGIN";
- var P;
- var q = (P = class extends Ra {
- // static override type = UniverInstanceType.UNIVER_DOC;
- constructor(i = H, e, t) {
- super(), this._config = i, this._injector = e, this._configService = t;
- const { ...n } = nu(
- {},
- H,
- this._config
- );
- this._configService.setConfig(we, n);
- }
- onStarting() {
- this._initializeDependencies(), this._initializeCommands();
- }
- _initializeCommands() {
- [
- M,
- be,
- j
- ].forEach((i) => {
- this._injector.get(Pt).registerCommand(i);
- });
- }
- _initializeDependencies() {
- [
- [m],
- [te],
- [T]
- ].forEach((i) => this._injector.add(i));
- }
- onReady() {
- this._injector.get(T);
- }
- }, u(P, "pluginName", Ve), P);
- q = Ne([
- k(1, ot(Ot)),
- k(2, SE)
- ], q);
- var Be = nR("CUSTOM_RANGE");
- var je = nR("CUSTOM_DECORATION");
- var E = {
- CUSTOM_RANGE: Be,
- CUSTOM_DECORATION: je
- };
- var Ae = Object.defineProperty;
- var Le = Object.getOwnPropertyDescriptor;
- var Xe = (i, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? Le(e, t) : e, r = i.length - 1, o; r >= 0; r--)
- (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && Ae(e, t, s), s;
- };
- var Ge = (i, e) => (t, n) => e(t, n, i);
- var J = class extends nt {
- constructor(e, t) {
- super();
- u(this, "_interceptorsByName", /* @__PURE__ */ new Map());
- this._context = e, this._docSkeletonManagerService = t;
- const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
- if (s === su || s === iu)
- return;
- this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(E.CUSTOM_RANGE, {
- priority: -1,
- handler: (o, c, a) => a(o)
- }));
- let r = new Mi();
- n.segmentViewModels$.subscribe((o) => {
- r.dispose(), r = new Mi(), o.forEach((c) => {
- r.add(this.interceptDocumentViewModel(c));
- });
- }), this.disposeWithMe(r);
- }
- intercept(e, t) {
- const n = e;
- this._interceptorsByName.has(n) || this._interceptorsByName.set(n, []);
- const s = this._interceptorsByName.get(n);
- return s.push(t), this._interceptorsByName.set(
- n,
- s.sort((r, o) => {
- var c, a;
- return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
- })
- ), this.disposeWithMe(Ze(() => cs(this._interceptorsByName.get(n), t)));
- }
- fetchThroughInterceptors(e) {
- const t = e, n = this._interceptorsByName.get(t);
- return x_(n || []);
- }
- interceptDocumentViewModel(e) {
- const t = new Mi();
- return t.add(e.registerCustomRangeInterceptor({
- getCustomRange: (n) => {
- var s;
- return this.fetchThroughInterceptors(E.CUSTOM_RANGE)(
- e.getCustomRangeRaw(n),
- {
- index: n,
- unitId: e.getDataModel().getUnitId(),
- customRanges: (s = e.getDataModel().getCustomRanges()) != null ? s : []
- }
- );
- },
- getCustomDecoration: (n) => {
- var s;
- return this.fetchThroughInterceptors(E.CUSTOM_DECORATION)(
- e.getCustomDecorationRaw(n),
- {
- index: n,
- unitId: e.getDataModel().getUnitId(),
- customDecorations: (s = e.getDataModel().getCustomDecorations()) != null ? s : []
- }
- );
- }
- })), t;
- }
- };
- J = Xe([
- Ge(1, ot(D))
- ], J);
- function A(i, e = "") {
- if (!e)
- return ["body"];
- const { headers: t, footers: n } = i.getSnapshot();
- if (t == null && n == null)
- throw new Error("Document data model must have headers or footers when update by segment id");
- if ((t == null ? void 0 : t[e]) != null)
- return ["headers", e, "body"];
- if ((n == null ? void 0 : n[e]) != null)
- return ["footers", e, "body"];
- throw new Error("Segment id not found in headers or footers");
- }
- function Ke(i, e, t) {
- const { unitId: n, segmentId: s } = e, o = i.get(_n).getUnit(n);
- if (!o)
- return false;
- const c = {
- id: M.id,
- params: {
- unitId: e.unitId,
- actions: [],
- textRanges: void 0
- }
- }, a = tn.getInstance(), l = st.customRange.add({ ...e, body: t });
- if (!l)
- return false;
- const d = A(o, s);
- return c.params.actions = a.editOp(l.serialize(), d), c;
- }
- function He(i, e) {
- var S;
- const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selections: c } = e, a = i.get(m), l = i.get(_n), d = c != null ? c : a.getTextRanges({ unitId: o, subUnitId: o }), _ = (S = d == null ? void 0 : d[0]) == null ? void 0 : S.segmentId;
- if (!(d != null && d.length))
- return false;
- const g = l.getUnit(o, Fe.UNIVER_DOC);
- if (!g)
- return false;
- const f = g.getSelfOrHeaderFooterModel(_).getBody();
- if (!f)
- return false;
- const h = st.customRange.add({
- ranges: d,
- rangeId: t,
- rangeType: n,
- segmentId: _,
- wholeEntity: s,
- properties: r,
- body: f
- });
- if (!h)
- return false;
- const R = tn.getInstance(), I = {
- id: M.id,
- params: {
- unitId: o,
- actions: [],
- textRanges: h.selections,
- segmentId: _
- },
- textX: h
- }, v = A(g, _);
- return I.params.actions = R.editOp(h.serialize(), v), I;
- }
- function ke(i, e) {
- const { unitId: t, segmentId: n, insert: s } = e, o = i.get(_n).getUnit(t);
- if (!o)
- return false;
- const c = {
- id: M.id,
- params: {
- unitId: e.unitId,
- actions: [],
- textRanges: void 0,
- segmentId: n
- }
- }, a = tn.getInstance(), l = st.customRange.delete({
- documentDataModel: o,
- rangeId: e.rangeId,
- insert: s,
- segmentId: n
- });
- if (!l)
- return false;
- const d = A(o, n);
- return c.params.actions = a.editOp(l.serialize(), d), c.params.textRanges = l.selections, c;
- }
- function qe(i, e) {
- var h, R, I, v;
- const { unitId: t, body: n, doc: s } = e;
- let r = s;
- if (r || (r = i.get(_n).getUnit(t)), !r)
- return false;
- const o = (h = e.selection) == null ? void 0 : h.segmentId, c = (R = r.getSelfOrHeaderFooterModel(o)) == null ? void 0 : R.getBody();
- if (!c)
- return false;
- const a = i.get(m), l = (I = e.selection) != null ? I : a.getActiveTextRange();
- if (!l || !c)
- return false;
- const d = (v = e.textRanges) != null ? v : [{
- startOffset: l.startOffset + n.dataStream.length,
- endOffset: l.startOffset + n.dataStream.length,
- collapsed: true,
- segmentId: o
- }], _ = st.selection.replace({
- selection: l,
- body: n,
- doc: r
- });
- if (!_)
- return false;
- const g = {
- id: M.id,
- params: {
- unitId: t,
- actions: [],
- textRanges: d,
- debounce: true,
- segmentId: o
- },
- textX: _
- }, f = tn.getInstance();
- return g.params.actions = f.editOp(_.serialize()), g;
- }
- export {
- j,
- m,
- D,
- te,
- M,
- q,
- E,
- J,
- Ke,
- He,
- ke,
- qe
- };
- //# sourceMappingURL=chunk-PZD7N4BC.js.map
|