Rich text / foldkit-mixins-richtext
The table and code toolbars
Toolbars for a block, drawn above it in an element blockAnchor({ side: 'above' }) places. The
table toolbar edits the table around the caret's cell; the code toolbar picks a code block's
language and copies it.
ts
import * as RichText from 'foldkit-richtext'
import { blockAnchor } from 'foldkit-richtext-dom/toolbar'
import { codeToolbar, tableToolbar } from 'foldkit-mixins-richtext'
const table = RichText.tableAt(model.document, model.editor.selection)
table === undefined
? h.empty
: h.div(
[
h.Key(table.table.id),
h.OnMount(blockAnchor({ hostId: 'body', node: table.table.id, gap: 6, side: 'above' })),
],
[
tableToolbar<Message>()(
{ document: model.document, selection: model.editor.selection, wrap: edited },
h,
),
],
)
codeToolbar<Message>()(
{
document: model.document,
node: code.id,
languages: [{ id: 'typescript', label: 'TypeScript' }, { id: '', label: 'Plain text' }],
wrap: edited,
copied: Message.CopiedCode({ node: code.id }),
},
h,
)- The table toolbar sends the editor's
InsertedRowandInsertedColumn(before,after),DeletedRow,DeletedColumn,DeletedBlockfor the whole table, andChangedPropson the first row'sheader, which its button shows pressed. Every button is disabled outside a table (RichText.tableAtfinds none), so it can be drawn always or only there. The editor takes Tab and Shift+Tab in a cell to move between cells, and Tab in the last adds a row. - The code toolbar shows the block's
languagein a picker and sets it withChangedProps, so it is saved and undone with the text; a language the list does not name is offered as itself. Copy sends the caller's Message, since the clipboard is a Command: copyRichText.toText([block]).
| Slot | Capability | Renders |
|---|---|---|
TableToolbarSlots.root | Container | the wrapper |
TableToolbarSlots.toolbar | Collection | role="toolbar" |
TableToolbarSlots.button | Interactive | one per change, data-table (row-above, …) |
CodeToolbarSlots.root | Container | role="toolbar" |
CodeToolbarSlots.language | Interactive | the select |
CodeToolbarSlots.copy | Interactive | data-code="copy" |