@ant-design/agentic-ui 2.20.2 → 2.22.0
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/BaseMarkdownEditor.js +1 -1
- package/dist/MarkdownEditor/editor/elements/Code.js +1 -1
- package/dist/MarkdownEditor/editor/elements/Image/index.js +37 -9
- package/dist/MarkdownEditor/editor/elements/LinkCard/index.js +87 -2
- package/dist/MarkdownEditor/editor/elements/List/List.js +10 -2
- package/dist/MarkdownEditor/editor/elements/Media.js +75 -23
- package/dist/MarkdownEditor/editor/elements/Table/ReadonlyTableComponent.js +2 -13
- package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +89 -15
- package/dist/MarkdownEditor/editor/elements/Table/Table.js +3 -75
- package/dist/MarkdownEditor/editor/elements/TagPopup/index.js +4 -4
- package/dist/MarkdownEditor/editor/elements/TagPopup/style.js +14 -12
- package/dist/MarkdownEditor/editor/elements/index.js +1 -32
- package/dist/MarkdownEditor/editor/parser/parse/applyContextPropsAndConfig.d.ts +8 -0
- package/dist/MarkdownEditor/editor/parser/parse/applyContextPropsAndConfig.js +58 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseBlockElements.d.ts +67 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseBlockElements.js +289 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseCode.d.ts +32 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseCode.js +186 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseElements.d.ts +27 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseElements.js +83 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseEmptyLines.d.ts +9 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseEmptyLines.js +60 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseFootnote.d.ts +10 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseFootnote.js +12 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseHtml.d.ts +63 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseHtml.js +759 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseMath.d.ts +24 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseMath.js +58 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseMedia.d.ts +27 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseMedia.js +127 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseTable.d.ts +39 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseTable.js +348 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseText.d.ts +26 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseText.js +304 -0
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +3 -44
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +141 -2282
- package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +137 -12
- package/dist/MarkdownEditor/editor/parser/remarkParse.d.ts +11 -1
- package/dist/MarkdownEditor/editor/parser/remarkParse.js +225 -39
- package/dist/MarkdownEditor/editor/plugins/elements.js +1 -1
- package/dist/MarkdownEditor/editor/types/Table.d.ts +2 -1
- package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +2 -1
- package/dist/MarkdownEditor/el.d.ts +3 -0
- package/dist/MarkdownEditor/style.js +2 -0
- package/dist/Plugins/chart/index.js +7 -7
- package/dist/Plugins/code/components/CodeRenderer.js +27 -10
- package/dist/Plugins/code/components/CodeToolbar.js +3 -16
- package/dist/Workspace/Task/index.d.ts +13 -8
- package/dist/Workspace/Task/index.js +19 -2
- package/dist/Workspace/index.js +3 -2
- package/dist/Workspace/types.d.ts +3 -1
- package/package.json +1 -1
|
@@ -140,9 +140,7 @@ import classNames from "classnames";
|
|
|
140
140
|
import React, { useContext, useEffect, useMemo, useRef } from "react";
|
|
141
141
|
import { Node } from "slate";
|
|
142
142
|
import stringWidth from "string-width";
|
|
143
|
-
import { Loading } from "../../../../Components/Loading";
|
|
144
143
|
import { MOBILE_BREAKPOINT, MOBILE_TABLE_MIN_COLUMN_WIDTH } from "../../../../Constants/mobile";
|
|
145
|
-
import { useMEditor } from "../../../hooks/editor";
|
|
146
144
|
import { useEditorStore } from "../../store";
|
|
147
145
|
import { ReadonlyTableComponent } from "./ReadonlyTableComponent";
|
|
148
146
|
import { TablePropsContext } from "./TableContext";
|
|
@@ -178,8 +176,8 @@ import useScrollShadow from "./useScrollShadow";
|
|
|
178
176
|
"hashId",
|
|
179
177
|
"children"
|
|
180
178
|
]);
|
|
181
|
-
var _props_element_children__children, _props_element_children_, _props_element_children, _props_element, _props_element_otherProps, _props_element1, _props_element_children1, _props_element2
|
|
182
|
-
var _useEditorStore = useEditorStore(), readonly = _useEditorStore.readonly, markdownContainerRef = _useEditorStore.markdownContainerRef
|
|
179
|
+
var _props_element_children__children, _props_element_children_, _props_element_children, _props_element, _props_element_otherProps, _props_element1, _props_element_children1, _props_element2;
|
|
180
|
+
var _useEditorStore = useEditorStore(), readonly = _useEditorStore.readonly, markdownContainerRef = _useEditorStore.markdownContainerRef;
|
|
183
181
|
var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
|
|
184
182
|
var tablePath = useContext(TablePropsContext).tablePath;
|
|
185
183
|
var baseCls = getPrefixCls('agentic-md-editor-content-table');
|
|
@@ -342,68 +340,6 @@ import useScrollShadow from "./useScrollShadow";
|
|
|
342
340
|
scrollState,
|
|
343
341
|
readonly
|
|
344
342
|
]);
|
|
345
|
-
// 检查表格是否未闭合
|
|
346
|
-
var isUnclosed = ((_props_element3 = props.element) === null || _props_element3 === void 0 ? void 0 : (_props_element_otherProps1 = _props_element3.otherProps) === null || _props_element_otherProps1 === void 0 ? void 0 : _props_element_otherProps1.finish) === false;
|
|
347
|
-
// 获取编辑器更新函数 - 必须在早期返回之前调用 hooks
|
|
348
|
-
var _useMEditor = _sliced_to_array(useMEditor(props.element), 2), update = _useMEditor[1];
|
|
349
|
-
// 判断是否是最后一个节点 - 必须在早期返回之前调用 hooks
|
|
350
|
-
var isLastNode = useMemo(function() {
|
|
351
|
-
try {
|
|
352
|
-
return store.isLatestNode(props.element);
|
|
353
|
-
} catch (e) {
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
}, [
|
|
357
|
-
store,
|
|
358
|
-
props.element
|
|
359
|
-
]);
|
|
360
|
-
// 如果不是最后一个节点,且未闭合,立即设置为完成 - 必须在早期返回之前调用 hooks
|
|
361
|
-
useEffect(function() {
|
|
362
|
-
if (isUnclosed && !readonly && !isLastNode) {
|
|
363
|
-
var _props_element_otherProps, _props_element;
|
|
364
|
-
// 检查 finish 是否仍然是 false(可能已经被其他逻辑更新)
|
|
365
|
-
if (((_props_element = props.element) === null || _props_element === void 0 ? void 0 : (_props_element_otherProps = _props_element.otherProps) === null || _props_element_otherProps === void 0 ? void 0 : _props_element_otherProps.finish) === false) {
|
|
366
|
-
var _props_element1;
|
|
367
|
-
update({
|
|
368
|
-
otherProps: _object_spread_props(_object_spread({}, (_props_element1 = props.element) === null || _props_element1 === void 0 ? void 0 : _props_element1.otherProps), {
|
|
369
|
-
finish: true
|
|
370
|
-
})
|
|
371
|
-
}, props.element);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}, [
|
|
375
|
-
isUnclosed,
|
|
376
|
-
readonly,
|
|
377
|
-
isLastNode,
|
|
378
|
-
props.element,
|
|
379
|
-
update
|
|
380
|
-
]);
|
|
381
|
-
// 5 秒超时机制:如果是最后一个节点且未闭合,5 秒后自动设置为完成 - 必须在早期返回之前调用 hooks
|
|
382
|
-
useEffect(function() {
|
|
383
|
-
if (isUnclosed && !readonly && isLastNode) {
|
|
384
|
-
var timer = setTimeout(function() {
|
|
385
|
-
var _props_element_otherProps, _props_element;
|
|
386
|
-
// 检查 finish 是否仍然是 false(可能已经被其他逻辑更新)
|
|
387
|
-
if (((_props_element = props.element) === null || _props_element === void 0 ? void 0 : (_props_element_otherProps = _props_element.otherProps) === null || _props_element_otherProps === void 0 ? void 0 : _props_element_otherProps.finish) === false) {
|
|
388
|
-
var _props_element1;
|
|
389
|
-
update({
|
|
390
|
-
otherProps: _object_spread_props(_object_spread({}, (_props_element1 = props.element) === null || _props_element1 === void 0 ? void 0 : _props_element1.otherProps), {
|
|
391
|
-
finish: true
|
|
392
|
-
})
|
|
393
|
-
}, props.element);
|
|
394
|
-
}
|
|
395
|
-
}, 5000); // 5 秒超时
|
|
396
|
-
return function() {
|
|
397
|
-
clearTimeout(timer);
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
}, [
|
|
401
|
-
isUnclosed,
|
|
402
|
-
readonly,
|
|
403
|
-
isLastNode,
|
|
404
|
-
props.element,
|
|
405
|
-
update
|
|
406
|
-
]);
|
|
407
343
|
// readonly 模式渲染 - 使用优化的组件(早期返回)
|
|
408
344
|
if (readonly) {
|
|
409
345
|
return /*#__PURE__*/ React.createElement(ReadonlyTableComponent, {
|
|
@@ -419,7 +355,6 @@ import useScrollShadow from "./useScrollShadow";
|
|
|
419
355
|
style: _object_spread_props(_object_spread({}, boxShadowStyle), {
|
|
420
356
|
position: 'relative'
|
|
421
357
|
}),
|
|
422
|
-
"data-is-unclosed": isUnclosed,
|
|
423
358
|
onDragStart: function(e) {
|
|
424
359
|
// 阻止拖拽开始时的文字选择
|
|
425
360
|
e.preventDefault();
|
|
@@ -428,12 +363,5 @@ import useScrollShadow from "./useScrollShadow";
|
|
|
428
363
|
// 阻止双击选择文字
|
|
429
364
|
e.preventDefault();
|
|
430
365
|
}
|
|
431
|
-
},
|
|
432
|
-
style: {
|
|
433
|
-
position: 'absolute',
|
|
434
|
-
top: '8px',
|
|
435
|
-
right: '8px',
|
|
436
|
-
zIndex: 10
|
|
437
|
-
}
|
|
438
|
-
}, /*#__PURE__*/ React.createElement(Loading, null)), tableDom);
|
|
366
|
+
}, tableDom);
|
|
439
367
|
};
|
|
@@ -329,9 +329,9 @@ var createDefaultDom = function(domRef, baseCls, hashId, loading, selectedItems,
|
|
|
329
329
|
ref: domRef,
|
|
330
330
|
"data-tag-popup-input": true,
|
|
331
331
|
"data-no-focus": true,
|
|
332
|
-
className: classNames("".concat(baseCls, "-
|
|
332
|
+
className: classNames("".concat(baseCls, "-input"), hashId, (_obj = {
|
|
333
333
|
empty: isEmpty
|
|
334
|
-
}, _define_property(_obj, "".concat(baseCls, "-
|
|
334
|
+
}, _define_property(_obj, "".concat(baseCls, "-loading"), loading), _define_property(_obj, "".concat(baseCls, "-has-arrow"), hasItems), _obj)),
|
|
335
335
|
onMouseEnter: function() {
|
|
336
336
|
return handleMouseEnter(domRef);
|
|
337
337
|
},
|
|
@@ -341,7 +341,7 @@ var createDefaultDom = function(domRef, baseCls, hashId, loading, selectedItems,
|
|
|
341
341
|
title: placeholder,
|
|
342
342
|
contentEditable: !hasItems ? undefined : false
|
|
343
343
|
}, children, hasItems && /*#__PURE__*/ React.createElement(ChevronDown, {
|
|
344
|
-
className: classNames("".concat(baseCls, "-
|
|
344
|
+
className: classNames("".concat(baseCls, "-arrow"), hashId, {
|
|
345
345
|
empty: isEmpty,
|
|
346
346
|
open: isOpen
|
|
347
347
|
})
|
|
@@ -394,7 +394,7 @@ export var TagPopup = function(props) {
|
|
|
394
394
|
var domRef = useRef(null);
|
|
395
395
|
var suggestionConnext = useContext(SuggestionConnext);
|
|
396
396
|
var antdContext = useContext(ConfigProvider.ConfigContext);
|
|
397
|
-
var baseCls = antdContext === null || antdContext === void 0 ? void 0 : antdContext.getPrefixCls('agentic-
|
|
397
|
+
var baseCls = antdContext === null || antdContext === void 0 ? void 0 : antdContext.getPrefixCls('agentic-tag-popup');
|
|
398
398
|
var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
|
|
399
399
|
var currentNodePath = useRef();
|
|
400
400
|
useEffect(function() {
|
|
@@ -79,21 +79,23 @@ var genStyle = function(token) {
|
|
|
79
79
|
opacity: 0,
|
|
80
80
|
overflow: 'hidden',
|
|
81
81
|
userSelect: 'none'
|
|
82
|
-
},
|
|
83
|
-
'&-arrow': {
|
|
84
|
-
position: 'absolute',
|
|
85
|
-
right: '4px',
|
|
86
|
-
top: '50%',
|
|
87
|
-
transform: 'translateY(-50%)',
|
|
88
|
-
color: 'var(--color-primary-text-disabled)',
|
|
89
|
-
transition: 'transform 0.2s ease',
|
|
90
|
-
'&.open': {
|
|
91
|
-
transform: 'translateY(-50%) rotate(180deg)'
|
|
92
|
-
}
|
|
93
82
|
}
|
|
94
83
|
},
|
|
95
|
-
'&-
|
|
84
|
+
'&-arrow': {
|
|
85
|
+
position: 'absolute',
|
|
86
|
+
right: '4px',
|
|
87
|
+
top: '50%',
|
|
88
|
+
transform: 'translateY(-50%)',
|
|
89
|
+
color: 'var(--color-primary-text-disabled)',
|
|
90
|
+
transition: 'transform 0.2s ease',
|
|
91
|
+
'&.open': {
|
|
92
|
+
transform: 'translateY(-50%) rotate(180deg)'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
'&-has-arrow': {
|
|
96
96
|
paddingRight: '12px'
|
|
97
|
+
},
|
|
98
|
+
'&-loading': {
|
|
97
99
|
}
|
|
98
100
|
});
|
|
99
101
|
};
|
|
@@ -304,7 +304,7 @@ export var MElement = /*#__PURE__*/ React.memo(MElementComponent, areElementProp
|
|
|
304
304
|
};
|
|
305
305
|
var MLeafComponent = function(props) {
|
|
306
306
|
var _leaf_text, _leaf_text1, _leaf_text_replaceAll_replaceAll, _leaf_text_replaceAll, _leaf_text2, _props_fncProps, _props_leaf;
|
|
307
|
-
var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, markdownContainerRef = _useEditorStore.markdownContainerRef,
|
|
307
|
+
var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, markdownContainerRef = _useEditorStore.markdownContainerRef, setShowComment = _useEditorStore.setShowComment;
|
|
308
308
|
var context = useContext(ConfigProvider.ConfigContext);
|
|
309
309
|
var locale = useContext(I18nContext).locale;
|
|
310
310
|
var mdEditorBaseClass = context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-md-editor-content');
|
|
@@ -407,37 +407,6 @@ var MLeafComponent = function(props) {
|
|
|
407
407
|
}
|
|
408
408
|
} catch (e) {}
|
|
409
409
|
};
|
|
410
|
-
if ((leaf === null || leaf === void 0 ? void 0 : leaf.url) && readonly) {
|
|
411
|
-
var _props_leaf1, _props_leaf2;
|
|
412
|
-
var renderDom = /*#__PURE__*/ React.createElement("span", _object_spread({
|
|
413
|
-
"data-be": "link",
|
|
414
|
-
draggable: false,
|
|
415
|
-
onDragStart: dragStart,
|
|
416
|
-
"data-url": (leaf === null || leaf === void 0 ? void 0 : leaf.url) ? 'url' : undefined,
|
|
417
|
-
onClick: function(e) {
|
|
418
|
-
e.stopPropagation();
|
|
419
|
-
e.preventDefault();
|
|
420
|
-
if (e.metaKey || e.ctrlKey || readonly) {
|
|
421
|
-
if (!(leaf === null || leaf === void 0 ? void 0 : leaf.url)) return;
|
|
422
|
-
if (typeof window === 'undefined') return;
|
|
423
|
-
window.open(leaf === null || leaf === void 0 ? void 0 : leaf.url);
|
|
424
|
-
} else if (e.detail === 2) {
|
|
425
|
-
selectFormat();
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
|
-
id: leaf === null || leaf === void 0 ? void 0 : leaf.url,
|
|
429
|
-
"data-slate-inline": true
|
|
430
|
-
}, props.attributes), children);
|
|
431
|
-
if (!props.leaf.comment) return renderDom;
|
|
432
|
-
return /*#__PURE__*/ React.createElement(CommentView, {
|
|
433
|
-
id: "comment-".concat((_props_leaf1 = props.leaf) === null || _props_leaf1 === void 0 ? void 0 : _props_leaf1.id),
|
|
434
|
-
comment: props.comment,
|
|
435
|
-
hashId: props.hashId,
|
|
436
|
-
selection: leaf === null || leaf === void 0 ? void 0 : leaf.selection,
|
|
437
|
-
commentItem: ((_props_leaf2 = props.leaf) === null || _props_leaf2 === void 0 ? void 0 : _props_leaf2.comment) ? props.leaf.data : null,
|
|
438
|
-
setShowComment: setShowComment
|
|
439
|
-
}, renderDom);
|
|
440
|
-
}
|
|
441
410
|
var _obj;
|
|
442
411
|
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));
|
|
443
412
|
var dom = /*#__PURE__*/ React.createElement("span", _object_spread_props(_object_spread({}, props.attributes), {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 应用上下文属性和配置到元素(纯函数版本)
|
|
31
|
+
* @param el - 目标元素或元素数组
|
|
32
|
+
* @param contextProps - 上下文属性对象
|
|
33
|
+
* @param config - 配置对象
|
|
34
|
+
* @returns 返回应用了属性和配置的新元素
|
|
35
|
+
*/ export var applyContextPropsAndConfig = function(el, contextProps, config) {
|
|
36
|
+
var hasContextProps = Object.keys(contextProps || {}).length > 0;
|
|
37
|
+
var hasConfig = Object.keys(config || {}).length > 0;
|
|
38
|
+
if (Array.isArray(el)) {
|
|
39
|
+
return el.map(function(item) {
|
|
40
|
+
var result = _object_spread({}, item);
|
|
41
|
+
if (hasContextProps) {
|
|
42
|
+
result.contextProps = contextProps;
|
|
43
|
+
}
|
|
44
|
+
if (hasConfig && !item.otherProps) {
|
|
45
|
+
result.otherProps = config;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
var result = _object_spread({}, el);
|
|
51
|
+
if (hasContextProps) {
|
|
52
|
+
result.contextProps = contextProps;
|
|
53
|
+
}
|
|
54
|
+
if (hasConfig && !el.otherProps) {
|
|
55
|
+
result.otherProps = config;
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CustomLeaf, Elements } from '../../../el';
|
|
2
|
+
import type { ParserMarkdownToSlateNodeConfig } from '../parserMarkdownToSlateNode';
|
|
3
|
+
type ParseNodesFn = (nodes: any[], top: boolean, parent: any) => (Elements | any)[];
|
|
4
|
+
/**
|
|
5
|
+
* 处理标题节点
|
|
6
|
+
*/
|
|
7
|
+
export declare const handleHeading: (currentElement: any, parseNodes: ParseNodesFn) => {
|
|
8
|
+
type: string;
|
|
9
|
+
level: any;
|
|
10
|
+
children: any[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 处理列表节点
|
|
14
|
+
*/
|
|
15
|
+
export declare const handleList: (currentElement: any, parseNodes: ParseNodesFn) => any;
|
|
16
|
+
/**
|
|
17
|
+
* 处理脚注定义节点
|
|
18
|
+
*/
|
|
19
|
+
export declare const handleFootnoteDefinition: (currentElement: any, parseNodes: ParseNodesFn) => {
|
|
20
|
+
value: any;
|
|
21
|
+
url: any;
|
|
22
|
+
type: string;
|
|
23
|
+
identifier: any;
|
|
24
|
+
children: any[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 处理列表项节点
|
|
28
|
+
*/
|
|
29
|
+
export declare const handleListItem: (currentElement: any, parseNodes: ParseNodesFn) => {
|
|
30
|
+
type: string;
|
|
31
|
+
checked: any;
|
|
32
|
+
children: any;
|
|
33
|
+
mentions: {
|
|
34
|
+
avatar: any;
|
|
35
|
+
name: any;
|
|
36
|
+
id: string | undefined;
|
|
37
|
+
}[] | undefined;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 处理段落子节点
|
|
41
|
+
*/
|
|
42
|
+
export declare const processParagraphChildren: (currentElement: any, parseNodes: ParseNodesFn) => ({
|
|
43
|
+
text: string;
|
|
44
|
+
} | {
|
|
45
|
+
type: string;
|
|
46
|
+
children: any[];
|
|
47
|
+
})[];
|
|
48
|
+
/**
|
|
49
|
+
* 处理段落节点
|
|
50
|
+
*/
|
|
51
|
+
export declare const handleParagraph: (currentElement: any, config: any, parseNodes: ParseNodesFn) => any;
|
|
52
|
+
/**
|
|
53
|
+
* 处理引用块节点
|
|
54
|
+
*/
|
|
55
|
+
export declare const handleBlockquote: (currentElement: any, parseNodes: ParseNodesFn) => {
|
|
56
|
+
type: string;
|
|
57
|
+
children: any[];
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* 应用内联格式到叶子节点
|
|
61
|
+
*/
|
|
62
|
+
export declare const applyInlineFormatting: (leaf: CustomLeaf, currentElement: any, config?: ParserMarkdownToSlateNodeConfig) => CustomLeaf;
|
|
63
|
+
/**
|
|
64
|
+
* 处理文本和内联元素节点
|
|
65
|
+
*/
|
|
66
|
+
export declare const handleTextAndInlineElements: (currentElement: any, htmlTag: any[], parseNodes: ParseNodesFn, config?: ParserMarkdownToSlateNodeConfig) => any;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
function ownKeys(object, enumerableOnly) {
|
|
30
|
+
var keys = Object.keys(object);
|
|
31
|
+
if (Object.getOwnPropertySymbols) {
|
|
32
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
33
|
+
if (enumerableOnly) {
|
|
34
|
+
symbols = symbols.filter(function(sym) {
|
|
35
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
keys.push.apply(keys, symbols);
|
|
39
|
+
}
|
|
40
|
+
return keys;
|
|
41
|
+
}
|
|
42
|
+
function _object_spread_props(target, source) {
|
|
43
|
+
source = source != null ? source : {};
|
|
44
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
45
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
46
|
+
} else {
|
|
47
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
import { EditorUtils } from "../../utils";
|
|
54
|
+
import { createMediaNodeFromElement, decodeURIComponentUrl, findImageElement } from "./parseHtml";
|
|
55
|
+
import { handleAttachmentLink, handleLinkCard } from "./parseMedia";
|
|
56
|
+
import { handleTextAndInlineElementsPure, setFinishedProp } from "./parseText";
|
|
57
|
+
/**
|
|
58
|
+
* 处理标题节点
|
|
59
|
+
*/ export var handleHeading = function(currentElement, parseNodes) {
|
|
60
|
+
var _currentElement_children;
|
|
61
|
+
return {
|
|
62
|
+
type: 'head',
|
|
63
|
+
level: currentElement.depth,
|
|
64
|
+
children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, false, currentElement) : [
|
|
65
|
+
{
|
|
66
|
+
text: ''
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 处理列表节点
|
|
73
|
+
*/ export var handleList = function(currentElement, parseNodes) {
|
|
74
|
+
var _el_children;
|
|
75
|
+
var el = {
|
|
76
|
+
type: 'list',
|
|
77
|
+
order: currentElement.ordered,
|
|
78
|
+
start: currentElement.start,
|
|
79
|
+
finished: currentElement.finished,
|
|
80
|
+
children: parseNodes(currentElement.children, false, currentElement)
|
|
81
|
+
};
|
|
82
|
+
el.task = (_el_children = el.children) === null || _el_children === void 0 ? void 0 : _el_children.some(function(s) {
|
|
83
|
+
return typeof s.checked === 'boolean';
|
|
84
|
+
});
|
|
85
|
+
return el;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* 处理脚注定义节点
|
|
89
|
+
*/ export var handleFootnoteDefinition = function(currentElement, parseNodes) {
|
|
90
|
+
var _parseNodes, _linkNode_children;
|
|
91
|
+
var linkNode = (_parseNodes = parseNodes(currentElement.children, false, currentElement)) === null || _parseNodes === void 0 ? void 0 : _parseNodes.at(0);
|
|
92
|
+
var cellNode = linkNode === null || linkNode === void 0 ? void 0 : (_linkNode_children = linkNode.children) === null || _linkNode_children === void 0 ? void 0 : _linkNode_children.at(0);
|
|
93
|
+
return {
|
|
94
|
+
value: cellNode === null || cellNode === void 0 ? void 0 : cellNode.text,
|
|
95
|
+
url: cellNode === null || cellNode === void 0 ? void 0 : cellNode.url,
|
|
96
|
+
type: 'footnoteDefinition',
|
|
97
|
+
identifier: currentElement.identifier,
|
|
98
|
+
children: [
|
|
99
|
+
cellNode
|
|
100
|
+
]
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* 处理列表项节点
|
|
105
|
+
*/ export var handleListItem = function(currentElement, parseNodes) {
|
|
106
|
+
var _currentElement_children, _currentElement_children__children_, _currentElement_children__children, _currentElement_children_, _currentElement_children1, _currentElement_children__children1, _currentElement_children_1, _currentElement_children2;
|
|
107
|
+
var children = ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, false, currentElement) : [
|
|
108
|
+
{
|
|
109
|
+
type: 'paragraph',
|
|
110
|
+
children: [
|
|
111
|
+
{
|
|
112
|
+
text: ''
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
];
|
|
117
|
+
var mentions = undefined;
|
|
118
|
+
if (((_currentElement_children1 = currentElement.children) === null || _currentElement_children1 === void 0 ? void 0 : (_currentElement_children_ = _currentElement_children1[0]) === null || _currentElement_children_ === void 0 ? void 0 : (_currentElement_children__children = _currentElement_children_.children) === null || _currentElement_children__children === void 0 ? void 0 : (_currentElement_children__children_ = _currentElement_children__children[0]) === null || _currentElement_children__children_ === void 0 ? void 0 : _currentElement_children__children_.type) === 'link' && ((_currentElement_children2 = currentElement.children) === null || _currentElement_children2 === void 0 ? void 0 : (_currentElement_children_1 = _currentElement_children2[0]) === null || _currentElement_children_1 === void 0 ? void 0 : (_currentElement_children__children1 = _currentElement_children_1.children) === null || _currentElement_children__children1 === void 0 ? void 0 : _currentElement_children__children1.length) > 1) {
|
|
119
|
+
var _children__children, _children_;
|
|
120
|
+
var item = children === null || children === void 0 ? void 0 : (_children_ = children[0]) === null || _children_ === void 0 ? void 0 : (_children__children = _children_.children) === null || _children__children === void 0 ? void 0 : _children__children[0];
|
|
121
|
+
var label = item === null || item === void 0 ? void 0 : item.text;
|
|
122
|
+
if (label) {
|
|
123
|
+
var _item_url, _children__children1, _children_1;
|
|
124
|
+
mentions = [
|
|
125
|
+
{
|
|
126
|
+
avatar: item === null || item === void 0 ? void 0 : item.url,
|
|
127
|
+
name: label,
|
|
128
|
+
id: new URLSearchParams('?' + (item === null || item === void 0 ? void 0 : (_item_url = item.url) === null || _item_url === void 0 ? void 0 : _item_url.split('?')[1])).get('id') || undefined
|
|
129
|
+
}
|
|
130
|
+
];
|
|
131
|
+
children === null || children === void 0 ? true : (_children_1 = children[0]) === null || _children_1 === void 0 ? true : (_children__children1 = _children_1.children) === null || _children__children1 === void 0 ? true : delete _children__children1[0];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
type: 'list-item',
|
|
136
|
+
checked: currentElement.checked,
|
|
137
|
+
children: children,
|
|
138
|
+
mentions: mentions
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* 处理段落子节点
|
|
143
|
+
*/ export var processParagraphChildren = function(currentElement, parseNodes) {
|
|
144
|
+
var elements = [];
|
|
145
|
+
var textNodes = [];
|
|
146
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
147
|
+
try {
|
|
148
|
+
for(var _iterator = (currentElement.children || [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
149
|
+
var currentChild = _step.value;
|
|
150
|
+
if (currentChild.type === 'image') {
|
|
151
|
+
// 将累积的文本节点生成段落
|
|
152
|
+
if (textNodes.length) {
|
|
153
|
+
elements.push({
|
|
154
|
+
type: 'paragraph',
|
|
155
|
+
children: parseNodes(textNodes, false, currentElement)
|
|
156
|
+
});
|
|
157
|
+
textNodes = [];
|
|
158
|
+
}
|
|
159
|
+
// 添加图片节点
|
|
160
|
+
elements.push(EditorUtils.createMediaNode(decodeURIComponentUrl(currentChild === null || currentChild === void 0 ? void 0 : currentChild.url), 'image', {
|
|
161
|
+
alt: currentChild.alt,
|
|
162
|
+
finished: currentChild.finished
|
|
163
|
+
}));
|
|
164
|
+
} else if (currentChild.type === 'html') {
|
|
165
|
+
// 跳过媒体标签的结束标签
|
|
166
|
+
if (currentChild.value.match(/^<\/(img|video|iframe)>/)) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
var mediaElement = findImageElement(currentChild.value);
|
|
170
|
+
if (mediaElement) {
|
|
171
|
+
var node = createMediaNodeFromElement(mediaElement);
|
|
172
|
+
if (node) {
|
|
173
|
+
elements.push(node);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
textNodes.push({
|
|
177
|
+
type: 'html',
|
|
178
|
+
value: currentChild.value
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
textNodes.push(currentChild);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
_didIteratorError = true;
|
|
187
|
+
_iteratorError = err;
|
|
188
|
+
} finally{
|
|
189
|
+
try {
|
|
190
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
191
|
+
_iterator.return();
|
|
192
|
+
}
|
|
193
|
+
} finally{
|
|
194
|
+
if (_didIteratorError) {
|
|
195
|
+
throw _iteratorError;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// 处理剩余的文本节点
|
|
200
|
+
if (textNodes.length) {
|
|
201
|
+
elements.push({
|
|
202
|
+
type: 'paragraph',
|
|
203
|
+
children: parseNodes(textNodes, false, currentElement)
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return elements;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* 处理段落节点
|
|
210
|
+
*/ export var handleParagraph = function(currentElement, config, parseNodes) {
|
|
211
|
+
var _currentElement_children, _currentElement_children_at, _currentElement_children1;
|
|
212
|
+
// 检查是否是附件链接
|
|
213
|
+
if (((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children[0].type) === 'html' && currentElement.children[0].value.startsWith('<a')) {
|
|
214
|
+
var attachNode = handleAttachmentLink(currentElement);
|
|
215
|
+
if (attachNode) return attachNode;
|
|
216
|
+
}
|
|
217
|
+
// 检查是否是链接卡片
|
|
218
|
+
if ((currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children1 = currentElement.children) === null || _currentElement_children1 === void 0 ? void 0 : (_currentElement_children_at = _currentElement_children1.at(0)) === null || _currentElement_children_at === void 0 ? void 0 : _currentElement_children_at.type) === 'link' && config.type === 'card') {
|
|
219
|
+
return handleLinkCard(currentElement, config);
|
|
220
|
+
}
|
|
221
|
+
// 处理混合内容段落
|
|
222
|
+
return processParagraphChildren(currentElement, parseNodes);
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* 处理引用块节点
|
|
226
|
+
*/ export var handleBlockquote = function(currentElement, parseNodes) {
|
|
227
|
+
var _currentElement_children;
|
|
228
|
+
return {
|
|
229
|
+
type: 'blockquote',
|
|
230
|
+
children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, false, currentElement) : [
|
|
231
|
+
{
|
|
232
|
+
type: 'paragraph',
|
|
233
|
+
children: [
|
|
234
|
+
{
|
|
235
|
+
text: ''
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* 应用内联格式到叶子节点
|
|
244
|
+
*/ export var applyInlineFormatting = function(leaf, currentElement, config) {
|
|
245
|
+
var result = _object_spread({}, leaf);
|
|
246
|
+
var elementType = currentElement.type;
|
|
247
|
+
var finished = currentElement.finished;
|
|
248
|
+
if (elementType === 'strong') {
|
|
249
|
+
return setFinishedProp(_object_spread_props(_object_spread({}, result), {
|
|
250
|
+
bold: true
|
|
251
|
+
}), finished);
|
|
252
|
+
}
|
|
253
|
+
if (elementType === 'emphasis') {
|
|
254
|
+
return setFinishedProp(_object_spread_props(_object_spread({}, result), {
|
|
255
|
+
italic: true
|
|
256
|
+
}), finished);
|
|
257
|
+
}
|
|
258
|
+
if (elementType === 'delete') {
|
|
259
|
+
result.strikethrough = true;
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
if (elementType === 'link') {
|
|
263
|
+
try {
|
|
264
|
+
result.url = currentElement === null || currentElement === void 0 ? void 0 : currentElement.url;
|
|
265
|
+
var shouldOpenInNewTab = (config === null || config === void 0 ? void 0 : config.openLinksInNewTab) || finished === false;
|
|
266
|
+
if (shouldOpenInNewTab) {
|
|
267
|
+
if (!result.otherProps) {
|
|
268
|
+
result.otherProps = {};
|
|
269
|
+
}
|
|
270
|
+
result.otherProps.target = '_blank';
|
|
271
|
+
result.otherProps.rel = 'noopener noreferrer';
|
|
272
|
+
if (finished === false) {
|
|
273
|
+
result.otherProps.finished = finished;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
} catch (e) {
|
|
277
|
+
result.url = currentElement === null || currentElement === void 0 ? void 0 : currentElement.url;
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* 处理文本和内联元素节点
|
|
285
|
+
*/ export var handleTextAndInlineElements = function(currentElement, htmlTag, parseNodes, config) {
|
|
286
|
+
return handleTextAndInlineElementsPure(currentElement, htmlTag, function(leaf, element) {
|
|
287
|
+
return applyInlineFormatting(leaf, element, config);
|
|
288
|
+
}, parseNodes);
|
|
289
|
+
};
|