@ant-design/agentic-ui 2.27.6 → 2.27.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.
Files changed (68) hide show
  1. package/dist/Bubble/Bubble.js +7 -1
  2. package/dist/Components/effects/EffectPlayer.js +4 -5
  3. package/dist/History/components/HistoryItem.js +13 -30
  4. package/dist/History/components/LoadMoreComponent.js +3 -5
  5. package/dist/History/components/NewChatComponent.js +6 -10
  6. package/dist/History/menu.js +6 -12
  7. package/dist/MarkdownEditor/editor/Editor.js +5 -11
  8. package/dist/MarkdownEditor/editor/components/MediaErrorLink.d.ts +16 -0
  9. package/dist/MarkdownEditor/editor/components/MediaErrorLink.js +90 -0
  10. package/dist/MarkdownEditor/editor/elements/{Blockquote.d.ts → Blockquote/index.d.ts} +1 -1
  11. package/dist/MarkdownEditor/editor/elements/{Blockquote.js → Blockquote/index.js} +1 -1
  12. package/dist/MarkdownEditor/editor/elements/{FootnoteDefinition.d.ts → FootnoteDefinition/index.d.ts} +1 -1
  13. package/dist/MarkdownEditor/editor/elements/{FootnoteDefinition.js → FootnoteDefinition/index.js} +2 -2
  14. package/dist/MarkdownEditor/editor/elements/{FootnoteReference.d.ts → FootnoteReference/index.d.ts} +1 -1
  15. package/dist/MarkdownEditor/editor/elements/{FootnoteReference.js → FootnoteReference/index.js} +3 -3
  16. package/dist/MarkdownEditor/editor/elements/{Head.d.ts → Head/index.d.ts} +1 -1
  17. package/dist/MarkdownEditor/editor/elements/{Head.js → Head/index.js} +4 -4
  18. package/dist/MarkdownEditor/editor/elements/Image/index.d.ts +11 -10
  19. package/dist/MarkdownEditor/editor/elements/Image/index.js +55 -148
  20. package/dist/MarkdownEditor/editor/elements/{Media.d.ts → Media/index.d.ts} +1 -1
  21. package/dist/MarkdownEditor/editor/elements/{Media.js → Media/index.js} +36 -107
  22. package/dist/MarkdownEditor/editor/elements/Mermaid/index.d.ts +3 -0
  23. package/dist/MarkdownEditor/editor/elements/{Mermaid.js → Mermaid/index.js} +13 -28
  24. package/dist/MarkdownEditor/editor/elements/Mermaid/style.d.ts +10 -0
  25. package/dist/MarkdownEditor/editor/elements/Mermaid/style.js +144 -0
  26. package/dist/MarkdownEditor/editor/elements/{Paragraph.d.ts → Paragraph/index.d.ts} +1 -1
  27. package/dist/MarkdownEditor/editor/elements/{Paragraph.js → Paragraph/index.js} +4 -4
  28. package/dist/MarkdownEditor/editor/elements/{Schema.js → Schema/index.js} +3 -3
  29. package/dist/MarkdownInputField/AttachmentButton/AttachmentButtonPopover.js +8 -13
  30. package/dist/MarkdownInputField/MarkdownInputField.js +4 -7
  31. package/dist/Plugins/code/components/AceEditor.js +5 -14
  32. package/dist/Plugins/mermaid/Mermaid.d.ts +0 -7
  33. package/dist/Plugins/mermaid/Mermaid.js +4 -501
  34. package/dist/Plugins/mermaid/MermaidFallback.d.ts +5 -0
  35. package/dist/Plugins/mermaid/MermaidFallback.js +21 -0
  36. package/dist/Plugins/mermaid/MermaidRendererImpl.d.ts +9 -0
  37. package/dist/Plugins/mermaid/MermaidRendererImpl.js +39 -0
  38. package/dist/Plugins/mermaid/style.d.ts +10 -0
  39. package/dist/Plugins/mermaid/style.js +219 -0
  40. package/dist/Plugins/mermaid/types.d.ts +1 -0
  41. package/dist/Plugins/mermaid/types.js +1 -0
  42. package/dist/Plugins/mermaid/useMermaidRender.d.ts +8 -0
  43. package/dist/Plugins/mermaid/useMermaidRender.js +303 -0
  44. package/dist/Plugins/mermaid/utils.d.ts +14 -0
  45. package/dist/Plugins/mermaid/utils.js +223 -0
  46. package/dist/TaskList/index.js +4 -8
  47. package/dist/ToolUseBar/BarItem/Content.js +5 -6
  48. package/dist/ToolUseBar/BarItem/index.js +6 -14
  49. package/dist/ToolUseBar/index.js +6 -13
  50. package/dist/ToolUseBarThink/index.js +6 -11
  51. package/dist/Utils/debugUtils.d.ts +9 -0
  52. package/dist/Utils/debugUtils.js +42 -0
  53. package/dist/index.d.ts +1 -0
  54. package/package.json +1 -1
  55. package/dist/MarkdownEditor/editor/elements/Mermaid.d.ts +0 -3
  56. /package/dist/MarkdownEditor/editor/elements/{Break.d.ts → Break/index.d.ts} +0 -0
  57. /package/dist/MarkdownEditor/editor/elements/{Break.js → Break/index.js} +0 -0
  58. /package/dist/MarkdownEditor/editor/elements/{Code.d.ts → Code/index.d.ts} +0 -0
  59. /package/dist/MarkdownEditor/editor/elements/{Code.js → Code/index.js} +0 -0
  60. /package/dist/MarkdownEditor/editor/elements/{ErrorBoundary.d.ts → ErrorBoundary/index.d.ts} +0 -0
  61. /package/dist/MarkdownEditor/editor/elements/{ErrorBoundary.js → ErrorBoundary/index.js} +0 -0
  62. /package/dist/MarkdownEditor/editor/elements/{Hr.d.ts → Hr/index.d.ts} +0 -0
  63. /package/dist/MarkdownEditor/editor/elements/{Hr.js → Hr/index.js} +0 -0
  64. /package/dist/MarkdownEditor/editor/elements/{InlineKatex.d.ts → InlineKatex/index.d.ts} +0 -0
  65. /package/dist/MarkdownEditor/editor/elements/{InlineKatex.js → InlineKatex/index.js} +0 -0
  66. /package/dist/MarkdownEditor/editor/elements/{Katex.d.ts → Katex/index.d.ts} +0 -0
  67. /package/dist/MarkdownEditor/editor/elements/{Katex.js → Katex/index.js} +0 -0
  68. /package/dist/MarkdownEditor/editor/elements/{Schema.d.ts → Schema/index.d.ts} +0 -0
