@ant-design/agentic-ui 2.0.12 → 2.0.13
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.
|
@@ -104,6 +104,23 @@ var SlateMarkdownEditor = (props) => {
|
|
|
104
104
|
readonly,
|
|
105
105
|
setDomRect
|
|
106
106
|
} = useEditorStore();
|
|
107
|
+
const lazyElementIndexRef = useRef(0);
|
|
108
|
+
const hasResetIndexRef = useRef(false);
|
|
109
|
+
const countLazyElements = useCallback((nodes) => {
|
|
110
|
+
let count = 0;
|
|
111
|
+
const traverse = (nodeList) => {
|
|
112
|
+
nodeList.forEach((node) => {
|
|
113
|
+
if (node.type !== "table-cell" && node.type !== "table-row") {
|
|
114
|
+
count++;
|
|
115
|
+
}
|
|
116
|
+
if (node.children && Array.isArray(node.children)) {
|
|
117
|
+
traverse(node.children);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
traverse(nodes);
|
|
122
|
+
return count;
|
|
123
|
+
}, []);
|
|
107
124
|
const changedMark = useRef(false);
|
|
108
125
|
const value = useRef([EditorUtils.p]);
|
|
109
126
|
const nodeRef = useRef();
|
|
@@ -599,6 +616,13 @@ var SlateMarkdownEditor = (props) => {
|
|
|
599
616
|
const elementRenderElement = useCallback(
|
|
600
617
|
(eleProps) => {
|
|
601
618
|
var _a2, _b2, _c2, _d2, _e;
|
|
619
|
+
if (!hasResetIndexRef.current) {
|
|
620
|
+
lazyElementIndexRef.current = 0;
|
|
621
|
+
hasResetIndexRef.current = true;
|
|
622
|
+
Promise.resolve().then(() => {
|
|
623
|
+
hasResetIndexRef.current = false;
|
|
624
|
+
});
|
|
625
|
+
}
|
|
602
626
|
const defaultDom = /* @__PURE__ */ React.createElement(
|
|
603
627
|
ErrorBoundary,
|
|
604
628
|
{
|
|
@@ -634,19 +658,27 @@ var SlateMarkdownEditor = (props) => {
|
|
|
634
658
|
if (eleProps.element.type === "table-cell" || eleProps.element.type === "table-row") {
|
|
635
659
|
return renderedDom;
|
|
636
660
|
}
|
|
661
|
+
const currentIndex = lazyElementIndexRef.current;
|
|
662
|
+
lazyElementIndexRef.current += 1;
|
|
663
|
+
const totalElements = countLazyElements(value.current);
|
|
637
664
|
return /* @__PURE__ */ React.createElement(
|
|
638
665
|
LazyElement,
|
|
639
666
|
{
|
|
640
667
|
placeholderHeight: (_c2 = props.lazy) == null ? void 0 : _c2.placeholderHeight,
|
|
641
668
|
rootMargin: (_d2 = props.lazy) == null ? void 0 : _d2.rootMargin,
|
|
642
|
-
renderPlaceholder: (_e = props.lazy) == null ? void 0 : _e.renderPlaceholder
|
|
669
|
+
renderPlaceholder: (_e = props.lazy) == null ? void 0 : _e.renderPlaceholder,
|
|
670
|
+
elementInfo: {
|
|
671
|
+
type: eleProps.element.type,
|
|
672
|
+
index: currentIndex,
|
|
673
|
+
total: totalElements
|
|
674
|
+
}
|
|
643
675
|
},
|
|
644
676
|
renderedDom
|
|
645
677
|
);
|
|
646
678
|
}
|
|
647
679
|
return renderedDom;
|
|
648
680
|
},
|
|
649
|
-
[props.eleItemRender, props.lazy, plugins, readonly]
|
|
681
|
+
[props.eleItemRender, props.lazy, plugins, readonly, countLazyElements]
|
|
650
682
|
);
|
|
651
683
|
const renderMarkdownLeaf = useRefFunction((leafComponentProps) => {
|
|
652
684
|
const defaultDom = /* @__PURE__ */ React.createElement(
|
|
@@ -3,6 +3,15 @@ import React from 'react';
|
|
|
3
3
|
* LazyElement 组件属性
|
|
4
4
|
*/
|
|
5
5
|
export interface LazyElementProps {
|
|
6
|
+
/** 元素在文档中的位置信息 */
|
|
7
|
+
elementInfo: {
|
|
8
|
+
/** 元素类型 */
|
|
9
|
+
type: string;
|
|
10
|
+
/** 元素在文档中的索引 */
|
|
11
|
+
index: number;
|
|
12
|
+
/** 元素总数量 */
|
|
13
|
+
total: number;
|
|
14
|
+
};
|
|
6
15
|
/** 子元素 */
|
|
7
16
|
children: React.ReactNode;
|
|
8
17
|
/** 占位符高度,默认 100px */
|
|
@@ -20,7 +29,7 @@ export interface LazyElementProps {
|
|
|
20
29
|
/** 元素是否即将进入视口 */
|
|
21
30
|
isIntersecting: boolean;
|
|
22
31
|
/** 元素在文档中的位置信息 */
|
|
23
|
-
elementInfo
|
|
32
|
+
elementInfo: {
|
|
24
33
|
/** 元素类型 */
|
|
25
34
|
type: string;
|
|
26
35
|
/** 元素在文档中的索引 */
|
|
@@ -22,7 +22,8 @@ var LazyElement = ({
|
|
|
22
22
|
placeholderHeight = 25,
|
|
23
23
|
rootMargin = "200px",
|
|
24
24
|
placeholderStyle,
|
|
25
|
-
renderPlaceholder
|
|
25
|
+
renderPlaceholder,
|
|
26
|
+
elementInfo
|
|
26
27
|
}) => {
|
|
27
28
|
const containerRef = useRef(null);
|
|
28
29
|
const [isVisible, setIsVisible] = useState(false);
|
|
@@ -63,7 +64,8 @@ var LazyElement = ({
|
|
|
63
64
|
return /* @__PURE__ */ React.createElement("div", { ref: containerRef, "aria-hidden": "true" }, renderPlaceholder({
|
|
64
65
|
height: placeholderHeight,
|
|
65
66
|
style: computedPlaceholderStyle,
|
|
66
|
-
isIntersecting
|
|
67
|
+
isIntersecting,
|
|
68
|
+
elementInfo
|
|
67
69
|
}));
|
|
68
70
|
}
|
|
69
71
|
return /* @__PURE__ */ React.createElement(
|