Skip to main content
Alpha: Document API is currently alpha and subject to breaking changes.

Summary

Replace content at a contiguous document selection. Text path accepts a SelectionTarget or ref plus replacement text. Structural path accepts a BlockNodeAddress (replaces whole block), SelectionTarget (expands to full covered block boundaries), or ref plus SDFragment content.
  • Operation ID: replace
  • API member path: editor.doc.replace(...)
  • Mutates document: yes
  • Idempotency: conditional
  • Supports tracked mode: yes
  • Supports dry run: yes
  • Deterministic target resolution: yes

Expected result

Returns an SDMutationReceipt with applied status; receipt reports NO_OP if the target range already contains identical content.

Input fields

Variant 1.1 (target.kind=“selection”)

FieldTypeRequiredDescription
targetSelectionTargetyesSelectionTarget
target.endSelectionPointyesSelectionPoint
target.kind"selection"yesConstant: "selection"
target.startSelectionPointyesSelectionPoint
textstringyes

Variant 1.2

FieldTypeRequiredDescription
refstringyes
textstringyes

Variant 2.1

FieldTypeRequiredDescription
contentobject \object[]yesOne of: object, object[]
nestingPolicyobjectno
nestingPolicy.tablesenumno"forbid", "allow"
targetBlockNodeAddress \SelectionTargetyesOne of: BlockNodeAddress, SelectionTarget

Variant 2.2

FieldTypeRequiredDescription
contentobject \object[]yesOne of: object, object[]
nestingPolicyobjectno
nestingPolicy.tablesenumno"forbid", "allow"
refstringyes

Example request

{
  "target": {
    "end": {
      "blockId": "block-abc123",
      "kind": "text",
      "offset": 12
    },
    "kind": "selection",
    "start": {
      "blockId": "block-abc123",
      "kind": "text",
      "offset": 0
    }
  },
  "text": "Hello, world."
}

Output fields

Variant 1 (success=true)

FieldTypeRequiredDescription
evaluatedRevisionobjectno
evaluatedRevision.afterstringno
evaluatedRevision.beforestringno
resolutionobjectno
resolution.rangeTextMutationRangenoTextMutationRange
resolution.range.fromintegerno
resolution.range.tointegerno
resolution.selectionTargetSelectionTargetnoSelectionTarget
resolution.selectionTarget.endSelectionPointnoSelectionPoint
resolution.selectionTarget.kind"selection"noConstant: "selection"
resolution.selectionTarget.startSelectionPointnoSelectionPoint
resolution.targetTextAddress \BlockNodeAddressnoOne of: TextAddress, BlockNodeAddress
successtrueyesConstant: true

Variant 2 (success=false)

FieldTypeRequiredDescription
evaluatedRevisionobjectno
evaluatedRevision.afterstringno
evaluatedRevision.beforestringno
failureobjectyes
failure.codeenumyes"INVALID_TARGET", "NO_OP", "INVALID_NESTING", "INVALID_PLACEMENT", "INVALID_PAYLOAD", "CAPABILITY_UNSUPPORTED", "ADDRESS_STALE", "DUPLICATE_ID", "INVALID_CONTEXT", "RAW_MODE_REQUIRED", "PRESERVE_ONLY_VIOLATION", "INVALID_INPUT"
failure.detailsanyno
failure.messagestringyes
resolutionobjectno
resolution.rangeTextMutationRangenoTextMutationRange
resolution.range.fromintegerno
resolution.range.tointegerno
resolution.selectionTargetSelectionTargetnoSelectionTarget
resolution.selectionTarget.endSelectionPointnoSelectionPoint
resolution.selectionTarget.kind"selection"noConstant: "selection"
resolution.selectionTarget.startSelectionPointnoSelectionPoint
resolution.targetTextAddress \BlockNodeAddressnoOne of: TextAddress, BlockNodeAddress
successfalseyesConstant: false

Example response

{
  "evaluatedRevision": {
    "after": "rev-002",
    "before": "rev-001"
  },
  "resolution": {
    "range": {
      "from": 0,
      "to": 12
    },
    "target": {
      "blockId": "block-abc123",
      "kind": "text",
      "range": {
        "end": 12,
        "start": 0
      }
    }
  },
  "success": true
}

Pre-apply throws

  • TARGET_NOT_FOUND
  • CAPABILITY_UNAVAILABLE
  • INVALID_TARGET
  • INVALID_INPUT
  • ADDRESS_STALE
  • DUPLICATE_ID
  • RAW_MODE_REQUIRED
  • PRESERVE_ONLY_VIOLATION
  • CAPABILITY_UNSUPPORTED

Non-applied failure codes

  • INVALID_TARGET
  • NO_OP
  • INVALID_NESTING
  • INVALID_PLACEMENT
  • INVALID_PAYLOAD
  • CAPABILITY_UNSUPPORTED
  • ADDRESS_STALE
  • DUPLICATE_ID
  • INVALID_CONTEXT
  • RAW_MODE_REQUIRED
  • PRESERVE_ONLY_VIOLATION
  • INVALID_INPUT

Raw schemas

