@cainiaofe/cn-ui-charts
Version:
1,052 lines (1,047 loc) • 40.2 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.AutoWireRerender = AutoWireRerender;
exports.AutoWireViewWithRerender = AutoWireViewWithRerender;
exports.calculateAdvancedConfig = calculateAdvancedConfig;
exports.calculateFeature = calculateFeature;
exports.calculateLabels = calculateLabels;
exports.calculateTextExprValue = calculateTextExprValue;
exports.condition = condition;
exports.createDataSourceSetters = createDataSourceSetters;
exports.createOpenUtil = createOpenUtil;
exports.executeFunction = executeFunction;
exports.getBizComponentNameList = getBizComponentNameList;
exports.getChartCommonStyle = getChartCommonStyle;
exports.getCommonInteraction = getCommonInteraction;
exports.getDataSourceList = void 0;
exports.getDataSourceListWithAllPath = getDataSourceListWithAllPath;
exports.getFilterValue = getFilterValue;
exports.getFirstOptions = getFirstOptions;
exports.getItem = getItem;
exports.getItemDefaultProps = getItemDefaultProps;
exports.getItemListByPosition = getItemListByPosition;
exports.getItemPrototypeListByPosition = getItemPrototypeListByPosition;
exports.getJSExpressionPrototype = getJSExpressionPrototype;
exports.getLowCodeCoreUtil = getLowCodeCoreUtil;
exports.getRealData = getRealData;
exports.getRealRequestUrl = getRealRequestUrl;
exports.getRealResponse = getRealResponse;
exports.getSlotDom = getSlotDom;
exports.handleDesignMokelayUrl = void 0;
exports.handleI18nLabel = handleI18nLabel;
exports.handlePrototypeCondition = handlePrototypeCondition;
exports.handleRequestParams = handleRequestParams;
exports.handleResultProcessFunc2 = handleResultProcessFunc2;
exports.handleSuccessMessage = handleSuccessMessage;
exports.isArrayEmpty = isArrayEmpty;
exports.isArrayNotEmpty = isArrayNotEmpty;
exports.isDesignMode = isDesignMode;
exports.isEmptyButNotZero = isEmptyButNotZero;
exports.isValueObjectExpr = isValueObjectExpr;
exports.judgeDataEmpty = judgeDataEmpty;
exports.makeChartRequestConfig = makeChartRequestConfig;
exports.setAliasName = setAliasName;
exports.setDataToDs = setDataToDs;
exports.transProxyToObject = void 0;
exports.transRequestConfigToRemote = transRequestConfigToRemote;
exports.uuid = uuid;
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
var _const = require("./const");
var _queryString = _interopRequireDefault(require("query-string"));
var _request = require("./request");
var _cnUi = require("@alife/cn-ui");
var _get = _interopRequireDefault(require("lodash/get"));
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
var _uniq = _interopRequireDefault(require("lodash/uniq"));
var _feature = require("../manager/feature");
var _algorithm = require("./algorithm");
var _react = _interopRequireDefault(require("react"));
var _datasourceSetter = _interopRequireDefault(require("../setter/datasource-setter/datasource-setter"));
var _set = _interopRequireDefault(require("lodash/set"));
var _useFilterSearchListener = _interopRequireDefault(require("../../lowcode/cn-column-chart/hooks/useFilterSearchListener"));
var _nanoid = require("nanoid");
var _excluded = ["options", "props", "position"];
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
var _window = window,
VisualEngine = _window.VisualEngine;
var Engine = VisualEngine;
var messageTypeMap = {
success: 'success',
warning: 'warning',
error: 'error',
notice: 'notice',
help: 'help',
loading: 'loading'
};
function getRealRequestUrl(config) {
var _ref = config || {},
requestConfig = _ref.requestConfig,
state = _ref.state,
extraParam = _ref.extraParam;
var result;
if (requestConfig) {
var dynamicUrl = requestConfig.dynamicUrl,
useDynamicUrl = requestConfig.useDynamicUrl,
url = requestConfig.url;
result = url;
if (useDynamicUrl === true && typeof dynamicUrl === 'function') {
var temp = executeFunction(dynamicUrl, state, extraParam || {});
if (typeof temp === 'string') {
result = temp;
} else {
result = '';
}
}
}
return result;
}
function executeFunction(func) {
if (typeof func === 'function') {
var result;
try {
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
rest[_key - 1] = arguments[_key];
}
result = func.apply(void 0, rest);
} catch (e) {}
return result;
}
}
function isDesignMode(props) {
var mode;
if ((0, _isPlainObject["default"])(props)) {
mode = props === null || props === void 0 ? void 0 : props.__designMode;
} else if (typeof props === 'string') {
mode = props;
}
return mode === 'design';
}
function isArrayNotEmpty(list) {
return Array.isArray(list) && list.length > 0;
}
function isArrayEmpty(list) {
return Array.isArray(list) && list.length === 0;
}
function judgeDataEmpty(options) {
if (options) {
var _options$children, _options$children$;
if (isArrayEmpty(options === null || options === void 0 ? void 0 : options.data)) {
return true;
}
if (isArrayEmpty((_options$children = options.children) === null || _options$children === void 0 ? void 0 : (_options$children$ = _options$children[0]) === null || _options$children$ === void 0 ? void 0 : _options$children$.data)) {
return true;
}
}
}
function getRealResponse(res) {
if (res === void 0) {
res = {};
}
var _res = res,
status = _res.status,
data = _res.data;
var result = res;
if (status === 200 && data) {
result = data;
}
return result;
}
function transRequestConfigToRemote(config) {
if (config === void 0) {
config = {};
}
var _config = config,
requestConfig = _config.requestConfig,
handleParams = _config.handleParams,
isDesign = _config.isDesign,
urlParamsDataSource = _config.urlParamsDataSource,
recordDataSource = _config.recordDataSource,
state = _config.state,
extraParamList = _config.extraParamList,
getExtraParam = _config.getExtraParam,
needFormatResult = _config.needFormatResult,
handleParamsBeforeSend = _config.handleParamsBeforeSend;
if (requestConfig) {
var realUrl = getRealRequestUrl({
requestConfig: requestConfig,
state: state,
extraParam: getExtraParam === null || getExtraParam === void 0 ? void 0 : getExtraParam()
});
var url = requestConfig.url,
_requestConfig$params = requestConfig.params,
params = _requestConfig$params === void 0 ? [] : _requestConfig$params,
serviceType = requestConfig.serviceType,
method = requestConfig.method,
contentType = requestConfig.contentType;
var temp = {
url: url,
method: 'post',
data: {}
};
if (realUrl) {
temp.url = realUrl;
}
if (isDesign && serviceType === 'mokelay') {
temp.url = handleDesignMokelayUrl(temp.url);
}
if (serviceType === 'http') {
temp.withCredentials = true;
}
if (typeof handleParams === 'function') {
temp.data = handleParams(temp.data);
}
var realParams = handleRequestParams(params, {
urlParamsDataSource: urlParamsDataSource,
recordDataSource: recordDataSource,
state: state,
extraParamList: extraParamList,
getExtraParam: getExtraParam
});
if (Object.keys(realParams).length > 0) {
temp.data = (0, _extends2["default"])({}, temp.data, realParams);
}
if (serviceType === 'http') {
if (method) {
temp.method = method;
}
if (contentType === _const.formUrlencoded) {
temp.headers = {
'content-type': contentType
};
if (temp.method === 'post' && (0, _isPlainObject["default"])(temp.data)) {
temp.data = _queryString["default"].stringify(temp.data);
}
}
}
if (typeof handleParamsBeforeSend === 'function') {
temp.data = handleParamsBeforeSend(temp.data);
}
if (temp.method === 'get') {
temp.params = temp.data;
delete temp.data;
}
if (needFormatResult === true) {
temp.formatResult = (0, _request.handleResultProcessFunc)(requestConfig);
}
return temp;
} else {
return {};
}
}
// 处理设计态的mokelay请求url
var handleDesignMokelayUrl = function handleDesignMokelayUrl(url) {
var _window$getCnLowcodeS, _window2;
var domain = (_window$getCnLowcodeS = (_window2 = window).getCnLowcodeStoreItem) === null || _window$getCnLowcodeS === void 0 ? void 0 : _window$getCnLowcodeS.call(_window2, '__next_cone_domain__');
if (domain && domain !== null && domain !== void 0 && domain.value) {
return location.protocol + "//" + domain.value + url;
}
return _const.preMokelayDomain + url;
};
exports.handleDesignMokelayUrl = handleDesignMokelayUrl;
function handleRequestParams(params, config) {
if (config === void 0) {
config = {};
}
var result = {};
if (params && params.length > 0) {
params.forEach(function (item) {
if (item) {
var label = item.label,
value = item.value;
if (label && value !== undefined) {
result[label] = calculateTextExprValue(value, config);
}
}
});
} else if (typeof params === 'function') {
var temp = calculateTextExprValue(params, config);
if ((0, _isPlainObject["default"])(temp)) {
result = temp;
}
}
return result;
}
function isValueObjectExpr(obj) {
return !!((0, _isPlainObject["default"])(obj) && obj.group && obj.param);
}
function calculateTextExprValue(originValue, config) {
if (config === void 0) {
config = {};
}
var _config2 = config,
urlParamsDataSource = _config2.urlParamsDataSource,
recordDataSource = _config2.recordDataSource,
state = _config2.state,
_config2$extraParamLi = _config2.extraParamList,
extraParamList = _config2$extraParamLi === void 0 ? [] : _config2$extraParamLi,
tableCurrentRow = _config2.tableCurrentRow,
extraParam = _config2.extraParam,
getExtraParam = _config2.getExtraParam;
if (typeof originValue === 'function') {
try {
var extra = extraParamList;
if (!Array.isArray(extra)) {
extra = [];
}
return originValue.apply(void 0, [recordDataSource, state].concat(extra));
} catch (e) {
return;
}
} else if (isValueObjectExpr(originValue)) {
var group = originValue.group,
param = originValue.param,
secondParam = originValue.secondParam,
thirdParam = originValue.thirdParam;
if (group && param) {
var _objExprArgMap;
var result;
var realExtraParam = extraParam;
if (typeof getExtraParam === 'function') {
realExtraParam = executeFunction(getExtraParam);
}
var objExprArgMap = (_objExprArgMap = {}, _objExprArgMap[_const.__record__] = recordDataSource, _objExprArgMap[_const.__dataSource__] = state, _objExprArgMap[_const.__tableCurrentRow__] = tableCurrentRow, _objExprArgMap[_const.__extraParam__] = realExtraParam, _objExprArgMap);
if (secondParam) {
result = (0, _get["default"])(objExprArgMap, group + "." + param + "." + secondParam + (thirdParam ? "." + thirdParam : ''));
} else {
result = (0, _get["default"])(objExprArgMap, group + "." + param);
}
return result;
}
}
return originValue;
}
function handleResultProcessFunc2(response, requestConfig, extra) {
var _ref2 = extra || {},
state = _ref2.state;
var newRes = getRealResponse(response);
if (requestConfig) {
var resultProcessFunc = requestConfig.resultProcessFunc,
serviceType = requestConfig.serviceType,
mockData = requestConfig.mockData;
if (typeof resultProcessFunc === 'function' && (serviceType === 'mokelay' || serviceType === 'http')) {
try {
if ((0, _isPlainObject["default"])(state)) {
newRes = resultProcessFunc(newRes, state);
} else {
newRes = resultProcessFunc(newRes);
}
} catch (e) {
console.error('请求结果回调执行失败', e);
}
return newRes;
} else if (serviceType === 'mock' && (0, _isPlainObject["default"])(mockData)) {
return mockData;
}
}
return newRes;
}
function handleSuccessMessage(res) {
var _ref3 = res || {},
msg = _ref3.msg,
extra = _ref3.extra;
var _ref4 = extra || {},
type = _ref4.type;
var resultType = 'success';
if (messageTypeMap[type]) {
resultType = type;
}
_cnUi.CnMessage[resultType](msg || '请求成功');
}
function handleI18nLabel(label) {
if ((0, _isPlainObject["default"])(label) && label.type === 'cn-i18n') {
return label.dm || '';
}
return label;
}
function getChartCommonStyle(props) {
var _ref5 = props || {},
chartStyle = _ref5.chartStyle;
return {
// style:{
// // minHeight: '100px',
// // height:'200px',
// height: chartStyle?.height,
// },
containerStyle: {
// minHeight: '100px',
// height:'200px',
height: chartStyle === null || chartStyle === void 0 ? void 0 : chartStyle.height
}
};
}
function getFilterValue(config) {
var _ref6 = config || {},
filterConfig = _ref6.filterConfig,
_context = _ref6._context;
var _ref7 = filterConfig || {},
_bindFilter = _ref7._bindFilter;
var result = {};
if (isArrayNotEmpty(_bindFilter)) {
for (var _iterator = _createForOfIteratorHelperLoose(_bindFilter), _step; !(_step = _iterator()).done;) {
var item = _step.value;
if (item) {
var filterDom = _context === null || _context === void 0 ? void 0 : _context.$(item);
var _ref8 = (filterDom === null || filterDom === void 0 ? void 0 : filterDom.props) || {},
_dataSourceName = _ref8._dataSourceName;
if (_dataSourceName) {
var _context$state;
result = (0, _extends2["default"])({}, result, transProxyToObject(_context === null || _context === void 0 ? void 0 : (_context$state = _context.state) === null || _context$state === void 0 ? void 0 : _context$state[_dataSourceName]));
}
}
}
}
return result;
}
var transProxyToObject = function transProxyToObject(origin) {
var result = {};
if (typeof origin === 'object') {
var keys = Object.keys(origin);
if (keys && keys.length > 0) {
keys.forEach(function (key) {
result[key] = origin[key];
});
}
}
return result;
};
exports.transProxyToObject = transProxyToObject;
function makeChartRequestConfig(config) {
var _ref9 = config || {},
filterConfig = _ref9.filterConfig,
_context = _ref9._context,
requestConfig = _ref9.requestConfig,
isDesign = _ref9.isDesign;
var _ref10 = requestConfig || {},
serviceType = _ref10.serviceType,
guid = _ref10.guid;
var filterValue = getFilterValue({
filterConfig: filterConfig,
_context: _context
});
// makeRequest方法return会一个Promise对象
var realRequestConfig = {
// 请求成功后是否toast提示
needSuccessToast: false,
buttonConfig: {
options: {
requestConfig: requestConfig
}
},
recordDataSource: {},
state: (_context === null || _context === void 0 ? void 0 : _context.state) || {}
};
if (serviceType === _const.dataOriginDataEasy) {
realRequestConfig.buttonConfig.options.requestConfig = (0, _extends2["default"])({}, requestConfig, {
url: (0, _const.getQueryDataPath)(isDesign),
method: 'post',
serviceType: 'http'
});
realRequestConfig.handleParamsBeforeSend = function (data) {
return {
conditions: (0, _extends2["default"])({}, filterValue, data),
guid: guid
};
};
} else {
realRequestConfig.handleParams = function (data) {
return (0, _extends2["default"])({}, data, filterValue);
};
}
return realRequestConfig;
}
function calculateLabels(config) {
var _ref11 = config || {},
labels = _ref11.labels;
if (isArrayNotEmpty(labels)) {
var result = [];
labels.forEach(function (item) {
var _ref12 = item || {},
type = _ref12.type,
position = _ref12.position;
var data = {};
if (type) {
var tempV = config === null || config === void 0 ? void 0 : config[type];
if (type === 'colorField+angleField') {
tempV = function tempV(d) {
return (d[config === null || config === void 0 ? void 0 : config.colorField] || '') + " " + (d[config === null || config === void 0 ? void 0 : config.angleField] || '');
};
} else if (type === 'anglePercent') {
tempV = function tempV(item, index, data) {
var key = config === null || config === void 0 ? void 0 : config.angleField;
return (0, _algorithm.calculatePercent)(key, item, data);
};
} else if (type === 'colorField+anglePercent') {
tempV = function tempV(item, index, data) {
return (item[config === null || config === void 0 ? void 0 : config.colorField] || '') + " " + ((0, _algorithm.calculatePercent)(config === null || config === void 0 ? void 0 : config.angleField, item, data) || '');
};
}
if (tempV) {
data.text = tempV;
}
position && (data.position = position);
if (position === 'outside' || position === 'spider') {
data.transform = [{
type: 'overlapDodgeY'
}];
}
}
if (!(0, _isEmpty["default"])(data)) {
result.push(data);
}
});
return result;
}
}
function getSlotDom(config) {
var _ref13 = config || {},
componentSlot = _ref13.componentSlot,
isDesign = _ref13.isDesign,
componentProps = _ref13.componentProps;
if (componentSlot) {
if (isArrayNotEmpty(componentSlot)) {
return componentSlot.map(function (item, index) {
return /*#__PURE__*/_react["default"].cloneElement(item, componentProps || {});
});
}
return componentSlot;
}
return null;
}
function isEmptyButNotZero(value) {
return value === undefined || value === null || value === '';
}
function getCommonInteraction() {
return {
interaction: {
tooltip: {
shared: true
},
elementHighlightByColor: {
background: true
}
}
};
}
function getItem(componentMap, position, componentName, propKey, extraQueryParams) {
var result;
if (componentName) {
var item = componentMap[componentName];
if (typeof item === 'function') {
item = executeFunction(item, {
position: position
});
}
var flag = true;
if (item && item.position && item.position.includes(position)) {} else {
flag = false;
}
if ((0, _isPlainObject["default"])(extraQueryParams)) {
for (var key in extraQueryParams) {
var _item;
if (key && Array.isArray((_item = item) === null || _item === void 0 ? void 0 : _item[key])) {
if (item[key].includes(extraQueryParams[key])) {} else {
flag = false;
}
}
}
}
if (flag) {
if (!item.label) {
item.label = item.title;
}
if (!item.value) {
item.value = item.componentName;
}
if (propKey) {
result = item[propKey];
} else {
result = item;
}
}
}
return result;
}
function condition(prop, type, primaryKey) {
var _prop$parent, _prop$parent$parent, _prop$parent$parent$g;
return (prop === null || prop === void 0 ? void 0 : (_prop$parent = prop.parent) === null || _prop$parent === void 0 ? void 0 : (_prop$parent$parent = _prop$parent.parent) === null || _prop$parent$parent === void 0 ? void 0 : (_prop$parent$parent$g = _prop$parent$parent.getPropValue) === null || _prop$parent$parent$g === void 0 ? void 0 : _prop$parent$parent$g.call(_prop$parent$parent, primaryKey)) === type;
}
function handlePrototypeCondition(prototypeList, componentName, primaryKey) {
var _prototypeList;
if (prototypeList === void 0) {
prototypeList = [];
}
if (((_prototypeList = prototypeList) === null || _prototypeList === void 0 ? void 0 : _prototypeList.length) > 0) {
return prototypeList.map(function (item) {
var _newItem;
var newItem = item;
if ((0, _isPlainObject["default"])(item)) {
newItem = (0, _extends2["default"])({}, item);
newItem.__optType = componentName;
}
if (!((_newItem = newItem) !== null && _newItem !== void 0 && _newItem.condition)) {
newItem.condition = function (prop) {
return condition(prop, componentName, primaryKey);
};
}
return newItem;
});
}
return prototypeList;
}
function getItemPrototypeListByPosition(config) {
var position = config.position,
primaryKey = config.primaryKey,
componentMap = config.componentMap;
var defaultList = Object.keys(componentMap);
var bizComponentNameList = getBizComponentNameList();
var prototypeList = [];
var allComponentList = (0, _uniq["default"])([].concat(defaultList, bizComponentNameList));
allComponentList.forEach(function (name) {
var item = getItem(componentMap, position, name) || {};
var getPrototypeList = item.getPrototypeList,
_item$configure = item.configure,
configure = _item$configure === void 0 ? [] : _item$configure;
if (typeof getPrototypeList === 'function') {
var temp = getPrototypeList(position);
if (temp && temp.length > 0) {
prototypeList = [].concat(prototypeList, handlePrototypeCondition(temp, name, primaryKey));
}
} else if ((configure === null || configure === void 0 ? void 0 : configure.length) > 0) {
prototypeList = [].concat(prototypeList, handlePrototypeCondition(configure, name, primaryKey));
}
});
return prototypeList;
}
function getItemListByPosition(config) {
var position = config.position,
componentMap = config.componentMap,
extraQueryParams = config.extraQueryParams;
var result = [];
var defaultList = Object.keys(componentMap);
var bizComponentNameList = getBizComponentNameList();
var allComponentList = (0, _uniq["default"])([].concat(defaultList, bizComponentNameList));
allComponentList.forEach(function (name) {
var component = getItem(componentMap, position, name, null, extraQueryParams);
if (component) {
var _component$bizInfo = component.bizInfo,
bizInfo = _component$bizInfo === void 0 ? [] : _component$bizInfo;
if (bizInfo.length > 0) {
bizInfo.forEach(function (item) {
var label = item.label,
value = item.value;
var existGroup = result.find(function (item2) {
return item2.value === value;
});
if (existGroup) {
existGroup === null || existGroup === void 0 ? void 0 : existGroup.children.push(component);
} else {
result.push({
title: label,
value: value,
children: [component]
});
}
});
return;
}
result.push(component);
}
});
return result;
}
// 获取业务组件列表
function getBizComponentNameList() {
var result = [];
if (VisualEngine) {
var _VisualEngine$designe, _VisualEngine$designe2;
var componentsMap = VisualEngine === null || VisualEngine === void 0 ? void 0 : (_VisualEngine$designe = VisualEngine.designer) === null || _VisualEngine$designe === void 0 ? void 0 : (_VisualEngine$designe2 = _VisualEngine$designe.getComponentsMap) === null || _VisualEngine$designe2 === void 0 ? void 0 : _VisualEngine$designe2.call(_VisualEngine$designe);
if (componentsMap) {
result = Object.keys(componentsMap);
}
}
return result;
}
function getItemDefaultProps(componentMap, position, componentName) {
var func = getItem(componentMap, position, componentName, 'getDefaultProps');
if (typeof func === 'function') {
return func();
}
}
function calculateFeature(config) {
var _ref14 = config || {},
options = _ref14.options,
props = _ref14.props,
position = _ref14.position,
rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref14, _excluded);
var _ref15 = props || {},
__featureConfig__ = _ref15.__featureConfig__;
var result = options;
if (isArrayNotEmpty(__featureConfig__)) {
for (var _iterator2 = _createForOfIteratorHelperLoose(__featureConfig__), _step2; !(_step2 = _iterator2()).done;) {
var item = _step2.value;
var _ref16 = item || {},
name = _ref16.name,
active = _ref16.active;
if (name && active) {
var handle = getItem(_feature.componentMap, position, name, 'handleFeature');
var tempResult = handle === null || handle === void 0 ? void 0 : handle((0, _extends2["default"])({
featureItemConfig: item,
props: props,
options: options,
position: position
}, rest));
if ((0, _isPlainObject["default"])(tempResult)) {
result = tempResult;
}
}
}
}
return result;
}
function getJSExpressionPrototype(config) {
var _ref17 = config || {},
configType = _ref17.type,
prototypeConfig = _ref17.prototypeConfig;
if (configType === 'handleProps') {
return getJSExpressionPrototypeTemplate({
prototypeConfig: prototypeConfig,
initialCode: "(options, state) => {\n return options;\n}",
tip: /*#__PURE__*/_react["default"].createElement("div", {
className: ""
}, "\u5F53\u524D\u51FD\u6570\u9700\u8981\u8FD4\u56DE G2 Spec options\u3002", /*#__PURE__*/_react["default"].createElement("div", {
className: ""
}, "\u8BF7\u5230", ' ', /*#__PURE__*/_react["default"].createElement("a", {
target: '_blank',
href: "https://g2.antv.antgroup.com/zh/examples/general/interval/#column",
rel: "noreferrer"
}, "G2\u5B98\u7F51"), ' ', "\u751F\u6210Spec\u914D\u7F6E\u9879"), /*#__PURE__*/_react["default"].createElement("div", {
className: ""
}, "state\uFF1A\u5168\u90E8\u7684\u6570\u636E\uFF0C\u5728\u5DE6\u4FA7\u5217\u8868\u4E2D\u9009\u62E9\u4F7F\u7528\u3002"))
});
} else if (configType === 'base') {
return getJSExpressionPrototypeTemplate({
prototypeConfig: prototypeConfig,
initialCode: "(arg, state) => {\n // return state.urlParams.xxx;\n}",
tip: "\nstate\uFF1A\u5168\u90E8\u7684\u6570\u636E\uFF0C\u5728\u5DE6\u4FA7\u5217\u8868\u4E2D\u9009\u62E9\u4F7F\u7528\u3002\n"
});
}
return {};
}
function getJSExpressionPrototypeTemplate(config) {
var _ref18 = config || {},
title = _ref18.title,
initialCode = _ref18.initialCode,
tip = _ref18.tip,
prototypeConfig = _ref18.prototypeConfig;
return {
title: title || '写js表达式',
componentName: 'CnRowDataSetter',
props: function props() {
var stateList = getDataSourceListWithAllPath({
needChildren: true,
prototypeConfig: prototypeConfig
});
return {
list: stateList,
initialCode: initialCode,
tip: tip
};
}
};
}
function getDataSourceListWithAllPath(config) {
var _VisualEngine$context;
var _ref19 = config || {},
typeList = _ref19.typeList;
var dataSource = VisualEngine === null || VisualEngine === void 0 ? void 0 : (_VisualEngine$context = VisualEngine.context) === null || _VisualEngine$context === void 0 ? void 0 : _VisualEngine$context.getManager('dataPool');
var items = dataSource === null || dataSource === void 0 ? void 0 : dataSource.getItems();
var result = [];
if ((items === null || items === void 0 ? void 0 : items.length) > 0) {
items.forEach(function (item) {
var name = item.name,
type = item.type,
dsConfig = item.config;
var label = (dsConfig === null || dsConfig === void 0 ? void 0 : dsConfig.description) || name;
var ds = {
text: label,
label: label,
value: "state." + name
};
if (Array.isArray(typeList) && typeList.length > 0) {
if (typeList.includes(type)) {
result.push(ds);
}
} else {
result.push(ds);
}
});
}
return result;
}
function calculateAdvancedConfig(config) {
var _ref20 = config || {},
options = _ref20.options,
props = _ref20.props,
state = _ref20.state;
var _ref21 = props || {},
__advancedConfig__ = _ref21.__advancedConfig__;
var _ref22 = __advancedConfig__ || {},
handleProps = _ref22.handleProps;
if (typeof handleProps === 'function') {
var result = executeFunction(handleProps, options, state);
if ((0, _isPlainObject["default"])(result)) {
return result;
}
}
return options;
}
var getDsNameFromVariable = function getDsNameFromVariable(dsExpr) {
var result = '';
if (dsExpr && dsExpr.variable) {
result = dsExpr.variable.slice(dsExpr.variable.lastIndexOf('.') + 1);
}
return result;
};
var getDataSourceList = function getDataSourceList(config) {
var _VisualEngine$context2;
var _ref23 = config || {},
typeList = _ref23.typeList,
needChildren = _ref23.needChildren;
var dataSource = VisualEngine === null || VisualEngine === void 0 ? void 0 : (_VisualEngine$context2 = VisualEngine.context) === null || _VisualEngine$context2 === void 0 ? void 0 : _VisualEngine$context2.getManager('dataPool');
var items = dataSource === null || dataSource === void 0 ? void 0 : dataSource.getItems();
var result = [];
if ((items === null || items === void 0 ? void 0 : items.length) > 0) {
items.forEach(function (item) {
var id = item.id,
name = item.name,
type = item.type,
dsConfig = item.config;
var label = (dsConfig === null || dsConfig === void 0 ? void 0 : dsConfig.description) || name;
var ds = {
text: label,
label: label,
value: name,
dataSourceId: dsConfig === null || dsConfig === void 0 ? void 0 : dsConfig.id,
id: id
};
if (Array.isArray(typeList) && typeList.length > 0) {
if (typeList.includes(type)) {
result.push(ds);
}
} else {
result.push(ds);
}
});
}
return result;
};
exports.getDataSourceList = getDataSourceList;
var generateIndex = function generateIndex(dataSourceList, componentName, key) {
if (key === void 0) {
key = 'value';
}
var index = 2;
while (dataSourceList.find(function (item) {
return item[key] === "" + componentName + index;
})) {
index++;
}
return index;
};
function generateDataSource(config) {
var _dataSourceList;
var _ref24 = config || {},
componentName = _ref24.componentName;
if (componentName) {}
var dataSourceList = [];
dataSourceList = getDataSourceList();
var index = '';
var first = (_dataSourceList = dataSourceList) === null || _dataSourceList === void 0 ? void 0 : _dataSourceList.find(function (item) {
return item.value === "" + componentName;
});
if (first) {
index = generateIndex(dataSourceList, componentName);
}
if (Engine) {
var _Engine$designer, _Engine$designer$getC, _Engine$designer$getC2, _Engine$context, _componentPrototype$o;
var componentPrototype = Engine === null || Engine === void 0 ? void 0 : (_Engine$designer = Engine.designer) === null || _Engine$designer === void 0 ? void 0 : (_Engine$designer$getC = _Engine$designer.getComponentMeta) === null || _Engine$designer$getC === void 0 ? void 0 : (_Engine$designer$getC2 = _Engine$designer$getC.call(_Engine$designer, componentName)) === null || _Engine$designer$getC2 === void 0 ? void 0 : _Engine$designer$getC2.prototype;
var dataSource = Engine === null || Engine === void 0 ? void 0 : (_Engine$context = Engine.context) === null || _Engine$context === void 0 ? void 0 : _Engine$context.getManager('dataPool');
var ds = dataSource === null || dataSource === void 0 ? void 0 : dataSource.addItem({
description: "" + ((componentPrototype === null || componentPrototype === void 0 ? void 0 : (_componentPrototype$o = componentPrototype.options) === null || _componentPrototype$o === void 0 ? void 0 : _componentPrototype$o.title) || componentName) + index + "\u7684\u6570\u636E\u6E90",
dpType: 'VALUE',
id: '',
initialData: '',
isGlobal: false,
name: "" + componentName + index,
protocal: 'VALUE'
});
if (ds !== null && ds !== void 0 && ds.name) {
return ds;
}
}
}
function createDataSourceSetters() {
return [{
name: '_dataSource',
title: '数据源',
display: 'inline',
supportVariable: false,
mutator: function mutator(value) {
var node = this.getProps().getNode();
var result = getDsNameFromVariable(value);
if (result) {
node.setPropValue('_dataSourceName', result);
}
},
initialValue: function initialValue(value) {
var v = this.getValue();
// if (value) {
// return value;
// }
// if(Engine?.Exchange?.hoveringNode){
// const node = this.getNode();
// const {componentName} = node;
// const currentDataSource = node.getPropValue('_dataSource');
var componentName = this.componentName;
var currentDataSource = this.getPropValue('_dataSource');
if (!currentDataSource && !v) {
var ds = generateDataSource({
componentName: componentName
});
if (ds !== null && ds !== void 0 && ds.name) {
var _this$parent, _this$parent$setPropV;
// this.setPropValue('_dataSourceName',ds.name)
(_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : (_this$parent$setPropV = _this$parent.setPropValue) === null || _this$parent$setPropV === void 0 ? void 0 : _this$parent$setPropV.call(_this$parent, '_dataSourceName', ds.name);
return {
type: 'variable',
variable: "state." + ds.name
};
}
}
},
setter: /*#__PURE__*/_react["default"].createElement(_datasourceSetter["default"], null)
}, {
name: '_dataSourceName',
title: '数据源名称',
display: 'none',
// supportVariable: true,
initialValue: function initialValue() {
var _this$parent2, _this$parent2$getProp;
var value = (_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : (_this$parent2$getProp = _this$parent2.getPropValue) === null || _this$parent2$getProp === void 0 ? void 0 : _this$parent2$getProp.call(_this$parent2, '_dataSourceName');
if (!value) {
var node = this.getNode();
var dsExpr = node === null || node === void 0 ? void 0 : node.getPropValue('_dataSource');
return getDsNameFromVariable(dsExpr);
}
return value;
}
}];
}
function getLowCodeCoreUtil(path) {
return (0, _get["default"])(window.cnLowCodeUtils, path);
}
function setAliasName(fieldName, aliasName, options) {
if (fieldName && aliasName && options) {
(0, _set["default"])(options, "axis." + fieldName + ".title", aliasName);
}
}
function getFirstOptions(options) {
if ((0, _isPlainObject["default"])(options)) {
return options;
} else if (isArrayNotEmpty(options)) {
return options[0];
}
return options;
}
function setDataToDs(config) {
var _ref25 = config || {},
data = _ref25.data,
_dataSourceName = _ref25._dataSourceName,
_context = _ref25._context,
_dataSource = _ref25._dataSource;
if ((0, _isPlainObject["default"])(data) && _dataSourceName && _context) {
var _context$setState;
_context === null || _context === void 0 ? void 0 : _context.setState((_context$setState = {}, _context$setState[_dataSourceName] = (0, _extends2["default"])({}, _dataSource, data), _context$setState));
}
}
function createOpenUtil() {
if (!window.cnChartsUtils) {
window.cnChartsUtils = {
hook: {
useFilterSearchListener: _useFilterSearchListener["default"]
}
};
}
}
function uuid(len) {
if (len === void 0) {
len = 4;
}
return (0, _nanoid.customAlphabet)('abcdefghijklmnopqrstuvwxyz', len)();
}
function getRealData(realRequestConfig, res, _context) {
var data = res === null || res === void 0 ? void 0 : res.data;
var resultProcessFunc = (0, _request.handleResultProcessFunc)(realRequestConfig);
if (typeof resultProcessFunc === 'function') {
data = executeFunction(resultProcessFunc, res, _context === null || _context === void 0 ? void 0 : _context.state);
}
return data;
}
// 自动装配rerender 方法
function AutoWireRerender(SourceComp) {
function useUpdate() {
var _React$useState = _react["default"].useState({}),
setState = _React$useState[1];
return _react["default"].useCallback(function () {
setState({});
}, []);
}
var UpdateComp = /*#__PURE__*/_react["default"].forwardRef(function (props, ref) {
var update = useUpdate();
_react["default"].useImperativeHandle(ref, function () {
return {
reRender: function reRender() {
update();
}
};
});
return /*#__PURE__*/_react["default"].createElement(SourceComp, props);
});
var Wrapper = /*#__PURE__*/function (_React$Component) {
(0, _inheritsLoose2["default"])(Wrapper, _React$Component);
function Wrapper(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.ref = /*#__PURE__*/_react["default"].createRef();
_this.reRender = function () {
var _this$ref, _this$ref$current, _this$ref$current$reR;
(_this$ref = _this.ref) === null || _this$ref === void 0 ? void 0 : (_this$ref$current = _this$ref.current) === null || _this$ref$current === void 0 ? void 0 : (_this$ref$current$reR = _this$ref$current.reRender) === null || _this$ref$current$reR === void 0 ? void 0 : _this$ref$current$reR.call(_this$ref$current);
};
return _this;
}
var _proto = Wrapper.prototype;
_proto.render = function render() {
return /*#__PURE__*/_react["default"].createElement(UpdateComp, (0, _extends2["default"])({
ref: this.ref
}, this.props));
};
return Wrapper;
}(_react["default"].Component);
(0, _hoistNonReactStatics["default"])(Wrapper, SourceComp);
Wrapper.displayName = SourceComp.displayName;
return Wrapper;
}
// 装配rerender效果配置名单
var rerenderOpenList = ['CnPieChart', 'CnLineChart', 'CnProgress', 'CnColumnChart'];
function AutoWireViewWithRerender(compList) {
return compList === null || compList === void 0 ? void 0 : compList.map(function (compItem) {
return rerenderOpenList.includes(compItem === null || compItem === void 0 ? void 0 : compItem.displayName) ? AutoWireRerender(compItem) : compItem;
});
}