@pithyjs/core 0.1.0-beta.0 → 0.1.0-beta.10

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 (226) hide show
  1. package/README.md +37 -6
  2. package/dist/a11y/focus-trap.d.ts.map +1 -1
  3. package/dist/a11y/focus-trap.js +2 -0
  4. package/dist/a11y/focus-trap.js.map +1 -1
  5. package/dist/a11y/index.d.ts +4 -4
  6. package/dist/a11y/index.js +4 -4
  7. package/dist/a11y/index.js.map +1 -1
  8. package/dist/a11y/keyboard-utils.js.map +1 -1
  9. package/dist/a11y/roving-tabindex.js.map +1 -1
  10. package/dist/a11y/skip-link.js.map +1 -1
  11. package/dist/compile/bindSwitchCases.d.ts +8 -3
  12. package/dist/compile/bindSwitchCases.d.ts.map +1 -1
  13. package/dist/compile/bindSwitchCases.js +113 -177
  14. package/dist/compile/bindSwitchCases.js.map +1 -1
  15. package/dist/compile/binds/bindBoundAttributes.d.ts +1 -0
  16. package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -1
  17. package/dist/compile/binds/bindBoundAttributes.js +24 -2
  18. package/dist/compile/binds/bindBoundAttributes.js.map +1 -1
  19. package/dist/compile/binds/bindClassDirectives.d.ts +3 -0
  20. package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
  21. package/dist/compile/binds/bindClassDirectives.js +59 -21
  22. package/dist/compile/binds/bindClassDirectives.js.map +1 -1
  23. package/dist/compile/binds/bindComponentsTags.d.ts +2 -0
  24. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
  25. package/dist/compile/binds/bindComponentsTags.js +171 -74
  26. package/dist/compile/binds/bindComponentsTags.js.map +1 -1
  27. package/dist/compile/binds/bindConditionals.d.ts +2 -2
  28. package/dist/compile/binds/bindConditionals.d.ts.map +1 -1
  29. package/dist/compile/binds/bindConditionals.js +22 -5
  30. package/dist/compile/binds/bindConditionals.js.map +1 -1
  31. package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -1
  32. package/dist/compile/binds/bindDefaultTwoWay.js +2 -1
  33. package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -1
  34. package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
  35. package/dist/compile/binds/bindDeferDirectives.js +45 -15
  36. package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
  37. package/dist/compile/binds/bindErrorBoundary.d.ts +13 -2
  38. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
  39. package/dist/compile/binds/bindErrorBoundary.js +25 -10
  40. package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
  41. package/dist/compile/binds/bindEventHandlers.js +2 -2
  42. package/dist/compile/binds/bindEventHandlers.js.map +1 -1
  43. package/dist/compile/binds/bindRefDirectives.js.map +1 -1
  44. package/dist/compile/binds/bindStyleDirectives.d.ts +17 -0
  45. package/dist/compile/binds/bindStyleDirectives.d.ts.map +1 -0
  46. package/dist/compile/binds/bindStyleDirectives.js +47 -0
  47. package/dist/compile/binds/bindStyleDirectives.js.map +1 -0
  48. package/dist/compile/binds/bindTextInterpolations.d.ts +2 -1
  49. package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
  50. package/dist/compile/binds/bindTextInterpolations.js +55 -17
  51. package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
  52. package/dist/compile/binds/directiveRegistry.js.map +1 -1
  53. package/dist/compile/binds/forwardedAttrs.d.ts +22 -0
  54. package/dist/compile/binds/forwardedAttrs.d.ts.map +1 -0
  55. package/dist/compile/binds/forwardedAttrs.js +66 -0
  56. package/dist/compile/binds/forwardedAttrs.js.map +1 -0
  57. package/dist/compile/binds/propNames.d.ts +14 -0
  58. package/dist/compile/binds/propNames.d.ts.map +1 -0
  59. package/dist/compile/binds/propNames.js +116 -0
  60. package/dist/compile/binds/propNames.js.map +1 -0
  61. package/dist/compile/compileExpression.js.map +1 -1
  62. package/dist/compile/compileNodes.d.ts.map +1 -1
  63. package/dist/compile/compileNodes.js +6 -3
  64. package/dist/compile/compileNodes.js.map +1 -1
  65. package/dist/compile/compileTemplate.d.ts +3 -4
  66. package/dist/compile/compileTemplate.d.ts.map +1 -1
  67. package/dist/compile/compileTemplate.js +28 -31
  68. package/dist/compile/compileTemplate.js.map +1 -1
  69. package/dist/compile/componentResult.d.ts +100 -0
  70. package/dist/compile/componentResult.d.ts.map +1 -0
  71. package/dist/compile/componentResult.js +138 -0
  72. package/dist/compile/componentResult.js.map +1 -0
  73. package/dist/compile/contentProjection.d.ts +1 -1
  74. package/dist/compile/contentProjection.d.ts.map +1 -1
  75. package/dist/compile/contentProjection.js +32 -15
  76. package/dist/compile/contentProjection.js.map +1 -1
  77. package/dist/compile/forLoops/bindForLoops.d.ts +2 -2
  78. package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -1
  79. package/dist/compile/forLoops/bindForLoops.js +9 -22
  80. package/dist/compile/forLoops/bindForLoops.js.map +1 -1
  81. package/dist/compile/forLoops/createLoopManager.d.ts +6 -3
  82. package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
  83. package/dist/compile/forLoops/createLoopManager.js +144 -114
  84. package/dist/compile/forLoops/createLoopManager.js.map +1 -1
  85. package/dist/compile/forLoops/index.d.ts +5 -5
  86. package/dist/compile/forLoops/index.js +5 -5
  87. package/dist/compile/forLoops/index.js.map +1 -1
  88. package/dist/compile/forLoops/loopHelpers.d.ts +6 -0
  89. package/dist/compile/forLoops/loopHelpers.d.ts.map +1 -1
  90. package/dist/compile/forLoops/loopHelpers.js +17 -0
  91. package/dist/compile/forLoops/loopHelpers.js.map +1 -1
  92. package/dist/compile/forLoops/loopSignals.js +2 -2
  93. package/dist/compile/forLoops/loopSignals.js.map +1 -1
  94. package/dist/compile/forLoops/loopTraversal.js +2 -2
  95. package/dist/compile/forLoops/loopTraversal.js.map +1 -1
  96. package/dist/compile/handleConditionalChain.d.ts +2 -2
  97. package/dist/compile/handleConditionalChain.d.ts.map +1 -1
  98. package/dist/compile/handleConditionalChain.js +21 -83
  99. package/dist/compile/handleConditionalChain.js.map +1 -1
  100. package/dist/compile/index.d.ts +17 -14
  101. package/dist/compile/index.d.ts.map +1 -1
  102. package/dist/compile/index.js +28 -12
  103. package/dist/compile/index.js.map +1 -1
  104. package/dist/compile/injectScopedStyle.js.map +1 -1
  105. package/dist/compile/nodeExpando.d.ts +6 -0
  106. package/dist/compile/nodeExpando.d.ts.map +1 -1
  107. package/dist/compile/nodeExpando.js.map +1 -1
  108. package/dist/compile/parseHtml.d.ts.map +1 -1
  109. package/dist/compile/parseHtml.js +2 -2
  110. package/dist/compile/parseHtml.js.map +1 -1
  111. package/dist/compile/pithyTreeToDom.js +1 -1
  112. package/dist/compile/pithyTreeToDom.js.map +1 -1
  113. package/dist/compile/renderBranch.d.ts +13 -0
  114. package/dist/compile/renderBranch.d.ts.map +1 -0
  115. package/dist/compile/renderBranch.js +65 -0
  116. package/dist/compile/renderBranch.js.map +1 -0
  117. package/dist/compile/renderChildren.d.ts +17 -0
  118. package/dist/compile/renderChildren.d.ts.map +1 -1
  119. package/dist/compile/renderChildren.js +22 -3
  120. package/dist/compile/renderChildren.js.map +1 -1
  121. package/dist/compile/ssrCrashes.d.ts +116 -0
  122. package/dist/compile/ssrCrashes.d.ts.map +1 -0
  123. package/dist/compile/ssrCrashes.js +173 -0
  124. package/dist/compile/ssrCrashes.js.map +1 -0
  125. package/dist/compile/ssrMode.js +1 -1
  126. package/dist/compile/ssrMode.js.map +1 -1
  127. package/dist/compile/textValue.js.map +1 -1
  128. package/dist/compile/trimBlankEdges.d.ts +2 -0
  129. package/dist/compile/trimBlankEdges.d.ts.map +1 -0
  130. package/dist/compile/trimBlankEdges.js +15 -0
  131. package/dist/compile/trimBlankEdges.js.map +1 -0
  132. package/dist/config/index.js.map +1 -1
  133. package/dist/index.d.ts +6 -6
  134. package/dist/index.js +6 -6
  135. package/dist/index.js.map +1 -1
  136. package/dist/interfaces/index.d.ts +2 -2
  137. package/dist/interfaces/index.js +2 -2
  138. package/dist/interfaces/index.js.map +1 -1
  139. package/dist/interfaces/ref-signal.interface.js.map +1 -1
  140. package/dist/interfaces/ref.interface.js.map +1 -1
  141. package/dist/runtime/applyBindings.d.ts +5 -5
  142. package/dist/runtime/applyBindings.d.ts.map +1 -1
  143. package/dist/runtime/applyBindings.js +97 -21
  144. package/dist/runtime/applyBindings.js.map +1 -1
  145. package/dist/runtime/bindings/applyComponent.d.ts +2 -2
  146. package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
  147. package/dist/runtime/bindings/applyComponent.js +137 -39
  148. package/dist/runtime/bindings/applyComponent.js.map +1 -1
  149. package/dist/runtime/bindings/applyDefer.d.ts +1 -1
  150. package/dist/runtime/bindings/applyDefer.d.ts.map +1 -1
  151. package/dist/runtime/bindings/applyDefer.js +46 -18
  152. package/dist/runtime/bindings/applyDefer.js.map +1 -1
  153. package/dist/runtime/bindings/applySimple.d.ts +2 -1
  154. package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
  155. package/dist/runtime/bindings/applySimple.js +70 -14
  156. package/dist/runtime/bindings/applySimple.js.map +1 -1
  157. package/dist/runtime/bindings/applyStructural.d.ts +1 -1
  158. package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
  159. package/dist/runtime/bindings/applyStructural.js +58 -68
  160. package/dist/runtime/bindings/applyStructural.js.map +1 -1
  161. package/dist/runtime/bindings/helpers.d.ts +1 -1
  162. package/dist/runtime/bindings/helpers.js +1 -1
  163. package/dist/runtime/bindings/helpers.js.map +1 -1
  164. package/dist/runtime/bindings/index.d.ts +6 -6
  165. package/dist/runtime/bindings/index.d.ts.map +1 -1
  166. package/dist/runtime/bindings/index.js +5 -5
  167. package/dist/runtime/bindings/index.js.map +1 -1
  168. package/dist/runtime/bindings/types.d.ts +12 -1
  169. package/dist/runtime/bindings/types.d.ts.map +1 -1
  170. package/dist/runtime/bindings/types.js.map +1 -1
  171. package/dist/runtime/bootstrap.d.ts +1 -1
  172. package/dist/runtime/bootstrap.js +1 -1
  173. package/dist/runtime/bootstrap.js.map +1 -1
  174. package/dist/runtime/createContextProxy.js.map +1 -1
  175. package/dist/runtime/deferHelpers.d.ts +1 -1
  176. package/dist/runtime/deferHelpers.js.map +1 -1
  177. package/dist/runtime/html.d.ts.map +1 -1
  178. package/dist/runtime/html.js +6 -5
  179. package/dist/runtime/html.js.map +1 -1
  180. package/dist/runtime/index.d.ts +6 -5
  181. package/dist/runtime/index.d.ts.map +1 -1
  182. package/dist/runtime/index.js +7 -5
  183. package/dist/runtime/index.js.map +1 -1
  184. package/dist/runtime/lazy.js +1 -1
  185. package/dist/runtime/lazy.js.map +1 -1
  186. package/dist/runtime/module-cache.js.map +1 -1
  187. package/dist/runtime/onDestroy.d.ts +7 -0
  188. package/dist/runtime/onDestroy.d.ts.map +1 -1
  189. package/dist/runtime/onDestroy.js +16 -1
  190. package/dist/runtime/onDestroy.js.map +1 -1
  191. package/dist/runtime/parseIdentifiersFromTemplate.js +1 -1
  192. package/dist/runtime/parseIdentifiersFromTemplate.js.map +1 -1
  193. package/dist/runtime/resource/createAction.d.ts +44 -0
  194. package/dist/runtime/resource/createAction.d.ts.map +1 -0
  195. package/dist/runtime/resource/createAction.js +102 -0
  196. package/dist/runtime/resource/createAction.js.map +1 -0
  197. package/dist/runtime/resource/createResource.d.ts +56 -0
  198. package/dist/runtime/resource/createResource.d.ts.map +1 -0
  199. package/dist/runtime/resource/createResource.js +102 -0
  200. package/dist/runtime/resource/createResource.js.map +1 -0
  201. package/dist/runtime/resource/engine.d.ts +136 -0
  202. package/dist/runtime/resource/engine.d.ts.map +1 -0
  203. package/dist/runtime/resource/engine.js +363 -0
  204. package/dist/runtime/resource/engine.js.map +1 -0
  205. package/dist/runtime/resource/index.d.ts +19 -0
  206. package/dist/runtime/resource/index.d.ts.map +1 -0
  207. package/dist/runtime/resource/index.js +18 -0
  208. package/dist/runtime/resource/index.js.map +1 -0
  209. package/dist/runtime/resource/types.d.ts +240 -0
  210. package/dist/runtime/resource/types.d.ts.map +1 -0
  211. package/dist/runtime/resource/types.js +9 -0
  212. package/dist/runtime/resource/types.js.map +1 -0
  213. package/dist/types/globals.d.ts +10 -1
  214. package/dist/types/globals.d.ts.map +1 -1
  215. package/dist/types/globals.js.map +1 -1
  216. package/dist/types/index.d.ts +15 -1
  217. package/dist/types/index.d.ts.map +1 -1
  218. package/dist/types/index.js.map +1 -1
  219. package/dist/utilities/index.d.ts +2 -2
  220. package/dist/utilities/index.js +2 -2
  221. package/dist/utilities/index.js.map +1 -1
  222. package/dist/utilities/ref-signal.utility.d.ts +1 -1
  223. package/dist/utilities/ref-signal.utility.js.map +1 -1
  224. package/dist/utilities/ref.untility.d.ts +1 -1
  225. package/dist/utilities/ref.untility.js.map +1 -1
  226. package/package.json +14 -9
