choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
263 lines (235 loc) • 7.83 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _defaultStatus;
import { observable, runInAction, toJS } from 'mobx';
import React from 'react';
import noop from 'lodash/noop';
import isObject from 'lodash/isObject';
import isBoolean from 'lodash/isBoolean';
import { categories } from 'choerodon-ui-font';
import { FieldType, RecordStatus } from '../../pro/es/data-set/enum';
import { $l } from '../../pro/es/locale-context';
import { ColumnAlign, TableQueryBarType } from '../../pro/es/table/enum';
import defaultFeedback from '../../pro/es/data-set/FeedBack';
import { LabelLayout, ShowValidation } from '../../pro/es/form/enum';
import { ButtonColor, FuncType } from '../../pro/es/button/enum';
import { defaultExcludeUseColonTag } from '../../pro/es/form/utils';
import { Action } from '../trigger/enum';
import { Size } from '../_util/enum';
import Popover from '../popover';
function isCustomizable(target) {
return isObject(target);
}
var defaultTooltipTheme = function defaultTooltipTheme(target) {
return target === 'validation' ? 'light' : 'dark';
};
var defaultRenderEmpty = function defaultRenderEmpty(componentName) {
switch (componentName) {
case 'Attachment':
return $l('Attachment', 'no_attachments');
case 'Table':
return $l('Table', 'empty_data');
case 'Select':
return $l('Select', 'no_matching_results');
case 'Output':
return '';
default:
}
};
var defaultFormFieldHighlightRenderer = function defaultFormFieldHighlightRenderer(_ref, element) {
var content = _ref.content,
hidden = _ref.hidden,
rest = _objectWithoutProperties(_ref, ["content", "hidden"]);
return content ? React.createElement(Popover, _extends({}, hidden ? _objectSpread({}, rest, {
visible: false
}) : rest, {
content: content
}), element) : element;
};
var defaultButtonProps = {
color: ButtonColor.primary,
funcType: FuncType.flat
};
var defaultSpinProps = {
size: Size["default"],
wrapperClassName: ''
};
var defaultTableColumnAlign = function defaultTableColumnAlign(_column, field) {
if (field) {
var type = field.type;
switch (type) {
case FieldType.number:
case FieldType.currency:
return ColumnAlign.right;
case FieldType["boolean"]:
return ColumnAlign.center;
default:
}
}
};
function getComponentKey(component) {
switch (component) {
case 'Tabs':
return 'tabs';
default:
return 'table';
}
}
var defaultLookupCache = {
maxAge: 1000 * 60 * 10,
max: 100
};
var defaultStatus = (_defaultStatus = {}, _defineProperty(_defaultStatus, RecordStatus.add, 'add'), _defineProperty(_defaultStatus, RecordStatus.update, 'update'), _defineProperty(_defaultStatus, RecordStatus["delete"], 'delete'), _defaultStatus);
var defaultCustomizedSave = function defaultCustomizedSave(code, customized, component) {
return localStorage.setItem("".concat(getComponentKey(component), ".customized.").concat(code), JSON.stringify(customized));
};
var defaultCustomizedLoad = function defaultCustomizedLoad(code, component) {
return Promise.resolve(JSON.parse(localStorage.getItem("".concat(getComponentKey(component), ".customized.").concat(code)) || 'null'));
};
var defaultFormatter = {
jsonDate: 'YYYY-MM-DD HH:mm:ss',
date: 'YYYY-MM-DD',
dateTime: 'YYYY-MM-DD HH:mm:ss',
time: 'HH:mm:ss',
year: 'YYYY',
month: 'YYYY-MM',
week: 'GGGG-Wo'
};
var defaultAttachment = {
defaultFileKey: 'file',
defaultFileSize: 0
};
var defaultConfig = {
prefixCls: 'c7n',
proPrefixCls: 'c7n-pro',
iconfontPrefix: 'icon',
ripple: true,
collapseExpandIconPosition: 'left',
collapseTrigger: 'header',
lookupCache: defaultLookupCache,
lookupUrl: function lookupUrl(code) {
return "/common/code/".concat(code, "/");
},
lookupAxiosMethod: 'post',
// lookupBatchAxiosConfig:
// codes => ({
// url: '/common/batch',
// params: codes.reduce((obj, code) => {
// obj[code] = code;
// return obj;
// }, {}),
// }),
lovDefineUrl: function lovDefineUrl(code) {
return "/sys/lov/lov_define?code=".concat(code);
},
lovQueryUrl: function lovQueryUrl(code) {
return "/common/lov/dataset/".concat(code);
},
lovTableProps: {},
lovModalProps: {},
lovAutoSelectSingle: false,
dataKey: 'rows',
totalKey: 'total',
statusKey: '__status',
tlsKey: '__tls',
status: defaultStatus,
labelLayout: LabelLayout.horizontal,
queryBar: TableQueryBarType.normal,
tableBorder: true,
tableHighLightRow: true,
tableSelectedHighLightRow: false,
tableRowHeight: 30,
tableDefaultRenderer: '',
tableColumnResizable: true,
tableColumnHideable: true,
performanceTableColumnHideable: true,
tableRowDraggable: false,
tableColumnDraggable: false,
performanceTableColumnDraggable: false,
tableColumnAlign: defaultTableColumnAlign,
tableSpinProps: defaultSpinProps,
tableButtonProps: defaultButtonProps,
tableCommandProps: defaultButtonProps,
tableAlwaysShowRowBox: false,
tableUseMouseBatchChoose: false,
tableEditorNextKeyEnterDown: true,
tableAutoFocus: false,
tableKeyboard: false,
tableFilterSearchText: 'params',
tableAutoHeightDiff: 80,
customizedSave: defaultCustomizedSave,
customizedLoad: defaultCustomizedLoad,
tableShowRemovedRow: true,
modalSectionBorder: true,
drawerSectionBorder: true,
drawerTransitionName: 'slide-right',
modalOkFirst: true,
modalAutoCenter: false,
modalKeyboard: true,
modalMaskClosable: false,
buttonColor: ButtonColor["default"],
buttonFuncType: FuncType.raised,
feedback: defaultFeedback,
renderEmpty: defaultRenderEmpty,
icons: categories,
formatter: defaultFormatter,
dropdownMatchSelectWidth: true,
selectReverse: true,
selectPagingOptionContent: '···',
selectSearchable: false,
selectTrigger: [Action.focus, Action.click],
useColon: false,
excludeUseColonTagList: defaultExcludeUseColonTag,
numberFieldNonStrictStep: false,
showInvalidDate: true,
highlightRenderer: defaultFormFieldHighlightRenderer,
onPerformance: noop,
performanceEnabled: {
Table: false
},
tooltipTheme: defaultTooltipTheme,
showValidation: ShowValidation.tooltip,
attachment: defaultAttachment
};
var globalConfig = observable.map(defaultConfig);
export function getConfig(key) {
return globalConfig.get(key);
}
export function getPrefixCls(suffixCls, customizePrefixCls) {
if (customizePrefixCls) {
return customizePrefixCls;
}
return "".concat(getConfig('prefixCls'), "-").concat(suffixCls);
}
export function getProPrefixCls(suffixCls, customizePrefixCls) {
if (customizePrefixCls) {
return customizePrefixCls;
}
return "".concat(getConfig('proPrefixCls'), "-").concat(suffixCls);
}
export function getCustomizable(component) {
var customizable = getConfig('customizable');
if (isBoolean(customizable)) {
return customizable;
}
if (isCustomizable(customizable)) {
return customizable[component];
}
}
var mergeProps = ['transport', 'feedback', 'formatter', 'attachment', 'pagination'];
export default function configure(config) {
var merge = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
runInAction(function () {
Object.keys(config).forEach(function (key) {
var value = config[key];
if (merge && mergeProps.includes(key) && isObject(value)) {
globalConfig.set(key, _objectSpread({}, toJS(globalConfig.get(key)), {}, value));
} else {
globalConfig.set(key, config[key]);
}
});
});
}
//# sourceMappingURL=index.js.map