@superwall/studio 2.1.0 → 2.2.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.
package/src/lib/time.ts CHANGED
@@ -7,14 +7,21 @@ const UNITS: [number, Intl.RelativeTimeFormatUnit][] = [
7
7
  [12, "month"],
8
8
  ];
9
9
 
10
- export const timeAgo = (iso: string, now = Date.now()): string | undefined => {
11
- const then = Date.parse(iso);
12
- if (Number.isNaN(then)) return undefined;
13
- let value = Math.max(0, (now - then) / 1000);
10
+ const relative = (seconds: number): string => {
14
11
  const formatter = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
12
+ const sign = Math.sign(seconds) || 1;
13
+ let value = Math.abs(seconds);
15
14
  for (const [factor, unit] of UNITS) {
16
- if (value < factor) return formatter.format(-Math.round(value), unit);
15
+ if (value < factor) return formatter.format(sign * Math.round(value), unit);
17
16
  value /= factor;
18
17
  }
19
- return formatter.format(-Math.round(value), "year");
18
+ return formatter.format(sign * Math.round(value), "year");
20
19
  };
20
+
21
+ export const timeAgo = (iso: string, now = Date.now()): string | undefined => {
22
+ const then = Date.parse(iso);
23
+ if (Number.isNaN(then)) return undefined;
24
+ return relative(-Math.max(0, (now - then) / 1000));
25
+ };
26
+
27
+ export const timeUntil = (ms: number): string => relative(Math.max(0, ms) / 1000);
@@ -41,6 +41,7 @@ import {
41
41
  deviceById,
42
42
  deviceVariablesFor,
43
43
  isWebOnly,
44
+ notificationScreenFor,
44
45
  webViewportFor,
45
46
  RESPONSIVE_DEFAULT,
46
47
  RESPONSIVE_ID,
@@ -254,7 +255,6 @@ export const SurfaceEditor = ({
254
255
  React.useEffect(() => () => window.clearTimeout(dismissTimer.current), []);
255
256
 
256
257
  const shipping = source.actions;
257
- const delegate = useStudioDelegate();
258
258
  const defaults = React.useMemo(studioDefaults, [surface]);
259
259
 
260
260
  const locales = surface.locales;
@@ -321,6 +321,12 @@ export const SurfaceEditor = ({
321
321
  ? webViewportFor(device)
322
322
  : { width: device.width, height: device.height };
323
323
  const presentation = web ? undefined : surface.presentation;
324
+ const reminderScreen = notificationScreenFor(device, web || responsive);
325
+ const delegate = useStudioDelegate({
326
+ platform: reminderScreen.platform,
327
+ screenWidth: reminderScreen.width,
328
+ app: source.app ?? { name: surface.project ?? source.title },
329
+ });
324
330
  const frame = landscape ? { width: upright.height, height: upright.width } : upright;
325
331
 
326
332
  const openPreview = () => {