@shadow-js/core 0.1.0 → 1.0.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 (387) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +2 -2
  3. package/README.md +134 -331
  4. package/dist/dev/action.d.ts +36 -0
  5. package/dist/dev/action.js +90 -0
  6. package/dist/dev/action.js.map +1 -0
  7. package/dist/dev/cache.d.ts +35 -0
  8. package/dist/dev/cache.js +62 -0
  9. package/dist/dev/cache.js.map +1 -0
  10. package/dist/dev/context.d.ts +106 -0
  11. package/dist/dev/context.js +111 -0
  12. package/dist/dev/context.js.map +1 -0
  13. package/dist/dev/effect.d.ts +122 -0
  14. package/dist/dev/effect.js +111 -0
  15. package/dist/dev/effect.js.map +1 -0
  16. package/dist/dev/env.d.ts +29 -0
  17. package/dist/dev/env.js +31 -0
  18. package/dist/dev/env.js.map +1 -0
  19. package/dist/dev/events.d.ts +28 -0
  20. package/dist/dev/events.js +33 -0
  21. package/dist/dev/events.js.map +1 -0
  22. package/dist/dev/extend/index.d.ts +331 -0
  23. package/dist/dev/extend/index.js +317 -0
  24. package/dist/dev/extend/index.js.map +1 -0
  25. package/dist/dev/external-store.d.ts +60 -0
  26. package/dist/dev/external-store.js +60 -0
  27. package/dist/dev/external-store.js.map +1 -0
  28. package/dist/dev/index.d.ts +29 -0
  29. package/dist/dev/index.js +26 -0
  30. package/dist/dev/internal/concurrency.d.ts +213 -0
  31. package/dist/dev/internal/concurrency.js +632 -0
  32. package/dist/dev/internal/concurrency.js.map +1 -0
  33. package/dist/dev/internal/devtools.d.ts +71 -0
  34. package/dist/dev/internal/devtools.js +77 -0
  35. package/dist/dev/internal/devtools.js.map +1 -0
  36. package/dist/dev/internal/diagnostics.d.ts +90 -0
  37. package/dist/dev/internal/diagnostics.js +102 -0
  38. package/dist/dev/internal/diagnostics.js.map +1 -0
  39. package/dist/dev/internal/dispose.d.ts +28 -0
  40. package/dist/dev/internal/dispose.js +49 -0
  41. package/dist/dev/internal/dispose.js.map +1 -0
  42. package/dist/dev/internal/flags.js +11 -0
  43. package/dist/dev/internal/flags.js.map +1 -0
  44. package/dist/dev/internal/graph.d.ts +233 -0
  45. package/dist/dev/internal/graph.js +578 -0
  46. package/dist/dev/internal/graph.js.map +1 -0
  47. package/dist/dev/internal/hydration-flag.d.ts +33 -0
  48. package/dist/dev/internal/hydration-flag.js +46 -0
  49. package/dist/dev/internal/hydration-flag.js.map +1 -0
  50. package/dist/dev/internal/messages.d.ts +56 -0
  51. package/dist/dev/internal/messages.js +54 -0
  52. package/dist/dev/internal/messages.js.map +1 -0
  53. package/dist/dev/internal/owner.d.ts +142 -0
  54. package/dist/dev/internal/owner.js +290 -0
  55. package/dist/dev/internal/owner.js.map +1 -0
  56. package/dist/dev/internal/queue.js +46 -0
  57. package/dist/dev/internal/queue.js.map +1 -0
  58. package/dist/dev/internal/scheduler.d.ts +113 -0
  59. package/dist/dev/internal/scheduler.js +287 -0
  60. package/dist/dev/internal/scheduler.js.map +1 -0
  61. package/dist/dev/internal/state.d.ts +141 -0
  62. package/dist/dev/internal/state.js +28 -0
  63. package/dist/dev/internal/state.js.map +1 -0
  64. package/dist/dev/internal/suspension.d.ts +43 -0
  65. package/dist/dev/internal/suspension.js +45 -0
  66. package/dist/dev/internal/suspension.js.map +1 -0
  67. package/dist/dev/internal/types.d.ts +46 -0
  68. package/dist/dev/list.d.ts +93 -0
  69. package/dist/dev/list.js +282 -0
  70. package/dist/dev/list.js.map +1 -0
  71. package/dist/dev/memo.d.ts +60 -0
  72. package/dist/dev/memo.js +41 -0
  73. package/dist/dev/memo.js.map +1 -0
  74. package/dist/dev/optimistic.d.ts +26 -0
  75. package/dist/dev/optimistic.js +45 -0
  76. package/dist/dev/optimistic.js.map +1 -0
  77. package/dist/dev/ownership.d.ts +204 -0
  78. package/dist/dev/ownership.js +261 -0
  79. package/dist/dev/ownership.js.map +1 -0
  80. package/dist/dev/props.d.ts +134 -0
  81. package/dist/dev/props.js +282 -0
  82. package/dist/dev/props.js.map +1 -0
  83. package/dist/dev/reaction.d.ts +29 -0
  84. package/dist/dev/reaction.js +61 -0
  85. package/dist/dev/reaction.js.map +1 -0
  86. package/dist/dev/reducer.d.ts +41 -0
  87. package/dist/dev/reducer.js +39 -0
  88. package/dist/dev/reducer.js.map +1 -0
  89. package/dist/dev/refs.d.ts +52 -0
  90. package/dist/dev/refs.js +58 -0
  91. package/dist/dev/refs.js.map +1 -0
  92. package/dist/dev/resource.d.ts +135 -0
  93. package/dist/dev/resource.js +177 -0
  94. package/dist/dev/resource.js.map +1 -0
  95. package/dist/dev/selector.d.ts +34 -0
  96. package/dist/dev/selector.js +118 -0
  97. package/dist/dev/selector.js.map +1 -0
  98. package/dist/dev/signal.d.ts +42 -0
  99. package/dist/dev/signal.js +39 -0
  100. package/dist/dev/signal.js.map +1 -0
  101. package/dist/dev/store/index.d.ts +5 -0
  102. package/dist/dev/store/index.js +4 -0
  103. package/dist/dev/store/nodes.js +192 -0
  104. package/dist/dev/store/nodes.js.map +1 -0
  105. package/dist/dev/store/proxies.js +160 -0
  106. package/dist/dev/store/proxies.js.map +1 -0
  107. package/dist/dev/store/read.d.ts +39 -0
  108. package/dist/dev/store/read.js +72 -0
  109. package/dist/dev/store/read.js.map +1 -0
  110. package/dist/dev/store/reconcile.d.ts +73 -0
  111. package/dist/dev/store/reconcile.js +186 -0
  112. package/dist/dev/store/reconcile.js.map +1 -0
  113. package/dist/dev/store/types.d.ts +106 -0
  114. package/dist/dev/store/use-store.d.ts +60 -0
  115. package/dist/dev/store/use-store.js +168 -0
  116. package/dist/dev/store/use-store.js.map +1 -0
  117. package/dist/dev/suspense.d.ts +101 -0
  118. package/dist/dev/suspense.js +45 -0
  119. package/dist/dev/suspense.js.map +1 -0
  120. package/dist/dev/transitions.d.ts +77 -0
  121. package/dist/dev/transitions.js +101 -0
  122. package/dist/dev/transitions.js.map +1 -0
  123. package/dist/prod/action.js +2 -0
  124. package/dist/prod/action.js.map +1 -0
  125. package/dist/prod/cache.js +2 -0
  126. package/dist/prod/cache.js.map +1 -0
  127. package/dist/prod/context.js +2 -0
  128. package/dist/prod/context.js.map +1 -0
  129. package/dist/prod/effect.js +2 -0
  130. package/dist/prod/effect.js.map +1 -0
  131. package/dist/prod/env.js +2 -0
  132. package/dist/prod/env.js.map +1 -0
  133. package/dist/prod/events.js +2 -0
  134. package/dist/prod/events.js.map +1 -0
  135. package/dist/prod/extend/index.js +2 -0
  136. package/dist/prod/extend/index.js.map +1 -0
  137. package/dist/prod/external-store.js +2 -0
  138. package/dist/prod/external-store.js.map +1 -0
  139. package/dist/prod/index.js +1 -0
  140. package/dist/prod/internal/concurrency.js +2 -0
  141. package/dist/prod/internal/concurrency.js.map +1 -0
  142. package/dist/prod/internal/devtools.js +2 -0
  143. package/dist/prod/internal/devtools.js.map +1 -0
  144. package/dist/prod/internal/diagnostics.js +2 -0
  145. package/dist/prod/internal/diagnostics.js.map +1 -0
  146. package/dist/prod/internal/dispose.js +2 -0
  147. package/dist/prod/internal/dispose.js.map +1 -0
  148. package/dist/prod/internal/flags.js +2 -0
  149. package/dist/prod/internal/flags.js.map +1 -0
  150. package/dist/prod/internal/graph.js +2 -0
  151. package/dist/prod/internal/graph.js.map +1 -0
  152. package/dist/prod/internal/hydration-flag.js +2 -0
  153. package/dist/prod/internal/hydration-flag.js.map +1 -0
  154. package/dist/prod/internal/messages.js +2 -0
  155. package/dist/prod/internal/messages.js.map +1 -0
  156. package/dist/prod/internal/owner.js +2 -0
  157. package/dist/prod/internal/owner.js.map +1 -0
  158. package/dist/prod/internal/queue.js +2 -0
  159. package/dist/prod/internal/queue.js.map +1 -0
  160. package/dist/prod/internal/scheduler.js +2 -0
  161. package/dist/prod/internal/scheduler.js.map +1 -0
  162. package/dist/prod/internal/state.js +2 -0
  163. package/dist/prod/internal/state.js.map +1 -0
  164. package/dist/prod/internal/suspension.js +2 -0
  165. package/dist/prod/internal/suspension.js.map +1 -0
  166. package/dist/prod/list.js +2 -0
  167. package/dist/prod/list.js.map +1 -0
  168. package/dist/prod/memo.js +2 -0
  169. package/dist/prod/memo.js.map +1 -0
  170. package/dist/prod/optimistic.js +2 -0
  171. package/dist/prod/optimistic.js.map +1 -0
  172. package/dist/prod/ownership.js +2 -0
  173. package/dist/prod/ownership.js.map +1 -0
  174. package/dist/prod/props.js +2 -0
  175. package/dist/prod/props.js.map +1 -0
  176. package/dist/prod/reaction.js +2 -0
  177. package/dist/prod/reaction.js.map +1 -0
  178. package/dist/prod/reducer.js +2 -0
  179. package/dist/prod/reducer.js.map +1 -0
  180. package/dist/prod/refs.js +2 -0
  181. package/dist/prod/refs.js.map +1 -0
  182. package/dist/prod/resource.js +2 -0
  183. package/dist/prod/resource.js.map +1 -0
  184. package/dist/prod/selector.js +2 -0
  185. package/dist/prod/selector.js.map +1 -0
  186. package/dist/prod/signal.js +2 -0
  187. package/dist/prod/signal.js.map +1 -0
  188. package/dist/prod/store/index.js +1 -0
  189. package/dist/prod/store/nodes.js +2 -0
  190. package/dist/prod/store/nodes.js.map +1 -0
  191. package/dist/prod/store/proxies.js +2 -0
  192. package/dist/prod/store/proxies.js.map +1 -0
  193. package/dist/prod/store/read.js +2 -0
  194. package/dist/prod/store/read.js.map +1 -0
  195. package/dist/prod/store/reconcile.js +2 -0
  196. package/dist/prod/store/reconcile.js.map +1 -0
  197. package/dist/prod/store/use-store.js +2 -0
  198. package/dist/prod/store/use-store.js.map +1 -0
  199. package/dist/prod/suspense.js +2 -0
  200. package/dist/prod/suspense.js.map +1 -0
  201. package/dist/prod/transitions.js +2 -0
  202. package/dist/prod/transitions.js.map +1 -0
  203. package/dist/server/action.js +2 -0
  204. package/dist/server/action.js.map +1 -0
  205. package/dist/server/cache.js +2 -0
  206. package/dist/server/cache.js.map +1 -0
  207. package/dist/server/context.js +2 -0
  208. package/dist/server/context.js.map +1 -0
  209. package/dist/server/effect.js +2 -0
  210. package/dist/server/effect.js.map +1 -0
  211. package/dist/server/env.js +2 -0
  212. package/dist/server/env.js.map +1 -0
  213. package/dist/server/events.js +2 -0
  214. package/dist/server/events.js.map +1 -0
  215. package/dist/server/extend/index.js +2 -0
  216. package/dist/server/extend/index.js.map +1 -0
  217. package/dist/server/external-store.js +2 -0
  218. package/dist/server/external-store.js.map +1 -0
  219. package/dist/server/index.js +1 -0
  220. package/dist/server/internal/concurrency.js +2 -0
  221. package/dist/server/internal/concurrency.js.map +1 -0
  222. package/dist/server/internal/devtools.js +2 -0
  223. package/dist/server/internal/devtools.js.map +1 -0
  224. package/dist/server/internal/diagnostics.js +2 -0
  225. package/dist/server/internal/diagnostics.js.map +1 -0
  226. package/dist/server/internal/dispose.js +2 -0
  227. package/dist/server/internal/dispose.js.map +1 -0
  228. package/dist/server/internal/flags.js +2 -0
  229. package/dist/server/internal/flags.js.map +1 -0
  230. package/dist/server/internal/graph.js +2 -0
  231. package/dist/server/internal/graph.js.map +1 -0
  232. package/dist/server/internal/hydration-flag.js +2 -0
  233. package/dist/server/internal/hydration-flag.js.map +1 -0
  234. package/dist/server/internal/messages.js +2 -0
  235. package/dist/server/internal/messages.js.map +1 -0
  236. package/dist/server/internal/owner.js +2 -0
  237. package/dist/server/internal/owner.js.map +1 -0
  238. package/dist/server/internal/queue.js +2 -0
  239. package/dist/server/internal/queue.js.map +1 -0
  240. package/dist/server/internal/scheduler.js +2 -0
  241. package/dist/server/internal/scheduler.js.map +1 -0
  242. package/dist/server/internal/state.js +2 -0
  243. package/dist/server/internal/state.js.map +1 -0
  244. package/dist/server/internal/suspension.js +2 -0
  245. package/dist/server/internal/suspension.js.map +1 -0
  246. package/dist/server/list.js +2 -0
  247. package/dist/server/list.js.map +1 -0
  248. package/dist/server/memo.js +2 -0
  249. package/dist/server/memo.js.map +1 -0
  250. package/dist/server/optimistic.js +2 -0
  251. package/dist/server/optimistic.js.map +1 -0
  252. package/dist/server/ownership.js +2 -0
  253. package/dist/server/ownership.js.map +1 -0
  254. package/dist/server/props.js +2 -0
  255. package/dist/server/props.js.map +1 -0
  256. package/dist/server/reaction.js +2 -0
  257. package/dist/server/reaction.js.map +1 -0
  258. package/dist/server/reducer.js +2 -0
  259. package/dist/server/reducer.js.map +1 -0
  260. package/dist/server/refs.js +2 -0
  261. package/dist/server/refs.js.map +1 -0
  262. package/dist/server/resource.js +2 -0
  263. package/dist/server/resource.js.map +1 -0
  264. package/dist/server/selector.js +2 -0
  265. package/dist/server/selector.js.map +1 -0
  266. package/dist/server/signal.js +2 -0
  267. package/dist/server/signal.js.map +1 -0
  268. package/dist/server/store/index.js +1 -0
  269. package/dist/server/store/nodes.js +2 -0
  270. package/dist/server/store/nodes.js.map +1 -0
  271. package/dist/server/store/proxies.js +2 -0
  272. package/dist/server/store/proxies.js.map +1 -0
  273. package/dist/server/store/read.js +2 -0
  274. package/dist/server/store/read.js.map +1 -0
  275. package/dist/server/store/reconcile.js +2 -0
  276. package/dist/server/store/reconcile.js.map +1 -0
  277. package/dist/server/store/use-store.js +2 -0
  278. package/dist/server/store/use-store.js.map +1 -0
  279. package/dist/server/suspense.js +2 -0
  280. package/dist/server/suspense.js.map +1 -0
  281. package/dist/server/transitions.js +2 -0
  282. package/dist/server/transitions.js.map +1 -0
  283. package/dist/server-dev/action.js +90 -0
  284. package/dist/server-dev/action.js.map +1 -0
  285. package/dist/server-dev/cache.js +62 -0
  286. package/dist/server-dev/cache.js.map +1 -0
  287. package/dist/server-dev/context.js +108 -0
  288. package/dist/server-dev/context.js.map +1 -0
  289. package/dist/server-dev/effect.js +56 -0
  290. package/dist/server-dev/effect.js.map +1 -0
  291. package/dist/server-dev/env.js +31 -0
  292. package/dist/server-dev/env.js.map +1 -0
  293. package/dist/server-dev/events.js +33 -0
  294. package/dist/server-dev/events.js.map +1 -0
  295. package/dist/server-dev/extend/index.js +317 -0
  296. package/dist/server-dev/extend/index.js.map +1 -0
  297. package/dist/server-dev/external-store.js +46 -0
  298. package/dist/server-dev/external-store.js.map +1 -0
  299. package/dist/server-dev/index.js +26 -0
  300. package/dist/server-dev/internal/concurrency.js +633 -0
  301. package/dist/server-dev/internal/concurrency.js.map +1 -0
  302. package/dist/server-dev/internal/devtools.js +77 -0
  303. package/dist/server-dev/internal/devtools.js.map +1 -0
  304. package/dist/server-dev/internal/diagnostics.js +102 -0
  305. package/dist/server-dev/internal/diagnostics.js.map +1 -0
  306. package/dist/server-dev/internal/dispose.js +49 -0
  307. package/dist/server-dev/internal/dispose.js.map +1 -0
  308. package/dist/server-dev/internal/flags.js +11 -0
  309. package/dist/server-dev/internal/flags.js.map +1 -0
  310. package/dist/server-dev/internal/graph.js +578 -0
  311. package/dist/server-dev/internal/graph.js.map +1 -0
  312. package/dist/server-dev/internal/hydration-flag.js +46 -0
  313. package/dist/server-dev/internal/hydration-flag.js.map +1 -0
  314. package/dist/server-dev/internal/messages.js +54 -0
  315. package/dist/server-dev/internal/messages.js.map +1 -0
  316. package/dist/server-dev/internal/owner.js +290 -0
  317. package/dist/server-dev/internal/owner.js.map +1 -0
  318. package/dist/server-dev/internal/queue.js +46 -0
  319. package/dist/server-dev/internal/queue.js.map +1 -0
  320. package/dist/server-dev/internal/scheduler.js +287 -0
  321. package/dist/server-dev/internal/scheduler.js.map +1 -0
  322. package/dist/server-dev/internal/state.js +28 -0
  323. package/dist/server-dev/internal/state.js.map +1 -0
  324. package/dist/server-dev/internal/suspension.js +45 -0
  325. package/dist/server-dev/internal/suspension.js.map +1 -0
  326. package/dist/server-dev/list.js +282 -0
  327. package/dist/server-dev/list.js.map +1 -0
  328. package/dist/server-dev/memo.js +41 -0
  329. package/dist/server-dev/memo.js.map +1 -0
  330. package/dist/server-dev/optimistic.js +45 -0
  331. package/dist/server-dev/optimistic.js.map +1 -0
  332. package/dist/server-dev/ownership.js +261 -0
  333. package/dist/server-dev/ownership.js.map +1 -0
  334. package/dist/server-dev/props.js +282 -0
  335. package/dist/server-dev/props.js.map +1 -0
  336. package/dist/server-dev/reaction.js +61 -0
  337. package/dist/server-dev/reaction.js.map +1 -0
  338. package/dist/server-dev/reducer.js +39 -0
  339. package/dist/server-dev/reducer.js.map +1 -0
  340. package/dist/server-dev/refs.js +58 -0
  341. package/dist/server-dev/refs.js.map +1 -0
  342. package/dist/server-dev/resource.js +176 -0
  343. package/dist/server-dev/resource.js.map +1 -0
  344. package/dist/server-dev/selector.js +82 -0
  345. package/dist/server-dev/selector.js.map +1 -0
  346. package/dist/server-dev/signal.js +39 -0
  347. package/dist/server-dev/signal.js.map +1 -0
  348. package/dist/server-dev/store/index.js +4 -0
  349. package/dist/server-dev/store/nodes.js +192 -0
  350. package/dist/server-dev/store/nodes.js.map +1 -0
  351. package/dist/server-dev/store/proxies.js +160 -0
  352. package/dist/server-dev/store/proxies.js.map +1 -0
  353. package/dist/server-dev/store/read.js +72 -0
  354. package/dist/server-dev/store/read.js.map +1 -0
  355. package/dist/server-dev/store/reconcile.js +186 -0
  356. package/dist/server-dev/store/reconcile.js.map +1 -0
  357. package/dist/server-dev/store/use-store.js +168 -0
  358. package/dist/server-dev/store/use-store.js.map +1 -0
  359. package/dist/server-dev/suspense.js +45 -0
  360. package/dist/server-dev/suspense.js.map +1 -0
  361. package/dist/server-dev/transitions.js +86 -0
  362. package/dist/server-dev/transitions.js.map +1 -0
  363. package/package.json +111 -50
  364. package/dist/chunk-6Y3CCWOY.js +0 -887
  365. package/dist/chunk-6Y3CCWOY.js.map +0 -1
  366. package/dist/chunk-B5FTYDUG.js +0 -3
  367. package/dist/chunk-B5FTYDUG.js.map +0 -1
  368. package/dist/index.cjs +0 -2000
  369. package/dist/index.cjs.map +0 -1
  370. package/dist/index.d.cts +0 -609
  371. package/dist/index.d.ts +0 -609
  372. package/dist/index.js +0 -1094
  373. package/dist/index.js.map +0 -1
  374. package/dist/jsx-Bugil6CJ.d.cts +0 -151
  375. package/dist/jsx-Bugil6CJ.d.ts +0 -151
  376. package/dist/jsx-dev-runtime.cjs +0 -742
  377. package/dist/jsx-dev-runtime.cjs.map +0 -1
  378. package/dist/jsx-dev-runtime.d.cts +0 -2
  379. package/dist/jsx-dev-runtime.d.ts +0 -2
  380. package/dist/jsx-dev-runtime.js +0 -4
  381. package/dist/jsx-dev-runtime.js.map +0 -1
  382. package/dist/jsx-runtime.cjs +0 -742
  383. package/dist/jsx-runtime.cjs.map +0 -1
  384. package/dist/jsx-runtime.d.cts +0 -36
  385. package/dist/jsx-runtime.d.ts +0 -36
  386. package/dist/jsx-runtime.js +0 -4
  387. package/dist/jsx-runtime.js.map +0 -1
