@univerjs/docs 1.0.4 → 1.1.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/facade.js +10 -10
- package/lib/cjs/index.js +40 -25
- package/lib/es/facade.js +6 -6
- package/lib/es/index.js +34 -19
- package/lib/facade.js +6 -6
- package/lib/index.js +34 -19
- package/lib/types/services/doc-skeleton-manager.service.d.ts +3 -2
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AlignTypeH, BooleanNumber, BuildTextUtils, ColumnSeparatorType, CommandType, CustomCommandExecutionError, CustomRangeType, DEFAULT_STYLES, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DataStreamTreeTokenType, DeleteDirection, DependentOn, Disposable, DisposableCollection, DocumentDataModel, DocumentFlavor, DocxBreakType, DrawingTypeEnum, ErrorService, ICommandService, IConfigService, ILogService, IPermissionService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSON1, JSONX, LocaleService, MODERN_DOCUMENT_DEFAULT_MARGIN, MODERN_DOCUMENT_WIDTH, MemoryCursor, ModernDocumentWidthMode, ObjectPermissionRuleModel, ObjectPermissionService, ObjectRelativeFromH, ObjectRelativeFromV, Optional, PAGE_SIZE, PageOrientType, PaperType, PermissionStatus, Plugin, PositionedObjectLayoutType, RESTORE_INSERTED_PARAGRAPH_IDS, RedoCommandId, RxDisposable, SectionType, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN, TextX, TextXActionType, Tools, UndoCommandId, UniverInstanceType, UpdateDocsAttributeType, composeInterceptors, containsInteriorInsertionOffset, createIdentifier, createInterceptorKey, createParagraphId, createSectionId, generateRandomId, getBlockRangeInterval, getColumnGroupRangeInterval, getParagraphContentStartOffset, getParagraphContentStartOffsets, getRichTextEditPath, getSdtBindingKey, getSdtBindingValue, getSectionHeaderFooterReferenceKey, getTableRangeInterval, isInternalEditorID, merge, remove, requestImmediateMacroTask, resolveSectionHeaderFooterReference, toDisposable, validateDocBodyStructure, validateDocumentStructure } from "@univerjs/core";
|
|
1
|
+
import { AlignTypeH, BooleanNumber, BuildTextUtils, ColumnSeparatorType, CommandType, CustomCommandExecutionError, CustomRangeType, DEFAULT_STYLES, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DataStreamTreeTokenType, DeleteDirection, DependentOn, Disposable, DisposableCollection, DocumentDataModel, DocumentFlavor, DocxBreakType, DrawingTypeEnum, ErrorService, ICommandService, IConfigService, ILogService, IPermissionService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSON1, JSONX, LocaleService, MODERN_DOCUMENT_DEFAULT_MARGIN, MODERN_DOCUMENT_WIDTH, MemoryCursor, ModernDocumentWidthMode, ObjectPermissionRuleModel, ObjectPermissionService, ObjectRelativeFromH, ObjectRelativeFromV, Optional, PAGE_SIZE, PageOrientType, PaperType, PermissionStatus, Plugin, PositionedObjectLayoutType, RESTORE_INSERTED_PARAGRAPH_IDS, RedoCommandId, RxDisposable, SHEET_TEXT_LINE_GAP, SectionType, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN, TextX, TextXActionType, Tools, UndoCommandId, UniverInstanceType, UpdateDocsAttributeType, composeInterceptors, containsInteriorInsertionOffset, createIdentifier, createInterceptorKey, createParagraphId, createSectionId, generateRandomId, getBlockRangeInterval, getColumnGroupRangeInterval, getParagraphContentStartOffset, getParagraphContentStartOffsets, getRichTextEditPath, getSdtBindingKey, getSdtBindingValue, getSectionHeaderFooterReferenceKey, getTableRangeInterval, isInternalEditorID, merge, remove, requestImmediateMacroTask, resolveSectionHeaderFooterReference, toDisposable, validateDocBodyStructure, validateDocumentStructure } from "@univerjs/core";
|
|
2
2
|
import { DocumentLayoutSession, DocumentSkeleton, DocumentViewModel, FontCache, IRenderManagerService, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, getDocsCustomBlockRenderViewport, getDocumentLayoutPresentation, getFontStyleString, setDocsCustomBlockRenderViewportProvider } from "@univerjs/engine-render";
|
|
3
3
|
import { BehaviorSubject, Observable, Subject, shareReplay, takeUntil } from "rxjs";
|
|
4
4
|
import { UnitAction, UnitObject } from "@univerjs/protocol";
|
|
@@ -14,7 +14,7 @@ const SetTextSelectionsOperation = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
//#endregion
|
|
17
|
-
//#region \0@oxc-project+runtime@0.
|
|
17
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
18
18
|
function _typeof(o) {
|
|
19
19
|
"@babel/helpers - typeof";
|
|
20
20
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -25,7 +25,7 @@ function _typeof(o) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
//#region \0@oxc-project+runtime@0.
|
|
28
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
29
29
|
function toPrimitive(t, r) {
|
|
30
30
|
if ("object" != _typeof(t) || !t) return t;
|
|
31
31
|
var e = t[Symbol.toPrimitive];
|
|
@@ -38,14 +38,14 @@ function toPrimitive(t, r) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
//#endregion
|
|
41
|
-
//#region \0@oxc-project+runtime@0.
|
|
41
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
42
42
|
function toPropertyKey(t) {
|
|
43
43
|
var i = toPrimitive(t, "string");
|
|
44
44
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
//#endregion
|
|
48
|
-
//#region \0@oxc-project+runtime@0.
|
|
48
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
49
49
|
function _defineProperty(e, r, t) {
|
|
50
50
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
51
51
|
value: t,
|
|
@@ -56,7 +56,7 @@ function _defineProperty(e, r, t) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
//#endregion
|
|
59
|
-
//#region \0@oxc-project+runtime@0.
|
|
59
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
60
60
|
function __decorateParam(paramIndex, decorator) {
|
|
61
61
|
return function(target, key) {
|
|
62
62
|
decorator(target, key, paramIndex);
|
|
@@ -64,7 +64,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
//#endregion
|
|
67
|
-
//#region \0@oxc-project+runtime@0.
|
|
67
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
68
68
|
function __decorate(decorators, target, key, desc) {
|
|
69
69
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
70
70
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -159,7 +159,10 @@ let DocSelectionManagerService = class DocSelectionManagerService extends RxDisp
|
|
|
159
159
|
subUnitId,
|
|
160
160
|
docRanges,
|
|
161
161
|
isEditing,
|
|
162
|
-
options
|
|
162
|
+
options: {
|
|
163
|
+
...options,
|
|
164
|
+
preserveInputStyle: false
|
|
165
|
+
}
|
|
163
166
|
});
|
|
164
167
|
}
|
|
165
168
|
/**
|
|
@@ -179,7 +182,13 @@ let DocSelectionManagerService = class DocSelectionManagerService extends RxDisp
|
|
|
179
182
|
...textSelectionInfo,
|
|
180
183
|
...search
|
|
181
184
|
};
|
|
182
|
-
this._replaceByParam(
|
|
185
|
+
this._replaceByParam({
|
|
186
|
+
...params,
|
|
187
|
+
options: {
|
|
188
|
+
...params.options,
|
|
189
|
+
preserveInputStyle: true
|
|
190
|
+
}
|
|
191
|
+
});
|
|
183
192
|
this._textSelection$.next(params);
|
|
184
193
|
const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params;
|
|
185
194
|
const ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => {
|
|
@@ -220,10 +229,11 @@ let DocSelectionManagerService = class DocSelectionManagerService extends RxDisp
|
|
|
220
229
|
subUnitId,
|
|
221
230
|
docRanges,
|
|
222
231
|
isEditing,
|
|
223
|
-
options:
|
|
232
|
+
options: {
|
|
224
233
|
...options,
|
|
225
|
-
forceFocus: false
|
|
226
|
-
|
|
234
|
+
forceFocus: false,
|
|
235
|
+
preserveInputStyle: (options === null || options === void 0 ? void 0 : options.preserveInputStyle) ?? true
|
|
236
|
+
}
|
|
227
237
|
});
|
|
228
238
|
}
|
|
229
239
|
_replaceByParam(insertParam) {
|
|
@@ -899,12 +909,13 @@ DocLayoutExecutorService = _DocLayoutExecutorService = __decorate([
|
|
|
899
909
|
//#endregion
|
|
900
910
|
//#region src/services/doc-skeleton-manager.service.ts
|
|
901
911
|
let DocSkeletonManagerService = class DocSkeletonManagerService extends RxDisposable {
|
|
902
|
-
constructor(_context, _localeService, _univerInstanceService, _docLayoutExecutorService) {
|
|
912
|
+
constructor(_context, _localeService, _univerInstanceService, _docLayoutExecutorService, _configService) {
|
|
903
913
|
super();
|
|
904
914
|
this._context = _context;
|
|
905
915
|
this._localeService = _localeService;
|
|
906
916
|
this._univerInstanceService = _univerInstanceService;
|
|
907
917
|
this._docLayoutExecutorService = _docLayoutExecutorService;
|
|
918
|
+
this._configService = _configService;
|
|
908
919
|
_defineProperty(this, "_skeleton", void 0);
|
|
909
920
|
_defineProperty(this, "_docViewModel", void 0);
|
|
910
921
|
_defineProperty(this, "_currentSkeleton$", new BehaviorSubject(null));
|
|
@@ -964,7 +975,8 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends RxDispos
|
|
|
964
975
|
this._currentViewModel$.next(this._docViewModel);
|
|
965
976
|
}
|
|
966
977
|
_buildSkeleton(documentViewModel) {
|
|
967
|
-
|
|
978
|
+
const isSheetEditor = this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || this._context.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;
|
|
979
|
+
return DocumentSkeleton.create(documentViewModel, this._localeService, { lineGap: isSheetEditor ? this._configService.getConfig(SHEET_TEXT_LINE_GAP) : void 0 });
|
|
968
980
|
}
|
|
969
981
|
_buildDocViewModel(documentDataModel) {
|
|
970
982
|
return new DocumentViewModel(documentDataModel);
|
|
@@ -973,7 +985,8 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends RxDispos
|
|
|
973
985
|
DocSkeletonManagerService = __decorate([
|
|
974
986
|
__decorateParam(1, Inject(LocaleService)),
|
|
975
987
|
__decorateParam(2, IUniverInstanceService),
|
|
976
|
-
__decorateParam(3, Inject(DocLayoutExecutorService))
|
|
988
|
+
__decorateParam(3, Inject(DocLayoutExecutorService)),
|
|
989
|
+
__decorateParam(4, IConfigService)
|
|
977
990
|
], DocSkeletonManagerService);
|
|
978
991
|
|
|
979
992
|
//#endregion
|
|
@@ -1372,13 +1385,15 @@ function scheduleDocumentSelectionUpdate(selectionManager, params, isSync) {
|
|
|
1372
1385
|
textRanges: logicalTextRanges,
|
|
1373
1386
|
rectRanges: [],
|
|
1374
1387
|
isEditing,
|
|
1375
|
-
options:
|
|
1388
|
+
options: {
|
|
1389
|
+
...params.options,
|
|
1390
|
+
preserveInputStyle: false
|
|
1391
|
+
}
|
|
1376
1392
|
}, selectionTarget);
|
|
1377
1393
|
const updatedSelection = selectionManager.getSelectionInfo(selectionTarget);
|
|
1378
1394
|
queueMicrotask(() => {
|
|
1379
1395
|
if (selectionManager.getSelectionInfo(selectionTarget) !== updatedSelection) return;
|
|
1380
|
-
|
|
1381
|
-
else selectionManager.refreshSelection(selectionTarget, isEditing);
|
|
1396
|
+
selectionManager.replaceDocRanges(logicalTextRanges, selectionTarget, isEditing, params.options);
|
|
1382
1397
|
});
|
|
1383
1398
|
}
|
|
1384
1399
|
/**
|
|
@@ -2786,7 +2801,7 @@ function composeActions(actions) {
|
|
|
2786
2801
|
//#endregion
|
|
2787
2802
|
//#region package.json
|
|
2788
2803
|
var name = "@univerjs/docs";
|
|
2789
|
-
var version = "1.0
|
|
2804
|
+
var version = "1.1.0";
|
|
2790
2805
|
|
|
2791
2806
|
//#endregion
|
|
2792
2807
|
//#region src/config/config.ts
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { DocumentDataModel, Nullable } from '@univerjs/core';
|
|
17
17
|
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
18
|
-
import { IUniverInstanceService, LocaleService, RxDisposable } from '@univerjs/core';
|
|
18
|
+
import { IConfigService, IUniverInstanceService, LocaleService, RxDisposable } from '@univerjs/core';
|
|
19
19
|
import { DocumentSkeleton, DocumentViewModel } from '@univerjs/engine-render';
|
|
20
20
|
import { DocLayoutExecutorService } from './doc-layout-executor.service';
|
|
21
21
|
/**
|
|
@@ -27,6 +27,7 @@ export declare class DocSkeletonManagerService extends RxDisposable implements I
|
|
|
27
27
|
private readonly _localeService;
|
|
28
28
|
private readonly _univerInstanceService;
|
|
29
29
|
private readonly _docLayoutExecutorService;
|
|
30
|
+
private readonly _configService;
|
|
30
31
|
private _skeleton;
|
|
31
32
|
private _docViewModel;
|
|
32
33
|
private readonly _currentSkeleton$;
|
|
@@ -35,7 +36,7 @@ export declare class DocSkeletonManagerService extends RxDisposable implements I
|
|
|
35
36
|
readonly currentSkeletonBefore$: import("rxjs").Observable<Nullable<DocumentSkeleton>>;
|
|
36
37
|
private readonly _currentViewModel$;
|
|
37
38
|
readonly currentViewModel$: import("rxjs").Observable<Nullable<DocumentViewModel>>;
|
|
38
|
-
constructor(_context: Pick<IRenderContext<DocumentDataModel>, 'type' | 'unit' | 'unitId'>, _localeService: LocaleService, _univerInstanceService: IUniverInstanceService, _docLayoutExecutorService: DocLayoutExecutorService);
|
|
39
|
+
constructor(_context: Pick<IRenderContext<DocumentDataModel>, 'type' | 'unit' | 'unitId'>, _localeService: LocaleService, _univerInstanceService: IUniverInstanceService, _docLayoutExecutorService: DocLayoutExecutorService, _configService: IConfigService);
|
|
39
40
|
dispose(): void;
|
|
40
41
|
getSkeleton(): DocumentSkeleton;
|
|
41
42
|
getViewModel(): DocumentViewModel;
|
package/lib/umd/facade.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/docs"),require("@univerjs/protocol")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/docs`,`@univerjs/protocol`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsFacade={},e.UniverCore,e.UniverCoreFacade,e.UniverDocs,e.UniverProtocol))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=class{constructor(e,t,n){this._unitId=e,this._commandService=t,this._permissionService=n}async setObjectPermissions(e){return this._commandService.executeCommand(r.SetDocumentPermissionsCommand.id,{unitId:this._unitId,changes:e})}async setPoint(e,t){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:e,value:t})}getPoint(e){return(0,r.getDocumentPermissionValue)(this._permissionService,this._unitId,this._unitId,e)}async setEditable(e=!0){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:i.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:i.UnitAction.Edit,value:!1})}canEdit(){return(0,r.getDocumentPermissionValue)(this._permissionService,this._unitId,this._unitId,i.UnitAction.Edit)}},o=class{constructor(e,t,n,r,i=()=>[]){this._unitId=e,this._objectId=t,this._commandService=n,this._permissionService=r,this._getParentObjectIds=i}async setEditable(e=!0){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:i.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:i.UnitAction.Edit,value:!1})}canEdit(){return(0,r.canEditDocumentTargets)(this._permissionService,this._unitId,[...this._getParentObjectIds(),this._objectId])}};function s(e){return e==null?e:JSON.parse(JSON.stringify(e))}function c(e){return e.replace(/\r\n/g,`\r`).replace(/\n/g,`\r`)}function l(e,t){let n=c(e);return t&&n.length>1&&n.startsWith(`\r`)?1:0}function u(e,n={}){let r=c(e).slice(l(e,n.removeLeadingParagraphBreak)),i={dataStream:r,customDecorations:[],customRanges:[],textRuns:[]},a=[],o
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/docs"),require("@univerjs/protocol")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/docs`,`@univerjs/protocol`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsFacade={},e.UniverCore,e.UniverCoreFacade,e.UniverDocs,e.UniverProtocol))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=class{constructor(e,t,n){this._unitId=e,this._commandService=t,this._permissionService=n}async setObjectPermissions(e){return this._commandService.executeCommand(r.SetDocumentPermissionsCommand.id,{unitId:this._unitId,changes:e})}async setPoint(e,t){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:e,value:t})}getPoint(e){return(0,r.getDocumentPermissionValue)(this._permissionService,this._unitId,this._unitId,e)}async setEditable(e=!0){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:i.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:i.UnitAction.Edit,value:!1})}canEdit(){return(0,r.getDocumentPermissionValue)(this._permissionService,this._unitId,this._unitId,i.UnitAction.Edit)}},o=class{constructor(e,t,n,r,i=()=>[]){this._unitId=e,this._objectId=t,this._commandService=n,this._permissionService=r,this._getParentObjectIds=i}async setEditable(e=!0){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:i.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:i.UnitAction.Edit,value:!1})}canEdit(){return(0,r.canEditDocumentTargets)(this._permissionService,this._unitId,[...this._getParentObjectIds(),this._objectId])}};function s(e){return e==null?e:JSON.parse(JSON.stringify(e))}function c(e){return e.replace(/\r\n/g,`\r`).replace(/\n/g,`\r`)}function l(e,t){let n=c(e);return t&&n.length>1&&n.startsWith(`\r`)?1:0}function u(e,n={}){let r=c(e).slice(l(e,n.removeLeadingParagraphBreak)),i={dataStream:r,customDecorations:[],customRanges:[],textRuns:[]},a=[],o=/* @__PURE__ */ new Set;for(let e=0;e<r.length;e++)r[e]===`\r`&&a.push({startIndex:e,paragraphId:(0,t.createParagraphId)(o),...n.paragraphStyle==null?{}:{paragraphStyle:s(n.paragraphStyle)}});return a.length>0&&(i.paragraphs=a),i}function d(e,t,n,i){let{startOffset:a,endOffset:o,segmentId:s}=e;return!!i.syncExecuteCommand(r.InsertTextCommand.id,{unitId:n.getUnitId(),body:t,range:{startOffset:a,endOffset:o,collapsed:a===o,segmentId:s},segmentId:s,debounce:!1,textRanges:[],noNeedSetTextRange:!0,isEditing:!1})}function f(e,n,i,a,o){var s,c;let{startOffset:l,endOffset:u,segmentId:d}=e,f=o.get(t.ICommandService);if((s=n.textRuns)!=null&&s.length&&((c=a.getSelfOrHeaderFooterModel(d))==null||(c=c.getBody())==null?void 0:c.textRuns)==null){let e=t.JSONX.getInstance().replaceOp([...(0,t.getRichTextEditPath)(a,d),`textRuns`],void 0,[]);f.syncExecuteCommand(r.RichTextEditingMutation.id,{unitId:a.getUnitId(),segmentId:d,actions:e,textRanges:[],isEditing:!1})}let p=new t.TextX;l>0&&p.push({t:t.TextXActionType.RETAIN,len:l}),p.push({t:t.TextXActionType.RETAIN,body:n,coverType:i,len:u-l});let m=t.JSONX.getInstance().editOp(p.serialize(),(0,t.getRichTextEditPath)(a,d)),h=f.syncExecuteCommand(r.RichTextEditingMutation.id,{unitId:a.getUnitId(),segmentId:d,actions:m,textRanges:[],isEditing:!1});return!!(h!=null&&h.actions&&h.actions.length>0)}function p(e){return Array.from(e).map(e=>e===t.DataStreamTreeTokenType.PARAGRAPH?`
|
|
2
2
|
`:e).filter(e=>e!==t.DataStreamTreeTokenType.BLOCK_START&&e!==t.DataStreamTreeTokenType.BLOCK_END&&e!==t.DataStreamTreeTokenType.SECTION_BREAK).join(``).replace(/\n$/,``)}function m(e,t){return function(n,r){t(n,r,e)}}function h(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 g=class extends n.FBaseInitialable{constructor(e,t,n,r,i,a){super(i),this._document=e,this._startOffset=t,this._endOffset=n,this._segmentId=r,this._injector=i,this._commandService=a,this._validateRange()}getRange(){return{startOffset:this._startOffset,endOffset:this._endOffset,segmentId:this._segmentId}}getText(){return this._document.getBody(this._segmentId).dataStream.slice(this._startOffset,this._endOffset)}getExplicitTextStyleRuns(){let{textRuns:e=[]}=this._document.getBody(this._segmentId);return e.filter(e=>e.st<this._endOffset&&e.ed>this._startOffset).map(e=>({startOffset:Math.max(e.st,this._startOffset),endOffset:Math.min(e.ed,this._endOffset),textStyle:t.Tools.deepClone(e.ts??{})}))}getCommonExplicitTextStyle(){if(this._startOffset===this._endOffset)return{};let[e,...n]=this._getStyleSegments(),r=t.Tools.deepClone(e.textStyle);for(let e of Object.keys(r))n.some(t=>!_(t.textStyle[e],r[e]))&&delete r[e];return r}describe(){let e=this.getExplicitTextStyleRuns(),t=this.getCommonExplicitTextStyle();return{...this.getRange(),text:this.getText(),length:this._endOffset-this._startOffset,explicitTextStyleRuns:e,commonExplicitTextStyle:t}}setTextStyle(e){return this._startOffset!==this._endOffset&&f(this.getRange(),{dataStream:``,textRuns:[{st:0,ed:this._endOffset-this._startOffset,ts:t.Tools.deepClone(e)}]},t.UpdateDocsAttributeType.COVER,this._document.getDocumentDataModel(),this._injector)}setText(e){return d(this.getRange(),u(e),this._document.getDocumentDataModel(),this._commandService)}_validateRange(){let e=this._document.getBody(this._segmentId).dataStream.length;if(!Number.isInteger(this._startOffset)||!Number.isInteger(this._endOffset)||this._startOffset<0||this._endOffset<this._startOffset||this._endOffset>e)throw RangeError(`Invalid document text range [${this._startOffset}, ${this._endOffset}) for body length ${e}.`)}_getStyleSegments(){let e=this.getExplicitTextStyleRuns(),t=[],n=this._startOffset;for(let r of e)n<r.startOffset&&t.push({startOffset:n,endOffset:r.startOffset,textStyle:{}}),t.push(r),n=r.endOffset;return n<this._endOffset&&t.push({startOffset:n,endOffset:this._endOffset,textStyle:{}}),t}};g=h([m(5,t.ICommandService)],g);function _(e,t){return JSON.stringify(e)===JSON.stringify(t)}let v=class extends n.FBaseInitialable{constructor(e,t,n=``,r,i,a){super(r),this._document=e,this._paragraphId=t,this._segmentId=n,this._injector=r,this._commandService=i,this._permissionService=a}getId(){return this._paragraphId}getSegmentId(){return this._segmentId}getPermission(){return new o(this._document.getId(),(0,r.getDocumentParagraphPermissionObjectId)(this._segmentId,this._paragraphId),this._commandService,this._permissionService,()=>(0,r.getDocumentParagraphParentPermissionObjectIds)(this._document.getDocumentDataModel(),this._segmentId,this._paragraphId))}getInfo(){let e=this._document.getBody(this._segmentId),{paragraphs:n=[]}=e,r=n.map((e,t)=>({paragraph:e,paragraphIndex:t})).filter(({paragraph:e})=>e.paragraphId===this._paragraphId);if(r.length===0)throw Error(`Document paragraph with id ${this._paragraphId} not found`);if(r.length>1)throw Error(`Multiple document paragraphs with id ${this._paragraphId} found`);let{paragraph:i,paragraphIndex:a}=r[0];return{paragraph:i,paragraphIndex:a,startOffset:(0,t.getParagraphContentStartOffset)(e,i),endOffset:i.startIndex}}getRange(){let{startOffset:e,endOffset:t}=this.getInfo();return{startOffset:e,endOffset:t,segmentId:this._segmentId}}getTextRange(){let{startOffset:e,endOffset:t}=this.getInfo();return this._injector.createInstance(g,this._document,e,t,this._segmentId,this._injector)}findText(e,t={}){let n=t.occurrence??0;if(!Number.isInteger(n)||n<0)throw RangeError(`Text occurrence must be a non-negative integer.`);return this.findAllText(e,t)[n]??null}findAllText(e,n={}){if(e.length===0)throw TypeError(`Text to find must not be empty.`);let r=n.matchCase??!0,i=this.getText(),a=t.regexp.createLiteralRegExp(e,r?`gu`:`giu`),{startOffset:o}=this.getInfo(),s=[];for(let e of i.matchAll(a)){let t=o+e.index;s.push(this._injector.createInstance(g,this._document,t,t+e[0].length,this._segmentId,this._injector))}return s}getText(){let{dataStream:e}=this._document.getBody(this._segmentId),{startOffset:t,endOffset:n}=this.getInfo();return e.slice(t,n)}setText(e){let{startOffset:t,endOffset:n}=this.getInfo();return d({startOffset:t,endOffset:n,segmentId:this._segmentId},u(e),this._document.getDocumentDataModel(),this._commandService)}appendText(e){let{endOffset:t}=this.getInfo();return this._document.insertText(t,e,this._segmentId)}setStyle(e){let{startOffset:t,endOffset:n}=this.getInfo();return this._commandService.syncExecuteCommand(r.UpdateDocumentParagraphStyleCommand.id,{unitId:this._document.getId(),segmentId:this._segmentId,paragraphId:this._paragraphId,startOffset:t,endOffset:n,style:e})}isListItem(){let{paragraph:e}=this.getInfo();return!!e.bullet}isTask(){var e;let{paragraph:n}=this.getInfo(),r=(e=n.bullet)==null?void 0:e.listType;return r===t.PresetListType.CHECK_LIST||r===t.PresetListType.CHECK_LIST_CHECKED}setTaskChecked(e){if(!this.isTask())return!1;let{paragraph:n,endOffset:r}=this.getInfo(),i=n.bullet,a={dataStream:``,paragraphs:[{...n,startIndex:0,bullet:{...i,listType:e?t.PresetListType.CHECK_LIST_CHECKED:t.PresetListType.CHECK_LIST}}]};return this._preserveExplicitParagraphIds(a),f({startOffset:r,endOffset:r+1,segmentId:this._segmentId},a,t.UpdateDocsAttributeType.REPLACE,this._document.getDocumentDataModel(),this._injector)}remove(){let{startOffset:e,endOffset:t}=this.getInfo();return this._document.deleteRange({startOffset:e,endOffset:t+1,segmentId:this._segmentId})}_preserveExplicitParagraphIds(e){e[t.RESTORE_INSERTED_PARAGRAPH_IDS]=!0}};v=h([m(4,t.ICommandService),m(5,t.IPermissionService)],v);function y(e){return typeof e!=`object`||!e?!1:typeof e.getId==`function`&&typeof e.getSegmentId==`function`&&typeof e.getInfo==`function`&&typeof e.getRange==`function`}function b(e){let{pageNumberStart:n,pageSize:r,pageOrient:i,marginTop:a,marginBottom:o,marginLeft:s,marginRight:c}=e;if(n!=null&&(!Number.isInteger(n)||n<1))throw RangeError(`Section page number start must be a positive integer.`);if(r&&[r.width,r.height].some(e=>e!=null&&(!Number.isFinite(e)||e<=0)))throw RangeError(`Section page size must be finite and positive.`);if(i!=null&&!Object.values(t.PageOrientType).includes(i))throw RangeError(`Invalid section page orientation.`);if([a,o,s,c].some(e=>e!=null&&(!Number.isFinite(e)||e<0)))throw RangeError(`Section page margins must be finite and non-negative.`)}var x=class extends Error{constructor(){super(`Section column APIs are supported only in traditional documents. Use ColumnGroup APIs for modern documents, or resolve an unspecified document flavor first.`),this.name=`DocsSectionUnsupportedDocumentFlavorError`}};let S=class{constructor(e,t,n,r){this._document=e,this._sectionId=t,this._commandService=n,this._permissionService=r}getId(){return this._sectionId}getPermission(){return new o(this._document.getId(),(0,r.getDocumentSectionPermissionObjectId)(``,this._sectionId),this._commandService,this._permissionService)}getIndex(){return this._resolve().index}getConfig(){return this._getConfigSnapshot()}getRange(){return this._getRange(this._resolve().index)}getColumns(){return t.Tools.deepClone(this._getConfigSnapshot().columnProperties??[])}describe(){let{index:e}=this._resolve(),n=this._getConfigSnapshot(),r=n.columnProperties??[],i={defaultHeader:this._describeHeaderFooterReference(`header`,`default`),defaultFooter:this._describeHeaderFooterReference(`footer`,`default`),firstHeader:this._describeHeaderFooterReference(`header`,`first`),firstFooter:this._describeHeaderFooterReference(`footer`,`first`),evenHeader:this._describeHeaderFooterReference(`header`,`even`),evenFooter:this._describeHeaderFooterReference(`footer`,`even`)};return{sectionId:this._sectionId,index:e,range:this._getRange(e),columnCount:r.length||1,columns:t.Tools.deepClone(r),columnSeparatorType:n.columnSeparatorType??t.ColumnSeparatorType.NONE,sectionType:n.sectionType??t.SectionType.SECTION_TYPE_UNSPECIFIED,headerFooter:i,config:n}}setColumns(e,n={}){if(this._assertTraditionalDocument(),!Number.isInteger(e)||e<1)throw RangeError(`Section column count must be a positive integer.`);if(n.widths&&n.widths.length!==e)throw RangeError(`Section column widths must match the column count.`);if(n.gap!=null&&(!Number.isFinite(n.gap)||n.gap<0))throw RangeError(`Section column gap must be finite and non-negative.`);let i=Math.max(0,n.gap??18),a=this._getConfigSnapshot(),o=(0,r.createSectionColumnProperties)(this._document.getDocumentDataModel().getSnapshot().documentStyle,a,e,i,n.widths),s=typeof n.separator==`boolean`?n.separator?t.ColumnSeparatorType.BETWEEN_EACH_COLUMN:t.ColumnSeparatorType.NONE:n.separator??t.ColumnSeparatorType.NONE;if(!Object.values(t.ColumnSeparatorType).includes(s))throw RangeError(`Invalid section column separator type.`);return this._update({columnProperties:o,columnSeparatorType:s})}setColumnProperties(e,n=t.ColumnSeparatorType.NONE){if(this._assertTraditionalDocument(),!Object.values(t.ColumnSeparatorType).includes(n))throw RangeError(`Invalid section column separator type.`);if(e.some(({width:e,paddingEnd:t})=>!Number.isFinite(e)||!Number.isFinite(t)||e<0||t<0))throw RangeError(`Section column widths and padding must be finite and non-negative.`);let i=(0,r.getSectionContentWidth)(this._document.getDocumentDataModel().getSnapshot().documentStyle,this._getConfigSnapshot());if(e.reduce((e,{width:t,paddingEnd:n})=>e+t+n,0)>i)throw RangeError(`Section columns exceed the available page content width.`);return this._update({columnProperties:t.Tools.deepClone(e),columnSeparatorType:n})}setSectionType(e){if(this._assertTraditionalDocument(),!Object.values(t.SectionType).includes(e))throw RangeError(`Invalid section type.`);return this._update({sectionType:e})}getPageSetup(){let{pageNumberStart:e,pageSize:n,pageOrient:r,marginTop:i,marginBottom:a,marginLeft:o,marginRight:s}=this._getConfigSnapshot();return t.Tools.deepClone({pageNumberStart:e,pageSize:n,pageOrient:r,marginTop:i,marginBottom:a,marginLeft:o,marginRight:s})}getEffectivePageSetup(){this._assertTraditionalDocument();let e=this._document.getDocumentDataModel().getSnapshot().documentStyle;return t.Tools.deepClone((0,r.getEffectiveSectionPageSetup)(e,this._getConfigSnapshot()))}setPageSetup(e){this._assertTraditionalDocument(),b(e);let n=t.Tools.deepClone(e);t.Tools.removeNull(n);let i=this._document.getDocumentDataModel().getSnapshot().documentStyle;return(0,r.getEffectiveSectionPageSetup)(i,{...this._getConfigSnapshot(),...n}),this._update(n)}ensureHeader(e=`default`){return this._ensureHeaderFooter(`header`,e)}ensureFooter(e=`default`){return this._ensureHeaderFooter(`footer`,e)}getHeaderId(e=`default`){return this._getHeaderFooterReference(`header`,e).segmentId??null}getFooterId(e=`default`){return this._getHeaderFooterReference(`footer`,e).segmentId??null}isHeaderLinkedToPrevious(e=`default`){return this._getHeaderFooterReference(`header`,e).linkedToPrevious}isFooterLinkedToPrevious(e=`default`){return this._getHeaderFooterReference(`footer`,e).linkedToPrevious}setHeaderLinkedToPrevious(e,t=`default`){return this._setHeaderFooterLinkedToPrevious(`header`,t,e)}setFooterLinkedToPrevious(e,t=`default`){return this._setHeaderFooterLinkedToPrevious(`footer`,t,e)}setHeaderFooterOptions(e){return this._assertTraditionalDocument(),this._update(e)}remove(){return this._assertTraditionalDocument(),this._commandService.syncExecuteCommand(r.DeleteDocumentSectionBreakCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId})}_update(e){let{sectionId:t,startIndex:n,...i}=e;return this._commandService.syncExecuteCommand(r.UpdateDocumentSectionCommand.id,{unitId:this._document.getId(),updates:[{sectionId:this._sectionId,config:i}]})}_ensureHeaderFooter(e,n){this._assertTraditionalDocument();let{index:i}=this._resolve(),a=this._getConfigSnapshot()[(0,t.getSectionHeaderFooterReferenceKey)(e,n)];if(typeof a==`string`&&a)return a;if(i>0){let i=(0,t.generateRandomId)(6);if(!this._commandService.syncExecuteCommand(r.SetSectionHeaderFooterLinkCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId,kind:e,variant:n,linkedToPrevious:!1,segmentId:i}))throw Error(`Failed to create section ${e}.`);return i}let o={default:e===`header`?r.HeaderFooterType.DEFAULT_HEADER:r.HeaderFooterType.DEFAULT_FOOTER,first:e===`header`?r.HeaderFooterType.FIRST_PAGE_HEADER:r.HeaderFooterType.FIRST_PAGE_FOOTER,even:e===`header`?r.HeaderFooterType.EVEN_PAGE_HEADER:r.HeaderFooterType.EVEN_PAGE_FOOTER},s=(0,t.generateRandomId)(6);if(!this._commandService.syncExecuteCommand(r.CreateHeaderFooterCommand.id,{unitId:this._document.getId(),segmentId:s,createType:o[n],sectionId:this._sectionId}))throw Error(`Failed to create section ${e}.`);return s}_getHeaderFooterReference(e,n){let{index:i}=this._resolve(),a=this._document.getDocumentDataModel().getSnapshot();return(0,t.resolveSectionHeaderFooterReference)(a.documentStyle,(0,r.getTopLevelSectionBreaks)(this._document.getBody()),i,(0,t.getSectionHeaderFooterReferenceKey)(e,n))}_describeHeaderFooterReference(e,t){let n=this._getHeaderFooterReference(e,t);return{segmentId:n.segmentId??null,linkedToPrevious:n.linkedToPrevious}}_setHeaderFooterLinkedToPrevious(e,n,i){return this._assertTraditionalDocument(),this._commandService.syncExecuteCommand(r.SetSectionHeaderFooterLinkCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId,kind:e,variant:n,linkedToPrevious:i,...i?{}:{segmentId:(0,t.generateRandomId)(6)}})}_assertTraditionalDocument(){if(this._document.getDocumentDataModel().getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x}_getConfigSnapshot(){return t.Tools.deepClone(this._resolve().sectionBreak)}_getRange(e){let t=(0,r.getTopLevelSectionBreaks)(this._document.getBody());return{startOffset:e===0?0:t[e-1].startIndex+1,endOffset:t[e].startIndex,segmentId:``}}_resolve(){this._assertTraditionalDocument();let e=(0,r.getTopLevelSectionBreaks)(this._document.getBody()),t=e.findIndex(e=>e.sectionId===this._sectionId);if(t<0)throw Error(`Document section with id ${this._sectionId} not found.`);return{index:t,sectionBreak:e[t]}}};S=h([m(2,t.ICommandService),m(3,t.IPermissionService)],S);function C(e){"@babel/helpers - typeof";return C=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},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let D=class extends n.FBaseInitialable{constructor(e,t,n,r,i,a){super(t),this._documentDataModel=e,this._injector=t,this._univerInstanceService=n,this._resourceLoaderService=r,this._commandService=i,this._permissionService=a,E(this,`id`,void 0),this.id=this._documentDataModel.getUnitId()}getDocumentDataModel(e=``){let t=this._documentDataModel.getSelfOrHeaderFooterModel(e);if(!t)throw Error(e===``?`Document data model is not found.`:`Document data model is not found in the segment: ${e}`);return t}getCustomBlockLayout(){var e;return{blocks:(((e=this._documentDataModel.getBody())==null?void 0:e.customBlocks)??[]).map(({blockId:e,startIndex:t},n)=>({blockId:e,startIndex:t,index:n}))}}getBody(e=``){var t;let n=(t=this._documentDataModel.getSelfOrHeaderFooterModel(e))==null?void 0:t.getBody();if(!n)throw Error(e===``?`Body is not found in the document.`:`Body is not found in the segment: ${e}`);return n}dispose(){super.dispose()}getId(){return this.id}getPermission(){return new a(this.id,this._commandService,this._permissionService)}getEntityPermission(e,t,n){return new o(this.id,(0,r.getDocumentEntityPermissionObjectId)(e,t,n),this._commandService,this._permissionService,()=>(0,r.getDocumentEntityParentPermissionObjectIds)(this._documentDataModel,e,t,n))}getName(){return this._documentDataModel.getTitle()||``}setName(e){return this._commandService.syncExecuteCommand(r.SetDocumentNameCommand.id,{unitId:this.id,name:e}),this}getDocumentFlavor(){return this._resolveDocumentFlavor()}isTraditional(){return this._resolveDocumentFlavor()===t.DocumentFlavor.TRADITIONAL}isModern(){return this._resolveDocumentFlavor()===t.DocumentFlavor.MODERN}_resolveDocumentFlavor(){return this._documentDataModel.getSnapshot().documentStyle.documentFlavor??t.DocumentFlavor.UNSPECIFIED}save(){return this._resourceLoaderService.saveUnit(this._documentDataModel.getUnitId())}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(t.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(t.RedoCommand.id)}ensurePageHeader(e=0){return this._ensureHeaderFooter(`header`,e)}ensurePageFooter(e=0){return this._ensureHeaderFooter(`footer`,e)}insertText(e,t,n=``){return d({startOffset:e,endOffset:e,segmentId:n},u(t),this._documentDataModel,this._commandService)}getHeaderFooterOptions(){let e=this._documentDataModel.getSnapshot().documentStyle;return{marginHeader:e.marginHeader,marginFooter:e.marginFooter,useFirstPageHeaderFooter:e.useFirstPageHeaderFooter,evenAndOddHeaders:e.evenAndOddHeaders}}setHeaderFooterOptions(e){if(this.isModern())throw Error(`The document is a modern document, header/footer is not supported.`);return this._commandService.syncExecuteCommand(r.CreateHeaderFooterCommand.id,{unitId:this.getId(),headerFooterProps:e})}getTextRange(e,t,n=``){return this._injector.createInstance(g,this,e,t,n,this._injector)}getSections(){return this._documentDataModel.getSnapshot().documentStyle.documentFlavor===t.DocumentFlavor.TRADITIONAL?(0,r.getTopLevelSectionBreaks)(this.getBody()).map(e=>this._injector.createInstance(S,this,e.sectionId)):[]}getSection(e){return this.getSections()[e]??null}getSectionAt(e){return this.getSections().find(t=>{let n=t.getRange();return e>=n.startOffset&&e<n.endOffset})??null}insertSectionBreak(e,n={}){if(this._documentDataModel.getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x;let{nextSectionType:i,...a}=n,o=(0,t.createSectionId)(new Set((this.getBody().sectionBreaks??[]).map(e=>e.sectionId)));return this._commandService.syncExecuteCommand(r.InsertDocumentSectionBreakCommand.id,{unitId:this.getId(),offset:e,sectionId:o,config:a,nextSectionType:i})?this._injector.createInstance(S,this,o):null}insertColumnBreak(e){if(this._documentDataModel.getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x;return this._commandService.syncExecuteCommand(r.InsertDocumentColumnBreakCommand.id,{unitId:this.getId(),offset:e})}insertHorizontalRule(e,n={padding:5,color:{rgb:`#CDD0D8`},width:1,dashStyle:t.DashStyleType.SOLID},i=``){var a;let o=this.getBody(i),s=(0,r.generateParagraphs)(t.DataStreamTreeTokenType.PARAGRAPH,void 0,n,(a=o.paragraphs)==null?void 0:a.map(e=>e.paragraphId)),c=s[0].paragraphId;return d({startOffset:e,endOffset:e,segmentId:i},{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:s},this._documentDataModel,this._commandService)?this.getParagraph(c,i):null}getParagraphs(e=``){let{paragraphs:t=[]}=this.getBody(e);return t.map(t=>this._createFDocumentParagraph(t.paragraphId,e))}getParagraph(e,t=``){let{paragraphs:n=[]}=this.getBody(t);return n.find(t=>t.paragraphId===e)?this._createFDocumentParagraph(e,t):null}findParagraphByText(e,t=``){return this.findParagraphs({text:e,segmentId:t})[0]||null}findParagraphs(e){let{text:t,paragraphId:n,segmentId:r=``}=typeof e==`string`?{text:e}:e;return this.getParagraphs(r).filter(e=>!(n&&e.getId()!==n||t&&!e.getText().includes(t)))}insertParagraph(e,t=``,n=``){let r=this._getParagraphInsertOffset(e,n);if(!d({startOffset:r,endOffset:r,segmentId:n},u(`${t}\r`),this._documentDataModel,this._commandService))throw Error(`Failed to insert paragraph.`);let{paragraphs:i=[]}=this.getBody(n),a=i[e];if(!a)throw Error(`Failed to insert paragraph.`);return this._createFDocumentParagraph(a.paragraphId,n)}appendParagraph(e=``,t=``){let{paragraphs:n=[]}=this.getBody(t);return this.insertParagraph(n.length,e,t)}deleteRange(e){let t=this._normalizeDeleteRange(e);return t.startOffset>=t.endOffset?!1:d(t,{dataStream:``},this._documentDataModel,this._commandService)}_createFDocumentParagraph(e,t=``){return this._injector.createInstance(v,this,e,t,this._injector)}_normalizeDeleteRange(e){let t=this.getBody(e.segmentId),n=t.dataStream.endsWith(`\r
|
|
3
3
|
`)?Math.max(0,t.dataStream.length-2):t.dataStream.length,r=Math.min(Math.max(e.endOffset,0),n);return{...e,startOffset:Math.min(Math.max(e.startOffset,0),r),endOffset:r}}_getParagraphInsertOffset(e,n=``){if(e<=0)return 0;let r=this.getBody(n),{dataStream:i,paragraphs:a=[]}=r;return a.length===0?Math.max(0,i.length-1):e>=a.length?a[a.length-1].startIndex+1:(0,t.getParagraphContentStartOffset)(r,a[e])}_ensureHeaderFooter(e,n){if(this.isModern())throw Error(`The document is a modern document, header/footer is not supported.`);let{createType:i,segmentId:a}=this._getHeaderFooterCreateInfo(e,n);if(a)return a;let o=(0,t.generateRandomId)(6);if(!this._commandService.syncExecuteCommand(r.CreateHeaderFooterCommand.id,{unitId:this.getId(),segmentId:o,createType:i}))throw Error(`Failed to create page ${e}.`);return o}_getHeaderFooterCreateInfo(e,n){let{documentStyle:i}=this._documentDataModel.getSnapshot(),a=n===0,o=(n+1)%2==0;return a&&i.useFirstPageHeaderFooter===t.BooleanNumber.TRUE?e===`header`?{createType:r.HeaderFooterType.FIRST_PAGE_HEADER,segmentId:i.firstPageHeaderId??``}:{createType:r.HeaderFooterType.FIRST_PAGE_FOOTER,segmentId:i.firstPageFooterId??``}:o&&i.evenAndOddHeaders===t.BooleanNumber.TRUE?e===`header`?{createType:r.HeaderFooterType.EVEN_PAGE_HEADER,segmentId:i.evenPageHeaderId??``}:{createType:r.HeaderFooterType.EVEN_PAGE_FOOTER,segmentId:i.evenPageFooterId??``}:e===`header`?{createType:r.HeaderFooterType.DEFAULT_HEADER,segmentId:i.defaultHeaderId??``}:{createType:r.HeaderFooterType.DEFAULT_FOOTER,segmentId:i.defaultFooterId??``}}};D=h([m(1,(0,t.Inject)(t.Injector)),m(2,t.IUniverInstanceService),m(3,(0,t.Inject)(t.IResourceLoaderService)),m(4,t.ICommandService),m(5,t.IPermissionService)],D);var O=class extends n.FUniver{createDocument(e,n){let r=this._injector.get(t.IUniverInstanceService).createUnit(t.UniverInstanceType.UNIVER_DOC,e,n);return this._injector.createInstance(D,r)}getActiveDocument(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);return e?this._injector.createInstance(D,e):null}getDocument(e){let n=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_DOC);return n?this._injector.createInstance(D,n):null}};n.FUniver.extend(O);var k=class extends n.FEnum{get DocumentFlavor(){return t.DocumentFlavor}get SectionType(){return t.SectionType}get ColumnSeparatorType(){return t.ColumnSeparatorType}};n.FEnum.extend(k),e.DocsSectionUnsupportedDocumentFlavorError=x,e.FDocsEnumMixin=k,Object.defineProperty(e,"FDocument",{enumerable:!0,get:function(){return D}}),e.FDocumentObjectPermission=o,Object.defineProperty(e,"FDocumentParagraph",{enumerable:!0,get:function(){return v}}),e.FDocumentPermission=a,Object.defineProperty(e,"FDocumentSection",{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,"FDocumentTextRange",{enumerable:!0,get:function(){return g}}),e.isParagraphFacade=y,e.stripBlockTokens=p});
|