@lobehub/editor 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/plugins/common/plugin/index.js +13 -6
- package/es/plugins/markdown/index.d.ts +1 -0
- package/es/plugins/markdown/index.js +2 -1
- package/es/plugins/markdown/utils/index.d.ts +6 -0
- package/es/plugins/markdown/utils/index.js +13 -0
- package/es/react/SendButton/SendButton.js +34 -17
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ import { createEmptyHistoryState, registerHistory } from '@lexical/history';
|
|
|
26
26
|
import { $createHeadingNode, $createQuoteNode, $isHeadingNode, $isQuoteNode, HeadingNode, QuoteNode, registerRichText } from '@lexical/rich-text';
|
|
27
27
|
import { $createLineBreakNode, $createParagraphNode, $isTextNode } from 'lexical';
|
|
28
28
|
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
29
|
-
import { IMarkdownShortCutService } from "../../markdown";
|
|
29
|
+
import { IMarkdownShortCutService, isPunctuationChar } from "../../markdown";
|
|
30
30
|
import { registerCommands } from "../command";
|
|
31
31
|
import JSONDataSource from "../data-source/json-data-source";
|
|
32
32
|
import TextDataSource from "../data-source/text-data-source";
|
|
@@ -190,9 +190,6 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
190
190
|
var isUnderline = node.hasFormat('underline');
|
|
191
191
|
var isStrikethrough = node.hasFormat('strikethrough');
|
|
192
192
|
var isCode = node.hasFormat('code');
|
|
193
|
-
if (isCode || isBold || isStrikethrough || isItalic || isUnderline) {
|
|
194
|
-
ctx.appendLine(' ');
|
|
195
|
-
}
|
|
196
193
|
if (isCode) {
|
|
197
194
|
ctx.appendLine('`');
|
|
198
195
|
}
|
|
@@ -208,7 +205,15 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
208
205
|
if (isUnderline) {
|
|
209
206
|
ctx.appendLine('<u>');
|
|
210
207
|
}
|
|
211
|
-
|
|
208
|
+
var textContent = node.getTextContent();
|
|
209
|
+
var res = textContent.match(/\s+$/);
|
|
210
|
+
var tailSpace = '';
|
|
211
|
+
if (res) {
|
|
212
|
+
tailSpace = res[0];
|
|
213
|
+
}
|
|
214
|
+
var append = textContent.trimEnd();
|
|
215
|
+
var lastChar = append.at(-1);
|
|
216
|
+
ctx.appendLine(append);
|
|
212
217
|
if (isUnderline) {
|
|
213
218
|
ctx.appendLine('</u>');
|
|
214
219
|
}
|
|
@@ -224,7 +229,9 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
224
229
|
if (isCode) {
|
|
225
230
|
ctx.appendLine('`');
|
|
226
231
|
}
|
|
227
|
-
if (
|
|
232
|
+
if (tailSpace) {
|
|
233
|
+
ctx.appendLine(tailSpace);
|
|
234
|
+
} else if (lastChar && isPunctuationChar(lastChar)) {
|
|
228
235
|
ctx.appendLine(' ');
|
|
229
236
|
}
|
|
230
237
|
});
|
|
@@ -10,3 +10,9 @@ export declare function isEqualSubString(stringA: string, aStart: number, string
|
|
|
10
10
|
export declare const PUNCTUATION_OR_SPACE: RegExp;
|
|
11
11
|
export declare function getOpenTagStartIndex(string: string, maxIndex: number, tag: string): number;
|
|
12
12
|
export declare function indexBy<T>(list: Array<T>, callback: (arg0: T) => string | undefined): Readonly<Record<string, Array<T>>>;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a character is a punctuation character.
|
|
15
|
+
* @param char The character to check.
|
|
16
|
+
* @returns True if the character is a punctuation character, false otherwise.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isPunctuationChar(char: string): boolean;
|
|
@@ -58,4 +58,17 @@ export function indexBy(list, callback) {
|
|
|
58
58
|
_iterator.f();
|
|
59
59
|
}
|
|
60
60
|
return index;
|
|
61
|
+
}
|
|
62
|
+
var Punctuation = /[!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~\u00A1\u2010-\u2027-]/;
|
|
63
|
+
try {
|
|
64
|
+
Punctuation = new RegExp('[\\p{Pc}|\\p{Pd}|\\p{Pe}|\\p{Pf}|\\p{Pi}|\\p{Po}|\\p{Ps}]', 'u');
|
|
65
|
+
} catch (_unused) {}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Checks if a character is a punctuation character.
|
|
69
|
+
* @param char The character to check.
|
|
70
|
+
* @returns True if the character is a punctuation character, false otherwise.
|
|
71
|
+
*/
|
|
72
|
+
export function isPunctuationChar(char) {
|
|
73
|
+
return Punctuation.test(char);
|
|
61
74
|
}
|
|
@@ -10,13 +10,14 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
10
10
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
11
11
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
12
|
import { Button, Icon } from '@lobehub/ui';
|
|
13
|
-
import { Dropdown } from 'antd';
|
|
13
|
+
import { Dropdown, Space } from 'antd';
|
|
14
14
|
import { ChevronDownIcon } from 'lucide-react';
|
|
15
15
|
import { memo } from 'react';
|
|
16
16
|
import SendIcon from "./components/SendIcon";
|
|
17
17
|
import StopIcon from "./components/StopIcon";
|
|
18
18
|
import { useStyles } from "./style";
|
|
19
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
21
|
var SendButton = /*#__PURE__*/memo(function (_ref) {
|
|
21
22
|
var _ref$type = _ref.type,
|
|
22
23
|
type = _ref$type === void 0 ? 'primary' : _ref$type,
|
|
@@ -77,24 +78,40 @@ var SendButton = /*#__PURE__*/memo(function (_ref) {
|
|
|
77
78
|
style: style,
|
|
78
79
|
type: type
|
|
79
80
|
}, rest));
|
|
80
|
-
return /*#__PURE__*/
|
|
81
|
+
return /*#__PURE__*/_jsxs(Space.Compact, _objectSpread(_objectSpread({
|
|
81
82
|
className: cx(styles.dropdownButton, disabled && styles.disabled, shape === 'round' && styles.dropdownButtonRound, className),
|
|
82
|
-
|
|
83
|
-
icon: /*#__PURE__*/_jsx(Icon, {
|
|
84
|
-
icon: ChevronDownIcon
|
|
85
|
-
}),
|
|
86
|
-
menu: menu,
|
|
87
|
-
onClick: function onClick(e) {
|
|
88
|
-
e.stopPropagation();
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
if (onSend) onSend(e);
|
|
91
|
-
if (_onClick) _onClick(e);
|
|
92
|
-
},
|
|
93
|
-
placement: 'topRight',
|
|
94
|
-
style: style,
|
|
95
|
-
type: type
|
|
83
|
+
style: style
|
|
96
84
|
}, rest), {}, {
|
|
97
|
-
children:
|
|
85
|
+
children: [/*#__PURE__*/_jsx(Button, _objectSpread({
|
|
86
|
+
className: cx(styles.button, disabled && styles.disabled, className),
|
|
87
|
+
disabled: disabled,
|
|
88
|
+
icon: /*#__PURE__*/_jsx(SendIcon, {}),
|
|
89
|
+
onClick: function onClick(e) {
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
if (onSend) onSend(e);
|
|
93
|
+
if (_onClick) _onClick(e);
|
|
94
|
+
},
|
|
95
|
+
shape: shape,
|
|
96
|
+
style: style,
|
|
97
|
+
type: type
|
|
98
|
+
}, rest)), /*#__PURE__*/_jsx(Dropdown, _objectSpread(_objectSpread({
|
|
99
|
+
menu: menu,
|
|
100
|
+
placement: 'topRight'
|
|
101
|
+
}, rest), {}, {
|
|
102
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
103
|
+
className: cx(styles.button, disabled && styles.disabled, className),
|
|
104
|
+
disabled: disabled,
|
|
105
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
|
106
|
+
icon: ChevronDownIcon
|
|
107
|
+
}),
|
|
108
|
+
shape: shape,
|
|
109
|
+
style: {
|
|
110
|
+
cursor: 'pointer'
|
|
111
|
+
},
|
|
112
|
+
type: type
|
|
113
|
+
})
|
|
114
|
+
}))]
|
|
98
115
|
}));
|
|
99
116
|
});
|
|
100
117
|
SendButton.displayName = 'SendButton';
|
package/package.json
CHANGED