hanbiro-react16-sdk 1.0.18 → 1.0.20
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 +2 -19
- package/dist/_virtual/_commonjsHelpers.js +6 -0
- package/dist/_virtual/index.js +4 -0
- package/dist/components/ChatAIDraft/CustomAIIcon.js +63 -0
- package/dist/components/ChatAIDraft/List.js +151 -0
- package/dist/components/ChatAIDraft/SettingPopper.js +225 -0
- package/dist/components/ChatAIDraft/TypingText.js +39 -0
- package/dist/components/ChatAIDraft/helper.js +121 -0
- package/dist/components/ChatAIDraft/index.js +281 -0
- package/dist/components/CountryFlag/flags/CNFlag.js +27 -0
- package/dist/components/CountryFlag/flags/DEFlag.js +21 -0
- package/dist/components/CountryFlag/flags/ESFlag.js +457 -0
- package/dist/components/CountryFlag/flags/FRFlag.js +21 -0
- package/dist/components/CountryFlag/flags/IDFlag.js +21 -0
- package/dist/components/CountryFlag/flags/ITFlag.js +21 -0
- package/dist/components/CountryFlag/flags/JPFlag.js +21 -0
- package/dist/components/CountryFlag/flags/KRFlag.js +39 -0
- package/dist/components/CountryFlag/flags/NLFlag.js +21 -0
- package/dist/components/CountryFlag/flags/PTFlag.js +139 -0
- package/dist/components/CountryFlag/flags/RUFlag.js +21 -0
- package/dist/components/CountryFlag/flags/SAFlag.js +24 -0
- package/dist/components/CountryFlag/flags/THFlag.js +21 -0
- package/dist/components/CountryFlag/flags/TWFlag.js +28 -0
- package/dist/components/CountryFlag/flags/USFlag.js +34 -0
- package/dist/components/CountryFlag/flags/VNFlag.js +29 -0
- package/dist/components/CountryFlag/index.js +73 -0
- package/dist/components/LoadingCircular/index.js +37 -0
- package/dist/components/LoadingContainer/index.js +53 -0
- package/dist/components/TinyMceEditor/index.js +181 -0
- package/dist/components/TinyMceEditor/scrollStyle.js +40 -0
- package/dist/components/TinyMceEditor/useEditor.js +120 -0
- package/dist/components/Tooltip/index.js +172 -0
- package/dist/constants/index.js +85 -0
- package/dist/hanbiro-react16-sdk.style.css +1 -1
- package/dist/hanbiro-react16-sdk.umd.js +2 -9680
- package/dist/index.js +23 -0
- package/dist/node_modules/@tinymce/tinymce-react/lib/es2015/main/ts/ScriptLoader2.js +148 -0
- package/dist/node_modules/@tinymce/tinymce-react/lib/es2015/main/ts/TinyMCE.js +7 -0
- package/dist/node_modules/@tinymce/tinymce-react/lib/es2015/main/ts/Utils.js +103 -0
- package/dist/node_modules/@tinymce/tinymce-react/lib/es2015/main/ts/components/Editor.js +353 -0
- package/dist/node_modules/@tinymce/tinymce-react/lib/es2015/main/ts/components/EditorPropTypes.js +102 -0
- package/dist/node_modules/axios/index.js +38 -0
- package/dist/node_modules/axios/lib/adapters/adapters.js +71 -0
- package/dist/node_modules/axios/lib/adapters/fetch.js +272 -0
- package/dist/node_modules/axios/lib/adapters/xhr.js +153 -0
- package/dist/node_modules/axios/lib/axios.js +50 -0
- package/dist/node_modules/axios/lib/cancel/CancelToken.js +99 -0
- package/dist/node_modules/axios/lib/cancel/CanceledError.js +20 -0
- package/dist/node_modules/axios/lib/cancel/isCancel.js +6 -0
- package/dist/node_modules/axios/lib/core/Axios.js +220 -0
- package/dist/node_modules/axios/lib/core/AxiosError.js +76 -0
- package/dist/node_modules/axios/lib/core/AxiosHeaders.js +238 -0
- package/dist/node_modules/axios/lib/core/InterceptorManager.js +66 -0
- package/dist/node_modules/axios/lib/core/buildFullPath.js +12 -0
- package/dist/node_modules/axios/lib/core/dispatchRequest.js +48 -0
- package/dist/node_modules/axios/lib/core/mergeConfig.js +100 -0
- package/dist/node_modules/axios/lib/core/settle.js +20 -0
- package/dist/node_modules/axios/lib/core/transformData.js +17 -0
- package/dist/node_modules/axios/lib/defaults/index.js +120 -0
- package/dist/node_modules/axios/lib/defaults/transitional.js +9 -0
- package/dist/node_modules/axios/lib/env/data.js +4 -0
- package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +34 -0
- package/dist/node_modules/axios/lib/helpers/HttpStatusCode.js +77 -0
- package/dist/node_modules/axios/lib/helpers/bind.js +8 -0
- package/dist/node_modules/axios/lib/helpers/buildURL.js +32 -0
- package/dist/node_modules/axios/lib/helpers/combineURLs.js +6 -0
- package/dist/node_modules/axios/lib/helpers/composeSignals.js +41 -0
- package/dist/node_modules/axios/lib/helpers/cookies.js +49 -0
- package/dist/node_modules/axios/lib/helpers/formDataToJSON.js +54 -0
- package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.js +9 -0
- package/dist/node_modules/axios/lib/helpers/isAxiosError.js +7 -0
- package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.js +11 -0
- package/dist/node_modules/axios/lib/helpers/null.js +4 -0
- package/dist/node_modules/axios/lib/helpers/parseHeaders.js +47 -0
- package/dist/node_modules/axios/lib/helpers/parseProtocol.js +7 -0
- package/dist/node_modules/axios/lib/helpers/progressEventReducer.js +44 -0
- package/dist/node_modules/axios/lib/helpers/resolveConfig.js +52 -0
- package/dist/node_modules/axios/lib/helpers/speedometer.js +36 -0
- package/dist/node_modules/axios/lib/helpers/spread.js +8 -0
- package/dist/node_modules/axios/lib/helpers/throttle.js +35 -0
- package/dist/node_modules/axios/lib/helpers/toFormData.js +120 -0
- package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.js +33 -0
- package/dist/node_modules/axios/lib/helpers/trackStream.js +169 -0
- package/dist/node_modules/axios/lib/helpers/validator.js +70 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/Blob.js +4 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/FormData.js +4 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js +5 -0
- package/dist/node_modules/axios/lib/platform/browser/index.js +15 -0
- package/dist/node_modules/axios/lib/platform/common/utils.js +15 -0
- package/dist/node_modules/axios/lib/platform/index.js +22 -0
- package/dist/node_modules/axios/lib/utils.js +429 -0
- package/dist/node_modules/marked/lib/marked.esm.js +2169 -0
- package/dist/node_modules/prop-types/factoryWithThrowingShims.js +51 -0
- package/dist/node_modules/prop-types/index.js +12 -0
- package/dist/node_modules/prop-types/lib/ReactPropTypesSecret.js +5 -0
- package/dist/node_modules/react-feather/dist/icons/copy.js +75 -0
- package/dist/node_modules/react-feather/dist/icons/send.js +73 -0
- package/dist/node_modules/react-feather/dist/icons/settings.js +72 -0
- package/dist/node_modules/uuid/dist/esm-browser/native.js +7 -0
- package/dist/node_modules/uuid/dist/esm-browser/rng.js +14 -0
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js +10 -0
- package/dist/node_modules/uuid/dist/esm-browser/v4.js +16 -0
- package/dist/utils/axiosAPI.js +89 -0
- package/dist/utils/url.js +54 -0
- package/package.json +10 -6
- package/dist/hanbiro-react16-sdk.es.js +0 -7911
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* hanbiro-react16-sdk v1.0.20
|
|
3
|
+
* Build Date: 2026-04-02
|
|
4
|
+
*/
|
|
5
|
+
/* empty css */
|
|
6
|
+
import { AI_LANG_FLAGS } from "./constants/index.js";
|
|
7
|
+
import { default as default2 } from "./components/ChatAIDraft/index.js";
|
|
8
|
+
import { default as default3 } from "./components/CountryFlag/index.js";
|
|
9
|
+
import { default as default4 } from "./components/LoadingCircular/index.js";
|
|
10
|
+
import { default as default5 } from "./components/LoadingContainer/index.js";
|
|
11
|
+
import { default as default6 } from "./components/Tooltip/index.js";
|
|
12
|
+
import { getBaseUrl, getGroupwareUrl, initHanbiroReactSDK } from "./utils/url.js";
|
|
13
|
+
export {
|
|
14
|
+
AI_LANG_FLAGS,
|
|
15
|
+
default2 as ChatAIDraft,
|
|
16
|
+
default3 as CountryFlag,
|
|
17
|
+
default4 as LoadingCircular,
|
|
18
|
+
default5 as LoadingContainer,
|
|
19
|
+
default6 as Tooltip,
|
|
20
|
+
getBaseUrl,
|
|
21
|
+
getGroupwareUrl,
|
|
22
|
+
initHanbiroReactSDK
|
|
23
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { uuid } from "./Utils.js";
|
|
2
|
+
var __assign = function() {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var injectScriptTag = function(doc, item, handler) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
var scriptTag = doc.createElement("script");
|
|
16
|
+
scriptTag.referrerPolicy = "origin";
|
|
17
|
+
scriptTag.type = "application/javascript";
|
|
18
|
+
scriptTag.id = item.id;
|
|
19
|
+
scriptTag.src = item.src;
|
|
20
|
+
scriptTag.async = (_a = item.async) !== null && _a !== void 0 ? _a : false;
|
|
21
|
+
scriptTag.defer = (_b = item.defer) !== null && _b !== void 0 ? _b : false;
|
|
22
|
+
var loadHandler = function() {
|
|
23
|
+
scriptTag.removeEventListener("load", loadHandler);
|
|
24
|
+
scriptTag.removeEventListener("error", errorHandler);
|
|
25
|
+
handler(item.src);
|
|
26
|
+
};
|
|
27
|
+
var errorHandler = function(err) {
|
|
28
|
+
scriptTag.removeEventListener("load", loadHandler);
|
|
29
|
+
scriptTag.removeEventListener("error", errorHandler);
|
|
30
|
+
handler(item.src, err);
|
|
31
|
+
};
|
|
32
|
+
scriptTag.addEventListener("load", loadHandler);
|
|
33
|
+
scriptTag.addEventListener("error", errorHandler);
|
|
34
|
+
if (doc.head) {
|
|
35
|
+
doc.head.appendChild(scriptTag);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var createDocumentScriptLoader = function(doc) {
|
|
39
|
+
var lookup = {};
|
|
40
|
+
var scriptLoadOrErrorHandler = function(src, err) {
|
|
41
|
+
var item = lookup[src];
|
|
42
|
+
item.done = true;
|
|
43
|
+
item.error = err;
|
|
44
|
+
for (var _i = 0, _a = item.handlers; _i < _a.length; _i++) {
|
|
45
|
+
var h = _a[_i];
|
|
46
|
+
h(src, err);
|
|
47
|
+
}
|
|
48
|
+
item.handlers = [];
|
|
49
|
+
};
|
|
50
|
+
var loadScripts = function(items, success, failure) {
|
|
51
|
+
var failureOrLog = function(err) {
|
|
52
|
+
return failure !== void 0 ? failure(err) : console.error(err);
|
|
53
|
+
};
|
|
54
|
+
if (items.length === 0) {
|
|
55
|
+
failureOrLog(new Error("At least one script must be provided"));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
var successCount = 0;
|
|
59
|
+
var failed = false;
|
|
60
|
+
var loaded = function(_src, err) {
|
|
61
|
+
if (failed) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (err) {
|
|
65
|
+
failed = true;
|
|
66
|
+
failureOrLog(err);
|
|
67
|
+
} else if (++successCount === items.length) {
|
|
68
|
+
success();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
72
|
+
var item = items_1[_i];
|
|
73
|
+
var existing = lookup[item.src];
|
|
74
|
+
if (existing) {
|
|
75
|
+
if (existing.done) {
|
|
76
|
+
loaded(item.src, existing.error);
|
|
77
|
+
} else {
|
|
78
|
+
existing.handlers.push(loaded);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
var id = uuid("tiny-");
|
|
82
|
+
lookup[item.src] = {
|
|
83
|
+
id,
|
|
84
|
+
src: item.src,
|
|
85
|
+
done: false,
|
|
86
|
+
error: null,
|
|
87
|
+
handlers: [loaded]
|
|
88
|
+
};
|
|
89
|
+
injectScriptTag(doc, __assign({ id }, item), scriptLoadOrErrorHandler);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var deleteScripts = function() {
|
|
94
|
+
var _a;
|
|
95
|
+
for (var _i = 0, _b = Object.values(lookup); _i < _b.length; _i++) {
|
|
96
|
+
var item = _b[_i];
|
|
97
|
+
var scriptTag = doc.getElementById(item.id);
|
|
98
|
+
if (scriptTag != null && scriptTag.tagName === "SCRIPT") {
|
|
99
|
+
(_a = scriptTag.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(scriptTag);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
lookup = {};
|
|
103
|
+
};
|
|
104
|
+
var getDocument = function() {
|
|
105
|
+
return doc;
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
loadScripts,
|
|
109
|
+
deleteScripts,
|
|
110
|
+
getDocument
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
var createScriptLoader = function() {
|
|
114
|
+
var cache = [];
|
|
115
|
+
var getDocumentScriptLoader = function(doc) {
|
|
116
|
+
var loader = cache.find(function(l) {
|
|
117
|
+
return l.getDocument() === doc;
|
|
118
|
+
});
|
|
119
|
+
if (loader === void 0) {
|
|
120
|
+
loader = createDocumentScriptLoader(doc);
|
|
121
|
+
cache.push(loader);
|
|
122
|
+
}
|
|
123
|
+
return loader;
|
|
124
|
+
};
|
|
125
|
+
var loadList = function(doc, items, delay, success, failure) {
|
|
126
|
+
var doLoad = function() {
|
|
127
|
+
return getDocumentScriptLoader(doc).loadScripts(items, success, failure);
|
|
128
|
+
};
|
|
129
|
+
if (delay > 0) {
|
|
130
|
+
setTimeout(doLoad, delay);
|
|
131
|
+
} else {
|
|
132
|
+
doLoad();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var reinitialize = function() {
|
|
136
|
+
for (var loader = cache.pop(); loader != null; loader = cache.pop()) {
|
|
137
|
+
loader.deleteScripts();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
loadList,
|
|
142
|
+
reinitialize
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
var ScriptLoader = createScriptLoader();
|
|
146
|
+
export {
|
|
147
|
+
ScriptLoader
|
|
148
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { eventPropTypes } from "./components/EditorPropTypes.js";
|
|
2
|
+
var isFunction = function(x) {
|
|
3
|
+
return typeof x === "function";
|
|
4
|
+
};
|
|
5
|
+
var isEventProp = function(name) {
|
|
6
|
+
return name in eventPropTypes;
|
|
7
|
+
};
|
|
8
|
+
var eventAttrToEventName = function(attrName) {
|
|
9
|
+
return attrName.substr(2);
|
|
10
|
+
};
|
|
11
|
+
var configHandlers2 = function(handlerLookup, on, off, adapter, prevProps, props, boundHandlers) {
|
|
12
|
+
var prevEventKeys = Object.keys(prevProps).filter(isEventProp);
|
|
13
|
+
var currEventKeys = Object.keys(props).filter(isEventProp);
|
|
14
|
+
var removedKeys = prevEventKeys.filter(function(key) {
|
|
15
|
+
return props[key] === void 0;
|
|
16
|
+
});
|
|
17
|
+
var addedKeys = currEventKeys.filter(function(key) {
|
|
18
|
+
return prevProps[key] === void 0;
|
|
19
|
+
});
|
|
20
|
+
removedKeys.forEach(function(key) {
|
|
21
|
+
var eventName = eventAttrToEventName(key);
|
|
22
|
+
var wrappedHandler = boundHandlers[eventName];
|
|
23
|
+
off(eventName, wrappedHandler);
|
|
24
|
+
delete boundHandlers[eventName];
|
|
25
|
+
});
|
|
26
|
+
addedKeys.forEach(function(key) {
|
|
27
|
+
var wrappedHandler = adapter(handlerLookup, key);
|
|
28
|
+
var eventName = eventAttrToEventName(key);
|
|
29
|
+
boundHandlers[eventName] = wrappedHandler;
|
|
30
|
+
on(eventName, wrappedHandler);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
var configHandlers = function(editor, prevProps, props, boundHandlers, lookup) {
|
|
34
|
+
return configHandlers2(
|
|
35
|
+
lookup,
|
|
36
|
+
editor.on.bind(editor),
|
|
37
|
+
editor.off.bind(editor),
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
39
|
+
function(handlerLookup, key) {
|
|
40
|
+
return function(e) {
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = handlerLookup(key)) === null || _a === void 0 ? void 0 : _a(e, editor);
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
prevProps,
|
|
46
|
+
props,
|
|
47
|
+
boundHandlers
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
var unique = 0;
|
|
51
|
+
var uuid = function(prefix) {
|
|
52
|
+
var time = Date.now();
|
|
53
|
+
var random = Math.floor(Math.random() * 1e9);
|
|
54
|
+
unique++;
|
|
55
|
+
return prefix + "_" + random + unique + String(time);
|
|
56
|
+
};
|
|
57
|
+
var isTextareaOrInput = function(element) {
|
|
58
|
+
return element !== null && (element.tagName.toLowerCase() === "textarea" || element.tagName.toLowerCase() === "input");
|
|
59
|
+
};
|
|
60
|
+
var normalizePluginArray = function(plugins) {
|
|
61
|
+
if (typeof plugins === "undefined" || plugins === "") {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return Array.isArray(plugins) ? plugins : plugins.split(" ");
|
|
65
|
+
};
|
|
66
|
+
var mergePlugins = function(initPlugins, inputPlugins) {
|
|
67
|
+
return normalizePluginArray(initPlugins).concat(normalizePluginArray(inputPlugins));
|
|
68
|
+
};
|
|
69
|
+
var isBeforeInputEventAvailable = function() {
|
|
70
|
+
return window.InputEvent && typeof InputEvent.prototype.getTargetRanges === "function";
|
|
71
|
+
};
|
|
72
|
+
var isInDoc = function(elem) {
|
|
73
|
+
if (!("isConnected" in Node.prototype)) {
|
|
74
|
+
var current = elem;
|
|
75
|
+
var parent_1 = elem.parentNode;
|
|
76
|
+
while (parent_1 != null) {
|
|
77
|
+
current = parent_1;
|
|
78
|
+
parent_1 = current.parentNode;
|
|
79
|
+
}
|
|
80
|
+
return current === elem.ownerDocument;
|
|
81
|
+
}
|
|
82
|
+
return elem.isConnected;
|
|
83
|
+
};
|
|
84
|
+
var setMode = function(editor, mode) {
|
|
85
|
+
if (editor !== void 0) {
|
|
86
|
+
if (editor.mode != null && typeof editor.mode === "object" && typeof editor.mode.set === "function") {
|
|
87
|
+
editor.mode.set(mode);
|
|
88
|
+
} else {
|
|
89
|
+
editor.setMode(mode);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
export {
|
|
94
|
+
configHandlers,
|
|
95
|
+
configHandlers2,
|
|
96
|
+
isBeforeInputEventAvailable,
|
|
97
|
+
isFunction,
|
|
98
|
+
isInDoc,
|
|
99
|
+
isTextareaOrInput,
|
|
100
|
+
mergePlugins,
|
|
101
|
+
setMode,
|
|
102
|
+
uuid
|
|
103
|
+
};
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ScriptLoader } from "../ScriptLoader2.js";
|
|
3
|
+
import { getTinymce } from "../TinyMCE.js";
|
|
4
|
+
import { isFunction, isInDoc, setMode, isTextareaOrInput, mergePlugins, uuid, isBeforeInputEventAvailable, configHandlers } from "../Utils.js";
|
|
5
|
+
import { EditorPropTypes } from "./EditorPropTypes.js";
|
|
6
|
+
var __extends = /* @__PURE__ */ function() {
|
|
7
|
+
var extendStatics = function(d, b) {
|
|
8
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
9
|
+
d2.__proto__ = b2;
|
|
10
|
+
} || function(d2, b2) {
|
|
11
|
+
for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
|
|
12
|
+
};
|
|
13
|
+
return extendStatics(d, b);
|
|
14
|
+
};
|
|
15
|
+
return function(d, b) {
|
|
16
|
+
if (typeof b !== "function" && b !== null)
|
|
17
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
18
|
+
extendStatics(d, b);
|
|
19
|
+
function __() {
|
|
20
|
+
this.constructor = d;
|
|
21
|
+
}
|
|
22
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
23
|
+
};
|
|
24
|
+
}();
|
|
25
|
+
var __assign = function() {
|
|
26
|
+
__assign = Object.assign || function(t) {
|
|
27
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
28
|
+
s = arguments[i];
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
30
|
+
t[p] = s[p];
|
|
31
|
+
}
|
|
32
|
+
return t;
|
|
33
|
+
};
|
|
34
|
+
return __assign.apply(this, arguments);
|
|
35
|
+
};
|
|
36
|
+
var Editor = (
|
|
37
|
+
/** @class */
|
|
38
|
+
function(_super) {
|
|
39
|
+
__extends(Editor2, _super);
|
|
40
|
+
function Editor2(props) {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
var _this = _super.call(this, props) || this;
|
|
43
|
+
_this.rollbackTimer = void 0;
|
|
44
|
+
_this.valueCursor = void 0;
|
|
45
|
+
_this.rollbackChange = function() {
|
|
46
|
+
var editor = _this.editor;
|
|
47
|
+
var value = _this.props.value;
|
|
48
|
+
if (editor && value && value !== _this.currentContent) {
|
|
49
|
+
editor.undoManager.ignore(function() {
|
|
50
|
+
editor.setContent(value);
|
|
51
|
+
if (_this.valueCursor && (!_this.inline || editor.hasFocus())) {
|
|
52
|
+
try {
|
|
53
|
+
editor.selection.moveToBookmark(_this.valueCursor);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
_this.rollbackTimer = void 0;
|
|
60
|
+
};
|
|
61
|
+
_this.handleBeforeInput = function(_evt) {
|
|
62
|
+
if (_this.props.value !== void 0 && _this.props.value === _this.currentContent && _this.editor) {
|
|
63
|
+
if (!_this.inline || _this.editor.hasFocus()) {
|
|
64
|
+
try {
|
|
65
|
+
_this.valueCursor = _this.editor.selection.getBookmark(3);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
_this.handleBeforeInputSpecial = function(evt) {
|
|
72
|
+
if (evt.key === "Enter" || evt.key === "Backspace" || evt.key === "Delete") {
|
|
73
|
+
_this.handleBeforeInput(evt);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
_this.handleEditorChange = function(_evt) {
|
|
77
|
+
var editor = _this.editor;
|
|
78
|
+
if (editor && editor.initialized) {
|
|
79
|
+
var newContent = editor.getContent();
|
|
80
|
+
if (_this.props.value !== void 0 && _this.props.value !== newContent && _this.props.rollback !== false) {
|
|
81
|
+
if (!_this.rollbackTimer) {
|
|
82
|
+
_this.rollbackTimer = window.setTimeout(_this.rollbackChange, typeof _this.props.rollback === "number" ? _this.props.rollback : 200);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (newContent !== _this.currentContent) {
|
|
86
|
+
_this.currentContent = newContent;
|
|
87
|
+
if (isFunction(_this.props.onEditorChange)) {
|
|
88
|
+
_this.props.onEditorChange(newContent, editor);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
_this.handleEditorChangeSpecial = function(evt) {
|
|
94
|
+
if (evt.key === "Backspace" || evt.key === "Delete") {
|
|
95
|
+
_this.handleEditorChange(evt);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
_this.initialise = function(attempts) {
|
|
99
|
+
var _a2, _b2, _c2;
|
|
100
|
+
if (attempts === void 0) {
|
|
101
|
+
attempts = 0;
|
|
102
|
+
}
|
|
103
|
+
var target = _this.elementRef.current;
|
|
104
|
+
if (!target) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!isInDoc(target)) {
|
|
108
|
+
if (attempts === 0) {
|
|
109
|
+
setTimeout(function() {
|
|
110
|
+
return _this.initialise(1);
|
|
111
|
+
}, 1);
|
|
112
|
+
} else if (attempts < 100) {
|
|
113
|
+
setTimeout(function() {
|
|
114
|
+
return _this.initialise(attempts + 1);
|
|
115
|
+
}, 100);
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error("tinymce can only be initialised when in a document");
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
var tinymce = getTinymce(_this.view);
|
|
122
|
+
if (!tinymce) {
|
|
123
|
+
throw new Error("tinymce should have been loaded into global scope");
|
|
124
|
+
}
|
|
125
|
+
var finalInit = __assign(__assign({}, _this.props.init), { selector: void 0, target, readonly: _this.props.disabled, inline: _this.inline, plugins: mergePlugins((_a2 = _this.props.init) === null || _a2 === void 0 ? void 0 : _a2.plugins, _this.props.plugins), toolbar: (_b2 = _this.props.toolbar) !== null && _b2 !== void 0 ? _b2 : (_c2 = _this.props.init) === null || _c2 === void 0 ? void 0 : _c2.toolbar, setup: function(editor) {
|
|
126
|
+
_this.editor = editor;
|
|
127
|
+
_this.bindHandlers({});
|
|
128
|
+
if (_this.inline && !isTextareaOrInput(target)) {
|
|
129
|
+
editor.once("PostRender", function(_evt) {
|
|
130
|
+
editor.setContent(_this.getInitialValue(), { no_events: true });
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (_this.props.init && isFunction(_this.props.init.setup)) {
|
|
134
|
+
_this.props.init.setup(editor);
|
|
135
|
+
}
|
|
136
|
+
}, init_instance_callback: function(editor) {
|
|
137
|
+
var _a3, _b3;
|
|
138
|
+
var initialValue = _this.getInitialValue();
|
|
139
|
+
_this.currentContent = (_a3 = _this.currentContent) !== null && _a3 !== void 0 ? _a3 : editor.getContent();
|
|
140
|
+
if (_this.currentContent !== initialValue) {
|
|
141
|
+
_this.currentContent = initialValue;
|
|
142
|
+
editor.setContent(initialValue);
|
|
143
|
+
editor.undoManager.clear();
|
|
144
|
+
editor.undoManager.add();
|
|
145
|
+
editor.setDirty(false);
|
|
146
|
+
}
|
|
147
|
+
var disabled = (_b3 = _this.props.disabled) !== null && _b3 !== void 0 ? _b3 : false;
|
|
148
|
+
setMode(_this.editor, disabled ? "readonly" : "design");
|
|
149
|
+
if (_this.props.init && isFunction(_this.props.init.init_instance_callback)) {
|
|
150
|
+
_this.props.init.init_instance_callback(editor);
|
|
151
|
+
}
|
|
152
|
+
} });
|
|
153
|
+
if (!_this.inline) {
|
|
154
|
+
target.style.visibility = "";
|
|
155
|
+
}
|
|
156
|
+
if (isTextareaOrInput(target)) {
|
|
157
|
+
target.value = _this.getInitialValue();
|
|
158
|
+
}
|
|
159
|
+
tinymce.init(finalInit);
|
|
160
|
+
};
|
|
161
|
+
_this.id = _this.props.id || uuid("tiny-react");
|
|
162
|
+
_this.elementRef = React.createRef();
|
|
163
|
+
_this.inline = (_c = (_a = _this.props.inline) !== null && _a !== void 0 ? _a : (_b = _this.props.init) === null || _b === void 0 ? void 0 : _b.inline) !== null && _c !== void 0 ? _c : false;
|
|
164
|
+
_this.boundHandlers = {};
|
|
165
|
+
return _this;
|
|
166
|
+
}
|
|
167
|
+
Object.defineProperty(Editor2.prototype, "view", {
|
|
168
|
+
get: function() {
|
|
169
|
+
var _a, _b;
|
|
170
|
+
return (_b = (_a = this.elementRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.defaultView) !== null && _b !== void 0 ? _b : window;
|
|
171
|
+
},
|
|
172
|
+
enumerable: false,
|
|
173
|
+
configurable: true
|
|
174
|
+
});
|
|
175
|
+
Editor2.prototype.componentDidUpdate = function(prevProps) {
|
|
176
|
+
var _this = this;
|
|
177
|
+
var _a, _b;
|
|
178
|
+
if (this.rollbackTimer) {
|
|
179
|
+
clearTimeout(this.rollbackTimer);
|
|
180
|
+
this.rollbackTimer = void 0;
|
|
181
|
+
}
|
|
182
|
+
if (this.editor) {
|
|
183
|
+
this.bindHandlers(prevProps);
|
|
184
|
+
if (this.editor.initialized) {
|
|
185
|
+
this.currentContent = (_a = this.currentContent) !== null && _a !== void 0 ? _a : this.editor.getContent();
|
|
186
|
+
if (typeof this.props.initialValue === "string" && this.props.initialValue !== prevProps.initialValue) {
|
|
187
|
+
this.editor.setContent(this.props.initialValue);
|
|
188
|
+
this.editor.undoManager.clear();
|
|
189
|
+
this.editor.undoManager.add();
|
|
190
|
+
this.editor.setDirty(false);
|
|
191
|
+
} else if (typeof this.props.value === "string" && this.props.value !== this.currentContent) {
|
|
192
|
+
var localEditor_1 = this.editor;
|
|
193
|
+
localEditor_1.undoManager.transact(function() {
|
|
194
|
+
var cursor;
|
|
195
|
+
if (!_this.inline || localEditor_1.hasFocus()) {
|
|
196
|
+
try {
|
|
197
|
+
cursor = localEditor_1.selection.getBookmark(3);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
var valueCursor = _this.valueCursor;
|
|
202
|
+
localEditor_1.setContent(_this.props.value);
|
|
203
|
+
if (!_this.inline || localEditor_1.hasFocus()) {
|
|
204
|
+
for (var _i = 0, _a2 = [cursor, valueCursor]; _i < _a2.length; _i++) {
|
|
205
|
+
var bookmark = _a2[_i];
|
|
206
|
+
if (bookmark) {
|
|
207
|
+
try {
|
|
208
|
+
localEditor_1.selection.moveToBookmark(bookmark);
|
|
209
|
+
_this.valueCursor = bookmark;
|
|
210
|
+
break;
|
|
211
|
+
} catch (e) {
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (this.props.disabled !== prevProps.disabled) {
|
|
219
|
+
var disabled = (_b = this.props.disabled) !== null && _b !== void 0 ? _b : false;
|
|
220
|
+
setMode(this.editor, disabled ? "readonly" : "design");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
Editor2.prototype.componentDidMount = function() {
|
|
226
|
+
var _this = this;
|
|
227
|
+
var _a, _b, _c, _d, _e;
|
|
228
|
+
if (getTinymce(this.view) !== null) {
|
|
229
|
+
this.initialise();
|
|
230
|
+
} else if (Array.isArray(this.props.tinymceScriptSrc) && this.props.tinymceScriptSrc.length === 0) {
|
|
231
|
+
(_b = (_a = this.props).onScriptsLoadError) === null || _b === void 0 ? void 0 : _b.call(_a, new Error("No `tinymce` global is present but the `tinymceScriptSrc` prop was an empty array."));
|
|
232
|
+
} else if ((_c = this.elementRef.current) === null || _c === void 0 ? void 0 : _c.ownerDocument) {
|
|
233
|
+
var successHandler = function() {
|
|
234
|
+
var _a2, _b2;
|
|
235
|
+
(_b2 = (_a2 = _this.props).onScriptsLoad) === null || _b2 === void 0 ? void 0 : _b2.call(_a2);
|
|
236
|
+
_this.initialise();
|
|
237
|
+
};
|
|
238
|
+
var errorHandler = function(err) {
|
|
239
|
+
var _a2, _b2;
|
|
240
|
+
(_b2 = (_a2 = _this.props).onScriptsLoadError) === null || _b2 === void 0 ? void 0 : _b2.call(_a2, err);
|
|
241
|
+
};
|
|
242
|
+
ScriptLoader.loadList(this.elementRef.current.ownerDocument, this.getScriptSources(), (_e = (_d = this.props.scriptLoading) === null || _d === void 0 ? void 0 : _d.delay) !== null && _e !== void 0 ? _e : 0, successHandler, errorHandler);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
Editor2.prototype.componentWillUnmount = function() {
|
|
246
|
+
var _this = this;
|
|
247
|
+
var editor = this.editor;
|
|
248
|
+
if (editor) {
|
|
249
|
+
editor.off(this.changeEvents(), this.handleEditorChange);
|
|
250
|
+
editor.off(this.beforeInputEvent(), this.handleBeforeInput);
|
|
251
|
+
editor.off("keypress", this.handleEditorChangeSpecial);
|
|
252
|
+
editor.off("keydown", this.handleBeforeInputSpecial);
|
|
253
|
+
editor.off("NewBlock", this.handleEditorChange);
|
|
254
|
+
Object.keys(this.boundHandlers).forEach(function(eventName) {
|
|
255
|
+
editor.off(eventName, _this.boundHandlers[eventName]);
|
|
256
|
+
});
|
|
257
|
+
this.boundHandlers = {};
|
|
258
|
+
editor.remove();
|
|
259
|
+
this.editor = void 0;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
Editor2.prototype.render = function() {
|
|
263
|
+
return this.inline ? this.renderInline() : this.renderIframe();
|
|
264
|
+
};
|
|
265
|
+
Editor2.prototype.changeEvents = function() {
|
|
266
|
+
var _a, _b, _c;
|
|
267
|
+
var isIE = (_c = (_b = (_a = getTinymce(this.view)) === null || _a === void 0 ? void 0 : _a.Env) === null || _b === void 0 ? void 0 : _b.browser) === null || _c === void 0 ? void 0 : _c.isIE();
|
|
268
|
+
return isIE ? "change keyup compositionend setcontent CommentChange" : "change input compositionend setcontent CommentChange";
|
|
269
|
+
};
|
|
270
|
+
Editor2.prototype.beforeInputEvent = function() {
|
|
271
|
+
return isBeforeInputEventAvailable() ? "beforeinput SelectionChange" : "SelectionChange";
|
|
272
|
+
};
|
|
273
|
+
Editor2.prototype.renderInline = function() {
|
|
274
|
+
var _a = this.props.tagName, tagName = _a === void 0 ? "div" : _a;
|
|
275
|
+
return React.createElement(tagName, {
|
|
276
|
+
ref: this.elementRef,
|
|
277
|
+
id: this.id
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
Editor2.prototype.renderIframe = function() {
|
|
281
|
+
return React.createElement("textarea", {
|
|
282
|
+
ref: this.elementRef,
|
|
283
|
+
style: { visibility: "hidden" },
|
|
284
|
+
name: this.props.textareaName,
|
|
285
|
+
id: this.id
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
Editor2.prototype.getScriptSources = function() {
|
|
289
|
+
var _a, _b;
|
|
290
|
+
var async = (_a = this.props.scriptLoading) === null || _a === void 0 ? void 0 : _a.async;
|
|
291
|
+
var defer = (_b = this.props.scriptLoading) === null || _b === void 0 ? void 0 : _b.defer;
|
|
292
|
+
if (this.props.tinymceScriptSrc !== void 0) {
|
|
293
|
+
if (typeof this.props.tinymceScriptSrc === "string") {
|
|
294
|
+
return [{ src: this.props.tinymceScriptSrc, async, defer }];
|
|
295
|
+
}
|
|
296
|
+
return this.props.tinymceScriptSrc.map(function(item) {
|
|
297
|
+
if (typeof item === "string") {
|
|
298
|
+
return { src: item, async, defer };
|
|
299
|
+
} else {
|
|
300
|
+
return item;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
var channel = this.props.cloudChannel;
|
|
305
|
+
var apiKey = this.props.apiKey ? this.props.apiKey : "no-api-key";
|
|
306
|
+
var cloudTinyJs = "https://cdn.tiny.cloud/1/".concat(apiKey, "/tinymce/").concat(channel, "/tinymce.min.js");
|
|
307
|
+
return [{ src: cloudTinyJs, async, defer }];
|
|
308
|
+
};
|
|
309
|
+
Editor2.prototype.getInitialValue = function() {
|
|
310
|
+
if (typeof this.props.initialValue === "string") {
|
|
311
|
+
return this.props.initialValue;
|
|
312
|
+
} else if (typeof this.props.value === "string") {
|
|
313
|
+
return this.props.value;
|
|
314
|
+
} else {
|
|
315
|
+
return "";
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
Editor2.prototype.bindHandlers = function(prevProps) {
|
|
319
|
+
var _this = this;
|
|
320
|
+
if (this.editor !== void 0) {
|
|
321
|
+
configHandlers(this.editor, prevProps, this.props, this.boundHandlers, function(key) {
|
|
322
|
+
return _this.props[key];
|
|
323
|
+
});
|
|
324
|
+
var isValueControlled = function(p) {
|
|
325
|
+
return p.onEditorChange !== void 0 || p.value !== void 0;
|
|
326
|
+
};
|
|
327
|
+
var wasControlled = isValueControlled(prevProps);
|
|
328
|
+
var nowControlled = isValueControlled(this.props);
|
|
329
|
+
if (!wasControlled && nowControlled) {
|
|
330
|
+
this.editor.on(this.changeEvents(), this.handleEditorChange);
|
|
331
|
+
this.editor.on(this.beforeInputEvent(), this.handleBeforeInput);
|
|
332
|
+
this.editor.on("keydown", this.handleBeforeInputSpecial);
|
|
333
|
+
this.editor.on("keyup", this.handleEditorChangeSpecial);
|
|
334
|
+
this.editor.on("NewBlock", this.handleEditorChange);
|
|
335
|
+
} else if (wasControlled && !nowControlled) {
|
|
336
|
+
this.editor.off(this.changeEvents(), this.handleEditorChange);
|
|
337
|
+
this.editor.off(this.beforeInputEvent(), this.handleBeforeInput);
|
|
338
|
+
this.editor.off("keydown", this.handleBeforeInputSpecial);
|
|
339
|
+
this.editor.off("keyup", this.handleEditorChangeSpecial);
|
|
340
|
+
this.editor.off("NewBlock", this.handleEditorChange);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
Editor2.propTypes = EditorPropTypes;
|
|
345
|
+
Editor2.defaultProps = {
|
|
346
|
+
cloudChannel: "6"
|
|
347
|
+
};
|
|
348
|
+
return Editor2;
|
|
349
|
+
}(React.Component)
|
|
350
|
+
);
|
|
351
|
+
export {
|
|
352
|
+
Editor
|
|
353
|
+
};
|