@univerjs/docs 1.0.0-alpha.7 → 1.0.0-beta.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 +539 -222
- package/lib/cjs/index.js +404 -111
- package/lib/es/facade.js +529 -222
- package/lib/es/index.js +400 -113
- package/lib/facade.js +529 -222
- package/lib/index.js +400 -113
- package/lib/types/{facade/f-types.d.ts → commands/commands/update-document-paragraph-style.command.d.ts} +10 -1
- package/lib/types/commands/commands/update-document-section.command.d.ts +7 -0
- package/lib/types/facade/f-document-paragraph.d.ts +115 -20
- package/lib/types/facade/f-document-section.d.ts +131 -28
- package/lib/types/facade/f-document-text-range.d.ts +7 -14
- package/lib/types/facade/f-document.d.ts +158 -20
- package/lib/types/facade/f-enum.d.ts +4 -1
- package/lib/types/facade/index.d.ts +3 -4
- package/lib/types/index.d.ts +8 -4
- package/lib/types/services/doc-selection-manager.service.d.ts +5 -11
- package/lib/types/services/doc-skeleton-manager.service.d.ts +1 -0
- package/lib/types/services/doc-text-resolver.service.d.ts +53 -0
- package/lib/types/utils/section-columns.d.ts +23 -1
- package/lib/umd/facade.js +2 -2
- package/lib/umd/index.js +2 -2
- package/package.json +4 -4
|
@@ -13,4 +13,13 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
import type { ICommand, IParagraphStyle } from '@univerjs/core';
|
|
17
|
+
export interface IUpdateDocumentParagraphStyleCommandParams {
|
|
18
|
+
unitId: string;
|
|
19
|
+
segmentId?: string;
|
|
20
|
+
paragraphId: string;
|
|
21
|
+
startOffset: number;
|
|
22
|
+
endOffset: number;
|
|
23
|
+
style: IParagraphStyle;
|
|
24
|
+
}
|
|
25
|
+
export declare const UpdateDocumentParagraphStyleCommand: ICommand<IUpdateDocumentParagraphStyleCommandParams>;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { ICommand, ISectionBreak } from '@univerjs/core';
|
|
17
|
+
import { SectionType } from '@univerjs/core';
|
|
17
18
|
export type IDocumentSectionConfig = Omit<ISectionBreak, 'sectionId' | 'startIndex'>;
|
|
18
19
|
export interface IDocumentSectionUpdate {
|
|
19
20
|
sectionId: string;
|
|
@@ -28,11 +29,17 @@ export interface IInsertDocumentSectionBreakCommandParams {
|
|
|
28
29
|
offset: number;
|
|
29
30
|
sectionId: string;
|
|
30
31
|
config?: Partial<IDocumentSectionConfig>;
|
|
32
|
+
nextSectionType?: SectionType;
|
|
31
33
|
}
|
|
32
34
|
export interface IDeleteDocumentSectionBreakCommandParams {
|
|
33
35
|
unitId: string;
|
|
34
36
|
sectionId: string;
|
|
35
37
|
}
|
|
38
|
+
export interface IInsertDocumentColumnBreakCommandParams {
|
|
39
|
+
unitId: string;
|
|
40
|
+
offset: number;
|
|
41
|
+
}
|
|
36
42
|
export declare const UpdateDocumentSectionCommand: ICommand<IUpdateDocumentSectionCommandParams>;
|
|
37
43
|
export declare const InsertDocumentSectionBreakCommand: ICommand<IInsertDocumentSectionBreakCommandParams>;
|
|
44
|
+
export declare const InsertDocumentColumnBreakCommand: ICommand<IInsertDocumentColumnBreakCommandParams>;
|
|
38
45
|
export declare const DeleteDocumentSectionBreakCommand: ICommand<IDeleteDocumentSectionBreakCommandParams>;
|
|
@@ -16,6 +16,8 @@
|
|
|
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 { ICommandService } from '@univerjs/core';
|
|
20
|
+
import { FBaseInitialable } from '@univerjs/core/facade';
|
|
19
21
|
import { FDocumentTextRange } from './f-document-text-range';
|
|
20
22
|
/**
|
|
21
23
|
* Resolved paragraph metadata in the the document body.
|
|
@@ -30,6 +32,21 @@ export interface IFDocumentParagraphInfo {
|
|
|
30
32
|
/** The exclusive end offset of the paragraph text, before the paragraph break. */
|
|
31
33
|
endOffset: number;
|
|
32
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Options for locating text inside a document paragraph.
|
|
37
|
+
*/
|
|
38
|
+
export interface IFDocumentFindTextOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Whether matching is case-sensitive.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
matchCase?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Zero-based occurrence to return from {@link FDocumentParagraph.findText}.
|
|
46
|
+
* @default 0
|
|
47
|
+
*/
|
|
48
|
+
occurrence?: number;
|
|
49
|
+
}
|
|
33
50
|
/**
|
|
34
51
|
* A paragraph facade wrapper.
|
|
35
52
|
*
|
|
@@ -39,12 +56,13 @@ export interface IFDocumentParagraphInfo {
|
|
|
39
56
|
*
|
|
40
57
|
* @hideconstructor
|
|
41
58
|
*/
|
|
42
|
-
export declare class FDocumentParagraph {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
export declare class FDocumentParagraph extends FBaseInitialable {
|
|
60
|
+
protected readonly _document: FDocument;
|
|
61
|
+
protected readonly _paragraphId: string;
|
|
62
|
+
protected readonly _segmentId: string;
|
|
63
|
+
protected readonly _injector: Injector;
|
|
64
|
+
private readonly _commandService;
|
|
65
|
+
constructor(_document: FDocument, _paragraphId: string, _segmentId: string | undefined, _injector: Injector, _commandService: ICommandService);
|
|
48
66
|
/**
|
|
49
67
|
* Get the persisted paragraph id.
|
|
50
68
|
* @returns {string} The paragraph id.
|
|
@@ -103,6 +121,55 @@ export declare class FDocumentParagraph {
|
|
|
103
121
|
* ```
|
|
104
122
|
*/
|
|
105
123
|
getTextRange(): FDocumentTextRange;
|
|
124
|
+
/**
|
|
125
|
+
* Finds one literal text occurrence inside this paragraph.
|
|
126
|
+
*
|
|
127
|
+
* The returned text range is fixed when it is created. Resolve a new range
|
|
128
|
+
* after edits that insert or remove content before the match.
|
|
129
|
+
*
|
|
130
|
+
* @param {string} text Literal text to find. It must not be empty.
|
|
131
|
+
* @param {IFDocumentFindTextOptions} [options] Case sensitivity and zero-based occurrence.
|
|
132
|
+
* @returns {FDocumentTextRange | null} The matching fixed text range, or `null` when no such occurrence exists.
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const univerAPI = FUniver.newAPI(univer);
|
|
136
|
+
* const document = univerAPI.getActiveDocument();
|
|
137
|
+
* if (!document) throw new Error('No active document');
|
|
138
|
+
*
|
|
139
|
+
* const paragraph = document.findParagraphByText('Launch formula');
|
|
140
|
+
* if (!paragraph) throw new Error('Target paragraph not found');
|
|
141
|
+
*
|
|
142
|
+
* const range = paragraph.findText('formula');
|
|
143
|
+
* if (!range) throw new Error('Target text not found');
|
|
144
|
+
*
|
|
145
|
+
* console.log(range.describe());
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
findText(text: string, options?: IFDocumentFindTextOptions): FDocumentTextRange | null;
|
|
149
|
+
/**
|
|
150
|
+
* Finds every non-overlapping literal text occurrence inside this paragraph.
|
|
151
|
+
*
|
|
152
|
+
* Results are ordered from the start of the paragraph. The returned ranges
|
|
153
|
+
* are fixed when created; use them immediately and resolve new ranges after
|
|
154
|
+
* edits that change earlier document content.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} text Literal text to find. It must not be empty.
|
|
157
|
+
* @param {Omit<IFDocumentFindTextOptions, 'occurrence'>} [options] Case-sensitivity option.
|
|
158
|
+
* @returns {FDocumentTextRange[]} All matching fixed text ranges, or an empty array when no matches exist.
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const univerAPI = FUniver.newAPI(univer);
|
|
162
|
+
* const document = univerAPI.getActiveDocument();
|
|
163
|
+
* if (!document) throw new Error('No active document');
|
|
164
|
+
*
|
|
165
|
+
* const paragraph = document.findParagraphByText('x plus x');
|
|
166
|
+
* if (!paragraph) throw new Error('Target paragraph not found');
|
|
167
|
+
*
|
|
168
|
+
* const matches = paragraph.findAllText('x');
|
|
169
|
+
* console.log(matches.map((range) => range.describe()));
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
findAllText(text: string, options?: Omit<IFDocumentFindTextOptions, 'occurrence'>): FDocumentTextRange[];
|
|
106
173
|
/**
|
|
107
174
|
* Get this paragraph's plain text.
|
|
108
175
|
* @returns {string} The paragraph text without the trailing paragraph break.
|
|
@@ -141,25 +208,53 @@ export declare class FDocumentParagraph {
|
|
|
141
208
|
*/
|
|
142
209
|
appendText(text: string): boolean;
|
|
143
210
|
/**
|
|
144
|
-
*
|
|
211
|
+
* Applies a paragraph and optional text-style patch through one document command.
|
|
212
|
+
*
|
|
213
|
+
* Pagination values use `BooleanNumber.TRUE` or `BooleanNumber.FALSE`; explicit
|
|
214
|
+
* false is preserved and overrides inherited true. The paragraph and text-style
|
|
215
|
+
* changes share one undo/redo item. A stale paragraph handle returns `false`
|
|
216
|
+
* without applying a partial update.
|
|
217
|
+
*
|
|
218
|
+
* The Traditional renderer applies these Word-compatible pagination rules:
|
|
219
|
+
* use `pageBreakBefore` for a hard chapter-page boundary, `keepLines` for a
|
|
220
|
+
* short paragraph that should stay intact, `keepNext` for a heading or caption
|
|
221
|
+
* that should accompany the next paragraph, and `widowControl` for natural
|
|
222
|
+
* multi-line body text. Do not enable every rule on every paragraph. Modern
|
|
223
|
+
* and Unspecified Docs preserve the values in the model but do not apply them
|
|
224
|
+
* to physical pages.
|
|
225
|
+
*
|
|
145
226
|
* `style.textStyle.fs` is a font size in points (pt), not CSS pixels.
|
|
146
227
|
* @param {IParagraphStyle} style The Univer paragraph style patch.
|
|
147
|
-
* @returns {boolean} `true`
|
|
228
|
+
* @returns {boolean} `true` when the complete patch was applied; otherwise `false`.
|
|
148
229
|
* @example
|
|
149
230
|
* ```ts
|
|
150
|
-
* const
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
231
|
+
* const document = univerAPI.getActiveDocument();
|
|
232
|
+
* if (!document) {
|
|
233
|
+
* throw new Error('No active document');
|
|
234
|
+
* }
|
|
235
|
+
* if (!document.isTraditional()) {
|
|
236
|
+
* throw new Error('Traditional document pagination is required');
|
|
237
|
+
* }
|
|
238
|
+
* const heading = document.findParagraphByText('Appendix');
|
|
239
|
+
* const following = document.findParagraphByText('Supporting details');
|
|
240
|
+
* if (!heading || !following) {
|
|
241
|
+
* throw new Error('Expected paragraphs were not found');
|
|
242
|
+
* }
|
|
243
|
+
*
|
|
244
|
+
* const headingUpdated = heading.setStyle({
|
|
245
|
+
* pageBreakBefore: univerAPI.Enum.BooleanNumber.TRUE,
|
|
246
|
+
* keepLines: univerAPI.Enum.BooleanNumber.TRUE,
|
|
247
|
+
* keepNext: univerAPI.Enum.BooleanNumber.TRUE,
|
|
161
248
|
* });
|
|
162
|
-
*
|
|
249
|
+
* const followingUpdated = following.setStyle({
|
|
250
|
+
* // Explicit FALSE terminates this authored keepNext chain even if a named
|
|
251
|
+
* // style or document default enables it.
|
|
252
|
+
* keepNext: univerAPI.Enum.BooleanNumber.FALSE,
|
|
253
|
+
* widowControl: univerAPI.Enum.BooleanNumber.TRUE,
|
|
254
|
+
* });
|
|
255
|
+
* if (!headingUpdated || !followingUpdated) {
|
|
256
|
+
* throw new Error('Failed to update paragraph pagination');
|
|
257
|
+
* }
|
|
163
258
|
* ```
|
|
164
259
|
*/
|
|
165
260
|
setStyle(style: IParagraphStyle): boolean;
|
|
@@ -13,21 +13,20 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type {
|
|
17
|
-
import type { IHeaderFooterProps } from '@univerjs/docs';
|
|
16
|
+
import type { ISectionBreak, ISectionColumnProperties, SectionHeaderFooterKind, SectionHeaderFooterVariant } from '@univerjs/core';
|
|
17
|
+
import type { IEffectiveSectionPageSetup, IHeaderFooterProps } from '@univerjs/docs';
|
|
18
18
|
import type { FDocument } from './f-document';
|
|
19
19
|
import type { IFDocumentTextRange } from './utils';
|
|
20
|
-
import { ColumnSeparatorType, SectionType } from '@univerjs/core';
|
|
20
|
+
import { ColumnSeparatorType, ICommandService, SectionType } from '@univerjs/core';
|
|
21
21
|
export interface IFDocumentSectionColumnOptions {
|
|
22
|
-
/** Gap after each column except the last, in
|
|
22
|
+
/** Gap after each column except the last, in 96-DPI layout pixels. */
|
|
23
23
|
gap?: number;
|
|
24
|
-
/** Optional explicit column widths in
|
|
24
|
+
/** Optional explicit column widths in 96-DPI layout pixels. Length must equal `columnCount`. */
|
|
25
25
|
widths?: number[];
|
|
26
26
|
/** Whether to draw separators, or the exact separator enum value. */
|
|
27
27
|
separator?: boolean | ColumnSeparatorType;
|
|
28
|
-
/** How the following section starts. */
|
|
29
|
-
sectionType?: SectionType;
|
|
30
28
|
}
|
|
29
|
+
export type FDocumentSectionPageSetup = Pick<ISectionBreak, 'pageNumberStart' | 'pageSize' | 'pageOrient' | 'marginTop' | 'marginBottom' | 'marginLeft' | 'marginRight'>;
|
|
31
30
|
export interface IFDocumentSectionDescription {
|
|
32
31
|
sectionId: string;
|
|
33
32
|
index: number;
|
|
@@ -42,17 +41,18 @@ export interface IFDocumentSectionDescription {
|
|
|
42
41
|
}>;
|
|
43
42
|
config: ISectionBreak;
|
|
44
43
|
}
|
|
45
|
-
/** Error thrown when
|
|
44
|
+
/** Error thrown when a Traditional-only section API is used with another document flavor. */
|
|
46
45
|
export declare class DocsSectionUnsupportedDocumentFlavorError extends Error {
|
|
47
46
|
constructor();
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* Facade wrapper for an OOXML-compatible traditional document section.
|
|
51
|
-
* Modern documents use ColumnGroup APIs
|
|
50
|
+
* Modern documents use ColumnGroup APIs. Unspecified documents must resolve
|
|
51
|
+
* their flavor before using this facade.
|
|
52
52
|
* @example
|
|
53
53
|
* ```ts
|
|
54
54
|
* const fDocument = univerAPI.getActiveDocument();
|
|
55
|
-
* if (fDocument
|
|
55
|
+
* if (fDocument?.isTraditional()) {
|
|
56
56
|
* console.log(fDocument.getSection(0)?.describe());
|
|
57
57
|
* }
|
|
58
58
|
* ```
|
|
@@ -60,8 +60,8 @@ export declare class DocsSectionUnsupportedDocumentFlavorError extends Error {
|
|
|
60
60
|
export declare class FDocumentSection {
|
|
61
61
|
private readonly _document;
|
|
62
62
|
private readonly _sectionId;
|
|
63
|
-
private readonly
|
|
64
|
-
constructor(_document: FDocument, _sectionId: string,
|
|
63
|
+
private readonly _commandService;
|
|
64
|
+
constructor(_document: FDocument, _sectionId: string, _commandService: ICommandService);
|
|
65
65
|
/**
|
|
66
66
|
* Returns the persisted section id.
|
|
67
67
|
* @example
|
|
@@ -100,7 +100,7 @@ export declare class FDocumentSection {
|
|
|
100
100
|
getRange(): IFDocumentTextRange;
|
|
101
101
|
/**
|
|
102
102
|
* Returns the explicit columns. An empty array means the normal single-column layout.
|
|
103
|
-
* Column widths and trailing spaces are in
|
|
103
|
+
* Column widths and trailing spaces are in 96-DPI layout pixels.
|
|
104
104
|
* @example
|
|
105
105
|
* ```ts
|
|
106
106
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -120,22 +120,22 @@ export declare class FDocumentSection {
|
|
|
120
120
|
/**
|
|
121
121
|
* Sets equal or explicitly sized columns for this traditional section.
|
|
122
122
|
* Use `columnCount = 1` to restore normal single-column layout.
|
|
123
|
-
* `gap` and `widths` are in
|
|
123
|
+
* `gap` and `widths` are in 96-DPI layout pixels.
|
|
124
124
|
* @example
|
|
125
125
|
* ```ts
|
|
126
126
|
* const fDocument = univerAPI.getActiveDocument();
|
|
127
|
-
* if (fDocument
|
|
127
|
+
* if (fDocument?.isTraditional()) {
|
|
128
128
|
* fDocument.getSection(0)?.setColumns(2, { gap: 18, separator: true });
|
|
129
129
|
* }
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
setColumns(columnCount: number, options?: IFDocumentSectionColumnOptions): boolean;
|
|
133
133
|
/**
|
|
134
|
-
* Sets explicit OOXML-compatible column width and trailing-space values in
|
|
134
|
+
* Sets explicit OOXML-compatible column width and trailing-space values in 96-DPI layout pixels.
|
|
135
135
|
* @example
|
|
136
136
|
* ```ts
|
|
137
137
|
* const fDocument = univerAPI.getActiveDocument();
|
|
138
|
-
* if (fDocument
|
|
138
|
+
* if (fDocument?.isTraditional()) {
|
|
139
139
|
* fDocument.getSection(0)?.setColumnProperties([
|
|
140
140
|
* { width: 240, paddingEnd: 18 },
|
|
141
141
|
* { width: 240, paddingEnd: 0 },
|
|
@@ -145,22 +145,123 @@ export declare class FDocumentSection {
|
|
|
145
145
|
*/
|
|
146
146
|
setColumnProperties(columns: ISectionColumnProperties[], separator?: ColumnSeparatorType): boolean;
|
|
147
147
|
/**
|
|
148
|
-
* Sets how the
|
|
148
|
+
* Sets how this section begins relative to the previous section.
|
|
149
|
+
*
|
|
150
|
+
* The first section has no preceding boundary, so setting its type does not
|
|
151
|
+
* create an initial blank page. Prefer `FDocument.insertSectionBreak` with
|
|
152
|
+
* `nextSectionType` when creating a new boundary; use this method when
|
|
153
|
+
* updating an existing section after resolving it again from the document.
|
|
154
|
+
*
|
|
155
|
+
* @param {SectionType} sectionType How this section begins.
|
|
156
|
+
* @returns {boolean} `true` when the section command was applied.
|
|
149
157
|
* @example
|
|
150
158
|
* ```ts
|
|
151
|
-
* const
|
|
152
|
-
* if (
|
|
153
|
-
*
|
|
159
|
+
* const document = univerAPI.getActiveDocument();
|
|
160
|
+
* if (!document?.isTraditional()) {
|
|
161
|
+
* throw new Error('A Traditional document is required');
|
|
162
|
+
* }
|
|
163
|
+
*
|
|
164
|
+
* const secondSection = document.getSection(1);
|
|
165
|
+
* if (!secondSection) {
|
|
166
|
+
* throw new Error('The second section does not exist');
|
|
167
|
+
* }
|
|
168
|
+
* if (!secondSection.setSectionType(univerAPI.Enum.SectionType.NEXT_PAGE)) {
|
|
169
|
+
* throw new Error('Failed to update the second section');
|
|
154
170
|
* }
|
|
155
171
|
* ```
|
|
156
172
|
*/
|
|
157
173
|
setSectionType(sectionType: SectionType): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Returns this section's explicit page setup overrides.
|
|
176
|
+
* Missing values inherit from the document style. Geometry values use 96-DPI layout pixels.
|
|
177
|
+
*
|
|
178
|
+
* Use `getEffectivePageSetup()` when an agent needs resolved page and content
|
|
179
|
+
* dimensions rather than only the overrides stored on this section.
|
|
180
|
+
*
|
|
181
|
+
* @returns {FDocumentSectionPageSetup} A cloned object containing only explicit section overrides.
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* const document = univerAPI.getActiveDocument();
|
|
185
|
+
* const section = document?.getSection(0);
|
|
186
|
+
* console.log(section?.getPageSetup());
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
getPageSetup(): FDocumentSectionPageSetup;
|
|
190
|
+
/**
|
|
191
|
+
* Returns nominal page geometry after resolving this section's overrides
|
|
192
|
+
* against document defaults. All geometry values use 96-DPI layout pixels.
|
|
193
|
+
*
|
|
194
|
+
* This synchronous model-only API works without `engine-render`. It does not
|
|
195
|
+
* report physical page count, remaining page space, or final coordinates.
|
|
196
|
+
*
|
|
197
|
+
* @returns {IEffectiveSectionPageSetup} A cloned, serializable page setup.
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* const document = univerAPI.getActiveDocument();
|
|
201
|
+
* if (!document) {
|
|
202
|
+
* throw new Error('No active document');
|
|
203
|
+
* }
|
|
204
|
+
* if (!document.isTraditional()) {
|
|
205
|
+
* throw new Error('Traditional document sections are required');
|
|
206
|
+
* }
|
|
207
|
+
*
|
|
208
|
+
* const section = document.getSection(0);
|
|
209
|
+
* if (!section) {
|
|
210
|
+
* throw new Error('The document has no traditional section');
|
|
211
|
+
* }
|
|
212
|
+
*
|
|
213
|
+
* const layout = section.getEffectivePageSetup();
|
|
214
|
+
* console.log({
|
|
215
|
+
* pageWidth: layout.pageSize.width,
|
|
216
|
+
* pageHeight: layout.pageSize.height,
|
|
217
|
+
* contentWidth: layout.contentSize.width,
|
|
218
|
+
* contentHeight: layout.contentSize.height,
|
|
219
|
+
* margins: layout.margins,
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
getEffectivePageSetup(): IEffectiveSectionPageSetup;
|
|
224
|
+
/**
|
|
225
|
+
* Updates this section's page setup through the document section command.
|
|
226
|
+
* Geometry values use 96-DPI layout pixels.
|
|
227
|
+
*
|
|
228
|
+
* This method changes static page geometry; it does not choose where the
|
|
229
|
+
* section begins. Use `setSectionType()` for an existing boundary, or
|
|
230
|
+
* `insertSectionBreak(..., { nextSectionType })` while creating one.
|
|
231
|
+
*
|
|
232
|
+
* @param {FDocumentSectionPageSetup} pageSetup Explicit section overrides to patch.
|
|
233
|
+
* @returns {boolean} `true` when the section command was applied.
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* const document = univerAPI.getActiveDocument();
|
|
237
|
+
* if (!document?.isTraditional()) {
|
|
238
|
+
* throw new Error('A Traditional document is required');
|
|
239
|
+
* }
|
|
240
|
+
*
|
|
241
|
+
* const section = document.getSection(1);
|
|
242
|
+
* if (!section) {
|
|
243
|
+
* throw new Error('The second section does not exist');
|
|
244
|
+
* }
|
|
245
|
+
* const updated = section.setPageSetup({
|
|
246
|
+
* pageSize: { width: 816, height: 1056 },
|
|
247
|
+
* marginTop: 96,
|
|
248
|
+
* marginBottom: 96,
|
|
249
|
+
* marginLeft: 96,
|
|
250
|
+
* marginRight: 96,
|
|
251
|
+
* });
|
|
252
|
+
* if (!updated) {
|
|
253
|
+
* throw new Error('Failed to update section page setup');
|
|
254
|
+
* }
|
|
255
|
+
* console.log(section.getEffectivePageSetup());
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
setPageSetup(pageSetup: FDocumentSectionPageSetup): boolean;
|
|
158
259
|
/**
|
|
159
260
|
* Ensures a header segment linked specifically to this section.
|
|
160
261
|
* @example
|
|
161
262
|
* ```ts
|
|
162
263
|
* const fDocument = univerAPI.getActiveDocument();
|
|
163
|
-
* if (fDocument
|
|
264
|
+
* if (fDocument?.isTraditional()) {
|
|
164
265
|
* const segmentId = fDocument.getSection(0)?.ensureHeader();
|
|
165
266
|
* if (segmentId) {
|
|
166
267
|
* fDocument.insertText(0, 'Quarterly report', segmentId);
|
|
@@ -174,7 +275,7 @@ export declare class FDocumentSection {
|
|
|
174
275
|
* @example
|
|
175
276
|
* ```ts
|
|
176
277
|
* const fDocument = univerAPI.getActiveDocument();
|
|
177
|
-
* if (fDocument
|
|
278
|
+
* if (fDocument?.isTraditional()) {
|
|
178
279
|
* const segmentId = fDocument.getSection(0)?.ensureFooter('first');
|
|
179
280
|
* if (segmentId) {
|
|
180
281
|
* fDocument.insertText(0, 'Confidential', segmentId);
|
|
@@ -224,7 +325,7 @@ export declare class FDocumentSection {
|
|
|
224
325
|
* @example
|
|
225
326
|
* ```ts
|
|
226
327
|
* const fDocument = univerAPI.getActiveDocument();
|
|
227
|
-
* if (fDocument
|
|
328
|
+
* if (fDocument?.isTraditional()) {
|
|
228
329
|
* fDocument.getSection(1)?.setHeaderLinkedToPrevious(false, 'default');
|
|
229
330
|
* }
|
|
230
331
|
* ```
|
|
@@ -235,7 +336,7 @@ export declare class FDocumentSection {
|
|
|
235
336
|
* @example
|
|
236
337
|
* ```ts
|
|
237
338
|
* const fDocument = univerAPI.getActiveDocument();
|
|
238
|
-
* if (fDocument
|
|
339
|
+
* if (fDocument?.isTraditional()) {
|
|
239
340
|
* fDocument.getSection(1)?.setFooterLinkedToPrevious(true, 'even');
|
|
240
341
|
* }
|
|
241
342
|
* ```
|
|
@@ -243,11 +344,11 @@ export declare class FDocumentSection {
|
|
|
243
344
|
setFooterLinkedToPrevious(linkedToPrevious: boolean, variant?: SectionHeaderFooterVariant): boolean;
|
|
244
345
|
/**
|
|
245
346
|
* Updates header/footer switches and margins on this section break.
|
|
246
|
-
* `marginHeader` and `marginFooter` are in
|
|
347
|
+
* `marginHeader` and `marginFooter` are in 96-DPI layout pixels.
|
|
247
348
|
* @example
|
|
248
349
|
* ```ts
|
|
249
350
|
* const fDocument = univerAPI.getActiveDocument();
|
|
250
|
-
* if (fDocument
|
|
351
|
+
* if (fDocument?.isTraditional()) {
|
|
251
352
|
* fDocument.getSection(0)?.setHeaderFooterOptions({
|
|
252
353
|
* marginHeader: 36,
|
|
253
354
|
* marginFooter: 36,
|
|
@@ -262,7 +363,7 @@ export declare class FDocumentSection {
|
|
|
262
363
|
* @example
|
|
263
364
|
* ```ts
|
|
264
365
|
* const fDocument = univerAPI.getActiveDocument();
|
|
265
|
-
* if (fDocument
|
|
366
|
+
* if (fDocument?.isTraditional()) {
|
|
266
367
|
* const sections = fDocument.getSections();
|
|
267
368
|
* if (sections.length > 1) {
|
|
268
369
|
* sections[0].remove();
|
|
@@ -277,5 +378,7 @@ export declare class FDocumentSection {
|
|
|
277
378
|
private _describeHeaderFooterReference;
|
|
278
379
|
private _setHeaderFooterLinkedToPrevious;
|
|
279
380
|
private _assertTraditionalDocument;
|
|
381
|
+
private _getConfigSnapshot;
|
|
382
|
+
private _getRange;
|
|
280
383
|
private _resolve;
|
|
281
384
|
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import type { Injector, ITextStyle } from '@univerjs/core';
|
|
17
17
|
import type { FDocument } from './f-document';
|
|
18
18
|
import type { IFDocumentTextRange } from './utils';
|
|
19
|
+
import { FBaseInitialable } from '@univerjs/core/facade';
|
|
19
20
|
/** A clipped text-style run in document offsets. */
|
|
20
21
|
export interface IFDocumentTextStyleRun {
|
|
21
22
|
/** Inclusive start offset in the document segment. */
|
|
@@ -33,10 +34,6 @@ export interface IFDocumentTextRangeDescription extends IFDocumentTextRange {
|
|
|
33
34
|
explicitTextStyleRuns: IFDocumentTextStyleRun[];
|
|
34
35
|
/** Top-level explicit style properties common to the complete range. */
|
|
35
36
|
commonExplicitTextStyle: ITextStyle;
|
|
36
|
-
/** @deprecated Use `explicitTextStyleRuns`. */
|
|
37
|
-
textStyleRuns: IFDocumentTextStyleRun[];
|
|
38
|
-
/** @deprecated Use `commonExplicitTextStyle`. */
|
|
39
|
-
commonTextStyle: ITextStyle;
|
|
40
37
|
}
|
|
41
38
|
/**
|
|
42
39
|
* Facade wrapper for reading and styling a fixed document text range.
|
|
@@ -45,12 +42,12 @@ export interface IFDocumentTextRangeDescription extends IFDocumentTextRange {
|
|
|
45
42
|
* that insert or remove content before it.
|
|
46
43
|
* @hideconstructor
|
|
47
44
|
*/
|
|
48
|
-
export declare class FDocumentTextRange {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
export declare class FDocumentTextRange extends FBaseInitialable {
|
|
46
|
+
protected readonly _document: FDocument;
|
|
47
|
+
protected readonly _startOffset: number;
|
|
48
|
+
protected readonly _endOffset: number;
|
|
49
|
+
protected readonly _segmentId: string;
|
|
50
|
+
protected readonly _injector: Injector;
|
|
54
51
|
constructor(_document: FDocument, _startOffset: number, _endOffset: number, _segmentId: string, _injector: Injector);
|
|
55
52
|
/**
|
|
56
53
|
* Returns the serializable document range.
|
|
@@ -83,8 +80,6 @@ export declare class FDocumentTextRange {
|
|
|
83
80
|
* ```
|
|
84
81
|
*/
|
|
85
82
|
getExplicitTextStyleRuns(): IFDocumentTextStyleRun[];
|
|
86
|
-
/** @deprecated Use `getExplicitTextStyleRuns()` to distinguish stored styles from effective styles. */
|
|
87
|
-
getTextStyleRuns(): IFDocumentTextStyleRun[];
|
|
88
83
|
/**
|
|
89
84
|
* Returns top-level style properties that have the same explicit value
|
|
90
85
|
* across the complete range. Unstyled gaps make a property non-common.
|
|
@@ -96,8 +91,6 @@ export declare class FDocumentTextRange {
|
|
|
96
91
|
* ```
|
|
97
92
|
*/
|
|
98
93
|
getCommonExplicitTextStyle(): ITextStyle;
|
|
99
|
-
/** @deprecated Use `getCommonExplicitTextStyle()` to distinguish stored styles from effective styles. */
|
|
100
|
-
getCommonTextStyle(): ITextStyle;
|
|
101
94
|
/**
|
|
102
95
|
* Returns a serializable summary suitable for an agent/tool response.
|
|
103
96
|
* @example
|