@revenuecat/purchases-ui-js 4.8.3 → 4.8.4
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/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
|
+
};
|