zag-ripple 0.1.3 → 0.1.4
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/index.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MachineSchema, Machine, Service } from '@zag-js/core';
|
|
2
|
+
export { mergeProps } from '@zag-js/core';
|
|
2
3
|
import { Tracked } from 'ripple';
|
|
3
4
|
import * as _zag_js_types from '@zag-js/types';
|
|
4
5
|
|
|
5
|
-
declare function mergeProps<T extends Record<string, any>>(...args: T[]): T;
|
|
6
|
-
|
|
7
6
|
type MaybeTracked<T> = {
|
|
8
7
|
[K in keyof T]?: T[K] | Tracked<T[K]>;
|
|
9
8
|
};
|
|
@@ -24,4 +23,4 @@ declare const normalizeProps: _zag_js_types.NormalizeProps<PropTypes>;
|
|
|
24
23
|
|
|
25
24
|
declare function onMount(fn: () => void | (() => void)): void;
|
|
26
25
|
|
|
27
|
-
export { type PropTypes,
|
|
26
|
+
export { type PropTypes, normalizeProps, onMount, useMachine };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MachineSchema, Machine, Service } from '@zag-js/core';
|
|
2
|
+
export { mergeProps } from '@zag-js/core';
|
|
2
3
|
import { Tracked } from 'ripple';
|
|
3
4
|
import * as _zag_js_types from '@zag-js/types';
|
|
4
5
|
|
|
5
|
-
declare function mergeProps<T extends Record<string, any>>(...args: T[]): T;
|
|
6
|
-
|
|
7
6
|
type MaybeTracked<T> = {
|
|
8
7
|
[K in keyof T]?: T[K] | Tracked<T[K]>;
|
|
9
8
|
};
|
|
@@ -24,4 +23,4 @@ declare const normalizeProps: _zag_js_types.NormalizeProps<PropTypes>;
|
|
|
24
23
|
|
|
25
24
|
declare function onMount(fn: () => void | (() => void)): void;
|
|
26
25
|
|
|
27
|
-
export { type PropTypes,
|
|
26
|
+
export { type PropTypes, normalizeProps, onMount, useMachine };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var core=require('@zag-js/core'),utils=require('@zag-js/utils'),ripple=require('ripple'),types=require('@zag-js/types');function C(t){let r=t().value??t().defaultValue,o=t().isEqual??Object.is,s=ripple.track(r),g=ripple.track(()=>t().value!=null),a={current:ripple.untrack(()=>ripple.get(s))},T={current:void 0};ripple.effect(()=>{let u=ripple.get(g)?t().value:ripple.get(s);T.current=u,a.current=u;});let x=u=>{let f=t().sync?ripple.flushSync:utils.identity;ripple.untrack(()=>f(()=>m(u)));},m=u=>{let f=T.current,p=utils.isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:p,prev:f}),ripple.get(g)||ripple.set(s,p),a.current=p,T.current=p,o(p,f)||t().onChange?.(p,f);};function v(){return ripple.get(g)?t().value:ripple.get(s)}return {initial:r,ref:a,get:v,set:x,invoke(u,f){t().onChange?.(u,f);},hash(u){return t().hash?.(u)??String(u)}}}C.cleanup=t=>{ripple.effect(()=>()=>t());};C.ref=t=>{let r=t;return {get:()=>r,set:o=>{r=o;}}};function L(t){let r={current:t};return {get(o){return r.current[o]},set(o,s){r.current[o]=s;}}}function b(t){let r=utils.isFunction(t)?t():t;return ripple.get(r)}function K(t){if(!utils.isPlainObject(t)||t===void 0)return t;let r=Reflect.ownKeys(t).filter(s=>typeof s=="string"),o={};for(let s of r){let g=ripple.get(t[s]);g!==void 0&&(o[s]=K(g));}return o}var q=(t,r)=>{let o=[],s=true;ripple.effect(()=>{if(s){o=t.map(a=>b(a)),s=false;return}let g=false;for(let a=0;a<t.length;a++)if(!utils.isEqual(o[a],b(t[a]))){g=true;break}g&&(o=t.map(a=>b(a)),r());});};function Wt(t,r={}){let o=ripple.track(()=>{let{id:e,ids:n,getRootNode:i}=b(r);return core.createScope({id:e,ids:n,getRootNode:i})}),s=(...e)=>{t.debug&&console.log(...e);},g=ripple.track(()=>{let e=K(b(r));return t.props?.({props:e,scope:ripple.get(o)})??e}),a=Tt(()=>ripple.get(g)),T=t.context?.({prop:a,bindable:C,get scope(){return ripple.get(o)},flush:Z,getContext(){return x},getComputed(){return M},getRefs(){return O},getEvent(){return p()}}),x={get(e){return T?.[e].get()},set(e,n){T?.[e].set(n);},initial(e){return T?.[e].initial},hash(e){let n=T?.[e].get();return T?.[e].hash(n)}},m={current:new Map},v={current:null},u={current:null},f={current:{type:""}},p=()=>({...f.current,current(){return f.current},previous(){return u.current}}),j=()=>({...h,matches(...e){let n=h.get();return e.some(i=>core.matchesState(n,i))},hasTag(e){let n=h.get();return core.hasTag(t,n,e)}}),O=L(t.refs?.({prop:a,context:x})??{}),y=()=>({state:j(),context:x,event:p(),prop:a,send:A,action:S,guard:w,track:q,refs:O,computed:M,flush:Z,get scope(){return ripple.get(o)},choose:B}),S=e=>{let n=utils.isFunction(e)?e(y()):e;if(!n)return;let i=n.map(l=>{let c=t.implementations?.actions?.[l];return c||utils.warn(`[zag-js] No implementation found for action "${JSON.stringify(l)}"`),c});for(let l of i)l?.(y());},w=e=>utils.isFunction(e)?e(y()):t.implementations?.guards?.[e](y()),z=e=>{let n=utils.isFunction(e)?e(y()):e;if(!n)return;let i=n.map(c=>{let d=t.implementations?.effects?.[c];return d||utils.warn(`[zag-js] No implementation found for effect "${JSON.stringify(c)}"`),d}),l=[];for(let c of i){let d=c?.(y());d&&l.push(d);}return ()=>l.forEach(c=>c?.())},B=e=>utils.toArray(e).find(n=>{let i=!n.guard;return utils.isString(n.guard)?i=!!w(n.guard):utils.isFunction(n.guard)&&(i=n.guard(y())),i}),M=e=>{utils.ensure(t.computed,()=>"[zag-js] No computed object found on machine");let n=t.computed[e];return n({context:x,event:f.current,prop:a,refs:O,scope:ripple.get(o),computed:M})},h=C(()=>({defaultValue:core.resolveStateValue(t,t.initialState({prop:a})),onChange(e,n){let{exiting:i,entering:l}=core.getExitEnterStates(t,n,e,v.current?.reenter);if(i.forEach(c=>{m.current.get(c.path)?.(),m.current.delete(c.path);}),i.forEach(c=>{S(c.state?.exit);}),S(v.current?.actions),l.forEach(c=>{let d=z(c.state?.effects);d&&m.current.set(c.path,d);}),n===core.INIT_STATE){S(t.entry);let c=z(t.effects);c&&m.current.set(core.INIT_STATE,c);}l.forEach(c=>{S(c.state?.entry);});}})),E=core.MachineStatus.NotStarted;ripple.effect(()=>ripple.untrack(()=>{let e=E===core.MachineStatus.Started;return E=core.MachineStatus.Started,s(e?"rehydrating...":"initializing..."),h.invoke(h.initial,core.INIT_STATE),()=>{s("unmounting..."),E=core.MachineStatus.Stopped,m.current.forEach(i=>i?.()),m.current=new Map,v.current=null,S(t.exit);}}));let A=e=>{if(E!==core.MachineStatus.Started)return;u.current=f.current,f.current=e;let n=ripple.untrack(()=>h.get()),{transitions:i,source:l}=core.findTransition(t,n,e.type),c=B(i);if(!c)return;v.current=c;let d=core.resolveStateValue(t,c.target??n,l);s("transition",e.type,c.target||n,`(${c.actions})`),d!==n?h.set(d):c.reenter?h.invoke(n,n):S(c.actions);};return t.watch?.(y()),{get state(){return j()},send:A,context:x,prop:a,get scope(){return ripple.get(o)},refs:O,computed:M,get event(){return p()},getStatus:()=>E}}function Z(t){t();}function Tt(t){return function(o){return t()[o]}}var _={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function xt(t){return t in _?_[t]:t}var Ut=types.createNormalizer(t=>{let r={};for(let o in t){let s=t[o];if(!(o==="readOnly"&&s===false)){if(o==="style"&&utils.isObject(s)){r.style=St(s);continue}if(o==="children"){utils.isString(s)&&(r.textContent=s);continue}r[xt(o)]=s;}}return r});function St(t){let r={};for(let o in t){let s=t[o];!utils.isString(s)&&!utils.isNumber(s)||(r[bt(o)]=s);}return r}var bt=t=>t.startsWith("--")?t:Et(t),vt=/[A-Z]/g,Ft=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var V={};function Et(t){if(V.hasOwnProperty(t))return V[t];let r=t.replace(vt,kt);return V[t]=Ft.test(r)?"-"+r:r}function Ot(t){ripple.effect(()=>ripple.untrack(()=>{let r=t();if(typeof r=="function")return r}));}Object.defineProperty(exports,"mergeProps",{enumerable:true,get:function(){return core.mergeProps}});exports.normalizeProps=Ut;exports.onMount=Ot;exports.useMachine=Wt;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {createScope,INIT_STATE,MachineStatus,hasTag,matchesState,findTransition,resolveStateValue,getExitEnterStates}from'@zag-js/core';export{mergeProps}from'@zag-js/core';import {isObject,isString,isNumber,ensure,isFunction,warn,toArray,isPlainObject,identity,isEqual}from'@zag-js/utils';import {track,get,effect,untrack,flushSync,set}from'ripple';import {createNormalizer}from'@zag-js/types';function C(t){let r=t().value??t().defaultValue,o=t().isEqual??Object.is,s=track(r),g=track(()=>t().value!=null),a={current:untrack(()=>get(s))},T={current:void 0};effect(()=>{let u=get(g)?t().value:get(s);T.current=u,a.current=u;});let x=u=>{let f=t().sync?flushSync:identity;untrack(()=>f(()=>m(u)));},m=u=>{let f=T.current,p=isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:p,prev:f}),get(g)||set(s,p),a.current=p,T.current=p,o(p,f)||t().onChange?.(p,f);};function v(){return get(g)?t().value:get(s)}return {initial:r,ref:a,get:v,set:x,invoke(u,f){t().onChange?.(u,f);},hash(u){return t().hash?.(u)??String(u)}}}C.cleanup=t=>{effect(()=>()=>t());};C.ref=t=>{let r=t;return {get:()=>r,set:o=>{r=o;}}};function L(t){let r={current:t};return {get(o){return r.current[o]},set(o,s){r.current[o]=s;}}}function b(t){let r=isFunction(t)?t():t;return get(r)}function K(t){if(!isPlainObject(t)||t===void 0)return t;let r=Reflect.ownKeys(t).filter(s=>typeof s=="string"),o={};for(let s of r){let g=get(t[s]);g!==void 0&&(o[s]=K(g));}return o}var q=(t,r)=>{let o=[],s=true;effect(()=>{if(s){o=t.map(a=>b(a)),s=false;return}let g=false;for(let a=0;a<t.length;a++)if(!isEqual(o[a],b(t[a]))){g=true;break}g&&(o=t.map(a=>b(a)),r());});};function Wt(t,r={}){let o=track(()=>{let{id:e,ids:n,getRootNode:i}=b(r);return createScope({id:e,ids:n,getRootNode:i})}),s=(...e)=>{t.debug&&console.log(...e);},g=track(()=>{let e=K(b(r));return t.props?.({props:e,scope:get(o)})??e}),a=Tt(()=>get(g)),T=t.context?.({prop:a,bindable:C,get scope(){return get(o)},flush:Z,getContext(){return x},getComputed(){return M},getRefs(){return O},getEvent(){return p()}}),x={get(e){return T?.[e].get()},set(e,n){T?.[e].set(n);},initial(e){return T?.[e].initial},hash(e){let n=T?.[e].get();return T?.[e].hash(n)}},m={current:new Map},v={current:null},u={current:null},f={current:{type:""}},p=()=>({...f.current,current(){return f.current},previous(){return u.current}}),j=()=>({...h,matches(...e){let n=h.get();return e.some(i=>matchesState(n,i))},hasTag(e){let n=h.get();return hasTag(t,n,e)}}),O=L(t.refs?.({prop:a,context:x})??{}),y=()=>({state:j(),context:x,event:p(),prop:a,send:A,action:S,guard:w,track:q,refs:O,computed:M,flush:Z,get scope(){return get(o)},choose:B}),S=e=>{let n=isFunction(e)?e(y()):e;if(!n)return;let i=n.map(l=>{let c=t.implementations?.actions?.[l];return c||warn(`[zag-js] No implementation found for action "${JSON.stringify(l)}"`),c});for(let l of i)l?.(y());},w=e=>isFunction(e)?e(y()):t.implementations?.guards?.[e](y()),z=e=>{let n=isFunction(e)?e(y()):e;if(!n)return;let i=n.map(c=>{let d=t.implementations?.effects?.[c];return d||warn(`[zag-js] No implementation found for effect "${JSON.stringify(c)}"`),d}),l=[];for(let c of i){let d=c?.(y());d&&l.push(d);}return ()=>l.forEach(c=>c?.())},B=e=>toArray(e).find(n=>{let i=!n.guard;return isString(n.guard)?i=!!w(n.guard):isFunction(n.guard)&&(i=n.guard(y())),i}),M=e=>{ensure(t.computed,()=>"[zag-js] No computed object found on machine");let n=t.computed[e];return n({context:x,event:f.current,prop:a,refs:O,scope:get(o),computed:M})},h=C(()=>({defaultValue:resolveStateValue(t,t.initialState({prop:a})),onChange(e,n){let{exiting:i,entering:l}=getExitEnterStates(t,n,e,v.current?.reenter);if(i.forEach(c=>{m.current.get(c.path)?.(),m.current.delete(c.path);}),i.forEach(c=>{S(c.state?.exit);}),S(v.current?.actions),l.forEach(c=>{let d=z(c.state?.effects);d&&m.current.set(c.path,d);}),n===INIT_STATE){S(t.entry);let c=z(t.effects);c&&m.current.set(INIT_STATE,c);}l.forEach(c=>{S(c.state?.entry);});}})),E=MachineStatus.NotStarted;effect(()=>untrack(()=>{let e=E===MachineStatus.Started;return E=MachineStatus.Started,s(e?"rehydrating...":"initializing..."),h.invoke(h.initial,INIT_STATE),()=>{s("unmounting..."),E=MachineStatus.Stopped,m.current.forEach(i=>i?.()),m.current=new Map,v.current=null,S(t.exit);}}));let A=e=>{if(E!==MachineStatus.Started)return;u.current=f.current,f.current=e;let n=untrack(()=>h.get()),{transitions:i,source:l}=findTransition(t,n,e.type),c=B(i);if(!c)return;v.current=c;let d=resolveStateValue(t,c.target??n,l);s("transition",e.type,c.target||n,`(${c.actions})`),d!==n?h.set(d):c.reenter?h.invoke(n,n):S(c.actions);};return t.watch?.(y()),{get state(){return j()},send:A,context:x,prop:a,get scope(){return get(o)},refs:O,computed:M,get event(){return p()},getStatus:()=>E}}function Z(t){t();}function Tt(t){return function(o){return t()[o]}}var _={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function xt(t){return t in _?_[t]:t}var Ut=createNormalizer(t=>{let r={};for(let o in t){let s=t[o];if(!(o==="readOnly"&&s===false)){if(o==="style"&&isObject(s)){r.style=St(s);continue}if(o==="children"){isString(s)&&(r.textContent=s);continue}r[xt(o)]=s;}}return r});function St(t){let r={};for(let o in t){let s=t[o];!isString(s)&&!isNumber(s)||(r[bt(o)]=s);}return r}var bt=t=>t.startsWith("--")?t:Et(t),vt=/[A-Z]/g,Ft=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var V={};function Et(t){if(V.hasOwnProperty(t))return V[t];let r=t.replace(vt,kt);return V[t]=Ft.test(r)?"-"+r:r}function Ot(t){effect(()=>untrack(()=>{let r=t();if(typeof r=="function")return r}));}export{Ut as normalizeProps,Ot as onMount,Wt as useMachine};
|