@h-ai/ui 0.1.0-alpha.53 → 0.1.0-alpha.55

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.md CHANGED
@@ -273,6 +273,10 @@ components/
273
273
 
274
274
  #### Crypto 加密展示(3 个)
275
275
 
276
+ 输入变化立即清空 `encryptedValue`,只有当前输入的成功结果会回填;清空、回调替换和卸载均使旧请求失效。失败显示内置错误提示且密文保持为空;表单应仅在当前密文非空时提交需要加密的输入。
277
+
278
+ `EncryptedInput` 必须由调用方通过 `onencrypt` 接入真实加密服务,`algorithm` 仅用于说明该服务所用算法。未配置回调时组件明确提示不可用,不生成密文;没有 Base64 等编码回退。
279
+
276
280
  | 组件 | 描述 | 主要属性 |
277
281
  | ------------------ | -------- | ------------------------------------------------------- |
278
282
  | `EncryptedInput` | 加密输入 | `value`, `encryptedValue`, `algorithm`, `showEncrypted` |
@@ -57,26 +57,34 @@
57
57
 
58
58
  const dataAttributes = $derived(getDataAttributes(restProps))
59
59
  let showValue = $state(false)
60
+ let encryptionError = $state(false)
60
61
 
61
- // 模拟加密(实际应该调用 crypto 服务)
62
- function encrypt(text: string): string {
63
- return btoa(text)
64
- }
62
+ // 输入、回调或组件生命周期变化时,旧请求立即失效。
63
+ $effect(() => {
64
+ const input = value
65
+ const encrypt = onencrypt
66
+ encryptedValue = ''
67
+ encryptionError = false
68
+ if (!input || !encrypt)
69
+ return
70
+ let active = true
71
+ const isCurrent = () => active && value === input && onencrypt === encrypt
72
+ void Promise.resolve().then(() => encrypt(input)).then((encrypted) => {
73
+ if (isCurrent())
74
+ encryptedValue = encrypted
75
+ }).catch(() => {
76
+ if (isCurrent())
77
+ encryptionError = true
78
+ })
79
+ return () => {
80
+ active = false
81
+ }
82
+ })
65
83
 
66
84
  function handleInput(e: Event & { currentTarget: HTMLInputElement }) {
67
85
  value = e.currentTarget.value
68
86
 
69
- if (value && onencrypt) {
70
- onencrypt(value).then((encrypted) => {
71
- encryptedValue = encrypted
72
- })
73
- }
74
- else if (value) {
75
- encryptedValue = encrypt(value)
76
- }
77
- else {
78
- encryptedValue = ''
79
- }
87
+ encryptedValue = ''
80
88
 
81
89
  oninput?.(e)
82
90
  }
@@ -97,6 +105,12 @@
97
105
  </script>
98
106
 
99
107
  <div {...dataAttributes} class='encrypted-input space-y-2 {className}'>
108
+ {#if encryptionError}
109
+ <p role='alert' class='text-sm text-error'>{uiM('encrypted_input_failed')}</p>
110
+ {/if}
111
+ {#if !onencrypt}
112
+ <p role='status' class='text-sm text-warning'>{uiM('encrypted_input_unavailable')}</p>
113
+ {/if}
100
114
  <!-- 输入框 -->
101
115
  <div class='relative'>
102
116
  <Input
@@ -48,6 +48,8 @@
48
48
  "encrypted_input_hide": "Hide",
49
49
  "encrypted_input_result": "Encrypted",
50
50
  "encrypted_input_copy": "Copy",
51
+ "encrypted_input_failed": "Encryption failed. Edit the input to retry.",
52
+ "encrypted_input_unavailable": "Encryption is not configured. No ciphertext will be generated.",
51
53
  "image_upload_placeholder": "Click to upload image",
52
54
  "image_upload_max_size_hint": "Max:",
53
55
  "image_upload_size_exceeded": "Image size exceeds limit (max",
@@ -48,6 +48,8 @@
48
48
  "encrypted_input_hide": "隐藏",
49
49
  "encrypted_input_result": "已加密",
50
50
  "encrypted_input_copy": "复制",
51
+ "encrypted_input_failed": "加密失败,请重新输入后重试。",
52
+ "encrypted_input_unavailable": "未配置加密功能,当前输入不会生成密文。",
51
53
  "image_upload_placeholder": "点击上传图片",
52
54
  "image_upload_max_size_hint": "最大:",
53
55
  "image_upload_size_exceeded": "图片大小超出限制(最大",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/ui",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.53",
4
+ "version": "0.1.0-alpha.55",
5
5
  "description": "Hai Framework UI component library for Svelte 5 Runes.",
6
6
  "license": "Apache-2.0",
7
7
  "svelte": "./dist/index.js",
@@ -38,6 +38,9 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
+ "engines": {
42
+ "node": ">=22.12.0"
43
+ },
41
44
  "peerDependencies": {
42
45
  "svelte": "^5.55.9"
43
46
  },
@@ -52,7 +55,7 @@
52
55
  "mermaid": "^11.12.0",
53
56
  "shiki": "^4.0.2",
54
57
  "tailwind-merge": "^3.5.0",
55
- "@h-ai/core": "0.1.0-alpha.53"
58
+ "@h-ai/core": "0.1.0-alpha.55"
56
59
  },
57
60
  "devDependencies": {
58
61
  "@sveltejs/package": "^2.5.7",