chunk-PZD7N4BC.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. import {
  2. LS,
  3. V2,
  4. Yx,
  5. k3
  6. } from "./chunk-2MK3Q52E.js";
  7. import {
  8. BehaviorSubject,
  9. Fe,
  10. J0,
  11. Mi,
  12. Ot,
  13. Pt,
  14. Ra,
  15. SE,
  16. Subject,
  17. Vr,
  18. Ze,
  19. _n,
  20. ar,
  21. cs,
  22. iu,
  23. nR,
  24. nt,
  25. nu,
  26. ot,
  27. st,
  28. su,
  29. takeUntil,
  30. tn,
  31. x_,
  32. zd
  33. } from "./chunk-23V3HWTR.js";
  34. // 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
  35. var ie = Object.defineProperty;
  36. var re = (i, e, t) => e in i ? ie(i, e, { enumerable: true, configurable: true, writable: true, value: t }) : i[e] = t;
  37. var u = (i, e, t) => re(i, typeof e != "symbol" ? e + "" : e, t);
  38. var j = {
  39. id: "doc.operation.set-selections",
  40. type: ar.OPERATION,
  41. handler: () => true
  42. };
  43. var Oe = Object.defineProperty;
  44. var xe = Object.getOwnPropertyDescriptor;
  45. var Ce = (i, e, t, n) => {
  46. for (var s = n > 1 ? void 0 : n ? xe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
  47. (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
  48. return n && s && Oe(e, t, s), s;
  49. };
  50. var W = (i, e) => (t, n) => e(t, n, i);
  51. var m = class extends J0 {
  52. constructor(e, t) {
  53. super();
  54. u(this, "_currentSelection", null);
  55. u(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
  56. u(this, "_textSelection$", new Subject());
  57. u(this, "textSelection$", this._textSelection$.asObservable());
  58. u(this, "_refreshSelection$", new BehaviorSubject(null));
  59. u(this, "refreshSelection$", this._refreshSelection$.asObservable());
  60. this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
  61. }
  62. _listenCurrentUnit() {
  63. this._univerInstanceService.getCurrentTypeOfUnit$(Fe.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((e) => {
  64. if (e == null)
  65. return;
  66. const t = e.getUnitId();
  67. this._setCurrentSelectionNotRefresh({
  68. unitId: t,
  69. subUnitId: t
  70. });
  71. });
  72. }
  73. __getCurrentSelection() {
  74. return this._currentSelection;
  75. }
  76. getSelectionInfo(e = this._currentSelection) {
  77. return this._getTextRanges(e);
  78. }
  79. refreshSelection(e = this._currentSelection) {
  80. e != null && this._refresh(e);
  81. }
  82. // **Only used in test case** because this does not go through the render layer.
  83. __TEST_ONLY_setCurrentSelection(e) {
  84. this._currentSelection = e, this._refresh(e);
  85. }
  86. getTextRanges(e = this._currentSelection) {
  87. var t;
  88. return (t = this._getTextRanges(e)) == null ? void 0 : t.textRanges;
  89. }
  90. getRectRanges(e = this._currentSelection) {
  91. var t;
  92. return (t = this._getTextRanges(e)) == null ? void 0 : t.rectRanges;
  93. }
  94. getDocRanges(e = this._currentSelection) {
  95. var r, o;
  96. const t = (r = this.getTextRanges(e)) != null ? r : [], n = (o = this.getRectRanges(e)) != null ? o : [];
  97. 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);
  98. }
  99. getActiveTextRange() {
  100. const e = this._getTextRanges(this._currentSelection);
  101. if (e == null)
  102. return;
  103. const { textRanges: t } = e;
  104. return t.find((n) => n.isActive);
  105. }
  106. /**
  107. *
  108. * @deprecated
  109. */
  110. getActiveRectRange() {
  111. const e = this._getTextRanges(this._currentSelection);
  112. if (e == null)
  113. return;
  114. const { rectRanges: t } = e;
  115. return t.find((n) => n.isActive);
  116. }
  117. // **Only used in test case** because this does not go through the render layer.
  118. __TEST_ONLY_add(e, t = true) {
  119. this._currentSelection != null && this._addByParam({
  120. ...this._currentSelection,
  121. textRanges: e,
  122. rectRanges: [],
  123. segmentId: "",
  124. segmentPage: -1,
  125. isEditing: t,
  126. style: LS
  127. // mock style.
  128. });
  129. }
  130. // Use to replace the current editor selection.
  131. /**
  132. * @deprecated pls use replaceDocRanges.
  133. */
  134. replaceTextRanges(e, t = true, n) {
  135. return this.replaceDocRanges(
  136. e,
  137. this._currentSelection,
  138. t,
  139. n
  140. );
  141. }
  142. replaceDocRanges(e, t = this._currentSelection, n = true, s) {
  143. if (t == null)
  144. return;
  145. const { unitId: r, subUnitId: o } = t;
  146. this._refreshSelection$.next({
  147. unitId: r,
  148. subUnitId: o,
  149. docRanges: e,
  150. isEditing: n,
  151. options: s
  152. });
  153. }
  154. // Only use in doc-selection-render.controller.ts
  155. __replaceTextRangesWithNoRefresh(e, t) {
  156. if (this._currentSelection == null)
  157. return;
  158. const n = {
  159. ...e,
  160. ...t
  161. };
  162. this._replaceByParam(n), this._textSelection$.next(n);
  163. 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);
  164. this._commandService.executeCommand(j.id, {
  165. unitId: s,
  166. subUnitId: r,
  167. segmentId: o,
  168. style: c,
  169. isEditing: d,
  170. ranges: _
  171. });
  172. }
  173. dispose() {
  174. this._textSelection$.complete();
  175. }
  176. _setCurrentSelectionNotRefresh(e) {
  177. this._currentSelection = e;
  178. }
  179. _getTextRanges(e) {
  180. var s;
  181. if (e == null)
  182. return;
  183. const { unitId: t, subUnitId: n = "" } = e;
  184. return (s = this._textSelectionInfo.get(t)) == null ? void 0 : s.get(n);
  185. }
  186. _refresh(e) {
  187. const t = this._getTextRanges(e);
  188. if (t == null)
  189. return;
  190. const { textRanges: n, rectRanges: s } = t, r = [...n, ...s], { unitId: o, subUnitId: c } = e;
  191. this._refreshSelection$.next({
  192. unitId: o,
  193. subUnitId: c,
  194. docRanges: r,
  195. isEditing: false
  196. });
  197. }
  198. _replaceByParam(e) {
  199. const { unitId: t, subUnitId: n, ...s } = e;
  200. this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, { ...s });
  201. }
  202. _addByParam(e) {
  203. const { unitId: t, subUnitId: n, ...s } = e;
  204. this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map());
  205. const r = this._textSelectionInfo.get(t);
  206. r.has(n) ? r.get(n).textRanges.push(...e.textRanges) : r.set(n, { ...s });
  207. }
  208. };
  209. m = Ce([
  210. W(0, Pt),
  211. W(1, _n)
  212. ], m);
  213. var Me = Object.defineProperty;
  214. var De = Object.getOwnPropertyDescriptor;
  215. var Te = (i, e, t, n) => {
  216. for (var s = n > 1 ? void 0 : n ? De(e, t) : e, r = i.length - 1, o; r >= 0; r--)
  217. (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
  218. return n && s && Me(e, t, s), s;
  219. };
  220. var Y = (i, e) => (t, n) => e(t, n, i);
  221. var D = class extends J0 {
  222. constructor(e, t, n) {
  223. super();
  224. u(this, "_skeleton");
  225. u(this, "_docViewModel");
  226. u(this, "_currentSkeleton$", new BehaviorSubject(null));
  227. u(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
  228. u(this, "_currentSkeletonBefore$", new BehaviorSubject(null));
  229. u(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
  230. u(this, "_currentViewModel$", new BehaviorSubject(null));
  231. u(this, "currentViewModel$", this._currentViewModel$.asObservable());
  232. this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(Fe.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((s) => {
  233. s && s.getUnitId() === this._context.unitId && this._update(s);
  234. });
  235. }
  236. dispose() {
  237. super.dispose(), this._currentSkeletonBefore$.complete(), this._currentSkeleton$.complete();
  238. }
  239. getSkeleton() {
  240. return this._skeleton;
  241. }
  242. getViewModel() {
  243. return this._docViewModel;
  244. }
  245. _init() {
  246. const e = this._context.unit;
  247. this._update(e);
  248. }
  249. _update(e) {
  250. const t = this._context.unitId;
  251. if (e.getBody() == null)
  252. return;
  253. 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));
  254. const n = this._skeleton;
  255. n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n), this._currentViewModel$.next(this._docViewModel);
  256. }
  257. _buildSkeleton(e) {
  258. return k3.create(e, this._localeService);
  259. }
  260. _buildDocViewModel(e) {
  261. return new V2(e);
  262. }
  263. };
  264. D = Te([
  265. Y(1, ot(Vr)),
  266. Y(2, _n)
  267. ], D);
  268. var te = class extends J0 {
  269. constructor() {
  270. super();
  271. u(this, "_docStateChangeParams$", new BehaviorSubject(null));
  272. u(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
  273. }
  274. emitStateChangeInfo(t) {
  275. this._docStateChangeParams$.next(t);
  276. }
  277. dispose() {
  278. super.dispose(), this._docStateChangeParams$.complete();
  279. }
  280. };
  281. var K = "doc.mutation.rich-text-editing";
  282. var M = {
  283. id: K,
  284. type: ar.MUTATION,
  285. // eslint-disable-next-line max-lines-per-function
  286. handler: (i, e) => {
  287. var z, F;
  288. const {
  289. unitId: t,
  290. segmentId: n = "",
  291. actions: s,
  292. textRanges: r,
  293. prevTextRanges: o,
  294. trigger: c,
  295. noHistory: a,
  296. isCompositionEnd: l,
  297. noNeedSetTextRange: d,
  298. debounce: _,
  299. isEditing: g = true,
  300. isSync: f,
  301. syncer: h
  302. } = 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();
  303. if (S == null || L == null)
  304. throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
  305. const X = i.get(m), y = (F = X.getDocRanges()) != null ? F : [], ne = !!S.getSnapshot().disabled;
  306. if (tn.isNoop(s) || s && s.length === 0 || ne)
  307. return {
  308. unitId: t,
  309. actions: [],
  310. textRanges: y
  311. };
  312. const G = tn.invertWithDoc(s, S.getSnapshot());
  313. S.apply(s), L.reset(S), !d && r && c != null && !f && queueMicrotask(() => {
  314. X.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
  315. });
  316. const se = {
  317. commandId: K,
  318. unitId: t,
  319. segmentId: n,
  320. trigger: c,
  321. noHistory: a,
  322. debounce: _,
  323. redoState: {
  324. actions: s,
  325. textRanges: r
  326. },
  327. undoState: {
  328. actions: G,
  329. textRanges: o != null ? o : y
  330. },
  331. isCompositionEnd: l,
  332. isSync: f,
  333. syncer: h
  334. };
  335. return v.emitStateChangeInfo(se), {
  336. unitId: t,
  337. actions: G,
  338. textRanges: y
  339. };
  340. }
  341. };
  342. var be = {
  343. id: "doc.mutation.rename-doc",
  344. type: ar.MUTATION,
  345. handler: (i, e) => {
  346. const n = i.get(_n).getUnit(e.unitId, Fe.UNIVER_DOC);
  347. return n ? (n.setName(e.name), true) : false;
  348. }
  349. };
  350. var we = "docs.config";
  351. var H = {};
  352. var ye = Object.defineProperty;
  353. var $e = Object.getOwnPropertyDescriptor;
  354. var Ue = (i, e, t, n) => {
  355. for (var s = n > 1 ? void 0 : n ? $e(e, t) : e, r = i.length - 1, o; r >= 0; r--)
  356. (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
  357. return n && s && ye(e, t, s), s;
  358. };
  359. var U = (i, e) => (t, n) => e(t, n, i);
  360. var T = class extends nt {
  361. constructor(i, e, t) {
  362. super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
  363. }
  364. _transformCustomRange(i, e) {
  365. var o;
  366. 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));
  367. if (r != null && r.length) {
  368. let c = t, a = n;
  369. return r.forEach((l) => {
  370. c = Math.min(l.startIndex, c), a = Math.max(l.endIndex + 1, a);
  371. }), {
  372. ...e,
  373. startOffset: c,
  374. endOffset: a,
  375. collapsed: c === a
  376. };
  377. }
  378. return e;
  379. }
  380. _initSelectionChange() {
  381. this.disposeWithMe(this._commandService.onCommandExecuted((i) => {
  382. if (i.id === j.id) {
  383. const e = i.params, { unitId: t, ranges: n, isEditing: s } = e, r = this._univerInstanceService.getUnit(t);
  384. if (!r)
  385. return;
  386. const o = n.map((c) => this._transformCustomRange(r, c));
  387. o.some((c, a) => n[a] !== c) && this._textSelectionManagerService.replaceTextRanges(o, s);
  388. }
  389. }));
  390. }
  391. };
  392. T = Ue([
  393. U(0, Pt),
  394. U(1, ot(m)),
  395. U(2, _n)
  396. ], T);
  397. var Ee = Object.defineProperty;
  398. var Pe = Object.getOwnPropertyDescriptor;
  399. var Ne = (i, e, t, n) => {
  400. for (var s = n > 1 ? void 0 : n ? Pe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
  401. (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
  402. return n && s && Ee(e, t, s), s;
  403. };
  404. var k = (i, e) => (t, n) => e(t, n, i);
  405. var Ve = "DOCS_PLUGIN";
  406. var P;
  407. var q = (P = class extends Ra {
  408. // static override type = UniverInstanceType.UNIVER_DOC;
  409. constructor(i = H, e, t) {
  410. super(), this._config = i, this._injector = e, this._configService = t;
  411. const { ...n } = nu(
  412. {},
  413. H,
  414. this._config
  415. );
  416. this._configService.setConfig(we, n);
  417. }
  418. onStarting() {
  419. this._initializeDependencies(), this._initializeCommands();
  420. }
  421. _initializeCommands() {
  422. [
  423. M,
  424. be,
  425. j
  426. ].forEach((i) => {
  427. this._injector.get(Pt).registerCommand(i);
  428. });
  429. }
  430. _initializeDependencies() {
  431. [
  432. [m],
  433. [te],
  434. [T]
  435. ].forEach((i) => this._injector.add(i));
  436. }
  437. onReady() {
  438. this._injector.get(T);
  439. }
  440. }, u(P, "pluginName", Ve), P);
  441. q = Ne([
  442. k(1, ot(Ot)),
  443. k(2, SE)
  444. ], q);
  445. var Be = nR("CUSTOM_RANGE");
  446. var je = nR("CUSTOM_DECORATION");
  447. var E = {
  448. CUSTOM_RANGE: Be,
  449. CUSTOM_DECORATION: je
  450. };
  451. var Ae = Object.defineProperty;
  452. var Le = Object.getOwnPropertyDescriptor;
  453. var Xe = (i, e, t, n) => {
  454. for (var s = n > 1 ? void 0 : n ? Le(e, t) : e, r = i.length - 1, o; r >= 0; r--)
  455. (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
  456. return n && s && Ae(e, t, s), s;
  457. };
  458. var Ge = (i, e) => (t, n) => e(t, n, i);
  459. var J = class extends nt {
  460. constructor(e, t) {
  461. super();
  462. u(this, "_interceptorsByName", /* @__PURE__ */ new Map());
  463. this._context = e, this._docSkeletonManagerService = t;
  464. const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
  465. if (s === su || s === iu)
  466. return;
  467. this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(E.CUSTOM_RANGE, {
  468. priority: -1,
  469. handler: (o, c, a) => a(o)
  470. }));
  471. let r = new Mi();
  472. n.segmentViewModels$.subscribe((o) => {
  473. r.dispose(), r = new Mi(), o.forEach((c) => {
  474. r.add(this.interceptDocumentViewModel(c));
  475. });
  476. }), this.disposeWithMe(r);
  477. }
  478. intercept(e, t) {
  479. const n = e;
  480. this._interceptorsByName.has(n) || this._interceptorsByName.set(n, []);
  481. const s = this._interceptorsByName.get(n);
  482. return s.push(t), this._interceptorsByName.set(
  483. n,
  484. s.sort((r, o) => {
  485. var c, a;
  486. return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
  487. })
  488. ), this.disposeWithMe(Ze(() => cs(this._interceptorsByName.get(n), t)));
  489. }
  490. fetchThroughInterceptors(e) {
  491. const t = e, n = this._interceptorsByName.get(t);
  492. return x_(n || []);
  493. }
  494. interceptDocumentViewModel(e) {
  495. const t = new Mi();
  496. return t.add(e.registerCustomRangeInterceptor({
  497. getCustomRange: (n) => {
  498. var s;
  499. return this.fetchThroughInterceptors(E.CUSTOM_RANGE)(
  500. e.getCustomRangeRaw(n),
  501. {
  502. index: n,
  503. unitId: e.getDataModel().getUnitId(),
  504. customRanges: (s = e.getDataModel().getCustomRanges()) != null ? s : []
  505. }
  506. );
  507. },
  508. getCustomDecoration: (n) => {
  509. var s;
  510. return this.fetchThroughInterceptors(E.CUSTOM_DECORATION)(
  511. e.getCustomDecorationRaw(n),
  512. {
  513. index: n,
  514. unitId: e.getDataModel().getUnitId(),
  515. customDecorations: (s = e.getDataModel().getCustomDecorations()) != null ? s : []
  516. }
  517. );
  518. }
  519. })), t;
  520. }
  521. };
  522. J = Xe([
  523. Ge(1, ot(D))
  524. ], J);
  525. function A(i, e = "") {
  526. if (!e)
  527. return ["body"];
  528. const { headers: t, footers: n } = i.getSnapshot();
  529. if (t == null && n == null)
  530. throw new Error("Document data model must have headers or footers when update by segment id");
  531. if ((t == null ? void 0 : t[e]) != null)
  532. return ["headers", e, "body"];
  533. if ((n == null ? void 0 : n[e]) != null)
  534. return ["footers", e, "body"];
  535. throw new Error("Segment id not found in headers or footers");
  536. }
  537. function Ke(i, e, t) {
  538. const { unitId: n, segmentId: s } = e, o = i.get(_n).getUnit(n);
  539. if (!o)
  540. return false;
  541. const c = {
  542. id: M.id,
  543. params: {
  544. unitId: e.unitId,
  545. actions: [],
  546. textRanges: void 0
  547. }
  548. }, a = tn.getInstance(), l = st.customRange.add({ ...e, body: t });
  549. if (!l)
  550. return false;
  551. const d = A(o, s);
  552. return c.params.actions = a.editOp(l.serialize(), d), c;
  553. }
  554. function He(i, e) {
  555. var S;
  556. 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;
  557. if (!(d != null && d.length))
  558. return false;
  559. const g = l.getUnit(o, Fe.UNIVER_DOC);
  560. if (!g)
  561. return false;
  562. const f = g.getSelfOrHeaderFooterModel(_).getBody();
  563. if (!f)
  564. return false;
  565. const h = st.customRange.add({
  566. ranges: d,
  567. rangeId: t,
  568. rangeType: n,
  569. segmentId: _,
  570. wholeEntity: s,
  571. properties: r,
  572. body: f
  573. });
  574. if (!h)
  575. return false;
  576. const R = tn.getInstance(), I = {
  577. id: M.id,
  578. params: {
  579. unitId: o,
  580. actions: [],
  581. textRanges: h.selections,
  582. segmentId: _
  583. },
  584. textX: h
  585. }, v = A(g, _);
  586. return I.params.actions = R.editOp(h.serialize(), v), I;
  587. }
  588. function ke(i, e) {
  589. const { unitId: t, segmentId: n, insert: s } = e, o = i.get(_n).getUnit(t);
  590. if (!o)
  591. return false;
  592. const c = {
  593. id: M.id,
  594. params: {
  595. unitId: e.unitId,
  596. actions: [],
  597. textRanges: void 0,
  598. segmentId: n
  599. }
  600. }, a = tn.getInstance(), l = st.customRange.delete({
  601. documentDataModel: o,
  602. rangeId: e.rangeId,
  603. insert: s,
  604. segmentId: n
  605. });
  606. if (!l)
  607. return false;
  608. const d = A(o, n);
  609. return c.params.actions = a.editOp(l.serialize(), d), c.params.textRanges = l.selections, c;
  610. }
  611. function qe(i, e) {
  612. var h, R, I, v;
  613. const { unitId: t, body: n, doc: s } = e;
  614. let r = s;
  615. if (r || (r = i.get(_n).getUnit(t)), !r)
  616. return false;
  617. const o = (h = e.selection) == null ? void 0 : h.segmentId, c = (R = r.getSelfOrHeaderFooterModel(o)) == null ? void 0 : R.getBody();
  618. if (!c)
  619. return false;
  620. const a = i.get(m), l = (I = e.selection) != null ? I : a.getActiveTextRange();
  621. if (!l || !c)
  622. return false;
  623. const d = (v = e.textRanges) != null ? v : [{
  624. startOffset: l.startOffset + n.dataStream.length,
  625. endOffset: l.startOffset + n.dataStream.length,
  626. collapsed: true,
  627. segmentId: o
  628. }], _ = st.selection.replace({
  629. selection: l,
  630. body: n,
  631. doc: r
  632. });
  633. if (!_)
  634. return false;
  635. const g = {
  636. id: M.id,
  637. params: {
  638. unitId: t,
  639. actions: [],
  640. textRanges: d,
  641. debounce: true,
  642. segmentId: o
  643. },
  644. textX: _
  645. }, f = tn.getInstance();
  646. return g.params.actions = f.editOp(_.serialize()), g;
  647. }
  648. export {
  649. j,
  650. m,
  651. D,
  652. te,
  653. M,
  654. q,
  655. E,
  656. J,
  657. Ke,
  658. He,
  659. ke,
  660. qe
  661. };
  662. //# sourceMappingURL=chunk-PZD7N4BC.js.map