@seafile/comment-editor 0.0.1-alpha.3 → 0.0.1-alpha.31

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 (67) hide show
  1. package/dist/basic-sdk/assets/css/layout.css +1 -45
  2. package/dist/basic-sdk/comment/utils.js +39 -0
  3. package/dist/basic-sdk/context.js +8 -14
  4. package/dist/basic-sdk/editor/comment-editor.css +138 -0
  5. package/dist/basic-sdk/{comment/components → editor}/comment-editor.js +41 -43
  6. package/dist/basic-sdk/extension/plugins/image/helpers.js +1 -1
  7. package/dist/basic-sdk/extension/plugins/image/use-copy-image.js +1 -1
  8. package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +1 -1
  9. package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/index.js +7 -3
  10. package/dist/basic-sdk/hooks/use-comment.js +27 -181
  11. package/dist/basic-sdk/index.js +3 -10
  12. package/dist/index.js +0 -12
  13. package/dist/pages/seafile-comment-editor.js +37 -13
  14. package/package.json +1 -1
  15. package/dist/assets/css/plugin-editor.css +0 -7
  16. package/dist/assets/css/simple-viewer.css +0 -6
  17. package/dist/basic-sdk/comment/components/comment-all-participants/index.css +0 -83
  18. package/dist/basic-sdk/comment/components/comment-all-participants/index.js +0 -67
  19. package/dist/basic-sdk/comment/components/comment-all-participants/participant-avatar.js +0 -43
  20. package/dist/basic-sdk/comment/components/comment-delete-popover.js +0 -80
  21. package/dist/basic-sdk/comment/components/comment-item-collapse-wrapper.js +0 -160
  22. package/dist/basic-sdk/comment/components/comment-item-content.js +0 -154
  23. package/dist/basic-sdk/comment/components/comment-item-reply.js +0 -124
  24. package/dist/basic-sdk/comment/components/comment-item-resolved-reply.js +0 -38
  25. package/dist/basic-sdk/comment/components/comment-item-wrapper.js +0 -364
  26. package/dist/basic-sdk/comment/components/comment-list.css +0 -422
  27. package/dist/basic-sdk/comment/components/comment-list.js +0 -216
  28. package/dist/basic-sdk/comment/components/comment-participants-editor/index.css +0 -132
  29. package/dist/basic-sdk/comment/components/comment-participants-editor/index.js +0 -69
  30. package/dist/basic-sdk/comment/components/comment-participants-editor/searched-collaborators.js +0 -62
  31. package/dist/basic-sdk/comment/components/comment-participants-editor/selected-participants.js +0 -48
  32. package/dist/basic-sdk/comment/components/editor-comment.js +0 -183
  33. package/dist/basic-sdk/comment/components/elements-comment-count/element-comment-count.js +0 -64
  34. package/dist/basic-sdk/comment/components/elements-comment-count/index.css +0 -29
  35. package/dist/basic-sdk/comment/components/elements-comment-count/index.js +0 -49
  36. package/dist/basic-sdk/comment/components/global-comment/global-comment-body-header.js +0 -88
  37. package/dist/basic-sdk/comment/components/global-comment/global-comment-header.js +0 -90
  38. package/dist/basic-sdk/comment/components/global-comment/index.css +0 -328
  39. package/dist/basic-sdk/comment/components/global-comment/index.js +0 -217
  40. package/dist/basic-sdk/comment/components/index.js +0 -21
  41. package/dist/basic-sdk/comment/components/style.css +0 -40
  42. package/dist/basic-sdk/comment/helper.js +0 -184
  43. package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-context.js +0 -20
  44. package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-list.js +0 -45
  45. package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-mount.js +0 -57
  46. package/dist/basic-sdk/comment/hooks/notification-hooks/index.js +0 -25
  47. package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-context.js +0 -20
  48. package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-mount.js +0 -70
  49. package/dist/basic-sdk/comment/hooks/use-participants.js +0 -26
  50. package/dist/basic-sdk/comment/index.js +0 -21
  51. package/dist/basic-sdk/comment/reducer/comment-reducer.js +0 -353
  52. package/dist/basic-sdk/comment/reducer/notification-reducer.js +0 -89
  53. package/dist/basic-sdk/comment/utils/get-event-transfer.js +0 -77
  54. package/dist/basic-sdk/comment/utils/index.js +0 -281
  55. package/dist/basic-sdk/comment/utils/notification-utils.js +0 -62
  56. package/dist/basic-sdk/layout/comment-layout/index.css +0 -15
  57. package/dist/basic-sdk/layout/comment-layout/index.js +0 -87
  58. package/dist/basic-sdk/layout/comment-layout/resize-width/index.css +0 -38
  59. package/dist/basic-sdk/layout/comment-layout/resize-width/index.js +0 -132
  60. package/dist/basic-sdk/layout/editor-container.js +0 -32
  61. package/dist/basic-sdk/layout/index.js +0 -13
  62. package/dist/basic-sdk/socket/helpers.js +0 -299
  63. package/dist/basic-sdk/socket/index.js +0 -20
  64. package/dist/basic-sdk/socket/socket-client.js +0 -211
  65. package/dist/basic-sdk/socket/socket-manager.js +0 -386
  66. package/dist/basic-sdk/socket/with-socket-io.js +0 -73
  67. /package/dist/basic-sdk/comment/{constants/index.js → constants.js} +0 -0
