@deijose/nix-js 0.1.5 → 0.2.1
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/README.md +68 -0
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/nix/form.d.ts +258 -0
- package/dist/lib/nix/index.d.ts +3 -0
- package/dist/lib/nix/lifecycle.d.ts +54 -0
- package/dist/lib/nix-js.cjs +7 -7
- package/dist/lib/nix-js.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,6 +105,74 @@ const App = () => html`
|
|
|
105
105
|
`;
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
### Forms
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { createForm, required, email, minLength, min } from "@deijose/nix-js";
|
|
112
|
+
|
|
113
|
+
const form = createForm(
|
|
114
|
+
{ name: "", email: "", age: 0 },
|
|
115
|
+
{
|
|
116
|
+
validators: {
|
|
117
|
+
name: [required(), minLength(2)],
|
|
118
|
+
email: [required(), email()],
|
|
119
|
+
age: [required(), min(18)],
|
|
120
|
+
},
|
|
121
|
+
// Optional: plug in Zod, Valibot, Yup, or any schema library
|
|
122
|
+
validate(values) {
|
|
123
|
+
const r = zodSchema.safeParse(values);
|
|
124
|
+
if (r.success) return null;
|
|
125
|
+
return Object.fromEntries(
|
|
126
|
+
Object.entries(r.error.flatten().fieldErrors).map(([k, v]) => [k, v?.[0]])
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
html`
|
|
133
|
+
<form @submit=${form.handleSubmit(onSubmit)}>
|
|
134
|
+
<input value=${() => form.fields.name.value.value}
|
|
135
|
+
@input=${form.fields.name.onInput}
|
|
136
|
+
@blur=${form.fields.name.onBlur} />
|
|
137
|
+
${() => form.fields.name.error.value
|
|
138
|
+
? html`<p class="err">${form.fields.name.error.value}</p>`
|
|
139
|
+
: null}
|
|
140
|
+
<button type="submit">Submit</button>
|
|
141
|
+
</form>
|
|
142
|
+
`
|
|
143
|
+
|
|
144
|
+
// Inject server errors after a failed API call:
|
|
145
|
+
form.setErrors({ email: "Email already in use" });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Children & slots
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import type { NixChildren } from "@deijose/nix-js";
|
|
152
|
+
|
|
153
|
+
class Card extends NixComponent {
|
|
154
|
+
render() {
|
|
155
|
+
return html`
|
|
156
|
+
<div class="card">
|
|
157
|
+
<header>${this.slot("header")}</header>
|
|
158
|
+
<main>${this.children}</main>
|
|
159
|
+
<footer>${this.slot("footer") ?? html`<small>Footer</small>`}</footer>
|
|
160
|
+
</div>
|
|
161
|
+
`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const app = new Card()
|
|
166
|
+
.setSlot("header", html`<h1>Título</h1>`)
|
|
167
|
+
.setChildren(html`<p>Cuerpo del card</p>`)
|
|
168
|
+
.setSlot("footer", html`<small>© 2026</small>`);
|
|
169
|
+
|
|
170
|
+
// Function component style:
|
|
171
|
+
function Box({ children }: { children?: NixChildren }) {
|
|
172
|
+
return html`<div class="box">${children}</div>`;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
108
176
|
### Dependency injection
|
|
109
177
|
|
|
110
178
|
```typescript
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, mount, NixComponent, createStore, createRouter, RouterView, Link, useRouter, suspend, lazy, provide, inject, createInjectionKey, } from "./nix";
|
|
2
|
-
export type { WatchOptions, NixTemplate, NixMountHandle, KeyedList, NixRef, Store, StoreSignals, Router, RouteRecord, SuspenseOptions, InjectionKey, } from "./nix";
|
|
1
|
+
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, mount, NixComponent, createStore, createRouter, RouterView, Link, useRouter, suspend, lazy, provide, inject, createInjectionKey, useField, createForm, required, minLength, maxLength, email, pattern, min, max, createValidator, validators, extendValidators, } from "./nix";
|
|
2
|
+
export type { WatchOptions, NixTemplate, NixMountHandle, KeyedList, NixRef, Store, StoreSignals, Router, RouteRecord, SuspenseOptions, InjectionKey, Validator, FieldState, FieldErrors, FormState, FormOptions, ValidatorsBase, NixChildren, } from "./nix";
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { Signal } from "./reactivity";
|
|
2
|
+
/** A validator function. Return an error string, or null/undefined if valid. */
|
|
3
|
+
export type Validator<T> = (value: T) => string | null | undefined;
|
|
4
|
+
export declare function required(message?: string): Validator<unknown>;
|
|
5
|
+
export declare function minLength(n: number, message?: string): Validator<string>;
|
|
6
|
+
export declare function maxLength(n: number, message?: string): Validator<string>;
|
|
7
|
+
export declare function pattern(regex: RegExp, message?: string): Validator<string>;
|
|
8
|
+
export declare function email(message?: string): Validator<string>;
|
|
9
|
+
export declare function min(n: number, message?: string): Validator<number>;
|
|
10
|
+
export declare function max(n: number, message?: string): Validator<number>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a typed custom validator, fully compatible with `useField` and
|
|
13
|
+
* `createForm`. The preferred way to define your own rules without importing
|
|
14
|
+
* the `Validator<T>` type manually.
|
|
15
|
+
*
|
|
16
|
+
* @example Simple rule
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const noSpaces = createValidator<string>((v) =>
|
|
19
|
+
* v.includes(" ") ? "No spaces allowed" : null
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* useField("", [noSpaces]);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Configurable rule (same pattern as built-ins)
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const phone = (msg = "Invalid phone number") =>
|
|
28
|
+
* createValidator<string>((v) =>
|
|
29
|
+
* /^\+?\d{7,15}$/.test(v) ? null : msg
|
|
30
|
+
* );
|
|
31
|
+
*
|
|
32
|
+
* useField("", [phone()]);
|
|
33
|
+
* useField("", [phone("Enter your mobile number")]);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function createValidator<T>(fn: (value: T) => string | null | undefined): Validator<T>;
|
|
37
|
+
/**
|
|
38
|
+
* All built-in validators grouped as a namespace object.
|
|
39
|
+
*
|
|
40
|
+
* Use this when you prefer `validators.required()` over individual named
|
|
41
|
+
* imports. Combine with `extendValidators` to add your own rules.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { validators } from "@deijose/nix-js";
|
|
46
|
+
*
|
|
47
|
+
* createForm(
|
|
48
|
+
* { name: "", email: "", age: 0 },
|
|
49
|
+
* {
|
|
50
|
+
* validators: {
|
|
51
|
+
* name: [validators.required(), validators.minLength(2)],
|
|
52
|
+
* email: [validators.required(), validators.email()],
|
|
53
|
+
* age: [validators.required(), validators.min(18)],
|
|
54
|
+
* },
|
|
55
|
+
* }
|
|
56
|
+
* );
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const validators: {
|
|
60
|
+
readonly required: typeof required;
|
|
61
|
+
readonly minLength: typeof minLength;
|
|
62
|
+
readonly maxLength: typeof maxLength;
|
|
63
|
+
readonly email: typeof email;
|
|
64
|
+
readonly pattern: typeof pattern;
|
|
65
|
+
readonly min: typeof min;
|
|
66
|
+
readonly max: typeof max;
|
|
67
|
+
};
|
|
68
|
+
/** Shape of the built-in `validators` namespace. Used as the base type for `extendValidators`. */
|
|
69
|
+
export type ValidatorsBase = typeof validators;
|
|
70
|
+
/**
|
|
71
|
+
* Merges your own validator factories into the `validators` namespace, returning
|
|
72
|
+
* a fully typed object that includes both built-ins and custom rules.
|
|
73
|
+
*
|
|
74
|
+
* The original `validators` object is **never mutated** — a new object is returned.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* import { validators, extendValidators, createValidator } from "@deijose/nix-js";
|
|
79
|
+
*
|
|
80
|
+
* const myValidators = extendValidators(validators, {
|
|
81
|
+
* // Configurable rule (custom message support)
|
|
82
|
+
* phone: (msg = "Invalid phone number") =>
|
|
83
|
+
* createValidator<string>((v) => /^\+?\d{7,15}$/.test(v) ? null : msg),
|
|
84
|
+
*
|
|
85
|
+
* // Rule reusing a built-in internally
|
|
86
|
+
* slug: (msg = "Only lowercase letters, numbers and hyphens") =>
|
|
87
|
+
* createValidator<string>((v) =>
|
|
88
|
+
* /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(v) ? null : msg
|
|
89
|
+
* ),
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // IDE auto-complete covers built-ins and custom rules alike:
|
|
93
|
+
* myValidators.required() // ✅ built-in
|
|
94
|
+
* myValidators.email() // ✅ built-in
|
|
95
|
+
* myValidators.phone() // ✅ custom
|
|
96
|
+
* myValidators.slug("Bad slug") // ✅ custom, custom message
|
|
97
|
+
*
|
|
98
|
+
* // Use in a form like any other validators:
|
|
99
|
+
* createForm(
|
|
100
|
+
* { phone: "", slug: "" },
|
|
101
|
+
* {
|
|
102
|
+
* validators: {
|
|
103
|
+
* phone: [myValidators.required(), myValidators.phone()],
|
|
104
|
+
* slug: [myValidators.required(), myValidators.slug()],
|
|
105
|
+
* },
|
|
106
|
+
* }
|
|
107
|
+
* );
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param base The base validators namespace (pass `validators`).
|
|
111
|
+
* @param extensions An object whose values are validator factory functions.
|
|
112
|
+
* @returns A new merged namespace object.
|
|
113
|
+
*/
|
|
114
|
+
export declare function extendValidators<E extends Record<string, (...args: any[]) => Validator<any>>>(base: ValidatorsBase, extensions: E): ValidatorsBase & E;
|
|
115
|
+
/** Public state of a single form field. */
|
|
116
|
+
export interface FieldState<T> {
|
|
117
|
+
/** Current value — read/write signal. */
|
|
118
|
+
value: Signal<T>;
|
|
119
|
+
/**
|
|
120
|
+
* Current error message, or null.
|
|
121
|
+
* Only non-null after the field has been touched (blur) or dirtied (input).
|
|
122
|
+
*/
|
|
123
|
+
readonly error: Signal<string | null>;
|
|
124
|
+
/** True after the input has lost focus at least once. */
|
|
125
|
+
touched: Signal<boolean>;
|
|
126
|
+
/** True after the user has typed at least once. */
|
|
127
|
+
dirty: Signal<boolean>;
|
|
128
|
+
/** Attach to `@input` on any `<input>`, `<select>`, `<textarea>`. */
|
|
129
|
+
readonly onInput: (e: Event) => void;
|
|
130
|
+
/** Attach to `@blur`. */
|
|
131
|
+
readonly onBlur: () => void;
|
|
132
|
+
/** Reset to initial value and clear touched/dirty/error state. */
|
|
133
|
+
reset(): void;
|
|
134
|
+
/**
|
|
135
|
+
* @internal — inject an external error message (server / schema validator).
|
|
136
|
+
* The error clears automatically when the user next edits the field.
|
|
137
|
+
*/
|
|
138
|
+
_setExternalError(msg: string | null): void;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Creates a standalone reactive form field with optional validators.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const name = useField("", [required(), minLength(2)]);
|
|
145
|
+
*
|
|
146
|
+
* html`
|
|
147
|
+
* <input value=${() => name.value.value}
|
|
148
|
+
* @input=${name.onInput}
|
|
149
|
+
* @blur=${name.onBlur} />
|
|
150
|
+
* ${() => name.error.value
|
|
151
|
+
* ? html`<p class="err">${name.error.value}</p>`
|
|
152
|
+
* : null}
|
|
153
|
+
* `
|
|
154
|
+
*/
|
|
155
|
+
export declare function useField<T>(initialValue: T, validators?: Validator<T>[]): FieldState<T>;
|
|
156
|
+
/** Map of field-name → error message for external validation results. */
|
|
157
|
+
export type FieldErrors<T extends Record<string, unknown>> = {
|
|
158
|
+
[K in keyof T]?: string | null;
|
|
159
|
+
};
|
|
160
|
+
export interface FormState<T extends Record<string, unknown>> {
|
|
161
|
+
/** Individual field states — access value, error, event handlers. */
|
|
162
|
+
fields: {
|
|
163
|
+
[K in keyof T]: FieldState<T[K]>;
|
|
164
|
+
};
|
|
165
|
+
/** Computed snapshot of all current field values. */
|
|
166
|
+
readonly values: Signal<T>;
|
|
167
|
+
/** Computed map of all currently visible field errors. */
|
|
168
|
+
readonly errors: Signal<FieldErrors<T>>;
|
|
169
|
+
/** True when no field has a visible error (meaningful after submit / touch-all). */
|
|
170
|
+
readonly valid: Signal<boolean>;
|
|
171
|
+
/** True when at least one field has been modified. */
|
|
172
|
+
readonly dirty: Signal<boolean>;
|
|
173
|
+
/**
|
|
174
|
+
* Wraps a submit callback. Returned handler:
|
|
175
|
+
* 1. Calls `e.preventDefault()`
|
|
176
|
+
* 2. Touches all fields (revealing validation errors)
|
|
177
|
+
* 3. Runs `options.validate` if provided (Zod, etc.)
|
|
178
|
+
* 4. Only calls `fn(values)` if all validations pass
|
|
179
|
+
*/
|
|
180
|
+
handleSubmit(fn: (values: T) => void | Promise<void>): (e: Event) => void;
|
|
181
|
+
/** Reset all fields to their initial values. */
|
|
182
|
+
reset(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Inject external errors (e.g., from a server response) into specific fields.
|
|
185
|
+
* Each field's error clears automatically the next time the user edits it.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* form.setErrors({ email: "Email already in use" });
|
|
189
|
+
*/
|
|
190
|
+
setErrors(errors: FieldErrors<T>): void;
|
|
191
|
+
}
|
|
192
|
+
export interface FormOptions<T extends Record<string, unknown>> {
|
|
193
|
+
/** Per-field built-in validators. */
|
|
194
|
+
validators?: {
|
|
195
|
+
[K in keyof T]?: Validator<T[K]>[];
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Optional schema-level validator — runs on submit after built-in validators pass.
|
|
199
|
+
* Return `null` / `undefined` if valid, or a field→error map if not.
|
|
200
|
+
* String arrays are accepted (first element shown per field).
|
|
201
|
+
*
|
|
202
|
+
* @example Zod interop
|
|
203
|
+
* ```typescript
|
|
204
|
+
* validate(values) {
|
|
205
|
+
* const r = schema.safeParse(values);
|
|
206
|
+
* if (r.success) return null;
|
|
207
|
+
* return Object.fromEntries(
|
|
208
|
+
* Object.entries(r.error.flatten().fieldErrors)
|
|
209
|
+
* .map(([k, v]) => [k, v?.[0]])
|
|
210
|
+
* );
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @example Valibot interop
|
|
215
|
+
* ```typescript
|
|
216
|
+
* validate(values) {
|
|
217
|
+
* const r = safeParse(schema, values);
|
|
218
|
+
* if (r.success) return null;
|
|
219
|
+
* const errs: Record<string, string> = {};
|
|
220
|
+
* for (const issue of r.issues)
|
|
221
|
+
* if (issue.path?.[0]?.key) errs[issue.path[0].key as string] = issue.message;
|
|
222
|
+
* return errs;
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
validate?: (values: T) => {
|
|
227
|
+
[K in keyof T]?: string | string[] | null | undefined;
|
|
228
|
+
} | null | undefined;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Creates a managed form with reactive fields, built-in validation,
|
|
232
|
+
* schema-level validation (Zod / Valibot / Yup / custom), and submit handling.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* const form = createForm(
|
|
236
|
+
* { name: "", email: "", age: 0 },
|
|
237
|
+
* {
|
|
238
|
+
* validators: {
|
|
239
|
+
* name: [required(), minLength(2)],
|
|
240
|
+
* email: [required(), email()],
|
|
241
|
+
* age: [required(), min(18)],
|
|
242
|
+
* },
|
|
243
|
+
* }
|
|
244
|
+
* );
|
|
245
|
+
*
|
|
246
|
+
* html`
|
|
247
|
+
* <form @submit=${form.handleSubmit(onSubmit)}>
|
|
248
|
+
* <input value=${() => form.fields.name.value.value}
|
|
249
|
+
* @input=${form.fields.name.onInput}
|
|
250
|
+
* @blur=${form.fields.name.onBlur} />
|
|
251
|
+
* ${() => form.fields.name.error.value
|
|
252
|
+
* ? html`<p class="err">${form.fields.name.error.value}</p>`
|
|
253
|
+
* : null}
|
|
254
|
+
* <button type="submit">Submit</button>
|
|
255
|
+
* </form>
|
|
256
|
+
* `
|
|
257
|
+
*/
|
|
258
|
+
export declare function createForm<T extends Record<string, unknown>>(initialValues: T, options?: FormOptions<T>): FormState<T>;
|
package/dist/lib/nix/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { html, repeat, ref } from "./template";
|
|
|
4
4
|
export type { NixTemplate, NixMountHandle, KeyedList, NixRef } from "./template";
|
|
5
5
|
export { mount } from "./component";
|
|
6
6
|
export { NixComponent } from "./lifecycle";
|
|
7
|
+
export type { NixChildren } from "./lifecycle";
|
|
7
8
|
export { createStore } from "./store";
|
|
8
9
|
export type { Store, StoreSignals } from "./store";
|
|
9
10
|
export { createRouter, RouterView, Link, useRouter } from "./router";
|
|
@@ -12,3 +13,5 @@ export { suspend, lazy } from "./async";
|
|
|
12
13
|
export type { SuspenseOptions } from "./async";
|
|
13
14
|
export { provide, inject, createInjectionKey } from "./context";
|
|
14
15
|
export type { InjectionKey } from "./context";
|
|
16
|
+
export { useField, createForm, required, minLength, maxLength, email, pattern, min, max, createValidator, validators, extendValidators, } from "./form";
|
|
17
|
+
export type { Validator, FieldState, FieldErrors, FormState, FormOptions, ValidatorsBase } from "./form";
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { NixTemplate } from "./template";
|
|
2
|
+
/**
|
|
3
|
+
* Tipos válidos para pasar como children a un componente.
|
|
4
|
+
* Acepta un template, un componente, arrays de ellos, o nada.
|
|
5
|
+
*/
|
|
6
|
+
export type NixChildren = NixTemplate | NixComponent | Array<NixTemplate | NixComponent> | null | undefined;
|
|
2
7
|
/**
|
|
3
8
|
* Clase base para componentes con lifecycle.
|
|
4
9
|
*
|
|
@@ -23,6 +28,55 @@ import type { NixTemplate } from "./template";
|
|
|
23
28
|
export declare abstract class NixComponent {
|
|
24
29
|
/** @internal – marca que identifica instancias NixComponent en el engine. */
|
|
25
30
|
readonly __isNixComponent: true;
|
|
31
|
+
/**
|
|
32
|
+
* Slot por defecto — contenido hijo que el componente padre inyecta.
|
|
33
|
+
*
|
|
34
|
+
* Úsalo en `render()` como cualquier valor interpolado:
|
|
35
|
+
* ```typescript
|
|
36
|
+
* render() {
|
|
37
|
+
* return html`<div class="card">${this.children}</div>`;
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
* Se puede asignar directamente o con el método fluido `setChildren()`.
|
|
41
|
+
*/
|
|
42
|
+
children?: NixChildren;
|
|
43
|
+
/** @internal */
|
|
44
|
+
private _slots;
|
|
45
|
+
/**
|
|
46
|
+
* Asigna el slot por defecto. Versión fluida de `this.children = content`.
|
|
47
|
+
* @returns `this` para encadenar con `setSlot()`.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* html`${new Card().setChildren(html`<p>Body</p>`)}`
|
|
51
|
+
*/
|
|
52
|
+
setChildren(content: NixChildren): this;
|
|
53
|
+
/**
|
|
54
|
+
* Asigna un slot con nombre. El componente lo lee con `this.slot(name)`.
|
|
55
|
+
* @returns `this` para encadenar.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* new Card()
|
|
59
|
+
* .setSlot("header", html`<h1>Título</h1>`)
|
|
60
|
+
* .setSlot("footer", html`<small>Footer</small>`)
|
|
61
|
+
* .setChildren(html`<p>Cuerpo</p>`)
|
|
62
|
+
*/
|
|
63
|
+
setSlot(name: string, content: NixChildren): this;
|
|
64
|
+
/**
|
|
65
|
+
* Obtiene el contenido de un slot con nombre.
|
|
66
|
+
* Úsalo dentro de `render()`:
|
|
67
|
+
* ```typescript
|
|
68
|
+
* render() {
|
|
69
|
+
* return html`
|
|
70
|
+
* <div>
|
|
71
|
+
* <header>${this.slot("header")}</header>
|
|
72
|
+
* <main>${this.children}</main>
|
|
73
|
+
* <footer>${this.slot("footer")}</footer>
|
|
74
|
+
* </div>
|
|
75
|
+
* `;
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
slot(name: string): NixChildren;
|
|
26
80
|
/**
|
|
27
81
|
* Debe implementarse: retorna el template del componente.
|
|
28
82
|
* Se llama UNA sola vez al montar — las actualizaciones ocurren por signals.
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return e&&(this._subs.add(e),n?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=[...this._subs];i>0?e.forEach(e=>a.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function s(e){return new o(e)}function c(o){let l,i=new Set,a=()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i=new Set,t.push(e),r.push(n),e=a,n=i;try{l=o()}finally{e=t.pop()||null,n=r.pop()||null}};return a(),()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i.clear()}}function l(e){let t=new o(void 0);return c(()=>{t.value=e()}),t}function u(e){i++;try{e()}finally{if(0===--i){let e=[...a];a.clear(),e.forEach(e=>e())}}}function d(t){let r=e,o=n;e=null,n=null;try{return t()}finally{e=r,n=o}}function f(e,t,n={}){let r,{immediate:l=!1,once:i=!1}=n,a=e instanceof o?()=>e.value:e,s=!0,u=!1,f=c(()=>{let e=a();if(s){if(s=!1,l&&!u){let n=e;d(()=>t(n,void 0)),i&&(u=!0,Promise.resolve().then(f))}r=e}else if(!u){let n=e,o=r;r=e,d(()=>t(n,o)),i&&(u=!0,Promise.resolve().then(f))}});return()=>{u=!0,f()}}function p(e){return e?Promise.resolve().then(e):Promise.resolve()}var m=class{__isNixComponent=!0};function h(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function g(e){return Symbol(e)}var _=[];function v(){return[..._]}function y(){_.push(new Map)}function b(){_.pop()}function x(e,t){let n=_.splice(0);e.forEach(e=>_.push(e)),_.push(new Map);try{return t()}finally{_.splice(0),n.forEach(e=>_.push(e))}}function S(e,t){let n=_[_.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function C(e){for(let t=_.length-1;t>=0;t--)if(_[t].has(e))return _[t].get(e)}function w(){return{el:null}}function T(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function E(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function D(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function O(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function k(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function A(e){let t,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;t=r.nextNode();){let e=t,r=e.nodeValue?.match(/^nix-(\d+)$/);r&&n.set(parseInt(r[1]),e)}return n}function j(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function M(e,t,n){let r=[],o=[],l=A(e),i=j(e);for(let e=0;e<t.length;e++){let a=t[e],s=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=s,u=a.modifiers,c={};u.includes("once")&&(c.once=!0),u.includes("capture")&&(c.capture=!0),u.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(u.includes("prevent")&&e.preventDefault(),u.includes("stop")&&e.stopPropagation(),!u.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of u){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){s.el=n,r.push(()=>{s.el=null});continue}if("function"==typeof s){let e=c(()=>{let e=s();null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else null!=s&&!1!==s&&n.setAttribute(o,String(s));continue}let u=l.get(e);if(!u)continue;if("function"!=typeof s){if(h(s)){let e,n,l=s;y();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(u.parentNode,u)}finally{b()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(O(s))s._render(u.parentNode,u);else if(Array.isArray(s))for(let e of s)if(h(e)){let n,l;y();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(u.parentNode,u)}finally{b()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else O(e)?e._render(u.parentNode,u):null!=e&&!1!==e&&u.parentNode.insertBefore(document.createTextNode(String(e)),u);else null!=s&&!1!==s&&u.parentNode.insertBefore(document.createTextNode(String(s)),u);continue}let f=null,d=null,p=null,m=v(),g=c(()=>{let e=s();if("string"==typeof e||"number"==typeof e)return d&&=(d(),null),void(f?f.nodeValue=String(e):(f=document.createTextNode(String(e)),u.parentNode.insertBefore(f,u)));if(f&&=(f.parentNode?.removeChild(f),null),d&&=(d(),null),null!=e&&!1!==e)if(O(e))d=e._render(u.parentNode,u);else if(h(e)){let t,n,r=e;x(m,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(u.parentNode,u)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}d=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(k(e)){p||=new Map;let t=u.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n);for(let[e,n]of p)if(!r.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),p.delete(e)}let o=u;for(let r=n.length-1;r>=0;r--){let l=n[r],i=e.items[r];if(p.has(l)){let e=p.get(l);if(e.end.nextSibling!==o){let n=[],r=e.start;for(;n.push(r),r!==e.end;)r=r.nextSibling;for(let e of n)t.insertBefore(e,o)}o=e.start}else{let n=document.createComment("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let s,u=e.renderFn(i,r);if(h(u)){let r,o;x(m,()=>{try{u.onInit?.()}catch(e){if(!u.onError)throw e;u.onError(e)}r=u.render()._render(t,n)});try{let e=u.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!u.onError)throw e;u.onError(e)}s=()=>{try{u.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else s=u._render(t,n);p.set(l,{start:a,end:n,cleanup:s}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(h(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(u.parentNode,u);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(O(n))t.push(n._render(u.parentNode,u));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));u.parentNode.insertBefore(e,u),t.push(()=>e.parentNode?.removeChild(e))}d=()=>t.forEach(e=>e())}else f=document.createTextNode(String(e)),u.parentNode.insertBefore(f,u)});r.push(()=>{if(g(),d&&=(d(),null),f&&=(f.parentNode?.removeChild(f),null),p){for(let e of p.values())e.cleanup();p=null}})}return{disposes:r,postMountHooks:o}}function N(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=E(r);n.push(o),r+="__nix__"}let o=D(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:s}=M(i,n,t),u=document.createComment("nix-scope");e.insertBefore(u,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return s.forEach(e=>e()),()=>{a.forEach(e=>e());let e=u.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}u.parentNode?.removeChild(u)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function P(e,t){if(h(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);y();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{b()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function F(e,t){let n={};for(let t of Object.keys(e))n[t]=s(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);Object.assign(o,e)}return o}var I=null;function L(){if(!I)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return I}function R(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function z(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function B(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function V(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function H(e,t="",n=[]){let r=[];for(let o of e){let e=V(t,o.path),l=[...n,o.component],i=B(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...H(o.children,e,l))}return r}function U(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else"param"===t.kind&&(i[t.name]=decodeURIComponent(n[e]??""))}return i}function W(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function G(e,t){let n,r={},o=-1;for(let l of t){let t=U(e,l);if(null===t)continue;let i=W(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function K(e){function t(){return window.location.pathname||"/"}let n=t(),r=H(e),o=G(n,r),l=s(n),i=s(o?.params??{}),a=s(R(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=G(e,r)?.params??{},a.value=R(window.location.search),l.value=e});let u={current:l,params:i,query:a,navigate:function(e,t){let n=e.indexOf("?"),o=-1===n?e:e.slice(0,n),s=-1===n?{}:R(e.slice(n)),u=t?{...s,...t}:s,c={};for(let[e,t]of Object.entries(u))null!=t&&!1!==t&&(c[e]=String(t));i.value=G(o,r)?.params??{},a.value=c,l.value=o;let f=o+z(c);history.pushState(null,"",f)},routes:e,_flat:r};return I=u,u}function q(){return L()}var J=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return N`<div class="router-view">${()=>{let t=L(),n=G(t.current.value,t._flat);return n?e>=n.route.chain.length?N`<span></span>`:n.route.chain[e]():N`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return e&&(this._subs.add(e),n?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=[...this._subs];i>0?e.forEach(e=>a.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function s(e){return new o(e)}function c(o){let l,i=new Set,a=()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i=new Set,t.push(e),r.push(n),e=a,n=i;try{l=o()}finally{e=t.pop()||null,n=r.pop()||null}};return a(),()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i.clear()}}function l(e){let t=new o(void 0);return c(()=>{t.value=e()}),t}function u(e){i++;try{e()}finally{if(0===--i){let e=[...a];a.clear(),e.forEach(e=>e())}}}function d(t){let r=e,o=n;e=null,n=null;try{return t()}finally{e=r,n=o}}function f(e,t,n={}){let r,{immediate:l=!1,once:i=!1}=n,a=e instanceof o?()=>e.value:e,u=!0,s=!1,f=c(()=>{let e=a();if(u){if(u=!1,l&&!s){let n=e;d(()=>t(n,void 0)),i&&(s=!0,Promise.resolve().then(f))}r=e}else if(!s){let n=e,o=r;r=e,d(()=>t(n,o)),i&&(s=!0,Promise.resolve().then(f))}});return()=>{s=!0,f()}}function p(e){return e?Promise.resolve().then(e):Promise.resolve()}var m=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function h(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function g(e){return Symbol(e)}var _=[];function v(){return[..._]}function y(){_.push(new Map)}function b(){_.pop()}function x(e,t){let n=_.splice(0);e.forEach(e=>_.push(e)),_.push(new Map);try{return t()}finally{_.splice(0),n.forEach(e=>_.push(e))}}function ee(e,t){let n=_[_.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function te(e){for(let t=_.length-1;t>=0;t--)if(_[t].has(e))return _[t].get(e)}function ne(){return{el:null}}function S(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function C(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function w(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function T(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function E(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function D(e){let t,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;t=r.nextNode();){let e=t,r=e.nodeValue?.match(/^nix-(\d+)$/);r&&n.set(parseInt(r[1]),e)}return n}function re(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function ie(e,t,n){let r=[],o=[],l=D(e),i=re(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){u.el=n,r.push(()=>{u.el=null});continue}let l=("value"===o||"checked"===o||"selected"===o)&&o in n;if("function"==typeof u){let e=c(()=>{let e=u();l?n[o]=e??"":null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else l?n[o]=u??"":null!=u&&!1!==u&&n.setAttribute(o,String(u));continue}let s=l.get(e);if(!s)continue;if("function"!=typeof u){if(h(u)){let e,n,l=u;y();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{b()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(T(u))u._render(s.parentNode,s);else if(Array.isArray(u))for(let e of u)if(h(e)){let n,l;y();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{b()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else T(e)?e._render(s.parentNode,s):null!=e&&!1!==e&&s.parentNode.insertBefore(document.createTextNode(String(e)),s);else null!=u&&!1!==u&&s.parentNode.insertBefore(document.createTextNode(String(u)),s);continue}let f=null,d=null,p=null,m=v(),g=c(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return d&&=(d(),null),void(f?f.nodeValue=String(e):(f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)));if(f&&=(f.parentNode?.removeChild(f),null),d&&=(d(),null),null!=e&&!1!==e)if(T(e))d=e._render(s.parentNode,s);else if(h(e)){let t,n,r=e;x(m,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}d=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(E(e)){p||=new Map;let t=s.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n);for(let[e,n]of p)if(!r.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),p.delete(e)}let o=s;for(let r=n.length-1;r>=0;r--){let l=n[r],i=e.items[r];if(p.has(l)){let e=p.get(l);if(e.end.nextSibling!==o){let n=[],r=e.start;for(;n.push(r),r!==e.end;)r=r.nextSibling;for(let e of n)t.insertBefore(e,o)}o=e.start}else{let n=document.createComment("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(h(s)){let r,o;x(m,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else u=s._render(t,n);p.set(l,{start:a,end:n,cleanup:u}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(h(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(T(n))t.push(n._render(s.parentNode,s));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));s.parentNode.insertBefore(e,s),t.push(()=>e.parentNode?.removeChild(e))}d=()=>t.forEach(e=>e())}else f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)});r.push(()=>{if(g(),d&&=(d(),null),f&&=(f.parentNode?.removeChild(f),null),p){for(let e of p.values())e.cleanup();p=null}})}return{disposes:r,postMountHooks:o}}function O(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=C(r);n.push(o),r+="__nix__"}let o=w(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=ie(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function ae(e,t){if(h(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);y();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{b()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function oe(e,t){let n={};for(let t of Object.keys(e))n[t]=s(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);Object.assign(o,e)}return o}var k=null;function A(){if(!k)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return k}function j(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function M(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function N(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function P(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function F(e,t="",n=[]){let r=[];for(let o of e){let e=P(t,o.path),l=[...n,o.component],i=N(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...F(o.children,e,l))}return r}function I(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else"param"===t.kind&&(i[t.name]=decodeURIComponent(n[e]??""))}return i}function L(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function R(e,t){let n,r={},o=-1;for(let l of t){let t=I(e,l);if(null===t)continue;let i=L(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function z(e){function t(){return window.location.pathname||"/"}let n=t(),r=F(e),o=R(n,r),l=s(n),i=s(o?.params??{}),a=s(j(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=R(e,r)?.params??{},a.value=j(window.location.search),l.value=e});let u={current:l,params:i,query:a,navigate:function(e,t){let n=e.indexOf("?"),o=-1===n?e:e.slice(0,n),u=-1===n?{}:j(e.slice(n)),s=t?{...u,...t}:u,c={};for(let[e,t]of Object.entries(s))null!=t&&!1!==t&&(c[e]=String(t));i.value=R(o,r)?.params??{},a.value=c,l.value=o;let f=o+M(c);history.pushState(null,"",f)},routes:e,_flat:r};return k=u,u}function B(){return A()}var V=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return O`<div class="router-view">${()=>{let t=A(),n=R(t.current.value,t._flat);return n?e>=n.route.chain.length?O`<span></span>`:n.route.chain[e]():O`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Ruta no encontrada: <strong>${t.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
3
|
+
</div>`}}</div>`}},H=class extends m{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to;return O`<a
|
|
4
4
|
href=${e}
|
|
5
|
-
style=${()=>
|
|
6
|
-
@click=${t=>{t.preventDefault(),
|
|
7
|
-
>${this._label}</a>`}};function
|
|
5
|
+
style=${()=>A().current.value===e?"color:#38bdf8;font-weight:700;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px;background:#0c2a3a":"color:#a3a3a3;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px"}
|
|
6
|
+
@click=${t=>{t.preventDefault(),A().navigate(e)}}
|
|
7
|
+
>${this._label}</a>`}};function U(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1}=n,i=r??O`
|
|
8
8
|
<span style="color:#52525b;font-size:13px;display:inline-flex;align-items:center;gap:6px">
|
|
9
9
|
<span class="nix-spinner" style="
|
|
10
10
|
display:inline-block;width:14px;height:14px;border-radius:50%;
|
|
@@ -14,8 +14,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=
|
|
|
14
14
|
Cargando…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
|
-
`,a=o??(e=>
|
|
17
|
+
`,a=o??(e=>O`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`);return new class extends m{_state=s({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.value.status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return
|
|
21
|
+
`);return new class extends m{_state=s({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.value.status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return O`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?i:"error"===e.status?a(e.error):t(e.data)}}</div>`}}}function W(e,t){let n=null;return()=>n?new n:U(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function G(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function K(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function q(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function J(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function Y(e="Invalid email"){return J(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function X(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Z(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function se(e){return e}const ce={required:G,minLength:K,maxLength:q,email:Y,pattern:J,min:X,max:Z};function le(e,t){return{...e,...t}}function Q(e,t=[]){let n=s(e),r=s(!1),o=s(!1),i=s(null),a=l(()=>{if(i.value)return i.value;if(!r.value&&!o.value)return null;for(let e of t){let t=e(n.value);if(t)return t}return null});function u(t){return"boolean"==typeof e?t.checked:"number"==typeof e?Number(t.value):t.value}return{value:n,error:a,touched:r,dirty:o,onInput:e=>{n.value=u(e.target),o.value=!0,i.value=null},onBlur:()=>{r.value=!0},reset:function(){n.value=e,r.value=!1,o.value=!1,i.value=null},_setExternalError:function(e){i.value=e,e&&(r.value=!0)}}}function $(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=Q(e[r],o)}let r=l(()=>{let e={};for(let t in n)e[t]=n[t].value.value;return e}),o=l(()=>{let e={};for(let t in n){let r=n[t].error.value;r&&(e[t]=r)}return e}),i=l(()=>{for(let e in n)if(n[e].error.value)return!1;return!0}),a=l(()=>{for(let e in n)if(n[e].dirty.value)return!0;return!1});function u(e){for(let t in e)n[t]?._setExternalError(e[t]??null)}return{fields:n,values:r,errors:o,valid:i,dirty:a,handleSubmit:function(e){return o=>{o.preventDefault();for(let e in n)n[e].touched.value=!0;let l=r.value;if(t.validate){let e=t.validate(l);if(e){let t={},n=!1;for(let r in e){let o=e[r],l=Array.isArray(o)?o[0]??null:o??null;l&&(t[r]=l,n=!0)}if(n)return void u(t)}}for(let e in n)if(n[e].error.value)return;e(l)}},reset:function(){for(let e in n)n[e].reset()},setErrors:u}}exports.Link=H,exports.NixComponent=m,exports.RouterView=V,exports.Signal=o,exports.batch=u,exports.computed=l,exports.createForm=$,exports.createInjectionKey=g,exports.createRouter=z,exports.createStore=oe,exports.createValidator=se,exports.effect=c,exports.email=Y,exports.extendValidators=le,exports.html=O,exports.inject=te,exports.lazy=W,exports.max=Z,exports.maxLength=q,exports.min=X,exports.minLength=K,exports.mount=ae,exports.nextTick=p,exports.pattern=J,exports.provide=ee,exports.ref=ne,exports.repeat=S,exports.required=G,exports.signal=s,exports.suspend=U,exports.untrack=d,exports.useField=Q,exports.useRouter=B,exports.validators=ce,exports.watch=f;
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return e&&(this._subs.add(e),n?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=[...this._subs];i>0?e.forEach(e=>a.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function s(e){return new o(e)}function c(o){let l,i=new Set,a=()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i=new Set,t.push(e),r.push(n),e=a,n=i;try{l=o()}finally{e=t.pop()||null,n=r.pop()||null}};return a(),()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i.clear()}}function l(e){let t=new o(void 0);return c(()=>{t.value=e()}),t}function u(e){i++;try{e()}finally{if(0===--i){let e=[...a];a.clear(),e.forEach(e=>e())}}}function d(t){let r=e,o=n;e=null,n=null;try{return t()}finally{e=r,n=o}}function f(e,t,n={}){let r,{immediate:l=!1,once:i=!1}=n,a=e instanceof o?()=>e.value:e,s=!0,u=!1,f=c(()=>{let e=a();if(s){if(s=!1,l&&!u){let n=e;d(()=>t(n,void 0)),i&&(u=!0,Promise.resolve().then(f))}r=e}else if(!u){let n=e,o=r;r=e,d(()=>t(n,o)),i&&(u=!0,Promise.resolve().then(f))}});return()=>{u=!0,f()}}function p(e){return e?Promise.resolve().then(e):Promise.resolve()}var m=class{__isNixComponent=!0};function h(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function g(e){return Symbol(e)}var _=[];function v(){return[..._]}function y(){_.push(new Map)}function b(){_.pop()}function x(e,t){let n=_.splice(0);e.forEach(e=>_.push(e)),_.push(new Map);try{return t()}finally{_.splice(0),n.forEach(e=>_.push(e))}}function S(e,t){let n=_[_.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function C(e){for(let t=_.length-1;t>=0;t--)if(_[t].has(e))return _[t].get(e)}function w(){return{el:null}}function T(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function E(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function D(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function O(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function k(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function A(e){let t,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;t=r.nextNode();){let e=t,r=e.nodeValue?.match(/^nix-(\d+)$/);r&&n.set(parseInt(r[1]),e)}return n}function j(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function M(e,t,n){let r=[],o=[],l=A(e),i=j(e);for(let e=0;e<t.length;e++){let a=t[e],s=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=s,u=a.modifiers,c={};u.includes("once")&&(c.once=!0),u.includes("capture")&&(c.capture=!0),u.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(u.includes("prevent")&&e.preventDefault(),u.includes("stop")&&e.stopPropagation(),!u.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of u){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){s.el=n,r.push(()=>{s.el=null});continue}if("function"==typeof s){let e=c(()=>{let e=s();null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else null!=s&&!1!==s&&n.setAttribute(o,String(s));continue}let u=l.get(e);if(!u)continue;if("function"!=typeof s){if(h(s)){let e,n,l=s;y();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(u.parentNode,u)}finally{b()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(O(s))s._render(u.parentNode,u);else if(Array.isArray(s))for(let e of s)if(h(e)){let n,l;y();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(u.parentNode,u)}finally{b()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else O(e)?e._render(u.parentNode,u):null!=e&&!1!==e&&u.parentNode.insertBefore(document.createTextNode(String(e)),u);else null!=s&&!1!==s&&u.parentNode.insertBefore(document.createTextNode(String(s)),u);continue}let f=null,d=null,p=null,m=v(),g=c(()=>{let e=s();if("string"==typeof e||"number"==typeof e)return d&&=(d(),null),void(f?f.nodeValue=String(e):(f=document.createTextNode(String(e)),u.parentNode.insertBefore(f,u)));if(f&&=(f.parentNode?.removeChild(f),null),d&&=(d(),null),null!=e&&!1!==e)if(O(e))d=e._render(u.parentNode,u);else if(h(e)){let t,n,r=e;x(m,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(u.parentNode,u)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}d=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(k(e)){p||=new Map;let t=u.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n);for(let[e,n]of p)if(!r.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),p.delete(e)}let o=u;for(let r=n.length-1;r>=0;r--){let l=n[r],i=e.items[r];if(p.has(l)){let e=p.get(l);if(e.end.nextSibling!==o){let n=[],r=e.start;for(;n.push(r),r!==e.end;)r=r.nextSibling;for(let e of n)t.insertBefore(e,o)}o=e.start}else{let n=document.createComment("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let s,u=e.renderFn(i,r);if(h(u)){let r,o;x(m,()=>{try{u.onInit?.()}catch(e){if(!u.onError)throw e;u.onError(e)}r=u.render()._render(t,n)});try{let e=u.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!u.onError)throw e;u.onError(e)}s=()=>{try{u.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else s=u._render(t,n);p.set(l,{start:a,end:n,cleanup:s}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(h(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(u.parentNode,u);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(O(n))t.push(n._render(u.parentNode,u));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));u.parentNode.insertBefore(e,u),t.push(()=>e.parentNode?.removeChild(e))}d=()=>t.forEach(e=>e())}else f=document.createTextNode(String(e)),u.parentNode.insertBefore(f,u)});r.push(()=>{if(g(),d&&=(d(),null),f&&=(f.parentNode?.removeChild(f),null),p){for(let e of p.values())e.cleanup();p=null}})}return{disposes:r,postMountHooks:o}}function N(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=E(r);n.push(o),r+="__nix__"}let o=D(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:s}=M(i,n,t),u=document.createComment("nix-scope");e.insertBefore(u,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return s.forEach(e=>e()),()=>{a.forEach(e=>e());let e=u.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}u.parentNode?.removeChild(u)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function P(e,t){if(h(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);y();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{b()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function F(e,t){let n={};for(let t of Object.keys(e))n[t]=s(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);Object.assign(o,e)}return o}var I=null;function L(){if(!I)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return I}function R(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function z(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function B(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function V(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function H(e,t="",n=[]){let r=[];for(let o of e){let e=V(t,o.path),l=[...n,o.component],i=B(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...H(o.children,e,l))}return r}function U(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else"param"===t.kind&&(i[t.name]=decodeURIComponent(n[e]??""))}return i}function W(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function G(e,t){let n,r={},o=-1;for(let l of t){let t=U(e,l);if(null===t)continue;let i=W(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function K(e){function t(){return window.location.pathname||"/"}let n=t(),r=H(e),o=G(n,r),l=s(n),i=s(o?.params??{}),a=s(R(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=G(e,r)?.params??{},a.value=R(window.location.search),l.value=e});let u={current:l,params:i,query:a,navigate:function(e,t){let n=e.indexOf("?"),o=-1===n?e:e.slice(0,n),s=-1===n?{}:R(e.slice(n)),u=t?{...s,...t}:s,c={};for(let[e,t]of Object.entries(u))null!=t&&!1!==t&&(c[e]=String(t));i.value=G(o,r)?.params??{},a.value=c,l.value=o;let f=o+z(c);history.pushState(null,"",f)},routes:e,_flat:r};return I=u,u}function q(){return L()}var J=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return N`<div class="router-view">${()=>{let t=L(),n=G(t.current.value,t._flat);return n?e>=n.route.chain.length?N`<span></span>`:n.route.chain[e]():N`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return e&&(this._subs.add(e),n?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=[...this._subs];i>0?e.forEach(e=>a.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function s(e){return new o(e)}function c(o){let l,i=new Set,a=()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i=new Set,t.push(e),r.push(n),e=a,n=i;try{l=o()}finally{e=t.pop()||null,n=r.pop()||null}};return a(),()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i.clear()}}function l(e){let t=new o(void 0);return c(()=>{t.value=e()}),t}function u(e){i++;try{e()}finally{if(0===--i){let e=[...a];a.clear(),e.forEach(e=>e())}}}function d(t){let r=e,o=n;e=null,n=null;try{return t()}finally{e=r,n=o}}function f(e,t,n={}){let r,{immediate:l=!1,once:i=!1}=n,a=e instanceof o?()=>e.value:e,u=!0,s=!1,f=c(()=>{let e=a();if(u){if(u=!1,l&&!s){let n=e;d(()=>t(n,void 0)),i&&(s=!0,Promise.resolve().then(f))}r=e}else if(!s){let n=e,o=r;r=e,d(()=>t(n,o)),i&&(s=!0,Promise.resolve().then(f))}});return()=>{s=!0,f()}}function p(e){return e?Promise.resolve().then(e):Promise.resolve()}var m=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function h(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function g(e){return Symbol(e)}var _=[];function v(){return[..._]}function y(){_.push(new Map)}function b(){_.pop()}function x(e,t){let n=_.splice(0);e.forEach(e=>_.push(e)),_.push(new Map);try{return t()}finally{_.splice(0),n.forEach(e=>_.push(e))}}function ee(e,t){let n=_[_.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function te(e){for(let t=_.length-1;t>=0;t--)if(_[t].has(e))return _[t].get(e)}function ne(){return{el:null}}function S(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function C(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function w(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function T(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function E(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function D(e){let t,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;t=r.nextNode();){let e=t,r=e.nodeValue?.match(/^nix-(\d+)$/);r&&n.set(parseInt(r[1]),e)}return n}function re(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function ie(e,t,n){let r=[],o=[],l=D(e),i=re(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){u.el=n,r.push(()=>{u.el=null});continue}let l=("value"===o||"checked"===o||"selected"===o)&&o in n;if("function"==typeof u){let e=c(()=>{let e=u();l?n[o]=e??"":null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else l?n[o]=u??"":null!=u&&!1!==u&&n.setAttribute(o,String(u));continue}let s=l.get(e);if(!s)continue;if("function"!=typeof u){if(h(u)){let e,n,l=u;y();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{b()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(T(u))u._render(s.parentNode,s);else if(Array.isArray(u))for(let e of u)if(h(e)){let n,l;y();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{b()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else T(e)?e._render(s.parentNode,s):null!=e&&!1!==e&&s.parentNode.insertBefore(document.createTextNode(String(e)),s);else null!=u&&!1!==u&&s.parentNode.insertBefore(document.createTextNode(String(u)),s);continue}let f=null,d=null,p=null,m=v(),g=c(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return d&&=(d(),null),void(f?f.nodeValue=String(e):(f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)));if(f&&=(f.parentNode?.removeChild(f),null),d&&=(d(),null),null!=e&&!1!==e)if(T(e))d=e._render(s.parentNode,s);else if(h(e)){let t,n,r=e;x(m,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}d=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(E(e)){p||=new Map;let t=s.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n);for(let[e,n]of p)if(!r.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),p.delete(e)}let o=s;for(let r=n.length-1;r>=0;r--){let l=n[r],i=e.items[r];if(p.has(l)){let e=p.get(l);if(e.end.nextSibling!==o){let n=[],r=e.start;for(;n.push(r),r!==e.end;)r=r.nextSibling;for(let e of n)t.insertBefore(e,o)}o=e.start}else{let n=document.createComment("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(h(s)){let r,o;x(m,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else u=s._render(t,n);p.set(l,{start:a,end:n,cleanup:u}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(h(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(T(n))t.push(n._render(s.parentNode,s));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));s.parentNode.insertBefore(e,s),t.push(()=>e.parentNode?.removeChild(e))}d=()=>t.forEach(e=>e())}else f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)});r.push(()=>{if(g(),d&&=(d(),null),f&&=(f.parentNode?.removeChild(f),null),p){for(let e of p.values())e.cleanup();p=null}})}return{disposes:r,postMountHooks:o}}function O(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=C(r);n.push(o),r+="__nix__"}let o=w(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=ie(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function ae(e,t){if(h(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);y();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{b()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function oe(e,t){let n={};for(let t of Object.keys(e))n[t]=s(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);Object.assign(o,e)}return o}var k=null;function A(){if(!k)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return k}function j(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function M(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function N(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function P(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function F(e,t="",n=[]){let r=[];for(let o of e){let e=P(t,o.path),l=[...n,o.component],i=N(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...F(o.children,e,l))}return r}function I(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else"param"===t.kind&&(i[t.name]=decodeURIComponent(n[e]??""))}return i}function L(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function R(e,t){let n,r={},o=-1;for(let l of t){let t=I(e,l);if(null===t)continue;let i=L(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function z(e){function t(){return window.location.pathname||"/"}let n=t(),r=F(e),o=R(n,r),l=s(n),i=s(o?.params??{}),a=s(j(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=R(e,r)?.params??{},a.value=j(window.location.search),l.value=e});let u={current:l,params:i,query:a,navigate:function(e,t){let n=e.indexOf("?"),o=-1===n?e:e.slice(0,n),u=-1===n?{}:j(e.slice(n)),s=t?{...u,...t}:u,c={};for(let[e,t]of Object.entries(s))null!=t&&!1!==t&&(c[e]=String(t));i.value=R(o,r)?.params??{},a.value=c,l.value=o;let f=o+M(c);history.pushState(null,"",f)},routes:e,_flat:r};return k=u,u}function B(){return A()}var V=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return O`<div class="router-view">${()=>{let t=A(),n=R(t.current.value,t._flat);return n?e>=n.route.chain.length?O`<span></span>`:n.route.chain[e]():O`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Ruta no encontrada: <strong>${t.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
3
|
+
</div>`}}</div>`}},H=class extends m{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to;return O`<a
|
|
4
4
|
href=${e}
|
|
5
|
-
style=${()=>
|
|
6
|
-
@click=${t=>{t.preventDefault(),
|
|
7
|
-
>${this._label}</a>`}};function
|
|
5
|
+
style=${()=>A().current.value===e?"color:#38bdf8;font-weight:700;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px;background:#0c2a3a":"color:#a3a3a3;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px"}
|
|
6
|
+
@click=${t=>{t.preventDefault(),A().navigate(e)}}
|
|
7
|
+
>${this._label}</a>`}};function U(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1}=n,i=r??O`
|
|
8
8
|
<span style="color:#52525b;font-size:13px;display:inline-flex;align-items:center;gap:6px">
|
|
9
9
|
<span class="nix-spinner" style="
|
|
10
10
|
display:inline-block;width:14px;height:14px;border-radius:50%;
|
|
@@ -14,8 +14,8 @@ var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;construct
|
|
|
14
14
|
Cargando…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
|
-
`,a=o??(e=>
|
|
17
|
+
`,a=o??(e=>O`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`);return new class extends m{_state=s({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.value.status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return
|
|
21
|
+
`);return new class extends m{_state=s({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.value.status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return O`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?i:"error"===e.status?a(e.error):t(e.data)}}</div>`}}}function W(e,t){let n=null;return()=>n?new n:U(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function G(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function K(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function q(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function J(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function Y(e="Invalid email"){return J(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function X(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Z(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function se(e){return e}const ce={required:G,minLength:K,maxLength:q,email:Y,pattern:J,min:X,max:Z};function le(e,t){return{...e,...t}}function Q(e,t=[]){let n=s(e),r=s(!1),o=s(!1),i=s(null),a=l(()=>{if(i.value)return i.value;if(!r.value&&!o.value)return null;for(let e of t){let t=e(n.value);if(t)return t}return null});function u(t){return"boolean"==typeof e?t.checked:"number"==typeof e?Number(t.value):t.value}return{value:n,error:a,touched:r,dirty:o,onInput:e=>{n.value=u(e.target),o.value=!0,i.value=null},onBlur:()=>{r.value=!0},reset:function(){n.value=e,r.value=!1,o.value=!1,i.value=null},_setExternalError:function(e){i.value=e,e&&(r.value=!0)}}}function $(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=Q(e[r],o)}let r=l(()=>{let e={};for(let t in n)e[t]=n[t].value.value;return e}),o=l(()=>{let e={};for(let t in n){let r=n[t].error.value;r&&(e[t]=r)}return e}),i=l(()=>{for(let e in n)if(n[e].error.value)return!1;return!0}),a=l(()=>{for(let e in n)if(n[e].dirty.value)return!0;return!1});function u(e){for(let t in e)n[t]?._setExternalError(e[t]??null)}return{fields:n,values:r,errors:o,valid:i,dirty:a,handleSubmit:function(e){return o=>{o.preventDefault();for(let e in n)n[e].touched.value=!0;let l=r.value;if(t.validate){let e=t.validate(l);if(e){let t={},n=!1;for(let r in e){let o=e[r],l=Array.isArray(o)?o[0]??null:o??null;l&&(t[r]=l,n=!0)}if(n)return void u(t)}}for(let e in n)if(n[e].error.value)return;e(l)}},reset:function(){for(let e in n)n[e].reset()},setErrors:u}}export{H as Link,m as NixComponent,V as RouterView,o as Signal,u as batch,l as computed,$ as createForm,g as createInjectionKey,z as createRouter,oe as createStore,se as createValidator,c as effect,Y as email,le as extendValidators,O as html,te as inject,W as lazy,Z as max,q as maxLength,X as min,K as minLength,ae as mount,p as nextTick,J as pattern,ee as provide,ne as ref,S as repeat,G as required,s as signal,U as suspend,d as untrack,Q as useField,B as useRouter,ce as validators,f as watch};
|
package/package.json
CHANGED