@h-ai/ui 1.0.0-beta.18 → 1.0.0-beta.19

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.
Files changed (100) hide show
  1. package/README.en.md +30 -27
  2. package/README.ja.md +30 -27
  3. package/README.md +30 -27
  4. package/auto-import.js +118 -53
  5. package/dist/components/compounds/Accordion.svelte +6 -2
  6. package/dist/components/compounds/BottomNav.svelte +6 -2
  7. package/dist/components/compounds/Card.svelte +3 -1
  8. package/dist/components/compounds/Combobox.svelte +24 -6
  9. package/dist/components/compounds/DataTable.svelte +28 -8
  10. package/dist/components/compounds/DatePicker.svelte +6 -1
  11. package/dist/components/compounds/Drawer.svelte +12 -4
  12. package/dist/components/compounds/Dropdown.svelte +9 -2
  13. package/dist/components/compounds/Empty.svelte +10 -2
  14. package/dist/components/compounds/FormField.svelte +10 -2
  15. package/dist/components/compounds/JsonViewer.svelte +18 -6
  16. package/dist/components/compounds/Modal.svelte +8 -2
  17. package/dist/components/compounds/Pagination.svelte +22 -7
  18. package/dist/components/compounds/Popover.svelte +28 -3
  19. package/dist/components/compounds/Steps.svelte +6 -2
  20. package/dist/components/compounds/SwipeCell.svelte +3 -1
  21. package/dist/components/compounds/TableToolbar.svelte +32 -9
  22. package/dist/components/compounds/Tabs.svelte +15 -5
  23. package/dist/components/compounds/Timeline.svelte +6 -2
  24. package/dist/components/compounds/ToastContainer.svelte +27 -7
  25. package/dist/components/control-size.js +48 -8
  26. package/dist/components/primitives/Avatar.svelte +9 -3
  27. package/dist/components/primitives/BareInput.svelte +3 -1
  28. package/dist/components/primitives/Button.svelte +6 -2
  29. package/dist/components/primitives/IconButton.svelte +3 -1
  30. package/dist/components/primitives/Input.svelte +18 -2
  31. package/dist/components/primitives/Radio.svelte +3 -1
  32. package/dist/components/primitives/Range.svelte +3 -1
  33. package/dist/components/primitives/Rating.svelte +9 -3
  34. package/dist/components/primitives/Select.svelte +21 -5
  35. package/dist/components/primitives/Textarea.svelte +14 -2
  36. package/dist/components/scenes/ai/AiDocumentEditor.svelte +40 -12
  37. package/dist/components/scenes/ai/document-download.js +6 -2
  38. package/dist/components/scenes/ai/document-parse.js +24 -8
  39. package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
  40. package/dist/components/scenes/ai/highlight.js +3 -1
  41. package/dist/components/scenes/ai/markdown-parse.js +36 -10
  42. package/dist/components/scenes/ai/mermaid-render.js +13 -1
  43. package/dist/components/scenes/ai/safe-html.js +9 -3
  44. package/dist/components/scenes/ai/table/AiTableEditor.svelte +27 -9
  45. package/dist/components/scenes/app/FeedbackDetail.svelte +102 -24
  46. package/dist/components/scenes/app/FeedbackForm.svelte +70 -16
  47. package/dist/components/scenes/app/FeedbackList.svelte +138 -21
  48. package/dist/components/scenes/app/FeedbackRecorder.svelte +18 -5
  49. package/dist/components/scenes/app/FeedbackReplay.svelte +15 -3
  50. package/dist/components/scenes/app/FeedbackScreenshot.svelte +64 -13
  51. package/dist/components/scenes/app/LanguageSwitch.svelte +6 -2
  52. package/dist/components/scenes/app/SettingsLayout.svelte +3 -1
  53. package/dist/components/scenes/app/ThemeSelector.svelte +22 -4
  54. package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
  55. package/dist/components/scenes/app/feedback-functions.js +6 -2
  56. package/dist/components/scenes/charts/Chart.svelte +16 -5
  57. package/dist/components/scenes/charts/MetricCard.svelte +21 -4
  58. package/dist/components/scenes/charts/chart-presets.js +42 -5
  59. package/dist/components/scenes/charts/renderers/LineChart.svelte +38 -12
  60. package/dist/components/scenes/crud/CrudDetailDrawer.svelte +6 -2
  61. package/dist/components/scenes/crud/CrudDetailPanel.svelte +6 -2
  62. package/dist/components/scenes/crud/CrudEditPanel.svelte +41 -12
  63. package/dist/components/scenes/crud/CrudPage.svelte +34 -9
  64. package/dist/components/scenes/crud/crud-controller.svelte.js +23 -8
  65. package/dist/components/scenes/crud/crud-form-validation.js +27 -9
  66. package/dist/components/scenes/crypto/EncryptedInput.svelte +9 -3
  67. package/dist/components/scenes/error/error-presets.js +30 -5
  68. package/dist/components/scenes/guide/GuideHostContent.svelte +7 -1
  69. package/dist/components/scenes/guide/HelpCenter.svelte +23 -4
  70. package/dist/components/scenes/iam/AgreementNotice.svelte +9 -3
  71. package/dist/components/scenes/iam/AuthPanel.svelte +73 -15
  72. package/dist/components/scenes/iam/ChangePasswordForm.svelte +6 -2
  73. package/dist/components/scenes/iam/ForgotPasswordForm.svelte +9 -3
  74. package/dist/components/scenes/iam/LoginForm.svelte +32 -8
  75. package/dist/components/scenes/iam/PasswordInput.svelte +49 -11
  76. package/dist/components/scenes/iam/RegisterForm.svelte +11 -3
  77. package/dist/components/scenes/iam/ResetPasswordForm.svelte +6 -2
  78. package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +3 -1
  79. package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +4 -1
  80. package/dist/components/scenes/iam/UserProfile.svelte +41 -14
  81. package/dist/components/scenes/iam/auth-captcha.js +9 -2
  82. package/dist/components/scenes/iam/auth-error-message.js +11 -3
  83. package/dist/components/scenes/iam/password-utils.js +9 -2
  84. package/dist/components/scenes/iam/sensitive-actions.svelte.js +4 -1
  85. package/dist/components/scenes/storage/FileList.svelte +3 -1
  86. package/dist/components/scenes/storage/FileUpload.svelte +7 -2
  87. package/dist/components/scenes/types.d.ts +2 -2
  88. package/dist/guide-storage.js +12 -4
  89. package/dist/guide.svelte.js +59 -16
  90. package/dist/i18n.svelte.js +9 -3
  91. package/dist/internal/dialog-focus.d.ts +19 -0
  92. package/dist/internal/dialog-focus.js +104 -4
  93. package/dist/internal/form-validation.svelte.js +46 -15
  94. package/dist/internal/icon-safety.js +6 -2
  95. package/dist/message.svelte.js +6 -2
  96. package/dist/messagebox.svelte.js +6 -2
  97. package/dist/theme-config.js +135 -21
  98. package/dist/toast.svelte.js +14 -3
  99. package/dist/utils.js +6 -2
  100. package/package.json +19 -19
