@univerjs/docs 0.20.1 → 0.21.0-insiders.20260422-d7fcb4d
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.
- package/lib/cjs/index.js +773 -1
- package/lib/es/index.js +741 -1
- package/lib/index.js +741 -1
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,773 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-render`),n=require(`rxjs`);const r={id:`doc.operation.set-selections`,type:e.CommandType.OPERATION,handler:()=>!0};function i(e){"@babel/helpers - typeof";return i=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){return function(n,r){t(n,r,e)}}function l(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let u=class extends e.RxDisposable{constructor(e,t){super(),this._commandService=e,this._univerInstanceService=t,s(this,`_currentSelection`,null),s(this,`_textSelectionInfo`,new Map),s(this,`_textSelection$`,new n.Subject),s(this,`textSelection$`,this._textSelection$.asObservable()),s(this,`_refreshSelection$`,new n.BehaviorSubject(null)),s(this,`refreshSelection$`,this._refreshSelection$.asObservable()),this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_DOC).pipe((0,n.takeUntil)(this.dispose$)).subscribe(e=>{if(e==null)return;let 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 t,n;let r=(t=this.getTextRanges(e))==null?[]:t,i=(n=this.getRectRanges(e))==null?[]:n;return[...r,...i].filter(e=>e.startOffset!=null&&e.endOffset!=null).sort((e,t)=>e.startOffset>t.startOffset?1:e.startOffset<t.startOffset?-1:0)}getActiveTextRange(){let e=this._getTextRanges(this._currentSelection);if(e==null)return;let{textRanges:t}=e;return t.find(e=>e.isActive)}getActiveRectRange(){let e=this._getTextRanges(this._currentSelection);if(e==null)return;let{rectRanges:t}=e;return t.find(e=>e.isActive)}__TEST_ONLY_add(e,n=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:``,segmentPage:-1,isEditing:n,style:t.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,r){if(t==null)return;let{unitId:i,subUnitId:a}=t;this._refreshSelection$.next({unitId:i,subUnitId:a,docRanges:e,isEditing:n,options:r})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;let n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);let{unitId:i,subUnitId:a,segmentId:o,style:s,textRanges:c,rectRanges:l,isEditing:u}=n,d=[...c,...l].filter(e=>e.startOffset!=null&&e.endOffset!=null).sort((e,t)=>e.startOffset>t.startOffset?1:e.startOffset<t.startOffset?-1:0);this._commandService.executeCommand(r.id,{unitId:i,subUnitId:a,segmentId:o,style:s,isEditing:u,ranges:d})}dispose(){this._textSelection$.complete(),this._refreshSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_getTextRanges(e){var t;if(e==null)return;let{unitId:n,subUnitId:r=``}=e;return(t=this._textSelectionInfo.get(n))==null?void 0:t.get(r)}_refresh(e){let t=this._getTextRanges(e);if(t==null)return;let{textRanges:n,rectRanges:r}=t,i=[...n,...r],{unitId:a,subUnitId:o}=e;this._refreshSelection$.next({unitId:a,subUnitId:o,docRanges:i,isEditing:!1})}_replaceByParam(e){let{unitId:t,subUnitId:n,...r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...r})}_addByParam(e){let{unitId:t,subUnitId:n,...r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);let i=this._textSelectionInfo.get(t);i.has(n)?i.get(n).textRanges.push(...e.textRanges):i.set(n,{...r})}};u=l([c(0,e.ICommandService),c(1,e.IUniverInstanceService)],u);let d=class extends e.RxDisposable{constructor(t,r,i){super(),this._context=t,this._localeService=r,this._univerInstanceService=i,s(this,`_skeleton`,void 0),s(this,`_docViewModel`,void 0),s(this,`_currentSkeleton$`,new n.BehaviorSubject(null)),s(this,`currentSkeleton$`,this._currentSkeleton$.asObservable()),s(this,`_currentSkeletonBefore$`,new n.BehaviorSubject(null)),s(this,`currentSkeletonBefore$`,this._currentSkeletonBefore$.asObservable()),s(this,`_currentViewModel$`,new n.BehaviorSubject(null)),s(this,`currentViewModel$`,this._currentViewModel$.asObservable()),this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_DOC).pipe((0,n.takeUntil)(this.dispose$)).subscribe(e=>{e&&e.getUnitId()===this._context.unitId&&this._update(e)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){let e=this._context.unit;this._update(e)}_update(t){let n=this._context.unitId;if(t.getBody()==null)return;this._docViewModel&&(0,e.isInternalEditorID)(n)?(this._docViewModel.reset(t),this._context.unit=t):this._docViewModel||(this._docViewModel=this._buildDocViewModel(t)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));let r=this._skeleton;r.calculate(),this._currentSkeletonBefore$.next(r),this._currentSkeleton$.next(r),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return t.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new t.DocumentViewModel(e)}};d=l([c(1,(0,e.Inject)(e.LocaleService)),c(2,e.IUniverInstanceService)],d);var f=class extends e.RxDisposable{constructor(){super(),s(this,`_docStateChangeParams$`,new n.BehaviorSubject(null)),s(this,`docStateChangeParams$`,this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}};const p=`doc.mutation.rich-text-editing`,m={id:p,type:e.CommandType.MUTATION,handler:(n,r)=>{var i,a;let{unitId:o,segmentId:s=``,actions:c,textRanges:l,prevTextRanges:m,trigger:h,noHistory:g,isCompositionEnd:_,noNeedSetTextRange:v,debounce:y,isEditing:b=!0,isSync:x,syncer:S}=r,C=n.get(e.IUniverInstanceService),w=n.get(t.IRenderManagerService),T=n.get(f),E=C.getUniverDocInstance(o),D=(i=w.getRenderById(o))==null?void 0:i.with(d).getViewModel();if(E==null||D==null)throw Error(`DocumentDataModel or documentViewModel not found for unitId: ${o}`);let O=n.get(u),k=(a=O.getDocRanges())==null?[]:a,A=!!E.getSnapshot().disabled;if(e.JSONX.isNoop(c)||c&&c.length===0||A)return{unitId:o,actions:[],textRanges:k};let j=e.JSONX.invertWithDoc(c,E.getSnapshot());E.apply(c),D.reset(E),!v&&l&&h!=null&&!x&&queueMicrotask(()=>{O.replaceDocRanges(l,{unitId:o,subUnitId:o},b,r.options)});let M={commandId:p,unitId:o,segmentId:s,trigger:h,noHistory:g,debounce:y,redoState:{actions:c,textRanges:l},undoState:{actions:j,textRanges:m==null?k:m},isCompositionEnd:_,isSync:x,syncer:S};return T.emitStateChangeInfo(M),{unitId:o,actions:j,textRanges:k}}};var h=`@univerjs/docs`,g=`0.20.1`;const _={id:`doc.mutation.rename-doc`,type:e.CommandType.MUTATION,handler:(t,n)=>{let r=t.get(e.IUniverInstanceService).getUnit(n.unitId,e.UniverInstanceType.UNIVER_DOC);return r?(r.setName(n.name),!0):!1}},v=`docs.config`;Symbol(v);const y={};let b=class extends e.Disposable{constructor(e,t,n){super(),this._commandService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,this._initSelectionChange()}_transformCustomRange(t,n){var r;let{startOffset:i,endOffset:a,collapsed:o}=n,s=(r=t.getCustomRanges())==null?void 0:r.filter(t=>!t.wholeEntity||i<=t.startIndex&&a>t.endIndex?!1:o?t.startIndex<i&&t.endIndex>=a:e.BuildTextUtils.range.isIntersects(i,a-1,t.startIndex,t.endIndex));if(s!=null&&s.length){let e=i,t=a;return s.forEach(n=>{e=Math.min(n.startIndex,e),t=Math.max(n.endIndex+1,t)}),{...n,startOffset:e,endOffset:t,collapsed:e===t}}return n}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===r.id){let{unitId:t,ranges:n,isEditing:r}=e.params,i=this._univerInstanceService.getUnit(t);if(!i)return;let a=n.map(e=>this._transformCustomRange(i,e));a.some((e,t)=>n[t]!==e)&&this._textSelectionManagerService.replaceTextRanges(a,r)}}))}};b=l([c(0,e.ICommandService),c(1,(0,e.Inject)(u)),c(2,e.IUniverInstanceService)],b);let x=class extends e.Plugin{constructor(t=y,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{...i}=(0,e.merge)({},y,this._config);this._configService.setConfig(v,i)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[m,_,r].forEach(t=>{this._injector.get(e.ICommandService).registerCommand(t)})}_initializeDependencies(){[[u],[f],[b]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(b)}};s(x,`pluginName`,`DOCS_PLUGIN`),s(x,`packageName`,h),s(x,`version`,g),x=l([c(1,(0,e.Inject)(e.Injector)),c(2,e.IConfigService)],x);const S={CUSTOM_RANGE:(0,e.createInterceptorKey)(`CUSTOM_RANGE`),CUSTOM_DECORATION:(0,e.createInterceptorKey)(`CUSTOM_DECORATION`)};let C=class extends e.Disposable{constructor(t,n){super(),this._context=t,this._docSkeletonManagerService=n,s(this,`_interceptorsByName`,new Map);let r=this._docSkeletonManagerService.getViewModel(),i=r.getDataModel().getUnitId();if(i===e.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===e.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(r)),this.disposeWithMe(this.intercept(S.CUSTOM_RANGE,{priority:-1,handler:(e,t,n)=>n(e)}));let a=new e.DisposableCollection;r.segmentViewModels$.subscribe(t=>{a.dispose(),a=new e.DisposableCollection,t.forEach(e=>{a.add(this.interceptDocumentViewModel(e))})}),this.disposeWithMe(a)}intercept(t,n){let r=t;this._interceptorsByName.has(r)||this._interceptorsByName.set(r,[]);let i=this._interceptorsByName.get(r);return i.push(n),this._interceptorsByName.set(r,i.sort((e,t)=>{var n,r;return((n=t.priority)==null?0:n)-((r=e.priority)==null?0:r)})),this.disposeWithMe((0,e.toDisposable)(()=>(0,e.remove)(this._interceptorsByName.get(r),n)))}fetchThroughInterceptors(t){let n=t;return(0,e.composeInterceptors)(this._interceptorsByName.get(n)||[])}interceptDocumentViewModel(t){let n=new e.DisposableCollection;return n.add(t.registerCustomRangeInterceptor({getCustomRange:e=>{var n;return this.fetchThroughInterceptors(S.CUSTOM_RANGE)(t.getCustomRangeRaw(e),{index:e,unitId:t.getDataModel().getUnitId(),customRanges:(n=t.getDataModel().getCustomRanges())==null?[]:n})},getCustomDecoration:e=>{var n;return this.fetchThroughInterceptors(S.CUSTOM_DECORATION)(t.getCustomDecorationRaw(e),{index:e,unitId:t.getDataModel().getUnitId(),customDecorations:(n=t.getDataModel().getCustomDecorations())==null?[]:n})}})),n}};C=l([c(1,(0,e.Inject)(d))],C);function w(e,t=``){if(!t)return[`body`];let{headers:n,footers:r}=e.getSnapshot();if(n==null&&r==null)throw Error(`Document data model must have headers or footers when update by segment id`);if((n==null?void 0:n[t])!=null)return[`headers`,t,`body`];if((r==null?void 0:r[t])!=null)return[`footers`,t,`body`];throw Error(`Segment id not found in headers or footers`)}function T(t,n,r){let{unitId:i,segmentId:a}=n,o=t.get(e.IUniverInstanceService).getUnit(i);if(!o)return!1;let s={id:m.id,params:{unitId:n.unitId,actions:[],textRanges:void 0}},c=e.JSONX.getInstance(),l=e.BuildTextUtils.customRange.add({...n,body:r});if(!l)return!1;let u=w(o,a);return s.params.actions=c.editOp(l.serialize(),u),s}function E(t,n){var r;let{rangeId:i,rangeType:a,wholeEntity:o,properties:s,unitId:c,selections:l}=n,d=t.get(u),f=t.get(e.IUniverInstanceService),p=l==null?d.getTextRanges({unitId:c,subUnitId:c}):l,h=p==null||(r=p[0])==null?void 0:r.segmentId;if(!(p!=null&&p.length))return!1;let g=f.getUnit(c,e.UniverInstanceType.UNIVER_DOC);if(!g)return!1;let _=g.getSelfOrHeaderFooterModel(h).getBody();if(!_)return!1;let v=e.BuildTextUtils.customRange.add({ranges:p,rangeId:i,rangeType:a,segmentId:h,wholeEntity:o,properties:s,body:_});if(!v)return!1;let y=e.JSONX.getInstance(),b={id:m.id,params:{unitId:c,actions:[],textRanges:v.selections,segmentId:h},textX:v},x=w(g,h);return b.params.actions=y.editOp(v.serialize(),x),b}function D(t,n){let{unitId:r,segmentId:i,insert:a}=n,o=t.get(e.IUniverInstanceService).getUnit(r);if(!o)return!1;let s={id:m.id,params:{unitId:n.unitId,actions:[],textRanges:void 0,segmentId:i}},c=e.JSONX.getInstance(),l=e.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:n.rangeId,insert:a,segmentId:i});if(!l)return!1;let u=w(o,i);return s.params.actions=c.editOp(l.serialize(),u),s.params.textRanges=l.selections,s}function O(t,n){var r,i,a,o;let{unitId:s,body:c,doc:l}=n,d=l;if(d||(d=t.get(e.IUniverInstanceService).getUnit(s)),!d)return!1;let f=(r=n.selection)==null?void 0:r.segmentId,p=(i=d.getSelfOrHeaderFooterModel(f))==null?void 0:i.getBody();if(!p)return!1;let h=t.get(u),g=(a=n.selection)==null?h.getActiveTextRange():a;if(!g||!p)return!1;let _=(o=n.textRanges)==null?[{startOffset:g.startOffset+c.dataStream.length,endOffset:g.startOffset+c.dataStream.length,collapsed:!0,segmentId:f}]:o,v=e.BuildTextUtils.selection.replace({selection:g,body:c,doc:d});if(!v)return!1;let y={id:m.id,params:{unitId:s,actions:[],textRanges:_,debounce:!0,segmentId:f},textX:v},b=e.JSONX.getInstance();return y.params.actions=b.editOp(v.serialize()),y}exports.DOC_INTERCEPTOR_POINT=S,Object.defineProperty(exports,`DocInterceptorService`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`DocSelectionManagerService`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`DocSkeletonManagerService`,{enumerable:!0,get:function(){return d}}),exports.DocStateEmitService=f,exports.RichTextEditingMutation=m,exports.SetTextSelectionsOperation=r,Object.defineProperty(exports,`UniverDocsPlugin`,{enumerable:!0,get:function(){return x}}),exports.addCustomRangeBySelectionFactory=E,exports.addCustomRangeFactory=T,exports.deleteCustomRangeFactory=D,exports.replaceSelectionFactory=O;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
4
|
+
let rxjs = require("rxjs");
|
|
5
|
+
|
|
6
|
+
//#region src/commands/operations/text-selection.operation.ts
|
|
7
|
+
const SetTextSelectionsOperation = {
|
|
8
|
+
id: "doc.operation.set-selections",
|
|
9
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
10
|
+
handler: () => {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
17
|
+
function _typeof(o) {
|
|
18
|
+
"@babel/helpers - typeof";
|
|
19
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
20
|
+
return typeof o;
|
|
21
|
+
} : function(o) {
|
|
22
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
23
|
+
}, _typeof(o);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
28
|
+
function toPrimitive(t, r) {
|
|
29
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
30
|
+
var e = t[Symbol.toPrimitive];
|
|
31
|
+
if (void 0 !== e) {
|
|
32
|
+
var i = e.call(t, r || "default");
|
|
33
|
+
if ("object" != _typeof(i)) return i;
|
|
34
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
35
|
+
}
|
|
36
|
+
return ("string" === r ? String : Number)(t);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
41
|
+
function toPropertyKey(t) {
|
|
42
|
+
var i = toPrimitive(t, "string");
|
|
43
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
48
|
+
function _defineProperty(e, r, t) {
|
|
49
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
50
|
+
value: t,
|
|
51
|
+
enumerable: !0,
|
|
52
|
+
configurable: !0,
|
|
53
|
+
writable: !0
|
|
54
|
+
}) : e[r] = t, e;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
59
|
+
function __decorateParam(paramIndex, decorator) {
|
|
60
|
+
return function(target, key) {
|
|
61
|
+
decorator(target, key, paramIndex);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
67
|
+
function __decorate(decorators, target, key, desc) {
|
|
68
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
69
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
70
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
71
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/services/doc-selection-manager.service.ts
|
|
76
|
+
let DocSelectionManagerService = class DocSelectionManagerService extends _univerjs_core.RxDisposable {
|
|
77
|
+
constructor(_commandService, _univerInstanceService) {
|
|
78
|
+
super();
|
|
79
|
+
this._commandService = _commandService;
|
|
80
|
+
this._univerInstanceService = _univerInstanceService;
|
|
81
|
+
_defineProperty(this, "_currentSelection", null);
|
|
82
|
+
_defineProperty(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
|
|
83
|
+
_defineProperty(this, "_textSelection$", new rxjs.Subject());
|
|
84
|
+
_defineProperty(this, "textSelection$", this._textSelection$.asObservable());
|
|
85
|
+
_defineProperty(this, "_refreshSelection$", new rxjs.BehaviorSubject(null));
|
|
86
|
+
_defineProperty(this, "refreshSelection$", this._refreshSelection$.asObservable());
|
|
87
|
+
this._listenCurrentUnit();
|
|
88
|
+
}
|
|
89
|
+
_listenCurrentUnit() {
|
|
90
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((documentModel) => {
|
|
91
|
+
if (documentModel == null) return;
|
|
92
|
+
const unitId = documentModel.getUnitId();
|
|
93
|
+
this._setCurrentSelectionNotRefresh({
|
|
94
|
+
unitId,
|
|
95
|
+
subUnitId: unitId
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
__getCurrentSelection() {
|
|
100
|
+
return this._currentSelection;
|
|
101
|
+
}
|
|
102
|
+
getSelectionInfo(params = this._currentSelection) {
|
|
103
|
+
return this._getTextRanges(params);
|
|
104
|
+
}
|
|
105
|
+
refreshSelection(params = this._currentSelection) {
|
|
106
|
+
if (params == null) return;
|
|
107
|
+
this._refresh(params);
|
|
108
|
+
}
|
|
109
|
+
__TEST_ONLY_setCurrentSelection(param) {
|
|
110
|
+
this._currentSelection = param;
|
|
111
|
+
this._refresh(param);
|
|
112
|
+
}
|
|
113
|
+
getTextRanges(params = this._currentSelection) {
|
|
114
|
+
var _this$_getTextRanges;
|
|
115
|
+
return (_this$_getTextRanges = this._getTextRanges(params)) === null || _this$_getTextRanges === void 0 ? void 0 : _this$_getTextRanges.textRanges;
|
|
116
|
+
}
|
|
117
|
+
getRectRanges(params = this._currentSelection) {
|
|
118
|
+
var _this$_getTextRanges2;
|
|
119
|
+
return (_this$_getTextRanges2 = this._getTextRanges(params)) === null || _this$_getTextRanges2 === void 0 ? void 0 : _this$_getTextRanges2.rectRanges;
|
|
120
|
+
}
|
|
121
|
+
getDocRanges(params = this._currentSelection) {
|
|
122
|
+
var _this$getTextRanges, _this$getRectRanges;
|
|
123
|
+
const textRanges = (_this$getTextRanges = this.getTextRanges(params)) !== null && _this$getTextRanges !== void 0 ? _this$getTextRanges : [];
|
|
124
|
+
const rectRanges = (_this$getRectRanges = this.getRectRanges(params)) !== null && _this$getRectRanges !== void 0 ? _this$getRectRanges : [];
|
|
125
|
+
return [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => {
|
|
126
|
+
if (a.startOffset > b.startOffset) return 1;
|
|
127
|
+
else if (a.startOffset < b.startOffset) return -1;
|
|
128
|
+
else return 0;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
getActiveTextRange() {
|
|
132
|
+
const selectionInfo = this._getTextRanges(this._currentSelection);
|
|
133
|
+
if (selectionInfo == null) return;
|
|
134
|
+
const { textRanges } = selectionInfo;
|
|
135
|
+
return textRanges.find((textRange) => textRange.isActive);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* @deprecated
|
|
140
|
+
*/
|
|
141
|
+
getActiveRectRange() {
|
|
142
|
+
const selectionInfo = this._getTextRanges(this._currentSelection);
|
|
143
|
+
if (selectionInfo == null) return;
|
|
144
|
+
const { rectRanges } = selectionInfo;
|
|
145
|
+
return rectRanges.find((rectRange) => rectRange.isActive);
|
|
146
|
+
}
|
|
147
|
+
__TEST_ONLY_add(textRanges, isEditing = true) {
|
|
148
|
+
if (this._currentSelection == null) return;
|
|
149
|
+
this._addByParam({
|
|
150
|
+
...this._currentSelection,
|
|
151
|
+
textRanges,
|
|
152
|
+
rectRanges: [],
|
|
153
|
+
segmentId: "",
|
|
154
|
+
segmentPage: -1,
|
|
155
|
+
isEditing,
|
|
156
|
+
style: _univerjs_engine_render.NORMAL_TEXT_SELECTION_PLUGIN_STYLE
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated pls use replaceDocRanges.
|
|
161
|
+
*/
|
|
162
|
+
replaceTextRanges(docRanges, isEditing = true, options) {
|
|
163
|
+
return this.replaceDocRanges(docRanges, this._currentSelection, isEditing, options);
|
|
164
|
+
}
|
|
165
|
+
replaceDocRanges(docRanges, params = this._currentSelection, isEditing = true, options) {
|
|
166
|
+
if (params == null) return;
|
|
167
|
+
const { unitId, subUnitId } = params;
|
|
168
|
+
this._refreshSelection$.next({
|
|
169
|
+
unitId,
|
|
170
|
+
subUnitId,
|
|
171
|
+
docRanges,
|
|
172
|
+
isEditing,
|
|
173
|
+
options
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
__replaceTextRangesWithNoRefresh(textSelectionInfo, search) {
|
|
177
|
+
if (this._currentSelection == null) return;
|
|
178
|
+
const params = {
|
|
179
|
+
...textSelectionInfo,
|
|
180
|
+
...search
|
|
181
|
+
};
|
|
182
|
+
this._replaceByParam(params);
|
|
183
|
+
this._textSelection$.next(params);
|
|
184
|
+
const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params;
|
|
185
|
+
const ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => {
|
|
186
|
+
if (a.startOffset > b.startOffset) return 1;
|
|
187
|
+
else if (a.startOffset < b.startOffset) return -1;
|
|
188
|
+
else return 0;
|
|
189
|
+
});
|
|
190
|
+
this._commandService.executeCommand(SetTextSelectionsOperation.id, {
|
|
191
|
+
unitId,
|
|
192
|
+
subUnitId,
|
|
193
|
+
segmentId,
|
|
194
|
+
style,
|
|
195
|
+
isEditing,
|
|
196
|
+
ranges
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
dispose() {
|
|
200
|
+
this._textSelection$.complete();
|
|
201
|
+
this._refreshSelection$.complete();
|
|
202
|
+
}
|
|
203
|
+
_setCurrentSelectionNotRefresh(param) {
|
|
204
|
+
this._currentSelection = param;
|
|
205
|
+
}
|
|
206
|
+
_getTextRanges(param) {
|
|
207
|
+
var _this$_textSelectionI;
|
|
208
|
+
if (param == null) return;
|
|
209
|
+
const { unitId, subUnitId = "" } = param;
|
|
210
|
+
return (_this$_textSelectionI = this._textSelectionInfo.get(unitId)) === null || _this$_textSelectionI === void 0 ? void 0 : _this$_textSelectionI.get(subUnitId);
|
|
211
|
+
}
|
|
212
|
+
_refresh(param) {
|
|
213
|
+
const allTextSelectionInfo = this._getTextRanges(param);
|
|
214
|
+
if (allTextSelectionInfo == null) return;
|
|
215
|
+
const { textRanges, rectRanges } = allTextSelectionInfo;
|
|
216
|
+
const docRanges = [...textRanges, ...rectRanges];
|
|
217
|
+
const { unitId, subUnitId } = param;
|
|
218
|
+
this._refreshSelection$.next({
|
|
219
|
+
unitId,
|
|
220
|
+
subUnitId,
|
|
221
|
+
docRanges,
|
|
222
|
+
isEditing: false
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
_replaceByParam(insertParam) {
|
|
226
|
+
const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
|
|
227
|
+
if (!this._textSelectionInfo.has(unitId)) this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map());
|
|
228
|
+
this._textSelectionInfo.get(unitId).set(subUnitId, { ...selectionInsertParam });
|
|
229
|
+
}
|
|
230
|
+
_addByParam(insertParam) {
|
|
231
|
+
const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
|
|
232
|
+
if (!this._textSelectionInfo.has(unitId)) this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map());
|
|
233
|
+
const unitTextRange = this._textSelectionInfo.get(unitId);
|
|
234
|
+
if (!unitTextRange.has(subUnitId)) unitTextRange.set(subUnitId, { ...selectionInsertParam });
|
|
235
|
+
else unitTextRange.get(subUnitId).textRanges.push(...insertParam.textRanges);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
DocSelectionManagerService = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, _univerjs_core.IUniverInstanceService)], DocSelectionManagerService);
|
|
239
|
+
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/services/doc-skeleton-manager.service.ts
|
|
242
|
+
let DocSkeletonManagerService = class DocSkeletonManagerService extends _univerjs_core.RxDisposable {
|
|
243
|
+
constructor(_context, _localeService, _univerInstanceService) {
|
|
244
|
+
super();
|
|
245
|
+
this._context = _context;
|
|
246
|
+
this._localeService = _localeService;
|
|
247
|
+
this._univerInstanceService = _univerInstanceService;
|
|
248
|
+
_defineProperty(this, "_skeleton", void 0);
|
|
249
|
+
_defineProperty(this, "_docViewModel", void 0);
|
|
250
|
+
_defineProperty(this, "_currentSkeleton$", new rxjs.BehaviorSubject(null));
|
|
251
|
+
_defineProperty(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
|
|
252
|
+
_defineProperty(this, "_currentSkeletonBefore$", new rxjs.BehaviorSubject(null));
|
|
253
|
+
_defineProperty(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
|
|
254
|
+
_defineProperty(this, "_currentViewModel$", new rxjs.BehaviorSubject(null));
|
|
255
|
+
_defineProperty(this, "currentViewModel$", this._currentViewModel$.asObservable());
|
|
256
|
+
this._init();
|
|
257
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((documentModel) => {
|
|
258
|
+
if (documentModel && documentModel.getUnitId() === this._context.unitId) this._update(documentModel);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
dispose() {
|
|
262
|
+
super.dispose();
|
|
263
|
+
this._currentSkeletonBefore$.complete();
|
|
264
|
+
this._currentSkeleton$.complete();
|
|
265
|
+
}
|
|
266
|
+
getSkeleton() {
|
|
267
|
+
return this._skeleton;
|
|
268
|
+
}
|
|
269
|
+
getViewModel() {
|
|
270
|
+
return this._docViewModel;
|
|
271
|
+
}
|
|
272
|
+
_init() {
|
|
273
|
+
const documentDataModel = this._context.unit;
|
|
274
|
+
this._update(documentDataModel);
|
|
275
|
+
}
|
|
276
|
+
_update(documentDataModel) {
|
|
277
|
+
const unitId = this._context.unitId;
|
|
278
|
+
if (documentDataModel.getBody() == null) return;
|
|
279
|
+
if (this._docViewModel && (0, _univerjs_core.isInternalEditorID)(unitId)) {
|
|
280
|
+
this._docViewModel.reset(documentDataModel);
|
|
281
|
+
this._context.unit = documentDataModel;
|
|
282
|
+
} else if (!this._docViewModel) this._docViewModel = this._buildDocViewModel(documentDataModel);
|
|
283
|
+
if (!this._skeleton) this._skeleton = this._buildSkeleton(this._docViewModel);
|
|
284
|
+
const skeleton = this._skeleton;
|
|
285
|
+
skeleton.calculate();
|
|
286
|
+
this._currentSkeletonBefore$.next(skeleton);
|
|
287
|
+
this._currentSkeleton$.next(skeleton);
|
|
288
|
+
this._currentViewModel$.next(this._docViewModel);
|
|
289
|
+
}
|
|
290
|
+
_buildSkeleton(documentViewModel) {
|
|
291
|
+
return _univerjs_engine_render.DocumentSkeleton.create(documentViewModel, this._localeService);
|
|
292
|
+
}
|
|
293
|
+
_buildDocViewModel(documentDataModel) {
|
|
294
|
+
return new _univerjs_engine_render.DocumentViewModel(documentDataModel);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
DocSkeletonManagerService = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)), __decorateParam(2, _univerjs_core.IUniverInstanceService)], DocSkeletonManagerService);
|
|
298
|
+
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/services/doc-state-emit.service.ts
|
|
301
|
+
var DocStateEmitService = class extends _univerjs_core.RxDisposable {
|
|
302
|
+
constructor() {
|
|
303
|
+
super();
|
|
304
|
+
_defineProperty(this, "_docStateChangeParams$", new rxjs.BehaviorSubject(null));
|
|
305
|
+
_defineProperty(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
|
|
306
|
+
}
|
|
307
|
+
emitStateChangeInfo(params) {
|
|
308
|
+
this._docStateChangeParams$.next(params);
|
|
309
|
+
}
|
|
310
|
+
dispose() {
|
|
311
|
+
super.dispose();
|
|
312
|
+
this._docStateChangeParams$.complete();
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region src/commands/mutations/core-editing.mutation.ts
|
|
318
|
+
const RichTextEditingMutationId = "doc.mutation.rich-text-editing";
|
|
319
|
+
/**
|
|
320
|
+
* The core mutator to change rich text actions. The execution result would be undo mutation params. Could be directly
|
|
321
|
+
* send to undo redo service (will be used by the triggering command).
|
|
322
|
+
*/
|
|
323
|
+
const RichTextEditingMutation = {
|
|
324
|
+
id: RichTextEditingMutationId,
|
|
325
|
+
type: _univerjs_core.CommandType.MUTATION,
|
|
326
|
+
handler: (accessor, params) => {
|
|
327
|
+
var _renderManagerService, _docSelectionManagerS;
|
|
328
|
+
const { unitId, segmentId = "", actions, textRanges, prevTextRanges, trigger, noHistory, isCompositionEnd, noNeedSetTextRange, debounce, isEditing = true, isSync, syncer } = params;
|
|
329
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
330
|
+
const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
|
|
331
|
+
const docStateEmitService = accessor.get(DocStateEmitService);
|
|
332
|
+
const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
|
|
333
|
+
const documentViewModel = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService).getViewModel();
|
|
334
|
+
if (documentDataModel == null || documentViewModel == null) throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
|
|
335
|
+
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
336
|
+
const docRanges = (_docSelectionManagerS = docSelectionManagerService.getDocRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : [];
|
|
337
|
+
const disabled = !!documentDataModel.getSnapshot().disabled;
|
|
338
|
+
if (_univerjs_core.JSONX.isNoop(actions) || actions && actions.length === 0 || disabled) return {
|
|
339
|
+
unitId,
|
|
340
|
+
actions: [],
|
|
341
|
+
textRanges: docRanges
|
|
342
|
+
};
|
|
343
|
+
const undoActions = _univerjs_core.JSONX.invertWithDoc(actions, documentDataModel.getSnapshot());
|
|
344
|
+
documentDataModel.apply(actions);
|
|
345
|
+
documentViewModel.reset(documentDataModel);
|
|
346
|
+
if (!noNeedSetTextRange && textRanges && trigger != null && !isSync) queueMicrotask(() => {
|
|
347
|
+
docSelectionManagerService.replaceDocRanges(textRanges, {
|
|
348
|
+
unitId,
|
|
349
|
+
subUnitId: unitId
|
|
350
|
+
}, isEditing, params.options);
|
|
351
|
+
});
|
|
352
|
+
const changeState = {
|
|
353
|
+
commandId: RichTextEditingMutationId,
|
|
354
|
+
unitId,
|
|
355
|
+
segmentId,
|
|
356
|
+
trigger,
|
|
357
|
+
noHistory,
|
|
358
|
+
debounce,
|
|
359
|
+
redoState: {
|
|
360
|
+
actions,
|
|
361
|
+
textRanges
|
|
362
|
+
},
|
|
363
|
+
undoState: {
|
|
364
|
+
actions: undoActions,
|
|
365
|
+
textRanges: prevTextRanges !== null && prevTextRanges !== void 0 ? prevTextRanges : docRanges
|
|
366
|
+
},
|
|
367
|
+
isCompositionEnd,
|
|
368
|
+
isSync,
|
|
369
|
+
syncer
|
|
370
|
+
};
|
|
371
|
+
docStateEmitService.emitStateChangeInfo(changeState);
|
|
372
|
+
return {
|
|
373
|
+
unitId,
|
|
374
|
+
actions: undoActions,
|
|
375
|
+
textRanges: docRanges
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region package.json
|
|
382
|
+
var name = "@univerjs/docs";
|
|
383
|
+
var version = "0.21.0-insiders.20260422-d7fcb4d";
|
|
384
|
+
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/commands/mutations/docs-rename.mutation.ts
|
|
387
|
+
const DocsRenameMutation = {
|
|
388
|
+
id: "doc.mutation.rename-doc",
|
|
389
|
+
type: _univerjs_core.CommandType.MUTATION,
|
|
390
|
+
handler: (accessor, params) => {
|
|
391
|
+
const doc = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
392
|
+
if (!doc) return false;
|
|
393
|
+
doc.setName(params.name);
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/config/config.ts
|
|
400
|
+
/**
|
|
401
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
402
|
+
*
|
|
403
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
404
|
+
* you may not use this file except in compliance with the License.
|
|
405
|
+
* You may obtain a copy of the License at
|
|
406
|
+
*
|
|
407
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
408
|
+
*
|
|
409
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
410
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
411
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
412
|
+
* See the License for the specific language governing permissions and
|
|
413
|
+
* limitations under the License.
|
|
414
|
+
*/
|
|
415
|
+
const DOCS_PLUGIN_CONFIG_KEY = "docs.config";
|
|
416
|
+
const configSymbol = Symbol(DOCS_PLUGIN_CONFIG_KEY);
|
|
417
|
+
const defaultPluginConfig = {};
|
|
418
|
+
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/controllers/custom-range.controller.ts
|
|
421
|
+
let DocCustomRangeController = class DocCustomRangeController extends _univerjs_core.Disposable {
|
|
422
|
+
constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
|
|
423
|
+
super();
|
|
424
|
+
this._commandService = _commandService;
|
|
425
|
+
this._textSelectionManagerService = _textSelectionManagerService;
|
|
426
|
+
this._univerInstanceService = _univerInstanceService;
|
|
427
|
+
this._initSelectionChange();
|
|
428
|
+
}
|
|
429
|
+
_transformCustomRange(doc, selection) {
|
|
430
|
+
var _doc$getCustomRanges;
|
|
431
|
+
const { startOffset, endOffset, collapsed } = selection;
|
|
432
|
+
const customRanges = (_doc$getCustomRanges = doc.getCustomRanges()) === null || _doc$getCustomRanges === void 0 ? void 0 : _doc$getCustomRanges.filter((range) => {
|
|
433
|
+
if (!range.wholeEntity) return false;
|
|
434
|
+
if (startOffset <= range.startIndex && endOffset > range.endIndex) return false;
|
|
435
|
+
if (collapsed) return range.startIndex < startOffset && range.endIndex >= endOffset;
|
|
436
|
+
return _univerjs_core.BuildTextUtils.range.isIntersects(startOffset, endOffset - 1, range.startIndex, range.endIndex);
|
|
437
|
+
});
|
|
438
|
+
if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.length) {
|
|
439
|
+
let start = startOffset;
|
|
440
|
+
let end = endOffset;
|
|
441
|
+
customRanges.forEach((range) => {
|
|
442
|
+
start = Math.min(range.startIndex, start);
|
|
443
|
+
end = Math.max(range.endIndex + 1, end);
|
|
444
|
+
});
|
|
445
|
+
return {
|
|
446
|
+
...selection,
|
|
447
|
+
startOffset: start,
|
|
448
|
+
endOffset: end,
|
|
449
|
+
collapsed: start === end
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
return selection;
|
|
453
|
+
}
|
|
454
|
+
_initSelectionChange() {
|
|
455
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
456
|
+
if (commandInfo.id === SetTextSelectionsOperation.id) {
|
|
457
|
+
const { unitId, ranges, isEditing } = commandInfo.params;
|
|
458
|
+
const doc = this._univerInstanceService.getUnit(unitId);
|
|
459
|
+
if (!doc) return;
|
|
460
|
+
const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range));
|
|
461
|
+
if (transformedRanges.some((range, i) => ranges[i] !== range)) this._textSelectionManagerService.replaceTextRanges(transformedRanges, isEditing);
|
|
462
|
+
}
|
|
463
|
+
}));
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
DocCustomRangeController = __decorate([
|
|
467
|
+
__decorateParam(0, _univerjs_core.ICommandService),
|
|
468
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(DocSelectionManagerService)),
|
|
469
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService)
|
|
470
|
+
], DocCustomRangeController);
|
|
471
|
+
|
|
472
|
+
//#endregion
|
|
473
|
+
//#region src/plugin.ts
|
|
474
|
+
let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
|
|
475
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
476
|
+
super();
|
|
477
|
+
this._config = _config;
|
|
478
|
+
this._injector = _injector;
|
|
479
|
+
this._configService = _configService;
|
|
480
|
+
const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
481
|
+
this._configService.setConfig(DOCS_PLUGIN_CONFIG_KEY, rest);
|
|
482
|
+
}
|
|
483
|
+
onStarting() {
|
|
484
|
+
this._initializeDependencies();
|
|
485
|
+
this._initializeCommands();
|
|
486
|
+
}
|
|
487
|
+
_initializeCommands() {
|
|
488
|
+
[
|
|
489
|
+
RichTextEditingMutation,
|
|
490
|
+
DocsRenameMutation,
|
|
491
|
+
SetTextSelectionsOperation
|
|
492
|
+
].forEach((command) => {
|
|
493
|
+
this._injector.get(_univerjs_core.ICommandService).registerCommand(command);
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
_initializeDependencies() {
|
|
497
|
+
[
|
|
498
|
+
[DocSelectionManagerService],
|
|
499
|
+
[DocStateEmitService],
|
|
500
|
+
[DocCustomRangeController]
|
|
501
|
+
].forEach((d) => this._injector.add(d));
|
|
502
|
+
}
|
|
503
|
+
onReady() {
|
|
504
|
+
this._injector.get(DocCustomRangeController);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
_defineProperty(UniverDocsPlugin, "pluginName", "DOCS_PLUGIN");
|
|
508
|
+
_defineProperty(UniverDocsPlugin, "packageName", name);
|
|
509
|
+
_defineProperty(UniverDocsPlugin, "version", version);
|
|
510
|
+
UniverDocsPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverDocsPlugin);
|
|
511
|
+
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/services/doc-interceptor/interceptor-const.ts
|
|
514
|
+
const CUSTOM_RANGE = (0, _univerjs_core.createInterceptorKey)("CUSTOM_RANGE");
|
|
515
|
+
const CUSTOM_DECORATION = (0, _univerjs_core.createInterceptorKey)("CUSTOM_DECORATION");
|
|
516
|
+
const DOC_INTERCEPTOR_POINT = {
|
|
517
|
+
CUSTOM_RANGE,
|
|
518
|
+
CUSTOM_DECORATION
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/services/doc-interceptor/doc-interceptor.service.ts
|
|
523
|
+
let DocInterceptorService = class DocInterceptorService extends _univerjs_core.Disposable {
|
|
524
|
+
constructor(_context, _docSkeletonManagerService) {
|
|
525
|
+
super();
|
|
526
|
+
this._context = _context;
|
|
527
|
+
this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
528
|
+
_defineProperty(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
529
|
+
const viewModel = this._docSkeletonManagerService.getViewModel();
|
|
530
|
+
const unitId = viewModel.getDataModel().getUnitId();
|
|
531
|
+
if (unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY || unitId === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) return;
|
|
532
|
+
this.disposeWithMe(this.interceptDocumentViewModel(viewModel));
|
|
533
|
+
this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
|
|
534
|
+
priority: -1,
|
|
535
|
+
handler: (data, pos, next) => {
|
|
536
|
+
return next(data);
|
|
537
|
+
}
|
|
538
|
+
}));
|
|
539
|
+
let disposableCollection = new _univerjs_core.DisposableCollection();
|
|
540
|
+
viewModel.segmentViewModels$.subscribe((segmentViewModels) => {
|
|
541
|
+
disposableCollection.dispose();
|
|
542
|
+
disposableCollection = new _univerjs_core.DisposableCollection();
|
|
543
|
+
segmentViewModels.forEach((segmentViewModel) => {
|
|
544
|
+
disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel));
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
this.disposeWithMe(disposableCollection);
|
|
548
|
+
}
|
|
549
|
+
intercept(name, interceptor) {
|
|
550
|
+
const key = name;
|
|
551
|
+
if (!this._interceptorsByName.has(key)) this._interceptorsByName.set(key, []);
|
|
552
|
+
const interceptors = this._interceptorsByName.get(key);
|
|
553
|
+
interceptors.push(interceptor);
|
|
554
|
+
this._interceptorsByName.set(key, interceptors.sort((a, b) => {
|
|
555
|
+
var _b$priority, _a$priority;
|
|
556
|
+
return ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0) - ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0);
|
|
557
|
+
}));
|
|
558
|
+
return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._interceptorsByName.get(key), interceptor)));
|
|
559
|
+
}
|
|
560
|
+
fetchThroughInterceptors(name) {
|
|
561
|
+
const key = name;
|
|
562
|
+
return (0, _univerjs_core.composeInterceptors)(this._interceptorsByName.get(key) || []);
|
|
563
|
+
}
|
|
564
|
+
interceptDocumentViewModel(viewModel) {
|
|
565
|
+
const disposableCollection = new _univerjs_core.DisposableCollection();
|
|
566
|
+
disposableCollection.add(viewModel.registerCustomRangeInterceptor({
|
|
567
|
+
getCustomRange: (index) => {
|
|
568
|
+
var _viewModel$getDataMod;
|
|
569
|
+
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(viewModel.getCustomRangeRaw(index), {
|
|
570
|
+
index,
|
|
571
|
+
unitId: viewModel.getDataModel().getUnitId(),
|
|
572
|
+
customRanges: (_viewModel$getDataMod = viewModel.getDataModel().getCustomRanges()) !== null && _viewModel$getDataMod !== void 0 ? _viewModel$getDataMod : []
|
|
573
|
+
});
|
|
574
|
+
},
|
|
575
|
+
getCustomDecoration: (index) => {
|
|
576
|
+
var _viewModel$getDataMod2;
|
|
577
|
+
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(viewModel.getCustomDecorationRaw(index), {
|
|
578
|
+
index,
|
|
579
|
+
unitId: viewModel.getDataModel().getUnitId(),
|
|
580
|
+
customDecorations: (_viewModel$getDataMod2 = viewModel.getDataModel().getCustomDecorations()) !== null && _viewModel$getDataMod2 !== void 0 ? _viewModel$getDataMod2 : []
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
}));
|
|
584
|
+
return disposableCollection;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
DocInterceptorService = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(DocSkeletonManagerService))], DocInterceptorService);
|
|
588
|
+
|
|
589
|
+
//#endregion
|
|
590
|
+
//#region src/utils/custom-range-factory.ts
|
|
591
|
+
/**
|
|
592
|
+
* @deprecated This is a duplication from docs-ui to avoid making too much breaking changes.
|
|
593
|
+
*/
|
|
594
|
+
function getRichTextEditPath(docDataModel, segmentId = "") {
|
|
595
|
+
if (!segmentId) return ["body"];
|
|
596
|
+
const { headers, footers } = docDataModel.getSnapshot();
|
|
597
|
+
if (headers == null && footers == null) throw new Error("Document data model must have headers or footers when update by segment id");
|
|
598
|
+
if ((headers === null || headers === void 0 ? void 0 : headers[segmentId]) != null) return [
|
|
599
|
+
"headers",
|
|
600
|
+
segmentId,
|
|
601
|
+
"body"
|
|
602
|
+
];
|
|
603
|
+
else if ((footers === null || footers === void 0 ? void 0 : footers[segmentId]) != null) return [
|
|
604
|
+
"footers",
|
|
605
|
+
segmentId,
|
|
606
|
+
"body"
|
|
607
|
+
];
|
|
608
|
+
else throw new Error("Segment id not found in headers or footers");
|
|
609
|
+
}
|
|
610
|
+
function addCustomRangeFactory(accessor, param, body) {
|
|
611
|
+
const { unitId, segmentId } = param;
|
|
612
|
+
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
|
|
613
|
+
if (!documentDataModel) return false;
|
|
614
|
+
const doMutation = {
|
|
615
|
+
id: RichTextEditingMutation.id,
|
|
616
|
+
params: {
|
|
617
|
+
unitId: param.unitId,
|
|
618
|
+
actions: [],
|
|
619
|
+
textRanges: void 0
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
623
|
+
const textX = _univerjs_core.BuildTextUtils.customRange.add({
|
|
624
|
+
...param,
|
|
625
|
+
body
|
|
626
|
+
});
|
|
627
|
+
if (!textX) return false;
|
|
628
|
+
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
629
|
+
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
630
|
+
return doMutation;
|
|
631
|
+
}
|
|
632
|
+
function addCustomRangeBySelectionFactory(accessor, param) {
|
|
633
|
+
var _selections$;
|
|
634
|
+
const { rangeId, rangeType, wholeEntity, properties, unitId, selections: propSelection } = param;
|
|
635
|
+
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
636
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
637
|
+
const selections = propSelection !== null && propSelection !== void 0 ? propSelection : docSelectionManagerService.getTextRanges({
|
|
638
|
+
unitId,
|
|
639
|
+
subUnitId: unitId
|
|
640
|
+
});
|
|
641
|
+
const segmentId = selections === null || selections === void 0 || (_selections$ = selections[0]) === null || _selections$ === void 0 ? void 0 : _selections$.segmentId;
|
|
642
|
+
if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return false;
|
|
643
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
644
|
+
if (!documentDataModel) return false;
|
|
645
|
+
const body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
646
|
+
if (!body) return false;
|
|
647
|
+
const textX = _univerjs_core.BuildTextUtils.customRange.add({
|
|
648
|
+
ranges: selections,
|
|
649
|
+
rangeId,
|
|
650
|
+
rangeType,
|
|
651
|
+
segmentId,
|
|
652
|
+
wholeEntity,
|
|
653
|
+
properties,
|
|
654
|
+
body
|
|
655
|
+
});
|
|
656
|
+
if (!textX) return false;
|
|
657
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
658
|
+
const doMutation = {
|
|
659
|
+
id: RichTextEditingMutation.id,
|
|
660
|
+
params: {
|
|
661
|
+
unitId,
|
|
662
|
+
actions: [],
|
|
663
|
+
textRanges: textX.selections,
|
|
664
|
+
segmentId
|
|
665
|
+
},
|
|
666
|
+
textX
|
|
667
|
+
};
|
|
668
|
+
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
669
|
+
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
670
|
+
return doMutation;
|
|
671
|
+
}
|
|
672
|
+
function deleteCustomRangeFactory(accessor, params) {
|
|
673
|
+
const { unitId, segmentId, insert } = params;
|
|
674
|
+
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
|
|
675
|
+
if (!documentDataModel) return false;
|
|
676
|
+
const doMutation = {
|
|
677
|
+
id: RichTextEditingMutation.id,
|
|
678
|
+
params: {
|
|
679
|
+
unitId: params.unitId,
|
|
680
|
+
actions: [],
|
|
681
|
+
textRanges: void 0,
|
|
682
|
+
segmentId
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
686
|
+
const textX = _univerjs_core.BuildTextUtils.customRange.delete({
|
|
687
|
+
documentDataModel,
|
|
688
|
+
rangeId: params.rangeId,
|
|
689
|
+
insert,
|
|
690
|
+
segmentId
|
|
691
|
+
});
|
|
692
|
+
if (!textX) return false;
|
|
693
|
+
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
694
|
+
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
695
|
+
doMutation.params.textRanges = textX.selections;
|
|
696
|
+
return doMutation;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
//#endregion
|
|
700
|
+
//#region src/utils/replace-selection-factory.ts
|
|
701
|
+
function replaceSelectionFactory(accessor, params) {
|
|
702
|
+
var _params$selection, _docDataModel$getSelf, _params$selection2, _params$textRanges;
|
|
703
|
+
const { unitId, body: insertBody, doc } = params;
|
|
704
|
+
let docDataModel = doc;
|
|
705
|
+
if (!docDataModel) docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
|
|
706
|
+
if (!docDataModel) return false;
|
|
707
|
+
const segmentId = (_params$selection = params.selection) === null || _params$selection === void 0 ? void 0 : _params$selection.segmentId;
|
|
708
|
+
const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
|
|
709
|
+
if (!body) return false;
|
|
710
|
+
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
711
|
+
const selection = (_params$selection2 = params.selection) !== null && _params$selection2 !== void 0 ? _params$selection2 : docSelectionManagerService.getActiveTextRange();
|
|
712
|
+
if (!selection || !body) return false;
|
|
713
|
+
const textRanges = (_params$textRanges = params.textRanges) !== null && _params$textRanges !== void 0 ? _params$textRanges : [{
|
|
714
|
+
startOffset: selection.startOffset + insertBody.dataStream.length,
|
|
715
|
+
endOffset: selection.startOffset + insertBody.dataStream.length,
|
|
716
|
+
collapsed: true,
|
|
717
|
+
segmentId
|
|
718
|
+
}];
|
|
719
|
+
const textX = _univerjs_core.BuildTextUtils.selection.replace({
|
|
720
|
+
selection,
|
|
721
|
+
body: insertBody,
|
|
722
|
+
doc: docDataModel
|
|
723
|
+
});
|
|
724
|
+
if (!textX) return false;
|
|
725
|
+
const doMutation = {
|
|
726
|
+
id: RichTextEditingMutation.id,
|
|
727
|
+
params: {
|
|
728
|
+
unitId,
|
|
729
|
+
actions: [],
|
|
730
|
+
textRanges,
|
|
731
|
+
debounce: true,
|
|
732
|
+
segmentId
|
|
733
|
+
},
|
|
734
|
+
textX
|
|
735
|
+
};
|
|
736
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
737
|
+
doMutation.params.actions = jsonX.editOp(textX.serialize());
|
|
738
|
+
return doMutation;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
//#endregion
|
|
742
|
+
exports.DOC_INTERCEPTOR_POINT = DOC_INTERCEPTOR_POINT;
|
|
743
|
+
Object.defineProperty(exports, 'DocInterceptorService', {
|
|
744
|
+
enumerable: true,
|
|
745
|
+
get: function () {
|
|
746
|
+
return DocInterceptorService;
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
Object.defineProperty(exports, 'DocSelectionManagerService', {
|
|
750
|
+
enumerable: true,
|
|
751
|
+
get: function () {
|
|
752
|
+
return DocSelectionManagerService;
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
Object.defineProperty(exports, 'DocSkeletonManagerService', {
|
|
756
|
+
enumerable: true,
|
|
757
|
+
get: function () {
|
|
758
|
+
return DocSkeletonManagerService;
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
exports.DocStateEmitService = DocStateEmitService;
|
|
762
|
+
exports.RichTextEditingMutation = RichTextEditingMutation;
|
|
763
|
+
exports.SetTextSelectionsOperation = SetTextSelectionsOperation;
|
|
764
|
+
Object.defineProperty(exports, 'UniverDocsPlugin', {
|
|
765
|
+
enumerable: true,
|
|
766
|
+
get: function () {
|
|
767
|
+
return UniverDocsPlugin;
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
exports.addCustomRangeBySelectionFactory = addCustomRangeBySelectionFactory;
|
|
771
|
+
exports.addCustomRangeFactory = addCustomRangeFactory;
|
|
772
|
+
exports.deleteCustomRangeFactory = deleteCustomRangeFactory;
|
|
773
|
+
exports.replaceSelectionFactory = replaceSelectionFactory;
|