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 +7 -4
- package/src/index.d.ts +2 -0
- package/src/index.ripple +1 -0
- package/src/machine.ripple +35 -35
- package/src/utils.ripple +7 -0
- package/tsconfig.json +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zag-ripple",
|
|
3
|
-
"version": "0.0.
|
|
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.
|
|
36
|
-
"@zag-js/types": "^1.
|
|
37
|
-
"@zag-js/utils": "^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
package/src/index.ripple
CHANGED
package/src/machine.ripple
CHANGED
|
@@ -10,18 +10,22 @@ import type {
|
|
|
10
10
|
Params,
|
|
11
11
|
Service,
|
|
12
12
|
} from "@zag-js/core"
|
|
13
|
-
import {
|
|
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,
|
|
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
|
-
|
|
118
|
-
|
|
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
|
-
|
|
201
|
+
const { exiting, entering } = getExitEnterStates(machine, prevState, nextState, transitionRef.current?.reenter)
|
|
200
202
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const exitEffects = effects.get(prevState)
|
|
203
|
+
exiting.forEach((item) => {
|
|
204
|
+
const exitEffects = effects.get(item.path)
|
|
204
205
|
exitEffects?.()
|
|
205
|
-
effects.delete(
|
|
206
|
-
}
|
|
206
|
+
effects.delete(item.path)
|
|
207
|
+
})
|
|
207
208
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
228
|
-
|
|
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
|
|
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
|
|
276
|
+
} else if (transition.reenter) {
|
|
277
277
|
// reenter will re-invoke the current state
|
|
278
278
|
state.invoke?.(currentState, currentState)
|
|
279
279
|
} else {
|
package/src/utils.ripple
ADDED