@stacksjs/stx 0.2.154 → 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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useForm — reactive form state reachable from a <script client> block
|
|
3
|
+
* (stacksjs/stx#1846, renamed in #1843).
|
|
4
|
+
*
|
|
5
|
+
* Named `defineForm` until it turned out to be the odd one out. In this
|
|
6
|
+
* codebase `define*` DECLARES — defineProps, defineEmits, defineExpose,
|
|
7
|
+
* definePageMeta, defineSlots, defineStore — while `use*` returns live reactive
|
|
8
|
+
* state: useFetch, useCookie, useMutation, useDark. This returns signal-backed
|
|
9
|
+
* state and a handleSubmit, so it was a `use*` wearing a `define*` name, and the
|
|
10
|
+
* file being called use-form.ts while exporting defineForm meant grepping for
|
|
11
|
+
* either one found the wrong half.
|
|
12
|
+
*
|
|
13
|
+
* `defineForm` remains as a deprecated alias below.
|
|
14
|
+
*
|
|
15
|
+
* ---
|
|
16
|
+
*
|
|
17
|
+
* THERE IS A SECOND `useForm`, in @stacksjs/composables
|
|
18
|
+
* (storage/framework/core/composables/src/useForm.ts). It is not this one, and
|
|
19
|
+
* the two are not interchangeable — they were written independently because
|
|
20
|
+
* neither side could find the other's, which is #1843's adoption problem
|
|
21
|
+
* happening to the framework itself.
|
|
22
|
+
*
|
|
23
|
+
* this one @stacksjs/composables
|
|
24
|
+
* useForm(schema, initialValues) useForm({ initialValues, onSubmit })
|
|
25
|
+
* form.values.email form.values.value.email
|
|
26
|
+
* form.getFieldState('email') form.field('email')
|
|
27
|
+
* v.required().email() schema.string().email() (ts-validation)
|
|
28
|
+
* validate() -> Promise<string[]> validate() -> { valid, errors }
|
|
29
|
+
* has: validating, validateField has: isSubmitting, isValid, isDirty,
|
|
30
|
+
* setErrors (422), clearErrors,
|
|
31
|
+
* submitButtonProps, firstErrorField,
|
|
32
|
+
* aria inputProps
|
|
33
|
+
*
|
|
34
|
+
* Before adding a feature here, check whether it exists there — and say so in
|
|
35
|
+
* the PR either way. Unifying them is a breaking change to one side's public
|
|
36
|
+
* API, not a re-export, so it needs a deliberate decision rather than drift.
|
|
37
|
+
*
|
|
38
|
+
* Lifted out of forms-validation.ts so the framework-composables demand-bundler
|
|
39
|
+
* (src/framework-composables.ts) can ship it to the browser. That bundler scans
|
|
40
|
+
* THIS directory, takes each file whole, strips the imports — every name they
|
|
41
|
+
* pull from stx is a runtime global by the time the emitted script runs — and
|
|
42
|
+
* merges the export onto window.stx. defineForm was exported from the package
|
|
43
|
+
* and type-checked, yet reached the client by no path at all, so an app that
|
|
44
|
+
* wanted reactive form state hand-rolled it. #1856 made it reactive; this makes
|
|
45
|
+
* it reachable.
|
|
46
|
+
*
|
|
47
|
+
* The signal comes from signals-api, whose `state` is published as a bare global
|
|
48
|
+
* (signals.ts does `window.state = state`), so the stripped `import { state }`
|
|
49
|
+
* below still resolves once the bundle runs. reactivity.ts's `reactive()` would
|
|
50
|
+
* NOT — it tracks a separate effect context the template runtime never reads
|
|
51
|
+
* (see #1885).
|
|
52
|
+
*/
|
|
53
|
+
import type { FormState, Validator } from '../forms-validation';
|
|
54
|
+
/**
|
|
55
|
+
* Reactive form state from a validation schema.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const form = useForm({
|
|
60
|
+
* email: v.required().email(),
|
|
61
|
+
* password: v.required().min(8),
|
|
62
|
+
* age: v.number().between(18, 100)
|
|
63
|
+
* })
|
|
64
|
+
*
|
|
65
|
+
* // Access form state
|
|
66
|
+
* form.values.email
|
|
67
|
+
* form.errors.email
|
|
68
|
+
* form.isValid
|
|
69
|
+
*
|
|
70
|
+
* // Validate
|
|
71
|
+
* await form.validate()
|
|
72
|
+
*
|
|
73
|
+
* // Handle submit
|
|
74
|
+
* form.handleSubmit((values) => {
|
|
75
|
+
* console.log(values)
|
|
76
|
+
* })
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function useForm<T extends Record<string, Validator>>(schema: T, initialValues?: Partial<{
|
|
80
|
+
[K in keyof T]: unknown;
|
|
81
|
+
}>): FormState<T>;
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Use {@link useForm}. Renamed in stacksjs/stx#1843 so the name
|
|
84
|
+
* matches what it does: `define*` declares in this codebase, `use*` returns
|
|
85
|
+
* live reactive state, and this returns the latter.
|
|
86
|
+
*
|
|
87
|
+
* A plain alias, not a wrapper — same reference, so `defineForm === useForm`
|
|
88
|
+
* and anything comparing or spying on the function keeps working. Kept for a
|
|
89
|
+
* minor; existing apps do not have to move in the same release they upgrade in.
|
|
90
|
+
*/
|
|
91
|
+
export declare const defineForm: typeof useForm;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { state } from "../signals-api.js";
|
|
2
|
+
function signalRecord(fields, init) {
|
|
3
|
+
const signals = {};
|
|
4
|
+
for (const field of fields)
|
|
5
|
+
signals[field] = state(init(field));
|
|
6
|
+
return new Proxy({}, {
|
|
7
|
+
get: (_target, prop) => signals[prop]?.(),
|
|
8
|
+
set: (_target, prop, value) => {
|
|
9
|
+
if (signals[prop])
|
|
10
|
+
signals[prop].set(value);
|
|
11
|
+
else
|
|
12
|
+
signals[prop] = state(value);
|
|
13
|
+
return !0;
|
|
14
|
+
},
|
|
15
|
+
has: (_target, prop) => (prop in signals),
|
|
16
|
+
deleteProperty: (_target, prop) => {
|
|
17
|
+
delete signals[prop];
|
|
18
|
+
return !0;
|
|
19
|
+
},
|
|
20
|
+
ownKeys: () => Reflect.ownKeys(signals),
|
|
21
|
+
getOwnPropertyDescriptor: (_target, prop) => (prop in signals) ? { enumerable: !0, configurable: !0, writable: !0, value: signals[prop]() } : void 0
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function snapshot(record, fields) {
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const field of fields)
|
|
27
|
+
out[field] = record[field];
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
export function useForm(schema, initialValues) {
|
|
31
|
+
const fields = Object.keys(schema), values = signalRecord(fields, (f) => initialValues?.[f] ?? schema[f].getDefaultValue()), errors = signalRecord(fields, () => []), touched = signalRecord(fields, () => !1), dirty = signalRecord(fields, () => !1), validating = signalRecord(fields, () => !1), isValidatingSignal = state(!1);
|
|
32
|
+
async function validateField(field) {
|
|
33
|
+
validating[field] = !0;
|
|
34
|
+
const fieldErrors = await schema[field].validate(values[field], values);
|
|
35
|
+
errors[field] = fieldErrors;
|
|
36
|
+
validating[field] = !1;
|
|
37
|
+
return fieldErrors.length === 0;
|
|
38
|
+
}
|
|
39
|
+
async function validate() {
|
|
40
|
+
isValidatingSignal.set(!0);
|
|
41
|
+
const results = await Promise.all(fields.map(validateField));
|
|
42
|
+
isValidatingSignal.set(!1);
|
|
43
|
+
return results.every(Boolean);
|
|
44
|
+
}
|
|
45
|
+
function reset() {
|
|
46
|
+
for (const field of fields) {
|
|
47
|
+
values[field] = initialValues?.[field] ?? schema[field].getDefaultValue();
|
|
48
|
+
errors[field] = [];
|
|
49
|
+
touched[field] = !1;
|
|
50
|
+
dirty[field] = !1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function setValues(newValues) {
|
|
54
|
+
for (const field of fields)
|
|
55
|
+
if (field in newValues) {
|
|
56
|
+
values[field] = newValues[field];
|
|
57
|
+
dirty[field] = !0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function setFieldValue(field, value) {
|
|
61
|
+
values[field] = value;
|
|
62
|
+
dirty[field] = !0;
|
|
63
|
+
}
|
|
64
|
+
function setFieldTouched(field, isTouched = !0) {
|
|
65
|
+
touched[field] = isTouched;
|
|
66
|
+
if (isTouched)
|
|
67
|
+
validateField(field);
|
|
68
|
+
}
|
|
69
|
+
function getFieldState(field) {
|
|
70
|
+
return {
|
|
71
|
+
value: values[field],
|
|
72
|
+
errors: errors[field],
|
|
73
|
+
touched: touched[field],
|
|
74
|
+
dirty: dirty[field],
|
|
75
|
+
valid: errors[field].length === 0,
|
|
76
|
+
validating: validating[field]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function handleSubmit(onSubmit) {
|
|
80
|
+
return async (e) => {
|
|
81
|
+
e?.preventDefault?.();
|
|
82
|
+
for (const field of fields)
|
|
83
|
+
touched[field] = !0;
|
|
84
|
+
if (await validate())
|
|
85
|
+
await onSubmit(snapshot(values, fields));
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
values,
|
|
90
|
+
errors,
|
|
91
|
+
touched,
|
|
92
|
+
dirty,
|
|
93
|
+
get isValid() {
|
|
94
|
+
return fields.every((f) => errors[f].length === 0);
|
|
95
|
+
},
|
|
96
|
+
get isValidating() {
|
|
97
|
+
return isValidatingSignal() || fields.some((f) => validating[f]);
|
|
98
|
+
},
|
|
99
|
+
get isDirty() {
|
|
100
|
+
return fields.some((f) => dirty[f]);
|
|
101
|
+
},
|
|
102
|
+
validate,
|
|
103
|
+
validateField,
|
|
104
|
+
reset,
|
|
105
|
+
setValues,
|
|
106
|
+
setFieldValue,
|
|
107
|
+
setFieldTouched,
|
|
108
|
+
getFieldState,
|
|
109
|
+
handleSubmit
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export const defineForm = useForm;
|
package/dist/composables.d.ts
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* STX Composables
|
|
3
|
+
*
|
|
4
|
+
* Vue-inspired composable utilities for STX components:
|
|
5
|
+
* - Lifecycle hooks (onMount, onDestroy, onUpdate)
|
|
6
|
+
* - Refs for DOM element references
|
|
7
|
+
* - Watch and computed for reactivity
|
|
8
|
+
*
|
|
9
|
+
* @module composables
|
|
10
|
+
*/
|
|
11
|
+
export type LifecycleHook = () => void | (() => void);
|
|
12
|
+
export type CleanupFn = () => void;
|
|
13
|
+
export type WatchCallback<T> = (newValue: T, oldValue: T | undefined) => void | CleanupFn;
|
|
14
|
+
export type WatchSource<T> = () => T;
|
|
15
|
+
export interface Ref<T> {
|
|
16
|
+
value: T | null;
|
|
17
|
+
readonly current: T | null;
|
|
18
|
+
}
|
|
19
|
+
export interface ComponentInstance {
|
|
20
|
+
id: string;
|
|
21
|
+
element: Element | null;
|
|
22
|
+
mountHooks: LifecycleHook[];
|
|
23
|
+
destroyHooks: CleanupFn[];
|
|
24
|
+
updateHooks: LifecycleHook[];
|
|
25
|
+
refs: Map<string, Ref<any>>;
|
|
26
|
+
watchers: Array<{
|
|
27
|
+
stop: () => void;
|
|
28
|
+
}>;
|
|
29
|
+
isMounted: boolean;
|
|
30
|
+
}
|
|
1
31
|
/**
|
|
2
32
|
* Create a new component instance context.
|
|
3
33
|
* Called internally when a component script starts executing.
|
|
@@ -65,6 +95,18 @@ export declare function onDestroy(hook: CleanupFn): void;
|
|
|
65
95
|
* ```
|
|
66
96
|
*/
|
|
67
97
|
export declare function onUpdate(hook: LifecycleHook): void;
|
|
98
|
+
/**
|
|
99
|
+
* Alias for onMount - matches common naming conventions.
|
|
100
|
+
*/
|
|
101
|
+
export declare const onMounted: typeof onMount;
|
|
102
|
+
/**
|
|
103
|
+
* Alias for onDestroy - matches Vue naming.
|
|
104
|
+
*/
|
|
105
|
+
export declare const onUnmounted: typeof onDestroy;
|
|
106
|
+
/**
|
|
107
|
+
* Alias for onUpdate - matches Vue naming.
|
|
108
|
+
*/
|
|
109
|
+
export declare const onUpdated: typeof onUpdate;
|
|
68
110
|
/**
|
|
69
111
|
* Create a ref for holding a DOM element reference.
|
|
70
112
|
*
|
|
@@ -106,7 +148,9 @@ export declare function namedRef<T = HTMLElement>(name: string, initialValue?: T
|
|
|
106
148
|
* </script>
|
|
107
149
|
* ```
|
|
108
150
|
*/
|
|
109
|
-
export declare function watch<T>(source: WatchSource<T>, callback: WatchCallback<T>, options?: {
|
|
151
|
+
export declare function watch<T>(source: WatchSource<T>, callback: WatchCallback<T>, options?: {
|
|
152
|
+
immediate?: boolean;
|
|
153
|
+
}): () => void;
|
|
110
154
|
/**
|
|
111
155
|
* Create a computed value that updates when dependencies change.
|
|
112
156
|
*
|
|
@@ -123,7 +167,9 @@ export declare function watch<T>(source: WatchSource<T>, callback: WatchCallback
|
|
|
123
167
|
* </script>
|
|
124
168
|
* ```
|
|
125
169
|
*/
|
|
126
|
-
export declare function computed<T>(getter: () => T): {
|
|
170
|
+
export declare function computed<T>(getter: () => T): {
|
|
171
|
+
readonly value: T;
|
|
172
|
+
};
|
|
127
173
|
/**
|
|
128
174
|
* Initialize a component and run its setup.
|
|
129
175
|
* This is called by the STX runtime when a component is created.
|
|
@@ -145,6 +191,10 @@ export declare function destroyComponent(instance: ComponentInstance): void;
|
|
|
145
191
|
* Generate the client-side runtime script for lifecycle management.
|
|
146
192
|
*/
|
|
147
193
|
export declare function generateLifecycleRuntime(): string;
|
|
194
|
+
/** Symbol for injection keys */
|
|
195
|
+
export type InjectionKey<T> = symbol & {
|
|
196
|
+
__type?: T;
|
|
197
|
+
};
|
|
148
198
|
/**
|
|
149
199
|
* Create a typed injection key.
|
|
150
200
|
*
|
|
@@ -209,65 +259,19 @@ export declare function withInjectionScope<T>(fn: () => T | Promise<T>): Promise
|
|
|
209
259
|
* Clear all injections (for testing).
|
|
210
260
|
*/
|
|
211
261
|
export declare function clearInjections(): void;
|
|
212
|
-
/**
|
|
213
|
-
* Alias for onMount - matches common naming conventions.
|
|
214
|
-
*/
|
|
215
|
-
export declare const onMounted: unknown;
|
|
216
|
-
/**
|
|
217
|
-
* Alias for onDestroy - matches Vue naming.
|
|
218
|
-
*/
|
|
219
|
-
export declare const onUnmounted: unknown;
|
|
220
|
-
/**
|
|
221
|
-
* Alias for onUpdate - matches Vue naming.
|
|
222
|
-
*/
|
|
223
|
-
export declare const onUpdated: unknown;
|
|
224
262
|
/** Built-in injection key for theme */
|
|
225
|
-
export declare const ThemeKey:
|
|
263
|
+
export declare const ThemeKey: InjectionKey<{
|
|
264
|
+
mode: 'light' | 'dark';
|
|
265
|
+
accent?: string;
|
|
266
|
+
}>;
|
|
226
267
|
/** Built-in injection key for router */
|
|
227
|
-
export declare const RouterKey:
|
|
228
|
-
|
|
229
|
-
|
|
268
|
+
export declare const RouterKey: InjectionKey<{
|
|
269
|
+
currentRoute: string;
|
|
270
|
+
navigate: (path: string) => void;
|
|
271
|
+
}>;
|
|
230
272
|
/** Built-in injection key for i18n */
|
|
231
|
-
export declare const I18nKey:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
value: T | null
|
|
236
|
-
readonly current: T | null
|
|
237
|
-
}
|
|
238
|
-
export declare interface ComponentInstance {
|
|
239
|
-
id: string
|
|
240
|
-
element: Element | null
|
|
241
|
-
mountHooks: LifecycleHook[]
|
|
242
|
-
destroyHooks: CleanupFn[]
|
|
243
|
-
updateHooks: LifecycleHook[]
|
|
244
|
-
refs: Map<string, Ref<any>>
|
|
245
|
-
watchers: Array<{ stop: () => void }>
|
|
246
|
-
isMounted: boolean
|
|
247
|
-
}
|
|
248
|
-
/* eslint-disable prefer-const, style/max-statements-per-line, no-super-linear-backtracking, regexp/no-unused-capturing-group */
|
|
249
|
-
/**
|
|
250
|
-
* STX Composables
|
|
251
|
-
*
|
|
252
|
-
* Vue-inspired composable utilities for STX components:
|
|
253
|
-
* - Lifecycle hooks (onMount, onDestroy, onUpdate)
|
|
254
|
-
* - Refs for DOM element references
|
|
255
|
-
* - Watch and computed for reactivity
|
|
256
|
-
*
|
|
257
|
-
* @module composables
|
|
258
|
-
*/
|
|
259
|
-
// =============================================================================
|
|
260
|
-
// Types
|
|
261
|
-
// =============================================================================
|
|
262
|
-
export type LifecycleHook = () => void | (() => void);
|
|
263
|
-
export type CleanupFn = () => void;
|
|
264
|
-
// eslint-disable-next-line pickier/no-unused-vars
|
|
265
|
-
export type WatchCallback<T> = (newValue: T, oldValue: T | undefined) => void | CleanupFn;
|
|
266
|
-
export type WatchSource<T> = () => T;
|
|
267
|
-
/** Symbol for injection keys */
|
|
268
|
-
export type InjectionKey<T> = symbol & { __type?: T }
|
|
269
|
-
// =============================================================================
|
|
270
|
-
// Export helpers for client-side usage
|
|
271
|
-
// =============================================================================
|
|
272
|
-
// Re-export for convenient importing
|
|
273
|
+
export declare const I18nKey: InjectionKey<{
|
|
274
|
+
locale: string;
|
|
275
|
+
t: (key: string) => string;
|
|
276
|
+
}>;
|
|
273
277
|
export { ref as createRef };
|
package/dist/computed.d.ts
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computed Properties Module
|
|
3
|
+
*
|
|
4
|
+
* Provides reactive computed values with automatic dependency tracking.
|
|
5
|
+
* Computed properties automatically update when their dependencies change,
|
|
6
|
+
* and are cached until dependencies are modified.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const firstName = ref('John')
|
|
11
|
+
* const lastName = ref('Doe')
|
|
12
|
+
*
|
|
13
|
+
* const fullName = computed(() => `${firstName.value} ${lastName.value}`)
|
|
14
|
+
*
|
|
15
|
+
* console.log(fullName.value) // 'John Doe'
|
|
16
|
+
* firstName.value = 'Jane'
|
|
17
|
+
* console.log(fullName.value) // 'Jane Doe'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export interface Ref<T> {
|
|
21
|
+
value: T;
|
|
22
|
+
/** Subscribe to value changes */
|
|
23
|
+
subscribe: (callback: (value: T) => void) => () => void;
|
|
24
|
+
/** Get raw value without tracking */
|
|
25
|
+
peek: () => T;
|
|
26
|
+
}
|
|
27
|
+
export interface ComputedRef<T> extends Ref<T> {
|
|
28
|
+
/** Force recalculation */
|
|
29
|
+
invalidate: () => void;
|
|
30
|
+
/** Check if value is dirty (needs recalculation) */
|
|
31
|
+
readonly dirty: boolean;
|
|
32
|
+
/** Get all dependencies */
|
|
33
|
+
readonly deps: Set<Ref<unknown>>;
|
|
34
|
+
}
|
|
35
|
+
export interface WritableComputedRef<T> extends ComputedRef<T> {
|
|
36
|
+
value: T;
|
|
37
|
+
}
|
|
38
|
+
export interface ComputedOptions<T> {
|
|
39
|
+
/** Getter function */
|
|
40
|
+
get: () => T;
|
|
41
|
+
/** Optional setter function */
|
|
42
|
+
set?: (value: T) => void;
|
|
43
|
+
/** Lazy evaluation (default: true) */
|
|
44
|
+
lazy?: boolean;
|
|
45
|
+
/** Custom equality check */
|
|
46
|
+
equals?: (a: T, b: T) => boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface WatchOptions {
|
|
49
|
+
/** Run immediately with current value */
|
|
50
|
+
immediate?: boolean;
|
|
51
|
+
/** Deep watch for object changes */
|
|
52
|
+
deep?: boolean;
|
|
53
|
+
/** Flush timing: 'pre' | 'post' | 'sync' */
|
|
54
|
+
flush?: 'pre' | 'post' | 'sync';
|
|
55
|
+
/** Stop watching after first change */
|
|
56
|
+
once?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface WatchStopHandle {
|
|
59
|
+
(): void;
|
|
60
|
+
pause: () => void;
|
|
61
|
+
resume: () => void;
|
|
62
|
+
}
|
|
1
63
|
/**
|
|
2
64
|
* Create a reactive reference
|
|
3
65
|
*/
|
|
@@ -13,7 +75,9 @@ export declare function unref<T>(value: T | Ref<T>): T;
|
|
|
13
75
|
/**
|
|
14
76
|
* Convert all properties of an object to refs
|
|
15
77
|
*/
|
|
16
|
-
export declare function toRefs<T extends object>(obj: T): {
|
|
78
|
+
export declare function toRefs<T extends object>(obj: T): {
|
|
79
|
+
[K in keyof T]: Ref<T[K]>;
|
|
80
|
+
};
|
|
17
81
|
/**
|
|
18
82
|
* Create a shallow reactive object
|
|
19
83
|
*/
|
|
@@ -22,7 +86,6 @@ export declare function shallowRef<T>(initialValue: T): Ref<T>;
|
|
|
22
86
|
* Create a computed property with automatic dependency tracking
|
|
23
87
|
*/
|
|
24
88
|
export declare function computed<T>(getter: () => T): ComputedRef<T>;
|
|
25
|
-
// eslint-disable-next-line pickier/no-unused-vars
|
|
26
89
|
export declare function computed<T>(options: ComputedOptions<T>): WritableComputedRef<T>;
|
|
27
90
|
/**
|
|
28
91
|
* Watch a reactive source and run a callback when it changes
|
|
@@ -31,10 +94,11 @@ export declare function watch<T>(source: Ref<T> | (() => T), callback: (newValue
|
|
|
31
94
|
/**
|
|
32
95
|
* Watch multiple sources
|
|
33
96
|
*/
|
|
34
|
-
export declare function watchMultiple<T extends readonly Ref<unknown>[]>(sources: [...T], callback: (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
97
|
+
export declare function watchMultiple<T extends readonly Ref<unknown>[]>(sources: [...T], callback: (newValues: {
|
|
98
|
+
[K in keyof T]: T[K] extends Ref<infer V> ? V : never;
|
|
99
|
+
}, oldValues: {
|
|
100
|
+
[K in keyof T]: T[K] extends Ref<infer V> ? V | undefined : never;
|
|
101
|
+
}) => void, options?: WatchOptions): WatchStopHandle;
|
|
38
102
|
/**
|
|
39
103
|
* Watch and run effect immediately, auto-tracking dependencies
|
|
40
104
|
*/
|
|
@@ -55,90 +119,20 @@ export declare function debouncedComputed<T>(getter: () => T, delay?: number): C
|
|
|
55
119
|
* Create a throttled computed
|
|
56
120
|
*/
|
|
57
121
|
export declare function throttledComputed<T>(getter: () => T, limit?: number): ComputedRef<T>;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* firstName.value = 'Jane'
|
|
74
|
-
* console.log(fullName.value) // 'Jane Doe'
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
// ============================================================================
|
|
78
|
-
// Types
|
|
79
|
-
// ============================================================================
|
|
80
|
-
export declare interface Ref<T> {
|
|
81
|
-
value: T
|
|
82
|
-
subscribe: (callback: (value: T) => void) => () => void
|
|
83
|
-
peek: () => T
|
|
84
|
-
}
|
|
85
|
-
export declare interface ComputedRef<T> extends Ref<T> {
|
|
86
|
-
invalidate: () => void
|
|
87
|
-
readonly dirty: boolean
|
|
88
|
-
readonly deps: Set<Ref<unknown>>
|
|
89
|
-
}
|
|
90
|
-
export declare interface WritableComputedRef<T> extends ComputedRef<T> {
|
|
91
|
-
value: T
|
|
92
|
-
}
|
|
93
|
-
export declare interface ComputedOptions<T> {
|
|
94
|
-
get: () => T
|
|
95
|
-
set?: (value: T) => void
|
|
96
|
-
lazy?: boolean
|
|
97
|
-
equals?: (a: T, b: T) => boolean
|
|
98
|
-
}
|
|
99
|
-
export declare interface WatchOptions {
|
|
100
|
-
immediate?: boolean
|
|
101
|
-
deep?: boolean
|
|
102
|
-
flush?: 'pre' | 'post' | 'sync'
|
|
103
|
-
once?: boolean
|
|
104
|
-
}
|
|
105
|
-
export declare interface WatchStopHandle {
|
|
106
|
-
(): void
|
|
107
|
-
pause: () => void
|
|
108
|
-
resume: () => void
|
|
109
|
-
}
|
|
110
|
-
// ============================================================================
|
|
111
|
-
// Aliased Exports (to avoid conflicts with other modules)
|
|
112
|
-
// ============================================================================
|
|
113
|
-
// Export with 'stx' prefix to avoid naming conflicts
|
|
114
|
-
export {
|
|
115
|
-
ref as stxRef,
|
|
116
|
-
computed as stxComputed,
|
|
117
|
-
watch as stxWatch,
|
|
118
|
-
watchMultiple as stxWatchMultiple,
|
|
119
|
-
watchEffect as stxWatchEffect,
|
|
120
|
-
isRef as stxIsRef,
|
|
121
|
-
unref as stxUnref,
|
|
122
|
-
toRefs as stxToRefs,
|
|
123
|
-
shallowRef as stxShallowRef,
|
|
124
|
-
debouncedComputed as stxDebouncedComputed,
|
|
125
|
-
throttledComputed as stxThrottledComputed,
|
|
126
|
-
};
|
|
127
|
-
// ============================================================================
|
|
128
|
-
// Exports
|
|
129
|
-
// ============================================================================
|
|
130
|
-
export default {
|
|
131
|
-
ref,
|
|
132
|
-
computed,
|
|
133
|
-
watch,
|
|
134
|
-
watchMultiple,
|
|
135
|
-
watchEffect,
|
|
136
|
-
isRef,
|
|
137
|
-
unref,
|
|
138
|
-
toRefs,
|
|
139
|
-
shallowRef,
|
|
140
|
-
debouncedComputed,
|
|
141
|
-
throttledComputed,
|
|
142
|
-
processComputedDirectives,
|
|
143
|
-
processWatchDirectives,
|
|
122
|
+
export { ref as stxRef, computed as stxComputed, watch as stxWatch, watchMultiple as stxWatchMultiple, watchEffect as stxWatchEffect, isRef as stxIsRef, unref as stxUnref, toRefs as stxToRefs, shallowRef as stxShallowRef, debouncedComputed as stxDebouncedComputed, throttledComputed as stxThrottledComputed, };
|
|
123
|
+
declare const _default: {
|
|
124
|
+
ref: typeof ref;
|
|
125
|
+
computed: typeof computed;
|
|
126
|
+
watch: typeof watch;
|
|
127
|
+
watchMultiple: typeof watchMultiple;
|
|
128
|
+
watchEffect: typeof watchEffect;
|
|
129
|
+
isRef: typeof isRef;
|
|
130
|
+
unref: typeof unref;
|
|
131
|
+
toRefs: typeof toRefs;
|
|
132
|
+
shallowRef: typeof shallowRef;
|
|
133
|
+
debouncedComputed: typeof debouncedComputed;
|
|
134
|
+
throttledComputed: typeof throttledComputed;
|
|
135
|
+
processComputedDirectives: typeof processComputedDirectives;
|
|
136
|
+
processWatchDirectives: typeof processWatchDirectives;
|
|
144
137
|
};
|
|
138
|
+
export default _default;
|
package/dist/conditionals.d.ts
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module for processing conditional directives (@if, @elseif, @else, @unless)
|
|
3
|
+
*
|
|
4
|
+
* Regex Pattern Reference:
|
|
5
|
+
* ========================
|
|
6
|
+
*
|
|
7
|
+
* NESTED_PARENS_PATTERN: `(?:[^()]|\([^()]*\))*`
|
|
8
|
+
* - Matches content with one level of nested parentheses
|
|
9
|
+
* - `[^()]` - Match any character except parentheses
|
|
10
|
+
* - `\([^()]*\)` - OR match balanced parentheses (one level deep)
|
|
11
|
+
* - Used in: @switch, @case, @if expressions to handle function calls
|
|
12
|
+
* - Example matches: `user.role`, `getRole()`, `check(a, b)`
|
|
13
|
+
* - Limitation: Only handles ONE level of nesting. `fn(a(b))` won't work correctly.
|
|
14
|
+
*
|
|
15
|
+
* DIRECTIVE_WITH_CONTENT: `@directive\s*\(EXPR\)([\s\S]*?)@enddirective`
|
|
16
|
+
* - `\s*` - Optional whitespace after directive name
|
|
17
|
+
* - `\(EXPR\)` - Parenthesized expression
|
|
18
|
+
* - `[\s\S]*?` - Non-greedy match of ANY content (including newlines)
|
|
19
|
+
* - `?` makes it non-greedy to match shortest possible content
|
|
20
|
+
*
|
|
21
|
+
* IF_ELSEIF_ELSE: Complex multi-branch matching
|
|
22
|
+
* - Processes from inside-out to handle nesting
|
|
23
|
+
* - Each @elseif/@else creates a branch in the condition chain
|
|
24
|
+
*/
|
|
1
25
|
/**
|
|
2
26
|
* Process switch statements (@switch, @case, @default)
|
|
3
27
|
*
|
|
@@ -7,14 +31,6 @@
|
|
|
7
31
|
* - @break directives
|
|
8
32
|
*/
|
|
9
33
|
export declare function processSwitchStatements(template: string, context: Record<string, any>, _filePath: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Process conditionals (@if, @elseif, @else, @unless)
|
|
12
|
-
*
|
|
13
|
-
* Uses the parser module for proper handling of:
|
|
14
|
-
* - Nested parentheses in conditions (e.g., @if(fn(a, fn(b))))
|
|
15
|
-
* - Nested @if blocks
|
|
16
|
-
* - Multiple @elseif branches
|
|
17
|
-
*/
|
|
18
34
|
export declare function processConditionals(template: string, context: Record<string, any>, filePath: string): string;
|
|
19
35
|
/**
|
|
20
36
|
* Process @auth and permissions directives
|
package/dist/conditionals.js
CHANGED
|
@@ -69,7 +69,23 @@ export function processSwitchStatements(template, context, _filePath) {
|
|
|
69
69
|
}
|
|
70
70
|
return output;
|
|
71
71
|
}
|
|
72
|
+
function maskScripts(template) {
|
|
73
|
+
const scripts = [];
|
|
74
|
+
return { masked: template.replace(/<script\b[\s\S]*?<\/script\s*>/gi, (match) => {
|
|
75
|
+
scripts.push(match);
|
|
76
|
+
return `\x00stx-script-${scripts.length - 1}\x00`;
|
|
77
|
+
}), scripts };
|
|
78
|
+
}
|
|
79
|
+
function restoreScripts(output, scripts) {
|
|
80
|
+
if (scripts.length === 0)
|
|
81
|
+
return output;
|
|
82
|
+
return output.replace(/\u0000stx-script-(\d+)\u0000/g, (match, index) => scripts[Number(index)] ?? match);
|
|
83
|
+
}
|
|
72
84
|
export function processConditionals(template, context, filePath) {
|
|
85
|
+
const { masked, scripts } = maskScripts(template);
|
|
86
|
+
return restoreScripts(processConditionalsIn(masked, context, filePath), scripts);
|
|
87
|
+
}
|
|
88
|
+
function processConditionalsIn(template, context, filePath) {
|
|
73
89
|
let output = template;
|
|
74
90
|
output = processSwitchStatements(output, context, filePath);
|
|
75
91
|
{
|