@vlian/framework 1.2.63 → 2.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.
Files changed (185) hide show
  1. package/README.md +21 -141
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.ts +1 -9
  4. package/dist/index.js +1 -1
  5. package/dist/index.umd.js +10 -220
  6. package/dist/kernel/constants.cjs +1 -1
  7. package/dist/kernel/constants.d.ts +1 -3
  8. package/dist/kernel/constants.js +1 -1
  9. package/dist/kernel/custom-manager/i18n/constants.cjs +1 -0
  10. package/dist/kernel/custom-manager/i18n/constants.d.ts +4 -0
  11. package/dist/kernel/custom-manager/i18n/constants.js +1 -0
  12. package/dist/kernel/custom-manager/i18n/index.cjs +1 -0
  13. package/dist/kernel/custom-manager/i18n/index.d.ts +7 -0
  14. package/dist/kernel/custom-manager/i18n/index.js +1 -0
  15. package/dist/kernel/custom-manager/i18n/types.d.ts +10 -0
  16. package/dist/kernel/custom-manager/index.cjs +1 -0
  17. package/dist/kernel/custom-manager/index.d.ts +4 -0
  18. package/dist/kernel/custom-manager/index.js +1 -0
  19. package/dist/kernel/custom-manager/theme/constants.cjs +1 -0
  20. package/dist/kernel/custom-manager/theme/constants.d.ts +4 -0
  21. package/dist/kernel/custom-manager/theme/constants.js +1 -0
  22. package/dist/kernel/custom-manager/theme/index.cjs +1 -0
  23. package/dist/kernel/custom-manager/theme/index.d.ts +7 -0
  24. package/dist/kernel/custom-manager/theme/index.js +1 -0
  25. package/dist/kernel/custom-manager/theme/types.d.ts +14 -0
  26. package/dist/kernel/index.cjs +1 -1
  27. package/dist/kernel/index.d.ts +4 -2
  28. package/dist/kernel/index.js +1 -1
  29. package/dist/kernel/kernel.cjs +1 -1
  30. package/dist/kernel/kernel.d.ts +3 -7
  31. package/dist/kernel/kernel.js +1 -1
  32. package/dist/kernel/manager/i18n/I18nManager.cjs +1 -1
  33. package/dist/kernel/manager/i18n/I18nManager.d.ts +2 -1
  34. package/dist/kernel/manager/i18n/I18nManager.js +1 -1
  35. package/dist/kernel/manager/i18n/i18n.persistence.d.ts +2 -1
  36. package/dist/kernel/manager/i18n/i18n.runtime.cjs +1 -0
  37. package/dist/kernel/manager/i18n/i18n.runtime.d.ts +8 -0
  38. package/dist/kernel/manager/i18n/i18n.runtime.js +1 -0
  39. package/dist/kernel/manager/i18n/i18n.schema.d.ts +1 -1
  40. package/dist/kernel/manager/i18nManager.cjs +1 -1
  41. package/dist/kernel/manager/i18nManager.d.ts +1 -1
  42. package/dist/kernel/manager/i18nManager.js +1 -1
  43. package/dist/kernel/manager/index.cjs +1 -1
  44. package/dist/kernel/manager/index.d.ts +0 -2
  45. package/dist/kernel/manager/index.js +1 -1
  46. package/dist/kernel/manager/theme/ThemeManager.cjs +1 -1
  47. package/dist/kernel/manager/theme/ThemeManager.d.ts +8 -1
  48. package/dist/kernel/manager/theme/ThemeManager.js +1 -1
  49. package/dist/kernel/manager/theme/theme.dom.cjs +1 -1
  50. package/dist/kernel/manager/theme/theme.dom.d.ts +10 -3
  51. package/dist/kernel/manager/theme/theme.dom.js +1 -1
  52. package/dist/kernel/manager/theme/theme.persistence.d.ts +2 -1
  53. package/dist/kernel/manager/theme/theme.schema.cjs +1 -1
  54. package/dist/kernel/manager/theme/theme.schema.d.ts +3 -1
  55. package/dist/kernel/manager/theme/theme.schema.js +1 -1
  56. package/dist/kernel/manager/themeManager.cjs +1 -1
  57. package/dist/kernel/manager/themeManager.d.ts +1 -1
  58. package/dist/kernel/manager/themeManager.js +1 -1
  59. package/dist/kernel/types.d.ts +10 -39
  60. package/package.json +10 -133
  61. package/dist/analytics/index.cjs +0 -1
  62. package/dist/analytics/index.d.ts +0 -2
  63. package/dist/analytics/index.js +0 -1
  64. package/dist/analytics.umd.js +0 -19
  65. package/dist/components/index.cjs +0 -1
  66. package/dist/components/index.d.ts +0 -1
  67. package/dist/components/index.js +0 -1
  68. package/dist/components/persistence.cjs +0 -1
  69. package/dist/components/persistence.d.ts +0 -12
  70. package/dist/components/persistence.js +0 -1
  71. package/dist/library/index.cjs +0 -1
  72. package/dist/library/index.d.ts +0 -2
  73. package/dist/library/index.js +0 -1
  74. package/dist/library/locale/index.cjs +0 -1
  75. package/dist/library/locale/index.d.ts +0 -6
  76. package/dist/library/locale/index.js +0 -1
  77. package/dist/library/locale/langs/en-us/index.cjs +0 -1
  78. package/dist/library/locale/langs/en-us/index.d.ts +0 -3
  79. package/dist/library/locale/langs/en-us/index.js +0 -1
  80. package/dist/library/locale/langs/zh-cn/index.cjs +0 -1
  81. package/dist/library/locale/langs/zh-cn/index.d.ts +0 -3
  82. package/dist/library/locale/langs/zh-cn/index.js +0 -1
  83. package/dist/library/locale/types.d.ts +0 -38
  84. package/dist/library/storage/cache.cjs +0 -1
  85. package/dist/library/storage/cache.d.ts +0 -57
  86. package/dist/library/storage/cache.js +0 -1
  87. package/dist/library/storage/encryption.cjs +0 -1
  88. package/dist/library/storage/encryption.d.ts +0 -45
  89. package/dist/library/storage/encryption.js +0 -1
  90. package/dist/library/storage/index.cjs +0 -1
  91. package/dist/library/storage/index.d.ts +0 -62
  92. package/dist/library/storage/index.js +0 -1
  93. package/dist/state/StateManager.cjs +0 -1
  94. package/dist/state/StateManager.d.ts +0 -120
  95. package/dist/state/StateManager.js +0 -1
  96. package/dist/state/adapters/AdapterFactory.cjs +0 -1
  97. package/dist/state/adapters/AdapterFactory.d.ts +0 -51
  98. package/dist/state/adapters/AdapterFactory.js +0 -1
  99. package/dist/state/adapters/DefaultAdapter.cjs +0 -1
  100. package/dist/state/adapters/DefaultAdapter.d.ts +0 -38
  101. package/dist/state/adapters/DefaultAdapter.js +0 -1
  102. package/dist/state/adapters/ReduxAdapter.cjs +0 -1
  103. package/dist/state/adapters/ReduxAdapter.d.ts +0 -129
  104. package/dist/state/adapters/ReduxAdapter.js +0 -1
  105. package/dist/state/adapters/ZustandAdapter.cjs +0 -1
  106. package/dist/state/adapters/ZustandAdapter.d.ts +0 -46
  107. package/dist/state/adapters/ZustandAdapter.js +0 -1
  108. package/dist/state/adapters/index.cjs +0 -1
  109. package/dist/state/adapters/index.d.ts +0 -8
  110. package/dist/state/adapters/index.js +0 -1
  111. package/dist/state/adapters/types.cjs +0 -1
  112. package/dist/state/adapters/types.d.ts +0 -4
  113. package/dist/state/adapters/types.js +0 -1
  114. package/dist/state/core/DerivedStateInstance.cjs +0 -1
  115. package/dist/state/core/DerivedStateInstance.d.ts +0 -100
  116. package/dist/state/core/DerivedStateInstance.js +0 -1
  117. package/dist/state/core/StateInstance.cjs +0 -1
  118. package/dist/state/core/StateInstance.d.ts +0 -85
  119. package/dist/state/core/StateInstance.js +0 -1
  120. package/dist/state/core/StateRegistry.cjs +0 -1
  121. package/dist/state/core/StateRegistry.d.ts +0 -55
  122. package/dist/state/core/StateRegistry.js +0 -1
  123. package/dist/state/core/StateScope.cjs +0 -1
  124. package/dist/state/core/StateScope.d.ts +0 -71
  125. package/dist/state/core/StateScope.js +0 -1
  126. package/dist/state/core/index.cjs +0 -1
  127. package/dist/state/core/index.d.ts +0 -7
  128. package/dist/state/core/index.js +0 -1
  129. package/dist/state/index.cjs +0 -1
  130. package/dist/state/index.d.ts +0 -8
  131. package/dist/state/index.js +0 -1
  132. package/dist/state/types.d.ts +0 -230
  133. package/dist/state.umd.js +0 -41
  134. package/dist/types.cjs +0 -1
  135. package/dist/types.d.ts +0 -7
  136. package/dist/types.js +0 -1
  137. package/dist/utils/analytics.cjs +0 -1
  138. package/dist/utils/analytics.d.ts +0 -127
  139. package/dist/utils/analytics.js +0 -1
  140. package/dist/utils/configSecurity.cjs +0 -3
  141. package/dist/utils/configSecurity.d.ts +0 -100
  142. package/dist/utils/configSecurity.js +0 -3
  143. package/dist/utils/csrf.cjs +0 -1
  144. package/dist/utils/csrf.d.ts +0 -1
  145. package/dist/utils/csrf.js +0 -1
  146. package/dist/utils/errors/ErrorCodes.cjs +0 -1
  147. package/dist/utils/errors/ErrorCodes.d.ts +0 -1
  148. package/dist/utils/errors/ErrorCodes.js +0 -1
  149. package/dist/utils/errors.cjs +0 -1
  150. package/dist/utils/errors.d.ts +0 -30
  151. package/dist/utils/errors.js +0 -1
  152. package/dist/utils/index.cjs +0 -1
  153. package/dist/utils/index.d.ts +0 -39
  154. package/dist/utils/index.js +0 -1
  155. package/dist/utils/logger.cjs +0 -1
  156. package/dist/utils/logger.d.ts +0 -2
  157. package/dist/utils/logger.js +0 -1
  158. package/dist/utils/logger.types.cjs +0 -1
  159. package/dist/utils/logger.types.d.ts +0 -2
  160. package/dist/utils/logger.types.js +0 -1
  161. package/dist/utils/monitoring.cjs +0 -1
  162. package/dist/utils/monitoring.d.ts +0 -1
  163. package/dist/utils/monitoring.js +0 -1
  164. package/dist/utils/performance.cjs +0 -1
  165. package/dist/utils/performance.d.ts +0 -2
  166. package/dist/utils/performance.js +0 -1
  167. package/dist/utils/resourceLoader.cjs +0 -1
  168. package/dist/utils/resourceLoader.d.ts +0 -2
  169. package/dist/utils/resourceLoader.js +0 -1
  170. package/dist/utils/runtimeSecurity.cjs +0 -1
  171. package/dist/utils/runtimeSecurity.d.ts +0 -2
  172. package/dist/utils/runtimeSecurity.js +0 -1
  173. package/dist/utils/security.cjs +0 -1
  174. package/dist/utils/security.d.ts +0 -2
  175. package/dist/utils/security.js +0 -1
  176. package/dist/utils/traceId.cjs +0 -1
  177. package/dist/utils/traceId.d.ts +0 -1
  178. package/dist/utils/traceId.js +0 -1
  179. package/dist/utils/validation.cjs +0 -1
  180. package/dist/utils/validation.d.ts +0 -2
  181. package/dist/utils/validation.js +0 -1
  182. /package/dist/{library/locale → kernel/custom-manager/i18n}/types.cjs +0 -0
  183. /package/dist/{library/locale → kernel/custom-manager/i18n}/types.js +0 -0
  184. /package/dist/{state → kernel/custom-manager/theme}/types.cjs +0 -0
  185. /package/dist/{state → kernel/custom-manager/theme}/types.js +0 -0
