@uiw/react-md-editor 3.14.0 → 3.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +22 -27
  2. package/dist/mdeditor.css +20 -11
  3. package/dist/mdeditor.js +773 -914
  4. package/dist/mdeditor.min.css +1 -1
  5. package/dist/mdeditor.min.js +1 -1
  6. package/esm/Editor.d.ts +4 -0
  7. package/esm/Editor.js +1 -1
  8. package/esm/Editor.js.map +3 -2
  9. package/esm/commands/bold.js +1 -1
  10. package/esm/commands/bold.js.map +2 -2
  11. package/esm/components/TextArea/Markdown.js +31 -24
  12. package/esm/components/TextArea/Markdown.js.map +12 -9
  13. package/esm/components/TextArea/index.js +3 -3
  14. package/esm/components/TextArea/index.js.map +4 -4
  15. package/esm/index.css +4 -0
  16. package/esm/index.less +6 -0
  17. package/lib/Context.js +3 -3
  18. package/lib/Context.js.map +1 -1
  19. package/lib/Editor.d.ts +4 -0
  20. package/lib/Editor.js +20 -20
  21. package/lib/Editor.js.map +3 -2
  22. package/lib/commands/bold.js +2 -2
  23. package/lib/commands/bold.js.map +1 -1
  24. package/lib/commands/code.js +1 -1
  25. package/lib/commands/fullscreen.js +1 -1
  26. package/lib/commands/group.js +4 -4
  27. package/lib/commands/group.js.map +1 -1
  28. package/lib/commands/hr.js +1 -1
  29. package/lib/commands/image.js +1 -1
  30. package/lib/commands/index.js +8 -8
  31. package/lib/commands/italic.js +1 -1
  32. package/lib/commands/link.js +1 -1
  33. package/lib/commands/list.js +1 -1
  34. package/lib/commands/preview.js +1 -1
  35. package/lib/commands/quote.js +1 -1
  36. package/lib/commands/strikeThrough.js +1 -1
  37. package/lib/commands/title.js +2 -2
  38. package/lib/commands/title.js.map +1 -1
  39. package/lib/commands/title1.js +1 -1
  40. package/lib/commands/title2.js +1 -1
  41. package/lib/commands/title3.js +1 -1
  42. package/lib/commands/title4.js +1 -1
  43. package/lib/commands/title5.js +1 -1
  44. package/lib/commands/title6.js +1 -1
  45. package/lib/components/DragBar/index.js +3 -3
  46. package/lib/components/TextArea/Markdown.js +39 -33
  47. package/lib/components/TextArea/Markdown.js.map +12 -9
  48. package/lib/components/TextArea/Textarea.js +10 -10
  49. package/lib/components/TextArea/Textarea.js.map +1 -1
  50. package/lib/components/TextArea/handleKeyDown.js +1 -1
  51. package/lib/components/TextArea/index.js +15 -15
  52. package/lib/components/TextArea/index.js.map +4 -4
  53. package/lib/components/TextArea/shortcuts.js +3 -3
  54. package/lib/components/TextArea/shortcuts.js.map +1 -1
  55. package/lib/components/Toolbar/Child.js +4 -4
  56. package/lib/components/Toolbar/Child.js.map +1 -1
  57. package/lib/components/Toolbar/index.js +11 -11
  58. package/lib/components/Toolbar/index.js.map +1 -1
  59. package/lib/index.js +4 -4
  60. package/lib/index.js.map +1 -1
  61. package/lib/index.less +6 -0
  62. package/lib/utils/InsertTextAtPosition.js +2 -2
  63. package/lib/utils/InsertTextAtPosition.js.map +1 -1
  64. package/markdown-editor.css +4 -0
  65. package/package.json +2 -60
  66. package/src/Editor.tsx +5 -1
  67. package/src/commands/bold.tsx +1 -1
  68. package/src/components/TextArea/Markdown.tsx +31 -24
  69. package/src/components/TextArea/index.tsx +1 -2
  70. package/src/index.less +6 -0
  71. package/LICENSE +0 -21
  72. package/src/tsconfig.json +0 -8
@@ -264,6 +264,10 @@
264
264
  width: 50%;
265
265
  height: 100%;
266
266
  }
