zag-ripple 0.0.17 → 0.0.19
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 +14 -3
- package/dist/index.d.ts +14 -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,8 +1,19 @@
|
|
|
1
1
|
import { MachineSchema, Machine, Service } from '@zag-js/core';
|
|
2
|
-
|
|
2
|
+
import { Tracked } from 'ripple';
|
|
3
3
|
import * as _zag_js_types from '@zag-js/types';
|
|
4
4
|
|
|
5
|
-
declare function
|
|
5
|
+
declare function mergeProps<T extends Record<string, any>>(...args: T[]): T;
|
|
6
|
+
|
|
7
|
+
type MaybeTracked<T> = {
|
|
8
|
+
[K in keyof T]?: T[K] | Tracked<T[K]>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* UseMachine hook for Ripple JS
|
|
12
|
+
* @param machine - The machine to use
|
|
13
|
+
* @param userProps - The user props to use
|
|
14
|
+
* @returns The service
|
|
15
|
+
*/
|
|
16
|
+
declare function useMachine<T extends MachineSchema>(machine: Machine<T>, userProps?: MaybeTracked<T["props"]>): Service<T>;
|
|
6
17
|
|
|
7
18
|
type PropTypes<T = Dict> = Record<"button" | "label" | "input" | "textarea" | "img" | "output" | "element" | "select" | "rect" | "style" | "circle" | "svg" | "path", T>;
|
|
8
19
|
type Dict = Record<string, any>;
|
|
@@ -10,4 +21,4 @@ declare const normalizeProps: _zag_js_types.NormalizeProps<PropTypes<Dict>>;
|
|
|
10
21
|
|
|
11
22
|
declare function onMount(fn: () => void | (() => void)): void;
|
|
12
23
|
|
|
13
|
-
export { normalizeProps, onMount, useMachine };
|
|
24
|
+
export { mergeProps, normalizeProps, onMount, useMachine };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { MachineSchema, Machine, Service } from '@zag-js/core';
|
|
2
|
-
|
|
2
|
+
import { Tracked } from 'ripple';
|
|
3
3
|
import * as _zag_js_types from '@zag-js/types';
|
|
4
4
|
|
|
5
|
-
declare function
|
|
5
|
+
declare function mergeProps<T extends Record<string, any>>(...args: T[]): T;
|
|
6
|
+
|
|
7
|
+
type MaybeTracked<T> = {
|
|
8
|
+
[K in keyof T]?: T[K] | Tracked<T[K]>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* UseMachine hook for Ripple JS
|
|
12
|
+
* @param machine - The machine to use
|
|
13
|
+
* @param userProps - The user props to use
|
|
14
|
+
* @returns The service
|
|
15
|
+
*/
|
|
16
|
+
declare function useMachine<T extends MachineSchema>(machine: Machine<T>, userProps?: MaybeTracked<T["props"]>): Service<T>;
|
|
6
17
|
|
|
7
18
|
type PropTypes<T = Dict> = Record<"button" | "label" | "input" | "textarea" | "img" | "output" | "element" | "select" | "rect" | "style" | "circle" | "svg" | "path", T>;
|
|
8
19
|
type Dict = Record<string, any>;
|
|
@@ -10,4 +21,4 @@ declare const normalizeProps: _zag_js_types.NormalizeProps<PropTypes<Dict>>;
|
|
|
10
21
|
|
|
11
22
|
declare function onMount(fn: () => void | (() => void)): void;
|
|
12
23
|
|
|
13
|
-
export { normalizeProps, onMount, useMachine };
|
|
24
|
+
export { mergeProps, normalizeProps, onMount, useMachine };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var core=require('@zag-js/core'),utils=require('@zag-js/utils'),
|
|
1
|
+
'use strict';var ripple=require('ripple'),core=require('@zag-js/core'),utils=require('@zag-js/utils'),types=require('@zag-js/types');function Kt(...t){let e={};for(let o of t)if(o){for(let n in e){let f=o[n],a=ripple.get(f);if(n.startsWith("on")&&typeof e[n]=="function"&&typeof a=="function"){let g=e[n];e[n]=(...T)=>{a(...T),g(...T);};continue}e[n]=a!==void 0?a:e[n];}for(let n in o)if(e[n]===void 0){let f=o[n];e[n]=ripple.get(f);}for(let n of Object.getOwnPropertySymbols(o))e[n]=o[n];}return e}function E(t){let e=t().value??t().defaultValue,o=t().isEqual??Object.is,n=ripple.track(e),f=ripple.track(()=>t().value!=null),a={current:ripple.untrack(()=>ripple.get(n))},g={current:void 0};ripple.effect(()=>{let u=ripple.get(f)?t().value:ripple.get(n);g.current=u,a.current=u;});let T=u=>{let y=g.current,l=utils.isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:l,prev:y}),ripple.get(f)||ripple.set(n,l),a.current=l,g.current=l,o(l,y)||t().onChange?.(l,y);};function m(){return ripple.get(f)?t().value:ripple.get(n)}return {initial:e,ref:a,get:m,set:T,invoke(u,y){t().onChange?.(u,y);},hash(u){return t().hash?.(u)??String(u)}}}E.cleanup=t=>{ripple.effect(()=>()=>t());};E.ref=t=>{let e=t;return {get:()=>e,set:o=>{e=o;}}};function q(t){let e={current:t};return {get(o){return e.current[o]},set(o,n){e.current[o]=n;}}}function v(t){let e=utils.isFunction(t)?t():t;return ripple.get(e)}function M(t){if(!utils.isPlainObject(t)||t===void 0)return t;let e=Reflect.ownKeys(t).filter(n=>typeof n=="string"),o={};for(let n of e){let f=ripple.get(t[n]);f!==void 0&&(o[n]=M(f));}return o}var J=(t,e)=>{let o=[],n=true;ripple.effect(()=>{if(n){o=t.map(a=>v(a)),n=false;return}let f=false;for(let a=0;a<t.length;a++)if(!utils.isEqual(o[a],v(t[a]))){f=true;break}f&&(o=t.map(a=>v(a)),e());});};function Qt(t,e={}){let o=ripple.track(()=>{let{id:r,ids:c,getRootNode:i}=v(e);return core.createScope({id:r,ids:c,getRootNode:i})}),n=(...r)=>{t.debug&&console.log(...r);},f=ripple.track(()=>{let r=M(v(e));return t.props?.({props:r,scope:ripple.get(o)})??r}),a=gt(()=>ripple.get(f)),g=t.context?.({prop:a,bindable:E,get scope(){return ripple.get(o)},flush:_,getContext(){return T},getComputed(){return C},getRefs(){return R},getEvent(){return K()}}),T={get(r){return g?.[r].get()},set(r,c){g?.[r].set(c);},initial(r){return g?.[r].initial},hash(r){let c=g?.[r].get();return g?.[r].hash(c)}},m={current:new Map},u={current:null},y={current:null},l={current:{type:""}},K=()=>({...l.current,current(){return l.current},previous(){return y.current}}),j=()=>({...x,matches(...r){let c=x.get();return r.some(i=>core.matchesState(c,i))},hasTag(r){let c=x.get();return core.hasTag(t,c,r)}}),R=q(t.refs?.({prop:a,context:T})??{}),h=()=>({state:j(),context:T,event:K(),prop:a,send:D,action:S,guard:w,track:J,refs:R,computed:C,flush:_,get scope(){return ripple.get(o)},choose:B}),S=r=>{let c=utils.isFunction(r)?r(h()):r;if(!c)return;let i=c.map(p=>{let s=t.implementations?.actions?.[p];return s||utils.warn(`[zag-js] No implementation found for action "${JSON.stringify(p)}"`),s});for(let p of i)p?.(h());},w=r=>utils.isFunction(r)?r(h()):t.implementations?.guards?.[r](h()),z=r=>{let c=utils.isFunction(r)?r(h()):r;if(!c)return;let i=c.map(s=>{let d=t.implementations?.effects?.[s];return d||utils.warn(`[zag-js] No implementation found for effect "${JSON.stringify(s)}"`),d}),p=[];for(let s of i){let d=s?.(h());d&&p.push(d);}return ()=>p.forEach(s=>s?.())},B=r=>utils.toArray(r).find(c=>{let i=!c.guard;return utils.isString(c.guard)?i=!!w(c.guard):utils.isFunction(c.guard)&&(i=c.guard(h())),i}),C=r=>{utils.ensure(t.computed,()=>"[zag-js] No computed object found on machine");let c=t.computed[r];return c({context:T,event:l.current,prop:a,refs:R,scope:ripple.get(o),computed:C})},x=E(()=>({defaultValue:core.resolveStateValue(t,t.initialState({prop:a})),onChange(r,c){let{exiting:i,entering:p}=core.getExitEnterStates(t,c,r,u.current?.reenter);if(i.forEach(s=>{m.current.get(s.path)?.(),m.current.delete(s.path);}),i.forEach(s=>{S(s.state?.exit);}),S(u.current?.actions),p.forEach(s=>{let d=z(s.state?.effects);d&&m.current.set(s.path,d);}),c===core.INIT_STATE){S(t.entry);let s=z(t.effects);s&&m.current.set(core.INIT_STATE,s);}p.forEach(s=>{S(s.state?.entry);});}})),F=core.MachineStatus.NotStarted;ripple.effect(()=>ripple.untrack(()=>{let r=F===core.MachineStatus.Started;return F=core.MachineStatus.Started,n(r?"rehydrating...":"initializing..."),x.invoke(x.initial,core.INIT_STATE),()=>{n("unmounting..."),F=core.MachineStatus.Stopped,m.current.forEach(i=>i?.()),m.current=new Map,u.current=null,S(t.exit);}}));let D=r=>{if(F!==core.MachineStatus.Started)return;y.current=l.current,l.current=r;let c=ripple.untrack(()=>x.get()),{transitions:i,source:p}=core.findTransition(t,c,r.type),s=B(i);if(!s)return;u.current=s;let d=core.resolveStateValue(t,s.target??c,p);n("transition",r.type,s.target||c,`(${s.actions})`),d!==c?x.set(d):s.reenter?x.invoke(c,c):S(s.actions);};return t.watch?.(h()),{get state(){return j()},send:D,context:T,prop:a,get scope(){return ripple.get(o)},refs:R,computed:C,get event(){return K()},getStatus:()=>F}}function _(t){t();}function gt(t){return function(o){return t()[o]}}var Q={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function ht(t){return t in Q?Q[t]:t}var te=types.createNormalizer(t=>{let e={};for(let o in t){let n=t[o];if(!(o==="readOnly"&&n===false)){if(o==="style"&&utils.isObject(n)){e.style=xt(n);continue}if(o==="children"){utils.isString(n)&&(e.textContent=n);continue}e[ht(o)]=n;}}return e});function xt(t){let e={};for(let o in t){let n=t[o];!utils.isString(n)&&!utils.isNumber(n)||(e[St(o)]=n);}return e}var St=t=>t.startsWith("--")?t:Ft(t),vt=/[A-Z]/g,bt=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var V={};function Ft(t){if(V.hasOwnProperty(t))return V[t];let e=t.replace(vt,kt);return V[t]=bt.test(e)?"-"+e:e}function Rt(t){ripple.effect(()=>ripple.untrack(()=>{let e=t();if(typeof e=="function")return e}));}exports.mergeProps=Kt;exports.normalizeProps=te;exports.onMount=Rt;exports.useMachine=Qt;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createScope,INIT_STATE,MachineStatus,hasTag,matchesState,findTransition,resolveStateValue,getExitEnterStates}from'@zag-js/core';
|
|
1
|
+
import {get,track,effect,untrack,set}from'ripple';import {createScope,INIT_STATE,MachineStatus,hasTag,matchesState,findTransition,resolveStateValue,getExitEnterStates}from'@zag-js/core';import {isObject,isString,isNumber,ensure,isFunction,warn,toArray,isPlainObject,isEqual}from'@zag-js/utils';import {createNormalizer}from'@zag-js/types';function Kt(...t){let e={};for(let o of t)if(o){for(let n in e){let f=o[n],a=get(f);if(n.startsWith("on")&&typeof e[n]=="function"&&typeof a=="function"){let g=e[n];e[n]=(...T)=>{a(...T),g(...T);};continue}e[n]=a!==void 0?a:e[n];}for(let n in o)if(e[n]===void 0){let f=o[n];e[n]=get(f);}for(let n of Object.getOwnPropertySymbols(o))e[n]=o[n];}return e}function E(t){let e=t().value??t().defaultValue,o=t().isEqual??Object.is,n=track(e),f=track(()=>t().value!=null),a={current:untrack(()=>get(n))},g={current:void 0};effect(()=>{let u=get(f)?t().value:get(n);g.current=u,a.current=u;});let T=u=>{let y=g.current,l=isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:l,prev:y}),get(f)||set(n,l),a.current=l,g.current=l,o(l,y)||t().onChange?.(l,y);};function m(){return get(f)?t().value:get(n)}return {initial:e,ref:a,get:m,set:T,invoke(u,y){t().onChange?.(u,y);},hash(u){return t().hash?.(u)??String(u)}}}E.cleanup=t=>{effect(()=>()=>t());};E.ref=t=>{let e=t;return {get:()=>e,set:o=>{e=o;}}};function q(t){let e={current:t};return {get(o){return e.current[o]},set(o,n){e.current[o]=n;}}}function v(t){let e=isFunction(t)?t():t;return get(e)}function M(t){if(!isPlainObject(t)||t===void 0)return t;let e=Reflect.ownKeys(t).filter(n=>typeof n=="string"),o={};for(let n of e){let f=get(t[n]);f!==void 0&&(o[n]=M(f));}return o}var J=(t,e)=>{let o=[],n=true;effect(()=>{if(n){o=t.map(a=>v(a)),n=false;return}let f=false;for(let a=0;a<t.length;a++)if(!isEqual(o[a],v(t[a]))){f=true;break}f&&(o=t.map(a=>v(a)),e());});};function Qt(t,e={}){let o=track(()=>{let{id:r,ids:c,getRootNode:i}=v(e);return createScope({id:r,ids:c,getRootNode:i})}),n=(...r)=>{t.debug&&console.log(...r);},f=track(()=>{let r=M(v(e));return t.props?.({props:r,scope:get(o)})??r}),a=gt(()=>get(f)),g=t.context?.({prop:a,bindable:E,get scope(){return get(o)},flush:_,getContext(){return T},getComputed(){return C},getRefs(){return R},getEvent(){return K()}}),T={get(r){return g?.[r].get()},set(r,c){g?.[r].set(c);},initial(r){return g?.[r].initial},hash(r){let c=g?.[r].get();return g?.[r].hash(c)}},m={current:new Map},u={current:null},y={current:null},l={current:{type:""}},K=()=>({...l.current,current(){return l.current},previous(){return y.current}}),j=()=>({...x,matches(...r){let c=x.get();return r.some(i=>matchesState(c,i))},hasTag(r){let c=x.get();return hasTag(t,c,r)}}),R=q(t.refs?.({prop:a,context:T})??{}),h=()=>({state:j(),context:T,event:K(),prop:a,send:D,action:S,guard:w,track:J,refs:R,computed:C,flush:_,get scope(){return get(o)},choose:B}),S=r=>{let c=isFunction(r)?r(h()):r;if(!c)return;let i=c.map(p=>{let s=t.implementations?.actions?.[p];return s||warn(`[zag-js] No implementation found for action "${JSON.stringify(p)}"`),s});for(let p of i)p?.(h());},w=r=>isFunction(r)?r(h()):t.implementations?.guards?.[r](h()),z=r=>{let c=isFunction(r)?r(h()):r;if(!c)return;let i=c.map(s=>{let d=t.implementations?.effects?.[s];return d||warn(`[zag-js] No implementation found for effect "${JSON.stringify(s)}"`),d}),p=[];for(let s of i){let d=s?.(h());d&&p.push(d);}return ()=>p.forEach(s=>s?.())},B=r=>toArray(r).find(c=>{let i=!c.guard;return isString(c.guard)?i=!!w(c.guard):isFunction(c.guard)&&(i=c.guard(h())),i}),C=r=>{ensure(t.computed,()=>"[zag-js] No computed object found on machine");let c=t.computed[r];return c({context:T,event:l.current,prop:a,refs:R,scope:get(o),computed:C})},x=E(()=>({defaultValue:resolveStateValue(t,t.initialState({prop:a})),onChange(r,c){let{exiting:i,entering:p}=getExitEnterStates(t,c,r,u.current?.reenter);if(i.forEach(s=>{m.current.get(s.path)?.(),m.current.delete(s.path);}),i.forEach(s=>{S(s.state?.exit);}),S(u.current?.actions),p.forEach(s=>{let d=z(s.state?.effects);d&&m.current.set(s.path,d);}),c===INIT_STATE){S(t.entry);let s=z(t.effects);s&&m.current.set(INIT_STATE,s);}p.forEach(s=>{S(s.state?.entry);});}})),F=MachineStatus.NotStarted;effect(()=>untrack(()=>{let r=F===MachineStatus.Started;return F=MachineStatus.Started,n(r?"rehydrating...":"initializing..."),x.invoke(x.initial,INIT_STATE),()=>{n("unmounting..."),F=MachineStatus.Stopped,m.current.forEach(i=>i?.()),m.current=new Map,u.current=null,S(t.exit);}}));let D=r=>{if(F!==MachineStatus.Started)return;y.current=l.current,l.current=r;let c=untrack(()=>x.get()),{transitions:i,source:p}=findTransition(t,c,r.type),s=B(i);if(!s)return;u.current=s;let d=resolveStateValue(t,s.target??c,p);n("transition",r.type,s.target||c,`(${s.actions})`),d!==c?x.set(d):s.reenter?x.invoke(c,c):S(s.actions);};return t.watch?.(h()),{get state(){return j()},send:D,context:T,prop:a,get scope(){return get(o)},refs:R,computed:C,get event(){return K()},getStatus:()=>F}}function _(t){t();}function gt(t){return function(o){return t()[o]}}var Q={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function ht(t){return t in Q?Q[t]:t}var te=createNormalizer(t=>{let e={};for(let o in t){let n=t[o];if(!(o==="readOnly"&&n===false)){if(o==="style"&&isObject(n)){e.style=xt(n);continue}if(o==="children"){isString(n)&&(e.textContent=n);continue}e[ht(o)]=n;}}return e});function xt(t){let e={};for(let o in t){let n=t[o];!isString(n)&&!isNumber(n)||(e[St(o)]=n);}return e}var St=t=>t.startsWith("--")?t:Ft(t),vt=/[A-Z]/g,bt=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var V={};function Ft(t){if(V.hasOwnProperty(t))return V[t];let e=t.replace(vt,kt);return V[t]=bt.test(e)?"-"+e:e}function Rt(t){effect(()=>untrack(()=>{let e=t();if(typeof e=="function")return e}));}export{Kt as mergeProps,te as normalizeProps,Rt as onMount,Qt as useMachine};
|