@polymorfa/react 0.1.0-dev.20260922094209
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 +5 -0
- package/README.md +303 -0
- package/dist/call-button.d.ts +29 -0
- package/dist/call-button.d.ts.map +1 -0
- package/dist/call-button.js +54 -0
- package/dist/calls.d.ts +201 -0
- package/dist/calls.d.ts.map +1 -0
- package/dist/calls.js +944 -0
- package/dist/components.d.ts +109 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +843 -0
- package/dist/context.d.ts +47 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +82 -0
- package/dist/dropin.d.ts +100 -0
- package/dist/dropin.d.ts.map +1 -0
- package/dist/dropin.js +298 -0
- package/dist/hooks.d.ts +30 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +71 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/package.json +45 -0
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useEffect, useReducer, useRef, useSyncExternalStore } from "react";
|
|
2
|
+
const safeSubscriptions = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* `controller.subscribe`, except that a disposed controller yields a no-op
|
|
5
|
+
* subscription. Under StrictMode an owned controller can be disposed and
|
|
6
|
+
* replaced while a child is still subscribing to it; the child re-renders
|
|
7
|
+
* with the replacement right after.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export function safeSubscribe(controller) {
|
|
11
|
+
let subscribe = safeSubscriptions.get(controller);
|
|
12
|
+
if (subscribe === undefined) {
|
|
13
|
+
subscribe = (listener) => {
|
|
14
|
+
try {
|
|
15
|
+
return controller.subscribe(listener);
|
|
16
|
+
}
|
|
17
|
+
catch (cause) {
|
|
18
|
+
if (cause instanceof Error && / is disposed\.$/.test(cause.message))
|
|
19
|
+
return () => undefined;
|
|
20
|
+
throw cause;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
safeSubscriptions.set(controller, subscribe);
|
|
24
|
+
}
|
|
25
|
+
return subscribe;
|
|
26
|
+
}
|
|
27
|
+
export function useController(controller) {
|
|
28
|
+
return useSyncExternalStore(safeSubscribe(controller), controller.getSnapshot, controller.getSnapshot);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The passed `controller`, or one made by `create` that this component owns
|
|
32
|
+
* and disposes. Safe under StrictMode and `<Activity>`: when an effect
|
|
33
|
+
* cleanup disposes the owned controller and the effect runs again, a fresh
|
|
34
|
+
* controller replaces it and the component re-renders with it.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export function useOwnedController(controller, create) {
|
|
38
|
+
const owned = useRef(undefined);
|
|
39
|
+
const latestCreate = useRef(create);
|
|
40
|
+
latestCreate.current = create;
|
|
41
|
+
const [, rerender] = useReducer((count) => count + 1, 0);
|
|
42
|
+
if (controller === undefined && owned.current === undefined && create)
|
|
43
|
+
owned.current = create();
|
|
44
|
+
const owning = controller === undefined;
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!owning)
|
|
47
|
+
return;
|
|
48
|
+
if (owned.current === undefined) {
|
|
49
|
+
// The previous cleanup disposed the controller we rendered with.
|
|
50
|
+
const make = latestCreate.current;
|
|
51
|
+
if (make === undefined)
|
|
52
|
+
return;
|
|
53
|
+
owned.current = make();
|
|
54
|
+
rerender();
|
|
55
|
+
}
|
|
56
|
+
return () => {
|
|
57
|
+
const current = owned.current;
|
|
58
|
+
owned.current = undefined;
|
|
59
|
+
current?.dispose();
|
|
60
|
+
};
|
|
61
|
+
}, [owning]);
|
|
62
|
+
return controller ?? owned.current;
|
|
63
|
+
}
|
|
64
|
+
export function useResolvedController(controller, createController) {
|
|
65
|
+
if (controller === undefined && createController === undefined)
|
|
66
|
+
throw new Error("Pass controller or createController.");
|
|
67
|
+
const resolved = useOwnedController(controller, createController);
|
|
68
|
+
if (resolved === undefined)
|
|
69
|
+
throw new Error("Controller resolution failed.");
|
|
70
|
+
return resolved;
|
|
71
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { PolymorfaProvider, usePolymorfa, type PolymorfaProviderProps, type PolymorfaReactConfiguration, } from "./context.js";
|
|
2
|
+
export { useController, useResolvedController, type ReactController, } from "./hooks.js";
|
|
3
|
+
export { ChatDrawer, ComposeBox, MessageList, TemplateBuilder, type ChatDrawerProps, type ComposeBoxProps, type MessageListProps, type RenderAttachment, type TemplateBuilderProps, } from "./components.js";
|
|
4
|
+
export type { QuickReplyOption } from "@polymorfa/ui";
|
|
5
|
+
export { CALLS_STYLES, CallControls, CallStage, CallSurface, DialPad, IncomingCallCard, ParticipantList, ParticipantVideoGrid, formatDuration, injectCallsStyles, useCallDuration, useCallPopout, type AvatarResolver, type CallControlsProps, type CallPopoutHandle, type CallStageProps, type CallSurfaceProps, type DialPadProps, type IncomingCallCardProps, type ParticipantListProps, type ParticipantVideoGridProps, } from "./calls.js";
|
|
6
|
+
export { useOptionalPolymorfaClient, usePermission, usePermissions, usePolymorfaClient, type PolymorfaPermissions, } from "./context.js";
|
|
7
|
+
export { ConnectWhatsAppButton, ContactPanel, ConversationList, Inbox, SessionStatus, TemplateManager, type ConnectWhatsAppButtonProps, type ContactPanelProps, type ConversationListProps, type InboxProps, type SessionStatusProps, type TemplateManagerProps, } from "./dropin.js";
|
|
8
|
+
export { CallButton, type CallButtonProps } from "./call-button.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,GACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,UAAU,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,GAC1B,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,WAAW,EACX,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,GAC/B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,KAAK,oBAAoB,GAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,eAAe,EACf,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { PolymorfaProvider, usePolymorfa, } from "./context.js";
|
|
2
|
+
export { useController, useResolvedController, } from "./hooks.js";
|
|
3
|
+
export { ChatDrawer, ComposeBox, MessageList, TemplateBuilder, } from "./components.js";
|
|
4
|
+
export { CALLS_STYLES, CallControls, CallStage, CallSurface, DialPad, IncomingCallCard, ParticipantList, ParticipantVideoGrid, formatDuration, injectCallsStyles, useCallDuration, useCallPopout, } from "./calls.js";
|
|
5
|
+
export { useOptionalPolymorfaClient, usePermission, usePermissions, usePolymorfaClient, } from "./context.js";
|
|
6
|
+
export { ConnectWhatsAppButton, ContactPanel, ConversationList, Inbox, SessionStatus, TemplateManager, } from "./dropin.js";
|
|
7
|
+
export { CallButton } from "./call-button.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@polymorfa/react",
|
|
3
|
+
"version": "0.1.0-dev.20260922094209",
|
|
4
|
+
"description": "React bindings for Polymorfa browser controllers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/polymorfa/sdks.git",
|
|
10
|
+
"directory": "packages/react"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/polymorfa/sdks/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/polymorfa/sdks#readme",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -p tsconfig.build.json",
|
|
32
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@polymorfa/ui": "0.1.0-dev.20260922094209"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@polymorfa/browser": "0.1.0-dev.20260922094209",
|
|
39
|
+
"react": ">=18.2.0 <20"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"provenance": true
|
|
44
|
+
}
|
|
45
|
+
}
|