@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.
- package/README.en.md +30 -27
- package/README.ja.md +30 -27
- package/README.md +30 -27
- package/auto-import.js +118 -53
- package/dist/components/compounds/Accordion.svelte +6 -2
- package/dist/components/compounds/BottomNav.svelte +6 -2
- package/dist/components/compounds/Card.svelte +3 -1
- package/dist/components/compounds/Combobox.svelte +24 -6
- 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 +9 -2
- 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 +28 -3
- package/dist/components/compounds/Steps.svelte +6 -2
- package/dist/components/compounds/SwipeCell.svelte +3 -1
- package/dist/components/compounds/TableToolbar.svelte +32 -9
- package/dist/components/compounds/Tabs.svelte +15 -5
- package/dist/components/compounds/Timeline.svelte +6 -2
- package/dist/components/compounds/ToastContainer.svelte +27 -7
- 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/IconButton.svelte +3 -1
- package/dist/components/primitives/Input.svelte +18 -2
- package/dist/components/primitives/Radio.svelte +3 -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/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 +3 -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 +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 +22 -4
- package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
- package/dist/components/scenes/app/feedback-functions.js +6 -2
- package/dist/components/scenes/charts/Chart.svelte +16 -5
- package/dist/components/scenes/charts/MetricCard.svelte +21 -4
- package/dist/components/scenes/charts/chart-presets.js +42 -5
- package/dist/components/scenes/charts/renderers/LineChart.svelte +38 -12
- 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 +73 -15
- 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 +49 -11
- 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.js +11 -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/theme-config.js +135 -21
- package/dist/toast.svelte.js +14 -3
- package/dist/utils.js +6 -2
- package/package.json +19 -19
package/README.en.md
CHANGED
|
@@ -10,6 +10,8 @@ Built-in messages support `zh-CN`, `en-US` and `ja-JP`; the language selector of
|
|
|
10
10
|
|
|
11
11
|
A cross-platform Svelte 5 Runes component library with DaisyUI v5 + Tailwind CSS v4 styling and Bits UI v2 headless interactions. Includes built-in i18n (zh-CN / en-US / ja-JP) and 15 curated DaisyUI themes plus high contrast, square business and eye-care themes.
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
HTTP/UI boundaries expose business messages only for explicit valid 4xx statuses. Missing or invalid `httpStatus` is treated as 500 with a safe message. Custom business errors must carry a complete error definition or an explicit status.
|
|
13
15
|
## Core features
|
|
14
16
|
|
|
15
17
|
- Forms, tables, dialogs, navigation, charts and application components.
|
|
@@ -30,49 +32,46 @@ For a Node server, declare both UI and core as production dependencies so the ad
|
|
|
30
32
|
|
|
31
33
|
### Quick start
|
|
32
34
|
|
|
33
|
-
#### 1. Configure
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
import { autoImportHaiUi } from '@h-ai/ui/auto-import'
|
|
37
|
-
import adapter from '@sveltejs/adapter-node'
|
|
38
|
-
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
39
|
-
|
|
40
|
-
/** @type {import('@sveltejs/kit').Config} */
|
|
41
|
-
const config = {
|
|
42
|
-
preprocess: [autoImportHaiUi(), vitePreprocess()],
|
|
43
|
-
compilerOptions: { runes: true },
|
|
44
|
-
kit: { adapter: adapter() },
|
|
45
|
-
}
|
|
35
|
+
#### 1. Configure application imports in package.json
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
```json
|
|
38
|
+
{ "imports": { "#lib/*": "./src/lib/*" } }
|
|
48
39
|
```
|
|
49
40
|
|
|
50
41
|
#### 2. Configure vite.config.ts
|
|
51
42
|
|
|
43
|
+
SvelteKit 3 configures preprocessing, the compiler and the adapter in the Vite plugin; only a plain Svelte/Vite project keeps svelte.config.js.
|
|
44
|
+
|
|
45
|
+
Run `vitePreprocess()` or other style/template language transforms before `autoImportHaiUi()`. Auto-import reads the complete Svelte AST and does not accept unprocessed SCSS, Pug or other nonstandard syntax. Its direct markup API remains synchronous.
|
|
46
|
+
|
|
52
47
|
```ts
|
|
48
|
+
import { autoImportHaiUi } from '@h-ai/ui/auto-import'
|
|
53
49
|
import { haiOptimizeExclude, haiPrebundledDeps } from '@h-ai/ui/vite'
|
|
50
|
+
import adapter from '@sveltejs/adapter-node'
|
|
54
51
|
import { sveltekit } from '@sveltejs/kit/vite'
|
|
52
|
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
55
53
|
import tailwindcss from '@tailwindcss/vite'
|
|
56
54
|
import { defineConfig } from 'vite'
|
|
57
55
|
|
|
58
56
|
export default defineConfig({
|
|
59
|
-
plugins: [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
plugins: [
|
|
58
|
+
sveltekit({
|
|
59
|
+
preprocess: [vitePreprocess(), autoImportHaiUi()],
|
|
60
|
+
compilerOptions: { runes: true },
|
|
61
|
+
adapter: adapter(),
|
|
62
|
+
paths: { relative: false },
|
|
63
|
+
}),
|
|
64
|
+
tailwindcss(),
|
|
65
|
+
],
|
|
66
|
+
optimizeDeps: { exclude: [...haiOptimizeExclude], include: [...haiPrebundledDeps] },
|
|
68
67
|
ssr: { noExternal: ['@h-ai/ui', '@h-ai/kit'], external: ['@h-ai/core', 'sm-crypto'] },
|
|
69
68
|
})
|
|
70
69
|
```
|
|
71
70
|
|
|
72
|
-
When using Crypto or Kit/IAM, include `sm-crypto@0.5.7` in application production dependencies. CLI projects already do this; for manual setup, run `pnpm add sm-crypto@0.5.7`. The external option alone is insufficient: adapter-node also uses direct production dependencies to preserve native package loading.
|
|
73
|
-
|
|
74
71
|
#### 3. Configure src/app.css
|
|
75
72
|
|
|
73
|
+
When using Crypto or Kit/IAM, include `sm-crypto@0.5.8` in application production dependencies. CLI projects already do this; for manual setup, run `pnpm add sm-crypto@0.5.8`. The external option alone is insufficient: adapter-node also uses direct production dependencies to preserve native package loading.
|
|
74
|
+
|
|
76
75
|
```css
|
|
77
76
|
@import 'tailwindcss';
|
|
78
77
|
@import '@h-ai/ui/styles/global.css';
|
|
@@ -116,7 +115,7 @@ With auto-import enabled, use components directly in templates without individua
|
|
|
116
115
|
|
|
117
116
|
Pages using a subset of components, such as administration screens, can import public component-directory entry points directly. Import theme utilities from the lightweight `@h-ai/ui/theme` entry so theme consumers do not load the root entry's AI and chart components. Use `@h-ai/ui/i18n` for locale utilities in stores without loading components or tour CSS. Check the installed package's exports; do not import its internal `src/` or `dist/` paths.
|
|
118
117
|
|
|
119
|
-
The preprocessor
|
|
118
|
+
The preprocessor uses the syntax tree to recognize real semicolon-free, multiline and aliased imports, preserving examples in strings and comments and existing runtime bindings. Type-only component bindings from the root `@h-ai/ui` entry are promoted to values when needed. A conflicting type-only import from another module causes a build error naming the file and component; alias the type, or explicitly import the component under another local name.
|
|
120
119
|
|
|
121
120
|
```ts
|
|
122
121
|
import { Card } from '@h-ai/ui/components/compounds/index'
|
|
@@ -211,6 +210,8 @@ Text controls validate on blur after input and update errors as input is correct
|
|
|
211
210
|
|
|
212
211
|
`UserProfile.fieldConstraints` accepts per-field `required`, `minlength`, `maxlength`, `pattern` and `validationMessage` (`pattern` applies to single-line inputs), so application rules such as username formats share blur validation. `validationMessage` also accepts a deferred translation function.
|
|
213
212
|
|
|
213
|
+
`UserProfile.onsubmit` must return `true` to confirm a successful save, or `false` to keep the editor and draft. Thrown errors also keep editing open and use the shared Toast feedback. Cancel restores the saved values from `user`.
|
|
214
|
+
|
|
214
215
|
`CrudEditPanel.onsubmit` receives only writable fields declared by the form. Fields marked `readonly` are omitted when editing and remain available when creating. Primary keys, related display values and audit timestamps are not copied from the entire row. Null values, `false` and `0` are preserved. Keep strict schema validation on the server.
|
|
215
216
|
|
|
216
217
|
`LoginForm`, `RegisterForm`, `ChangePasswordForm`, `ForgotPasswordForm`, `ResetPasswordForm`, `AuthPanel`, `UserProfile` and `FeedbackModal` accept the same layout options. Pass them through `CrudPage.form` or directly to `CrudEditPanel`. CRUD fields support `colSpan` and deferred `validation.message`. Buttons and Enter both validate before submission; corrections clear errors. Server validation remains required.
|
|
@@ -246,6 +247,8 @@ Text controls validate on blur after input and update errors as input is correct
|
|
|
246
247
|
|
|
247
248
|
`Popover` renders in `body` by default. In `click` mode, Enter or Space opens the panel and moves focus into it. Escape closes the panel and returns focus to the trigger. Use `portal={false}` to render inline.
|
|
248
249
|
|
|
250
|
+
Inside a Modal or Drawer, portal controls participate in the owning dialog's Tab and Shift+Tab order. Closing the Popover removes that registration and restores focus to its trigger.
|
|
251
|
+
|
|
249
252
|
##### Data display
|
|
250
253
|
|
|
251
254
|
| Component | Description | Key props |
|
|
@@ -811,7 +814,7 @@ Client locale state management, automatically synchronized with the `@h-ai/core`
|
|
|
811
814
|
```svelte
|
|
812
815
|
<script>
|
|
813
816
|
import { createLocaleStore, setGlobalLocale } from '@h-ai/ui/i18n'
|
|
814
|
-
import { setLocale } from '
|
|
817
|
+
import { setLocale } from '#lib/paraglide/runtime.js'
|
|
815
818
|
|
|
816
819
|
const localeStore = createLocaleStore()
|
|
817
820
|
|
package/README.ja.md
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
Svelte 5 Runes のクロスプラットフォーム UI ライブラリーです。DaisyUI v5 + Tailwind CSS v4 のスタイル、Bits UI v2 のヘッドレス UI、内蔵 i18n(zh-CN / en-US / ja-JP)、15 種類の厳選テーマ、ハイコントラスト、直角ビジネス、目にやさしいテーマを提供します。
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
HTTP/UI 境界で業務メッセージを公開するのは、明示された有効な4xx状態のみです。`httpStatus` が未指定または不正な場合は500として安全なメッセージを返します。独自の業務エラーには完全なエラー定義または明示的な状態を指定してください。
|
|
13
15
|
## 主な機能
|
|
14
16
|
|
|
15
17
|
- フォーム、テーブル、ダイアログ、ナビゲーション、チャートなどの部品。
|
|
@@ -30,49 +32,46 @@ Node サーバーでは UI と core の両方を本番依存に含め、ログ
|
|
|
30
32
|
|
|
31
33
|
### クイックスタート
|
|
32
34
|
|
|
33
|
-
#### 1.
|
|
35
|
+
#### 1. package.json のアプリ内インポートを設定
|
|
34
36
|
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
37
|
+
```json
|
|
38
|
+
{ "imports": { "#lib/*": "./src/lib/*" } }
|
|
39
|
+
```
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
const config = {
|
|
42
|
-
preprocess: [autoImportHaiUi(), vitePreprocess()],
|
|
43
|
-
compilerOptions: { runes: true },
|
|
44
|
-
kit: { adapter: adapter() },
|
|
45
|
-
}
|
|
41
|
+
#### 2. vite.config.ts を設定
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
```
|
|
43
|
+
SvelteKit 3 の前処理、コンパイラー、アダプターは Vite プラグインで設定します。通常の Svelte/Vite プロジェクトのみ svelte.config.js を保持します。
|
|
49
44
|
|
|
50
|
-
|
|
45
|
+
`vitePreprocess()` などのスタイル・テンプレート言語変換を先に、`autoImportHaiUi()` を後に実行してください。自動 import は Svelte 全体の AST を読み取るため、変換前の SCSS・Pug などの非標準構文は受け付けません。直接の markup API は同期のままです。
|
|
51
46
|
|
|
52
47
|
```ts
|
|
48
|
+
import { autoImportHaiUi } from '@h-ai/ui/auto-import'
|
|
53
49
|
import { haiOptimizeExclude, haiPrebundledDeps } from '@h-ai/ui/vite'
|
|
50
|
+
import adapter from '@sveltejs/adapter-node'
|
|
54
51
|
import { sveltekit } from '@sveltejs/kit/vite'
|
|
52
|
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
55
53
|
import tailwindcss from '@tailwindcss/vite'
|
|
56
54
|
import { defineConfig } from 'vite'
|
|
57
55
|
|
|
58
56
|
export default defineConfig({
|
|
59
|
-
plugins: [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
plugins: [
|
|
58
|
+
sveltekit({
|
|
59
|
+
preprocess: [vitePreprocess(), autoImportHaiUi()],
|
|
60
|
+
compilerOptions: { runes: true },
|
|
61
|
+
adapter: adapter(),
|
|
62
|
+
paths: { relative: false },
|
|
63
|
+
}),
|
|
64
|
+
tailwindcss(),
|
|
65
|
+
],
|
|
66
|
+
optimizeDeps: { exclude: [...haiOptimizeExclude], include: [...haiPrebundledDeps] },
|
|
68
67
|
ssr: { noExternal: ['@h-ai/ui', '@h-ai/kit'], external: ['@h-ai/core', 'sm-crypto'] },
|
|
69
68
|
})
|
|
70
69
|
```
|
|
71
70
|
|
|
72
|
-
Crypto または Kit/IAM を使う場合、アプリの本番依存に `sm-crypto@0.5.7` を含めます。CLI 生成済みのプロジェクトでは設定済みです。手動導入は `pnpm add sm-crypto@0.5.7` を実行してください。adapter-node は直接の本番依存も参照するため、external 指定だけでは不十分です。
|
|
73
|
-
|
|
74
71
|
#### 3. src/app.css の設定
|
|
75
72
|
|
|
73
|
+
Crypto または Kit/IAM を使うアプリでは `sm-crypto@0.5.8` を本番依存に追加します。CLI は設定済みです。手動導入では `pnpm add sm-crypto@0.5.8` を実行してください。external だけでは不十分で、adapter-node がネイティブ解決を維持するには直接の本番依存が必要です。
|
|
74
|
+
|
|
76
75
|
```css
|
|
77
76
|
@import 'tailwindcss';
|
|
78
77
|
@import '@h-ai/ui/styles/global.css';
|
|
@@ -116,7 +115,7 @@ Crypto または Kit/IAM を使う場合、アプリの本番依存に `sm-crypt
|
|
|
116
115
|
|
|
117
116
|
管理画面など一部のコンポーネントを使うページは、公開コンポーネントディレクトリーの入口から直接 import できます。テーマツールは軽量な `@h-ai/ui/theme` から読み込み、テーマの利用だけでルート入口の AI・グラフコンポーネントを読み込まないようにします。ストアの言語ツールは `@h-ai/ui/i18n` から読み込み、コンポーネントやガイド CSS を読み込みません。インストール済みパッケージの exports を確認し、内部 `src/`・`dist/` は import しないでください。
|
|
118
117
|
|
|
119
|
-
自動 import
|
|
118
|
+
自動 import は構文木からセミコロンなし、複数行、別名の実際の import を認識し、文字列やコメント内の例と既存の実行時バインドを保持します。ルート入口 `@h-ai/ui` の型のみのコンポーネントは必要時に値へ昇格します。他モジュールの同名の型を安全に統合できない場合、ファイル名とコンポーネント名を含むビルドエラーになります。型に別名を付けるか、コンポーネントを別のローカル名で明示的に import してください。
|
|
120
119
|
|
|
121
120
|
```ts
|
|
122
121
|
import { Card } from '@h-ai/ui/components/compounds/index'
|
|
@@ -211,6 +210,8 @@ components/
|
|
|
211
210
|
|
|
212
211
|
`UserProfile.fieldConstraints` は項目別に `required`、`minlength`、`maxlength`、`pattern`、`validationMessage` を受け取り、ユーザー名などの業務ルールをフォーカス離脱時に検証します。`pattern` は単一行の入力に適用し、`validationMessage` は翻訳関数にも対応します。
|
|
213
212
|
|
|
213
|
+
`UserProfile.onsubmit` は保存成功時に `true`、編集と下書きを保持する場合は `false` を必ず返します。例外時も編集を閉じず、共通の Toast で通知します。キャンセルすると `user` の保存済み値に戻ります。
|
|
214
|
+
|
|
214
215
|
`CrudEditPanel.onsubmit` はフォームに宣言された書き込み可能な項目だけを受け取ります。`readonly` の項目は編集時に除外し、新規作成時には入力できます。主キー、関連データの表示値、監査日時を行全体から自動送信しません。空値、`false`、`0` は保持します。サーバーでは引き続き厳密なスキーマ検証を行ってください。
|
|
215
216
|
|
|
216
217
|
`LoginForm`、`RegisterForm`、`ChangePasswordForm`、`ForgotPasswordForm`、`ResetPasswordForm`、`AuthPanel`、`UserProfile`、`FeedbackModal` は同じレイアウト設定に対応します。`CrudPage.form` または `CrudEditPanel` に渡します。CRUD 項目は `colSpan` と翻訳関数の `validation.message` に対応し、ボタンと Enter のどちらも送信前に検証します。入力修正でエラーが消えます。サーバー側の検証も必要です。
|
|
@@ -246,6 +247,8 @@ components/
|
|
|
246
247
|
|
|
247
248
|
`Popover` は既定で `body` に描画されます。`click` モードでは Enter または Space で開くとパネルにフォーカスが移り、Escape で閉じるとトリガーに戻ります。インラインで描画する場合は `portal={false}` を指定します。
|
|
248
249
|
|
|
250
|
+
Modal または Drawer 内では、portal の操作要素も所属ダイアログの Tab/Shift+Tab 順序に含まれます。閉じると登録を解除してトリガーにフォーカスを戻します。
|
|
251
|
+
|
|
249
252
|
##### データ表示
|
|
250
253
|
|
|
251
254
|
| コンポーネント | 説明 | 主なプロパティ |
|
|
@@ -811,7 +814,7 @@ transformPageChunk: ({ html }) => html.replace('%theme_bootstrap%', themeBootstr
|
|
|
811
814
|
```svelte
|
|
812
815
|
<script>
|
|
813
816
|
import { createLocaleStore, setGlobalLocale } from '@h-ai/ui/i18n'
|
|
814
|
-
import { setLocale } from '
|
|
817
|
+
import { setLocale } from '#lib/paraglide/runtime.js'
|
|
815
818
|
|
|
816
819
|
const localeStore = createLocaleStore()
|
|
817
820
|
|
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
基于 Svelte 5 Runes 的多端 UI 组件库,采用 DaisyUI v5 + Tailwind CSS v4 样式 + Bits UI v2 headless 交互,内置 i18n(zh-CN / en-US / ja-JP),内置 15 个精选 DaisyUI 主题、高对比、直角商务及护眼主题。
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
HTTP/UI 边界只对明确的有效 4xx 状态公开业务提示;错误缺少 `httpStatus` 或状态非法时按 500 返回安全提示。手写业务错误须提供完整错误定义或显式状态,不能依赖缺省状态展示原文。
|
|
13
15
|
## 核心功能清单
|
|
14
16
|
|
|
15
17
|
- 表单、表格、弹窗、导航、图表与业务场景组件。
|
|
@@ -30,49 +32,46 @@ Node 服务端工程将 UI 与 core 都列为生产依赖,确保适配器保
|
|
|
30
32
|
|
|
31
33
|
### 快速开始
|
|
32
34
|
|
|
33
|
-
#### 1. 配置
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
import { autoImportHaiUi } from '@h-ai/ui/auto-import'
|
|
37
|
-
import adapter from '@sveltejs/adapter-node'
|
|
38
|
-
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
39
|
-
|
|
40
|
-
/** @type {import('@sveltejs/kit').Config} */
|
|
41
|
-
const config = {
|
|
42
|
-
preprocess: [autoImportHaiUi(), vitePreprocess()],
|
|
43
|
-
compilerOptions: { runes: true },
|
|
44
|
-
kit: { adapter: adapter() },
|
|
45
|
-
}
|
|
35
|
+
#### 1. 配置 package.json 的应用导入
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
```json
|
|
38
|
+
{ "imports": { "#lib/*": "./src/lib/*" } }
|
|
48
39
|
```
|
|
49
40
|
|
|
50
41
|
#### 2. 配置 vite.config.ts
|
|
51
42
|
|
|
43
|
+
SvelteKit 3 的预处理、编译器与适配器都在 Vite 插件中配置;纯 Svelte/Vite 工程才保留 svelte.config.js。
|
|
44
|
+
|
|
45
|
+
预处理顺序为 `vitePreprocess()` 或其他样式/模板语言转换在前、`autoImportHaiUi()` 在后。自动导入读取整份 Svelte AST,不直接接受尚未转换的 SCSS、Pug 等非标准语法;保留同步调用方式。
|
|
46
|
+
|
|
52
47
|
```ts
|
|
48
|
+
import { autoImportHaiUi } from '@h-ai/ui/auto-import'
|
|
53
49
|
import { haiOptimizeExclude, haiPrebundledDeps } from '@h-ai/ui/vite'
|
|
50
|
+
import adapter from '@sveltejs/adapter-node'
|
|
54
51
|
import { sveltekit } from '@sveltejs/kit/vite'
|
|
52
|
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
55
53
|
import tailwindcss from '@tailwindcss/vite'
|
|
56
54
|
import { defineConfig } from 'vite'
|
|
57
55
|
|
|
58
56
|
export default defineConfig({
|
|
59
|
-
plugins: [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
plugins: [
|
|
58
|
+
sveltekit({
|
|
59
|
+
preprocess: [vitePreprocess(), autoImportHaiUi()],
|
|
60
|
+
compilerOptions: { runes: true },
|
|
61
|
+
adapter: adapter(),
|
|
62
|
+
paths: { relative: false },
|
|
63
|
+
}),
|
|
64
|
+
tailwindcss(),
|
|
65
|
+
],
|
|
66
|
+
optimizeDeps: { exclude: [...haiOptimizeExclude], include: [...haiPrebundledDeps] },
|
|
68
67
|
ssr: { noExternal: ['@h-ai/ui', '@h-ai/kit'], external: ['@h-ai/core', 'sm-crypto'] },
|
|
69
68
|
})
|
|
70
69
|
```
|
|
71
70
|
|
|
72
|
-
使用 Crypto 或依赖它的 Kit/IAM 时,应用生产依赖需包含 `sm-crypto@0.5.7`。CLI 已配好这一项;手工接入时运行 `pnpm add sm-crypto@0.5.7`。仅设置 external 不够,adapter-node 还需要这项直接依赖声明才能保留原包加载。
|
|
73
|
-
|
|
74
71
|
#### 3. 配置 src/app.css
|
|
75
72
|
|
|
73
|
+
使用 Crypto 或依赖它的 Kit/IAM 时,应用生产依赖需包含 `sm-crypto@0.5.8`。CLI 已配好这一项;手工接入时运行 `pnpm add sm-crypto@0.5.8`。仅设置 external 不够,adapter-node 还需要直接生产依赖声明才能保留原包加载。
|
|
74
|
+
|
|
76
75
|
```css
|
|
77
76
|
@import 'tailwindcss';
|
|
78
77
|
@import '@h-ai/ui/styles/global.css';
|
|
@@ -116,7 +115,7 @@ export default defineConfig({
|
|
|
116
115
|
|
|
117
116
|
管理后台等只使用部分组件的页面,可直接使用公开组件目录入口;主题工具通过轻量 `@h-ai/ui/theme` 导入,避免主题消费加载根入口中的 AI、图表等组件。状态层的语言工具使用 `@h-ai/ui/i18n`,不加载组件与引导 CSS。组件路径以已安装版本的 exports 为准,不导入包内 `src/` 或 `dist/`。
|
|
118
117
|
|
|
119
|
-
|
|
118
|
+
自动导入器按语法树识别无分号、跨行及带别名的真实导入,不改写字符串或注释中的示例;已绑定的运行时组件名称不会重复注入。根入口 `@h-ai/ui` 的仅类型组件绑定按需提升为值;外部模块的同名类型无法安全合并时,构建错误会列出文件和组件名,请为类型设置别名,或用其他本地名显式导入组件。
|
|
120
119
|
|
|
121
120
|
```ts
|
|
122
121
|
import { Card } from '@h-ai/ui/components/compounds/index'
|
|
@@ -211,6 +210,8 @@ components/
|
|
|
211
210
|
|
|
212
211
|
`UserProfile.fieldConstraints` 按字段接收 `required`、`minlength`、`maxlength`、`pattern` 和 `validationMessage`(`pattern` 用于单行输入),让应用的用户名等业务规则复用失焦校验;`validationMessage` 支持延迟翻译函数。
|
|
213
212
|
|
|
213
|
+
`UserProfile.onsubmit` 必须返回 `true` 确认保存成功,返回 `false` 时保留编辑器和草稿;抛错也保留草稿并通过统一 Toast 提示。取消编辑恢复 `user` 中已保存的值。
|
|
214
|
+
|
|
214
215
|
`CrudEditPanel.onsubmit` 只接收表单声明的可写字段,编辑时排除 `readonly` 字段;新建时仍可填写该字段。主键、关联展示值和审计时间不从整行记录自动回传,空值、`false` 和 `0` 保持原值。服务端继续使用严格 schema 校验。
|
|
215
216
|
|
|
216
217
|
`LoginForm`、`RegisterForm`、`ChangePasswordForm`、`ForgotPasswordForm`、`ResetPasswordForm`、`AuthPanel`、`UserProfile` 和 `FeedbackModal` 接受同一组布局参数。`CrudPage` 通过 `form` 传入;`CrudEditPanel` 直接接收。CRUD 字段支持 `colSpan`,`validation.message` 支持翻译函数;按钮与回车均先校验,修正后错误消失,客户端校验不能替代服务端校验。
|
|
@@ -246,6 +247,8 @@ components/
|
|
|
246
247
|
|
|
247
248
|
`Popover` 默认挂载到 `body`。在 `click` 模式下按 Enter 或空格打开后,焦点进入面板,按 Escape 关闭并返回触发控件。需要内联挂载时使用 `portal={false}`。
|
|
248
249
|
|
|
250
|
+
在 Modal/Drawer 内,Popover 的 portal 内容参与所属弹窗的 Tab 与 Shift+Tab 顺序,保持在模态边界内;关闭后撤销登记并恢复触发位置。
|
|
251
|
+
|
|
249
252
|
##### 数据展示
|
|
250
253
|
|
|
251
254
|
| 组件 | 描述 | 主要属性 |
|
|
@@ -810,7 +813,7 @@ transformPageChunk: ({ html }) => html.replace('%theme_bootstrap%', themeBootstr
|
|
|
810
813
|
```svelte
|
|
811
814
|
<script>
|
|
812
815
|
import { createLocaleStore, setGlobalLocale } from '@h-ai/ui/i18n'
|
|
813
|
-
import { setLocale } from '
|
|
816
|
+
import { setLocale } from '#lib/paraglide/runtime.js'
|
|
814
817
|
|
|
815
818
|
const localeStore = createLocaleStore()
|
|
816
819
|
|
package/auto-import.js
CHANGED
|
@@ -130,10 +130,7 @@ const UI_COMPONENTS = new Set([
|
|
|
130
130
|
])
|
|
131
131
|
|
|
132
132
|
const TAG_REGEX = /<([A-Z][A-Za-z0-9]*)\b/g
|
|
133
|
-
const SCRIPT_REGEX = /<script\b([^>]*)>([\s\S]*?)<\/script>/g
|
|
134
|
-
const UI_IMPORT_REGEX = /import\s*\{([^}]+)\}\s*from\s*['"]@h-ai\/ui['"];?/
|
|
135
133
|
const WINDOWS_PATH_SEPARATOR_REGEX = /\\/g
|
|
136
|
-
const MODULE_CONTEXT_ATTR_REGEX = /context\s*=\s*['"]module['"]/i
|
|
137
134
|
|
|
138
135
|
function collectUsedComponents(content) {
|
|
139
136
|
const used = new Set()
|
|
@@ -146,44 +143,123 @@ function collectUsedComponents(content) {
|
|
|
146
143
|
return used
|
|
147
144
|
}
|
|
148
145
|
|
|
149
|
-
|
|
146
|
+
/** 一次解析同时提供运行时绑定与真实 import 范围,不再扫描字符串/注释中的伪 import。 */
|
|
147
|
+
function analyzeScript(script) {
|
|
150
148
|
const imported = new Set()
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
for (const statement of
|
|
154
|
-
if (statement.type !== 'ImportDeclaration'
|
|
149
|
+
const externalTypeBindings = new Set()
|
|
150
|
+
const declarations = []
|
|
151
|
+
for (const statement of script?.content.body ?? []) {
|
|
152
|
+
if (statement.type !== 'ImportDeclaration')
|
|
155
153
|
continue
|
|
156
154
|
for (const specifier of statement.specifiers) {
|
|
157
|
-
if (specifier.importKind !== 'type')
|
|
155
|
+
if (statement.importKind !== 'type' && specifier.importKind !== 'type')
|
|
158
156
|
imported.add(specifier.local.name)
|
|
157
|
+
else if (statement.source.value !== '@h-ai/ui')
|
|
158
|
+
externalTypeBindings.add(specifier.local.name)
|
|
159
159
|
}
|
|
160
|
+
if (statement.source.value === '@h-ai/ui')
|
|
161
|
+
declarations.push(statement)
|
|
160
162
|
}
|
|
161
|
-
return
|
|
163
|
+
return {
|
|
164
|
+
imported,
|
|
165
|
+
externalTypeBindings,
|
|
166
|
+
declarations,
|
|
167
|
+
offset: script?.content.start ?? 0,
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** 整条 type import 提升为混合导入时,跳过词法空白和注释,只移除解析器确认的 type 关键字。 */
|
|
172
|
+
function typeKeywordStart(scriptContent, declarationStart) {
|
|
173
|
+
let cursor = declarationStart + 'import'.length
|
|
174
|
+
while (cursor < scriptContent.length) {
|
|
175
|
+
if (/\s/.test(scriptContent[cursor])) {
|
|
176
|
+
cursor++
|
|
177
|
+
}
|
|
178
|
+
else if (scriptContent.startsWith('/*', cursor)) {
|
|
179
|
+
const end = scriptContent.indexOf('*/', cursor + 2)
|
|
180
|
+
if (end === -1)
|
|
181
|
+
break
|
|
182
|
+
cursor = end + 2
|
|
183
|
+
}
|
|
184
|
+
else if (scriptContent.startsWith('//', cursor)) {
|
|
185
|
+
const end = scriptContent.indexOf('\n', cursor + 2)
|
|
186
|
+
if (end === -1)
|
|
187
|
+
break
|
|
188
|
+
cursor = end + 1
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
break
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (scriptContent.slice(cursor, cursor + 4) !== 'type')
|
|
195
|
+
throw new Error('Unable to locate the parsed type-only import keyword')
|
|
196
|
+
return cursor
|
|
162
197
|
}
|
|
163
198
|
|
|
164
|
-
function mergeHaiUiImport(scriptContent, components) {
|
|
199
|
+
function mergeHaiUiImport(scriptContent, components, analysis) {
|
|
165
200
|
if (components.length === 0)
|
|
166
201
|
return scriptContent
|
|
167
202
|
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
203
|
+
const missing = new Set(components)
|
|
204
|
+
const edits = []
|
|
205
|
+
let target
|
|
206
|
+
for (const declaration of analysis.declarations) {
|
|
207
|
+
const named = declaration.specifiers.filter(specifier => specifier.type === 'ImportSpecifier')
|
|
208
|
+
if (named.length === 0)
|
|
209
|
+
continue
|
|
210
|
+
const typeOnly = declaration.importKind === 'type'
|
|
211
|
+
const promoted = named.filter(specifier => (typeOnly || specifier.importKind === 'type') && missing.has(specifier.local.name))
|
|
212
|
+
if (typeOnly) {
|
|
213
|
+
if (promoted.length === 0)
|
|
214
|
+
continue
|
|
215
|
+
const start = typeKeywordStart(scriptContent, declaration.start - analysis.offset)
|
|
216
|
+
edits.push({ start, end: start + 4, text: '' })
|
|
217
|
+
// 仅被用作组件的类型绑定提升为值;同声明内其它类型继续保持 type,不引入不存在的运行时导出。
|
|
218
|
+
for (const specifier of named) {
|
|
219
|
+
if (!promoted.includes(specifier)) {
|
|
220
|
+
const start = specifier.start - analysis.offset
|
|
221
|
+
edits.push({ start, end: start, text: 'type ' })
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
for (const specifier of promoted) {
|
|
227
|
+
const start = specifier.start - analysis.offset
|
|
228
|
+
edits.push({ start, end: start + 'type'.length, text: '' })
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for (const specifier of promoted)
|
|
232
|
+
missing.delete(specifier.local.name)
|
|
233
|
+
target ??= named[named.length - 1]
|
|
178
234
|
}
|
|
179
235
|
|
|
180
|
-
|
|
236
|
+
if (missing.size > 0) {
|
|
237
|
+
if (target) {
|
|
238
|
+
const start = target.end - analysis.offset
|
|
239
|
+
// 在最后一个真实具名绑定后插入;已有注释、别名、尾逗号和导入属性保持原样。
|
|
240
|
+
edits.push({ start, end: start, text: `, ${[...missing].join(', ')}` })
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
edits.push({ start: 0, end: 0, text: `import { ${[...missing].join(', ')} } from '@h-ai/ui'\n` })
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
let result = scriptContent
|
|
247
|
+
for (const edit of edits.sort((left, right) => right.start - left.start))
|
|
248
|
+
result = result.slice(0, edit.start) + edit.text + result.slice(edit.end)
|
|
249
|
+
return result
|
|
181
250
|
}
|
|
182
251
|
|
|
183
|
-
function updateScriptBlock(scriptContent, usedComponents) {
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
252
|
+
function updateScriptBlock(scriptContent, usedComponents, filename, ast) {
|
|
253
|
+
const analysis = analyzeScript(ast.instance)
|
|
254
|
+
// 模块脚本的运行时 import 同样可供模板使用,但只向实例脚本注入缺失项。
|
|
255
|
+
for (const name of analyzeScript(ast.module).imported)
|
|
256
|
+
analysis.imported.add(name)
|
|
257
|
+
const missing = [...usedComponents].filter(name => !analysis.imported.has(name))
|
|
258
|
+
const conflicts = missing.filter(name => analysis.externalTypeBindings.has(name))
|
|
259
|
+
if (conflicts.length > 0) {
|
|
260
|
+
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.`)
|
|
261
|
+
}
|
|
262
|
+
return mergeHaiUiImport(scriptContent, missing, analysis)
|
|
187
263
|
}
|
|
188
264
|
|
|
189
265
|
function autoImportHaiUi() {
|
|
@@ -205,35 +281,24 @@ function autoImportHaiUi() {
|
|
|
205
281
|
return { code: content }
|
|
206
282
|
}
|
|
207
283
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const newScript = updateScriptBlock(scriptContent, usedComponents)
|
|
222
|
-
updated += `<script${attrs}>${newScript}</script>`
|
|
223
|
-
applied = true
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
updated += fullMatch
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (!applied) {
|
|
231
|
-
const scriptBlock = `<script lang="ts">${updateScriptBlock('', usedComponents)}</script>\n`
|
|
232
|
-
return { code: scriptBlock + content }
|
|
284
|
+
// 先由语言预处理器转换样式/模板,再按整份 Svelte AST 选择真实实例脚本。
|
|
285
|
+
// Svelte parse 会移除 BOM;局部坐标基于去除 BOM 的源码,输出仍保留它。
|
|
286
|
+
const prefix = content.startsWith('\uFEFF')
|
|
287
|
+
? '\uFEFF'
|
|
288
|
+
: ''
|
|
289
|
+
const source = content.slice(prefix.length)
|
|
290
|
+
const ast = parse(source, { modern: true })
|
|
291
|
+
const instance = ast.instance
|
|
292
|
+
if (!instance) {
|
|
293
|
+
const scriptContent = updateScriptBlock('', usedComponents, filename, ast)
|
|
294
|
+
if (!scriptContent)
|
|
295
|
+
return { code: content }
|
|
296
|
+
return { code: `${prefix}<script lang="ts">${scriptContent}</script>\n${source}` }
|
|
233
297
|
}
|
|
234
298
|
|
|
235
|
-
|
|
236
|
-
|
|
299
|
+
const { start, end } = instance.content
|
|
300
|
+
const scriptContent = updateScriptBlock(source.slice(start, end), usedComponents, filename, ast)
|
|
301
|
+
return { code: prefix + source.slice(0, start) + scriptContent + source.slice(end) }
|
|
237
302
|
},
|
|
238
303
|
}
|
|
239
304
|
}
|
|
@@ -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
|
}
|
|
@@ -115,7 +115,9 @@
|
|
|
115
115
|
class={cn(
|
|
116
116
|
'flex flex-col items-center justify-center flex-1 h-full relative transition-colors',
|
|
117
117
|
'hai-no-select',
|
|
118
|
-
item.id === active
|
|
118
|
+
item.id === active
|
|
119
|
+
? 'text-primary'
|
|
120
|
+
: 'text-base-content/60',
|
|
119
121
|
)}
|
|
120
122
|
onclick={() => onchange?.(item.id)}
|
|
121
123
|
>
|
|
@@ -128,7 +130,9 @@
|
|
|
128
130
|
{/if}
|
|
129
131
|
{#if item.badge && item.badge > 0}
|
|
130
132
|
<span class='absolute -top-1 -right-2 badge badge-error badge-xs text-[10px] min-w-4 h-4'>
|
|
131
|
-
{item.badge > 99
|
|
133
|
+
{item.badge > 99
|
|
134
|
+
? '99+'
|
|
135
|
+
: item.badge}
|
|
132
136
|
</span>
|
|
133
137
|
{/if}
|
|
134
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
|
)
|