@pontive/pontkit-react 1.6.0 → 1.7.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/dist/elements.generated.d.ts +81 -53
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -30
- package/dist/index.js +222 -60
- package/dist/index.js.map +1 -1
- package/dist/{pont2/provider.d.ts → provider.d.ts} +22 -25
- package/dist/types.d.ts +106 -114
- package/dist/wrap.d.ts +8 -17
- package/package.json +5 -10
- package/dist/auth.d.ts +0 -102
- package/dist/coexistence-CEqhGd4-.js +0 -170
- package/dist/coexistence-CEqhGd4-.js.map +0 -1
- package/dist/coexistence-dvfn_5A6.cjs +0 -2
- package/dist/coexistence-dvfn_5A6.cjs.map +0 -1
- package/dist/coexistence.d.ts +0 -19
- package/dist/enums.d.ts +0 -58
- package/dist/pont2/elements.generated.d.ts +0 -81
- package/dist/pont2/index.d.ts +0 -18
- package/dist/pont2/types.d.ts +0 -118
- package/dist/pont2.cjs +0 -2
- package/dist/pont2.cjs.map +0 -1
- package/dist/pont2.js +0 -181
- package/dist/pont2.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,125 +1,117 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { AccountClient, AccountMenuItem, AccountSettingsContent, AccountSettingsLayout, AccountSettingsMode, AccountSettingsOrientation, AppSdkConfig, BrandingEntitlements, MemberManagementMode, ProviderSdk, SessionChange, WidgetClient } from '@pontive/pontkit-core';
|
|
3
|
+
export type { AccountClient, AccountMenuItem, AuthState, ProviderSdk, SessionChange, WidgetClient, } from '@pontive/pontkit-core';
|
|
4
|
+
/**
|
|
5
|
+
* Events core declares on `HTMLElementEventMap` are typed from there; this
|
|
6
|
+
* covers the ones it fires without declaring.
|
|
7
|
+
*/
|
|
8
|
+
interface UndeclaredEvents {
|
|
9
|
+
"pont-session-changed": CustomEvent<SessionChange>;
|
|
10
|
+
}
|
|
11
|
+
/** The event a generated `on…` callback receives: the DOM event itself. */
|
|
12
|
+
export type PontEvent<K extends string> = K extends keyof HTMLElementEventMap ? HTMLElementEventMap[K] : K extends keyof UndeclaredEvents ? UndeclaredEvents[K] : CustomEvent<unknown>;
|
|
13
|
+
/** The inputs of `<pont-provider>` (pontkit-core docs/kit/provider.md). */
|
|
14
|
+
export interface ProviderInputProps {
|
|
15
|
+
/** Required. */
|
|
16
|
+
appId: string;
|
|
17
|
+
/** Required: a hostname, a `/path` on this origin (the auth proxy, `/__pontive`), or a base URL. */
|
|
18
|
+
domain: string;
|
|
19
|
+
/** BCP-47 tags in preference order; empty lets the server negotiate. */
|
|
20
|
+
locales?: string;
|
|
21
|
+
signinUrl?: string;
|
|
22
|
+
signupUrl?: string;
|
|
23
|
+
invitationUrl?: string;
|
|
24
|
+
/** Where a signed-in user is sent from the sign-in, sign-up and invitation pages. */
|
|
25
|
+
signinRedirectUrl?: string;
|
|
26
|
+
/** "Continue here instead" (default: `signinRedirectUrl`). */
|
|
27
|
+
continueHereUrl?: string;
|
|
28
|
+
/** The OAuth scopes every flow asks for. Member management needs `pontive:org:member:*`. */
|
|
29
|
+
scope?: string | string[];
|
|
30
|
+
/** The organization a sign-in starts in. */
|
|
31
|
+
organizationId?: string;
|
|
6
32
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `fallbackChildren` used to sit alongside this, asking for the children to
|
|
11
|
-
* stand in as the placeholder while the CDN loaded. Widgets no longer wait on
|
|
12
|
-
* the CDN to render — the tag goes out with the server response and upgrades
|
|
13
|
-
* in place — so children are already on the page throughout that window and
|
|
14
|
-
* the flag had nothing left to switch on.
|
|
33
|
+
* The management gateway the default account client calls
|
|
34
|
+
* (`https://api.us.pontive.com`). Absolute http(s) only: the auth proxy does
|
|
35
|
+
* not forward `/me` or `/mgmt/v1`.
|
|
15
36
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
type WidgetLayout = "ROW" | "COLUMN" | typeof USER_PROFILE_WIDGETS_LAYOUT.ROW | typeof USER_PROFILE_WIDGETS_LAYOUT.COLUMN;
|
|
22
|
-
type CommonWidgetProps = WithChildren & {
|
|
23
|
-
showIcons?: boolean;
|
|
24
|
-
Layout?: WidgetLayout;
|
|
25
|
-
content?: IProfileWidgetCustomization | null;
|
|
26
|
-
};
|
|
27
|
-
export interface ProviderProps {
|
|
28
|
-
children?: ReactNode;
|
|
37
|
+
apiBaseUrl?: string;
|
|
38
|
+
/** The identifier to pre-fill (default: the URL's `login_hint`). */
|
|
39
|
+
loginHint?: string;
|
|
40
|
+
/** Default on. `false` keeps a signed-in user on the auth pages. */
|
|
29
41
|
autoRedirect?: boolean;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
accountSettingsPath?: string;
|
|
43
|
-
menuItems?: MenuItem[];
|
|
42
|
+
/** `"none"` opts out of linking the published theme. */
|
|
43
|
+
theme?: string;
|
|
44
|
+
/** Extra request headers for the SDK and the default account client. */
|
|
45
|
+
headers?: Record<string, string>;
|
|
46
|
+
/** The app's own account client; wins over the default one. */
|
|
47
|
+
accountClient?: AccountClient;
|
|
48
|
+
/**
|
|
49
|
+
* The app's own SDK options and callbacks (`onFlowStateChange`,
|
|
50
|
+
* `onAuthenticated` …). The provider chains them after its own; don't call
|
|
51
|
+
* `Auth.configure()` yourself.
|
|
52
|
+
*/
|
|
53
|
+
config?: AppSdkConfig;
|
|
44
54
|
}
|
|
45
|
-
/**
|
|
46
|
-
export interface
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
permissions: string[];
|
|
55
|
+
/** The raw `<pont-provider>` wrapper's props: the inputs plus the SDK. */
|
|
56
|
+
export interface ProviderElementProps extends ProviderInputProps {
|
|
57
|
+
children?: ReactNode;
|
|
58
|
+
sdk?: ProviderSdk;
|
|
50
59
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
60
|
+
/** `pont-signin`, `pont-signup`, `pont-invitation`. */
|
|
61
|
+
export interface FlowWidgetProps {
|
|
62
|
+
/**
|
|
63
|
+
* Shown until the first screen renders, then removed by the widget.
|
|
64
|
+
*/
|
|
65
|
+
fallback?: ReactNode | null;
|
|
66
|
+
/** The widget's own client. Inside a `Provider` it uses the provider's. */
|
|
67
|
+
client?: WidgetClient;
|
|
68
|
+
/** Its own branding entitlements. Inside a `Provider` it uses the provider's. */
|
|
69
|
+
branding?: BrandingEntitlements;
|
|
70
|
+
/** Default `sys_signin-flow-passkey` / `sys_signup-flow`; none for the invitation. */
|
|
71
|
+
flowId?: string;
|
|
72
|
+
}
|
|
73
|
+
/** `pont-consent` (the OAuth consent page). */
|
|
74
|
+
export interface ConsentProps {
|
|
75
|
+
/** The page's `consent_request` parameter. */
|
|
76
|
+
consentRequest: string;
|
|
77
|
+
/** Where auth-api is (default: this origin, which the session cookie needs). */
|
|
78
|
+
baseUrl?: string;
|
|
79
|
+
locales?: string;
|
|
80
|
+
branding?: BrandingEntitlements;
|
|
81
|
+
}
|
|
82
|
+
/** What every account widget takes. */
|
|
83
|
+
interface AccountWidgetProps {
|
|
84
|
+
/** Its own account client. Inside a `Provider` it uses the provider's. */
|
|
85
|
+
client?: AccountClient;
|
|
86
|
+
}
|
|
87
|
+
export interface AccountMenuProps extends AccountWidgetProps {
|
|
88
|
+
/** Where "Account settings" goes when `onAccountSettings` doesn't cancel. */
|
|
89
|
+
accountSettingsUrl?: string;
|
|
90
|
+
/** Entries between "Account settings" and "Log out". */
|
|
91
|
+
items?: AccountMenuItem[];
|
|
92
|
+
}
|
|
93
|
+
export interface OrganizationSwitcherProps extends AccountWidgetProps {
|
|
94
|
+
/** Reload the page after a switch (for server-rendered pages). */
|
|
58
95
|
reloadOnSwitch?: boolean;
|
|
59
|
-
/**
|
|
96
|
+
/** The button's text while the session acts in no organization. */
|
|
60
97
|
emptyLabel?: string;
|
|
61
|
-
/** Called after a switch; refetch whatever depends on the organization. */
|
|
62
|
-
onOrganizationChanged?: (detail: OrganizationChangedDetail) => void;
|
|
63
|
-
/** Called when a switch is refused; the session is unchanged. */
|
|
64
|
-
onSwitchFailed?: (detail: {
|
|
65
|
-
organizationId: string;
|
|
66
|
-
error: unknown;
|
|
67
|
-
}) => void;
|
|
68
98
|
}
|
|
69
|
-
export interface AccountSettingsProps extends
|
|
70
|
-
|
|
71
|
-
orientation?:
|
|
72
|
-
|
|
73
|
-
mode
|
|
74
|
-
|
|
75
|
-
content?:
|
|
76
|
-
}
|
|
77
|
-
export interface MemberManagementProps extends
|
|
78
|
-
|
|
79
|
-
|
|
99
|
+
export interface AccountSettingsProps extends AccountWidgetProps {
|
|
100
|
+
mode?: AccountSettingsMode;
|
|
101
|
+
orientation?: AccountSettingsOrientation;
|
|
102
|
+
widgetsLayout?: AccountSettingsLayout;
|
|
103
|
+
/** Modal mode: whether the dialog is open. */
|
|
104
|
+
open?: boolean;
|
|
105
|
+
content?: AccountSettingsContent | null;
|
|
106
|
+
}
|
|
107
|
+
export interface MemberManagementProps extends AccountWidgetProps {
|
|
108
|
+
/** The organization to manage (default: the session's). */
|
|
109
|
+
organizationId?: string;
|
|
110
|
+
mode?: MemberManagementMode;
|
|
111
|
+
/** Modal mode: whether the dialog is open. */
|
|
112
|
+
open?: boolean;
|
|
113
|
+
heading?: string;
|
|
80
114
|
description?: string;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export interface AccountInfoProps extends WithChildren {
|
|
84
|
-
account?: AccountInfo;
|
|
85
|
-
showAvatarMenu?: boolean;
|
|
86
|
-
toggleAvatarMenu: (e: Event) => void;
|
|
87
|
-
onAvatarChange: () => void;
|
|
88
|
-
onAvatarRemove: () => void;
|
|
89
|
-
showIcons?: boolean;
|
|
90
|
-
content?: IProfileWidgetCustomization | null;
|
|
91
|
-
otpVariant?: "simple" | "with_spacing" | "with_separator" | "digits_only";
|
|
92
|
-
otpLength?: number;
|
|
93
|
-
Layout?: WidgetLayout;
|
|
94
|
-
}
|
|
95
|
-
export interface LocationInfoProps extends CommonWidgetProps {
|
|
96
|
-
locationInfo?: LocationInfo;
|
|
97
|
-
}
|
|
98
|
-
export interface UrlsInfoProps extends CommonWidgetProps {
|
|
99
|
-
URLsInfo?: URLsInfo;
|
|
100
|
-
}
|
|
101
|
-
export interface PersonalInfoProps extends CommonWidgetProps {
|
|
102
|
-
personal?: PersonalInfo;
|
|
103
|
-
}
|
|
104
|
-
export interface PersonalInfo {
|
|
105
|
-
username: string;
|
|
106
|
-
first: string;
|
|
107
|
-
middle: string;
|
|
108
|
-
last: string;
|
|
109
|
-
nickname: string;
|
|
110
|
-
gender: string;
|
|
111
|
-
bio: string;
|
|
112
|
-
}
|
|
113
|
-
export interface URLsInfo {
|
|
114
|
-
website: string;
|
|
115
|
-
}
|
|
116
|
-
export interface LocationInfo {
|
|
117
|
-
location: string;
|
|
118
|
-
zoneInfo: string;
|
|
119
|
-
}
|
|
120
|
-
export interface AccountInfo {
|
|
121
|
-
email: string;
|
|
122
|
-
phone: string;
|
|
123
|
-
avatar: string;
|
|
115
|
+
/** 5, 10 or 25. */
|
|
116
|
+
pageSize?: number;
|
|
124
117
|
}
|
|
125
|
-
export {};
|
package/dist/wrap.d.ts
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { ProviderProps as ReactProviderProps } from './types';
|
|
3
2
|
/**
|
|
4
|
-
* What a
|
|
5
|
-
* tools/gen-wrappers). The legacy wrappers pass none.
|
|
3
|
+
* What a wrapper says about its element (generated, see tools/gen-wrappers).
|
|
6
4
|
*/
|
|
7
5
|
export interface WrapOptions {
|
|
8
6
|
/**
|
|
9
|
-
* Callback prop -> DOM event.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* cancelable one can be `preventDefault()`ed).
|
|
7
|
+
* Callback prop -> DOM event. The elements report through events, so these
|
|
8
|
+
* props are listened for instead of assigned, and the callback gets the
|
|
9
|
+
* event itself (a cancelable one can be `preventDefault()`ed).
|
|
13
10
|
*/
|
|
14
11
|
events?: Readonly<Record<string, string>>;
|
|
15
12
|
/** Whether the element honours the `[part="fallback"]` contract. */
|
|
16
13
|
fallback?: boolean;
|
|
17
|
-
/** Starts the CDN load on mount
|
|
14
|
+
/** Starts the CDN load on mount. */
|
|
18
15
|
provider?: boolean;
|
|
19
16
|
}
|
|
20
17
|
/**
|
|
21
|
-
* A
|
|
22
|
-
*
|
|
18
|
+
* A React component over the custom element `tagName`, typed by `P` alone:
|
|
19
|
+
* children and `fallback` are whatever its props type says, because only the
|
|
23
20
|
* provider takes children and only the flow widgets honour a fallback.
|
|
24
21
|
*/
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function wrap<T extends HTMLElement, P = {}>(tagName: string, options?: WrapOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<P & React.RefAttributes<T> & (P extends ReactProviderProps ? {
|
|
27
|
-
children?: React.ReactNode;
|
|
28
|
-
} : {
|
|
29
|
-
children?: React.ReactNode;
|
|
30
|
-
fallback?: React.ReactNode | null;
|
|
31
|
-
})> & React.RefAttributes<T>>;
|
|
22
|
+
export declare function wrap<T extends HTMLElement, P = {}>(tagName: string, options?: WrapOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pontive/pontkit-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "React components over the pont-* custom elements
|
|
5
|
+
"description": "React components over the PontKit (pont-*) custom elements.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
8
8
|
"module": "./dist/index.js",
|
|
@@ -12,11 +12,6 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"import": "./dist/index.js",
|
|
14
14
|
"require": "./dist/index.cjs"
|
|
15
|
-
},
|
|
16
|
-
"./pont2": {
|
|
17
|
-
"types": "./dist/pont2/index.d.ts",
|
|
18
|
-
"import": "./dist/pont2.js",
|
|
19
|
-
"require": "./dist/pont2.cjs"
|
|
20
15
|
}
|
|
21
16
|
},
|
|
22
17
|
"files": [
|
|
@@ -36,11 +31,11 @@
|
|
|
36
31
|
"react-dom": "^18 || ^19"
|
|
37
32
|
},
|
|
38
33
|
"dependencies": {
|
|
39
|
-
"@pontive/
|
|
34
|
+
"@pontive/oidc-client": "^1.7.0",
|
|
35
|
+
"@pontive/pontkit-loader": "^1.7.0"
|
|
40
36
|
},
|
|
41
37
|
"devDependencies": {
|
|
42
|
-
"@pontive/
|
|
43
|
-
"@pontive/pontkit-core": "1.41.0",
|
|
38
|
+
"@pontive/pontkit-core": "1.43.0",
|
|
44
39
|
"@testing-library/dom": "^10.4.1",
|
|
45
40
|
"@testing-library/react": "^16.3.3",
|
|
46
41
|
"@types/react-dom": "^19.2.5",
|
package/dist/auth.d.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { AuthState, EnvConfig } from '@pontive/pontkit-core';
|
|
3
|
-
interface PontKitContextValue {
|
|
4
|
-
auth: AuthState;
|
|
5
|
-
/**
|
|
6
|
-
* Carried alongside the session because `<Authenticated>` needs it: its
|
|
7
|
-
* default redirect target is `env.signinUrl`, which the element read from the
|
|
8
|
-
* provider's Lit `envContext`. React has the same need and no way into that
|
|
9
|
-
* context, and the Provider already holds `env` as a prop.
|
|
10
|
-
*/
|
|
11
|
-
env: EnvConfig | null;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The current session state.
|
|
15
|
-
*
|
|
16
|
-
* Throws when there is no `<Provider>` above the caller, which is always a
|
|
17
|
-
* wiring mistake rather than a state to handle.
|
|
18
|
-
*/
|
|
19
|
-
export declare function useAuthState(): AuthState;
|
|
20
|
-
/** The `env` the nearest `<Provider>` was configured with. */
|
|
21
|
-
export declare function useEnvConfig(): EnvConfig | null;
|
|
22
|
-
/**
|
|
23
|
-
* Tracks the session by listening to the provider element.
|
|
24
|
-
*
|
|
25
|
-
* Subscribing is not enough on its own: the provider resolves after a network
|
|
26
|
-
* round trip, but nothing guarantees that happens *after* this listener is
|
|
27
|
-
* attached — a Provider mounted into an application that is already running has
|
|
28
|
-
* missed the event entirely. So the element's own `auth` property is read as a
|
|
29
|
-
* seed, both immediately and once the definition has arrived, since before the
|
|
30
|
-
* upgrade there is no property to read.
|
|
31
|
-
*/
|
|
32
|
-
export declare function useProviderAuthState(element: HTMLElement | null, tagName: string, eventName?: string): AuthState;
|
|
33
|
-
export declare function AuthStateProvider({ value, children, }: {
|
|
34
|
-
value: PontKitContextValue;
|
|
35
|
-
children?: React.ReactNode;
|
|
36
|
-
}): React.FunctionComponentElement<React.ProviderProps<PontKitContextValue | undefined>>;
|
|
37
|
-
export interface ControlProps {
|
|
38
|
-
children?: React.ReactNode;
|
|
39
|
-
/**
|
|
40
|
-
* What to render while the session is still being resolved.
|
|
41
|
-
*
|
|
42
|
-
* Both components render nothing during that window by default, because the
|
|
43
|
-
* interim answer is "signed out" and showing the signed-out branch to a
|
|
44
|
-
* signed-in user is the flash this is here to avoid.
|
|
45
|
-
*/
|
|
46
|
-
fallback?: React.ReactNode | null;
|
|
47
|
-
}
|
|
48
|
-
export declare function SignedIn({ children, fallback, }: ControlProps): React.ReactNode;
|
|
49
|
-
export declare function SignedOut({ children, fallback, }: ControlProps): React.ReactNode;
|
|
50
|
-
/**
|
|
51
|
-
* Renders its children once the session is known, and a placeholder until then.
|
|
52
|
-
*
|
|
53
|
-
* This replaces `<pont-auth-state>`, whose real job was pruning: it removed
|
|
54
|
-
* whichever of `<pont-signed-in>` / `<pont-signed-out>` did not apply, permanently,
|
|
55
|
-
* with `querySelectorAll(...).forEach(el => el.remove())`. Those tags are React
|
|
56
|
-
* components now and never reach the DOM, so the search finds nothing — the
|
|
57
|
-
* element still runs, and quietly does nothing at all.
|
|
58
|
-
*
|
|
59
|
-
* What is left is the half that was always worth having: one placeholder for a
|
|
60
|
-
* group, instead of a `fallback` on every child. `<SignedIn>` and `<SignedOut>`
|
|
61
|
-
* each gate on `resolved` themselves, so this is only about what fills the space
|
|
62
|
-
* while the answer is in flight.
|
|
63
|
-
*
|
|
64
|
-
* Named for the flag it gates on rather than inheriting the element's name,
|
|
65
|
-
* which described a state rather than a behaviour — and which collided with the
|
|
66
|
-
* `AuthState` type.
|
|
67
|
-
*/
|
|
68
|
-
export declare function AuthResolved({ children, fallback, }: ControlProps): React.ReactNode;
|
|
69
|
-
export interface AuthenticatedProps {
|
|
70
|
-
children?: React.ReactNode;
|
|
71
|
-
/**
|
|
72
|
-
* Rendered while the session is being resolved.
|
|
73
|
-
*
|
|
74
|
-
* The element spelled this `slot="loading"` and partitioned the children on
|
|
75
|
-
* capture, because it stayed in the light DOM and so had no real `<slot>` to
|
|
76
|
-
* use. A prop says the same thing without the machinery.
|
|
77
|
-
*/
|
|
78
|
-
loading?: React.ReactNode;
|
|
79
|
-
/** Where to send an unauthenticated visitor. Defaults to `env.signinUrl`. */
|
|
80
|
-
redirectUrl?: string;
|
|
81
|
-
/**
|
|
82
|
-
* Hand the navigation to the host's router instead of loading a new document.
|
|
83
|
-
*
|
|
84
|
-
* The default is a full page load, which is what the element did. In a single
|
|
85
|
-
* page application that throws away the router's state and everything else in
|
|
86
|
-
* memory, so a host with a router should pass its own navigate here —
|
|
87
|
-
* `(url) => navigate(url)` for React Router, `router.push` for Next.
|
|
88
|
-
*/
|
|
89
|
-
onRedirect?: (url: string) => void;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Renders its children only for a signed-in visitor, and sends everyone else to
|
|
93
|
-
* the sign-in page.
|
|
94
|
-
*
|
|
95
|
-
* The redirect runs in an effect, which is the substantive change from the
|
|
96
|
-
* element this replaces. That one assigned `window.location.href` from inside
|
|
97
|
-
* `render()` — a side effect in a method the framework may call whenever it
|
|
98
|
-
* likes, and which React would call twice in StrictMode. An effect fires once,
|
|
99
|
-
* after the commit, on a transition that actually happened.
|
|
100
|
-
*/
|
|
101
|
-
export declare function Authenticated({ children, loading, redirectUrl, onRedirect, }: AuthenticatedProps): React.ReactNode;
|
|
102
|
-
export {};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { forwardRef as x, useRef as P, useState as D, useEffect as A, createElement as U, useLayoutEffect as z, createContext as F, useContext as M } from "react";
|
|
2
|
-
import { createPortal as T } from "react-dom";
|
|
3
|
-
import { loadWebComponents as V } from "@pontive/pontkit-loader";
|
|
4
|
-
const _ = /* @__PURE__ */ new Set(["className", "style", "id", "slot"]), b = typeof window < "u" ? z : A;
|
|
5
|
-
function Q(e, t) {
|
|
6
|
-
return $(e, t);
|
|
7
|
-
}
|
|
8
|
-
function $(e, t) {
|
|
9
|
-
const r = e === "pont-provider" || !!t?.provider, o = t?.events ?? {}, c = new Set(Object.keys(o)), f = t ? !!t.fallback : !0;
|
|
10
|
-
return x((a, s) => {
|
|
11
|
-
const l = P(null), i = P({}), d = P({}), [y, k] = D(null), { fallback: E, children: I, ...K } = a, S = {}, C = {}, O = {};
|
|
12
|
-
for (const [n, u] of Object.entries(K))
|
|
13
|
-
c.has(n) ? O[n] = u : (_.has(n) ? S : C)[n] = u;
|
|
14
|
-
d.current = O, A(() => {
|
|
15
|
-
r && V().catch(console.error);
|
|
16
|
-
}, []), b(() => {
|
|
17
|
-
const n = l.current;
|
|
18
|
-
if (!n) return;
|
|
19
|
-
let u = !1;
|
|
20
|
-
function v() {
|
|
21
|
-
if (!(u || !n)) {
|
|
22
|
-
for (const [h, p] of Object.entries(C))
|
|
23
|
-
if (i.current[h] !== p)
|
|
24
|
-
try {
|
|
25
|
-
n[h] = p, i.current[h] = p;
|
|
26
|
-
} catch {
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return customElements.get(e) ? v() : customElements.whenDefined(e).then(v), () => {
|
|
31
|
-
u = !0;
|
|
32
|
-
};
|
|
33
|
-
}), b(() => {
|
|
34
|
-
const n = l.current;
|
|
35
|
-
if (!n || c.size === 0) return;
|
|
36
|
-
const u = Object.entries(o).map(([v, h]) => {
|
|
37
|
-
const p = (W) => {
|
|
38
|
-
const L = d.current[v];
|
|
39
|
-
typeof L == "function" && L(W);
|
|
40
|
-
};
|
|
41
|
-
return n.addEventListener(h, p), () => n.removeEventListener(h, p);
|
|
42
|
-
});
|
|
43
|
-
return () => u.forEach((v) => v());
|
|
44
|
-
}, []), b(() => {
|
|
45
|
-
const n = l.current;
|
|
46
|
-
if (!n || E == null || !f) return;
|
|
47
|
-
const u = document.createElement("div");
|
|
48
|
-
return u.setAttribute("part", "fallback"), n.prepend(u), k(u), () => {
|
|
49
|
-
u.remove(), k(null);
|
|
50
|
-
};
|
|
51
|
-
}, [E == null]);
|
|
52
|
-
function R(n) {
|
|
53
|
-
l.current = n, typeof s == "function" ? s(n) : s && (s.current = n);
|
|
54
|
-
}
|
|
55
|
-
return U(
|
|
56
|
-
e,
|
|
57
|
-
{ ...S, ref: R },
|
|
58
|
-
I ?? null,
|
|
59
|
-
y ? T(E, y) : null
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
const q = { isAuthenticated: !1, resolved: !1 }, H = F(
|
|
64
|
-
void 0
|
|
65
|
-
);
|
|
66
|
-
function g(e) {
|
|
67
|
-
const t = M(H);
|
|
68
|
-
if (t === void 0)
|
|
69
|
-
throw new Error(
|
|
70
|
-
`${e} was called outside <Provider>. Wrap your app in the Provider from @pontive/pontkit-react/react — the same component that configures \`env\`.`
|
|
71
|
-
);
|
|
72
|
-
return t;
|
|
73
|
-
}
|
|
74
|
-
function w() {
|
|
75
|
-
return g("useAuthState").auth;
|
|
76
|
-
}
|
|
77
|
-
function X() {
|
|
78
|
-
return g("useEnvConfig").env;
|
|
79
|
-
}
|
|
80
|
-
function Y(e, t, r = "pont:auth-changed") {
|
|
81
|
-
const [o, c] = D(q);
|
|
82
|
-
return A(() => {
|
|
83
|
-
if (!e) return;
|
|
84
|
-
let f = !1;
|
|
85
|
-
function a(i) {
|
|
86
|
-
f || !i || c(
|
|
87
|
-
(d) => d.isAuthenticated === i.isAuthenticated && d.resolved === i.resolved ? d : { isAuthenticated: !!i.isAuthenticated, resolved: !!i.resolved }
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
function s(i) {
|
|
91
|
-
a(i.detail);
|
|
92
|
-
}
|
|
93
|
-
e.addEventListener(r, s);
|
|
94
|
-
function l() {
|
|
95
|
-
a(e?.auth);
|
|
96
|
-
}
|
|
97
|
-
return l(), customElements.whenDefined(t).then(l), () => {
|
|
98
|
-
f = !0, e.removeEventListener(r, s);
|
|
99
|
-
};
|
|
100
|
-
}, [e, t, r]), o;
|
|
101
|
-
}
|
|
102
|
-
function Z({
|
|
103
|
-
value: e,
|
|
104
|
-
children: t
|
|
105
|
-
}) {
|
|
106
|
-
return U(H.Provider, { value: e }, t);
|
|
107
|
-
}
|
|
108
|
-
function N({
|
|
109
|
-
children: e,
|
|
110
|
-
fallback: t = null
|
|
111
|
-
}) {
|
|
112
|
-
const { isAuthenticated: r, resolved: o } = w();
|
|
113
|
-
return o ? r ? e : null : t;
|
|
114
|
-
}
|
|
115
|
-
function ee({
|
|
116
|
-
children: e,
|
|
117
|
-
fallback: t = null
|
|
118
|
-
}) {
|
|
119
|
-
const { isAuthenticated: r, resolved: o } = w();
|
|
120
|
-
return o ? r ? null : e : t;
|
|
121
|
-
}
|
|
122
|
-
function te({
|
|
123
|
-
children: e,
|
|
124
|
-
fallback: t = null
|
|
125
|
-
}) {
|
|
126
|
-
const { resolved: r } = w();
|
|
127
|
-
return r ? e : t;
|
|
128
|
-
}
|
|
129
|
-
function ne({
|
|
130
|
-
children: e,
|
|
131
|
-
loading: t = null,
|
|
132
|
-
redirectUrl: r,
|
|
133
|
-
onRedirect: o
|
|
134
|
-
}) {
|
|
135
|
-
const { auth: c, env: f } = g("Authenticated"), a = P(!1), s = r || f?.signinUrl;
|
|
136
|
-
return A(() => {
|
|
137
|
-
if (!(!c.resolved || c.isAuthenticated) && !a.current) {
|
|
138
|
-
if (!s) {
|
|
139
|
-
console.error(
|
|
140
|
-
"[pontive] <Authenticated> has nobody to redirect to: pass `redirectUrl`, or give the Provider an `env.signinUrl`."
|
|
141
|
-
);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
a.current = !0, o ? o(s) : window.location.href = s;
|
|
145
|
-
}
|
|
146
|
-
}, [c.resolved, c.isAuthenticated, s, o]), c.resolved ? c.isAuthenticated ? e : null : t;
|
|
147
|
-
}
|
|
148
|
-
const m = { legacy: 0, pont2: 0 };
|
|
149
|
-
let j = !1;
|
|
150
|
-
function re(e) {
|
|
151
|
-
A(() => (m[e] += 1, !j && m.legacy > 0 && m.pont2 > 0 && (j = !0, console.warn(
|
|
152
|
-
"[pontive] <Provider> (@pontive/pontkit-react) and <Pont2Provider> (@pontive/pontkit-react/pont2) are mounted together. They share one Auth and one configuration, so each overwrites the other's: mount only one per page."
|
|
153
|
-
)), () => {
|
|
154
|
-
m[e] -= 1;
|
|
155
|
-
}), [e]);
|
|
156
|
-
}
|
|
157
|
-
export {
|
|
158
|
-
Z as A,
|
|
159
|
-
N as S,
|
|
160
|
-
Y as a,
|
|
161
|
-
te as b,
|
|
162
|
-
ne as c,
|
|
163
|
-
ee as d,
|
|
164
|
-
w as e,
|
|
165
|
-
X as f,
|
|
166
|
-
Q as g,
|
|
167
|
-
re as u,
|
|
168
|
-
$ as w
|
|
169
|
-
};
|
|
170
|
-
//# sourceMappingURL=coexistence-CEqhGd4-.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coexistence-CEqhGd4-.js","sources":["../src/wrap.ts","../src/auth.ts","../src/coexistence.ts"],"sourcesContent":["import React, {\n createElement,\n forwardRef,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { loadWebComponents } from \"@pontive/pontkit-loader\";\nimport type { ProviderProps as ReactProviderProps } from \"./types\";\n\n/**\n * React components over the custom elements the core SDK defines.\n *\n * One rule holds this file together, and every bug it used to have was a\n * violation of it: **React owns the tag, the element owns everything inside it,\n * and React never reconciles a node the element touches.**\n *\n * The version this replaces built `<pont-provider>` with `document.createElement`\n * and then spliced it into the page by hand:\n *\n * parent.replaceChild(providerEl, container);\n * providerEl.appendChild(container);\n *\n * That moves a div React rendered, and owns, underneath an element React has\n * never heard of. React keeps its own picture of the DOM and does not re-read\n * it, so from that moment its picture said the container was a child of\n * `<body>` while the browser said it was a child of `<pont-provider>`. The two\n * disagreed silently until React next placed a node against that container:\n *\n * NotFoundError: Failed to execute 'insertBefore' on 'Node': the node\n * before which the new node is to be inserted is not a child of this node.\n *\n * The throw lands in React's commit phase, which has no recovery — the tree is\n * abandoned mid-commit and the application disappears from the page. In a\n * Next.js app it fired on the first client-side navigation, so signing in\n * appeared to work and then left a blank document behind.\n *\n * Rendering the tag is both the fix and the simpler thing. A custom element is\n * inert until its definition arrives and upgrades in place when it does, so\n * there is nothing to wait for and nothing to move; the `sdkReady` gate that\n * used to hold every widget back until the CDN answered bought nothing and is\n * gone with it. Widgets now server-render as empty tags and fill themselves in\n * on upgrade, which is what a custom element is for.\n */\n\n/**\n * Props React sets itself, because they are ordinary DOM attributes rather than\n * component inputs. Everything else is assigned as a property — see below for\n * why that distinction cannot be left to React.\n */\nconst DOM_PROPS = new Set([\"className\", \"style\", \"id\", \"slot\"]);\n\ntype UnknownProps = Record<string, unknown>;\n\n/**\n * Everything here has to be in place before the element's first update, and a\n * passive effect is not.\n *\n * Lit schedules its update as a microtask when the element connects, which is\n * during React's commit; passive effects are flushed in a later task. On a cold\n * load nobody notices, because the element is waiting on the CDN and a network\n * round trip. On a client-side navigation, where the provider has already\n * resolved the session, the element updates and goes looking for its\n * placeholder immediately — and a placeholder created in a passive effect does\n * not exist yet, so the element never removes it and it stays on screen over\n * the finished widget. A layout effect runs synchronously in the commit, before\n * the stack unwinds and Lit's microtask gets its turn.\n *\n * On a server there is no layout to read, and React warns about useLayoutEffect\n * for that reason. useEffect is the same no-op without the noise.\n */\nconst useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\n/**\n * What a pont2 wrapper says about its element (generated, see\n * tools/gen-wrappers). The legacy wrappers pass none.\n */\nexport interface WrapOptions {\n /**\n * Callback prop -> DOM event. pont2 elements report through events where\n * the legacy ones took callback properties, so these props are listened\n * for instead of assigned, and the callback gets the event itself (a\n * cancelable one can be `preventDefault()`ed).\n */\n events?: Readonly<Record<string, string>>;\n /** Whether the element honours the `[part=\"fallback\"]` contract. */\n fallback?: boolean;\n /** Starts the CDN load on mount, as the legacy provider does. */\n provider?: boolean;\n}\n\n/**\n * A pont2 wrapper: `wrap()` with the element's options, typed by `P` alone.\n * Children and `fallback` are whatever its props type says, because only the\n * provider takes children and only the flow widgets honour a fallback.\n */\nexport function wrapPont2<T extends HTMLElement, P = {}>(\n tagName: string,\n options: WrapOptions,\n) {\n return wrap<T, P>(tagName, options) as unknown as React.ForwardRefExoticComponent<\n React.PropsWithoutRef<P> & React.RefAttributes<T>\n >;\n}\n\nexport function wrap<T extends HTMLElement, P = {}>(\n tagName: string,\n options?: WrapOptions,\n) {\n type Props = P &\n React.RefAttributes<T> &\n (P extends ReactProviderProps\n ? { children?: React.ReactNode }\n : {\n children?: React.ReactNode;\n fallback?: React.ReactNode | null;\n });\n\n const isProvider = tagName === \"pont-provider\" || !!options?.provider;\n const events = options?.events ?? {};\n const eventProps = new Set(Object.keys(events));\n const fallbackAllowed = options ? !!options.fallback : true;\n\n return forwardRef<T, Props>((props, forwardedRef) => {\n const elementRef = useRef<T | null>(null);\n const assigned = useRef<UnknownProps>({});\n // The latest callbacks, read when an event fires, so a new function on\n // every render does not re-subscribe.\n const callbacks = useRef<UnknownProps>({});\n const [fallbackHost, setFallbackHost] = useState<HTMLElement | null>(null);\n\n const { fallback, children, ...rest } = props as UnknownProps & {\n fallback?: React.ReactNode;\n children?: React.ReactNode;\n };\n\n const domProps: UnknownProps = {};\n const elementProps: UnknownProps = {};\n\n const eventCallbacks: UnknownProps = {};\n\n for (const [key, value] of Object.entries(rest)) {\n if (eventProps.has(key)) eventCallbacks[key] = value;\n else (DOM_PROPS.has(key) ? domProps : elementProps)[key] = value;\n }\n\n callbacks.current = eventCallbacks;\n\n // The provider is the one component every app mounts, which makes it the\n // honest place to start the CDN fetch. Importing the root entry also kicks\n // it off, but the React entry can be imported on its own.\n useEffect(() => {\n if (!isProvider) return;\n loadWebComponents().catch(console.error);\n }, []);\n\n /**\n * Component inputs are assigned as DOM properties, once the tag is defined.\n *\n * Both halves of that matter. An attribute can only ever hold a string, so\n * `env` and `menuItems` cannot travel as one — and React 19's own custom\n * element support does not save us here, because it chooses between\n * property and attribute by testing `'env' in element`. The definitions\n * arrive from a CDN long after React first renders, so that test runs\n * against an un-upgraded element, finds no property, and writes the\n * attribute `env=\"[object Object]\"` for Lit to try to parse.\n *\n * Waiting for the definition is the other half. Assigning to an element\n * that has not upgraded writes an own property, and Lit's accessor — added\n * to the prototype at upgrade — is then shadowed by it for good: the value\n * sits on the element in plain sight and the component never observes it.\n */\n useIsomorphicLayoutEffect(() => {\n const el = elementRef.current;\n if (!el) return;\n\n let cancelled = false;\n\n function assign() {\n if (cancelled || !el) return;\n\n for (const [key, value] of Object.entries(elementProps)) {\n // Re-assigning an unchanged value would still mark the property\n // dirty and re-render the element on every React render.\n if (assigned.current[key] === value) continue;\n\n try {\n (el as unknown as UnknownProps)[key] = value;\n assigned.current[key] = value;\n } catch {\n // A read-only property on the element is the element's business.\n }\n }\n }\n\n if (customElements.get(tagName)) assign();\n else void customElements.whenDefined(tagName).then(assign);\n\n return () => {\n cancelled = true;\n };\n });\n\n /**\n * The element's events, mapped to callback props (pont2 only).\n *\n * Subscribed in a layout effect, like the properties above, so an event\n * fired during the element's first update is not missed. Listening needs\n * no definition: an un-upgraded element is still an event target.\n */\n useIsomorphicLayoutEffect(() => {\n const el = elementRef.current;\n if (!el || eventProps.size === 0) return;\n\n const listeners = Object.entries(events).map(([prop, type]) => {\n const listener = (event: Event) => {\n const callback = callbacks.current[prop];\n if (typeof callback === \"function\") callback(event);\n };\n el.addEventListener(type, listener);\n return () => el.removeEventListener(type, listener);\n });\n\n return () => listeners.forEach((remove) => remove());\n }, []);\n\n /**\n * The fallback is rendered through a portal into a node built by hand.\n *\n * Every widget looks for a `[part=\"fallback\"]` child once it has something\n * real to show, and removes it — that is the placeholder's whole contract,\n * and `[pont-signin] fallback not found yet` on repeat is that search coming\n * up empty. But a React child that something else deletes is the same\n * desynchronised DOM described at the top of this file, so React cannot own\n * the node it hands over.\n *\n * A portal splits the difference: the host div is ours to give away, while\n * the content inside it stays an ordinary part of the React tree. When the\n * element deletes the host, React's nodes go with it into a detached\n * subtree it can still unmount from safely.\n *\n * The host is built after mount rather than during render, and that is not\n * a stylistic choice. Building it during render means branching on\n * `typeof document`, so the server renders no portal and the client's\n * hydration render does — React compares the two and reports\n *\n * Hydration failed because the server rendered HTML didn't match the\n * client\n *\n * naming the placeholder as the extra node. Creating it here keeps the\n * first client render identical to the server's; the state update below is\n * flushed synchronously before paint, so the placeholder still lands ahead\n * of the element's first update.\n *\n * The cost is that the placeholder does not server-render. The window it\n * covers is the CDN fetch, which is far longer than the one before\n * hydration, so this is nearly all of what the placeholder was for.\n */\n useIsomorphicLayoutEffect(() => {\n const el = elementRef.current;\n if (!el || fallback == null || !fallbackAllowed) return;\n\n const host = document.createElement(\"div\");\n host.setAttribute(\"part\", \"fallback\");\n el.prepend(host);\n setFallbackHost(host);\n\n return () => {\n // A no-op once the element has removed it, which is the ordinary case.\n host.remove();\n setFallbackHost(null);\n };\n }, [fallback == null]);\n\n function setRef(el: T | null) {\n elementRef.current = el;\n\n if (typeof forwardedRef === \"function\") forwardedRef(el);\n else if (forwardedRef) forwardedRef.current = el;\n }\n\n return createElement(\n tagName,\n { ...domProps, ref: setRef },\n children ?? null,\n fallbackHost ? createPortal(fallback, fallbackHost) : null,\n );\n });\n}\n","import React, {\n createContext,\n createElement,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport type { AuthState, EnvConfig } from \"@pontive/pontkit-core\";\n\n/**\n * The session, as React sees it.\n *\n * `<SignedIn>` and `<SignedOut>` used to be `<pont-signed-in>` and\n * `<pont-signed-out>`: custom elements that cached their child nodes on connect,\n * removed them, and re-rendered them inside a `<div>` of their own once the\n * session resolved. React went on believing those children were where it had\n * put them. Static children survived it; a child React later wanted to update\n * or remove was one it could no longer find — the same defect as the\n * `insertBefore` crash in `wrap()`, one level down.\n *\n * A control component has no business owning DOM at all. It is a question about\n * the session and a branch on the answer, so here it is a hook and a\n * conditional, and React keeps every node.\n *\n * The one thing that needs building is a way for React to see the session.\n * `pont-provider` publishes it on a Lit context, which nothing outside the custom\n * element tree can read, and `Auth` cannot answer instead: `resolved` means\n * \"restoreSession() has come back\", which is the provider's knowledge, not the\n * SDK's. So the provider also dispatches `pont:auth-changed`, and this file turns\n * that into React context.\n */\n\nconst UNRESOLVED: AuthState = { isAuthenticated: false, resolved: false };\n\ninterface PontKitContextValue {\n auth: AuthState;\n /**\n * Carried alongside the session because `<Authenticated>` needs it: its\n * default redirect target is `env.signinUrl`, which the element read from the\n * provider's Lit `envContext`. React has the same need and no way into that\n * context, and the Provider already holds `env` as a prop.\n */\n env: EnvConfig | null;\n}\n\n/**\n * `undefined` rather than a default value, so \"no Provider above me\" is a state\n * the hooks can tell apart from \"not resolved yet\". Defaulting to UNRESOLVED\n * would make a missing Provider look like a session that never resolves, and\n * every control component below it would render nothing forever without saying\n * why.\n */\nconst PontKitContext = createContext<PontKitContextValue | undefined>(\n undefined,\n);\n\nfunction usePontKitContext(caller: string): PontKitContextValue {\n const value = useContext(PontKitContext);\n\n if (value === undefined) {\n throw new Error(\n `${caller} was called outside <Provider>. Wrap your app in the Provider ` +\n \"from @pontive/pontkit-react/react — the same component that \" +\n \"configures `env`.\",\n );\n }\n\n return value;\n}\n\n/**\n * The current session state.\n *\n * Throws when there is no `<Provider>` above the caller, which is always a\n * wiring mistake rather than a state to handle.\n */\nexport function useAuthState(): AuthState {\n return usePontKitContext(\"useAuthState\").auth;\n}\n\n/** The `env` the nearest `<Provider>` was configured with. */\nexport function useEnvConfig(): EnvConfig | null {\n return usePontKitContext(\"useEnvConfig\").env;\n}\n\n/**\n * Tracks the session by listening to the provider element.\n *\n * Subscribing is not enough on its own: the provider resolves after a network\n * round trip, but nothing guarantees that happens *after* this listener is\n * attached — a Provider mounted into an application that is already running has\n * missed the event entirely. So the element's own `auth` property is read as a\n * seed, both immediately and once the definition has arrived, since before the\n * upgrade there is no property to read.\n */\nexport function useProviderAuthState(\n element: HTMLElement | null,\n tagName: string,\n // `pont2-auth-changed` for `<pont2-provider>` (pontkit-core decision D10).\n eventName = \"pont:auth-changed\",\n): AuthState {\n const [auth, setAuth] = useState<AuthState>(UNRESOLVED);\n\n useEffect(() => {\n if (!element) return;\n\n let cancelled = false;\n\n function accept(next: AuthState | undefined) {\n if (cancelled || !next) return;\n\n setAuth((current) =>\n current.isAuthenticated === next.isAuthenticated &&\n current.resolved === next.resolved\n ? current\n : { isAuthenticated: !!next.isAuthenticated, resolved: !!next.resolved },\n );\n }\n\n function onAuthChanged(event: Event) {\n accept((event as CustomEvent<AuthState>).detail);\n }\n\n element.addEventListener(eventName, onAuthChanged);\n\n function seed() {\n accept((element as unknown as { auth?: AuthState } | null)?.auth);\n }\n\n seed();\n void customElements.whenDefined(tagName).then(seed);\n\n return () => {\n cancelled = true;\n element.removeEventListener(eventName, onAuthChanged);\n };\n }, [element, tagName, eventName]);\n\n return auth;\n}\n\nexport function AuthStateProvider({\n value,\n children,\n}: {\n value: PontKitContextValue;\n children?: React.ReactNode;\n}) {\n return createElement(PontKitContext.Provider, { value }, children);\n}\n\nexport interface ControlProps {\n children?: React.ReactNode;\n /**\n * What to render while the session is still being resolved.\n *\n * Both components render nothing during that window by default, because the\n * interim answer is \"signed out\" and showing the signed-out branch to a\n * signed-in user is the flash this is here to avoid.\n */\n fallback?: React.ReactNode | null;\n}\n\nexport function SignedIn({\n children,\n fallback = null,\n}: ControlProps): React.ReactNode {\n const { isAuthenticated, resolved } = useAuthState();\n\n if (!resolved) return fallback;\n\n return isAuthenticated ? children : null;\n}\n\nexport function SignedOut({\n children,\n fallback = null,\n}: ControlProps): React.ReactNode {\n const { isAuthenticated, resolved } = useAuthState();\n\n if (!resolved) return fallback;\n\n return isAuthenticated ? null : children;\n}\n\n/**\n * Renders its children once the session is known, and a placeholder until then.\n *\n * This replaces `<pont-auth-state>`, whose real job was pruning: it removed\n * whichever of `<pont-signed-in>` / `<pont-signed-out>` did not apply, permanently,\n * with `querySelectorAll(...).forEach(el => el.remove())`. Those tags are React\n * components now and never reach the DOM, so the search finds nothing — the\n * element still runs, and quietly does nothing at all.\n *\n * What is left is the half that was always worth having: one placeholder for a\n * group, instead of a `fallback` on every child. `<SignedIn>` and `<SignedOut>`\n * each gate on `resolved` themselves, so this is only about what fills the space\n * while the answer is in flight.\n *\n * Named for the flag it gates on rather than inheriting the element's name,\n * which described a state rather than a behaviour — and which collided with the\n * `AuthState` type.\n */\nexport function AuthResolved({\n children,\n fallback = null,\n}: ControlProps): React.ReactNode {\n const { resolved } = useAuthState();\n\n return resolved ? children : fallback;\n}\n\nexport interface AuthenticatedProps {\n children?: React.ReactNode;\n /**\n * Rendered while the session is being resolved.\n *\n * The element spelled this `slot=\"loading\"` and partitioned the children on\n * capture, because it stayed in the light DOM and so had no real `<slot>` to\n * use. A prop says the same thing without the machinery.\n */\n loading?: React.ReactNode;\n /** Where to send an unauthenticated visitor. Defaults to `env.signinUrl`. */\n redirectUrl?: string;\n /**\n * Hand the navigation to the host's router instead of loading a new document.\n *\n * The default is a full page load, which is what the element did. In a single\n * page application that throws away the router's state and everything else in\n * memory, so a host with a router should pass its own navigate here —\n * `(url) => navigate(url)` for React Router, `router.push` for Next.\n */\n onRedirect?: (url: string) => void;\n}\n\n/**\n * Renders its children only for a signed-in visitor, and sends everyone else to\n * the sign-in page.\n *\n * The redirect runs in an effect, which is the substantive change from the\n * element this replaces. That one assigned `window.location.href` from inside\n * `render()` — a side effect in a method the framework may call whenever it\n * likes, and which React would call twice in StrictMode. An effect fires once,\n * after the commit, on a transition that actually happened.\n */\nexport function Authenticated({\n children,\n loading = null,\n redirectUrl,\n onRedirect,\n}: AuthenticatedProps): React.ReactNode {\n const { auth, env } = usePontKitContext(\"Authenticated\");\n const redirected = useRef(false);\n\n const target = redirectUrl || env?.signinUrl;\n\n useEffect(() => {\n // Never on the interim answer. On a fresh page an app using HttpOnly cookie\n // delivery holds no session locally, so `isAuthenticated` is false for a\n // signed-in user right up until the cookie has been tried — redirecting on\n // that sends every reload and every post-sign-in return to the sign-in page.\n if (!auth.resolved || auth.isAuthenticated) return;\n\n // A redirect is not idempotent, and a re-render before the browser has\n // navigated would otherwise fire it again.\n if (redirected.current) return;\n\n if (!target) {\n console.error(\n \"[pontive] <Authenticated> has nobody to redirect to: pass \" +\n \"`redirectUrl`, or give the Provider an `env.signinUrl`.\",\n );\n return;\n }\n\n redirected.current = true;\n\n if (onRedirect) onRedirect(target);\n else window.location.href = target;\n }, [auth.resolved, auth.isAuthenticated, target, onRedirect]);\n\n if (!auth.resolved) return loading;\n\n // Nothing for the visitor being redirected. The navigation is in flight and\n // this content is not theirs to see.\n return auth.isAuthenticated ? children : null;\n}\n","import { useEffect } from \"react\";\n\n/**\n * One provider per page (pontkit-core tracker W-15).\n *\n * `<Provider>` (legacy `<pont-provider>`) and `<Pont2Provider>`\n * (`<pont2-provider>`) configure the one `Auth` the bundle carries, and\n * `configure()` replaces the whole configuration: mounted together, each\n * overwrites the other's, and their widgets miss each other's flow events and\n * locale. The elements already warn about each other once the bundle has\n * loaded; this says it from React, at mount, naming the components the app\n * actually wrote.\n *\n * Counted per kind rather than flagged, so a provider that unmounts (a route\n * change) stops counting. Warns once per page load.\n */\ntype Kind = \"legacy\" | \"pont2\";\n\nconst mounted: Record<Kind, number> = { legacy: 0, pont2: 0 };\nlet warned = false;\n\nexport function useProviderPresence(kind: Kind): void {\n useEffect(() => {\n mounted[kind] += 1;\n\n if (!warned && mounted.legacy > 0 && mounted.pont2 > 0) {\n warned = true;\n console.warn(\n \"[pontive] <Provider> (@pontive/pontkit-react) and <Pont2Provider> \" +\n \"(@pontive/pontkit-react/pont2) are mounted together. They share one \" +\n \"Auth and one configuration, so each overwrites the other's: mount \" +\n \"only one per page.\",\n );\n }\n\n return () => {\n mounted[kind] -= 1;\n };\n }, [kind]);\n}\n\n/** Test seam: forget what was counted and warned. */\nexport function resetProviderPresence(): void {\n mounted.legacy = 0;\n mounted.pont2 = 0;\n warned = false;\n}\n"],"names":["DOM_PROPS","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","wrapPont2","tagName","options","wrap","isProvider","events","eventProps","fallbackAllowed","forwardRef","props","forwardedRef","elementRef","useRef","assigned","callbacks","fallbackHost","setFallbackHost","useState","fallback","children","rest","domProps","elementProps","eventCallbacks","key","value","loadWebComponents","el","cancelled","assign","listeners","prop","type","listener","event","callback","remove","host","setRef","createElement","createPortal","UNRESOLVED","PontKitContext","createContext","usePontKitContext","caller","useContext","useAuthState","useEnvConfig","useProviderAuthState","element","eventName","auth","setAuth","accept","next","current","onAuthChanged","seed","AuthStateProvider","SignedIn","isAuthenticated","resolved","SignedOut","AuthResolved","Authenticated","loading","redirectUrl","onRedirect","env","redirected","target","mounted","warned","useProviderPresence","kind"],"mappings":";;;AAoDA,MAAMA,wBAAgB,IAAI,CAAC,aAAa,SAAS,MAAM,MAAM,CAA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