@ant-design/agentic-ui 2.29.37 → 2.29.39

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 (29) hide show
  1. package/dist/Hooks/useLanguage.d.ts +21 -0
  2. package/dist/I18n/locales.d.ts +22 -3
  3. package/dist/I18n/locales.js +51 -5
  4. package/dist/MarkdownEditor/editor/elements/index.js +15 -1
  5. package/dist/MarkdownEditor/editor/parser/constants.d.ts +5 -0
  6. package/dist/MarkdownEditor/editor/parser/constants.js +4 -0
  7. package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +5 -4
  8. package/dist/MarkdownEditor/editor/parser/remarkParse.d.ts +5 -0
  9. package/dist/MarkdownEditor/editor/parser/remarkParse.js +16 -0
  10. package/dist/MarkdownEditor/editor/plugins/useHighlight.js +53 -10
  11. package/dist/MarkdownEditor/editor/plugins/useKeyboard.js +2 -2
  12. package/dist/MarkdownEditor/editor/style.js +1 -1
  13. package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/index.js +35 -23
  14. package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/style.js +47 -37
  15. package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/templates.d.ts +13 -1
  16. package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/templates.js +30 -11
  17. package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +5 -3
  18. package/dist/MarkdownInputField/RefinePromptButton/index.js +4 -2
  19. package/dist/Plugins/chart/ChartRender.js +4 -2
  20. package/dist/Plugins/chart/DonutChart/Legend.js +132 -12
  21. package/dist/Plugins/chart/DonutChart/index.js +58 -6
  22. package/dist/Plugins/chart/DonutChart/plugins.d.ts +5 -0
  23. package/dist/Plugins/chart/DonutChart/plugins.js +48 -0
  24. package/dist/Plugins/chart/DonutChart/style.js +17 -6
  25. package/dist/Plugins/chart/DonutChart/types.d.ts +2 -0
  26. package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundary.d.ts +44 -2
  27. package/dist/Plugins/code/CodeUI/Katex/katex.min.css +1 -3
  28. package/dist/Plugins/katex/katex.min.css +1 -3
  29. package/package.json +3 -1
@@ -406,6 +406,27 @@ export declare function useLanguage(): {
406
406
  'comment.jumpTo': string;
407
407
  'chart.renderFailed': string;
408
408
  'chart.renderFailedSubTitle': string;
409
+ 'chart.legend.show': string;
410
+ 'chart.legend.hide': string;
411
+ 'chart.legend.prevPage': string;
412
+ 'chart.legend.nextPage': string;
413
+ 'chart.legend.remaining': string;
414
+ 'refine.loading': string;
415
+ 'refine.oneClickOptimize': string;
416
+ 'refine.optimizePrompt': string;
417
+ 'jinja.panel.title': string;
418
+ 'jinja.panel.docLink': string;
419
+ 'jinja.panel.noTemplates': string;
420
+ 'jinja.template.variableInterpolation.title': string;
421
+ 'jinja.template.variableInterpolation.description': string;
422
+ 'jinja.template.condition.title': string;
423
+ 'jinja.template.condition.description': string;
424
+ 'jinja.template.loop.title': string;
425
+ 'jinja.template.loop.description': string;
426
+ 'jinja.template.filter.title': string;
427
+ 'jinja.template.filter.description': string;
428
+ 'jinja.template.setVariable.title': string;
429
+ 'jinja.template.setVariable.description': string;
409
430
  };
410
431
  setLanguage: ((language: "zh-CN" | "en-US") => void) | undefined;
411
432
  toggleLanguage: () => void;
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * 中文标签映射对象
3
3
  *
4
- * 包含所有界面文本的中文翻译,用于国际化 dataTime: '数据时间',
5
- columns: '列',
6
- all: '全部',
4
+ * 包含所有界面文本的中文翻译,用于国际化
7
5
  * 提供完整的用户界面文本本地化。
8
6
  */
