@revenuecat/purchases-ui-js 4.8.3 → 4.8.5
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/components/express-purchase-button/ExpressPurchaseButton.stories.svelte +44 -0
- package/dist/components/express-purchase-button/ExpressPurchaseButton.svelte +12 -2
- package/dist/components/express-purchase-button/component-subtree-utils.d.ts +5 -0
- package/dist/components/express-purchase-button/component-subtree-utils.js +31 -0
- package/dist/components/package/Package.svelte +3 -0
- package/dist/components/purchase-button/PurchaseButton.svelte +7 -1
- package/dist/components/stack/Stack.svelte +15 -1
- package/dist/stores/packageId.d.ts +2 -0
- package/dist/stores/packageId.js +8 -0
- package/package.json +1 -1
|
@@ -377,6 +377,50 @@
|
|
|
377
377
|
args={{}}
|
|
378
378
|
/>
|
|
379
379
|
|
|
380
|
+
<Story
|
|
381
|
+
name="Missing Wallet Button"
|
|
382
|
+
decorators={[
|
|
383
|
+
paywallDecorator(
|
|
384
|
+
createWalletButtonRender({ available: true, delay: 1000 }),
|
|
385
|
+
"some-package-id",
|
|
386
|
+
),
|
|
387
|
+
]}
|
|
388
|
+
args={{
|
|
389
|
+
wallet_available_stack: {
|
|
390
|
+
type: "stack",
|
|
391
|
+
id: "wallet-available-stack-without-wallet-button",
|
|
392
|
+
name: "Wallet Available Stack Without Wallet Button",
|
|
393
|
+
components: [purchaseButtonWhenAvailableProps],
|
|
394
|
+
size: {
|
|
395
|
+
width: { type: "fill" },
|
|
396
|
+
height: { type: "fit" },
|
|
397
|
+
},
|
|
398
|
+
dimension: {
|
|
399
|
+
type: "vertical",
|
|
400
|
+
alignment: "center",
|
|
401
|
+
distribution: "center",
|
|
402
|
+
},
|
|
403
|
+
spacing: 8,
|
|
404
|
+
margin: { top: 0, trailing: 0, bottom: 0, leading: 0 },
|
|
405
|
+
padding: { top: 16, trailing: 16, bottom: 16, leading: 16 },
|
|
406
|
+
background_color: null,
|
|
407
|
+
background: null,
|
|
408
|
+
border: null,
|
|
409
|
+
shape: {
|
|
410
|
+
type: "rectangle",
|
|
411
|
+
corners: {
|
|
412
|
+
top_leading: 8,
|
|
413
|
+
top_trailing: 8,
|
|
414
|
+
bottom_leading: 8,
|
|
415
|
+
bottom_trailing: 8,
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
shadow: null,
|
|
419
|
+
badge: null,
|
|
420
|
+
},
|
|
421
|
+
}}
|
|
422
|
+
/>
|
|
423
|
+
|
|
380
424
|
<Story
|
|
381
425
|
name="Parent Stack Props"
|
|
382
426
|
decorators={[
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { getPaywallContext, setPaywallContext } from "../../stores/paywall";
|
|
4
4
|
import type { ExpressPurchaseButtonProps } from "../../types/components/express-purchase-button-props";
|
|
5
5
|
import type { StackProps } from "../../types/components/stack";
|
|
6
|
+
import { hasComponentOfTypeInSubtree } from "./component-subtree-utils";
|
|
6
7
|
|
|
7
8
|
const props: ExpressPurchaseButtonProps = $props();
|
|
8
9
|
const {
|
|
@@ -15,8 +16,17 @@
|
|
|
15
16
|
|
|
16
17
|
const { walletButtonRender, ...rest } = getPaywallContext();
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const availableStackHasWalletButton = hasComponentOfTypeInSubtree(
|
|
20
|
+
wallet_available_stack,
|
|
21
|
+
"wallet_button",
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
let walletButtonAvailable = $state<boolean | undefined>(
|
|
25
|
+
availableStackHasWalletButton ? undefined : false,
|
|
26
|
+
);
|
|
27
|
+
let shouldShowWalletSkeleton = $state(
|
|
28
|
+
!!walletButtonRender && availableStackHasWalletButton,
|
|
29
|
+
);
|
|
20
30
|
|
|
21
31
|
const onWalletButtonReady = (isAvailable?: boolean) => {
|
|
22
32
|
walletButtonAvailable = isAvailable;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Component } from "../../types/component";
|
|
2
|
+
import type { StackProps } from "../../types/components/stack";
|
|
3
|
+
type ComponentType = Component["type"];
|
|
4
|
+
export declare const hasComponentOfTypeInSubtree: (stack: StackProps, componentType: ComponentType) => boolean;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const hasComponentOfTypeInSubtree = (stack, componentType) => {
|
|
2
|
+
return (stack.components.some((component) => componentHasTypeInSubtree(component, componentType)) ||
|
|
3
|
+
(stack.badge?.stack
|
|
4
|
+
? hasComponentOfTypeInSubtree(stack.badge.stack, componentType)
|
|
5
|
+
: false));
|
|
6
|
+
};
|
|
7
|
+
const componentHasTypeInSubtree = (component, componentType) => {
|
|
8
|
+
if (component.type === componentType) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (component.fallback &&
|
|
12
|
+
componentHasTypeInSubtree(component.fallback, componentType)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
switch (component.type) {
|
|
16
|
+
case "carousel":
|
|
17
|
+
return component.pages.some((page) => hasComponentOfTypeInSubtree(page, componentType));
|
|
18
|
+
case "package":
|
|
19
|
+
case "purchase_button":
|
|
20
|
+
case "tab":
|
|
21
|
+
case "tab_control_button":
|
|
22
|
+
return hasComponentOfTypeInSubtree(component.stack, componentType);
|
|
23
|
+
case "stack":
|
|
24
|
+
return hasComponentOfTypeInSubtree(component, componentType);
|
|
25
|
+
case "tabs":
|
|
26
|
+
return (hasComponentOfTypeInSubtree(component.control.stack, componentType) ||
|
|
27
|
+
component.tabs.some((tab) => hasComponentOfTypeInSubtree(tab.stack, componentType)));
|
|
28
|
+
default:
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import Stack from "../stack/Stack.svelte";
|
|
3
3
|
import { getPaywallContext } from "../../stores/paywall";
|
|
4
|
+
import { setPackageIdContext } from "../../stores/packageId";
|
|
4
5
|
import { setSelectedStateContext } from "../../stores/selected";
|
|
5
6
|
import {
|
|
6
7
|
getVariablesContext,
|
|
@@ -18,6 +19,8 @@
|
|
|
18
19
|
const { stack, package_id, is_selected_by_default, name }: PackageProps =
|
|
19
20
|
$props();
|
|
20
21
|
|
|
22
|
+
setPackageIdContext(package_id);
|
|
23
|
+
|
|
21
24
|
const {
|
|
22
25
|
defaultPackageId,
|
|
23
26
|
emitComponentInteraction,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import Stack from "../stack/Stack.svelte";
|
|
3
3
|
import { getLocalizationContext } from "../../stores/localization";
|
|
4
|
+
import { getOptionalPackageIdContext } from "../../stores/packageId";
|
|
4
5
|
import { getPaywallContext } from "../../stores/paywall";
|
|
5
6
|
import type { PurchaseButtonProps } from "../../types/components/purchase-button";
|
|
6
7
|
import type { PurchaseButtonInteractionData } from "../../types/paywall-component-interaction";
|
|
@@ -16,6 +17,9 @@
|
|
|
16
17
|
} = getPaywallContext();
|
|
17
18
|
const { getLocalizedString } = getLocalizationContext();
|
|
18
19
|
|
|
20
|
+
// Set when embedded in a package; standalone buttons fall back to the store.
|
|
21
|
+
const enclosingPackageId = getOptionalPackageIdContext();
|
|
22
|
+
|
|
19
23
|
const appendQueryParam = (url: string, key: string, value: string) => {
|
|
20
24
|
const hashIndex = url.indexOf("#");
|
|
21
25
|
const hash = hashIndex === -1 ? "" : url.slice(hashIndex);
|
|
@@ -64,8 +68,10 @@
|
|
|
64
68
|
};
|
|
65
69
|
|
|
66
70
|
const onclick = () => {
|
|
67
|
-
const packageId = $selectedPackageId;
|
|
71
|
+
const packageId = enclosingPackageId ?? $selectedPackageId;
|
|
68
72
|
if (packageId !== undefined) {
|
|
73
|
+
// Sync before purchasing so onPurchase reads this package, not a stale one.
|
|
74
|
+
$selectedPackageId = packageId;
|
|
69
75
|
emitComponentInteraction(getPurchaseButtonInteractionData(packageId));
|
|
70
76
|
}
|
|
71
77
|
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
style="position: relative; width: 100%; height: 100%; isolation: isolate;"
|
|
188
188
|
>
|
|
189
189
|
{#each components as component, index}
|
|
190
|
-
<div style={getLayerStyle(index)}>
|
|
190
|
+
<div class="rc-zlayer-layer" style={getLayerStyle(index)}>
|
|
191
191
|
<Node nodeData={component} />
|
|
192
192
|
</div>
|
|
193
193
|
{/each}
|
|
@@ -236,4 +236,18 @@
|
|
|
236
236
|
position: relative;
|
|
237
237
|
z-index: 3;
|
|
238
238
|
}
|
|
239
|
+
|
|
240
|
+
/*
|
|
241
|
+
* Each overlay layer is a full-size (inset:0) box, so by default it swallows
|
|
242
|
+
* clicks anywhere over the stack — including where it has no content —
|
|
243
|
+
* blocking interactive elements on the layers beneath. Only its own content
|
|
244
|
+
* should be hit-testable.
|
|
245
|
+
*/
|
|
246
|
+
.rc-zlayer-layer {
|
|
247
|
+
pointer-events: none;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.rc-zlayer-layer > :global(*) {
|
|
251
|
+
pointer-events: auto;
|
|
252
|
+
}
|
|
239
253
|
</style>
|