Documentation
¶
Overview ¶
Package richeditor is a rich text editor after ProseMirror's architecture (NSH's RichEditor, nsh/docs/dev/rich-editor.md): a document whose structure a Schema defines, changes as invertible, mappable steps grouped into transactions, immutable states, commands and plugins. The kernel depends on no view and is tested on its own; View renders its states.
Positions count as ProseMirror's do: a text its UTF-16 code units, a leaf node one, a node with content its two boundaries.
The kernel is a port of ProseMirror's (MIT, © Marijn Haverbeke and others) and the extension layer follows Tiptap's (MIT, © Tiptap GmbH), whose structures, algorithms and names it keeps; see NOTICE.
Index ¶
- Constants
- Variables
- func BaseKeymap() map[string]Command
- func CanJoin(doc *Node, pos int) bool
- func CanSplit(doc *Node, pos, depth int, typesAfter []NodeTypeAttrs) bool
- func Characters(s *State, nodes bool) int
- func ColumnWidths(table *Node) []float64
- func CreateParagraphNear(s *State, dispatch func(*Transaction)) bool
- func DeleteCellSelection(s *State, dispatch func(*Transaction)) bool
- func DeleteSelection(s *State, dispatch func(*Transaction)) bool
- func DeleteTable(s *State, dispatch func(*Transaction)) bool
- func DocJSONString(n *Node) string
- func DragSource(s *State, pos int) (from, to int, ok bool)
- func ExitCode(s *State, dispatch func(*Transaction)) bool
- func FindParentNode(s *State, pred func(*Node) bool) int
- func GapCursorValid(r *ResolvedPos) bool
- func GoToNextCellOrAddRow(s *State, dispatch func(*Transaction)) bool
- func InsertCells(s *State, dispatch func(*Transaction), tableStart int, rect Rect, ...)
- func InsertPoint(doc *Node, pos int, typ *NodeType) int
- func IsActive(s *State, name string, attrs Attrs) bool
- func IsAllowedURI(href string, protocols []string) bool
- func IsMarkActive(s *State, t *MarkType, attrs Attrs) bool
- func IsNodeActive(s *State, t *NodeType, attrs Attrs) bool
- func JoinBackward(s *State, dispatch func(*Transaction)) bool
- func JoinForward(s *State, dispatch func(*Transaction)) bool
- func JoinPoint(doc *Node, pos, dir int) int
- func Lift(s *State, dispatch func(*Transaction)) bool
- func LiftEmptyBlock(s *State, dispatch func(*Transaction)) bool
- func LiftTarget(r *NodeRange) int
- func MarkRange(r *ResolvedPos, t *MarkType) (from, to int, ok bool)
- func MergeBindings(maps ...map[string]Command) map[string]Command
- func MergeCells(s *State, dispatch func(*Transaction)) bool
- func NewlineInCode(s *State, dispatch func(*Transaction)) bool
- func NodeJSON(n *Node) map[string]any
- func PlainText(doc *Node) string
- func RedoDepth(s *State) int
- func SelectAll(s *State, dispatch func(*Transaction)) bool
- func SelectNodeBackward(s *State, dispatch func(*Transaction)) bool
- func SelectNodeForward(s *State, dispatch func(*Transaction)) bool
- func SelectParentNode(s *State, dispatch func(*Transaction)) bool
- func SelectionPosNext(r *ResolvedPos, dir int) int
- func SliceToText(s *Slice) string
- func SplitBlock(s *State, dispatch func(*Transaction)) bool
- func SplitCell(s *State, dispatch func(*Transaction)) bool
- func UndoDepth(s *State) int
- func UndoInputRule(s *State, dispatch func(*Transaction)) bool
- func Words(s *State) int
- func WriteHTML(n *Node) string
- func WriteMarkdown(doc *Node) string
- type AddMarkStep
- type AllSelection
- func (s *AllSelection) Anchor() int
- func (s *AllSelection) AnchorPos() *ResolvedPos
- func (s *AllSelection) Bookmark() Bookmark
- func (s *AllSelection) Content() *Slice
- func (s *AllSelection) Empty() bool
- func (s *AllSelection) Eq(o Selection) bool
- func (s *AllSelection) From() int
- func (s *AllSelection) FromPos() *ResolvedPos
- func (s *AllSelection) Head() int
- func (s *AllSelection) HeadPos() *ResolvedPos
- func (s *AllSelection) Map(doc *Node, _ Mappable) Selection
- func (s *AllSelection) Ranges() []SelectionRange
- func (s *AllSelection) Replace(tr *Transaction, content *Slice)
- func (s *AllSelection) ReplaceWith(tr *Transaction, node *Node)
- func (s *AllSelection) To() int
- func (s *AllSelection) ToPos() *ResolvedPos
- type AttrSpec
- type AttrStep
- type Attrs
- type Bookmark
- type Built
- type CellArea
- type CellRect
- type CellSelection
- func (s *CellSelection) Anchor() int
- func (s *CellSelection) AnchorPos() *ResolvedPos
- func (s *CellSelection) Bookmark() Bookmark
- func (s *CellSelection) Content() *Slice
- func (s *CellSelection) Empty() bool
- func (s *CellSelection) Eq(o Selection) bool
- func (s *CellSelection) From() int
- func (s *CellSelection) FromPos() *ResolvedPos
- func (s *CellSelection) Head() int
- func (s *CellSelection) HeadPos() *ResolvedPos
- func (s *CellSelection) IsColSelection() bool
- func (s *CellSelection) IsRowSelection() bool
- func (s *CellSelection) Map(doc *Node, m Mappable) Selection
- func (s *CellSelection) Ranges() []SelectionRange
- func (s *CellSelection) Replace(tr *Transaction, content *Slice)
- func (s *CellSelection) ReplaceWith(tr *Transaction, node *Node)
- func (s *CellSelection) To() int
- func (s *CellSelection) ToPos() *ResolvedPos
- type CharacterCountOptions
- type Classes
- type Command
- func Chain(cmds ...Command) Command
- func ChainCommands(cmds ...Command) Command
- func ExitSuggestion(key string) Command
- func GoToNextCell(dir int) Command
- func InsertHardBreak(t *NodeType) Command
- func InsertMention(t *NodeType, key string, attrs Attrs) Command
- func InsertTable(rows, cols int, withHeader bool) Command
- func LiftListItem(itemType *NodeType) Command
- func MoveBlocks(from, to, target int) Command
- func MoveTableColumn(from, to, tablePos int) Command
- func MoveTableRow(from, to, tablePos int) Command
- func SetBlockType(t *NodeType, attrs Attrs) Command
- func SetCellSelection(anchor, head int) Command
- func SetColumnWidth(col int, width float64, tablePos int) Command
- func SetLink(t *MarkType, href string, protocols []string) Command
- func SetMark(t *MarkType, attrs Attrs) Command
- func SetRowHeight(row int, height float64, tablePos int) Command
- func ShiftArrow(axis string, dir int) Command
- func SinkListItem(itemType *NodeType) Command
- func SplitListItem(itemType *NodeType, itemAttrs Attrs) Command
- func ToggleBlockType(t *NodeType, attrs Attrs) Command
- func ToggleList(t, item *NodeType) Command
- func ToggleMark(t *MarkType, attrs Attrs) Command
- func ToggleWrap(t *NodeType, attrs Attrs) Command
- func UnsetMark(t *MarkType) Command
- func UpdateAttributes(t *NodeType, attrs Attrs) Command
- func WrapIn(t *NodeType, attrs Attrs) Command
- func WrapInList(listType *NodeType, attrs Attrs) Command
- type CommandFactory
- type ContentMatch
- func (m *ContentMatch) Edge(n int) (*NodeType, *ContentMatch)
- func (m *ContentMatch) EdgeCount() int
- func (m *ContentMatch) FillBefore(after *Fragment, toEnd bool, start int) *Fragment
- func (m *ContentMatch) FindWrapping(target *NodeType) []*NodeType
- func (m *ContentMatch) MatchFragment(frag *Fragment, start, end int) *ContentMatch
- func (m *ContentMatch) MatchType(t *NodeType) *ContentMatch
- type Decoration
- type Extension
- type FoundLink
- type Fragment
- func (f *Fragment) AddToEnd(node *Node) *Fragment
- func (f *Fragment) AddToStart(node *Node) *Fragment
- func (f *Fragment) Append(o *Fragment) *Fragment
- func (f *Fragment) Child(i int) *Node
- func (f *Fragment) ChildCount() int
- func (f *Fragment) Cut(from, to int) *Fragment
- func (f *Fragment) CutByIndex(from, to int) *Fragment
- func (f *Fragment) Descendants(fn func(*Node, int, *Node, int) bool)
- func (f *Fragment) Eq(o *Fragment) bool
- func (f *Fragment) FirstChild() *Node
- func (f *Fragment) LastChild() *Node
- func (f *Fragment) MaybeChild(i int) *Node
- func (f *Fragment) NodesBetween(from, to int, fn func(*Node, int, *Node, int) bool, start int, parent *Node)
- func (f *Fragment) ReplaceChild(i int, node *Node) *Fragment
- func (f *Fragment) String() string
- func (f *Fragment) TextBetween(from, to int, blockSep, leafText string) string
- type GapCursor
- func (s *GapCursor) Anchor() int
- func (s *GapCursor) AnchorPos() *ResolvedPos
- func (s *GapCursor) Bookmark() Bookmark
- func (s *GapCursor) Content() *Slice
- func (s *GapCursor) Empty() bool
- func (s *GapCursor) Eq(o Selection) bool
- func (s *GapCursor) From() int
- func (s *GapCursor) FromPos() *ResolvedPos
- func (s *GapCursor) Head() int
- func (s *GapCursor) HeadPos() *ResolvedPos
- func (s *GapCursor) Map(doc *Node, m Mappable) Selection
- func (s *GapCursor) Ranges() []SelectionRange
- func (s *GapCursor) Replace(tr *Transaction, content *Slice)
- func (s *GapCursor) ReplaceWith(tr *Transaction, node *Node)
- func (s *GapCursor) To() int
- func (s *GapCursor) ToPos() *ResolvedPos
- type Geometry
- type GlobalAttrs
- type HistoryOptions
- type HistoryState
- type InputRule
- func MarkInputRule(re *regexp.Regexp, t *MarkType, attrs func(match []string) Attrs) InputRule
- func TextInputRule(re *regexp.Regexp, text string) InputRule
- func TextblockTypeInputRule(re *regexp.Regexp, t *NodeType, attrs func(match []string) Attrs) InputRule
- func WrappingInputRule(re *regexp.Regexp, t *NodeType, attrs func(match []string) Attrs, ...) InputRule
- type LinkOptions
- type MapResult
- type Mappable
- type Mapping
- func (m *Mapping) AppendMap(sm *StepMap, mirrors int)
- func (m *Mapping) AppendMapping(o *Mapping)
- func (m *Mapping) AppendMappingInverted(o *Mapping)
- func (m *Mapping) GetMirror(n int) int
- func (m *Mapping) Invert() *Mapping
- func (m *Mapping) Map(pos, assoc int) int
- func (m *Mapping) MapResult(pos, assoc int) MapResult
- func (m *Mapping) Slice(from, to int) *Mapping
- type Mark
- type MarkSpec
- type MarkType
- type MentionOptions
- type Node
- func (n *Node) AttrNum(name string) float64
- func (n *Node) AttrStr(name string) string
- func (n *Node) CanAppend(o *Node) bool
- func (n *Node) CanReplace(from, to int, replacement *Fragment, start, end int) bool
- func (n *Node) CanReplaceWith(from, to int, t *NodeType, marks []*Mark) bool
- func (n *Node) Check() error
- func (n *Node) Child(i int) *Node
- func (n *Node) ChildCount() int
- func (n *Node) Copy(content *Fragment) *Node
- func (n *Node) Cut(from, to int) *Node
- func (n *Node) Descendants(f func(node *Node, pos int, parent *Node, index int) bool)
- func (n *Node) Eq(o *Node) bool
- func (n *Node) FirstChild() *Node
- func (n *Node) HasMarkup(t *NodeType, attrs Attrs, marks []*Mark) bool
- func (n *Node) InlineContent() bool
- func (n *Node) IsAtom() bool
- func (n *Node) IsBlock() bool
- func (n *Node) IsInline() bool
- func (n *Node) IsLeaf() bool
- func (n *Node) IsText() bool
- func (n *Node) IsTextblock() bool
- func (n *Node) LastChild() *Node
- func (n *Node) Mark(marks []*Mark) *Node
- func (n *Node) MaybeChild(i int) *Node
- func (n *Node) NodeAt(pos int) *Node
- func (n *Node) NodeSize() int
- func (n *Node) NodesBetween(from, to int, f func(node *Node, pos int, parent *Node, index int) bool, ...)
- func (n *Node) RangeHasMark(from, to int, m *MarkType) bool
- func (n *Node) Replace(from, to int, slice *Slice) (*Node, error)
- func (n *Node) Resolve(pos int) *ResolvedPos
- func (n *Node) SameMarkup(o *Node) bool
- func (n *Node) Slice(from, to int, includeParents bool) *Slice
- func (n *Node) String() string
- func (n *Node) TextBetween(from, to int, blockSep, leafText string) string
- func (n *Node) TextContent() string
- func (n *Node) WithText(text string) *Node
- type NodeProps
- type NodeRange
- type NodeSelection
- func (s *NodeSelection) Anchor() int
- func (s *NodeSelection) AnchorPos() *ResolvedPos
- func (s *NodeSelection) Bookmark() Bookmark
- func (s *NodeSelection) Content() *Slice
- func (s *NodeSelection) Empty() bool
- func (s *NodeSelection) Eq(o Selection) bool
- func (s *NodeSelection) From() int
- func (s *NodeSelection) FromPos() *ResolvedPos
- func (s *NodeSelection) Head() int
- func (s *NodeSelection) HeadPos() *ResolvedPos
- func (s *NodeSelection) Map(doc *Node, m Mappable) Selection
- func (s *NodeSelection) Ranges() []SelectionRange
- func (s *NodeSelection) Replace(tr *Transaction, content *Slice)
- func (s *NodeSelection) ReplaceWith(tr *Transaction, node *Node)
- func (s *NodeSelection) To() int
- func (s *NodeSelection) ToPos() *ResolvedPos
- type NodeSpec
- type NodeType
- func (t *NodeType) AllowsMarkType(m *MarkType) bool
- func (t *NodeType) AllowsMarks(marks []*Mark) bool
- func (t *NodeType) Create(attrs Attrs, content *Fragment, marks []*Mark) *Node
- func (t *NodeType) CreateAndFill(attrs Attrs, content *Fragment, marks []*Mark) *Node
- func (t *NodeType) IsAtom() bool
- func (t *NodeType) IsBlock() bool
- func (t *NodeType) IsInline() bool
- func (t *NodeType) IsLeaf() bool
- func (t *NodeType) IsText() bool
- func (t *NodeType) IsTextblock() bool
- func (t *NodeType) ValidContent(content *Fragment) bool
- type NodeTypeAttrs
- type NodeView
- type Origin
- type Plugin
- type Rect
- type Rect2
- type Ref
- type RemoveMarkStep
- type ReplaceAroundStep
- type ReplaceStep
- type ResolvedPos
- func (r *ResolvedPos) After(d int) int
- func (r *ResolvedPos) Before(d int) int
- func (r *ResolvedPos) BlockRange(other *ResolvedPos, pred func(*Node) bool) *NodeRange
- func (r *ResolvedPos) Doc() *Node
- func (r *ResolvedPos) End(d int) int
- func (r *ResolvedPos) Index(d int) int
- func (r *ResolvedPos) IndexAfter(d int) int
- func (r *ResolvedPos) MarksAcross(end *ResolvedPos) []*Mark
- func (r *ResolvedPos) MarksHere() []*Mark
- func (r *ResolvedPos) Node(d int) *Node
- func (r *ResolvedPos) NodeAfter() *Node
- func (r *ResolvedPos) NodeBefore() *Node
- func (r *ResolvedPos) Parent() *Node
- func (r *ResolvedPos) PosAtIndex(index, d int) int
- func (r *ResolvedPos) SameParent(o *ResolvedPos) bool
- func (r *ResolvedPos) SharedDepth(pos int) int
- func (r *ResolvedPos) Start(d int) int
- func (r *ResolvedPos) TextOffset() int
- type Schema
- type SchemaSpec
- type Selection
- func SelectionAtEnd(doc *Node) Selection
- func SelectionAtStart(doc *Node) Selection
- func SelectionFindFrom(pos *ResolvedPos, dir int, textOnly bool) Selection
- func SelectionFindFromOrNear(pos *ResolvedPos, dir int) Selection
- func SelectionNear(pos *ResolvedPos, bias int) Selection
- func TextSelectionAt(doc *Node, anchor, head int) Selection
- func TextSelectionBetween(anchor, head *ResolvedPos, bias int) Selection
- type SelectionRange
- type Session
- func (v *Session) Apply(tr *Transaction) error
- func (v *Session) Blur()
- func (v *Session) Can(c Command) bool
- func (v *Session) CanNamed(name string, args Attrs) bool
- func (v *Session) Command(name string, args Attrs) Command
- func (v *Session) CoordsAtPos(pos int) (Rect2, bool)
- func (v *Session) Copy() (text, html string)
- func (v *Session) Cut() (text, html string)
- func (v *Session) Dispatch(tr *Transaction)
- func (v *Session) DragBlock(pos int, x, y float64) bool
- func (v *Session) DragTo(x, y float64)
- func (v *Session) Editable() bool
- func (v *Session) EndDrag() bool
- func (v *Session) Focus()
- func (v *Session) HTML() string
- func (v *Session) HandleKey(name string) bool
- func (v *Session) IsActive(name string, attrs Attrs) bool
- func (v *Session) JSON() string
- func (v *Session) Markdown() string
- func (v *Session) MoveChar(dir int, extend bool)
- func (v *Session) MoveWord(dir int, extend bool)
- func (v *Session) OpenGap() bool
- func (v *Session) PageCoordsAtPos(pos int) (Rect2, bool)
- func (v *Session) Paste(text, html string)
- func (v *Session) PosAtCoords(x, y float64) (int, bool)
- func (v *Session) PosAtPageCoords(x, y float64) (int, bool)
- func (v *Session) Run(c Command) bool
- func (v *Session) RunNamed(name string, args Attrs) bool
- func (v *Session) SelectionRect() (Rect2, bool)
- func (v *Session) SetContent(doc *Node)
- func (v *Session) SetEditable(on bool)
- func (v *Session) State() *State
- func (v *Session) Subscribe(f func(s *State, trs []*Transaction)) func()
- func (v *Session) Text() string
- func (v *Session) TypeText(text string, composition any)
- func (v *Session) UpdateState(s *State)
- type SessionConfig
- type Slice
- type StarterOptions
- type State
- type StateConfig
- type StateError
- type Step
- type StepMap
- type Styles
- type SuggestionOptions
- type SuggestionState
- type TableMap
- func (m *TableMap) Cells() []CellRect
- func (m *TableMap) CellsInRect(rect Rect) []int
- func (m *TableMap) ColCount(pos int) int
- func (m *TableMap) FindCell(pos int) Rect
- func (m *TableMap) NextCell(pos int, axis string, dir int) int
- func (m *TableMap) PositionAt(row, col int, table *Node) int
- func (m *TableMap) RectBetween(a, b int) Rect
- type TableOptions
- type TextSelection
- func (s *TextSelection) Anchor() int
- func (s *TextSelection) AnchorPos() *ResolvedPos
- func (s *TextSelection) Bookmark() Bookmark
- func (s *TextSelection) Content() *Slice
- func (s *TextSelection) Cursor() *ResolvedPos
- func (s *TextSelection) Empty() bool
- func (s *TextSelection) Eq(o Selection) bool
- func (s *TextSelection) From() int
- func (s *TextSelection) FromPos() *ResolvedPos
- func (s *TextSelection) Head() int
- func (s *TextSelection) HeadPos() *ResolvedPos
- func (s *TextSelection) Map(doc *Node, m Mappable) Selection
- func (s *TextSelection) Ranges() []SelectionRange
- func (s *TextSelection) Replace(tr *Transaction, content *Slice)
- func (s *TextSelection) ReplaceWith(tr *Transaction, node *Node)
- func (s *TextSelection) To() int
- func (s *TextSelection) ToPos() *ResolvedPos
- type Transaction
- func (tr *Transaction) AddMark(from, to int, mark *Mark) *Transaction
- func (tr *Transaction) AddStoredMark(m *Mark) *Transaction
- func (tr *Transaction) Delete(from, to int) *Transaction
- func (tr *Transaction) DeleteRange(from, to int) *Transaction
- func (tr *Transaction) DeleteSelection() *Transaction
- func (tr *Transaction) EnsureMarks(marks []*Mark) *Transaction
- func (tr *Transaction) Insert(pos int, content ...*Node) *Transaction
- func (tr *Transaction) InsertText(text string, from, to int) *Transaction
- func (tr *Transaction) Join(pos, depth int) *Transaction
- func (tr *Transaction) Lift(r *NodeRange, target int) *Transaction
- func (tr *Transaction) Meta(key any) any
- func (tr *Transaction) RemoveMark(from, to int, mark *Mark, typ *MarkType) *Transaction
- func (tr *Transaction) RemoveStoredMark(t *MarkType) *Transaction
- func (tr *Transaction) Replace(from, to int, slice *Slice) *Transaction
- func (tr *Transaction) ReplaceRange(from, to int, slice *Slice) *Transaction
- func (tr *Transaction) ReplaceRangeWith(from, to int, node *Node) *Transaction
- func (tr *Transaction) ReplaceSelection(slice *Slice) *Transaction
- func (tr *Transaction) ReplaceSelectionWith(node *Node, inheritMarks bool) *Transaction
- func (tr *Transaction) ReplaceWith(from, to int, content ...*Node) *Transaction
- func (tr *Transaction) ScrollIntoView() *Transaction
- func (tr *Transaction) ScrolledIntoView() bool
- func (tr *Transaction) Selection() Selection
- func (tr *Transaction) SelectionSet() bool
- func (tr *Transaction) SetBlockType(from, to int, typ *NodeType, attrs func(*Node) Attrs) *Transaction
- func (tr *Transaction) SetMeta(key, value any) *Transaction
- func (tr *Transaction) SetNodeAttribute(pos int, attr string, value any) *Transaction
- func (tr *Transaction) SetNodeMarkup(pos int, typ *NodeType, attrs Attrs, marks []*Mark) *Transaction
- func (tr *Transaction) SetSelection(s Selection) *Transaction
- func (tr *Transaction) SetStoredMarks(marks []*Mark) *Transaction
- func (tr *Transaction) Split(pos, depth int, typesAfter []NodeTypeAttrs) *Transaction
- func (tr *Transaction) Step(s Step) *Transaction
- func (tr *Transaction) StoredMarks() []*Mark
- func (tr *Transaction) Wrap(r *NodeRange, wrappers []NodeTypeAttrs) *Transaction
- type Transform
- func (t *Transform) AddMark(from, to int, mark *Mark) *Transform
- func (t *Transform) Before() *Node
- func (t *Transform) ClearIncompatible(pos int, typ *NodeType, match *ContentMatch) *Transform
- func (t *Transform) Delete(from, to int) *Transform
- func (t *Transform) DeleteRange(from, to int) *Transform
- func (t *Transform) DocChanged() bool
- func (t *Transform) Insert(pos int, content ...*Node) *Transform
- func (t *Transform) Join(pos, depth int) *Transform
- func (t *Transform) Lift(r *NodeRange, target int) *Transform
- func (t *Transform) RemoveMark(from, to int, mark *Mark, typ *MarkType) *Transform
- func (t *Transform) Replace(from, to int, slice *Slice) *Transform
- func (t *Transform) ReplaceRange(from, to int, slice *Slice) *Transform
- func (t *Transform) ReplaceRangeWith(from, to int, node *Node) *Transform
- func (t *Transform) ReplaceWith(from, to int, content ...*Node) *Transform
- func (t *Transform) SetBlockType(from, to int, typ *NodeType, attrs func(*Node) Attrs) *Transform
- func (t *Transform) SetNodeAttribute(pos int, attr string, value any) *Transform
- func (t *Transform) SetNodeMarkup(pos int, typ *NodeType, attrs Attrs, marks []*Mark) *Transform
- func (t *Transform) Split(pos, depth int, typesAfter []NodeTypeAttrs) *Transform
- func (t *Transform) Step(s Step) *Transform
- func (t *Transform) Wrap(r *NodeRange, wrappers []NodeTypeAttrs) *Transform
- type View
Constants ¶
const DefaultPriority = 100
DefaultPriority is an extension's unless it gives one: higher runs first.
Variables ¶
var ( Undo = historyCommand(false) Redo = historyCommand(true) )
Undo and Redo walk the history.
var ( AddColumnBefore = tableCommand(func(_ *State, r *selectedRect, tr *Transaction) bool { addColumn(tr, r, r.Left) return true }) AddColumnAfter = tableCommand(func(_ *State, r *selectedRect, tr *Transaction) bool { addColumn(tr, r, r.Right) return true }) AddRowBefore = tableCommand(func(_ *State, r *selectedRect, tr *Transaction) bool { addRow(tr, r, r.Top) return true }) AddRowAfter = tableCommand(func(_ *State, r *selectedRect, tr *Transaction) bool { addRow(tr, r, r.Bottom) return true }) // DeleteColumn and DeleteRow refuse to delete every column or row. DeleteColumn = tableCommand(func(s *State, r *selectedRect, tr *Transaction) bool { if r.Left == 0 && r.Right == r.m.Width { return false } for i := r.Right - 1; ; i-- { removeColumn(tr, r, i) if i == r.Left { break } table := tr.Doc.Resolve(r.tableStart - 1).NodeAfter() if table == nil { return false } r = &selectedRect{r.Rect, r.tableStart, TableMapOf(table), table} } return true }) DeleteRow = tableCommand(func(s *State, r *selectedRect, tr *Transaction) bool { if r.Top == 0 && r.Bottom == r.m.Height { return false } for i := r.Bottom - 1; ; i-- { removeRow(tr, r, i) if i == r.Top { break } table := tr.Doc.Resolve(r.tableStart - 1).NodeAfter() if table == nil { return false } r = &selectedRect{r.Rect, r.tableStart, TableMapOf(table), table} } return true }) )
AddColumnBefore and the commands after it edit the table at the selection, by Tiptap's names.
var ( ToggleHeaderRow = toggleHeader("row") ToggleHeaderColumn = toggleHeader("column") ToggleHeaderCell = toggleHeader("cell") )
ToggleHeaderRow, ToggleHeaderColumn and ToggleHeaderCell turn cells to header cells and back.
var EmptySlice = &Slice{Content: emptyFragment}
EmptySlice holds nothing.
var EmptyStepMap = &StepMap{}
EmptyStepMap moves nothing.
Functions ¶
func BaseKeymap ¶
BaseKeymap is what a press of Enter and the deleting keys do anywhere.
func CanSplit ¶
func CanSplit(doc *Node, pos, depth int, typesAfter []NodeTypeAttrs) bool
CanSplit says pos can split depth levels, each new level's types or the same when nil.
func ColumnWidths ¶
ColumnWidths are a table's widths by column, 0 for none.
func CreateParagraphNear ¶
func CreateParagraphNear(s *State, dispatch func(*Transaction)) bool
CreateParagraphNear makes a paragraph beside a selected block.
func DeleteCellSelection ¶
func DeleteCellSelection(s *State, dispatch func(*Transaction)) bool
DeleteCellSelection empties the selected cells.
func DeleteSelection ¶
func DeleteSelection(s *State, dispatch func(*Transaction)) bool
DeleteSelection deletes a selection that holds something.
func DeleteTable ¶
func DeleteTable(s *State, dispatch func(*Transaction)) bool
DeleteTable deletes the table at the selection.
func DragSource ¶
DragSource is what a handle at pos carries, from to to: the siblings the selection covers when pos is in a selection over several, else the block at pos, a defining parent standing for its first child, as a list item for its paragraph. ok is false where there is no block.
func ExitCode ¶
func ExitCode(s *State, dispatch func(*Transaction)) bool
ExitCode leaves a code block to the block after it.
func FindParentNode ¶
FindParentNode is the position before the nearest ancestor of the selection pred accepts, -1 for none.
func GapCursorValid ¶
func GapCursorValid(r *ResolvedPos) bool
GapCursorValid says a gap cursor may stand at pos: between closed blocks, in a parent whose default content there is a textblock, unless its spec's Extra["allowGapCursor"] says otherwise.
func GoToNextCellOrAddRow ¶
func GoToNextCellOrAddRow(s *State, dispatch func(*Transaction)) bool
GoToNextCellOrAddRow is Tab: past the last cell a new row.
func InsertCells ¶
func InsertCells(s *State, dispatch func(*Transaction), tableStart int, rect Rect, cells *CellArea)
InsertCells puts cells into the table starting at tableStart with their top left at rect's, growing the table and splitting the cells crossing the area's edges, and selects them.
func InsertPoint ¶
InsertPoint is where a node of typ fits at or near pos, -1 for nowhere.
func IsAllowedURI ¶
IsAllowedURI is Tiptap's check of a link's address.
func IsMarkActive ¶
IsMarkActive says the selection is in a mark of t with attrs.
func IsNodeActive ¶
IsNodeActive says the selection is in a node of t with attrs.
func JoinBackward ¶
func JoinBackward(s *State, dispatch func(*Transaction)) bool
JoinBackward joins the textblock at a cursor's start with what is before.
func JoinForward ¶
func JoinForward(s *State, dispatch func(*Transaction)) bool
JoinForward joins the textblock at a cursor's end with what is after.
func Lift ¶
func Lift(s *State, dispatch func(*Transaction)) bool
Lift lifts the selected block out of its parent.
func LiftEmptyBlock ¶
func LiftEmptyBlock(s *State, dispatch func(*Transaction)) bool
LiftEmptyBlock lifts an empty block out of its parent.
func LiftTarget ¶
LiftTarget is the depth a range can lift to, -1 for none.
func MarkRange ¶
func MarkRange(r *ResolvedPos, t *MarkType) (from, to int, ok bool)
MarkRange is the range of the mark of t around pos, its marks' run.
func MergeBindings ¶
MergeBindings joins keymaps, a key's commands running in the given order.
func MergeCells ¶
func MergeCells(s *State, dispatch func(*Transaction)) bool
MergeCells merges the selected cells, their contents joined.
func NewlineInCode ¶
func NewlineInCode(s *State, dispatch func(*Transaction)) bool
NewlineInCode inserts a line break in a code block.
func PlainText ¶
PlainText is a document's text, a blank line between its blocks, a table's rows as lines of tab-separated cells.
func SelectAll ¶
func SelectAll(s *State, dispatch func(*Transaction)) bool
SelectAll selects the document.
func SelectNodeBackward ¶
func SelectNodeBackward(s *State, dispatch func(*Transaction)) bool
SelectNodeBackward selects the node before a cursor at a textblock's start.
func SelectNodeForward ¶
func SelectNodeForward(s *State, dispatch func(*Transaction)) bool
SelectNodeForward selects the node after a cursor at a textblock's end.
func SelectParentNode ¶
func SelectParentNode(s *State, dispatch func(*Transaction)) bool
SelectParentNode selects the block around the selection.
func SelectionPosNext ¶
func SelectionPosNext(r *ResolvedPos, dir int) int
SelectionPosNext is the caret of the next textblock going dir.
func SplitBlock ¶
func SplitBlock(s *State, dispatch func(*Transaction)) bool
SplitBlock splits the textblock at the selection.
func SplitCell ¶
func SplitCell(s *State, dispatch func(*Transaction)) bool
SplitCell splits a merged cell into cells of one slot.
func UndoInputRule ¶
func UndoInputRule(s *State, dispatch func(*Transaction)) bool
UndoInputRule undoes the rule that just ran, leaving the typed text.
func WriteMarkdown ¶
WriteMarkdown writes a document as Markdown: GFM's task items and pipe tables, and a table a pipe table cannot hold as its HTML on one line, which reads back as it was.
Types ¶
type AddMarkStep ¶
AddMarkStep adds Mark from From to To.
func (*AddMarkStep) Invert ¶
func (s *AddMarkStep) Invert(*Node) Step
func (*AddMarkStep) Map ¶
func (s *AddMarkStep) Map(m Mappable) Step
func (*AddMarkStep) Merge ¶
func (s *AddMarkStep) Merge(other Step) Step
func (*AddMarkStep) StepMap ¶
func (s *AddMarkStep) StepMap() *StepMap
type AllSelection ¶
type AllSelection struct {
// contains filtered or unexported fields
}
AllSelection selects the whole document.
func (*AllSelection) AnchorPos ¶
func (s *AllSelection) AnchorPos() *ResolvedPos
func (*AllSelection) Bookmark ¶
func (s *AllSelection) Bookmark() Bookmark
func (*AllSelection) Eq ¶
func (s *AllSelection) Eq(o Selection) bool
func (*AllSelection) FromPos ¶
func (s *AllSelection) FromPos() *ResolvedPos
func (*AllSelection) HeadPos ¶
func (s *AllSelection) HeadPos() *ResolvedPos
func (*AllSelection) Ranges ¶
func (s *AllSelection) Ranges() []SelectionRange
func (*AllSelection) Replace ¶
func (s *AllSelection) Replace(tr *Transaction, content *Slice)
func (*AllSelection) ReplaceWith ¶
func (s *AllSelection) ReplaceWith(tr *Transaction, node *Node)
func (*AllSelection) ToPos ¶
func (s *AllSelection) ToPos() *ResolvedPos
type AttrSpec ¶
type AttrSpec struct {
Name string
Default any
HasDefault bool
// Validate refuses a value, for documents that come from outside.
Validate func(any) error
}
AttrSpec is an attribute: required unless it has a default.
type Attrs ¶
Attrs are a node's or mark's attributes: JSON's values, numbers as float64, never changed once made.
type Built ¶
type Built struct {
Schema *Schema
Plugins []*Plugin
Commands map[string]CommandFactory
}
Built is what a list of extensions makes.
type CellArea ¶
CellArea is a rectangle of pasted cells, a fragment of cells per row.
func PastedCells ¶
PastedCells is the cells slice holds, nil unless it is a table's rows or cells.
type CellSelection ¶
type CellSelection struct {
AnchorCell, HeadCell *ResolvedPos
// contains filtered or unexported fields
}
CellSelection selects a rectangle of cells: Replace fills the first and empties the others.
func ColSelection ¶
func ColSelection(anchor, head *ResolvedPos) *CellSelection
ColSelection selects the columns from anchor's to head's.
func NewCellSelection ¶
func NewCellSelection(anchor, head *ResolvedPos) *CellSelection
NewCellSelection selects the cells between two positions before cells.
func RowSelection ¶
func RowSelection(anchor, head *ResolvedPos) *CellSelection
RowSelection selects the rows from anchor's to head's.
func (*CellSelection) AnchorPos ¶
func (s *CellSelection) AnchorPos() *ResolvedPos
func (*CellSelection) Bookmark ¶
func (s *CellSelection) Bookmark() Bookmark
func (*CellSelection) Content ¶
func (s *CellSelection) Content() *Slice
Content is the rectangle as rows.
func (*CellSelection) Eq ¶
func (s *CellSelection) Eq(o Selection) bool
func (*CellSelection) FromPos ¶
func (s *CellSelection) FromPos() *ResolvedPos
func (*CellSelection) HeadPos ¶
func (s *CellSelection) HeadPos() *ResolvedPos
func (*CellSelection) IsColSelection ¶
func (s *CellSelection) IsColSelection() bool
IsColSelection says the selection covers whole columns.
func (*CellSelection) IsRowSelection ¶
func (s *CellSelection) IsRowSelection() bool
IsRowSelection says the selection covers whole rows.
func (*CellSelection) Ranges ¶
func (s *CellSelection) Ranges() []SelectionRange
func (*CellSelection) Replace ¶
func (s *CellSelection) Replace(tr *Transaction, content *Slice)
func (*CellSelection) ReplaceWith ¶
func (s *CellSelection) ReplaceWith(tr *Transaction, node *Node)
func (*CellSelection) ToPos ¶
func (s *CellSelection) ToPos() *ResolvedPos
type CharacterCountOptions ¶
type CharacterCountOptions struct {
// Limit is the most characters, none when 0.
Limit int
// CountNodes counts every position rather than text.
CountNodes bool
}
CharacterCountOptions tune CharacterCount.
type Classes ¶
type Classes struct {
Content string
Nodes, Marks map[string]string
Placeholder, Caret, Selection, Composition string
GapCursor, DropCursor string
SelectedNode, SelectedCell string
SelectionHandle string
ListMarker, TaskCheckbox string
TableResizeHandle, TableGrip, TableDropIndicator string
}
Classes are Tailwind classes of the parts, by Styles' names, each under its part's style.
type Command ¶
type Command func(s *State, dispatch func(*Transaction)) bool
Command is an edit over a state: it says whether it applies, and with a dispatch makes the change. With a nil dispatch it only checks.
func Chain ¶
Chain runs commands one after another, each on the state the one before left, and dispatches their changes as one transaction, as Tiptap's chain does: it says whether every one applied. Without a dispatch each checks on the state the ones before would leave.
func ChainCommands ¶
ChainCommands is ProseMirror's chainCommands: the first command that applies runs.
func ExitSuggestion ¶
ExitSuggestion dismisses the Suggestion keyed key.
func GoToNextCell ¶
GoToNextCell moves to the next cell, or the previous when dir is negative.
func InsertHardBreak ¶
InsertHardBreak replaces the selection with a node of t.
func InsertMention ¶
InsertMention replaces the active query with a mention and a space after it, one already there taken in.
func InsertTable ¶
InsertTable inserts a table of rows and cols, a header row with withHeader, its first cell selected.
func LiftListItem ¶
LiftListItem lifts the selected list items out of their list.
func MoveBlocks ¶
MoveBlocks moves the blocks from from to to to target, a position between blocks outside them whose parent takes them, as one transaction that selects what moved.
func MoveTableColumn ¶
MoveTableColumn moves a column, as MoveTableRow a row.
func MoveTableRow ¶
MoveTableRow moves row from to the place of row to; table is the position before a table, the selection's when negative. The moved rows end up selected.
func SetBlockType ¶
SetBlockType sets the selected textblocks to t.
func SetCellSelection ¶
SetCellSelection selects from the cell at anchor to the one at head.
func SetColumnWidth ¶
SetColumnWidth sets col's width on every cell covering it, 0 for none.
func SetRowHeight ¶
SetRowHeight sets row's height, 0 for none.
func ShiftArrow ¶
ShiftArrow extends a cell selection, starting one from a text selection at a cell's edge.
func SinkListItem ¶
SinkListItem nests the selected list items in the item before them.
func SplitListItem ¶
SplitListItem splits the list item at the selection; an empty one leaves the list or lifts.
func ToggleBlockType ¶
ToggleBlockType sets the textblock to t, or back to paragraph-like default when it is t.
func ToggleList ¶
ToggleList wraps the selection in a list of t, lifts it out, or turns the list it is in into one of t.
func ToggleMark ¶
ToggleMark toggles a mark over the selection, or in the stored marks at a cursor.
func ToggleWrap ¶
ToggleWrap wraps the selection in t, or lifts it out.
func UpdateAttributes ¶
UpdateAttributes sets attrs on the blocks of t in the selection.
func WrapInList ¶
WrapInList wraps the selected blocks in a list of listType.
type CommandFactory ¶
CommandFactory makes a named command from its arguments.
type ContentMatch ¶
type ContentMatch struct {
ValidEnd bool
// contains filtered or unexported fields
}
ContentMatch is a state of the automaton a content expression compiles to, ProseMirror's: the node types it may go on with, and whether the content may end here.
func (*ContentMatch) Edge ¶
func (m *ContentMatch) Edge(n int) (*NodeType, *ContentMatch)
Edge is its nth edge.
func (*ContentMatch) EdgeCount ¶
func (m *ContentMatch) EdgeCount() int
EdgeCount and Edge list the types it goes on with.
func (*ContentMatch) FillBefore ¶
func (m *ContentMatch) FillBefore(after *Fragment, toEnd bool, start int) *Fragment
FillBefore is what must go before after, from index start, for it to fit here, ending in a valid end with toEnd; nil when nothing can.
func (*ContentMatch) FindWrapping ¶
func (m *ContentMatch) FindWrapping(target *NodeType) []*NodeType
FindWrapping is the types to wrap a node of target in to fit here, an empty list for none needed; nil when none can.
func (*ContentMatch) MatchFragment ¶
func (m *ContentMatch) MatchFragment(frag *Fragment, start, end int) *ContentMatch
MatchFragment is the state after frag's children from start to end (the end of frag when negative), nil when one does not fit.
func (*ContentMatch) MatchType ¶
func (m *ContentMatch) MatchType(t *NodeType) *ContentMatch
MatchType is the state after a node of t, nil when t does not fit.
type Decoration ¶
type Decoration struct {
From, To int
Class string
Node bool
Widget func(cx *core.Scope) core.Node
Side int
Key string
}
Decoration styles a range without changing the document: Class on the range's text, or with Node on the block at From. With Widget it is a view in the text at From instead, taking no position: Side below zero puts it before a cursor there, else after, and Key, when set, keeps its view while the decoration stays.
type Extension ¶
type Extension struct {
Name string
Priority int
Nodes []NodeSpec
Marks []MarkSpec
Global []GlobalAttrs
Keys func(s *Schema) map[string]Command
Rules func(s *Schema) []InputRule
Plugins func(s *Schema) []*Plugin
Commands func(s *Schema) map[string]CommandFactory
}
Extension contributes to an editor in one unit, as Tiptap's do: to the schema, the keys, the rules, the plugins and the named commands.
func CharacterCount ¶
func CharacterCount(o CharacterCountOptions) Extension
CharacterCount refuses changes that grow past the limit, a document over it already may shrink, and trims what is pasted to what fits.
func Link ¶
func Link(o LinkOptions) Extension
Link is the link mark with autolinking, opening on Mod-click and linking a selection when a URL is pasted over it, not growing as text is typed after it.
func Mention ¶
func Mention(o MentionOptions) Extension
Mention is an inline node showing @name with its one position, and the Suggestion that finds it. Id identifies who, so nothing goes by the text.
func StarterKit ¶
func StarterKit(o StarterOptions) []Extension
StarterKit is a rich text editor's usual types with their commands, keys and rules, by Tiptap's names.
func TableKit ¶
func TableKit(o TableOptions) Extension
TableKit is tables with their commands and keys, outside StarterKit.
type Fragment ¶
Fragment is a node's children.
func FragmentFrom ¶
FragmentFrom makes a fragment of nodes, joining text with equal marks.
func (*Fragment) AddToStart ¶
AddToStart is the fragment after node.
func (*Fragment) ChildCount ¶
func (*Fragment) CutByIndex ¶
CutByIndex is its children from from to to.
func (*Fragment) Descendants ¶
Descendants calls fn on every node inside.
func (*Fragment) FirstChild ¶
func (*Fragment) MaybeChild ¶
MaybeChild is its child i, nil past the end.
func (*Fragment) NodesBetween ¶
func (f *Fragment) NodesBetween(from, to int, fn func(*Node, int, *Node, int) bool, start int, parent *Node)
NodesBetween calls fn on the nodes between from and to.
func (*Fragment) ReplaceChild ¶
ReplaceChild is the fragment with child i replaced.
type GapCursor ¶
type GapCursor struct {
// contains filtered or unexported fields
}
GapCursor is a cursor at a position no text selection can hold.
func NewGapCursor ¶
func NewGapCursor(pos *ResolvedPos) *GapCursor
NewGapCursor is a gap cursor at pos, which GapCursorValid accepts.
func (*GapCursor) AnchorPos ¶
func (s *GapCursor) AnchorPos() *ResolvedPos
func (*GapCursor) FromPos ¶
func (s *GapCursor) FromPos() *ResolvedPos
func (*GapCursor) HeadPos ¶
func (s *GapCursor) HeadPos() *ResolvedPos
func (*GapCursor) Ranges ¶
func (s *GapCursor) Ranges() []SelectionRange
func (*GapCursor) Replace ¶
func (s *GapCursor) Replace(tr *Transaction, content *Slice)
func (*GapCursor) ReplaceWith ¶
func (s *GapCursor) ReplaceWith(tr *Transaction, node *Node)
func (*GapCursor) ToPos ¶
func (s *GapCursor) ToPos() *ResolvedPos
type Geometry ¶
type Geometry interface {
// CoordsAtPos is the caret's box at pos in the content box, the box
// that scrolls.
CoordsAtPos(pos int) (Rect2, bool)
// PosAtCoords is the position nearest a point of the content box.
PosAtCoords(x, y float64) (int, bool)
// SelectionRect is the box over the selection's lines.
SelectionRect() (Rect2, bool)
}
Geometry answers where positions are, from the last view mounted.
type GlobalAttrs ¶
GlobalAttrs add attributes to other types.
type HistoryOptions ¶
type HistoryOptions struct {
// Depth is the most undo steps kept, 100 when 0.
Depth int
// NewGroupDelay is the pause that starts a new undo step, 500 ms
// when 0.
NewGroupDelay time.Duration
}
HistoryOptions tune the history.
type HistoryState ¶
type HistoryState struct {
// contains filtered or unexported fields
}
HistoryState is the history plugin's field.
type InputRule ¶
type InputRule struct {
Match *regexp.Regexp
Handler func(s *State, match []string, start, end int) *Transaction
// NoUndo keeps Backspace from undoing it.
NoUndo bool
}
InputRule changes text as it is typed: Match, ending in $, is tried on the text before the cursor, and Handler gives the transaction of what it does, nil for nothing. Match is the groups' text, by index, "" for one unmatched.
func MarkInputRule ¶
MarkInputRule marks the last group, deleting what is around it in the match: "**bold**".
func TextInputRule ¶
TextInputRule replaces what matched with text.
type LinkOptions ¶
type LinkOptions struct {
// NoAutolink keeps URLs typed from becoming links, and NoOpenOnClick
// presses from opening them.
NoAutolink, NoOpenOnClick bool
// Open opens a link pressed with Mod, or in a read-only editor.
Open func(href string)
// Protocols are allowed beside http, https, ftp, mailto and tel.
Protocols []string
}
LinkOptions tune Link.
type MapResult ¶
type MapResult struct {
Pos int
// contains filtered or unexported fields
}
MapResult is a position mapped: where it went and what became of the content around it.
func (MapResult) DeletedAcross ¶
DeletedAcross says tokens on both sides are gone.
func (MapResult) DeletedAfter ¶
func (MapResult) DeletedBefore ¶
DeletedBefore and DeletedAfter say the token before or after it is gone.
type Mapping ¶
Mapping is a run of maps, some mirroring others, so what one deleted the other's undoing brings back.
func (*Mapping) AppendMapping ¶
AppendMapping adds another mapping's maps.
func (*Mapping) AppendMappingInverted ¶
AppendMappingInverted adds another mapping's maps inverted, last first.
type Mark ¶
Mark is a mark on inline content.
func (*Mark) AddToSet ¶
AddToSet is set with the mark, in rank order, without what it excludes; set itself when a mark there excludes it.
func (*Mark) RemoveFromSet ¶
RemoveFromSet is set without the mark.
type MarkSpec ¶
type MarkSpec struct {
Name string
Attrs []AttrSpec
// NotInclusive keeps text typed at its end out of it.
NotInclusive bool
// Excludes are the marks it cannot coexist with, space separated: its
// own type when "", every one with "_", none with "none".
Excludes string
Group string
// RenderText is unused by marks' kernel; Extra is as NodeSpec's.
Extra map[string]any
}
MarkSpec is a type of mark.
type MarkType ¶
type MarkType struct {
Name string
Schema *Schema
Spec MarkSpec
Rank int
// contains filtered or unexported fields
}
MarkType is a type of a schema's marks.
func (*MarkType) RemoveFromSet ¶
RemoveFromSet is set without marks of the type.
type MentionOptions ¶
type MentionOptions struct {
Suggestion SuggestionOptions
}
MentionOptions tune Mention.
type Node ¶
type Node struct {
Type *NodeType
Attrs Attrs
Content *Fragment
Marks []*Mark
Text string
// contains filtered or unexported fields
}
Node is a node of a document, never changed once made; a text node holds Text and the others Content.
func DocFromJSONString ¶
DocFromJSONString reads a document from JSON and checks it.
func NodeFromJSON ¶
NodeFromJSON reads a node of s, checking only what it needs to.
func ParseHTML ¶
ParseHTML reads HTML into a document of the starter's names, what the schema does not have dropped to its text.
func ParseMarkdown ¶
ParseMarkdown reads CommonMark and GFM into a document of the starter's names, keeping what the schema has: task items as taskItem, pipe tables as tables, the first row header cells.
func (*Node) CanReplace ¶
CanReplace says replacing children from to to with replacement, from start to end of it, keeps the node valid.
func (*Node) CanReplaceWith ¶
CanReplaceWith says a node of t in place of children from to to keeps the node valid.
func (*Node) ChildCount ¶
func (*Node) Descendants ¶
Descendants calls f on every node inside.
func (*Node) FirstChild ¶
func (*Node) InlineContent ¶
func (*Node) IsTextblock ¶
func (*Node) MaybeChild ¶
func (*Node) NodesBetween ¶
func (n *Node) NodesBetween(from, to int, f func(node *Node, pos int, parent *Node, index int) bool, start int)
NodesBetween calls f on the nodes from from to to, depth first, skipping a node's children when it returns false.
func (*Node) RangeHasMark ¶
RangeHasMark says a node from from to to has a mark of m.
func (*Node) Resolve ¶
func (n *Node) Resolve(pos int) *ResolvedPos
Resolve resolves pos, which must be in the document.
func (*Node) SameMarkup ¶
SameMarkup says two nodes differ at most in content.
func (*Node) Slice ¶
Slice is the document from from to to, open as far as the two share no parent, or to their deepest shared depth with includeParents.
func (*Node) TextBetween ¶
TextBetween is the text from from to to, blocks joined by blockSep and leaves as leafText or their LeafText.
type NodeProps ¶
type NodeProps struct {
// Node is the node now, and Pos where it is.
Node func() *Node
Pos func() int
// Selected says a node selection holds it.
Selected func() bool
// Content is the editor's rendering of the node's content, editable
// where the view places it; nil for a leaf.
Content core.Node
Editor *Session
// SetAttrs changes attributes as a transaction, undoable as any other.
SetAttrs func(attrs Attrs)
}
NodeProps is what a node view follows.
type NodeRange ¶
type NodeRange struct {
From, To *ResolvedPos
Depth int
}
NodeRange is a flat range of a node's children.
func (*NodeRange) StartIndex ¶
type NodeSelection ¶
type NodeSelection struct {
Node *Node
// contains filtered or unexported fields
}
NodeSelection selects one node.
func NewNodeSelection ¶
func NewNodeSelection(pos *ResolvedPos) *NodeSelection
NewNodeSelection selects the node after pos.
func NodeSelectionAt ¶
func NodeSelectionAt(doc *Node, from int) *NodeSelection
NodeSelectionAt selects the node at from.
func (*NodeSelection) AnchorPos ¶
func (s *NodeSelection) AnchorPos() *ResolvedPos
func (*NodeSelection) Bookmark ¶
func (s *NodeSelection) Bookmark() Bookmark
func (*NodeSelection) Content ¶
func (s *NodeSelection) Content() *Slice
func (*NodeSelection) Eq ¶
func (s *NodeSelection) Eq(o Selection) bool
func (*NodeSelection) FromPos ¶
func (s *NodeSelection) FromPos() *ResolvedPos
func (*NodeSelection) HeadPos ¶
func (s *NodeSelection) HeadPos() *ResolvedPos
func (*NodeSelection) Ranges ¶
func (s *NodeSelection) Ranges() []SelectionRange
func (*NodeSelection) Replace ¶
func (s *NodeSelection) Replace(tr *Transaction, content *Slice)
func (*NodeSelection) ReplaceWith ¶
func (s *NodeSelection) ReplaceWith(tr *Transaction, node *Node)
func (*NodeSelection) ToPos ¶
func (s *NodeSelection) ToPos() *ResolvedPos
type NodeSpec ¶
type NodeSpec struct {
Name string
// Content is its content expression ("paragraph+", "inline*",
// "(heading | paragraph) block*"); a leaf without one.
Content string
// Marks are the marks allowed in it, space separated, "_" for every
// one and "none" for none; unset, an inline container's take every one.
Marks string
// Group is the groups it belongs to, space separated.
Group string
Inline bool
// Atom has a node with content count as one unit from outside.
Atom bool
// NoSelect keeps node selections off it.
NoSelect bool
// Code has its content kept as code: marks and commands treat it so.
Code bool
// Defining keeps a node when its content is replaced, and its content
// keeps it when pasted; Isolating stops edits at its boundaries.
Defining, Isolating bool
// Whitespace "pre" keeps its white space as it is.
Whitespace string
Attrs []AttrSpec
// LeafText is what a leaf is as text.
LeafText func(n *Node) string
// RenderText is what the view shows for an inline leaf, one position
// however long, a mention's @name.
RenderText func(n *Node) string
// Extra is what other parts read: a list's "listMarker", a table's
// "tableRole".
Extra map[string]any
}
NodeSpec is a type of node.
type NodeType ¶
type NodeType struct {
Name string
Schema *Schema
Spec NodeSpec
Groups []string
ContentMatch *ContentMatch
InlineContent bool
// MarkSet is the marks allowed, nil for every one.
MarkSet []*MarkType
// contains filtered or unexported fields
}
NodeType is a type of a schema's nodes.
func (*NodeType) AllowsMarkType ¶
AllowsMarkType says the type's content may hold marks of m.
func (*NodeType) AllowsMarks ¶
AllowsMarks says it may hold all of marks.
func (*NodeType) CreateAndFill ¶
CreateAndFill makes a node filling what its content requires around content, nil when it cannot.
func (*NodeType) IsBlock ¶
IsBlock, IsText, IsInline, IsLeaf, IsTextblock and IsAtom say what a type's nodes are.
func (*NodeType) IsTextblock ¶
func (*NodeType) ValidContent ¶
ValidContent says content fits the type.
type NodeTypeAttrs ¶
NodeTypeAttrs is a wrapper and its attributes.
func FindWrapping ¶
func FindWrapping(r *NodeRange, typ *NodeType, attrs Attrs, innerRange *NodeRange) []NodeTypeAttrs
FindWrapping is the wrappers a range takes to sit in typ, nil for none.
type NodeView ¶
NodeView renders a node type in place of the editor's: its element follows Node, and never changes the node but through SetAttrs. A block's is its block; an inline node's is a view in the text's lines, an attachment in place of what RenderText or LeafText calls it, which copy takes instead, and a press on it selects the node, atomically as it stays one position.
type Plugin ¶
type Plugin struct {
// Key is unique in a state.
Key string
// Init and Apply are the plugin's field in the state.
Init func(s *State) any
Apply func(tr *Transaction, value any, old, new *State) any
// FilterTransaction refuses a transaction before it applies.
FilterTransaction func(tr *Transaction, s *State) bool
// AppendTransaction may add a transaction after others applied.
AppendTransaction func(trs []*Transaction, old, new *State) *Transaction
HandleKeyDown func(v *Session, key string) bool
HandleTextInput func(v *Session, from, to int, text string) bool
HandlePaste func(v *Session, slice *Slice) bool
// TransformPasted changes what is pasted, and TransformPastedText the
// text it comes from.
TransformPasted func(v *Session, slice *Slice) *Slice
TransformPastedText func(v *Session, text string) string
// HandleClick hears a press at pos, Clicks in a row, Mod held or not.
HandleClick func(v *Session, pos, clicks int, mod bool) bool
// Decorations are what the view draws without changing the document.
Decorations func(s *State) []Decoration
}
Plugin is optional behavior over a state: a field in the state, hooks on transactions and hooks on the view's events, asked in plugin order, the first true consuming the event.
func GapCursorPlugin ¶
func GapCursorPlugin() *Plugin
GapCursorPlugin is prosemirror-gapcursor's plugin: arrows move into gaps, a press in one puts the cursor there, and the view draws it.
func History ¶
func History(o HistoryOptions) *Plugin
History is the undo history: changes further apart than NewGroupDelay, or not adjacent, start a new step, an input method's commits group, and changes kept out of it or made by others map its steps.
func Keymap ¶
Keymap binds keys ("Mod-b", "Shift-Enter", "Backspace") to commands; a key's commands run until one applies. A binding with Shift spelled out goes before the shifted character's.
func Suggestion ¶
func Suggestion(o SuggestionOptions) *Plugin
Suggestion follows a trigger and the query after it, for the app's list, which reads SuggestionStateOf and replaces the range.
func TableEditing ¶
func TableEditing() *Plugin
TableEditing normalizes selections in tables: a selected cell, row or table becomes a cell selection, and a text selection across two cells of one table does.
type Rect ¶
type Rect struct{ Left, Top, Right, Bottom int }
Rect is a rectangle of a table's map, its right and bottom past the end.
type Ref ¶
type Ref struct {
// contains filtered or unexported fields
}
Ref is a View's methods.
func (*Ref) PageBounds ¶
PageBounds is the caret's box at pos in the surface, for an Overlay the app places by the text, such as a mention's list.
type RemoveMarkStep ¶
RemoveMarkStep removes Mark from From to To.
func (*RemoveMarkStep) Invert ¶
func (s *RemoveMarkStep) Invert(*Node) Step
func (*RemoveMarkStep) Map ¶
func (s *RemoveMarkStep) Map(m Mappable) Step
func (*RemoveMarkStep) Merge ¶
func (s *RemoveMarkStep) Merge(other Step) Step
func (*RemoveMarkStep) StepMap ¶
func (s *RemoveMarkStep) StepMap() *StepMap
type ReplaceAroundStep ¶
type ReplaceAroundStep struct {
From, To, GapFrom, GapTo int
Slice *Slice
Insert int
Structure bool
}
ReplaceAroundStep replaces From to To, keeping GapFrom to GapTo as the content at Insert of Slice.
func (*ReplaceAroundStep) Invert ¶
func (s *ReplaceAroundStep) Invert(doc *Node) Step
func (*ReplaceAroundStep) Map ¶
func (s *ReplaceAroundStep) Map(m Mappable) Step
func (*ReplaceAroundStep) Merge ¶
func (s *ReplaceAroundStep) Merge(Step) Step
func (*ReplaceAroundStep) StepMap ¶
func (s *ReplaceAroundStep) StepMap() *StepMap
type ReplaceStep ¶
ReplaceStep replaces From to To with Slice.
func (*ReplaceStep) Invert ¶
func (s *ReplaceStep) Invert(doc *Node) Step
func (*ReplaceStep) Map ¶
func (s *ReplaceStep) Map(m Mappable) Step
func (*ReplaceStep) Merge ¶
func (s *ReplaceStep) Merge(other Step) Step
func (*ReplaceStep) StepMap ¶
func (s *ReplaceStep) StepMap() *StepMap
type ResolvedPos ¶
type ResolvedPos struct {
Pos int
Depth int
ParentOffset int
// contains filtered or unexported fields
}
ResolvedPos is a position with what it is in.
func FindGapCursorFrom ¶
func FindGapCursorFrom(r *ResolvedPos, dir int, mustMove bool) *ResolvedPos
FindGapCursorFrom is the first gap from pos going dir, moving off pos when mustMove; nil for none.
func (*ResolvedPos) Before ¶
func (r *ResolvedPos) Before(d int) int
Before is the position before its ancestor at depth d.
func (*ResolvedPos) BlockRange ¶
func (r *ResolvedPos) BlockRange(other *ResolvedPos, pred func(*Node) bool) *NodeRange
BlockRange is the flat range of blocks around from here to other, nil for none.
func (*ResolvedPos) Index ¶
func (r *ResolvedPos) Index(d int) int
Index is the child of its ancestor at depth d it points into.
func (*ResolvedPos) IndexAfter ¶
func (r *ResolvedPos) IndexAfter(d int) int
IndexAfter is the index after it at depth d.
func (*ResolvedPos) MarksAcross ¶
func (r *ResolvedPos) MarksAcross(end *ResolvedPos) []*Mark
MarksAcross are the marks after it that also go on to end.
func (*ResolvedPos) MarksHere ¶
func (r *ResolvedPos) MarksHere() []*Mark
MarksHere are the marks typed text would take here.
func (*ResolvedPos) Node ¶
func (r *ResolvedPos) Node(d int) *Node
Node is its ancestor at depth d; a negative d counts from its own.
func (*ResolvedPos) NodeAfter ¶
func (r *ResolvedPos) NodeAfter() *Node
NodeAfter is the node after it, a text's rest, nil for none.
func (*ResolvedPos) NodeBefore ¶
func (r *ResolvedPos) NodeBefore() *Node
NodeBefore is the node before it, a text's start, nil for none.
func (*ResolvedPos) Parent ¶
func (r *ResolvedPos) Parent() *Node
Parent is the node it is directly in.
func (*ResolvedPos) PosAtIndex ¶
func (r *ResolvedPos) PosAtIndex(index, d int) int
PosAtIndex is the position of child index of its ancestor at depth d.
func (*ResolvedPos) SameParent ¶
func (r *ResolvedPos) SameParent(o *ResolvedPos) bool
SameParent says two positions are in one node.
func (*ResolvedPos) SharedDepth ¶
func (r *ResolvedPos) SharedDepth(pos int) int
SharedDepth is the deepest ancestor holding pos too.
func (*ResolvedPos) Start ¶
func (r *ResolvedPos) Start(d int) int
Start is where the content of its ancestor at depth d starts.
func (*ResolvedPos) TextOffset ¶
func (r *ResolvedPos) TextOffset() int
TextOffset is how far into a text node it is.
type Schema ¶
type Schema struct {
Spec SchemaSpec
Nodes map[string]*NodeType
Marks map[string]*MarkType
TopNode *NodeType
// contains filtered or unexported fields
}
Schema is a document's node and mark types.
func NewSchema ¶
func NewSchema(spec SchemaSpec) (*Schema, error)
NewSchema makes a schema, refusing what cannot make one: a content expression that does not read or requires a type no document can fill.
func (*Schema) DefaultBlock ¶
DefaultBlock is the first block type in the top node's content.
type SchemaSpec ¶
SchemaSpec is a schema's types in order: the first block type is the default one, and TopNode, "doc" when "", the document's.
type Selection ¶
type Selection interface {
Anchor() int
Head() int
From() int
To() int
FromPos() *ResolvedPos
ToPos() *ResolvedPos
HeadPos() *ResolvedPos
AnchorPos() *ResolvedPos
Ranges() []SelectionRange
Empty() bool
Eq(Selection) bool
Map(doc *Node, m Mappable) Selection
Content() *Slice
Replace(tr *Transaction, content *Slice)
ReplaceWith(tr *Transaction, node *Node)
Bookmark() Bookmark
}
Selection is what is selected: text, a node, everything or a table's cells. Each kind maps through changes, gives its content as a Slice, replaces it, and has a bookmark that maps without a document.
func SelectionAtEnd ¶
SelectionAtEnd is the last selection in doc.
func SelectionAtStart ¶
SelectionAtStart is the first selection in doc.
func SelectionFindFrom ¶
func SelectionFindFrom(pos *ResolvedPos, dir int, textOnly bool) Selection
SelectionFindFrom is the first valid selection from pos going dir, a text one with textOnly; nil for none.
func SelectionFindFromOrNear ¶
func SelectionFindFromOrNear(pos *ResolvedPos, dir int) Selection
SelectionFindFromOrNear is the selection from pos going dir, else near.
func SelectionNear ¶
func SelectionNear(pos *ResolvedPos, bias int) Selection
SelectionNear is a valid selection near pos, bias the side looked at first.
func TextSelectionAt ¶
TextSelectionAt selects from anchor to head.
func TextSelectionBetween ¶
func TextSelectionBetween(anchor, head *ResolvedPos, bias int) Selection
TextSelectionBetween is the text selection nearest the two positions.
type SelectionRange ¶
type SelectionRange struct{ From, To *ResolvedPos }
SelectionRange is a range a selection covers.
type Session ¶
type Session struct {
// DispatchTransaction, when set, takes every transaction in place of
// Dispatch's applying it, the app committing with UpdateState.
DispatchTransaction func(tr *Transaction)
// contains filtered or unexported fields
}
Session is the one live editor a view and the app share, on the engine goroutine as the reactive graph is: it holds the state, applies transactions, runs commands and tells its subscribers.
func (*Session) Apply ¶
func (v *Session) Apply(tr *Transaction) error
Apply applies tr at once, dropping one that fails: the document stays as it was.
func (*Session) CoordsAtPos ¶
CoordsAtPos is the caret's box at pos in the view's content box, false with no view; it panics on a position outside the document, as Resolve.
func (*Session) Dispatch ¶
func (v *Session) Dispatch(tr *Transaction)
Dispatch applies tr, or hands it to DispatchTransaction.
func (*Session) DragBlock ¶
DragBlock starts a handle's drag at a point of the surface: it selects the block at pos, a table too, and carries it, or the siblings a selection over several covers when pos is in it, and says whether it did. DragTo moves the drop cursor, and EndDrag drops them there, as one undo step.
func (*Session) EndDrag ¶
EndDrag drops what a handle carries where its drop cursor is, and says whether the blocks moved.
func (*Session) Focus ¶
func (v *Session) Focus()
Focus and Blur are requests to the views showing it.
func (*Session) HandleKey ¶
HandleKey offers a key, by its name ("Mod-b", "Shift-Enter"), to the plugins, the first taking it.
func (*Session) OpenGap ¶
OpenGap fills a gap cursor with the textblock its place takes, and puts a text cursor in it, for an input method to compose there; it says whether it did.
func (*Session) PageCoordsAtPos ¶
PageCoordsAtPos is CoordsAtPos in the surface's points, for what the app places outside the editor, such as a block's handle.
func (*Session) PosAtCoords ¶
PosAtCoords is the position nearest a point of the content box.
func (*Session) PosAtPageCoords ¶
PosAtPageCoords is PosAtCoords from a point of the surface.
func (*Session) SelectionRect ¶
SelectionRect is the box over the selection's lines.
func (*Session) SetContent ¶
SetContent replaces the document, kept out of the history.
func (*Session) SetEditable ¶
SetEditable sets whether the user can change the document.
func (*Session) Subscribe ¶
func (v *Session) Subscribe(f func(s *State, trs []*Transaction)) func()
Subscribe calls f after every change, and the returned function stops it.
func (*Session) TypeText ¶
TypeText types text as a user does: input rules first, then the stored marks, tagged with an input method's composition.
func (*Session) UpdateState ¶
UpdateState replaces the state.
type SessionConfig ¶
type SessionConfig struct {
Extensions []Extension
Schema *Schema
Plugins []*Plugin
Doc *Node
Markdown string
JSON string
HTML string
// ReadOnly keeps the user from changing it.
ReadOnly bool
}
SessionConfig makes a Session: Extensions make its schema and plugins, or Schema and Plugins give them. Content is a Markdown text, unless Doc gives the document or JSON Tiptap's.
type Slice ¶
Slice is a piece of a document: content with OpenStart and OpenEnd levels open on each side.
func SliceFromText ¶
func SliceFromText(s *Schema, text string, r *ResolvedPos) *Slice
SliceFromText is pasted text as a slice: lines of the default block, a paragraph per run, in code as the text it is.
func (*Slice) RemoveBetween ¶
RemoveBetween is the slice without from to to.
type StarterOptions ¶
type StarterOptions struct {
// Levels are the headings' levels, 1 to 6 when nil.
Levels []int
History HistoryOptions
NoHistory, NoTrailingNode, NoTaskList, NoTypography bool
NoGapCursor bool
Link LinkOptions
}
StarterOptions leave parts of StarterKit out, or tune them.
type State ¶
type State struct {
Schema *Schema
Doc *Node
Selection Selection
StoredMarks []*Mark
Plugins []*Plugin
// Revision counts the transactions applied.
Revision int
// contains filtered or unexported fields
}
State is an editor's state, never changed once made: Apply returns a new one, which is what history and the view's updates rely on.
func NewState ¶
func NewState(c StateConfig) (*State, error)
NewState makes a state, refusing two plugins with one key.
func (*State) Apply ¶
func (s *State) Apply(tr *Transaction) (*State, error)
Apply applies tr, the new state alone.
func (*State) ApplyTransaction ¶
func (s *State) ApplyTransaction(root *Transaction) (*State, []*Transaction, error)
ApplyTransaction applies tr and what plugins append to it, atomically: the new state, and every transaction applied. A filtered transaction leaves the state.
func (*State) PluginState ¶
PluginState is plugin key's field.
func (*State) Reconfigure ¶
Reconfigure is the state with other plugins, whose fields start again unless a plugin stays.
type StateConfig ¶
type StateConfig struct {
Schema *Schema
Doc *Node
Selection Selection
StoredMarks []*Mark
Plugins []*Plugin
}
StateConfig makes a state: Doc, or an empty document of Schema.
type StateError ¶
type StateError struct{ Msg string }
StateError says a transaction could not apply.
func (*StateError) Error ¶
func (e *StateError) Error() string
type Step ¶
type Step interface {
Apply(doc *Node) (*Node, error)
StepMap() *StepMap
Invert(doc *Node) Step
// Map is the step over another change, nil when that deleted it.
Map(m Mappable) Step
// Merge joins the step with the next, nil when it cannot.
Merge(other Step) Step
}
Step is one change of a document: it applies or fails, maps positions, inverts against the document it applied to and maps over other changes.
type StepMap ¶
type StepMap struct {
// contains filtered or unexported fields
}
StepMap is how a step moves positions: triples of a start, an old size and a new size.
type Styles ¶
type Styles struct {
// Content is the box that scrolls, whose padding is the text's.
Content core.Style
// Nodes style blocks by type name, then "type[attr=value]"; Marks
// inline text by mark name, as "mention" does its leaves.
Nodes, Marks map[string]core.Style
// Placeholder is the text of an empty document; Caret the caret, 2
// points wide unless it gives a width; Selection behind selected text;
// Composition what an input method composes; GapCursor the cursor
// between blocks, 20 by 2 points unless it gives a size; DropCursor
// the line where blocks a handle drags will land, 2 points tall.
Placeholder, Caret, Selection, Composition, GapCursor, DropCursor core.Style
// SelectedNode goes on the block a node selection holds, and SelectedCell
// on the box in each selected cell.
SelectedNode, SelectedCell core.Style
// SelectionHandle is the knobs at a touch selection's ends.
SelectionHandle core.Style
// ListMarker is the marker a list's item shows; TaskCheckbox a task
// item's box, whose Selected state is its check.
ListMarker, TaskCheckbox core.Style
// TableResizeHandle is the line of a column or row being resized;
// TableGrip a table's grip over a column or beside a row;
// TableDropIndicator the line where one dragged will land.
TableResizeHandle, TableGrip, TableDropIndicator core.Style
}
Styles are the styles of the editor's parts, which supply its whole look.
type SuggestionOptions ¶
type SuggestionOptions struct {
// Key names it among an editor's, "suggestion" when "".
Key string
// Char is what starts it, "@" when "".
Char string
// AllowSpaces lets a query hold spaces.
AllowSpaces bool
// AllowedPrefixes are what may go before Char, " " and a line's start
// when nil.
AllowedPrefixes []string
// Allow says a match may become active.
Allow func(s *State, from, to int) bool
// Class goes on the active range.
Class string
// CaptureKeys are taken while it is active, for the app's list.
CaptureKeys []string
// OnKey hears keys while it is active, and those it returns true for
// are taken.
OnKey func(key string) bool
}
SuggestionOptions tune a Suggestion.
type SuggestionState ¶
type SuggestionState struct {
Active bool
From, To int
Query string
// Text is the trigger and the query.
Text string
// LastKey and KeyCount say what was captured, for an app reading them
// after the fact.
LastKey string
KeyCount int
// contains filtered or unexported fields
}
SuggestionState is what a Suggestion's plugin holds.
func SuggestionStateOf ¶
func SuggestionStateOf(s *State, key string) *SuggestionState
SuggestionStateOf is the state of the Suggestion keyed key.
type TableMap ¶
TableMap is a table's grid, each slot the cell covering it as an offset from the table's start.
func (*TableMap) CellsInRect ¶
CellsInRect are the cells whose top left is in rect.
func (*TableMap) NextCell ¶
NextCell is the cell next to the one at pos on axis ("horiz" or "vert"), -1 for none.
func (*TableMap) PositionAt ¶
PositionAt is where a cell at row and col of the table would go.
func (*TableMap) RectBetween ¶
RectBetween is the rectangle around the cells at a and b, grown over the cells it cuts.
type TableOptions ¶
type TableOptions struct {
CellMinWidth float64
// NotResizable keeps tables from resizing by their handles.
NotResizable, LastColumnNotResizable bool
}
Table are a table's Tiptap options.
type TextSelection ¶
type TextSelection struct {
// contains filtered or unexported fields
}
TextSelection is a caret or range in inline content.
func NewTextSelection ¶
func NewTextSelection(anchor, head *ResolvedPos) *TextSelection
NewTextSelection selects from anchor to head, which sit in inline content; head is anchor when nil.
func (*TextSelection) AnchorPos ¶
func (s *TextSelection) AnchorPos() *ResolvedPos
func (*TextSelection) Bookmark ¶
func (s *TextSelection) Bookmark() Bookmark
func (*TextSelection) Cursor ¶
func (s *TextSelection) Cursor() *ResolvedPos
Cursor is the empty selection at the head, nil unless it is one.
func (*TextSelection) Eq ¶
func (s *TextSelection) Eq(o Selection) bool
func (*TextSelection) FromPos ¶
func (s *TextSelection) FromPos() *ResolvedPos
func (*TextSelection) HeadPos ¶
func (s *TextSelection) HeadPos() *ResolvedPos
func (*TextSelection) Ranges ¶
func (s *TextSelection) Ranges() []SelectionRange
func (*TextSelection) Replace ¶
func (s *TextSelection) Replace(tr *Transaction, content *Slice)
func (*TextSelection) ReplaceWith ¶
func (s *TextSelection) ReplaceWith(tr *Transaction, node *Node)
func (*TextSelection) ToPos ¶
func (s *TextSelection) ToPos() *ResolvedPos
type Transaction ¶
type Transaction struct {
Transform
Time time.Time
Origin Origin
// contains filtered or unexported fields
}
Transaction is one user action's changes: a Transform with the state's selection, stored marks, metadata and an origin.
func CloseHistory ¶
func CloseHistory(tr *Transaction) *Transaction
CloseHistory has the next change start a new undo step.
func (*Transaction) AddMark ¶
func (tr *Transaction) AddMark(from, to int, mark *Mark) *Transaction
func (*Transaction) AddStoredMark ¶
func (tr *Transaction) AddStoredMark(m *Mark) *Transaction
AddStoredMark adds a mark to the ensured marks.
func (*Transaction) Delete ¶
func (tr *Transaction) Delete(from, to int) *Transaction
func (*Transaction) DeleteRange ¶
func (tr *Transaction) DeleteRange(from, to int) *Transaction
func (*Transaction) DeleteSelection ¶
func (tr *Transaction) DeleteSelection() *Transaction
DeleteSelection deletes the selection.
func (*Transaction) EnsureMarks ¶
func (tr *Transaction) EnsureMarks(marks []*Mark) *Transaction
EnsureMarks keeps marks as the stored marks unless the selection's place has them.
func (*Transaction) Insert ¶
func (tr *Transaction) Insert(pos int, content ...*Node) *Transaction
func (*Transaction) InsertText ¶
func (tr *Transaction) InsertText(text string, from, to int) *Transaction
InsertText inserts text from from to to, or over the selection when from is negative, with the marks there, and puts the cursor after it.
func (*Transaction) Join ¶
func (tr *Transaction) Join(pos, depth int) *Transaction
func (*Transaction) Lift ¶
func (tr *Transaction) Lift(r *NodeRange, target int) *Transaction
func (*Transaction) Meta ¶
func (tr *Transaction) Meta(key any) any
Meta reads a value stored under key.
func (*Transaction) RemoveMark ¶
func (tr *Transaction) RemoveMark(from, to int, mark *Mark, typ *MarkType) *Transaction
func (*Transaction) RemoveStoredMark ¶
func (tr *Transaction) RemoveStoredMark(t *MarkType) *Transaction
RemoveStoredMark removes a mark type from the ensured marks.
func (*Transaction) Replace ¶
func (tr *Transaction) Replace(from, to int, slice *Slice) *Transaction
func (*Transaction) ReplaceRange ¶
func (tr *Transaction) ReplaceRange(from, to int, slice *Slice) *Transaction
func (*Transaction) ReplaceRangeWith ¶
func (tr *Transaction) ReplaceRangeWith(from, to int, node *Node) *Transaction
func (*Transaction) ReplaceSelection ¶
func (tr *Transaction) ReplaceSelection(slice *Slice) *Transaction
ReplaceSelection replaces the selection with slice.
func (*Transaction) ReplaceSelectionWith ¶
func (tr *Transaction) ReplaceSelectionWith(node *Node, inheritMarks bool) *Transaction
ReplaceSelectionWith replaces the selection with node, which takes the marks there when inheritMarks.
func (*Transaction) ReplaceWith ¶
func (tr *Transaction) ReplaceWith(from, to int, content ...*Node) *Transaction
func (*Transaction) ScrollIntoView ¶
func (tr *Transaction) ScrollIntoView() *Transaction
ScrollIntoView has the view reveal the selection.
func (*Transaction) ScrolledIntoView ¶
func (tr *Transaction) ScrolledIntoView() bool
ScrolledIntoView says the view should reveal the selection.
func (*Transaction) Selection ¶
func (tr *Transaction) Selection() Selection
Selection is the transaction's selection, mapped through its steps.
func (*Transaction) SelectionSet ¶
func (tr *Transaction) SelectionSet() bool
SelectionSet says the selection was set.
func (*Transaction) SetBlockType ¶
func (tr *Transaction) SetBlockType(from, to int, typ *NodeType, attrs func(*Node) Attrs) *Transaction
func (*Transaction) SetMeta ¶
func (tr *Transaction) SetMeta(key, value any) *Transaction
SetMeta stores a value under key.
func (*Transaction) SetNodeAttribute ¶
func (tr *Transaction) SetNodeAttribute(pos int, attr string, value any) *Transaction
func (*Transaction) SetNodeMarkup ¶
func (tr *Transaction) SetNodeMarkup(pos int, typ *NodeType, attrs Attrs, marks []*Mark) *Transaction
func (*Transaction) SetSelection ¶
func (tr *Transaction) SetSelection(s Selection) *Transaction
SetSelection sets the selection, which drops the stored marks.
func (*Transaction) SetStoredMarks ¶
func (tr *Transaction) SetStoredMarks(marks []*Mark) *Transaction
SetStoredMarks sets the marks the next typed text takes.
func (*Transaction) Split ¶
func (tr *Transaction) Split(pos, depth int, typesAfter []NodeTypeAttrs) *Transaction
func (*Transaction) Step ¶
func (tr *Transaction) Step(s Step) *Transaction
func (*Transaction) StoredMarks ¶
func (tr *Transaction) StoredMarks() []*Mark
StoredMarks are the marks stored now: any step drops them.
func (*Transaction) Wrap ¶
func (tr *Transaction) Wrap(r *NodeRange, wrappers []NodeTypeAttrs) *Transaction
type Transform ¶
Transform collects steps, the documents between them and their mapping. A step that fails leaves it unchanged and sets Err, after which it takes no more.
func (*Transform) ClearIncompatible ¶
func (t *Transform) ClearIncompatible(pos int, typ *NodeType, match *ContentMatch) *Transform
ClearIncompatible drops what a node of t at pos could not hold.
func (*Transform) DeleteRange ¶
DeleteRange deletes from to to, growing it over nodes it covers whole.
func (*Transform) RemoveMark ¶
RemoveMark removes mark from from to to; with a nil mark every mark, and with a type its marks by it.
func (*Transform) ReplaceRange ¶
ReplaceRange replaces from to to with slice, moving the range up and the slice open as what is selected and pasted suggest.
func (*Transform) ReplaceRangeWith ¶
ReplaceRangeWith replaces from to to with node.
func (*Transform) ReplaceWith ¶
ReplaceWith replaces from to to with content.
func (*Transform) SetBlockType ¶
SetBlockType sets the textblocks from from to to to typ.
func (*Transform) SetNodeAttribute ¶
SetNodeAttribute sets one attribute of the node at pos.
func (*Transform) SetNodeMarkup ¶
SetNodeMarkup changes the node at pos, keeping its content.
type View ¶
type View struct {
// Editor is the session it shows; without one it makes its own of
// StarterKit and TableKit from Markdown.
Editor *Session
Markdown string
// Placeholder shows while the document is empty.
Placeholder string
// NodeViews render node types by name: a block's in place of its own,
// an inline node's as a view in the line where the node stands.
NodeViews map[string]NodeView
// BubbleMenu is the app's content in an overlay over the selection's
// lines, shown while it returns one.
BubbleMenu func() core.Node
// BubbleMenuPlacement is its side, above when 0, and BubbleMenuOffset
// its gap.
BubbleMenuPlacement core.Placement
BubbleMenuOffset core.Points
// OnChange receives the revision after a change of the document,
// and OnSelectionChange after a move of the selection: read them from
// the session.
OnChange func(revision int)
OnSelectionChange func(s Selection)
// OnPasteFiles receives pasted files and images, which insert nothing.
OnPasteFiles func(paths []string)
OnFocus func()
OnBlur func()
AutoFocus bool
Label string
Classes Classes
Styles Styles
StylesFunc func() Styles
Class string
Style core.Style
StyleFunc func() core.Style
TestID string
// OnLayout and Tooltip are its view's, as a core.View's.
OnLayout func(core.Bounds)
Tooltip core.Node
Ref *Ref
}
View is a rich text editor over a Session: the document's blocks in a scroll view, the app styling every part (Classes, Styles), with typing, input methods composing in the line, selections by press and drag, keys through the session's keymaps, and tables' handles while they can be edited.
Source Files
¶
- blockdrag.go
- commands.go
- content.go
- fit.go
- format.go
- gapcursor.go
- geometry.go
- history.go
- html.go
- input.go
- inputrules.go
- keymap.go
- kit.go
- link.go
- markdown.go
- node.go
- resolve.go
- schema.go
- selection.go
- session.go
- state.go
- step.go
- tablecommands.go
- tablemap.go
- tablepaste.go
- tableview.go
- touch.go
- transaction_steps.go
- transform.go
- view.go