@univerjs/docs 1.0.0-alpha.0 → 1.0.0-alpha.1
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 +834 -1405
- package/lib/cjs/index.js +30 -1
- package/lib/es/facade.js +831 -1400
- package/lib/es/index.js +30 -2
- package/lib/facade.js +831 -1400
- package/lib/index.js +30 -2
- package/lib/types/facade/f-document-block-range.d.ts +132 -0
- package/lib/types/facade/f-document-body.d.ts +276 -0
- package/lib/types/facade/f-document-custom-block.d.ts +57 -0
- package/lib/types/facade/f-document-element.d.ts +193 -0
- package/lib/types/facade/f-document-paragraph.d.ts +231 -0
- package/lib/types/facade/f-document-table.d.ts +57 -0
- package/lib/types/facade/f-document.d.ts +12 -94
- package/lib/types/facade/index.d.ts +6 -8
- package/lib/types/facade/utils.d.ts +2 -4
- package/lib/types/index.d.ts +2 -0
- package/lib/types/services/doc-block-move-validator.service.d.ts +46 -0
- package/lib/umd/facade.js +1 -5
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
- package/lib/types/facade/doc-element-registry.d.ts +0 -84
- package/lib/types/facade/f-doc-block-range.d.ts +0 -139
- package/lib/types/facade/f-doc-body.d.ts +0 -535
- package/lib/types/facade/f-doc-custom-block.d.ts +0 -94
- package/lib/types/facade/f-doc-element.d.ts +0 -177
- package/lib/types/facade/f-doc-paragraph.d.ts +0 -194
- package/lib/types/facade/f-doc-table.d.ts +0 -94
|
@@ -1,535 +0,0 @@
|
|
|
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 { DocumentDataModel, ICommandService, ICustomBlock, ICustomTable, IDocumentBlockRange, IDocumentBody, IParagraph, IParagraphStyle, ITextStyle } from '@univerjs/core';
|
|
17
|
-
import type { DocElementRegistry, FDocElementType } from './doc-element-registry';
|
|
18
|
-
import { FDocElement } from './f-doc-element';
|
|
19
|
-
import { FDocParagraph } from './f-doc-paragraph';
|
|
20
|
-
/**
|
|
21
|
-
* A text range in a document segment. Offsets are zero-based positions in the segment data stream.
|
|
22
|
-
*/
|
|
23
|
-
export interface IFDocTextRange {
|
|
24
|
-
/** The inclusive start offset of the range. */
|
|
25
|
-
startOffset: number;
|
|
26
|
-
/** The exclusive end offset of the range. */
|
|
27
|
-
endOffset: number;
|
|
28
|
-
/** The header/footer segment id. Omit or use an empty string for the main body. */
|
|
29
|
-
segmentId?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Resolved paragraph metadata in the current document body.
|
|
33
|
-
*/
|
|
34
|
-
export interface IFDocResolvedParagraph {
|
|
35
|
-
/** The underlying paragraph snapshot object. */
|
|
36
|
-
paragraph: IParagraph;
|
|
37
|
-
/** The current paragraph index in the body paragraph list. */
|
|
38
|
-
paragraphIndex: number;
|
|
39
|
-
/** The inclusive start offset of the paragraph text. */
|
|
40
|
-
startOffset: number;
|
|
41
|
-
/** The exclusive end offset of the paragraph text, before the paragraph break. */
|
|
42
|
-
endOffset: number;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* A stable facade element handle that can be resolved by type and key.
|
|
46
|
-
*/
|
|
47
|
-
export interface IFDocElementHandle {
|
|
48
|
-
/**
|
|
49
|
-
* Get the element type.
|
|
50
|
-
* @returns {FDocElementType} The element type used by the facade resolver.
|
|
51
|
-
*/
|
|
52
|
-
getType(): FDocElementType;
|
|
53
|
-
/**
|
|
54
|
-
* Get the persisted key used by the facade to resolve the element.
|
|
55
|
-
* @returns {string} The facade key.
|
|
56
|
-
*/
|
|
57
|
-
getKey(): string;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* A rich-text-like object, such as `RichTextValue` or `RichTextBuilder`, that can provide document body data.
|
|
61
|
-
*/
|
|
62
|
-
export interface IFDocRichTextLike {
|
|
63
|
-
/**
|
|
64
|
-
* Get rich text data that contains document body data.
|
|
65
|
-
* @returns {{ body?: IDocumentBody }} The rich text data object.
|
|
66
|
-
*/
|
|
67
|
-
getData(): {
|
|
68
|
-
body?: IDocumentBody;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
interface IFDocChildInfo {
|
|
72
|
-
type: FDocElementType;
|
|
73
|
-
key: string;
|
|
74
|
-
position: number;
|
|
75
|
-
priority: number;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* A Facade API object bounded to a document body or header/footer segment.
|
|
79
|
-
* It provides Google Docs-like element access and range editing methods.
|
|
80
|
-
*
|
|
81
|
-
* Paragraph elements use their persisted `paragraphId`. Tables, block ranges, and
|
|
82
|
-
* custom blocks use their persisted ids.
|
|
83
|
-
*
|
|
84
|
-
* @hideconstructor
|
|
85
|
-
*/
|
|
86
|
-
export declare class FDocBody {
|
|
87
|
-
private readonly _documentDataModel;
|
|
88
|
-
private readonly _commandService;
|
|
89
|
-
private readonly _segmentId;
|
|
90
|
-
constructor(_documentDataModel: DocumentDataModel, _commandService: ICommandService, _registry: DocElementRegistry, _segmentId?: string);
|
|
91
|
-
/**
|
|
92
|
-
* Get the number of top-level child elements in the body.
|
|
93
|
-
* @returns {number} The number of child elements.
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* const doc = univerAPI.getActiveDocument();
|
|
97
|
-
* if (!doc) throw new Error('No active document');
|
|
98
|
-
*
|
|
99
|
-
* const body = doc.getBody();
|
|
100
|
-
* console.log(body.getNumChildren());
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
getNumChildren(): number;
|
|
104
|
-
/**
|
|
105
|
-
* Get a top-level child element by child index.
|
|
106
|
-
* @param {number} index The zero-based child index.
|
|
107
|
-
* @returns {FDocElement} The child element wrapper.
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* const doc = univerAPI.getActiveDocument();
|
|
111
|
-
* if (!doc) throw new Error('No active document');
|
|
112
|
-
*
|
|
113
|
-
* const body = doc.getBody();
|
|
114
|
-
* const firstChild = body.getChild(0);
|
|
115
|
-
* console.log(firstChild.getType());
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
getChild(index: number): FDocElement;
|
|
119
|
-
/**
|
|
120
|
-
* Get the current child index of an element handle.
|
|
121
|
-
* The index is resolved from the element key, so a paragraph handle keeps pointing
|
|
122
|
-
* to the same paragraph after facade edits insert content before it.
|
|
123
|
-
* @param {IFDocElementHandle} element The element handle to locate.
|
|
124
|
-
* @returns {number} The current zero-based child index.
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* const doc = univerAPI.getActiveDocument();
|
|
128
|
-
* if (!doc) throw new Error('No active document');
|
|
129
|
-
*
|
|
130
|
-
* const body = doc.getBody();
|
|
131
|
-
* const paragraph = body.getChild(1).asParagraph();
|
|
132
|
-
* body.insertParagraph(0, 'Intro');
|
|
133
|
-
* console.log(body.getChildIndex(paragraph));
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
getChildIndex(element: IFDocElementHandle): number;
|
|
137
|
-
/**
|
|
138
|
-
* Insert plain text at a document body offset.
|
|
139
|
-
* @param {number} index The zero-based insertion offset.
|
|
140
|
-
* @param {string} text The plain text to insert.
|
|
141
|
-
* @returns {boolean} `true` if the edit was applied.
|
|
142
|
-
* @example
|
|
143
|
-
* ```ts
|
|
144
|
-
* const doc = univerAPI.getActiveDocument();
|
|
145
|
-
* if (!doc) throw new Error('No active document');
|
|
146
|
-
*
|
|
147
|
-
* const body = doc.getBody();
|
|
148
|
-
* body.insertText(0, 'Hello ');
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
insertText(index: number, text: string): boolean;
|
|
152
|
-
/**
|
|
153
|
-
* Insert a plain-text paragraph before the paragraph at the given paragraph index.
|
|
154
|
-
* @param {number} index The zero-based paragraph insertion index.
|
|
155
|
-
* @param {string} text The paragraph text. Defaults to an empty paragraph.
|
|
156
|
-
* @returns {FDocParagraph} The inserted paragraph wrapper.
|
|
157
|
-
* @example
|
|
158
|
-
* ```ts
|
|
159
|
-
* const doc = univerAPI.getActiveDocument();
|
|
160
|
-
* if (!doc) throw new Error('No active document');
|
|
161
|
-
*
|
|
162
|
-
* const body = doc.getBody();
|
|
163
|
-
* const paragraph = body.insertParagraph(0, 'Document title');
|
|
164
|
-
* paragraph.appendText(' suffix');
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
insertParagraph(index: number, text?: string): FDocParagraph;
|
|
168
|
-
/**
|
|
169
|
-
* Append a plain-text paragraph at the end of the body.
|
|
170
|
-
* @param {string} text The paragraph text. Defaults to an empty paragraph.
|
|
171
|
-
* @returns {FDocParagraph} The appended paragraph wrapper.
|
|
172
|
-
* @example
|
|
173
|
-
* ```ts
|
|
174
|
-
* const doc = univerAPI.getActiveDocument();
|
|
175
|
-
* if (!doc) throw new Error('No active document');
|
|
176
|
-
*
|
|
177
|
-
* const body = doc.getBody();
|
|
178
|
-
* const paragraph = body.appendParagraph('Summary');
|
|
179
|
-
* console.log(paragraph.getText());
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
appendParagraph(text?: string): FDocParagraph;
|
|
183
|
-
/**
|
|
184
|
-
* Delete a range from the body.
|
|
185
|
-
* @param {IFDocTextRange} range The text range to delete.
|
|
186
|
-
* @returns {boolean} `true` if the range was deleted.
|
|
187
|
-
* @example
|
|
188
|
-
* ```ts
|
|
189
|
-
* const doc = univerAPI.getActiveDocument();
|
|
190
|
-
* if (!doc) throw new Error('No active document');
|
|
191
|
-
*
|
|
192
|
-
* const body = doc.getBody();
|
|
193
|
-
* body.deleteRange({ startOffset: 0, endOffset: 5 });
|
|
194
|
-
* ```
|
|
195
|
-
*/
|
|
196
|
-
deleteRange(range: IFDocTextRange): boolean;
|
|
197
|
-
/**
|
|
198
|
-
* Replace a range with plain text or rich text body data.
|
|
199
|
-
* @param {IFDocTextRange} range The text range to replace.
|
|
200
|
-
* @param {string | IFDocRichTextLike | { body?: IDocumentBody }} value The replacement text or rich-text-like value.
|
|
201
|
-
* @returns {boolean} `true` if the replacement was applied.
|
|
202
|
-
* @example
|
|
203
|
-
* ```ts
|
|
204
|
-
* const doc = univerAPI.getActiveDocument();
|
|
205
|
-
* if (!doc) throw new Error('No active document');
|
|
206
|
-
*
|
|
207
|
-
* const body = doc.getBody();
|
|
208
|
-
* body.replaceRange({ startOffset: 0, endOffset: 5 }, 'Hello');
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
replaceRange(range: IFDocTextRange, value: string | IFDocRichTextLike | {
|
|
212
|
-
body?: IDocumentBody;
|
|
213
|
-
}): boolean;
|
|
214
|
-
/**
|
|
215
|
-
* Apply text style to a body range.
|
|
216
|
-
* @param {IFDocTextRange} range The range to style.
|
|
217
|
-
* @param {ITextStyle} style The Univer text style patch.
|
|
218
|
-
* @returns {boolean} `true` if the style was applied.
|
|
219
|
-
* @example
|
|
220
|
-
* ```ts
|
|
221
|
-
* const doc = univerAPI.getActiveDocument();
|
|
222
|
-
* if (!doc) throw new Error('No active document');
|
|
223
|
-
*
|
|
224
|
-
* const body = doc.getBody();
|
|
225
|
-
* body.setTextStyle({ startOffset: 0, endOffset: 5 }, { bl: 1 });
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
setTextStyle(range: IFDocTextRange, style: ITextStyle): boolean;
|
|
229
|
-
/**
|
|
230
|
-
* Apply paragraph style to a paragraph handle or text range.
|
|
231
|
-
* @param {FDocElement | FDocParagraph | IFDocTextRange} paragraph The paragraph handle or a range inside the paragraph.
|
|
232
|
-
* @param {IParagraphStyle} style The Univer paragraph style patch.
|
|
233
|
-
* @returns {boolean} `true` if the style was applied.
|
|
234
|
-
* @example
|
|
235
|
-
* ```ts
|
|
236
|
-
* const doc = univerAPI.getActiveDocument();
|
|
237
|
-
* if (!doc) throw new Error('No active document');
|
|
238
|
-
*
|
|
239
|
-
* const body = doc.getBody();
|
|
240
|
-
* const paragraph = body.getChild(0).asParagraph();
|
|
241
|
-
* body.setParagraphStyle(paragraph, { horizontalAlign: 2 });
|
|
242
|
-
* ```
|
|
243
|
-
*/
|
|
244
|
-
setParagraphStyle(paragraph: FDocElement | FDocParagraph | IFDocTextRange, style: IParagraphStyle): boolean;
|
|
245
|
-
/**
|
|
246
|
-
* Get the text content of a paragraph by paragraph id.
|
|
247
|
-
* @param {string} key The paragraph id.
|
|
248
|
-
* @returns {string} The paragraph text without the trailing paragraph break.
|
|
249
|
-
* @example
|
|
250
|
-
* ```ts
|
|
251
|
-
* const doc = univerAPI.getActiveDocument();
|
|
252
|
-
* if (!doc) throw new Error('No active document');
|
|
253
|
-
*
|
|
254
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
255
|
-
* console.log(doc.getBody().getParagraphText(paragraph.getKey()));
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
getParagraphText(key: string): string;
|
|
259
|
-
/**
|
|
260
|
-
* Replace the text content of a paragraph by paragraph id.
|
|
261
|
-
* @param {string} key The paragraph id.
|
|
262
|
-
* @param {string} text The replacement paragraph text.
|
|
263
|
-
* @returns {boolean} `true` if the paragraph text was replaced.
|
|
264
|
-
* @example
|
|
265
|
-
* ```ts
|
|
266
|
-
* const doc = univerAPI.getActiveDocument();
|
|
267
|
-
* if (!doc) throw new Error('No active document');
|
|
268
|
-
*
|
|
269
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
270
|
-
* doc.getBody().setParagraphText(paragraph.getKey(), 'Updated text');
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
setParagraphText(key: string, text: string): boolean;
|
|
274
|
-
/**
|
|
275
|
-
* Append text to a paragraph by paragraph id.
|
|
276
|
-
* @param {string} key The paragraph id.
|
|
277
|
-
* @param {string} text The text to append before the paragraph break.
|
|
278
|
-
* @returns {boolean} `true` if the text was appended.
|
|
279
|
-
* @example
|
|
280
|
-
* ```ts
|
|
281
|
-
* const doc = univerAPI.getActiveDocument();
|
|
282
|
-
* if (!doc) throw new Error('No active document');
|
|
283
|
-
*
|
|
284
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
285
|
-
* doc.getBody().appendParagraphText(paragraph.getKey(), ' suffix');
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
appendParagraphText(key: string, text: string): boolean;
|
|
289
|
-
/**
|
|
290
|
-
* Remove a paragraph by paragraph id.
|
|
291
|
-
* @param {string} key The paragraph id.
|
|
292
|
-
* @returns {boolean} `true` if the paragraph was removed.
|
|
293
|
-
* @example
|
|
294
|
-
* ```ts
|
|
295
|
-
* const doc = univerAPI.getActiveDocument();
|
|
296
|
-
* if (!doc) throw new Error('No active document');
|
|
297
|
-
*
|
|
298
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
299
|
-
* doc.getBody().removeParagraph(paragraph.getKey());
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
removeParagraph(key: string): boolean;
|
|
303
|
-
/**
|
|
304
|
-
* Get a paragraph text range by paragraph id.
|
|
305
|
-
* @param {string} key The paragraph id.
|
|
306
|
-
* @returns {IFDocTextRange} The paragraph range excluding the trailing paragraph break.
|
|
307
|
-
* @example
|
|
308
|
-
* ```ts
|
|
309
|
-
* const doc = univerAPI.getActiveDocument();
|
|
310
|
-
* if (!doc) throw new Error('No active document');
|
|
311
|
-
*
|
|
312
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
313
|
-
* const range = doc.getBody().getParagraphRange(paragraph.getKey());
|
|
314
|
-
* console.log(range.startOffset, range.endOffset);
|
|
315
|
-
* ```
|
|
316
|
-
*/
|
|
317
|
-
getParagraphRange(key: string): IFDocTextRange;
|
|
318
|
-
/**
|
|
319
|
-
* Check whether a paragraph has list metadata.
|
|
320
|
-
* @param {string} key The paragraph id.
|
|
321
|
-
* @returns {boolean} `true` if the paragraph is a list item.
|
|
322
|
-
* @example
|
|
323
|
-
* ```ts
|
|
324
|
-
* const doc = univerAPI.getActiveDocument();
|
|
325
|
-
* if (!doc) throw new Error('No active document');
|
|
326
|
-
*
|
|
327
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
328
|
-
* console.log(doc.getBody().isListParagraph(paragraph.getKey()));
|
|
329
|
-
* ```
|
|
330
|
-
*/
|
|
331
|
-
isListParagraph(key: string): boolean;
|
|
332
|
-
/**
|
|
333
|
-
* Check whether a paragraph is a task/checklist item.
|
|
334
|
-
* @param {string} key The paragraph id.
|
|
335
|
-
* @returns {boolean} `true` if the paragraph is an unchecked or checked task item.
|
|
336
|
-
* @example
|
|
337
|
-
* ```ts
|
|
338
|
-
* const doc = univerAPI.getActiveDocument();
|
|
339
|
-
* if (!doc) throw new Error('No active document');
|
|
340
|
-
*
|
|
341
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
342
|
-
* console.log(doc.getBody().isTaskParagraph(paragraph.getKey()));
|
|
343
|
-
* ```
|
|
344
|
-
*/
|
|
345
|
-
isTaskParagraph(key: string): boolean;
|
|
346
|
-
/**
|
|
347
|
-
* Set the checked state of a task/checklist paragraph.
|
|
348
|
-
* @param {string} key The paragraph id.
|
|
349
|
-
* @param {boolean} checked Whether the task should be checked.
|
|
350
|
-
* @returns {boolean} `true` if the task state was updated, or `false` if the paragraph is not a task item.
|
|
351
|
-
* @example
|
|
352
|
-
* ```ts
|
|
353
|
-
* const doc = univerAPI.getActiveDocument();
|
|
354
|
-
* if (!doc) throw new Error('No active document');
|
|
355
|
-
*
|
|
356
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
357
|
-
* doc.getBody().setTaskChecked(paragraph.getKey(), true);
|
|
358
|
-
* ```
|
|
359
|
-
*/
|
|
360
|
-
setTaskChecked(key: string, checked: boolean): boolean;
|
|
361
|
-
/**
|
|
362
|
-
* Resolve a paragraph id to its current paragraph metadata.
|
|
363
|
-
* @param {string} key The paragraph id.
|
|
364
|
-
* @returns {IFDocResolvedParagraph} The current paragraph metadata.
|
|
365
|
-
* @example
|
|
366
|
-
* ```ts
|
|
367
|
-
* const doc = univerAPI.getActiveDocument();
|
|
368
|
-
* if (!doc) throw new Error('No active document');
|
|
369
|
-
*
|
|
370
|
-
* const paragraph = doc.getBody().getChild(0).asParagraph();
|
|
371
|
-
* const resolved = doc.getBody().resolveParagraph(paragraph.getKey());
|
|
372
|
-
* console.log(resolved.paragraphIndex);
|
|
373
|
-
* ```
|
|
374
|
-
*/
|
|
375
|
-
resolveParagraph(key: string): IFDocResolvedParagraph;
|
|
376
|
-
/**
|
|
377
|
-
* Resolve an element key to its current child metadata.
|
|
378
|
-
* @param {FDocElementType} type The element type.
|
|
379
|
-
* @param {string} key The persisted element key.
|
|
380
|
-
* @returns {object} The current child metadata used by the facade.
|
|
381
|
-
* @example
|
|
382
|
-
* ```ts
|
|
383
|
-
* const doc = univerAPI.getActiveDocument();
|
|
384
|
-
* if (!doc) throw new Error('No active document');
|
|
385
|
-
*
|
|
386
|
-
* const element = doc.getBody().getChild(0);
|
|
387
|
-
* const resolved = doc.getBody().resolveElement(element.getType(), element.getKey());
|
|
388
|
-
* console.log(resolved.position);
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
resolveElement(type: FDocElementType, key: string): IFDocChildInfo;
|
|
392
|
-
/**
|
|
393
|
-
* Get a callout, quote, or code block range by block id.
|
|
394
|
-
* @param {string} key The persisted block range id.
|
|
395
|
-
* @returns {IDocumentBlockRange} The matching block range snapshot.
|
|
396
|
-
* @example
|
|
397
|
-
* ```ts
|
|
398
|
-
* const doc = univerAPI.getActiveDocument();
|
|
399
|
-
* if (!doc) throw new Error('No active document');
|
|
400
|
-
*
|
|
401
|
-
* const block = doc.getBody().getChild(0).asBlockRange();
|
|
402
|
-
* console.log(doc.getBody().getBlockRange(block.getKey()).blockType);
|
|
403
|
-
* ```
|
|
404
|
-
*/
|
|
405
|
-
getBlockRange(key: string): IDocumentBlockRange;
|
|
406
|
-
/**
|
|
407
|
-
* Get the text inside a callout, quote, or code block range.
|
|
408
|
-
* @param {string} key The persisted block range id.
|
|
409
|
-
* @returns {string} The block range text.
|
|
410
|
-
* @example
|
|
411
|
-
* ```ts
|
|
412
|
-
* const doc = univerAPI.getActiveDocument();
|
|
413
|
-
* if (!doc) throw new Error('No active document');
|
|
414
|
-
*
|
|
415
|
-
* const block = doc.getBody().getChild(0).asBlockRange();
|
|
416
|
-
* console.log(doc.getBody().getBlockRangeText(block.getKey()));
|
|
417
|
-
* ```
|
|
418
|
-
*/
|
|
419
|
-
getBlockRangeText(key: string): string;
|
|
420
|
-
/**
|
|
421
|
-
* Replace the text inside a callout, quote, or code block range.
|
|
422
|
-
* @param {string} key The persisted block range id.
|
|
423
|
-
* @param {string} text The replacement text.
|
|
424
|
-
* @returns {boolean} `true` if the text was replaced.
|
|
425
|
-
* @example
|
|
426
|
-
* ```ts
|
|
427
|
-
* const doc = univerAPI.getActiveDocument();
|
|
428
|
-
* if (!doc) throw new Error('No active document');
|
|
429
|
-
*
|
|
430
|
-
* const block = doc.getBody().getChild(0).asBlockRange();
|
|
431
|
-
* doc.getBody().setBlockRangeText(block.getKey(), 'Updated block');
|
|
432
|
-
* ```
|
|
433
|
-
*/
|
|
434
|
-
setBlockRangeText(key: string, text: string): boolean;
|
|
435
|
-
/**
|
|
436
|
-
* Remove a callout, quote, or code block range and its content.
|
|
437
|
-
* @param {string} key The persisted block range id.
|
|
438
|
-
* @returns {boolean} `true` if the block range content was removed.
|
|
439
|
-
* @example
|
|
440
|
-
* ```ts
|
|
441
|
-
* const doc = univerAPI.getActiveDocument();
|
|
442
|
-
* if (!doc) throw new Error('No active document');
|
|
443
|
-
*
|
|
444
|
-
* const block = doc.getBody().getChild(0).asBlockRange();
|
|
445
|
-
* doc.getBody().removeBlockRange(block.getKey());
|
|
446
|
-
* ```
|
|
447
|
-
*/
|
|
448
|
-
removeBlockRange(key: string): boolean;
|
|
449
|
-
/**
|
|
450
|
-
* Get a table marker by table id.
|
|
451
|
-
* @param {string} key The persisted table id.
|
|
452
|
-
* @returns {ICustomTable} The matching table marker.
|
|
453
|
-
* @example
|
|
454
|
-
* ```ts
|
|
455
|
-
* const doc = univerAPI.getActiveDocument();
|
|
456
|
-
* if (!doc) throw new Error('No active document');
|
|
457
|
-
*
|
|
458
|
-
* const table = doc.getBody().getChild(0).asTable();
|
|
459
|
-
* console.log(doc.getBody().getTable(table.getTableId()));
|
|
460
|
-
* ```
|
|
461
|
-
*/
|
|
462
|
-
getTable(key: string): ICustomTable;
|
|
463
|
-
/**
|
|
464
|
-
* Remove a table marker and its content range.
|
|
465
|
-
* @param {string} key The persisted table id.
|
|
466
|
-
* @returns {boolean} `true` if the table range was removed.
|
|
467
|
-
* @example
|
|
468
|
-
* ```ts
|
|
469
|
-
* const doc = univerAPI.getActiveDocument();
|
|
470
|
-
* if (!doc) throw new Error('No active document');
|
|
471
|
-
*
|
|
472
|
-
* const table = doc.getBody().getChild(0).asTable();
|
|
473
|
-
* doc.getBody().removeTable(table.getTableId());
|
|
474
|
-
* ```
|
|
475
|
-
*/
|
|
476
|
-
removeTable(key: string): boolean;
|
|
477
|
-
/**
|
|
478
|
-
* Get a custom block marker by block id.
|
|
479
|
-
* @param {string} key The persisted custom block id.
|
|
480
|
-
* @returns {ICustomBlock} The matching custom block marker.
|
|
481
|
-
* @example
|
|
482
|
-
* ```ts
|
|
483
|
-
* const doc = univerAPI.getActiveDocument();
|
|
484
|
-
* if (!doc) throw new Error('No active document');
|
|
485
|
-
*
|
|
486
|
-
* const customBlock = doc.getBody().getChild(0).asCustomBlock();
|
|
487
|
-
* console.log(doc.getBody().getCustomBlock(customBlock.getBlockId()));
|
|
488
|
-
* ```
|
|
489
|
-
*/
|
|
490
|
-
getCustomBlock(key: string): ICustomBlock;
|
|
491
|
-
/**
|
|
492
|
-
* Remove a custom block marker and its placeholder character.
|
|
493
|
-
* @param {string} key The persisted custom block id.
|
|
494
|
-
* @returns {boolean} `true` if the custom block placeholder was removed.
|
|
495
|
-
* @example
|
|
496
|
-
* ```ts
|
|
497
|
-
* const doc = univerAPI.getActiveDocument();
|
|
498
|
-
* if (!doc) throw new Error('No active document');
|
|
499
|
-
*
|
|
500
|
-
* const customBlock = doc.getBody().getChild(0).asCustomBlock();
|
|
501
|
-
* doc.getBody().removeCustomBlock(customBlock.getBlockId());
|
|
502
|
-
* ```
|
|
503
|
-
*/
|
|
504
|
-
removeCustomBlock(key: string): boolean;
|
|
505
|
-
/**
|
|
506
|
-
* Create a sibling element wrapper relative to the current element key.
|
|
507
|
-
* @param {FDocElementType} type The current element type.
|
|
508
|
-
* @param {string} key The current element key.
|
|
509
|
-
* @param {-1 | 1} direction `-1` for previous sibling, `1` for next sibling.
|
|
510
|
-
* @returns {FDocElement | null} The sibling wrapper, or `null` if none exists.
|
|
511
|
-
* @example
|
|
512
|
-
* ```ts
|
|
513
|
-
* const doc = univerAPI.getActiveDocument();
|
|
514
|
-
* if (!doc) throw new Error('No active document');
|
|
515
|
-
*
|
|
516
|
-
* const element = doc.getBody().getChild(0);
|
|
517
|
-
* const next = doc.getBody().createSibling(element.getType(), element.getKey(), 1);
|
|
518
|
-
* console.log(next?.getType());
|
|
519
|
-
* ```
|
|
520
|
-
*/
|
|
521
|
-
createSibling(type: FDocElementType, key: string, direction: -1 | 1): FDocElement | null;
|
|
522
|
-
private _getChildren;
|
|
523
|
-
private _createElement;
|
|
524
|
-
private _getBody;
|
|
525
|
-
private _getParagraphInsertOffset;
|
|
526
|
-
private _normalizeInsertedParagraphIndex;
|
|
527
|
-
private _getParagraphId;
|
|
528
|
-
private _preserveExplicitParagraphIds;
|
|
529
|
-
private _findParagraphByRange;
|
|
530
|
-
private _replaceBodyRange;
|
|
531
|
-
private _retainBodyRange;
|
|
532
|
-
private _ensureTextRuns;
|
|
533
|
-
private _executeTextX;
|
|
534
|
-
}
|
|
535
|
-
export {};
|
|
@@ -1,94 +0,0 @@
|
|
|
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 { FDocBody } from './f-doc-body';
|
|
17
|
-
/**
|
|
18
|
-
* A facade wrapper for a document custom block, such as an embedded drawing or widget.
|
|
19
|
-
*
|
|
20
|
-
* Custom block identity is backed by the persisted `ICustomBlock.blockId`, so the
|
|
21
|
-
* wrapper can be re-resolved after text is inserted before the custom block.
|
|
22
|
-
*
|
|
23
|
-
* @hideconstructor
|
|
24
|
-
*/
|
|
25
|
-
export declare class FDocCustomBlock {
|
|
26
|
-
protected readonly _body: FDocBody;
|
|
27
|
-
protected readonly _key: string;
|
|
28
|
-
constructor(_body: FDocBody, _key: string);
|
|
29
|
-
/**
|
|
30
|
-
* Get the document element type.
|
|
31
|
-
* @returns {'customBlock'} The literal custom block element type.
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const doc = univerAPI.getActiveDocument();
|
|
35
|
-
* if (!doc) throw new Error('No active document');
|
|
36
|
-
*
|
|
37
|
-
* const customBlock = doc.getBody().getChild(0).asCustomBlock();
|
|
38
|
-
* console.log(customBlock.getType());
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
getType(): 'customBlock';
|
|
42
|
-
/**
|
|
43
|
-
* Get the custom block key.
|
|
44
|
-
* @returns {string} The persisted `blockId` for this custom block.
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* const doc = univerAPI.getActiveDocument();
|
|
48
|
-
* if (!doc) throw new Error('No active document');
|
|
49
|
-
*
|
|
50
|
-
* const customBlock = doc.getBody().getChild(0).asCustomBlock();
|
|
51
|
-
* console.log(customBlock.getKey());
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
getKey(): string;
|
|
55
|
-
/**
|
|
56
|
-
* Get the parent body facade that owns this custom block.
|
|
57
|
-
* @returns {FDocBody} The document body facade.
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* const doc = univerAPI.getActiveDocument();
|
|
61
|
-
* if (!doc) throw new Error('No active document');
|
|
62
|
-
*
|
|
63
|
-
* const customBlock = doc.getBody().getChild(0).asCustomBlock();
|
|
64
|
-
* console.log(customBlock.getParent().getChildIndex(customBlock));
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
getParent(): FDocBody;
|
|
68
|
-
/**
|
|
69
|
-
* Remove this custom block from the parent body.
|
|
70
|
-
* @returns {boolean} `true` if the custom block placeholder was removed.
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* const doc = univerAPI.getActiveDocument();
|
|
74
|
-
* if (!doc) throw new Error('No active document');
|
|
75
|
-
*
|
|
76
|
-
* const customBlock = doc.getBody().getChild(0).asCustomBlock();
|
|
77
|
-
* customBlock.removeFromParent();
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
removeFromParent(): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Get the persisted custom block id.
|
|
83
|
-
* @returns {string} The `ICustomBlock.blockId` value.
|
|
84
|
-
* @example
|
|
85
|
-
* ```ts
|
|
86
|
-
* const doc = univerAPI.getActiveDocument();
|
|
87
|
-
* if (!doc) throw new Error('No active document');
|
|
88
|
-
*
|
|
89
|
-
* const customBlock = doc.getBody().getChild(0).asCustomBlock();
|
|
90
|
-
* console.log(customBlock.getBlockId());
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
getBlockId(): string;
|
|
94
|
-
}
|