@ywfe/materials-design
Version:
YwDesign for lowcode
123 lines (122 loc) • 4.42 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.showWithLabelAlignShortcut = exports.showWithLabelAlign = exports.set = exports.registerActions = exports.mockId = exports.hideProp = exports.has = exports.getRefConfig = exports.getPropsByDependence = exports.getPropValueWithPath = exports.getParentValue = exports.get = void 0;
exports.uuid = uuid;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _lodash = require("lodash");
exports.get = _lodash.get;
exports.set = _lodash.set;
exports.has = _lodash.has;
// simple uuid
function uuid() {
return (Math.random() * 1e6 >> 0).toString(36);
}
var mockId = exports.mockId = function mockId() {
return "id-" + uuid();
};
var hideProp = exports.hideProp = function hideProp() {
return false;
};
var showWithLabelAlign = exports.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;
};
var showWithLabelAlignShortcut = exports.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;
};
var getParentValue = exports.getParentValue = function getParentValue(target) {
return target.getProps().node.parent.getPropValue(target.name);
};
// 获取同级节点 父节点值 同级 .x 父级 ..x
var getPropValueWithPath = exports.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;
};
var getPropsByDependence = exports.getPropsByDependence = function getPropsByDependence(items, deps, path) {
return items.map(function (v) {
return (0, _extends2["default"])({}, v, {
condition: function condition(target) {
return deps.includes(getPropValueWithPath(target, path));
}
});
});
};
// 组件基于 ref 注册联动事件
var registerActions = exports.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([])) }'
});
};
var getRefConfig = exports.getRefConfig = function getRefConfig(name, action) {
var flag = name + "_" + uuid();
return {
name: 'ref',
display: 'block',
title: {
label: '组件标识',
tip: "ref | \u901A\u8FC7 this.$('" + flag + "') \u83B7\u53D6\u5230\u7EC4\u4EF6\u5B9E\u4F8B"
},
supportVariable: false,
setter: {
initialValue: flag,
componentName: 'StringSetter',
props: {
placeholder: '请输入组件标识'
}
},
extraProps: {
setValue: function setValue(target, value) {
if (action) {
registerActions(target, action.map(function (v) {
return (0, _extends2["default"])({
path: value
}, v);
}));
}
}
}
};
};