@revenuecat/purchases-ui-js 2.2.0 → 3.0.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.
@@ -1,5 +1,6 @@
1
1
  <script module lang="ts">
2
2
  import Package from "./Package.svelte";
3
+ import type { PackageProps } from "../../types/components/package";
3
4
  import { componentDecorator } from "../../stories/component-decorator";
4
5
  import { localizationDecorator } from "../../stories/localization-decorator";
5
6
  import { defineMeta } from "@storybook/addon-svelte-csf";
@@ -9,6 +9,7 @@
9
9
  Video,
10
10
  } from "../..";
11
11
  import ButtonNode from "../button/ButtonNode.svelte";
12
+ import Countdown from "../countdown/Countdown.svelte";
12
13
  import InputMultipleChoice from "../options/InputMultipleChoice.svelte";
13
14
  import InputOption from "../options/InputOption.svelte";
14
15
  import InputSingleChoice from "../options/InputSingleChoice.svelte";
@@ -29,6 +30,7 @@
29
30
  const ComponentTypes = {
30
31
  button: ButtonNode,
31
32
  carousel: Carousel,
33
+ countdown: Countdown,
32
34
  footer: Footer,
33
35
  icon: Icon,
34
36
  image: Image,
@@ -26,13 +26,17 @@
26
26
  import { SHEET_PAYWALL } from "./fixtures/sheet-paywall";
27
27
  import { STACK_PAYWALL } from "./fixtures/stack-paywall";
28
28
  import { VARIABLES } from "./fixtures/variables";
29
+ import { COUNTDOWN_PAYWALL } from "../countdown/fixtures/countdown-paywall";
30
+ import { mockDateDecorator } from "storybook-mock-date-decorator";
29
31
 
30
32
  const { Story } = defineMeta({
31
33
  title: "Example/Paywall",
32
34
  component: Paywall,
33
35
  args: {
34
- onPurchaseClicked: (selectedPackageId: string) =>
35
- alert(`Purchase package ${selectedPackageId}`),
36
+ onPurchaseClicked: (selectedPackageId: string, actionId: string) =>
37
+ alert(
38
+ `Purchase package ${selectedPackageId}${actionId ? ` with action ${actionId}` : ""}`,
39
+ ),
36
40
  onBackClicked: () => alert("Go back"),
37
41
  onVisitCustomerCenterClicked: () => alert("Visit customer center"),
38
42
  onRestorePurchasesClicked: () => alert("Restore purchases"),
@@ -322,3 +326,30 @@
322
326
  paywallData: listTemplate,
323
327
  }}
324
328
  />
329
+
330
+ <Story
331
+ name="With Countdown"
332
+ decorators={[mockDateDecorator]}
333
+ parameters={{
334
+ date: new Date("2024-01-15T12:00:00Z"),
335
+ }}
336
+ args={{
337
+ paywallData: COUNTDOWN_PAYWALL,
338
+ }}
339
+ />
340
+
341
+ <Story
342
+ name="Wallet Button"
343
+ args={{
344
+ paywallData: pastaPaywallData,
345
+ walletButtonRender: (element: HTMLElement, selectedPackageId) => {
346
+ const newDiv = document.createElement("div");
347
+ newDiv.innerText = "Hi! I was injected from the walletButtonRender";
348
+ newDiv.style.width = "100%";
349
+ newDiv.style.textAlign = "center";
350
+ newDiv.style.border = "1px solid black";
351
+ element.append(newDiv);
352
+ return {};
353
+ },
354
+ }}
355
+ />
@@ -33,13 +33,20 @@
33
33
  infoPerPackage?: Record<string, PackageInfo>;
34
34
  uiConfig: UIConfig;
35
35
  preferredColorMode?: ColorMode;
36
- onPurchaseClicked?: (selectedPackageId: string) => void;
36
+ onPurchaseClicked?: (selectedPackageId: string, actionId: string) => void;
37
37
  onBackClicked?: () => void;
38
38
  onVisitCustomerCenterClicked?: () => void;
39
39
  onRestorePurchasesClicked?: () => void;
40
40
  onNavigateToUrlClicked?: (url: string) => void;
41
41
  onActionTriggered?: (actionId: string) => void;
42
42
  onError?: (error: unknown) => void;
43
+ walletButtonRender?: (
44
+ node: HTMLElement,
45
+ selectedPackageId: string,
46
+ ) => {
47
+ destroy?: () => void;
48
+ update?: (selectedPackageId: string) => void;
49
+ };
43
50
  }
44
51
 
45
52
  const {
@@ -56,6 +63,7 @@
56
63
  onActionTriggered,
57
64
  onError,
58
65
  uiConfig,
66
+ walletButtonRender,
59
67
  }: Props = $props();
60
68
 
61
69
  const getColorMode = setColorModeContext(() => preferredColorMode);
@@ -75,10 +83,10 @@
75
83
  findSelectedPackageId(base),
76
84
  );
