@univerjs/docs 0.25.0 → 1.0.0-alpha.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.
@@ -0,0 +1,94 @@
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
+ }
@@ -0,0 +1,177 @@
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
+ import type { FDocElementType } from './doc-element-registry';
18
+ import { FDocBlockRange } from './f-doc-block-range';
19
+ import { FDocCustomBlock } from './f-doc-custom-block';
20
+ import { FDocParagraph } from './f-doc-paragraph';
21
+ import { FDocTable } from './f-doc-table';
22
+ /**
23
+ * A generic top-level document body element.
24
+ *
25
+ * Use this wrapper when you need to inspect an element type first, navigate to
26
+ * neighboring elements, or cast the element to a more specific facade wrapper.
27
+ *
28
+ * Paragraph keys are persisted `paragraphId` values. Tables, block ranges, and
29
+ * custom blocks use their persisted ids.
30
+ *
31
+ * @hideconstructor
32
+ */
33
+ export declare class FDocElement {
34
+ protected readonly _body: FDocBody;
35
+ protected readonly _type: FDocElementType;
36
+ protected readonly _key: string;
37
+ constructor(_body: FDocBody, _type: FDocElementType, _key: string);
38
+ /**
39
+ * Get the document element type.
40
+ * @returns {FDocElementType} The element type, such as `paragraph`, `table`, `blockRange`, or `customBlock`.
41
+ * @example
42
+ * ```ts
43
+ * const doc = univerAPI.getActiveDocument();
44
+ * if (!doc) throw new Error('No active document');
45
+ *
46
+ * const element = doc.getBody().getChild(0);
47
+ * console.log(element.getType());
48
+ * ```
49
+ */
50
+ getType(): FDocElementType;
51
+ /**
52
+ * Get the facade key used to resolve this element.
53
+ * @returns {string} The paragraph `paragraphId` or persisted table/block/custom block id.
54
+ * @example
55
+ * ```ts
56
+ * const doc = univerAPI.getActiveDocument();
57
+ * if (!doc) throw new Error('No active document');
58
+ *
59
+ * const body = doc.getBody();
60
+ * const element = body.getChild(0);
61
+ * console.log(element.getKey());
62
+ * ```
63
+ */
64
+ getKey(): string;
65
+ /**
66
+ * Get the parent body facade that owns this element.
67
+ * @returns {FDocBody} The document body facade.
68
+ * @example
69
+ * ```ts
70
+ * const doc = univerAPI.getActiveDocument();
71
+ * if (!doc) throw new Error('No active document');
72
+ *
73
+ * const element = doc.getBody().getChild(0);
74
+ * console.log(element.getParent().getNumChildren());
75
+ * ```
76
+ */
77
+ getParent(): FDocBody;
78
+ /**
79
+ * Get the next sibling element in the current body order.
80
+ * @returns {FDocElement | null} The next sibling wrapper, or `null` when this is the last child.
81
+ * @example
82
+ * ```ts
83
+ * const doc = univerAPI.getActiveDocument();
84
+ * if (!doc) throw new Error('No active document');
85
+ *
86
+ * const first = doc.getBody().getChild(0);
87
+ * const next = first.getNextSibling();
88
+ * console.log(next?.getType());
89
+ * ```
90
+ */
91
+ getNextSibling(): FDocElement | null;
92
+ /**
93
+ * Get the previous sibling element in the current body order.
94
+ * @returns {FDocElement | null} The previous sibling wrapper, or `null` when this is the first child.
95
+ * @example
96
+ * ```ts
97
+ * const doc = univerAPI.getActiveDocument();
98
+ * if (!doc) throw new Error('No active document');
99
+ *
100
+ * const second = doc.getBody().getChild(1);
101
+ * const previous = second.getPreviousSibling();
102
+ * console.log(previous?.getType());
103
+ * ```
104
+ */
105
+ getPreviousSibling(): FDocElement | null;
106
+ /**
107
+ * Remove this element from its parent body.
108
+ * @returns {boolean} `true` if the element content was removed.
109
+ * @example
110
+ * ```ts
111
+ * const doc = univerAPI.getActiveDocument();
112
+ * if (!doc) throw new Error('No active document');
113
+ *
114
+ * const body = doc.getBody();
115
+ * const element = body.getChild(0);
116
+ * element.removeFromParent();
117
+ * ```
118
+ */
119
+ removeFromParent(): boolean;
120
+ /**
121
+ * Cast this generic element to a paragraph facade.
122
+ * @returns {FDocParagraph} The paragraph facade wrapper.
123
+ * @throws {TypeError} If the element is not a paragraph.
124
+ * @example
125
+ * ```ts
126
+ * const doc = univerAPI.getActiveDocument();
127
+ * if (!doc) throw new Error('No active document');
128
+ *
129
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
130
+ * console.log(paragraph.getText());
131
+ * ```
132
+ */
133
+ asParagraph(): FDocParagraph;
134
+ /**
135
+ * Cast this generic element to a table facade.
136
+ * @returns {FDocTable} The table facade wrapper.
137
+ * @throws {TypeError} If the element is not a table.
138
+ * @example
139
+ * ```ts
140
+ * const doc = univerAPI.getActiveDocument();
141
+ * if (!doc) throw new Error('No active document');
142
+ *
143
+ * const table = doc.getBody().getChild(0).asTable();
144
+ * console.log(table.getTableId());
145
+ * ```
146
+ */
147
+ asTable(): FDocTable;
148
+ /**
149
+ * Cast this generic element to a callout, quote, or code block range facade.
150
+ * @returns {FDocBlockRange} The block range facade wrapper.
151
+ * @throws {TypeError} If the element is not a block range.
152
+ * @example
153
+ * ```ts
154
+ * const doc = univerAPI.getActiveDocument();
155
+ * if (!doc) throw new Error('No active document');
156
+ *
157
+ * const blockRange = doc.getBody().getChild(0).asBlockRange();
158
+ * console.log(blockRange.getBlockType());
159
+ * ```
160
+ */
161
+ asBlockRange(): FDocBlockRange;
162
+ /**
163
+ * Cast this generic element to a custom block facade.
164
+ * @returns {FDocCustomBlock} The custom block facade wrapper.
165
+ * @throws {TypeError} If the element is not a custom block.
166
+ * @example
167
+ * ```ts
168
+ * const doc = univerAPI.getActiveDocument();
169
+ * if (!doc) throw new Error('No active document');
170
+ *
171
+ * const customBlock = doc.getBody().getChild(0).asCustomBlock();
172
+ * console.log(customBlock.getBlockId());
173
+ * ```
174
+ */
175
+ asCustomBlock(): FDocCustomBlock;
176
+ private _assertType;
177
+ }
@@ -0,0 +1,194 @@
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, IFDocTextRange } from './f-doc-body';
17
+ /**
18
+ * A paragraph facade wrapper.
19
+ *
20
+ * Paragraph identity is backed by the persisted `paragraphId`. The id is
21
+ * re-resolved before each method call, so insertions before this paragraph do
22
+ * not break the wrapper.
23
+ *
24
+ * @hideconstructor
25
+ */
26
+ export declare class FDocParagraph {
27
+ protected readonly _body: FDocBody;
28
+ protected readonly _key: string;
29
+ constructor(_body: FDocBody, _key: string);
30
+ /**
31
+ * Get the document element type.
32
+ * @returns {'paragraph'} The literal paragraph element type.
33
+ * @example
34
+ * ```ts
35
+ * const doc = univerAPI.getActiveDocument();
36
+ * if (!doc) throw new Error('No active document');
37
+ *
38
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
39
+ * console.log(paragraph.getType());
40
+ * ```
41
+ */
42
+ getType(): 'paragraph';
43
+ /**
44
+ * Get the persisted paragraph id.
45
+ * @returns {string} The paragraph id.
46
+ * @example
47
+ * ```ts
48
+ * const doc = univerAPI.getActiveDocument();
49
+ * if (!doc) throw new Error('No active document');
50
+ *
51
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
52
+ * console.log(paragraph.getKey());
53
+ * ```
54
+ */
55
+ getKey(): string;
56
+ /**
57
+ * Get the persisted paragraph id.
58
+ * @returns {string} The paragraph id.
59
+ * @example
60
+ * ```ts
61
+ * const doc = univerAPI.getActiveDocument();
62
+ * if (!doc) throw new Error('No active document');
63
+ *
64
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
65
+ * console.log(paragraph.getId());
66
+ * ```
67
+ */
68
+ getId(): string;
69
+ /**
70
+ * Get the parent body facade that owns this paragraph.
71
+ * @returns {FDocBody} The document body facade.
72
+ * @example
73
+ * ```ts
74
+ * const doc = univerAPI.getActiveDocument();
75
+ * if (!doc) throw new Error('No active document');
76
+ *
77
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
78
+ * console.log(paragraph.getParent().getChildIndex(paragraph));
79
+ * ```
80
+ */
81
+ getParent(): FDocBody;
82
+ /**
83
+ * Remove this paragraph from its parent body.
84
+ * @returns {boolean} `true` if the paragraph was removed.
85
+ * @example
86
+ * ```ts
87
+ * const doc = univerAPI.getActiveDocument();
88
+ * if (!doc) throw new Error('No active document');
89
+ *
90
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
91
+ * paragraph.removeFromParent();
92
+ * ```
93
+ */
94
+ removeFromParent(): boolean;
95
+ /**
96
+ * Get this paragraph's plain text.
97
+ * @returns {string} The paragraph text without the trailing paragraph break.
98
+ * @example
99
+ * ```ts
100
+ * const doc = univerAPI.getActiveDocument();
101
+ * if (!doc) throw new Error('No active document');
102
+ *
103
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
104
+ * console.log(paragraph.getText());
105
+ * ```
106
+ */
107
+ getText(): string;
108
+ /**
109
+ * Replace this paragraph's plain text.
110
+ * @param {string} text The replacement text. Do not include the paragraph break.
111
+ * @returns {boolean} `true` if the paragraph text was replaced.
112
+ * @example
113
+ * ```ts
114
+ * const doc = univerAPI.getActiveDocument();
115
+ * if (!doc) throw new Error('No active document');
116
+ *
117
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
118
+ * paragraph.setText('Updated title');
119
+ * ```
120
+ */
121
+ setText(text: string): boolean;
122
+ /**
123
+ * Append plain text before this paragraph's trailing paragraph break.
124
+ * @param {string} text The plain text to append.
125
+ * @returns {boolean} `true` if the text was appended.
126
+ * @example
127
+ * ```ts
128
+ * const doc = univerAPI.getActiveDocument();
129
+ * if (!doc) throw new Error('No active document');
130
+ *
131
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
132
+ * paragraph.appendText(' suffix');
133
+ * ```
134
+ */
135
+ appendText(text: string): boolean;
136
+ /**
137
+ * Get the current text range occupied by this paragraph.
138
+ * @returns {IFDocTextRange} The paragraph text range, excluding the trailing paragraph break.
139
+ * @example
140
+ * ```ts
141
+ * const doc = univerAPI.getActiveDocument();
142
+ * if (!doc) throw new Error('No active document');
143
+ *
144
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
145
+ * const range = paragraph.getRange();
146
+ * doc.getBody().setTextStyle(range, { bl: 1 });
147
+ * ```
148
+ */
149
+ getRange(): IFDocTextRange;
150
+ /**
151
+ * Check whether this paragraph is a bullet, ordered, or checklist item.
152
+ * @returns {boolean} `true` if the paragraph has list metadata.
153
+ * @example
154
+ * ```ts
155
+ * const doc = univerAPI.getActiveDocument();
156
+ * if (!doc) throw new Error('No active document');
157
+ *
158
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
159
+ * console.log(paragraph.isListItem());
160
+ * ```
161
+ */
162
+ isListItem(): boolean;
163
+ /**
164
+ * Check whether this paragraph is a task/checklist item.
165
+ * @returns {boolean} `true` if this paragraph is an unchecked or checked task item.
166
+ * @example
167
+ * ```ts
168
+ * const doc = univerAPI.getActiveDocument();
169
+ * if (!doc) throw new Error('No active document');
170
+ *
171
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
172
+ * if (paragraph.isTask()) {
173
+ * paragraph.setTaskChecked(true);
174
+ * }
175
+ * ```
176
+ */
177
+ isTask(): boolean;
178
+ /**
179
+ * Set the checked state of this task/checklist paragraph.
180
+ * @param {boolean} checked Whether the task item should be checked.
181
+ * @returns {boolean} `true` if the task state was updated, or `false` if this paragraph is not a task item.
182
+ * @example
183
+ * ```ts
184
+ * const doc = univerAPI.getActiveDocument();
185
+ * if (!doc) throw new Error('No active document');
186
+ *
187
+ * const paragraph = doc.getBody().getChild(0).asParagraph();
188
+ * if (paragraph.isTask()) {
189
+ * paragraph.setTaskChecked(false);
190
+ * }
191
+ * ```
192
+ */
193
+ setTaskChecked(checked: boolean): boolean;
194
+ }
@@ -0,0 +1,94 @@
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 table marker.
19
+ *
20
+ * Table identity is backed by the persisted `ICustomTable.tableId`, so the
21
+ * wrapper can be re-resolved after text is inserted before the table.
22
+ *
23
+ * @hideconstructor
24
+ */
25
+ export declare class FDocTable {
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 {'table'} The literal table element type.
32
+ * @example
33
+ * ```ts
34
+ * const doc = univerAPI.getActiveDocument();
35
+ * if (!doc) throw new Error('No active document');
36
+ *
37
+ * const table = doc.getBody().getChild(0).asTable();
38
+ * console.log(table.getType());
39
+ * ```
40
+ */
41
+ getType(): 'table';
42
+ /**
43
+ * Get the table key.
44
+ * @returns {string} The persisted `tableId` for this table.
45
+ * @example
46
+ * ```ts
47
+ * const doc = univerAPI.getActiveDocument();
48
+ * if (!doc) throw new Error('No active document');
49
+ *
50
+ * const table = doc.getBody().getChild(0).asTable();
51
+ * console.log(table.getKey());
52
+ * ```
53
+ */
54
+ getKey(): string;
55
+ /**
56
+ * Get the parent body facade that owns this table.
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 table = doc.getBody().getChild(0).asTable();
64
+ * console.log(table.getParent().getChildIndex(table));
65
+ * ```
66
+ */
67
+ getParent(): FDocBody;
68
+ /**
69
+ * Remove this table from the parent body.
70
+ * @returns {boolean} `true` if the table range was removed.
71
+ * @example
72
+ * ```ts
73
+ * const doc = univerAPI.getActiveDocument();
74
+ * if (!doc) throw new Error('No active document');
75
+ *
76
+ * const table = doc.getBody().getChild(0).asTable();
77
+ * table.removeFromParent();
78
+ * ```
79
+ */
80
+ removeFromParent(): boolean;
81
+ /**
82
+ * Get the persisted table id.
83
+ * @returns {string} The `ICustomTable.tableId` value.
84
+ * @example
85
+ * ```ts
86
+ * const doc = univerAPI.getActiveDocument();
87
+ * if (!doc) throw new Error('No active document');
88
+ *
89
+ * const table = doc.getBody().getChild(0).asTable();
90
+ * console.log(table.getTableId());
91
+ * ```
92
+ */
93
+ getTableId(): string;
94
+ }