@stll/docx-core 0.29.0 → 0.30.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.
Binary file
@@ -1,16 +1,19 @@
1
- import { Jt as ParagraphMarkChange, Kt as Paragraph, Wr as TextFormatting, Xt as ParagraphPropertyChange, kr as ParagraphFormatting, n as Document, qt as ParagraphContent, zn as TableRow } from "../document-DrtmJ_hz.js";
1
+ import { A as BlockContent, An as Table, Jt as ParagraphMarkChange, Kt as Paragraph, Wr as TextFormatting, Xt as ParagraphPropertyChange, kr as ParagraphFormatting, n as Document, qt as ParagraphContent, zn as TableRow } from "../document-DrtmJ_hz.js";
2
2
  import { Result } from "better-result";
3
3
  //#region src/ops/types.d.ts
4
4
  /**
5
5
  * The operation schema this module reads and writes.
6
6
  *
7
- * Version 3 adds paragraph insertion through `insertBlocks` and the table-row
7
+ * Version 4 adds paragraph deletion through `deleteBlocks`, direct and tracked
8
+ * whole-table operations with their exact structural inverse, terminal insertion,
9
+ * and cell-ending paragraph marks on tracked row operations.
10
+ * Version 3 added paragraph insertion through `insertBlocks` and the table-row
8
11
  * operations `insertRow`, `deleteRow` and `setTableRows`.
9
12
  * Version 2 added tracked changes: the `revision` stamp on the text, formatting
10
13
  * and paragraph operations, and the review operations `setParagraphReview`,
11
14
  * `replaceInline` and `resolveRevision`.
12
15
  */
13
- declare const DOCUMENT_OP_SCHEMA_VERSION = 3;
16
+ declare const DOCUMENT_OP_SCHEMA_VERSION = 4;
14
17
  /**
15
18
  * The stories an operation can address. Headers, footers, notes and comment
16
19
  * bodies are stories too; this version addresses the main story only.
@@ -112,8 +115,9 @@ type RevisionStamp = {
112
115
  };
113
116
  /** The paragraph fields a split gives the new paragraph, besides its id, content and mark. */
114
117
  type SplitParagraphFields = Omit<Paragraph, "type" | "paraId" | "content" | "sectionProperties" | "pPrMark">;
