dash-core-components 1.15.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +8 -44
  2. package/dash_core_components/async-datepicker.js +1 -1
  3. package/dash_core_components/async-datepicker.js.map +1 -1
  4. package/dash_core_components/async-dropdown.js +2 -2
  5. package/dash_core_components/async-dropdown.js.map +1 -1
  6. package/dash_core_components/async-graph.js +1 -1
  7. package/dash_core_components/async-graph.js.map +1 -1
  8. package/dash_core_components/async-highlight.js +1 -1
  9. package/dash_core_components/async-highlight.js.map +1 -1
  10. package/dash_core_components/async-markdown.js +2 -2
  11. package/dash_core_components/async-markdown.js.map +1 -1
  12. package/dash_core_components/async-plotlyjs.js +2 -2
  13. package/dash_core_components/async-slider.js +1 -2
  14. package/dash_core_components/async-slider.js.map +1 -1
  15. package/dash_core_components/async-upload.js +1 -1
  16. package/dash_core_components/async-upload.js.map +1 -1
  17. package/dash_core_components/dash_core_components-shared.js +2 -2
  18. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  19. package/dash_core_components/dash_core_components.js +3 -0
  20. package/dash_core_components/dash_core_components.js.map +1 -0
  21. package/dash_core_components/plotly.min.js +30 -26
  22. package/lib/components/Checklist.react.js +77 -35
  23. package/lib/components/Clipboard.react.js +354 -0
  24. package/lib/components/ConfirmDialog.react.js +16 -12
  25. package/lib/components/ConfirmDialogProvider.react.js +19 -15
  26. package/lib/components/DatePickerRange.react.js +111 -97
  27. package/lib/components/DatePickerSingle.react.js +95 -81
  28. package/lib/components/Download.react.js +138 -0
  29. package/lib/components/Dropdown.react.js +69 -47
  30. package/lib/components/Graph.react.js +36 -24
  31. package/lib/components/Input.react.js +98 -92
  32. package/lib/components/Interval.react.js +18 -12
  33. package/lib/components/Link.react.js +36 -30
  34. package/lib/components/Loading.react.js +21 -15
  35. package/lib/components/Location.react.js +15 -13
  36. package/lib/components/LogoutButton.react.js +18 -14
  37. package/lib/components/Markdown.react.js +23 -17
  38. package/lib/components/RadioItems.react.js +77 -35
  39. package/lib/components/RangeSlider.react.js +61 -55
  40. package/lib/components/Slider.react.js +52 -46
  41. package/lib/components/Store.react.js +16 -16
  42. package/lib/components/Tab.react.js +6 -2
  43. package/lib/components/Tabs.react.js +32 -23
  44. package/lib/components/Textarea.react.js +19 -13
  45. package/lib/components/Tooltip.react.js +152 -0
  46. package/lib/components/Upload.react.js +25 -19
  47. package/lib/components/css/Dropdown.css +1 -1
  48. package/lib/fragments/DatePickerRange.react.js +63 -51
  49. package/lib/fragments/DatePickerSingle.react.js +28 -17
  50. package/lib/fragments/Dropdown.react.js +33 -22
  51. package/lib/fragments/Graph.privateprops.js +1 -1
  52. package/lib/fragments/Graph.react.js +44 -28
  53. package/lib/fragments/Loading/spinners/CircleSpinner.js +16 -16
  54. package/lib/fragments/Loading/spinners/CubeSpinner.js +11 -11
  55. package/lib/fragments/Loading/spinners/DefaultSpinner.js +9 -9
  56. package/lib/fragments/Loading/spinners/DotSpinner.js +7 -7
  57. package/lib/fragments/Loading/spinners/GraphSpinner.js +18 -18
  58. package/lib/fragments/Markdown.react.js +35 -32
  59. package/lib/fragments/RangeSlider.react.js +57 -22
  60. package/lib/fragments/Slider.react.js +40 -21
  61. package/lib/fragments/Upload.react.js +19 -13
  62. package/lib/index.js +77 -53
  63. package/lib/third-party/highlight.js +12 -0
  64. package/lib/utils/LazyLoader/datePickerRange.js +9 -3
  65. package/lib/utils/LazyLoader/datePickerSingle.js +9 -3
  66. package/lib/utils/LazyLoader/dropdown.js +9 -3
  67. package/lib/utils/LazyLoader/graph.js +9 -3
  68. package/lib/utils/LazyLoader/hljs.js +9 -3
  69. package/lib/utils/LazyLoader/markdown.js +9 -3
  70. package/lib/utils/LazyLoader/plotly.js +9 -3
  71. package/lib/utils/LazyLoader/rangeSlider.js +9 -3
  72. package/lib/utils/LazyLoader/slider.js +9 -3
  73. package/lib/utils/LazyLoader/upload.js +9 -3
  74. package/lib/utils/computeSliderMarkers.js +230 -0
  75. package/lib/utils/convertToMoment.js +4 -0
  76. package/lib/utils/optionTypes.js +52 -0
  77. package/package.json +68 -75
  78. package/CHANGELOG.md +0 -1034
  79. package/dash_core_components/dash_core_components.min.js +0 -2
  80. package/dash_core_components/dash_core_components.min.js.map +0 -1
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ 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); }
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
- exports.defaultProps = exports.propTypes = exports.default = void 0;
8
+ exports.propTypes = exports.defaultProps = exports.default = void 0;
7
9
 
