@v-ibe/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -0
  3. package/dist/DI/__tests__/scoped-container-dependencies.test.d.ts +1 -0
  4. package/dist/DI/bootstrap.d.ts +18 -0
  5. package/dist/DI/decorators/inject.d.ts +37 -0
  6. package/dist/DI/decorators/inject.js +45 -0
  7. package/dist/DI/decorators/service.d.ts +24 -0
  8. package/dist/DI/decorators/service.js +13 -0
  9. package/dist/DI/di-container.d.ts +53 -0
  10. package/dist/DI/di-container.js +158 -0
  11. package/dist/DI/lifecycle.d.ts +37 -0
  12. package/dist/DI/lifecycle.js +6 -0
  13. package/dist/DI/scoped-container.d.ts +68 -0
  14. package/dist/DI/scoped-container.js +193 -0
  15. package/dist/DI/service-metadata.d.ts +32 -0
  16. package/dist/DI/service-metadata.js +31 -0
  17. package/dist/DI/types.d.ts +4 -0
  18. package/dist/behaviors/__tests__/behavior-system.test.d.ts +1 -0
  19. package/dist/behaviors/behavior-manager.d.ts +60 -0
  20. package/dist/behaviors/behavior-manager.js +131 -0
  21. package/dist/behaviors/behavior-registry.d.ts +68 -0
  22. package/dist/behaviors/behavior-registry.js +105 -0
  23. package/dist/behaviors/constants.d.ts +16 -0
  24. package/dist/behaviors/constants.js +8 -0
  25. package/dist/behaviors/decorators.d.ts +87 -0
  26. package/dist/behaviors/decorators.js +46 -0
  27. package/dist/behaviors/index.d.ts +4 -0
  28. package/dist/components/__tests__/host.test.d.ts +1 -0
  29. package/dist/components/app-tree.d.ts +49 -0
  30. package/dist/components/app-tree.js +122 -0
  31. package/dist/components/base-component.d.ts +85 -0
  32. package/dist/components/base-component.js +438 -0
  33. package/dist/components/decorators/component.d.ts +27 -0
  34. package/dist/components/decorators/component.js +47 -0
  35. package/dist/components/decorators/prop.d.ts +14 -0
  36. package/dist/components/decorators/prop.js +37 -0
  37. package/dist/components/types.d.ts +26 -0
  38. package/dist/core.d.ts +23 -0
  39. package/dist/core.js +8 -0
  40. package/dist/custom-components/__tests__/for.test.d.ts +1 -0
  41. package/dist/custom-components/__tests__/show.test.d.ts +1 -0
  42. package/dist/custom-components/for.d.ts +58 -0
  43. package/dist/custom-components/for.js +313 -0
  44. package/dist/custom-components/index.d.ts +2 -0
  45. package/dist/custom-components/show.d.ts +78 -0
  46. package/dist/custom-components/show.js +88 -0
  47. package/dist/data-management/cache/cache-invalidate.decorator.d.ts +35 -0
  48. package/dist/data-management/cache/cache-invalidate.decorator.js +21 -0
  49. package/dist/data-management/cache/cache-metadata.d.ts +15 -0
  50. package/dist/data-management/cache/cache-provider.interface.d.ts +67 -0
  51. package/dist/data-management/cache/cache-tags.decorator.d.ts +52 -0
  52. package/dist/data-management/cache/cache-tags.decorator.js +13 -0
  53. package/dist/data-management/cache/cache-update.decorator.d.ts +28 -0
  54. package/dist/data-management/cache/cache-update.decorator.js +21 -0
  55. package/dist/data-management/cache/cache.decorator.d.ts +28 -0
  56. package/dist/data-management/cache/cache.decorator.js +13 -0
  57. package/dist/data-management/cache/index.d.ts +11 -0
  58. package/dist/data-management/cache/local-storage-cache.d.ts +40 -0
  59. package/dist/data-management/cache/local-storage-cache.js +268 -0
  60. package/dist/data-management/cache/memory-cache.d.ts +37 -0
  61. package/dist/data-management/cache/memory-cache.js +149 -0
  62. package/dist/data-management/cache/session-storage-cache.d.ts +35 -0
  63. package/dist/data-management/cache/session-storage-cache.js +242 -0
  64. package/dist/data-management/cache/ttl.decorator.d.ts +31 -0
  65. package/dist/data-management/cache/ttl.decorator.js +34 -0
  66. package/dist/data-management/decorators/consume.d.ts +29 -0
  67. package/dist/data-management/decorators/consume.js +28 -0
  68. package/dist/data-management/decorators/id.d.ts +28 -0
  69. package/dist/data-management/decorators/id.js +19 -0
  70. package/dist/data-management/decorators/model.d.ts +48 -0
  71. package/dist/data-management/decorators/model.js +24 -0
  72. package/dist/data-management/decorators/prop.d.ts +43 -0
  73. package/dist/data-management/decorators/prop.js +32 -0
  74. package/dist/data-management/index.d.ts +13 -0
  75. package/dist/data-management/store/json-to-model.d.ts +45 -0
  76. package/dist/data-management/store/json-to-model.js +36 -0
  77. package/dist/data-management/store/store.d.ts +108 -0
  78. package/dist/data-management/store/store.js +207 -0
  79. package/dist/data-management/store/types.d.ts +53 -0
  80. package/dist/events-handler/decorators/emit.d.ts +29 -0
  81. package/dist/events-handler/decorators/emit.js +51 -0
  82. package/dist/events-handler/event-decorators.d.ts +1 -0
  83. package/dist/events-handler/event-emitter.service.d.ts +21 -0
  84. package/dist/events-handler/event-emitter.service.js +85 -0
  85. package/dist/events-handler/event-types.d.ts +12 -0
  86. package/dist/index.d.ts +55 -0
  87. package/dist/index.js +121 -0
  88. package/dist/jsx/dynamic/__tests__/granular-array-renderer.test.d.ts +1 -0
  89. package/dist/jsx/dynamic/__tests__/jsx-array-rendering.test.d.ts +1 -0
  90. package/dist/jsx/dynamic/array-renderer.d.ts +2 -0
  91. package/dist/jsx/dynamic/array-renderer.js +133 -0
  92. package/dist/jsx/dynamic/child-renderer.d.ts +1 -0
  93. package/dist/jsx/dynamic/child-renderer.js +180 -0
  94. package/dist/jsx/dynamic/dom-utils.d.ts +5 -0
  95. package/dist/jsx/dynamic/dom-utils.js +22 -0
  96. package/dist/jsx/dynamic/granular-array-renderer.d.ts +16 -0
  97. package/dist/jsx/dynamic/granular-array-renderer.js +153 -0
  98. package/dist/jsx/dynamic/node-renderer.d.ts +2 -0
  99. package/dist/jsx/dynamic/props-handler.d.ts +3 -0
  100. package/dist/jsx/dynamic/props-handler.js +281 -0
  101. package/dist/jsx/dynamic/text-renderer.d.ts +2 -0
  102. package/dist/jsx/jsx-dev-runtime.d.ts +2 -0
  103. package/dist/jsx/jsx-runtime.d.ts +3 -0
  104. package/dist/jsx/types.d.ts +35 -0
  105. package/dist/jsx/types.js +4 -0
  106. package/dist/jsx-dev-runtime.d.ts +2 -0
  107. package/dist/jsx-dev-runtime.js +8 -0
  108. package/dist/jsx-runtime.d.ts +2 -0
  109. package/dist/jsx-runtime.js +11 -0
  110. package/dist/reactivity/__tests__/context-stack.test.d.ts +1 -0
  111. package/dist/reactivity/__tests__/nested-effects-untrack.test.d.ts +22 -0
  112. package/dist/reactivity/context-scope.d.ts +57 -0
  113. package/dist/reactivity/context-scope.js +35 -0
  114. package/dist/reactivity/decorators/__tests__/ctx-integration.test.d.ts +5 -0
  115. package/dist/reactivity/decorators/__tests__/ctx-loop.test.d.ts +10 -0
  116. package/dist/reactivity/decorators/__tests__/state-intelligent.test.d.ts +1 -0
  117. package/dist/reactivity/decorators/computed.d.ts +6 -0
  118. package/dist/reactivity/decorators/computed.js +17 -0
  119. package/dist/reactivity/decorators/create-event-decorator.d.ts +5 -0
  120. package/dist/reactivity/decorators/create-event-decorator.js +28 -0
  121. package/dist/reactivity/decorators/ctx.d.ts +9 -0
  122. package/dist/reactivity/decorators/ctx.js +91 -0
  123. package/dist/reactivity/decorators/effect.d.ts +9 -0
  124. package/dist/reactivity/decorators/effect.js +24 -0
  125. package/dist/reactivity/decorators/resource.d.ts +48 -0
  126. package/dist/reactivity/decorators/resource.js +20 -0
  127. package/dist/reactivity/decorators/state.d.ts +8 -0
  128. package/dist/reactivity/decorators/state.js +68 -0
  129. package/dist/reactivity/decorators/store.d.ts +6 -0
  130. package/dist/reactivity/decorators/store.js +25 -0
  131. package/dist/reactivity/phase-scheduler.d.ts +81 -0
  132. package/dist/reactivity/phase-scheduler.js +88 -0
  133. package/dist/reactivity/phase-scheduler.test.d.ts +1 -0
  134. package/dist/reactivity/reactive-cache.d.ts +21 -0
  135. package/dist/reactivity/reactive-cache.js +31 -0
  136. package/dist/reactivity/reactive-cache.test.d.ts +1 -0
  137. package/dist/reactivity/reactive-context.d.ts +152 -0
  138. package/dist/reactivity/reactive-context.js +184 -0
  139. package/dist/reactivity/signals/__tests__/composicion-automatica.test.d.ts +1 -0
  140. package/dist/reactivity/signals/__tests__/composite/nivel-1-estructura-basica.test.d.ts +1 -0
  141. package/dist/reactivity/signals/__tests__/composite/nivel-2-registro-subscribers.test.d.ts +1 -0
  142. package/dist/reactivity/signals/__tests__/composite/nivel-3-notificaciones-basicas.test.d.ts +1 -0
  143. package/dist/reactivity/signals/__tests__/composite/nivel-4-comparacion-valores.test.d.ts +1 -0
  144. package/dist/reactivity/signals/__tests__/composite/nivel-5-tracking-automatico.test.d.ts +1 -0
  145. package/dist/reactivity/signals/__tests__/composite/nivel-6-anti-glitch.test.d.ts +1 -0
  146. package/dist/reactivity/signals/__tests__/composite/nivel-7-objetos-anidados.test.d.ts +1 -0
  147. package/dist/reactivity/signals/__tests__/composite/nivel-8-observable-array-support.test.d.ts +1 -0
  148. package/dist/reactivity/signals/__tests__/composite-shallow-tracking.test.d.ts +1 -0
  149. package/dist/reactivity/signals/__tests__/effect.test.d.ts +1 -0
  150. package/dist/reactivity/signals/__tests__/reactive-array/nivel-1-estructura-basica.test.d.ts +1 -0
  151. package/dist/reactivity/signals/__tests__/reactive-array/nivel-2-metodos-mutadores.test.d.ts +1 -0
  152. package/dist/reactivity/signals/__tests__/reactive-array/nivel-3-tracking-por-indice.test.d.ts +1 -0
  153. package/dist/reactivity/signals/__tests__/reactive-array/nivel-4-tracking-length.test.d.ts +1 -0
  154. package/dist/reactivity/signals/__tests__/reactive-array/nivel-5-tracking-mutation.test.d.ts +1 -0
  155. package/dist/reactivity/signals/__tests__/reactive-array/nivel-6-metodos-no-mutadores.test.d.ts +1 -0
  156. package/dist/reactivity/signals/__tests__/reactive-array/nivel-7-composicion-bidireccional.test.d.ts +1 -0
  157. package/dist/reactivity/signals/__tests__/reactive-array/nivel-8-proxies.test.d.ts +1 -0
  158. package/dist/reactivity/signals/__tests__/reactive-array/nivel-9-derived-cache-optimization.test.d.ts +1 -0
  159. package/dist/reactivity/signals/__tests__/resource.test.d.ts +1 -0
  160. package/dist/reactivity/signals/__tests__/signal.test.d.ts +1 -0
  161. package/dist/reactivity/signals/array-strategies.d.ts +120 -0
  162. package/dist/reactivity/signals/array-strategies.js +261 -0
  163. package/dist/reactivity/signals/composite.d.ts +89 -0
  164. package/dist/reactivity/signals/composite.js +145 -0
  165. package/dist/reactivity/signals/computed.d.ts +61 -0
  166. package/dist/reactivity/signals/computed.js +107 -0
  167. package/dist/reactivity/signals/computed.test.d.ts +1 -0
  168. package/dist/reactivity/signals/derived.d.ts +10 -0
  169. package/dist/reactivity/signals/derived.js +24 -0
  170. package/dist/reactivity/signals/effect.d.ts +27 -0
  171. package/dist/reactivity/signals/effect.js +46 -0
  172. package/dist/reactivity/signals/event.d.ts +9 -0
  173. package/dist/reactivity/signals/event.js +15 -0
  174. package/dist/reactivity/signals/reactive-array.d.ts +133 -0
  175. package/dist/reactivity/signals/reactive-array.js +490 -0
  176. package/dist/reactivity/signals/reactive-proxy.d.ts +54 -0
  177. package/dist/reactivity/signals/reactive-proxy.js +299 -0
  178. package/dist/reactivity/signals/reactive-tracking.test.d.ts +1 -0
  179. package/dist/reactivity/signals/resource.d.ts +9 -0
  180. package/dist/reactivity/signals/resource.js +58 -0
  181. package/dist/reactivity/signals/signal.d.ts +39 -0
  182. package/dist/reactivity/signals/signal.js +56 -0
  183. package/dist/reactivity/signals/subscription-management.test.d.ts +1 -0
  184. package/dist/reactivity/types.d.ts +12 -0
  185. package/dist/router/__tests__/link-behavior-active-class.test.d.ts +1 -0
  186. package/dist/router/__tests__/loop-detector.test.d.ts +1 -0
  187. package/dist/router/__tests__/params-container-resolution.test.d.ts +1 -0
  188. package/dist/router/__tests__/router-generated-routes.test.d.ts +1 -0
  189. package/dist/router/__tests__/router-params-granular.test.d.ts +1 -0
  190. package/dist/router/__tests__/router-params-simple.test.d.ts +1 -0
  191. package/dist/router/__tests__/router-query-params.test.d.ts +1 -0
  192. package/dist/router/__tests__/router-route-candidates.test.d.ts +1 -0
  193. package/dist/router/__tests__/routeview-app-articles.test.d.ts +1 -0
  194. package/dist/router/__tests__/routeview-debug.test.d.ts +1 -0
  195. package/dist/router/__tests__/routeview-integration.test.d.ts +1 -0
  196. package/dist/router/__tests__/routeview-this.test.d.ts +1 -0
  197. package/dist/router/decorators/base-policy.d.ts +141 -0
  198. package/dist/router/decorators/base-policy.js +63 -0
  199. package/dist/router/decorators/index.d.ts +6 -0
  200. package/dist/router/decorators/params.d.ts +31 -0
  201. package/dist/router/decorators/params.js +97 -0
  202. package/dist/router/decorators/route-metadata.d.ts +11 -0
  203. package/dist/router/decorators/route-metadata.js +23 -0
  204. package/dist/router/decorators/route.d.ts +39 -0
  205. package/dist/router/decorators/route.js +7 -0
  206. package/dist/router/link.behavior.d.ts +87 -0
  207. package/dist/router/link.behavior.js +227 -0
  208. package/dist/router/policy-evaluator.d.ts +81 -0
  209. package/dist/router/policy-evaluator.js +209 -0
  210. package/dist/router/route-view.d.ts +56 -0
  211. package/dist/router/route-view.js +156 -0
  212. package/dist/router/router.d.ts +67 -0
  213. package/dist/router/router.js +308 -0
  214. package/dist/router/static-analysis/index.d.ts +37 -0
  215. package/dist/router/static-analysis/parser.d.ts +14 -0
  216. package/dist/router/static-analysis/parser.js +147 -0
  217. package/dist/router/static-analysis/scanner.d.ts +27 -0
  218. package/dist/router/static-analysis/scanner.js +91 -0
  219. package/dist/router/trie.d.ts +14 -0
  220. package/dist/router/trie.js +126 -0
  221. package/dist/router/trie.types.d.ts +36 -0
  222. package/dist/styles/base-style-sheet.d.ts +96 -0
  223. package/dist/styles/base-style-sheet.js +149 -0
  224. package/dist/styles/decorators/factories.d.ts +76 -0
  225. package/dist/styles/decorators/factories.js +11 -0
  226. package/dist/styles/decorators/keyframes.d.ts +238 -0
  227. package/dist/styles/decorators/keyframes.js +79 -0
  228. package/dist/styles/decorators/rule.d.ts +177 -0
  229. package/dist/styles/decorators/rule.js +72 -0
  230. package/dist/styles/decorators/scope.d.ts +66 -0
  231. package/dist/styles/decorators/scope.js +17 -0
  232. package/dist/styles/decorators/style.d.ts +1 -0
  233. package/dist/styles/decorators/style.js +20 -0
  234. package/dist/styles/decorators/useStyles.d.ts +5 -0
  235. package/dist/styles/decorators/useStyles.js +29 -0
  236. package/dist/styles/global-styles-registry.d.ts +72 -0
  237. package/dist/styles/global-styles-registry.js +155 -0
  238. package/dist/types.d.ts +1 -0
  239. package/dist/vite-plugins/__tests__/jsx-control-flow-transform.test.d.ts +1 -0
  240. package/dist/vite-plugins/index.d.ts +4 -0
  241. package/dist/vite-plugins/index.js +10 -0
  242. package/dist/vite-plugins/jsx-contextual.d.ts +7 -0
  243. package/dist/vite-plugins/jsx-contextual.js +53 -0
  244. package/dist/vite-plugins/jsx-control-flow-transform.d.ts +60 -0
  245. package/dist/vite-plugins/jsx-control-flow-transform.js +180 -0
  246. package/dist/vite-plugins/jsx-signals.d.ts +2 -0
  247. package/dist/vite-plugins/jsx-signals.js +124 -0
  248. package/dist/vite-plugins/router/route-generator-plugin.d.ts +63 -0
  249. package/dist/vite-plugins/router/route-generator-plugin.js +310 -0
  250. package/package.json +85 -0
