@whop/embedded-components-react-js 0.0.12 → 0.0.13-beta.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.
Files changed (113) hide show
  1. package/dist/chat/elements/chat.d.ts +11 -0
  2. package/dist/chat/elements/chat.js +30 -0
  3. package/dist/chat/elements/chat.js.map +1 -0
  4. package/dist/chat/elements/chat.mjs +8 -0
  5. package/dist/chat/elements/chat.mjs.map +1 -0
  6. package/dist/chat/elements/dms-list.d.ts +11 -0
  7. package/dist/chat/elements/dms-list.js +30 -0
  8. package/dist/chat/elements/dms-list.js.map +1 -0
  9. package/dist/chat/elements/dms-list.mjs +8 -0
  10. package/dist/chat/elements/dms-list.mjs.map +1 -0
  11. package/dist/chat/elements/index.d.ts +5 -0
  12. package/dist/chat/elements/index.js +27 -0
  13. package/dist/chat/elements/index.js.map +1 -0
  14. package/dist/chat/elements/index.mjs +4 -0
  15. package/dist/chat/elements/index.mjs.map +1 -0
  16. package/dist/chat/index.d.ts +6 -0
  17. package/dist/chat/index.js +20 -0
  18. package/dist/chat/index.js.map +1 -0
  19. package/dist/chat/index.mjs +2 -0
  20. package/dist/chat/index.mjs.map +1 -0
  21. package/dist/chat/session.d.ts +11 -0
  22. package/dist/chat/session.js +69 -0
  23. package/dist/chat/session.js.map +1 -0
  24. package/dist/chat/session.mjs +46 -0
  25. package/dist/chat/session.mjs.map +1 -0
  26. package/dist/chat/use-session-ref.d.ts +8 -0
  27. package/dist/chat/use-session-ref.js +29 -0
  28. package/dist/chat/use-session-ref.js.map +1 -0
  29. package/dist/chat/use-session-ref.mjs +7 -0
  30. package/dist/chat/use-session-ref.mjs.map +1 -0
  31. package/dist/chat/with-fallback.d.ts +55 -0
  32. package/dist/chat/with-fallback.js +85 -0
  33. package/dist/chat/with-fallback.js.map +1 -0
  34. package/dist/chat/with-fallback.mjs +58 -0
  35. package/dist/chat/with-fallback.mjs.map +1 -0
  36. package/dist/index.d.ts +6 -1
  37. package/dist/index.js +2 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +2 -0
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/payouts/elements/add-payout-method.d.ts +1 -1
  42. package/dist/payouts/elements/add-payout-method.js +1 -1
  43. package/dist/payouts/elements/add-payout-method.js.map +1 -1
  44. package/dist/payouts/elements/add-payout-method.mjs +1 -1
  45. package/dist/payouts/elements/add-payout-method.mjs.map +1 -1
  46. package/dist/payouts/elements/automatic-withdraw.d.ts +1 -1
  47. package/dist/payouts/elements/automatic-withdraw.js +1 -1
  48. package/dist/payouts/elements/automatic-withdraw.js.map +1 -1
  49. package/dist/payouts/elements/automatic-withdraw.mjs +1 -1
  50. package/dist/payouts/elements/automatic-withdraw.mjs.map +1 -1
  51. package/dist/payouts/elements/balance.d.ts +1 -1
  52. package/dist/payouts/elements/balance.js +1 -1
  53. package/dist/payouts/elements/balance.js.map +1 -1
  54. package/dist/payouts/elements/balance.mjs +1 -1
  55. package/dist/payouts/elements/balance.mjs.map +1 -1
  56. package/dist/payouts/elements/bnpl-reserve-balance-breakdown.d.ts +1 -1
  57. package/dist/payouts/elements/bnpl-reserve-balance-breakdown.js +1 -1
  58. package/dist/payouts/elements/bnpl-reserve-balance-breakdown.js.map +1 -1
  59. package/dist/payouts/elements/bnpl-reserve-balance-breakdown.mjs +1 -1
  60. package/dist/payouts/elements/bnpl-reserve-balance-breakdown.mjs.map +1 -1
  61. package/dist/payouts/elements/change-account-country.d.ts +1 -1
  62. package/dist/payouts/elements/change-account-country.js +1 -1
  63. package/dist/payouts/elements/change-account-country.js.map +1 -1
  64. package/dist/payouts/elements/change-account-country.mjs +1 -1
  65. package/dist/payouts/elements/change-account-country.mjs.map +1 -1
  66. package/dist/payouts/elements/generate-withdrawal-receipt.d.ts +1 -1
  67. package/dist/payouts/elements/generate-withdrawal-receipt.js +1 -1
  68. package/dist/payouts/elements/generate-withdrawal-receipt.js.map +1 -1
  69. package/dist/payouts/elements/generate-withdrawal-receipt.mjs +1 -1
  70. package/dist/payouts/elements/generate-withdrawal-receipt.mjs.map +1 -1
  71. package/dist/payouts/elements/index.d.ts +1 -1
  72. package/dist/payouts/elements/regular-reserve-balance-breakdown.d.ts +1 -1
  73. package/dist/payouts/elements/regular-reserve-balance-breakdown.js +1 -1
  74. package/dist/payouts/elements/regular-reserve-balance-breakdown.js.map +1 -1
  75. package/dist/payouts/elements/regular-reserve-balance-breakdown.mjs +1 -1
  76. package/dist/payouts/elements/regular-reserve-balance-breakdown.mjs.map +1 -1
  77. package/dist/payouts/elements/reset-account.d.ts +1 -1
  78. package/dist/payouts/elements/reset-account.js +1 -1
  79. package/dist/payouts/elements/reset-account.js.map +1 -1
  80. package/dist/payouts/elements/reset-account.mjs +1 -1
  81. package/dist/payouts/elements/reset-account.mjs.map +1 -1
  82. package/dist/payouts/elements/total-balance-breakdown.d.ts +1 -1
  83. package/dist/payouts/elements/total-balance-breakdown.js +1 -1
  84. package/dist/payouts/elements/total-balance-breakdown.js.map +1 -1
  85. package/dist/payouts/elements/total-balance-breakdown.mjs +1 -1
  86. package/dist/payouts/elements/total-balance-breakdown.mjs.map +1 -1
  87. package/dist/payouts/elements/verify.d.ts +1 -1
  88. package/dist/payouts/elements/verify.js +1 -1
  89. package/dist/payouts/elements/verify.js.map +1 -1
  90. package/dist/payouts/elements/verify.mjs +1 -1
  91. package/dist/payouts/elements/verify.mjs.map +1 -1
  92. package/dist/payouts/elements/withdraw-button.d.ts +1 -1
  93. package/dist/payouts/elements/withdraw-button.js +1 -1
  94. package/dist/payouts/elements/withdraw-button.js.map +1 -1
  95. package/dist/payouts/elements/withdraw-button.mjs +1 -1
  96. package/dist/payouts/elements/withdraw-button.mjs.map +1 -1
  97. package/dist/payouts/elements/withdrawal-breakdown.d.ts +1 -1
  98. package/dist/payouts/elements/withdrawal-breakdown.js +1 -1
  99. package/dist/payouts/elements/withdrawal-breakdown.js.map +1 -1
  100. package/dist/payouts/elements/withdrawal-breakdown.mjs +1 -1
  101. package/dist/payouts/elements/withdrawal-breakdown.mjs.map +1 -1
  102. package/dist/payouts/elements/withdrawals.d.ts +1 -1
  103. package/dist/payouts/elements/withdrawals.js +1 -1
  104. package/dist/payouts/elements/withdrawals.js.map +1 -1
  105. package/dist/payouts/elements/withdrawals.mjs +1 -1
  106. package/dist/payouts/elements/withdrawals.mjs.map +1 -1
  107. package/dist/payouts/index.d.ts +1 -1
  108. package/dist/{lib → payouts}/with-fallback.js +2 -2
  109. package/dist/{lib → payouts}/with-fallback.js.map +1 -1
  110. package/dist/{lib → payouts}/with-fallback.mjs +2 -2
  111. package/dist/{lib → payouts}/with-fallback.mjs.map +1 -1
  112. package/package.json +2 -2
  113. /package/dist/{lib → payouts}/with-fallback.d.ts +0 -0
