EditorBridge
An Interface of all the commands you can do with the editor on the react native side, can be extended with a BridgeExtension. With all of the bridges included in TenTapStartKit the EditorBridge will have the methods below.
A method only exists when its bridge is in bridgeExtensions. For example, toggleBold is added by BoldBridge; if you pass your own bridgeExtensions array without it, toggleBold is missing from both the object and its type.
Commands can be called right away, even before the editor has loaded. They are queued and sent in order once the editor is ready.
focus
(pos?: 'start' | 'end' | 'all' | number | boolean | null) => void
a function that will focus the editor and open the keyboard. If a custom keyboard is open, it closes and the system keyboard comes back.
extended by CoreBridge
blur
a function that will blur the editor and close the keyboard
extended by CoreBridge
webviewRef
RefObject<WebView>
a ref for the webview that renders the editor
extended by CoreBridge
getEditorState
() => BridgeState
a function that will return the most up to date BridgeState
extended by CoreBridge
getHTML
() => Promise<string>
an async function that will return the content of the editor in html format. List items are always wrapped in a paragraph (<li><p>…</p></li>); see Rendering editor HTML if you display the HTML outside the editor.
extended by CoreBridge
getText
() => Promise<string>
an async function that will return the content of the editor in text format
extended by CoreBridge
getJSON
() => Promise<object>
an async function that will return the content of the editor in json format
extended by CoreBridge
getSelectedText
(range?: { from: number; to: number }) => Promise<string>
an async function that returns the text of the current selection, read from the live editor inside the WebView. Pass a range to read another part of the document instead. Blocks are separated by \n, matching what the system "Copy" gives you.
const selected = await editor.getSelectedText();
const text = await editor.getSelectedText({ from: 1, to: 20 });
from and to are ProseMirror positions, the same numbers as BridgeState.selection, not character offsets into getText(). Out of range values are clamped to the document.
Rejects with TentapUnsupportedError when the editor runs a custom bundle built with an older version; rebuild the bundle to use it.
extended by CoreBridge
setContent
(content: Content, options?: { parseOptions?: ParseOptions; emitUpdate?: boolean }) => void
a function that gets html as string or document object and sets it as the editor's content.
parseOptionsoverrides the editor-level parseOptions for this call, e.g.{ preserveWhitespace: 'full' }.emitUpdate(defaulttrue) controls whether the change triggersonChangeand useEditorContent.
extended by CoreBridge
insertContent
(content: Content) => void
inserts HTML, plain text or TipTap JSON at the cursor, replacing the current selection if there is one, and focuses the editor. HTML is parsed with the editor's parseOptions. It works with the default editor, no custom bundle needed.
editor.insertContent('<strong>Hello</strong> world');
editor.insertContent('just some text');
The content still has to fit the editor's schema: a custom node type needs a bridge extension that defines it (advanced setup). A custom bundle built with an older version ignores the command; rebuild the bundle to use it.
extended by CoreBridge
setEditable
(editable: boolean) => void
a function that sets the editable state
extended by CoreBridge
setSelection
(from: number, to: number) => void
sets the selection of the editor
extended by CoreBridge
injectCSS
(css: string, tag?: string) => void
creates or updates the stylesheet with the given tag, see Dynamically Updating CSS. The stylesheet is re-applied if the WebView reloads. For CSS that has to be there from the first paint, such as fonts, use configureCSS on a bridge instead.
default tag: custom-css
available on every editor, also without CoreBridge
injectJS
(js: string) => void
inject custom javascript into the editor's webview. Calls made before the editor is ready are queued.
extended by CoreBridge
updateScrollThresholdAndMargin
(offset: number) => void
a function that gets offset in px and changes scrollThreshold scrollMargin. RichText sets this itself when the keyboard opens or closes; to keep extra space permanently, use the scrollBottomOffset option.
extended by CoreBridge
toggleBold
() => void
will toggle bold on the editor if possible
extended by BoldBridge
toggleItalic
() => void
will toggle italic on the editor if possible
extended by ItalicBridge
toggleUnderline
() => void
will toggle underline on the editor if possible
extended by UnderlineBridge
toggleStrike
() => void
will toggle strikethrough on the editor if possible
extended by StrikeBridge
toggleCode
() => void
will toggle inline code on the editor if possible
extended by CodeBridge
toggleBlockquote
() => void
will toggle blockquote on the editor if possible
extended by BlockquoteBridge
toggleBulletList
() => void
will toggle bullet list on the editor if possible
extended by BulletListBridge
toggleOrderedList
() => void
will toggle order list on the editor if possible
extended by OrderedListBridge
toggleHeading
(level: 1 | 2 | 3 | 4 | 5 | 6) => void
gets level and toggles heading on the editor if possible
extended by HeadingBridge
lift
() => void
will lift the list item on the editor if possible
extended by ListItemBridge
sink
() => void
will sink the list item on the editor if possible
extended by ListItemBridge
toggleTaskList
() => void
will toggle task list on the editor if possible
extended by TaskListBridge
liftTaskListItem
() => void
will lift the task list item on the editor if possible
extended by TaskListBridge
sinkTaskListItem
() => void
will sink the task list item on the editor if possible
extended by TaskListBridge
undo
() => void
will undo the last history transaction if possible
extended by HistoryBridge
redo
() => void
will redo the last undo transaction if possible
extended by HistoryBridge
setColor
(color: string) => void
sets text color
extended by ColorBridge
unsetColor
() => void
un-sets text color
extended by ColorBridge
setHighlight
(color: string) => void
sets text highlight
extended by HighlightBridge
toggleHighlight
(color: string) => void
toggles text highlight
extended by HighlightBridge
unsetHighlight
() => void
un-sets text highlight
extended by HighlightBridge
setImage
(src: string) => void
gets image url string and inserts an image. If the image ends up as the last block of the document, an empty paragraph is added after it and the cursor moves there, so you can keep typing below it.
extended by ImageBridge
setLink
(link: string | null) => void
gets link url as string and sets link. '' removes the link and null does nothing. A URL without a scheme gets one added (www.google.com becomes https://www.google.com); see LinkBridge.
extended by LinkBridge
setPlaceholder
(newPlaceholder: string) => void
will change the placeholder on run time
extended by PlaceholderBridge
setHardBreak
() => void
inserts a line break (<br>) at the cursor
extended by HardBreakBridge
Errors
The async methods can reject with these errors, both exported from @10play/tentap-editor:
| Error | When |
|---|---|
TentapRpcTimeoutError | The WebView didn't answer within rpcTimeoutMs. Has requestType and timeoutMs. |
TentapUnsupportedError | The editor bundle doesn't support the method, usually a custom bundle built with an older version. Has capability. |