`
* children). It renders nothing — the editor reads the items and renders the
* real bubble menu in its own shadow DOM. The editor's internal instance
* lives in a shadow root, so `closest` never matches it.
*/
private get isAuthoringContainer(): boolean {
return !!this.closest('nile-wysiwyg-editor');
}
public render(): TemplateResult {
if (this.isAuthoringContainer) return html``;
const state = this.toolbarState;
const entries: AuthoredToolbarItem[] =
this.items && this.items.length
? this.items
: DEFAULT_BUBBLE.map(name => ({ name }));
return html`
e.preventDefault()}>
${entries.map(entry => this.renderEntry(entry, state))}
`;
}
private renderEntry(
entry: AuthoredToolbarItem,
state?: ToolbarState
): TemplateResult | typeof nothing {
if (entry.name === '|') {
return html``;
}
const base = BUBBLE_ITEMS[entry.name];
const label = entry.label || base?.label || entry.name;
const icon = entry.icon || base?.icon;
// Unknown command with no icon to draw → nothing to render.
if (!icon) return nothing;
const command = base?.command ?? (entry.name as WysiwygCommandDetail['name']);
const attrs = base?.attrs;
const isActive = base?.active && state ? base.active(state) : false;
return html`
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'nile-wysiwyg-bubble-menu': NileWysiwygBubbleMenu;
}
}