@ywfe/materials-design
Version:
YwDesign for lowcode
85 lines (84 loc) • 2.93 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
export { get, set, has } from 'lodash';
// simple uuid
export function uuid() {
return (Math.random() * 1e6 >> 0).toString(36);
}
export var mockId = function mockId() {
return "id-" + uuid();
};
export var hideProp = function hideProp() {
return false;
};
export var showWithLabelAlign = function showWithLabelAlign(target) {
var parentLabelAlign = target && target.parent.node.parent.getPropValue('labelAlign');
var labelAlign = parentLabelAlign || target && target.parent.getPropValue('labelAlign');
if (labelAlign === 'top') {
var enableLabelTip = target.parent.getPropValue('labelTip.enable');
if (enableLabelTip) {
return target.name.startsWith('labelTip');
}
return target.name === 'labelTip.enable';
}
if (labelAlign === 'inset') {
return target.name.startsWith('wrapper');
}
if (labelAlign === 'left') {
return !target.name.startsWith('labelTip');
}
return true;
};
export var showWithLabelAlignShortcut = function showWithLabelAlignShortcut(target) {
var _ref = target && target.parent.node.propsData,
parentLabelAlign = _ref.labelAlign;
var labelAlign = parentLabelAlign || target && target.parent.getPropValue('labelAlign');
if (labelAlign === 'top') {
var enableLabelTip = target.parent.getPropValue('labelTip.enable');
if (enableLabelTip) {
return target.name.startsWith('labelTip');
}
return target.name === 'labelTip.enable';
}
if (labelAlign === 'inset') {
return target.name.startsWith('wrapper');
}
if (labelAlign === 'left') {
return !target.name.startsWith('labelTip');
}
return true;
};
export var getParentValue = function getParentValue(target) {
return target.getProps().node.parent.getPropValue(target.name);
};
// 获取同级节点 父节点值 同级 .x 父级 ..x
export var getPropValueWithPath = function getPropValueWithPath(_target, _path) {
var targetPath = _path.split('.');
var target = _target;
var data = targetPath.reduce(function (prev, curr) {
if (curr === '') {
target = target.parent;
return target.path;
} else {
return prev.concat([curr]);
}
}, _target.path);
var value = _target.top.node.getPropValue(data.join('.'));
return value;
};
export var getPropsByDependence = function getPropsByDependence(items, deps, path) {
return items.map(function (v) {
return _extends({}, v, {
condition: function condition(target) {
return deps.includes(getPropValueWithPath(target, path));
}
});
});
};
// 组件基于 ref 注册联动事件
export var registerActions = function registerActions(target, actions) {
target.parent.setPropValue('_actions', actions);
target.parent.setPropValue('_registerActions', {
type: 'JSFunction',
value: 'function(){return this.registerActions.apply(this,Array.prototype.slice.call(arguments).concat([])) }'
});
};