@@ -0,0 +1,240 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.core.resource.types",
4
+ "title": "Async State Primitive Types",
5
+ "category": "types"
6
+ }
7
+ */
8
+ /**
9
+ * Public types for the async-state primitives (`createResource`, `createAction`).
10
+ *
11
+ * @module runtime/resource/types
12
+ */
13
+ /**
14
+ * Read access to a signal: call it to read (tracked normally inside an
15
+ * effect), `subscribe` to observe. Deliberately omits `.set()`.
16
+ *
17
+ * `@pithyjs/signals` exports `ReadonlySignal<T> = () => T`, which drops
18
+ * `.subscribe` as well. Observing without an effect is legitimate read access,
19
+ * so the handles use this instead — the write path is what has to be closed
20
+ * off, not the read path. If this proves generally useful it belongs in
21
+ * `@pithyjs/signals` beside `Signal` and `ReadonlySignal`.
22
+ */
23
+ export type ReadableSignal<T> = (() => T) & {
24
+ subscribe: (fn: (value: T) => void) => () => void;
25
+ };
26
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ResourceStatus","stability":"stable","signature":"type ResourceStatus = 'idle' | 'loading' | 'success' | 'error'"} */
27
+ /**
28
+ * Lifecycle status of a resource or action.
29
+ *
30
+ * NAMING NOTE: this is deliberately NOT called `ResourceState`. `@pithyjs/router`
31
+ * already exports an interface named `ResourceState` (route loader state), and
32
+ * `@pithyjs/core` re-exports its whole runtime barrel — an app importing both
33
+ * packages would otherwise face an ambiguous name.
34
+ */
35
+ export type ResourceStatus = 'idle' | 'loading' | 'success' | 'error';
36
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ResourceFetcher","stability":"stable","signature":"type ResourceFetcher<T> = (signal: AbortSignal) => T | Promise<T>"} */
37
+ /**
38
+ * The function a resource calls to produce its data.
39
+ *
40
+ * Receives an `AbortSignal` that is aborted when the resource is refetched,
41
+ * reset or destroyed. Forwarding it to `fetch()` is a courtesy optimisation
42
+ * only — correctness never depends on the fetcher honouring it (see
43
+ * `engine.ts` for the generation counter that guarantees it).
44
+ *
45
+ * @typeParam T - Type of the resolved data.
46
+ */
47
+ export type ResourceFetcher<T> = (signal: AbortSignal) => T | Promise<T>;
48
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ActionPerformer","stability":"stable","signature":"type ActionPerformer<T, A extends unknown[]> = (...args: A) => T | Promise<T>"} */
49
+ /**
50
+ * The function an action calls to perform its side effect.
51
+ *
52
+ * @typeParam T - Type of the resolved data.
53
+ * @typeParam A - Tuple of arguments forwarded from `run()`.
54
+ */
55
+ export type ActionPerformer<T, A extends unknown[]> = (...args: A) => T | Promise<T>;
56
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ActionResult","stability":"stable","signature":"type ActionResult<T, E = unknown> = { ok: true; data: T } | { ok: false; dropped: false; error: E } | { ok: false; dropped: true }"} */
57
+ /**
58
+ * Discriminated union resolved by `run()` and `refetch()`.
59
+ *
60
+ * These methods RESOLVE this union — they never reject. This deliberately
61
+ * diverges from the router's `executeLoader`, which rejects on failure; see the
62
+ * comment above `run()` in `createAction.ts` for the rationale.
63
+ *
64
+ * Narrowing:
65
+ * ```ts
66
+ * if (result.ok) result.data; // success
67
+ * else if (result.dropped) { } // superseded / destroyed / SSR — no run happened
68
+ * else result.error; // failure, error carried by reference
69
+ * ```
70
+ *
71
+ * @typeParam T - Type of the resolved data.
72
+ * @typeParam E - Type of the carried error (defaults to `unknown` — thrown values
73
+ * are carried by reference and never wrapped in an `Error`).
74
+ */
75
+ export type ActionResult<T, E = unknown> = {
76
+ readonly ok: true;
77
+ readonly data: T;
78
+ } | {
79
+ readonly ok: false;
80
+ readonly dropped: false;
81
+ readonly error: E;
82
+ } | {
83
+ readonly ok: false;
84
+ readonly dropped: true;
85
+ };
86
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ResourceOptions","stability":"stable","signature":"interface ResourceOptions"} */
87
+ /** Options for {@link createResource}. */
88
+ export interface ResourceOptions {
89
+ /**
90
+ * Fetch as soon as the resource is created.
91
+ *
92
+ * Ignored under server rendering (SSG *and* dynamic SSR), where the
93
+ * resource always stays `'idle'`.
94
+ *
95
+ * @default true
96
+ */
97
+ immediate?: boolean;
98
+ /**
99
+ * Keep the last successful `data` readable while a refetch is in flight,
100
+ * **and after that refetch fails**. When `false`, `data` is cleared the
101
+ * moment a refetch starts.
102
+ *
103
+ * The post-failure half matters: on failure `status` becomes `'error'` and
104
+ * `error` is populated, but `data` still holds the last success. A view that
105
+ * renders `data` whenever it is defined will therefore show stale content
106
+ * beside a fresh error unless it checks `status` too. That is the intended
107
+ * behaviour — it is what makes a transient refetch failure non-destructive —
108
+ * but it has to be handled deliberately.
109
+ *
110
+ * @default false
111
+ */
112
+ keepPreviousData?: boolean;
113
+ }
114
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ActionOverlap","stability":"stable","signature":"type ActionOverlap = 'drop' | 'restart'"} */
115
+ /**
116
+ * What happens when `run()` is called while a previous run is still in flight.
117
+ *
118
+ * - `'drop'` — the new call is ignored and resolves `{ ok: false, dropped: true }`.
119
+ * The default for actions: double-submitting a form should not fire twice.
120
+ * - `'restart'` — the new call supersedes the old one, which resolves
121
+ * `{ ok: false, dropped: true }` and can never write state again.
122
+ */
123
+ export type ActionOverlap = 'drop' | 'restart';
124
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ActionOptions","stability":"stable","signature":"interface ActionOptions"} */
125
+ /** Options for {@link createAction}. */
126
+ export interface ActionOptions {
127
+ /**
128
+ * Overlap policy for concurrent `run()` calls.
129
+ *
130
+ * @default 'drop'
131
+ */
132
+ overlap?: ActionOverlap;
133
+ /**
134
+ * Keep the last successful `data` readable while the next run is in flight
135
+ * — AND after that run fails. `writeFailure()` never clears `data`, so with
136
+ * this on (the default), a failed run leaves the previous success value
137
+ * readable in `data()` alongside the new `error()`/`status() === 'error'`.
138
+ * Only a subsequent success or an explicit `reset()` clears it.
139
+ *
140
+ * Defaults to `true` — the inverse of {@link ResourceOptions.keepPreviousData} —
141
+ * because an action's result is usually a receipt the UI keeps showing.
142
+ *
143
+ * @default true
144
+ */
145
+ keepPreviousData?: boolean;
146
+ }
147
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ResourceHandle","stability":"stable","signature":"interface ResourceHandle<T, E = unknown>"} */
148
+ /**
149
+ * Handle returned by {@link createResource}.
150
+ *
151
+ * `data`, `error` and `status` are exposed as {@link ReadableSignal} — read and
152
+ * subscribe, but no `.set()` — rather than `Signal`. `readonly` on the property alone
153
+ * would only stop the field being reassigned; the `Signal` behind it still
154
+ * carries `.set()`, so `resource.status.set('success')` would type-check and
155
+ * desync `status` from the engine's untracked bookkeeping, after which
156
+ * `destroy()` cannot clear a stuck spinner and `loading()` reports a state the
157
+ * engine never produced. The accessor type makes the intent enforceable
158
+ * instead of conventional.
159
+ *
160
+ * @typeParam T - Type of the resolved data.
161
+ * @typeParam E - Type of the carried error.
162
+ */
163
+ export interface ResourceHandle<T, E = unknown> {
164
+ /** Latest successful value, or `undefined` before the first success. */
165
+ readonly data: ReadableSignal<T | undefined>;
166
+ /**
167
+ * Latest error, carried by reference and never wrapped.
168
+ *
169
+ * `status() === 'error'` is the authoritative failure check, NOT
170
+ * `error() !== undefined`. A rejection can legitimately carry `undefined`
171
+ * (e.g. `Promise.reject()` / `throw undefined`), in which case `status()`
172
+ * is `'error'` while `error()` reads `undefined` — a consumer checking only
173
+ * `error()` would silently miss that failure.
174
+ */
175
+ readonly error: ReadableSignal<E | undefined>;
176
+ /** Current lifecycle status. */
177
+ readonly status: ReadableSignal<ResourceStatus>;
178
+ /**
179
+ * `true` while a fetch is in flight.
180
+ *
181
+ * A plain accessor rather than `computed()` — it still tracks reactively
182
+ * because it reads `status()` inside the caller's effect, and it avoids
183
+ * `computed()`'s leaked internal subscription.
184
+ */
185
+ readonly loading: () => boolean;
186
+ /**
187
+ * Re-run the fetcher. The newest call always wins; superseded calls resolve
188
+ * `{ ok: false, dropped: true }`. Inert under any server render.
189
+ */
190
+ refetch: () => Promise<ActionResult<T, E>>;
191
+ /** Return to `'idle'`, clearing data and error, and abandon any in-flight fetch. */
192
+ reset: () => void;
193
+ /**
194
+ * Permanently stop the resource: aborts the in-flight request and guarantees
195
+ * no signal is ever written again.
196
+ *
197
+ * MUST be called from the owning component's cleanup. `onCleanup()` is a
198
+ * silent no-op outside an effect, so this is not optional.
199
+ */
200
+ destroy: () => void;
201
+ }
202
+ /** @codexApi {"parent":"pithy.core.resource.types","name":"ActionHandle","stability":"stable","signature":"interface ActionHandle<T, A extends unknown[], E = unknown>"} */
203
+ /**
204
+ * Handle returned by {@link createAction}.
205
+ *
206
+ * @typeParam T - Type of the resolved data.
207
+ * @typeParam A - Tuple of arguments accepted by `run()`.
208
+ * @typeParam E - Type of the carried error.
209
+ */
210
+ export interface ActionHandle<T, A extends unknown[], E = unknown> {
211
+ /** Result of the latest successful run. */
212
+ readonly data: ReadableSignal<T | undefined>;
213
+ /**
214
+ * Error of the latest failed run, carried by reference and never wrapped.
215
+ *
216
+ * `status() === 'error'` is the authoritative failure check, NOT
217
+ * `error() !== undefined`. A rejection can legitimately carry `undefined`
218
+ * (e.g. `Promise.reject()` / `throw undefined`), in which case `status()`
219
+ * is `'error'` while `error()` reads `undefined` — a consumer checking only
220
+ * `error()` would silently miss that failure.
221
+ */
222
+ readonly error: ReadableSignal<E | undefined>;
223
+ /** Current lifecycle status. */
224
+ readonly status: ReadableSignal<ResourceStatus>;
225
+ /** `true` while a run is in flight (plain accessor, see `ResourceHandle.loading`). */
226
+ readonly pending: () => boolean;
227
+ /**
228
+ * Perform the action. Always resolves — never rejects — with an
229
+ * {@link ActionResult}.
230
+ */
231
+ run: (...args: A) => Promise<ActionResult<T, E>>;
232
+ /** Return to `'idle'`, clearing data and error, and abandon any in-flight run. */
233
+ reset: () => void;
234
+ /**
235
+ * Permanently stop the action: aborts the in-flight run and guarantees no
236
+ * signal is ever written again. See {@link ResourceHandle.destroy}.
237
+ */
238
+ destroy: () => void;
239
+ }
240
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/resource/types.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,9 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.core.resource.types",
4
+ "title": "Async State Primitive Types",
5
+ "category": "types"
6
+ }
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/runtime/resource/types.ts"],"names":[],"mappings":"AAAA;;;;;;EAME","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.core.resource.types\",\n \"title\": \"Async State Primitive Types\",\n \"category\": \"types\"\n}\n*/\n\n/**\n * Public types for the async-state primitives (`createResource`, `createAction`).\n *\n * @module runtime/resource/types\n */\n\n/**\n * Read access to a signal: call it to read (tracked normally inside an\n * effect), `subscribe` to observe. Deliberately omits `.set()`.\n *\n * `@pithyjs/signals` exports `ReadonlySignal<T> = () => T`, which drops\n * `.subscribe` as well. Observing without an effect is legitimate read access,\n * so the handles use this instead — the write path is what has to be closed\n * off, not the read path. If this proves generally useful it belongs in\n * `@pithyjs/signals` beside `Signal` and `ReadonlySignal`.\n */\nexport type ReadableSignal<T> = (() => T) & {\n subscribe: (fn: (value: T) => void) => () => void;\n};\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ResourceStatus\",\"stability\":\"stable\",\"signature\":\"type ResourceStatus = 'idle' | 'loading' | 'success' | 'error'\"} */\n/**\n * Lifecycle status of a resource or action.\n *\n * NAMING NOTE: this is deliberately NOT called `ResourceState`. `@pithyjs/router`\n * already exports an interface named `ResourceState` (route loader state), and\n * `@pithyjs/core` re-exports its whole runtime barrel — an app importing both\n * packages would otherwise face an ambiguous name.\n */\nexport type ResourceStatus = 'idle' | 'loading' | 'success' | 'error';\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ResourceFetcher\",\"stability\":\"stable\",\"signature\":\"type ResourceFetcher<T> = (signal: AbortSignal) => T | Promise<T>\"} */\n/**\n * The function a resource calls to produce its data.\n *\n * Receives an `AbortSignal` that is aborted when the resource is refetched,\n * reset or destroyed. Forwarding it to `fetch()` is a courtesy optimisation\n * only — correctness never depends on the fetcher honouring it (see\n * `engine.ts` for the generation counter that guarantees it).\n *\n * @typeParam T - Type of the resolved data.\n */\nexport type ResourceFetcher<T> = (signal: AbortSignal) => T | Promise<T>;\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ActionPerformer\",\"stability\":\"stable\",\"signature\":\"type ActionPerformer<T, A extends unknown[]> = (...args: A) => T | Promise<T>\"} */\n/**\n * The function an action calls to perform its side effect.\n *\n * @typeParam T - Type of the resolved data.\n * @typeParam A - Tuple of arguments forwarded from `run()`.\n */\nexport type ActionPerformer<T, A extends unknown[]> = (\n ...args: A\n) => T | Promise<T>;\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ActionResult\",\"stability\":\"stable\",\"signature\":\"type ActionResult<T, E = unknown> = { ok: true; data: T } | { ok: false; dropped: false; error: E } | { ok: false; dropped: true }\"} */\n/**\n * Discriminated union resolved by `run()` and `refetch()`.\n *\n * These methods RESOLVE this union — they never reject. This deliberately\n * diverges from the router's `executeLoader`, which rejects on failure; see the\n * comment above `run()` in `createAction.ts` for the rationale.\n *\n * Narrowing:\n * ```ts\n * if (result.ok) result.data; // success\n * else if (result.dropped) { } // superseded / destroyed / SSR — no run happened\n * else result.error; // failure, error carried by reference\n * ```\n *\n * @typeParam T - Type of the resolved data.\n * @typeParam E - Type of the carried error (defaults to `unknown` — thrown values\n * are carried by reference and never wrapped in an `Error`).\n */\nexport type ActionResult<T, E = unknown> =\n | { readonly ok: true; readonly data: T }\n | { readonly ok: false; readonly dropped: false; readonly error: E }\n | { readonly ok: false; readonly dropped: true };\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ResourceOptions\",\"stability\":\"stable\",\"signature\":\"interface ResourceOptions\"} */\n/** Options for {@link createResource}. */\nexport interface ResourceOptions {\n /**\n * Fetch as soon as the resource is created.\n *\n * Ignored under server rendering (SSG *and* dynamic SSR), where the\n * resource always stays `'idle'`.\n *\n * @default true\n */\n immediate?: boolean;\n\n /**\n * Keep the last successful `data` readable while a refetch is in flight,\n * **and after that refetch fails**. When `false`, `data` is cleared the\n * moment a refetch starts.\n *\n * The post-failure half matters: on failure `status` becomes `'error'` and\n * `error` is populated, but `data` still holds the last success. A view that\n * renders `data` whenever it is defined will therefore show stale content\n * beside a fresh error unless it checks `status` too. That is the intended\n * behaviour — it is what makes a transient refetch failure non-destructive —\n * but it has to be handled deliberately.\n *\n * @default false\n */\n keepPreviousData?: boolean;\n}\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ActionOverlap\",\"stability\":\"stable\",\"signature\":\"type ActionOverlap = 'drop' | 'restart'\"} */\n/**\n * What happens when `run()` is called while a previous run is still in flight.\n *\n * - `'drop'` — the new call is ignored and resolves `{ ok: false, dropped: true }`.\n * The default for actions: double-submitting a form should not fire twice.\n * - `'restart'` — the new call supersedes the old one, which resolves\n * `{ ok: false, dropped: true }` and can never write state again.\n */\nexport type ActionOverlap = 'drop' | 'restart';\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ActionOptions\",\"stability\":\"stable\",\"signature\":\"interface ActionOptions\"} */\n/** Options for {@link createAction}. */\nexport interface ActionOptions {\n /**\n * Overlap policy for concurrent `run()` calls.\n *\n * @default 'drop'\n */\n overlap?: ActionOverlap;\n\n /**\n * Keep the last successful `data` readable while the next run is in flight\n * — AND after that run fails. `writeFailure()` never clears `data`, so with\n * this on (the default), a failed run leaves the previous success value\n * readable in `data()` alongside the new `error()`/`status() === 'error'`.\n * Only a subsequent success or an explicit `reset()` clears it.\n *\n * Defaults to `true` — the inverse of {@link ResourceOptions.keepPreviousData} —\n * because an action's result is usually a receipt the UI keeps showing.\n *\n * @default true\n */\n keepPreviousData?: boolean;\n}\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ResourceHandle\",\"stability\":\"stable\",\"signature\":\"interface ResourceHandle<T, E = unknown>\"} */\n/**\n * Handle returned by {@link createResource}.\n *\n * `data`, `error` and `status` are exposed as {@link ReadableSignal} — read and\n * subscribe, but no `.set()` — rather than `Signal`. `readonly` on the property alone\n * would only stop the field being reassigned; the `Signal` behind it still\n * carries `.set()`, so `resource.status.set('success')` would type-check and\n * desync `status` from the engine's untracked bookkeeping, after which\n * `destroy()` cannot clear a stuck spinner and `loading()` reports a state the\n * engine never produced. The accessor type makes the intent enforceable\n * instead of conventional.\n *\n * @typeParam T - Type of the resolved data.\n * @typeParam E - Type of the carried error.\n */\nexport interface ResourceHandle<T, E = unknown> {\n /** Latest successful value, or `undefined` before the first success. */\n readonly data: ReadableSignal<T | undefined>;\n\n /**\n * Latest error, carried by reference and never wrapped.\n *\n * `status() === 'error'` is the authoritative failure check, NOT\n * `error() !== undefined`. A rejection can legitimately carry `undefined`\n * (e.g. `Promise.reject()` / `throw undefined`), in which case `status()`\n * is `'error'` while `error()` reads `undefined` — a consumer checking only\n * `error()` would silently miss that failure.\n */\n readonly error: ReadableSignal<E | undefined>;\n\n /** Current lifecycle status. */\n readonly status: ReadableSignal<ResourceStatus>;\n\n /**\n * `true` while a fetch is in flight.\n *\n * A plain accessor rather than `computed()` — it still tracks reactively\n * because it reads `status()` inside the caller's effect, and it avoids\n * `computed()`'s leaked internal subscription.\n */\n readonly loading: () => boolean;\n\n /**\n * Re-run the fetcher. The newest call always wins; superseded calls resolve\n * `{ ok: false, dropped: true }`. Inert under any server render.\n */\n refetch: () => Promise<ActionResult<T, E>>;\n\n /** Return to `'idle'`, clearing data and error, and abandon any in-flight fetch. */\n reset: () => void;\n\n /**\n * Permanently stop the resource: aborts the in-flight request and guarantees\n * no signal is ever written again.\n *\n * MUST be called from the owning component's cleanup. `onCleanup()` is a\n * silent no-op outside an effect, so this is not optional.\n */\n destroy: () => void;\n}\n\n/** @codexApi {\"parent\":\"pithy.core.resource.types\",\"name\":\"ActionHandle\",\"stability\":\"stable\",\"signature\":\"interface ActionHandle<T, A extends unknown[], E = unknown>\"} */\n/**\n * Handle returned by {@link createAction}.\n *\n * @typeParam T - Type of the resolved data.\n * @typeParam A - Tuple of arguments accepted by `run()`.\n * @typeParam E - Type of the carried error.\n */\nexport interface ActionHandle<T, A extends unknown[], E = unknown> {\n /** Result of the latest successful run. */\n readonly data: ReadableSignal<T | undefined>;\n\n /**\n * Error of the latest failed run, carried by reference and never wrapped.\n *\n * `status() === 'error'` is the authoritative failure check, NOT\n * `error() !== undefined`. A rejection can legitimately carry `undefined`\n * (e.g. `Promise.reject()` / `throw undefined`), in which case `status()`\n * is `'error'` while `error()` reads `undefined` — a consumer checking only\n * `error()` would silently miss that failure.\n */\n readonly error: ReadableSignal<E | undefined>;\n\n /** Current lifecycle status. */\n readonly status: ReadableSignal<ResourceStatus>;\n\n /** `true` while a run is in flight (plain accessor, see `ResourceHandle.loading`). */\n readonly pending: () => boolean;\n\n /**\n * Perform the action. Always resolves — never rejects — with an\n * {@link ActionResult}.\n */\n run: (...args: A) => Promise<ActionResult<T, E>>;\n\n /** Return to `'idle'`, clearing data and error, and abandon any in-flight run. */\n reset: () => void;\n\n /**\n * Permanently stop the action: aborts the in-flight run and guarantees no\n * signal is ever written again. See {@link ResourceHandle.destroy}.\n */\n destroy: () => void;\n}\n"]}
@@ -1,15 +1,24 @@
1
- import type { SlotMap } from '../compile/contentProjection';
1
+ import type { SlotMap } from '../compile/contentProjection.js';
2
2
  import type { PithyNode } from '@pithyjs/compiler';