@@ -1,70 +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 _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
13
- var _constants2 = require("../../constants");
14
- var _utils = require("../../utils");
15
- const useNotificationsMount = (dispatch, api, collaborators) => {
16
- const {
17
- t
18
- } = (0, _reactI18next.useTranslation)('sdoc-editor');
19
- const popupBrowserCommentNotification = (0, _react.useCallback)(notification => {
20
- if (!notification) return;
21
- const {
22
- author,
23
- msg_type: msgType,
24
- reply,
25
- comment
26
- } = notification;
27
- const authorInfo = collaborators.find(collaborator => collaborator.email === author);
28
- const notificationContent = comment || reply;
29
- const titleKey = msgType === 'comment' ? 'xxx_added_a_new_comment' : 'xxx_added_a_reply';
30
- const title = t(titleKey, {
31
- author: authorInfo ? authorInfo.name : t('Unknown')
32
- });
33
- const options = {
34
- body: `${notificationContent}`
35
- };
36
- (0, _utils.createNotify)(title, options);
37
- }, [collaborators, t]);
38
- const request = (0, _react.useCallback)(async notification => {
39
- popupBrowserCommentNotification(notification);
40
- const eventBus = _eventBus.default.getInstance();
41
- dispatch({
42
- type: _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCHING
43
- });
44
- try {
45
- const res = await api.listUnseenNotifications();
46
- const notifications = res.data.notifications;
47
- dispatch({
48
- type: _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCHED,
49
- payload: notifications
50
- });
51
- eventBus.dispatch(_constants.INTERNAL_EVENT.UNSEEN_NOTIFICATIONS_COUNT, notifications === null || notifications === void 0 ? void 0 : notifications.length);
52
- } catch (error) {
53
- console.log(error);
54
- dispatch({
55
- type: _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCH_ERROR
56
- });
57
- }
58
- // eslint-disable-next-line react-hooks/exhaustive-deps
59
- }, [popupBrowserCommentNotification]);
60
- (0, _react.useEffect)(() => {
61
- request();
62
- const eventBus = _eventBus.default.getInstance();
63
- const unsubscribeNewNotification = eventBus.subscribe(_constants.INTERNAL_EVENT.NEW_NOTIFICATION, request);
64
- return () => {
65
- unsubscribeNewNotification();
66
- };
67
- // eslint-disable-next-line react-hooks/exhaustive-deps
68
- }, []);
69
- };
70
- 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,21 +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 _components = require("./components");
10
- const CommentWrapper = _ref => {
11
- let {
12
- type,
13
- editor
14
- } = _ref;
15
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, type === 'editor' && /*#__PURE__*/_react.default.createElement(_components.EditorComment, {
16
- editor: editor
17
- }), type === 'global' && /*#__PURE__*/_react.default.createElement(_components.GlobalComment, {
18
- editor: editor
19
- }));
20
- };
21
- var _default = exports.default = CommentWrapper;
@@ -1,353 +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.sortCommentList = exports.initElementCommentsMap = exports.initCommentsInfo = exports.initCommentList = exports.formatCommentsData = exports.commentReducer = void 0;
8
- var _deepCopy = _interopRequireDefault(require("deep-copy"));
9
- var _helper = require("../helper");
10
- const formatCommentsData = comments => {
11
- const formatComments = [];
12
- const dupComments = (0, _deepCopy.default)(comments);
13
- for (let i = 0; i < dupComments.length; i++) {
14
- const item = dupComments[i];
15
-
16
- // the comment is not in sdoc document
17
- if (!item.detail) continue;
18
- try {
19
- item.detail = JSON.parse(item.detail);
20
- formatComments.push(item);
21
- } catch (err) {
22
- continue;
23
- }
24
- }
25
- return formatComments;
26
- };
27
- exports.formatCommentsData = formatCommentsData;
28
- const initElementCommentsMap = comments => {
29
- const elementCommentsMap = {};
30
- const formatComments = formatCommentsData(comments);
31
- for (let i = 0; i < formatComments.length; i++) {
32
- const item = formatComments[i];
33
- const element_id = (0, _helper.getPrimaryElementId)(item.detail);
34
- if (!elementCommentsMap[element_id]) {
35
- elementCommentsMap[element_id] = [];
36
- }
37
- elementCommentsMap[element_id].push(item);
38
- }
39
- return elementCommentsMap;
40
- };
41
- exports.initElementCommentsMap = initElementCommentsMap;
42
- const initCommentList = comments => {
43
- // format comments
44
- const formatComments = formatCommentsData(comments);
45
- return formatComments;
46
-
47
- // sort comments by update time
48
- // return sortCommentList(formatComments);
49
- };
50
- exports.initCommentList = initCommentList;
51
- const sortCommentList = commentList => {
52
- const newComments = commentList.map(item => {
53
- const {
54
- updated_at,
55
- replies
56
- } = item;
57
- const replayUpdatedTimes = replies.map(item => item.updated_at);
58
- const updatedTimes = [updated_at, ...replayUpdatedTimes];
59
- updatedTimes.sort((a, b) => {
60
- return new Date(a).getTime() <= new Date(b).getTime() ? 1 : -1;
61
- });
62
- item.updated_time = updatedTimes[0];
63
- return item;
64
- });
65
- const unresolvedComments = [];
66
- const resolvedComments = [];
67
- // Differentiate between resolved and unresolved comments
68
- newComments.forEach(item => {
69
- if (item.resolved) {
70
- resolvedComments.push(item);
71
- } else {
72
- unresolvedComments.push(item);
73
- }
74
- });
75
- unresolvedComments.sort((a, b) => {
76
- return new Date(a.updated_time).getTime() <= new Date(b.updated_time).getTime() ? 1 : -1;
77
- });
78
- resolvedComments.sort((a, b) => {
79
- return new Date(a.updated_time).getTime() <= new Date(b.updated_time).getTime() ? 1 : -1;
80
- });
81
- return [...unresolvedComments, ...resolvedComments];
82
- };
83
- exports.sortCommentList = sortCommentList;
84
- const initCommentsInfo = exports.initCommentsInfo = {
85
- isFetching: true,
86
- comment_list: [],
87
- element_comments_map: {},
88
- error: false
89
- };
90
- const commentReducer = (state, action) => {
91
- switch (action.type) {
92
- case 'FETCHING_STATE':
93
- {
94
- return initCommentsInfo;
95
- }
96
- case 'RECEIVE_STATE':
97
- {
98
- const commentList = initCommentList(action.payload);
99
- return {
100
- isFetching: false,
101
- comment_list: commentList,
102
- element_comments_map: initElementCommentsMap(action.payload),
103
- error: false
104
- };
105
- }
106
- case 'FETCHING_ERROR':
107
- {
108
- return {
109
- isFetching: false,
110
- element_comments_map: {},
111
- error: true
112
- };
113
- }
114
- case 'INSERT_COMMENT':
115
- {
116
- const {
117
- element_comments_map,
118
- comment_list
119
- } = state;
120
- const {
121
- element_id,
122
- comment
123
- } = action.payload;
124
- if (!element_comments_map[element_id]) {
125
- element_comments_map[element_id] = [];
126
- }
127
- element_comments_map[element_id] = [...element_comments_map[element_id], comment];
128
- const commentList = [...comment_list, (0, _deepCopy.default)(comment)];
129
- return {
130
- ...state,
131
- element_comments_map: {
132
- ...element_comments_map
133
- },
134
- comment_list: commentList
135
- };
136
- }
137
- case 'DELETE_COMMENT':
138
- {
139
- const {
140
- element_comments_map,
141
- comment_list
142
- } = state;
143
- const {
144
- element_id,
145
- comment_id
146
- } = action.payload;
147
- if (element_comments_map[element_id]) {
148
- element_comments_map[element_id] = element_comments_map[element_id].filter(item => item.id !== comment_id);
149
- }
150
- const commentList = comment_list.filter(item => item.id !== comment_id);
151
- return {
152
- ...state,
153
- element_comments_map: {
154
- ...element_comments_map
155
- },
156
- comment_list: commentList
157
- };
158
- }
159
- case 'UPDATE_COMMENT':
160
- {
161
- const {
162
- element_comments_map,
163
- comment_list
164
- } = state;
165
- const {
166
- element_id,
167
- comment_id,
168
- comment
169
- } = action.payload;
170
- element_comments_map[element_id] = element_comments_map[element_id].map(item => {
171
- if (item.id === comment_id) {
172
- item.comment = comment.comment;
173
- item.detail = comment.detail;
174
- item.updated_at = comment.updated_at;
175
- return item;
176
- }
177
- return item;
178
- });
179
- const commentList = comment_list.map(item => {
180
- if (item.id === comment_id) {
181
- item.comment = comment.comment;
182
- item.detail = comment.detail;
183
- item.updated_at = comment.updated_at;
184
- return item;
185
- }
186
- return item;
187
- });
188
- return {
189
- ...state,
190
- element_comments_map: {
191
- ...element_comments_map
192
- },
193
- comment_list: commentList
194
- };
195
- }
196
- case 'UPDATE_COMMENT_STATE':
197
- {
198
- const {
199
- element_comments_map,
200
- comment_list
201
- } = state;
202
- const {
203
- element_id,
204
- comment_id,
205
- comment
206
- } = action.payload;
207
-
208
- // modify comment state
209
- element_comments_map[element_id] = element_comments_map[element_id].map(item => {
210
- if (item.id === comment_id) {
211
- item.resolved = comment.resolved;
212
- return item;
213
- }
214
- return item;
215
- });
216
- const commentList = comment_list.map(item => {
217
- if (item.id === comment_id) {
218
- item.resolved = comment.resolved;
219
- return item;
220
- }
221
- return item;
222
- });
223
- return {
224
- ...state,
225
- element_comments_map: {
226
- ...element_comments_map
227
- },
228
- comment_list: sortCommentList(commentList)
229
- };
230
- }
231
- case 'INSERT_REPLY':
232
- {
233
- const {
234
- element_comments_map,
235
- comment_list
236
- } = state;
237
- const {
238
- element_id,
239
- comment_id,
240
- reply
241
- } = action.payload;
242
- element_comments_map[element_id] = element_comments_map[element_id].map(item => {
243
- if (item.id === comment_id) {
244
- item.replies = [...item.replies, (0, _deepCopy.default)(reply)];
245
- return item;
246
- }
247
- return item;
248
- });
249
- const commentList = comment_list.map(item => {
250
- if (item.id === comment_id) {
251
- item.replies = [...item.replies, reply];
252
- return item;
253
- }
254
- return item;
255
- });
256
- return {
257
- ...state,
258
- element_comments_map: {
259
- ...element_comments_map
260
- },
261
- comment_list: commentList
262
- };
263
- }
264
- case 'DELETE_REPLY':
265
- {
266
- const {
267
- element_comments_map,
268
- comment_list
269
- } = state;
270
- const {
271
- element_id,
272
- comment_id,
273
- reply_id
274
- } = action.payload;
275
- element_comments_map[element_id] = element_comments_map[element_id].map(item => {
276
- if (item.id === comment_id) {
277
- item.replies = item.replies.filter(reply => reply.id !== reply_id);
278
- return item;
279
- }
280
- return item;
281
- });
282
- const commentList = comment_list.map(item => {
283
- if (item.id === comment_id) {
284
- item.replies = item.replies.filter(reply => reply.id !== reply_id);
285
- return item;
286
- }
287
- return item;
288
- });
289
- return {
290
- ...state,
291
- element_comments_map: {
292
- ...element_comments_map
293
- },
294
- comment_list: commentList
295
- };
296
- }
297
- case 'UPDATE_REPLY':
298
- {
299
- const {
300
- element_comments_map,
301
- comment_list
302
- } = state;
303
- const {
304
- element_id,
305
- comment_id,
306
- reply_id,
307
- reply
308
- } = action.payload;
309
- element_comments_map[element_id] = element_comments_map[element_id].map(item => {
310
- if (item.id === comment_id) {
311
- item.replies = item.replies.map(replyItem => {
312
- if (replyItem.id === reply_id) {
313
- // need update replay updated_at
314
- return {
315
- ...replyItem,
316
- ...reply
317
- };
318
- }
319
- return replyItem;
320
- });
321
- return item;
322
- }
323
- return item;
324
- });
325
- const commentList = comment_list.map(item => {
326
- if (item.id === comment_id) {
327
- item.replies = item.replies.map(replyItem => {
328
- if (replyItem.id === reply_id) {
329
- // need update replay updated_at
330
- return {
331
- ...replyItem,
332
- ...reply
333
- };
334
- }
335
- return replyItem;
336
- });
337
- return item;
338
- }
339
- return item;
340
- });
341
- return {
342
- ...state,
343
- element_comments_map: {
344
- ...element_comments_map
345
- },
346
- comment_list: commentList
347
- };
348
- }
349
- default:
350
- return state;
351
- }
352
- };
353
- exports.commentReducer = commentReducer;
@@ -1,89 +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.notificationReducer = exports.initNotificationsInfo = void 0;
8
- var _constants = require("../../constants");
9
- var _model = require("../../model");
10
- var _eventBus = _interopRequireDefault(require("../../utils/event-bus"));
11
- var _constants2 = require("../constants");
12
- const initNotificationsInfo = exports.initNotificationsInfo = {
13
- isFetching: true,
14
- notifications_map: {},
15
- error: false
16
- };
17
- const notificationReducer = (state, action) => {
18
- switch (action.type) {
19
- case _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCHING:
20
- {
21
- return initNotificationsInfo;
22
- }
23
- case _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCHED:
24
- {
25
- const notifications = action.payload;
26
- let notificationsMap = {};
27
- notifications.forEach(n => {
28
- const newNotification = new _model.Notification(n);
29
- notificationsMap[newNotification.key] = newNotification;
30
- });
31
- return {
32
- isFetching: false,
33
- notifications_map: notificationsMap,
34
- error: false
35
- };
36
- }
37
- case _constants2.DOC_NOTIFICATION_REDUCER_TYPE.FETCH_ERROR:
38
- {
39
- return {
40
- isFetching: false,
41
- notifications_map: {},
42
- error: true
43
- };
44
- }
45
- case _constants2.DOC_NOTIFICATION_REDUCER_TYPE.ADD:
46
- {
47
- const {
48
- notification
49
- } = action.payload;
50
- const newNotification = new _model.Notification(notification);
51
- return {
52
- ...state,
53
- notifications_map: {
54
- ...state.notifications_map,
55
- [newNotification.key]: newNotification
56
- }
57
- };
58
- }
59
- case _constants2.DOC_NOTIFICATION_REDUCER_TYPE.DEL:
60
- {
61
- const notificationKeys = action.payload;
62
- const {
63
- notifications_map
64
- } = state;
65
- if (Array.isArray(notificationKeys) && notificationKeys.length > 0) {
66
- notificationKeys.forEach(notificationKey => {
67
- if (notifications_map[notificationKey]) {
68
- delete notifications_map[notificationKey];
69
- }
70
- });
71
- }
72
- const eventBus = _eventBus.default.getInstance();
73
- eventBus.dispatch(_constants.INTERNAL_EVENT.UNSEEN_NOTIFICATIONS_COUNT, Object.keys(notifications_map).length);
74
- // No unread messages, clearly marked
75
- if (Object.keys(notifications_map).length === 0) {
76
- eventBus.dispatch(_constants.INTERNAL_EVENT.CLEAR_NOTIFICATION);
77
- }
78
- return {
79
- ...state,
80
- notifications_map
81
- };
82
- }
83
- default:
84
- {
85
- return state;
86
- }
87
- }
88
- };
89
- exports.notificationReducer = notificationReducer;
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.TEXT = exports.HTML = exports.FILES = void 0;
7
- const HTML = exports.HTML = 'text/html';
8
- const TEXT = exports.TEXT = 'text/plain';
9
- const FILES = exports.FILES = 'files';
10
- function getEventTransfer(event) {
11
- let html;
12
- let text;
13
- let files;
14
- if (window.isMobile) {
15
- if (window.dtableTransfer) {
16
- text = window.dtableTransfer['TEXT'];
17
- }
18
- } else {
19
- const transfer = event.dataTransfer || event.clipboardData;
20
- html = getType(transfer, HTML);
21
- text = getType(transfer, TEXT);
22
- files = getFiles(transfer);
23
- }
24
-
25
- // paste html
26
- if (html) {
27
- // eslint-disable-next-line new-parens
28
- let copiedTableNode = new DOMParser().parseFromString(html, HTML).querySelector('table');
29
- if (copiedTableNode) return {
30
- html,
31
- text,
32
- type: 'html'
33
- };
34
- return {
35
- html,
36
- text,
37
- type: 'html'
38
- };
39
- }
40
-
41
- // paste local picture or other files here
42
- if (files && files.length) return {
43
- 'files': files,
44
- type: 'files'
45
- };
46
-
47
- // paste text
48
- return {
49
- text: text || '',
50
- type: 'text'
51
- };
52
- }
53
- function getType(transfer, type) {
54
- if (!transfer.types || !transfer.types.length) {
55
- // COMPAT: In IE 11, there is no `types` field but `getData('Text')`
56
- // is supported`. (2017/06/23)
57
- return type === TEXT ? transfer.getData('Text') || null : null;
58
- }
59
- return transfer.getData(type);
60
- }
61
- function getFiles(transfer) {
62
- let files;
63
- try {
64
- // Get and normalize files if they exist.
65
- if (transfer.items && transfer.items.length) {
66
- files = Array.from(transfer.items).map(item => item.kind === 'file' ? item.getAsFile() : null).filter(exists => exists);
67
- } else if (transfer.files && transfer.files.length) {
68
- files = Array.from(transfer.files);
69
- }
70
- } catch (err) {
71
- if (transfer.files && transfer.files.length) {
72
- files = Array.from(transfer.files);
73
- }
74
- }
75
- return files;
76
- }
77
- var _default = exports.default = getEventTransfer;