@h-ai/ui 1.0.0-beta.3 → 1.0.0-beta.30
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 +251 -71
- package/README.ja.md +250 -70
- package/README.md +252 -73
- package/auto-import.d.ts +5 -0
- package/auto-import.js +242 -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 +45 -69
- 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/document-types.d.ts +0 -12
- package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
- package/dist/components/scenes/ai/highlight.js +3 -1
- package/dist/components/scenes/ai/index.d.ts +1 -1
- package/dist/components/scenes/ai/markdown-parse.js +36 -10
- 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 +28 -16
- 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/code/CodeWorkspace.svelte +946 -0
- package/dist/components/scenes/code/CodeWorkspace.svelte.d.ts +21 -0
- package/dist/components/scenes/code/CodeWorkspaceEditor.svelte +737 -0
- package/dist/components/scenes/code/CodeWorkspaceEditor.svelte.d.ts +37 -0
- package/dist/components/scenes/code/CodeWorkspaceGutter.svelte +246 -0
- package/dist/components/scenes/code/CodeWorkspaceGutter.svelte.d.ts +23 -0
- package/dist/components/scenes/code/CodeWorkspaceSearch.svelte +234 -0
- package/dist/components/scenes/code/CodeWorkspaceSearch.svelte.d.ts +23 -0
- package/dist/components/scenes/code/CodeWorkspaceTree.svelte +519 -0
- package/dist/components/scenes/code/CodeWorkspaceTree.svelte.d.ts +26 -0
- package/dist/components/scenes/code/code-editor.d.ts +12 -0
- package/dist/components/scenes/code/code-editor.js +93 -0
- package/dist/components/scenes/code/code-types.d.ts +346 -0
- package/dist/components/scenes/code/code-types.js +1 -0
- package/dist/components/scenes/code/index.d.ts +2 -0
- package/dist/components/scenes/code/index.js +1 -0
- package/dist/components/scenes/code/workers/css.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/css.worker.js +1 -0
- package/dist/components/scenes/code/workers/editor.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/editor.worker.js +1 -0
- package/dist/components/scenes/code/workers/html.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/html.worker.js +1 -0
- package/dist/components/scenes/code/workers/json.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/json.worker.js +1 -0
- package/dist/components/scenes/code/workers/ts.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/ts.worker.js +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/index.d.ts +1 -0
- package/dist/components/scenes/index.js +2 -0
- 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 +60 -2
- package/dist/messages/ja-JP.json +60 -2
- package/dist/messages/zh-CN.json +60 -2
- 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 -3
- package/dist/theme-config.js +137 -22
- package/dist/toast.svelte.js +27 -7
- package/dist/types.d.ts +3 -3
- package/dist/utils.js +6 -2
- package/package.json +25 -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}
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
import type { DataAttributes } from '../../../types.js'
|
|
26
26
|
import type {
|
|
27
27
|
AiDocumentEditorProps,
|
|
28
|
-
MarkdownBlockFormatKind,
|
|
29
28
|
MarkdownBlockStyleKind,
|
|
30
29
|
MarkdownCodeBlockItem,
|
|
31
30
|
MarkdownCodeRunRequest,
|
|
@@ -405,8 +404,6 @@
|
|
|
405
404
|
onhistory,
|
|
406
405
|
// 全文复制回调。
|
|
407
406
|
oncopydocument,
|
|
408
|
-
// 块级格式动作回调。
|
|
409
|
-
onapplyblockformat,
|
|
410
407
|
// 细粒度块样式动作回调。
|
|
411
408
|
onapplyblockstyle,
|
|
412
409
|
// 行内格式动作回调。
|
|
@@ -539,23 +536,15 @@
|
|
|
539
536
|
)
|
|
540
537
|
// 只有一个改写动作时直接渲染成按钮,多动作才保留菜单,减少一次点击。
|
|
541
538
|
const directRewriteAction = $derived(
|
|
542
|
-
resolvedRewriteActions.length === 1
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const richBlockFormattingEnabled = $derived(Boolean(onapplyblockstyle))
|
|
546
|
-
// 旧版 heading / bullet 回调仍然保留,用于兼容外部还没迁移的调用方。
|
|
547
|
-
const legacyBlockFormattingEnabled = $derived(
|
|
548
|
-
Boolean(onapplyblockformat) && !onapplyblockstyle,
|
|
549
|
-
)
|
|
550
|
-
// 这里统一判断是否存在任意块级格式能力,方便控制分隔线和浮层显隐。
|
|
551
|
-
const anyBlockFormattingEnabled = $derived(
|
|
552
|
-
richBlockFormattingEnabled || legacyBlockFormattingEnabled,
|
|
539
|
+
resolvedRewriteActions.length === 1
|
|
540
|
+
? resolvedRewriteActions[0]
|
|
541
|
+
: null,
|
|
553
542
|
)
|
|
554
543
|
// selectionToolsEnabled 统一判断选区工具条是否值得出现,避免正文只读展示时还露出空浮层。
|
|
555
544
|
const selectionToolsEnabled = $derived(
|
|
556
545
|
[
|
|
557
546
|
onrewrite,
|
|
558
|
-
|
|
547
|
+
onapplyblockstyle,
|
|
559
548
|
onapplyinlineformat,
|
|
560
549
|
onapplyalignment,
|
|
561
550
|
onapplylink,
|
|
@@ -575,7 +564,9 @@
|
|
|
575
564
|
cn(
|
|
576
565
|
'hai-markdown',
|
|
577
566
|
'hai-markdown-document',
|
|
578
|
-
sourceKind === 'code'
|
|
567
|
+
sourceKind === 'code'
|
|
568
|
+
? 'hai-markdown-code-only'
|
|
569
|
+
: '',
|
|
579
570
|
editable ? 'hai-markdown-editable' : '',
|
|
580
571
|
),
|
|
581
572
|
)
|
|
@@ -777,10 +768,22 @@
|
|
|
777
768
|
}
|
|
778
769
|
|
|
779
770
|
return [
|
|
780
|
-
{
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
771
|
+
{
|
|
772
|
+
id: 'polish',
|
|
773
|
+
label: uiM('markdown_rewrite_polish'),
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
id: 'expand',
|
|
777
|
+
label: uiM('markdown_rewrite_expand'),
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
id: 'shorten',
|
|
781
|
+
label: uiM('markdown_rewrite_shorten'),
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
id: 'explain',
|
|
785
|
+
label: uiM('markdown_rewrite_explain'),
|
|
786
|
+
},
|
|
784
787
|
]
|
|
785
788
|
}
|
|
786
789
|
|
|
@@ -925,7 +928,9 @@
|
|
|
925
928
|
[blockId]: {
|
|
926
929
|
status: 'error',
|
|
927
930
|
error:
|
|
928
|
-
error instanceof Error
|
|
931
|
+
error instanceof Error
|
|
932
|
+
? error.message
|
|
933
|
+
: uiM('markdown_run_failed'),
|
|
929
934
|
},
|
|
930
935
|
}
|
|
931
936
|
}
|
|
@@ -1216,7 +1221,9 @@
|
|
|
1216
1221
|
return
|
|
1217
1222
|
}
|
|
1218
1223
|
|
|
1219
|
-
const message = error instanceof Error
|
|
1224
|
+
const message = error instanceof Error
|
|
1225
|
+
? error.message
|
|
1226
|
+
: uiM('markdown_mermaid_failed')
|
|
1220
1227
|
const entry: MermaidRenderCacheEntry = {
|
|
1221
1228
|
signature: renderToken,
|
|
1222
1229
|
status: 'error',
|
|
@@ -1531,7 +1538,9 @@
|
|
|
1531
1538
|
return false
|
|
1532
1539
|
}
|
|
1533
1540
|
|
|
1534
|
-
return visit(root)
|
|
1541
|
+
return visit(root)
|
|
1542
|
+
? length
|
|
1543
|
+
: null
|
|
1535
1544
|
}
|
|
1536
1545
|
|
|
1537
1546
|
function getTextOffsetInPreview(node: Node, offset: number): number | null {
|
|
@@ -2146,7 +2155,9 @@
|
|
|
2146
2155
|
}
|
|
2147
2156
|
|
|
2148
2157
|
function resolveColorOptionValue(colorOption: string | ColorSwatchOption): string | null {
|
|
2149
|
-
return typeof colorOption === 'string'
|
|
2158
|
+
return typeof colorOption === 'string'
|
|
2159
|
+
? colorOption
|
|
2160
|
+
: colorOption.value
|
|
2150
2161
|
}
|
|
2151
2162
|
|
|
2152
2163
|
function updateHoveredLink(link: HTMLAnchorElement | null): void {
|
|
@@ -2385,7 +2396,9 @@
|
|
|
2385
2396
|
: 0
|
|
2386
2397
|
const minLeft = Math.max(
|
|
2387
2398
|
horizontalPadding,
|
|
2388
|
-
outlineOverlap > 24
|
|
2399
|
+
outlineOverlap > 24
|
|
2400
|
+
? outlineOverlap + 12
|
|
2401
|
+
: horizontalPadding,
|
|
2389
2402
|
)
|
|
2390
2403
|
const measuredToolbarWidth = selectionChromeEl
|
|
2391
2404
|
? Math.max(selectionChromeEl.offsetWidth, selectionChromeEl.clientWidth)
|
|
@@ -2448,17 +2461,6 @@
|
|
|
2448
2461
|
})
|
|
2449
2462
|
}
|
|
2450
2463
|
|
|
2451
|
-
function applyBlockFormat(kind: MarkdownBlockFormatKind): void {
|
|
2452
|
-
if (!syncSelectionForToolbarAction()) {
|
|
2453
|
-
return
|
|
2454
|
-
}
|
|
2455
|
-
|
|
2456
|
-
onapplyblockformat?.(kind)
|
|
2457
|
-
activeSelectionMenu = null
|
|
2458
|
-
activeSelectionMenuTrigger = null
|
|
2459
|
-
queueSelectionRefresh()
|
|
2460
|
-
}
|
|
2461
|
-
|
|
2462
2464
|
function applyBlockStyle(kind: MarkdownBlockStyleKind): void {
|
|
2463
2465
|
if (!syncSelectionForToolbarAction()) {
|
|
2464
2466
|
return
|
|
@@ -2581,7 +2583,9 @@
|
|
|
2581
2583
|
? target.closest<HTMLAnchorElement>('a[href]')
|
|
2582
2584
|
: null
|
|
2583
2585
|
|
|
2584
|
-
updateHoveredLink(link && previewHost?.contains(link)
|
|
2586
|
+
updateHoveredLink(link && previewHost?.contains(link)
|
|
2587
|
+
? link
|
|
2588
|
+
: null)
|
|
2585
2589
|
}
|
|
2586
2590
|
|
|
2587
2591
|
function handlePreviewMouseLeave(): void {
|
|
@@ -2858,7 +2862,7 @@
|
|
|
2858
2862
|
</button>
|
|
2859
2863
|
{/if}
|
|
2860
2864
|
|
|
2861
|
-
{#if
|
|
2865
|
+
{#if onapplyblockstyle}
|
|
2862
2866
|
{#if onrewrite}
|
|
2863
2867
|
<span class='hai-ai-doc-selection-divider'></span>
|
|
2864
2868
|
{/if}
|
|
@@ -2886,38 +2890,10 @@
|
|
|
2886
2890
|
></path>
|
|
2887
2891
|
</svg>
|
|
2888
2892
|
</button>
|
|
2889
|
-
{:else if legacyBlockFormattingEnabled}
|
|
2890
|
-
{#if onrewrite}
|
|
2891
|
-
<span class='hai-ai-doc-selection-divider'></span>
|
|
2892
|
-
{/if}
|
|
2893
|
-
<button
|
|
2894
|
-
type='button'
|
|
2895
|
-
class='hai-ai-doc-selection-btn'
|
|
2896
|
-
title={uiM('markdown_format_heading')}
|
|
2897
|
-
onclick={() => applyBlockFormat('heading')}
|
|
2898
|
-
>
|
|
2899
|
-
<svg viewBox='0 0 24 24' aria-hidden='true'>
|
|
2900
|
-
<path
|
|
2901
|
-
d='M5 5.25a.75.75 0 0 1 .75.75V11h6.5V6a.75.75 0 0 1 1.5 0v12a.75.75 0 0 1-1.5 0v-5.5h-6.5V18a.75.75 0 0 1-1.5 0V6A.75.75 0 0 1 5 5.25Zm11.25 2.5a.75.75 0 0 1 0 1.5h3a.75.75 0 0 1 0 1.5H18.5v8.5a.75.75 0 0 1-1.5 0v-8.5h-.75a.75.75 0 0 1 0-1.5h3Z'
|
|
2902
|
-
></path>
|
|
2903
|
-
</svg>
|
|
2904
|
-
</button>
|
|
2905
|
-
<button
|
|
2906
|
-
type='button'
|
|
2907
|
-
class='hai-ai-doc-selection-btn'
|
|
2908
|
-
title={uiM('markdown_format_bullet')}
|
|
2909
|
-
onclick={() => applyBlockFormat('bullet')}
|
|
2910
|
-
>
|
|
2911
|
-
<svg viewBox='0 0 24 24' aria-hidden='true'>
|
|
2912
|
-
<path
|
|
2913
|
-
d='M6.25 7.25a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Zm14 0a.75.75 0 0 1-.75.75H8.75a.75.75 0 0 1 0-1.5H19.5a.75.75 0 0 1 .75.75Zm-14 5.5a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Zm14 0a.75.75 0 0 1-.75.75H8.75a.75.75 0 0 1 0-1.5H19.5a.75.75 0 0 1 .75.75Zm-14 5.5a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Zm14 0a.75.75 0 0 1-.75.75H8.75a.75.75 0 0 1 0-1.5H19.5a.75.75 0 0 1 .75.75Z'
|
|
2914
|
-
></path>
|
|
2915
|
-
</svg>
|
|
2916
|
-
</button>
|
|
2917
2893
|
{/if}
|
|
2918
2894
|
|
|
2919
2895
|
{#if onapplyalignment}
|
|
2920
|
-
{#if
|
|
2896
|
+
{#if onapplyblockstyle || onrewrite}
|
|
2921
2897
|
<span class='hai-ai-doc-selection-divider'></span>
|
|
2922
2898
|
{/if}
|
|
2923
2899
|
<button
|
|
@@ -2955,7 +2931,7 @@
|
|
|
2955
2931
|
{/if}
|
|
2956
2932
|
|
|
2957
2933
|
{#if onapplyinlineformat || onapplylink || onapplycolor}
|
|
2958
|
-
{#if
|
|
2934
|
+
{#if onapplyblockstyle || onapplyalignment || onrewrite}
|
|
2959
2935
|
<span class='hai-ai-doc-selection-divider'></span>
|
|
2960
2936
|
{/if}
|
|
2961
2937
|
{/if}
|
|
@@ -3150,7 +3126,7 @@
|
|
|
3150
3126
|
</button>
|
|
3151
3127
|
{/each}
|
|
3152
3128
|
</div>
|
|
3153
|
-
{:else if activeSelectionMenu === 'block' &&
|
|
3129
|
+
{:else if activeSelectionMenu === 'block' && onapplyblockstyle}
|
|
3154
3130
|
<div
|
|
3155
3131
|
class='hai-ai-doc-selection-panel'
|
|
3156
3132
|
data-menu-alignment={selectionMenuAlignment}
|
|
@@ -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
|
}
|
|
@@ -125,16 +125,6 @@ export interface MarkdownRewriteRequest {
|
|
|
125
125
|
/** 当前文档标题。 */
|
|
126
126
|
title?: string;
|
|
127
127
|
}
|
|
128
|
-
/**
|
|
129
|
-
* 块级快捷操作种类:标题或列表。
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* import type { MarkdownBlockFormatKind } from '@h-ai/ui'
|
|
134
|
-
* const example: MarkdownBlockFormatKind = 'heading'
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
export type MarkdownBlockFormatKind = 'heading' | 'bullet';
|
|
138
128
|
/**
|
|
139
129
|
* 当前工具栏支持的具体段落和标题样式。
|
|
140
130
|
*
|
|
@@ -357,8 +347,6 @@ export interface AiDocumentEditorProps extends DataAttributes {
|
|
|
357
347
|
onhistory?: () => void;
|
|
358
348
|
/** 宿主自定义的整篇复制操作。 */
|
|
359
349
|
oncopydocument?: () => void | Promise<void>;
|
|
360
|
-
/** 标题/列表快捷格式操作回调。 */
|
|
361
|
-
onapplyblockformat?: BivariantCallback<[kind: MarkdownBlockFormatKind], void>;
|
|
362
350
|
/** 切换段落或具体标题级别的回调。 */
|
|
363
351
|
onapplyblockstyle?: BivariantCallback<[kind: MarkdownBlockStyleKind], void>;
|
|
364
352
|
/** 选区工具栏的行内格式回调。 */
|
|
@@ -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);
|
|
@@ -124,7 +124,9 @@ function resolveLang(lang) {
|
|
|
124
124
|
return null;
|
|
125
125
|
const resolved = LANG_ALIASES[normalized] ?? normalized;
|
|
126
126
|
const loaded = highlighter.getLoadedLanguages();
|
|
127
|
-
return loaded.includes(resolved)
|
|
127
|
+
return loaded.includes(resolved)
|
|
128
|
+
? resolved
|
|
129
|
+
: null;
|
|
128
130
|
}
|
|
129
131
|
/**
|
|
130
132
|
* 从 codeToHtml 输出中提取 <code> 标签内的 innerHTML
|
|
@@ -11,7 +11,7 @@ export { downloadAiDocument, resolveDocumentDownloadActions, resolveDocumentMark
|
|
|
11
11
|
export type { AiDocumentDownloadFormat, AiDocumentDownloadRequest, AiDocumentResolvedDownloadAction, } from './document-download.js';
|
|
12
12
|
export { renderMarkdownDocument } from './document-parse.js';
|
|
13
13
|
export type { MarkdownDocumentBlock, MarkdownDocumentHtmlBlock, MarkdownDocumentMermaidBlock, MarkdownDocumentParseOptions, MarkdownRenderResult, } from './document-parse.js';
|
|
14
|
-
export type { AiDocumentEditorProps,
|
|
14
|
+
export type { AiDocumentEditorProps, MarkdownBlockStyleKind, MarkdownCodeBlockItem, MarkdownCodeRunRequest, MarkdownCodeRunResult, MarkdownColorFormatRequest, MarkdownInlineFormatKind, MarkdownOutlineItem, MarkdownRewriteAction, MarkdownRewriteRequest, MarkdownTextAlignKind, MarkdownToolbarDownloadAction, } from './document-types.js';
|
|
15
15
|
export { highlightCode, isLanguageSupported } from './highlight.js';
|
|
16
16
|
export { parseMarkdown } from './markdown-parse.js';
|
|
17
17
|
export type { MarkdownParseOptions } from './markdown-parse.js';
|
|
@@ -26,11 +26,15 @@ 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
|
+
: '';
|
|
30
32
|
}
|
|
31
33
|
/** 围栏代码和 HTML 代码共用渲染,颜色与复制控件始终由框架生成。 */
|
|
32
34
|
function renderCodeBlock(text, lang, options) {
|
|
33
|
-
const language = lang && isLanguageSupported(lang)
|
|
35
|
+
const language = lang && isLanguageSupported(lang)
|
|
36
|
+
? lang
|
|
37
|
+
: '';
|
|
34
38
|
let highlighted;
|
|
35
39
|
if (options.enableHighlight && language) {
|
|
36
40
|
highlighted = highlightCode(text, language);
|
|
@@ -50,17 +54,30 @@ function renderCodeBlock(text, lang, options) {
|
|
|
50
54
|
: '';
|
|
51
55
|
return `<div class="hai-md-code-block">`
|
|
52
56
|
+ `<div class="hai-md-code-header">${langLabel}${copyBtn}</div>`
|
|
53
|
-
+ `<pre><code class="hai-hl${language
|
|
57
|
+
+ `<pre><code class="hai-hl${language
|
|
58
|
+
? ` language-${escapeHtml(language)}`
|
|
59
|
+
: ''}">${highlighted}</code></pre>`
|
|
54
60
|
+ `</div>`;
|
|
55
61
|
}
|
|
56
62
|
/** 仅还原代码文本的实体;随后仍按普通代码转义,绝不把代码中的标签作为 HTML 执行。 */
|
|
57
63
|
function decodeCodeText(text) {
|
|
58
|
-
const named = {
|
|
64
|
+
const named = {
|
|
65
|
+
amp: '&',
|
|
66
|
+
lt: '<',
|
|
67
|
+
gt: '>',
|
|
68
|
+
quot: '"',
|
|
69
|
+
apos: '\'',
|
|
70
|
+
nbsp: '\u00A0',
|
|
71
|
+
};
|
|
59
72
|
return text.replace(/&(#(?:[xX][\da-fA-F]+|\d+)|amp|lt|gt|quot|apos|nbsp);/g, (entity, key) => {
|
|
60
73
|
if (!key.startsWith('#'))
|
|
61
74
|
return named[key] ?? entity;
|
|
62
|
-
const code = key[1]?.toLowerCase() === 'x'
|
|
63
|
-
|
|
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;
|
|
64
81
|
});
|
|
65
82
|
}
|
|
66
83
|
/** 重建 pre/code,不保留输入的 style、事件或任意 class;其余 HTML 继续通过原有白名单。 */
|
|
@@ -103,7 +120,9 @@ function createRendererObject(options) {
|
|
|
103
120
|
const isExternal = safeHref && isExternalLinkHref(safeHref);
|
|
104
121
|
const attrs = [
|
|
105
122
|
`href="${escapeHtml(safeHref)}"`,
|
|
106
|
-
title
|
|
123
|
+
title
|
|
124
|
+
? `title="${escapeHtml(title)}"`
|
|
125
|
+
: '',
|
|
107
126
|
isExternal ? 'target="_blank" rel="noopener noreferrer"' : '',
|
|
108
127
|
].filter(Boolean).join(' ');
|
|
109
128
|
return `<a ${attrs}>${text}</a>`;
|
|
@@ -115,7 +134,9 @@ function createRendererObject(options) {
|
|
|
115
134
|
const attrs = [
|
|
116
135
|
`src="${escapeHtml(safeSrc)}"`,
|
|
117
136
|
`alt="${escapeHtml(text || '')}"`,
|
|
118
|
-
title
|
|
137
|
+
title
|
|
138
|
+
? `title="${escapeHtml(title)}"`
|
|
139
|
+
: '',
|
|
119
140
|
'loading="lazy"',
|
|
120
141
|
'class="hai-md-img"',
|
|
121
142
|
].filter(Boolean).join(' ');
|
|
@@ -187,7 +208,10 @@ function getOptionsKey(options) {
|
|
|
187
208
|
export function parseMarkdown(content, options) {
|
|
188
209
|
if (!content)
|
|
189
210
|
return '';
|
|
190
|
-
const mergedOptions = {
|
|
211
|
+
const mergedOptions = {
|
|
212
|
+
...DEFAULT_OPTIONS,
|
|
213
|
+
...options,
|
|
214
|
+
};
|
|
191
215
|
const key = getOptionsKey(mergedOptions);
|
|
192
216
|
if (!cachedInstance || cachedOptionsKey !== key) {
|
|
193
217
|
cachedInstance = createMarkedInstance(mergedOptions);
|
|
@@ -195,5 +219,7 @@ export function parseMarkdown(content, options) {
|
|
|
195
219
|
}
|
|
196
220
|
const result = cachedInstance.parse(content);
|
|
197
221
|
// marked.parse 可能返回 string | Promise<string>,此处同步调用
|
|
198
|
-
return typeof result === 'string'
|
|
222
|
+
return typeof result === 'string'
|
|
223
|
+
? result
|
|
224
|
+
: '';
|
|
199
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 = [];
|