3
+ import type { ChildFactory } from '../runtime/bindings/types.js';
3
4
  export interface PithyComponentContext extends Record<string, unknown> {
4
5
  __parentComponentContext?: PithyComponentContext;
5
6
  __slotMap?: SlotMap;
6
7
  __childAstNodes?: PithyNode[];
8
+ __childFactory?: ChildFactory;
7
9
  }
8
10
  export interface PithyGlobals {
11
+ /**
12
+ * SSR component-crash registry. Lives on `globalThis` rather than in a module
13
+ * so that an app and `@pithyjs/ssr` resolving two physical copies of
14
+ * `@pithyjs/core` still share one — see `compile/ssrCrashes.ts`.
15
+ */
16
+ __pithySSRCrashes?: Map<Element, unknown>;
9
17
  PITHY_DEBUG_PROJECTION?: boolean;
10
18
  __PITHY_SSR__?: boolean;
11
19
  __getComponentContext?: () => Record<string, unknown> | undefined;
12
20
  __pithyComponentContext?: PithyComponentContext;
21
+ __pithyProjectedChildren?: DocumentFragment;
13
22
  __pithyRenderingComponent?: boolean;
14
23
  __pithyGetDestroyCallbacks?: () => (() => void)[] | undefined;
15
24
  __pithySetDestroyCallbacks?: (cbs: (() => void)[]) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../src/types/globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,qBAAsB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE,wBAAwB,CAAC,EAAE,qBAAqB,CAAC;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAClE,uBAAuB,CAAC,EAAE,qBAAqB,CAAC;IAChD,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,0BAA0B,CAAC,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;IAC9D,0BAA0B,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC;CAC5D;AAED,wBAAgB,YAAY,IAAI,OAAO,UAAU,GAAG,YAAY,CAE/D"}
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../src/types/globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,WAAW,qBAAsB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE,wBAAwB,CAAC,EAAE,qBAAqB,CAAC;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;IAC9B,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1C,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAClE,uBAAuB,CAAC,EAAE,qBAAqB,CAAC;IAChD,wBAAwB,CAAC,EAAE,gBAAgB,CAAC;IAC5C,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,0BAA0B,CAAC,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;IAC9D,0BAA0B,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC;CAC5D;AAED,wBAAgB,YAAY,IAAI,OAAO,UAAU,GAAG,YAAY,CAE/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/types/globals.ts"],"names":[],"mappings":"AAmBA,MAAM,UAAU,YAAY;IAC1B,OAAO,UAA8C,CAAC;AACxD,CAAC"}
1
+ {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/types/globals.ts"],"names":[],"mappings":"AA4BA,MAAM,UAAU,YAAY;IAC1B,OAAO,UAA8C,CAAC;AACxD,CAAC","sourcesContent":["import type { SlotMap } from '../compile/contentProjection';\nimport type { PithyNode } from '@pithyjs/compiler';\nimport type { ChildFactory } from '../runtime/bindings/types';\n\nexport interface PithyComponentContext extends Record<string, unknown> {\n __parentComponentContext?: PithyComponentContext;\n __slotMap?: SlotMap;\n __childAstNodes?: PithyNode[];\n __childFactory?: ChildFactory;\n}\n\nexport interface PithyGlobals {\n /**\n * SSR component-crash registry. Lives on `globalThis` rather than in a module\n * so that an app and `@pithyjs/ssr` resolving two physical copies of\n * `@pithyjs/core` still share one — see `compile/ssrCrashes.ts`.\n */\n __pithySSRCrashes?: Map<Element, unknown>;\n PITHY_DEBUG_PROJECTION?: boolean;\n __PITHY_SSR__?: boolean;\n __getComponentContext?: () => Record<string, unknown> | undefined;\n __pithyComponentContext?: PithyComponentContext;\n __pithyProjectedChildren?: DocumentFragment;\n __pithyRenderingComponent?: boolean;\n __pithyGetDestroyCallbacks?: () => (() => void)[] | undefined;\n __pithySetDestroyCallbacks?: (cbs: (() => void)[]) => void;\n}\n\nexport function pithyGlobals(): typeof globalThis & PithyGlobals {\n return globalThis as typeof globalThis & PithyGlobals;\n}\n"]}
@@ -1,5 +1,19 @@
1
+ /**
2
+ * What a component returns.
3
+ *
4
+ * `el` is any DOM `Node`, not only an element or fragment. It was declared as
5
+ * `HTMLElement | DocumentFragment` while the runtime happily inserted anything
6
+ * `replaceWith` accepts — a component returning `document.createTextNode('hi')`
7
+ * rendered correctly and always had. Narrowing the runtime to match the old
8
+ * declaration would have silently dropped those subtrees, so the declaration is
9
+ * widened to match the behaviour instead.
10
+ *
11
+ * Anything that is a real node but cannot be inserted at a given position — a
12
+ * `Document`, say — still fails at insertion and is reported, rather than being
13
+ * excluded by type.
14
+ */
1
15
  export type Component = () => {
2
- el: HTMLElement | DocumentFragment;
16
+ el: Node;
3
17
  destroy?: () => void;
4
18
  };
5
19
  declare global {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM;IAC5B,EAAE,EAAE,WAAW,GAAG,gBAAgB,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC1C;CACF;AAED,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM;IAC5B,EAAE,EAAE,IAAI,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC1C;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * What a component returns.\n *\n * `el` is any DOM `Node`, not only an element or fragment. It was declared as\n * `HTMLElement | DocumentFragment` while the runtime happily inserted anything\n * `replaceWith` accepts — a component returning `document.createTextNode('hi')`\n * rendered correctly and always had. Narrowing the runtime to match the old\n * declaration would have silently dropped those subtrees, so the declaration is\n * widened to match the behaviour instead.\n *\n * Anything that is a real node but cannot be inserted at a given position — a\n * `Document`, say — still fails at insertion and is reported, rather than being\n * excluded by type.\n */\nexport type Component = () => {\n el: Node;\n destroy?: () => void;\n};\n\ndeclare global {\n interface Window {\n __pithyCapture?: Record<string, unknown>;\n }\n}\n\nexport {};\n"]}
@@ -1,3 +1,3 @@
1
- export * from './ref.untility';
2
- export * from './ref-signal.utility';
1
+ export * from './ref.untility.js';
2
+ export * from './ref-signal.utility.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- export * from './ref.untility';
2
- export * from './ref-signal.utility';
1
+ export * from './ref.untility.js';
2
+ export * from './ref-signal.utility.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC","sourcesContent":["export * from './ref.untility';\nexport * from './ref-signal.utility';\n"]}
@@ -1,4 +1,4 @@
1
- import type { RefSignal } from '../interfaces/ref-signal.interface';
1
+ import type { RefSignal } from '../interfaces/ref-signal.interface.js';
2
2
  /**
3
3
  * Creates a reactive reference signal for HTML elements.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ref-signal.utility.js","sourceRoot":"","sources":["../../src/utilities/ref-signal.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,kBAAkB,CAAC;AAGlD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,8JAA8J;AAC9J,MAAM,UAAU,SAAS;IACvB,MAAM,CAAC,GAAqB,MAAM,CAAW,IAAI,CAAC,CAAC;IAEnD,MAAM,GAAG,GAAG;QACV,OAAO,CAAC,EAAE,CAAC;IACb,CAAiB,CAAC;IAElB,GAAG,CAAC,GAAG,GAAG,CAAC,EAAY,EAAQ,EAAE;QAC/B,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC,CAAC;IAEF,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE;QACpC,GAAG;YACD,OAAO,CAAC,EAAE,CAAC;QACb,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
1
+ {"version":3,"file":"ref-signal.utility.js","sourceRoot":"","sources":["../../src/utilities/ref-signal.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,kBAAkB,CAAC;AAGlD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,8JAA8J;AAC9J,MAAM,UAAU,SAAS;IACvB,MAAM,CAAC,GAAqB,MAAM,CAAW,IAAI,CAAC,CAAC;IAEnD,MAAM,GAAG,GAAG;QACV,OAAO,CAAC,EAAE,CAAC;IACb,CAAiB,CAAC;IAElB,GAAG,CAAC,GAAG,GAAG,CAAC,EAAY,EAAQ,EAAE;QAC/B,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC,CAAC;IAEF,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE;QACpC,GAAG;YACD,OAAO,CAAC,EAAE,CAAC;QACb,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { signal, Signal } from '@pithyjs/signals';\nimport type { RefSignal } from '../interfaces/ref-signal.interface';\n\n/**\n * Creates a reactive reference signal for HTML elements.\n *\n * This function returns a RefSignal object that can be used to hold and manage\n * references to DOM elements. It provides both function-style and object-style\n * access to the referenced element.\n *\n * @template T - The type of HTML element being referenced, defaults to HTMLElement\n *\n * @returns {RefSignal<T>} A RefSignal object with the following capabilities:\n * - Can be called as a function to get the current element\n * - Has a `set` method to update the referenced element\n * - Has a `current` property to access the referenced element (React-style)\n *\n * @example\n * ```typescript\n * const divRef = refSignal<HTMLDivElement>();\n *\n * // Function-style usage\n * const element = divRef();\n *\n * // Setter usage\n * divRef.set(someElement);\n *\n * // Property-style usage (React-like)\n * const currentElement = divRef.current;\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.feature.refs\",\"name\":\"refSignal\",\"stability\":\"stable\",\"signature\":\"<T extends HTMLElement = HTMLElement>() => RefSignal<T>\"} */\nexport function refSignal<T extends HTMLElement = HTMLElement>(): RefSignal<T> {\n const r: Signal<T | null> = signal<T | null>(null);\n\n const ref = function (): T | null {\n return r();\n } as RefSignal<T>;\n\n ref.set = (el: T | null): void => {\n r.set(el);\n };\n\n Object.defineProperty(ref, 'current', {\n get(): T | null {\n return r();\n },\n });\n\n return ref;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "category": "feature"
6
6
  }
7
7
  */
8
- import type { Ref } from '../interfaces/ref.interface';
8
+ import type { Ref } from '../interfaces/ref.interface.js';
9
9
  /**
10
10
  * Creates a non-reactive reference object for HTML elements.
11
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ref.untility.js","sourceRoot":"","sources":["../../src/utilities/ref.untility.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,kJAAkJ;AAClJ,MAAM,UAAU,GAAG;IACjB,IAAI,KAAK,GAAa,IAAI,CAAC;IAC3B,MAAM,GAAG,GAAG,CAAC,EAAY,EAAE,EAAE;QAC3B,KAAK,GAAG,EAAE,CAAC;IACb,CAAC,CAAC;IACF,OAAO;QACL,IAAI,OAAO;YACT,OAAO,KAAK,CAAC;QACf,CAAC;QACD,GAAG;KACa,CAAC;AACrB,CAAC"}
1
+ {"version":3,"file":"ref.untility.js","sourceRoot":"","sources":["../../src/utilities/ref.untility.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,kJAAkJ;AAClJ,MAAM,UAAU,GAAG;IACjB,IAAI,KAAK,GAAa,IAAI,CAAC;IAC3B,MAAM,GAAG,GAAG,CAAC,EAAY,EAAE,EAAE;QAC3B,KAAK,GAAG,EAAE,CAAC;IACb,CAAC,CAAC;IACF,OAAO;QACL,IAAI,OAAO;YACT,OAAO,KAAK,CAAC;QACf,CAAC;QACD,GAAG;KACa,CAAC;AACrB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.feature.refs\",\n \"title\": \"Element Reference System\",\n \"category\": \"feature\"\n}\n*/\n\nimport type { Ref } from '../interfaces/ref.interface';\n\n/**\n * Creates a non-reactive reference object for HTML elements.\n *\n * This function returns a Ref object that can be used to hold and manage\n * references to DOM elements. It provides a React-like interface with\n * a `current` property and a `set` method.\n *\n * @template T - The type of HTML element being referenced, defaults to HTMLElement\n *\n * @returns {Ref<T>} A Ref object with the following:\n * - `current` - A getter property that returns the current element reference\n * - `set` - A method to update the referenced element\n *\n * @example\n * ```typescript\n * const divRef = ref<HTMLDivElement>();\n *\n * // Update the reference\n * divRef.set(someElement);\n *\n * // Access the current element\n * const element = divRef.current;\n * ```\n *\n * @see {@link RefSignal} for a reactive version of this reference\n */\n/** @codexApi {\"parent\":\"pithy.feature.refs\",\"name\":\"ref\",\"stability\":\"stable\",\"signature\":\"<T extends HTMLElement = HTMLElement>() => Ref<T>\"} */\nexport function ref<T extends HTMLElement = HTMLElement>(): Ref<T> {\n let value: T | null = null;\n const set = (el: T | null) => {\n value = el;\n };\n return {\n get current() {\n return value;\n },\n set,\n } satisfies Ref<T>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@pithyjs/core",
3
- "version": "0.1.0-beta.0",
3
+ "version": "0.1.0-beta.10",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/PithyJS/pithyjs.git",
7
+ "directory": "packages/core"
8
+ },
4
9
  "main": "dist/index.js",
5
10
  "types": "dist/index.d.ts",
6
11
  "type": "module",
@@ -19,10 +24,10 @@
19
24
  }
20
25
  },
21
26
  "dependencies": {
22
- "@pithyjs/shared": "0.1.0-beta.0",
23
- "@pithyjs/signals": "0.1.0-beta.0",
24
- "@pithyjs/compiler": "0.1.0-beta.0",
25
- "@pithyjs/design-system": "0.1.0-beta.0"
27
+ "@pithyjs/shared": "0.1.0-beta.3",
28
+ "@pithyjs/signals": "0.1.0-beta.2",
29
+ "@pithyjs/compiler": "0.1.0-beta.4",
30
+ "@pithyjs/design-system": "0.1.0-beta.6"
26
31
  },
27
32
  "peerDependencies": {
28
33
  "parse5": ">=7.0.0"
@@ -33,12 +38,12 @@
33
38
  }
34
39
  },
35
40
  "devDependencies": {
36
- "@vitest/ui": "^3.2.4",
41
+ "@vitest/ui": "3.2.4",
37
42
  "happy-dom": "^20.0.3",
38
43
  "parse5": "^7.3.0",
39
44
  "typescript": "^5.0.0",
40
- "@vitest/coverage-v8": "^3.2.4",
41
- "vitest": "^3.2.4"
45
+ "@vitest/coverage-v8": "3.2.4",
46
+ "vitest": "3.2.4"
42
47
  },
43
48
  "license": "MIT",
44
49
  "publishConfig": {
@@ -49,7 +54,7 @@
49
54
  "dist"
50
55
  ],
51
56
  "scripts": {
52
- "build": "tsc -p tsconfig.json",
57
+ "build": "tsc -p tsconfig.json && node ../../scripts/add-js-extensions.mjs dist",
53
58
  "test": "vitest"
54
59
  }
55
60
  }