@univerjs/docs 0.17.0 → 0.18.0
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 +1 -1
- package/lib/es/index.js +1 -610
- package/lib/index.js +1 -610
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +17 -2
- package/lib/types/commands/mutations/docs-rename.mutation.d.ts +16 -1
- package/lib/types/commands/operations/text-selection.operation.d.ts +17 -2
- package/lib/types/controllers/custom-range.controller.d.ts +15 -0
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/services/doc-interceptor/doc-interceptor.service.d.ts +19 -3
- package/lib/types/services/doc-interceptor/interceptor-const.d.ts +18 -3
- package/lib/types/services/doc-selection-manager.service.d.ts +20 -4
- package/lib/types/services/doc-skeleton-manager.service.d.ts +22 -5
- package/lib/types/services/doc-state-emit.service.d.ts +19 -3
- package/lib/types/services/doc-view-model-manager.service.d.ts +21 -4
- package/lib/types/utils/custom-range-factory.d.ts +17 -2
- package/lib/types/utils/replace-selection-factory.d.ts +18 -3
- package/lib/umd/index.js +1 -1
- package/package.json +8 -7
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IOperation } from '@univerjs/core';
|
|
17
|
+
import type { ITextRangeWithStyle, ITextSelectionStyle } from '@univerjs/engine-render';
|
|
3
18
|
export interface ISetTextSelectionsOperationParams {
|
|
4
19
|
unitId: string;
|
|
5
20
|
subUnitId: string;
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
1
16
|
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
17
|
import { DocSelectionManagerService } from '../services/doc-selection-manager.service';
|
|
3
18
|
export declare class DocCustomRangeController extends Disposable {
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IUniverDocsConfig } from './config/config';
|
|
2
17
|
import { IConfigService, Injector, Plugin } from '@univerjs/core';
|
|
3
18
|
export declare class UniverDocsPlugin extends Plugin {
|
|
4
19
|
private readonly _config;
|
|
@@ -1,12 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { DocumentDataModel, IInterceptor, Nullable } from '@univerjs/core';
|
|
17
|
+
import type { DocumentViewModel, IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
18
|
+
import { Disposable, DisposableCollection } from '@univerjs/core';
|
|
3
19
|
import { DocSkeletonManagerService } from '../doc-skeleton-manager.service';
|
|
4
20
|
export declare class DocInterceptorService extends Disposable implements IRenderModule {
|
|
5
21
|
private readonly _context;
|
|
6
22
|
private readonly _docSkeletonManagerService;
|
|
7
23
|
private _interceptorsByName;
|
|
8
24
|
constructor(_context: IRenderContext<DocumentDataModel>, _docSkeletonManagerService: DocSkeletonManagerService);
|
|
9
|
-
intercept<T extends IInterceptor<any, any>>(name: T, interceptor: T): import(
|
|
25
|
+
intercept<T extends IInterceptor<any, any>>(name: T, interceptor: T): import("@wendellhu/redi").IDisposable;
|
|
10
26
|
fetchThroughInterceptors<T, C>(name: IInterceptor<T, C>): (initValue: Nullable<T>, initContext: C) => Nullable<T>;
|
|
11
27
|
interceptDocumentViewModel(viewModel: DocumentViewModel): DisposableCollection;
|
|
12
28
|
}
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICustomDecoration, ICustomDecorationForInterceptor, ICustomRange, ICustomRangeForInterceptor } from '@univerjs/core';
|
|
2
17
|
export declare const DOC_INTERCEPTOR_POINT: {
|
|
3
|
-
CUSTOM_RANGE: import(
|
|
18
|
+
CUSTOM_RANGE: import("@univerjs/core").IInterceptor<ICustomRangeForInterceptor, {
|
|
4
19
|
index: number;
|
|
5
20
|
unitId: string;
|
|
6
21
|
customRanges: ICustomRange[];
|
|
7
22
|
}>;
|
|
8
|
-
CUSTOM_DECORATION: import(
|
|
23
|
+
CUSTOM_DECORATION: import("@univerjs/core").IInterceptor<ICustomDecorationForInterceptor, {
|
|
9
24
|
index: number;
|
|
10
25
|
unitId: string;
|
|
11
26
|
customDecorations: ICustomDecoration[];
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { Nullable } from '@univerjs/core';
|
|
17
|
+
import type { IDocSelectionInnerParam, IRectRangeWithStyle, ISuccinctDocRangeParam, ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
|
+
import { ICommandService, IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
3
19
|
interface IDocSelectionManagerSearchParam {
|
|
4
20
|
unitId: string;
|
|
5
21
|
subUnitId: string;
|
|
@@ -22,9 +38,9 @@ export declare class DocSelectionManagerService extends RxDisposable {
|
|
|
22
38
|
private _currentSelection;
|
|
23
39
|
private readonly _textSelectionInfo;
|
|
24
40
|
private readonly _textSelection$;
|
|
25
|
-
readonly textSelection$: import(
|
|
41
|
+
readonly textSelection$: import("rxjs").Observable<ITextSelectionManagerInsertParam>;
|
|
26
42
|
private readonly _refreshSelection$;
|
|
27
|
-
readonly refreshSelection$: import(
|
|
43
|
+
readonly refreshSelection$: import("rxjs").Observable<Nullable<IRefreshSelectionParam>>;
|
|
28
44
|
constructor(_commandService: ICommandService, _univerInstanceService: IUniverInstanceService);
|
|
29
45
|
private _listenCurrentUnit;
|
|
30
46
|
__getCurrentSelection(): Nullable<IDocSelectionManagerSearchParam>;
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { DocumentDataModel, Nullable } from '@univerjs/core';
|
|
17
|
+
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
18
|
+
import { IUniverInstanceService, LocaleService, RxDisposable } from '@univerjs/core';
|
|
19
|
+
import { DocumentSkeleton, DocumentViewModel } from '@univerjs/engine-render';
|
|
3
20
|
/**
|
|
4
21
|
* This service is for document build and manage doc skeletons. It also manages
|
|
5
22
|
* DocumentViewModels.
|
|
@@ -11,11 +28,11 @@ export declare class DocSkeletonManagerService extends RxDisposable implements I
|
|
|
11
28
|
private _skeleton;
|
|
12
29
|
private _docViewModel;
|
|
13
30
|
private readonly _currentSkeleton$;
|
|
14
|
-
readonly currentSkeleton$: import(
|
|
31
|
+
readonly currentSkeleton$: import("rxjs").Observable<Nullable<DocumentSkeleton>>;
|
|
15
32
|
private readonly _currentSkeletonBefore$;
|
|
16
|
-
readonly currentSkeletonBefore$: import(
|
|
33
|
+
readonly currentSkeletonBefore$: import("rxjs").Observable<Nullable<DocumentSkeleton>>;
|
|
17
34
|
private readonly _currentViewModel$;
|
|
18
|
-
readonly currentViewModel$: import(
|
|
35
|
+
readonly currentViewModel$: import("rxjs").Observable<Nullable<DocumentViewModel>>;
|
|
19
36
|
constructor(_context: IRenderContext<DocumentDataModel>, _localeService: LocaleService, _univerInstanceService: IUniverInstanceService);
|
|
20
37
|
dispose(): void;
|
|
21
38
|
getSkeleton(): DocumentSkeleton;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { JSONXActions, Nullable } from '@univerjs/core';
|
|
17
|
+
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
|
+
import { RxDisposable } from '@univerjs/core';
|
|
3
19
|
interface IDocChangeState {
|
|
4
20
|
actions: JSONXActions;
|
|
5
21
|
textRanges: Nullable<ITextRangeWithStyle[]>;
|
|
@@ -21,7 +37,7 @@ export interface IDocStateChangeInfo extends IDocStateChangeParams {
|
|
|
21
37
|
}
|
|
22
38
|
export declare class DocStateEmitService extends RxDisposable {
|
|
23
39
|
private readonly _docStateChangeParams$;
|
|
24
|
-
readonly docStateChangeParams$: import(
|
|
40
|
+
readonly docStateChangeParams$: import("rxjs").Observable<Nullable<IDocStateChangeInfo>>;
|
|
25
41
|
constructor();
|
|
26
42
|
emitStateChangeInfo(params: IDocStateChangeInfo): void;
|
|
27
43
|
dispose(): void;
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { DocumentDataModel, Nullable } from '@univerjs/core';
|
|
17
|
+
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
18
|
+
import { IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
19
|
+
import { DocumentViewModel } from '@univerjs/engine-render';
|
|
3
20
|
export interface IDocumentViewModelManagerParam {
|
|
4
21
|
unitId: string;
|
|
5
22
|
docViewModel: DocumentViewModel;
|
|
@@ -13,9 +30,9 @@ export declare class DocViewModelManagerService extends RxDisposable implements
|
|
|
13
30
|
private readonly _univerInstanceService;
|
|
14
31
|
private _docViewModelMap;
|
|
15
32
|
private readonly _currentDocViewModel$;
|
|
16
|
-
readonly currentDocViewModel$: import(
|
|
33
|
+
readonly currentDocViewModel$: import("rxjs").Observable<Nullable<IDocumentViewModelManagerParam>>;
|
|
17
34
|
private readonly _docViewModelAdd$;
|
|
18
|
-
readonly docViewModelAdd$: import(
|
|
35
|
+
readonly docViewModelAdd$: import("rxjs").Observable<DocumentViewModel>;
|
|
19
36
|
constructor(_context: IRenderContext<DocumentDataModel>, _univerInstanceService: IUniverInstanceService);
|
|
20
37
|
private _initialize;
|
|
21
38
|
dispose(): void;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { CustomRangeType, DocumentDataModel, IAccessor, IAddCustomRangeTextXParam, IDocumentBody, IMutationInfo, ITextRangeParam, Nullable, TextX } from '@univerjs/core';
|
|
17
|
+
import type { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
|
|
3
18
|
interface IAddCustomRangeParam extends IAddCustomRangeTextXParam {
|
|
4
19
|
unitId: string;
|
|
5
20
|
}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { DocumentDataModel, IAccessor, IDocumentBody, IMutationInfo, ITextRangeParam, TextX } from '@univerjs/core';
|
|
17
|
+
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
|
+
import type { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
|
|
4
19
|
export interface IReplaceSelectionFactoryParams {
|
|
5
20
|
unitId: string;
|
|
6
21
|
/**
|
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")):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,p){"use strict";var de=Object.defineProperty;var ge=(l,r,v)=>r in l?de(l,r,{enumerable:!0,configurable:!0,writable:!0,value:v}):l[r]=v;var g=(l,r,v)=>ge(l,typeof r!="symbol"?r+"":r,v);var M;const T={id:"doc.operation.set-selections",type:r.CommandType.OPERATION,handler:()=>!0};var z=Object.getOwnPropertyDescriptor,G=(c,s,e,t)=>{for(var n=t>1?void 0:t?z(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},N=(c,s)=>(e,t)=>s(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 p.Subject);g(this,"textSelection$",this._textSelection$.asObservable());g(this,"_refreshSelection$",new p.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(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 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,i){if(t==null)return;const{unitId:o,subUnitId:a}=t;this._refreshSelection$.next({unitId:o,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:o,segmentId:a,style:u,textRanges:d,rectRanges:h,isEditing:_}=n,I=[...d,...h].filter(S=>S.startOffset!=null&&S.endOffset!=null).sort((S,f)=>S.startOffset>f.startOffset?1:S.startOffset<f.startOffset?-1:0);this._commandService.executeCommand(T.id,{unitId:i,subUnitId:o,segmentId:a,style:u,isEditing:_,ranges:I})}dispose(){this._textSelection$.complete(),this._refreshSelection$.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,o=[...n,...i],{unitId:a,subUnitId:u}=e;this._refreshSelection$.next({unitId:a,subUnitId:u,docRanges:o,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 o=this._textSelectionInfo.get(t);o.has(n)?o.get(n).textRanges.push(...e.textRanges):o.set(n,{...i})}},l.DocSelectionManagerService=G([N(0,r.ICommandService),N(1,r.IUniverInstanceService)],l.DocSelectionManagerService);var W=Object.getOwnPropertyDescriptor,J=(c,s,e,t)=>{for(var n=t>1?void 0:t?W(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},$=(c,s)=>(e,t)=>s(e,t,c);l.DocSkeletonManagerService=class extends r.RxDisposable{constructor(e,t,n){super();g(this,"_skeleton");g(this,"_docViewModel");g(this,"_currentSkeleton$",new p.BehaviorSubject(null));g(this,"currentSkeleton$",this._currentSkeleton$.asObservable());g(this,"_currentSkeletonBefore$",new p.BehaviorSubject(null));g(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());g(this,"_currentViewModel$",new p.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(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&&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([$(1,r.Inject(r.LocaleService)),$(2,r.IUniverInstanceService)],l.DocSkeletonManagerService);class U extends r.RxDisposable{constructor(){super();g(this,"_docStateChangeParams$",new p.BehaviorSubject(null));g(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const P="doc.mutation.rich-text-editing",O={id:P,type:r.CommandType.MUTATION,handler:(c,s)=>{var F,L;const{unitId:e,segmentId:t="",actions:n,textRanges:i,prevTextRanges:o,trigger:a,noHistory:u,isCompositionEnd:d,noNeedSetTextRange:h,debounce:_,isEditing:I=!0,isSync:S,syncer:f}=s,D=c.get(r.IUniverInstanceService),R=c.get(v.IRenderManagerService),C=c.get(U),m=D.getUniverDocInstance(e),j=(F=R.getRenderById(e))==null?void 0:F.with(l.DocSkeletonManagerService).getViewModel();if(m==null||j==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const A=c.get(l.DocSelectionManagerService),E=(L=A.getDocRanges())!=null?L:[],le=!!m.getSnapshot().disabled;if(r.JSONX.isNoop(n)||n&&n.length===0||le)return{unitId:e,actions:[],textRanges:E};const X=r.JSONX.invertWithDoc(n,m.getSnapshot());m.apply(n),j.reset(m),!h&&i&&a!=null&&!S&&queueMicrotask(()=>{A.replaceDocRanges(i,{unitId:e,subUnitId:e},I,s.options)});const ue={commandId:P,unitId:e,segmentId:t,trigger:a,noHistory:u,debounce:_,redoState:{actions:n,textRanges:i},undoState:{actions:X,textRanges:o!=null?o:E},isCompositionEnd:d,isSync:S,syncer:f};return C.emitStateChangeInfo(ue),{unitId:e,actions:X,textRanges:E}}},B={name:"@univerjs/docs",version:"0.17.0"},Y={id:"doc.mutation.rename-doc",type:r.CommandType.MUTATION,handler:(c,s)=>{const t=c.get(r.IUniverInstanceService).getUnit(s.unitId,r.UniverInstanceType.UNIVER_DOC);return t?(t.setName(s.name),!0):!1}},K="docs.config",k={};var q=Object.getOwnPropertyDescriptor,H=(c,s,e,t)=>{for(var n=t>1?void 0:t?q(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},b=(c,s)=>(e,t)=>s(e,t,c);let x=class extends r.Disposable{constructor(c,s,e){super(),this._commandService=c,this._textSelectionManagerService=s,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(c,s){var o;const{startOffset:e,endOffset:t,collapsed:n}=s,i=(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(i!=null&&i.length){let a=e,u=t;return i.forEach(d=>{a=Math.min(d.startIndex,a),u=Math.max(d.endIndex+1,u)}),{...s,startOffset:a,endOffset:u,collapsed:a===u}}return s}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(c=>{if(c.id===T.id){const s=c.params,{unitId:e,ranges:t,isEditing:n}=s,i=this._univerInstanceService.getUnit(e);if(!i)return;const o=t.map(a=>this._transformCustomRange(i,a));o.some((a,u)=>t[u]!==a)&&this._textSelectionManagerService.replaceTextRanges(o,n)}}))}};x=H([b(0,r.ICommandService),b(1,r.Inject(l.DocSelectionManagerService)),b(2,r.IUniverInstanceService)],x);var Q=Object.getOwnPropertyDescriptor,Z=(c,s,e,t)=>{for(var n=t>1?void 0:t?Q(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},V=(c,s)=>(e,t)=>s(e,t,c);l.UniverDocsPlugin=(M=class extends r.Plugin{constructor(s=k,e,t){super(),this._config=s,this._injector=e,this._configService=t;const{...n}=r.merge({},k,this._config);this._configService.setConfig(K,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[O,Y,T].forEach(s=>{this._injector.get(r.ICommandService).registerCommand(s)})}_initializeDependencies(){[[l.DocSelectionManagerService],[U],[x]].forEach(s=>this._injector.add(s))}onReady(){this._injector.get(x)}},g(M,"pluginName","DOCS_PLUGIN"),g(M,"packageName",B.name),g(M,"version",B.version),M),l.UniverDocsPlugin=Z([V(1,r.Inject(r.Injector)),V(2,r.IConfigService)],l.UniverDocsPlugin);const ee=r.createInterceptorKey("CUSTOM_RANGE"),te=r.createInterceptorKey("CUSTOM_DECORATION"),y={CUSTOM_RANGE:ee,CUSTOM_DECORATION:te};var ne=Object.getOwnPropertyDescriptor,ie=(c,s,e,t)=>{for(var n=t>1?void 0:t?ne(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},se=(c,s)=>(e,t)=>s(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(),i=n.getDataModel().getUnitId();if(i===r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===r.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(n)),this.disposeWithMe(this.intercept(y.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 i=this._interceptorsByName.get(n);return i.push(t),this._interceptorsByName.set(n,i.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 i;return this.fetchThroughInterceptors(y.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(y.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(i=e.getDataModel().getCustomDecorations())!=null?i:[]})}})),t}},l.DocInterceptorService=ie([se(1,r.Inject(l.DocSkeletonManagerService))],l.DocInterceptorService);function w(c,s=""){if(!s)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[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 re(c,s,e){const{unitId:t,segmentId:n}=s,o=c.get(r.IUniverInstanceService).getUnit(t);if(!o)return!1;const a={id:O.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},u=r.JSONX.getInstance(),d=r.BuildTextUtils.customRange.add({...s,body:e});if(!d)return!1;const h=w(o,n);return a.params.actions=u.editOp(d.serialize(),h),a}function oe(c,s){var m;const{rangeId:e,rangeType:t,wholeEntity:n,properties:i,unitId:o,selections:a}=s,u=c.get(l.DocSelectionManagerService),d=c.get(r.IUniverInstanceService),h=a!=null?a:u.getTextRanges({unitId:o,subUnitId:o}),_=(m=h==null?void 0:h[0])==null?void 0:m.segmentId;if(!(h!=null&&h.length))return!1;const I=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!I)return!1;const S=I.getSelfOrHeaderFooterModel(_).getBody();if(!S)return!1;const f=r.BuildTextUtils.customRange.add({ranges:h,rangeId:e,rangeType:t,segmentId:_,wholeEntity:n,properties:i,body:S});if(!f)return!1;const D=r.JSONX.getInstance(),R={id:O.id,params:{unitId:o,actions:[],textRanges:f.selections,segmentId:_},textX:f},C=w(I,_);return R.params.actions=D.editOp(f.serialize(),C),R}function ce(c,s){const{unitId:e,segmentId:t,insert:n}=s,o=c.get(r.IUniverInstanceService).getUnit(e);if(!o)return!1;const a={id:O.id,params:{unitId:s.unitId,actions:[],textRanges:void 0,segmentId:t}},u=r.JSONX.getInstance(),d=r.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:s.rangeId,insert:n,segmentId:t});if(!d)return!1;const h=w(o,t);return a.params.actions=u.editOp(d.serialize(),h),a.params.textRanges=d.selections,a}function ae(c,s){var f,D,R,C;const{unitId:e,body:t,doc:n}=s;let i=n;if(i||(i=c.get(r.IUniverInstanceService).getUnit(e)),!i)return!1;const o=(f=s.selection)==null?void 0:f.segmentId,a=(D=i.getSelfOrHeaderFooterModel(o))==null?void 0:D.getBody();if(!a)return!1;const u=c.get(l.DocSelectionManagerService),d=(R=s.selection)!=null?R:u.getActiveTextRange();if(!d||!a)return!1;const h=(C=s.textRanges)!=null?C:[{startOffset:d.startOffset+t.dataStream.length,endOffset:d.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],_=r.BuildTextUtils.selection.replace({selection:d,body:t,doc:i});if(!_)return!1;const I={id:O.id,params:{unitId:e,actions:[],textRanges:h,debounce:!0,segmentId:o},textX:_},S=r.JSONX.getInstance();return I.params.actions=S.editOp(_.serialize()),I}l.DOC_INTERCEPTOR_POINT=y,l.DocStateEmitService=U,l.RichTextEditingMutation=O,l.SetTextSelectionsOperation=T,l.addCustomRangeBySelectionFactory=oe,l.addCustomRangeFactory=re,l.deleteCustomRangeFactory=ce,l.replaceSelectionFactory=ae,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocs={},e.UniverCore,e.UniverEngineRender,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i={id:`doc.operation.set-selections`,type:t.CommandType.OPERATION,handler:()=>!0};function a(e){"@babel/helpers - typeof";return a=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},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(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 d=class extends t.RxDisposable{constructor(e,t){super(),this._commandService=e,this._univerInstanceService=t,c(this,`_currentSelection`,null),c(this,`_textSelectionInfo`,new Map),c(this,`_textSelection$`,new r.Subject),c(this,`textSelection$`,this._textSelection$.asObservable()),c(this,`_refreshSelection$`,new r.BehaviorSubject(null)),c(this,`refreshSelection$`,this._refreshSelection$.asObservable()),this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,r.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,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:``,segmentPage:-1,isEditing:t,style:n.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:r,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(i.id,{unitId:r,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})}};d=u([l(0,t.ICommandService),l(1,t.IUniverInstanceService)],d);let f=class extends t.RxDisposable{constructor(e,n,i){super(),this._context=e,this._localeService=n,this._univerInstanceService=i,c(this,`_skeleton`,void 0),c(this,`_docViewModel`,void 0),c(this,`_currentSkeleton$`,new r.BehaviorSubject(null)),c(this,`currentSkeleton$`,this._currentSkeleton$.asObservable()),c(this,`_currentSkeletonBefore$`,new r.BehaviorSubject(null)),c(this,`currentSkeletonBefore$`,this._currentSkeletonBefore$.asObservable()),c(this,`_currentViewModel$`,new r.BehaviorSubject(null)),c(this,`currentViewModel$`,this._currentViewModel$.asObservable()),this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,r.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(e){let n=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&(0,t.isInternalEditorID)(n)?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),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 n.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new n.DocumentViewModel(e)}};f=u([l(1,(0,t.Inject)(t.LocaleService)),l(2,t.IUniverInstanceService)],f);var p=class extends t.RxDisposable{constructor(){super(),c(this,`_docStateChangeParams$`,new r.BehaviorSubject(null)),c(this,`docStateChangeParams$`,this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}};let m=`doc.mutation.rich-text-editing`,h={id:m,type:t.CommandType.MUTATION,handler:(e,r)=>{var i,a;let{unitId:o,segmentId:s=``,actions:c,textRanges:l,prevTextRanges:u,trigger:h,noHistory:g,isCompositionEnd:_,noNeedSetTextRange:v,debounce:y,isEditing:b=!0,isSync:x,syncer:S}=r,C=e.get(t.IUniverInstanceService),w=e.get(n.IRenderManagerService),T=e.get(p),E=C.getUniverDocInstance(o),D=(i=w.getRenderById(o))==null?void 0:i.with(f).getViewModel();if(E==null||D==null)throw Error(`DocumentDataModel or documentViewModel not found for unitId: ${o}`);let O=e.get(d),k=(a=O.getDocRanges())==null?[]:a,A=!!E.getSnapshot().disabled;if(t.JSONX.isNoop(c)||c&&c.length===0||A)return{unitId:o,actions:[],textRanges:k};let j=t.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:m,unitId:o,segmentId:s,trigger:h,noHistory:g,debounce:y,redoState:{actions:c,textRanges:l},undoState:{actions:j,textRanges:u==null?k:u},isCompositionEnd:_,isSync:x,syncer:S};return T.emitStateChangeInfo(M),{unitId:o,actions:j,textRanges:k}}};var g=`@univerjs/docs`,_=`0.18.0`;let v={id:`doc.mutation.rename-doc`,type:t.CommandType.MUTATION,handler:(e,n)=>{let r=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);return r?(r.setName(n.name),!0):!1}},y=`docs.config`;Symbol(y);let b={},x=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,this._initSelectionChange()}_transformCustomRange(e,n){var r;let{startOffset:i,endOffset:a,collapsed:o}=n,s=(r=e.getCustomRanges())==null?void 0:r.filter(e=>!e.wholeEntity||i<=e.startIndex&&a>e.endIndex?!1:o?e.startIndex<i&&e.endIndex>=a:t.BuildTextUtils.range.isIntersects(i,a-1,e.startIndex,e.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===i.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)}}))}};x=u([l(0,t.ICommandService),l(1,(0,t.Inject)(d)),l(2,t.IUniverInstanceService)],x);let S=class extends t.Plugin{constructor(e=b,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},b,this._config);this._configService.setConfig(y,i)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[h,v,i].forEach(e=>{this._injector.get(t.ICommandService).registerCommand(e)})}_initializeDependencies(){[[d],[p],[x]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(x)}};c(S,`pluginName`,`DOCS_PLUGIN`),c(S,`packageName`,g),c(S,`version`,_),S=u([l(1,(0,t.Inject)(t.Injector)),l(2,t.IConfigService)],S);let C={CUSTOM_RANGE:(0,t.createInterceptorKey)(`CUSTOM_RANGE`),CUSTOM_DECORATION:(0,t.createInterceptorKey)(`CUSTOM_DECORATION`)},w=class extends t.Disposable{constructor(e,n){super(),this._context=e,this._docSkeletonManagerService=n,c(this,`_interceptorsByName`,new Map);let r=this._docSkeletonManagerService.getViewModel(),i=r.getDataModel().getUnitId();if(i===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(r)),this.disposeWithMe(this.intercept(C.CUSTOM_RANGE,{priority:-1,handler:(e,t,n)=>n(e)}));let a=new t.DisposableCollection;r.segmentViewModels$.subscribe(e=>{a.dispose(),a=new t.DisposableCollection,e.forEach(e=>{a.add(this.interceptDocumentViewModel(e))})}),this.disposeWithMe(a)}intercept(e,n){let r=e;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,t.toDisposable)(()=>(0,t.remove)(this._interceptorsByName.get(r),n)))}fetchThroughInterceptors(e){let n=e;return(0,t.composeInterceptors)(this._interceptorsByName.get(n)||[])}interceptDocumentViewModel(e){let n=new t.DisposableCollection;return n.add(e.registerCustomRangeInterceptor({getCustomRange:t=>{var n;return this.fetchThroughInterceptors(C.CUSTOM_RANGE)(e.getCustomRangeRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customRanges:(n=e.getDataModel().getCustomRanges())==null?[]:n})},getCustomDecoration:t=>{var n;return this.fetchThroughInterceptors(C.CUSTOM_DECORATION)(e.getCustomDecorationRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customDecorations:(n=e.getDataModel().getCustomDecorations())==null?[]:n})}})),n}};w=u([l(1,(0,t.Inject)(f))],w);function T(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 E(e,n,r){let{unitId:i,segmentId:a}=n,o=e.get(t.IUniverInstanceService).getUnit(i);if(!o)return!1;let s={id:h.id,params:{unitId:n.unitId,actions:[],textRanges:void 0}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.add({...n,body:r});if(!l)return!1;let u=T(o,a);return s.params.actions=c.editOp(l.serialize(),u),s}function D(e,n){var r;let{rangeId:i,rangeType:a,wholeEntity:o,properties:s,unitId:c,selections:l}=n,u=e.get(d),f=e.get(t.IUniverInstanceService),p=l==null?u.getTextRanges({unitId:c,subUnitId:c}):l,m=p==null||(r=p[0])==null?void 0:r.segmentId;if(!(p!=null&&p.length))return!1;let g=f.getUnit(c,t.UniverInstanceType.UNIVER_DOC);if(!g)return!1;let _=g.getSelfOrHeaderFooterModel(m).getBody();if(!_)return!1;let v=t.BuildTextUtils.customRange.add({ranges:p,rangeId:i,rangeType:a,segmentId:m,wholeEntity:o,properties:s,body:_});if(!v)return!1;let y=t.JSONX.getInstance(),b={id:h.id,params:{unitId:c,actions:[],textRanges:v.selections,segmentId:m},textX:v},x=T(g,m);return b.params.actions=y.editOp(v.serialize(),x),b}function O(e,n){let{unitId:r,segmentId:i,insert:a}=n,o=e.get(t.IUniverInstanceService).getUnit(r);if(!o)return!1;let s={id:h.id,params:{unitId:n.unitId,actions:[],textRanges:void 0,segmentId:i}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:n.rangeId,insert:a,segmentId:i});if(!l)return!1;let u=T(o,i);return s.params.actions=c.editOp(l.serialize(),u),s.params.textRanges=l.selections,s}function k(e,n){var r,i,a,o;let{unitId:s,body:c,doc:l}=n,u=l;if(u||(u=e.get(t.IUniverInstanceService).getUnit(s)),!u)return!1;let f=(r=n.selection)==null?void 0:r.segmentId,p=(i=u.getSelfOrHeaderFooterModel(f))==null?void 0:i.getBody();if(!p)return!1;let m=e.get(d),g=(a=n.selection)==null?m.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=t.BuildTextUtils.selection.replace({selection:g,body:c,doc:u});if(!v)return!1;let y={id:h.id,params:{unitId:s,actions:[],textRanges:_,debounce:!0,segmentId:f},textX:v},b=t.JSONX.getInstance();return y.params.actions=b.editOp(v.serialize()),y}e.DOC_INTERCEPTOR_POINT=C,Object.defineProperty(e,`DocInterceptorService`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(e,`DocSelectionManagerService`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,`DocSkeletonManagerService`,{enumerable:!0,get:function(){return f}}),e.DocStateEmitService=p,e.RichTextEditingMutation=h,e.SetTextSelectionsOperation=i,Object.defineProperty(e,`UniverDocsPlugin`,{enumerable:!0,get:function(){return S}}),e.addCustomRangeBySelectionFactory=D,e.addCustomRangeFactory=E,e.deleteCustomRangeFactory=O,e.replaceSelectionFactory=k});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet normal base-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -48,22 +48,23 @@
|
|
|
48
48
|
"rxjs": ">=7.0.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@univerjs/
|
|
52
|
-
"@univerjs/
|
|
51
|
+
"@univerjs/engine-render": "0.18.0",
|
|
52
|
+
"@univerjs/core": "0.18.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"rxjs": "^7.8.2",
|
|
56
56
|
"typescript": "^5.9.3",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"@univerjs-infra/shared": "0.17.0"
|
|
57
|
+
"vitest": "^4.1.0",
|
|
58
|
+
"@univerjs-infra/shared": "0.18.0"
|
|
60
59
|
},
|
|
61
60
|
"scripts": {
|
|
62
61
|
"test": "vitest run",
|
|
63
62
|
"test:watch": "vitest",
|
|
64
63
|
"coverage": "vitest run --coverage",
|
|
65
64
|
"typecheck": "tsc --noEmit",
|
|
66
|
-
"build": "univer-cli build"
|
|
65
|
+
"build:bundle": "univer-cli build",
|
|
66
|
+
"build:types": "tsc -p tsconfig.node.json",
|
|
67
|
+
"build": "pnpm run build:bundle && pnpm run build:types"
|
|
67
68
|
},
|
|
68
69
|
"module": "./lib/es/index.js"
|
|
69
70
|
}
|