@@ -247,92 +247,62 @@ function _ts_generator(thisArg, body) {
247
247
  };
248
248
  }
249
249
  }
250
- import { BlockOutlined, DeleteFilled, ExclamationCircleOutlined, LoadingOutlined } from "@ant-design/icons";
250
+ import { BlockOutlined, DeleteFilled, LoadingOutlined } from "@ant-design/icons";
251
251
  import { Image, Modal, Popover, Skeleton, Space } from "antd";
252
- import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
252
+ import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
253
+ import { useRefFunction } from "../../../../Hooks/useRefFunction";
253
254
  import { useDebounceFn } from "@ant-design/pro-components";
254
- import { SquareArrowUpRight } from "@sofa-design/icons";
255
255
  import { Rnd } from "react-rnd";
256
256
  import { Path, Transforms } from "slate";
257
257
  import { ActionIconBox } from "../../../../Components/ActionIconBox";
258
258
  import { I18nContext } from "../../../../I18n";
259
259
  import { useSelStatus } from "../../../hooks/editor";
260
+ import { MediaErrorLink } from "../../components/MediaErrorLink";
260
261
  import { useEditorStore } from "../../store";
261
262
  import { useGetSetState } from "../../utils";
262
263
  import { getMediaType } from "../../utils/dom";
