import { type BlockModel, Slice } from '@blockeditor/store'; import { html, nothing } from 'lit'; import { ref, type RefOrCallback } from 'lit/directives/ref.js'; import { toast } from '../../_common/components/toast.js'; import { CancelWrapIcon, CopyIcon, DeleteIcon, WrapIcon, } from '../../_common/icons/index.js'; import type { CodeBlockComponent } from '../code-block.js'; export function CodeOptionTemplate({ ref: containerRef, model, wrap, onClickWrap, anchor, }: { ref?: RefOrCallback; anchor: CodeBlockComponent; model: BlockModel; wrap: boolean; abortController: AbortController; onClickWrap: () => void; }) { const page = model.page; const readonly = page.readonly; return html`
{ const slice = Slice.fromModels(model.page, [model]); anchor.std.clipboard .copySlice(slice) .then(() => { toast(anchor.host, 'Copied to clipboard'); }) .catch(e => { toast(anchor.host, 'Copied failed, something went wrong'); console.error(e); }); }} > ${CopyIcon} Copy to Clipboard ${wrap ? CancelWrapIcon : WrapIcon} ${wrap ? 'Cancel wrap' : 'Wrap code'} ${readonly ? nothing : html` { if (readonly) return; model.page.deleteBlock(model); }} > ${DeleteIcon} Delete `}
`; }