@pushwoosh/websdk-common 6.22.2 → 6.22.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
2
|
import { type InboxCellPreviewProps } from './types';
|
|
3
|
-
/** One inbox cell drawn the way the SDK of `platform` draws it; the web skin is the WebSDK widget cell itself. */
|
|
3
|
+
/** One inbox cell drawn the way the SDK of `platform` draws it; the web skin is the WebSDK widget cell itself. A known layout is kept as chosen, with placeholders for its missing media. */
|
|
4
4
|
export declare function InboxCellPreview(props: InboxCellPreviewProps): ReactElement;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import { INBOX_WIDGET_CSS } from './constants';
|
|
4
|
-
import { formatInboxMessageTime,
|
|
3
|
+
import { INBOX_KNOWN_LAYOUTS, INBOX_WIDGET_CSS } from './constants';
|
|
4
|
+
import { formatInboxMessageTime, getInboxHeroUrl, getInboxIconInitial, getInboxMobileTexts, getInboxValidSlides, isInboxContentEmpty, resolveInboxLayout, resolveInboxWidgetAppearance } from './helpers';
|
|
5
5
|
import { InboxWebCell, inboxWidgetPreviewFrame } from './InboxWidgetReader';
|
|
6
6
|
const MAIN = '#4B5057';
|
|
7
7
|
const LOCKED = '#767C82';
|
|
@@ -195,12 +195,15 @@ function Carousel({
|
|
|
195
195
|
})]
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
+
function hasMedia(content, layout) {
|
|
199
|
+
return layout === 'carousel' ? getInboxValidSlides(content.carousel).length > 0 : !!getInboxHeroUrl(content);
|
|
200
|
+
}
|
|
198
201
|
function Media({
|
|
199
202
|
content,
|
|
200
203
|
layout,
|
|
201
204
|
isEmpty
|
|
202
205
|
}) {
|
|
203
|
-
if (isEmpty) {
|
|
206
|
+
if (isEmpty || !hasMedia(content, layout)) {
|
|
204
207
|
return _jsx("div", {
|
|
205
208
|
style: {
|
|
206
209
|
aspectRatio: '2 / 1',
|
|
@@ -424,7 +427,7 @@ function AndroidCell(props) {
|
|
|
424
427
|
}), layout !== 'banner' && texts]
|
|
425
428
|
});
|
|
426
429
|
}
|
|
427
|
-
/** One inbox cell drawn the way the SDK of `platform` draws it; the web skin is the WebSDK widget cell itself. */
|
|
430
|
+
/** One inbox cell drawn the way the SDK of `platform` draws it; the web skin is the WebSDK widget cell itself. A known layout is kept as chosen, with placeholders for its missing media. */
|
|
428
431
|
export function InboxCellPreview(props) {
|
|
429
432
|
const {
|
|
430
433
|
platform = 'ios',
|
|
@@ -458,7 +461,13 @@ export function InboxCellPreview(props) {
|
|
|
458
461
|
}
|
|
459
462
|
const picked = content || {};
|
|
460
463
|
const isEmpty = isInboxContentEmpty(picked);
|
|
461
|
-
const
|
|
464
|
+
const requested = picked.layoutType;
|
|
465
|
+
let layout = 'classic';
|
|
466
|
+
if (INBOX_KNOWN_LAYOUTS.includes(requested)) {
|
|
467
|
+
layout = requested;
|
|
468
|
+
} else if (!isEmpty) {
|
|
469
|
+
layout = resolveInboxLayout(picked);
|
|
470
|
+
}
|
|
462
471
|
if (platform === 'web') {
|
|
463
472
|
const appearance = resolveInboxWidgetAppearance(props.appearance);
|
|
464
473
|
const widget = inboxWidgetPreviewFrame(appearance, 'pw-inbox-widget--cell');
|
|
@@ -480,7 +489,7 @@ export function InboxCellPreview(props) {
|
|
|
480
489
|
isActionPerformed: !unread,
|
|
481
490
|
isRead: !unread,
|
|
482
491
|
layout: layout,
|
|
483
|
-
placeholder: isEmpty,
|
|
492
|
+
placeholder: isEmpty || layout !== 'classic' && !hasMedia(picked, layout),
|
|
484
493
|
timeLabel: formatInboxMessageTime(sendDate || new Date().toISOString()),
|
|
485
494
|
title: isEmpty ? emptyTitle : picked.title
|
|
486
495
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/websdk-common",
|
|
3
|
-
"version": "6.22.
|
|
3
|
+
"version": "6.22.4",
|
|
4
4
|
"description": "Code shared by the Pushwoosh WebSDK and the Control Panel, one entry point per module (web-popups: web popup model and renderer; subscription-widget: push subscription widget model and renderer; inbox: web inbox widget and inbox cell previews)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -7,13 +7,20 @@ function prefersDark() {
|
|
|
7
7
|
// be on screen when the theme flips, and a stale palette is the visible half.
|
|
8
8
|
export function useColorScheme(pref, watch) {
|
|
9
9
|
const [dark, setDark] = useState(() => pref === 'auto' && watch && prefersDark());
|
|
10
|
+
const watchDeps = [pref, watch];
|
|
11
|
+
const [prevWatchDeps, setPrevWatchDeps] = useState(null);
|
|
12
|
+
if (prevWatchDeps === null || watchDeps.some((dep, index) => dep !== prevWatchDeps[index])) {
|
|
13
|
+
setPrevWatchDeps(watchDeps);
|
|
14
|
+
if (pref === 'auto' && watch) {
|
|
15
|
+
setDark(prefersDark());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
10
18
|
useEffect(() => {
|
|
11
19
|
if (pref !== 'auto' || !watch || typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
|
|
12
20
|
return undefined;
|
|
13
21
|
}
|
|
14
22
|
const media = window.matchMedia(DARK_MEDIA_QUERY);
|
|
15
23
|
const onChange = event => setDark(event.matches);
|
|
16
|
-
setDark(media.matches);
|
|
17
24
|
media.addEventListener('change', onChange);
|
|
18
25
|
return () => media.removeEventListener('change', onChange);
|
|
19
26
|
}, [pref, watch]);
|