@agent-arts/editor 0.0.2 → 0.0.4

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/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # @agent-arts/editor
2
+
3
+ 一个基于 CodeMirror 6 的提示词编辑器,框架无关,支持 Vue.js、Angular、React。
4
+
5
+ ## 特性
6
+
7
+ - 编辑块 edit-block:可编辑
8
+ - 插件块 plugin-block:不可编辑,通过大括号 `{` 呼起,用户插入插件、工作流、变量等
9
+ - AI 对话 ai-dialog:通过斜线 `/` 或拖选内容呼起,通过 AI 生成和优化提示词
10
+
11
+ ## 演示动画
12
+
13
+ ![演示动画](./product-animation.gif)
14
+
15
+ ## 使用
16
+
17
+ ### 安装
18
+
19
+ ```bash
20
+ npm install @agent-arts/editor
21
+ ```
22
+
23
+ ### 快速上手
24
+
25
+ ```typescript
26
+ import { CustomEditor, CustomEditorOptions } from '@agent-arts/editor';
27
+
28
+ const options: CustomEditorOptions = {
29
+ parent: document.querySelector('#editor')!,
30
+ initialDoc: '# 欢迎使用 AgentArts Editor',
31
+ onOpenPopup: (id, rect) => {
32
+ // 处理编辑块弹窗
33
+ },
34
+ onTriggerPluginPopup: (pos) => {
35
+ // 输入 '{' 时触发
36
+ },
37
+ onTriggerAIDialog: (pos) => {
38
+ // 输入 '/' 时触发
39
+ }
40
+ };
41
+
42
+ const editor = new CustomEditor(options);
43
+ ```
44
+
45
+ ### 插件配置
46
+
47
+ #### AI 对话插件 (AIDialogPlugin)
48
+
49
+ ```typescript
50
+ import { AIDialogPlugin } from '@agent-arts/editor';
51
+
52
+ const aiPlugin = new AIDialogPlugin({
53
+ onStream: (text) => { /* 处理流式输出 */ },
54
+ onLoading: (loading) => { /* 处理加载状态 */ },
55
+ onShow: (pos, style) => { /* 显示 AI 浮框 */ },
56
+ onHide: () => { /* 隐藏 AI 浮框 */ }
57
+ });
58
+ ```
59
+
60
+ #### 插件库浮框 (LibraryBlockPlugin)
61
+
62
+ ```typescript
63
+ import { LibraryBlockPlugin } from '@agent-arts/editor';
64
+
65
+ const libraryPlugin = new LibraryBlockPlugin({
66
+ onShow: (pos, style) => { /* 显示插件列表浮框 */ },
67
+ onHide: () => { /* 隐藏插件列表浮框 */ }
68
+ });
69
+
70
+ // 插入选中的插件块
71
+ editor.addPluginBlock(libraryPlugin.getTriggerPos(), {
72
+ id: 'plugin-id',
73
+ name: '插件名称',
74
+ type: 'plugin'
75
+ });
76
+ ```
77
+
78
+ #### 编辑块插件 (EditBlockPlugin)
79
+
80
+ ```typescript
81
+ import { EditBlockPlugin } from '@agent-arts/editor';
82
+
83
+ const editPlugin = new EditBlockPlugin({
84
+ onShow: (block, style) => { /* 显示编辑块配置浮框 */ },
85
+ onHide: () => { /* 隐藏浮框 */ }
86
+ });
87
+ ```
88
+
89
+ ### 核心 API
90
+
91
+ - `editor.addBlock()`: 手动添加一个新的编辑块。
92
+ - `editor.syncBlock(block)`: 同步外部状态到编辑器内部的块。
93
+ - `editor.getData()`: 获取编辑器的 JSON 数据和 HTML 内容。
94
+ - `editor.destroy()`: 销毁编辑器实例。
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@agent-arts/editor",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
+ "description": "A prompt editor based on CodeMirror 6, support Vue.js 3 and Angular.",
5
+ "author": "AgentArts Team",
6
+ "license": "MIT",
7
+ "homepage": "https://agent-arts.github.io/editor/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git@github.com:agent-arts/editor.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/agent-arts/editor"
14
+ },
15
+ "keywords": [
16
+ "prompt",
17
+ "editor",
18
+ "codemirror",
19
+ "agent-arts",
20
+ "typescript",
21
+ "ai",
22
+ "ai-agent"
23
+ ],
4
24
  "type": "module",
5
25
  "main": "./dist/editor.umd.cjs",
6
26
  "module": "./dist/editor.js",
@@ -13,7 +33,8 @@
13
33
  }
14
34
  },
15
35
  "files": [
16
- "dist"
36
+ "dist",
37
+ "product-animation.gif"
17
38
  ],
18
39
  "publishConfig": {
19
40
  "access": "public",
Binary file