@ant-design/agentic-ui 2.25.0 → 2.27.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.
@@ -1058,7 +1058,8 @@ var defaultAllowedTypes = [
1058
1058
  comment: props === null || props === void 0 ? void 0 : props.comment,
1059
1059
  children: leafComponentProps.children,
1060
1060
  hashId: hashId,
1061
- tagInputProps: props.tagInputProps
1061
+ tagInputProps: props.tagInputProps,
1062
+ linkConfig: props.linkConfig
1062
1063
  }));
1063
1064
  if (!props.leafRender) return defaultDom;
1064
1065
  return props.leafRender(_object_spread_props(_object_spread({}, leafComponentProps), {
@@ -279,9 +279,19 @@ import { getMediaType } from "../../utils/dom";
279
279
  // 图片加载失败时显示为链接
280
280
  if (error) {
281
281
  return /*#__PURE__*/ React.createElement("a", {
282
- href: props.src,
283
282
  target: "_blank",
284
283
  rel: "noopener noreferrer",
284
+ onClick: function(e) {
285
+ var _editorProps_linkConfig, _editorProps_linkConfig1;
286
+ e.stopPropagation();
287
+ e.preventDefault();
288
+ if ((_editorProps_linkConfig = editorProps.linkConfig) === null || _editorProps_linkConfig === void 0 ? void 0 : _editorProps_linkConfig.onClick) {
289
+ if (editorProps.linkConfig.onClick(props.src || '') === false) {
290
+ return;
291
+ }
292
+ }
293
+ window.open(props.src, (editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_linkConfig1 = editorProps.linkConfig) === null || _editorProps_linkConfig1 === void 0 ? void 0 : _editorProps_linkConfig1.openInNewTab) ? '_blank' : '_self');
294
+ },
285
295
  style: {
286
296
  color: '#1890ff',
287
297
  textDecoration: 'underline',
@@ -382,6 +382,7 @@ export function Media(param) {
382
382
  var _state, _state1;
383
383
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
384
384
  var _useSelStatus = _sliced_to_array(useSelStatus(element), 2), _ = _useSelStatus[0], path = _useSelStatus[1];
385
+ var editorProps = useEditorStore().editorProps;
385
386
  var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, readonly = _useEditorStore.readonly;
386
387
  var locale = useContext(I18nContext).locale;
387
388
  var htmlRef = React.useRef(null);
@@ -594,11 +595,23 @@ export function Media(param) {
594
595
  });
595
596
  }
596
597
  if (!state().loadSuccess) {
597
- var _state1, _state2;
598
+ var _state1;
598
599
  return /*#__PURE__*/ React.createElement("a", {
599
- href: ((_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url) || (element === null || element === void 0 ? void 0 : element.url),
600
600
  target: "_blank",
601
601
  rel: "noopener noreferrer",
602
+ onClick: function(e) {
603
+ var _state, _editorProps_linkConfig, _state1, _editorProps_linkConfig1;
604
+ if (!((_state = state()) === null || _state === void 0 ? void 0 : _state.url)) return;
605
+ e.stopPropagation();
606
+ e.preventDefault();
607
+ if ((_editorProps_linkConfig = editorProps.linkConfig) === null || _editorProps_linkConfig === void 0 ? void 0 : _editorProps_linkConfig.onClick) {
608
+ var _state2;
609
+ if (editorProps.linkConfig.onClick(((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || '') === false) {
610
+ return;
611
+ }
612
+ }
613
+ window.open((_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url, (editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_linkConfig1 = editorProps.linkConfig) === null || _editorProps_linkConfig1 === void 0 ? void 0 : _editorProps_linkConfig1.openInNewTab) ? '_blank' : '_self');
614
+ },
602
615
  style: {
603
616
  color: '#1890ff',
604
617
  textDecoration: 'underline',
@@ -616,7 +629,7 @@ export function Media(param) {
616
629
  style: {
617
630
  color: '#faad14'
618
631
  }
619
- }), element.alt || ((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || (element === null || element === void 0 ? void 0 : element.url) || '视频链接');
632
+ }), element.alt || ((_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url) || (element === null || element === void 0 ? void 0 : element.url) || '视频链接');
620
633
  }
621
634
  return /*#__PURE__*/ React.createElement("video", {
622
635
  "data-testid": "video-element",
@@ -645,7 +658,7 @@ export function Media(param) {
645
658
  });
646
659
  }
647
660
  if (state().type === 'audio') {
648
- var _state3;
661
+ var _state2;
649
662
  // 如果是不完整状态
650
663
  if (element.finished === false) {
651
664
  // 如果 5 秒后仍未完成,显示为文本
@@ -688,11 +701,23 @@ export function Media(param) {
688
701
  }, rawMarkdown || (element === null || element === void 0 ? void 0 : element.alt) || '音频加载中...'));
689
702
  }
690
703
  if (!state().loadSuccess) {
691
- var _state4, _state5;
704
+ var _state3;
692
705
  return /*#__PURE__*/ React.createElement("a", {
693
- href: ((_state4 = state()) === null || _state4 === void 0 ? void 0 : _state4.url) || (element === null || element === void 0 ? void 0 : element.url),
694
706
  target: "_blank",
695
707
  rel: "noopener noreferrer",
708
+ onClick: function(e) {
709
+ var _state, _editorProps_linkConfig, _state1, _editorProps_linkConfig1;
710
+ if (!(((_state = state()) === null || _state === void 0 ? void 0 : _state.url) || (element === null || element === void 0 ? void 0 : element.url))) return;
711
+ e.stopPropagation();
712
+ e.preventDefault();
713
+ if ((_editorProps_linkConfig = editorProps.linkConfig) === null || _editorProps_linkConfig === void 0 ? void 0 : _editorProps_linkConfig.onClick) {
714
+ var _state2;
715
+ if (editorProps.linkConfig.onClick(((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || (element === null || element === void 0 ? void 0 : element.url) || '') === false) {
716
+ return;
717
+ }
718
+ }
719
+ window.open(((_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url) || (element === null || element === void 0 ? void 0 : element.url), (editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_linkConfig1 = editorProps.linkConfig) === null || _editorProps_linkConfig1 === void 0 ? void 0 : _editorProps_linkConfig1.openInNewTab) ? '_blank' : '_self');
720
+ },
696
721
  style: {
697
722
  color: '#1890ff',
698
723
  textDecoration: 'underline',
@@ -710,7 +735,7 @@ export function Media(param) {
710
735
  style: {
711
736
  color: '#faad14'
712
737
  }
713
- }), element.alt || ((_state5 = state()) === null || _state5 === void 0 ? void 0 : _state5.url) || (element === null || element === void 0 ? void 0 : element.url) || '音频链接');
738
+ }), element.alt || ((_state3 = state()) === null || _state3 === void 0 ? void 0 : _state3.url) || (element === null || element === void 0 ? void 0 : element.url) || '音频链接');
714
739
  }
715
740
  return /*#__PURE__*/ React.createElement("audio", {
716
741
  "data-testid": "audio-element",
@@ -719,7 +744,7 @@ export function Media(param) {
719
744
  width: '100%',
720
745
  height: 'auto'
721
746
  },
722
- src: ((_state3 = state()) === null || _state3 === void 0 ? void 0 : _state3.url) || '',
747
+ src: ((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || '',
723
748
  onError: function() {
724
749
  var _state;
725
750
  console.warn('Audio failed to load:', (_state = state()) === null || _state === void 0 ? void 0 : _state.url);
@@ -730,7 +755,7 @@ export function Media(param) {
730
755
  }, "Your browser does not support the", /*#__PURE__*/ React.createElement("code", null, "audio"), " element.");
731
756
  }
732
757
  if (state().type === 'attachment') {
733
- var _state6, _element_alt, _element_alt1, _element_otherProps1, _element_otherProps_collaborators, _element_otherProps2, _element_otherProps3;
758
+ var _state4, _element_alt, _element_alt1, _element_otherProps1, _element_otherProps_collaborators, _element_otherProps2, _element_otherProps3;
734
759
  return /*#__PURE__*/ React.createElement("div", {
735
760
  style: {
736
761
  padding: 12,
@@ -762,7 +787,7 @@ export function Media(param) {
762
787
  minWidth: 0
763
788
  }
764
789
  }, /*#__PURE__*/ React.createElement("a", {
765
- href: (_state6 = state()) === null || _state6 === void 0 ? void 0 : _state6.url,
790
+ href: (_state4 = state()) === null || _state4 === void 0 ? void 0 : _state4.url,
766
791
  style: {
767
792
  overflow: 'ellipsis',
768
793
  textOverflow: 'ellipsis',
@@ -21,5 +21,6 @@ export declare const MLeaf: React.MemoExoticComponent<(props: RenderLeafProps &
21
21
  comment: MarkdownEditorProps['comment'];
22
22
  fncProps: MarkdownEditorProps['fncProps'];
23
23
  tagInputProps: MarkdownEditorProps['tagInputProps'];
24
+ linkConfig: MarkdownEditorProps['linkConfig'];
24
25
  }) => React.JSX.Element>;
25
26
  export { Blockquote, Break, Code, Head, Hr, InlineKatex, Katex, List, ListItem, Media, Mermaid, Paragraph, Schema, };
@@ -455,7 +455,7 @@ var MLeafComponent = function(props) {
455
455
  draggable: false,
456
456
  onDragStart: dragStart,
457
457
  onClick: function(e) {
458
- var _props_fncProps;
458
+ var _props_fncProps, _props_linkConfig, _props_linkConfig1, _props_linkConfig2;
459
459
  // 在手机上,如果是 fnc,阻止点击事件(使用长按代替)
460
460
  if (isMobile && hasFnc) {
461
461
  e.preventDefault();
@@ -467,9 +467,19 @@ var MLeafComponent = function(props) {
467
467
  if ((_props_fncProps = props.fncProps) === null || _props_fncProps === void 0 ? void 0 : _props_fncProps.onOriginUrlClick) {
468
468
  props.fncProps.onOriginUrlClick(leaf === null || leaf === void 0 ? void 0 : leaf.identifier);
469
469
  }
470
- if (leaf.url) {
470
+ if ((_props_linkConfig = props.linkConfig) === null || _props_linkConfig === void 0 ? void 0 : _props_linkConfig.onClick) {
471
+ var _props_linkConfig3;
472
+ var res = (_props_linkConfig3 = props.linkConfig) === null || _props_linkConfig3 === void 0 ? void 0 : _props_linkConfig3.onClick(leaf.url);
473
+ if (res === false) {
474
+ return;
475
+ }
476
+ }
477
+ if (leaf.url && ((_props_linkConfig1 = props.linkConfig) === null || _props_linkConfig1 === void 0 ? void 0 : _props_linkConfig1.openInNewTab) !== false) {
471
478
  window.open(leaf.url, '_blank');
472
479
  }
480
+ if (leaf.url && ((_props_linkConfig2 = props.linkConfig) === null || _props_linkConfig2 === void 0 ? void 0 : _props_linkConfig2.openInNewTab) === false) {
481
+ window.location.href = leaf.url;
482
+ }
473
483
  },
474
484
  onTouchStart: hasFnc ? handleTouchStart : undefined,
475
485
  onTouchEnd: hasFnc ? handleTouchEnd : undefined,
@@ -1381,7 +1381,8 @@ export var EditorStoreContext = createContext(null);
1381
1381
  value: /**
1382
1382
  * 判断是否是简单文本单元格
1383
1383
  */ function isSimpleTextCell(newChildren, oldChildren) {
1384
- return newChildren.length === 1 && oldChildren.length === 1 && typeof newChildren[0].text === 'string' && typeof oldChildren[0].text === 'string';
1384
+ var _newChildren_, _oldChildren_;
1385
+ return newChildren.length === 1 && oldChildren.length === 1 && typeof (newChildren === null || newChildren === void 0 ? void 0 : (_newChildren_ = newChildren[0]) === null || _newChildren_ === void 0 ? void 0 : _newChildren_.text) === 'string' && typeof (oldChildren === null || oldChildren === void 0 ? void 0 : (_oldChildren_ = oldChildren[0]) === null || _oldChildren_ === void 0 ? void 0 : _oldChildren_.text) === 'string';
1385
1386
  }
1386
1387
  },
1387
1388
  {
@@ -1389,14 +1390,16 @@ export var EditorStoreContext = createContext(null);
1389
1390
  value: /**
1390
1391
  * 比较简单文本单元格
1391
1392
  */ function compareSimpleTextCell(newChildren, oldChildren, path, operations) {
1393
+ var _newChildren_, _oldChildren_;
1392
1394
  // 只有文本内容变化
1393
- if (newChildren[0].text !== oldChildren[0].text) {
1395
+ if ((newChildren === null || newChildren === void 0 ? void 0 : (_newChildren_ = newChildren[0]) === null || _newChildren_ === void 0 ? void 0 : _newChildren_.text) !== (oldChildren === null || oldChildren === void 0 ? void 0 : (_oldChildren_ = oldChildren[0]) === null || _oldChildren_ === void 0 ? void 0 : _oldChildren_.text)) {
1396
+ var _newChildren_1;
1394
1397
  operations.push({
1395
1398
  type: 'text',
1396
1399
  path: _to_consumable_array(path).concat([
1397
1400
  0
1398
1401
  ]),
1399
- text: newChildren[0].text,
1402
+ text: (newChildren === null || newChildren === void 0 ? void 0 : (_newChildren_1 = newChildren[0]) === null || _newChildren_1 === void 0 ? void 0 : _newChildren_1.text) || '',
1400
1403
  priority: 8
1401
1404
  });
1402
1405
  }
@@ -302,6 +302,12 @@ export type MarkdownEditorProps = {
302
302
  * 自定义 markdown 转 HTML 的 remark 插件配置,格式类似 Babel 插件数组
303
303
  */
304
304
  markdownToHtmlOptions?: MarkdownToHtmlOptions;
305
+ linkConfig?: {
306
+ /** 是否在新标签页打开链接 */
307
+ openInNewTab?: boolean;
308
+ /** 自定义链接渲染函数 */
309
+ onClick?: (url?: string) => boolean | void;
310
+ };
305
311
  /**
306
312
  * 其他属性
307
313
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/agentic-ui",
3
- "version": "2.25.0",
3
+ "version": "2.27.0",
4
4
  "description": "面向智能体的 UI 组件库,提供多步推理可视化、工具调用展示、任务执行协同等 Agentic UI 能力",
5
5
  "repository": "git@github.com:ant-design/agentic-ui.git",
6
6
  "license": "MIT",