@univerjs/docs 1.0.4 → 1.2.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/README.md +50 -0
- package/lib/cjs/facade.js +10 -10
- package/lib/cjs/index.js +704 -617
- package/lib/es/facade.js +6 -6
- package/lib/es/index.js +698 -612
- package/lib/facade.js +6 -6
- package/lib/index.js +698 -612
- package/lib/types/commands/commands/set-heading-collapsed.command.d.ts +22 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/services/doc-skeleton-manager.service.d.ts +3 -2
- package/lib/types/utils/section-columns.d.ts +2 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +8 -8
|
@@ -0,0 +1,22 @@
|
|
|
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 { ICommand } from '@univerjs/core';
|
|
17
|
+
export interface ISetHeadingCollapsedCommandParams {
|
|
18
|
+
unitId: string;
|
|
19
|
+
paragraphId: string;
|
|
20
|
+
collapsed: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const SetHeadingCollapsedCommand: ICommand<ISetHeadingCollapsedCommandParams>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type { ISetDocumentNameCommandParams } from './commands/commands/set-docu
|
|
|
24
24
|
export { SetDocumentPermissionCommand } from './commands/commands/set-document-permission.command';
|
|
25
25
|
export type { ISetDocumentPermissionCommandParams } from './commands/commands/set-document-permission.command';
|
|
26
26
|
export { SetDocumentPermissionsCommand } from './commands/commands/set-document-permissions.command';
|
|
27
|
+
export { SetHeadingCollapsedCommand } from './commands/commands/set-heading-collapsed.command';
|
|
27
28
|
export { SetSectionHeaderFooterLinkCommand } from './commands/commands/set-section-header-footer-link.command';
|
|
28
29
|
export type { ISetSectionHeaderFooterLinkCommandParams } from './commands/commands/set-section-header-footer-link.command';
|
|
29
30
|
export { UpdateDocumentParagraphStyleCommand } from './commands/commands/update-document-paragraph-style.command';
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IUniverDocsConfig } from './config/config';
|
|
17
16
|
import { IConfigService, Injector, Plugin } from '@univerjs/core';
|
|
17
|
+
import type { IUniverDocsConfig } from './config/config';
|
|
18
18
|
export declare class UniverDocsPlugin extends Plugin {
|
|
19
19
|
private readonly _config;
|
|
20
20
|
_injector: Injector;
|
|
@@ -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;
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IDocumentStyle, ISectionBreak, ISectionColumnProperties
|
|
16
|
+
import type { IDocumentStyle, ISectionBreak, ISectionColumnProperties } from '@univerjs/core';
|
|
17
|
+
import { PageOrientType } from '@univerjs/core';
|
|
17
18
|
export interface IEffectiveSectionPageSetup {
|
|
18
19
|
pageSize: {
|
|
19
20
|
width: number;
|
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});
|