@uiw/react-md-editor 4.1.4 → 4.1.6

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.
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "autoFocusEnd", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
3
+ var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "id", "name", "required", "disabled", "readOnly", "placeholder", "aria-label", "aria-labelledby", "aria-describedby", "aria-invalid", "aria-required", "aria-errormessage", "maxHeight", "minHeight", "autoFocus", "autoFocusEnd", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
4
4
  import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
5
5
  import { ToolbarVisibility } from "./components/Toolbar/index.js";
6
6
  import DragBar from "./components/DragBar/index.js";
@@ -50,6 +50,18 @@ export function createMDEditor(options) {
50
50
  _ref$previewOptions = _ref.previewOptions,
51
51
  previewOptions = _ref$previewOptions === void 0 ? {} : _ref$previewOptions,
52
52
  textareaProps = _ref.textareaProps,
53
+ id = _ref.id,
54
+ name = _ref.name,
55
+ required = _ref.required,
56
+ disabled = _ref.disabled,
57
+ readOnly = _ref.readOnly,
58
+ placeholder = _ref.placeholder,
59
+ ariaLabel = _ref['aria-label'],
60
+ ariaLabelledBy = _ref['aria-labelledby'],
61
+ ariaDescribedBy = _ref['aria-describedby'],
62
+ ariaInvalid = _ref['aria-invalid'],
63
+ ariaRequired = _ref['aria-required'],
64
+ ariaErrorMessage = _ref['aria-errormessage'],
53
65
  _ref$maxHeight = _ref.maxHeight,
54
66
  maxHeight = _ref$maxHeight === void 0 ? 1200 : _ref$maxHeight,
55
67
  _ref$minHeight = _ref.minHeight,
@@ -256,7 +268,19 @@ export function createMDEditor(options) {
256
268
  children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/_jsx(TextAreaComponent, _extends({
257
269
  className: prefixCls + "-input",
258
270
  prefixCls: prefixCls,
259
- autoFocus: autoFocus
271
+ autoFocus: autoFocus,
272
+ id: id,
273
+ name: name,
274
+ required: required,
275
+ disabled: disabled,
276
+ readOnly: readOnly,
277
+ placeholder: placeholder,
278
+ "aria-label": ariaLabel,
279
+ "aria-labelledby": ariaLabelledBy,
280
+ "aria-describedby": ariaDescribedBy,
281
+ "aria-invalid": ariaInvalid,
282
+ "aria-required": ariaRequired,
283
+ "aria-errormessage": ariaErrorMessage
260
284
  }, textareaProps, {
261
285
  onChange: changeHandle,
262
286
  renderTextarea: (components == null ? void 0 : components.textarea) || renderTextarea,
package/esm/Types.d.ts CHANGED
@@ -18,6 +18,12 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
18
18
  * The Markdown value.
19
19
  */
20
20
  value?: string;
21
+ /** Native textarea form attributes. */
22
+ name?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['name'];
23
+ required?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['required'];
24
+ disabled?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['disabled'];
25
+ readOnly?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['readOnly'];
26
+ placeholder?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['placeholder'];
21
27
  /**
22
28
  * Event handler for the `onChange` event.
23
29
  */
@@ -1,6 +1,7 @@
1
1
  import { type ICommand } from './';
2
2
  import { divider } from './divider';
3
3
  import { group } from './group';
4
+ import { makeList } from './list';
4
5
  declare let bold: ICommand;
5
6
  declare let code: ICommand;
6
7
  declare let codeBlock: ICommand;
@@ -30,4 +31,4 @@ declare let table: ICommand;
30
31
  declare let help: ICommand;
31
32
  export declare const getCommands: () => ICommand[];
32
33
  export declare const getExtraCommands: () => ICommand[];
33
- export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, };
34
+ export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, makeList, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, };
@@ -9,7 +9,7 @@ import { hr as hrInit } from "./hr.js";
9
9
  import { image as imageInit } from "./image.js";
10
10
  import { italic as italicInit } from "./italic.js";
11
11
  import { link as linkInit } from "./link.js";
12
- import { checkedListCommand as checkedListCommandInit, orderedListCommand as orderedListCommandInit, unorderedListCommand as unorderedListCommandInit } from "./list.js";
12
+ import { checkedListCommand as checkedListCommandInit, makeList, orderedListCommand as orderedListCommandInit, unorderedListCommand as unorderedListCommandInit } from "./list.js";
13
13
  import { codeEdit as codeEditInit, codeLive as codeLiveInit, codePreview as codePreviewInit } from "./preview.js";
14
14
  import { quote as quoteInit } from "./quote.js";
15
15
  import { strikethrough as strikethroughInit } from "./strikeThrough.js";
@@ -194,4 +194,4 @@ export var getCommands = () => [bold, italic, strikethrough, hr, group([title1,
194
194
  }
195
195
  }), divider, link, quote, code, codeBlock, comment, image, table, divider, unorderedListCommand, orderedListCommand, checkedListCommand, divider, help];
196
196
  export var getExtraCommands = () => [codeEdit, codeLive, codePreview, divider, fullscreen];
197
- export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, table, issue, help, codeEdit, codeLive, codePreview, fullscreen };
197
+ export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, makeList, table, issue, help, codeEdit, codeLive, codePreview, fullscreen };
@@ -10,7 +10,7 @@ import { hr } from './hr';
10
10
  import { image } from './image';
