@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.
Files changed (137) hide show
  1. package/dist/mdeditor.js +1559 -1578
  2. package/dist/mdeditor.min.js +1 -1
  3. package/esm/Context.js.map +1 -1
  4. package/esm/Editor.js +43 -67
  5. package/esm/Editor.js.map +1 -1
  6. package/esm/commands/bold.js +4 -4
  7. package/esm/commands/bold.js.map +1 -1
  8. package/esm/commands/code.js +4 -6
  9. package/esm/commands/code.js.map +1 -1
  10. package/esm/commands/comment.js +4 -4
  11. package/esm/commands/comment.js.map +1 -1
  12. package/esm/commands/divider.js.map +1 -1
  13. package/esm/commands/fullscreen.js +3 -4
  14. package/esm/commands/fullscreen.js.map +2 -2
  15. package/esm/commands/group.js +2 -4
  16. package/esm/commands/group.js.map +1 -1
  17. package/esm/commands/hr.js.map +1 -1
  18. package/esm/commands/image.js +4 -4
  19. package/esm/commands/image.js.map +1 -1
  20. package/esm/commands/index.d.ts +2 -2
  21. package/esm/commands/index.js +6 -17
  22. package/esm/commands/index.js.map +3 -2
  23. package/esm/commands/italic.js +4 -4
  24. package/esm/commands/italic.js.map +1 -1
  25. package/esm/commands/link.js +4 -4
  26. package/esm/commands/link.js.map +1 -1
  27. package/esm/commands/list.js +4 -4
  28. package/esm/commands/list.js.map +1 -1
  29. package/esm/commands/preview.js +21 -3
  30. package/esm/commands/preview.js.map +7 -2
  31. package/esm/commands/quote.js +2 -1
  32. package/esm/commands/quote.js.map +1 -1
  33. package/esm/commands/strikeThrough.js +4 -4
  34. package/esm/commands/strikeThrough.js.map +1 -1
  35. package/esm/commands/title.js.map +1 -1
  36. package/esm/commands/title1.js.map +1 -1
  37. package/esm/commands/title2.js.map +1 -1
  38. package/esm/commands/title3.js.map +1 -1
  39. package/esm/commands/title4.js.map +1 -1
  40. package/esm/commands/title5.js.map +1 -1
  41. package/esm/commands/title6.js.map +1 -1
  42. package/esm/components/DragBar/index.js +2 -9
  43. package/esm/components/DragBar/index.js.map +1 -1
  44. package/esm/components/TextArea/Markdown.js +2 -7
  45. package/esm/components/TextArea/Markdown.js.map +1 -1
  46. package/esm/components/TextArea/Textarea.js +8 -11
  47. package/esm/components/TextArea/Textarea.js.map +1 -1
  48. package/esm/components/TextArea/handleKeyDown.js +2 -16
  49. package/esm/components/TextArea/handleKeyDown.js.map +1 -1
  50. package/esm/components/TextArea/index.js +11 -15
  51. package/esm/components/TextArea/index.js.map +1 -1
  52. package/esm/components/TextArea/shortcuts.js +1 -17
  53. package/esm/components/TextArea/shortcuts.js.map +2 -2
  54. package/esm/components/Toolbar/Child.js +2 -1
  55. package/esm/components/Toolbar/Child.js.map +1 -1
  56. package/esm/components/Toolbar/index.js +2 -12
  57. package/esm/components/Toolbar/index.js.map +1 -1
  58. package/esm/index.js.map +1 -1
  59. package/esm/utils/InsertTextAtPosition.js +28 -34
  60. package/esm/utils/InsertTextAtPosition.js.map +1 -1
  61. package/esm/utils/markdownUtils.js +14 -23
  62. package/esm/utils/markdownUtils.js.map +1 -1
  63. package/lib/Context.js +0 -6
  64. package/lib/Context.js.map +1 -1
  65. package/lib/Editor.js +74 -114
  66. package/lib/Editor.js.map +1 -1
  67. package/lib/commands/bold.js +4 -9
  68. package/lib/commands/bold.js.map +1 -1
  69. package/lib/commands/code.js +4 -11
  70. package/lib/commands/code.js.map +1 -1
  71. package/lib/commands/comment.js +4 -7
  72. package/lib/commands/comment.js.map +1 -1
  73. package/lib/commands/divider.js.map +1 -1
  74. package/lib/commands/fullscreen.js +3 -8
  75. package/lib/commands/fullscreen.js.map +2 -2
  76. package/lib/commands/group.js +2 -10
  77. package/lib/commands/group.js.map +1 -1
  78. package/lib/commands/hr.js +0 -4
  79. package/lib/commands/hr.js.map +1 -1
  80. package/lib/commands/image.js +4 -9
  81. package/lib/commands/image.js.map +1 -1
  82. package/lib/commands/index.d.ts +2 -2
  83. package/lib/commands/index.js +4 -41
  84. package/lib/commands/index.js.map +3 -2
  85. package/lib/commands/italic.js +4 -9
  86. package/lib/commands/italic.js.map +1 -1
  87. package/lib/commands/link.js +4 -9
  88. package/lib/commands/link.js.map +1 -1
  89. package/lib/commands/list.js +4 -10
  90. package/lib/commands/list.js.map +1 -1
  91. package/lib/commands/preview.js +21 -7
  92. package/lib/commands/preview.js.map +7 -2
  93. package/lib/commands/quote.js +2 -6
  94. package/lib/commands/quote.js.map +1 -1
  95. package/lib/commands/strikeThrough.js +4 -9
  96. package/lib/commands/strikeThrough.js.map +1 -1
  97. package/lib/commands/title.js +0 -6
  98. package/lib/commands/title.js.map +1 -1
  99. package/lib/commands/title1.js +0 -5
  100. package/lib/commands/title1.js.map +1 -1
  101. package/lib/commands/title2.js +0 -5
  102. package/lib/commands/title2.js.map +1 -1
  103. package/lib/commands/title3.js +0 -5
  104. package/lib/commands/title3.js.map +1 -1
  105. package/lib/commands/title4.js +0 -5
  106. package/lib/commands/title4.js.map +1 -1
  107. package/lib/commands/title5.js +0 -5
  108. package/lib/commands/title5.js.map +1 -1
  109. package/lib/commands/title6.js +0 -5
  110. package/lib/commands/title6.js.map +1 -1
  111. package/lib/components/DragBar/index.js +4 -15
  112. package/lib/components/DragBar/index.js.map +1 -1
  113. package/lib/components/TextArea/Markdown.js +6 -22
  114. package/lib/components/TextArea/Markdown.js.map +1 -1
  115. package/lib/components/TextArea/Textarea.js +15 -36
  116. package/lib/components/TextArea/Textarea.js.map +1 -1
  117. package/lib/components/TextArea/handleKeyDown.js +1 -18
  118. package/lib/components/TextArea/handleKeyDown.js.map +1 -1
  119. package/lib/components/TextArea/index.js +15 -37
  120. package/lib/components/TextArea/index.js.map +1 -1
  121. package/lib/components/TextArea/shortcuts.js +1 -17
  122. package/lib/components/TextArea/shortcuts.js.map +2 -2
  123. package/lib/components/Toolbar/Child.js +8 -18
  124. package/lib/components/Toolbar/Child.js.map +1 -1
  125. package/lib/components/Toolbar/index.js +14 -36
  126. package/lib/components/Toolbar/index.js.map +1 -1
  127. package/lib/index.js +0 -9
  128. package/lib/index.js.map +1 -1
  129. package/lib/utils/InsertTextAtPosition.js +28 -37
  130. package/lib/utils/InsertTextAtPosition.js.map +1 -1
  131. package/lib/utils/markdownUtils.js +17 -28
  132. package/lib/utils/markdownUtils.js.map +1 -1
  133. package/package.json +1 -1
  134. package/src/commands/fullscreen.tsx +3 -2
  135. package/src/commands/index.ts +3 -1
  136. package/src/commands/preview.tsx +35 -4
  137. 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: (string | number)[] = [];\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);\n return;\n }\n}\n"
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": ";;;;;;;;;;;AAGA,SAASA,WAAT,GAA8G;EAAA,IAAzFC,IAAyF,uEAAtE,EAAsE;EAAA,IAAlEC,OAAkE,uEAA9B,EAA8B;EAC5GD,IAAI,CAACE,OAAL,CAAa,UAACC,IAAD,EAAU;IACrB,IAAIA,IAAI,CAACC,QAAL,IAAiBC,KAAK,CAACC,OAAN,CAAcH,IAAI,CAACC,QAAnB,CAArB,EAAmD;MACjDH,OAAO,qEAAQA,OAAR,GAAoBF,WAAW,CAACI,IAAI,CAACC,QAAL,IAAiB,EAAlB,CAA/B,CAAP;IACD,CAFD,MAEO,IAAID,IAAI,CAACI,UAAL,IAAmBJ,IAAI,CAACK,SAAxB,IAAqCL,IAAI,CAACM,OAA9C,EAAuD;MAC5DR,OAAO,CAACE,IAAI,CAACK,SAAL,CAAeE,iBAAf,EAAD,CAAP,GAA8CP,IAA9C;IACD;EACF,CAND;EAOA,OAAOF,OAAP;AACD;;AAEc,SAASU,eAAT,CACbC,CADa,EAMb;EAAA,IAJA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AC6B,KAAK,CAAC,GAAG,CAAC,CAACC,KAAK,CAAC,UAACC,CAAC,EAAK;MAC3C,IAAI,SAAS,CAACX,IAAI,CAACW,CAAC,CAAC,EAAE;QACrB,OAAO1B,SAAS,CAAC2B,QAAQ,CAAC,MAAM,CAAC,IAAI3B,SAAS,CAAC2B,QAAQ,CAAC,KAAK,CAAC;MAChE;MACA,OAAO3B,SAAS,CAAC2B,QAAQ,CAACD,CAAC,CAAC;IAC9B,CAAC,CAAC;IACF,IAAIH,OAAO,EAAE;MACXJ,OAAO,GAAG3B,IAAI,CAACG,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
- prefixCls = _ref.prefixCls,
25
- groupName = _ref.groupName,
26
- commands = _ref.commands,
27
- children = _ref.children;
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
- _useContext$barPopup = _useContext.barPopup,
31
- barPopup = _useContext$barPopup === void 0 ? {} : _useContext$barPopup;
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
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
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": ";;;;;;;;;;;;;AAAA;;AAEA;;AACA;;;;AAOe,SAASA,KAAT,CAAeC,KAAf,EAAkC;EAC/C,WAAqDA,KAAK,IAAI,EAA9D;EAAA,IAAQC,SAAR,QAAQA,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,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
- overflow = props.overflow;
26
-
17
+ overflow = props.overflow;
27
18
  var _useContext = (0, _react.useContext)(_Context.EditorContext),
