Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cell ¶
type Cell struct {
Raw string `json:"raw"`
Value string `json:"value,omitempty"`
ValueType string `json:"valueType,omitempty"`
StyleId int `json:"styleId"`
}
Cell is the atomic unit of a sheet. Raw is the source of truth (a literal value or a formula string like "=SUM(A1:A10)"). Value/ValueType are an optional client-reported cache of the computed result; the backend core never computes them. StyleId references the workbook StylePool.
type CellRef ¶
CellRef is a zero-based (row, col) address within a single sheet. It is a comparable struct so it can be used directly as a map key.
type CellSnapshot ¶
type CellSnapshot struct {
Row int `json:"row"`
Col int `json:"col"`
Raw string `json:"raw"`
Value string `json:"value,omitempty"`
ValueType string `json:"valueType,omitempty"`
StyleId int `json:"styleId,omitempty"`
}
CellSnapshot is the serializable form of one populated cell (map keys can't be JSON-encoded, so cells become a flat slice).
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is the authoritative server-side state for one sheet document: the current Workbook, a monotonically growing op-log, and the head revision. It is NOT goroutine-safe; the per-document serialization goroutine (plan 2c) provides the total order, exactly as the text pad channel does.
func NewDocument ¶
func NewDocumentAt ¶
NewDocumentAt builds a Document whose workbook is already materialized to the end of log; head becomes len(log). Used when loading a persisted document (workbook from the snapshot, log from sheet_op) so stale-op rebasing keeps working after a server restart.
type Op ¶
type Op struct {
Type OpType `json:"type"`
Sheet string `json:"sheet"`
BaseRev int `json:"baseRev"`
// Cell ops (setCell, setStyle) and the top-left of a range (clearRange).
Row int `json:"row,omitempty"`
Col int `json:"col,omitempty"`
// Range end (inclusive) for clearRange.
EndRow int `json:"endRow,omitempty"`
EndCol int `json:"endCol,omitempty"`
// setCell payload (pointers so "unset" is distinguishable from empty).
Raw *string `json:"raw,omitempty"`
Value *string `json:"value,omitempty"`
ValueType *string `json:"valueType,omitempty"`
// setCell + setStyle payload.
StyleId *int `json:"styleId,omitempty"`
// setCell + setStyle: style properties to intern into the workbook StylePool.
// When present, Apply interns them and sets the cell's StyleId to the result.
Props map[string]string `json:"props,omitempty"`
// Structural ops (insert/delete rows/cols). Index doubles as the insertion
// position for addSheet.
Index int `json:"index,omitempty"`
Count int `json:"count,omitempty"`
// Sheet-list ops.
Name string `json:"name,omitempty"` // addSheet, renameSheet
ToIndex int `json:"toIndex,omitempty"` // moveSheet
// setDimension.
Axis string `json:"axis,omitempty"` // "col" or "row"
Size int `json:"size,omitempty"` // px
// setFreeze. 0 or 1 each (freeze first row / first col only for now).
FrozenRows int `json:"frozenRows,omitempty"`
FrozenCols int `json:"frozenCols,omitempty"`
}
Op is one cell-based operation. BaseRev is the workbook revision the client composed it against (used by the server to rebase stale ops). Payload fields are optional per type.
func Transform ¶
Transform adjusts `in` so it applies cleanly after `applied`, where both were originally composed against the same base revision and `applied` was ordered first by the server. Only structural ops (row/col insert/delete) on the same sheet and axis move coordinates; everything else is returned unchanged.
type OpType ¶
type OpType string
const ( OpSetCell OpType = "setCell" OpSetStyle OpType = "setStyle" OpClearRange OpType = "clearRange" OpInsertRows OpType = "insertRows" OpDeleteRows OpType = "deleteRows" OpInsertCols OpType = "insertCols" OpDeleteCols OpType = "deleteCols" // Sheet-list ops: Op.Sheet names the target sheet id. OpAddSheet OpType = "addSheet" OpRenameSheet OpType = "renameSheet" OpDeleteSheet OpType = "deleteSheet" OpMoveSheet OpType = "moveSheet" // Grid metadata ops. OpSetDimension OpType = "setDimension" OpSetFreeze OpType = "setFreeze" )
type Sheet ¶
type Sheet struct {
Id string `json:"id"`
Name string `json:"name"`
Cells map[CellRef]Cell `json:"-"` // sparse; JSON handled by the snapshot/persistence layer
// Sparse per-index pixel overrides; unset = view default.
ColWidths map[int]int `json:"-"`
RowHeights map[int]int `json:"-"`
// 0 or 1 each: freeze the first row / first col (position: sticky in the view).
FrozenRows int `json:"-"`
FrozenCols int `json:"-"`
}
Sheet is a single tab: sparse cells plus structural metadata.
type SheetSnapshot ¶
type SheetSnapshot struct {
Id string `json:"id"`
Name string `json:"name"`
Cells []CellSnapshot `json:"cells"`
// Sparse dimension overrides; JSON object keys are stringified indices.
ColWidths map[int]int `json:"colWidths,omitempty"`
RowHeights map[int]int `json:"rowHeights,omitempty"`
FrozenRows int `json:"frozenRows,omitempty"`
FrozenCols int `json:"frozenCols,omitempty"`
}
type Style ¶
Style is a set of formatting properties (e.g. numFmt, bold, color, align, border). Kept as a string->string map so the pool stays format-agnostic.
type StylePool ¶
type StylePool struct {
IdToStyle map[int]Style `json:"idToStyle"`
NextId int `json:"nextId"`
// contains filtered or unexported fields
}
StylePool deduplicates styles per workbook. Id 0 is reserved for the empty style; cells default to it.
func NewStylePool ¶
func NewStylePool() *StylePool
type Workbook ¶
Workbook is the full document: ordered sheets plus the shared StylePool.
func NewWorkbook ¶
func NewWorkbook() *Workbook
func WorkbookFromSnapshot ¶
func WorkbookFromSnapshot(snap WorkbookSnapshot) *Workbook
WorkbookFromSnapshot rebuilds a Workbook (and its StylePool dedup index) from a deserialized snapshot.
func (*Workbook) Apply ¶
Apply mutates the workbook by op. The op is assumed already rebased to the current revision (see reconcile.go). Cell ops are last-writer-wins; the caller's total ordering decides the winner.
func (*Workbook) Snapshot ¶
func (w *Workbook) Snapshot() WorkbookSnapshot
Snapshot converts the workbook to its serializable form. Cells are emitted in (row, col) order for deterministic output.
type WorkbookSnapshot ¶
type WorkbookSnapshot struct {
Sheets []SheetSnapshot `json:"sheets"`
Styles *StylePool `json:"styles"`
}
WorkbookSnapshot is the JSON-serializable form of a Workbook for persistence.