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

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
@@ -0,0 +1,76 @@
1
+ <script setup lang="ts">
2
+ import { onMounted, ref, useId } from "vue";
3
+ import { VueFinalModal } from "vue-final-modal";
4
+ import QRCode from "qrcode";
5
+ import { X } from "@lucide/vue";
6
+ import { Card, CardContent, CardHeader } from "../../ui/card";
7
+ import { IconBtn, Text } from "../base";
8
+
9
+ defineOptions({ name: "QrModal" });
10
+
11
+ const props = withDefaults(
12
+ defineProps<{
13
+ value: string;
14
+ onClose?: () => void;
15
+ title?: string;
16
+ closeLabel?: string;
17
+ loadingText?: string;
18
+ errorText?: string;
19
+ }>(),
20
+ {
21
+ onClose: undefined,
22
+ title: "二维码",
23
+ closeLabel: "关闭二维码",
24
+ loadingText: "生成中…",
25
+ errorText: "二维码生成失败",
26
+ },
27
+ );
28
+
29
+ const titleId = useId();
30
+ const closeButton = ref<InstanceType<typeof IconBtn> | null>(null);
31
+ const dataUrl = ref("");
32
+ const error = ref("");
33
+
34
+ const initialFocus = (): HTMLElement | false => {
35
+ const element = closeButton.value?.$el as HTMLElement | undefined;
36
+ return element ?? false;
37
+ };
38
+
39
+ onMounted(async () => {
40
+ try {
41
+ dataUrl.value = await QRCode.toDataURL(props.value, {
42
+ errorCorrectionLevel: "M",
43
+ margin: 2,
44
+ width: 256,
45
+ });
46
+ } catch (err) {
47
+ error.value = err instanceof Error && err.message ? `${props.errorText}:${err.message}` : props.errorText;
48
+ }
49
+ });
50
+ </script>
51
+
52
+ <template>
53
+ <VueFinalModal
54
+ class="flex items-center justify-center"
55
+ :aria-labelledby="titleId"
56
+ :focus-trap="{ initialFocus }"
57
+ @click-outside="onClose?.()"
58
+ >
59
+ <Card class="max-w-xs">
60
+ <CardHeader class="flex flex-row items-center justify-between gap-2">
61
+ <Text :id="titleId" variant="section">{{ title }}</Text>
62
+ <IconBtn ref="closeButton" :icon="X" :aria-label="closeLabel" @click="onClose?.()" />
63
+ </CardHeader>
64
+ <CardContent class="flex flex-col items-center gap-2">
65
+ <Text v-if="error" role="alert" class="text-destructive">{{ error }}</Text>
66
+ <Text v-else-if="!dataUrl" variant="muted" role="status">
67
+ {{ loadingText }}
68
+ </Text>
69
+ <div v-else class="bg-white p-2">
70
+ <img :src="dataUrl" :alt="`${title}:${value}`" width="256" height="256" class="block size-64" />
71
+ </div>
72
+ <Text variant="muted" class="max-w-64 font-mono break-all">{{ value }}</Text>
73
+ </CardContent>
74
+ </Card>
75
+ </VueFinalModal>
76
+ </template>
@@ -0,0 +1,52 @@
1
+ <!-- eslint-disable vue/multi-word-component-names -->
2
+ <script setup lang="ts">
3
+ import type { HTMLAttributes } from "vue";
4
+ import { computed } from "vue";
5
+ import { RouterLink, type RouteLocationRaw } from "vue-router";
6
+ import { cn } from "cn";
7
+ import { Badge, type BadgeVariants } from "../../ui/badge";
8
+ import { EmptyValue } from "../base";
9
+
10
+ defineOptions({ name: "Route", inheritAttrs: false });
11
+
12
+ const props = withDefaults(
13
+ defineProps<{
14
+ to?: RouteLocationRaw | null;
15
+ variant?: BadgeVariants["variant"] | "raw";
16
+ class?: HTMLAttributes["class"];
17
+ }>(),
18
+ {
19
+ to: undefined,
20
+ variant: "raw",
21
+ class: undefined,
22
+ },
23
+ );
24
+
25
+ const target = computed<RouteLocationRaw>(() => props.to ?? "");
26
+ const hasTarget = computed(() => Boolean(props.to));
27
+ const isRaw = computed(() => props.variant === "raw");
28
+ const badgeVariant = computed(() => (props.variant === "raw" ? undefined : props.variant));
29
+ </script>
30
+
31
+ <template>
32
+ <RouterLink
33
+ v-if="hasTarget"
34
+ v-bind="$attrs"
35
+ :to="target"
36
+ data-slot="route"
37
+ :class="cn('inline-flex min-w-0 items-center', isRaw ? 'underline underline-offset-2' : '', props.class)"
38
+ >
39
+ <Badge v-if="!isRaw" as="span" :variant="badgeVariant" class="min-w-0">
40
+ <slot><EmptyValue /></slot>
41
+ </Badge>
42
+ <slot v-else><EmptyValue /></slot>
43
+ </RouterLink>
44
+ <span
45
+ v-else
46
+ v-bind="$attrs"
47
+ data-slot="route"
48
+ :class="cn('text-muted-foreground inline-flex min-w-0 items-center', props.class)"
49
+ >
50
+ <slot><EmptyValue /></slot>
51
+ </span>
52
+ </template>
@@ -0,0 +1,106 @@
1
+ <!-- eslint-disable vue/multi-word-component-names -->
2
+ <script setup lang="ts">
3
+ import type { HTMLAttributes } from "vue";
4
+ import { computed, ref } from "vue";
5
+ import { cn } from "cn";
6
+ import { RotateCcw } from "@lucide/vue";
7
+ import { CopyBtn, EmptyValue, Icon, IconBtn, Text, VSeparator } from "../base";
8
+ import { Spinner } from "../../ui/spinner";
9
+
10
+ defineOptions({ name: "Token", inheritAttrs: false });
11
+
12
+ const props = withDefaults(
13
+ defineProps<{
14
+ value: string;
15
+ copy?: boolean;
16
+ suffix?: number;
17
+ prefix?: number;
18
+ onRotate?: () => Promise<unknown>;
19
+ copyLabel?: string;
20
+ copiedText?: string;
21
+ copyFailedText?: string;
22
+ rotateLabel?: string;
23
+ rotatingLabel?: string;
24
+ retryLabel?: string;
25
+ rotateErrorText?: string;
26
+ class?: HTMLAttributes["class"];
27
+ }>(),
28
+ {
29
+ copy: true,
30
+ suffix: 4,
31
+ prefix: 0,
32
+ onRotate: undefined,
33
+ copyLabel: "复制令牌",
34
+ copiedText: "已复制",
35
+ copyFailedText: "复制失败",
36
+ rotateLabel: "轮换令牌",
37
+ rotatingLabel: "正在轮换令牌",
38
+ retryLabel: "重试轮换令牌",
39
+ rotateErrorText: "轮换失败",
40
+ class: undefined,
41
+ },
42
+ );
43
+
44
+ const rotating = ref(false);
45
+ const rotateError = ref("");
46
+
47
+ const masked = computed(() => {
48
+ const value = props.value ?? "";
49
+ if (!value) return "";
50
+ const prefixLength = Math.max(props.prefix, 0);
51
+ const suffixLength = Math.max(props.suffix, 0);
52
+ // 长度不超过前后缀之和时全部遮罩,避免把完整值直接暴露出去。
53
+ if (value.length <= prefixLength + suffixLength) return "•".repeat(value.length);
54
+ const head = value.slice(0, prefixLength);
55
+ const tail = suffixLength > 0 ? value.slice(-suffixLength) : "";
56
+ return `${head}${"•".repeat(value.length - prefixLength - suffixLength)}${tail}`;
57
+ });
58
+
59
+ const rotate = async () => {
60
+ if (!props.onRotate || rotating.value) return;
61
+ rotating.value = true;
62
+ rotateError.value = "";
63
+ try {
64
+ await props.onRotate();
65
+ } catch (error) {
66
+ rotateError.value =
67
+ error instanceof Error && error.message ? `${props.rotateErrorText}:${error.message}` : props.rotateErrorText;
68
+ } finally {
69
+ rotating.value = false;
70
+ }
71
+ };
72
+
73
+ const rotateAriaLabel = computed(() => {
74
+ if (rotateError.value) return props.retryLabel;
75
+ return rotating.value ? props.rotatingLabel : props.rotateLabel;
76
+ });
77
+ </script>
78
+
79
+ <template>
80
+ <span v-bind="$attrs" data-slot="token" :class="cn('inline-flex min-w-0 items-center gap-1', props.class)">
81
+ <Text v-if="value" variant="inlineCode" class="truncate text-xs">{{ masked }}</Text>
82
+ <EmptyValue v-else />
83
+ <template v-if="(copy && value) || onRotate">
84
+ <VSeparator />
85
+ <CopyBtn
86
+ v-if="copy && value"
87
+ :value="value"
88
+ :label="copyLabel"
89
+ :copied-text="copiedText"
90
+ :failed-text="copyFailedText"
91
+ />
92
+ <IconBtn
93
+ v-if="onRotate"
94
+ :aria-label="rotateAriaLabel"
95
+ :disabled="rotating"
96
+ size="icon-xs"
97
+ class="shrink-0"
98
+ @click="rotate"
99
+ >
100
+ <Spinner v-if="rotating" aria-hidden="true" />
101
+ <Icon v-else :icon="RotateCcw" />
102
+ </IconBtn>
103
+ </template>
104
+ <span v-if="rotateError" role="alert" class="text-destructive text-xs break-all">{{ rotateError }}</span>
105
+ </span>
106
+ </template>
@@ -0,0 +1,46 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from "vue";
3
+ import { computed } from "vue";
4
+ import { cn } from "cn";
5
+ import { CopyBtn, EmptyValue, Text, VSeparator } from "../base";
6
+
7
+ defineOptions({ name: "UUID", inheritAttrs: false });
8
+
9
+ const props = withDefaults(
10
+ defineProps<{
11
+ value: string;
12
+ copy?: boolean;
13
+ short?: number;
14
+ copyLabel?: string;
15
+ copiedText?: string;
16
+ copyFailedText?: string;
17
+ class?: HTMLAttributes["class"];
18
+ }>(),
19
+ {
20
+ copy: true,
21
+ short: 12,
22
+ copyLabel: "复制 UUID",
23
+ copiedText: "已复制",
24
+ copyFailedText: "复制失败",
25
+ class: undefined,
26
+ },
27
+ );
28
+
29
+ // 主键是 UUIDv7(时间有序),同一批次 ID 的时间前缀几乎相同、尾部熵最高;
30
+ // 默认只展示末 12 位以便区分,复制时仍复制完整值。
31
+ const shortened = computed(() => {
32
+ const size = Math.max(props.short, 0);
33
+ return size === 0 ? props.value : props.value.slice(-size);
34
+ });
35
+ </script>
36
+
37
+ <template>
38
+ <span v-bind="$attrs" data-slot="uuid" :class="cn('inline-flex min-w-0 items-center gap-1', props.class)">
39
+ <Text v-if="value" variant="inlineCode" class="truncate text-xs" :title="value">{{ shortened }}</Text>
40
+ <EmptyValue v-else />
41
+ <template v-if="value && copy">
42
+ <VSeparator />
43
+ <CopyBtn :value="value" :label="copyLabel" :copied-text="copiedText" :failed-text="copyFailedText" />
44
+ </template>
45
+ </span>
46
+ </template>
@@ -0,0 +1,17 @@
1
+ export { DataView, DataItem } from "./DataView.ts";
2
+
3
+ export { default as DateFormatter } from "./DateFormatter.vue";
4
+ export { default as Disclosure } from "./Disclosure.vue";
5
+ export { default as MultiLine } from "./MultiLine.vue";
6
+
7
+ export { default as Link } from "./Link.vue";
8
+ export { default as Pem } from "./Pem.vue";
9
+ export { default as Route } from "./Route.vue";
10
+
11
+ export { default as AsyncError } from "./AsyncError.vue";
12
+ export { default as CodeBlock } from "./CodeBlock.vue";
13
+ export { default as CopyTag } from "./CopyTag.vue";
14
+ export { default as Notice } from "./Notice.vue";
15
+ export { default as QrBtn } from "./QrBtn.vue";
16
+ export { default as Token } from "./Token.vue";
17
+ export { default as UUID } from "./UUID.vue";
@@ -0,0 +1,100 @@
1
+ /**
2
+ * PEM parsing utilities — pure logic, no DOM/Vue dependencies.
3
+ */
4
+
5
+ export type PemEncode = "hex" | "hex16" | "base64";
6
+
7
+ export interface PemBlock {
8
+ label: string;
9
+ raw: string;
10
+ }
11
+
12
+ /**
13
+ * Split a (possibly multi-block) PEM string into individual blocks.
14
+ * Each block retains its full PEM text including headers/footers.
15
+ */
16
+ export function parsePemBlocks(pem: string): PemBlock[] {
17
+ if (!pem?.includes("-----BEGIN ")) return [];
18
+ const re = /(-----BEGIN [^-]+-----[\s\S]*?-----END [^-]+-----)/g;
19
+ const blocks: PemBlock[] = [];
20
+ let m: RegExpExecArray | null;
21
+ while ((m = re.exec(pem)) !== null) {
22
+ const raw = (m[1] ?? "").trim();
23
+ if (!raw) continue;
24
+ const label = raw.match(/-----BEGIN ([^-]+)-----/)?.[1] ?? "";
25
+ blocks.push({ label, raw });
26
+ }
27
+ return blocks;
28
+ }
29
+
30
+ /**
31
+ * Strip PEM headers/footers and whitespace, returning the raw base64 body.
32
+ * Returns "" if the input contains no valid PEM block.
33
+ */
34
+ export function parsePemBody(pem: string): string {
35
+ if (!pem.includes("-----BEGIN ")) return "";
36
+ return pem.replace(/-----[^-]+-----/g, "").replace(/\s+/g, "");
37
+ }
38
+
39
+ /**
40
+ * Decode a PEM string into its raw binary bytes.
41
+ * Returns an empty Uint8Array if the input has no valid base64 body.
42
+ */
43
+ export function pemToBytes(pem: string): Uint8Array {
44
+ const body = parsePemBody(pem);
45
+ if (!body) return new Uint8Array(0);
46
+ const raw = atob(body);
47
+ const bytes = new Uint8Array(raw.length);
48
+ for (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);
49
+ return bytes;
50
+ }
51
+
52
+ const toHex = (buf: ArrayBuffer) =>
53
+ Array.from(new Uint8Array(buf))
54
+ .map((b) => b.toString(16).padStart(2, "0"))
55
+ .join(":");
56
+
57
+ const toHex16 = (buf: ArrayBuffer) => {
58
+ const hex = Array.from(new Uint8Array(buf))
59
+ .map((b) => b.toString(16).padStart(2, "0"))
60
+ .join("");
61
+ const tail = hex.slice(-16);
62
+ return tail.replace(/(.{4})/g, "$1 ").trim();
63
+ };
64
+
65
+ const toBase64 = (buf: ArrayBuffer) => btoa(String.fromCharCode(...new Uint8Array(buf)));
66
+
67
+ /**
68
+ * Compute the SHA-256 fingerprint of a single PEM string.
69
+ *
70
+ * @param encode Output format (default "base64"):
71
+ * - "hex" — "xx:xx:xx:..." colon-separated hex
72
+ * - "hex16" — last 16 hex chars, space-separated every 4
73
+ * - "base64" — standard base64 of the raw hash
74
+ * Returns "" for empty input.
75
+ */
76
+ export async function pemFingerprint(pem: string, encode: PemEncode = "base64"): Promise<string> {
77
+ const bytes = pemToBytes(pem);
78
+ if (bytes.length === 0) return "";
79
+ const hash = await crypto.subtle.digest("SHA-256", bytes.buffer as ArrayBuffer);
80
+ if (encode === "hex") return toHex(hash);
81
+ if (encode === "hex16") return toHex16(hash);
82
+ return toBase64(hash);
83
+ }
84
+
85
+ /**
86
+ * Compute SHA-256 fingerprints for each PEM block in a (possibly multi-block) string.
87
+ * Returns one entry per block: { label, fingerprint }.
88
+ */
89
+ export async function pemFingerprints(
90
+ pem: string,
91
+ encode: PemEncode = "base64",
92
+ ): Promise<{ label: string; fingerprint: string }[]> {
93
+ const blocks = parsePemBlocks(pem);
94
+ return Promise.all(
95
+ blocks.map(async (b) => ({
96
+ label: b.label,
97
+ fingerprint: await pemFingerprint(b.raw, encode),
98
+ })),
99
+ );
100
+ }
@@ -0,0 +1,20 @@
1
+ /** 异步 modal 没有成功挂载时,先结束打开流程,再把错误交给触发器旁 UI。 */
2
+ export const failModalLoad = (
3
+ error: Error,
4
+ fail: () => void,
5
+ destroy: () => void,
6
+ onError: (error: unknown) => void,
7
+ ) => {
8
+ onError(error);
9
+ fail();
10
+ destroy();
11
+ };
12
+
13
+ /** modal.open 拒绝没有 modal 内渲染位置,把错误交给触发器旁的局部 UI。 */
14
+ export const captureModalOpenError = async (open: () => Promise<unknown>, onError: (error: unknown) => void) => {
15
+ try {
16
+ await open();
17
+ } catch (error) {
18
+ onError(error);
19
+ }
20
+ };
@@ -0,0 +1,253 @@
1
+ <script setup lang="ts" generic="T">
2
+ import { computed, ref, useId, watch, type HTMLAttributes } from "vue";
3
+ import { Pencil, SquareCheck, Trash2 } from "@lucide/vue";
4
+ import type { AsyncStatus } from "@geektr.cloud/acrux-core";
5
+ import { Icon, IconBtn, Text } from "../base";
6
+ import { Input } from "../../ui/input";
7
+ import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover";
8
+ import { Skeleton } from "../../ui/skeleton";
9
+ import { cn } from "cn";
10
+ import FieldError from "./FieldError.vue";
11
+ import { useFieldAccessibility } from "./fieldAccessibility";
12
+
13
+ defineOptions({ name: "EntitySelect", inheritAttrs: false });
14
+
15
+ const props = withDefaults(
16
+ defineProps<{
17
+ items: T[];
18
+ status?: AsyncStatus;
19
+ preFilterFn?: (item: T) => boolean;
20
+ transformFn: (item: T) => { id: string; searchText: string; title: string; summary?: string };
21
+ placeholder?: string;
22
+ editable?: boolean;
23
+ cleanupEnabled?: boolean;
24
+ searchLabel?: string;
25
+ searchPlaceholder?: string;
26
+ selectAllText?: string;
27
+ cleanupText?: string;
28
+ emptyText?: string;
29
+ errorText?: string;
30
+ class?: HTMLAttributes["class"];
31
+ }>(),
32
+ {
33
+ preFilterFn: undefined,
34
+ status: () => ({ loading: false, error: null }),
35
+ placeholder: "未选择",
36
+ editable: true,
37
+ cleanupEnabled: true,
38
+ searchLabel: "搜索候选项",
39
+ searchPlaceholder: "搜索…",
40
+ selectAllText: "全选当前结果",
41
+ cleanupText: "清理失效项",
42
+ emptyText: "无匹配结果",
43
+ errorText: "加载候选项失败",
44
+ class: undefined,
45
+ },
46
+ );
47
+
48
+ const model = defineModel<string[]>({ default: () => [] });
49
+
50
+ const search = ref("");
51
+ const open = ref(false);
52
+ const searchId = `${useId()}-search`;
53
+ const { controlAttrs, rootAttrs, errorId, describedBy } = useFieldAccessibility(() => props.status.error);
54
+
55
+ const loading = computed(() => props.status.loading);
56
+ const hasItems = computed(() => props.items.length > 0);
57
+
58
+ const transformedAll = computed(() => props.items.map((item) => ({ item, ...props.transformFn(item) })));
59
+ const transformed = computed(() =>
60
+ props.preFilterFn ? transformedAll.value.filter((entry) => props.preFilterFn?.(entry.item)) : transformedAll.value,
61
+ );
62
+
63
+ const filtered = computed(() => {
64
+ const term = search.value.trim().toLowerCase();
65
+ if (!term) return transformed.value;
66
+ return transformed.value.filter((entry) => entry.searchText.toLowerCase().includes(term));
67
+ });
68
+
69
+ // Stale means absent from the full item set, not merely hidden by search or preFilterFn.
70
+ const knownIds = computed(() => new Set(transformedAll.value.map((entry) => entry.id)));
71
+ const staleIds = computed(() => model.value.filter((id) => !knownIds.value.has(id)));
72
+
73
+ const selectedSet = computed(() => new Set(model.value));
74
+ const labelById = computed(() => new Map(transformedAll.value.map((entry) => [entry.id, entry.title])));
75
+ const selectedEntries = computed(() =>
76
+ model.value.map((id) => ({ id, label: labelById.value.get(id) || id.slice(0, 8) })),
77
+ );
78
+
79
+ const showCleanup = computed(
80
+ () => props.editable && props.cleanupEnabled && !props.status.error && staleIds.value.length > 0,
81
+ );
82
+
83
+ const toggle = (id: string) => {
84
+ const next = new Set(model.value);
85
+ if (next.has(id)) next.delete(id);
86
+ else next.add(id);
87
+ model.value = [...next];
88
+ };
89
+
90
+ const selectAll = () => {
91
+ const next = new Set(model.value);
92
+ for (const entry of filtered.value) next.add(entry.id);
93
+ model.value = [...next];
94
+ };
95
+
96
+ const cleanupStale = () => {
97
+ model.value = model.value.filter((id) => knownIds.value.has(id));
98
+ };
99
+
100
+ // A closed popover should not keep a stale search term for the next open.
101
+ watch(open, (isOpen) => {
102
+ if (!isOpen) search.value = "";
103
+ });
104
+
105
+ // The popover is not rendered without items; reset its transient state so it reopens clean.
106
+ watch(hasItems, (value) => {
107
+ if (value) return;
108
+ open.value = false;
109
+ search.value = "";
110
+ });
111
+ </script>
112
+
113
+ <template>
114
+ <div data-slot="entity-select" :class="cn('min-w-0 flex-1', props.class)" v-bind="rootAttrs">
115
+ <Skeleton v-if="loading" class="h-7 w-full" />
116
+ <template v-else>
117
+ <div
118
+ v-if="!editable"
119
+ data-slot="entity-select-readonly"
120
+ role="group"
121
+ v-bind="controlAttrs"
122
+ :aria-describedby="describedBy"
123
+ class="flex max-h-[3.25rem] w-full min-w-0 flex-wrap items-center gap-1 overflow-y-auto"
124
+ >
125
+ <template v-if="selectedEntries.length">
126
+ <span
127
+ v-for="entry in selectedEntries"
128
+ :key="entry.id"
129
+ class="block max-w-full min-w-0 truncate rounded-none bg-muted px-1.5 py-0.5 text-xs text-foreground"
130
+ >
131
+ {{ entry.label }}
132
+ </span>
133
+ </template>
134
+ <span v-else class="text-xs text-muted-foreground">{{ placeholder }}</span>
135
+ </div>
136
+ <div
137
+ v-else-if="!hasItems"
138
+ data-slot="entity-select-static"
139
+ role="group"
140
+ v-bind="controlAttrs"
141
+ :aria-describedby="describedBy"
142
+ class="flex max-h-[3.25rem] min-h-7 w-full min-w-0 flex-wrap items-center gap-1 overflow-y-auto rounded-none border border-input bg-transparent px-1.5 py-0.5 text-left text-xs opacity-60"
143
+ >
144
+ <template v-if="selectedEntries.length">
145
+ <span
146
+ v-for="entry in selectedEntries"
147
+ :key="entry.id"
148
+ class="block max-w-full min-w-0 truncate rounded-none bg-muted px-1.5 py-0.5 text-xs text-foreground"
149
+ >
150
+ {{ entry.label }}
151
+ </span>
152
+ </template>
153
+ <span v-else class="text-xs text-muted-foreground">{{ placeholder }}</span>
154
+ </div>
155
+ <Popover v-else v-model:open="open">
156
+ <PopoverTrigger as-child>
157
+ <button
158
+ type="button"
159
+ data-slot="entity-select-trigger"
160
+ v-bind="controlAttrs"
161
+ :aria-describedby="describedBy"
162
+ class="flex max-h-[3.25rem] min-h-7 w-full min-w-0 flex-wrap items-center gap-1 overflow-y-auto rounded-none border border-input bg-transparent px-1.5 py-0.5 text-left text-xs transition-colors outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50"
163
+ >
164
+ <template v-if="selectedEntries.length">
165
+ <span
166
+ v-for="entry in selectedEntries"
167
+ :key="entry.id"
168
+ class="block max-w-full min-w-0 truncate rounded-none bg-muted px-1.5 py-0.5 text-xs text-foreground"
169
+ >
170
+ {{ entry.label }}
171
+ </span>
172
+ </template>
173
+ <span v-else class="text-xs text-muted-foreground">{{ placeholder }}</span>
174
+ <Icon :icon="Pencil" size="xs" class="text-muted-foreground" aria-hidden="true" />
175
+ </button>
176
+ </PopoverTrigger>
177
+ <PopoverContent
178
+ align="start"
179
+ side="bottom"
180
+ class="flex max-h-80 w-80 max-w-[calc(100vw_-_2rem)] flex-col overflow-hidden"
181
+ >
182
+ <div class="flex items-center gap-1">
183
+ <label :for="searchId" class="sr-only">{{ searchLabel }}</label>
184
+ <Input
185
+ :id="searchId"
186
+ v-model="search"
187
+ class="h-6 min-w-0 flex-1 text-xs"
188
+ :placeholder="searchPlaceholder"
189
+ />
190
+ <IconBtn
191
+ :icon="SquareCheck"
192
+ type="button"
193
+ size="icon-xs"
194
+ class="shrink-0"
195
+ :aria-label="selectAllText"
196
+ :title="selectAllText"
197
+ :disabled="filtered.length === 0"
198
+ @click="selectAll"
199
+ />
200
+ </div>
201
+ <div class="min-h-0 flex-1 overflow-y-auto">
202
+ <Text
203
+ v-if="filtered.length === 0"
204
+ variant="muted"
205
+ data-slot="entity-select-empty"
206
+ class="px-1 py-3 text-center text-xs text-muted-foreground"
207
+ >
208
+ {{ emptyText }}
209
+ </Text>
210
+ <label
211
+ v-for="entry in filtered"
212
+ :key="entry.id"
213
+ data-slot="entity-select-option"
214
+ class="flex min-h-6 min-w-0 cursor-pointer items-start gap-2 px-1 py-1 text-left hover:bg-accent"
215
+ >
216
+ <input
217
+ type="checkbox"
218
+ class="mt-0.5 size-3.5 shrink-0 cursor-pointer rounded-none accent-primary"
219
+ :checked="selectedSet.has(entry.id)"
220
+ @change="toggle(entry.id)"
221
+ />
222
+ <span class="flex min-w-0 flex-col">
223
+ <span class="truncate text-xs">{{ entry.title }}</span>
224
+ <span v-if="entry.summary" class="truncate text-xs text-muted-foreground">{{ entry.summary }}</span>
225
+ </span>
226
+ </label>
227
+ </div>
228
+ </PopoverContent>
229
+ </Popover>
230
+ <Text
231
+ v-if="!hasItems && !status.error"
232
+ variant="muted"
233
+ data-slot="entity-select-no-items"
234
+ class="mt-1 text-xs text-muted-foreground"
235
+ >
236
+ {{ emptyText }}
237
+ </Text>
238
+ <button
239
+ v-if="showCleanup"
240
+ type="button"
241
+ data-slot="entity-select-cleanup"
242
+ class="mt-1 inline-flex min-h-6 items-center gap-0.5 text-xs text-destructive hover:underline"
243
+ @click="cleanupStale"
244
+ >
245
+ <Icon :icon="Trash2" size="xs" aria-hidden="true" />
246
+ {{ cleanupText }}
247
+ </button>
248
+ </template>
249
+ <FieldError v-if="status.error" :id="errorId" data-slot="entity-select-error" class="mt-1">
250
+ {{ errorText }}
251
+ </FieldError>
252
+ </div>
253
+ </template>
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ import { Text } from "../base";
3
+
4
+ defineOptions({ name: "FieldError", inheritAttrs: false });
5
+ </script>
6
+
7
+ <template>
8
+ <Text v-bind="$attrs" role="alert" class="text-destructive text-xs">
9
+ <slot />
10
+ </Text>
11
+ </template>