11
11
  import { italic } from './italic';
12
12
  import { link } from './link';
13
- import { checkedListCommand, orderedListCommand, unorderedListCommand } from './list';
13
+ import { checkedListCommand, makeList, orderedListCommand, unorderedListCommand } from './list';
14
14
  import { codeEdit, codeLive, codePreview } from './preview';
15
15
  import { quote } from './quote';
16
16
  import { strikethrough } from './strikeThrough';
@@ -93,4 +93,4 @@ declare class TextAreaCommandOrchestrator implements CommandOrchestrator {
93
93
  getState(): false | TextState;
94
94
  executeCommand(command: ICommand<string>, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState, shortcuts?: string[]): void;
95
95
  }
96
- export { title, title1, title2, title3, title4, title5, title6, heading, heading1, heading2, heading3, heading4, heading5, heading6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi, };
96
+ export { title, title1, title2, title3, title4, title5, title6, heading, heading1, heading2, heading3, heading4, heading5, heading6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, makeList, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi, };
@@ -10,7 +10,7 @@ import { hr } from "./hr.js";
10
10
  import { image } from "./image.js";
11
11
  import { italic } from "./italic.js";
12
12
  import { link } from "./link.js";
13
- import { checkedListCommand, orderedListCommand, unorderedListCommand } from "./list.js";
13
+ import { checkedListCommand, makeList, orderedListCommand, unorderedListCommand } from "./list.js";
14
14
  import { codeEdit, codeLive, codePreview } from "./preview.js";
15
15
  import { quote } from "./quote.js";
16
16
  import { strikethrough } from "./strikeThrough.js";
@@ -88,6 +88,6 @@ class TextAreaCommandOrchestrator {
88
88
  }, getStateFromTextArea(this.textArea)), this.textApi, dispatch, state, shortcuts);
89
89
  }
90
90
  }
