fix(plugin-embed): 修复插入网址插件在查看模式下还可以复制、删除的bug

This commit is contained in:
zgh 2022-01-12 15:40:53 +08:00
parent c2742bd908
commit 77d2badd2c
1 changed files with 46 additions and 35 deletions

View File

@ -9,6 +9,7 @@ import {
CardToolbarItemOptions, CardToolbarItemOptions,
ToolbarItemOptions, ToolbarItemOptions,
sanitizeUrl, sanitizeUrl,
isEngine,
} from '@aomao/engine'; } from '@aomao/engine';
import './index.css'; import './index.css';
@ -82,42 +83,52 @@ class EmbedComponent extends Card<EmbedValue> {
} }
toolbar() { toolbar() {
const items: Array<CardToolbarItemOptions | ToolbarItemOptions> = [ if (isEngine(this.editor)) {
{ const items: Array<CardToolbarItemOptions | ToolbarItemOptions> =
type: 'dnd', [];
}, const value = this.getValue();
{ if (value?.url) {
type: 'copy', items.push(
}, {
{ type: 'button',
type: 'delete', content: '<span class="data-icon data-icon-expand" />',
}, title: this.editor.language.get<string>(
]; 'embed',
const value = this.getValue(); 'expand',
if (value?.url) { ),
items.push( onClick: () => this.expand(),
{ },
type: 'separator', {
}, type: 'button',
{ content:
type: 'button', '<span class="data-icon data-icon-compact-display" />',
content: '<span class="data-icon data-icon-expand" />', title: this.editor.language.get<string>(
title: this.editor.language.get<string>('embed', 'expand'), 'embed',
onClick: () => this.expand(), 'collapse',
}, ),
{ onClick: () => this.collapse(),
type: 'button', },
content: );
'<span class="data-icon data-icon-compact-display" />', }
title: this.editor.language.get<string>( if (!this.editor.readonly) {
'embed', items.unshift(
'collapse', {
), type: 'dnd',
onClick: () => this.collapse(), },
}, {
); type: 'copy',
},
{
type: 'delete',
},
{
type: 'separator',
},
);
}
return items;
} }
return items; return [];
} }
handleInputKeydown(e: KeyboardEvent) { handleInputKeydown(e: KeyboardEvent) {