@pushwoosh/websdk-common 6.25.0 → 6.26.1
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.d.ts +3 -1
- package/inbox/InboxCellPreview.js +79 -6
- package/inbox/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { type ReactElement } from 'react';
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
2
|
import { type InboxCellPreviewProps } from './types';
|
|
3
|
+
/** Plain text with every `{Tag|modifier}` token drawn as a tag chip. */
|
|
4
|
+
export declare function renderInboxTags(text: string): ReactNode;
|
|
3
5
|
/** 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
6
|
export declare function InboxCellPreview(props: InboxCellPreviewProps): ReactElement;
|
|
@@ -10,6 +10,8 @@ const CLEAR = '#FFFFFF';
|
|
|
10
10
|
const DIVIDER = '#EBF0F5';
|
|
11
11
|
const BRIGHT = '#00A2FF';
|
|
12
12
|
const BRIGHT_LIGHT = '#80B7FF33';
|
|
13
|
+
const EXCEPTIONAL = '#B255E0';
|
|
14
|
+
const EXCEPTIONAL_LIGHT = '#DE9BFF24';
|
|
13
15
|
const SOFT_LIGHT = '#889EB81A';
|
|
14
16
|
const RADIUS = '8px';
|
|
15
17
|
const FONT = 'Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif';
|
|
@@ -51,6 +53,71 @@ const ELLIPSIS = {
|
|
|
51
53
|
textOverflow: 'ellipsis',
|
|
52
54
|
whiteSpace: 'nowrap'
|
|
53
55
|
};
|
|
56
|
+
// `{{key|text}}` is a localization placeholder, not a tag, so it is matched first and kept literal.
|
|
57
|
+
const TAG_TOKEN = /(\{\{[^{}]*\}\}|\{(?=[^{}]*\|)[^{}]*\})/;
|
|
58
|
+
const TAG = {
|
|
59
|
+
display: 'inline-flex',
|
|
60
|
+
alignItems: 'center',
|
|
61
|
+
gap: 1,
|
|
62
|
+
height: 16,
|
|
63
|
+
padding: 2,
|
|
64
|
+
boxSizing: 'border-box',
|
|
65
|
+
borderRadius: 4,
|
|
66
|
+
background: EXCEPTIONAL_LIGHT,
|
|
67
|
+
verticalAlign: 'middle',
|
|
68
|
+
whiteSpace: 'nowrap'
|
|
69
|
+
};
|
|
70
|
+
const TAG_BRACKET = {
|
|
71
|
+
fontSize: 13,
|
|
72
|
+
lineHeight: '18px',
|
|
73
|
+
fontWeight: 500,
|
|
74
|
+
color: EXCEPTIONAL
|
|
75
|
+
};
|
|
76
|
+
const TAG_NAME = {
|
|
77
|
+
fontSize: 10,
|
|
78
|
+
lineHeight: 1.2,
|
|
79
|
+
fontWeight: 400,
|
|
80
|
+
color: MAIN
|
|
81
|
+
};
|
|
82
|
+
const PREVIEW_CSS = `
|
|
83
|
+
.pw-inbox-widget--cell .pw-inbox_item--carousel .pw-inbox_hero--placeholder {
|
|
84
|
+
position: relative;
|
|
85
|
+
}
|
|
86
|
+
.pw-inbox-widget--cell .pw-inbox_item--carousel .pw-inbox_hero--placeholder::after {
|
|
87
|
+
content: '';
|
|
88
|
+
position: absolute;
|
|
89
|
+
left: 50%;
|
|
90
|
+
bottom: 9px;
|
|
91
|
+
width: 4px;
|
|
92
|
+
height: 4px;
|
|
93
|
+
margin-left: -10px;
|
|
94
|
+
border-radius: 50%;
|
|
95
|
+
background: ${MAIN};
|
|
96
|
+
box-shadow: 8px 0 0 ${MAIN}, 16px 0 0 ${MAIN};
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
/** Plain text with every `{Tag|modifier}` token drawn as a tag chip. */
|
|
100
|
+
export function renderInboxTags(text) {
|
|
101
|
+
return text.split(TAG_TOKEN).map((part, index) => {
|
|
102
|
+
if (index % 2 === 0 || part.startsWith('{{')) {
|
|
103
|
+
return part;
|
|
104
|
+
}
|
|
105
|
+
return _jsxs("span", {
|
|
106
|
+
"data-inbox-tag": true,
|
|
107
|
+
style: TAG,
|
|
108
|
+
children: [_jsx("span", {
|
|
109
|
+
style: TAG_BRACKET,
|
|
110
|
+
children: '{'
|
|
111
|
+
}), _jsx("span", {
|
|
112
|
+
style: TAG_NAME,
|
|
113
|
+
children: part.slice(1, -1).split('|')[0]
|
|
114
|
+
}), _jsx("span", {
|
|
115
|
+
style: TAG_BRACKET,
|
|
116
|
+
children: '}'
|
|
117
|
+
})]
|
|
118
|
+
}, index);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
54
121
|
const AVATAR = {
|
|
55
122
|
ios: {
|
|
56
123
|
size: 30,
|
|
@@ -59,7 +126,7 @@ const AVATAR = {
|
|
|
59
126
|
},
|
|
60
127
|
android: {
|
|
61
128
|
size: 40,
|
|
62
|
-
radius:
|
|
129
|
+
radius: '50%',
|
|
63
130
|
text: TEXT.h4
|
|
64
131
|
}
|
|
65
132
|
};
|
|
@@ -454,7 +521,7 @@ export function InboxCellPreview(props) {
|
|
|
454
521
|
isLoading = false,
|
|
455
522
|
emptyTitle = 'Message preview',
|
|
456
523
|
emptyDescription = 'Enter text of your inbox message to see the preview',
|
|
457
|
-
renderText =
|
|
524
|
+
renderText = renderInboxTags,
|
|
458
525
|
iconPlaceholder = false,
|
|
459
526
|
width = '100%'
|
|
460
527
|
} = props;
|
|
@@ -492,7 +559,7 @@ export function InboxCellPreview(props) {
|
|
|
492
559
|
return _jsxs("div", {
|
|
493
560
|
style: frame,
|
|
494
561
|
children: [_jsx("style", {
|
|
495
|
-
children: INBOX_WIDGET_CSS
|
|
562
|
+
children: INBOX_WIDGET_CSS + PREVIEW_CSS
|
|
496
563
|
}), _jsx("div", {
|
|
497
564
|
className: widget.className,
|
|
498
565
|
style: {
|
|
@@ -502,14 +569,20 @@ export function InboxCellPreview(props) {
|
|
|
502
569
|
children: _jsx("ul", {
|
|
503
570
|
className: "pw-inbox_list",
|
|
504
571
|
children: _jsx(InboxWebCell, {
|
|
505
|
-
body: isEmpty ? emptyDescription : picked.body,
|
|
572
|
+
body: isEmpty ? emptyDescription : picked.body && renderText(picked.body),
|
|
506
573
|
content: picked,
|
|
507
574
|
isActionPerformed: !unread,
|
|
508
575
|
isRead: !unread,
|
|
509
576
|
layout: layout,
|
|
510
577
|
placeholder: isEmpty || (layout === 'classic' ? isIconPending : !hasMedia(picked, layout)),
|
|
511
|
-
timeLabel: formatInboxMessageTime(sendDate || new Date().toISOString()),
|
|
512
|
-
title: isEmpty ? emptyTitle : picked.title
|
|
578
|
+
timeLabel: formatInboxMessageTime(sendDate || new Date().toISOString()).replace(/ \d{4},/, ','),
|
|
579
|
+
title: isEmpty ? emptyTitle : picked.title && _jsx("span", {
|
|
580
|
+
style: {
|
|
581
|
+
...ELLIPSIS,
|
|
582
|
+
minWidth: 0
|
|
583
|
+
},
|
|
584
|
+
children: renderText(picked.title)
|
|
585
|
+
})
|
|
513
586
|
})
|
|
514
587
|
})
|
|
515
588
|
})]
|
package/inbox/types.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ export interface InboxCellPreviewProps {
|
|
|
117
117
|
emptyTitle?: ReactNode;
|
|
118
118
|
/** Description of the empty placeholder. */
|
|
119
119
|
emptyDescription?: ReactNode;
|
|
120
|
-
/** Renders the title/body of
|
|
120
|
+
/** Renders the title/body of every cell (e.g. a rich-text viewer); by default tags are drawn as chips. */
|
|
121
121
|
renderText?: (text: string) => ReactNode;
|
|
122
122
|
/** Appearance of the web cell. */
|
|
123
123
|
appearance?: Partial<InboxWidgetAppearance>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/websdk-common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.26.1",
|
|
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",
|