zag-ripple 0.0.14 → 0.0.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zag-ripple",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "RippleJS Adapter for Zag JS",
5
5
  "keywords": [
6
6
  "js",
@@ -16,6 +16,9 @@
16
16
  "homepage": "https://github.com/anubra266/zag-ripple#readme",
17
17
  "license": "MIT",
18
18
  "main": "src/index.ripple",
19
+ "files": [
20
+ "src"
21
+ ],
19
22
  "exports": {
20
23
  ".": {
21
24
  "import": "./src/index.ripple",
@@ -32,9 +35,9 @@
32
35
  "url": "https://github.com/anubra266i/zag-ripple/issues"
33
36
  },
34
37
  "dependencies": {
35
- "@zag-js/core": "^1.34.1",
36
- "@zag-js/types": "^1.34.1",
37
- "@zag-js/utils": "^1.34.1"
38
+ "@zag-js/core": "^1.35.0",
39
+ "@zag-js/types": "^1.35.0",
40
+ "@zag-js/utils": "^1.35.0"
38
41
  },
39
42
  "peerDependencies": {
40
43
  "ripple": ">=0.2.0"
package/src/index.d.ts CHANGED
@@ -58,6 +58,8 @@ export declare function createTrack(
58
58
  effectCallback: VoidFunction
59
59
  ): void;
60
60
 
61
+ // Utils
62
+ export declare function onMount(mount: () => void): void;
61
63
 
62
64
 
63
65
 
package/src/index.ripple CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./normalize-props.ripple"
2
2
  export * from "./machine.ripple"
3
3
  export * from "./portal.ripple"
4
+ export * from "./utils.ripple"
4
5
 
5
6
  export function mergeProps<T extends Record<string, any>>(...args: T[]): T {
6
7
  let result: any = {}
@@ -10,18 +10,22 @@ import type {
10
10
  Params,
11
11
  Service,
12
12
  } from "@zag-js/core"
13
- import { createScope, INIT_STATE, MachineStatus } from "@zag-js/core"
13
+ import {
14
+ createScope,
15
+ findTransition,
16
+ getExitEnterStates,
17
+ hasTag,
18
+ INIT_STATE,
19
+ MachineStatus,
20
+ matchesState,
21
+ resolveStateValue,
22
+ } from "@zag-js/core"
14
23
  import { ensure, isFunction, isPlainObject, isString, toArray, warn } from "@zag-js/utils"
15
- import { track, effect, flushSync, untrack } from "ripple"
24
+ import { track, flushSync } from "ripple"
16
25
  import { bindable } from "./bindable.ripple"
17
26
  import { useRefs } from "./refs.ripple"
18
27
  import { createTrack } from "./track.ripple"
19
-
20
- function onMount(mount) {
21
- effect(() => {
22
- return untrack(mount);
23
- });
24
- }
28
+ import { onMount } from "./utils.ripple"
25
29
 
26
30
  function compact<T extends Record<string, unknown> | undefined>(obj: T): T {
27
31
  if (!isPlainObject(obj) || obj === undefined) return obj
@@ -109,13 +113,11 @@ export function useMachine<T extends MachineSchema>(
109
113
 
110
114
  const getState = () => ({
111
115
  ...state,
112
- hasTag(tag) {
113
- const currentState = state.get()
114
- return !!machine.states[currentState]?.tags?.includes(tag)
115
- },
116
116
  matches(...values) {
117
- const currentState = state.get()
118
- return values.includes(currentState)
117
+ return values.some((value) => matchesState(state.get(), value))
118
+ },
119
+ hasTag(tag) {
120
+ return hasTag(machine, state.get(), tag)
119
121
  },
120
122
  })
121
123
 
@@ -194,38 +196,36 @@ export function useMachine<T extends MachineSchema>(
194
196
  }
195
197
 
196
198
  const state = bindable(() => ({
197
- defaultValue: machine.initialState({ prop }),
199
+ defaultValue: resolveStateValue(machine, machine.initialState({ prop })),
198
200
  onChange(nextState: string, prevState: string | undefined) {
199
- // compute effects: exit -> transition -> enter
201
+ const { exiting, entering } = getExitEnterStates(machine, prevState, nextState, transitionRef.current?.reenter)
200
202
 
201
- // exit effects
202
- if (prevState) {
203
- const exitEffects = effects.get(prevState)
203
+ exiting.forEach((item) => {
204
+ const exitEffects = effects.get(item.path)
204
205
  exitEffects?.()
205
- effects.delete(prevState)
206
- }
206
+ effects.delete(item.path)
207
+ })
207
208
 
208
- // exit actions
209
- if (prevState) {
210
- action(machine.states[prevState]?.exit)
211
- }
209
+ exiting.forEach((item) => {
210
+ action(item.state?.exit)
211
+ })
212
212
 
213
- // transition actions
214
213
  action(transitionRef.current?.actions)
215
214
 
216
- // enter effects
217
- const cleanup = effectFn( machine.states[nextState]?.effects)
218
- if (cleanup) effects.set(nextState, cleanup)
215
+ entering.forEach((item) => {
216
+ const cleanup = effectFn(item.state?.effects)
217
+ if (cleanup) effects.set(item.path, cleanup)
218
+ })
219
219
 
220
- // root entry actions
221
220
  if (prevState === INIT_STATE) {
222
221
  action(machine.entry)
223
222
  const cleanup = effectFn(machine.effects)
224
223
  if (cleanup) effects.set(INIT_STATE, cleanup)
225
224
  }
226
225
 
227
- // enter actions
228
- action(machine.states[nextState]?.entry)
226
+ entering.forEach((item) => {
227
+ action(item.state?.entry)
228
+ })
229
229
  },
230
230
  }))
231
231
 
@@ -258,14 +258,14 @@ export function useMachine<T extends MachineSchema>(
258
258
 
259
259
  let currentState = state.get()
260
260
 
261
- const transitions = machine.states[currentState].on?.[event.type] ?? machine.on?.[event.type]
261
+ const { transitions, source } = findTransition(machine, currentState, event.type)
262
262
 
263
263
  const transition = choose(transitions)
264
264
  if (!transition) return
265
265
 
266
266
  // save current transition
267
267
  transitionRef.current = transition
268
- const target = transition.target ?? currentState
268
+ const target = resolveStateValue(machine, transition.target ?? currentState, source)
269
269
 
270
270
  debug("transition", event.type, transition.target || currentState, `(${transition.actions})`)
271
271
 
@@ -273,7 +273,7 @@ export function useMachine<T extends MachineSchema>(
273
273
  if (changed) {
274
274
  // state change is high priority
275
275
  state.set(target)
276
- } else if (transition.reenter && !changed) {
276
+ } else if (transition.reenter) {
277
277
  // reenter will re-invoke the current state
278
278
  state.invoke?.(currentState, currentState)
279
279
  } else {
@@ -0,0 +1,7 @@
1
+ import { effect, untrack } from "ripple"
2
+
3
+ export function onMount(mount) {
4
+ effect(() => {
5
+ return untrack(mount);
6
+ });
7
+ }
package/tsconfig.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "tsBuildInfoFile": "node_modules/.cache/.tsbuildinfo",
5
- }
6
- }