@revenuecat/purchases-ui-js 2.0.0 → 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.
Files changed (105) hide show
  1. package/dist/components/button/Button.svelte +1 -5
  2. package/dist/components/button/ButtonNode.stories.svelte +57 -71
  3. package/dist/components/button/ButtonNode.stories.svelte.d.ts +0 -8
  4. package/dist/components/button/ButtonNode.svelte +10 -21
  5. package/dist/components/button/ButtonNode.svelte.d.ts +2 -2
  6. package/dist/components/button/button-utils.d.ts +2 -2
  7. package/dist/components/footer/Footer.stories.svelte +26 -22
  8. package/dist/components/footer/Footer.stories.svelte.d.ts +0 -5
  9. package/dist/components/footer/Footer.svelte +3 -10
  10. package/dist/components/footer/Footer.svelte.d.ts +1 -1
  11. package/dist/components/image/Image.stories.svelte +27 -19
  12. package/dist/components/image/Image.svelte +18 -17
  13. package/dist/components/image/image-utils.d.ts +2 -1
  14. package/dist/components/image/image-utils.js +2 -2
  15. package/dist/components/package/Package.stories.svelte +31 -31
  16. package/dist/components/package/Package.stories.svelte.d.ts +0 -6
  17. package/dist/components/package/Package.svelte +19 -30
  18. package/dist/components/package/Package.svelte.d.ts +1 -1
  19. package/dist/components/paywall/Node.svelte +26 -50
  20. package/dist/components/paywall/Node.svelte.d.ts +11 -14
  21. package/dist/components/paywall/Paywall.stories.svelte +21 -78
  22. package/dist/components/paywall/Paywall.svelte +75 -100
  23. package/dist/components/paywall/Paywall.svelte.d.ts +4 -4
  24. package/dist/components/paywall/paywall-utils.d.ts +3 -2
  25. package/dist/components/paywall/paywall-utils.js +5 -5
  26. package/dist/components/purchase-button/PurchaseButton.stories.svelte +29 -31
  27. package/dist/components/purchase-button/PurchaseButton.stories.svelte.d.ts +0 -5
  28. package/dist/components/purchase-button/PurchaseButton.svelte +9 -20
  29. package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -1
  30. package/dist/components/purchase-button/purchase-button-utils.d.ts +1 -1
  31. package/dist/components/stack/Stack.stories.svelte +17 -94
  32. package/dist/components/stack/Stack.svelte +18 -48
  33. package/dist/components/stack/stack-utils.d.ts +4 -3
  34. package/dist/components/stack/stack-utils.js +7 -10
  35. package/dist/components/text/TextNode.stories.svelte +45 -152
  36. package/dist/components/text/TextNode.svelte +15 -23
  37. package/dist/components/text/text-utils.d.ts +7 -6
  38. package/dist/components/text/text-utils.js +7 -7
  39. package/dist/components/timeline/Timeline.stories.svelte +37 -48
  40. package/dist/components/timeline/Timeline.svelte +0 -2
  41. package/dist/components/timeline/TimelineItem.svelte +28 -11
  42. package/dist/components/timeline/timeline-utils.d.ts +3 -3
  43. package/dist/components/timeline/timeline-utils.js +7 -17
  44. package/dist/data/entities.d.ts +54 -145
  45. package/dist/index.d.ts +10 -10
  46. package/dist/index.js +10 -10
  47. package/dist/stores/color-mode.d.ts +6 -0
  48. package/dist/stores/color-mode.js +15 -0
  49. package/dist/stores/localization.d.ts +13 -0
  50. package/dist/stores/localization.js +26 -0
  51. package/dist/stores/paywall.d.ts +11 -0
  52. package/dist/stores/paywall.js +13 -0
  53. package/dist/stores/variables.d.ts +5 -0
  54. package/dist/stores/variables.js +14 -0
  55. package/dist/stories/fixtures.d.ts +1 -1
  56. package/dist/stories/fixtures.js +30 -135
  57. package/dist/stories/localization-decorator.d.ts +3 -0
  58. package/dist/stories/localization-decorator.js +7 -0
  59. package/dist/stories/paywall-decorator.d.ts +2 -0
  60. package/dist/stories/paywall-decorator.js +19 -0
  61. package/dist/stories/variables-decorator.d.ts +3 -0
  62. package/dist/stories/variables-decorator.js +9 -0
  63. package/dist/stories/with-layout.svelte +4 -4
  64. package/dist/types/alignment.d.ts +19 -0
  65. package/dist/types/background.d.ts +18 -0
  66. package/dist/types/background.js +1 -0
  67. package/dist/types/colors.d.ts +34 -0
  68. package/dist/types/colors.js +1 -0
  69. package/dist/types/component.d.ts +6 -0
  70. package/dist/types/component.js +1 -0
  71. package/dist/types/components/button.d.ts +36 -0
  72. package/dist/types/components/button.js +1 -0
  73. package/dist/types/components/footer.d.ts +5 -0
  74. package/dist/types/components/footer.js +1 -0
  75. package/dist/types/components/package.d.ts +8 -0
  76. package/dist/types/components/package.js +1 -0
  77. package/dist/types/components/purchase-button.d.ts +5 -0
  78. package/dist/types/components/purchase-button.js +1 -0
  79. package/dist/types/localization.d.ts +4 -0
  80. package/dist/types/localization.js +1 -0
  81. package/dist/types/media.d.ts +18 -0
  82. package/dist/types/media.js +1 -0
  83. package/dist/types.d.ts +5 -35
  84. package/dist/ui/atoms/typography.stories.svelte +7 -13
  85. package/dist/ui/atoms/typography.stories.svelte.d.ts +1 -1
  86. package/dist/ui/atoms/typography.svelte +1 -1
  87. package/dist/ui/layout/main-block.svelte +2 -2
  88. package/dist/ui/molecules/button.stories.svelte +8 -15
  89. package/dist/ui/molecules/button.svelte +3 -2
  90. package/dist/ui/molecules/button.svelte.d.ts +2 -26
  91. package/dist/ui/molecules/types.d.ts +2 -1
  92. package/dist/ui/theme/theme.d.ts +2 -2
  93. package/dist/ui/theme/theme.js +2 -2
  94. package/dist/ui/theme/utils.d.ts +2 -2
  95. package/dist/utils/style-utils.d.ts +13 -11
  96. package/dist/utils/style-utils.js +21 -27
  97. package/dist/utils/variable-utils.d.ts +1 -38
  98. package/dist/utils/variable-utils.js +6 -48
  99. package/dist/web-components/index.css +1 -1
  100. package/dist/web-components/index.js +610 -657
  101. package/package.json +33 -36
  102. package/dist/data/state.d.ts +0 -9
  103. package/dist/stores/theme.d.ts +0 -1
  104. package/dist/stores/theme.js +0 -17
  105. /package/dist/{data/state.js → types/alignment.js} +0 -0
