first commit
This commit is contained in:
103
node_modules/vant/es/field/utils.mjs
generated
vendored
Normal file
103
node_modules/vant/es/field/utils.mjs
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
import {
|
||||
isObject,
|
||||
isPromise,
|
||||
isFunction,
|
||||
getRootScrollTop,
|
||||
setRootScrollTop
|
||||
} from "../utils/index.mjs";
|
||||
function isEmptyValue(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return !value.length;
|
||||
}
|
||||
if (value === 0) {
|
||||
return false;
|
||||
}
|
||||
return !value;
|
||||
}
|
||||
function runSyncRule(value, rule) {
|
||||
if (isEmptyValue(value)) {
|
||||
if (rule.required) {
|
||||
return false;
|
||||
}
|
||||
if (rule.validateEmpty === false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (rule.pattern && !rule.pattern.test(String(value))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function runRuleValidator(value, rule) {
|
||||
return new Promise((resolve) => {
|
||||
const returnVal = rule.validator(value, rule);
|
||||
if (isPromise(returnVal)) {
|
||||
returnVal.then(resolve);
|
||||
return;
|
||||
}
|
||||
resolve(returnVal);
|
||||
});
|
||||
}
|
||||
function getRuleMessage(value, rule) {
|
||||
const { message } = rule;
|
||||
if (isFunction(message)) {
|
||||
return message(value, rule);
|
||||
}
|
||||
return message || "";
|
||||
}
|
||||
function startComposing({ target }) {
|
||||
target.composing = true;
|
||||
}
|
||||
function endComposing({ target }) {
|
||||
if (target.composing) {
|
||||
target.composing = false;
|
||||
target.dispatchEvent(new Event("input"));
|
||||
}
|
||||
}
|
||||
function resizeTextarea(input, autosize) {
|
||||
const scrollTop = getRootScrollTop();
|
||||
input.style.height = "auto";
|
||||
let height = input.scrollHeight;
|
||||
if (isObject(autosize)) {
|
||||
const { maxHeight, minHeight } = autosize;
|
||||
if (maxHeight !== void 0) {
|
||||
height = Math.min(height, maxHeight);
|
||||
}
|
||||
if (minHeight !== void 0) {
|
||||
height = Math.max(height, minHeight);
|
||||
}
|
||||
}
|
||||
if (height) {
|
||||
input.style.height = `${height}px`;
|
||||
setRootScrollTop(scrollTop);
|
||||
}
|
||||
}
|
||||
function mapInputType(type, inputmode) {
|
||||
if (type === "number") {
|
||||
type = "text";
|
||||
inputmode != null ? inputmode : inputmode = "decimal";
|
||||
}
|
||||
if (type === "digit") {
|
||||
type = "tel";
|
||||
inputmode != null ? inputmode : inputmode = "numeric";
|
||||
}
|
||||
return { type, inputmode };
|
||||
}
|
||||
function getStringLength(str) {
|
||||
return [...str].length;
|
||||
}
|
||||
function cutString(str, maxlength) {
|
||||
return [...str].slice(0, maxlength).join("");
|
||||
}
|
||||
export {
|
||||
cutString,
|
||||
endComposing,
|
||||
getRuleMessage,
|
||||
getStringLength,
|
||||
isEmptyValue,
|
||||
mapInputType,
|
||||
resizeTextarea,
|
||||
runRuleValidator,
|
||||
runSyncRule,
|
||||
startComposing
|
||||
};
|
||||
Reference in New Issue
Block a user