You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Leaving this here as a rough start to writing the docs for adding tables:
We have a custom editor:
// This custom editor// extends the default tiptap editor to have a toolbar// with table editing buttons in it.import{html}from"lit"import{TipTapEditor}from"rhino-editor/exports/elements/tip-tap-editor.js"import*astable_iconsfrom"./table_icons.js"import*astable_translationsfrom"./table_translations.js"classCustomEditorextendsTipTapEditor{renderToolbar(){if(this.readonly)returnhtml``;returnhtml`<slotname="toolbar"><role-toolbarclass="toolbar" part="toolbar" role="toolbar"><slotname="toolbar-start">${this.renderToolbarStart()}</slot><!-- Bold --><slotname="before-bold-button"></slot><slotname="bold-button">${this.renderBoldButton()}</slot><slotname="after-bold-button"></slot><!-- Italic --><slotname="before-italic-button"></slot><slotname="italic-button">${this.renderItalicButton()}</slot><slotname="after-italic-button"></slot><!-- Strike --><slotname="before-strike-button"></slot><slotname="strike-button">${this.renderStrikeButton()}</slot><slotname="after-strike-button"></slot><!-- Link --><slotname="before-link-button"></slot><slotname="link-button">${this.renderLinkButton()}</slot><slotname="after-link-button"></slot><!-- Heading --><slotname="before-heading-button"></slot><slotname="heading-button">${this.renderHeadingButton()}</slot><slotname="after-heading-button"></slot><!-- Blockquote --><slotname="before-blockquote-button"></slot><slotname="blockquote-button">${this.renderBlockquoteButton()}</slot><slotname="after-blockquote-button"></slot><!-- Code block --><slotname="before-code-block-button"></slot><slotname="code-block-button">${this.renderCodeBlockButton()}</slot><slotname="after-code-block-button"></slot><!-- Bullet List --><slotname="before-bullet-list-button"></slot><slotname="bullet-list-button">${this.renderBulletListButton()}</slot><slotname="after-bullet-list-button"></slot><!-- Ordered list --><slotname="before-ordered-list-button"></slot><slotname="ordered-list-button">${this.renderOrderedListButton()}</slot><slotname="after-ordered-list-button"></slot><slotname="before-decrease-indentation-button"></slot><slotname="decrease-indentation-button">${this.renderDecreaseIndentation()}</slot><slotname="after-decrease-indentation-button"></slot><slotname="before-increase-indentation-button"></slot><slotname="increase-indentation-button">${this.renderIncreaseIndentation()}</slot><slotname="after-increase-indentation-button"></slot><slotname="table-button">${this.renderTableButton()}</slot><!-- Attachments --><slotname="before-attach-files-button"></slot><slotname="attach-files-button">${this.renderAttachmentButton()}</slot><slotname="after-attach-files-button"></slot><!-- Undo --><slotname="before-undo-button"></slot><!-- @ts-expect-error --><slotname="undo-button">${this.renderUndoButton()}</slot><slotname="after-undo-button"></slot><!-- Redo --><slotname="before-redo-button"></slot><slotname="redo-button">${this.renderRedoButton()}</slot><slotname="after-redo-button"></slot><slotname="toolbar-end">${this.renderToolbarEnd()}</slot></role-toolbar>${this.renderTableMenu()}</slot> `;}renderTableButton(){consttableEnabled=true;// Boolean(this.editor?.commands.setAttachment);if(!tableEnabled)returnhtml``;constisDisabled=this.editor==null;returnhtml`<buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled=${isDisabled}data-role="toolbar-item" @click=${function(e){this.editor.chain().focus().insertTable({rows: 3,cols: 3,withHeaderRow: true}).run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.insertTable}</role-tooltip></slot><slotname="table-icon">${table_icons.insertTable}</slot></button> `;}renderTableMenu(){if(!this.editor.isActive('table'))returnhtml``;returnhtml`<role-toolbarclass="toolbar" part="toolbar" role="toolbar"><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().deleteTable().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.deleteTable}</role-tooltip></slot><slotname="table-icon">${table_icons.deleteTable}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().addColumnBefore().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.addColumnBefore}</role-tooltip></slot><slotname="table-icon">${table_icons.addColumnBefore}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().addColumnAfter().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.addColumnAfter}</role-tooltip></slot><slotname="table-icon">${table_icons.addColumnAfter}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().deleteColumn().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.deleteColumn}</role-tooltip></slot><slotname="table-icon">${table_icons.deleteColumn}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().addRowBefore().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.addRowBefore}</role-tooltip></slot><slotname="table-icon">${table_icons.addRowBefore}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().addRowAfter().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.addRowAfter}</role-tooltip></slot><slotname="table-icon">${table_icons.addRowAfter}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().deleteRow().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.deleteRow}</role-tooltip></slot><slotname="table-icon">${table_icons.deleteRow}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().mergeOrSplit().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.mergeOrSplit}</role-tooltip></slot><slotname="table-icon">${table_icons.mergeOrSplit}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().toggleHeaderRow().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.toggleHeaderRow}</role-tooltip></slot><slotname="table-icon">${table_icons.toggleHeaderRow}</slot></button><buttonclass="toolbar__button rhino-toolbar-button"type="button"aria-describedby="table"aria-disabled="false"data-role="toolbar-item"@click=${function(e){this.editor.chain().focus().toggleHeaderColumn().run()}}><slotname="table-tooltip"><role-tooltipid="table"hoistpart="toolbar-tooltip toolbar-tooltip__table"exportparts=${this.__tooltipExportParts}>${table_translations.toggleHeaderColumn}</role-tooltip></slot><slotname="table-icon">${table_icons.toggleHeaderColumn}</slot></button></role-toolbar> `;}}CustomEditor.define("rhino-editor")
With some new table icons:
import{html,svg}from"lit";functiontoSvg(path,size=24){returnhtml`<svgxmlns="http://www.w3.org/2000/svg"aria-hidden="true"fill="currentColor"viewBox="0 0 ${size}${size}"width="${size}px"height="${size}px"part="toolbar__icon">${path}</svg> `}exportconstinsertTable=toSvg(svg`<path pid="0" fill-rule="evenodd" d="M17 17v5h2a3 3 0 0 0 3-3v-2h-5zm-2 0H9v5h6v-5zm2-2h5V9h-5v6zm-2 0V9H9v6h6zm2-8h5V5a3 3 0 0 0-3-3h-2v5zm-2 0V2H9v5h6zm9 9.177V19a5 5 0 0 1-5 5H5a5 5 0 0 1-5-5V5a5 5 0 0 1 5-5h14a5 5 0 0 1 5 5v2.823a.843.843 0 0 1 0 .354v7.646a.843.843 0 0 1 0 .354zM7 2H5a3 3 0 0 0-3 3v2h5V2zM2 9v6h5V9H2zm0 8v2a3 3 0 0 0 3 3h2v-5H2z"></path>`);exportconstdeleteTable=toSvg(svg`<path pid="0" d="M19 14a5 5 0 1 1 0 10 5 5 0 0 1 0-10zm-2.5 5.938h5a.937.937 0 1 0 0-1.875h-5a.937.937 0 1 0 0 1.875zM12.29 17H9v5h3.674c.356.75.841 1.426 1.427 2H5a5 5 0 0 1-5-5V5a5 5 0 0 1 5-5h14a5 5 0 0 1 5 5v2.823a.843.843 0 0 1 0 .354V14.1a7.018 7.018 0 0 0-2-1.427V9h-5v3.29a6.972 6.972 0 0 0-2 .965V9H9v6h4.255a6.972 6.972 0 0 0-.965 2zM17 7h5V5a3 3 0 0 0-3-3h-2v5zm-2 0V2H9v5h6zM7 2H5a3 3 0 0 0-3 3v2h5V2zM2 9v6h5V9H2zm0 8v2a3 3 0 0 0 3 3h2v-5H2z"></path>`);exportconstaddColumnBefore=toSvg(svg`<path pid="0" d="M19 14a5 5 0 1 1 0 10 5 5 0 0 1 0-10zm2.5 5.938a.937.937 0 1 0 0-1.875h-1.25a.312.312 0 0 1-.313-.313V16.5a.937.937 0 1 0-1.875 0v1.25c0 .173-.14.313-.312.313H16.5a.937.937 0 1 0 0 1.875h1.25c.173 0 .313.14.313.312v1.25a.937.937 0 1 0 1.875 0v-1.25c0-.173.14-.313.312-.313h1.25zM2 19a3 3 0 0 0 6 0V5a3 3 0 1 0-6 0v14zm-2 0V5a5 5 0 1 1 10 0v14a5 5 0 0 1-10 0z"></path>`);exportconstaddColumnAfter=toSvg(svg`<path pid="0" d="M5 14a5 5 0 1 1 0 10 5 5 0 0 1 0-10zm2.5 5.938a.937.937 0 1 0 0-1.875H6.25a.312.312 0 0 1-.313-.313V16.5a.937.937 0 1 0-1.875 0v1.25c0 .173-.14.313-.312.313H2.5a.937.937 0 1 0 0 1.875h1.25c.173 0 .313.14.313.312v1.25a.937.937 0 1 0 1.875 0v-1.25c0-.173.14-.313.312-.313H7.5zM16 19a3 3 0 0 0 6 0V5a3 3 0 0 0-6 0v14zm-2 0V5a5 5 0 0 1 10 0v14a5 5 0 0 1-10 0z"></path>`);exportconstdeleteColumn=toSvg(svg`<path pid="0" d="M12.641 21.931a7.01 7.01 0 0 0 1.146 1.74A5 5 0 0 1 7 19V5a5 5 0 1 1 10 0v7.29a6.972 6.972 0 0 0-2 .965V5a3 3 0 0 0-6 0v14a3 3 0 0 0 3.641 2.931zM19 14a5 5 0 1 1 0 10 5 5 0 0 1 0-10zm-2.5 5.938h5a.937.937 0 1 0 0-1.875h-5a.937.937 0 1 0 0 1.875z"></path>`);exportconstaddRowBefore=toSvg(svg`<path pid="0" d="M19 14a5 5 0 1 1 0 10 5 5 0 0 1 0-10zm2.5 5.938a.937.937 0 1 0 0-1.875h-1.25a.312.312 0 0 1-.313-.313V16.5a.937.937 0 1 0-1.875 0v1.25c0 .173-.14.313-.312.313H16.5a.937.937 0 1 0 0 1.875h1.25c.173 0 .313.14.313.312v1.25a.937.937 0 1 0 1.875 0v-1.25c0-.173.14-.313.312-.313h1.25zM5 2a3 3 0 1 0 0 6h14a3 3 0 0 0 0-6H5zm0-2h14a5 5 0 0 1 0 10H5A5 5 0 1 1 5 0z"></path>`);exportconstaddRowAfter=toSvg(svg`<path pid="0" d="M19 0a5 5 0 1 1 0 10 5 5 0 0 1 0-10zm2.5 5.938a.937.937 0 1 0 0-1.875h-1.25a.312.312 0 0 1-.313-.313V2.5a.937.937 0 1 0-1.875 0v1.25c0 .173-.14.313-.312.313H16.5a.937.937 0 1 0 0 1.875h1.25c.173 0 .313.14.313.312V7.5a.937.937 0 1 0 1.875 0V6.25c0-.173.14-.313.312-.313h1.25zM5 16a3 3 0 0 0 0 6h14a3 3 0 0 0 0-6H5zm0-2h14a5 5 0 0 1 0 10H5a5 5 0 0 1 0-10z"></path>`);exportconstdeleteRow=toSvg(svg`<path pid="0" d="M13.255 15a6.972 6.972 0 0 0-.965 2H5A5 5 0 0 1 5 7h14a5 5 0 0 1 4.671 6.787 7.01 7.01 0 0 0-1.74-1.146A3 3 0 0 0 19 9H5a3 3 0 0 0 0 6h8.255zM19 14a5 5 0 1 1 0 10 5 5 0 0 1 0-10zm-2.5 5.938h5a.937.937 0 1 0 0-1.875h-5a.937.937 0 1 0 0 1.875z"></path>`);exportconstmergeCells=toSvg(svg``);exportconstsplitCells=toSvg(svg``);exportconsttoggleHeaderColumn=toSvg(svg`<path d="M 23.5625 0 c 1.3439 0 2.4375 1.0936 2.4375 2.4375 v 21.125 c 0 1.3439 -1.0936 2.4375 -2.4375 2.4375 H 2.4375 c -1.3439 0 -2.4375 -1.0936 -2.4375 -2.4375 V 2.4375 C 0 1.0936 1.0936 0 2.4375 0 h 21.125 Z m 0.8125 17.875 h -6.5 v 6.5 h 5.6875 c 0.4469 0 0.8125 -0.3656 0.8125 -0.8125 v -5.6875 Z m -8.125 0 H 9.75 v 6.5 h 6.5 v -6.5 Z m 8.125 -8.125 h -6.5 v 6.5 h 6.5 V 9.75 Z m -8.125 0 H 9.75 v 6.5 h 6.5 V 9.75 Z m 7.3125 -8.125 h -5.6875 v 6.5 h 6.5 V 2.4375 c 0 -0.4469 -0.3656 -0.8125 -0.8125 -0.8125 Z m -7.3125 0 H 9.75 v 6.5 h 6.5 V 1.625 Z" fill-rule="evenodd"/>`);exportconsttoggleHeaderRow=toSvg(svg`<path d="M 23.5625 0 c 1.3439 0 2.4375 1.0936 2.4375 2.4375 v 21.125 c 0 1.3439 -1.0936 2.4375 -2.4375 2.4375 H 2.4375 c -1.3439 0 -2.4375 -1.0936 -2.4375 -2.4375 V 2.4375 C 0 1.0936 1.0936 0 2.4375 0 h 21.125 Z m -5.6875 16.25 h 6.5 V 9.75 h -6.5 v 6.5 Z m 6.5 7.3125 v -5.6875 h -6.5 v 6.5 h 5.6875 c 0.4469 0 0.8125 -0.3656 0.8125 -0.8125 Z M 9.75 16.25 h 6.5 V 9.75 H 9.75 v 6.5 Z m 0 8.125 h 6.5 v -6.5 H 9.75 v 6.5 Z m -8.125 -8.125 h 6.5 V 9.75 H 1.625 v 6.5 Z m 6.5 8.125 v -6.5 H 1.625 v 5.6875 c 0 0.4469 0.3656 0.8125 0.8125 0.8125 h 5.6875 Z" fill-rule="evenodd"/>`);exportconsttoggleHeaderCell=toSvg(svg``);exportconstmergeOrSplit=toSvg(svg`<path pid="0" d="M2 19a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3V5a3 3 0 0 0-3-3H5a3 3 0 0 0-3 3v14zm-2 0V5a5 5 0 0 1 5-5h14a5 5 0 0 1 5 5v14a5 5 0 0 1-5 5H5a5 5 0 0 1-5-5zm12-9a1 1 0 0 1 1 1v2a1 1 0 0 1-2 0v-2a1 1 0 0 1 1-1zm0 6a1 1 0 0 1 1 1v3a1 1 0 0 1-2 0v-3a1 1 0 0 1 1-1zm0-13a1 1 0 0 1 1 1v3a1 1 0 0 1-2 0V4a1 1 0 0 1 1-1z"></path>`);exportconstsetCellAttribute=toSvg(svg``);exportconstfixTables=toSvg(svg``);exportconstgoToNextCell=toSvg(svg``);exportconstgoToPreviousCell=toSvg(svg``);
And table translations:
exportconstinsertTable="Insert a Table";exportconstdeleteTable="Delete a Table";exportconstaddColumnBefore="Add A Column Before";exportconstaddColumnAfter="Add a Column After";exportconstdeleteColumn="Delete a Column";exportconstaddRowBefore="Add a Row Before";exportconstaddRowAfter="Add a Row After";exportconstdeleteRow="Delete a Row";exportconstmergeCells="Merge Cells";exportconstsplitCells="Split Cells";exportconsttoggleHeaderColumn="Toggle Header Column";exportconsttoggleHeaderRow="Toggle Header Row";exportconsttoggleHeaderCell="Toggle Header Cell";exportconstmergeOrSplit="Merge or Split Cells";exportconstsetCellAttribute="Set Cell Attribute";exportconstfixTables="Fix Tables";exportconstgoToNextCell="Go To Next Cell";exportconstgoToPreviousCell="Go To Previous Cell";
@nathancolgate holy crap! You are awesome! I'm adding this to the docs first chance I get! thank you so much for sharing!!
minor suggestion btw:
functionextendRhinoEditor(event){constrhinoEditor=event.targetif(rhinoEditor==null)returnrhinoEditor.addExtensions(Table,TableRow,TableHeader,TableCell)// any time addExtensions is called, rebuildEditor should run.}
everytime you call addExtensions it should be calling rebuildEditor so the editor is essentially loading N number of times for each extension. If it's not working, well then i have a bug fix to make 😆.
I should probably do a better job calling this out in the docs!
EDIT: I totally forgot Lit batches updates so rebuildEditor will actually only be called once. Carry on 🙈
Leaving this here as a rough start to writing the docs for adding tables:
We have a custom editor:
With some new table icons:
And table translations:
And some custom styling:
We then get things going by calling:
It gives us an editor that looks like:
The text was updated successfully, but these errors were encountered: