@geektr.cloud/acrux-ui 0.0.0-stage → 0.1.1

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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -2
  3. package/package.json +70 -3
  4. package/src/components/acrux-ui/actions/ConfirmPopover.vue +107 -0
  5. package/src/components/acrux-ui/actions/FormShell.vue +96 -0
  6. package/src/components/acrux-ui/actions/RemovalButton.vue +65 -0
  7. package/src/components/acrux-ui/actions/Stepper.vue +116 -0
  8. package/src/components/acrux-ui/actions/form.ts +36 -0
  9. package/src/components/acrux-ui/actions/index.ts +70 -0
  10. package/src/components/acrux-ui/actions/stepper.ts +65 -0
  11. package/src/components/acrux-ui/actions/utils.ts +138 -0
  12. package/src/components/acrux-ui/base/CopyBtn.vue +85 -0
  13. package/src/components/acrux-ui/base/EmptyValue.vue +25 -0
  14. package/src/components/acrux-ui/base/Icon.vue +44 -0
  15. package/src/components/acrux-ui/base/IconBtn.vue +51 -0
  16. package/src/components/acrux-ui/base/Text.vue +85 -0
  17. package/src/components/acrux-ui/base/VSeparator.vue +21 -0
  18. package/src/components/acrux-ui/base/async.ts +35 -0
  19. package/src/components/acrux-ui/base/index.ts +7 -0
  20. package/src/components/acrux-ui/display/AsyncError.vue +46 -0
  21. package/src/components/acrux-ui/display/CodeBlock.vue +91 -0
  22. package/src/components/acrux-ui/display/CopyTag.vue +51 -0
  23. package/src/components/acrux-ui/display/DataView.ts +47 -0
  24. package/src/components/acrux-ui/display/DateFormatter.vue +61 -0
  25. package/src/components/acrux-ui/display/Disclosure.vue +45 -0
  26. package/src/components/acrux-ui/display/Link.vue +81 -0
  27. package/src/components/acrux-ui/display/MultiLine.vue +29 -0
  28. package/src/components/acrux-ui/display/Notice.vue +71 -0
  29. package/src/components/acrux-ui/display/Pem.vue +165 -0
  30. package/src/components/acrux-ui/display/QrBtn.vue +117 -0
  31. package/src/components/acrux-ui/display/QrModal.vue +76 -0
  32. package/src/components/acrux-ui/display/Route.vue +52 -0
  33. package/src/components/acrux-ui/display/Token.vue +106 -0
  34. package/src/components/acrux-ui/display/UUID.vue +46 -0
  35. package/src/components/acrux-ui/display/index.ts +17 -0
  36. package/src/components/acrux-ui/display/pem.ts +100 -0
  37. package/src/components/acrux-ui/display/qr.ts +20 -0
  38. package/src/components/acrux-ui/fields/EntitySelect.vue +253 -0
  39. package/src/components/acrux-ui/fields/FieldError.vue +11 -0
  40. package/src/components/acrux-ui/fields/JsonTextArea.vue +105 -0
  41. package/src/components/acrux-ui/fields/MultiLineInput.vue +145 -0
  42. package/src/components/acrux-ui/fields/Select.vue +106 -0
  43. package/src/components/acrux-ui/fields/fieldAccessibility.ts +38 -0
  44. package/src/components/acrux-ui/fields/index.ts +4 -0
  45. package/src/components/acrux-ui/page/BackButton.vue +70 -0
  46. package/src/components/acrux-ui/page/PageDetail.vue +125 -0
  47. package/src/components/acrux-ui/page/PageEntry.vue +130 -0
  48. package/src/components/acrux-ui/page/PageState.vue +108 -0
  49. package/src/components/acrux-ui/page/index.ts +3 -0
  50. package/src/components/acrux-ui/page/pageState.ts +18 -0
  51. package/src/components/ui/alert/Alert.vue +17 -0
  52. package/src/components/ui/alert/AlertAction.vue +17 -0
  53. package/src/components/ui/alert/AlertDescription.vue +22 -0
  54. package/src/components/ui/alert/AlertTitle.vue +22 -0
  55. package/src/components/ui/alert/index.ts +25 -0
  56. package/src/components/ui/badge/Badge.vue +29 -0
  57. package/src/components/ui/badge/index.ts +25 -0
  58. package/src/components/ui/button/Button.vue +31 -0
  59. package/src/components/ui/button/index.ts +39 -0
  60. package/src/components/ui/card/Card.vue +29 -0
  61. package/src/components/ui/card/CardAction.vue +17 -0
  62. package/src/components/ui/card/CardContent.vue +14 -0
  63. package/src/components/ui/card/CardDescription.vue +14 -0
  64. package/src/components/ui/card/CardFooter.vue +17 -0
  65. package/src/components/ui/card/CardHeader.vue +22 -0
  66. package/src/components/ui/card/CardTitle.vue +14 -0
  67. package/src/components/ui/card/index.ts +7 -0
  68. package/src/components/ui/collapsible/Collapsible.vue +15 -0
  69. package/src/components/ui/collapsible/CollapsibleContent.vue +12 -0
  70. package/src/components/ui/collapsible/CollapsibleTrigger.vue +12 -0
  71. package/src/components/ui/collapsible/index.ts +3 -0
  72. package/src/components/ui/combobox/Combobox.vue +15 -0
  73. package/src/components/ui/combobox/ComboboxAnchor.vue +19 -0
  74. package/src/components/ui/combobox/ComboboxEmpty.vue +26 -0
  75. package/src/components/ui/combobox/ComboboxInput.vue +40 -0
  76. package/src/components/ui/combobox/ComboboxItem.vue +29 -0
  77. package/src/components/ui/combobox/ComboboxList.vue +38 -0
  78. package/src/components/ui/combobox/ComboboxViewport.vue +28 -0
  79. package/src/components/ui/combobox/index.ts +9 -0
  80. package/src/components/ui/empty/Empty.vue +22 -0
  81. package/src/components/ui/empty/EmptyContent.vue +17 -0
  82. package/src/components/ui/empty/EmptyDescription.vue +22 -0
  83. package/src/components/ui/empty/EmptyHeader.vue +14 -0
  84. package/src/components/ui/empty/EmptyMedia.vue +22 -0
  85. package/src/components/ui/empty/EmptyTitle.vue +14 -0
  86. package/src/components/ui/empty/index.ts +26 -0
  87. package/src/components/ui/field/Field.vue +27 -0
  88. package/src/components/ui/field/FieldContent.vue +17 -0
  89. package/src/components/ui/field/FieldDescription.vue +24 -0
  90. package/src/components/ui/field/FieldError.vue +50 -0
  91. package/src/components/ui/field/FieldGroup.vue +22 -0
  92. package/src/components/ui/field/FieldLabel.vue +24 -0
  93. package/src/components/ui/field/FieldLegend.vue +24 -0
  94. package/src/components/ui/field/FieldSeparator.vue +26 -0
  95. package/src/components/ui/field/FieldSet.vue +22 -0
  96. package/src/components/ui/field/FieldTitle.vue +22 -0
  97. package/src/components/ui/field/index.ts +30 -0
  98. package/src/components/ui/input/Input.vue +33 -0
  99. package/src/components/ui/input/index.ts +1 -0
  100. package/src/components/ui/input-group/InputGroup.vue +23 -0
  101. package/src/components/ui/input-group/InputGroupAddon.vue +39 -0
  102. package/src/components/ui/input-group/InputGroupButton.vue +22 -0
  103. package/src/components/ui/input-group/InputGroupInput.vue +21 -0
  104. package/src/components/ui/input-group/InputGroupText.vue +21 -0
  105. package/src/components/ui/input-group/InputGroupTextarea.vue +21 -0
  106. package/src/components/ui/input-group/index.ts +53 -0
  107. package/src/components/ui/label/Label.vue +26 -0
  108. package/src/components/ui/label/index.ts +1 -0
  109. package/src/components/ui/popover/Popover.vue +15 -0
  110. package/src/components/ui/popover/PopoverAnchor.vue +12 -0
  111. package/src/components/ui/popover/PopoverContent.vue +38 -0
  112. package/src/components/ui/popover/PopoverDescription.vue +14 -0
  113. package/src/components/ui/popover/PopoverHeader.vue +14 -0
  114. package/src/components/ui/popover/PopoverTitle.vue +14 -0
  115. package/src/components/ui/popover/PopoverTrigger.vue +12 -0
  116. package/src/components/ui/popover/index.ts +7 -0
  117. package/src/components/ui/select/Select.vue +15 -0
  118. package/src/components/ui/select/SelectContent.vue +53 -0
  119. package/src/components/ui/select/SelectGroup.vue +17 -0
  120. package/src/components/ui/select/SelectItem.vue +40 -0
  121. package/src/components/ui/select/SelectItemText.vue +12 -0
  122. package/src/components/ui/select/SelectLabel.vue +14 -0
  123. package/src/components/ui/select/SelectScrollDownButton.vue +32 -0
  124. package/src/components/ui/select/SelectScrollUpButton.vue +32 -0
  125. package/src/components/ui/select/SelectSeparator.vue +19 -0
  126. package/src/components/ui/select/SelectTrigger.vue +36 -0
  127. package/src/components/ui/select/SelectValue.vue +12 -0
  128. package/src/components/ui/select/index.ts +11 -0
  129. package/src/components/ui/separator/Separator.vue +27 -0
  130. package/src/components/ui/separator/index.ts +1 -0
  131. package/src/components/ui/skeleton/Skeleton.vue +14 -0
  132. package/src/components/ui/skeleton/index.ts +1 -0
  133. package/src/components/ui/spinner/Spinner.vue +14 -0
  134. package/src/components/ui/spinner/index.ts +1 -0
  135. package/src/components/ui/switch/Switch.vue +47 -0
  136. package/src/components/ui/switch/index.ts +1 -0
  137. package/src/components/ui/table/Table.vue +24 -0
  138. package/src/components/ui/table/TableBody.vue +14 -0
  139. package/src/components/ui/table/TableCaption.vue +14 -0
  140. package/src/components/ui/table/TableCell.vue +17 -0
  141. package/src/components/ui/table/TableEmpty.vue +32 -0
  142. package/src/components/ui/table/TableFooter.vue +14 -0
  143. package/src/components/ui/table/TableHead.vue +29 -0
  144. package/src/components/ui/table/TableHeader.vue +14 -0
  145. package/src/components/ui/table/TableRow.vue +22 -0
  146. package/src/components/ui/table/index.ts +9 -0
  147. package/src/components/ui/tags-input/TagsInput.vue +31 -0
  148. package/src/components/ui/tags-input/TagsInputInput.vue +20 -0
  149. package/src/components/ui/tags-input/TagsInputItem.vue +28 -0
  150. package/src/components/ui/tags-input/TagsInputItemDelete.vue +23 -0
  151. package/src/components/ui/tags-input/TagsInputItemText.vue +17 -0
  152. package/src/components/ui/tags-input/index.ts +5 -0
  153. package/src/components/ui/textarea/Textarea.vue +33 -0
  154. package/src/components/ui/textarea/index.ts +1 -0
  155. package/src/index.ts +5 -0
  156. package/src/testing/renderer.ts +99 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 geektr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # @geektr.cloud/acrux-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Acrux 的 Vue 应用组件层与 shadcn 基础原语,提供 `base`、`display`、`fields`、`page`、`actions` 五组入口。