{
  "oneOf": [
    {
      "oneOf": [
        {
          "additionalProperties": false,
          "properties": {
            "target": {
              "$ref": "#/$defs/SelectionTarget"
            },
            "text": {
              "type": "string"
            }
          },
          "required": [
            "target",
            "text"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "ref": {
              "type": "string"
            },
            "text": {
              "type": "string"
            }
          },
          "required": [
            "ref",
            "text"
          ],
          "type": "object"
        }
      ]
    },
    {
      "oneOf": [
        {
          "additionalProperties": false,
          "properties": {
            "content": {
              "oneOf": [
                {
                  "type": "object"
                },
                {
                  "items": {
                    "type": "object"
                  },
                  "type": "array"
                }
              ]
            },
            "nestingPolicy": {
              "additionalProperties": false,
              "properties": {
                "tables": {
                  "enum": [
                    "forbid",
                    "allow"
                  ]
                }
              },
              "type": "object"
            },
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                },
                {
                  "$ref": "#/$defs/SelectionTarget"
                }
              ]
            }
          },
          "required": [
            "target",
            "content"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "content": {
              "oneOf": [
                {
                  "type": "object"
                },
                {
                  "items": {
                    "type": "object"
                  },
                  "type": "array"
                }
              ]
            },
            "nestingPolicy": {
              "additionalProperties": false,
              "properties": {
                "tables": {
                  "enum": [
                    "forbid",
                    "allow"
                  ]
                }
              },
              "type": "object"
            },
            "ref": {
              "type": "string"
            }
          },
          "required": [
            "ref",
            "content"
          ],
          "type": "object"
        }
      ]
    }
  ]
}
{
  "oneOf": [
    {
      "additionalProperties": false,
      "properties": {
        "evaluatedRevision": {
          "additionalProperties": false,
          "properties": {
            "after": {
              "type": "string"
            },
            "before": {
              "type": "string"
            }
          },
          "required": [
            "before",
            "after"
          ],
          "type": "object"
        },
        "resolution": {
          "additionalProperties": false,
          "properties": {
            "range": {
              "$ref": "#/$defs/TextMutationRange"
            },
            "selectionTarget": {
              "$ref": "#/$defs/SelectionTarget"
            },
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/TextAddress"
                },
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                }
              ]
            }
          },
          "required": [
            "target",
            "range"
          ],
          "type": "object"
        },
        "success": {
          "const": true
        }
      },
      "required": [
        "success"
      ],
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "evaluatedRevision": {
          "additionalProperties": false,
          "properties": {
            "after": {
              "type": "string"
            },
            "before": {
              "type": "string"
            }
          },
          "required": [
            "before",
            "after"
          ],
          "type": "object"
        },
        "failure": {
          "additionalProperties": false,
          "properties": {
            "code": {
              "enum": [
                "INVALID_TARGET",
                "NO_OP",
                "INVALID_NESTING",
                "INVALID_PLACEMENT",
                "INVALID_PAYLOAD",
                "CAPABILITY_UNSUPPORTED",
                "ADDRESS_STALE",
                "DUPLICATE_ID",
                "INVALID_CONTEXT",
                "RAW_MODE_REQUIRED",
                "PRESERVE_ONLY_VIOLATION",
                "INVALID_INPUT"
              ]
            },
            "details": {},
            "message": {
              "type": "string"
            }
          },
          "required": [
            "code",
            "message"
          ],
          "type": "object"
        },
        "resolution": {
          "additionalProperties": false,
          "properties": {
            "range": {
              "$ref": "#/$defs/TextMutationRange"
            },
            "selectionTarget": {
              "$ref": "#/$defs/SelectionTarget"
            },
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/TextAddress"
                },
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                }
              ]
            }
          },
          "required": [
            "target",
            "range"
          ],
          "type": "object"
        },
        "success": {
          "const": false
        }
      },
      "required": [
        "success",
        "failure"
      ],
      "type": "object"
    }
  ]
}
{
  "additionalProperties": false,
  "properties": {
    "evaluatedRevision": {
      "additionalProperties": false,
      "properties": {
        "after": {
          "type": "string"
        },
        "before": {
          "type": "string"
        }
      },
      "required": [
        "before",
        "after"
      ],
      "type": "object"
    },
    "resolution": {
      "additionalProperties": false,
      "properties": {
        "range": {
          "$ref": "#/$defs/TextMutationRange"
        },
        "selectionTarget": {
          "$ref": "#/$defs/SelectionTarget"
        },
        "target": {
          "oneOf": [
            {
              "$ref": "#/$defs/TextAddress"
            },
            {
              "$ref": "#/$defs/BlockNodeAddress"
            }
          ]
        }
      },
      "required": [
        "target",
        "range"
      ],
      "type": "object"
    },
    "success": {
      "const": true
    }
  },
  "required": [
    "success"
  ],
  "type": "object"
}
{
  "additionalProperties": false,
  "properties": {
    "evaluatedRevision": {
      "additionalProperties": false,
      "properties": {
        "after": {
          "type": "string"
        },
        "before": {
          "type": "string"
        }
      },
      "required": [
        "before",
        "after"
      ],
      "type": "object"
    },
    "failure": {
      "additionalProperties": false,
      "properties": {
        "code": {
          "enum": [
            "INVALID_TARGET",
            "NO_OP",
            "INVALID_NESTING",
            "INVALID_PLACEMENT",
            "INVALID_PAYLOAD",
            "CAPABILITY_UNSUPPORTED",
            "ADDRESS_STALE",
            "DUPLICATE_ID",
            "INVALID_CONTEXT",
            "RAW_MODE_REQUIRED",
            "PRESERVE_ONLY_VIOLATION",
            "INVALID_INPUT"
          ]
        },
        "details": {},
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object"
    },
    "resolution": {
      "additionalProperties": false,
      "properties": {
        "range": {
          "$ref": "#/$defs/TextMutationRange"
        },
        "selectionTarget": {
          "$ref": "#/$defs/SelectionTarget"
        },
        "target": {
          "oneOf": [
            {
              "$ref": "#/$defs/TextAddress"
            },
            {
              "$ref": "#/$defs/BlockNodeAddress"
            }
          ]
        }
      },
      "required": [
        "target",
        "range"
      ],
      "type": "object"
    },
    "success": {
      "const": false
    }
  },
  "required": [
    "success",
    "failure"
  ],
  "type": "object"
}