77
85
 
78
- const onPurchase = () => {
86
+ const onPurchase = (actionId?: string) => {
79
87
  const packageId = $selectedPackageId;
80
88
  if (packageId !== undefined) {
81
- onPurchaseClicked?.(packageId);
89
+ onPurchaseClicked?.(packageId, actionId ?? "");
82
90
  }
83
91
  };
84
92
 
@@ -127,6 +135,7 @@
127
135
  infoPerPackage: readable(infoPerPackage),
128
136
  onPurchase,
129
137
  onButtonAction,
138
+ walletButtonRender,
130
139
  uiConfig,
131
140
  });
132
141
 
@@ -9,13 +9,17 @@ interface Props {
9
9
  infoPerPackage?: Record<string, PackageInfo>;
10
10
  uiConfig: UIConfig;
11
11
  preferredColorMode?: ColorMode;
12
- onPurchaseClicked?: (selectedPackageId: string) => void;
12
+ onPurchaseClicked?: (selectedPackageId: string, actionId: string) => void;
13
13
  onBackClicked?: () => void;
14
14
  onVisitCustomerCenterClicked?: () => void;
15
15
  onRestorePurchasesClicked?: () => void;
16
16
  onNavigateToUrlClicked?: (url: string) => void;
17
17
  onActionTriggered?: (actionId: string) => void;
18
18
  onError?: (error: unknown) => void;
19
+ walletButtonRender?: (node: HTMLElement, selectedPackageId: string) => {
20
+ destroy?: () => void;
21
+ update?: (selectedPackageId: string) => void;
22
+ };
19
23
  }
20
24
  declare const Paywall: import("svelte").Component<Props, {}, "">;
21
25
  type Paywall = ReturnType<typeof Paywall>;
@@ -2,10 +2,61 @@
2
2
  import Stack from "../stack/Stack.svelte";
3
3
  import { getPaywallContext } from "../../stores/paywall";
4
4
  import type { PurchaseButtonProps } from "../../types/components/purchase-button";
5
+ import { getSelectedStateContext } from "../../stores/selected";
6
+ import { getActiveStateProps } from "../../utils/style-utils";
7
+ import {
8
+ type CSS,
9
+ css,
10
+ mapSize,
11
+ mapSpacing,
12
+ px,
13
+ } from "../../utils/base-utils";
14
+ import { mapDimension } from "../stack/stack-utils";
15
+ import type { StackProps } from "../../types/components/stack";
5
16
 
6
- const { stack }: PurchaseButtonProps = $props();
17
+ const props: PurchaseButtonProps = $props();
18
+ const { stack } = props;
7
19
 
