@zohodesk/dot 1.0.0-beta.216 → 1.0.0-beta.219

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 (31) hide show
  1. package/README.md +8 -0
  2. package/assets/Appearance/dark/mode/dotDarkMode.module.css +10 -0
  3. package/assets/Appearance/dark/themes/blue/blueDarkDotTheme.module.css +6 -0
  4. package/assets/Appearance/dark/themes/green/greenDarkDotTheme.module.css +6 -0
  5. package/assets/Appearance/dark/themes/orange/orangeDarkDotTheme.module.css +6 -0
  6. package/assets/Appearance/dark/themes/red/redDarkDotTheme.module.css +6 -0
  7. package/assets/Appearance/dark/themes/yellow/yellowDarkDotTheme.module.css +6 -0
  8. package/assets/Appearance/default/mode/dotDefaultMode.module.css +10 -0
  9. package/assets/Appearance/default/themes/blue/blueDefaultDotTheme.module.css +6 -0
  10. package/assets/Appearance/default/themes/green/greenDefaultDotTheme.module.css +6 -0
  11. package/assets/Appearance/default/themes/orange/orangeDefaultDotTheme.module.css +6 -0
  12. package/assets/Appearance/default/themes/red/redDefaultDotTheme.module.css +6 -0
  13. package/assets/Appearance/default/themes/yellow/yellowDefaultDotTheme.module.css +6 -0
  14. package/es/AttachmentViewer/Attachment.js +17 -0
  15. package/es/AttachmentViewer/AttachmentImage.js +85 -0
  16. package/es/AttachmentViewer/AttachmentViewer.js +535 -0
  17. package/es/AttachmentViewer/AttachmentViewer.module.css +346 -0
  18. package/es/AttachmentViewer/utils.js +107 -0
  19. package/es/common/dot_animation.module.css +27 -0
  20. package/es/common/dot_common.module.css +4 -0
  21. package/es/form/fields/TagsMultiSelect/TagsMultiSelect.js +7 -4
  22. package/images/audio_thumbnail.png +0 -0
  23. package/lib/AttachmentViewer/Attachment.js +28 -0
  24. package/lib/AttachmentViewer/AttachmentImage.js +129 -0
  25. package/lib/AttachmentViewer/AttachmentViewer.js +618 -0
  26. package/lib/AttachmentViewer/AttachmentViewer.module.css +346 -0
  27. package/lib/AttachmentViewer/utils.js +134 -0
  28. package/lib/common/dot_animation.module.css +27 -0
  29. package/lib/common/dot_common.module.css +4 -0
  30. package/lib/form/fields/TagsMultiSelect/TagsMultiSelect.js +7 -4
  31. package/package.json +15 -13