9
7
  export declare const cnLabels: {
@@ -370,6 +368,27 @@ export declare const cnLabels: {
370
368
  'comment.jumpTo': string;
371
369
  'chart.renderFailed': string;
372
370
  'chart.renderFailedSubTitle': string;
371
+ 'chart.legend.show': string;
372
+ 'chart.legend.hide': string;
373
+ 'chart.legend.prevPage': string;
374
+ 'chart.legend.nextPage': string;
375
+ 'chart.legend.remaining': string;
376
+ 'refine.loading': string;
377
+ 'refine.oneClickOptimize': string;
378
+ 'refine.optimizePrompt': string;
379
+ 'jinja.panel.title': string;
380
+ 'jinja.panel.docLink': string;
381
+ 'jinja.panel.noTemplates': string;
382
+ 'jinja.template.variableInterpolation.title': string;
383
+ 'jinja.template.variableInterpolation.description': string;
384
+ 'jinja.template.condition.title': string;
385
+ 'jinja.template.condition.description': string;
386
+ 'jinja.template.loop.title': string;
387
+ 'jinja.template.loop.description': string;
388
+ 'jinja.template.filter.title': string;
389
+ 'jinja.template.filter.description': string;
390
+ 'jinja.template.setVariable.title': string;
391
+ 'jinja.template.setVariable.description': string;
373
392
  };
374
393
  /**
375
394
  * 英文标签映射对象
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * 中文标签映射对象
3
3
  *
4
- * 包含所有界面文本的中文翻译,用于国际化 dataTime: '数据时间',
5
- columns: '列',
6
- all: '全部',
4
+ * 包含所有界面文本的中文翻译,用于国际化
7
5
  * 提供完整的用户界面文本本地化。
8
6
  */ export var cnLabels = {
9
7
  attachmentSingleMax: '单个最大',
@@ -394,7 +392,31 @@
394
392
  'comment.jumpTo': '跳转到评论位置',
395
393
  // 图表错误相关
396
394
  'chart.renderFailed': '图表渲染失败',
397
- 'chart.renderFailedSubTitle': '图表组件遇到了一个错误,请稍后重试'
395
+ 'chart.renderFailedSubTitle': '图表组件遇到了一个错误,请稍后重试',
396
+ // DonutChart 图例相关
397
+ 'chart.legend.show': '显示',
398
+ 'chart.legend.hide': '隐藏',
399
+ 'chart.legend.prevPage': '上一页',
400
+ 'chart.legend.nextPage': '下一页',
401
+ 'chart.legend.remaining': '剩余',
402
+ // RefinePromptButton 相关
403
+ 'refine.loading': '优化中',
404
+ 'refine.oneClickOptimize': '一键优化提示词',
405
+ 'refine.optimizePrompt': '优化提示词',
406
+ // Jinja 模板面板相关
407
+ 'jinja.panel.title': 'Jinja 模板',
408
+ 'jinja.panel.docLink': '使用说明',
409
+ 'jinja.panel.noTemplates': '暂无模板',
410
+ 'jinja.template.variableInterpolation.title': '变量插值',
411
+ 'jinja.template.variableInterpolation.description': '{{ variable }}',
412
+ 'jinja.template.condition.title': '条件语句',
413
+ 'jinja.template.condition.description': '{% if condition %}...{% endif %}',
414
+ 'jinja.template.loop.title': '循环遍历',
415
+ 'jinja.template.loop.description': '{% for item in list %}...{% endfor %}',
416
+ 'jinja.template.filter.title': '过滤器',
417
+ 'jinja.template.filter.description': '{{ value | filter }}',
418
+ 'jinja.template.setVariable.title': '设置变量',
419
+ 'jinja.template.setVariable.description': '{% set name = value %}'
398
420
  };
399
421
  /**
400
422
  * 英文标签映射对象
@@ -790,5 +812,29 @@
790
812
  'comment.jumpTo': 'Jump to Comment',
791
813
  // Chart error related
792
814
  'chart.renderFailed': 'Chart Rendering Failed',
793
- 'chart.renderFailedSubTitle': 'The chart component encountered an error, please try again later'
815
+ 'chart.renderFailedSubTitle': 'The chart component encountered an error, please try again later',
816
+ // DonutChart legend related
817
+ 'chart.legend.show': 'Show',
818
+ 'chart.legend.hide': 'Hide',
819
+ 'chart.legend.prevPage': 'Previous page',
820
+ 'chart.legend.nextPage': 'Next page',
821
+ 'chart.legend.remaining': 'Remaining',
822
+ // RefinePromptButton related
823
+ 'refine.loading': 'Optimizing',
824
+ 'refine.oneClickOptimize': 'One-click optimize prompt',
825
+ 'refine.optimizePrompt': 'Optimize prompt',
826
+ // Jinja template panel related
827
+ 'jinja.panel.title': 'Jinja Templates',
828
+ 'jinja.panel.docLink': 'Documentation',
829
+ 'jinja.panel.noTemplates': 'No templates',
830
+ 'jinja.template.variableInterpolation.title': 'Variable interpolation',
831
+ 'jinja.template.variableInterpolation.description': '{{ variable }}',
832
+ 'jinja.template.condition.title': 'Conditional',
833
+ 'jinja.template.condition.description': '{% if condition %}...{% endif %}',
834
+ 'jinja.template.loop.title': 'Loop',
835
+ 'jinja.template.loop.description': '{% for item in list %}...{% endfor %}',
836
+ 'jinja.template.filter.title': 'Filter',
837
+ 'jinja.template.filter.description': '{{ value | filter }}',
838
+ 'jinja.template.setVariable.title': 'Set variable',
839
+ 'jinja.template.setVariable.description': '{% set name = value %}'
794
840
  };
@@ -132,9 +132,23 @@ import { Paragraph } from "./Paragraph";
132
132
  import { ReadonlyParagraph } from "./Paragraph/ReadonlyParagraph";
133
133
  import { Schema } from "./Schema";
134
134
  import { ReadonlySchema } from "./Schema/ReadonlySchema";
135
+ import { JINJA_DOLLAR_PLACEHOLDER } from "../parser/constants";
135
136
  import { tableRenderElement } from "./Table";
136
137
  import { ReadonlyTableComponent } from "./Table/ReadonlyTableComponent";
137
138
  import { TagPopup } from "./TagPopup";
139
+ /** 递归将 Jinja 占位符还原为 $ 显示 */ var restoreJinjaDollarInChildren = function restoreJinjaDollarInChildren1(children) {
140
+ return React.Children.map(children, function(child) {
141
+ if (typeof child === 'string') {
142
+ return child.split(JINJA_DOLLAR_PLACEHOLDER).join('$');
143
+ }
144
+ if (/*#__PURE__*/ React.isValidElement(child) && child.props.children !== undefined && child.props.children !== null) {
145
+ return /*#__PURE__*/ React.cloneElement(child, {
146
+ children: restoreJinjaDollarInChildren(child.props.children)
147
+ });
148
+ }
149
+ return child;
150
+ });
151
+ };
138
152
  /**
139
153
  * 性能优化说明:
140
154
  *
@@ -481,7 +495,7 @@ var MLeafComponent = function MLeafComponent(props) {
481
495
  "data-url": leaf.url ? 'url' : undefined,
482
496
  style: style,
483
497
  className: (prefixClassName === null || prefixClassName === void 0 ? void 0 : prefixClassName.trim()) ? prefixClassName === null || prefixClassName === void 0 ? void 0 : prefixClassName.trim() : undefined
484
- }), children);
498
+ }), restoreJinjaDollarInChildren(children));
485
499
  // 如果有评论,使用 CommentLeaf 包裹普通 DOM
486
500
  if (hasComment) {
487
501
  return /*#__PURE__*/ React.createElement(CommentLeaf, {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 占位符:保护 Jinja 块内 $ 不被 remark-math 解析为数学公式。
3
+ * 在 markdown 解析前替换,渲染与序列化时还原为 $。
4
+ */
5
+ export declare const JINJA_DOLLAR_PLACEHOLDER = "\uE01A";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 占位符:保护 Jinja 块内 $ 不被 remark-math 解析为数学公式。
3
+ * 在 markdown 解析前替换,渲染与序列化时还原为 $。
4
+ */ export var JINJA_DOLLAR_PLACEHOLDER = '\uE01A';
@@ -82,6 +82,7 @@ function _unsupported_iterable_to_array(o, minLen) {
82
82
  /* eslint-disable @typescript-eslint/no-loop-func */ /* eslint-disable no-case-declarations */ /* eslint-disable no-param-reassign */ /* eslint-disable @typescript-eslint/no-use-before-define */ import { Node } from "slate";
83
83
  import stringWidth from "string-width";
84
84
  import { debugInfo } from "../../../Utils/debugUtils";
85
+ import { JINJA_DOLLAR_PLACEHOLDER } from "./constants";
85
86
  import { getMediaType } from "../utils/dom";
86
87
  var inlineNode = new Set([
87
88
  'break'
@@ -718,7 +719,7 @@ export var isMix = function isMix(t) {
718
719
  * - `<del>` if `strikethrough` is true.
719
720
  * - `<a href="{url}">` if `url` is defined.
720
721
  */ var textHtml = function textHtml(t) {
721
- var str = t.text || '';
722
+ var str = (t.text || '').split(JINJA_DOLLAR_PLACEHOLDER).join('$');
722
723
  if (t.highColor) str = '<span style="color:'.concat(t.highColor, '">').concat(str, "</span>");
723
724
  if (t.code) str = "<code>".concat(str, "</code>");
724
725
  if (t.italic) str = "<i>".concat(str, "</i>");
@@ -745,9 +746,9 @@ export var isMix = function isMix(t) {
745
746
  * - 将换行符转换为 Markdown 换行符
746
747
  * - 保留文本前后的空白字符
747
748
  */ var textStyle = function textStyle(t) {
748
- var _t_text;
749
+ var _split_join;
749
750
  if (!t.text && !t.tag) return '';
750
- var str = (t === null || t === void 0 ? void 0 : (_t_text = t.text) === null || _t_text === void 0 ? void 0 : _t_text.replace(RegExp("(?<!\\\\)\\\\", "g"), '\\').replace(/\n/g, ' \n')) || '';
751
+ var str = ((_split_join = ((t === null || t === void 0 ? void 0 : t.text) || '').split(JINJA_DOLLAR_PLACEHOLDER).join('$')) === null || _split_join === void 0 ? void 0 : _split_join.replace(RegExp("(?<!\\\\)\\\\", "g"), '\\').replace(/\n/g, ' \n')) || '';
751
752
  var preStr = '', afterStr = '';
752
753
  // Apply formats in a consistent order:
753
754
  // 1. Code (most specific)
@@ -834,7 +835,7 @@ export var isMix = function isMix(t) {
834
835
  });
835
836
  var str = textStyle(t);
836
837
  if (t === null || t === void 0 ? void 0 : t.url) {
837
- str = "[".concat(t.text, "](").concat(encodeURI(t === null || t === void 0 ? void 0 : t.url), ")");
838
+ str = "[".concat((t.text || '').split(JINJA_DOLLAR_PLACEHOLDER).join('$'), "](").concat(encodeURI(t === null || t === void 0 ? void 0 : t.url), ")");
838
839
  } else if (isMix(t) && index !== -1) {
839
840
  var next = siblings[index + 1];
840
841
  if (!str.endsWith(' ') && next && !Node.string(next).startsWith(' ')) {
@@ -15,5 +15,10 @@ export declare function convertParagraphToImage(): (tree: any) => void;
15
15
  * Transformer function.
16
16
  */
17
17
  export declare function fixStrongWithSpecialChars(): (tree: any) => void;
18
+ /**
19
+ * 保护 Jinja 块内的 $,防止被 remark-math 误解析为行内数学(如 {{ $var }})
20
+ * 须在 remark-math 之前运行
21
+ */
22
+ export declare function protectJinjaDollarInText(): (tree: any) => void;
18
23
  declare const markdownParser: import("unified").Processor<import("mdast").Root, undefined, undefined, import("mdast").Root, string>;
19
24
  export default markdownParser;
@@ -30,6 +30,7 @@ import remarkMath from "remark-math";
30
30
  import remarkParse from "remark-parse";
31
31
  import { unified } from "unified";
32
32
  import { visit } from "unist-util-visit";
33
+ import { JINJA_DOLLAR_PLACEHOLDER } from "./constants";
33
34
  /**
34
35
  * 提取段落节点的文本内容
35
36
  * @param paragraphNode - 段落节点
@@ -344,6 +345,20 @@ import { visit } from "unist-util-visit";
344
345
  });
345
346
  };
346
347
  }
348
+ /**
349
+ * 保护 Jinja 块内的 $,防止被 remark-math 误解析为行内数学(如 {{ $var }})
350
+ * 须在 remark-math 之前运行
351
+ */ export function protectJinjaDollarInText() {
352
+ return function(tree) {
353
+ visit(tree, 'text', function(node) {
354
+ if (!node.value || typeof node.value !== 'string') return;
355
+ var replaceInBlock = function replaceInBlock(str) {
356
+ return str.replace(/\$/g, JINJA_DOLLAR_PLACEHOLDER);
357
+ };
358
+ node.value = node.value.replace(/\{\{[^}]*\}\}/g, replaceInBlock).replace(/\{%[^%]*%\}/g, replaceInBlock).replace(/\{#[\s\S]*?#\}/g, replaceInBlock);
359
+ });
360
+ };
361
+ }
347
362
  // Markdown 解析器(用于解析 Markdown 为 mdast AST)
348
363
  // 注意:这个解析器只用于解析,不包含 HTML 渲染相关的插件
349
364
  var markdownParser = unified().use(remarkParse) // 解析 Markdown
@@ -355,6 +370,7 @@ var markdownParser = unified().use(remarkParse) // 解析 Markdown
355
370
  }) // GFM 插件,禁用单波浪线删除线
356
371
  .use(fixStrongWithSpecialChars) // 修复包含特殊字符的加粗文本
357
372
  .use(convertParagraphToImage) // 将以 ! 开头的段落转换为图片,将 | 开头的段落转换为表格
373
+ .use(protectJinjaDollarInText) // 保护 Jinja 块内 $,避免被 remark-math 误解析
358
374
  .use(remarkMath, {
359
375
  singleDollarTextMath: true
360
376
  });
@@ -134,6 +134,45 @@ var createRange = function createRange(path, childIndex, offset, length) {
134
134
  }
135
135
  }, props);
136
136
  };
137
+ /** 创建可跨子节点的 range(用于 Jinja 等可能被 inline code 分割的匹配) */ var createRangeSpanningChildren = function createRangeSpanningChildren(path, children, globalStart, globalEnd) {
138
+ var props = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {};
139
+ var offset = 0;
140
+ var anchorPath = null;
141
+ var anchorOffset = 0;
142
+ var focusPath = null;
143
+ var focusOffset = 0;
144
+ for(var i = 0; i < children.length; i++){
145
+ var _ref;
146
+ var _children_i;
147
+ var text = (_ref = (_children_i = children[i]) === null || _children_i === void 0 ? void 0 : _children_i.text) !== null && _ref !== void 0 ? _ref : '';
148
+ var len = text.length;
149
+ var childStart = offset;
150
+ var childEnd = offset + len;
151
+ if (globalStart < childEnd && anchorPath === null) {
152
+ anchorPath = path.concat(i);
153
+ anchorOffset = Math.max(0, globalStart - childStart);
154
+ }
155
+ if (globalEnd <= childEnd && focusPath === null) {
156
+ focusPath = path.concat(i);
157
+ focusOffset = Math.min(len, globalEnd - childStart);
158
+ break;
159
+ }
160
+ offset = childEnd;
161
+ }
162
+ if (anchorPath && focusPath) {
163
+ return _object_spread({
164
+ anchor: {
165
+ path: anchorPath,
166
+ offset: anchorOffset
167
+ },
168
+ focus: {
169
+ path: focusPath,
170
+ offset: focusOffset
171
+ }
172
+ }, props);
173
+ }
174
+ return null;
175
+ };
137
176
  // 处理文本节点的匹配逻辑
138
177
  var processTextMatches = function processTextMatches(text, path, childIndex) {
139
178
  var ranges = [];
@@ -176,16 +215,18 @@ var processLinkMatches = function processLinkMatches(text, path, childIndex) {
176
215
  }
177
216
  return ranges;
178
217
  };
179
- var processJinjaMatches = function processJinjaMatches(text, path, childIndex) {
218
+ /** 在整段文本上匹配 Jinja,支持被 inline code 分割的语法(如 {% if `x` %}) */ var processJinjaMatchesOnFullText = function processJinjaMatchesOnFullText(fullText, path, children) {
180
219
  var ranges = [];
181
220
  var collect = function collect(reg, prop) {
182
221
  reg.lastIndex = 0;
183
222
  var match;
184
- while((match = reg.exec(text)) !== null){
185
- var index = match.index;
186
- if (typeof index === 'number') {
187
- ranges.push(createRange(path, childIndex, index, match[0].length, _define_property({}, prop, true)));
188
- }
223
+ while((match = reg.exec(fullText)) !== null){
224
+ var start = match.index;
225
+ var matched = match[0];
226
+ if (typeof start !== 'number' || !matched) continue;
227
+ var end = start + matched.length;
228
+ var range = createRangeSpanningChildren(path, children, start, end, _define_property({}, prop, true));
229
+ if (range) ranges.push(range);
189
230
  }
190
231
  };
191
232
  collect(JINJA_VARIABLE_REG, 'jinjaVariable');
@@ -213,6 +254,7 @@ export function useHighlight(store, jinjaEnabled) {
213
254
  var allTextRanges = [];
214
255
  var children = node.children;
215
256
  var childrenLength = children.length;
257
+ var fullText = Node.string(node);
216
258
  for(var i = 0; i < childrenLength; i++){
217
259
  var child = children[i];
218
260
  // 处理 footnote 和 HTML
@@ -225,10 +267,11 @@ export function useHighlight(store, jinjaEnabled) {
225
267
  var _allTextRanges1;
226
268
  (_allTextRanges1 = allTextRanges).push.apply(_allTextRanges1, _to_consumable_array(processLinkMatches(child.text, path, i)));
227
269
  }
228
- if (jinjaEnabled && child.text && !EditorUtils.isDirtLeaf(child)) {
229
- var _allTextRanges2;
230
- (_allTextRanges2 = allTextRanges).push.apply(_allTextRanges2, _to_consumable_array(processJinjaMatches(child.text, path, i)));
231
- }
270
+ }
271
+ // Jinja 在整段文本上匹配,支持 {% if `x` %} 等被 inline code 分割的语法
272
+ if (jinjaEnabled && fullText) {
273
+ var _allTextRanges2;
274
+ (_allTextRanges2 = allTextRanges).push.apply(_allTextRanges2, _to_consumable_array(processJinjaMatchesOnFullText(fullText, path, children)));
232
275
  }
233
276
  // 统一缓存
234
277
  cacheTextNode.set(node, {
@@ -257,8 +257,8 @@ import { useEditorStore } from "../store";
257
257
  var codeMatch = str.match(/^```([\w+\-#]+)$/i);
258
258
  if (codeMatch) {} else {
259
259
  var strAfterKey = str + (e.key.length === 1 ? e.key : '');
260
- // 仅在实际输入一个字符且刚好补全 trigger 时打开面板,避免 Backspace 等导致误打开
261
- if (jinjaTemplatePanelEnabled && e.key.length === 1 && strAfterKey === jinjaTrigger && setOpenJinjaTemplate && setJinjaAnchorPath) {
260
+ // 在实际输入一个字符且补全 trigger 时打开面板,支持在文本后输入(如 "hello {}")
261
+ if (jinjaTemplatePanelEnabled && e.key.length === 1 && strAfterKey.endsWith(jinjaTrigger) && setOpenJinjaTemplate && setJinjaAnchorPath) {
262
262
  setJinjaAnchorPath(node3[1]);
263
263
  setTimeout(function() {
264
264
  return setOpenJinjaTemplate(true);
@@ -498,7 +498,7 @@ var genStyle = function genStyle(token) {
498
498
  marginTop: '0.5em',
499
499
  marginBottom: '0.5em'
500
500
  },
501
- '& &-inline-code': {
501
+ '& code&-inline-code': {
502
502
  display: 'inline',
503
503
  fontFamily: "'Roboto,Mono SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace",
504
504
  margin: '1px 3px',
@@ -61,18 +61,20 @@ function _unsupported_iterable_to_array(o, minLen) {
61
61
  if (n === "Map" || n === "Set") return Array.from(n);
62
62
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
63
63
  }
64
- import { ConfigProvider, Typography } from "antd";
64
+ import { Info } from "@sofa-design/icons";
65
+ import { ConfigProvider } from "antd";
65
66
  import classNames from "clsx";
66
67
  import isHotkey from "is-hotkey";
67
- import React, { useCallback, useEffect, useRef, useState } from "react";
68
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
68
69
  import ReactDOM from "react-dom";
69
70
  import { Editor, Transforms } from "slate";
70
71
  import { ReactEditor } from "slate-react";
72
+ import { useLocale } from "../../../../I18n";
71
73
  import { useEditorStore } from "../../store";
72
74
  import { getOffsetLeft } from "../../utils/dom";
73
75
  import { EditorUtils } from "../../utils/editorUtils";
74
76
  import { JINJA_PANEL_PREFIX_CLS, useJinjaTemplatePanelStyle } from "./style";
75
- import { JINJA_DOC_LINK, JINJA_TEMPLATE_DATA } from "./templates";
77
+ import { getJinjaTemplateData, JINJA_DOC_LINK } from "./templates";
76
78
  var PANEL_MAX_HEIGHT = 320;
77
79
  function getPosition(nodeEl) {
78
80
  var rect = nodeEl.getBoundingClientRect();
@@ -101,7 +103,13 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
101
103
  var docLink = (_ref1 = jinjaConfig === null || jinjaConfig === void 0 ? void 0 : jinjaConfig.docLink) !== null && _ref1 !== void 0 ? _ref1 : JINJA_DOC_LINK;
102
104
  var notFoundContent = (_ref2 = templatePanelConfig === null || templatePanelConfig === void 0 ? void 0 : templatePanelConfig.notFoundContent) !== null && _ref2 !== void 0 ? _ref2 : null;
103
105
  var itemsConfig = templatePanelConfig === null || templatePanelConfig === void 0 ? void 0 : templatePanelConfig.items;
104
- var _useState = _sliced_to_array(useState(JINJA_TEMPLATE_DATA), 2), items = _useState[0], setItems = _useState[1];
106
+ var locale = useLocale();
107
+ var defaultItems = useMemo(function() {
108
+ return getJinjaTemplateData(locale);
109
+ }, [
110
+ locale
111
+ ]);
112
+ var _useState = _sliced_to_array(useState(defaultItems), 2), items = _useState[0], setItems = _useState[1];
105
113
  var _useState1 = _sliced_to_array(useState(false), 2), loading = _useState1[0], setLoading = _useState1[1];
106
114
  var _useState2 = _sliced_to_array(useState(0), 2), activeIndex = _useState2[0], setActiveIndex = _useState2[1];
107
115
  var _useState3 = _sliced_to_array(useState({
@@ -135,9 +143,9 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
135
143
  itemsConfig({
136
144
  editor: editor
137
145
  }).then(function(list) {
138
- setItems(Array.isArray(list) ? list : JINJA_TEMPLATE_DATA);
146
+ setItems(Array.isArray(list) ? list : defaultItems);
139
147
  }).catch(function(err) {
140
- setItems(JINJA_TEMPLATE_DATA);
148
+ setItems(defaultItems);
141
149
  if (process.env.NODE_ENV !== 'production') {
142
150
  console.error('[JinjaTemplatePanel] Failed to load template items:', err);
143
151
  }
@@ -147,12 +155,13 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
147
155
  } else if (Array.isArray(itemsConfig)) {
148
156
  setItems(itemsConfig);
149
157
  } else {
150
- setItems(JINJA_TEMPLATE_DATA);
158
+ setItems(defaultItems);
151
159
  }
152
160
  }, [
153
161
  openJinjaTemplate,
154
162
  itemsConfig,
155
- markdownEditorRef
163
+ markdownEditorRef,
164
+ defaultItems
156
165
  ]);
157
166
  useEffect(function() {
158
167
  if (!openJinjaTemplate || !jinjaAnchorPath || !(markdownEditorRef === null || markdownEditorRef === void 0 ? void 0 : markdownEditorRef.current)) return;
@@ -284,32 +293,35 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
284
293
  return e.preventDefault();
285
294
  }
286
295
  }, /*#__PURE__*/ React.createElement("div", {
287
- className: "".concat(prefixCls, "__content")
288
- }, docLink ? /*#__PURE__*/ React.createElement("div", {
289
- className: "".concat(prefixCls, "__doc-link")
290
- }, /*#__PURE__*/ React.createElement(Typography.Link, {
291
- href: docLink,
292
- target: "_blank",
293
- rel: "noopener noreferrer",
294
- "aria-label": "打开 Jinja 使用说明(新窗口)"
295
- }, "使用说明")) : null, /*#__PURE__*/ React.createElement("div", {
296
- className: "".concat(prefixCls, "__list-box")
296
+ className: "".concat(prefixCls, "-content")
297
+ }, /*#__PURE__*/ React.createElement("div", {
298
+ className: "".concat(prefixCls, "-header")
299
+ }, /*#__PURE__*/ React.createElement("div", {
300
+ className: "".concat(prefixCls, "-title")
301
+ }, locale['jinja.panel.title']), docLink ? /*#__PURE__*/ React.createElement("div", {
302
+ className: "".concat(prefixCls, "-doc-link"),
303
+ onClick: function onClick(e) {
304
+ e.preventDefault();
305
+ window.open(docLink, '_blank');
306
+ }
307
+ }, /*#__PURE__*/ React.createElement(Info, null), locale['jinja.panel.docLink']) : null), /*#__PURE__*/ React.createElement("div", {
308
+ className: "".concat(prefixCls, "-list-box")
297
309
  }, loading ? /*#__PURE__*/ React.createElement("div", {
298
310
  style: {
299
311
  padding: 12,
300
312
  color: 'var(--color-text-secondary)'
301
313
  }
302
- }, "加载中...") : items.length === 0 ? notFoundContent !== null && notFoundContent !== void 0 ? notFoundContent : /*#__PURE__*/ React.createElement("div", {
314
+ }, locale.loading) : items.length === 0 ? notFoundContent !== null && notFoundContent !== void 0 ? notFoundContent : /*#__PURE__*/ React.createElement("div", {
303
315
  style: {
304
316
  padding: 12,
305
317
  color: 'var(--color-text-secondary)'
306
318
  }
307
- }, "暂无模板") : items.map(function(item, i) {
319
+ }, locale['jinja.panel.noTemplates']) : items.map(function(item, i) {
308
320
  return /*#__PURE__*/ React.createElement("div", {
309
321
  key: i,
310
322
  role: "option",
311
323
  "aria-selected": i === activeIndex,
312
- className: classNames("".concat(prefixCls, "__item"), _define_property({}, "".concat(prefixCls, "__item--active"), i === activeIndex)),
324
+ className: classNames("".concat(prefixCls, "-item"), _define_property({}, "".concat(prefixCls, "-item-active"), i === activeIndex)),
313
325
  onMouseDown: function onMouseDown(e) {
314
326
  e.preventDefault();
315
327
  insertTemplate(item);
@@ -318,9 +330,9 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
318
330
  return setActiveIndex(i);
319
331
  }
320
332
  }, /*#__PURE__*/ React.createElement("span", {
321
- className: "".concat(prefixCls, "__item-title")
333
+ className: "".concat(prefixCls, "-item-title")
322
334
  }, item.title), item.description ? /*#__PURE__*/ React.createElement("span", {
323
- className: "".concat(prefixCls, "__item-desc")
335
+ className: "".concat(prefixCls, "-item-desc")
324
336
  }, item.description) : null);
325
337
  })))));
326
338
  return /*#__PURE__*/ ReactDOM.createPortal(panel, document.body);
@@ -57,63 +57,73 @@ var genJinjaPanelStyle = function genJinjaPanelStyle(token) {
57
57
  boxSizing: 'border-box',
58
58
  display: 'flex',
59
59
  flexDirection: 'column',
60
+ width: 360,
61
+ height: 200,
60
62
  maxHeight: 320,
61
63
  minWidth: 240,
62
64
  overflow: 'hidden',
63
- borderRadius: token.borderRadius,
64
- backgroundColor: token.colorBgContainer,
65
- boxShadow: token.boxShadowSecondary,
66
- border: "1px solid ".concat(token.colorBorder),
67
- '&__content': {
65
+ borderRadius: 'var(--radius-control-sm, var(--ant-border-radius-sm))',
66
+ backgroundColor: 'var(--color-gray-bg-page-light, var(--ant-color-bg-container))',
67
+ boxShadow: 'var(--shadow-control-lg, var(--ant-box-shadow))',
68
+ '&-content': {
68
69
  display: 'flex',
69
70
  flexDirection: 'column',
70
71
  flex: 1,
71
- overflow: 'hidden'
72
+ overflow: 'hidden',
73
+ padding: 4
72
74
  },
73
- '&__doc-link': {
74
- padding: '8px 12px',
75
- fontSize: token.fontSizeSM,
76
- color: token.colorLink,
77
- borderBottom: "1px solid ".concat(token.colorBorder),
78
- a: {
79
- color: 'inherit',
80
- textDecoration: 'none',
81
- '&:hover': {
82
- textDecoration: 'underline'
83
- },
84
- '&:focus-visible': {
85
- outline: "2px solid ".concat(token.colorPrimary),
86
- outlineOffset: 2,
87
- borderRadius: token.borderRadiusSM
88
- }
89
- }
75
+ '&-header': {
76
+ padding: '6px 12px',
77
+ display: 'flex',
78
+ alignItems: 'center',
79
+ justifyContent: 'space-between'
80
+ },
81
+ '&-title': {
82
+ font: 'var(--font-text-body-emphasized-sm)',
83
+ letterSpacing: 'var(--letter-spacing-body-emphasized-sm, normal)',
84
+ color: 'var(--color-gray-text-light, var(--ant-color-text-secondary))'
85
+ },
86
+ '&-doc-link': {
87
+ display: 'flex',
88
+ cursor: 'pointer',
89
+ alignItems: 'center',
90
+ gap: 4,
91
+ font: 'var(--font-text-body-emphasized-sm)',
92
+ letterSpacing: 'var(--letter-spacing-body-emphasized-sm, normal)',
93
+ color: 'var(--color-primary-text-default, var(--ant-color-link))'
90
94
  },
91
- '&__list-box': {
95
+ '&-list-box': {
92
96
  flex: 1,
93
97
  overflowY: 'auto',
94
98
  padding: '4px 0'
95
99
  },
96
- '&__item': {
100
+ '&-item': {
97
101
  display: 'flex',
98
- flexDirection: 'column',
99
- gap: 2,
102
+ borderRadius: token.borderRadiusSM,
103
+ flexDirection: 'row',
104
+ alignItems: 'center',
105
+ gap: 8,
100
106
  padding: '8px 12px',
101
107
  cursor: 'pointer',
102
108
  '&:hover': {
103
109
  backgroundColor: token.colorFillTertiary
104
- },
105
- '&--active': {
106
- backgroundColor: token.controlItemBgHover
107
110
  }
108
111
  },
109
- '&__item-title': {
110
- fontSize: token.fontSize,
111
- fontWeight: token.fontWeightStrong,
112
- color: token.colorText
112
+ '&-item-active': {
113
+ backgroundColor: token.controlItemBgHover
113
114
  },
114
- '&__item-desc': {
115
- fontSize: token.fontSizeSM,
116
- color: token.colorTextSecondary
115
+ '&-item-title': {
116
+ flexShrink: 0,
117
+ font: 'var(--font-text-body-base)',
118
+ letterSpacing: 'var(--letter-spacing-body-base, normal)',
119
+ color: 'var(--color-gray-text-default, var(--ant-color-text))'
120
+ },
121
+ '&-item-desc': {
122
+ flex: 1,
123
+ minWidth: 0,
124
+ font: 'var(--font-text-body-sm)',
125
+ letterSpacing: 'var(--letter-spacing-body-sm, normal)',
126
+ color: 'var(--color-gray-text-light, var(--ant-color-text-secondary))'
117
127
  }
118
128
  });
119
129
  };