@schema-render/form-render-react
Version:
Out-of-the-box form rendering library based on Core and Antd.
149 lines (148 loc) • 4.83 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
addActionsSchema: function() {
return addActionsSchema;
},
calcActionsMarginLeft: function() {
return calcActionsMarginLeft;
},
getCheckedOptions: function() {
return getCheckedOptions;
},
getOptionsLabels: function() {
return getOptionsLabels;
},
isEmpty: function() {
return isEmpty;
}
});
var _corereact = require("@schema-render/core-react");
var _constants = require("../constants");
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _object_spread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
var isArray = _corereact.utils.isArray, isNil = _corereact.utils.isNil, isObject = _corereact.utils.isObject;
function addActionsSchema(schema, actionsRestSchema) {
var filed = "".concat(_constants.ACTIONS_RENDER_TYPE, "_").concat(Date.now());
return _object_spread_props(_object_spread({}, schema), {
properties: _object_spread_props(_object_spread({}, schema === null || schema === void 0 ? void 0 : schema.properties), _define_property({}, filed, _object_spread_props(_object_spread({}, actionsRestSchema), {
renderType: _constants.ACTIONS_RENDER_TYPE
})))
});
}
function calcActionsMarginLeft(param) {
var itemLayout = param.itemLayout, labelWidth = param.labelWidth, labelGap = param.labelGap;
if (itemLayout === 'horizontal' && _corereact.utils.isNumber(labelWidth)) {
return labelWidth + labelGap;
}
return 0;
}
/**
* 标准化遍历 Antd options 数据,支持跳出遍历
*/ function forEachOptions() {
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], callback = arguments.length > 1 ? arguments[1] : void 0;
for(var i = 0; i < options.length; i++){
// 标准化 item 数据
var item = options[i];
var objectItem = isObject(item) ? item : {
label: item,
value: item
};
var breakEach = callback(objectItem);
if (breakEach) {
return;
}
}
}
function getOptionsLabels(options, checkedValues) {
var labels = [];
if (!isArray(options) || !isArray(checkedValues)) {
return labels;
}
checkedValues.forEach(function(value) {
if (isNil(value)) {
return;
}
forEachOptions(options, function(item) {
// 找到一项,跳出遍历
if (value === item.value) {
labels.push(item.label);
return true;
}
});
});
return labels;
}
function getCheckedOptions(options, checkedValues) {
var result = [];
if (!isArray(options) || !isArray(checkedValues)) {
return result;
}
forEachOptions(options, function(item) {
if (checkedValues.includes(item.value)) {
result.push(item);
}
});
return result;
}
function isEmpty(value) {
return !!(isNil(value) || value === '');
}
;