@@ -1,85 +0,0 @@
1
- /**
2
- * 状态实例核心实现
3
- */
4
- import type { IStateInstance, StateInstanceId, StateScope, StateSubscriber, StateUpdater, Unsubscribe } from '../types';
5
- /**
6
- * 基础状态实例实现
7
- *
8
- * 这是一个通用的状态实例实现,不依赖任何外部状态管理库
9
- *
10
- * @template T - 状态值类型
11
- */
12
- export declare class StateInstance<T = unknown> implements IStateInstance<T> {
13
- /**
14
- * 状态实例标识符
15
- */
16
- private readonly id;
17
- /**
18
- * 状态作用域
19
- */
20
- private readonly scope?;
21
- /**
22
- * 当前状态值
23
- */
24
- private value;
25
- /**
26
- * 订阅者集合
27
- */
28
- private readonly subscribers;
29
- /**
30
- * 是否已销毁
31
- */
32
- private destroyed;
33
- /**
34
- * 开发模式标志
35
- */
36
- private readonly devMode;
37
- /**
38
- * 中间件函数数组
39
- */
40
- private readonly middleware;
41
- /**
42
- * 构造函数
43
- *
44
- * @param initialValue - 初始状态值
45
- * @param options - 状态实例配置选项
46
- */
47
- constructor(initialValue: T, options?: {
48
- id?: StateInstanceId;
49
- scope?: StateScope;
50
- devMode?: boolean;
51
- middleware?: Array<(value: unknown, previous: unknown) => unknown>;
52
- });
53
- /**
54
- * 获取当前状态值
55
- */
56
- get(): T;
57
- /**
58
- * 更新状态值
59
- */
60
- set(valueOrUpdater: T | StateUpdater<T>): void;
61
- /**
62
- * 订阅状态变化
63
- */
64
- subscribe(subscriber: StateSubscriber<T>): Unsubscribe;
65
- /**
66
- * 获取状态实例标识符
67
- */
68
- getId(): StateInstanceId;
69
- /**
70
- * 获取状态作用域
71
- */
72
- getScope(): StateScope | undefined;
73
- /**
74
- * 销毁状态实例
75
- */
76
- destroy(): void;
77
- /**
78
- * 检查状态实例是否已销毁
79
- */
80
- isDestroyed(): boolean;
81
- /**
82
- * 通知所有订阅者
83
- */
84
- private notifySubscribers;
85
- }
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}export class StateInstance{get(){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}return this.value}set(valueOrUpdater){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}const previousValue=this.value;let newValue;if(typeof valueOrUpdater==="function"){newValue=valueOrUpdater(this.value)}else{newValue=valueOrUpdater}let processedValue=newValue;for(const middleware of this.middleware){processedValue=middleware(processedValue,previousValue)}if(processedValue===this.value){return}this.value=processedValue;if(this.devMode){console.debug(`[StateInstance] Updated: ${String(this.id)}`,{previous:previousValue,current:this.value})}this.notifySubscribers(this.value,previousValue)}subscribe(subscriber){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);if(this.devMode){console.debug(`[StateInstance] Subscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size})}return()=>{this.subscribers.delete(subscriber);if(this.devMode){console.debug(`[StateInstance] Unsubscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size})}}}getId(){return this.id}getScope(){return this.scope}destroy(){if(this.destroyed){return}this.destroyed=true;this.subscribers.clear();this.value=undefined;if(this.devMode){console.debug(`[StateInstance] Destroyed: ${String(this.id)}`)}}isDestroyed(){return this.destroyed}notifySubscribers(value,previous){const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(value,previous)}catch(error){console.error(`[StateInstance] Error in subscriber for ${String(this.id)}:`,error)}}}constructor(initialValue,options={}){_define_property(this,"id",void 0);_define_property(this,"scope",void 0);_define_property(this,"value",void 0);_define_property(this,"subscribers",new Set);_define_property(this,"destroyed",false);_define_property(this,"devMode",void 0);_define_property(this,"middleware",void 0);this.value=initialValue;this.id=options.id??Symbol("StateInstance");this.scope=options.scope;this.devMode=options.devMode??false;this.middleware=options.middleware??[];if(this.devMode){console.debug(`[StateInstance] Created: ${String(this.id)}`,{scope:this.scope,initialValue:this.value})}}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"StateRegistry",{enumerable:true,get:function(){return StateRegistry}});const _StateScope=require("./StateScope");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let StateRegistry=class StateRegistry{register(instance){const id=instance.getId();if(this.instances.has(id)){console.warn(`[StateRegistry] Instance with id ${String(id)} already exists, replacing...`)}this.instances.set(id,instance);const scope=instance.getScope();if(scope){this.scopeManager.register(instance,scope)}}unregister(id){const instance=this.instances.get(id);if(!instance){return}this.scopeManager.unregister(instance);instance.destroy();this.instances.delete(id)}getInstance(id){return this.instances.get(id)}getInstancesByScope(scope){return this.scopeManager.getInstances(scope)}getAllInstances(){return Array.from(this.instances.values())}destroyScope(scope){const instances=this.scopeManager.getInstances(scope);for(const instance of instances){instance.destroy();this.instances.delete(instance.getId())}this.scopeManager.destroyScope(scope)}destroyAll(){for(const instance of this.instances.values()){instance.destroy()}this.instances.clear();this.scopeManager.destroyAll()}size(){return this.instances.size}constructor(){_define_property(this,"instances",new Map);_define_property(this,"scopeManager",void 0);this.scopeManager=new _StateScope.StateScopeManager}};
@@ -1,55 +0,0 @@
1
- /**
2
- * 状态注册表实现
3
- */
4
- import type { IStateRegistry, IStateInstance, StateInstanceId, StateScope } from '../types';
5
- /**
6
- * 状态注册表
7
- *
8
- * 负责管理所有状态实例的注册、查询和销毁
9
- */
10
- export declare class StateRegistry implements IStateRegistry {
11
- /**
12
- * 状态实例映射表(ID -> Instance)
13
- */
14
- private readonly instances;
15
- /**
16
- * 作用域管理器
17
- */
18
- private readonly scopeManager;
19
- /**
20
- * 构造函数
21
- */
22
- constructor();
23
- /**
24
- * 注册状态实例
25
- */
26
- register(instance: IStateInstance): void;
27
- /**
28
- * 注销状态实例
29
- */
30
- unregister(id: StateInstanceId): void;
31
- /**
32
- * 根据标识符获取状态实例
33
- */
34
- getInstance(id: StateInstanceId): IStateInstance | undefined;
35
- /**
36
- * 根据作用域获取所有状态实例
37
- */
38
- getInstancesByScope(scope: StateScope): IStateInstance[];
39
- /**
40
- * 获取所有状态实例
41
- */
42
- getAllInstances(): IStateInstance[];
43
- /**
44
- * 销毁指定作用域的所有状态实例
45
- */
46
- destroyScope(scope: StateScope): void;
47
- /**
48
- * 销毁所有状态实例
49
- */
50
- destroyAll(): void;
51
- /**
52
- * 获取注册表中的实例数量
53
- */
54
- size(): number;
55
- }
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}import{StateScopeManager}from"./StateScope";export class StateRegistry{register(instance){const id=instance.getId();if(this.instances.has(id)){console.warn(`[StateRegistry] Instance with id ${String(id)} already exists, replacing...`)}this.instances.set(id,instance);const scope=instance.getScope();if(scope){this.scopeManager.register(instance,scope)}}unregister(id){const instance=this.instances.get(id);if(!instance){return}this.scopeManager.unregister(instance);instance.destroy();this.instances.delete(id)}getInstance(id){return this.instances.get(id)}getInstancesByScope(scope){return this.scopeManager.getInstances(scope)}getAllInstances(){return Array.from(this.instances.values())}destroyScope(scope){const instances=this.scopeManager.getInstances(scope);for(const instance of instances){instance.destroy();this.instances.delete(instance.getId())}this.scopeManager.destroyScope(scope)}destroyAll(){for(const instance of this.instances.values()){instance.destroy()}this.instances.clear();this.scopeManager.destroyAll()}size(){return this.instances.size}constructor(){_define_property(this,"instances",new Map);_define_property(this,"scopeManager",void 0);this.scopeManager=new StateScopeManager}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"StateScopeManager",{enumerable:true,get:function(){return StateScopeManager}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let StateScopeManager=class StateScopeManager{register(instance,scope){const existingScope=this.instanceToScopeMap.get(instance);if(existingScope){this.unregister(instance)}if(!this.scopeMap.has(scope)){this.scopeMap.set(scope,new Set)}const instances=this.scopeMap.get(scope);instances.add(instance);this.instanceToScopeMap.set(instance,scope)}unregister(instance){const scope=this.instanceToScopeMap.get(instance);if(!scope){return}const instances=this.scopeMap.get(scope);if(instances){instances.delete(instance);if(instances.size===0){this.scopeMap.delete(scope)}}this.instanceToScopeMap.delete(instance)}getInstances(scope){const instances=this.scopeMap.get(scope);return instances?Array.from(instances):[]}getScope(instance){return this.instanceToScopeMap.get(instance)}destroyScope(scope){const instances=this.scopeMap.get(scope);if(!instances){return}for(const instance of instances){instance.destroy();this.instanceToScopeMap.delete(instance)}this.scopeMap.delete(scope)}destroyAll(){for(const instances of this.scopeMap.values()){for(const instance of instances){instance.destroy()}}this.scopeMap.clear();this.instanceToScopeMap.clear()}getAllScopes(){return Array.from(this.scopeMap.keys())}getScopeCount(){return this.scopeMap.size}getInstanceCount(){return this.instanceToScopeMap.size}constructor(){_define_property(this,"scopeMap",new Map);_define_property(this,"instanceToScopeMap",new Map)}};
@@ -1,71 +0,0 @@
1
- /**
2
- * 状态作用域管理
3
- */
4
- import type { StateScope } from '../types';
5
- import type { IStateInstance } from '../types';
6
- /**
7
- * 状态作用域管理器
8
- *
9
- * 负责管理状态作用域的创建、销毁和查询
10
- */
11
- export declare class StateScopeManager {
12
- /**
13
- * 作用域到状态实例的映射
14
- */
15
- private readonly scopeMap;
16
- /**
17
- * 状态实例到作用域的映射(用于快速查找)
18
- */
19
- private readonly instanceToScopeMap;
20
- /**
21
- * 注册状态实例到作用域
22
- *
23
- * @param instance - 状态实例
24
- * @param scope - 状态作用域
25
- */
26
- register(instance: IStateInstance, scope: StateScope): void;
27
- /**
28
- * 注销状态实例
29
- *
30
- * @param instance - 状态实例
31
- */
32
- unregister(instance: IStateInstance): void;
33
- /**
34
- * 根据作用域获取所有状态实例
35
- *
36
- * @param scope - 状态作用域
37
- * @returns 状态实例数组
38
- */
39
- getInstances(scope: StateScope): IStateInstance[];
40
- /**
41
- * 获取状态实例的作用域
42
- *
43
- * @param instance - 状态实例
44
- * @returns 状态作用域,如果不存在则返回 undefined
45
- */
46
- getScope(instance: IStateInstance): StateScope | undefined;
47
- /**
48
- * 销毁指定作用域的所有状态实例
49
- *
50
- * @param scope - 状态作用域
51
- */
52
- destroyScope(scope: StateScope): void;
53
- /**
54
- * 销毁所有作用域和状态实例
55
- */
56
- destroyAll(): void;
57
- /**
58
- * 获取所有作用域
59
- *
60
- * @returns 作用域数组
61
- */
62
- getAllScopes(): StateScope[];
63
- /**
64
- * 获取作用域数量
65
- */
66
- getScopeCount(): number;
67
- /**
68
- * 获取总实例数量
69
- */
70
- getInstanceCount(): number;
71
- }
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}export class StateScopeManager{register(instance,scope){const existingScope=this.instanceToScopeMap.get(instance);if(existingScope){this.unregister(instance)}if(!this.scopeMap.has(scope)){this.scopeMap.set(scope,new Set)}const instances=this.scopeMap.get(scope);instances.add(instance);this.instanceToScopeMap.set(instance,scope)}unregister(instance){const scope=this.instanceToScopeMap.get(instance);if(!scope){return}const instances=this.scopeMap.get(scope);if(instances){instances.delete(instance);if(instances.size===0){this.scopeMap.delete(scope)}}this.instanceToScopeMap.delete(instance)}getInstances(scope){const instances=this.scopeMap.get(scope);return instances?Array.from(instances):[]}getScope(instance){return this.instanceToScopeMap.get(instance)}destroyScope(scope){const instances=this.scopeMap.get(scope);if(!instances){return}for(const instance of instances){instance.destroy();this.instanceToScopeMap.delete(instance)}this.scopeMap.delete(scope)}destroyAll(){for(const instances of this.scopeMap.values()){for(const instance of instances){instance.destroy()}}this.scopeMap.clear();this.instanceToScopeMap.clear()}getAllScopes(){return Array.from(this.scopeMap.keys())}getScopeCount(){return this.scopeMap.size}getInstanceCount(){return this.instanceToScopeMap.size}constructor(){_define_property(this,"scopeMap",new Map);_define_property(this,"instanceToScopeMap",new Map)}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get DerivedStateInstance(){return _DerivedStateInstance.DerivedStateInstance},get StateInstance(){return _StateInstance.StateInstance},get StateRegistry(){return _StateRegistry.StateRegistry},get StateScopeManager(){return _StateScope.StateScopeManager}});const _StateInstance=require("./StateInstance");const _StateScope=require("./StateScope");const _StateRegistry=require("./StateRegistry");const _DerivedStateInstance=require("./DerivedStateInstance");
@@ -1,7 +0,0 @@
1
- /**
2
- * 状态管理器核心模块导出
3
- */
4
- export { StateInstance } from './StateInstance';
5
- export { StateScopeManager } from './StateScope';
6
- export { StateRegistry } from './StateRegistry';
7
- export { DerivedStateInstance } from './DerivedStateInstance';
@@ -1 +0,0 @@
1
- export{StateInstance}from"./StateInstance";export{StateScopeManager}from"./StateScope";export{StateRegistry}from"./StateRegistry";export{DerivedStateInstance}from"./DerivedStateInstance";
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"StateManager",{enumerable:true,get:function(){return _StateManager.StateManager}});_export_star(require("./types"),exports);_export_star(require("./core"),exports);_export_star(require("./adapters"),exports);const _StateManager=require("./StateManager");function _export_star(from,to){Object.keys(from).forEach(function(k){if(k!=="default"&&!Object.prototype.hasOwnProperty.call(to,k)){Object.defineProperty(to,k,{enumerable:true,get:function(){return from[k]}})}});return from}
@@ -1,8 +0,0 @@
1
- /**
2
- * 状态管理器模块统一导出
3
- */
4
- export * from './types';
5
- export * from './core';
6
- export * from './adapters';
7
- export { StateManager } from './StateManager';
8
- export type { IStateManager } from './StateManager';
@@ -1 +0,0 @@
1
- export*from"./types";export*from"./core";export*from"./adapters";export{StateManager}from"./StateManager";
@@ -1,230 +0,0 @@
1
- /**
2
- * 状态管理器类型定义
3
- */
4
- /**
5
- * 状态更新函数类型
6
- *
7
- * @template T - 状态值类型
8
- * @param current - 当前状态值
9
- * @returns 新的状态值
10
- */
11
- export type StateUpdater<T> = (current: T) => T;
12
- /**
13
- * 状态订阅回调函数类型
14
- *
15
- * @template T - 状态值类型
16
- * @param value - 新的状态值
17
- * @param previous - 之前的状态值
18
- */
19
- export type StateSubscriber<T> = (value: T, previous: T) => void;
20
- /**
21
- * 取消订阅函数类型
22
- */
23
- export type Unsubscribe = () => void;
24
- /**
25
- * 状态作用域标识符
26
- */
27
- export type StateScope = string | symbol;
28
- /**
29
- * 状态实例标识符
30
- */
31
- export type StateInstanceId = string | symbol;
32
- /**
33
- * 状态实例配置选项
34
- */
35
- export interface StateInstanceOptions {
36
- /**
37
- * 状态实例标识符
38
- */
39
- id?: StateInstanceId;
40
- /**
41
- * 状态作用域
42
- */
43
- scope?: StateScope;
44
- /**
45
- * 是否启用开发模式(用于调试)
46
- */
47
- devMode?: boolean;
48
- /**
49
- * 状态变更时的中间件函数
50
- */
51
- middleware?: Array<(value: unknown, previous: unknown) => unknown>;
52
- }
53
- /**
54
- * 状态实例核心接口
55
- *
56
- * 这是状态管理器的最小抽象接口,不绑定任何具体实现
57
- *
58
- * @template T - 状态值类型
59
- */
60
- export interface IStateInstance<T = unknown> {
61
- /**
62
- * 获取当前状态值
63
- *
64
- * @returns 当前状态值
65
- */
66
- get(): T;
67
- /**
68
- * 更新状态值
69
- *
70
- * @param value - 新的状态值或更新函数
71
- */
72
- set(value: T | StateUpdater<T>): void;
73
- /**
74
- * 订阅状态变化
75
- *
76
- * @param subscriber - 订阅回调函数
77
- * @returns 取消订阅函数
78
- */
79
- subscribe(subscriber: StateSubscriber<T>): Unsubscribe;
80
- /**
81
- * 获取状态实例标识符
82
- */
83
- getId(): StateInstanceId;
84
- /**
85
- * 获取状态作用域
86
- */
87
- getScope(): StateScope | undefined;
88
- /**
89
- * 销毁状态实例,清理所有订阅和资源
90
- */
91
- destroy(): void;
92
- /**
93
- * 检查状态实例是否已销毁
94
- */
95
- isDestroyed(): boolean;
96
- }
97
- /**
98
- * 状态适配器接口
99
- *
100
- * 适配器负责将外部状态库映射到 Secra 状态抽象
101
- *
102
- * @template T - 状态值类型
103
- */
104
- export interface IStateAdapter {
105
- /**
106
- * 创建状态实例
107
- *
108
- * @param initialValue - 初始状态值
109
- * @param options - 状态实例配置选项
110
- * @returns 状态实例
111
- */
112
- createInstance<T>(initialValue: T, options?: StateInstanceOptions): IStateInstance<T>;
113
- /**
114
- * 销毁适配器,清理所有资源
115
- */
116
- destroy(): void;
117
- /**
118
- * 获取适配器名称(用于调试和日志)
119
- */
120
- getName(): string;
121
- }
122
- /**
123
- * 状态注册表接口
124
- */
125
- export interface IStateRegistry {
126
- /**
127
- * 注册状态实例
128
- *
129
- * @param instance - 状态实例
130
- */
131
- register(instance: IStateInstance): void;
132
- /**
133
- * 注销状态实例
134
- *
135
- * @param id - 状态实例标识符
136
- */
137
- unregister(id: StateInstanceId): void;
138
- /**
139
- * 根据标识符获取状态实例
140
- *
141
- * @param id - 状态实例标识符
142
- * @returns 状态实例,如果不存在则返回 undefined
143
- */
144
- getInstance(id: StateInstanceId): IStateInstance | undefined;
145
- /**
146
- * 根据作用域获取所有状态实例
147
- *
148
- * @param scope - 状态作用域
149
- * @returns 状态实例数组
150
- */
151
- getInstancesByScope(scope: StateScope): IStateInstance[];
152
- /**
153
- * 获取所有状态实例
154
- *
155
- * @returns 状态实例数组
156
- */
157
- getAllInstances(): IStateInstance[];
158
- /**
159
- * 销毁指定作用域的所有状态实例
160
- *
161
- * @param scope - 状态作用域
162
- */
163
- destroyScope(scope: StateScope): void;
164
- /**
165
- * 销毁所有状态实例
166
- */
167
- destroyAll(): void;
168
- /**
169
- * 获取注册表中的实例数量
170
- */
171
- size(): number;
172
- }
173
- /**
174
- * 派生状态配置
175
- */
176
- export interface DerivedStateConfig<T, D extends readonly IStateInstance[]> {
177
- /**
178
- * 依赖的状态实例数组
179
- */
180
- dependencies: D;
181
- /**
182
- * 派生函数,根据依赖状态计算派生状态
183
- *
184
- * @param values - 依赖状态的当前值数组
185
- * @returns 派生状态值
186
- */
187
- derive: (values: {
188
- [K in keyof D]: D[K] extends IStateInstance<infer V> ? V : never;
189
- }) => T;
190
- /**
191
- * 是否启用相等性检查(避免不必要的更新)
192
- */
193
- equalityCheck?: (a: T, b: T) => boolean;
194
- }
195
- /**
196
- * 派生状态实例接口
197
- *
198
- * @template T - 派生状态值类型
199
- */
200
- export interface IDerivedStateInstance<T = unknown> extends IStateInstance<T> {
201
- /**
202
- * 获取依赖的状态实例
203
- */
204
- getDependencies(): readonly IStateInstance[];
205
- /**
206
- * 手动重新计算派生状态
207
- */
208
- recompute(): void;
209
- }
210
- /**
211
- * 状态管理器配置选项
212
- */
213
- export interface StateManagerOptions {
214
- /**
215
- * 默认状态适配器
216
- */
217
- defaultAdapter?: IStateAdapter;
218
- /**
219
- * 是否启用全局注册表
220
- */
221
- enableRegistry?: boolean;
222
- /**
223
- * 默认作用域
224
- */
225
- defaultScope?: StateScope;
226
- /**
227
- * 是否启用开发模式
228
- */
229
- devMode?: boolean;
230
- }
package/dist/state.umd.js DELETED
@@ -1,41 +0,0 @@
1
- /*!
2
- * @vlian/framework v1.2.62
3
- * Secra Framework - 一个现代化的低代码框架
4
- * (c) 2026 Secra Framework Contributors
5
- * Licensed under Apache-2.0
6
- */
7
- (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
9
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vlianFrameworkState = {}));
11
- })(this, (function (exports) { 'use strict';
12
-
13
- function _define_property$8(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}class StateInstance{get(){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}return this.value}set(valueOrUpdater){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}const previousValue=this.value;let newValue;if(typeof valueOrUpdater==="function"){newValue=valueOrUpdater(this.value);}else {newValue=valueOrUpdater;}let processedValue=newValue;for(const middleware of this.middleware){processedValue=middleware(processedValue,previousValue);}if(processedValue===this.value){return}this.value=processedValue;if(this.devMode){console.debug(`[StateInstance] Updated: ${String(this.id)}`,{previous:previousValue,current:this.value});}this.notifySubscribers(this.value,previousValue);}subscribe(subscriber){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);if(this.devMode){console.debug(`[StateInstance] Subscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size});}return ()=>{this.subscribers.delete(subscriber);if(this.devMode){console.debug(`[StateInstance] Unsubscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size});}}}getId(){return this.id}getScope(){return this.scope}destroy(){if(this.destroyed){return}this.destroyed=true;this.subscribers.clear();this.value=undefined;if(this.devMode){console.debug(`[StateInstance] Destroyed: ${String(this.id)}`);}}isDestroyed(){return this.destroyed}notifySubscribers(value,previous){const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(value,previous);}catch(error){console.error(`[StateInstance] Error in subscriber for ${String(this.id)}:`,error);}}}constructor(initialValue,options={}){_define_property$8(this,"id",void 0);_define_property$8(this,"scope",void 0);_define_property$8(this,"value",void 0);_define_property$8(this,"subscribers",new Set);_define_property$8(this,"destroyed",false);_define_property$8(this,"devMode",void 0);_define_property$8(this,"middleware",void 0);this.value=initialValue;this.id=options.id??Symbol("StateInstance");this.scope=options.scope;this.devMode=options.devMode??false;this.middleware=options.middleware??[];if(this.devMode){console.debug(`[StateInstance] Created: ${String(this.id)}`,{scope:this.scope,initialValue:this.value});}}}
14
-
15
- function _define_property$7(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}class StateScopeManager{register(instance,scope){const existingScope=this.instanceToScopeMap.get(instance);if(existingScope){this.unregister(instance);}if(!this.scopeMap.has(scope)){this.scopeMap.set(scope,new Set);}const instances=this.scopeMap.get(scope);instances.add(instance);this.instanceToScopeMap.set(instance,scope);}unregister(instance){const scope=this.instanceToScopeMap.get(instance);if(!scope){return}const instances=this.scopeMap.get(scope);if(instances){instances.delete(instance);if(instances.size===0){this.scopeMap.delete(scope);}}this.instanceToScopeMap.delete(instance);}getInstances(scope){const instances=this.scopeMap.get(scope);return instances?Array.from(instances):[]}getScope(instance){return this.instanceToScopeMap.get(instance)}destroyScope(scope){const instances=this.scopeMap.get(scope);if(!instances){return}for(const instance of instances){instance.destroy();this.instanceToScopeMap.delete(instance);}this.scopeMap.delete(scope);}destroyAll(){for(const instances of this.scopeMap.values()){for(const instance of instances){instance.destroy();}}this.scopeMap.clear();this.instanceToScopeMap.clear();}getAllScopes(){return Array.from(this.scopeMap.keys())}getScopeCount(){return this.scopeMap.size}getInstanceCount(){return this.instanceToScopeMap.size}constructor(){_define_property$7(this,"scopeMap",new Map);_define_property$7(this,"instanceToScopeMap",new Map);}}
16
-
17
- function _define_property$6(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}class StateRegistry{register(instance){const id=instance.getId();if(this.instances.has(id)){console.warn(`[StateRegistry] Instance with id ${String(id)} already exists, replacing...`);}this.instances.set(id,instance);const scope=instance.getScope();if(scope){this.scopeManager.register(instance,scope);}}unregister(id){const instance=this.instances.get(id);if(!instance){return}this.scopeManager.unregister(instance);instance.destroy();this.instances.delete(id);}getInstance(id){return this.instances.get(id)}getInstancesByScope(scope){return this.scopeManager.getInstances(scope)}getAllInstances(){return Array.from(this.instances.values())}destroyScope(scope){const instances=this.scopeManager.getInstances(scope);for(const instance of instances){instance.destroy();this.instances.delete(instance.getId());}this.scopeManager.destroyScope(scope);}destroyAll(){for(const instance of this.instances.values()){instance.destroy();}this.instances.clear();this.scopeManager.destroyAll();}size(){return this.instances.size}constructor(){_define_property$6(this,"instances",new Map);_define_property$6(this,"scopeManager",void 0);this.scopeManager=new StateScopeManager;}}
18
-
19
- function _define_property$5(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}class DerivedStateInstance{get(){if(this.destroyed){throw new Error(`DerivedStateInstance ${String(this.id)} has been destroyed`)}return this.value}set(_valueOrUpdater){throw new Error("Derived state cannot be set directly. Modify the dependency states instead.")}subscribe(subscriber){if(this.destroyed){throw new Error(`DerivedStateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);return ()=>{this.subscribers.delete(subscriber);}}getId(){return this.id}getScope(){return this.scope}getDependencies(){return this.config.dependencies}recompute(){if(this.destroyed||this.recomputing){return}this.recomputing=true;try{const dependencyValues=this.config.dependencies.map(dep=>dep.get());const newValue=this.config.derive(dependencyValues);const hasChanged=this.config.equalityCheck?!this.config.equalityCheck(this.value,newValue):this.value!==newValue;if(hasChanged){const previousValue=this.value;this.value=newValue;this.notifySubscribers(this.value,previousValue);}}catch(error){console.error(`[DerivedStateInstance] Error recomputing ${String(this.id)}:`,error);}finally{this.recomputing=false;}}destroy(){if(this.destroyed){return}this.destroyed=true;for(const unsubscribe of this.dependencyUnsubscribes){unsubscribe();}this.dependencyUnsubscribes.length=0;this.subscribers.clear();}isDestroyed(){return this.destroyed}setupDependencies(){for(const dependency of this.config.dependencies){const unsubscribe=dependency.subscribe(()=>{this.recompute();});this.dependencyUnsubscribes.push(unsubscribe);}}notifySubscribers(value,previous){const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(value,previous);}catch(error){console.error(`[DerivedStateInstance] Error in subscriber for ${String(this.id)}:`,error);}}}constructor(config,options={}){_define_property$5(this,"id",void 0);_define_property$5(this,"scope",void 0);_define_property$5(this,"config",void 0);_define_property$5(this,"value",void 0);_define_property$5(this,"subscribers",new Set);_define_property$5(this,"dependencyUnsubscribes",[]);_define_property$5(this,"destroyed",false);_define_property$5(this,"recomputing",false);this.config=config;this.id=options.id??Symbol("DerivedStateInstance");this.scope=options.scope;this.setupDependencies();this.recompute();}}
20
-
21
- function _define_property$4(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}class DefaultAdapter{createInstance(initialValue,options){if(this.destroyed){throw new Error("Adapter has been destroyed")}const instance=new StateInstance(initialValue,{id:options?.id,scope:options?.scope,devMode:options?.devMode,middleware:options?.middleware});this.instances.add(instance);return instance}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy();}this.instances.clear();this.destroyed=true;}getName(){return this.name}constructor(){_define_property$4(this,"name","DefaultAdapter");_define_property$4(this,"destroyed",false);_define_property$4(this,"instances",new Set);}}
22
-
23
- function _define_property$3(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}class AdapterFactory{static getDefaultAdapter(){if(!this.defaultAdapter){this.defaultAdapter=new DefaultAdapter;}return this.defaultAdapter}static createAdapter(adapterName){if(!adapterName){return this.getDefaultAdapter()}const factory=this.customAdapters.get(adapterName);if(!factory){throw new Error(`Adapter "${adapterName}" not found. Available adapters: ${Array.from(this.customAdapters.keys()).join(", ")}`)}return factory()}static registerAdapter(name,factory){if(this.customAdapters.has(name)){console.warn(`[AdapterFactory] Adapter "${name}" already registered, replacing...`);}this.customAdapters.set(name,factory);}static unregisterAdapter(name){this.customAdapters.delete(name);}static getRegisteredAdapters(){return Array.from(this.customAdapters.keys())}static reset(){if(this.defaultAdapter){this.defaultAdapter.destroy();this.defaultAdapter=null;}this.customAdapters.clear();}}_define_property$3(AdapterFactory,"defaultAdapter",null);_define_property$3(AdapterFactory,"customAdapters",new Map);
24
-
25
- function _define_property$2(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}let ReduxStateInstance=class ReduxStateInstance{get(){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}const state=this.store.getState();return state[this.sliceName]??this.previousValue}set(valueOrUpdater){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}const currentValue=this.get();let newValue;if(typeof valueOrUpdater==="function"){newValue=valueOrUpdater(currentValue);}else {newValue=valueOrUpdater;}let processedValue=newValue;for(const middleware of this.middleware){processedValue=middleware(processedValue,currentValue);}if(processedValue===currentValue){return}this.previousValue=currentValue;const action=this.actions.setValue(processedValue);this.store.dispatch(action);if(this.devMode){console.debug(`[ReduxStateInstance] Updated: ${String(this.id)}`,{previous:currentValue,current:processedValue,action});}}subscribe(subscriber){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);if(this.devMode){console.debug(`[ReduxStateInstance] Subscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size});}return ()=>{this.subscribers.delete(subscriber);if(this.devMode){console.debug(`[ReduxStateInstance] Unsubscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size});}}}getId(){return this.id}getScope(){return this.scope}destroy(){if(this.destroyed){return}this.destroyed=true;if(this.unsubscribeStore){this.unsubscribeStore();this.unsubscribeStore=undefined;}this.subscribers.clear();if(this.devMode){console.debug(`[ReduxStateInstance] Destroyed: ${String(this.id)}`);}}isDestroyed(){return this.destroyed}notifySubscribers(){if(this.destroyed){return}try{const currentValue=this.get();if(currentValue===this.previousValue){return}const previousValue=this.previousValue;this.previousValue=currentValue;const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(currentValue,previousValue);}catch(error){console.error(`[ReduxStateInstance] Error in subscriber for ${String(this.id)}:`,error);}}}catch(error){console.error(`[ReduxStateInstance] Error getting state for ${String(this.id)}:`,error);}}constructor(store,sliceName,actions,initialValue,options={}){_define_property$2(this,"id",void 0);_define_property$2(this,"scope",void 0);_define_property$2(this,"store",void 0);_define_property$2(this,"sliceName",void 0);_define_property$2(this,"actions",void 0);_define_property$2(this,"subscribers",new Set);_define_property$2(this,"unsubscribeStore",void 0);_define_property$2(this,"destroyed",false);_define_property$2(this,"devMode",void 0);_define_property$2(this,"middleware",void 0);_define_property$2(this,"previousValue",void 0);this.store=store;this.sliceName=sliceName;this.actions=actions;this.id=options.id??Symbol("ReduxStateInstance");this.scope=options.scope;this.devMode=options.devMode??false;this.middleware=options.middleware??[];this.previousValue=initialValue;this.unsubscribeStore=this.store.subscribe(()=>{this.notifySubscribers();});if(this.devMode){console.debug(`[ReduxStateInstance] Created: ${String(this.id)}`,{scope:this.scope,sliceName:this.sliceName,initialValue});}}};let DynamicReducerManager=class DynamicReducerManager{addReducer(key,reducer){this.reducers.set(key,reducer);}removeReducer(key){this.reducers.delete(key);}getRootReducer(){return this.rootReducer}hasReducer(key){return this.reducers.has(key)}constructor(){_define_property$2(this,"reducers",new Map);_define_property$2(this,"rootReducer",void 0);this.rootReducer=(state,action)=>{const stateRecord=state??{};const newState={...stateRecord};for(const[key,reducer]of this.reducers.entries()){newState[key]=reducer(stateRecord[key],action);}return newState};}};class ReduxAdapter{checkReduxAvailable(){}getOrCreateStore(){if(this.store){return this.store}try{const{configureStore}=require("@reduxjs/toolkit");this.store=configureStore({reducer:this.reducerManager.getRootReducer(),devTools:this.devMode,middleware:undefined});if(this.devMode){console.debug("[ReduxAdapter] Redux store created");}return this.store}catch(error){throw new Error("ReduxAdapter requires @reduxjs/toolkit to be installed. "+"Please install it: npm install @reduxjs/toolkit\n"+`Original error: ${error instanceof Error?error.message:String(error)}`)}}createSlice(sliceName,initialValue){try{const{createSlice}=require("@reduxjs/toolkit");const slice=createSlice({name:sliceName,initialState:initialValue,reducers:{setValue:(_state,action)=>{return action.payload??initialValue}}});return slice}catch(error){throw new Error("ReduxAdapter requires @reduxjs/toolkit to be installed. "+"Please install it: npm install @reduxjs/toolkit\n"+`Original error: ${error instanceof Error?error.message:String(error)}`)}}createInstance(initialValue,options){if(this.destroyed){throw new Error("ReduxAdapter has been destroyed")}const store=this.getOrCreateStore();const sliceName=options?.id?`secra_${String(options.id)}`:`secra_slice_${++this.sliceCounter}`;const slice=this.createSlice(sliceName,initialValue);if(!this.reducerManager.hasReducer(sliceName)){this.reducerManager.addReducer(sliceName,slice.reducer);store.replaceReducer(this.reducerManager.getRootReducer());}const instance=new ReduxStateInstance(store,sliceName,slice.actions,initialValue,{id:options?.id,scope:options?.scope,devMode:options?.devMode??this.devMode,middleware:options?.middleware});this.instances.add(instance);this.sliceToInstance.set(sliceName,instance);if(this.devMode){console.debug(`[ReduxAdapter] Created instance: ${String(instance.getId())}`,{sliceName,scope:options?.scope});}return instance}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy();}for(const sliceName of this.sliceToInstance.keys()){this.reducerManager.removeReducer(sliceName);}if(this.store){this.store.replaceReducer(this.reducerManager.getRootReducer());}this.instances.clear();this.sliceToInstance.clear();this.store=null;this.destroyed=true;if(this.devMode){console.debug("[ReduxAdapter] Destroyed");}}getName(){return this.name}constructor(options){_define_property$2(this,"name","ReduxAdapter");_define_property$2(this,"destroyed",false);_define_property$2(this,"instances",new Set);_define_property$2(this,"store",null);_define_property$2(this,"sliceCounter",0);_define_property$2(this,"sliceToInstance",new Map);_define_property$2(this,"reducerManager",void 0);_define_property$2(this,"devMode",void 0);this.devMode=options?.devMode??false;this.reducerManager=new DynamicReducerManager;this.store=options?.store??null;this.checkReduxAvailable();}}
26
-
27
- function _define_property$1(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}class ZustandAdapter{createInstance(_initialValue,_options){if(this.destroyed){throw new Error("Adapter has been destroyed")}throw new Error("ZustandAdapter is a placeholder implementation. "+"To use Zustand, you need to:\n"+"1. Install zustand\n"+"2. Implement a complete Zustand store integration\n"+"3. Map Zustand store methods to IStateInstance interface\n"+"See docs/state-manager.md for implementation guide.")}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy();}this.instances.clear();this.destroyed=true;}getName(){return this.name}constructor(){_define_property$1(this,"name","ZustandAdapter");_define_property$1(this,"destroyed",false);_define_property$1(this,"instances",new Set);}}
28
-
29
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}class StateManager{createState(initialValue,options){if(this.destroyed){throw new Error("StateManager has been destroyed")}const mergedOptions={...options,scope:options?.scope??this.defaultScope,devMode:options?.devMode??this.devMode};const instance=this.adapter.createInstance(initialValue,mergedOptions);if(this.registry){this.registry.register(instance);}return instance}createDerivedState(config,options){if(this.destroyed){throw new Error("StateManager has been destroyed")}const mergedOptions={...options,scope:options?.scope??this.defaultScope};const instance=new DerivedStateInstance(config,mergedOptions);if(this.registry){this.registry.register(instance);}return instance}getState(id){if(!this.registry){throw new Error("Registry is not enabled. Enable it in StateManagerOptions.")}return this.registry.getInstance(id)}getStatesByScope(scope){if(!this.registry){throw new Error("Registry is not enabled. Enable it in StateManagerOptions.")}return this.registry.getInstancesByScope(scope)}getAllStates(){if(!this.registry){throw new Error("Registry is not enabled. Enable it in StateManagerOptions.")}return this.registry.getAllInstances()}destroyScope(scope){if(!this.registry){throw new Error("Registry is not enabled. Enable it in StateManagerOptions.")}this.registry.destroyScope(scope);}destroy(){if(this.destroyed){return}this.destroyed=true;if(this.registry){this.registry.destroyAll();}this.adapter.destroy();if(this.devMode){console.debug("[StateManager] Destroyed");}}isDestroyed(){return this.destroyed}getAdapter(){return this.adapter}getRegistry(){return this.registry}constructor(options={}){_define_property(this,"adapter",void 0);_define_property(this,"registry",void 0);_define_property(this,"defaultScope",void 0);_define_property(this,"devMode",void 0);_define_property(this,"destroyed",false);this.adapter=options.defaultAdapter??AdapterFactory.getDefaultAdapter();this.defaultScope=options.defaultScope;this.devMode=options.devMode??false;this.registry=options.enableRegistry!==false?new StateRegistry:null;if(this.devMode){console.debug("[StateManager] Initialized",{adapter:this.adapter.getName(),registryEnabled:!!this.registry,defaultScope:this.defaultScope});}}}
30
-
31
- exports.AdapterFactory = AdapterFactory;
32
- exports.DefaultAdapter = DefaultAdapter;
33
- exports.DerivedStateInstance = DerivedStateInstance;
34
- exports.ReduxAdapter = ReduxAdapter;
35
- exports.StateInstance = StateInstance;
36
- exports.StateManager = StateManager;
37
- exports.StateRegistry = StateRegistry;
38
- exports.StateScopeManager = StateScopeManager;
39
- exports.ZustandAdapter = ZustandAdapter;
40
-
41
- }));
package/dist/types.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});
package/dist/types.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { StorageType } from '@vlian/utils';
2
- export type StorageOptions = {
3
- prefix: string;
4
- defaultExpire: number;
5
- tableName?: string;
6
- type?: StorageType;
7
- };
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export{};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get AnalyticsService(){return AnalyticsService},get getAnalytics(){return getAnalytics},get initAnalytics(){return initAnalytics}});const _logger=require("./logger");const _security=require("./security");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let AnalyticsService=class AnalyticsService{startBatchTimer(){if(this.batchTimer){return}this.batchTimer=setInterval(()=>{this.flush()},this.config.batchInterval)}stopBatchTimer(){if(this.batchTimer){clearInterval(this.batchTimer);this.batchTimer=null}}track(event){if(!this.config.enabled){return}if(Math.random()>this.config.sampleRate){return}const anonymizedEvent={...event,timestamp:Date.now(),properties:this.anonymizeProperties(event.properties)};this.eventQueue.push(anonymizedEvent);if(this.config.onEvent){this.config.onEvent(anonymizedEvent)}if(this.eventQueue.length>=this.config.batchSize){this.flush()}}trackPageView(page,properties){this.track({type:"pageview",name:"page_view",properties:{page,...properties}})}trackClick(element,properties){this.track({type:"click",name:"click",properties:{element,...properties}})}trackCustom(name,properties){this.track({type:"custom",name,properties})}trackError(error,properties){this.track({type:"error",name:"error",properties:{errorName:error.name,errorMessage:error.message,errorStack:error.stack,...properties}})}trackPerformance(metrics,properties){this.track({type:"performance",name:"performance",properties:{...metrics,...properties}})}anonymizeProperties(properties){if(!this.config.anonymize||!properties){return properties}return _security.SecurityUtils.deepSanitize(properties)}flush(){if(this.eventQueue.length===0){return}const events=[...this.eventQueue];this.eventQueue=[];if(this.config.onBatch){this.config.onBatch(events)}_logger.logger.debug(`分析服务批量上报 ${events.length} 个事件`)}enable(){this.config.enabled=true;this.startBatchTimer()}disable(){this.config.enabled=false;this.stopBatchTimer();this.flush()}destroy(){this.stopBatchTimer();this.flush()}constructor(config={}){_define_property(this,"config",void 0);_define_property(this,"eventQueue",[]);_define_property(this,"batchTimer",null);this.config={enabled:config.enabled??true,sampleRate:config.sampleRate??1,anonymize:config.anonymize??true,onEvent:config.onEvent??(()=>{}),onBatch:config.onBatch??(()=>{}),batchSize:config.batchSize??10,batchInterval:config.batchInterval??5e3};if(this.config.enabled){this.startBatchTimer()}}};let defaultAnalyticsService=null;function initAnalytics(config){if(!defaultAnalyticsService){defaultAnalyticsService=new AnalyticsService(config)}return defaultAnalyticsService}function getAnalytics(){if(!defaultAnalyticsService){return initAnalytics()}return defaultAnalyticsService}