@stacksjs/stx 0.2.155 → 0.2.156
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.
- package/dist/a11y.d.ts +87 -46
- package/dist/animation.d.ts +96 -42
- package/dist/appearance-bootstrap.d.ts +49 -15
- package/dist/asset-roots.d.ts +32 -0
- package/dist/asset-roots.js +7 -0
- package/dist/assets.d.ts +9 -7
- package/dist/async-components.d.ts +78 -56
- package/dist/auth.d.ts +3 -0
- package/dist/build-externalize.d.ts +40 -0
- package/dist/build-externalize.js +63 -0
- package/dist/build-id.d.ts +22 -22
- package/dist/build-message.d.ts +73 -2
- package/dist/build-message.js +47 -8
- package/dist/builtins/attrs.d.ts +14 -0
- package/dist/builtins/drawer.d.ts +22 -0
- package/dist/builtins/icon.d.ts +16 -2
- package/dist/builtins/index.d.ts +5 -15
- package/dist/builtins/modal.d.ts +24 -0
- package/dist/builtins/safe-image.d.ts +42 -0
- package/dist/builtins/stx-image.d.ts +27 -0
- package/dist/builtins/stx-link.d.ts +9 -0
- package/dist/builtins/stx-loading-indicator.d.ts +11 -0
- package/dist/builtins/suspense.d.ts +28 -0
- package/dist/builtins/toast.d.ts +17 -0
- package/dist/builtins/transition-group.d.ts +25 -0
- package/dist/caching.d.ts +12 -15
- package/dist/cli.js +1798 -908
- package/dist/client/directive.d.ts +7 -0
- package/dist/client/index.d.ts +0 -1
- package/dist/client-script-bundler.d.ts +63 -5
- package/dist/client-script-bundler.js +30 -2
- package/dist/client-script.d.ts +102 -47
- package/dist/client-script.js +15 -3
- package/dist/codemod.d.ts +56 -0
- package/dist/codemod.js +192 -0
- package/dist/color-mode-boot.d.ts +83 -65
- package/dist/component-client-factories.d.ts +1 -6
- package/dist/component-processing.d.ts +58 -49
- package/dist/component-processing.js +1 -1
- package/dist/component-registry.d.ts +94 -31
- package/dist/component-renderer.d.ts +18 -0
- package/dist/composable-loader.d.ts +24 -0
- package/dist/composable-loader.js +12 -9
- package/dist/composables/index.d.ts +7 -0
- package/dist/composables/index.js +1 -0
- package/dist/composables/use-fetch.js +30 -2
- package/dist/composables/use-form.d.ts +91 -0
- package/dist/composables/use-form.js +112 -0
- package/dist/composables.d.ts +64 -60
- package/dist/computed.d.ts +86 -92
- package/dist/conditionals.d.ts +24 -8
- package/dist/conditionals.js +16 -0
- package/dist/config.d.ts +34 -21
- package/dist/config.js +35 -14
- package/dist/craft.js +1476 -768
- package/dist/crosswind-config.d.ts +58 -0
- package/dist/crosswind-config.js +40 -0
- package/dist/csp.d.ts +107 -41
- package/dist/defer.d.ts +24 -0
- package/dist/dev-server/crosswind.d.ts +35 -26
- package/dist/dev-server/crosswind.js +2 -18
- package/dist/dev-server/serve-app.js +4 -3
- package/dist/dev-server/terminal-colors.d.ts +32 -32
- package/dist/directive-api.d.ts +86 -43
- package/dist/document-shell.d.ts +54 -41
- package/dist/dynamic-components.d.ts +9 -0
- package/dist/error-boundaries.d.ts +47 -41
- package/dist/error-handling.d.ts +1 -1
- package/dist/errors/codes.d.ts +51 -43
- package/dist/errors/formatter.d.ts +58 -38
- package/dist/errors/index.d.ts +5 -61
- package/dist/errors/logger.d.ts +114 -40
- package/dist/errors/sanitizer.d.ts +53 -23
- package/dist/errors/types.d.ts +44 -31
- package/dist/events.d.ts +86 -25
- package/dist/expressions.d.ts +50 -42
- package/dist/forms-validation.d.ts +138 -123
- package/dist/forms-validation.js +1 -90
- package/dist/forms.d.ts +120 -66
- package/dist/forms.js +31 -11
- package/dist/fragment-container.d.ts +57 -0
- package/dist/fragment-container.js +109 -0
- package/dist/framework-composables.d.ts +32 -0
- package/dist/head.d.ts +156 -114
- package/dist/heatmap.d.ts +152 -72
- package/dist/html-masking.d.ts +40 -34
- package/dist/hydration-runtime.d.ts +20 -24
- package/dist/i18n.d.ts +93 -32
- package/dist/image-optimization/auto-sibling.d.ts +32 -4
- package/dist/includes.d.ts +69 -7
- package/dist/index.d.ts +66 -0
- package/dist/index.js +23 -0
- package/dist/internal-markdown.d.ts +12 -8
- package/dist/island-chunking.d.ts +30 -13
- package/dist/keep-alive.d.ts +72 -52
- package/dist/layout-types.d.ts +45 -0
- package/dist/layout-types.js +56 -0
- package/dist/lazy-module.d.ts +10 -0
- package/dist/loops.d.ts +66 -0
- package/dist/loops.js +47 -6
- package/dist/markdown.d.ts +0 -1
- package/dist/media/image/component.d.ts +25 -9
- package/dist/media/image/directive.d.ts +15 -1
- package/dist/media/image/placeholder.d.ts +20 -9
- package/dist/media/image/processor/cache.d.ts +40 -18
- package/dist/media/image/processor/index.d.ts +1 -10
- package/dist/media/image/processor/optimizer.d.ts +12 -1
- package/dist/media/image/processor/responsive.d.ts +16 -6
- package/dist/media/image/srcset.d.ts +47 -50
- package/dist/media/shared/cache.d.ts +51 -31
- package/dist/media/shared/hash.d.ts +7 -0
- package/dist/media/types.d.ts +1235 -754
- package/dist/media/video/directive.d.ts +15 -1
- package/dist/media/video/index.d.ts +39 -17
- package/dist/media/video/processor/cache.d.ts +42 -19
- package/dist/media/video/processor/index.d.ts +1 -18
- package/dist/media/video/processor/streaming.d.ts +17 -10
- package/dist/media/video/processor/thumbnail.d.ts +21 -15
- package/dist/media/video/processor/transcoder.d.ts +11 -1
- package/dist/method-spoofing.d.ts +7 -0
- package/dist/middleware.d.ts +60 -0
- package/dist/owned-routes.d.ts +42 -0
- package/dist/owned-routes.js +26 -0
- package/dist/page-meta.d.ts +38 -0
- package/dist/page-meta.js +16 -0
- package/dist/parser/directive-parser.d.ts +57 -45
- package/dist/parser/expression-parser.d.ts +33 -35
- package/dist/parser/index.d.ts +4 -39
- package/dist/parser/tokenizer.d.ts +61 -49
- package/dist/partial-hydration.d.ts +82 -50
- package/dist/performance-utils.d.ts +217 -124
- package/dist/placeholder.d.ts +18 -9
- package/dist/plugin-system.d.ts +264 -115
- package/dist/process.d.ts +11 -6
- package/dist/process.js +21 -4
- package/dist/production-builder.js +7 -0
- package/dist/prop-sentinels.d.ts +11 -11
- package/dist/public-env.d.ts +14 -0
- package/dist/pwa/directives.d.ts +12 -3
- package/dist/pwa/inject.d.ts +10 -0
- package/dist/pwa/precache.d.ts +22 -16
- package/dist/pwa/service-worker.d.ts +12 -0
- package/dist/pwa.js +1318 -610
- package/dist/reactive-bindings.d.ts +34 -11
- package/dist/reactive.d.ts +58 -30
- package/dist/reactive.js +56 -31
- package/dist/render.js +1 -0
- package/dist/route-middleware.d.ts +2 -35
- package/dist/route-types.d.ts +134 -0
- package/dist/route-types.js +24 -0
- package/dist/router.d.ts +5 -7
- package/dist/routes.d.ts +1 -3
- package/dist/runtime-globals.d.ts +147 -24
- package/dist/runtime-globals.js +16 -1
- package/dist/runtime-injection.d.ts +8 -0
- package/dist/runtime-injection.js +33 -24
- package/dist/script-emit.d.ts +30 -0
- package/dist/script-json.d.ts +36 -0
- package/dist/script-json.js +6 -0
- package/dist/script-validation.d.ts +21 -4
- package/dist/seo.d.ts +118 -47
- package/dist/server-bindings.d.ts +21 -0
- package/dist/sfc-template.d.ts +8 -8
- package/dist/signal-processing.d.ts +35 -15
- package/dist/signals-api.d.ts +117 -58
- package/dist/signals-api.js +7 -4
- package/dist/signals.d.ts +24 -17
- package/dist/signals.js +765 -60
- package/dist/site-builder/build.js +8 -0
- package/dist/site-url.d.ts +46 -0
- package/dist/site-url.js +70 -0
- package/dist/slots.d.ts +86 -20
- package/dist/source-signature.d.ts +45 -0
- package/dist/source-signature.js +20 -0
- package/dist/ssg.d.ts +285 -142
- package/dist/ssg.js +1268 -556
- package/dist/state-dir.d.ts +4 -4
- package/dist/state-management.d.ts +0 -12
- package/dist/state-management.js +8 -25
- package/dist/store-imports.d.ts +23 -0
- package/dist/store-imports.js +3 -0
- package/dist/store-loader.d.ts +10 -0
- package/dist/store-loader.js +10 -9
- package/dist/story/analytics.d.ts +138 -60
- package/dist/story/bookmarks.d.ts +87 -34
- package/dist/story/cli.d.ts +123 -69
- package/dist/story/collect/scanner.d.ts +4 -0
- package/dist/story/collect/tree.d.ts +8 -1
- package/dist/story/commands/build.d.ts +11 -6
- package/dist/story/commands/dev.d.ts +15 -8
- package/dist/story/commands/preview.d.ts +13 -7
- package/dist/story/config-watcher.d.ts +20 -13
- package/dist/story/config.d.ts +11 -8
- package/dist/story/context.d.ts +14 -8
- package/dist/story/hmr.d.ts +24 -26
- package/dist/story/hot-swap.d.ts +34 -23
- package/dist/story/keyboard-shortcuts.d.ts +23 -18
- package/dist/story/output.d.ts +46 -44
- package/dist/story/performance.d.ts +107 -45
- package/dist/story/presets.d.ts +107 -41
- package/dist/story/renderer.d.ts +41 -27
- package/dist/story/search.d.ts +23 -12
- package/dist/story/server.d.ts +21 -11
- package/dist/story/setup.d.ts +23 -15
- package/dist/story/testing.d.ts +65 -40
- package/dist/story/types.d.ts +262 -160
- package/dist/streaming.d.ts +119 -57
- package/dist/stx-virtual-ts.d.ts +165 -0
- package/dist/stx-virtual-ts.js +372 -0
- package/dist/stx.d.ts +78 -1
- package/dist/style-scoping.d.ts +17 -4
- package/dist/suspense.d.ts +67 -52
- package/dist/teleport.d.ts +22 -0
- package/dist/template-tag-balance.d.ts +22 -6
- package/dist/transitions.d.ts +66 -55
- package/dist/typecheck.d.ts +77 -0
- package/dist/typecheck.js +156 -0
- package/dist/types/component-types.d.ts +187 -122
- package/dist/types/config-types.d.ts +758 -297
- package/dist/types/context-types.d.ts +46 -24
- package/dist/types/csp-types.d.ts +70 -66
- package/dist/types/directive-types.d.ts +211 -155
- package/dist/types/index.d.ts +6 -109
- package/dist/types/pwa-types.d.ts +273 -148
- package/dist/types.d.ts +0 -1
- package/dist/typescript-templates.d.ts +11 -0
- package/dist/unresolved-identifiers.d.ts +24 -22
- package/dist/unresolved-identifiers.js +2 -0
- package/dist/utils.d.ts +24 -21
- package/dist/validator.d.ts +28 -26
- package/dist/variable-extractor.d.ts +48 -13
- package/dist/variable-extractor.js +27 -4
- package/dist/view-composers.d.ts +80 -81
- package/dist/virtual-scrolling.d.ts +101 -81
- package/dist/vue-template.d.ts +23 -0
- package/dist/web-components/css-scoping.d.ts +21 -11
- package/dist/web-components.d.ts +81 -58
- package/dist/x-element.d.ts +0 -1
- package/package.json +5 -5
- package/stx.d.ts +78 -1
package/dist/sfc-template.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export declare function isClientTemplateTag(openingTag: string): boolean;
|
|
2
|
-
export declare function findSfcTemplateBlock(source: string): SfcTemplateBlock | null;
|
|
3
1
|
/**
|
|
4
2
|
* Locate the explicit wrapper `<template>` in an STX single-file component.
|
|
5
3
|
*
|
|
@@ -8,10 +6,12 @@ export declare function findSfcTemplateBlock(source: string): SfcTemplateBlock |
|
|
|
8
6
|
* and must stay in the rendered body. Keeping this distinction in one scanner
|
|
9
7
|
* avoids subtle regex boundary bugs for punctuation-prefixed attributes.
|
|
10
8
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
export interface SfcTemplateBlock {
|
|
10
|
+
start: number;
|
|
11
|
+
openEnd: number;
|
|
12
|
+
closeStart: number;
|
|
13
|
+
end: number;
|
|
14
|
+
content: string;
|
|
17
15
|
}
|
|
16
|
+
export declare function isClientTemplateTag(openingTag: string): boolean;
|
|
17
|
+
export declare function findSfcTemplateBlock(source: string): SfcTemplateBlock | null;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signal Processing Module
|
|
3
|
+
*
|
|
4
|
+
* Handles detection, conversion, and setup of STX signals in templates.
|
|
5
|
+
* Converts directive-style syntax (@if, @for) to attribute-style for the
|
|
6
|
+
* client-side signals runtime, and wraps signal scripts in setup functions.
|
|
7
|
+
*
|
|
8
|
+
* @module signal-processing
|
|
9
|
+
*/
|
|
1
10
|
import type { StxOptions } from './types';
|
|
2
11
|
/**
|
|
3
12
|
* Scan a template for `<script>` tags in browser order: each opening tag is
|
|
@@ -14,7 +23,28 @@ import type { StxOptions } from './types';
|
|
|
14
23
|
* `skipAttrs` lets callers drop tags whose attribute string contains certain
|
|
15
24
|
* patterns (e.g. `server`, `src=`, `data-stx-scoped`).
|
|
16
25
|
*/
|
|
17
|
-
export declare function scanScriptTags(html: string, opts?: {
|
|
26
|
+
export declare function scanScriptTags(html: string, opts?: {
|
|
27
|
+
skipAttrs?: RegExp;
|
|
28
|
+
}): Array<{
|
|
29
|
+
fullMatch: string;
|
|
30
|
+
attrs: string;
|
|
31
|
+
body: string;
|
|
32
|
+
start: number;
|
|
33
|
+
end: number;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Parsed form of a loop expression (`@for` / `@foreach` argument).
|
|
37
|
+
*
|
|
38
|
+
* `style: 'as'` — "iterable as item" / "iterable as idx => item" / "iterable as (item, idx)"
|
|
39
|
+
* `style: 'in'` — "item in iterable" / "(item, idx) in iterable" / "item of iterable"
|
|
40
|
+
* `style: 'unknown'` — fell through all parsers; iterable is `null`
|
|
41
|
+
*/
|
|
42
|
+
export interface ParsedLoopExpression {
|
|
43
|
+
style: 'as' | 'in' | 'unknown';
|
|
44
|
+
iterable: string | null;
|
|
45
|
+
itemVar: string | null;
|
|
46
|
+
indexVar: string | null;
|
|
47
|
+
}
|
|
18
48
|
/**
|
|
19
49
|
* Parse a loop argument — accepts every syntax stx supports at runtime.
|
|
20
50
|
*
|
|
@@ -118,7 +148,10 @@ export declare function preEvalLiteralReactiveIfs(template: string): string;
|
|
|
118
148
|
* </template>
|
|
119
149
|
*/
|
|
120
150
|
export declare function convertSignalLoopsToAttributes(template: string, context?: Record<string, any>): string;
|
|
121
|
-
export declare function processScriptSetup(template: string, filePath?: string, serverData?: Record<string, unknown>): Promise<{
|
|
151
|
+
export declare function processScriptSetup(template: string, filePath?: string, serverData?: Record<string, unknown>): Promise<{
|
|
152
|
+
output: string;
|
|
153
|
+
setupCode: string | null;
|
|
154
|
+
}>;
|
|
122
155
|
/**
|
|
123
156
|
* Extract exported variable names from setup script.
|
|
124
157
|
* Returns variables that should be exposed to the template.
|
|
@@ -160,16 +193,3 @@ export declare function findMarkupIndexOutsideScripts(html: string, pattern: Reg
|
|
|
160
193
|
* Type-only specifiers are erased: they have no runtime binding to alias.
|
|
161
194
|
*/
|
|
162
195
|
export declare function rewriteStxImportSpecifiers(specifiers: string): string;
|
|
163
|
-
/**
|
|
164
|
-
* Parsed form of a loop expression (`@for` / `@foreach` argument).
|
|
165
|
-
*
|
|
166
|
-
* `style: 'as'` — "iterable as item" / "iterable as idx => item" / "iterable as (item, idx)"
|
|
167
|
-
* `style: 'in'` — "item in iterable" / "(item, idx) in iterable" / "item of iterable"
|
|
168
|
-
* `style: 'unknown'` — fell through all parsers; iterable is `null`
|
|
169
|
-
*/
|
|
170
|
-
export declare interface ParsedLoopExpression {
|
|
171
|
-
style: 'as' | 'in' | 'unknown'
|
|
172
|
-
iterable: string | null
|
|
173
|
-
itemVar: string | null
|
|
174
|
-
indexVar: string | null
|
|
175
|
-
}
|
package/dist/signals-api.d.ts
CHANGED
|
@@ -1,3 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* STX Signals API — module-import path for reactive primitives.
|
|
3
|
+
* =============================================================
|
|
4
|
+
*
|
|
5
|
+
* This module exports `state`, `derived`, `effect`, `batch`, `untrack`,
|
|
6
|
+
* `peek`, `isSignal`, `isDerived`, `onMount`, `onDestroy` as standalone
|
|
7
|
+
* TypeScript functions. They have their own subscriber sets, effect
|
|
8
|
+
* tracking, and batching — fully self-contained reactivity.
|
|
9
|
+
*
|
|
10
|
+
* ## Why this exists alongside `signals.ts`
|
|
11
|
+
*
|
|
12
|
+
* stx ships TWO independent reactive implementations:
|
|
13
|
+
*
|
|
14
|
+
* 1. **This file (`signals-api.ts`)** — module-import path. Used by
|
|
15
|
+
* composables, stores, SSR/server code, and tests that import
|
|
16
|
+
* from `'@stacksjs/stx'` and run in Node (or browser) without
|
|
17
|
+
* going through the stx bundler.
|
|
18
|
+
*
|
|
19
|
+
* 2. **The runtime template literal in `signals.ts`** — generated as
|
|
20
|
+
* a JS string and injected into client pages. Owns its own
|
|
21
|
+
* subscribers; populates `window.stx.{state, derived, …}`.
|
|
22
|
+
*
|
|
23
|
+
* The stx bundler rewrites `<script client>` imports of these symbols
|
|
24
|
+
* to destructure from `window.stx`. So a `const count = state(0)` in a
|
|
25
|
+
* client script ends up using the runtime version (#2). The same call
|
|
26
|
+
* in an unbundled context — a composable test, an SSR helper — uses
|
|
27
|
+
* this file (#1).
|
|
28
|
+
*
|
|
29
|
+
* **Important**: signals created in one impl are invisible to the other.
|
|
30
|
+
* A `state()` returned by this module cannot be `.set()`-ed from inside
|
|
31
|
+
* a client page's `<script>` block (and vice versa). The two reactive
|
|
32
|
+
* worlds are disjoint by design — they exist because bundled and
|
|
33
|
+
* non-bundled contexts need different code-generation strategies.
|
|
34
|
+
*
|
|
35
|
+
* ## Parity contract
|
|
36
|
+
*
|
|
37
|
+
* Both implementations expose the same public surface and must behave
|
|
38
|
+
* equivalently. Pinned by `test/reactivity/dual-impl-parity.test.ts`,
|
|
39
|
+
* which executes the same suite against both. When parity drifts, fix
|
|
40
|
+
* the lagging side — don't update only one.
|
|
41
|
+
*
|
|
42
|
+
* See stacksjs/stx#1712 for the architectural rationale.
|
|
43
|
+
*
|
|
44
|
+
* @module signals-api
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* A reactive state signal.
|
|
48
|
+
*
|
|
49
|
+
* Call it to read the value, use `.set()` to write, or `.update()` to transform.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const count = state(0)
|
|
54
|
+
* count() // Read: 0
|
|
55
|
+
* count.set(5) // Write: 5
|
|
56
|
+
* count.update(n => n + 1) // Update: 6
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export interface Signal<T> {
|
|
60
|
+
/** Read the current value */
|
|
61
|
+
(): T;
|
|
62
|
+
/** Vue-compatible value accessor */
|
|
63
|
+
value: T;
|
|
64
|
+
/** Set a new value */
|
|
65
|
+
set(value: T): void;
|
|
66
|
+
/** Update the value using a function */
|
|
67
|
+
update(fn: (current: T) => T): void;
|
|
68
|
+
/** Subscribe to changes (returns unsubscribe function) */
|
|
69
|
+
subscribe(callback: (value: T, prev: T) => void): () => void;
|
|
70
|
+
/** Internal marker */
|
|
71
|
+
readonly _isSignal: true;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A derived (computed) signal that automatically updates when dependencies change.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const doubled = derived(() => count() * 2)
|
|
79
|
+
* doubled() // Read the computed value
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export interface DerivedSignal<T> {
|
|
83
|
+
/** Read the current computed value */
|
|
84
|
+
(): T;
|
|
85
|
+
/** Vue-compatible read-only value accessor */
|
|
86
|
+
readonly value: T;
|
|
87
|
+
/** Internal marker */
|
|
88
|
+
readonly _isDerived: true;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Options for creating effects.
|
|
92
|
+
*/
|
|
93
|
+
export interface EffectOptions {
|
|
94
|
+
/** Run the effect immediately (default: true) */
|
|
95
|
+
immediate?: boolean;
|
|
96
|
+
/** Name for debugging */
|
|
97
|
+
name?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Cleanup function returned by effects.
|
|
101
|
+
*/
|
|
102
|
+
export type CleanupFn = () => void;
|
|
103
|
+
/**
|
|
104
|
+
* Lifecycle hook callback.
|
|
105
|
+
*/
|
|
106
|
+
export type LifecycleCallback = () => void | CleanupFn | Promise<void>;
|
|
1
107
|
/**
|
|
2
108
|
* Creates a reactive state signal.
|
|
3
109
|
*
|
|
@@ -228,7 +334,10 @@ export declare function runDestroyCallbacks(): void;
|
|
|
228
334
|
* How many callbacks are queued. Exposed for tests and diagnostics — a queue
|
|
229
335
|
* that only ever grows is the shape of the defect above.
|
|
230
336
|
*/
|
|
231
|
-
export declare function pendingLifecycleCounts(): {
|
|
337
|
+
export declare function pendingLifecycleCounts(): {
|
|
338
|
+
mount: number;
|
|
339
|
+
destroy: number;
|
|
340
|
+
};
|
|
232
341
|
/**
|
|
233
342
|
* Checks if a value is a signal.
|
|
234
343
|
*
|
|
@@ -289,6 +398,13 @@ export declare function untrack<T>(value: T | Signal<T> | DerivedSignal<T>): T;
|
|
|
289
398
|
* ```
|
|
290
399
|
*/
|
|
291
400
|
export declare function peek<T>(fn: () => T): T;
|
|
401
|
+
/**
|
|
402
|
+
* The function returned by {@link useOptimistic} to apply an optimistic update.
|
|
403
|
+
* Returns a `settle` function that removes this specific optimistic entry (call
|
|
404
|
+
* it to roll back, e.g. in a `catch`). If a `settleWhen` promise is passed, the
|
|
405
|
+
* entry is removed automatically when that promise settles (success or error).
|
|
406
|
+
*/
|
|
407
|
+
export type AddOptimistic<A> = (action: A, settleWhen?: PromiseLike<unknown>) => () => void;
|
|
292
408
|
/**
|
|
293
409
|
* React-19-style optimistic state, adapted to signals.
|
|
294
410
|
*
|
|
@@ -323,60 +439,3 @@ export declare function peek<T>(fn: () => T): T;
|
|
|
323
439
|
* @see stacksjs/stx#1742
|
|
324
440
|
*/
|
|
325
441
|
export declare function useOptimistic<T, A>(base: Signal<T> | DerivedSignal<T> | (() => T) | T, reducer: (current: T, action: A) => T): [DerivedSignal<T>, AddOptimistic<A>];
|
|
326
|
-
/**
|
|
327
|
-
* A reactive state signal.
|
|
328
|
-
*
|
|
329
|
-
* Call it to read the value, use `.set()` to write, or `.update()` to transform.
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```typescript
|
|
333
|
-
* const count = state(0)
|
|
334
|
-
* count() // Read: 0
|
|
335
|
-
* count.set(5) // Write: 5
|
|
336
|
-
* count.update(n => n + 1) // Update: 6
|
|
337
|
-
* ```
|
|
338
|
-
*/
|
|
339
|
-
export declare interface Signal<T> {
|
|
340
|
-
(): T
|
|
341
|
-
value: T
|
|
342
|
-
set(value: T): void
|
|
343
|
-
update(fn: (current: T) => T): void
|
|
344
|
-
subscribe(callback: (value: T, prev: T) => void): () => void
|
|
345
|
-
readonly _isSignal: true
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* A derived (computed) signal that automatically updates when dependencies change.
|
|
349
|
-
*
|
|
350
|
-
* @example
|
|
351
|
-
* ```typescript
|
|
352
|
-
* const doubled = derived(() => count() * 2)
|
|
353
|
-
* doubled() // Read the computed value
|
|
354
|
-
* ```
|
|
355
|
-
*/
|
|
356
|
-
export declare interface DerivedSignal<T> {
|
|
357
|
-
(): T
|
|
358
|
-
readonly value: T
|
|
359
|
-
readonly _isDerived: true
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Options for creating effects.
|
|
363
|
-
*/
|
|
364
|
-
export declare interface EffectOptions {
|
|
365
|
-
immediate?: boolean
|
|
366
|
-
name?: string
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Cleanup function returned by effects.
|
|
370
|
-
*/
|
|
371
|
-
export type CleanupFn = () => void;
|
|
372
|
-
/**
|
|
373
|
-
* Lifecycle hook callback.
|
|
374
|
-
*/
|
|
375
|
-
export type LifecycleCallback = () => void | CleanupFn | Promise<void>;
|
|
376
|
-
/**
|
|
377
|
-
* The function returned by {@link useOptimistic} to apply an optimistic update.
|
|
378
|
-
* Returns a `settle` function that removes this specific optimistic entry (call
|
|
379
|
-
* it to roll back, e.g. in a `catch`). If a `settleWhen` promise is passed, the
|
|
380
|
-
* entry is removed automatically when that promise settles (success or error).
|
|
381
|
-
*/
|
|
382
|
-
export type AddOptimistic<A> = (action: A, settleWhen?: PromiseLike<unknown>) => () => void;
|
package/dist/signals-api.js
CHANGED
|
@@ -82,7 +82,8 @@ export function effect(fn, options = {}) {
|
|
|
82
82
|
activeEffect = runEffect;
|
|
83
83
|
effectStack.push(runEffect);
|
|
84
84
|
try {
|
|
85
|
-
|
|
85
|
+
const result = fn();
|
|
86
|
+
cleanup = typeof result === "function" ? result : void 0;
|
|
86
87
|
} finally {
|
|
87
88
|
effectStack.pop();
|
|
88
89
|
activeEffect = prevEffect;
|
|
@@ -117,16 +118,18 @@ export function onDestroy(callback) {
|
|
|
117
118
|
destroyCallbacks.push(callback);
|
|
118
119
|
}
|
|
119
120
|
export function runMountCallbacks() {
|
|
120
|
-
drain(mountCallbacks, "onMount");
|
|
121
|
+
drain(mountCallbacks, "onMount", destroyCallbacks);
|
|
121
122
|
}
|
|
122
123
|
export function runDestroyCallbacks() {
|
|
123
124
|
drain(destroyCallbacks, "onDestroy");
|
|
124
125
|
}
|
|
125
|
-
function drain(queue, label) {
|
|
126
|
+
function drain(queue, label, sink) {
|
|
126
127
|
const pending = queue.splice(0, queue.length);
|
|
127
128
|
for (const callback of pending)
|
|
128
129
|
try {
|
|
129
|
-
callback();
|
|
130
|
+
const cleanup = callback();
|
|
131
|
+
if (sink && typeof cleanup === "function")
|
|
132
|
+
sink.push(cleanup);
|
|
130
133
|
} catch (error) {
|
|
131
134
|
console.error(`[stx] ${label} callback threw:`, error);
|
|
132
135
|
}
|
package/dist/signals.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* STX Signals - Reactive State Management
|
|
3
|
+
* =========================================
|
|
4
|
+
*
|
|
5
|
+
* This module re-exports the build-time signals API from signals-api.ts
|
|
6
|
+
* and provides the client runtime string generators.
|
|
7
|
+
*
|
|
8
|
+
* @module signals
|
|
9
|
+
*/
|
|
1
10
|
import { state, derived, effect, batch, onMount, onDestroy, isSignal, isDerived, untrack, peek } from './signals-api';
|
|
11
|
+
export * from './signals-api';
|
|
2
12
|
/**
|
|
3
13
|
* Generates the browser runtime for STX signals.
|
|
4
14
|
*
|
|
@@ -14,21 +24,18 @@ export declare function generateSignalsRuntime(): string;
|
|
|
14
24
|
* @returns Human-readable JavaScript runtime code
|
|
15
25
|
*/
|
|
16
26
|
export declare function generateSignalsRuntimeDev(): string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
untrack,
|
|
31
|
-
peek,
|
|
32
|
-
generateSignalsRuntime,
|
|
33
|
-
generateSignalsRuntimeDev
|
|
27
|
+
declare const _default: {
|
|
28
|
+
state: typeof state;
|
|
29
|
+
derived: typeof derived;
|
|
30
|
+
effect: typeof effect;
|
|
31
|
+
batch: typeof batch;
|
|
32
|
+
onMount: typeof onMount;
|
|
33
|
+
onDestroy: typeof onDestroy;
|
|
34
|
+
isSignal: typeof isSignal;
|
|
35
|
+
isDerived: typeof isDerived;
|
|
36
|
+
untrack: typeof untrack;
|
|
37
|
+
peek: typeof peek;
|
|
38
|
+
generateSignalsRuntime: typeof generateSignalsRuntime;
|
|
39
|
+
generateSignalsRuntimeDev: typeof generateSignalsRuntimeDev;
|
|
34
40
|
};
|
|
41
|
+
export default _default;
|