UNPKG

8.16 kBJavaScriptView Raw
1"use strict";
2
3function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports["default"] = void 0;
9
10var _propTypes = _interopRequireDefault(require("prop-types"));
11
12var _react = _interopRequireWildcard(require("react"));
13
14var _components = require("@storybook/components");
15
16function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
18function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
22function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
23
24function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
26function _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); }
27
28function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
29
30function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
31
32function _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; }
33
34function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
35
36function _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); } }
37
38function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
39
40function _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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
41
42function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
43
44function _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); }; }
45
46function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
47
48function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
49
50function _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; } }
51
52function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
53
54function _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; }
55
56function formatArray(value, separator) {
57 if (value === '') {
58 return [];
59 }
60
61 return value.split(separator);
62}
63
64var ArrayType = /*#__PURE__*/function (_Component) {
65 _inherits(ArrayType, _Component);
66
67 var _super = _createSuper(ArrayType);
68
69 function ArrayType() {
70 var _this;
71
72 _classCallCheck(this, ArrayType);
73
74 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
75 args[_key] = arguments[_key];
76 }
77
78 _this = _super.call.apply(_super, [this].concat(args));
79
80 _defineProperty(_assertThisInitialized(_this), "handleChange", function (e) {
81 var _this$props = _this.props,
82 knob = _this$props.knob,
83 onChange = _this$props.onChange;
84 var _ref = e.target,
85 value = _ref.value;
86 var newVal = formatArray(value, knob.separator);
87 onChange(newVal);
88 });
89
90 return _this;
91 }
92
93 _createClass(ArrayType, [{
94 key: "shouldComponentUpdate",
95 value: function shouldComponentUpdate(nextProps) {
96 var knob = this.props.knob;
97 return nextProps.knob.value !== knob.value;
98 }
99 }, {
100 key: "render",
101 value: function render() {
102 var knob = this.props.knob;
103 var value = knob.value && knob.value.join(knob.separator);
104 return /*#__PURE__*/_react["default"].createElement(_components.Form.Textarea, {
105 id: knob.name,
106 name: knob.name,
107 value: value,
108 onChange: this.handleChange,
109 size: "flex"
110 });
111 }
112 }]);
113
114 return ArrayType;
115}(_react.Component);
116
117exports["default"] = ArrayType;
118
119_defineProperty(ArrayType, "defaultProps", {
120 knob: {},
121 onChange: function onChange(value) {
122 return value;
123 }
124});
125
126_defineProperty(ArrayType, "propTypes", {
127 knob: _propTypes["default"].shape({
128 name: _propTypes["default"].string,
129 value: _propTypes["default"].array,
130 separator: _propTypes["default"].string
131 }),
132 onChange: _propTypes["default"].func
133});
134
135_defineProperty(ArrayType, "serialize", function (value) {
136 return value;
137});
138
139_defineProperty(ArrayType, "deserialize", function (value) {
140 if (Array.isArray(value)) return value;
141 return Object.keys(value).sort().reduce(function (array, key) {
142 return [].concat(_toConsumableArray(array), [value[key]]);
143 }, []);
144});
\No newline at end of file