267
+ .w-md-editor-text-pre > code {
268
+ word-break: break-word !important;
269
+ white-space: pre-wrap !important;
270
+ }
267
271
  .w-md-editor-preview {
268
272
  width: 50%;
269
273
  box-sizing: border-box;
package/package.json CHANGED
@@ -1,16 +1,12 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "3.14.0",
3
+ "version": "3.14.3",
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>",
7
7
  "main": "lib/index.js",
8
8
  "module": "esm/index.js",
9
9
  "scripts": {
10
- "prepare": "husky install && npm run build",
11
- "released": "npm run build && npm run doc",
12
- "doc": "kkt build --app-src ./website",
13
- "start": "kkt start --app-src ./website",
14
10
  "css:build": "compile-less -d src -o esm",
15
11
  "css:watch": "compile-less -d src -o esm --watch",
16
12
  "css:build:dist": "compile-less -d src --combine markdown-editor.css --rm-global",
@@ -20,9 +16,7 @@
20
16
  "watch": "tsbb watch & npm run css:watch",
21
17
  "build": "tsbb build && npm run css:build && npm run css:build:dist",
22
18
  "test": "tsbb test --env=jsdom",
23
- "coverage": "tsbb test --env=jsdom --coverage --bail",
24
- "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
25
- "map": "source-map-explorer build/static/js/*.js --html build/website-result.html"
19
+ "coverage": "tsbb test --env=jsdom --coverage --bail"
26
20
  },
27
21
  "repository": {
28
22
  "type": "git",
@@ -40,35 +34,9 @@
40
34
  "react": ">=16.8.0",
41
35
  "react-dom": ">=16.8.0"
42
36
  },
43
- "devDependencies": {
44
- "@kkt/less-modules": "~7.1.1",
45
- "@kkt/ncc": "~1.0.9",
46
- "@kkt/raw-modules": "~7.1.1",
47
- "@kkt/scope-plugin-options": "~7.1.1",
48
- "@types/katex": "~0.14.0",
49
- "@types/react": "~18.0.9",
50
- "@types/react-dom": "~18.0.3",
51
- "@types/react-test-renderer": "~18.0.0",
52
- "@uiw/react-github-corners": "~1.5.3",
53
- "@uiw/react-shields": "~1.1.2",
54
- "@wcj/dark-mode": "~1.0.9",
55
- "compile-less-cli": "~1.8.13",
56
- "katex": "~0.15.2",
57
- "husky": "~8.0.0",
58
- "kkt": "~7.1.5",
59
- "lint-staged": "~12.4.0",
60
- "mermaid": "~8.14.0",
61
- "prettier": "~2.6.0",
62
- "react": "~18.1.0",
63
- "react-dom": "~18.1.0",
64
- "react-test-renderer": "~18.1.0",
65
- "source-map-explorer": "~2.5.2",
66
- "tsbb": "~3.7.0"
67
- },
68
37
  "dependencies": {
69
38
  "@babel/runtime": "^7.14.6",
70
39
  "@uiw/react-markdown-preview": "^4.0.10",
71
- "rehype-sanitize": "~5.0.1",
72
40
  "rehype": "~12.0.1"
73
41
  },
74
42
  "keywords": [
@@ -89,31 +57,5 @@
89
57
  "transformIgnorePatterns": [
90
58
  "<rootDir>/node_modules/?!(.*)"
91
59
  ]
92
- },
93
- "lint-staged": {
94
- "*.{js,jsx,less,md,json}": [
95
- "prettier --write"
96
- ],
97
- "*.ts?(x)": [
98
- "prettier --parser=typescript --write"
99
- ]
100
- },
101
- "eslintConfig": {
102
- "extends": [
103
- "react-app",
104
- "react-app/jest"
105
- ]
106
- },
107
- "browserslist": {
108
- "production": [
109
- ">0.2%",
110
- "not dead",
111
- "not op_mini all"
112
- ],
113
- "development": [
114
- "last 1 chrome version",
115
- "last 1 firefox version",
116
- "last 1 safari version"
117
- ]
118
60
  }
119
61
  }
package/src/Editor.tsx CHANGED
@@ -44,6 +44,10 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
44
44
  * Show drag and drop tool. Set the height of the editor.
45
45
  */
46
46
  visibleDragbar?: boolean;
47
+ /**
48
+ * @deprecated use `visibleDragbar`
49
+ */
50
+ visiableDragbar?: boolean;
47
51
  /**
48
52
  * Show markdown preview.
49
53
  */
