Documentation ¶
Overview ¶
Package data impleements data structures for use with rich text
Index ¶
- type BlockQuote
- type Col
- type Cols
- type Dir
- type FontStyle
- type FontWeight
- type Heading
- type Image
- type Link
- type List
- type Ref
- type Row
- type Rows
- type Table
- func (t *Table) AppendCol(col Col) changes.Change
- func (t Table) AppendRow(row Row) changes.Change
- func (t *Table) Apply(ctx changes.Context, c changes.Change) changes.Value
- func (t *Table) ColIDs() []interface{}
- func (t *Table) DeleteCol(colID interface{}) changes.Change
- func (t *Table) DeleteRow(rowID interface{}) changes.Change
- func (t *Table) InsertColBefore(col Col, beforeCol Col) changes.Change
- func (t *Table) InsertRowBefore(row Row, beforeRow Row) changes.Change
- func (t *Table) Name() string
- func (t *Table) RowIDs() []interface{}
- func (t Table) SetCellValue(rowID, colID interface{}, r *rich.Text) changes.Change
- func (t *Table) UpdateCellValue(rowID, colID interface{}, c changes.Change) changes.Change
- func (t Table) UpdateCol(colID interface{}, c changes.Change) changes.Change
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockQuote ¶
BlockQuote represents a block quote with any embedded content
type Col ¶
Col represents the information about the column.
The ID field is immutable. The Ord field is meant to help sort the columns and is not meant to be directly modified by the application. Instead, Table methods can be used to effectively manipulate these.
The value field tracks the actual heading/name for the column and should not be nil.
type Dir ¶
Dir wraps a value along with a map of objects. The contents of the value can refer to entries in the map using Ref
type FontStyle ¶
type FontStyle string
FontStyle is CSS font-style
const ( FontStyleNormal FontStyle = "normal" FontStyleItalic FontStyle = "italic" FontStyleOblique FontStyle = "oblique" )
FontStyle values
type FontWeight ¶
type FontWeight int
FontWeight is CSS font-weight
const ( FontThin FontWeight = 100 * (iota + 1) FontExtraLight FontLight FontNormal FontMedium FontSemibold FontBold FontExtraBold FontBlack )
FontWeight constants
type Heading ¶
Heading represents h1 to h6.
Note that the contents of the heading tag can be any rich text.
type List ¶
List represents an ordered or unordered list
The type can be one of the string values defined here: https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type
(such as disc, circle etc)
type Ref ¶
type Ref struct {
ID interface{}
}
Ref represents a refereence to an embedded object storeed in a Dir. The Dir must be an ancestor of the Ref
type Row ¶
Row represents the information about a row
The ID field is immutable. The Ord field is meant to help sort the rows and is not meant to be directly modified by the application. Instead, Table methods can be used to effectively manipulate these.
The Cells field contains a map of Column.ID to actual cell value
type Table ¶
Table represents a table with named columns and rows
This is an immutable type and all mutation methods (like AppendCol) return changes.Change (which can be applied to get the new Table)
The rows and columns are stored in a map structure but ordered IDs can be obtained via RowIDs and ColIDs
Example ¶
package main import ( "fmt" "strings" "github.com/dotchain/dot/x/rich" "github.com/dotchain/dot/x/rich/data" ) func main() { t := &data.Table{} col1, col2 := rich.NewText("col1"), rich.NewText("col2") t = t.Apply(nil, t.AppendCol(data.Col{ID: "col2", Value: col2})).(*data.Table) t = t.Apply(nil, t.InsertColBefore(data.Col{ID: "col1", Value: col1}, *t.Cols["col2"])).(*data.Table) t = t.Apply(nil, t.AppendRow(data.Row{ID: "row1"})).(*data.Table) t = t.Apply(nil, t.SetCellValue("row1", "col1", rich.NewText("1-1"))).(*data.Table) t = t.Apply(nil, t.SetCellValue("row1", "col2", rich.NewText("1-2"))).(*data.Table) fmt.Println(tableToText(t)) } func tableToText(t *data.Table) string { lines := []string{} colIDs := t.ColIDs() for _, rowID := range t.RowIDs() { cells := []string{} r := *t.Rows[rowID] for _, colID := range colIDs { cell := "" if v, ok := r.Cells[colID]; ok { cell = v.(*rich.Text).PlainText() } cells = append(cells, cell) } lines = append(lines, strings.Join(cells, " ")) } return strings.Join(lines, "\n") }
Output: 1-1 1-2
func (*Table) AppendCol ¶
AppendCol adds a new column to the end of the sorted list.
The column can already exist in which case it is simply moved.
func (Table) AppendRow ¶
AppendRow adds a new row to the end of the sorted list.
The row can already exist in which case it is simply moved.
func (*Table) ColIDs ¶
func (t *Table) ColIDs() []interface{}
ColIDs returns all the column IDs sorted in order
func (*Table) InsertColBefore ¶
InsertColBefore inserts a new column before another
The column may already exist in which case it is simply moved
func (*Table) InsertRowBefore ¶
InsertRowBefore inserts a new row before another
The row may already exist in which case it is simply moved
func (*Table) RowIDs ¶
func (t *Table) RowIDs() []interface{}
RowIDs returns all the row IDs sorted in order
func (Table) SetCellValue ¶
SetCellValue sets the rich text for a cell. It works for rows which don't have values for specific columns as well as rows where the columns have a value already.
func (*Table) UpdateCellValue ¶
UpdateCellValue takes a change meant for a cell value and wraps it with the path of the column -- the resulting change can be applied directly on the table.
Note that the cell must exist (i.e the row must have a entry for the colID)