@@ -60,7 +60,9 @@
60
60
  if (!id)
61
61
  return
62
62
  const paused = expandedId === id || hoveredId === id || focusedId === id
63
- untrack(() => paused ? toast.pause(id) : toast.resume(id))
63
+ untrack(() => paused
64
+ ? toast.pause(id)
65
+ : toast.resume(id))
64
66
  return () => untrack(() => toast.resume(id))
65
67
  })
66
68
 
@@ -100,7 +102,9 @@
100
102
  restoreFocus()
101
103
  }
102
104
  else {
103
- previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null
105
+ previousFocus = document.activeElement instanceof HTMLElement
106
+ ? document.activeElement
107
+ : null
104
108
  const target = layerElement?.querySelector<HTMLElement>('button, .hai-toast-item')
105
109
  // 优先聚焦排查或关闭按钮;没有按钮的提示仍可聚焦阅读,再按 F8 返回。
106
110
  const button = layerElement?.querySelector<HTMLButtonElement>('button')
@@ -176,7 +180,9 @@
176
180
  return
177
181
  }
178
182
 
179
- const modal = hasItems ? findTopModalDialog() : null
183
+ const modal = hasItems
184
+ ? findTopModalDialog()
185
+ : null
180
186
 
181
187
  if (modal) {
182
188
  // 寄宿到 dialog:popover 元素未显示时会 display:none,故先移除 popover 属性。
@@ -214,7 +220,11 @@
214
220
 
215
221
  // dialog 通过 showModal()/close() 切换 `open` 属性;据此重新寄宿 Toast 层。
216
222
  const observer = new MutationObserver(() => relocate())
217
- observer.observe(document.body, { subtree: true, attributes: true, attributeFilter: ['open'] })
223
+ observer.observe(document.body, {
224
+ subtree: true,
225
+ attributes: true,
226
+ attributeFilter: ['open'],
227
+ })
218
228
 
219
229
  return () => {
220
230
  observer.disconnect()
@@ -238,7 +248,11 @@
238
248
  <div {...dataAttributes} bind:this={layerElement} popover='manual' class='hai-toast-layer'>
239
249
  {#each currentItems as item (item.id)}
240
250
  <div class='hai-toast-position' data-position={item.position ?? 'bottom-right'}>
241
- <div {...getDataAttributes(item)} class='hai-toast-item text-base-content' role={item.variant === 'error' ? 'alert' : 'status'} aria-live={item.variant === 'error' ? 'assertive' : 'polite'} aria-atomic='true' aria-keyshortcuts='F8' tabindex='-1' data-variant={item.variant ?? 'info'}
251
+ <div {...getDataAttributes(item)} class='hai-toast-item text-base-content' role={item.variant === 'error'
252
+ ? 'alert'
253
+ : 'status'} aria-live={item.variant === 'error'
254
+ ? 'assertive'
255
+ : 'polite'} aria-atomic='true' aria-keyshortcuts='F8' tabindex='-1' data-variant={item.variant ?? 'info'}
242
256
  onpointerenter={(event) => {
243
257
  if (event.pointerType !== 'touch')
244
258
  hoveredId = item.id
@@ -263,7 +277,9 @@
263
277
  {uiM('toast_copyTraceId')}
264
278
  </button>
265
279
  {#if copyResult?.id === item.id}
266
- <p class='mt-1' role='status'>{copyResult.success ? uiM('toast_traceCopied') : uiM('toast_traceCopyFailed')}</p>
280
+ <p class='mt-1' role='status'>{copyResult.success
281
+ ? uiM('toast_traceCopied')
282
+ : uiM('toast_traceCopyFailed')}</p>
267
283
  {/if}
268
284
  </div>
269
285
  {/if}
@@ -273,7 +289,11 @@
273
289
  <button type='button' class='btn btn-ghost btn-sm btn-square hai-toast-details-toggle'
274
290
  aria-label={uiM('toast_diagnostics')} title={uiM('toast_diagnostics')}
275
291
  aria-expanded={expandedId === item.id} aria-controls={`toast-details-${item.id}`}
276
- onclick={() => { expandedId = expandedId === item.id ? undefined : item.id }}
292
+ onclick={() => {
293
+ expandedId = expandedId === item.id
294
+ ? undefined
295
+ : item.id
296
+ }}
277
297
  ><span aria-hidden='true' class='icon-[tabler--info-circle] size-4'></span></button>
278
298
  {/if}
279
299
  {#if item.dismissible}
@@ -1,12 +1,52 @@
1
1
  const FORM_CONTROL_SIZE_CLASSES = {
2
- 'xs': { height: 'h-8', minHeight: 'min-h-8', spacing: 'px-2.5 text-xs', control: 'h-8 px-2.5 text-xs' },
3
- 'sm': { height: 'h-9', minHeight: 'min-h-9', spacing: 'px-3 text-sm', control: 'h-9 px-3 text-sm' },
4
- 'md': { height: 'h-10', minHeight: 'min-h-10', spacing: 'px-3 text-sm', control: 'h-10 px-3 text-sm' },
5
- 'lg': { height: 'h-12', minHeight: 'min-h-12', spacing: 'px-4 text-base', control: 'h-12 px-4 text-base' },
6
- 'xl': { height: 'h-14', minHeight: 'min-h-14', spacing: 'px-4 text-lg', control: 'h-14 px-4 text-lg' },
7
- '2xl': { height: 'h-14', minHeight: 'min-h-14', spacing: 'px-4 text-lg', control: 'h-14 px-4 text-lg' },
8
- '3xl': { height: 'h-14', minHeight: 'min-h-14', spacing: 'px-4 text-lg', control: 'h-14 px-4 text-lg' },
9
- '4xl': { height: 'h-14', minHeight: 'min-h-14', spacing: 'px-4 text-lg', control: 'h-14 px-4 text-lg' },
2
+ 'xs': {
3
+ height: 'h-8',
4
+ minHeight: 'min-h-8',
5
+ spacing: 'px-2.5 text-xs',
6
+ control: 'h-8 px-2.5 text-xs',
7
+ },
8
+ 'sm': {
9
+ height: 'h-9',
10
+ minHeight: 'min-h-9',
11
+ spacing: 'px-3 text-sm',
12
+ control: 'h-9 px-3 text-sm',
13
+ },
14
+ 'md': {
15
+ height: 'h-10',
16
+ minHeight: 'min-h-10',
17
+ spacing: 'px-3 text-sm',
18
+ control: 'h-10 px-3 text-sm',
19
+ },
20
+ 'lg': {
21
+ height: 'h-12',
22
+ minHeight: 'min-h-12',
23
+ spacing: 'px-4 text-base',
24
+ control: 'h-12 px-4 text-base',
25
+ },
26
+ 'xl': {
27
+ height: 'h-14',
28
+ minHeight: 'min-h-14',
29
+ spacing: 'px-4 text-lg',
30
+ control: 'h-14 px-4 text-lg',
31
+ },
32
+ '2xl': {
33
+ height: 'h-14',
34
+ minHeight: 'min-h-14',
35
+ spacing: 'px-4 text-lg',
36
+ control: 'h-14 px-4 text-lg',
37
+ },
38
+ '3xl': {
39
+ height: 'h-14',
40
+ minHeight: 'min-h-14',
41
+ spacing: 'px-4 text-lg',
42
+ control: 'h-14 px-4 text-lg',
43
+ },
44
+ '4xl': {
45
+ height: 'h-14',
46
+ minHeight: 'min-h-14',
47
+ spacing: 'px-4 text-lg',
48
+ control: 'h-14 px-4 text-lg',
49
+ },
10
50
  };
11
51
  /**
12
52
  * 获取输入类控件的统一尺寸类名。
@@ -79,7 +79,9 @@
79
79
  return gradientPairs[hash % gradientPairs.length]
80
80
  })
81
81
 
82
- const sizeValue = $derived(typeof size === 'number' ? `${size}px` : undefined)
82
+ const sizeValue = $derived(typeof size === 'number'
83
+ ? `${size}px`
84
+ : undefined)
83
85
 
84
86
  const containerClass = $derived(
85
87
  cn(
@@ -92,7 +94,9 @@
92
94
  cn(
93
95
  'flex items-center justify-center font-semibold',
94
96
  typeof size === 'string' && sizeMap[size],
95
- shape === 'circle' ? 'rounded-full' : 'rounded-lg',
97
+ shape === 'circle'
98
+ ? 'rounded-full'
99
+ : 'rounded-lg',
96
100
  !src && `bg-gradient-to-br ${colorPair()[0]} ${colorPair()[1]}`,
97
101
  className,
98
102
  ),
@@ -108,7 +112,9 @@
108
112
  {#if src}
109
113
  <img {src} {alt} />
110
114
  {:else}
111
- <span class={typeof size === 'string' ? textSizeMap[size] : 'text-lg'}>
115
+ <span class={typeof size === 'string'
116
+ ? textSizeMap[size]
117
+ : 'text-lg'}>
112
118
  {initials()}
113
119
  </span>
114
120
  {/if}
@@ -113,7 +113,9 @@
113
113
  aria-controls={ariaControls}
114
114
  aria-autocomplete={ariaAutocomplete}
115
115
  class={className}
116
- value={type === 'file' ? undefined : value}
116
+ value={type === 'file'
117
+ ? undefined
118
+ : value}
117
119
  oninput={handleInput}
118
120
  onchange={handleChange}
119
121
  onkeydown={handleKeydown}
@@ -65,8 +65,12 @@
65
65
  class={buttonClass}
66
66
  disabled={disabled || loading}
67
67
  aria-label={ariaLabel || undefined}
68
- aria-keyshortcuts={type === 'submit' && submitHint ? 'Enter' : undefined}
69
- title={type === 'submit' && submitHint ? uiM('keyboard_submit_enter') : undefined}
68
+ aria-keyshortcuts={type === 'submit' && submitHint
69
+ ? 'Enter'
70
+ : undefined}
71
+ title={type === 'submit' && submitHint
72
+ ? uiM('keyboard_submit_enter')
73
+ : undefined}
70
74
  onclick={handleClick}
71
75
  >
72
76
  {#if loading}
@@ -49,7 +49,9 @@
49
49
  * 若需要复杂内容,请改用 Snippet / children。
50
50
  */
51
51
  const sanitizedIcon = $derived(
52
- typeof icon === 'string' ? sanitizeInlineSvg(icon) : '',
52
+ typeof icon === 'string'
53
+ ? sanitizeInlineSvg(icon)
54
+ : '',
53
55
  )
54
56
 
55
57
  const buttonClass = $derived(
@@ -53,7 +53,18 @@
53
53
 
54
54
  const dataAttributes = $derived(getDataAttributes(restProps))
55
55
  const field = getFormFieldContext()
56
- const validation = createControlValidation(() => validationMessage, () => [value, required, readonly, disabled, pattern, min, max, minlength, maxlength, step])
56
+ const validation = createControlValidation(() => validationMessage, () => [
57
+ value,
58
+ required,
59
+ readonly,
60
+ disabled,
61
+ pattern,
62
+ min,
63
+ max,
64
+ minlength,
65
+ maxlength,
66
+ step,
67
+ ])
57
68
  const uniqueId = $props.id()
58
69
  const messageId = `${uniqueId}-error`
59
70
  const localError = $derived(resolveFormText(error) || validation.message)
@@ -124,7 +135,12 @@
124
135
  bind:this={inputRef}
125
136
  id={id ?? field?.controlId}
126
137
  aria-invalid={effectiveError ? true : undefined}
127
- aria-describedby={[field?.messageId, localError && !field?.error ? messageId : ''].filter(Boolean).join(' ') || undefined}
138
+ aria-describedby={[
139
+ field?.messageId,
140
+ localError && !field?.error
141
+ ? messageId
142
+ : '',
143
+ ].filter(Boolean).join(' ') || undefined}
128
144
  {name}
129
145
  {type}
130
146
  {placeholder}
@@ -38,7 +38,9 @@
38
38
  const containerClass = $derived(
39
39
  cn(
40
40
  'flex gap-2',
41
- direction === 'horizontal' ? 'flex-row flex-wrap' : 'flex-col',
41
+ direction === 'horizontal'
42
+ ? 'flex-row flex-wrap'
43
+ : 'flex-col',
42
44
  className,
43
45
  ),
44
46
  )
@@ -106,7 +106,9 @@
106
106
  )
107
107
 
108
108
  // 计算步长数量
109
- const stepCount = $derived(showSteps ? Math.floor((max - min) / step) + 1 : 0)
109
+ const stepCount = $derived(showSteps
110
+ ? Math.floor((max - min) / step) + 1
111
+ : 0)
110
112
 
111
113
  function handleInput(e: Event) {
112
114
  const target = e.target as HTMLInputElement
@@ -148,7 +148,9 @@
148
148
  i === Math.floor(value) && value % 1 !== 0 && 'opacity-60',
149
149
  )}
150
150
  aria-label={uiM('rating_star', { count: i + 1 })}
151
- aria-current={i + 1 <= value ? 'true' : undefined}
151
+ aria-current={i + 1 <= value
152
+ ? 'true'
153
+ : undefined}
152
154
  ></div>
153
155
  {/each}
154
156
  </div>
@@ -160,12 +162,16 @@
160
162
  type='radio'
161
163
  {name}
162
164
  class={cn(
163
- item.value === 0 ? 'rating-hidden' : 'mask mask-star-2',
165
+ item.value === 0
166
+ ? 'rating-hidden'
167
+ : 'mask mask-star-2',
164
168
  item.value !== 0 && colorClass,
165
169
  half && item.isHalf && 'mask-half-1',
166
170
  half && !item.isHalf && item.value !== 0 && 'mask-half-2',
167
171
  )}
168
- aria-label={item.value === 0 ? uiM('rating_clear') : uiM('rating_star', { count: item.value })}
172
+ aria-label={item.value === 0
173
+ ? uiM('rating_clear')
174
+ : uiM('rating_star', { count: item.value })}
169
175
  checked={value === item.value}
170
176
  {disabled}
171
177
  onchange={() => handleChange(item.value)}
@@ -57,7 +57,9 @@
57
57
  useControlFeedback(() => resolveFormText(error) || validation.message)
58
58
  let nativeSelect: HTMLSelectElement | undefined = $state()
59
59
  // 独立保存原生选中值,筛选输入的文字不能代替表单实际选项。
60
- const nativeValue = $derived(value === undefined || value === null ? '' : String(value))
60
+ const nativeValue = $derived(value === undefined || value === null
61
+ ? ''
62
+ : String(value))
61
63
  $effect(() => {
62
64
  void options
63
65
  void required
@@ -333,12 +335,19 @@
333
335
  bind:this={inputRef}
334
336
  id={controlId}
335
337
  aria-invalid={effectiveError ? true : undefined}
336
- aria-describedby={[field?.messageId, localError && !field?.error ? messageId : ''].filter(Boolean).join(' ') || undefined}
338
+ aria-describedby={[
339
+ field?.messageId,
340
+ localError && !field?.error
341
+ ? messageId
342
+ : '',
343
+ ].filter(Boolean).join(' ') || undefined}
337
344
  type='text'
338
345
  class={inputClass}
339
346
  {disabled}
340
347
  {placeholder}
341
- value={isDropdownOpen ? filterText : selectedLabel()}
348
+ value={isDropdownOpen
349
+ ? filterText
350
+ : selectedLabel()}
342
351
  oninput={handleFilterInput}
343
352
  onkeydown={handleInputKeydown}
344
353
  onfocus={() => {
@@ -357,7 +366,12 @@
357
366
  bind:this={inputRef}
358
367
  id={controlId}
359
368
  aria-invalid={effectiveError ? true : undefined}
360
- aria-describedby={[field?.messageId, localError && !field?.error ? messageId : ''].filter(Boolean).join(' ') || undefined}
369
+ aria-describedby={[
370
+ field?.messageId,
371
+ localError && !field?.error
372
+ ? messageId
373
+ : '',
374
+ ].filter(Boolean).join(' ') || undefined}
361
375
  type='text'
362
376
  class={inputClass}
363
377
  readonly
@@ -434,7 +448,9 @@
434
448
  handleOptionSelect(option.value, option.disabled)
435
449
  }
436
450
  }}
437
- tabindex={option.disabled ? -1 : 0}
451
+ tabindex={option.disabled
452
+ ? -1
453
+ : 0}
438
454
  >
439
455
  {option.label}
440
456
  </li>
@@ -50,7 +50,14 @@
50
50
 
51
51
  const dataAttributes = $derived(getDataAttributes(restProps))
52
52
  const field = getFormFieldContext()
53
- const validation = createControlValidation(() => validationMessage, () => [value, required, readonly, disabled, minlength, maxlength])
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={[field?.messageId, localError && !field?.error ? messageId : ''].filter(Boolean).join(' ') || undefined}
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 ? resolvedRewriteActions[0] : null,
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' ? 'hai-markdown-code-only' : '',
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
- { id: 'polish', label: uiM('markdown_rewrite_polish') },
781
- { id: 'expand', label: uiM('markdown_rewrite_expand') },
782
- { id: 'shorten', label: uiM('markdown_rewrite_shorten') },
783
- { id: 'explain', label: uiM('markdown_rewrite_explain') },
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 ? error.message : uiM('markdown_run_failed'),
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 ? error.message : uiM('markdown_mermaid_failed')
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) ? length : null
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' ? colorOption : colorOption.value
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 ? outlineOverlap + 12 : horizontalPadding,
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) ? link : null)
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') ? '' : '\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') ? title : `${title}.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 ? base : `${base}-${nextCount}`;
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 ? `${prefix} ${item.text}` : item.text,
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 ? ` language-${escapeHtml(highlightLanguage)}` : ''}">${highlighted}</code></pre>`
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 ? `title="${escapeHtml(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 ? `title="${escapeHtml(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 ? ` style="text-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 ? ` style="text-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' ? result : '',
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) ? normalized : undefined;
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 ? `color:${spanToken.color}` : '',
150
- spanToken.background ? `background-color:${spanToken.background}` : '',
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) ? resolved : null;
127
+ return loaded.includes(resolved)
128
+ ? resolved
129
+ : null;
128
130
  }
129
131
  /**
130
132
  * 从 codeToHtml 输出中提取 <code> 标签内的 innerHTML