slightning-coco-widget
Version:
SLIGHTNING 的 CoCo 控件框架。
130 lines (129 loc) • 3.83 kB
JavaScript
import { betterToString, XMLEscape } from "../../utils";
import { TypeValidateError } from "./type-validate-error";
import { typeToString } from "./utils";
export var StringInputType;
(function (StringInputType) {
StringInputType["INLINE"] = "INLINE";
StringInputType["MULTILINE"] = "MULTILINE";
StringInputType["RICH"] = "RICH";
})(StringInputType || (StringInputType = {}));
const COCO_EDITOR_TYPE_MAP = {
[StringInputType.INLINE]: "TextInput",
[StringInputType.MULTILINE]: "TextArea",
[StringInputType.RICH]: "RichTextEditor"
};
const COCO_VALUE_TYPE_MAP = {
[StringInputType.INLINE]: "string",
[StringInputType.MULTILINE]: "multilineString",
[StringInputType.RICH]: "richTextString"
};
const CREATION_PROJECT_1_VALUE_TYPE_MAP = {
[StringInputType.INLINE]: "string",
[StringInputType.MULTILINE]: "multiline_string",
[StringInputType.RICH]: "multiline_string"
};
const CREATION_PROJECT_2_VALUE_TYPE_MAP = {
[StringInputType.INLINE]: "string",
[StringInputType.MULTILINE]: "multilineString",
[StringInputType.RICH]: "multilineString"
};
export class StringType {
constructor(props = {}) {
var _a, _b;
if (typeof props == "string") {
props = { defaultValue: props };
}
this.defaultValue = (_a = props.defaultValue) !== null && _a !== void 0 ? _a : "";
this.inputType = (_b = props.inputType) !== null && _b !== void 0 ? _b : StringInputType.INLINE;
}
validate(value) {
if (typeof value != "string") {
throw new TypeValidateError(`不能将 ${betterToString(value)} 分配给 ${typeToString(this)}`, value, this);
}
return true;
}
getSameDirectionChildren() {
return [];
}
getReverseDirectionChildren() {
return [];
}
isVoid() {
return false;
}
typeToString() {
return "字符串";
}
inlineTypeToString() {
return this.typeToString();
}
toCoCoPropertyValueTypes() {
return {
editorType: COCO_EDITOR_TYPE_MAP[this.inputType],
valueType: "string",
checkType: "string",
defaultValue: XMLEscape(this.defaultValue)
};
}
toCoCoMethodParamValueTypes() {
return {
valueType: COCO_VALUE_TYPE_MAP[this.inputType],
checkType: "string",
defaultValue: XMLEscape(this.defaultValue)
};
}
toCoCoMethodValueTypes() {
return {
valueType: "string"
};
}
toCoCoEventParamValueTypes() {
return {
valueType: "string"
};
}
toCreationProject1PropValueTypes() {
return {
valueType: "string",
defaultValue: this.defaultValue
};
}
toCreationProject1MethodParamValueTypes() {
return {
valueType: CREATION_PROJECT_1_VALUE_TYPE_MAP[this.inputType],
defaultValue: this.defaultValue
};
}
toCreationProject1MethodValueTypes() {
return {
valueType: "string"
};
}
toCreationProject1EmitParamValueTypes() {
return {
valueType: "string"
};
}
toCreationProject2PropValueTypes() {
return {
valueType: CREATION_PROJECT_2_VALUE_TYPE_MAP[this.inputType],
defaultValue: this.defaultValue
};
}
toCreationProject2MethodParamValueTypes() {
return {
valueType: CREATION_PROJECT_2_VALUE_TYPE_MAP[this.inputType],
defaultValue: this.defaultValue
};
}
toCreationProject2MethodValueTypes() {
return {
valueType: "string"
};
}
toCreationProject2EmitParamValueTypes() {
return {
valueType: "string"
};
}
}