@revenuecat/purchases-ui-js 2.0.1 → 2.0.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.
- package/dist/components/button/ButtonNode.stories.svelte +0 -6
- package/dist/components/button/ButtonNode.svelte +3 -6
- package/dist/components/footer/Footer.stories.svelte +0 -4
- package/dist/components/footer/Footer.svelte +3 -3
- package/dist/components/image/Image.stories.svelte +2 -13
- package/dist/components/image/Image.svelte +1 -2
- package/dist/components/package/Package.stories.svelte +2 -6
- package/dist/components/package/Package.svelte +4 -11
- package/dist/components/paywall/Node.svelte +23 -20
- package/dist/components/paywall/Node.svelte.d.ts +9 -8
- package/dist/components/paywall/Paywall.svelte +16 -14
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +0 -8
- package/dist/components/purchase-button/PurchaseButton.svelte +3 -10
- package/dist/components/stack/Stack.stories.svelte +11 -43
- package/dist/components/stack/Stack.svelte +3 -23
- package/dist/components/stack/stack-utils.js +0 -2
- package/dist/components/text/TextNode.stories.svelte +0 -12
- package/dist/components/text/TextNode.svelte +2 -11
- package/dist/components/text/text-utils.d.ts +1 -1
- package/dist/components/timeline/Timeline.stories.svelte +0 -5
- package/dist/components/timeline/Timeline.svelte +0 -2
- package/dist/components/timeline/timeline-utils.js +0 -1
- package/dist/data/entities.d.ts +18 -48
- package/dist/index.d.ts +10 -10
- package/dist/index.js +10 -10
- package/dist/stores/localization.d.ts +1 -1
- package/dist/stores/localization.js +3 -2
- package/dist/stores/paywall.d.ts +5 -4
- package/dist/stores/variables.d.ts +1 -2
- package/dist/stories/fixtures.d.ts +1 -1
- package/dist/stories/fixtures.js +23 -59
- package/dist/stories/localization-decorator.js +1 -1
- package/dist/stories/paywall-decorator.js +2 -1
- package/dist/stories/with-layout.svelte +3 -3
- package/dist/types/component.d.ts +6 -0
- package/dist/types/components/button.d.ts +2 -2
- package/dist/types/components/footer.d.ts +2 -2
- package/dist/types/components/package.d.ts +2 -2
- package/dist/types/components/purchase-button.d.ts +2 -2
- package/dist/ui/atoms/typography.stories.svelte +2 -2
- package/dist/ui/atoms/typography.stories.svelte.d.ts +1 -1
- package/dist/ui/layout/main-block.svelte +2 -2
- package/dist/ui/molecules/button.stories.svelte +2 -2
- package/dist/ui/molecules/button.svelte +1 -1
- package/dist/ui/theme/theme.d.ts +2 -2
- package/dist/ui/theme/theme.js +2 -2
- package/dist/ui/theme/utils.d.ts +2 -2
- package/dist/utils/style-utils.js +13 -12
- package/dist/web-components/index.css +1 -1
- package/dist/web-components/index.js +144 -144
- package/package.json +1 -1
- package/dist/data/state.d.ts +0 -4
- /package/dist/{data/state.js → types/component.js} +0 -0
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import ButtonNode from "./ButtonNode.svelte";
|
|
3
3
|
import type { StackProps, TextNodeProps } from "../../data/entities";
|
|
4
|
-
import type { PurchaseState } from "../../data/state";
|
|
5
4
|
import { localizationDecorator } from "../../stories/localization-decorator";
|
|
6
5
|
import { DEFAULT_TEXT_COLOR } from "../../utils/constants";
|
|
7
6
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
8
7
|
|
|
9
8
|
const defaultLocale = "en_US";
|
|
10
9
|
|
|
11
|
-
const purchaseState: PurchaseState = {};
|
|
12
|
-
|
|
13
10
|
const { Story } = defineMeta({
|
|
14
11
|
title: "Components/Button",
|
|
15
12
|
component: ButtonNode,
|
|
@@ -27,7 +24,6 @@
|
|
|
27
24
|
},
|
|
28
25
|
}),
|
|
29
26
|
],
|
|
30
|
-
args: { purchaseState },
|
|
31
27
|
argTypes: {
|
|
32
28
|
action: {
|
|
33
29
|
control: { type: "object" },
|
|
@@ -63,7 +59,6 @@
|
|
|
63
59
|
({
|
|
64
60
|
type: "text",
|
|
65
61
|
name: "Button Text",
|
|
66
|
-
components: [],
|
|
67
62
|
id: "button-text-1",
|
|
68
63
|
text_lid: `id${id}`,
|
|
69
64
|
font_weight: "medium",
|
|
@@ -113,7 +108,6 @@
|
|
|
113
108
|
},
|
|
114
109
|
border: null,
|
|
115
110
|
shadow: null,
|
|
116
|
-
purchaseState,
|
|
117
111
|
} satisfies Partial<StackProps>;
|
|
118
112
|
</script>
|
|
119
113
|
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getButtonStyles } from "./button-utils";
|
|
3
3
|
import Stack from "../stack/Stack.svelte";
|
|
4
|
-
import type { ButtonProps } from "../../types/components/button";
|
|
5
4
|
import { ButtonDeprecated } from "../../index";
|
|
6
5
|
import { getPaywallContext } from "../../stores/paywall";
|
|
6
|
+
import type { ButtonProps } from "../../types/components/button";
|
|
7
7
|
|
|
8
|
-
const { stack, action,
|
|
9
|
-
$props();
|
|
8
|
+
const { stack, action, ...restProps }: ButtonProps = $props();
|
|
10
9
|
const { onButtonAction } = getPaywallContext();
|
|
11
10
|
|
|
12
11
|
const onclick = () => onButtonAction(action);
|
|
@@ -15,15 +14,13 @@
|
|
|
15
14
|
getButtonStyles({
|
|
16
15
|
stack,
|
|
17
16
|
action,
|
|
18
|
-
labels,
|
|
19
|
-
purchaseState,
|
|
20
17
|
...restProps,
|
|
21
18
|
}),
|
|
22
19
|
);
|
|
23
20
|
</script>
|
|
24
21
|
|
|
25
22
|
<ButtonDeprecated {onclick} style={buttonStyles} class={"rc-pw-button"}>
|
|
26
|
-
<Stack {...stack}
|
|
23
|
+
<Stack {...stack} />
|
|
27
24
|
</ButtonDeprecated>
|
|
28
25
|
|
|
29
26
|
<style>
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import Footer from "./Footer.svelte";
|
|
3
|
-
import type { PurchaseState } from "../../data/state";
|
|
4
3
|
import { localizationDecorator } from "../../stories/localization-decorator";
|
|
5
4
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
6
5
|
|
|
7
6
|
const defaultLocale = "en_US";
|
|
8
|
-
const purchaseState: PurchaseState = {};
|
|
9
7
|
|
|
10
8
|
const { Story } = defineMeta({
|
|
11
9
|
title: "Components/Footer",
|
|
12
10
|
component: Footer,
|
|
13
11
|
tags: ["autodocs"],
|
|
14
|
-
args: { purchaseState },
|
|
15
12
|
decorators: [
|
|
16
13
|
localizationDecorator({
|
|
17
14
|
defaultLocale,
|
|
@@ -32,7 +29,6 @@
|
|
|
32
29
|
id: "kHhCWlo9au",
|
|
33
30
|
name: "",
|
|
34
31
|
stack: {
|
|
35
|
-
purchaseState,
|
|
36
32
|
background_color: {
|
|
37
33
|
light: {
|
|
38
34
|
type: "hex",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { FooterProps } from "../../types/components/footer";
|
|
3
2
|
import Stack from "../stack/Stack.svelte";
|
|
3
|
+
import type { FooterProps } from "../../types/components/footer";
|
|
4
4
|
|
|
5
|
-
const { stack, id
|
|
5
|
+
const { stack, id }: FooterProps = $props();
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<div class="rc-pw-footer" {id}>
|
|
9
|
-
<Stack {...stack}
|
|
9
|
+
<Stack {...stack} />
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
12
|
<style>
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import Image from "./Image.svelte";
|
|
3
|
-
import type { PurchaseState } from "../../data/state";
|
|
4
3
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
5
4
|
|
|
6
|
-
const purchaseState: PurchaseState = {};
|
|
7
|
-
|
|
8
5
|
const { Story } = defineMeta({
|
|
9
6
|
title: "Components/Image",
|
|
10
7
|
component: Image,
|
|
11
8
|
tags: ["autodocs"],
|
|
12
9
|
argTypes: {
|
|
13
10
|
id: { control: "text", description: "Unique identifier for the image" },
|
|
14
|
-
|
|
11
|
+
color_overlay: {
|
|
15
12
|
control: "object",
|
|
16
|
-
description: "
|
|
13
|
+
description: "Image overlay",
|
|
17
14
|
},
|
|
18
15
|
size: {
|
|
19
16
|
control: "object",
|
|
@@ -40,7 +37,6 @@
|
|
|
40
37
|
<Story
|
|
41
38
|
name="Rectangle"
|
|
42
39
|
args={{
|
|
43
|
-
purchaseState,
|
|
44
40
|
id: "example-id",
|
|
45
41
|
fit_mode: "fit",
|
|
46
42
|
size: {
|
|
@@ -67,7 +63,6 @@
|
|
|
67
63
|
<Story
|
|
68
64
|
name="Rounded Rectangle"
|
|
69
65
|
args={{
|
|
70
|
-
purchaseState,
|
|
71
66
|
id: "example-id",
|
|
72
67
|
fit_mode: "fit",
|
|
73
68
|
size: {
|
|
@@ -101,7 +96,6 @@
|
|
|
101
96
|
<Story
|
|
102
97
|
name="Circle"
|
|
103
98
|
args={{
|
|
104
|
-
purchaseState,
|
|
105
99
|
id: "example-id",
|
|
106
100
|
fit_mode: "fit",
|
|
107
101
|
size: {
|
|
@@ -127,7 +121,6 @@
|
|
|
127
121
|
<Story
|
|
128
122
|
name="Concave"
|
|
129
123
|
args={{
|
|
130
|
-
purchaseState,
|
|
131
124
|
id: "example-id",
|
|
132
125
|
fit_mode: "fit",
|
|
133
126
|
size: {
|
|
@@ -153,7 +146,6 @@
|
|
|
153
146
|
<Story
|
|
154
147
|
name="Convex"
|
|
155
148
|
args={{
|
|
156
|
-
purchaseState,
|
|
157
149
|
id: "example-id",
|
|
158
150
|
fit_mode: "fit",
|
|
159
151
|
size: {
|
|
@@ -179,7 +171,6 @@
|
|
|
179
171
|
<Story
|
|
180
172
|
name="Overlay Radial Gradient"
|
|
181
173
|
args={{
|
|
182
|
-
purchaseState,
|
|
183
174
|
id: "example-id",
|
|
184
175
|
fit_mode: "fit",
|
|
185
176
|
size: {
|
|
@@ -223,7 +214,6 @@
|
|
|
223
214
|
<Story
|
|
224
215
|
name="Overlay Linear Gradient"
|
|
225
216
|
args={{
|
|
226
|
-
purchaseState,
|
|
227
217
|
id: "example-id",
|
|
228
218
|
fit_mode: "fit",
|
|
229
219
|
size: {
|
|
@@ -268,7 +258,6 @@
|
|
|
268
258
|
<Story
|
|
269
259
|
name="Overlay Solid"
|
|
270
260
|
args={{
|
|
271
|
-
purchaseState,
|
|
272
261
|
id: "example-id",
|
|
273
262
|
fit_mode: "fit",
|
|
274
263
|
size: {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { getColorModeContext } from "../../stores/color-mode";
|
|
5
5
|
import { DEFAULT_COLOR_MODE } from "../../utils/constants";
|
|
6
6
|
|
|
7
|
-
const { id, source,
|
|
7
|
+
const { id, source, ...restProps }: ImageProps = $props();
|
|
8
8
|
|
|
9
9
|
const getColorMode = getColorModeContext();
|
|
10
10
|
const colorMode = $derived(getColorMode());
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
getImageComponentStyles(colorMode, {
|
|
24
24
|
id,
|
|
25
25
|
source,
|
|
26
|
-
purchaseState,
|
|
27
26
|
...restProps,
|
|
28
27
|
imageAspectRatio,
|
|
29
28
|
}),
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import Package from "./Package.svelte";
|
|
3
|
-
import type { PurchaseState } from "../../data/state";
|
|
4
3
|
import { localizationDecorator } from "../../stories/localization-decorator";
|
|
5
4
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
6
5
|
|
|
7
6
|
const defaultLocale = "en_US";
|
|
8
7
|
const priceLid = "QZ4ZmYsqjN";
|
|
9
8
|
const nameLid = "BcX-6YwhoV";
|
|
10
|
-
const purchaseState: PurchaseState = {};
|
|
11
9
|
|
|
12
10
|
const { Story } = defineMeta({
|
|
13
11
|
title: "Components/Package",
|
|
@@ -24,7 +22,6 @@
|
|
|
24
22
|
},
|
|
25
23
|
}),
|
|
26
24
|
],
|
|
27
|
-
args: { purchaseState },
|
|
28
25
|
argTypes: {
|
|
29
26
|
stack: {
|
|
30
27
|
control: { type: "object" },
|
|
@@ -49,7 +46,6 @@
|
|
|
49
46
|
name: "Package - Monthly",
|
|
50
47
|
package_id: "$rc_monthly",
|
|
51
48
|
stack: {
|
|
52
|
-
purchaseState,
|
|
53
49
|
background_color: {
|
|
54
50
|
light: {
|
|
55
51
|
type: "hex",
|
|
@@ -83,7 +79,6 @@
|
|
|
83
79
|
value: "#ffffff",
|
|
84
80
|
},
|
|
85
81
|
},
|
|
86
|
-
components: [],
|
|
87
82
|
font_name: null,
|
|
88
83
|
font_size: "heading_s",
|
|
89
84
|
font_weight: "bold",
|
|
@@ -122,6 +117,8 @@
|
|
|
122
117
|
value: "#292631",
|
|
123
118
|
},
|
|
124
119
|
},
|
|
120
|
+
background: null,
|
|
121
|
+
shadow: null,
|
|
125
122
|
border: null,
|
|
126
123
|
components: [
|
|
127
124
|
{
|
|
@@ -132,7 +129,6 @@
|
|
|
132
129
|
value: "#ffffff",
|
|
133
130
|
},
|
|
134
131
|
},
|
|
135
|
-
components: [],
|
|
136
132
|
font_name: null,
|
|
137
133
|
font_size: "body_m",
|
|
138
134
|
font_weight: "extra_bold",
|
|
@@ -9,23 +9,16 @@
|
|
|
9
9
|
import { prefixObject, stringifyStyles } from "../../utils/style-utils";
|
|
10
10
|
import { derived } from "svelte/store";
|
|
11
11
|
|
|
12
|
-
const {
|
|
13
|
-
stack,
|
|
14
|
-
package_id,
|
|
15
|
-
labels,
|
|
16
|
-
id,
|
|
17
|
-
purchaseState,
|
|
18
|
-
zStackChildStyles,
|
|
19
|
-
}: PackageProps = $props();
|
|
12
|
+
const { stack, package_id, id, zStackChildStyles }: PackageProps = $props();
|
|
20
13
|
|
|
21
|
-
const { selectedPackageId } = getPaywallContext();
|
|
14
|
+
const { selectedPackageId, variablesPerPackage } = getPaywallContext();
|
|
22
15
|
|
|
23
16
|
const onPackageClick = () => ($selectedPackageId = package_id);
|
|
24
17
|
|
|
25
18
|
const fallbackVariables = getVariablesContext();
|
|
26
19
|
const variables = derived(
|
|
27
20
|
fallbackVariables,
|
|
28
|
-
(fallback) =>
|
|
21
|
+
(fallback) => $variablesPerPackage?.[package_id] ?? fallback,
|
|
29
22
|
);
|
|
30
23
|
setVariablesContext(variables);
|
|
31
24
|
|
|
@@ -45,7 +38,7 @@
|
|
|
45
38
|
onclick={onPackageClick}
|
|
46
39
|
style={styles}
|
|
47
40
|
>
|
|
48
|
-
<Stack {...stack} {
|
|
41
|
+
<Stack {...stack} {componentState} />
|
|
49
42
|
</button>
|
|
50
43
|
|
|
51
44
|
<style>
|
|
@@ -10,12 +10,9 @@
|
|
|
10
10
|
import ButtonNode from "../button/ButtonNode.svelte";
|
|
11
11
|
import type { ZStackChildStyles } from "../stack/stack-utils";
|
|
12
12
|
import TextNode from "../text/TextNode.svelte";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type PurchaseStateProps,
|
|
17
|
-
} from "../../data/entities";
|
|
18
|
-
import type { Component } from "svelte";
|
|
13
|
+
import type { ComponentState } from "../../data/entities";
|
|
14
|
+
import type { Component } from "../../types/component";
|
|
15
|
+
import type { Component as SvelteComponent } from "svelte";
|
|
19
16
|
import Self from "./Node.svelte";
|
|
20
17
|
|
|
21
18
|
type SupportedComponents =
|
|
@@ -28,8 +25,8 @@
|
|
|
28
25
|
| Footer
|
|
29
26
|
| Timeline;
|
|
30
27
|
|
|
31
|
-
interface Props
|
|
32
|
-
nodeData:
|
|
28
|
+
interface Props {
|
|
29
|
+
nodeData: Component;
|
|
33
30
|
zStackChildStyles?: ZStackChildStyles;
|
|
34
31
|
componentState?: ComponentState;
|
|
35
32
|
}
|
|
@@ -43,6 +40,10 @@
|
|
|
43
40
|
package: Package,
|
|
44
41
|
footer: Footer,
|
|
45
42
|
timeline: Timeline,
|
|
43
|
+
} satisfies {
|
|
44
|
+
[key in Component["type"]]: SvelteComponent<
|
|
45
|
+
Extract<Component, { type: key }>
|
|
46
|
+
>;
|
|
46
47
|
};
|
|
47
48
|
|
|
48
49
|
/**
|
|
@@ -50,18 +51,18 @@
|
|
|
50
51
|
* It first checks if the component type is supported and returns the corresponding component class.
|
|
51
52
|
* If not supported, it checks if the fallback component type is supported and returns the corresponding component class,
|
|
52
53
|
* finally it throws an error if the component type is not supported and the fallback component type is not supported.
|
|
53
|
-
* @param nodeData:
|
|
54
|
-
* @returns [Component<SupportedComponents>,
|
|
54
|
+
* @param nodeData:Component - the Component object representing a Node in the paywall
|
|
55
|
+
* @returns [Component<SupportedComponents>, Component] - a tuple containing the component class and the node data
|
|
55
56
|
* @throws Error - if the component type and the fallback component type are not supported
|
|
56
57
|
*/
|
|
57
58
|
export const getComponentClass: (
|
|
58
|
-
nodeData:
|
|
59
|
-
) => [
|
|
60
|
-
nodeData:
|
|
59
|
+
nodeData: Component,
|
|
60
|
+
) => [SvelteComponent<SupportedComponents>, Component] = (
|
|
61
|
+
nodeData: Component,
|
|
61
62
|
) => {
|
|
62
63
|
if (ComponentTypes[nodeData.type]) {
|
|
63
64
|
return [
|
|
64
|
-
ComponentTypes[nodeData.type] as
|
|
65
|
+
ComponentTypes[nodeData.type] as SvelteComponent<SupportedComponents>,
|
|
65
66
|
nodeData,
|
|
66
67
|
];
|
|
67
68
|
}
|
|
@@ -69,7 +70,7 @@
|
|
|
69
70
|
const { fallback } = nodeData;
|
|
70
71
|
if (fallback && ComponentTypes[fallback?.type]) {
|
|
71
72
|
return [
|
|
72
|
-
ComponentTypes[fallback.type] as
|
|
73
|
+
ComponentTypes[fallback.type] as SvelteComponent<SupportedComponents>,
|
|
73
74
|
fallback,
|
|
74
75
|
];
|
|
75
76
|
}
|
|
@@ -79,19 +80,21 @@
|
|
|
79
80
|
throw new Error(`Invalid component type: ${nodeData.type}`);
|
|
80
81
|
};
|
|
81
82
|
|
|
82
|
-
const { nodeData,
|
|
83
|
-
$props();
|
|
83
|
+
const { nodeData, zStackChildStyles, ...restProps }: Props = $props();
|
|
84
84
|
|
|
85
85
|
const [ComponentToRender, dataToUse] = $derived(getComponentClass(nodeData));
|
|
86
|
+
|
|
87
|
+
const components = $derived(
|
|
88
|
+
("components" in nodeData ? nodeData.components : undefined) ?? [],
|
|
89
|
+
);
|
|
86
90
|
</script>
|
|
87
91
|
|
|
88
92
|
<ComponentToRender
|
|
89
93
|
{...(dataToUse as any) || {}}
|
|
90
|
-
{purchaseState}
|
|
91
94
|
{zStackChildStyles}
|
|
92
95
|
{...restProps}
|
|
93
96
|
>
|
|
94
|
-
{#each
|
|
95
|
-
<Self nodeData={childData} {
|
|
97
|
+
{#each components as childData}
|
|
98
|
+
<Self nodeData={childData} {...restProps} />
|
|
96
99
|
{/each}
|
|
97
100
|
</ComponentToRender>
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
1
2
|
import { Footer, Image, Package, PurchaseButton, Stack, Timeline } from "../..";
|
|
2
3
|
import ButtonNode from "../button/ButtonNode.svelte";
|
|
3
4
|
import type { ZStackChildStyles } from "../stack/stack-utils";
|
|
4
5
|
import TextNode from "../text/TextNode.svelte";
|
|
5
|
-
import {
|
|
6
|
-
import type { Component } from "
|
|
6
|
+
import type { ComponentState } from "../../data/entities";
|
|
7
|
+
import type { Component } from "../../types/component";
|
|
7
8
|
type SupportedComponents = TextNode | Stack | Image | ButtonNode | PurchaseButton | Package | Footer | Timeline;
|
|
8
|
-
interface Props
|
|
9
|
-
nodeData:
|
|
9
|
+
interface Props {
|
|
10
|
+
nodeData: Component;
|
|
10
11
|
zStackChildStyles?: ZStackChildStyles;
|
|
11
12
|
componentState?: ComponentState;
|
|
12
13
|
}
|
|
13
|
-
declare const Node: Component<Props, {
|
|
14
|
+
declare const Node: import("svelte").Component<Props, {
|
|
14
15
|
/**
|
|
15
16
|
* This function returns the component class and the node data for a given paywall component.
|
|
16
17
|
* It first checks if the component type is supported and returns the corresponding component class.
|
|
17
18
|
* If not supported, it checks if the fallback component type is supported and returns the corresponding component class,
|
|
18
19
|
* finally it throws an error if the component type is not supported and the fallback component type is not supported.
|
|
19
|
-
* @param nodeData:
|
|
20
|
-
* @returns [Component<SupportedComponents>,
|
|
20
|
+
* @param nodeData:Component - the Component object representing a Node in the paywall
|
|
21
|
+
* @returns [Component<SupportedComponents>, Component] - a tuple containing the component class and the node data
|
|
21
22
|
* @throws Error - if the component type and the fallback component type are not supported
|
|
22
|
-
*/ getComponentClass: (nodeData:
|
|
23
|
+
*/ getComponentClass: (nodeData: Component) => [SvelteComponent<SupportedComponents>, Component];
|
|
23
24
|
}, "">;
|
|
24
25
|
type Node = ReturnType<typeof Node>;
|
|
25
26
|
export default Node;
|
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
getBackgroundImageSource,
|
|
8
8
|
getBackgroundStyles,
|
|
9
9
|
} from "./paywall-utils";
|
|
10
|
-
import type { PurchaseState } from "../../data/state";
|
|
11
10
|
import { setColorModeContext } from "../../stores/color-mode";
|
|
12
11
|
import { setLocalizationContext } from "../../stores/localization";
|
|
13
12
|
import { setPaywallContext } from "../../stores/paywall";
|
|
14
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
setVariablesContext,
|
|
15
|
+
type VariablesStore,
|
|
16
|
+
} from "../../stores/variables";
|
|
15
17
|
import type { ColorMode } from "../../types";
|
|
16
18
|
import type { Action } from "../../types/components/button";
|
|
17
19
|
import { findSelectedPackageId } from "../../utils/style-utils";
|
|
18
20
|
import { type VariableDictionary } from "../../utils/variable-utils";
|
|
19
|
-
import { derived, writable } from "svelte/store";
|
|
21
|
+
import { derived, readable, writable } from "svelte/store";
|
|
20
22
|
|
|
21
23
|
interface Props {
|
|
22
24
|
paywallData: PaywallData;
|
|
@@ -47,15 +49,11 @@
|
|
|
47
49
|
const getColorMode = setColorModeContext(() => preferredColorMode);
|
|
48
50
|
const colorMode = $derived(getColorMode());
|
|
49
51
|
|
|
50
|
-
const { getLocalizedString } = setLocalizationContext({
|
|
52
|
+
const { getLocalizedString } = setLocalizationContext(() => ({
|
|
51
53
|
defaultLocale: paywallData.default_locale,
|
|
52
54
|
selectedLocale,
|
|
53
55
|
localizations: paywallData.components_localizations!,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
let purchaseState = $state({
|
|
57
|
-
variablesPerPackage,
|
|
58
|
-
} satisfies PurchaseState);
|
|
56
|
+
}));
|
|
59
57
|
|
|
60
58
|
const selectedPackageId = writable<string | undefined>(
|
|
61
59
|
findSelectedPackageId(paywallData),
|
|
@@ -98,11 +96,16 @@
|
|
|
98
96
|
}
|
|
99
97
|
};
|
|
100
98
|
|
|
101
|
-
setPaywallContext({
|
|
99
|
+
setPaywallContext({
|
|
100
|
+
selectedPackageId,
|
|
101
|
+
variablesPerPackage: readable(variablesPerPackage),
|
|
102
|
+
onPurchase,
|
|
103
|
+
onButtonAction,
|
|
104
|
+
});
|
|
102
105
|
|
|
103
|
-
const variables = derived(
|
|
106
|
+
const variables: VariablesStore = derived(
|
|
104
107
|
selectedPackageId,
|
|
105
|
-
(packageId) => variablesPerPackage[packageId || ""]
|
|
108
|
+
(packageId) => variablesPerPackage[packageId || ""],
|
|
106
109
|
);
|
|
107
110
|
|
|
108
111
|
setVariablesContext(variables);
|
|
@@ -120,14 +123,13 @@
|
|
|
120
123
|
|
|
121
124
|
<svelte:boundary onerror={onError}>
|
|
122
125
|
<div class="rc-pw-paywall">
|
|
123
|
-
<Node nodeData={paywallData.components_config.base.stack}
|
|
126
|
+
<Node nodeData={paywallData.components_config.base.stack} />
|
|
124
127
|
|
|
125
128
|
{#if paywallData.components_config.base.sticky_footer}
|
|
126
129
|
<Footer
|
|
127
130
|
{...paywallData.components_config.base.sticky_footer}
|
|
128
131
|
stack={paywallData.components_config.base.sticky_footer
|
|
129
132
|
.stack as StackProps}
|
|
130
|
-
{purchaseState}
|
|
131
133
|
/>
|
|
132
134
|
{/if}
|
|
133
135
|
{#if paywallData.components_config.base.background?.type === "color"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import PurchaseButton from "./PurchaseButton.svelte";
|
|
3
|
-
import type { PurchaseState } from "../../data/state";
|
|
4
3
|
import { localizationDecorator } from "../../stories/localization-decorator";
|
|
5
4
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
6
5
|
|
|
7
6
|
const defaultLocale = "en_US";
|
|
8
7
|
const text_lid = "6gpcQ4q6T8";
|
|
9
8
|
|
|
10
|
-
const purchaseState: PurchaseState = {};
|
|
11
|
-
|
|
12
9
|
const { Story } = defineMeta({
|
|
13
10
|
title: "Components/PurchaseButton",
|
|
14
11
|
component: PurchaseButton,
|
|
@@ -23,7 +20,6 @@
|
|
|
23
20
|
},
|
|
24
21
|
}),
|
|
25
22
|
],
|
|
26
|
-
args: { purchaseState },
|
|
27
23
|
argTypes: {
|
|
28
24
|
stack: {
|
|
29
25
|
control: { type: "object" },
|
|
@@ -45,9 +41,7 @@
|
|
|
45
41
|
args={{
|
|
46
42
|
id: "mjaE9fOv5z",
|
|
47
43
|
name: "Purchase_button",
|
|
48
|
-
purchaseState,
|
|
49
44
|
stack: {
|
|
50
|
-
purchaseState,
|
|
51
45
|
background_color: {
|
|
52
46
|
light: {
|
|
53
47
|
type: "hex",
|
|
@@ -65,7 +59,6 @@
|
|
|
65
59
|
},
|
|
66
60
|
components: [
|
|
67
61
|
{
|
|
68
|
-
purchaseState,
|
|
69
62
|
background_color: null,
|
|
70
63
|
color: {
|
|
71
64
|
light: {
|
|
@@ -73,7 +66,6 @@
|
|
|
73
66
|
value: "#ffffff",
|
|
74
67
|
},
|
|
75
68
|
},
|
|
76
|
-
components: [],
|
|
77
69
|
font_name: null,
|
|
78
70
|
font_size: "heading_m",
|
|
79
71
|
font_weight: "extra_bold",
|
|
@@ -5,21 +5,14 @@
|
|
|
5
5
|
import { getPaywallContext } from "../../stores/paywall";
|
|
6
6
|
import type { PurchaseButtonProps } from "../../types/components/purchase-button";
|
|
7
7
|
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
labels,
|
|
11
|
-
purchaseState,
|
|
12
|
-
zStackChildStyles,
|
|
13
|
-
...restProps
|
|
14
|
-
}: PurchaseButtonProps = $props();
|
|
8
|
+
const { stack, zStackChildStyles, ...restProps }: PurchaseButtonProps =
|
|
9
|
+
$props();
|
|
15
10
|
|
|
16
11
|
const { onPurchase } = getPaywallContext();
|
|
17
12
|
|
|
18
13
|
const buttonStyles = $derived(
|
|
19
14
|
getPurchaseButtonStyles({
|
|
20
15
|
stack,
|
|
21
|
-
labels,
|
|
22
|
-
purchaseState,
|
|
23
16
|
zStackChildStyles,
|
|
24
17
|
...restProps,
|
|
25
18
|
}),
|
|
@@ -31,7 +24,7 @@
|
|
|
31
24
|
class="rc-pw-purchase-button"
|
|
32
25
|
style={buttonStyles}
|
|
33
26
|
>
|
|
34
|
-
<Stack {...stack}
|
|
27
|
+
<Stack {...stack} />
|
|
35
28
|
</ButtonDeprecated>
|
|
36
29
|
|
|
37
30
|
<style>
|