@pushwoosh/dumb-components 4.13.2 → 4.15.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/RichMessageEditor/RichMessageEditor.js +11 -11
- package/RichMessageEditor/RichMessageEditor.types.d.ts +2 -0
- package/RichMessageEditor/index.d.ts +1 -0
- package/RichMessageEditor/index.js +2 -1
- package/RichMessageEditor/slate/DynamicContentElement.js +3 -2
- package/RichMessageEditor/slate/SlateEditor.d.ts +1 -0
- package/RichMessageEditor/slate/SlateEditor.js +3 -0
- package/RichMessageEditor/slate/styles.d.ts +1 -0
- package/RichMessageEditor/slate/styles.js +4 -2
- package/RichMessageEditor/styles.js +2 -1
- package/WhatsAppPreview/WhatsAppPreview.js +43 -40
- package/WhatsAppPreview/styles.js +3 -4
- package/WhatsAppPreview/types.d.ts +2 -0
- package/hooks/useLayer.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +2 -2
- package/shared/dynamicContent/index.d.ts +1 -1
- package/shared/dynamicContent/index.js +1 -1
- package/shared/dynamicContent/token.d.ts +4 -0
- package/shared/dynamicContent/token.js +8 -3
- package/shared/layers.d.ts +2 -0
- package/shared/layers.js +2 -0
|
@@ -29,6 +29,7 @@ export const RichMessageEditor = ({
|
|
|
29
29
|
placeholder,
|
|
30
30
|
error,
|
|
31
31
|
isErrored,
|
|
32
|
+
disabled,
|
|
32
33
|
canUsePersonalization,
|
|
33
34
|
canUseEmoji,
|
|
34
35
|
onChange,
|
|
@@ -56,8 +57,14 @@ export const RichMessageEditor = ({
|
|
|
56
57
|
element: arrowElement
|
|
57
58
|
})]
|
|
58
59
|
});
|
|
59
|
-
const onSelectionChange = selection => {
|
|
60
|
-
if (
|
|
60
|
+
const onSelectionChange = (selection, isFocusing = false) => {
|
|
61
|
+
if (disabled) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (isFocusing) {
|
|
65
|
+
setIsFocused(true);
|
|
66
|
+
}
|
|
67
|
+
if (selection && isEqual(selection.anchor, selection.focus)) {
|
|
61
68
|
const {
|
|
62
69
|
path
|
|
63
70
|
} = selection.anchor;
|
|
@@ -133,15 +140,8 @@ export const RichMessageEditor = ({
|
|
|
133
140
|
compact: compact,
|
|
134
141
|
placeholder: placeholder,
|
|
135
142
|
isErrored: isErrored || !!error,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const {
|
|
139
|
-
selection
|
|
140
|
-
} = editor;
|
|
141
|
-
if (selection) {
|
|
142
|
-
onSelectionChange(selection);
|
|
143
|
-
}
|
|
144
|
-
},
|
|
143
|
+
disabled: disabled,
|
|
144
|
+
onFocus: () => onSelectionChange(editor.selection, true),
|
|
145
145
|
onDelete: () => {
|
|
146
146
|
setShowDrop(undefined);
|
|
147
147
|
}
|
|
@@ -32,6 +32,8 @@ export type RichMessageEditorProps = {
|
|
|
32
32
|
error?: ReactNode;
|
|
33
33
|
/** Draw the error border without an error message. */
|
|
34
34
|
isErrored?: boolean;
|
|
35
|
+
/** Make the editor read-only and hide its personalization and emoji actions. */
|
|
36
|
+
disabled?: boolean;
|
|
35
37
|
/** Enable inserting personalization (dynamic-content) tokens. */
|
|
36
38
|
canUsePersonalization?: boolean;
|
|
37
39
|
/** Enable the emoji picker. */
|
|
@@ -3,4 +3,5 @@ export { RichMessageEditor } from './RichMessageEditor';
|
|
|
3
3
|
export { RichMessageViewer } from './RichMessageViewer';
|
|
4
4
|
export { type DynamicContent } from './slate/types';
|
|
5
5
|
export { validateContentSting } from './slate/helpers';
|
|
6
|
+
export { isIgnoringNonTagged } from '../shared/dynamicContent';
|
|
6
7
|
export type { RichMessageEditorProps } from './RichMessageEditor.types';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { RichMessageEditor } from './RichMessageEditor';
|
|
2
2
|
export { RichMessageViewer } from './RichMessageViewer';
|
|
3
|
-
export { validateContentSting } from './slate/helpers';
|
|
3
|
+
export { validateContentSting } from './slate/helpers';
|
|
4
|
+
export { isIgnoringNonTagged } from '../shared/dynamicContent';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Node as SlateNode, Transforms } from 'slate';
|
|
3
|
-
import { useSelected, useSlateStatic } from 'slate-react';
|
|
3
|
+
import { useReadOnly, useSelected, useSlateStatic } from 'slate-react';
|
|
4
4
|
import { Chip } from '../../Chip';
|
|
5
5
|
import { isResolvableDc } from '../../shared/dynamicContent';
|
|
6
6
|
const DynamicContentElementComponent = ({
|
|
@@ -11,6 +11,7 @@ const DynamicContentElementComponent = ({
|
|
|
11
11
|
}) => {
|
|
12
12
|
const editor = useSlateStatic();
|
|
13
13
|
const selected = useSelected();
|
|
14
|
+
const readOnly = useReadOnly();
|
|
14
15
|
const {
|
|
15
16
|
tagName
|
|
16
17
|
} = element.dc;
|
|
@@ -21,7 +22,7 @@ const DynamicContentElementComponent = ({
|
|
|
21
22
|
contentEditable: false,
|
|
22
23
|
"$variant": isResolvable ? 'primary' : 'danger',
|
|
23
24
|
"$selected": selected,
|
|
24
|
-
"$onClose": event => {
|
|
25
|
+
"$onClose": readOnly ? undefined : event => {
|
|
25
26
|
event.preventDefault();
|
|
26
27
|
event.stopPropagation();
|
|
27
28
|
const path = SlateNode.findPath(editor, element);
|
|
@@ -29,6 +29,7 @@ export const SlateEditable = ({
|
|
|
29
29
|
compact,
|
|
30
30
|
placeholder,
|
|
31
31
|
isErrored,
|
|
32
|
+
disabled,
|
|
32
33
|
onFocus,
|
|
33
34
|
onDelete
|
|
34
35
|
}) => {
|
|
@@ -41,6 +42,8 @@ export const SlateEditable = ({
|
|
|
41
42
|
} : undefined,
|
|
42
43
|
"$isErrored": isErrored,
|
|
43
44
|
"$compact": compact,
|
|
45
|
+
"$disabled": disabled,
|
|
46
|
+
readOnly: disabled,
|
|
44
47
|
placeholder: placeholder,
|
|
45
48
|
renderElement: renderElementPersistent,
|
|
46
49
|
onFocus: onFocus
|
|
@@ -18,6 +18,7 @@ export declare const EditableStyled: import("styled-components/dist/types").ISty
|
|
|
18
18
|
}, {
|
|
19
19
|
$isErrored?: boolean;
|
|
20
20
|
$compact?: boolean;
|
|
21
|
+
$disabled?: boolean;
|
|
21
22
|
}>> & string & Omit<import("react").ForwardRefExoticComponent<{
|
|
22
23
|
decorate?: ((entry: import("slate").NodeEntry) => import("slate").DecoratedRange[]) | undefined;
|
|
23
24
|
onDOMBeforeInput?: ((event: InputEvent) => void) | undefined;
|
|
@@ -4,8 +4,10 @@ import { Color, FontSize, FontWeight, ShapeRadius } from '@pushwoosh/kit-constan
|
|
|
4
4
|
export const EditableStyled = styled(Editable).withConfig({
|
|
5
5
|
displayName: "EditableStyled",
|
|
6
6
|
componentId: "sc-16lukqt-0"
|
|
7
|
-
})(["font-weight:", ";font-size:", ";line-height:140%;padding:8px;color:", ";background:", ";caret-color:", ";border:1px solid ", ";border-radius:", ";overflow-x:auto;", " & [data-slate-placeholder='true']{color:", ";opacity:1 !important;}&:focus{border-color:", ";outline:none;}& > p{position:relative;margin:4px 0;&:first-child{margin-top:0;}&:last-child{margin-bottom:0;}}"], FontWeight.REGULAR, FontSize.REGULAR, Color.MAIN, Color.CLEAR, Color.BRIGHT, ({
|
|
7
|
+
})(["font-weight:", ";font-size:", ";line-height:140%;padding:8px;color:", ";background:", ";caret-color:", ";border:1px solid ", ";border-radius:", ";overflow-x:auto;", " ", " & [data-slate-placeholder='true']{color:", ";opacity:1 !important;}&:focus{border-color:", ";outline:none;}& > p{position:relative;margin:4px 0;&:first-child{margin-top:0;}&:last-child{margin-bottom:0;}}"], FontWeight.REGULAR, FontSize.REGULAR, Color.MAIN, Color.CLEAR, Color.BRIGHT, ({
|
|
8
8
|
$isErrored
|
|
9
9
|
}) => $isErrored ? Color.DANGER : Color.FORM, ShapeRadius.CONTROL, ({
|
|
10
10
|
$compact
|
|
11
|
-
}) => $compact && css(["box-sizing:border-box;padding-top:7px;padding-bottom:7px;"]),
|
|
11
|
+
}) => $compact && css(["box-sizing:border-box;padding-top:7px;padding-bottom:7px;"]), ({
|
|
12
|
+
$disabled
|
|
13
|
+
}) => $disabled && css(["color:", ";background:", ";"], Color.LOCKED, Color.FROZEN), Color.PHANTOM, Color.BRIGHT);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
2
|
import { Color, Shadow, ShapeRadius } from '@pushwoosh/kit-constants';
|
|
3
3
|
import { Horizontal } from '@pushwoosh/kit-helpers';
|
|
4
|
+
import { BASE_LAYER_Z_INDEX } from '../shared/layers';
|
|
4
5
|
export const ImSpan = styled.span.withConfig({
|
|
5
6
|
displayName: "ImSpan",
|
|
6
7
|
componentId: "sc-1n9vpwc-0"
|
|
@@ -8,7 +9,7 @@ export const ImSpan = styled.span.withConfig({
|
|
|
8
9
|
export const DropArea = styled.div.withConfig({
|
|
9
10
|
displayName: "DropArea",
|
|
10
11
|
componentId: "sc-1n9vpwc-1"
|
|
11
|
-
})(["z-index:
|
|
12
|
+
})(["z-index:", ";"], BASE_LAYER_Z_INDEX);
|
|
12
13
|
export const DropContent = styled.div.withConfig({
|
|
13
14
|
displayName: "DropContent",
|
|
14
15
|
componentId: "sc-1n9vpwc-2"
|
|
@@ -3,7 +3,7 @@ import { Color } from '@pushwoosh/kit-constants';
|
|
|
3
3
|
import { Horizontal, Vertical } from '@pushwoosh/kit-helpers';
|
|
4
4
|
import { CloseIcon, WhatsappIcon } from '@pushwoosh/kit-icons';
|
|
5
5
|
import { WhatsAppMessageContent } from './components/WhatsAppMessageContent';
|
|
6
|
-
import { WHATSAPP_CARD_PADDING } from './constants';
|
|
6
|
+
import { WHATSAPP_CARD_PADDING, WHATSAPP_CARD_WIDTH } from './constants';
|
|
7
7
|
import { isMessageDrawable } from './helpers';
|
|
8
8
|
import { Lang } from './polyglot';
|
|
9
9
|
import { AppBar, AppName, Backdrop, Card, MissedGlyph, MissedHint, MissedRow, MissedTitle, PreviewText } from './styles';
|
|
@@ -15,51 +15,54 @@ export function WhatsAppPreview(props) {
|
|
|
15
15
|
emptyText,
|
|
16
16
|
isLoading = false,
|
|
17
17
|
applicationName,
|
|
18
|
-
isContentMissing = false
|
|
18
|
+
isContentMissing = false,
|
|
19
|
+
width
|
|
19
20
|
} = props;
|
|
20
21
|
const isDrawable = !isContentMissing && message !== undefined && isMessageDrawable(message);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
const card = _jsxs(Card, {
|
|
23
|
+
"$width": width ?? WHATSAPP_CARD_WIDTH,
|
|
24
|
+
children: [applicationName && _jsxs(AppBar, {
|
|
25
|
+
children: [_jsx(WhatsappIcon, {
|
|
26
|
+
size: "small",
|
|
27
|
+
view: "filled"
|
|
28
|
+
}), _jsx(AppName, {
|
|
29
|
+
children: applicationName
|
|
30
|
+
})]
|
|
31
|
+
}), isLoading && _jsx(Horizontal, {
|
|
32
|
+
"$alignItems": "center",
|
|
33
|
+
"$justifyContent": "center",
|
|
34
|
+
"$padding": WHATSAPP_CARD_PADDING,
|
|
35
|
+
children: _jsx(Spinner, {
|
|
36
|
+
color: Color.LOCKED,
|
|
37
|
+
size: "medium"
|
|
38
|
+
})
|
|
39
|
+
}), !isLoading && isContentMissing && _jsxs(MissedRow, {
|
|
40
|
+
children: [_jsx(MissedGlyph, {
|
|
41
|
+
children: _jsx(CloseIcon, {
|
|
36
42
|
size: "medium"
|
|
37
43
|
})
|
|
38
|
-
}),
|
|
39
|
-
children: [_jsx(
|
|
40
|
-
children: _jsx(
|
|
41
|
-
|
|
44
|
+
}), _jsxs(Vertical, {
|
|
45
|
+
children: [_jsx(MissedTitle, {
|
|
46
|
+
children: _jsx(Lang, {
|
|
47
|
+
message: "DUMB.WHATSAPP_PREVIEW.CONTENT_MISSED_TITLE"
|
|
48
|
+
})
|
|
49
|
+
}), _jsx(MissedHint, {
|
|
50
|
+
children: _jsx(Lang, {
|
|
51
|
+
message: "DUMB.WHATSAPP_PREVIEW.CONTENT_MISSED_HINT"
|
|
42
52
|
})
|
|
43
|
-
}), _jsxs(Vertical, {
|
|
44
|
-
children: [_jsx(MissedTitle, {
|
|
45
|
-
children: _jsx(Lang, {
|
|
46
|
-
message: "DUMB.WHATSAPP_PREVIEW.CONTENT_MISSED_TITLE"
|
|
47
|
-
})
|
|
48
|
-
}), _jsx(MissedHint, {
|
|
49
|
-
children: _jsx(Lang, {
|
|
50
|
-
message: "DUMB.WHATSAPP_PREVIEW.CONTENT_MISSED_HINT"
|
|
51
|
-
})
|
|
52
|
-
})]
|
|
53
53
|
})]
|
|
54
|
-
}), !isLoading && !isContentMissing && !isDrawable && _jsx(PreviewText, {
|
|
55
|
-
"$color": Color.LOCKED,
|
|
56
|
-
"$ellipsis": true,
|
|
57
|
-
children: emptyText ?? _jsx(Lang, {
|
|
58
|
-
message: "DUMB.WHATSAPP_PREVIEW.EMPTY"
|
|
59
|
-
})
|
|
60
|
-
}), !isLoading && isDrawable && _jsx(WhatsAppMessageContent, {
|
|
61
|
-
message: message
|
|
62
54
|
})]
|
|
63
|
-
})
|
|
55
|
+
}), !isLoading && !isContentMissing && !isDrawable && _jsx(PreviewText, {
|
|
56
|
+
"$color": Color.LOCKED,
|
|
57
|
+
"$ellipsis": true,
|
|
58
|
+
children: emptyText ?? _jsx(Lang, {
|
|
59
|
+
message: "DUMB.WHATSAPP_PREVIEW.EMPTY"
|
|
60
|
+
})
|
|
61
|
+
}), !isLoading && isDrawable && _jsx(WhatsAppMessageContent, {
|
|
62
|
+
message: message
|
|
63
|
+
})]
|
|
64
64
|
});
|
|
65
|
+
return width === undefined ? _jsx(Backdrop, {
|
|
66
|
+
children: card
|
|
67
|
+
}) : card;
|
|
65
68
|
}
|
|
@@ -2,7 +2,7 @@ import styled from 'styled-components';
|
|
|
2
2
|
import { Color, FontFamily, FontSize, FontWeight, Shadow, ShapeRadius } from '@pushwoosh/kit-constants';
|
|
3
3
|
import { Columns, Horizontal, Vertical } from '@pushwoosh/kit-helpers';
|
|
4
4
|
import { Text } from '@pushwoosh/kit-typography';
|
|
5
|
-
import { WHATSAPP_APP_BAR_GAP, WHATSAPP_BACKDROP_PADDING, WHATSAPP_BACKDROP_WIDTH, WHATSAPP_APP_BAR_PADDING, WHATSAPP_CARD_PADDING,
|
|
5
|
+
import { WHATSAPP_APP_BAR_GAP, WHATSAPP_BACKDROP_PADDING, WHATSAPP_BACKDROP_WIDTH, WHATSAPP_APP_BAR_PADDING, WHATSAPP_CARD_PADDING, WHATSAPP_MISSED_GAP, WHATSAPP_MISSED_GLYPH_SIZE } from './constants';
|
|
6
6
|
export const Backdrop = styled(Vertical).attrs({
|
|
7
7
|
$alignContent: 'start',
|
|
8
8
|
$justifyItems: 'center',
|
|
@@ -20,12 +20,11 @@ export const Card = styled(Vertical).attrs({
|
|
|
20
20
|
$border: `1px solid ${Color.DIVIDER}`,
|
|
21
21
|
$borderRadius: ShapeRadius.SECTION,
|
|
22
22
|
$gap: WHATSAPP_CARD_PADDING,
|
|
23
|
-
$padding: WHATSAPP_CARD_PADDING
|
|
24
|
-
$width: WHATSAPP_CARD_WIDTH
|
|
23
|
+
$padding: WHATSAPP_CARD_PADDING
|
|
25
24
|
}).withConfig({
|
|
26
25
|
displayName: "Card",
|
|
27
26
|
componentId: "sc-15y0kbp-1"
|
|
28
|
-
})(["box-shadow:", ";overflow-wrap:anywhere;"], Shadow.LARGE);
|
|
27
|
+
})(["box-sizing:border-box;box-shadow:", ";overflow-wrap:anywhere;"], Shadow.LARGE);
|
|
29
28
|
// styled-components merges attrs OVER incoming props, so a plain object here would
|
|
30
29
|
// silently clobber every call-site `$color`; the callback keeps MAIN as a default only.
|
|
31
30
|
export const PreviewText = styled(Text).attrs(props => ({
|
|
@@ -41,4 +41,6 @@ export interface WhatsAppPreviewProps {
|
|
|
41
41
|
applicationName?: string;
|
|
42
42
|
/** Draw the unavailable-content row instead of the message: the address is stale or invalid. */
|
|
43
43
|
isContentMissing?: boolean;
|
|
44
|
+
/** CSS width of the card; when set, the card is drawn bare on the caller's background, without its own backdrop. */
|
|
45
|
+
width?: string | number;
|
|
44
46
|
}
|
package/hooks/useLayer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useId, useLayoutEffect, useRef, useSyncExternalStore } from 'react';
|
|
2
|
-
|
|
2
|
+
import { BASE_LAYER_Z_INDEX as BASE_Z_INDEX } from '../shared/layers';
|
|
3
3
|
const Z_INDEX_STEP = 100;
|
|
4
4
|
const GLOBAL_KEY = '__pushwoosh_dumb_components_layer_state__';
|
|
5
5
|
function createState() {
|
package/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export { RichmediaPreview, useRichmediaHtml } from './RichmediaPreview';
|
|
|
55
55
|
export { SandboxedHtmlFrame, type SandboxedHtmlFrameProps, type IsolatedSandboxedHtmlFrameProps, type InspectableSandboxedHtmlFrameProps, } from './SandboxedHtmlFrame';
|
|
56
56
|
export { NativeRichMediaPreview, parseNativeRichMediaConfig, parseLocalizationParams, NATIVE_RICH_MEDIA_DISPLAY_TYPES, EDITABLE_NATIVE_RICH_MEDIA_DISPLAY_TYPES, } from './NativeRichMediaPreview';
|
|
57
57
|
export type { NativeRichMediaConfig, NativeRichMediaDisplayType, NativeRichMediaText, NativeRichMediaBorder, NativeRichMediaCover, NativeRichMediaAction, NativeRichMediaButton, NativeRichMediaReward, NativeRichMediaDarkOverlay, NativeRichMediaModalBlock, NativeRichMediaSheetBlock, NativeRichMediaCarouselBlock, NativeRichMediaStoriesBlock, NativeRichMediaBannerBlock, NativeRichMediaFullscreenBlock, NativeRichMediaVideoBlock, NativeRichMediaPipBlock, NativeRichMediaScratchcardBlock, NativeRichMediaSpinwheelBlock, NativeRichMediaPreviewProps, NativeRichMediaLocalization, NativeRichMediaTheme, } from './NativeRichMediaPreview';
|
|
58
|
-
export { RichMessageEditor, RichMessageViewer, validateContentSting, type DynamicContent, type RichMessageEditorProps, } from './RichMessageEditor';
|
|
58
|
+
export { RichMessageEditor, RichMessageViewer, validateContentSting, isIgnoringNonTagged, type DynamicContent, type RichMessageEditorProps, } from './RichMessageEditor';
|
|
59
59
|
export { FrequencyCappingEdit, FrequencyCappingReadonly, FrequencyCappingInApps, CappingCountingMode, CountingMode, type CountingModeProps, type LocalCapping, type CappingInAppBase, } from './FrequencyCapping';
|
|
60
60
|
export { SendRateEdit, SendRateReadonly, type SendRateBase, type SendRateEditProps, type SendRateReadonlyProps, } from './SendRate';
|
|
61
61
|
export { Alert } from './Alert';
|
package/index.js
CHANGED
|
@@ -51,7 +51,7 @@ export { Chip } from './Chip';
|
|
|
51
51
|
export { RichmediaPreview, useRichmediaHtml } from './RichmediaPreview';
|
|
52
52
|
export { SandboxedHtmlFrame } from './SandboxedHtmlFrame';
|
|
53
53
|
export { NativeRichMediaPreview, parseNativeRichMediaConfig, parseLocalizationParams, NATIVE_RICH_MEDIA_DISPLAY_TYPES, EDITABLE_NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './NativeRichMediaPreview';
|
|
54
|
-
export { RichMessageEditor, RichMessageViewer, validateContentSting } from './RichMessageEditor';
|
|
54
|
+
export { RichMessageEditor, RichMessageViewer, validateContentSting, isIgnoringNonTagged } from './RichMessageEditor';
|
|
55
55
|
export { FrequencyCappingEdit, FrequencyCappingReadonly, FrequencyCappingInApps, CappingCountingMode, CountingMode } from './FrequencyCapping';
|
|
56
56
|
export { SendRateEdit, SendRateReadonly } from './SendRate';
|
|
57
57
|
export { Alert } from './Alert';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/dumb-components",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.0",
|
|
4
4
|
"description": "React components to build Pushwoosh products",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@codemirror/view": "^6.43.11",
|
|
46
46
|
"@floating-ui/react-dom": "^2.1.2",
|
|
47
47
|
"@lezer/highlight": "^1.2.1",
|
|
48
|
-
"@pushwoosh/kit-constants": "^3.
|
|
48
|
+
"@pushwoosh/kit-constants": "^3.2.0",
|
|
49
49
|
"@pushwoosh/kit-helpers": "^4.17.1",
|
|
50
50
|
"@pushwoosh/kit-icons": "^3.0.1",
|
|
51
51
|
"@pushwoosh/kit-typography": "^2.1.1",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DynamicContentChip, type DynamicContentChipProps } from './DynamicContentChip';
|
|
2
2
|
export { DynamicContentText, type DynamicContentTextProps } from './DynamicContentText';
|
|
3
|
-
export { isResolvableDc, parseDc, splitDynamicContent, stringifyDc } from './token';
|
|
3
|
+
export { isIgnoringNonTagged, isResolvableDc, parseDc, splitDynamicContent, stringifyDc, } from './token';
|
|
4
4
|
export { Paragraph } from './styles';
|
|
5
5
|
export type { DynamicContent, DynamicContentPart, DynamicContentTone } from './types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DynamicContentChip } from './DynamicContentChip';
|
|
2
2
|
export { DynamicContentText } from './DynamicContentText';
|
|
3
|
-
export { isResolvableDc, parseDc, splitDynamicContent, stringifyDc } from './token';
|
|
3
|
+
export { isIgnoringNonTagged, isResolvableDc, parseDc, splitDynamicContent, stringifyDc } from './token';
|
|
4
4
|
export { Paragraph } from './styles';
|
|
@@ -11,11 +11,15 @@ export type DynamicContent = {
|
|
|
11
11
|
modifier: string;
|
|
12
12
|
/** Fallback value used when the tag resolves to nothing. */
|
|
13
13
|
defaultValue: string;
|
|
14
|
+
/** Skip the message for users without the tag instead of sending `defaultValue`; defaults to `!defaultValue`. */
|
|
15
|
+
ignoreNonTagged?: boolean;
|
|
14
16
|
};
|
|
15
17
|
/** Splits text into literal runs and dynamic-content tokens. */
|
|
16
18
|
export declare function splitDynamicContent(text: string): DynamicContentPart[];
|
|
17
19
|
/** Parses `{tagName|modifier|defaultValue}` into its parts. */
|
|
18
20
|
export declare function parseDc(value: string): DynamicContent;
|
|
21
|
+
/** Whether the token skips users without the tag: explicit `ignoreNonTagged`, else an empty `defaultValue`. */
|
|
22
|
+
export declare function isIgnoringNonTagged(dc: DynamicContent): boolean;
|
|
19
23
|
/** Serializes a token back to `{tagName|modifier|defaultValue}`. */
|
|
20
24
|
export declare function stringifyDc(dc: DynamicContent): string;
|
|
21
25
|
/** Whether the sender substitutes this token, or ships it verbatim (dates are case-sensitive, other modifiers are not). */
|
|
@@ -27,13 +27,18 @@ export function splitDynamicContent(text) {
|
|
|
27
27
|
}
|
|
28
28
|
/** Parses `{tagName|modifier|defaultValue}` into its parts. */
|
|
29
29
|
export function parseDc(value) {
|
|
30
|
-
const [tagName, modifier, defaultValue
|
|
30
|
+
const [tagName, modifier, defaultValue] = value.slice(1, -1).split('|');
|
|
31
31
|
return {
|
|
32
32
|
tagName,
|
|
33
33
|
modifier,
|
|
34
|
-
defaultValue
|
|
34
|
+
defaultValue: defaultValue ?? '',
|
|
35
|
+
ignoreNonTagged: defaultValue === undefined
|
|
35
36
|
};
|
|
36
37
|
}
|
|
38
|
+
/** Whether the token skips users without the tag: explicit `ignoreNonTagged`, else an empty `defaultValue`. */
|
|
39
|
+
export function isIgnoringNonTagged(dc) {
|
|
40
|
+
return dc.ignoreNonTagged ?? !dc.defaultValue;
|
|
41
|
+
}
|
|
37
42
|
/** Serializes a token back to `{tagName|modifier|defaultValue}`. */
|
|
38
43
|
export function stringifyDc(dc) {
|
|
39
44
|
const {
|
|
@@ -41,7 +46,7 @@ export function stringifyDc(dc) {
|
|
|
41
46
|
modifier,
|
|
42
47
|
defaultValue
|
|
43
48
|
} = dc;
|
|
44
|
-
return `{${tagName}|${modifier}${
|
|
49
|
+
return `{${tagName}|${modifier}${isIgnoringNonTagged(dc) ? '' : `|${defaultValue}`}}`;
|
|
45
50
|
}
|
|
46
51
|
const CASE_INSENSITIVE_MODIFIERS = ['capitalizefirst', 'capitalizeallfirst', 'uppercase', 'lowercase', 'regular', 'base64', 'cent', 'dollar', 'comma', 'euro', 'jpy', 'lira'];
|
|
47
52
|
const DATE_MODIFIERS = ['M-d-y', 'm-d-y', 'M d y', 'M d Y', 'l', 'M d', 'H:i', 'm-d-y H:i'];
|
package/shared/layers.js
ADDED