@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
package/README.md
CHANGED
|
@@ -399,7 +399,7 @@ export default HomePage;
|
|
|
399
399
|
- `value: string`: The Markdown value.
|
|
400
400
|
- `onChange?: (value: string)`: Event handler for the `onChange` event.
|
|
401
401
|
- `commands?: ICommand[]`: An array of [`ICommand`](https://github.com/uiwjs/react-md-editor/blob/d02543050c9abd8f7c72ae02b6421ac2e6ae421a/src/commands/index.ts#L39-L57), which, each one, contain a [`commands`](https://github.com/uiwjs/react-md-editor/blob/d02543050c9abd8f7c72ae02b6421ac2e6ae421a/src/commands/index.ts#L155-L180) property. If no commands are specified, the default will be used. Commands are explained in more details below.
|
|
402
|
-
- `commandsFilter?: (command: ICommand) =>
|
|
402
|
+
- `commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand`: Filter or modify your commands.
|
|
403
403
|
- `extraCommands?: ICommand[]`: Displayed on the right side of the toolbar.
|
|
404
404
|
- `autoFocus?: true`: Can be used to make `Markdown Editor` focus itself on initialization.
|
|
405
405
|
- `previewOptions?: ReactMarkdown.ReactMarkdownProps`: This is reset [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview/tree/e6e8462d9a5c64a7045e25adcb4928095d74ca37#options-props) settings.
|
package/esm/Context.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export declare type ContextStore = {
|
|
|
10
10
|
fullscreen?: boolean;
|
|
11
11
|
highlightEnable?: boolean;
|
|
12
12
|
autoFocus?: boolean;
|
|
13
|
-
onChange?: (value?: string) => void;
|
|
14
13
|
textarea?: HTMLTextAreaElement;
|
|
15
14
|
commandOrchestrator?: TextAreaCommandOrchestrator;
|
|
16
15
|
textareaWarp?: HTMLDivElement;
|
|
@@ -32,7 +31,6 @@ export declare function reducer(state: ContextStore, action: ContextStore): {
|
|
|
32
31
|
fullscreen?: boolean | undefined;
|
|
33
32
|
highlightEnable?: boolean | undefined;
|
|
34
33
|
autoFocus?: boolean | undefined;
|
|
35
|
-
onChange?: ((value?: string | undefined) => void) | undefined;
|
|
36
34
|
textarea?: HTMLTextAreaElement | undefined;
|
|
37
35
|
commandOrchestrator?: TextAreaCommandOrchestrator | undefined;
|
|
38
36
|
textareaWarp?: HTMLDivElement | undefined;
|
package/esm/Context.js.map
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"createContext",
|
|
13
13
|
"markdown"
|
|
14
14
|
],
|
|
15
|
-
"mappings": ";AAAA,OAAOA,KAAP,MAAkB,OAAlB;
|
|
15
|
+
"mappings": ";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AA4BA,OAAO,SAASC,OAAT,CAAiBC,KAAjB,EAAsCC,MAAtC,EAA4D;AACjE,sBAAYD,KAAZ,EAAsBC,MAAtB;AACD;AAED,OAAO,IAAMC,aAAa,gBAAGJ,KAAK,CAACK,aAAN,CAAkC;AAAEC,EAAAA,QAAQ,EAAE;AAAZ,CAAlC,CAAtB",
|
|
16
16
|
"sourcesContent": [
|
|
17
|
-
"import React from 'react';\nimport { ICommand, TextAreaCommandOrchestrator } from './commands';\n\nexport type PreviewType = 'live' | 'edit' | 'preview';\n\nexport type ContextStore = {\n commands?: ICommand<string>[];\n extraCommands?: ICommand<string>[];\n markdown?: string;\n preview?: PreviewType;\n height?: number;\n fullscreen?: boolean;\n highlightEnable?: boolean;\n autoFocus?: boolean;\n
|
|
17
|
+
"import React from 'react';\nimport { ICommand, TextAreaCommandOrchestrator } from './commands';\n\nexport type PreviewType = 'live' | 'edit' | 'preview';\n\nexport type ContextStore = {\n commands?: ICommand<string>[];\n extraCommands?: ICommand<string>[];\n markdown?: string;\n preview?: PreviewType;\n height?: number;\n fullscreen?: boolean;\n highlightEnable?: boolean;\n autoFocus?: boolean;\n textarea?: HTMLTextAreaElement;\n commandOrchestrator?: TextAreaCommandOrchestrator;\n textareaWarp?: HTMLDivElement;\n textareaPre?: HTMLPreElement;\n container?: HTMLDivElement | null;\n dispatch?: React.Dispatch<ContextStore>;\n barPopup?: Record<string, boolean>;\n scrollTop?: number;\n scrollTopPreview?: number;\n tabSize?: number;\n};\n\nexport type ExecuteCommandState = Pick<ContextStore, 'fullscreen' | 'preview' | 'highlightEnable'>;\n\nexport function reducer(state: ContextStore, action: ContextStore) {\n return { ...state, ...action };\n}\n\nexport const EditorContext = React.createContext<ContextStore>({ markdown: '' });\n"
|
|
18
18
|
]
|
|
19
19
|
}
|
package/esm/Editor.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
80
80
|
* Filter or modify your commands.
|
|
81
81
|
* https://github.com/uiwjs/react-md-editor/issues/296
|
|
82
82
|
*/
|
|
83
|
-
commandsFilter?: (command: ICommand) =>
|
|
83
|
+
commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;
|
|
84
84
|
/**
|
|
85
85
|
* You can create your own commands or reuse existing commands.
|
|
86
86
|
*/
|
package/esm/Editor.js
CHANGED
|
@@ -45,13 +45,14 @@ var InternalMDEditor = (props, ref) => {
|
|
|
45
45
|
minHeight = 100,
|
|
46
46
|
autoFocus,
|
|
47
47
|
tabSize = 2,
|
|
48
|
-
onChange,
|
|
48
|
+
onChange: _onChange,
|
|
49
49
|
hideToolbar,
|
|
50
50
|
renderTextarea
|
|
51
51
|
} = _ref,
|
|
52
52
|
other = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
53
53
|
|
|
54
|
-
var cmds = commands.map(item => commandsFilter ? commandsFilter(item) : item).filter(Boolean);
|
|
54
|
+
var cmds = commands.map(item => commandsFilter ? commandsFilter(item, false) : item).filter(Boolean);
|
|
55
|
+
var extraCmds = extraCommands.map(item => commandsFilter ? commandsFilter(item, true) : item).filter(Boolean);
|
|
55
56
|
var [state, dispatch] = useReducer(reducer, {
|
|
56
57
|
markdown: propsValue,
|
|
57
58
|
preview: previewType,
|
|
@@ -61,9 +62,8 @@ var InternalMDEditor = (props, ref) => {
|
|
|
61
62
|
scrollTop: 0,
|
|
62
63
|
scrollTopPreview: 0,
|
|
63
64
|
commands: cmds,
|
|
64
|
-
extraCommands,
|
|
65
|
+
extraCommands: extraCmds,
|
|
65
66
|
fullscreen,
|
|
66
|
-
onChange,
|
|
67
67
|
barPopup: {}
|
|
68
68
|
});
|
|
69
69
|
var container = useRef(null);
|
|
@@ -194,6 +194,13 @@ var InternalMDEditor = (props, ref) => {
|
|
|
194
194
|
prefixCls: prefixCls,
|
|
195
195
|
autoFocus: autoFocus
|
|
196
196
|
}, textareaProps, {
|
|
197
|
+
onChange: evn => {
|
|
198
|
+
_onChange && _onChange(evn.target.value);
|
|
199
|
+
|
|
200
|
+
if (textareaProps && textareaProps.onChange) {
|
|
201
|
+
textareaProps.onChange(evn);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
197
204
|
renderTextarea: renderTextarea,
|
|
198
205
|
onScroll: e => handleScroll(e, 'text')
|
|
199
206
|
})), /(live|preview)/.test(state.preview || '') && /*#__PURE__*/_jsx(MarkdownPreview, _extends({}, previewOptions, {
|
package/esm/Editor.js.map
CHANGED
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"item",
|
|
58
58
|
"filter",
|
|
59
59
|
"Boolean",
|
|
60
|
+
"extraCmds",
|
|
60
61
|
"state",
|
|
61
62
|
"d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kBAA0Be,cAAc,CAACd,SAAf,IAA4B,EAAtD;AALX,WAvBJ;AAAA,QAbF,EA6CGS,eAAe,IAAI,CAACqB,KAAK,CAACjB,UAA1B,iBACC,KAAC,OAAD;AACE,QAAA,SAAS,EAAEd,SADb;AAEE,QAAA,MAAM,EAAE+B,KAAK,CAACxB,MAFhB;AAGE,QAAA,SAAS,EAAEU,SAHb;AAIE,QAAA,SAAS,EAAEC,SAJb;AAKE,QAAA,QAAQ,EAAG+C,SAAD,IAAe;AACvBjC,UAAAA,QAAQ,CAAC;AAAEzB,YAAAA,MAAM,EAAE0D;AAAV,WAAD,CAAR;AACD;AAPH,QA9CJ;AAAA;AADF,IADF;AA6DD,CA7MD;;AA+MA,IAAMC,QAAQ,gBAAGzF,KAAK,CAAC0F,UAAN,CAA8CtE,gBAA9C,CAAjB;AAMCqE,QAAD,CAAuBE,QAAvB,GAAkCrF,eAAlC;AAEA,eAAemF,QAAf",
|
|
99
101
|
"sourcesContent": [
|
|
100
|
-
"import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';\nimport MarkdownPreview, { MarkdownPreviewProps, MarkdownPreviewRef } from '@uiw/react-markdown-preview';\nimport TextArea, { ITextAreaProps } from './components/TextArea';\nimport Toolbar from './components/Toolbar';\nimport DragBar from './components/DragBar';\nimport { getCommands, getExtraCommands, ICommand } from './commands';\nimport { reducer, EditorContext, ContextStore, PreviewType } from './Context';\nimport './index.less';\n\nexport interface IProps {\n prefixCls?: string;\n className?: string;\n}\n\nexport interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {\n /**\n * The Markdown value.\n */\n value?: string;\n /**\n * Event handler for the `onChange` event.\n */\n onChange?: (value?: string) => void;\n /**\n * Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.\n * it will be set to true when either the source `textarea` is focused,\n * or it has an `autofocus` attribute and no other element is focused.\n */\n autoFocus?: ITextAreaProps['autoFocus'];\n /**\n * The height of the editor.\n */\n height?: number;\n /**\n * Custom toolbar heigth\n * @default 29px\n */\n toolbarHeight?: number;\n /**\n * Show drag and drop tool. Set the height of the editor.\n */\n visiableDragbar?: boolean;\n /**\n * Show markdown preview.\n */\n preview?: PreviewType;\n /**\n * Full screen display editor.\n */\n fullscreen?: boolean;\n /**\n * Maximum drag height. `visiableDragbar=true`\n */\n maxHeight?: number;\n /**\n * Minimum drag height. `visiableDragbar=true`\n */\n minHeight?: number;\n /**\n * This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.\n */\n previewOptions?: Omit<MarkdownPreviewProps, 'source'>;\n /**\n * Set the `textarea` related props.\n */\n textareaProps?: ITextAreaProps;\n /** Use div to replace TextArea or re-render TextArea */\n renderTextarea?: ITextAreaProps['renderTextarea'];\n /**\n * Disable editing area code highlighting. The value is `false`, which increases the editing speed.\n * @default true\n */\n highlightEnable?: boolean;\n /**\n * The number of characters to insert when pressing tab key.\n * Default `2` spaces.\n */\n tabSize?: number;\n /**\n * You can create your own commands or reuse existing commands.\n */\n commands?: ICommand[];\n /**\n * Filter or modify your commands.\n * https://github.com/uiwjs/react-md-editor/issues/296\n */\n commandsFilter?: (command: ICommand) => boolean | ICommand;\n /**\n * You can create your own commands or reuse existing commands.\n */\n extraCommands?: ICommand[];\n /**\n * Hide the tool bar\n */\n hideToolbar?: boolean;\n /** Whether to enable scrolling */\n enableScroll?: boolean;\n}\n\nfunction setGroupPopFalse(data: Record<string, boolean> = {}) {\n Object.keys(data).forEach((keyname) => {\n data[keyname] = false;\n });\n return data;\n}\n\nconst InternalMDEditor = (\n props: MDEditorProps,\n ref?: ((instance: ContextStore) => void) | React.RefObject<ContextStore> | null,\n) => {\n const {\n prefixCls = 'w-md-editor',\n className,\n value: propsValue,\n commands = getCommands(),\n commandsFilter,\n extraCommands = getExtraCommands(),\n height = 200,\n toolbarHeight = 29,\n enableScroll = true,\n visiableDragbar = true,\n highlightEnable = true,\n preview: previewType = 'live',\n fullscreen = false,\n previewOptions = {},\n textareaProps,\n maxHeight = 1200,\n minHeight = 100,\n autoFocus,\n tabSize = 2,\n onChange,\n hideToolbar,\n renderTextarea,\n ...other\n } = props || {};\n\n const cmds = commands.map((item) => (commandsFilter ? commandsFilter(item) : item)).filter(Boolean) as ICommand[];\n let [state, dispatch] = useReducer(reducer, {\n markdown: propsValue,\n preview: previewType,\n height,\n highlightEnable,\n tabSize,\n scrollTop: 0,\n scrollTopPreview: 0,\n commands: cmds,\n extraCommands,\n fullscreen,\n onChange,\n barPopup: {},\n });\n const container = useRef<HTMLDivElement>(null);\n const previewRef = useRef<MarkdownPreviewRef>(null);\n const enableScrollRef = useRef(enableScroll);\n\n useImperativeHandle(ref, () => ({ ...state }));\n useMemo(() => (enableScrollRef.current = enableScroll), [enableScroll]);\n useEffect(() => {\n const stateInit: ContextStore = {};\n if (container.current) {\n stateInit.container = container.current || undefined;\n }\n stateInit.markdown = propsValue || '';\n stateInit.barPopup = {};\n if (dispatch) {\n dispatch({ ...state, ...stateInit });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const cls = [\n className,\n prefixCls,\n state.preview ? `${prefixCls}-show-${state.preview}` : null,\n state.fullscreen ? `${prefixCls}-fullscreen` : null,\n ]\n .filter(Boolean)\n .join(' ')\n .trim();\n\n useMemo(\n () => propsValue !== state.markdown && dispatch({ markdown: propsValue || '' }),\n [propsValue, state.markdown],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => previewType !== state.preview && dispatch({ preview: previewType }), [previewType]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => height !== state.height && dispatch({ height: height }), [height]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => tabSize !== state.tabSize && dispatch({ tabSize }), [tabSize]);\n useMemo(\n () => highlightEnable !== state.highlightEnable && dispatch({ highlightEnable }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [highlightEnable],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);\n useMemo(\n () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [fullscreen],\n );\n\n const textareaDomRef = useRef<HTMLDivElement>();\n const active = useRef<'text' | 'preview'>('preview');\n const initScroll = useRef(false);\n\n useMemo(() => {\n textareaDomRef.current = state.textareaWarp;\n if (state.textareaWarp) {\n state.textareaWarp.addEventListener('mouseover', () => {\n active.current = 'text';\n });\n state.textareaWarp.addEventListener('mouseleave', () => {\n active.current = 'preview';\n });\n }\n }, [state.textareaWarp]);\n\n const handleScroll = (e: React.UIEvent<HTMLDivElement>, type: 'text' | 'preview') => {\n if (!enableScrollRef.current) return;\n const textareaDom = textareaDomRef.current;\n const previewDom = previewRef.current ? previewRef.current.mdp.current : undefined;\n if (!initScroll.current) {\n active.current = type;\n initScroll.current = true;\n }\n if (textareaDom && previewDom) {\n const scale =\n (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);\n if (e.target === textareaDom && active.current === 'text') {\n previewDom.scrollTop = textareaDom.scrollTop / scale;\n }\n if (e.target === previewDom && active.current === 'preview') {\n textareaDom.scrollTop = previewDom.scrollTop * scale;\n }\n let scrollTop = 0;\n if (active.current === 'text') {\n scrollTop = textareaDom.scrollTop || 0;\n } else if (active.current === 'preview') {\n scrollTop = previewDom.scrollTop || 0;\n }\n dispatch({ scrollTop });\n }\n };\n\n return (\n <EditorContext.Provider value={{ ...state, dispatch }}>\n <div\n ref={container}\n className={cls}\n {...other}\n onClick={() => {\n dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });\n }}\n style={{\n ...other.style,\n height: state.fullscreen ? '100%' : hideToolbar ? Number(state.height) - toolbarHeight : state.height,\n }}\n >\n {!hideToolbar && <Toolbar prefixCls={prefixCls} height={toolbarHeight} />}\n <div\n className={`${prefixCls}-content`}\n style={{\n height: state.fullscreen ? `calc(100% - ${toolbarHeight}px)` : Number(state.height) - toolbarHeight,\n }}\n >\n {/(edit|live)/.test(state.preview || '') && (\n <TextArea\n className={`${prefixCls}-input`}\n prefixCls={prefixCls}\n autoFocus={autoFocus}\n {...textareaProps}\n renderTextarea={renderTextarea}\n onScroll={(e) => handleScroll(e, 'text')}\n />\n )}\n {/(live|preview)/.test(state.preview || '') && (\n <MarkdownPreview\n {...previewOptions}\n onScroll={(e) => handleScroll(e, 'preview')}\n ref={previewRef}\n source={state.markdown || ''}\n className={`${prefixCls}-preview ${previewOptions.className || ''}`}\n />\n )}\n </div>\n {visiableDragbar && !state.fullscreen && (\n <DragBar\n prefixCls={prefixCls}\n height={state.height as number}\n maxHeight={maxHeight!}\n minHeight={minHeight!}\n onChange={(newHeight) => {\n dispatch({ height: newHeight });\n }}\n />\n )}\n </div>\n </EditorContext.Provider>\n );\n};\n\nconst mdEditor = React.forwardRef<ContextStore, MDEditorProps>(InternalMDEditor);\n\ntype MDEditor = typeof mdEditor & {\n Markdown: typeof MarkdownPreview;\n};\n\n(mdEditor as MDEditor).Markdown = MarkdownPreview;\n\nexport default mdEditor as MDEditor;\n"
|
|
102
|
+
"import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';\nimport MarkdownPreview, { MarkdownPreviewProps, MarkdownPreviewRef } from '@uiw/react-markdown-preview';\nimport TextArea, { ITextAreaProps } from './components/TextArea';\nimport Toolbar from './components/Toolbar';\nimport DragBar from './components/DragBar';\nimport { getCommands, getExtraCommands, ICommand } from './commands';\nimport { reducer, EditorContext, ContextStore, PreviewType } from './Context';\nimport './index.less';\n\nexport interface IProps {\n prefixCls?: string;\n className?: string;\n}\n\nexport interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, IProps {\n /**\n * The Markdown value.\n */\n value?: string;\n /**\n * Event handler for the `onChange` event.\n */\n onChange?: (value?: string) => void;\n /**\n * Can be used to make `Markdown Editor` focus itself on initialization. Defaults to on.\n * it will be set to true when either the source `textarea` is focused,\n * or it has an `autofocus` attribute and no other element is focused.\n */\n autoFocus?: ITextAreaProps['autoFocus'];\n /**\n * The height of the editor.\n */\n height?: number;\n /**\n * Custom toolbar heigth\n * @default 29px\n */\n toolbarHeight?: number;\n /**\n * Show drag and drop tool. Set the height of the editor.\n */\n visiableDragbar?: boolean;\n /**\n * Show markdown preview.\n */\n preview?: PreviewType;\n /**\n * Full screen display editor.\n */\n fullscreen?: boolean;\n /**\n * Maximum drag height. `visiableDragbar=true`\n */\n maxHeight?: number;\n /**\n * Minimum drag height. `visiableDragbar=true`\n */\n minHeight?: number;\n /**\n * This is reset [react-markdown](https://github.com/rexxars/react-markdown) settings.\n */\n previewOptions?: Omit<MarkdownPreviewProps, 'source'>;\n /**\n * Set the `textarea` related props.\n */\n textareaProps?: ITextAreaProps;\n /** Use div to replace TextArea or re-render TextArea */\n renderTextarea?: ITextAreaProps['renderTextarea'];\n /**\n * Disable editing area code highlighting. The value is `false`, which increases the editing speed.\n * @default true\n */\n highlightEnable?: boolean;\n /**\n * The number of characters to insert when pressing tab key.\n * Default `2` spaces.\n */\n tabSize?: number;\n /**\n * You can create your own commands or reuse existing commands.\n */\n commands?: ICommand[];\n /**\n * Filter or modify your commands.\n * https://github.com/uiwjs/react-md-editor/issues/296\n */\n commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand;\n /**\n * You can create your own commands or reuse existing commands.\n */\n extraCommands?: ICommand[];\n /**\n * Hide the tool bar\n */\n hideToolbar?: boolean;\n /** Whether to enable scrolling */\n enableScroll?: boolean;\n}\n\nfunction setGroupPopFalse(data: Record<string, boolean> = {}) {\n Object.keys(data).forEach((keyname) => {\n data[keyname] = false;\n });\n return data;\n}\n\nconst InternalMDEditor = (\n props: MDEditorProps,\n ref?: ((instance: ContextStore) => void) | React.RefObject<ContextStore> | null,\n) => {\n const {\n prefixCls = 'w-md-editor',\n className,\n value: propsValue,\n commands = getCommands(),\n commandsFilter,\n extraCommands = getExtraCommands(),\n height = 200,\n toolbarHeight = 29,\n enableScroll = true,\n visiableDragbar = true,\n highlightEnable = true,\n preview: previewType = 'live',\n fullscreen = false,\n previewOptions = {},\n textareaProps,\n maxHeight = 1200,\n minHeight = 100,\n autoFocus,\n tabSize = 2,\n onChange,\n hideToolbar,\n renderTextarea,\n ...other\n } = props || {};\n\n const cmds = commands\n .map((item) => (commandsFilter ? commandsFilter(item, false) : item))\n .filter(Boolean) as ICommand[];\n const extraCmds = extraCommands\n .map((item) => (commandsFilter ? commandsFilter(item, true) : item))\n .filter(Boolean) as ICommand[];\n let [state, dispatch] = useReducer(reducer, {\n markdown: propsValue,\n preview: previewType,\n height,\n highlightEnable,\n tabSize,\n scrollTop: 0,\n scrollTopPreview: 0,\n commands: cmds,\n extraCommands: extraCmds,\n fullscreen,\n barPopup: {},\n });\n const container = useRef<HTMLDivElement>(null);\n const previewRef = useRef<MarkdownPreviewRef>(null);\n const enableScrollRef = useRef(enableScroll);\n\n useImperativeHandle(ref, () => ({ ...state }));\n useMemo(() => (enableScrollRef.current = enableScroll), [enableScroll]);\n useEffect(() => {\n const stateInit: ContextStore = {};\n if (container.current) {\n stateInit.container = container.current || undefined;\n }\n stateInit.markdown = propsValue || '';\n stateInit.barPopup = {};\n if (dispatch) {\n dispatch({ ...state, ...stateInit });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const cls = [\n className,\n prefixCls,\n state.preview ? `${prefixCls}-show-${state.preview}` : null,\n state.fullscreen ? `${prefixCls}-fullscreen` : null,\n ]\n .filter(Boolean)\n .join(' ')\n .trim();\n\n useMemo(\n () => propsValue !== state.markdown && dispatch({ markdown: propsValue || '' }),\n [propsValue, state.markdown],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => previewType !== state.preview && dispatch({ preview: previewType }), [previewType]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => height !== state.height && dispatch({ height: height }), [height]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => tabSize !== state.tabSize && dispatch({ tabSize }), [tabSize]);\n useMemo(\n () => highlightEnable !== state.highlightEnable && dispatch({ highlightEnable }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [highlightEnable],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useMemo(() => autoFocus !== state.autoFocus && dispatch({ autoFocus: autoFocus }), [autoFocus]);\n useMemo(\n () => fullscreen !== state.fullscreen && dispatch({ fullscreen: fullscreen }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [fullscreen],\n );\n\n const textareaDomRef = useRef<HTMLDivElement>();\n const active = useRef<'text' | 'preview'>('preview');\n const initScroll = useRef(false);\n\n useMemo(() => {\n textareaDomRef.current = state.textareaWarp;\n if (state.textareaWarp) {\n state.textareaWarp.addEventListener('mouseover', () => {\n active.current = 'text';\n });\n state.textareaWarp.addEventListener('mouseleave', () => {\n active.current = 'preview';\n });\n }\n }, [state.textareaWarp]);\n\n const handleScroll = (e: React.UIEvent<HTMLDivElement>, type: 'text' | 'preview') => {\n if (!enableScrollRef.current) return;\n const textareaDom = textareaDomRef.current;\n const previewDom = previewRef.current ? previewRef.current.mdp.current : undefined;\n if (!initScroll.current) {\n active.current = type;\n initScroll.current = true;\n }\n if (textareaDom && previewDom) {\n const scale =\n (textareaDom.scrollHeight - textareaDom.offsetHeight) / (previewDom.scrollHeight - previewDom.offsetHeight);\n if (e.target === textareaDom && active.current === 'text') {\n previewDom.scrollTop = textareaDom.scrollTop / scale;\n }\n if (e.target === previewDom && active.current === 'preview') {\n textareaDom.scrollTop = previewDom.scrollTop * scale;\n }\n let scrollTop = 0;\n if (active.current === 'text') {\n scrollTop = textareaDom.scrollTop || 0;\n } else if (active.current === 'preview') {\n scrollTop = previewDom.scrollTop || 0;\n }\n dispatch({ scrollTop });\n }\n };\n\n return (\n <EditorContext.Provider value={{ ...state, dispatch }}>\n <div\n ref={container}\n className={cls}\n {...other}\n onClick={() => {\n dispatch({ barPopup: { ...setGroupPopFalse(state.barPopup) } });\n }}\n style={{\n ...other.style,\n height: state.fullscreen ? '100%' : hideToolbar ? Number(state.height) - toolbarHeight : state.height,\n }}\n >\n {!hideToolbar && <Toolbar prefixCls={prefixCls} height={toolbarHeight} />}\n <div\n className={`${prefixCls}-content`}\n style={{\n height: state.fullscreen ? `calc(100% - ${toolbarHeight}px)` : Number(state.height) - toolbarHeight,\n }}\n >\n {/(edit|live)/.test(state.preview || '') && (\n <TextArea\n className={`${prefixCls}-input`}\n prefixCls={prefixCls}\n autoFocus={autoFocus}\n {...textareaProps}\n onChange={(evn) => {\n onChange && onChange(evn.target.value);\n if (textareaProps && textareaProps.onChange) {\n textareaProps.onChange(evn);\n }\n }}\n renderTextarea={renderTextarea}\n onScroll={(e) => handleScroll(e, 'text')}\n />\n )}\n {/(live|preview)/.test(state.preview || '') && (\n <MarkdownPreview\n {...previewOptions}\n onScroll={(e) => handleScroll(e, 'preview')}\n ref={previewRef}\n source={state.markdown || ''}\n className={`${prefixCls}-preview ${previewOptions.className || ''}`}\n />\n )}\n </div>\n {visiableDragbar && !state.fullscreen && (\n <DragBar\n prefixCls={prefixCls}\n height={state.height as number}\n maxHeight={maxHeight!}\n minHeight={minHeight!}\n onChange={(newHeight) => {\n dispatch({ height: newHeight });\n }}\n />\n )}\n </div>\n </EditorContext.Provider>\n );\n};\n\nconst mdEditor = React.forwardRef<ContextStore, MDEditorProps>(InternalMDEditor);\n\ntype MDEditor = typeof mdEditor & {\n Markdown: typeof MarkdownPreview;\n};\n\n(mdEditor as MDEditor).Markdown = MarkdownPreview;\n\nexport default mdEditor as MDEditor;\n"
|
|
101
103
|
]
|
|
102
104
|
}
|
package/esm/commands/title1.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { insertAtLineStart } from '../utils/InsertTextAtPosition';
|
|
2
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
4
|
export var title1 = {
|
|
4
5
|
name: 'title1',
|
|
@@ -16,13 +17,11 @@ export var title1 = {
|
|
|
16
17
|
children: "Title 1"
|
|
17
18
|
}),
|
|
18
19
|
execute: (state, api) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
21
|
+
api.replaceSelection('# ');
|
|
22
|
+
} else {
|
|
23
|
+
insertAtLineStart('# ', state.selection.start, api.textArea);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
api.replaceSelection(modifyText);
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
//# sourceMappingURL=title1.js.map
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
],
|
|
6
6
|
"names": [
|
|
7
7
|
"React",
|
|
8
|
+
"insertAtLineStart",
|
|
8
9
|
"title1",
|
|
9
10
|
"name",
|
|
10
11
|
"keyCommand",
|
|
@@ -17,12 +18,15 @@
|
|
|
17
18
|
"execute",
|
|
18
19
|
"state",
|
|
19
20
|
"api",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"selection",
|
|
22
|
+
"start",
|
|
23
|
+
"test",
|
|
24
|
+
"text",
|
|
25
|
+
"replaceSelection",
|
|
26
|
+
"textArea"
|
|
23
27
|
],
|
|
24
|
-
"mappings": "AAAA,OAAOA,KAAP,MAAkB,OAAlB;;AAGA,OAAO,IAAMC,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,gBAAhB;AAAkCC,IAAAA,KAAK,EAAE;AAAzC,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,CAACC,KAAD,EAAmBC,GAAnB,KAA4C;AACnD,
|
|
28
|
+
"mappings": "AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,iBAAT,QAAkC,+BAAlC;;AAGA,OAAO,IAAMC,MAAgB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,QADwB;AAE9BC,EAAAA,UAAU,EAAE,QAFkB;AAG9BC,EAAAA,SAAS,EAAE,WAHmB;AAI9BC,EAAAA,WAAW,EAAE;AAAE,kBAAc,gBAAhB;AAAkCC,IAAAA,KAAK,EAAE;AAAzC,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,CAACC,KAAD,EAAmBC,GAAnB,KAA4C;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,IAArB;AACD,KAFD,MAEO;AACLjB,MAAAA,iBAAiB,CAAC,IAAD,EAAOW,KAAK,CAACE,SAAN,CAAgBC,KAAvB,EAA8BF,GAAG,CAACM,QAAlC,CAAjB;AACD;AACF;AAZ6B,CAAzB",
|
|
25
29
|
"sourcesContent": [
|
|
26
|
-
"import React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title1: ICommand = {\n name: 'title1',\n keyCommand: 'title1',\n shortcuts: 'ctrlcmd+1',\n buttonProps: { 'aria-label': 'Insert title 1', title: 'Insert title 1' },\n icon: <div style={{ fontSize: 18, textAlign: 'left' }}>Title 1</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n
|
|
30
|
+
"import React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title1: ICommand = {\n name: 'title1',\n keyCommand: 'title1',\n shortcuts: 'ctrlcmd+1',\n buttonProps: { 'aria-label': 'Insert title 1', title: 'Insert title 1' },\n icon: <div style={{ fontSize: 18, textAlign: 'left' }}>Title 1</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"
|
|
27
31
|
]
|
|
28
32
|
}
|
package/esm/commands/title2.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { insertAtLineStart } from '../utils/InsertTextAtPosition';
|
|
2
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
4
|
export var title2 = {
|
|
4
5
|
name: 'title2',
|
|
@@ -16,13 +17,11 @@ export var title2 = {
|
|
|
16
17
|
children: "Title 2"
|
|
17
18
|
}),
|
|
18
19
|
execute: (state, api) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
21
|
+
api.replaceSelection('## ');
|
|
22
|
+
} else {
|
|
23
|
+
insertAtLineStart('## ', state.selection.start, api.textArea);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
api.replaceSelection(modifyText);
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
//# sourceMappingURL=title2.js.map
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
],
|
|
6
6
|
"names": [
|
|
7
7
|
"React",
|
|
8
|
+
"insertAtLineStart",
|
|
8
9
|
"title2",
|
|
9
10
|
"name",
|
|
10
11
|
"keyCommand",
|
|
@@ -17,12 +18,15 @@
|
|
|
17
18
|
"execute",
|
|
18
19
|
"state",
|
|
19
20
|
"api",
|
|
20
|
-
"
|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,KAA0B,CAA1B,IAA+B,MAAMC,IAAN,CAAWJ,KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,KAArB;AACD,KAFD,MAEO;AACLjB,MAAAA,iBAAiB,CAAC,KAAD,EAAQW,KAAK,CAACE,SAAN,CAAgBC,KAAxB,EAA+BF,GAAG,CAACM,QAAnC,CAAjB;AACD;AACF;AAZ6B,CAAzB",
|
|
25
29
|
"sourcesContent": [
|
|
26
|
-
"import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title2: ICommand = {\n name: 'title2',\n keyCommand: 'title2',\n shortcuts: 'ctrlcmd+2',\n buttonProps: { 'aria-label': 'Insert title2', title: 'Insert title 2' },\n icon: <div style={{ fontSize: 16, textAlign: 'left' }}>Title 2</div>,\n execute: (state: TextState, api: TextAreaTextApi) => {\n
|
|
30
|
+
"import * as React from 'react';\nimport { insertAtLineStart } from '../utils/InsertTextAtPosition';\nimport { ICommand, TextState, TextAreaTextApi } from './';\n\nexport const title2: ICommand = {\n name: 'title2',\n keyCommand: 'title2',\n shortcuts: 'ctrlcmd+2',\n buttonProps: { 'aria-label': 'Insert title2', title: 'Insert title 2' },\n icon: <div style={{ fontSize: 16, textAlign: 'left' }}>Title 2</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"
|
|
27
31
|
]
|
|
28
32
|
}
|
package/esm/commands/title3.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { insertAtLineStart } from '../utils/InsertTextAtPosition';
|
|
2
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
4
|
export var title3 = {
|
|
4
5
|
name: 'title3',
|
|
@@ -16,13 +17,11 @@ export var title3 = {
|
|
|
16
17
|
children: "Title 3"
|
|
17
18
|
}),
|
|
18
19
|
execute: (state, api) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
21
|
+
api.replaceSelection('### ');
|
|
22
|
+
} else {
|
|
23
|
+
insertAtLineStart('### ', state.selection.start, api.textArea);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
api.replaceSelection(modifyText);
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
//# sourceMappingURL=title3.js.map
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
],
|
|
6
6
|
"names": [
|
|
7
7
|
"React",
|
|
8
|
+
"insertAtLineStart",
|
|
8
9
|
"title3",
|
|
9
10
|
"name",
|
|
10
11
|
"keyCommand",
|
|
@@ -17,12 +18,15 @@
|
|
|
17
18
|
"execute",
|
|
18
19
|
"state",
|
|
19
20
|
"api",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"selection",
|
|
22
|
+
"start",
|
|
23
|
+
"test",
|
|
24
|
+
"text",
|
|
25
|
+
"replaceSelection",
|
|
26
|
+
"textArea"
|
|
23
27
|
],
|
|
24
|
-
"mappings": "AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAGA,OAAO,IAAMC,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,CAACC,KAAD,EAAmBC,GAAnB,KAA4C;AACnD,
|
|
28
|
+
"mappings": "AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,iBAAT,QAAkC,+BAAlC;;AAGA,OAAO,IAAMC,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,CAACC,KAAD,EAAmBC,GAAnB,KAA4C;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;AACLjB,MAAAA,iBAAiB,CAAC,MAAD,EAASW,KAAK,CAACE,SAAN,CAAgBC,KAAzB,EAAgCF,GAAG,CAACM,QAApC,CAAjB;AACD;AACF;AAZ6B,CAAzB",
|
|
25
29
|
"sourcesContent": [
|
|
26
|
-
"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
|
|
30
|
+
"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"
|
|
27
31
|
]
|
|
28
32
|
}
|
package/esm/commands/title4.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { insertAtLineStart } from '../utils/InsertTextAtPosition';
|
|
2
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
4
|
export var title4 = {
|
|
4
5
|
name: 'title4',
|
|
@@ -16,13 +17,11 @@ export var title4 = {
|
|
|
16
17
|
children: "Title 4"
|
|
17
18
|
}),
|
|
18
19
|
execute: (state, api) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
21
|
+
api.replaceSelection('#### ');
|
|
22
|
+
} else {
|
|
23
|
+
insertAtLineStart('#### ', state.selection.start, api.textArea);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
api.replaceSelection(modifyText);
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
//# sourceMappingURL=title4.js.map
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
],
|
|
6
6
|
"names": [
|
|
7
7
|
"React",
|
|
8
|
+
"insertAtLineStart",
|
|
8
9
|
"title4",
|
|
9
10
|
"name",
|
|
10
11
|
"keyCommand",
|
|
@@ -17,12 +18,15 @@
|
|
|
17
18
|
"execute",
|
|
18
19
|
"state",
|
|
19
20
|
"api",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"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MC,IAAN,CAAWJ,KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,OAArB;AACD,KAFD,MAEO;AACLjB,MAAAA,iBAAiB,CAAC,OAAD,EAAUW,KAAK,CAACE,SAAN,CAAgBC,KAA1B,EAAiCF,GAAG,CAACM,QAArC,CAAjB;AACD;AACF;AAZ6B,CAAzB",
|
|
25
29
|
"sourcesContent": [
|
|
26
|
-
"import * as React from 'react';\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
|
|
30
|
+
"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"
|
|
27
31
|
]
|
|
28
32
|
}
|
package/esm/commands/title5.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { insertAtLineStart } from '../utils/InsertTextAtPosition';
|
|
2
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
4
|
export var title5 = {
|
|
4
5
|
name: 'title5',
|
|
@@ -16,13 +17,11 @@ export var title5 = {
|
|
|
16
17
|
children: "Title 5"
|
|
17
18
|
}),
|
|
18
19
|
execute: (state, api) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
21
|
+
api.replaceSelection('##### ');
|
|
22
|
+
} else {
|
|
23
|
+
insertAtLineStart('##### ', state.selection.start, api.textArea);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
api.replaceSelection(modifyText);
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
//# sourceMappingURL=title5.js.map
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
],
|
|
6
6
|
"names": [
|
|
7
7
|
"React",
|
|
8
|
+
"insertAtLineStart",
|
|
8
9
|
"title5",
|
|
9
10
|
"name",
|
|
10
11
|
"keyCommand",
|
|
@@ -17,12 +18,15 @@
|
|
|
17
18
|
"execute",
|
|
18
19
|
"state",
|
|
19
20
|
"api",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"selection",
|
|
22
|
+
"start",
|
|
23
|
+
"test",
|
|
24
|
+
"text",
|
|
25
|
+
"replaceSelection",
|
|
26
|
+
"textArea"
|
|
23
27
|
],
|
|
24
|
-
"mappings": "AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAGA,OAAO,IAAMC,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,CAACC,KAAD,EAAmBC,GAAnB,KAA4C;AACnD,
|
|
28
|
+
"mappings": "AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,iBAAT,QAAkC,+BAAlC;;AAGA,OAAO,IAAMC,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,CAACC,KAAD,EAAmBC,GAAnB,KAA4C;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;AACLjB,MAAAA,iBAAiB,CAAC,QAAD,EAAWW,KAAK,CAACE,SAAN,CAAgBC,KAA3B,EAAkCF,GAAG,CAACM,QAAtC,CAAjB;AACD;AACF;AAZ6B,CAAzB",
|
|
25
29
|
"sourcesContent": [
|
|
26
|
-
"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
|
|
30
|
+
"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"
|
|
27
31
|
]
|
|
28
32
|
}
|
package/esm/commands/title6.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { insertAtLineStart } from '../utils/InsertTextAtPosition';
|
|
2
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
4
|
export var title6 = {
|
|
4
5
|
name: 'title6',
|
|
@@ -16,13 +17,11 @@ export var title6 = {
|
|
|
16
17
|
children: "Title 6"
|
|
17
18
|
}),
|
|
18
19
|
execute: (state, api) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (state.selection.start === 0 || /\n$/.test(state.text)) {
|
|
21
|
+
api.replaceSelection('###### ');
|
|
22
|
+
} else {
|
|
23
|
+
insertAtLineStart('###### ', state.selection.start, api.textArea);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
api.replaceSelection(modifyText);
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
//# sourceMappingURL=title6.js.map
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
],
|
|
6
6
|
"names": [
|
|
7
7
|
"React",
|
|
8
|
+
"insertAtLineStart",
|
|
8
9
|
"title6",
|
|
9
10
|
"name",
|
|
10
11
|
"keyCommand",
|
|
@@ -17,12 +18,15 @@
|
|
|
17
18
|
"execute",
|
|
18
19
|
"state",
|
|
19
20
|
"api",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"selection",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KAAK,CAACK,IAAjB,CAAnC,EAA2D;AACzDJ,MAAAA,GAAG,CAACK,gBAAJ,CAAqB,SAArB;AACD,KAFD,MAEO;AACLjB,MAAAA,iBAAiB,CAAC,SAAD,EAAYW,KAAK,CAACE,SAAN,CAAgBC,KAA5B,EAAmCF,GAAG,CAACM,QAAvC,CAAjB;AACD;AACF;AAZ6B,CAAzB",
|
|
25
29
|
"sourcesContent": [
|
|
26
|
-
"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
|
|
30
|
+
"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"
|
|
27
31
|
]
|
|
28
32
|
}
|
|
@@ -11,7 +11,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
11
11
|
export default function Textarea(props) {
|
|
12
12
|
var {
|
|
13
13
|
prefixCls,
|
|
14
|
-
onChange:
|
|
14
|
+
onChange: _onChange
|
|
15
15
|
} = props,
|
|
16
16
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
17
17
|
|
|
@@ -23,7 +23,6 @@ export default function Textarea(props) {
|
|
|
23
23
|
highlightEnable,
|
|
24
24
|
extraCommands,
|
|
25
25
|
tabSize,
|
|
26
|
-
onChange: _onChange,
|
|
27
26
|
dispatch
|
|
28
27
|
} = useContext(EditorContext);
|
|
29
28
|
var textRef = React.useRef(null);
|
|
@@ -81,8 +80,7 @@ export default function Textarea(props) {
|
|
|
81
80
|
dispatch && dispatch({
|
|
82
81
|
markdown: e.target.value
|
|
83
82
|
});
|
|
84
|
-
_onChange && _onChange(e
|
|
85
|
-
onChangeFromProps && onChangeFromProps(e);
|
|
83
|
+
_onChange && _onChange(e);
|
|
86
84
|
}
|
|
87
85
|
}));
|
|
88
86
|
}
|