@univerjs/docs 0.4.2-nightly.202411061606 → 0.4.2-nightly.202411081606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";var G=Object.defineProperty;var k=(o,i,e)=>i in o?G(o,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[i]=e;var d=(o,i,e)=>k(o,typeof i!="symbol"?i+"":i,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),T=require("@univerjs/engine-render"),p=require("rxjs"),x=require("@univerjs/docs"),b={id:"doc.operation.set-selections",type:c.CommandType.OPERATION,handler:()=>!0};var W=Object.defineProperty,J=Object.getOwnPropertyDescriptor,Y=(o,i,e,t)=>{for(var n=t>1?void 0:t?J(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&W(i,e,n),n},j=(o,i)=>(e,t)=>i(e,t,o);exports.DocSelectionManagerService=class extends c.RxDisposable{constructor(e,t){super();d(this,"_currentSelection",null);d(this,"_textSelectionInfo",new Map);d(this,"_textSelection$",new p.Subject);d(this,"textSelection$",this._textSelection$.asObservable());d(this,"_refreshSelection$",new p.BehaviorSubject(null));d(this,"refreshSelection$",this._refreshSelection$.asObservable());this._commandService=e,this._univerInstanceService=t,this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_DOC).pipe(p.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)}__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,a;const t=(r=this.getTextRanges(e))!=null?r:[],n=(a=this.getRectRanges(e))!=null?a:[];return[...t,...n].filter(l=>l.startOffset!=null&&l.endOffset!=null).sort((l,u)=>l.startOffset>u.startOffset?1:l.startOffset<u.startOffset?-1:0)}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(n=>n.isActive)}getActiveRectRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{rectRanges:t}=e;return t.find(n=>n.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:"",segmentPage:-1,isEditing:t,style:T.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,s){if(t==null)return;const{unitId:r,subUnitId:a}=t;this._refreshSelection$.next({unitId:r,subUnitId:a,docRanges:e,isEditing:n,options:s})}__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:a,style:l,textRanges:u,rectRanges:g,isEditing:S}=n,f=[...u,...g].filter(_=>_.startOffset!=null&&_.endOffset!=null).sort((_,I)=>_.startOffset>I.startOffset?1:_.startOffset<I.startOffset?-1:0);this._commandService.executeCommand(b.id,{unitId:s,subUnitId:r,segmentId:a,style:l,isEditing:S,ranges:f})}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:a,subUnitId:l}=e;this._refreshSelection$.next({unitId:a,subUnitId:l,docRanges:r,isEditing:!1})}_replaceByParam(e){const{unitId:t,subUnitId:n,...s}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,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,new Map);const r=this._textSelectionInfo.get(t);r.has(n)?r.get(n).textRanges.push(...e.textRanges):r.set(n,{...s})}};exports.DocSelectionManagerService=Y([j(0,c.ICommandService),j(1,c.IUniverInstanceService)],exports.DocSelectionManagerService);var q=Object.defineProperty,K=Object.getOwnPropertyDescriptor,H=(o,i,e,t)=>{for(var n=t>1?void 0:t?K(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&q(i,e,n),n},V=(o,i)=>(e,t)=>i(e,t,o);exports.DocSkeletonManagerService=class extends c.RxDisposable{constructor(e,t,n){super();d(this,"_skeleton");d(this,"_docViewModel");d(this,"_currentSkeleton$",new p.BehaviorSubject(null));d(this,"currentSkeleton$",this._currentSkeleton$.asObservable());d(this,"_currentSkeletonBefore$",new p.BehaviorSubject(null));d(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());d(this,"_currentViewModel$",new p.BehaviorSubject(null));d(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=e,this._localeService=t,this._univerInstanceService=n,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_DOC).pipe(p.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&&c.isInternalEditorID(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 T.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new T.DocumentViewModel(e)}};exports.DocSkeletonManagerService=H([V(1,c.Inject(c.LocaleService)),V(2,c.IUniverInstanceService)],exports.DocSkeletonManagerService);class P extends c.RxDisposable{constructor(){super();d(this,"_docStateChangeParams$",new p.BehaviorSubject(null));d(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const A="doc.mutation.rich-text-editing",F={id:A,type:c.CommandType.MUTATION,handler:(o,i)=>{var $,B;const{unitId:e,segmentId:t="",actions:n,textRanges:s,prevTextRanges:r,trigger:a,noHistory:l,isCompositionEnd:u,noNeedSetTextRange:g,debounce:S,isEditing:f=!0,isSync:_,syncer:I}=i,m=o.get(c.IUniverInstanceService),v=o.get(T.IRenderManagerService),R=o.get(P),h=m.getUniverDocInstance(e),O=($=v.getRenderById(e))==null?void 0:$.with(exports.DocSkeletonManagerService).getViewModel();if(h==null||O==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const D=o.get(exports.DocSelectionManagerService),y=(B=D.getDocRanges())!=null?B:[],L=!!h.getSnapshot().disabled;if(c.JSONX.isNoop(n)||n&&n.length===0||L)return{unitId:e,actions:[],textRanges:y};const N=c.JSONX.invertWithDoc(n,h.getSnapshot());h.apply(n),O.reset(h),!g&&s&&a!=null&&queueMicrotask(()=>{D.replaceDocRanges(s,{unitId:e,subUnitId:e},f,i.options)});const z={commandId:A,unitId:e,segmentId:t,trigger:a,noHistory:l,debounce:S,redoState:{actions:n,textRanges:s},undoState:{actions:N,textRanges:r!=null?r:y},isCompositionEnd:u,isSync:_,syncer:I};return R.emitStateChangeInfo(z),{unitId:e,actions:N,textRanges:y}}},Q={id:"doc.mutation.rename-doc",type:c.CommandType.MUTATION,handler:(o,i)=>{const t=o.get(c.IUniverInstanceService).getUnit(i.unitId,c.UniverInstanceType.UNIVER_DOC);return t?(t.setName(i.name),!0):!1}},Z="docs.config",ee={};var te=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,ie=(o,i,e,t)=>{for(var n=t>1?void 0:t?ne(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&te(i,e,n),n},w=(o,i)=>(e,t)=>i(e,t,o);let C=class extends c.Disposable{constructor(o,i,e){super(),this._commandService=o,this._textSelectionManagerService=i,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(o,i){var r;const{startOffset:e,endOffset:t,collapsed:n}=i,s=(r=o.getCustomRanges())==null?void 0:r.filter(a=>!a.wholeEntity||e<=a.startIndex&&t>a.endIndex?!1:n?a.startIndex<e&&a.endIndex>=t:c.BuildTextUtils.range.isIntersects(e,t-1,a.startIndex,a.endIndex));if(s!=null&&s.length){let a=e,l=t;return s.forEach(u=>{a=Math.min(u.startIndex,a),l=Math.max(u.endIndex+1,l)}),{...i,startOffset:a,endOffset:l,collapsed:a===l}}return i}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===b.id){const i=o.params,{unitId:e,ranges:t,isEditing:n}=i,s=this._univerInstanceService.getUnit(e);if(!s)return;const r=t.map(a=>this._transformCustomRange(s,a));r.some((a,l)=>t[l]!==a)&&this._textSelectionManagerService.replaceTextRanges(r,n)}}))}};C=ie([w(0,c.ICommandService),w(1,c.Inject(exports.DocSelectionManagerService)),w(2,c.IUniverInstanceService)],C);var se=Object.defineProperty,re=Object.getOwnPropertyDescriptor,oe=(o,i,e,t)=>{for(var n=t>1?void 0:t?re(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&se(i,e,n),n},X=(o,i)=>(e,t)=>i(e,t,o);const ce="DOCS_PLUGIN";var E;exports.UniverDocsPlugin=(E=class extends c.Plugin{constructor(i=ee,e,t){super(),this._config=i,this._injector=e,this._configService=t;const{...n}=this._config;this._configService.setConfig(Z,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[F,Q,b].forEach(i=>{this._injector.get(c.ICommandService).registerCommand(i)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[P],[C]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(C)}},d(E,"pluginName",ce),E);exports.UniverDocsPlugin=oe([X(1,c.Inject(c.Injector)),X(2,c.IConfigService)],exports.UniverDocsPlugin);const ae=c.createInterceptorKey("CUSTOM_RANGE"),le=c.createInterceptorKey("CUSTOM_DECORATION"),M={CUSTOM_RANGE:ae,CUSTOM_DECORATION:le};var ue=Object.defineProperty,de=Object.getOwnPropertyDescriptor,ge=(o,i,e,t)=>{for(var n=t>1?void 0:t?de(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ue(i,e,n),n},_e=(o,i)=>(e,t)=>i(e,t,o);exports.DocInterceptorService=class extends c.Disposable{constructor(e,t){super();d(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=t;const n=this._docSkeletonManagerService.getViewModel(),s=n.getDataModel().getUnitId();if(s===c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||s===c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(n)),this.disposeWithMe(this.intercept(M.CUSTOM_RANGE,{priority:-1,handler:(a,l,u)=>u(a)}));let r=new c.DisposableCollection;n.segmentViewModels$.subscribe(a=>{r.dispose(),r=new c.DisposableCollection,a.forEach(l=>{r.add(this.interceptDocumentViewModel(l))})}),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,a)=>{var l,u;return((l=a.priority)!=null?l:0)-((u=r.priority)!=null?u:0)})),this.disposeWithMe(c.toDisposable(()=>c.remove(this._interceptorsByName.get(n),t)))}fetchThroughInterceptors(e){const t=e,n=this._interceptorsByName.get(t);return c.composeInterceptors(n||[])}interceptDocumentViewModel(e){const t=new c.DisposableCollection;return t.add(e.registerCustomRangeInterceptor({getCustomRange:n=>{var s;return this.fetchThroughInterceptors(M.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(M.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(s=e.getDataModel().getCustomDecorations())!=null?s:[]})}})),t}};exports.DocInterceptorService=ge([_e(1,c.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);function U(o,i=""){if(!i)return["body"];const{headers:e,footers:t}=o.getSnapshot();if(e==null&&t==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[i])!=null)return["headers",i,"body"];if((t==null?void 0:t[i])!=null)return["footers",i,"body"];throw new Error("Segment id not found in headers or footers")}function he(o,i,e){const{unitId:t,segmentId:n}=i,r=o.get(c.IUniverInstanceService).getUnit(t);if(!r)return!1;const a={id:x.RichTextEditingMutation.id,params:{unitId:i.unitId,actions:[],textRanges:void 0}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.add({...i,body:e});if(!u)return!1;const g=U(r,n);return a.params.actions=l.editOp(u.serialize(),g),a}function Se(o,i){var D;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:r,selection:a}=i,l=o.get(x.DocSelectionManagerService),u=o.get(c.IUniverInstanceService),g=a!=null?a:(D=l.getTextRanges({unitId:r,subUnitId:r}))==null?void 0:D[0],S=g==null?void 0:g.segmentId;if(!g)return!1;const f=u.getUnit(r,c.UniverInstanceType.UNIVER_DOC);if(!f)return!1;const _=f.getSelfOrHeaderFooterModel(g.segmentId).getBody();if(!_)return!1;const{startOffset:I,endOffset:m}=c.BuildTextUtils.selection.normalizeSelection(g),v=c.BuildTextUtils.customRange.add({range:{startOffset:I,endOffset:m,collapsed:I===m},rangeId:e,rangeType:t,segmentId:S,wholeEntity:n,properties:s,body:_});if(!v)return!1;const R=c.JSONX.getInstance(),h={id:x.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:v.selections},textX:v},O=U(f,S);return h.params.actions=R.editOp(v.serialize(),O),h}function fe(o,i){const{unitId:e,segmentId:t,insert:n}=i,r=o.get(c.IUniverInstanceService).getUnit(e);if(!r)return!1;const a={id:x.RichTextEditingMutation.id,params:{unitId:i.unitId,actions:[],textRanges:void 0,segmentId:t}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.delete(o,{documentDataModel:r,rangeId:i.rangeId,insert:n,segmentId:t});if(!u)return!1;const g=U(r,t);return a.params.actions=l.editOp(u.serialize(),g),a.params.textRanges=u.selections,a}function Ie(o,i){var m,v,R,h;const{unitId:e,body:t,doc:n}=i;let s=n;if(s||(s=o.get(c.IUniverInstanceService).getUnit(e)),!s)return!1;const r=(m=i.selection)==null?void 0:m.segmentId,a=(v=s.getSelfOrHeaderFooterModel(r))==null?void 0:v.getBody();if(!a)return!1;const l=o.get(x.DocSelectionManagerService),u=(R=i.selection)!=null?R:l.getActiveTextRange();if(!u||!a)return!1;const g=(h=i.textRanges)!=null?h:[{startOffset:u.startOffset+t.dataStream.length,endOffset:u.startOffset+t.dataStream.length,collapsed:!0,segmentId:r}],S=c.BuildTextUtils.selection.replace({selection:u,body:t,doc:s});if(!S)return!1;const f={id:x.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:g,debounce:!0,segmentId:r},textX:S},_=c.JSONX.getInstance(),I=U(s,r);return f.params.actions=_.editOp(S.serialize(),I),f}exports.DOC_INTERCEPTOR_POINT=M;exports.DocStateEmitService=P;exports.RichTextEditingMutation=F;exports.SetTextSelectionsOperation=b;exports.addCustomRangeBySelectionFactory=Se;exports.addCustomRangeFactory=he;exports.deleteCustomRangeFactory=fe;exports.replaceSelectionFactory=Ie;
package/lib/es/index.js CHANGED
@@ -1,97 +1,96 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { CommandType, RxDisposable, UniverInstanceType, ICommandService, IUniverInstanceService, Inject, LocaleService, isInternalEditorID, JSONX, Disposable, BuildTextUtils, Injector, Plugin, IConfigService, createInterceptorKey, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DisposableCollection, toDisposable, remove, composeInterceptors } from "@univerjs/core";
6
- import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE, DocumentSkeleton, DocumentViewModel, IRenderManagerService } from "@univerjs/engine-render";
7
- import { Subject, BehaviorSubject, takeUntil } from "rxjs";
8
- import { RichTextEditingMutation as RichTextEditingMutation$1, DocSelectionManagerService as DocSelectionManagerService$1 } from "@univerjs/docs";
9
- const SetTextSelectionsOperation = {
1
+ var ie = Object.defineProperty;
2
+ var re = (i, e, t) => e in i ? ie(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var u = (i, e, t) => re(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import { CommandType as j, RxDisposable as A, UniverInstanceType as w, ICommandService as L, IUniverInstanceService as p, Inject as $, LocaleService as oe, isInternalEditorID as ce, JSONX as R, Disposable as J, BuildTextUtils as O, Injector as ae, Plugin as le, IConfigService as ue, createInterceptorKey as Q, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as de, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as ge, DisposableCollection as P, toDisposable as _e, remove as he, composeInterceptors as fe } from "@univerjs/core";
5
+ import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as Se, DocumentSkeleton as pe, DocumentViewModel as Ie, IRenderManagerService as me } from "@univerjs/engine-render";
6
+ import { Subject as ve, BehaviorSubject as C, takeUntil as Z } from "rxjs";
7
+ import { RichTextEditingMutation as y, DocSelectionManagerService as ee } from "@univerjs/docs";
8
+ const X = {
10
9
  id: "doc.operation.set-selections",
11
- type: CommandType.OPERATION,
12
- handler: /* @__PURE__ */ __name(() => !0, "handler")
10
+ type: j.OPERATION,
11
+ handler: () => !0
13
12
  };
14
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
15
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
16
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
17
- return kind && result && __defProp$4(target, key, result), result;
18
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a;
19
- let DocSelectionManagerService = (_a = class extends RxDisposable {
20
- constructor(_commandService, _univerInstanceService) {
13
+ var Re = Object.defineProperty, Oe = Object.getOwnPropertyDescriptor, xe = (i, e, t, n) => {
14
+ for (var s = n > 1 ? void 0 : n ? Oe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
15
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
16
+ return n && s && Re(e, t, s), s;
17
+ }, W = (i, e) => (t, n) => e(t, n, i);
18
+ let D = class extends A {
19
+ constructor(e, t) {
21
20
  super();
22
- __publicField(this, "_currentSelection", null);
23
- __publicField(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
24
- __publicField(this, "_textSelection$", new Subject());
25
- __publicField(this, "textSelection$", this._textSelection$.asObservable());
26
- __publicField(this, "_refreshSelection$", new BehaviorSubject(null));
27
- __publicField(this, "refreshSelection$", this._refreshSelection$.asObservable());
28
- this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._listenCurrentUnit();
21
+ u(this, "_currentSelection", null);
22
+ u(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
23
+ u(this, "_textSelection$", new ve());
24
+ u(this, "textSelection$", this._textSelection$.asObservable());
25
+ u(this, "_refreshSelection$", new C(null));
26
+ u(this, "refreshSelection$", this._refreshSelection$.asObservable());
27
+ this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
29
28
  }
30
29
  _listenCurrentUnit() {
31
- this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
32
- if (documentModel == null)
30
+ this._univerInstanceService.getCurrentTypeOfUnit$(w.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((e) => {
31
+ if (e == null)
33
32
  return;
34
- const unitId = documentModel.getUnitId();
33
+ const t = e.getUnitId();
35
34
  this._setCurrentSelectionNotRefresh({
36
- unitId,
37
- subUnitId: unitId
35
+ unitId: t,
36
+ subUnitId: t
38
37
  });
39
38
  });
40
39
  }
41
40
  __getCurrentSelection() {
42
41
  return this._currentSelection;
43
42
  }
44
- getSelectionInfo(params = this._currentSelection) {
45
- return this._getTextRanges(params);
43
+ getSelectionInfo(e = this._currentSelection) {
44
+ return this._getTextRanges(e);
46
45
  }
47
- refreshSelection(params = this._currentSelection) {
48
- params != null && this._refresh(params);
46
+ refreshSelection(e = this._currentSelection) {
47
+ e != null && this._refresh(e);
49
48
  }
50
49
  // **Only used in test case** because this does not go through the render layer.
51
- __TEST_ONLY_setCurrentSelection(param) {
52
- this._currentSelection = param, this._refresh(param);
50
+ __TEST_ONLY_setCurrentSelection(e) {
51
+ this._currentSelection = e, this._refresh(e);
53
52
  }
54
- getTextRanges(params = this._currentSelection) {
55
- var _a6;
56
- return (_a6 = this._getTextRanges(params)) == null ? void 0 : _a6.textRanges;
53
+ getTextRanges(e = this._currentSelection) {
54
+ var t;
55
+ return (t = this._getTextRanges(e)) == null ? void 0 : t.textRanges;
57
56
  }
58
- getRectRanges(params = this._currentSelection) {
59
- var _a6;
60
- return (_a6 = this._getTextRanges(params)) == null ? void 0 : _a6.rectRanges;
57
+ getRectRanges(e = this._currentSelection) {
58
+ var t;
59
+ return (t = this._getTextRanges(e)) == null ? void 0 : t.rectRanges;
61
60
  }
62
- getDocRanges(params = this._currentSelection) {
63
- var _a6, _b;
64
- const textRanges = (_a6 = this.getTextRanges(params)) != null ? _a6 : [], rectRanges = (_b = this.getRectRanges(params)) != null ? _b : [];
65
- return [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0);
61
+ getDocRanges(e = this._currentSelection) {
62
+ var r, o;
63
+ const t = (r = this.getTextRanges(e)) != null ? r : [], n = (o = this.getRectRanges(e)) != null ? o : [];
64
+ 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);
66
65
  }
67
66
  getActiveTextRange() {
68
- const selectionInfo = this._getTextRanges(this._currentSelection);
69
- if (selectionInfo == null)
67
+ const e = this._getTextRanges(this._currentSelection);
68
+ if (e == null)
70
69
  return;
71
- const { textRanges } = selectionInfo;
72
- return textRanges.find((textRange) => textRange.isActive);
70
+ const { textRanges: t } = e;
71
+ return t.find((n) => n.isActive);
73
72
  }
74
73
  /**
75
74
  *
76
75
  * @deprecated
77
76
  */
78
77
  getActiveRectRange() {
79
- const selectionInfo = this._getTextRanges(this._currentSelection);
80
- if (selectionInfo == null)
78
+ const e = this._getTextRanges(this._currentSelection);
79
+ if (e == null)
81
80
  return;
82
- const { rectRanges } = selectionInfo;
83
- return rectRanges.find((rectRange) => rectRange.isActive);
81
+ const { rectRanges: t } = e;
82
+ return t.find((n) => n.isActive);
84
83
  }
85
84
  // **Only used in test case** because this does not go through the render layer.
86
- __TEST_ONLY_add(textRanges, isEditing = !0) {
85
+ __TEST_ONLY_add(e, t = !0) {
87
86
  this._currentSelection != null && this._addByParam({
88
87
  ...this._currentSelection,
89
- textRanges,
88
+ textRanges: e,
90
89
  rectRanges: [],
91
90
  segmentId: "",
92
91
  segmentPage: -1,
93
- isEditing,
94
- style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE
92
+ isEditing: t,
93
+ style: Se
95
94
  // mock style.
96
95
  });
97
96
  }
@@ -99,104 +98,104 @@ let DocSelectionManagerService = (_a = class extends RxDisposable {
99
98
  /**
100
99
  * @deprecated pls use replaceDocRanges.
101
100
  */
102
- replaceTextRanges(docRanges, isEditing = !0, options) {
101
+ replaceTextRanges(e, t = !0, n) {
103
102
  return this.replaceDocRanges(
104
- docRanges,
103
+ e,
105
104
  this._currentSelection,
106
- isEditing,
107
- options
105
+ t,
106
+ n
108
107
  );
109
108
  }
110
- replaceDocRanges(docRanges, params = this._currentSelection, isEditing = !0, options) {
111
- if (params == null)
109
+ replaceDocRanges(e, t = this._currentSelection, n = !0, s) {
110
+ if (t == null)
112
111
  return;
113
- const { unitId, subUnitId } = params;
112
+ const { unitId: r, subUnitId: o } = t;
114
113
  this._refreshSelection$.next({
115
- unitId,
116
- subUnitId,
117
- docRanges,
118
- isEditing,
119
- options
114
+ unitId: r,
115
+ subUnitId: o,
116
+ docRanges: e,
117
+ isEditing: n,
118
+ options: s
120
119
  });
121
120
  }
122
121
  // Only use in doc-selection-render.controller.ts
123
- __replaceTextRangesWithNoRefresh(textSelectionInfo, search) {
122
+ __replaceTextRangesWithNoRefresh(e, t) {
124
123
  if (this._currentSelection == null)
125
124
  return;
126
- const params = {
127
- ...textSelectionInfo,
128
- ...search
125
+ const n = {
126
+ ...e,
127
+ ...t
129
128
  };
130
- this._replaceByParam(params), this._textSelection$.next(params);
131
- const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params, ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0);
132
- this._commandService.executeCommand(SetTextSelectionsOperation.id, {
133
- unitId,
134
- subUnitId,
135
- segmentId,
136
- style,
137
- isEditing,
138
- ranges
129
+ this._replaceByParam(n), this._textSelection$.next(n);
130
+ const { unitId: s, subUnitId: r, segmentId: o, style: c, textRanges: a, rectRanges: l, isEditing: d } = n, h = [...a, ...l].filter((g) => g.startOffset != null && g.endOffset != null).sort((g, f) => g.startOffset > f.startOffset ? 1 : g.startOffset < f.startOffset ? -1 : 0);
131
+ this._commandService.executeCommand(X.id, {
132
+ unitId: s,
133
+ subUnitId: r,
134
+ segmentId: o,
135
+ style: c,
136
+ isEditing: d,
137
+ ranges: h
139
138
  });
140
139
  }
141
140
  dispose() {
142
141
  this._textSelection$.complete();
143
142
  }
144
- _setCurrentSelectionNotRefresh(param) {
145
- this._currentSelection = param;
143
+ _setCurrentSelectionNotRefresh(e) {
144
+ this._currentSelection = e;
146
145
  }
147
- _getTextRanges(param) {
148
- var _a6;
149
- if (param == null)
146
+ _getTextRanges(e) {
147
+ var s;
148
+ if (e == null)
150
149
  return;
151
- const { unitId, subUnitId = "" } = param;
152
- return (_a6 = this._textSelectionInfo.get(unitId)) == null ? void 0 : _a6.get(subUnitId);
150
+ const { unitId: t, subUnitId: n = "" } = e;
151
+ return (s = this._textSelectionInfo.get(t)) == null ? void 0 : s.get(n);
153
152
  }
154
- _refresh(param) {
155
- const allTextSelectionInfo = this._getTextRanges(param);
156
- if (allTextSelectionInfo == null)
153
+ _refresh(e) {
154
+ const t = this._getTextRanges(e);
155
+ if (t == null)
157
156
  return;
158
- const { textRanges, rectRanges } = allTextSelectionInfo, docRanges = [...textRanges, ...rectRanges], { unitId, subUnitId } = param;
157
+ const { textRanges: n, rectRanges: s } = t, r = [...n, ...s], { unitId: o, subUnitId: c } = e;
159
158
  this._refreshSelection$.next({
160
- unitId,
161
- subUnitId,
162
- docRanges,
159
+ unitId: o,
160
+ subUnitId: c,
161
+ docRanges: r,
163
162
  isEditing: !1
164
163
  });
165
164
  }
166
- _replaceByParam(insertParam) {
167
- const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
168
- this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(unitId).set(subUnitId, { ...selectionInsertParam });
169
- }
170
- _addByParam(insertParam) {
171
- const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
172
- this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map());
173
- const unitTextRange = this._textSelectionInfo.get(unitId);
174
- unitTextRange.has(subUnitId) ? unitTextRange.get(subUnitId).textRanges.push(...insertParam.textRanges) : unitTextRange.set(subUnitId, { ...selectionInsertParam });
175
- }
176
- }, __name(_a, "DocSelectionManagerService"), _a);
177
- DocSelectionManagerService = __decorateClass$4([
178
- __decorateParam$4(0, ICommandService),
179
- __decorateParam$4(1, IUniverInstanceService)
180
- ], DocSelectionManagerService);
181
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
182
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
183
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
184
- return kind && result && __defProp$3(target, key, result), result;
185
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a2;
186
- let DocSkeletonManagerService = (_a2 = class extends RxDisposable {
187
- constructor(_context, _localeService, _univerInstanceService) {
165
+ _replaceByParam(e) {
166
+ const { unitId: t, subUnitId: n, ...s } = e;
167
+ this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, { ...s });
168
+ }
169
+ _addByParam(e) {
170
+ const { unitId: t, subUnitId: n, ...s } = e;
171
+ this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map());
172
+ const r = this._textSelectionInfo.get(t);
173
+ r.has(n) ? r.get(n).textRanges.push(...e.textRanges) : r.set(n, { ...s });
174
+ }
175
+ };
176
+ D = xe([
177
+ W(0, L),
178
+ W(1, p)
179
+ ], D);
180
+ var Me = Object.defineProperty, Ce = Object.getOwnPropertyDescriptor, De = (i, e, t, n) => {
181
+ for (var s = n > 1 ? void 0 : n ? Ce(e, t) : e, r = i.length - 1, o; r >= 0; r--)
182
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
183
+ return n && s && Me(e, t, s), s;
184
+ }, Y = (i, e) => (t, n) => e(t, n, i);
185
+ let T = class extends A {
186
+ constructor(e, t, n) {
188
187
  super();
189
- __publicField(this, "_skeleton");
190
- __publicField(this, "_docViewModel");
191
- __publicField(this, "_currentSkeleton$", new BehaviorSubject(null));
192
- __publicField(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
188
+ u(this, "_skeleton");
189
+ u(this, "_docViewModel");
190
+ u(this, "_currentSkeleton$", new C(null));
191
+ u(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
193
192
  // CurrentSkeletonBefore for pre-triggered logic during registration
194
- __publicField(this, "_currentSkeletonBefore$", new BehaviorSubject(null));
195
- __publicField(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
196
- __publicField(this, "_currentViewModel$", new BehaviorSubject(null));
197
- __publicField(this, "currentViewModel$", this._currentViewModel$.asObservable());
198
- this._context = _context, this._localeService = _localeService, this._univerInstanceService = _univerInstanceService, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
199
- documentModel && documentModel.getUnitId() === this._context.unitId && this._update(documentModel);
193
+ u(this, "_currentSkeletonBefore$", new C(null));
194
+ u(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
195
+ u(this, "_currentViewModel$", new C(null));
196
+ u(this, "currentViewModel$", this._currentViewModel$.asObservable());
197
+ this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(w.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((s) => {
198
+ s && s.getUnitId() === this._context.unitId && this._update(s);
200
199
  });
201
200
  }
202
201
  dispose() {
@@ -209,405 +208,398 @@ let DocSkeletonManagerService = (_a2 = class extends RxDisposable {
209
208
  return this._docViewModel;
210
209
  }
211
210
  _init() {
212
- const documentDataModel = this._context.unit;
213
- this._update(documentDataModel);
211
+ const e = this._context.unit;
212
+ this._update(e);
214
213
  }
215
- _update(documentDataModel) {
216
- const unitId = this._context.unitId;
217
- if (documentDataModel.getBody() == null)
214
+ _update(e) {
215
+ const t = this._context.unitId;
216
+ if (e.getBody() == null)
218
217
  return;
219
- this._docViewModel && isInternalEditorID(unitId) ? (this._docViewModel.reset(documentDataModel), this._context.unit = documentDataModel) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(documentDataModel)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
220
- const skeleton = this._skeleton;
221
- skeleton.calculate(), this._currentSkeletonBefore$.next(skeleton), this._currentSkeleton$.next(skeleton), this._currentViewModel$.next(this._docViewModel);
222
- }
223
- _buildSkeleton(documentViewModel) {
224
- return DocumentSkeleton.create(documentViewModel, this._localeService);
225
- }
226
- _buildDocViewModel(documentDataModel) {
227
- return new DocumentViewModel(documentDataModel);
228
- }
229
- }, __name(_a2, "DocSkeletonManagerService"), _a2);
230
- DocSkeletonManagerService = __decorateClass$3([
231
- __decorateParam$3(1, Inject(LocaleService)),
232
- __decorateParam$3(2, IUniverInstanceService)
233
- ], DocSkeletonManagerService);
234
- const _DocStateEmitService = class _DocStateEmitService extends RxDisposable {
218
+ this._docViewModel && ce(t) ? (this._docViewModel.reset(e), this._context.unit = e) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(e)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
219
+ const n = this._skeleton;
220
+ n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n), this._currentViewModel$.next(this._docViewModel);
221
+ }
222
+ _buildSkeleton(e) {
223
+ return pe.create(e, this._localeService);
224
+ }
225
+ _buildDocViewModel(e) {
226
+ return new Ie(e);
227
+ }
228
+ };
229
+ T = De([
230
+ Y(1, $(oe)),
231
+ Y(2, p)
232
+ ], T);
233
+ class te extends A {
235
234
  constructor() {
236
235
  super();
237
- __publicField(this, "_docStateChangeParams$", new BehaviorSubject(null));
238
- __publicField(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
236
+ u(this, "_docStateChangeParams$", new C(null));
237
+ u(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
239
238
  }
240
- emitStateChangeInfo(params) {
241
- this._docStateChangeParams$.next(params);
239
+ emitStateChangeInfo(t) {
240
+ this._docStateChangeParams$.next(t);
242
241
  }
243
242
  dispose() {
244
243
  super.dispose(), this._docStateChangeParams$.complete();
245
244
  }
246
- };
247
- __name(_DocStateEmitService, "DocStateEmitService");
248
- let DocStateEmitService = _DocStateEmitService;
249
- const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEditingMutation = {
250
- id: RichTextEditingMutationId,
251
- type: CommandType.MUTATION,
245
+ }
246
+ const K = "doc.mutation.rich-text-editing", Te = {
247
+ id: K,
248
+ type: j.MUTATION,
252
249
  // eslint-disable-next-line max-lines-per-function
253
- handler: /* @__PURE__ */ __name((accessor, params) => {
254
- var _a6, _b;
250
+ handler: (i, e) => {
251
+ var G, F;
255
252
  const {
256
- unitId,
257
- segmentId = "",
258
- actions,
259
- textRanges,
260
- prevTextRanges,
261
- trigger,
262
- noHistory,
263
- isCompositionEnd,
264
- noNeedSetTextRange,
265
- debounce,
266
- isEditing = !0,
267
- isSync,
268
- syncer
269
- } = params, univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), docStateEmitService = accessor.get(DocStateEmitService), documentDataModel = univerInstanceService.getUniverDocInstance(unitId), documentViewModel = (_a6 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a6.with(DocSkeletonManagerService).getViewModel();
270
- if (documentDataModel == null || documentViewModel == null)
271
- throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
272
- const docSelectionManagerService = accessor.get(DocSelectionManagerService), docRanges = (_b = docSelectionManagerService.getDocRanges()) != null ? _b : [], disabled = !!documentDataModel.getSnapshot().disabled;
273
- if (JSONX.isNoop(actions) || actions && actions.length === 0 || disabled)
253
+ unitId: t,
254
+ segmentId: n = "",
255
+ actions: s,
256
+ textRanges: r,
257
+ prevTextRanges: o,
258
+ trigger: c,
259
+ noHistory: a,
260
+ isCompositionEnd: l,
261
+ noNeedSetTextRange: d,
262
+ debounce: h,
263
+ isEditing: g = !0,
264
+ isSync: f,
265
+ syncer: m
266
+ } = e, I = i.get(p), S = i.get(me), v = i.get(te), _ = I.getUniverDocInstance(t), x = (G = S.getRenderById(t)) == null ? void 0 : G.with(T).getViewModel();
267
+ if (_ == null || x == null)
268
+ throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
269
+ const M = i.get(D), E = (F = M.getDocRanges()) != null ? F : [], ne = !!_.getSnapshot().disabled;
270
+ if (R.isNoop(s) || s && s.length === 0 || ne)
274
271
  return {
275
- unitId,
272
+ unitId: t,
276
273
  actions: [],
277
- textRanges: docRanges
274
+ textRanges: E
278
275
  };
279
- const undoActions = JSONX.invertWithDoc(actions, documentDataModel.getSnapshot());
280
- documentDataModel.apply(actions), documentViewModel.reset(documentDataModel), !noNeedSetTextRange && textRanges && trigger != null && queueMicrotask(() => {
281
- docSelectionManagerService.replaceDocRanges(textRanges, { unitId, subUnitId: unitId }, isEditing, params.options);
276
+ const z = R.invertWithDoc(s, _.getSnapshot());
277
+ _.apply(s), x.reset(_), !d && r && c != null && queueMicrotask(() => {
278
+ M.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
282
279
  });
283
- const changeState = {
284
- commandId: RichTextEditingMutationId,
285
- unitId,
286
- segmentId,
287
- trigger,
288
- noHistory,
289
- debounce,
280
+ const se = {
281
+ commandId: K,
282
+ unitId: t,
283
+ segmentId: n,
284
+ trigger: c,
285
+ noHistory: a,
286
+ debounce: h,
290
287
  redoState: {
291
- actions,
292
- textRanges
288
+ actions: s,
289
+ textRanges: r
293
290
  },
294
291
  undoState: {
295
- actions: undoActions,
296
- textRanges: prevTextRanges != null ? prevTextRanges : docRanges
292
+ actions: z,
293
+ textRanges: o != null ? o : E
297
294
  },
298
- isCompositionEnd,
299
- isSync,
300
- syncer
295
+ isCompositionEnd: l,
296
+ isSync: f,
297
+ syncer: m
301
298
  };
302
- return docStateEmitService.emitStateChangeInfo(changeState), {
303
- unitId,
304
- actions: undoActions,
305
- textRanges: docRanges
299
+ return v.emitStateChangeInfo(se), {
300
+ unitId: t,
301
+ actions: z,
302
+ textRanges: E
306
303
  };
307
- }, "handler")
308
- }, DocsRenameMutation = {
304
+ }
305
+ }, be = {
309
306
  id: "doc.mutation.rename-doc",
310
- type: CommandType.MUTATION,
311
- handler: /* @__PURE__ */ __name((accessor, params) => {
312
- const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
313
- return doc ? (doc.setName(params.name), !0) : !1;
314
- }, "handler")
315
- }, PLUGIN_CONFIG_KEY = "docs.config", defaultPluginConfig = {};
316
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
317
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
318
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
319
- return kind && result && __defProp$2(target, key, result), result;
320
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
321
- let DocCustomRangeController = (_a3 = class extends Disposable {
322
- constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
323
- super(), this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._initSelectionChange();
324
- }
325
- _transformCustomRange(doc, selection) {
326
- var _a6;
327
- const { startOffset, endOffset, collapsed } = selection, customRanges = (_a6 = doc.getCustomRanges()) == null ? void 0 : _a6.filter((range) => !range.wholeEntity || startOffset <= range.startIndex && endOffset > range.endIndex ? !1 : collapsed ? range.startIndex < startOffset && range.endIndex >= endOffset : BuildTextUtils.range.isIntersects(startOffset, endOffset - 1, range.startIndex, range.endIndex));
328
- if (customRanges != null && customRanges.length) {
329
- let start = startOffset, end = endOffset;
330
- return customRanges.forEach((range) => {
331
- start = Math.min(range.startIndex, start), end = Math.max(range.endIndex + 1, end);
307
+ type: j.MUTATION,
308
+ handler: (i, e) => {
309
+ const n = i.get(p).getUnit(e.unitId, w.UNIVER_DOC);
310
+ return n ? (n.setName(e.name), !0) : !1;
311
+ }
312
+ }, we = "docs.config", $e = {};
313
+ var ye = Object.defineProperty, Ue = Object.getOwnPropertyDescriptor, Ee = (i, e, t, n) => {
314
+ for (var s = n > 1 ? void 0 : n ? Ue(e, t) : e, r = i.length - 1, o; r >= 0; r--)
315
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
316
+ return n && s && ye(e, t, s), s;
317
+ }, N = (i, e) => (t, n) => e(t, n, i);
318
+ let b = class extends J {
319
+ constructor(i, e, t) {
320
+ super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
321
+ }
322
+ _transformCustomRange(i, e) {
323
+ var o;
324
+ 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 ? !1 : s ? c.startIndex < t && c.endIndex >= n : O.range.isIntersects(t, n - 1, c.startIndex, c.endIndex));
325
+ if (r != null && r.length) {
326
+ let c = t, a = n;
327
+ return r.forEach((l) => {
328
+ c = Math.min(l.startIndex, c), a = Math.max(l.endIndex + 1, a);
332
329
  }), {
333
- ...selection,
334
- startOffset: start,
335
- endOffset: end,
336
- collapsed: start === end
330
+ ...e,
331
+ startOffset: c,
332
+ endOffset: a,
333
+ collapsed: c === a
337
334
  };
338
335
  }
339
- return selection;
336
+ return e;
340
337
  }
341
338
  _initSelectionChange() {
342
- this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
343
- if (commandInfo.id === SetTextSelectionsOperation.id) {
344
- const params = commandInfo.params, { unitId, ranges, isEditing } = params, doc = this._univerInstanceService.getUnit(unitId);
345
- if (!doc)
339
+ this.disposeWithMe(this._commandService.onCommandExecuted((i) => {
340
+ if (i.id === X.id) {
341
+ const e = i.params, { unitId: t, ranges: n, isEditing: s } = e, r = this._univerInstanceService.getUnit(t);
342
+ if (!r)
346
343
  return;
347
- const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range));
348
- transformedRanges.some((range, i) => ranges[i] !== range) && this._textSelectionManagerService.replaceTextRanges(transformedRanges, isEditing);
344
+ const o = n.map((c) => this._transformCustomRange(r, c));
345
+ o.some((c, a) => n[a] !== c) && this._textSelectionManagerService.replaceTextRanges(o, s);
349
346
  }
350
347
  }));
351
348
  }
352
- }, __name(_a3, "DocCustomRangeController"), _a3);
353
- DocCustomRangeController = __decorateClass$2([
354
- __decorateParam$2(0, ICommandService),
355
- __decorateParam$2(1, Inject(DocSelectionManagerService)),
356
- __decorateParam$2(2, IUniverInstanceService)
357
- ], DocCustomRangeController);
358
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
359
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
360
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
361
- return kind && result && __defProp$1(target, key, result), result;
362
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
363
- const PLUGIN_NAME = "DOCS_PLUGIN";
364
- var _a4;
365
- let UniverDocsPlugin = (_a4 = class extends Plugin {
349
+ };
350
+ b = Ee([
351
+ N(0, L),
352
+ N(1, $(D)),
353
+ N(2, p)
354
+ ], b);
355
+ var Pe = Object.defineProperty, Ne = Object.getOwnPropertyDescriptor, Ve = (i, e, t, n) => {
356
+ for (var s = n > 1 ? void 0 : n ? Ne(e, t) : e, r = i.length - 1, o; r >= 0; r--)
357
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
358
+ return n && s && Pe(e, t, s), s;
359
+ }, H = (i, e) => (t, n) => e(t, n, i);
360
+ const Be = "DOCS_PLUGIN";
361
+ var B;
362
+ let k = (B = class extends le {
366
363
  // static override type = UniverInstanceType.UNIVER_DOC;
367
- constructor(_config = defaultPluginConfig, _injector, _configService) {
368
- super(), this._config = _config, this._injector = _injector, this._configService = _configService;
369
- const { ...rest } = this._config;
370
- this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
364
+ constructor(i = $e, e, t) {
365
+ super(), this._config = i, this._injector = e, this._configService = t;
366
+ const { ...n } = this._config;
367
+ this._configService.setConfig(we, n);
371
368
  }
372
369
  onStarting() {
373
370
  this._initializeDependencies(), this._initializeCommands();
374
371
  }
375
372
  _initializeCommands() {
376
373
  [
377
- RichTextEditingMutation,
378
- DocsRenameMutation,
379
- SetTextSelectionsOperation
380
- ].forEach((command) => {
381
- this._injector.get(ICommandService).registerCommand(command);
374
+ Te,
375
+ be,
376
+ X
377
+ ].forEach((i) => {
378
+ this._injector.get(L).registerCommand(i);
382
379
  });
383
380
  }
384
381
  _initializeDependencies() {
385
382
  [
386
- [DocSelectionManagerService],
387
- [DocStateEmitService],
388
- [DocCustomRangeController]
389
- ].forEach((d) => this._injector.add(d));
383
+ [D],
384
+ [te],
385
+ [b]
386
+ ].forEach((i) => this._injector.add(i));
390
387
  }
391
388
  onReady() {
392
- this._injector.get(DocCustomRangeController);
393
- }
394
- }, __name(_a4, "UniverDocsPlugin"), __publicField(_a4, "pluginName", PLUGIN_NAME), _a4);
395
- UniverDocsPlugin = __decorateClass$1([
396
- __decorateParam$1(1, Inject(Injector)),
397
- __decorateParam$1(2, IConfigService)
398
- ], UniverDocsPlugin);
399
- const CUSTOM_RANGE = createInterceptorKey("CUSTOM_RANGE"), CUSTOM_DECORATION = createInterceptorKey("CUSTOM_DECORATION"), DOC_INTERCEPTOR_POINT = {
400
- CUSTOM_RANGE,
401
- CUSTOM_DECORATION
389
+ this._injector.get(b);
390
+ }
391
+ }, u(B, "pluginName", Be), B);
392
+ k = Ve([
393
+ H(1, $(ae)),
394
+ H(2, ue)
395
+ ], k);
396
+ const je = Q("CUSTOM_RANGE"), Ae = Q("CUSTOM_DECORATION"), V = {
397
+ CUSTOM_RANGE: je,
398
+ CUSTOM_DECORATION: Ae
402
399
  };
403
- var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
404
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
405
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
406
- return kind && result && __defProp2(target, key, result), result;
407
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a5;
408
- let DocInterceptorService = (_a5 = class extends Disposable {
409
- constructor(_context, _docSkeletonManagerService) {
400
+ var Le = Object.defineProperty, Xe = Object.getOwnPropertyDescriptor, ze = (i, e, t, n) => {
401
+ for (var s = n > 1 ? void 0 : n ? Xe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
402
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
403
+ return n && s && Le(e, t, s), s;
404
+ }, Ge = (i, e) => (t, n) => e(t, n, i);
405
+ let q = class extends J {
406
+ constructor(e, t) {
410
407
  super();
411
- __publicField(this, "_interceptorsByName", /* @__PURE__ */ new Map());
412
- this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService;
413
- const viewModel = this._docSkeletonManagerService.getViewModel(), unitId = viewModel.getDataModel().getUnitId();
414
- if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)
408
+ u(this, "_interceptorsByName", /* @__PURE__ */ new Map());
409
+ this._context = e, this._docSkeletonManagerService = t;
410
+ const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
411
+ if (s === de || s === ge)
415
412
  return;
416
- this.disposeWithMe(this.interceptDocumentViewModel(viewModel)), this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
413
+ this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(V.CUSTOM_RANGE, {
417
414
  priority: -1,
418
- handler: /* @__PURE__ */ __name((data, pos, next) => next(data), "handler")
415
+ handler: (o, c, a) => a(o)
419
416
  }));
420
- let disposableCollection = new DisposableCollection();
421
- viewModel.segmentViewModels$.subscribe((segmentViewModels) => {
422
- disposableCollection.dispose(), disposableCollection = new DisposableCollection(), segmentViewModels.forEach((segmentViewModel) => {
423
- disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel));
417
+ let r = new P();
418
+ n.segmentViewModels$.subscribe((o) => {
419
+ r.dispose(), r = new P(), o.forEach((c) => {
420
+ r.add(this.interceptDocumentViewModel(c));
424
421
  });
425
- }), this.disposeWithMe(disposableCollection);
426
- }
427
- intercept(name, interceptor) {
428
- const key = name;
429
- this._interceptorsByName.has(key) || this._interceptorsByName.set(key, []);
430
- const interceptors = this._interceptorsByName.get(key);
431
- return interceptors.push(interceptor), this._interceptorsByName.set(
432
- key,
433
- interceptors.sort((a, b) => {
434
- var _a6, _b;
435
- return ((_a6 = b.priority) != null ? _a6 : 0) - ((_b = a.priority) != null ? _b : 0);
422
+ }), this.disposeWithMe(r);
423
+ }
424
+ intercept(e, t) {
425
+ const n = e;
426
+ this._interceptorsByName.has(n) || this._interceptorsByName.set(n, []);
427
+ const s = this._interceptorsByName.get(n);
428
+ return s.push(t), this._interceptorsByName.set(
429
+ n,
430
+ s.sort((r, o) => {
431
+ var c, a;
432
+ return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
436
433
  })
437
- ), this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key), interceptor)));
438
- }
439
- fetchThroughInterceptors(name) {
440
- const key = name, interceptors = this._interceptorsByName.get(key);
441
- return composeInterceptors(interceptors || []);
442
- }
443
- interceptDocumentViewModel(viewModel) {
444
- const disposableCollection = new DisposableCollection();
445
- return disposableCollection.add(viewModel.registerCustomRangeInterceptor({
446
- getCustomRange: /* @__PURE__ */ __name((index) => {
447
- var _a6;
448
- return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(
449
- viewModel.getCustomRangeRaw(index),
434
+ ), this.disposeWithMe(_e(() => he(this._interceptorsByName.get(n), t)));
435
+ }
436
+ fetchThroughInterceptors(e) {
437
+ const t = e, n = this._interceptorsByName.get(t);
438
+ return fe(n || []);
439
+ }
440
+ interceptDocumentViewModel(e) {
441
+ const t = new P();
442
+ return t.add(e.registerCustomRangeInterceptor({
443
+ getCustomRange: (n) => {
444
+ var s;
445
+ return this.fetchThroughInterceptors(V.CUSTOM_RANGE)(
446
+ e.getCustomRangeRaw(n),
450
447
  {
451
- index,
452
- unitId: viewModel.getDataModel().getUnitId(),
453
- customRanges: (_a6 = viewModel.getDataModel().getCustomRanges()) != null ? _a6 : []
448
+ index: n,
449
+ unitId: e.getDataModel().getUnitId(),
450
+ customRanges: (s = e.getDataModel().getCustomRanges()) != null ? s : []
454
451
  }
455
452
  );
456
- }, "getCustomRange"),
457
- getCustomDecoration: /* @__PURE__ */ __name((index) => {
458
- var _a6;
459
- return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(
460
- viewModel.getCustomDecorationRaw(index),
453
+ },
454
+ getCustomDecoration: (n) => {
455
+ var s;
456
+ return this.fetchThroughInterceptors(V.CUSTOM_DECORATION)(
457
+ e.getCustomDecorationRaw(n),
461
458
  {
462
- index,
463
- unitId: viewModel.getDataModel().getUnitId(),
464
- customDecorations: (_a6 = viewModel.getDataModel().getCustomDecorations()) != null ? _a6 : []
459
+ index: n,
460
+ unitId: e.getDataModel().getUnitId(),
461
+ customDecorations: (s = e.getDataModel().getCustomDecorations()) != null ? s : []
465
462
  }
466
463
  );
467
- }, "getCustomDecoration")
468
- })), disposableCollection;
469
- }
470
- }, __name(_a5, "DocInterceptorService"), _a5);
471
- DocInterceptorService = __decorateClass([
472
- __decorateParam(1, Inject(DocSkeletonManagerService))
473
- ], DocInterceptorService);
474
- function getRichTextEditPath(docDataModel, segmentId = "") {
475
- if (!segmentId)
464
+ }
465
+ })), t;
466
+ }
467
+ };
468
+ q = ze([
469
+ Ge(1, $(T))
470
+ ], q);
471
+ function U(i, e = "") {
472
+ if (!e)
476
473
  return ["body"];
477
- const { headers, footers } = docDataModel.getSnapshot();
478
- if (headers == null && footers == null)
474
+ const { headers: t, footers: n } = i.getSnapshot();
475
+ if (t == null && n == null)
479
476
  throw new Error("Document data model must have headers or footers when update by segment id");
480
- if ((headers == null ? void 0 : headers[segmentId]) != null)
481
- return ["headers", segmentId, "body"];
482
- if ((footers == null ? void 0 : footers[segmentId]) != null)
483
- return ["footers", segmentId, "body"];
477
+ if ((t == null ? void 0 : t[e]) != null)
478
+ return ["headers", e, "body"];
479
+ if ((n == null ? void 0 : n[e]) != null)
480
+ return ["footers", e, "body"];
484
481
  throw new Error("Segment id not found in headers or footers");
485
482
  }
486
- __name(getRichTextEditPath, "getRichTextEditPath");
487
- function addCustomRangeFactory(accessor, param, body) {
488
- const { unitId, segmentId } = param, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
489
- if (!documentDataModel)
483
+ function ke(i, e, t) {
484
+ const { unitId: n, segmentId: s } = e, o = i.get(p).getUnit(n);
485
+ if (!o)
490
486
  return !1;
491
- const doMutation = {
492
- id: RichTextEditingMutation$1.id,
487
+ const c = {
488
+ id: y.id,
493
489
  params: {
494
- unitId: param.unitId,
490
+ unitId: e.unitId,
495
491
  actions: [],
496
492
  textRanges: void 0
497
493
  }
498
- }, jsonX = JSONX.getInstance(), textX = BuildTextUtils.customRange.add({ ...param, body });
499
- if (!textX)
494
+ }, a = R.getInstance(), l = O.customRange.add({ ...e, body: t });
495
+ if (!l)
500
496
  return !1;
501
- const path = getRichTextEditPath(documentDataModel, segmentId);
502
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
497
+ const d = U(o, s);
498
+ return c.params.actions = a.editOp(l.serialize(), d), c;
503
499
  }
504
- __name(addCustomRangeFactory, "addCustomRangeFactory");
505
- function addCustomRangeBySelectionFactory(accessor, param) {
506
- var _a6;
507
- const { rangeId, rangeType, wholeEntity, properties, unitId, selection: propSelection } = param, docSelectionManagerService = accessor.get(DocSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), selection = propSelection != null ? propSelection : (_a6 = docSelectionManagerService.getTextRanges({ unitId, subUnitId: unitId })) == null ? void 0 : _a6[0], segmentId = selection == null ? void 0 : selection.segmentId;
508
- if (!selection)
500
+ function qe(i, e) {
501
+ var M;
502
+ const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selection: c } = e, a = i.get(ee), l = i.get(p), d = c != null ? c : (M = a.getTextRanges({ unitId: o, subUnitId: o })) == null ? void 0 : M[0], h = d == null ? void 0 : d.segmentId;
503
+ if (!d)
509
504
  return !1;
510
- const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
511
- if (!documentDataModel)
505
+ const g = l.getUnit(o, w.UNIVER_DOC);
506
+ if (!g)
512
507
  return !1;
513
- const body = documentDataModel.getSelfOrHeaderFooterModel(selection.segmentId).getBody();
514
- if (!body)
508
+ const f = g.getSelfOrHeaderFooterModel(d.segmentId).getBody();
509
+ if (!f)
515
510
  return !1;
516
- const { startOffset, endOffset } = BuildTextUtils.selection.normalizeSelection(selection), textX = BuildTextUtils.customRange.add({
517
- range: { startOffset, endOffset, collapsed: startOffset === endOffset },
518
- rangeId,
519
- rangeType,
520
- segmentId,
521
- wholeEntity,
522
- properties,
523
- body
511
+ const { startOffset: m, endOffset: I } = O.selection.normalizeSelection(d), S = O.customRange.add({
512
+ range: { startOffset: m, endOffset: I, collapsed: m === I },
513
+ rangeId: t,
514
+ rangeType: n,
515
+ segmentId: h,
516
+ wholeEntity: s,
517
+ properties: r,
518
+ body: f
524
519
  });
525
- if (!textX)
520
+ if (!S)
526
521
  return !1;
527
- const jsonX = JSONX.getInstance(), doMutation = {
528
- id: RichTextEditingMutation$1.id,
522
+ const v = R.getInstance(), _ = {
523
+ id: y.id,
529
524
  params: {
530
- unitId,
525
+ unitId: o,
531
526
  actions: [],
532
- textRanges: textX.selections
527
+ textRanges: S.selections
533
528
  },
534
- textX
535
- }, path = getRichTextEditPath(documentDataModel, segmentId);
536
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
529
+ textX: S
530
+ }, x = U(g, h);
531
+ return _.params.actions = v.editOp(S.serialize(), x), _;
537
532
  }
538
- __name(addCustomRangeBySelectionFactory, "addCustomRangeBySelectionFactory");
539
- function deleteCustomRangeFactory(accessor, params) {
540
- const { unitId, segmentId, insert } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
541
- if (!documentDataModel)
533
+ function Je(i, e) {
534
+ const { unitId: t, segmentId: n, insert: s } = e, o = i.get(p).getUnit(t);
535
+ if (!o)
542
536
  return !1;
543
- const doMutation = {
544
- id: RichTextEditingMutation$1.id,
537
+ const c = {
538
+ id: y.id,
545
539
  params: {
546
- unitId: params.unitId,
540
+ unitId: e.unitId,
547
541
  actions: [],
548
542
  textRanges: void 0,
549
- segmentId
543
+ segmentId: n
550
544
  }
551
- }, jsonX = JSONX.getInstance(), textX = BuildTextUtils.customRange.delete(accessor, {
552
- documentDataModel,
553
- rangeId: params.rangeId,
554
- insert,
555
- segmentId
545
+ }, a = R.getInstance(), l = O.customRange.delete(i, {
546
+ documentDataModel: o,
547
+ rangeId: e.rangeId,
548
+ insert: s,
549
+ segmentId: n
556
550
  });
557
- if (!textX)
551
+ if (!l)
558
552
  return !1;
559
- const path = getRichTextEditPath(documentDataModel, segmentId);
560
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation.params.textRanges = textX.selections, doMutation;
553
+ const d = U(o, n);
554
+ return c.params.actions = a.editOp(l.serialize(), d), c.params.textRanges = l.selections, c;
561
555
  }
562
- __name(deleteCustomRangeFactory, "deleteCustomRangeFactory");
563
- function replaceSelectionFactory(accessor, params) {
564
- var _a6, _b, _c, _d;
565
- const { unitId, body: insertBody, doc } = params;
566
- let docDataModel = doc;
567
- if (docDataModel || (docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId)), !docDataModel)
556
+ function Qe(i, e) {
557
+ var I, S, v, _;
558
+ const { unitId: t, body: n, doc: s } = e;
559
+ let r = s;
560
+ if (r || (r = i.get(p).getUnit(t)), !r)
568
561
  return !1;
569
- const segmentId = (_a6 = params.selection) == null ? void 0 : _a6.segmentId, body = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _b.getBody();
570
- if (!body) return !1;
571
- const docSelectionManagerService = accessor.get(DocSelectionManagerService$1), selection = (_c = params.selection) != null ? _c : docSelectionManagerService.getActiveTextRange();
572
- if (!selection || !body)
562
+ const o = (I = e.selection) == null ? void 0 : I.segmentId, c = (S = r.getSelfOrHeaderFooterModel(o)) == null ? void 0 : S.getBody();
563
+ if (!c) return !1;
564
+ const a = i.get(ee), l = (v = e.selection) != null ? v : a.getActiveTextRange();
565
+ if (!l || !c)
573
566
  return !1;
574
- const textRanges = (_d = params.textRanges) != null ? _d : [{
575
- startOffset: selection.startOffset + insertBody.dataStream.length,
576
- endOffset: selection.startOffset + insertBody.dataStream.length,
567
+ const d = (_ = e.textRanges) != null ? _ : [{
568
+ startOffset: l.startOffset + n.dataStream.length,
569
+ endOffset: l.startOffset + n.dataStream.length,
577
570
  collapsed: !0,
578
- segmentId
579
- }], textX = BuildTextUtils.selection.replace({
580
- selection,
581
- body: insertBody,
582
- doc: docDataModel
571
+ segmentId: o
572
+ }], h = O.selection.replace({
573
+ selection: l,
574
+ body: n,
575
+ doc: r
583
576
  });
584
- if (!textX)
577
+ if (!h)
585
578
  return !1;
586
- const doMutation = {
587
- id: RichTextEditingMutation$1.id,
579
+ const g = {
580
+ id: y.id,
588
581
  params: {
589
- unitId,
582
+ unitId: t,
590
583
  actions: [],
591
- textRanges,
584
+ textRanges: d,
592
585
  debounce: !0,
593
- segmentId
586
+ segmentId: o
594
587
  },
595
- textX
596
- }, jsonX = JSONX.getInstance(), path = getRichTextEditPath(docDataModel, segmentId);
597
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
588
+ textX: h
589
+ }, f = R.getInstance(), m = U(r, o);
590
+ return g.params.actions = f.editOp(h.serialize(), m), g;
598
591
  }
599
- __name(replaceSelectionFactory, "replaceSelectionFactory");
600
592
  export {
601
- DOC_INTERCEPTOR_POINT,
602
- DocInterceptorService,
603
- DocSelectionManagerService,
604
- DocSkeletonManagerService,
605
- DocStateEmitService,
606
- RichTextEditingMutation,
607
- SetTextSelectionsOperation,
608
- UniverDocsPlugin,
609
- addCustomRangeBySelectionFactory,
610
- addCustomRangeFactory,
611
- deleteCustomRangeFactory,
612
- replaceSelectionFactory
593
+ V as DOC_INTERCEPTOR_POINT,
594
+ q as DocInterceptorService,
595
+ D as DocSelectionManagerService,
596
+ T as DocSkeletonManagerService,
597
+ te as DocStateEmitService,
598
+ Te as RichTextEditingMutation,
599
+ X as SetTextSelectionsOperation,
600
+ k as UniverDocsPlugin,
601
+ qe as addCustomRangeBySelectionFactory,
602
+ ke as addCustomRangeFactory,
603
+ Je as deleteCustomRangeFactory,
604
+ Qe as replaceSelectionFactory
613
605
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs",
3
- "version": "0.4.2-nightly.202411061606",
3
+ "version": "0.4.2-nightly.202411081606",
4
4
  "private": false,
5
5
  "description": "UniverSheet normal base-docs",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -23,10 +23,12 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "import": "./lib/es/index.js",
26
+ "require": "./lib/cjs/index.js",
26
27
  "types": "./lib/types/index.d.ts"
27
28
  },
28
29
  "./*": {
29
30
  "import": "./lib/es/*",
31
+ "require": "./lib/cjs/*",
30
32
  "types": "./lib/types/index.d.ts"
31
33
  },
32
34
  "./lib/*": "./lib/*"
@@ -47,8 +49,8 @@
47
49
  },
48
50
  "dependencies": {
49
51
  "@vitejs/plugin-react": "4.3.3",
50
- "@univerjs/core": "0.4.2-nightly.202411061606",
51
- "@univerjs/engine-render": "0.4.2-nightly.202411061606"
52
+ "@univerjs/core": "0.4.2-nightly.202411081606",
53
+ "@univerjs/engine-render": "0.4.2-nightly.202411081606"
52
54
  },
53
55
  "devDependencies": {
54
56
  "rxjs": "^7.8.1",
@@ -57,13 +59,15 @@
57
59
  "vitest": "^2.1.4",
58
60
  "@univerjs-infra/shared": "0.4.2"
59
61
  },
60
- "univerSpace": {
62
+ "space": {
61
63
  ".": {
62
64
  "import": "./lib/es/index.js",
65
+ "require": "./lib/cjs/index.js",
63
66
  "types": "./lib/types/index.d.ts"
64
67
  },
65
68
  "./*": {
66
69
  "import": "./lib/es/*",
70
+ "require": "./lib/cjs/*",
67
71
  "types": "./lib/types/index.d.ts"
68
72
  },
69
73
  "./lib/*": "./lib/*"
@@ -73,7 +77,7 @@
73
77
  "test:watch": "vitest",
74
78
  "coverage": "vitest run --coverage",
75
79
  "lint:types": "tsc --noEmit",
76
- "build": "tsc && vite build"
80
+ "build": "tsx build.ts"
77
81
  },
78
82
  "module": "./lib/es/index.js"
79
83
  }