8
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
11
 
@@ -13,29 +15,33 @@ var _datePickerSingle = _interopRequireDefault(require("../utils/LazyLoader/date
13
15
 
14
16
  var _DatePickerPersistence = _interopRequireDefault(require("../utils/DatePickerPersistence"));
15
17
 
16
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
18
+ function _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
19
 
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+ function _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
21
 
20
- function _typeof(obj) { 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); }
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
23
 
22
24
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
25
 
24
26
  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); } }
25
27
 
26
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
28
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
27
29
 
28
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
30
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
31
 
30
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
32
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
33
 
32
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
34
+ 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); }; }
33
35
 
34
- 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
36
+ 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); }
35
37
 
36
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
38
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
39
+
40
+ 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; } }
37
41
 
38
- var RealDateSingleRange = (0, _react.lazy)(_datePickerSingle.default);
42
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
+
44
+ var RealDateSingleRange = /*#__PURE__*/(0, _react.lazy)(_datePickerSingle.default);
39
45
  /**
40
46
  * DatePickerSingle is a tailor made component designed for selecting
41
47
  * a single day off of a calendar.
@@ -48,23 +54,23 @@ var RealDateSingleRange = (0, _react.lazy)(_datePickerSingle.default);
48
54
  * which can be found here: https://github.com/airbnb/react-dates
49
55
  */
50
56
 