@@ -0,0 +1,490 @@
1
+ import { reactiveContext } from "../reactive-context.js";
2
+ import { phaseScheduler } from "../phase-scheduler.js";
3
+ import { getOrCreateReactive } from "../reactive-cache.js";
4
+ import { OwnedArrayStrategy, DerivedArrayStrategy, FilteredArrayStrategy } from "./array-strategies.js";
5
+ class ReactiveArray {
6
+ constructor(itemsOrConfig) {
7
+ this.subscribers = /* @__PURE__ */ new Map();
8
+ this.mapCache = /* @__PURE__ */ new Map();
9
+ if (Array.isArray(itemsOrConfig) || itemsOrConfig === void 0) {
10
+ const items = itemsOrConfig || [];
11
+ this.ownedStrategy = new OwnedArrayStrategy([...items]);
12
+ this.strategy = this.ownedStrategy;
13
+ } else {
14
+ const { source } = itemsOrConfig;
15
+ if ("transform" in itemsOrConfig) {
16
+ this.strategy = new DerivedArrayStrategy(
17
+ source,
18
+ itemsOrConfig.transform,
19
+ () => this._notifyMutation()
20
+ );
21
+ } else if ("predicate" in itemsOrConfig) {
22
+ this.strategy = new FilteredArrayStrategy(
23
+ source,
24
+ itemsOrConfig.predicate,
25
+ () => this._notifyMutation()
26
+ );
27
+ } else {
28
+ throw new Error("Config must contain either transform or predicate");
29
+ }
30
+ }
31
+ }
32
+ /**
33
+ * Registra un callback que se llama síncronamente antes de notificar subscribers
34
+ */
35
+ onChange(callback) {
36
+ this.onChangeCallback = callback;
37
+ }
38
+ /**
39
+ * Retorna el array plano subyacente (sin reactividad)
40
+ * Útil para serialización o interoperación con código no reactivo
41
+ */
42
+ getPlainValue() {
43
+ return this.strategy.getItems();
44
+ }
45
+ /**
46
+ * Getter reactivo para la longitud del array
47
+ */
48
+ get length() {
49
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
50
+ this._subscribe("length", reactiveContext.currentComputation);
51
+ }
52
+ return this.strategy.getLength();
53
+ }
54
+ /**
55
+ * Método at() reactivo que soporta índices negativos
56
+ * Similar a array.at() pero con tracking granular por índice
57
+ */
58
+ at(index) {
59
+ const normalizedIndex = index < 0 ? this.strategy.getLength() + index : index;
60
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
61
+ this._subscribe(normalizedIndex, reactiveContext.currentComputation);
62
+ }
63
+ const value = this.strategy.getAt(index);
64
+ if (value !== null && value !== void 0 && (typeof value === "object" || Array.isArray(value))) {
65
+ const wrapped = getOrCreateReactive(value);
66
+ return wrapped;
67
+ }
68
+ return value;
69
+ }
70
+ /**
71
+ * Asegura que el array esté en modo owned (tiene datos propios)
72
+ * Lanza error si se intenta mutar un array derivado
73
+ */
74
+ ensureOwned() {
75
+ if (!this.ownedStrategy) {
76
+ throw new Error("Cannot mutate a derived array. Derived arrays are read-only.");
77
+ }
78
+ return this.ownedStrategy;
79
+ }
80
+ // --- MÉTODOS MUTADORES ---
81
+ push(...items) {
82
+ const owned = this.ensureOwned();
83
+ const oldLength = this.strategy.getLength();
84
+ const result = owned.push(...items);
85
+ if (this.onChangeCallback) {
86
+ this.onChangeCallback("push", items);
87
+ }
88
+ this._notifyMutation();
89
+ if (result !== oldLength) {
90
+ this._notifyLength();
91
+ }
92
+ return result;
93
+ }
94
+ pop() {
95
+ const owned = this.ensureOwned();
96
+ const oldLength = this.strategy.getLength();
97
+ const result = owned.pop();
98
+ if (this.onChangeCallback) {
99
+ this.onChangeCallback("pop", result);
100
+ }
101
+ if (oldLength !== this.strategy.getLength()) {
102
+ this._notifyLength();
103
+ this._notify(oldLength - 1);
104
+ }
105
+ this._notifyMutation();
106
+ return result;
107
+ }
108
+ shift() {
109
+ const owned = this.ensureOwned();
110
+ const oldLength = this.strategy.getLength();
111
+ const result = owned.shift();
112
+ if (this.onChangeCallback) {
113
+ this.onChangeCallback("shift");
114
+ }
115
+ if (oldLength !== this.strategy.getLength()) {
116
+ this._notifyLength();
117
+ }
118
+ this._notifyAllIndices();
119
+ this._notifyMutation();
120
+ return result;
121
+ }
122
+ unshift(...items) {
123
+ const owned = this.ensureOwned();
124
+ const oldLength = this.strategy.getLength();
125
+ const result = owned.unshift(...items);
126
+ if (this.onChangeCallback) {
127
+ this.onChangeCallback("unshift", items);
128
+ }
129
+ this._notifyMutation();
130
+ if (result !== oldLength) {
131
+ this._notifyLength();
132
+ }
133
+ this._notifyAllIndices();
134
+ return result;
135
+ }
136
+ splice(start, deleteCount, ...items) {
137
+ const owned = this.ensureOwned();
138
+ const oldLength = this.strategy.getLength();
139
+ const actualDeleteCount = deleteCount ?? oldLength - start;
140
+ const result = owned.splice(start, actualDeleteCount, ...items);
141
+ if (this.onChangeCallback) {
142
+ this.onChangeCallback("splice", start, actualDeleteCount, ...items);
143
+ }
144
+ const itemsAdded = items.length;
145
+ this._notifyMutation();
146
+ if (oldLength !== this.strategy.getLength()) {
147
+ this._notifyLength();
148
+ }
149
+ if (actualDeleteCount > 0 || itemsAdded > 0) {
150
+ const startIndex = Math.max(0, start);
151
+ if (actualDeleteCount === itemsAdded) {
152
+ for (let i = startIndex; i < startIndex + itemsAdded; i++) {
153
+ this._notify(i);
154
+ }
155
+ } else {
156
+ this._notifyIndicesFrom(startIndex);
157
+ }
158
+ }
159
+ return result;
160
+ }
161
+ sort(compareFn) {
162
+ const owned = this.ensureOwned();
163
+ if (this.onChangeCallback) {
164
+ this.onChangeCallback("sort", compareFn);
165
+ }
166
+ owned.sort(compareFn);
167
+ this._notifyMutation();
168
+ this._notifyAllIndices();
169
+ return this;
170
+ }
171
+ reverse() {
172
+ const owned = this.ensureOwned();
173
+ if (this.onChangeCallback) {
174
+ this.onChangeCallback("reverse");
175
+ }
176
+ owned.reverse();
177
+ this._notifyMutation();
178
+ this._notifyAllIndices();
179
+ return this;
180
+ }
181
+ fill(value, start, end) {
182
+ const owned = this.ensureOwned();
183
+ if (this.onChangeCallback) {
184
+ this.onChangeCallback("fill", value, start, end);
185
+ }
186
+ owned.fill(value, start, end);
187
+ this._notifyMutation();
188
+ const actualStart = start ?? 0;
189
+ const actualEnd = end ?? this.strategy.getLength();
190
+ if (actualStart < actualEnd) {
191
+ this._notifyIndicesFrom(actualStart);
192
+ }
193
+ return this;
194
+ }
195
+ // --- MÉTODOS NO-MUTADORES (LECTURA) ---
196
+ /**
197
+ * map() ahora retorna un ReactiveArray derivado, no un array plano
198
+ * Este es el corazón de tu insight: mantener la reactividad en la cadena
199
+ *
200
+ * MEMOIZACIÓN INTELIGENTE:
201
+ * - Cachea el array derivado por toString() del callback
202
+ * - Captura dependencias externas (signals que el callback lee)
203
+ * - Si las dependencias no cambiaron, retorna el MISMO array derivado
204
+ * - Esto permite granularidad: push/pop solo afectan nuevos elementos
205
+ */
206
+ map(callback) {
207
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
208
+ this._subscribe("mutation", reactiveContext.currentComputation);
209
+ }
210
+ const callbackStr = callback.toString();
211
+ if (this.mapCache.has(callbackStr)) {
212
+ const cached = this.mapCache.get(callbackStr);
213
+ const currentDepsValues = Array.from(cached.externalDeps).map((dep) => {
214
+ try {
215
+ return dep.get ? dep.get() : dep;
216
+ } catch {
217
+ return dep;
218
+ }
219
+ });
220
+ const depsChanged = cached.depsValues.length !== currentDepsValues.length || cached.depsValues.some((v, i) => v !== currentDepsValues[i]);
221
+ if (!depsChanged) {
222
+ return cached.derived;
223
+ }
224
+ this.mapCache.delete(callbackStr);
225
+ }
226
+ const externalDeps = /* @__PURE__ */ new Set();
227
+ reactiveContext.onTrack;
228
+ const wrappedCallback = (value, index) => {
229
+ const originalOnTrack = reactiveContext.onTrack;
230
+ reactiveContext.onTrack = (signal) => {
231
+ externalDeps.add(signal);
232
+ if (originalOnTrack) originalOnTrack(signal);
233
+ };
234
+ try {
235
+ return callback(value, index, this.strategy.getItems());
236
+ } finally {
237
+ reactiveContext.onTrack = originalOnTrack;
238
+ }
239
+ };
240
+ const derived = new ReactiveArray({
241
+ source: this,
242
+ transform: wrappedCallback
243
+ });
244
+ if (this.length > 0) {
245
+ const prevTracking = reactiveContext.isTracking;
246
+ reactiveContext.setTracking(true);
247
+ try {
248
+ derived.at(0);
249
+ } finally {
250
+ reactiveContext.setTracking(prevTracking);
251
+ }
252
+ }
253
+ const depsValues = Array.from(externalDeps).map((dep) => {
254
+ try {
255
+ return dep.get ? dep.get() : dep;
256
+ } catch {
257
+ return dep;
258
+ }
259
+ });
260
+ this.mapCache.set(callbackStr, {
261
+ derived,
262
+ externalDeps,
263
+ depsValues
264
+ });
265
+ return derived;
266
+ }
267
+ /**
268
+ * filter() también retorna un ReactiveArray derivado
269
+ * Implementación especial que necesita manejar índices no lineales
270
+ */
271
+ filter(callback) {
272
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
273
+ this._subscribe("mutation", reactiveContext.currentComputation);
274
+ }
275
+ return new ReactiveArray({
276
+ source: this,
277
+ predicate: callback
278
+ });
279
+ }
280
+ slice(start, end) {
281
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
282
+ this._subscribe("mutation", reactiveContext.currentComputation);
283
+ }
284
+ return this.strategy.getItems().slice(start, end);
285
+ }
286
+ concat(...items) {
287
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
288
+ this._subscribe("mutation", reactiveContext.currentComputation);
289
+ }
290
+ const base = this.strategy.getItems();
291
+ const result = [...base];
292
+ for (const item of items) {
293
+ if (Array.isArray(item)) {
294
+ result.push(...item);
295
+ } else {
296
+ result.push(item);
297
+ }
298
+ }
299
+ return result;
300
+ }
301
+ find(callback) {
302
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
303
+ this._subscribe("mutation", reactiveContext.currentComputation);
304
+ }
305
+ return this.strategy.getItems().find(callback);
306
+ }
307
+ findIndex(callback) {
308
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
309
+ this._subscribe("mutation", reactiveContext.currentComputation);
310
+ }
311
+ return this.strategy.getItems().findIndex(callback);
312
+ }
313
+ indexOf(searchElement, fromIndex) {
314
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
315
+ this._subscribe("mutation", reactiveContext.currentComputation);
316
+ }
317
+ return this.strategy.getItems().indexOf(searchElement, fromIndex);
318
+ }
319
+ includes(searchElement, fromIndex) {
320
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
321
+ this._subscribe("mutation", reactiveContext.currentComputation);
322
+ }
323
+ return this.strategy.getItems().includes(searchElement, fromIndex);
324
+ }
325
+ forEach(callback) {
326
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
327
+ this._subscribe("mutation", reactiveContext.currentComputation);
328
+ }
329
+ this.strategy.getItems().forEach(callback);
330
+ }
331
+ some(callback) {
332
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
333
+ this._subscribe("mutation", reactiveContext.currentComputation);
334
+ }
335
+ return this.strategy.getItems().some(callback);
336
+ }
337
+ every(callback) {
338
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
339
+ this._subscribe("mutation", reactiveContext.currentComputation);
340
+ }
341
+ return this.strategy.getItems().every(callback);
342
+ }
343
+ reduce(callback, initialValue) {
344
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
345
+ this._subscribe("mutation", reactiveContext.currentComputation);
346
+ }
347
+ return this.strategy.getItems().reduce(callback, initialValue);
348
+ }
349
+ reduceRight(callback, initialValue) {
350
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
351
+ this._subscribe("mutation", reactiveContext.currentComputation);
352
+ }
353
+ return this.strategy.getItems().reduceRight(callback, initialValue);
354
+ }
355
+ // --- MÉTODOS DE CONVERSIÓN ---
356
+ join(separator) {
357
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
358
+ this._subscribe("mutation", reactiveContext.currentComputation);
359
+ }
360
+ return this.strategy.getItems().join(separator);
361
+ }
362
+ toString() {
363
+ return this.strategy.getItems().toString();
364
+ }
365
+ toLocaleString() {
366
+ return this.strategy.getItems().toLocaleString();
367
+ }
368
+ // --- ITERADORES ---
369
+ [Symbol.iterator]() {
370
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
371
+ this._subscribe("mutation", reactiveContext.currentComputation);
372
+ }
373
+ return this.strategy.getItems()[Symbol.iterator]();
374
+ }
375
+ entries() {
376
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
377
+ this._subscribe("mutation", reactiveContext.currentComputation);
378
+ }
379
+ return this.strategy.getItems().entries();
380
+ }
381
+ keys() {
382
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
383
+ this._subscribe("mutation", reactiveContext.currentComputation);
384
+ }
385
+ return this.strategy.getItems().keys();
386
+ }
387
+ values() {
388
+ if (reactiveContext.currentComputation && reactiveContext.isTracking) {
389
+ this._subscribe("mutation", reactiveContext.currentComputation);
390
+ }
391
+ return this.strategy.getItems().values();
392
+ }
393
+ // --- GESTIÓN INTERNA DE SUBSCRIPTIONS ---
394
+ /**
395
+ * Registra un subscriber para un tipo específico de cambio
396
+ */
397
+ _subscribe(key, subscriber) {
398
+ if (!this.subscribers.has(key)) {
399
+ this.subscribers.set(key, /* @__PURE__ */ new Set());
400
+ }
401
+ this.subscribers.get(key).add(subscriber);
402
+ }
403
+ /**
404
+ * Notifica a subscribers de un tipo específico de cambio
405
+ */
406
+ _notify(key) {
407
+ const subs = this.subscribers.get(key);
408
+ if (subs && subs.size > 0) {
409
+ subs.forEach((subscriber) => {
410
+ if (subscriber._isComputation) {
411
+ subscriber();
412
+ } else {
413
+ phaseScheduler.schedule(subscriber);
414
+ }
415
+ });
416
+ }
417
+ }
418
+ /**
419
+ * Notifica que el array mutó (cualquier cambio en contenido)
420
+ */
421
+ _notifyMutation() {
422
+ this._notify("mutation");
423
+ }
424
+ /**
425
+ * Notifica que la longitud cambió
426
+ */
427
+ _notifyLength() {
428
+ this._notify("length");
429
+ }
430
+ /**
431
+ * Notifica a todos los índices numéricos suscritos
432
+ * Se usa cuando operaciones como shift/unshift/splice afectan múltiples índices
433
+ */
434
+ _notifyAllIndices() {
435
+ for (const key of this.subscribers.keys()) {
436
+ if (typeof key === "number") {
437
+ this._notify(key);
438
+ }
439
+ }
440
+ }
441
+ /**
442
+ * Notifica todos los índices desde start hacia adelante
443
+ * Útil cuando splice/insert afecta índices posteriores
444
+ */
445
+ _notifyIndicesFrom(start) {
446
+ for (const key of this.subscribers.keys()) {
447
+ if (typeof key === "number" && key >= start) {
448
+ this._notify(key);
449
+ }
450
+ }
451
+ }
452
+ // --- MÉTODOS DE DEBUG/INSPECCIÓN ---
453
+ getSubscribers(key) {
454
+ return this.subscribers.get(key);
455
+ }
456
+ getSubscribedKeys() {
457
+ return Array.from(this.subscribers.keys());
458
+ }
459
+ }
460
+ function collection(items) {
461
+ return new ReactiveArray(items);
462
+ }
463
+ function isObservableArray(value) {
464
+ return value instanceof ReactiveArray;
465
+ }
466
+ function isCollection(value) {
467
+ return value instanceof ReactiveArray;
468
+ }
469
+ function isReactiveArrayLike(value) {
470
+ if (value instanceof ReactiveArray) return true;
471
+ if (value && typeof value === "object" && value.__isReactive && value.__getReactiveArray) {
472
+ return true;
473
+ }
474
+ return false;
475
+ }
476
+ function unwrapReactiveArray(value) {
477
+ if (value instanceof ReactiveArray) return value;
478
+ if (value && typeof value === "object" && value.__isReactive && value.__getReactiveArray) {
479
+ return value.__getReactiveArray;
480
+ }
481
+ return null;
482
+ }
483
+ export {
484
+ ReactiveArray,
485
+ collection,
486
+ isCollection,
487
+ isObservableArray,
488
+ isReactiveArrayLike,
489
+ unwrapReactiveArray
490
+ };
@@ -0,0 +1,54 @@
1
+ import { CompositeSignal } from './composite.js';
2
+ import { ReactiveArray } from './reactive-array.js';
3
+ /**
4
+ * Crea un Proxy para un CompositeSignal que permite acceso y modificación
5
+ * usando sintaxis nativa de JavaScript.
6
+ *
7
+ * Características:
8
+ * - Lectura de propiedades: proxy.name accede a composite.get('name')
9
+ * - Escritura de propiedades: proxy.name = 'value' ejecuta composite.set('name', 'value')
10
+ * - Composición automática: valores nested son automáticamente envueltos en Proxies
11
+ * - Propiedades especiales: __isReactive, __getCompositeSignal
12
+ *
13
+ * @param composite - El CompositeSignal a envolver
14
+ * @returns Un Proxy que se comporta como un objeto plano pero mantiene reactividad
15
+ */
16
+ export declare function createObjectProxy<T extends Record<string, any>>(composite: CompositeSignal<T>): T;
17
+ /**
18
+ * Crea un Proxy para un ReactiveArray que permite acceso y modificación
19
+ * usando sintaxis nativa de Arrays de JavaScript.
20
+ *
21
+ * Características:
22
+ * - Acceso por índice: proxy[0] accede a reactiveArray.at(0)
23
+ * - Métodos nativos: push, pop, map, filter, etc. funcionan como en arrays normales
24
+ * - Iteración: for...of, forEach, etc. funcionan nativamente
25
+ * - Composición automática: elementos nested son automáticamente envueltos en Proxies
26
+ * - Propiedades especiales: __isReactive, __getReactiveArray
27
+ *
28
+ * @param reactiveArray - El ReactiveArray a envolver
29
+ * @returns Un Proxy que se comporta como un Array plano pero mantiene reactividad
30
+ */
31
+ export declare function createArrayProxy<T>(reactiveArray: ReactiveArray<T>): T[];
32
+ /**
33
+ * API principal para crear stores reactivos con sintaxis nativa de JavaScript.
34
+ *
35
+ * Esta función es el punto de entrada recomendado para usuarios del framework.
36
+ * Automáticamente detecta si el estado inicial es un objeto o array y crea
37
+ * el tipo de Proxy apropiado.
38
+ *
39
+ * Ejemplos:
40
+ * ```typescript
41
+ * // Objeto reactivo
42
+ * const app = createStore({ user: { name: 'Julian' } });
43
+ * app.user.name = 'Julián'; // Sintaxis nativa con reactividad completa
44
+ *
45
+ * // Array reactivo
46
+ * const items = createStore([1, 2, 3]);
47
+ * items.push(4); // Métodos nativos de Array
48
+ * items[0] = 10; // Asignación por índice
49
+ * ```
50
+ *
51
+ * @param initialState - El estado inicial (objeto o array)
52
+ * @returns Un Proxy que permite sintaxis nativa con reactividad completa
53
+ */
54
+ export declare function createStore<T extends Record<string, any> | any[]>(initialState: T): T;