@ant-design/agentic-ui 2.28.0 → 2.28.2
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/MarkdownEditor/editor/elements/CommentLeaf/index.d.ts +11 -0
- package/dist/MarkdownEditor/editor/elements/CommentLeaf/index.js +69 -0
- package/dist/MarkdownEditor/editor/elements/FncLeaf/index.d.ts +15 -0
- package/dist/MarkdownEditor/editor/elements/FncLeaf/index.js +208 -0
- package/dist/MarkdownEditor/editor/elements/Paragraph/index.js +2 -2
- package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +43 -88
- package/dist/MarkdownEditor/editor/elements/index.d.ts +12 -0
- package/dist/MarkdownEditor/editor/elements/index.js +44 -102
- package/dist/MarkdownEditor/editor/parser/parse/parseTable.js +9 -2
- package/dist/MarkdownEditor/editor/plugins/useHighlight.js +160 -186
- package/dist/Plugins/chart/AreaChart/index.js +3 -0
- package/dist/Plugins/chart/BarChart/index.js +3 -0
- package/dist/Plugins/chart/DonutChart/index.js +1 -1
- package/dist/Plugins/chart/FunnelChart/index.js +3 -0
- package/dist/Plugins/chart/LineChart/index.js +3 -0
- package/dist/Plugins/chart/RadarChart/index.js +3 -0
- package/dist/Plugins/chart/ScatterChart/index.js +3 -0
- package/dist/Plugins/code/components/ThinkBlock.js +66 -5
- package/package.json +1 -1
|
@@ -52,11 +52,10 @@ function _object_spread_props(target, source) {
|
|
|
52
52
|
}
|
|
53
53
|
import { ConfigProvider } from "antd";
|
|
54
54
|
import classNames from "classnames";
|
|
55
|
-
import React, { useContext
|
|
55
|
+
import React, { useContext } from "react";
|
|
56
56
|
import { Editor, Path, Transforms } from "slate";
|
|
57
57
|
import { ReactEditor } from "slate-react";
|
|
58
58
|
import { I18nContext } from "../../../I18n";
|
|
59
|
-
import { isMobileDevice } from "../../../MarkdownInputField/AttachmentButton/utils";
|
|
60
59
|
import { debugInfo } from "../../../Utils/debugUtils";
|
|
61
60
|
import { useEditorStore } from "../store";
|
|
62
61
|
import { EditorUtils } from "../utils/editorUtils";
|
|
@@ -64,7 +63,8 @@ import { Blockquote } from "./Blockquote";
|
|
|
64
63
|
import { Break } from "./Break";
|
|
65
64
|
import { WarpCard } from "./Card";
|
|
66
65
|
import { Code } from "./Code";
|
|
67
|
-
import {
|
|
66
|
+
import { CommentLeaf } from "./CommentLeaf";
|
|
67
|
+
import { FncLeaf } from "./FncLeaf";
|
|
68
68
|
import { FootnoteDefinition } from "./FootnoteDefinition";
|
|
69
69
|
import { FootnoteReference } from "./FootnoteReference";
|
|
70
70
|
import { Head } from "./Head";
|
|
@@ -90,7 +90,7 @@ import { TagPopup } from "./TagPopup";
|
|
|
90
90
|
* 4. **批量属性检查**:对 MLeaf 组件使用数组批量检查关键属性
|
|
91
91
|
*
|
|
92
92
|
* 性能测试结果显示约 43% 的渲染性能提升,在相同 props 的情况下避免了重复渲染。
|
|
93
|
-
*/ var dragStart = function(e) {
|
|
93
|
+
*/ export var dragStart = function(e) {
|
|
94
94
|
e.preventDefault();
|
|
95
95
|
e.stopPropagation();
|
|
96
96
|
};
|
|
@@ -319,8 +319,8 @@ export var MElement = /*#__PURE__*/ React.memo(MElementComponent, areElementProp
|
|
|
319
319
|
return true;
|
|
320
320
|
};
|
|
321
321
|
var MLeafComponent = function(props) {
|
|
322
|
-
var _leaf_text
|
|
323
|
-
var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, markdownContainerRef = _useEditorStore.markdownContainerRef
|
|
322
|
+
var _leaf_text;
|
|
323
|
+
var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, markdownContainerRef = _useEditorStore.markdownContainerRef;
|
|
324
324
|
var context = useContext(ConfigProvider.ConfigContext);
|
|
325
325
|
var locale = useContext(I18nContext).locale;
|
|
326
326
|
var mdEditorBaseClass = context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-md-editor-content');
|
|
@@ -489,79 +489,48 @@ var MLeafComponent = function(props) {
|
|
|
489
489
|
});
|
|
490
490
|
}
|
|
491
491
|
};
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
492
|
+
// 如果检测到 fnc、identifier 或 fnd,使用 FncLeaf 组件
|
|
493
|
+
var hasFnc = leaf.fnc || leaf.identifier || leaf.fnd;
|
|
494
|
+
var hasComment = !!leaf.comment;
|
|
495
|
+
if (hasFnc) {
|
|
496
|
+
debugInfo('MLeafComponent - 使用 FncLeaf 组件', {
|
|
497
|
+
hasFnc: !!leaf.fnc,
|
|
498
|
+
hasIdentifier: !!leaf.identifier,
|
|
499
|
+
hasFnd: !!leaf.fnd
|
|
498
500
|
});
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
isLongPressRef.current = true;
|
|
515
|
-
handleFncOpen();
|
|
516
|
-
}, 500); // 500ms 长按时间
|
|
517
|
-
};
|
|
518
|
-
var handleTouchEnd = function(e) {
|
|
519
|
-
if (!hasFnc) return;
|
|
520
|
-
if (longPressTimerRef.current) {
|
|
521
|
-
clearTimeout(longPressTimerRef.current);
|
|
522
|
-
longPressTimerRef.current = null;
|
|
501
|
+
var baseClassName = classNames(prefixClassName === null || prefixClassName === void 0 ? void 0 : prefixClassName.trim(), props.hashId);
|
|
502
|
+
var fncDom = /*#__PURE__*/ React.createElement(FncLeaf, _object_spread_props(_object_spread({}, props), {
|
|
503
|
+
hashId: props.hashId,
|
|
504
|
+
fncProps: props.fncProps,
|
|
505
|
+
linkConfig: props.linkConfig,
|
|
506
|
+
style: style,
|
|
507
|
+
prefixClassName: baseClassName
|
|
508
|
+
}));
|
|
509
|
+
// 如果有评论,使用 CommentLeaf 包裹 fnc DOM
|
|
510
|
+
if (hasComment) {
|
|
511
|
+
return /*#__PURE__*/ React.createElement(CommentLeaf, {
|
|
512
|
+
leaf: props.leaf,
|
|
513
|
+
hashId: props.hashId,
|
|
514
|
+
comment: props.comment
|
|
515
|
+
}, fncDom);
|
|
523
516
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
e.preventDefault();
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
var handleTouchCancel = function() {
|
|
531
|
-
if (longPressTimerRef.current) {
|
|
532
|
-
clearTimeout(longPressTimerRef.current);
|
|
533
|
-
longPressTimerRef.current = null;
|
|
534
|
-
}
|
|
535
|
-
isLongPressRef.current = false;
|
|
536
|
-
};
|
|
537
|
-
var _obj;
|
|
538
|
-
var fncClassName = classNames(prefixClassName === null || prefixClassName === void 0 ? void 0 : prefixClassName.trim(), props.hashId, (_obj = {}, _define_property(_obj, "".concat(mdEditorBaseClass, "-fnc"), leaf.fnc), _define_property(_obj, "".concat(mdEditorBaseClass, "-fnd"), leaf.fnd), _define_property(_obj, "".concat(mdEditorBaseClass, "-comment"), leaf.comment), _obj));
|
|
517
|
+
return fncDom;
|
|
518
|
+
}
|
|
519
|
+
var baseClassName1 = classNames(prefixClassName === null || prefixClassName === void 0 ? void 0 : prefixClassName.trim(), props.hashId);
|
|
539
520
|
var dom = /*#__PURE__*/ React.createElement("span", _object_spread_props(_object_spread({}, props.attributes), {
|
|
540
521
|
"data-be": "text",
|
|
541
522
|
draggable: false,
|
|
542
523
|
onDragStart: dragStart,
|
|
543
524
|
onClick: function(e) {
|
|
544
|
-
var
|
|
525
|
+
var _props_linkConfig, _props_linkConfig1, _props_linkConfig2;
|
|
545
526
|
debugInfo('MLeafComponent - onClick 事件', {
|
|
546
|
-
isMobile: isMobile,
|
|
547
|
-
hasFnc: hasFnc,
|
|
548
527
|
detail: e.detail,
|
|
549
528
|
hasUrl: !!leaf.url
|
|
550
529
|
});
|
|
551
|
-
// 在手机上,如果是 fnc,阻止点击事件(使用长按代替)
|
|
552
|
-
if (isMobile && hasFnc) {
|
|
553
|
-
debugInfo('MLeafComponent - 移动端阻止 fnc 点击');
|
|
554
|
-
e.preventDefault();
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
530
|
if (e.detail === 2) {
|
|
558
531
|
debugInfo('MLeafComponent - 双击选择格式');
|
|
559
532
|
selectFormat();
|
|
560
533
|
}
|
|
561
|
-
if ((_props_fncProps = props.fncProps) === null || _props_fncProps === void 0 ? void 0 : _props_fncProps.onOriginUrlClick) {
|
|
562
|
-
debugInfo('MLeafComponent - 触发 fnc 点击');
|
|
563
|
-
props.fncProps.onOriginUrlClick(leaf === null || leaf === void 0 ? void 0 : leaf.identifier);
|
|
564
|
-
}
|
|
565
534
|
if ((_props_linkConfig = props.linkConfig) === null || _props_linkConfig === void 0 ? void 0 : _props_linkConfig.onClick) {
|
|
566
535
|
var _props_linkConfig3;
|
|
567
536
|
var res = (_props_linkConfig3 = props.linkConfig) === null || _props_linkConfig3 === void 0 ? void 0 : _props_linkConfig3.onClick(leaf.url);
|
|
@@ -585,47 +554,20 @@ var MLeafComponent = function(props) {
|
|
|
585
554
|
window.location.href = leaf.url;
|
|
586
555
|
}
|
|
587
556
|
},
|
|
588
|
-
onTouchStart: hasFnc ? handleTouchStart : undefined,
|
|
589
|
-
onTouchEnd: hasFnc ? handleTouchEnd : undefined,
|
|
590
|
-
onTouchCancel: hasFnc ? handleTouchCancel : undefined,
|
|
591
|
-
contentEditable: leaf.fnc ? false : undefined,
|
|
592
|
-
"data-fnc": leaf.fnc || leaf.identifier ? 'fnc' : undefined,
|
|
593
|
-
"data-fnd": leaf.fnd ? 'fnd' : undefined,
|
|
594
557
|
"data-comment": leaf.comment ? 'comment' : undefined,
|
|
595
|
-
"data-fnc-name": leaf.fnc ? (_leaf_text1 = leaf.text) === null || _leaf_text1 === void 0 ? void 0 : _leaf_text1.replace(/\[\^(.+)]:?/g, '$1') : undefined,
|
|
596
558
|
"data-url": leaf.url ? 'url' : undefined,
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
hasIdentifier: !!leaf.identifier
|
|
608
|
-
});
|
|
609
|
-
dom = /*#__PURE__*/ React.createElement(React.Fragment, null, (_props_fncProps_render = (_props_fncProps1 = props.fncProps).render) === null || _props_fncProps_render === void 0 ? void 0 : _props_fncProps_render.call(_props_fncProps1, _object_spread_props(_object_spread({}, leaf), {
|
|
610
|
-
children: ((_leaf_text4 = leaf.text) === null || _leaf_text4 === void 0 ? void 0 : (_leaf_text_toLocaleUpperCase = _leaf_text4.toLocaleUpperCase()) === null || _leaf_text_toLocaleUpperCase === void 0 ? void 0 : _leaf_text_toLocaleUpperCase.replaceAll('[^', '').replaceAll(']', '')) || ''
|
|
611
|
-
}), dom));
|
|
612
|
-
}
|
|
613
|
-
if (!props.leaf.comment) {
|
|
614
|
-
debugInfo('MLeafComponent - 返回 DOM(无评论)');
|
|
615
|
-
return dom;
|
|
559
|
+
className: baseClassName1 ? baseClassName1 : undefined,
|
|
560
|
+
style: style
|
|
561
|
+
}), children);
|
|
562
|
+
// 如果有评论,使用 CommentLeaf 包裹普通 DOM
|
|
563
|
+
if (hasComment) {
|
|
564
|
+
return /*#__PURE__*/ React.createElement(CommentLeaf, {
|
|
565
|
+
leaf: props.leaf,
|
|
566
|
+
hashId: props.hashId,
|
|
567
|
+
comment: props.comment
|
|
568
|
+
}, dom);
|
|
616
569
|
}
|
|
617
|
-
|
|
618
|
-
commentId: (_props_leaf = props.leaf) === null || _props_leaf === void 0 ? void 0 : _props_leaf.id,
|
|
619
|
-
hasCommentItem: !!(leaf === null || leaf === void 0 ? void 0 : leaf.comment)
|
|
620
|
-
});
|
|
621
|
-
return /*#__PURE__*/ React.createElement(CommentView, {
|
|
622
|
-
id: "comment-".concat((_props_leaf1 = props.leaf) === null || _props_leaf1 === void 0 ? void 0 : _props_leaf1.id),
|
|
623
|
-
comment: props.comment,
|
|
624
|
-
hashId: props.hashId,
|
|
625
|
-
selection: leaf === null || leaf === void 0 ? void 0 : leaf.selection,
|
|
626
|
-
commentItem: (leaf === null || leaf === void 0 ? void 0 : leaf.comment) ? leaf.data : null,
|
|
627
|
-
setShowComment: setShowComment
|
|
628
|
-
}, dom);
|
|
570
|
+
return dom;
|
|
629
571
|
};
|
|
630
572
|
// 使用 React.memo 优化 MLeaf 组件的性能
|
|
631
573
|
export var MLeaf = /*#__PURE__*/ React.memo(MLeafComponent, areLeafPropsEqual);
|
|
@@ -148,7 +148,7 @@ var myRemark = {
|
|
|
148
148
|
* @param parserConfig - 解析配置
|
|
149
149
|
* @returns 返回表格或图表节点
|
|
150
150
|
*/ export var parseTableOrChart = function(table, preNode, plugins, parseNodes, parserConfig) {
|
|
151
|
-
var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align
|
|
151
|
+
var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align;
|
|
152
152
|
var keyMap = new Map();
|
|
153
153
|
var config = (preNode === null || preNode === void 0 ? void 0 : preNode.type) === 'code' && (preNode === null || preNode === void 0 ? void 0 : preNode.language) === 'html' && (preNode === null || preNode === void 0 ? void 0 : preNode.otherProps) ? preNode === null || preNode === void 0 ? void 0 : preNode.otherProps : parserConfig || {};
|
|
154
154
|
var tableHeader = table === null || table === void 0 ? void 0 : (_table_children = table.children) === null || _table_children === void 0 ? void 0 : _table_children.at(0);
|
|
@@ -233,7 +233,14 @@ var myRemark = {
|
|
|
233
233
|
var chartConfig = Array.isArray(config === null || config === void 0 ? void 0 : config.config) ? config.config : (config === null || config === void 0 ? void 0 : config.config) || config;
|
|
234
234
|
// 如果 chartConfig 是对象且键都是数字(如 {0: {...}}),转换为数组
|
|
235
235
|
chartConfig = convertObjectToArray(chartConfig);
|
|
236
|
-
|
|
236
|
+
// 获取 chartType,支持多种配置格式
|
|
237
|
+
var getChartType = function() {
|
|
238
|
+
var _chartConfig_, _config_at, _config_at1;
|
|
239
|
+
return (chartConfig === null || chartConfig === void 0 ? void 0 : chartConfig.chartType) || Array.isArray(chartConfig) && (chartConfig === null || chartConfig === void 0 ? void 0 : (_chartConfig_ = chartConfig[0]) === null || _chartConfig_ === void 0 ? void 0 : _chartConfig_.chartType) || (config === null || config === void 0 ? void 0 : config.chartType) || (config === null || config === void 0 ? void 0 : (_config_at1 = config.at) === null || _config_at1 === void 0 ? void 0 : (_config_at = _config_at1.call(config, 0)) === null || _config_at === void 0 ? void 0 : _config_at.chartType);
|
|
240
|
+
};
|
|
241
|
+
var chartType = getChartType();
|
|
242
|
+
// 如果 chartType 为 "table",将其视为不存在,按普通表格处理
|
|
243
|
+
var isChart = chartType && chartType !== 'table';
|
|
237
244
|
// 计算合并单元格信息
|
|
238
245
|
var mergeCells = (config === null || config === void 0 ? void 0 : config.mergeCells) || [];
|
|
239
246
|
// 创建合并单元格映射,用于快速查找
|
|
@@ -9,6 +9,19 @@ function _array_with_holes(arr) {
|
|
|
9
9
|
function _array_without_holes(arr) {
|
|
10
10
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
11
|
}
|
|
12
|
+
function _define_property(obj, key, value) {
|
|
13
|
+
if (key in obj) {
|
|
14
|
+
Object.defineProperty(obj, key, {
|
|
15
|
+
value: value,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
obj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
12
25
|
function _iterable_to_array(iter) {
|
|
13
26
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
14
27
|
}
|
|
@@ -42,6 +55,21 @@ function _non_iterable_rest() {
|
|
|
42
55
|
function _non_iterable_spread() {
|
|
43
56
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
44
57
|
}
|
|
58
|
+
function _object_spread(target) {
|
|
59
|
+
for(var i = 1; i < arguments.length; i++){
|
|
60
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
61
|
+
var ownKeys = Object.keys(source);
|
|
62
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
63
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
64
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
ownKeys.forEach(function(key) {
|
|
68
|
+
_define_property(target, key, source[key]);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return target;
|
|
72
|
+
}
|
|
45
73
|
function _sliced_to_array(arr, i) {
|
|
46
74
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
47
75
|
}
|
|
@@ -58,8 +86,11 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
58
86
|
}
|
|
59
87
|
import { Editor, Element, Node, Path } from "slate";
|
|
60
88
|
import { EditorUtils } from "../utils/editorUtils";
|
|
61
|
-
|
|
62
|
-
var
|
|
89
|
+
// 预编译正则表达式,避免重复创建
|
|
90
|
+
var HTML_REG = /<[a-z]+[\s"'=:;()\w\-[\]/.]*\/?>(.*<\/[a-z]+>:?)?/g;
|
|
91
|
+
var LINK_REG = /(https?|ftp):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/gi;
|
|
92
|
+
var FOOTNOTE_REG = /\[\^[^\]]+\]/g;
|
|
93
|
+
var TABLE_ROW_REG = /^\|([^|]+\|)+$/;
|
|
63
94
|
export var cacheTextNode = new WeakMap();
|
|
64
95
|
export var clearInlineKatex = function(editor) {
|
|
65
96
|
var inlineMath = Array.from(Editor.nodes(editor, {
|
|
@@ -68,10 +99,14 @@ export var clearInlineKatex = function(editor) {
|
|
|
68
99
|
},
|
|
69
100
|
at: []
|
|
70
101
|
}));
|
|
71
|
-
inlineMath.
|
|
102
|
+
inlineMath.forEach(function(c) {
|
|
72
103
|
return cacheTextNode.delete(c[0]);
|
|
73
104
|
});
|
|
74
105
|
};
|
|
106
|
+
var PARAGRAPH_TYPES = new Set([
|
|
107
|
+
'paragraph',
|
|
108
|
+
'table-cell'
|
|
109
|
+
]);
|
|
75
110
|
var highlightNodes = new Set([
|
|
76
111
|
'paragraph',
|
|
77
112
|
'table-cell',
|
|
@@ -80,198 +115,137 @@ var highlightNodes = new Set([
|
|
|
80
115
|
'head',
|
|
81
116
|
'inline-katex'
|
|
82
117
|
]);
|
|
118
|
+
// 创建 range 对象的工厂函数,复用 path 数组
|
|
119
|
+
var createRange = function(path, childIndex, offset, length) {
|
|
120
|
+
var props = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {};
|
|
121
|
+
var childPath = path.concat(childIndex);
|
|
122
|
+
return _object_spread({
|
|
123
|
+
anchor: {
|
|
124
|
+
path: childPath,
|
|
125
|
+
offset: offset
|
|
126
|
+
},
|
|
127
|
+
focus: {
|
|
128
|
+
path: childPath,
|
|
129
|
+
offset: offset + length
|
|
130
|
+
}
|
|
131
|
+
}, props);
|
|
132
|
+
};
|
|
133
|
+
// 处理文本节点的匹配逻辑
|
|
134
|
+
var processTextMatches = function(text, path, childIndex) {
|
|
135
|
+
var ranges = [];
|
|
136
|
+
// 匹配 footnote reference
|
|
137
|
+
var match;
|
|
138
|
+
FOOTNOTE_REG.lastIndex = 0;
|
|
139
|
+
while((match = FOOTNOTE_REG.exec(text)) !== null){
|
|
140
|
+
var index = match.index;
|
|
141
|
+
if (typeof index === 'number') {
|
|
142
|
+
ranges.push(createRange(path, childIndex, index, match[0].length, {
|
|
143
|
+
fnc: true,
|
|
144
|
+
fnd: false
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// 匹配 HTML
|
|
149
|
+
HTML_REG.lastIndex = 0;
|
|
150
|
+
while((match = HTML_REG.exec(text)) !== null){
|
|
151
|
+
var index1 = match.index;
|
|
152
|
+
if (typeof index1 === 'number') {
|
|
153
|
+
ranges.push(createRange(path, childIndex, index1, match[0].length, {
|
|
154
|
+
html: true
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return ranges;
|
|
159
|
+
};
|
|
160
|
+
// 处理链接匹配
|
|
161
|
+
var processLinkMatches = function(text, path, childIndex) {
|
|
162
|
+
var ranges = [];
|
|
163
|
+
var match;
|
|
164
|
+
LINK_REG.lastIndex = 0;
|
|
165
|
+
while((match = LINK_REG.exec(text)) !== null){
|
|
166
|
+
var index = match.index;
|
|
167
|
+
if (typeof index === 'number') {
|
|
168
|
+
ranges.push(createRange(path, childIndex, index, match[0].length, {
|
|
169
|
+
link: match[0]
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return ranges;
|
|
174
|
+
};
|
|
83
175
|
export function useHighlight(store) {
|
|
84
176
|
return function(param) {
|
|
85
177
|
var _param = _sliced_to_array(param, 2), node = _param[0], path = _param[1];
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
anchor: {
|
|
110
|
-
path: _to_consumable_array(path).concat([
|
|
111
|
-
i
|
|
112
|
-
]),
|
|
113
|
-
offset: m.index
|
|
114
|
-
},
|
|
115
|
-
focus: {
|
|
116
|
-
path: _to_consumable_array(path).concat([
|
|
117
|
-
i
|
|
118
|
-
]),
|
|
119
|
-
offset: m.index + m[0].length
|
|
120
|
-
},
|
|
121
|
-
html: true
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
} catch (err) {
|
|
125
|
-
_didIteratorError = true;
|
|
126
|
-
_iteratorError = err;
|
|
127
|
-
} finally{
|
|
128
|
-
try {
|
|
129
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
130
|
-
_iterator.return();
|
|
131
|
-
}
|
|
132
|
-
} finally{
|
|
133
|
-
if (_didIteratorError) {
|
|
134
|
-
throw _iteratorError;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
var match = c.text.matchAll(/\[\^.+?]:?/g);
|
|
139
|
-
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
140
|
-
try {
|
|
141
|
-
for(var _iterator1 = match[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
142
|
-
var m1 = _step1.value;
|
|
143
|
-
if (typeof m1.index !== 'number') continue;
|
|
144
|
-
textRanges.push({
|
|
145
|
-
anchor: {
|
|
146
|
-
path: _to_consumable_array(path).concat([
|
|
147
|
-
i
|
|
148
|
-
]),
|
|
149
|
-
offset: m1.index
|
|
150
|
-
},
|
|
151
|
-
focus: {
|
|
152
|
-
path: _to_consumable_array(path).concat([
|
|
153
|
-
i
|
|
154
|
-
]),
|
|
155
|
-
offset: m1.index + m1[0].length
|
|
156
|
-
},
|
|
157
|
-
fnc: !m1[0].endsWith(':'),
|
|
158
|
-
fnd: m1[0].endsWith(':')
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
} catch (err) {
|
|
162
|
-
_didIteratorError1 = true;
|
|
163
|
-
_iteratorError1 = err;
|
|
164
|
-
} finally{
|
|
165
|
-
try {
|
|
166
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
167
|
-
_iterator1.return();
|
|
168
|
-
}
|
|
169
|
-
} finally{
|
|
170
|
-
if (_didIteratorError1) {
|
|
171
|
-
throw _iteratorError1;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
cacheTextNode.set(node, {
|
|
176
|
-
path: path,
|
|
177
|
-
range: textRanges
|
|
178
|
-
});
|
|
179
|
-
(_ranges1 = ranges).push.apply(_ranges1, _to_consumable_array(textRanges));
|
|
180
|
-
}
|
|
178
|
+
// 快速路径:非元素节点或不在高亮节点列表中
|
|
179
|
+
if (!Element.isElement(node) || !highlightNodes.has(node.type)) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
var ranges = (store === null || store === void 0 ? void 0 : store.highlightCache.get(node)) || [];
|
|
183
|
+
var cacheText = cacheTextNode.get(node);
|
|
184
|
+
var isCached = cacheText && Path.equals(cacheText.path, path);
|
|
185
|
+
// 处理 paragraph 和 table-cell
|
|
186
|
+
if (PARAGRAPH_TYPES.has(node.type)) {
|
|
187
|
+
if (isCached) {
|
|
188
|
+
var _ranges;
|
|
189
|
+
(_ranges = ranges).push.apply(_ranges, _to_consumable_array(cacheText.range));
|
|
190
|
+
} else {
|
|
191
|
+
var _ranges1;
|
|
192
|
+
var allTextRanges = [];
|
|
193
|
+
var children = node.children;
|
|
194
|
+
var childrenLength = children.length;
|
|
195
|
+
for(var i = 0; i < childrenLength; i++){
|
|
196
|
+
var child = children[i];
|
|
197
|
+
// 处理 footnote 和 HTML
|
|
198
|
+
if (child.text && !EditorUtils.isDirtLeaf(child)) {
|
|
199
|
+
var _allTextRanges;
|
|
200
|
+
(_allTextRanges = allTextRanges).push.apply(_allTextRanges, _to_consumable_array(processTextMatches(child.text, path, i)));
|
|
181
201
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
var
|
|
185
|
-
|
|
186
|
-
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
187
|
-
try {
|
|
188
|
-
for(var _iterator2 = links[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
189
|
-
var m2 = _step2.value;
|
|
190
|
-
textRanges1.push({
|
|
191
|
-
anchor: {
|
|
192
|
-
path: _to_consumable_array(path).concat([
|
|
193
|
-
i
|
|
194
|
-
]),
|
|
195
|
-
offset: m2.index
|
|
196
|
-
},
|
|
197
|
-
focus: {
|
|
198
|
-
path: _to_consumable_array(path).concat([
|
|
199
|
-
i
|
|
200
|
-
]),
|
|
201
|
-
offset: m2.index + m2[0].length
|
|
202
|
-
},
|
|
203
|
-
link: m2[0]
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
} catch (err) {
|
|
207
|
-
_didIteratorError2 = true;
|
|
208
|
-
_iteratorError2 = err;
|
|
209
|
-
} finally{
|
|
210
|
-
try {
|
|
211
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
212
|
-
_iterator2.return();
|
|
213
|
-
}
|
|
214
|
-
} finally{
|
|
215
|
-
if (_didIteratorError2) {
|
|
216
|
-
throw _iteratorError2;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
(_ranges2 = ranges).push.apply(_ranges2, _to_consumable_array(textRanges1));
|
|
202
|
+
// 处理链接
|
|
203
|
+
if (child.text && !child.url && !child.docId && !child.hash) {
|
|
204
|
+
var _allTextRanges1;
|
|
205
|
+
(_allTextRanges1 = allTextRanges).push.apply(_allTextRanges1, _to_consumable_array(processLinkMatches(child.text, path, i)));
|
|
221
206
|
}
|
|
222
207
|
}
|
|
208
|
+
// 统一缓存
|
|
209
|
+
cacheTextNode.set(node, {
|
|
210
|
+
path: path,
|
|
211
|
+
range: allTextRanges
|
|
212
|
+
});
|
|
213
|
+
(_ranges1 = ranges).push.apply(_ranges1, _to_consumable_array(allTextRanges));
|
|
223
214
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
]),
|
|
256
|
-
offset: 0
|
|
257
|
-
},
|
|
258
|
-
focus: {
|
|
259
|
-
path: _to_consumable_array(path).concat([
|
|
260
|
-
0
|
|
261
|
-
]),
|
|
262
|
-
offset: str.length
|
|
263
|
-
},
|
|
264
|
-
color: '#a3a3a3'
|
|
265
|
-
});
|
|
266
|
-
cacheTextNode.set(node, {
|
|
267
|
-
path: path,
|
|
268
|
-
range: ranges
|
|
269
|
-
});
|
|
270
|
-
}
|
|
215
|
+
}
|
|
216
|
+
// 处理特殊段落(代码块或表格行)
|
|
217
|
+
if (node.type === 'paragraph' && node.children.length === 1 && !EditorUtils.isDirtLeaf(node.children[0])) {
|
|
218
|
+
if (isCached) {
|
|
219
|
+
var _ranges2;
|
|
220
|
+
(_ranges2 = ranges).push.apply(_ranges2, _to_consumable_array(cacheText.range));
|
|
221
|
+
} else {
|
|
222
|
+
var str = Node.string(node);
|
|
223
|
+
var strLength = str.length;
|
|
224
|
+
if (str.startsWith('```')) {
|
|
225
|
+
var range = createRange(path, 0, 0, 3, {
|
|
226
|
+
color: '#a3a3a3'
|
|
227
|
+
});
|
|
228
|
+
ranges.push(range);
|
|
229
|
+
cacheTextNode.set(node, {
|
|
230
|
+
path: path,
|
|
231
|
+
range: [
|
|
232
|
+
range
|
|
233
|
+
]
|
|
234
|
+
});
|
|
235
|
+
} else if (TABLE_ROW_REG.test(str)) {
|
|
236
|
+
var range1 = createRange(path, 0, 0, strLength, {
|
|
237
|
+
color: '#a3a3a3'
|
|
238
|
+
});
|
|
239
|
+
ranges.push(range1);
|
|
240
|
+
cacheTextNode.set(node, {
|
|
241
|
+
path: path,
|
|
242
|
+
range: [
|
|
243
|
+
range1
|
|
244
|
+
]
|
|
245
|
+
});
|
|
271
246
|
}
|
|
272
247
|
}
|
|
273
|
-
return ranges;
|
|
274
248
|
}
|
|
275
|
-
return
|
|
249
|
+
return ranges;
|
|
276
250
|
};
|
|
277
251
|
}
|