@stacksjs/stx 0.2.176 → 0.2.177

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 (44) hide show
  1. package/dist/builtins/attrs.d.ts +19 -0
  2. package/dist/builtins/attrs.js +18 -0
  3. package/dist/builtins/safe-image.js +2 -1
  4. package/dist/builtins/stx-image.js +2 -1
  5. package/dist/builtins/stx-link.js +2 -1
  6. package/dist/cli-flags.d.ts +34 -0
  7. package/dist/cli-flags.js +20 -0
  8. package/dist/cli.js +899 -778
  9. package/dist/client-script.js +2 -1
  10. package/dist/component-registry.d.ts +9 -0
  11. package/dist/component-renderer.js +20 -1
  12. package/dist/composables/use-fetch.d.ts +6 -1
  13. package/dist/composables/use-fetch.js +40 -18
  14. package/dist/composables/use-query.d.ts +7 -2
  15. package/dist/cookie-serialize.d.ts +40 -0
  16. package/dist/cookie-serialize.js +18 -0
  17. package/dist/craft.js +500 -381
  18. package/dist/crosswind-config.d.ts +13 -0
  19. package/dist/crosswind-config.js +6 -2
  20. package/dist/dev-server/crosswind.js +2 -1
  21. package/dist/edge-runtime.d.ts +2 -9
  22. package/dist/edge-runtime.js +2 -16
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +2 -0
  25. package/dist/page-action.d.ts +10 -20
  26. package/dist/page-action.js +33 -9
  27. package/dist/production-server.js +8 -7
  28. package/dist/pwa.js +452 -333
  29. package/dist/reactive.js +2 -2
  30. package/dist/signal-processing.js +37 -6
  31. package/dist/signals.js +150 -32
  32. package/dist/ssg.js +465 -346
  33. package/dist/ssr.js +2 -16
  34. package/dist/stx-virtual-ts.d.ts +45 -1
  35. package/dist/stx-virtual-ts.js +75 -5
  36. package/dist/stx.d.ts +66 -7
  37. package/dist/template-hydrator.d.ts +1 -1
  38. package/dist/template-hydrator.js +6 -6
  39. package/dist/theme-tokens.d.ts +88 -0
  40. package/dist/theme-tokens.js +71 -0
  41. package/dist/typecheck.d.ts +6 -1
  42. package/dist/typecheck.js +7 -6
  43. package/package.json +5 -5
  44. package/stx.d.ts +66 -7
package/stx.d.ts CHANGED
@@ -199,11 +199,42 @@ declare function useSearchParams(): {
199
199
  // Data fetching
200
200
  // ============================================================================
201
201
 
202
- interface StxQueryResult<T> {
202
+ /** How one run of a request should behave. */
203
+ interface StxRefetchOptions {
204
+ /**
205
+ * Refresh without touching `loading` or clearing the current error.
206
+ *
207
+ * A poll refreshes data that is already on screen, so driving the first-load
208
+ * state from it puts a spinner over a populated view on every tick — the
209
+ * reason a polling view could not use these primitives at all (#1929). Bind
210
+ * `isFetching` for a subtle in-flight indicator instead.
211
+ */
212
+ background?: boolean
213
+ }
214
+
215
+ interface StxFetchResult<T> {
203
216
  data: StxSignal<T | null>
217
+ /** True while a first-load request is in flight. A background one leaves it alone. */
204
218
  loading: StxSignal<boolean>
219
+ /** True while ANY request is in flight, background ones included. */
220
+ isFetching: StxSignal<boolean>
205
221
  error: StxSignal<Error | null>
206
- refetch: () => Promise<void>
222
+ refetch: (_options?: StxRefetchOptions) => Promise<void>
223
+ }
224
+
225
+ /*
226
+ * `useQuery` returns more than `useFetch` does, and declaring one shape for
227
+ * both hid it: `isStale` and `invalidate` existed at runtime and were invisible
228
+ * to the type, so reading either was an error on a value that was really there
229
+ * (#1929). Extending rather than widening the shared interface, because the
230
+ * inverse mistake is worse — declaring `invalidate` on `useFetch` would
231
+ * type-check a call to something that is undefined at runtime.
232
+ */
233
+ interface StxQueryResult<T> extends StxFetchResult<T> {
234
+ /** True when cached data is on screen while a revalidation runs. */
235
+ isStale: StxSignal<boolean>
236
+ /** Drop this key from the cache and refetch. */
237
+ invalidate: (_options?: StxRefetchOptions) => Promise<void>
207
238
  }
208
239
 
209
240
  interface StxMutationResult<T> {
@@ -213,7 +244,7 @@ interface StxMutationResult<T> {
213
244
  mutate: (body?: unknown) => Promise<T>
214
245
  }
215
246
 
216
- declare function useFetch<T = any>(_url: string, _options?: any): StxQueryResult<T>
247
+ declare function useFetch<T = any>(_url: string, _options?: any): StxFetchResult<T>
217
248
  declare function useQuery<T = any>(_url: string, _options?: any): StxQueryResult<T>
218
249
  declare function useMutation<T = any>(_url: string, _options?: any): StxMutationResult<T>
219
250
 
@@ -271,17 +302,45 @@ declare function useOptimistic<T = any, A = any>(
271
302
  // DOM utilities
272
303
  // ============================================================================
273
304
 
305
+ /**
306
+ * Options the runtime reads, including the target it binds to.
307
+ *
308
+ * The target travels HERE rather than in a leading parameter, because that is
309
+ * what the implementation does: `var target = (options && options.target) || window`.
310
+ */
311
+ interface StxEventListenerOptions {
312
+ /** Element, selector, or document/window. Defaults to `window`. */
313
+ target?: Window | Document | HTMLElement | string | null
314
+ capture?: boolean
315
+ passive?: boolean
316
+ once?: boolean
317
+ }
318
+
319
+ /*
320
+ * Event first, then handler, then options (stacksjs/stx#1923).
321
+ *
322
+ * This was declared target-first while the runtime has always been
323
+ * event-first, so the two disagreed in the worst possible direction: `_target`
324
+ * accepted `string`, so the CORRECT call got as far as reading 'keydown' as a
325
+ * selector before failing on the handler, and an author who trusted the type
326
+ * and added a target wrote `useEventListener(window, 'keydown', fn)` — which
327
+ * binds an event named "window" with the string 'keydown' as its handler, and
328
+ * silently attaches nothing.
329
+ *
330
+ * `browser-composables.ts` had it right all along; the package shipped two
331
+ * declarations of one name with different arities and the registry got the
332
+ * wrong one. Same shape as the `reactive` split: one name, two conventions, and
333
+ * no way for the call site to tell which it has.
334
+ */
274
335
  declare function useEventListener<K extends keyof WindowEventMap>(
275
- _target: Window | Document | HTMLElement | string | null,
276
336
  _event: K,
277
337
  _handler: (event: WindowEventMap[K]) => void,
278
- _options?: boolean | AddEventListenerOptions,
338
+ _options?: StxEventListenerOptions,
279
339
  ): StxCleanup
280
340
  declare function useEventListener(
281
- _target: Window | Document | HTMLElement | string | null,
282
341
  _event: string,
283
342
  _handler: (event: Event) => void,
284
- _options?: boolean | AddEventListenerOptions,
343
+ _options?: StxEventListenerOptions,
285
344
  ): StxCleanup
286
345
  declare function useScrollLock(
287
346
  _target?: HTMLElement | null | { current?: HTMLElement | null, value?: HTMLElement | null } | (() => HTMLElement | null | undefined),