zag-ripple 0.0.2 → 0.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zag-ripple",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "RippleJS Adapter for Zag JS",
5
5
  "keywords": [
6
6
  "js",
@@ -108,6 +108,40 @@ export function useMachine(
108
108
 
109
109
  const refs = createRefs(machine.refs?.({ prop, context: ctx }) ?? {})
110
110
 
111
+ const send = (event) => {
112
+
113
+ if (status !== MachineStatus.Started) return
114
+
115
+ previousEventRef.current = eventRef.current
116
+ eventRef.current = event
117
+
118
+ let currentState = state.get()
119
+
120
+ const transitions =
121
+ machine.states[currentState]?.on?.[event.type] ??
122
+ machine.on?.[event.type]
123
+
124
+ const transition = choose(transitions)
125
+ if (!transition) return
126
+
127
+ // save current transition
128
+ transitionRef.current = transition
129
+ const target = transition.target ?? currentState
130
+
131
+ debug("transition", event.type, transition.target || currentState, `(${transition.actions})`)
132
+
133
+ const changed = target !== currentState
134
+ if (changed) {
135
+ state.set(target)
136
+ } else if (transition.reenter && !changed) {
137
+ // reenter will re-invoke the current state
138
+ state.invoke?.(currentState, currentState)
139
+ } else {
140
+ // call transition actions
141
+ action(transition.actions ?? [])
142
+ }
143
+ }
144
+
111
145
  const getParams = () => ({
112
146
  state: getState(),
113
147
  context: ctx,
@@ -220,45 +254,27 @@ export function useMachine(
220
254
 
221
255
  let status = MachineStatus.NotStarted
222
256
 
223
- // Initialize machine immediately - RippleJS components run imperatively
224
- status = MachineStatus.Started
225
- debug("initializing...")
226
- const initialState = machine.initialState({ prop })
227
- state.set(initialState)
228
-
229
- const send = (event) => {
230
- console.log("send", event)
231
- if (status !== MachineStatus.Started) return
232
-
233
- previousEventRef.current = eventRef.current
234
- eventRef.current = event
235
-
236
- let currentState = state.get()
237
-
238
- const transitions =
239
- machine.states[currentState]?.on?.[event.type] ??
240
- machine.on?.[event.type]
241
-
242
- const transition = choose(transitions)
243
- if (!transition) return
244
-
245
- // save current transition
246
- transitionRef.current = transition
247
- const target = transition.target ?? currentState
248
-
249
- debug("transition", event.type, transition.target || currentState, `(${transition.actions})`)
250
-
251
- const changed = target !== currentState
252
- if (changed) {
253
- state.set(target)
254
- } else if (transition.reenter && !changed) {
255
- // reenter will re-invoke the current state
256
- state.invoke?.(currentState, currentState)
257
- } else {
258
- // call transition actions
259
- action(transition.actions ?? [])
260
- }
261
- }
257
+ effect(() => {
258
+ queueMicrotask(() => {
259
+ const started = status === MachineStatus.Started
260
+ status = MachineStatus.Started
261
+ debug(started ? "rehydrating..." : "initializing...")
262
+ state.invoke(state.initial, INIT_STATE)
263
+ })
264
+
265
+ return () => {
266
+ debug("unmounting...")
267
+ status = MachineStatus.Stopped
268
+ effects.forEach((fn) => fn?.())
269
+ effects = new Map()
270
+ transitionRef.current = null
271
+ queueMicrotask(() => {
272
+ action(machine.exit)
273
+ })
274
+ }
275
+ })
276
+
277
+
262
278
 
263
279
  machine.watch?.(getParams())
264
280
 
@@ -34,16 +34,9 @@ export function toStyleString(style: Record<string, number | string>) {
34
34
  return string
35
35
  }
36
36
 
37
- const preserveKeys = new Set<string>(
38
- "viewBox,className,preserveAspectRatio,fillRule,clipPath,clipRule,strokeWidth,strokeLinecap,strokeLinejoin,strokeDasharray,strokeDashoffset,strokeMiterlimit".split(
39
- ",",
40
- ),
41
- )
42
-
43
37
  function toRippleProp(key: string) {
44
38
  if (key in propMap) return propMap[key]
45
- if (preserveKeys.has(key)) return key
46
- return key.toLowerCase()
39
+ return key
47
40
  }
48
41
 
49
42
  function toRipplePropValue(key: string, value: Dict[string]) {