@ant-design/agentic-ui 2.29.41 → 2.29.45

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.
@@ -112,54 +112,62 @@ export * from "./Robot";
112
112
  }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar9 = locale.agentRunBar) === null || _locale_agentRunBar9 === void 0 ? void 0 : _locale_agentRunBar9.newTask);
113
113
  }
114
114
  } else if (taskStatus === "stopped" || taskStatus === "cancelled") {
115
- if (onCreateNewTask) {
116
- var _locale_agentRunBar10;
117
- actionNode1 = /*#__PURE__*/ React.createElement(Button, {
118
- type: "primary",
119
- onClick: onCreateNewTask,
120
- icon: /*#__PURE__*/ React.createElement(PlusOutlined, null),
121
- color: "default",
122
- variant: "solid"
123
- }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar10 = locale.agentRunBar) === null || _locale_agentRunBar10 === void 0 ? void 0 : _locale_agentRunBar10.createNewTask);
124
- }
115
+ var _locale_agentRunBar10, _locale_agentRunBar11;
116
+ actionNode1 = /*#__PURE__*/ React.createElement(React.Fragment, null, onViewResult && /*#__PURE__*/ React.createElement(Button, {
117
+ onClick: onViewResult,
118
+ color: "default",
119
+ variant: "solid",
120
+ autoInsertSpace: false
121
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar10 = locale.agentRunBar) === null || _locale_agentRunBar10 === void 0 ? void 0 : _locale_agentRunBar10.submitTask), onCreateNewTask && /*#__PURE__*/ React.createElement(Button, {
122
+ type: "primary",
123
+ onClick: onCreateNewTask,
124
+ icon: /*#__PURE__*/ React.createElement(PlusOutlined, null),
125
+ color: "default",
126
+ variant: "solid"
127
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar11 = locale.agentRunBar) === null || _locale_agentRunBar11 === void 0 ? void 0 : _locale_agentRunBar11.createNewTask));
125
128
  } else if (taskStatus === "success" && taskRunningStatus === "complete") {
126
- var _locale_agentRunBar11, _locale_agentRunBar12, _locale_agentRunBar13;
129
+ var _locale_agentRunBar12, _locale_agentRunBar13, _locale_agentRunBar14;
127
130
  actionNode1 = /*#__PURE__*/ React.createElement(React.Fragment, null, onReplay && /*#__PURE__*/ React.createElement(Button, {
128
131
  onClick: onReplay,
129
132
  variant: "solid",
130
133
  autoInsertSpace: false
131
- }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar11 = locale.agentRunBar) === null || _locale_agentRunBar11 === void 0 ? void 0 : _locale_agentRunBar11.replayTask), onViewResult && /*#__PURE__*/ React.createElement(Button, {
134
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar12 = locale.agentRunBar) === null || _locale_agentRunBar12 === void 0 ? void 0 : _locale_agentRunBar12.replayTask), onViewResult && /*#__PURE__*/ React.createElement(Button, {
132
135
  onClick: onViewResult,
133
136
  color: "default",
134
137
  variant: "solid",
135
138
  autoInsertSpace: false
136
- }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar12 = locale.agentRunBar) === null || _locale_agentRunBar12 === void 0 ? void 0 : _locale_agentRunBar12.submitTask), onCreateNewTask && /*#__PURE__*/ React.createElement(Button, {
139
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar13 = locale.agentRunBar) === null || _locale_agentRunBar13 === void 0 ? void 0 : _locale_agentRunBar13.submitTask), onCreateNewTask && /*#__PURE__*/ React.createElement(Button, {
137
140
  onClick: onCreateNewTask,
138
141
  icon: /*#__PURE__*/ React.createElement(PlusOutlined, null),
139
142
  color: "default",
140
143
  variant: "solid"
141
- }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar13 = locale.agentRunBar) === null || _locale_agentRunBar13 === void 0 ? void 0 : _locale_agentRunBar13.newTask));
144
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar14 = locale.agentRunBar) === null || _locale_agentRunBar14 === void 0 ? void 0 : _locale_agentRunBar14.newTask));
142
145
  } else if (taskStatus === "error") {
143
- var _locale_agentRunBar14, _locale_agentRunBar15;
146
+ var _locale_agentRunBar15, _locale_agentRunBar16, _locale_agentRunBar17;
144
147
  actionNode1 = /*#__PURE__*/ React.createElement(React.Fragment, null, onReplay && /*#__PURE__*/ React.createElement(Button, {
145
148
  onClick: onReplay,
146
149
  variant: "solid",
147
150
  autoInsertSpace: false
148
- }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar14 = locale.agentRunBar) === null || _locale_agentRunBar14 === void 0 ? void 0 : _locale_agentRunBar14.replayTask), onCreateNewTask && /*#__PURE__*/ React.createElement(Button, {
151
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar15 = locale.agentRunBar) === null || _locale_agentRunBar15 === void 0 ? void 0 : _locale_agentRunBar15.replayTask), onViewResult && /*#__PURE__*/ React.createElement(Button, {
152
+ onClick: onViewResult,
153
+ color: "default",
154
+ variant: "solid",
155
+ autoInsertSpace: false
156
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar16 = locale.agentRunBar) === null || _locale_agentRunBar16 === void 0 ? void 0 : _locale_agentRunBar16.submitTask), onCreateNewTask && /*#__PURE__*/ React.createElement(Button, {
149
157
  onClick: onCreateNewTask,
150
158
  icon: /*#__PURE__*/ React.createElement(PlusOutlined, null),
151
159
  color: "default",
152
160
  variant: "solid"
153
- }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar15 = locale.agentRunBar) === null || _locale_agentRunBar15 === void 0 ? void 0 : _locale_agentRunBar15.newTask));
161
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar17 = locale.agentRunBar) === null || _locale_agentRunBar17 === void 0 ? void 0 : _locale_agentRunBar17.newTask));
154
162
  } else if (!isRunning && !isPause) {
155
163
  if (onCreateNewTask) {
156
- var _locale_agentRunBar16;
164
+ var _locale_agentRunBar18;
157
165
  actionNode1 = /*#__PURE__*/ React.createElement(Button, {
158
166
  onClick: onCreateNewTask,
159
167
  icon: /*#__PURE__*/ React.createElement(PlusOutlined, null),
160
168
  color: "default",
161
169
  variant: "solid"
162
- }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar16 = locale.agentRunBar) === null || _locale_agentRunBar16 === void 0 ? void 0 : _locale_agentRunBar16.createNewTask);
170
+ }, locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar18 = locale.agentRunBar) === null || _locale_agentRunBar18 === void 0 ? void 0 : _locale_agentRunBar18.createNewTask);
163
171
  }
