@univerjs/docs 1.0.0-alpha.1 → 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 +1156 -868
- package/lib/cjs/index.js +723 -18
- package/lib/es/facade.js +1154 -867
- package/lib/es/index.js +701 -19
- package/lib/facade.js +1154 -867
- package/lib/index.js +701 -19
- package/lib/types/commands/commands/create-header-footer.command.d.ts +45 -0
- 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 +87 -100
- 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 +316 -26
- 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 +11 -6
- package/lib/types/facade/utils.d.ts +15 -1
- package/lib/types/index.d.ts +15 -1
- 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/types/utils/util.d.ts +19 -0
- package/lib/umd/facade.js +3 -1
- package/lib/umd/index.js +2 -1
- package/package.json +5 -5
- package/lib/types/facade/f-document-block-range.d.ts +0 -132
- package/lib/types/facade/f-document-body.d.ts +0 -276
- package/lib/types/facade/f-document-custom-block.d.ts +0 -57
- package/lib/types/facade/f-document-element.d.ts +0 -193
- package/lib/types/facade/f-document-table.d.ts +0 -57
|
@@ -13,10 +13,19 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { DocumentDataModel, IDocumentData } from '@univerjs/core';
|
|
16
|
+
import type { DocumentDataModel, IDocumentBody, IDocumentData, IParagraphBorder, ISectionBreak } from '@univerjs/core';
|
|
17
|
+
import type { IHeaderFooterProps } from '@univerjs/docs';
|
|
18
|
+
import type { IFDocumentTextRange } from './utils';
|
|
17
19
|
import { ICommandService, Injector, IResourceLoaderService, IUniverInstanceService } from '@univerjs/core';
|
|
18
20
|
import { FBaseInitialable } from '@univerjs/core/facade';
|
|
19
|
-
import {
|
|
21
|
+
import { FDocumentParagraph } from './f-document-paragraph';
|
|
22
|
+
import { FDocumentSection } from './f-document-section';
|
|
23
|
+
import { FDocumentTextRange } from './f-document-text-range';
|
|
24
|
+
export interface IFDocumentParagraphQuery {
|
|
25
|
+
text?: string;
|
|
26
|
+
paragraphId?: string;
|
|
27
|
+
segmentId?: string;
|
|
28
|
+
}
|
|
20
29
|
/**
|
|
21
30
|
* Facade API object bounded to a document. It provides a set of methods to interact with the document.
|
|
22
31
|
* @hideconstructor
|
|
@@ -31,39 +40,34 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
31
40
|
constructor(_documentDataModel: DocumentDataModel, _injector: Injector, _univerInstanceService: IUniverInstanceService, _resourceLoaderService: IResourceLoaderService, _commandService: ICommandService);
|
|
32
41
|
/**
|
|
33
42
|
* Get the document data model of the document.
|
|
43
|
+
* @param {string} segmentId The segment id used to get the header/footer data model. Defaults to an empty string for the document data model of the document.
|
|
34
44
|
* @returns {DocumentDataModel} The document data model.
|
|
35
45
|
* @example
|
|
36
46
|
* ```typescript
|
|
37
47
|
* const fDocument = univerAPI.getActiveDocument();
|
|
38
|
-
*
|
|
39
|
-
*
|
|
48
|
+
* console.log(fDocument.getDocumentDataModel());
|
|
49
|
+
*
|
|
50
|
+
* const headerSegmentId = fDocument.ensurePageHeader();
|
|
51
|
+
* console.log(fDocument.getDocumentDataModel(headerSegmentId));
|
|
40
52
|
* ```
|
|
41
53
|
*/
|
|
42
|
-
getDocumentDataModel(): DocumentDataModel;
|
|
54
|
+
getDocumentDataModel(segmentId?: string): DocumentDataModel;
|
|
43
55
|
/**
|
|
44
|
-
* Get the document body
|
|
45
|
-
*
|
|
46
|
-
* The
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* and custom blocks, use their existing ids.
|
|
50
|
-
*
|
|
51
|
-
* @returns {FDocumentBody} The document body API instance.
|
|
56
|
+
* Get the document body or header/footer body by the segment id.
|
|
57
|
+
* The main body has an empty segment id.
|
|
58
|
+
* The header and footer body have their respective segment ids.
|
|
59
|
+
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
60
|
+
* @returns {IDocumentBody} The document body.
|
|
52
61
|
* @example
|
|
53
62
|
* ```typescript
|
|
54
63
|
* const fDocument = univerAPI.getActiveDocument();
|
|
55
|
-
*
|
|
56
|
-
* console.log(fDocumentBody.getBody());
|
|
64
|
+
* console.log(fDocument.getBody()); // Get the main body
|
|
57
65
|
*
|
|
58
|
-
* const
|
|
59
|
-
*
|
|
60
|
-
* const paragraph = element.asParagraph();
|
|
61
|
-
* paragraph.appendText(' updated');
|
|
62
|
-
* console.log(paragraph.getText());
|
|
63
|
-
* }
|
|
66
|
+
* const footerSegmentId = fDocument.ensurePageFooter();
|
|
67
|
+
* console.log(fDocument.getBody(footerSegmentId)); // Get the footer body
|
|
64
68
|
* ```
|
|
65
69
|
*/
|
|
66
|
-
getBody():
|
|
70
|
+
getBody(segmentId?: string): IDocumentBody;
|
|
67
71
|
dispose(): void;
|
|
68
72
|
/**
|
|
69
73
|
* Get the document id.
|
|
@@ -71,8 +75,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
71
75
|
* @example
|
|
72
76
|
* ```typescript
|
|
73
77
|
* const fDocument = univerAPI.getActiveDocument();
|
|
74
|
-
*
|
|
75
|
-
* console.log(unitId);
|
|
78
|
+
* console.log(fDocument.getId());
|
|
76
79
|
* ```
|
|
77
80
|
*/
|
|
78
81
|
getId(): string;
|
|
@@ -82,11 +85,20 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
82
85
|
* @example
|
|
83
86
|
* ```typescript
|
|
84
87
|
* const fDocument = univerAPI.getActiveDocument();
|
|
85
|
-
*
|
|
86
|
-
* console.log(name);
|
|
88
|
+
* console.log(fDocument.getName());
|
|
87
89
|
* ```
|
|
88
90
|
*/
|
|
89
91
|
getName(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Whether the document is a modern document or not.
|
|
94
|
+
* @returns {boolean} `true` if the document is a modern document, or `false` if it is not.
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
98
|
+
* console.log(fDocument.isModern());
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
isModern(): boolean;
|
|
90
102
|
/**
|
|
91
103
|
* Save the document snapshot data, including the document content and resource data, etc.
|
|
92
104
|
* @returns {IDocumentData} The document snapshot data.
|
|
@@ -120,4 +132,282 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
120
132
|
* ```
|
|
121
133
|
*/
|
|
122
134
|
redo(): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Ensure the page header segment exists and return its segment id.
|
|
137
|
+
* @param {number} pageIndex The zero-based page index. Defaults to the first page.
|
|
138
|
+
* @returns {string} The header segment id.
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
142
|
+
* const headerSegmentId = fDocument.ensurePageHeader();
|
|
143
|
+
* fDocument.insertText(0, 'Header text', headerSegmentId);
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
ensurePageHeader(pageIndex?: number): string;
|
|
147
|
+
/**
|
|
148
|
+
* Ensure the page footer segment exists and return its segment id.
|
|
149
|
+
* @param {number} pageIndex The zero-based page index. Defaults to the first page.
|
|
150
|
+
* @returns {string} The footer segment id.
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
154
|
+
* const footerSegmentId = fDocument.ensurePageFooter();
|
|
155
|
+
* fDocument.insertText(0, 'Footer text', footerSegmentId);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
ensurePageFooter(pageIndex?: number): string;
|
|
159
|
+
/**
|
|
160
|
+
* Insert plain text at a document body offset.
|
|
161
|
+
* @param {number} index The zero-based insertion offset.
|
|
162
|
+
* @param {string} text The plain text to insert.
|
|
163
|
+
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
164
|
+
* @returns {boolean} `true` if the edit was applied.
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
168
|
+
* fDocument.insertText(0, 'Hello ');
|
|
169
|
+
*
|
|
170
|
+
* const headerSegmentId = fDocument.ensurePageHeader();
|
|
171
|
+
* fDocument.insertText(0, 'Header text', headerSegmentId);
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
insertText(index: number, text: string, segmentId?: string): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Returns document-level header/footer switches and margins. Margin values are in points (pt).
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
180
|
+
* console.log(fDocument?.getHeaderFooterOptions());
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
getHeaderFooterOptions(): IHeaderFooterProps;
|
|
184
|
+
/**
|
|
185
|
+
* Updates document-level header/footer switches and margins in a traditional document.
|
|
186
|
+
* `marginHeader` and `marginFooter` are in points (pt).
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
190
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
191
|
+
* fDocument.setHeaderFooterOptions({ marginHeader: 36, marginFooter: 36 });
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
setHeaderFooterOptions(options: IHeaderFooterProps): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Creates a facade for reading and styling a document text range.
|
|
198
|
+
* The end offset is exclusive, and offsets are scoped to the selected body segment.
|
|
199
|
+
* @param {number} startOffset The inclusive start offset.
|
|
200
|
+
* @param {number} endOffset The exclusive end offset.
|
|
201
|
+
* @param {string} segmentId The header/footer segment id, or an empty string for the main body.
|
|
202
|
+
* @returns {FDocumentTextRange} A fixed text-range facade.
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const range = univerAPI.getActiveDocument()?.getTextRange(0, 5);
|
|
206
|
+
* console.log(range?.describe());
|
|
207
|
+
* range?.setTextStyle({ bl: 1 });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
getTextRange(startOffset: number, endOffset: number, segmentId?: string): FDocumentTextRange;
|
|
211
|
+
/**
|
|
212
|
+
* Returns traditional document sections backed by persisted SectionBreak ids.
|
|
213
|
+
* Modern documents use ColumnGroup instead and return an empty array from this read API.
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
217
|
+
* const sections = fDocument?.getSections() ?? [];
|
|
218
|
+
* console.log(sections.map((section) => section.describe()));
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
getSections(): FDocumentSection[];
|
|
222
|
+
/**
|
|
223
|
+
* Returns a traditional section by zero-based index, or `null` in modern documents.
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
227
|
+
* const firstSection = fDocument?.getSection(0);
|
|
228
|
+
* console.log(firstSection?.describe());
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
getSection(index: number): FDocumentSection | null;
|
|
232
|
+
/**
|
|
233
|
+
* Returns the traditional section containing a data-stream offset, or `null` in modern documents.
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
237
|
+
* const paragraph = fDocument?.findParagraphByText('Launch');
|
|
238
|
+
* const offset = paragraph?.getInfo().startOffset;
|
|
239
|
+
* const section = offset == null ? null : fDocument?.getSectionAt(offset);
|
|
240
|
+
* console.log(section?.getId());
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
getSectionAt(offset: number): FDocumentSection | null;
|
|
244
|
+
/**
|
|
245
|
+
* Inserts a traditional document section break and returns its stable facade.
|
|
246
|
+
* Modern documents must use ColumnGroup and throw `DocsSectionUnsupportedDocumentFlavorError`.
|
|
247
|
+
* Numeric layout values in `config` are in points (pt).
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
251
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
252
|
+
* const paragraph = fDocument.findParagraphByText('Appendix');
|
|
253
|
+
* const offset = paragraph?.getInfo().startOffset;
|
|
254
|
+
* const section = offset == null ? null : fDocument.insertSectionBreak(offset);
|
|
255
|
+
* console.log(section?.getId());
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
insertSectionBreak(offset: number, config?: Partial<Omit<ISectionBreak, 'sectionId' | 'startIndex'>>): FDocumentSection | null;
|
|
260
|
+
/**
|
|
261
|
+
* Inserts a column-break token in a traditional document.
|
|
262
|
+
* Modern documents must use ColumnGroup and throw `DocsSectionUnsupportedDocumentFlavorError`.
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
266
|
+
* if (fDocument && !fDocument.isModern()) {
|
|
267
|
+
* const paragraph = fDocument.findParagraphByText('Continue in next column');
|
|
268
|
+
* const offset = paragraph?.getInfo().startOffset;
|
|
269
|
+
* if (offset != null) {
|
|
270
|
+
* fDocument.insertColumnBreak(offset);
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
insertColumnBreak(offset: number): boolean;
|
|
276
|
+
/**
|
|
277
|
+
* Inserts a horizontal rule using the existing paragraph `borderBottom` mechanism.
|
|
278
|
+
* The returned paragraph can be inspected or removed with normal paragraph APIs.
|
|
279
|
+
* Border width and padding are in points (pt).
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
283
|
+
* const paragraph = fDocument?.findParagraphByText('Summary');
|
|
284
|
+
* const offset = paragraph?.getInfo().startOffset;
|
|
285
|
+
* const rule = offset == null ? null : fDocument?.insertHorizontalRule(offset);
|
|
286
|
+
* console.log(rule?.getId());
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
insertHorizontalRule(offset: number, border?: IParagraphBorder, segmentId?: string): FDocumentParagraph | null;
|
|
290
|
+
/**
|
|
291
|
+
* Get all paragraphs in the document body or header/footer body by the segment id.
|
|
292
|
+
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
293
|
+
* @returns {FDocumentParagraph[]} An array of paragraph facade instances.
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
297
|
+
* const paragraphs = fDocument.getParagraphs();
|
|
298
|
+
* console.log(paragraphs);
|
|
299
|
+
*
|
|
300
|
+
* const headerSegmentId = fDocument.ensurePageHeader();
|
|
301
|
+
* const headerParagraphs = fDocument.getParagraphs(headerSegmentId);
|
|
302
|
+
* console.log(headerParagraphs);
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
getParagraphs(segmentId?: string): FDocumentParagraph[];
|
|
306
|
+
/**
|
|
307
|
+
* Get a paragraph by its paragraph id and segment id.
|
|
308
|
+
* @param {string} paragraphId The paragraph id.
|
|
309
|
+
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
310
|
+
* @returns {FDocumentParagraph | null} The paragraph facade instance, or `null` if the paragraph is not found.
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
314
|
+
* const paragraph = fDocument.getParagraph('paragraph-01');
|
|
315
|
+
* console.log(paragraph);
|
|
316
|
+
*
|
|
317
|
+
* const headerSegmentId = fDocument.ensurePageHeader();
|
|
318
|
+
* const headerParagraph = fDocument.getParagraph('header-paragraph-01', headerSegmentId);
|
|
319
|
+
* console.log(headerParagraph);
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
getParagraph(paragraphId: string, segmentId?: string): FDocumentParagraph | null;
|
|
323
|
+
/**
|
|
324
|
+
* Find a paragraph by its text content and segment id.
|
|
325
|
+
* @param {string} text The text content to search for.
|
|
326
|
+
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
327
|
+
* @returns {FDocumentParagraph | null} The paragraph facade instance, or `null` if the paragraph is not found.
|
|
328
|
+
* @example
|
|
329
|
+
* ```ts
|
|
330
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
331
|
+
* const paragraph = fDocument.findParagraphByText('Hello');
|
|
332
|
+
* console.log(paragraph);
|
|
333
|
+
*
|
|
334
|
+
* const footerSegmentId = fDocument.ensurePageFooter();
|
|
335
|
+
* const footerParagraph = fDocument.findParagraphByText('Page', footerSegmentId);
|
|
336
|
+
* console.log(footerParagraph);
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
findParagraphByText(text: string, segmentId?: string): FDocumentParagraph | null;
|
|
340
|
+
/**
|
|
341
|
+
* Find paragraphs by a query object, which can include text content, paragraph id, and segment id.
|
|
342
|
+
* @param {string | IFDocumentParagraphQuery} query The query object or text content to search for.
|
|
343
|
+
* @returns {FDocumentParagraph[]} An array of paragraph facade instances that match the query.
|
|
344
|
+
* @example
|
|
345
|
+
* ```ts
|
|
346
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
347
|
+
* const paragraphsWithText = fDocument.findParagraphs('Hello');
|
|
348
|
+
* console.log(paragraphsWithText);
|
|
349
|
+
*
|
|
350
|
+
* const paragraphsWithId = fDocument.findParagraphs({ paragraphId: 'paragraph-01' });
|
|
351
|
+
* console.log(paragraphsWithId);
|
|
352
|
+
*
|
|
353
|
+
* const headerSegmentId = fDocument.ensurePageHeader();
|
|
354
|
+
* const paragraphsWithSegment = fDocument.findParagraphs({ segmentId: headerSegmentId });
|
|
355
|
+
* console.log(paragraphsWithSegment);
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
findParagraphs(query: string | IFDocumentParagraphQuery): FDocumentParagraph[];
|
|
359
|
+
/**
|
|
360
|
+
* Insert a plain-text paragraph before the paragraph at the given paragraph index.
|
|
361
|
+
* @param {number} index The zero-based paragraph insertion index.
|
|
362
|
+
* @param {string} text The paragraph text. Defaults to an empty paragraph.
|
|
363
|
+
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
364
|
+
* @returns {FDocumentParagraph} The inserted paragraph facade instance.
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
368
|
+
* const paragraph = fDocument.insertParagraph(0, 'Document title');
|
|
369
|
+
* paragraph.appendText(' suffix');
|
|
370
|
+
*
|
|
371
|
+
* const headerSegmentId = fDocument.ensurePageHeader();
|
|
372
|
+
* const headerParagraph = fDocument.insertParagraph(0, 'Header title', headerSegmentId);
|
|
373
|
+
* headerParagraph.appendText(' suffix');
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
insertParagraph(index: number, text?: string, segmentId?: string): FDocumentParagraph;
|
|
377
|
+
/**
|
|
378
|
+
* Append a plain-text paragraph at the end of the body.
|
|
379
|
+
* @param {string} text The paragraph text. Defaults to an empty paragraph.
|
|
380
|
+
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
381
|
+
* @returns {FDocumentParagraph} The appended paragraph wrapper.
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
385
|
+
* const paragraph = fDocument.appendParagraph('Summary');
|
|
386
|
+
* console.log(paragraph.getText());
|
|
387
|
+
*
|
|
388
|
+
* const footerSegmentId = fDocument.ensurePageFooter();
|
|
389
|
+
* const footerParagraph = fDocument.appendParagraph('Confidential', footerSegmentId);
|
|
390
|
+
* console.log(footerParagraph.getText());
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
appendParagraph(text?: string, segmentId?: string): FDocumentParagraph;
|
|
394
|
+
/**
|
|
395
|
+
* Delete a range from the body.
|
|
396
|
+
* @param {IFDocumentTextRange} range The text range to delete.
|
|
397
|
+
* @returns {boolean} `true` if the range was deleted.
|
|
398
|
+
* @example
|
|
399
|
+
* ```ts
|
|
400
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
401
|
+
* fDocument.deleteRange({ startOffset: 0, endOffset: 5 });
|
|
402
|
+
*
|
|
403
|
+
* const headerSegmentId = fDocument.ensurePageHeader();
|
|
404
|
+
* fDocument.deleteRange({ startOffset: 0, endOffset: 5, segmentId: headerSegmentId });
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
deleteRange(range: IFDocumentTextRange): boolean;
|
|
408
|
+
private _createFDocumentParagraph;
|
|
409
|
+
private _normalizeDeleteRange;
|
|
410
|
+
private _getParagraphInsertOffset;
|
|
411
|
+
private _ensureHeaderFooter;
|
|
412
|
+
private _getHeaderFooterCreateInfo;
|
|
123
413
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { ColumnSeparatorType, SectionType } from '@univerjs/core';
|
|
17
|
+
import { FEnum } from '@univerjs/core/facade';
|
|
18
|
+
/** @ignore */
|
|
19
|
+
export interface IFDocsEnumMixin {
|
|
20
|
+
/** OOXML-compatible section start types. */
|
|
21
|
+
SectionType: typeof SectionType;
|
|
22
|
+
/** Section column separator types. */
|
|
23
|
+
ColumnSeparatorType: typeof ColumnSeparatorType;
|
|
24
|
+
}
|
|
25
|
+
export declare class FDocsEnumMixin extends FEnum implements IFDocsEnumMixin {
|
|
26
|
+
get SectionType(): typeof SectionType;
|
|
27
|
+
get ColumnSeparatorType(): typeof ColumnSeparatorType;
|
|
28
|
+
}
|
|
29
|
+
declare module '@univerjs/core/facade' {
|
|
30
|
+
interface FEnum extends IFDocsEnumMixin {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export type FDocEmbedUnitFacadeMapAugmentation = never;
|
|
@@ -14,10 +14,15 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import './f-univer';
|
|
17
|
+
import './f-enum';
|
|
17
18
|
export { FDocument } from './f-document';
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
19
|
+
export { FDocumentParagraph, isParagraphFacade } from './f-document-paragraph';
|
|
20
|
+
export type { IFDocumentParagraphInfo } from './f-document-paragraph';
|
|
21
|
+
export { DocsSectionUnsupportedDocumentFlavorError, FDocumentSection } from './f-document-section';
|
|
22
|
+
export type { IFDocumentSectionColumnOptions, IFDocumentSectionDescription } from './f-document-section';
|
|
23
|
+
export { FDocumentTextRange } from './f-document-text-range';
|
|
24
|
+
export type { IFDocumentTextRangeDescription, IFDocumentTextStyleRun } from './f-document-text-range';
|
|
25
|
+
export * from './f-enum';
|
|
26
|
+
export type { FDocEmbedUnitFacadeMapAugmentation } from './f-types';
|
|
27
|
+
export type { IFDocumentTextRange } from './utils';
|
|
28
|
+
export { stripBlockTokens } from './utils';
|
|
@@ -13,12 +13,26 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IDocumentBody, IParagraphStyle } from '@univerjs/core';
|
|
16
|
+
import type { DocumentDataModel, IDocumentBody, Injector, IParagraphStyle, UpdateDocsAttributeType } from '@univerjs/core';
|
|
17
17
|
export interface IBuildPlainTextInsertBodyOptions {
|
|
18
18
|
paragraphStyle?: IParagraphStyle;
|
|
19
19
|
removeLeadingParagraphBreak?: boolean;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A text range in a document segment. Offsets are zero-based positions in the segment data stream.
|
|
23
|
+
*/
|
|
24
|
+
export interface IFDocumentTextRange {
|
|
25
|
+
/** The inclusive start offset of the range. */
|
|
26
|
+
startOffset: number;
|
|
27
|
+
/** The exclusive end offset of the range. */
|
|
28
|
+
endOffset: number;
|
|
29
|
+
/** The header/footer segment id. Omit or use an empty string for the main body. */
|
|
30
|
+
segmentId?: string;
|
|
31
|
+
}
|
|
21
32
|
export declare function getRemovedLeadingParagraphBreakLength(dataStream: string, removeLeadingParagraphBreak?: boolean): number;
|
|
22
33
|
export declare function getNormalizedPlainTextCursorOffset(dataStream: string, cursorOffset: number, removeLeadingParagraphBreak?: boolean): number;
|
|
23
34
|
export declare function getParagraphStyleAtOffset(body: IDocumentBody, offset: number): IParagraphStyle | undefined;
|
|
24
35
|
export declare function buildPlainTextInsertBody(dataStream: string, options?: IBuildPlainTextInsertBodyOptions): IDocumentBody;
|
|
36
|
+
export declare function replaceBodyRange(range: IFDocumentTextRange, insertBody: IDocumentBody, docDataModel: DocumentDataModel, injector: Injector): boolean;
|
|
37
|
+
export declare function retainBodyRange(range: IFDocumentTextRange, updateBody: IDocumentBody, coverType: UpdateDocsAttributeType, docDataModel: DocumentDataModel, injector: Injector): boolean;
|
|
38
|
+
export declare function stripBlockTokens(text: string): string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,14 +15,24 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export { DeleteTextCommand, InsertTextCommand, UpdateTextCommand } from './commands/commands/core-editing.command';
|
|
17
17
|
export type { IDeleteTextCommandParams, IInsertTextCommandParams, IUpdateTextCommandParams, } from './commands/commands/core-editing.command';
|
|
18
|
+
export { CreateHeaderFooterCommand, HeaderFooterType } from './commands/commands/create-header-footer.command';
|
|
19
|
+
export type { HeaderFooterCreateMode, ICreateHeaderFooterCommandParams, IHeaderFooterProps, } from './commands/commands/create-header-footer.command';
|
|
20
|
+
export { SetDocumentDefaultParagraphStyleCommand } from './commands/commands/set-document-default-paragraph-style.command';
|
|
21
|
+
export type { IDocumentDefaultParagraphStylePatch, ISetDocumentDefaultParagraphStyleCommandParams, } from './commands/commands/set-document-default-paragraph-style.command';
|
|
22
|
+
export { SetSectionHeaderFooterLinkCommand } from './commands/commands/set-section-header-footer-link.command';
|
|
23
|
+
export type { ISetSectionHeaderFooterLinkCommandParams } from './commands/commands/set-section-header-footer-link.command';
|
|
24
|
+
export { DeleteDocumentSectionBreakCommand, InsertDocumentSectionBreakCommand, UpdateDocumentSectionCommand } from './commands/commands/update-document-section.command';
|
|
25
|
+
export type { IDeleteDocumentSectionBreakCommandParams, IDocumentSectionConfig, IDocumentSectionUpdate, IInsertDocumentSectionBreakCommandParams, IUpdateDocumentSectionCommandParams } from './commands/commands/update-document-section.command';
|
|
18
26
|
export { RichTextEditingMutation } from './commands/mutations/core-editing.mutation';
|
|
19
27
|
export type { IRichTextEditingMutationParams } from './commands/mutations/core-editing.mutation';
|
|
20
28
|
export { SetTextSelectionsOperation } from './commands/operations/text-selection.operation';
|
|
21
29
|
export type { ISetTextSelectionsOperationParams } from './commands/operations/text-selection.operation';
|
|
22
30
|
export type { IUniverDocsConfig } from './config/config';
|
|
31
|
+
export { createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, isEmbedDocsCustomBlockData, isSheetLikeDocsCustomBlockChildType, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, } from './embed-host-anchor';
|
|
32
|
+
export type { EmbedDocsCustomBlockInteractionMode, IDocsCustomBlockMutationParams, IEmbedDocsCustomBlockData, } from './embed-host-anchor';
|
|
23
33
|
export { UniverDocsPlugin } from './plugin';
|
|
24
34
|
export { DocBlockMoveValidatorService } from './services/doc-block-move-validator.service';
|
|
25
|
-
export type { DocBlockMoveTransformer, DocBlockMoveValidator, IDocBlockMoveResult, IDocBlockMoveTransformContext, IDocBlockMoveValidationContext } from './services/doc-block-move-validator.service';
|
|
35
|
+
export type { DocBlockMoveTransformer, DocBlockMoveValidator, IDocBlockMoveResult, IDocBlockMoveTransformContext, IDocBlockMoveValidationContext, } from './services/doc-block-move-validator.service';
|
|
26
36
|
export { DocContentInsertService } from './services/doc-content-insert.service';
|
|
27
37
|
export type { IDocContentInsertRange } from './services/doc-content-insert.service';
|
|
28
38
|
export { DocInterceptorService } from './services/doc-interceptor/doc-interceptor.service';
|
|
@@ -33,4 +43,8 @@ export { DocStateChangeManagerService, IDocStateChangeInterceptorService, } from
|
|
|
33
43
|
export type { IDocStateChangeInfo, IDocStateChangeParams } from './services/doc-state-emit.service';
|
|
34
44
|
export { DocStateEmitService } from './services/doc-state-emit.service';
|
|
35
45
|
export { addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory, } from './utils/custom-range-factory';
|
|
46
|
+
export { generateParagraphs } from './utils/paragraphs';
|
|
36
47
|
export { replaceSelectionFactory } from './utils/replace-selection-factory';
|
|
48
|
+
export { createSectionColumnProperties } from './utils/section-columns';
|
|
49
|
+
export { getTopLevelSectionBreaks } from './utils/sections';
|
|
50
|
+
export { consumeContentInsertRange, isHeaderFooterSelection } from './utils/util';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IParagraph, IParagraphBorder } from '@univerjs/core';
|
|
17
|
+
/** Builds paragraph metadata for inserted paragraph tokens, including horizontal-rule borders. */
|
|
18
|
+
export declare function generateParagraphs(dataStream: string, prevParagraph?: IParagraph, borderBottom?: IParagraphBorder, existingParagraphIds?: Iterable<string>): IParagraph[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IDocumentStyle, ISectionBreak, ISectionColumnProperties } from '@univerjs/core';
|
|
17
|
+
/** Creates explicit OOXML section columns from a count, gap, and optional widths. */
|
|
18
|
+
export declare function createSectionColumnProperties(documentStyle: IDocumentStyle | undefined, section: ISectionBreak | undefined, columnCount: number, gap: number, widths?: number[]): ISectionColumnProperties[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IDocumentBody, ISectionBreak } from '@univerjs/core';
|
|
17
|
+
/** Returns document-level section breaks, excluding table-cell and modern-column sentinels. */
|
|
18
|
+
export declare function getTopLevelSectionBreaks(body: IDocumentBody): ISectionBreak[];
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { IAccessor } from '@univerjs/core';
|
|
17
|
+
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
|
+
export declare function consumeContentInsertRange(accessor: IAccessor, unitId: string): import("..").IDocContentInsertRange | null;
|
|
19
|
+
export declare function isHeaderFooterSelection(range?: ITextRangeWithStyle): boolean;
|