@pushwoosh/websdk-common 6.22.3 → 6.22.5
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/inbox/InboxCellPreview.js +6 -3
- package/inbox/helpers.d.ts +2 -0
- package/inbox/helpers.js +16 -0
- package/package.json +1 -1
- package/web-popups/colorScheme.js +8 -1
|
@@ -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
3
|
import { INBOX_KNOWN_LAYOUTS, INBOX_WIDGET_CSS } from './constants';
|
|
4
|
-
import { formatInboxMessageTime, getInboxHeroUrl, getInboxIconInitial, getInboxMobileTexts, getInboxValidSlides, isInboxContentEmpty, resolveInboxLayout, resolveInboxWidgetAppearance } from './helpers';
|
|
4
|
+
import { formatInboxMessageTime, getInboxHeroUrl, getInboxIconInitial, getInboxMobileTexts, getInboxTextDirection, getInboxValidSlides, isInboxContentEmpty, resolveInboxLayout, resolveInboxWidgetAppearance } from './helpers';
|
|
5
5
|
import { InboxWebCell, inboxWidgetPreviewFrame } from './InboxWidgetReader';
|
|
6
6
|
const MAIN = '#4B5057';
|
|
7
7
|
const LOCKED = '#767C82';
|
|
@@ -291,7 +291,8 @@ function IOSCell(props) {
|
|
|
291
291
|
display: 'flex',
|
|
292
292
|
alignItems: 'center',
|
|
293
293
|
gap: 8,
|
|
294
|
-
|
|
294
|
+
paddingBlock: 16,
|
|
295
|
+
paddingInline: '18px 16px',
|
|
295
296
|
background: CLEAR,
|
|
296
297
|
borderRadius: RADIUS,
|
|
297
298
|
boxShadow: CARD_EDGE_SHADOW
|
|
@@ -318,7 +319,7 @@ function IOSCell(props) {
|
|
|
318
319
|
children: [media, unread && _jsx(UnreadDot, {
|
|
319
320
|
style: {
|
|
320
321
|
position: 'absolute',
|
|
321
|
-
|
|
322
|
+
insetInlineStart: 10,
|
|
322
323
|
top: 10
|
|
323
324
|
}
|
|
324
325
|
})]
|
|
@@ -499,7 +500,9 @@ export function InboxCellPreview(props) {
|
|
|
499
500
|
}
|
|
500
501
|
const texts = getInboxMobileTexts(picked, layout);
|
|
501
502
|
const Cell = platform === 'android' ? AndroidCell : IOSCell;
|
|
503
|
+
const rtl = !isEmpty && getInboxTextDirection(texts.title, texts.body) === 'rtl';
|
|
502
504
|
return _jsx("div", {
|
|
505
|
+
dir: rtl ? 'rtl' : undefined,
|
|
503
506
|
style: frame,
|
|
504
507
|
children: _jsx(Cell, {
|
|
505
508
|
body: isEmpty ? emptyDescription : texts.body && renderText(texts.body),
|
package/inbox/helpers.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export declare function getInboxMobileTexts(content: InboxCellContent, layout: I
|
|
|
16
16
|
title: string;
|
|
17
17
|
body: string;
|
|
18
18
|
};
|
|
19
|
+
/** 'rtl' when most letters of the copy read right to left; markup and Liquid do not vote. */
|
|
20
|
+
export declare function getInboxTextDirection(...texts: (string | undefined)[]): 'rtl' | 'ltr';
|
|
19
21
|
/** The colored initial a classic cell shows when there is no icon. */
|
|
20
22
|
export declare function getInboxIconInitial(content: InboxCellContent): string;
|
|
21
23
|
/** Date label of a web widget message: relative within a day of `now`, then `D Mon YYYY, H:mm` in local time. */
|
package/inbox/helpers.js
CHANGED
|
@@ -76,6 +76,22 @@ export function getInboxMobileTexts(content, layout) {
|
|
|
76
76
|
body: content.body || ''
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
+
const RTL_LETTER = /[\p{Script=Arabic}\p{Script=Hebrew}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Samaritan}\p{Script=Mandaic}\p{Script=Adlam}\p{Script=Hanifi_Rohingya}\p{Script=Mende_Kikakui}\p{Script=Yezidi}]/u;
|
|
80
|
+
const LETTER = /\p{L}/u;
|
|
81
|
+
const NOT_COPY = /<[^>]*>|\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}/g;
|
|
82
|
+
/** 'rtl' when most letters of the copy read right to left; markup and Liquid do not vote. */
|
|
83
|
+
export function getInboxTextDirection(...texts) {
|
|
84
|
+
let rtl = 0;
|
|
85
|
+
let ltr = 0;
|
|
86
|
+
for (const char of texts.join(' ').replace(NOT_COPY, '')) {
|
|
87
|
+
if (RTL_LETTER.test(char)) {
|
|
88
|
+
rtl += 1;
|
|
89
|
+
} else if (LETTER.test(char)) {
|
|
90
|
+
ltr += 1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return rtl > ltr ? 'rtl' : 'ltr';
|
|
94
|
+
}
|
|
79
95
|
/** The colored initial a classic cell shows when there is no icon. */
|
|
80
96
|
export function getInboxIconInitial(content) {
|
|
81
97
|
return (content.title || content.body || '?').trim().charAt(0).toUpperCase() || '?';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/websdk-common",
|
|
3
|
-
"version": "6.22.
|
|
3
|
+
"version": "6.22.5",
|
|
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]);
|