263
- /**
264
- * 图片组件,带有错误处理功能
265
- * 如果图片加载失败,将显示可点击的链接
266
- *
267
- * @component
268
- * @param props - 图片属性,继承自 ImageProps 接口
269
- * @param props.src - 图片的源地址
270
- * @returns 返回一个图片组件,如果加载失败则返回一个链接
271
- *
272
- * @example
273
- * ```tsx
274
- * <ImageAndError src="https://example.com/image.jpg" alt="示例图片" />
275
- * ```
276
- */ export var ImageAndError = function(props) {
264
+ export var ReadonlyImage = function(param) {
265
+ var src = param.src, alt = param.alt, width = param.width, height = param.height, crossOrigin = param.crossOrigin;
277
266
  var _editorProps_image;
278
267
  var editorProps = useEditorStore().editorProps;
279
268
  var _React_useState = _sliced_to_array(React.useState(false), 2), error = _React_useState[0], setError = _React_useState[1];
280
- console.log(editorProps);
281
269
  // 图片加载失败时显示为链接
282
270
  if (error) {
283
- return /*#__PURE__*/ React.createElement("span", {
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
- },
295
- style: {
296
- color: '#1890ff',
297
- textDecoration: 'underline',
298
- wordBreak: 'break-all',
299
- display: 'inline-flex',
300
- alignItems: 'center',
301
- gap: '8px',
302
- maxWidth: '100%',
303
- padding: '8px 12px',
304
- border: '1px dashed #d9d9d9',
305
- borderRadius: '6px',
306
- backgroundColor: '#fafafa'
307
- }
308
- }, /*#__PURE__*/ React.createElement(ExclamationCircleOutlined, {
309
- style: {
310
- color: '#faad14'
311
- }
312
- }), props.alt || props.src || '图片链接', /*#__PURE__*/ React.createElement(SquareArrowUpRight, null));
271
+ return /*#__PURE__*/ React.createElement(MediaErrorLink, {
272
+ url: src,
273
+ displayText: alt || src || '图片链接'
274
+ });
313
275
  }
276
+ var imageProps = {
277
+ src: src,
278
+ alt: alt || 'image',
279
+ width: width ? Number(width) || width : 400,
280
+ height: height,
281
+ preview: {
282
+ getContainer: function() {
283
+ return document.body;
284
+ }
285
+ },
286
+ referrerPolicy: 'no-referrer',
287
+ crossOrigin: crossOrigin,
288
+ draggable: false,
289
+ style: {
290
+ maxWidth: '100%',
291
+ height: 'auto',
292
+ display: 'block'
293
+ },
294
+ onError: function() {
295
+ setError(true);
296
+ }
297
+ };
314
298
  if (editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_image = editorProps.image) === null || _editorProps_image === void 0 ? void 0 : _editorProps_image.render) {
315
299
  var _editorProps_image_render, _editorProps_image1;
316
- return (_editorProps_image_render = (_editorProps_image1 = editorProps.image).render) === null || _editorProps_image_render === void 0 ? void 0 : _editorProps_image_render.call(_editorProps_image1, _object_spread_props(_object_spread({}, props), {
317
- onError: function() {
318
- setError(true);
319
- }
320
- }), /*#__PURE__*/ React.createElement(Image, _object_spread_props(_object_spread({}, props), {
321
- width: Number(props.width) || props.width || 400,
322
- onError: function() {
323
- setError(true);
324
- }
325
- })));
300
+ return (_editorProps_image_render = (_editorProps_image1 = editorProps.image).render) === null || _editorProps_image_render === void 0 ? void 0 : _editorProps_image_render.call(_editorProps_image1, imageProps, /*#__PURE__*/ React.createElement(Image, imageProps));
326
301
  }
327
302
  return /*#__PURE__*/ React.createElement("div", {
328
303
  "data-testid": "image-container",
329
304
  "data-be": "image-container"
330
- }, /*#__PURE__*/ React.createElement(Image, _object_spread_props(_object_spread({}, props), {
331
- width: Number(props.width) || props.width || 400,
332
- onError: function() {
333
- setError(true);
334
- }
335
- })));
305
+ }, /*#__PURE__*/ React.createElement(Image, imageProps));
336
306
  };
337
307
  /**
338
308
  * 修复图片大小的问题
@@ -345,7 +315,6 @@ import { getMediaType } from "../../utils/dom";
345
315
  "selected",
346
316
  "defaultSize"
347
317
  ]);
348
- var editorProps = useEditorStore().editorProps;
349
318
  var _React_useState = _sliced_to_array(React.useState(true), 2), loading = _React_useState[0], setLoading = _React_useState[1];
350
319
  var _React_useState1 = _sliced_to_array(React.useState(false), 2), error = _React_useState1[0], setError = _React_useState1[1];
351
320
  var radio = useRef(1);
@@ -366,38 +335,14 @@ import { getMediaType } from "../../utils/dom";
366
335
  }, 160);
367
336
  // 如果图片加载失败,显示为链接
368
337
  if (error) {
369
- return /*#__PURE__*/ React.createElement("span", {
370
- onClick: function(e) {
371
- var _editorProps_linkConfig, _editorProps_linkConfig1;
372
- e.stopPropagation();
373
- e.preventDefault();
374
- if ((_editorProps_linkConfig = editorProps.linkConfig) === null || _editorProps_linkConfig === void 0 ? void 0 : _editorProps_linkConfig.onClick) {
375
- if (editorProps.linkConfig.onClick(props.src || '') === false) {
376
- return;
377
- }
378
- }
379
- 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');
380
- },
338
+ return /*#__PURE__*/ React.createElement(MediaErrorLink, {
339
+ url: props.src,
340
+ displayText: props.alt || props.src || '图片链接',
381
341
  style: {
382
- color: '#1890ff',
383
- textDecoration: 'underline',
384
- wordBreak: 'break-all',
385
- display: 'inline-flex',
386
- alignItems: 'center',
387
- gap: '8px',
388
- maxWidth: '100%',
389
- padding: '8px 12px',
390
- border: '1px dashed #d9d9d9',
391
- borderRadius: '6px',
392
- backgroundColor: '#fafafa',
393
342
  fontSize: '13px',
394
343
  lineHeight: '1.5'
395
344
  }
396
- }, /*#__PURE__*/ React.createElement(ExclamationCircleOutlined, {
397
- style: {
398
- color: '#faad14'
399
- }
400
- }), props.alt || props.src, /*#__PURE__*/ React.createElement(SquareArrowUpRight, null));
345
+ });
401
346
  }
