@h-ai/ui 1.0.0-beta.2 → 1.0.0-beta.20
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.en.md +228 -70
- package/README.ja.md +227 -69
- package/README.md +229 -72
- package/auto-import.d.ts +4 -0
- package/auto-import.js +241 -65
- package/dist/components/compounds/Accordion.svelte +6 -2
- package/dist/components/compounds/BottomNav.svelte +14 -2
- package/dist/components/compounds/Card.svelte +3 -1
- package/dist/components/compounds/Combobox.svelte +41 -5
- package/dist/components/compounds/DataTable.svelte +28 -8
- package/dist/components/compounds/DatePicker.svelte +6 -1
- package/dist/components/compounds/Drawer.svelte +12 -4
- package/dist/components/compounds/Dropdown.svelte +135 -59
- package/dist/components/compounds/Empty.svelte +10 -2
- package/dist/components/compounds/FormField.svelte +10 -2
- package/dist/components/compounds/JsonViewer.svelte +18 -6
- package/dist/components/compounds/Modal.svelte +8 -2
- package/dist/components/compounds/Pagination.svelte +22 -7
- package/dist/components/compounds/Popover.svelte +93 -12
- package/dist/components/compounds/Steps.svelte +24 -8
- package/dist/components/compounds/SwipeCell.svelte +3 -1
- package/dist/components/compounds/TableToolbar.svelte +32 -9
- package/dist/components/compounds/Tabs.svelte +25 -5
- package/dist/components/compounds/TagInput.svelte +2 -0
- package/dist/components/compounds/Timeline.svelte +6 -2
- package/dist/components/compounds/ToastContainer.svelte +41 -10
- package/dist/components/compounds/Tooltip.svelte +1 -1
- package/dist/components/compounds/Tooltip.svelte.d.ts +1 -1
- package/dist/components/control-size.js +48 -8
- package/dist/components/primitives/Avatar.svelte +9 -3
- package/dist/components/primitives/BareInput.svelte +3 -1
- package/dist/components/primitives/Button.svelte +6 -2
- package/dist/components/primitives/Checkbox.svelte +5 -0
- package/dist/components/primitives/IconButton.svelte +3 -1
- package/dist/components/primitives/Input.svelte +19 -3
- package/dist/components/primitives/Radio.svelte +4 -1
- package/dist/components/primitives/Range.svelte +3 -1
- package/dist/components/primitives/Rating.svelte +9 -3
- package/dist/components/primitives/Select.svelte +21 -5
- package/dist/components/primitives/Tag.svelte +6 -10
- package/dist/components/primitives/Textarea.svelte +14 -2
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +40 -12
- package/dist/components/scenes/ai/document-download.js +6 -2
- package/dist/components/scenes/ai/document-parse.js +24 -8
- package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
- package/dist/components/scenes/ai/highlight.js +18 -1
- package/dist/components/scenes/ai/markdown-parse.js +81 -28
- package/dist/components/scenes/ai/mermaid-render.js +13 -1
- package/dist/components/scenes/ai/safe-html.js +9 -3
- package/dist/components/scenes/ai/table/AiTableEditor.svelte +27 -9
- package/dist/components/scenes/app/FeedbackDetail.svelte +102 -24
- package/dist/components/scenes/app/FeedbackForm.svelte +70 -16
- package/dist/components/scenes/app/FeedbackList.svelte +138 -21
- package/dist/components/scenes/app/FeedbackRecorder.svelte +18 -5
- package/dist/components/scenes/app/FeedbackReplay.svelte +15 -3
- package/dist/components/scenes/app/FeedbackScreenshot.svelte +64 -13
- package/dist/components/scenes/app/LanguageSwitch.svelte +6 -2
- package/dist/components/scenes/app/SettingsLayout.svelte +3 -1
- package/dist/components/scenes/app/ThemeSelector.svelte +29 -5
- package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
- package/dist/components/scenes/app/WorkspaceLayout.svelte +1 -1
- package/dist/components/scenes/app/feedback-functions.js +6 -2
- package/dist/components/scenes/charts/Chart.svelte +55 -21
- package/dist/components/scenes/charts/Chart.svelte.d.ts +0 -1
- package/dist/components/scenes/charts/ChartLoadError.svelte +13 -0
- package/dist/components/scenes/charts/ChartLoadError.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/DashboardGrid.svelte +34 -0
- package/dist/components/scenes/charts/DashboardGrid.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/MetricCard.svelte +69 -0
- package/dist/components/scenes/charts/MetricCard.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/ReportCard.svelte +48 -0
- package/dist/components/scenes/charts/ReportCard.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/chart-presets.d.ts +15 -0
- package/dist/components/scenes/charts/chart-presets.js +56 -0
- package/dist/components/scenes/charts/chart-types.d.ts +13 -2
- package/dist/components/scenes/charts/dashboard-types.d.ts +79 -0
- package/dist/components/scenes/charts/dashboard-types.js +1 -0
- package/dist/components/scenes/charts/index.d.ts +6 -2
- package/dist/components/scenes/charts/index.js +4 -1
- package/dist/components/scenes/charts/renderers/AreaChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte +39 -12
- package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +1 -0
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte +6 -2
- package/dist/components/scenes/crud/CrudDetailPanel.svelte +6 -2
- package/dist/components/scenes/crud/CrudEditPanel.svelte +41 -12
- package/dist/components/scenes/crud/CrudPage.svelte +34 -9
- package/dist/components/scenes/crud/crud-controller.svelte.js +23 -8
- package/dist/components/scenes/crud/crud-form-validation.js +27 -9
- package/dist/components/scenes/crypto/EncryptedInput.svelte +9 -3
- package/dist/components/scenes/error/error-presets.js +30 -5
- package/dist/components/scenes/guide/GuideHostContent.svelte +7 -1
- package/dist/components/scenes/guide/HelpCenter.svelte +23 -4
- package/dist/components/scenes/iam/AgreementNotice.svelte +9 -3
- package/dist/components/scenes/iam/AuthPanel.svelte +74 -16
- package/dist/components/scenes/iam/ChangePasswordForm.svelte +6 -2
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte +9 -3
- package/dist/components/scenes/iam/LoginForm.svelte +32 -8
- package/dist/components/scenes/iam/PasswordInput.svelte +50 -12
- package/dist/components/scenes/iam/RegisterForm.svelte +11 -3
- package/dist/components/scenes/iam/ResetPasswordForm.svelte +6 -2
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +3 -1
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +4 -1
- package/dist/components/scenes/iam/UserProfile.svelte +41 -14
- package/dist/components/scenes/iam/auth-captcha.js +9 -2
- package/dist/components/scenes/iam/auth-error-message.d.ts +2 -2
- package/dist/components/scenes/iam/auth-error-message.js +16 -3
- package/dist/components/scenes/iam/password-utils.js +9 -2
- package/dist/components/scenes/iam/sensitive-actions.svelte.js +4 -1
- package/dist/components/scenes/storage/FileList.svelte +3 -1
- package/dist/components/scenes/storage/FileUpload.svelte +7 -2
- package/dist/components/scenes/types.d.ts +2 -2
- package/dist/guide-storage.js +12 -4
- package/dist/guide.svelte.js +59 -16
- package/dist/i18n.svelte.js +9 -3
- package/dist/internal/dialog-focus.d.ts +19 -0
- package/dist/internal/dialog-focus.js +104 -4
- package/dist/internal/form-validation.svelte.js +46 -15
- package/dist/internal/icon-safety.js +6 -2
- package/dist/message.svelte.js +6 -2
- package/dist/messagebox.svelte.js +6 -2
- package/dist/messages/en-US.json +7 -1
- package/dist/messages/ja-JP.json +7 -1
- package/dist/messages/zh-CN.json +7 -1
- package/dist/styles/eye-care.css +55 -0
- package/dist/styles/global.css +16 -0
- package/dist/styles/theme.css +1 -0
- package/dist/theme-config.d.ts +1 -1
- package/dist/theme-config.js +136 -21
- package/dist/toast.svelte.js +14 -3
- package/dist/types.d.ts +3 -3
- package/dist/utils.js +6 -2
- package/package.json +19 -19
|
@@ -50,7 +50,14 @@
|
|
|
50
50
|
|
|
51
51
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
52
52
|
const field = getFormFieldContext()
|
|
53
|
-
const validation = createControlValidation(() => validationMessage, () => [
|
|
53
|
+
const validation = createControlValidation(() => validationMessage, () => [
|
|
54
|
+
value,
|
|
55
|
+
required,
|
|
56
|
+
readonly,
|
|
57
|
+
disabled,
|
|
58
|
+
minlength,
|
|
59
|
+
maxlength,
|
|
60
|
+
])
|
|
54
61
|
const uniqueId = $props.id()
|
|
55
62
|
const messageId = `${uniqueId}-error`
|
|
56
63
|
const localError = $derived(resolveFormText(error) || validation.message)
|
|
@@ -114,7 +121,12 @@
|
|
|
114
121
|
bind:this={textareaRef}
|
|
115
122
|
id={id ?? field?.controlId}
|
|
116
123
|
aria-invalid={effectiveError ? true : undefined}
|
|
117
|
-
aria-describedby={[
|
|
124
|
+
aria-describedby={[
|
|
125
|
+
field?.messageId,
|
|
126
|
+
localError && !field?.error
|
|
127
|
+
? messageId
|
|
128
|
+
: '',
|
|
129
|
+
].filter(Boolean).join(' ') || undefined}
|
|
118
130
|
{name}
|
|
119
131
|
{placeholder}
|
|
120
132
|
{rows}
|
|
@@ -539,7 +539,9 @@
|
|
|
539
539
|
)
|
|
540
540
|
// 只有一个改写动作时直接渲染成按钮,多动作才保留菜单,减少一次点击。
|
|
541
541
|
const directRewriteAction = $derived(
|
|
542
|
-
resolvedRewriteActions.length === 1
|
|
542
|
+
resolvedRewriteActions.length === 1
|
|
543
|
+
? resolvedRewriteActions[0]
|
|
544
|
+
: null,
|
|
543
545
|
)
|
|
544
546
|
// 新版工具条支持 paragraph / heading1-4,优先走细粒度回调,避免把旧接口误当成新接口调用。
|
|
545
547
|
const richBlockFormattingEnabled = $derived(Boolean(onapplyblockstyle))
|
|
@@ -575,7 +577,9 @@
|
|
|
575
577
|
cn(
|
|
576
578
|
'hai-markdown',
|
|
577
579
|
'hai-markdown-document',
|
|
578
|
-
sourceKind === 'code'
|
|
580
|
+
sourceKind === 'code'
|
|
581
|
+
? 'hai-markdown-code-only'
|
|
582
|
+
: '',
|
|
579
583
|
editable ? 'hai-markdown-editable' : '',
|
|
580
584
|
),
|
|
581
585
|
)
|
|
@@ -777,10 +781,22 @@
|
|
|
777
781
|
}
|
|
778
782
|
|
|
779
783
|
return [
|
|
780
|
-
{
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
+
{
|
|
785
|
+
id: 'polish',
|
|
786
|
+
label: uiM('markdown_rewrite_polish'),
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
id: 'expand',
|
|
790
|
+
label: uiM('markdown_rewrite_expand'),
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
id: 'shorten',
|
|
794
|
+
label: uiM('markdown_rewrite_shorten'),
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
id: 'explain',
|
|
798
|
+
label: uiM('markdown_rewrite_explain'),
|
|
799
|
+
},
|
|
784
800
|
]
|
|
785
801
|
}
|
|
786
802
|
|
|
@@ -925,7 +941,9 @@
|
|
|
925
941
|
[blockId]: {
|
|
926
942
|
status: 'error',
|
|
927
943
|
error:
|
|
928
|
-
error instanceof Error
|
|
944
|
+
error instanceof Error
|
|
945
|
+
? error.message
|
|
946
|
+
: uiM('markdown_run_failed'),
|
|
929
947
|
},
|
|
930
948
|
}
|
|
931
949
|
}
|
|
@@ -1216,7 +1234,9 @@
|
|
|
1216
1234
|
return
|
|
1217
1235
|
}
|
|
1218
1236
|
|
|
1219
|
-
const message = error instanceof Error
|
|
1237
|
+
const message = error instanceof Error
|
|
1238
|
+
? error.message
|
|
1239
|
+
: uiM('markdown_mermaid_failed')
|
|
1220
1240
|
const entry: MermaidRenderCacheEntry = {
|
|
1221
1241
|
signature: renderToken,
|
|
1222
1242
|
status: 'error',
|
|
@@ -1531,7 +1551,9 @@
|
|
|
1531
1551
|
return false
|
|
1532
1552
|
}
|
|
1533
1553
|
|
|
1534
|
-
return visit(root)
|
|
1554
|
+
return visit(root)
|
|
1555
|
+
? length
|
|
1556
|
+
: null
|
|
1535
1557
|
}
|
|
1536
1558
|
|
|
1537
1559
|
function getTextOffsetInPreview(node: Node, offset: number): number | null {
|
|
@@ -2146,7 +2168,9 @@
|
|
|
2146
2168
|
}
|
|
2147
2169
|
|
|
2148
2170
|
function resolveColorOptionValue(colorOption: string | ColorSwatchOption): string | null {
|
|
2149
|
-
return typeof colorOption === 'string'
|
|
2171
|
+
return typeof colorOption === 'string'
|
|
2172
|
+
? colorOption
|
|
2173
|
+
: colorOption.value
|
|
2150
2174
|
}
|
|
2151
2175
|
|
|
2152
2176
|
function updateHoveredLink(link: HTMLAnchorElement | null): void {
|
|
@@ -2385,7 +2409,9 @@
|
|
|
2385
2409
|
: 0
|
|
2386
2410
|
const minLeft = Math.max(
|
|
2387
2411
|
horizontalPadding,
|
|
2388
|
-
outlineOverlap > 24
|
|
2412
|
+
outlineOverlap > 24
|
|
2413
|
+
? outlineOverlap + 12
|
|
2414
|
+
: horizontalPadding,
|
|
2389
2415
|
)
|
|
2390
2416
|
const measuredToolbarWidth = selectionChromeEl
|
|
2391
2417
|
? Math.max(selectionChromeEl.offsetWidth, selectionChromeEl.clientWidth)
|
|
@@ -2581,7 +2607,9 @@
|
|
|
2581
2607
|
? target.closest<HTMLAnchorElement>('a[href]')
|
|
2582
2608
|
: null
|
|
2583
2609
|
|
|
2584
|
-
updateHoveredLink(link && previewHost?.contains(link)
|
|
2610
|
+
updateHoveredLink(link && previewHost?.contains(link)
|
|
2611
|
+
? link
|
|
2612
|
+
: null)
|
|
2585
2613
|
}
|
|
2586
2614
|
|
|
2587
2615
|
function handlePreviewMouseLeave(): void {
|
|
@@ -51,7 +51,9 @@ export function resolveDocumentMarkdownContent(value, kind = 'markdown', languag
|
|
|
51
51
|
const fenceLength = Math.max(3, ...Array.from(value.matchAll(/`{3,}/g), match => match[0].length + 1));
|
|
52
52
|
const fence = '`'.repeat(fenceLength);
|
|
53
53
|
const normalizedLanguage = language?.trim() ?? '';
|
|
54
|
-
const suffix = value.endsWith('\n')
|
|
54
|
+
const suffix = value.endsWith('\n')
|
|
55
|
+
? ''
|
|
56
|
+
: '\n';
|
|
55
57
|
return `${fence}${normalizedLanguage}\n${value}${suffix}${fence}`;
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
@@ -328,7 +330,9 @@ function buildDocumentExportHtml(title, bodyHtml) {
|
|
|
328
330
|
</html>`;
|
|
329
331
|
}
|
|
330
332
|
function htmlToPdfFilename(title) {
|
|
331
|
-
return title.endsWith('.pdf')
|
|
333
|
+
return title.endsWith('.pdf')
|
|
334
|
+
? title
|
|
335
|
+
: `${title}.pdf`;
|
|
332
336
|
}
|
|
333
337
|
function createBrowserPdfRenderHost(bodyHtml) {
|
|
334
338
|
const frame = document.createElement('iframe');
|
|
@@ -87,7 +87,9 @@ function createHeadingId(state, text) {
|
|
|
87
87
|
// next count per slug ensures stable suffixing.
|
|
88
88
|
const nextCount = (state.headingIds.get(base) ?? 0) + 1;
|
|
89
89
|
state.headingIds.set(base, nextCount);
|
|
90
|
-
return nextCount === 1
|
|
90
|
+
return nextCount === 1
|
|
91
|
+
? base
|
|
92
|
+
: `${base}-${nextCount}`;
|
|
91
93
|
}
|
|
92
94
|
/**
|
|
93
95
|
* 为目录条目添加 1、1.1 等层级编号。
|
|
@@ -109,7 +111,9 @@ function createNumberedOutline(outline) {
|
|
|
109
111
|
.join('.');
|
|
110
112
|
return {
|
|
111
113
|
...item,
|
|
112
|
-
numberedTitle: prefix
|
|
114
|
+
numberedTitle: prefix
|
|
115
|
+
? `${prefix} ${item.text}`
|
|
116
|
+
: item.text,
|
|
113
117
|
};
|
|
114
118
|
});
|
|
115
119
|
}
|
|
@@ -197,7 +201,9 @@ function createRendererObject(options, state) {
|
|
|
197
201
|
+ `<div class="hai-md-code-header-main">${codePreviewToggle}${langLabel}${previewHint}</div>`
|
|
198
202
|
+ `<div class="hai-md-code-actions">${runBtn}${copyBtn}</div>`
|
|
199
203
|
+ `</div>`
|
|
200
|
-
+ `<pre><code class="hai-hl${highlightLanguage
|
|
204
|
+
+ `<pre><code class="hai-hl${highlightLanguage
|
|
205
|
+
? ` language-${escapeHtml(highlightLanguage)}`
|
|
206
|
+
: ''}">${highlighted}</code></pre>`
|
|
201
207
|
+ `${previewHost}`
|
|
202
208
|
+ `</div>`;
|
|
203
209
|
},
|
|
@@ -217,7 +223,9 @@ function createRendererObject(options, state) {
|
|
|
217
223
|
// attrs is the flattened HTML attribute string.
|
|
218
224
|
const attrs = [
|
|
219
225
|
`href="${escapeHtml(safeHref)}"`,
|
|
220
|
-
title
|
|
226
|
+
title
|
|
227
|
+
? `title="${escapeHtml(title)}"`
|
|
228
|
+
: '',
|
|
221
229
|
isExternal ? 'target="_blank" rel="noopener noreferrer"' : '',
|
|
222
230
|
].filter(Boolean).join(' ');
|
|
223
231
|
return `<a ${attrs}>${text}</a>`;
|
|
@@ -229,7 +237,9 @@ function createRendererObject(options, state) {
|
|
|
229
237
|
const attrs = [
|
|
230
238
|
`src="${escapeHtml(safeSrc)}"`,
|
|
231
239
|
`alt="${escapeHtml(text || '')}"`,
|
|
232
|
-
title
|
|
240
|
+
title
|
|
241
|
+
? `title="${escapeHtml(title)}"`
|
|
242
|
+
: '',
|
|
233
243
|
'loading="lazy"',
|
|
234
244
|
'class="hai-md-img"',
|
|
235
245
|
].filter(Boolean).join(' ');
|
|
@@ -240,7 +250,9 @@ function createRendererObject(options, state) {
|
|
|
240
250
|
let headerHtml = '';
|
|
241
251
|
for (const cell of token.header) {
|
|
242
252
|
// align adds text alignment for each header cell.
|
|
243
|
-
const align = cell.align
|
|
253
|
+
const align = cell.align
|
|
254
|
+
? ` style="text-align:${cell.align}"`
|
|
255
|
+
: '';
|
|
244
256
|
headerHtml += `<th${align}>${this.parser.parseInline(cell.tokens)}</th>`;
|
|
245
257
|
}
|
|
246
258
|
// bodyHtml accumulates all body rows.
|
|
@@ -250,7 +262,9 @@ function createRendererObject(options, state) {
|
|
|
250
262
|
let rowHtml = '';
|
|
251
263
|
for (const cell of row) {
|
|
252
264
|
// align adds text alignment for each body cell.
|
|
253
|
-
const align = cell.align
|
|
265
|
+
const align = cell.align
|
|
266
|
+
? ` style="text-align:${cell.align}"`
|
|
267
|
+
: '';
|
|
254
268
|
rowHtml += `<td${align}>${this.parser.parseInline(cell.tokens)}</td>`;
|
|
255
269
|
}
|
|
256
270
|
bodyHtml += `<tr>${rowHtml}</tr>`;
|
|
@@ -298,7 +312,9 @@ function renderMarkdownDocumentHtmlChunk(content, options, state) {
|
|
|
298
312
|
const marked = createMarkedInstance(options, state);
|
|
299
313
|
const result = marked.parse(content);
|
|
300
314
|
return {
|
|
301
|
-
html: typeof result === 'string'
|
|
315
|
+
html: typeof result === 'string'
|
|
316
|
+
? result
|
|
317
|
+
: '',
|
|
302
318
|
codeBlocks: state.codeBlocks,
|
|
303
319
|
};
|
|
304
320
|
}
|
|
@@ -53,7 +53,9 @@ function sanitizeColor(value) {
|
|
|
53
53
|
return undefined;
|
|
54
54
|
}
|
|
55
55
|
const normalized = value.trim().toLowerCase();
|
|
56
|
-
return HEX_COLOR_REGEX.test(normalized)
|
|
56
|
+
return HEX_COLOR_REGEX.test(normalized)
|
|
57
|
+
? normalized
|
|
58
|
+
: undefined;
|
|
57
59
|
}
|
|
58
60
|
function sanitizeAlign(value) {
|
|
59
61
|
if (!value) {
|
|
@@ -146,8 +148,12 @@ export function createEditorMarkdownExtensions() {
|
|
|
146
148
|
renderer(token) {
|
|
147
149
|
const spanToken = token;
|
|
148
150
|
const style = [
|
|
149
|
-
spanToken.color
|
|
150
|
-
|
|
151
|
+
spanToken.color
|
|
152
|
+
? `color:${spanToken.color}`
|
|
153
|
+
: '',
|
|
154
|
+
spanToken.background
|
|
155
|
+
? `background-color:${spanToken.background}`
|
|
156
|
+
: '',
|
|
151
157
|
].filter(Boolean).join(';');
|
|
152
158
|
if (!style) {
|
|
153
159
|
return this.parser.parseInline(spanToken.tokens);
|
|
@@ -13,22 +13,28 @@ import langCpp from '@shikijs/langs/cpp';
|
|
|
13
13
|
import langCsharp from '@shikijs/langs/csharp';
|
|
14
14
|
import langCss from '@shikijs/langs/css';
|
|
15
15
|
import langDiff from '@shikijs/langs/diff';
|
|
16
|
+
import langDockerfile from '@shikijs/langs/dockerfile';
|
|
17
|
+
import langDotenv from '@shikijs/langs/dotenv';
|
|
16
18
|
import langGo from '@shikijs/langs/go';
|
|
17
19
|
import langGraphql from '@shikijs/langs/graphql';
|
|
18
20
|
import langHtml from '@shikijs/langs/html';
|
|
21
|
+
import langIni from '@shikijs/langs/ini';
|
|
19
22
|
import langJava from '@shikijs/langs/java';
|
|
20
23
|
import langJavascript from '@shikijs/langs/javascript';
|
|
21
24
|
import langJson from '@shikijs/langs/json';
|
|
22
25
|
import langKotlin from '@shikijs/langs/kotlin';
|
|
23
26
|
import langLua from '@shikijs/langs/lua';
|
|
24
27
|
import langMarkdown from '@shikijs/langs/markdown';
|
|
28
|
+
import langNginx from '@shikijs/langs/nginx';
|
|
25
29
|
import langPhp from '@shikijs/langs/php';
|
|
30
|
+
import langPowershell from '@shikijs/langs/powershell';
|
|
26
31
|
import langPython from '@shikijs/langs/python';
|
|
27
32
|
import langRuby from '@shikijs/langs/ruby';
|
|
28
33
|
import langRust from '@shikijs/langs/rust';
|
|
29
34
|
import langScss from '@shikijs/langs/scss';
|
|
30
35
|
import langShell from '@shikijs/langs/shellscript';
|
|
31
36
|
import langSql from '@shikijs/langs/sql';
|
|
37
|
+
import langSvelte from '@shikijs/langs/svelte';
|
|
32
38
|
import langSwift from '@shikijs/langs/swift';
|
|
33
39
|
import langToml from '@shikijs/langs/toml';
|
|
34
40
|
import langTypescript from '@shikijs/langs/typescript';
|
|
@@ -73,6 +79,12 @@ const highlighter = createHighlighterCoreSync({
|
|
|
73
79
|
langToml,
|
|
74
80
|
langMarkdown,
|
|
75
81
|
langDiff,
|
|
82
|
+
langDockerfile,
|
|
83
|
+
langDotenv,
|
|
84
|
+
langIni,
|
|
85
|
+
langNginx,
|
|
86
|
+
langPowershell,
|
|
87
|
+
langSvelte,
|
|
76
88
|
langGraphql,
|
|
77
89
|
langLua,
|
|
78
90
|
],
|
|
@@ -88,6 +100,9 @@ const LANG_ALIASES = {
|
|
|
88
100
|
'sh': 'bash',
|
|
89
101
|
'shell': 'bash',
|
|
90
102
|
'zsh': 'bash',
|
|
103
|
+
'ps1': 'powershell',
|
|
104
|
+
'pwsh': 'powershell',
|
|
105
|
+
'env': 'dotenv',
|
|
91
106
|
'yml': 'yaml',
|
|
92
107
|
'c++': 'cpp',
|
|
93
108
|
'c#': 'csharp',
|
|
@@ -109,7 +124,9 @@ function resolveLang(lang) {
|
|
|
109
124
|
return null;
|
|
110
125
|
const resolved = LANG_ALIASES[normalized] ?? normalized;
|
|
111
126
|
const loaded = highlighter.getLoadedLanguages();
|
|
112
|
-
return loaded.includes(resolved)
|
|
127
|
+
return loaded.includes(resolved)
|
|
128
|
+
? resolved
|
|
129
|
+
: null;
|
|
113
130
|
}
|
|
114
131
|
/**
|
|
115
132
|
* 从 codeToHtml 输出中提取 <code> 标签内的 innerHTML
|
|
@@ -26,7 +26,72 @@ function createTableCellAttrs(cell) {
|
|
|
26
26
|
if (cell.text.trim()) {
|
|
27
27
|
attrs.push(`title="${escapeHtml(cell.text)}"`);
|
|
28
28
|
}
|
|
29
|
-
return attrs.length > 0
|
|
29
|
+
return attrs.length > 0
|
|
30
|
+
? ` ${attrs.join(' ')}`
|
|
31
|
+
: '';
|
|
32
|
+
}
|
|
33
|
+
/** 围栏代码和 HTML 代码共用渲染,颜色与复制控件始终由框架生成。 */
|
|
34
|
+
function renderCodeBlock(text, lang, options) {
|
|
35
|
+
const language = lang && isLanguageSupported(lang)
|
|
36
|
+
? lang
|
|
37
|
+
: '';
|
|
38
|
+
let highlighted;
|
|
39
|
+
if (options.enableHighlight && language) {
|
|
40
|
+
highlighted = highlightCode(text, language);
|
|
41
|
+
}
|
|
42
|
+
else if (options.enableHighlight) {
|
|
43
|
+
// 未指定语言时不做自动检测,直接转义
|
|
44
|
+
highlighted = escapeHtml(text);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
highlighted = escapeHtml(text);
|
|
48
|
+
}
|
|
49
|
+
const langLabel = language
|
|
50
|
+
? `<span class="hai-md-code-lang">${escapeHtml(language)}</span>`
|
|
51
|
+
: '';
|
|
52
|
+
const copyBtn = options.showCopyButton
|
|
53
|
+
? `<button type="button" class="hai-md-copy-btn" data-copy-code aria-label="${escapeHtml(uiM('markdown_copy_code'))}"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button>`
|
|
54
|
+
: '';
|
|
55
|
+
return `<div class="hai-md-code-block">`
|
|
56
|
+
+ `<div class="hai-md-code-header">${langLabel}${copyBtn}</div>`
|
|
57
|
+
+ `<pre><code class="hai-hl${language
|
|
58
|
+
? ` language-${escapeHtml(language)}`
|
|
59
|
+
: ''}">${highlighted}</code></pre>`
|
|
60
|
+
+ `</div>`;
|
|
61
|
+
}
|
|
62
|
+
/** 仅还原代码文本的实体;随后仍按普通代码转义,绝不把代码中的标签作为 HTML 执行。 */
|
|
63
|
+
function decodeCodeText(text) {
|
|
64
|
+
const named = {
|
|
65
|
+
amp: '&',
|
|
66
|
+
lt: '<',
|
|
67
|
+
gt: '>',
|
|
68
|
+
quot: '"',
|
|
69
|
+
apos: '\'',
|
|
70
|
+
nbsp: '\u00A0',
|
|
71
|
+
};
|
|
72
|
+
return text.replace(/&(#(?:[xX][\da-fA-F]+|\d+)|amp|lt|gt|quot|apos|nbsp);/g, (entity, key) => {
|
|
73
|
+
if (!key.startsWith('#'))
|
|
74
|
+
return named[key] ?? entity;
|
|
75
|
+
const code = key[1]?.toLowerCase() === 'x'
|
|
76
|
+
? Number.parseInt(key.slice(2), 16)
|
|
77
|
+
: Number(key.slice(1));
|
|
78
|
+
return code > 0 && code <= 0x10FFFF && !(code >= 0xD800 && code <= 0xDFFF)
|
|
79
|
+
? String.fromCodePoint(code)
|
|
80
|
+
: entity;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** 重建 pre/code,不保留输入的 style、事件或任意 class;其余 HTML 继续通过原有白名单。 */
|
|
84
|
+
function renderHtmlWithCode(source, options) {
|
|
85
|
+
let html = '';
|
|
86
|
+
let offset = 0;
|
|
87
|
+
for (const match of source.matchAll(/<pre\b[^>]*>\s*<code\b([^>]*)>([\s\S]*?)<\/code>\s*<\/pre>/gi)) {
|
|
88
|
+
html += sanitizeMarkdownHtml(source.slice(offset, match.index));
|
|
89
|
+
const classes = /\bclass\s*=\s*(?:"([^"]*)"|'([^']*)')/i.exec(match[1]);
|
|
90
|
+
const language = /(?:^|\s)language-([a-z\d#+.-]+)(?:\s|$)/i.exec(classes?.[1] ?? classes?.[2] ?? '')?.[1];
|
|
91
|
+
html += renderCodeBlock(decodeCodeText(match[2]), language, options);
|
|
92
|
+
offset = match.index + match[0].length;
|
|
93
|
+
}
|
|
94
|
+
return html + sanitizeMarkdownHtml(source.slice(offset));
|
|
30
95
|
}
|
|
31
96
|
/**
|
|
32
97
|
* 创建自定义渲染器对象
|
|
@@ -38,34 +103,13 @@ function createRendererObject(options) {
|
|
|
38
103
|
return {
|
|
39
104
|
// 代码块:语法高亮 + 语言标签 + 复制按钮
|
|
40
105
|
code({ text, lang }) {
|
|
41
|
-
|
|
42
|
-
let highlighted;
|
|
43
|
-
if (options.enableHighlight && language) {
|
|
44
|
-
highlighted = highlightCode(text, language);
|
|
45
|
-
}
|
|
46
|
-
else if (options.enableHighlight) {
|
|
47
|
-
// 未指定语言时不做自动检测,直接转义
|
|
48
|
-
highlighted = escapeHtml(text);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
highlighted = escapeHtml(text);
|
|
52
|
-
}
|
|
53
|
-
const langLabel = language
|
|
54
|
-
? `<span class="hai-md-code-lang">${escapeHtml(language)}</span>`
|
|
55
|
-
: '';
|
|
56
|
-
const copyBtn = options.showCopyButton
|
|
57
|
-
? `<button type="button" class="hai-md-copy-btn" data-copy-code aria-label="${escapeHtml(uiM('markdown_copy_code'))}"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button>`
|
|
58
|
-
: '';
|
|
59
|
-
return `<div class="hai-md-code-block">`
|
|
60
|
-
+ `<div class="hai-md-code-header">${langLabel}${copyBtn}</div>`
|
|
61
|
-
+ `<pre><code class="hai-hl${language ? ` language-${escapeHtml(language)}` : ''}">${highlighted}</code></pre>`
|
|
62
|
-
+ `</div>`;
|
|
106
|
+
return renderCodeBlock(text, lang, options);
|
|
63
107
|
},
|
|
64
108
|
// 原始 HTML 块:转义以防止 XSS
|
|
65
109
|
html(token) {
|
|
66
110
|
const source = readHtmlTokenSource(token);
|
|
67
111
|
return options.allowHtmlTags
|
|
68
|
-
?
|
|
112
|
+
? renderHtmlWithCode(source, options)
|
|
69
113
|
: escapeHtml(source);
|
|
70
114
|
},
|
|
71
115
|
// 链接:外部链接自动添加 target="_blank",阻止危险协议
|
|
@@ -76,7 +120,9 @@ function createRendererObject(options) {
|
|
|
76
120
|
const isExternal = safeHref && isExternalLinkHref(safeHref);
|
|
77
121
|
const attrs = [
|
|
78
122
|
`href="${escapeHtml(safeHref)}"`,
|
|
79
|
-
title
|
|
123
|
+
title
|
|
124
|
+
? `title="${escapeHtml(title)}"`
|
|
125
|
+
: '',
|
|
80
126
|
isExternal ? 'target="_blank" rel="noopener noreferrer"' : '',
|
|
81
127
|
].filter(Boolean).join(' ');
|
|
82
128
|
return `<a ${attrs}>${text}</a>`;
|
|
@@ -88,7 +134,9 @@ function createRendererObject(options) {
|
|
|
88
134
|
const attrs = [
|
|
89
135
|
`src="${escapeHtml(safeSrc)}"`,
|
|
90
136
|
`alt="${escapeHtml(text || '')}"`,
|
|
91
|
-
title
|
|
137
|
+
title
|
|
138
|
+
? `title="${escapeHtml(title)}"`
|
|
139
|
+
: '',
|
|
92
140
|
'loading="lazy"',
|
|
93
141
|
'class="hai-md-img"',
|
|
94
142
|
].filter(Boolean).join(' ');
|
|
@@ -160,7 +208,10 @@ function getOptionsKey(options) {
|
|
|
160
208
|
export function parseMarkdown(content, options) {
|
|
161
209
|
if (!content)
|
|
162
210
|
return '';
|
|
163
|
-
const mergedOptions = {
|
|
211
|
+
const mergedOptions = {
|
|
212
|
+
...DEFAULT_OPTIONS,
|
|
213
|
+
...options,
|
|
214
|
+
};
|
|
164
215
|
const key = getOptionsKey(mergedOptions);
|
|
165
216
|
if (!cachedInstance || cachedOptionsKey !== key) {
|
|
166
217
|
cachedInstance = createMarkedInstance(mergedOptions);
|
|
@@ -168,5 +219,7 @@ export function parseMarkdown(content, options) {
|
|
|
168
219
|
}
|
|
169
220
|
const result = cachedInstance.parse(content);
|
|
170
221
|
// marked.parse 可能返回 string | Promise<string>,此处同步调用
|
|
171
|
-
return typeof result === 'string'
|
|
222
|
+
return typeof result === 'string'
|
|
223
|
+
? result
|
|
224
|
+
: '';
|
|
172
225
|
}
|
|
@@ -33,7 +33,19 @@ async function loadMermaid() {
|
|
|
33
33
|
securityLevel: 'strict',
|
|
34
34
|
theme: 'default',
|
|
35
35
|
// 不允许文档指令修改安全策略、消毒规则或注入页面级 CSS。
|
|
36
|
-
secure: [
|
|
36
|
+
secure: [
|
|
37
|
+
'secure',
|
|
38
|
+
'securityLevel',
|
|
39
|
+
'startOnLoad',
|
|
40
|
+
'maxTextSize',
|
|
41
|
+
'suppressErrorRendering',
|
|
42
|
+
'maxEdges',
|
|
43
|
+
'themeCSS',
|
|
44
|
+
'themeVariables',
|
|
45
|
+
'fontFamily',
|
|
46
|
+
'altFontFamily',
|
|
47
|
+
'dompurifyConfig',
|
|
48
|
+
],
|
|
37
49
|
});
|
|
38
50
|
return mermaid;
|
|
39
51
|
});
|
|
@@ -99,7 +99,9 @@ function escapeHtmlText(text) {
|
|
|
99
99
|
*/
|
|
100
100
|
export function sanitizeLinkHref(href) {
|
|
101
101
|
const normalized = href?.trim() ?? '';
|
|
102
|
-
return SAFE_LINK_HREF_REGEX.test(normalized)
|
|
102
|
+
return SAFE_LINK_HREF_REGEX.test(normalized)
|
|
103
|
+
? normalized
|
|
104
|
+
: '';
|
|
103
105
|
}
|
|
104
106
|
/**
|
|
105
107
|
* 识别外部链接,供渲染器添加相应的 rel/target 安全属性。
|
|
@@ -126,7 +128,9 @@ export function isExternalLinkHref(href) {
|
|
|
126
128
|
*/
|
|
127
129
|
export function sanitizeImageSrc(src) {
|
|
128
130
|
const normalized = src?.trim() ?? '';
|
|
129
|
-
return SAFE_IMAGE_SRC_REGEX.test(normalized)
|
|
131
|
+
return SAFE_IMAGE_SRC_REGEX.test(normalized)
|
|
132
|
+
? normalized
|
|
133
|
+
: '';
|
|
130
134
|
}
|
|
131
135
|
function sanitizeAlignValue(value) {
|
|
132
136
|
const normalized = value?.trim().toLowerCase();
|
|
@@ -276,7 +280,9 @@ function sanitizeHtmlTag(rawTag) {
|
|
|
276
280
|
return escapeHtml(rawTag);
|
|
277
281
|
}
|
|
278
282
|
if (isClosingTag) {
|
|
279
|
-
return VOID_HTML_TAGS.has(tagName)
|
|
283
|
+
return VOID_HTML_TAGS.has(tagName)
|
|
284
|
+
? ''
|
|
285
|
+
: `</${tagName}>`;
|
|
280
286
|
}
|
|
281
287
|
const attributes = readSanitizedAttributes(tagName, rawAttributes);
|
|
282
288
|
const renderedAttributes = [];
|
|
@@ -230,7 +230,9 @@
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
function normalizeColumnType(value: unknown): AiTableColumnType {
|
|
233
|
-
return value === 'number' || value === 'tag'
|
|
233
|
+
return value === 'number' || value === 'tag'
|
|
234
|
+
? value
|
|
235
|
+
: 'text'
|
|
234
236
|
}
|
|
235
237
|
|
|
236
238
|
function serializeTableDataForComparison(
|
|
@@ -265,7 +267,9 @@
|
|
|
265
267
|
|
|
266
268
|
const key = typeof item.key === 'string' && item.key.trim()
|
|
267
269
|
? item.key.trim()
|
|
268
|
-
: (typeof item.name === 'string'
|
|
270
|
+
: (typeof item.name === 'string'
|
|
271
|
+
? item.name.trim()
|
|
272
|
+
: '')
|
|
269
273
|
if (!key || usedKeys.has(key)) {
|
|
270
274
|
continue
|
|
271
275
|
}
|
|
@@ -515,10 +519,14 @@
|
|
|
515
519
|
if (isRecord(parsedWhole)) {
|
|
516
520
|
const columns = Array.isArray(parsedWhole.table_columns)
|
|
517
521
|
? normalizeTableColumns(parsedWhole.table_columns)
|
|
518
|
-
: (Array.isArray(parsedWhole.columns)
|
|
522
|
+
: (Array.isArray(parsedWhole.columns)
|
|
523
|
+
? normalizeTableColumns(parsedWhole.columns)
|
|
524
|
+
: [])
|
|
519
525
|
const rows = Array.isArray(parsedWhole.table_rows)
|
|
520
526
|
? normalizeTableRows(parsedWhole.table_rows)
|
|
521
|
-
: (Array.isArray(parsedWhole.rows)
|
|
527
|
+
: (Array.isArray(parsedWhole.rows)
|
|
528
|
+
? normalizeTableRows(parsedWhole.rows)
|
|
529
|
+
: [])
|
|
522
530
|
|
|
523
531
|
if (columns.length > 0 || rows.length > 0) {
|
|
524
532
|
return {
|
|
@@ -540,8 +548,12 @@
|
|
|
540
548
|
return null
|
|
541
549
|
}
|
|
542
550
|
|
|
543
|
-
const columns = columnsChunk
|
|
544
|
-
|
|
551
|
+
const columns = columnsChunk
|
|
552
|
+
? parseTableColumnsFromChunk(columnsChunk)
|
|
553
|
+
: []
|
|
554
|
+
const rows = rowsChunk
|
|
555
|
+
? parseTableRowsFromChunk(rowsChunk)
|
|
556
|
+
: []
|
|
545
557
|
if (columns.length === 0 && rows.length === 0) {
|
|
546
558
|
return null
|
|
547
559
|
}
|
|
@@ -781,7 +793,9 @@
|
|
|
781
793
|
}
|
|
782
794
|
|
|
783
795
|
const rowBounds = currentTarget.getBoundingClientRect()
|
|
784
|
-
return event.clientY < rowBounds.top + rowBounds.height / 2
|
|
796
|
+
return event.clientY < rowBounds.top + rowBounds.height / 2
|
|
797
|
+
? 'before'
|
|
798
|
+
: 'after'
|
|
785
799
|
}
|
|
786
800
|
|
|
787
801
|
function updateRowDropHint(rowId: string, event: DragEvent): void {
|
|
@@ -1067,7 +1081,9 @@
|
|
|
1067
1081
|
function resolveBodyRowClass(rowId: string): string {
|
|
1068
1082
|
return cn(
|
|
1069
1083
|
'hai-ai-table-body-row',
|
|
1070
|
-
draggingRowId === rowId
|
|
1084
|
+
draggingRowId === rowId
|
|
1085
|
+
? 'hai-ai-table-body-row--dragging'
|
|
1086
|
+
: '',
|
|
1071
1087
|
isDropIndicatorVisible(rowId, 'before')
|
|
1072
1088
|
? 'hai-ai-table-body-row--drop-before'
|
|
1073
1089
|
: '',
|
|
@@ -1175,7 +1191,9 @@
|
|
|
1175
1191
|
<td>
|
|
1176
1192
|
<input
|
|
1177
1193
|
class={resolveCellInputClass(column.type)}
|
|
1178
|
-
type={column.type === 'number'
|
|
1194
|
+
type={column.type === 'number'
|
|
1195
|
+
? 'number'
|
|
1196
|
+
: 'text'}
|
|
1179
1197
|
value={cellInputValue}
|
|
1180
1198
|
title={cellInputValue}
|
|
1181
1199
|
disabled={!editable}
|