vgapp 1.3.0 → 1.3.1
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/README.md +133 -133
- package/app/langs/en/buttons.json +17 -17
- package/app/langs/en/messages.json +36 -36
- package/app/langs/ru/buttons.json +17 -17
- package/app/langs/ru/messages.json +36 -36
- package/app/modules/base-module.js +111 -111
- package/app/modules/vgalert/readme.md +105 -105
- package/app/modules/vgdynamictable/index.js +5 -5
- package/app/modules/vgdynamictable/js/editable.js +19 -19
- package/app/modules/vgdynamictable/js/filters.js +21 -21
- package/app/modules/vgdynamictable/js/fixed.js +179 -179
- package/app/modules/vgdynamictable/js/pagination.js +1 -1
- package/app/modules/vgdynamictable/js/search.js +12 -12
- package/app/modules/vgdynamictable/js/sortable.js +71 -71
- package/app/modules/vgdynamictable/js/summary-footer.js +28 -28
- package/app/modules/vgdynamictable/js/table-remote.js +79 -79
- package/app/modules/vgdynamictable/js/table-url-state.js +31 -31
- package/app/modules/vgdynamictable/js/utils/common.js +48 -48
- package/app/modules/vgdynamictable/js/vgdynamictable.js +268 -268
- package/app/modules/vgdynamictable/readme.md +250 -250
- package/app/modules/vgdynamictable/scss/_skeleton.scss +6 -6
- package/app/modules/vgdynamictable/scss/_sortable.scss +24 -24
- package/app/modules/vgdynamictable/scss/_table.scss +4 -4
- package/app/modules/vgdynamictable/scss/_variables.scss +79 -79
- package/app/modules/vgdynamictable/scss/vgdynamictable.scss +27 -27
- package/app/modules/vgfilepreview/js/i18n.js +56 -56
- package/app/modules/vgfilepreview/js/renderers/image-modal.js +145 -145
- package/app/modules/vgfilepreview/js/renderers/image.js +92 -92
- package/app/modules/vgfilepreview/js/renderers/index.js +19 -19
- package/app/modules/vgfilepreview/js/renderers/office-modal.js +168 -168
- package/app/modules/vgfilepreview/js/renderers/office.js +79 -79
- package/app/modules/vgfilepreview/js/renderers/pdf-modal.js +260 -260
- package/app/modules/vgfilepreview/js/renderers/pdf.js +76 -76
- package/app/modules/vgfilepreview/js/renderers/playlist.js +71 -71
- package/app/modules/vgfilepreview/js/renderers/text-modal.js +343 -343
- package/app/modules/vgfilepreview/js/renderers/text.js +83 -83
- package/app/modules/vgfilepreview/js/renderers/video-modal.js +272 -272
- package/app/modules/vgfilepreview/js/renderers/video.js +80 -80
- package/app/modules/vgfilepreview/js/renderers/zip-modal.js +522 -522
- package/app/modules/vgfilepreview/js/renderers/zip.js +89 -89
- package/app/modules/vgfilepreview/js/vgfilepreview.js +7 -7
- package/app/modules/vgfilepreview/readme.md +68 -68
- package/app/modules/vgfilepreview/scss/_variables.scss +113 -113
- package/app/modules/vgfilepreview/scss/vgfilepreview.scss +464 -464
- package/app/modules/vgfiles/js/base.js +26 -26
- package/app/modules/vgfiles/js/droppable.js +260 -260
- package/app/modules/vgfiles/js/render.js +153 -153
- package/app/modules/vgfiles/js/vgfiles.js +104 -104
- package/app/modules/vgfiles/readme.md +123 -123
- package/app/modules/vgfiles/scss/_variables.scss +18 -18
- package/app/modules/vgfiles/scss/vgfiles.scss +148 -148
- package/app/modules/vgformsender/js/hideshowpass.js +16 -16
- package/app/modules/vgformsender/scss/vgformsender.scss +34 -34
- package/app/modules/vgmodal/js/vgmodal.drag.js +332 -332
- package/app/modules/vgmodal/js/vgmodal.js +188 -188
- package/app/modules/vgmodal/js/vgmodal.resize.js +27 -27
- package/app/modules/vgmodal/scss/vgmodal.scss +14 -14
- package/app/modules/vgnav/js/vgnav.js +135 -135
- package/app/modules/vgnav/readme.md +67 -67
- package/app/modules/vgnestable/README.md +307 -307
- package/app/modules/vgnestable/scss/_variables.scss +60 -60
- package/app/modules/vgnestable/scss/vgnestable.scss +163 -163
- package/app/modules/vgrangeslider/js/skins.js +222 -222
- package/app/modules/vgrangeslider/js/vgrangeslider.js +704 -704
- package/app/modules/vgrangeslider/readme.md +523 -523
- package/app/modules/vgrangeslider/scss/_variables.scss +53 -53
- package/app/modules/vgrangeslider/scss/vgrangeslider.scss +240 -240
- package/app/modules/vgselect/js/vgselect.js +39 -39
- package/app/modules/vgselect/scss/vgselect.scss +22 -22
- package/app/modules/vgspy/readme.md +28 -28
- package/app/modules/vgtoast/readme.md +18 -18
- package/app/modules/vgtoast/scss/vgtoast.scss +48 -48
- package/app/modules/vgtooltip/js/vgtooltip.js +89 -89
- package/app/modules/vgtooltip/readme.md +181 -181
- package/app/utils/js/components/ajax.js +117 -117
- package/app/utils/js/components/audio-metadata.js +240 -240
- package/app/utils/js/components/backdrop.js +17 -17
- package/app/utils/js/components/file-icon.js +109 -109
- package/app/utils/js/components/file-preview.js +304 -304
- package/app/utils/js/components/sanitize.js +150 -150
- package/app/utils/js/components/video-metadata.js +140 -140
- package/app/vgapp.js +130 -107
- package/build/vgapp.css +2 -2
- package/build/vgapp.js +2 -2
- package/build/vgapp.js.LICENSE.txt +1 -1
- package/build/vgapp.js.map +1 -1
- package/index.js +14 -14
- package/package.json +1 -1
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import ImageModal from "./image-modal";
|
|
2
|
-
|
|
3
|
-
const IMAGE_EXTENSIONS = new Set([
|
|
4
|
-
'.png',
|
|
5
|
-
'.jpg',
|
|
6
|
-
'.jpeg',
|
|
7
|
-
'.gif',
|
|
8
|
-
'.webp',
|
|
9
|
-
'.svg',
|
|
10
|
-
'.bmp',
|
|
11
|
-
'.tif',
|
|
12
|
-
'.tiff',
|
|
13
|
-
'.heic',
|
|
14
|
-
'.heif',
|
|
15
|
-
'.avif'
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
class ImageFilePreviewRenderer {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.name = 'image';
|
|
21
|
-
this._modal = ImageModal.getInstance();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
canRender(context = {}) {
|
|
25
|
-
const ext = String(context?.fileMeta?.ext || '').toLowerCase();
|
|
26
|
-
return IMAGE_EXTENSIONS.has(ext);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
render(context = {}) {
|
|
30
|
-
const container = context?.previewContainer;
|
|
31
|
-
const nameOnly = Boolean(context?.ui?.nameOnly);
|
|
32
|
-
const i18n = context?.i18n;
|
|
33
|
-
|
|
34
|
-
const src = context?.fileUrl?.href || context?.filePath || '';
|
|
35
|
-
if (!src) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const openImage = (event) => {
|
|
40
|
-
if (event) {
|
|
41
|
-
event.preventDefault();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this._modal.open({
|
|
45
|
-
src,
|
|
46
|
-
title: context?.fileMeta?.name || i18n?.message('image_title') || '',
|
|
47
|
-
defaultTitle: i18n?.message('image_title') || ''
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const titleLink = context?.element?.querySelector('.name');
|
|
52
|
-
if (titleLink && !titleLink.hasAttribute('data-vg-filepreview-image-bind')) {
|
|
53
|
-
titleLink.setAttribute('data-vg-filepreview-image-bind', 'true');
|
|
54
|
-
titleLink.classList.add('is-preview-action');
|
|
55
|
-
titleLink.addEventListener('click', openImage);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const listImage = context?.element?.closest('.file')?.querySelector('.file-image .file-preview');
|
|
59
|
-
if (listImage && !listImage.hasAttribute('data-vg-filepreview-image-bind')) {
|
|
60
|
-
listImage.setAttribute('data-vg-filepreview-image-bind', 'true');
|
|
61
|
-
listImage.classList.add('is-preview-action');
|
|
62
|
-
listImage.addEventListener('click', openImage);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (nameOnly) {
|
|
66
|
-
return Boolean(titleLink || listImage);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!container) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const trigger = document.createElement('button');
|
|
74
|
-
trigger.type = 'button';
|
|
75
|
-
trigger.className = 'vg-filepreview-image-trigger';
|
|
76
|
-
trigger.textContent = i18n?.button('open_image') || '';
|
|
77
|
-
trigger.addEventListener('click', openImage);
|
|
78
|
-
container.appendChild(trigger);
|
|
79
|
-
|
|
80
|
-
const thumbnail = document.createElement('img');
|
|
81
|
-
thumbnail.className = 'vg-filepreview-image-thumb';
|
|
82
|
-
thumbnail.src = src;
|
|
83
|
-
thumbnail.alt = context?.fileMeta?.name || i18n?.message('image_thumbnail_alt') || '';
|
|
84
|
-
thumbnail.loading = 'lazy';
|
|
85
|
-
thumbnail.addEventListener('click', openImage);
|
|
86
|
-
container.appendChild(thumbnail);
|
|
87
|
-
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export default ImageFilePreviewRenderer;
|
|
1
|
+
import ImageModal from "./image-modal";
|
|
2
|
+
|
|
3
|
+
const IMAGE_EXTENSIONS = new Set([
|
|
4
|
+
'.png',
|
|
5
|
+
'.jpg',
|
|
6
|
+
'.jpeg',
|
|
7
|
+
'.gif',
|
|
8
|
+
'.webp',
|
|
9
|
+
'.svg',
|
|
10
|
+
'.bmp',
|
|
11
|
+
'.tif',
|
|
12
|
+
'.tiff',
|
|
13
|
+
'.heic',
|
|
14
|
+
'.heif',
|
|
15
|
+
'.avif'
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
class ImageFilePreviewRenderer {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.name = 'image';
|
|
21
|
+
this._modal = ImageModal.getInstance();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
canRender(context = {}) {
|
|
25
|
+
const ext = String(context?.fileMeta?.ext || '').toLowerCase();
|
|
26
|
+
return IMAGE_EXTENSIONS.has(ext);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
render(context = {}) {
|
|
30
|
+
const container = context?.previewContainer;
|
|
31
|
+
const nameOnly = Boolean(context?.ui?.nameOnly);
|
|
32
|
+
const i18n = context?.i18n;
|
|
33
|
+
|
|
34
|
+
const src = context?.fileUrl?.href || context?.filePath || '';
|
|
35
|
+
if (!src) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const openImage = (event) => {
|
|
40
|
+
if (event) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this._modal.open({
|
|
45
|
+
src,
|
|
46
|
+
title: context?.fileMeta?.name || i18n?.message('image_title') || '',
|
|
47
|
+
defaultTitle: i18n?.message('image_title') || ''
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const titleLink = context?.element?.querySelector('.name');
|
|
52
|
+
if (titleLink && !titleLink.hasAttribute('data-vg-filepreview-image-bind')) {
|
|
53
|
+
titleLink.setAttribute('data-vg-filepreview-image-bind', 'true');
|
|
54
|
+
titleLink.classList.add('is-preview-action');
|
|
55
|
+
titleLink.addEventListener('click', openImage);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const listImage = context?.element?.closest('.file')?.querySelector('.file-image .file-preview');
|
|
59
|
+
if (listImage && !listImage.hasAttribute('data-vg-filepreview-image-bind')) {
|
|
60
|
+
listImage.setAttribute('data-vg-filepreview-image-bind', 'true');
|
|
61
|
+
listImage.classList.add('is-preview-action');
|
|
62
|
+
listImage.addEventListener('click', openImage);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (nameOnly) {
|
|
66
|
+
return Boolean(titleLink || listImage);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!container) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const trigger = document.createElement('button');
|
|
74
|
+
trigger.type = 'button';
|
|
75
|
+
trigger.className = 'vg-filepreview-image-trigger';
|
|
76
|
+
trigger.textContent = i18n?.button('open_image') || '';
|
|
77
|
+
trigger.addEventListener('click', openImage);
|
|
78
|
+
container.appendChild(trigger);
|
|
79
|
+
|
|
80
|
+
const thumbnail = document.createElement('img');
|
|
81
|
+
thumbnail.className = 'vg-filepreview-image-thumb';
|
|
82
|
+
thumbnail.src = src;
|
|
83
|
+
thumbnail.alt = context?.fileMeta?.name || i18n?.message('image_thumbnail_alt') || '';
|
|
84
|
+
thumbnail.loading = 'lazy';
|
|
85
|
+
thumbnail.addEventListener('click', openImage);
|
|
86
|
+
container.appendChild(thumbnail);
|
|
87
|
+
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default ImageFilePreviewRenderer;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import ImageFilePreviewRenderer from "./image";
|
|
2
|
-
import OfficeFilePreviewRenderer from "./office";
|
|
3
|
-
import PdfFilePreviewRenderer from "./pdf";
|
|
4
|
-
import TextFilePreviewRenderer from "./text";
|
|
5
|
-
import VideoFilePreviewRenderer from "./video";
|
|
6
|
-
import ZipFilePreviewRenderer from "./zip";
|
|
7
|
-
|
|
8
|
-
const createFilePreviewRenderers = () => {
|
|
9
|
-
return [
|
|
10
|
-
new ImageFilePreviewRenderer(),
|
|
11
|
-
new VideoFilePreviewRenderer(),
|
|
12
|
-
new PdfFilePreviewRenderer(),
|
|
13
|
-
new OfficeFilePreviewRenderer(),
|
|
14
|
-
new ZipFilePreviewRenderer(),
|
|
15
|
-
new TextFilePreviewRenderer()
|
|
16
|
-
];
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default createFilePreviewRenderers;
|
|
1
|
+
import ImageFilePreviewRenderer from "./image";
|
|
2
|
+
import OfficeFilePreviewRenderer from "./office";
|
|
3
|
+
import PdfFilePreviewRenderer from "./pdf";
|
|
4
|
+
import TextFilePreviewRenderer from "./text";
|
|
5
|
+
import VideoFilePreviewRenderer from "./video";
|
|
6
|
+
import ZipFilePreviewRenderer from "./zip";
|
|
7
|
+
|
|
8
|
+
const createFilePreviewRenderers = () => {
|
|
9
|
+
return [
|
|
10
|
+
new ImageFilePreviewRenderer(),
|
|
11
|
+
new VideoFilePreviewRenderer(),
|
|
12
|
+
new PdfFilePreviewRenderer(),
|
|
13
|
+
new OfficeFilePreviewRenderer(),
|
|
14
|
+
new ZipFilePreviewRenderer(),
|
|
15
|
+
new TextFilePreviewRenderer()
|
|
16
|
+
];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default createFilePreviewRenderers;
|
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
import VGModal from "../../../vgmodal";
|
|
2
|
-
|
|
3
|
-
class OfficeModal {
|
|
4
|
-
constructor() {
|
|
5
|
-
this._modalId = 'vg-filepreview-office-modal';
|
|
6
|
-
this._labels = {};
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
static getInstance() {
|
|
10
|
-
if (!OfficeModal._instance) {
|
|
11
|
-
OfficeModal._instance = new OfficeModal();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return OfficeModal._instance;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
open(payload = {}) {
|
|
18
|
-
const src = String(payload.src || '').trim();
|
|
19
|
-
if (!src) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this._ensureModal();
|
|
24
|
-
if (!this._modal || !this._frame) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
this._labels = payload?.labels && typeof payload.labels === 'object' ? payload.labels : {};
|
|
29
|
-
this._src = src;
|
|
30
|
-
this._downloadName = String(payload.downloadName || '').trim();
|
|
31
|
-
|
|
32
|
-
const defaultTitle = String(payload.defaultTitle || '').trim();
|
|
33
|
-
const title = String(payload.title || '').trim();
|
|
34
|
-
this._title.textContent = title || defaultTitle;
|
|
35
|
-
this._fallback.textContent = this._label('fallback');
|
|
36
|
-
this._download.textContent = this._label('download');
|
|
37
|
-
|
|
38
|
-
this._frame.src = this._buildViewerUrl(src);
|
|
39
|
-
this._modal.show();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
_ensureModal() {
|
|
43
|
-
if (this._modal && this._root) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
this._initModal();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_initModal() {
|
|
50
|
-
const params = {
|
|
51
|
-
centered: true,
|
|
52
|
-
dismiss: true,
|
|
53
|
-
backdrop: true,
|
|
54
|
-
keyboard: true,
|
|
55
|
-
sizes: {
|
|
56
|
-
width: 'fit-content',
|
|
57
|
-
},
|
|
58
|
-
animation: {
|
|
59
|
-
enable: false
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
this._modal = VGModal.build(this._modalId, params, (modalInstance) => {
|
|
64
|
-
const element = modalInstance._element;
|
|
65
|
-
this._root = element;
|
|
66
|
-
element.classList.add('vg-filepreview-office-modal');
|
|
67
|
-
|
|
68
|
-
const body = element.querySelector('.vg-modal-body');
|
|
69
|
-
const content = element.querySelector('.vg-modal-content');
|
|
70
|
-
if (!body || !content) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
body.classList.add('vg-filepreview-image-modal__body');
|
|
75
|
-
body.innerHTML = '';
|
|
76
|
-
|
|
77
|
-
let header = element.querySelector('.vg-modal-header');
|
|
78
|
-
if (!header) {
|
|
79
|
-
header = document.createElement('div');
|
|
80
|
-
header.className = 'vg-modal-header';
|
|
81
|
-
content.prepend(header);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
this._title = document.createElement('div');
|
|
85
|
-
this._title.className = 'vg-modal-title';
|
|
86
|
-
|
|
87
|
-
this._frame = document.createElement('iframe');
|
|
88
|
-
this._frame.className = 'vg-filepreview-office-modal__frame';
|
|
89
|
-
this._frame.setAttribute('title', 'Office preview');
|
|
90
|
-
|
|
91
|
-
const footer = document.createElement('div');
|
|
92
|
-
footer.className = 'vg-filepreview-office-modal__footer';
|
|
93
|
-
|
|
94
|
-
this._fallback = document.createElement('span');
|
|
95
|
-
this._fallback.className = 'vg-filepreview-office-modal__hint';
|
|
96
|
-
|
|
97
|
-
this._download = document.createElement('button');
|
|
98
|
-
this._download.type = 'button';
|
|
99
|
-
this._download.className = 'vg-filepreview-office-modal__btn';
|
|
100
|
-
this._download.addEventListener('click', () => this._downloadFile());
|
|
101
|
-
|
|
102
|
-
footer.appendChild(this._fallback);
|
|
103
|
-
footer.appendChild(this._download);
|
|
104
|
-
|
|
105
|
-
header.appendChild(this._title);
|
|
106
|
-
body.appendChild(this._frame);
|
|
107
|
-
content.appendChild(footer);
|
|
108
|
-
|
|
109
|
-
this._bindLifecycle(element);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
_buildViewerUrl(src) {
|
|
114
|
-
const absolute = new URL(src, window.location.origin).href;
|
|
115
|
-
const viewerBase = 'https://view.officeapps.live.com/op/embed.aspx?src=';
|
|
116
|
-
return `${viewerBase}${encodeURIComponent(absolute)}`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
_downloadFile() {
|
|
120
|
-
if (!this._src) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const link = document.createElement('a');
|
|
125
|
-
link.href = this._src;
|
|
126
|
-
if (this._downloadName) {
|
|
127
|
-
link.setAttribute('download', this._downloadName);
|
|
128
|
-
}
|
|
129
|
-
link.style.display = 'none';
|
|
130
|
-
document.body.appendChild(link);
|
|
131
|
-
link.click();
|
|
132
|
-
document.body.removeChild(link);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
_label(key) {
|
|
136
|
-
const value = this._labels?.[key];
|
|
137
|
-
return String(value || '').trim();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
_bindLifecycle(root) {
|
|
141
|
-
if (!root || root.hasAttribute('data-vg-filepreview-office-lifecycle-bind')) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
root.setAttribute('data-vg-filepreview-office-lifecycle-bind', 'true');
|
|
145
|
-
root.addEventListener('vg.modal.hidden', () => this._destroyModal());
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
_destroyModal() {
|
|
149
|
-
if (this._modal && typeof this._modal.dispose === 'function') {
|
|
150
|
-
this._modal.dispose();
|
|
151
|
-
}
|
|
152
|
-
if (this._root && this._root.parentNode) {
|
|
153
|
-
this._root.parentNode.removeChild(this._root);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
this._root = null;
|
|
157
|
-
this._modal = null;
|
|
158
|
-
this._title = null;
|
|
159
|
-
this._frame = null;
|
|
160
|
-
this._fallback = null;
|
|
161
|
-
this._download = null;
|
|
162
|
-
this._labels = null;
|
|
163
|
-
this._src = '';
|
|
164
|
-
this._downloadName = '';
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export default OfficeModal;
|
|
1
|
+
import VGModal from "../../../vgmodal";
|
|
2
|
+
|
|
3
|
+
class OfficeModal {
|
|
4
|
+
constructor() {
|
|
5
|
+
this._modalId = 'vg-filepreview-office-modal';
|
|
6
|
+
this._labels = {};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static getInstance() {
|
|
10
|
+
if (!OfficeModal._instance) {
|
|
11
|
+
OfficeModal._instance = new OfficeModal();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return OfficeModal._instance;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
open(payload = {}) {
|
|
18
|
+
const src = String(payload.src || '').trim();
|
|
19
|
+
if (!src) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this._ensureModal();
|
|
24
|
+
if (!this._modal || !this._frame) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this._labels = payload?.labels && typeof payload.labels === 'object' ? payload.labels : {};
|
|
29
|
+
this._src = src;
|
|
30
|
+
this._downloadName = String(payload.downloadName || '').trim();
|
|
31
|
+
|
|
32
|
+
const defaultTitle = String(payload.defaultTitle || '').trim();
|
|
33
|
+
const title = String(payload.title || '').trim();
|
|
34
|
+
this._title.textContent = title || defaultTitle;
|
|
35
|
+
this._fallback.textContent = this._label('fallback');
|
|
36
|
+
this._download.textContent = this._label('download');
|
|
37
|
+
|
|
38
|
+
this._frame.src = this._buildViewerUrl(src);
|
|
39
|
+
this._modal.show();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_ensureModal() {
|
|
43
|
+
if (this._modal && this._root) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this._initModal();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
_initModal() {
|
|
50
|
+
const params = {
|
|
51
|
+
centered: true,
|
|
52
|
+
dismiss: true,
|
|
53
|
+
backdrop: true,
|
|
54
|
+
keyboard: true,
|
|
55
|
+
sizes: {
|
|
56
|
+
width: 'fit-content',
|
|
57
|
+
},
|
|
58
|
+
animation: {
|
|
59
|
+
enable: false
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
this._modal = VGModal.build(this._modalId, params, (modalInstance) => {
|
|
64
|
+
const element = modalInstance._element;
|
|
65
|
+
this._root = element;
|
|
66
|
+
element.classList.add('vg-filepreview-office-modal');
|
|
67
|
+
|
|
68
|
+
const body = element.querySelector('.vg-modal-body');
|
|
69
|
+
const content = element.querySelector('.vg-modal-content');
|
|
70
|
+
if (!body || !content) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
body.classList.add('vg-filepreview-image-modal__body');
|
|
75
|
+
body.innerHTML = '';
|
|
76
|
+
|
|
77
|
+
let header = element.querySelector('.vg-modal-header');
|
|
78
|
+
if (!header) {
|
|
79
|
+
header = document.createElement('div');
|
|
80
|
+
header.className = 'vg-modal-header';
|
|
81
|
+
content.prepend(header);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this._title = document.createElement('div');
|
|
85
|
+
this._title.className = 'vg-modal-title';
|
|
86
|
+
|
|
87
|
+
this._frame = document.createElement('iframe');
|
|
88
|
+
this._frame.className = 'vg-filepreview-office-modal__frame';
|
|
89
|
+
this._frame.setAttribute('title', 'Office preview');
|
|
90
|
+
|
|
91
|
+
const footer = document.createElement('div');
|
|
92
|
+
footer.className = 'vg-filepreview-office-modal__footer';
|
|
93
|
+
|
|
94
|
+
this._fallback = document.createElement('span');
|
|
95
|
+
this._fallback.className = 'vg-filepreview-office-modal__hint';
|
|
96
|
+
|
|
97
|
+
this._download = document.createElement('button');
|
|
98
|
+
this._download.type = 'button';
|
|
99
|
+
this._download.className = 'vg-filepreview-office-modal__btn';
|
|
100
|
+
this._download.addEventListener('click', () => this._downloadFile());
|
|
101
|
+
|
|
102
|
+
footer.appendChild(this._fallback);
|
|
103
|
+
footer.appendChild(this._download);
|
|
104
|
+
|
|
105
|
+
header.appendChild(this._title);
|
|
106
|
+
body.appendChild(this._frame);
|
|
107
|
+
content.appendChild(footer);
|
|
108
|
+
|
|
109
|
+
this._bindLifecycle(element);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_buildViewerUrl(src) {
|
|
114
|
+
const absolute = new URL(src, window.location.origin).href;
|
|
115
|
+
const viewerBase = 'https://view.officeapps.live.com/op/embed.aspx?src=';
|
|
116
|
+
return `${viewerBase}${encodeURIComponent(absolute)}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_downloadFile() {
|
|
120
|
+
if (!this._src) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const link = document.createElement('a');
|
|
125
|
+
link.href = this._src;
|
|
126
|
+
if (this._downloadName) {
|
|
127
|
+
link.setAttribute('download', this._downloadName);
|
|
128
|
+
}
|
|
129
|
+
link.style.display = 'none';
|
|
130
|
+
document.body.appendChild(link);
|
|
131
|
+
link.click();
|
|
132
|
+
document.body.removeChild(link);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_label(key) {
|
|
136
|
+
const value = this._labels?.[key];
|
|
137
|
+
return String(value || '').trim();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
_bindLifecycle(root) {
|
|
141
|
+
if (!root || root.hasAttribute('data-vg-filepreview-office-lifecycle-bind')) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
root.setAttribute('data-vg-filepreview-office-lifecycle-bind', 'true');
|
|
145
|
+
root.addEventListener('vg.modal.hidden', () => this._destroyModal());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_destroyModal() {
|
|
149
|
+
if (this._modal && typeof this._modal.dispose === 'function') {
|
|
150
|
+
this._modal.dispose();
|
|
151
|
+
}
|
|
152
|
+
if (this._root && this._root.parentNode) {
|
|
153
|
+
this._root.parentNode.removeChild(this._root);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this._root = null;
|
|
157
|
+
this._modal = null;
|
|
158
|
+
this._title = null;
|
|
159
|
+
this._frame = null;
|
|
160
|
+
this._fallback = null;
|
|
161
|
+
this._download = null;
|
|
162
|
+
this._labels = null;
|
|
163
|
+
this._src = '';
|
|
164
|
+
this._downloadName = '';
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export default OfficeModal;
|