@bigbinary/neeto-editor-frontend 0.0.0-stage → 2.0.2
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/LICENSE.md +21 -0
- package/README.md +145 -2
- package/app/javascript/src/translations/ar.json +209 -0
- package/app/javascript/src/translations/bg.json +209 -0
- package/app/javascript/src/translations/ca.json +209 -0
- package/app/javascript/src/translations/cs.json +209 -0
- package/app/javascript/src/translations/da.json +209 -0
- package/app/javascript/src/translations/de.json +209 -0
- package/app/javascript/src/translations/en.json +208 -0
- package/app/javascript/src/translations/es-MX.json +209 -0
- package/app/javascript/src/translations/es.json +209 -0
- package/app/javascript/src/translations/et.json +209 -0
- package/app/javascript/src/translations/fi.json +209 -0
- package/app/javascript/src/translations/fil.json +209 -0
- package/app/javascript/src/translations/fr.json +209 -0
- package/app/javascript/src/translations/he.json +209 -0
- package/app/javascript/src/translations/hi.json +209 -0
- package/app/javascript/src/translations/hr.json +209 -0
- package/app/javascript/src/translations/hu.json +209 -0
- package/app/javascript/src/translations/id.json +209 -0
- package/app/javascript/src/translations/index.js +1 -0
- package/app/javascript/src/translations/it.json +209 -0
- package/app/javascript/src/translations/ja.json +209 -0
- package/app/javascript/src/translations/ko.json +209 -0
- package/app/javascript/src/translations/lv.json +208 -0
- package/app/javascript/src/translations/nl.json +209 -0
- package/app/javascript/src/translations/pl.json +209 -0
- package/app/javascript/src/translations/pt-BR.json +209 -0
- package/app/javascript/src/translations/pt.json +209 -0
- package/app/javascript/src/translations/ro.json +209 -0
- package/app/javascript/src/translations/ru.json +209 -0
- package/app/javascript/src/translations/sk.json +209 -0
- package/app/javascript/src/translations/sl.json +209 -0
- package/app/javascript/src/translations/sv.json +209 -0
- package/app/javascript/src/translations/th.json +209 -0
- package/app/javascript/src/translations/tr.json +209 -0
- package/app/javascript/src/translations/uk.json +209 -0
- package/app/javascript/src/translations/vi.json +209 -0
- package/app/javascript/src/translations/zh-CN.json +209 -0
- package/app/javascript/src/translations/zh-TW.json +209 -0
- package/dist/.ready +1 -0
- package/dist/Attachments.js +53 -0
- package/dist/Attachments.js.map +1 -0
- package/dist/Editor.js +5532 -0
- package/dist/Editor.js.map +1 -0
- package/dist/EditorContent.js +252 -0
- package/dist/EditorContent.js.map +1 -0
- package/dist/FormikEditor.js +202 -0
- package/dist/FormikEditor.js.map +1 -0
- package/dist/Menu.js +107 -0
- package/dist/Menu.js.map +1 -0
- package/dist/chunk-1NlIGj6C.js +378 -0
- package/dist/chunk-1NlIGj6C.js.map +1 -0
- package/dist/chunk-BFKmIsWV.js +8660 -0
- package/dist/chunk-BFKmIsWV.js.map +1 -0
- package/dist/chunk-BFTU3MAI.js +8 -0
- package/dist/chunk-BFTU3MAI.js.map +1 -0
- package/dist/chunk-Ba4Q3HC8.js +15258 -0
- package/dist/chunk-Ba4Q3HC8.js.map +1 -0
- package/dist/chunk-Bra5VPWO.js +555 -0
- package/dist/chunk-Bra5VPWO.js.map +1 -0
- package/dist/chunk-C2dztUxs.js +4 -0
- package/dist/chunk-C2dztUxs.js.map +1 -0
- package/dist/chunk-CK_Ss-J5.js +425 -0
- package/dist/chunk-CK_Ss-J5.js.map +1 -0
- package/dist/chunk-CO-Yfs5R.js +206 -0
- package/dist/chunk-CO-Yfs5R.js.map +1 -0
- package/dist/chunk-CX-0IHKE.js +381 -0
- package/dist/chunk-CX-0IHKE.js.map +1 -0
- package/dist/chunk-CeoqieEt.js +25570 -0
- package/dist/chunk-CeoqieEt.js.map +1 -0
- package/dist/chunk-D52F37yF.js +19 -0
- package/dist/chunk-D52F37yF.js.map +1 -0
- package/dist/chunk-DcFvJOrc.js +3368 -0
- package/dist/chunk-DcFvJOrc.js.map +1 -0
- package/dist/chunk-DgZGzqPs.js +6804 -0
- package/dist/chunk-DgZGzqPs.js.map +1 -0
- package/dist/chunk-Di3ipdfT.js +20227 -0
- package/dist/chunk-Di3ipdfT.js.map +1 -0
- package/dist/chunk-DrHVV_g1.js +89 -0
- package/dist/chunk-DrHVV_g1.js.map +1 -0
- package/dist/chunk-DsAUS6bL.js +3464 -0
- package/dist/chunk-DsAUS6bL.js.map +1 -0
- package/dist/chunk-PSGRE5nX.js +97 -0
- package/dist/chunk-PSGRE5nX.js.map +1 -0
- package/dist/chunk-Qg4uQqj3.js +16238 -0
- package/dist/chunk-Qg4uQqj3.js.map +1 -0
- package/dist/chunk-aCTMceVU.js +135 -0
- package/dist/chunk-aCTMceVU.js.map +1 -0
- package/dist/chunk-fDmcpgqx.js +12510 -0
- package/dist/chunk-fDmcpgqx.js.map +1 -0
- package/dist/chunk-mFZL53CS.js +204 -0
- package/dist/chunk-mFZL53CS.js.map +1 -0
- package/dist/chunk-y5pmJStT.js +573 -0
- package/dist/chunk-y5pmJStT.js.map +1 -0
- package/dist/cjs/Attachments.cjs.js +59 -0
- package/dist/cjs/Attachments.cjs.js.map +1 -0
- package/dist/cjs/Editor.cjs.js +5611 -0
- package/dist/cjs/Editor.cjs.js.map +1 -0
- package/dist/cjs/EditorContent.cjs.js +266 -0
- package/dist/cjs/EditorContent.cjs.js.map +1 -0
- package/dist/cjs/FormikEditor.cjs.js +209 -0
- package/dist/cjs/FormikEditor.cjs.js.map +1 -0
- package/dist/cjs/Menu.cjs.js +113 -0
- package/dist/cjs/Menu.cjs.js.map +1 -0
- package/dist/cjs/chunk-B2NfgecV.cjs.js +599 -0
- package/dist/cjs/chunk-B2NfgecV.cjs.js.map +1 -0
- package/dist/cjs/chunk-B6qYtOJe.cjs.js +6 -0
- package/dist/cjs/chunk-B6qYtOJe.cjs.js.map +1 -0
- package/dist/cjs/chunk-BJu3ubxk.cjs.js +11 -0
- package/dist/cjs/chunk-BJu3ubxk.cjs.js.map +1 -0
- package/dist/cjs/chunk-BKvkHB8E.cjs.js +16259 -0
- package/dist/cjs/chunk-BKvkHB8E.cjs.js.map +1 -0
- package/dist/cjs/chunk-BlWQNLLE.cjs.js +3450 -0
- package/dist/cjs/chunk-BlWQNLLE.cjs.js.map +1 -0
- package/dist/cjs/chunk-Bmjmsp-E.cjs.js +97 -0
- package/dist/cjs/chunk-Bmjmsp-E.cjs.js.map +1 -0
- package/dist/cjs/chunk-C-VxABfm.cjs.js +25578 -0
- package/dist/cjs/chunk-C-VxABfm.cjs.js.map +1 -0
- package/dist/cjs/chunk-C8X4oFtP.cjs.js +216 -0
- package/dist/cjs/chunk-C8X4oFtP.cjs.js.map +1 -0
- package/dist/cjs/chunk-CCCSexAh.cjs.js +206 -0
- package/dist/cjs/chunk-CCCSexAh.cjs.js.map +1 -0
- package/dist/cjs/chunk-CNIzgxEP.cjs.js +49 -0
- package/dist/cjs/chunk-CNIzgxEP.cjs.js.map +1 -0
- package/dist/cjs/chunk-CesnwG-V.cjs.js +140 -0
- package/dist/cjs/chunk-CesnwG-V.cjs.js.map +1 -0
- package/dist/cjs/chunk-CohcWDmm.cjs.js +20318 -0
- package/dist/cjs/chunk-CohcWDmm.cjs.js.map +1 -0
- package/dist/cjs/chunk-Crp27WMe.cjs.js +6833 -0
- package/dist/cjs/chunk-Crp27WMe.cjs.js.map +1 -0
- package/dist/cjs/chunk-D3Unocnm.cjs.js +8681 -0
- package/dist/cjs/chunk-D3Unocnm.cjs.js.map +1 -0
- package/dist/cjs/chunk-D6ygkQBu.cjs.js +421 -0
- package/dist/cjs/chunk-D6ygkQBu.cjs.js.map +1 -0
- package/dist/cjs/chunk-D7p10rIr.cjs.js +112 -0
- package/dist/cjs/chunk-D7p10rIr.cjs.js.map +1 -0
- package/dist/cjs/chunk-DM1lUvXy.cjs.js +3525 -0
- package/dist/cjs/chunk-DM1lUvXy.cjs.js.map +1 -0
- package/dist/cjs/chunk-DWyvxp1a.cjs.js +394 -0
- package/dist/cjs/chunk-DWyvxp1a.cjs.js.map +1 -0
- package/dist/cjs/chunk-DXsX8co9.cjs.js +12512 -0
- package/dist/cjs/chunk-DXsX8co9.cjs.js.map +1 -0
- package/dist/cjs/chunk-DxXc6tiG.cjs.js +15326 -0
- package/dist/cjs/chunk-DxXc6tiG.cjs.js.map +1 -0
- package/dist/cjs/chunk-MxWVMW6e.cjs.js +569 -0
- package/dist/cjs/chunk-MxWVMW6e.cjs.js.map +1 -0
- package/dist/cjs/chunk-cwORbcv3.cjs.js +479 -0
- package/dist/cjs/chunk-cwORbcv3.cjs.js.map +1 -0
- package/dist/cjs/constants.cjs.js +13 -0
- package/dist/cjs/constants.cjs.js.map +1 -0
- package/dist/cjs/index.cjs.js +163 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/utils.cjs.js +29 -0
- package/dist/cjs/utils.cjs.js.map +1 -0
- package/dist/cjs/v2/Attachments.cjs.js +49 -0
- package/dist/cjs/v2/Attachments.cjs.js.map +1 -0
- package/dist/cjs/v2/Editor.cjs.js +5741 -0
- package/dist/cjs/v2/Editor.cjs.js.map +1 -0
- package/dist/cjs/v2/EditorContent.cjs.js +33 -0
- package/dist/cjs/v2/EditorContent.cjs.js.map +1 -0
- package/dist/cjs/v2/FormikEditor.cjs.js +164 -0
- package/dist/cjs/v2/FormikEditor.cjs.js.map +1 -0
- package/dist/cjs/v2/Menu.cjs.js +62 -0
- package/dist/cjs/v2/Menu.cjs.js.map +1 -0
- package/dist/cjs/v2/constants.cjs.js +13 -0
- package/dist/cjs/v2/constants.cjs.js.map +1 -0
- package/dist/cjs/v2/index.cjs.js +120 -0
- package/dist/cjs/v2/index.cjs.js.map +1 -0
- package/dist/cjs/v2/utils.cjs.js +29 -0
- package/dist/cjs/v2/utils.cjs.js.map +1 -0
- package/dist/codeblockHighlight.js +15155 -0
- package/dist/codeblockHighlight.js.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/editor-content.min.css +1 -0
- package/dist/editor-output-pdf-email.css +1 -0
- package/dist/editor-output-pdf-email.js +4 -0
- package/dist/editor-output-pdf-email.js.map +1 -0
- package/dist/editor-output.js +4 -0
- package/dist/editor-output.js.map +1 -0
- package/dist/editor-stats.html +4842 -0
- package/dist/editorUtils.js +170 -0
- package/dist/headerLinks.js +59 -0
- package/dist/headerLinks.js.map +1 -0
- package/dist/index.js +146 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.js +17 -0
- package/dist/utils.js.map +1 -0
- package/dist/v2/Attachments.js +43 -0
- package/dist/v2/Attachments.js.map +1 -0
- package/dist/v2/Editor.js +5692 -0
- package/dist/v2/Editor.js.map +1 -0
- package/dist/v2/EditorContent.js +27 -0
- package/dist/v2/EditorContent.js.map +1 -0
- package/dist/v2/FormikEditor.js +157 -0
- package/dist/v2/FormikEditor.js.map +1 -0
- package/dist/v2/Menu.js +56 -0
- package/dist/v2/Menu.js.map +1 -0
- package/dist/v2/constants.js +6 -0
- package/dist/v2/constants.js.map +1 -0
- package/dist/v2/editor-content-styles.js +4 -0
- package/dist/v2/editor-content-styles.js.map +1 -0
- package/dist/v2/editor-content.min.css +1 -0
- package/dist/v2/index.js +101 -0
- package/dist/v2/index.js.map +1 -0
- package/dist/v2/styles.css +1 -0
- package/dist/v2/styles.js +4 -0
- package/dist/v2/styles.js.map +1 -0
- package/dist/v2/utils.js +17 -0
- package/dist/v2/utils.js.map +1 -0
- package/formik.d.ts +9 -0
- package/package.json +322 -4
- package/types.d.ts +199 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
import { findIndexBy, truncate } from '@bigbinary/neeto-cist';
|
|
3
|
+
import Left from '@bigbinary/neeto-icons/Left';
|
|
4
|
+
import Right from '@bigbinary/neeto-icons/Right';
|
|
5
|
+
import Modal from '@bigbinary/neetoui/Modal';
|
|
6
|
+
import Typography from '@bigbinary/neetoui/Typography';
|
|
7
|
+
import Button from '@bigbinary/neetoui/Button';
|
|
8
|
+
import { isEmpty } from 'ramda';
|
|
9
|
+
import { D as DocViewer, a as DocViewerRenderers } from './chunk-CeoqieEt.js';
|
|
10
|
+
import { useTranslation, Trans } from 'react-i18next';
|
|
11
|
+
import { c as convertToFileSize } from './chunk-CK_Ss-J5.js';
|
|
12
|
+
import { d as downloadFile, c as checkPreviewAvailability, a as ATTACHMENTS_PREVIEW_DATA_CY } from './chunk-y5pmJStT.js';
|
|
13
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
|
+
import './chunk-BFTU3MAI.js';
|
|
15
|
+
import '@babel/runtime/helpers/toConsumableArray';
|
|
16
|
+
import '@babel/runtime/helpers/slicedToArray';
|
|
17
|
+
import '@babel/runtime/helpers/objectWithoutProperties';
|
|
18
|
+
import '@babel/runtime/helpers/asyncToGenerator';
|
|
19
|
+
import '@babel/runtime/regenerator';
|
|
20
|
+
import 'zustand/shallow';
|
|
21
|
+
import 'axios';
|
|
22
|
+
import '@bigbinary/neetoui/Toastr';
|
|
23
|
+
import './chunk-BFKmIsWV.js';
|
|
24
|
+
import '@babel/runtime/helpers/defineProperty';
|
|
25
|
+
import '@bigbinary/neeto-commons-frontend/react-utils';
|
|
26
|
+
import 'zustand';
|
|
27
|
+
import '@babel/runtime/helpers/createClass';
|
|
28
|
+
import '@babel/runtime/helpers/classCallCheck';
|
|
29
|
+
import 'i18next';
|
|
30
|
+
import '@bigbinary/neeto-icons/LeftAlign';
|
|
31
|
+
import '@bigbinary/neeto-icons/CenterAlign';
|
|
32
|
+
import '@bigbinary/neeto-icons/RightAlign';
|
|
33
|
+
import '@bigbinary/neeto-icons/Delete';
|
|
34
|
+
import '@bigbinary/neeto-icons/CustomSize';
|
|
35
|
+
import '@bigbinary/neeto-icons/BorderDisable';
|
|
36
|
+
import '@bigbinary/neeto-icons/BorderEnable';
|
|
37
|
+
import '@bigbinary/neeto-icons/AspectRatio11';
|
|
38
|
+
import '@bigbinary/neeto-icons/AspectRatio169';
|
|
39
|
+
import '@bigbinary/neeto-icons/AspectRatio916';
|
|
40
|
+
import '@bigbinary/neeto-icons/AspectRatio43';
|
|
41
|
+
import '@bigbinary/neeto-icons/AspectRatio32';
|
|
42
|
+
import '@bigbinary/neeto-commons-frontend/initializers';
|
|
43
|
+
import 'yup';
|
|
44
|
+
import './chunk-DrHVV_g1.js';
|
|
45
|
+
import 'classnames';
|
|
46
|
+
import './chunk-C2dztUxs.js';
|
|
47
|
+
import '@bigbinary/neeto-commons-frontend/react-utils/useOnClickOutside';
|
|
48
|
+
import '@bigbinary/neeto-commons-frontend/utils';
|
|
49
|
+
import '@bigbinary/neeto-icons/MenuVertical';
|
|
50
|
+
import '@bigbinary/neeto-icons/Close';
|
|
51
|
+
import '@bigbinary/neeto-icons/Check';
|
|
52
|
+
import '@bigbinary/neetoui/Dropdown';
|
|
53
|
+
import '@bigbinary/neetoui/Input';
|
|
54
|
+
import '@bigbinary/neetoui/Spinner';
|
|
55
|
+
import '@bigbinary/neetoui/Tooltip';
|
|
56
|
+
import '@bigbinary/neetoui/Alert';
|
|
57
|
+
|
|
58
|
+
var Preview = function Preview(_ref) {
|
|
59
|
+
var onClose = _ref.onClose,
|
|
60
|
+
attachments = _ref.attachments,
|
|
61
|
+
selectedAttachment = _ref.selectedAttachment,
|
|
62
|
+
setSelectedAttachment = _ref.setSelectedAttachment,
|
|
63
|
+
setDidFetchPreviewBundle = _ref.setDidFetchPreviewBundle;
|
|
64
|
+
var _useTranslation = useTranslation(),
|
|
65
|
+
t = _useTranslation.t;
|
|
66
|
+
var downloadRef = useRef(null);
|
|
67
|
+
var _selectedAttachment$f = selectedAttachment.filename,
|
|
68
|
+
filename = _selectedAttachment$f === void 0 ? "" : _selectedAttachment$f,
|
|
69
|
+
_selectedAttachment$c = selectedAttachment.contentType,
|
|
70
|
+
contentType = _selectedAttachment$c === void 0 ? null : _selectedAttachment$c,
|
|
71
|
+
_selectedAttachment$u = selectedAttachment.url,
|
|
72
|
+
url = _selectedAttachment$u === void 0 ? "" : _selectedAttachment$u,
|
|
73
|
+
_selectedAttachment$s = selectedAttachment.signedId,
|
|
74
|
+
signedId = _selectedAttachment$s === void 0 ? "" : _selectedAttachment$s,
|
|
75
|
+
_selectedAttachment$s2 = selectedAttachment.size,
|
|
76
|
+
size = _selectedAttachment$s2 === void 0 ? undefined : _selectedAttachment$s2,
|
|
77
|
+
_selectedAttachment$p = selectedAttachment.previewUrl,
|
|
78
|
+
previewUrl = _selectedAttachment$p === void 0 ? null : _selectedAttachment$p;
|
|
79
|
+
var attachmentIndex = findIndexBy({
|
|
80
|
+
signedId: signedId
|
|
81
|
+
}, attachments);
|
|
82
|
+
var handleRightArrowClick = function handleRightArrowClick() {
|
|
83
|
+
var _downloadRef$current;
|
|
84
|
+
var newIndex = (attachmentIndex + 1) % attachments.length;
|
|
85
|
+
setSelectedAttachment(attachments[newIndex]);
|
|
86
|
+
(_downloadRef$current = downloadRef.current) === null || _downloadRef$current === void 0 || _downloadRef$current.focus();
|
|
87
|
+
};
|
|
88
|
+
var handleLeftArrowClick = function handleLeftArrowClick() {
|
|
89
|
+
var _downloadRef$current2;
|
|
90
|
+
var newIndex = (attachmentIndex - 1 + attachments.length) % attachments.length;
|
|
91
|
+
setSelectedAttachment(attachments[newIndex]);
|
|
92
|
+
(_downloadRef$current2 = downloadRef.current) === null || _downloadRef$current2 === void 0 || _downloadRef$current2.focus();
|
|
93
|
+
};
|
|
94
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
95
|
+
if (event.key === "ArrowRight") {
|
|
96
|
+
handleRightArrowClick();
|
|
97
|
+
} else if (event.key === "ArrowLeft") {
|
|
98
|
+
handleLeftArrowClick();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
useEffect(function () {
|
|
102
|
+
setDidFetchPreviewBundle(true);
|
|
103
|
+
}, []);
|
|
104
|
+
var handleDownload = function handleDownload() {
|
|
105
|
+
return downloadFile(url, filename);
|
|
106
|
+
};
|
|
107
|
+
var setPreview = function setPreview() {
|
|
108
|
+
var isPreviewAvailable = checkPreviewAvailability(contentType, previewUrl);
|
|
109
|
+
if (isPreviewAvailable) {
|
|
110
|
+
switch (contentType.split("/")[0]) {
|
|
111
|
+
case "image":
|
|
112
|
+
return /*#__PURE__*/jsx("img", {
|
|
113
|
+
"data-testid": ATTACHMENTS_PREVIEW_DATA_CY,
|
|
114
|
+
src: previewUrl || url
|
|
115
|
+
});
|
|
116
|
+
case "video":
|
|
117
|
+
return /*#__PURE__*/jsx("video", {
|
|
118
|
+
controls: true,
|
|
119
|
+
"data-testid": ATTACHMENTS_PREVIEW_DATA_CY,
|
|
120
|
+
src: url
|
|
121
|
+
});
|
|
122
|
+
case "application":
|
|
123
|
+
case "text":
|
|
124
|
+
if (contentType === "application/pdf") {
|
|
125
|
+
return /*#__PURE__*/jsx("iframe", {
|
|
126
|
+
"data-testid": ATTACHMENTS_PREVIEW_DATA_CY,
|
|
127
|
+
src: url,
|
|
128
|
+
width: "100%"
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return /*#__PURE__*/jsx(DocViewer, {
|
|
132
|
+
className: "ne-attachments-preview__body-docviewer",
|
|
133
|
+
"data-testid": ATTACHMENTS_PREVIEW_DATA_CY,
|
|
134
|
+
documents: [{
|
|
135
|
+
uri: url,
|
|
136
|
+
fileType: contentType
|
|
137
|
+
}],
|
|
138
|
+
pluginRenderers: DocViewerRenderers,
|
|
139
|
+
config: {
|
|
140
|
+
header: {
|
|
141
|
+
disableHeader: true,
|
|
142
|
+
disableFileName: true
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
default:
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
151
|
+
children: /*#__PURE__*/jsx(Trans, {
|
|
152
|
+
i18nKey: "neetoEditor.attachments.noPreview",
|
|
153
|
+
components: {
|
|
154
|
+
span: /*#__PURE__*/jsx("span", {
|
|
155
|
+
className: "ne-attachments-preview__body-download",
|
|
156
|
+
onClick: handleDownload
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
return /*#__PURE__*/jsxs(Modal, {
|
|
163
|
+
onClose: onClose,
|
|
164
|
+
className: "ne-attachments-preview",
|
|
165
|
+
isOpen: !isEmpty(selectedAttachment),
|
|
166
|
+
size: "fullScreen",
|
|
167
|
+
onKeyDown: handleKeyDown,
|
|
168
|
+
children: [/*#__PURE__*/jsxs(Modal.Header, {
|
|
169
|
+
className: "ne-attachments-preview__header",
|
|
170
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
171
|
+
className: "ne-attachments-preview__header__fileinfo",
|
|
172
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
173
|
+
style: "h4",
|
|
174
|
+
children: truncate(filename, 25)
|
|
175
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
176
|
+
style: "body2",
|
|
177
|
+
children: convertToFileSize(size)
|
|
178
|
+
})]
|
|
179
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
180
|
+
"data-testid": "download-preview-button",
|
|
181
|
+
label: t("neetoEditor.common.download"),
|
|
182
|
+
ref: downloadRef,
|
|
183
|
+
style: "link",
|
|
184
|
+
onClick: handleDownload
|
|
185
|
+
})]
|
|
186
|
+
}), /*#__PURE__*/jsxs(Modal.Body, {
|
|
187
|
+
className: "ne-attachments-preview__body",
|
|
188
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
189
|
+
className: "ne-attachments-preview__body-left",
|
|
190
|
+
icon: Left,
|
|
191
|
+
size: "large",
|
|
192
|
+
style: "tertiary",
|
|
193
|
+
onClick: handleLeftArrowClick
|
|
194
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
195
|
+
className: "ne-attachments-preview__body-right",
|
|
196
|
+
icon: Right,
|
|
197
|
+
size: "large",
|
|
198
|
+
style: "tertiary",
|
|
199
|
+
onClick: handleRightArrowClick
|
|
200
|
+
}), setPreview()]
|
|
201
|
+
})]
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export { Preview as default };
|
|
206
|
+
//# sourceMappingURL=chunk-CO-Yfs5R.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-CO-Yfs5R.js","sources":["../app/javascript/src/components/Attachments/Preview.jsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\nimport { findIndexBy, truncate } from \"neetocist\";\nimport { Left, Right } from \"neetoicons\";\nimport { Modal, Typography, Button } from \"neetoui\";\nimport { isEmpty } from \"ramda\";\nimport DocViewer, { DocViewerRenderers } from \"react-doc-viewer\";\nimport { Trans, useTranslation } from \"react-i18next\";\n\nimport { convertToFileSize } from \"components/Editor/MediaUploader/utils\";\n\nimport { ATTACHMENTS_PREVIEW_DATA_CY } from \"./constants\";\nimport { checkPreviewAvailability, downloadFile } from \"./utils\";\n\nconst Preview = ({\n onClose,\n attachments,\n selectedAttachment,\n setSelectedAttachment,\n setDidFetchPreviewBundle,\n}) => {\n const { t } = useTranslation();\n const downloadRef = useRef(null);\n\n const {\n filename = \"\",\n contentType = null,\n url = \"\",\n signedId = \"\",\n size = undefined,\n previewUrl = null,\n } = selectedAttachment;\n\n const attachmentIndex = findIndexBy({ signedId }, attachments);\n\n const handleRightArrowClick = () => {\n const newIndex = (attachmentIndex + 1) % attachments.length;\n setSelectedAttachment(attachments[newIndex]);\n downloadRef.current?.focus();\n };\n\n const handleLeftArrowClick = () => {\n const newIndex =\n (attachmentIndex - 1 + attachments.length) % attachments.length;\n setSelectedAttachment(attachments[newIndex]);\n downloadRef.current?.focus();\n };\n\n const handleKeyDown = event => {\n if (event.key === \"ArrowRight\") {\n handleRightArrowClick();\n } else if (event.key === \"ArrowLeft\") {\n handleLeftArrowClick();\n }\n };\n\n useEffect(() => {\n setDidFetchPreviewBundle(true);\n }, []);\n\n const handleDownload = () => downloadFile(url, filename);\n\n const setPreview = () => {\n const isPreviewAvailable = checkPreviewAvailability(\n contentType,\n previewUrl\n );\n\n if (isPreviewAvailable) {\n switch (contentType.split(\"/\")[0]) {\n case \"image\":\n return (\n <img\n data-testid={ATTACHMENTS_PREVIEW_DATA_CY}\n src={previewUrl || url}\n />\n );\n case \"video\":\n return (\n <video\n controls\n data-testid={ATTACHMENTS_PREVIEW_DATA_CY}\n src={url}\n />\n );\n case \"application\":\n case \"text\":\n if (contentType === \"application/pdf\") {\n return (\n <iframe\n data-testid={ATTACHMENTS_PREVIEW_DATA_CY}\n src={url}\n width=\"100%\"\n />\n );\n }\n\n return (\n <DocViewer\n className=\"ne-attachments-preview__body-docviewer\"\n data-testid={ATTACHMENTS_PREVIEW_DATA_CY}\n documents={[{ uri: url, fileType: contentType }]}\n pluginRenderers={DocViewerRenderers}\n config={{\n header: { disableHeader: true, disableFileName: true },\n }}\n />\n );\n default:\n return null;\n }\n }\n\n return (\n <Typography>\n <Trans\n i18nKey=\"neetoEditor.attachments.noPreview\"\n components={{\n span: (\n <span\n className=\"ne-attachments-preview__body-download\"\n onClick={handleDownload}\n />\n ),\n }}\n />\n </Typography>\n );\n };\n\n return (\n <Modal\n {...{ onClose }}\n className=\"ne-attachments-preview\"\n isOpen={!isEmpty(selectedAttachment)}\n size=\"fullScreen\"\n onKeyDown={handleKeyDown}\n >\n <Modal.Header className=\"ne-attachments-preview__header\">\n <div className=\"ne-attachments-preview__header__fileinfo\">\n <Typography style=\"h4\">{truncate(filename, 25)}</Typography>\n <Typography style=\"body2\">{convertToFileSize(size)}</Typography>\n </div>\n <Button\n data-testid=\"download-preview-button\"\n label={t(\"neetoEditor.common.download\")}\n ref={downloadRef}\n style=\"link\"\n onClick={handleDownload}\n />\n </Modal.Header>\n <Modal.Body className=\"ne-attachments-preview__body\">\n <Button\n className=\"ne-attachments-preview__body-left\"\n icon={Left}\n size=\"large\"\n style=\"tertiary\"\n onClick={handleLeftArrowClick}\n />\n <Button\n className=\"ne-attachments-preview__body-right\"\n icon={Right}\n size=\"large\"\n style=\"tertiary\"\n onClick={handleRightArrowClick}\n />\n {setPreview()}\n </Modal.Body>\n </Modal>\n );\n};\n\nexport default Preview;\n"],"names":["Preview","_ref","onClose","attachments","selectedAttachment","setSelectedAttachment","setDidFetchPreviewBundle","_useTranslation","useTranslation","t","downloadRef","useRef","_selectedAttachment$f","filename","_selectedAttachment$c","contentType","_selectedAttachment$u","url","_selectedAttachment$s","signedId","_selectedAttachment$s2","size","undefined","_selectedAttachment$p","previewUrl","attachmentIndex","findIndexBy","handleRightArrowClick","_downloadRef$current","newIndex","length","current","focus","handleLeftArrowClick","_downloadRef$current2","handleKeyDown","event","key","useEffect","handleDownload","downloadFile","setPreview","isPreviewAvailable","checkPreviewAvailability","split","_jsx","ATTACHMENTS_PREVIEW_DATA_CY","src","controls","width","DocViewer","className","documents","uri","fileType","pluginRenderers","DocViewerRenderers","config","header","disableHeader","disableFileName","Typography","children","Trans","i18nKey","components","span","onClick","_jsxs","Modal","isOpen","isEmpty","onKeyDown","Header","style","truncate","convertToFileSize","Button","label","ref","Body","icon","Left","Right"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,IAAMA,OAAO,GAAG,SAAVA,OAAOA,CAAAC,IAAA,EAMP;AAAA,EAAA,IALJC,OAAO,GAAAD,IAAA,CAAPC,OAAO;IACPC,WAAW,GAAAF,IAAA,CAAXE,WAAW;IACXC,kBAAkB,GAAAH,IAAA,CAAlBG,kBAAkB;IAClBC,qBAAqB,GAAAJ,IAAA,CAArBI,qBAAqB;IACrBC,wBAAwB,GAAAL,IAAA,CAAxBK,wBAAwB;AAExB,EAAA,IAAAC,eAAA,GAAcC,cAAc,EAAE;IAAtBC,CAAC,GAAAF,eAAA,CAADE,CAAC;AACT,EAAA,IAAMC,WAAW,GAAGC,MAAM,CAAC,IAAI,CAAC;AAEhC,EAAA,IAAAC,qBAAA,GAOIR,kBAAkB,CANpBS,QAAQ;AAARA,IAAAA,QAAQ,GAAAD,qBAAA,KAAA,MAAA,GAAG,EAAE,GAAAA,qBAAA;IAAAE,qBAAA,GAMXV,kBAAkB,CALpBW,WAAW;AAAXA,IAAAA,WAAW,GAAAD,qBAAA,KAAA,MAAA,GAAG,IAAI,GAAAA,qBAAA;IAAAE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AChC,CAAC,EACDc,UAAU,EAAE;AAAA,KACH,CAAC;AAAA,GACR,CAAC;AAEZ;;;;"}
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
|
+
import { createElement, useState, useRef, useEffect, memo } from 'react';
|
|
5
|
+
import classnames from 'classnames';
|
|
6
|
+
import DOMPurify from 'dompurify';
|
|
7
|
+
import CopyToClipboardButton from '@bigbinary/neeto-molecules/v2/CopyToClipboardButton';
|
|
8
|
+
import { isEmpty, isNil } from 'ramda';
|
|
9
|
+
import { createRoot } from 'react-dom/client';
|
|
10
|
+
import { a as EDITOR_SIZES } from './chunk-DrHVV_g1.js';
|
|
11
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
12
|
+
import { l as lowlight, r as removeEmptyTags } from './chunk-Qg4uQqj3.js';
|
|
13
|
+
import { H as HighlightJS } from './chunk-fDmcpgqx.js';
|
|
14
|
+
import { findBy } from '@bigbinary/neeto-cist';
|
|
15
|
+
import { renderToString } from 'react-dom/server';
|
|
16
|
+
import './chunk-D52F37yF.js';
|
|
17
|
+
import { Spinner, Button } from '@bigbinary/neeto-atoms';
|
|
18
|
+
import { X } from 'lucide-react';
|
|
19
|
+
import { useOnClickOutside } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
|
|
20
|
+
import { createPortal } from 'react-dom';
|
|
21
|
+
import { useTranslation } from 'react-i18next';
|
|
22
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
23
|
+
|
|
24
|
+
var EDITOR_CONTENT_CLASS_NAME = "neeto-editor-content";
|
|
25
|
+
var SANITIZE_OPTIONS = {
|
|
26
|
+
ADD_TAGS: ["iframe"],
|
|
27
|
+
ADD_ATTR: ["target", "allow", "allowfullscreen", "frameborder"]
|
|
28
|
+
};
|
|
29
|
+
var CODE_BLOCK_REGEX = /<pre(?:\s+[^>]+)?><code(?:\s+class="language-([^"]*)")?>([\S\s]*?)<\/code><\/pre>/gim;
|
|
30
|
+
var VARIABLE_SPAN_REGEX = /<span data-variable="" [^>]*data-label="([^"]+)">{{([^}]+)}}<\/span>/g;
|
|
31
|
+
var LANGUAGE_LIST = [].concat(_toConsumableArray(lowlight.listLanguages()), ["html"]);
|
|
32
|
+
var EDITOR_CONTENT_DEFAULT_CONFIGURATION = {
|
|
33
|
+
enableHeaderLinks: false
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike) { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
37
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
38
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
39
|
+
var transformCode = function transformCode(code) {
|
|
40
|
+
return code.replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
|
41
|
+
};
|
|
42
|
+
var buildReactElementFromAST = function buildReactElementFromAST(element) {
|
|
43
|
+
if (element.tagName) {
|
|
44
|
+
var children = element.children ? element.children.map(buildReactElementFromAST) : null;
|
|
45
|
+
return /*#__PURE__*/createElement(element.tagName, element.properties, children);
|
|
46
|
+
}
|
|
47
|
+
return element.value;
|
|
48
|
+
};
|
|
49
|
+
var splitCodeBlockIntoLines = function splitCodeBlockIntoLines(codeBlock) {
|
|
50
|
+
codeBlock.innerHTML = codeBlock.innerHTML.replace(/([ \S]*\n|[ \S]*$)/gm, function (match) {
|
|
51
|
+
return "<div class=\"highlight-line\">".concat(match, "</div>");
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
var highlightLinesCode = function highlightLinesCode(code, options) {
|
|
55
|
+
if (options === undefined) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
var paddingLeft = parseInt(window.getComputedStyle(code).paddingLeft);
|
|
59
|
+
var paddingRight = parseInt(window.getComputedStyle(code).paddingRight);
|
|
60
|
+
var lines = code.getElementsByClassName("highlight-line");
|
|
61
|
+
var scroll_width = code.scrollWidth;
|
|
62
|
+
// eslint-disable-next-line @bigbinary/neeto/use-array-methods
|
|
63
|
+
var _iterator = _createForOfIteratorHelper(options),
|
|
64
|
+
_step;
|
|
65
|
+
try {
|
|
66
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
67
|
+
var option = _step.value;
|
|
68
|
+
for (var j = option.start; j <= option.end; ++j) {
|
|
69
|
+
if (j >= lines.length) return;
|
|
70
|
+
lines[j].style.backgroundColor = option.color;
|
|
71
|
+
lines[j].style.minWidth = "".concat(scroll_width - paddingLeft - paddingRight, "px");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} catch (err) {
|
|
75
|
+
_iterator.e(err);
|
|
76
|
+
} finally {
|
|
77
|
+
_iterator.f();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var highlightLinesElement = function highlightLinesElement(code, options) {
|
|
81
|
+
// eslint-disable-next-line @bigbinary/neeto/use-array-methods
|
|
82
|
+
var _iterator2 = _createForOfIteratorHelper(options),
|
|
83
|
+
_step2;
|
|
84
|
+
try {
|
|
85
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
86
|
+
var option = _step2.value;
|
|
87
|
+
--option.start;
|
|
88
|
+
--option.end;
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
_iterator2.e(err);
|
|
92
|
+
} finally {
|
|
93
|
+
_iterator2.f();
|
|
94
|
+
}
|
|
95
|
+
highlightLinesCode(code, options);
|
|
96
|
+
};
|
|
97
|
+
var applySyntaxHighlightingAndLineNumbers = function applySyntaxHighlightingAndLineNumbers(content) {
|
|
98
|
+
lowlight.highlightAuto("");
|
|
99
|
+
var highlightedAST = {};
|
|
100
|
+
return content.replace(CODE_BLOCK_REGEX, function (_, language, code) {
|
|
101
|
+
var _highlightMatch$;
|
|
102
|
+
var highlightRegex = /data-highlighted-lines="([^"]*)"/;
|
|
103
|
+
var linenumbersRegex = /data-linenumbers/;
|
|
104
|
+
var highlightMatch = content.match(highlightRegex);
|
|
105
|
+
if (language && LANGUAGE_LIST.includes(language)) {
|
|
106
|
+
highlightedAST = lowlight.highlight(language, transformCode(code));
|
|
107
|
+
} else {
|
|
108
|
+
highlightedAST = HighlightJS.highlightAuto(transformCode(code))._emitter.root;
|
|
109
|
+
if (isEmpty(highlightedAST.children)) {
|
|
110
|
+
highlightedAST = lowlight.highlight("javascript", transformCode(code));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
var highlightedNode = highlightedAST.children.map(buildReactElementFromAST);
|
|
114
|
+
var dataHighlight = "data-highlighted-lines=".concat((_highlightMatch$ = highlightMatch === null || highlightMatch === void 0 ? void 0 : highlightMatch[1]) !== null && _highlightMatch$ !== void 0 ? _highlightMatch$ : "");
|
|
115
|
+
var dataLinenumbers = content.match(linenumbersRegex) ? "data-linenumbers=\"true\"" : "";
|
|
116
|
+
return "<pre ".concat(dataLinenumbers, " ").concat(dataHighlight, "><code>").concat(renderToString(highlightedNode), "</code></pre>");
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
var applyLineHighlighting = function applyLineHighlighting(editorContent) {
|
|
120
|
+
var codeTags = editorContent === null || editorContent === void 0 ? void 0 : editorContent.querySelectorAll("pre code");
|
|
121
|
+
codeTags.forEach(function (codeTag) {
|
|
122
|
+
splitCodeBlockIntoLines(codeTag);
|
|
123
|
+
var highlightedLines = codeTag.closest("pre").getAttribute("data-highlighted-lines");
|
|
124
|
+
if (highlightedLines) {
|
|
125
|
+
var linesToHighlight = highlightedLines.split(",").map(Number).filter(Boolean);
|
|
126
|
+
var highlightLinesOptions = linesToHighlight.map(function (line) {
|
|
127
|
+
return {
|
|
128
|
+
start: line,
|
|
129
|
+
end: line,
|
|
130
|
+
color: "rgba(255, 255, 0, 0.2)"
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
highlightLinesElement(codeTag, highlightLinesOptions);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
var substituteVariables = function substituteVariables(highlightedContent, variables) {
|
|
138
|
+
return highlightedContent.replace(VARIABLE_SPAN_REGEX, function (matchedSpan, _, key) {
|
|
139
|
+
var keySplitted = key.split(".");
|
|
140
|
+
if (keySplitted.length > 1) {
|
|
141
|
+
var category = findBy({
|
|
142
|
+
category: keySplitted[0]
|
|
143
|
+
}, variables);
|
|
144
|
+
var _variable = findBy({
|
|
145
|
+
key: keySplitted[1]
|
|
146
|
+
}, (category === null || category === void 0 ? void 0 : category.variables) || []);
|
|
147
|
+
return _variable !== null && _variable !== void 0 && _variable.value ? _variable.value : matchedSpan;
|
|
148
|
+
}
|
|
149
|
+
var variable = findBy({
|
|
150
|
+
key: keySplitted[0]
|
|
151
|
+
}, variables);
|
|
152
|
+
return variable !== null && variable !== void 0 && variable.value ? variable.value : matchedSpan;
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
var convertPlainTextToHtml = function convertPlainTextToHtml(htmlString) {
|
|
156
|
+
if (/^<[a-z].*>/i.test(htmlString.trim())) return htmlString;
|
|
157
|
+
return htmlString.split("\n").reduce(function (html, str) {
|
|
158
|
+
return "".concat(html, "<p>").concat(str, "</p>");
|
|
159
|
+
}, "");
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
var buildLinkSVG = function buildLinkSVG() {
|
|
163
|
+
var svgNS = "http://www.w3.org/2000/svg";
|
|
164
|
+
var svgWrapper = document.createElement("span");
|
|
165
|
+
svgWrapper.classList.add("header-link-icon-wrapper");
|
|
166
|
+
var svg = document.createElementNS(svgNS, "svg");
|
|
167
|
+
svg.setAttribute("aria-hidden", "true");
|
|
168
|
+
svg.setAttribute("height", "20");
|
|
169
|
+
svg.setAttribute("viewBox", "0 0 16 16");
|
|
170
|
+
svg.setAttribute("width", "20");
|
|
171
|
+
var path = document.createElementNS(svgNS, "path");
|
|
172
|
+
path.setAttribute("d", "M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z");
|
|
173
|
+
svg.appendChild(path);
|
|
174
|
+
svgWrapper.appendChild(svg);
|
|
175
|
+
return svgWrapper;
|
|
176
|
+
};
|
|
177
|
+
var convertTextToId = function convertTextToId(text) {
|
|
178
|
+
return text.trim().toLowerCase().replace(/[^a-z0-9\s]/g, "").replace(/\s+/g, "-");
|
|
179
|
+
};
|
|
180
|
+
var buildHeaderLinks = function buildHeaderLinks(editorContentNode) {
|
|
181
|
+
var headerTags = editorContentNode.querySelectorAll("h1, h2, h3, h4, h5, h6");
|
|
182
|
+
var usedIds = new Map();
|
|
183
|
+
headerTags.forEach(function (heading) {
|
|
184
|
+
if (heading.getAttribute("data-link") === "false") {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
var headingId = convertTextToId(heading.textContent);
|
|
188
|
+
if (usedIds.has(headingId)) {
|
|
189
|
+
var count = usedIds.get(headingId);
|
|
190
|
+
usedIds.set(headingId, count + 1);
|
|
191
|
+
headingId = "".concat(headingId, "-").concat(count);
|
|
192
|
+
} else usedIds.set(headingId, 1);
|
|
193
|
+
heading.setAttribute("id", headingId);
|
|
194
|
+
var wrapper = document.createElement("div");
|
|
195
|
+
var anchor = document.createElement("a");
|
|
196
|
+
wrapper.classList.add("header-wrapper");
|
|
197
|
+
anchor.setAttribute("href", "#".concat(headingId));
|
|
198
|
+
anchor.classList.add("header-wrapper__link");
|
|
199
|
+
anchor.appendChild(buildLinkSVG());
|
|
200
|
+
wrapper.appendChild(heading.cloneNode(true));
|
|
201
|
+
wrapper.appendChild(anchor);
|
|
202
|
+
heading.replaceWith(wrapper);
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
var handleTodoCheckboxClick = function handleTodoCheckboxClick(event, editorContentRef, onChange) {
|
|
207
|
+
if (!(event.target.type === "checkbox" && event.target.closest('ul[data-type="todoList"] li[data-type="taskItem"]'))) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
var checkbox = event.target;
|
|
211
|
+
var listItem = checkbox.closest("li");
|
|
212
|
+
if (listItem) {
|
|
213
|
+
listItem.setAttribute("data-checked", checkbox.checked.toString());
|
|
214
|
+
if (checkbox.checked) {
|
|
215
|
+
checkbox.setAttribute("checked", "checked");
|
|
216
|
+
} else {
|
|
217
|
+
checkbox.removeAttribute("checked");
|
|
218
|
+
}
|
|
219
|
+
onChange === null || onChange === void 0 || onChange(editorContentRef === null || editorContentRef === void 0 ? void 0 : editorContentRef.innerHTML);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var syncTodoCheckboxStates = function syncTodoCheckboxStates(editorContentRef) {
|
|
223
|
+
if (!editorContentRef) return;
|
|
224
|
+
var todoItems = editorContentRef.querySelectorAll("ul[data-type=\"todoList\"] li[data-type=\"taskItem\"]");
|
|
225
|
+
todoItems.forEach(function (listItem) {
|
|
226
|
+
var isChecked = listItem.getAttribute("data-checked") === "true";
|
|
227
|
+
var checkbox = listItem.querySelector('input[type="checkbox"]');
|
|
228
|
+
if (checkbox) {
|
|
229
|
+
checkbox.checked = isChecked;
|
|
230
|
+
if (isChecked) {
|
|
231
|
+
checkbox.setAttribute("checked", "checked");
|
|
232
|
+
} else {
|
|
233
|
+
checkbox.removeAttribute("checked");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
var ImagePreview = function ImagePreview(_ref) {
|
|
240
|
+
var imagePreviewDetails = _ref.imagePreviewDetails,
|
|
241
|
+
setImagePreviewDetails = _ref.setImagePreviewDetails;
|
|
242
|
+
var _useState = useState(true),
|
|
243
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
244
|
+
isLoading = _useState2[0],
|
|
245
|
+
setIsLoading = _useState2[1];
|
|
246
|
+
var _useTranslation = useTranslation(),
|
|
247
|
+
t = _useTranslation.t;
|
|
248
|
+
var imagePreviewRef = useRef(null);
|
|
249
|
+
useOnClickOutside(imagePreviewRef, function () {
|
|
250
|
+
return setImagePreviewDetails(null);
|
|
251
|
+
}, {
|
|
252
|
+
enabled: true
|
|
253
|
+
});
|
|
254
|
+
useEffect(function () {
|
|
255
|
+
if (!imagePreviewRef.current) return;
|
|
256
|
+
imagePreviewRef.current.setAttribute("tabindex", "-1");
|
|
257
|
+
imagePreviewRef.current.focus();
|
|
258
|
+
}, []);
|
|
259
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
260
|
+
e.stopPropagation();
|
|
261
|
+
e.key === "Escape" && setImagePreviewDetails(null);
|
|
262
|
+
};
|
|
263
|
+
return /*#__PURE__*/createPortal(/*#__PURE__*/jsxs("div", {
|
|
264
|
+
className: "ne-image-preview-wrapper active",
|
|
265
|
+
children: [isLoading && /*#__PURE__*/jsx(Spinner, {
|
|
266
|
+
className: "ne-image-preview-wrapper__spinner"
|
|
267
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
268
|
+
className: classnames("ne-image-preview", {
|
|
269
|
+
"image-loaded": !isLoading
|
|
270
|
+
}),
|
|
271
|
+
children: [!isLoading && /*#__PURE__*/jsx("div", {
|
|
272
|
+
className: "close-button",
|
|
273
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
274
|
+
icon: X,
|
|
275
|
+
variant: "secondary",
|
|
276
|
+
onClick: function onClick() {
|
|
277
|
+
return setImagePreviewDetails(null);
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
}), /*#__PURE__*/jsx("img", {
|
|
281
|
+
alt: t("neetoEditor.editorContent.imagePreviewAltText"),
|
|
282
|
+
ref: imagePreviewRef,
|
|
283
|
+
src: imagePreviewDetails.src,
|
|
284
|
+
onKeyDown: handleKeyDown,
|
|
285
|
+
onLoad: function onLoad() {
|
|
286
|
+
return setIsLoading(false);
|
|
287
|
+
}
|
|
288
|
+
}), imagePreviewDetails && /*#__PURE__*/jsx("p", {
|
|
289
|
+
className: "ne-image-preview__caption",
|
|
290
|
+
children: imagePreviewDetails.caption
|
|
291
|
+
})]
|
|
292
|
+
})]
|
|
293
|
+
}), document.body);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
var _excluded = ["content", "variables", "className", "size", "configuration", "onChange", "onClick"];
|
|
297
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
298
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
299
|
+
var EditorContent = function EditorContent(_ref) {
|
|
300
|
+
var _ref$content = _ref.content,
|
|
301
|
+
content = _ref$content === void 0 ? "" : _ref$content,
|
|
302
|
+
_ref$variables = _ref.variables,
|
|
303
|
+
variables = _ref$variables === void 0 ? [] : _ref$variables,
|
|
304
|
+
className = _ref.className,
|
|
305
|
+
_ref$size = _ref.size,
|
|
306
|
+
size = _ref$size === void 0 ? EDITOR_SIZES.SMALL : _ref$size,
|
|
307
|
+
_ref$configuration = _ref.configuration,
|
|
308
|
+
configuration = _ref$configuration === void 0 ? EDITOR_CONTENT_DEFAULT_CONFIGURATION : _ref$configuration,
|
|
309
|
+
onChange = _ref.onChange,
|
|
310
|
+
onClick = _ref.onClick,
|
|
311
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
312
|
+
var _useState = useState(null),
|
|
313
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
314
|
+
imagePreviewDetails = _useState2[0],
|
|
315
|
+
setImagePreviewDetails = _useState2[1];
|
|
316
|
+
var editorContentRef = useRef(null);
|
|
317
|
+
var htmlContent = convertPlainTextToHtml(substituteVariables(applySyntaxHighlightingAndLineNumbers(removeEmptyTags(content)), variables));
|
|
318
|
+
var sanitize = DOMPurify.sanitize;
|
|
319
|
+
var handleContentClick = function handleContentClick(event) {
|
|
320
|
+
handleTodoCheckboxClick(event, editorContentRef.current, onChange);
|
|
321
|
+
onClick === null || onClick === void 0 || onClick(event);
|
|
322
|
+
};
|
|
323
|
+
var injectCopyButtonToCodeBlocks = function injectCopyButtonToCodeBlocks() {
|
|
324
|
+
var _editorContentRef$cur;
|
|
325
|
+
var preTags = (_editorContentRef$cur = editorContentRef.current) === null || _editorContentRef$cur === void 0 ? void 0 : _editorContentRef$cur.querySelectorAll(".".concat(EDITOR_CONTENT_CLASS_NAME, " pre"));
|
|
326
|
+
preTags.forEach(function (preTag) {
|
|
327
|
+
var button = document.createElement("div");
|
|
328
|
+
button.className = "neeto-editor-codeblock-options";
|
|
329
|
+
var root = createRoot(button);
|
|
330
|
+
root.render(/*#__PURE__*/jsx(CopyToClipboardButton, {
|
|
331
|
+
size: "sm",
|
|
332
|
+
value: preTag.textContent,
|
|
333
|
+
variant: "ghost"
|
|
334
|
+
}));
|
|
335
|
+
preTag.appendChild(button);
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
var bindImageClickListener = function bindImageClickListener() {
|
|
339
|
+
var _editorContentRef$cur2;
|
|
340
|
+
var figureTags = (_editorContentRef$cur2 = editorContentRef.current) === null || _editorContentRef$cur2 === void 0 ? void 0 : _editorContentRef$cur2.querySelectorAll(".".concat(EDITOR_CONTENT_CLASS_NAME, " figure"));
|
|
341
|
+
figureTags.forEach(function (figureTag) {
|
|
342
|
+
var image = figureTag.querySelector("img");
|
|
343
|
+
var link = figureTag.querySelector("a");
|
|
344
|
+
if (isNil(image) || isNil(link)) return;
|
|
345
|
+
figureTag.addEventListener("click", function (event) {
|
|
346
|
+
var _figureTag$querySelec;
|
|
347
|
+
event.preventDefault();
|
|
348
|
+
var caption = (_figureTag$querySelec = figureTag.querySelector("figcaption")) === null || _figureTag$querySelec === void 0 ? void 0 : _figureTag$querySelec.innerText;
|
|
349
|
+
setImagePreviewDetails({
|
|
350
|
+
src: image.src,
|
|
351
|
+
caption: caption
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
useEffect(function () {
|
|
357
|
+
injectCopyButtonToCodeBlocks();
|
|
358
|
+
bindImageClickListener();
|
|
359
|
+
syncTodoCheckboxStates(editorContentRef.current);
|
|
360
|
+
applyLineHighlighting(editorContentRef.current);
|
|
361
|
+
configuration.enableHeaderLinks && buildHeaderLinks(editorContentRef.current);
|
|
362
|
+
}, [content]);
|
|
363
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
364
|
+
children: [/*#__PURE__*/jsx("div", _objectSpread({
|
|
365
|
+
"data-testid": "neeto-editor-content",
|
|
366
|
+
ref: editorContentRef,
|
|
367
|
+
className: classnames(EDITOR_CONTENT_CLASS_NAME, _defineProperty(_defineProperty({}, className, className), "neeto-editor-size--".concat(size), true)),
|
|
368
|
+
dangerouslySetInnerHTML: {
|
|
369
|
+
__html: sanitize(htmlContent, SANITIZE_OPTIONS)
|
|
370
|
+
},
|
|
371
|
+
onClick: handleContentClick
|
|
372
|
+
}, otherProps)), imagePreviewDetails && /*#__PURE__*/jsx(ImagePreview, {
|
|
373
|
+
imagePreviewDetails: imagePreviewDetails,
|
|
374
|
+
setImagePreviewDetails: setImagePreviewDetails
|
|
375
|
+
})]
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
var index = /*#__PURE__*/memo(EditorContent);
|
|
379
|
+
|
|
380
|
+
export { index as i, substituteVariables as s };
|
|
381
|
+
//# sourceMappingURL=chunk-CX-0IHKE.js.map
|