@seafile/comment-editor 0.0.1-alpha.0 → 0.0.1-alpha.10
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/README.md +2 -4
- package/dist/basic-sdk/assets/css/layout.css +1 -45
- package/dist/basic-sdk/assets/css/sdoc-comment-editor-plugin.css +4 -4
- package/dist/basic-sdk/comment/utils.js +39 -0
- package/dist/basic-sdk/constants/index.js +1 -2
- package/dist/basic-sdk/context.js +9 -8
- package/dist/basic-sdk/editor/comment-editor.css +138 -0
- package/dist/basic-sdk/editor/comment-editor.js +289 -0
- package/dist/basic-sdk/extension/plugins/image/helpers.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/use-copy-image.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +2 -1
- package/dist/basic-sdk/extension/plugins/link/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/mention/render-elem/participant-popover.js +3 -6
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +1 -2
- package/dist/basic-sdk/extension/render/render-comment-editor-element.js +1 -1
- package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/index.js +3 -3
- package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/post-comment/index.js +2 -2
- package/dist/basic-sdk/hooks/use-comment.js +53 -0
- package/dist/basic-sdk/index.js +12 -39
- package/dist/pages/seafile-comment-editor.js +30 -54
- package/package.json +2 -1
- package/dist/assets/css/plugin-editor.css +0 -7
- package/dist/assets/css/simple-viewer.css +0 -6
- package/dist/basic-sdk/comment/components/comment-all-participants/index.css +0 -83
- package/dist/basic-sdk/comment/components/comment-all-participants/index.js +0 -67
- package/dist/basic-sdk/comment/components/comment-all-participants/participant-avatar.js +0 -43
- package/dist/basic-sdk/comment/components/comment-context-menu/index.css +0 -16
- package/dist/basic-sdk/comment/components/comment-context-menu/index.js +0 -43
- package/dist/basic-sdk/comment/components/comment-context-menu/menu-item.js +0 -57
- package/dist/basic-sdk/comment/components/comment-delete-popover.js +0 -80
- package/dist/basic-sdk/comment/components/comment-editor.js +0 -165
- package/dist/basic-sdk/comment/components/comment-item-collapse-wrapper.js +0 -160
- package/dist/basic-sdk/comment/components/comment-item-content.js +0 -156
- package/dist/basic-sdk/comment/components/comment-item-reply.js +0 -124
- package/dist/basic-sdk/comment/components/comment-item-resolved-reply.js +0 -38
- package/dist/basic-sdk/comment/components/comment-item-wrapper.js +0 -368
- package/dist/basic-sdk/comment/components/comment-list.css +0 -422
- package/dist/basic-sdk/comment/components/comment-list.js +0 -216
- package/dist/basic-sdk/comment/components/comment-operation/index.css +0 -26
- package/dist/basic-sdk/comment/components/comment-operation/index.js +0 -31
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.css +0 -132
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.js +0 -69
- package/dist/basic-sdk/comment/components/comment-participants-editor/searched-collaborators.js +0 -62
- package/dist/basic-sdk/comment/components/comment-participants-editor/selected-participants.js +0 -48
- package/dist/basic-sdk/comment/components/editor-comment.js +0 -183
- package/dist/basic-sdk/comment/components/elements-comment-count/element-comment-count.js +0 -64
- package/dist/basic-sdk/comment/components/elements-comment-count/index.css +0 -29
- package/dist/basic-sdk/comment/components/elements-comment-count/index.js +0 -49
- package/dist/basic-sdk/comment/components/global-comment/global-comment-body-header.js +0 -87
- package/dist/basic-sdk/comment/components/global-comment/global-comment-editor.js +0 -36
- package/dist/basic-sdk/comment/components/global-comment/global-comment-header.js +0 -82
- package/dist/basic-sdk/comment/components/global-comment/index.css +0 -326
- package/dist/basic-sdk/comment/components/global-comment/index.js +0 -212
- package/dist/basic-sdk/comment/components/index.js +0 -21
- package/dist/basic-sdk/comment/components/style.css +0 -40
- package/dist/basic-sdk/comment/helper.js +0 -184
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-context.js +0 -20
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-list.js +0 -45
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-mount.js +0 -58
- package/dist/basic-sdk/comment/hooks/notification-hooks/index.js +0 -25
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-context.js +0 -20
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-mount.js +0 -74
- package/dist/basic-sdk/comment/hooks/use-participants.js +0 -26
- package/dist/basic-sdk/comment/index.js +0 -67
- package/dist/basic-sdk/comment/provider/comment-context-provider.js +0 -37
- package/dist/basic-sdk/comment/provider/index.js +0 -23
- package/dist/basic-sdk/comment/provider/notification-context-provider.js +0 -31
- package/dist/basic-sdk/comment/provider/participants-content-provider.js +0 -96
- package/dist/basic-sdk/comment/reducer/comment-reducer.js +0 -353
- package/dist/basic-sdk/comment/reducer/notification-reducer.js +0 -89
- package/dist/basic-sdk/comment/utils/get-event-transfer.js +0 -77
- package/dist/basic-sdk/comment/utils/index.js +0 -281
- package/dist/basic-sdk/comment/utils/notification-utils.js +0 -62
- package/dist/basic-sdk/editor/comment-article.js +0 -104
- package/dist/basic-sdk/editor/sdoc-comment-editor.js +0 -128
- package/dist/basic-sdk/editor/sdoc-editor.js +0 -50
- package/dist/basic-sdk/hooks/use-collaborators.js +0 -62
- package/dist/basic-sdk/hooks/use-plugins.js +0 -9
- package/dist/basic-sdk/layout/article-container.js +0 -89
- package/dist/basic-sdk/layout/editor-container.js +0 -32
- package/dist/basic-sdk/layout/index.js +0 -20
- package/dist/basic-sdk/right-panel/index.css +0 -15
- package/dist/basic-sdk/right-panel/index.js +0 -86
- package/dist/basic-sdk/right-panel/resize-width/index.css +0 -38
- package/dist/basic-sdk/right-panel/resize-width/index.js +0 -132
- package/dist/basic-sdk/socket/helpers.js +0 -299
- package/dist/basic-sdk/socket/index.js +0 -20
- package/dist/basic-sdk/socket/socket-client.js +0 -211
- package/dist/basic-sdk/socket/socket-manager.js +0 -386
- package/dist/basic-sdk/socket/with-socket-io.js +0 -73
- package/dist/hooks/index.js +0 -12
- package/dist/hooks/use-document.js +0 -75
- /package/dist/basic-sdk/comment/{constants/index.js → constants.js} +0 -0
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useNotificationsMount = void 0;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _reactI18next = require("react-i18next");
|
|
10
|
-
var _constants = require("../../../constants");
|
|
11
|
-
var _context = _interopRequireDefault(require("../../../context"));
|
|
12
|
-
var _useCollaborators = require("../../../hooks/use-collaborators");
|
|
13
|
-
var _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
|
|
14
|
-
var _constants2 = require("../../constants");
|
|
15
|
-
var _utils = require("../../utils");
|
|
16
|
-
const useNotificationsMount = dispatch => {
|
|
17
|
-
const {
|
|
18
|
-
t
|
|
19
|
-
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
20
|
-
const {
|
|
21
|
-
collaborators
|
|
22
|
-
} = (0, _useCollaborators.useCollaborators)();
|
|
23
|
-
const popupBrowserCommentNotification = (0, _react.useCallback)(notification => {
|
|
24
|
-
if (!notification) return;
|
|
25
|
-
const {
|
|
26
|
-
author,
|
|
27
|
-
msg_type: msgType,
|
|
28
|
-
reply,
|
|
29
|
-
comment
|
|
30
|
-
} = notification;
|
|
31
|
-
const authorInfo = collaborators.find(collaborator => collaborator.email === author);
|
|
32
|
-
const notificationContent = comment || reply;
|
|
33
|
-
const titleKey = msgType === 'comment' ? 'xxx_added_a_new_comment' : 'xxx_added_a_reply';
|
|
34
|
-
const title = t(titleKey, {
|
|
35
|
-
author: authorInfo ? authorInfo.name : t('Unknown')
|
|
36
|
-
});
|
|
37
|
-
const options = {
|
|
38
|
-
body: `${notificationContent}`
|
|
39
|
-
};
|
|
40
|
-
(0, _utils.createNotify)(title, options);
|
|
41
|
-
}, [collaborators, t]);
|
|
42
|
-
const request = (0, _react.useCallback)(async notification => {
|
|
43
|
-
popupBrowserCommentNotification(notification);
|
|
44
|
-
const eventBus = _eventBus.default.getInstance();
|
|
45
|
-
dispatch({
|
|
46
|
-
type: _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCHING
|
|
47
|
-
});
|
|
48
|
-
try {
|
|
49
|
-
const res = await _context.default.listUnseenNotifications();
|
|
50
|
-
const notifications = res.data.notifications;
|
|
51
|
-
dispatch({
|
|
52
|
-
type: _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCHED,
|
|
53
|
-
payload: notifications
|
|
54
|
-
});
|
|
55
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.UNSEEN_NOTIFICATIONS_COUNT, notifications === null || notifications === void 0 ? void 0 : notifications.length);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.log(error);
|
|
58
|
-
dispatch({
|
|
59
|
-
type: _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCH_ERROR
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
-
}, [popupBrowserCommentNotification]);
|
|
64
|
-
(0, _react.useEffect)(() => {
|
|
65
|
-
request();
|
|
66
|
-
const eventBus = _eventBus.default.getInstance();
|
|
67
|
-
const unsubscribeNewNotification = eventBus.subscribe(_constants.INTERNAL_EVENT.NEW_NOTIFICATION, request);
|
|
68
|
-
return () => {
|
|
69
|
-
unsubscribeNewNotification();
|
|
70
|
-
};
|
|
71
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
72
|
-
}, []);
|
|
73
|
-
};
|
|
74
|
-
exports.useNotificationsMount = useNotificationsMount;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useParticipantsContext = exports.ParticipantsContext = void 0;
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
const ParticipantsContext = exports.ParticipantsContext = /*#__PURE__*/_react.default.createContext(null);
|
|
10
|
-
const useParticipantsContext = () => {
|
|
11
|
-
const context = (0, _react.useContext)(ParticipantsContext);
|
|
12
|
-
if (!context) {
|
|
13
|
-
throw new Error('\'ParticipantsContext\' is null');
|
|
14
|
-
}
|
|
15
|
-
const {
|
|
16
|
-
participants,
|
|
17
|
-
addParticipants,
|
|
18
|
-
deleteParticipant
|
|
19
|
-
} = context;
|
|
20
|
-
return {
|
|
21
|
-
participants,
|
|
22
|
-
addParticipants,
|
|
23
|
-
deleteParticipant
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
exports.useParticipantsContext = useParticipantsContext;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _context = _interopRequireDefault(require("../context"));
|
|
11
|
-
var _components = require("./components");
|
|
12
|
-
var _constants = require("./constants");
|
|
13
|
-
var _useCommentContext = require("./hooks/comment-hooks/use-comment-context");
|
|
14
|
-
var _notificationHooks = require("./hooks/notification-hooks");
|
|
15
|
-
var _utils = require("./utils");
|
|
16
|
-
const CommentWrapper = _ref => {
|
|
17
|
-
let {
|
|
18
|
-
type,
|
|
19
|
-
editor
|
|
20
|
-
} = _ref;
|
|
21
|
-
const {
|
|
22
|
-
commentsInfo
|
|
23
|
-
} = (0, _useCommentContext.useCommentContext)();
|
|
24
|
-
console.log(commentsInfo);
|
|
25
|
-
const {
|
|
26
|
-
notificationsInfo,
|
|
27
|
-
dispatch: notificationDispatch
|
|
28
|
-
} = (0, _notificationHooks.useNotificationContext)();
|
|
29
|
-
const deleteUnseenNotifications = (0, _react.useCallback)(comment => {
|
|
30
|
-
let unseenCommentIds = [];
|
|
31
|
-
let unseenNotificationKeys = [];
|
|
32
|
-
const commentNotificationKey = (0, _utils.generatorNotificationKey)(comment.id);
|
|
33
|
-
const commentNotification = notificationsInfo.notifications_map[commentNotificationKey];
|
|
34
|
-
if (commentNotification) {
|
|
35
|
-
unseenNotificationKeys.push(commentNotification.key);
|
|
36
|
-
unseenCommentIds.push(commentNotification.id);
|
|
37
|
-
}
|
|
38
|
-
Array.isArray(comment.replies) && comment.replies.forEach(reply => {
|
|
39
|
-
const replyNotificationKey = (0, _utils.generatorNotificationKey)(reply.comment_id, reply.id);
|
|
40
|
-
const replyNotification = notificationsInfo.notifications_map[replyNotificationKey];
|
|
41
|
-
if (replyNotification) {
|
|
42
|
-
unseenNotificationKeys.push(replyNotification.key);
|
|
43
|
-
unseenCommentIds.push(replyNotification.id);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
_context.default.deleteUnseenNotifications(unseenCommentIds).then(res => {
|
|
47
|
-
notificationDispatch({
|
|
48
|
-
type: _constants.DOC_NOTIFICATION_REDUCER_TYPE.DEL,
|
|
49
|
-
payload: unseenNotificationKeys
|
|
50
|
-
});
|
|
51
|
-
}).catch(error => {
|
|
52
|
-
//
|
|
53
|
-
});
|
|
54
|
-
}, [notificationDispatch, notificationsInfo.notifications_map]);
|
|
55
|
-
const {
|
|
56
|
-
isFreezed
|
|
57
|
-
} = _context.default.getSettings('isFreezed');
|
|
58
|
-
if (commentsInfo.isFetching) return null;
|
|
59
|
-
console.log(type);
|
|
60
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, type === 'editor' && !isFreezed && /*#__PURE__*/_react.default.createElement(_components.EditorComment, {
|
|
61
|
-
editor: editor
|
|
62
|
-
}), type === 'global' && /*#__PURE__*/_react.default.createElement(_components.GlobalComment, {
|
|
63
|
-
deleteUnseenNotifications: deleteUnseenNotifications,
|
|
64
|
-
editor: editor
|
|
65
|
-
}));
|
|
66
|
-
};
|
|
67
|
-
var _default = exports.default = CommentWrapper;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _constants = require("../../constants");
|
|
11
|
-
var _eventBus = _interopRequireDefault(require("../../utils/event-bus"));
|
|
12
|
-
var _useCommentContext = require("../hooks/comment-hooks/use-comment-context");
|
|
13
|
-
var _useCommentMount = require("../hooks/comment-hooks/use-comment-mount");
|
|
14
|
-
var _commentReducer = require("../reducer/comment-reducer");
|
|
15
|
-
const CommentContextProvider = _ref => {
|
|
16
|
-
let {
|
|
17
|
-
children,
|
|
18
|
-
editor
|
|
19
|
-
} = _ref;
|
|
20
|
-
const [commentsInfo, dispatch] = (0, _react.useReducer)(_commentReducer.commentReducer, _commentReducer.initCommentsInfo);
|
|
21
|
-
(0, _useCommentMount.useCommentsMount)(dispatch);
|
|
22
|
-
(0, _react.useEffect)(() => {
|
|
23
|
-
if (Object.keys(commentsInfo.element_comments_map).length) {
|
|
24
|
-
editor.element_comments_map = commentsInfo.element_comments_map;
|
|
25
|
-
const eventBus = _eventBus.default.getInstance();
|
|
26
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.RELOAD_COMMENT);
|
|
27
|
-
}
|
|
28
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
-
}, [commentsInfo.element_comments_map]);
|
|
30
|
-
return /*#__PURE__*/_react.default.createElement(_useCommentContext.CommentContext.Provider, {
|
|
31
|
-
value: {
|
|
32
|
-
commentsInfo,
|
|
33
|
-
dispatch
|
|
34
|
-
}
|
|
35
|
-
}, children);
|
|
36
|
-
};
|
|
37
|
-
var _default = exports.default = CommentContextProvider;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _commentContextProvider = _interopRequireDefault(require("./comment-context-provider"));
|
|
10
|
-
var _notificationContextProvider = _interopRequireDefault(require("./notification-context-provider"));
|
|
11
|
-
var _participantsContentProvider = _interopRequireDefault(require("./participants-content-provider"));
|
|
12
|
-
const Provider = _ref => {
|
|
13
|
-
let {
|
|
14
|
-
children,
|
|
15
|
-
editor
|
|
16
|
-
} = _ref;
|
|
17
|
-
return /*#__PURE__*/_react.default.createElement(_notificationContextProvider.default, {
|
|
18
|
-
editor: editor
|
|
19
|
-
}, /*#__PURE__*/_react.default.createElement(_commentContextProvider.default, {
|
|
20
|
-
editor: editor
|
|
21
|
-
}, /*#__PURE__*/_react.default.createElement(_participantsContentProvider.default, null, children)));
|
|
22
|
-
};
|
|
23
|
-
var _default = exports.default = Provider;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var _notificationHooks = require("../hooks/notification-hooks");
|
|
10
|
-
var _notificationReducer = require("../reducer/notification-reducer");
|
|
11
|
-
const NotificationContextProvider = _ref => {
|
|
12
|
-
let {
|
|
13
|
-
children,
|
|
14
|
-
editor
|
|
15
|
-
} = _ref;
|
|
16
|
-
const [notificationsInfo, dispatch] = (0, _react.useReducer)(_notificationReducer.notificationReducer, _notificationReducer.initNotificationsInfo);
|
|
17
|
-
(0, _notificationHooks.useNotificationsMount)(dispatch);
|
|
18
|
-
(0, _react.useEffect)(() => {
|
|
19
|
-
editor.notifications_map = {
|
|
20
|
-
...notificationsInfo.notifications_map
|
|
21
|
-
};
|
|
22
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
23
|
-
}, [notificationsInfo]);
|
|
24
|
-
return /*#__PURE__*/_react.default.createElement(_notificationHooks.NotificationContext.Provider, {
|
|
25
|
-
value: {
|
|
26
|
-
notificationsInfo,
|
|
27
|
-
dispatch
|
|
28
|
-
}
|
|
29
|
-
}, children);
|
|
30
|
-
};
|
|
31
|
-
var _default = exports.default = NotificationContextProvider;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _reactI18next = require("react-i18next");
|
|
11
|
-
var _toast = _interopRequireDefault(require("../../components/toast"));
|
|
12
|
-
var _constants = require("../../constants");
|
|
13
|
-
var _context = _interopRequireDefault(require("../../context"));
|
|
14
|
-
var _model = require("../../model");
|
|
15
|
-
var _commonUtils = require("../../utils/common-utils");
|
|
16
|
-
var _eventBus = _interopRequireDefault(require("../../utils/event-bus"));
|
|
17
|
-
var _useParticipants = require("../hooks/use-participants");
|
|
18
|
-
const ParticipantsProvider = _ref => {
|
|
19
|
-
let {
|
|
20
|
-
children
|
|
21
|
-
} = _ref;
|
|
22
|
-
const isSdocRevision = _context.default.getSetting('isSdocRevision');
|
|
23
|
-
const isPublished = _context.default.getSetting('isPublished');
|
|
24
|
-
const [participants, setParticipants] = (0, _react.useState)([]);
|
|
25
|
-
const {
|
|
26
|
-
t
|
|
27
|
-
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
28
|
-
const updateLocalParticipants = (0, _react.useCallback)(function () {
|
|
29
|
-
let added = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
30
|
-
if (!Array.isArray(added) || added.length === 0) return;
|
|
31
|
-
let newParticipants = participants.slice(0);
|
|
32
|
-
added.forEach(participant => {
|
|
33
|
-
const newParticipant = new _model.User(participant);
|
|
34
|
-
if (!newParticipants.find(item => item.username === newParticipant.username)) {
|
|
35
|
-
newParticipants.push(newParticipant);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
setParticipants(newParticipants);
|
|
39
|
-
}, [participants]);
|
|
40
|
-
const addParticipants = (0, _react.useCallback)(otherEmail => {
|
|
41
|
-
if (participants.find(participant => participant.username === otherEmail)) return;
|
|
42
|
-
_context.default.addParticipants([otherEmail]).then(res => {
|
|
43
|
-
const {
|
|
44
|
-
success
|
|
45
|
-
} = res.data;
|
|
46
|
-
updateLocalParticipants(success);
|
|
47
|
-
}).catch(error => {
|
|
48
|
-
const errorMessage = (0, _commonUtils.getErrorMsg)(error);
|
|
49
|
-
_toast.default.danger(t(errorMessage));
|
|
50
|
-
});
|
|
51
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
-
}, [updateLocalParticipants, participants]);
|
|
53
|
-
const deleteLocalParticipant = (0, _react.useCallback)(email => {
|
|
54
|
-
if (!participants.find(participant => participant.username === email)) return;
|
|
55
|
-
let newParticipants = participants.slice(0);
|
|
56
|
-
newParticipants = newParticipants.filter(participant => participant.username !== email);
|
|
57
|
-
setParticipants(newParticipants);
|
|
58
|
-
}, [participants]);
|
|
59
|
-
const deleteParticipant = (0, _react.useCallback)(email => {
|
|
60
|
-
if (!participants.find(participant => participant.username === email)) return;
|
|
61
|
-
_context.default.deleteParticipants(email).then(res => {
|
|
62
|
-
let newParticipants = participants.slice(0);
|
|
63
|
-
newParticipants = newParticipants.filter(participant => participant.username !== email);
|
|
64
|
-
setParticipants(newParticipants);
|
|
65
|
-
}).catch(error => {
|
|
66
|
-
const errorMessage = (0, _commonUtils.getErrorMsg)(error);
|
|
67
|
-
_toast.default.danger(t(errorMessage));
|
|
68
|
-
});
|
|
69
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
|
-
}, [participants]);
|
|
71
|
-
(0, _react.useEffect)(() => {
|
|
72
|
-
if (isSdocRevision && isPublished) return;
|
|
73
|
-
_context.default.listParticipants().then(res => {
|
|
74
|
-
const participants = res.data.participant_list;
|
|
75
|
-
updateLocalParticipants(participants);
|
|
76
|
-
}).catch(error => {});
|
|
77
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
-
}, []);
|
|
79
|
-
(0, _react.useEffect)(() => {
|
|
80
|
-
const eventBus = _eventBus.default.getInstance();
|
|
81
|
-
const unsubscribeParticipantAdded = eventBus.subscribe(_constants.INTERNAL_EVENT.PARTICIPANT_ADDED, updateLocalParticipants);
|
|
82
|
-
const unsubscribeParticipantRemoved = eventBus.subscribe(_constants.INTERNAL_EVENT.PARTICIPANT_REMOVED, deleteLocalParticipant);
|
|
83
|
-
return () => {
|
|
84
|
-
unsubscribeParticipantAdded();
|
|
85
|
-
unsubscribeParticipantRemoved();
|
|
86
|
-
};
|
|
87
|
-
}, [updateLocalParticipants, deleteLocalParticipant]);
|
|
88
|
-
return /*#__PURE__*/_react.default.createElement(_useParticipants.ParticipantsContext.Provider, {
|
|
89
|
-
value: {
|
|
90
|
-
participants,
|
|
91
|
-
addParticipants,
|
|
92
|
-
deleteParticipant
|
|
93
|
-
}
|
|
94
|
-
}, children);
|
|
95
|
-
};
|
|
96
|
-
var _default = exports.default = ParticipantsProvider;
|