402
347
  return /*#__PURE__*/ React.createElement("div", {
403
348
  "data-testid": "resize-image-container",
@@ -500,7 +445,7 @@ export function EditorImage(param) {
500
445
  var _state;
501
446
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
502
447
  var _useSelStatus = _sliced_to_array(useSelStatus(element), 2), _ = _useSelStatus[0], path = _useSelStatus[1];
503
- var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, readonly = _useEditorStore.readonly, editorProps = _useEditorStore.editorProps;
448
+ var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, readonly = _useEditorStore.readonly;
504
449
  var htmlRef = React.useRef(null);
505
450
  var _useState = _sliced_to_array(useState(false), 2), showAsText = _useState[0], setShowAsText = _useState[1];
506
451
  var _useGetSetState = _sliced_to_array(useGetSetState({
@@ -511,16 +456,14 @@ export function EditorImage(param) {
511
456
  selected: false,
512
457
  type: getMediaType(element === null || element === void 0 ? void 0 : element.url, element.alt)
513
458
  }), 2), state = _useGetSetState[0], setState = _useGetSetState[1];
514
- var updateElement = useCallback(function(attr) {
515
- if (!markdownEditorRef.current) return;
459
+ var updateElement = useRefFunction(function(attr) {
460
+ if (!(markdownEditorRef === null || markdownEditorRef === void 0 ? void 0 : markdownEditorRef.current)) return;
516
461
  Transforms.setNodes(markdownEditorRef.current, attr, {
517
462
  at: path
518
463
  });
519
- }, [
520
- path
521
- ]);
464
+ });
522
465
  var locale = useContext(I18nContext).locale;
523
- var initial = useCallback(/*#__PURE__*/ _async_to_generator(function() {
466
+ var initial = useRefFunction(/*#__PURE__*/ _async_to_generator(function() {
524
467
  var type, realUrl, img;
525
468
  return _ts_generator(this, function(_state) {
526
469
  type = getMediaType(element === null || element === void 0 ? void 0 : element.url, element.alt);
@@ -562,9 +505,7 @@ export function EditorImage(param) {
562
505
  2
563
506
  ];
564
507
  });
565
- }), [
566
- element
567
- ]);
508
+ }));
568
509
  useLayoutEffect(function() {
569
510
  initial();
570
511
  }, [
@@ -609,41 +550,16 @@ export function EditorImage(param) {
609
550
  }
610
551
  // 如果图片加载失败,显示为链接
611
552
  if (!state().loadSuccess) {
612
- var _state2;
613
- return /*#__PURE__*/ React.createElement("span", {
553
+ var _state2, _state3;
554
+ return /*#__PURE__*/ React.createElement(MediaErrorLink, {
555
+ url: (_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url,
556
+ fallbackUrl: element === null || element === void 0 ? void 0 : element.url,
557
+ displayText: (element === null || element === void 0 ? void 0 : element.alt) || ((_state3 = state()) === null || _state3 === void 0 ? void 0 : _state3.url) || (element === null || element === void 0 ? void 0 : element.url) || '图片链接',
614
558
  style: {
615
- color: '#1890ff',
616
- textDecoration: 'underline',
617
- wordBreak: 'break-all',
618
- display: 'inline-flex',
619
- alignItems: 'center',
620
- gap: '8px',
621
- maxWidth: '100%',
622
- padding: '8px 12px',
623
- border: '1px dashed #d9d9d9',
624
- borderRadius: '6px',
625
- backgroundColor: '#fafafa',
626
559
  fontSize: '13px',
627
560
  lineHeight: '1.5'
628
- },
629
- onClick: function(e) {
630
- var _state, _editorProps_linkConfig, _state1, _editorProps_linkConfig1;
631
- if (!(((_state = state()) === null || _state === void 0 ? void 0 : _state.url) || (element === null || element === void 0 ? void 0 : element.url))) return;
632
- e.stopPropagation();
633
- e.preventDefault();
634
- if ((_editorProps_linkConfig = editorProps.linkConfig) === null || _editorProps_linkConfig === void 0 ? void 0 : _editorProps_linkConfig.onClick) {
635
- var _state2;
636
- if (editorProps.linkConfig.onClick(((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || (element === null || element === void 0 ? void 0 : element.url) || '') === false) {
637
- return;
638
- }
639
- }
640
- 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');
641
- }
642
- }, /*#__PURE__*/ React.createElement(ExclamationCircleOutlined, {
643
- style: {
644
- color: '#faad14'
645
561
  }
646
- }), (element === null || element === void 0 ? void 0 : element.alt) || ((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || (element === null || element === void 0 ? void 0 : element.url) || '图片链接', /*#__PURE__*/ React.createElement(SquareArrowUpRight, null));
562
+ });
647
563
  }
648
564
  return !readonly ? /*#__PURE__*/ React.createElement(ResizeImage, {
649
565
  defaultSize: {
@@ -658,6 +574,7 @@ export function EditorImage(param) {
658
574
  });
659
575
  },
660
576
  onResizeStop: function(size) {
577
+ if (!(markdownEditorRef === null || markdownEditorRef === void 0 ? void 0 : markdownEditorRef.current)) return;
661
578
  Transforms.setNodes(markdownEditorRef.current, size, {
662
579
  at: path
663
580
  });
@@ -665,21 +582,9 @@ export function EditorImage(param) {
665
582
  selected: false
666
583
  });
667
584
  }
668
- }) : /*#__PURE__*/ React.createElement(ImageAndError, {
585
+ }) : /*#__PURE__*/ React.createElement(ReadonlyImage, {
669
586
  src: ((_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url) || (element === null || element === void 0 ? void 0 : element.url),
670
- alt: 'image',
671
- preview: {
672
- getContainer: function() {
673
- return document.body;
674
- }
675
- },
676
- referrerPolicy: 'no-referrer',
677
- draggable: false,
678
- style: {
679
- maxWidth: '100%',
680
- height: 'auto',
681
- display: 'block'
682
- },
587
+ alt: (element === null || element === void 0 ? void 0 : element.alt) || 'image',
683
588
  width: element.width,
684
589
  height: element.height
685
590
  });
@@ -737,6 +642,7 @@ export function EditorImage(param) {
737
642
  title: (locale === null || locale === void 0 ? void 0 : locale.deleteMedia) || '删除媒体',
738
643
  content: (locale === null || locale === void 0 ? void 0 : locale.confirmDelete) || '确定删除该媒体吗?',
739
644
  onOk: function() {
645
+ if (!(markdownEditorRef === null || markdownEditorRef === void 0 ? void 0 : markdownEditorRef.current)) return;
740
646
  Transforms.removeNodes(markdownEditorRef.current, {
741
647
  at: path
742
648
  });
@@ -747,6 +653,7 @@ export function EditorImage(param) {
747
653
  title: (element === null || element === void 0 ? void 0 : element.block) ? locale === null || locale === void 0 ? void 0 : locale.blockImage : locale === null || locale === void 0 ? void 0 : locale.inlineImage,
748
654
  onClick: function(e) {
749
655
  e.stopPropagation();
656
+ if (!(markdownEditorRef === null || markdownEditorRef === void 0 ? void 0 : markdownEditorRef.current)) return;
750
657
  Transforms.setNodes(markdownEditorRef.current, {
751
658
  block: !element.block
752
659
  }, {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ElementProps, MediaNode } from '../../el';
2
+ import { ElementProps, MediaNode } from '../../../el';
3
3
  /**
4
4
  * 可调整大小的图片组件的属性接口
5
5
  */
@@ -223,21 +223,22 @@ function _ts_generator(thisArg, body) {
223
223
  };
224
224
  }
225
225
  }
226
- import { DeleteFilled, ExclamationCircleOutlined, EyeOutlined, LoadingOutlined } from "@ant-design/icons";
226
+ import { DeleteFilled, EyeOutlined, LoadingOutlined } from "@ant-design/icons";
227
227
  import { Modal, Popover, Skeleton } from "antd";
228
- import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
228
+ import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
229
+ import { useRefFunction } from "../../../../Hooks/useRefFunction";
229
230
  import { useDebounceFn } from "@ant-design/pro-components";
230
- import { SquareArrowUpRight } from "@sofa-design/icons";
231
231
  import { Rnd } from "react-rnd";
232
232
  import { Transforms } from "slate";
233
- import { ActionIconBox } from "../../../Components/ActionIconBox";
234
- import { I18nContext } from "../../../I18n";
235
- import { useSelStatus } from "../../hooks/editor";
236
- import { AvatarList } from "../components/ContributorAvatar";
237
- import { useEditorStore } from "../store";
238
- import { useGetSetState } from "../utils";
239
- import { getMediaType } from "../utils/dom";
240
- import { ImageAndError } from "./Image";
233
+ import { ActionIconBox } from "../../../../Components/ActionIconBox";
234
+ import { I18nContext } from "../../../../I18n";
235
+ import { useSelStatus } from "../../../hooks/editor";
236
+ import { AvatarList } from "../../components/ContributorAvatar";
237
+ import { MediaErrorLink } from "../../components/MediaErrorLink";
238
+ import { useEditorStore } from "../../store";
239
+ import { useGetSetState } from "../../utils";
240
+ import { getMediaType } from "../../utils/dom";
241
+ import { ReadonlyImage } from "../Image";
241
242
  /**
242
243
  * 可调整大小的图片组件
243
244
  *
@@ -383,12 +384,10 @@ export function Media(param) {
383
384
  var _state, _state1;
384
385
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
385
386
  var _useSelStatus = _sliced_to_array(useSelStatus(element), 2), _ = _useSelStatus[0], path = _useSelStatus[1];
386
- var editorProps = useEditorStore().editorProps;
387
387
  var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, readonly = _useEditorStore.readonly;
388
388
  var locale = useContext(I18nContext).locale;
389
389
  var htmlRef = React.useRef(null);
390
390
  var _useState = _sliced_to_array(useState(false), 2), showAsText = _useState[0], setShowAsText = _useState[1];
391
- console.log(editorProps);
392
391
  var _useGetSetState = _sliced_to_array(useGetSetState({
393
392
  height: element.height,
394
393
  dragging: false,
@@ -397,14 +396,12 @@ export function Media(param) {
397
396
  selected: false,
398
397
  type: getMediaType(element === null || element === void 0 ? void 0 : element.url, element.alt)
399
398
  }), 2), state = _useGetSetState[0], setState = _useGetSetState[1];
400
- var updateElement = useCallback(function(attr) {
399
+ var updateElement = useRefFunction(function(attr) {
401
400
  if (!markdownEditorRef.current) return;
402
401
  Transforms.setNodes(markdownEditorRef.current, attr, {
403
402
  at: path
404
403
  });
405
- }, [
406
- path
407
- ]);
404
+ });
408
405
  // 如果 finished 为 false,设置 5 秒超时,超时后显示为文本
409
406
  useEffect(function() {
410
407
  if (element.finished === false) {
@@ -421,7 +418,7 @@ export function Media(param) {
421
418
  }, [
422
419
  element.finished
423
420
  ]);
424
- var initial = useCallback(/*#__PURE__*/ _async_to_generator(function() {
421
+ var initial = useRefFunction(/*#__PURE__*/ _async_to_generator(function() {
425
422
  var type, finalType, realUrl, img, video, audio;
426
423
  return _ts_generator(this, function(_state) {
427
424
  type = getMediaType(element === null || element === void 0 ? void 0 : element.url, element.alt);
@@ -494,9 +491,7 @@ export function Media(param) {
494
491
  2
495
492
  ];
496
493
  });
497
- }), [
498
- element
499
- ]);
494
+ }));
500
495
  useLayoutEffect(function() {
501
496
  initial();
502
497
  }, [
@@ -544,24 +539,12 @@ export function Media(param) {
544
539
  selected: false
545
540
  });
546
541
  }
547
- }) : /*#__PURE__*/ React.createElement(ImageAndError, {
542
+ }) : /*#__PURE__*/ React.createElement(ReadonlyImage, {
548
543
  src: ((_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url) || (element === null || element === void 0 ? void 0 : element.url),
549
- alt: 'image',
550
- preview: {
551
- getContainer: function() {
552
- return document.body;
553
- }
554
- },
555
- referrerPolicy: 'no-referrer',
556
- crossOrigin: 'anonymous',
557
- draggable: false,
558
- style: {
559
- maxWidth: '100%',
560
- height: 'auto',
561
- display: 'block'
562
- },
544
+ alt: (element === null || element === void 0 ? void 0 : element.alt) || 'image',
563
545
  width: element.width,
564
- height: element.height
546
+ height: element.height,
547
+ crossOrigin: "anonymous"
565
548
  });
566
549
  }, [
567
550
  state().type,
@@ -597,39 +580,12 @@ export function Media(param) {
597
580
  });
598
581
  }
599
582
  if (!state().loadSuccess) {
600
- var _state1;
601
- return /*#__PURE__*/ React.createElement("span", {
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
- },
615
- style: {
616
- color: '#1890ff',
617
- textDecoration: 'underline',
618
- wordBreak: 'break-all',
619
- display: 'inline-flex',
620
- alignItems: 'center',
621
- gap: '8px',
622
- maxWidth: '100%',
623
- padding: '8px 12px',
624
- border: '1px dashed #d9d9d9',
625
- borderRadius: '6px',
626
- backgroundColor: '#fafafa'
627
- }
628
- }, /*#__PURE__*/ React.createElement(ExclamationCircleOutlined, {
629
- style: {
630
- color: '#faad14'
631
- }
632
- }), element.alt || ((_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url) || (element === null || element === void 0 ? void 0 : element.url) || '视频链接', /*#__PURE__*/ React.createElement(SquareArrowUpRight, null));
583
+ var _state1, _state2;
584
+ return /*#__PURE__*/ React.createElement(MediaErrorLink, {
585
+ url: (_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url,
586
+ fallbackUrl: element === null || element === void 0 ? void 0 : element.url,
587
+ displayText: element.alt || ((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || (element === null || element === void 0 ? void 0 : element.url) || '视频链接'
588
+ });
633
589
  }
634
590
  return /*#__PURE__*/ React.createElement("video", {
635
591
  "data-testid": "video-element",
@@ -658,7 +614,7 @@ export function Media(param) {
658
614
  });
659
615
  }
660
616
  if (state().type === 'audio') {
661
- var _state2;
617
+ var _state3;
662
618
  // 如果是不完整状态
663
619
  if (element.finished === false) {
664
620
  // 如果 5 秒后仍未完成,显示为文本
@@ -701,39 +657,12 @@ export function Media(param) {
701
657
  }, rawMarkdown || (element === null || element === void 0 ? void 0 : element.alt) || '音频加载中...'));
702
658
  }
703
659
  if (!state().loadSuccess) {
704
- var _state3;
705
- return /*#__PURE__*/ React.createElement("span", {
706
- onClick: function(e) {
707
- var _state, _editorProps_linkConfig, _state1, _editorProps_linkConfig1;
708
- if (!(((_state = state()) === null || _state === void 0 ? void 0 : _state.url) || (element === null || element === void 0 ? void 0 : element.url))) return;
709
- e.stopPropagation();
710
- e.preventDefault();
711
- if ((_editorProps_linkConfig = editorProps.linkConfig) === null || _editorProps_linkConfig === void 0 ? void 0 : _editorProps_linkConfig.onClick) {
712
- var _state2;
713
- if (editorProps.linkConfig.onClick(((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || (element === null || element === void 0 ? void 0 : element.url) || '') === false) {
714
- return;
715
- }
716
- }
717
- 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');
718
- },
719
- style: {
720
- color: '#1890ff',
721
- textDecoration: 'underline',
722
- wordBreak: 'break-all',
723
- display: 'inline-flex',
724
- alignItems: 'center',
725
- gap: '8px',
726
- maxWidth: '100%',
727
- padding: '8px 12px',
728
- border: '1px dashed #d9d9d9',
729
- borderRadius: '6px',
730
- backgroundColor: '#fafafa'
731
- }
732
- }, /*#__PURE__*/ React.createElement(ExclamationCircleOutlined, {
733
- style: {
734
- color: '#faad14'
735
- }
736
- }), element.alt || ((_state3 = state()) === null || _state3 === void 0 ? void 0 : _state3.url) || (element === null || element === void 0 ? void 0 : element.url) || '音频链接', /*#__PURE__*/ React.createElement(SquareArrowUpRight, null));
660
+ var _state4, _state5;
661
+ return /*#__PURE__*/ React.createElement(MediaErrorLink, {
662
+ url: (_state4 = state()) === null || _state4 === void 0 ? void 0 : _state4.url,
663
+ fallbackUrl: element === null || element === void 0 ? void 0 : element.url,
664
+ displayText: element.alt || ((_state5 = state()) === null || _state5 === void 0 ? void 0 : _state5.url) || (element === null || element === void 0 ? void 0 : element.url) || '音频链接'
665
+ });
737
666
  }
738
667
  return /*#__PURE__*/ React.createElement("audio", {
739
668
  "data-testid": "audio-element",
@@ -742,7 +671,7 @@ export function Media(param) {
742
671
  width: '100%',
743
672
  height: 'auto'
744
673
  },
745
- src: ((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || '',
674
+ src: ((_state3 = state()) === null || _state3 === void 0 ? void 0 : _state3.url) || '',
746
675
  onError: function() {
747
676
  var _state;
748
677
  console.warn('Audio failed to load:', (_state = state()) === null || _state === void 0 ? void 0 : _state.url);
@@ -753,7 +682,7 @@ export function Media(param) {
753
682
  }, "Your browser does not support the", /*#__PURE__*/ React.createElement("code", null, "audio"), " element.");
754
683
  }
755
684
  if (state().type === 'attachment') {
756
- var _state4, _element_alt, _element_alt1, _element_otherProps1, _element_otherProps_collaborators, _element_otherProps2, _element_otherProps3;
685
+ var _state6, _element_alt, _element_alt1, _element_otherProps1, _element_otherProps_collaborators, _element_otherProps2, _element_otherProps3;
757
686
  return /*#__PURE__*/ React.createElement("div", {
758
687
  style: {
759
688
  padding: 12,
@@ -785,7 +714,7 @@ export function Media(param) {
785
714
  minWidth: 0
786
715
  }
787
716
  }, /*#__PURE__*/ React.createElement("a", {
788
- href: (_state4 = state()) === null || _state4 === void 0 ? void 0 : _state4.url,
717
+ href: (_state6 = state()) === null || _state6 === void 0 ? void 0 : _state6.url,
789
718
  style: {
790
719
  overflow: 'ellipsis',
791
720
  textOverflow: 'ellipsis',
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { RenderElementProps } from 'slate-react';
3
+ export declare const Mermaid: ({ attributes, children, element, }: RenderElementProps) => React.JSX.Element;
@@ -50,33 +50,18 @@ function _object_spread_props(target, source) {
50
50
  }
51
51
  return target;
52
52
  }
53
- import React from "react";
53
+ import { ConfigProvider } from "antd";
54
+ import classNames from "classnames";
55
+ import React, { useContext } from "react";
56
+ import { useStyle } from "./style";
54
57
  export var Mermaid = function(param) {
55
- var attributes = param.attributes, children = param.children;
56
- return /*#__PURE__*/ React.createElement("pre", _object_spread_props(_object_spread({}, attributes), {
57
- style: {
58
- height: '240px',
59
- minWidth: '398px',
60
- maxWidth: '800px',
61
- minHeight: '240px',
62
- display: 'flex',
63
- flexDirection: 'column',
64
- alignItems: 'center',
65
- alignSelf: 'stretch',
66
- zIndex: 5,
67
- color: 'rgb(27, 27, 27)',
68
- padding: '1em',
69
- margin: '1em 0',
70
- fontSize: '0.8em',
71
- lineHeight: '1.5',
72
- overflowX: 'auto',
73
- whiteSpace: 'pre-wrap',
74
- wordBreak: 'break-all',
75
- fontFamily: "'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace",
76
- wordWrap: 'break-word',
77
- borderRadius: '12px',
78
- background: '#FFFFFF',
79
- boxShadow: 'var(--shadow-control-base)'
80
- }
81
- }), /*#__PURE__*/ React.createElement("code", null, children));
58
+ var attributes = param.attributes, children = param.children, element = param.element;
59
+ var _element_otherProps;
60
+ var context = useContext(ConfigProvider.ConfigContext);
61
+ var baseCls = context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-md-editor-mermaid');
62
+ var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
63
+ var hasError = (element === null || element === void 0 ? void 0 : (_element_otherProps = element.otherProps) === null || _element_otherProps === void 0 ? void 0 : _element_otherProps.error) === true;
64
+ return wrapSSR(/*#__PURE__*/ React.createElement("pre", _object_spread_props(_object_spread({}, attributes), {
65
+ className: classNames(baseCls, hashId, _define_property({}, "".concat(baseCls, "-error"), hasError))
66
+ }), /*#__PURE__*/ React.createElement("code", null, children)));
82
67
  };
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * Mermaid 组件样式 Hook
4
+ * @param prefixCls - 样式类名前缀
5
+ * @returns 样式相关的 className 和 hashId
6
+ */
7
+ export declare function useStyle(prefixCls?: string): {
8
+ wrapSSR: (node: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) => import("react").JSX.Element;
9
+ hashId: string;
10
+ };