@univerjs/docs 1.0.0-alpha.1 → 1.0.0-alpha.2

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DeleteDirection, Disposable, DisposableCollection, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSONX, LocaleService, Optional, Plugin, RedoCommandId, RxDisposable, TextX, TextXActionType, UndoCommandId, UniverInstanceType, composeInterceptors, createIdentifier, createInterceptorKey, getRichTextEditPath, isInternalEditorID, merge, remove, toDisposable } from "@univerjs/core";
1
+ import { BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DeleteDirection, Disposable, DisposableCollection, DocumentFlavor, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSONX, LocaleService, Optional, Plugin, RedoCommandId, RxDisposable, TextX, TextXActionType, UndoCommandId, UniverInstanceType, composeInterceptors, createIdentifier, createInterceptorKey, createParagraphId, generateRandomId, getRichTextEditPath, isInternalEditorID, merge, remove, toDisposable } from "@univerjs/core";
2
2
  import { DocumentSkeleton, DocumentViewModel, IRenderManagerService, NORMAL_TEXT_SELECTION_PLUGIN_STYLE } from "@univerjs/engine-render";
3
3
  import { BehaviorSubject, Subject, takeUntil } from "rxjs";
4
4
 
@@ -386,14 +386,14 @@ const InsertTextCommand = {
386
386
  id: "doc.command.insert-text",
387
387
  type: CommandType.COMMAND,
388
388
  handler: (accessor, params) => {
389
- var _activeRange$segmentI;
389
+ var _docDataModel$getSelf, _activeRange$segmentI;
390
390
  const commandService = accessor.get(ICommandService);
391
391
  const { range, segmentId, body, unitId, cursorOffset } = params;
392
392
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
393
393
  const docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
394
394
  if (docDataModel == null) return false;
395
395
  const activeRange = docSelectionManagerService.getActiveTextRange();
396
- const originBody = docDataModel.getSelfOrHeaderFooterModel((_activeRange$segmentI = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) !== null && _activeRange$segmentI !== void 0 ? _activeRange$segmentI : "").getBody();
396
+ const originBody = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel((_activeRange$segmentI = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) !== null && _activeRange$segmentI !== void 0 ? _activeRange$segmentI : "")) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
397
397
  if (originBody == null) return false;
398
398
  const { startOffset, collapsed } = range;
399
399
  const cursorMove = cursorOffset !== null && cursorOffset !== void 0 ? cursorOffset : body.dataStream.length;
@@ -446,12 +446,12 @@ const DeleteTextCommand = {
446
446
  id: "doc.command.delete-text",
447
447
  type: CommandType.COMMAND,
448
448
  handler: (accessor, params) => {
449
- var _body$customRanges;
449
+ var _docDataModel$getSelf2, _body$customRanges;
450
450
  const commandService = accessor.get(ICommandService);
451
451
  const univerInstanceService = accessor.get(IUniverInstanceService);
452
452
  const { range, segmentId, unitId, direction, len = 1 } = params;
453
453
  const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
454
- const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
454
+ const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
455
455
  if (docDataModel == null || body == null) return false;
456
456
  const { startOffset } = range;
457
457
  let start = direction === DeleteDirection.LEFT ? startOffset - len : startOffset;
@@ -499,7 +499,7 @@ const UpdateTextCommand = {
499
499
  handler: (accessor, params) => {
500
500
  const { range, segmentId, updateBody, coverType, unitId, textRanges } = params;
501
501
  const commandService = accessor.get(ICommandService);
502
- const docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
502
+ const docDataModel = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
503
503
  if (docDataModel == null) return false;
504
504
  const doMutation = {
505
505
  id: RichTextEditingMutation.id,
@@ -529,10 +529,141 @@ const UpdateTextCommand = {
529
529
  }
530
530
  };
531
531
 
532
+ //#endregion
533
+ //#region src/commands/commands/create-header-footer.command.ts
534
+ let HeaderFooterType = /* @__PURE__ */ function(HeaderFooterType) {
535
+ HeaderFooterType[HeaderFooterType["FIRST_PAGE_HEADER"] = 0] = "FIRST_PAGE_HEADER";
536
+ HeaderFooterType[HeaderFooterType["FIRST_PAGE_FOOTER"] = 1] = "FIRST_PAGE_FOOTER";
537
+ HeaderFooterType[HeaderFooterType["DEFAULT_HEADER"] = 2] = "DEFAULT_HEADER";
538
+ HeaderFooterType[HeaderFooterType["DEFAULT_FOOTER"] = 3] = "DEFAULT_FOOTER";
539
+ HeaderFooterType[HeaderFooterType["EVEN_PAGE_HEADER"] = 4] = "EVEN_PAGE_HEADER";
540
+ HeaderFooterType[HeaderFooterType["EVEN_PAGE_FOOTER"] = 5] = "EVEN_PAGE_FOOTER";
541
+ return HeaderFooterType;
542
+ }({});
543
+ function getEmptyHeaderFooterBody() {
544
+ return {
545
+ dataStream: "\r\n",
546
+ textRuns: [{
547
+ st: 0,
548
+ ed: 0,
549
+ ts: { fs: 9 }
550
+ }],
551
+ customBlocks: [],
552
+ paragraphs: [{
553
+ startIndex: 0,
554
+ paragraphId: createParagraphId(/* @__PURE__ */ new Set()),
555
+ paragraphStyle: {
556
+ spaceAbove: { v: 0 },
557
+ lineSpacing: 1.5,
558
+ spaceBelow: { v: 0 }
559
+ }
560
+ }],
561
+ sectionBreaks: [{ startIndex: 1 }]
562
+ };
563
+ }
564
+ function createHeaderFooterAction(segmentId, createType, documentStyle, actions, createMode = "single") {
565
+ const jsonX = JSONX.getInstance();
566
+ const ID_LEN = 6;
567
+ const firstSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : generateRandomId(ID_LEN);
568
+ const isHeader = createType === 2 || createType === 0 || createType === 4;
569
+ const insertAction = jsonX.insertOp([isHeader ? "headers" : "footers", firstSegmentId], {
570
+ [isHeader ? "headerId" : "footerId"]: firstSegmentId,
571
+ body: getEmptyHeaderFooterBody()
572
+ });
573
+ actions.push(insertAction);
574
+ let key = "defaultHeaderId";
575
+ let pairKey = "defaultFooterId";
576
+ switch (createType) {
577
+ case 2:
578
+ key = "defaultHeaderId";
579
+ pairKey = "defaultFooterId";
580
+ break;
581
+ case 3:
582
+ key = "defaultFooterId";
583
+ pairKey = "defaultHeaderId";
584
+ break;
585
+ case 0:
586
+ key = "firstPageHeaderId";
587
+ pairKey = "firstPageFooterId";
588
+ break;
589
+ case 1:
590
+ key = "firstPageFooterId";
591
+ pairKey = "firstPageHeaderId";
592
+ break;
593
+ case 4:
594
+ key = "evenPageHeaderId";
595
+ pairKey = "evenPageFooterId";
596
+ break;
597
+ case 5:
598
+ key = "evenPageFooterId";
599
+ pairKey = "evenPageHeaderId";
600
+ break;
601
+ default: throw new Error(`Unknown header footer type: ${createType}`);
602
+ }
603
+ const linkedSegmentIds = [[key, firstSegmentId]];
604
+ if (createMode === "pair" && pairKey != null) {
605
+ const secondSegmentId = generateRandomId(ID_LEN);
606
+ const insertPairAction = jsonX.insertOp([isHeader ? "footers" : "headers", secondSegmentId], {
607
+ [isHeader ? "footerId" : "headerId"]: secondSegmentId,
608
+ body: getEmptyHeaderFooterBody()
609
+ });
610
+ actions.push(insertPairAction);
611
+ linkedSegmentIds.push([pairKey, secondSegmentId]);
612
+ }
613
+ for (const [k, id] of linkedSegmentIds) if (documentStyle[k] != null) {
614
+ const replaceAction = jsonX.replaceOp(["documentStyle", k], documentStyle[k], id);
615
+ actions.push(replaceAction);
616
+ } else {
617
+ const insertAction = jsonX.insertOp(["documentStyle", k], id);
618
+ actions.push(insertAction);
619
+ }
620
+ return actions;
621
+ }
622
+ const CreateHeaderFooterCommand = {
623
+ id: "doc.command.create-header-footer",
624
+ type: CommandType.COMMAND,
625
+ handler: (accessor, params) => {
626
+ const commandService = accessor.get(ICommandService);
627
+ const univerInstanceService = accessor.get(IUniverInstanceService);
628
+ const { unitId, segmentId, createType, headerFooterProps, createMode = "single" } = params;
629
+ const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
630
+ if (docDataModel == null) return false;
631
+ const { documentStyle } = docDataModel.getSnapshot();
632
+ if (documentStyle.documentFlavor === DocumentFlavor.MODERN) return false;
633
+ const rawActions = [];
634
+ const jsonX = JSONX.getInstance();
635
+ if (createType != null) createHeaderFooterAction(segmentId, createType, documentStyle, rawActions, createMode);
636
+ if (headerFooterProps != null) Object.keys(headerFooterProps).forEach((key) => {
637
+ const value = headerFooterProps[key];
638
+ const oldValue = documentStyle[key];
639
+ if (value === oldValue) return;
640
+ const action = oldValue === void 0 ? jsonX.insertOp(["documentStyle", key], value) : jsonX.replaceOp(["documentStyle", key], oldValue, value);
641
+ rawActions.push(action);
642
+ });
643
+ if (rawActions.length === 0) return false;
644
+ const doMutation = {
645
+ id: RichTextEditingMutation.id,
646
+ params: {
647
+ unitId,
648
+ actions: rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null),
649
+ textRanges: [{
650
+ startOffset: 0,
651
+ endOffset: 0,
652
+ collapsed: true
653
+ }],
654
+ debounce: true
655
+ }
656
+ };
657
+ if ((headerFooterProps === null || headerFooterProps === void 0 ? void 0 : headerFooterProps.marginFooter) != null || (headerFooterProps === null || headerFooterProps === void 0 ? void 0 : headerFooterProps.marginHeader) != null) doMutation.params.noNeedSetTextRange = true;
658
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
659
+ return Boolean(result);
660
+ }
661
+ };
662
+
532
663
  //#endregion
533
664
  //#region package.json
534
665
  var name = "@univerjs/docs";
535
- var version = "1.0.0-alpha.1";
666
+ var version = "1.0.0-alpha.2";
536
667
 
537
668
  //#endregion
538
669
  //#region src/commands/mutations/docs-rename.mutation.ts
@@ -724,7 +855,7 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
724
855
  _initialize() {
725
856
  this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
726
857
  if (command.id === UndoCommandId || command.id === RedoCommandId) {
727
- const univerDoc = this._univerInstanceService.getCurrentUniverDocInstance();
858
+ const univerDoc = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
728
859
  if (univerDoc == null) return;
729
860
  const unitId = univerDoc.getUnitId();
730
861
  this._pushHistory(unitId);
@@ -854,6 +985,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
854
985
  InsertTextCommand,
855
986
  DeleteTextCommand,
856
987
  UpdateTextCommand,
988
+ CreateHeaderFooterCommand,
857
989
  RichTextEditingMutation,
858
990
  DocsRenameMutation,
859
991
  SetTextSelectionsOperation
@@ -983,7 +1115,7 @@ function addCustomRangeFactory(accessor, param, body) {
983
1115
  return doMutation;
984
1116
  }
985
1117
  function addCustomRangeBySelectionFactory(accessor, param) {
986
- var _selections$;
1118
+ var _selections$, _documentDataModel$ge;
987
1119
  const { rangeId, rangeType, wholeEntity, properties, unitId, selections: propSelection } = param;
988
1120
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
989
1121
  const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -995,7 +1127,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
995
1127
  if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return false;
996
1128
  const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
997
1129
  if (!documentDataModel) return false;
998
- const body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1130
+ const body = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
999
1131
  if (!body) return false;
1000
1132
  const textX = BuildTextUtils.customRange.add({
1001
1133
  ranges: selections,
@@ -1092,4 +1224,17 @@ function replaceSelectionFactory(accessor, params) {
1092
1224
  }
1093
1225
 
1094
1226
  //#endregion
1095
- export { DOC_INTERCEPTOR_POINT, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, IDocStateChangeInterceptorService, InsertTextCommand, RichTextEditingMutation, SetTextSelectionsOperation, UniverDocsPlugin, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory, replaceSelectionFactory };
1227
+ //#region src/utils/util.ts
1228
+ function consumeContentInsertRange(accessor, unitId) {
1229
+ try {
1230
+ return accessor.get(DocContentInsertService).consumeInsertRange(unitId);
1231
+ } catch {
1232
+ return null;
1233
+ }
1234
+ }
1235
+ function isHeaderFooterSelection(range) {
1236
+ return Boolean(range === null || range === void 0 ? void 0 : range.segmentId);
1237
+ }
1238
+
1239
+ //#endregion
1240
+ export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, HeaderFooterType, IDocStateChangeInterceptorService, InsertTextCommand, RichTextEditingMutation, SetTextSelectionsOperation, UniverDocsPlugin, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, consumeContentInsertRange, deleteCustomRangeFactory, isHeaderFooterSelection, replaceSelectionFactory };
@@ -0,0 +1,41 @@
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 { BooleanNumber, ICommand, IDocumentBody, JSONXActions } from '@univerjs/core';
17
+ export declare enum HeaderFooterType {
18
+ FIRST_PAGE_HEADER = 0,
19
+ FIRST_PAGE_FOOTER = 1,
20
+ DEFAULT_HEADER = 2,
21
+ DEFAULT_FOOTER = 3,
22
+ EVEN_PAGE_HEADER = 4,
23
+ EVEN_PAGE_FOOTER = 5
24
+ }
25
+ export interface IHeaderFooterProps {
26
+ marginHeader?: number;
27
+ marginFooter?: number;
28
+ useFirstPageHeaderFooter?: BooleanNumber;
29
+ evenAndOddHeaders?: BooleanNumber;
30
+ }
31
+ export type HeaderFooterCreateMode = 'single' | 'pair';
32
+ export interface ICreateHeaderFooterCommandParams {
33
+ unitId: string;
34
+ createType?: HeaderFooterType;
35
+ segmentId?: string;
36
+ headerFooterProps?: IHeaderFooterProps;
37
+ createMode?: HeaderFooterCreateMode;
38
+ }
39
+ export declare function getEmptyHeaderFooterBody(): IDocumentBody;
40
+ export declare function createHeaderFooterAction(segmentId: string | undefined, createType: HeaderFooterType, documentStyle: IHeaderFooterProps, actions: JSONXActions, createMode?: HeaderFooterCreateMode): JSONXActions;
41
+ export declare const CreateHeaderFooterCommand: ICommand<ICreateHeaderFooterCommandParams>;
@@ -14,16 +14,12 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { Injector, IParagraph, IParagraphStyle } from '@univerjs/core';
17
- import type { FDocumentBody, IFDocumentBodyEdit, IFDocumentTextRange } from './f-document-body';
18
- import type { IFDocumentElementInfo } from './f-document-element';
19
- import { FDocumentElement } from './f-document-element';
20
- interface IFDocumentParagraphMixin {
21
- asParagraph(): FDocumentParagraph;
22
- }
17
+ import type { FDocument } from './f-document';
18
+ import type { IFDocumentTextRange } from './utils';
23
19
  /**
24
20
  * Resolved paragraph metadata in the the document body.
25
21
  */
26
- export interface IFDocumentResolvedParagraph {
22
+ export interface IFDocumentParagraphInfo {
27
23
  /** The underlying paragraph snapshot object. */
28
24
  paragraph: IParagraph;
29
25
  /** The current paragraph index in the body paragraph list. */
@@ -42,58 +38,55 @@ export interface IFDocumentResolvedParagraph {
42
38
  *
43
39
  * @hideconstructor
44
40
  */
45
- export declare class FDocumentParagraph extends FDocumentElement {
46
- protected readonly body: FDocumentBody;
47
- protected readonly bodyEdit: IFDocumentBodyEdit;
48
- protected readonly info: IFDocumentElementInfo;
49
- protected readonly injector: Injector;
50
- constructor(body: FDocumentBody, bodyEdit: IFDocumentBodyEdit, info: IFDocumentElementInfo, injector: Injector);
41
+ export declare class FDocumentParagraph {
42
+ private readonly _document;
43
+ private readonly _paragraphId;
44
+ private readonly _segmentId;
45
+ private readonly _injector;
46
+ constructor(_document: FDocument, _paragraphId: string, _segmentId: string | undefined, _injector: Injector);
51
47
  /**
52
48
  * Get the persisted paragraph id.
53
49
  * @returns {string} The paragraph id.
54
50
  * @example
55
51
  * ```ts
56
52
  * const fDocument = univerAPI.getActiveDocument();
57
- * const fDocumentBody = fDocument.getBody();
58
- * const element = fDocumentBody.getElement(0);
59
- *
60
- * if (element?.isParagraph()) {
61
- * const paragraph = element.asParagraph();
62
- * console.log(paragraph.getParagraphId());
63
- * }
53
+ * const paragraph = fDocument.getParagraphs()[0];
54
+ * console.log(paragraph?.getId());
64
55
  * ```
65
56
  */
66
- getParagraphId(): string;
57
+ getId(): string;
67
58
  /**
68
- * Get the resolved paragraph info for this wrapper.
69
- * @returns {IFDocumentResolvedParagraph} The resolved paragraph info, including the paragraph object, its index, and its text range.
59
+ * Get the segment id of this paragraph.
60
+ * The main body paragraphs have an empty string segment id.
61
+ * The header and footer paragraphs have a non-empty string segment id.
62
+ * @returns {string} The segment id.
70
63
  * @example
71
64
  * ```ts
72
65
  * const fDocument = univerAPI.getActiveDocument();
73
- * const fDocumentBody = fDocument.getBody();
74
- * const element = fDocumentBody.getElement(0);
75
- *
76
- * if (element?.isParagraph()) {
77
- * const paragraph = element.asParagraph();
78
- * console.log(paragraph.getResolvedParagraphInfo());
79
- * }
66
+ * const paragraph = fDocument.getParagraphs()[0];
67
+ * console.log(paragraph?.getSegmentId());
80
68
  * ```
81
69
  */
82
- getResolvedParagraphInfo(): IFDocumentResolvedParagraph;
70
+ getSegmentId(): string;
71
+ /**
72
+ * Get this paragraph's metadata.
73
+ * @returns {IFDocumentParagraphInfo} The paragraph info.
74
+ * @example
75
+ * ```ts
76
+ * const fDocument = univerAPI.getActiveDocument();
77
+ * const paragraph = fDocument.getParagraphs()[0];
78
+ * console.log(paragraph?.getInfo());
79
+ * ```
80
+ */
81
+ getInfo(): IFDocumentParagraphInfo;
83
82
  /**
84
83
  * Get the current text range occupied by this paragraph.
85
84
  * @returns {IFDocumentTextRange} The paragraph text range, excluding the trailing paragraph break.
86
85
  * @example
87
86
  * ```ts
88
87
  * const fDocument = univerAPI.getActiveDocument();
89
- * const fDocumentBody = fDocument.getBody();
90
- * const element = fDocumentBody.getElement(0);
91
- *
92
- * if (element?.isParagraph()) {
93
- * const paragraph = element.asParagraph();
94
- * const range = paragraph.getRange();
95
- * fDocumentBody.setTextStyle(range, { bl: 1 });
96
- * }
88
+ * const paragraph = fDocument.getParagraphs()[0];
89
+ * console.log(paragraph?.getRange());
97
90
  * ```
98
91
  */
99
92
  getRange(): IFDocumentTextRange;
@@ -103,13 +96,8 @@ export declare class FDocumentParagraph extends FDocumentElement {
103
96
  * @example
104
97
  * ```ts
105
98
  * const fDocument = univerAPI.getActiveDocument();
106
- * const fDocumentBody = fDocument.getBody();
107
- * const element = fDocumentBody.getElement(0);
108
- *
109
- * if (element?.isParagraph()) {
110
- * const paragraph = element.asParagraph();
111
- * console.log(paragraph.getText());
112
- * }
99
+ * const paragraph = fDocument.getParagraphs()[0];
100
+ * console.log(paragraph?.getText());
113
101
  * ```
114
102
  */
115
103
  getText(): string;
@@ -120,14 +108,9 @@ export declare class FDocumentParagraph extends FDocumentElement {
120
108
  * @example
121
109
  * ```ts
122
110
  * const fDocument = univerAPI.getActiveDocument();
123
- * const fDocumentBody = fDocument.getBody();
124
- * const element = fDocumentBody.getElement(0);
125
- *
126
- * if (element?.isParagraph()) {
127
- * const paragraph = element.asParagraph();
128
- * const success = paragraph.setText('Updated title');
129
- * console.log(success ? 'Text updated' : 'Failed to update text');
130
- * }
111
+ * const paragraph = fDocument.getParagraphs()[0];
112
+ * paragraph?.setText('New text');
113
+ * console.log(paragraph?.getText());
131
114
  * ```
132
115
  */
133
116
  setText(text: string): boolean;
@@ -138,14 +121,9 @@ export declare class FDocumentParagraph extends FDocumentElement {
138
121
  * @example
139
122
  * ```ts
140
123
  * const fDocument = univerAPI.getActiveDocument();
141
- * const fDocumentBody = fDocument.getBody();
142
- * const element = fDocumentBody.getElement(0);
143
- *
144
- * if (element?.isParagraph()) {
145
- * const paragraph = element.asParagraph();
146
- * const success = paragraph.appendText(' Appended text');
147
- * console.log(success ? 'Text appended' : 'Failed to append text');
148
- * }
124
+ * const paragraph = fDocument.getParagraphs()[0];
125
+ * paragraph?.appendText(' Appended text');
126
+ * console.log(paragraph?.getText());
149
127
  * ```
150
128
  */
151
129
  appendText(text: string): boolean;
@@ -156,13 +134,18 @@ export declare class FDocumentParagraph extends FDocumentElement {
156
134
  * @example
157
135
  * ```ts
158
136
  * const fDocument = univerAPI.getActiveDocument();
159
- * const fDocumentBody = fDocument.getBody();
160
- * const element = fDocumentBody.getElement(0);
161
- *
162
- * if (element?.isParagraph()) {
163
- * const paragraph = element.asParagraph();
164
- * paragraph.setStyle({ horizontalAlign: 2 });
165
- * }
137
+ * const paragraph = fDocument.getParagraphs()[0];
138
+ * paragraph?.setText('Styled text');
139
+ * paragraph?.setStyle({
140
+ * textStyle: {
141
+ * cl: {
142
+ * rgb: '#FF0000',
143
+ * },
144
+ * fs: 14,
145
+ * },
146
+ * horizontalAlign: 2,
147
+ * });
148
+ * console.log(paragraph?.getInfo().paragraph.paragraphStyle);
166
149
  * ```
167
150
  */
168
151
  setStyle(style: IParagraphStyle): boolean;
@@ -172,13 +155,8 @@ export declare class FDocumentParagraph extends FDocumentElement {
172
155
  * @example
173
156
  * ```ts
174
157
  * const fDocument = univerAPI.getActiveDocument();
175
- * const fDocumentBody = fDocument.getBody();
176
- * const element = fDocumentBody.getElement(0);
177
- *
178
- * if (element?.isParagraph()) {
179
- * const paragraph = element.asParagraph();
180
- * console.log(paragraph.isListItem() ? 'This is a list item' : 'This is not a list item');
181
- * }
158
+ * const paragraph = fDocument.getParagraphs()[0];
159
+ * console.log(paragraph?.isListItem());
182
160
  * ```
183
161
  */
184
162
  isListItem(): boolean;
@@ -188,13 +166,8 @@ export declare class FDocumentParagraph extends FDocumentElement {
188
166
  * @example
189
167
  * ```ts
190
168
  * const fDocument = univerAPI.getActiveDocument();
191
- * const fDocumentBody = fDocument.getBody();
192
- * const element = fDocumentBody.getElement(0);
193
- *
194
- * if (element?.isParagraph()) {
195
- * const paragraph = element.asParagraph();
196
- * console.log(paragraph.isTask() ? 'This is a task item' : 'This is not a task item');
197
- * }
169
+ * const paragraph = fDocument.getParagraphs()[0];
170
+ * console.log(paragraph?.isTask());
198
171
  * ```
199
172
  */
200
173
  isTask(): boolean;
@@ -205,27 +178,27 @@ export declare class FDocumentParagraph extends FDocumentElement {
205
178
  * @example
206
179
  * ```ts
207
180
  * const fDocument = univerAPI.getActiveDocument();
208
- * const fDocumentBody = fDocument.getBody();
209
- * const element = fDocumentBody.getElement(0);
210
- *
211
- * if (element?.isParagraph()) {
212
- * const paragraph = element.asParagraph();
181
+ * const paragraph = fDocument.getParagraphs()[0];
213
182
  *
214
- * if (paragraph.isTask()) {
215
- * const success = paragraph.setTaskChecked(true);
216
- * console.log(success ? 'Task checked' : 'Failed to check task');
217
- * }
183
+ * if (paragraph.isTask()) {
184
+ * const success = paragraph.setTaskChecked(true);
185
+ * console.log(success ? 'Task checked' : 'Failed to check task');
218
186
  * }
219
187
  * ```
220
188
  */
221
189
  setTaskChecked(checked: boolean): boolean;
190
+ /**
191
+ * Remove this paragraph.
192
+ * @returns {boolean} `true` if the paragraph was removed.
193
+ * @example
194
+ * ```ts
195
+ * const fDocument = univerAPI.getActiveDocument();
196
+ * const paragraph = fDocument.getParagraphs()[0];
197
+ * const success = paragraph?.remove();
198
+ * console.log(success ? 'Paragraph removed' : 'Failed to remove paragraph');
199
+ * ```
200
+ */
201
+ remove(): boolean;
222
202
  private _preserveExplicitParagraphIds;
223
203
  }
224
- export declare class FDocumentParagraphMixin extends FDocumentElement {
225
- asParagraph(): FDocumentParagraph;
226
- }
227
- declare module '@univerjs/docs/facade' {
228
- interface FDocumentElement extends IFDocumentParagraphMixin {
229
- }
230
- }
231
- export {};
204
+ export declare function isParagraphFacade(value: unknown): value is FDocumentParagraph;