@@ -0,0 +1,11 @@
1
+ import { WithFallbackPropsRequired } from '../with-fallback.js';
2
+ import * as _whop_embedded_components_vanilla_js_types from '@whop/embedded-components-vanilla-js/types';
3
+ import 'react';
4
+
5
+ declare const ChatElement: {
6
+ (props: WithFallbackPropsRequired<_whop_embedded_components_vanilla_js_types.ChatElementOptions>): React.ReactNode;
7
+ displayName: string;
8
+ type: string;
9
+ };
10
+
11
+ export { ChatElement };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var chat_exports = {};
21
+ __export(chat_exports, {
22
+ ChatElement: () => ChatElement
23
+ });
24
+ module.exports = __toCommonJS(chat_exports);
25
+ var import_with_fallback = require("../with-fallback");
26
+ const ChatElement = (0, import_with_fallback.withFallback)({
27
+ displayName: "ChatElement",
28
+ type: "chat-element"
29
+ });
30
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/chat/elements/chat.tsx"],"sourcesContent":["\"use client\";\n\nimport { withFallback } from \"../with-fallback\";\n\nexport const ChatElement = withFallback<\"chat-element\", true>({\n\tdisplayName: \"ChatElement\",\n\ttype: \"chat-element\",\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,2BAA6B;AAEtB,MAAM,kBAAc,mCAAmC;AAAA,EAC7D,aAAa;AAAA,EACb,MAAM;AACP,CAAC;","names":[]}
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import "../../chunk-NSSMTXJJ.mjs";
3
+ import { withFallback } from "../with-fallback.mjs";
4
+ const ChatElement = withFallback({
5
+ displayName: "ChatElement",
6
+ type: "chat-element"
7
+ });
8
+ export { ChatElement };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/chat/elements/chat.tsx"],"sourcesContent":["\"use client\";\n\nimport { withFallback } from \"../with-fallback\";\n\nexport const ChatElement = withFallback<\"chat-element\", true>({\n\tdisplayName: \"ChatElement\",\n\ttype: \"chat-element\",\n});\n"],"mappings":";;AAEA,SAAS,oBAAoB;AAEtB,MAAM,cAAc,aAAmC;AAAA,EAC7D,aAAa;AAAA,EACb,MAAM;AACP,CAAC;","names":[]}
@@ -0,0 +1,11 @@
1
+ import { WithFallbackPropsOptional } from '../with-fallback.js';
2
+ import * as _whop_embedded_components_vanilla_js_types from '@whop/embedded-components-vanilla-js/types';
3
+ import 'react';
4
+
5
+ declare const DmsListElement: {
6
+ (props: WithFallbackPropsOptional<_whop_embedded_components_vanilla_js_types.DmsListElementOptions>): React.ReactNode;
7
+ displayName: string;
8
+ type: string;
9
+ };
10
+
11
+ export { DmsListElement };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var dms_list_exports = {};
21
+ __export(dms_list_exports, {
22
+ DmsListElement: () => DmsListElement
23
+ });
24
+ module.exports = __toCommonJS(dms_list_exports);
25
+ var import_with_fallback = require("../with-fallback");
26
+ const DmsListElement = (0, import_with_fallback.withFallback)({
27
+ displayName: "DmsListElement",
28
+ type: "dms-list-element"
29
+ });
30
+ //# sourceMappingURL=dms-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/chat/elements/dms-list.tsx"],"sourcesContent":["\"use client\";\n\nimport { withFallback } from \"../with-fallback\";\n\nexport const DmsListElement = withFallback({\n\tdisplayName: \"DmsListElement\",\n\ttype: \"dms-list-element\",\n} as const);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,2BAA6B;AAEtB,MAAM,qBAAiB,mCAAa;AAAA,EAC1C,aAAa;AAAA,EACb,MAAM;AACP,CAAU;","names":[]}
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import "../../chunk-NSSMTXJJ.mjs";
3
+ import { withFallback } from "../with-fallback.mjs";
4
+ const DmsListElement = withFallback({
5
+ displayName: "DmsListElement",
6
+ type: "dms-list-element"
7
+ });
8
+ export { DmsListElement };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/chat/elements/dms-list.tsx"],"sourcesContent":["\"use client\";\n\nimport { withFallback } from \"../with-fallback\";\n\nexport const DmsListElement = withFallback({\n\tdisplayName: \"DmsListElement\",\n\ttype: \"dms-list-element\",\n} as const);\n"],"mappings":";;AAEA,SAAS,oBAAoB;AAEtB,MAAM,iBAAiB,aAAa;AAAA,EAC1C,aAAa;AAAA,EACb,MAAM;AACP,CAAU;","names":[]}
@@ -0,0 +1,5 @@
1
+ export { ChatElement } from './chat.js';
2
+ export { DmsListElement } from './dms-list.js';
3
+ import '../with-fallback.js';
4
+ import '@whop/embedded-components-vanilla-js/types';
5
+ import 'react';
@@ -0,0 +1,27 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var elements_exports = {};
20
+ __export(elements_exports, {
21
+ ChatElement: () => import_chat.ChatElement,
22
+ DmsListElement: () => import_dms_list.DmsListElement
23
+ });
24
+ module.exports = __toCommonJS(elements_exports);
25
+ var import_chat = require("./chat");
26
+ var import_dms_list = require("./dms-list");
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/chat/elements/index.tsx"],"sourcesContent":["export { ChatElement } from \"./chat\";\nexport { DmsListElement } from \"./dms-list\";\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4B;AAC5B,sBAA+B;","names":[]}
@@ -0,0 +1,4 @@
1
+ import "../../chunk-NSSMTXJJ.mjs";
2
+ import { ChatElement } from "./chat.mjs";
3
+ import { DmsListElement } from "./dms-list.mjs";
4
+ export { ChatElement, DmsListElement };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/chat/elements/index.tsx"],"sourcesContent":["export { ChatElement } from \"./chat\";\nexport { DmsListElement } from \"./dms-list\";\n\n"],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;","names":[]}
@@ -0,0 +1,6 @@
1
+ export { ChatElement } from './elements/chat.js';
2
+ export { DmsListElement } from './elements/dms-list.js';
3
+ export { ChatSession, useChatSession } from './session.js';
4
+ import './with-fallback.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 chat_exports = {};
17
+ module.exports = __toCommonJS(chat_exports);
18
+ __reExport(chat_exports, require("./elements"), module.exports);
19
+ __reExport(chat_exports, require("./session"), module.exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chat/index.tsx"],"sourcesContent":["export * from \"./elements\";\nexport * from \"./session\";\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,yBAAc,uBAAd;AACA,yBAAc,sBADd;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./elements/index.mjs";
2
+ export * from "./session.mjs";
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chat/index.tsx"],"sourcesContent":["export * from \"./elements\";\nexport * from \"./session\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,11 @@
1
+ import { ChatSessionOptions, ChatSession as ChatSession$1 } from '@whop/embedded-components-vanilla-js/types';
2
+ import React__default, { PropsWithChildren } from 'react';
3
+
4
+ declare function ChatSession({ children, token, ref, }: PropsWithChildren<ChatSessionOptions & {
5
+ ref?: React__default.RefObject<{
6
+ chatSession: ChatSession$1 | null;
7
+ } | null>;
8
+ }>): React__default.JSX.Element;
9
+ declare function useChatSession(): ChatSession$1 | null;
10
+
11
+ export { ChatSession, useChatSession };
@@ -0,0 +1,69 @@
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
+ ChatSession: () => ChatSession,
33
+ useChatSession: () => useChatSession
34
+ });
35
+ module.exports = __toCommonJS(session_exports);
36
+ var import_react = __toESM(require("react"));
37
+ var import_provider = require("../provider");
38
+ const ChatSessionContext = (0, import_react.createContext)(null);
39
+ function ChatSession({
40
+ children,
41
+ token,
42
+ ref
43
+ }) {
44
+ const elements = (0, import_provider.useElements)();
45
+ const chatSession = (0, import_react.useMemo)(() => {
46
+ if (!elements) return null;
47
+ return elements.createChatSession({ token });
48
+ }, [elements]);
49
+ (0, import_react.useEffect)(() => {
50
+ if (!chatSession) return;
51
+ chatSession.updateOptions({ token });
52
+ }, [chatSession, token]);
53
+ const value = (0, import_react.useMemo)(
54
+ () => ({
55
+ chatSession
56
+ }),
57
+ [chatSession]
58
+ );
59
+ (0, import_react.useImperativeHandle)(ref, () => ({ chatSession }), [chatSession]);
60
+ return /* @__PURE__ */ import_react.default.createElement(ChatSessionContext.Provider, { value }, children);
61
+ }
62
+ function useChatSession() {
63
+ const ctx = (0, import_react.useContext)(ChatSessionContext);
64
+ if (!ctx) {
65
+ throw new Error("useChatSession must be used within a ChatSessionProvider");
66
+ }
67
+ return ctx.chatSession;
68
+ }
69
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chat/session.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tChatSessionOptions,\n\tChatSession as ChatSessionType,\n} from \"@whop/embedded-components-vanilla-js/types\";\nimport type { PropsWithChildren } from \"react\";\n\nimport React, {\n\tcreateContext,\n\tuseContext,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseMemo,\n} from \"react\";\nimport { useElements } from \"../provider\";\n\ninterface ContextState {\n\tchatSession: ChatSessionType | null;\n}\n\nconst ChatSessionContext = createContext<ContextState | null>(null);\n\nexport function ChatSession({\n\tchildren,\n\ttoken,\n\tref,\n}: PropsWithChildren<\n\tChatSessionOptions & {\n\t\tref?: React.RefObject<{\n\t\t\tchatSession: ChatSessionType | null;\n\t\t} | null>;\n\t}\n>) {\n\tconst elements = useElements();\n\n\tconst chatSession = useMemo(() => {\n\t\tif (!elements) return null;\n\t\treturn elements.createChatSession({ token });\n\t}, [elements]);\n\n\tuseEffect(() => {\n\t\tif (!chatSession) return;\n\t\tchatSession.updateOptions({ token });\n\t}, [chatSession, token]);\n\n\tconst value: ContextState = useMemo(\n\t\t() => ({\n\t\t\tchatSession,\n\t\t}),\n\t\t[chatSession],\n\t);\n\n\tuseImperativeHandle(ref, () => ({ chatSession }), [chatSession]);\n\n\treturn (\n\t\t<ChatSessionContext.Provider value={value}>\n\t\t\t{children}\n\t\t</ChatSessionContext.Provider>\n\t);\n}\n\nexport function useChatSession() {\n\tconst ctx = useContext(ChatSessionContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useChatSession must be used within a ChatSessionProvider\");\n\t}\n\treturn ctx.chatSession;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,mBAMO;AACP,sBAA4B;AAM5B,MAAM,yBAAqB,4BAAmC,IAAI;AAE3D,SAAS,YAAY;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACD,GAMG;AACF,QAAM,eAAW,6BAAY;AAE7B,QAAM,kBAAc,sBAAQ,MAAM;AACjC,QAAI,CAAC,SAAU,QAAO;AACtB,WAAO,SAAS,kBAAkB,EAAE,MAAM,CAAC;AAAA,EAC5C,GAAG,CAAC,QAAQ,CAAC;AAEb,8BAAU,MAAM;AACf,QAAI,CAAC,YAAa;AAClB,gBAAY,cAAc,EAAE,MAAM,CAAC;AAAA,EACpC,GAAG,CAAC,aAAa,KAAK,CAAC;AAEvB,QAAM,YAAsB;AAAA,IAC3B,OAAO;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAC,WAAW;AAAA,EACb;AAEA,wCAAoB,KAAK,OAAO,EAAE,YAAY,IAAI,CAAC,WAAW,CAAC;AAE/D,SACC,6BAAAA,QAAA,cAAC,mBAAmB,UAAnB,EAA4B,SAC3B,QACF;AAEF;AAEO,SAAS,iBAAiB;AAChC,QAAM,UAAM,yBAAW,kBAAkB;AACzC,MAAI,CAAC,KAAK;AACT,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC3E;AACA,SAAO,IAAI;AACZ;","names":["React"]}
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ import "../chunk-NSSMTXJJ.mjs";
3
+ import React, { createContext, useContext, useEffect, useImperativeHandle, useMemo } from "react";
4
+ import { useElements } from "../provider.mjs";
5
+ const ChatSessionContext = createContext(null);
6
+ function ChatSession({ children, token, ref }) {
7
+ const elements = useElements();
8
+ const chatSession = useMemo(()=>{
9
+ if (!elements) return null;
10
+ return elements.createChatSession({
11
+ token
12
+ });
13
+ }, [
14
+ elements
15
+ ]);
16
+ useEffect(()=>{
17
+ if (!chatSession) return;
18
+ chatSession.updateOptions({
19
+ token
20
+ });
21
+ }, [
22
+ chatSession,
23
+ token
24
+ ]);
25
+ const value = useMemo(()=>({
26
+ chatSession
27
+ }), [
28
+ chatSession
29
+ ]);
30
+ useImperativeHandle(ref, ()=>({
31
+ chatSession
32
+ }), [
33
+ chatSession
34
+ ]);
35
+ return React.createElement(ChatSessionContext.Provider, {
36
+ value
37
+ }, children);
38
+ }
39
+ function useChatSession() {
40
+ const ctx = useContext(ChatSessionContext);
41
+ if (!ctx) {
42
+ throw new Error("useChatSession must be used within a ChatSessionProvider");
43
+ }
44
+ return ctx.chatSession;
45
+ }
46
+ export { ChatSession, useChatSession };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chat/session.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tChatSessionOptions,\n\tChatSession as ChatSessionType,\n} from \"@whop/embedded-components-vanilla-js/types\";\nimport type { PropsWithChildren } from \"react\";\n\nimport React, {\n\tcreateContext,\n\tuseContext,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseMemo,\n} from \"react\";\nimport { useElements } from \"../provider\";\n\ninterface ContextState {\n\tchatSession: ChatSessionType | null;\n}\n\nconst ChatSessionContext = createContext<ContextState | null>(null);\n\nexport function ChatSession({\n\tchildren,\n\ttoken,\n\tref,\n}: PropsWithChildren<\n\tChatSessionOptions & {\n\t\tref?: React.RefObject<{\n\t\t\tchatSession: ChatSessionType | null;\n\t\t} | null>;\n\t}\n>) {\n\tconst elements = useElements();\n\n\tconst chatSession = useMemo(() => {\n\t\tif (!elements) return null;\n\t\treturn elements.createChatSession({ token });\n\t}, [elements]);\n\n\tuseEffect(() => {\n\t\tif (!chatSession) return;\n\t\tchatSession.updateOptions({ token });\n\t}, [chatSession, token]);\n\n\tconst value: ContextState = useMemo(\n\t\t() => ({\n\t\t\tchatSession,\n\t\t}),\n\t\t[chatSession],\n\t);\n\n\tuseImperativeHandle(ref, () => ({ chatSession }), [chatSession]);\n\n\treturn (\n\t\t<ChatSessionContext.Provider value={value}>\n\t\t\t{children}\n\t\t</ChatSessionContext.Provider>\n\t);\n}\n\nexport function useChatSession() {\n\tconst ctx = useContext(ChatSessionContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useChatSession must be used within a ChatSessionProvider\");\n\t}\n\treturn ctx.chatSession;\n}\n"],"mappings":";;AAQA,OAAO;AAAA,EACN;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB;AAM5B,MAAM,qBAAqB,cAAmC,IAAI;AAE3D,SAAS,YAAY;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACD,GAMG;AACF,QAAM,WAAW,YAAY;AAE7B,QAAM,cAAc,QAAQ,MAAM;AACjC,QAAI,CAAC,SAAU,QAAO;AACtB,WAAO,SAAS,kBAAkB,EAAE,MAAM,CAAC;AAAA,EAC5C,GAAG,CAAC,QAAQ,CAAC;AAEb,YAAU,MAAM;AACf,QAAI,CAAC,YAAa;AAClB,gBAAY,cAAc,EAAE,MAAM,CAAC;AAAA,EACpC,GAAG,CAAC,aAAa,KAAK,CAAC;AAEvB,QAAM,QAAsB;AAAA,IAC3B,OAAO;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAC,WAAW;AAAA,EACb;AAEA,sBAAoB,KAAK,OAAO,EAAE,YAAY,IAAI,CAAC,WAAW,CAAC;AAE/D,SACC,oCAAC,mBAAmB,UAAnB,EAA4B,SAC3B,QACF;AAEF;AAEO,SAAS,iBAAiB;AAChC,QAAM,MAAM,WAAW,kBAAkB;AACzC,MAAI,CAAC,KAAK;AACT,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC3E;AACA,SAAO,IAAI;AACZ;","names":[]}
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ChatSession } from '@whop/embedded-components-vanilla-js/types';
3
+
4
+ declare function useChatSessionRef(): React.RefObject<{
5
+ chatSession: ChatSession | null;
6
+ } | null>;
7
+
8
+ export { useChatSessionRef };
@@ -0,0 +1,29 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var use_session_ref_exports = {};
20
+ __export(use_session_ref_exports, {
21
+ useChatSessionRef: () => useChatSessionRef
22
+ });
23
+ module.exports = __toCommonJS(use_session_ref_exports);
24
+ var import_react = require("react");
25
+ function useChatSessionRef() {
26
+ const ref = (0, import_react.useRef)(null);
27
+ return ref;
28
+ }
29
+ //# sourceMappingURL=use-session-ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chat/use-session-ref.ts"],"sourcesContent":["import type { ChatSession as ChatSessionType } from \"@whop/embedded-components-vanilla-js/types\";\n\nimport { useRef } from \"react\";\n\nexport function useChatSessionRef() {\n\tconst ref = useRef<{\n\t\tchatSession: ChatSessionType | null;\n\t}>(null);\n\treturn ref;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAuB;AAEhB,SAAS,oBAAoB;AACnC,QAAM,UAAM,qBAET,IAAI;AACP,SAAO;AACR;","names":[]}
@@ -0,0 +1,7 @@
1
+ import "../chunk-NSSMTXJJ.mjs";
2
+ import { useRef } from "react";
3
+ function useChatSessionRef() {
4
+ const ref = useRef(null);
5
+ return ref;
6
+ }
7
+ export { useChatSessionRef };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chat/use-session-ref.ts"],"sourcesContent":["import type { ChatSession as ChatSessionType } from \"@whop/embedded-components-vanilla-js/types\";\n\nimport { useRef } from \"react\";\n\nexport function useChatSessionRef() {\n\tconst ref = useRef<{\n\t\tchatSession: ChatSessionType | null;\n\t}>(null);\n\treturn ref;\n}\n"],"mappings":";AAEA,SAAS,cAAc;AAEhB,SAAS,oBAAoB;AACnC,QAAM,MAAM,OAET,IAAI;AACP,SAAO;AACR;","names":[]}
@@ -0,0 +1,55 @@
1
+ import { ChatSessionElements } from '@whop/embedded-components-vanilla-js/types';
2
+ import React__default from 'react';
3
+
4
+ /**
5
+ * Valid element type strings that can be passed to createElement.
6
+ */
7
+ type ElementType = keyof ChatSessionElements;
8
+ /**
9
+ * Extract the options type for a given element type using indexed access.
10
+ * PayoutsSessionElements maps element types to [Options, Element] tuples.
11
+ */
12
+ type ElementOptionsFor<T extends ElementType> = ChatSessionElements[T][0];
13
+ /**
14
+ * Component definition with a constrained element type.
15
+ * The type must be a valid element type from the SDK.
16
+ */
17
+ interface ElementComponentDefinition<T extends ElementType = ElementType> {
18
+ displayName: string;
19
+ type: T;
20
+ }
21
+ interface WithFallbackPropsBase {
22
+ className?: string;
23
+ style?: React__default.CSSProperties;
24
+ onReady?: () => void;
25
+ fallback?: React__default.ReactNode;
26
+ }
27
+ interface WithFallbackPropsRequired<TOptions> extends WithFallbackPropsBase {
28
+ options: TOptions;
29
+ }
30
+ interface WithFallbackPropsOptional<TOptions> extends WithFallbackPropsBase {
31
+ options?: TOptions;
32
+ }
33
+ type WithFallbackComponent<TOptions, TRequired extends boolean> = {
34
+ (props: TRequired extends true ? WithFallbackPropsRequired<TOptions> : WithFallbackPropsOptional<TOptions>): React__default.ReactNode;
35
+ displayName: string;
36
+ type: string;
37
+ };
38
+ /**
39
+ * Creates a React component that wraps an embedded element with fallback support.
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * // Type-safe: options type is inferred from the element type
44
+ * export const ChatElement = withFallback({
45
+ * displayName: "ChatElement",
46
+ * type: "chat-element",
47
+ * } as const);
48
+ *
49
+ * // Usage - TypeScript knows the correct options type
50
+ * <ChatElement options={{ channelId: "channel_xxx" }} />
51
+ * ```
52
+ */
53
+ declare function withFallback<const T extends ElementType, TRequired extends boolean = false>(Component: ElementComponentDefinition<T>): WithFallbackComponent<ElementOptionsFor<T>, TRequired>;
54
+
55
+ export { type WithFallbackPropsOptional, type WithFallbackPropsRequired, withFallback };
@@ -0,0 +1,85 @@
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 with_fallback_exports = {};
31
+ __export(with_fallback_exports, {
32
+ withFallback: () => withFallback
33
+ });
34
+ module.exports = __toCommonJS(with_fallback_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 withFallback(Component) {
39
+ function WrappedElement({
40
+ options,
41
+ className,
42
+ style,
43
+ onReady,
44
+ fallback
45
+ }) {
46
+ const chatSession = (0, import_session.useChatSession)();
47
+ const ref = (0, import_react.useRef)(null);
48
+ const element = (0, import_react.useMemo)(() => {
49
+ if (!chatSession) return null;
50
+ return chatSession.createElement(Component, options ?? {});
51
+ }, [chatSession]);
52
+ const elementSnapshot = (0, import_use_element_snapshot.useElementSnapshot)(element);
53
+ const isReady = elementSnapshot?.state === "ready";
54
+ (0, import_react.useEffect)(() => {
55
+ if (!element) return;
56
+ element.updateOptions(options ?? {});
57
+ }, [options, element]);
58
+ (0, import_react.useEffect)(() => {
59
+ if (!element || !onReady) return;
60
+ element.on("ready", onReady);
61
+ return () => {
62
+ element.off("ready", onReady);
63
+ };
64
+ }, [element, onReady]);
65
+ (0, import_react.useLayoutEffect)(() => {
66
+ if (!element || !ref.current) return;
67
+ element.mount(ref.current);
68
+ return () => {
69
+ element.unmount();
70
+ };
71
+ }, [element, ref.current]);
72
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
73
+ "div",
74
+ {
75
+ style: { ...style, visibility: isReady ? void 0 : "hidden" },
76
+ className,
77
+ ref
78
+ }
79
+ ), !isReady && (fallback ?? null));
80
+ }
81
+ WrappedElement.displayName = Component.displayName;
82
+ WrappedElement.type = Component.type;
83
+ return WrappedElement;
84
+ }
85
+ //# sourceMappingURL=with-fallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chat/with-fallback.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tChatSessionElements,\n\tWhopElement,\n} from \"@whop/embedded-components-vanilla-js/types\";\nimport React, { useEffect, useLayoutEffect, useMemo, useRef } from \"react\";\nimport { useElementSnapshot } from \"../lib/use-element-snapshot\";\nimport { useChatSession } from \"./session\";\n\n/**\n * Valid element type strings that can be passed to createElement.\n */\ntype ElementType = keyof ChatSessionElements;\n\n/**\n * Extract the options type for a given element type using indexed access.\n * PayoutsSessionElements maps element types to [Options, Element] tuples.\n */\ntype ElementOptionsFor<T extends ElementType> = ChatSessionElements[T][0];\n\n/**\n * Base element type that all created elements conform to.\n * Using WhopElement<any, any, any> gives us access to common methods\n * (mount, unmount, on, off, updateOptions) without union type issues.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype BaseElement = WhopElement<any, any, any>;\n\n/**\n * Component definition with a constrained element type.\n * The type must be a valid element type from the SDK.\n */\ninterface ElementComponentDefinition<T extends ElementType = ElementType> {\n\tdisplayName: string;\n\ttype: T;\n}\n\ninterface WithFallbackPropsBase {\n\tclassName?: string;\n\tstyle?: React.CSSProperties;\n\tonReady?: () => void;\n\tfallback?: React.ReactNode;\n}\n\nexport interface WithFallbackPropsRequired<TOptions>\n\textends WithFallbackPropsBase {\n\toptions: TOptions;\n}\n\nexport interface WithFallbackPropsOptional<TOptions>\n\textends WithFallbackPropsBase {\n\toptions?: TOptions;\n}\n\ntype WithFallbackComponent<TOptions, TRequired extends boolean> = {\n\t(\n\t\tprops: TRequired extends true\n\t\t\t? WithFallbackPropsRequired<TOptions>\n\t\t\t: WithFallbackPropsOptional<TOptions>,\n\t): React.ReactNode;\n\tdisplayName: string;\n\ttype: string;\n};\n\n/**\n * Creates a React component that wraps an embedded element with fallback support.\n *\n * @example\n * ```tsx\n * // Type-safe: options type is inferred from the element type\n * export const ChatElement = withFallback({\n * displayName: \"ChatElement\",\n * type: \"chat-element\",\n * } as const);\n *\n * // Usage - TypeScript knows the correct options type\n * <ChatElement options={{ channelId: \"channel_xxx\" }} />\n * ```\n */\nexport function withFallback<\n\tconst T extends ElementType,\n\tTRequired extends boolean = false,\n>(\n\tComponent: ElementComponentDefinition<T>,\n): WithFallbackComponent<ElementOptionsFor<T>, TRequired> {\n\ttype TOptions = ElementOptionsFor<T>;\n\n\tfunction WrappedElement({\n\t\toptions,\n\t\tclassName,\n\t\tstyle,\n\t\tonReady,\n\t\tfallback,\n\t}: WithFallbackPropsOptional<TOptions>) {\n\t\tconst chatSession = useChatSession();\n\t\tconst ref = useRef<HTMLDivElement>(null);\n\n\t\tconst element = useMemo((): BaseElement | null => {\n\t\t\tif (!chatSession) return null;\n\t\t\t// Safe: T is constrained to valid element types, and options matches T\n\t\t\treturn chatSession.createElement(Component, options ?? {} as TOptions);\n\t\t}, [chatSession]);\n\n\t\tconst elementSnapshot = useElementSnapshot(element);\n\n\t\tconst isReady = elementSnapshot?.state === \"ready\";\n\n\t\tuseEffect(() => {\n\t\t\tif (!element) return;\n\t\t\telement.updateOptions(options ?? {});\n\t\t}, [options, element]);\n\n\t\tuseEffect(() => {\n\t\t\tif (!element || !onReady) return;\n\t\t\telement.on(\"ready\", onReady);\n\t\t\treturn () => {\n\t\t\t\telement.off(\"ready\", onReady);\n\t\t\t};\n\t\t}, [element, onReady]);\n\n\t\tuseLayoutEffect(() => {\n\t\t\tif (!element || !ref.current) return;\n\t\t\telement.mount(ref.current);\n\t\t\treturn () => {\n\t\t\t\telement.unmount();\n\t\t\t};\n\t\t}, [element, ref.current]);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<div\n\t\t\t\t\tstyle={{ ...style, visibility: isReady ? undefined : \"hidden\" }}\n\t\t\t\t\tclassName={className}\n\t\t\t\t\tref={ref}\n\t\t\t\t/>\n\t\t\t\t{!isReady && (fallback ?? null)}\n\t\t\t</>\n\t\t);\n\t}\n\n\tWrappedElement.displayName = Component.displayName;\n\tWrappedElement.type = Component.type;\n\n\treturn WrappedElement as WithFallbackComponent<TOptions, TRequired>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,mBAAmE;AACnE,kCAAmC;AACnC,qBAA+B;AAwExB,SAAS,aAIf,WACyD;AAGzD,WAAS,eAAe;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAAwC;AACvC,UAAM,kBAAc,+BAAe;AACnC,UAAM,UAAM,qBAAuB,IAAI;AAEvC,UAAM,cAAU,sBAAQ,MAA0B;AACjD,UAAI,CAAC,YAAa,QAAO;AAEzB,aAAO,YAAY,cAAc,WAAW,WAAW,CAAC,CAAa;AAAA,IACtE,GAAG,CAAC,WAAW,CAAC;AAEhB,UAAM,sBAAkB,gDAAmB,OAAO;AAElD,UAAM,UAAU,iBAAiB,UAAU;AAE3C,gCAAU,MAAM;AACf,UAAI,CAAC,QAAS;AACd,cAAQ,cAAc,WAAW,CAAC,CAAC;AAAA,IACpC,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,gCAAU,MAAM;AACf,UAAI,CAAC,WAAW,CAAC,QAAS;AAC1B,cAAQ,GAAG,SAAS,OAAO;AAC3B,aAAO,MAAM;AACZ,gBAAQ,IAAI,SAAS,OAAO;AAAA,MAC7B;AAAA,IACD,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,sCAAgB,MAAM;AACrB,UAAI,CAAC,WAAW,CAAC,IAAI,QAAS;AAC9B,cAAQ,MAAM,IAAI,OAAO;AACzB,aAAO,MAAM;AACZ,gBAAQ,QAAQ;AAAA,MACjB;AAAA,IACD,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC;AAEzB,WACC,6BAAAA,QAAA,2BAAAA,QAAA,gBACC,6BAAAA,QAAA;AAAA,MAAC;AAAA;AAAA,QACA,OAAO,EAAE,GAAG,OAAO,YAAY,UAAU,SAAY,SAAS;AAAA,QAC9D;AAAA,QACA;AAAA;AAAA,IACD,GACC,CAAC,YAAY,YAAY,KAC3B;AAAA,EAEF;AAEA,iBAAe,cAAc,UAAU;AACvC,iBAAe,OAAO,UAAU;AAEhC,SAAO;AACR;","names":["React"]}
@@ -0,0 +1,58 @@
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 { useChatSession } from "./session.mjs";
6
+ function withFallback(Component) {
7
+ function WrappedElement({ options, className, style, onReady, fallback }) {
8
+ const chatSession = useChatSession();
9
+ const ref = useRef(null);
10
+ const element = useMemo(()=>{
11
+ if (!chatSession) return null;
12
+ return chatSession.createElement(Component, options ?? {});
13
+ }, [
14
+ chatSession
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 ? void 0 : "hidden"
49
+ },
50
+ className,
51
+ ref
52
+ }), !isReady && (fallback ?? null));
53
+ }
54
+ WrappedElement.displayName = Component.displayName;
55
+ WrappedElement.type = Component.type;
56
+ return WrappedElement;
57
+ }
58
+ export { withFallback };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/chat/with-fallback.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tChatSessionElements,\n\tWhopElement,\n} from \"@whop/embedded-components-vanilla-js/types\";\nimport React, { useEffect, useLayoutEffect, useMemo, useRef } from \"react\";\nimport { useElementSnapshot } from \"../lib/use-element-snapshot\";\nimport { useChatSession } from \"./session\";\n\n/**\n * Valid element type strings that can be passed to createElement.\n */\ntype ElementType = keyof ChatSessionElements;\n\n/**\n * Extract the options type for a given element type using indexed access.\n * PayoutsSessionElements maps element types to [Options, Element] tuples.\n */\ntype ElementOptionsFor<T extends ElementType> = ChatSessionElements[T][0];\n\n/**\n * Base element type that all created elements conform to.\n * Using WhopElement<any, any, any> gives us access to common methods\n * (mount, unmount, on, off, updateOptions) without union type issues.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype BaseElement = WhopElement<any, any, any>;\n\n/**\n * Component definition with a constrained element type.\n * The type must be a valid element type from the SDK.\n */\ninterface ElementComponentDefinition<T extends ElementType = ElementType> {\n\tdisplayName: string;\n\ttype: T;\n}\n\ninterface WithFallbackPropsBase {\n\tclassName?: string;\n\tstyle?: React.CSSProperties;\n\tonReady?: () => void;\n\tfallback?: React.ReactNode;\n}\n\nexport interface WithFallbackPropsRequired<TOptions>\n\textends WithFallbackPropsBase {\n\toptions: TOptions;\n}\n\nexport interface WithFallbackPropsOptional<TOptions>\n\textends WithFallbackPropsBase {\n\toptions?: TOptions;\n}\n\ntype WithFallbackComponent<TOptions, TRequired extends boolean> = {\n\t(\n\t\tprops: TRequired extends true\n\t\t\t? WithFallbackPropsRequired<TOptions>\n\t\t\t: WithFallbackPropsOptional<TOptions>,\n\t): React.ReactNode;\n\tdisplayName: string;\n\ttype: string;\n};\n\n/**\n * Creates a React component that wraps an embedded element with fallback support.\n *\n * @example\n * ```tsx\n * // Type-safe: options type is inferred from the element type\n * export const ChatElement = withFallback({\n * displayName: \"ChatElement\",\n * type: \"chat-element\",\n * } as const);\n *\n * // Usage - TypeScript knows the correct options type\n * <ChatElement options={{ channelId: \"channel_xxx\" }} />\n * ```\n */\nexport function withFallback<\n\tconst T extends ElementType,\n\tTRequired extends boolean = false,\n>(\n\tComponent: ElementComponentDefinition<T>,\n): WithFallbackComponent<ElementOptionsFor<T>, TRequired> {\n\ttype TOptions = ElementOptionsFor<T>;\n\n\tfunction WrappedElement({\n\t\toptions,\n\t\tclassName,\n\t\tstyle,\n\t\tonReady,\n\t\tfallback,\n\t}: WithFallbackPropsOptional<TOptions>) {\n\t\tconst chatSession = useChatSession();\n\t\tconst ref = useRef<HTMLDivElement>(null);\n\n\t\tconst element = useMemo((): BaseElement | null => {\n\t\t\tif (!chatSession) return null;\n\t\t\t// Safe: T is constrained to valid element types, and options matches T\n\t\t\treturn chatSession.createElement(Component, options ?? {} as TOptions);\n\t\t}, [chatSession]);\n\n\t\tconst elementSnapshot = useElementSnapshot(element);\n\n\t\tconst isReady = elementSnapshot?.state === \"ready\";\n\n\t\tuseEffect(() => {\n\t\t\tif (!element) return;\n\t\t\telement.updateOptions(options ?? {});\n\t\t}, [options, element]);\n\n\t\tuseEffect(() => {\n\t\t\tif (!element || !onReady) return;\n\t\t\telement.on(\"ready\", onReady);\n\t\t\treturn () => {\n\t\t\t\telement.off(\"ready\", onReady);\n\t\t\t};\n\t\t}, [element, onReady]);\n\n\t\tuseLayoutEffect(() => {\n\t\t\tif (!element || !ref.current) return;\n\t\t\telement.mount(ref.current);\n\t\t\treturn () => {\n\t\t\t\telement.unmount();\n\t\t\t};\n\t\t}, [element, ref.current]);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<div\n\t\t\t\t\tstyle={{ ...style, visibility: isReady ? undefined : \"hidden\" }}\n\t\t\t\t\tclassName={className}\n\t\t\t\t\tref={ref}\n\t\t\t\t/>\n\t\t\t\t{!isReady && (fallback ?? null)}\n\t\t\t</>\n\t\t);\n\t}\n\n\tWrappedElement.displayName = Component.displayName;\n\tWrappedElement.type = Component.type;\n\n\treturn WrappedElement as WithFallbackComponent<TOptions, TRequired>;\n}\n"],"mappings":";;AAMA,OAAO,SAAS,WAAW,iBAAiB,SAAS,cAAc;AACnE,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAwExB,SAAS,aAIf,WACyD;AAGzD,WAAS,eAAe;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAAwC;AACvC,UAAM,cAAc,eAAe;AACnC,UAAM,MAAM,OAAuB,IAAI;AAEvC,UAAM,UAAU,QAAQ,MAA0B;AACjD,UAAI,CAAC,YAAa,QAAO;AAEzB,aAAO,YAAY,cAAc,WAAW,WAAW,CAAC,CAAa;AAAA,IACtE,GAAG,CAAC,WAAW,CAAC;AAEhB,UAAM,kBAAkB,mBAAmB,OAAO;AAElD,UAAM,UAAU,iBAAiB,UAAU;AAE3C,cAAU,MAAM;AACf,UAAI,CAAC,QAAS;AACd,cAAQ,cAAc,WAAW,CAAC,CAAC;AAAA,IACpC,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,cAAU,MAAM;AACf,UAAI,CAAC,WAAW,CAAC,QAAS;AAC1B,cAAQ,GAAG,SAAS,OAAO;AAC3B,aAAO,MAAM;AACZ,gBAAQ,IAAI,SAAS,OAAO;AAAA,MAC7B;AAAA,IACD,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,oBAAgB,MAAM;AACrB,UAAI,CAAC,WAAW,CAAC,IAAI,QAAS;AAC9B,cAAQ,MAAM,IAAI,OAAO;AACzB,aAAO,MAAM;AACZ,gBAAQ,QAAQ;AAAA,MACjB;AAAA,IACD,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC;AAEzB,WACC,0DACC;AAAA,MAAC;AAAA;AAAA,QACA,OAAO,EAAE,GAAG,OAAO,YAAY,UAAU,SAAY,SAAS;AAAA,QAC9D;AAAA,QACA;AAAA;AAAA,IACD,GACC,CAAC,YAAY,YAAY,KAC3B;AAAA,EAEF;AAEA,iBAAe,cAAc,UAAU;AACvC,iBAAe,OAAO,UAAU;AAEhC,SAAO;AACR;","names":[]}