drip-table
Version:
A tiny and powerful enterprise-class solution for building tables.
447 lines (382 loc) • 17.2 kB
JavaScript
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
require("./index.less");
var _classnames = _interopRequireDefault(require("classnames"));
var _react = _interopRequireDefault(require("react"));
var _alert = _interopRequireDefault(require("../../react-components/alert"));
var _dropdown = _interopRequireDefault(require("../../react-components/dropdown"));
var _menu = _interopRequireDefault(require("../../react-components/menu"));
var _tooltip = _interopRequireDefault(require("../../react-components/tooltip"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(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; }
var prefixCls = 'jfe-drip-table-cc-link';
var DTCLink = /*#__PURE__*/function (_React$PureComponent) {
_inherits(DTCLink, _React$PureComponent);
var _super = _createSuper(DTCLink);
function DTCLink() {
var _this;
_classCallCheck(this, DTCLink);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "renderInfoCircle", function () {
return /*#__PURE__*/_react.default.createElement("span", {
role: "img",
"aria-label": "info-circle"
}, /*#__PURE__*/_react.default.createElement("svg", {
viewBox: "64 64 896 896",
focusable: "false",
"data-icon": "info-circle",
width: "1em",
height: "1em",
fill: "currentColor",
"aria-hidden": "true"
}, /*#__PURE__*/_react.default.createElement("path", {
d: "M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"
}), /*#__PURE__*/_react.default.createElement("path", {
d: "M464 336a48 48 0 1096 0 48 48 0 10-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"
})));
});
_defineProperty(_assertThisInitialized(_this), "renderToolTip", function (template) {
var tooltip = _this.props.schema.options.tooltip;
if (tooltip) {
return /*#__PURE__*/_react.default.createElement("div", {
style: {
marginLeft: 8
}
}, _this.props.preview ? _this.renderInfoCircle() : /*#__PURE__*/_react.default.createElement(_tooltip.default, {
title: _this.props.finalizeString('pattern', tooltip, _this.props.record, _this.props.recordIndex, _this.props.ext)
}, _this.renderInfoCircle()));
}
return null;
});
return _this;
}
_createClass(DTCLink, [{
key: "formatLabel",
value: function formatLabel(label) {
return this.props.finalizeString('pattern', label || '', this.props.record, this.props.recordIndex, this.props.ext);
}
}, {
key: "configured",
get: function get() {
var options = this.props.schema.options;
if (options.mode === 'multiple') {
if (options.operates) {
return true;
}
return false;
}
if (options.mode === 'single' && (this.props.finalizeString('pattern', options.href || '', this.props.record, this.props.recordIndex, this.props.ext) || options.event)) {
return true;
}
return false;
}
}, {
key: "finalizeDisabled",
value: function finalizeDisabled(disabled) {
if (typeof disabled === 'string') {
return !!this.props.safeEvaluate("return ".concat(disabled), {
props: {
value: this.props.value,
record: this.props.record,
ext: this.props.ext
},
rec: this.props.record
}, false);
}
return !!disabled;
}
}, {
key: "visible",
get: function get() {
var _this$props = this.props,
schema = _this$props.schema,
record = _this$props.record;
var dataIndex = schema.dataIndex,
options = schema.options;
var mode = options.mode,
visibleFunc = options.visibleFunc;
if (mode === 'single' && visibleFunc) {
return !!(0, _utils.dataProcessValue)(this.props.evaluate, record, dataIndex, visibleFunc);
}
return true;
}
}, {
key: "getIcon",
value: function getIcon(iconName) {
var Icons = this.props.icons;
var Icon = Icons === null || Icons === void 0 ? void 0 : Icons[iconName];
if (Icon) {
return /*#__PURE__*/_react.default.createElement(Icon, null);
}
return null;
}
}, {
key: "renderMenu",
value: function renderMenu() {
var _options$operates,
_this2 = this;
var options = this.props.schema.options;
var menuList = (_options$operates = options.operates) === null || _options$operates === void 0 ? void 0 : _options$operates.slice(options.maxTiledCount);
return /*#__PURE__*/_react.default.createElement(_menu.default, null, menuList === null || menuList === void 0 ? void 0 : menuList.map(function (config, index) {
var event = config.event;
if (event) {
return /*#__PURE__*/_react.default.createElement(_menu.default.Item, {
key: index,
disabled: _this2.finalizeDisabled(config.disabled)
}, /*#__PURE__*/_react.default.createElement("a", {
className: "".concat(prefixCls, "-link"),
onClick: function onClick() {
if (_this2.props.preview) {
return;
}
_this2.props.fireEvent({
type: 'drip-link-click',
payload: event
});
}
}, _this2.formatLabel(config.label)));
}
return /*#__PURE__*/_react.default.createElement(_menu.default.Item, {
key: index,
disabled: _this2.finalizeDisabled(config.disabled)
}, /*#__PURE__*/_react.default.createElement("a", {
className: "".concat(prefixCls, "-link"),
href: _this2.props.finalizeString('pattern', config.href || '', _this2.props.record, _this2.props.recordIndex, _this2.props.ext),
onClick: _this2.props.preview ? function (e) {
return e.preventDefault();
} : void 0,
target: config.target
}, _this2.formatLabel(config.label)));
}));
}
}, {
key: "render",
value: function render() {
var _this3 = this,
_options$operates2,
_options$operates3;
var options = this.props.schema.options;
if (!this.visible && options.mode === 'single') {
return /*#__PURE__*/_react.default.createElement("div", null);
}
if (!this.configured) {
return /*#__PURE__*/_react.default.createElement(_alert.default, {
type: "error",
showIcon: true,
message: "\u5C5E\u6027\u914D\u7F6E\u9519\u8BEF"
});
}
if (options.mode === 'single') {
var event = options.event;
if (event) {
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("a", {
className: (0, _classnames.default)("".concat(prefixCls, "-link"), "".concat(prefixCls, "-link-break"), _defineProperty({}, "".concat(prefixCls, "-link-disabled"), this.finalizeDisabled(options.disabled))),
style: {
lineHeight: options.lineHeight
},
onClick: function onClick() {
if (_this3.props.preview || _this3.finalizeDisabled(options.disabled)) {
return;
}
_this3.props.fireEvent({
type: 'drip-link-click',
payload: event
});
}
}, this.formatLabel(options.label)), this.renderToolTip());
}
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("a", {
className: (0, _classnames.default)("".concat(prefixCls, "-link"), "".concat(prefixCls, "-link-break"), _defineProperty({}, "".concat(prefixCls, "-link-disabled"), this.finalizeDisabled(options.disabled))),
href: this.finalizeDisabled(options.disabled) ? void 0 : this.props.finalizeString('pattern', options.href || '', this.props.record, this.props.recordIndex, this.props.ext),
target: options.target,
onClick: this.props.preview || this.finalizeDisabled(options.disabled) ? function (e) {
return e.preventDefault();
} : void 0,
style: {
lineHeight: options.lineHeight
}
}, this.formatLabel(options.label)), this.renderToolTip());
}
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (_options$operates2 = options.operates) === null || _options$operates2 === void 0 ? void 0 : _options$operates2.slice(0, options.maxTiledCount).map(function (config, index) {
var event = config.event;
var disabled = _this3.finalizeDisabled(config.disabled);
if (event) {
return /*#__PURE__*/_react.default.createElement("div", {
key: index,
style: {
display: 'inline'
}
}, /*#__PURE__*/_react.default.createElement("a", {
className: "".concat(prefixCls, "-link"),
style: {
marginRight: '5px',
lineHeight: options.lineHeight
},
onClick: function onClick() {
if (_this3.props.preview) {
return;
}
_this3.props.fireEvent({
type: 'drip-link-click',
payload: event
});
}
}, _this3.formatLabel(config.label)), _this3.renderToolTip());
}
return /*#__PURE__*/_react.default.createElement("div", {
key: index,
style: {
display: (0, _utils.dataProcessValue)(_this3.props.evaluate, _this3.props.record, _this3.props.schema.dataIndex, config.visibleFunc) || !config.visibleFunc ? 'inline' : 'none'
}
}, /*#__PURE__*/_react.default.createElement("a", {
className: (0, _classnames.default)("".concat(prefixCls, "-link"), "".concat(prefixCls, "-link-break"), _defineProperty({}, "".concat(prefixCls, "-link-disabled"), disabled)),
style: {
marginRight: '5px',
lineHeight: options.lineHeight
},
href: disabled ? void 0 : _this3.props.finalizeString('pattern', config.href || '', _this3.props.record, _this3.props.recordIndex, _this3.props.ext),
target: disabled ? void 0 : config.target,
onClick: function onClick(e) {
if (_this3.props.preview || disabled) {
e.preventDefault();
return;
}
_this3.props.fireEvent({
type: 'drip-link-click',
payload: event
});
}
}, _this3.formatLabel(config.label)), _this3.renderToolTip());
}), typeof options.maxTiledCount === 'number' && options.maxTiledCount < (((_options$operates3 = options.operates) === null || _options$operates3 === void 0 ? void 0 : _options$operates3.length) || 0) ? /*#__PURE__*/_react.default.createElement(_dropdown.default, {
overlay: this.renderMenu(),
trigger: options.trigger ? [options.trigger] : void 0,
placement: options.placement
}, /*#__PURE__*/_react.default.createElement("a", {
className: "".concat(prefixCls, "-link"),
style: {
color: options.textColor
}
}, options.dropdownText || 'more', options.suffixIcon ? ' ' : '', options.suffixIcon ? this.getIcon(options.suffixIcon) : null)) : null);
}
}]);
return DTCLink;
}(_react.default.PureComponent);
exports.default = DTCLink;
_defineProperty(DTCLink, "componentName", 'link');
_defineProperty(DTCLink, "schema", {
type: 'object',
properties: {
mode: {
enum: ['single', 'multiple']
},
name: {
type: 'string'
},
lineHeight: {
type: 'string'
},
label: {
type: 'string'
},
href: {
type: 'string'
},
event: {
type: 'string'
},
target: {
type: 'string'
},
disabled: {
anyOf: [{
type: 'string'
}, {
type: 'boolean'
}]
},
tooltip: {
type: 'string'
},
operates: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string'
},
label: {
type: 'string'
},
href: {
type: 'string'
},
event: {
type: 'string'
},
target: {
type: 'string'
},
disabled: {
anyOf: [{
type: 'string'
}, {
type: 'boolean'
}]
},
disableFunc: {
type: 'string'
},
visibleFunc: {
type: 'string'
}
}
}
},
maxTiledCount: {
type: 'number'
},
dropdownText: {
type: 'string'
},
textColor: {
type: 'string'
},
suffixIcon: {
type: 'string'
},
trigger: {
enum: ['hover', 'click']
},
placement: {
enum: ['bottom', 'bottomLeft', 'bottomRight', 'top', 'topLeft', 'topRight']
},
dataProcess: {
type: 'string'
},
disableFunc: {
type: 'string'
},
visibleFunc: {
type: 'string'
}
}
});