zag-ripple 0.0.4 → 0.0.6
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 -1
- package/src/index.d.ts +15 -0
- package/src/index.ripple +1 -0
- package/src/machine.ripple +22 -11
- package/src/normalize-props.ripple +10 -2
- package/src/portal.ripple +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zag-ripple",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "RippleJS Adapter for Zag JS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"main": "src/index.ripple",
|
|
19
19
|
"types": "src/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./src/index.ripple",
|
|
23
|
+
"types": "./src/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
20
26
|
"repository": "https://github.com/anubra266/zag-ripple/tree/main/packages/zag-ripple",
|
|
21
27
|
"sideEffects": false,
|
|
22
28
|
"publishConfig": {
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Machine, Scope } from "@zag-js/core";
|
|
2
|
+
import { Component } from "ripple";
|
|
2
3
|
|
|
3
4
|
export { mergeProps } from "@zag-js/core";
|
|
4
5
|
|
|
@@ -46,3 +47,17 @@ export declare function useMachine<
|
|
|
46
47
|
machine: Machine<TContext>,
|
|
47
48
|
options?: MachineOptions | (() => MachineOptions)
|
|
48
49
|
): MachineApi<TContext, TState>;
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
export interface PortalProps {
|
|
55
|
+
disabled?: boolean | undefined
|
|
56
|
+
container?: HTMLElement | undefined
|
|
57
|
+
getRootNode?: (() => ShadowRoot | Document | Node) | undefined
|
|
58
|
+
children: Component
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export declare const Portal: Component<PortalProps>;
|
|
62
|
+
// export declare function Portal(props: PortalProps): Component;
|
|
63
|
+
|
package/src/index.ripple
CHANGED
package/src/machine.ripple
CHANGED
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
Service,
|
|
12
12
|
} from "@zag-js/core"
|
|
13
13
|
import { createScope, INIT_STATE, MachineStatus } from "@zag-js/core"
|
|
14
|
-
import {
|
|
15
|
-
import { track, effect, flushSync } from "ripple"
|
|
14
|
+
import { ensure, isFunction, isPlainObject, isString, toArray, warn } from "@zag-js/utils"
|
|
15
|
+
import { track, trackSplit, untrack, effect, flushSync } from "ripple"
|
|
16
16
|
import { createBindable } from "./bindable.ripple"
|
|
17
17
|
import { createRefs } from "./refs.ripple"
|
|
18
18
|
import { createTrack } from "./track.ripple"
|
|
@@ -22,24 +22,36 @@ function access(userProps) {
|
|
|
22
22
|
return userProps
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
function compact(obj) {
|
|
26
|
+
if (!isPlainObject(obj) || obj === undefined) return obj
|
|
27
|
+
const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string")
|
|
28
|
+
const filtered = {}
|
|
29
|
+
for (const key of keys) {
|
|
30
|
+
const value = (obj)[key]
|
|
31
|
+
if (@value !== undefined) {
|
|
32
|
+
filtered[key as keyof T] = compact(@value)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return filtered as T
|
|
36
|
+
}
|
|
37
|
+
|
|
25
38
|
export function useMachine(
|
|
26
39
|
machine,
|
|
27
|
-
|
|
40
|
+
_userProps,
|
|
28
41
|
) {
|
|
42
|
+
let [id, ids, getRootNode,rest ]= trackSplit(access(_userProps), ['id', 'ids', 'getRootNode'])
|
|
29
43
|
let scope = track(() => {
|
|
30
|
-
|
|
31
|
-
return createScope({ id, ids, getRootNode })
|
|
44
|
+
return createScope({ id: @id, ids: @ids, getRootNode: @getRootNode })
|
|
32
45
|
})
|
|
33
|
-
|
|
34
46
|
const debug = (...args: any[]) => {
|
|
35
47
|
if (machine.debug) console.log(...args)
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
let props = track(() =>
|
|
39
|
-
machine.props?.({ props: compact(access(
|
|
51
|
+
machine.props?.({ props: compact(access(@rest)), scope: @scope }) ?? access(@rest)
|
|
40
52
|
)
|
|
41
53
|
|
|
42
|
-
const prop = useProp(() => @
|
|
54
|
+
const prop = useProp(() => ({...@props, id: @id, ids: @ids, getRootNode: @getRootNode }))
|
|
43
55
|
|
|
44
56
|
const context = machine.context?.({
|
|
45
57
|
prop,
|
|
@@ -109,7 +121,6 @@ export function useMachine(
|
|
|
109
121
|
const refs = createRefs(machine.refs?.({ prop, context: ctx }) ?? {})
|
|
110
122
|
|
|
111
123
|
const send = (event) => {
|
|
112
|
-
|
|
113
124
|
if (status !== MachineStatus.Started) return
|
|
114
125
|
|
|
115
126
|
previousEventRef.current = eventRef.current
|
|
@@ -274,7 +285,6 @@ export function useMachine(
|
|
|
274
285
|
}
|
|
275
286
|
})
|
|
276
287
|
|
|
277
|
-
|
|
278
288
|
|
|
279
289
|
machine.watch?.(getParams())
|
|
280
290
|
|
|
@@ -299,7 +309,8 @@ export function useMachine(
|
|
|
299
309
|
|
|
300
310
|
function useProp(value) {
|
|
301
311
|
return function get(key) {
|
|
302
|
-
|
|
312
|
+
const v = value()[key]
|
|
313
|
+
return @v
|
|
303
314
|
}
|
|
304
315
|
}
|
|
305
316
|
|
|
@@ -8,9 +8,17 @@ const propMap: Record<string, string> = {
|
|
|
8
8
|
defaultChecked: "checked",
|
|
9
9
|
defaultValue: "value",
|
|
10
10
|
htmlFor: "for",
|
|
11
|
-
onBlur: "onFocusOut",
|
|
12
11
|
onChange: "onInput",
|
|
13
|
-
|
|
12
|
+
// TODO
|
|
13
|
+
// onFocus: "onFocusIn",
|
|
14
|
+
// onBlur: "onFocusOut",
|
|
15
|
+
// TODO remove when ripple fix is merged
|
|
16
|
+
onFocus: "onFocusin",
|
|
17
|
+
onBlur: "onFocusout",
|
|
18
|
+
onKeyDown: "onKeydown",
|
|
19
|
+
onPointerDown: "onPointerdown",
|
|
20
|
+
onPointerMove: "onPointermove",
|
|
21
|
+
onPointerLeave: "onPointerleave",
|
|
14
22
|
}
|
|
15
23
|
|
|
16
24
|
export function toStyleString(style: Record<string, number | string>) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Portal as RipplePortal } from 'ripple';
|
|
2
|
+
|
|
3
|
+
export component Portal({ disabled, getRootNode, container, ...rest }:any) {
|
|
4
|
+
if(!disabled) {
|
|
5
|
+
const doc = getRootNode?.()?.ownerDocument ?? document
|
|
6
|
+
const target = container ?? doc.body
|
|
7
|
+
<RipplePortal {...rest} {target} />
|
|
8
|
+
}
|
|
9
|
+
}
|