Add more valid

This commit is contained in:
Harvey committed 2021-12-10 11:05:44 +08:00
1 parent 5f45ad112f
commit d919471838
7 files changed
+31 -11

No files matched your search

+4
View File
@@ -1,3 +1,5 @@
import { errorHandle } from './utils';
export default class Hotkey {
constructor(art) {
this.keys = {};
@@ -55,6 +57,8 @@ export default class Hotkey {
}
add(key, event) {
errorHandle(typeof key === 'number', 'The Hotkey.add() first parameter is not a number');
errorHandle(typeof event === 'function', 'The Hotkey.add() second parameter is not a function');
if (this.keys[key]) {
this.keys[key].push(event);
} else {
+1
View File
@@ -34,6 +34,7 @@ export default class Plugins {
add(plugin) {
this.id += 1;
errorHandle(typeof plugin === 'function', `The Plugins.add() first parameter is not a function`);
const result = plugin.call(this, this.art);
const pluginName = (result && result.name) || plugin.name || `plugin${this.id}`;
errorHandle(!has(this, pluginName), `Cannot add a plugin that already has the same name: ${pluginName}`);
+5 -5
View File
@@ -12,7 +12,7 @@ function validElement(value, type, paths) {
return errorHandle(type === s || value instanceof Element, `${paths.join('.')} require '${s}' or 'Element' type`);
}
const component = {
export const ComponentOption = {
html: validElement,
disable: `?${b}`,
name: `?${s}`,
@@ -59,12 +59,12 @@ export default {
useSSR: b,
plugins: [f],
whitelist: [`${s}|${f}|${r}`],
layers: [component],
contextmenu: [component],
settings: [component],
layers: [ComponentOption],
contextmenu: [ComponentOption],
settings: [ComponentOption],
controls: [
{
...component,
...ComponentOption,
position: (value, _, paths) => {
const position = ['top', 'left', 'right'];
return errorHandle(
+3
View File
@@ -12,6 +12,8 @@ import {
errorHandle,
} from './utils';
import Component from './utils/component';
import validator from 'option-validator';
import scheme from './scheme';
export default class Subtitle extends Component {
constructor(art) {
@@ -86,6 +88,7 @@ export default class Subtitle extends Component {
}
init(subtitleOption) {
validator(subtitleOption, scheme.subtitle);
if (!subtitleOption.url) return;
const {
@@ -1,4 +1,6 @@
import { hasClass, addClass, removeClass, append, setStyles, tooltip, getStyle, inverseClass } from './dom';
import validator from 'option-validator';
import { ComponentOption } from '../scheme';
import { has, def } from './property';
import { errorHandle } from './error';
@@ -32,6 +34,9 @@ export default class Component {
add(getOption) {
const option = typeof getOption === 'function' ? getOption(this.art) : getOption;
option.html = option.html || '';
validator(option, ComponentOption);
if (!this.$parent || !this.name || option.disable) return;
const name = option.name || `${this.name}${this.id}`;
errorHandle(!has(this, name), `Cannot add an existing name [${name}] to the [${this.name}]`);