🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(editor): add alert, chart and footnote to the document slash menu (#21826)
Inneiac5485dc1db5
diff --git a/locales/en-US/editor.json b/locales/en-US/editor.jsonindex ace33da99a9..99a4fa0b8eb 100644--- a/locales/en-US/editor.json+++ b/locales/en-US/editor.json@@ -126,7 +126,10 @@"skillFrontmatter.invalid.syntax": "Invalid YAML syntax.","skillFrontmatter.saveFailed": "Metadata was not saved. Retry, or keep editing.","skillFrontmatter.title": "Skill metadata",+ "slash.alert": "Alert",+ "slash.chart": "Chart","slash.compact": "Compact context",+ "slash.footnote": "Footnote","slash.goal": "Goal","slash.goal.desc": "Plan and start a goal with editable acceptance criteria","slash.h1": "Heading 1",diff --git a/locales/zh-CN/editor.json b/locales/zh-CN/editor.jsonindex 3b54c027c3d..a73a1591b49 100644--- a/locales/zh-CN/editor.json+++ b/locales/zh-CN/editor.json@@ -126,7 +126,10 @@"skillFrontmatter.invalid.syntax": "YAML 语法无效。","skillFrontmatter.saveFailed": "元信息未保存。请重试,或继续编辑。","skillFrontmatter.title": "技能元信息",+ "slash.alert": "提示块",+ "slash.chart": "图表","slash.compact": "压缩上下文",+ "slash.footnote": "脚注","slash.goal": "目标","slash.goal.desc": "规划并启动带有可编辑验收标准的目标","slash.h1": "一级标题",diff --git a/packages/locales/src/default/editor.ts b/packages/locales/src/default/editor.tsindex a70c32d8720..d6f0fff7592 100644--- a/packages/locales/src/default/editor.ts+++ b/packages/locales/src/default/editor.ts@@ -54,7 +54,10 @@ export default {"Sent as a slash invocation so the agent's CLI runs the matching project skill.",'actionTag.tooltip.skill': 'Loads a reusable skill package for this request.','actionTag.tooltip.tool': 'Marks a tool the user explicitly selected for this request.',+ 'slash.alert': 'Alert',+ 'slash.chart': 'Chart','slash.compact': 'Compact context',+ 'slash.footnote': 'Footnote','slash.goal': 'Goal','slash.goal.desc': 'Plan and start a goal with editable acceptance criteria','slash.h1': 'Heading 1',diff --git a/src/features/PageEditor/EditorCanvas/useSlashItems.test.ts b/src/features/PageEditor/EditorCanvas/useSlashItems.test.tsnew file mode 100644index 00000000000..2704f1f231c--- /dev/null+++ b/src/features/PageEditor/EditorCanvas/useSlashItems.test.ts@@ -0,0 +1,49 @@+import {+ INSERT_ALERT_COMMAND,+ INSERT_CHART_COMMAND,+ INSERT_FOOTNOTE_COMMAND,+ type SlashOptions,+} from '@lobehub/editor';+import { renderHook } from '@testing-library/react';+import { describe, expect, it, vi } from 'vitest';++import { useSlashItems } from './useSlashItems';++vi.mock('@lobehub/editor', () => ({+ INSERT_ALERT_COMMAND: 'INSERT_ALERT_COMMAND',+ INSERT_CHART_COMMAND: 'INSERT_CHART_COMMAND',+ INSERT_CHECK_LIST_COMMAND: 'INSERT_CHECK_LIST_COMMAND',+ INSERT_CODEMIRROR_COMMAND: 'INSERT_CODEMIRROR_COMMAND',+ INSERT_FOOTNOTE_COMMAND: 'INSERT_FOOTNOTE_COMMAND',+ INSERT_HEADING_COMMAND: 'INSERT_HEADING_COMMAND',+ INSERT_HORIZONTAL_RULE_COMMAND: 'INSERT_HORIZONTAL_RULE_COMMAND',+ INSERT_IMAGE_COMMAND: 'INSERT_IMAGE_COMMAND',+ INSERT_MATH_COMMAND: 'INSERT_MATH_COMMAND',+ INSERT_ORDERED_LIST_COMMAND: 'INSERT_ORDERED_LIST_COMMAND',+ INSERT_TABLE_COMMAND: 'INSERT_TABLE_COMMAND',+ INSERT_UNORDERED_LIST_COMMAND: 'INSERT_UNORDERED_LIST_COMMAND',+}));++vi.mock('@/features/EditorCanvas', () => ({ openFileSelector: vi.fn() }));++type SlashItem = Extract<NonNullable<SlashOptions['items']>[number], { key: string }>;++const findItem = (items: SlashOptions['items'], key: string) =>+ (items as SlashItem[]).find((item) => item.key === key);++describe('useSlashItems', () => {+ it.each([+ ['alert', INSERT_ALERT_COMMAND],+ ['chart', INSERT_CHART_COMMAND],+ ['footnote', INSERT_FOOTNOTE_COMMAND],+ ])('inserts a %s block from the slash menu', (key, command) => {+ const { result } = renderHook(() => useSlashItems());+ const item = findItem(result.current, key);+ const editor = { dispatchCommand: vi.fn(), focus: vi.fn() };++ expect(item).toBeDefined();+ item!.onSelect!(editor as any, {} as any);++ expect(editor.dispatchCommand).toHaveBeenCalledWith(command, undefined);+ });+});diff --git a/src/features/PageEditor/EditorCanvas/useSlashItems.tsx b/src/features/PageEditor/EditorCanvas/useSlashItems.tsxindex 0c120dd37cf..40f2f9de2af 100644--- a/src/features/PageEditor/EditorCanvas/useSlashItems.tsx+++ b/src/features/PageEditor/EditorCanvas/useSlashItems.tsx@@ -1,7 +1,10 @@import { type SlashOptions } from '@lobehub/editor';import {+ INSERT_ALERT_COMMAND,+ INSERT_CHART_COMMAND,INSERT_CHECK_LIST_COMMAND,INSERT_CODEMIRROR_COMMAND,+ INSERT_FOOTNOTE_COMMAND,INSERT_HEADING_COMMAND,INSERT_HORIZONTAL_RULE_COMMAND,INSERT_IMAGE_COMMAND,@@ -12,6 +15,7 @@ import {} from '@lobehub/editor';import { Text } from '@lobehub/ui';import {+ ChartColumnIcon,Heading1Icon,Heading2Icon,Heading3Icon,@@ -19,9 +23,11 @@ import {ListIcon,ListOrderedIcon,ListTodoIcon,+ MessageSquareWarningIcon,MinusIcon,SigmaIcon,SquareDashedBottomCodeIcon,+ SuperscriptIcon,Table2Icon,} from 'lucide-react';import { useMemo } from 'react';@@ -118,6 +124,22 @@ export const useSlashItems = (): SlashOptions['items'] => {editor.dispatchCommand(INSERT_TABLE_COMMAND, { columns: '3', rows: '3' });},},+ {+ icon: MessageSquareWarningIcon,+ key: 'alert',+ label: t('slash.alert'),+ onSelect: (editor) => {+ editor.dispatchCommand(INSERT_ALERT_COMMAND, undefined);+ },+ },+ {+ icon: ChartColumnIcon,+ key: 'chart',+ label: t('slash.chart'),+ onSelect: (editor) => {+ editor.dispatchCommand(INSERT_CHART_COMMAND, undefined);+ },+ },{icon: SquareDashedBottomCodeIcon,key: 'codeblock',@@ -140,6 +162,14 @@ export const useSlashItems = (): SlashOptions['items'] => {});},},+ {+ icon: SuperscriptIcon,+ key: 'footnote',+ label: t('slash.footnote'),+ onSelect: (editor) => {+ editor.dispatchCommand(INSERT_FOOTNOTE_COMMAND, undefined);+ },+ },];return data.map((item) => {if (item.type === 'divider') return item;