@univerjs/docs 1.0.0-alpha.2 → 1.0.0-alpha.3
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 +812 -4
- package/lib/cjs/index.js +578 -22
- package/lib/es/facade.js +812 -8
- package/lib/es/index.js +560 -23
- package/lib/facade.js +812 -8
- package/lib/index.js +560 -23
- package/lib/types/commands/commands/create-header-footer.command.d.ts +5 -1
- package/lib/types/commands/commands/set-document-default-paragraph-style.command.d.ts +24 -0
- package/lib/types/commands/commands/set-section-header-footer-link.command.d.ts +26 -0
- package/lib/types/commands/commands/update-document-section.command.d.ts +38 -0
- package/lib/types/embed-host-anchor.d.ts +61 -0
- package/lib/types/facade/f-document-paragraph.d.ts +14 -0
- package/lib/types/facade/f-document-section.d.ts +281 -0
- package/lib/types/facade/f-document-text-range.d.ts +136 -0
- package/lib/types/facade/f-document.d.ts +120 -1
- package/lib/types/facade/f-enum.d.ts +32 -0
- package/lib/types/facade/f-types.d.ts +16 -0
- package/lib/types/facade/index.d.ts +7 -0
- package/lib/types/index.d.ts +13 -2
- package/lib/types/utils/paragraphs.d.ts +18 -0
- package/lib/types/utils/section-columns.d.ts +18 -0
- package/lib/types/utils/sections.d.ts +18 -0
- package/lib/umd/facade.js +2 -2
- package/lib/umd/index.js +2 -2
- package/package.json +5 -5
|
@@ -23,7 +23,9 @@ export declare enum HeaderFooterType {
|
|
|
23
23
|
EVEN_PAGE_FOOTER = 5
|
|
24
24
|
}
|
|
25
25
|
export interface IHeaderFooterProps {
|
|
26
|
+
/** Distance from the page edge to the header, in points (pt). */
|
|
26
27
|
marginHeader?: number;
|
|
28
|
+
/** Distance from the page edge to the footer, in points (pt). */
|
|
27
29
|
marginFooter?: number;
|
|
28
30
|
useFirstPageHeaderFooter?: BooleanNumber;
|
|
29
31
|
evenAndOddHeaders?: BooleanNumber;
|
|
@@ -35,7 +37,9 @@ export interface ICreateHeaderFooterCommandParams {
|
|
|
35
37
|
segmentId?: string;
|
|
36
38
|
headerFooterProps?: IHeaderFooterProps;
|
|
37
39
|
createMode?: HeaderFooterCreateMode;
|
|
40
|
+
/** Optional stable section id. Omit to configure the document-level default. */
|
|
41
|
+
sectionId?: string;
|
|
38
42
|
}
|
|
39
43
|
export declare function getEmptyHeaderFooterBody(): IDocumentBody;
|
|
40
|
-
export declare function createHeaderFooterAction(segmentId: string | undefined, createType: HeaderFooterType,
|
|
44
|
+
export declare function createHeaderFooterAction(segmentId: string | undefined, createType: HeaderFooterType, headerFooterConfig: IHeaderFooterProps, actions: JSONXActions, createMode?: HeaderFooterCreateMode, configPath?: Array<string | number>): JSONXActions;
|
|
41
45
|
export declare const CreateHeaderFooterCommand: ICommand<ICreateHeaderFooterCommandParams>;
|
|
@@ -0,0 +1,24 @@
|
|
|
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, IDocumentDefaultParagraphStyle, Nullable } from '@univerjs/core';
|
|
17
|
+
export type IDocumentDefaultParagraphStylePatch = {
|
|
18
|
+
[K in keyof IDocumentDefaultParagraphStyle]?: Nullable<IDocumentDefaultParagraphStyle[K]>;
|
|
19
|
+
};
|
|
20
|
+
export interface ISetDocumentDefaultParagraphStyleCommandParams {
|
|
21
|
+
unitId: string;
|
|
22
|
+
defaultParagraphStyle: Nullable<IDocumentDefaultParagraphStylePatch>;
|
|
23
|
+
}
|
|
24
|
+
export declare const SetDocumentDefaultParagraphStyleCommand: ICommand<ISetDocumentDefaultParagraphStyleCommandParams>;
|
|
@@ -0,0 +1,26 @@
|
|
|
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, SectionHeaderFooterKind, SectionHeaderFooterVariant } from '@univerjs/core';
|
|
17
|
+
export interface ISetSectionHeaderFooterLinkCommandParams {
|
|
18
|
+
unitId: string;
|
|
19
|
+
sectionId: string;
|
|
20
|
+
kind: SectionHeaderFooterKind;
|
|
21
|
+
variant: SectionHeaderFooterVariant;
|
|
22
|
+
linkedToPrevious: boolean;
|
|
23
|
+
/** Stable id to use when unlinking. Generated automatically when omitted. */
|
|
24
|
+
segmentId?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const SetSectionHeaderFooterLinkCommand: ICommand<ISetSectionHeaderFooterLinkCommandParams>;
|
|
@@ -0,0 +1,38 @@
|
|
|
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, ISectionBreak } from '@univerjs/core';
|
|
17
|
+
export type IDocumentSectionConfig = Omit<ISectionBreak, 'sectionId' | 'startIndex'>;
|
|
18
|
+
export interface IDocumentSectionUpdate {
|
|
19
|
+
sectionId: string;
|
|
20
|
+
config: Partial<IDocumentSectionConfig>;
|
|
21
|
+
}
|
|
22
|
+
export interface IUpdateDocumentSectionCommandParams {
|
|
23
|
+
unitId: string;
|
|
24
|
+
updates: IDocumentSectionUpdate[];
|
|
25
|
+
}
|
|
26
|
+
export interface IInsertDocumentSectionBreakCommandParams {
|
|
27
|
+
unitId: string;
|
|
28
|
+
offset: number;
|
|
29
|
+
sectionId: string;
|
|
30
|
+
config?: Partial<IDocumentSectionConfig>;
|
|
31
|
+
}
|
|
32
|
+
export interface IDeleteDocumentSectionBreakCommandParams {
|
|
33
|
+
unitId: string;
|
|
34
|
+
sectionId: string;
|
|
35
|
+
}
|
|
36
|
+
export declare const UpdateDocumentSectionCommand: ICommand<IUpdateDocumentSectionCommandParams>;
|
|
37
|
+
export declare const InsertDocumentSectionBreakCommand: ICommand<IInsertDocumentSectionBreakCommandParams>;
|
|
38
|
+
export declare const DeleteDocumentSectionBreakCommand: ICommand<IDeleteDocumentSectionBreakCommandParams>;
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { IDocDrawingBase, IMutationInfo, JSONXActions } from '@univerjs/core';
|
|
17
|
+
import type { IRichTextEditingMutationParams } from './commands/mutations/core-editing.mutation';
|
|
18
|
+
import { UniverInstanceType } from '@univerjs/core';
|
|
19
|
+
export interface IDocsCustomBlockMutationParams {
|
|
20
|
+
unitId: string;
|
|
21
|
+
blockId: string;
|
|
22
|
+
startIndex: number;
|
|
23
|
+
segmentId?: string;
|
|
24
|
+
drawingOrderIndex?: number;
|
|
25
|
+
embedId?: string;
|
|
26
|
+
childUnitId?: string;
|
|
27
|
+
childType?: UniverInstanceType;
|
|
28
|
+
componentKey?: string;
|
|
29
|
+
interactionMode?: EmbedDocsCustomBlockInteractionMode;
|
|
30
|
+
}
|
|
31
|
+
export declare const EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY = "UniverEmbedDocsCustomBlock";
|
|
32
|
+
export type EmbedDocsCustomBlockInteractionMode = 'block' | 'inline';
|
|
33
|
+
export interface IEmbedDocsCustomBlockData {
|
|
34
|
+
version: 1;
|
|
35
|
+
embedId: string;
|
|
36
|
+
hostUnitId?: string;
|
|
37
|
+
hostAnchorId: string;
|
|
38
|
+
childUnitId?: string;
|
|
39
|
+
childType?: UniverInstanceType;
|
|
40
|
+
interactionMode?: EmbedDocsCustomBlockInteractionMode;
|
|
41
|
+
}
|
|
42
|
+
export declare function createDocsCustomBlockInsertMutation(params: IDocsCustomBlockMutationParams): IMutationInfo<IRichTextEditingMutationParams>;
|
|
43
|
+
export declare function createDocsCustomBlockRemoveMutation(params: IDocsCustomBlockMutationParams): IMutationInfo<IRichTextEditingMutationParams>;
|
|
44
|
+
export declare function createInsertCustomBlockActions(params: IDocsCustomBlockMutationParams): JSONXActions;
|
|
45
|
+
export declare function createRemoveCustomBlockActions(params: IDocsCustomBlockMutationParams): JSONXActions;
|
|
46
|
+
export declare function createDocsCustomBlockDrawing(params: IDocsCustomBlockMutationParams): IDocDrawingBase;
|
|
47
|
+
export declare function resolveDocsCustomBlockSize(childType?: UniverInstanceType): {
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
};
|
|
51
|
+
export declare function isSheetLikeDocsCustomBlockChildType(childType?: UniverInstanceType): boolean;
|
|
52
|
+
export declare function createEmbedDocsCustomBlockData(params: {
|
|
53
|
+
blockId: string;
|
|
54
|
+
embedId?: string;
|
|
55
|
+
unitId?: string;
|
|
56
|
+
childUnitId?: string;
|
|
57
|
+
childType?: UniverInstanceType;
|
|
58
|
+
interactionMode?: EmbedDocsCustomBlockInteractionMode;
|
|
59
|
+
}): IEmbedDocsCustomBlockData;
|
|
60
|
+
export declare function isEmbedDocsCustomBlockData(data: unknown): data is IEmbedDocsCustomBlockData;
|
|
61
|
+
export declare function shouldUseInlineTextSelectionForDocsCustomBlockDrawing(drawing: unknown): boolean;
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import type { Injector, IParagraph, IParagraphStyle } from '@univerjs/core';
|
|
17
17
|
import type { FDocument } from './f-document';
|
|
18
18
|
import type { IFDocumentTextRange } from './utils';
|
|
19
|
+
import { FDocumentTextRange } from './f-document-text-range';
|
|
19
20
|
/**
|
|
20
21
|
* Resolved paragraph metadata in the the document body.
|
|
21
22
|
*/
|
|
@@ -90,6 +91,18 @@ export declare class FDocumentParagraph {
|
|
|
90
91
|
* ```
|
|
91
92
|
*/
|
|
92
93
|
getRange(): IFDocumentTextRange;
|
|
94
|
+
/**
|
|
95
|
+
* Returns an agent-friendly facade for reading and styling this paragraph's text.
|
|
96
|
+
* @returns {FDocumentTextRange} The paragraph text range, excluding the trailing paragraph break.
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
100
|
+
* const paragraph = fDocument?.findParagraphByText('Launch');
|
|
101
|
+
* const range = paragraph?.getTextRange();
|
|
102
|
+
* console.log(range?.describe());
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
getTextRange(): FDocumentTextRange;
|
|
93
106
|
/**
|
|
94
107
|
* Get this paragraph's plain text.
|
|
95
108
|
* @returns {string} The paragraph text without the trailing paragraph break.
|
|
@@ -129,6 +142,7 @@ export declare class FDocumentParagraph {
|
|
|
129
142
|
appendText(text: string): boolean;
|
|
130
143
|
/**
|
|
131
144
|
* Apply paragraph style to a paragraph handle or text range.
|
|
145
|
+
* `style.textStyle.fs` is a font size in points (pt), not CSS pixels.
|
|
132
146
|
* @param {IParagraphStyle} style The Univer paragraph style patch.
|
|
133
147
|
* @returns {boolean} `true` if the style was applied.
|
|
134
148
|
* @example
|
|
@@ -0,0 +1,281 @@
|
|
|
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 { Injector, ISectionBreak, ISectionColumnProperties, SectionHeaderFooterKind, SectionHeaderFooterVariant } from '@univerjs/core';
|
|
17
|
+
import type { IHeaderFooterProps } from '@univerjs/docs';
|
|
18
|
+
import type { FDocument } from './f-document';
|
|
19
|
+
import type { IFDocumentTextRange } from './utils';
|
|
20
|
+
import { ColumnSeparatorType, SectionType } from '@univerjs/core';
|
|
21
|
+
export interface IFDocumentSectionColumnOptions {
|
|
22
|
+
/** Gap after each column except the last, in points (pt). */
|
|
23
|
+
gap?: number;
|
|
24
|
+
/** Optional explicit column widths in points (pt). Length must equal `columnCount`. */
|
|
25
|
+
widths?: number[];
|
|
26
|
+
/** Whether to draw separators, or the exact separator enum value. */
|
|
27
|
+
separator?: boolean | ColumnSeparatorType;
|
|
28
|
+
/** How the following section starts. */
|
|
29
|
+
sectionType?: SectionType;
|
|
30
|
+
}
|
|
31
|
+
export interface IFDocumentSectionDescription {
|
|
32
|
+
sectionId: string;
|
|
33
|
+
index: number;
|
|
34
|
+
range: IFDocumentTextRange;
|
|
35
|
+
columnCount: number;
|
|
36
|
+
columns: ISectionColumnProperties[];
|
|
37
|
+
columnSeparatorType: ColumnSeparatorType;
|
|
38
|
+
sectionType: SectionType;
|
|
39
|
+
headerFooter: Record<`${SectionHeaderFooterVariant}${Capitalize<SectionHeaderFooterKind>}`, {
|
|
40
|
+
segmentId: string | null;
|
|
41
|
+
linkedToPrevious: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
config: ISectionBreak;
|
|
44
|
+
}
|
|
45
|
+
/** Error thrown when traditional section APIs are used to mutate a modern document. */
|
|
46
|
+
export declare class DocsSectionUnsupportedDocumentFlavorError extends Error {
|
|
47
|
+
constructor();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Facade wrapper for an OOXML-compatible traditional document section.
|
|
51
|
+
* Modern documents use ColumnGroup APIs and cannot mutate this facade.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
55
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
56
|
+
* console.log(fDocument.getSection(0)?.describe());
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare class FDocumentSection {
|
|
61
|
+
private readonly _document;
|
|
62
|
+
private readonly _sectionId;
|
|
63
|
+
private readonly _injector;
|
|
64
|
+
constructor(_document: FDocument, _sectionId: string, _injector: Injector);
|
|
65
|
+
/**
|
|
66
|
+
* Returns the persisted section id.
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
70
|
+
* console.log(fDocument?.getSection(0)?.getId());
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
getId(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the current zero-based section index.
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
79
|
+
* console.log(fDocument?.getSection(0)?.getIndex());
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
getIndex(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the section break snapshot that terminates this section.
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
88
|
+
* console.log(fDocument?.getSection(0)?.getConfig());
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
getConfig(): ISectionBreak;
|
|
92
|
+
/**
|
|
93
|
+
* Returns the section content range, excluding its terminating section-break token.
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
97
|
+
* console.log(fDocument?.getSection(0)?.getRange());
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
getRange(): IFDocumentTextRange;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the explicit columns. An empty array means the normal single-column layout.
|
|
103
|
+
* Column widths and trailing spaces are in points (pt).
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
107
|
+
* console.log(fDocument?.getSection(0)?.getColumns());
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
getColumns(): ISectionColumnProperties[];
|
|
111
|
+
/**
|
|
112
|
+
* Returns a compact serializable section summary.
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
116
|
+
* console.log(fDocument?.getSection(0)?.describe());
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
describe(): IFDocumentSectionDescription;
|
|
120
|
+
/**
|
|
121
|
+
* Sets equal or explicitly sized columns for this traditional section.
|
|
122
|
+
* Use `columnCount = 1` to restore normal single-column layout.
|
|
123
|
+
* `gap` and `widths` are in points (pt).
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
127
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
128
|
+
* fDocument.getSection(0)?.setColumns(2, { gap: 18, separator: true });
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
setColumns(columnCount: number, options?: IFDocumentSectionColumnOptions): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Sets explicit OOXML-compatible column width and trailing-space values in points (pt).
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
138
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
139
|
+
* fDocument.getSection(0)?.setColumnProperties([
|
|
140
|
+
* { width: 240, paddingEnd: 18 },
|
|
141
|
+
* { width: 240, paddingEnd: 0 },
|
|
142
|
+
* ], univerAPI.Enum.ColumnSeparatorType.BETWEEN_EACH_COLUMN);
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
setColumnProperties(columns: ISectionColumnProperties[], separator?: ColumnSeparatorType): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Sets how the next section begins.
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
152
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
153
|
+
* fDocument.getSection(0)?.setSectionType(univerAPI.Enum.SectionType.NEXT_PAGE);
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
setSectionType(sectionType: SectionType): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Ensures a header segment linked specifically to this section.
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
163
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
164
|
+
* const segmentId = fDocument.getSection(0)?.ensureHeader();
|
|
165
|
+
* if (segmentId) {
|
|
166
|
+
* fDocument.insertText(0, 'Quarterly report', segmentId);
|
|
167
|
+
* }
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
ensureHeader(variant?: SectionHeaderFooterVariant): string;
|
|
172
|
+
/**
|
|
173
|
+
* Ensures a footer segment linked specifically to this section.
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
177
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
178
|
+
* const segmentId = fDocument.getSection(0)?.ensureFooter('first');
|
|
179
|
+
* if (segmentId) {
|
|
180
|
+
* fDocument.insertText(0, 'Confidential', segmentId);
|
|
181
|
+
* }
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
ensureFooter(variant?: SectionHeaderFooterVariant): string;
|
|
186
|
+
/**
|
|
187
|
+
* Returns the effective header id after resolving links to previous sections.
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
191
|
+
* console.log(fDocument?.getSection(0)?.getHeaderId('default'));
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
getHeaderId(variant?: SectionHeaderFooterVariant): string | null;
|
|
195
|
+
/**
|
|
196
|
+
* Returns the effective footer id after resolving links to previous sections.
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
200
|
+
* console.log(fDocument?.getSection(0)?.getFooterId('first'));
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
getFooterId(variant?: SectionHeaderFooterVariant): string | null;
|
|
204
|
+
/**
|
|
205
|
+
* Whether this header variant inherits the previous section's reference.
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
209
|
+
* console.log(fDocument?.getSection(1)?.isHeaderLinkedToPrevious());
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
isHeaderLinkedToPrevious(variant?: SectionHeaderFooterVariant): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Whether this footer variant inherits the previous section's reference.
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
218
|
+
* console.log(fDocument?.getSection(1)?.isFooterLinkedToPrevious('even'));
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
isFooterLinkedToPrevious(variant?: SectionHeaderFooterVariant): boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Links or unlinks this header variant. Unlinking clones the inherited header.
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
227
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
228
|
+
* fDocument.getSection(1)?.setHeaderLinkedToPrevious(false, 'default');
|
|
229
|
+
* }
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
setHeaderLinkedToPrevious(linkedToPrevious: boolean, variant?: SectionHeaderFooterVariant): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Links or unlinks this footer variant. Unlinking clones the inherited footer.
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
238
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
239
|
+
* fDocument.getSection(1)?.setFooterLinkedToPrevious(true, 'even');
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
setFooterLinkedToPrevious(linkedToPrevious: boolean, variant?: SectionHeaderFooterVariant): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Updates header/footer switches and margins on this section break.
|
|
246
|
+
* `marginHeader` and `marginFooter` are in points (pt).
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
250
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
251
|
+
* fDocument.getSection(0)?.setHeaderFooterOptions({
|
|
252
|
+
* marginHeader: 36,
|
|
253
|
+
* marginFooter: 36,
|
|
254
|
+
* useFirstPageHeaderFooter: univerAPI.Enum.BooleanNumber.TRUE,
|
|
255
|
+
* });
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
setHeaderFooterOptions(options: IHeaderFooterProps): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Deletes this section break. The final top-level section break cannot be removed.
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
265
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
266
|
+
* const sections = fDocument.getSections();
|
|
267
|
+
* if (sections.length > 1) {
|
|
268
|
+
* sections[0].remove();
|
|
269
|
+
* }
|
|
270
|
+
* }
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
remove(): boolean;
|
|
274
|
+
private _update;
|
|
275
|
+
private _ensureHeaderFooter;
|
|
276
|
+
private _getHeaderFooterReference;
|
|
277
|
+
private _describeHeaderFooterReference;
|
|
278
|
+
private _setHeaderFooterLinkedToPrevious;
|
|
279
|
+
private _assertTraditionalDocument;
|
|
280
|
+
private _resolve;
|
|
281
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
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 { Injector, ITextStyle } from '@univerjs/core';
|
|
17
|
+
import type { FDocument } from './f-document';
|
|
18
|
+
import type { IFDocumentTextRange } from './utils';
|
|
19
|
+
/** A clipped text-style run in document offsets. */
|
|
20
|
+
export interface IFDocumentTextStyleRun {
|
|
21
|
+
/** Inclusive start offset in the document segment. */
|
|
22
|
+
startOffset: number;
|
|
23
|
+
/** Exclusive end offset in the document segment. */
|
|
24
|
+
endOffset: number;
|
|
25
|
+
/** Explicit text style stored on this run. */
|
|
26
|
+
textStyle: ITextStyle;
|
|
27
|
+
}
|
|
28
|
+
/** Agent-friendly summary of a document text range. */
|
|
29
|
+
export interface IFDocumentTextRangeDescription extends IFDocumentTextRange {
|
|
30
|
+
text: string;
|
|
31
|
+
length: number;
|
|
32
|
+
/** Explicit styles stored directly in text runs. */
|
|
33
|
+
explicitTextStyleRuns: IFDocumentTextStyleRun[];
|
|
34
|
+
/** Top-level explicit style properties common to the complete range. */
|
|
35
|
+
commonExplicitTextStyle: ITextStyle;
|
|
36
|
+
/** @deprecated Use `explicitTextStyleRuns`. */
|
|
37
|
+
textStyleRuns: IFDocumentTextStyleRun[];
|
|
38
|
+
/** @deprecated Use `commonExplicitTextStyle`. */
|
|
39
|
+
commonTextStyle: ITextStyle;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Facade wrapper for reading and styling a fixed document text range.
|
|
43
|
+
*
|
|
44
|
+
* Offsets are fixed when the wrapper is created. Create a new range after edits
|
|
45
|
+
* that insert or remove content before it.
|
|
46
|
+
* @hideconstructor
|
|
47
|
+
*/
|
|
48
|
+
export declare class FDocumentTextRange {
|
|
49
|
+
private readonly _document;
|
|
50
|
+
private readonly _startOffset;
|
|
51
|
+
private readonly _endOffset;
|
|
52
|
+
private readonly _segmentId;
|
|
53
|
+
private readonly _injector;
|
|
54
|
+
constructor(_document: FDocument, _startOffset: number, _endOffset: number, _segmentId: string, _injector: Injector);
|
|
55
|
+
/**
|
|
56
|
+
* Returns the serializable document range.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
60
|
+
* const range = fDocument?.findParagraphByText('Launch')?.getTextRange();
|
|
61
|
+
* console.log(range?.getRange());
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
getRange(): IFDocumentTextRange;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the plain data-stream text in this range.
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
70
|
+
* const range = fDocument?.findParagraphByText('Launch')?.getTextRange();
|
|
71
|
+
* console.log(range?.getText());
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
getText(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Returns explicit text-style runs intersecting this range.
|
|
77
|
+
* Returned offsets are clipped to the range and remain document-relative.
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
81
|
+
* const range = fDocument?.findParagraphByText('Launch')?.getTextRange();
|
|
82
|
+
* console.log(range?.getExplicitTextStyleRuns());
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
getExplicitTextStyleRuns(): IFDocumentTextStyleRun[];
|
|
86
|
+
/** @deprecated Use `getExplicitTextStyleRuns()` to distinguish stored styles from effective styles. */
|
|
87
|
+
getTextStyleRuns(): IFDocumentTextStyleRun[];
|
|
88
|
+
/**
|
|
89
|
+
* Returns top-level style properties that have the same explicit value
|
|
90
|
+
* across the complete range. Unstyled gaps make a property non-common.
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
94
|
+
* const range = fDocument?.findParagraphByText('Launch')?.getTextRange();
|
|
95
|
+
* console.log(range?.getCommonExplicitTextStyle());
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
getCommonExplicitTextStyle(): ITextStyle;
|
|
99
|
+
/** @deprecated Use `getCommonExplicitTextStyle()` to distinguish stored styles from effective styles. */
|
|
100
|
+
getCommonTextStyle(): ITextStyle;
|
|
101
|
+
/**
|
|
102
|
+
* Returns a serializable summary suitable for an agent/tool response.
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
106
|
+
* const range = fDocument?.findParagraphByText('Launch')?.getTextRange();
|
|
107
|
+
* console.log(range?.describe());
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
describe(): IFDocumentTextRangeDescription;
|
|
111
|
+
/**
|
|
112
|
+
* Merges a text-style patch into every character in the range.
|
|
113
|
+
* Existing text-run splitting, merging, and normalization are handled by
|
|
114
|
+
* the document mutation pipeline.
|
|
115
|
+
* `style.fs` is a font size in points (pt), not CSS pixels.
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
119
|
+
* const range = fDocument?.findParagraphByText('Launch')?.getTextRange();
|
|
120
|
+
* range?.setTextStyle({ fs: 10.5, bl: univerAPI.Enum.BooleanNumber.TRUE });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
setTextStyle(style: ITextStyle): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Replaces the range with plain text while preserving document mutation semantics.
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
129
|
+
* const range = fDocument?.findParagraphByText('Draft')?.getTextRange();
|
|
130
|
+
* range?.setText('Final');
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
setText(text: string): boolean;
|
|
134
|
+
private _validateRange;
|
|
135
|
+
private _getStyleSegments;
|
|
136
|
+
}
|