@univerjs/docs 0.4.2-nightly.202411071606 → 0.4.2-nightly.202411091134

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