@pnlight/sdk-react 0.1.0
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/LICENSE +21 -0
- package/README.md +101 -0
- package/dist/RemoteUi.d.ts +16 -0
- package/dist/RemoteUi.d.ts.map +1 -0
- package/dist/RemoteUi.js +48 -0
- package/dist/RemoteUi.js.map +1 -0
- package/dist/custom-components.d.ts +4 -0
- package/dist/custom-components.d.ts.map +1 -0
- package/dist/custom-components.js +909 -0
- package/dist/custom-components.js.map +1 -0
- package/dist/dialogs.d.ts +32 -0
- package/dist/dialogs.d.ts.map +1 -0
- package/dist/dialogs.js +107 -0
- package/dist/dialogs.js.map +1 -0
- package/dist/flow.d.ts +88 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/flow.js +270 -0
- package/dist/flow.js.map +1 -0
- package/dist/haptics.d.ts +7 -0
- package/dist/haptics.d.ts.map +1 -0
- package/dist/haptics.js +69 -0
- package/dist/haptics.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime.d.ts +27 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +192 -0
- package/dist/runtime.js.map +1 -0
- package/dist/safe-area.d.ts +22 -0
- package/dist/safe-area.d.ts.map +1 -0
- package/dist/safe-area.js +104 -0
- package/dist/safe-area.js.map +1 -0
- package/dist/schema-version.d.ts +11 -0
- package/dist/schema-version.d.ts.map +1 -0
- package/dist/schema-version.js +30 -0
- package/dist/schema-version.js.map +1 -0
- package/dist/styles.css +172 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) PNLight
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# `@pnlight/sdk-react`
|
|
2
|
+
|
|
3
|
+
A thin React wrapper around the official DivKit Web renderer with PNLight
|
|
4
|
+
Remote UI behavior installed automatically.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @pnlight/sdk-react
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Use
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { RemoteUi } from "@pnlight/sdk-react";
|
|
16
|
+
import "@pnlight/sdk-react/styles.css";
|
|
17
|
+
|
|
18
|
+
export function Screen({ config }: { config: object }) {
|
|
19
|
+
return (
|
|
20
|
+
<RemoteUi
|
|
21
|
+
id="home"
|
|
22
|
+
json={config}
|
|
23
|
+
theme="system"
|
|
24
|
+
onCustomAction={(action) => {
|
|
25
|
+
console.log(action.url);
|
|
26
|
+
}}
|
|
27
|
+
onError={({ error }) => {
|
|
28
|
+
console.error(error);
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Like the official `@divkitframework/react` package, the component accepts the
|
|
36
|
+
DivKit client render options except `target` and `hydrate`. PNLight supplies its
|
|
37
|
+
own target, custom components, global scaling/safe-area variables, Lottie
|
|
38
|
+
extension, and protocol handlers.
|
|
39
|
+
|
|
40
|
+
The package also exports `PNLightDivKit` as an alias for `RemoteUi`.
|
|
41
|
+
|
|
42
|
+
The registered custom components include `pnlight.animated_prepend_list`. It
|
|
43
|
+
uses the same props as the iOS component: increasing `count` by one smoothly
|
|
44
|
+
prepends the next discovery-ordered item, while larger jumps or resets apply
|
|
45
|
+
immediately. Rows use intrinsic content height, and `instance_id` preserves the
|
|
46
|
+
displayed count if DivKit replaces the underlying custom element.
|
|
47
|
+
|
|
48
|
+
On the web, DivKit does not make expressions inside `custom_props` reactive.
|
|
49
|
+
For a variable-driven list, keep `count` as a literal initial value and pass
|
|
50
|
+
the variable name through `count_variable`:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"custom_props": {
|
|
55
|
+
"count": 0,
|
|
56
|
+
"count_variable": "visible_item_count",
|
|
57
|
+
"items": []
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The component subscribes to that DivKit variable and applies the same prepend
|
|
63
|
+
animation for each increment.
|
|
64
|
+
|
|
65
|
+
## PNLight actions
|
|
66
|
+
|
|
67
|
+
Navigation, dialogs, and haptics are consumed inside the component for
|
|
68
|
+
`schemaVersion: 2` documents. Observe them when needed:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
<RemoteUi
|
|
72
|
+
id="offer"
|
|
73
|
+
json={config}
|
|
74
|
+
onPNLightAction={({ kind, url, logId, message }) => {
|
|
75
|
+
console.log(kind, url, logId, message);
|
|
76
|
+
}}
|
|
77
|
+
/>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Unconsumed custom URLs continue through DivKit's standard `onCustomAction`
|
|
81
|
+
callback.
|
|
82
|
+
|
|
83
|
+
## Styling
|
|
84
|
+
|
|
85
|
+
Import `@pnlight/sdk-react/styles.css` once. Give the component or its parent an
|
|
86
|
+
explicit height when the document uses `match_parent`:
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
<RemoteUi id="full-screen" json={config} style={{ minHeight: "100dvh" }} />
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Compatibility
|
|
93
|
+
|
|
94
|
+
- Missing `schemaVersion`, or version `1`, keeps legacy edge-to-edge behavior.
|
|
95
|
+
- `schemaVersion: 2` enables PNLight flows, safe areas, scaling variables,
|
|
96
|
+
dialogs, and haptics.
|
|
97
|
+
- CTA, icon button, circular loader, animated prepend list, and Lottie support
|
|
98
|
+
are additive.
|
|
99
|
+
|
|
100
|
+
This initial package is client-side only. Use it from a client component in
|
|
101
|
+
SSR frameworks.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactElement } from "react";
|
|
2
|
+
import { type RemoteUiRenderOptions } from "./runtime.js";
|
|
3
|
+
export type RemoteUiProps = Omit<RemoteUiRenderOptions, "target"> & {
|
|
4
|
+
className?: string;
|
|
5
|
+
style?: CSSProperties;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Declarative PNLight wrapper around DivKit's client renderer.
|
|
9
|
+
*
|
|
10
|
+
* PNLight-owned flow navigation, safe-area/scaling variables, dialogs,
|
|
11
|
+
* haptics, Lottie, and custom components are installed automatically.
|
|
12
|
+
*/
|
|
13
|
+
export declare function RemoteUi(props: RemoteUiProps): ReactElement;
|
|
14
|
+
/** A descriptive alias for teams that want to distinguish it from host UI. */
|
|
15
|
+
export declare const PNLightDivKit: typeof RemoteUi;
|
|
16
|
+
//# sourceMappingURL=RemoteUi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteUi.d.ts","sourceRoot":"","sources":["../src/RemoteUi.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,GAAG;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC;AAiBF;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,CAwC3D;AAED,8EAA8E;AAC9E,eAAO,MAAM,aAAa,iBAAW,CAAC"}
|
package/dist/RemoteUi.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createElement, useEffect, useRef } from "react";
|
|
2
|
+
import { mountRemoteUi } from "./runtime.js";
|
|
3
|
+
function shallowEqualOptions(left, right) {
|
|
4
|
+
const leftKeys = Object.keys(left);
|
|
5
|
+
const rightKeys = Object.keys(right);
|
|
6
|
+
return leftKeys.length === rightKeys.length
|
|
7
|
+
&& leftKeys.every((key) => Object.is(left[key], right[key]));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Declarative PNLight wrapper around DivKit's client renderer.
|
|
11
|
+
*
|
|
12
|
+
* PNLight-owned flow navigation, safe-area/scaling variables, dialogs,
|
|
13
|
+
* haptics, Lottie, and custom components are installed automatically.
|
|
14
|
+
*/
|
|
15
|
+
export function RemoteUi(props) {
|
|
16
|
+
const targetRef = useRef(null);
|
|
17
|
+
const { className, style, onStat, onCustomAction, onError, onPNLightAction, ...renderOptions } = props;
|
|
18
|
+
const callbackRef = useRef({});
|
|
19
|
+
callbackRef.current = { onStat, onCustomAction, onError, onPNLightAction };
|
|
20
|
+
const stableOptionsRef = useRef(renderOptions);
|
|
21
|
+
if (!shallowEqualOptions(stableOptionsRef.current, renderOptions)) {
|
|
22
|
+
stableOptionsRef.current = renderOptions;
|
|
23
|
+
}
|
|
24
|
+
const stableRenderOptions = stableOptionsRef.current;
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const target = targetRef.current;
|
|
27
|
+
if (!target)
|
|
28
|
+
return;
|
|
29
|
+
const mounted = mountRemoteUi({
|
|
30
|
+
...stableRenderOptions,
|
|
31
|
+
target,
|
|
32
|
+
onStat: (...args) => callbackRef.current.onStat?.(...args),
|
|
33
|
+
onCustomAction: (...args) => callbackRef.current.onCustomAction?.(...args),
|
|
34
|
+
onError: (...args) => callbackRef.current.onError?.(...args),
|
|
35
|
+
onPNLightAction: (...args) => callbackRef.current.onPNLightAction?.(...args)
|
|
36
|
+
});
|
|
37
|
+
return () => mounted.destroy();
|
|
38
|
+
}, [stableRenderOptions]);
|
|
39
|
+
return createElement("div", {
|
|
40
|
+
ref: targetRef,
|
|
41
|
+
className,
|
|
42
|
+
style,
|
|
43
|
+
suppressHydrationWarning: true
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** A descriptive alias for teams that want to distinguish it from host UI. */
|
|
47
|
+
export const PNLightDivKit = RemoteUi;
|
|
48
|
+
//# sourceMappingURL=RemoteUi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteUi.js","sourceRoot":"","sources":["../src/RemoteUi.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EACT,MAAM,EAGP,MAAM,OAAO,CAAC;AACf,OAAO,EACL,aAAa,EAEd,MAAM,cAAc,CAAC;AAYtB,SAAS,mBAAmB,CAC1B,IAA0E,EAC1E,KAA2E;IAE3E,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAA6B,CAAC;IAC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