51
- var DatePickerSingle =
52
- /*#__PURE__*/
53
- function (_Component) {
57
+ var DatePickerSingle = /*#__PURE__*/function (_Component) {
54
58
  _inherits(DatePickerSingle, _Component);
55
59
 
60
+ var _super = _createSuper(DatePickerSingle);
61
+
56
62
  function DatePickerSingle() {
57
63
  _classCallCheck(this, DatePickerSingle);
58
64
 
59
- return _possibleConstructorReturn(this, _getPrototypeOf(DatePickerSingle).apply(this, arguments));
65
+ return _super.apply(this, arguments);
60
66
  }
61
67
 
62
68
  _createClass(DatePickerSingle, [{
63
69
  key: "render",
64
70
  value: function render() {
65
- return _react.default.createElement(_react.Suspense, {
71
+ return /*#__PURE__*/_react.default.createElement(_react.Suspense, {
66
72
  fallback: null
67
- }, _react.default.createElement(RealDateSingleRange, this.props));
73
+ }, /*#__PURE__*/_react.default.createElement(RealDateSingleRange, this.props));
68
74
  }
69
75
  }]);
70
76
 
@@ -73,13 +79,6 @@ function (_Component) {
73
79
 
74
80
  exports.default = DatePickerSingle;
75
81
  DatePickerSingle.propTypes = {
76
- /**
77
- * The ID of this component, used to identify dash components
78
- * in callbacks. The ID needs to be unique across all of the
79
- * components in an app.
80
- */
81
- id: _propTypes.default.string,
82
-
83
82
  /**
84
83
  * Specifies the starting date for the component, best practice is to pass
85
84
  * value via datetime object
@@ -101,37 +100,33 @@ DatePickerSingle.propTypes = {
101
100
  max_date_allowed: _propTypes.default.string,
102
101
 
103
102
  /**
104
- * Specifies the month that is initially presented when the user
105
- * opens the calendar. Accepts datetime.datetime objects or strings
103
+ * Specifies additional days between min_date_allowed and max_date_allowed
104
+ * that should be disabled. Accepted datetime.datetime objects or strings
106
105
  * in the format 'YYYY-MM-DD'
107
- *
108
- */
109
- initial_visible_month: _propTypes.default.string,
110
-
111
- /**
112
- * Size of rendered calendar days, higher number
113
- * means bigger day size and larger calendar overall
114
106
  */
115
- day_size: _propTypes.default.number,
107
+ disabled_days: _propTypes.default.arrayOf(_propTypes.default.string),
116
108
 
117
109
  /**
118
- * Orientation of calendar, either vertical or horizontal.
119
- * Valid options are 'vertical' or 'horizontal'.
110
+ * Text that will be displayed in the input
111
+ * box of the date picker when no date is selected.
112
+ * Default value is 'Start Date'
120
113
  */
121
- calendar_orientation: _propTypes.default.oneOf(['vertical', 'horizontal']),
114
+ placeholder: _propTypes.default.string,
122
115
 
123
116
  /**
124
- * Determines whether the calendar and days operate
125
- * from left to right or from right to left
117
+ * Specifies the month that is initially presented when the user
118
+ * opens the calendar. Accepts datetime.datetime objects or strings
119
+ * in the format 'YYYY-MM-DD'
120
+ *
126
121
  */
127
- is_RTL: _propTypes.default.bool,
122
+ initial_visible_month: _propTypes.default.string,
128
123
 
129
124
  /**
130
- * Text that will be displayed in the input
131
- * box of the date picker when no date is selected.
132
- * Default value is 'Start Date'
125
+ * Whether or not the dropdown is "clearable", that is, whether or
126
+ * not a small "x" appears on the right of the dropdown that removes
127
+ * the selected value.
133
128
  */
134
- placeholder: _propTypes.default.string,
129
+ clearable: _propTypes.default.bool,
135
130
 
136
131
  /**
137
132
  * If True, the calendar will automatically open when cleared
@@ -139,22 +134,23 @@ DatePickerSingle.propTypes = {
139
134
  reopen_calendar_on_clear: _propTypes.default.bool,
140
135
 
141
136
  /**
142
- * Number of calendar months that are shown when calendar is opened
143
- */
144
- number_of_months_shown: _propTypes.default.number,
145
-
146
- /**
147
- * If True, calendar will open in a screen overlay portal,
148
- * not supported on vertical calendar
137
+ * Specifies the format that the selected dates will be displayed
138
+ * valid formats are variations of "MM YY DD". For example:
139
+ * "MM YY DD" renders as '05 10 97' for May 10th 1997
140
+ * "MMMM, YY" renders as 'May, 1997' for May 10th 1997
141
+ * "M, D, YYYY" renders as '07, 10, 1997' for September 10th 1997
142
+ * "MMMM" renders as 'May' for May 10 1997
149
143
  */
150
- with_portal: _propTypes.default.bool,
144
+ display_format: _propTypes.default.string,
151
145
 
152
146
  /**
153
- * If True, calendar will open in a full screen overlay portal, will
154
- * take precedent over 'withPortal' if both are set to True,
155
- * not supported on vertical calendar
147
+ * Specifies the format that the month will be displayed in the calendar,
148
+ * valid formats are variations of "MM YY". For example:
149
+ * "MM YY" renders as '05 97' for May 1997
150
+ * "MMMM, YYYY" renders as 'May, 1997' for May 1997
151
+ * "MMM, YY" renders as 'Sep, 97' for September 1997
156
152
  */
157
- with_full_screen_portal: _propTypes.default.bool,
153
+ month_format: _propTypes.default.string,
158
154
 
159
155
  /**
160
156
  * Specifies what day is the first day of the week, values must be
@@ -162,6 +158,12 @@ DatePickerSingle.propTypes = {
162
158
  */
163
159
  first_day_of_week: _propTypes.default.oneOf([0, 1, 2, 3, 4, 5, 6]),
164
160
 
161
+ /**
162
+ * If True the calendar will display days that rollover into
163
+ * the next month
164
+ */
165
+ show_outside_days: _propTypes.default.bool,
166
+
165
167
  /**
166
168
  * If True the calendar will not close when the user has selected a value
167
169
  * and will wait until the user clicks off the calendar
@@ -169,46 +171,45 @@ DatePickerSingle.propTypes = {
169
171
  stay_open_on_select: _propTypes.default.bool,
170
172
 
171
173
  /**
172
- * If True the calendar will display days that rollover into
173
- * the next month
174
+ * Orientation of calendar, either vertical or horizontal.
175
+ * Valid options are 'vertical' or 'horizontal'.
174
176
  */
175
- show_outside_days: _propTypes.default.bool,
177
+ calendar_orientation: _propTypes.default.oneOf(['vertical', 'horizontal']),
176
178
 
177
179
  /**
178
- * Specifies the format that the month will be displayed in the calendar,
179
- * valid formats are variations of "MM YY". For example:
180
- * "MM YY" renders as '05 97' for May 1997
181
- * "MMMM, YYYY" renders as 'May, 1997' for May 1997
182
- * "MMM, YY" renders as 'Sep, 97' for September 1997
180
+ * Number of calendar months that are shown when calendar is opened
183
181
  */
184
- month_format: _propTypes.default.string,
182
+ number_of_months_shown: _propTypes.default.number,
185
183
 
186
184
  /**
187
- * Specifies the format that the selected dates will be displayed
188
- * valid formats are variations of "MM YY DD". For example:
189
- * "MM YY DD" renders as '05 10 97' for May 10th 1997
190
- * "MMMM, YY" renders as 'May, 1997' for May 10th 1997
191
- * "M, D, YYYY" renders as '07, 10, 1997' for September 10th 1997
192
- * "MMMM" renders as 'May' for May 10 1997
185
+ * If True, calendar will open in a screen overlay portal,
186
+ * not supported on vertical calendar
193
187
  */
194
- display_format: _propTypes.default.string,
188
+ with_portal: _propTypes.default.bool,
195
189
 
196
190
  /**
197
- * If True, no dates can be selected.
191
+ * If True, calendar will open in a full screen overlay portal, will
192
+ * take precedent over 'withPortal' if both are set to True,
193
+ * not supported on vertical calendar
198
194
  */
199
- disabled: _propTypes.default.bool,
195
+ with_full_screen_portal: _propTypes.default.bool,
200
196
 
201
197
  /**
202
- * Whether or not the dropdown is "clearable", that is, whether or
203
- * not a small "x" appears on the right of the dropdown that removes
204
- * the selected value.
198
+ * Size of rendered calendar days, higher number
199
+ * means bigger day size and larger calendar overall
205
200
  */
206
- clearable: _propTypes.default.bool,
201
+ day_size: _propTypes.default.number,
207
202
 
208
203
  /**
209
- * Dash-assigned callback that gets fired when the value changes.
204
+ * Determines whether the calendar and days operate
205
+ * from left to right or from right to left
210
206
  */
211
- setProps: _propTypes.default.func,
207
+ is_RTL: _propTypes.default.bool,
208
+
209
+ /**
210
+ * If True, no dates can be selected.
211
+ */
212
+ disabled: _propTypes.default.bool,
212
213
 
213
214
  /**
214
215
  * CSS styles appended to wrapper div
@@ -220,6 +221,18 @@ DatePickerSingle.propTypes = {
220
221
  */
221
222
  className: _propTypes.default.string,
222
223
 
224
+ /**
225
+ * The ID of this component, used to identify dash components
226
+ * in callbacks. The ID needs to be unique across all of the
227
+ * components in an app.
228
+ */
229
+ id: _propTypes.default.string,
230
+
231
+ /**
232
+ * Dash-assigned callback that gets fired when the value changes.
233
+ */
234
+ setProps: _propTypes.default.func,
235
+
223
236
  /**
224
237
  * Object that holds the loading state object coming from dash-renderer
225
238
  */
@@ -282,7 +295,8 @@ DatePickerSingle.defaultProps = {
282
295
  clearable: false,
283
296
  disabled: false,
284
297
  persisted_props: ['date'],
285
- persistence_type: 'local'
298
+ persistence_type: 'local',
299
+ disabled_days: []
286
300
  };
287
301
  var propTypes = DatePickerSingle.propTypes;
288
302
  exports.propTypes = propTypes;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _base64Js = require("base64-js");
15
+
16
+ var _fileSaver = require("file-saver");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+
22
+ 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); } }
23
+
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
25
+
26
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
27
+
28
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
+
30
+ 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); }; }
31
+
32
+ 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); }
33
+
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
+
36
+ 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; } }
37
+
38
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39
+
40
+ var getValue = function getValue(src, fallback, key) {
41
+ return key in src ? src[key] : fallback[key];
42
+ };
43
+ /**
44
+ * The Download component opens a download dialog when the data property changes.
45
+ */
46
+
47
+
48
+ var Download = /*#__PURE__*/function (_Component) {
49
+ _inherits(Download, _Component);
50
+
51
+ var _super = _createSuper(Download);
52
+
53
+ function Download() {
54
+ _classCallCheck(this, Download);
55
+
56
+ return _super.apply(this, arguments);
57
+ }
58
+
59
+ _createClass(Download, [{
60
+ key: "componentDidUpdate",
61
+ value: function componentDidUpdate(prevProps) {
62
+ var data = this.props.data; // If the data hasn't changed, do nothing.
63
+
64
+ if (!data || data === prevProps.data) {
65
+ return;
66
+ } // Extract options from data if provided, fallback to props.
67
+
68
+
69
+ var type = getValue(data, this.props, 'type');
70
+ var base64 = getValue(data, this.props, 'base64'); // Invoke the download using a Blob.
71
+
72
+ var content = base64 ? (0, _base64Js.toByteArray)(data.content) : data.content;
73
+ var blob = new Blob([content], {
74
+ type: type
75
+ });
76
+ (0, _fileSaver.saveAs)(blob, data.filename);
77
+ }
78
+ }, {
79
+ key: "render",
80
+ value: function render() {
81
+ return null;
82
+ }
83
+ }]);
84
+
85
+ return Download;
86
+ }(_react.Component);
87
+
88
+ exports.default = Download;
89
+ Download.propTypes = {
90
+ /**
91
+ * The ID of this component, used to identify dash components in callbacks.
92
+ */
93
+ id: _propTypes.default.string,
94
+
95
+ /**
96
+ * On change, a download is invoked.
97
+ */
98
+ data: _propTypes.default.exact({
99
+ /**
100
+ * Suggested filename in the download dialogue.
101
+ */
102
+ filename: _propTypes.default.string.isRequired,
103
+
104
+ /**
105
+ * File content.
106
+ */
107
+ content: _propTypes.default.string.isRequired,
108
+
109
+ /**
110
+ * Set to true, when data is base64 encoded.
111
+ */
112
+ base64: _propTypes.default.bool,
113
+
114
+ /**
115
+ * Blob type, usually a MIME-type.
116
+ */
117
+ type: _propTypes.default.string
118
+ }),
119
+
120
+ /**
121
+ * Default value for base64, used when not set as part of the data property.
122
+ */
123
+ base64: _propTypes.default.bool,
124
+
125
+ /**
126
+ * Default value for type, used when not set as part of the data property.
127
+ */
128
+ type: _propTypes.default.string,
129
+
130
+ /**
131
+ * Dash-supplied function for updating props.
132
+ */
133
+ setProps: _propTypes.default.func
134
+ };
135
+ Download.defaultProps = {
136
+ type: 'text/plain',
137
+ base64: false
138
+ };