28
- fullscreen = _useContext.fullscreen,
29
- preview = _useContext.preview,
30
- _useContext$barPopup = _useContext.barPopup,
31
- barPopup = _useContext$barPopup === void 0 ? {} : _useContext$barPopup,
32
- components = _useContext.components,
33
- commandOrchestrator = _useContext.commandOrchestrator,
34
- dispatch = _useContext.dispatch;
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
- } // reset to the original overflow
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
- toolbarBottom = props.toolbarBottom,
144
- isChild = props.isChild;
145
-
123
+ toolbarBottom = props.toolbarBottom,
124
+ isChild = props.isChild;
146
125
  var _useContext2 = (0, _react.useContext)(_Context.EditorContext),
147
- commands = _useContext2.commands,
148
- extraCommands = _useContext2.extraCommands;
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": ";;;;;;;;;;;;;;AAAA;;AAEA;;AAEA;;;;AAWO,SAASA,YAAT,CAAsBC,KAAtB,EAA4C;EACjD,IAAQC,SAAR,GAAgCD,KAAhC,CAAQC,SAAR;EAAA,IAAmBC,QAAnB,GAAgCF,KAAhC,CAAmBE,QAAnB;;EACA,kBAA0F,IAAAC,iBAAA,EAAWC,sBAAX,CAA1F;EAAA,IAAQC,UAAR,eAAQA,UAAR;EAAA,IAAoBC,OAApB,eAAoBA,OAApB;EAAA,uCAA6BC,QAA7B;EAAA,IAA6BA,QAA7B,qCAAwC,EAAxC;EAAA,IAA4CC,UAA5C,eAA4CA,UAA5C;EAAA,IAAwDC,mBAAxD,eAAwDA,mBAAxD;EAAA,IAA6EC,QAA7E,eAA6EA,QAA7E;;EACA,IAAMC,gBAAgB,GAAG,IAAAC,aAAA,EAAO,EAAP,CAAzB;;EAEA,SAASC,WAAT,CAAqBC,OAArB,EAAgDC,IAAhD,EAA+D;IAC7D,IAAI,CAACL,QAAL,EAAe;IACf,IAAMM,KAAmB,GAAG;MAAET,QAAQ,qCAAOA,QAAP;IAAV,CAA5B;;IACA,IAAIO,OAAO,CAACG,UAAR,KAAuB,SAA3B,EAAsC;MACpCD,KAAK,CAACV,OAAN,GAAgBQ,OAAO,CAACI,KAAxB;IACD;;IACD,IAAIJ,OAAO,CAACG,UAAR,KAAuB,YAA3B,EAAyC;MACvCD,KAAK,CAACX,UAAN,GAAmB,CAACA,UAApB;IACD;;IACD,I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@
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": ";;;;;;;;;;;;;AAAA;;AAMA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AALA;;;AAGA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAFA;;;AAGA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;eAIeA,kB"
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(); // IE 8-10
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; // Move cursor after the inserted text
68
+ ieRange.text = text;
76
69
 
77
- ieRange.collapse(false
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
- } // Webkit + Edge
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; // Firefox (non-standard method)
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; // If textarea is empty, just insert the text
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; // if start of the selection falls into current node
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
- } // if end of the selection falls into current node
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
- } // If there is some text selected, remove it as we should replace it
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
- } // If the node is a textarea and the range doesn't span outside the element
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
- } // Correct the cursor position to be at the end of the insertion
146
-
135
+ }
147
136
 
148
- input.setSelectionRange(start + text.length, start + text.length); // Notify any possible listeners of the change
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
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