91
- export { title, title1, title2, title3, title4, title5, title6, heading, heading1, heading2, heading3, heading4, heading5, heading6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, table, issue, help, codeEdit, codeLive, codePreview, fullscreen,
91
+ export { title, title1, title2, title3, title4, title5, title6, heading, heading1, heading2, heading3, heading4, heading5, heading6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, makeList, table, issue, help, codeEdit, codeLive, codePreview, fullscreen,
92
92
  // Tool method.
93
93
  getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi };
@@ -1,6 +1,6 @@
1
1
  import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
2
2
  import { AlterLineFunction } from '../utils/markdownUtils';
3
- export declare const makeList: (state: ExecuteState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction) => void;
3
+ export declare const makeList: (state: ExecuteState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction, selectionStrategy?: "word" | "line") => void;
4
4
  export declare const unorderedListCommand: ICommand;
5
5
  export declare const orderedListCommand: ICommand;
6
6
  export declare const checkedListCommand: ICommand;
@@ -1,8 +1,14 @@
1
1
  import React from 'react';
2
- import { selectWord, getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter, insertBeforeEachLine } from "../utils/markdownUtils.js";
2
+ import { selectWord, selectLine, getBreaksNeededForEmptyLineBefore, getBreaksNeededForEmptyLineAfter, insertBeforeEachLine } from "../utils/markdownUtils.js";
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
- export var makeList = (state, api, insertBefore) => {
5
- var newSelectionRange = selectWord({
4
+ export var makeList = function makeList(state, api, insertBefore, selectionStrategy) {
5
+ if (selectionStrategy === void 0) {
6
+ selectionStrategy = 'word';
7
+ }
8
+ var newSelectionRange = selectionStrategy === 'line' ? selectLine({
9
+ text: state.text,
10
+ selection: state.selection
11
+ }) : selectWord({
6
12
  text: state.text,
7
13
  selection: state.selection,
8
14
  prefix: state.command.prefix
@@ -83,7 +83,6 @@ export default function Textarea(props) {
83
83
  }, []);
84
84
  return /*#__PURE__*/_jsx("textarea", _extends({
85
85
  autoComplete: "off",
86
- autoCorrect: "off",
87
86
  autoCapitalize: "off",
88
87
  spellCheck: false
89
88
  }, other, {
@@ -56,6 +56,10 @@ export function createTextArea(options) {
56
56
  WebkitTextFillColor: 'initial',
57
57
  overflow: 'auto'
58
58
  };
59
+ var inputProps = _extends({}, otherProps);
60
+ if (!inputProps['aria-label'] && !inputProps['aria-labelledby'] && !inputProps.id && !inputProps.title) {
61
+ inputProps['aria-label'] = 'Markdown editor';
62
+ }
59
63
  return /*#__PURE__*/_jsx("div", {
60
64
  ref: warp,
61
65
  className: prefixCls + "-area " + (className || ''),
@@ -65,10 +69,9 @@ export function createTextArea(options) {
65
69
  style: useMinHeight ? {
66
70
  minHeight
67
71
  } : undefined,
68
- children: renderTextarea ? (/*#__PURE__*/React.cloneElement(renderTextarea(_extends({}, otherProps, {
72
+ children: renderTextarea ? (/*#__PURE__*/React.cloneElement(renderTextarea(_extends({}, inputProps, {
69
73
  value: markdown,
70
74
  autoComplete: 'off',
71
- autoCorrect: 'off',
72
75
  spellCheck: 'false',
73
76
  autoCapitalize: 'off',
74
77
  className: prefixCls + "-text-input",
@@ -92,7 +95,7 @@ export function createTextArea(options) {
92
95
  prefixCls: prefixCls
93
96
  }), /*#__PURE__*/_jsx(Textarea, _extends({
94
97
  prefixCls: prefixCls
95
- }, otherProps, {
98
+ }, inputProps, {
96
99
  style: textStyle
97
100
  }))]
98
101
  })
@@ -15,7 +15,7 @@ var _DragBar = _interopRequireDefault(require("./components/DragBar/"));
15
15
  var _commands = require("./commands/");
16
16
  var _Context = require("./Context");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
- var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "autoFocusEnd", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
18
+ var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "id", "name", "required", "disabled", "readOnly", "placeholder", "aria-label", "aria-labelledby", "aria-describedby", "aria-invalid", "aria-required", "aria-errormessage", "maxHeight", "minHeight", "autoFocus", "autoFocusEnd", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
19
19
  function setGroupPopFalse() {
20
20
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
21
21
  Object.keys(data).forEach(function (keyname) {
@@ -57,6 +57,18 @@ function createMDEditor(options) {
57
57
  _ref$previewOptions = _ref.previewOptions,
58
58
  previewOptions = _ref$previewOptions === void 0 ? {} : _ref$previewOptions,
59
59
  textareaProps = _ref.textareaProps,
60
+ id = _ref.id,
61
+ name = _ref.name,
62
+ required = _ref.required,
63
+ disabled = _ref.disabled,
64
+ readOnly = _ref.readOnly,
65
+ placeholder = _ref.placeholder,
66
+ ariaLabel = _ref['aria-label'],
67
+ ariaLabelledBy = _ref['aria-labelledby'],
68
+ ariaDescribedBy = _ref['aria-describedby'],
69
+ ariaInvalid = _ref['aria-invalid'],
70
+ ariaRequired = _ref['aria-required'],
71
+ ariaErrorMessage = _ref['aria-errormessage'],
60
72
  _ref$maxHeight = _ref.maxHeight,
61
73
  maxHeight = _ref$maxHeight === void 0 ? 1200 : _ref$maxHeight,
62
74
  _ref$minHeight = _ref.minHeight,
@@ -302,7 +314,19 @@ function createMDEditor(options) {
302
314
  children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/(0, _jsxRuntime.jsx)(TextAreaComponent, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
303
315
  className: "".concat(prefixCls, "-input"),
304
316
  prefixCls: prefixCls,
305
- autoFocus: autoFocus
317
+ autoFocus: autoFocus,
318
+ id: id,
319
+ name: name,
320
+ required: required,
321
+ disabled: disabled,
322
+ readOnly: readOnly,
323
+ placeholder: placeholder,
324
+ "aria-label": ariaLabel,
325
+ "aria-labelledby": ariaLabelledBy,
326
+ "aria-describedby": ariaDescribedBy,
327
+ "aria-invalid": ariaInvalid,
328
+ "aria-required": ariaRequired,
329
+ "aria-errormessage": ariaErrorMessage
306
330
  }, textareaProps), {}, {
307
331
  onChange: changeHandle,
308
332
  renderTextarea: (components === null || components === void 0 ? void 0 : components.textarea) || renderTextarea,
package/lib/Types.d.ts CHANGED
@@ -18,6 +18,12 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
18
18
  * The Markdown value.
19
19
  */
20
20
  value?: string;
21
+ /** Native textarea form attributes. */
22
+ name?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['name'];
23
+ required?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['required'];
24
+ disabled?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['disabled'];
25
+ readOnly?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['readOnly'];
26
+ placeholder?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['placeholder'];
21
27
  /**
22
28
  * Event handler for the `onChange` event.
23
29
  */
@@ -1,6 +1,7 @@
1
1
  import { type ICommand } from './';
2
2
  import { divider } from './divider';
3
3
  import { group } from './group';
4
+ import { makeList } from './list';
4
5
  declare let bold: ICommand;
5
6
  declare let code: ICommand;
6
7
  declare let codeBlock: ICommand;
@@ -30,4 +31,4 @@ declare let table: ICommand;
30
31
  declare let help: ICommand;
31
32
  export declare const getCommands: () => ICommand[];
32
33
  export declare const getExtraCommands: () => ICommand[];
33
- export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, };
34
+ export { title, title1, title2, title3, title4, title5, title6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, makeList, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, };
@@ -18,7 +18,14 @@ Object.defineProperty(exports, "group", {
18
18
  return _group.group;
19
19
  }
20
20
  });
21
- exports.unorderedListCommand = exports.title6 = exports.title5 = exports.title4 = exports.title3 = exports.title2 = exports.title1 = exports.title = exports.table = exports.strikethrough = exports.quote = exports.orderedListCommand = exports.link = exports.italic = exports.issue = exports.image = exports.hr = exports.help = void 0;
21
+ exports.link = exports.italic = exports.issue = exports.image = exports.hr = exports.help = void 0;
22
+ Object.defineProperty(exports, "makeList", {
23
+ enumerable: true,
24
+ get: function get() {
25
+ return _list.makeList;
26
+ }
27
+ });
28
+ exports.unorderedListCommand = exports.title6 = exports.title5 = exports.title4 = exports.title3 = exports.title2 = exports.title1 = exports.title = exports.table = exports.strikethrough = exports.quote = exports.orderedListCommand = void 0;
22
29
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
23
30
  var _divider = require("./divider");
24
31
  var _group = require("./group");
@@ -10,7 +10,7 @@ import { hr } from './hr';
10
10
  import { image } from './image';
11
11
  import { italic } from './italic';
12
12
  import { link } from './link';
13
- import { checkedListCommand, orderedListCommand, unorderedListCommand } from './list';
13
+ import { checkedListCommand, makeList, orderedListCommand, unorderedListCommand } from './list';
14
14
  import { codeEdit, codeLive, codePreview } from './preview';
15
15
  import { quote } from './quote';
16
16
  import { strikethrough } from './strikeThrough';
@@ -93,4 +93,4 @@ declare class TextAreaCommandOrchestrator implements CommandOrchestrator {
93
93
  getState(): false | TextState;
94
94
  executeCommand(command: ICommand<string>, dispatch?: React.Dispatch<ContextStore>, state?: ExecuteCommandState, shortcuts?: string[]): void;
95
95
  }
96
- export { title, title1, title2, title3, title4, title5, title6, heading, heading1, heading2, heading3, heading4, heading5, heading6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi, };
96
+ export { title, title1, title2, title3, title4, title5, title6, heading, heading1, heading2, heading3, heading4, heading5, heading6, bold, codeBlock, comment, italic, strikethrough, hr, group, divider, link, quote, code, image, unorderedListCommand, orderedListCommand, checkedListCommand, makeList, table, issue, help, codeEdit, codeLive, codePreview, fullscreen, getCommands, getExtraCommands, getStateFromTextArea, TextAreaCommandOrchestrator, TextAreaTextApi, };
@@ -151,6 +151,12 @@ Object.defineProperty(exports, "link", {
151
151
  return _link.link;
152
152
  }
153
153
  });
154
+ Object.defineProperty(exports, "makeList", {
155
+ enumerable: true,
156
+ get: function get() {
157
+ return _list.makeList;
158
+ }
159
+ });
154
160
  Object.defineProperty(exports, "orderedListCommand", {
155
161
  enumerable: true,
156
162
  get: function get() {
@@ -1,6 +1,6 @@
1
1
  import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
2
2
  import { AlterLineFunction } from '../utils/markdownUtils';
3
- export declare const makeList: (state: ExecuteState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction) => void;
3
+ export declare const makeList: (state: ExecuteState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction, selectionStrategy?: "word" | "line") => void;
4
4
  export declare const unorderedListCommand: ICommand;
5
5
  export declare const orderedListCommand: ICommand;
6
6
  export declare const checkedListCommand: ICommand;
@@ -9,7 +9,11 @@ var _react = _interopRequireDefault(require("react"));
9
9
  var _markdownUtils = require("../utils/markdownUtils");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
11
  var makeList = exports.makeList = function makeList(state, api, insertBefore) {
12
- var newSelectionRange = (0, _markdownUtils.selectWord)({
12
+ var selectionStrategy = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'word';
13
+ var newSelectionRange = selectionStrategy === 'line' ? (0, _markdownUtils.selectLine)({
14
+ text: state.text,
15
+ selection: state.selection
16
+ }) : (0, _markdownUtils.selectWord)({
13
17
  text: state.text,
14
18
  selection: state.selection,
15
19
  prefix: state.command.prefix
@@ -91,7 +91,6 @@ function Textarea(props) {
91
91
  }, []);
92
92
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("textarea", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
93
93
  autoComplete: "off",
94
- autoCorrect: "off",
95
94
  autoCapitalize: "off",
96
95
  spellCheck: false
97
96
  }, other), {}, {
@@ -63,6 +63,10 @@ function createTextArea(options) {
63
63
  WebkitTextFillColor: 'initial',
64
64
  overflow: 'auto'
65
65
  };
66
+ var inputProps = (0, _objectSpread2["default"])({}, otherProps);
67
+ if (!inputProps['aria-label'] && !inputProps['aria-labelledby'] && !inputProps.id && !inputProps.title) {
68
+ inputProps['aria-label'] = 'Markdown editor';
69
+ }
66
70
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
67
71
  ref: warp,
68
72
  className: "".concat(prefixCls, "-area ").concat(className || ''),
@@ -72,10 +76,9 @@ function createTextArea(options) {
72
76
  style: useMinHeight ? {
73
77
  minHeight: minHeight
74
78
  } : undefined,
75
- children: renderTextarea ? (/*#__PURE__*/_react["default"].cloneElement(renderTextarea((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, otherProps), {}, {
79
+ children: renderTextarea ? (/*#__PURE__*/_react["default"].cloneElement(renderTextarea((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, inputProps), {}, {
76
80
  value: markdown,
77
81
  autoComplete: 'off',
78
- autoCorrect: 'off',
79
82
  spellCheck: 'false',
80
83
  autoCapitalize: 'off',
81
84
  className: "".concat(prefixCls, "-text-input"),
@@ -99,7 +102,7 @@ function createTextArea(options) {
99
102
  prefixCls: prefixCls
100
103
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Textarea["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
101
104
  prefixCls: prefixCls
102
- }, otherProps), {}, {
105
+ }, inputProps), {}, {
103
106
  style: textStyle
104
107
  }))]
105
108
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "4.1.4",
3
+ "version": "4.1.6",
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
  "funding": "https://jaywcjlove.github.io/#/sponsor",
@@ -44,6 +44,18 @@ export function createMDEditor<
44
44
  overflow = true,
45
45
  previewOptions = {},
46
46
  textareaProps,
47
+ id,
48
+ name,
49
+ required,
50
+ disabled,
51
+ readOnly,
52
+ placeholder,
53
+ 'aria-label': ariaLabel,
54
+ 'aria-labelledby': ariaLabelledBy,
55
+ 'aria-describedby': ariaDescribedBy,
56
+ 'aria-invalid': ariaInvalid,
57
+ 'aria-required': ariaRequired,
58
+ 'aria-errormessage': ariaErrorMessage,
47
59
  maxHeight = 1200,
48
60
  minHeight = 100,
49
61
  autoFocus,
@@ -244,6 +256,18 @@ export function createMDEditor<
244
256
  className={`${prefixCls}-input`}
245
257
  prefixCls={prefixCls}
246
258
  autoFocus={autoFocus}
259
+ id={id}
260
+ name={name}
261
+ required={required}
262
+ disabled={disabled}
263
+ readOnly={readOnly}
264
+ placeholder={placeholder}
265
+ aria-label={ariaLabel}
266
+ aria-labelledby={ariaLabelledBy}
267
+ aria-describedby={ariaDescribedBy}
268
+ aria-invalid={ariaInvalid}
269
+ aria-required={ariaRequired}
270
+ aria-errormessage={ariaErrorMessage}
247
271
  {...textareaProps}
248
272
  onChange={changeHandle}
249
273
  renderTextarea={components?.textarea || renderTextarea}
package/src/Types.ts CHANGED
@@ -21,6 +21,12 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
21
21
  * The Markdown value.
22
22
  */
23
23
  value?: string;
24
+ /** Native textarea form attributes. */
25
+ name?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['name'];
26
+ required?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['required'];
27
+ disabled?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['disabled'];
28
+ readOnly?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['readOnly'];
29
+ placeholder?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['placeholder'];
24
30
  /**
25
31
  * Event handler for the `onChange` event.
26
32
  */
@@ -12,6 +12,7 @@ import { italic as italicInit } from './italic';
12
12
  import { link as linkInit } from './link';
13
13
  import {
14
14
  checkedListCommand as checkedListCommandInit,
15
+ makeList,
15
16
  orderedListCommand as orderedListCommandInit,
16
17
  unorderedListCommand as unorderedListCommandInit,
17
18
  } from './list';
@@ -177,6 +178,7 @@ export {
177
178
  unorderedListCommand,
178
179
  orderedListCommand,
179
180
  checkedListCommand,
181
+ makeList,
180
182
  table,
181
183
  issue,
182
184
  help,
@@ -11,7 +11,7 @@ import { hr } from './hr';
11
11
  import { image } from './image';
12
12
  import { italic } from './italic';
13
13
  import { link } from './link';
14
- import { checkedListCommand, orderedListCommand, unorderedListCommand } from './list';
14
+ import { checkedListCommand, makeList, orderedListCommand, unorderedListCommand } from './list';
15
15
  import { codeEdit, codeLive, codePreview } from './preview';
16
16
  import { quote } from './quote';
17
17
  import { strikethrough } from './strikeThrough';
@@ -210,6 +210,7 @@ export {
210
210
  unorderedListCommand,
211
211
  orderedListCommand,
212
212
  checkedListCommand,
213
+ makeList,
213
214
  table,
214
215
  issue,
215
216
  help,
@@ -2,14 +2,23 @@ import React from 'react';
2
2
  import { type ICommand, type ExecuteState, TextAreaTextApi } from './';
3
3
  import {
4
4
  selectWord,
5
+ selectLine,
5
6
  getBreaksNeededForEmptyLineBefore,
6
7
  getBreaksNeededForEmptyLineAfter,
7
8
  insertBeforeEachLine,
8
9
  AlterLineFunction,
9
10
  } from '../utils/markdownUtils';
10
11
 
11
- export const makeList = (state: ExecuteState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction) => {
12
- const newSelectionRange = selectWord({ text: state.text, selection: state.selection, prefix: state.command.prefix! });
12
+ export const makeList = (
13
+ state: ExecuteState,
14
+ api: TextAreaTextApi,
15
+ insertBefore: string | AlterLineFunction,
16
+ selectionStrategy: 'word' | 'line' = 'word',
17
+ ) => {
18
+ const newSelectionRange =
19
+ selectionStrategy === 'line'
20
+ ? selectLine({ text: state.text, selection: state.selection })
21
+ : selectWord({ text: state.text, selection: state.selection, prefix: state.command.prefix! });
13
22
  const state1 = api.setSelectionRange(newSelectionRange);
14
23
 
15
24
  const breaksBeforeCount = getBreaksNeededForEmptyLineBefore(state1.text, state1.selection.start);
@@ -77,7 +77,6 @@ export default function Textarea(props: TextAreaProps) {
77
77
  return (
78
78
  <textarea
79
79
  autoComplete="off"
80
- autoCorrect="off"
81
80
  autoCapitalize="off"
82
81
  spellCheck={false}
83
82
  {...other}
@@ -25,8 +25,7 @@ export type RenderTextareaHandle = {
25
25
  };
26
26
 
27
27
  export interface ITextAreaProps
28
- extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>,
29
- IProps {
28
+ extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onScroll'>, IProps {
30
29
  value?: string;
31
30
  onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
32
31
  renderTextarea?: (
@@ -76,6 +75,10 @@ export function createTextArea(options?: { Markdown?: MarkdownComponent; useMinH
76
75
 
77
76
  const textStyle: CSS.Properties =
78
77
  MarkdownComponent && highlightEnable ? {} : { WebkitTextFillColor: 'initial', overflow: 'auto' };
78
+ const inputProps = { ...otherProps };
79
+ if (!inputProps['aria-label'] && !inputProps['aria-labelledby'] && !inputProps.id && !inputProps.title) {
80
+ inputProps['aria-label'] = 'Markdown editor';
81
+ }
79
82
 
80
83
  return (
81
84
  <div ref={warp} className={`${prefixCls}-area ${className || ''}`} onScroll={onScroll}>
@@ -84,10 +87,9 @@ export function createTextArea(options?: { Markdown?: MarkdownComponent; useMinH
84
87
  React.cloneElement(
85
88
  renderTextarea(
86
89
  {
87
- ...otherProps,
90
+ ...inputProps,
88
91
  value: markdown,
89
92
  autoComplete: 'off',
90
- autoCorrect: 'off',
91
93
  spellCheck: 'false',
92
94
  autoCapitalize: 'off',
93
95
  className: `${prefixCls}-text-input`,
@@ -110,7 +112,7 @@ export function createTextArea(options?: { Markdown?: MarkdownComponent; useMinH
110
112
  ) : (
111
113
  <Fragment>
112
114
  {MarkdownComponent && highlightEnable && <MarkdownComponent prefixCls={prefixCls} />}
113
- <Textarea prefixCls={prefixCls} {...otherProps} style={textStyle} />
115
+ <Textarea prefixCls={prefixCls} {...inputProps} style={textStyle} />
114
116
  </Fragment>
115
117
  )}
116
118
  </div>