@deijose/nix-js 2.2.1 → 2.2.2
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/lib/index.d.ts +2 -2
- package/dist/lib/nix/index.d.ts +2 -1
- package/dist/lib/nix/plugins.d.ts +38 -2
- package/dist/lib/nix-js.cjs +1 -1
- package/dist/lib/nix-js.js +1 -1
- package/dist/lib/plugins.cjs +1 -0
- package/dist/lib/plugins.js +1 -0
- package/package.json +1 -1
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, showWhen, portal, createPortalOutlet, portalOutlet, provideOutlet, injectOutlet, createErrorBoundary, transition, mount, NixComponent, createStore, createRouter, RouterView, Link, nixRouter, RouterKey, suspend, lazy, provide, inject, createInjectionKey, nixField, nixFieldArray, createForm, required, minLength, maxLength, email, pattern, min, max, createValidator, validators, extendValidators, } from "./nix";
|
|
2
|
-
export type { WatchOptions, NixTemplate, NixMountHandle, MountOptions, KeyedList, NixRef, PortalOutlet, ErrorFallback, TransitionOptions, TransitionContent, Store, StoreSignals, Router, NamedRouteLocation, RouteLocation, RouteRecord, RouterOptions, NavigationGuard, NavigationGuardResult, AfterEachHook, ResolvedRoute, ScrollPosition, ScrollBehavior, RouterMode, SuspenseOptions, InjectionKey, Validator, ValidateOn, FieldState, FieldArrayState, FieldErrors, FormState, FormOptions, ValidatorsBase, NixChildren, } from "./nix";
|
|
1
|
+
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, showWhen, portal, createPortalOutlet, portalOutlet, provideOutlet, injectOutlet, createErrorBoundary, transition, mount, NixComponent, createStore, persistPlugin, loggerPlugin, guardPlugin, bridgePlugin, createRouter, RouterView, Link, nixRouter, RouterKey, suspend, lazy, provide, inject, createInjectionKey, nixField, nixFieldArray, createForm, required, minLength, maxLength, email, pattern, min, max, createValidator, validators, extendValidators, } from "./nix";
|
|
2
|
+
export type { WatchOptions, NixTemplate, NixMountHandle, MountOptions, KeyedList, NixRef, PortalOutlet, ErrorFallback, TransitionOptions, TransitionContent, Store, StoreSignals, NixPlugin, Router, NamedRouteLocation, RouteLocation, RouteRecord, RouterOptions, NavigationGuard, NavigationGuardResult, AfterEachHook, ResolvedRoute, ScrollPosition, ScrollBehavior, RouterMode, SuspenseOptions, InjectionKey, Validator, ValidateOn, FieldState, FieldArrayState, FieldErrors, FormState, FormOptions, ValidatorsBase, NixChildren, } from "./nix";
|
package/dist/lib/nix/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export type { MountOptions } from "./component";
|
|
|
7
7
|
export { NixComponent } from "./lifecycle";
|
|
8
8
|
export type { NixChildren } from "./lifecycle";
|
|
9
9
|
export { createStore } from "./store";
|
|
10
|
-
export type { Store, StoreSignals } from "./store";
|
|
10
|
+
export type { Store, StoreSignals, NixPlugin } from "./store";
|
|
11
|
+
export { persistPlugin, loggerPlugin, guardPlugin, bridgePlugin } from "./plugins";
|
|
11
12
|
export { createRouter, RouterView, Link, nixRouter, RouterKey } from "./router";
|
|
12
13
|
export type { Router, NamedRouteLocation, RouteLocation, RouteRecord, RouterOptions, NavigationGuard, NavigationGuardResult, AfterEachHook, ResolvedRoute, ScrollPosition, ScrollBehavior, RouterMode, } from "./router";
|
|
13
14
|
export { suspend, lazy } from "./async";
|
|
@@ -1,16 +1,52 @@
|
|
|
1
1
|
import { type NixPlugin, type Store } from "./store";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal interface that any storage adapter must implement.
|
|
4
|
+
* Compatible with localStorage, sessionStorage, AsyncStorage, IndexedDB, etc.
|
|
5
|
+
*/
|
|
6
|
+
interface StorageAdapter {
|
|
7
|
+
/** Retrieves an item from storage. Returns null if not found. */
|
|
8
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
9
|
+
/** Stores an item in storage. */
|
|
10
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
11
|
+
/** Optional: Removes an item from storage. */
|
|
12
|
+
removeItem?(key: string): void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Persists the store state to a storage medium (defaults to localStorage).
|
|
16
|
+
* Automatically hydrates on initialization and saves changes on every reactive flush.
|
|
17
|
+
*/
|
|
2
18
|
export declare function persistPlugin<T extends Record<string, unknown>>(storageKey: string, opts?: {
|
|
3
|
-
/**
|
|
19
|
+
/** Storage adapter to use. Defaults to localStorage. */
|
|
20
|
+
storage?: StorageAdapter;
|
|
21
|
+
/** Properties to exclude from persistence. */
|
|
4
22
|
exclude?: Array<keyof T>;
|
|
5
|
-
/**
|
|
23
|
+
/** Custom serialization function. Defaults to JSON.stringify. */
|
|
6
24
|
serialize?: (state: T) => string;
|
|
25
|
+
/** Custom deserialization function. Defaults to JSON.parse. */
|
|
7
26
|
deserialize?: (raw: string) => Partial<T>;
|
|
27
|
+
/** Debounce interval in milliseconds for batching writes. Defaults to 0 (immediate). */
|
|
28
|
+
debounce?: number;
|
|
8
29
|
}): NixPlugin<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Logs state transitions to the console.
|
|
32
|
+
* Calculates property-level diffs and groups output by store ID.
|
|
33
|
+
*/
|
|
9
34
|
export declare function loggerPlugin<T extends Record<string, unknown>>(opts?: {
|
|
35
|
+
/** Whether the console group should be collapsed by default. */
|
|
10
36
|
collapsed?: boolean;
|
|
37
|
+
/** Optional filter to skip logging for specific changes. */
|
|
11
38
|
filter?: (diff: Partial<T>) => boolean;
|
|
12
39
|
}): NixPlugin<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Function type for mutation guards.
|
|
42
|
+
*/
|
|
13
43
|
type GuardFn<T extends Record<string, unknown>> = (next: Partial<T>, current: T) => Partial<T> | void;
|
|
44
|
+
/**
|
|
45
|
+
* Intercepts $patch and $reset calls to validate or transform state before it is applied.
|
|
46
|
+
*/
|
|
14
47
|
export declare function guardPlugin<T extends Record<string, unknown>>(guards: GuardFn<T>[]): NixPlugin<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Synchronizes data between two stores by watching one and patching the other.
|
|
50
|
+
*/
|
|
15
51
|
export declare function bridgePlugin<TA extends Record<string, unknown>, TB extends Record<string, unknown>>(sourceStore: Store<TB>, sync: (sourceState: TB, targetStore: Store<TA>) => void): NixPlugin<TA>;
|
|
16
52
|
export {};
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./template2.cjs"),n=require("./lifecycle.cjs"),r=require("./context.cjs"),i=require("./router.cjs"),a=require("./component.cjs"),o=require("./store.cjs"),s=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./template2.cjs"),n=require("./lifecycle.cjs"),r=require("./context.cjs"),i=require("./router.cjs"),a=require("./component.cjs"),o=require("./store.cjs"),s=require("./plugins.cjs"),c=require("./async.cjs"),l=require("./form.cjs");exports.Link=i.Link,exports.NixComponent=n.NixComponent,exports.RouterKey=i.RouterKey,exports.RouterView=i.RouterView,exports.Signal=e.Signal,exports.batch=e.batch,exports.bridgePlugin=s.bridgePlugin,exports.computed=e.computed,exports.createErrorBoundary=t.t,exports.createForm=l.createForm,exports.createInjectionKey=r.createInjectionKey,exports.createPortalOutlet=t.n,exports.createRouter=i.createRouter,exports.createStore=o.createStore,exports.createValidator=l.createValidator,exports.effect=e.effect,exports.email=l.email,exports.extendValidators=l.extendValidators,exports.guardPlugin=s.guardPlugin,exports.html=t.l,exports.inject=r.inject,exports.injectOutlet=t.r,exports.lazy=c.lazy,exports.loggerPlugin=s.loggerPlugin,exports.max=l.max,exports.maxLength=l.maxLength,exports.min=l.min,exports.minLength=l.minLength,exports.mount=a.mount,exports.nextTick=e.nextTick,exports.nixField=l.nixField,exports.nixFieldArray=l.nixFieldArray,exports.nixRouter=i.nixRouter,exports.pattern=l.pattern,exports.persistPlugin=s.persistPlugin,exports.portal=t.i,exports.portalOutlet=t.a,exports.provide=r.provide,exports.provideOutlet=t.o,exports.ref=t.h,exports.repeat=t.d,exports.required=l.required,exports.showWhen=t.u,exports.signal=e.signal,exports.suspend=c.suspend,exports.transition=t.s,exports.untrack=e.untrack,exports.validators=l.validators,exports.watch=e.watch;
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Signal as e,batch as t,computed as n,effect as r,nextTick as i,signal as a,untrack as o,watch as s}from"./signals.js";import{a as c,d as l,h as u,i as d,l as f,n as p,o as m,r as h,s as g,t as _,u as v}from"./template2.js";import{NixComponent as y}from"./lifecycle.js";import{createInjectionKey as b,inject as x,provide as S}from"./context.js";import{Link as C,RouterKey as w,RouterView as T,createRouter as E,nixRouter as D}from"./router.js";import{mount as O}from"./component.js";import{createStore as k}from"./store.js";import{
|
|
1
|
+
import{Signal as e,batch as t,computed as n,effect as r,nextTick as i,signal as a,untrack as o,watch as s}from"./signals.js";import{a as c,d as l,h as u,i as d,l as f,n as p,o as m,r as h,s as g,t as _,u as v}from"./template2.js";import{NixComponent as y}from"./lifecycle.js";import{createInjectionKey as b,inject as x,provide as S}from"./context.js";import{Link as C,RouterKey as w,RouterView as T,createRouter as E,nixRouter as D}from"./router.js";import{mount as O}from"./component.js";import{createStore as k}from"./store.js";import{bridgePlugin as A,guardPlugin as j,loggerPlugin as M,persistPlugin as N}from"./plugins.js";import{lazy as P,suspend as F}from"./async.js";import{createForm as I,createValidator as L,email as R,extendValidators as z,max as B,maxLength as V,min as H,minLength as U,nixField as W,nixFieldArray as G,pattern as K,required as q,validators as J}from"./form.js";export{C as Link,y as NixComponent,w as RouterKey,T as RouterView,e as Signal,t as batch,A as bridgePlugin,n as computed,_ as createErrorBoundary,I as createForm,b as createInjectionKey,p as createPortalOutlet,E as createRouter,k as createStore,L as createValidator,r as effect,R as email,z as extendValidators,j as guardPlugin,f as html,x as inject,h as injectOutlet,P as lazy,M as loggerPlugin,B as max,V as maxLength,H as min,U as minLength,O as mount,i as nextTick,W as nixField,G as nixFieldArray,D as nixRouter,K as pattern,N as persistPlugin,d as portal,c as portalOutlet,S as provide,m as provideOutlet,u as ref,l as repeat,q as required,v as showWhen,a as signal,F as suspend,g as transition,o as untrack,J as validators,s as watch};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs");function t(t,r={}){let{storage:n=localStorage,exclude:o=[],serialize:l=JSON.stringify,deserialize:i=JSON.parse,debounce:c=0}=r;return r=>{let s;return e.untrack(async()=>{try{let e=await n.getItem(t);if(!e)return;let l=i(e),c={};for(let e of Object.keys(l))e in r.$state&&!o.includes(e)&&(c[e]=l[e]);Object.keys(c).length>0&&r.$patch(c)}catch{}}),e.watch(r.$stateSignal,e=>{let r=()=>{try{let r=0===o.length?e:Object.fromEntries(Object.entries(e).filter(([e])=>!o.includes(e)));n.setItem(t,l(r))}catch{}};c>0?(clearTimeout(s),s=setTimeout(r,c)):r()})}}function n(t={}){let{collapsed:r=!0,filter:n}=t;return t=>{let o=r?console.groupCollapsed:console.group;return e.watch(t.$stateSignal,(e,r)=>{if(!r)return;let l={};for(let t of Object.keys(e))Object.is(e[t],r[t])||(l[t]=e[t]);0!==Object.keys(l).length&&(n&&!n(l)||(o(`%c[nix:${t.$id}]%c ${Object.keys(l).join(", ")}`,"color:#7F77DD;font-weight:500","color:inherit;font-weight:400"),console.log("prev →",r),console.log("next →",e),console.log("diff →",l),console.groupEnd()))},{immediate:!0})}}function r(t){return r=>{let n=r.$patch.bind(r),o=r.$reset.bind(r);return r.$patch=function(o){let l=o,i=e.untrack(()=>r.$state);for(let e of t){let t=e(l,i);void 0!==t&&(l=t)}n(l)},r.$reset=function(){let n=e.untrack(()=>r.$state);for(let e of t)e(n,n);o()},()=>{r.$patch=n,r.$reset=o}}}function i(t,r){return n=>e.watch(t.$stateSignal,e=>{r(e,n)})}exports.bridgePlugin=i,exports.guardPlugin=r,exports.loggerPlugin=n,exports.persistPlugin=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{untrack as e,watch as t}from"./signals.js";function n(n,r={}){let{storage:l=localStorage,exclude:o=[],serialize:i=JSON.stringify,deserialize:s=JSON.parse,debounce:c=0}=r;return r=>{let a;return e(async()=>{try{let e=await l.getItem(n);if(!e)return;let t=s(e),i={};for(let e of Object.keys(t))e in r.$state&&!o.includes(e)&&(i[e]=t[e]);Object.keys(i).length>0&&r.$patch(i)}catch{}}),t(r.$stateSignal,e=>{let t=()=>{try{let t=0===o.length?e:Object.fromEntries(Object.entries(e).filter(([e])=>!o.includes(e)));l.setItem(n,i(t))}catch{}};c>0?(clearTimeout(a),a=setTimeout(t,c)):t()})}}function r(e={}){let{collapsed:n=!0,filter:r}=e;return e=>{let l=n?console.groupCollapsed:console.group;return t(e.$stateSignal,(t,n)=>{if(!n)return;let o={};for(let e of Object.keys(t))Object.is(t[e],n[e])||(o[e]=t[e]);0!==Object.keys(o).length&&(r&&!r(o)||(l(`%c[nix:${e.$id}]%c ${Object.keys(o).join(", ")}`,"color:#7F77DD;font-weight:500","color:inherit;font-weight:400"),console.log("prev →",n),console.log("next →",t),console.log("diff →",o),console.groupEnd()))},{immediate:!0})}}function i(t){return n=>{let r=n.$patch.bind(n),l=n.$reset.bind(n);return n.$patch=function(l){let o=l,i=e(()=>n.$state);for(let e of t){let t=e(o,i);void 0!==t&&(o=t)}r(o)},n.$reset=function(){let r=e(()=>n.$state);for(let e of t)e(r,r);l()},()=>{n.$patch=r,n.$reset=l}}}function a(e,n){return r=>t(e.$stateSignal,e=>{n(e,r)})}export{a as bridgePlugin,i as guardPlugin,r as loggerPlugin,n as persistPlugin};
|
package/package.json
CHANGED