UNPKG

cspace-ui

Version:
95 lines (79 loc) 4.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.ConnectedUploadInput = void 0; var _reactRedux = require("react-redux"); var _reactIntl = require("react-intl"); var _cspaceInput = require("cspace-input"); var _reducers = require("../../reducers"); var _prefs = require("../../actions/prefs"); function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } 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; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } const { UploadInput } = _cspaceInput.components; const messages = (0, _reactIntl.defineMessages)({ typeInputLabel: { "id": "UploadInputContainer.typeInputLabel", "defaultMessage": "Upload" }, fileOptionLabel: { "id": "UploadInputContainer.fileOptionLabel", "defaultMessage": "local file" }, urlOptionLabel: { "id": "UploadInputContainer.urlOptionLabel", "defaultMessage": "external media" }, fileInputLabel: { "id": "UploadInputContainer.fileInputLabel", "defaultMessage": "File" }, fileChooseButtonLabel: { "id": "UploadInputContainer.fileChooseButtonLabel", "defaultMessage": "Select\u2026" }, urlInputLabel: { "id": "UploadInputContainer.urlInputLabel", "defaultMessage": "URL" }, fileInfo: { "id": "UploadInputContainer.fileInfo", "defaultMessage": "{name} ({type}, {size, number} bytes)" } }); const mapStateToProps = state => ({ type: (0, _reducers.getUploadType)(state) }); const mapDispatchToProps = { onTypeChanged: _prefs.setUploadType }; const mergeProps = (stateProps, dispatchProps, ownProps) => { const { intl } = ownProps, remainingOwnProps = _objectWithoutProperties(ownProps, ["intl"]); const intlProps = { typeInputLabel: intl.formatMessage(messages.typeInputLabel), fileOptionLabel: intl.formatMessage(messages.fileOptionLabel), urlOptionLabel: intl.formatMessage(messages.urlOptionLabel), fileInputLabel: intl.formatMessage(messages.fileInputLabel), fileChooseButtonLabel: intl.formatMessage(messages.fileChooseButtonLabel), urlInputLabel: intl.formatMessage(messages.urlInputLabel), formatFileInfo: (name, type, size) => intl.formatMessage(messages.fileInfo, { name, type, size }) }; return _objectSpread({}, remainingOwnProps, stateProps, dispatchProps, intlProps); }; const ConnectedUploadInput = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps, mergeProps)(UploadInput); exports.ConnectedUploadInput = ConnectedUploadInput; const IntlizedUploadInput = (0, _reactIntl.injectIntl)(ConnectedUploadInput); IntlizedUploadInput.propTypes = UploadInput.propTypes; var _default = IntlizedUploadInput; exports.default = _default;