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,
ToolbarItemOptions,
sanitizeUrl,
isEngine,
} from '@aomao/engine';
import './index.css';
@ -82,27 +83,19 @@ class EmbedComponent extends Card<EmbedValue> {
}
toolbar() {
const items: Array<CardToolbarItemOptions | ToolbarItemOptions> = [
{
type: 'dnd',
},
{
type: 'copy',
},
{
type: 'delete',
},
];
if (isEngine(this.editor)) {
const items: Array<CardToolbarItemOptions | ToolbarItemOptions> =
[];
const value = this.getValue();
if (value?.url) {
items.push(
{
type: 'separator',
},
{
type: 'button',
content: '<span class="data-icon data-icon-expand" />',
title: this.editor.language.get<string>('embed', 'expand'),
title: this.editor.language.get<string>(
'embed',
'expand',
),
onClick: () => this.expand(),
},
{
@ -117,8 +110,26 @@ class EmbedComponent extends Card<EmbedValue> {
},
);
}
if (!this.editor.readonly) {
items.unshift(
{
type: 'dnd',
},
{
type: 'copy',
},
{
type: 'delete',
},
{
type: 'separator',
},
);
}
return items;
}
return [];
}
handleInputKeydown(e: KeyboardEvent) {
if (isHotkey('enter', e)) this.handleSubmit();