164
172
  }
165
173
  var stopTitle = locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar = locale.agentRunBar) === null || _locale_agentRunBar === void 0 ? void 0 : _locale_agentRunBar.stop;
@@ -1,3 +1,5 @@
1
+ /** 表格列宽计算的列数阈值,少于该列数不设置 col 元素,使用浏览器默认布局 */
2
+ export declare const TABLE_COL_WIDTH_MIN_COLUMNS = 3;
1
3
  export declare const MOBILE_PADDING = "clamp(4px, 2vw, 12px)";
2
4
  export declare const MOBILE_BREAKPOINT = "768px";
3
5
  export declare const MOBILE_TABLE_MIN_COLUMN_WIDTH = 96;
@@ -2,6 +2,7 @@ var MOBILE_PADDING_MIN = '4px';
2
2
  var MOBILE_PADDING_MAX = '12px';
3
3
  var MOBILE_PADDING_SCALE = '2vw';
4
4
  var MOBILE_TABLE_MIN_CELL_WIDTH = 96;
5
+ /** 表格列宽计算的列数阈值,少于该列数不设置 col 元素,使用浏览器默认布局 */ export var TABLE_COL_WIDTH_MIN_COLUMNS = 3;
5
6
  export var MOBILE_PADDING = "clamp(".concat(MOBILE_PADDING_MIN, ", ").concat(MOBILE_PADDING_SCALE, ", ").concat(MOBILE_PADDING_MAX, ")");
6
7
  export var MOBILE_BREAKPOINT = '768px';
7
8
  export var MOBILE_TABLE_MIN_COLUMN_WIDTH = MOBILE_TABLE_MIN_CELL_WIDTH;
