feat:add video block menu
This commit is contained in:
@@ -6,6 +6,7 @@ export interface IDialogData {
|
|||||||
label?: string;
|
label?: string;
|
||||||
name: string;
|
name: string;
|
||||||
value?: string;
|
value?: string;
|
||||||
|
options?: { label: string; value: string; }[];
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
@@ -29,7 +30,7 @@ export class Dialog {
|
|||||||
private options: IDialogOptions
|
private options: IDialogOptions
|
||||||
private mask: HTMLDivElement | null
|
private mask: HTMLDivElement | null
|
||||||
private container: HTMLDivElement | null
|
private container: HTMLDivElement | null
|
||||||
private inputList: (HTMLInputElement | HTMLTextAreaElement)[]
|
private inputList: (HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement)[]
|
||||||
|
|
||||||
constructor(options: IDialogOptions) {
|
constructor(options: IDialogOptions) {
|
||||||
this.options = options
|
this.options = options
|
||||||
@@ -85,8 +86,16 @@ export class Dialog {
|
|||||||
optionItemContainer.append(optionName)
|
optionItemContainer.append(optionName)
|
||||||
}
|
}
|
||||||
// 选项输入框
|
// 选项输入框
|
||||||
let optionInput: HTMLInputElement | HTMLTextAreaElement
|
let optionInput: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
|
||||||
if (option.type === 'textarea') {
|
if (option.type === 'select') {
|
||||||
|
optionInput = document.createElement('select')
|
||||||
|
option.options?.forEach(item => {
|
||||||
|
const optionItem = document.createElement('option')
|
||||||
|
optionItem.value = item.value
|
||||||
|
optionItem.label = item.label
|
||||||
|
optionInput.append(optionItem)
|
||||||
|
})
|
||||||
|
} else if (option.type === 'textarea') {
|
||||||
optionInput = document.createElement('textarea')
|
optionInput = document.createElement('textarea')
|
||||||
} else {
|
} else {
|
||||||
optionInput = document.createElement('input')
|
optionInput = document.createElement('input')
|
||||||
@@ -100,7 +109,9 @@ export class Dialog {
|
|||||||
}
|
}
|
||||||
optionInput.name = option.name
|
optionInput.name = option.name
|
||||||
optionInput.value = option.value || ''
|
optionInput.value = option.value || ''
|
||||||
optionInput.placeholder = option.placeholder || ''
|
if (!(optionInput instanceof HTMLSelectElement)) {
|
||||||
|
optionInput.placeholder = option.placeholder || ''
|
||||||
|
}
|
||||||
optionItemContainer.append(optionInput)
|
optionItemContainer.append(optionInput)
|
||||||
optionContainer.append(optionItemContainer)
|
optionContainer.append(optionItemContainer)
|
||||||
this.inputList.push(optionInput)
|
this.inputList.push(optionInput)
|
||||||
|
|||||||
@@ -64,7 +64,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.dialog-option__item input,
|
.dialog-option__item input,
|
||||||
.dialog-option__item textarea {
|
.dialog-option__item textarea,
|
||||||
|
.dialog-option__item select {
|
||||||
width: 276px;
|
width: 276px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
|||||||
+3
-1
@@ -27,6 +27,7 @@ import { INavigateInfo } from './core/draw/interactive/Search'
|
|||||||
import { Shortcut } from './core/shortcut/Shortcut'
|
import { Shortcut } from './core/shortcut/Shortcut'
|
||||||
import { KeyMap } from './dataset/enum/KeyMap'
|
import { KeyMap } from './dataset/enum/KeyMap'
|
||||||
import { BlockType } from './dataset/enum/Block'
|
import { BlockType } from './dataset/enum/Block'
|
||||||
|
import { IBlock } from './interface/Block'
|
||||||
|
|
||||||
export default class Editor {
|
export default class Editor {
|
||||||
|
|
||||||
@@ -138,5 +139,6 @@ export type {
|
|||||||
IContextMenuContext,
|
IContextMenuContext,
|
||||||
IRegisterContextMenu,
|
IRegisterContextMenu,
|
||||||
IWatermark,
|
IWatermark,
|
||||||
INavigateInfo
|
INavigateInfo,
|
||||||
|
IBlock
|
||||||
}
|
}
|
||||||
+28
-7
@@ -1,7 +1,7 @@
|
|||||||
import { data, options } from './mock'
|
import { data, options } from './mock'
|
||||||
import './style.css'
|
import './style.css'
|
||||||
import prism from 'prismjs'
|
import prism from 'prismjs'
|
||||||
import Editor, { BlockType, Command, ControlType, EditorMode, ElementType, IElement, KeyMap, PageMode } from './editor'
|
import Editor, { BlockType, Command, ControlType, EditorMode, ElementType, IBlock, IElement, KeyMap, PageMode } from './editor'
|
||||||
import { Dialog } from './components/dialog/Dialog'
|
import { Dialog } from './components/dialog/Dialog'
|
||||||
import { formatPrismToken } from './utils/prism'
|
import { formatPrismToken } from './utils/prism'
|
||||||
import { Signature } from './components/signature/Signature'
|
import { Signature } from './components/signature/Signature'
|
||||||
@@ -618,6 +618,18 @@ window.onload = function () {
|
|||||||
new Dialog({
|
new Dialog({
|
||||||
title: '内容块',
|
title: '内容块',
|
||||||
data: [{
|
data: [{
|
||||||
|
type: 'select',
|
||||||
|
label: '类型',
|
||||||
|
name: 'type',
|
||||||
|
value: 'iframe',
|
||||||
|
options: [{
|
||||||
|
label: '网址',
|
||||||
|
value: 'iframe'
|
||||||
|
}, {
|
||||||
|
label: '视频',
|
||||||
|
value: 'video'
|
||||||
|
}]
|
||||||
|
}, {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
label: '宽度',
|
label: '宽度',
|
||||||
name: 'width',
|
name: 'width',
|
||||||
@@ -635,23 +647,32 @@ window.onload = function () {
|
|||||||
placeholder: '请输入地址'
|
placeholder: '请输入地址'
|
||||||
}],
|
}],
|
||||||
onConfirm: (payload) => {
|
onConfirm: (payload) => {
|
||||||
|
const type = payload.find(p => p.name === 'type')?.value
|
||||||
|
if (!type) return
|
||||||
const value = payload.find(p => p.name === 'value')?.value
|
const value = payload.find(p => p.name === 'value')?.value
|
||||||
if (!value) return
|
if (!value) return
|
||||||
const width = payload.find(p => p.name === 'width')?.value
|
const width = payload.find(p => p.name === 'width')?.value
|
||||||
if (!width) return
|
if (!width) return
|
||||||
const height = payload.find(p => p.name === 'height')?.value
|
const height = payload.find(p => p.name === 'height')?.value
|
||||||
if (!height) return
|
if (!height) return
|
||||||
|
const block: IBlock = {
|
||||||
|
type: <BlockType>type
|
||||||
|
}
|
||||||
|
if (block.type === BlockType.IFRAME) {
|
||||||
|
block.iframeBlock = {
|
||||||
|
src: value
|
||||||
|
}
|
||||||
|
} else if (block.type === BlockType.VIDEO) {
|
||||||
|
block.videoBlock = {
|
||||||
|
src: value
|
||||||
|
}
|
||||||
|
}
|
||||||
instance.command.executeInsertElementList([{
|
instance.command.executeInsertElementList([{
|
||||||
type: ElementType.BLOCK,
|
type: ElementType.BLOCK,
|
||||||
value: '',
|
value: '',
|
||||||
width: Number(width),
|
width: Number(width),
|
||||||
height: Number(height),
|
height: Number(height),
|
||||||
block: {
|
block
|
||||||
type: BlockType.IFRAME,
|
|
||||||
iframeBlock: {
|
|
||||||
src: value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}])
|
}])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user