This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex-65112a6a.js
433 lines (404 loc) · 15.1 KB
/
index-65112a6a.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
import { e as _toConsumableArray, c as LocalizationContext, b as _slicedToArray } from './LocalizationContext-ec52e278.js';
import React__default, { useContext, useRef, useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { m as Colors, n as changeColorToClassName, I as IconButton, B as Button, d as ButtonTypes, e as ButtonSizes, o as MODAL_ROOT } from './index-e9eccbb4.js';
import { L as Label, a as LabelTypography, b as LabelColors, I as Icon, c as IconTypes, d as IconColors, A as Avatar, k as changeColorToClassName$1 } from './index-4456ba1e.js';
import { createPortal } from 'react-dom';
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
var SUPPORTED_MIMES = {
IMAGE: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/svg+xml', 'image/webp' // not supported in IE
],
VIDEO: ['video/mpeg', 'video/ogg', 'video/webm', 'video/mp4']
};
var isImage = function isImage(type) {
return SUPPORTED_MIMES.IMAGE.indexOf(type) >= 0;
};
var isVideo = function isVideo(type) {
return SUPPORTED_MIMES.VIDEO.indexOf(type) >= 0;
};
var isGif = function isGif(type) {
return type === 'image/gif';
};
var unSupported = function unSupported(type) {
return !(isImage(type) || isVideo(type));
};
var isEmpty = function isEmpty(val) {
return val === null || val === undefined;
}; // Some Ids return string and number inconsistently
// only use to comapre IDs
function compareIds (a, b) {
if (isEmpty(a) || isEmpty(b)) {
return false;
}
var aString = a.toString();
var bString = b.toString();
return aString === bString;
}
function DateSeparator(_ref) {
var className = _ref.className,
children = _ref.children,
separatorColor = _ref.separatorColor;
return /*#__PURE__*/React__default.createElement("div", {
className: [].concat(_toConsumableArray(Array.isArray(className) ? className : [className]), ['sendbird-separator']).join(' ')
}, /*#__PURE__*/React__default.createElement("div", {
className: ['sendbird-separator__left', "".concat(changeColorToClassName(separatorColor), "--background-color")].join(' ')
}), /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-separator__text"
}, children), /*#__PURE__*/React__default.createElement("div", {
className: ['sendbird-separator__right', "".concat(changeColorToClassName(separatorColor), "--background-color")].join(' ')
}));
}
DateSeparator.propTypes = {
className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
children: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string), PropTypes.element]),
separatorColor: PropTypes.string
};
DateSeparator.defaultProps = {
className: '',
children: /*#__PURE__*/React__default.createElement(Label, {
type: LabelTypography.CAPTION_2,
color: LabelColors.ONBACKGROUND_2
}, "Date Separator"),
separatorColor: Colors.ONBACKGROUND_4
};
// import IconAttach from '../../svgs/icon-attach.svg';
var LINE_HEIGHT = 76;
var noop = function noop() {};
var KeyCode = {
SHIFT: 16,
ENTER: 13
};
var handleUploadFile = function handleUploadFile(callback) {
return function (event) {
if (event.target.files && event.target.files[0]) {
callback(event.target.files[0]);
} // eslint-disable-next-line no-param-reassign
event.target.value = '';
};
};
var MessageInput = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
var isEdit = props.isEdit,
disabled = props.disabled,
value = props.value,
name = props.name,
placeholder = props.placeholder,
maxLength = props.maxLength,
onFileUpload = props.onFileUpload,
onSendMessage = props.onSendMessage,
onCancelEdit = props.onCancelEdit,
onStartTyping = props.onStartTyping;
var _useContext = useContext(LocalizationContext),
stringSet = _useContext.stringSet;
var fileInputRef = useRef(null);
var _useState = useState(value),
_useState2 = _slicedToArray(_useState, 2),
inputValue = _useState2[0],
setInputValue = _useState2[1];
var _useState3 = useState(false),
_useState4 = _slicedToArray(_useState3, 2),
isShiftPressed = _useState4[0],
setIsShiftPressed = _useState4[1];
var setHeight = function setHeight() {
try {
var elem = ref.current;
var MAX_HEIGHT = window.document.body.offsetHeight * 0.6;
if (elem && elem.scrollHeight >= LINE_HEIGHT) {
if (MAX_HEIGHT < elem.scrollHeight) {
elem.style.height = 'auto';
elem.style.height = "".concat(MAX_HEIGHT, "px");
} else {
elem.style.height = 'auto';
elem.style.height = "".concat(elem.scrollHeight, "px");
}
} else {
elem.style.height = '';
}
} catch (error) {// error
}
}; // after setHeight called twice, the textarea goes to the initialized
useEffect(function () {
setHeight();
return setHeight;
}, [inputValue]);
var sendMessage = function sendMessage() {
if (inputValue && inputValue.trim().length > 0) {
var trimmedInputValue = inputValue.trim();
if (isEdit) {
onSendMessage(name, trimmedInputValue, function () {
onCancelEdit();
});
} else {
onSendMessage(trimmedInputValue);
setInputValue('');
}
}
};
return /*#__PURE__*/React__default.createElement("form", {
className: [isEdit ? 'sendbird-message-input__edit' : '', disabled ? 'sendbird-message-input-form__disabled' : ''].join(' ')
}, /*#__PURE__*/React__default.createElement("div", {
className: ['sendbird-message-input', disabled ? 'sendbird-message-input__disabled' : ''].join(' ')
}, /*#__PURE__*/React__default.createElement("textarea", {
className: "sendbird-message-input--textarea",
disabled: disabled,
ref: ref,
name: name,
value: inputValue,
maxLength: maxLength,
onChange: function onChange(e) {
setInputValue(e.target.value);
onStartTyping();
},
onKeyDown: function onKeyDown(e) {
if (e.keyCode === KeyCode.SHIFT) {
setIsShiftPressed(true);
}
if (!isShiftPressed && e.keyCode === KeyCode.ENTER) {
e.preventDefault();
sendMessage();
}
},
onKeyUp: function onKeyUp(e) {
if (e.keyCode === KeyCode.SHIFT) {
setIsShiftPressed(false);
}
}
}), !inputValue && /*#__PURE__*/React__default.createElement(Label, {
className: "sendbird-message-input--placeholder",
type: LabelTypography.BODY_1,
color: LabelColors.ONBACKGROUND_3
}, placeholder || stringSet.CHANNEL__MESSAGE_INPUT__PLACE_HOLDER), !isEdit && inputValue && inputValue.trim().length > 0 && /*#__PURE__*/React__default.createElement(IconButton, {
className: "sendbird-message-input--send",
height: "32px",
width: "32px",
onClick: sendMessage
}, /*#__PURE__*/React__default.createElement(Icon, {
type: IconTypes.SEND,
fillColor: IconColors.PRIMARY,
width: "20px",
height: "20px"
})), !isEdit && (!inputValue || !(inputValue.trim().length > 0)) && /*#__PURE__*/React__default.createElement(IconButton, {
className: "sendbird-message-input--attach",
height: "32px",
width: "32px",
onClick: function onClick() {
// todo: clear previous input
fileInputRef.current.click();
}
}, /*#__PURE__*/React__default.createElement(Icon, {
type: IconTypes.ATTACH,
fillColor: IconColors.CONTENT_INVERSE,
width: "20px",
height: "20px"
}), /*#__PURE__*/React__default.createElement("input", {
className: "sendbird-message-input--attach-input",
type: "file",
ref: fileInputRef,
onChange: handleUploadFile(onFileUpload)
}))), isEdit && /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-message-input--edit-action"
}, /*#__PURE__*/React__default.createElement(Button, {
className: "sendbird-message-input--edit-action__cancel",
type: ButtonTypes.SECONDARY,
size: ButtonSizes.SMALL,
onClick: onCancelEdit
}, stringSet.BUTTON__CANCEL), /*#__PURE__*/React__default.createElement(Button, {
className: "sendbird-message-input--edit-action__save",
type: ButtonTypes.PRIMARY,
size: ButtonSizes.SMALL,
onClick: function onClick() {
if (inputValue) {
var trimmedInputValue = inputValue.trim();
onSendMessage(name, trimmedInputValue, function () {
onCancelEdit();
});
}
}
}, stringSet.BUTTON__SAVE)));
});
MessageInput.propTypes = {
placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
isEdit: PropTypes.bool,
name: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
value: PropTypes.string,
disabled: PropTypes.bool,
maxLength: PropTypes.number,
onFileUpload: PropTypes.func,
onSendMessage: PropTypes.func,
onStartTyping: PropTypes.func,
onCancelEdit: PropTypes.func
};
MessageInput.defaultProps = {
value: '',
onSendMessage: noop,
name: 'sendbird-message-input',
isEdit: false,
disabled: false,
placeholder: '',
maxLength: 5000,
onFileUpload: noop,
onCancelEdit: noop,
onStartTyping: noop
};
var FileViewerComponent = function FileViewerComponent(_ref) {
var profileUrl = _ref.profileUrl,
nickname = _ref.nickname,
name = _ref.name,
type = _ref.type,
url = _ref.url,
isByMe = _ref.isByMe,
onClose = _ref.onClose,
onDelete = _ref.onDelete;
return /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer"
}, /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__header"
}, /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__header__left"
}, /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__header__left__avatar"
}, /*#__PURE__*/React__default.createElement(Avatar, {
height: "32px",
width: "32px",
src: profileUrl
})), /*#__PURE__*/React__default.createElement(Label, {
className: "sendbird-fileviewer__header__left__filename",
type: LabelTypography.H_2,
color: LabelColors.ONBACKGROUND_1
}, name), /*#__PURE__*/React__default.createElement(Label, {
className: "sendbird-fileviewer__header__left__sender-name",
type: LabelTypography.BODY_1,
color: LabelColors.ONBACKGROUND_2
}, nickname)), /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__header__right"
}, !unSupported(type) && /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__header__right__actions"
}, /*#__PURE__*/React__default.createElement("a", {
className: "sendbird-fileviewer__header__right__actions__download",
rel: "noopener noreferrer",
href: url,
target: "_blank"
}, /*#__PURE__*/React__default.createElement(Icon, {
type: IconTypes.DOWNLOAD,
height: "24px",
width: "24px"
})), onDelete && isByMe && /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__header__right__actions__delete"
}, /*#__PURE__*/React__default.createElement(Icon, {
type: IconTypes.DELETE,
height: "24px",
width: "24px",
onClick: onDelete
}))), /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__header__right__actions__close"
}, /*#__PURE__*/React__default.createElement(Icon, {
type: IconTypes.CLOSE,
height: "24px",
width: "24px",
onClick: onClose
})))), /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__content"
}, isVideo(type) &&
/*#__PURE__*/
// eslint-disable-next-line jsx-a11y/media-has-caption
React__default.createElement("video", {
controls: true,
className: "sendbird-fileviewer__content__video"
}, /*#__PURE__*/React__default.createElement("source", {
src: url,
type: type
})), isImage(type) && /*#__PURE__*/React__default.createElement("img", {
src: url,
alt: name,
className: "sendbird-fileviewer__content__img"
}), unSupported(type) && /*#__PURE__*/React__default.createElement("div", {
className: "sendbird-fileviewer__content__unsupported"
}, /*#__PURE__*/React__default.createElement(Label, {
type: LabelTypography.H_1,
color: LabelColors.ONBACKGROUND_1
}, "Unsupoprted message"))));
};
FileViewerComponent.propTypes = {
profileUrl: PropTypes.string.isRequired,
nickname: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
isByMe: PropTypes.bool
};
FileViewerComponent.defaultProps = {
isByMe: true
};
function FileViewer(props) {
var message = props.message,
isByMe = props.isByMe,
onClose = props.onClose,
onDelete = props.onDelete;
var sender = message.sender,
type = message.type,
url = message.url,
_message$name = message.name,
name = _message$name === void 0 ? '' : _message$name;
var profileUrl = sender.profileUrl,
_sender$nickname = sender.nickname,
nickname = _sender$nickname === void 0 ? '' : _sender$nickname;
return /*#__PURE__*/createPortal( /*#__PURE__*/React__default.createElement(FileViewerComponent, {
profileUrl: profileUrl,
nickname: nickname,
type: type,
url: url,
name: name,
onClose: onClose,
onDelete: onDelete,
isByMe: isByMe
}), document.getElementById(MODAL_ROOT));
}
FileViewer.propTypes = {
message: PropTypes.shape({
sender: PropTypes.shape({
profileUrl: PropTypes.string,
nickname: PropTypes.string
}),
type: PropTypes.string,
url: PropTypes.string,
name: PropTypes.string
}).isRequired,
isByMe: PropTypes.bool,
onClose: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired
};
FileViewer.defaultProps = {
isByMe: true
};
var http = /https?:\/\//;
function LinkLabel(_ref) {
var className = _ref.className,
src = _ref.src,
type = _ref.type,
color = _ref.color,
children = _ref.children;
var url = http.test(src) ? src : "http://".concat(src);
return /*#__PURE__*/React__default.createElement("a", {
className: [].concat(_toConsumableArray(Array.isArray(className) ? className : [className]), ['sendbird-link-label', color ? changeColorToClassName$1(color) : '']).join(' '),
href: url,
target: "_blank",
rel: "noopener noreferrer"
}, /*#__PURE__*/React__default.createElement(Label, {
className: "sendbird-link-label__label",
type: type,
color: color
}, children));
}
LinkLabel.propTypes = {
className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
src: PropTypes.string.isRequired,
type: PropTypes.oneOf(Object.keys(LabelTypography)).isRequired,
color: PropTypes.oneOf(Object.keys(LabelColors)).isRequired,
children: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.arrayOf(PropTypes.string), PropTypes.arrayOf(PropTypes.element)]).isRequired
};
LinkLabel.defaultProps = {
className: ''
};
export { DateSeparator as D, FileViewer as F, LinkLabel as L, MessageInput as M, isVideo as a, isGif as b, compareIds as c, isImage as i, unSupported as u };
//# sourceMappingURL=index-65112a6a.js.map