@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
package/auto-import.js
CHANGED
|
@@ -120,65 +120,254 @@ const UI_COMPONENTS = new Set([
|
|
|
120
120
|
'CrudEditPanel',
|
|
121
121
|
'CrudFilterBar',
|
|
122
122
|
'CrudPage',
|
|
123
|
+
// scenes - charts
|
|
124
|
+
'Chart',
|
|
125
|
+
'DashboardGrid',
|
|
126
|
+
'MetricCard',
|
|
127
|
+
'ReportCard',
|
|
123
128
|
// scenes - error
|
|
124
129
|
'ErrorPage',
|
|
125
130
|
])
|
|
126
131
|
|
|
127
|
-
const TAG_REGEX = /<([A-Z][A-Za-z0-9]*)\b/g
|
|
128
|
-
const SCRIPT_REGEX = /<script\b([^>]*)>([\s\S]*?)<\/script>/g
|
|
129
|
-
const UI_IMPORT_REGEX = /import\s*\{([^}]+)\}\s*from\s*['"]@h-ai\/ui['"];?/
|
|
130
132
|
const WINDOWS_PATH_SEPARATOR_REGEX = /\\/g
|
|
131
|
-
const MODULE_CONTEXT_ATTR_REGEX = /context\s*=\s*['"]module['"]/i
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
/** 解构绑定与普通名称共用同一收集路径,类型注解不会创建运行时值。 */
|
|
135
|
+
function bindPattern(pattern, bindings) {
|
|
136
|
+
if (!pattern)
|
|
137
|
+
return
|
|
138
|
+
if (pattern.type === 'Identifier') {
|
|
139
|
+
bindings.add(pattern.name)
|
|
140
|
+
}
|
|
141
|
+
else if (pattern.type === 'RestElement' || pattern.type === 'SpreadElement') {
|
|
142
|
+
bindPattern(pattern.argument, bindings)
|
|
143
|
+
}
|
|
144
|
+
else if (pattern.type === 'AssignmentPattern') {
|
|
145
|
+
bindPattern(pattern.left, bindings)
|
|
146
|
+
}
|
|
147
|
+
else if (pattern.type === 'ArrayPattern' || pattern.type === 'ArrayExpression') {
|
|
148
|
+
pattern.elements.forEach(element => bindPattern(element, bindings))
|
|
149
|
+
}
|
|
150
|
+
else if (pattern.type === 'ObjectPattern' || pattern.type === 'ObjectExpression') {
|
|
151
|
+
pattern.properties.forEach(property => bindPattern(['RestElement', 'SpreadElement'].includes(property.type)
|
|
152
|
+
? property.argument
|
|
153
|
+
: property.value, bindings))
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** 只记录顶层真实值声明;声明在函数体里的同名局部值不影响组件模板。 */
|
|
158
|
+
function bindDeclaration(statement, bindings) {
|
|
159
|
+
const declaration = statement.type === 'ExportNamedDeclaration' || statement.type === 'ExportDefaultDeclaration'
|
|
160
|
+
? statement.declaration
|
|
161
|
+
: statement
|
|
162
|
+
if (!declaration)
|
|
163
|
+
return
|
|
164
|
+
if (declaration.type === 'VariableDeclaration') {
|
|
165
|
+
declaration.declarations.forEach(item => bindPattern(item.id, bindings))
|
|
166
|
+
}
|
|
167
|
+
else if ([
|
|
168
|
+
'FunctionDeclaration',
|
|
169
|
+
'ClassDeclaration',
|
|
170
|
+
'TSEnumDeclaration',
|
|
171
|
+
'TSModuleDeclaration',
|
|
172
|
+
].includes(declaration.type)) {
|
|
173
|
+
bindPattern(declaration.id, bindings)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 组件只来自模板 AST,同时尊重脚本与 each/await/snippet/let 的词法绑定。 */
|
|
178
|
+
function collectUsedComponents(ast) {
|
|
134
179
|
const used = new Set()
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
180
|
+
const outer = new Set([
|
|
181
|
+
...analyzeScript(ast.module).bindings,
|
|
182
|
+
...analyzeScript(ast.instance).bindings,
|
|
183
|
+
])
|
|
184
|
+
const pending = [
|
|
185
|
+
{ node: ast.fragment, bindings: outer },
|
|
186
|
+
]
|
|
187
|
+
while (pending.length) {
|
|
188
|
+
const { node, bindings } = pending.pop()
|
|
189
|
+
if (!node || typeof node !== 'object')
|
|
190
|
+
continue
|
|
191
|
+
if (Array.isArray(node)) {
|
|
192
|
+
for (let index = node.length - 1; index >= 0; index--)
|
|
193
|
+
pending.push({ node: node[index], bindings })
|
|
194
|
+
continue
|
|
195
|
+
}
|
|
196
|
+
if (node.type === 'Component' && UI_COMPONENTS.has(node.name) && !bindings.has(node.name))
|
|
197
|
+
used.add(node.name)
|
|
198
|
+
if (node.type === 'EachBlock') {
|
|
199
|
+
const body = new Set(bindings)
|
|
200
|
+
bindPattern(node.context, body)
|
|
201
|
+
if (node.index)
|
|
202
|
+
body.add(node.index)
|
|
203
|
+
pending.push({ node: node.fallback, bindings }, { node: node.body, bindings: body })
|
|
204
|
+
continue
|
|
205
|
+
}
|
|
206
|
+
if (node.type === 'AwaitBlock') {
|
|
207
|
+
const then = new Set(bindings)
|
|
208
|
+
const caught = new Set(bindings)
|
|
209
|
+
bindPattern(node.value, then)
|
|
210
|
+
bindPattern(node.error, caught)
|
|
211
|
+
pending.push({ node: node.catch, bindings: caught }, { node: node.then, bindings: then }, { node: node.pending, bindings })
|
|
212
|
+
continue
|
|
213
|
+
}
|
|
214
|
+
if (node.type === 'SnippetBlock') {
|
|
215
|
+
const body = new Set(bindings)
|
|
216
|
+
bindPattern(node.expression, body)
|
|
217
|
+
node.parameters.forEach(parameter => bindPattern(parameter, body))
|
|
218
|
+
pending.push({ node: node.body, bindings: body })
|
|
219
|
+
continue
|
|
220
|
+
}
|
|
221
|
+
let scoped = bindings
|
|
222
|
+
if (node.type === 'Fragment') {
|
|
223
|
+
scoped = new Set(bindings)
|
|
224
|
+
for (const child of node.nodes) {
|
|
225
|
+
if (child.type === 'SnippetBlock')
|
|
226
|
+
bindPattern(child.expression, scoped)
|
|
227
|
+
else if (child.type === 'ConstTag' || child.type === 'DeclarationTag')
|
|
228
|
+
bindDeclaration(child.declaration, scoped)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for (const attribute of node.attributes ?? []) {
|
|
232
|
+
if (attribute.type === 'LetDirective') {
|
|
233
|
+
if (scoped === bindings)
|
|
234
|
+
scoped = new Set(bindings)
|
|
235
|
+
bindPattern(attribute.expression ?? { type: 'Identifier', name: attribute.name }, scoped)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// 仅遍历模板子节点;脚本、属性表达式和样式中的文本不会成为组件节点。
|
|
239
|
+
for (const key of [
|
|
240
|
+
'fragment',
|
|
241
|
+
'nodes',
|
|
242
|
+
'consequent',
|
|
243
|
+
'alternate',
|
|
244
|
+
]) {
|
|
245
|
+
if (node[key])
|
|
246
|
+
pending.push({ node: node[key], bindings: scoped })
|
|
139
247
|
}
|
|
140
248
|
}
|
|
141
249
|
return used
|
|
142
250
|
}
|
|
143
251
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
252
|
+
/** 一次解析同时提供运行时绑定与真实 import 范围,不再扫描字符串/注释中的伪 import。 */
|
|
253
|
+
function analyzeScript(script) {
|
|
254
|
+
const bindings = new Set()
|
|
255
|
+
const externalTypeBindings = new Set()
|
|
256
|
+
const declarations = []
|
|
257
|
+
for (const statement of script?.content.body ?? []) {
|
|
258
|
+
if (statement.type !== 'ImportDeclaration') {
|
|
259
|
+
bindDeclaration(statement, bindings)
|
|
150
260
|
continue
|
|
261
|
+
}
|
|
151
262
|
for (const specifier of statement.specifiers) {
|
|
152
|
-
if (specifier.importKind !== 'type')
|
|
153
|
-
|
|
263
|
+
if (statement.importKind !== 'type' && specifier.importKind !== 'type')
|
|
264
|
+
bindings.add(specifier.local.name)
|
|
265
|
+
else if (statement.source.value !== '@h-ai/ui')
|
|
266
|
+
externalTypeBindings.add(specifier.local.name)
|
|
267
|
+
}
|
|
268
|
+
if (statement.source.value === '@h-ai/ui')
|
|
269
|
+
declarations.push(statement)
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
bindings,
|
|
273
|
+
externalTypeBindings,
|
|
274
|
+
declarations,
|
|
275
|
+
offset: script?.content.start ?? 0,
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** 整条 type import 提升为混合导入时,跳过词法空白和注释,只移除解析器确认的 type 关键字。 */
|
|
280
|
+
function typeKeywordStart(scriptContent, declarationStart) {
|
|
281
|
+
let cursor = declarationStart + 'import'.length
|
|
282
|
+
while (cursor < scriptContent.length) {
|
|
283
|
+
if (/\s/.test(scriptContent[cursor])) {
|
|
284
|
+
cursor++
|
|
285
|
+
}
|
|
286
|
+
else if (scriptContent.startsWith('/*', cursor)) {
|
|
287
|
+
const end = scriptContent.indexOf('*/', cursor + 2)
|
|
288
|
+
if (end === -1)
|
|
289
|
+
break
|
|
290
|
+
cursor = end + 2
|
|
291
|
+
}
|
|
292
|
+
else if (scriptContent.startsWith('//', cursor)) {
|
|
293
|
+
const end = scriptContent.indexOf('\n', cursor + 2)
|
|
294
|
+
if (end === -1)
|
|
295
|
+
break
|
|
296
|
+
cursor = end + 1
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
break
|
|
154
300
|
}
|
|
155
301
|
}
|
|
156
|
-
|
|
302
|
+
if (scriptContent.slice(cursor, cursor + 4) !== 'type')
|
|
303
|
+
throw new Error('Unable to locate the parsed type-only import keyword')
|
|
304
|
+
return cursor
|
|
157
305
|
}
|
|
158
306
|
|
|
159
|
-
function mergeHaiUiImport(scriptContent, components) {
|
|
307
|
+
function mergeHaiUiImport(scriptContent, components, analysis) {
|
|
160
308
|
if (components.length === 0)
|
|
161
309
|
return scriptContent
|
|
162
310
|
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
|
|
311
|
+
const missing = new Set(components)
|
|
312
|
+
const edits = []
|
|
313
|
+
let target
|
|
314
|
+
for (const declaration of analysis.declarations) {
|
|
315
|
+
const named = declaration.specifiers.filter(specifier => specifier.type === 'ImportSpecifier')
|
|
316
|
+
if (named.length === 0)
|
|
317
|
+
continue
|
|
318
|
+
const typeOnly = declaration.importKind === 'type'
|
|
319
|
+
const promoted = named.filter(specifier => (typeOnly || specifier.importKind === 'type') && missing.has(specifier.local.name))
|
|
320
|
+
if (typeOnly) {
|
|
321
|
+
if (promoted.length === 0)
|
|
322
|
+
continue
|
|
323
|
+
const start = typeKeywordStart(scriptContent, declaration.start - analysis.offset)
|
|
324
|
+
edits.push({ start, end: start + 4, text: '' })
|
|
325
|
+
// 仅被用作组件的类型绑定提升为值;同声明内其它类型继续保持 type,不引入不存在的运行时导出。
|
|
326
|
+
for (const specifier of named) {
|
|
327
|
+
if (!promoted.includes(specifier)) {
|
|
328
|
+
const start = specifier.start - analysis.offset
|
|
329
|
+
edits.push({ start, end: start, text: 'type ' })
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
for (const specifier of promoted) {
|
|
335
|
+
const start = specifier.start - analysis.offset
|
|
336
|
+
edits.push({ start, end: start + 'type'.length, text: '' })
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
for (const specifier of promoted)
|
|
340
|
+
missing.delete(specifier.local.name)
|
|
341
|
+
target ??= named[named.length - 1]
|
|
173
342
|
}
|
|
174
343
|
|
|
175
|
-
|
|
344
|
+
if (missing.size > 0) {
|
|
345
|
+
if (target) {
|
|
346
|
+
const start = target.end - analysis.offset
|
|
347
|
+
// 在最后一个真实具名绑定后插入;已有注释、别名、尾逗号和导入属性保持原样。
|
|
348
|
+
edits.push({ start, end: start, text: `, ${[...missing].join(', ')}` })
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
edits.push({ start: 0, end: 0, text: `import { ${[...missing].join(', ')} } from '@h-ai/ui'\n` })
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
let result = scriptContent
|
|
355
|
+
for (const edit of edits.sort((left, right) => right.start - left.start))
|
|
356
|
+
result = result.slice(0, edit.start) + edit.text + result.slice(edit.end)
|
|
357
|
+
return result
|
|
176
358
|
}
|
|
177
359
|
|
|
178
|
-
function updateScriptBlock(scriptContent, usedComponents) {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
360
|
+
function updateScriptBlock(scriptContent, usedComponents, filename, ast) {
|
|
361
|
+
const analysis = analyzeScript(ast.instance)
|
|
362
|
+
// 模块脚本的运行时 import 同样可供模板使用,但只向实例脚本注入缺失项。
|
|
363
|
+
for (const name of analyzeScript(ast.module).bindings)
|
|
364
|
+
analysis.bindings.add(name)
|
|
365
|
+
const missing = [...usedComponents].filter(name => !analysis.bindings.has(name))
|
|
366
|
+
const conflicts = missing.filter(name => analysis.externalTypeBindings.has(name))
|
|
367
|
+
if (conflicts.length > 0) {
|
|
368
|
+
throw new Error(`[auto-import-hai-ui] ${filename}: Cannot auto-import component(s) ${conflicts.join(', ')} because a type-only import from another module uses the same local name. Alias the type-only import or explicitly import the component under a different local name.`)
|
|
369
|
+
}
|
|
370
|
+
return mergeHaiUiImport(scriptContent, missing, analysis)
|
|
182
371
|
}
|
|
183
372
|
|
|
184
373
|
function autoImportHaiUi() {
|
|
@@ -195,40 +384,27 @@ function autoImportHaiUi() {
|
|
|
195
384
|
return { code: content }
|
|
196
385
|
}
|
|
197
386
|
|
|
198
|
-
|
|
199
|
-
|
|
387
|
+
// 先由语言预处理器转换样式/模板,再按整份 Svelte AST 选择真实实例脚本。
|
|
388
|
+
// Svelte parse 会移除 BOM;局部坐标基于去除 BOM 的源码,输出仍保留它。
|
|
389
|
+
const prefix = content.startsWith('\uFEFF')
|
|
390
|
+
? '\uFEFF'
|
|
391
|
+
: ''
|
|
392
|
+
const source = content.slice(prefix.length)
|
|
393
|
+
const ast = parse(source, { modern: true })
|
|
394
|
+
const usedComponents = collectUsedComponents(ast)
|
|
395
|
+
if (usedComponents.size === 0)
|
|
200
396
|
return { code: content }
|
|
397
|
+
const instance = ast.instance
|
|
398
|
+
if (!instance) {
|
|
399
|
+
const scriptContent = updateScriptBlock('', usedComponents, filename, ast)
|
|
400
|
+
if (!scriptContent)
|
|
401
|
+
return { code: content }
|
|
402
|
+
return { code: `${prefix}<script lang="ts">${scriptContent}</script>\n${source}` }
|
|
201
403
|
}
|
|
202
404
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
for (const match of content.matchAll(SCRIPT_REGEX)) {
|
|
208
|
-
const [fullMatch, attrs, scriptContent] = match
|
|
209
|
-
const isModule = MODULE_CONTEXT_ATTR_REGEX.test(attrs)
|
|
210
|
-
const start = match.index ?? 0
|
|
211
|
-
|
|
212
|
-
updated += content.slice(lastIndex, start)
|
|
213
|
-
lastIndex = start + fullMatch.length
|
|
214
|
-
|
|
215
|
-
if (!applied && !isModule) {
|
|
216
|
-
const newScript = updateScriptBlock(scriptContent, usedComponents)
|
|
217
|
-
updated += `<script${attrs}>${newScript}</script>`
|
|
218
|
-
applied = true
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
updated += fullMatch
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (!applied) {
|
|
226
|
-
const scriptBlock = `<script lang="ts">${updateScriptBlock('', usedComponents)}</script>\n`
|
|
227
|
-
return { code: scriptBlock + content }
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
updated += content.slice(lastIndex)
|
|
231
|
-
return { code: updated }
|
|
405
|
+
const { start, end } = instance.content
|
|
406
|
+
const scriptContent = updateScriptBlock(source.slice(start, end), usedComponents, filename, ast)
|
|
407
|
+
return { code: prefix + source.slice(0, start) + scriptContent + source.slice(end) }
|
|
232
408
|
},
|
|
233
409
|
}
|
|
234
410
|
}
|
|
@@ -89,7 +89,9 @@
|
|
|
89
89
|
|
|
90
90
|
function toggleItem(itemId: string) {
|
|
91
91
|
if (multiple) {
|
|
92
|
-
const current = Array.isArray(value)
|
|
92
|
+
const current = Array.isArray(value)
|
|
93
|
+
? value
|
|
94
|
+
: []
|
|
93
95
|
const newValue = current.includes(itemId)
|
|
94
96
|
? current.filter(id => id !== itemId)
|
|
95
97
|
: [...current, itemId]
|
|
@@ -97,7 +99,9 @@
|
|
|
97
99
|
onchange?.(newValue)
|
|
98
100
|
}
|
|
99
101
|
else {
|
|
100
|
-
const newValue = value === itemId
|
|
102
|
+
const newValue = value === itemId
|
|
103
|
+
? undefined
|
|
104
|
+
: itemId
|
|
101
105
|
value = newValue as string
|
|
102
106
|
onchange?.(newValue as string)
|
|
103
107
|
}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
<script lang='ts'>
|
|
19
19
|
import type { DataAttributes } from '../../types.js'
|
|
20
20
|
import type { BottomNavItem } from './bottom-nav-types.js'
|
|
21
|
+
import { onMount } from 'svelte'
|
|
21
22
|
import { cn, getDataAttributes } from '../../utils.js'
|
|
22
23
|
|
|
23
24
|
// eslint-disable-next-line no-import-assign -- type re-export
|
|
@@ -89,6 +90,12 @@
|
|
|
89
90
|
|
|
90
91
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
91
92
|
const constrained = $derived(centered && maxWidth !== 'none')
|
|
93
|
+
|
|
94
|
+
// 服务端已渲染导航时,先等待客户端绑定事件,避免提前点击丢失。
|
|
95
|
+
let ready = $state(false)
|
|
96
|
+
onMount(() => {
|
|
97
|
+
ready = true
|
|
98
|
+
})
|
|
92
99
|
</script>
|
|
93
100
|
|
|
94
101
|
<nav {...dataAttributes}
|
|
@@ -104,10 +111,13 @@
|
|
|
104
111
|
{#each items as item (item.id)}
|
|
105
112
|
<button
|
|
106
113
|
type='button'
|
|
114
|
+
disabled={!ready}
|
|
107
115
|
class={cn(
|
|
108
116
|
'flex flex-col items-center justify-center flex-1 h-full relative transition-colors',
|
|
109
117
|
'hai-no-select',
|
|
110
|
-
item.id === active
|
|
118
|
+
item.id === active
|
|
119
|
+
? 'text-primary'
|
|
120
|
+
: 'text-base-content/60',
|
|
111
121
|
)}
|
|
112
122
|
onclick={() => onchange?.(item.id)}
|
|
113
123
|
>
|
|
@@ -120,7 +130,9 @@
|
|
|
120
130
|
{/if}
|
|
121
131
|
{#if item.badge && item.badge > 0}
|
|
122
132
|
<span class='absolute -top-1 -right-2 badge badge-error badge-xs text-[10px] min-w-4 h-4'>
|
|
123
|
-
{item.badge > 99
|
|
133
|
+
{item.badge > 99
|
|
134
|
+
? '99+'
|
|
135
|
+
: item.badge}
|
|
124
136
|
</span>
|
|
125
137
|
{/if}
|
|
126
138
|
</div>
|
|
@@ -53,7 +53,9 @@
|
|
|
53
53
|
cn(
|
|
54
54
|
'card bg-base-100 rounded-xl border border-base-content/6',
|
|
55
55
|
bordered && 'border-base-300',
|
|
56
|
-
typeof shadow === 'boolean'
|
|
56
|
+
typeof shadow === 'boolean'
|
|
57
|
+
? shadowMap[String(shadow) as 'true' | 'false']
|
|
58
|
+
: shadowMap[shadow],
|
|
57
59
|
className,
|
|
58
60
|
),
|
|
59
61
|
)
|
|
@@ -135,6 +135,10 @@
|
|
|
135
135
|
|
|
136
136
|
let searchValue = $state('')
|
|
137
137
|
let open = $state(false)
|
|
138
|
+
// 多选触发器宽度:标签会挤占内层 input,弹出层仍应与整个输入框等宽。
|
|
139
|
+
let triggerWidth = $state(0)
|
|
140
|
+
let fieldEl = $state<HTMLDivElement | null>(null)
|
|
141
|
+
let anchorOffset = $state(0)
|
|
138
142
|
let inputRef = $state<HTMLInputElement | null>(null)
|
|
139
143
|
|
|
140
144
|
/** 根据搜索关键词过滤选项 */
|
|
@@ -167,10 +171,14 @@
|
|
|
167
171
|
)
|
|
168
172
|
|
|
169
173
|
/** 多选模式:提供给 Combobox.Root 的类型安全值 */
|
|
170
|
-
const multiVal = $derived(Array.isArray(value)
|
|
174
|
+
const multiVal = $derived(Array.isArray(value)
|
|
175
|
+
? value as string[]
|
|
176
|
+
: [])
|
|
171
177
|
|
|
172
178
|
/** 单选模式:提供给 Combobox.Root 的类型安全值 */
|
|
173
|
-
const singleVal = $derived(typeof value === 'string'
|
|
179
|
+
const singleVal = $derived(typeof value === 'string'
|
|
180
|
+
? value
|
|
181
|
+
: '')
|
|
174
182
|
|
|
175
183
|
function syncInputElementValue() {
|
|
176
184
|
if (!inputRef)
|
|
@@ -185,6 +193,15 @@
|
|
|
185
193
|
syncInputElementValue()
|
|
186
194
|
})
|
|
187
195
|
|
|
196
|
+
// 多选时 input 从标签后开始,按其在字段内的左偏移把弹出层对齐到字段左边。
|
|
197
|
+
$effect(() => {
|
|
198
|
+
void multiVal.length
|
|
199
|
+
void triggerWidth
|
|
200
|
+
if (!open || !fieldEl || !inputRef)
|
|
201
|
+
return
|
|
202
|
+
anchorOffset = -Math.round(inputRef.getBoundingClientRect().left - fieldEl.getBoundingClientRect().left)
|
|
203
|
+
})
|
|
204
|
+
|
|
188
205
|
function handleInput(e: Event & { currentTarget: HTMLInputElement }) {
|
|
189
206
|
searchValue = e.currentTarget.value
|
|
190
207
|
if (!open)
|
|
@@ -244,6 +261,8 @@
|
|
|
244
261
|
>
|
|
245
262
|
<div class='relative'>
|
|
246
263
|
<div
|
|
264
|
+
bind:this={fieldEl}
|
|
265
|
+
bind:clientWidth={triggerWidth}
|
|
247
266
|
class={cn(
|
|
248
267
|
'rounded-lg border bg-base-100 flex flex-wrap gap-1.5 items-center py-1 pl-2.5 pr-9 transition-[border-color,box-shadow] duration-150',
|
|
249
268
|
sizeClasses.minHeight,
|
|
@@ -270,10 +289,17 @@
|
|
|
270
289
|
<Combobox.Input
|
|
271
290
|
id={field?.controlId}
|
|
272
291
|
aria-invalid={effectiveError ? true : undefined}
|
|
273
|
-
aria-describedby={[
|
|
292
|
+
aria-describedby={[
|
|
293
|
+
field?.messageId,
|
|
294
|
+
localError && !field?.error
|
|
295
|
+
? messageId
|
|
296
|
+
: '',
|
|
297
|
+
].filter(Boolean).join(' ') || undefined}
|
|
274
298
|
bind:ref={inputRef}
|
|
275
299
|
class={cn('flex-1 min-w-20 bg-transparent py-0.5 outline-none placeholder:text-base-content/40', sizeClasses.spacing)}
|
|
276
|
-
placeholder={selectedOptions.length === 0
|
|
300
|
+
placeholder={selectedOptions.length === 0
|
|
301
|
+
? placeholder
|
|
302
|
+
: ''}
|
|
277
303
|
{disabled}
|
|
278
304
|
oninput={handleInput}
|
|
279
305
|
onfocus={() => {
|
|
@@ -293,6 +319,11 @@
|
|
|
293
319
|
<Combobox.Portal>
|
|
294
320
|
<Combobox.Content
|
|
295
321
|
class={contentClass}
|
|
322
|
+
align='start'
|
|
323
|
+
alignOffset={anchorOffset}
|
|
324
|
+
style={triggerWidth > 0
|
|
325
|
+
? `--bits-combobox-anchor-width:${triggerWidth}px`
|
|
326
|
+
: undefined}
|
|
296
327
|
sideOffset={4}
|
|
297
328
|
>
|
|
298
329
|
{#if filteredOptions.length === 0}
|
|
@@ -342,7 +373,12 @@
|
|
|
342
373
|
<Combobox.Input
|
|
343
374
|
id={field?.controlId}
|
|
344
375
|
aria-invalid={effectiveError ? true : undefined}
|
|
345
|
-
aria-describedby={[
|
|
376
|
+
aria-describedby={[
|
|
377
|
+
field?.messageId,
|
|
378
|
+
localError && !field?.error
|
|
379
|
+
? messageId
|
|
380
|
+
: '',
|
|
381
|
+
].filter(Boolean).join(' ') || undefined}
|
|
346
382
|
bind:ref={inputRef}
|
|
347
383
|
class={cn(
|
|
348
384
|
'w-full rounded-lg border bg-base-100 pr-9 outline-none transition-[border-color,box-shadow] duration-150 placeholder:text-base-content/40',
|
|
@@ -115,9 +115,13 @@
|
|
|
115
115
|
let localSortDir = $state<'asc' | 'desc'>('asc')
|
|
116
116
|
|
|
117
117
|
/** 当前生效的排序字段。 */
|
|
118
|
-
const activeSortKey = $derived(controlled
|
|
118
|
+
const activeSortKey = $derived(controlled
|
|
119
|
+
? (sortKey ?? null)
|
|
120
|
+
: localSortKey)
|
|
119
121
|
/** 当前生效的排序方向。 */
|
|
120
|
-
const activeSortDir = $derived<'asc' | 'desc' | null>(controlled
|
|
122
|
+
const activeSortDir = $derived<'asc' | 'desc' | null>(controlled
|
|
123
|
+
? (sortDir ?? null)
|
|
124
|
+
: (localSortKey ? localSortDir : null))
|
|
121
125
|
|
|
122
126
|
/** 切换列排序,并在受控模式下通知父组件。 */
|
|
123
127
|
function toggleSort(col: Column) {
|
|
@@ -126,7 +130,9 @@
|
|
|
126
130
|
/** 统一为字符串的列 key,用于和受控排序字段比较。 */
|
|
127
131
|
const key = String(col.key)
|
|
128
132
|
/** 同一列再次点击时切换方向,否则从升序开始。 */
|
|
129
|
-
const nextDir: 'asc' | 'desc' = activeSortKey === key && activeSortDir === 'asc'
|
|
133
|
+
const nextDir: 'asc' | 'desc' = activeSortKey === key && activeSortDir === 'asc'
|
|
134
|
+
? 'desc'
|
|
135
|
+
: 'asc'
|
|
130
136
|
if (controlled) {
|
|
131
137
|
onsort?.(key, nextDir)
|
|
132
138
|
return
|
|
@@ -163,7 +169,9 @@
|
|
|
163
169
|
else {
|
|
164
170
|
cmp = String(av).localeCompare(String(bv), undefined, { numeric: true })
|
|
165
171
|
}
|
|
166
|
-
return dir === 'asc'
|
|
172
|
+
return dir === 'asc'
|
|
173
|
+
? cmp
|
|
174
|
+
: -cmp
|
|
167
175
|
})
|
|
168
176
|
return copy
|
|
169
177
|
})
|
|
@@ -239,9 +247,13 @@
|
|
|
239
247
|
/** 数据操作格的背景由 rowClass 统一下发,确保默认、斑马纹和 hover 状态一致且不透明。 */
|
|
240
248
|
const actionCellClass = $derived(actionColumnClass)
|
|
241
249
|
/** 操作按钮保持单行的固有宽度,既不强制填满单元格,也不会被其它列挤压。 */
|
|
242
|
-
const actionWrapClass = $derived(density === 'compact'
|
|
250
|
+
const actionWrapClass = $derived(density === 'compact'
|
|
251
|
+
? 'inline-flex flex-nowrap items-center justify-center gap-0.5'
|
|
252
|
+
: 'inline-flex flex-nowrap items-center justify-center gap-1')
|
|
243
253
|
/** 加载和空数据占位单元格样式。 */
|
|
244
|
-
const placeholderCellClass = $derived(density === 'compact'
|
|
254
|
+
const placeholderCellClass = $derived(density === 'compact'
|
|
255
|
+
? 'text-center py-6 text-base-content/40'
|
|
256
|
+
: 'text-center py-8 text-base-content/40')
|
|
245
257
|
/** 未声明宽度的文本列最多占用的空间,保留其他列与操作列的可见区域。 */
|
|
246
258
|
const defaultContentMaxWidth = 'min(24rem, 40vw)'
|
|
247
259
|
|
|
@@ -290,7 +302,9 @@
|
|
|
290
302
|
* 仅给 th 设置 width 会被 table-auto 的内容尺寸重新撑开,必须同时限制 td 内的内容盒子。
|
|
291
303
|
*/
|
|
292
304
|
function getContentStyle(col: Column): string {
|
|
293
|
-
const maxWidth = col.width
|
|
305
|
+
const maxWidth = col.width
|
|
306
|
+
? `min(${col.width}, 20vw)`
|
|
307
|
+
: defaultContentMaxWidth
|
|
294
308
|
return `max-width: ${maxWidth};`
|
|
295
309
|
}
|
|
296
310
|
</script>
|
|
@@ -303,7 +317,13 @@
|
|
|
303
317
|
{@const isSorted = activeSortKey === String(col.key)}
|
|
304
318
|
<th
|
|
305
319
|
scope='col'
|
|
306
|
-
aria-sort={col.sortable
|
|
320
|
+
aria-sort={col.sortable
|
|
321
|
+
? (isSorted
|
|
322
|
+
? (activeSortDir === 'asc'
|
|
323
|
+
? 'ascending'
|
|
324
|
+
: 'descending')
|
|
325
|
+
: 'none')
|
|
326
|
+
: undefined}
|
|
307
327
|
style={getColumnStyle(col)}
|
|
308
328
|
class='{getAlignClass(col.align)} {headerCellDividerClass} relative font-medium'
|
|
309
329
|
>
|
|
@@ -103,7 +103,12 @@
|
|
|
103
103
|
>
|
|
104
104
|
<BitsDatePicker.Input
|
|
105
105
|
aria-labelledby={field?.labelId}
|
|
106
|
-
aria-describedby={[
|
|
106
|
+
aria-describedby={[
|
|
107
|
+
field?.messageId,
|
|
108
|
+
localError && !field?.error
|
|
109
|
+
? messageId
|
|
110
|
+
: '',
|
|
111
|
+
].filter(Boolean).join(' ') || undefined}
|
|
107
112
|
class={cn(
|
|
108
113
|
'flex w-full items-center gap-0.5 rounded-lg border bg-base-100 pr-2 transition-[border-color,box-shadow] duration-150',
|
|
109
114
|
sizeClasses.control,
|
|
@@ -195,8 +195,12 @@
|
|
|
195
195
|
return
|
|
196
196
|
|
|
197
197
|
event.preventDefault()
|
|
198
|
-
const edgeDelta = event.key === 'ArrowLeft'
|
|
199
|
-
|
|
198
|
+
const edgeDelta = event.key === 'ArrowLeft'
|
|
199
|
+
? -16
|
|
200
|
+
: 16
|
|
201
|
+
const nextWidth = clampWidth(drawer.getBoundingClientRect().width + (position === 'right'
|
|
202
|
+
? -edgeDelta
|
|
203
|
+
: edgeDelta))
|
|
200
204
|
resizeWidthForStorage = nextWidth
|
|
201
205
|
resizedWidth = nextWidth
|
|
202
206
|
if (widthStorageKey) {
|
|
@@ -234,13 +238,17 @@
|
|
|
234
238
|
onclick={handleBackdropClick}
|
|
235
239
|
></button>
|
|
236
240
|
|
|
237
|
-
<div bind:this={panel} class={contentClass} style={widthStyle} role='dialog' aria-modal={open ? 'true' : undefined} aria-labelledby={title ? titleId : undefined} aria-label={title
|
|
241
|
+
<div bind:this={panel} class={contentClass} style={widthStyle} role='dialog' aria-modal={open ? 'true' : undefined} aria-labelledby={title ? titleId : undefined} aria-label={title
|
|
242
|
+
? undefined
|
|
243
|
+
: uiM('common_dialog')} tabindex='-1'>
|
|
238
244
|
{#if canResize}
|
|
239
245
|
<button
|
|
240
246
|
type='button'
|
|
241
247
|
aria-label={uiM('drawer_resize')}
|
|
242
248
|
data-drawer-resize-handle
|
|
243
|
-
class='absolute inset-y-0 z-20 hidden w-2 cursor-col-resize touch-none border-0 bg-transparent p-0 md:block {position === 'right'
|
|
249
|
+
class='absolute inset-y-0 z-20 hidden w-2 cursor-col-resize touch-none border-0 bg-transparent p-0 md:block {position === 'right'
|
|
250
|
+
? 'left-0'
|
|
251
|
+
: 'right-0'}'
|
|
244
252
|
onmousedown={startResize}
|
|
245
253
|
onkeydown={handleResizeKeydown}
|
|
246
254
|
></button>
|