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,170 @@
|
|
|
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 _toaster = _interopRequireDefault(require("../../toaster"));
|
|
10
|
+
var _utils = require("../../utils/utils");
|
|
11
|
+
var _participants = _interopRequireDefault(require("./participants"));
|
|
12
|
+
var _input = _interopRequireDefault(require("./input"));
|
|
13
|
+
var _btns = _interopRequireDefault(require("./btns"));
|
|
14
|
+
require("./index.css");
|
|
15
|
+
class Footer extends _react.default.Component {
|
|
16
|
+
constructor(_props) {
|
|
17
|
+
super(_props);
|
|
18
|
+
this.initParticipants = props => {
|
|
19
|
+
const {
|
|
20
|
+
row,
|
|
21
|
+
collaborators
|
|
22
|
+
} = props;
|
|
23
|
+
console.log(props);
|
|
24
|
+
if (row._participants && Array.isArray(row._participants)) {
|
|
25
|
+
let rowParticipants = row._participants.filter(Boolean);
|
|
26
|
+
rowParticipants = rowParticipants.filter(participant => {
|
|
27
|
+
const email = typeof participant === 'string' ? participant : participant.email;
|
|
28
|
+
return !!collaborators.find(collaborator => collaborator.email === email);
|
|
29
|
+
});
|
|
30
|
+
this.setState({
|
|
31
|
+
participants: rowParticipants
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this.setState({
|
|
36
|
+
participants: []
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
this.updateParticipants = participantList => {
|
|
40
|
+
this.setState({
|
|
41
|
+
participants: participantList
|
|
42
|
+
}, () => {
|
|
43
|
+
this.props.onChangeParticipants && this.props.onChangeParticipants(participantList);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
this.addParticipant = email => {
|
|
47
|
+
if (!email) return;
|
|
48
|
+
const {
|
|
49
|
+
participants
|
|
50
|
+
} = this.state;
|
|
51
|
+
const {
|
|
52
|
+
collaborators
|
|
53
|
+
} = this.props;
|
|
54
|
+
const isExist = participants.some(participant => participant.email === email);
|
|
55
|
+
if (isExist) return;
|
|
56
|
+
let newParticipantList = participants.slice(0);
|
|
57
|
+
let newParticipant = collaborators.find(collaborator => collaborator.email === email);
|
|
58
|
+
newParticipantList.push(newParticipant);
|
|
59
|
+
this.updateParticipants(newParticipantList);
|
|
60
|
+
};
|
|
61
|
+
this.convertComment = value => {
|
|
62
|
+
let regex = /<[a-zA-Z]+.*?>([\s\S]*?)<\/[a-zA-Z]*?>/g;
|
|
63
|
+
let match;
|
|
64
|
+
let start = 0;
|
|
65
|
+
let newValue = '';
|
|
66
|
+
while ((match = regex.exec(value)) !== null) {
|
|
67
|
+
let notificationName = "".concat(match[1]);
|
|
68
|
+
let substr = value.substring(start, match.index);
|
|
69
|
+
start = regex.lastIndex;
|
|
70
|
+
newValue += substr + notificationName;
|
|
71
|
+
}
|
|
72
|
+
if (start < value.length) {
|
|
73
|
+
newValue += value.slice(start);
|
|
74
|
+
}
|
|
75
|
+
return newValue;
|
|
76
|
+
};
|
|
77
|
+
this.updateAddState = isAdding => {
|
|
78
|
+
this.setState({
|
|
79
|
+
isAdding
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
this.handleError = error => {
|
|
83
|
+
let errMsg = (0, _utils.getErrorMsg)(error, true);
|
|
84
|
+
if (!error.response || error.response.status !== 403) {
|
|
85
|
+
_toaster.default.danger(this.props.t(errMsg));
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
this.addComment = comment => {
|
|
89
|
+
this.setState({
|
|
90
|
+
isAdding: true
|
|
91
|
+
}, () => {
|
|
92
|
+
this.props.addComment(comment, {
|
|
93
|
+
successCallback: () => {
|
|
94
|
+
this.commentInputRef.setCommentInputValue();
|
|
95
|
+
this.updateAddState(false);
|
|
96
|
+
},
|
|
97
|
+
failCallback: error => {
|
|
98
|
+
this.handleError(error);
|
|
99
|
+
this.updateAddState(false);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
this.onSubmit = () => {
|
|
105
|
+
const commentValue = this.commentInputRef.getCommentInputValue();
|
|
106
|
+
const comment = this.convertComment(commentValue);
|
|
107
|
+
if (!comment.trim()) return;
|
|
108
|
+
this.addComment(comment);
|
|
109
|
+
const {
|
|
110
|
+
username
|
|
111
|
+
} = window.dtable;
|
|
112
|
+
this.addParticipant(username);
|
|
113
|
+
};
|
|
114
|
+
this.onInsertElement = (content, nodeType) => {
|
|
115
|
+
this.commentInputRef.onInsertElement(content, nodeType);
|
|
116
|
+
};
|
|
117
|
+
this.state = {
|
|
118
|
+
isAdding: false,
|
|
119
|
+
participants: []
|
|
120
|
+
};
|
|
121
|
+
this.commentInputRef = null;
|
|
122
|
+
}
|
|
123
|
+
componentDidMount() {
|
|
124
|
+
this.initParticipants(this.props);
|
|
125
|
+
}
|
|
126
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
127
|
+
var _this$props$row, _nextProps$row;
|
|
128
|
+
if (((_this$props$row = this.props.row) === null || _this$props$row === void 0 ? void 0 : _this$props$row._id) !== ((_nextProps$row = nextProps.row) === null || _nextProps$row === void 0 ? void 0 : _nextProps$row._id)) {
|
|
129
|
+
this.initParticipants(nextProps);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
render() {
|
|
133
|
+
const {
|
|
134
|
+
isAdding,
|
|
135
|
+
participants
|
|
136
|
+
} = this.state;
|
|
137
|
+
const {
|
|
138
|
+
collaborators
|
|
139
|
+
} = this.props;
|
|
140
|
+
const canUpdateParticipants = Boolean(this.props.onChangeParticipants);
|
|
141
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
142
|
+
className: "dtable-ui-comments-footer"
|
|
143
|
+
}, /*#__PURE__*/_react.default.createElement(_participants.default, {
|
|
144
|
+
canUpdate: canUpdateParticipants,
|
|
145
|
+
participants: participants,
|
|
146
|
+
collaborators: collaborators,
|
|
147
|
+
showIconTip: true,
|
|
148
|
+
onChange: this.updateParticipants
|
|
149
|
+
}), /*#__PURE__*/_react.default.createElement(_input.default, {
|
|
150
|
+
ref: ref => this.commentInputRef = ref,
|
|
151
|
+
collaborators: collaborators,
|
|
152
|
+
onSubmit: this.onSubmit,
|
|
153
|
+
uploadFile: this.props.uploadFile,
|
|
154
|
+
addParticipant: this.addParticipant,
|
|
155
|
+
onInputFocus: this.props.onInputFocus,
|
|
156
|
+
onInputBlur: this.props.onInputBlur,
|
|
157
|
+
autoFocusInput: this.props.autoFocusInput,
|
|
158
|
+
canUpdateParticipants: canUpdateParticipants
|
|
159
|
+
}), /*#__PURE__*/_react.default.createElement(_btns.default, {
|
|
160
|
+
isAdding: isAdding,
|
|
161
|
+
canUpdateParticipants: canUpdateParticipants,
|
|
162
|
+
collaborators: collaborators,
|
|
163
|
+
uploadFile: this.props.uploadFile,
|
|
164
|
+
onInsertElement: this.onInsertElement,
|
|
165
|
+
onSubmit: this.onSubmit,
|
|
166
|
+
addParticipant: this.addParticipant
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
var _default = exports.default = Footer;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
.dtable-ui-comments-footer .dtable-ui-comment-input {
|
|
2
|
+
background-color: #fff;
|
|
3
|
+
height: 90px;
|
|
4
|
+
overflow: auto;
|
|
5
|
+
margin: 0px;
|
|
6
|
+
padding: 9px;
|
|
7
|
+
min-height: 90px;
|
|
8
|
+
border: 1px solid #e6e6dd;
|
|
9
|
+
border-bottom: none;
|
|
10
|
+
border-radius: 5px 5px 0px 0px;
|
|
11
|
+
white-space: pre-wrap;
|
|
12
|
+
overflow-wrap: break-word;
|
|
13
|
+
font-size: 14px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.dtable-ui-comments-footer .dtable-ui-comment-input.dtable-ui-comment-input-archive {
|
|
17
|
+
height: 130px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.dtable-ui-comments-footer .dtable-ui-comment-input:empty::before {
|
|
21
|
+
content: attr(placeholder);
|
|
22
|
+
color: #868E96;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.dtable-ui-comments-footer .dtable-ui-comment-input .image-container {
|
|
26
|
+
display: inline-block;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.dtable-ui-comments-footer .dtable-ui-comment-caret-list {
|
|
31
|
+
background: #fff;
|
|
32
|
+
position: absolute;
|
|
33
|
+
padding: 10px 0;
|
|
34
|
+
max-height: 200px;
|
|
35
|
+
overflow: auto;
|
|
36
|
+
min-width: 150px;
|
|
37
|
+
/* higher than row expand */
|
|
38
|
+
z-index: 1049;
|
|
39
|
+
border-radius: 5px;
|
|
40
|
+
border: 1px solid #ededed;
|
|
41
|
+
max-width: 200px;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.dtable-ui-comments-footer .dtable-ui-comment-caret-list .comment-participant-item {
|
|
45
|
+
padding: 5px 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.dtable-ui-comments-footer .dtable-ui-comment-caret-list .comment-participant-item.active,
|
|
49
|
+
.dtable-ui-comments-footer .dtable-ui-comment-caret-list .comment-participant-item:hover {
|
|
50
|
+
background: #f5f5f5;
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
}
|
|
@@ -0,0 +1,448 @@
|
|
|
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 _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
+
var _dtableUtils = require("dtable-utils");
|
|
12
|
+
var _ModalPortal = _interopRequireDefault(require("../../../ModalPortal"));
|
|
13
|
+
var _utils = require("../../utils");
|
|
14
|
+
var _ImagePreviewerLightbox = _interopRequireDefault(require("../../../ImagePreviewerLightbox"));
|
|
15
|
+
var _FileUploader = _interopRequireDefault(require("../../../FileUploader"));
|
|
16
|
+
var _constants = require("../../../constants");
|
|
17
|
+
var _hotkey = require("../../../utils/hotkey");
|
|
18
|
+
var _participant = _interopRequireDefault(require("./participant"));
|
|
19
|
+
var _lang = require("../../../lang");
|
|
20
|
+
require("./index.css");
|
|
21
|
+
const FONT_SIZE_WIDTH = 15;
|
|
22
|
+
const PADDING_WIDTH = 9;
|
|
23
|
+
const LINE_HEIGHT = 22;
|
|
24
|
+
const POPOVER_PADDING_HEIGHT = 10;
|
|
25
|
+
const DOWN = 'down';
|
|
26
|
+
const UP = 'up';
|
|
27
|
+
class Input extends _react.default.Component {
|
|
28
|
+
constructor(props) {
|
|
29
|
+
super(props);
|
|
30
|
+
this.hidePopover = event => {
|
|
31
|
+
if (this.commentPopoverRef && event && !this.commentPopoverRef.contains(event.target)) {
|
|
32
|
+
this.onHidePopover();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this.onHidePopover = () => {
|
|
36
|
+
if (this.state.filteredCollaborators.length > 0) {
|
|
37
|
+
this.setState({
|
|
38
|
+
filteredCollaborators: [],
|
|
39
|
+
activeCollaboratorIndex: 0
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
this.setPopoverPosition = () => {
|
|
44
|
+
const {
|
|
45
|
+
caretPosition
|
|
46
|
+
} = this.state;
|
|
47
|
+
let {
|
|
48
|
+
right,
|
|
49
|
+
left
|
|
50
|
+
} = this.commentRef.getBoundingClientRect();
|
|
51
|
+
this.commentPopoverRef.style.left = "".concat(caretPosition.x + FONT_SIZE_WIDTH, "px");
|
|
52
|
+
this.commentPopoverRef.style.top = "".concat(caretPosition.y - this.commentPopoverRef.offsetHeight, "px");
|
|
53
|
+
if (caretPosition.x + FONT_SIZE_WIDTH > right - PADDING_WIDTH) {
|
|
54
|
+
// is last code
|
|
55
|
+
this.commentPopoverRef.style.left = "".concat(left + PADDING_WIDTH + FONT_SIZE_WIDTH, "px");
|
|
56
|
+
this.commentPopoverRef.style.top = "".concat(caretPosition.y - this.commentPopoverRef.offsetHeight + LINE_HEIGHT, "px");
|
|
57
|
+
}
|
|
58
|
+
if (caretPosition.x + FONT_SIZE_WIDTH + this.commentPopoverRef.offsetWidth > document.body.clientWidth) {
|
|
59
|
+
this.commentPopoverRef.style.right = 0;
|
|
60
|
+
this.commentPopoverRef.style.left = '';
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
this.onKeyDown = event => {
|
|
64
|
+
if ((0, _hotkey.isModZ)(event)) {
|
|
65
|
+
this.onHidePopover();
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
event.stopPropagation();
|
|
68
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
69
|
+
this.commentRef.innerHTML = '';
|
|
70
|
+
return;
|
|
71
|
+
} else if ((0, _hotkey.isShiftEnter)(event)) {
|
|
72
|
+
return;
|
|
73
|
+
} else if ((0, _hotkey.isModP)(event)) {
|
|
74
|
+
this.commentRef.blur();
|
|
75
|
+
}
|
|
76
|
+
switch (event.keyCode) {
|
|
77
|
+
case _constants.KeyCodes.DownArrow:
|
|
78
|
+
case _constants.KeyCodes.UpArrow:
|
|
79
|
+
{
|
|
80
|
+
event.stopPropagation();
|
|
81
|
+
if (this.commentPopoverRef) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case _constants.KeyCodes.Enter:
|
|
87
|
+
{
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
|
|
90
|
+
// exec select collaborator operation.
|
|
91
|
+
if (this.state.filteredCollaborators.length > 0) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
this.props.onSubmit();
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
default:
|
|
98
|
+
{
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
this.onFocus = () => {
|
|
104
|
+
this.props.onInputFocus && this.props.onInputFocus();
|
|
105
|
+
};
|
|
106
|
+
this.onBlur = () => {
|
|
107
|
+
this.props.onInputBlur && this.props.onInputBlur();
|
|
108
|
+
};
|
|
109
|
+
this.setScrollTop = (offsetTop, itemOffsetHeight, mouseDownType) => {
|
|
110
|
+
let {
|
|
111
|
+
offsetHeight,
|
|
112
|
+
scrollTop
|
|
113
|
+
} = this.commentPopoverRef;
|
|
114
|
+
if (mouseDownType === DOWN) {
|
|
115
|
+
if (offsetTop + itemOffsetHeight - scrollTop - offsetHeight + POPOVER_PADDING_HEIGHT > 0) {
|
|
116
|
+
let top = offsetTop + itemOffsetHeight - offsetHeight + POPOVER_PADDING_HEIGHT;
|
|
117
|
+
this.commentPopoverRef.scrollTop = top;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (mouseDownType === UP) {
|
|
121
|
+
if (offsetTop < scrollTop) {
|
|
122
|
+
this.commentPopoverRef.scrollTop = offsetTop - POPOVER_PADDING_HEIGHT;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
this.setCommentInputValue = () => {
|
|
127
|
+
this.commentRef.innerHTML = '';
|
|
128
|
+
};
|
|
129
|
+
this.getCommentInputValue = () => {
|
|
130
|
+
return this.commentRef.innerHTML;
|
|
131
|
+
};
|
|
132
|
+
this.onInsertElement = (content, nodeType) => {
|
|
133
|
+
const selection = window.getSelection();
|
|
134
|
+
let {
|
|
135
|
+
range
|
|
136
|
+
} = this.state;
|
|
137
|
+
let newRange = this.commentUtilities.onInsertElement({
|
|
138
|
+
selection,
|
|
139
|
+
range,
|
|
140
|
+
content,
|
|
141
|
+
nodeType,
|
|
142
|
+
commentRef: this.commentRef
|
|
143
|
+
});
|
|
144
|
+
this.setState({
|
|
145
|
+
range: newRange
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
this.createHtmlElement = (selection, range, content, nodeType) => {
|
|
149
|
+
let spanNode1;
|
|
150
|
+
let spanNode2;
|
|
151
|
+
let imageContainer;
|
|
152
|
+
if (nodeType === 'image') {
|
|
153
|
+
spanNode1 = document.createElement('div');
|
|
154
|
+
spanNode1.className = 'image-container';
|
|
155
|
+
spanNode1.contentEditable = 'false';
|
|
156
|
+
imageContainer = document.createElement('img');
|
|
157
|
+
imageContainer.src = content;
|
|
158
|
+
imageContainer.height = 60;
|
|
159
|
+
spanNode1.appendChild(imageContainer);
|
|
160
|
+
spanNode2 = document.createElement('span');
|
|
161
|
+
spanNode2.innerHTML = ' ';
|
|
162
|
+
}
|
|
163
|
+
if (nodeType === 'collaborator') {
|
|
164
|
+
spanNode1 = document.createElement('span');
|
|
165
|
+
spanNode2 = document.createElement('span');
|
|
166
|
+
spanNode1.className = 'at-text';
|
|
167
|
+
spanNode1.contentEditable = 'false';
|
|
168
|
+
spanNode1.innerHTML = "@".concat(content.name);
|
|
169
|
+
spanNode2.innerHTML = ' ';
|
|
170
|
+
}
|
|
171
|
+
let frag = document.createDocumentFragment();
|
|
172
|
+
let node;
|
|
173
|
+
let lastNode;
|
|
174
|
+
frag.appendChild(spanNode1);
|
|
175
|
+
while (node = spanNode2.firstChild) {
|
|
176
|
+
lastNode = frag.appendChild(node);
|
|
177
|
+
}
|
|
178
|
+
if (!range) {
|
|
179
|
+
this.commentRef.appendChild(frag);
|
|
180
|
+
range = selection.getRangeAt(0);
|
|
181
|
+
} else {
|
|
182
|
+
range.insertNode(frag);
|
|
183
|
+
}
|
|
184
|
+
if (lastNode) {
|
|
185
|
+
range = range.cloneRange();
|
|
186
|
+
range.setStartAfter(lastNode);
|
|
187
|
+
range.collapse(true);
|
|
188
|
+
selection.removeAllRanges();
|
|
189
|
+
selection.addRange(range);
|
|
190
|
+
}
|
|
191
|
+
this.setState({
|
|
192
|
+
range: selection.getRangeAt(0)
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
this.onSelectCollaborator = collaborator => {
|
|
196
|
+
const selection = window.getSelection();
|
|
197
|
+
let {
|
|
198
|
+
range
|
|
199
|
+
} = this.state;
|
|
200
|
+
let callBack = () => {
|
|
201
|
+
this.onHidePopover();
|
|
202
|
+
this.props.addParticipant(collaborator.email);
|
|
203
|
+
};
|
|
204
|
+
let newRange = this.commentUtilities.onSelectParticipant({
|
|
205
|
+
selection,
|
|
206
|
+
range,
|
|
207
|
+
participant: collaborator,
|
|
208
|
+
callBack,
|
|
209
|
+
commentRef: this.commentRef
|
|
210
|
+
});
|
|
211
|
+
this.setState({
|
|
212
|
+
range: newRange
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
this.onPaste = event => {
|
|
216
|
+
let _this = this;
|
|
217
|
+
let callBack = files => {
|
|
218
|
+
_this.uploaderFileRef.handleFilesChange(files);
|
|
219
|
+
};
|
|
220
|
+
this.commentUtilities.onPaste(event, callBack);
|
|
221
|
+
};
|
|
222
|
+
this.onFileUploadSuccess = uploadFileMessage => {
|
|
223
|
+
this.onInsertElement(uploadFileMessage.url, 'image');
|
|
224
|
+
};
|
|
225
|
+
this.handleImageZoom = event => {
|
|
226
|
+
event.persist();
|
|
227
|
+
if (event.target.tagName === 'IMG') {
|
|
228
|
+
let imageUrl = event.target.src;
|
|
229
|
+
let imageTagList = this.commentRef.getElementsByTagName('img');
|
|
230
|
+
let imageUrlList = [];
|
|
231
|
+
for (let i = 0; i < imageTagList.length; i++) {
|
|
232
|
+
imageUrlList.push(imageTagList[i].src);
|
|
233
|
+
}
|
|
234
|
+
this.setState({
|
|
235
|
+
imageUrlList: imageUrlList,
|
|
236
|
+
largeImageIndex: imageUrlList.findIndex(imageItemUrl => imageItemUrl === imageUrl)
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
this.moveNext = () => {
|
|
241
|
+
let images = this.state.imageUrlList;
|
|
242
|
+
this.setState(prevState => ({
|
|
243
|
+
largeImageIndex: (prevState.largeImageIndex + 1) % images.length
|
|
244
|
+
}));
|
|
245
|
+
};
|
|
246
|
+
this.movePrev = () => {
|
|
247
|
+
let images = this.state.imageUrlList;
|
|
248
|
+
this.setState(prevState => ({
|
|
249
|
+
largeImageIndex: (prevState.largeImageIndex + images.length - 1) % images.length
|
|
250
|
+
}));
|
|
251
|
+
};
|
|
252
|
+
this.hideLargeImage = () => {
|
|
253
|
+
this.setState({
|
|
254
|
+
largeImageIndex: -1,
|
|
255
|
+
imageUrlList: []
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
this.onKeyUp = event => {
|
|
259
|
+
const selection = window.getSelection();
|
|
260
|
+
this.setState({
|
|
261
|
+
range: selection.getRangeAt(0)
|
|
262
|
+
});
|
|
263
|
+
if (event.keyCode === _constants.KeyCodes.DownArrow) {
|
|
264
|
+
return this.handleSelectingCollaborator(event, DOWN);
|
|
265
|
+
}
|
|
266
|
+
if (event.keyCode === _constants.KeyCodes.UpArrow) {
|
|
267
|
+
return this.handleSelectingCollaborator(event, UP);
|
|
268
|
+
}
|
|
269
|
+
if (event.keyCode === _constants.KeyCodes.Enter) {
|
|
270
|
+
return this.handleSelectCollaborator();
|
|
271
|
+
}
|
|
272
|
+
this.handleMentions(event);
|
|
273
|
+
};
|
|
274
|
+
this.onMouseUp = () => {
|
|
275
|
+
const selection = window.getSelection();
|
|
276
|
+
this.setState({
|
|
277
|
+
range: selection.getRangeAt(0)
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
this.checkMentionOperation = event => {
|
|
281
|
+
const {
|
|
282
|
+
keyCode
|
|
283
|
+
} = event;
|
|
284
|
+
const {
|
|
285
|
+
Escape,
|
|
286
|
+
LeftArrow,
|
|
287
|
+
RightArrow
|
|
288
|
+
} = _constants.KeyCodes;
|
|
289
|
+
if (keyCode === Escape || keyCode === LeftArrow || keyCode === RightArrow) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
return true;
|
|
293
|
+
};
|
|
294
|
+
this.handleMentions = event => {
|
|
295
|
+
if (this.props.isArchive) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const isValidOperation = this.checkMentionOperation(event);
|
|
299
|
+
if (!isValidOperation) {
|
|
300
|
+
return this.onHidePopover();
|
|
301
|
+
}
|
|
302
|
+
const selection = window.getSelection();
|
|
303
|
+
const {
|
|
304
|
+
collaborators
|
|
305
|
+
} = this.props;
|
|
306
|
+
let filteredCollaborators = [];
|
|
307
|
+
const {
|
|
308
|
+
isCollapsed,
|
|
309
|
+
anchorNode,
|
|
310
|
+
anchorOffset
|
|
311
|
+
} = selection;
|
|
312
|
+
if (!isCollapsed || !anchorNode || !anchorNode.data) {
|
|
313
|
+
return this.onHidePopover();
|
|
314
|
+
}
|
|
315
|
+
const text = anchorNode.data;
|
|
316
|
+
const atIndex = this.commentUtilities.getAtIndexWithAnchorPosition(anchorOffset, text);
|
|
317
|
+
if (atIndex === -1) {
|
|
318
|
+
return this.onHidePopover();
|
|
319
|
+
}
|
|
320
|
+
if (atIndex === 0 || text[atIndex - 1] === ' ') {
|
|
321
|
+
if (atIndex === anchorOffset - 1) {
|
|
322
|
+
filteredCollaborators = [...collaborators];
|
|
323
|
+
} else {
|
|
324
|
+
const searchingText = text.substring(atIndex + 1);
|
|
325
|
+
if (searchingText) {
|
|
326
|
+
filteredCollaborators = (0, _dtableUtils.searchCollaborators)(collaborators, searchingText);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (filteredCollaborators.length === 0) {
|
|
331
|
+
return this.onHidePopover();
|
|
332
|
+
}
|
|
333
|
+
this.setState({
|
|
334
|
+
filteredCollaborators,
|
|
335
|
+
activeCollaboratorIndex: 0,
|
|
336
|
+
caretPosition: (0, _utils.getSelectionCoords)(),
|
|
337
|
+
range: selection.getRangeAt(0)
|
|
338
|
+
}, () => {
|
|
339
|
+
this.setPopoverPosition();
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
this.handleSelectingCollaborator = (event, direction) => {
|
|
343
|
+
event.stopPropagation();
|
|
344
|
+
const {
|
|
345
|
+
filteredCollaborators,
|
|
346
|
+
activeCollaboratorIndex
|
|
347
|
+
} = this.state;
|
|
348
|
+
const collaboratorsLen = filteredCollaborators.length;
|
|
349
|
+
if (collaboratorsLen === 0) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
let nextActiveCollaboratorIndex = activeCollaboratorIndex;
|
|
353
|
+
if (direction === DOWN) {
|
|
354
|
+
nextActiveCollaboratorIndex++;
|
|
355
|
+
if (nextActiveCollaboratorIndex >= collaboratorsLen) {
|
|
356
|
+
nextActiveCollaboratorIndex = 0;
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
nextActiveCollaboratorIndex--;
|
|
360
|
+
if (nextActiveCollaboratorIndex < 0) {
|
|
361
|
+
nextActiveCollaboratorIndex = collaboratorsLen - 1;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
this.setState({
|
|
365
|
+
activeCollaboratorIndex: nextActiveCollaboratorIndex
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
this.handleSelectCollaborator = () => {
|
|
369
|
+
const {
|
|
370
|
+
filteredCollaborators,
|
|
371
|
+
activeCollaboratorIndex
|
|
372
|
+
} = this.state;
|
|
373
|
+
if (filteredCollaborators.length === 0) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
this.onSelectCollaborator(filteredCollaborators[activeCollaboratorIndex]);
|
|
377
|
+
};
|
|
378
|
+
this.state = {
|
|
379
|
+
filteredCollaborators: [],
|
|
380
|
+
caretPosition: {},
|
|
381
|
+
range: null,
|
|
382
|
+
imageUrlList: [],
|
|
383
|
+
activeCollaboratorIndex: 0,
|
|
384
|
+
largeImageIndex: -1
|
|
385
|
+
};
|
|
386
|
+
this.commentUtilities = new _utils.Utilities();
|
|
387
|
+
}
|
|
388
|
+
componentDidMount() {
|
|
389
|
+
document.addEventListener('mousedown', this.hidePopover);
|
|
390
|
+
if (this.props.autoFocusInput) {
|
|
391
|
+
this.commentRef.focus();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
componentWillUnmount() {
|
|
395
|
+
document.removeEventListener('mousedown', this.hidePopover);
|
|
396
|
+
}
|
|
397
|
+
render() {
|
|
398
|
+
const {
|
|
399
|
+
api
|
|
400
|
+
} = this.props;
|
|
401
|
+
const {
|
|
402
|
+
imageUrlList,
|
|
403
|
+
largeImageIndex,
|
|
404
|
+
filteredCollaborators,
|
|
405
|
+
activeCollaboratorIndex
|
|
406
|
+
} = this.state;
|
|
407
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
408
|
+
className: (0, _classnames.default)('dtable-ui-comment-input', {
|
|
409
|
+
'dtable-ui-comment-input-archive': !(api !== null && api !== void 0 && api.add)
|
|
410
|
+
}),
|
|
411
|
+
ref: ref => this.commentRef = ref,
|
|
412
|
+
onKeyDown: this.onKeyDown,
|
|
413
|
+
onFocus: this.onFocus,
|
|
414
|
+
onBlur: this.onBlur,
|
|
415
|
+
onKeyUp: this.onKeyUp,
|
|
416
|
+
onMouseUp: this.onMouseUp,
|
|
417
|
+
onPaste: this.onPaste,
|
|
418
|
+
placeholder: (0, _lang.getLocale)('Add_comment'),
|
|
419
|
+
onClick: this.handleImageZoom,
|
|
420
|
+
tabIndex: -1,
|
|
421
|
+
contentEditable: true
|
|
422
|
+
}), filteredCollaborators.length > 0 && /*#__PURE__*/_react.default.createElement(_ModalPortal.default, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
423
|
+
className: "dtable-ui-comment-caret-list",
|
|
424
|
+
ref: ref => this.commentPopoverRef = ref
|
|
425
|
+
}, filteredCollaborators.map((participant, i) => {
|
|
426
|
+
return /*#__PURE__*/_react.default.createElement(_participant.default, {
|
|
427
|
+
key: participant.email,
|
|
428
|
+
index: i,
|
|
429
|
+
activeIndex: activeCollaboratorIndex,
|
|
430
|
+
participant: participant,
|
|
431
|
+
setScrollTop: this.setScrollTop,
|
|
432
|
+
onSelect: this.onSelectCollaborator.bind(this, participant)
|
|
433
|
+
});
|
|
434
|
+
}))), largeImageIndex > -1 && /*#__PURE__*/_react.default.createElement(_ImagePreviewerLightbox.default, {
|
|
435
|
+
imageItems: imageUrlList,
|
|
436
|
+
imageIndex: this.state.largeImageIndex,
|
|
437
|
+
closeImagePopup: this.hideLargeImage,
|
|
438
|
+
moveToPrevImage: this.movePrev,
|
|
439
|
+
moveToNextImage: this.moveNext
|
|
440
|
+
}), /*#__PURE__*/_react.default.createElement(_FileUploader.default, {
|
|
441
|
+
className: "dtable-ui-comment-paste-uploader",
|
|
442
|
+
ref: ref => this.uploaderFileRef = ref,
|
|
443
|
+
onFileUploadSuccess: this.onFileUploadSuccess,
|
|
444
|
+
uploadFile: this.props.uploadFile
|
|
445
|
+
}));
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
var _default = exports.default = Input;
|
|
File without changes
|