@seafile/sdoc-editor 0.1.18 → 0.1.19
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.
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +1 -1
- package/dist/components/doc-operations/index.js +18 -3
- package/dist/components/tip-message/index.js +32 -0
- package/dist/components/toast/alert.js +130 -0
- package/dist/components/toast/index.js +3 -0
- package/dist/components/toast/toast.js +164 -0
- package/dist/components/toast/toastManager.js +149 -0
- package/dist/components/toast/toaster.js +65 -0
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +4 -1
- package/public/locales/zh-CN/sdoc-editor.json +4 -1
|
@@ -38,7 +38,7 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
38
38
|
};
|
|
39
39
|
_this.onToggleClick = function (event) {
|
|
40
40
|
event.stopPropagation();
|
|
41
|
-
event.nativeEvent.stopImmediatePropagation;
|
|
41
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
42
42
|
var isShowHeaderPopover = !_this.state.isShowHeaderPopover;
|
|
43
43
|
if (isShowHeaderPopover) {
|
|
44
44
|
_this.setState({
|
|
@@ -4,25 +4,40 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
|
4
4
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
5
|
import React, { Fragment } from 'react';
|
|
6
6
|
import CollaboratorsOperation from './collaborators-operation';
|
|
7
|
+
import context from '../../context';
|
|
7
8
|
import './style.css';
|
|
8
9
|
var DocOperations = /*#__PURE__*/function (_React$Component) {
|
|
9
10
|
_inherits(DocOperations, _React$Component);
|
|
10
11
|
var _super = _createSuper(DocOperations);
|
|
11
12
|
function DocOperations() {
|
|
13
|
+
var _this;
|
|
12
14
|
_classCallCheck(this, DocOperations);
|
|
13
|
-
|
|
15
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
16
|
+
args[_key] = arguments[_key];
|
|
17
|
+
}
|
|
18
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
19
|
+
_this.toggleHistory = function (event) {
|
|
20
|
+
event.stopPropagation();
|
|
21
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
22
|
+
var historyURL = context.getSetting('historyURL');
|
|
23
|
+
window.location.href = historyURL;
|
|
24
|
+
};
|
|
25
|
+
return _this;
|
|
14
26
|
}
|
|
15
27
|
_createClass(DocOperations, [{
|
|
16
28
|
key: "render",
|
|
17
29
|
value: function render() {
|
|
30
|
+
var docPerm = context.getSetting('docPerm');
|
|
31
|
+
var historyURL = context.getSetting('historyURL');
|
|
18
32
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
19
33
|
className: "doc-ops"
|
|
20
34
|
}, /*#__PURE__*/React.createElement("span", {
|
|
21
35
|
className: "op-item"
|
|
22
36
|
}, /*#__PURE__*/React.createElement("i", {
|
|
23
37
|
className: "iconfont icon-share"
|
|
24
|
-
})), /*#__PURE__*/React.createElement("span", {
|
|
25
|
-
className: "op-item"
|
|
38
|
+
})), docPerm === 'rw' && historyURL && /*#__PURE__*/React.createElement("span", {
|
|
39
|
+
className: "op-item",
|
|
40
|
+
onClick: this.toggleHistory
|
|
26
41
|
}, /*#__PURE__*/React.createElement("i", {
|
|
27
42
|
className: "iconfont icon-history"
|
|
28
43
|
})), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), /*#__PURE__*/React.createElement("span", {
|
|
@@ -5,6 +5,7 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { withTranslation } from 'react-i18next';
|
|
7
7
|
import { EventBus } from '../../basic-sdk';
|
|
8
|
+
import toaster from '../toast';
|
|
8
9
|
import './style.css';
|
|
9
10
|
var TipMessage = /*#__PURE__*/function (_React$Component) {
|
|
10
11
|
_inherits(TipMessage, _React$Component);
|
|
@@ -13,6 +14,33 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
|
|
|
13
14
|
var _this;
|
|
14
15
|
_classCallCheck(this, TipMessage);
|
|
15
16
|
_this = _super.call(this, props);
|
|
17
|
+
_this.onDisconnect = function () {
|
|
18
|
+
var t = _this.props.t;
|
|
19
|
+
var message = t('Server_is_not_connected_Operation_will_be_sent_to_server_later');
|
|
20
|
+
toaster.warning(message, {
|
|
21
|
+
hasCloseButton: true,
|
|
22
|
+
duration: null
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
_this.onReconnectError = function () {
|
|
26
|
+
if (!_this.isConnectError) {
|
|
27
|
+
_this.isConnectError = true;
|
|
28
|
+
var t = _this.props.t;
|
|
29
|
+
var message = t('Server_is_disconnected_Reconnecting');
|
|
30
|
+
toaster.closeAll();
|
|
31
|
+
toaster.warning(message, {
|
|
32
|
+
hasCloseButton: true,
|
|
33
|
+
duration: null
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
_this.onReconnect = function () {
|
|
38
|
+
_this.isConnectError = false;
|
|
39
|
+
var t = _this.props.t;
|
|
40
|
+
var message = t('Server_is_reconnected');
|
|
41
|
+
toaster.closeAll();
|
|
42
|
+
toaster.success(message); // close after serval seconds
|
|
43
|
+
};
|
|
16
44
|
_this.onDocumentSaving = function () {
|
|
17
45
|
_this.setState({
|
|
18
46
|
isSaving: true,
|
|
@@ -65,6 +93,10 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
|
|
|
65
93
|
var eventBus = EventBus.getInstance();
|
|
66
94
|
this.unsubscribeSavingEvent = eventBus.subscribe('is-saving', this.onDocumentSaving);
|
|
67
95
|
this.unsubscribeSavedEvent = eventBus.subscribe('saved', this.onDocumentSaved);
|
|
96
|
+
// offline reconnect
|
|
97
|
+
this.unsubscribeDisconnectEvent = eventBus.subscribe('disconnect', this.onDisconnect);
|
|
98
|
+
this.unsubscribeReconnectErrorEvent = eventBus.subscribe('reconnect_error', this.onReconnectError);
|
|
99
|
+
this.unsubscribeReconnectEvent = eventBus.subscribe('reconnect', this.onReconnect);
|
|
68
100
|
}
|
|
69
101
|
}, {
|
|
70
102
|
key: "componentWillUnmount",
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { css } from 'glamor';
|
|
7
|
+
var Alert = /*#__PURE__*/function (_React$PureComponent) {
|
|
8
|
+
_inherits(Alert, _React$PureComponent);
|
|
9
|
+
var _super = _createSuper(Alert);
|
|
10
|
+
function Alert(props) {
|
|
11
|
+
var _this;
|
|
12
|
+
_classCallCheck(this, Alert);
|
|
13
|
+
_this = _super.call(this, props);
|
|
14
|
+
_this.containerStyle = css({
|
|
15
|
+
borderRadius: '3px',
|
|
16
|
+
backgroundColor: '#fff',
|
|
17
|
+
padding: '10px 16px',
|
|
18
|
+
display: 'flex',
|
|
19
|
+
boxSizing: 'border-box',
|
|
20
|
+
boxShadow: 'rgba(67, 90, 111, 0.3) 0px 0px 1px, rgba(67, 90, 111, 0.47) 0px 8px 10px -4px',
|
|
21
|
+
justifyContent: 'space-between',
|
|
22
|
+
flexDirection: 'row'
|
|
23
|
+
});
|
|
24
|
+
_this.containerBorderSuccess = css({
|
|
25
|
+
borderLeft: '3px solid rgb(71, 184, 129)'
|
|
26
|
+
});
|
|
27
|
+
_this.containerBorderWarn = css({
|
|
28
|
+
borderLeft: '3px solid rgb(217, 130, 43)'
|
|
29
|
+
});
|
|
30
|
+
_this.containerBorderDanger = css({
|
|
31
|
+
borderLeft: '3px solid rgb(236, 76, 71)'
|
|
32
|
+
});
|
|
33
|
+
_this.containerBorderNotify = css({
|
|
34
|
+
borderLeft: '3px solid rgb(16, 112, 202)'
|
|
35
|
+
});
|
|
36
|
+
_this.toastTextTitle = css({
|
|
37
|
+
fontWeight: '600',
|
|
38
|
+
fontSize: '14px',
|
|
39
|
+
color: '#435a6f',
|
|
40
|
+
margin: '0'
|
|
41
|
+
});
|
|
42
|
+
_this.toastTextChild = css({
|
|
43
|
+
fontSize: '14px',
|
|
44
|
+
color: '#999',
|
|
45
|
+
margin: '0'
|
|
46
|
+
});
|
|
47
|
+
_this.toastClose = css({
|
|
48
|
+
marginLeft: '15px',
|
|
49
|
+
height: '24px',
|
|
50
|
+
width: '24px',
|
|
51
|
+
lineHeight: '22px',
|
|
52
|
+
fontWeight: '700',
|
|
53
|
+
textAlign: 'center',
|
|
54
|
+
fontSize: '20px',
|
|
55
|
+
color: '#000',
|
|
56
|
+
cursor: 'pointer',
|
|
57
|
+
opacity: '0.5',
|
|
58
|
+
':hover': {
|
|
59
|
+
opacity: 1
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
_this.toastIcon = css({
|
|
63
|
+
marginRight: '10px',
|
|
64
|
+
width: '14px',
|
|
65
|
+
height: '20px',
|
|
66
|
+
lineHeight: '20px'
|
|
67
|
+
});
|
|
68
|
+
return _this;
|
|
69
|
+
}
|
|
70
|
+
_createClass(Alert, [{
|
|
71
|
+
key: "getContainerStyle",
|
|
72
|
+
value: function getContainerStyle(intent) {
|
|
73
|
+
switch (intent) {
|
|
74
|
+
case 'success':
|
|
75
|
+
return {
|
|
76
|
+
borderStyle: this.containerBorderSuccess,
|
|
77
|
+
iconColor: css({
|
|
78
|
+
color: 'rgb(71, 184, 129)'
|
|
79
|
+
}),
|
|
80
|
+
iconClass: 'dtable-font dtable-icon-check-circle'
|
|
81
|
+
};
|
|
82
|
+
case 'warning':
|
|
83
|
+
return {
|
|
84
|
+
borderStyle: this.containerBorderWarn,
|
|
85
|
+
iconColor: css({
|
|
86
|
+
color: 'rgb(217, 130, 43)'
|
|
87
|
+
}),
|
|
88
|
+
iconClass: 'dtable-font dtable-icon-exclamation-triangle'
|
|
89
|
+
};
|
|
90
|
+
case 'none':
|
|
91
|
+
return {
|
|
92
|
+
borderStyle: this.containerBorderNotify,
|
|
93
|
+
iconColor: css({
|
|
94
|
+
color: 'rgb(16, 112, 202)'
|
|
95
|
+
}),
|
|
96
|
+
iconClass: 'dtable-font dtable-icon-description'
|
|
97
|
+
};
|
|
98
|
+
case 'danger':
|
|
99
|
+
return {
|
|
100
|
+
borderStyle: this.containerBorderDanger,
|
|
101
|
+
iconColor: css({
|
|
102
|
+
color: 'rgb(236, 76, 71)'
|
|
103
|
+
}),
|
|
104
|
+
iconClass: 'dtable-font dtable-icon-exclamation-circle'
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
key: "render",
|
|
110
|
+
value: function render() {
|
|
111
|
+
var toastStyle = this.getContainerStyle(this.props.intent);
|
|
112
|
+
return /*#__PURE__*/React.createElement("div", css(toastStyle.borderStyle, this.containerStyle), /*#__PURE__*/React.createElement("div", {
|
|
113
|
+
className: this.toastIcon
|
|
114
|
+
}, /*#__PURE__*/React.createElement("i", Object.assign({
|
|
115
|
+
className: toastStyle.iconClass
|
|
116
|
+
}, toastStyle.iconColor))), /*#__PURE__*/React.createElement("div", {
|
|
117
|
+
className: this.toastTextContainer
|
|
118
|
+
}, /*#__PURE__*/React.createElement("p", {
|
|
119
|
+
className: this.toastTextTitle
|
|
120
|
+
}, this.props.title), this.props.children ? /*#__PURE__*/React.createElement("p", {
|
|
121
|
+
className: this.toastTextChild
|
|
122
|
+
}, this.props.children) : null), this.props.isRemoveable && /*#__PURE__*/React.createElement("div", {
|
|
123
|
+
onClick: this.props.onRemove,
|
|
124
|
+
className: this.toastClose
|
|
125
|
+
}, /*#__PURE__*/React.createElement("span", null, "\xD7")));
|
|
126
|
+
}
|
|
127
|
+
}]);
|
|
128
|
+
return Alert;
|
|
129
|
+
}(React.PureComponent);
|
|
130
|
+
export default Alert;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { css } from 'glamor';
|
|
7
|
+
import Transition from 'react-transition-group/Transition';
|
|
8
|
+
import Alert from './alert';
|
|
9
|
+
var animationEasing = {
|
|
10
|
+
deceleration: 'cubic-bezier(0.0, 0.0, 0.2, 1)',
|
|
11
|
+
acceleration: 'cubic-bezier(0.4, 0.0, 1, 1)',
|
|
12
|
+
spring: 'cubic-bezier(0.175, 0.885, 0.320, 1.175)'
|
|
13
|
+
};
|
|
14
|
+
var ANIMATION_DURATION = 240;
|
|
15
|
+
var openAnimation = css.keyframes('openAnimation', {
|
|
16
|
+
from: {
|
|
17
|
+
opacity: 0,
|
|
18
|
+
transform: 'translateY(-120%)'
|
|
19
|
+
},
|
|
20
|
+
to: {
|
|
21
|
+
transform: 'translateY(0)'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var closeAnimation = css.keyframes('closeAnimation', {
|
|
25
|
+
from: {
|
|
26
|
+
transform: 'scale(1)',
|
|
27
|
+
opacity: 1
|
|
28
|
+
},
|
|
29
|
+
to: {
|
|
30
|
+
transform: 'scale(0.9)',
|
|
31
|
+
opacity: 0
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
var animationStyles = css({
|
|
35
|
+
display: 'flex',
|
|
36
|
+
flexDirection: 'column',
|
|
37
|
+
alignItems: 'center',
|
|
38
|
+
height: 0,
|
|
39
|
+
transition: "all ".concat(ANIMATION_DURATION, "ms ").concat(animationEasing.deceleration),
|
|
40
|
+
'&[data-state="entering"], &[data-state="entered"]': {
|
|
41
|
+
animation: "".concat(openAnimation, " ").concat(ANIMATION_DURATION, "ms ").concat(animationEasing.spring, " both")
|
|
42
|
+
},
|
|
43
|
+
'&[data-state="exiting"]': {
|
|
44
|
+
animation: "".concat(closeAnimation, " 120ms ").concat(animationEasing.acceleration, " both")
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
var Toast = /*#__PURE__*/function (_React$PureComponent) {
|
|
48
|
+
_inherits(Toast, _React$PureComponent);
|
|
49
|
+
var _super = _createSuper(Toast);
|
|
50
|
+
function Toast() {
|
|
51
|
+
var _this;
|
|
52
|
+
_classCallCheck(this, Toast);
|
|
53
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
54
|
+
args[_key] = arguments[_key];
|
|
55
|
+
}
|
|
56
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
57
|
+
_this.state = {
|
|
58
|
+
isShown: true,
|
|
59
|
+
height: 0
|
|
60
|
+
};
|
|
61
|
+
_this.close = function (event) {
|
|
62
|
+
if (event) {
|
|
63
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
64
|
+
event.stopPropagation();
|
|
65
|
+
}
|
|
66
|
+
_this.clearCloseTimer();
|
|
67
|
+
_this.setState({
|
|
68
|
+
isShown: false
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
_this.startCloseTimer = function () {
|
|
72
|
+
if (_this.props.duration) {
|
|
73
|
+
_this.closeTimer = setTimeout(function () {
|
|
74
|
+
_this.close();
|
|
75
|
+
}, _this.props.duration * 1000);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
_this.clearCloseTimer = function () {
|
|
79
|
+
if (_this.closeTimer) {
|
|
80
|
+
clearTimeout(_this.closeTimer);
|
|
81
|
+
_this.closeTimer = null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
_this.handleMouseEnter = function () {
|
|
85
|
+
_this.clearCloseTimer();
|
|
86
|
+
};
|
|
87
|
+
_this.handleMouseLeave = function () {
|
|
88
|
+
_this.startCloseTimer();
|
|
89
|
+
};
|
|
90
|
+
_this.onRef = function (ref) {
|
|
91
|
+
if (ref === null) return;
|
|
92
|
+
var _ref$getBoundingClien = ref.getBoundingClientRect(),
|
|
93
|
+
height = _ref$getBoundingClien.height;
|
|
94
|
+
_this.setState({
|
|
95
|
+
height: height
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
return _this;
|
|
99
|
+
}
|
|
100
|
+
_createClass(Toast, [{
|
|
101
|
+
key: "componentDidUpdate",
|
|
102
|
+
value: function componentDidUpdate(prevProps) {
|
|
103
|
+
if (prevProps.isShown !== this.props.isShown) {
|
|
104
|
+
// eslint-disable-next-line react/no-did-update-set-state
|
|
105
|
+
this.setState({
|
|
106
|
+
isShown: this.props.isShown
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "componentDidMount",
|
|
112
|
+
value: function componentDidMount() {
|
|
113
|
+
this.startCloseTimer();
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "componentWillUnmount",
|
|
117
|
+
value: function componentWillUnmount() {
|
|
118
|
+
this.clearCloseTimer();
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "render",
|
|
122
|
+
value: function render() {
|
|
123
|
+
var _this2 = this;
|
|
124
|
+
return /*#__PURE__*/React.createElement(Transition, {
|
|
125
|
+
appear: true,
|
|
126
|
+
unmountOnExit: true,
|
|
127
|
+
timeout: ANIMATION_DURATION,
|
|
128
|
+
in: this.state.isShown,
|
|
129
|
+
onExited: this.props.onRemove
|
|
130
|
+
}, function (state) {
|
|
131
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
132
|
+
"data-state": state,
|
|
133
|
+
className: animationStyles,
|
|
134
|
+
onMouseEnter: _this2.handleMouseEnter,
|
|
135
|
+
onMouseLeave: _this2.handleMouseLeave,
|
|
136
|
+
style: {
|
|
137
|
+
height: _this2.state.height,
|
|
138
|
+
zIndex: _this2.props.zIndex,
|
|
139
|
+
marginBottom: _this2.state.isShown ? 0 : -_this2.state.height
|
|
140
|
+
}
|
|
141
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
142
|
+
ref: _this2.onRef,
|
|
143
|
+
style: {
|
|
144
|
+
padding: 8
|
|
145
|
+
}
|
|
146
|
+
}, /*#__PURE__*/React.createElement(Alert, {
|
|
147
|
+
intent: _this2.props.intent,
|
|
148
|
+
title: _this2.props.title,
|
|
149
|
+
"aria-label": _this2.props.title,
|
|
150
|
+
children: _this2.props.children || '',
|
|
151
|
+
isRemoveable: _this2.props.hasCloseButton,
|
|
152
|
+
onRemove: function onRemove(event) {
|
|
153
|
+
return _this2.close(event);
|
|
154
|
+
}
|
|
155
|
+
})));
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}]);
|
|
159
|
+
return Toast;
|
|
160
|
+
}(React.PureComponent);
|
|
161
|
+
Toast.defaultProps = {
|
|
162
|
+
intent: 'none'
|
|
163
|
+
};
|
|
164
|
+
export { Toast as default };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
5
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
6
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
7
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
8
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
9
|
+
var _excluded = ["id", "description"];
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { css } from 'glamor';
|
|
12
|
+
import Toast from './toast';
|
|
13
|
+
var wrapperClass = css({
|
|
14
|
+
maxWidth: 560,
|
|
15
|
+
margin: '0 auto',
|
|
16
|
+
top: 0,
|
|
17
|
+
left: 0,
|
|
18
|
+
right: 0,
|
|
19
|
+
position: 'fixed',
|
|
20
|
+
zIndex: 30
|
|
21
|
+
});
|
|
22
|
+
var hasCustomId = function hasCustomId(settings) {
|
|
23
|
+
return Object.hasOwnProperty.call(settings, 'id');
|
|
24
|
+
};
|
|
25
|
+
var ToastManager = /*#__PURE__*/function (_React$PureComponent) {
|
|
26
|
+
_inherits(ToastManager, _React$PureComponent);
|
|
27
|
+
var _super = _createSuper(ToastManager);
|
|
28
|
+
function ToastManager(props, context) {
|
|
29
|
+
var _this;
|
|
30
|
+
_classCallCheck(this, ToastManager);
|
|
31
|
+
_this = _super.call(this, props, context);
|
|
32
|
+
_this.getToasts = function () {
|
|
33
|
+
return _this.state.toasts;
|
|
34
|
+
};
|
|
35
|
+
_this.closeAll = function () {
|
|
36
|
+
_this.getToasts().forEach(function (toast) {
|
|
37
|
+
return toast.close();
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
_this.notify = function (title, settings) {
|
|
41
|
+
// If there's a custom toast ID passed, close existing toasts with the same custom ID
|
|
42
|
+
if (hasCustomId(settings)) {
|
|
43
|
+
var _iterator = _createForOfIteratorHelper(_this.state.toasts),
|
|
44
|
+
_step;
|
|
45
|
+
try {
|
|
46
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
47
|
+
var toast = _step.value;
|
|
48
|
+
// Since unique ID is still appended to a custom ID, skip the unique ID and check only prefix
|
|
49
|
+
if (String(toast.id).startsWith(settings.id)) {
|
|
50
|
+
_this.closeToast(toast.id);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_iterator.e(err);
|
|
55
|
+
} finally {
|
|
56
|
+
_iterator.f();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var instance = _this.createToastInstance(title, settings);
|
|
60
|
+
_this.onClose = settings.onClose;
|
|
61
|
+
_this.setState(function (previousState) {
|
|
62
|
+
return {
|
|
63
|
+
toasts: [instance].concat(_toConsumableArray(previousState.toasts))
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
return instance;
|
|
67
|
+
};
|
|
68
|
+
_this.createToastInstance = function (title, settings) {
|
|
69
|
+
var uniqueId = ++ToastManager.idCounter;
|
|
70
|
+
var id = hasCustomId(settings) ? "".concat(settings.id, "-").concat(uniqueId) : uniqueId;
|
|
71
|
+
var hasCloseButton = settings.hasCloseButton || true;
|
|
72
|
+
var duration = settings.duration || 2;
|
|
73
|
+
if (settings.hasCloseButton !== undefined) {
|
|
74
|
+
hasCloseButton = settings.hasCloseButton;
|
|
75
|
+
}
|
|
76
|
+
if (settings.duration !== undefined) {
|
|
77
|
+
duration = settings.duration;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
id: id,
|
|
81
|
+
title: title,
|
|
82
|
+
description: settings.description,
|
|
83
|
+
hasCloseButton: hasCloseButton,
|
|
84
|
+
duration: duration,
|
|
85
|
+
close: function close() {
|
|
86
|
+
return _this.closeToast(id);
|
|
87
|
+
},
|
|
88
|
+
intent: settings.intent
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* This will set isShown on the Toast which will close the toast.
|
|
93
|
+
* It won't remove the toast until onExited triggers onRemove.
|
|
94
|
+
*/
|
|
95
|
+
_this.closeToast = function (id) {
|
|
96
|
+
_this.setState(function (previousState) {
|
|
97
|
+
return {
|
|
98
|
+
toasts: previousState.toasts.map(function (toast) {
|
|
99
|
+
if (toast.id === id) {
|
|
100
|
+
return _objectSpread(_objectSpread({}, toast), {}, {
|
|
101
|
+
isShown: false
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return toast;
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
_this.removeToast = function (id) {
|
|
110
|
+
_this.onClose && _this.onClose();
|
|
111
|
+
_this.setState(function (previousState) {
|
|
112
|
+
return {
|
|
113
|
+
toasts: previousState.toasts.filter(function (toast) {
|
|
114
|
+
return toast.id !== id;
|
|
115
|
+
})
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
props.bindNotify(_this.notify);
|
|
120
|
+
props.bindGetToasts(_this.getToasts);
|
|
121
|
+
props.bindCloseAll(_this.closeAll);
|
|
122
|
+
_this.state = {
|
|
123
|
+
toasts: []
|
|
124
|
+
};
|
|
125
|
+
return _this;
|
|
126
|
+
}
|
|
127
|
+
_createClass(ToastManager, [{
|
|
128
|
+
key: "render",
|
|
129
|
+
value: function render() {
|
|
130
|
+
var _this2 = this;
|
|
131
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
132
|
+
className: wrapperClass
|
|
133
|
+
}, this.state.toasts.map(function (_ref) {
|
|
134
|
+
var id = _ref.id,
|
|
135
|
+
description = _ref.description,
|
|
136
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
137
|
+
return /*#__PURE__*/React.createElement(Toast, Object.assign({
|
|
138
|
+
key: id,
|
|
139
|
+
onRemove: function onRemove() {
|
|
140
|
+
return _this2.removeToast(id);
|
|
141
|
+
}
|
|
142
|
+
}, props), description);
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
}]);
|
|
146
|
+
return ToastManager;
|
|
147
|
+
}(React.PureComponent);
|
|
148
|
+
ToastManager.idCounter = 0;
|
|
149
|
+
export { ToastManager as default };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import ReactDOM from 'react-dom';
|
|
6
|
+
import ToastManager from './toastManager';
|
|
7
|
+
var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Toaster manages the interactionsb between
|
|
11
|
+
* the ToasterManger and the toast API.
|
|
12
|
+
*/
|
|
13
|
+
var Toaster = /*#__PURE__*/_createClass(function Toaster() {
|
|
14
|
+
var _this = this;
|
|
15
|
+
_classCallCheck(this, Toaster);
|
|
16
|
+
this._bindNotify = function (handler) {
|
|
17
|
+
_this.notifyHandler = handler;
|
|
18
|
+
};
|
|
19
|
+
this._bindGetToasts = function (handler) {
|
|
20
|
+
_this.getToastsHandler = handler;
|
|
21
|
+
};
|
|
22
|
+
this._bindCloseAll = function (handler) {
|
|
23
|
+
_this.closeAllHandler = handler;
|
|
24
|
+
};
|
|
25
|
+
this.getToasts = function () {
|
|
26
|
+
return _this.getToastsHandler();
|
|
27
|
+
};
|
|
28
|
+
this.closeAll = function () {
|
|
29
|
+
return _this.closeAllHandler();
|
|
30
|
+
};
|
|
31
|
+
this.notify = function (title) {
|
|
32
|
+
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33
|
+
return _this.notifyHandler(title, _objectSpread(_objectSpread({}, settings), {}, {
|
|
34
|
+
intent: 'none'
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
this.success = function (title) {
|
|
38
|
+
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
39
|
+
return _this.notifyHandler(title, _objectSpread(_objectSpread({}, settings), {}, {
|
|
40
|
+
intent: 'success'
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
43
|
+
this.warning = function (title) {
|
|
44
|
+
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
45
|
+
return _this.notifyHandler(title, _objectSpread(_objectSpread({}, settings), {}, {
|
|
46
|
+
intent: 'warning'
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
this.danger = function (title) {
|
|
50
|
+
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
51
|
+
return _this.notifyHandler(title, _objectSpread(_objectSpread({}, settings), {}, {
|
|
52
|
+
intent: 'danger'
|
|
53
|
+
}));
|
|
54
|
+
};
|
|
55
|
+
if (!isBrowser) return;
|
|
56
|
+
var container = document.createElement('div');
|
|
57
|
+
container.setAttribute('data-evergreen-toaster-container', '');
|
|
58
|
+
document.body.appendChild(container);
|
|
59
|
+
ReactDOM.render( /*#__PURE__*/React.createElement(ToastManager, {
|
|
60
|
+
bindNotify: this._bindNotify,
|
|
61
|
+
bindGetToasts: this._bindGetToasts,
|
|
62
|
+
bindCloseAll: this._bindCloseAll
|
|
63
|
+
}), container);
|
|
64
|
+
});
|
|
65
|
+
export { Toaster as default };
|
package/package.json
CHANGED
|
@@ -230,5 +230,8 @@
|
|
|
230
230
|
"Saving": "Saving...",
|
|
231
231
|
"Collaborators": "Collaborators",
|
|
232
232
|
"Online_members": "Online members",
|
|
233
|
-
"me": "me"
|
|
233
|
+
"me": "me",
|
|
234
|
+
"Server_is_not_connected_Operation_will_be_sent_to_server_later": "Server is not connected. Operation will be sent to server later.",
|
|
235
|
+
"Server_is_disconnected_Reconnecting": "Server is disconnected. Reconnecting...",
|
|
236
|
+
"Server_is_reconnected": "Server is reconnected."
|
|
234
237
|
}
|
|
@@ -225,5 +225,8 @@
|
|
|
225
225
|
"All_changes_saved": "所有更改均已保存",
|
|
226
226
|
"Saving": "保存中...",
|
|
227
227
|
"Online_members": "在线成员",
|
|
228
|
-
"me": "我"
|
|
228
|
+
"me": "我",
|
|
229
|
+
"Server_is_not_connected_Operation_will_be_sent_to_server_later": "服务器未连接。 操作稍后将发送到服务器。",
|
|
230
|
+
"Server_is_disconnected_Reconnecting": "服务器断开连接。正在重新连接...",
|
|
231
|
+
"Server_is_reconnected": "服务器已重新连接。"
|
|
229
232
|
}
|