drip-table
Version:
A tiny and powerful enterprise-class solution for building tables.
191 lines (160 loc) • 8.67 kB
JavaScript
;
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;
var _react = _interopRequireDefault(require("react"));
var _dom = require("../../../utils/dom");
var _col = _interopRequireDefault(require("../../react-components/col"));
var _row = _interopRequireDefault(require("../../react-components/row"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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 DTCGroup = /*#__PURE__*/function (_React$PureComponent) {
_inherits(DTCGroup, _React$PureComponent);
var _super = _createSuper(DTCGroup);
function DTCGroup() {
_classCallCheck(this, DTCGroup);
return _super.apply(this, arguments);
}
_createClass(DTCGroup, [{
key: "rowItems",
get: function get() {
var options = this.props.schema.options;
var items = options.items.map(function (item) {
if (!item || 'component' in item) {
return {
schema: item
};
}
return item;
});
var startIndex = 0;
return options.layout.map(function (columnLength) {
var columnItems = items.slice(startIndex, startIndex + columnLength);
startIndex += columnLength;
return columnItems;
});
}
}, {
key: "parseReactCSS",
value: function parseReactCSS(style) {
var _this$props = this.props,
record = _this$props.record,
recordIndex = _this$props.recordIndex,
ext = _this$props.ext;
var styleObject = typeof style === 'string' ? this.props.safeEvaluate(style, {
props: {
record: record,
recordIndex: recordIndex,
ext: ext
}
}) : style;
return (0, _dom.parseReactCSS)(styleObject);
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
record = _this$props2.record,
recordIndex = _this$props2.recordIndex,
renderSchema = _this$props2.renderSchema;
var options = this.props.schema.options;
return /*#__PURE__*/_react.default.createElement("div", {
style: _objectSpread({
wordBreak: 'break-word'
}, this.parseReactCSS(options.style))
}, this.rowItems.map(function (columnItems, rowIndex) {
var _options$gutter, _options$gutter2;
return /*#__PURE__*/_react.default.createElement(_row.default, {
key: rowIndex,
style: {
marginTop: (_options$gutter = options.gutter) === null || _options$gutter === void 0 ? void 0 : _options$gutter[1],
marginBottom: (_options$gutter2 = options.gutter) === null || _options$gutter2 === void 0 ? void 0 : _options$gutter2[1]
},
gutter: options.gutter,
justify: options.horizontalAlign,
align: options.verticalAlign,
wrap: options.wrap
}, columnItems.map(function (item, columnIndex) {
return /*#__PURE__*/_react.default.createElement(_col.default, {
key: columnIndex,
gutter: options.gutter,
style: _objectSpread(_objectSpread({}, columnIndex ? void 0 : {
marginLeft: 0
}), {}, {
wordBreak: 'break-word'
}, item.style)
}, item.schema ? renderSchema(item.schema, record, recordIndex) : null);
}));
}));
}
}]);
return DTCGroup;
}(_react.default.PureComponent);
exports.default = DTCGroup;
_defineProperty(DTCGroup, "componentName", 'group');
_defineProperty(DTCGroup, "schema", {
type: 'object',
properties: {
style: {
anyOf: [{
type: 'string'
}, {
type: 'object',
patternProperties: {
'^.*$': {
anyOf: [{
type: 'string'
}, {
type: 'number'
}]
}
}
}]
},
horizontalAlign: {
enum: ['start', 'end', 'center', 'space-around', 'space-between']
},
verticalAlign: {
enum: ['top', 'middle', 'bottom']
},
layout: {
type: 'array',
items: {
type: 'number'
}
},
gutter: {
type: 'array',
items: {
type: 'number'
}
},
wrap: {
type: 'boolean'
},
offset: {
type: 'array',
items: {
type: 'number'
}
},
items: {
type: 'array',
items: {}
}
}
});