@elliemae/ds-wysiwygeditor 2.2.0 → 2.3.0-alpha.3
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/cjs/DSWYSIWYGEditor.js +83 -72
- package/cjs/DSWYSIWYGEditor.js.map +7 -0
- package/cjs/components/CustomImageUploader.js +92 -94
- package/cjs/components/CustomImageUploader.js.map +7 -0
- package/cjs/components/CustomToolbar.js +172 -193
- package/cjs/components/CustomToolbar.js.map +7 -0
- package/cjs/components/DSWYSIWYGEditorImpl.js +147 -185
- package/cjs/components/DSWYSIWYGEditorImpl.js.map +7 -0
- package/cjs/components/ImageLibraryModal.js +75 -55
- package/cjs/components/ImageLibraryModal.js.map +7 -0
- package/cjs/components/InsertFieldModal.js +109 -142
- package/cjs/components/InsertFieldModal.js.map +7 -0
- package/cjs/components/TippedButton.js +56 -54
- package/cjs/components/TippedButton.js.map +7 -0
- package/cjs/components/TippedSelect.js +50 -39
- package/cjs/components/TippedSelect.js.map +7 -0
- package/cjs/components/colors.js +41 -21
- package/cjs/components/colors.js.map +7 -0
- package/cjs/components/customFields.js +66 -47
- package/cjs/components/customFields.js.map +7 -0
- package/cjs/constants.js +112 -38
- package/cjs/constants.js.map +7 -0
- package/cjs/index.js +39 -21
- package/cjs/index.js.map +7 -0
- package/cjs/quillMatchers/clipboardLinkWithTagMatcher.js +37 -22
- package/cjs/quillMatchers/clipboardLinkWithTagMatcher.js.map +7 -0
- package/cjs/quillOverrides/IndentStyle.js +41 -19
- package/cjs/quillOverrides/IndentStyle.js.map +7 -0
- package/cjs/quillOverrides/LinkFormat.js +57 -39
- package/cjs/quillOverrides/LinkFormat.js.map +7 -0
- package/cjs/quillOverrides/PlainClipboard.js +41 -21
- package/cjs/quillOverrides/PlainClipboard.js.map +7 -0
- package/cjs/utils.js +41 -18
- package/cjs/utils.js.map +7 -0
- package/esm/DSWYSIWYGEditor.js +50 -58
- package/esm/DSWYSIWYGEditor.js.map +7 -0
- package/esm/components/CustomImageUploader.js +60 -81
- package/esm/components/CustomImageUploader.js.map +7 -0
- package/esm/components/CustomToolbar.js +145 -184
- package/esm/components/CustomToolbar.js.map +7 -0
- package/esm/components/DSWYSIWYGEditorImpl.js +113 -169
- package/esm/components/DSWYSIWYGEditorImpl.js.map +7 -0
- package/esm/components/ImageLibraryModal.js +46 -47
- package/esm/components/ImageLibraryModal.js.map +7 -0
- package/esm/components/InsertFieldModal.js +72 -124
- package/esm/components/InsertFieldModal.js.map +7 -0
- package/esm/components/TippedButton.js +27 -44
- package/esm/components/TippedButton.js.map +7 -0
- package/esm/components/TippedSelect.js +21 -31
- package/esm/components/TippedSelect.js.map +7 -0
- package/esm/components/colors.js +12 -17
- package/esm/components/colors.js.map +7 -0
- package/esm/components/customFields.js +38 -40
- package/esm/components/customFields.js.map +7 -0
- package/esm/constants.js +83 -30
- package/esm/constants.js.map +7 -0
- package/esm/index.js +10 -4
- package/esm/index.js.map +7 -0
- package/esm/quillMatchers/clipboardLinkWithTagMatcher.js +8 -18
- package/esm/quillMatchers/clipboardLinkWithTagMatcher.js.map +7 -0
- package/esm/quillOverrides/IndentStyle.js +12 -17
- package/esm/quillOverrides/IndentStyle.js.map +7 -0
- package/esm/quillOverrides/LinkFormat.js +28 -37
- package/esm/quillOverrides/LinkFormat.js.map +7 -0
- package/esm/quillOverrides/PlainClipboard.js +12 -19
- package/esm/quillOverrides/PlainClipboard.js.map +7 -0
- package/esm/utils.js +12 -14
- package/esm/utils.js.map +7 -0
- package/package.json +9 -9
package/cjs/DSWYSIWYGEditor.js
CHANGED
|
@@ -1,82 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var DSWYSIWYGEditor_exports = {};
|
|
29
|
+
__export(DSWYSIWYGEditor_exports, {
|
|
30
|
+
WYSIWYWithSchema: () => WYSIWYWithSchema,
|
|
31
|
+
default: () => DSWYSIWYGEditor_default
|
|
32
|
+
});
|
|
33
|
+
var React = __toESM(require("react"));
|
|
34
|
+
var import_react = __toESM(require("react"));
|
|
35
|
+
var import_react_desc = require("react-desc");
|
|
36
|
+
var import_DSWYSIWYGEditorImpl = __toESM(require("./components/DSWYSIWYGEditorImpl"));
|
|
37
|
+
const DSWYSIWYGEditor = ({
|
|
38
|
+
value = "",
|
|
39
|
+
onChange = () => null,
|
|
40
|
+
getQuillRef = () => null,
|
|
41
|
+
quillModules = {},
|
|
42
|
+
customToolbar,
|
|
43
|
+
toolbarHandlers,
|
|
44
|
+
showRawHTML = false,
|
|
45
|
+
height,
|
|
46
|
+
hideItems,
|
|
47
|
+
...rest
|
|
48
|
+
}) => {
|
|
49
|
+
const emptyAction = () => {
|
|
50
|
+
};
|
|
51
|
+
const [showHTML, setShowHTML] = (0, import_react.useState)(showRawHTML);
|
|
52
|
+
(0, import_react.useEffect)(() => setShowHTML(showRawHTML), [showRawHTML]);
|
|
53
|
+
return /* @__PURE__ */ import_react.default.createElement(import_DSWYSIWYGEditorImpl.default, {
|
|
48
54
|
forceHttpLink: true,
|
|
49
55
|
handleCustomFieldClick: emptyAction,
|
|
50
56
|
handleImageClick: emptyAction,
|
|
51
57
|
quillOverrides: [],
|
|
52
|
-
value
|
|
53
|
-
onChange
|
|
54
|
-
getQuillRef
|
|
55
|
-
quillModules
|
|
56
|
-
customToolbar
|
|
57
|
-
toolbarHandlers
|
|
58
|
+
value,
|
|
59
|
+
onChange,
|
|
60
|
+
getQuillRef,
|
|
61
|
+
quillModules,
|
|
62
|
+
customToolbar,
|
|
63
|
+
toolbarHandlers,
|
|
58
64
|
showRawHTML: showHTML,
|
|
59
65
|
onShowHTML: () => setShowHTML(!showHTML),
|
|
60
|
-
height
|
|
61
|
-
hideItems
|
|
62
|
-
|
|
66
|
+
height,
|
|
67
|
+
hideItems,
|
|
68
|
+
...rest
|
|
69
|
+
});
|
|
63
70
|
};
|
|
64
|
-
|
|
65
71
|
const wysiwygEditorProps = {
|
|
66
|
-
value:
|
|
67
|
-
onChange:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
value: import_react_desc.PropTypes.string.description("editors value").isRequired,
|
|
73
|
+
onChange: import_react_desc.PropTypes.func.description(`(content, delta, source, editor) : Called back with the new contents of the editor after change.
|
|
74
|
+
It will be passed the HTML contents of the editor, a delta object expressing the change, the source of the change, and finally a read-only proxy to editor accessors such as getHTML().
|
|
75
|
+
\u26A0\uFE0F Do not use this delta object as value, as it will cause a loop.
|
|
76
|
+
Use editor.getContents() instead. See Using Deltas for details.
|
|
77
|
+
Read more: https://github.com/zenoamaro/react-quill#props`).isRequired,
|
|
78
|
+
getQuillRef: import_react_desc.PropTypes.func.description("function to use quill.js ref"),
|
|
79
|
+
quillModules: import_react_desc.PropTypes.object.description("object to override quill modules"),
|
|
80
|
+
customToolbar: import_react_desc.PropTypes.element.description("custom toolbar"),
|
|
81
|
+
toolbarHandlers: import_react_desc.PropTypes.object.description("object with toolbar handlers"),
|
|
82
|
+
showRawHTML: import_react_desc.PropTypes.bool.description("whether to display html view or not").defaultValue(false),
|
|
83
|
+
height: import_react_desc.PropTypes.string.description("heigth of the editors text area"),
|
|
84
|
+
readOnly: import_react_desc.PropTypes.string.description("If true, the editor won't allow changing its contents. Wraps the Quill disable API."),
|
|
85
|
+
hideItems: import_react_desc.PropTypes.object.description("object of defaultItems to be removed from toolbar").defaultValue({}),
|
|
86
|
+
zIndex: import_react_desc.PropTypes.number.description("zIndex to be used (required when used in a modal for correct tooltips displaying)")
|
|
77
87
|
};
|
|
78
|
-
|
|
88
|
+
DSWYSIWYGEditor.propTypes = wysiwygEditorProps;
|
|
89
|
+
const WYSIWYWithSchema = (0, import_react_desc.describe)(DSWYSIWYGEditor);
|
|
79
90
|
WYSIWYWithSchema.propTypes = wysiwygEditorProps;
|
|
80
|
-
|
|
81
|
-
exports
|
|
82
|
-
|
|
91
|
+
var DSWYSIWYGEditor_default = DSWYSIWYGEditor;
|
|
92
|
+
module.exports = __toCommonJS(DSWYSIWYGEditor_exports);
|
|
93
|
+
//# sourceMappingURL=DSWYSIWYGEditor.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/DSWYSIWYGEditor.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import React, { useState, useEffect } from 'react';\nimport { describe, PropTypes } from 'react-desc';\nimport DSWYSIWYGEditorImpl from './components/DSWYSIWYGEditorImpl';\n\nconst DSWYSIWYGEditor = ({\n value = '',\n onChange = () => null,\n getQuillRef = () => null,\n quillModules = {},\n customToolbar,\n toolbarHandlers,\n showRawHTML = false,\n height,\n hideItems,\n ...rest\n}) => {\n const emptyAction = () => {};\n const [showHTML, setShowHTML] = useState(showRawHTML);\n\n useEffect(() => setShowHTML(showRawHTML), [showRawHTML]);\n\n return (\n <DSWYSIWYGEditorImpl\n forceHttpLink\n handleCustomFieldClick={emptyAction}\n handleImageClick={emptyAction}\n quillOverrides={[]}\n value={value}\n onChange={onChange}\n getQuillRef={getQuillRef}\n quillModules={quillModules}\n customToolbar={customToolbar}\n toolbarHandlers={toolbarHandlers}\n showRawHTML={showHTML}\n onShowHTML={() => setShowHTML(!showHTML)}\n height={height}\n hideItems={hideItems}\n {...rest}\n />\n );\n};\n\nconst wysiwygEditorProps = {\n value: PropTypes.string.description('editors value').isRequired,\n onChange: PropTypes.func.description(\n `(content, delta, source, editor) : Called back with the new contents of the editor after change. \n It will be passed the HTML contents of the editor, a delta object expressing the change, the source of the change, and finally a read-only proxy to editor accessors such as getHTML(). \n \u26A0\uFE0F Do not use this delta object as value, as it will cause a loop. \n Use editor.getContents() instead. See Using Deltas for details. \n Read more: https://github.com/zenoamaro/react-quill#props`,\n ).isRequired,\n getQuillRef: PropTypes.func.description('function to use quill.js ref'),\n quillModules: PropTypes.object.description('object to override quill modules'),\n customToolbar: PropTypes.element.description('custom toolbar'),\n toolbarHandlers: PropTypes.object.description('object with toolbar handlers'),\n showRawHTML: PropTypes.bool.description('whether to display html view or not').defaultValue(false),\n height: PropTypes.string.description('heigth of the editors text area'),\n readOnly: PropTypes.string.description(\n \"If true, the editor won't allow changing its contents. Wraps the Quill disable API.\",\n ),\n hideItems: PropTypes.object.description('object of defaultItems to be removed from toolbar').defaultValue({}),\n zIndex: PropTypes.number.description(\n 'zIndex to be used (required when used in a modal for correct tooltips displaying)',\n ),\n};\n\nDSWYSIWYGEditor.propTypes = wysiwygEditorProps;\n\nconst WYSIWYWithSchema = describe(DSWYSIWYGEditor);\nWYSIWYWithSchema.propTypes = wysiwygEditorProps;\n\nexport { WYSIWYWithSchema };\nexport default DSWYSIWYGEditor;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA2C;AAC3C,wBAAoC;AACpC,iCAAgC;AAEhC,MAAM,kBAAkB,CAAC;AAAA,EACvB,QAAQ;AAAA,EACR,WAAW,MAAM;AAAA,EACjB,cAAc,MAAM;AAAA,EACpB,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA;AAAA,KACG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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var CustomImageUploader_exports = {};
|
|
29
|
+
__export(CustomImageUploader_exports, {
|
|
30
|
+
CustomImageUploader: () => CustomImageUploader
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react = __toESM(require("react"));
|
|
34
|
+
var import_ds_icons = require("@elliemae/ds-icons");
|
|
35
|
+
var import_ds_uploader = __toESM(require("@elliemae/ds-uploader"));
|
|
36
|
+
var import_ds_modal = __toESM(require("@elliemae/ds-modal"));
|
|
37
|
+
var import_TippedButton = require("./TippedButton");
|
|
38
|
+
const ALLOWED_TYPES_TEXT = "JPG, JPEG, PNG, GIF, BMP, TIFF";
|
|
21
39
|
const ALLOWED_TYPES = /image\/(jpeg|jpg|png|gif|bmp|tiff)/;
|
|
22
|
-
const DEFAULT_MAX_SIZE = 1024 * 1024;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const [
|
|
33
|
-
const [
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
index: 0,
|
|
37
|
-
length: 0
|
|
38
|
-
});
|
|
39
|
-
const elementId = "uploadImage".concat(editorFieldName); // eslint-disable-next-line consistent-return
|
|
40
|
-
|
|
41
|
-
const handleFileChange = async files => {
|
|
40
|
+
const DEFAULT_MAX_SIZE = 1024 * 1024;
|
|
41
|
+
const CustomImageUploader = ({
|
|
42
|
+
quillRef,
|
|
43
|
+
editorFieldName,
|
|
44
|
+
allowedImageTypes = ALLOWED_TYPES_TEXT,
|
|
45
|
+
uploadAsset = () => null,
|
|
46
|
+
zIndex = 1
|
|
47
|
+
}) => {
|
|
48
|
+
const [isOpen, setIsOpen] = (0, import_react.useState)(false);
|
|
49
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
50
|
+
const [inProgress, setInProgress] = (0, import_react.useState)(false);
|
|
51
|
+
const [lastSelection, setLastSelection] = (0, import_react.useState)({ index: 0, length: 0 });
|
|
52
|
+
const elementId = `uploadImage${editorFieldName}`;
|
|
53
|
+
const handleFileChange = async (files) => {
|
|
42
54
|
if (!inProgress) {
|
|
43
55
|
setError(null);
|
|
44
56
|
const selectedFile = files[0];
|
|
45
|
-
|
|
46
57
|
if (!selectedFile) {
|
|
47
|
-
setError(
|
|
58
|
+
setError("Please select a file.");
|
|
48
59
|
return false;
|
|
49
60
|
}
|
|
50
|
-
|
|
51
61
|
if (!selectedFile.type.match(ALLOWED_TYPES)) {
|
|
52
|
-
setError(
|
|
62
|
+
setError("File must be an image.");
|
|
53
63
|
} else if (selectedFile.size > DEFAULT_MAX_SIZE) {
|
|
54
|
-
setError(
|
|
64
|
+
setError("File is too large.");
|
|
55
65
|
} else {
|
|
56
66
|
const fr = new FileReader();
|
|
57
|
-
|
|
58
67
|
fr.onload = async () => {
|
|
59
68
|
setInProgress(true);
|
|
60
|
-
|
|
61
69
|
try {
|
|
62
70
|
const url = await uploadAsset({
|
|
63
71
|
name: selectedFile.name,
|
|
@@ -67,59 +75,49 @@ const CustomImageUploader = _ref => {
|
|
|
67
75
|
file: fr.result
|
|
68
76
|
});
|
|
69
77
|
setIsOpen(false);
|
|
70
|
-
quillRef
|
|
78
|
+
quillRef?.getEditor().insertEmbed(lastSelection?.index || 0, "image", url);
|
|
71
79
|
} catch (e) {
|
|
72
|
-
setError(
|
|
80
|
+
setError("An error has occurred, try again");
|
|
73
81
|
}
|
|
74
|
-
|
|
75
82
|
setInProgress(false);
|
|
76
83
|
};
|
|
77
|
-
|
|
78
84
|
fr.readAsArrayBuffer(selectedFile);
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
onDrop: handleFileChange
|
|
116
|
-
}), inProgress && 'Upload in progress...', error && /*#__PURE__*/_jsx__default["default"]("div", {
|
|
117
|
-
style: {
|
|
118
|
-
color: 'red',
|
|
119
|
-
marginTop: '10px'
|
|
120
|
-
}
|
|
121
|
-
}, void 0, error))]
|
|
122
|
-
});
|
|
88
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_TippedButton.TippedButton, {
|
|
89
|
+
zIndex,
|
|
90
|
+
tip: "Insert Image",
|
|
91
|
+
onClick: () => {
|
|
92
|
+
setLastSelection(quillRef?.getEditor().getSelection());
|
|
93
|
+
setIsOpen(true);
|
|
94
|
+
}
|
|
95
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_ds_icons.Image, {
|
|
96
|
+
color: ["neutral", 500],
|
|
97
|
+
size: "s"
|
|
98
|
+
})), /* @__PURE__ */ import_react.default.createElement(import_ds_modal.default, {
|
|
99
|
+
isOpen,
|
|
100
|
+
title: "",
|
|
101
|
+
onConfirm: () => {
|
|
102
|
+
setIsOpen(false);
|
|
103
|
+
},
|
|
104
|
+
onClose: () => {
|
|
105
|
+
setIsOpen(false);
|
|
106
|
+
},
|
|
107
|
+
showClose: true,
|
|
108
|
+
version: 2,
|
|
109
|
+
size: "xsmall",
|
|
110
|
+
modalType: import_ds_modal.MODAL_TYPE_V2.DECISION,
|
|
111
|
+
confirmLabel: "Cancel",
|
|
112
|
+
message: ""
|
|
113
|
+
}, !inProgress && /* @__PURE__ */ import_react.default.createElement(import_ds_uploader.default, {
|
|
114
|
+
containerProps: { id: elementId },
|
|
115
|
+
showAltAction: false,
|
|
116
|
+
acceptedTypesText: allowedImageTypes,
|
|
117
|
+
onDrop: handleFileChange
|
|
118
|
+
}), inProgress && "Upload in progress...", error && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
119
|
+
style: { color: "red", marginTop: "10px" }
|
|
120
|
+
}, error)));
|
|
123
121
|
};
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
module.exports = __toCommonJS(CustomImageUploader_exports);
|
|
123
|
+
//# sourceMappingURL=CustomImageUploader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/CustomImageUploader.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n/* eslint-disable jsx-a11y/no-static-element-interactions */\n/* eslint-disable jsx-a11y/click-events-have-key-events */\n/* eslint-disable react/prop-types */\nimport React, { useState } from 'react';\nimport { Image } from '@elliemae/ds-icons';\nimport DSUploader from '@elliemae/ds-uploader';\nimport DSModal, { MODAL_TYPE_V2 } from '@elliemae/ds-modal';\nimport { TippedButton } from './TippedButton';\n\nconst ALLOWED_TYPES_TEXT = 'JPG, JPEG, PNG, GIF, BMP, TIFF';\nconst ALLOWED_TYPES = /image\\/(jpeg|jpg|png|gif|bmp|tiff)/;\nconst DEFAULT_MAX_SIZE = 1024 * 1024; // 1 MB\n\nexport const CustomImageUploader = ({\n quillRef,\n editorFieldName,\n allowedImageTypes = ALLOWED_TYPES_TEXT,\n uploadAsset = () => null,\n zIndex = 1,\n}) => {\n const [isOpen, setIsOpen] = useState(false);\n const [error, setError] = useState(null);\n const [inProgress, setInProgress] = useState(false);\n const [lastSelection, setLastSelection] = useState({ index: 0, length: 0 });\n\n const elementId = `uploadImage${editorFieldName}`;\n\n // eslint-disable-next-line consistent-return\n const handleFileChange = async (files) => {\n if (!inProgress) {\n setError(null);\n const selectedFile = files[0];\n if (!selectedFile) {\n setError('Please select a file.');\n return false;\n }\n if (!selectedFile.type.match(ALLOWED_TYPES)) {\n setError('File must be an image.');\n } else if (selectedFile.size > DEFAULT_MAX_SIZE) {\n setError('File is too large.');\n } else {\n const fr = new FileReader();\n fr.onload = async () => {\n setInProgress(true);\n try {\n const url = await uploadAsset({\n name: selectedFile.name,\n type: selectedFile.type,\n description: selectedFile.name,\n isSystemAsset: false,\n file: fr.result,\n });\n setIsOpen(false);\n quillRef?.getEditor().insertEmbed(lastSelection?.index || 0, 'image', url);\n } catch (e) {\n setError('An error has occurred, try again');\n }\n setInProgress(false);\n };\n fr.readAsArrayBuffer(selectedFile);\n }\n }\n };\n return (\n <>\n <TippedButton\n zIndex={zIndex}\n tip=\"Insert Image\"\n onClick={() => {\n setLastSelection(quillRef?.getEditor().getSelection());\n setIsOpen(true);\n }}\n >\n <Image color={['neutral', 500]} size=\"s\" />\n </TippedButton>\n <DSModal\n isOpen={isOpen}\n title=\"\"\n onConfirm={() => {\n setIsOpen(false);\n }}\n onClose={() => {\n setIsOpen(false);\n }}\n showClose\n version={2}\n size=\"xsmall\"\n modalType={MODAL_TYPE_V2.DECISION}\n confirmLabel=\"Cancel\"\n message=\"\"\n >\n {!inProgress && (\n <DSUploader\n containerProps={{ id: elementId }}\n showAltAction={false}\n acceptedTypesText={allowedImageTypes}\n onDrop={handleFileChange}\n />\n )}\n {inProgress && 'Upload in progress...'}\n {error && <div style={{ color: 'red', marginTop: '10px' }}>{error}</div>}\n </DSModal>\n </>\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAgC;AAChC,sBAAsB;AACtB,yBAAuB;AACvB,sBAAuC;AACvC,0BAA6B;AAE7B,MAAM,qBAAqB;AAC3B,MAAM,gBAAgB;AACtB,MAAM,mBAAmB,OAAO;AAEzB,MAAM,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA;AAAA,EACA,oBAAoB;AAAA,EAC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