x-star-editor 0.3.7 → 0.3.8
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/dist/utils/markdown.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { Root as HastRoot } from 'hast';
|
|
3
2
|
import { defaultSchema } from 'rehype-sanitize';
|
|
4
3
|
import type { ViewerOptions } from '../x-star-md-viewer';
|
|
@@ -36,7 +35,7 @@ export declare const viewerRender: (root: HastRoot, schema: Schema) => HastRoot;
|
|
|
36
35
|
* @param options 配置项
|
|
37
36
|
* @returns React 虚拟 DOM 树
|
|
38
37
|
*/
|
|
39
|
-
export declare const postViewerRender: (root: HastRoot, options: ViewerOptions) =>
|
|
38
|
+
export declare const postViewerRender: (root: HastRoot, options: ViewerOptions) => any;
|
|
40
39
|
/**
|
|
41
40
|
* 将 Markdown 文本转成 HTML 文本
|
|
42
41
|
*
|
package/dist/utils/markdown.js
CHANGED
|
@@ -341,23 +341,33 @@ export var viewerRender = function viewerRender(root, schema) {
|
|
|
341
341
|
* @returns React 虚拟 DOM 树
|
|
342
342
|
*/
|
|
343
343
|
export var postViewerRender = function postViewerRender(root, options) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
344
|
+
try {
|
|
345
|
+
var components = _objectSpread(_objectSpread({}, options.customHTMLElements), {}, {
|
|
346
|
+
input: function input(props) {
|
|
347
|
+
return jsx('input', props);
|
|
348
|
+
},
|
|
349
|
+
custom: function custom(props) {
|
|
350
|
+
var _options$customBlocks;
|
|
351
|
+
return jsx((_options$customBlocks = options.customBlocks[props.meta]) !== null && _options$customBlocks !== void 0 ? _options$customBlocks : 'div', {
|
|
352
|
+
children: props.value
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
return toJsxRuntime(unified().use(rehypeKatex).runSync(root), {
|
|
357
|
+
Fragment: Fragment,
|
|
358
|
+
jsx: jsx,
|
|
359
|
+
jsxs: jsxs,
|
|
360
|
+
components: components
|
|
361
|
+
});
|
|
362
|
+
} catch (_unused) {
|
|
363
|
+
return jsx('div', {
|
|
364
|
+
style: {
|
|
365
|
+
fontStyle: 'italic',
|
|
366
|
+
color: 'red'
|
|
367
|
+
},
|
|
368
|
+
children: 'Parse error!'
|
|
369
|
+
});
|
|
370
|
+
}
|
|
361
371
|
};
|
|
362
372
|
var toHTMLProcessor = unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkRehype, {
|
|
363
373
|
allowDangerousHtml: true,
|
|
@@ -125,11 +125,6 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
125
125
|
});
|
|
126
126
|
break;
|
|
127
127
|
}
|
|
128
|
-
case 'compositionstart':
|
|
129
|
-
{
|
|
130
|
-
container.normalizeSelection();
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
128
|
}
|
|
134
129
|
};
|
|
135
130
|
var dragEventHandler = function dragEventHandler(e) {
|
|
@@ -176,6 +171,7 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
176
171
|
{
|
|
177
172
|
// 组合时不触发快捷键
|
|
178
173
|
if (!e.nativeEvent.isComposing) {
|
|
174
|
+
container.normalizeSelection();
|
|
179
175
|
composeHandlers(options.keyboardEventHandlers)({
|
|
180
176
|
history: history,
|
|
181
177
|
sourceCode: sourceCode,
|
|
@@ -377,7 +373,6 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
377
373
|
contentEditable: true,
|
|
378
374
|
onBlur: focusEventHandler,
|
|
379
375
|
onCompositionEnd: compositionEventHandler,
|
|
380
|
-
onCompositionStart: compositionEventHandler,
|
|
381
376
|
onCopy: clipboardEventHandler,
|
|
382
377
|
onCut: clipboardEventHandler,
|
|
383
378
|
onDragStart: dragEventHandler,
|
|
@@ -57,7 +57,7 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
57
57
|
}
|
|
58
58
|
}, [enableWebWorker]);
|
|
59
59
|
useEffect(function () {
|
|
60
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
60
|
+
var timer = window.setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
61
61
|
var root, _worker$current2;
|
|
62
62
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
63
63
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -76,13 +76,21 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
76
76
|
return _context.stop();
|
|
77
77
|
}
|
|
78
78
|
}, _callee);
|
|
79
|
-
}))
|
|
79
|
+
})), 100);
|
|
80
|
+
return function () {
|
|
81
|
+
return window.clearTimeout(timer);
|
|
82
|
+
};
|
|
80
83
|
}, [value, options]);
|
|
81
84
|
|
|
82
85
|
// 确保在末尾输入时能同步滚动
|
|
83
86
|
useEffect(function () {
|
|
84
|
-
var
|
|
85
|
-
|
|
87
|
+
var timer = window.setTimeout(function () {
|
|
88
|
+
var _containerRef$current;
|
|
89
|
+
return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.dispatchEvent(new Event('render'));
|
|
90
|
+
}, 100);
|
|
91
|
+
return function () {
|
|
92
|
+
return window.clearTimeout(timer);
|
|
93
|
+
};
|
|
86
94
|
}, [children]);
|
|
87
95
|
return /*#__PURE__*/React.createElement("div", {
|
|
88
96
|
ref: containerRef,
|