@@ -1,9 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { getImageComponentStyles } from "./image-utils";
3
3
  import type { ImageProps } from "../../data/entities";
4
+ import { getColorModeContext } from "../../stores/color-mode";
4
5
  import { DEFAULT_COLOR_MODE } from "../../utils/constants";
5
6
 
6
- const { id, source, purchaseState, ...restProps }: ImageProps = $props();
7
+ const { id, source, ...restProps }: ImageProps = $props();
8
+
9
+ const getColorMode = getColorModeContext();
10
+ const colorMode = $derived(getColorMode());
7
11
 
8
12
  let imageAspectRatio = $state(0);
9
13
  let imageElement: HTMLImageElement | null;
@@ -14,25 +18,28 @@
14
18
  imageAspectRatio = imageElement.naturalHeight / imageElement.naturalWidth;
15
19
  }
16
20
  }
21
+
17
22
  const { imageStyles, maskPath, linearGradientAngle } = $derived(
18
- getImageComponentStyles({
23
+ getImageComponentStyles(colorMode, {
19
24
  id,
20
- colorMode: purchaseState.colorMode,
21
25
  source,
22
- purchaseState,
23
26
  ...restProps,
24
27
  imageAspectRatio,
25
28
  }),
26
29
  );
27
30
 
28
31
  const imageSource = $derived.by(() => {
29
- const colorMode = purchaseState.colorMode;
30
32
  if (source[colorMode]?.original) {
31
33
  return source[colorMode].original;
32
34
  } else {
33
35
  return source[DEFAULT_COLOR_MODE]?.original as string;
34
36
  }
35
37
  });
38
+
39
+ const colorOverlay = $derived(restProps.color_overlay);
40
+ const colorInfo = $derived(
41
+ colorOverlay?.[colorMode] ?? colorOverlay?.[DEFAULT_COLOR_MODE],
42
+ );
36
43
  </script>
37
44
 
38
45
  <img
@@ -64,7 +71,7 @@
64
71
  {/if}
65
72
  </clipPath>
66
73
 
67
- {#if restProps.color_overlay?.[purchaseState.colorMode]?.type === "linear"}
74
+ {#if colorInfo?.type === "linear"}
68
75
  <linearGradient
69
76
  id={`gradient-${id}`}
70
77
  x1={linearGradientAngle.x1}
@@ -72,14 +79,14 @@
72
79
  x2={linearGradientAngle.x2}
73
80
  y2={linearGradientAngle.y2}
74
81
  >
75
- {#each restProps.color_overlay?.[purchaseState.colorMode]?.points || restProps.color_overlay?.[DEFAULT_COLOR_MODE]?.points || [] as stop}
82
+ {#each colorInfo?.points || [] as stop}
76
83
  <stop
77
84
  offset={`${stop.percent}%`}
78
85
  style={`stop-color: ${stop.color}`}
79
86
  />
80
87
  {/each}
81
88
  </linearGradient>
82
- {:else if restProps.color_overlay?.[purchaseState.colorMode]?.type === "radial"}
89
+ {:else if colorInfo?.type === "radial"}
83
90
  <radialGradient
84
91
  id={`gradient-${id}`}
85
92
  cx="50%"
@@ -88,22 +95,16 @@
88
95
  fx="50%"
89
96
  fy="50%"
90
97
  >
91
- {#each restProps.color_overlay?.[purchaseState.colorMode]?.points || restProps.color_overlay?.[DEFAULT_COLOR_MODE]?.points || [] as stop}
98
+ {#each colorInfo?.points || [] as stop}
92
99
  <stop
93
100
  offset={`${stop.percent}%`}
94
101
  style={`stop-color: ${stop.color}`}
95
102
  />
96
103
  {/each}
97
104
  </radialGradient>
98
- {:else if restProps.color_overlay?.[purchaseState.colorMode]?.type === "hex"}
105
+ {:else if colorInfo?.type === "hex"}
99
106
  <linearGradient id={`gradient-${id}`}>
100
- <stop
101
- offset="0%"
102
- style={`stop-color: ${
103
- restProps.color_overlay[purchaseState.colorMode]?.value ||
104
- restProps.color_overlay?.[DEFAULT_COLOR_MODE]?.value
105
- }`}
106
- />
107
+ <stop offset="0%" style={`stop-color: ${colorInfo?.value}`} />
107
108
  </linearGradient>
108
109
  {/if}
109
110
  </defs>
@@ -1,10 +1,11 @@
1
1
  import type { ImageProps } from "../../data/entities";
2
+ import type { ColorMode } from "../../types";
2
3
  /**
3
4
  * Generates comprehensive styles for image components by combining gradient and size styles
4
5
  * @param props - Image component properties including gradient, mask and size
5
6
  * @returns Object containing image style variables and gradient style variables
6
7
  */
7
- export declare const getImageComponentStyles: (props: ImageProps & {
8
+ export declare const getImageComponentStyles: (colorMode: ColorMode, props: ImageProps & {
8
9
  imageAspectRatio: number;
9
10
  }) => {
10
11
  imageStyles: string;
@@ -4,7 +4,7 @@ import { getActiveStateProps, getLinearGradientAngle, getMaskPath, getMaskStyle,
4
4
  * @param props - Image component properties including gradient, mask and size
5
5
  * @returns Object containing image style variables and gradient style variables
6
6
  */
7
- export const getImageComponentStyles = (props) => {
7
+ export const getImageComponentStyles = (colorMode, props) => {
8
8
  const { size, overrides, componentState, zStackChildStyles } = props;
9
9
  const imageStyles = {
10
10
  "--height": "unset",
@@ -24,7 +24,7 @@ export const getImageComponentStyles = (props) => {
24
24
  Object.assign(imageStyles, getMaskStyle(props.mask_shape));
25
25
  const prefixedImageStyles = prefixObject(imageStyles, "image");
26
26
  const maskPath = getMaskPath(props);
27
- const linearGradientAngle = getLinearGradientAngle(props);
27
+ const linearGradientAngle = getLinearGradientAngle(colorMode, props);
28
28
  return {
29
29
  imageStyles: stringifyStyles(prefixedImageStyles),
30
30
  maskPath,
@@ -1,18 +1,27 @@
1
1
  <script module lang="ts">
2
- import { defineMeta } from "@storybook/addon-svelte-csf";
3
2
  import Package from "./Package.svelte";
4
- import type { Extra, SupportedActions } from "../../data/entities";
5
- import type { PurchaseState } from "../../data/state";
6
- import { DEFAULT_COLOR_MODE } from "../../utils/constants";
3
+ import { localizationDecorator } from "../../stories/localization-decorator";
4
+ import { defineMeta } from "@storybook/addon-svelte-csf";
7
5
 
8
- const onAction = (action: SupportedActions, data?: Extra) => {
9
- alert(`${action.type} ${JSON.stringify(data)}`);
10
- };
6
+ const defaultLocale = "en_US";
7
+ const priceLid = "QZ4ZmYsqjN";
8
+ const nameLid = "BcX-6YwhoV";
11
9
 
12
10
  const { Story } = defineMeta({
13
11
  title: "Components/Package",
14
12
  component: Package,
15
13
  tags: ["autodocs"],
14
+ decorators: [
15
+ localizationDecorator({
16
+ defaultLocale,
17
+ localizations: {
18
+ [defaultLocale]: {
19
+ [nameLid]: "Monthly",
20
+ [priceLid]: "$1.99",
21
+ },
22
+ },
23
+ }),
24
+ ],
16
25
  argTypes: {
17
26
  stack: {
18
27
  control: { type: "object" },
@@ -26,18 +35,6 @@
26
35
  },
27
36
  },
28
37
  });
29
-
30
- export const labelsData = {
31
- en_US: {
32
- "BcX-6YwhoV": "Monthly",
33
- QZ4ZmYsqjN: "$1.99",
34
- },
35
- };
36
- const purchaseState: PurchaseState = {
37
- colorMode: DEFAULT_COLOR_MODE,
38
- locale: "en_US",
39
- defaultLocale: "en_US",
40
- };
41
38
  </script>
42
39
 
43
40
  <!-- Default -->
@@ -47,17 +44,23 @@
47
44
  id: "6rQSD5e2Kz",
48
45
  is_selected_by_default: false,
49
46
  name: "Package - Monthly",
50
- package_id: "$rc_annual",
51
- purchaseState,
47
+ package_id: "$rc_monthly",
52
48
  stack: {
53
- purchaseState,
54
49
  background_color: {
55
50
  light: {
56
51
  type: "hex",
57
52
  value: "#09090b",
58
53
  },
59
54
  },
60
- labels: labelsData,
55
+ background: {
56
+ type: "color",
57
+ value: {
58
+ light: {
59
+ type: "hex",
60
+ value: "#09090b",
61
+ },
62
+ },
63
+ },
61
64
  border: {
62
65
  color: {
63
66
  light: {
@@ -76,8 +79,6 @@
76
79
  value: "#ffffff",
77
80
  },
78
81
  },
79
- labels: labelsData,
80
- components: [],
81
82
  font_name: null,
82
83
  font_size: "heading_s",
83
84
  font_weight: "bold",
@@ -106,7 +107,7 @@
106
107
  value: null,
107
108
  },
108
109
  },
109
- text_lid: "BcX-6YwhoV",
110
+ text_lid: nameLid,
110
111
  type: "text",
111
112
  },
112
113
  {
@@ -116,7 +117,8 @@
116
117
  value: "#292631",
117
118
  },
118
119
  },
119
- labels: labelsData,
120
+ background: null,
121
+ shadow: null,
120
122
  border: null,
121
123
  components: [
122
124
  {
@@ -127,7 +129,6 @@
127
129
  value: "#ffffff",
128
130
  },
129
131
  },
130
- components: [],
131
132
  font_name: null,
132
133
  font_size: "body_m",
133
134
  font_weight: "extra_bold",
@@ -156,7 +157,7 @@
156
157
  value: null,
157
158
  },
158
159
  },
159
- text_lid: "QZ4ZmYsqjN",
160
+ text_lid: priceLid,
160
161
  type: "text",
161
162
  },
162
163
  ],
@@ -241,9 +242,8 @@
241
242
  },
242
243
  spacing: 8,
243
244
  type: "stack",
245
+ shadow: null,
244
246
  },
245
- onAction,
246
- labels: labelsData,
247
247
  type: "package",
248
248
  }}
249
249
  />
@@ -1,10 +1,4 @@
1
1
  import Package from "./Package.svelte";
2
- export declare const labelsData: {
3
- en_US: {
4
- "BcX-6YwhoV": string;
5
- QZ4ZmYsqjN: string;
6
- };
7
- };
8
2
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
9
3
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
10
4
  $$bindings?: Bindings;
@@ -1,33 +1,29 @@
1
1
  <script lang="ts">
2
- import type { PackageProps, SelectPackageAction } from "../../data/entities";
3
2
  import Stack from "../stack/Stack.svelte";
3
+ import { getPaywallContext } from "../../stores/paywall";
4
+ import {
5
+ getVariablesContext,
6
+ setVariablesContext,
7
+ } from "../../stores/variables";
8
+ import type { PackageProps } from "../../types/components/package";
4
9
  import { prefixObject, stringifyStyles } from "../../utils/style-utils";
10
+ import { derived } from "svelte/store";
5
11
 
6
- const {
7
- stack,
8
- package_id,
9
- labels,
10
- id,
11
- onAction,
12
- purchaseState,
13
- variableDictionary,
14
- zStackChildStyles,
15
- }: PackageProps = $props();
16
- const onPackageClick = (evt: MouseEvent) => {
17
- evt.preventDefault();
18
- evt.stopPropagation();
19
- onAction &&
20
- onAction({ type: "select_package" } as SelectPackageAction, {
21
- packageId: package_id,
22
- });
23
- };
12
+ const { stack, package_id, id, zStackChildStyles }: PackageProps = $props();
24
13
 
25
- const packageVariables = $derived(
26
- purchaseState.variablesPerPackage?.[package_id] || variableDictionary,
14
+ const { selectedPackageId, variablesPerPackage } = getPaywallContext();
15
+
16
+ const onPackageClick = () => ($selectedPackageId = package_id);
17
+
18
+ const fallbackVariables = getVariablesContext();
19
+ const variables = derived(
20
+ fallbackVariables,
21
+ (fallback) => $variablesPerPackage?.[package_id] ?? fallback,
27
22
  );
23
+ setVariablesContext(variables);
28
24
 
29
25
  const componentState = $derived({
30
- selected: purchaseState?.selectedPackageId === package_id,
26
+ selected: $selectedPackageId === package_id,
31
27
  });
32
28
 
33
29
  const styles = $derived(
@@ -42,14 +38,7 @@
42
38
  onclick={onPackageClick}
43
39
  style={styles}
44
40
  >
45
- <Stack
46
- {...stack}
47
- {labels}
48
- {onAction}
49
- {purchaseState}
50
- {componentState}
51
- variableDictionary={packageVariables}
52
- />
41
+ <Stack {...stack} {componentState} />
53
42
  </button>
54
43
 
55
44
  <style>
@@ -1,4 +1,4 @@
1
- import type { PackageProps } from "../../data/entities";
1
+ import type { PackageProps } from "../../types/components/package";
2
2
  declare const Package: import("svelte").Component<PackageProps, {}, "">;
3
3
  type Package = ReturnType<typeof Package>;
4
4
  export default Package;
@@ -1,18 +1,4 @@
1
1
  <script lang="ts">
2
- import Self from "./Node.svelte";
3
- import {
4
- type ActionsProps,
5
- type ComponentLocalizations,
6
- type ComponentState,
7
- type Extra,
8
- type PaywallComponent,
9
- type PurchaseStateProps,
10
- type SupportedActions,
11
- } from "../../data/entities";
12
- import { prefersDarkMode } from "../../stores/theme";
13
- import type { VariableDictionary } from "../../utils/variable-utils";
14
- import type { ZStackChildStyles } from "../stack/stack-utils";
15
- import TextNode from "../text/TextNode.svelte";
16
2
  import {
17
3
  Footer,
18
4
  Image,
@@ -22,7 +8,12 @@
22
8
  Timeline,
23
9
  } from "../..";
24
10
  import ButtonNode from "../button/ButtonNode.svelte";
25
- import type { Component } from "svelte";
11
+ import type { ZStackChildStyles } from "../stack/stack-utils";
12
+ import TextNode from "../text/TextNode.svelte";
13
+ import type { ComponentState } from "../../data/entities";
14
+ import type { Component } from "../../types/component";
15
+ import type { Component as SvelteComponent } from "svelte";
16
+ import Self from "./Node.svelte";
26
17
 
27
18
  type SupportedComponents =
28
19
  | TextNode
@@ -34,11 +25,8 @@
34
25
  | Footer
35
26
  | Timeline;
36
27
 
37
- interface Props extends ActionsProps, PurchaseStateProps {
38
- nodeData: PaywallComponent;
39
- labels: ComponentLocalizations;
40
- onAction?: (action: SupportedActions, data?: Extra) => void;
41
- variableDictionary?: VariableDictionary;
28
+ interface Props {
29
+ nodeData: Component;
42
30
  zStackChildStyles?: ZStackChildStyles;
43
31
  componentState?: ComponentState;
44
32
  }
@@ -52,6 +40,10 @@
52
40
  package: Package,
53
41
  footer: Footer,
54
42
  timeline: Timeline,
43
+ } satisfies {
44
+ [key in Component["type"]]: SvelteComponent<
45
+ Extract<Component, { type: key }>
46
+ >;
55
47
  };
56
48
 
57
49
  /**
@@ -59,18 +51,18 @@
59
51
  * It first checks if the component type is supported and returns the corresponding component class.
60
52
  * If not supported, it checks if the fallback component type is supported and returns the corresponding component class,
61
53
  * finally it throws an error if the component type is not supported and the fallback component type is not supported.
62
- * @param nodeData:PaywallComponent - the PaywallComponent object representing a Node in the paywall
63
- * @returns [Component<SupportedComponents>, PaywallComponent] - a tuple containing the component class and the node data
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
64
56
  * @throws Error - if the component type and the fallback component type are not supported
65
57
  */
66
58
  export const getComponentClass: (
67
- nodeData: PaywallComponent,
68
- ) => [Component<SupportedComponents>, PaywallComponent] = (
69
- nodeData: PaywallComponent,
59
+ nodeData: Component,
60
+ ) => [SvelteComponent<SupportedComponents>, Component] = (
61
+ nodeData: Component,
70
62
  ) => {
71
63
  if (ComponentTypes[nodeData.type]) {
72
64
  return [
73
- ComponentTypes[nodeData.type] as Component<SupportedComponents>,
65
+ ComponentTypes[nodeData.type] as SvelteComponent<SupportedComponents>,
74
66
  nodeData,
75
67
  ];
76
68
  }
@@ -78,7 +70,7 @@
78
70
  const { fallback } = nodeData;
79
71
  if (fallback && ComponentTypes[fallback?.type]) {
80
72
  return [
81
- ComponentTypes[fallback.type] as Component<SupportedComponents>,
73
+ ComponentTypes[fallback.type] as SvelteComponent<SupportedComponents>,
82
74
  fallback,
83
75
  ];
84
76
  }
@@ -88,37 +80,21 @@
88
80
  throw new Error(`Invalid component type: ${nodeData.type}`);
89
81
  };
90
82
 
91
- const {
92
- nodeData,
93
- labels,
94
- onAction,
95
- purchaseState,
96
- variableDictionary,
97
- zStackChildStyles,
98
- ...restProps
99
- }: Props = $props();
83
+ const { nodeData, zStackChildStyles, ...restProps }: Props = $props();
100
84
 
101
85
  const [ComponentToRender, dataToUse] = $derived(getComponentClass(nodeData));
86
+
87
+ const components = $derived(
88
+ ("components" in nodeData ? nodeData.components : undefined) ?? [],
89
+ );
102
90
  </script>
103
91
 
104
92
  <ComponentToRender
105
93
  {...(dataToUse as any) || {}}
106
- {labels}
107
- prefersDarkMode={$prefersDarkMode}
108
- {onAction}
109
- {purchaseState}
110
- {variableDictionary}
111
94
  {zStackChildStyles}
112
95
  {...restProps}
113
96
  >
114
- {#each nodeData.components as PaywallComponent[] as childData}
115
- <Self
116
- nodeData={childData}
117
- {labels}
118
- {onAction}
119
- {purchaseState}
120
- {variableDictionary}
121
- {...restProps}
122
- />
97
+ {#each components as childData}
98
+ <Self nodeData={childData} {...restProps} />
123
99
  {/each}
124
100
  </ComponentToRender>
@@ -1,29 +1,26 @@
1
- import { type ActionsProps, type ComponentLocalizations, type ComponentState, type Extra, type PaywallComponent, type PurchaseStateProps, type SupportedActions } from "../../data/entities";
2
- import type { VariableDictionary } from "../../utils/variable-utils";
3
- import type { ZStackChildStyles } from "../stack/stack-utils";
4
- import TextNode from "../text/TextNode.svelte";
1
+ import { SvelteComponent } from "svelte";
5
2
  import { Footer, Image, Package, PurchaseButton, Stack, Timeline } from "../..";
6
3
  import ButtonNode from "../button/ButtonNode.svelte";
7
- import type { Component } from "svelte";
4
+ import type { ZStackChildStyles } from "../stack/stack-utils";
5
+ import TextNode from "../text/TextNode.svelte";
6
+ import type { ComponentState } from "../../data/entities";
7
+ import type { Component } from "../../types/component";
8
8
  type SupportedComponents = TextNode | Stack | Image | ButtonNode | PurchaseButton | Package | Footer | Timeline;
9
- interface Props extends ActionsProps, PurchaseStateProps {
10
- nodeData: PaywallComponent;
11
- labels: ComponentLocalizations;
12
- onAction?: (action: SupportedActions, data?: Extra) => void;
13
- variableDictionary?: VariableDictionary;
9
+ interface Props {
10
+ nodeData: Component;
14
11
  zStackChildStyles?: ZStackChildStyles;
15
12
  componentState?: ComponentState;
16
13
  }
17
- declare const Node: Component<Props, {
14
+ declare const Node: import("svelte").Component<Props, {
18
15
  /**
19
16
  * This function returns the component class and the node data for a given paywall component.
20
17
  * It first checks if the component type is supported and returns the corresponding component class.
21
18
  * If not supported, it checks if the fallback component type is supported and returns the corresponding component class,
22
19
  * finally it throws an error if the component type is not supported and the fallback component type is not supported.
23
- * @param nodeData:PaywallComponent - the PaywallComponent object representing a Node in the paywall
24
- * @returns [Component<SupportedComponents>, PaywallComponent] - a tuple containing the component class and the node data
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
25
22
  * @throws Error - if the component type and the fallback component type are not supported
26
- */ getComponentClass: (nodeData: PaywallComponent) => [Component<SupportedComponents>, PaywallComponent];
23
+ */ getComponentClass: (nodeData: Component) => [SvelteComponent<SupportedComponents>, Component];
27
24
  }, "">;
28
25
  type Node = ReturnType<typeof Node>;
29
26
  export default Node;