Documentation
¶
Overview ¶
Package plan compiles high-level edit operations into Docs API batchUpdate requests. It owns every piece of index arithmetic on the write path: fragment layout, minimal diffs, request ordering, and the overwrite guard. It never talks to the network.
Index ¶
- Constants
- Variables
- func AcceptSuggestion(id string) json.RawMessage
- func AddDocumentTab(p TabProperties) json.RawMessage
- func ClearTextStyle(r Rng) json.RawMessage
- func CreateBullets(r Rng, preset string) json.RawMessage
- func CreateFooter(tabID string) json.RawMessage
- func CreateFootnote(at Loc) json.RawMessage
- func CreateHeader(tabID string) json.RawMessage
- func CreateNamedRange(name string, r Rng) json.RawMessage
- func DeleteBullets(r Rng) json.RawMessage
- func DeleteFooter(footerID, tabID string) json.RawMessage
- func DeleteHeader(headerID, tabID string) json.RawMessage
- func DeleteNamedRange(p NamedRangeParams, tabID string) json.RawMessage
- func DeletePositionedObject(objectID, tabID string) json.RawMessage
- func DeleteRange(r Rng) json.RawMessage
- func DeleteSuggestion(id string) json.RawMessage
- func DeleteTab(tabID string) json.RawMessage
- func DeleteTableColumn(cell CellLoc) json.RawMessage
- func DeleteTableRow(cell CellLoc) json.RawMessage
- func Deletes(k OpKind) bool
- func EditRequests(edits []Edit, seg Segment) []json.RawMessage
- func InsertComment(content string, r Rng, assignee string) json.RawMessage
- func InsertDate(d DateSpec, at Loc) json.RawMessage
- func InsertInlineImage(uri string, at Loc, widthPt, heightPt float64) json.RawMessage
- func InsertPageBreak(at Loc) json.RawMessage
- func InsertPerson(name, email string, at Loc) json.RawMessage
- func InsertRichLink(uri, title string, at Loc) json.RawMessage
- func InsertSectionBreak(at Loc, sectionType string) json.RawMessage
- func InsertTable(rows, cols int, at Loc) json.RawMessage
- func InsertTableColumn(cell CellLoc, right bool) json.RawMessage
- func InsertTableRow(cell CellLoc, below bool) json.RawMessage
- func InsertText(text string, at Loc) json.RawMessage
- func Kind(r json.RawMessage) string
- func KindList(t Tool) string
- func MergeTableCells(cell CellLoc, rowSpan, colSpan int) json.RawMessage
- func Noun(k OpKind) string
- func PinTableHeaderRows(table Loc, n int) json.RawMessage
- func RejectSuggestion(id string) json.RawMessage
- func ReplaceAllText(find, replace string, matchCase bool, tabID string) json.RawMessage
- func ReplaceImage(objectID, uri string, crop bool, tabID string) json.RawMessage
- func ReplaceNamedRangeContent(p NamedRangeParams, tabID string) json.RawMessage
- func SegmentReplies() []struct{ ... }
- func Structural(k OpKind) bool
- func UnmergeTableCells(cell CellLoc, rowSpan, colSpan int) json.RawMessage
- func UpdateDocumentStyle(s PageSpec, tabID string) json.RawMessage
- func UpdateDocumentTabProperties(tabID string, p TabProperties) json.RawMessage
- func UpdateNamedStyle(s NamedStyleSpec, tabID string) json.RawMessage
- func UpdateParagraphStyle(r Rng, s ParagraphStyleSpec) json.RawMessage
- func UpdateSectionStyle(r Rng, s SectionSpec) json.RawMessage
- func UpdateTableCellStyle(cell CellLoc, rowSpan, colSpan int, s CellStyleSpec) json.RawMessage
- func UpdateTableColumnProperties(table Loc, columns []int, widthPt *float64, even bool) json.RawMessage
- func UpdateTableRowStyle(table Loc, rows []int, minHeightPt *float64, preventOverflow *bool) json.RawMessage
- func UpdateTextStyle(r Rng, s TextStyleSpec) json.RawMessage
- func ValidColor(s string) bool
- type Anchor
- type Border
- type BorderSpec
- type CellLoc
- type CellStyleSpec
- type Compiled
- type DateSpec
- type Edit
- type FragmentOptions
- type Group
- type KindInfo
- type Loc
- type Mode
- type NamedRangeParams
- type NamedStyleSpec
- type ObjectParams
- type Op
- type OpKind
- type OpSummary
- type Options
- type PageMargins
- type PageSpec
- type ParagraphStyleSpec
- type Params
- type Proposal
- type Result
- type Rng
- type SectionSpec
- type Segment
- type Shape
- type TabProperties
- type TableParams
- type TextStyleSpec
- type Tool
Constants ¶
const ( SectionContinuous = "CONTINUOUS" SectionNextPage = "NEXT_PAGE" )
Section types insertSectionBreak accepts. Columns are not a section type: they are set with SectionSpec.Columns on the section itself.
const ( BulletPreset = "BULLET_DISC_CIRCLE_SQUARE" NumberedPreset = "NUMBERED_DECIMAL_ALPHA_ROMAN" CheckboxPreset = "BULLET_CHECKBOX" )
Bullet presets.
const CodeFont = "Courier New"
CodeFont is the font used for code blocks and inline code.
const MaxNamedRangeName = 256
MaxNamedRangeName is the API's limit on a name.
Variables ¶
var DateFormats = map[string]string{
"": "", "iso": "DATE_FORMAT_ISO8601", "full": "DATE_FORMAT_MONTH_DAY_FULL", "abbreviated": "DATE_FORMAT_MONTH_DAY_YEAR_ABBREVIATED", "month_day": "DATE_FORMAT_MONTH_DAY_ABBREVIATED",
}
DateFormats maps the friendly date_format names to the API enum.
var ErrBlocked = errors.New("blocked")
ErrBlocked is returned when the guard refuses a direct edit.
var NamedStyleTypes = doc.NamedStyleOrder
NamedStyleTypes are the styles every paragraph inherits from, in the order a read reports them.
var SuggestModeUnsupported = map[string]bool{ "addDocumentTab": true, "createNamedRange": true, "deleteFooter": true, "deleteHeader": true, "deleteNamedRange": true, "deleteTab": true, "updateDocumentTabProperties": true, "updateTableColumnProperties": true, }
SuggestModeUnsupported lists request types the API refuses in SUGGEST mode; later phases that build those requests must check it.
Functions ¶
func AcceptSuggestion ¶
func AcceptSuggestion(id string) json.RawMessage
AcceptSuggestion accepts a suggestion by id (Developer Preview).
func AddDocumentTab ¶ added in v0.2.0
func AddDocumentTab(p TabProperties) json.RawMessage
AddDocumentTab adds a tab; the reply carries the new tabProperties.
func ClearTextStyle ¶
func ClearTextStyle(r Rng) json.RawMessage
ClearTextStyle resets every character property in the range to the paragraph's default style.
func CreateBullets ¶
func CreateBullets(r Rng, preset string) json.RawMessage
CreateBullets turns the paragraphs in r into a list. Leading tabs set nesting and are consumed by the API.
func CreateFooter ¶
func CreateFooter(tabID string) json.RawMessage
CreateFooter creates a default footer; the reply carries footerId.
func CreateFootnote ¶
func CreateFootnote(at Loc) json.RawMessage
CreateFootnote inserts a footnote reference at a location; the reply carries footnoteId.
func CreateHeader ¶
func CreateHeader(tabID string) json.RawMessage
CreateHeader creates a default header; the reply carries headerId.
func CreateNamedRange ¶ added in v0.4.0
func CreateNamedRange(name string, r Rng) json.RawMessage
CreateNamedRange names a range so later calls can find it again.
func DeleteBullets ¶
func DeleteBullets(r Rng) json.RawMessage
DeleteBullets removes list membership from the paragraphs in r.
func DeleteFooter ¶ added in v0.2.0
func DeleteFooter(footerID, tabID string) json.RawMessage
DeleteFooter removes a footer segment.
func DeleteHeader ¶ added in v0.2.0
func DeleteHeader(headerID, tabID string) json.RawMessage
DeleteHeader removes a header segment.
func DeleteNamedRange ¶ added in v0.4.0
func DeleteNamedRange(p NamedRangeParams, tabID string) json.RawMessage
DeleteNamedRange forgets a named range. The text it covered stays.
func DeletePositionedObject ¶ added in v0.4.0
func DeletePositionedObject(objectID, tabID string) json.RawMessage
DeletePositionedObject removes a floating object, which no range covers and so no text deletion can reach.
func DeleteSuggestion ¶ added in v0.4.0
func DeleteSuggestion(id string) json.RawMessage
DeleteSuggestion removes a suggestion without applying or declining it. Google allows only its author to; an editor rejects instead (Developer Preview).
func DeleteTab ¶ added in v0.2.0
func DeleteTab(tabID string) json.RawMessage
DeleteTab deletes a tab and everything in it.
func DeleteTableColumn ¶ added in v0.2.0
func DeleteTableColumn(cell CellLoc) json.RawMessage
DeleteTableColumn deletes the cell's column.
func DeleteTableRow ¶ added in v0.2.0
func DeleteTableRow(cell CellLoc) json.RawMessage
DeleteTableRow deletes the cell's row.
func Deletes ¶ added in v0.2.0
Deletes reports whether the kind removes existing content, which is what the overwrite guard protects.
func EditRequests ¶
func EditRequests(edits []Edit, seg Segment) []json.RawMessage
EditRequests turns edits into requests in descending position order, deleting before inserting at each position.
func InsertComment ¶
func InsertComment(content string, r Rng, assignee string) json.RawMessage
InsertComment anchors a comment to a range (Developer Preview).
func InsertDate ¶ added in v0.2.0
func InsertDate(d DateSpec, at Loc) json.RawMessage
InsertDate inserts a date chip.
func InsertInlineImage ¶ added in v0.2.0
func InsertInlineImage(uri string, at Loc, widthPt, heightPt float64) json.RawMessage
InsertInlineImage inserts an image fetched from a public URL. Width and height in points are optional; the API keeps the aspect ratio when only one is given.
func InsertPageBreak ¶
func InsertPageBreak(at Loc) json.RawMessage
InsertPageBreak inserts a page break at a location.
func InsertPerson ¶ added in v0.2.0
func InsertPerson(name, email string, at Loc) json.RawMessage
InsertPerson inserts a people chip. The email is required; the name is what the chip shows when set.
func InsertRichLink ¶ added in v0.2.0
func InsertRichLink(uri, title string, at Loc) json.RawMessage
InsertRichLink inserts a smart chip linking to a Google resource (a Drive file, a Calendar event, a YouTube video).
func InsertSectionBreak ¶ added in v0.4.0
func InsertSectionBreak(at Loc, sectionType string) json.RawMessage
InsertSectionBreak starts a new section at the insertion point.
func InsertTable ¶ added in v0.2.0
func InsertTable(rows, cols int, at Loc) json.RawMessage
InsertTable inserts an empty rows×cols table at a location. The API puts a paragraph boundary before the table, so the table occupies [at+1, …).
func InsertTableColumn ¶ added in v0.2.0
func InsertTableColumn(cell CellLoc, right bool) json.RawMessage
InsertTableColumn inserts a column left or right of the cell's column.
func InsertTableRow ¶ added in v0.2.0
func InsertTableRow(cell CellLoc, below bool) json.RawMessage
InsertTableRow inserts a row above or below the cell's row.
func InsertText ¶
func InsertText(text string, at Loc) json.RawMessage
InsertText inserts text at a location.
func Kind ¶
func Kind(r json.RawMessage) string
Kind returns the request type name of a marshalled request.
func MergeTableCells ¶ added in v0.2.0
func MergeTableCells(cell CellLoc, rowSpan, colSpan int) json.RawMessage
MergeTableCells merges the rowSpan×colSpan block starting at cell.
func PinTableHeaderRows ¶ added in v0.2.0
func PinTableHeaderRows(table Loc, n int) json.RawMessage
PinTableHeaderRows pins the first n rows as repeating header rows.
func RejectSuggestion ¶
func RejectSuggestion(id string) json.RawMessage
RejectSuggestion rejects a suggestion by id (Developer Preview).
func ReplaceAllText ¶
func ReplaceAllText(find, replace string, matchCase bool, tabID string) json.RawMessage
ReplaceAllText replaces every occurrence in the given tab. The tab is always named because the API's default is every tab.
func ReplaceImage ¶ added in v0.4.0
func ReplaceImage(objectID, uri string, crop bool, tabID string) json.RawMessage
ReplaceImage swaps an image's source, keeping its place in the text. Crop asks Google to centre-crop the new image into the old one's frame instead of resizing the frame to it.
func ReplaceNamedRangeContent ¶ added in v0.4.0
func ReplaceNamedRangeContent(p NamedRangeParams, tabID string) json.RawMessage
ReplaceNamedRangeContent writes text over every range of the name.
func SegmentReplies ¶ added in v0.3.0
SegmentReplies lists the kinds whose reply names a new segment, with the reply key, in registry order.
func Structural ¶ added in v0.4.0
Structural reports whether the op changes a table's grid, which renumbers the rows or columns that later ops name.
func UnmergeTableCells ¶ added in v0.2.0
func UnmergeTableCells(cell CellLoc, rowSpan, colSpan int) json.RawMessage
UnmergeTableCells splits merged cells in the block.
func UpdateDocumentStyle ¶ added in v0.4.0
func UpdateDocumentStyle(s PageSpec, tabID string) json.RawMessage
UpdateDocumentStyle sets a tab's page properties.
func UpdateDocumentTabProperties ¶ added in v0.2.0
func UpdateDocumentTabProperties(tabID string, p TabProperties) json.RawMessage
UpdateDocumentTabProperties renames or moves a tab.
func UpdateNamedStyle ¶ added in v0.4.0
func UpdateNamedStyle(s NamedStyleSpec, tabID string) json.RawMessage
UpdateNamedStyle redefines a named style, which restyles every paragraph that carries it and every one written with it afterwards.
func UpdateParagraphStyle ¶
func UpdateParagraphStyle(r Rng, s ParagraphStyleSpec) json.RawMessage
UpdateParagraphStyle applies a spec to the paragraphs overlapping r.
func UpdateSectionStyle ¶ added in v0.4.0
func UpdateSectionStyle(r Rng, s SectionSpec) json.RawMessage
UpdateSectionStyle styles the sections the range touches.
func UpdateTableCellStyle ¶ added in v0.2.0
func UpdateTableCellStyle(cell CellLoc, rowSpan, colSpan int, s CellStyleSpec) json.RawMessage
UpdateTableCellStyle styles the rowSpan×colSpan block starting at cell.
func UpdateTableColumnProperties ¶ added in v0.4.0
func UpdateTableColumnProperties(table Loc, columns []int, widthPt *float64, even bool) json.RawMessage
UpdateTableColumnProperties sizes the named columns: a fixed width in points, or an even share of the table when even is set.
func UpdateTableRowStyle ¶ added in v0.4.0
func UpdateTableRowStyle(table Loc, rows []int, minHeightPt *float64, preventOverflow *bool) json.RawMessage
UpdateTableRowStyle styles the named rows: a minimum height and whether the row may break across pages. TableRowStyle.tableHeader is in the schema but the API answers "Unallowed field" for it (confirmed live, 2026-09-03); pinTableHeaderRows is how a header row is set.
func UpdateTextStyle ¶
func UpdateTextStyle(r Rng, s TextStyleSpec) json.RawMessage
UpdateTextStyle applies a spec to a range.
func ValidColor ¶
ValidColor reports whether s is "#rrggbb" or "none".
Types ¶
type Anchor ¶
type Anchor struct {
Kind string // comment, suggestion, image, footnote
ID string
Start int64
End int64
Text string
}
Anchor is content inside a range that a deletion would destroy.
type BorderSpec ¶ added in v0.6.0
type BorderSpec struct {
Raw string
}
BorderSpec is one edge as a caller writes it: "1pt solid #cccccc", or "none" to clear it. Tokens come in any order; a missing width is 1pt, a missing dash is solid and a missing colour is black, because the API draws nothing unless all three are set.
type CellLoc ¶ added in v0.2.0
CellLoc names one cell of a table by the table's start index and zero-based row and column.
type CellStyleSpec ¶ added in v0.2.0
type CellStyleSpec struct {
Background string // #rrggbb or none
Align string // TOP, MIDDLE, BOTTOM (contentAlignment)
// PaddingPt sets every side; the four below override one side each.
PaddingPt *float64
PaddingTopPt *float64
PaddingBottomPt *float64
PaddingLeftPt *float64
PaddingRightPt *float64
// Borders take the same shorthand as a paragraph's, minus padding:
// "1pt solid #cccccc", or "none". Border sets all four sides.
Border string
BorderTop string
BorderBottom string
BorderLeft string
BorderRight string
}
CellStyleSpec is a set of table-cell formatting changes.
func (CellStyleSpec) IsZero ¶ added in v0.2.0
func (s CellStyleSpec) IsZero() bool
IsZero reports whether the spec changes nothing.
func (CellStyleSpec) Validate ¶ added in v0.2.0
func (s CellStyleSpec) Validate() error
Validate checks enum and colour values.
type Compiled ¶
type Compiled struct {
Requests []json.RawMessage
Text string
Length int64 // UTF-16 units inserted
// Start and End bound the inserted content (excluding the prefix
// newline, including the suffix newline).
Start int64
End int64
}
Compiled is a fragment laid out at an insertion point.
func CompileFragment ¶
CompileFragment lays a fragment out at `at` and returns the requests: one insertText, a style reset over the whole insertion, paragraph styles, inline styles, and finally list creation in descending order (createParagraphBullets consumes the nesting tabs, so it goes last).
type DateSpec ¶ added in v0.2.0
type DateSpec struct {
Timestamp string // RFC 3339
TimeZoneID string // CLDR id such as Europe/Copenhagen; default UTC
DateFormat string // a DateFormats key; "" for the API default
TimeFormat string // TIME_FORMAT_* enum
}
DateSpec describes a date chip.
type Edit ¶
type Edit struct {
Pos int64
Delete int64 // units to delete at Pos, 0 for pure insert
Insert string
}
Edit is one hunk of a minimal diff, in UTF-16 units of the segment.
func MinimalEdits ¶
MinimalEdits computes the smallest set of edits that turn oldText into newText, positioned relative to start. Unchanged spans keep their formatting and anything anchored to them.
type FragmentOptions ¶
type FragmentOptions struct {
// Prefix puts a newline before the fragment: used when inserting
// before a segment's final newline (append at end).
Prefix bool
// Suffix puts a newline after the fragment: used when inserting at a
// block boundary so the following block stays separate.
Suffix bool
// NearBullet says the paragraph at the insertion point is a list
// item; inserted non-list paragraphs then explicitly drop the bullet
// they would inherit.
NearBullet bool
// Inline says the insertion point is inside an existing paragraph:
// the first fragment paragraph merges into it and keeps its style.
Inline bool
// Fill says the paragraph at an inline insertion point is empty, so
// the first fragment paragraph takes its own style instead.
Fill bool
}
FragmentOptions say how a fragment lands relative to existing text.
type Group ¶ added in v0.3.0
type Group int
Group is an op's place in the compile order.
const ( GroupContent Group = iota // index-ordered content ops, highest index first GroupFormat // formatting first: it shifts nothing GroupBullets // lists after the content that would shift them GroupGlobal // replace_all last GroupSegment // header and footer creation and deletion: no range to overlap )
Groups, in the order compile emits them.
type KindInfo ¶ added in v0.3.0
type KindInfo struct {
Tool Tool
Shape Shape
Content bool // carries a markdown fragment
// Deletes says the op removes existing content, which the overwrite
// guard inspects.
Deletes bool
Group Group
// Structural says the op changes a table's grid, which renumbers rows
// or columns; at most one per table per batch.
Structural bool
// Followup says the op may create something (a segment, a table)
// whose content lands in a second batch once it exists.
Followup bool
// SuggestRefused names the request kind the API refuses in SUGGEST
// mode, when the op compiles to one.
SuggestRefused string
// Reply names the batchUpdate reply an op that creates a segment
// comes back in; the reply carries the new segment's id.
Reply string
// Noun is what the op works on, for messages: "header", "footer",
// "footnote", "table".
Noun string
}
KindInfo is everything the planner, the service and the tools need to know about an op kind apart from its own arithmetic.
type NamedRangeParams ¶ added in v0.4.0
type NamedRangeParams struct {
// Name is the range's name. Several ranges may share one, and every
// one of them is deleted or filled together.
Name string
// ID names exactly one range instead, as a read reports it.
ID string
// Text is the plain text replace_named_range writes over the range.
Text string
}
NamedRangeParams name a range to create, delete or fill.
type NamedStyleSpec ¶ added in v0.4.0
type NamedStyleSpec struct {
Style string // NORMAL_TEXT, TITLE, SUBTITLE, HEADING_1..6
Text TextStyleSpec
Para ParagraphStyleSpec
}
NamedStyleSpec redefines one named style for the whole tab.
func (NamedStyleSpec) IsZero ¶ added in v0.4.0
func (s NamedStyleSpec) IsZero() bool
IsZero reports whether the spec changes nothing.
func (NamedStyleSpec) Validate ¶ added in v0.4.0
func (s NamedStyleSpec) Validate() error
Validate checks the spec on its own.
type ObjectParams ¶ added in v0.2.0
type ObjectParams struct {
Kind string // image, person, rich_link, date
URL string
WidthPt float64
HeightPt float64
Name string
Email string
Title string
Date DateSpec
// ID names the object replace_image and delete_object work on, and
// Positioned says it floats: a positioned object has no range, so it
// is removed by id rather than by deleting the text it sits in.
ID string
Positioned bool
// Crop asks Google to centre-crop the new image into the old one's
// size instead of resizing the frame.
Crop bool
}
ObjectParams describe an insert_object op, and the object an existing image is replaced or removed by.
type Op ¶
type Op struct {
Seq int
Kind OpKind
Seg Segment
Description string
Params
// Target is the affected range for replace, delete and formatting.
Target *Rng
// TargetIsBlock says Target covers whole blocks including the trailing newline.
TargetIsBlock bool
// TargetText is the current text of Target (inline view, no trailing newline).
TargetText string
// TargetAligned is TargetText with every non-text element (chips,
// images, footnote references, breaks) replaced by U+FFFC per UTF-16
// unit, so its offsets line up with the index space. Empty when the
// service could not build it; the minimal diff then needs TargetText
// to be exact.
TargetAligned string
// Insert is the insertion point for insert, append, breaks and footnotes.
Insert *Loc
// AtEnd says the insertion point is the segment's final newline (append form).
AtEnd bool
// Inline says the insertion point is inside a paragraph: the first
// fragment paragraph merges into it and no boundary newline is added.
Inline bool
// Fill says that paragraph is blank, so the first fragment paragraph
// styles it rather than inheriting its style. ClearTo, when greater
// than the insertion point, is the whitespace the fill replaces.
Fill bool
ClearTo int64
// NearBullet says the paragraph at the insertion point is a list item.
NearBullet bool
Fragment *markdown.Fragment
// CommentAnchor is where a comment-mode proposal attaches. Defaults to Target.
CommentAnchor *Rng
Anchors []Anchor
// TableAt is the start of the table a table op works on.
TableAt *Loc
Table TableParams
Object ObjectParams
// SegmentRef names the header or footer a delete_header/delete_footer removes.
SegmentRef string
// Page, Section and NamedStyle carry the layout ops' specs.
Page PageSpec
Section SectionSpec
NamedStyle NamedStyleSpec
// SectionType is what a section_break starts.
SectionType string
// NamedRange names the range a named-range op works on.
NamedRange NamedRangeParams
}
Op is one resolved operation. The service fills in ranges, text and anchors; the planner only does arithmetic. Seq is the caller's op number; several ops may share it when the service expands one caller op (set_cells), and their summaries are then aggregated.
func (*Op) NeedsFollowup ¶
NeedsFollowup reports whether the op creates something whose content is inserted in a second batch: a header, footer or footnote with content, or a table with a data grid.
type OpKind ¶
type OpKind string
OpKind is an operation type.
const ( OpPageSetup OpKind = "page" OpSectionStyle OpKind = "section" OpSectionBreak OpKind = "section_break" OpNamedStyle OpKind = "named_style" )
Layout ops change how a document is laid out rather than what it says: the page itself, one section of it, and the named styles every paragraph inherits from.
const ( OpInsert OpKind = "insert" OpAppend OpKind = "append" OpReplace OpKind = "replace" OpDelete OpKind = "delete" OpReplaceAll OpKind = "replace_all" OpPageBreak OpKind = "insert_break" OpCreateHeader OpKind = "create_header" OpFootnote OpKind = "insert_footnote" )
Content operations (edit_document).
const ( OpTextStyle OpKind = "text_style" OpParagraphStyle OpKind = "paragraph_style" OpBullets OpKind = "bullets" OpClearFormatting OpKind = "clear_formatting" )
Formatting operations (format_document).
const ( OpCreateNamedRange OpKind = "create_named_range" OpDeleteNamedRange OpKind = "delete_named_range" OpReplaceNamedRange OpKind = "replace_named_range" )
Named-range ops. A named range is the one anchor that survives an edit: Google moves it with the text it covers, where a handle is only valid for the revision it came from.
const ( OpInsertTable OpKind = "insert_table" OpSetCells OpKind = "set_cells" OpInsertRows OpKind = "insert_rows" OpDeleteRows OpKind = "delete_rows" OpInsertColumns OpKind = "insert_columns" OpDeleteColumns OpKind = "delete_columns" OpMergeCells OpKind = "merge_cells" OpUnmergeCells OpKind = "unmerge_cells" OpStyleCells OpKind = "style_cells" OpPinHeaderRows OpKind = "pin_header_rows" OpDeleteHeader OpKind = "delete_header" OpStyleColumns OpKind = "style_columns" OpStyleRows OpKind = "style_rows" OpInsertObject OpKind = "insert_object" OpReplaceImage OpKind = "replace_image" OpDeleteObject OpKind = "delete_object" )
Table operations (edit_table). set_cells is expanded by the service into replace ops on cells and never reaches the planner.
type OpSummary ¶
type OpSummary struct {
Seq int `json:"op"`
Kind OpKind `json:"kind"`
Description string `json:"target"`
Requests int `json:"requests"`
Minimal bool `json:"minimal_diff,omitempty"`
}
OpSummary describes what an op compiled to.
type PageMargins ¶ added in v0.4.0
PageMargins are the margin fields a page and a section share, in the order the API names them.
type PageSpec ¶ added in v0.4.0
type PageSpec struct {
WidthPt float64
HeightPt float64
PageMargins
MarginHeaderPt *float64
Background string
PageNumberStart *int
Landscape *bool
}
PageSpec is a change to a tab's page setup.
type ParagraphStyleSpec ¶
type ParagraphStyleSpec struct {
NamedStyle string // NORMAL_TEXT, HEADING_1..6, TITLE, SUBTITLE
Alignment string // START, CENTER, END, JUSTIFIED
Direction string // LEFT_TO_RIGHT, RIGHT_TO_LEFT
SpacingMode string // NEVER_COLLAPSE, COLLAPSE_LISTS
LineSpacing float64
SpaceAbovePt *float64
SpaceBelowPt *float64
IndentStartPt *float64
IndentEndPt *float64
IndentFirstLine *float64
KeepWithNext *bool
// Shading is the paragraph background, #rrggbb or "none".
Shading string
// Borders are the shorthand strings; Border replaces every side.
Border string
BorderTop string
BorderBottom string
BorderLeft string
BorderRight string
BorderBetween string
BorderPaddingPt *float64
KeepLinesTogether *bool
AvoidWidowAndOrphan *bool
PageBreakBefore *bool
}
ParagraphStyleSpec is a set of paragraph-formatting changes.
func (ParagraphStyleSpec) IsZero ¶
func (s ParagraphStyleSpec) IsZero() bool
IsZero reports whether the spec changes nothing.
func (ParagraphStyleSpec) Validate ¶
func (s ParagraphStyleSpec) Validate() error
Validate checks enum values.
type Params ¶
type Params struct {
Find string
Replace string
MatchCase bool
Text TextStyleSpec
Para ParagraphStyleSpec
Bullets string // bullet, numbered, checkbox, none
}
Params are the caller-supplied arguments an op carries unchanged from the tool layer to the planner.
type Result ¶
type Result struct {
Requests []json.RawMessage
Proposals []Proposal
// Followups are the ops whose content lands in a second batch once
// the first has created its home: a new header, footer or footnote
// (the reply names the segment) or a table inserted with a data grid
// (found again by the handle its position predicts).
Followups []*Op
Warnings []string
Summary []OpSummary
}
Result is a plan.
type SectionSpec ¶ added in v0.4.0
type SectionSpec struct {
PageMargins
Columns int
ColumnGapPt *float64
ColumnSeparator string // none or between
ContentDirection string // LEFT_TO_RIGHT or RIGHT_TO_LEFT
PageNumberStart *int
Landscape *bool
}
SectionSpec is a change to one section: its columns, its own margins, and where its page numbering starts. It carries no section type: SectionStyle.sectionType is output only, so a section is continuous or starts a page according to the break that made it.
func (SectionSpec) IsZero ¶ added in v0.4.0
func (s SectionSpec) IsZero() bool
IsZero reports whether the spec changes nothing.
func (SectionSpec) Validate ¶ added in v0.4.0
func (s SectionSpec) Validate() error
Validate checks the spec on its own.
type Segment ¶
Segment describes the index space an op works in. Start is the first index content can occupy (after the leading section break), End is the segment's end index (one past its final newline).
type Shape ¶ added in v0.3.0
type Shape int
Shape says what an op must carry to be planned.
const ( ShapeNone Shape = iota // nothing positional: replace_all, create_header, create_footer ShapeTarget // Target: replace, delete, formatting ShapeInsert // Insert: insert, append, breaks, footnotes, objects, insert_table ShapeTable // TableAt: grid and cell ops ShapeSegment // SegmentRef: delete_header, delete_footer ShapeTab // nothing but the tab: page setup, named styles, objects by id )
Shapes.
type TabProperties ¶ added in v0.2.0
TabProperties are the mutable properties of a tab.
type TableParams ¶ added in v0.2.0
type TableParams struct {
Rows, Cols int // insert_table size; table size for other ops
Row, Col int // reference cell
Count int
Before bool // insert above / to the left
Indices []int // rows or columns to delete
RowSpan int
ColSpan int
Cell CellStyleSpec
HeaderRows int
// Data is the grid an insert_table fills after the table exists.
Data [][]string
// WidthPt and Even size the columns style_columns names; Even
// distributes them and takes no width.
WidthPt *float64
Even bool
// MinHeightPt and PreventOverflow style the rows style_rows names.
MinHeightPt *float64
PreventOverflow *bool
}
TableParams are the resolved arguments of a table op. Row and column numbers are zero-based here; the service converts from the 1-based numbers people use.
type TextStyleSpec ¶
type TextStyleSpec struct {
Bold *bool
Italic *bool
Underline *bool
Strikethrough *bool
SmallCaps *bool
Font string
SizePt float64
Foreground string
Background string
Link string
Baseline string // SUPERSCRIPT, SUBSCRIPT, NONE
}
TextStyleSpec is a set of character-formatting changes. Nil pointers and empty strings mean "leave as is"; the string "none" clears a font, colour or link.
func (TextStyleSpec) IsZero ¶
func (s TextStyleSpec) IsZero() bool
IsZero reports whether the spec changes nothing.
func (TextStyleSpec) Validate ¶
func (s TextStyleSpec) Validate() error
Validate checks enum and colour values.