@h-ai/ui 0.1.0-alpha.12 → 0.1.0-alpha.13
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/components/primitives/Switch.svelte +5 -0
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +1207 -144
- package/dist/components/scenes/ai/document-types.d.ts +26 -2
- package/dist/components/scenes/ai/editor-markdown-extensions.js +19 -4
- package/dist/messages/en-US.json +5 -0
- package/dist/messages/zh-CN.json +5 -0
- package/package.json +2 -2
|
@@ -65,7 +65,7 @@ export type MarkdownBlockFormatKind = 'heading' | 'bullet';
|
|
|
65
65
|
/**
|
|
66
66
|
* Rich block-style actions used by the current editor toolbar.
|
|
67
67
|
*/
|
|
68
|
-
export type MarkdownBlockStyleKind = 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'heading4';
|
|
68
|
+
export type MarkdownBlockStyleKind = 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'orderedList' | 'bulletList';
|
|
69
69
|
/**
|
|
70
70
|
* Inline format actions for the editor toolbar.
|
|
71
71
|
* `highlight` and `link` stay in the public union so older integrations keep compiling.
|
|
@@ -75,6 +75,14 @@ export type MarkdownInlineFormatKind = 'bold' | 'italic' | 'strike' | 'underline
|
|
|
75
75
|
* Paragraph alignment actions for the editor toolbar.
|
|
76
76
|
*/
|
|
77
77
|
export type MarkdownTextAlignKind = 'left' | 'center' | 'right' | 'justify';
|
|
78
|
+
export interface MarkdownSelectionSnapshot {
|
|
79
|
+
/** Selection start offset within the plain-text document. */
|
|
80
|
+
start: number;
|
|
81
|
+
/** Selection end offset within the plain-text document. */
|
|
82
|
+
end: number;
|
|
83
|
+
/** Selected plain text, used as a fallback when structure changes. */
|
|
84
|
+
text: string;
|
|
85
|
+
}
|
|
78
86
|
/**
|
|
79
87
|
* 颜色面板一次只会修改前景色或背景色中的一个维度。
|
|
80
88
|
*/
|
|
@@ -83,6 +91,18 @@ export interface MarkdownColorFormatRequest {
|
|
|
83
91
|
target: 'text' | 'background';
|
|
84
92
|
/** 颜色值为空时表示恢复默认。 */
|
|
85
93
|
value: string | null;
|
|
94
|
+
/** 当前工具条记住的选中文本,供外层在 DOM 重建后兜底恢复定位。 */
|
|
95
|
+
selectedText?: string;
|
|
96
|
+
/** 当前工具条记住的精确选区偏移,优先用于重复文本场景的恢复。 */
|
|
97
|
+
selectionSnapshot?: MarkdownSelectionSnapshot;
|
|
98
|
+
}
|
|
99
|
+
export interface MarkdownLinkFormatRequest {
|
|
100
|
+
/** 为空时表示移除当前链接。 */
|
|
101
|
+
href: string | null;
|
|
102
|
+
/** 当前工具条记住的精确选区偏移。 */
|
|
103
|
+
selectionSnapshot?: MarkdownSelectionSnapshot;
|
|
104
|
+
/** 当前工具条记住的选中文本,供宿主做文本兜底。 */
|
|
105
|
+
selectedText?: string;
|
|
86
106
|
}
|
|
87
107
|
export interface MarkdownToolbarDownloadAction {
|
|
88
108
|
/** Action id used to identify the download target. */
|
|
@@ -191,7 +211,11 @@ export interface AiDocumentEditorProps {
|
|
|
191
211
|
/** Paragraph alignment handler from the selection toolbar. */
|
|
192
212
|
onapplyalignment?: (kind: MarkdownTextAlignKind) => void;
|
|
193
213
|
/** Link add / edit / remove handler from the selection toolbar. */
|
|
194
|
-
onapplylink?:
|
|
214
|
+
onapplylink?: BivariantCallback<[
|
|
215
|
+
href: string | null,
|
|
216
|
+
selectionSnapshot?: MarkdownSelectionSnapshot,
|
|
217
|
+
selectedText?: string
|
|
218
|
+
], void>;
|
|
195
219
|
/** Text or background color handler from the selection toolbar. */
|
|
196
220
|
onapplycolor?: (request: MarkdownColorFormatRequest) => void;
|
|
197
221
|
/** Selection copy handler for custom behavior. */
|
|
@@ -7,7 +7,8 @@ const HEX_COLOR_REGEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
|
7
7
|
*/
|
|
8
8
|
const ALIGN_VALUE_REGEX = /^(?:left|center|right|justify)$/i;
|
|
9
9
|
const HAI_ALIGN_BLOCK_REGEX = /^<hai-align\s+value="(left|center|right|justify)">\n?([\s\S]+?)\n?<\/hai-align>\n{0,2}/i;
|
|
10
|
-
const HAI_SPAN_INLINE_REGEX = /^<hai-span(
|
|
10
|
+
const HAI_SPAN_INLINE_REGEX = /^<hai-span\b([^>]*)>([\s\S]+?)<\/hai-span>/i;
|
|
11
|
+
const HAI_SPAN_ATTR_REGEX = /\b(color|bg)="([^"]+)"/gi;
|
|
11
12
|
const HAI_UNDERLINE_REGEX = /^\+\+((?:\\.|[\s\S])+?)\+\+/;
|
|
12
13
|
const HAI_HIGHLIGHT_REGEX = /^==((?:\\.|[\s\S])+?)==/;
|
|
13
14
|
/**
|
|
@@ -55,6 +56,21 @@ function sanitizeAlign(value) {
|
|
|
55
56
|
? normalized
|
|
56
57
|
: undefined;
|
|
57
58
|
}
|
|
59
|
+
function parseHaiSpanAttributes(rawAttributes) {
|
|
60
|
+
let color;
|
|
61
|
+
let background;
|
|
62
|
+
for (const match of rawAttributes.matchAll(HAI_SPAN_ATTR_REGEX)) {
|
|
63
|
+
const [, attrName, attrValue] = match;
|
|
64
|
+
if (attrName === 'color') {
|
|
65
|
+
color = sanitizeColor(attrValue) ?? color;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (attrName === 'bg') {
|
|
69
|
+
background = sanitizeColor(attrValue) ?? background;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { color, background };
|
|
73
|
+
}
|
|
58
74
|
/**
|
|
59
75
|
* ChatWorkspace 编辑器会把“非标准 Markdown”能力写成自定义标签,
|
|
60
76
|
* 这里把它们注册为 marked 扩展,保证普通 Markdown 和编辑器增强能力共享同一条渲染链路。
|
|
@@ -101,14 +117,13 @@ export function createEditorMarkdownExtensions() {
|
|
|
101
117
|
if (!match) {
|
|
102
118
|
return undefined;
|
|
103
119
|
}
|
|
104
|
-
const color =
|
|
105
|
-
const background = sanitizeColor(match[2]);
|
|
120
|
+
const { color, background } = parseHaiSpanAttributes(match[1] ?? '');
|
|
106
121
|
return {
|
|
107
122
|
type: 'haiSpan',
|
|
108
123
|
raw: match[0],
|
|
109
124
|
color,
|
|
110
125
|
background,
|
|
111
|
-
tokens: this.lexer.inlineTokens(match[
|
|
126
|
+
tokens: this.lexer.inlineTokens(match[2]),
|
|
112
127
|
};
|
|
113
128
|
},
|
|
114
129
|
renderer(token) {
|
package/dist/messages/en-US.json
CHANGED
|
@@ -210,6 +210,8 @@
|
|
|
210
210
|
"markdown_format_heading_3": "Heading 3",
|
|
211
211
|
"markdown_format_heading_4": "Heading 4",
|
|
212
212
|
"markdown_format_bullet": "Bullets",
|
|
213
|
+
"markdown_format_ordered_list": "Ordered list",
|
|
214
|
+
"markdown_format_bullet_list": "Bullet list",
|
|
213
215
|
"markdown_format_bold": "Bold",
|
|
214
216
|
"markdown_format_strike": "Strike",
|
|
215
217
|
"markdown_format_italic": "Italic",
|
|
@@ -224,6 +226,7 @@
|
|
|
224
226
|
"markdown_align_justify": "Justify",
|
|
225
227
|
"markdown_text_color": "Text color",
|
|
226
228
|
"markdown_background_color": "Background color",
|
|
229
|
+
"markdown_background_none": "No background",
|
|
227
230
|
"markdown_reset_default": "Reset default",
|
|
228
231
|
"markdown_color_dialog_label": "Text and background color",
|
|
229
232
|
"markdown_link_dialog_label": "Edit link",
|
|
@@ -231,6 +234,8 @@
|
|
|
231
234
|
"markdown_link_placeholder": "Paste or type a link",
|
|
232
235
|
"markdown_link_apply": "Apply link",
|
|
233
236
|
"markdown_link_remove": "Remove link",
|
|
237
|
+
"markdown_link_open": "Open link",
|
|
238
|
+
"markdown_link_edit": "Edit link",
|
|
234
239
|
"markdown_copy_selection": "Copy",
|
|
235
240
|
"markdown_annotation": "Annotate",
|
|
236
241
|
"markdown_run_preview": "Run Preview",
|
package/dist/messages/zh-CN.json
CHANGED
|
@@ -210,6 +210,8 @@
|
|
|
210
210
|
"markdown_format_heading_3": "三级标题",
|
|
211
211
|
"markdown_format_heading_4": "四级标题",
|
|
212
212
|
"markdown_format_bullet": "列表",
|
|
213
|
+
"markdown_format_ordered_list": "有序列表",
|
|
214
|
+
"markdown_format_bullet_list": "无序列表",
|
|
213
215
|
"markdown_format_bold": "加粗",
|
|
214
216
|
"markdown_format_strike": "删除线",
|
|
215
217
|
"markdown_format_italic": "斜体",
|
|
@@ -224,6 +226,7 @@
|
|
|
224
226
|
"markdown_align_justify": "两端对齐",
|
|
225
227
|
"markdown_text_color": "字体颜色",
|
|
226
228
|
"markdown_background_color": "背景颜色",
|
|
229
|
+
"markdown_background_none": "无背景",
|
|
227
230
|
"markdown_reset_default": "恢复默认",
|
|
228
231
|
"markdown_color_dialog_label": "文本和背景颜色",
|
|
229
232
|
"markdown_link_dialog_label": "编辑链接",
|
|
@@ -231,6 +234,8 @@
|
|
|
231
234
|
"markdown_link_placeholder": "输入或粘贴链接地址",
|
|
232
235
|
"markdown_link_apply": "应用链接",
|
|
233
236
|
"markdown_link_remove": "移除链接",
|
|
237
|
+
"markdown_link_open": "打开链接",
|
|
238
|
+
"markdown_link_edit": "修改链接",
|
|
234
239
|
"markdown_copy_selection": "复制",
|
|
235
240
|
"markdown_annotation": "注释",
|
|
236
241
|
"markdown_run_preview": "运行预览",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-ai/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.0-alpha.
|
|
4
|
+
"version": "0.1.0-alpha.13",
|
|
5
5
|
"description": "Hai Framework UI component library for Svelte 5 Runes.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"svelte": "./dist/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"marked": "^18.0.0",
|
|
45
45
|
"shiki": "^4.0.2",
|
|
46
46
|
"tailwind-merge": "^3.5.0",
|
|
47
|
-
"@h-ai/core": "0.1.0-alpha.
|
|
47
|
+
"@h-ai/core": "0.1.0-alpha.13"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@sveltejs/package": "^2.5.7",
|