@@ -0,0 +1,535 @@
1
+ import React, { Component } from "react";
2
+ import PropTypes from "prop-types";
3
+ import { Container, Box } from "@zohodesk/components/lib/Layout";
4
+ import Icon from "@zohodesk/icons/lib/Icon";
5
+ import Avatar from "@zohodesk/components/lib/Avatar/Avatar";
6
+ import { ResponsiveReceiver } from "@zohodesk/components/lib/Responsive/CustomResponsive";
7
+ import { getUniqueId } from "@zohodesk/components/lib/Provider/IdProvider";
8
+ import AttachmentImage from "./AttachmentImage";
9
+ import Link from "../Link/Link";
10
+ import IconButton from "../IconButton/IconButton";
11
+ import FreezeLayer from "../FreezeLayer/FreezeLayer";
12
+ import { isAudioFile, getExtensionFromFileName } from "./Attachment";
13
+ import style from "./AttachmentViewer.module.css";
14
+ export default class AttachmentViewer extends Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.state = {
18
+ isPViewListOpen: !!(this.props.previewObj && this.props.previewObj.previewData),
19
+ selectedIndex: this.props.previewObj.selectedIndex,
20
+ isZoomed: false,
21
+ data: this.props.previewObj ? this.props.previewObj.previewData : [],
22
+ dataList: this.getUpdateDataList({
23
+ index: this.props.previewObj.selectedIndex,
24
+ data: this.props.previewObj ? this.props.previewObj.previewData : [],
25
+ dataList: []
26
+ })
27
+ };
28
+ this.togglePViewList = this.togglePViewList.bind(this);
29
+ this.changeSelectedIndex = this.changeSelectedIndex.bind(this);
30
+ this.closeAttachmentViewer = this.closeAttachmentViewer.bind(this);
31
+ this.responsiveFunc = this.responsiveFunc.bind(this);
32
+ this.zoomIn = this.zoomIn.bind(this);
33
+ this.zoomOut = this.zoomOut.bind(this);
34
+ this.imgPreviewView = this.imgPreviewView.bind(this);
35
+ this.getNextId = getUniqueId(this);
36
+ this.getUpdateDataList = this.getUpdateDataList.bind(this);
37
+ this.zoomMaintain = this.zoomMaintain.bind(this);
38
+ }
39
+
40
+ togglePViewList() {
41
+ this.setState(prevState => ({
42
+ isPViewListOpen: !prevState.isPViewListOpen
43
+ }), () => {
44
+ this.focusSelectedImg(this.state.selectedIndex);
45
+ });
46
+ }
47
+
48
+ zoomOut(ele) {
49
+ this.setState({
50
+ isZoomed: false
51
+ });
52
+ const img = document.getElementById(`img${ele}`);
53
+
54
+ if (img) {
55
+ img.classList.remove(style.zoomedImg);
56
+ img.classList.add(style.normalImg);
57
+ }
58
+ }
59
+
60
+ zoomIn(event, ele) {
61
+ let moveToPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
62
+ this.setState({
63
+ isZoomed: true
64
+ });
65
+ const img = document.getElementById(`img${ele}`);
66
+ const ratio = 95;
67
+ let imgContainer, imgUnits, imgSize, imgRatio, imgContainerUnits, imgContainerPosition;
68
+
69
+ if (moveToPosition) {
70
+ imgContainer = document.getElementById(`imgBox${ele}`);
71
+ imgUnits = img.getBoundingClientRect();
72
+ imgSize = {
73
+ height: img.naturalHeight,
74
+ width: img.naturalWidth
75
+ };
76
+ imgRatio = {
77
+ height: Math.floor(imgSize.height / imgUnits.height / 100 * ratio),
78
+ width: Math.floor(imgSize.width / imgUnits.width / 100 * ratio)
79
+ };
80
+ imgContainerUnits = imgContainer.getBoundingClientRect();
81
+ imgContainerPosition = imgContainer ? {
82
+ top: imgContainerUnits.top,
83
+ left: imgContainerUnits.left
84
+ } : {
85
+ top: 0,
86
+ left: 0
87
+ };
88
+ }
89
+
90
+ if (img) {
91
+ img.classList.remove(style.normalImg);
92
+ img.classList.add(style.zoomedImg);
93
+ }
94
+
95
+ if (moveToPosition) {
96
+ imgContainer.scrollLeft = (event.pageX - imgContainerPosition.left - imgUnits.left) * imgRatio.width;
97
+ imgContainer.scrollTop = (event.pageY - imgContainerPosition.top - imgUnits.top) * imgRatio.height;
98
+ }
99
+ }
100
+
101
+ zoomMaintain(selectedIndex) {
102
+ let {
103
+ isZoomed
104
+ } = this.state;
105
+ isZoomed ? this.zoomIn({}, selectedIndex) : this.zoomOut(selectedIndex);
106
+ }
107
+
108
+ getUpdateDataList(_ref) {
109
+ let {
110
+ index,
111
+ data,
112
+ dataList
113
+ } = _ref;
114
+ data = data || this.state.data;
115
+ dataList = dataList || this.state.dataList;
116
+ const finalDataList = [...dataList];
117
+
118
+ if (index >= finalDataList.length) {
119
+ for (let i = dataList.length; i <= index; i++) {
120
+ finalDataList.push(data.slice(i)[0]);
121
+ }
122
+ } else if (index + 1 === finalDataList.length && index + 1 < data.length) {
123
+ finalDataList.push(data.slice(index + 1)[0]);
124
+ }
125
+
126
+ return finalDataList;
127
+ }
128
+
129
+ updateDataList(index) {
130
+ this.setState({
131
+ dataList: this.getUpdateDataList({
132
+ index
133
+ })
134
+ });
135
+ }
136
+
137
+ changeSelectedIndex(index) {
138
+ const {
139
+ data,
140
+ selectedIndex
141
+ } = this.state;
142
+ const {
143
+ maintainZoom
144
+ } = this.props;
145
+ maintainZoom ? this.zoomMaintain(index) : this.zoomOut(selectedIndex);
146
+
147
+ if (index <= data.length - 1) {
148
+ this.updateDataList(index);
149
+ }
150
+
151
+ this.setState({
152
+ selectedIndex: index
153
+ }, () => {
154
+ this.focusSelectedImg(index);
155
+ });
156
+ }
157
+
158
+ focusSelectedImg(index) {
159
+ const ele = this[`img_${index}`];
160
+
161
+ if (ele) {
162
+ const cont = this.imgListCont;
163
+ cont.scrollLeft = ele.offsetLeft;
164
+ }
165
+ }
166
+
167
+ closeAttachmentViewer() {
168
+ this.setState({
169
+ isPViewListOpen: false,
170
+ isZoomed: false
171
+ });
172
+ this.props.hideAttachmentViewer();
173
+ }
174
+
175
+ responsiveFunc(_ref2) {
176
+ let {
177
+ mediaQueryOR
178
+ } = _ref2;
179
+ return {
180
+ uptoTablet: mediaQueryOR([{
181
+ maxWidth: 768
182
+ }])
183
+ };
184
+ }
185
+
186
+ imgPreviewView() {
187
+ var _this = this;
188
+
189
+ const {
190
+ dataList,
191
+ selectedIndex,
192
+ isZoomed
193
+ } = this.state;
194
+ const {
195
+ maintainZoom
196
+ } = this.props;
197
+
198
+ const getImgStyle = i => {
199
+ let position;
200
+
201
+ if (selectedIndex < i) {
202
+ position = (i - selectedIndex) * 100;
203
+ return {
204
+ transform: `translateX(${parseInt(position)}%)`,
205
+ opacity: "0"
206
+ };
207
+ }
208
+
209
+ if (i === selectedIndex) {
210
+ return {
211
+ transform: "translateX(0%)",
212
+ opacity: "1"
213
+ };
214
+ }
215
+
216
+ position = (selectedIndex - i) * 100 * -1;
217
+ return {
218
+ transform: `translateX(${parseInt(position)}%)`,
219
+ opacity: "0"
220
+ };
221
+ };
222
+
223
+ return dataList.length && dataList.map(function () {
224
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
225
+ let i = arguments.length > 1 ? arguments[1] : undefined;
226
+ const selectedImgUrl = data.viewUrl;
227
+ return /*#__PURE__*/React.createElement(Container, {
228
+ className: style.imgBox,
229
+ id: `imgBox${i}`,
230
+ key: i,
231
+ alignBox: "row",
232
+ align: "both",
233
+ style: getImgStyle(i)
234
+ }, /*#__PURE__*/React.createElement(Box, {
235
+ className: style.imgRef,
236
+ id: `imgPreviewRef${i}`
237
+ }, isAudioFile(data.name) ? selectedIndex == i ? /*#__PURE__*/React.createElement("video", {
238
+ autoPlay: true,
239
+ controls: true,
240
+ className: style.zoomIn
241
+ }, /*#__PURE__*/React.createElement("source", {
242
+ src: data.viewUrl,
243
+ type: `audio/${getExtensionFromFileName(data.name)}`
244
+ })) : null : /*#__PURE__*/React.createElement(AttachmentImage, {
245
+ className: `${style.img} ${selectedIndex == i && maintainZoom ? isZoomed ? style.zoomedImg : style.normalImg : ""}`,
246
+ src: selectedImgUrl,
247
+ onClick: isZoomed ? _this.zoomOut.bind(_this, i) : e => {
248
+ _this.zoomIn(e, i, true);
249
+ },
250
+ alt: "Preview",
251
+ dataId: "attachViewed",
252
+ id: `img${i}`,
253
+ isImage: true,
254
+ isCover: false
255
+ })));
256
+ });
257
+ }
258
+
259
+ render() {
260
+ const {
261
+ isPViewListOpen,
262
+ selectedIndex,
263
+ data,
264
+ isZoomed
265
+ } = this.state;
266
+ const {
267
+ responsiveId,
268
+ needDownload,
269
+ i18nKeys,
270
+ isActive
271
+ } = this.props;
272
+ const totalLen = data.length;
273
+ const selectedAttachment = data[selectedIndex] || {};
274
+ const selectedImgUrl = selectedAttachment.viewUrl;
275
+ const downloadUrl = selectedAttachment.downloadUrl;
276
+ let authorHref;
277
+ let authorName;
278
+ const {
279
+ author
280
+ } = data[selectedIndex] ? data[selectedIndex] : {};
281
+
282
+ if (author) {
283
+ authorHref = author.href;
284
+ authorName = author.name;
285
+ }
286
+
287
+ const ariaId = this.getNextId();
288
+ return /*#__PURE__*/React.createElement(FreezeLayer, {
289
+ isActive: isActive && totalLen >= 1,
290
+ palette: "dark",
291
+ animationName: "expand"
292
+ }, /*#__PURE__*/React.createElement(ResponsiveReceiver, {
293
+ responsiveId: responsiveId,
294
+ query: this.responsiveFunc
295
+ }, _ref3 => {
296
+ let {
297
+ uptoTablet
298
+ } = _ref3;
299
+ return /*#__PURE__*/React.createElement(Container, {
300
+ scroll: "none",
301
+ "data-scroll-palette": "dark"
302
+ }, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Container, {
303
+ alignBox: "row",
304
+ className: style.header,
305
+ align: "between",
306
+ tabindex: "0"
307
+ }, /*#__PURE__*/React.createElement(Box, {
308
+ shrink: true,
309
+ className: style.title,
310
+ "data-title": selectedAttachment.name,
311
+ dataId: "attachName",
312
+ id: ariaId
313
+ }, selectedAttachment.name), /*#__PURE__*/React.createElement(Box, {
314
+ flexible: true,
315
+ className: style.count,
316
+ dataId: "attachCountContainer"
317
+ }, selectedIndex + 1, "/", totalLen), /*#__PURE__*/React.createElement(Box, {
318
+ className: uptoTablet ? style.mbleMenuBar : style.menuBar
319
+ }, /*#__PURE__*/React.createElement(Container, {
320
+ isInline: true,
321
+ alignBox: uptoTablet ? "column-reverse" : "row",
322
+ align: uptoTablet ? "bottom" : "center",
323
+ wrap: "wrap",
324
+ isCover: false
325
+ }, isZoomed ? /*#__PURE__*/React.createElement("div", {
326
+ className: uptoTablet ? style.mobileMenu : style.menu,
327
+ onClick: this.zoomOut.bind(this, selectedIndex),
328
+ "data-id": "zoomOut",
329
+ "data-title": i18nKeys.zoomOutText
330
+ }, /*#__PURE__*/React.createElement(IconButton, {
331
+ iconName: "ZD-GN-zoomOut",
332
+ className: style.menuIcon,
333
+ iconSize: "16",
334
+ hoverType: "border",
335
+ a11y: {
336
+ ariaLabel: i18nKeys.zoomOutText
337
+ }
338
+ })) : /*#__PURE__*/React.createElement("div", {
339
+ className: uptoTablet ? style.mobileMenu : style.menu,
340
+ onClick: e => this.zoomIn(e, selectedIndex),
341
+ "data-id": "zoomIn",
342
+ "data-title": i18nKeys.zoomInText
343
+ }, /*#__PURE__*/React.createElement(IconButton, {
344
+ iconName: "ZD-GN-zoomIn",
345
+ className: style.menuIcon,
346
+ iconSize: "16",
347
+ hoverType: "border",
348
+ a11y: {
349
+ ariaLabel: i18nKeys.zoomInText
350
+ }
351
+ })), /*#__PURE__*/React.createElement("div", {
352
+ className: uptoTablet ? style.mobileMenu : style.menu
353
+ }, /*#__PURE__*/React.createElement(Link, {
354
+ href: selectedImgUrl,
355
+ target: "_blank",
356
+ dataId: "newTabAttach",
357
+ title: i18nKeys.newTabText
358
+ }, /*#__PURE__*/React.createElement(IconButton, {
359
+ iconName: "ZD-GN-newLink",
360
+ className: style.menuIcon,
361
+ iconSize: "16",
362
+ hoverType: "border",
363
+ needButtonTag: false,
364
+ a11y: {
365
+ ariaLabel: i18nKeys.newTabText
366
+ }
367
+ }))), needDownload ? /*#__PURE__*/React.createElement("div", {
368
+ className: uptoTablet ? style.mobileMenu : style.menu
369
+ }, /*#__PURE__*/React.createElement(Link, {
370
+ href: downloadUrl,
371
+ target: "_parent",
372
+ hasReload: true,
373
+ download: true,
374
+ title: i18nKeys.downloadText
375
+ }, /*#__PURE__*/React.createElement(IconButton, {
376
+ iconName: "ZD-GN-download",
377
+ className: style.menuIcon,
378
+ iconSize: "16",
379
+ hoverType: "border",
380
+ needButtonTag: false,
381
+ a11y: {
382
+ ariaLabel: i18nKeys.downloadText
383
+ }
384
+ }))) : null, /*#__PURE__*/React.createElement("div", {
385
+ className: uptoTablet ? style.mobileMenu : style.menu,
386
+ onClick: this.closeAttachmentViewer,
387
+ "data-id": "closeAttach",
388
+ "data-title": i18nKeys.closeText
389
+ }, /*#__PURE__*/React.createElement(IconButton, {
390
+ iconName: "ZD-cross",
391
+ iconSize: "15",
392
+ hoverType: "border",
393
+ className: style.menuIcon,
394
+ a11y: {
395
+ ariaLabel: i18nKeys.closeText
396
+ },
397
+ title: i18nKeys.closeText
398
+ })))))), /*#__PURE__*/React.createElement(Box, {
399
+ flexible: true,
400
+ role: "toolbar",
401
+ tabindex: "0"
402
+ }, /*#__PURE__*/React.createElement(Container, {
403
+ alignBox: "row"
404
+ }, /*#__PURE__*/React.createElement(Box, {
405
+ className: `${style.arrowBox} ${uptoTablet ? style.mbleArrowBox : style.nrmlArrowBox} ${selectedIndex === 0 ? style.hidden : ""}`,
406
+ onClick: this.changeSelectedIndex.bind(this, selectedIndex - 1),
407
+ "data-title": i18nKeys.previousText,
408
+ "data-title-position": "left"
409
+ }, /*#__PURE__*/React.createElement("button", {
410
+ className: style.btn,
411
+ "aria-label": i18nKeys.previousText
412
+ }, /*#__PURE__*/React.createElement(Icon, {
413
+ name: "ZD-arrowLeft3",
414
+ iconClass: style.arrow,
415
+ dataId: "leftAttachNav",
416
+ isBold: true
417
+ }))), /*#__PURE__*/React.createElement(Box, {
418
+ className: style.previewBox,
419
+ role: "option",
420
+ tabindex: "0",
421
+ "aria-describedby": ariaId,
422
+ isShrink: false,
423
+ eleRef: this.setImgBoxRef,
424
+ scroll: "both",
425
+ flexible: true
426
+ }, this.imgPreviewView()), /*#__PURE__*/React.createElement(Box, {
427
+ className: `${style.arrowBox} ${uptoTablet ? style.mbleArrowBox : style.nrmlArrowBox} ${totalLen === selectedIndex + 1 ? style.hidden : ""}`,
428
+ onClick: this.changeSelectedIndex.bind(this, selectedIndex + 1),
429
+ "data-title": i18nKeys.nextText,
430
+ "data-title-position": "right"
431
+ }, /*#__PURE__*/React.createElement("button", {
432
+ className: style.btn,
433
+ "aria-label": i18nKeys.nextText
434
+ }, /*#__PURE__*/React.createElement(Icon, {
435
+ name: "ZD-arrowRight3",
436
+ iconClass: style.arrow,
437
+ dataId: "rightAttachNav",
438
+ isBold: true
439
+ }))))), /*#__PURE__*/React.createElement(Box, {
440
+ className: `${style.footer} ${isPViewListOpen && totalLen !== 1 ? style.footerHeight : style.footerHide} `
441
+ }, /*#__PURE__*/React.createElement(Container, {
442
+ align: "vertical",
443
+ alignBox: "row",
444
+ className: style.footerHeight
445
+ }, author && /*#__PURE__*/React.createElement(Box, {
446
+ className: style.author
447
+ }, /*#__PURE__*/React.createElement(Container, {
448
+ alignBox: "row",
449
+ align: "both"
450
+ }, /*#__PURE__*/React.createElement(Avatar, {
451
+ name: authorName,
452
+ size: "xmedium",
453
+ src: authorHref,
454
+ palette: "info"
455
+ }), /*#__PURE__*/React.createElement(Box, {
456
+ flexible: true,
457
+ className: style.authorName,
458
+ "data-title": authorName
459
+ }, authorName))), /*#__PURE__*/React.createElement(Box, {
460
+ flexible: true
461
+ }, /*#__PURE__*/React.createElement(Container, {
462
+ align: "vertical",
463
+ alignBox: "row",
464
+ scroll: "horizontal",
465
+ eleRef: el => this.imgListCont = el,
466
+ className: style.listContainer
467
+ }, data.map((item, index) => {
468
+ const {
469
+ name,
470
+ viewUrl
471
+ } = item;
472
+ const isAudio = isAudioFile(name);
473
+ return /*#__PURE__*/React.createElement(Box, {
474
+ className: `${style.imgItem} ${index === selectedIndex ? style.selected : ""} ${isAudio ? style.isAudio : ""}`,
475
+ key: index,
476
+ onClick: this.changeSelectedIndex.bind(this, index),
477
+ eleRef: el => this[`img_${index}`] = el,
478
+ dataId: "attachPreviewList",
479
+ "data-title": name
480
+ }, /*#__PURE__*/React.createElement(AttachmentImage, {
481
+ src: viewUrl,
482
+ size: "small",
483
+ alt: name,
484
+ className: style.image,
485
+ isImage: !isAudio
486
+ }));
487
+ }))))), totalLen !== 1 && /*#__PURE__*/React.createElement(IconButton, {
488
+ dataId: "attachToggle",
489
+ onClick: this.togglePViewList,
490
+ iconName: "ZD-GN-hideTab",
491
+ iconSize: "14",
492
+ hoverType: "border",
493
+ iconClass: `${style.thumpIcon} ${isPViewListOpen ? style.thumpIconActive : ""}`,
494
+ className: style.button,
495
+ a11y: {
496
+ ariaLabel: i18nKeys.hideText
497
+ },
498
+ title: isPViewListOpen ? i18nKeys.hideText : i18nKeys.showText
499
+ }));
500
+ }));
501
+ }
502
+
503
+ }
504
+ AttachmentViewer.propTypes = {
505
+ hideAttachmentViewer: PropTypes.func,
506
+ i18nKeys: PropTypes.shape({
507
+ nextText: PropTypes.string,
508
+ previousText: PropTypes.string,
509
+ zoomOutText: PropTypes.string,
510
+ zoomInText: PropTypes.string,
511
+ newTabText: PropTypes.string,
512
+ downloadText: PropTypes.string,
513
+ closeText: PropTypes.string,
514
+ hideText: PropTypes.string,
515
+ showText: PropTypes.string
516
+ }),
517
+ needDownload: PropTypes.string,
518
+ previewObj: PropTypes.object,
519
+ responsiveId: PropTypes.string,
520
+ maintainZoom: PropTypes.bool,
521
+ isActive: PropTypes.bool
522
+ };
523
+ AttachmentViewer.defaultProps = {
524
+ responsiveId: "Helmet",
525
+ needDownload: true,
526
+ i18nKeys: {},
527
+ maintainZoom: false,
528
+ isActive: false
529
+ };
530
+
531
+ if (false) {
532
+ AttachmentViewer.docs = {
533
+ componentGroup: "Molecule"
534
+ };
535
+ }