4
+
5
+ ```sh
6
+ pnpm add @geektr.cloud/acrux-ui
7
+ ```
8
+
9
+ 这是 **source-only** 包:消费者需要能够编译 TypeScript 与 Vue SFC 的 bundler,并提供 Tailwind 主题及源码扫描配置。
10
+
11
+ ```ts
12
+ import { PageEntry } from "@geektr.cloud/acrux-ui/page";
13
+ import { Button } from "@geektr.cloud/acrux-ui/ui/button";
14
+ ```
15
+
16
+ 也可以通过 shadcn-vue registry 安装可编辑源码;registry namespace 仍为 `@acrux`,与 npm scope 不同:
17
+
18
+ ```sh
19
+ npx shadcn-vue add @acrux/page
20
+ ```
21
+
22
+ 完整说明见 [registry 文档](https://acrux.geektr.cloud/packages/registry)与[仓库](https://github.com/geektr-cloud/acrux)。
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@geektr.cloud/acrux-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "有明确主张的 Vue 应用组件层与 shadcn 基础原语,同时提供源码包入口与 shadcn-vue registry。",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/geektr-cloud/acrux.git",
10
+ "directory": "packages/acrux-ui"
11
+ },
12
+ "homepage": "https://acrux.geektr.cloud/packages/registry",
13
+ "files": [
14
+ "src",
15
+ "!**/*.test.ts",
16
+ "!**/__fixtures__/",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "registry": "https://registry.npmjs.org"
23
+ },
24
+ "exports": {
25
+ ".": "./src/index.ts",
26
+ "./base": "./src/components/acrux-ui/base/index.ts",
27
+ "./display": "./src/components/acrux-ui/display/index.ts",
28
+ "./fields": "./src/components/acrux-ui/fields/index.ts",
29
+ "./page": "./src/components/acrux-ui/page/index.ts",
30
+ "./actions": "./src/components/acrux-ui/actions/index.ts",
31
+ "./ui/*": "./src/components/ui/*/index.ts"
32
+ },
33
+ "prettier": "@geektr.cloud/acrux-eslint-config/prettier",
34
+ "engines": {
35
+ "node": "^22.12.0 || ^24.0.0 || >=26.0.0"
36
+ },
37
+ "dependencies": {
38
+ "@lucide/vue": "^1.83.0",
39
+ "@types/qrcode": "^1.5.6",
40
+ "@vueuse/core": "^15.1.0",
41
+ "class-variance-authority": "^0.7.1",
42
+ "cn": "^0.5.2",
43
+ "date-fns": "^4.4.0",
44
+ "qrcode": "^1.5.4",
45
+ "reka-ui": "^2.12.0",
46
+ "@geektr.cloud/acrux-core": "0.1.1"
47
+ },
48
+ "devDependencies": {
49
+ "@vitejs/plugin-vue": "^6.0.11",
50
+ "eslint": "^10.16.0",
51
+ "prettier": "3.10.1",
52
+ "shadcn-vue": "^2.9.0",
53
+ "typescript": "~5.9.3",
54
+ "vitest": "^5.1.2",
55
+ "vue": "^3.5.46",
56
+ "vue-final-modal": "^5.0.1",
57
+ "vue-router": "^5.5.3",
58
+ "vue-tsc": "3.3.13",
59
+ "@geektr.cloud/acrux-eslint-config": "0.1.1"
60
+ },
61
+ "peerDependencies": {
62
+ "vue": "^3.5.46",
63
+ "vue-final-modal": "^5.0.1",
64
+ "vue-router": "^5.5.3"
65
+ },
66
+ "scripts": {
67
+ "type-check": "vue-tsc --noEmit -p tsconfig.json",
68
+ "test": "vitest",
69
+ "test:run": "vitest run",
70
+ "lint": "eslint --fix ./src && prettier --write ./src",
71
+ "registry:build": "shadcn-vue build -c . -o ../../apps/acrux-docs/public/r/acrux-ui/v0 registries/acrux-ui.json"
72
+ }
6
73
  }
@@ -0,0 +1,107 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from "vue";
3
+ import { computed, ref, watch } from "vue";
4
+ import { cn } from "cn";
5
+ import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "../../ui/popover";
6
+ import { Spinner } from "../../ui/spinner";
7
+ import { Icon, IconBtn, Text } from "../base";
8
+ import type { ReferenceElement } from "reka-ui";
9
+ import { Check, X } from "@lucide/vue";
10
+ import type { ConfirmAction } from "./index";
11
+
12
+ defineOptions({ inheritAttrs: false });
13
+
14
+ const props = withDefaults(
15
+ defineProps<{
16
+ anchor?: ReferenceElement;
17
+ message: string;
18
+ ctx: ConfirmAction;
19
+ confirmLabel?: string;
20
+ cancelLabel?: string;
21
+ errorText?: string;
22
+ class?: HTMLAttributes["class"];
23
+ }>(),
24
+ {
25
+ anchor: undefined,
26
+ confirmLabel: "确认删除",
27
+ cancelLabel: "取消",
28
+ errorText: undefined,
29
+ class: undefined,
30
+ },
31
+ );
32
+
33
+ const emit = defineEmits<{ (e: "removed"): void }>();
34
+ const open = defineModel<boolean>("open", { default: false });
35
+ const attempted = ref(false);
36
+
37
+ // 直接读取 props.ctx,避免 setup 时解构后 id / removal 变化仍持旧引用。
38
+ const status = computed(() => props.ctx[0]);
39
+
40
+ watch([open, () => status.value.loading], ([isOpen, loading]) => {
41
+ // 删除进行中可能因外部原因触发关闭;此时保留 attempted,避免错误提示被提前清掉。
42
+ if (!isOpen && !loading) attempted.value = false;
43
+ });
44
+
45
+ const errorMessage = computed(() => {
46
+ if (!attempted.value) return "";
47
+ const error = status.value.error;
48
+ if (!error) return "";
49
+ return props.errorText ?? (error instanceof Error ? error.message : String(error));
50
+ });
51
+
52
+ // 进行中不允许 Esc、外部点击或 light dismiss 关掉确认层。
53
+ const guardDismiss = (event: Event) => {
54
+ if (status.value.loading) event.preventDefault();
55
+ };
56
+
57
+ // trigger 再次点击也走受控开关;删除进行中直接拒绝关闭。
58
+ const setOpen = (value: boolean) => {
59
+ if (!value && props.ctx[0].loading) return;
60
+ open.value = value;
61
+ };
62
+
63
+ const submit = async () => {
64
+ if (status.value.loading) return;
65
+ attempted.value = true;
66
+ await props.ctx[1]();
67
+ // useAsyncState 会吞掉异常并写入 status.error;仅无错误时视为删除成功。
68
+ if (status.value.error) return;
69
+ open.value = false;
70
+ emit("removed");
71
+ };
72
+ </script>
73
+
74
+ <template>
75
+ <Popover :open="open" @update:open="setOpen">
76
+ <PopoverAnchor v-if="anchor" :reference="anchor" />
77
+ <PopoverTrigger v-else-if="$slots.trigger" as-child>
78
+ <slot name="trigger" />
79
+ </PopoverTrigger>
80
+ <PopoverContent
81
+ v-bind="$attrs"
82
+ data-slot="confirm-popover"
83
+ side="left"
84
+ :class="cn('w-auto', props.class)"
85
+ @escape-key-down="guardDismiss"
86
+ @interact-outside="guardDismiss"
87
+ >
88
+ <div class="flex flex-row items-center gap-2" data-slot="confirm-popover-actions">
89
+ <div>{{ message }}</div>
90
+ <IconBtn
91
+ type="button"
92
+ variant="secondary"
93
+ :aria-label="confirmLabel"
94
+ :disabled="status.loading"
95
+ @click="void submit()"
96
+ >
97
+ <Spinner v-if="status.loading" />
98
+ <Icon v-else :icon="Check" />
99
+ </IconBtn>
100
+ <IconBtn type="button" :aria-label="cancelLabel" :disabled="status.loading" @click="setOpen(false)">
101
+ <Icon :icon="X" />
102
+ </IconBtn>
103
+ </div>
104
+ <Text v-if="errorMessage" class="text-destructive" role="alert">{{ errorMessage }}</Text>
105
+ </PopoverContent>
106
+ </Popover>
107
+ </template>
@@ -0,0 +1,96 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from "vue";
3
+ import { computed, nextTick, ref, shallowRef, useId } from "vue";
4
+ import type { AsyncStatus } from "@geektr.cloud/acrux-core";
5
+ import { cn } from "cn";
6
+ import { Button } from "../../ui/button";
7
+ import { FieldGroup, FieldLegend, FieldSet } from "../../ui/field";
8
+ import { Notice } from "../display";
9
+ import { canSubmitForm, focusFirstInvalidField, runFormSubmission } from "./form";
10
+ import type { SubmitForm, ValidateForm } from "./form";
11
+
12
+ defineOptions({ name: "FormShell", inheritAttrs: false });
13
+
14
+ const props = withDefaults(
15
+ defineProps<{
16
+ title: string;
17
+ status: AsyncStatus;
18
+ validate?: ValidateForm;
19
+ submit: SubmitForm;
20
+ saveLabel?: string;
21
+ savingLabel?: string;
22
+ cancelLabel?: string;
23
+ errorTitle?: string;
24
+ unknownErrorText?: string;
25
+ class?: HTMLAttributes["class"];
26
+ }>(),
27
+ {
28
+ validate: undefined,
29
+ saveLabel: "保存",
30
+ savingLabel: "保存中…",
31
+ cancelLabel: "取消",
32
+ errorTitle: "保存失败",
33
+ unknownErrorText: "未知错误",
34
+ class: undefined,
35
+ },
36
+ );
37
+
38
+ const emit = defineEmits<{ close: [] }>();
39
+ const titleId = `${useId()}-form-title`;
40
+ const formElement = ref<HTMLFormElement>();
41
+ const pending = ref(false);
42
+ const noCommandError = Symbol("no-command-error");
43
+ const commandError = shallowRef<unknown>(noCommandError);
44
+ const busy = computed(() => pending.value || props.status.loading);
45
+ const hasError = computed(() => commandError.value !== noCommandError || Boolean(props.status.error));
46
+ const currentError = computed(() => (commandError.value === noCommandError ? props.status.error : commandError.value));
47
+ const errorMessage = computed(() =>
48
+ currentError.value instanceof Error ? currentError.value.message : props.unknownErrorText,
49
+ );
50
+
51
+ const onSubmit = async () => {
52
+ if (!canSubmitForm(pending.value, props.status.loading)) return;
53
+ pending.value = true;
54
+ commandError.value = noCommandError;
55
+ try {
56
+ const result = await runFormSubmission(props.status, props.validate, props.submit);
57
+ if (result.type === "invalid") {
58
+ await nextTick();
59
+ focusFirstInvalidField(formElement.value);
60
+ }
61
+ if (result.type === "error") commandError.value = result.error;
62
+ if (result.type === "success") emit("close");
63
+ } finally {
64
+ pending.value = false;
65
+ }
66
+ };
67
+ </script>
68
+
69
+ <template>
70
+ <form
71
+ ref="formElement"
72
+ v-bind="$attrs"
73
+ data-slot="form-shell"
74
+ novalidate
75
+ :aria-labelledby="titleId"
76
+ :aria-busy="busy"
77
+ :class="cn('w-full max-w-md', props.class)"
78
+ @submit.prevent="void onSubmit()"
79
+ >
80
+ <FieldSet>
81
+ <FieldLegend :id="titleId">{{ title }}</FieldLegend>
82
+ <FieldGroup>
83
+ <slot />
84
+ </FieldGroup>
85
+ </FieldSet>
86
+ <Notice v-if="hasError" tone="error" :title="errorTitle" class="mt-4">
87
+ {{ errorMessage }}
88
+ </Notice>
89
+ <div data-slot="form-shell-actions" class="mt-4 flex justify-end gap-2">
90
+ <Button type="submit" :disabled="busy">{{ busy ? savingLabel : saveLabel }}</Button>
91
+ <Button type="button" variant="secondary" :disabled="busy" @click="emit('close')">
92
+ {{ cancelLabel }}
93
+ </Button>
94
+ </div>
95
+ </form>
96
+ </template>
@@ -0,0 +1,65 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from "vue";
3
+ import { computed, ref } from "vue";
4
+ import { cn } from "cn";
5
+ import { Button } from "../../ui/button";
6
+ import { Icon } from "../base";
7
+ import { Trash } from "@lucide/vue";
8
+ import ConfirmPopover from "./ConfirmPopover.vue";
9
+ import type { Removal } from "@geektr.cloud/acrux-core";
10
+
11
+ defineOptions({ name: "RemovalButton", inheritAttrs: false });
12
+
13
+ const props = withDefaults(
14
+ defineProps<{
15
+ label?: string;
16
+ message: string;
17
+ ctx: Removal<unknown>;
18
+ triggerLabel?: string;
19
+ confirmLabel?: string;
20
+ cancelLabel?: string;
21
+ errorText?: string;
22
+ class?: HTMLAttributes["class"];
23
+ }>(),
24
+ {
25
+ label: undefined,
26
+ triggerLabel: "删除",
27
+ confirmLabel: "确认删除",
28
+ cancelLabel: "取消",
29
+ errorText: undefined,
30
+ class: undefined,
31
+ },
32
+ );
33
+
34
+ const emit = defineEmits<{ (e: "removed"): void }>();
35
+ const open = ref(false);
36
+ // 空字符串 label 不产生可见文本,仍需 aria-label 兜底。
37
+ const hasVisibleLabel = computed(() => Boolean(props.label));
38
+ </script>
39
+
40
+ <template>
41
+ <ConfirmPopover
42
+ v-model:open="open"
43
+ :message="message"
44
+ :ctx="ctx"
45
+ :confirm-label="confirmLabel"
46
+ :cancel-label="cancelLabel"
47
+ :error-text="errorText"
48
+ @removed="emit('removed')"
49
+ >
50
+ <template #trigger>
51
+ <Button
52
+ type="button"
53
+ variant="destructive"
54
+ data-slot="removal-button"
55
+ :aria-label="hasVisibleLabel ? undefined : triggerLabel"
56
+ :title="hasVisibleLabel ? undefined : triggerLabel"
57
+ :class="cn('cursor-pointer', props.class)"
58
+ v-bind="$attrs"
59
+ >
60
+ <Icon :icon="Trash" />
61
+ <slot>{{ label }}</slot>
62
+ </Button>
63
+ </template>
64
+ </ConfirmPopover>
65
+ </template>
@@ -0,0 +1,116 @@
1
+ <!-- eslint-disable vue/multi-word-component-names -->
2
+ <script setup lang="ts">
3
+ import type { HTMLAttributes } from "vue";
4
+ import { nextTick, ref, useId, watch } from "vue";
5
+ import { ChevronDown } from "@lucide/vue";
6
+ import { cn } from "cn";
7
+ import { Icon } from "../base";
8
+ import { canOpenStepperStep, continueStepperStep, getStepperStatus, openStepperStep } from "./stepper";
9
+ import type { StepperItem, StepperSlotProps, StepperState } from "./stepper";
10
+
11
+ defineOptions({ name: "Stepper", inheritAttrs: false });
12
+
13
+ const props = withDefaults(
14
+ defineProps<{
15
+ items: StepperItem[];
16
+ class?: HTMLAttributes["class"];
17
+ }>(),
18
+ { class: undefined },
19
+ );
20
+
21
+ defineSlots<{ default?: (props: StepperSlotProps) => unknown }>();
22
+ const model = defineModel<StepperState>({ required: true });
23
+ const uid = useId();
24
+ const headingElements = ref<HTMLHeadingElement[]>([]);
25
+
26
+ const headingId = (index: number) => `${uid}-stepper-${index}-heading`;
27
+ const panelId = (index: number) => `${uid}-stepper-${index}-panel`;
28
+ const stepNumber = (index: number) => String(index + 1).padStart(2, "0");
29
+ const canOpen = (item: StepperItem) => canOpenStepperStep(model.value, item.id, props.items);
30
+ const status = (item: StepperItem) => getStepperStatus(model.value, item, props.items);
31
+
32
+ const setHeadingRef = (index: number, element: unknown) => {
33
+ if (element instanceof HTMLHeadingElement) headingElements.value[index] = element;
34
+ else delete headingElements.value[index];
35
+ };
36
+
37
+ const open = (item: StepperItem) => {
38
+ const next = openStepperStep(model.value, item.id, props.items);
39
+ if (next !== model.value) model.value = next;
40
+ };
41
+
42
+ const continueCurrent = () => {
43
+ const next = continueStepperStep(model.value, props.items);
44
+ if (next !== model.value) model.value = next;
45
+ };
46
+
47
+ watch(
48
+ () => model.value.current,
49
+ async (current) => {
50
+ await nextTick();
51
+ const index = props.items.findIndex((item) => item.id === current);
52
+ if (index >= 0) headingElements.value[index]?.focus();
53
+ },
54
+ );
55
+ </script>
56
+
57
+ <template>
58
+ <div v-bind="$attrs" data-slot="stepper" :class="cn('grid w-full min-w-0 gap-3 sm:gap-4', props.class)">
59
+ <div
60
+ v-for="(item, index) in items"
61
+ :key="item.id"
62
+ data-slot="stepper-item"
63
+ :data-step="item.id"
64
+ :data-state="status(item)"
65
+ class="min-w-0 border border-border bg-background"
66
+ >
67
+ <h2
68
+ :id="headingId(index)"
69
+ :ref="(element) => setHeadingRef(index, element)"
70
+ :aria-current="model.current === item.id ? 'step' : undefined"
71
+ tabindex="-1"
72
+ class="scroll-m-4 text-sm font-medium tracking-tight focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
73
+ >
74
+ <button
75
+ type="button"
76
+ class="min-h-8 w-full min-w-0 px-3 py-1.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-inset disabled:cursor-default disabled:opacity-60 sm:px-4"
77
+ :aria-expanded="model.current === item.id"
78
+ :aria-controls="panelId(index)"
79
+ :disabled="!canOpen(item)"
80
+ @click="open(item)"
81
+ >
82
+ <span class="grid min-w-0 grid-cols-[auto_auto_minmax(0,1fr)_auto] items-center gap-2">
83
+ <span class="w-5 shrink-0 font-mono text-xs text-muted-foreground">{{ stepNumber(index) }}</span>
84
+ <Icon
85
+ :icon="ChevronDown"
86
+ size="md"
87
+ class="text-muted-foreground motion-safe:transition-transform"
88
+ :class="model.current === item.id ? 'rotate-0' : '-rotate-90'"
89
+ />
90
+ <span class="min-w-0">
91
+ <span class="block break-words">{{ item.title }}</span>
92
+ <span
93
+ v-if="model.current !== item.id && item.summary"
94
+ class="mt-0.5 block truncate text-xs font-normal text-muted-foreground"
95
+ >
96
+ {{ item.summary }}
97
+ </span>
98
+ </span>
99
+ <span v-if="model.current === item.id" class="shrink-0 text-xs font-normal text-muted-foreground">
100
+ 当前
101
+ </span>
102
+ </span>
103
+ </button>
104
+ </h2>
105
+
106
+ <div
107
+ v-if="model.current === item.id"
108
+ :id="panelId(index)"
109
+ data-slot="stepper-panel"
110
+ class="min-w-0 border-t border-border p-4 sm:p-5"
111
+ >
112
+ <slot :item="item" :continue="continueCurrent" />
113
+ </div>
114
+ </div>
115
+ </div>
116
+ </template>
@@ -0,0 +1,36 @@
1
+ import type { AsyncStatus } from "@geektr.cloud/acrux-core";
2
+
3
+ export type ValidateForm = () => boolean | Promise<boolean>;
4
+ export type SubmitForm = () => unknown | Promise<unknown>;
5
+
6
+ export type FormSubmissionResult = { type: "success" } | { type: "invalid" } | { type: "error"; error: unknown };
7
+
8
+ /** 本地 pending 覆盖校验阶段,外部 loading 覆盖实际提交阶段。 */
9
+ export const canSubmitForm = (pending: boolean, loading: boolean) => !pending && !loading;
10
+
11
+ /** novalidate 表单校验失败后,把焦点送到首个无效字段,确保错误可被读屏器感知。 */
12
+ export const focusFirstInvalidField = (form: HTMLFormElement | undefined) => {
13
+ const invalidField = form?.querySelector<HTMLElement>('[data-invalid="true"]');
14
+ const control =
15
+ invalidField?.querySelector<HTMLElement>(
16
+ '[aria-invalid="true"], input, select, textarea, button, [tabindex]:not([tabindex="-1"])',
17
+ ) ?? form?.querySelector<HTMLElement>('[aria-invalid="true"]');
18
+ control?.focus();
19
+ };
20
+
21
+ /** 只有校验通过、提交完成且 status.error 为空时才允许关闭。 */
22
+ export const runFormSubmission = async (
23
+ status: Pick<AsyncStatus, "error">,
24
+ validate: ValidateForm | undefined,
25
+ submit: SubmitForm,
26
+ ): Promise<FormSubmissionResult> => {
27
+ try {
28
+ if (validate && !(await validate())) return { type: "invalid" };
29
+ await submit();
30
+ // useAsyncState 会吞掉异常并写入 status.error;抛出异常则由这里转为失败结果。
31
+ if (status.error) return { type: "error", error: status.error };
32
+ return { type: "success" };
33
+ } catch (error) {
34
+ return { type: "error", error };
35
+ }
36
+ };
@@ -0,0 +1,70 @@
1
+ import type { ReferenceElement } from "reka-ui";
2
+ import { computed, defineComponent, h, ref, watch } from "vue";
3
+ import _ConfirmPopover from "./ConfirmPopover.vue";
4
+ import type { AsyncStatus, BaseData, BaseId, Removal, UseRemoval } from "@geektr.cloud/acrux-core";
5
+
6
+ export type ConfirmAction = readonly [status: AsyncStatus, execute: () => Promise<void>] | Removal<unknown>;
7
+
8
+ export { useFormModel } from "./utils";
9
+ export type { FormModelComponent, FormModelEmits, FormModelLoader, FormModelProps, UseFormModelOptions } from "./utils";
10
+ export { default as FormShell } from "./FormShell.vue";
11
+ export { default as RemovalButton } from "./RemovalButton.vue";
12
+ export { default as ConfirmPopover } from "./ConfirmPopover.vue";
13
+ export { default as Stepper } from "./Stepper.vue";
14
+ export { createStepperState } from "./stepper";
15
+ export type { StepperItem, StepperSlotProps, StepperState } from "./stepper";
16
+
17
+ export interface ConfirmPopoverOptions<T extends BaseData> {
18
+ message: string | ((src: T | undefined) => string);
19
+ useRemoval: UseRemoval<T>;
20
+ confirmLabel?: string;
21
+ cancelLabel?: string;
22
+ errorText?: string;
23
+ onRemoved?: () => void;
24
+ }
25
+
26
+ export const useConfirmPopover = <T extends BaseData>(opts: ConfirmPopoverOptions<T>) => {
27
+ const id = ref<BaseId | undefined>();
28
+ const anchor = ref<ReferenceElement>();
29
+ const isOpen = ref(false);
30
+
31
+ const ConfirmPopover = defineComponent({
32
+ setup() {
33
+ const removal = opts.useRemoval(id);
34
+ const message = computed(() =>
35
+ typeof opts.message === "function" ? opts.message(removal[2][0].value) : opts.message,
36
+ );
37
+
38
+ return () =>
39
+ h(_ConfirmPopover, {
40
+ anchor: anchor.value,
41
+ message: message.value,
42
+ ctx: removal,
43
+ confirmLabel: opts.confirmLabel,
44
+ cancelLabel: opts.cancelLabel,
45
+ errorText: opts.errorText,
46
+ open: isOpen.value,
47
+ "onUpdate:open": (v: boolean) => (isOpen.value = v),
48
+ onRemoved: () => opts.onRemoved?.(),
49
+ });
50
+ },
51
+ });
52
+
53
+ watch(isOpen, (value) => {
54
+ if (value) return;
55
+ anchor.value = undefined;
56
+ id.value = undefined;
57
+ });
58
+
59
+ const open = (event: Event, _id: BaseId) => {
60
+ anchor.value = event.target as ReferenceElement;
61
+ id.value = _id;
62
+ isOpen.value = true;
63
+ };
64
+
65
+ const close = () => {
66
+ isOpen.value = false;
67
+ };
68
+
69
+ return { open, close, ConfirmPopover };
70
+ };
@@ -0,0 +1,65 @@
1
+ export interface StepperItem {
2
+ id: string;
3
+ title: string;
4
+ summary?: string;
5
+ disabled?: boolean;
6
+ }
7
+
8
+ export interface StepperState {
9
+ /** 当前唯一展开的步骤。 */
10
+ current: string;
11
+ /** 当前有效输入下最远已解锁的步骤。 */
12
+ furthest: string;
13
+ }
14
+
15
+ export type StepperStatus = "current" | "completed" | "available" | "upcoming";
16
+
17
+ export interface StepperSlotProps {
18
+ item: StepperItem;
19
+ continue: () => void;
20
+ }
21
+
22
+ const stepIndex = (items: StepperItem[], id: string) => items.findIndex((item) => item.id === id);
23
+
24
+ /** 输入失效时由调用方重建状态,避免保留旧输入解锁的步骤。 */
25
+ export const createStepperState = (initialStep: string): StepperState => ({
26
+ current: initialStep,
27
+ furthest: initialStep,
28
+ });
29
+
30
+ export const canOpenStepperStep = (state: StepperState, step: string, items: StepperItem[]): boolean => {
31
+ const targetIndex = stepIndex(items, step);
32
+ const furthestIndex = stepIndex(items, state.furthest);
33
+ const target = items[targetIndex];
34
+ return Boolean(target && !target.disabled && furthestIndex >= 0 && targetIndex <= furthestIndex);
35
+ };
36
+
37
+ /** 只有已解锁且未禁用的步骤可以打开;当前步骤不重复更新。 */
38
+ export const openStepperStep = (state: StepperState, step: string, items: StepperItem[]): StepperState => {
39
+ if (step === state.current) return state;
40
+ if (!canOpenStepperStep(state, step, items)) return state;
41
+ return { ...state, current: step };
42
+ };
43
+
44
+ /** 进入紧邻的下一步,不回退已经到达的最远步骤。 */
45
+ export const continueStepperStep = (state: StepperState, items: StepperItem[]): StepperState => {
46
+ const currentIndex = stepIndex(items, state.current);
47
+ const furthestIndex = stepIndex(items, state.furthest);
48
+ const current = items[currentIndex];
49
+ const next = items[currentIndex + 1];
50
+ if (furthestIndex < 0 || !current || current.disabled || !next || next.disabled) return state;
51
+
52
+ const nextIndex = currentIndex + 1;
53
+ return {
54
+ current: next.id,
55
+ furthest: nextIndex > furthestIndex ? next.id : state.furthest,
56
+ };
57
+ };
58
+
59
+ export const getStepperStatus = (state: StepperState, item: StepperItem, items: StepperItem[]): StepperStatus => {
60
+ if (state.current === item.id) return "current";
61
+ const itemIndex = stepIndex(items, item.id);
62
+ const furthestIndex = stepIndex(items, state.furthest);
63
+ if (itemIndex >= 0 && furthestIndex >= 0 && itemIndex < furthestIndex) return "completed";
64
+ return canOpenStepperStep(state, item.id, items) ? "available" : "upcoming";
65
+ };