@uiw/react-md-editor 3.8.0 → 3.8.4
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 +1 -1
- package/esm/Context.d.ts +0 -2
- package/esm/Context.js.map +2 -2
- package/esm/Editor.d.ts +1 -1
- package/esm/Editor.js +11 -4
- package/esm/Editor.js.map +4 -2
- package/esm/commands/title1.js +5 -6
- package/esm/commands/title1.js.map +9 -5
- package/esm/commands/title2.js +5 -6
- package/esm/commands/title2.js.map +9 -5
- package/esm/commands/title3.js +5 -6
- package/esm/commands/title3.js.map +9 -5
- package/esm/commands/title4.js +5 -6
- package/esm/commands/title4.js.map +9 -5
- package/esm/commands/title5.js +5 -6
- package/esm/commands/title5.js.map +9 -5
- package/esm/commands/title6.js +5 -6
- package/esm/commands/title6.js.map +9 -5
- package/esm/components/TextArea/Textarea.js +2 -4
- package/esm/components/TextArea/Textarea.js.map +2 -3
- package/esm/components/TextArea/index.d.ts +3 -2
- package/esm/components/TextArea/index.js +1 -2
- package/esm/components/TextArea/index.js.map +3 -3
- package/esm/utils/InsertTextAtPosition.d.ts +7 -0
- package/esm/utils/InsertTextAtPosition.js +27 -1
- package/esm/utils/InsertTextAtPosition.js.map +14 -6
- package/lib/Context.d.ts +0 -2
- package/lib/Context.js.map +2 -2
- package/lib/Editor.d.ts +1 -1
- package/lib/Editor.js +13 -4
- package/lib/Editor.js.map +4 -2
- package/lib/commands/title1.js +6 -6
- package/lib/commands/title1.js.map +8 -5
- package/lib/commands/title2.js +6 -6
- package/lib/commands/title2.js.map +8 -5
- package/lib/commands/title3.js +6 -6
- package/lib/commands/title3.js.map +8 -5
- package/lib/commands/title4.js +6 -6
- package/lib/commands/title4.js.map +8 -5
- package/lib/commands/title5.js +6 -6
- package/lib/commands/title5.js.map +8 -5
- package/lib/commands/title6.js +6 -6
- package/lib/commands/title6.js.map +8 -5
- package/lib/components/TextArea/Textarea.js +2 -4
- package/lib/components/TextArea/Textarea.js.map +2 -3
- package/lib/components/TextArea/index.d.ts +3 -2
- package/lib/components/TextArea/index.js +1 -2
- package/lib/components/TextArea/index.js.map +3 -3
- package/lib/utils/InsertTextAtPosition.d.ts +7 -0
- package/lib/utils/InsertTextAtPosition.js +30 -0
- package/lib/utils/InsertTextAtPosition.js.map +14 -6
- package/package.json +6 -6
- package/src/Context.tsx +0 -1
- package/src/Editor.tsx +14 -4
- package/src/commands/title1.tsx +5 -4
- package/src/commands/title2.tsx +5 -4
- package/src/commands/title3.tsx +5 -4
- package/src/commands/title4.tsx +5 -4
- package/src/commands/title5.tsx +5 -4
- package/src/commands/title6.tsx +5 -4
- package/src/components/TextArea/Textarea.tsx +3 -4
- package/src/components/TextArea/index.tsx +5 -5
- package/src/utils/InsertTextAtPosition.ts +29 -2
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
"execute",
|
|
17
17
|
"state",
|
|
18
18
|
"api",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
19
|
+
"selection",
|
|
20
|
+
"start",
|
|
21
|
+
"test",
|
|
22
|
+
"text",
|
|
23
|
+
"replaceSelection",
|
|
24
|
+
"textArea"
|
|
22
25
|
],
|
|
23
|
-
"mappings": ";;;;;;;;;AAAA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,
|
|
26
|
+
"mappings": ";;;;;;;;;AAAA;;AACA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAID,KAAK,CAACE,SAAN,CAAgBC,KAAhB,KAA0B,CAA1B,IAA+B,MAAMC,IAAN,CAAWJ,KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,MAArB;AACD,KAFD,MAEO;AACL,mDAAkB,MAAlB,EAA0BN,KAAK,CAACE,SAAN,CAAgBC,KAA1C,EAAiDF,GAAG,CAACM,QAArD;AACD;AACF;AAZ6B,CAAzB",
|
|
24
27
|
"sourcesContent": [
|
|
25
|
-
"import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title3: ICommand = {\n name: 'title3',\n keyCommand: 'title3',\n shortcuts: 'ctrlcmd+3',\n buttonProps: { 'aria-label': 'Insert title3', title: 'Insert title 3' },\n icon: <div style={{ fontSize: 15, textAlign: 'left' }}>Title 3</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n
|
|
28
|
+
"import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title3: ICommand = {\n name: 'title3',\n keyCommand: 'title3',\n shortcuts: 'ctrlcmd+3',\n buttonProps: { 'aria-label': 'Insert title3', title: 'Insert title 3' },\n icon: <div style={{ fontSize: 15, textAlign: 'left' }}>Title 3</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n if (state.selection.start === 0 || /\\n$/.test(state.text)) {\n api.replaceSelection('### ');\n } else {\n insertAtLineStart('### ', state.selection.start, api.textArea);\n }\n },\n};\n"
|
|
26
29
|
]
|
|
27
30
|
}
|
package/lib/commands/title4.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.title4 = void 0;
|
|
|
9
9
|
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
12
|
+
var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
|
|
13
|
+
|
|
12
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
15
|
|
|
14
16
|
var title4 = {
|
|
@@ -27,13 +29,11 @@ var title4 = {
|
|
|
27
29
|
children: "Title 4"
|
|
28
30
|
}),
|
|
29
31
|
execute: function execute(state, api) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
33
|
+
api.replaceSelection('#### ');
|
|
34
|
+
} else {
|
|
35
|
+
(0, _InsertTextAtPosition.insertAtLineStart)('#### ', state.selection.start, api.textArea);
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
api.replaceSelection(modifyText);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
exports.title4 = title4;
|
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
"execute",
|
|
17
17
|
"state",
|
|
18
18
|
"api",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
19
|
+
"selection",
|
|
20
|
+
"start",
|
|
21
|
+
"test",
|
|
22
|
+
"text",
|
|
23
|
+
"replaceSelection",
|
|
24
|
+
"textArea"
|
|
22
25
|
],
|
|
23
|
-
"mappings": ";;;;;;;;;AAAA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IA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ommand, TextState, TextAreaTextApi } from './';\n\nexport const title4: ICommand = {\n name: 'title4',\n keyCommand: 'title4',\n shortcuts: 'ctrlcmd+4',\n buttonProps: { 'aria-label': 'Insert title4', title: 'Insert title 4' },\n icon: <div style={{ fontSize: 14, textAlign: 'left' }}>Title 4</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n
|
|
28
|
+
"import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title4: ICommand = {\n name: 'title4',\n keyCommand: 'title4',\n shortcuts: 'ctrlcmd+4',\n buttonProps: { 'aria-label': 'Insert title4', title: 'Insert title 4' },\n icon: <div style={{ fontSize: 14, textAlign: 'left' }}>Title 4</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n if (state.selection.start === 0 || /\\n$/.test(state.text)) {\n api.replaceSelection('#### ');\n } else {\n insertAtLineStart('#### ', state.selection.start, api.textArea);\n }\n },\n};\n"
|
|
26
29
|
]
|
|
27
30
|
}
|
package/lib/commands/title5.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.title5 = void 0;
|
|
|
9
9
|
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
12
|
+
var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
|
|
13
|
+
|
|
12
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
15
|
|
|
14
16
|
var title5 = {
|
|
@@ -27,13 +29,11 @@ var title5 = {
|
|
|
27
29
|
children: "Title 5"
|
|
28
30
|
}),
|
|
29
31
|
execute: function execute(state, api) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
33
|
+
api.replaceSelection('##### ');
|
|
34
|
+
} else {
|
|
35
|
+
(0, _InsertTextAtPosition.insertAtLineStart)('##### ', state.selection.start, api.textArea);
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
api.replaceSelection(modifyText);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
exports.title5 = title5;
|
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
"execute",
|
|
17
17
|
"state",
|
|
18
18
|
"api",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
19
|
+
"selection",
|
|
20
|
+
"start",
|
|
21
|
+
"test",
|
|
22
|
+
"text",
|
|
23
|
+
"replaceSelection",
|
|
24
|
+
"textArea"
|
|
22
25
|
],
|
|
23
|
-
"mappings": ";;;;;;;;;AAAA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,
|
|
26
|
+
"mappings": ";;;;;;;;;AAAA;;AACA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAID,KAAK,CAACE,SAAN,CAAgBC,KAAhB,KAA0B,CAA1B,IAA+B,MAAMC,IAAN,CAAWJ,KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,QAArB;AACD,KAFD,MAEO;AACL,mDAAkB,QAAlB,EAA4BN,KAAK,CAACE,SAAN,CAAgBC,KAA5C,EAAmDF,GAAG,CAACM,QAAvD;AACD;AACF;AAZ6B,CAAzB",
|
|
24
27
|
"sourcesContent": [
|
|
25
|
-
"import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title5: ICommand = {\n name: 'title5',\n keyCommand: 'title5',\n shortcuts: 'ctrlcmd+5',\n buttonProps: { 'aria-label': 'Insert title5', title: 'Insert title 5' },\n icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 5</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n
|
|
28
|
+
"import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title5: ICommand = {\n name: 'title5',\n keyCommand: 'title5',\n shortcuts: 'ctrlcmd+5',\n buttonProps: { 'aria-label': 'Insert title5', title: 'Insert title 5' },\n icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 5</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n if (state.selection.start === 0 || /\\n$/.test(state.text)) {\n api.replaceSelection('##### ');\n } else {\n insertAtLineStart('##### ', state.selection.start, api.textArea);\n }\n },\n};\n"
|
|
26
29
|
]
|
|
27
30
|
}
|
package/lib/commands/title6.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.title6 = void 0;
|
|
|
9
9
|
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
12
|
+
var _InsertTextAtPosition = require("../utils/InsertTextAtPosition");
|
|
13
|
+
|
|
12
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
15
|
|
|
14
16
|
var title6 = {
|
|
@@ -27,13 +29,11 @@ var title6 = {
|
|
|
27
29
|
children: "Title 6"
|
|
28
30
|
}),
|
|
29
31
|
execute: function execute(state, api) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
33
|
+
api.replaceSelection('###### ');
|
|
34
|
+
} else {
|
|
35
|
+
(0, _InsertTextAtPosition.insertAtLineStart)('###### ', state.selection.start, api.textArea);
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
api.replaceSelection(modifyText);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
exports.title6 = title6;
|
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
"execute",
|
|
17
17
|
"state",
|
|
18
18
|
"api",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
19
|
+
"selection",
|
|
20
|
+
"start",
|
|
21
|
+
"test",
|
|
22
|
+
"text",
|
|
23
|
+
"replaceSelection",
|
|
24
|
+
"textArea"
|
|
22
25
|
],
|
|
23
|
-
"mappings": ";;;;;;;;;AAAA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,
|
|
26
|
+
"mappings": ";;;;;;;;;AAAA;;AACA;;;;AAGO,IAAMA,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,eAAhB;AAAiCC,IAAAA,KAAK,EAAE;AAAxC,GAJiB;AAK9BC,EAAAA,IAAI,eAAE;AAAK,IAAA,KAAK,EAAE;AAAEC,MAAAA,QAAQ,EAAE,EAAZ;AAAgBC,MAAAA,SAAS,EAAE;AAA3B,KAAZ;AAAA;AAAA,IALwB;AAM9BC,EAAAA,OAAO,EAAE,iBAACC,KAAD,EAAmBC,GAAnB,EAA4C;AACnD,QAAID,KAAK,CAACE,SAAN,CAAgBC,KAAhB,KAA0B,CAA1B,IAA+B,MAAMC,IAAN,CAAWJ,KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,SAArB;AACD,KAFD,MAEO;AACL,mDAAkB,SAAlB,EAA6BN,KAAK,CAACE,SAAN,CAAgBC,KAA7C,EAAoDF,GAAG,CAACM,QAAxD;AACD;AACF;AAZ6B,CAAzB",
|
|
24
27
|
"sourcesContent": [
|
|
25
|
-
"import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title6: ICommand = {\n name: 'title6',\n keyCommand: 'title6',\n shortcuts: 'ctrlcmd+6',\n buttonProps: { 'aria-label': 'Insert title6', title: 'Insert title 6' },\n icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 6</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n
|
|
28
|
+
"import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title6: ICommand = {\n name: 'title6',\n keyCommand: 'title6',\n shortcuts: 'ctrlcmd+6',\n buttonProps: { 'aria-label': 'Insert title6', title: 'Insert title 6' },\n icon: <div style={{ fontSize: 12, textAlign: 'left' }}>Title 6</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n if (state.selection.start === 0 || /\\n$/.test(state.text)) {\n api.replaceSelection('###### ');\n } else {\n insertAtLineStart('###### ', state.selection.start, api.textArea);\n }\n },\n};\n"
|
|
26
29
|
]
|
|
27
30
|
}
|
|
@@ -31,7 +31,7 @@ var _excluded = ["prefixCls", "onChange"];
|
|
|
31
31
|
|
|
32
32
|
function Textarea(props) {
|
|
33
33
|
var prefixCls = props.prefixCls,
|
|
34
|
-
|
|
34
|
+
_onChange = props.onChange,
|
|
35
35
|
other = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
36
36
|
|
|
37
37
|
var _useContext = (0, _react.useContext)(_Context.EditorContext),
|
|
@@ -42,7 +42,6 @@ function Textarea(props) {
|
|
|
42
42
|
highlightEnable = _useContext.highlightEnable,
|
|
43
43
|
extraCommands = _useContext.extraCommands,
|
|
44
44
|
tabSize = _useContext.tabSize,
|
|
45
|
-
_onChange = _useContext.onChange,
|
|
46
45
|
dispatch = _useContext.dispatch;
|
|
47
46
|
|
|
48
47
|
var textRef = _react.default.useRef(null);
|
|
@@ -103,8 +102,7 @@ function Textarea(props) {
|
|
|
103
102
|
dispatch && dispatch({
|
|
104
103
|
markdown: e.target.value
|
|
105
104
|
});
|
|
106
|
-
_onChange && _onChange(e
|
|
107
|
-
onChangeFromProps && onChangeFromProps(e);
|
|
105
|
+
_onChange && _onChange(e);
|
|
108
106
|
}
|
|
109
107
|
}));
|
|
110
108
|
}
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
"Textarea",
|
|
8
8
|
"props",
|
|
9
9
|
"prefixCls",
|
|
10
|
-
"onChangeFromProps",
|
|
11
10
|
"onChange",
|
|
12
11
|
"other",
|
|
13
12
|
"EditorContext",
|
|
@@ -36,8 +35,8 @@
|
|
|
36
35
|
"target",
|
|
37
36
|
"value"
|
|
38
37
|
],
|
|
39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EAAE,kBAACkB,CAAD,EAAO;AACfX,MAAAA,QAAQ,IAAIA,QAAQ,CAAC;AAAEP,QAAAA,QAAQ,EAAEkB,CAAC,CAACI,MAAF,CAASC;AAArB,OAAD,CAApB;AACA1B,MAAAA,SAAQ,IAAIA,SAAQ,CAACqB,CAAD,CAApB;AACD;AAZH,KADF;AAgBD",
|
|
40
39
|
"sourcesContent": [
|
|
41
|
-
"import React, { useContext, useEffect } from 'react';\nimport { IProps } from '../../Editor';\nimport { EditorContext, ExecuteCommandState } from '../../Context';\nimport { TextAreaCommandOrchestrator } from '../../commands';\nimport handleKeyDown from './handleKeyDown';\nimport shortcuts from './shortcuts';\nimport './index.less';\n\nexport interface TextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value'>, IProps {}\n\nexport default function Textarea(props: TextAreaProps) {\n const { prefixCls, onChange
|
|
40
|
+
"import React, { useContext, useEffect } from 'react';\nimport { IProps } from '../../Editor';\nimport { EditorContext, ExecuteCommandState } from '../../Context';\nimport { TextAreaCommandOrchestrator } from '../../commands';\nimport handleKeyDown from './handleKeyDown';\nimport shortcuts from './shortcuts';\nimport './index.less';\n\nexport interface TextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value'>, IProps {}\n\nexport default function Textarea(props: TextAreaProps) {\n const { prefixCls, onChange, ...other } = props;\n const { markdown, commands, fullscreen, preview, highlightEnable, extraCommands, tabSize, dispatch } =\n useContext(EditorContext);\n const textRef = React.useRef<HTMLTextAreaElement>(null);\n const executeRef = React.useRef<TextAreaCommandOrchestrator>();\n const statesRef = React.useRef<ExecuteCommandState>({ fullscreen, preview });\n\n useEffect(() => {\n statesRef.current = { fullscreen, preview, highlightEnable };\n }, [fullscreen, preview, highlightEnable]);\n\n useEffect(() => {\n if (textRef.current && dispatch) {\n const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);\n executeRef.current = commandOrchestrator;\n dispatch({ textarea: textRef.current, commandOrchestrator });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const onKeyDown = (e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>) => {\n handleKeyDown(e, tabSize);\n shortcuts(e, [...(commands || []), ...(extraCommands || [])], executeRef.current, dispatch, statesRef.current);\n };\n useEffect(() => {\n if (textRef.current) {\n textRef.current.addEventListener('keydown', onKeyDown);\n }\n return () => {\n if (textRef.current) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n textRef.current.removeEventListener('keydown', onKeyDown);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <textarea\n autoComplete=\"off\"\n autoCorrect=\"off\"\n autoCapitalize=\"off\"\n spellCheck={false}\n {...other}\n ref={textRef}\n className={`${prefixCls}-text-input ${other.className ? other.className : ''}`}\n value={markdown}\n onChange={(e) => {\n dispatch && dispatch({ markdown: e.target.value });\n onChange && onChange(e);\n }}\n />\n );\n}\n"
|
|
42
41
|
]
|
|
43
42
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ContextStore, ExecuteCommandState } from '../../Context';
|
|
3
|
-
import {
|
|
3
|
+
import { TextAreaProps } from './Textarea';
|
|
4
|
+
import { IProps } from '../../Editor';
|
|
4
5
|
import { TextAreaCommandOrchestrator, ICommand } from '../../commands';
|
|
5
6
|
import './index.less';
|
|
6
7
|
declare type RenderTextareaHandle = {
|
|
7
8
|
dispatch: ContextStore['dispatch'];
|
|
8
|
-
onChange?:
|
|
9
|
+
onChange?: TextAreaProps['onChange'];
|
|
9
10
|
useContext?: {
|
|
10
11
|
commands: ContextStore['commands'];
|
|
11
12
|
extraCommands: ContextStore['extraCommands'];
|
|
@@ -42,7 +42,6 @@ function TextArea(props) {
|
|
|
42
42
|
scrollTop = _useContext.scrollTop,
|
|
43
43
|
commands = _useContext.commands,
|
|
44
44
|
extraCommands = _useContext.extraCommands,
|
|
45
|
-
onChange = _useContext.onChange,
|
|
46
45
|
dispatch = _useContext.dispatch;
|
|
47
46
|
|
|
48
47
|
var textRef = _react.default.useRef(null);
|
|
@@ -95,7 +94,7 @@ function TextArea(props) {
|
|
|
95
94
|
}
|
|
96
95
|
}), {
|
|
97
96
|
dispatch: dispatch,
|
|
98
|
-
onChange: onChange,
|
|
97
|
+
onChange: otherProps.onChange,
|
|
99
98
|
shortcuts: _shortcuts.default,
|
|
100
99
|
useContext: {
|
|
101
100
|
commands: commands,
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"scrollTop",
|
|
17
17
|
"commands",
|
|
18
18
|
"extraCommands",
|
|
19
|
-
"onChange",
|
|
20
19
|
"dispatch",
|
|
21
20
|
"textRef",
|
|
22
21
|
"React",
|
|
@@ -40,12 +39,13 @@
|
|
|
40
39
|
"style",
|
|
41
40
|
"WebkitTextFillColor",
|
|
42
41
|
"overflow",
|
|
42
|
+
"onChange",
|
|
43
43
|
"shortcuts",
|
|
44
44
|
"useContext",
|
|
45
45
|
"ref"
|
|
46
46
|
],
|
|
47
|
-
"mappings": ";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAoCe,SAASA,QAAT,CAAkBC,KAAlB,EAAyC;AACtD,aAA0EA,KAAK,IAAI,EAAnF;AAAA,MAAQC,SAAR,QAAQA,SAAR;AAAA,MAAmBC,SAAnB,QAAmBA,SAAnB;AAAA,MAA8BC,QAA9B,QAA8BA,QAA9B;AAAA,MAAwCC,cAAxC,QAAwCA,cAAxC;AAAA,MAA2DC,UAA3D;;AACA,
|
|
47
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAoCe,SAASA,QAAT,CAAkBC,KAAlB,EAAyC;AACtD,aAA0EA,KAAK,IAAI,EAAnF;AAAA,MAAQC,SAAR,QAAQA,SAAR;AAAA,MAAmBC,SAAnB,QAAmBA,SAAnB;AAAA,MAA8BC,QAA9B,QAA8BA,QAA9B;AAAA,MAA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,EAApC,CAAzB;AAAmE,IAAA,QAAQ,EAAEC,QAA7E;AAAA,2BACE;AAAK,MAAA,SAAS,YAAKF,SAAL,UAAd;AAAA,gBACGG,cAAc,gBACbS,eAAMY,YAAN,CACErB,cAAc,6DAEPC,UAFO;AAGVqB,QAAAA,KAAK,EAAEnB,QAHG;AAIVoB,QAAAA,YAAY,EAAE,KAJJ;AAKVC,QAAAA,WAAW,EAAE,KALH;AAMVC,QAAAA,UAAU,EAAE,OANF;AAOVC,QAAAA,cAAc,EAAE,KAPN;AAQV5B,QAAAA,SAAS,YAAKD,SAAL,gBARC;AASV8B,QAAAA,KAAK,EAAE;AACLC,UAAAA,mBAAmB,EAAE,SADhB;AAELC,UAAAA,QAAQ,EAAE;AAFL;AATG,UAcZ;AACEtB,QAAAA,QAAQ,EAARA,QADF;AAEEuB,QAAAA,QAAQ,EAAE7B,UAAU,CAAC6B,QAFvB;AAGEC,QAAAA,SAAS,EAATA,kBAHF;AAIEC,QAAAA,UAAU,EAAE;AAAE3B,UAAAA,QAAQ,EAARA,QAAF;AAAYC,UAAAA,aAAa,EAAbA,aAAZ;AAA2BY,UAAAA,mBAAmB,EAAEP,UAAU,CAACI;AAA3D;AAJd,OAdY,CADhB,EAsBE;AACEkB,QAAAA,GAAG,EAAEzB;AADP,OAtBF,CADa,gBA4Bb,sBAAC,eAAD;AAAA,gCACE,qBAAC,iBAAD;AAAU,UAAA,SAAS,EAAEX;AAArB,UADF,eAEE,qBAAC,iBAAD;AAAU,UAAA,SAAS,EAAEA;AAArB,WAAoCI,UAApC,EAFF;AAAA;AA7BJ;AADF,IADF;AAuCD",
|
|
48
48
|
"sourcesContent": [
|
|
49
|
-
"import React, { useEffect, Fragment, useContext } from 'react';\nimport { EditorContext, ContextStore, ExecuteCommandState } from '../../Context';\nimport shortcuts from './shortcuts';\nimport Markdown from './Markdown';\nimport Textarea from './Textarea';\nimport {
|
|
49
|
+
"import React, { useEffect, Fragment, useContext } from 'react';\nimport { EditorContext, ContextStore, ExecuteCommandState } from '../../Context';\nimport shortcuts from './shortcuts';\nimport Markdown from './Markdown';\nimport Textarea, { TextAreaProps } from './Textarea';\nimport { IProps } from '../../Editor';\nimport { TextAreaCommandOrchestrator, ICommand } from '../../commands';\nimport './index.less';\n\ntype RenderTextareaHandle = {\n dispatch: ContextStore['dispatch'];\n onChange?: TextAreaProps['onChange'];\n useContext?: {\n commands: ContextStore['commands'];\n extraCommands: ContextStore['extraCommands'];\n commandOrchestrator?: TextAreaCommandOrchestrator;\n };\n shortcuts?: (\n e: KeyboardEvent | React.KeyboardEvent<HTMLTextAreaElement>,\n commands: ICommand[],\n commandOrchestrator?: TextAreaCommandOrchestrator,\n dispatch?: React.Dispatch<ContextStore>,\n state?: ExecuteCommandState,\n ) => void;\n};\n\nexport interface ITextAreaProps\n extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>,\n IProps {\n value?: string;\n onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;\n renderTextarea?: (\n props: React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.HTMLAttributes<HTMLDivElement>,\n opts: RenderTextareaHandle,\n ) => JSX.Element;\n}\n\nexport type TextAreaRef = {\n text?: HTMLTextAreaElement;\n warp?: HTMLDivElement;\n};\n\nexport default function TextArea(props: ITextAreaProps) {\n const { prefixCls, className, onScroll, renderTextarea, ...otherProps } = props || {};\n const { markdown, scrollTop, commands, extraCommands, dispatch } = useContext(EditorContext);\n const textRef = React.useRef<HTMLTextAreaElement>(null);\n const executeRef = React.useRef<TextAreaCommandOrchestrator>();\n const warp = React.createRef<HTMLDivElement>();\n useEffect(() => {\n const state: ContextStore = {};\n if (warp.current) {\n state.textareaWarp = warp.current || undefined;\n warp.current.scrollTop = scrollTop || 0;\n }\n if (dispatch) {\n dispatch({ ...state });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (textRef.current && dispatch) {\n const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current);\n executeRef.current = commandOrchestrator;\n dispatch({ textarea: textRef.current, commandOrchestrator });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div ref={warp} className={`${prefixCls}-aree ${className || ''}`} onScroll={onScroll}>\n <div className={`${prefixCls}-text`}>\n {renderTextarea ? (\n React.cloneElement(\n renderTextarea(\n {\n ...otherProps,\n value: markdown,\n autoComplete: 'off',\n autoCorrect: 'off',\n spellCheck: 'false',\n autoCapitalize: 'off',\n className: `${prefixCls}-text-input`,\n style: {\n WebkitTextFillColor: 'inherit',\n overflow: 'auto',\n },\n },\n {\n dispatch,\n onChange: otherProps.onChange,\n shortcuts,\n useContext: { commands, extraCommands, commandOrchestrator: executeRef.current },\n },\n ),\n {\n ref: textRef,\n },\n )\n ) : (\n <Fragment>\n <Markdown prefixCls={prefixCls} />\n <Textarea prefixCls={prefixCls} {...otherProps} />\n </Fragment>\n )}\n </div>\n </div>\n );\n}\n"
|
|
50
50
|
]
|
|
51
51
|
}
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* Copyright (c) 2018 Dmitriy Kubyshkin
|
|
4
4
|
* Copied from https://github.com/grassator/insert-text-at-cursor
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} val
|
|
8
|
+
* @param {number} cursorIdx
|
|
9
|
+
* @param {HTMLTextAreaElement|HTMLInputElement} input
|
|
10
|
+
* @return {void}
|
|
11
|
+
*/
|
|
12
|
+
export declare const insertAtLineStart: (val: string, cursorIdx: number, input: HTMLTextAreaElement | HTMLInputElement) => void;
|
|
6
13
|
/**
|
|
7
14
|
* @param {HTMLTextAreaElement|HTMLInputElement} input
|
|
8
15
|
* @param {string} text
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.insertAtLineStart = void 0;
|
|
6
7
|
exports.insertTextAtPosition = insertTextAtPosition;
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -29,6 +30,33 @@ function canManipulateViaTextNodes(input) {
|
|
|
29
30
|
|
|
30
31
|
return browserSupportsTextareaTextNodes;
|
|
31
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} val
|
|
35
|
+
* @param {number} cursorIdx
|
|
36
|
+
* @param {HTMLTextAreaElement|HTMLInputElement} input
|
|
37
|
+
* @return {void}
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var insertAtLineStart = function insertAtLineStart(val, cursorIdx, input) {
|
|
42
|
+
var content = input.value;
|
|
43
|
+
var startIdx = 0;
|
|
44
|
+
|
|
45
|
+
while (cursorIdx--) {
|
|
46
|
+
var char = content[cursorIdx];
|
|
47
|
+
|
|
48
|
+
if (char === '\n') {
|
|
49
|
+
startIdx = cursorIdx + 1;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
input.focus();
|
|
55
|
+
input.setRangeText(val, startIdx, startIdx);
|
|
56
|
+
input.dispatchEvent(new Event('input', {
|
|
57
|
+
bubbles: true
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
32
60
|
/**
|
|
33
61
|
* @param {HTMLTextAreaElement|HTMLInputElement} input
|
|
34
62
|
* @param {string} text
|
|
@@ -36,6 +64,8 @@ function canManipulateViaTextNodes(input) {
|
|
|
36
64
|
*/
|
|
37
65
|
|
|
38
66
|
|
|
67
|
+
exports.insertAtLineStart = insertAtLineStart;
|
|
68
|
+
|
|
39
69
|
function insertTextAtPosition(input, text) {
|
|
40
70
|
// Most of the used APIs only work with the field selected
|
|
41
71
|
input.focus(); // IE 8-10
|
|
@@ -13,9 +13,19 @@
|
|
|
13
13
|
"createElement",
|
|
14
14
|
"value",
|
|
15
15
|
"firstChild",
|
|
16
|
+
"insertAtLineStart",
|
|
17
|
+
"val",
|
|
18
|
+
"cursorIdx",
|
|
19
|
+
"content",
|
|
20
|
+
"startIdx",
|
|
21
|
+
"char",
|
|
22
|
+
"focus",
|
|
23
|
+
"setRangeText",
|
|
24
|
+
"dispatchEvent",
|
|
25
|
+
"Event",
|
|
26
|
+
"bubbles",
|
|
16
27
|
"insertTextAtPosition",
|
|
17
28
|
"text",
|
|
18
|
-
"focus",
|
|
19
29
|
"selection",
|
|
20
30
|
"ieRange",
|
|
21
31
|
"createRange",
|
|
@@ -27,7 +37,6 @@
|
|
|
27
37
|
"selectionStart",
|
|
28
38
|
"end",
|
|
29
39
|
"selectionEnd",
|
|
30
|
-
"setRangeText",
|
|
31
40
|
"range",
|
|
32
41
|
"textNode",
|
|
33
42
|
"createTextNode",
|
|
@@ -49,11 +58,10 @@
|
|
|
49
58
|
"setSelectionRange",
|
|
50
59
|
"e",
|
|
51
60
|
"createEvent",
|
|
52
|
-
"initEvent"
|
|
53
|
-
"dispatchEvent"
|
|
61
|
+
"initEvent"
|
|
54
62
|
],
|
|
55
|
-
"mappings": "
|
|
63
|
+
"mappings": ";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA,IAAIA,gCAAJ;AAEA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAmCC,KAAnC,EAA2F;AACzF,MAAIA,KAAK,CAACC,QAAN,KAAmB,UAAvB,EAAmC;AACjC,WAAO,KAAP;AACD;;AACD,MAAI,OAAOH,gCAAP,KAA4C,WAAhD,EAA6D;AAC3D,QAAMI,QAA6B,GAAGC,QAAQ,CAACC,aAAT,CAAuB,UAAvB,CAAtC;AACAF,IAAAA,QAAQ,CAACG,KAAT,GAAiB,GAAjB;AACAP,IAAAA,gCAAgC,GAAG,CAAC,CAACI,QAAQ,CAACI,UAA9C;AACD;;AACD,SAAOR,gCAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,IAAMS,iBAAiB,GAAG,SAApBA,iBAAoB,CAC/BC,GAD+B,EAE/BC,SAF+B,EAG/BT,KAH+B,EAItB;AACT,MAAMU,OAAO,GAAGV,KAAK,CAACK,KAA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ACA;AACA;AACA;;;AACA,UAAI9C,yBAAyB,CAACC,KAAD,CAAzB,IAAoC+B,KAAK,CAACe,uBAAN,CAA8B7C,QAA9B,KAA2C,OAAnF,EAA4F;AAC1F;AACA8B,QAAAA,KAAK,CAACgB,UAAN,CAAiBf,QAAjB;AACD,OAHD,MAGO;AACL;AACA,YAAM3B,KAAK,GAAGL,KAAK,CAACK,KAApB;AACAL,QAAAA,KAAK,CAACK,KAAN,GAAcA,KAAK,CAAC2C,KAAN,CAAY,CAAZ,EAAerB,KAAf,IAAwBR,IAAxB,GAA+Bd,KAAK,CAAC2C,KAAN,CAAYnB,GAAZ,CAA7C;AACD;AACF,KA5Da,CA8Dd;;;AACA7B,IAAAA,KAAK,CAACiD,iBAAN,CAAwBtB,KAAK,GAAGR,IAAI,CAACsB,MAArC,EAA6Cd,KAAK,GAAGR,IAAI,CAACsB,MAA1D,EA/Dc,CAiEd;;AACA,QAAMS,CAAC,GAAG/C,QAAQ,CAACgD,WAAT,CAAqB,SAArB,CAAV;AACAD,IAAAA,CAAC,CAACE,SAAF,CAAY,OAAZ,EAAqB,IAArB,EAA2B,KAA3B;AACApD,IAAAA,KAAK,CAACe,aAAN,CAAoBmC,CAApB;AACD;AACF",
|
|
56
64
|
"sourcesContent": [
|
|
57
|
-
"/**\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) {\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 {HTMLTextAreaElement|HTMLInputElement} input\n * @param {string} text\n * @returns {void}\n */\nexport function insertTextAtPosition(input: HTMLTextAreaElement | HTMLInputElement, text: string) {\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
|
+
"/**\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"
|
|
58
66
|
]
|
|
59
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.4",
|
|
4
4
|
"description": "A markdown editor with preview, implemented with React.js and TypeScript.",
|
|
5
5
|
"homepage": "https://uiwjs.github.io/react-md-editor/",
|
|
6
6
|
"author": "kenny wang <wowohoo@qq.com>",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@kkt/react-library": "6.11.0",
|
|
45
45
|
"@kkt/scope-plugin-options": "6.11.0",
|
|
46
46
|
"@types/katex": "0.11.1",
|
|
47
|
-
"@types/react": "17.0.
|
|
47
|
+
"@types/react": "17.0.37",
|
|
48
48
|
"@types/react-dom": "17.0.11",
|
|
49
49
|
"@types/react-test-renderer": "17.0.1",
|
|
50
50
|
"@uiw/react-github-corners": "1.5.3",
|
|
@@ -53,15 +53,15 @@
|
|
|
53
53
|
"compile-less-cli": "1.8.9",
|
|
54
54
|
"katex": "0.15.1",
|
|
55
55
|
"husky": "7.0.4",
|
|
56
|
-
"jest-environment-jsdom": "27.3
|
|
56
|
+
"jest-environment-jsdom": "27.4.3",
|
|
57
57
|
"kkt": "6.11.0",
|
|
58
|
-
"lint-staged": "
|
|
59
|
-
"prettier": "2.
|
|
58
|
+
"lint-staged": "12.1.2",
|
|
59
|
+
"prettier": "2.5.0",
|
|
60
60
|
"react": "17.0.2",
|
|
61
61
|
"react-dom": "17.0.2",
|
|
62
62
|
"react-test-renderer": "17.0.2",
|
|
63
63
|
"source-map-explorer": "2.5.2",
|
|
64
|
-
"tsbb": "3.
|
|
64
|
+
"tsbb": "3.5.2"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@babel/runtime": "^7.14.6",
|
package/src/Context.tsx
CHANGED
|
@@ -12,7 +12,6 @@ export type ContextStore = {
|
|
|
12
12
|
fullscreen?: boolean;
|
|
13
13
|
highlightEnable?: boolean;
|
|
14
14
|
autoFocus?: boolean;
|
|
15
|
-
onChange?: (value?: string) => void;
|
|
16
15
|
textarea?: HTMLTextAreaElement;
|
|
17
16
|
commandOrchestrator?: TextAreaCommandOrchestrator;
|
|
18
17
|
textareaWarp?: HTMLDivElement;
|
package/src/Editor.tsx
CHANGED
|
@@ -84,7 +84,7 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
84
84
|
* Filter or modify your commands.
|
|
85
85
|
* https://github.com/uiwjs/react-md-editor/issues/296
|
|
86
86
|
*/
|
|
87
|
-
commandsFilter?: (command: ICommand) =>
|
|
87
|
+
commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;
|
|
88
88
|
/**
|
|
89
89
|
* You can create your own commands or reuse existing commands.
|
|
90
90
|
*/
|
|
@@ -134,7 +134,12 @@ const InternalMDEditor = (
|
|
|
134
134
|
...other
|
|
135
135
|
} = props || {};
|
|
136
136
|
|
|
137
|
-
const cmds = commands
|
|
137
|
+
const cmds = commands
|
|
138
|
+
.map((item) => (commandsFilter ? commandsFilter(item, false) : item))
|
|
139
|
+
.filter(Boolean) as ICommand[];
|
|
140
|
+
const extraCmds = extraCommands
|
|
141
|
+
.map((item) => (commandsFilter ? commandsFilter(item, true) : item))
|
|
142
|
+
.filter(Boolean) as ICommand[];
|
|
138
143
|
let [state, dispatch] = useReducer(reducer, {
|
|
139
144
|
markdown: propsValue,
|
|
140
145
|
preview: previewType,
|
|
@@ -144,9 +149,8 @@ const InternalMDEditor = (
|
|
|
144
149
|
scrollTop: 0,
|
|
145
150
|
scrollTopPreview: 0,
|
|
146
151
|
commands: cmds,
|
|
147
|
-
extraCommands,
|
|
152
|
+
extraCommands: extraCmds,
|
|
148
153
|
fullscreen,
|
|
149
|
-
onChange,
|
|
150
154
|
barPopup: {},
|
|
151
155
|
});
|
|
152
156
|
const container = useRef<HTMLDivElement>(null);
|
|
@@ -271,6 +275,12 @@ const InternalMDEditor = (
|
|
|
271
275
|
prefixCls={prefixCls}
|
|
272
276
|
autoFocus={autoFocus}
|
|
273
277
|
{...textareaProps}
|
|
278
|
+
onChange={(evn) => {
|
|
279
|
+
onChange && onChange(evn.target.value);
|
|
280
|
+
if (textareaProps && textareaProps.onChange) {
|
|
281
|
+
textareaProps.onChange(evn);
|
|
282
|
+
}
|
|
283
|
+
}}
|
|
274
284
|
renderTextarea={renderTextarea}
|
|
275
285
|
onScroll={(e) => handleScroll(e, 'text')}
|
|
276
286
|
/>
|
package/src/commands/title1.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { insertAtLineStart } from '../utils/InsertTextAtPosition';
|
|
2
3
|
import { ICommand, TextState, TextAreaTextApi } from './';
|
|
3
4
|
|
|
4
5
|
export const title1: ICommand = {
|
|
@@ -8,10 +9,10 @@ export const title1: ICommand = {
|
|
|
8
9
|
buttonProps: { 'aria-label': 'Insert title 1', title: 'Insert title 1' },
|
|
9
10
|
icon: <div style={{ fontSize: 18, textAlign: 'left' }}>Title 1</div>,
|
|
10
11
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
13
|
+
api.replaceSelection('# ');
|
|
14
|
+
} else {
|
|
15
|
+
insertAtLineStart('# ', state.selection.start, api.textArea);
|
|
14
16
|
}
|
|
15
|
-
api.replaceSelection(modifyText);
|
|
16
17
|
},
|
|
17
18
|
};
|
package/src/commands/title2.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { insertAtLineStart } from '../utils/InsertTextAtPosition';
|
|
2
3
|
import { ICommand, TextState, TextAreaTextApi } from './';
|
|
3
4
|
|
|
4
5
|
export const title2: ICommand = {
|
|
@@ -8,10 +9,10 @@ export const title2: ICommand = {
|
|
|
8
9
|
buttonProps: { 'aria-label': 'Insert title2', title: 'Insert title 2' },
|
|
9
10
|
icon: <div style={{ fontSize: 16, textAlign: 'left' }}>Title 2</div>,
|
|
10
11
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
13
|
+
api.replaceSelection('## ');
|
|
14
|
+
} else {
|
|
15
|
+
insertAtLineStart('## ', state.selection.start, api.textArea);
|
|
14
16
|
}
|
|
15
|
-
api.replaceSelection(modifyText);
|
|
16
17
|
},
|
|
17
18
|
};
|