@geektr.cloud/acrux-ui 0.2.0 → 0.3.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geektr.cloud/acrux-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "有明确主张的 Vue 应用组件层与 shadcn 基础原语,同时提供源码包入口与 shadcn-vue registry。",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"qrcode": "^1.5.4",
|
|
45
45
|
"reka-ui": "^2.12.0",
|
|
46
46
|
"shiki": "^4.6.0",
|
|
47
|
-
"@geektr.cloud/acrux-core": "0.
|
|
47
|
+
"@geektr.cloud/acrux-core": "0.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@vitejs/plugin-vue": "^6.0.11",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"vue-final-modal": "^5.0.1",
|
|
58
58
|
"vue-router": "^5.5.3",
|
|
59
59
|
"vue-tsc": "3.3.13",
|
|
60
|
-
"@geektr.cloud/acrux-eslint-config": "0.
|
|
60
|
+
"@geektr.cloud/acrux-eslint-config": "0.3.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"vue": "^3.5.46",
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Component, ComputedOptions, MethodOptions } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { defineComponent, h, nextTick, onUnmounted, ref, useId } from "vue";
|
|
3
3
|
import { useModal, VueFinalModal } from "vue-final-modal";
|
|
4
4
|
import { Card, CardContent } from "../../ui/card";
|
|
5
|
-
import {
|
|
6
|
-
import { AsyncError } from "../display";
|
|
5
|
+
import { defineAsyncView } from "../display";
|
|
7
6
|
|
|
8
7
|
/** 表单组件必须接收的 id(undefined 表示新建)。 */
|
|
9
8
|
export interface FormModelProps {
|
|
@@ -43,38 +42,11 @@ export interface UseFormModelOptions {
|
|
|
43
42
|
export const useFormModel = (loader: FormModelLoader, options: UseFormModelOptions = {}) => {
|
|
44
43
|
const id = ref<string>();
|
|
45
44
|
const titleId = `acrux-form-title-${useId()}`;
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
defineAsyncComponent({
|
|
52
|
-
loader: async () => (await loader()).default,
|
|
53
|
-
delay: 0,
|
|
54
|
-
loadingComponent: defineComponent({
|
|
55
|
-
name: "FormModelLoading",
|
|
56
|
-
inheritAttrs: false,
|
|
57
|
-
setup() {
|
|
58
|
-
return () => h(Text, { variant: "muted", role: "status", class: "py-4" }, loadingText());
|
|
59
|
-
},
|
|
60
|
-
}),
|
|
61
|
-
errorComponent: defineComponent({
|
|
62
|
-
name: "FormModelError",
|
|
63
|
-
inheritAttrs: false,
|
|
64
|
-
props: { error: { type: null, required: true } },
|
|
65
|
-
setup(props) {
|
|
66
|
-
return () =>
|
|
67
|
-
h(AsyncError, {
|
|
68
|
-
error: props.error,
|
|
69
|
-
title: errorText(),
|
|
70
|
-
retryLabel: retryLabel(),
|
|
71
|
-
onRetry: asyncRetry.retry,
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
}),
|
|
75
|
-
onError: asyncRetry.onError,
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
45
|
+
const AsyncForm = defineAsyncView(loader, {
|
|
46
|
+
loadingText: options.loadingText ?? "表单加载中…",
|
|
47
|
+
errorText: options.errorText ?? "表单加载失败",
|
|
48
|
+
retryLabel: options.retryLabel ?? "重试",
|
|
49
|
+
});
|
|
78
50
|
|
|
79
51
|
const component = defineComponent({
|
|
80
52
|
setup() {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Component } from "vue";
|
|
2
|
+
import { defineAsyncComponent, defineComponent, h } from "vue";
|
|
3
|
+
import { createAsyncLoaderRetry, Text } from "../base";
|
|
4
|
+
import AsyncError from "./AsyncError.vue";
|
|
5
|
+
|
|
6
|
+
export interface AsyncViewOptions {
|
|
7
|
+
loadingText?: string;
|
|
8
|
+
errorText?: string;
|
|
9
|
+
retryLabel?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type AsyncViewLoader<T extends Component> = () => Promise<{ default: T }>;
|
|
13
|
+
|
|
14
|
+
/** 为动态视图提供一致的加载状态、局部错误和仅重跑 loader 的重试。 */
|
|
15
|
+
export const defineAsyncView = <T extends Component>(loader: AsyncViewLoader<T>, options: AsyncViewOptions = {}): T => {
|
|
16
|
+
const asyncRetry = createAsyncLoaderRetry();
|
|
17
|
+
const component = defineAsyncComponent({
|
|
18
|
+
loader: async () => (await loader()).default,
|
|
19
|
+
delay: 0,
|
|
20
|
+
loadingComponent: defineComponent({
|
|
21
|
+
name: "AsyncViewLoading",
|
|
22
|
+
inheritAttrs: false,
|
|
23
|
+
setup() {
|
|
24
|
+
return () =>
|
|
25
|
+
h(
|
|
26
|
+
Text,
|
|
27
|
+
{ variant: "muted", role: "status", class: "py-4" },
|
|
28
|
+
{ default: () => options.loadingText ?? "加载中…" },
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
errorComponent: defineComponent({
|
|
33
|
+
name: "AsyncViewError",
|
|
34
|
+
inheritAttrs: false,
|
|
35
|
+
props: { error: { type: null, required: true } },
|
|
36
|
+
setup(props) {
|
|
37
|
+
return () =>
|
|
38
|
+
h(AsyncError, {
|
|
39
|
+
error: props.error,
|
|
40
|
+
title: options.errorText ?? "加载失败",
|
|
41
|
+
retryLabel: options.retryLabel ?? "重试",
|
|
42
|
+
onRetry: asyncRetry.retry,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
onError: asyncRetry.onError,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return asyncRetry.withRetryBoundary(component) as T;
|
|
50
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { DataView, DataItem } from "./DataView.ts";
|
|
2
|
+
export { defineAsyncView, type AsyncViewLoader, type AsyncViewOptions } from "./asyncView.ts";
|
|
2
3
|
export { registerCodeLanguage, type CodeLanguageLoader } from "./code-languages.ts";
|
|
3
4
|
|
|
4
5
|
export { default as DateFormatter } from "./DateFormatter.vue";
|
|
@@ -49,7 +49,7 @@ function update(event: Event) {
|
|
|
49
49
|
:data-selected="selected ? 'true' : undefined"
|
|
50
50
|
:class="
|
|
51
51
|
cn(
|
|
52
|
-
'choice-item h-6 cursor-pointer border-input/40 px-3 py-1 leading-none text-muted-foreground hover:border-input hover:text-foreground',
|
|
52
|
+
'choice-item relative h-6 cursor-pointer border-input/40 px-3 py-1 leading-none text-muted-foreground hover:border-input hover:text-foreground',
|
|
53
53
|
disabled && 'pointer-events-none cursor-not-allowed opacity-50',
|
|
54
54
|
props.class,
|
|
55
55
|
)
|
|
@@ -65,7 +65,12 @@ function update(event: Event) {
|
|
|
65
65
|
:disabled="disabled"
|
|
66
66
|
@change="update"
|
|
67
67
|
/>
|
|
68
|
-
<Icon
|
|
68
|
+
<Icon
|
|
69
|
+
v-if="selected"
|
|
70
|
+
:icon="Check"
|
|
71
|
+
size="xs"
|
|
72
|
+
class="pointer-events-none absolute -top-1 -right-1 bg-primary text-primary-foreground"
|
|
73
|
+
/>
|
|
69
74
|
<slot :selected="selected" :disabled="disabled" :multiple="multiple">
|
|
70
75
|
<span v-if="label">{{ label }}</span>
|
|
71
76
|
<span v-if="description" class="font-normal text-muted-foreground">· {{ description }}</span>
|