feat: @idraw/core add static check/is type declare

This commit is contained in:
chenshenhai 2021-06-21 13:50:16 +08:00
parent 2901353f9b
commit c36bf50156
4 changed files with 48 additions and 9 deletions

View file

@ -1,8 +1,8 @@
# @idraw/core
* [x] Can't controll element at scroll-area
* [] Disable controll element
* [] static check/is type declare
* [x] Disable controll element
* [x] static check/is type declare
* [x] Force update image/svg image when element change
* [x] Reset board's size
* [] Keep all num two decimals

View file

@ -12,8 +12,8 @@ import { Mapper } from './lib/mapper';
import { mergeConfig } from './lib/config';
import { CoreEvent, TypeCoreEventArgMap } from './lib/core-event';
import { parseData } from './lib/parse';
import is from './lib/is';
import check from './lib/check';
import is, { TypeIs } from './lib/is';
import check, { TypeCheck } from './lib/check';
import {
_board, _data, _opts, _config, _renderer, _element, _helper, _hasInited,
_hasInitedData, _mode, _selectedUUID, _prevPoint, _selectedDotDirection,
@ -52,8 +52,8 @@ class Core {
private [_selectedDotDirection]: TypeHelperWrapperDotDirection | null = null;
private [_onlyRender]: boolean = false;
static is: any = is;
static check: any = check;
static is: TypeIs = is;
static check: TypeCheck = check;
constructor(mount: HTMLDivElement, opts: TypeCoreOptions, config?: TypeConfig) {
this[_data] = { elements: [] };

View file

@ -103,6 +103,17 @@ const check = {
svgDesc,
textDesc,
}
type TypeCheck = {
attrs: (value: any) => boolean,
rectDesc: (value: any) => boolean,
imageDesc: (value: any) => boolean,
svgDesc: (value: any) => boolean,
textDesc: (value: any) => boolean,
}
export {
TypeCheck
}
export default check;

View file

@ -2,6 +2,8 @@ import util from "@idraw/util";
const { isColorStr } = util.color;
function number(value: any) {
return (typeof value === 'number' && (value > 0 || value <= 0))
}
@ -74,11 +76,37 @@ function fontFamily(value: any) {
return typeof value === 'string' && value.length > 0;
}
const is = {
const is: TypeIs = {
x, y, w, h, angle, number,
borderWidth, borderRadius, color,
imageSrc, imageURL, imageBase64, svg,
text, fontSize, lineHeight, textAlign, fontFamily,
}
export default is;
type TypeIs = {
x: (value: any) => boolean,
y: (value: any) => boolean,
w: (value: any) => boolean,
h: (value: any) => boolean,
angle: (value: any) => boolean,
number: (value: any) => boolean,
borderWidth: (value: any) => boolean,
borderRadius: (value: any) => boolean,
color: (value: any) => boolean,
imageSrc: (value: any) => boolean,
imageURL: (value: any) => boolean,
imageBase64: (value: any) => boolean,
svg: (value: any) => boolean,
text: (value: any) => boolean,
fontSize: (value: any) => boolean,
lineHeight: (value: any) => boolean,
textAlign: (value: any) => boolean,
fontFamily: (value: any) => boolean,
}
export default is;
export {
TypeIs,
}