Documentation
¶
Overview ¶
Package richeditor gives TSX nsgo/base's RichEditor and its sessions, which link packages other apps should not: an app whose TSX uses them imports this package for its effect.
An app makes a session with createRichEditor from extensions (the built-in StarterKit, TableKit, Mention and CharacterCount, and its own from defineExtension) and plugins whose hooks are its functions, drives it with commands as data (command, chain, toggleMark, …), and shows it with <RichEditor editor={editor} />.
Index ¶
- type Command
- type Editor
- func (e *Editor) Blur()
- func (e *Editor) Can(c *Command) (bool, error)
- func (e *Editor) Characters(nodes bool) int
- func (e *Editor) Close() error
- func (e *Editor) CoordsAtPos(pos int) (RichRect, bool, error)
- func (e *Editor) DocJSON() map[string]any
- func (e *Editor) DragBlock(pos int, x, y float64) (bool, error)
- func (e *Editor) DragTo(x, y float64)
- func (e *Editor) Editable() bool
- func (e *Editor) EndDrag() bool
- func (e *Editor) Focus()
- func (e *Editor) GetAttributes(name string) map[string]any
- func (e *Editor) HTML() string
- func (e *Editor) IsActive(name string, attrs map[string]any) bool
- func (e *Editor) IsFocused() bool
- func (e *Editor) Markdown() string
- func (e *Editor) On(event string, handler func(RichEditorEvent)) func()
- func (e *Editor) PageCoordsAtPos(pos int) (RichRect, bool, error)
- func (e *Editor) PosAtCoords(x, y float64) (int, bool)
- func (e *Editor) PosAtPageCoords(x, y float64) (int, bool)
- func (e *Editor) RedoDepth() int
- func (e *Editor) Revision() int
- func (e *Editor) Run(c *Command) (bool, error)
- func (e *Editor) Selection() RichSelection
- func (e *Editor) SelectionRect() (RichRect, bool)
- func (e *Editor) SetContent(content any) error
- func (e *Editor) SetEditable(on bool)
- func (e *Editor) SetHTML(html string) error
- func (e *Editor) Size() int
- func (e *Editor) Suggestion(key string) (RichSuggestion, bool)
- func (e *Editor) Text() string
- func (e *Editor) UndoDepth() int
- func (e *Editor) Words() int
- type Extension
- type RichClickEvent
- type RichDecoration
- type RichEditorEvent
- type RichEditorOptions
- type RichExtensionSpec
- type RichGlobalAttributes
- type RichInputRule
- type RichMarkSpec
- type RichNodeSpec
- type RichPasteEvent
- type RichPluginSpec
- type RichRect
- type RichSelection
- type RichSuggestion
- type RichTextInputEvent
- type RichTransactionInfo
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command is RichCommand: an edit as data, resolved against the editor it runs in, so a named command is that editor's and a type name its schema's.
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor is RichEditorSession: the session a RichEditor shows and the app drives, its document and selection read on demand.
func (*Editor) Characters ¶
Characters counts the document's characters, every position with nodes; Words its words.
func (*Editor) CoordsAtPos ¶
CoordsAtPos is the caret's box at pos in the editor's content box, null with no view showing it.
func (*Editor) DragBlock ¶
DragBlock starts a handle's drag at a point of the page, carrying the block at pos, DragTo moves its drop cursor and EndDrag drops it, as one undo step.
func (*Editor) Focus ¶
func (e *Editor) Focus()
Focus and Blur are requests to the views showing it.
func (*Editor) GetAttributes ¶
GetAttributes are the attributes of the mark or node of name at the selection, empty for none.
func (*Editor) IsActive ¶
IsActive says whether the node or mark of name, with attrs, is at the selection.
func (*Editor) On ¶
func (e *Editor) On(event string, handler func(RichEditorEvent)) func()
On listens to an event (revision, update, selectionUpdate, transaction, focus, blur, destroy) and returns what stops it.
func (*Editor) PageCoordsAtPos ¶
PageCoordsAtPos and PosAtPageCoords answer in the page's points, for what the app places outside the editor.
func (*Editor) PosAtCoords ¶
PosAtCoords is the position nearest a point of the content box.
func (*Editor) PosAtPageCoords ¶
PosAtPageCoords is the position nearest a point of the page.
func (*Editor) Selection ¶
func (e *Editor) Selection() RichSelection
Selection is the selection now.
func (*Editor) SelectionRect ¶
SelectionRect is the box over the selection's lines.
func (*Editor) SetContent ¶
SetContent replaces the document, kept out of the history: a string is Markdown, an object Tiptap's JSON.
func (*Editor) SetEditable ¶
SetEditable sets whether the user can change the document.
func (*Editor) Suggestion ¶
func (e *Editor) Suggestion(key string) (RichSuggestion, bool)
Suggestion is the suggestion of key, null when it has none.
type Extension ¶
type Extension struct {
// contains filtered or unexported fields
}
Extension is RichExtension: Tiptap's extension, a built-in one or the app's, made into the kernel's as createRichEditor builds the editor.
func CharacterCount ¶
CharacterCount limits the characters to limit, counting every position with mode "nodes".
func Mention ¶
Mention is Tiptap's mention and its suggestion: char, key, allowSpaces, class and the captureKeys its list takes.
func StarterKit ¶
StarterKit is the kit of Tiptap's usual types: levels for headings, false for history, trailingNode, taskList, typography or gapcursor to leave one out, history's depth and newGroupDelay, and link's autolink, openOnClick and protocols.
type RichClickEvent ¶
RichClickEvent is a press at a position, Clicks in a row, Mod held or not.
type RichDecoration ¶
type RichDecoration struct {
From, To int
Class string
Node bool
Widget func() core.Node
Side int
Key string
}
RichDecoration styles a range without changing the document: Class on its text, or on the block at From with Node; with Widget, a view in the text at From, before a cursor there when Side is below zero, kept while Key stays.
type RichEditorEvent ¶
RichEditorEvent is what an editor's events carry.
type RichEditorOptions ¶
type RichEditorOptions struct {
Extensions []*Extension
Markdown string
HTML string
JSON map[string]any
Plugins []RichPluginSpec
// Editable false keeps the user from changing the document.
Editable *bool
// OpenLink opens a link pressed with Mod, or in a read-only editor.
OpenLink func(href string)
}
RichEditorOptions are createRichEditor's: the extensions, StarterKit and TableKit when none, the document as Markdown, HTML or Tiptap's JSON, and plugins after the extensions'.
type RichExtensionSpec ¶
type RichExtensionSpec struct {
Name string
Priority int
Node *RichNodeSpec
Mark *RichMarkSpec
// AddOptions gives the defaults under what configure sets.
AddOptions func() map[string]any
AddGlobalAttributes func(options map[string]any) []RichGlobalAttributes
AddKeyboardShortcuts func(options map[string]any) map[string]*Command
AddCommands func(options map[string]any) map[string]func(args map[string]any) *Command
AddInputRules func(options map[string]any) []RichInputRule
AddProseMirrorPlugins func(options map[string]any) []RichPluginSpec
}
RichExtensionSpec is defineExtension's, Tiptap's extension config: a node or a mark named after it, and functions of its options run once as an editor is made, returning data.
type RichGlobalAttributes ¶
RichGlobalAttributes add attributes to other types.
type RichInputRule ¶
type RichInputRule struct {
Find *regexp.Regexp
Type string
Name string
Replace string
Attrs map[string]any
}
RichInputRule changes text as it is typed: Find, ending at the cursor ("$"), becomes a mark ("mark", its last group the text), a textblock ("textblock"), wraps the block ("wrapping") or is replaced by Replace ("text"). Name is the type, the extension's own when "".
type RichMarkSpec ¶
type RichMarkSpec struct {
Attrs map[string]map[string]any
// Inclusive false keeps text typed at its end out of it.
Inclusive *bool
Excludes, Group string
Extra map[string]any
}
RichMarkSpec is a mark type.
type RichNodeSpec ¶
type RichNodeSpec struct {
Content, Marks, Group string
Inline, Atom, Code bool
Defining, Isolating bool
// Selectable false keeps node selections off it.
Selectable *bool
Whitespace string
Attrs map[string]map[string]any
// LeafText is a leaf as text, RenderText what the view shows for an
// inline leaf, of its attributes.
LeafText, RenderText func(attrs map[string]any) string
Extra map[string]any
}
RichNodeSpec is a node type: ProseMirror's spec, attrs by name with their defaults ({ level: { default: 1 } }), and what it is as text.
type RichPasteEvent ¶
type RichPasteEvent struct{ Text string }
RichPasteEvent is what is pasted, as text.
type RichPluginSpec ¶
type RichPluginSpec struct {
// Key names it among the editor's plugins.
Key string
// Keys bind keys by ProseMirror's names ("Mod-k") to commands.
Keys map[string]*Command
HandleKeyDown func(editor *Editor, key string) bool
HandleTextInput func(editor *Editor, event RichTextInputEvent) bool
HandleClick func(editor *Editor, event RichClickEvent) bool
HandlePaste func(editor *Editor, event RichPasteEvent) bool
// Decorations are what the view draws over the editor's state.
Decorations func(editor *Editor) []RichDecoration
// FilterTransaction refuses a transaction before it applies, the
// editor's state still the one before it.
FilterTransaction func(editor *Editor, tr RichTransactionInfo) bool
// AppendTransaction may answer transactions that applied with a
// command, run on the state they left.
AppendTransaction func(editor *Editor, tr RichTransactionInfo) *Command
}
RichPluginSpec is a plugin whose behavior is the app's: a keymap and hooks the editor calls with itself, asked in plugin order, the first true taking the event.
type RichSelection ¶
RichSelection is a selection as JS reads it: its kind ("text", "node", "all", "cell", "gap") and positions.
type RichSuggestion ¶
RichSuggestion is an active suggestion's, as a mention list reads it.
type RichTextInputEvent ¶
RichTextInputEvent is text typed over from to to.
type RichTransactionInfo ¶
RichTransactionInfo is what JS reads of a transaction.
type View ¶
type View struct {
Editor *Editor
Markdown string
Placeholder string
BubbleMenu func() core.Node
BubbleMenuPlacement core.Placement
BubbleMenuOffset core.Points
OnChange func(revision int)
OnSelectionChange func(selection RichSelection)
OnFocus, OnBlur func()
AutoFocus bool
Label string
Classes richeditor.Classes
Styles richeditor.Styles
Class string
Style core.Style
TestID string
OnLayout func(core.Bounds)
Tooltip core.Node
}
View is RichEditor in TSX: base/richeditor's View over a RichEditorSession, else over a session of its own from Markdown.
func (View) Base ¶
func (v View) Base() richeditor.View
Base is the Go view it shows, for a styled form to give its look.