@embedreach/components 0.3.16 → 0.3.17
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/dist/chunks/index.js +135 -31
- package/dist/index.d.ts +6 -0
- package/dist/index.umd.js +8 -8
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/chunks/index.js
CHANGED
|
@@ -97651,6 +97651,11 @@ const buildFinalSMSBody = (args) => {
|
|
|
97651
97651
|
return companyName && smsBody ? `${companyName}:
|
|
97652
97652
|
${smsBody}` : smsBody ?? "";
|
|
97653
97653
|
};
|
|
97654
|
+
var ReachMergeFieldTypeEnum = /* @__PURE__ */ ((ReachMergeFieldTypeEnum2) => {
|
|
97655
|
+
ReachMergeFieldTypeEnum2["STATIC"] = "static";
|
|
97656
|
+
ReachMergeFieldTypeEnum2["DYNAMIC"] = "dynamic";
|
|
97657
|
+
return ReachMergeFieldTypeEnum2;
|
|
97658
|
+
})(ReachMergeFieldTypeEnum || {});
|
|
97654
97659
|
const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
97655
97660
|
async function convertToPng(base64Data) {
|
|
97656
97661
|
if (!isBrowser) {
|
|
@@ -97702,6 +97707,12 @@ function extractBase64Data(dataUrl) {
|
|
|
97702
97707
|
}
|
|
97703
97708
|
return parts[1];
|
|
97704
97709
|
}
|
|
97710
|
+
const extractMergeFieldNamesUtil = (text2) => {
|
|
97711
|
+
const mergeFieldRegex = /\{\{([^}]+)\}\}/g;
|
|
97712
|
+
const matches2 = text2.match(mergeFieldRegex);
|
|
97713
|
+
if (!matches2) return [];
|
|
97714
|
+
return matches2.map((match2) => match2.slice(2, -2));
|
|
97715
|
+
};
|
|
97705
97716
|
const capitalize = (str) => {
|
|
97706
97717
|
if (!str) return str;
|
|
97707
97718
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -100342,7 +100353,7 @@ const SMSEditor = ({
|
|
|
100342
100353
|
]
|
|
100343
100354
|
}
|
|
100344
100355
|
),
|
|
100345
|
-
/* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground pt-1 border-t", children: "Maximum
|
|
100356
|
+
/* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground pt-1 border-t", children: "Maximum size of all images: 5MB. We will try to compress the image if possible." })
|
|
100346
100357
|
] }) })
|
|
100347
100358
|
]
|
|
100348
100359
|
}
|
|
@@ -100354,7 +100365,7 @@ const SMSEditor = ({
|
|
|
100354
100365
|
"Enter the URL of the image you want to add to your SMS message. You can use merge fields to make the URL dynamic (e.g., https://example.com/images/{{customer_name}}.jpg).",
|
|
100355
100366
|
/* @__PURE__ */ jsx("br", {}),
|
|
100356
100367
|
/* @__PURE__ */ jsx("br", {}),
|
|
100357
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "Maximum
|
|
100368
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "Maximum size of all images: 5MB. We will try to compress the image if possible." })
|
|
100358
100369
|
] })
|
|
100359
100370
|
] }),
|
|
100360
100371
|
/* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
@@ -100681,6 +100692,9 @@ const SMSEditorContent = ({
|
|
|
100681
100692
|
const hasMergeFieldsInUrl = useCallback((url) => {
|
|
100682
100693
|
return /\{\{[^}]+\}\}/.test(url);
|
|
100683
100694
|
}, []);
|
|
100695
|
+
const extractMergeFieldNames = useCallback((content2) => {
|
|
100696
|
+
return extractMergeFieldNamesUtil(content2);
|
|
100697
|
+
}, []);
|
|
100684
100698
|
const [editingMessage, setEditingMessage] = useState(initialMessage);
|
|
100685
100699
|
const [imagePreview, setImagePreview] = useState(
|
|
100686
100700
|
initialImageUrls.length > 0 ? initialImageUrls[0] : null
|
|
@@ -100690,6 +100704,7 @@ const SMSEditorContent = ({
|
|
|
100690
100704
|
const [isUploadingImage, setIsUploadingImage] = useState(false);
|
|
100691
100705
|
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
|
|
100692
100706
|
const [hasInitialized, setHasInitialized] = useState(false);
|
|
100707
|
+
const [dynamicMergeFieldImages, setDynamicMergeFieldImages] = useState([]);
|
|
100693
100708
|
const fileInputRef = useRef(null);
|
|
100694
100709
|
const autoSaveRef = useRef();
|
|
100695
100710
|
const isInitialMountRef = useRef(true);
|
|
@@ -100697,6 +100712,29 @@ const SMSEditorContent = ({
|
|
|
100697
100712
|
message: initialMessage
|
|
100698
100713
|
});
|
|
100699
100714
|
const { communicationGroup } = useGetCommunicationGroup(communicationGroupId);
|
|
100715
|
+
const getDynamicMergeFieldImages = useCallback(
|
|
100716
|
+
(content2) => {
|
|
100717
|
+
if (!communicationGroup?.extraMergeFields) return [];
|
|
100718
|
+
const mergeFieldNames = extractMergeFieldNames(content2);
|
|
100719
|
+
const dynamicImages = [];
|
|
100720
|
+
for (const mergeField of communicationGroup.extraMergeFields) {
|
|
100721
|
+
if (mergeField.type === ReachMergeFieldTypeEnum.DYNAMIC) {
|
|
100722
|
+
for (const field of mergeField.mergeFields) {
|
|
100723
|
+
if (mergeFieldNames.includes(field.templateName) && field.image) {
|
|
100724
|
+
dynamicImages.push({
|
|
100725
|
+
templateName: field.templateName,
|
|
100726
|
+
displayName: field.displayName,
|
|
100727
|
+
placeholderUrl: field.image.placeholderUrl,
|
|
100728
|
+
maxSize: field.image.maxSize
|
|
100729
|
+
});
|
|
100730
|
+
}
|
|
100731
|
+
}
|
|
100732
|
+
}
|
|
100733
|
+
}
|
|
100734
|
+
return dynamicImages;
|
|
100735
|
+
},
|
|
100736
|
+
[communicationGroup?.extraMergeFields, extractMergeFieldNames]
|
|
100737
|
+
);
|
|
100700
100738
|
const finalSMSBody = useMemo(() => {
|
|
100701
100739
|
return buildFinalSMSBody({
|
|
100702
100740
|
companyName: stableCompanyName || void 0,
|
|
@@ -100704,6 +100742,12 @@ const SMSEditorContent = ({
|
|
|
100704
100742
|
});
|
|
100705
100743
|
}, [stableCompanyName, editingMessage]);
|
|
100706
100744
|
const debouncedMessage = useDebounce(editingMessage, 1e3);
|
|
100745
|
+
useEffect(() => {
|
|
100746
|
+
if (hasInitialized) {
|
|
100747
|
+
const dynamicImages = getDynamicMergeFieldImages(editingMessage);
|
|
100748
|
+
setDynamicMergeFieldImages(dynamicImages);
|
|
100749
|
+
}
|
|
100750
|
+
}, [editingMessage, getDynamicMergeFieldImages, hasInitialized]);
|
|
100707
100751
|
const autoSave = useCallback(async () => {
|
|
100708
100752
|
if (isInitialMountRef.current) {
|
|
100709
100753
|
return;
|
|
@@ -100825,7 +100869,7 @@ const SMSEditorContent = ({
|
|
|
100825
100869
|
console.log("File too large", file.size, MAX_FILE_SIZE);
|
|
100826
100870
|
toast2({
|
|
100827
100871
|
title: "File too large",
|
|
100828
|
-
description: `
|
|
100872
|
+
description: `Sum of all images attached must be 5MB or smaller. The file you tried to upload is ${(file.size / (1024 * 1024)).toFixed(1)}MB.`,
|
|
100829
100873
|
variant: "destructive"
|
|
100830
100874
|
});
|
|
100831
100875
|
return;
|
|
@@ -100941,30 +100985,52 @@ const SMSEditorContent = ({
|
|
|
100941
100985
|
) }),
|
|
100942
100986
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col lg:flex-row gap-6 h-full", children: [
|
|
100943
100987
|
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
100944
|
-
imagePreview
|
|
100945
|
-
/* @__PURE__ */ jsx("div", { className: "
|
|
100946
|
-
|
|
100947
|
-
|
|
100948
|
-
|
|
100949
|
-
|
|
100950
|
-
|
|
100951
|
-
|
|
100952
|
-
|
|
100953
|
-
|
|
100954
|
-
|
|
100955
|
-
|
|
100956
|
-
|
|
100957
|
-
|
|
100958
|
-
"
|
|
100959
|
-
|
|
100960
|
-
|
|
100961
|
-
|
|
100962
|
-
|
|
100963
|
-
|
|
100964
|
-
|
|
100965
|
-
|
|
100966
|
-
|
|
100967
|
-
|
|
100988
|
+
(imagePreview || dynamicMergeFieldImages.length > 0) && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-4 justify-center mb-6", children: [
|
|
100989
|
+
imagePreview && /* @__PURE__ */ jsx("div", { className: "relative group w-fit", children: hasMergeFieldsInUrl(imagePreview) ? /* @__PURE__ */ jsx("div", { className: "max-h-48 max-w-xs rounded-xl shadow-lg border border-gray-200 bg-gray-50 p-4 flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
100990
|
+
/* @__PURE__ */ jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "Image will be populated at send time based on the following merge fields:" }),
|
|
100991
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1 justify-center", children: getMergeFieldsFromUrl(
|
|
100992
|
+
imagePreview,
|
|
100993
|
+
getMergeFields2
|
|
100994
|
+
).map((fieldName, index2) => /* @__PURE__ */ jsx(
|
|
100995
|
+
"span",
|
|
100996
|
+
{
|
|
100997
|
+
className: "inline-flex items-center px-2 py-1 rounded text-xs bg-blue-100 text-blue-800 font-medium border border-blue-200",
|
|
100998
|
+
children: fieldName
|
|
100999
|
+
},
|
|
101000
|
+
index2
|
|
101001
|
+
)) })
|
|
101002
|
+
] }) }) : /* @__PURE__ */ jsxs("div", { className: "max-h-48 max-w-xs rounded-xl shadow-lg border border-green-200 bg-green-50 p-4 flex flex-col items-center justify-center min-h-[12rem]", children: [
|
|
101003
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 flex flex-col items-center justify-center", children: /* @__PURE__ */ jsx(
|
|
101004
|
+
"img",
|
|
101005
|
+
{
|
|
101006
|
+
src: imagePreview,
|
|
101007
|
+
alt: "SMS attachment preview",
|
|
101008
|
+
className: "max-h-32 max-w-48 rounded-lg border border-green-300 object-contain bg-white",
|
|
101009
|
+
style: {
|
|
101010
|
+
boxShadow: "0 2px 12px 0 rgba(0,0,0,0.06)"
|
|
101011
|
+
}
|
|
101012
|
+
}
|
|
101013
|
+
) }),
|
|
101014
|
+
/* @__PURE__ */ jsx("div", { className: "text-xs text-green-600 mt-2", children: "Uploaded Image" })
|
|
101015
|
+
] }) }),
|
|
101016
|
+
dynamicMergeFieldImages.map((dynamicImage, index2) => /* @__PURE__ */ jsxs("div", { className: "relative group w-fit", children: [
|
|
101017
|
+
/* @__PURE__ */ jsx("div", { className: "max-h-48 max-w-xs rounded-xl shadow-lg border border-blue-200 bg-blue-50 p-4 flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
101018
|
+
/* @__PURE__ */ jsx(
|
|
101019
|
+
"img",
|
|
101020
|
+
{
|
|
101021
|
+
src: dynamicImage.placeholderUrl,
|
|
101022
|
+
alt: `Dynamic merge field ${dynamicImage.displayName} placeholder`,
|
|
101023
|
+
className: "max-h-32 max-w-48 rounded-lg border border-blue-300 object-contain bg-white",
|
|
101024
|
+
style: {
|
|
101025
|
+
boxShadow: "0 2px 12px 0 rgba(0,0,0,0.06)"
|
|
101026
|
+
}
|
|
101027
|
+
}
|
|
101028
|
+
),
|
|
101029
|
+
/* @__PURE__ */ jsx("div", { className: "text-xs text-blue-600 mt-3", children: dynamicImage.displayName })
|
|
101030
|
+
] }) }),
|
|
101031
|
+
/* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground mt-2 text-center", children: "Will be dynamically fetched at send time" })
|
|
101032
|
+
] }, index2))
|
|
101033
|
+
] }),
|
|
100968
101034
|
/* @__PURE__ */ jsx(
|
|
100969
101035
|
"input",
|
|
100970
101036
|
{
|
|
@@ -100999,7 +101065,10 @@ const SMSEditorContent = ({
|
|
|
100999
101065
|
MemoizedSMSPreview,
|
|
101000
101066
|
{
|
|
101001
101067
|
body: finalSMSBody,
|
|
101002
|
-
imageUrls:
|
|
101068
|
+
imageUrls: [
|
|
101069
|
+
...dynamicMergeFieldImages.map((img) => img.placeholderUrl),
|
|
101070
|
+
...imagePreview ? [imagePreview] : []
|
|
101071
|
+
]
|
|
101003
101072
|
}
|
|
101004
101073
|
) }) }) })
|
|
101005
101074
|
] })
|
|
@@ -103624,11 +103693,46 @@ const AutomationEditorSMSPreview = ({
|
|
|
103624
103693
|
const currentlySelectedSender = smsChannelSenders.find(
|
|
103625
103694
|
(sender) => sender.channelSender.id === communicationGroup?.smsChannelSenderId
|
|
103626
103695
|
);
|
|
103696
|
+
const extractMergeFieldNames = useCallback((content2) => {
|
|
103697
|
+
return extractMergeFieldNamesUtil(content2);
|
|
103698
|
+
}, []);
|
|
103699
|
+
const smsBody = communicationGroup?.smsMessageBody || "";
|
|
103700
|
+
const getDynamicMergeFieldImages = useCallback(
|
|
103701
|
+
(content2) => {
|
|
103702
|
+
if (!communicationGroup?.extraMergeFields) return [];
|
|
103703
|
+
const mergeFieldNames = extractMergeFieldNames(content2);
|
|
103704
|
+
const dynamicImages = [];
|
|
103705
|
+
for (const mergeField of communicationGroup.extraMergeFields) {
|
|
103706
|
+
if (mergeField.type === ReachMergeFieldTypeEnum.DYNAMIC) {
|
|
103707
|
+
for (const field of mergeField.mergeFields) {
|
|
103708
|
+
if (mergeFieldNames.includes(field.templateName) && field.image) {
|
|
103709
|
+
dynamicImages.push({
|
|
103710
|
+
templateName: field.templateName,
|
|
103711
|
+
displayName: field.displayName,
|
|
103712
|
+
placeholderUrl: field.image.placeholderUrl,
|
|
103713
|
+
maxSize: field.image.maxSize
|
|
103714
|
+
});
|
|
103715
|
+
}
|
|
103716
|
+
}
|
|
103717
|
+
}
|
|
103718
|
+
}
|
|
103719
|
+
return dynamicImages;
|
|
103720
|
+
},
|
|
103721
|
+
[communicationGroup?.extraMergeFields, extractMergeFieldNames]
|
|
103722
|
+
);
|
|
103627
103723
|
const imageUrls = useMemo(
|
|
103628
103724
|
() => communicationGroup?.textMessageMediaUrls ?? [],
|
|
103629
103725
|
[communicationGroup?.textMessageMediaUrls]
|
|
103630
103726
|
);
|
|
103631
|
-
const
|
|
103727
|
+
const dynamicMergeFieldImages = useMemo(() => {
|
|
103728
|
+
return getDynamicMergeFieldImages(smsBody);
|
|
103729
|
+
}, [getDynamicMergeFieldImages, smsBody]);
|
|
103730
|
+
const allImageUrls = useMemo(() => {
|
|
103731
|
+
return [
|
|
103732
|
+
...dynamicMergeFieldImages.map((img) => img.placeholderUrl),
|
|
103733
|
+
...imageUrls
|
|
103734
|
+
];
|
|
103735
|
+
}, [imageUrls, dynamicMergeFieldImages]);
|
|
103632
103736
|
const isLoading = !communicationGroup || !channelSenders || !channelAccounts;
|
|
103633
103737
|
const lastValidCompanyName = useRef(null);
|
|
103634
103738
|
const lastChangeTime = useRef(0);
|
|
@@ -103857,7 +103961,7 @@ const AutomationEditorSMSPreview = ({
|
|
|
103857
103961
|
SMSPreviewExpanded,
|
|
103858
103962
|
{
|
|
103859
103963
|
smsBody: finalSMSBody,
|
|
103860
|
-
imageUrls
|
|
103964
|
+
imageUrls: allImageUrls
|
|
103861
103965
|
}
|
|
103862
103966
|
)
|
|
103863
103967
|
}
|
|
@@ -103868,7 +103972,7 @@ const AutomationEditorSMSPreview = ({
|
|
|
103868
103972
|
MemoizedSMSPreview,
|
|
103869
103973
|
{
|
|
103870
103974
|
body: finalSMSBody,
|
|
103871
|
-
imageUrls
|
|
103975
|
+
imageUrls: allImageUrls
|
|
103872
103976
|
}
|
|
103873
103977
|
)
|
|
103874
103978
|
] }),
|
package/dist/index.d.ts
CHANGED
|
@@ -87,6 +87,7 @@ declare type DynamicMergeField = ReachMergeFieldBase & {
|
|
|
87
87
|
mergeFields: {
|
|
88
88
|
displayName: string;
|
|
89
89
|
templateName: string;
|
|
90
|
+
image?: ImageMergeFieldType;
|
|
90
91
|
}[];
|
|
91
92
|
/**
|
|
92
93
|
* The url of the dynamic merge field (e.g. "https://acme.co/id/")
|
|
@@ -120,6 +121,11 @@ declare interface EngageTypedOverrides {
|
|
|
120
121
|
*/
|
|
121
122
|
declare type FeatureKey = 'measure' | 'measure-setup' | 'acquire-setup' | 'reputation' | 'engage-segment-builder' | 'engage-automations-create-modal' | 'engage-automations-view-modal' | 'engage';
|
|
122
123
|
|
|
124
|
+
declare type ImageMergeFieldType = {
|
|
125
|
+
placeholderUrl: string;
|
|
126
|
+
maxSize: number;
|
|
127
|
+
};
|
|
128
|
+
|
|
123
129
|
declare interface LanguageConfig {
|
|
124
130
|
/** Initial language code (e.g., 'en', 'es', 'fr') */
|
|
125
131
|
default: string;
|