115
- /** The operation kinds of schema version 3. */
118
+ /** The operation kinds of schema version 4. */
116
119
  declare const DOCUMENT_OP_TYPES: Readonly<{
120
+ readonly DELETE_BLOCKS: "deleteBlocks";
117
121
  readonly INSERT_BLOCKS: "insertBlocks";
118
122
  readonly INSERT_TEXT: "insertText";
119
123
  readonly INSERT_CONTENT: "insertContent";
@@ -128,6 +132,9 @@ declare const DOCUMENT_OP_TYPES: Readonly<{
128
132
  readonly SET_PARAGRAPH_REVIEW: "setParagraphReview";
129
133
  readonly REPLACE_INLINE: "replaceInline";
130
134
  readonly RESOLVE_REVISION: "resolveRevision";
135
+ readonly INSERT_TABLE: "insertTable";
136
+ readonly DELETE_TABLE: "deleteTable";
137
+ readonly SET_CONTAINER_BLOCKS: "setContainerBlocks";
131
138
  readonly INSERT_ROW: "insertRow";
132
139
  readonly DELETE_ROW: "deleteRow";
133
140
  readonly SET_TABLE_ROWS: "setTableRows";
@@ -320,7 +327,9 @@ type SplitHalf = (typeof SPLIT_HALVES)[keyof typeof SPLIT_HALVES];
320
327
  * (`firstMark` must then be absent), and the new paragraph, when its paragraph
321
328
  * properties differ from the source's and it carries no property change,
322
329
  * records one from the source's. Rejecting the mark removes it, which leaves
323
- * the second half with the first's content before its own.
330
+ * the second half with the first's content before its own. A property change
331
+ * does not record the mark's run properties, so a new second half, which ends
332
+ * with the paragraph's own mark, must state the same ones as the paragraph.
324
333
  */
325
334
  type SplitBlockOp = {
326
335
  type: typeof DOCUMENT_OP_TYPES.SPLIT_BLOCK;
@@ -394,6 +403,26 @@ type InsertBlocksOp = {
394
403
  revision?: RevisionStamp;
395
404
  newIds?: NewIds;
396
405
  };
406
+ /**
407
+ * Delete adjacent paragraphs in one block list. A following paragraph keeps
408
+ * its identity and fields. At the end of a block list, the last selected
409
+ * paragraph survives: it takes the preceding paragraph's content and
410
+ * paragraph properties when present, keeping its own mark properties and id;
411
+ * without a preceding paragraph it becomes empty.
412
+ *
413
+ * With `revision`, selected content is wrapped in deletions and the removed
414
+ * breaks are marked. The container-final paragraph never receives a mark.
415
+ * Section boundaries, non-paragraph following blocks and conflicting
416
+ * paragraph reviews are refused rather than partially removed. Tracked deletion
417
+ * of content carrying revision or content-control ids is also unsupported.
418
+ */
419
+ type DeleteBlocksOp = {
420
+ type: typeof DOCUMENT_OP_TYPES.DELETE_BLOCKS;
421
+ story: OpStory;
422
+ blockIds: readonly string[];
423
+ revision?: RevisionStamp;
424
+ newIds?: NewIds;
425
+ };
397
426
  /**
398
427
  * Replace a run of adjacent paragraphs with other paragraphs.
399
428
  *
@@ -471,8 +500,8 @@ type RevisionDecision = (typeof REVISION_DECISIONS)[keyof typeof REVISION_DECISI
471
500
  * a join at a section break.
472
501
  * - Row insertions and deletions are resolved after inline changes and before
473
502
  * paragraph marks. Keeping a row clears its structural revision; removing
474
- * it also removes its nested revisions. Removing every row requires a
475
- * whole-table operation and is refused as `untrackable`.
503
+ * it also removes its nested revisions. Removing every row removes the
504
+ * table, preserving the surrounding paragraphs.
476
505
  * - Records the resolution leaves meeting are merged as far as they are
477
506
  * alike: the pieces a change cut apart are one record again.
478
507
  *
@@ -489,8 +518,9 @@ type ResolveRevisionOp = {
489
518
  /**
490
519
  * Insert a row at a zero-based index in the table holding `blockId`.
491
520
  * The paragraph reference selects the innermost table containing it.
492
- * With `revision`, the row and its cell content record an insertion; no
493
- * paragraph mark changes. `newIds` names the additional wrapper ids.
521
+ * With `revision`, the row, its cell content and
522
+ * cell-ending paragraph marks record insertion. `newIds` supplies the
523
+ * additional physical revision ids.
494
524
  */
495
525
  type InsertRowOp = {
496
526
  type: typeof DOCUMENT_OP_TYPES.INSERT_ROW;
@@ -504,8 +534,8 @@ type InsertRowOp = {
504
534
  /**
505
535
  * Remove the row holding `blockId`, or record a row and cell-content deletion
506
536
  * with `revision`. The innermost containing row is selected. `expected`, when
507
- * present, refuses a stale row. Removing the last row requires a table
508
- * operation and is refused; tracked deletion keeps a row not pending deletion.
537
+ * present, refuses a stale row. Direct removal of the last row removes its
538
+ * table; tracked deletion keeps a row not pending deletion.
509
539
  */
510
540
  type DeleteRowOp = {
511
541
  type: typeof DOCUMENT_OP_TYPES.DELETE_ROW;
@@ -517,9 +547,8 @@ type DeleteRowOp = {
517
547
  };
518
548
  /**
519
549
  * Replace a table's rows exactly, with a structural staleness precondition.
520
- * This is the inverse and resolution primitive for row operations. The table
521
- * holding `blockId` must retain at least one row; whole-table removal is a
522
- * separate operation.
550
+ * This is the inverse and resolution primitive for row operations. An empty
551
+ * row list removes the table, with an exact structural inverse.
523
552
  */
524
553
  type SetTableRowsOp = {
525
554
  type: typeof DOCUMENT_OP_TYPES.SET_TABLE_ROWS;
@@ -528,8 +557,51 @@ type SetTableRowsOp = {
528
557
  expected: readonly TableRow[];
529
558
  rows: readonly TableRow[];
530
559
  };
531
- /** A schema-version-3 document operation. */
532
- type DocumentOp = InsertBlocksOp | InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp | SetParagraphReviewOp | ReplaceInlineOp | ResolveRevisionOp | InsertRowOp | DeleteRowOp | SetTableRowsOp;
560
+ /**
561
+ * Insert a table before or after a paragraph. Tracking records each row,
562
+ * cell content and cell-ending paragraph mark. At a container's end,
563
+ * `terminal` moves the source content into a new preceding paragraph while
564
+ * retaining the source id and fields on the untracked final paragraph.
565
+ */
566
+ type InsertTableOp = {
567
+ type: typeof DOCUMENT_OP_TYPES.INSERT_TABLE;
568
+ story: OpStory;
569
+ at: BlockInsertionPoint;
570
+ table: Table;
571
+ revision?: RevisionStamp;
572
+ newIds?: NewIds;
573
+ terminal?: {
574
+ beforeBlockId: string;
575
+ };
576
+ };
577
+ /**
578
+ * Remove the innermost table holding the addressed paragraph. Its block list
579
+ * must retain a paragraph for the inverse. Tracking records row, cell-content
580
+ * and cell-ending paragraph-mark deletions without removing content.
581
+ */
582
+ type DeleteTableOp = {
583
+ type: typeof DOCUMENT_OP_TYPES.DELETE_TABLE;
584
+ story: OpStory;
585
+ blockId: string;
586
+ expected?: Table;
587
+ revision?: RevisionStamp;
588
+ newIds?: NewIds;
589
+ };
590
+ /**
591
+ * Exact structural inverse for table edits. The addressed paragraph must
592
+ * remain in the same block list; unrelated edits in that list make it stale.
593
+ * Section boundaries and story-final marks are preserved; cell-ending marks
594
+ * are exact model data, including after independent row resolution.
595
+ */
596
+ type SetContainerBlocksOp = {
597
+ type: typeof DOCUMENT_OP_TYPES.SET_CONTAINER_BLOCKS;
598
+ story: OpStory;
599
+ blockId: string;
600
+ expected: readonly BlockContent[];
601
+ blocks: readonly BlockContent[];
602
+ };
603
+ /** A schema-version-4 document operation. */
604
+ type DocumentOp = DeleteBlocksOp | InsertTableOp | DeleteTableOp | SetContainerBlocksOp | InsertBlocksOp | InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp | SetParagraphReviewOp | ReplaceInlineOp | ResolveRevisionOp | InsertRowOp | DeleteRowOp | SetTableRowsOp;
533
605
  /**
534
606
  * An operation as it is journaled and sent: the schema that reads it, and the
535
607
  * operation. A reader refuses an envelope of a schema it does not know rather
@@ -715,18 +787,33 @@ type PlanTrackedDeletionOptions = {
715
787
  newIds?: NewIds;
716
788
  };
717
789
  /**
718
- * The operations a tracked deletion of a range is made of, to apply in
719
- * order as one batch: a direct `deleteRange` for each stretch of the author's
720
- * own insertions (retracting a suggestion removes it), and a tracked one for
721
- * each other stretch, split around comment boundaries and references, which
722
- * no tracked change can hold and which therefore stay. Stretches go from the
723
- * last to the first, so each position still names what it named in the
724
- * input. The positions default their `zeroWidthBefore` as `deleteRange` does.
725
- *
726
- * The first tracked deletion carries the stamp's id. Each later one takes the
727
- * next id of `newIds.revision` the package does not use for its stamp, then
728
- * the ones it needs for the records it cuts.
790
+ * Plan a same-list range as inline deletions followed by tracked paragraph
791
+ * joins. Own insertions are retracted directly; comment anchors remain.
792
+ * Inline ranges run in reverse order, then joins run from last to first.
793
+ * All physical revision ids come from one pool for the complete batch.
729
794
  */
730
795
  declare const planTrackedDeletion: (document: Document, options: PlanTrackedDeletionOptions) => Result<DocumentOp[], DocumentOpRefusal>;
731
796
  //#endregion
732
- export { type AppliedDocumentOp, type BlockInsertionPoint, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, type DeleteRangeOp, type DeleteRowOp, type DocumentOp, type DocumentOpEnvelope, DocumentOpRefusal, type DocumentOpRefusalReason, type DocumentOpType, DocumentOpsContractError, EMPTY_PROPERTY_SETS, type EmptyPropertySet, type FormattingPatch, INHERIT_RUN_PROPS, type InlineSlice, type InsertBlocksOp, type InsertContentOp, type InsertRowOp, type InsertTextOp, type InsertedRunProps, type JoinBlocksOp, type JoinInlineOp, type NewIds, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, type OpStory, PARAGRAPH_MARK_FORMATTING_KEYS, type ParagraphPropsPatch, type ParagraphReviewFields, type PlanTrackedDeletionOptions, REVISION_DECISIONS, type ReplaceBlocksOp, type ReplaceInlineOp, type ResolveRevisionOp, type RevisionDecision, type RevisionStamp, type RunPropsPatch, SPLIT_HALVES, type SetParagraphPropsOp, type SetParagraphReviewOp, type SetRunPropsOp, type SetTableRowsOp, type SplitBlockOp, type SplitHalf, type SplitInlineOp, type SplitParagraphFields, type TextPosition, type TouchedBlocks, applyDocumentOp, applyDocumentOps, normalizeForOps, paragraphLength, paragraphLogicalText, planTrackedDeletion, revisionIdDemand, toOpEnvelope, validateOpsDocument };
797
+ //#region src/ops/rangeReplacement.d.ts
798
+ /**
799
+ * A range replacement fragment: newly identified paragraphs before its last
800
+ * paragraph, and the inline tail inserted into the retained original paragraph.
801
+ * Each new paragraph's own fields apply to it, including when it takes the
802
+ * source prefix. The last fragment keeps the original survivor's identity.
803
+ * Closed inline slices are required; review and content-control ids in the
804
+ * fragment, and section-bearing paragraphs, are unsupported.
805
+ */
806
+ type PlanTrackedReplaceOptions = PlanTrackedDeletionOptions & {
807
+ replacement: {
808
+ paragraphs: readonly Paragraph[];
809
+ tail: InlineSlice;
810
+ };
811
+ };
812
+ /**
813
+ * Plan a tracked replacement of a same-list range: the range's tracked
814
+ * deletion followed by the replacement fragment as tracked insertions.
815
+ * All physical revision ids come from one pool for the complete batch.
816
+ */
817
+ declare const planTrackedReplace: (document: Document, options: PlanTrackedReplaceOptions) => Result<DocumentOp[], DocumentOpRefusal>;
818
+ //#endregion
819
+ export { type AppliedDocumentOp, type BlockInsertionPoint, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, type DeleteBlocksOp, type DeleteRangeOp, type DeleteRowOp, type DeleteTableOp, type DocumentOp, type DocumentOpEnvelope, DocumentOpRefusal, type DocumentOpRefusalReason, type DocumentOpType, DocumentOpsContractError, EMPTY_PROPERTY_SETS, type EmptyPropertySet, type FormattingPatch, INHERIT_RUN_PROPS, type InlineSlice, type InsertBlocksOp, type InsertContentOp, type InsertRowOp, type InsertTableOp, type InsertTextOp, type InsertedRunProps, type JoinBlocksOp, type JoinInlineOp, type NewIds, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, type OpStory, PARAGRAPH_MARK_FORMATTING_KEYS, type ParagraphPropsPatch, type ParagraphReviewFields, type PlanTrackedDeletionOptions, type PlanTrackedReplaceOptions, REVISION_DECISIONS, type ReplaceBlocksOp, type ReplaceInlineOp, type ResolveRevisionOp, type RevisionDecision, type RevisionStamp, type RunPropsPatch, SPLIT_HALVES, type SetContainerBlocksOp, type SetParagraphPropsOp, type SetParagraphReviewOp, type SetRunPropsOp, type SetTableRowsOp, type SplitBlockOp, type SplitHalf, type SplitInlineOp, type SplitParagraphFields, type TextPosition, type TouchedBlocks, applyDocumentOp, applyDocumentOps, normalizeForOps, paragraphLength, paragraphLogicalText, planTrackedDeletion, planTrackedReplace, revisionIdDemand, toOpEnvelope, validateOpsDocument };