@whop/embedded-components-react-js 0.0.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/dist/chunk-NSSMTXJJ.mjs +9 -0
- package/dist/chunk-NSSMTXJJ.mjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/use-element-snapshot.d.ts +5 -0
- package/dist/lib/use-element-snapshot.js +64 -0
- package/dist/lib/use-element-snapshot.js.map +1 -0
- package/dist/lib/use-element-snapshot.mjs +41 -0
- package/dist/lib/use-element-snapshot.mjs.map +1 -0
- package/dist/payouts/elements/balance.d.ts +16 -0
- package/dist/payouts/elements/balance.js +86 -0
- package/dist/payouts/elements/balance.js.map +1 -0
- package/dist/payouts/elements/balance.mjs +56 -0
- package/dist/payouts/elements/balance.mjs.map +1 -0
- package/dist/payouts/elements/index.d.ts +5 -0
- package/dist/payouts/elements/index.js +21 -0
- package/dist/payouts/elements/index.js.map +1 -0
- package/dist/payouts/elements/index.mjs +3 -0
- package/dist/payouts/elements/index.mjs.map +1 -0
- package/dist/payouts/elements/verify.d.ts +16 -0
- package/dist/payouts/elements/verify.js +83 -0
- package/dist/payouts/elements/verify.js.map +1 -0
- package/dist/payouts/elements/verify.mjs +56 -0
- package/dist/payouts/elements/verify.mjs.map +1 -0
- package/dist/payouts/elements/withdraw-button.d.ts +16 -0
- package/dist/payouts/elements/withdraw-button.js +86 -0
- package/dist/payouts/elements/withdraw-button.js.map +1 -0
- package/dist/payouts/elements/withdraw-button.mjs +56 -0
- package/dist/payouts/elements/withdraw-button.mjs.map +1 -0
- package/dist/payouts/index.d.ts +6 -0
- package/dist/payouts/index.js +20 -0
- package/dist/payouts/index.js.map +1 -0
- package/dist/payouts/index.mjs +2 -0
- package/dist/payouts/index.mjs.map +1 -0
- package/dist/payouts/session.d.ts +7 -0
- package/dist/payouts/session.js +77 -0
- package/dist/payouts/session.js.map +1 -0
- package/dist/payouts/session.mjs +45 -0
- package/dist/payouts/session.mjs.map +1 -0
- package/dist/provider.d.ts +11 -0
- package/dist/provider.js +116 -0
- package/dist/provider.js.map +1 -0
- package/dist/provider.mjs +87 -0
- package/dist/provider.mjs.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var withdraw_button_exports = {};
|
|
31
|
+
__export(withdraw_button_exports, {
|
|
32
|
+
WithdrawButtonElement: () => WithdrawButtonElement
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(withdraw_button_exports);
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import_use_element_snapshot = require("../../lib/use-element-snapshot");
|
|
37
|
+
var import_session = require("../session");
|
|
38
|
+
function WithdrawButtonElement({
|
|
39
|
+
options = {},
|
|
40
|
+
className,
|
|
41
|
+
style,
|
|
42
|
+
onReady,
|
|
43
|
+
fallback
|
|
44
|
+
}) {
|
|
45
|
+
const payoutsSession = (0, import_session.usePayoutsSession)();
|
|
46
|
+
const ref = (0, import_react.useRef)(null);
|
|
47
|
+
const element = (0, import_react.useMemo)(() => {
|
|
48
|
+
if (!payoutsSession) return null;
|
|
49
|
+
const createdElement = payoutsSession.createElement(
|
|
50
|
+
WithdrawButtonElement,
|
|
51
|
+
options
|
|
52
|
+
);
|
|
53
|
+
return createdElement;
|
|
54
|
+
}, [payoutsSession]);
|
|
55
|
+
const elementSnapshot = (0, import_use_element_snapshot.useElementSnapshot)(element);
|
|
56
|
+
const isReady = elementSnapshot?.state === "ready";
|
|
57
|
+
(0, import_react.useEffect)(() => {
|
|
58
|
+
if (!element) return;
|
|
59
|
+
element.updateOptions(options);
|
|
60
|
+
}, [options, element]);
|
|
61
|
+
(0, import_react.useEffect)(() => {
|
|
62
|
+
if (!element || !onReady) return;
|
|
63
|
+
element.on("ready", onReady);
|
|
64
|
+
return () => {
|
|
65
|
+
element.off("ready", onReady);
|
|
66
|
+
};
|
|
67
|
+
}, [element, onReady]);
|
|
68
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
69
|
+
if (!element || !ref.current) return;
|
|
70
|
+
element.mount(ref.current);
|
|
71
|
+
return () => {
|
|
72
|
+
element.unmount();
|
|
73
|
+
};
|
|
74
|
+
}, [element, ref.current]);
|
|
75
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
|
|
76
|
+
"div",
|
|
77
|
+
{
|
|
78
|
+
style: { ...style, visibility: isReady ? "visible" : "hidden" },
|
|
79
|
+
className,
|
|
80
|
+
ref
|
|
81
|
+
}
|
|
82
|
+
), !isReady && (fallback ?? null));
|
|
83
|
+
}
|
|
84
|
+
WithdrawButtonElement.displayName = "WithdrawButtonElement";
|
|
85
|
+
WithdrawButtonElement.type = "withdraw-button-element";
|
|
86
|
+
//# sourceMappingURL=withdraw-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/payouts/elements/withdraw-button.tsx"],"sourcesContent":["\"use client\";\n\nimport type { WithdrawButtonElementOptions } from \"@whop/embedded-components-vanilla-js/types\";\n\nimport React, { useEffect, useLayoutEffect, useMemo, useRef } from \"react\";\nimport { useElementSnapshot } from \"../../lib/use-element-snapshot\";\nimport { usePayoutsSession } from \"../session\";\n\nexport function WithdrawButtonElement({\n\toptions = {},\n\tclassName,\n\tstyle,\n\tonReady,\n\tfallback,\n}: {\n\toptions?: WithdrawButtonElementOptions;\n\tclassName?: string;\n\tstyle?: React.CSSProperties;\n\tonReady?: () => void;\n\tfallback?: React.ReactNode;\n}) {\n\tconst payoutsSession = usePayoutsSession();\n\tconst ref = useRef<HTMLDivElement>(null);\n\tconst element = useMemo(() => {\n\t\tif (!payoutsSession) return null;\n\t\tconst createdElement = payoutsSession.createElement(\n\t\t\tWithdrawButtonElement,\n\t\t\toptions,\n\t\t);\n\t\treturn createdElement;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [payoutsSession]);\n\n\tconst elementSnapshot = useElementSnapshot(element);\n\n\tconst isReady = elementSnapshot?.state === \"ready\";\n\n\tuseEffect(() => {\n\t\tif (!element) return;\n\t\telement.updateOptions(options);\n\t}, [options, element]);\n\n\tuseEffect(() => {\n\t\tif (!element || !onReady) return;\n\t\telement.on(\"ready\", onReady);\n\t\treturn () => {\n\t\t\telement.off(\"ready\", onReady);\n\t\t};\n\t}, [element, onReady]);\n\n\tuseLayoutEffect(() => {\n\t\tif (!element || !ref.current) return;\n\t\telement.mount(ref.current);\n\t\treturn () => {\n\t\t\telement.unmount();\n\t\t};\n\t}, [element, ref.current]);\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tstyle={{ ...style, visibility: isReady ? \"visible\" : \"hidden\" }}\n\t\t\t\tclassName={className}\n\t\t\t\tref={ref}\n\t\t\t/>\n\t\t\t{!isReady && (fallback ?? null)}\n\t\t</>\n\t);\n}\n\nWithdrawButtonElement.displayName = \"WithdrawButtonElement\";\nWithdrawButtonElement.type = \"withdraw-button-element\" as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAmE;AACnE,kCAAmC;AACnC,qBAAkC;AAE3B,SAAS,sBAAsB;AAAA,EACrC,UAAU,CAAC;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAMG;AACF,QAAM,qBAAiB,kCAAkB;AACzC,QAAM,UAAM,qBAAuB,IAAI;AACvC,QAAM,cAAU,sBAAQ,MAAM;AAC7B,QAAI,CAAC,eAAgB,QAAO;AAC5B,UAAM,iBAAiB,eAAe;AAAA,MACrC;AAAA,MACA;AAAA,IACD;AACA,WAAO;AAAA,EAER,GAAG,CAAC,cAAc,CAAC;AAEnB,QAAM,sBAAkB,gDAAmB,OAAO;AAElD,QAAM,UAAU,iBAAiB,UAAU;AAE3C,8BAAU,MAAM;AACf,QAAI,CAAC,QAAS;AACd,YAAQ,cAAc,OAAO;AAAA,EAC9B,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,8BAAU,MAAM;AACf,QAAI,CAAC,WAAW,CAAC,QAAS;AAC1B,YAAQ,GAAG,SAAS,OAAO;AAC3B,WAAO,MAAM;AACZ,cAAQ,IAAI,SAAS,OAAO;AAAA,IAC7B;AAAA,EACD,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,oCAAgB,MAAM;AACrB,QAAI,CAAC,WAAW,CAAC,IAAI,QAAS;AAC9B,YAAQ,MAAM,IAAI,OAAO;AACzB,WAAO,MAAM;AACZ,cAAQ,QAAQ;AAAA,IACjB;AAAA,EACD,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC;AAEzB,SACC,6BAAAA,QAAA,2BAAAA,QAAA,gBACC,6BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACA,OAAO,EAAE,GAAG,OAAO,YAAY,UAAU,YAAY,SAAS;AAAA,MAC9D;AAAA,MACA;AAAA;AAAA,EACD,GACC,CAAC,YAAY,YAAY,KAC3B;AAEF;AAEA,sBAAsB,cAAc;AACpC,sBAAsB,OAAO;","names":["React"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../../chunk-NSSMTXJJ.mjs";
|
|
3
|
+
import React, { useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { useElementSnapshot } from "../../lib/use-element-snapshot.mjs";
|
|
5
|
+
import { usePayoutsSession } from "../session.mjs";
|
|
6
|
+
function WithdrawButtonElement({ options = {}, className, style, onReady, fallback }) {
|
|
7
|
+
const payoutsSession = usePayoutsSession();
|
|
8
|
+
const ref = useRef(null);
|
|
9
|
+
const element = useMemo(()=>{
|
|
10
|
+
if (!payoutsSession) return null;
|
|
11
|
+
const createdElement = payoutsSession.createElement(WithdrawButtonElement, options);
|
|
12
|
+
return createdElement;
|
|
13
|
+
}, [
|
|
14
|
+
payoutsSession
|
|
15
|
+
]);
|
|
16
|
+
const elementSnapshot = useElementSnapshot(element);
|
|
17
|
+
const isReady = elementSnapshot?.state === "ready";
|
|
18
|
+
useEffect(()=>{
|
|
19
|
+
if (!element) return;
|
|
20
|
+
element.updateOptions(options);
|
|
21
|
+
}, [
|
|
22
|
+
options,
|
|
23
|
+
element
|
|
24
|
+
]);
|
|
25
|
+
useEffect(()=>{
|
|
26
|
+
if (!element || !onReady) return;
|
|
27
|
+
element.on("ready", onReady);
|
|
28
|
+
return ()=>{
|
|
29
|
+
element.off("ready", onReady);
|
|
30
|
+
};
|
|
31
|
+
}, [
|
|
32
|
+
element,
|
|
33
|
+
onReady
|
|
34
|
+
]);
|
|
35
|
+
useLayoutEffect(()=>{
|
|
36
|
+
if (!element || !ref.current) return;
|
|
37
|
+
element.mount(ref.current);
|
|
38
|
+
return ()=>{
|
|
39
|
+
element.unmount();
|
|
40
|
+
};
|
|
41
|
+
}, [
|
|
42
|
+
element,
|
|
43
|
+
ref.current
|
|
44
|
+
]);
|
|
45
|
+
return React.createElement(React.Fragment, null, React.createElement("div", {
|
|
46
|
+
style: {
|
|
47
|
+
...style,
|
|
48
|
+
visibility: isReady ? "visible" : "hidden"
|
|
49
|
+
},
|
|
50
|
+
className,
|
|
51
|
+
ref
|
|
52
|
+
}), !isReady && (fallback ?? null));
|
|
53
|
+
}
|
|
54
|
+
WithdrawButtonElement.displayName = "WithdrawButtonElement";
|
|
55
|
+
WithdrawButtonElement.type = "withdraw-button-element";
|
|
56
|
+
export { WithdrawButtonElement };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/payouts/elements/withdraw-button.tsx"],"sourcesContent":["\"use client\";\n\nimport type { WithdrawButtonElementOptions } from \"@whop/embedded-components-vanilla-js/types\";\n\nimport React, { useEffect, useLayoutEffect, useMemo, useRef } from \"react\";\nimport { useElementSnapshot } from \"../../lib/use-element-snapshot\";\nimport { usePayoutsSession } from \"../session\";\n\nexport function WithdrawButtonElement({\n\toptions = {},\n\tclassName,\n\tstyle,\n\tonReady,\n\tfallback,\n}: {\n\toptions?: WithdrawButtonElementOptions;\n\tclassName?: string;\n\tstyle?: React.CSSProperties;\n\tonReady?: () => void;\n\tfallback?: React.ReactNode;\n}) {\n\tconst payoutsSession = usePayoutsSession();\n\tconst ref = useRef<HTMLDivElement>(null);\n\tconst element = useMemo(() => {\n\t\tif (!payoutsSession) return null;\n\t\tconst createdElement = payoutsSession.createElement(\n\t\t\tWithdrawButtonElement,\n\t\t\toptions,\n\t\t);\n\t\treturn createdElement;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [payoutsSession]);\n\n\tconst elementSnapshot = useElementSnapshot(element);\n\n\tconst isReady = elementSnapshot?.state === \"ready\";\n\n\tuseEffect(() => {\n\t\tif (!element) return;\n\t\telement.updateOptions(options);\n\t}, [options, element]);\n\n\tuseEffect(() => {\n\t\tif (!element || !onReady) return;\n\t\telement.on(\"ready\", onReady);\n\t\treturn () => {\n\t\t\telement.off(\"ready\", onReady);\n\t\t};\n\t}, [element, onReady]);\n\n\tuseLayoutEffect(() => {\n\t\tif (!element || !ref.current) return;\n\t\telement.mount(ref.current);\n\t\treturn () => {\n\t\t\telement.unmount();\n\t\t};\n\t}, [element, ref.current]);\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tstyle={{ ...style, visibility: isReady ? \"visible\" : \"hidden\" }}\n\t\t\t\tclassName={className}\n\t\t\t\tref={ref}\n\t\t\t/>\n\t\t\t{!isReady && (fallback ?? null)}\n\t\t</>\n\t);\n}\n\nWithdrawButtonElement.displayName = \"WithdrawButtonElement\";\nWithdrawButtonElement.type = \"withdraw-button-element\" as const;\n"],"mappings":";;AAIA,OAAO,SAAS,WAAW,iBAAiB,SAAS,cAAc;AACnE,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAE3B,SAAS,sBAAsB;AAAA,EACrC,UAAU,CAAC;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAMG;AACF,QAAM,iBAAiB,kBAAkB;AACzC,QAAM,MAAM,OAAuB,IAAI;AACvC,QAAM,UAAU,QAAQ,MAAM;AAC7B,QAAI,CAAC,eAAgB,QAAO;AAC5B,UAAM,iBAAiB,eAAe;AAAA,MACrC;AAAA,MACA;AAAA,IACD;AACA,WAAO;AAAA,EAER,GAAG,CAAC,cAAc,CAAC;AAEnB,QAAM,kBAAkB,mBAAmB,OAAO;AAElD,QAAM,UAAU,iBAAiB,UAAU;AAE3C,YAAU,MAAM;AACf,QAAI,CAAC,QAAS;AACd,YAAQ,cAAc,OAAO;AAAA,EAC9B,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,YAAU,MAAM;AACf,QAAI,CAAC,WAAW,CAAC,QAAS;AAC1B,YAAQ,GAAG,SAAS,OAAO;AAC3B,WAAO,MAAM;AACZ,cAAQ,IAAI,SAAS,OAAO;AAAA,IAC7B;AAAA,EACD,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,kBAAgB,MAAM;AACrB,QAAI,CAAC,WAAW,CAAC,IAAI,QAAS;AAC9B,YAAQ,MAAM,IAAI,OAAO;AACzB,WAAO,MAAM;AACZ,cAAQ,QAAQ;AAAA,IACjB;AAAA,EACD,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC;AAEzB,SACC,0DACC;AAAA,IAAC;AAAA;AAAA,MACA,OAAO,EAAE,GAAG,OAAO,YAAY,UAAU,YAAY,SAAS;AAAA,MAC9D;AAAA,MACA;AAAA;AAAA,EACD,GACC,CAAC,YAAY,YAAY,KAC3B;AAEF;AAEA,sBAAsB,cAAc;AACpC,sBAAsB,OAAO;","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PayoutsSession, usePayoutsSession } from './session.js';
|
|
2
|
+
export { VerifyElement } from './elements/verify.js';
|
|
3
|
+
export { WithdrawButtonElement } from './elements/withdraw-button.js';
|
|
4
|
+
export { BalanceElement } from './elements/balance.js';
|
|
5
|
+
import '@whop/embedded-components-vanilla-js/types';
|
|
6
|
+
import 'react';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var payouts_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(payouts_exports);
|
|
18
|
+
__reExport(payouts_exports, require("./session"), module.exports);
|
|
19
|
+
__reExport(payouts_exports, require("./elements"), module.exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payouts/index.tsx"],"sourcesContent":["export * from \"./session\";\nexport * from \"./elements\";\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,sBAAd;AACA,4BAAc,uBADd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payouts/index.tsx"],"sourcesContent":["export * from \"./session\";\nexport * from \"./elements\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PayoutsSession as PayoutsSession$1, PayoutsSessionOptions } from '@whop/embedded-components-vanilla-js/types';
|
|
2
|
+
import React, { PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
declare function usePayoutsSession(): PayoutsSession$1 | null;
|
|
5
|
+
declare function PayoutsSession({ children, currency, token, }: PropsWithChildren<PayoutsSessionOptions>): React.JSX.Element;
|
|
6
|
+
|
|
7
|
+
export { PayoutsSession, usePayoutsSession };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var session_exports = {};
|
|
31
|
+
__export(session_exports, {
|
|
32
|
+
PayoutsSession: () => PayoutsSession,
|
|
33
|
+
usePayoutsSession: () => usePayoutsSession
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(session_exports);
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var import_react2 = require("react");
|
|
38
|
+
var import_provider = require("../provider");
|
|
39
|
+
const PayoutsSessionContext = (0, import_react2.createContext)(null);
|
|
40
|
+
function usePayoutsSession() {
|
|
41
|
+
const ctx = (0, import_react2.useContext)(PayoutsSessionContext);
|
|
42
|
+
if (!ctx) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"usePayoutsSession must be used within a PayoutsSessionProvider"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return ctx.payoutsSession;
|
|
48
|
+
}
|
|
49
|
+
function PayoutsSession({
|
|
50
|
+
children,
|
|
51
|
+
currency,
|
|
52
|
+
token
|
|
53
|
+
}) {
|
|
54
|
+
const elements = (0, import_provider.useElements)();
|
|
55
|
+
const payoutsSession = (0, import_react2.useMemo)(() => {
|
|
56
|
+
if (!elements) return null;
|
|
57
|
+
return elements.createPayoutsSession({
|
|
58
|
+
token,
|
|
59
|
+
currency
|
|
60
|
+
});
|
|
61
|
+
}, [elements]);
|
|
62
|
+
(0, import_react2.useEffect)(() => {
|
|
63
|
+
if (!payoutsSession) return;
|
|
64
|
+
payoutsSession.updateOptions({
|
|
65
|
+
token,
|
|
66
|
+
currency
|
|
67
|
+
});
|
|
68
|
+
}, [payoutsSession, currency, token]);
|
|
69
|
+
const value = (0, import_react2.useMemo)(
|
|
70
|
+
() => ({
|
|
71
|
+
payoutsSession
|
|
72
|
+
}),
|
|
73
|
+
[payoutsSession]
|
|
74
|
+
);
|
|
75
|
+
return /* @__PURE__ */ import_react.default.createElement(PayoutsSessionContext.Provider, { value }, children);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payouts/session.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tPayoutsSessionOptions,\n\tPayoutsSession as PayoutsSessionType,\n} from \"@whop/embedded-components-vanilla-js/types\";\nimport type { PropsWithChildren } from \"react\";\n\nimport React from \"react\";\nimport { createContext, useContext, useEffect, useMemo } from \"react\";\nimport { useElements } from \"../provider\";\n\ninterface ContextState {\n\tpayoutsSession: PayoutsSessionType | null;\n}\n\nconst PayoutsSessionContext = createContext<ContextState | null>(null);\n\nexport function usePayoutsSession() {\n\tconst ctx = useContext(PayoutsSessionContext);\n\tif (!ctx) {\n\t\tthrow new Error(\n\t\t\t\"usePayoutsSession must be used within a PayoutsSessionProvider\",\n\t\t);\n\t}\n\treturn ctx.payoutsSession;\n}\n\nexport function PayoutsSession({\n\tchildren,\n\tcurrency,\n\ttoken,\n}: PropsWithChildren<PayoutsSessionOptions>) {\n\tconst elements = useElements();\n\n\tconst payoutsSession = useMemo(() => {\n\t\tif (!elements) return null;\n\t\treturn elements.createPayoutsSession({\n\t\t\ttoken,\n\t\t\tcurrency,\n\t\t});\n\t}, [elements]);\n\n\tuseEffect(() => {\n\t\tif (!payoutsSession) return;\n\n\t\tpayoutsSession.updateOptions({\n\t\t\ttoken,\n\t\t\tcurrency,\n\t\t});\n\t}, [payoutsSession, currency, token]);\n\n\tconst value: ContextState = useMemo(\n\t\t() => ({\n\t\t\tpayoutsSession,\n\t\t}),\n\t\t[payoutsSession],\n\t);\n\n\treturn (\n\t\t<PayoutsSessionContext.Provider value={value}>\n\t\t\t{children}\n\t\t</PayoutsSessionContext.Provider>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,mBAAkB;AAClB,IAAAA,gBAA8D;AAC9D,sBAA4B;AAM5B,MAAM,4BAAwB,6BAAmC,IAAI;AAE9D,SAAS,oBAAoB;AACnC,QAAM,UAAM,0BAAW,qBAAqB;AAC5C,MAAI,CAAC,KAAK;AACT,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO,IAAI;AACZ;AAEO,SAAS,eAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,GAA6C;AAC5C,QAAM,eAAW,6BAAY;AAE7B,QAAM,qBAAiB,uBAAQ,MAAM;AACpC,QAAI,CAAC,SAAU,QAAO;AACtB,WAAO,SAAS,qBAAqB;AAAA,MACpC;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,+BAAU,MAAM;AACf,QAAI,CAAC,eAAgB;AAErB,mBAAe,cAAc;AAAA,MAC5B;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF,GAAG,CAAC,gBAAgB,UAAU,KAAK,CAAC;AAEpC,QAAM,YAAsB;AAAA,IAC3B,OAAO;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAC,cAAc;AAAA,EAChB;AAEA,SACC,6BAAAC,QAAA,cAAC,sBAAsB,UAAtB,EAA+B,SAC9B,QACF;AAEF;","names":["import_react","React"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-NSSMTXJJ.mjs";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useMemo } from "react";
|
|
5
|
+
import { useElements } from "../provider.mjs";
|
|
6
|
+
const PayoutsSessionContext = createContext(null);
|
|
7
|
+
function usePayoutsSession() {
|
|
8
|
+
const ctx = useContext(PayoutsSessionContext);
|
|
9
|
+
if (!ctx) {
|
|
10
|
+
throw new Error("usePayoutsSession must be used within a PayoutsSessionProvider");
|
|
11
|
+
}
|
|
12
|
+
return ctx.payoutsSession;
|
|
13
|
+
}
|
|
14
|
+
function PayoutsSession({ children, currency, token }) {
|
|
15
|
+
const elements = useElements();
|
|
16
|
+
const payoutsSession = useMemo(()=>{
|
|
17
|
+
if (!elements) return null;
|
|
18
|
+
return elements.createPayoutsSession({
|
|
19
|
+
token,
|
|
20
|
+
currency
|
|
21
|
+
});
|
|
22
|
+
}, [
|
|
23
|
+
elements
|
|
24
|
+
]);
|
|
25
|
+
useEffect(()=>{
|
|
26
|
+
if (!payoutsSession) return;
|
|
27
|
+
payoutsSession.updateOptions({
|
|
28
|
+
token,
|
|
29
|
+
currency
|
|
30
|
+
});
|
|
31
|
+
}, [
|
|
32
|
+
payoutsSession,
|
|
33
|
+
currency,
|
|
34
|
+
token
|
|
35
|
+
]);
|
|
36
|
+
const value = useMemo(()=>({
|
|
37
|
+
payoutsSession
|
|
38
|
+
}), [
|
|
39
|
+
payoutsSession
|
|
40
|
+
]);
|
|
41
|
+
return React.createElement(PayoutsSessionContext.Provider, {
|
|
42
|
+
value
|
|
43
|
+
}, children);
|
|
44
|
+
}
|
|
45
|
+
export { PayoutsSession, usePayoutsSession };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payouts/session.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tPayoutsSessionOptions,\n\tPayoutsSession as PayoutsSessionType,\n} from \"@whop/embedded-components-vanilla-js/types\";\nimport type { PropsWithChildren } from \"react\";\n\nimport React from \"react\";\nimport { createContext, useContext, useEffect, useMemo } from \"react\";\nimport { useElements } from \"../provider\";\n\ninterface ContextState {\n\tpayoutsSession: PayoutsSessionType | null;\n}\n\nconst PayoutsSessionContext = createContext<ContextState | null>(null);\n\nexport function usePayoutsSession() {\n\tconst ctx = useContext(PayoutsSessionContext);\n\tif (!ctx) {\n\t\tthrow new Error(\n\t\t\t\"usePayoutsSession must be used within a PayoutsSessionProvider\",\n\t\t);\n\t}\n\treturn ctx.payoutsSession;\n}\n\nexport function PayoutsSession({\n\tchildren,\n\tcurrency,\n\ttoken,\n}: PropsWithChildren<PayoutsSessionOptions>) {\n\tconst elements = useElements();\n\n\tconst payoutsSession = useMemo(() => {\n\t\tif (!elements) return null;\n\t\treturn elements.createPayoutsSession({\n\t\t\ttoken,\n\t\t\tcurrency,\n\t\t});\n\t}, [elements]);\n\n\tuseEffect(() => {\n\t\tif (!payoutsSession) return;\n\n\t\tpayoutsSession.updateOptions({\n\t\t\ttoken,\n\t\t\tcurrency,\n\t\t});\n\t}, [payoutsSession, currency, token]);\n\n\tconst value: ContextState = useMemo(\n\t\t() => ({\n\t\t\tpayoutsSession,\n\t\t}),\n\t\t[payoutsSession],\n\t);\n\n\treturn (\n\t\t<PayoutsSessionContext.Provider value={value}>\n\t\t\t{children}\n\t\t</PayoutsSessionContext.Provider>\n\t);\n}\n"],"mappings":";;AAQA,OAAO,WAAW;AAClB,SAAS,eAAe,YAAY,WAAW,eAAe;AAC9D,SAAS,mBAAmB;AAM5B,MAAM,wBAAwB,cAAmC,IAAI;AAE9D,SAAS,oBAAoB;AACnC,QAAM,MAAM,WAAW,qBAAqB;AAC5C,MAAI,CAAC,KAAK;AACT,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO,IAAI;AACZ;AAEO,SAAS,eAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,GAA6C;AAC5C,QAAM,WAAW,YAAY;AAE7B,QAAM,iBAAiB,QAAQ,MAAM;AACpC,QAAI,CAAC,SAAU,QAAO;AACtB,WAAO,SAAS,qBAAqB;AAAA,MACpC;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,YAAU,MAAM;AACf,QAAI,CAAC,eAAgB;AAErB,mBAAe,cAAc;AAAA,MAC5B;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF,GAAG,CAAC,gBAAgB,UAAU,KAAK,CAAC;AAEpC,QAAM,QAAsB;AAAA,IAC3B,OAAO;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAC,cAAc;AAAA,EAChB;AAEA,SACC,oCAAC,sBAAsB,UAAtB,EAA+B,SAC9B,QACF;AAEF;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WhopElements, WhopElementsOptions } from '@whop/embedded-components-vanilla-js/types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
declare function useElements(): WhopElements | null;
|
|
5
|
+
type ElementsProp = PromiseLike<WhopElements | null> | WhopElements | null;
|
|
6
|
+
declare function Elements({ children, elements: elementsProp, appearance, locale, }: {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
elements: ElementsProp;
|
|
9
|
+
} & WhopElementsOptions): React.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { Elements, useElements };
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
+
var provider_exports = {};
|
|
33
|
+
__export(provider_exports, {
|
|
34
|
+
Elements: () => Elements,
|
|
35
|
+
useElements: () => useElements
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(provider_exports);
|
|
38
|
+
var import_react = __toESM(require("react"));
|
|
39
|
+
var import_react2 = require("react");
|
|
40
|
+
const ElementsContext = (0, import_react2.createContext)(null);
|
|
41
|
+
function useElements() {
|
|
42
|
+
const ctx = (0, import_react2.useContext)(ElementsContext);
|
|
43
|
+
if (!ctx) {
|
|
44
|
+
throw new Error("useElements must be used within a ElementsProvider");
|
|
45
|
+
}
|
|
46
|
+
return ctx.elements;
|
|
47
|
+
}
|
|
48
|
+
function normalizeElementsProp(prop) {
|
|
49
|
+
if (prop instanceof Promise) return prop;
|
|
50
|
+
return Promise.resolve(prop);
|
|
51
|
+
}
|
|
52
|
+
class PromiseStore {
|
|
53
|
+
constructor(promise) {
|
|
54
|
+
__publicField(this, "subscribers", /* @__PURE__ */ new Set());
|
|
55
|
+
__publicField(this, "value", { state: "pending" });
|
|
56
|
+
__publicField(this, "subscribe", (listener) => {
|
|
57
|
+
this.subscribers.add(listener);
|
|
58
|
+
return () => {
|
|
59
|
+
this.subscribers.delete(listener);
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
promise.then((value) => {
|
|
63
|
+
this.value = { state: "fulfilled", value };
|
|
64
|
+
for (const subscriber of this.subscribers) {
|
|
65
|
+
subscriber();
|
|
66
|
+
}
|
|
67
|
+
}).catch((err) => {
|
|
68
|
+
this.value = { state: "rejected", error: err };
|
|
69
|
+
for (const subscriber of this.subscribers) {
|
|
70
|
+
subscriber();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
getSnapshot() {
|
|
75
|
+
return this.value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function useAwaitElements(elements) {
|
|
79
|
+
const store = (0, import_react2.useMemo)(
|
|
80
|
+
() => new PromiseStore(Promise.resolve(elements)),
|
|
81
|
+
[elements]
|
|
82
|
+
);
|
|
83
|
+
const state = (0, import_react.useSyncExternalStore)(
|
|
84
|
+
store.subscribe,
|
|
85
|
+
() => {
|
|
86
|
+
const snapshot = store.getSnapshot();
|
|
87
|
+
if (snapshot.state === "fulfilled") {
|
|
88
|
+
return snapshot.value;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
},
|
|
92
|
+
() => null
|
|
93
|
+
);
|
|
94
|
+
return state;
|
|
95
|
+
}
|
|
96
|
+
function Elements({
|
|
97
|
+
children,
|
|
98
|
+
elements: elementsProp,
|
|
99
|
+
appearance,
|
|
100
|
+
locale
|
|
101
|
+
}) {
|
|
102
|
+
const elementsPromise = normalizeElementsProp(elementsProp);
|
|
103
|
+
const elements = useAwaitElements(elementsPromise);
|
|
104
|
+
(0, import_react2.useEffect)(() => {
|
|
105
|
+
if (!elements) return;
|
|
106
|
+
elements.updateOptions({ appearance, locale });
|
|
107
|
+
}, [elements, appearance, locale]);
|
|
108
|
+
const value = (0, import_react2.useMemo)(
|
|
109
|
+
() => ({
|
|
110
|
+
elements
|
|
111
|
+
}),
|
|
112
|
+
[elements]
|
|
113
|
+
);
|
|
114
|
+
return /* @__PURE__ */ import_react.default.createElement(ElementsContext.Provider, { value }, children);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tWhopElements,\n\tWhopElementsOptions,\n} from \"@whop/embedded-components-vanilla-js/types\";\n\nimport React, { useSyncExternalStore } from \"react\";\nimport { createContext, useContext, useEffect, useMemo } from \"react\";\n\ninterface ContextState {\n\telements: WhopElements | null;\n}\n\nconst ElementsContext = createContext<ContextState | null>(null);\n\nexport function useElements() {\n\tconst ctx = useContext(ElementsContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useElements must be used within a ElementsProvider\");\n\t}\n\n\treturn ctx.elements;\n}\n\ntype ElementsProp = PromiseLike<WhopElements | null> | WhopElements | null;\n\nfunction normalizeElementsProp(\n\tprop: ElementsProp,\n): Promise<Awaited<ElementsProp>> {\n\tif (prop instanceof Promise) return prop;\n\treturn Promise.resolve(prop);\n}\n\nclass PromiseStore<T> {\n\tprivate subscribers: Set<() => void> = new Set();\n\tprivate value:\n\t\t| {\n\t\t\t\tstate: \"pending\";\n\t\t }\n\t\t| {\n\t\t\t\tstate: \"fulfilled\";\n\t\t\t\tvalue: T;\n\t\t }\n\t\t| {\n\t\t\t\tstate: \"rejected\";\n\t\t\t\terror: unknown;\n\t\t } = { state: \"pending\" };\n\n\tconstructor(promise: Promise<T>) {\n\t\tpromise\n\t\t\t.then((value) => {\n\t\t\t\tthis.value = { state: \"fulfilled\", value };\n\t\t\t\tfor (const subscriber of this.subscribers) {\n\t\t\t\t\tsubscriber();\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((err) => {\n\t\t\t\tthis.value = { state: \"rejected\", error: err };\n\t\t\t\tfor (const subscriber of this.subscribers) {\n\t\t\t\t\tsubscriber();\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\tpublic getSnapshot() {\n\t\treturn this.value;\n\t}\n\n\tpublic subscribe = (listener: () => void) => {\n\t\tthis.subscribers.add(listener);\n\t\treturn () => {\n\t\t\tthis.subscribers.delete(listener);\n\t\t};\n\t};\n}\n\nfunction useAwaitElements(elements: ElementsProp | null) {\n\tconst store = useMemo(\n\t\t() => new PromiseStore(Promise.resolve(elements)),\n\t\t[elements],\n\t);\n\n\tconst state = useSyncExternalStore(\n\t\tstore.subscribe,\n\t\t() => {\n\t\t\tconst snapshot = store.getSnapshot();\n\t\t\tif (snapshot.state === \"fulfilled\") {\n\t\t\t\treturn snapshot.value;\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t\t() => null,\n\t);\n\n\treturn state;\n}\n\nexport function Elements({\n\tchildren,\n\telements: elementsProp,\n\tappearance,\n\tlocale,\n}: {\n\tchildren: React.ReactNode;\n\telements: ElementsProp;\n} & WhopElementsOptions) {\n\tconst elementsPromise = normalizeElementsProp(elementsProp);\n\tconst elements = useAwaitElements(elementsPromise);\n\n\tuseEffect(() => {\n\t\tif (!elements) return;\n\t\telements.updateOptions({ appearance, locale });\n\t}, [elements, appearance, locale]);\n\n\tconst value: ContextState = useMemo(\n\t\t() => ({\n\t\t\telements,\n\t\t}),\n\t\t[elements],\n\t);\n\n\treturn (\n\t\t<ElementsContext.Provider value={value}>\n\t\t\t{children}\n\t\t</ElementsContext.Provider>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAA4C;AAC5C,IAAAA,gBAA8D;AAM9D,MAAM,sBAAkB,6BAAmC,IAAI;AAExD,SAAS,cAAc;AAC7B,QAAM,UAAM,0BAAW,eAAe;AACtC,MAAI,CAAC,KAAK;AACT,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACrE;AAEA,SAAO,IAAI;AACZ;AAIA,SAAS,sBACR,MACiC;AACjC,MAAI,gBAAgB,QAAS,QAAO;AACpC,SAAO,QAAQ,QAAQ,IAAI;AAC5B;AAEA,MAAM,aAAgB;AAAA,EAerB,YAAY,SAAqB;AAdjC,wBAAQ,eAA+B,oBAAI,IAAI;AAC/C,wBAAQ,SAWD,EAAE,OAAO,UAAU;AAsB1B,wBAAO,aAAY,CAAC,aAAyB;AAC5C,WAAK,YAAY,IAAI,QAAQ;AAC7B,aAAO,MAAM;AACZ,aAAK,YAAY,OAAO,QAAQ;AAAA,MACjC;AAAA,IACD;AAxBC,YACE,KAAK,CAAC,UAAU;AAChB,WAAK,QAAQ,EAAE,OAAO,aAAa,MAAM;AACzC,iBAAW,cAAc,KAAK,aAAa;AAC1C,mBAAW;AAAA,MACZ;AAAA,IACD,CAAC,EACA,MAAM,CAAC,QAAQ;AACf,WAAK,QAAQ,EAAE,OAAO,YAAY,OAAO,IAAI;AAC7C,iBAAW,cAAc,KAAK,aAAa;AAC1C,mBAAW;AAAA,MACZ;AAAA,IACD,CAAC;AAAA,EACH;AAAA,EAEO,cAAc;AACpB,WAAO,KAAK;AAAA,EACb;AAQD;AAEA,SAAS,iBAAiB,UAA+B;AACxD,QAAM,YAAQ;AAAA,IACb,MAAM,IAAI,aAAa,QAAQ,QAAQ,QAAQ,CAAC;AAAA,IAChD,CAAC,QAAQ;AAAA,EACV;AAEA,QAAM,YAAQ;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AACL,YAAM,WAAW,MAAM,YAAY;AACnC,UAAI,SAAS,UAAU,aAAa;AACnC,eAAO,SAAS;AAAA,MACjB;AACA,aAAO;AAAA,IACR;AAAA,IACA,MAAM;AAAA,EACP;AAEA,SAAO;AACR;AAEO,SAAS,SAAS;AAAA,EACxB;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AACD,GAGyB;AACxB,QAAM,kBAAkB,sBAAsB,YAAY;AAC1D,QAAM,WAAW,iBAAiB,eAAe;AAEjD,+BAAU,MAAM;AACf,QAAI,CAAC,SAAU;AACf,aAAS,cAAc,EAAE,YAAY,OAAO,CAAC;AAAA,EAC9C,GAAG,CAAC,UAAU,YAAY,MAAM,CAAC;AAEjC,QAAM,YAAsB;AAAA,IAC3B,OAAO;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAC,QAAQ;AAAA,EACV;AAEA,SACC,6BAAAC,QAAA,cAAC,gBAAgB,UAAhB,EAAyB,SACxB,QACF;AAEF;","names":["import_react","React"]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { __publicField } from "./chunk-NSSMTXJJ.mjs";
|
|
3
|
+
import React, { useSyncExternalStore } from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useMemo } from "react";
|
|
5
|
+
const ElementsContext = createContext(null);
|
|
6
|
+
function useElements() {
|
|
7
|
+
const ctx = useContext(ElementsContext);
|
|
8
|
+
if (!ctx) {
|
|
9
|
+
throw new Error("useElements must be used within a ElementsProvider");
|
|
10
|
+
}
|
|
11
|
+
return ctx.elements;
|
|
12
|
+
}
|
|
13
|
+
function normalizeElementsProp(prop) {
|
|
14
|
+
if (prop instanceof Promise) return prop;
|
|
15
|
+
return Promise.resolve(prop);
|
|
16
|
+
}
|
|
17
|
+
class PromiseStore {
|
|
18
|
+
constructor(promise){
|
|
19
|
+
__publicField(this, "subscribers", new Set());
|
|
20
|
+
__publicField(this, "value", {
|
|
21
|
+
state: "pending"
|
|
22
|
+
});
|
|
23
|
+
__publicField(this, "subscribe", (listener)=>{
|
|
24
|
+
this.subscribers.add(listener);
|
|
25
|
+
return ()=>{
|
|
26
|
+
this.subscribers.delete(listener);
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
promise.then((value)=>{
|
|
30
|
+
this.value = {
|
|
31
|
+
state: "fulfilled",
|
|
32
|
+
value
|
|
33
|
+
};
|
|
34
|
+
for (const subscriber of this.subscribers){
|
|
35
|
+
subscriber();
|
|
36
|
+
}
|
|
37
|
+
}).catch((err)=>{
|
|
38
|
+
this.value = {
|
|
39
|
+
state: "rejected",
|
|
40
|
+
error: err
|
|
41
|
+
};
|
|
42
|
+
for (const subscriber of this.subscribers){
|
|
43
|
+
subscriber();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getSnapshot() {
|
|
48
|
+
return this.value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function useAwaitElements(elements) {
|
|
52
|
+
const store = useMemo(()=>new PromiseStore(Promise.resolve(elements)), [
|
|
53
|
+
elements
|
|
54
|
+
]);
|
|
55
|
+
const state = useSyncExternalStore(store.subscribe, ()=>{
|
|
56
|
+
const snapshot = store.getSnapshot();
|
|
57
|
+
if (snapshot.state === "fulfilled") {
|
|
58
|
+
return snapshot.value;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}, ()=>null);
|
|
62
|
+
return state;
|
|
63
|
+
}
|
|
64
|
+
function Elements({ children, elements: elementsProp, appearance, locale }) {
|
|
65
|
+
const elementsPromise = normalizeElementsProp(elementsProp);
|
|
66
|
+
const elements = useAwaitElements(elementsPromise);
|
|
67
|
+
useEffect(()=>{
|
|
68
|
+
if (!elements) return;
|
|
69
|
+
elements.updateOptions({
|
|
70
|
+
appearance,
|
|
71
|
+
locale
|
|
72
|
+
});
|
|
73
|
+
}, [
|
|
74
|
+
elements,
|
|
75
|
+
appearance,
|
|
76
|
+
locale
|
|
77
|
+
]);
|
|
78
|
+
const value = useMemo(()=>({
|
|
79
|
+
elements
|
|
80
|
+
}), [
|
|
81
|
+
elements
|
|
82
|
+
]);
|
|
83
|
+
return React.createElement(ElementsContext.Provider, {
|
|
84
|
+
value
|
|
85
|
+
}, children);
|
|
86
|
+
}
|
|
87
|
+
export { Elements, useElements };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tWhopElements,\n\tWhopElementsOptions,\n} from \"@whop/embedded-components-vanilla-js/types\";\n\nimport React, { useSyncExternalStore } from \"react\";\nimport { createContext, useContext, useEffect, useMemo } from \"react\";\n\ninterface ContextState {\n\telements: WhopElements | null;\n}\n\nconst ElementsContext = createContext<ContextState | null>(null);\n\nexport function useElements() {\n\tconst ctx = useContext(ElementsContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useElements must be used within a ElementsProvider\");\n\t}\n\n\treturn ctx.elements;\n}\n\ntype ElementsProp = PromiseLike<WhopElements | null> | WhopElements | null;\n\nfunction normalizeElementsProp(\n\tprop: ElementsProp,\n): Promise<Awaited<ElementsProp>> {\n\tif (prop instanceof Promise) return prop;\n\treturn Promise.resolve(prop);\n}\n\nclass PromiseStore<T> {\n\tprivate subscribers: Set<() => void> = new Set();\n\tprivate value:\n\t\t| {\n\t\t\t\tstate: \"pending\";\n\t\t }\n\t\t| {\n\t\t\t\tstate: \"fulfilled\";\n\t\t\t\tvalue: T;\n\t\t }\n\t\t| {\n\t\t\t\tstate: \"rejected\";\n\t\t\t\terror: unknown;\n\t\t } = { state: \"pending\" };\n\n\tconstructor(promise: Promise<T>) {\n\t\tpromise\n\t\t\t.then((value) => {\n\t\t\t\tthis.value = { state: \"fulfilled\", value };\n\t\t\t\tfor (const subscriber of this.subscribers) {\n\t\t\t\t\tsubscriber();\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((err) => {\n\t\t\t\tthis.value = { state: \"rejected\", error: err };\n\t\t\t\tfor (const subscriber of this.subscribers) {\n\t\t\t\t\tsubscriber();\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\tpublic getSnapshot() {\n\t\treturn this.value;\n\t}\n\n\tpublic subscribe = (listener: () => void) => {\n\t\tthis.subscribers.add(listener);\n\t\treturn () => {\n\t\t\tthis.subscribers.delete(listener);\n\t\t};\n\t};\n}\n\nfunction useAwaitElements(elements: ElementsProp | null) {\n\tconst store = useMemo(\n\t\t() => new PromiseStore(Promise.resolve(elements)),\n\t\t[elements],\n\t);\n\n\tconst state = useSyncExternalStore(\n\t\tstore.subscribe,\n\t\t() => {\n\t\t\tconst snapshot = store.getSnapshot();\n\t\t\tif (snapshot.state === \"fulfilled\") {\n\t\t\t\treturn snapshot.value;\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t\t() => null,\n\t);\n\n\treturn state;\n}\n\nexport function Elements({\n\tchildren,\n\telements: elementsProp,\n\tappearance,\n\tlocale,\n}: {\n\tchildren: React.ReactNode;\n\telements: ElementsProp;\n} & WhopElementsOptions) {\n\tconst elementsPromise = normalizeElementsProp(elementsProp);\n\tconst elements = useAwaitElements(elementsPromise);\n\n\tuseEffect(() => {\n\t\tif (!elements) return;\n\t\telements.updateOptions({ appearance, locale });\n\t}, [elements, appearance, locale]);\n\n\tconst value: ContextState = useMemo(\n\t\t() => ({\n\t\t\telements,\n\t\t}),\n\t\t[elements],\n\t);\n\n\treturn (\n\t\t<ElementsContext.Provider value={value}>\n\t\t\t{children}\n\t\t</ElementsContext.Provider>\n\t);\n}\n"],"mappings":";;;;AAOA,OAAO,SAAS,4BAA4B;AAC5C,SAAS,eAAe,YAAY,WAAW,eAAe;AAM9D,MAAM,kBAAkB,cAAmC,IAAI;AAExD,SAAS,cAAc;AAC7B,QAAM,MAAM,WAAW,eAAe;AACtC,MAAI,CAAC,KAAK;AACT,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACrE;AAEA,SAAO,IAAI;AACZ;AAIA,SAAS,sBACR,MACiC;AACjC,MAAI,gBAAgB,QAAS,QAAO;AACpC,SAAO,QAAQ,QAAQ,IAAI;AAC5B;AAEA,MAAM,aAAgB;AAAA,EAerB,YAAY,SAAqB;AAdjC,wBAAQ,eAA+B,oBAAI,IAAI;AAC/C,wBAAQ,SAWD,EAAE,OAAO,UAAU;AAsB1B,wBAAO,aAAY,CAAC,aAAyB;AAC5C,WAAK,YAAY,IAAI,QAAQ;AAC7B,aAAO,MAAM;AACZ,aAAK,YAAY,OAAO,QAAQ;AAAA,MACjC;AAAA,IACD;AAxBC,YACE,KAAK,CAAC,UAAU;AAChB,WAAK,QAAQ,EAAE,OAAO,aAAa,MAAM;AACzC,iBAAW,cAAc,KAAK,aAAa;AAC1C,mBAAW;AAAA,MACZ;AAAA,IACD,CAAC,EACA,MAAM,CAAC,QAAQ;AACf,WAAK,QAAQ,EAAE,OAAO,YAAY,OAAO,IAAI;AAC7C,iBAAW,cAAc,KAAK,aAAa;AAC1C,mBAAW;AAAA,MACZ;AAAA,IACD,CAAC;AAAA,EACH;AAAA,EAEO,cAAc;AACpB,WAAO,KAAK;AAAA,EACb;AAQD;AAEA,SAAS,iBAAiB,UAA+B;AACxD,QAAM,QAAQ;AAAA,IACb,MAAM,IAAI,aAAa,QAAQ,QAAQ,QAAQ,CAAC;AAAA,IAChD,CAAC,QAAQ;AAAA,EACV;AAEA,QAAM,QAAQ;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AACL,YAAM,WAAW,MAAM,YAAY;AACnC,UAAI,SAAS,UAAU,aAAa;AACnC,eAAO,SAAS;AAAA,MACjB;AACA,aAAO;AAAA,IACR;AAAA,IACA,MAAM;AAAA,EACP;AAEA,SAAO;AACR;AAEO,SAAS,SAAS;AAAA,EACxB;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AACD,GAGyB;AACxB,QAAM,kBAAkB,sBAAsB,YAAY;AAC1D,QAAM,WAAW,iBAAiB,eAAe;AAEjD,YAAU,MAAM;AACf,QAAI,CAAC,SAAU;AACf,aAAS,cAAc,EAAE,YAAY,OAAO,CAAC;AAAA,EAC9C,GAAG,CAAC,UAAU,YAAY,MAAM,CAAC;AAEjC,QAAM,QAAsB;AAAA,IAC3B,OAAO;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAC,QAAQ;AAAA,EACV;AAEA,SACC,oCAAC,gBAAgB,UAAhB,EAAyB,SACxB,QACF;AAEF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@whop/embedded-components-react-js",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "React components for Whop.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"jsnext:main": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"typing": "dist/index.d.ts",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"Whop",
|
|
12
|
+
"Whop.js",
|
|
13
|
+
"React",
|
|
14
|
+
"embedded",
|
|
15
|
+
"payments",
|
|
16
|
+
"payouts"
|
|
17
|
+
],
|
|
18
|
+
"author": "Whop (https://whop.com)",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@swc/core": "1.11.29",
|
|
25
|
+
"@types/node": "latest",
|
|
26
|
+
"@types/react": "^18.0.0",
|
|
27
|
+
"@types/react-dom": "^18.0.0",
|
|
28
|
+
"eslint": "latest",
|
|
29
|
+
"fast-glob": "^3.3.3",
|
|
30
|
+
"react": "18.1.0",
|
|
31
|
+
"react-dom": "18.1.0",
|
|
32
|
+
"rimraf": "^6.1.0",
|
|
33
|
+
"tsup": "latest",
|
|
34
|
+
"typescript": "latest",
|
|
35
|
+
"@local/eslint-config": "0.0.0",
|
|
36
|
+
"@whop/embedded-components-vanilla-js": "^0.0.0",
|
|
37
|
+
"@local/typescript-config": "0.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": ">=16.8.0 <20.0.0",
|
|
41
|
+
"react-dom": ">=16.8.0 <20.0.0",
|
|
42
|
+
"@whop/embedded-components-vanilla-js": "^0.0.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rimraf dist && NODE_ENV=production tsup",
|
|
46
|
+
"dev": "NODE_ENV=development tsup --watch"
|
|
47
|
+
}
|
|
48
|
+
}
|