@uiw/react-md-editor 3.19.0 → 3.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mdeditor.js +1559 -1578
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.js.map +1 -1
- package/esm/Editor.js +43 -67
- package/esm/Editor.js.map +1 -1
- package/esm/commands/bold.js +4 -4
- package/esm/commands/bold.js.map +1 -1
- package/esm/commands/code.js +4 -6
- package/esm/commands/code.js.map +1 -1
- package/esm/commands/comment.js +4 -4
- package/esm/commands/comment.js.map +1 -1
- package/esm/commands/divider.js.map +1 -1
- package/esm/commands/fullscreen.js +3 -4
- package/esm/commands/fullscreen.js.map +2 -2
- package/esm/commands/group.js +2 -4
- package/esm/commands/group.js.map +1 -1
- package/esm/commands/hr.js.map +1 -1
- package/esm/commands/image.js +4 -4
- package/esm/commands/image.js.map +1 -1
- package/esm/commands/index.d.ts +2 -2
- package/esm/commands/index.js +6 -17
- package/esm/commands/index.js.map +3 -2
- package/esm/commands/italic.js +4 -4
- package/esm/commands/italic.js.map +1 -1
- package/esm/commands/link.js +4 -4
- package/esm/commands/link.js.map +1 -1
- package/esm/commands/list.js +4 -4
- package/esm/commands/list.js.map +1 -1
- package/esm/commands/preview.js +21 -3
- package/esm/commands/preview.js.map +7 -2
- package/esm/commands/quote.js +2 -1
- package/esm/commands/quote.js.map +1 -1
- package/esm/commands/strikeThrough.js +4 -4
- package/esm/commands/strikeThrough.js.map +1 -1
- package/esm/commands/title.js.map +1 -1
- package/esm/commands/title1.js.map +1 -1
- package/esm/commands/title2.js.map +1 -1
- package/esm/commands/title3.js.map +1 -1
- package/esm/commands/title4.js.map +1 -1
- package/esm/commands/title5.js.map +1 -1
- package/esm/commands/title6.js.map +1 -1
- package/esm/components/DragBar/index.js +2 -9
- package/esm/components/DragBar/index.js.map +1 -1
- package/esm/components/TextArea/Markdown.js +2 -7
- package/esm/components/TextArea/Markdown.js.map +1 -1
- package/esm/components/TextArea/Textarea.js +8 -11
- package/esm/components/TextArea/Textarea.js.map +1 -1
- package/esm/components/TextArea/handleKeyDown.js +2 -16
- package/esm/components/TextArea/handleKeyDown.js.map +1 -1
- package/esm/components/TextArea/index.js +11 -15
- package/esm/components/TextArea/index.js.map +1 -1
- package/esm/components/TextArea/shortcuts.js +1 -17
- package/esm/components/TextArea/shortcuts.js.map +2 -2
- package/esm/components/Toolbar/Child.js +2 -1
- package/esm/components/Toolbar/Child.js.map +1 -1
- package/esm/components/Toolbar/index.js +2 -12
- package/esm/components/Toolbar/index.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/utils/InsertTextAtPosition.js +28 -34
- package/esm/utils/InsertTextAtPosition.js.map +1 -1
- package/esm/utils/markdownUtils.js +14 -23
- package/esm/utils/markdownUtils.js.map +1 -1
- package/lib/Context.js +0 -6
- package/lib/Context.js.map +1 -1
- package/lib/Editor.js +74 -114
- package/lib/Editor.js.map +1 -1
- package/lib/commands/bold.js +4 -9
- package/lib/commands/bold.js.map +1 -1
- package/lib/commands/code.js +4 -11
- package/lib/commands/code.js.map +1 -1
- package/lib/commands/comment.js +4 -7
- package/lib/commands/comment.js.map +1 -1
- package/lib/commands/divider.js.map +1 -1
- package/lib/commands/fullscreen.js +3 -8
- package/lib/commands/fullscreen.js.map +2 -2
- package/lib/commands/group.js +2 -10
- package/lib/commands/group.js.map +1 -1
- package/lib/commands/hr.js +0 -4
- package/lib/commands/hr.js.map +1 -1
- package/lib/commands/image.js +4 -9
- package/lib/commands/image.js.map +1 -1
- package/lib/commands/index.d.ts +2 -2
- package/lib/commands/index.js +4 -41
- package/lib/commands/index.js.map +3 -2
- package/lib/commands/italic.js +4 -9
- package/lib/commands/italic.js.map +1 -1
- package/lib/commands/link.js +4 -9
- package/lib/commands/link.js.map +1 -1
- package/lib/commands/list.js +4 -10
- package/lib/commands/list.js.map +1 -1
- package/lib/commands/preview.js +21 -7
- package/lib/commands/preview.js.map +7 -2
- package/lib/commands/quote.js +2 -6
- package/lib/commands/quote.js.map +1 -1
- package/lib/commands/strikeThrough.js +4 -9
- package/lib/commands/strikeThrough.js.map +1 -1
- package/lib/commands/title.js +0 -6
- package/lib/commands/title.js.map +1 -1
- package/lib/commands/title1.js +0 -5
- package/lib/commands/title1.js.map +1 -1
- package/lib/commands/title2.js +0 -5
- package/lib/commands/title2.js.map +1 -1
- package/lib/commands/title3.js +0 -5
- package/lib/commands/title3.js.map +1 -1
- package/lib/commands/title4.js +0 -5
- package/lib/commands/title4.js.map +1 -1
- package/lib/commands/title5.js +0 -5
- package/lib/commands/title5.js.map +1 -1
- package/lib/commands/title6.js +0 -5
- package/lib/commands/title6.js.map +1 -1
- package/lib/components/DragBar/index.js +4 -15
- package/lib/components/DragBar/index.js.map +1 -1
- package/lib/components/TextArea/Markdown.js +6 -22
- package/lib/components/TextArea/Markdown.js.map +1 -1
- package/lib/components/TextArea/Textarea.js +15 -36
- package/lib/components/TextArea/Textarea.js.map +1 -1
- package/lib/components/TextArea/handleKeyDown.js +1 -18
- package/lib/components/TextArea/handleKeyDown.js.map +1 -1
- package/lib/components/TextArea/index.js +15 -37
- package/lib/components/TextArea/index.js.map +1 -1
- package/lib/components/TextArea/shortcuts.js +1 -17
- package/lib/components/TextArea/shortcuts.js.map +2 -2
- package/lib/components/Toolbar/Child.js +8 -18
- package/lib/components/Toolbar/Child.js.map +1 -1
- package/lib/components/Toolbar/index.js +14 -36
- package/lib/components/Toolbar/index.js.map +1 -1
- package/lib/index.js +0 -9
- package/lib/index.js.map +1 -1
- package/lib/utils/InsertTextAtPosition.js +28 -37
- package/lib/utils/InsertTextAtPosition.js.map +1 -1
- package/lib/utils/markdownUtils.js +17 -28
- package/lib/utils/markdownUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/fullscreen.tsx +3 -2
- package/src/commands/index.ts +3 -1
- package/src/commands/preview.tsx +35 -4
- package/src/components/TextArea/shortcuts.ts +2 -2
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = shortcutsHandle;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
function getCommands() {
|
|
13
10
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
14
11
|
var resulte = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -21,7 +18,6 @@ function getCommands() {
|
|
|
21
18
|
});
|
|
22
19
|
return resulte;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
function shortcutsHandle(e) {
|
|
26
22
|
var commands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
27
23
|
var commandOrchestrator = arguments.length > 2 ? arguments[2] : undefined;
|
|
@@ -29,35 +25,27 @@ function shortcutsHandle(e) {
|
|
|
29
25
|
var state = arguments.length > 4 ? arguments[4] : undefined;
|
|
30
26
|
var data = getCommands(commands || []);
|
|
31
27
|
var shortcuts = [];
|
|
32
|
-
|
|
33
28
|
if (e.altKey) {
|
|
34
29
|
shortcuts.push('alt');
|
|
35
30
|
}
|
|
36
|
-
|
|
37
31
|
if (e.shiftKey) {
|
|
38
32
|
shortcuts.push('shift');
|
|
39
33
|
}
|
|
40
|
-
|
|
41
34
|
if (e.metaKey) {
|
|
42
35
|
shortcuts.push('cmd');
|
|
43
36
|
}
|
|
44
|
-
|
|
45
37
|
if (e.ctrlKey) {
|
|
46
38
|
shortcuts.push('ctrl');
|
|
47
39
|
}
|
|
48
|
-
|
|
49
40
|
if (shortcuts.length > 0 && !/(control|alt|meta|shift)/.test(e.key.toLocaleLowerCase())) {
|
|
50
41
|
shortcuts.push(e.key.toLocaleLowerCase());
|
|
51
42
|
}
|
|
52
|
-
|
|
53
43
|
if (/escape/.test(e.key.toLocaleLowerCase())) {
|
|
54
44
|
shortcuts.push('escape');
|
|
55
45
|
}
|
|
56
|
-
|
|
57
46
|
if (shortcuts.length < 1) {
|
|
58
47
|
return;
|
|
59
48
|
}
|
|
60
|
-
|
|
61
49
|
var equal = !!data[shortcuts.join('+')];
|
|
62
50
|
var command = equal ? data[shortcuts.join('+')] : undefined;
|
|
63
51
|
Object.keys(data).forEach(function (item) {
|
|
@@ -65,22 +53,18 @@ function shortcutsHandle(e) {
|
|
|
65
53
|
if (/ctrlcmd/.test(v)) {
|
|
66
54
|
return shortcuts.includes('ctrl') || shortcuts.includes('cmd');
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
return shortcuts.includes(v);
|
|
70
57
|
});
|
|
71
|
-
|
|
72
58
|
if (isequal) {
|
|
73
59
|
command = data[item];
|
|
74
60
|
}
|
|
75
61
|
});
|
|
76
|
-
|
|
77
62
|
if (command && commandOrchestrator) {
|
|
78
63
|
e.stopPropagation();
|
|
79
64
|
e.preventDefault();
|
|
80
|
-
commandOrchestrator.executeCommand(command, dispatch, state);
|
|
65
|
+
commandOrchestrator.executeCommand(command, dispatch, state, shortcuts);
|
|
81
66
|
return;
|
|
82
67
|
}
|
|
83
68
|
}
|
|
84
|
-
|
|
85
69
|
module.exports = exports.default;
|
|
86
70
|
//# sourceMappingURL=shortcuts.js.map
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"../../../src/components/TextArea/shortcuts.ts"
|
|
47
47
|
],
|
|
48
48
|
"sourcesContent": [
|
|
49
|
-
"import { ICommand, TextAreaCommandOrchestrator } from '../../commands';\nimport { ContextStore, ExecuteCommandState } from '../../Context';\n\nfunction getCommands(data: ICommand[] = [], resulte: Record<string, ICommand> = {}): Record<string, ICommand> {\n data.forEach((item) => {\n if (item.children && Array.isArray(item.children)) {\n resulte = { ...resulte, ...getCommands(item.children || []) };\n } else if (item.keyCommand && item.shortcuts && item.execute) {\n resulte[item.shortcuts.toLocaleLowerCase()] = item;\n }\n });\n return resulte;\n}\n\nexport default function shortcutsHandle(\n e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,\n commands: ICommand[] = [],\n commandOrchestrator?: TextAreaCommandOrchestrator,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n) {\n const data = getCommands(commands || []);\n const shortcuts:
|
|
49
|
+
"import { ICommand, TextAreaCommandOrchestrator } from '../../commands';\nimport { ContextStore, ExecuteCommandState } from '../../Context';\n\nfunction getCommands(data: ICommand[] = [], resulte: Record<string, ICommand> = {}): Record<string, ICommand> {\n data.forEach((item) => {\n if (item.children && Array.isArray(item.children)) {\n resulte = { ...resulte, ...getCommands(item.children || []) };\n } else if (item.keyCommand && item.shortcuts && item.execute) {\n resulte[item.shortcuts.toLocaleLowerCase()] = item;\n }\n });\n return resulte;\n}\n\nexport default function shortcutsHandle(\n e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,\n commands: ICommand[] = [],\n commandOrchestrator?: TextAreaCommandOrchestrator,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n) {\n const data = getCommands(commands || []);\n const shortcuts: string[] = [];\n if (e.altKey) {\n shortcuts.push('alt');\n }\n if (e.shiftKey) {\n shortcuts.push('shift');\n }\n if (e.metaKey) {\n shortcuts.push('cmd');\n }\n if (e.ctrlKey) {\n shortcuts.push('ctrl');\n }\n if (shortcuts.length > 0 && !/(control|alt|meta|shift)/.test(e.key.toLocaleLowerCase())) {\n shortcuts.push(e.key.toLocaleLowerCase());\n }\n if (/escape/.test(e.key.toLocaleLowerCase())) {\n shortcuts.push('escape');\n }\n if (shortcuts.length < 1) {\n return;\n }\n\n let equal = !!data[shortcuts.join('+')];\n let command = equal ? data[shortcuts.join('+')] : undefined;\n\n Object.keys(data).forEach((item) => {\n const isequal = item.split('+').every((v) => {\n if (/ctrlcmd/.test(v)) {\n return shortcuts.includes('ctrl') || shortcuts.includes('cmd');\n }\n return shortcuts.includes(v);\n });\n if (isequal) {\n command = data[item];\n }\n });\n if (command && commandOrchestrator) {\n e.stopPropagation();\n e.preventDefault();\n commandOrchestrator.executeCommand(command, dispatch, state, shortcuts);\n return;\n }\n}\n"
|
|
50
50
|
],
|
|
51
|
-
"mappings": "
|
|
51
|
+
"mappings": ";;;;;;;;AAGA,SAASA,WAAW,GAA0F;EAAA,IAAzFC,IAAgB,uEAAG,EAAE;EAAA,IAAEC,OAAiC,uEAAG,CAAC,CAAC;EAChFD,IAAI,CAACE,OAAO,CAAC,UAACC,IAAI,EAAK;IACrB,IAAIA,IAAI,CAACC,QAAQ,IAAIC,KAAK,CAACC,OAAO,CAACH,IAAI,CAACC,QAAQ,CAAC,EAAE;MACjDH,OAAO,qEAAQA,OAAO,GAAKF,WAAW,CAACI,IAAI,CAACC,QAAQ,IAAI,EAAE,CAAC,CAAE;IAC/D,CAAC,MAAM,IAAID,IAAI,CAACI,UAAU,IAAIJ,IAAI,CAACK,SAAS,IAAIL,IAAI,CAACM,OAAO,EAAE;MAC5DR,OAAO,CAACE,IAAI,CAACK,SAAS,CAACE,iBAAiB,EAAE,CAAC,GAAGP,IAAI;IACpD;EACF,CAAC,CAAC;EACF,OAAOF,OAAO;AAChB;AAEe,SAASU,eAAe,CACrCC,CAA2D,EAK3D;EAAA,IAJAC,QAAoB,uEAAG,EAAE;EAAA,IACzBC,mBAAiD;EAAA,IACjDC,QAAuC;EAAA,IACvCC,KAA2B;EAE3B,IAAMhB,IAAI,GAAGD,WAAW,CAACc,QAAQ,IAAI,EAAE,CAAC;EACxC,IAAML,SAAmB,GAAG,EAAE;EAC9B,IAAII,CAAC,CAACK,MAAM,EAAE;IACZT,SAAS,CAACU,IAAI,CAAC,KAAK,CAAC;EACvB;EACA,IAAIN,CAAC,CAACO,QAAQ,EAAE;IACdX,SAAS,CAACU,IAAI,CAAC,OAAO,CAAC;EACzB;EACA,IAAIN,CAAC,CAACQ,OAAO,EAAE;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IAAI,CAAC;IACtB;EACF,CAAC,CAAC;EACF,IAAIwB,OAAO,IAAIb,mBAAmB,EAAE;IAClCF,CAAC,CAACwB,eAAe,EAAE;IACnBxB,CAAC,CAACyB,cAAc,EAAE;IAClBvB,mBAAmB,CAACwB,cAAc,CAACX,OAAO,EAAEZ,QAAQ,EAAEC,KAAK,EAAER,SAAS,CAAC;IACvE;EACF;AACF;AAAC"
|
|
52
52
|
}
|
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports["default"] = Child;
|
|
11
|
-
|
|
12
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
-
|
|
14
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
-
|
|
16
11
|
var _ = _interopRequireDefault(require("./"));
|
|
17
|
-
|
|
18
12
|
var _Context = require("../../Context");
|
|
19
|
-
|
|
20
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
-
|
|
22
14
|
function Child(props) {
|
|
23
15
|
var _ref = props || {},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
prefixCls = _ref.prefixCls,
|
|
17
|
+
groupName = _ref.groupName,
|
|
18
|
+
commands = _ref.commands,
|
|
19
|
+
children = _ref.children;
|
|
29
20
|
var _useContext = (0, _react.useContext)(_Context.EditorContext),
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
_useContext$barPopup = _useContext.barPopup,
|
|
22
|
+
barPopup = _useContext$barPopup === void 0 ? {} : _useContext$barPopup;
|
|
33
23
|
return (0, _react.useMemo)(function () {
|
|
34
24
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
35
25
|
className: "".concat(prefixCls, "-toolbar-child ").concat(groupName && barPopup[groupName] ? 'active' : ''),
|
|
@@ -42,9 +32,9 @@ function Child(props) {
|
|
|
42
32
|
isChild: true
|
|
43
33
|
})) : children
|
|
44
34
|
});
|
|
45
|
-
},
|
|
35
|
+
},
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
37
|
[commands, barPopup, groupName, prefixCls]);
|
|
47
38
|
}
|
|
48
|
-
|
|
49
39
|
module.exports = exports.default;
|
|
50
40
|
//# sourceMappingURL=Child.js.map
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"sourcesContent": [
|
|
23
23
|
"import React, { useContext, useMemo } from 'react';\nimport './Child.less';\nimport Toolbar, { IToolbarProps } from './';\nimport { EditorContext } from '../../Context';\n\nexport type ChildProps = IToolbarProps & {\n children?: JSX.Element;\n groupName?: string;\n};\n\nexport default function Child(props: ChildProps) {\n const { prefixCls, groupName, commands, children } = props || {};\n const { barPopup = {} } = useContext(EditorContext);\n return useMemo(\n () => (\n <div\n className={`${prefixCls}-toolbar-child ${groupName && barPopup[groupName] ? 'active' : ''}`}\n onClick={(e) => e.stopPropagation()}\n >\n {Array.isArray(commands) ? <Toolbar commands={commands} {...props} isChild /> : children}\n </div>\n ),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [commands, barPopup, groupName, prefixCls],\n );\n}\n"
|
|
24
24
|
],
|
|
25
|
-
"mappings": "
|
|
25
|
+
"mappings": ";;;;;;;;;AAAA;AAEA;AACA;AAA8C;AAO/B,SAASA,KAAK,CAACC,KAAiB,EAAE;EAC/C,WAAqDA,KAAK,IAAI,CAAC,CAAC;IAAxDC,SAAS,QAATA,SAAS;IAAEC,SAAS,QAATA,SAAS;IAAEC,QAAQ,QAARA,QAAQ;IAAEC,QAAQ,QAARA,QAAQ;EAChD,kBAA0B,IAAAC,iBAAU,EAACC,sBAAa,CAAC;IAAA,mCAA3CC,QAAQ;IAARA,QAAQ,qCAAG,CAAC,CAAC;EACrB,OAAO,IAAAC,cAAO,EACZ;IAAA,oBACE;MACE,SAAS,YAAKP,SAAS,4BAAkBC,SAAS,IAAIK,QAAQ,CAACL,SAAS,CAAC,GAAG,QAAQ,GAAG,EAAE,CAAG;MAC5F,OAAO,EAAE,iBAACO,CAAC;QAAA,OAAKA,CAAC,CAACC,eAAe,EAAE;MAAA,CAAC;MAAA,UAEnCC,KAAK,CAACC,OAAO,CAACT,QAAQ,CAAC,gBAAG,qBAAC,YAAO;QAAC,QAAQ,EAAEA;MAAS,GAAKH,KAAK;QAAE,OAAO;MAAA,GAAG,GAAGI;IAAQ,EACpF;EAAA,CACP;EACD;EACA,CAACD,QAAQ,EAAEI,QAAQ,EAAEL,SAAS,EAAED,SAAS,CAAC,CAC3C;AACH;AAAC"
|
|
26
26
|
}
|
|
@@ -1,54 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.ToolbarItems = ToolbarItems;
|
|
11
9
|
exports["default"] = Toolbar;
|
|
12
|
-
|
|
13
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
|
-
|
|
15
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
16
|
-
|
|
17
12
|
var _Context = require("../../Context");
|
|
18
|
-
|
|
19
13
|
var _Child = _interopRequireDefault(require("./Child"));
|
|
20
|
-
|
|
21
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
|
|
23
15
|
function ToolbarItems(props) {
|
|
24
16
|
var prefixCls = props.prefixCls,
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
overflow = props.overflow;
|
|
27
18
|
var _useContext = (0, _react.useContext)(_Context.EditorContext),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
fullscreen = _useContext.fullscreen,
|
|
20
|
+
preview = _useContext.preview,
|
|
21
|
+
_useContext$barPopup = _useContext.barPopup,
|
|
22
|
+
barPopup = _useContext$barPopup === void 0 ? {} : _useContext$barPopup,
|
|
23
|
+
components = _useContext.components,
|
|
24
|
+
commandOrchestrator = _useContext.commandOrchestrator,
|
|
25
|
+
dispatch = _useContext.dispatch;
|
|
36
26
|
var originalOverflow = (0, _react.useRef)('');
|
|
37
|
-
|
|
38
27
|
function handleClick(command, name) {
|
|
39
28
|
if (!dispatch) return;
|
|
40
29
|
var state = {
|
|
41
30
|
barPopup: (0, _objectSpread2["default"])({}, barPopup)
|
|
42
31
|
};
|
|
43
|
-
|
|
44
32
|
if (command.keyCommand === 'preview') {
|
|
45
33
|
state.preview = command.value;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
if (command.keyCommand === 'fullscreen') {
|
|
49
36
|
state.fullscreen = !fullscreen;
|
|
50
37
|
}
|
|
51
|
-
|
|
52
38
|
if (props.commands && command.keyCommand === 'group') {
|
|
53
39
|
props.commands.forEach(function (item) {
|
|
54
40
|
if (name === item.groupName) {
|
|
@@ -62,14 +48,11 @@ function ToolbarItems(props) {
|
|
|
62
48
|
state.barPopup[keyName] = false;
|
|
63
49
|
});
|
|
64
50
|
}
|
|
65
|
-
|
|
66
51
|
if (Object.keys(state).length) {
|
|
67
52
|
dispatch((0, _objectSpread2["default"])({}, state));
|
|
68
53
|
}
|
|
69
|
-
|
|
70
54
|
commandOrchestrator && commandOrchestrator.executeCommand(command);
|
|
71
55
|
}
|
|
72
|
-
|
|
73
56
|
(0, _react.useEffect)(function () {
|
|
74
57
|
if (document && overflow) {
|
|
75
58
|
if (fullscreen) {
|
|
@@ -79,9 +62,8 @@ function ToolbarItems(props) {
|
|
|
79
62
|
// get the original overflow only the first time
|
|
80
63
|
if (!originalOverflow.current) {
|
|
81
64
|
originalOverflow.current = window.getComputedStyle(document.body, null).overflow;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
65
|
+
}
|
|
66
|
+
// reset to the original overflow
|
|
85
67
|
document.body.style.overflow = originalOverflow.current;
|
|
86
68
|
}
|
|
87
69
|
}
|
|
@@ -93,7 +75,6 @@ function ToolbarItems(props) {
|
|
|
93
75
|
className: "".concat(prefixCls, "-toolbar-divider")
|
|
94
76
|
}), idx);
|
|
95
77
|
}
|
|
96
|
-
|
|
97
78
|
if (!item.keyCommand) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {}, idx);
|
|
98
79
|
var activeBtn = fullscreen && item.keyCommand === 'fullscreen' || item.keyCommand === 'preview' && preview === item.value;
|
|
99
80
|
var childNode = item.children && typeof item.children === 'function' ? item.children({
|
|
@@ -136,17 +117,14 @@ function ToolbarItems(props) {
|
|
|
136
117
|
})
|
|
137
118
|
});
|
|
138
119
|
}
|
|
139
|
-
|
|
140
120
|
function Toolbar() {
|
|
141
121
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
142
122
|
var prefixCls = props.prefixCls,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
123
|
+
toolbarBottom = props.toolbarBottom,
|
|
124
|
+
isChild = props.isChild;
|
|
146
125
|
var _useContext2 = (0, _react.useContext)(_Context.EditorContext),
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
126
|
+
commands = _useContext2.commands,
|
|
127
|
+
extraCommands = _useContext2.extraCommands;
|
|
150
128
|
var bottomClassName = toolbarBottom ? 'bottom' : '';
|
|
151
129
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
152
130
|
className: "".concat(prefixCls, "-toolbar ").concat(bottomClassName),
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"sourcesContent": [
|
|
79
79
|
"import React, { Fragment, useContext, useEffect, useRef } from 'react';\nimport { IProps } from '../../Editor';\nimport { EditorContext, PreviewType, ContextStore } from '../../Context';\nimport { ICommand } from '../../commands';\nimport Child from './Child';\nimport './index.less';\n\nexport interface IToolbarProps extends IProps {\n overflow?: boolean;\n toolbarBottom?: boolean;\n onCommand?: (command: ICommand<string>, groupName?: string) => void;\n commands?: ICommand<string>[];\n isChild?: boolean;\n}\n\nexport function ToolbarItems(props: IToolbarProps) {\n const { prefixCls, overflow } = props;\n const { fullscreen, preview, barPopup = {}, components, commandOrchestrator, dispatch } = useContext(EditorContext);\n const originalOverflow = useRef('');\n\n function handleClick(command: ICommand<string>, name?: string) {\n if (!dispatch) return;\n const state: ContextStore = { barPopup: { ...barPopup } };\n if (command.keyCommand === 'preview') {\n state.preview = command.value as PreviewType;\n }\n if (command.keyCommand === 'fullscreen') {\n state.fullscreen = !fullscreen;\n }\n if (props.commands && command.keyCommand === 'group') {\n props.commands.forEach((item) => {\n if (name === item.groupName) {\n state.barPopup![name!] = true;\n } else if (item.keyCommand) {\n state.barPopup![item.groupName!] = false;\n }\n });\n } else if (name || command.parent) {\n Object.keys(state.barPopup || {}).forEach((keyName) => {\n state.barPopup![keyName] = false;\n });\n }\n\n if (Object.keys(state).length) {\n dispatch({ ...state });\n }\n commandOrchestrator && commandOrchestrator.executeCommand(command);\n }\n\n useEffect(() => {\n if (document && overflow) {\n if (fullscreen) {\n // prevent scroll on fullscreen\n document.body.style.overflow = 'hidden';\n } else {\n // get the original overflow only the first time\n if (!originalOverflow.current) {\n originalOverflow.current = window.getComputedStyle(document.body, null).overflow;\n }\n // reset to the original overflow\n document.body.style.overflow = originalOverflow.current;\n }\n }\n }, [fullscreen, originalOverflow, overflow]);\n\n return (\n <ul>\n {(props.commands || []).map((item, idx) => {\n if (item.keyCommand === 'divider') {\n return <li key={idx} {...item.liProps} className={`${prefixCls}-toolbar-divider`} />;\n }\n if (!item.keyCommand) return <Fragment key={idx} />;\n const activeBtn =\n (fullscreen && item.keyCommand === 'fullscreen') || (item.keyCommand === 'preview' && preview === item.value);\n const childNode =\n item.children && typeof item.children === 'function'\n ? item.children({\n getState: () => commandOrchestrator!.getState(),\n textApi: commandOrchestrator ? commandOrchestrator!.textApi : undefined,\n close: () => handleClick({}, item.groupName),\n execute: () => handleClick({ execute: item.execute }),\n })\n : undefined;\n const disabled = barPopup && preview && preview === 'preview' && !/(preview|fullscreen)/.test(item.keyCommand);\n const render = components?.toolbar || item.render;\n const com = (\n render && typeof render === 'function' ? render(item, !!disabled, handleClick, idx) : null\n ) as React.ReactElement;\n return (\n <li key={idx} {...item.liProps} className={activeBtn ? `active` : ''}>\n {com && React.isValidElement(com) && com}\n {!com && !item.buttonProps && item.icon}\n {!com &&\n item.buttonProps &&\n React.createElement(\n 'button',\n {\n type: 'button',\n key: idx,\n disabled,\n 'data-name': item.name,\n ...item.buttonProps,\n onClick: (evn: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n evn.stopPropagation();\n handleClick(item, item.groupName);\n },\n },\n item.icon,\n )}\n {item.children && (\n <Child\n overflow={overflow}\n groupName={item.groupName}\n prefixCls={prefixCls}\n children={childNode}\n commands={Array.isArray(item.children) ? item.children : undefined}\n />\n )}\n </li>\n );\n })}\n </ul>\n );\n}\n\nexport default function Toolbar(props: IToolbarProps = {}) {\n const { prefixCls, toolbarBottom, isChild } = props;\n const { commands, extraCommands } = useContext(EditorContext);\n const bottomClassName = toolbarBottom ? 'bottom' : '';\n return (\n <div className={`${prefixCls}-toolbar ${bottomClassName}`}>\n <ToolbarItems {...props} commands={props.commands || commands || []} />\n {!isChild && <ToolbarItems {...props} commands={extraCommands || []} />}\n </div>\n );\n}\n"
|
|
80
80
|
],
|
|
81
|
-
"mappings": "
|
|
81
|
+
"mappings": ";;;;;;;;;;AAAA;AAEA;AAEA;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AAG,QAAQ,GAAG,EAAE;EACrD,oBACE;IAAK,SAAS,YAAKhE,SAAS,sBAAYmE,eAAe,CAAG;IAAA,wBACxD,qBAAC,YAAY,oEAAKpE,KAAK;MAAE,QAAQ,EAAEA,KAAK,CAACmB,QAAQ,IAAIA,QAAQ,IAAI;IAAG,GAAG,EACtE,CAAC+C,OAAO,iBAAI,qBAAC,YAAY,oEAAKlE,KAAK;MAAE,QAAQ,EAAEmE,aAAa,IAAI;IAAG,GAAG;EAAA,EACnE;AAEV"
|
|
82
82
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -10,9 +9,7 @@ var _exportNames = {
|
|
|
10
9
|
MarkdownUtil: true
|
|
11
10
|
};
|
|
12
11
|
exports["default"] = exports.commands = exports.MarkdownUtil = void 0;
|
|
13
|
-
|
|
14
12
|
var _Editor = _interopRequireWildcard(require("./Editor"));
|
|
15
|
-
|
|
16
13
|
Object.keys(_Editor).forEach(function (key) {
|
|
17
14
|
if (key === "default" || key === "__esModule") return;
|
|
18
15
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -24,9 +21,7 @@ Object.keys(_Editor).forEach(function (key) {
|
|
|
24
21
|
}
|
|
25
22
|
});
|
|
26
23
|
});
|
|
27
|
-
|
|
28
24
|
var commands = _interopRequireWildcard(require("./commands"));
|
|
29
|
-
|
|
30
25
|
exports.commands = commands;
|
|
31
26
|
Object.keys(commands).forEach(function (key) {
|
|
32
27
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -39,9 +34,7 @@ Object.keys(commands).forEach(function (key) {
|
|
|
39
34
|
}
|
|
40
35
|
});
|
|
41
36
|
});
|
|
42
|
-
|
|
43
37
|
var MarkdownUtil = _interopRequireWildcard(require("./utils/markdownUtils"));
|
|
44
|
-
|
|
45
38
|
exports.MarkdownUtil = MarkdownUtil;
|
|
46
39
|
Object.keys(MarkdownUtil).forEach(function (key) {
|
|
47
40
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -54,9 +47,7 @@ Object.keys(MarkdownUtil).forEach(function (key) {
|
|
|
54
47
|
}
|
|
55
48
|
});
|
|
56
49
|
});
|
|
57
|
-
|
|
58
50
|
var _Context = require("./Context");
|
|
59
|
-
|
|
60
51
|
Object.keys(_Context).forEach(function (key) {
|
|
61
52
|
if (key === "default" || key === "__esModule") return;
|
|
62
53
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
package/lib/index.js.map
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
"sourcesContent": [
|
|
10
10
|
"import MDEditor from './Editor';\nimport * as commands from './commands';\nimport * as MarkdownUtil from './utils/markdownUtils';\n\nexport * from './commands';\nexport * from './utils/markdownUtils';\nexport * from './Editor';\nexport * from './Context';\n\nexport { MarkdownUtil, commands };\n\nexport default MDEditor;\n"
|
|
11
11
|
],
|
|
12
|
-
"mappings": "
|
|
12
|
+
"mappings": ";;;;;;;;;;;AAAA;AAMA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AALA;AAAuC;AAGvC;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAFA;AAAsD;AAGtD;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAA0B,eAIXA,kBAAQ;AAAA"
|
|
13
13
|
}
|
|
@@ -5,99 +5,90 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.insertAtLineStart = void 0;
|
|
7
7
|
exports.insertTextAtPosition = insertTextAtPosition;
|
|
8
|
-
|
|
9
8
|
/**
|
|
10
9
|
* The MIT License
|
|
11
10
|
* Copyright (c) 2018 Dmitriy Kubyshkin
|
|
12
11
|
* Copied from https://github.com/grassator/insert-text-at-cursor
|
|
13
12
|
*/
|
|
13
|
+
|
|
14
14
|
var browserSupportsTextareaTextNodes;
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* @param {HTMLElement} input
|
|
17
18
|
* @return {boolean}
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
20
|
function canManipulateViaTextNodes(input) {
|
|
21
21
|
if (input.nodeName !== 'TEXTAREA') {
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
24
|
if (typeof browserSupportsTextareaTextNodes === 'undefined') {
|
|
26
25
|
var textarea = document.createElement('textarea');
|
|
27
26
|
textarea.value = '1';
|
|
28
27
|
browserSupportsTextareaTextNodes = !!textarea.firstChild;
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
return browserSupportsTextareaTextNodes;
|
|
32
30
|
}
|
|
31
|
+
|
|
33
32
|
/**
|
|
34
33
|
* @param {string} val
|
|
35
34
|
* @param {number} cursorIdx
|
|
36
35
|
* @param {HTMLTextAreaElement|HTMLInputElement} input
|
|
37
36
|
* @return {void}
|
|
38
37
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
38
|
var insertAtLineStart = function insertAtLineStart(val, cursorIdx, input) {
|
|
42
39
|
var content = input.value;
|
|
43
40
|
var startIdx = 0;
|
|
44
|
-
|
|
45
41
|
while (cursorIdx--) {
|
|
46
42
|
var _char = content[cursorIdx];
|
|
47
|
-
|
|
48
43
|
if (_char === '\n') {
|
|
49
44
|
startIdx = cursorIdx + 1;
|
|
50
45
|
break;
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
|
-
|
|
54
48
|
input.focus();
|
|
55
49
|
input.setRangeText(val, startIdx, startIdx);
|
|
56
50
|
input.dispatchEvent(new Event('input', {
|
|
57
51
|
bubbles: true
|
|
58
52
|
}));
|
|
59
53
|
};
|
|
54
|
+
|
|
60
55
|
/**
|
|
61
56
|
* @param {HTMLTextAreaElement|HTMLInputElement} input
|
|
62
57
|
* @param {string} text
|
|
63
58
|
* @returns {void}
|
|
64
59
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
60
|
exports.insertAtLineStart = insertAtLineStart;
|
|
68
|
-
|
|
69
61
|
function insertTextAtPosition(input, text) {
|
|
70
62
|
// Most of the used APIs only work with the field selected
|
|
71
|
-
input.focus();
|
|
63
|
+
input.focus();
|
|
72
64
|
|
|
65
|
+
// IE 8-10
|
|
73
66
|
if (document.selection) {
|
|
74
67
|
var ieRange = document.selection.createRange();
|
|
75
|
-
ieRange.text = text;
|
|
68
|
+
ieRange.text = text;
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
/* to the end */
|
|
79
|
-
);
|
|
70
|
+
// Move cursor after the inserted text
|
|
71
|
+
ieRange.collapse(false /* to the end */);
|
|
80
72
|
ieRange.select();
|
|
81
73
|
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
74
|
+
}
|
|
84
75
|
|
|
76
|
+
// Webkit + Edge
|
|
85
77
|
var isSuccess = document.execCommand && document.execCommand('insertText', false, text);
|
|
86
|
-
|
|
87
78
|
if (!isSuccess) {
|
|
88
79
|
var start = input.selectionStart;
|
|
89
|
-
var end = input.selectionEnd;
|
|
90
|
-
|
|
80
|
+
var end = input.selectionEnd;
|
|
81
|
+
// Firefox (non-standard method)
|
|
91
82
|
if (typeof input.setRangeText === 'function') {
|
|
92
83
|
input.setRangeText(text);
|
|
93
84
|
} else {
|
|
94
85
|
// To make a change we just need a Range, not a Selection
|
|
95
86
|
var range = document.createRange();
|
|
96
87
|
var textNode = document.createTextNode(text);
|
|
97
|
-
|
|
98
88
|
if (canManipulateViaTextNodes(input)) {
|
|
99
|
-
var node = input.firstChild;
|
|
89
|
+
var node = input.firstChild;
|
|
100
90
|
|
|
91
|
+
// If textarea is empty, just insert the text
|
|
101
92
|
if (!node) {
|
|
102
93
|
input.appendChild(textNode);
|
|
103
94
|
} else {
|
|
@@ -105,35 +96,34 @@ function insertTextAtPosition(input, text) {
|
|
|
105
96
|
var offset = 0;
|
|
106
97
|
var startNode = null;
|
|
107
98
|
var endNode = null;
|
|
108
|
-
|
|
109
99
|
while (node && (startNode === null || endNode === null)) {
|
|
110
|
-
var nodeLength = node.nodeValue.length;
|
|
100
|
+
var nodeLength = node.nodeValue.length;
|
|
111
101
|
|
|
102
|
+
// if start of the selection falls into current node
|
|
112
103
|
if (start >= offset && start <= offset + nodeLength) {
|
|
113
104
|
range.setStart(startNode = node, start - offset);
|
|
114
|
-
}
|
|
115
|
-
|
|
105
|
+
}
|
|
116
106
|
|
|
107
|
+
// if end of the selection falls into current node
|
|
117
108
|
if (end >= offset && end <= offset + nodeLength) {
|
|
118
109
|
range.setEnd(endNode = node, end - offset);
|
|
119
110
|
}
|
|
120
|
-
|
|
121
111
|
offset += nodeLength;
|
|
122
112
|
node = node.nextSibling;
|
|
123
|
-
}
|
|
124
|
-
|
|
113
|
+
}
|
|
125
114
|
|
|
115
|
+
// If there is some text selected, remove it as we should replace it
|
|
126
116
|
if (start !== end) {
|
|
127
117
|
range.deleteContents();
|
|
128
118
|
}
|
|
129
119
|
}
|
|
130
|
-
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// If the node is a textarea and the range doesn't span outside the element
|
|
131
123
|
//
|
|
132
124
|
// Get the commonAncestorContainer of the selected range and test its type
|
|
133
125
|
// If the node is of type `#text` it means that we're still working with text nodes within our textarea element
|
|
134
126
|
// otherwise, if it's of type `#document` for example it means our selection spans outside the textarea.
|
|
135
|
-
|
|
136
|
-
|
|
137
127
|
if (canManipulateViaTextNodes(input) && range.commonAncestorContainer.nodeName === '#text') {
|
|
138
128
|
// Finally insert a new node. The browser will automatically split start and end nodes into two if necessary
|
|
139
129
|
range.insertNode(textNode);
|
|
@@ -142,11 +132,12 @@ function insertTextAtPosition(input, text) {
|
|
|
142
132
|
var value = input.value;
|
|
143
133
|
input.value = value.slice(0, start) + text + value.slice(end);
|
|
144
134
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
135
|
+
}
|
|
147
136
|
|
|
148
|
-
|
|
137
|
+
// Correct the cursor position to be at the end of the insertion
|
|
138
|
+
input.setSelectionRange(start + text.length, start + text.length);
|
|
149
139
|
|
|
140
|
+
// Notify any possible listeners of the change
|
|
150
141
|
var e = document.createEvent('UIEvent');
|
|
151
142
|
e.initEvent('input', true, false);
|
|
152
143
|
input.dispatchEvent(e);
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"sourcesContent": [
|
|
64
64
|
"/**\n * The MIT License\n * Copyright (c) 2018 Dmitriy Kubyshkin\n * Copied from https://github.com/grassator/insert-text-at-cursor\n */\n\nlet browserSupportsTextareaTextNodes: any;\n\n/**\n * @param {HTMLElement} input\n * @return {boolean}\n */\nfunction canManipulateViaTextNodes(input: HTMLTextAreaElement | HTMLInputElement): boolean {\n if (input.nodeName !== 'TEXTAREA') {\n return false;\n }\n if (typeof browserSupportsTextareaTextNodes === 'undefined') {\n const textarea: HTMLTextAreaElement = document.createElement('textarea');\n textarea.value = '1';\n browserSupportsTextareaTextNodes = !!textarea.firstChild;\n }\n return browserSupportsTextareaTextNodes;\n}\n\n/**\n * @param {string} val\n * @param {number} cursorIdx\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @return {void}\n */\nexport const insertAtLineStart = (\n val: string,\n cursorIdx: number,\n input: HTMLTextAreaElement | HTMLInputElement,\n): void => {\n const content = input.value;\n let startIdx = 0;\n\n while (cursorIdx--) {\n let char = content[cursorIdx];\n if (char === '\\n') {\n startIdx = cursorIdx + 1;\n break;\n }\n }\n\n input.focus();\n input.setRangeText(val, startIdx, startIdx);\n input.dispatchEvent(new Event('input', { bubbles: true }));\n};\n\n/**\n * @param {HTMLTextAreaElement|HTMLInputElement} input\n * @param {string} text\n * @returns {void}\n */\nexport function insertTextAtPosition(input: HTMLTextAreaElement | HTMLInputElement, text: string): void {\n // Most of the used APIs only work with the field selected\n input.focus();\n\n // IE 8-10\n if ((document as any).selection) {\n const ieRange = (document as any).selection.createRange();\n ieRange.text = text;\n\n // Move cursor after the inserted text\n ieRange.collapse(false /* to the end */);\n ieRange.select();\n\n return;\n }\n\n // Webkit + Edge\n const isSuccess = document.execCommand && document.execCommand('insertText', false, text);\n if (!isSuccess) {\n const start = input.selectionStart!;\n const end = input.selectionEnd!;\n // Firefox (non-standard method)\n if (typeof input.setRangeText === 'function') {\n input.setRangeText(text);\n } else {\n // To make a change we just need a Range, not a Selection\n const range = document.createRange();\n const textNode = document.createTextNode(text);\n\n if (canManipulateViaTextNodes(input)) {\n let node = input.firstChild;\n\n // If textarea is empty, just insert the text\n if (!node) {\n input.appendChild(textNode);\n } else {\n // Otherwise we need to find a nodes for start and end\n let offset = 0;\n let startNode = null;\n let endNode = null;\n\n while (node && (startNode === null || endNode === null)) {\n const nodeLength = node.nodeValue!.length;\n\n // if start of the selection falls into current node\n if (start >= offset && start <= offset + nodeLength) {\n range.setStart((startNode = node), start - offset);\n }\n\n // if end of the selection falls into current node\n if (end >= offset && end <= offset + nodeLength) {\n range.setEnd((endNode = node), end - offset);\n }\n\n offset += nodeLength;\n node = node.nextSibling;\n }\n\n // If there is some text selected, remove it as we should replace it\n if (start !== end) {\n range.deleteContents();\n }\n }\n }\n\n // If the node is a textarea and the range doesn't span outside the element\n //\n // Get the commonAncestorContainer of the selected range and test its type\n // If the node is of type `#text` it means that we're still working with text nodes within our textarea element\n // otherwise, if it's of type `#document` for example it means our selection spans outside the textarea.\n if (canManipulateViaTextNodes(input) && range.commonAncestorContainer.nodeName === '#text') {\n // Finally insert a new node. The browser will automatically split start and end nodes into two if necessary\n range.insertNode(textNode);\n } else {\n // If the node is not a textarea or the range spans outside a textarea the only way is to replace the whole value\n const value = input.value;\n input.value = value.slice(0, start) + text + value.slice(end);\n }\n }\n\n // Correct the cursor position to be at the end of the insertion\n input.setSelectionRange(start + text.length, start + text.length);\n\n // Notify any possible listeners of the change\n const e = document.createEvent('UIEvent');\n e.initEvent('input', true, false);\n input.dispatchEvent(e);\n }\n}\n"
|
|
65
65
|
],
|
|
66
|
-
"mappings": "
|
|
66
|
+
"mappings": ";;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,gCAAqC;;AAEzC;AACA;AACA;AACA;AACA,SAASC,yBAAyB,CAACC,KAA6C,EAAW;EACzF,IAAIA,KAAK,CAACC,QAAQ,KAAK,UAAU,EAAE;IACjC,OAAO,KAAK;EACd;EACA,IAAI,OAAOH,gCAAgC,KAAK,WAAW,EAAE;IAC3D,IAAMI,QAA6B,GAAGC,QAAQ,CAACC,aAAa,CAAC,UAAU,CAAC;IACxEF,QAAQ,CAACG,KAAK,GAAG,GAAG;IACpBP,gCAAgC,GAAG,CAAC,CAACI,QAAQ,CAACI,UAAU;EAC1D;EACA,OAAOR,gCAAgC;AACzC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMS,iBAAiB,GAAG,SAApBA,iBAAiB,CAC5BC,GAAW,EACXC,SAAiB,EACjBT,KAA6C,EACpC;EACT,IAAMU,OAAO,GAAGV,KAAK,CAACK,KAAK;EAC3B,IAAIM,QAAQ,GAAG,CAAC;EAEhB,OAAOF,SAAS,EAAE,EAAE;IAClB,IAAIG,KAAI,GAAGF,OAAO,CAACD,SAAS,CAAC;IAC7B,IAAIG,KAAI,KAAK,IAAI,EAAE;MACjBD,QAAQ,GAAGF,SAAS,GAAG,CAAC;MACxB;IACF;EACF;EAEAT,KAAK,CAACa,KAAK,EAAE;EACbb,KAAK,CAACc,YAAY,CAACN,GAAG,EAAEG,QAAQ,EAAEA,QAAQ,CAAC;EAC3CX,KAAK,CAACe,aAAa,CAAC,IAAIC,KAAK,CAAC,OAAO,EAAE;IAAEC,OAAO,EAAE;EAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;;AAED;AACA;AACA;AACA;AACA;AAJA;AAKO,SAASC,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