@pushwoosh/dumb-components 4.5.1 → 4.7.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/ChatPreview/ChatPreview.d.ts +4 -0
- package/ChatPreview/ChatPreview.js +65 -0
- package/ChatPreview/components/ChatCardView/ChatCardView.d.ts +4 -0
- package/ChatPreview/components/ChatCardView/ChatCardView.js +61 -0
- package/ChatPreview/components/ChatCardView/index.d.ts +1 -0
- package/ChatPreview/components/ChatCardView/index.js +1 -0
- package/ChatPreview/components/ChatCardView/styles.d.ts +24 -0
- package/ChatPreview/components/ChatCardView/styles.js +40 -0
- package/ChatPreview/components/ChatCardView/types.d.ts +15 -0
- package/ChatPreview/components/ChatMediaView/ChatMediaView.d.ts +4 -0
- package/ChatPreview/components/ChatMediaView/ChatMediaView.js +49 -0
- package/ChatPreview/components/ChatMediaView/index.d.ts +1 -0
- package/ChatPreview/components/ChatMediaView/index.js +1 -0
- package/ChatPreview/components/ChatMediaView/styles.d.ts +13 -0
- package/ChatPreview/components/ChatMediaView/styles.js +18 -0
- package/ChatPreview/components/ChatMediaView/types.d.ts +8 -0
- package/ChatPreview/components/ChatMediaView/types.js +1 -0
- package/ChatPreview/components/ChatText/ChatText.d.ts +4 -0
- package/ChatPreview/components/ChatText/ChatText.js +18 -0
- package/ChatPreview/components/ChatText/index.d.ts +1 -0
- package/ChatPreview/components/ChatText/index.js +1 -0
- package/ChatPreview/components/ChatText/types.d.ts +8 -0
- package/ChatPreview/components/ChatText/types.js +1 -0
- package/ChatPreview/components/Deliverable/Deliverable.d.ts +4 -0
- package/ChatPreview/components/Deliverable/Deliverable.js +25 -0
- package/ChatPreview/components/Deliverable/index.d.ts +1 -0
- package/ChatPreview/components/Deliverable/index.js +1 -0
- package/ChatPreview/components/Deliverable/styles.d.ts +6 -0
- package/ChatPreview/components/Deliverable/styles.js +10 -0
- package/ChatPreview/components/Deliverable/types.d.ts +8 -0
- package/ChatPreview/components/Deliverable/types.js +1 -0
- package/ChatPreview/components/ListSheet/ListSheet.d.ts +4 -0
- package/ChatPreview/components/ListSheet/ListSheet.js +27 -0
- package/ChatPreview/components/ListSheet/index.d.ts +1 -0
- package/ChatPreview/components/ListSheet/index.js +1 -0
- package/ChatPreview/components/ListSheet/styles.d.ts +13 -0
- package/ChatPreview/components/ListSheet/styles.js +20 -0
- package/ChatPreview/components/ListSheet/types.d.ts +9 -0
- package/ChatPreview/components/ListSheet/types.js +1 -0
- package/ChatPreview/components/MessageBubble/MessageBubble.d.ts +4 -0
- package/ChatPreview/components/MessageBubble/MessageBubble.js +67 -0
- package/ChatPreview/components/MessageBubble/index.d.ts +1 -0
- package/ChatPreview/components/MessageBubble/index.js +1 -0
- package/ChatPreview/components/MessageBubble/styles.d.ts +7 -0
- package/ChatPreview/components/MessageBubble/styles.js +11 -0
- package/ChatPreview/components/MessageBubble/types.d.ts +3 -0
- package/ChatPreview/components/MessageBubble/types.js +1 -0
- package/ChatPreview/components/NativeMessage/NativeMessage.d.ts +4 -0
- package/ChatPreview/components/NativeMessage/NativeMessage.js +55 -0
- package/ChatPreview/components/NativeMessage/index.d.ts +1 -0
- package/ChatPreview/components/NativeMessage/index.js +1 -0
- package/ChatPreview/components/NativeMessage/styles.d.ts +6 -0
- package/ChatPreview/components/NativeMessage/styles.js +11 -0
- package/ChatPreview/components/NativeMessage/types.d.ts +7 -0
- package/ChatPreview/components/NativeMessage/types.js +1 -0
- package/ChatPreview/components/ReplyChips/ReplyChips.d.ts +4 -0
- package/ChatPreview/components/ReplyChips/ReplyChips.js +18 -0
- package/ChatPreview/components/ReplyChips/index.d.ts +1 -0
- package/ChatPreview/components/ReplyChips/index.js +1 -0
- package/ChatPreview/components/ReplyChips/styles.d.ts +7 -0
- package/ChatPreview/components/ReplyChips/styles.js +15 -0
- package/ChatPreview/components/ReplyChips/types.d.ts +3 -0
- package/ChatPreview/components/ReplyChips/types.js +1 -0
- package/ChatPreview/components/StatusNotice/StatusNotice.d.ts +4 -0
- package/ChatPreview/components/StatusNotice/StatusNotice.js +44 -0
- package/ChatPreview/components/StatusNotice/index.d.ts +2 -0
- package/ChatPreview/components/StatusNotice/index.js +2 -0
- package/ChatPreview/components/StatusNotice/styles.d.ts +15 -0
- package/ChatPreview/components/StatusNotice/styles.js +22 -0
- package/ChatPreview/components/StatusNotice/types.d.ts +9 -0
- package/ChatPreview/components/StatusNotice/types.js +1 -0
- package/ChatPreview/components/index.d.ts +4 -0
- package/ChatPreview/components/index.js +3 -0
- package/ChatPreview/components/types.d.ts +13 -0
- package/ChatPreview/components/types.js +1 -0
- package/ChatPreview/constants.d.ts +47 -0
- package/ChatPreview/constants.js +89 -0
- package/ChatPreview/helpers.d.ts +22 -0
- package/ChatPreview/helpers.js +57 -0
- package/ChatPreview/index.d.ts +2 -0
- package/ChatPreview/index.js +1 -0
- package/ChatPreview/polyglot/index.d.ts +2 -0
- package/ChatPreview/polyglot/index.js +34 -0
- package/ChatPreview/polyglot/messages_ar.d.ts +3 -0
- package/ChatPreview/polyglot/messages_ar.js +14 -0
- package/ChatPreview/polyglot/messages_bn.d.ts +3 -0
- package/ChatPreview/polyglot/messages_bn.js +14 -0
- package/ChatPreview/polyglot/messages_de.d.ts +3 -0
- package/ChatPreview/polyglot/messages_de.js +14 -0
- package/ChatPreview/polyglot/messages_en.d.ts +3 -0
- package/ChatPreview/polyglot/messages_en.js +14 -0
- package/ChatPreview/polyglot/messages_es.d.ts +3 -0
- package/ChatPreview/polyglot/messages_es.js +14 -0
- package/ChatPreview/polyglot/messages_fr.d.ts +3 -0
- package/ChatPreview/polyglot/messages_fr.js +14 -0
- package/ChatPreview/polyglot/messages_he.d.ts +3 -0
- package/ChatPreview/polyglot/messages_he.js +14 -0
- package/ChatPreview/polyglot/messages_hi.d.ts +3 -0
- package/ChatPreview/polyglot/messages_hi.js +14 -0
- package/ChatPreview/polyglot/messages_ja.d.ts +3 -0
- package/ChatPreview/polyglot/messages_ja.js +14 -0
- package/ChatPreview/polyglot/messages_ko.d.ts +3 -0
- package/ChatPreview/polyglot/messages_ko.js +14 -0
- package/ChatPreview/polyglot/messages_pt.d.ts +3 -0
- package/ChatPreview/polyglot/messages_pt.js +14 -0
- package/ChatPreview/polyglot/messages_ru.d.ts +3 -0
- package/ChatPreview/polyglot/messages_ru.js +14 -0
- package/ChatPreview/polyglot/messages_th.d.ts +3 -0
- package/ChatPreview/polyglot/messages_th.js +14 -0
- package/ChatPreview/polyglot/messages_zh.d.ts +3 -0
- package/ChatPreview/polyglot/messages_zh.js +14 -0
- package/ChatPreview/polyglot/types.d.ts +17 -0
- package/ChatPreview/polyglot/types.js +1 -0
- package/ChatPreview/styles.d.ts +33 -0
- package/ChatPreview/styles.js +54 -0
- package/ChatPreview/types.d.ts +134 -0
- package/ChatPreview/types.js +1 -0
- package/Modal/components/ModalName/ModalName.d.ts +4 -0
- package/Modal/components/ModalName/ModalName.js +151 -0
- package/Modal/components/ModalName/index.d.ts +2 -0
- package/Modal/components/ModalName/index.js +1 -0
- package/Modal/components/ModalName/types.d.ts +39 -0
- package/Modal/components/ModalName/types.js +1 -0
- package/Modal/index.d.ts +1 -0
- package/Modal/index.js +1 -0
- package/Modal/polyglot/messages_ar.js +1 -0
- package/Modal/polyglot/messages_bn.js +1 -0
- package/Modal/polyglot/messages_de.js +1 -0
- package/Modal/polyglot/messages_en.js +1 -0
- package/Modal/polyglot/messages_es.js +1 -0
- package/Modal/polyglot/messages_fr.js +1 -0
- package/Modal/polyglot/messages_he.js +1 -0
- package/Modal/polyglot/messages_hi.js +1 -0
- package/Modal/polyglot/messages_ja.js +1 -0
- package/Modal/polyglot/messages_ko.js +1 -0
- package/Modal/polyglot/messages_pt.js +1 -0
- package/Modal/polyglot/messages_ru.js +1 -0
- package/Modal/polyglot/messages_th.js +1 -0
- package/Modal/polyglot/messages_zh.js +1 -0
- package/Modal/polyglot/types.d.ts +1 -0
- package/PageHeader/components/Rename/Rename.d.ts +1 -1
- package/PageHeader/components/Rename/Rename.js +1 -1
- package/WhatsAppPreview/components/WhatsAppMessageContent/WhatsAppMessageContent.js +1 -1
- package/WhatsAppPreview/helpers.d.ts +0 -3
- package/WhatsAppPreview/helpers.js +0 -56
- package/index.d.ts +3 -1
- package/index.js +2 -1
- package/native/Input.js +3 -1
- package/package.json +1 -1
- package/{WhatsAppPreview/components/WhatsAppFormattedText → shared/whatsAppMarkup}/WhatsAppFormattedText.js +2 -2
- package/shared/whatsAppMarkup/index.d.ts +3 -0
- package/{WhatsAppPreview/components/WhatsAppFormattedText/index.d.ts → shared/whatsAppMarkup/index.js} +1 -0
- package/shared/whatsAppMarkup/parse.d.ts +3 -0
- package/shared/whatsAppMarkup/parse.js +56 -0
- package/shared/whatsAppMarkup/types.js +1 -0
- package/WhatsAppPreview/components/WhatsAppFormattedText/index.js +0 -1
- /package/{WhatsAppPreview/components/WhatsAppFormattedText → ChatPreview/components/ChatCardView}/types.js +0 -0
- /package/{WhatsAppPreview/components/WhatsAppFormattedText → shared/whatsAppMarkup}/WhatsAppFormattedText.d.ts +0 -0
- /package/{WhatsAppPreview/components/WhatsAppFormattedText → shared/whatsAppMarkup}/types.d.ts +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Horizontal, Vertical } from '@pushwoosh/kit-helpers';
|
|
4
|
+
import { Paragraph } from '@pushwoosh/kit-typography';
|
|
5
|
+
import { Banner } from '../../../Banner';
|
|
6
|
+
import { Button } from '../../../Button';
|
|
7
|
+
import { FieldBox } from '../../../FieldBox';
|
|
8
|
+
import { NativeInput } from '../../../native';
|
|
9
|
+
import { useLang } from '../../polyglot';
|
|
10
|
+
import { Modal } from '../Modal';
|
|
11
|
+
import { ModalBody, ModalFooter, ModalHeader } from '../ModalContent';
|
|
12
|
+
import { ModalTitle } from '../ModalTitle';
|
|
13
|
+
function ModalNameDialog(props) {
|
|
14
|
+
const {
|
|
15
|
+
title,
|
|
16
|
+
description,
|
|
17
|
+
label,
|
|
18
|
+
placeholder,
|
|
19
|
+
initialName = '',
|
|
20
|
+
suggestedName,
|
|
21
|
+
initialWarning,
|
|
22
|
+
initialError,
|
|
23
|
+
maxLength,
|
|
24
|
+
submitText,
|
|
25
|
+
cancelText,
|
|
26
|
+
onSubmit,
|
|
27
|
+
onClose
|
|
28
|
+
} = props;
|
|
29
|
+
const lang = useLang();
|
|
30
|
+
const inputRef = useRef(null);
|
|
31
|
+
const [name, setName] = useState(suggestedName ?? initialName);
|
|
32
|
+
const [isEmptyError, setIsEmptyError] = useState(false);
|
|
33
|
+
const [error, setError] = useState(initialError);
|
|
34
|
+
const [warning, setWarning] = useState(initialWarning ? {
|
|
35
|
+
name: initialName.trim(),
|
|
36
|
+
content: initialWarning
|
|
37
|
+
} : undefined);
|
|
38
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
39
|
+
const trimmedName = name.trim();
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const frame = requestAnimationFrame(() => inputRef.current?.select());
|
|
42
|
+
return () => cancelAnimationFrame(frame);
|
|
43
|
+
}, []);
|
|
44
|
+
const close = () => {
|
|
45
|
+
if (!isSaving) {
|
|
46
|
+
onClose();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const submit = async event => {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
if (isSaving) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!trimmedName) {
|
|
55
|
+
setIsEmptyError(true);
|
|
56
|
+
inputRef.current?.focus();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!warning && !error && trimmedName === initialName.trim()) {
|
|
60
|
+
onClose();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
setIsSaving(true);
|
|
64
|
+
setError(undefined);
|
|
65
|
+
try {
|
|
66
|
+
const result = await onSubmit(trimmedName);
|
|
67
|
+
setWarning(result?.warning ? {
|
|
68
|
+
name: trimmedName,
|
|
69
|
+
content: result.warning
|
|
70
|
+
} : undefined);
|
|
71
|
+
setError(result?.error);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
setWarning(undefined);
|
|
74
|
+
setError(e?.message || lang({
|
|
75
|
+
message: 'DUMB.MODAL.UNEXPECTED_ERROR'
|
|
76
|
+
}));
|
|
77
|
+
} finally {
|
|
78
|
+
setIsSaving(false);
|
|
79
|
+
requestAnimationFrame(() => inputRef.current?.focus());
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return _jsx(Modal, {
|
|
83
|
+
size: "small",
|
|
84
|
+
isOpen: true,
|
|
85
|
+
onClose: close,
|
|
86
|
+
children: _jsxs("form", {
|
|
87
|
+
onSubmit: submit,
|
|
88
|
+
children: [_jsx(ModalHeader, {
|
|
89
|
+
children: _jsx(ModalTitle, {
|
|
90
|
+
children: title
|
|
91
|
+
})
|
|
92
|
+
}), _jsx(ModalBody, {
|
|
93
|
+
children: _jsxs(Vertical, {
|
|
94
|
+
"$gap": 16,
|
|
95
|
+
children: [description && _jsx(Paragraph, {
|
|
96
|
+
children: description
|
|
97
|
+
}), _jsx(FieldBox, {
|
|
98
|
+
title: label,
|
|
99
|
+
error: error,
|
|
100
|
+
children: _jsx(NativeInput, {
|
|
101
|
+
ref: inputRef,
|
|
102
|
+
type: "text",
|
|
103
|
+
value: name,
|
|
104
|
+
placeholder: placeholder,
|
|
105
|
+
maxLength: maxLength,
|
|
106
|
+
disabled: isSaving,
|
|
107
|
+
"$isErrored": isEmptyError || !!error,
|
|
108
|
+
"aria-invalid": isEmptyError || !!error,
|
|
109
|
+
onChange: event => {
|
|
110
|
+
setName(event.target.value);
|
|
111
|
+
setIsEmptyError(false);
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
}), warning && warning.name === trimmedName && _jsx(Banner, {
|
|
115
|
+
type: "warning",
|
|
116
|
+
title: warning.content
|
|
117
|
+
})]
|
|
118
|
+
})
|
|
119
|
+
}), _jsx(ModalFooter, {
|
|
120
|
+
children: _jsxs(Horizontal, {
|
|
121
|
+
"$justifyContent": "end",
|
|
122
|
+
"$gap": 8,
|
|
123
|
+
children: [_jsx(Button, {
|
|
124
|
+
color: "secondary",
|
|
125
|
+
isDisabled: isSaving,
|
|
126
|
+
onClick: close,
|
|
127
|
+
children: cancelText ?? lang({
|
|
128
|
+
message: 'DUMB.MODAL.CANCEL'
|
|
129
|
+
})
|
|
130
|
+
}), _jsx(Button, {
|
|
131
|
+
color: "primary",
|
|
132
|
+
type: "submit",
|
|
133
|
+
isLoading: isSaving,
|
|
134
|
+
children: submitText ?? lang({
|
|
135
|
+
message: 'DUMB.MODAL.SAVE'
|
|
136
|
+
})
|
|
137
|
+
})]
|
|
138
|
+
})
|
|
139
|
+
})]
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** Asks for an entity name on save, rename or with a suggestion; warnings and errors go under the field. */
|
|
144
|
+
export function ModalName({
|
|
145
|
+
isOpen,
|
|
146
|
+
...props
|
|
147
|
+
}) {
|
|
148
|
+
return isOpen ? _jsx(ModalNameDialog, {
|
|
149
|
+
...props
|
|
150
|
+
}) : null;
|
|
151
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ModalName } from './ModalName';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/** What {@link ModalNameProps.onSubmit} reports back; nothing means the name was saved. */
|
|
3
|
+
export type ModalNameResult = void | {
|
|
4
|
+
/** Keeps the dialog open with an orange banner under the field, e.g. "name already taken". */
|
|
5
|
+
warning?: string;
|
|
6
|
+
/** Keeps the dialog open with the message under the field. */
|
|
7
|
+
error?: string;
|
|
8
|
+
};
|
|
9
|
+
/** Props of {@link ModalName}. */
|
|
10
|
+
export interface ModalNameProps {
|
|
11
|
+
/** Whether the dialog is open; every opening starts from `initialName`. */
|
|
12
|
+
isOpen: boolean;
|
|
13
|
+
/** Heading, e.g. "Save the segment". */
|
|
14
|
+
title: string;
|
|
15
|
+
/** Hint above the field. */
|
|
16
|
+
description?: ReactNode;
|
|
17
|
+
/** Caption of the field. */
|
|
18
|
+
label: string;
|
|
19
|
+
/** Example name ending with an ellipsis, e.g. "Active buyers in Germany…". */
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/** Value the field opens with, e.g. the current name when renaming; Save without changes just closes. */
|
|
22
|
+
initialName?: string;
|
|
23
|
+
/** Name proposed by the screen, e.g. the push title; the field opens with it selected and Save saves it as is. */
|
|
24
|
+
suggestedName?: string;
|
|
25
|
+
/** Banner shown on opening while the field still holds `initialName`. */
|
|
26
|
+
initialWarning?: string;
|
|
27
|
+
/** Error shown under the field on opening, e.g. the name typed in the header is too long. */
|
|
28
|
+
initialError?: string;
|
|
29
|
+
/** Field length limit. */
|
|
30
|
+
maxLength?: number;
|
|
31
|
+
/** Save button caption (defaults to localized "Save"). */
|
|
32
|
+
submitText?: string;
|
|
33
|
+
/** Cancel button caption (defaults to localized "Cancel"). */
|
|
34
|
+
cancelText?: string;
|
|
35
|
+
/** Called with the trimmed non-empty name; a throw is shown as an error. */
|
|
36
|
+
onSubmit: (name: string) => ModalNameResult | Promise<ModalNameResult>;
|
|
37
|
+
/** Called on Cancel or Escape. */
|
|
38
|
+
onClose: () => void;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/Modal/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Modal } from './components/Modal';
|
|
2
2
|
export { ModalTitle } from './components/ModalTitle';
|
|
3
|
+
export { ModalName, type ModalNameProps, type ModalNameResult } from './components/ModalName';
|
|
3
4
|
export { ModalConfirm, ModalConfirmProvider, useModalConfirm, } from './components/ModalConfirm';
|
|
4
5
|
export { ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter, } from './components/ModalContent';
|
package/Modal/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Modal } from './components/Modal';
|
|
2
2
|
export { ModalTitle } from './components/ModalTitle';
|
|
3
|
+
export { ModalName } from './components/ModalName';
|
|
3
4
|
export { ModalConfirm, ModalConfirmProvider, useModalConfirm } from './components/ModalConfirm';
|
|
4
5
|
export { ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter } from './components/ModalContent';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
2
|
import type { RenameProps } from './types';
|
|
3
|
-
/** Editable name for `PageHeader` `titleExtra`: click to edit
|
|
3
|
+
/** Editable name for `PageHeader` `titleExtra`: click to edit, Enter or blur commits, Escape reverts; pairs with `ModalName`. */
|
|
4
4
|
export declare function Rename(props: RenameProps): ReactElement;
|
|
@@ -6,7 +6,7 @@ import { PAGE_HEADER_RENAME_ATTRIBUTE } from '../../constants';
|
|
|
6
6
|
const RENAME_MARK = {
|
|
7
7
|
[PAGE_HEADER_RENAME_ATTRIBUTE]: true
|
|
8
8
|
};
|
|
9
|
-
/** Editable name for `PageHeader` `titleExtra`: click to edit
|
|
9
|
+
/** Editable name for `PageHeader` `titleExtra`: click to edit, Enter or blur commits, Escape reverts; pairs with `ModalName`. */
|
|
10
10
|
export function Rename(props) {
|
|
11
11
|
const {
|
|
12
12
|
value,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { MessageText } from './styles';
|
|
3
|
+
import { WhatsAppFormattedText } from '../../../shared/whatsAppMarkup';
|
|
3
4
|
import { drawableAttachments } from '../../helpers';
|
|
4
5
|
import { WhatsAppAttachment } from '../WhatsAppAttachment';
|
|
5
|
-
import { WhatsAppFormattedText } from '../WhatsAppFormattedText';
|
|
6
6
|
/** Card body: attachments on top, message text underneath. */
|
|
7
7
|
export function WhatsAppMessageContent(props) {
|
|
8
8
|
const {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type { WhatsAppTextNode } from './components/WhatsAppFormattedText/types';
|
|
2
1
|
import type { WhatsAppAttachment, WhatsAppAttachmentKind, WhatsAppMessage } from './types';
|
|
3
|
-
/** Splits WhatsApp markup (`*bold*`, `_italic_`, `~strike~`, backtick monospace) into a render tree. */
|
|
4
|
-
export declare function parseWhatsAppMarkup(text: string): WhatsAppTextNode[];
|
|
5
2
|
/** File type shown on a document card: the name extension, or the MIME subtype when the name carries none. */
|
|
6
3
|
export declare function getAttachmentExtension(attachment: WhatsAppAttachment): string;
|
|
7
4
|
/** Picks how the attachment is drawn: explicit `kind` first, then the MIME type, then the extension. */
|
|
@@ -1,60 +1,4 @@
|
|
|
1
1
|
import { WHATSAPP_ATTACHMENT_EXTENSIONS } from './constants';
|
|
2
|
-
const MARKERS = [{
|
|
3
|
-
style: 'mono',
|
|
4
|
-
marker: '```'
|
|
5
|
-
}, {
|
|
6
|
-
style: 'mono',
|
|
7
|
-
marker: '`'
|
|
8
|
-
}, {
|
|
9
|
-
style: 'bold',
|
|
10
|
-
marker: '*'
|
|
11
|
-
}, {
|
|
12
|
-
style: 'italic',
|
|
13
|
-
marker: '_'
|
|
14
|
-
}, {
|
|
15
|
-
style: 'strike',
|
|
16
|
-
marker: '~'
|
|
17
|
-
}];
|
|
18
|
-
function findMarkerAt(text, index) {
|
|
19
|
-
return MARKERS.find(({
|
|
20
|
-
marker
|
|
21
|
-
}) => text.startsWith(marker, index)) || null;
|
|
22
|
-
}
|
|
23
|
-
/** Splits WhatsApp markup (`*bold*`, `_italic_`, `~strike~`, backtick monospace) into a render tree. */
|
|
24
|
-
export function parseWhatsAppMarkup(text) {
|
|
25
|
-
const nodes = [];
|
|
26
|
-
let plain = '';
|
|
27
|
-
let index = 0;
|
|
28
|
-
const flush = () => {
|
|
29
|
-
if (plain) {
|
|
30
|
-
nodes.push({
|
|
31
|
-
text: plain
|
|
32
|
-
});
|
|
33
|
-
plain = '';
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
while (index < text.length) {
|
|
37
|
-
const found = findMarkerAt(text, index);
|
|
38
|
-
const openEnd = found ? index + found.marker.length : index;
|
|
39
|
-
const closeStart = found ? text.indexOf(found.marker, openEnd) : -1;
|
|
40
|
-
if (!found || closeStart <= openEnd) {
|
|
41
|
-
plain += text[index];
|
|
42
|
-
index += 1;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const inner = text.slice(openEnd, closeStart);
|
|
46
|
-
flush();
|
|
47
|
-
nodes.push({
|
|
48
|
-
style: found.style,
|
|
49
|
-
children: found.style === 'mono' ? [{
|
|
50
|
-
text: inner
|
|
51
|
-
}] : parseWhatsAppMarkup(inner)
|
|
52
|
-
});
|
|
53
|
-
index = closeStart + found.marker.length;
|
|
54
|
-
}
|
|
55
|
-
flush();
|
|
56
|
-
return nodes;
|
|
57
|
-
}
|
|
58
2
|
/** File type shown on a document card: the name extension, or the MIME subtype when the name carries none. */
|
|
59
3
|
export function getAttachmentExtension(attachment) {
|
|
60
4
|
const {
|
package/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { GetStartedPage, type GetStartedPageCheckListView, type GetStartedPagePr
|
|
|
13
13
|
export { EditableField } from './EditableField';
|
|
14
14
|
export { EmojiPicker } from './EmojiPicker';
|
|
15
15
|
export { InputFile } from './InputFile';
|
|
16
|
-
export { Modal, ModalTitle, ModalConfirm, ModalConfirmProvider, useModalConfirm, ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter, } from './Modal';
|
|
16
|
+
export { Modal, ModalTitle, ModalConfirm, ModalConfirmProvider, useModalConfirm, ModalName, type ModalNameProps, type ModalNameResult, ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter, } from './Modal';
|
|
17
17
|
export { Pagination } from './Pagination';
|
|
18
18
|
export { ProgressBar } from './ProgressBar';
|
|
19
19
|
export { Popover } from './Popover';
|
|
@@ -37,6 +37,8 @@ export { PushStoriesPreview, hasStoryButton, normalizeStoryDuration, PUSH_STORIE
|
|
|
37
37
|
export { InboxPreview, resolveInboxLayout, MAX_CAROUSEL_SLIDES, type InboxLayoutType, type InboxPreviewPlatform, type InboxPreviewContent, type InboxPreviewProps, type InboxPreviewSlide, } from './InboxPreview';
|
|
38
38
|
export { WhatsAppPreview } from './WhatsAppPreview';
|
|
39
39
|
export type { WhatsAppAttachment, WhatsAppAttachmentKind, WhatsAppMessage, WhatsAppPreviewProps, } from './WhatsAppPreview';
|
|
40
|
+
export { ChatPreview } from './ChatPreview';
|
|
41
|
+
export type { ChatButton, ChatButtonKind, ChatCard, ChatChannel, ChatCompatibility, ChatContent, ChatContentType, ChatHeader, ChatList, ChatListItem, ChatMedia, ChatMediaKind, ChatPreviewProps, ChatRcsLayout, } from './ChatPreview';
|
|
40
42
|
export { Toast, ToastProvider, useToast } from './Toast';
|
|
41
43
|
export { AutosizeInput, PageHeader, PageHeaderEditable, Rename, } from './PageHeader';
|
|
42
44
|
export { Steps, useSteps } from './Steps';
|
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export { GetStartedPage } from './GetStartedPage';
|
|
|
13
13
|
export { EditableField } from './EditableField';
|
|
14
14
|
export { EmojiPicker } from './EmojiPicker';
|
|
15
15
|
export { InputFile } from './InputFile';
|
|
16
|
-
export { Modal, ModalTitle, ModalConfirm, ModalConfirmProvider, useModalConfirm, ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter } from './Modal';
|
|
16
|
+
export { Modal, ModalTitle, ModalConfirm, ModalConfirmProvider, useModalConfirm, ModalName, ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter } from './Modal';
|
|
17
17
|
export { Pagination } from './Pagination';
|
|
18
18
|
export { ProgressBar } from './ProgressBar';
|
|
19
19
|
export { Popover } from './Popover';
|
|
@@ -36,6 +36,7 @@ export { PushPreview } from './PushPreview';
|
|
|
36
36
|
export { PushStoriesPreview, hasStoryButton, normalizeStoryDuration, PUSH_STORIES_ASPECT_RATIO, PUSH_STORIES_DEFAULT_DURATION, PUSH_STORIES_MAX_DURATION } from './PushStoriesPreview';
|
|
37
37
|
export { InboxPreview, resolveInboxLayout, MAX_CAROUSEL_SLIDES } from './InboxPreview';
|
|
38
38
|
export { WhatsAppPreview } from './WhatsAppPreview';
|
|
39
|
+
export { ChatPreview } from './ChatPreview';
|
|
39
40
|
export { Toast, ToastProvider, useToast } from './Toast';
|
|
40
41
|
export { AutosizeInput, PageHeader, PageHeaderEditable, Rename } from './PageHeader';
|
|
41
42
|
export { Steps, useSteps } from './Steps';
|
package/native/Input.js
CHANGED
|
@@ -6,4 +6,6 @@ export const NativeInput = styled.input.withConfig({
|
|
|
6
6
|
componentId: "sc-oqkcxd-0"
|
|
7
7
|
})(["height:", ";padding:0 calc(12px - 1px);border:1px solid ", ";border-radius:", ";font-size:", ";line-height:", ";color:", ";-webkit-text-fill-color:", ";background-color:", ";&:focus{outline:none;border-color:", ";}&:disabled{background-color:", ";-webkit-text-fill-color:", ";}&::placeholder{color:", ";-webkit-text-fill-color:", ";}"], UnitSize.FIELD_HEIGHT, ({
|
|
8
8
|
$isErrored
|
|
9
|
-
}) => $isErrored ? Color.DANGER : Color.FORM, ShapeRadius.CONTROL, FontSize.REGULAR, LineHeight.REGULAR, Color.MAIN, Color.MAIN, Color.CLEAR,
|
|
9
|
+
}) => $isErrored ? Color.DANGER : Color.FORM, ShapeRadius.CONTROL, FontSize.REGULAR, LineHeight.REGULAR, Color.MAIN, Color.MAIN, Color.CLEAR, ({
|
|
10
|
+
$isErrored
|
|
11
|
+
}) => $isErrored ? Color.DANGER : Color.BRIGHT, Color.FROZEN, Color.LOCKED, Color.PHANTOM, Color.PHANTOM);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Text } from '@pushwoosh/kit-typography';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { parseWhatsAppMarkup } from './parse';
|
|
4
|
+
import { DynamicContentText } from '../dynamicContent';
|
|
5
5
|
const TAGS = {
|
|
6
6
|
bold: 'b',
|
|
7
7
|
italic: 'i',
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const MARKERS = [{
|
|
2
|
+
style: 'mono',
|
|
3
|
+
marker: '```'
|
|
4
|
+
}, {
|
|
5
|
+
style: 'mono',
|
|
6
|
+
marker: '`'
|
|
7
|
+
}, {
|
|
8
|
+
style: 'bold',
|
|
9
|
+
marker: '*'
|
|
10
|
+
}, {
|
|
11
|
+
style: 'italic',
|
|
12
|
+
marker: '_'
|
|
13
|
+
}, {
|
|
14
|
+
style: 'strike',
|
|
15
|
+
marker: '~'
|
|
16
|
+
}];
|
|
17
|
+
function findMarkerAt(text, index) {
|
|
18
|
+
return MARKERS.find(({
|
|
19
|
+
marker
|
|
20
|
+
}) => text.startsWith(marker, index)) || null;
|
|
21
|
+
}
|
|
22
|
+
/** Splits WhatsApp markup (`*bold*`, `_italic_`, `~strike~`, backtick monospace) into a render tree. */
|
|
23
|
+
export function parseWhatsAppMarkup(text) {
|
|
24
|
+
const nodes = [];
|
|
25
|
+
let plain = '';
|
|
26
|
+
let index = 0;
|
|
27
|
+
const flush = () => {
|
|
28
|
+
if (plain) {
|
|
29
|
+
nodes.push({
|
|
30
|
+
text: plain
|
|
31
|
+
});
|
|
32
|
+
plain = '';
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
while (index < text.length) {
|
|
36
|
+
const found = findMarkerAt(text, index);
|
|
37
|
+
const openEnd = found ? index + found.marker.length : index;
|
|
38
|
+
const closeStart = found ? text.indexOf(found.marker, openEnd) : -1;
|
|
39
|
+
if (!found || closeStart <= openEnd) {
|
|
40
|
+
plain += text[index];
|
|
41
|
+
index += 1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const inner = text.slice(openEnd, closeStart);
|
|
45
|
+
flush();
|
|
46
|
+
nodes.push({
|
|
47
|
+
style: found.style,
|
|
48
|
+
children: found.style === 'mono' ? [{
|
|
49
|
+
text: inner
|
|
50
|
+
}] : parseWhatsAppMarkup(inner)
|
|
51
|
+
});
|
|
52
|
+
index = closeStart + found.marker.length;
|
|
53
|
+
}
|
|
54
|
+
flush();
|
|
55
|
+
return nodes;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { WhatsAppFormattedText } from './WhatsAppFormattedText';
|
|
File without changes
|
|
File without changes
|
/package/{WhatsAppPreview/components/WhatsAppFormattedText → shared/whatsAppMarkup}/types.d.ts
RENAMED
|
File without changes
|