@playruo/embed 1.1.1 → 1.1.2
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/dist/index.cjs +24 -3
- package/dist/index.d.cts +18 -5
- package/dist/index.d.ts +18 -5
- package/dist/index.js +24 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -56,6 +56,13 @@ var PlayruoEmbed = ({
|
|
|
56
56
|
const [state, setState] = (0, import_react.useState)(null);
|
|
57
57
|
const [errorMessage, setErrorMessage] = (0, import_react.useState)(null);
|
|
58
58
|
const src = (0, import_react.useMemo)(() => buildEmbedUrl({ baseUrl, operation, storeUrl }), [baseUrl, operation, storeUrl]);
|
|
59
|
+
const sendCommand = (type) => {
|
|
60
|
+
if (!iframeRef.current?.contentWindow) {
|
|
61
|
+
console.warn(`PlayruoEmbed: Cannot send ${type} command, iframe not ready`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
iframeRef.current.contentWindow.postMessage({ type }, "*");
|
|
65
|
+
};
|
|
59
66
|
(0, import_react.useEffect)(() => {
|
|
60
67
|
const handler = (event) => {
|
|
61
68
|
const msg = event?.data ?? {};
|
|
@@ -82,10 +89,24 @@ var PlayruoEmbed = ({
|
|
|
82
89
|
const isAvailable = Boolean(isReady && state?.tryNow?.available);
|
|
83
90
|
const renderContent = () => {
|
|
84
91
|
if (!renderState) return null;
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
const actions = {
|
|
93
|
+
tryNow: () => sendCommand("try_now"),
|
|
94
|
+
buyNow: () => sendCommand("buy_now"),
|
|
95
|
+
canTryNow: Boolean(isReady && state?.tryNow?.available),
|
|
96
|
+
canBuyNow: Boolean(isReady && state?.buyNow?.available)
|
|
97
|
+
};
|
|
98
|
+
if (errorMessage) {
|
|
99
|
+
return renderState({ status: "error", message: errorMessage, actions });
|
|
100
|
+
}
|
|
101
|
+
if (!isReady) {
|
|
102
|
+
return renderState({ status: "loading", actions });
|
|
103
|
+
}
|
|
87
104
|
const message = !isAvailable ? state?.tryNow?.status ?? state?.buyNow?.status : void 0;
|
|
88
|
-
return renderState({
|
|
105
|
+
return renderState({
|
|
106
|
+
status: isAvailable ? "available" : "unavailable",
|
|
107
|
+
message,
|
|
108
|
+
actions
|
|
109
|
+
});
|
|
89
110
|
};
|
|
90
111
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className, children: [
|
|
91
112
|
renderContent(),
|
package/dist/index.d.cts
CHANGED
|
@@ -20,6 +20,21 @@ interface DemoCompletedPayload {
|
|
|
20
20
|
storeUrl?: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
interface PlayruoEmbedActions {
|
|
24
|
+
/** Start the demo session */
|
|
25
|
+
tryNow: () => void;
|
|
26
|
+
/** Request purchase (opens store URL) */
|
|
27
|
+
buyNow: () => void;
|
|
28
|
+
/** Whether try now is currently available */
|
|
29
|
+
canTryNow: boolean;
|
|
30
|
+
/** Whether buy now is currently available */
|
|
31
|
+
canBuyNow: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface PlayruoEmbedRenderState {
|
|
34
|
+
status: "loading" | "available" | "unavailable" | "error";
|
|
35
|
+
message?: string;
|
|
36
|
+
actions: PlayruoEmbedActions;
|
|
37
|
+
}
|
|
23
38
|
interface PlayruoEmbedProps {
|
|
24
39
|
baseUrl: string;
|
|
25
40
|
operation?: string;
|
|
@@ -35,11 +50,9 @@ interface PlayruoEmbedProps {
|
|
|
35
50
|
onError?: (error: string) => void;
|
|
36
51
|
/**
|
|
37
52
|
* Single render entry point representing the current status.
|
|
53
|
+
* Provides status, message, and available actions based on current state.
|
|
38
54
|
*/
|
|
39
|
-
renderState?: (render:
|
|
40
|
-
status: "loading" | "available" | "unavailable" | "error";
|
|
41
|
-
message?: string;
|
|
42
|
-
}) => ReactNode;
|
|
55
|
+
renderState?: (render: PlayruoEmbedRenderState) => ReactNode;
|
|
43
56
|
}
|
|
44
57
|
declare const PlayruoEmbed: FC<PlayruoEmbedProps>;
|
|
45
58
|
|
|
@@ -50,4 +63,4 @@ interface BuildUrlParams {
|
|
|
50
63
|
}
|
|
51
64
|
declare const buildEmbedUrl: ({ baseUrl, operation, storeUrl }: BuildUrlParams) => string;
|
|
52
65
|
|
|
53
|
-
export { PlayruoEmbed, type PlayruoEmbedMessage, type PlayruoEmbedState, buildEmbedUrl };
|
|
66
|
+
export { type DemoCompletedPayload, PlayruoEmbed, type PlayruoEmbedActions, type PlayruoEmbedMessage, type PlayruoEmbedProps, type PlayruoEmbedRenderState, type PlayruoEmbedState, buildEmbedUrl };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,21 @@ interface DemoCompletedPayload {
|
|
|
20
20
|
storeUrl?: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
interface PlayruoEmbedActions {
|
|
24
|
+
/** Start the demo session */
|
|
25
|
+
tryNow: () => void;
|
|
26
|
+
/** Request purchase (opens store URL) */
|
|
27
|
+
buyNow: () => void;
|
|
28
|
+
/** Whether try now is currently available */
|
|
29
|
+
canTryNow: boolean;
|
|
30
|
+
/** Whether buy now is currently available */
|
|
31
|
+
canBuyNow: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface PlayruoEmbedRenderState {
|
|
34
|
+
status: "loading" | "available" | "unavailable" | "error";
|
|
35
|
+
message?: string;
|
|
36
|
+
actions: PlayruoEmbedActions;
|
|
37
|
+
}
|
|
23
38
|
interface PlayruoEmbedProps {
|
|
24
39
|
baseUrl: string;
|
|
25
40
|
operation?: string;
|
|
@@ -35,11 +50,9 @@ interface PlayruoEmbedProps {
|
|
|
35
50
|
onError?: (error: string) => void;
|
|
36
51
|
/**
|
|
37
52
|
* Single render entry point representing the current status.
|
|
53
|
+
* Provides status, message, and available actions based on current state.
|
|
38
54
|
*/
|
|
39
|
-
renderState?: (render:
|
|
40
|
-
status: "loading" | "available" | "unavailable" | "error";
|
|
41
|
-
message?: string;
|
|
42
|
-
}) => ReactNode;
|
|
55
|
+
renderState?: (render: PlayruoEmbedRenderState) => ReactNode;
|
|
43
56
|
}
|
|
44
57
|
declare const PlayruoEmbed: FC<PlayruoEmbedProps>;
|
|
45
58
|
|
|
@@ -50,4 +63,4 @@ interface BuildUrlParams {
|
|
|
50
63
|
}
|
|
51
64
|
declare const buildEmbedUrl: ({ baseUrl, operation, storeUrl }: BuildUrlParams) => string;
|
|
52
65
|
|
|
53
|
-
export { PlayruoEmbed, type PlayruoEmbedMessage, type PlayruoEmbedState, buildEmbedUrl };
|
|
66
|
+
export { type DemoCompletedPayload, PlayruoEmbed, type PlayruoEmbedActions, type PlayruoEmbedMessage, type PlayruoEmbedProps, type PlayruoEmbedRenderState, type PlayruoEmbedState, buildEmbedUrl };
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,13 @@ var PlayruoEmbed = ({
|
|
|
29
29
|
const [state, setState] = useState(null);
|
|
30
30
|
const [errorMessage, setErrorMessage] = useState(null);
|
|
31
31
|
const src = useMemo(() => buildEmbedUrl({ baseUrl, operation, storeUrl }), [baseUrl, operation, storeUrl]);
|
|
32
|
+
const sendCommand = (type) => {
|
|
33
|
+
if (!iframeRef.current?.contentWindow) {
|
|
34
|
+
console.warn(`PlayruoEmbed: Cannot send ${type} command, iframe not ready`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
iframeRef.current.contentWindow.postMessage({ type }, "*");
|
|
38
|
+
};
|
|
32
39
|
useEffect(() => {
|
|
33
40
|
const handler = (event) => {
|
|
34
41
|
const msg = event?.data ?? {};
|
|
@@ -55,10 +62,24 @@ var PlayruoEmbed = ({
|
|
|
55
62
|
const isAvailable = Boolean(isReady && state?.tryNow?.available);
|
|
56
63
|
const renderContent = () => {
|
|
57
64
|
if (!renderState) return null;
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
const actions = {
|
|
66
|
+
tryNow: () => sendCommand("try_now"),
|
|
67
|
+
buyNow: () => sendCommand("buy_now"),
|
|
68
|
+
canTryNow: Boolean(isReady && state?.tryNow?.available),
|
|
69
|
+
canBuyNow: Boolean(isReady && state?.buyNow?.available)
|
|
70
|
+
};
|
|
71
|
+
if (errorMessage) {
|
|
72
|
+
return renderState({ status: "error", message: errorMessage, actions });
|
|
73
|
+
}
|
|
74
|
+
if (!isReady) {
|
|
75
|
+
return renderState({ status: "loading", actions });
|
|
76
|
+
}
|
|
60
77
|
const message = !isAvailable ? state?.tryNow?.status ?? state?.buyNow?.status : void 0;
|
|
61
|
-
return renderState({
|
|
78
|
+
return renderState({
|
|
79
|
+
status: isAvailable ? "available" : "unavailable",
|
|
80
|
+
message,
|
|
81
|
+
actions
|
|
82
|
+
});
|
|
62
83
|
};
|
|
63
84
|
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
64
85
|
renderContent(),
|