@ant-design/agentic-ui 2.29.27 → 2.29.29
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.
- package/dist/Bubble/UserBubble.js +7 -7
- package/dist/Bubble/schema-editor/SchemaEditorBridgeManager.d.ts +4 -0
- package/dist/Bubble/schema-editor/SchemaEditorBridgeManager.js +9 -0
- package/dist/MarkdownEditor/BaseMarkdownEditor.js +29 -4
- package/dist/MarkdownEditor/editor/Editor.js +2 -2
- package/dist/MarkdownEditor/editor/elements/index.js +9 -0
- package/dist/MarkdownEditor/editor/plugins/useHighlight.d.ts +1 -1
- package/dist/MarkdownEditor/editor/plugins/useHighlight.js +25 -1
- package/dist/MarkdownEditor/editor/plugins/useKeyboard.js +30 -2
- package/dist/MarkdownEditor/editor/store.d.ts +12 -0
- package/dist/MarkdownEditor/editor/store.js +7 -1
- package/dist/MarkdownEditor/editor/style.js +10 -0
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/index.d.ts +2 -0
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/index.js +327 -0
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/style.d.ts +9 -0
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/style.js +131 -0
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/templates.d.ts +5 -0
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/templates.js +28 -0
- package/dist/MarkdownEditor/editor/utils/media.js +4 -4
- package/dist/MarkdownEditor/el.d.ts +3 -0
- package/dist/MarkdownEditor/plugin.d.ts +5 -0
- package/dist/MarkdownEditor/plugins/jinja.d.ts +21 -0
- package/dist/MarkdownEditor/plugins/jinja.js +70 -0
- package/dist/MarkdownEditor/types.d.ts +38 -1
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileIcon.js +182 -3
- package/dist/MarkdownInputField/AttachmentButton/utils.d.ts +12 -0
- package/dist/MarkdownInputField/AttachmentButton/utils.js +42 -0
- package/dist/MarkdownInputField/FileMapView/index.js +111 -15
- package/dist/MarkdownInputField/FileMapView/style.js +45 -0
- package/dist/TaskList/index.d.ts +1 -1
- package/dist/ThoughtChainList/CostMillis.d.ts +15 -0
- package/dist/ThoughtChainList/CostMillis.js +1 -1
- package/dist/index.d.ts +16 -15
- package/dist/index.js +16 -15
- package/package.json +1 -1
|
@@ -202,7 +202,12 @@ var getContentStyle = function getContentStyle(standalone, customStyle) {
|
|
|
202
202
|
style: styles === null || styles === void 0 ? void 0 : styles.bubbleListItemExtraStyle,
|
|
203
203
|
className: cx("".concat(prefixClass, "-bubble-before"), "".concat(prefixClass, "-bubble-before-").concat(placement), "".concat(prefixClass, "-bubble-before-user"), hashId),
|
|
204
204
|
"data-testid": "message-before"
|
|
205
|
-
}, contentBeforeDom),
|
|
205
|
+
}, contentBeforeDom), /*#__PURE__*/ React.createElement("div", {
|
|
206
|
+
style: contentStyle,
|
|
207
|
+
className: cx("".concat(prefixClass, "-bubble-content"), "".concat(prefixClass, "-bubble-content-").concat(placement), "".concat(prefixClass, "-bubble-content-user"), _define_property({}, "".concat(prefixClass, "-bubble-content-pure"), props.pure), classNames === null || classNames === void 0 ? void 0 : classNames.bubbleListItemContentClassName, hashId),
|
|
208
|
+
onDoubleClick: props.onDoubleClick,
|
|
209
|
+
"data-testid": "message-content"
|
|
210
|
+
}, childrenDom), hasFileMap && /*#__PURE__*/ React.createElement("div", {
|
|
206
211
|
style: fileViewStyle,
|
|
207
212
|
className: cx("".concat(prefixClass, "-bubble-after"), "".concat(prefixClass, "-bubble-after-").concat(placement), "".concat(prefixClass, "-bubble-after-ai"), hashId),
|
|
208
213
|
"data-testid": "message-after"
|
|
@@ -210,12 +215,7 @@ var getContentStyle = function getContentStyle(standalone, customStyle) {
|
|
|
210
215
|
bubbleListRef: props.bubbleListRef,
|
|
211
216
|
bubble: props,
|
|
212
217
|
placement: placement
|
|
213
|
-
})),
|
|
214
|
-
style: contentStyle,
|
|
215
|
-
className: cx("".concat(prefixClass, "-bubble-content"), "".concat(prefixClass, "-bubble-content-").concat(placement), "".concat(prefixClass, "-bubble-content-user"), _define_property({}, "".concat(prefixClass, "-bubble-content-pure"), props.pure), classNames === null || classNames === void 0 ? void 0 : classNames.bubbleListItemContentClassName, hashId),
|
|
216
|
-
onDoubleClick: props.onDoubleClick,
|
|
217
|
-
"data-testid": "message-content"
|
|
218
|
-
}, childrenDom), contentAfterDom)))));
|
|
218
|
+
})), contentAfterDom)))));
|
|
219
219
|
if ((bubbleRenderConfig === null || bubbleRenderConfig === void 0 ? void 0 : bubbleRenderConfig.render) === false) return null;
|
|
220
220
|
return /*#__PURE__*/ React.createElement(MessagesContext.Provider, {
|
|
221
221
|
value: {
|
|
@@ -134,6 +134,15 @@ import { MarkdownEditor } from "../../MarkdownEditor";
|
|
|
134
134
|
return this.registry.has(id);
|
|
135
135
|
}
|
|
136
136
|
},
|
|
137
|
+
{
|
|
138
|
+
/**
|
|
139
|
+
* 获取指定 id 的当前内容(用于测试或调试)
|
|
140
|
+
*/ key: "getContentById",
|
|
141
|
+
value: function getContentById(id) {
|
|
142
|
+
var handler = this.registry.get(id);
|
|
143
|
+
return handler === null || handler === void 0 ? void 0 : handler.getContent();
|
|
144
|
+
}
|
|
145
|
+
},
|
|
137
146
|
{
|
|
138
147
|
key: "startBridge",
|
|
139
148
|
value: /**
|
|
@@ -136,6 +136,10 @@ function _sliced_to_array(arr, i) {
|
|
|
136
136
|
function _to_consumable_array(arr) {
|
|
137
137
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
138
138
|
}
|
|
139
|
+
function _type_of(obj) {
|
|
140
|
+
"@swc/helpers - typeof";
|
|
141
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
142
|
+
}
|
|
139
143
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
140
144
|
if (!o) return;
|
|
141
145
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -161,6 +165,7 @@ import { withErrorReporting } from "./editor/plugins/catchError";
|
|
|
161
165
|
import { EditorStore, EditorStoreContext } from "./editor/store";
|
|
162
166
|
import { InsertAutocomplete } from "./editor/tools/InsertAutocomplete";
|
|
163
167
|
import { InsertLink } from "./editor/tools/InsertLink";
|
|
168
|
+
import { JinjaTemplatePanel } from "./editor/tools/JinjaTemplatePanel";
|
|
164
169
|
import { TocHeading } from "./editor/tools/Leading";
|
|
165
170
|
import { FloatBar } from "./editor/tools/ToolBar/FloatBar";
|
|
166
171
|
import ToolBar from "./editor/tools/ToolBar/ToolBar";
|
|
@@ -244,7 +249,7 @@ var I18nBoundary = function I18nBoundary(param) {
|
|
|
244
249
|
* - 提供Markdown解析和渲染
|
|
245
250
|
*/ export var BaseMarkdownEditor = function BaseMarkdownEditor(props) {
|
|
246
251
|
var _props_typewriter, _props_readonly;
|
|
247
|
-
var _props_floatBar, _props_floatBar1, _props_textAreaProps;
|
|
252
|
+
var _props_jinja, _effectiveJinja_templatePanel, _props_floatBar, _props_floatBar1, _props_textAreaProps;
|
|
248
253
|
var initValue = props.initValue, width = props.width, _props_toolBar = props.toolBar, toolBar = _props_toolBar === void 0 ? {} : _props_toolBar, editorRef = props.editorRef, _props_toc = props.toc, toc = _props_toc === void 0 ? false : _props_toc, readonly = props.readonly, lazy = props.lazy, style = props.style, _props_contentStyle = props.contentStyle, contentStyle = _props_contentStyle === void 0 ? {
|
|
249
254
|
height: '100%'
|
|
250
255
|
} : _props_contentStyle, editorStyle = props.editorStyle, height = props.height, children = props.children, rest = _object_without_properties(props, [
|
|
@@ -395,6 +400,18 @@ var I18nBoundary = function I18nBoundary(param) {
|
|
|
395
400
|
return new Subject();
|
|
396
401
|
}, []);
|
|
397
402
|
var _useState6 = _sliced_to_array(useState(null), 2), domRect = _useState6[0], setDomRect = _useState6[1];
|
|
403
|
+
var jinjaEnabled = ((_props_jinja = props.jinja) === null || _props_jinja === void 0 ? void 0 : _props_jinja.enable) === true || Array.isArray(props.plugins) && props.plugins.some(function(p) {
|
|
404
|
+
return p.jinja === true;
|
|
405
|
+
});
|
|
406
|
+
var pluginWithJinja = Array.isArray(props.plugins) ? props.plugins.find(function(p) {
|
|
407
|
+
return p.jinja === true;
|
|
408
|
+
}) : undefined;
|
|
409
|
+
var effectiveJinja = props.jinja ? props.jinja : (pluginWithJinja === null || pluginWithJinja === void 0 ? void 0 : pluginWithJinja.jinjaConfig) ? pluginWithJinja.jinjaConfig : pluginWithJinja ? {
|
|
410
|
+
enable: true
|
|
411
|
+
} : undefined;
|
|
412
|
+
var jinjaTemplatePanelEnabled = jinjaEnabled && effectiveJinja !== undefined && effectiveJinja !== null && effectiveJinja.templatePanel !== false && (_type_of(effectiveJinja.templatePanel) !== 'object' || ((_effectiveJinja_templatePanel = effectiveJinja.templatePanel) === null || _effectiveJinja_templatePanel === void 0 ? void 0 : _effectiveJinja_templatePanel.enable) !== false);
|
|
413
|
+
var _useState7 = _sliced_to_array(useState(false), 2), openJinjaTemplate = _useState7[0], setOpenJinjaTemplate = _useState7[1];
|
|
414
|
+
var _useState8 = _sliced_to_array(useState(null), 2), jinjaAnchorPath = _useState8[0], setJinjaAnchorPath = _useState8[1];
|
|
398
415
|
var _obj;
|
|
399
416
|
return wrapSSR(/*#__PURE__*/ React.createElement(I18nBoundary, null, /*#__PURE__*/ React.createElement(PluginContext.Provider, {
|
|
400
417
|
value: props.plugins || []
|
|
@@ -414,9 +431,17 @@ var I18nBoundary = function I18nBoundary(param) {
|
|
|
414
431
|
setDomRect: setDomRect,
|
|
415
432
|
typewriter: (_props_typewriter = props.typewriter) !== null && _props_typewriter !== void 0 ? _props_typewriter : false,
|
|
416
433
|
readonly: (_props_readonly = props.readonly) !== null && _props_readonly !== void 0 ? _props_readonly : false,
|
|
417
|
-
editorProps:
|
|
434
|
+
editorProps: effectiveJinja !== undefined ? _object_spread_props(_object_spread({}, props), {
|
|
435
|
+
jinja: effectiveJinja
|
|
436
|
+
}) : props || {},
|
|
418
437
|
markdownEditorRef: markdownEditorRef,
|
|
419
|
-
markdownContainerRef: markdownContainerRef
|
|
438
|
+
markdownContainerRef: markdownContainerRef,
|
|
439
|
+
openJinjaTemplate: openJinjaTemplate,
|
|
440
|
+
setOpenJinjaTemplate: setOpenJinjaTemplate,
|
|
441
|
+
jinjaAnchorPath: jinjaAnchorPath,
|
|
442
|
+
setJinjaAnchorPath: setJinjaAnchorPath,
|
|
443
|
+
jinjaEnabled: jinjaEnabled,
|
|
444
|
+
jinjaTemplatePanelEnabled: jinjaTemplatePanelEnabled
|
|
420
445
|
}
|
|
421
446
|
}, /*#__PURE__*/ React.createElement("div", {
|
|
422
447
|
id: props.id ? String(props.id) || undefined : undefined,
|
|
@@ -473,5 +498,5 @@ var I18nBoundary = function I18nBoundary(param) {
|
|
|
473
498
|
comment: props.comment
|
|
474
499
|
}) : null), readonly || (props === null || props === void 0 ? void 0 : (_props_textAreaProps = props.textAreaProps) === null || _props_textAreaProps === void 0 ? void 0 : _props_textAreaProps.enable) || (props === null || props === void 0 ? void 0 : props.reportMode) ? null : /*#__PURE__*/ React.createElement("div", {
|
|
475
500
|
className: classNames("".concat(baseClassName, "-focus"))
|
|
476
|
-
}), readonly ? /*#__PURE__*/ React.createElement(React.Fragment, null) : /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(InsertLink, null), /*#__PURE__*/ React.createElement(InsertAutocomplete, (props === null || props === void 0 ? void 0 : props.insertAutocompleteProps) || {})), children)))));
|
|
501
|
+
}), readonly ? /*#__PURE__*/ React.createElement(React.Fragment, null) : /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(InsertLink, null), /*#__PURE__*/ React.createElement(InsertAutocomplete, (props === null || props === void 0 ? void 0 : props.insertAutocompleteProps) || {}), jinjaTemplatePanelEnabled ? /*#__PURE__*/ React.createElement(JinjaTemplatePanel, null) : null), children)))));
|
|
477
502
|
};
|
|
@@ -325,7 +325,7 @@ var defaultAllowedTypes = [
|
|
|
325
325
|
*/ export var SlateMarkdownEditor = function SlateMarkdownEditor(props) {
|
|
326
326
|
var _markdownEditorRef_current, _props_textAreaProps, _props_comment, _markdownEditorRef_current1;
|
|
327
327
|
// 所有hooks必须在组件顶部按固定顺序调用
|
|
328
|
-
var _useEditorStore = useEditorStore(), store = _useEditorStore.store, markdownEditorRef = _useEditorStore.markdownEditorRef, markdownContainerRef = _useEditorStore.markdownContainerRef, readonly = _useEditorStore.readonly, setDomRect = _useEditorStore.setDomRect;
|
|
328
|
+
var _useEditorStore = useEditorStore(), store = _useEditorStore.store, markdownEditorRef = _useEditorStore.markdownEditorRef, markdownContainerRef = _useEditorStore.markdownContainerRef, readonly = _useEditorStore.readonly, setDomRect = _useEditorStore.setDomRect, jinjaEnabled = _useEditorStore.jinjaEnabled;
|
|
329
329
|
// 懒加载元素索引计数器
|
|
330
330
|
var lazyElementIndexRef = useRef(0);
|
|
331
331
|
// 用于标记是否已在当前渲染周期重置过索引
|
|
@@ -357,7 +357,7 @@ var defaultAllowedTypes = [
|
|
|
357
357
|
var plugins = useContext(PluginContext);
|
|
358
358
|
var onKeyDown = useKeyboard(store, markdownEditorRef, props);
|
|
359
359
|
var onChange = useOnchange(markdownEditorRef.current, props.onChange);
|
|
360
|
-
var high = useHighlight(store);
|
|
360
|
+
var high = useHighlight(store, jinjaEnabled);
|
|
361
361
|
var childrenIsEmpty = useMemo(function() {
|
|
362
362
|
var _markdownEditorRef_current;
|
|
363
363
|
if (!((_markdownEditorRef_current = markdownEditorRef.current) === null || _markdownEditorRef_current === void 0 ? void 0 : _markdownEditorRef_current.children)) return false;
|
|
@@ -410,6 +410,15 @@ var MLeafComponent = function MLeafComponent(props) {
|
|
|
410
410
|
if (leaf.html) {
|
|
411
411
|
prefixClassName = classNames(mdEditorBaseClass + '-m-html');
|
|
412
412
|
}
|
|
413
|
+
if (leaf.jinjaVariable) {
|
|
414
|
+
prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-variable"));
|
|
415
|
+
}
|
|
416
|
+
if (leaf.jinjaTag) {
|
|
417
|
+
prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-tag"));
|
|
418
|
+
}
|
|
419
|
+
if (leaf.jinjaComment) {
|
|
420
|
+
prefixClassName = classNames(prefixClassName, "".concat(mdEditorBaseClass, "-jinja-comment"));
|
|
421
|
+
}
|
|
413
422
|
if (leaf.current) {
|
|
414
423
|
style.background = '#f59e0b';
|
|
415
424
|
}
|
|
@@ -5,4 +5,4 @@ export declare const cacheTextNode: WeakMap<object, {
|
|
|
5
5
|
range: Range[];
|
|
6
6
|
}>;
|
|
7
7
|
export declare const clearInlineKatex: (editor: Editor) => void;
|
|
8
|
-
export declare function useHighlight(store?: EditorStore): ([node, path]: NodeEntry) => Range[];
|
|
8
|
+
export declare function useHighlight(store?: EditorStore, jinjaEnabled?: boolean): ([node, path]: NodeEntry) => Range[];
|
|
@@ -91,6 +91,9 @@ var HTML_REG = /<[a-z]+[\s"'=:;()\w\-[\]/.]*\/?>(.*<\/[a-z]+>:?)?/g;
|
|
|
91
91
|
var LINK_REG = /(https?|ftp):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/gi;
|
|
92
92
|
var FOOTNOTE_REG = /\[\^[^\]]+\]/g;
|
|
93
93
|
var TABLE_ROW_REG = /^\|([^|]+\|)+$/;
|
|
94
|
+
/** 至少一个非 } 字符,避免匹配 {{}}、{{ 等不完整表达式 */ var JINJA_VARIABLE_REG = /\{\{[^}]+\}\}/g;
|
|
95
|
+
/** 至少一个非 % 字符,避免匹配 {%%} */ var JINJA_TAG_REG = /\{%[^%]+%\}/g;
|
|
96
|
+
/** 单行内注释,避免跨多行高亮造成大段误匹配(编辑器场景) */ var JINJA_COMMENT_REG = /\{#[^\n]*?#\}/g;
|
|
94
97
|
export var cacheTextNode = new WeakMap();
|
|
95
98
|
export var clearInlineKatex = function clearInlineKatex(editor) {
|
|
96
99
|
var inlineMath = Array.from(Editor.nodes(editor, {
|
|
@@ -172,7 +175,24 @@ var processLinkMatches = function processLinkMatches(text, path, childIndex) {
|
|
|
172
175
|
}
|
|
173
176
|
return ranges;
|
|
174
177
|
};
|
|
175
|
-
|
|
178
|
+
var processJinjaMatches = function processJinjaMatches(text, path, childIndex) {
|
|
179
|
+
var ranges = [];
|
|
180
|
+
var collect = function collect(reg, prop) {
|
|
181
|
+
reg.lastIndex = 0;
|
|
182
|
+
var match;
|
|
183
|
+
while((match = reg.exec(text)) !== null){
|
|
184
|
+
var index = match.index;
|
|
185
|
+
if (typeof index === 'number') {
|
|
186
|
+
ranges.push(createRange(path, childIndex, index, match[0].length, _define_property({}, prop, true)));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
collect(JINJA_VARIABLE_REG, 'jinjaVariable');
|
|
191
|
+
collect(JINJA_TAG_REG, 'jinjaTag');
|
|
192
|
+
collect(JINJA_COMMENT_REG, 'jinjaComment');
|
|
193
|
+
return ranges;
|
|
194
|
+
};
|
|
195
|
+
export function useHighlight(store, jinjaEnabled) {
|
|
176
196
|
return function(param) {
|
|
177
197
|
var _param = _sliced_to_array(param, 2), node = _param[0], path = _param[1];
|
|
178
198
|
// 快速路径:非元素节点或不在高亮节点列表中
|
|
@@ -204,6 +224,10 @@ export function useHighlight(store) {
|
|
|
204
224
|
var _allTextRanges1;
|
|
205
225
|
(_allTextRanges1 = allTextRanges).push.apply(_allTextRanges1, _to_consumable_array(processLinkMatches(child.text, path, i)));
|
|
206
226
|
}
|
|
227
|
+
if (jinjaEnabled && child.text && !EditorUtils.isDirtLeaf(child)) {
|
|
228
|
+
var _allTextRanges2;
|
|
229
|
+
(_allTextRanges2 = allTextRanges).push.apply(_allTextRanges2, _to_consumable_array(processJinjaMatches(child.text, path, i)));
|
|
230
|
+
}
|
|
207
231
|
}
|
|
208
232
|
// 统一缓存
|
|
209
233
|
cacheTextNode.set(node, {
|
|
@@ -36,6 +36,10 @@ function _non_iterable_rest() {
|
|
|
36
36
|
function _sliced_to_array(arr, i) {
|
|
37
37
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
38
38
|
}
|
|
39
|
+
function _type_of(obj) {
|
|
40
|
+
"@swc/helpers - typeof";
|
|
41
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
42
|
+
}
|
|
39
43
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
40
44
|
if (!o) return;
|
|
41
45
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -94,7 +98,10 @@ import { useEditorStore } from "../store";
|
|
|
94
98
|
* - 与编辑器状态深度集成,实现上下文相关的行为
|
|
95
99
|
* - 提供良好的用户体验和 Markdown 编辑效率
|
|
96
100
|
*/ export var useKeyboard = function useKeyboard(store, markdownEditorRef, props) {
|
|
97
|
-
var _useEditorStore = useEditorStore(), openInsertCompletion = _useEditorStore.openInsertCompletion, insertCompletionText$ = _useEditorStore.insertCompletionText$, setOpenInsertCompletion = _useEditorStore.setOpenInsertCompletion;
|
|
101
|
+
var _useEditorStore = useEditorStore(), openInsertCompletion = _useEditorStore.openInsertCompletion, insertCompletionText$ = _useEditorStore.insertCompletionText$, setOpenInsertCompletion = _useEditorStore.setOpenInsertCompletion, openJinjaTemplate = _useEditorStore.openJinjaTemplate, setOpenJinjaTemplate = _useEditorStore.setOpenJinjaTemplate, setJinjaAnchorPath = _useEditorStore.setJinjaAnchorPath, jinjaTemplatePanelEnabled = _useEditorStore.jinjaTemplatePanelEnabled, editorProps = _useEditorStore.editorProps;
|
|
102
|
+
// 从 editorProps.jinja 读取(BaseMarkdownEditor 已写入 effectiveJinja),支持插件配置的 trigger
|
|
103
|
+
var effectiveJinja = editorProps === null || editorProps === void 0 ? void 0 : editorProps.jinja;
|
|
104
|
+
var jinjaTrigger = (effectiveJinja === null || effectiveJinja === void 0 ? void 0 : effectiveJinja.templatePanel) && _type_of(effectiveJinja.templatePanel) === 'object' && effectiveJinja.templatePanel.trigger || '{}';
|
|
98
105
|
return useMemo(function() {
|
|
99
106
|
var tab = new TabKey(markdownEditorRef.current);
|
|
100
107
|
var backspace = new BackspaceKey(markdownEditorRef.current);
|
|
@@ -114,6 +121,10 @@ import { useEditorStore } from "../store";
|
|
|
114
121
|
e.preventDefault();
|
|
115
122
|
return;
|
|
116
123
|
}
|
|
124
|
+
if (openJinjaTemplate && (isHotkey('up', e) || isHotkey('down', e))) {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
117
128
|
if (isHotkey('mod+ArrowDown', e)) {
|
|
118
129
|
e.preventDefault();
|
|
119
130
|
Transforms.select(markdownEditorRef.current, Editor.end(markdownEditorRef.current, []));
|
|
@@ -239,6 +250,15 @@ import { useEditorStore } from "../store";
|
|
|
239
250
|
var str = Node.string(node3[0]) || '';
|
|
240
251
|
var codeMatch = str.match(/^```([\w+\-#]+)$/i);
|
|
241
252
|
if (codeMatch) {} else {
|
|
253
|
+
var strAfterKey = str + (e.key.length === 1 ? e.key : '');
|
|
254
|
+
// 仅在实际输入一个字符且刚好补全 trigger 时打开面板,避免 Backspace 等导致误打开
|
|
255
|
+
if (jinjaTemplatePanelEnabled && e.key.length === 1 && strAfterKey === jinjaTrigger && setOpenJinjaTemplate && setJinjaAnchorPath) {
|
|
256
|
+
setJinjaAnchorPath(node3[1]);
|
|
257
|
+
setTimeout(function() {
|
|
258
|
+
return setOpenJinjaTemplate(true);
|
|
259
|
+
});
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
242
262
|
var insertMatch = str.match(/^\/([^\n]+)?$/i);
|
|
243
263
|
if (insertMatch && !(!Path.hasPrevious(node3[1]) && Node.parent(markdownEditorRef.current, node3[1]).type === 'list-item')) {
|
|
244
264
|
setOpenInsertCompletion === null || setOpenInsertCompletion === void 0 ? void 0 : setOpenInsertCompletion(true);
|
|
@@ -252,6 +272,14 @@ import { useEditorStore } from "../store";
|
|
|
252
272
|
};
|
|
253
273
|
}, [
|
|
254
274
|
markdownEditorRef.current,
|
|
255
|
-
props === null || props === void 0 ? void 0 : props.readonly
|
|
275
|
+
props === null || props === void 0 ? void 0 : props.readonly,
|
|
276
|
+
openInsertCompletion,
|
|
277
|
+
insertCompletionText$,
|
|
278
|
+
setOpenInsertCompletion,
|
|
279
|
+
openJinjaTemplate,
|
|
280
|
+
setOpenJinjaTemplate,
|
|
281
|
+
setJinjaAnchorPath,
|
|
282
|
+
jinjaTemplatePanelEnabled,
|
|
283
|
+
jinjaTrigger
|
|
256
284
|
]);
|
|
257
285
|
};
|
|
@@ -46,6 +46,18 @@ export interface EditorStoreContextType {
|
|
|
46
46
|
openInsertCompletion?: boolean;
|
|
47
47
|
/** 设置打开插入自动完成状态 */
|
|
48
48
|
setOpenInsertCompletion?: (open: boolean) => void;
|
|
49
|
+
/** 是否打开 Jinja 模板面板 */
|
|
50
|
+
openJinjaTemplate?: boolean;
|
|
51
|
+
/** 设置打开 Jinja 模板面板状态 */
|
|
52
|
+
setOpenJinjaTemplate?: (open: boolean) => void;
|
|
53
|
+
/** Jinja 弹层插入锚点 path(当前段落节点 path) */
|
|
54
|
+
jinjaAnchorPath?: number[] | null;
|
|
55
|
+
/** 设置 Jinja 弹层锚点 path */
|
|
56
|
+
setJinjaAnchorPath?: (path: number[] | null) => void;
|
|
57
|
+
/** 是否启用 Jinja(总开关,用于语法高亮等) */
|
|
58
|
+
jinjaEnabled?: boolean;
|
|
59
|
+
/** 是否启用 Jinja 模板面板(用于触发与弹层) */
|
|
60
|
+
jinjaTemplatePanelEnabled?: boolean;
|
|
49
61
|
/** 编辑器属性配置 */
|
|
50
62
|
editorProps: MarkdownEditorProps;
|
|
51
63
|
/** Markdown编辑器引用 */
|
|
@@ -163,7 +163,13 @@ export var EditorStoreContext = createContext(null);
|
|
|
163
163
|
readonly: true,
|
|
164
164
|
typewriter: false,
|
|
165
165
|
editorProps: {},
|
|
166
|
-
markdownEditorRef: {}
|
|
166
|
+
markdownEditorRef: {},
|
|
167
|
+
openJinjaTemplate: false,
|
|
168
|
+
setOpenJinjaTemplate: undefined,
|
|
169
|
+
jinjaAnchorPath: null,
|
|
170
|
+
setJinjaAnchorPath: undefined,
|
|
171
|
+
jinjaEnabled: false,
|
|
172
|
+
jinjaTemplatePanelEnabled: false
|
|
167
173
|
};
|
|
168
174
|
};
|
|
169
175
|
/** 支持键入操作的标签类型列表 */ var SUPPORT_TYPING_TAG = [
|
|
@@ -529,6 +529,16 @@ var genStyle = function genStyle(token) {
|
|
|
529
529
|
'& &-m-html': {
|
|
530
530
|
color: 'rgba(0,0,0,0.45)'
|
|
531
531
|
},
|
|
532
|
+
'& &-jinja-variable': {
|
|
533
|
+
color: 'var(--color-primary-control-fill-primary, #1677ff)'
|
|
534
|
+
},
|
|
535
|
+
'& &-jinja-tag': {
|
|
536
|
+
color: 'var(--color-orange-6, #d46b08)'
|
|
537
|
+
},
|
|
538
|
+
'& &-jinja-comment': {
|
|
539
|
+
color: 'var(--color-text-tertiary, rgba(0,0,0,0.25))',
|
|
540
|
+
fontStyle: 'italic'
|
|
541
|
+
},
|
|
532
542
|
'&:not(:last-child)': {
|
|
533
543
|
marginBottom: '0.5em'
|
|
534
544
|
},
|