dtable-ui-component 5.3.1-beta1 → 5.3.1-beta3
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/lib/Comment/body/comment.js +190 -0
- package/lib/Comment/body/index.css +95 -0
- package/lib/Comment/body/index.js +32 -0
- package/lib/Comment/footer/btns/index.css +40 -0
- package/lib/Comment/footer/btns/index.js +113 -0
- package/lib/Comment/footer/index.css +157 -0
- package/lib/Comment/footer/index.js +170 -0
- package/lib/Comment/footer/input/index.css +52 -0
- package/lib/Comment/footer/input/index.js +448 -0
- package/lib/Comment/footer/input/participant/index.css +0 -0
- package/lib/Comment/footer/input/participant/index.js +53 -0
- package/lib/Comment/footer/participants/index.css +22 -0
- package/lib/Comment/footer/participants/index.js +68 -0
- package/lib/Comment/footer/participants/participant/index.css +5 -0
- package/lib/Comment/footer/participants/participant/index.js +32 -0
- package/lib/Comment/footer/participants/participant-select/index.css +104 -0
- package/lib/Comment/footer/participants/participant-select/index.js +182 -0
- package/lib/Comment/index.css +19 -0
- package/lib/Comment/index.js +305 -0
- package/lib/Comment/model.js +25 -0
- package/lib/Comment/utils/common.js +62 -0
- package/lib/Comment/utils/index.js +27 -0
- package/lib/Comment/utils/utilities.js +176 -0
- package/lib/DigitalSignEditor/index.js +1 -1
- package/lib/FileEditor/index.js +16 -2
- package/lib/RowExpandDialog/body/index.js +43 -60
- package/lib/RowExpandDialog/column-content/index.css +1 -0
- package/lib/RowExpandDialog/header/index.css +3 -3
- package/lib/RowExpandDialog/header/index.js +33 -11
- package/lib/RowExpandDialog/index.js +37 -57
- package/lib/RowExpandEditor/RowExpandLongTextEditor/index.js +1 -2
- package/lib/RowExpandFormatter/RowExpandLinkFormatter/index.js +1 -1
- package/lib/RowExpandFormatter/index.css +1 -1
- package/lib/RowExpandFormatter/index.js +3 -4
- package/lib/lang/index.js +3 -2
- package/lib/locales/de.json +5 -1
- package/lib/locales/en.json +5 -1
- package/lib/locales/es.json +5 -1
- package/lib/locales/fr.json +5 -1
- package/lib/locales/pt.json +5 -1
- package/lib/locales/ru.json +5 -1
- package/lib/locales/zh-CN.json +5 -1
- package/lib/utils/hotkey.js +37 -0
- package/lib/utils/utils.js +58 -2
- package/package.json +1 -1
- package/lib/RowExpandDialog/constants.js +0 -114
- package/lib/RowExpandDialog/utils.js +0 -83
- package/lib/RowExpandFormatter/RowExpandLinkFormatter/utils.js +0 -71
|
@@ -0,0 +1,305 @@
|
|
|
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 _dtableUtils = require("dtable-utils");
|
|
10
|
+
var _Loading = _interopRequireDefault(require("../Loading"));
|
|
11
|
+
var _toaster = _interopRequireDefault(require("../toaster"));
|
|
12
|
+
var _body = _interopRequireDefault(require("./body"));
|
|
13
|
+
var _footer = _interopRequireDefault(require("./footer"));
|
|
14
|
+
var _model = _interopRequireDefault(require("./model"));
|
|
15
|
+
var _utils = require("../utils/utils");
|
|
16
|
+
var _lang = require("../lang");
|
|
17
|
+
require("./index.css");
|
|
18
|
+
const ROW_COMMENT = 'row_comment';
|
|
19
|
+
class Comment extends _react.default.Component {
|
|
20
|
+
constructor(_props) {
|
|
21
|
+
var _this;
|
|
22
|
+
super(_props);
|
|
23
|
+
_this = this;
|
|
24
|
+
this.handleError = error => {
|
|
25
|
+
let errMsg = (0, _utils.getErrorMsg)(error, true);
|
|
26
|
+
if (!error.response || error.response.status !== 403) {
|
|
27
|
+
_toaster.default.danger((0, _lang.getLocale)(errMsg));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
// comment and count
|
|
31
|
+
this.updateCount = function (row) {
|
|
32
|
+
let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
33
|
+
_this.setState({
|
|
34
|
+
count
|
|
35
|
+
}, () => {
|
|
36
|
+
_this.props.updateCount && _this.props.updateCount(row, count);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
this.reCalculateComments = function (row) {
|
|
40
|
+
let pageNum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
41
|
+
let isGetCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
42
|
+
_this.initComments(row, 1, pageNum);
|
|
43
|
+
if (!isGetCount) return;
|
|
44
|
+
const {
|
|
45
|
+
api
|
|
46
|
+
} = _this.props;
|
|
47
|
+
api.getCount(row).then(res => {
|
|
48
|
+
const count = res.data.count;
|
|
49
|
+
_this.updateCount(row, count);
|
|
50
|
+
}).catch(e => {
|
|
51
|
+
_this.handleError(e);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
this.initComments = function (row) {
|
|
55
|
+
let page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
56
|
+
let perPage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
57
|
+
const {
|
|
58
|
+
api
|
|
59
|
+
} = _this.props;
|
|
60
|
+
api.get(row, page, perPage).then(res => {
|
|
61
|
+
console.log(res);
|
|
62
|
+
let comments = res.data.comment_list || [];
|
|
63
|
+
let newComments = [];
|
|
64
|
+
comments.forEach(item => {
|
|
65
|
+
const comment = new _model.default(item);
|
|
66
|
+
newComments.push(comment);
|
|
67
|
+
});
|
|
68
|
+
_this.setState({
|
|
69
|
+
comments: newComments,
|
|
70
|
+
isLoading: false
|
|
71
|
+
});
|
|
72
|
+
}).catch(e => {
|
|
73
|
+
_this.handleError(e);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
this.addComment = (newComment, _ref) => {
|
|
77
|
+
let {
|
|
78
|
+
successCallback,
|
|
79
|
+
failCallback
|
|
80
|
+
} = _ref;
|
|
81
|
+
const {
|
|
82
|
+
row,
|
|
83
|
+
api
|
|
84
|
+
} = this.props;
|
|
85
|
+
api.add(row, newComment).then(res => api.getCount(row)).then(res => {
|
|
86
|
+
const count = res.data.count;
|
|
87
|
+
this.updateCount(row, count);
|
|
88
|
+
this.reCalculateComments(row, count, false);
|
|
89
|
+
successCallback();
|
|
90
|
+
}).catch(error => {
|
|
91
|
+
failCallback && failCallback(error);
|
|
92
|
+
});
|
|
93
|
+
this.setState({
|
|
94
|
+
isFirstLoading: true
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
this.resolveComment = (event, commentID) => {
|
|
98
|
+
event.persist();
|
|
99
|
+
const {
|
|
100
|
+
row,
|
|
101
|
+
api
|
|
102
|
+
} = this.props;
|
|
103
|
+
api.update(row, commentID, null, 1).then(() => {
|
|
104
|
+
this.reCalculateComments(row);
|
|
105
|
+
}).catch(error => {
|
|
106
|
+
this.handleError(error);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
this.deleteComment = (event, commentID) => {
|
|
110
|
+
const {
|
|
111
|
+
api,
|
|
112
|
+
row
|
|
113
|
+
} = this.props;
|
|
114
|
+
api.delete(row, commentID).then(() => {
|
|
115
|
+
this.reCalculateComments(row);
|
|
116
|
+
}).catch(e => {
|
|
117
|
+
this.handleError(e);
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
// notification
|
|
121
|
+
this.onNewNotification = notification => {
|
|
122
|
+
const {
|
|
123
|
+
msg_type
|
|
124
|
+
} = notification;
|
|
125
|
+
if (msg_type !== ROW_COMMENT) return;
|
|
126
|
+
this.setState({
|
|
127
|
+
isFirstLoading: true
|
|
128
|
+
});
|
|
129
|
+
const {
|
|
130
|
+
row,
|
|
131
|
+
api
|
|
132
|
+
} = this.props;
|
|
133
|
+
api.getCount(row).then(res => {
|
|
134
|
+
const count = res.data.count;
|
|
135
|
+
this.updateCount(row, count);
|
|
136
|
+
this.reCalculateComments(row, count, false);
|
|
137
|
+
}).catch(e => {
|
|
138
|
+
this.handleError(e);
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
// collaborators
|
|
142
|
+
this.initCollaborators = props => {
|
|
143
|
+
const {
|
|
144
|
+
columns,
|
|
145
|
+
row,
|
|
146
|
+
collaborators
|
|
147
|
+
} = props;
|
|
148
|
+
let collaboratorColumnKeyList = [];
|
|
149
|
+
columns.forEach(column => {
|
|
150
|
+
if (column.type === _dtableUtils.CellType.COLLABORATOR) {
|
|
151
|
+
collaboratorColumnKeyList.push(column.key);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
if (collaboratorColumnKeyList.length === 0) {
|
|
155
|
+
this.setState({
|
|
156
|
+
collaborators
|
|
157
|
+
});
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
let rowCollaborators = [];
|
|
161
|
+
collaboratorColumnKeyList.forEach(collaboratorKey => {
|
|
162
|
+
if (row[collaboratorKey] && row[collaboratorKey].length > 0) {
|
|
163
|
+
rowCollaborators.push(...row[collaboratorKey]);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
rowCollaborators = Array.from(new Set(rowCollaborators));
|
|
167
|
+
let newCollaborators = [];
|
|
168
|
+
if (rowCollaborators.length > 0) {
|
|
169
|
+
collaborators.forEach(collaborator => {
|
|
170
|
+
let rowCollaborator = rowCollaborators.find(rowCollaboratorItem => {
|
|
171
|
+
return rowCollaboratorItem === collaborator.email;
|
|
172
|
+
});
|
|
173
|
+
if (rowCollaborator) {
|
|
174
|
+
newCollaborators.unshift(collaborator);
|
|
175
|
+
} else {
|
|
176
|
+
newCollaborators.push(collaborator);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
} else {
|
|
180
|
+
newCollaborators = collaborators;
|
|
181
|
+
}
|
|
182
|
+
this.setState({
|
|
183
|
+
collaborators: newCollaborators
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
// scroll
|
|
187
|
+
this.onScrollBottom = () => {
|
|
188
|
+
const commentListPaddingHeight = 16;
|
|
189
|
+
this.body.scrollTop = this.bodyContent.offsetHeight - this.body.offsetHeight + commentListPaddingHeight;
|
|
190
|
+
this.setState({
|
|
191
|
+
isFirstLoading: false
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
this.onScroll = () => {
|
|
195
|
+
if (this.body.offsetHeight + this.body.scrollTop + 1 < this.bodyContent.offsetHeight + 32) return; // 16 is padding height
|
|
196
|
+
const {
|
|
197
|
+
api,
|
|
198
|
+
row
|
|
199
|
+
} = this.props;
|
|
200
|
+
const {
|
|
201
|
+
comments,
|
|
202
|
+
count
|
|
203
|
+
} = this.state;
|
|
204
|
+
let currentCommentsLength = comments.length;
|
|
205
|
+
if (currentCommentsLength < count) {
|
|
206
|
+
// Have pagination
|
|
207
|
+
let page = currentCommentsLength % 10 === 0 ? Math.floor(currentCommentsLength / 10) + 1 : Math.ceil(currentCommentsLength / 10);
|
|
208
|
+
if (page === 0) return;
|
|
209
|
+
api.get(row, page, 10).then(res => {
|
|
210
|
+
let newComments = comments.slice(0);
|
|
211
|
+
const nextPageCommentList = res.data.comment_list || [];
|
|
212
|
+
nextPageCommentList.forEach(item => {
|
|
213
|
+
const comment = new Comment(item);
|
|
214
|
+
const commentId = comment.id;
|
|
215
|
+
const commentIndex = newComments.findIndex(item => item.id === commentId);
|
|
216
|
+
if (commentIndex === -1) {
|
|
217
|
+
newComments.push(comment);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
this.setState({
|
|
221
|
+
comments: newComments,
|
|
222
|
+
isFirstLoading: false
|
|
223
|
+
});
|
|
224
|
+
}).catch(e => {
|
|
225
|
+
this.handleError(e);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
this.state = {
|
|
230
|
+
count: 0,
|
|
231
|
+
collaborators: _props.collaborators || [],
|
|
232
|
+
comments: [],
|
|
233
|
+
isLoading: true,
|
|
234
|
+
isFirstLoading: true
|
|
235
|
+
};
|
|
236
|
+
this.unsubscribeNotification = null;
|
|
237
|
+
}
|
|
238
|
+
componentDidMount() {
|
|
239
|
+
var _this$props$eventBus;
|
|
240
|
+
this.initComments(this.props.row);
|
|
241
|
+
this.initCollaborators(this.props);
|
|
242
|
+
this.unsubscribeNotification = (_this$props$eventBus = this.props.eventBus) === null || _this$props$eventBus === void 0 ? void 0 : _this$props$eventBus.subscribe('new-notification', this.onNewNotification);
|
|
243
|
+
}
|
|
244
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
245
|
+
if (this.props.row._id !== nextProps.row._id) {
|
|
246
|
+
this.initComments(nextProps.row);
|
|
247
|
+
this.initCollaborators(nextProps);
|
|
248
|
+
this.setState({
|
|
249
|
+
isFirstLoading: true,
|
|
250
|
+
isLoading: true
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
componentWillUnmount() {
|
|
255
|
+
this.body = null;
|
|
256
|
+
this.bodyContent = null;
|
|
257
|
+
this.unsubscribeNotification();
|
|
258
|
+
}
|
|
259
|
+
render() {
|
|
260
|
+
const {
|
|
261
|
+
collaborators,
|
|
262
|
+
comments,
|
|
263
|
+
isLoading,
|
|
264
|
+
isFirstLoading
|
|
265
|
+
} = this.state;
|
|
266
|
+
const {
|
|
267
|
+
autoFocusInput,
|
|
268
|
+
row,
|
|
269
|
+
columns,
|
|
270
|
+
onInputFocus,
|
|
271
|
+
onInputBlur,
|
|
272
|
+
api,
|
|
273
|
+
uploadFile
|
|
274
|
+
} = this.props;
|
|
275
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
276
|
+
className: "dtable-ui-comments h-100 w-100"
|
|
277
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
278
|
+
className: "dtable-ui-comments-body",
|
|
279
|
+
onScroll: this.onScroll,
|
|
280
|
+
ref: ref => this.body = ref
|
|
281
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
282
|
+
ref: ref => this.bodyContent = ref
|
|
283
|
+
}, isLoading ? /*#__PURE__*/_react.default.createElement("div", {
|
|
284
|
+
className: "w-100 h-100 d-flex align-items-center justify-content-center"
|
|
285
|
+
}, /*#__PURE__*/_react.default.createElement(_Loading.default, null)) : /*#__PURE__*/_react.default.createElement(_body.default, {
|
|
286
|
+
isFirstLoading: isFirstLoading,
|
|
287
|
+
comments: comments,
|
|
288
|
+
collaborators: collaborators,
|
|
289
|
+
onDelete: this.deleteComment,
|
|
290
|
+
onResolve: this.resolveComment,
|
|
291
|
+
onScrollBottom: this.onScrollBottom
|
|
292
|
+
}))), /*#__PURE__*/_react.default.createElement(_footer.default, {
|
|
293
|
+
autoFocusInput: autoFocusInput,
|
|
294
|
+
collaborators: collaborators,
|
|
295
|
+
row: row,
|
|
296
|
+
columns: columns,
|
|
297
|
+
addComment: this.addComment,
|
|
298
|
+
onChangeParticipants: api.modifyParticipants,
|
|
299
|
+
uploadFile: uploadFile,
|
|
300
|
+
onInputFocus: onInputFocus,
|
|
301
|
+
onInputBlur: onInputBlur
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
var _default = exports.default = Comment;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 _dayjs = _interopRequireDefault(require("dayjs"));
|
|
9
|
+
class Comment {
|
|
10
|
+
constructor(object) {
|
|
11
|
+
this.id = object.id || null;
|
|
12
|
+
this.author = object.author || null;
|
|
13
|
+
this.comment = object.comment || null;
|
|
14
|
+
this.dtable_uuid = object.dtable_uuid || null;
|
|
15
|
+
this.row_id = object.row_id || null;
|
|
16
|
+
this.created_at = object.created_at || null;
|
|
17
|
+
this.updated_at = object.updated_at || null;
|
|
18
|
+
this.resolved = object.resolved || 0;
|
|
19
|
+
if (this.created_at) {
|
|
20
|
+
const time = new Date(this.created_at).getTime();
|
|
21
|
+
this.created_at = (0, _dayjs.default)(time).format('YYYY-MM-DD HH:mm');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
var _default = exports.default = Comment;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelectionCoords = void 0;
|
|
7
|
+
const getSelectionCoords = () => {
|
|
8
|
+
let doc = window.document;
|
|
9
|
+
let sel = doc.selection;
|
|
10
|
+
let range;
|
|
11
|
+
let rects;
|
|
12
|
+
let rect;
|
|
13
|
+
let x = 0;
|
|
14
|
+
let y = 0;
|
|
15
|
+
if (sel) {
|
|
16
|
+
if (sel.type !== 'Control') {
|
|
17
|
+
range = sel.createRange();
|
|
18
|
+
range.collapse(true);
|
|
19
|
+
x = range.boundingLeft;
|
|
20
|
+
y = range.boundingTop;
|
|
21
|
+
}
|
|
22
|
+
} else if (window.getSelection) {
|
|
23
|
+
sel = window.getSelection();
|
|
24
|
+
if (sel.rangeCount) {
|
|
25
|
+
range = sel.getRangeAt(0).cloneRange();
|
|
26
|
+
if (range.getClientRects) {
|
|
27
|
+
range.collapse(true);
|
|
28
|
+
rects = range.getClientRects();
|
|
29
|
+
if (rects.length > 0) {
|
|
30
|
+
rect = rects[0];
|
|
31
|
+
}
|
|
32
|
+
// When the cursor is at the beginning of the line, rect is undefined
|
|
33
|
+
if (rect) {
|
|
34
|
+
x = rect.left;
|
|
35
|
+
y = rect.top;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Fall back to inserting a temporary element
|
|
39
|
+
if (x === 0 && y === 0 || rect === undefined) {
|
|
40
|
+
let span = doc.createElement('span');
|
|
41
|
+
if (span.getClientRects) {
|
|
42
|
+
// Ensure span has dimensions and position by
|
|
43
|
+
// adding a zero-width space character
|
|
44
|
+
span.appendChild(doc.createTextNode('\u200b'));
|
|
45
|
+
range.insertNode(span);
|
|
46
|
+
rect = span.getClientRects()[0];
|
|
47
|
+
x = rect.left;
|
|
48
|
+
y = rect.top;
|
|
49
|
+
let spanParent = span.parentNode;
|
|
50
|
+
spanParent.removeChild(span);
|
|
51
|
+
// Glue any broken text nodes back together
|
|
52
|
+
spanParent.normalize();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
x: x,
|
|
59
|
+
y: y
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.getSelectionCoords = getSelectionCoords;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _common = require("./common");
|
|
7
|
+
Object.keys(_common).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _common[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _common[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _utilities = require("./utilities");
|
|
18
|
+
Object.keys(_utilities).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _utilities[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _utilities[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Utilities = void 0;
|
|
8
|
+
var _getEventTransfer = _interopRequireDefault(require("../../utils/get-event-transfer"));
|
|
9
|
+
class Utilities {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.onInsertElement = _ref => {
|
|
12
|
+
let {
|
|
13
|
+
commentRef,
|
|
14
|
+
selection,
|
|
15
|
+
range,
|
|
16
|
+
content,
|
|
17
|
+
nodeType
|
|
18
|
+
} = _ref;
|
|
19
|
+
if (range) {
|
|
20
|
+
selection.removeAllRanges();
|
|
21
|
+
selection.addRange(range);
|
|
22
|
+
}
|
|
23
|
+
return this.createHtmlElement({
|
|
24
|
+
commentRef,
|
|
25
|
+
selection,
|
|
26
|
+
range,
|
|
27
|
+
content,
|
|
28
|
+
nodeType
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
this.getHtmlElement = (nodeType, content) => {
|
|
32
|
+
switch (nodeType) {
|
|
33
|
+
case 'image':
|
|
34
|
+
{
|
|
35
|
+
let parentElement = document.createElement('div');
|
|
36
|
+
parentElement.className = 'image-container';
|
|
37
|
+
parentElement.contentEditable = 'false';
|
|
38
|
+
let imageContainer = document.createElement('img');
|
|
39
|
+
imageContainer.src = content;
|
|
40
|
+
imageContainer.height = 60;
|
|
41
|
+
parentElement.appendChild(imageContainer);
|
|
42
|
+
return parentElement.outerHTML;
|
|
43
|
+
}
|
|
44
|
+
default:
|
|
45
|
+
{
|
|
46
|
+
return '';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this.createHtmlElement = _ref2 => {
|
|
51
|
+
let {
|
|
52
|
+
commentRef,
|
|
53
|
+
selection,
|
|
54
|
+
range,
|
|
55
|
+
content,
|
|
56
|
+
nodeType
|
|
57
|
+
} = _ref2;
|
|
58
|
+
let spanNode1;
|
|
59
|
+
let spanNode2;
|
|
60
|
+
let imageContainer;
|
|
61
|
+
if (nodeType === 'image') {
|
|
62
|
+
spanNode1 = document.createElement('div');
|
|
63
|
+
spanNode1.className = 'image-container';
|
|
64
|
+
spanNode1.contentEditable = 'false';
|
|
65
|
+
imageContainer = document.createElement('img');
|
|
66
|
+
imageContainer.src = content;
|
|
67
|
+
imageContainer.height = 60;
|
|
68
|
+
spanNode1.appendChild(imageContainer);
|
|
69
|
+
spanNode2 = document.createElement('span');
|
|
70
|
+
spanNode2.innerHTML = ' ';
|
|
71
|
+
}
|
|
72
|
+
if (nodeType === 'collaborator') {
|
|
73
|
+
spanNode1 = document.createElement('span');
|
|
74
|
+
spanNode2 = document.createElement('span');
|
|
75
|
+
spanNode1.className = 'at-text';
|
|
76
|
+
spanNode1.contentEditable = 'true';
|
|
77
|
+
spanNode1.innerHTML = "@".concat(content.name);
|
|
78
|
+
spanNode2.innerHTML = ' ';
|
|
79
|
+
}
|
|
80
|
+
let frag = document.createDocumentFragment();
|
|
81
|
+
let lastNode;
|
|
82
|
+
frag.appendChild(spanNode1);
|
|
83
|
+
lastNode = frag.appendChild(spanNode2.firstChild);
|
|
84
|
+
if (range) {
|
|
85
|
+
range.insertNode(frag);
|
|
86
|
+
} else {
|
|
87
|
+
commentRef.appendChild(frag);
|
|
88
|
+
range = selection.getRangeAt(0);
|
|
89
|
+
}
|
|
90
|
+
if (lastNode) {
|
|
91
|
+
range = range.cloneRange();
|
|
92
|
+
range.setStartAfter(lastNode);
|
|
93
|
+
range.collapse(true);
|
|
94
|
+
selection.removeAllRanges();
|
|
95
|
+
selection.addRange(range);
|
|
96
|
+
}
|
|
97
|
+
return range;
|
|
98
|
+
};
|
|
99
|
+
this.onSelectParticipant = _ref3 => {
|
|
100
|
+
let {
|
|
101
|
+
selection,
|
|
102
|
+
range,
|
|
103
|
+
participant,
|
|
104
|
+
callBack,
|
|
105
|
+
commentRef
|
|
106
|
+
} = _ref3;
|
|
107
|
+
if (range) {
|
|
108
|
+
// delete '@xxx';
|
|
109
|
+
selection.removeAllRanges();
|
|
110
|
+
selection.addRange(range);
|
|
111
|
+
const textNode = range.startContainer;
|
|
112
|
+
const atIndex = this.getAtIndexWithAnchorPosition(range.startOffset, textNode.data);
|
|
113
|
+
if (atIndex > -1) {
|
|
114
|
+
range.setStart(textNode, atIndex);
|
|
115
|
+
range.setEnd(textNode, range.endOffset);
|
|
116
|
+
range.deleteContents();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
let newRange = this.createHtmlElement({
|
|
120
|
+
selection,
|
|
121
|
+
range,
|
|
122
|
+
content: participant,
|
|
123
|
+
nodeType: 'collaborator',
|
|
124
|
+
commentRef
|
|
125
|
+
});
|
|
126
|
+
if (callBack) {
|
|
127
|
+
callBack();
|
|
128
|
+
}
|
|
129
|
+
if (commentRef) {
|
|
130
|
+
commentRef.focus();
|
|
131
|
+
}
|
|
132
|
+
return newRange;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* get the index of '@' from anchor position.
|
|
136
|
+
* @param {*} anchorPosition '@text|anchor position|'
|
|
137
|
+
* @param {*} text '@abc'
|
|
138
|
+
* @returns index
|
|
139
|
+
* e.g. '@abc|anchor position|' // 0
|
|
140
|
+
* '@123 @|anchor position| @abc' // 5
|
|
141
|
+
*/
|
|
142
|
+
this.getAtIndexWithAnchorPosition = (anchorPosition, text) => {
|
|
143
|
+
let atIndex = -1;
|
|
144
|
+
for (let i = anchorPosition - 1; i > -1; i--) {
|
|
145
|
+
if (text[i] === '@') {
|
|
146
|
+
atIndex = i;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return atIndex;
|
|
151
|
+
};
|
|
152
|
+
this.onPaste = (event, callBack) => {
|
|
153
|
+
event.stopPropagation();
|
|
154
|
+
let cliperData = (0, _getEventTransfer.default)(event);
|
|
155
|
+
if (cliperData.files) {
|
|
156
|
+
let file = cliperData.files[0];
|
|
157
|
+
let isImage = /image/i.test(file.type);
|
|
158
|
+
if (isImage) {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
if (callBack) {
|
|
161
|
+
callBack(cliperData.files);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
let text = cliperData.text;
|
|
167
|
+
if (document.queryCommandSupported('insertText')) {
|
|
168
|
+
document.execCommand('insertText', false, text);
|
|
169
|
+
} else {
|
|
170
|
+
document.execCommand('paste', false, text);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.Utilities = Utilities;
|
|
@@ -94,7 +94,7 @@ class DigitalSignEditor extends _react.Component {
|
|
|
94
94
|
failedCallback: error => {
|
|
95
95
|
const errMsg = (0, _utils2.getErrorMsg)(error, true);
|
|
96
96
|
if (!error.response || error.response.status !== 403) {
|
|
97
|
-
_toaster.default.danger(
|
|
97
|
+
_toaster.default.danger((0, _lang.getLocale)(errMsg));
|
|
98
98
|
}
|
|
99
99
|
this.setState({
|
|
100
100
|
saving: false
|
package/lib/FileEditor/index.js
CHANGED
|
@@ -13,6 +13,8 @@ var _constants = require("../constants");
|
|
|
13
13
|
var _DTableModalHeader = _interopRequireDefault(require("../DTableModalHeader"));
|
|
14
14
|
var _lang = require("../lang");
|
|
15
15
|
var _constants2 = require("./constants");
|
|
16
|
+
var _utils = require("../utils/utils");
|
|
17
|
+
var _toaster = _interopRequireDefault(require("../toaster"));
|
|
16
18
|
require("./index.css");
|
|
17
19
|
class FileEditor extends _react.default.Component {
|
|
18
20
|
constructor(props) {
|
|
@@ -207,10 +209,22 @@ class FileEditor extends _react.default.Component {
|
|
|
207
209
|
this.setState({
|
|
208
210
|
value: newValue
|
|
209
211
|
});
|
|
210
|
-
}).catch(error => {
|
|
212
|
+
}).catch(error => {
|
|
213
|
+
const errorMessage = (0, _utils.getErrorMsg)(error);
|
|
214
|
+
if (!error.response || error.response.status !== 403) {
|
|
215
|
+
_toaster.default.danger((0, _lang.getLocale)(errorMessage));
|
|
216
|
+
}
|
|
217
|
+
});
|
|
211
218
|
};
|
|
212
219
|
this.onRotateImage = (url, degree) => {
|
|
213
|
-
this.props.rotateImage(url, degree).then(res => {
|
|
220
|
+
this.props.rotateImage(url, degree).then(res => {
|
|
221
|
+
// todo
|
|
222
|
+
}).catch(error => {
|
|
223
|
+
const errorMessage = (0, _utils.getErrorMsg)(error);
|
|
224
|
+
if (!error.response || error.response.status !== 403) {
|
|
225
|
+
_toaster.default.danger((0, _lang.getLocale)(errorMessage));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
214
228
|
};
|
|
215
229
|
this.state = {
|
|
216
230
|
value: props.value || [],
|