8
- const { onPurchase } = getPaywallContext();
20
+ const { onPurchase, walletButtonRender, selectedPackageId } =
21
+ getPaywallContext();
22
+
23
+ const stackProps: StackProps & { style?: CSS } = { ...stack };
24
+ const selectedState = getSelectedStateContext();
25
+ const { size, dimension, spacing, margin } = $derived.by(() => {
26
+ return {
27
+ ...stackProps,
28
+ ...getActiveStateProps($selectedState, stackProps.overrides),
29
+ };
30
+ });
31
+
32
+ const stackStyle = $derived(
33
+ css({
34
+ ...stackProps.style,
35
+ display: "flex",
36
+ position: "relative",
37
+ width: mapSize(size.width),
38
+ height: mapSize(size.height),
39
+ ...mapDimension(dimension),
40
+ gap: px(spacing),
41
+ margin: mapSpacing(margin),
42
+ }),
43
+ );
44
+
45
+ const onclick = () => {
46
+ const actionId = props.triggers?.on_purchase_press;
47
+ onPurchase(actionId);
48
+ };
9
49
  </script>
10
50
 
11
- <Stack {...stack} onclick={onPurchase} />
51
+ {#if walletButtonRender}
52
+ {#if $selectedPackageId}
53
+ <div style={stackStyle}>
54
+ <div
55
+ style="flex-grow: 1"
56
+ use:walletButtonRender={$selectedPackageId}
57
+ ></div>
58
+ </div>
59
+ {/if}
60
+ {/if}
61
+
62
+ <Stack {...stack} {onclick} />
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as ButtonDeprecated } from "./components/button/Button.svelte";
2
+ export { default as Countdown } from "./components/countdown/Countdown.svelte";
2
3
  export { default as Footer } from "./components/footer/Footer.svelte";
3
4
  export { default as Image } from "./components/image/Image.svelte";
4
5
  export { default as InputMultipleChoice } from "./components/options/InputMultipleChoice.svelte";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Reexport your entry components here
2
2
  export { default as ButtonDeprecated } from "./components/button/Button.svelte";
3
+ export { default as Countdown } from "./components/countdown/Countdown.svelte";
3
4
  export { default as Footer } from "./components/footer/Footer.svelte";
4
5
  export { default as Image } from "./components/image/Image.svelte";
5
6
  export { default as InputMultipleChoice } from "./components/options/InputMultipleChoice.svelte";
@@ -6,7 +6,11 @@ type PaywallContext = Readonly<{
6
6
  selectedPackageId: Writable<string | undefined>;
7
7
  variablesPerPackage: Readable<Record<string, VariableDictionary> | undefined>;
8
8
  infoPerPackage: Readable<Record<string, PackageInfo> | undefined>;
9
- onPurchase: () => void;
9
+ onPurchase: (actionId?: string) => void;
10
+ walletButtonRender?: (node: HTMLElement, selectedPackageId: string) => {
11
+ destroy?: () => void;
12
+ update?: (selectedPackageId: string) => void;
13
+ };
10
14
  onButtonAction: (action: Action, actionId?: string) => void;
11
15
  uiConfig: UIConfig;
12
16
  }>;
@@ -18,6 +18,10 @@ export declare const localizations: {
18
18
  id2: string;
19
19
  id3: string;
20
20
  badge: string;
21
+ countdown: string;
22
+ ended: string;
23
+ days: string;
24
+ time: string;
21
25
  };
22
26
  };
23
27
  export declare const colorModeOverrideTemplate: PaywallData;
@@ -17307,6 +17307,10 @@ export const localizations = {
17307
17307
  id2: "Item 2",
17308
17308
  id3: "Item 3",
17309
17309
  badge: "Badge Text",
17310
+ countdown: "{{ count_days_with_zero }} : {{ count_hours_with_zero }} : {{ count_minutes_with_zero }} : {{ count_seconds_with_zero }}",
17311
+ ended: "Time's up!",
17312
+ days: "{{ count_days_without_zero }} days",
17313
+ time: "{{ count_hours_with_zero }}:{{ count_minutes_with_zero }}:{{ count_seconds_with_zero }}",
17310
17314
  },
17311
17315
  };
