@fluixi/reactive 1.0.0-alpha.100

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 (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +280 -0
  3. package/dist/cdn/reactive.cjs +2803 -0
  4. package/dist/cdn/reactive.d.ts +11 -0
  5. package/dist/cdn/reactive.d.ts.map +1 -0
  6. package/dist/cdn/reactive.global.js +2 -0
  7. package/dist/cdn/reactive.js +10 -0
  8. package/dist/cdn/reactive.mjs +2787 -0
  9. package/dist/cdn/signal.cjs +299 -0
  10. package/dist/cdn/signal.d.ts +19 -0
  11. package/dist/cdn/signal.d.ts.map +1 -0
  12. package/dist/cdn/signal.global.js +2 -0
  13. package/dist/cdn/signal.js +18 -0
  14. package/dist/cdn/signal.mjs +276 -0
  15. package/dist/index.cjs +2803 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +1 -0
  19. package/dist/index.mjs +2787 -0
  20. package/dist/lib/index.cjs +2804 -0
  21. package/dist/lib/index.d.ts +8 -0
  22. package/dist/lib/index.d.ts.map +1 -0
  23. package/dist/lib/index.js +11 -0
  24. package/dist/lib/index.mjs +2789 -0
  25. package/dist/lib/observable/index.cjs +386 -0
  26. package/dist/lib/observable/index.d.ts +4 -0
  27. package/dist/lib/observable/index.d.ts.map +1 -0
  28. package/dist/lib/observable/index.js +3 -0
  29. package/dist/lib/observable/index.mjs +364 -0
  30. package/dist/lib/observable/observable.cjs +384 -0
  31. package/dist/lib/observable/observable.d.ts +246 -0
  32. package/dist/lib/observable/observable.d.ts.map +1 -0
  33. package/dist/lib/observable/observable.js +268 -0
  34. package/dist/lib/observable/observable.mjs +361 -0
  35. package/dist/lib/observable/subscription.cjs +180 -0
  36. package/dist/lib/observable/subscription.d.ts +58 -0
  37. package/dist/lib/observable/subscription.d.ts.map +1 -0
  38. package/dist/lib/observable/subscription.js +177 -0
  39. package/dist/lib/observable/subscription.mjs +157 -0
  40. package/dist/lib/observable/types.cjs +18 -0
  41. package/dist/lib/observable/types.d.ts +44 -0
  42. package/dist/lib/observable/types.d.ts.map +1 -0
  43. package/dist/lib/observable/types.js +1 -0
  44. package/dist/lib/observable/types.mjs +0 -0
  45. package/dist/lib/predicates.cjs +44 -0
  46. package/dist/lib/predicates.d.ts +37 -0
  47. package/dist/lib/predicates.d.ts.map +1 -0
  48. package/dist/lib/predicates.js +62 -0
  49. package/dist/lib/predicates.mjs +23 -0
  50. package/dist/lib/signal/api.cjs +592 -0
  51. package/dist/lib/signal/api.d.ts +227 -0
  52. package/dist/lib/signal/api.d.ts.map +1 -0
  53. package/dist/lib/signal/api.js +228 -0
  54. package/dist/lib/signal/api.mjs +569 -0
  55. package/dist/lib/signal/cached-resource.cjs +726 -0
  56. package/dist/lib/signal/cached-resource.d.ts +86 -0
  57. package/dist/lib/signal/cached-resource.d.ts.map +1 -0
  58. package/dist/lib/signal/cached-resource.js +250 -0
  59. package/dist/lib/signal/cached-resource.mjs +704 -0
  60. package/dist/lib/signal/graph/children.cjs +326 -0
  61. package/dist/lib/signal/graph/children.d.ts +2 -0
  62. package/dist/lib/signal/graph/children.d.ts.map +1 -0
  63. package/dist/lib/signal/graph/children.js +30 -0
  64. package/dist/lib/signal/graph/children.mjs +303 -0
  65. package/dist/lib/signal/graph/compat.cjs +590 -0
  66. package/dist/lib/signal/graph/compat.d.ts +66 -0
  67. package/dist/lib/signal/graph/compat.d.ts.map +1 -0
  68. package/dist/lib/signal/graph/compat.js +197 -0
  69. package/dist/lib/signal/graph/compat.mjs +568 -0
  70. package/dist/lib/signal/graph/core.cjs +295 -0
  71. package/dist/lib/signal/graph/core.d.ts +99 -0
  72. package/dist/lib/signal/graph/core.d.ts.map +1 -0
  73. package/dist/lib/signal/graph/core.js +268 -0
  74. package/dist/lib/signal/graph/core.mjs +273 -0
  75. package/dist/lib/signal/graph/debounced.cjs +680 -0
  76. package/dist/lib/signal/graph/debounced.d.ts +67 -0
  77. package/dist/lib/signal/graph/debounced.d.ts.map +1 -0
  78. package/dist/lib/signal/graph/debounced.js +92 -0
  79. package/dist/lib/signal/graph/debounced.mjs +657 -0
  80. package/dist/lib/signal/graph/derived.cjs +508 -0
  81. package/dist/lib/signal/graph/derived.d.ts +14 -0
  82. package/dist/lib/signal/graph/derived.d.ts.map +1 -0
  83. package/dist/lib/signal/graph/derived.js +65 -0
  84. package/dist/lib/signal/graph/derived.mjs +485 -0
  85. package/dist/lib/signal/graph/detect.cjs +66 -0
  86. package/dist/lib/signal/graph/detect.d.ts +17 -0
  87. package/dist/lib/signal/graph/detect.d.ts.map +1 -0
  88. package/dist/lib/signal/graph/detect.js +39 -0
  89. package/dist/lib/signal/graph/detect.mjs +45 -0
  90. package/dist/lib/signal/graph/error-boundary.cjs +313 -0
  91. package/dist/lib/signal/graph/error-boundary.d.ts +16 -0
  92. package/dist/lib/signal/graph/error-boundary.d.ts.map +1 -0
  93. package/dist/lib/signal/graph/error-boundary.js +34 -0
  94. package/dist/lib/signal/graph/error-boundary.mjs +290 -0
  95. package/dist/lib/signal/graph/index.cjs +305 -0
  96. package/dist/lib/signal/graph/index.d.ts +22 -0
  97. package/dist/lib/signal/graph/index.d.ts.map +1 -0
  98. package/dist/lib/signal/graph/index.js +21 -0
  99. package/dist/lib/signal/graph/index.mjs +283 -0
  100. package/dist/lib/signal/graph/observe.cjs +198 -0
  101. package/dist/lib/signal/graph/observe.d.ts +185 -0
  102. package/dist/lib/signal/graph/observe.d.ts.map +1 -0
  103. package/dist/lib/signal/graph/observe.js +198 -0
  104. package/dist/lib/signal/graph/observe.mjs +175 -0
  105. package/dist/lib/signal/graph/resource.cjs +632 -0
  106. package/dist/lib/signal/graph/resource.d.ts +39 -0
  107. package/dist/lib/signal/graph/resource.d.ts.map +1 -0
  108. package/dist/lib/signal/graph/resource.js +165 -0
  109. package/dist/lib/signal/graph/resource.mjs +609 -0
  110. package/dist/lib/signal/graph/runtime.cjs +522 -0
  111. package/dist/lib/signal/graph/runtime.d.ts +80 -0
  112. package/dist/lib/signal/graph/runtime.d.ts.map +1 -0
  113. package/dist/lib/signal/graph/runtime.js +358 -0
  114. package/dist/lib/signal/graph/runtime.mjs +499 -0
  115. package/dist/lib/signal/graph/signal-next.cjs +1249 -0
  116. package/dist/lib/signal/graph/signal-next.d.ts +38 -0
  117. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -0
  118. package/dist/lib/signal/graph/signal-next.js +44 -0
  119. package/dist/lib/signal/graph/signal-next.mjs +1227 -0
  120. package/dist/lib/signal/graph/ssr-hooks.cjs +89 -0
  121. package/dist/lib/signal/graph/ssr-hooks.d.ts +51 -0
  122. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -0
  123. package/dist/lib/signal/graph/ssr-hooks.js +80 -0
  124. package/dist/lib/signal/graph/ssr-hooks.mjs +68 -0
  125. package/dist/lib/signal/graph/state.cjs +72 -0
  126. package/dist/lib/signal/graph/state.d.ts +76 -0
  127. package/dist/lib/signal/graph/state.d.ts.map +1 -0
  128. package/dist/lib/signal/graph/state.js +99 -0
  129. package/dist/lib/signal/graph/state.mjs +49 -0
  130. package/dist/lib/signal/graph/suspense.cjs +313 -0
  131. package/dist/lib/signal/graph/suspense.d.ts +13 -0
  132. package/dist/lib/signal/graph/suspense.d.ts.map +1 -0
  133. package/dist/lib/signal/graph/suspense.js +36 -0
  134. package/dist/lib/signal/graph/suspense.mjs +290 -0
  135. package/dist/lib/signal/index-legacy.cjs +2582 -0
  136. package/dist/lib/signal/index-legacy.d.ts +12 -0
  137. package/dist/lib/signal/index-legacy.d.ts.map +1 -0
  138. package/dist/lib/signal/index-legacy.js +11 -0
  139. package/dist/lib/signal/index-legacy.mjs +2560 -0
  140. package/dist/lib/signal/index.cjs +1350 -0
  141. package/dist/lib/signal/index.d.ts +19 -0
  142. package/dist/lib/signal/index.d.ts.map +1 -0
  143. package/dist/lib/signal/index.js +19 -0
  144. package/dist/lib/signal/index.mjs +1328 -0
  145. package/dist/lib/signal/list.cjs +561 -0
  146. package/dist/lib/signal/list.d.ts +39 -0
  147. package/dist/lib/signal/list.d.ts.map +1 -0
  148. package/dist/lib/signal/list.js +172 -0
  149. package/dist/lib/signal/list.mjs +538 -0
  150. package/dist/lib/signal/resource-api.cjs +638 -0
  151. package/dist/lib/signal/resource-api.d.ts +19 -0
  152. package/dist/lib/signal/resource-api.d.ts.map +1 -0
  153. package/dist/lib/signal/resource-api.js +27 -0
  154. package/dist/lib/signal/resource-api.mjs +615 -0
  155. package/dist/lib/signal/signal.cjs +2035 -0
  156. package/dist/lib/signal/signal.d.ts +303 -0
  157. package/dist/lib/signal/signal.d.ts.map +1 -0
  158. package/dist/lib/signal/signal.js +1233 -0
  159. package/dist/lib/signal/signal.mjs +2012 -0
  160. package/dist/lib/signal/types.cjs +38 -0
  161. package/dist/lib/signal/types.d.ts +133 -0
  162. package/dist/lib/signal/types.d.ts.map +1 -0
  163. package/dist/lib/signal/types.js +38 -0
  164. package/dist/lib/signal/types.mjs +17 -0
  165. package/dist/lib/signal/utilities.cjs +1024 -0
  166. package/dist/lib/signal/utilities.d.ts +247 -0
  167. package/dist/lib/signal/utilities.d.ts.map +1 -0
  168. package/dist/lib/signal/utilities.js +346 -0
  169. package/dist/lib/signal/utilities.mjs +1002 -0
  170. package/dist/lib/store/api.cjs +662 -0
  171. package/dist/lib/store/api.d.ts +40 -0
  172. package/dist/lib/store/api.d.ts.map +1 -0
  173. package/dist/lib/store/api.js +63 -0
  174. package/dist/lib/store/api.mjs +646 -0
  175. package/dist/lib/store/index.cjs +741 -0
  176. package/dist/lib/store/index.d.ts +16 -0
  177. package/dist/lib/store/index.d.ts.map +1 -0
  178. package/dist/lib/store/index.js +13 -0
  179. package/dist/lib/store/index.mjs +726 -0
  180. package/dist/lib/store/setter.types.cjs +18 -0
  181. package/dist/lib/store/setter.types.d.ts +131 -0
  182. package/dist/lib/store/setter.types.d.ts.map +1 -0
  183. package/dist/lib/store/setter.types.js +65 -0
  184. package/dist/lib/store/setter.types.mjs +0 -0
  185. package/dist/lib/store/store.cjs +708 -0
  186. package/dist/lib/store/store.d.ts +142 -0
  187. package/dist/lib/store/store.d.ts.map +1 -0
  188. package/dist/lib/store/store.js +812 -0
  189. package/dist/lib/store/store.mjs +694 -0
  190. package/dist/lib/store/types.cjs +18 -0
  191. package/dist/lib/store/types.d.ts +57 -0
  192. package/dist/lib/store/types.d.ts.map +1 -0
  193. package/dist/lib/store/types.js +1 -0
  194. package/dist/lib/store/types.mjs +0 -0
  195. package/dist/lib/store/utils.cjs +43 -0
  196. package/dist/lib/store/utils.d.ts +13 -0
  197. package/dist/lib/store/utils.d.ts.map +1 -0
  198. package/dist/lib/store/utils.js +29 -0
  199. package/dist/lib/store/utils.mjs +22 -0
  200. package/dist/lib/subject.cjs +450 -0
  201. package/dist/lib/subject.d.ts +14 -0
  202. package/dist/lib/subject.d.ts.map +1 -0
  203. package/dist/lib/subject.js +81 -0
  204. package/dist/lib/subject.mjs +427 -0
  205. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  206. package/dist/version.generated.cjs +27 -0
  207. package/dist/version.generated.d.ts +3 -0
  208. package/dist/version.generated.d.ts.map +1 -0
  209. package/dist/version.generated.js +3 -0
  210. package/dist/version.generated.mjs +7 -0
  211. package/package.json +115 -0
@@ -0,0 +1,561 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/signal/list.ts
21
+ var list_exports = {};
22
+ __export(list_exports, {
23
+ indexArray: () => indexArray,
24
+ keyArray: () => keyArray,
25
+ mapArray: () => mapArray
26
+ });
27
+ module.exports = __toCommonJS(list_exports);
28
+
29
+ // src/version.generated.ts
30
+ var VERSION = "1.0.0-alpha.100";
31
+
32
+ // src/lib/signal/graph/state.ts
33
+ var MAJOR = VERSION.split(".")[0];
34
+ var KEY = `__fluixi_signal_state_v${MAJOR}__`;
35
+ var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
36
+ var defaultSchedule = (run) => {
37
+ if (typeof queueMicrotask === "function") queueMicrotask(run);
38
+ else void Promise.resolve().then(run);
39
+ };
40
+ function defaults() {
41
+ return {
42
+ consumer: null,
43
+ untracked: false,
44
+ owner: null,
45
+ queue: [],
46
+ scheduled: false,
47
+ flushing: false,
48
+ batchDepth: 0,
49
+ hostSchedule: defaultSchedule,
50
+ onSuspend: null,
51
+ onError: null,
52
+ observer: null
53
+ };
54
+ }
55
+ var realm = globalThis;
56
+ function backfillState(existing) {
57
+ const fresh = defaults();
58
+ const target = existing;
59
+ for (const field of Object.keys(fresh)) {
60
+ if (!(field in existing)) target[field] = fresh[field];
61
+ }
62
+ return existing;
63
+ }
64
+ function claim() {
65
+ const existing = realm[KEY];
66
+ return existing ? backfillState(existing) : realm[KEY] = defaults();
67
+ }
68
+ var G = claim();
69
+ (realm[VERSIONS_KEY] ??= []).push(VERSION);
70
+
71
+ // src/lib/signal/graph/observe.ts
72
+ function observeReactiveNodes(next) {
73
+ G.observer = next;
74
+ return () => {
75
+ if (G.observer === next) G.observer = null;
76
+ };
77
+ }
78
+ var running = [];
79
+ var origin;
80
+ var currentScope;
81
+ function reportReactiveNode(report) {
82
+ const observer = G.observer;
83
+ if (observer) {
84
+ observer.created(
85
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
86
+ );
87
+ }
88
+ }
89
+ function enterReactiveRun(node) {
90
+ if (!G.observer) return false;
91
+ running.push(node);
92
+ return true;
93
+ }
94
+ function exitReactiveRun() {
95
+ running.pop();
96
+ }
97
+ function reportReactiveRun(node) {
98
+ G.observer?.ran?.(node);
99
+ }
100
+ function reportReactiveWrite(node, by) {
101
+ G.observer?.wrote?.(node, by);
102
+ }
103
+ function reportReactiveDispose(node) {
104
+ G.observer?.disposed?.(node);
105
+ }
106
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
107
+ var hook = globalThis[HOOK];
108
+ if (typeof hook?.inject === "function") {
109
+ try {
110
+ hook.inject({ observeReactiveNodes, version: VERSION });
111
+ } catch {
112
+ }
113
+ }
114
+ function isObserved() {
115
+ return G.observer != null;
116
+ }
117
+
118
+ // src/lib/signal/graph/core.ts
119
+ var CLEAN = 0;
120
+ var CHECK = 1;
121
+ var DIRTY = 2;
122
+ var Source = class {
123
+ constructor() {
124
+ /** Computeds, and watched leaves, that read this node. */
125
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
+ this.observers = null;
127
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
128
+ this.watchers = null;
129
+ /** Bumped whenever this node's value actually changes (equality-gated). */
130
+ this.version = 0;
131
+ }
132
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
133
+ updateIfNecessary() {
134
+ }
135
+ /** Link the current consumer (if any) as an observer of this node. */
136
+ track() {
137
+ if (G.untracked) return;
138
+ const consumer = G.consumer;
139
+ if (!consumer) return;
140
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
141
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
142
+ }
143
+ };
144
+ var State = class extends Source {
145
+ constructor(value, options) {
146
+ super();
147
+ this._value = value;
148
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
149
+ }
150
+ get() {
151
+ this.track();
152
+ return this._value;
153
+ }
154
+ set(next) {
155
+ if (this._equals(this._value, next)) return;
156
+ this._value = next;
157
+ this.version++;
158
+ reportReactiveWrite(this, G.consumer);
159
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
160
+ notifyWatchers(this);
161
+ }
162
+ /** Read without subscribing (peek). */
163
+ peek() {
164
+ return this._value;
165
+ }
166
+ };
167
+ var Computed = class extends Source {
168
+ constructor(fn, options) {
169
+ super();
170
+ this._threw = false;
171
+ this._initialized = false;
172
+ this.state = DIRTY;
173
+ /** Nodes this computation read on its last run. Rebuilt on every run. */
174
+ this.sources = null;
175
+ this._fn = fn;
176
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
177
+ }
178
+ get() {
179
+ if (G.consumer === this) {
180
+ throw new Error("Signal.Computed cannot read itself");
181
+ }
182
+ this.track();
183
+ this.updateIfNecessary();
184
+ if (this._threw) throw this._error;
185
+ return this._value;
186
+ }
187
+ /** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
188
+ updateIfNecessary() {
189
+ if (this.state === CHECK) {
190
+ if (this.sources) {
191
+ for (const s of this.sources) {
192
+ s.updateIfNecessary();
193
+ if (this.state === DIRTY) break;
194
+ }
195
+ }
196
+ }
197
+ if (this.state === DIRTY || !this._initialized) this.recompute();
198
+ this.state = CLEAN;
199
+ }
200
+ recompute() {
201
+ if (this.sources) {
202
+ for (const s of this.sources) s.observers?.delete(this);
203
+ this.sources.clear();
204
+ }
205
+ const prevConsumer = G.consumer;
206
+ const prevUntracked = G.untracked;
207
+ const watched = enterReactiveRun(this);
208
+ G.consumer = this;
209
+ G.untracked = false;
210
+ let next;
211
+ let threw = false;
212
+ let err;
213
+ try {
214
+ next = this._fn();
215
+ } catch (e) {
216
+ threw = true;
217
+ err = e;
218
+ next = this._value;
219
+ } finally {
220
+ G.consumer = prevConsumer;
221
+ G.untracked = prevUntracked;
222
+ if (watched) exitReactiveRun();
223
+ }
224
+ const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
225
+ this._initialized = true;
226
+ this._threw = threw;
227
+ this._error = err;
228
+ this._value = next;
229
+ reportReactiveRun(this);
230
+ if (changed) {
231
+ this.version++;
232
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
233
+ notifyWatchers(this);
234
+ }
235
+ }
236
+ /**
237
+ * Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
238
+ * own observers get CHECK (recurse), stopping where already marked, so the
239
+ * push is O(newly-dirtied) and never recomputes.
240
+ */
241
+ markDirty(level) {
242
+ if (this.state >= level) return;
243
+ const wasClean = this.state === CLEAN;
244
+ this.state = level;
245
+ if (wasClean) {
246
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
247
+ notifyWatchers(this);
248
+ }
249
+ }
250
+ peek() {
251
+ this.updateIfNecessary();
252
+ if (this._threw) throw this._error;
253
+ return this._value;
254
+ }
255
+ };
256
+ function notifyWatchers(node) {
257
+ if (!node.watchers) return;
258
+ for (const w of [...node.watchers]) w._notify(node);
259
+ }
260
+ function untrack(fn) {
261
+ if (G.untracked) return fn();
262
+ G.untracked = true;
263
+ try {
264
+ return fn();
265
+ } finally {
266
+ G.untracked = false;
267
+ }
268
+ }
269
+
270
+ // src/lib/signal/graph/runtime.ts
271
+ function makeOwner(parent) {
272
+ return { cleanups: null, owned: null, parent, contexts: null };
273
+ }
274
+ function reportSuspend(promise) {
275
+ if (G.onSuspend) {
276
+ G.onSuspend(promise, G.owner);
277
+ return true;
278
+ }
279
+ return false;
280
+ }
281
+ function getOwner() {
282
+ return G.owner;
283
+ }
284
+ function runWithOwner(owner, fn) {
285
+ const prev = G.owner;
286
+ G.owner = owner;
287
+ try {
288
+ return fn();
289
+ } finally {
290
+ G.owner = prev;
291
+ }
292
+ }
293
+ function onCleanup(fn) {
294
+ if (!G.owner) return;
295
+ if (G.owner.disposed) {
296
+ fn();
297
+ return;
298
+ }
299
+ (G.owner.cleanups ??= []).push(fn);
300
+ }
301
+ function disposeOwner(owner, final = true) {
302
+ if (owner.disposed) return;
303
+ if (owner.owned) {
304
+ for (let i = owner.owned.length - 1; i >= 0; i--) disposeOwner(owner.owned[i]);
305
+ owner.owned = null;
306
+ }
307
+ if (owner.cleanups) {
308
+ for (let i = owner.cleanups.length - 1; i >= 0; i--) owner.cleanups[i]();
309
+ owner.cleanups = null;
310
+ }
311
+ if (final) owner.disposed = true;
312
+ }
313
+ function createRoot(fn) {
314
+ const owner = makeOwner(G.owner);
315
+ if (G.owner) (G.owner.owned ??= []).push(owner);
316
+ const prev = G.owner;
317
+ G.owner = owner;
318
+ try {
319
+ return untrack(() => fn(() => disposeOwner(owner)));
320
+ } finally {
321
+ G.owner = prev;
322
+ }
323
+ }
324
+ function setScheduler(fn) {
325
+ G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
326
+ }
327
+ function flushSync() {
328
+ G.scheduled = false;
329
+ if (G.flushing) return;
330
+ G.flushing = true;
331
+ let guard = 0;
332
+ let failed = false;
333
+ let first;
334
+ try {
335
+ while (G.queue.length) {
336
+ if (++guard > 1e5) throw new Error("[fluixi] effect flush did not settle (cycle?)");
337
+ const batchOf = G.queue;
338
+ G.queue = [];
339
+ for (const e of batchOf) {
340
+ e.queued = false;
341
+ if (e.disposed) continue;
342
+ try {
343
+ e.run();
344
+ } catch (error) {
345
+ if (!failed) {
346
+ failed = true;
347
+ first = error;
348
+ }
349
+ }
350
+ }
351
+ }
352
+ } finally {
353
+ G.flushing = false;
354
+ }
355
+ if (failed) throw first;
356
+ }
357
+ function afterWrite() {
358
+ if (G.batchDepth === 0) flushSync();
359
+ }
360
+
361
+ // src/lib/signal/graph/compat.ts
362
+ function isThenable(v) {
363
+ return !!v && typeof v.then === "function";
364
+ }
365
+ setScheduler(() => {
366
+ });
367
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
368
+ var $MEMO = /* @__PURE__ */ Symbol.for("memo");
369
+ var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
370
+ function createSignal(value, options) {
371
+ const state = new State(value, { equals: options?.equals });
372
+ const read = (() => state.get());
373
+ const write = ((next) => {
374
+ const v = typeof next === "function" ? next(state.peek()) : next;
375
+ state.set(v);
376
+ afterWrite();
377
+ return v;
378
+ });
379
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
380
+ Object.defineProperty(read, $NODE, {
381
+ value: {
382
+ get value() {
383
+ return state.peek();
384
+ },
385
+ get version() {
386
+ return state.version;
387
+ }
388
+ },
389
+ enumerable: false
390
+ });
391
+ reportReactiveNode({
392
+ kind: "signal",
393
+ node: state,
394
+ handle: read,
395
+ name: options?.name,
396
+ set: write
397
+ });
398
+ if (isObserved()) onCleanup(() => reportReactiveDispose(state));
399
+ return [read, write];
400
+ }
401
+ function createMemo(fn, value, options) {
402
+ let prev = value;
403
+ const owner = getOwner();
404
+ const c = new Computed(
405
+ () => runWithOwner(owner, () => {
406
+ try {
407
+ return prev = fn(prev);
408
+ } catch (e) {
409
+ if (isThenable(e)) {
410
+ reportSuspend(e);
411
+ return prev;
412
+ }
413
+ throw e;
414
+ }
415
+ }),
416
+ { equals: options?.equals }
417
+ );
418
+ const read = (() => c.get());
419
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
420
+ Object.defineProperty(read, $MEMO, { value: true, enumerable: true });
421
+ reportReactiveNode({ kind: "memo", node: c, handle: read, name: options?.name });
422
+ if (isObserved()) onCleanup(() => reportReactiveDispose(c));
423
+ return read;
424
+ }
425
+ function untrack2(fn) {
426
+ return untrack(fn);
427
+ }
428
+
429
+ // src/lib/signal/list.ts
430
+ function mapArray(list, mapFn, options) {
431
+ let items = [];
432
+ onCleanup(() => {
433
+ for (const e of items) e.dispose();
434
+ items = [];
435
+ });
436
+ return createMemo(() => {
437
+ const next = list() || [];
438
+ return untrack2(() => {
439
+ if (next.length === 0) {
440
+ for (const e of items) e.dispose();
441
+ items = [];
442
+ return options?.fallback ? options.fallback() : [];
443
+ }
444
+ const prevByItem = /* @__PURE__ */ new Map();
445
+ for (const e of items) if (!prevByItem.has(e.item)) prevByItem.set(e.item, e);
446
+ const result = [];
447
+ const used = /* @__PURE__ */ new Set();
448
+ for (let i = 0; i < next.length; i++) {
449
+ const value = next[i];
450
+ const reuse = prevByItem.get(value);
451
+ if (reuse && !used.has(reuse)) {
452
+ reuse.setIndex(i);
453
+ result.push(reuse);
454
+ used.add(reuse);
455
+ } else {
456
+ let rendered, setIndex, dispose;
457
+ createRoot((d) => {
458
+ dispose = d;
459
+ const [index, setIdx] = createSignal(i, { name: "row index" });
460
+ setIndex = setIdx;
461
+ rendered = mapFn(value, index);
462
+ });
463
+ const entry = { item: value, rendered, dispose, setIndex };
464
+ result.push(entry);
465
+ used.add(entry);
466
+ }
467
+ }
468
+ for (const e of items) if (!used.has(e)) e.dispose();
469
+ items = result;
470
+ return result.map((e) => e.rendered);
471
+ });
472
+ }, void 0, { name: "mapArray" });
473
+ }
474
+ function keyArray(list, keyFn, mapFn, options) {
475
+ let keys = [];
476
+ let entries = [];
477
+ onCleanup(() => {
478
+ for (const e of entries) e.dispose();
479
+ keys = [];
480
+ entries = [];
481
+ });
482
+ return createMemo(() => {
483
+ const next = list() || [];
484
+ return untrack2(() => {
485
+ if (next.length === 0) {
486
+ for (const e of entries) e.dispose();
487
+ keys = [];
488
+ entries = [];
489
+ return options?.fallback ? options.fallback() : [];
490
+ }
491
+ const prevByKey = /* @__PURE__ */ new Map();
492
+ for (let i = 0; i < keys.length; i++) prevByKey.set(keys[i], entries[i]);
493
+ const resultEntries = [];
494
+ const resultKeys = [];
495
+ const usedKeys = /* @__PURE__ */ new Set();
496
+ for (let i = 0; i < next.length; i++) {
497
+ const key = keyFn(next[i]);
498
+ const reuse = prevByKey.get(key);
499
+ if (reuse && !usedKeys.has(key)) {
500
+ reuse.setIndex(i);
501
+ resultEntries.push(reuse);
502
+ } else {
503
+ let rendered, setIndex, dispose;
504
+ createRoot((d) => {
505
+ dispose = d;
506
+ const [index, setIdx] = createSignal(i, { name: "row index" });
507
+ setIndex = setIdx;
508
+ const item = createMemo((prev) => {
509
+ const cur = list() || [];
510
+ const v = cur[index()];
511
+ return v !== void 0 && v !== null ? v : prev;
512
+ }, next[i]);
513
+ rendered = mapFn(item, index);
514
+ });
515
+ resultEntries.push({ rendered, dispose, setIndex });
516
+ }
517
+ resultKeys.push(key);
518
+ usedKeys.add(key);
519
+ }
520
+ for (const [key, e] of prevByKey) if (!usedKeys.has(key)) e.dispose();
521
+ keys = resultKeys;
522
+ entries = resultEntries;
523
+ return resultEntries.map((e) => e.rendered);
524
+ });
525
+ }, void 0, { name: "keyArray" });
526
+ }
527
+ function indexArray(list, mapFn, options) {
528
+ let slots = [];
529
+ onCleanup(() => {
530
+ for (const s of slots) s.dispose();
531
+ slots = [];
532
+ });
533
+ return createMemo(() => {
534
+ const next = list() || [];
535
+ return untrack2(() => {
536
+ if (next.length === 0) {
537
+ for (const s of slots) s.dispose();
538
+ slots = [];
539
+ return options?.fallback ? options.fallback() : [];
540
+ }
541
+ const prevLen = slots.length;
542
+ const nextLen = next.length;
543
+ for (let i = prevLen; i < nextLen; i++) {
544
+ let rendered, setItem, dispose;
545
+ const value = next[i];
546
+ createRoot((d) => {
547
+ dispose = d;
548
+ const [item, setVal] = createSignal(value);
549
+ setItem = setVal;
550
+ rendered = mapFn(item, i);
551
+ });
552
+ slots.push({ rendered, setItem, dispose });
553
+ }
554
+ for (let i = nextLen; i < prevLen; i++) slots[i].dispose();
555
+ if (nextLen < prevLen) slots = slots.slice(0, nextLen);
556
+ const survive = Math.min(prevLen, nextLen);
557
+ for (let i = 0; i < survive; i++) slots[i].setItem(next[i]);
558
+ return slots.map((s) => s.rendered);
559
+ });
560
+ }, void 0, { name: "indexArray" });
561
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Keyed list reconciliation primitives, the reactive foundation for `<For>`,
3
+ * `<For by>` and `<Index>` (mirrors SolidJS `mapArray`/`keyArray`/`indexArray`).
4
+ *
5
+ * Each maps a reactive array to an array of mapped values and reuses per-item
6
+ * reactive scopes across updates so only changed items re-run their map fn. Every
7
+ * mapped item lives in its own `createRoot`, so it has a disposable owner scope
8
+ * this is what keeps list items owner-stable (the thing ad-hoc array handling gets
9
+ * wrong).
10
+ */
11
+ import { type Accessor } from './graph/compat.js';
12
+ type ListSource<T> = Accessor<readonly T[] | null | undefined | false>;
13
+ interface ListOptions {
14
+ /** Returned (as-is, not wrapped) when the list is empty/nullish. */
15
+ fallback?: () => any;
16
+ }
17
+ /**
18
+ * Reference-keyed map. Reuses an item's mapped value while the same value (by
19
+ * `===`) stays in the list; new values get a fresh root + index signal; removed
20
+ * values are disposed. The map fn receives the plain value (a snapshot) and a
21
+ * reactive index accessor. Backs `<For>`.
22
+ */
23
+ export declare function mapArray<T, U>(list: ListSource<T>, mapFn: (item: T, index: Accessor<number>) => U, options?: ListOptions): Accessor<U[]>;
24
+ /**
25
+ * Key-function map. Like `mapArray` but reuse is keyed by `keyFn(item)` (so the
26
+ * same key survives object recreation), and the map fn receives a *live* item
27
+ * accessor (reads through to the current list value, so sub-property updates
28
+ * propagate). Backs `<For by={...}>`.
29
+ */
30
+ export declare function keyArray<T, U>(list: ListSource<T>, keyFn: (item: T) => any, mapFn: (item: Accessor<T>, index: Accessor<number>) => U, options?: ListOptions): Accessor<U[]>;
31
+ /**
32
+ * Index-keyed map. Reuse is keyed by *position*, growing adds slots, shrinking
33
+ * disposes trailing slots, and when the value at a position changes only that
34
+ * slot's item signal updates (the map fn is not re-run). The map fn receives a
35
+ * live item accessor and a plain (stable) index. Backs `<Index>`.
36
+ */
37
+ export declare function indexArray<T, U>(list: ListSource<T>, mapFn: (item: Accessor<T>, index: number) => U, options?: ListOptions): Accessor<U[]>;
38
+ export {};
39
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/lib/signal/list.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,QAAQ,EAA4D,MAAM,mBAAmB,CAAC;AAE5G,KAAK,UAAU,CAAC,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC;AAEvE,UAAU,WAAW;IACnB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAC9C,OAAO,CAAC,EAAE,WAAW,GACpB,QAAQ,CAAC,CAAC,EAAE,CAAC,CA6Cf;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,EACvB,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EACxD,OAAO,CAAC,EAAE,WAAW,GACpB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAuDf;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC7B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,EAC9C,OAAO,CAAC,EAAE,WAAW,GACpB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAuCf"}