@@ -416,6 +416,7 @@ export declare function useLanguage(): {
416
416
  'refine.optimizePrompt': string;
417
417
  'jinja.panel.title': string;
418
418
  'jinja.panel.docLink': string;
419
+ 'jinja.panel.close': string;
419
420
  'jinja.panel.noTemplates': string;
420
421
  'jinja.template.variableInterpolation.title': string;
421
422
  'jinja.template.variableInterpolation.description': string;
@@ -378,6 +378,7 @@ export declare const cnLabels: {
378
378
  'refine.optimizePrompt': string;
379
379
  'jinja.panel.title': string;
380
380
  'jinja.panel.docLink': string;
381
+ 'jinja.panel.close': string;
381
382
  'jinja.panel.noTemplates': string;
382
383
  'jinja.template.variableInterpolation.title': string;
383
384
  'jinja.template.variableInterpolation.description': string;
@@ -406,6 +406,7 @@
406
406
  // Jinja 模板面板相关
407
407
  'jinja.panel.title': 'Jinja 模板',
408
408
  'jinja.panel.docLink': '使用说明',
409
+ 'jinja.panel.close': '关闭',
409
410
  'jinja.panel.noTemplates': '暂无模板',
410
411
  'jinja.template.variableInterpolation.title': '变量插值',
411
412
  'jinja.template.variableInterpolation.description': '{{ variable }}',
@@ -826,6 +827,7 @@
826
827
  // Jinja template panel related
827
828
  'jinja.panel.title': 'Jinja Templates',
828
829
  'jinja.panel.docLink': 'Documentation',
830
+ 'jinja.panel.close': 'Close',
829
831
  'jinja.panel.noTemplates': 'No templates',
830
832
  'jinja.template.variableInterpolation.title': 'Variable interpolation',
831
833
  'jinja.template.variableInterpolation.description': '{{ variable }}',
@@ -64,6 +64,7 @@ import classNames from "clsx";
64
64
  import copy from "copy-to-clipboard";
65
65
  import React, { useCallback, useContext, useMemo, useRef, useState } from "react";
66
66
  import { ActionIconBox } from "../../../../Components/ActionIconBox";
67
+ import { TABLE_COL_WIDTH_MIN_COLUMNS } from "../../../../Constants/mobile";
67
68
  import { I18nContext } from "../../../../I18n";
68
69
  import { useEditorStore } from "../../store";
69
70
  import { parserSlateNodeToMarkdown } from "../../utils";
@@ -84,15 +85,15 @@ import { parserSlateNodeToMarkdown } from "../../utils";
84
85
  var modelTargetRef = useRef(null);
85
86
  var _useState = _sliced_to_array(useState(false), 2), previewOpen = _useState[0], setPreviewOpen = _useState[1];
86
87
  var i18n = useContext(I18nContext);
87
- // 简化的列宽计算 - 只为 readonly 模式设计
88
+ // 简化的列宽计算 - 只为 readonly 模式设计,少于 3 列不设置 col
88
89
  var colWidths = useMemo(function() {
89
90
  var _element_children__children, _element_children_, _element_children;
91
+ var columnCount = (element === null || element === void 0 ? void 0 : (_element_children = element.children) === null || _element_children === void 0 ? void 0 : (_element_children_ = _element_children[0]) === null || _element_children_ === void 0 ? void 0 : (_element_children__children = _element_children_.children) === null || _element_children__children === void 0 ? void 0 : _element_children__children.length) || 0;
92
+ if (columnCount === 0 || columnCount < TABLE_COL_WIDTH_MIN_COLUMNS) return [];
90
93
  var otherProps = element === null || element === void 0 ? void 0 : element.otherProps;
91
94
  if (otherProps === null || otherProps === void 0 ? void 0 : otherProps.colWidths) {
92
95
  return otherProps.colWidths;
93
96
  }
94
- var columnCount = (element === null || element === void 0 ? void 0 : (_element_children = element.children) === null || _element_children === void 0 ? void 0 : (_element_children_ = _element_children[0]) === null || _element_children_ === void 0 ? void 0 : (_element_children__children = _element_children_.children) === null || _element_children__children === void 0 ? void 0 : _element_children__children.length) || 0;
95
- if (columnCount === 0) return [];
96
97
  // 使用固定宽度避免复杂计算
97
98
  var defaultWidth = 80;
98
99
  return Array(columnCount).fill(defaultWidth);
@@ -147,7 +148,7 @@ import { parserSlateNodeToMarkdown } from "../../utils";
147
148
  return /*#__PURE__*/ React.createElement("table", {
148
149
  ref: tableTargetRef,
149
150
  className: classNames("".concat(baseCls, "-editor-table"), 'readonly', "".concat(baseCls, "-readonly-table"), _define_property({}, "".concat(baseCls, "-readonly-pure"), editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_tableConfig = editorProps.tableConfig) === null || _editorProps_tableConfig === void 0 ? void 0 : _editorProps_tableConfig.pure))
150
- }, /*#__PURE__*/ React.createElement("colgroup", null, colWidths.map(function(colWidth, index) {
151
+ }, colWidths.length > 0 && /*#__PURE__*/ React.createElement("colgroup", null, colWidths.map(function(colWidth, index) {
151
152
  var isLastCol = index === colWidths.length - 1;
152
153
  return /*#__PURE__*/ React.createElement("col", {
153
154
  key: index,
@@ -194,6 +195,12 @@ import { parserSlateNodeToMarkdown } from "../../utils";
194
195
  afterClose: handleModalClose,
195
196
  width: "80vw",
196
197
  onCancel: handleModalClose
198
+ }, /*#__PURE__*/ React.createElement("div", {
199
+ className: getPrefixCls('agentic-md-editor'),
200
+ style: {
201
+ flex: 1,
202
+ minWidth: 0
203
+ }
197
204
  }, /*#__PURE__*/ React.createElement("div", {
198
205
  className: classNames(baseCls, getPrefixCls('agentic-md-editor-content')),
199
206
  style: {
@@ -204,15 +211,12 @@ import { parserSlateNodeToMarkdown } from "../../utils";
204
211
  },
205
212
  ref: modelTargetRef,
206
213
  onMouseDown: function onMouseDown(e) {
207
- // 阻止默认的文字选择行为
208
214
  e.preventDefault();
209
215
  },
210
216
  onDragStart: function onDragStart(e) {
211
- // 阻止拖拽开始时的文字选择
212
217
  e.preventDefault();
213
218
  },
214
219
  onDoubleClick: function onDoubleClick(e) {
215
- // 阻止双击选择文字
216
220
  e.preventDefault();
217
221
  }
218
222
  }, /*#__PURE__*/ React.createElement(ConfigProvider, {
@@ -222,6 +226,6 @@ import { parserSlateNodeToMarkdown } from "../../utils";
222
226
  getTargetContainer: function getTargetContainer() {
223
227
  return modelTargetRef.current || document.body;
224
228
  }
225
- }, tableDom))));
229
+ }, tableDom)))));
226
230
  });
227
231
  ReadonlyTableComponent.displayName = 'ReadonlyTableComponent';
@@ -149,7 +149,7 @@ import classNames from "clsx";
149
149
  import React, { useContext, useEffect, useMemo, useRef } from "react";
150
150
  import { Node } from "slate";
151
151
  import stringWidth from "string-width";
152
- import { MOBILE_BREAKPOINT, MOBILE_TABLE_MIN_COLUMN_WIDTH } from "../../../../Constants/mobile";
152
+ import { MOBILE_BREAKPOINT, MOBILE_TABLE_MIN_COLUMN_WIDTH, TABLE_COL_WIDTH_MIN_COLUMNS } from "../../../../Constants/mobile";
153
153
  import { useEditorStore } from "../../store";
154
154
  import { ReadonlyTableComponent } from "./ReadonlyTableComponent";
155
155
  import { TablePropsContext } from "./TableContext";
@@ -197,18 +197,20 @@ import useScrollShadow from "./useScrollShadow";
197
197
  // 只在编辑模式下进行复杂的列宽计算
198
198
  var colWidths = useMemo(function() {
199
199
  var _props_element_otherProps, _props_element, _props_element_children, _props_element1, _tableRows__children, _tableRows_, _markdownContainerRef_current_querySelector, _markdownContainerRef_current;
200
- // readonly 模式下使用简化计算
200
+ // readonly 模式下使用简化计算,少于 3 列不设置 col
201
201
  if (readonly) {
202
- var _props_element2, _props_element_children__children, _props_element_children_, _props_element_children1, _props_element3;
203
- var otherProps = (_props_element2 = props.element) === null || _props_element2 === void 0 ? void 0 : _props_element2.otherProps;
202
+ var _props_element_children__children, _props_element_children_, _props_element_children1, _props_element2, _props_element3;
203
+ var colCount = ((_props_element2 = props.element) === null || _props_element2 === void 0 ? void 0 : (_props_element_children1 = _props_element2.children) === null || _props_element_children1 === void 0 ? void 0 : (_props_element_children_ = _props_element_children1[0]) === null || _props_element_children_ === void 0 ? void 0 : (_props_element_children__children = _props_element_children_.children) === null || _props_element_children__children === void 0 ? void 0 : _props_element_children__children.length) || 0;
204
+ if (colCount === 0 || colCount < TABLE_COL_WIDTH_MIN_COLUMNS) return [];
205
+ var otherProps = (_props_element3 = props.element) === null || _props_element3 === void 0 ? void 0 : _props_element3.otherProps;
204
206
  if (otherProps === null || otherProps === void 0 ? void 0 : otherProps.colWidths) {
205
207
  return otherProps.colWidths;
206
208
  }
207
- var columnCount1 = ((_props_element3 = props.element) === null || _props_element3 === void 0 ? void 0 : (_props_element_children1 = _props_element3.children) === null || _props_element_children1 === void 0 ? void 0 : (_props_element_children_ = _props_element_children1[0]) === null || _props_element_children_ === void 0 ? void 0 : (_props_element_children__children = _props_element_children_.children) === null || _props_element_children__children === void 0 ? void 0 : _props_element_children__children.length) || 0;
208
- if (columnCount1 === 0) return [];
209
- return Array(columnCount1).fill(80); // 固定宽度
209
+ return Array(colCount).fill(80); // 固定宽度
210
210
  }
211
- // 如果在props中存在,直接使用以避免计算
211
+ // 少于 3 列不设置 col,使用浏览器默认布局
212
+ if (columnCount < TABLE_COL_WIDTH_MIN_COLUMNS) return [];
213
+ // 如果在 props 中存在,直接使用以避免计算
212
214
  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.colWidths) {
213
215
  var _props_element_otherProps1, _props_element4;
214
216
  return (_props_element4 = props.element) === null || _props_element4 === void 0 ? void 0 : (_props_element_otherProps1 = _props_element4.otherProps) === null || _props_element_otherProps1 === void 0 ? void 0 : _props_element_otherProps1.colWidths;
@@ -221,7 +223,8 @@ import useScrollShadow from "./useScrollShadow";
221
223
  var isMobileLayout = containerWidth <= mobileBreakpointValue;
222
224
  var minColumnWidth = isMobileLayout ? MOBILE_TABLE_MIN_COLUMN_WIDTH : 60;
223
225
  var maxColumnWidth = isMobileLayout ? containerWidth : containerWidth / 4;
224
- var rowsToSample = Math.min(5, tableRows.length);
226
+ // 至少采样 3 行用于列宽计算(若有 3 行以上),不足 3 行时自动使用全部可用行
227
+ var rowsToSample = tableRows.length >= 3 ? Math.min(5, tableRows.length) : tableRows.length;
225
228
  // 一次性计算宽度
226
229
  var calculatedWidths = Array.from({
227
230
  length: columnCount
@@ -333,10 +336,12 @@ import useScrollShadow from "./useScrollShadow";
333
336
  });
334
337
  }) || null), /*#__PURE__*/ React.createElement("tbody", null, readonly ? null : /*#__PURE__*/ React.createElement(TableRowIndex, {
335
338
  colWidths: colWidths,
339
+ columnCount: columnCount,
336
340
  tablePath: tablePath
337
341
  }), children));