17312
17316
  export const colorModeOverrideTemplate = {
@@ -1,2 +1,5 @@
1
1
  import type { DecoratorFunction, Renderer } from "storybook/internal/csf";
2
- export declare function paywallDecorator<TRenderer extends Renderer, TArgs>(): DecoratorFunction<TRenderer, TArgs>;
2
+ export declare function paywallDecorator<TRenderer extends Renderer, TArgs>(walletButtonRender?: (node: HTMLElement, selectedPackageId: string) => {
3
+ destroy?: () => void;
4
+ update?: (selectedPackageId: string) => void;
5
+ }): DecoratorFunction<TRenderer, TArgs>;
@@ -1,6 +1,6 @@
1
1
  import { setPaywallContext } from "../stores/paywall";
2
2
  import { readable, writable } from "svelte/store";
3
- export function paywallDecorator() {
3
+ export function paywallDecorator(walletButtonRender) {
4
4
  return (Story) => {
5
5
  const selectedPackageId = writable(undefined);
6
6
  selectedPackageId.subscribe((packageId) => {
@@ -19,6 +19,7 @@ export function paywallDecorator() {
19
19
  infoPerPackage: readable(undefined),
20
20
  onPurchase: () => window.alert("Purchase clicked"),
21
21
  onButtonAction: (action, actionId) => window.alert(`Button clicked: ${JSON.stringify({ action, actionId }, undefined, 2)}`),
22
+ walletButtonRender,
22
23
  uiConfig: emptyUiConfig,
23
24
  });
24
25
  return Story();
@@ -1,5 +1,6 @@
1
1
  import type { ButtonProps } from "./components/button";
2
2
  import type { CarouselProps } from "./components/carousel";
3
+ import type { CountdownProps } from "./components/countdown";
3
4
  import type { FooterProps } from "./components/footer";
4
5
  import type { IconProps } from "./components/icon";
5
6
  import type { ImageProps } from "./components/image";
@@ -11,4 +12,4 @@ import type { TabControlButtonProps, TabControlProps, TabControlToggleProps, Tab
11
12
  import type { TextNodeProps } from "./components/text";
12
13
  import type { TimelineProps } from "./components/timeline";
13
14
  import type { VideoProps } from "./components/video";
14
- export type Component = ButtonProps | CarouselProps | FooterProps | IconProps | ImageProps | InputMultipleChoiceProps | InputOptionProps | InputSingleChoiceProps | PackageProps | PurchaseButtonProps | StackProps | TabControlButtonProps | TabControlToggleProps | TabControlProps | TabsProps | TextNodeProps | TimelineProps | VideoProps;
15
+ export type Component = ButtonProps | CarouselProps | CountdownProps | FooterProps | IconProps | ImageProps | InputMultipleChoiceProps | InputOptionProps | InputSingleChoiceProps | PackageProps | PurchaseButtonProps | StackProps | TabControlButtonProps | TabControlToggleProps | TabControlProps | TabsProps | TextNodeProps | TimelineProps | VideoProps;
@@ -0,0 +1,13 @@
1
+ import type { BaseComponent } from "../base";
2
+ import type { StackProps } from "./stack";
3
+ export interface CountdownStyle {
4
+ type: "date";
5
+ date: string;
6
+ }
7
+ export interface CountdownProps extends BaseComponent {
8
+ type: "countdown";
9
+ visible?: boolean | null;
10
+ style: CountdownStyle;
11
+ countdown_stack: StackProps;
12
+ end_stack: StackProps | null;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@revenuecat/purchases-ui-js",
3
3
  "description": "Web components for Paywalls. Powered by RevenueCat",
4
4
  "private": false,
5
- "version": "2.2.0",
5
+ "version": "3.0.0",
6
6
  "author": {
7
7
  "name": "RevenueCat, Inc."
8
8
  },
@@ -97,6 +97,7 @@
97
97
  "prettier-plugin-svelte": "3.4.0",
98
98
  "publint": "0.3.15",
99
99
  "storybook": "9.1.10",
100
+ "storybook-mock-date-decorator": "^3.0.0",
100
101
  "svelte": "5.43.0",
101
102
  "svelte-check": "4.3.3",
102
103
  "typescript": "5.9.3",