zag-ripple 0.0.9 → 0.0.11

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.9",
3
+ "version": "0.0.11",
4
4
  "description": "RippleJS Adapter for Zag JS",
5
5
  "keywords": [
6
6
  "js",
package/src/index.d.ts CHANGED
@@ -4,7 +4,8 @@ import { Component } from "ripple";
4
4
  export { mergeProps } from "@zag-js/core";
5
5
 
6
6
  // From normalize-props.ripple
7
- export declare const normalizeProps: <T>(props: T) => T;
7
+ import { NormalizeProps, PropTypes } from "@zag-js/types";
8
+ export declare const normalizeProps: NormalizeProps<PropTypes>;
8
9
 
9
10
  // From machine.ripple
10
11
  export interface MachineApi<TContext = Record<string, any>, TState extends string = string> {
@@ -12,16 +12,11 @@ import type {
12
12
  } from "@zag-js/core"
13
13
  import { createScope, INIT_STATE, MachineStatus } from "@zag-js/core"
14
14
  import { ensure, isFunction, isPlainObject, isString, toArray, warn } from "@zag-js/utils"
15
- import { track, trackSplit, effect, flushSync } from "ripple"
15
+ import { track, effect, flushSync } from "ripple"
16
16
  import { bindable } from "./bindable.ripple"
17
17
  import { useRefs } from "./refs.ripple"
18
18
  import { createTrack } from "./track.ripple"
19
19
 
20
- function access(userProps) {
21
- if (isFunction(userProps)) return userProps()
22
- return userProps
23
- }
24
-
25
20
  function compact(obj) {
26
21
  if (!isPlainObject(obj) || obj === undefined) return obj
27
22
  const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string")
@@ -39,9 +34,9 @@ export function useMachine(
39
34
  machine,
40
35
  _userProps,
41
36
  ) {
42
- let [id, ids, getRootNode, rest]= trackSplit(access(_userProps), ['id', 'ids', 'getRootNode'])
37
+ const userProps = track(() => @_userProps)
43
38
  let scope = track(() => {
44
- return createScope({ id: @id, ids: @ids, getRootNode: @getRootNode })
39
+ return createScope({ id: @userProps.id, ids: @userProps.ids, getRootNode: @userProps.getRootNode })
45
40
  })
46
41
 
47
42
  const debug = (...args: any[]) => {
@@ -49,8 +44,7 @@ export function useMachine(
49
44
  }
50
45
 
51
46
  let props = track(() => {
52
- const p = { ...@rest, id: @id, ids: @ids, getRootNode: @getRootNode }
53
- return machine.props?.({ props: compact(p), scope: @scope }) ?? p
47
+ return machine.props?.({ props: compact(@userProps), scope: @scope }) ?? @userProps
54
48
  })
55
49
 
56
50
  const prop = useProp(() => @props)
@@ -1,5 +1,4 @@
1
- import { createNormalizer } from "@zag-js/types"
2
-
1
+ import { createNormalizer, type PropTypes } from "@zag-js/types"
3
2
 
4
3
  type Dict = Record<string, boolean | number | string | undefined>
5
4
 
@@ -44,7 +43,7 @@ function toRipplePropValue(key: string, value: Dict[string]) {
44
43
  return value
45
44
  }
46
45
 
47
- export const normalizeProps = createNormalizer<Record<string, any>>((props) => {
46
+ const normalizeFn = (props: any) => {
48
47
  const normalized: Dict = {}
49
48
 
50
49
  for (const key in props) {
@@ -52,4 +51,6 @@ export const normalizeProps = createNormalizer<Record<string, any>>((props) => {
52
51
  }
53
52
 
54
53
  return normalized
55
- })
54
+ }
55
+
56
+ export const normalizeProps = createNormalizer<PropTypes>(normalizeFn)