338
342
  }, [
339
343
  colWidths,
344
+ columnCount,
340
345
  children,
341
346
  baseCls
342
347
  ]);
@@ -3,8 +3,10 @@ import React from 'react';
3
3
  * TableRowIndex 组件的属性接口
4
4
  */
5
5
  export interface TableRowIndexProps {
6
- /** 列宽度数组 */
6
+ /** 列宽度数组,为空时使用 columnCount 渲染占位单元格 */
7
7
  colWidths?: number[];
8
+ /** 数据列数,colWidths 为空时用于渲染占位单元格数量 */
9
+ columnCount?: number;
8
10
  /** 自定义样式 */
9
11
  style?: React.CSSProperties;
10
12
  /** 自定义类名 */
@@ -34,7 +34,8 @@ import { TableCellIndexSpacer } from "../TableCellIndexSpacer";
34
34
  * - 根据列宽度数组生成对应的间隔单元格
35
35
  * - 包含行索引单元格和列间隔单元格
36
36
  */ export var TableRowIndex = function TableRowIndex(param) {
37
- var _param_colWidths = param.colWidths, colWidths = _param_colWidths === void 0 ? [] : _param_colWidths, style = param.style, className = param.className, tablePath = param.tablePath;
37
+ var _param_colWidths = param.colWidths, colWidths = _param_colWidths === void 0 ? [] : _param_colWidths, _param_columnCount = param.columnCount, columnCount = _param_columnCount === void 0 ? 0 : _param_columnCount, style = param.style, className = param.className, tablePath = param.tablePath;
38
+ var spacerCount = colWidths.length > 0 ? colWidths.length : columnCount;
38
39
  var context = useContext(ConfigProvider.ConfigContext);
39
40
  var baseClassName = context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-md-editor-table-row-index');
40
41
  return /*#__PURE__*/ React.createElement("tr", {
@@ -51,7 +52,9 @@ import { TableCellIndexSpacer } from "../TableCellIndexSpacer";
51
52
  columnIndex: -1,
52
53
  key: -1,
53
54
  tablePath: tablePath
54
- }), colWidths.map(function(_, index) {
55
+ }), Array.from({
56
+ length: spacerCount
57
+ }).map(function(_, index) {
55
58
  return /*#__PURE__*/ React.createElement(TableCellIndexSpacer, {
56
59
  key: index,
57
60
  columnIndex: index,
@@ -433,6 +433,27 @@ var MLeafComponent = function MLeafComponent(props) {
433
433
  if (leaf.jinjaComment) {
434
434
  prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-comment"));
435
435
  }
436
+ if (leaf.jinjaKeyword) {
437
+ prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-keyword"));
438
+ }
439
+ if (leaf.jinjaString) {
440
+ prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-string"));
441
+ }
442
+ if (leaf.jinjaNumber) {
443
+ prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-number"));
444
+ }
445
+ if (leaf.jinjaFilter) {
446
+ prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-filter"));
447
+ }
448
+ if (leaf.jinjaVariableName) {
449
+ prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-variable-name"));
450
+ }
451
+ if (leaf.jinjaPlaceholder) {
452
+ prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-placeholder"));
453
+ }
454
+ if (leaf.jinjaDelimiter) {
455
+ prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-delimiter"));
456
+ }
436
457
  if (leaf.current) {
437
458
  style.background = '#f59e0b';
438
459
  }
@@ -491,6 +491,21 @@ export var EnterKey = /*#__PURE__*/ function() {
491
491
  }
492
492
  }
493
493
  if (parent[0].type === 'list-item') {
494
+ // 列表为空(仅有一项且该项无内容)时,回车将列表转换为段落
495
+ var listItemPath = parent[1];
496
+ var _Editor_parent = _sliced_to_array(Editor.parent(this.editor, listItemPath), 2), listNode = _Editor_parent[0], listPath = _Editor_parent[1];
497
+ var isListWithSingleEmptyItem = listNode.children.length === 1 && Node.string(node[0]) === '' && !Path.hasPrevious(listItemPath);
498
+ if (isListWithSingleEmptyItem) {
499
+ e.preventDefault();
500
+ Transforms.removeNodes(this.editor, {
501
+ at: listPath
502
+ });
503
+ Transforms.insertNodes(this.editor, EditorUtils.p, {
504
+ at: listPath,
505
+ select: true
506
+ });
507
+ return true;
508
+ }
494
509
  if (isMod(e) || Path.hasPrevious(node[1])) {
495
510
  var text = Point.equals(end, sel.focus) ? [
496
511
  {
@@ -215,23 +215,182 @@ var processLinkMatches = function processLinkMatches(text, path, childIndex) {
215
215
  }
216
216
  return ranges;
217
217
  };
218
+ /** Jinja 关键字集合 */ var JINJA_KEYWORDS = new Set([
219
+ 'set',
220
+ 'if',
221
+ 'elif',
222
+ 'else',
223
+ 'endif',
224
+ 'for',
225
+ 'endfor',
226
+ 'in',
227
+ 'and',
228
+ 'or',
229
+ 'not',
230
+ 'with',
231
+ 'without',
232
+ 'true',
233
+ 'false',
234
+ 'is',
235
+ 'none'
236
+ ]);
237
+ /** 解析 {% %} 标签内部内容,返回子 token 的 [start, end, prop][] */ var tokenizeJinjaTagContent = function tokenizeJinjaTagContent(content, baseOffset) {
238
+ var tokens = [];
239
+ var pos = 0;
240
+ var addToken = function addToken(len, prop) {
241
+ if (len > 0) {
242
+ tokens.push({
243
+ start: baseOffset + pos,
244
+ end: baseOffset + pos + len,
245
+ prop: prop
246
+ });
247
+ pos += len;
248
+ }
249
+ };
250
+ while(pos < content.length){
251
+ var rest = content.slice(pos);
252
+ // 占位符 $(xxx:yyy)
253
+ var placeholderMatch = rest.match(/^\$\([^)]+\)/);
254
+ if (placeholderMatch) {
255
+ addToken(placeholderMatch[0].length, 'jinjaPlaceholder');
256
+ continue;
257
+ }
258
+ // 字符串 '...' 或 "..."
259
+ var singleStrMatch = rest.match(/^'([^'\\]|\\.)*'/);
260
+ var doubleStrMatch = rest.match(/^"([^"\\]|\\.)*"/);
261
+ var strMatch = singleStrMatch || doubleStrMatch;
262
+ if (strMatch) {
263
+ addToken(strMatch[0].length, 'jinjaString');
264
+ continue;
265
+ }
266
+ // 数字(含小数)
267
+ var numMatch = rest.match(/^\d+(\.\d+)?/);
268
+ if (numMatch) {
269
+ addToken(numMatch[0].length, 'jinjaNumber');
270
+ continue;
271
+ }
272
+ // 过滤器 | name
273
+ var filterMatch = rest.match(/^\|\s*[a-zA-Z_][a-zA-Z0-9_]*/);
274
+ if (filterMatch) {
275
+ addToken(filterMatch[0].length, 'jinjaFilter');
276
+ continue;
277
+ }
278
+ // 关键字(需与标识符区分)
279
+ var wordMatch = rest.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);
280
+ if (wordMatch) {
281
+ var word = wordMatch[0];
282
+ addToken(word.length, JINJA_KEYWORDS.has(word) ? 'jinjaKeyword' : 'jinjaVariableName');
283
+ continue;
284
+ }
285
+ // 比较运算符(多字符优先)
286
+ if (rest.startsWith('==') || rest.startsWith('!=') || rest.startsWith('>=') || rest.startsWith('<=')) {
287
+ addToken(2, 'jinjaDelimiter');
288
+ continue;
289
+ }
290
+ if ('=<>'.includes(rest[0])) {
291
+ addToken(1, 'jinjaDelimiter');
292
+ continue;
293
+ }
294
+ // 其他符号或空格:作为 jinjaDelimiter(括括号等)或跳过
295
+ pos += 1;
296
+ }
297
+ return tokens;
298
+ };
299
+ /** 解析 {{ }} 变量块内部,返回子 token(变量名、过滤器、占位符) */ var tokenizeJinjaVariableContent = function tokenizeJinjaVariableContent(content, baseOffset) {
300
+ var tokens = [];
301
+ var i = 0;
302
+ while(i < content.length){
303
+ var rest = content.slice(i);
304
+ var ph = rest.match(/^\$\([^)]+\)/);
305
+ if (ph) {
306
+ tokens.push({
307
+ start: baseOffset + i,
308
+ end: baseOffset + i + ph[0].length,
309
+ prop: 'jinjaPlaceholder'
310
+ });
311
+ i += ph[0].length;
312
+ continue;
313
+ }
314
+ var flt = rest.match(/^\|\s*[a-zA-Z_][a-zA-Z0-9_]*/);
315
+ if (flt) {
316
+ tokens.push({
317
+ start: baseOffset + i,
318
+ end: baseOffset + i + flt[0].length,
319
+ prop: 'jinjaFilter'
320
+ });
321
+ i += flt[0].length;
322
+ continue;
323
+ }
324
+ var word = rest.match(/^[a-zA-Z_$][a-zA-Z0-9_]*/);
325
+ if (word) {
326
+ tokens.push({
327
+ start: baseOffset + i,
328
+ end: baseOffset + i + word[0].length,
329
+ prop: 'jinjaVariableName'
330
+ });
331
+ i += word[0].length;
332
+ continue;
333
+ }
334
+ i += 1;
335
+ }
336
+ return tokens;
337
+ };
218
338
  /** 在整段文本上匹配 Jinja,支持被 inline code 分割的语法(如 {% if `x` %}) */ var processJinjaMatchesOnFullText = function processJinjaMatchesOnFullText(fullText, path, children) {
219
339
  var ranges = [];
220
- var collect = function collect(reg, prop) {
221
- reg.lastIndex = 0;
222
- var match;
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);
230
- }
340
+ var addRange = function addRange(start, end, prop) {
341
+ var range = createRangeSpanningChildren(path, children, start, end, _define_property({}, prop, true));
342
+ if (range) ranges.push(range);
231
343
  };
232
- collect(JINJA_VARIABLE_REG, 'jinjaVariable');
233
- collect(JINJA_TAG_REG, 'jinjaTag');
234
- collect(JINJA_COMMENT_REG, 'jinjaComment');
344
+ // 注释:整块灰色
345
+ JINJA_COMMENT_REG.lastIndex = 0;
346
+ var match;
347
+ while((match = JINJA_COMMENT_REG.exec(fullText)) !== null){
348
+ var start = match.index;
349
+ var matched = match[0];
350
+ if (typeof start === 'number' && matched) {
351
+ addRange(start, start + matched.length, 'jinjaComment');
352
+ }
353
+ }
354
+ // 变量 {{ }}:细粒度高亮
355
+ JINJA_VARIABLE_REG.lastIndex = 0;
356
+ while((match = JINJA_VARIABLE_REG.exec(fullText)) !== null){
357
+ var start1 = match.index;
358
+ var matched1 = match[0];
359
+ if (typeof start1 !== 'number' || !matched1) continue;
360
+ var openLen = 2; // {{
361
+ var closeLen = 2; // }}
362
+ var innerStart = start1 + openLen;
363
+ var innerEnd = start1 + matched1.length - closeLen;
364
+ var innerContent = matched1.slice(openLen, matched1.length - closeLen);
365
+ addRange(start1, innerStart, 'jinjaDelimiter');
366
+ var varTokens = tokenizeJinjaVariableContent(innerContent, innerStart);
367
+ if (varTokens.length > 0) {
368
+ varTokens.forEach(function(t) {
369
+ return addRange(t.start, t.end, t.prop);
370
+ });
371
+ } else if (innerContent.trim()) {
372
+ addRange(innerStart, innerEnd, 'jinjaVariableName');
373
+ }
374
+ addRange(innerEnd, start1 + matched1.length, 'jinjaDelimiter');
375
+ }
376
+ // 标签 {% %}:细粒度高亮
377
+ JINJA_TAG_REG.lastIndex = 0;
378
+ while((match = JINJA_TAG_REG.exec(fullText)) !== null){
379
+ var start2 = match.index;
380
+ var matched2 = match[0];
381
+ if (typeof start2 !== 'number' || !matched2) continue;
382
+ var openLen1 = 2; // {%
383
+ var closeLen1 = 2; // %}
384
+ var innerStart1 = start2 + openLen1;
385
+ var innerEnd1 = start2 + matched2.length - closeLen1;
386
+ var innerContent1 = matched2.slice(openLen1, matched2.length - closeLen1);
387
+ addRange(start2, innerStart1, 'jinjaDelimiter');
388
+ var tagTokens = tokenizeJinjaTagContent(innerContent1, innerStart1);
389
+ tagTokens.forEach(function(t) {
390
+ return addRange(t.start, t.end, t.prop);
391
+ });
392
+ addRange(innerEnd1, start2 + matched2.length, 'jinjaDelimiter');
393
+ }
235
394
  return ranges;
236
395
  };
237
396
  export function useHighlight(store, jinjaEnabled) {