@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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Pinia } from 'pinia';
|
|
2
|
+
import type { EnhancedPersistPluginOptions } from '../plugins/pinia-plugin';
|
|
3
|
+
/**
|
|
4
|
+
* store 运行时配置选项接口
|
|
5
|
+
* 用于配置 store 运行时的行为
|
|
6
|
+
*/
|
|
7
|
+
export interface StoreRuntimeOptions {
|
|
8
|
+
pinia?: Pinia;
|
|
9
|
+
persist?: boolean;
|
|
10
|
+
persistOptions?: EnhancedPersistPluginOptions;
|
|
11
|
+
globalProperties?: boolean;
|
|
12
|
+
provide?: boolean;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* store Vue 插件选项接口
|
|
17
|
+
* 继承自 StoreRuntimeOptions,当前无额外扩展
|
|
18
|
+
*/
|
|
19
|
+
export interface StoreVuePluginOptions extends StoreRuntimeOptions {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 解析后的 store 运行时选项接口
|
|
23
|
+
* 所有字段均已填充默认值,不再包含可选标记
|
|
24
|
+
*/
|
|
25
|
+
export interface ResolvedStoreRuntimeOptions {
|
|
26
|
+
pinia?: Pinia;
|
|
27
|
+
persist: boolean;
|
|
28
|
+
persistOptions: EnhancedPersistPluginOptions;
|
|
29
|
+
globalProperties: boolean;
|
|
30
|
+
provide: boolean;
|
|
31
|
+
debug: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 将用户传入的 store 运行时选项规范化为完整配置
|
|
35
|
+
* 为每个可选字段填充默认值
|
|
36
|
+
* @param options - 用户传入的配置选项
|
|
37
|
+
* @returns 规范化后的完整配置对象
|
|
38
|
+
*/
|
|
39
|
+
export declare function normalizeStoreRuntimeOptions(options?: StoreRuntimeOptions): ResolvedStoreRuntimeOptions;
|
|
40
|
+
//# sourceMappingURL=store-plugin-options.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
12
|
+
//#region src/runtime/store-registry.ts
|
|
13
|
+
const STORE_DISPOSE_PATCH_KEY = /* @__PURE__ */ Symbol("ldesign-store-registry-dispose");
|
|
14
|
+
function patchStoreDispose(store, unregister) {
|
|
15
|
+
const restorePatchedDispose = store[STORE_DISPOSE_PATCH_KEY];
|
|
16
|
+
if (restorePatchedDispose) restorePatchedDispose();
|
|
17
|
+
const originalDispose = store.$dispose;
|
|
18
|
+
store.$dispose = function patchedDispose() {
|
|
19
|
+
unregister(store.$id);
|
|
20
|
+
return originalDispose.call(this);
|
|
21
|
+
};
|
|
22
|
+
store[STORE_DISPOSE_PATCH_KEY] = () => {
|
|
23
|
+
store.$dispose = originalDispose;
|
|
24
|
+
delete store[STORE_DISPOSE_PATCH_KEY];
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createStoreRegistry() {
|
|
28
|
+
const stores = /* @__PURE__ */ new Map();
|
|
29
|
+
const unregister = (storeId) => {
|
|
30
|
+
stores.delete(storeId);
|
|
31
|
+
};
|
|
32
|
+
const register = (store) => {
|
|
33
|
+
stores.set(store.$id, store);
|
|
34
|
+
patchStoreDispose(store, unregister);
|
|
35
|
+
};
|
|
36
|
+
const hasStore = (storeId) => {
|
|
37
|
+
return stores.has(storeId);
|
|
38
|
+
};
|
|
39
|
+
const getStore = (storeId) => {
|
|
40
|
+
return stores.get(storeId);
|
|
41
|
+
};
|
|
42
|
+
const getStoreIds = () => {
|
|
43
|
+
return Array.from(stores.keys());
|
|
44
|
+
};
|
|
45
|
+
const resetAll = () => {
|
|
46
|
+
stores.forEach((store) => {
|
|
47
|
+
if (typeof store.$reset !== "function") return;
|
|
48
|
+
try {
|
|
49
|
+
store.$reset();
|
|
50
|
+
} catch {}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const clear = () => {
|
|
54
|
+
stores.clear();
|
|
55
|
+
};
|
|
56
|
+
const registerExistingStores = (pinia) => {
|
|
57
|
+
pinia._s?.forEach((store) => register(store));
|
|
58
|
+
};
|
|
59
|
+
const createStoreAPI = (pinia) => {
|
|
60
|
+
return {
|
|
61
|
+
pinia,
|
|
62
|
+
getStore,
|
|
63
|
+
hasStore,
|
|
64
|
+
getStoreIds,
|
|
65
|
+
resetAll
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
stores,
|
|
70
|
+
register,
|
|
71
|
+
unregister,
|
|
72
|
+
hasStore,
|
|
73
|
+
getStore,
|
|
74
|
+
getStoreIds,
|
|
75
|
+
resetAll,
|
|
76
|
+
clear,
|
|
77
|
+
registerExistingStores,
|
|
78
|
+
createStoreAPI
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
let globalRegistry = createStoreRegistry();
|
|
82
|
+
function setGlobalStoreRegistry(registry) {
|
|
83
|
+
globalRegistry = registry ?? createStoreRegistry();
|
|
84
|
+
}
|
|
85
|
+
function getStoreRegistry() {
|
|
86
|
+
return globalRegistry.stores;
|
|
87
|
+
}
|
|
88
|
+
function createRegistryMethods(registry = globalRegistry) {
|
|
89
|
+
return {
|
|
90
|
+
getStore: registry.getStore,
|
|
91
|
+
hasStore: registry.hasStore,
|
|
92
|
+
getStoreIds: registry.getStoreIds,
|
|
93
|
+
resetAll: registry.resetAll
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function createStoreRegistryPlugin(registry = globalRegistry) {
|
|
97
|
+
return ({ store }) => {
|
|
98
|
+
registry.register(store);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.createRegistryMethods = createRegistryMethods;
|
|
103
|
+
exports.createStoreRegistry = createStoreRegistry;
|
|
104
|
+
exports.createStoreRegistryPlugin = createStoreRegistryPlugin;
|
|
105
|
+
exports.getStoreRegistry = getStoreRegistry;
|
|
106
|
+
exports.setGlobalStoreRegistry = setGlobalStoreRegistry;
|
|
107
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
108
|
+
//# sourceMappingURL=store-registry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-registry.cjs","names":[],"sources":["../../src/runtime/store-registry.ts"],"sourcesContent":["/* ============================================================\n * store-registry.ts\n * Store 注册表模块\n * 管理所有活跃的 Pinia Store 实例,提供注册/注销/查询/重置能力\n * 通过 patch $dispose 方法实现 Store 销毁时自动注销\n * ============================================================ */\n\n/* 从 Pinia 导入类型 */\nimport type { Pinia, PiniaPluginContext, StoreGeneric } from 'pinia'\n/* 导入全局 Store API 类型 */\nimport type { GlobalStoreAPI } from '../types'\n\n/* 用于标记 store 的 $dispose 是否已被 patch 的 Symbol 键 */\nconst STORE_DISPOSE_PATCH_KEY = Symbol('ldesign-store-registry-dispose')\n\n/* 可被 patch $dispose 的 Store 扩展类型 */\ntype DisposableStore = StoreGeneric & {\n [STORE_DISPOSE_PATCH_KEY]?: () => void /* 恢复原始 $dispose 的函数 */\n}\n\n/* 扩展 Pinia 类型,访问内部的 _s(Store 实例映射) */\ntype PiniaWithStores = Pinia & {\n _s?: Map<string, StoreGeneric>\n}\n\n/**\n * Store 注册表接口\n * 提供对所有活跃 Store 的集中管理能力\n * @property stores - Store 实例映射(storeId → Store)\n * @property register - 注册一个 Store\n * @property unregister - 注销一个 Store\n * @property hasStore - 检查 Store 是否已注册\n * @property getStore - 获取指定 ID 的 Store\n * @property getStoreIds - 获取所有已注册的 Store ID\n * @property resetAll - 重置所有 Store 到初始状态\n * @property clear - 清空注册表(不重置 Store)\n * @property registerExistingStores - 从 Pinia 实例中批量注册已有的 Store\n * @property createStoreAPI - 创建全局 Store API 对象\n */\nexport interface StoreRegistry {\n readonly stores: Map<string, StoreGeneric>\n register: (store: StoreGeneric) => void\n unregister: (storeId: string) => void\n hasStore: (storeId: string) => boolean\n getStore: <T = unknown>(storeId: string) => T | undefined\n getStoreIds: () => string[]\n resetAll: () => void\n clear: () => void\n registerExistingStores: (pinia: Pinia) => void\n createStoreAPI: (pinia: Pinia) => GlobalStoreAPI\n}\n\n/**\n * 为 Store 的 $dispose 方法打补丁\n * 在 Store 被销毁时自动从注册表中注销\n * 确保注册表中的 Store 引用不会过期\n *\n * @param store - 目标 Store\n * @param unregister - 注销回调函数\n */\nfunction patchStoreDispose(store: DisposableStore, unregister: (storeId: string) => void): void {\n /* 如果之前已有补丁,先恢复原始方法 */\n const restorePatchedDispose = store[STORE_DISPOSE_PATCH_KEY]\n if (restorePatchedDispose) {\n restorePatchedDispose()\n }\n\n /* 保存原始 $dispose 方法 */\n const originalDispose = store.$dispose\n /* 替换为带注销逻辑的版本 */\n store.$dispose = function patchedDispose() {\n unregister(store.$id) /* 从注册表注销 */\n return originalDispose.call(this) /* 调用原始 dispose */\n }\n\n /* 保存恢复函数,供后续补丁使用 */\n store[STORE_DISPOSE_PATCH_KEY] = () => {\n store.$dispose = originalDispose\n delete store[STORE_DISPOSE_PATCH_KEY]\n }\n}\n\n/**\n * 创建 Store 注册表实例\n * @returns StoreRegistry 注册表对象\n */\nexport function createStoreRegistry(): StoreRegistry {\n /* Store 实例映射(storeId → Store) */\n const stores = new Map<string, StoreGeneric>()\n\n /**\n * 注销指定 ID 的 Store\n * @param storeId - Store ID\n */\n const unregister = (storeId: string): void => {\n stores.delete(storeId)\n }\n\n /**\n * 注册一个 Store\n * 同时为 $dispose 打补丁,确保销毁时自动注销\n * @param store - 要注册的 Store 实例\n */\n const register = (store: StoreGeneric): void => {\n stores.set(store.$id, store)\n patchStoreDispose(store as DisposableStore, unregister)\n }\n\n /**\n * 检查 Store 是否已注册\n * @param storeId - Store ID\n * @returns 是否已注册\n */\n const hasStore = (storeId: string): boolean => {\n return stores.has(storeId)\n }\n\n /**\n * 获取指定 ID 的 Store\n * @param storeId - Store ID\n * @returns Store 实例或 undefined\n */\n const getStore = <T = unknown>(storeId: string): T | undefined => {\n return stores.get(storeId) as T | undefined\n }\n\n /**\n * 获取所有已注册的 Store ID 列表\n * @returns Store ID 数组\n */\n const getStoreIds = (): string[] => {\n return Array.from(stores.keys())\n }\n\n /**\n * 重置所有 Store 到初始状态\n * 调用每个 Store 的 $reset() 方法\n * 注意:Setup stores 可能不支持 $reset\n */\n const resetAll = (): void => {\n stores.forEach((store) => {\n /* 检查是否有 $reset 方法 */\n if (typeof store.$reset !== 'function') {\n return\n }\n\n try {\n store.$reset()\n }\n catch {\n /* Setup stores 可能暴露了 $reset 但实际拒绝直接重置 */\n }\n })\n }\n\n /**\n * 清空注册表\n * 只清除映射,不重置 Store\n */\n const clear = (): void => {\n stores.clear()\n }\n\n /**\n * 从 Pinia 实例中批量注册已有的 Store\n * 访问 Pinia 内部的 _s 映射(所有已创建的 Store)\n * @param pinia - Pinia 实例\n */\n const registerExistingStores = (pinia: Pinia): void => {\n const typedPinia = pinia as PiniaWithStores\n typedPinia._s?.forEach(store => register(store))\n }\n\n /**\n * 创建全局 Store API 对象\n * 提供只读的 Store 查询和管理能力\n * @param pinia - Pinia 实例\n * @returns GlobalStoreAPI 对象\n */\n const createStoreAPI = (pinia: Pinia): GlobalStoreAPI => {\n return {\n pinia, /* Pinia 实例引用 */\n getStore, /* 获取 Store */\n hasStore, /* 检查 Store 是否存在 */\n getStoreIds, /* 获取所有 Store ID */\n resetAll, /* 重置所有 Store */\n }\n }\n\n /* 返回完整的注册表对象 */\n return {\n stores,\n register,\n unregister,\n hasStore,\n getStore,\n getStoreIds,\n resetAll,\n clear,\n registerExistingStores,\n createStoreAPI,\n }\n}\n\n/* ── 全局注册表单例 ── */\n\n/* 全局注册表实例(模块级单例) */\nlet globalRegistry = createStoreRegistry()\n\n/**\n * 设置全局注册表\n * 传 null 则创建新的空注册表\n * @param registry - 新的注册表或 null\n */\nexport function setGlobalStoreRegistry(registry: StoreRegistry | null): void {\n globalRegistry = registry ?? createStoreRegistry()\n}\n\n/**\n * 获取全局 Store 映射(兼容旧接口)\n * @returns Store 映射(类型擦除版)\n */\nexport function getStoreRegistry(): Map<string, unknown> {\n return globalRegistry.stores as Map<string, unknown>\n}\n\n/**\n * 创建注册表方法集合\n * 从注册表中提取常用的查询方法\n * @param registry - 注册表实例,默认使用全局注册表\n * @returns 方法集合对象\n */\nexport function createRegistryMethods(registry: StoreRegistry = globalRegistry) {\n return {\n getStore: registry.getStore,\n hasStore: registry.hasStore,\n getStoreIds: registry.getStoreIds,\n resetAll: registry.resetAll,\n }\n}\n\n/**\n * 创建注册表 Pinia 插件\n * 当 Store 被创建/使用时自动注册到注册表\n * @param registry - 注册表实例,默认使用全局注册表\n * @returns Pinia 插件函数\n */\nexport function createStoreRegistryPlugin(registry: StoreRegistry = globalRegistry) {\n return ({ store }: PiniaPluginContext): void => {\n registry.register(store)\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,0BAA0B,uBAAO,gCAAgC;AA+CvE,SAAS,kBAAkB,OAAwB,YAA6C;CAE9F,MAAM,wBAAwB,MAAM;CACpC,IAAI,uBACF,sBAAsB;CAIxB,MAAM,kBAAkB,MAAM;CAE9B,MAAM,WAAW,SAAS,iBAAiB;EACzC,WAAW,MAAM,GAAG;EACpB,OAAO,gBAAgB,KAAK,IAAI;CAClC;CAGA,MAAM,iCAAiC;EACrC,MAAM,WAAW;EACjB,OAAO,MAAM;CACf;AACF;AAMO,SAAS,sBAAqC;CAEnD,MAAM,yBAAS,IAAI,IAA0B;CAM7C,MAAM,cAAc,YAA0B;EAC5C,OAAO,OAAO,OAAO;CACvB;CAOA,MAAM,YAAY,UAA8B;EAC9C,OAAO,IAAI,MAAM,KAAK,KAAK;EAC3B,kBAAkB,OAA0B,UAAU;CACxD;CAOA,MAAM,YAAY,YAA6B;EAC7C,OAAO,OAAO,IAAI,OAAO;CAC3B;CAOA,MAAM,YAAyB,YAAmC;EAChE,OAAO,OAAO,IAAI,OAAO;CAC3B;CAMA,MAAM,oBAA8B;EAClC,OAAO,MAAM,KAAK,OAAO,KAAK,CAAC;CACjC;CAOA,MAAM,iBAAuB;EAC3B,OAAO,SAAS,UAAU;GAExB,IAAI,OAAO,MAAM,WAAW,YAC1B;GAGF,IAAI;IACF,MAAM,OAAO;GACf,QACM,CAEN;EACF,CAAC;CACH;CAMA,MAAM,cAAoB;EACxB,OAAO,MAAM;CACf;CAOA,MAAM,0BAA0B,UAAuB;EAErD,MAAW,IAAI,SAAQ,UAAS,SAAS,KAAK,CAAC;CACjD;CAQA,MAAM,kBAAkB,UAAiC;EACvD,OAAO;GACL;GACA;GACA;GACA;GACA;EACF;CACF;CAGA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAKA,IAAI,iBAAiB,oBAAoB;AAOlC,SAAS,uBAAuB,UAAsC;CAC3E,iBAAiB,YAAY,oBAAoB;AACnD;AAMO,SAAS,mBAAyC;CACvD,OAAO,eAAe;AACxB;AAQO,SAAS,sBAAsB,WAA0B,gBAAgB;CAC9E,OAAO;EACL,UAAU,SAAS;EACnB,UAAU,SAAS;EACnB,aAAa,SAAS;EACtB,UAAU,SAAS;CACrB;AACF;AAQO,SAAS,0BAA0B,WAA0B,gBAAgB;CAClF,QAAQ,EAAE,YAAsC;EAC9C,SAAS,SAAS,KAAK;CACzB;AACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Pinia, PiniaPluginContext, StoreGeneric } from 'pinia';
|
|
2
|
+
import type { GlobalStoreAPI } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Store 注册表接口
|
|
5
|
+
* 提供对所有活跃 Store 的集中管理能力
|
|
6
|
+
* @property stores - Store 实例映射(storeId → Store)
|
|
7
|
+
* @property register - 注册一个 Store
|
|
8
|
+
* @property unregister - 注销一个 Store
|
|
9
|
+
* @property hasStore - 检查 Store 是否已注册
|
|
10
|
+
* @property getStore - 获取指定 ID 的 Store
|
|
11
|
+
* @property getStoreIds - 获取所有已注册的 Store ID
|
|
12
|
+
* @property resetAll - 重置所有 Store 到初始状态
|
|
13
|
+
* @property clear - 清空注册表(不重置 Store)
|
|
14
|
+
* @property registerExistingStores - 从 Pinia 实例中批量注册已有的 Store
|
|
15
|
+
* @property createStoreAPI - 创建全局 Store API 对象
|
|
16
|
+
*/
|
|
17
|
+
export interface StoreRegistry {
|
|
18
|
+
readonly stores: Map<string, StoreGeneric>;
|
|
19
|
+
register: (store: StoreGeneric) => void;
|
|
20
|
+
unregister: (storeId: string) => void;
|
|
21
|
+
hasStore: (storeId: string) => boolean;
|
|
22
|
+
getStore: <T = unknown>(storeId: string) => T | undefined;
|
|
23
|
+
getStoreIds: () => string[];
|
|
24
|
+
resetAll: () => void;
|
|
25
|
+
clear: () => void;
|
|
26
|
+
registerExistingStores: (pinia: Pinia) => void;
|
|
27
|
+
createStoreAPI: (pinia: Pinia) => GlobalStoreAPI;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 创建 Store 注册表实例
|
|
31
|
+
* @returns StoreRegistry 注册表对象
|
|
32
|
+
*/
|
|
33
|
+
export declare function createStoreRegistry(): StoreRegistry;
|
|
34
|
+
/**
|
|
35
|
+
* 设置全局注册表
|
|
36
|
+
* 传 null 则创建新的空注册表
|
|
37
|
+
* @param registry - 新的注册表或 null
|
|
38
|
+
*/
|
|
39
|
+
export declare function setGlobalStoreRegistry(registry: StoreRegistry | null): void;
|
|
40
|
+
/**
|
|
41
|
+
* 获取全局 Store 映射(兼容旧接口)
|
|
42
|
+
* @returns Store 映射(类型擦除版)
|
|
43
|
+
*/
|
|
44
|
+
export declare function getStoreRegistry(): Map<string, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* 创建注册表方法集合
|
|
47
|
+
* 从注册表中提取常用的查询方法
|
|
48
|
+
* @param registry - 注册表实例,默认使用全局注册表
|
|
49
|
+
* @returns 方法集合对象
|
|
50
|
+
*/
|
|
51
|
+
export declare function createRegistryMethods(registry?: StoreRegistry): {
|
|
52
|
+
getStore: <T = unknown>(storeId: string) => T | undefined;
|
|
53
|
+
hasStore: (storeId: string) => boolean;
|
|
54
|
+
getStoreIds: () => string[];
|
|
55
|
+
resetAll: () => void;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* 创建注册表 Pinia 插件
|
|
59
|
+
* 当 Store 被创建/使用时自动注册到注册表
|
|
60
|
+
* @param registry - 注册表实例,默认使用全局注册表
|
|
61
|
+
* @returns Pinia 插件函数
|
|
62
|
+
*/
|
|
63
|
+
export declare function createStoreRegistryPlugin(registry?: StoreRegistry): ({ store }: PiniaPluginContext) => void;
|
|
64
|
+
//# sourceMappingURL=store-registry.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
12
|
+
const require_pinia_plugin = require("../plugins/pinia-plugin.cjs");
|
|
13
|
+
const require_store_plugin_options = require("./store-plugin-options.cjs");
|
|
14
|
+
const require_store_registry = require("./store-registry.cjs");
|
|
15
|
+
let pinia = require("pinia");
|
|
16
|
+
//#region src/runtime/store-runtime.ts
|
|
17
|
+
const STORE_RUNTIME_KEY = /* @__PURE__ */ Symbol("ldesign-store-runtime");
|
|
18
|
+
let globalStoreRuntime = null;
|
|
19
|
+
function getGlobalStoreAPI() {
|
|
20
|
+
return globalStoreRuntime?.storeAPI ?? null;
|
|
21
|
+
}
|
|
22
|
+
function setGlobalStoreRuntime(runtime) {
|
|
23
|
+
globalStoreRuntime = runtime;
|
|
24
|
+
require_store_registry.setGlobalStoreRegistry(runtime?.registry ?? null);
|
|
25
|
+
}
|
|
26
|
+
function createStoreRuntime(options = {}) {
|
|
27
|
+
const resolvedOptions = require_store_plugin_options.normalizeStoreRuntimeOptions(options);
|
|
28
|
+
const pinia$1 = resolvedOptions.pinia ?? (0, pinia.createPinia)();
|
|
29
|
+
if (pinia$1[STORE_RUNTIME_KEY]) return pinia$1[STORE_RUNTIME_KEY];
|
|
30
|
+
const registry = require_store_registry.createStoreRegistry();
|
|
31
|
+
const persistController = resolvedOptions.persist ? require_pinia_plugin.createPersistPluginController({
|
|
32
|
+
...resolvedOptions.persistOptions,
|
|
33
|
+
debug: resolvedOptions.debug || resolvedOptions.persistOptions.debug
|
|
34
|
+
}) : null;
|
|
35
|
+
pinia$1.use(require_store_registry.createStoreRegistryPlugin(registry));
|
|
36
|
+
persistController && pinia$1.use(persistController.plugin);
|
|
37
|
+
registry.registerExistingStores(pinia$1);
|
|
38
|
+
const runtime = {
|
|
39
|
+
pinia: pinia$1,
|
|
40
|
+
registry,
|
|
41
|
+
storeAPI: registry.createStoreAPI(pinia$1),
|
|
42
|
+
options: resolvedOptions,
|
|
43
|
+
/**
|
|
44
|
+
* 清理函数
|
|
45
|
+
* 释放所有资源:清除运行时标记、持久化插件、注册表
|
|
46
|
+
*/
|
|
47
|
+
dispose: () => {
|
|
48
|
+
if (pinia$1[STORE_RUNTIME_KEY] === runtime) delete pinia$1[STORE_RUNTIME_KEY];
|
|
49
|
+
persistController?.dispose();
|
|
50
|
+
registry.clear();
|
|
51
|
+
if (globalStoreRuntime === runtime) setGlobalStoreRuntime(null);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
pinia$1[STORE_RUNTIME_KEY] = runtime;
|
|
55
|
+
return runtime;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.createStoreRuntime = createStoreRuntime;
|
|
59
|
+
exports.getGlobalStoreAPI = getGlobalStoreAPI;
|
|
60
|
+
exports.setGlobalStoreRuntime = setGlobalStoreRuntime;
|
|
61
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
62
|
+
//# sourceMappingURL=store-runtime.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-runtime.cjs","names":[],"sources":["../../src/runtime/store-runtime.ts"],"sourcesContent":["/* ============================================================\n * store-runtime.ts\n * Store 运行时模块\n * 负责创建和管理 Store 运行时实例,包括 Pinia 创建、\n * 注册表初始化、持久化插件配置和生命周期管理\n * ============================================================ */\n\n/* 从 Pinia 导入类型 */\nimport type { Pinia, StoreGeneric } from 'pinia'\n/* 全局 Store API 类型 */\nimport type { GlobalStoreAPI } from '../types'\n/* 运行时选项类型 */\nimport type {\n ResolvedStoreRuntimeOptions, /* 解析后的运行时选项 */\n StoreRuntimeOptions, /* 原始运行时选项 */\n} from './store-plugin-options'\n/* 注册表类型 */\nimport type { StoreRegistry } from './store-registry'\n/* 从 Pinia 导入创建实例函数 */\nimport { createPinia } from 'pinia'\n/* 导入持久化插件控制器 */\nimport { createPersistPluginController } from '../plugins/pinia-plugin'\n/* 导入选项规范化函数 */\nimport {\n normalizeStoreRuntimeOptions,\n} from './store-plugin-options'\n/* 导入注册表相关函数 */\nimport {\n createStoreRegistry,\n createStoreRegistryPlugin,\n setGlobalStoreRegistry,\n} from './store-registry'\n\n/* 用于标记 Pinia 实例上已绑定的运行时的 Symbol 键 */\nconst STORE_RUNTIME_KEY = Symbol('ldesign-store-runtime')\n\n/* 扩展 Pinia 类型,添加运行时和 Store 映射引用 */\ntype PiniaWithRuntime = Pinia & {\n _s?: Map<string, StoreGeneric> /* Pinia 内部的 Store 实例映射 */\n [STORE_RUNTIME_KEY]?: StoreRuntime /* 绑定的运行时 */\n}\n\n/**\n * Store 运行时接口\n * 封装了 Pinia、注册表、API 和生命周期管理\n * @property pinia - Pinia 实例\n * @property registry - Store 注册表\n * @property storeAPI - 全局 Store API\n * @property options - 解析后的运行时选项\n * @property dispose - 清理函数,释放所有资源\n */\nexport interface StoreRuntime {\n pinia: Pinia\n registry: StoreRegistry\n storeAPI: GlobalStoreAPI\n options: ResolvedStoreRuntimeOptions\n dispose: () => void\n}\n\n/* 全局运行时实例(模块级单例) */\nlet globalStoreRuntime: StoreRuntime | null = null\n\n/**\n * 获取全局 Store API\n * @returns 全局 Store API 或 null(运行时未初始化时)\n */\nexport function getGlobalStoreAPI(): GlobalStoreAPI | null {\n return globalStoreRuntime?.storeAPI ?? null\n}\n\n/**\n * 设置全局运行时\n * 同步更新全局注册表引用\n * @param runtime - 新的运行时实例或 null\n */\nexport function setGlobalStoreRuntime(runtime: StoreRuntime | null): void {\n globalStoreRuntime = runtime\n /* 同步更新全局注册表 */\n setGlobalStoreRegistry(runtime?.registry ?? null)\n}\n\n/**\n * 创建 Store 运行时实例\n * 这是 Store 系统的核心工厂函数,负责:\n * 1. 规范化配置选项\n * 2. 创建或复用 Pinia 实例\n * 3. 创建 Store 注册表\n * 4. 配置持久化插件\n * 5. 注册 Pinia 插件\n * 6. 组装运行时对象\n *\n * @param options - 运行时配置选项\n * @returns StoreRuntime 实例\n */\nexport function createStoreRuntime(\n options: StoreRuntimeOptions = {},\n): StoreRuntime {\n /* 规范化配置选项(填充默认值) */\n const resolvedOptions = normalizeStoreRuntimeOptions(options)\n /* 创建或复用 Pinia 实例,扩展为带运行时标记的类型 */\n const pinia = (resolvedOptions.pinia ?? createPinia()) as PiniaWithRuntime\n\n /* 如果 Pinia 实例上已有运行时,直接复用(防止重复创建) */\n if (pinia[STORE_RUNTIME_KEY]) {\n return pinia[STORE_RUNTIME_KEY]\n }\n\n /* 创建 Store 注册表 */\n const registry = createStoreRegistry()\n\n /* 如果启用了持久化,创建持久化插件控制器 */\n const persistController = resolvedOptions.persist\n ? createPersistPluginController({\n ...resolvedOptions.persistOptions, /* 透传持久化选项 */\n debug: resolvedOptions.debug || resolvedOptions.persistOptions.debug, /* 调试模式 */\n })\n : null\n\n /* 注册注册表插件(自动注册新创建的 Store) */\n pinia.use(createStoreRegistryPlugin(registry))\n /* 如果有持久化插件,也注册到 Pinia */\n persistController && pinia.use(persistController.plugin)\n /* 批量注册 Pinia 中已有的 Store */\n registry.registerExistingStores(pinia)\n\n /* 组装运行时对象 */\n const runtime: StoreRuntime = {\n pinia, /* Pinia 实例 */\n registry, /* Store 注册表 */\n storeAPI: registry.createStoreAPI(pinia), /* 全局 Store API */\n options: resolvedOptions, /* 解析后的选项 */\n\n /**\n * 清理函数\n * 释放所有资源:清除运行时标记、持久化插件、注册表\n */\n dispose: () => {\n /* 清除 Pinia 上的运行时标记 */\n if (pinia[STORE_RUNTIME_KEY] === runtime) {\n delete pinia[STORE_RUNTIME_KEY]\n }\n\n /* 销毁持久化插件(取消订阅、移除事件监听等) */\n persistController?.dispose()\n /* 清空注册表 */\n registry.clear()\n\n /* 如果当前是全局运行时,也清除全局引用 */\n if (globalStoreRuntime === runtime) {\n setGlobalStoreRuntime(null)\n }\n },\n }\n\n /* 在 Pinia 实例上保存运行时引用(防止重复创建) */\n pinia[STORE_RUNTIME_KEY] = runtime\n return runtime\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,MAAM,oBAAoB,uBAAO,uBAAuB;AA0BxD,IAAI,qBAA0C;AAMvC,SAAS,oBAA2C;CACzD,OAAO,oBAAoB,YAAY;AACzC;AAOO,SAAS,sBAAsB,SAAoC;CACxE,qBAAqB;CAErB,uBAAA,uBAAuB,SAAS,YAAY,IAAI;AAClD;AAeO,SAAS,mBACd,UAA+B,CAAC,GAClB;CAEd,MAAM,kBAAkB,6BAAA,6BAA6B,OAAO;CAE5D,MAAM,UAAS,gBAAgB,UAAA,GAAA,MAAA,YAAA,CAAqB;CAGpD,IAAI,QAAM,oBACR,OAAO,QAAM;CAIf,MAAM,WAAW,uBAAA,oBAAoB;CAGrC,MAAM,oBAAoB,gBAAgB,UACtC,qBAAA,8BAA8B;EAC5B,GAAG,gBAAgB;EACnB,OAAO,gBAAgB,SAAS,gBAAgB,eAAe;CACjE,CAAC,IACD;CAGJ,QAAM,IAAI,uBAAA,0BAA0B,QAAQ,CAAC;CAE7C,qBAAqB,QAAM,IAAI,kBAAkB,MAAM;CAEvD,SAAS,uBAAuB,OAAK;CAGrC,MAAM,UAAwB;EAC5B,OAAA;EACA;EACA,UAAU,SAAS,eAAe,OAAK;EACvC,SAAS;;;;;EAMT,eAAe;GAEb,IAAI,QAAM,uBAAuB,SAC/B,OAAO,QAAM;GAIf,mBAAmB,QAAQ;GAE3B,SAAS,MAAM;GAGf,IAAI,uBAAuB,SACzB,sBAAsB,IAAI;EAE9B;CACF;CAGA,QAAM,qBAAqB;CAC3B,OAAO;AACT"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Pinia } from 'pinia';
|
|
2
|
+
import type { GlobalStoreAPI } from '../types';
|
|
3
|
+
import type { ResolvedStoreRuntimeOptions, /* 解析后的运行时选项 */ StoreRuntimeOptions } from './store-plugin-options';
|
|
4
|
+
import type { StoreRegistry } from './store-registry';
|
|
5
|
+
/**
|
|
6
|
+
* Store 运行时接口
|
|
7
|
+
* 封装了 Pinia、注册表、API 和生命周期管理
|
|
8
|
+
* @property pinia - Pinia 实例
|
|
9
|
+
* @property registry - Store 注册表
|
|
10
|
+
* @property storeAPI - 全局 Store API
|
|
11
|
+
* @property options - 解析后的运行时选项
|
|
12
|
+
* @property dispose - 清理函数,释放所有资源
|
|
13
|
+
*/
|
|
14
|
+
export interface StoreRuntime {
|
|
15
|
+
pinia: Pinia;
|
|
16
|
+
registry: StoreRegistry;
|
|
17
|
+
storeAPI: GlobalStoreAPI;
|
|
18
|
+
options: ResolvedStoreRuntimeOptions;
|
|
19
|
+
dispose: () => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 获取全局 Store API
|
|
23
|
+
* @returns 全局 Store API 或 null(运行时未初始化时)
|
|
24
|
+
*/
|
|
25
|
+
export declare function getGlobalStoreAPI(): GlobalStoreAPI | null;
|
|
26
|
+
/**
|
|
27
|
+
* 设置全局运行时
|
|
28
|
+
* 同步更新全局注册表引用
|
|
29
|
+
* @param runtime - 新的运行时实例或 null
|
|
30
|
+
*/
|
|
31
|
+
export declare function setGlobalStoreRuntime(runtime: StoreRuntime | null): void;
|
|
32
|
+
/**
|
|
33
|
+
* 创建 Store 运行时实例
|
|
34
|
+
* 这是 Store 系统的核心工厂函数,负责:
|
|
35
|
+
* 1. 规范化配置选项
|
|
36
|
+
* 2. 创建或复用 Pinia 实例
|
|
37
|
+
* 3. 创建 Store 注册表
|
|
38
|
+
* 4. 配置持久化插件
|
|
39
|
+
* 5. 注册 Pinia 插件
|
|
40
|
+
* 6. 组装运行时对象
|
|
41
|
+
*
|
|
42
|
+
* @param options - 运行时配置选项
|
|
43
|
+
* @returns StoreRuntime 实例
|
|
44
|
+
*/
|
|
45
|
+
export declare function createStoreRuntime(options?: StoreRuntimeOptions): StoreRuntime;
|
|
46
|
+
//# sourceMappingURL=store-runtime.d.ts.map
|
package/lib/types.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
12
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
package/lib/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
|
package/package.json
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@composy/store-vue",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "Vue 3 状态管理适配器 - 基于 Pinia 的增强版状态管理解决方案",
|
|
6
|
+
"author": "ldesign",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"vue3",
|
|
10
|
+
"pinia",
|
|
11
|
+
"state-management",
|
|
12
|
+
"store",
|
|
13
|
+
"typescript",
|
|
14
|
+
"composables",
|
|
15
|
+
"reactive"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./es/index.d.ts",
|
|
21
|
+
"import": "./es/index.js",
|
|
22
|
+
"require": "./lib/index.cjs",
|
|
23
|
+
"default": "./es/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./composables": {
|
|
26
|
+
"types": "./es/composables/index.d.ts",
|
|
27
|
+
"import": "./es/composables/index.js",
|
|
28
|
+
"require": "./lib/composables/index.cjs",
|
|
29
|
+
"default": "./es/composables/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./composables/*": {
|
|
32
|
+
"types": "./es/composables/*.d.ts",
|
|
33
|
+
"import": "./es/composables/*.js",
|
|
34
|
+
"require": "./lib/composables/*.cjs",
|
|
35
|
+
"default": "./es/composables/*.js"
|
|
36
|
+
},
|
|
37
|
+
"./context/*": {
|
|
38
|
+
"types": "./es/context/*.d.ts",
|
|
39
|
+
"import": "./es/context/*.js",
|
|
40
|
+
"require": "./lib/context/*.cjs",
|
|
41
|
+
"default": "./es/context/*.js"
|
|
42
|
+
},
|
|
43
|
+
"./plugins": {
|
|
44
|
+
"types": "./es/plugins/index.d.ts",
|
|
45
|
+
"import": "./es/plugins/index.js",
|
|
46
|
+
"require": "./lib/plugins/index.cjs",
|
|
47
|
+
"default": "./es/plugins/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./plugins/*": {
|
|
50
|
+
"types": "./es/plugins/*.d.ts",
|
|
51
|
+
"import": "./es/plugins/*.js",
|
|
52
|
+
"require": "./lib/plugins/*.cjs",
|
|
53
|
+
"default": "./es/plugins/*.js"
|
|
54
|
+
},
|
|
55
|
+
"./runtime/*": {
|
|
56
|
+
"types": "./es/runtime/*.d.ts",
|
|
57
|
+
"import": "./es/runtime/*.js",
|
|
58
|
+
"require": "./lib/runtime/*.cjs",
|
|
59
|
+
"default": "./es/runtime/*.js"
|
|
60
|
+
},
|
|
61
|
+
"./package.json": "./package.json"
|
|
62
|
+
},
|
|
63
|
+
"main": "./lib/index.cjs",
|
|
64
|
+
"module": "./es/index.js",
|
|
65
|
+
"unpkg": "./dist/index.min.js",
|
|
66
|
+
"jsdelivr": "./dist/index.min.js",
|
|
67
|
+
"types": "./es/index.d.ts",
|
|
68
|
+
"files": [
|
|
69
|
+
"CHANGELOG.md",
|
|
70
|
+
"LICENSE",
|
|
71
|
+
"README.md",
|
|
72
|
+
"dist",
|
|
73
|
+
"es",
|
|
74
|
+
"esm",
|
|
75
|
+
"lib"
|
|
76
|
+
],
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "ldesign-builder build",
|
|
79
|
+
"build:watch": "ldesign-builder build --watch",
|
|
80
|
+
"clean": "rimraf es esm lib dist",
|
|
81
|
+
"dev": "ldesign-builder build --watch",
|
|
82
|
+
"lint": "eslint . --fix",
|
|
83
|
+
"lint:check": "eslint . --max-warnings 0",
|
|
84
|
+
"lint:fix": "eslint . --fix",
|
|
85
|
+
"test": "ltesting run:unit",
|
|
86
|
+
"test:run": "ltesting run:unit",
|
|
87
|
+
"type-check": "vue-tsc -p tsconfig.typecheck.json --noEmit",
|
|
88
|
+
"test:watch": "ltesting run:unit --watch",
|
|
89
|
+
"test:coverage": "ltesting run:unit --coverage",
|
|
90
|
+
"test:changed": "ltesting run:unit --changed",
|
|
91
|
+
"test:failed": "ltesting run:unit --failed",
|
|
92
|
+
"test:ui": "ltesting dashboard"
|
|
93
|
+
},
|
|
94
|
+
"peerDependencies": {
|
|
95
|
+
"pinia": "^2.1.0",
|
|
96
|
+
"vue": "^3.5.32"
|
|
97
|
+
},
|
|
98
|
+
"dependencies": {
|
|
99
|
+
"@composy/store-core": "^0.0.1",
|
|
100
|
+
"pinia": "^3.0.4"
|
|
101
|
+
},
|
|
102
|
+
"devDependencies": {
|
|
103
|
+
"@antfu/eslint-config": "9.1.0",
|
|
104
|
+
"@composy/builder": "^0.0.1",
|
|
105
|
+
"@composy/testing": "^0.0.1",
|
|
106
|
+
"@types/node": "26.1.1",
|
|
107
|
+
"@vue/test-utils": "^2.4.11",
|
|
108
|
+
"eslint": "10.7.0",
|
|
109
|
+
"typescript": "5.9.3",
|
|
110
|
+
"vue": "3.5.39",
|
|
111
|
+
"vue-tsc": "^3.3.7"
|
|
112
|
+
},
|
|
113
|
+
"typings": "./es/index.d.ts",
|
|
114
|
+
"browser": "./dist/index.js"
|
|
115
|
+
}
|