@pushwoosh/websdk-common 6.22.4 → 6.23.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/inbox/InboxCellPreview.js +14 -6
- package/inbox/helpers.d.ts +2 -0
- package/inbox/helpers.js +16 -0
- package/inbox/types.d.ts +2 -0
- package/package.json +1 -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';
|
|
@@ -239,6 +239,7 @@ function IOSCell(props) {
|
|
|
239
239
|
content,
|
|
240
240
|
layout,
|
|
241
241
|
isEmpty,
|
|
242
|
+
isIconPending,
|
|
242
243
|
title,
|
|
243
244
|
body,
|
|
244
245
|
dateLabel,
|
|
@@ -291,14 +292,15 @@ function IOSCell(props) {
|
|
|
291
292
|
display: 'flex',
|
|
292
293
|
alignItems: 'center',
|
|
293
294
|
gap: 8,
|
|
294
|
-
|
|
295
|
+
paddingBlock: 16,
|
|
296
|
+
paddingInline: '18px 16px',
|
|
295
297
|
background: CLEAR,
|
|
296
298
|
borderRadius: RADIUS,
|
|
297
299
|
boxShadow: CARD_EDGE_SHADOW
|
|
298
300
|
},
|
|
299
301
|
children: [unread && _jsx(UnreadDot, {}), _jsx(Avatar, {
|
|
300
302
|
content: content,
|
|
301
|
-
isEmpty: isEmpty,
|
|
303
|
+
isEmpty: isEmpty || isIconPending,
|
|
302
304
|
platform: "ios"
|
|
303
305
|
}), texts]
|
|
304
306
|
});
|
|
@@ -318,7 +320,7 @@ function IOSCell(props) {
|
|
|
318
320
|
children: [media, unread && _jsx(UnreadDot, {
|
|
319
321
|
style: {
|
|
320
322
|
position: 'absolute',
|
|
321
|
-
|
|
323
|
+
insetInlineStart: 10,
|
|
322
324
|
top: 10
|
|
323
325
|
}
|
|
324
326
|
})]
|
|
@@ -358,6 +360,7 @@ function AndroidCell(props) {
|
|
|
358
360
|
content,
|
|
359
361
|
layout,
|
|
360
362
|
isEmpty,
|
|
363
|
+
isIconPending,
|
|
361
364
|
title,
|
|
362
365
|
body,
|
|
363
366
|
dateLabel,
|
|
@@ -412,7 +415,7 @@ function AndroidCell(props) {
|
|
|
412
415
|
},
|
|
413
416
|
children: [_jsx(Avatar, {
|
|
414
417
|
content: content,
|
|
415
|
-
isEmpty: isEmpty,
|
|
418
|
+
isEmpty: isEmpty || isIconPending,
|
|
416
419
|
platform: "android"
|
|
417
420
|
}), texts]
|
|
418
421
|
})
|
|
@@ -439,6 +442,7 @@ export function InboxCellPreview(props) {
|
|
|
439
442
|
emptyTitle = 'Message preview',
|
|
440
443
|
emptyDescription = 'Enter text of your inbox message to see the preview',
|
|
441
444
|
renderText = text => text,
|
|
445
|
+
iconPlaceholder = false,
|
|
442
446
|
width = '100%'
|
|
443
447
|
} = props;
|
|
444
448
|
const frame = {
|
|
@@ -461,6 +465,7 @@ export function InboxCellPreview(props) {
|
|
|
461
465
|
}
|
|
462
466
|
const picked = content || {};
|
|
463
467
|
const isEmpty = isInboxContentEmpty(picked);
|
|
468
|
+
const isIconPending = iconPlaceholder && !picked.iconUrl;
|
|
464
469
|
const requested = picked.layoutType;
|
|
465
470
|
let layout = 'classic';
|
|
466
471
|
if (INBOX_KNOWN_LAYOUTS.includes(requested)) {
|
|
@@ -489,7 +494,7 @@ export function InboxCellPreview(props) {
|
|
|
489
494
|
isActionPerformed: !unread,
|
|
490
495
|
isRead: !unread,
|
|
491
496
|
layout: layout,
|
|
492
|
-
placeholder: isEmpty || layout
|
|
497
|
+
placeholder: isEmpty || (layout === 'classic' ? isIconPending : !hasMedia(picked, layout)),
|
|
493
498
|
timeLabel: formatInboxMessageTime(sendDate || new Date().toISOString()),
|
|
494
499
|
title: isEmpty ? emptyTitle : picked.title
|
|
495
500
|
})
|
|
@@ -499,13 +504,16 @@ export function InboxCellPreview(props) {
|
|
|
499
504
|
}
|
|
500
505
|
const texts = getInboxMobileTexts(picked, layout);
|
|
501
506
|
const Cell = platform === 'android' ? AndroidCell : IOSCell;
|
|
507
|
+
const rtl = !isEmpty && getInboxTextDirection(texts.title, texts.body) === 'rtl';
|
|
502
508
|
return _jsx("div", {
|
|
509
|
+
dir: rtl ? 'rtl' : undefined,
|
|
503
510
|
style: frame,
|
|
504
511
|
children: _jsx(Cell, {
|
|
505
512
|
body: isEmpty ? emptyDescription : texts.body && renderText(texts.body),
|
|
506
513
|
content: picked,
|
|
507
514
|
dateLabel: dateLabel,
|
|
508
515
|
isEmpty: isEmpty,
|
|
516
|
+
isIconPending: isIconPending,
|
|
509
517
|
layout: layout,
|
|
510
518
|
title: isEmpty ? emptyTitle : renderText(texts.title),
|
|
511
519
|
unread: unread
|
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/inbox/types.d.ts
CHANGED
|
@@ -121,6 +121,8 @@ export interface InboxCellPreviewProps {
|
|
|
121
121
|
renderText?: (text: string) => ReactNode;
|
|
122
122
|
/** Appearance of the web cell. */
|
|
123
123
|
appearance?: Partial<InboxWidgetAppearance>;
|
|
124
|
+
/** Keep the icon placeholder instead of the title's initial while the cell has no icon, as an editor does (default `false`). */
|
|
125
|
+
iconPlaceholder?: boolean;
|
|
124
126
|
/** CSS width of the preview (default `100%`). */
|
|
125
127
|
width?: string | number;
|
|
126
128
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/websdk-common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.23.0",
|
|
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",
|