dtable-ui-component 0.1.75-beta → 0.1.75-beta1

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 (115) hide show
  1. package/lib/app.css +20 -0
  2. package/lib/app.js +96 -0
  3. package/lib/assets/images/avatar/default_avatar.png +0 -0
  4. package/lib/assets/images/file/192/excel.png +0 -0
  5. package/lib/assets/images/file/192/file.png +0 -0
  6. package/lib/assets/images/file/192/music.png +0 -0
  7. package/lib/assets/images/file/192/pdf.png +0 -0
  8. package/lib/assets/images/file/192/pic.png +0 -0
  9. package/lib/assets/images/file/192/ppt.png +0 -0
  10. package/lib/assets/images/file/192/txt.png +0 -0
  11. package/lib/assets/images/file/192/video.png +0 -0
  12. package/lib/assets/images/file/192/word.png +0 -0
  13. package/lib/assets/images/file/24/excel.png +0 -0
  14. package/lib/assets/images/file/24/file.png +0 -0
  15. package/lib/assets/images/file/24/music.png +0 -0
  16. package/lib/assets/images/file/24/pdf.png +0 -0
  17. package/lib/assets/images/file/24/pic.png +0 -0
  18. package/lib/assets/images/file/24/ppt.png +0 -0
  19. package/lib/assets/images/file/24/txt.png +0 -0
  20. package/lib/assets/images/file/24/video.png +0 -0
  21. package/lib/assets/images/file/24/word.png +0 -0
  22. package/lib/assets/images/folder/folder-192.png +0 -0
  23. package/lib/assets/images/folder/folder-24.png +0 -0
  24. package/lib/components/cell-editor/checkbox-editor.js +111 -0
  25. package/lib/components/cell-editor/collaborator-editor.js +249 -0
  26. package/lib/components/cell-editor/date-editor.js +171 -0
  27. package/lib/components/cell-editor/index.js +40 -0
  28. package/lib/components/cell-editor/link-editor.js +321 -0
  29. package/lib/components/cell-editor/multiple-select-editor.js +250 -0
  30. package/lib/components/cell-editor/number-editor.js +162 -0
  31. package/lib/components/cell-editor/single-select-editor.js +216 -0
  32. package/lib/components/cell-editor/text-editor.js +129 -0
  33. package/lib/components/cell-editor-dialog/pc-file-editor-dialog.js +66 -0
  34. package/lib/components/cell-editor-dialog/pc-files-addition/index.js +1 -0
  35. package/lib/components/cell-editor-dialog/pc-files-addition/pc-file-uploaded-item.js +1 -0
  36. package/lib/components/cell-editor-dialog/pc-files-preview/index.js +1 -0
  37. package/lib/components/cell-editor-dialog/pc-files-preview/pc-file-item-preview.js +1 -0
  38. package/lib/components/cell-editor-popover/mb-collaborator-editor-popover.js +183 -0
  39. package/lib/components/cell-editor-popover/mb-date-editor-popover.js +262 -0
  40. package/lib/components/cell-editor-popover/mb-link-editor-popover.js +176 -0
  41. package/lib/components/cell-editor-popover/mb-select-editor-popover.js +243 -0
  42. package/lib/components/cell-editor-popover/pc-collaborator-editor-popover.js +124 -0
  43. package/lib/components/cell-editor-popover/pc-date-editor-popover.js +156 -0
  44. package/lib/components/cell-editor-popover/pc-link-editor-popover.js +128 -0
  45. package/lib/components/cell-editor-popover/pc-select-editor-popover.js +157 -0
  46. package/lib/components/cell-factory/cell-formatter-factory.js +28 -0
  47. package/lib/components/cell-formatter/auto-number-formatter.js +45 -0
  48. package/lib/components/cell-formatter/button-formatter.js +66 -0
  49. package/lib/components/cell-formatter/checkbox-formatter.js +56 -0
  50. package/lib/components/cell-formatter/collaborator-formatter.js +111 -0
  51. package/lib/components/cell-formatter/creator-formatter.js +105 -0
  52. package/lib/components/cell-formatter/ctime-formatter.js +70 -0
  53. package/lib/components/cell-formatter/date-formatter.js +73 -0
  54. package/lib/components/cell-formatter/duration-formatter.js +49 -0
  55. package/lib/components/cell-formatter/email-formatter.js +45 -0
  56. package/lib/components/cell-formatter/file-formatter.js +77 -0
  57. package/lib/components/cell-formatter/formatter-config.js +66 -0
  58. package/lib/components/cell-formatter/formula-formatter.js +189 -0
  59. package/lib/components/cell-formatter/geolocation-formatter.js +66 -0
  60. package/lib/components/cell-formatter/image-formatter.js +171 -0
  61. package/lib/components/cell-formatter/index.js +112 -0
  62. package/lib/components/cell-formatter/last-modifier-formatter.js +105 -0
  63. package/lib/components/cell-formatter/link-formatter.js +165 -0
  64. package/lib/components/cell-formatter/long-text-formatter.js +46 -0
  65. package/lib/components/cell-formatter/mtime-formatter.js +70 -0
  66. package/lib/components/cell-formatter/multiple-select-formatter.js +84 -0
  67. package/lib/components/cell-formatter/number-formatter.js +60 -0
  68. package/lib/components/cell-formatter/rate-formatter.js +93 -0
  69. package/lib/components/cell-formatter/single-select-formatter.js +84 -0
  70. package/lib/components/cell-formatter/text-formatter.js +67 -0
  71. package/lib/components/cell-formatter/url-formatter.js +45 -0
  72. package/lib/components/cell-formatter/widgets/file-item-formatter.js +63 -0
  73. package/lib/components/cell-formatter/widgets/image-previewer-lightbox.js +152 -0
  74. package/lib/components/cell-formatter/widgets/long-text-formatter/html-long-text-formatter.js +107 -0
  75. package/lib/components/cell-formatter/widgets/long-text-formatter/simple-long-text-formatter.js +110 -0
  76. package/lib/components/common/collaborator-item.js +79 -0
  77. package/lib/components/common/edit-editor-button.js +67 -0
  78. package/lib/components/common/images-lazy-load.js +158 -0
  79. package/lib/components/common/link-editor-option.js +121 -0
  80. package/lib/components/common/mobile/mb-editor-header.js +61 -0
  81. package/lib/components/common/modal-portal.js +51 -0
  82. package/lib/components/common/select-editor-option.js +122 -0
  83. package/lib/components/common/select-item.js +73 -0
  84. package/lib/components/file-uploader/index.js +63 -0
  85. package/lib/components/loading.js +16 -0
  86. package/lib/components/toast/alert.js +164 -0
  87. package/lib/components/toast/index.js +12 -0
  88. package/lib/components/toast/toast.js +223 -0
  89. package/lib/components/toast/toastManager.js +189 -0
  90. package/lib/components/toast/toaster.js +92 -0
  91. package/lib/constants/cell-types.js +54 -0
  92. package/lib/constants/index.js +70 -0
  93. package/lib/css/cell-editor.css +614 -0
  94. package/lib/css/cell-formatter.css +247 -0
  95. package/lib/css/custom-rc-calendar.css +118 -0
  96. package/lib/css/image-previewer-ligntbox.css +87 -0
  97. package/lib/css/loading.css +54 -0
  98. package/lib/index.js +64 -0
  99. package/lib/lang/index.js +66 -0
  100. package/lib/locals/de.js +7 -0
  101. package/lib/locals/en.js +22 -0
  102. package/lib/locals/fr.js +7 -0
  103. package/lib/locals/zh-CN.js +22 -0
  104. package/lib/utils/cell-value-validator.js +41 -0
  105. package/lib/utils/column-utils.js +15 -0
  106. package/lib/utils/editor-utils.js +81 -0
  107. package/lib/utils/markdown2html.js +68 -0
  108. package/lib/utils/normalize-long-text-value.js +74 -0
  109. package/lib/utils/number-precision.js +181 -0
  110. package/lib/utils/unified/index.js +470 -0
  111. package/lib/utils/utils.js +141 -0
  112. package/lib/utils/value-format-utils.js +545 -0
  113. package/lib/utils/vfile/core.js +172 -0
  114. package/lib/utils/vfile/index.js +48 -0
  115. package/package.json +3 -3
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
11
+
12
+ var _react = _interopRequireDefault(require("react"));
13
+
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
+
16
+ var _glamor = require("glamor");
17
+
18
+ var propTypes = {
19
+ intent: _propTypes.default.string.isRequired,
20
+ title: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]).isRequired,
21
+ onRemove: _propTypes.default.func.isRequired,
22
+ children: _propTypes.default.string,
23
+ isRemoveable: _propTypes.default.bool
24
+ };
25
+
26
+ var Alert = /*#__PURE__*/function (_React$PureComponent) {
27
+ (0, _inheritsLoose2.default)(Alert, _React$PureComponent);
28
+
29
+ function Alert(props) {
30
+ var _this;
31
+
32
+ _this = _React$PureComponent.call(this, props) || this;
33
+ _this.containerStyle = (0, _glamor.css)({
34
+ borderRadius: '3px',
35
+ backgroundColor: '#fff',
36
+ padding: '10px 16px',
37
+ display: 'flex',
38
+ boxSizing: 'border-box',
39
+ boxShadow: 'rgba(67, 90, 111, 0.3) 0px 0px 1px, rgba(67, 90, 111, 0.47) 0px 8px 10px -4px',
40
+ justifyContent: 'space-between',
41
+ flexDirection: 'row'
42
+ });
43
+ _this.containerBorderSuccess = (0, _glamor.css)({
44
+ borderLeft: '3px solid rgb(71, 184, 129)'
45
+ });
46
+ _this.containerBorderWarn = (0, _glamor.css)({
47
+ borderLeft: '3px solid rgb(217, 130, 43)'
48
+ });
49
+ _this.containerBorderDanger = (0, _glamor.css)({
50
+ borderLeft: '3px solid rgb(236, 76, 71)'
51
+ });
52
+ _this.containerBorderNotify = (0, _glamor.css)({
53
+ borderLeft: '3px solid rgb(16, 112, 202)'
54
+ });
55
+ _this.toastTextTitle = (0, _glamor.css)({
56
+ fontWeight: '600',
57
+ fontSize: '14px',
58
+ color: '#435a6f',
59
+ margin: '0'
60
+ });
61
+ _this.toastTextChild = (0, _glamor.css)({
62
+ fontSize: '14px',
63
+ color: '#999',
64
+ margin: '0'
65
+ });
66
+ _this.toastClose = (0, _glamor.css)({
67
+ marginLeft: '15px',
68
+ height: '24px',
69
+ width: '24px',
70
+ lineHeight: '22px',
71
+ fontWeight: '700',
72
+ textAlign: 'center',
73
+ fontSize: '20px',
74
+ color: '#000',
75
+ cursor: 'pointer',
76
+ opacity: '0.5',
77
+ ':hover': {
78
+ opacity: 1
79
+ }
80
+ });
81
+ _this.toastIcon = (0, _glamor.css)({
82
+ marginRight: '10px',
83
+ width: '14px',
84
+ height: '20px',
85
+ lineHeight: '20px'
86
+ });
87
+ return _this;
88
+ }
89
+
90
+ var _proto = Alert.prototype;
91
+
92
+ _proto.getContainerStyle = function getContainerStyle(intent) {
93
+ switch (intent) {
94
+ case 'success':
95
+ return {
96
+ borderStyle: this.containerBorderSuccess,
97
+ iconColor: (0, _glamor.css)({
98
+ color: 'rgb(71, 184, 129)'
99
+ }),
100
+ iconClass: 'dtable-font dtable-icon-check-circle'
101
+ };
102
+
103
+ case 'warning':
104
+ return {
105
+ borderStyle: this.containerBorderWarn,
106
+ iconColor: (0, _glamor.css)({
107
+ color: 'rgb(217, 130, 43)'
108
+ }),
109
+ iconClass: 'dtable-font dtable-icon-exclamation-triangle'
110
+ };
111
+
112
+ case 'none':
113
+ return {
114
+ borderStyle: this.containerBorderNotify,
115
+ iconColor: (0, _glamor.css)({
116
+ color: 'rgb(16, 112, 202)'
117
+ }),
118
+ iconClass: 'dtable-font dtable-icon-exclamation-circle'
119
+ };
120
+
121
+ case 'danger':
122
+ return {
123
+ borderStyle: this.containerBorderDanger,
124
+ iconColor: (0, _glamor.css)({
125
+ color: 'rgb(236, 76, 71)'
126
+ }),
127
+ iconClass: 'dtable-font dtable-icon-exclamation-circle'
128
+ };
129
+
130
+ default:
131
+ return {
132
+ borderStyle: this.containerBorderSuccess,
133
+ iconColor: (0, _glamor.css)({
134
+ color: 'rgb(71, 184, 129)'
135
+ }),
136
+ iconClass: 'dtable-font dtable-icon-check-circle'
137
+ };
138
+ }
139
+ };
140
+
141
+ _proto.render = function render() {
142
+ var toastStyle = this.getContainerStyle(this.props.intent);
143
+ return /*#__PURE__*/_react.default.createElement("div", (0, _glamor.css)(toastStyle.borderStyle, this.containerStyle), /*#__PURE__*/_react.default.createElement("div", {
144
+ className: this.toastIcon
145
+ }, /*#__PURE__*/_react.default.createElement("i", (0, _extends2.default)({
146
+ className: toastStyle.iconClass
147
+ }, toastStyle.iconColor))), /*#__PURE__*/_react.default.createElement("div", {
148
+ className: this.toastTextContainer
149
+ }, /*#__PURE__*/_react.default.createElement("p", {
150
+ className: this.toastTextTitle
151
+ }, this.props.title), this.props.children ? /*#__PURE__*/_react.default.createElement("p", {
152
+ className: this.toastTextChild
153
+ }, this.props.children) : null), this.props.isRemoveable && /*#__PURE__*/_react.default.createElement("div", {
154
+ onClick: this.props.onRemove,
155
+ className: this.toastClose
156
+ }, /*#__PURE__*/_react.default.createElement("span", null, "\xD7")));
157
+ };
158
+
159
+ return Alert;
160
+ }(_react.default.PureComponent);
161
+
162
+ Alert.propTypes = propTypes;
163
+ var _default = Alert;
164
+ exports.default = _default;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+
8
+ var _toaster = _interopRequireDefault(require("./toaster"));
9
+
10
+ var toaster = new _toaster.default();
11
+ var _default = toaster;
12
+ exports.default = _default;
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+
8
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
9
+
10
+ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _react = _interopRequireDefault(require("react"));
15
+
16
+ var _glamor = require("glamor");
17
+
18
+ var _propTypes = _interopRequireDefault(require("prop-types"));
19
+
20
+ var _Transition = _interopRequireDefault(require("react-transition-group/Transition"));
21
+
22
+ var _alert = _interopRequireDefault(require("./alert"));
23
+
24
+ var animationEasing = {
25
+ deceleration: 'cubic-bezier(0.0, 0.0, 0.2, 1)',
26
+ acceleration: 'cubic-bezier(0.4, 0.0, 1, 1)',
27
+ spring: 'cubic-bezier(0.175, 0.885, 0.320, 1.175)'
28
+ };
29
+ var ANIMATION_DURATION = 240;
30
+
31
+ var openAnimation = _glamor.css.keyframes('openAnimation', {
32
+ from: {
33
+ opacity: 0,
34
+ transform: 'translateY(-120%)'
35
+ },
36
+ to: {
37
+ transform: 'translateY(0)'
38
+ }
39
+ });
40
+
41
+ var closeAnimation = _glamor.css.keyframes('closeAnimation', {
42
+ from: {
43
+ transform: 'scale(1)',
44
+ opacity: 1
45
+ },
46
+ to: {
47
+ transform: 'scale(0.9)',
48
+ opacity: 0
49
+ }
50
+ });
51
+
52
+ var animationStyles = (0, _glamor.css)({
53
+ display: 'flex',
54
+ flexDirection: 'column',
55
+ alignItems: 'center',
56
+ height: 0,
57
+ transition: "all " + ANIMATION_DURATION + "ms " + animationEasing.deceleration,
58
+ '&[data-state="entering"], &[data-state="entered"]': {
59
+ animation: openAnimation + " " + ANIMATION_DURATION + "ms " + animationEasing.spring + " both"
60
+ },
61
+ '&[data-state="exiting"]': {
62
+ animation: closeAnimation + " 120ms " + animationEasing.acceleration + " both"
63
+ }
64
+ });
65
+
66
+ var Toast = /*#__PURE__*/function (_React$PureComponent) {
67
+ (0, _inheritsLoose2.default)(Toast, _React$PureComponent);
68
+
69
+ function Toast() {
70
+ var _this;
71
+
72
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
73
+ args[_key] = arguments[_key];
74
+ }
75
+
76
+ _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;
77
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
78
+ isShown: true,
79
+ height: 0
80
+ });
81
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "close", function () {
82
+ _this.clearCloseTimer();
83
+
84
+ _this.setState({
85
+ isShown: false
86
+ });
87
+ });
88
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "startCloseTimer", function () {
89
+ if (_this.props.duration) {
90
+ _this.closeTimer = setTimeout(function () {
91
+ _this.close();
92
+ }, _this.props.duration * 1000);
93
+ }
94
+ });
95
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "clearCloseTimer", function () {
96
+ if (_this.closeTimer) {
97
+ clearTimeout(_this.closeTimer);
98
+ _this.closeTimer = null;
99
+ }
100
+ });
101
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleMouseEnter", function () {
102
+ _this.clearCloseTimer();
103
+ });
104
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleMouseLeave", function () {
105
+ _this.startCloseTimer();
106
+ });
107
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onRef", function (ref) {
108
+ if (ref === null) return;
109
+
110
+ var _ref$getBoundingClien = ref.getBoundingClientRect(),
111
+ height = _ref$getBoundingClien.height;
112
+
113
+ _this.setState({
114
+ height: height
115
+ });
116
+ });
117
+ return _this;
118
+ }
119
+
120
+ var _proto = Toast.prototype;
121
+
122
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
123
+ if (prevProps.isShown !== this.props.isShown) {
124
+ // eslint-disable-next-line react/no-did-update-set-state
125
+ this.setState({
126
+ isShown: this.props.isShown
127
+ });
128
+ }
129
+ };
130
+
131
+ _proto.componentDidMount = function componentDidMount() {
132
+ this.startCloseTimer();
133
+ };
134
+
135
+ _proto.componentWillUnmount = function componentWillUnmount() {
136
+ this.clearCloseTimer();
137
+ };
138
+
139
+ _proto.render = function render() {
140
+ var _this2 = this;
141
+
142
+ return /*#__PURE__*/_react.default.createElement(_Transition.default, {
143
+ appear: true,
144
+ unmountOnExit: true,
145
+ timeout: ANIMATION_DURATION,
146
+ in: this.state.isShown,
147
+ onExited: this.props.onRemove
148
+ }, function (state) {
149
+ return /*#__PURE__*/_react.default.createElement("div", {
150
+ "data-state": state,
151
+ className: animationStyles,
152
+ onMouseEnter: _this2.handleMouseEnter,
153
+ onMouseLeave: _this2.handleMouseLeave,
154
+ style: {
155
+ height: _this2.state.height,
156
+ zIndex: _this2.props.zIndex,
157
+ marginBottom: _this2.state.isShown ? 0 : -_this2.state.height
158
+ }
159
+ }, /*#__PURE__*/_react.default.createElement("div", {
160
+ ref: _this2.onRef,
161
+ style: {
162
+ padding: 8
163
+ }
164
+ }, /*#__PURE__*/_react.default.createElement(_alert.default, {
165
+ intent: _this2.props.intent,
166
+ title: _this2.props.title,
167
+ children: _this2.props.children || '',
168
+ isRemoveable: _this2.props.hasCloseButton,
169
+ onRemove: function onRemove() {
170
+ return _this2.close();
171
+ }
172
+ })));
173
+ });
174
+ };
175
+
176
+ return Toast;
177
+ }(_react.default.PureComponent);
178
+
179
+ exports.default = Toast;
180
+ (0, _defineProperty2.default)(Toast, "propTypes", {
181
+ /**
182
+ * The z-index of the toast.
183
+ */
184
+ zIndex: _propTypes.default.number,
185
+
186
+ /**
187
+ * Duration of the toast.
188
+ */
189
+ duration: _propTypes.default.number,
190
+
191
+ /**
192
+ * Function called when the toast is all the way closed.
193
+ */
194
+ onRemove: _propTypes.default.func,
195
+
196
+ /**
197
+ * The type of the alert.
198
+ */
199
+ intent: _propTypes.default.oneOf(['none', 'success', 'warning', 'danger']).isRequired,
200
+
201
+ /**
202
+ * The title of the alert.
203
+ */
204
+ title: _propTypes.default.node,
205
+
206
+ /**
207
+ * Description of the alert.
208
+ */
209
+ children: _propTypes.default.node,
210
+
211
+ /**
212
+ * When true, show a close icon button inside of the toast.
213
+ */
214
+ hasCloseButton: _propTypes.default.bool,
215
+
216
+ /**
217
+ * When false, will close the Toast and call onRemove when finished.
218
+ */
219
+ isShown: _propTypes.default.bool
220
+ });
221
+ (0, _defineProperty2.default)(Toast, "defaultProps", {
222
+ intent: 'none'
223
+ });
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
+
12
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
13
+
14
+ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
15
+
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+
18
+ var _react = _interopRequireDefault(require("react"));
19
+
20
+ var _glamor = require("glamor");
21
+
22
+ var _propTypes = _interopRequireDefault(require("prop-types"));
23
+
24
+ var _toast = _interopRequireDefault(require("./toast"));
25
+
26
+ var _excluded = ["id", "description"];
27
+
28
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
29
+
30
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
31
+
32
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
33
+
34
+ function _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); }
35
+
36
+ function _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; }
37
+
38
+ var wrapperClass = (0, _glamor.css)({
39
+ maxWidth: 560,
40
+ margin: '0 auto',
41
+ top: 0,
42
+ left: 0,
43
+ right: 0,
44
+ position: 'fixed',
45
+ zIndex: 999999
46
+ });
47
+
48
+ var hasCustomId = function hasCustomId(settings) {
49
+ return Object.hasOwnProperty.call(settings, 'id');
50
+ };
51
+
52
+ var ToastManager = /*#__PURE__*/function (_React$PureComponent) {
53
+ (0, _inheritsLoose2.default)(ToastManager, _React$PureComponent);
54
+
55
+ function ToastManager(props, context) {
56
+ var _this;
57
+
58
+ _this = _React$PureComponent.call(this, props, context) || this;
59
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getToasts", function () {
60
+ return _this.state.toasts;
61
+ });
62
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "closeAll", function () {
63
+ _this.getToasts().forEach(function (toast) {
64
+ return toast.close();
65
+ });
66
+ });
67
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "notify", function (title, settings) {
68
+ // If there's a custom toast ID passed, close existing toasts with the same custom ID
69
+ if (hasCustomId(settings)) {
70
+ for (var _iterator = _createForOfIteratorHelperLoose(_this.state.toasts), _step; !(_step = _iterator()).done;) {
71
+ var toast = _step.value;
72
+
73
+ // Since unique ID is still appended to a custom ID, skip the unique ID and check only prefix
74
+ if (String(toast.id).startsWith(settings.id)) {
75
+ _this.closeToast(toast.id);
76
+ }
77
+ }
78
+ }
79
+
80
+ var instance = _this.createToastInstance(title, settings);
81
+
82
+ _this.setState(function (previousState) {
83
+ return {
84
+ toasts: [instance].concat(previousState.toasts)
85
+ };
86
+ });
87
+
88
+ return instance;
89
+ });
90
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createToastInstance", function (title, settings) {
91
+ var uniqueId = ++ToastManager.idCounter;
92
+ var id = hasCustomId(settings) ? settings.id + "-" + uniqueId : uniqueId;
93
+ var hasCloseButton = settings.hasCloseButton || true;
94
+ var duration = settings.duration || 2;
95
+
96
+ if (settings.hasCloseButton !== undefined) {
97
+ hasCloseButton = settings.hasCloseButton;
98
+ }
99
+
100
+ if (settings.duration !== undefined) {
101
+ duration = settings.duration;
102
+ }
103
+
104
+ return {
105
+ id: id,
106
+ title: title,
107
+ description: settings.description,
108
+ hasCloseButton: hasCloseButton,
109
+ duration: duration,
110
+ close: function close() {
111
+ return _this.closeToast(id);
112
+ },
113
+ intent: settings.intent
114
+ };
115
+ });
116
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "closeToast", function (id) {
117
+ _this.setState(function (previousState) {
118
+ return {
119
+ toasts: previousState.toasts.map(function (toast) {
120
+ if (toast.id === id) {
121
+ return _objectSpread(_objectSpread({}, toast), {}, {
122
+ isShown: false
123
+ });
124
+ }
125
+
126
+ return toast;
127
+ })
128
+ };
129
+ });
130
+ });
131
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "removeToast", function (id) {
132
+ _this.setState(function (previousState) {
133
+ return {
134
+ toasts: previousState.toasts.filter(function (toast) {
135
+ return toast.id !== id;
136
+ })
137
+ };
138
+ });
139
+ });
140
+ props.bindNotify(_this.notify);
141
+ props.bindGetToasts(_this.getToasts);
142
+ props.bindCloseAll(_this.closeAll);
143
+ _this.state = {
144
+ toasts: []
145
+ };
146
+ return _this;
147
+ }
148
+
149
+ var _proto = ToastManager.prototype;
150
+
151
+ _proto.render = function render() {
152
+ var _this2 = this;
153
+
154
+ return /*#__PURE__*/_react.default.createElement("span", {
155
+ className: wrapperClass
156
+ }, this.state.toasts.map(function (_ref) {
157
+ var id = _ref.id,
158
+ description = _ref.description,
159
+ props = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
160
+ return /*#__PURE__*/_react.default.createElement(_toast.default, (0, _extends2.default)({
161
+ key: id,
162
+ onRemove: function onRemove() {
163
+ return _this2.removeToast(id);
164
+ }
165
+ }, props), description);
166
+ }));
167
+ };
168
+
169
+ return ToastManager;
170
+ }(_react.default.PureComponent);
171
+
172
+ exports.default = ToastManager;
173
+ (0, _defineProperty2.default)(ToastManager, "propTypes", {
174
+ /**
175
+ * Function called with the `this.notify` function.
176
+ */
177
+ bindNotify: _propTypes.default.func.isRequired,
178
+
179
+ /**
180
+ * Function called with the `this.getToasts` function.
181
+ */
182
+ bindGetToasts: _propTypes.default.func.isRequired,
183
+
184
+ /**
185
+ * Function called with the `this.closeAll` function.
186
+ */
187
+ bindCloseAll: _propTypes.default.func.isRequired
188
+ });
189
+ (0, _defineProperty2.default)(ToastManager, "idCounter", 0);
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _reactDom = _interopRequireDefault(require("react-dom"));
13
+
14
+ var _toastManager = _interopRequireDefault(require("./toastManager"));
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
21
+ /**
22
+ * The Toaster manages the interactionsb between
23
+ * the ToasterManger and the toast API.
24
+ */
25
+
26
+ var Toaster = function Toaster() {
27
+ var _this = this;
28
+
29
+ (0, _defineProperty2.default)(this, "_bindNotify", function (handler) {
30
+ _this.notifyHandler = handler;
31
+ });
32
+ (0, _defineProperty2.default)(this, "_bindGetToasts", function (handler) {
33
+ _this.getToastsHandler = handler;
34
+ });
35
+ (0, _defineProperty2.default)(this, "_bindCloseAll", function (handler) {
36
+ _this.closeAllHandler = handler;
37
+ });
38
+ (0, _defineProperty2.default)(this, "getToasts", function () {
39
+ return _this.getToastsHandler();
40
+ });
41
+ (0, _defineProperty2.default)(this, "closeAll", function () {
42
+ return _this.closeAllHandler();
43
+ });
44
+ (0, _defineProperty2.default)(this, "notify", function (title, settings) {
45
+ if (settings === void 0) {
46
+ settings = {};
47
+ }
48
+
49
+ return _this.notifyHandler(title, _objectSpread(_objectSpread({}, settings), {}, {
50
+ intent: 'none'
51
+ }));
52
+ });
53
+ (0, _defineProperty2.default)(this, "success", function (title, settings) {
54
+ if (settings === void 0) {
55
+ settings = {};
56
+ }
57
+
58
+ return _this.notifyHandler(title, _objectSpread(_objectSpread({}, settings), {}, {
59
+ intent: 'success'
60
+ }));
61
+ });
62
+ (0, _defineProperty2.default)(this, "warning", function (title, settings) {
63
+ if (settings === void 0) {
64
+ settings = {};
65
+ }
66
+
67
+ return _this.notifyHandler(title, _objectSpread(_objectSpread({}, settings), {}, {
68
+ intent: 'warning'
69
+ }));
70
+ });
71
+ (0, _defineProperty2.default)(this, "danger", function (title, settings) {
72
+ if (settings === void 0) {
73
+ settings = {};
74
+ }
75
+
76
+ return _this.notifyHandler(title, _objectSpread(_objectSpread({}, settings), {}, {
77
+ intent: 'danger'
78
+ }));
79
+ });
80
+ if (!isBrowser) return;
81
+ var container = document.createElement('div');
82
+ container.setAttribute('data-evergreen-toaster-container', '');
83
+ document.body.appendChild(container);
84
+
85
+ _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_toastManager.default, {
86
+ bindNotify: this._bindNotify,
87
+ bindGetToasts: this._bindGetToasts,
88
+ bindCloseAll: this._bindCloseAll
89
+ }), container);
90
+ };
91
+
92
+ exports.default = Toaster;