@@ -132,7 +136,7 @@ const InternalMDEditor = (
132
136
  height = 200,
133
137
  toolbarHeight = 29,
134
138
  enableScroll = true,
135
- visibleDragbar = true,
139
+ visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,
136
140
  highlightEnable = true,
137
141
  preview: previewType = 'live',
138
142
  fullscreen = false,
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { ICommand, TextState, TextAreaTextApi } from './';
3
3
  import { selectWord } from '../utils/markdownUtils';
4
4
 
@@ -4,11 +4,25 @@ import rehypePrism from 'rehype-prism-plus';
4
4
  import { IProps } from '../../Editor';
5
5
  import { EditorContext } from '../../Context';
6
6
 
7
+ function html2Escape(sHtml: string) {
8
+ return sHtml
9
+ .replace(/```(tsx?|jsx?|html|xml)(.*)\s+([\s\S]*?)(\s.+)?```/g, (str: string) => {
10
+ return str.replace(
11
+ /[<&"]/g,
12
+ (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' } as Record<string, string>)[c]),
13
+ );
14
+ })
15
+ .replace(
16
+ /[<&"]/g,
17
+ (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' } as Record<string, string>)[c]),
18
+ );
19
+ }
20
+
7
21
  export interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {}
8
22
 
9
23
  export default function Markdown(props: MarkdownProps) {
10
24
  const { prefixCls } = props;
11
- const { markdown = '', dispatch } = useContext(EditorContext);
25
+ const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);
12
26
  const preRef = React.createRef<HTMLPreElement>();
13
27
  useEffect(() => {
14
28
  if (preRef.current && dispatch) {
@@ -16,35 +30,28 @@ export default function Markdown(props: MarkdownProps) {
16
30
  }
17
31
  // eslint-disable-next-line react-hooks/exhaustive-deps
18
32
  }, []);
19
- function html2Escape(sHtml: string) {
20
- return sHtml
21
- .replace(/```(tsx?|jsx?|html|xml)(.*)\s+([\s\S]*?)(\s.+)?```/g, (str: string) => {
22
- return str.replace(
23
- /[<&"]/g,
24
- (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' } as Record<string, string>)[c]),
25
- );
26
- })
27
- .replace(
28
- /[<&"]/g,
29
- (c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' } as Record<string, string>)[c]),
30
- );
31
- }
32
33
 
33
34
  return useMemo(() => {
34
35
  if (!markdown) {
35
- return <pre children={markdown || ''} ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;
36
+ return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;
36
37
  }
37
- const str = rehype()
38
- .data('settings', { fragment: true })
39
- .use(rehypePrism, { ignoreMissing: true })
40
- .processSync(
41
- `<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
42
- markdown,
43
- )}\n</code></pre>`,
44
- );
38
+ let mdStr = `<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
39
+ markdown,
40
+ )}\n</code></pre>`;
41
+
42
+ if (highlightEnable) {
43
+ try {
44
+ mdStr = rehype()
45
+ .data('settings', { fragment: true })
46
+ .use(rehypePrism, { ignoreMissing: false })
47
+ .processSync(mdStr)
48
+ .toString();
49
+ } catch (error) {}
50
+ }
51
+
45
52
  return React.createElement('div', {
46
53
  className: 'wmde-markdown-color',
47
- dangerouslySetInnerHTML: { __html: str.value as string },
54
+ dangerouslySetInnerHTML: { __html: mdStr || '' },
48
55
  });
49
56
  }, [markdown, preRef, prefixCls]);
50
57
  }
@@ -67,8 +67,7 @@ export default function TextArea(props: ITextAreaProps) {
67
67
  // eslint-disable-next-line react-hooks/exhaustive-deps
68
68
  }, []);
69
69
 
70
- // @ts-ignore
71
- const textStyle: React.CSSProperties = highlightEnable ? {} : { '-webkit-text-fill-color': 'inherit' };
70
+ const textStyle: React.CSSProperties = highlightEnable ? {} : { WebkitTextFillColor: 'initial', overflow: 'auto' };
72
71
 
73
72
  return (
74
73
  <div ref={warp} className={`${prefixCls}-aree ${className || ''}`} onScroll={onScroll}>
package/src/index.less CHANGED
@@ -22,6 +22,10 @@
22
22
  width: 50%;
23
23
  height: 100%;
24
24
  }
25
+ &-text-pre > code {
26
+ word-break: break-word !important;
27
+ white-space: pre-wrap !important;
28
+ }
25
29
  &-preview {
26
30
  width: 50%;
27
31
  box-sizing: border-box;
@@ -35,6 +39,8 @@
35
39
  border-radius: 0 0 5px 0;
36
40
  display: flex;
37
41
  flex-direction: column;
42
+ // word-break: break-word !important;
43
+ // white-space: pre-wrap !important;
38
44
  .anchor {
39
45
  display: none;
40
46
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 uiw
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/src/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../tsconfig",
3
- "compilerOptions": {
4
- "baseUrl": "../cjs",
5
- "emitDeclarationOnly": true,
6
- "noEmit": false
7
- }
8
- }