@composy/store-vue 0.0.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.
- package/README.md +154 -0
- package/dist/index.js +1536 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +1008 -0
- package/dist/index.min.js.map +1 -0
- package/es/composables/defineSetupStore.d.ts +120 -0
- package/es/composables/defineSetupStore.d.ts.map +1 -0
- package/es/composables/defineSetupStore.js +29 -0
- package/es/composables/defineSetupStore.js.map +1 -0
- package/es/composables/index.d.ts +24 -0
- package/es/composables/index.d.ts.map +1 -0
- package/es/composables/index.js +21 -0
- package/es/composables/useFormStore.d.ts +131 -0
- package/es/composables/useFormStore.d.ts.map +1 -0
- package/es/composables/useFormStore.js +189 -0
- package/es/composables/useFormStore.js.map +1 -0
- package/es/composables/useOptimistic.d.ts +67 -0
- package/es/composables/useOptimistic.d.ts.map +1 -0
- package/es/composables/useOptimistic.js +64 -0
- package/es/composables/useOptimistic.js.map +1 -0
- package/es/composables/usePersist.d.ts +68 -0
- package/es/composables/usePersist.d.ts.map +1 -0
- package/es/composables/usePersist.js +96 -0
- package/es/composables/usePersist.js.map +1 -0
- package/es/composables/usePersistedState.d.ts +59 -0
- package/es/composables/usePersistedState.d.ts.map +1 -0
- package/es/composables/usePersistedState.js +121 -0
- package/es/composables/usePersistedState.js.map +1 -0
- package/es/composables/useSharedState.d.ts +62 -0
- package/es/composables/useSharedState.d.ts.map +1 -0
- package/es/composables/useSharedState.js +94 -0
- package/es/composables/useSharedState.js.map +1 -0
- package/es/composables/useStore.d.ts +99 -0
- package/es/composables/useStore.d.ts.map +1 -0
- package/es/composables/useStore.js +61 -0
- package/es/composables/useStore.js.map +1 -0
- package/es/composables/useStoreDevtools.d.ts +31 -0
- package/es/composables/useStoreDevtools.d.ts.map +1 -0
- package/es/composables/useStoreDevtools.js +112 -0
- package/es/composables/useStoreDevtools.js.map +1 -0
- package/es/composables/useStoreSnapshot.d.ts +122 -0
- package/es/composables/useStoreSnapshot.d.ts.map +1 -0
- package/es/composables/useStoreSnapshot.js +209 -0
- package/es/composables/useStoreSnapshot.js.map +1 -0
- package/es/composables/useSubscribe.d.ts +90 -0
- package/es/composables/useSubscribe.d.ts.map +1 -0
- package/es/composables/useSubscribe.js +53 -0
- package/es/composables/useSubscribe.js.map +1 -0
- package/es/context/injection-keys.d.ts +8 -0
- package/es/context/injection-keys.d.ts.map +1 -0
- package/es/context/injection-keys.js +17 -0
- package/es/context/injection-keys.js.map +1 -0
- package/es/index.d.ts +24 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +32 -0
- package/es/index.js.map +1 -0
- package/es/plugins/engine-plugin.d.ts +36 -0
- package/es/plugins/engine-plugin.d.ts.map +1 -0
- package/es/plugins/engine-plugin.js +83 -0
- package/es/plugins/engine-plugin.js.map +1 -0
- package/es/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/es/plugins/enhanced-persist-plugin.d.ts.map +1 -0
- package/es/plugins/enhanced-persist-plugin.js +12 -0
- package/es/plugins/index.d.ts +7 -0
- package/es/plugins/index.d.ts.map +1 -0
- package/es/plugins/index.js +15 -0
- package/es/plugins/pinia-plugin.d.ts +68 -0
- package/es/plugins/pinia-plugin.d.ts.map +1 -0
- package/es/plugins/pinia-plugin.js +172 -0
- package/es/plugins/pinia-plugin.js.map +1 -0
- package/es/plugins/registry-plugin.d.ts +2 -0
- package/es/plugins/registry-plugin.d.ts.map +1 -0
- package/es/plugins/registry-plugin.js +12 -0
- package/es/plugins/vue-plugin.d.ts +10 -0
- package/es/plugins/vue-plugin.d.ts.map +1 -0
- package/es/plugins/vue-plugin.js +24 -0
- package/es/plugins/vue-plugin.js.map +1 -0
- package/es/runtime/install-store-app.d.ts +23 -0
- package/es/runtime/install-store-app.d.ts.map +1 -0
- package/es/runtime/install-store-app.js +54 -0
- package/es/runtime/install-store-app.js.map +1 -0
- package/es/runtime/store-plugin-options.d.ts +40 -0
- package/es/runtime/store-plugin-options.d.ts.map +1 -0
- package/es/runtime/store-plugin-options.js +24 -0
- package/es/runtime/store-plugin-options.js.map +1 -0
- package/es/runtime/store-registry.d.ts +64 -0
- package/es/runtime/store-registry.d.ts.map +1 -0
- package/es/runtime/store-registry.js +102 -0
- package/es/runtime/store-registry.js.map +1 -0
- package/es/runtime/store-runtime.d.ts +46 -0
- package/es/runtime/store-runtime.d.ts.map +1 -0
- package/es/runtime/store-runtime.js +58 -0
- package/es/runtime/store-runtime.js.map +1 -0
- package/es/types.d.ts +167 -0
- package/es/types.d.ts.map +1 -0
- package/es/types.js +10 -0
- package/esm/composables/defineSetupStore.d.ts +120 -0
- package/esm/composables/defineSetupStore.d.ts.map +1 -0
- package/esm/composables/defineSetupStore.js +29 -0
- package/esm/composables/defineSetupStore.js.map +1 -0
- package/esm/composables/index.d.ts +24 -0
- package/esm/composables/index.d.ts.map +1 -0
- package/esm/composables/index.js +21 -0
- package/esm/composables/useFormStore.d.ts +131 -0
- package/esm/composables/useFormStore.d.ts.map +1 -0
- package/esm/composables/useFormStore.js +189 -0
- package/esm/composables/useFormStore.js.map +1 -0
- package/esm/composables/useOptimistic.d.ts +67 -0
- package/esm/composables/useOptimistic.d.ts.map +1 -0
- package/esm/composables/useOptimistic.js +64 -0
- package/esm/composables/useOptimistic.js.map +1 -0
- package/esm/composables/usePersist.d.ts +68 -0
- package/esm/composables/usePersist.d.ts.map +1 -0
- package/esm/composables/usePersist.js +96 -0
- package/esm/composables/usePersist.js.map +1 -0
- package/esm/composables/usePersistedState.d.ts +59 -0
- package/esm/composables/usePersistedState.d.ts.map +1 -0
- package/esm/composables/usePersistedState.js +121 -0
- package/esm/composables/usePersistedState.js.map +1 -0
- package/esm/composables/useSharedState.d.ts +62 -0
- package/esm/composables/useSharedState.d.ts.map +1 -0
- package/esm/composables/useSharedState.js +94 -0
- package/esm/composables/useSharedState.js.map +1 -0
- package/esm/composables/useStore.d.ts +99 -0
- package/esm/composables/useStore.d.ts.map +1 -0
- package/esm/composables/useStore.js +61 -0
- package/esm/composables/useStore.js.map +1 -0
- package/esm/composables/useStoreDevtools.d.ts +31 -0
- package/esm/composables/useStoreDevtools.d.ts.map +1 -0
- package/esm/composables/useStoreDevtools.js +112 -0
- package/esm/composables/useStoreDevtools.js.map +1 -0
- package/esm/composables/useStoreSnapshot.d.ts +122 -0
- package/esm/composables/useStoreSnapshot.d.ts.map +1 -0
- package/esm/composables/useStoreSnapshot.js +209 -0
- package/esm/composables/useStoreSnapshot.js.map +1 -0
- package/esm/composables/useSubscribe.d.ts +90 -0
- package/esm/composables/useSubscribe.d.ts.map +1 -0
- package/esm/composables/useSubscribe.js +53 -0
- package/esm/composables/useSubscribe.js.map +1 -0
- package/esm/context/injection-keys.d.ts +8 -0
- package/esm/context/injection-keys.d.ts.map +1 -0
- package/esm/context/injection-keys.js +17 -0
- package/esm/context/injection-keys.js.map +1 -0
- package/esm/index.d.ts +24 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +34 -0
- package/esm/index.js.map +1 -0
- package/esm/plugins/engine-plugin.d.ts +36 -0
- package/esm/plugins/engine-plugin.d.ts.map +1 -0
- package/esm/plugins/engine-plugin.js +83 -0
- package/esm/plugins/engine-plugin.js.map +1 -0
- package/esm/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/esm/plugins/enhanced-persist-plugin.d.ts.map +1 -0
- package/esm/plugins/enhanced-persist-plugin.js +12 -0
- package/esm/plugins/index.d.ts +7 -0
- package/esm/plugins/index.d.ts.map +1 -0
- package/esm/plugins/index.js +16 -0
- package/esm/plugins/pinia-plugin.d.ts +68 -0
- package/esm/plugins/pinia-plugin.d.ts.map +1 -0
- package/esm/plugins/pinia-plugin.js +172 -0
- package/esm/plugins/pinia-plugin.js.map +1 -0
- package/esm/plugins/registry-plugin.d.ts +2 -0
- package/esm/plugins/registry-plugin.d.ts.map +1 -0
- package/esm/plugins/registry-plugin.js +12 -0
- package/esm/plugins/vue-plugin.d.ts +10 -0
- package/esm/plugins/vue-plugin.d.ts.map +1 -0
- package/esm/plugins/vue-plugin.js +24 -0
- package/esm/plugins/vue-plugin.js.map +1 -0
- package/esm/runtime/install-store-app.d.ts +23 -0
- package/esm/runtime/install-store-app.d.ts.map +1 -0
- package/esm/runtime/install-store-app.js +54 -0
- package/esm/runtime/install-store-app.js.map +1 -0
- package/esm/runtime/store-plugin-options.d.ts +40 -0
- package/esm/runtime/store-plugin-options.d.ts.map +1 -0
- package/esm/runtime/store-plugin-options.js +24 -0
- package/esm/runtime/store-plugin-options.js.map +1 -0
- package/esm/runtime/store-registry.d.ts +64 -0
- package/esm/runtime/store-registry.d.ts.map +1 -0
- package/esm/runtime/store-registry.js +94 -0
- package/esm/runtime/store-registry.js.map +1 -0
- package/esm/runtime/store-runtime.d.ts +46 -0
- package/esm/runtime/store-runtime.d.ts.map +1 -0
- package/esm/runtime/store-runtime.js +58 -0
- package/esm/runtime/store-runtime.js.map +1 -0
- package/esm/types.d.ts +167 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +10 -0
- package/lib/composables/defineSetupStore.cjs +33 -0
- package/lib/composables/defineSetupStore.cjs.map +1 -0
- package/lib/composables/defineSetupStore.d.ts +120 -0
- package/lib/composables/index.cjs +46 -0
- package/lib/composables/index.d.ts +24 -0
- package/lib/composables/useFormStore.cjs +197 -0
- package/lib/composables/useFormStore.cjs.map +1 -0
- package/lib/composables/useFormStore.d.ts +131 -0
- package/lib/composables/useOptimistic.cjs +66 -0
- package/lib/composables/useOptimistic.cjs.map +1 -0
- package/lib/composables/useOptimistic.d.ts +67 -0
- package/lib/composables/usePersist.cjs +100 -0
- package/lib/composables/usePersist.cjs.map +1 -0
- package/lib/composables/usePersist.d.ts +68 -0
- package/lib/composables/usePersistedState.cjs +123 -0
- package/lib/composables/usePersistedState.cjs.map +1 -0
- package/lib/composables/usePersistedState.d.ts +59 -0
- package/lib/composables/useSharedState.cjs +96 -0
- package/lib/composables/useSharedState.cjs.map +1 -0
- package/lib/composables/useSharedState.d.ts +62 -0
- package/lib/composables/useStore.cjs +65 -0
- package/lib/composables/useStore.cjs.map +1 -0
- package/lib/composables/useStore.d.ts +99 -0
- package/lib/composables/useStoreDevtools.cjs +114 -0
- package/lib/composables/useStoreDevtools.cjs.map +1 -0
- package/lib/composables/useStoreDevtools.d.ts +31 -0
- package/lib/composables/useStoreSnapshot.cjs +211 -0
- package/lib/composables/useStoreSnapshot.cjs.map +1 -0
- package/lib/composables/useStoreSnapshot.d.ts +122 -0
- package/lib/composables/useSubscribe.cjs +57 -0
- package/lib/composables/useSubscribe.cjs.map +1 -0
- package/lib/composables/useSubscribe.d.ts +90 -0
- package/lib/context/injection-keys.cjs +21 -0
- package/lib/context/injection-keys.cjs.map +1 -0
- package/lib/context/injection-keys.d.ts +8 -0
- package/lib/index.cjs +235 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +24 -0
- package/lib/package.json +3 -0
- package/lib/plugins/engine-plugin.cjs +90 -0
- package/lib/plugins/engine-plugin.cjs.map +1 -0
- package/lib/plugins/engine-plugin.d.ts +36 -0
- package/lib/plugins/enhanced-persist-plugin.cjs +15 -0
- package/lib/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/lib/plugins/index.cjs +28 -0
- package/lib/plugins/index.d.ts +7 -0
- package/lib/plugins/pinia-plugin.cjs +177 -0
- package/lib/plugins/pinia-plugin.cjs.map +1 -0
- package/lib/plugins/pinia-plugin.d.ts +68 -0
- package/lib/plugins/registry-plugin.cjs +18 -0
- package/lib/plugins/registry-plugin.d.ts +2 -0
- package/lib/plugins/vue-plugin.cjs +26 -0
- package/lib/plugins/vue-plugin.cjs.map +1 -0
- package/lib/plugins/vue-plugin.d.ts +10 -0
- package/lib/runtime/install-store-app.cjs +57 -0
- package/lib/runtime/install-store-app.cjs.map +1 -0
- package/lib/runtime/install-store-app.d.ts +23 -0
- package/lib/runtime/store-plugin-options.cjs +26 -0
- package/lib/runtime/store-plugin-options.cjs.map +1 -0
- package/lib/runtime/store-plugin-options.d.ts +40 -0
- package/lib/runtime/store-registry.cjs +108 -0
- package/lib/runtime/store-registry.cjs.map +1 -0
- package/lib/runtime/store-registry.d.ts +64 -0
- package/lib/runtime/store-runtime.cjs +62 -0
- package/lib/runtime/store-runtime.cjs.map +1 -0
- package/lib/runtime/store-runtime.d.ts +46 -0
- package/lib/types.cjs +12 -0
- package/lib/types.d.ts +167 -0
- package/package.json +115 -0
package/es/types.d.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Pinia } from 'pinia';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* Store 基础配置选项
|
|
5
|
+
* @property persist - 持久化配置,true 使用默认配置,或传入 PersistOptions 对象
|
|
6
|
+
* @property devtools - 是否启用 Vue DevTools 支持
|
|
7
|
+
* @property strict - 是否启用严格模式(如 Pinia 的 $patch 严格检查)
|
|
8
|
+
*/
|
|
9
|
+
export interface StoreOptions {
|
|
10
|
+
persist?: boolean | PersistOptions;
|
|
11
|
+
devtools?: boolean;
|
|
12
|
+
strict?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 持久化配置选项
|
|
16
|
+
* 控制 Pinia Store 状态如何被保存到浏览器存储
|
|
17
|
+
* @property key - 自定义存储键名(默认使用 store.$id)
|
|
18
|
+
* @property storage - 存储类型:'localStorage' 或 'sessionStorage'
|
|
19
|
+
* @property paths - 只持久化指定路径的状态(白名单模式)
|
|
20
|
+
* @property excludePaths - 排除指定路径不持久化(黑名单模式)
|
|
21
|
+
* @property debounce - 防抖延迟(毫秒),避免频繁写入
|
|
22
|
+
* @property syncTabs - 是否跨标签页同步状态
|
|
23
|
+
* @property ttl - 存活时间(毫秒),过期后自动清除
|
|
24
|
+
* @property serializer - 自定义序列化/反序列化函数
|
|
25
|
+
* @property beforeRestore - 恢复前钩子
|
|
26
|
+
* @property afterRestore - 恢复后钩子
|
|
27
|
+
*/
|
|
28
|
+
export interface PersistOptions {
|
|
29
|
+
key?: string;
|
|
30
|
+
storage?: 'localStorage' | 'sessionStorage';
|
|
31
|
+
paths?: string[];
|
|
32
|
+
excludePaths?: string[];
|
|
33
|
+
debounce?: number;
|
|
34
|
+
syncTabs?: boolean;
|
|
35
|
+
ttl?: number;
|
|
36
|
+
serializer?: {
|
|
37
|
+
serialize: (value: unknown) => string;
|
|
38
|
+
deserialize: (value: string) => unknown;
|
|
39
|
+
};
|
|
40
|
+
beforeRestore?: (context: {
|
|
41
|
+
store: unknown;
|
|
42
|
+
}) => void;
|
|
43
|
+
afterRestore?: (context: {
|
|
44
|
+
store: unknown;
|
|
45
|
+
}) => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Store Engine 插件配置选项
|
|
49
|
+
* 控制 Store 引擎插件的行为
|
|
50
|
+
* @property name - 插件名称
|
|
51
|
+
* @property version - 插件版本
|
|
52
|
+
* @property dependencies - 依赖的其他插件列表
|
|
53
|
+
* @property persist - 是否启用持久化
|
|
54
|
+
* @property persistOptions - 持久化配置选项
|
|
55
|
+
* @property devtools - 是否启用 DevTools
|
|
56
|
+
* @property debug - 是否开启调试日志
|
|
57
|
+
* @property globalProperties - 是否挂载到 app.config.globalProperties
|
|
58
|
+
* @property provide - 是否通过 Vue provide/inject 注入
|
|
59
|
+
* @property pinia - 外部传入的 Pinia 实例(可选,不传则自动创建)
|
|
60
|
+
*/
|
|
61
|
+
export interface StoreEnginePluginOptions {
|
|
62
|
+
name?: string;
|
|
63
|
+
version?: string;
|
|
64
|
+
dependencies?: string[];
|
|
65
|
+
persist?: boolean;
|
|
66
|
+
persistOptions?: PersistOptions;
|
|
67
|
+
devtools?: boolean;
|
|
68
|
+
debug?: boolean;
|
|
69
|
+
globalProperties?: boolean;
|
|
70
|
+
provide?: boolean;
|
|
71
|
+
pinia?: Pinia;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* useStore 返回值接口
|
|
75
|
+
* 提供响应式状态和常用操作方法
|
|
76
|
+
* @property state - 响应式状态引用
|
|
77
|
+
* @property reset - 重置状态到初始值
|
|
78
|
+
* @property patch - 部分更新状态(支持对象或函数)
|
|
79
|
+
* @property store - 底层 Pinia Store 实例
|
|
80
|
+
*/
|
|
81
|
+
export interface UseStoreReturn<S = unknown> {
|
|
82
|
+
state: Ref<S>;
|
|
83
|
+
reset: () => void;
|
|
84
|
+
patch: (partial: Partial<S> | ((state: S) => void)) => void;
|
|
85
|
+
store: unknown;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* usePersist 配置选项
|
|
89
|
+
* 简化版的持久化选项,用于 composable 场景
|
|
90
|
+
* @property key - 存储键名
|
|
91
|
+
* @property storage - 存储类型
|
|
92
|
+
* @property defaultValue - 默认值
|
|
93
|
+
* @property serialize - 自定义序列化函数
|
|
94
|
+
* @property deserialize - 自定义反序列化函数
|
|
95
|
+
*/
|
|
96
|
+
export interface UsePersistOptions {
|
|
97
|
+
key: string;
|
|
98
|
+
storage?: 'localStorage' | 'sessionStorage';
|
|
99
|
+
defaultValue?: unknown;
|
|
100
|
+
serialize?: (value: unknown) => string;
|
|
101
|
+
deserialize?: (value: string) => unknown;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* usePersist 返回值接口
|
|
105
|
+
* @property value - 持久化的响应式引用
|
|
106
|
+
* @property save - 手动保存
|
|
107
|
+
* @property restore - 从存储恢复
|
|
108
|
+
* @property clear - 清除存储
|
|
109
|
+
*/
|
|
110
|
+
export interface UsePersistReturn<T> {
|
|
111
|
+
value: Ref<T>;
|
|
112
|
+
save: () => void;
|
|
113
|
+
restore: () => void;
|
|
114
|
+
clear: () => void;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 订阅选项接口
|
|
118
|
+
* 控制 Store 订阅行为
|
|
119
|
+
* @property immediate - 是否立即触发一次回调
|
|
120
|
+
* @property deep - 是否深度监听
|
|
121
|
+
* @property detached - 是否脱离当前组件生命周期(组件卸载后继续监听)
|
|
122
|
+
*/
|
|
123
|
+
export interface SubscribeOptions {
|
|
124
|
+
immediate?: boolean;
|
|
125
|
+
deep?: boolean;
|
|
126
|
+
detached?: boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 变更信息接口
|
|
130
|
+
* 描述 Store 状态变更的详细信息
|
|
131
|
+
* @property type - 变更类型:'direct'(直接赋值)、'patch object'(对象补丁)、'patch function'(函数补丁)
|
|
132
|
+
* @property storeId - Store ID
|
|
133
|
+
* @property events - 触发的事件列表
|
|
134
|
+
* @property oldState - 变更前的状态(部分)
|
|
135
|
+
*/
|
|
136
|
+
export interface MutationInfo<S = unknown> {
|
|
137
|
+
type: 'direct' | 'patch object' | 'patch function';
|
|
138
|
+
storeId: string;
|
|
139
|
+
events?: string[];
|
|
140
|
+
oldState?: Partial<S>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Store Provider 组件 Props
|
|
144
|
+
* @property pinia - Pinia 实例
|
|
145
|
+
* @property children - 子组件(React 风格,Vue 中较少使用)
|
|
146
|
+
*/
|
|
147
|
+
export interface StoreProviderProps {
|
|
148
|
+
pinia?: Pinia;
|
|
149
|
+
children?: unknown;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 全局 Store API 接口
|
|
153
|
+
* 提供只读的 Store 查询和管理能力
|
|
154
|
+
* @property pinia - Pinia 实例引用
|
|
155
|
+
* @property getStore - 获取指定 ID 的 Store
|
|
156
|
+
* @property hasStore - 检查 Store 是否存在
|
|
157
|
+
* @property getStoreIds - 获取所有已注册的 Store ID
|
|
158
|
+
* @property resetAll - 重置所有 Store 到初始状态
|
|
159
|
+
*/
|
|
160
|
+
export interface GlobalStoreAPI {
|
|
161
|
+
pinia: Pinia;
|
|
162
|
+
getStore: <T>(id: string) => T | undefined;
|
|
163
|
+
hasStore: (id: string) => boolean;
|
|
164
|
+
getStoreIds: () => string[];
|
|
165
|
+
resetAll: () => void;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 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;;;;;;GAOG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,IAAI,EAAE,QAAQ,GAAG,cAAc,GAAG,gBAAgB,CAAA;IAClD,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,KAAK,CAAA;IACZ,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,CAAA;IAC1C,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAA;IACjC,WAAW,EAAE,MAAM,MAAM,EAAE,CAAA;IAC3B,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB"}
|
package/es/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/store-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:39:29 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* defineSetupStore - Setup 风格 Store 定义助手
|
|
3
|
+
*
|
|
4
|
+
* 提供更简洁的 composition API 风格来定义 Pinia Store。
|
|
5
|
+
* 本质是对 defineStore 的 setup 语法的薄封装,增加类型推断和开发体验。
|
|
6
|
+
*
|
|
7
|
+
* @module composables/defineSetupStore
|
|
8
|
+
*/
|
|
9
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
10
|
+
/**
|
|
11
|
+
* defineSetupStore - 使用 Composition API 风格定义 Store
|
|
12
|
+
*
|
|
13
|
+
* 与 defineStore 的 setup 语法等价,但提供更清晰的语义。
|
|
14
|
+
* 适合喜欢 Composition API 风格的开发者。
|
|
15
|
+
*
|
|
16
|
+
* @param id - Store 唯一标识
|
|
17
|
+
* @param setup - Setup 函数(在函数内使用 ref、computed、普通函数来定义 state、getters、actions)
|
|
18
|
+
* @returns Pinia Store 定义
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { defineSetupStore } from '@composy/store-vue'
|
|
23
|
+
* import { ref, computed } from 'vue'
|
|
24
|
+
*
|
|
25
|
+
* // Setup 风格定义(推荐)
|
|
26
|
+
* export const useCounterStore = defineSetupStore('counter', () => {
|
|
27
|
+
* // state(使用 ref)
|
|
28
|
+
* const count = ref(0)
|
|
29
|
+
* const step = ref(1)
|
|
30
|
+
*
|
|
31
|
+
* // getters(使用 computed)
|
|
32
|
+
* const doubleCount = computed(() => count.value * 2)
|
|
33
|
+
* const isPositive = computed(() => count.value > 0)
|
|
34
|
+
*
|
|
35
|
+
* // actions(普通函数)
|
|
36
|
+
* function increment() {
|
|
37
|
+
* count.value += step.value
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* function decrement() {
|
|
41
|
+
* count.value -= step.value
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* async function fetchCount(id: string) {
|
|
45
|
+
* const res = await fetch(`/api/count/${id}`)
|
|
46
|
+
* count.value = await res.json()
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* function reset() {
|
|
50
|
+
* count.value = 0
|
|
51
|
+
* step.value = 1
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* return {
|
|
55
|
+
* count, step,
|
|
56
|
+
* doubleCount, isPositive,
|
|
57
|
+
* increment, decrement, fetchCount, reset,
|
|
58
|
+
* }
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function defineSetupStore<T>(id: string, setup: () => T): import("pinia").StoreDefinition<string, import("pinia")._ExtractStateFromSetupStore<T>, import("pinia")._ExtractGettersFromSetupStore<T>, import("pinia")._ExtractActionsFromSetupStore<T>>;
|
|
63
|
+
/**
|
|
64
|
+
* createStoreState - 创建带有类型推断的 Store State
|
|
65
|
+
*
|
|
66
|
+
* 工具函数,帮助在 setup store 中快速创建多个 ref 状态。
|
|
67
|
+
*
|
|
68
|
+
* @param initial - 初始状态对象
|
|
69
|
+
* @returns 以 ref 包装的响应式状态对象
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const useUserStore = defineSetupStore('user', () => {
|
|
74
|
+
* const state = createStoreState({
|
|
75
|
+
* name: '张三',
|
|
76
|
+
* age: 25,
|
|
77
|
+
* email: '',
|
|
78
|
+
* })
|
|
79
|
+
*
|
|
80
|
+
* // state.name 是 Ref<string>
|
|
81
|
+
* // state.age 是 Ref<number>
|
|
82
|
+
*
|
|
83
|
+
* function updateName(name: string) {
|
|
84
|
+
* state.name.value = name
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* return { ...state, updateName }
|
|
88
|
+
* })
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function createStoreState<T extends Record<string, unknown>>(initial: T): {
|
|
92
|
+
[K in keyof T]: Ref<T[K]>;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* createStoreGetters - 创建带有类型推断的 Store Getters
|
|
96
|
+
*
|
|
97
|
+
* 工具函数,帮助在 setup store 中快速创建多个 computed getter。
|
|
98
|
+
*
|
|
99
|
+
* @param getters - getter 函数映射
|
|
100
|
+
* @returns 以 computed 包装的响应式 getter 对象
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const useUserStore = defineSetupStore('user', () => {
|
|
105
|
+
* const name = ref('张三')
|
|
106
|
+
* const age = ref(25)
|
|
107
|
+
*
|
|
108
|
+
* const getters = createStoreGetters({
|
|
109
|
+
* displayName: () => `${name.value} (${age.value}岁)`,
|
|
110
|
+
* isAdult: () => age.value >= 18,
|
|
111
|
+
* })
|
|
112
|
+
*
|
|
113
|
+
* return { name, age, ...getters }
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function createStoreGetters<T extends Record<string, () => unknown>>(getters: T): {
|
|
118
|
+
[K in keyof T]: ComputedRef<ReturnType<T[K]>>;
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=defineSetupStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineSetupStore.d.ts","sourceRoot":"","sources":["../../src/composables/defineSetupStore.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAE,GAAG,EAAC,MAAM,KAAK,CAAC;AAI1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,CAAC,+LAGf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,OAAO,EAAE,CAAC,GACT;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAM/B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,EACxE,OAAO,EAAE,CAAC,GACT;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAMnD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/store-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:39:29 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import { defineStore } from "pinia";
|
|
11
|
+
import { computed, ref } from "vue";
|
|
12
|
+
//#region src/composables/defineSetupStore.ts
|
|
13
|
+
function defineSetupStore(id, setup) {
|
|
14
|
+
return defineStore(id, setup);
|
|
15
|
+
}
|
|
16
|
+
function createStoreState(initial) {
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const key of Object.keys(initial)) result[key] = ref(initial[key]);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function createStoreGetters(getters) {
|
|
22
|
+
const result = {};
|
|
23
|
+
for (const key of Object.keys(getters)) result[key] = computed(getters[key]);
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createStoreGetters, createStoreState, defineSetupStore };
|
|
28
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
29
|
+
//# sourceMappingURL=defineSetupStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineSetupStore.js","names":[],"sources":["../../src/composables/defineSetupStore.ts"],"sourcesContent":["/**\n * defineSetupStore - Setup 风格 Store 定义助手\n *\n * 提供更简洁的 composition API 风格来定义 Pinia Store。\n * 本质是对 defineStore 的 setup 语法的薄封装,增加类型推断和开发体验。\n *\n * @module composables/defineSetupStore\n */\n\nimport type {ComputedRef, Ref} from 'vue';\nimport { defineStore } from 'pinia'\nimport { computed, ref } from 'vue'\n\n/**\n * defineSetupStore - 使用 Composition API 风格定义 Store\n *\n * 与 defineStore 的 setup 语法等价,但提供更清晰的语义。\n * 适合喜欢 Composition API 风格的开发者。\n *\n * @param id - Store 唯一标识\n * @param setup - Setup 函数(在函数内使用 ref、computed、普通函数来定义 state、getters、actions)\n * @returns Pinia Store 定义\n *\n * @example\n * ```typescript\n * import { defineSetupStore } from '@composy/store-vue'\n * import { ref, computed } from 'vue'\n *\n * // Setup 风格定义(推荐)\n * export const useCounterStore = defineSetupStore('counter', () => {\n * // state(使用 ref)\n * const count = ref(0)\n * const step = ref(1)\n *\n * // getters(使用 computed)\n * const doubleCount = computed(() => count.value * 2)\n * const isPositive = computed(() => count.value > 0)\n *\n * // actions(普通函数)\n * function increment() {\n * count.value += step.value\n * }\n *\n * function decrement() {\n * count.value -= step.value\n * }\n *\n * async function fetchCount(id: string) {\n * const res = await fetch(`/api/count/${id}`)\n * count.value = await res.json()\n * }\n *\n * function reset() {\n * count.value = 0\n * step.value = 1\n * }\n *\n * return {\n * count, step,\n * doubleCount, isPositive,\n * increment, decrement, fetchCount, reset,\n * }\n * })\n * ```\n */\nexport function defineSetupStore<T>(\n id: string,\n setup: () => T,\n) {\n return defineStore(id, setup)\n}\n\n/**\n * createStoreState - 创建带有类型推断的 Store State\n *\n * 工具函数,帮助在 setup store 中快速创建多个 ref 状态。\n *\n * @param initial - 初始状态对象\n * @returns 以 ref 包装的响应式状态对象\n *\n * @example\n * ```typescript\n * const useUserStore = defineSetupStore('user', () => {\n * const state = createStoreState({\n * name: '张三',\n * age: 25,\n * email: '',\n * })\n *\n * // state.name 是 Ref<string>\n * // state.age 是 Ref<number>\n *\n * function updateName(name: string) {\n * state.name.value = name\n * }\n *\n * return { ...state, updateName }\n * })\n * ```\n */\nexport function createStoreState<T extends Record<string, unknown>>(\n initial: T,\n): { [K in keyof T]: Ref<T[K]> } {\n const result = {} as { [K in keyof T]: Ref<T[K]> }\n for (const key of Object.keys(initial) as Array<keyof T>) {\n result[key] = ref(initial[key]) as Ref<T[typeof key]>\n }\n return result\n}\n\n/**\n * createStoreGetters - 创建带有类型推断的 Store Getters\n *\n * 工具函数,帮助在 setup store 中快速创建多个 computed getter。\n *\n * @param getters - getter 函数映射\n * @returns 以 computed 包装的响应式 getter 对象\n *\n * @example\n * ```typescript\n * const useUserStore = defineSetupStore('user', () => {\n * const name = ref('张三')\n * const age = ref(25)\n *\n * const getters = createStoreGetters({\n * displayName: () => `${name.value} (${age.value}岁)`,\n * isAdult: () => age.value >= 18,\n * })\n *\n * return { name, age, ...getters }\n * })\n * ```\n */\nexport function createStoreGetters<T extends Record<string, () => unknown>>(\n getters: T,\n): { [K in keyof T]: ComputedRef<ReturnType<T[K]>> } {\n const result = {} as { [K in keyof T]: ComputedRef<ReturnType<T[K]>> }\n for (const key of Object.keys(getters) as Array<keyof T>) {\n result[key] = computed(getters[key]) as ComputedRef<ReturnType<T[typeof key]>>\n }\n return result\n}\n"],"mappings":";;;;;;;;;;;;AAiEO,SAAS,iBACd,IACA,OACA;CACA,OAAO,YAAY,IAAI,KAAK;AAC9B;AA8BO,SAAS,iBACd,SAC+B;CAC/B,MAAM,SAAS,CAAC;CAChB,KAAA,MAAW,OAAO,OAAO,KAAK,OAAO,GACnC,OAAO,OAAO,IAAI,QAAQ,IAAI;CAEhC,OAAO;AACT;AAyBO,SAAS,mBACd,SACmD;CACnD,MAAM,SAAS,CAAC;CAChB,KAAA,MAAW,OAAO,OAAO,KAAK,OAAO,GACnC,OAAO,OAAO,SAAS,QAAQ,IAAI;CAErC,OAAO;AACT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composables 模块导出
|
|
3
|
+
*
|
|
4
|
+
* 提供 Vue 3 组合式 API 的 Store 工具函数
|
|
5
|
+
* @module composables
|
|
6
|
+
*/
|
|
7
|
+
export { createStoreGetters, createStoreState, defineSetupStore, } from './defineSetupStore';
|
|
8
|
+
export { email, maxLength, minLength, numberRange, pattern, required, useFormStore, } from './useFormStore';
|
|
9
|
+
export type { FormFieldRules, FormFieldState, FormValidator, UseFormStoreOptions, UseFormStoreReturn, } from './useFormStore';
|
|
10
|
+
export { useOptimistic, } from './useOptimistic';
|
|
11
|
+
export type { OptimisticEntry, UseOptimisticReturn, } from './useOptimistic';
|
|
12
|
+
export { usePersist, usePersistedRef, usePersistedRefWithTTL, } from './usePersist';
|
|
13
|
+
export { usePersistedState, } from './usePersistedState';
|
|
14
|
+
export type { PersistedStateOptions, PersistedStateReturn, } from './usePersistedState';
|
|
15
|
+
export { useSharedState, } from './useSharedState';
|
|
16
|
+
export type { UseSharedStateOptions, UseSharedStateReturn, } from './useSharedState';
|
|
17
|
+
export { useComputedStore, useSimpleStore, useStore, } from './useStore';
|
|
18
|
+
export { useStoreDevtools, } from './useStoreDevtools';
|
|
19
|
+
export type { EventLogEntry, StoreInfo, UseStoreDevtoolsReturn, } from './useStoreDevtools';
|
|
20
|
+
export { useStoreSnapshot, } from './useStoreSnapshot';
|
|
21
|
+
export type { StateDiff, StateSnapshot, UseStoreSnapshotOptions, UseStoreSnapshotReturn, } from './useStoreSnapshot';
|
|
22
|
+
export { useOnAction, useSubscribe, useWatch, } from './useSubscribe';
|
|
23
|
+
export type { ActionContext } from './useSubscribe';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composables/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,KAAK,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,QAAQ,EACR,YAAY,GACb,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EACV,cAAc,EACd,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,aAAa,GACd,MAAM,iBAAiB,CAAA;AAExB,YAAY,EACV,eAAe,EACf,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EACL,UAAU,EACV,eAAe,EACf,sBAAsB,GACvB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,iBAAiB,GAClB,MAAM,qBAAqB,CAAA;AAE5B,YAAY,EACV,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,cAAc,GACf,MAAM,kBAAkB,CAAA;AAEzB,YAAY,EACV,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,QAAQ,GACT,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,gBAAgB,GACjB,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EACV,aAAa,EACb,SAAS,EACT,sBAAsB,GACvB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,gBAAgB,GACjB,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EACV,SAAS,EACT,aAAa,EACb,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,QAAQ,GACT,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/store-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:39:29 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import { createStoreGetters, createStoreState, defineSetupStore } from "./defineSetupStore.js";
|
|
11
|
+
import { email, maxLength, minLength, numberRange, pattern, required, useFormStore } from "./useFormStore.js";
|
|
12
|
+
import { useOptimistic } from "./useOptimistic.js";
|
|
13
|
+
import { usePersist, usePersistedRef, usePersistedRefWithTTL } from "./usePersist.js";
|
|
14
|
+
import { usePersistedState } from "./usePersistedState.js";
|
|
15
|
+
import { useSharedState } from "./useSharedState.js";
|
|
16
|
+
import { useComputedStore, useSimpleStore, useStore } from "./useStore.js";
|
|
17
|
+
import { useStoreDevtools } from "./useStoreDevtools.js";
|
|
18
|
+
import { useStoreSnapshot } from "./useStoreSnapshot.js";
|
|
19
|
+
import { useOnAction, useSubscribe, useWatch } from "./useSubscribe.js";
|
|
20
|
+
export { createStoreGetters, createStoreState, defineSetupStore, email, maxLength, minLength, numberRange, pattern, required, useComputedStore, useFormStore, useOnAction, useOptimistic, usePersist, usePersistedRef, usePersistedRefWithTTL, usePersistedState, useSharedState, useSimpleStore, useStore, useStoreDevtools, useStoreSnapshot, useSubscribe, useWatch };
|
|
21
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* 表单校验器函数类型
|
|
4
|
+
* @param value - 当前字段值
|
|
5
|
+
* @param allValues - 表单所有字段的值(用于跨字段校验)
|
|
6
|
+
* @returns 校验错误信息或 null(无错误),支持异步校验
|
|
7
|
+
*/
|
|
8
|
+
export type FormValidator<T = unknown> = (value: T, allValues: Record<string, unknown>) => string | null | Promise<string | null>;
|
|
9
|
+
/**
|
|
10
|
+
* 字段校验规则接口
|
|
11
|
+
* @property required - 是否必填,可传 string 自定义提示
|
|
12
|
+
* @property rules - 自定义校验器数组,按顺序依次执行
|
|
13
|
+
*/
|
|
14
|
+
export interface FormFieldRules<T = unknown> {
|
|
15
|
+
required?: boolean | string;
|
|
16
|
+
rules?: FormValidator<T>[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* useFormStore 的配置选项接口
|
|
20
|
+
* @property initialValues - 表单初始值(必须提供完整对象)
|
|
21
|
+
* @property validationRules - 各字段的校验规则映射
|
|
22
|
+
* @property onSubmit - 表单提交回调(校验通过后调用)
|
|
23
|
+
* @property validateOn - 触发校验的时机:'blur' | 'change' | 'submit'
|
|
24
|
+
*/
|
|
25
|
+
export interface UseFormStoreOptions<T extends Record<string, unknown>> {
|
|
26
|
+
initialValues: T;
|
|
27
|
+
validationRules?: {
|
|
28
|
+
[K in keyof T]?: FormFieldRules<T[K]>;
|
|
29
|
+
};
|
|
30
|
+
onSubmit?: (values: T) => void | Promise<void>;
|
|
31
|
+
validateOn?: 'blur' | 'change' | 'submit';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 单个字段的状态接口
|
|
35
|
+
* @property touched - 字段是否被触碰过(获得过焦点或提交过)
|
|
36
|
+
* @property dirty - 字段值是否与初始值不同(被修改过)
|
|
37
|
+
* @property error - 当前校验错误信息,null 表示无错误
|
|
38
|
+
* @property validating - 字段是否正在异步校验中
|
|
39
|
+
*/
|
|
40
|
+
export interface FormFieldState {
|
|
41
|
+
touched: boolean;
|
|
42
|
+
dirty: boolean;
|
|
43
|
+
error: string | null;
|
|
44
|
+
validating: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* useFormStore 返回值接口
|
|
48
|
+
* @property values - 表单当前值(reactive 对象)
|
|
49
|
+
* @property fields - 各字段的状态映射
|
|
50
|
+
* @property isDirty - 是否有任意字段被修改过(计算属性)
|
|
51
|
+
* @property isValid - 是否所有字段都无校验错误(计算属性)
|
|
52
|
+
* @property isSubmitting - 表单是否正在提交中
|
|
53
|
+
* @property submitError - 提交失败的错误信息
|
|
54
|
+
* @property submitCount - 累计提交次数
|
|
55
|
+
* @property setFieldValue - 设置指定字段的值
|
|
56
|
+
* @property setFieldTouched - 标记字段为已触碰
|
|
57
|
+
* @property validateField - 校验单个字段(异步)
|
|
58
|
+
* @property validateAll - 校验所有字段(异步)
|
|
59
|
+
* @property handleSubmit - 提交表单
|
|
60
|
+
* @property reset - 重置整个表单(可传新的初始值)
|
|
61
|
+
* @property resetField - 重置单个字段
|
|
62
|
+
* @property errors - 所有字段错误信息的计算属性
|
|
63
|
+
*/
|
|
64
|
+
export interface UseFormStoreReturn<T extends Record<string, unknown>> {
|
|
65
|
+
values: T;
|
|
66
|
+
fields: Record<string, FormFieldState>;
|
|
67
|
+
isDirty: ComputedRef<boolean>;
|
|
68
|
+
isValid: ComputedRef<boolean>;
|
|
69
|
+
isSubmitting: Ref<boolean>;
|
|
70
|
+
submitError: Ref<string | null>;
|
|
71
|
+
submitCount: Ref<number>;
|
|
72
|
+
setFieldValue: <K extends keyof T>(field: K, value: T[K]) => void;
|
|
73
|
+
setFieldTouched: (field: keyof T) => void;
|
|
74
|
+
validateField: (field: keyof T) => Promise<string | null>;
|
|
75
|
+
validateAll: () => Promise<boolean>;
|
|
76
|
+
handleSubmit: () => Promise<void>;
|
|
77
|
+
reset: (newInitialValues?: Partial<T>) => void;
|
|
78
|
+
resetField: (field: keyof T) => void;
|
|
79
|
+
errors: ComputedRef<Record<string, string | null>>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 表单状态管理 Composable
|
|
83
|
+
* 提供完整的表单生命周期管理能力,包括值管理、字段状态追踪、校验、提交和重置
|
|
84
|
+
*
|
|
85
|
+
* @param options - 表单配置选项
|
|
86
|
+
* @returns 包含表单状态和操作方法的对象
|
|
87
|
+
*/
|
|
88
|
+
export declare function useFormStore<T extends Record<string, unknown>>(options: UseFormStoreOptions<T>): UseFormStoreReturn<T>;
|
|
89
|
+
/**
|
|
90
|
+
* 创建必填校验器
|
|
91
|
+
* @param message - 自定义错误提示,默认为 '此字段为必填项'
|
|
92
|
+
* @returns 校验器函数
|
|
93
|
+
*/
|
|
94
|
+
export declare function required(message?: string): FormValidator;
|
|
95
|
+
/**
|
|
96
|
+
* 创建最小长度校验器
|
|
97
|
+
* @param min - 最小字符数
|
|
98
|
+
* @param message - 自定义错误提示
|
|
99
|
+
* @returns 字符串校验器函数
|
|
100
|
+
*/
|
|
101
|
+
export declare function minLength(min: number, message?: string): FormValidator<string>;
|
|
102
|
+
/**
|
|
103
|
+
* 创建最大长度校验器
|
|
104
|
+
* @param max - 最大字符数
|
|
105
|
+
* @param message - 自定义错误提示
|
|
106
|
+
* @returns 字符串校验器函数
|
|
107
|
+
*/
|
|
108
|
+
export declare function maxLength(max: number, message?: string): FormValidator<string>;
|
|
109
|
+
/**
|
|
110
|
+
* 创建正则匹配校验器
|
|
111
|
+
* @param regex - 正则表达式
|
|
112
|
+
* @param message - 自定义错误提示,默认为 '格式不正确'
|
|
113
|
+
* @returns 字符串校验器函数
|
|
114
|
+
*/
|
|
115
|
+
export declare function pattern(regex: RegExp, message?: string): FormValidator<string>;
|
|
116
|
+
/**
|
|
117
|
+
* 创建邮箱格式校验器
|
|
118
|
+
* 基于内置的 EMAIL_PATTERN 正则
|
|
119
|
+
* @param message - 自定义错误提示,默认为 '邮箱格式不正确'
|
|
120
|
+
* @returns 字符串校验器函数
|
|
121
|
+
*/
|
|
122
|
+
export declare function email(message?: string): FormValidator<string>;
|
|
123
|
+
/**
|
|
124
|
+
* 创建数值范围校验器
|
|
125
|
+
* @param min - 最小值
|
|
126
|
+
* @param max - 最大值
|
|
127
|
+
* @param message - 自定义错误提示
|
|
128
|
+
* @returns 数字校验器函数
|
|
129
|
+
*/
|
|
130
|
+
export declare function numberRange(min: number, max: number, message?: string): FormValidator<number>;
|
|
131
|
+
//# sourceMappingURL=useFormStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormStore.d.ts","sourceRoot":"","sources":["../../src/composables/useFormStore.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAqB3C;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI,CACvC,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,MAAM,CAAC,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