修改验证方法

This commit is contained in:
Harvey Zack committed 2018-10-24 14:54:56 +08:00
1 parent 4ce05442c7
commit 8a88fb3043
9 files changed
+189 -123

No files matched your search

+5 -9
View File
@@ -14,11 +14,7 @@ let id = 0;
export default class Controls {
constructor(art) {
this.art = art;
this.$map = {
top: [],
left: [],
right: []
};
this.$map = {};
this.init();
this.mount();
}
@@ -84,14 +80,14 @@ export default class Controls {
index: 50
}));
this.art.option.controls.filter(item => !item.disable).forEach(item => {
this.art.option.controls.forEach(item => {
this.add(item);
});
}
add(control) {
const { option } = control;
if (!option.disable) {
if (option && !option.disable) {
id++;
const name = control.constructor.name.toLowerCase() || `control${id}`;
const $control = document.createElement('div');
@@ -99,8 +95,8 @@ export default class Controls {
$control.setAttribute('data-control-index', String(option.index) || id);
option.$control = $control;
this.commonMethod(control);
this.$map[option.position].push($control);
control.apply(this.art);
(this.$map[option.position] || (this.$map[option.position] = [])).push($control);
control.apply && control.apply(this.art);
this[name] = control;
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ export default class Layers {
constructor(art) {
this.art = art;
this.add = this.add.bind(this);
this.art.option.layers.forEach(this.add);
this.art.option.layers.filter(item => item.disable === false).forEach(this.add);
this.init();
}
+7 -4
View File
@@ -69,11 +69,14 @@ export function deepMerge(...sources) {
}
returnValue = [...returnValue, ...source];
} else if (isObject(source)) {
for (let [key, value] of Object.entries(source)) {
if (isObject(value) && Reflect.has(returnValue, key)) {
value = deepMerge(returnValue[key], value);
for (const key in source) {
if (source.hasOwnProperty(key)) {
let value = source[key];
if (isObject(value) && key in returnValue) {
value = deepMerge(returnValue[key], value);
}
returnValue = { ...returnValue, [key]: value };
}
returnValue = { ...returnValue, [key]: value };
}
}
}
-18
View File
@@ -1,18 +0,0 @@
import { errorHandle } from '../utils';
export default function validControl(option) {
errorHandle(
typeof option.disable === 'boolean',
`'disable' option require 'boolean' type, but got '${typeof option.disable}'.`
);
errorHandle(
['top', 'left', 'right'].indexOf(option.position) > -1,
`'position' option require one of 'top、left、right', but got '${option.position}'.`
);
errorHandle(
typeof option.index === 'number',
`'index' option require 'number' type, but got '${typeof option.index}'.`
);
}
+65 -1
View File
@@ -6,10 +6,74 @@ export default function validOption(DEFAULTS, option, path = ['option']) {
const value = option[key];
const defaultType = getType(defaultValue);
const type = getType(value);
errorHandle(defaultType === type, `'${path.join('.')}.${key}' require '${defaultType}' type, but got '${type}'`);
errorHandle(
defaultType === type,
`'${path.join('.')}.${key}' require '${defaultType}' type, but got '${type}'`
);
if (type === 'object') {
validOption(defaultValue, value, path.concat(key));
}
if (path.length === 1) {
if (key === 'layers') {
value.forEach((item, index) => {
validOption(
{
name: '',
index: 0,
html: '',
style: {}
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'contextmenu') {
value.forEach((item, index) => {
validOption(
{
name: '',
click: new Function(),
html: '',
style: {}
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'highlight') {
value.forEach((item, index) => {
validOption(
{
time: 0,
text: ''
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'controls') {
value.forEach((item, index) => {
if (item.option) {
validOption(
{
disable: false,
position: '',
index: 0
},
item.option,
path.concat(`${key}[${index}]`)
);
}
});
}
}
});
}