@@ -0,0 +1,168 @@
1
+ import { DEVTOOLS_EVENT, report } from "../internal/devtools.js";
2
+ import { ShadowError } from "../internal/diagnostics.js";
3
+ import { group } from "../internal/scheduler.js";
4
+ import { untrack } from "../ownership.js";
5
+ import { useSignal } from "../signal.js";
6
+ import { currentOwner, isComputingMemo } from "../extend/index.js";
7
+ import { isReservedKey, isWrappable, unwrapValue } from "./nodes.js";
8
+ import { snapshot } from "./read.js";
9
+ import { applyReconcile, reconcile, specOf } from "./reconcile.js";
10
+ import { Transaction, draftOf, readProxyOf } from "./proxies.js";
11
+ //#region src/store/use-store.ts
12
+ function isPlainObject(value) {
13
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
14
+ const prototype = Object.getPrototypeOf(value);
15
+ return prototype === Object.prototype || prototype === null;
16
+ }
17
+ function rangeKeys(range, length) {
18
+ const from = range.from ?? 0;
19
+ const to = range.to ?? length - 1;
20
+ const by = range.by ?? 1;
21
+ if (!Number.isFinite(by) || by === 0) throw new TypeError("ShadowStore: a range needs a non-zero `by`");
22
+ const keys = [];
23
+ for (let i = from; by > 0 ? i <= to : i >= to; i += by) {
24
+ keys.push(i);
25
+ if (keys.length > length + 1) break;
26
+ }
27
+ return keys;
28
+ }
29
+ /** The keys one path step addresses on `target` (a draft). */
30
+ function stepKeys(target, step, label) {
31
+ const keys = [];
32
+ if (Array.isArray(target)) {
33
+ if (typeof step === "number") keys.push(step);
34
+ else if (typeof step === "function") {
35
+ const filter = step;
36
+ for (let i = 0; i < target.length; i += 1) if (filter(target[i], i)) keys.push(i);
37
+ } else if (Array.isArray(step)) keys.push(...step);
38
+ else if (typeof step === "object" && step !== null) keys.push(...rangeKeys(step, target.length));
39
+ else throw new TypeError(`ShadowStore${label}: bad path step for an array`);
40
+ } else if (typeof step === "string" || typeof step === "number") keys.push(step);
41
+ else if (Array.isArray(step)) keys.push(...step);
42
+ else throw new TypeError(`ShadowStore${label}: bad path step for an object`);
43
+ for (const key of keys) if (typeof key === "string" && isReservedKey(key)) throw new TypeError(`ShadowStore${label}: the key "${key}" cannot be used in a path`);
44
+ return keys;
45
+ }
46
+ /** Writes `value` (or the updater's result) at the end of a path, merging plain objects. */
47
+ function applyPath(root, path, label) {
48
+ const value = path[path.length - 1];
49
+ const steps = path.slice(0, -1);
50
+ const walk = (target, depth) => {
51
+ for (const key of stepKeys(target, steps[depth], label)) {
52
+ const holder = target;
53
+ if (depth === steps.length - 1) {
54
+ const previous = holder[key];
55
+ const spec = typeof value === "function" ? specOf(value) : void 0;
56
+ if (spec !== void 0) {
57
+ if (isWrappable(previous)) applyReconcile(unwrapValue(previous), spec, label);
58
+ else holder[key] = spec.next;
59
+ continue;
60
+ }
61
+ const next = typeof value === "function" ? value(previous) : value;
62
+ if (isPlainObject(next) && isWrappable(previous) && !Array.isArray(previous)) mergeInto(previous, next, label);
63
+ else holder[key] = next;
64
+ } else {
65
+ const child = holder[key];
66
+ if (!isWrappable(child)) throw new TypeError(`ShadowStore${label}: the path goes through a value that is not an object`);
67
+ walk(child, depth + 1);
68
+ }
69
+ }
70
+ };
71
+ walk(root, 0);
72
+ }
73
+ function mergeInto(target, source, label) {
74
+ for (const key of Object.keys(source)) {
75
+ if (isReservedKey(key)) throw new TypeError(`ShadowStore${label}: the key "${key}" cannot be assigned`);
76
+ target[key] = source[key];
77
+ }
78
+ }
79
+ /**
80
+ * Devtools handles of the stores, by store root. Dev builds only: the WeakMap is unused (and dropped)
81
+ * in production, where `__DEV__` is false.
82
+ */
83
+ const storeHandles = /* @__PURE__ */ new WeakMap();
84
+ function createDeepStore(initial, label) {
85
+ const root = unwrapValue(initial);
86
+ const store = readProxyOf(root);
87
+ const apply = (...args) => {
88
+ if (isComputingMemo()) throw new ShadowError("WRITE_IN_MEMO");
89
+ if (args.length === 0) throw new TypeError(`ShadowStore${label}: setStore() needs an argument`);
90
+ const first = args[0];
91
+ group(() => untrack(() => {
92
+ if (args.length > 1) {
93
+ const tx = new Transaction(label);
94
+ try {
95
+ applyPath(draftOf(root, tx), args, label);
96
+ } finally {
97
+ tx.open = false;
98
+ }
99
+ return;
100
+ }
101
+ if (typeof first === "function") {
102
+ const spec = specOf(first);
103
+ if (spec !== void 0) {
104
+ applyReconcile(root, spec, label);
105
+ return;
106
+ }
107
+ const tx = new Transaction(label);
108
+ let result;
109
+ try {
110
+ result = first(draftOf(root, tx));
111
+ } finally {
112
+ tx.open = false;
113
+ }
114
+ if (result !== void 0) replaceWith(root, result, label);
115
+ return;
116
+ }
117
+ replaceWith(root, first, label);
118
+ }));
119
+ };
120
+ const setStore = apply;
121
+ {
122
+ const handle = {
123
+ name: label === "" ? "store" : label.replace(/^ \((.*)\)$/, "$1"),
124
+ snapshot: () => snapshot(store),
125
+ set: (path, value) => {
126
+ apply(...path, value);
127
+ }
128
+ };
129
+ const anchored = storeHandles.get(root);
130
+ if (anchored === void 0) storeHandles.set(root, [handle]);
131
+ else anchored.push(handle);
132
+ report(DEVTOOLS_EVENT.STORE_CREATED, handle, currentOwner());
133
+ }
134
+ return [store, setStore];
135
+ }
136
+ /** `setStore(value)`: an array replaces (diffed in place), a plain object merges its keys. */
137
+ function replaceWith(root, value, label) {
138
+ if (Array.isArray(root)) {
139
+ if (!Array.isArray(value)) throw new TypeError(`ShadowStore${label}: an array store is updated with an array or a function`);
140
+ const spec = specOf(reconcile(value));
141
+ if (spec !== void 0) applyReconcile(root, spec, label);
142
+ return;
143
+ }
144
+ if (!isPlainObject(value)) throw new TypeError(`ShadowStore${label}: setStore() expects an object, a function or a reconcile() result`);
145
+ const tx = new Transaction(label);
146
+ try {
147
+ mergeInto(draftOf(root, tx), value, label);
148
+ } finally {
149
+ tx.open = false;
150
+ }
151
+ }
152
+ function useStore(initial, options) {
153
+ const label = options?.name === void 0 ? "" : ` (${options.name})`;
154
+ const root = unwrapValue(initial);
155
+ if (isWrappable(root)) return createDeepStore(root, label);
156
+ const [read, write] = useSignal(wrapCell(initial), options?.name === void 0 ? void 0 : { name: options.name });
157
+ const set = (next) => write(typeof next === "function" ? (previous) => wrapCell(next(previous)) : wrapCell(next));
158
+ return [read, set];
159
+ }
160
+ /** The value a single-value cell holds: plain data becomes its (stable) read proxy. */
161
+ function wrapCell(value) {
162
+ const raw = unwrapValue(value);
163
+ return isWrappable(raw) ? readProxyOf(raw) : value;
164
+ }
165
+ //#endregion
166
+ export { useStore };
167
+
168
+ //# sourceMappingURL=use-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-store.js","names":[],"sources":["../../../src/store/use-store.ts"],"sourcesContent":["import {\n currentOwner,\n DEVTOOLS_EVENT,\n devtoolsReport,\n group,\n isComputingMemo,\n ShadowError,\n} from \"../extend\";\nimport { untrack } from \"../ownership\";\nimport { useSignal } from \"../signal\";\nimport { isReservedKey, isWrappable, unwrapValue } from \"./nodes\";\nimport { draftOf, readProxyOf, Transaction } from \"./proxies\";\nimport { snapshot } from \"./read\";\nimport { applyReconcile, reconcile, specOf } from \"./reconcile\";\nimport type { MixedInitial, NotMixed, SetStore, Store, StoreResult } from \"./types\";\n\n/**\n * Options of {@link useStore}.\n * @since 1.0.0\n */\nexport interface StoreOptions {\n /**\n * Label shown in error messages and by devtools.\n * @default undefined (the store is unnamed)\n */\n name?: string;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction rangeKeys(range: { from?: number; to?: number; by?: number }, length: number): number[] {\n const from = range.from ?? 0;\n const to = range.to ?? length - 1;\n const by = range.by ?? 1;\n if (!Number.isFinite(by) || by === 0)\n throw new TypeError(\n __DEV__ ? \"ShadowStore: a range needs a non-zero `by`\" : \"SHADOW_STORE_RANGE\",\n );\n const keys: number[] = [];\n for (let i = from; by > 0 ? i <= to : i >= to; i += by) {\n keys.push(i);\n if (keys.length > length + 1) break;\n }\n return keys;\n}\n\n/** The keys one path step addresses on `target` (a draft). */\nfunction stepKeys(target: object, step: unknown, label: string): Array<string | number> {\n const keys: Array<string | number> = [];\n if (Array.isArray(target)) {\n if (typeof step === \"number\") keys.push(step);\n else if (typeof step === \"function\") {\n const filter = step as (item: unknown, index: number) => boolean;\n for (let i = 0; i < target.length; i += 1) if (filter(target[i], i)) keys.push(i);\n } else if (Array.isArray(step)) keys.push(...(step as number[]));\n else if (typeof step === \"object\" && step !== null)\n keys.push(...rangeKeys(step, target.length));\n else\n throw new TypeError(\n __DEV__ ? `ShadowStore${label}: bad path step for an array` : \"SHADOW_STORE_PATH_ARRAY\",\n );\n } else if (typeof step === \"string\" || typeof step === \"number\") {\n keys.push(step);\n } else if (Array.isArray(step)) {\n keys.push(...(step as Array<string | number>));\n } else {\n throw new TypeError(\n __DEV__ ? `ShadowStore${label}: bad path step for an object` : \"SHADOW_STORE_PATH_OBJECT\",\n );\n }\n for (const key of keys) {\n if (typeof key === \"string\" && isReservedKey(key)) {\n throw new TypeError(\n __DEV__\n ? `ShadowStore${label}: the key \"${key}\" cannot be used in a path`\n : \"SHADOW_STORE_PATH_KEY\",\n );\n }\n }\n return keys;\n}\n\n/** Writes `value` (or the updater's result) at the end of a path, merging plain objects. */\nfunction applyPath(root: object, path: unknown[], label: string): void {\n const value = path[path.length - 1];\n const steps = path.slice(0, -1);\n const walk = (target: object, depth: number): void => {\n for (const key of stepKeys(target, steps[depth], label)) {\n const holder = target as Record<string | number, unknown>;\n if (depth === steps.length - 1) {\n const previous = holder[key];\n const spec = typeof value === \"function\" ? specOf(value) : undefined;\n if (spec !== undefined) {\n // reconcile(...) at a path diffs only that sub-tree.\n if (isWrappable(previous)) applyReconcile(unwrapValue(previous) as object, spec, label);\n else holder[key] = spec.next;\n continue;\n }\n const next =\n typeof value === \"function\" ? (value as (p: unknown) => unknown)(previous) : value;\n if (isPlainObject(next) && isWrappable(previous) && !Array.isArray(previous)) {\n mergeInto(previous as Record<string, unknown>, next, label);\n } else {\n holder[key] = next;\n }\n } else {\n const child = holder[key];\n if (!isWrappable(child)) {\n throw new TypeError(\n __DEV__\n ? `ShadowStore${label}: the path goes through a value that is not an object`\n : \"SHADOW_STORE_PATH_VALUE\",\n );\n }\n walk(child, depth + 1);\n }\n }\n };\n walk(root, 0);\n}\n\nfunction mergeInto(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n label: string,\n): void {\n for (const key of Object.keys(source)) {\n if (isReservedKey(key)) {\n throw new TypeError(\n __DEV__\n ? `ShadowStore${label}: the key \"${key}\" cannot be assigned`\n : \"SHADOW_STORE_ASSIGN_KEY\",\n );\n }\n target[key] = source[key];\n }\n}\n\n/**\n * Devtools handles of the stores, by store root. Dev builds only: the WeakMap is unused (and dropped)\n * in production, where `__DEV__` is false.\n */\nconst storeHandles = /* @__PURE__ */ new WeakMap<object, Array<{ readonly name: string }>>();\n\nfunction createDeepStore<T extends object>(initial: T, label: string): [Store<T>, SetStore<T>] {\n const root = unwrapValue(initial) as object;\n const store = readProxyOf(root) as Store<T>;\n\n // One untyped entry point for every form of update. It is assignable to SetStore<T> because its\n // parameters accept anything: the typed overloads are the public contract, and the devtools\n // path setter below calls this function directly with a path it built at run time.\n const apply = (...args: unknown[]): void => {\n if (__DEV__ && isComputingMemo()) throw new ShadowError(\"WRITE_IN_MEMO\");\n if (args.length === 0)\n throw new TypeError(\n __DEV__ ? `ShadowStore${label}: setStore() needs an argument` : \"SHADOW_STORE_NO_ARGUMENT\",\n );\n const first = args[0];\n group(() =>\n untrack(() => {\n if (args.length > 1) {\n const tx = new Transaction(label);\n try {\n applyPath(draftOf(root, tx), args, label);\n } finally {\n tx.open = false;\n }\n return;\n }\n if (typeof first === \"function\") {\n const spec = specOf(first);\n if (spec !== undefined) {\n applyReconcile(root, spec, label);\n return;\n }\n const tx = new Transaction(label);\n let result: unknown;\n try {\n result = (first as (draft: unknown) => unknown)(draftOf(root, tx));\n } finally {\n tx.open = false;\n }\n if (result !== undefined) replaceWith(root, result, label);\n return;\n }\n replaceWith(root, first, label);\n }),\n );\n };\n const setStore: SetStore<T> = apply;\n if (__DEV__) {\n const handle = {\n name: label === \"\" ? \"store\" : label.replace(/^ \\((.*)\\)$/, \"$1\"),\n snapshot: () => snapshot(store),\n set: (path: readonly (string | number)[], value: unknown) => {\n apply(...path, value);\n },\n };\n // Devtools hold the handle weakly, so the handle must stay reachable exactly as long as the store.\n // The store's proxy and its setter both reach `root`, and a WeakMap value lives as long as its key.\n // A root shared by two stores keeps both handles.\n const anchored = storeHandles.get(root);\n if (anchored === undefined) storeHandles.set(root, [handle]);\n else anchored.push(handle);\n devtoolsReport(DEVTOOLS_EVENT.STORE_CREATED, handle, currentOwner());\n }\n return [store, setStore];\n}\n\n/** `setStore(value)`: an array replaces (diffed in place), a plain object merges its keys. */\nfunction replaceWith(root: object, value: unknown, label: string): void {\n if (Array.isArray(root)) {\n if (!Array.isArray(value)) {\n throw new TypeError(\n __DEV__\n ? `ShadowStore${label}: an array store is updated with an array or a function`\n : \"SHADOW_STORE_ARRAY_UPDATE\",\n );\n }\n const spec = specOf(reconcile(value));\n if (spec !== undefined) applyReconcile(root, spec, label);\n return;\n }\n if (!isPlainObject(value)) {\n throw new TypeError(\n __DEV__\n ? `ShadowStore${label}: setStore() expects an object, a function or a reconcile() result`\n : \"SHADOW_STORE_UPDATE_ARGUMENT\",\n );\n }\n const tx = new Transaction(label);\n try {\n mergeInto(draftOf(root, tx) as Record<string, unknown>, value, label);\n } finally {\n tx.open = false;\n }\n}\n\n/**\n * The state hook. Pass a single value for a reactive cell, or plain data for a deep store:\n *\n * ```ts\n * const [count, setCount] = useStore(0); // count() / setCount(n => n + 1)\n * const [todos, setTodos] = useStore({ items: [] as Todo[] });\n * todos.items[0]?.done; // tracks exactly this property\n * setTodos((draft) => { draft.items.push(todo); }); // notifies only what changed\n * setTodos(\"items\", (t) => t.id === 3, \"done\", true); // path form\n * ```\n *\n * Reads inside effects, memos and JSX subscribe to the exact value or property read; writes notify\n * exactly the readers of what changed, in one batch. A store wraps plain objects and arrays in\n * place; class instances, `Date`, `Map`, `Set` and functions are single values. A value that may\n * be `null` or another type (`Todo[] | null`) is a single value too: it is replaced as a whole, and\n * plain data assigned to it is read through the same fine-grained proxies a store uses.\n *\n * @param initial Initial value or plain data. Plain objects and arrays are wrapped in place, not\n * copied.\n * @param options `name` labels the store in messages. Undefined uses the default (unnamed).\n * @returns `[read, write]` for a single value, `[store, setStore]` for plain data.\n * @throws ShadowError `WRITE_IN_MEMO` from the setter, in development builds only, when it is called\n * while a {@link useMemo} computation runs. `setStore` throws TypeError (production messages\n * `SHADOW_STORE_*`) for an update it cannot apply: no argument, a bad path step, a path through a\n * value that is not an object, a reserved key such as `__proto__`, or a non-array value for an\n * array store. Writing to the store view itself throws TypeError (`SHADOW_STORE_READ_ONLY`).\n * @example\n * import { useStore } from \"@shadow-js/core\";\n *\n * interface Todo { id: number; title: string; done: boolean }\n *\n * const [count, setCount] = useStore(0);\n * const [todos, setTodos] = useStore({ items: [] as Todo[] });\n * setCount((n) => n + 1);\n * setTodos((draft) => {\n * draft.items.push({ id: 1, title: \"Write docs\", done: false });\n * });\n * setTodos(\"items\", (todo) => todo.id === 1, \"done\", true);\n * console.log(count(), todos.items[0]?.done); // 1 true\n * @see useSignal\n * @see reconcile\n * @since 1.0.0\n */\nexport function useStore<T extends NotMixed<T>>(initial: T, options?: StoreOptions): StoreResult<T>;\nexport function useStore<T>(initial: MixedInitial<T>, options?: StoreOptions): StoreResult<T>;\nexport function useStore(initial: unknown, options?: StoreOptions): unknown {\n const label = options?.name === undefined ? \"\" : ` (${options.name})`;\n const root = unwrapValue(initial);\n if (isWrappable(root)) return createDeepStore(root, label);\n // A single value, which may be plain data later (`Todo[] | null`): objects and arrays that are\n // assigned are wrapped in read proxies, so `todos()?.[0]?.done` tracks exactly what it reads.\n const [read, write] = useSignal<unknown>(\n wrapCell(initial),\n options?.name === undefined ? undefined : { name: options.name },\n );\n const set = (next: unknown): unknown =>\n write(\n typeof next === \"function\"\n ? (previous: unknown) => wrapCell((next as (previous: unknown) => unknown)(previous))\n : wrapCell(next),\n );\n return [read, set];\n}\n\n/** The value a single-value cell holds: plain data becomes its (stable) read proxy. */\nfunction wrapCell(value: unknown): unknown {\n const raw = unwrapValue(value);\n return isWrappable(raw) ? readProxyOf(raw) : value;\n}\n"],"mappings":"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"}
@@ -0,0 +1,101 @@
1
+ import { Context } from "./context.js";
2
+ //#region src/suspense.d.ts
3
+ /**
4
+ * Counter protocol between asynchronous sources and the nearest `<Suspense>` boundary.
5
+ * A source calls `increment()` when it starts blocking its readers and `decrement()` exactly once
6
+ * when it settles.
7
+ * @since 1.0.0
8
+ */
9
+ export interface SuspenseTracker {
10
+ /**
11
+ * Records one more pending source. The boundary shows its fallback while the count is above
12
+ * zero; call it once per source, the first time a reader sees that source pending.
13
+ */
14
+ increment(): void;
15
+ /**
16
+ * Records that one pending source settled (with a value or an error). Call it exactly once per
17
+ * `increment()`; when the count returns to zero the boundary shows its content again.
18
+ */
19
+ decrement(): void;
20
+ /**
21
+ * Called when a transition reads pending data in this boundary. Returns true when the boundary keeps
22
+ * its content meanwhile: the reader then throws the suspension and keeps its previous value until
23
+ * the boundary releases it. Returns false (or is absent) to show the fallback as usual.
24
+ * @default undefined (the boundary never holds its content: the fallback shows as usual)
25
+ */
26
+ hold?(): boolean;
27
+ }
28
+ /**
29
+ * The context through which an asynchronous source finds the nearest `<Suspense>` boundary. Each
30
+ * boundary provides its {@link SuspenseTracker}; the value is `null` outside any boundary. Read it
31
+ * when building a data primitive that should hold the boundary while it loads, as `useResource`
32
+ * does.
33
+ *
34
+ * @example
35
+ * import { SuspenseContext, useContext } from "@shadow-js/core";
36
+ *
37
+ * function useLoadingHold(promise: Promise<unknown>): void {
38
+ * const tracker = useContext(SuspenseContext); // null outside any <Suspense>
39
+ * if (tracker === null) return;
40
+ * tracker.increment(); // the boundary shows its fallback
41
+ * promise.finally(() => tracker.decrement());
42
+ * }
43
+ * @see useResource
44
+ * @since 1.0.0
45
+ */
46
+ export declare const SuspenseContext: Context<SuspenseTracker | null>;
47
+ /**
48
+ * Bridge between resources and the server/hydration runtime. During server rendering it collects
49
+ * in-flight fetches and replays finished ones on the next pass; during hydration it serves the
50
+ * values the server already fetched, so the client does not fetch them again.
51
+ * @since 1.0.0
52
+ */
53
+ export interface ResourceCache {
54
+ /**
55
+ * Deterministic key for a resource created at this point of the render. `explicit` is the
56
+ * resource's `key` option, or `undefined` when it has none.
57
+ */
58
+ key(explicit: string | undefined): string;
59
+ /** A cached value, wrapped so that `undefined` values are representable. */
60
+ read(key: string): {
61
+ value: unknown;
62
+ } | undefined;
63
+ /**
64
+ * A fetch started; the cache stores its value under `key` when it resolves. `options.deferStream` is
65
+ * true for a resource that holds the first streamed flush (see `ResourceOptions.deferStream`).
66
+ */
67
+ track(key: string, promise: Promise<unknown>, options?: ResourceTrackOptions): void;
68
+ /**
69
+ * The fetch an earlier pass of the same render started for `key` and that has not settled, when there
70
+ * is one. A resource that finds it waits for that fetch instead of starting another, so a pass that
71
+ * renders again does not fetch twice. Optional: a cache that does not keep earlier fetches omits it.
72
+ */
73
+ pending?(key: string): Promise<unknown> | undefined;
74
+ }
75
+ /** What {@link ResourceCache.track} is told about a fetch. @since 1.0.0 */
76
+ export interface ResourceTrackOptions {
77
+ /** True when the resource was created with `deferStream: true`. */
78
+ readonly deferStream?: boolean | undefined;
79
+ }
80
+ /**
81
+ * The context through which `useResource` reaches the renderer's {@link ResourceCache}. Server
82
+ * renderers and hydration provide it; the value is `null` when resources should always fetch. Only
83
+ * a custom renderer needs to provide it.
84
+ *
85
+ * @example
86
+ * import { type ResourceCache, ResourceCacheContext } from "@shadow-js/core";
87
+ *
88
+ * const values = new Map<string, unknown>();
89
+ * let created = 0;
90
+ * const cache: ResourceCache = {
91
+ * key: (explicit) => explicit ?? `resource-${created++}`,
92
+ * read: (key) => (values.has(key) ? { value: values.get(key) } : undefined),
93
+ * track: (key, promise) => void promise.then((value) => values.set(key, value)),
94
+ * };
95
+ * const page = <ResourceCacheContext value={cache}><p>Loading data</p></ResourceCacheContext>;
96
+ * @see useResource
97
+ * @since 1.0.0
98
+ */
99
+ export declare const ResourceCacheContext: Context<ResourceCache | null>;
100
+ //#endregion
101
+ //# sourceMappingURL=suspense.d.ts.map
@@ -0,0 +1,45 @@
1
+ import { createContext } from "./context.js";
2
+ //#region src/suspense.ts
3
+ /**
4
+ * The context through which an asynchronous source finds the nearest `<Suspense>` boundary. Each
5
+ * boundary provides its {@link SuspenseTracker}; the value is `null` outside any boundary. Read it
6
+ * when building a data primitive that should hold the boundary while it loads, as `useResource`
7
+ * does.
8
+ *
9
+ * @example
10
+ * import { SuspenseContext, useContext } from "@shadow-js/core";
11
+ *
12
+ * function useLoadingHold(promise: Promise<unknown>): void {
13
+ * const tracker = useContext(SuspenseContext); // null outside any <Suspense>
14
+ * if (tracker === null) return;
15
+ * tracker.increment(); // the boundary shows its fallback
16
+ * promise.finally(() => tracker.decrement());
17
+ * }
18
+ * @see useResource
19
+ * @since 1.0.0
20
+ */
21
+ const SuspenseContext = /* @__PURE__ */ createContext(null, { name: "Suspense" });
22
+ /**
23
+ * The context through which `useResource` reaches the renderer's {@link ResourceCache}. Server
24
+ * renderers and hydration provide it; the value is `null` when resources should always fetch. Only
25
+ * a custom renderer needs to provide it.
26
+ *
27
+ * @example
28
+ * import { type ResourceCache, ResourceCacheContext } from "@shadow-js/core";
29
+ *
30
+ * const values = new Map<string, unknown>();
31
+ * let created = 0;
32
+ * const cache: ResourceCache = {
33
+ * key: (explicit) => explicit ?? `resource-${created++}`,
34
+ * read: (key) => (values.has(key) ? { value: values.get(key) } : undefined),
35
+ * track: (key, promise) => void promise.then((value) => values.set(key, value)),
36
+ * };
37
+ * const page = <ResourceCacheContext value={cache}><p>Loading data</p></ResourceCacheContext>;
38
+ * @see useResource
39
+ * @since 1.0.0
40
+ */
41
+ const ResourceCacheContext = /* @__PURE__ */ createContext(null, { name: "ResourceCache" });
42
+ //#endregion
43
+ export { ResourceCacheContext, SuspenseContext };
44
+
45
+ //# sourceMappingURL=suspense.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense.js","names":[],"sources":["../../src/suspense.ts"],"sourcesContent":["import { type Context, createContext } from \"./context\";\n\n/**\n * Counter protocol between asynchronous sources and the nearest `<Suspense>` boundary.\n * A source calls `increment()` when it starts blocking its readers and `decrement()` exactly once\n * when it settles.\n * @since 1.0.0\n */\nexport interface SuspenseTracker {\n /**\n * Records one more pending source. The boundary shows its fallback while the count is above\n * zero; call it once per source, the first time a reader sees that source pending.\n */\n increment(): void;\n /**\n * Records that one pending source settled (with a value or an error). Call it exactly once per\n * `increment()`; when the count returns to zero the boundary shows its content again.\n */\n decrement(): void;\n /**\n * Called when a transition reads pending data in this boundary. Returns true when the boundary keeps\n * its content meanwhile: the reader then throws the suspension and keeps its previous value until\n * the boundary releases it. Returns false (or is absent) to show the fallback as usual.\n * @default undefined (the boundary never holds its content: the fallback shows as usual)\n */\n hold?(): boolean;\n}\n\n/**\n * The context through which an asynchronous source finds the nearest `<Suspense>` boundary. Each\n * boundary provides its {@link SuspenseTracker}; the value is `null` outside any boundary. Read it\n * when building a data primitive that should hold the boundary while it loads, as `useResource`\n * does.\n *\n * @example\n * import { SuspenseContext, useContext } from \"@shadow-js/core\";\n *\n * function useLoadingHold(promise: Promise<unknown>): void {\n * const tracker = useContext(SuspenseContext); // null outside any <Suspense>\n * if (tracker === null) return;\n * tracker.increment(); // the boundary shows its fallback\n * promise.finally(() => tracker.decrement());\n * }\n * @see useResource\n * @since 1.0.0\n */\nexport const SuspenseContext: Context<SuspenseTracker | null> =\n /* @__PURE__ */ createContext<SuspenseTracker | null>(null, { name: \"Suspense\" });\n\n/**\n * Bridge between resources and the server/hydration runtime. During server rendering it collects\n * in-flight fetches and replays finished ones on the next pass; during hydration it serves the\n * values the server already fetched, so the client does not fetch them again.\n * @since 1.0.0\n */\nexport interface ResourceCache {\n /**\n * Deterministic key for a resource created at this point of the render. `explicit` is the\n * resource's `key` option, or `undefined` when it has none.\n */\n key(explicit: string | undefined): string;\n /** A cached value, wrapped so that `undefined` values are representable. */\n read(key: string): { value: unknown } | undefined;\n /**\n * A fetch started; the cache stores its value under `key` when it resolves. `options.deferStream` is\n * true for a resource that holds the first streamed flush (see `ResourceOptions.deferStream`).\n */\n track(key: string, promise: Promise<unknown>, options?: ResourceTrackOptions): void;\n /**\n * The fetch an earlier pass of the same render started for `key` and that has not settled, when there\n * is one. A resource that finds it waits for that fetch instead of starting another, so a pass that\n * renders again does not fetch twice. Optional: a cache that does not keep earlier fetches omits it.\n */\n pending?(key: string): Promise<unknown> | undefined;\n}\n\n/** What {@link ResourceCache.track} is told about a fetch. @since 1.0.0 */\nexport interface ResourceTrackOptions {\n /** True when the resource was created with `deferStream: true`. */\n readonly deferStream?: boolean | undefined;\n}\n\n/**\n * The context through which `useResource` reaches the renderer's {@link ResourceCache}. Server\n * renderers and hydration provide it; the value is `null` when resources should always fetch. Only\n * a custom renderer needs to provide it.\n *\n * @example\n * import { type ResourceCache, ResourceCacheContext } from \"@shadow-js/core\";\n *\n * const values = new Map<string, unknown>();\n * let created = 0;\n * const cache: ResourceCache = {\n * key: (explicit) => explicit ?? `resource-${created++}`,\n * read: (key) => (values.has(key) ? { value: values.get(key) } : undefined),\n * track: (key, promise) => void promise.then((value) => values.set(key, value)),\n * };\n * const page = <ResourceCacheContext value={cache}><p>Loading data</p></ResourceCacheContext>;\n * @see useResource\n * @since 1.0.0\n */\nexport const ResourceCacheContext: Context<ResourceCache | null> =\n /* @__PURE__ */ createContext<ResourceCache | null>(null, { name: \"ResourceCache\" });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,kBACK,8BAAsC,MAAM,EAAE,MAAM,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;AAsDlF,MAAa,uBACK,8BAAoC,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { Accessor, Equals } from "./internal/types.js";
2
+ import { inTransition } from "./internal/concurrency.js";
3
+ //#region src/transitions.d.ts
4
+ /**
5
+ * Options of {@link useDeferredValue}.
6
+ * @since 1.0.0
7
+ */
8
+ export interface DeferredValueOptions<T> {
9
+ /**
10
+ * Decides whether the deferred value changed: readers are notified only when it returns `false`.
11
+ * @default Object.is
12
+ */
13
+ equals?: Equals<T>;
14
+ /**
15
+ * Label shown by devtools and diagnostics.
16
+ * @default "useDeferredValue" for the watcher; the value itself is unnamed
17
+ */
18
+ name?: string;
19
+ }
20
+ /**
21
+ * Runs `fn` as a transition and reports whether it is pending. Returns `[isPending, start]`:
22
+ * `isPending` is true from `start(fn)` until the transition has been applied (including any Suspense
23
+ * boundary it waits on); `start(fn)` is {@link startTransition} that also updates `isPending`.
24
+ *
25
+ * Use it for updates that may be slow to show (navigating to a page that loads data): the previous
26
+ * screen stays until the new one is ready, and the input stays responsive meanwhile.
27
+ *
28
+ * @returns `[isPending, start]`. `isPending` is an accessor; `start` returns a promise that
29
+ * resolves when the transition has been applied. On the server `start` runs `fn` at once.
30
+ * @throws Nothing itself. `start` rethrows synchronously what `fn` throws, after clearing
31
+ * `isPending` when no other transition of this hook is running.
32
+ * @example
33
+ * import { useSignal, useTransition } from "@shadow-js/core";
34
+ *
35
+ * function Tabs() {
36
+ * const [page, setPage] = useSignal("home");
37
+ * const [pending, start] = useTransition();
38
+ * return (
39
+ * <button disabled={pending()} onClick={() => start(() => setPage("reports"))}>
40
+ * {page() === "reports" ? "Reports" : "Open reports"}
41
+ * </button>
42
+ * );
43
+ * }
44
+ * @see startTransition
45
+ * @see useDeferredValue
46
+ * @since 1.0.0
47
+ */
48
+ export declare function useTransition(): [Accessor<boolean>, (fn: () => void) => Promise<void>];
49
+ /**
50
+ * Returns a value that follows `source` in the transition lane: it keeps the previous value while
51
+ * urgent updates run, and takes the new value when the lane applies it. Reads of the source are
52
+ * unaffected. On the server it returns the source itself (there is no lane).
53
+ *
54
+ * @param source The value to follow. Tracked by a watcher that runs in the transition lane.
55
+ * @param options Equality and a devtools name. Undefined uses the defaults.
56
+ * @returns An accessor of the deferred value. It starts as the source's current value.
57
+ * @example
58
+ * import { useDeferredValue, useMemo, useSignal } from "@shadow-js/core";
59
+ *
60
+ * const names = ["Ada", "Grace", "Linus"];
61
+ * function Search() {
62
+ * const [query, setQuery] = useSignal("");
63
+ * const deferredQuery = useDeferredValue(query);
64
+ * const results = useMemo(() => names.filter((name) => name.includes(deferredQuery())));
65
+ * return (
66
+ * <label>
67
+ * <input value={query()} onInput={(e) => setQuery(e.currentTarget.value)} />
68
+ * {results().join(", ")}
69
+ * </label>
70
+ * );
71
+ * }
72
+ * @see useTransition
73
+ * @since 1.0.0
74
+ */
75
+ export declare function useDeferredValue<T>(source: Accessor<T>, options?: DeferredValueOptions<T>): Accessor<T>;
76
+ //#endregion
77
+ //# sourceMappingURL=transitions.d.ts.map
@@ -0,0 +1,101 @@
1
+ import { untrack } from "./ownership.js";
2
+ import { useSignal } from "./signal.js";
3
+ import { registerTransitionLane, startTransition } from "./internal/concurrency.js";
4
+ import { createComputation } from "./extend/index.js";
5
+ //#region src/transitions.ts
6
+ /**
7
+ * Runs `fn` as a transition and reports whether it is pending. Returns `[isPending, start]`:
8
+ * `isPending` is true from `start(fn)` until the transition has been applied (including any Suspense
9
+ * boundary it waits on); `start(fn)` is {@link startTransition} that also updates `isPending`.
10
+ *
11
+ * Use it for updates that may be slow to show (navigating to a page that loads data): the previous
12
+ * screen stays until the new one is ready, and the input stays responsive meanwhile.
13
+ *
14
+ * @returns `[isPending, start]`. `isPending` is an accessor; `start` returns a promise that
15
+ * resolves when the transition has been applied. On the server `start` runs `fn` at once.
16
+ * @throws Nothing itself. `start` rethrows synchronously what `fn` throws, after clearing
17
+ * `isPending` when no other transition of this hook is running.
18
+ * @example
19
+ * import { useSignal, useTransition } from "@shadow-js/core";
20
+ *
21
+ * function Tabs() {
22
+ * const [page, setPage] = useSignal("home");
23
+ * const [pending, start] = useTransition();
24
+ * return (
25
+ * <button disabled={pending()} onClick={() => start(() => setPage("reports"))}>
26
+ * {page() === "reports" ? "Reports" : "Open reports"}
27
+ * </button>
28
+ * );
29
+ * }
30
+ * @see startTransition
31
+ * @see useDeferredValue
32
+ * @since 1.0.0
33
+ */
34
+ function useTransition() {
35
+ const [pending, setPending] = useSignal(false);
36
+ let running = 0;
37
+ const start = (fn) => {
38
+ running += 1;
39
+ untrack(() => setPending(true));
40
+ let applied;
41
+ try {
42
+ applied = startTransition(fn);
43
+ } catch (error) {
44
+ running -= 1;
45
+ if (running === 0) untrack(() => setPending(false));
46
+ throw error;
47
+ }
48
+ return applied.then(() => {
49
+ running -= 1;
50
+ if (running === 0) untrack(() => setPending(false));
51
+ });
52
+ };
53
+ return [pending, start];
54
+ }
55
+ /**
56
+ * Returns a value that follows `source` in the transition lane: it keeps the previous value while
57
+ * urgent updates run, and takes the new value when the lane applies it. Reads of the source are
58
+ * unaffected. On the server it returns the source itself (there is no lane).
59
+ *
60
+ * @param source The value to follow. Tracked by a watcher that runs in the transition lane.
61
+ * @param options Equality and a devtools name. Undefined uses the defaults.
62
+ * @returns An accessor of the deferred value. It starts as the source's current value.
63
+ * @example
64
+ * import { useDeferredValue, useMemo, useSignal } from "@shadow-js/core";
65
+ *
66
+ * const names = ["Ada", "Grace", "Linus"];
67
+ * function Search() {
68
+ * const [query, setQuery] = useSignal("");
69
+ * const deferredQuery = useDeferredValue(query);
70
+ * const results = useMemo(() => names.filter((name) => name.includes(deferredQuery())));
71
+ * return (
72
+ * <label>
73
+ * <input value={query()} onInput={(e) => setQuery(e.currentTarget.value)} />
74
+ * {results().join(", ")}
75
+ * </label>
76
+ * );
77
+ * }
78
+ * @see useTransition
79
+ * @since 1.0.0
80
+ */
81
+ function useDeferredValue(source, options) {
82
+ registerTransitionLane();
83
+ const [value, setValue] = useSignal(untrack(source), {
84
+ equals: options?.equals ?? Object.is,
85
+ ...options?.name === void 0 ? {} : { name: options.name }
86
+ });
87
+ createComputation({
88
+ kind: "effect",
89
+ fn: () => source(),
90
+ apply: (next) => {
91
+ setValue(() => next);
92
+ },
93
+ lane: true,
94
+ name: options?.name ?? "useDeferredValue"
95
+ });
96
+ return value;
97
+ }
98
+ //#endregion
99
+ export { useDeferredValue, useTransition };
100
+
101
+ //# sourceMappingURL=transitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transitions.js","names":[],"sources":["../../src/transitions.ts"],"sourcesContent":["import {\n type Accessor,\n createComputation,\n type Equals,\n inTransition,\n registerTransitionLane,\n startTransition,\n} from \"./extend\";\nimport { untrack } from \"./ownership\";\nimport { useSignal } from \"./signal\";\n\n/**\n * Options of {@link useDeferredValue}.\n * @since 1.0.0\n */\nexport interface DeferredValueOptions<T> {\n /**\n * Decides whether the deferred value changed: readers are notified only when it returns `false`.\n * @default Object.is\n */\n equals?: Equals<T>;\n /**\n * Label shown by devtools and diagnostics.\n * @default \"useDeferredValue\" for the watcher; the value itself is unnamed\n */\n name?: string;\n}\n\n/**\n * Runs `fn` as a transition and reports whether it is pending. Returns `[isPending, start]`:\n * `isPending` is true from `start(fn)` until the transition has been applied (including any Suspense\n * boundary it waits on); `start(fn)` is {@link startTransition} that also updates `isPending`.\n *\n * Use it for updates that may be slow to show (navigating to a page that loads data): the previous\n * screen stays until the new one is ready, and the input stays responsive meanwhile.\n *\n * @returns `[isPending, start]`. `isPending` is an accessor; `start` returns a promise that\n * resolves when the transition has been applied. On the server `start` runs `fn` at once.\n * @throws Nothing itself. `start` rethrows synchronously what `fn` throws, after clearing\n * `isPending` when no other transition of this hook is running.\n * @example\n * import { useSignal, useTransition } from \"@shadow-js/core\";\n *\n * function Tabs() {\n * const [page, setPage] = useSignal(\"home\");\n * const [pending, start] = useTransition();\n * return (\n * <button disabled={pending()} onClick={() => start(() => setPage(\"reports\"))}>\n * {page() === \"reports\" ? \"Reports\" : \"Open reports\"}\n * </button>\n * );\n * }\n * @see startTransition\n * @see useDeferredValue\n * @since 1.0.0\n */\nexport function useTransition(): [Accessor<boolean>, (fn: () => void) => Promise<void>] {\n const [pending, setPending] = useSignal(false);\n let running = 0;\n const start = (fn: () => void): Promise<void> => {\n running += 1;\n // Urgent: the pending state must show before the transition's own work.\n untrack(() => setPending(true));\n let applied: Promise<void>;\n try {\n applied = startTransition(fn);\n } catch (error) {\n running -= 1;\n if (running === 0) untrack(() => setPending(false));\n throw error;\n }\n return applied.then(() => {\n running -= 1;\n if (running === 0) untrack(() => setPending(false));\n });\n };\n return [pending, start];\n}\n\n/**\n * Returns a value that follows `source` in the transition lane: it keeps the previous value while\n * urgent updates run, and takes the new value when the lane applies it. Reads of the source are\n * unaffected. On the server it returns the source itself (there is no lane).\n *\n * @param source The value to follow. Tracked by a watcher that runs in the transition lane.\n * @param options Equality and a devtools name. Undefined uses the defaults.\n * @returns An accessor of the deferred value. It starts as the source's current value.\n * @example\n * import { useDeferredValue, useMemo, useSignal } from \"@shadow-js/core\";\n *\n * const names = [\"Ada\", \"Grace\", \"Linus\"];\n * function Search() {\n * const [query, setQuery] = useSignal(\"\");\n * const deferredQuery = useDeferredValue(query);\n * const results = useMemo(() => names.filter((name) => name.includes(deferredQuery())));\n * return (\n * <label>\n * <input value={query()} onInput={(e) => setQuery(e.currentTarget.value)} />\n * {results().join(\", \")}\n * </label>\n * );\n * }\n * @see useTransition\n * @since 1.0.0\n */\nexport function useDeferredValue<T>(\n source: Accessor<T>,\n options?: DeferredValueOptions<T>,\n): Accessor<T> {\n if (__SERVER__) return source;\n registerTransitionLane();\n const [value, setValue] = useSignal<T>(untrack(source), {\n equals: options?.equals ?? Object.is,\n ...(options?.name === undefined ? {} : { name: options.name }),\n });\n // The watcher runs in the lane. Its first run (queued at creation) finds the value equal, so it\n // writes nothing; a later run writes the source's value, and an equal value notifies nobody.\n createComputation({\n kind: \"effect\",\n fn: () => source(),\n apply: (next: T) => {\n setValue(() => next);\n },\n lane: true,\n name: options?.name ?? \"useDeferredValue\",\n });\n return value;\n}\n\nexport { inTransition };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,gBAAwE;CACtF,MAAM,CAAC,SAAS,cAAc,UAAU,KAAK;CAC7C,IAAI,UAAU;CACd,MAAM,SAAS,OAAkC;EAC/C,WAAW;EAEX,cAAc,WAAW,IAAI,CAAC;EAC9B,IAAI;EACJ,IAAI;GACF,UAAU,gBAAgB,EAAE;EAC9B,SAAS,OAAO;GACd,WAAW;GACX,IAAI,YAAY,GAAG,cAAc,WAAW,KAAK,CAAC;GAClD,MAAM;EACR;EACA,OAAO,QAAQ,WAAW;GACxB,WAAW;GACX,IAAI,YAAY,GAAG,cAAc,WAAW,KAAK,CAAC;EACpD,CAAC;CACH;CACA,OAAO,CAAC,SAAS,KAAK;AACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,iBACd,QACA,SACa;CAEb,uBAAuB;CACvB,MAAM,CAAC,OAAO,YAAY,UAAa,QAAQ,MAAM,GAAG;EACtD,QAAQ,SAAS,UAAU,OAAO;EAClC,GAAI,SAAS,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,KAAK;CAC9D,CAAC;CAGD,kBAAkB;EAChB,MAAM;EACN,UAAU,OAAO;EACjB,QAAQ,SAAY;GAClB,eAAe,IAAI;EACrB;EACA,MAAM;EACN,MAAM,SAAS,QAAQ;CACzB,CAAC;CACD,OAAO;AACT"}
@@ -0,0 +1,2 @@
1
+ import{handleError as e}from"./internal/owner.js";import{batch as t}from"./internal/scheduler.js";import{untrack as n}from"./ownership.js";import{useSignal as r}from"./signal.js";import{currentOwner as i}from"./extend/index.js";function a(e){return e!==null&&(typeof e==`object`||typeof e==`function`)&&typeof e.then==`function`}function o(o,s){let c=i(),[l,u]=r(s),[d,f]=r(!1),p=0;return[l,(...r)=>{p+=1;let i=p,s=n(l),d=e=>{i===p&&t(()=>{u(()=>e),f(!1)})},m=t=>{if(i===p){if(f(!1),c===null)throw t;e(t,c)}},h;try{h=n(()=>o(s,...r))}catch(e){return c===null?(i===p&&f(!1),Promise.reject(e)):(m(e),Promise.resolve())}return a(h)?(f(!0),Promise.resolve(h).then(d,m)):(d(h),Promise.resolve())},d]}export{o as useAction};
2
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.js","names":["isPromiseLike","value","useAction","owner","currentOwner","state","setState","useSignal","initialState","pending","setPending","latest","args","id","previous","untrack","commit","batch","fail","error","handleError","result","action"],"sources":["../../src/action.ts"],"sourcesContent":["import { type Accessor, batch, currentOwner, handleError } from \"./extend\";\nimport { untrack } from \"./ownership\";\nimport { useSignal } from \"./signal\";\n\nfunction isPromiseLike<T>(value: unknown): value is PromiseLike<T> {\n return (\n value !== null &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n typeof (value as { then?: unknown }).then === \"function\"\n );\n}\n\n/**\n * A state machine for a form-style action: `dispatch(...args)` runs `action(previous, ...args)`,\n * tracks whether it is pending, and commits its result. The ShadowJS form of React's\n * `useActionState` (state, dispatch, pending). `previous` is the last committed state.\n *\n * Only the latest dispatch commits: when two actions overlap, a slower result that settles after a\n * newer dispatch is discarded, so the screen never goes back to an older answer. A failure does not\n * change the state; it clears `pending` and is sent to the owner's error handler (`onError`), so an\n * error boundary can show it. Without an owner the returned promise rejects instead.\n *\n * @param action `(previous, ...args) => next`, synchronous or async. It runs untracked.\n * @param initialState The state before the first dispatch.\n * @returns `[state, dispatch, pending]`. A synchronous result commits at once; `pending` is true\n * only while a returned promise is unsettled. `dispatch` returns a promise that settles when this\n * call has finished, whether it committed or not.\n * @throws Nothing synchronously. Without an owner, the promise returned by `dispatch` rejects with\n * the action's error. With an owner, the error goes to its error handler, or is reported as an\n * uncaught error (`reportError`) when no handler is registered above it.\n * @example\n * import { useAction } from \"@shadow-js/core\";\n *\n * const [message, send, sending] = useAction(async (_prev: string, text: string) => {\n * await fetch(\"/api/messages\", { method: \"POST\", body: text });\n * return `sent: ${text}`;\n * }, \"\");\n * void send(\"hello\");\n * console.log(sending(), message());\n * @see useOptimistic\n * @see useTransition\n * @since 1.0.0\n */\nexport function useAction<S, A extends unknown[]>(\n action: (previous: S, ...args: A) => S | PromiseLike<S>,\n initialState: S,\n): [state: Accessor<S>, dispatch: (...args: A) => Promise<void>, pending: Accessor<boolean>] {\n const owner = currentOwner();\n const [state, setState] = useSignal<S>(initialState);\n const [pending, setPending] = useSignal(false);\n let latest = 0;\n\n const dispatch = (...args: A): Promise<void> => {\n latest += 1;\n const id = latest;\n const previous = untrack(state);\n const commit = (value: S): void => {\n if (id !== latest) return;\n batch(() => {\n setState(() => value);\n setPending(false);\n });\n };\n const fail = (error: unknown): void => {\n if (id !== latest) return;\n setPending(false);\n if (owner === null) throw error;\n handleError(error, owner);\n };\n let result: S | PromiseLike<S>;\n try {\n result = untrack(() => action(previous, ...args));\n } catch (error) {\n if (owner === null) {\n // `fail` would rethrow synchronously; without an owner the promise carries the error.\n if (id === latest) setPending(false);\n return Promise.reject(error);\n }\n fail(error);\n return Promise.resolve();\n }\n if (!isPromiseLike<S>(result)) {\n commit(result);\n return Promise.resolve();\n }\n setPending(true);\n return Promise.resolve(result).then(commit, fail);\n };\n return [state, dispatch, pending];\n}\n"],"mappings":"A,oOAIA,SAASA,EAAiB,EAAyC,CACjE,OACEC,IAAU,OACT,OAAOA,GAAU,UAAY,OAAOA,GAAU,aAC/C,OAAQA,EAA6B,MAAS,UAElD,CAiCA,SAAgBC,EACd,EACA,EAC2F,CAC3F,IAAMC,EAAQC,EAAa,EACrB,CAACC,EAAOC,GAAYC,EAAaC,CAAY,EAC7C,CAACC,EAASC,GAAcH,EAAU,EAAK,EACzCI,EAAS,EAsCb,MAAO,CAACN,GApCU,GAAGO,IAA2B,CAC9C,GAAU,EACV,IAAMC,EAAKF,EACLG,EAAWC,EAAQV,CAAK,EACxBW,EAAU,GAAmB,CAC7BH,IAAOF,GACXM,MAAY,CACVX,MAAeL,CAAK,EACpBS,EAAW,EAAK,CAClB,CAAC,CACH,EACMQ,EAAQ,GAAyB,CACrC,GAAIL,IAAOF,EACX,CACA,GADAD,EAAW,EAAK,EACZP,IAAU,KAAM,MAAMgB,EAC1BC,EAAYD,EAAOhB,CAAK,CAFR,CAGlB,EACIkB,EACJ,GAAI,CACF,EAASN,MAAcO,EAAOR,EAAU,GAAGF,CAAI,CAAC,CAClD,OAASO,EAAO,CAOd,OANIhB,IAAU,MAERU,IAAOF,GAAQD,EAAW,EAAK,EAC5B,QAAQ,OAAOS,CAAK,IAE7BD,EAAKC,CAAK,EACH,QAAQ,QAAQ,EACzB,CAMA,OALKnB,EAAiBqB,CAAM,GAI5BX,EAAW,EAAI,EACR,QAAQ,QAAQW,CAAM,CAAC,CAAC,KAAKL,EAAQE,CAAI,IAJ9CF,EAAOK,CAAM,EACN,QAAQ,QAAQ,EAI3B,EACyBZ,CAAO,CAClC,C"}
@@ -0,0 +1,2 @@
1
+ import{currentOwner as e}from"./extend/index.js";function t(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(!Object.is(e[n],t[n]))return!1;return!0}function n(e){let t=e;for(;t!==null&&t.parent!==null;)t=t.parent;return t}function r(r,i){let a=i?.limit??100;if(!Number.isInteger(a)||a<1)throw RangeError(`SHADOW_CACHE_LIMIT`);let o=/* @__PURE__ */ new WeakMap;return(...i)=>{let s=n(e());if(s===null)return r(...i);let c=o.get(s);c===void 0&&(c=[],o.set(s,c));for(let e of c)if(t(e.args,i))return e.value;let l=r(...i);return c.push({args:i,value:l}),c.length>a&&c.shift(),l}}export{r as cache};
2
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","names":["sameArgs","a","b","i","rootOf","root","owner","cache","limit","options","scopes","args","currentOwner","fn","entries","entry","value"],"sources":["../../src/cache.ts"],"sourcesContent":["import { currentOwner, type Owner } from \"./extend\";\n\n/** Options of {@link cache}. @since 1.0.0 */\nexport interface CacheOptions {\n /**\n * Most results kept per scope (one root); the oldest is dropped first. A positive integer.\n * @default 100\n */\n limit?: number;\n}\n\ninterface Entry {\n readonly args: readonly unknown[];\n readonly value: unknown;\n}\n\nfunction sameArgs(a: readonly unknown[], b: readonly unknown[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i += 1) {\n if (!Object.is(a[i], b[i])) return false;\n }\n return true;\n}\n\n/** The outermost owner: the root of the render (a request on the server, the app on the client). */\nfunction rootOf(owner: Owner | null): Owner | null {\n let root = owner;\n while (root !== null && root.parent !== null) root = root.parent;\n return root;\n}\n\n/**\n * Memoizes `fn` per request: within one root (a server render, or the app on the client) the same\n * arguments return the same result without calling `fn` again. Arguments compare with `Object.is`,\n * position by position. Results are kept in a list bounded by `limit`; the oldest is dropped first.\n * A call that throws is not kept. Outside any owner nothing is scoped, so `fn` runs every time.\n *\n * Use it to share one data fetch between components rendered in the same request.\n *\n * @param fn The function to memoize. Its result is kept as is, so a promise is shared, not awaited.\n * @param options Per-scope limit. Undefined uses the default.\n * @returns A function with the same signature.\n * @throws RangeError when `limit` is not a positive integer (message code `SHADOW_CACHE_LIMIT` in\n * production builds). The returned function rethrows what `fn` throws.\n * @example\n * import { cache } from \"@shadow-js/core\";\n *\n * const loadUser = cache((id: string) =>\n * fetch(`/api/users/${id}`).then((response) => response.json()),\n * );\n * // Two components calling loadUser(\"u1\") in the same render fetch once.\n * @see useResource\n * @since 1.0.0\n */\nexport function cache<A extends unknown[], R>(\n fn: (...args: A) => R,\n options?: CacheOptions,\n): (...args: A) => R {\n const limit = options?.limit ?? 100;\n if (!Number.isInteger(limit) || limit < 1) {\n throw new RangeError(\n __DEV__ ? \"cache: limit must be a positive integer\" : \"SHADOW_CACHE_LIMIT\",\n );\n }\n const scopes = new WeakMap<Owner, Entry[]>();\n return (...args: A): R => {\n const root = rootOf(currentOwner());\n if (root === null) return fn(...args);\n let entries = scopes.get(root);\n if (entries === undefined) {\n entries = [];\n scopes.set(root, entries);\n }\n for (const entry of entries) {\n if (sameArgs(entry.args, args)) return entry.value as R;\n }\n const value = fn(...args);\n entries.push({ args, value });\n if (entries.length > limit) entries.shift();\n return value;\n };\n}\n"],"mappings":"A,iDAgBA,SAASA,EAAS,EAAuB,EAAgC,CACvE,GAAIC,EAAE,SAAWC,EAAE,OAAQ,MAAO,GAClC,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAE,OAAQ,GAAK,EACjC,GAAI,CAAC,OAAO,GAAGA,EAAEE,GAAID,EAAEC,EAAE,EAAG,MAAO,GAErC,MAAO,EACT,CAGA,SAASC,EAAO,EAAmC,CACjD,IAAIC,EAAOC,EACX,KAAOD,IAAS,MAAQA,EAAK,SAAW,MAAM,EAAOA,EAAK,OAC1D,OAAOA,CACT,CAyBA,SAAgBE,EACd,EACA,EACmB,CACnB,IAAMC,EAAQC,GAAS,OAAS,IAChC,GAAI,CAAC,OAAO,UAAUD,CAAK,GAAKA,EAAQ,EACtC,MAAU,WAC8C,oBACxD,EAEF,IAAME,kBAAS,IAAI,QACnB,OAAQ,GAAGC,IAAe,CACxB,IAAMN,EAAOD,EAAOQ,EAAa,CAAC,EAClC,GAAIP,IAAS,KAAM,OAAOQ,EAAG,GAAGF,CAAI,EACpC,IAAIG,EAAUJ,EAAO,IAAIL,CAAI,EACzBS,IAAY,IAAA,KACd,EAAU,CAAC,EACXJ,EAAO,IAAIL,EAAMS,CAAO,GAE1B,IAAK,IAAMC,KAASD,EAClB,GAAId,EAASe,EAAM,KAAMJ,CAAI,EAAG,OAAOI,EAAM,MAE/C,IAAMC,EAAQH,EAAG,GAAGF,CAAI,EAGxB,OAFAG,EAAQ,KAAK,CAAE,OAAM,OAAM,CAAC,EACxBA,EAAQ,OAASN,GAAOM,EAAQ,MAAM,EACnCE,CACT,CACF,C"}
@@ -0,0 +1,2 @@
1
+ import{ShadowError as e}from"./internal/diagnostics.js";import{Owner as t}from"./internal/owner.js";import{runWithOwner as n}from"./ownership.js";import{useRenderEffect as r}from"./effect.js";import{useSignal as i}from"./signal.js";import{currentOwner as a}from"./extend/index.js";function o(e,o){let s=Symbol(o?.name??`context`),c=e=>{let o=new t(a()),c=o.context,l=Object.create(c);return l[s]=e.value,o.context=l,n(o,()=>{let[t,n]=i(void 0,{equals:!1});return r(()=>e.children,e=>{n(()=>e)}),t})};return Object.assign(c,{id:s,defaultValue:e,Provider:c})}function s(e,r,i){let o=new t(a()),s=Object.create(o.context);return s[e.id]=r,o.context=s,n(o,i)}function c(t){let n=a()?.context;if(n!=null&&t.id in n)return n[t.id];if(t.defaultValue===void 0)throw new e(`CONTEXT_MISSING`);return t.defaultValue}export{o as createContext,s as runWithContext,c as useContext};
2
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":["createContext","id","options","provider","scope","Owner","currentOwner","inherited","next","props","runWithOwner","children","setChildren","useSignal","useRenderEffect","value","runWithContext","context","fn","useContext","map","ShadowError"],"sources":["../../src/context.ts"],"sourcesContent":["import { useRenderEffect } from \"./effect\";\nimport { currentOwner, Owner, ShadowError } from \"./extend\";\nimport { runWithOwner } from \"./ownership\";\nimport { useSignal } from \"./signal\";\n\n/**\n * A context made by {@link createContext}: a value that a subtree receives from the nearest provider\n * above it. The context is itself the provider component; `Provider` is the same function.\n * @since 1.0.0\n */\nexport interface Context<T> {\n /**\n * Renders `children` with `value` provided. The value is read once, when the provider is created;\n * provide an accessor or a store for a value that changes. Returns an accessor of the children.\n */\n (props: { value: T; children?: unknown }): unknown;\n /** The unique key the provided value is stored under, described by the context's `name`. */\n readonly id: symbol;\n /** The value {@link useContext} returns without a provider. `undefined` means none: it throws. */\n readonly defaultValue: T | undefined;\n /** The same component, for code written as `<Ctx.Provider value={...}>`. */\n readonly Provider: (props: { value: T; children?: unknown }) => unknown;\n}\n\n/**\n * Options of {@link createContext}.\n * @since 1.0.0\n */\nexport interface ContextOptions {\n /**\n * Label shown in diagnostics and used as the description of the context's `id` symbol.\n * @default \"context\"\n */\n name?: string;\n}\n\n/**\n * Creates a context: a value that components read with {@link useContext} without passing it\n * through props. Render the returned component around a subtree to provide a value. The value is\n * read once; pass a signal accessor or a store to provide something reactive. On the server the\n * provider builds its subtree once.\n *\n * @param defaultValue Returned by `useContext` when no provider is above the reader. Undefined\n * (or omitted) means the context has no default, so reading it without a provider throws.\n * @param options A diagnostics name. Undefined uses the default.\n * @returns The context, which is also its provider component.\n * @example\n * import { createContext, useContext } from \"@shadow-js/core\";\n *\n * const Theme = createContext<\"light\" | \"dark\">(\"light\", { name: \"Theme\" });\n *\n * function Label() {\n * return <p>Theme: {useContext(Theme)}</p>;\n * }\n *\n * const app = <Theme.Provider value=\"dark\"><Label /></Theme.Provider>;\n * @see useContext\n * @since 1.0.0\n */\nexport function createContext<T>(defaultValue?: T, options?: ContextOptions): Context<T> {\n const id = Symbol(options?.name ?? \"context\");\n const provider = (props: { value: T; children?: unknown }): unknown => {\n const scope = new Owner(currentOwner());\n const inherited = scope.context;\n const next = Object.create(inherited) as Record<symbol, unknown>;\n next[id] = props.value;\n scope.context = next;\n // A render effect, so a children expression that reads signals stays reactive and still sees\n // the provided value. An effect (not a memo) because component setup may legitimately write\n // signals, and errors thrown while building the subtree must reach the error boundaries.\n return runWithOwner(scope, () => {\n if (__SERVER__) {\n // Nothing is reactive on the server: build the subtree once.\n const built = props.children;\n return () => built;\n }\n const [children, setChildren] = useSignal<unknown>(undefined, { equals: false });\n useRenderEffect(\n () => props.children,\n (value) => {\n setChildren(() => value);\n },\n );\n return children;\n });\n };\n return Object.assign(provider, { id, defaultValue, Provider: provider }) as Context<T>;\n}\n\n/**\n * Runs `fn` with `value` provided for `context` (as a Provider does), without a render effect: the\n * value is set for the duration of `fn` only, and what `fn` creates sees it. Used where a renderer\n * builds a subtree that must not be re-run by a Provider's effect. `fn` runs untracked, in a new\n * child owner of the current owner that is disposed with it.\n *\n * @param context The context to provide.\n * @param value The value `useContext(context)` returns inside `fn`.\n * @param fn Runs once, synchronously.\n * @returns What `fn` returns.\n * @example\n * import { createContext, useContext } from \"@shadow-js/core\";\n * import { runWithContext } from \"@shadow-js/core/extend\";\n *\n * const Theme = createContext(\"light\");\n * const theme = runWithContext(Theme, \"dark\", () => useContext(Theme));\n * console.log(theme); // \"dark\"\n * @see createContext\n * @since 1.0.0\n */\nexport function runWithContext<T, R>(context: Context<T>, value: T, fn: () => R): R {\n const scope = new Owner(currentOwner());\n const next = Object.create(scope.context) as Record<symbol, unknown>;\n next[context.id] = value;\n scope.context = next;\n return runWithOwner(scope, fn);\n}\n\n/**\n * Reads the nearest provided value of `context`. Falls back to its default; throws when there is\n * neither a provider nor a default, because no correct value exists. The lookup follows the current\n * owner, so call it while a component runs (or in an effect or memo it creates), not after an\n * `await` or in an event handler. The read is not tracked.\n *\n * @param context A context made by {@link createContext}.\n * @returns The value of the nearest provider above the current owner, else the default value.\n * @throws ShadowError `CONTEXT_MISSING` when no provider is above the current owner and the\n * context's default is `undefined`.\n * @example\n * import { createContext, useContext } from \"@shadow-js/core\";\n *\n * const User = createContext<{ name: string }>();\n *\n * function Greeting() {\n * const user = useContext(User); // throws CONTEXT_MISSING without a provider\n * return <p>Hello, {user.name}</p>;\n * }\n * @see createContext\n * @since 1.0.0\n */\nexport function useContext<T>(context: Context<T>): T {\n const map = currentOwner()?.context;\n if (map !== null && map !== undefined && context.id in map) return map[context.id] as T;\n if (context.defaultValue === undefined) throw new ShadowError(\"CONTEXT_MISSING\");\n return context.defaultValue;\n}\n"],"mappings":"A,yRA2DA,SAAgBA,EAAiB,EAAkB,EAAsC,CACvF,IAAMC,EAAK,OAAOC,GAAS,MAAQ,SAAS,EACtCC,EAAY,GAAqD,CACrE,IAAMC,EAAQ,IAAIC,EAAMC,EAAa,CAAC,EAChCC,EAAYH,EAAM,QAClBI,EAAO,OAAO,OAAOD,CAAS,EAMpC,MALA,GAAKN,GAAMQ,EAAM,MACjB,EAAM,QAAUD,EAITE,EAAaN,MAAa,CAM/B,GAAM,CAACO,EAAUC,GAAeC,EAAmB,IAAA,GAAW,CAAE,OAAQ,EAAM,CAAC,EAO/E,OANAC,MACQL,EAAM,SACX,GAAU,CACTG,MAAkBG,CAAK,CACzB,CACF,EACOJ,CACT,CAAC,CACH,EACA,OAAO,OAAO,OAAOR,EAAU,CAAE,KAAI,eAAc,SAAUA,CAAS,CAAC,CACzE,CAsBA,SAAgBa,EAAqB,EAAqB,EAAU,EAAgB,CAClF,IAAMZ,EAAQ,IAAIC,EAAMC,EAAa,CAAC,EAChCE,EAAO,OAAO,OAAOJ,EAAM,OAAO,EAGxC,MAFA,GAAKa,EAAQ,IAAMF,EACnB,EAAM,QAAUP,EACTE,EAAaN,EAAOc,CAAE,CAC/B,CAwBA,SAAgBC,EAAc,EAAwB,CACpD,IAAMC,EAAMd,EAAa,CAAC,EAAE,QAC5B,GAAIc,GAAQ,MAA6BH,EAAQ,MAAMG,EAAK,OAAOA,EAAIH,EAAQ,IAC/E,GAAIA,EAAQ,eAAiB,IAAA,GAAW,MAAM,IAAII,EAAY,iBAAiB,EAC/E,OAAOJ,EAAQ,YACjB,C"}
@@ -0,0 +1,2 @@
1
+ import"./internal/diagnostics.js";import{untrack as e}from"./ownership.js";import{createComputation as t,currentOwner as n}from"./extend/index.js";const r=Symbol(`held`);function i(){for(let e=n();e!==null;e=e.parent)if(e.gate!==null)return e.gate;return null}function a(e,a,o,s,c){n();let l=e,u=a,d=s,f=o?null:i();if(f!==null){let e=!1,t=()=>e?!1:f()?!0:(e=!0,!1);if(u===null){let e=l;l=n=>t()?void 0:e(n)}else{let e=l,n=u,i=d;d=!1,l=n=>t()?r:e(n),u=(e,t)=>{if(e!==r){if(i)i=!1;else return n(e,t===r?void 0:t)}}}}t({kind:`effect`,fn:l,render:o,defer:d,...u===null?{}:{apply:u},...c===void 0?{}:{name:c}})}function o(e,t,n){typeof t==`function`?a(e,t,!1,n?.defer===!0,n?.name):a(e,null,!1,!1,t?.name)}function s(e,t){a(e,t??null,!0,!1,void 0)}function c(t){a(()=>e(t),null,!1,!1,`onMount`)}export{c as onMount,o as useEffect,s as useRenderEffect};
2
+ //# sourceMappingURL=effect.js.map